summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2017-10-24 03:15:23 -0400
committerTakashi Iwai <tiwai@suse.de>2017-10-31 06:06:39 -0400
commit727dede0ba8afbd8d19116d39f2ae8d19d00033d (patch)
tree45e476bd259b8d5e7851f1adf31fe5e3f21fd27b
parent3f1185d6c9d3fe91aa85ec8d3f4d71207452c458 (diff)
sound: Retire OSS
Since no complaints have been raised after disabling the build of OSS (Open Sound System) by the commit 31cbee6a5611 ("sound: Disable the build of OSS drivers"), let's finally drop the whole code and documentation. Some glue codes are still left intact since sound/oss/dmasound stuff remains -- which is an independent implementation solely for m68k, and it's not covered by ALSA yet. Also, a couple of API header files (linux/sound.h and linux/soundcard.h) are kept remaining as well, since the OSS API itself is still supported by ALSA OSS emulation, and applications can refer to these. Where we're at it, some help texts in the top-level Kconfig are adjusted, too (who still needs to specify I/O port in kbuild nowadays?). Reviewed-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--Documentation/sound/oss/ALS66
-rw-r--r--Documentation/sound/oss/AudioExcelDSP16101
-rw-r--r--Documentation/sound/oss/CMI8330152
-rw-r--r--Documentation/sound/oss/ESS34
-rw-r--r--Documentation/sound/oss/ESS186855
-rw-r--r--Documentation/sound/oss/Introduction459
-rw-r--r--Documentation/sound/oss/MultiSound1137
-rw-r--r--Documentation/sound/oss/OPL36
-rw-r--r--Documentation/sound/oss/Opti218
-rw-r--r--Documentation/sound/oss/PAS16162
-rw-r--r--Documentation/sound/oss/PSS41
-rw-r--r--Documentation/sound/oss/PSS-updates88
-rw-r--r--Documentation/sound/oss/README.OSS1455
-rw-r--r--Documentation/sound/oss/README.modules106
-rw-r--r--Documentation/sound/oss/README.ymfsb107
-rw-r--r--Documentation/sound/oss/SoundPro105
-rw-r--r--Documentation/sound/oss/Soundblaster53
-rw-r--r--Documentation/sound/oss/Tropez+26
-rw-r--r--Documentation/sound/oss/VIBRA1680
-rw-r--r--Documentation/sound/oss/WaveArtist170
-rw-r--r--Documentation/sound/oss/btaudio92
-rw-r--r--Documentation/sound/oss/mwave185
-rw-r--r--Documentation/sound/oss/oss-parameters.txt51
-rw-r--r--Documentation/sound/oss/ultrasound30
-rw-r--r--MAINTAINERS11
-rw-r--r--sound/Kconfig33
-rw-r--r--sound/Makefile3
-rw-r--r--sound/oss/CHANGELOG369
-rw-r--r--sound/oss/Kconfig533
-rw-r--r--sound/oss/Makefile107
-rw-r--r--sound/oss/README.FIRST6
-rw-r--r--sound/oss/ad1848.c3062
-rw-r--r--sound/oss/ad1848.h24
-rw-r--r--sound/oss/ad1848_mixer.h253
-rw-r--r--sound/oss/aedsp16.c1373
-rw-r--r--sound/oss/audio.c985
-rw-r--r--sound/oss/bin2hex.c39
-rw-r--r--sound/oss/coproc.h12
-rw-r--r--sound/oss/dev_table.c256
-rw-r--r--sound/oss/dev_table.h390
-rw-r--r--sound/oss/dmabuf.c1268
-rw-r--r--sound/oss/hex2hex.c101
-rw-r--r--sound/oss/kahlua.c229
-rw-r--r--sound/oss/midi_ctrl.h22
-rw-r--r--sound/oss/midi_synth.c712
-rw-r--r--sound/oss/midi_synth.h47
-rw-r--r--sound/oss/midibuf.c427
-rw-r--r--sound/oss/mpu401.c1804
-rw-r--r--sound/oss/mpu401.h11
-rw-r--r--sound/oss/msnd.c413
-rw-r--r--sound/oss/msnd.h278
-rw-r--r--sound/oss/msnd_classic.c3
-rw-r--r--sound/oss/msnd_classic.h185
-rw-r--r--sound/oss/msnd_pinnacle.c1941
-rw-r--r--sound/oss/msnd_pinnacle.h246
-rw-r--r--sound/oss/opl3.c1255
-rw-r--r--sound/oss/opl3_hw.h246
-rw-r--r--sound/oss/os.h45
-rw-r--r--sound/oss/pas2.h20
-rw-r--r--sound/oss/pas2_card.c458
-rw-r--r--sound/oss/pas2_midi.c262
-rw-r--r--sound/oss/pas2_mixer.c327
-rw-r--r--sound/oss/pas2_pcm.c419
-rw-r--r--sound/oss/pss.c1270
-rw-r--r--sound/oss/sb.h185
-rw-r--r--sound/oss/sb_audio.c1097
-rw-r--r--sound/oss/sb_card.c354
-rw-r--r--sound/oss/sb_card.h149
-rw-r--r--sound/oss/sb_common.c1287
-rw-r--r--sound/oss/sb_ess.c1822
-rw-r--r--sound/oss/sb_ess.h34
-rw-r--r--sound/oss/sb_midi.c206
-rw-r--r--sound/oss/sb_mixer.c770
-rw-r--r--sound/oss/sb_mixer.h105
-rw-r--r--sound/oss/sequencer.c1661
-rw-r--r--sound/oss/sleep.h18
-rw-r--r--sound/oss/sound_calls.h87
-rw-r--r--sound/oss/sound_config.h144
-rw-r--r--sound/oss/sound_firmware.h29
-rw-r--r--sound/oss/sound_timer.c327
-rw-r--r--sound/oss/soundcard.c733
-rw-r--r--sound/oss/soundvers.h2
-rw-r--r--sound/oss/swarm_cs4297a.c2781
-rw-r--r--sound/oss/sys_timer.c280
-rw-r--r--sound/oss/trix.c525
-rw-r--r--sound/oss/tuning.h23
-rw-r--r--sound/oss/uart401.c477
-rw-r--r--sound/oss/uart6850.c361
-rw-r--r--sound/oss/ulaw.h69
-rw-r--r--sound/oss/v_midi.c290
-rw-r--r--sound/oss/v_midi.h14
-rw-r--r--sound/oss/vidc.c557
-rw-r--r--sound/oss/vidc.h63
-rw-r--r--sound/oss/vidc_fill.S218
-rw-r--r--sound/oss/waveartist.c2043
-rw-r--r--sound/oss/waveartist.h92
96 files changed, 2 insertions, 41225 deletions
diff --git a/Documentation/sound/oss/ALS b/Documentation/sound/oss/ALS
deleted file mode 100644
index bf10bed4574b..000000000000
--- a/Documentation/sound/oss/ALS
+++ /dev/null
@@ -1,66 +0,0 @@
1ALS-007/ALS-100/ALS-200 based sound cards
2=========================================
3
4Support for sound cards based around the Avance Logic
5ALS-007/ALS-100/ALS-200 chip is included. These chips are a single
6chip PnP sound solution which is mostly hardware compatible with the
7Sound Blaster 16 card, with most differences occurring in the use of
8the mixer registers. For this reason the ALS code is integrated
9as part of the Sound Blaster 16 driver (adding only 800 bytes to the
10SB16 driver).
11
12To use an ALS sound card under Linux, enable the following options as
13modules in the sound configuration section of the kernel config:
14 - 100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support
15 - FM synthesizer (YM3812/OPL-3) support
16 - standalone MPU401 support may be required for some cards; for the
17 ALS-007, when using isapnptools, it is required
18Since the ALS-007/100/200 are PnP cards, ISAPnP support should probably be
19compiled in. If kernel level PnP support is not included, isapnptools will
20be required to configure the card before the sound modules are loaded.
21
22When using kernel level ISAPnP, the kernel should correctly identify and
23configure all resources required by the card when the "sb" module is
24inserted. Note that the ALS-007 does not have a 16 bit DMA channel and that
25the MPU401 interface on this card uses a different interrupt to the audio
26section. This should all be correctly configured by the kernel; if problems
27with the MPU401 interface surface, try using the standalone MPU401 module,
28passing "0" as the "sb" module's "mpu_io" module parameter to prevent the
29soundblaster driver attempting to register the MPU401 itself. The onboard
30synth device can be accessed using the "opl3" module.
31
32If isapnptools is used to wake up the sound card (as in 2.2.x), the settings
33of the card's resources should be passed to the kernel modules ("sb", "opl3"
34and "mpu401") using the module parameters. When configuring an ALS-007, be
35sure to specify different IRQs for the audio and MPU401 sections - this card
36requires they be different. For "sb", "io", "irq" and "dma" should be set
37to the same values used to configure the audio section of the card with
38isapnp. "dma16" should be explicitly set to "-1" for an ALS-007 since this
39card does not have a 16 bit dma channel; if not specified the kernel will
40default to using channel 5 anyway which will cause audio not to work.
41"mpu_io" should be set to 0. The "io" parameter of the "opl3" module should
42also agree with the setting used by isapnp. To get the MPU401 interface
43working on an ALS-007 card, the "mpu401" module will be required since this
44card uses separate IRQs for the audio and MPU401 sections and there is no
45parameter available to pass a different IRQ to the "sb" driver (whose
46inbuilt MPU401 driver would otherwise be fine). Insert the mpu401 module
47passing appropriate values using the "io" and "irq" parameters.
48
49The resulting sound driver will provide the following capabilities:
50 - 8 and 16 bit audio playback
51 - 8 and 16 bit audio recording
52 - Software selection of record source (line in, CD, FM, mic, master)
53 - Record and playback of midi data via the external MPU-401
54 - Playback of midi data using inbuilt FM synthesizer
55 - Control of the ALS-007 mixer via any OSS-compatible mixer programs.
56 Controls available are Master (L&R), Line in (L&R), CD (L&R),
57 DSP/PCM/audio out (L&R), FM (L&R) and Mic in (mono).
58
59Jonathan Woithe
60jwoithe@just42.net
6130 March 1998
62
63Modified 2000-02-26 by Dave Forrest, drf5n@virginia.edu to add ALS100/ALS200
64Modified 2000-04-10 by Paul Laufer, pelaufer@csupomona.edu to add ISAPnP info.
65Modified 2000-11-19 by Jonathan Woithe, jwoithe@just42.net
66 - updated information for kernel 2.4.x.
diff --git a/Documentation/sound/oss/AudioExcelDSP16 b/Documentation/sound/oss/AudioExcelDSP16
deleted file mode 100644
index ea8549faede9..000000000000
--- a/Documentation/sound/oss/AudioExcelDSP16
+++ /dev/null
@@ -1,101 +0,0 @@
1Driver
2------
3
4Information about Audio Excel DSP 16 driver can be found in the source
5file aedsp16.c
6Please, read the head of the source before using it. It contain useful
7information.
8
9Configuration
10-------------
11
12The Audio Excel configuration, is now done with the standard Linux setup.
13You have to configure the sound card (Sound Blaster or Microsoft Sound System)
14and, if you want it, the Roland MPU-401 (do not use the Sound Blaster MPU-401,
15SB-MPU401) in the main driver menu. Activate the lowlevel drivers then select
16the Audio Excel hardware that you want to initialize. Check the IRQ/DMA/MIRQ
17of the Audio Excel initialization: it must be the same as the SBPRO (or MSS)
18setup. If the parameters are different, correct it.
19I you own a Gallant's audio card based on SC-6600, activate the SC-6600 support.
20If you want to change the configuration of the sound board, be sure to
21check off all the configuration items before re-configure it.
22
23Module parameters
24-----------------
25To use this driver as a module, you must configure some module parameters, to
26set up I/O addresses, IRQ lines and DMA channels. Some parameters are
27mandatory while some others are optional. Here a list of parameters you can
28use with this module:
29
30Name Description
31==== ===========
32MANDATORY
33io I/O base address (0x220 or 0x240)
34irq irq line (5, 7, 9, 10 or 11)
35dma dma channel (0, 1 or 3)
36
37OPTIONAL
38mss_base I/O base address for activate MSS mode (default SBPRO)
39 (0x530 or 0xE80)
40mpu_base I/O base address for activate MPU-401 mode
41 (0x300, 0x310, 0x320 or 0x330)
42mpu_irq MPU-401 irq line (5, 7, 9, 10 or 0)
43
44A configuration file in /etc/modprobe.d/ directory will have lines like this:
45
46options opl3 io=0x388
47options ad1848 io=0x530 irq=11 dma=3
48options aedsp16 io=0x220 irq=11 dma=3 mss_base=0x530
49
50Where the aedsp16 options are the options for this driver while opl3 and
51ad1848 are the corresponding options for the MSS and OPL3 modules.
52
53Loading MSS and OPL3 needs to pre load the aedsp16 module to set up correctly
54the sound card. Installation dependencies must be written in configuration
55files under /etc/modprobe.d/ directory:
56
57softdep ad1848 pre: aedsp16
58softdep opl3 pre: aedsp16
59
60Then you must load the sound modules stack in this order:
61sound -> aedsp16 -> [ ad1848, opl3 ]
62
63With the above configuration, loading ad1848 or opl3 modules, will
64automatically load all the sound stack.
65
66Sound cards supported
67---------------------
68This driver supports the SC-6000 and SC-6600 based Gallant's sound card.
69It don't support the Audio Excel DSP 16 III (try the SC-6600 code).
70I'm working on the III version of the card: if someone have useful
71information about it, please let me know.
72For all the non-supported audio cards, you have to boot MS-DOS (or WIN95)
73activating the audio card with the MS-DOS device driver, then you have to
74<ctrl>-<alt>-<del> and boot Linux.
75Follow these steps:
76
771) Compile Linux kernel with standard sound driver, using the emulation
78 you want, with the parameters of your audio card,
79 e.g. Microsoft Sound System irq10 dma3
802) Install your new kernel as the default boot kernel.
813) Boot MS-DOS and configure the audio card with the boot time device
82 driver, for MSS irq10 dma3 in our example.
834) <ctrl>-<alt>-<del> and boot Linux. This will maintain the DOS configuration
84 and will boot the new kernel with sound driver. The sound driver will find
85 the audio card and will recognize and attach it.
86
87Reports on User successes
88-------------------------
89
90> Date: Mon, 29 Jul 1996 08:35:40 +0100
91> From: Mr S J Greenaway <sjg95@unixfe.rl.ac.uk>
92> To: riccardo@cdc8g5.cdc.polimi.it (Riccardo Facchetti)
93> Subject: Re: Audio Excel DSP 16 initialization code
94>
95> Just to let you know got my Audio Excel (emulating a MSS) working
96> with my original SB16, thanks for the driver!
97
98
99Last revised: 20 August 1998
100Riccardo Facchetti
101fizban@tin.it
diff --git a/Documentation/sound/oss/CMI8330 b/Documentation/sound/oss/CMI8330
deleted file mode 100644
index 8a5fd1611c6f..000000000000
--- a/Documentation/sound/oss/CMI8330
+++ /dev/null
@@ -1,152 +0,0 @@
1Documentation for CMI 8330 (SoundPRO)
2-------------------------------------
3Alessandro Zummo <azummo@ita.flashnet.it>
4
5( Be sure to read Documentation/sound/oss/SoundPro too )
6
7
8This adapter is now directly supported by the sb driver.
9
10 The only thing you have to do is to compile the kernel sound
11support as a module and to enable kernel ISAPnP support,
12as shown below.
13
14
15CONFIG_SOUND=m
16CONFIG_SOUND_SB=m
17
18CONFIG_PNP=y
19CONFIG_ISAPNP=y
20
21
22and optionally:
23
24
25CONFIG_SOUND_MPU401=m
26
27 for MPU401 support.
28
29
30(I suggest you to use "make menuconfig" or "make xconfig"
31 for a more comfortable configuration editing)
32
33
34
35Then you can do
36
37 modprobe sb
38
39and everything will be (hopefully) configured.
40
41You should get something similar in syslog:
42
43sb: CMI8330 detected.
44sb: CMI8330 sb base located at 0x220
45sb: CMI8330 mpu base located at 0x330
46sb: CMI8330 mail reports to Alessandro Zummo <azummo@ita.flashnet.it>
47sb: ISAPnP reports CMI 8330 SoundPRO at i/o 0x220, irq 7, dma 1,5
48
49
50
51
52The old documentation file follows for reference
53purposes.
54
55
56How to enable CMI 8330 (SOUNDPRO) soundchip on Linux
57------------------------------------------
58Stefan Laudat <Stefan.Laudat@asit.ro>
59
60[Note: The CMI 8338 is unrelated and is supported by cmpci.o]
61
62
63 In order to use CMI8330 under Linux you just have to use a proper isapnp.conf, a good isapnp and a little bit of patience. I use isapnp 1.17, but
64you may get a better one I guess at http://www.roestock.demon.co.uk/isapnptools/.
65
66 Of course you will have to compile kernel sound support as module, as shown below:
67
68CONFIG_SOUND=m
69CONFIG_SOUND_OSS=m
70CONFIG_SOUND_SB=m
71CONFIG_SOUND_ADLIB=m
72CONFIG_SOUND_MPU401=m
73# Mikro$chaft sound system (kinda useful here ;))
74CONFIG_SOUND_MSS=m
75
76 The /etc/isapnp.conf file will be:
77
78<snip below>
79
80
81(READPORT 0x0203)
82(ISOLATE PRESERVE)
83(IDENTIFY *)
84(VERBOSITY 2)
85(CONFLICT (IO FATAL)(IRQ FATAL)(DMA FATAL)(MEM FATAL)) # or WARNING
86(VERIFYLD N)
87
88
89# WSS
90
91(CONFIGURE CMI0001/16777472 (LD 0
92(IO 0 (SIZE 8) (BASE 0x0530))
93(IO 1 (SIZE 8) (BASE 0x0388))
94(INT 0 (IRQ 7 (MODE +E)))
95(DMA 0 (CHANNEL 0))
96(NAME "CMI0001/16777472[0]{CMI8330/C3D Audio Adapter}")
97(ACT Y)
98))
99
100# MPU
101
102(CONFIGURE CMI0001/16777472 (LD 1
103(IO 0 (SIZE 2) (BASE 0x0330))
104(INT 0 (IRQ 11 (MODE +E)))
105(NAME "CMI0001/16777472[1]{CMI8330/C3D Audio Adapter}")
106(ACT Y)
107))
108
109# Joystick
110
111(CONFIGURE CMI0001/16777472 (LD 2
112(IO 0 (SIZE 8) (BASE 0x0200))
113(NAME "CMI0001/16777472[2]{CMI8330/C3D Audio Adapter}")
114(ACT Y)
115))
116
117# SoundBlaster
118
119(CONFIGURE CMI0001/16777472 (LD 3
120(IO 0 (SIZE 16) (BASE 0x0220))
121(INT 0 (IRQ 5 (MODE +E)))
122(DMA 0 (CHANNEL 1))
123(DMA 1 (CHANNEL 5))
124(NAME "CMI0001/16777472[3]{CMI8330/C3D Audio Adapter}")
125(ACT Y)
126))
127
128
129(WAITFORKEY)
130
131<end of snip>
132
133 The module sequence is trivial:
134
135/sbin/insmod soundcore
136/sbin/insmod sound
137/sbin/insmod uart401
138# insert this first
139/sbin/insmod ad1848 io=0x530 irq=7 dma=0 soundpro=1
140# The sb module is an alternative to the ad1848 (Microsoft Sound System)
141# Anyhow, this is full duplex and has MIDI
142/sbin/insmod sb io=0x220 dma=1 dma16=5 irq=5 mpu_io=0x330
143
144
145
146Alma Chao <elysian@ethereal.torsion.org> suggests the following in
147a /etc/modprobe.d/*conf file:
148
149alias sound ad1848
150alias synth0 opl3
151options ad1848 io=0x530 irq=7 dma=0 soundpro=1
152options opl3 io=0x388
diff --git a/Documentation/sound/oss/ESS b/Documentation/sound/oss/ESS
deleted file mode 100644
index bba93b4d2def..000000000000
--- a/Documentation/sound/oss/ESS
+++ /dev/null
@@ -1,34 +0,0 @@
1Documentation for the ESS AudioDrive chips
2
3In 2.4 kernels the SoundBlaster driver not only tries to detect an ESS chip, it
4tries to detect the type of ESS chip too. The correct detection of the chip
5doesn't always succeed however, so unless you use the kernel isapnp facilities
6(and you chip is pnp capable) the default behaviour is 2.0 behaviour which
7means: only detect ES688 and ES1688.
8
9All ESS chips now have a recording level setting. This is a need-to-have for
10people who want to use their ESS for recording sound.
11
12Every chip that's detected as a later-than-es1688 chip has a 6 bits logarithmic
13master volume control.
14
15Every chip that's detected as a ES1887 now has Full Duplex support. Made a
16little testprogram that shows that is works, haven't seen a real program that
17needs this however.
18
19For ESS chips an additional parameter "esstype" can be specified. This controls
20the (auto) detection of the ESS chips. It can have 3 kinds of values:
21
22-1 Act like 2.0 kernels: only detect ES688 or ES1688.
230 Try to auto-detect the chip (may fail for ES1688)
24688 The chip will be treated as ES688
251688 ,, ,, ,, ,, ,, ,, ES1688
261868 ,, ,, ,, ,, ,, ,, ES1868
271869 ,, ,, ,, ,, ,, ,, ES1869
281788 ,, ,, ,, ,, ,, ,, ES1788
291887 ,, ,, ,, ,, ,, ,, ES1887
301888 ,, ,, ,, ,, ,, ,, ES1888
31
32Because Full Duplex is supported for ES1887 you can specify a second DMA
33channel by specifying module parameter dma16. It can be one of: 0, 1, 3 or 5.
34
diff --git a/Documentation/sound/oss/ESS1868 b/Documentation/sound/oss/ESS1868
deleted file mode 100644
index 55e922f21bc0..000000000000
--- a/Documentation/sound/oss/ESS1868
+++ /dev/null
@@ -1,55 +0,0 @@
1Documentation for the ESS1868F AudioDrive PnP sound card
2
3The ESS1868 sound card is a PnP ESS1688-compatible 16-bit sound card.
4
5It should be automatically detected by the Linux Kernel isapnp support when you
6load the sb.o module. Otherwise you should take care of:
7
8 * The ESS1868 does not allow use of a 16-bit DMA, thus DMA 0, 1, 2, and 3
9 may only be used.
10
11 * isapnptools version 1.14 does work with ESS1868. Earlier versions might
12 not.
13
14 * Sound support MUST be compiled as MODULES, not statically linked
15 into the kernel.
16
17
18NOTE: this is only needed when not using the kernel isapnp support!
19
20For configuring the sound card's I/O addresses, IRQ and DMA, here is a
21sample copy of the isapnp.conf directives regarding the ESS1868:
22
23(CONFIGURE ESS1868/-1 (LD 1
24(IO 0 (BASE 0x0220))
25(IO 1 (BASE 0x0388))
26(IO 2 (BASE 0x0330))
27(DMA 0 (CHANNEL 1))
28(INT 0 (IRQ 5 (MODE +E)))
29(ACT Y)
30))
31
32(for a full working isapnp.conf file, remember the
33(ISOLATE)
34(IDENTIFY *)
35at the beginning and the
36(WAITFORKEY)
37at the end.)
38
39In this setup, the main card I/O is 0x0220, FM synthesizer is 0x0388, and
40the MPU-401 MIDI port is located at 0x0330. IRQ is IRQ 5, DMA is channel 1.
41
42After configuring the sound card via isapnp, to use the card you must load
43the sound modules with the proper I/O information. Here is my setup:
44
45# ESS1868F AudioDrive initialization
46
47/sbin/modprobe sound
48/sbin/insmod uart401
49/sbin/insmod sb io=0x220 irq=5 dma=1 dma16=-1
50/sbin/insmod mpu401 io=0x330
51/sbin/insmod opl3 io=0x388
52/sbin/insmod v_midi
53
54opl3 is the FM synthesizer
55/sbin/insmod opl3 io=0x388
diff --git a/Documentation/sound/oss/Introduction b/Documentation/sound/oss/Introduction
deleted file mode 100644
index 42da2d8fa372..000000000000
--- a/Documentation/sound/oss/Introduction
+++ /dev/null
@@ -1,459 +0,0 @@
1Introduction Notes on Modular Sound Drivers and Soundcore
2Wade Hampton
32/14/2001
4
5Purpose:
6========
7This document provides some general notes on the modular
8sound drivers and their configuration, along with the
9support modules sound.o and soundcore.o.
10
11Note, some of this probably should be added to the Sound-HOWTO!
12
13Note, soundlow.o was present with 2.2 kernels but is not
14required for 2.4.x kernels. References have been removed
15to this.
16
17
18Copying:
19========
20none
21
22
23History:
24========
250.1.0 11/20/1998 First version, draft
261.0.0 11/1998 Alan Cox changes, incorporation in 2.2.0
27 as Documentation/sound/oss/Introduction
281.1.0 6/30/1999 Second version, added notes on making the drivers,
29 added info on multiple sound cards of similar types,]
30 added more diagnostics info, added info about esd.
31 added info on OSS and ALSA.
321.1.1 19991031 Added notes on sound-slot- and sound-service.
33 (Alan Cox)
341.1.2 20000920 Modified for Kernel 2.4 (Christoph Hellwig)
351.1.3 20010214 Minor notes and corrections (Wade Hampton)
36 Added examples of sound-slot-0, etc.
37
38
39Modular Sound Drivers:
40======================
41
42Thanks to the GREAT work by Alan Cox (alan@lxorguk.ukuu.org.uk),
43
44[And Oleg Drokin, Thomas Sailer, Andrew Veliath and more than a few
45 others - not to mention Hannu's original code being designed well
46 enough to cope with that kind of chopping up](Alan)
47
48the standard Linux kernels support a modular sound driver. From
49Alan's comments in linux/drivers/sound/README.FIRST:
50
51 The modular sound driver patches were funded by Red Hat Software
52 (www.redhat.com). The sound driver here is thus a modified version of
53 Hannu's code. Please bear that in mind when considering the appropriate
54 forums for bug reporting.
55
56The modular sound drivers may be loaded via insmod or modprobe.
57To support all the various sound modules, there are two general
58support modules that must be loaded first:
59
60 soundcore.o: Top level handler for the sound system, provides
61 a set of functions for registration of devices
62 by type.
63
64 sound.o: Common sound functions required by all modules.
65
66For the specific sound modules (e.g., sb.o for the Soundblaster),
67read the documentation on that module to determine what options
68are available, for example IRQ, address, DMA.
69
70Warning, the options for different cards sometime use different names
71for the same or a similar feature (dma1= versus dma16=). As a last
72resort, inspect the code (search for module_param).
73
74Notes:
75
761. There is a new OpenSource sound driver called ALSA which is
77 currently under development: http://www.alsa-project.org/
78 The ALSA drivers support some newer hardware that may not
79 be supported by this sound driver and also provide some
80 additional features.
81
822. The commercial OSS driver may be obtained from the site:
83 http://www.opensound.com. This may be used for cards that
84 are unsupported by the kernel driver, or may be used
85 by other operating systems.
86
873. The enlightenment sound daemon may be used for playing
88 multiple sounds at the same time via a single card, eliminating
89 some of the requirements for multiple sound card systems. For
90 more information, see: http://www.tux.org/~ricdude/EsounD.html
91 The "esd" program may be used with the real-player and mpeg
92 players like mpg123 and x11amp. The newer real-player
93 and some games even include built-in support for ESD!
94
95
96Building the Modules:
97=====================
98
99This document does not provide full details on building the
100kernel, etc. The notes below apply only to making the kernel
101sound modules. If this conflicts with the kernel's README,
102the README takes precedence.
103
1041. To make the kernel sound modules, cd to your /usr/src/linux
105 directory (typically) and type make config, make menuconfig,
106 or make xconfig (to start the command line, dialog, or x-based
107 configuration tool).
108
1092. Select the Sound option and a dialog will be displayed.
110
1113. Select M (module) for "Sound card support".
112
1134. Select your sound driver(s) as a module. For ProAudio, Sound
114 Blaster, etc., select M (module) for OSS sound modules.
115 [thanks to Marvin Stodolsky <stodolsk@erols.com>]A
116
1175. Make the kernel (e.g., make bzImage), and install the kernel.
118
1196. Make the modules and install them (make modules; make modules_install).
120
121Note, for 2.5.x kernels, make sure you have the newer module-init-tools
122installed or modules will not be loaded properly. 2.5.x requires an
123updated module-init-tools.
124
125
126Plug and Play (PnP:
127===================
128
129If the sound card is an ISA PnP card, isapnp may be used
130to configure the card. See the file isapnp.txt in the
131directory one level up (e.g., /usr/src/linux/Documentation).
132
133Also the 2.4.x kernels provide PnP capabilities, see the
134file NEWS in this directory.
135
136PCI sound cards are highly recommended, as they are far
137easier to configure and from what I have read, they use
138less resources and are more CPU efficient.
139
140
141INSMOD:
142=======
143
144If loading via insmod, the common modules must be loaded in the
145order below BEFORE loading the other sound modules. The card-specific
146modules may then be loaded (most require parameters). For example,
147I use the following via a shell script to load my SoundBlaster:
148
149SB_BASE=0x240
150SB_IRQ=9
151SB_DMA=3
152SB_DMA2=5
153SB_MPU=0x300
154#
155echo Starting sound
156/sbin/insmod soundcore
157/sbin/insmod sound
158#
159echo Starting sound blaster....
160/sbin/insmod uart401
161/sbin/insmod sb io=$SB_BASE irq=$SB_IRQ dma=$SB_DMA dma16=$SB_DMA2 mpu_io=$SB_MP
162
163When using sound as a module, I typically put these commands
164in a file such as /root/soundon.sh.
165
166
167MODPROBE:
168=========
169
170If loading via modprobe, these common files are automatically loaded when
171requested by modprobe. For example, my /etc/modprobe.d/oss.conf contains:
172
173alias sound sb
174options sb io=0x240 irq=9 dma=3 dma16=5 mpu_io=0x300
175
176All you need to do to load the module is:
177
178 /sbin/modprobe sb
179
180
181Sound Status:
182=============
183
184The status of sound may be read/checked by:
185 cat (anyfile).au >/dev/audio
186
187[WWH: This may not work properly for SoundBlaster PCI 128 cards
188such as the es1370/1 (see the es1370/1 files in this directory)
189as they do not automatically support uLaw on /dev/audio.]
190
191The status of the modules and which modules depend on
192which other modules may be checked by:
193 /sbin/lsmod
194
195/sbin/lsmod should show something like the following:
196 sb 26280 0
197 uart401 5640 0 [sb]
198 sound 57112 0 [sb uart401]
199 soundcore 1968 8 [sb sound]
200
201
202Removing Sound:
203===============
204
205Sound may be removed by using /sbin/rmmod in the reverse order
206in which you load the modules. Note, if a program has a sound device
207open (e.g., xmixer), that module (and the modules on which it
208depends) may not be unloaded.
209
210For example, I use the following to remove my Soundblaster (rmmod
211in the reverse order in which I loaded the modules):
212
213/sbin/rmmod sb
214/sbin/rmmod uart401
215/sbin/rmmod sound
216/sbin/rmmod soundcore
217
218When using sound as a module, I typically put these commands
219in a script such as /root/soundoff.sh.
220
221
222Removing Sound for use with OSS:
223================================
224
225If you get really stuck or have a card that the kernel modules
226will not support, you can get a commercial sound driver from
227http://www.opensound.com. Before loading the commercial sound
228driver, you should do the following:
229
2301. remove sound modules (detailed above)
2312. remove the sound modules from /etc/modprobe.d/*.conf
2323. move the sound modules from /lib/modules/<kernel>/misc
233 (for example, I make a /lib/modules/<kernel>/misc/tmp
234 directory and copy the sound module files to that
235 directory).
236
237
238Multiple Sound Cards:
239=====================
240
241The sound drivers will support multiple sound cards and there
242are some great applications like multitrack that support them.
243Typically, you need two sound cards of different types. Note, this
244uses more precious interrupts and DMA channels and sometimes
245can be a configuration nightmare. I have heard reports of 3-4
246sound cards (typically I only use 2). You can sometimes use
247multiple PCI sound cards of the same type.
248
249On my machine I have two sound cards (cs4232 and Soundblaster Vibra
25016). By loading sound as modules, I can control which is the first
251sound device (/dev/dsp, /dev/audio, /dev/mixer) and which is
252the second. Normally, the cs4232 (Dell sound on the motherboard)
253would be the first sound device, but I prefer the Soundblaster.
254All you have to do is to load the one you want as /dev/dsp
255first (in my case "sb") and then load the other one
256(in my case "cs4232").
257
258If you have two cards of the same type that are jumpered
259cards or different PnP revisions, you may load the same
260module twice. For example, I have a SoundBlaster vibra 16
261and an older SoundBlaster 16 (jumpers). To load the module
262twice, you need to do the following:
263
2641. Copy the sound modules to a new name. For example
265 sb.o could be copied (or symlinked) to sb1.o for the
266 second SoundBlaster.
267
2682. Make a second entry in /etc/modprobe.d/*conf, for example,
269 sound1 or sb1. This second entry should refer to the
270 new module names for example sb1, and should include
271 the I/O, etc. for the second sound card.
272
2733. Update your soundon.sh script, etc.
274
275Warning: I have never been able to get two PnP sound cards of the
276same type to load at the same time. I have tried this several times
277with the Soundblaster Vibra 16 cards. OSS has indicated that this
278is a PnP problem.... If anyone has any luck doing this, please
279send me an E-MAIL. PCI sound cards should not have this problem.a
280Since this was originally release, I have received a couple of
281mails from people who have accomplished this!
282
283NOTE: In Linux 2.4 the Sound Blaster driver (and only this one yet)
284supports multiple cards with one module by default.
285Read the file 'Soundblaster' in this directory for details.
286
287
288Sound Problems:
289===============
290
291First RTFM (including the troubleshooting section
292in the Sound-HOWTO).
293
2941) If you are having problems loading the modules (for
295 example, if you get device conflict errors) try the
296 following:
297
298 A) If you have Win95 or NT on the same computer,
299 write down what addresses, IRQ, and DMA channels
300 those were using for the same hardware. You probably
301 can use these addresses, IRQs, and DMA channels.
302 You should really do this BEFORE attempting to get
303 sound working!
304
305 B) Check (cat) /proc/interrupts, /proc/ioports,
306 and /proc/dma. Are you trying to use an address,
307 IRQ or DMA port that another device is using?
308
309 C) Check (cat) /proc/isapnp
310
311 D) Inspect your /var/log/messages file. Often that will
312 indicate what IRQ or IO port could not be obtained.
313
314 E) Try another port or IRQ. Note this may involve
315 using the PnP tools to move the sound card to
316 another location. Sometimes this is the only way
317 and it is more or less trial and error.
318
3192) If you get motor-boating (the same sound or part of a
320 sound clip repeated), you probably have either an IRQ
321 or DMA conflict. Move the card to another IRQ or DMA
322 port. This has happened to me when playing long files
323 when I had an IRQ conflict.
324
3253. If you get dropouts or pauses when playing high sample
326 rate files such as using mpg123 or x11amp/xmms, you may
327 have too slow of a CPU and may have to use the options to
328 play the files at 1/2 speed. For example, you may use
329 the -2 or -4 option on mpg123. You may also get this
330 when trying to play mpeg files stored on a CD-ROM
331 (my Toshiba T8000 PII/366 sometimes has this problem).
332
3334. If you get "cannot access device" errors, your /dev/dsp
334 files, etc. may be set to owner root, mode 600. You
335 may have to use the command:
336 chmod 666 /dev/dsp /dev/mixer /dev/audio
337
3385. If you get "device busy" errors, another program has the
339 sound device open. For example, if using the Enlightenment
340 sound daemon "esd", the "esd" program has the sound device.
341 If using "esd", please RTFM the docs on ESD. For example,
342 esddsp <program> may be used to play files via a non-esd
343 aware program.
344
3456) Ask for help on the sound list or send E-MAIL to the
346 sound driver author/maintainer.
347
3487) Turn on debug in drivers/sound/sound_config.h (DEB, DDB, MDB).
349
3508) If the system reports insufficient DMA memory then you may want to
351 load sound with the "dmabufs=1" option. Or in /etc/conf.modules add
352
353 preinstall sound dmabufs=1
354
355 This makes the sound system allocate its buffers and hang onto them.
356
357 You may also set persistent DMA when building a 2.4.x kernel.
358
359
360Configuring Sound:
361==================
362
363There are several ways of configuring your sound:
364
3651) On the kernel command line (when using the sound driver(s)
366 compiled in the kernel). Check the driver source and
367 documentation for details.
368
3692) On the command line when using insmod or in a bash script
370 using command line calls to load sound.
371
3723) In /etc/modprobe.d/*conf when using modprobe.
373
3744) Via Red Hat's GPL'd /usr/sbin/sndconfig program (text based).
375
3765) Via the OSS soundconf program (with the commercial version
377 of the OSS driver.
378
3796) By just loading the module and let isapnp do everything relevant
380 for you. This works only with a few drivers yet and - of course -
381 only with isapnp hardware.
382
383And I am sure, several other ways.
384
385Anyone want to write a linuxconf module for configuring sound?
386
387
388Module Loading:
389===============
390
391When a sound card is first referenced and sound is modular, the sound system
392will ask for the sound devices to be loaded. Initially it requests that
393the driver for the sound system is loaded. It then will ask for
394sound-slot-0, where 0 is the first sound card. (sound-slot-1 the second and
395so on). Thus you can do
396
397alias sound-slot-0 sb
398
399To load a soundblaster at this point. If the slot loading does not provide
400the desired device - for example a soundblaster does not directly provide
401a midi synth in all cases then it will request "sound-service-0-n" where n
402is
403
404 0 Mixer
405
406 2 MIDI
407
408 3, 4 DSP audio
409
410
411For example, I use the following to load my Soundblaster PCI 128
412(ES 1371) card first, followed by my SoundBlaster Vibra 16 card,
413then by my TV card:
414
415# Load the Soundblaster PCI 128 as /dev/dsp, /dev/dsp1, /dev/mixer
416alias sound-slot-0 es1371
417
418# Load the Soundblaster Vibra 16 as /dev/dsp2, /dev/mixer1
419alias sound-slot-1 sb
420options sb io=0x240 irq=5 dma=1 dma16=5 mpu_io=0x330
421
422# Load the BTTV (TV card) as /dev/mixer2
423alias sound-slot-2 bttv
424alias sound-service-2-0 tvmixer
425
426pre-install bttv modprobe tuner ; modprobe tvmixer
427pre-install tvmixer modprobe msp3400; modprobe tvaudio
428options tuner debug=0 type=8
429options bttv card=0 radio=0 pll=0
430
431
432For More Information (RTFM):
433============================
4341) Information on kernel modules: manual pages for insmod and modprobe.
435
4362) Information on PnP, RTFM manual pages for isapnp.
437
4383) Sound-HOWTO and Sound-Playing-HOWTO.
439
4404) OSS's WWW site at http://www.opensound.com.
441
4425) All the files in Documentation/sound.
443
4446) The comments and code in linux/drivers/sound.
445
4467) The sndconfig and rhsound documentation from Red Hat.
447
4488) The Linux-sound mailing list: sound-list@redhat.com.
449
4509) Enlightenment documentation (for info on esd)
451 http://www.tux.org/~ricdude/EsounD.html.
452
45310) ALSA home page: http://www.alsa-project.org/
454
455
456Contact Information:
457====================
458Wade Hampton: (whampton@staffnet.com)
459
diff --git a/Documentation/sound/oss/MultiSound b/Documentation/sound/oss/MultiSound
deleted file mode 100644
index e4a18bb7f73a..000000000000
--- a/Documentation/sound/oss/MultiSound
+++ /dev/null
@@ -1,1137 +0,0 @@
1#! /bin/sh
2#
3# Turtle Beach MultiSound Driver Notes
4# -- Andrew Veliath <andrewtv@usa.net>
5#
6# Last update: September 10, 1998
7# Corresponding msnd driver: 0.8.3
8#
9# ** This file is a README (top part) and shell archive (bottom part).
10# The corresponding archived utility sources can be unpacked by
11# running `sh MultiSound' (the utilities are only needed for the
12# Pinnacle and Fiji cards). **
13#
14#
15# -=-=- Getting Firmware -=-=-
16# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17#
18# See the section `Obtaining and Creating Firmware Files' in this
19# document for instructions on obtaining the necessary firmware
20# files.
21#
22#
23# Supported Features
24# ~~~~~~~~~~~~~~~~~~
25#
26# Currently, full-duplex digital audio (/dev/dsp only, /dev/audio is
27# not currently available) and mixer functionality (/dev/mixer) are
28# supported (memory mapped digital audio is not yet supported).
29# Digital transfers and monitoring can be done as well if you have
30# the digital daughterboard (see the section on using the S/PDIF port
31# for more information).
32#
33# Support for the Turtle Beach MultiSound Hurricane architecture is
34# composed of the following modules (these can also operate compiled
35# into the kernel):
36#
37# msnd - MultiSound base (requires soundcore)
38#
39# msnd_classic - Base audio/mixer support for Classic, Monetery and
40# Tahiti cards
41#
42# msnd_pinnacle - Base audio/mixer support for Pinnacle and Fiji cards
43#
44#
45# Important Notes - Read Before Using
46# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47#
48# The firmware files are not included (may change in future). You
49# must obtain these images from Turtle Beach (they are included in
50# the MultiSound Development Kits), and place them in /etc/sound for
51# example, and give the full paths in the Linux configuration. If
52# you are compiling in support for the MultiSound driver rather than
53# using it as a module, these firmware files must be accessible
54# during kernel compilation.
55#
56# Please note these files must be binary files, not assembler. See
57# the section later in this document for instructions to obtain these
58# files.
59#
60#
61# Configuring Card Resources
62# ~~~~~~~~~~~~~~~~~~~~~~~~~~
63#
64# ** This section is very important, as your card may not work at all
65# or your machine may crash if you do not do this correctly. **
66#
67# * Classic/Monterey/Tahiti
68#
69# These cards are configured through the driver msnd_classic. You must
70# know the io port, then the driver will select the irq and memory resources
71# on the card. It is up to you to know if these are free locations or now,
72# a conflict can lock the machine up.
73#
74# * Pinnacle/Fiji
75#
76# The Pinnacle and Fiji cards have an extra config port, either
77# 0x250, 0x260 or 0x270. This port can be disabled to have the card
78# configured strictly through PnP, however you lose the ability to
79# access the IDE controller and joystick devices on this card when
80# using PnP. The included pinnaclecfg program in this shell archive
81# can be used to configure the card in non-PnP mode, and in PnP mode
82# you can use isapnptools. These are described briefly here.
83#
84# pinnaclecfg is not required; you can use the msnd_pinnacle module
85# to fully configure the card as well. However, pinnaclecfg can be
86# used to change the resource values of a particular device after the
87# msnd_pinnacle module has been loaded. If you are compiling the
88# driver into the kernel, you must set these values during compile
89# time, however other peripheral resource values can be changed with
90# the pinnaclecfg program after the kernel is loaded.
91#
92#
93# *** PnP mode
94#
95# Use pnpdump to obtain a sample configuration if you can; I was able
96# to obtain one with the command `pnpdump 1 0x203' -- this may vary
97# for you (running pnpdump by itself did not work for me). Then,
98# edit this file and use isapnp to uncomment and set the card values.
99# Use these values when inserting the msnd_pinnacle module. Using
100# this method, you can set the resources for the DSP and the Kurzweil
101# synth (Pinnacle). Since Linux does not directly support PnP
102# devices, you may have difficulty when using the card in PnP mode
103# when it the driver is compiled into the kernel. Using non-PnP mode
104# is preferable in this case.
105#
106# Here is an example mypinnacle.conf for isapnp that sets the card to
107# io base 0x210, irq 5 and mem 0xd8000, and also sets the Kurzweil
108# synth to 0x330 and irq 9 (may need editing for your system):
109#
110# (READPORT 0x0203)
111# (CSN 2)
112# (IDENTIFY *)
113#
114# # DSP
115# (CONFIGURE BVJ0440/-1 (LD 0
116# (INT 0 (IRQ 5 (MODE +E))) (IO 0 (BASE 0x0210)) (MEM 0 (BASE 0x0d8000))
117# (ACT Y)))
118#
119# # Kurzweil Synth (Pinnacle Only)
120# (CONFIGURE BVJ0440/-1 (LD 1
121# (IO 0 (BASE 0x0330)) (INT 0 (IRQ 9 (MODE +E)))
122# (ACT Y)))
123#
124# (WAITFORKEY)
125#
126#
127# *** Non-PnP mode
128#
129# The second way is by running the card in non-PnP mode. This
130# actually has some advantages in that you can access some other
131# devices on the card, such as the joystick and IDE controller. To
132# configure the card, unpack this shell archive and build the
133# pinnaclecfg program. Using this program, you can assign the
134# resource values to the card's devices, or disable the devices. As
135# an alternative to using pinnaclecfg, you can specify many of the
136# configuration values when loading the msnd_pinnacle module (or
137# during kernel configuration when compiling the driver into the
138# kernel).
139#
140# If you specify cfg=0x250 for the msnd_pinnacle module, it
141# automatically configure the card to the given io, irq and memory
142# values using that config port (the config port is jumper selectable
143# on the card to 0x250, 0x260 or 0x270).
144#
145# See the `msnd_pinnacle Additional Options' section below for more
146# information on these parameters (also, if you compile the driver
147# directly into the kernel, these extra parameters can be useful
148# here).
149#
150#
151# ** It is very easy to cause problems in your machine if you choose a
152# resource value which is incorrect. **
153#
154#
155# Examples
156# ~~~~~~~~
157#
158# * MultiSound Classic/Monterey/Tahiti:
159#
160# modprobe soundcore
161# insmod msnd
162# insmod msnd_classic io=0x290 irq=7 mem=0xd0000
163#
164# * MultiSound Pinnacle in PnP mode:
165#
166# modprobe soundcore
167# insmod msnd
168# isapnp mypinnacle.conf
169# insmod msnd_pinnacle io=0x210 irq=5 mem=0xd8000 <-- match mypinnacle.conf values
170#
171# * MultiSound Pinnacle in non-PnP mode (replace 0x250 with your configuration port,
172# one of 0x250, 0x260 or 0x270):
173#
174# insmod soundcore
175# insmod msnd
176# insmod msnd_pinnacle cfg=0x250 io=0x290 irq=5 mem=0xd0000
177#
178# * To use the MPU-compatible Kurzweil synth on the Pinnacle in PnP
179# mode, add the following (assumes you did `isapnp mypinnacle.conf'):
180#
181# insmod sound
182# insmod mpu401 io=0x330 irq=9 <-- match mypinnacle.conf values
183#
184# * To use the MPU-compatible Kurzweil synth on the Pinnacle in non-PnP
185# mode, add the following. Note how we first configure the peripheral's
186# resources, _then_ install a Linux driver for it:
187#
188# insmod sound
189# pinnaclecfg 0x250 mpu 0x330 9
190# insmod mpu401 io=0x330 irq=9
191#
192# -- OR you can use the following sequence without pinnaclecfg in non-PnP mode:
193#
194# insmod soundcore
195# insmod msnd
196# insmod msnd_pinnacle cfg=0x250 io=0x290 irq=5 mem=0xd0000 mpu_io=0x330 mpu_irq=9
197# insmod sound
198# insmod mpu401 io=0x330 irq=9
199#
200# * To setup the joystick port on the Pinnacle in non-PnP mode (though
201# you have to find the actual Linux joystick driver elsewhere), you
202# can use pinnaclecfg:
203#
204# pinnaclecfg 0x250 joystick 0x200
205#
206# -- OR you can configure this using msnd_pinnacle with the following:
207#
208# insmod soundcore
209# insmod msnd
210# insmod msnd_pinnacle cfg=0x250 io=0x290 irq=5 mem=0xd0000 joystick_io=0x200
211#
212#
213# msnd_classic, msnd_pinnacle Required Options
214# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
215#
216# If the following options are not given, the module will not load.
217# Examine the kernel message log for informative error messages.
218# WARNING--probing isn't supported so try to make sure you have the
219# correct shared memory area, otherwise you may experience problems.
220#
221# io I/O base of DSP, e.g. io=0x210
222# irq IRQ number, e.g. irq=5
223# mem Shared memory area, e.g. mem=0xd8000
224#
225#
226# msnd_classic, msnd_pinnacle Additional Options
227# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228#
229# fifosize The digital audio FIFOs, in kilobytes. If not
230# specified, the default will be used. Increasing
231# this value will reduce the chance of a FIFO
232# underflow at the expense of increasing overall
233# latency. For example, fifosize=512 will
234# allocate 512kB read and write FIFOs (1MB total).
235# While this may reduce dropouts, a heavy machine
236# load will undoubtedly starve the FIFO of data
237# and you will eventually get dropouts. One
238# option is to alter the scheduling priority of
239# the playback process, using `nice' or some form
240# of POSIX soft real-time scheduling.
241#
242# calibrate_signal Setting this to one calibrates the ADCs to the
243# signal, zero calibrates to the card (defaults
244# to zero).
245#
246#
247# msnd_pinnacle Additional Options
248# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249#
250# digital Specify digital=1 to enable the S/PDIF input
251# if you have the digital daughterboard
252# adapter. This will enable access to the
253# DIGITAL1 input for the soundcard in the mixer.
254# Some mixer programs might have trouble setting
255# the DIGITAL1 source as an input. If you have
256# trouble, you can try the setdigital.c program
257# at the bottom of this document.
258#
259# cfg Non-PnP configuration port for the Pinnacle
260# and Fiji (typically 0x250, 0x260 or 0x270,
261# depending on the jumper configuration). If
262# this option is omitted, then it is assumed
263# that the card is in PnP mode, and that the
264# specified DSP resource values are already
265# configured with PnP (i.e. it won't attempt to
266# do any sort of configuration).
267#
268# When the Pinnacle is in non-PnP mode, you can use the following
269# options to configure particular devices. If a full specification
270# for a device is not given, then the device is not configured. Note
271# that you still must use a Linux driver for any of these devices
272# once their resources are setup (such as the Linux joystick driver,
273# or the MPU401 driver from OSS for the Kurzweil synth).
274#
275# mpu_io I/O port of MPU (on-board Kurzweil synth)
276# mpu_irq IRQ of MPU (on-board Kurzweil synth)
277# ide_io0 First I/O port of IDE controller
278# ide_io1 Second I/O port of IDE controller
279# ide_irq IRQ IDE controller
280# joystick_io I/O port of joystick
281#
282#
283# Obtaining and Creating Firmware Files
284# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285#
286# For the Classic/Tahiti/Monterey
287# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
288#
289# Download to /tmp and unzip the following file from Turtle Beach:
290#
291# ftp://ftp.voyetra.com/pub/tbs/msndcl/msndvkit.zip
292#
293# When unzipped, unzip the file named MsndFiles.zip. Then copy the
294# following firmware files to /etc/sound (note the file renaming):
295#
296# cp DSPCODE/MSNDINIT.BIN /etc/sound/msndinit.bin
297# cp DSPCODE/MSNDPERM.REB /etc/sound/msndperm.bin
298#
299# When configuring the Linux kernel, specify /etc/sound/msndinit.bin and
300# /etc/sound/msndperm.bin for the two firmware files (Linux kernel
301# versions older than 2.2 do not ask for firmware paths, and are
302# hardcoded to /etc/sound).
303#
304# If you are compiling the driver into the kernel, these files must
305# be accessible during compilation, but will not be needed later.
306# The files must remain, however, if the driver is used as a module.
307#
308#
309# For the Pinnacle/Fiji
310# ~~~~~~~~~~~~~~~~~~~~~
311#
312# Download to /tmp and unzip the following file from Turtle Beach (be
313# sure to use the entire URL; some have had trouble navigating to the
314# URL):
315#
316# ftp://ftp.voyetra.com/pub/tbs/pinn/pnddk100.zip
317#
318# Unpack this shell archive, and run make in the created directory
319# (you need a C compiler and flex to build the utilities). This
320# should give you the executables conv, pinnaclecfg and setdigital.
321# conv is only used temporarily here to create the firmware files,
322# while pinnaclecfg is used to configure the Pinnacle or Fiji card in
323# non-PnP mode, and setdigital can be used to set the S/PDIF input on
324# the mixer (pinnaclecfg and setdigital should be copied to a
325# convenient place, possibly run during system initialization).
326#
327# To generating the firmware files with the `conv' program, we create
328# the binary firmware files by doing the following conversion
329# (assuming the archive unpacked into a directory named PINNDDK):
330#
331# ./conv < PINNDDK/dspcode/pndspini.asm > /etc/sound/pndspini.bin
332# ./conv < PINNDDK/dspcode/pndsperm.asm > /etc/sound/pndsperm.bin
333#
334# The conv (and conv.l) program is not needed after conversion and can
335# be safely deleted. Then, when configuring the Linux kernel, specify
336# /etc/sound/pndspini.bin and /etc/sound/pndsperm.bin for the two
337# firmware files (Linux kernel versions older than 2.2 do not ask for
338# firmware paths, and are hardcoded to /etc/sound).
339#
340# If you are compiling the driver into the kernel, these files must
341# be accessible during compilation, but will not be needed later.
342# The files must remain, however, if the driver is used as a module.
343#
344#
345# Using Digital I/O with the S/PDIF Port
346# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
347#
348# If you have a Pinnacle or Fiji with the digital daughterboard and
349# want to set it as the input source, you can use this program if you
350# have trouble trying to do it with a mixer program (be sure to
351# insert the module with the digital=1 option, or say Y to the option
352# during compiled-in kernel operation). Upon selection of the S/PDIF
353# port, you should be able monitor and record from it.
354#
355# There is something to note about using the S/PDIF port. Digital
356# timing is taken from the digital signal, so if a signal is not
357# connected to the port and it is selected as recording input, you
358# will find PCM playback to be distorted in playback rate. Also,
359# attempting to record at a sampling rate other than the DAT rate may
360# be problematic (i.e. trying to record at 8000Hz when the DAT signal
361# is 44100Hz). If you have a problem with this, set the recording
362# input to analog if you need to record at a rate other than that of
363# the DAT rate.
364#
365#
366# -- Shell archive attached below, just run `sh MultiSound' to extract.
367# Contains Pinnacle/Fiji utilities to convert firmware, configure
368# in non-PnP mode, and select the DIGITAL1 input for the mixer.
369#
370#
371#!/bin/sh
372# This is a shell archive (produced by GNU sharutils 4.2).
373# To extract the files from this archive, save it to some FILE, remove
374# everything before the `!/bin/sh' line above, then type `sh FILE'.
375#
376# Made on 1998-12-04 10:07 EST by <andrewtv@ztransform.velsoft.com>.
377# Source directory was `/home/andrewtv/programming/pinnacle/pinnacle'.
378#
379# Existing files will *not* be overwritten unless `-c' is specified.
380#
381# This shar contains:
382# length mode name
383# ------ ---------- ------------------------------------------
384# 2046 -rw-rw-r-- MultiSound.d/setdigital.c
385# 10235 -rw-rw-r-- MultiSound.d/pinnaclecfg.c
386# 106 -rw-rw-r-- MultiSound.d/Makefile
387# 141 -rw-rw-r-- MultiSound.d/conv.l
388# 1472 -rw-rw-r-- MultiSound.d/msndreset.c
389#
390save_IFS="${IFS}"
391IFS="${IFS}:"
392gettext_dir=FAILED
393locale_dir=FAILED
394first_param="$1"
395for dir in $PATH
396do
397 if test "$gettext_dir" = FAILED && test -f $dir/gettext \
398 && ($dir/gettext --version >/dev/null 2>&1)
399 then
400 set `$dir/gettext --version 2>&1`
401 if test "$3" = GNU
402 then
403 gettext_dir=$dir
404 fi
405 fi
406 if test "$locale_dir" = FAILED && test -f $dir/shar \
407 && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
408 then
409 locale_dir=`$dir/shar --print-text-domain-dir`
410 fi
411done
412IFS="$save_IFS"
413if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
414then
415 echo=echo
416else
417 TEXTDOMAINDIR=$locale_dir
418 export TEXTDOMAINDIR
419 TEXTDOMAIN=sharutils
420 export TEXTDOMAIN
421 echo="$gettext_dir/gettext -s"
422fi
423touch -am 1231235999 $$.touch >/dev/null 2>&1
424if test ! -f 1231235999 && test -f $$.touch; then
425 shar_touch=touch
426else
427 shar_touch=:
428 echo
429 $echo 'WARNING: not restoring timestamps. Consider getting and'
430 $echo "installing GNU \`touch', distributed in GNU File Utilities..."
431 echo
432fi
433rm -f 1231235999 $$.touch
434#
435if mkdir _sh01426; then
436 $echo 'x -' 'creating lock directory'
437else
438 $echo 'failed to create lock directory'
439 exit 1
440fi
441# ============= MultiSound.d/setdigital.c ==============
442if test ! -d 'MultiSound.d'; then
443 $echo 'x -' 'creating directory' 'MultiSound.d'
444 mkdir 'MultiSound.d'
445fi
446if test -f 'MultiSound.d/setdigital.c' && test "$first_param" != -c; then
447 $echo 'x -' SKIPPING 'MultiSound.d/setdigital.c' '(file already exists)'
448else
449 $echo 'x -' extracting 'MultiSound.d/setdigital.c' '(text)'
450 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/setdigital.c' &&
451/*********************************************************************
452X *
453X * setdigital.c - sets the DIGITAL1 input for a mixer
454X *
455X * Copyright (C) 1998 Andrew Veliath
456X *
457X * This program is free software; you can redistribute it and/or modify
458X * it under the terms of the GNU General Public License as published by
459X * the Free Software Foundation; either version 2 of the License, or
460X * (at your option) any later version.
461X *
462X * This program is distributed in the hope that it will be useful,
463X * but WITHOUT ANY WARRANTY; without even the implied warranty of
464X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
465X * GNU General Public License for more details.
466X *
467X * You should have received a copy of the GNU General Public License
468X * along with this program; if not, write to the Free Software
469X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
470X *
471X ********************************************************************/
472X
473#include <stdio.h>
474#include <unistd.h>
475#include <fcntl.h>
476#include <sys/types.h>
477#include <sys/stat.h>
478#include <sys/ioctl.h>
479#include <sys/soundcard.h>
480X
481int main(int argc, char *argv[])
482{
483X int fd;
484X unsigned long recmask, recsrc;
485X
486X if (argc != 2) {
487X fprintf(stderr, "usage: setdigital <mixer device>\n");
488X exit(1);
489X }
490X
491X if ((fd = open(argv[1], O_RDWR)) < 0) {
492X perror(argv[1]);
493X exit(1);
494X }
495X
496X if (ioctl(fd, SOUND_MIXER_READ_RECMASK, &recmask) < 0) {
497X fprintf(stderr, "error: ioctl read recording mask failed\n");
498X perror("ioctl");
499X close(fd);
500X exit(1);
501X }
502X
503X if (!(recmask & SOUND_MASK_DIGITAL1)) {
504X fprintf(stderr, "error: cannot find DIGITAL1 device in mixer\n");
505X close(fd);
506X exit(1);
507X }
508X
509X if (ioctl(fd, SOUND_MIXER_READ_RECSRC, &recsrc) < 0) {
510X fprintf(stderr, "error: ioctl read recording source failed\n");
511X perror("ioctl");
512X close(fd);
513X exit(1);
514X }
515X
516X recsrc |= SOUND_MASK_DIGITAL1;
517X
518X if (ioctl(fd, SOUND_MIXER_WRITE_RECSRC, &recsrc) < 0) {
519X fprintf(stderr, "error: ioctl write recording source failed\n");
520X perror("ioctl");
521X close(fd);
522X exit(1);
523X }
524X
525X close(fd);
526X
527X return 0;
528}
529SHAR_EOF
530 $shar_touch -am 1204092598 'MultiSound.d/setdigital.c' &&
531 chmod 0664 'MultiSound.d/setdigital.c' ||
532 $echo 'restore of' 'MultiSound.d/setdigital.c' 'failed'
533 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
534 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
535 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
536 || $echo 'MultiSound.d/setdigital.c:' 'MD5 check failed'
537e87217fc3e71288102ba41fd81f71ec4 MultiSound.d/setdigital.c
538SHAR_EOF
539 else
540 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/setdigital.c'`"
541 test 2046 -eq "$shar_count" ||
542 $echo 'MultiSound.d/setdigital.c:' 'original size' '2046,' 'current size' "$shar_count!"
543 fi
544fi
545# ============= MultiSound.d/pinnaclecfg.c ==============
546if test -f 'MultiSound.d/pinnaclecfg.c' && test "$first_param" != -c; then
547 $echo 'x -' SKIPPING 'MultiSound.d/pinnaclecfg.c' '(file already exists)'
548else
549 $echo 'x -' extracting 'MultiSound.d/pinnaclecfg.c' '(text)'
550 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/pinnaclecfg.c' &&
551/*********************************************************************
552X *
553X * pinnaclecfg.c - Pinnacle/Fiji Device Configuration Program
554X *
555X * This is for NON-PnP mode only. For PnP mode, use isapnptools.
556X *
557X * This is Linux-specific, and must be run with root permissions.
558X *
559X * Part of the Turtle Beach MultiSound Sound Card Driver for Linux
560X *
561X * Copyright (C) 1998 Andrew Veliath
562X *
563X * This program is free software; you can redistribute it and/or modify
564X * it under the terms of the GNU General Public License as published by
565X * the Free Software Foundation; either version 2 of the License, or
566X * (at your option) any later version.
567X *
568X * This program is distributed in the hope that it will be useful,
569X * but WITHOUT ANY WARRANTY; without even the implied warranty of
570X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
571X * GNU General Public License for more details.
572X *
573X * You should have received a copy of the GNU General Public License
574X * along with this program; if not, write to the Free Software
575X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
576X *
577X ********************************************************************/
578X
579#include <stdio.h>
580#include <stdlib.h>
581#include <string.h>
582#include <errno.h>
583#include <unistd.h>
584#include <asm/io.h>
585#include <asm/types.h>
586X
587#define IREG_LOGDEVICE 0x07
588#define IREG_ACTIVATE 0x30
589#define LD_ACTIVATE 0x01
590#define LD_DISACTIVATE 0x00
591#define IREG_EECONTROL 0x3F
592#define IREG_MEMBASEHI 0x40
593#define IREG_MEMBASELO 0x41
594#define IREG_MEMCONTROL 0x42
595#define IREG_MEMRANGEHI 0x43
596#define IREG_MEMRANGELO 0x44
597#define MEMTYPE_8BIT 0x00
598#define MEMTYPE_16BIT 0x02
599#define MEMTYPE_RANGE 0x00
600#define MEMTYPE_HIADDR 0x01
601#define IREG_IO0_BASEHI 0x60
602#define IREG_IO0_BASELO 0x61
603#define IREG_IO1_BASEHI 0x62
604#define IREG_IO1_BASELO 0x63
605#define IREG_IRQ_NUMBER 0x70
606#define IREG_IRQ_TYPE 0x71
607#define IRQTYPE_HIGH 0x02
608#define IRQTYPE_LOW 0x00
609#define IRQTYPE_LEVEL 0x01
610#define IRQTYPE_EDGE 0x00
611X
612#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
613#define LOBYTE(w) ((BYTE)(w))
614#define MAKEWORD(low,hi) ((WORD)(((BYTE)(low))|(((WORD)((BYTE)(hi)))<<8)))
615X
616typedef __u8 BYTE;
617typedef __u16 USHORT;
618typedef __u16 WORD;
619X
620static int config_port = -1;
621X
622static int msnd_write_cfg(int cfg, int reg, int value)
623{
624X outb(reg, cfg);
625X outb(value, cfg + 1);
626X if (value != inb(cfg + 1)) {
627X fprintf(stderr, "error: msnd_write_cfg: I/O error\n");
628X return -EIO;
629X }
630X return 0;
631}
632X
633static int msnd_read_cfg(int cfg, int reg)
634{
635X outb(reg, cfg);
636X return inb(cfg + 1);
637}
638X
639static int msnd_write_cfg_io0(int cfg, int num, WORD io)
640{
641X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
642X return -EIO;
643X if (msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
644X return -EIO;
645X if (msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
646X return -EIO;
647X return 0;
648}
649X
650static int msnd_read_cfg_io0(int cfg, int num, WORD *io)
651{
652X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
653X return -EIO;
654X
655X *io = MAKEWORD(msnd_read_cfg(cfg, IREG_IO0_BASELO),
656X msnd_read_cfg(cfg, IREG_IO0_BASEHI));
657X
658X return 0;
659}
660X
661static int msnd_write_cfg_io1(int cfg, int num, WORD io)
662{
663X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
664X return -EIO;
665X if (msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
666X return -EIO;
667X if (msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
668X return -EIO;
669X return 0;
670}
671X
672static int msnd_read_cfg_io1(int cfg, int num, WORD *io)
673{
674X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
675X return -EIO;
676X
677X *io = MAKEWORD(msnd_read_cfg(cfg, IREG_IO1_BASELO),
678X msnd_read_cfg(cfg, IREG_IO1_BASEHI));
679X
680X return 0;
681}
682X
683static int msnd_write_cfg_irq(int cfg, int num, WORD irq)
684{
685X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
686X return -EIO;
687X if (msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
688X return -EIO;
689X if (msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
690X return -EIO;
691X return 0;
692}
693X
694static int msnd_read_cfg_irq(int cfg, int num, WORD *irq)
695{
696X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
697X return -EIO;
698X
699X *irq = msnd_read_cfg(cfg, IREG_IRQ_NUMBER);
700X
701X return 0;
702}
703X
704static int msnd_write_cfg_mem(int cfg, int num, int mem)
705{
706X WORD wmem;
707X
708X mem >>= 8;
709X mem &= 0xfff;
710X wmem = (WORD)mem;
711X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
712X return -EIO;
713X if (msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
714X return -EIO;
715X if (msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
716X return -EIO;
717X if (wmem && msnd_write_cfg(cfg, IREG_MEMCONTROL, (MEMTYPE_HIADDR | MEMTYPE_16BIT)))
718X return -EIO;
719X return 0;
720}
721X
722static int msnd_read_cfg_mem(int cfg, int num, int *mem)
723{
724X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
725X return -EIO;
726X
727X *mem = MAKEWORD(msnd_read_cfg(cfg, IREG_MEMBASELO),
728X msnd_read_cfg(cfg, IREG_MEMBASEHI));
729X *mem <<= 8;
730X
731X return 0;
732}
733X
734static int msnd_activate_logical(int cfg, int num)
735{
736X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
737X return -EIO;
738X if (msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
739X return -EIO;
740X return 0;
741}
742X
743static int msnd_write_cfg_logical(int cfg, int num, WORD io0, WORD io1, WORD irq, int mem)
744{
745X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
746X return -EIO;
747X if (msnd_write_cfg_io0(cfg, num, io0))
748X return -EIO;
749X if (msnd_write_cfg_io1(cfg, num, io1))
750X return -EIO;
751X if (msnd_write_cfg_irq(cfg, num, irq))
752X return -EIO;
753X if (msnd_write_cfg_mem(cfg, num, mem))
754X return -EIO;
755X if (msnd_activate_logical(cfg, num))
756X return -EIO;
757X return 0;
758}
759X
760static int msnd_read_cfg_logical(int cfg, int num, WORD *io0, WORD *io1, WORD *irq, int *mem)
761{
762X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
763X return -EIO;
764X if (msnd_read_cfg_io0(cfg, num, io0))
765X return -EIO;
766X if (msnd_read_cfg_io1(cfg, num, io1))
767X return -EIO;
768X if (msnd_read_cfg_irq(cfg, num, irq))
769X return -EIO;
770X if (msnd_read_cfg_mem(cfg, num, mem))
771X return -EIO;
772X return 0;
773}
774X
775static void usage(void)
776{
777X fprintf(stderr,
778X "\n"
779X "pinnaclecfg 1.0\n"
780X "\n"
781X "usage: pinnaclecfg <config port> [device config]\n"
782X "\n"
783X "This is for use with the card in NON-PnP mode only.\n"
784X "\n"
785X "Available devices (not all available for Fiji):\n"
786X "\n"
787X " Device Description\n"
788X " -------------------------------------------------------------------\n"
789X " reset Reset all devices (i.e. disable)\n"
790X " show Display current device configurations\n"
791X "\n"
792X " dsp <io> <irq> <mem> Audio device\n"
793X " mpu <io> <irq> Internal Kurzweil synth\n"
794X " ide <io0> <io1> <irq> On-board IDE controller\n"
795X " joystick <io> Joystick port\n"
796X "\n");
797X exit(1);
798}
799X
800static int cfg_reset(void)
801{
802X int i;
803X
804X for (i = 0; i < 4; ++i)
805X msnd_write_cfg_logical(config_port, i, 0, 0, 0, 0);
806X
807X return 0;
808}
809X
810static int cfg_show(void)
811{
812X int i;
813X int count = 0;
814X
815X for (i = 0; i < 4; ++i) {
816X WORD io0, io1, irq;
817X int mem;
818X msnd_read_cfg_logical(config_port, i, &io0, &io1, &irq, &mem);
819X switch (i) {
820X case 0:
821X if (io0 || irq || mem) {
822X printf("dsp 0x%x %d 0x%x\n", io0, irq, mem);
823X ++count;
824X }
825X break;
826X case 1:
827X if (io0 || irq) {
828X printf("mpu 0x%x %d\n", io0, irq);
829X ++count;
830X }
831X break;
832X case 2:
833X if (io0 || io1 || irq) {
834X printf("ide 0x%x 0x%x %d\n", io0, io1, irq);
835X ++count;
836X }
837X break;
838X case 3:
839X if (io0) {
840X printf("joystick 0x%x\n", io0);
841X ++count;
842X }
843X break;
844X }
845X }
846X
847X if (count == 0)
848X fprintf(stderr, "no devices configured\n");
849X
850X return 0;
851}
852X
853static int cfg_dsp(int argc, char *argv[])
854{
855X int io, irq, mem;
856X
857X if (argc < 3 ||
858X sscanf(argv[0], "0x%x", &io) != 1 ||
859X sscanf(argv[1], "%d", &irq) != 1 ||
860X sscanf(argv[2], "0x%x", &mem) != 1)
861X usage();
862X
863X if (!(io == 0x290 ||
864X io == 0x260 ||
865X io == 0x250 ||
866X io == 0x240 ||
867X io == 0x230 ||
868X io == 0x220 ||
869X io == 0x210 ||
870X io == 0x3e0)) {
871X fprintf(stderr, "error: io must be one of "
872X "210, 220, 230, 240, 250, 260, 290, or 3E0\n");
873X usage();
874X }
875X
876X if (!(irq == 5 ||
877X irq == 7 ||
878X irq == 9 ||
879X irq == 10 ||
880X irq == 11 ||
881X irq == 12)) {
882X fprintf(stderr, "error: irq must be one of "
883X "5, 7, 9, 10, 11 or 12\n");
884X usage();
885X }
886X
887X if (!(mem == 0xb0000 ||
888X mem == 0xc8000 ||
889X mem == 0xd0000 ||
890X mem == 0xd8000 ||
891X mem == 0xe0000 ||
892X mem == 0xe8000)) {
893X fprintf(stderr, "error: mem must be one of "
894X "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
895X usage();
896X }
897X
898X return msnd_write_cfg_logical(config_port, 0, io, 0, irq, mem);
899}
900X
901static int cfg_mpu(int argc, char *argv[])
902{
903X int io, irq;
904X
905X if (argc < 2 ||
906X sscanf(argv[0], "0x%x", &io) != 1 ||
907X sscanf(argv[1], "%d", &irq) != 1)
908X usage();
909X
910X return msnd_write_cfg_logical(config_port, 1, io, 0, irq, 0);
911}
912X
913static int cfg_ide(int argc, char *argv[])
914{
915X int io0, io1, irq;
916X
917X if (argc < 3 ||
918X sscanf(argv[0], "0x%x", &io0) != 1 ||
919X sscanf(argv[0], "0x%x", &io1) != 1 ||
920X sscanf(argv[1], "%d", &irq) != 1)
921X usage();
922X
923X return msnd_write_cfg_logical(config_port, 2, io0, io1, irq, 0);
924}
925X
926static int cfg_joystick(int argc, char *argv[])
927{
928X int io;
929X
930X if (argc < 1 ||
931X sscanf(argv[0], "0x%x", &io) != 1)
932X usage();
933X
934X return msnd_write_cfg_logical(config_port, 3, io, 0, 0, 0);
935}
936X
937int main(int argc, char *argv[])
938{
939X char *device;
940X int rv = 0;
941X
942X --argc; ++argv;
943X
944X if (argc < 2)
945X usage();
946X
947X sscanf(argv[0], "0x%x", &config_port);
948X if (config_port != 0x250 && config_port != 0x260 && config_port != 0x270) {
949X fprintf(stderr, "error: <config port> must be 0x250, 0x260 or 0x270\n");
950X exit(1);
951X }
952X if (ioperm(config_port, 2, 1)) {
953X perror("ioperm");
954X fprintf(stderr, "note: pinnaclecfg must be run as root\n");
955X exit(1);
956X }
957X device = argv[1];
958X
959X argc -= 2; argv += 2;
960X
961X if (strcmp(device, "reset") == 0)
962X rv = cfg_reset();
963X else if (strcmp(device, "show") == 0)
964X rv = cfg_show();
965X else if (strcmp(device, "dsp") == 0)
966X rv = cfg_dsp(argc, argv);
967X else if (strcmp(device, "mpu") == 0)
968X rv = cfg_mpu(argc, argv);
969X else if (strcmp(device, "ide") == 0)
970X rv = cfg_ide(argc, argv);
971X else if (strcmp(device, "joystick") == 0)
972X rv = cfg_joystick(argc, argv);
973X else {
974X fprintf(stderr, "error: unknown device %s\n", device);
975X usage();
976X }
977X
978X if (rv)
979X fprintf(stderr, "error: device configuration failed\n");
980X
981X return 0;
982}
983SHAR_EOF
984 $shar_touch -am 1204092598 'MultiSound.d/pinnaclecfg.c' &&
985 chmod 0664 'MultiSound.d/pinnaclecfg.c' ||
986 $echo 'restore of' 'MultiSound.d/pinnaclecfg.c' 'failed'
987 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
988 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
989 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
990 || $echo 'MultiSound.d/pinnaclecfg.c:' 'MD5 check failed'
991366bdf27f0db767a3c7921d0a6db20fe MultiSound.d/pinnaclecfg.c
992SHAR_EOF
993 else
994 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/pinnaclecfg.c'`"
995 test 10235 -eq "$shar_count" ||
996 $echo 'MultiSound.d/pinnaclecfg.c:' 'original size' '10235,' 'current size' "$shar_count!"
997 fi
998fi
999# ============= MultiSound.d/Makefile ==============
1000if test -f 'MultiSound.d/Makefile' && test "$first_param" != -c; then
1001 $echo 'x -' SKIPPING 'MultiSound.d/Makefile' '(file already exists)'
1002else
1003 $echo 'x -' extracting 'MultiSound.d/Makefile' '(text)'
1004 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/Makefile' &&
1005CC = gcc
1006CFLAGS = -O
1007PROGS = setdigital msndreset pinnaclecfg conv
1008X
1009all: $(PROGS)
1010X
1011clean:
1012X rm -f $(PROGS)
1013SHAR_EOF
1014 $shar_touch -am 1204092398 'MultiSound.d/Makefile' &&
1015 chmod 0664 'MultiSound.d/Makefile' ||
1016 $echo 'restore of' 'MultiSound.d/Makefile' 'failed'
1017 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
1018 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
1019 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
1020 || $echo 'MultiSound.d/Makefile:' 'MD5 check failed'
102176ca8bb44e3882edcf79c97df6c81845 MultiSound.d/Makefile
1022SHAR_EOF
1023 else
1024 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/Makefile'`"
1025 test 106 -eq "$shar_count" ||
1026 $echo 'MultiSound.d/Makefile:' 'original size' '106,' 'current size' "$shar_count!"
1027 fi
1028fi
1029# ============= MultiSound.d/conv.l ==============
1030if test -f 'MultiSound.d/conv.l' && test "$first_param" != -c; then
1031 $echo 'x -' SKIPPING 'MultiSound.d/conv.l' '(file already exists)'
1032else
1033 $echo 'x -' extracting 'MultiSound.d/conv.l' '(text)'
1034 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/conv.l' &&
1035%%
1036[ \n\t,\r]
1037\;.*
1038DB
1039[0-9A-Fa-f]+H { int n; sscanf(yytext, "%xH", &n); printf("%c", n); }
1040%%
1041int yywrap() { return 1; }
1042main() { yylex(); }
1043SHAR_EOF
1044 $shar_touch -am 0828231798 'MultiSound.d/conv.l' &&
1045 chmod 0664 'MultiSound.d/conv.l' ||
1046 $echo 'restore of' 'MultiSound.d/conv.l' 'failed'
1047 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
1048 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
1049 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
1050 || $echo 'MultiSound.d/conv.l:' 'MD5 check failed'
1051d2411fc32cd71a00dcdc1f009e858dd2 MultiSound.d/conv.l
1052SHAR_EOF
1053 else
1054 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/conv.l'`"
1055 test 141 -eq "$shar_count" ||
1056 $echo 'MultiSound.d/conv.l:' 'original size' '141,' 'current size' "$shar_count!"
1057 fi
1058fi
1059# ============= MultiSound.d/msndreset.c ==============
1060if test -f 'MultiSound.d/msndreset.c' && test "$first_param" != -c; then
1061 $echo 'x -' SKIPPING 'MultiSound.d/msndreset.c' '(file already exists)'
1062else
1063 $echo 'x -' extracting 'MultiSound.d/msndreset.c' '(text)'
1064 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/msndreset.c' &&
1065/*********************************************************************
1066X *
1067X * msndreset.c - resets the MultiSound card
1068X *
1069X * Copyright (C) 1998 Andrew Veliath
1070X *
1071X * This program is free software; you can redistribute it and/or modify
1072X * it under the terms of the GNU General Public License as published by
1073X * the Free Software Foundation; either version 2 of the License, or
1074X * (at your option) any later version.
1075X *
1076X * This program is distributed in the hope that it will be useful,
1077X * but WITHOUT ANY WARRANTY; without even the implied warranty of
1078X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1079X * GNU General Public License for more details.
1080X *
1081X * You should have received a copy of the GNU General Public License
1082X * along with this program; if not, write to the Free Software
1083X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1084X *
1085X ********************************************************************/
1086X
1087#include <stdio.h>
1088#include <unistd.h>
1089#include <fcntl.h>
1090#include <sys/types.h>
1091#include <sys/stat.h>
1092#include <sys/ioctl.h>
1093#include <sys/soundcard.h>
1094X
1095int main(int argc, char *argv[])
1096{
1097X int fd;
1098X
1099X if (argc != 2) {
1100X fprintf(stderr, "usage: msndreset <mixer device>\n");
1101X exit(1);
1102X }
1103X
1104X if ((fd = open(argv[1], O_RDWR)) < 0) {
1105X perror(argv[1]);
1106X exit(1);
1107X }
1108X
1109X if (ioctl(fd, SOUND_MIXER_PRIVATE1, 0) < 0) {
1110X fprintf(stderr, "error: msnd ioctl reset failed\n");
1111X perror("ioctl");
1112X close(fd);
1113X exit(1);
1114X }
1115X
1116X close(fd);
1117X
1118X return 0;
1119}
1120SHAR_EOF
1121 $shar_touch -am 1204100698 'MultiSound.d/msndreset.c' &&
1122 chmod 0664 'MultiSound.d/msndreset.c' ||
1123 $echo 'restore of' 'MultiSound.d/msndreset.c' 'failed'
1124 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
1125 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
1126 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
1127 || $echo 'MultiSound.d/msndreset.c:' 'MD5 check failed'
1128c52f876521084e8eb25e12e01dcccb8a MultiSound.d/msndreset.c
1129SHAR_EOF
1130 else
1131 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/msndreset.c'`"
1132 test 1472 -eq "$shar_count" ||
1133 $echo 'MultiSound.d/msndreset.c:' 'original size' '1472,' 'current size' "$shar_count!"
1134 fi
1135fi
1136rm -fr _sh01426
1137exit 0
diff --git a/Documentation/sound/oss/OPL3 b/Documentation/sound/oss/OPL3
deleted file mode 100644
index 2468ff827688..000000000000
--- a/Documentation/sound/oss/OPL3
+++ /dev/null
@@ -1,6 +0,0 @@
1A pure OPL3 card is nice and easy to configure. Simply do
2
3insmod opl3 io=0x388
4
5Change the I/O address in the very unlikely case this card is differently
6configured
diff --git a/Documentation/sound/oss/Opti b/Documentation/sound/oss/Opti
deleted file mode 100644
index 4cd5d9ab3580..000000000000
--- a/Documentation/sound/oss/Opti
+++ /dev/null
@@ -1,218 +0,0 @@
1Support for the OPTi 82C931 chip
2--------------------------------
3Note: parts of this README file apply also to other
4cards that use the mad16 driver.
5
6Some items in this README file are based on features
7added to the sound driver after Linux-2.1.91 was out.
8By the time of writing this I do not know which official
9kernel release will include these features.
10Please do not report inconsistencies on older Linux
11kernels.
12
13The OPTi 82C931 is supported in its non-PnP mode.
14Usually you do not need to set jumpers, etc. The sound driver
15will check the card status and if it is required it will
16force the card into a mode in which it can be programmed.
17
18If you have another OS installed on your computer it is recommended
19that Linux and the other OS use the same resources.
20
21Also, it is recommended that resources specified in /etc/modprobe.d/*.conf
22and resources specified in /etc/isapnp.conf agree.
23
24Compiling the sound driver
25--------------------------
26I highly recommend that you build a modularized sound driver.
27This document does not cover a sound-driver which is built in
28the kernel.
29
30Sound card support should be enabled as a module (chose m).
31Answer 'm' for these items:
32 Generic OPL2/OPL3 FM synthesizer support (CONFIG_SOUND_ADLIB)
33 Microsoft Sound System support (CONFIG_SOUND_MSS)
34 Support for OPTi MAD16 and/or Mozart based cards (CONFIG_SOUND_MAD16)
35 FM synthesizer (YM3812/OPL-3) support (CONFIG_SOUND_YM3812)
36
37The configuration menu may ask for addresses, IRQ lines or DMA
38channels. If the card is used as a module the module loading
39options will override these values.
40
41For the OPTi 931 you can answer 'n' to:
42 Support MIDI in older MAD16 based cards (requires SB) (CONFIG_SOUND_MAD16_OLDCARD)
43If you do need MIDI support in a Mozart or C928 based card you
44need to answer 'm' to the above question. In that case you will
45also need to answer 'm' to:
46 '100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support' (CONFIG_SOUND_SB)
47
48Go on and compile your kernel and modules. Install the modules. Run depmod -a.
49
50Using isapnptools
51-----------------
52In most systems with a PnP BIOS you do not need to use isapnp. The
53initialization provided by the BIOS is sufficient for the driver
54to pick up the card and continue initialization.
55
56If that fails, or if you have other PnP cards, you need to use isapnp
57to initialize the card.
58This was tested with isapnptools-1.11 but I recommend that you use
59isapnptools-1.13 (or newer). Run pnpdump to dump the information
60about your PnP cards. Then edit the resulting file and select
61the options of your choice. This file is normally installed as
62/etc/isapnp.conf.
63
64The driver has one limitation with respect to I/O port resources:
65IO3 base must be 0x0E0C. Although isapnp allows other ports, this
66address is hard-coded into the driver.
67
68Using kmod and autoloading the sound driver
69-------------------------------------------
70Config files in '/etc/modprobe.d/' are used as below:
71
72alias mixer0 mad16
73alias audio0 mad16
74alias midi0 mad16
75alias synth0 opl3
76options sb mad16=1
77options mad16 irq=10 dma=0 dma16=1 io=0x530 joystick=1 cdtype=0
78options opl3 io=0x388
79install mad16 /sbin/modprobe -i mad16 && /sbin/ad1848_mixer_reroute 14 8 15 3 16 6
80
81If you have an MPU daughtercard or onboard MPU you will want to add to the
82"options mad16" line - eg
83
84options mad16 irq=5 dma=0 dma16=3 io=0x530 mpu_io=0x330 mpu_irq=9
85
86To set the I/O and IRQ of the MPU.
87
88
89Explain:
90
91alias mixer0 mad16
92alias audio0 mad16
93alias midi0 mad16
94alias synth0 opl3
95
96When any sound device is opened the kernel requests auto-loading
97of char-major-14. There is a built-in alias that translates this
98request to loading the main sound module.
99
100The sound module in its turn will request loading of a sub-driver
101for mixer, audio, midi or synthesizer device. The first 3 are
102supported by the mad16 driver. The synth device is supported
103by the opl3 driver.
104
105There is currently no way to autoload the sound device driver
106if more than one card is installed.
107
108options sb mad16=1
109
110This is left for historical reasons. If you enable the
111config option 'Support MIDI in older MAD16 based cards (requires SB)'
112or if you use an older mad16 driver it will force loading of the
113SoundBlaster driver. This option tells the SB driver not to look
114for a SB card but to wait for the mad16 driver.
115
116options mad16 irq=10 dma=0 dma16=1 io=0x530 joystick=1 cdtype=0
117options opl3 io=0x388
118
119post-install mad16 /sbin/ad1848_mixer_reroute 14 8 15 3 16 6
120
121This sets resources and options for the mad16 and opl3 drivers.
122I use two DMA channels (only one is required) to enable full duplex.
123joystick=1 enables the joystick port. cdtype=0 disables the cd port.
124You can also set mpu_io and mpu_irq in the mad16 options for the
125uart401 driver.
126
127This tells modprobe to run /sbin/ad1848_mixer_reroute after
128mad16 is successfully loaded and initialized. The source
129for ad1848_mixer_reroute is appended to the end of this readme
130file. It is impossible for the sound driver to know the actual
131connections to the mixer. The 3 inputs intended for cd, synth
132and line-in are mapped to the generic inputs line1, line2 and
133line3. This program reroutes these mixer channels to their
134right names (note the right mapping depends on the actual sound
135card that you use).
136The numeric parameters mean:
137 14=line1 8=cd - reroute line1 to the CD input.
138 15=line2 3=synth - reroute line2 to the synthesizer input.
139 16=line3 6=line - reroute line3 to the line input.
140For reference on other input names look at the file
141/usr/include/linux/soundcard.h.
142
143Using a joystick
144-----------------
145You must enable a joystick in the mad16 options. (also
146in /etc/isapnp.conf if you use it).
147Tested with regular analog joysticks.
148
149A CDROM drive connected to the sound card
150-----------------------------------------
151The 82C931 chip has support only for secondary ATAPI cdrom.
152(cdtype=8). Loading the mad16 driver resets the C931 chip
153and if a cdrom was already mounted it may cause a complete
154system hang. Do not use the sound card if you have an alternative.
155If you do use the sound card it is important that you load
156the mad16 driver (use "modprobe mad16" to prevent auto-unloading)
157before the cdrom is accessed the first time.
158
159Using the sound driver built-in to the kernel may help here, but...
160Most new systems have a PnP BIOS and also two IDE controllers.
161The IDE controller on the sound card may be needed only on older
162systems (which have only one IDE controller) but these systems
163also do not have a PnP BIOS - requiring isapnptools and a modularized
164driver.
165
166Known problems
167--------------
1681. See the section on "A CDROM drive connected to the sound card".
169
1702. On my system the codec cannot capture companded sound samples.
171 (eg., recording from /dev/audio). When any companded capture is
172 requested I get stereo-16 bit samples instead. Playback of
173 companded samples works well. Apparently this problem is not common
174 to all C931 based cards. I do not know how to identify cards that
175 have this problem.
176
177Source for ad1848_mixer_reroute.c
178---------------------------------
179#include <stdio.h>
180#include <fcntl.h>
181#include <linux/soundcard.h>
182
183static char *mixer_names[SOUND_MIXER_NRDEVICES] =
184 SOUND_DEVICE_LABELS;
185
186int
187main(int argc, char **argv) {
188 int val, from, to;
189 int i, fd;
190
191 fd = open("/dev/mixer", O_RDWR);
192 if(fd < 0) {
193 perror("/dev/mixer");
194 return 1;
195 }
196
197 for(i = 2; i < argc; i += 2) {
198 from = atoi(argv[i-1]);
199 to = atoi(argv[i]);
200
201 if(to == SOUND_MIXER_NONE)
202 fprintf(stderr, "%s: turning off mixer %s\n",
203 argv[0], mixer_names[to]);
204 else
205 fprintf(stderr, "%s: rerouting mixer %s to %s\n",
206 argv[0], mixer_names[from], mixer_names[to]);
207
208 val = from << 8 | to;
209
210 if(ioctl(fd, SOUND_MIXER_PRIVATE2, &val)) {
211 perror("AD1848 mixer reroute");
212 return 1;
213 }
214 }
215
216 return 0;
217}
218
diff --git a/Documentation/sound/oss/PAS16 b/Documentation/sound/oss/PAS16
deleted file mode 100644
index 5c27229eec8c..000000000000
--- a/Documentation/sound/oss/PAS16
+++ /dev/null
@@ -1,162 +0,0 @@
1Pro Audio Spectrum 16 for 2.3.99 and later
2=========================================
3by Thomas Molina (tmolina@home.com)
4last modified 3 Mar 2001
5Acknowledgement to Axel Boldt (boldt@math.ucsb.edu) for stuff taken
6from Configure.help, Riccardo Facchetti for stuff from README.OSS,
7and others whose names I could not find.
8
9This documentation is relevant for the PAS16 driver (pas2_card.c and
10friends) under kernel version 2.3.99 and later. If you are
11unfamiliar with configuring sound under Linux, please read the
12Sound-HOWTO, Documentation/sound/oss/Introduction and other
13relevant docs first.
14
15The following information is relevant information from README.OSS
16and legacy docs for the Pro Audio Spectrum 16 (PAS16):
17==================================================================
18
19The pas2_card.c driver supports the following cards --
20Pro Audio Spectrum 16 (PAS16) and compatibles:
21 Pro Audio Spectrum 16
22 Pro Audio Studio 16
23 Logitech Sound Man 16
24 NOTE! The original Pro Audio Spectrum as well as the PAS+ are not
25 and will not be supported by the driver.
26
27The sound driver configuration dialog
28-------------------------------------
29
30Sound configuration starts by making some yes/no questions. Be careful
31when answering to these questions since answering y to a question may
32prevent some later ones from being asked. For example don't answer y to
33the question about (PAS16) if you don't really have a PAS16. Sound
34configuration may also be made modular by answering m to configuration
35options presented.
36
37Note also that all questions may not be asked. The configuration program
38may disable some questions depending on the earlier choices. It may also
39select some options automatically as well.
40
41 "ProAudioSpectrum 16 support",
42 - Answer 'y'_ONLY_ if you have a Pro Audio Spectrum _16_,
43 Pro Audio Studio 16 or Logitech SoundMan 16 (be sure that
44 you read the above list correctly). Don't answer 'y' if you
45 have some other card made by Media Vision or Logitech since they
46 are not PAS16 compatible.
47 NOTE! Since 3.5-beta10 you need to enable SB support (next question)
48 if you want to use the SB emulation of PAS16. It's also possible to
49 the emulation if you want to use a true SB card together with PAS16
50 (there is another question about this that is asked later).
51
52 "Generic OPL2/OPL3 FM synthesizer support",
53 - Answer 'y' if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
54 The PAS16 has an OPL3-compatible FM chip.
55
56With PAS16 you can use two audio device files at the same time. /dev/dsp (and
57/dev/audio) is connected to the 8/16 bit native codec and the /dev/dsp1 (and
58/dev/audio1) is connected to the SB emulation (8 bit mono only).
59
60
61The new stuff for 2.3.99 and later
62============================================================================
63The following configuration options are relevant to configuring the PAS16:
64
65Sound card support
66CONFIG_SOUND
67 If you have a sound card in your computer, i.e. if it can say more
68 than an occasional beep, say Y. Be sure to have all the information
69 about your sound card and its configuration down (I/O port,
70 interrupt and DMA channel), because you will be asked for it.
71
72 You want to read the Sound-HOWTO, available from
73 http://www.tldp.org/docs.html#howto . General information
74 about the modular sound system is contained in the files
75 Documentation/sound/oss/Introduction. The file
76 Documentation/sound/oss/README.OSS contains some slightly outdated but
77 still useful information as well.
78
79OSS sound modules
80CONFIG_SOUND_OSS
81 OSS is the Open Sound System suite of sound card drivers. They make
82 sound programming easier since they provide a common API. Say Y or M
83 here (the module will be called sound.o) if you haven't found a
84 driver for your sound card above, then pick your driver from the
85 list below.
86
87Persistent DMA buffers
88CONFIG_SOUND_DMAP
89 Linux can often have problems allocating DMA buffers for ISA sound
90 cards on machines with more than 16MB of RAM. This is because ISA
91 DMA buffers must exist below the 16MB boundary and it is quite
92 possible that a large enough free block in this region cannot be
93 found after the machine has been running for a while. If you say Y
94 here the DMA buffers (64Kb) will be allocated at boot time and kept
95 until the shutdown. This option is only useful if you said Y to
96 "OSS sound modules", above. If you said M to "OSS sound modules"
97 then you can get the persistent DMA buffer functionality by passing
98 the command-line argument "dmabuf=1" to the sound.o module.
99
100 Say y here for PAS16.
101
102ProAudioSpectrum 16 support
103CONFIG_SOUND_PAS
104 Answer Y only if you have a Pro Audio Spectrum 16, ProAudio Studio
105 16 or Logitech SoundMan 16 sound card. Don't answer Y if you have
106 some other card made by Media Vision or Logitech since they are not
107 PAS16 compatible. It is not necessary to enable the separate
108 Sound Blaster support; it is included in the PAS driver.
109
110 If you compile the driver into the kernel, you have to add
111 "pas2=<io>,<irq>,<dma>,<dma2>,<sbio>,<sbirq>,<sbdma>,<sbdma2>
112 to the kernel command line.
113
114FM Synthesizer (YM3812/OPL-3) support
115CONFIG_SOUND_YM3812
116 Answer Y if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
117 Answering Y is usually a safe and recommended choice, however some
118 cards may have software (TSR) FM emulation. Enabling FM support with
119 these cards may cause trouble (I don't currently know of any such
120 cards, however).
121 Please read the file Documentation/sound/oss/OPL3 if your card has an
122 OPL3 chip.
123 If you compile the driver into the kernel, you have to add
124 "opl3=<io>" to the kernel command line.
125
126 If you compile your drivers into the kernel, you MUST configure
127 OPL3 support as a module for PAS16 support to work properly.
128 You can then get OPL3 functionality by issuing the command:
129 insmod opl3
130 In addition, you must either add the following line to
131 /etc/modprobe.d/*.conf:
132 options opl3 io=0x388
133 or else add the following line to /etc/lilo.conf:
134 opl3=0x388
135
136
137EXAMPLES
138===================================================================
139To use the PAS16 in my computer I have enabled the following sound
140configuration options:
141
142CONFIG_SOUND=y
143CONFIG_SOUND_OSS=y
144CONFIG_SOUND_TRACEINIT=y
145CONFIG_SOUND_DMAP=y
146CONFIG_SOUND_PAS=y
147CONFIG_SOUND_SB=n
148CONFIG_SOUND_YM3812=m
149
150I have also included the following append line in /etc/lilo.conf:
151append="pas2=0x388,10,3,-1,0x220,5,1,-1 sb=0x220,5,1,-1 opl3=0x388"
152
153The io address of 0x388 is default configuration on the PAS16. The
154irq of 10 and dma of 3 may not match your installation. The above
155configuration enables PAS16, 8-bit Soundblaster and OPL3
156functionality. If Soundblaster functionality is not desired, the
157following line would be appropriate:
158append="pas2=0x388,10,3,-1,0,-1,-1,-1 opl3=0x388"
159
160If sound is built totally modular, the above options may be
161specified in /etc/modprobe.d/*.conf for pas2, sb and opl3
162respectively.
diff --git a/Documentation/sound/oss/PSS b/Documentation/sound/oss/PSS
deleted file mode 100644
index 187b9525e1f6..000000000000
--- a/Documentation/sound/oss/PSS
+++ /dev/null
@@ -1,41 +0,0 @@
1The PSS cards and other ECHO based cards provide an onboard DSP with
2downloadable programs and also has an AD1848 "Microsoft Sound System"
3device. The PSS driver enables MSS and MPU401 modes of the card. SB
4is not enabled since it doesn't work concurrently with MSS.
5
6If you build this driver as a module then the driver takes the following
7parameters
8
9pss_io. The I/O base the PSS card is configured at (normally 0x220
10 or 0x240)
11
12mss_io The base address of the Microsoft Sound System interface.
13 This is normally 0x530, but may be 0x604 or other addresses.
14
15mss_irq The interrupt assigned to the Microsoft Sound System
16 emulation. IRQ's 3,5,7,9,10,11 and 12 are available. If you
17 get IRQ errors be sure to check the interrupt is set to
18 "ISA/Legacy" in the BIOS on modern machines.
19
20mss_dma The DMA channel used by the Microsoft Sound System.
21 This can be 0, 1, or 3. DMA 0 is not available on older
22 machines and will cause a crash on them.
23
24mpu_io The MPU emulation base address. This sets the base of the
25 synthesizer. It is typically 0x330 but can be altered.
26
27mpu_irq The interrupt to use for the synthesizer. It must differ
28 from the IRQ used by the Microsoft Sound System port.
29
30
31The mpu_io/mpu_irq fields are optional. If they are not specified the
32synthesizer parts are not configured.
33
34When the module is loaded it looks for a file called
35/etc/sound/pss_synth. This is the firmware file from the DOS install disks.
36This fil holds a general MIDI emulation. The file expected is called
37genmidi.ld on newer DOS driver install disks and synth.ld on older ones.
38
39You can also load alternative DSP algorithms into the card if you wish. One
40alternative driver can be found at http://www.mpg123.de/
41
diff --git a/Documentation/sound/oss/PSS-updates b/Documentation/sound/oss/PSS-updates
deleted file mode 100644
index 11914a1dc7e7..000000000000
--- a/Documentation/sound/oss/PSS-updates
+++ /dev/null
@@ -1,88 +0,0 @@
1 This file contains notes for users of PSS sound cards who wish to use the
2newly added features of the newest version of this driver.
3
4 The major enhancements present in this new revision of this driver is the
5addition of two new module parameters that allow you to take full advantage of
6all the features present on your PSS sound card. These features include the
7ability to enable both the builtin CDROM and joystick ports.
8
9pss_enable_joystick
10
11 This parameter is basically a flag. A 0 will leave the joystick port
12disabled, while a non-zero value would enable the joystick port. The default
13setting is pss_enable_joystick=0 as this keeps this driver fully compatible
14with systems that were using previous versions of this driver. If you wish to
15enable the joystick port you will have to add pss_enable_joystick=1 as an
16argument to the driver. To actually use the joystick port you will then have
17to load the joystick driver itself. Just remember to load the joystick driver
18AFTER the pss sound driver.
19
20pss_cdrom_port
21
22 This parameter takes a port address as its parameter. Any available port
23address can be specified to enable the CDROM port, except for 0x0 and -1 as
24these values would leave the port disabled. Like the joystick port, the cdrom
25port will require that an appropriate CDROM driver be loaded before you can make
26use of the newly enabled CDROM port. Like the joystick port option above,
27remember to load the CDROM driver AFTER the pss sound driver. While it may
28differ on some PSS sound cards, all the PSS sound cards that I have seen have a
29builtin Wearnes CDROM port. If this is the case with your PSS sound card you
30should load aztcd with the appropriate port option that matches the port you
31assigned to the CDROM port when you loaded your pss sound driver. (ex.
32modprobe pss pss_cdrom_port=0x340 && modprobe aztcd aztcd=0x340) The default
33setting of this parameter leaves the CDROM port disabled to maintain full
34compatibility with systems using previous versions of this driver.
35
36 Other options have also been added for the added convenience and utility
37of the user. These options are only available if this driver is loaded as a
38module.
39
40pss_no_sound
41
42 This module parameter is a flag that can be used to tell the driver to
43just configure non-sound components. 0 configures all components, a non-0
44value will only attempt to configure the CDROM and joystick ports. This
45parameter can be used by a user who only wished to use the builtin joystick
46and/or CDROM port(s) of his PSS sound card. If this driver is loaded with this
47parameter and with the parameter below set to true then a user can safely unload
48this driver with the following command "rmmod pss && rmmod ad1848 && rmmod
49mpu401 && rmmod sound && rmmod soundcore" and retain the full functionality of
50his CDROM and/or joystick port(s) while gaining back the memory previously used
51by the sound drivers. This default setting of this parameter is 0 to retain
52full behavioral compatibility with previous versions of this driver.
53
54pss_keep_settings
55
56 This parameter can be used to specify whether you want the driver to reset
57all emulations whenever its unloaded. This can be useful for those who are
58sharing resources (io ports, IRQ's, DMA's) between different ISA cards. This
59flag can also be useful in that future versions of this driver may reset all
60emulations by default on the driver's unloading (as it probably should), so
61specifying it now will ensure that all future versions of this driver will
62continue to work as expected. The default value of this parameter is 1 to
63retain full behavioral compatibility with previous versions of this driver.
64
65pss_firmware
66
67 This parameter can be used to specify the file containing the firmware
68code so that a user could tell the driver where that file is located instead
69of having to put it in a predefined location with a predefined name. The
70default setting of this parameter is "/etc/sound/pss_synth" as this was the
71path and filename the hardcoded value in the previous versions of this driver.
72
73Examples:
74
75# Normal PSS sound card system, loading of drivers.
76# Should be specified in an rc file (ex. Slackware uses /etc/rc.d/rc.modules).
77
78/sbin/modprobe pss pss_io=0x220 mpu_io=0x338 mpu_irq=9 mss_io=0x530 mss_irq=10 mss_dma=1 pss_cdrom_port=0x340 pss_enable_joystick=1
79/sbin/modprobe aztcd aztcd=0x340
80/sbin/modprobe joystick
81
82# System using the PSS sound card just for its CDROM and joystick ports.
83# Should be specified in an rc file (ex. Slackware uses /etc/rc.d/rc.modules).
84
85/sbin/modprobe pss pss_io=0x220 pss_cdrom_port=0x340 pss_enable_joystick=1 pss_no_sound=1
86/sbin/rmmod pss && /sbin/rmmod ad1848 && /sbin/rmmod mpu401 && /sbin/rmmod sound && /sbin/rmmod soundcore # This line not needed, but saves memory.
87/sbin/modprobe aztcd aztcd=0x340
88/sbin/modprobe joystick
diff --git a/Documentation/sound/oss/README.OSS b/Documentation/sound/oss/README.OSS
deleted file mode 100644
index a085ea3611a1..000000000000
--- a/Documentation/sound/oss/README.OSS
+++ /dev/null
@@ -1,1455 +0,0 @@
1Introduction
2------------
3
4This file is a collection of all the old Readme files distributed with
5OSS/Lite by Hannu Savolainen. Since the new Linux sound driver is founded
6on it I think these information may still be interesting for users that
7have to configure their sound system.
8
9Be warned: Alan Cox is the current maintainer of the Linux sound driver so if
10you have problems with it, please contact him or the current device-specific
11driver maintainer (e.g. for aedsp16 specific problems contact me). If you have
12patches, contributions or suggestions send them to Alan: I'm sure they are
13welcome.
14
15In this document you will find a lot of references about OSS/Lite or ossfree:
16they are gone forever. Keeping this in mind and with a grain of salt this
17document can be still interesting and very helpful.
18
19[ File edited 17.01.1999 - Riccardo Facchetti ]
20[ Edited miroSOUND section 19.04.2001 - Robert Siemer ]
21
22OSS/Free version 3.8 release notes
23----------------------------------
24
25Please read the SOUND-HOWTO (available from sunsite.unc.edu and other Linux FTP
26sites). It gives instructions about using sound with Linux. It's bit out of
27date but still very useful. Information about bug fixes and such things
28is available from the web page (see above).
29
30Please check http://www.opensound.com/pguide for more info about programming
31with OSS API.
32
33 ====================================================
34- THIS VERSION ____REQUIRES____ Linux 2.1.57 OR LATER.
35 ====================================================
36
37Packages "snd-util-3.8.tar.gz" and "snd-data-0.1.tar.Z"
38contain useful utilities to be used with this driver.
39See http://www.opensound.com/ossfree/ for
40download instructions.
41
42If you are looking for the installation instructions, please
43look forward into this document.
44
45Supported sound cards
46---------------------
47
48See below.
49
50Contributors
51------------
52
53This driver contains code by several contributors. In addition several other
54persons have given useful suggestions. The following is a list of major
55contributors. (I could have forgotten some names.)
56
57 Craig Metz 1/2 of the PAS16 Mixer and PCM support
58 Rob Hooft Volume computation algorithm for the FM synth.
59 Mika Liljeberg uLaw encoding and decoding routines
60 Jeff Tranter Linux SOUND HOWTO document
61 Greg Lee Volume computation algorithm for the GUS and
62 lots of valuable suggestions.
63 Andy Warner ISC port
64 Jim Lowe,
65 Amancio Hasty Jr FreeBSD/NetBSD port
66 Anders Baekgaard Bug hunting and valuable suggestions.
67 Joerg Schubert SB16 DSP support (initial version).
68 Andrew Robinson Improvements to the GUS driver
69 Megens SA MIDI recording for SB and SB Pro (initial version).
70 Mikael Nordqvist Linear volume support for GUS and
71 nonblocking /dev/sequencer.
72 Ian Hartas SVR4.2 port
73 Markus Aroharju and
74 Risto Kankkunen Major contributions to the mixer support
75 of GUS v3.7.
76 Hunyue Yau Mixer support for SG NX Pro.
77 Marc Hoffman PSS support (initial version).
78 Rainer Vranken Initialization for Jazz16 (initial version).
79 Peter Trattler Initial version of loadable module support for Linux.
80 JRA Gibson 16 bit mode for Jazz16 (initial version)
81 Davor Jadrijevic MAD16 support (initial version)
82 Gregor Hoffleit Mozart support (initial version)
83 Riccardo Facchetti Audio Excel DSP 16 (aedsp16) support
84 James Hightower Spotting a tiny but important bug in CS423x support.
85 Denis Sablic OPTi 82C924 specific enhancements (non PnP mode)
86 Tim MacKenzie Full duplex support for OPTi 82C930.
87
88 Please look at lowlevel/README for more contributors.
89
90There are probably many other names missing. If you have sent me some
91patches and your name is not in the above list, please inform me.
92
93Sending your contributions or patches
94-------------------------------------
95
96First of all it's highly recommended to contact me before sending anything
97or before even starting to do any work. Tell me what you suggest to be
98changed or what you have planned to do. Also ensure you are using the
99very latest (development) version of OSS/Free since the change may already be
100implemented there. In general it's a major waste of time to try to improve a
101several months old version. Information about the latest version can be found
102from http://www.opensound.com/ossfree. In general there is no point in
103sending me patches relative to production kernels.
104
105Sponsors etc.
106-------------
107
108The following companies have greatly helped development of this driver
109in form of a free copy of their product:
110
111Novell, Inc. UnixWare personal edition + SDK
112The Santa Cruz Operation, Inc. A SCO OpenServer + SDK
113Ensoniq Corp, a SoundScape card and extensive amount of assistance
114MediaTrix Peripherals Inc, a AudioTrix Pro card + SDK
115Acer, Inc. a pair of AcerMagic S23 cards.
116
117In addition the following companies have provided me sufficient amount
118of technical information at least some of their products (free or $$$):
119
120Advanced Gravis Computer Technology Ltd.
121Media Vision Inc.
122Analog Devices Inc.
123Logitech Inc.
124Aztech Labs Inc.
125Crystal Semiconductor Corporation,
126Integrated Circuit Systems Inc.
127OAK Technology
128OPTi
129Turtle Beach
130miro
131Ad Lib Inc. ($$)
132Music Quest Inc. ($$)
133Creative Labs ($$$)
134
135If you have some problems
136=========================
137
138Read the sound HOWTO (sunsite.unc.edu:/pub/Linux/docs/...?).
139Also look at the home page (http://www.opensound.com/ossfree). It may
140contain info about some recent bug fixes.
141
142It's likely that you have some problems when trying to use the sound driver
143first time. Sound cards don't have standard configuration so there are no
144good default configuration to use. Please try to use same I/O, DMA and IRQ
145values for the sound card than with DOS.
146
147If you get an error message when trying to use the driver, please look
148at /var/adm/messages for more verbose error message.
149
150
151The following errors are likely with /dev/dsp and /dev/audio.
152
153 - "No such device or address".
154 This error indicates that there are no suitable hardware for the
155 device file or the sound driver has been compiled without support for
156 this particular device. For example /dev/audio and /dev/dsp will not
157 work if "digitized voice support" was not enabled during "make config".
158
159 - "Device or resource busy". Probably the IRQ (or DMA) channel
160 required by the sound card is in use by some other device/driver.
161
162 - "I/O error". Almost certainly (99%) it's an IRQ or DMA conflict.
163 Look at the kernel messages in /var/adm/notice for more info.
164
165 - "Invalid argument". The application is calling ioctl()
166 with impossible parameters. Check that the application is
167 for sound driver version 2.X or later.
168
169Linux installation
170==================
171
172IMPORTANT! Read this if you are installing a separately
173 distributed version of this driver.
174
175 Check that your kernel version works with this
176 release of the driver (see Readme). Also verify
177 that your current kernel version doesn't have more
178 recent sound driver version than this one. IT'S HIGHLY
179 RECOMMENDED THAT YOU USE THE SOUND DRIVER VERSION THAT
180 IS DISTRIBUTED WITH KERNEL SOURCES.
181
182- When installing separately distributed sound driver you should first
183 read the above notice. Then try to find proper directory where and how
184 to install the driver sources. You should not try to install a separately
185 distributed driver version if you are not able to find the proper way
186 yourself (in this case use the version that is distributed with kernel
187 sources). Remove old version of linux/drivers/sound directory before
188 installing new files.
189
190- To build the device files you need to run the enclosed shell script
191 (see below). You need to do this only when installing sound driver
192 first time or when upgrading to much recent version than the earlier
193 one.
194
195- Configure and compile Linux as normally (remember to include the
196 sound support during "make config"). Please refer to kernel documentation
197 for instructions about configuring and compiling kernel. File Readme.cards
198 contains card specific instructions for configuring this driver for
199 use with various sound cards.
200
201Boot time configuration (using lilo and insmod)
202-----------------------------------------------
203
204This information has been removed. Too many users didn't believe
205that it's really not necessary to use this method. Please look at
206Readme of sound driver version 3.0.1 if you still want to use this method.
207
208Problems
209--------
210
211Common error messages:
212
213- /dev/???????: No such file or directory.
214Run the script at the end of this file.
215
216- /dev/???????: No such device.
217You are not running kernel which contains the sound driver. When using
218modularized sound driver this error means that the sound driver is not
219loaded.
220
221- /dev/????: No such device or address.
222Sound driver didn't detect suitable card when initializing. Please look at
223Readme.cards for info about configuring the driver with your card. Also
224check for possible boot (insmod) time error messages in /var/adm/messages.
225
226- Other messages or problems
227Please check http://www.opensound.com/ossfree for more info.
228
229Configuring version 3.8 (for Linux) with some common sound cards
230================================================================
231
232This document describes configuring sound cards with the freeware version of
233Open Sound Systems (OSS/Free). Information about the commercial version
234(OSS/Linux) and its configuration is available from
235http://www.opensound.com/linux.html. Information presented here is
236not valid for OSS/Linux.
237
238If you are unsure about how to configure OSS/Free
239you can download the free evaluation version of OSS/Linux from the above
240address. There is a chance that it can autodetect your sound card. In this case
241you can use the information included in soundon.log when configuring OSS/Free.
242
243
244IMPORTANT! This document covers only cards that were "known" when
245 this driver version was released. Please look at
246 http://www.opensound.com/ossfree for info about
247 cards introduced recently.
248
249 When configuring the sound driver, you should carefully
250 check each sound configuration option (particularly
251 "Support for /dev/dsp and /dev/audio"). The default values
252 offered by these programs are not necessarily valid.
253
254
255THE BIGGEST MISTAKES YOU CAN MAKE
256=================================
257
2581. Assuming that the card is Sound Blaster compatible when it's not.
259--------------------------------------------------------------------
260
261The number one mistake is to assume that your card is compatible with
262Sound Blaster. Only the cards made by Creative Technology or which have
263one or more chips labeled by Creative are SB compatible. In addition there
264are few sound chipsets which are SB compatible in Linux such as ESS1688 or
265Jazz16. Note that SB compatibility in DOS/Windows does _NOT_ mean anything
266in Linux.
267
268IF YOU REALLY ARE 150% SURE YOU HAVE A SOUND BLASTER YOU CAN SKIP THE REST OF
269THIS CHAPTER.
270
271For most other "supposed to be SB compatible" cards you have to use other
272than SB drivers (see below). It is possible to get most sound cards to work
273in SB mode but in general it's a complete waste of time. There are several
274problems which you will encounter by using SB mode with cards that are not
275truly SB compatible:
276
277- The SB emulation is at most SB Pro (DSP version 3.x) which means that
278you get only 8 bit audio (there is always an another ("native") mode which
279gives the 16 bit capability). The 8 bit only operation is the reason why
280many users claim that sound quality in Linux is much worse than in DOS.
281In addition some applications require 16 bit mode and they produce just
282noise with a 8 bit only device.
283- The card may work only in some cases but refuse to work most of the
284time. The SB compatible mode always requires special initialization which is
285done by the DOS/Windows drivers. This kind of cards work in Linux after
286you have warm booted it after DOS but they don't work after cold boot
287(power on or reset).
288- You get the famous "DMA timed out" messages. Usually all SB clones have
289software selectable IRQ and DMA settings. If the (power on default) values
290currently used by the card don't match configuration of the driver you will
291get the above error message whenever you try to record or play. There are
292few other reasons to the DMA timeout message but using the SB mode seems
293to be the most common cause.
294
2952. Trying to use a PnP (Plug & Play) card just like an ordinary sound card
296--------------------------------------------------------------------------
297
298Plug & Play is a protocol defined by Intel and Microsoft. It lets operating
299systems to easily identify and reconfigure I/O ports, IRQs and DMAs of ISA
300cards. The problem with PnP cards is that the standard Linux doesn't currently
301(versions 2.1.x and earlier) don't support PnP. This means that you will have
302to use some special tricks (see later) to get a PnP card alive. Many PnP cards
303work after they have been initialized but this is not always the case.
304
305There are sometimes both PnP and non-PnP versions of the same sound card.
306The non-PnP version is the original model which usually has been discontinued
307more than an year ago. The PnP version has the same name but with "PnP"
308appended to it (sometimes not). This causes major confusion since the non-PnP
309model works with Linux but the PnP one doesn't.
310
311You should carefully check if "Plug & Play" or "PnP" is mentioned in the name
312of the card or in the documentation or package that came with the card.
313Everything described in the rest of this document is not necessarily valid for
314PnP models of sound cards even you have managed to wake up the card properly.
315Many PnP cards are simply too different from their non-PnP ancestors which are
316covered by this document.
317
318
319Cards that are not (fully) supported by this driver
320===================================================
321
322See http://www.opensound.com/ossfree for information about sound cards
323to be supported in future.
324
325
326How to use sound without recompiling kernel and/or sound driver
327===============================================================
328
329There is a commercial sound driver which comes in precompiled form and doesn't
330require recompiling of the kernel. See http://www.4Front-tech.com/oss.html for
331more info.
332
333
334Configuring PnP cards
335=====================
336
337New versions of most sound cards use the so-called ISA PnP protocol for
338soft configuring their I/O, IRQ, DMA and shared memory resources.
339Currently at least cards made by Creative Technology (SB32 and SB32AWE
340PnP), Gravis (GUS PnP and GUS PnP Pro), Ensoniq (Soundscape PnP) and
341Aztech (some Sound Galaxy models) use PnP technology. The CS4232/4236 audio
342chip by Crystal Semiconductor (Intel Atlantis, HP Pavilion and many other
343motherboards) is also based on PnP technology but there is a "native" driver
344available for it (see information about CS4232 later in this document).
345
346PnP sound cards (as well as most other PnP ISA cards) are not supported
347by this version of the driver . Proper
348support for them should be released during 97 once the kernel level
349PnP support is available.
350
351There is a method to get most of the PnP cards to work. The basic method
352is the following:
353
3541) Boot DOS so the card's DOS drivers have a chance to initialize it.
3552) _Cold_ boot to Linux by using "loadlin.exe". Hitting ctrl-alt-del
356works with older machines but causes a hard reset of all cards on recent
357(Pentium) machines.
3583) If you have the sound driver in Linux configured properly, the card should
359work now. "Proper" means that I/O, IRQ and DMA settings are the same as in
360DOS. The hard part is to find which settings were used. See the documentation of
361your card for more info.
362
363Windows 95 could work as well as DOS but running loadlin may be difficult.
364Probably you should "shut down" your machine to MS-DOS mode before running it.
365
366Some machines have a BIOS utility for setting PnP resources. This is a good
367way to configure some cards. In this case you don't need to boot DOS/Win95
368before starting Linux.
369
370Another way to initialize PnP cards without DOS/Win95 is a Linux based
371PnP isolation tool. When writing this there is a pre alpha test version
372of such a tool available from ftp://ftp.demon.co.uk/pub/unix/linux/utils. The
373file is called isapnptools-*. Please note that this tool is just a temporary
374solution which may be incompatible with future kernel versions having proper
375support for PnP cards. There are bugs in setting DMA channels in earlier
376versions of isapnptools so at least version 1.6 is required with sound cards.
377
378Yet another way to use PnP cards is to use (commercial) OSS/Linux drivers. See
379http://www.opensound.com/linux.html for more info. This is probably the way you
380should do it if you don't want to spend time recompiling the kernel and
381required tools.
382
383
384Read this before trying to configure the driver
385===============================================
386
387There are currently many cards that work with this driver. Some of the cards
388have native support while others work since they emulate some other
389card (usually SB, MSS/WSS and/or MPU401). The following cards have native
390support in the driver. Detailed instructions for configuring these cards
391will be given later in this document.
392
393Pro Audio Spectrum 16 (PAS16) and compatibles:
394 Pro Audio Spectrum 16
395 Pro Audio Studio 16
396 Logitech Sound Man 16
397 NOTE! The original Pro Audio Spectrum as well as the PAS+ are not
398 and will not be supported by the driver.
399
400Media Vision Jazz16 based cards
401 Pro Sonic 16
402 Logitech SoundMan Wave
403 (Other Jazz based cards should work but I don't have any reports
404 about them).
405
406Sound Blasters
407 SB 1.0 to 2.0
408 SB Pro
409 SB 16
410 SB32/64/AWE
411 Configure SB32/64/AWE just like SB16. See lowlevel/README.awe
412 for information about using the wave table synth.
413 NOTE! AWE63/Gold and 16/32/AWE "PnP" cards need to be activated
414 using isapnptools before they work with OSS/Free.
415 SB16 compatible cards by other manufacturers than Creative.
416 You have been fooled since there are _no_ SB16 compatible
417 cards on the market (as of May 1997). It's likely that your card
418 is compatible just with SB Pro but there is also a non-SB-
419 compatible 16 bit mode. Usually it's MSS/WSS but it could also
420 be a proprietary one like MV Jazz16 or ESS ES688. OPTi
421 MAD16 chips are very common in so called "SB 16 bit cards"
422 (try with the MAD16 driver).
423
424 ======================================================================
425 "Supposed to be SB compatible" cards.
426 Forget the SB compatibility and check for other alternatives
427 first. The only cards that work with the SB driver in
428 Linux have been made by Creative Technology (there is at least
429 one chip on the card with "CREATIVE" printed on it). The
430 only other SB compatible chips are ESS and Jazz16 chips
431 (maybe ALSxxx chips too but they probably don't work).
432 Most other "16 bit SB compatible" cards such as "OPTi/MAD16" or
433 "Crystal" are _NOT_ SB compatible in Linux.
434
435 Practically all sound cards have some kind of SB emulation mode
436 in addition to their native (16 bit) mode. In most cases this
437 (8 bit only) SB compatible mode doesn't work with Linux. If
438 you get it working it may cause problems with games and
439 applications which require 16 bit audio. Some 16 bit only
440 applications don't check if the card actually supports 16 bits.
441 They just dump 16 bit data to a 8 bit card which produces just
442 noise.
443
444 In most cases the 16 bit native mode is supported by Linux.
445 Use the SB mode with "clones" only if you don't find anything
446 better from the rest of this doc.
447 ======================================================================
448
449Gravis Ultrasound (GUS)
450 GUS
451 GUS + the 16 bit option
452 GUS MAX
453 GUS ACE (No MIDI port and audio recording)
454 GUS PnP (with RAM)
455
456MPU-401 and compatibles
457 The driver works both with the full (intelligent mode) MPU-401
458 cards (such as MPU IPC-T and MQX-32M) and with the UART only
459 dumb MIDI ports. MPU-401 is currently the most common MIDI
460 interface. Most sound cards are compatible with it. However,
461 don't enable MPU401 mode blindly. Many cards with native support
462 in the driver have their own MPU401 driver. Enabling the standard one
463 will cause a conflict with these cards. So check if your card is
464 in the list of supported cards before enabling MPU401.
465
466Windows Sound System (MSS/WSS)
467 Even when Microsoft has discontinued their own Sound System card
468 they managed to make it a standard. MSS compatible cards are based on
469 a codec chip which is easily available from at least two manufacturers
470 (AD1848 by Analog Devices and CS4231/CS4248 by Crystal Semiconductor).
471 Currently most sound cards are based on one of the MSS compatible codec
472 chips. The CS4231 is used in the high quality cards such as GUS MAX,
473 MediaTrix AudioTrix Pro and TB Tropez (GUS MAX is not MSS compatible).
474
475 Having a AD1848, CS4248 or CS4231 codec chip on the card is a good
476 sign. Even if the card is not MSS compatible, it could be easy to write
477 support for it. Note also that most MSS compatible cards
478 require special boot time initialization which may not be present
479 in the driver. Also, some MSS compatible cards have native support.
480 Enabling the MSS support with these cards is likely to
481 cause a conflict. So check if your card is listed in this file before
482 enabling the MSS support.
483
484Yamaha FM synthesizers (OPL2, OPL3 (not OPL3-SA) and OPL4)
485 Most sound cards have a FM synthesizer chip. The OPL2 is a 2
486 operator chip used in the original AdLib card. Currently it's used
487 only in the cheapest (8 bit mono) cards. The OPL3 is a 4 operator
488 FM chip which provides better sound quality and/or more available
489 voices than the OPL2. The OPL4 is a new chip that has an OPL3 and
490 a wave table synthesizer packed onto the same chip. The driver supports
491 just the OPL3 mode directly. Most cards with an OPL4 (like
492 SM Wave and AudioTrix Pro) support the OPL4 mode using MPU401
493 emulation. Writing a native OPL4 support is difficult
494 since Yamaha doesn't give information about their sample ROM chip.
495
496 Enable the generic OPL2/OPL3 FM synthesizer support if your
497 card has a FM chip made by Yamaha. Don't enable it if your card
498 has a software (TRS) based FM emulator.
499
500 ----------------------------------------------------------------
501 NOTE! OPL3-SA is different chip than the ordinary OPL3. In addition
502 to the FM synth this chip has also digital audio (WSS) and
503 MIDI (MPU401) capabilities. Support for OPL3-SA is described below.
504 ----------------------------------------------------------------
505
506Yamaha OPL3-SA1
507
508 Yamaha OPL3-SA1 (YMF701) is an audio controller chip used on some
509 (Intel) motherboards and on cheap sound cards. It should not be
510 confused with the original OPL3 chip (YMF278) which is entirely
511 different chip. OPL3-SA1 has support for MSS, MPU401 and SB Pro
512 (not used in OSS/Free) in addition to the OPL3 FM synth.
513
514 There are also chips called OPL3-SA2, OPL3-SA3, ..., OPL3SA-N. They
515 are PnP chips and will not work with the OPL3-SA1 driver. You should
516 use the standard MSS, MPU401 and OPL3 options with these chips and to
517 activate the card using isapnptools.
518
5194Front Technologies SoftOSS
520
521 SoftOSS is a software based wave table emulation which works with
522 any 16 bit stereo sound card. Due to its nature a fast CPU is
523 required (P133 is minimum). Although SoftOSS does _not_ use MMX
524 instructions it has proven out that recent processors (which appear
525 to have MMX) perform significantly better with SoftOSS than earlier
526 ones. For example a P166MMX beats a PPro200. SoftOSS should not be used
527 on 486 or 386 machines.
528
529 The amount of CPU load caused by SoftOSS can be controlled by
530 selecting the CONFIG_SOFTOSS_RATE and CONFIG_SOFTOSS_VOICES
531 parameters properly (they will be prompted by make config). It's
532 recommended to set CONFIG_SOFTOSS_VOICES to 32. If you have a
533 P166MMX or faster (PPro200 is not faster) you can set
534 CONFIG_SOFTOSS_RATE to 44100 (kHz). However with slower systems it
535 recommended to use sampling rates around 22050 or even 16000 kHz.
536 Selecting too high values for these parameters may hang your
537 system when playing MIDI files with hight degree of polyphony
538 (number of concurrently playing notes). It's also possible to
539 decrease CONFIG_SOFTOSS_VOICES. This makes it possible to use
540 higher sampling rates. However using fewer voices decreases
541 playback quality more than decreasing the sampling rate.
542
543 SoftOSS keeps the samples loaded on the system's RAM so much RAM is
544 required. SoftOSS should never be used on machines with less than 16 MB
545 of RAM since this is potentially dangerous (you may accidentally run out
546 of memory which probably crashes the machine).
547
548 SoftOSS implements the wave table API originally designed for GUS. For
549 this reason all applications designed for GUS should work (at least
550 after minor modifications). For example gmod/xgmod and playmidi -g are
551 known to work.
552
553 To work SoftOSS will require GUS compatible
554 patch files to be installed on the system (in /dos/ultrasnd/midi). You
555 can use the public domain MIDIA patchset available from several ftp
556 sites.
557
558 *********************************************************************
559 IMPORTANT NOTICE! The original patch set distributed with the Gravis
560 Ultrasound card is not in public domain (even though it's available from
561 some FTP sites). You should contact Voice Crystal (www.voicecrystal.com)
562 if you like to use these patches with SoftOSS included in OSS/Free.
563 *********************************************************************
564
565PSS based cards (AD1848 + ADSP-2115 + Echo ESC614 ASIC)
566 Analog Devices and Echo Speech have together defined a sound card
567 architecture based on the above chips. The DSP chip is used
568 for emulation of SB Pro, FM and General MIDI/MT32.
569
570 There are several cards based on this architecture. The most known
571 ones are Orchid SW32 and Cardinal DSP16.
572
573 The driver supports downloading DSP algorithms to these cards.
574
575 NOTE! You will have to use the "old" config script when configuring
576 PSS cards.
577
578MediaTrix AudioTrix Pro
579 The ATP card is built around a CS4231 codec and an OPL4 synthesizer
580 chips. The OPL4 mode is supported by a microcontroller running a
581 General MIDI emulator. There is also a SB 1.5 compatible playback mode.
582
583Ensoniq SoundScape and compatibles
584 Ensoniq has designed a sound card architecture based on the
585 OTTO synthesizer chip used in their professional MIDI synthesizers.
586 Several companies (including Ensoniq, Reveal and Spea) are selling
587 cards based on this architecture.
588
589 NOTE! The SoundScape PnP is not supported by OSS/Free. Ensoniq VIVO and
590 VIVO90 cards are not compatible with Soundscapes so the Soundscape
591 driver will not work with them. You may want to use OSS/Linux with these
592 cards.
593
594OPTi MAD16 and Mozart based cards
595 The Mozart (OAK OTI-601), MAD16 (OPTi 82C928), MAD16 Pro (OPTi 82C929),
596 OPTi 82C924/82C925 (in _non_ PnP mode) and OPTi 82C930 interface
597 chips are used in many different sound cards, including some
598 cards by Reveal miro and Turtle Beach (Tropez). The purpose of these
599 chips is to connect other audio components to the PC bus. The
600 interface chip performs address decoding for the other chips.
601 NOTE! Tropez Plus is not MAD16 but CS4232 based.
602 NOTE! MAD16 PnP cards (82C924, 82C925, 82C931) are not MAD16 compatible
603 in the PnP mode. You will have to use them in MSS mode after having
604 initialized them using isapnptools or DOS. 82C931 probably requires
605 initialization using DOS/Windows (running isapnptools is not enough).
606 It's possible to use 82C931 with OSS/Free by jumpering it to non-PnP
607 mode (provided that the card has a jumper for this). In non-PnP mode
608 82C931 is compatible with 82C930 and should work with the MAD16 driver
609 (without need to use isapnptools or DOS to initialize it). All OPTi
610 chips are supported by OSS/Linux (both in PnP and non-PnP modes).
611
612Audio Excel DSP16
613 Support for this card was written by Riccardo Faccetti
614 (riccardo@cdc8g5.cdc.polimi.it). The AEDSP16 driver included in
615 the lowlevel/ directory. To use it you should enable the
616 "Additional low level drivers" option.
617
618Crystal CS4232 and CS4236 based cards such as AcerMagic S23, TB Tropez _Plus_ and
619 many PC motherboards (Compaq, HP, Intel, ...)
620 CS4232 is a PnP multimedia chip which contains a CS3231A codec,
621 SB and MPU401 emulations. There is support for OPL3 too.
622 Unfortunately the MPU401 mode doesn't work (I don't know how to
623 initialize it). CS4236 is an enhanced (compatible) version of CS4232.
624 NOTE! Don't ever try to use isapnptools with CS4232 since this will just
625 freeze your machine (due to chip bugs). If you have problems in getting
626 CS4232 working you could try initializing it with DOS (CS4232C.EXE) and
627 then booting Linux using loadlin. CS4232C.EXE loads a secret firmware
628 patch which is not documented by Crystal.
629
630Turtle Beach Maui and Tropez "classic"
631 This driver version supports sample, patch and program loading commands
632 described in the Maui/Tropez User's manual.
633 There is now full initialization support too. The audio side of
634 the Tropez is based on the MAD16 chip (see above).
635 NOTE! Tropez Plus is different card than Tropez "classic" and will not
636 work fully in Linux. You can get audio features working by configuring
637 the card as a CS4232 based card (above).
638
639
640Jumpers and software configuration
641==================================
642
643Some of the earliest sound cards were jumper configurable. You have to
644configure the driver use I/O, IRQ and DMA settings
645that match the jumpers. Just few 8 bit cards are fully jumper
646configurable (SB 1.x/2.x, SB Pro and clones).
647Some cards made by Aztech have an EEPROM which contains the
648config info. These cards behave much like hardware jumpered cards.
649
650Most cards have jumper for the base I/O address but other parameters
651are software configurable. Sometimes there are few other jumpers too.
652
653Latest cards are fully software configurable or they are PnP ISA
654compatible. There are no jumpers on the board.
655
656The driver handles software configurable cards automatically. Just configure
657the driver to use I/O, IRQ and DMA settings which are known to work.
658You could usually use the same values than with DOS and/or Windows.
659Using different settings is possible but not recommended since it may cause
660some trouble (for example when warm booting from an OS to another or
661when installing new hardware to the machine).
662
663Sound driver sets the soft configurable parameters of the card automatically
664during boot. Usually you don't need to run any extra initialization
665programs when booting Linux but there are some exceptions. See the
666card-specific instructions below for more info.
667
668The drawback of software configuration is that the driver needs to know
669how the card must be initialized. It cannot initialize unknown cards
670even if they are otherwise compatible with some other cards (like SB,
671MPU401 or Windows Sound System).
672
673
674What if your card was not listed above?
675=======================================
676
677The first thing to do is to look at the major IC chips on the card.
678Many of the latest sound cards are based on some standard chips. If you
679are lucky, all of them could be supported by the driver. The most common ones
680are the OPTi MAD16, Mozart, SoundScape (Ensoniq) and the PSS architectures
681listed above. Also look at the end of this file for list of unsupported
682cards and the ones which could be supported later.
683
684The last resort is to send _exact_ name and model information of the card
685to me together with a list of the major IC chips (manufactured, model) to
686me. I could then try to check if your card looks like something familiar.
687
688There are many more cards in the world than listed above. The first thing to
689do with these cards is to check if they emulate some other card or interface
690such as SB, MSS and/or MPU401. In this case there is a chance to get the
691card to work by booting DOS before starting Linux (boot DOS, hit ctrl-alt-del
692and boot Linux without hard resetting the machine). In this method the
693DOS based driver initializes the hardware to use known I/O, IRQ and DMA
694settings. If sound driver is configured to use the same settings, everything
695should work OK.
696
697
698Configuring sound driver (with Linux)
699=====================================
700
701The sound driver is currently distributed as part of the Linux kernel. The
702files are in /usr/src/linux/drivers/sound/.
703
704****************************************************************************
705* ALWAYS USE THE SOUND DRIVER VERSION WHICH IS DISTRIBUTED WITH *
706* THE KERNEL SOURCE PACKAGE YOU ARE USING. SOME ALPHA AND BETA TEST *
707* VERSIONS CAN BE INSTALLED FROM A SEPARATELY DISTRIBUTED PACKAGE *
708* BUT CHECK THAT THE PACKAGE IS NOT MUCH OLDER (OR NEWER) THAN THE *
709* KERNEL YOU ARE USING. IT'S POSSIBLE THAT THE KERNEL/DRIVER *
710* INTERFACE CHANGES BETWEEN KERNEL RELEASES WHICH MAY CAUSE SOME *
711* INCOMPATIBILITY PROBLEMS. *
712* *
713* IN CASE YOU INSTALL A SEPARATELY DISTRIBUTED SOUND DRIVER VERSION, *
714* BE SURE TO REMOVE OR RENAME THE OLD SOUND DRIVER DIRECTORY BEFORE *
715* INSTALLING THE NEW ONE. LEAVING OLD FILES TO THE SOUND DRIVER *
716* DIRECTORY _WILL_ CAUSE PROBLEMS WHEN THE DRIVER IS USED OR *
717* COMPILED. *
718****************************************************************************
719
720To configure the driver, run "make config" in the kernel source directory
721(/usr/src/linux). Answer "y" or "m" to the question about Sound card support
722(after the questions about mouse, CD-ROM, ftape, etc. support). Questions
723about options for sound will then be asked.
724
725After configuring the kernel and sound driver and compile the kernel
726following instructions in the kernel README.
727
728The sound driver configuration dialog
729-------------------------------------
730
731Sound configuration starts by making some yes/no questions. Be careful
732when answering to these questions since answering y to a question may
733prevent some later ones from being asked. For example don't answer y to
734the first question (PAS16) if you don't really have a PAS16. Don't enable
735more cards than you really need since they just consume memory. Also
736some drivers (like MPU401) may conflict with your SCSI controller and
737prevent kernel from booting. If you card was in the list of supported
738cards (above), please look at the card specific config instructions
739(later in this file) before starting to configure. Some cards must be
740configured in way which is not obvious.
741
742So here is the beginning of the config dialog. Answer 'y' or 'n' to these
743questions. The default answer is shown so that (y/n) means 'y' by default and
744(n/y) means 'n'. To use the default value, just hit ENTER. But be careful
745since using the default _doesn't_ guarantee anything.
746
747Note also that all questions may not be asked. The configuration program
748may disable some questions depending on the earlier choices. It may also
749select some options automatically as well.
750
751 "ProAudioSpectrum 16 support",
752 - Answer 'y'_ONLY_ if you have a Pro Audio Spectrum _16_,
753 Pro Audio Studio 16 or Logitech SoundMan 16 (be sure that
754 you read the above list correctly). Don't answer 'y' if you
755 have some other card made by Media Vision or Logitech since they
756 are not PAS16 compatible.
757 NOTE! Since 3.5-beta10 you need to enable SB support (next question)
758 if you want to use the SB emulation of PAS16. It's also possible to
759 the emulation if you want to use a true SB card together with PAS16
760 (there is another question about this that is asked later).
761 "Sound Blaster support",
762 - Answer 'y' if you have an original SB card made by Creative Labs
763 or a full 100% hardware compatible clone (like Thunderboard or
764 SM Games). If your card was in the list of supported cards (above),
765 please look at the card specific instructions later in this file
766 before answering this question. For an unknown card you may answer
767 'y' if the card claims to be SB compatible.
768 Enable this option also with PAS16 (changed since v3.5-beta9).
769
770 Don't enable SB if you have a MAD16 or Mozart compatible card.
771
772 "Generic OPL2/OPL3 FM synthesizer support",
773 - Answer 'y' if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
774 Answering 'y' is usually a safe and recommended choice. However some
775 cards may have software (TSR) FM emulation. Enabling FM support
776 with these cards may cause trouble. However I don't currently know
777 such cards.
778 "Gravis Ultrasound support",
779 - Answer 'y' if you have GUS or GUS MAX. Answer 'n' if you don't
780 have GUS since the GUS driver consumes much memory.
781 Currently I don't have experiences with the GUS ACE so I don't
782 know what to answer with it.
783 "MPU-401 support (NOT for SB16)",
784 - Be careful with this question. The MPU401 interface is supported
785 by almost any sound card today. However some natively supported cards
786 have their own driver for MPU401. Enabling the MPU401 option with
787 these cards will cause a conflict. Also enabling MPU401 on a system
788 that doesn't really have a MPU401 could cause some trouble. If your
789 card was in the list of supported cards (above), please look at
790 the card specific instructions later in this file.
791
792 In MOST cases this MPU401 driver should only be used with "true"
793 MIDI-only MPU401 professional cards. In most other cases there
794 is another way to get the MPU401 compatible interface of a
795 sound card to work.
796 Support for the MPU401 compatible MIDI port of SB16, ESS1688
797 and MV Jazz16 cards is included in the SB driver. Use it instead
798 of this separate MPU401 driver with these cards. As well
799 Soundscape, PSS and Maui drivers include their own MPU401
800 options.
801
802 It's safe to answer 'y' if you have a true MPU401 MIDI interface
803 card.
804 "6850 UART Midi support",
805 - It's safe to answer 'n' to this question in all cases. The 6850
806 UART interface is so rarely used.
807 "PSS (ECHO-ADI2111) support",
808 - Answer 'y' only if you have Orchid SW32, Cardinal DSP16 or some
809 other card based on the PSS chipset (AD1848 codec + ADSP-2115
810 DSP chip + Echo ESC614 ASIC CHIP).
811 "16 bit sampling option of GUS (_NOT_ GUS MAX)",
812 - Answer 'y' if you have installed the 16 bit sampling daughtercard
813 to your GUS. Answer 'n' if you have GUS MAX. Enabling this option
814 disables GUS MAX support.
815 "GUS MAX support",
816 - Answer 'y' only if you have a GUS MAX.
817 "Microsoft Sound System support",
818 - Again think carefully before answering 'y' to this question. It's
819 safe to answer 'y' in case you have the original Windows Sound
820 System card made by Microsoft or Aztech SG 16 Pro (or NX16 Pro).
821 Also you may answer 'y' in case your card was not listed earlier
822 in this file. For cards having native support in the driver, consult
823 the card specific instructions later in this file. Some drivers
824 have their own MSS support and enabling this option will cause a
825 conflict.
826 Note! The MSS driver permits configuring two DMA channels. This is a
827 "nonstandard" feature and works only with very few cards (if any).
828 In most cases the second DMA channel should be disabled or set to
829 the same channel than the first one. Trying to configure two separate
830 channels with cards that don't support this feature will prevent
831 audio (at least recording) from working.
832 "Ensoniq Soundscape support",
833 - Answer 'y' if you have a sound card based on the Ensoniq SoundScape
834 chipset. Such cards are being manufactured at least by Ensoniq,
835 Spea and Reveal (note that Reveal makes other cards also). The oldest
836 cards made by Spea don't work properly with Linux.
837 Soundscape PnP as well as Ensoniq VIVO work only with the commercial
838 OSS/Linux version.
839 "MediaTrix AudioTrix Pro support",
840 - Answer 'y' if you have the AudioTrix Pro.
841 "Support for MAD16 and/or Mozart based cards",
842 - Answer y if your card has a Mozart (OAK OTI-601) or MAD16
843 (OPTi 82C928, 82C929, 82C924/82C925 or 82C930) audio interface chip.
844 These chips are
845 currently quite common so it's possible that many no-name cards
846 have one of them. In addition the MAD16 chip is used in some
847 cards made by known manufacturers such as Turtle Beach (Tropez),
848 Reveal (some models) and Diamond (some recent models).
849 Note OPTi 82C924 and 82C925 are MAD16 compatible only in non PnP
850 mode (jumper selectable on many cards).
851 "Support for TB Maui"
852 - This enables TB Maui specific initialization. Works with TB Maui
853 and TB Tropez (may not work with Tropez Plus).
854
855
856Then the configuration program asks some y/n questions about the higher
857level services. It's recommended to answer 'y' to each of these questions.
858Answer 'n' only if you know you will not need the option.
859
860 "MIDI interface support",
861 - Answering 'n' disables /dev/midi## devices and access to any
862 MIDI ports using /dev/sequencer and /dev/music. This option
863 also affects any MPU401 and/or General MIDI compatible devices.
864 "FM synthesizer (YM3812/OPL-3) support",
865 - Answer 'y' here.
866 "/dev/sequencer support",
867 - Answering 'n' disables /dev/sequencer and /dev/music.
868
869Entering the I/O, IRQ and DMA config parameters
870-----------------------------------------------
871
872After the above questions the configuration program prompts for the
873card specific configuration information. Usually just a set of
874I/O address, IRQ and DMA numbers are asked. With some cards the program
875asks for some files to be used during initialization of the card. For example
876many cards have a DSP chip or microprocessor which must be initialized by
877downloading a program (microcode) file to the card.
878
879Instructions for answering these questions are given in the next section.
880
881
882Card specific information
883=========================
884
885This section gives additional instructions about configuring some cards.
886Please refer manual of your card for valid I/O, IRQ and DMA numbers. Using
887the same settings with DOS/Windows and Linux is recommended. Using
888different values could cause some problems when switching between
889different operating systems.
890
891Sound Blasters (the original ones by Creative)
892---------------------------------------------
893
894NOTE! Check if you have a PnP Sound Blaster (cards sold after summer 1995
895 are almost certainly PnP ones). With PnP cards you should use isapnptools
896 to activate them (see above).
897
898It's possible to configure these cards to use different I/O, IRQ and
899DMA settings. Since the possible/default settings have changed between various
900models, you have to consult manual of your card for the proper ones. It's
901a good idea to use the same values than with DOS/Windows. With SB and SB Pro
902it's the only choice. SB16 has software selectable IRQ and DMA channels but
903using different values with DOS and Linux is likely to cause troubles. The
904DOS driver is not able to reset the card properly after warm boot from Linux
905if Linux has used different IRQ or DMA values.
906
907The original (steam) Sound Blaster (versions 1.x and 2.x) use always
908DMA1. There is no way to change it.
909
910The SB16 needs two DMA channels. A 8 bit one (1 or 3) is required for
9118 bit operation and a 16 bit one (5, 6 or 7) for the 16 bit mode. In theory
912it's possible to use just one (8 bit) DMA channel by answering the 8 bit
913one when the configuration program asks for the 16 bit one. This may work
914in some systems but is likely to cause terrible noise on some other systems.
915
916It's possible to use two SB16/32/64 at the same time. To do this you should
917first configure OSS/Free for one card. Then edit local.h manually and define
918SB2_BASE, SB2_IRQ, SB2_DMA and SB2_DMA2 for the second one. You can't get
919the OPL3, MIDI and EMU8000 devices of the second card to work. If you are
920going to use two PnP Sound Blasters, ensure that they are of different model
921and have different PnP IDs. There is no way to get two cards with the same
922card ID and serial number to work. The easiest way to check this is trying
923if isapnptools can see both cards or just one.
924
925NOTE! Don't enable the SM Games option (asked by the configuration program)
926 if you are not 101% sure that your card is a Logitech Soundman Games
927 (not a SM Wave or SM16).
928
929SB Clones
930---------
931
932First of all: There are no SB16 clones. There are SB Pro clones with a
93316 bit mode which is not SB16 compatible. The most likely alternative is that
934the 16 bit mode means MSS/WSS.
935
936There are just a few fully 100% hardware SB or SB Pro compatible cards.
937I know just Thunderboard and SM Games. Other cards require some kind of
938hardware initialization before they become SB compatible. Check if your card
939was listed in the beginning of this file. In this case you should follow
940instructions for your card later in this file.
941
942For other not fully SB clones you may try initialization using DOS in
943the following way:
944
945 - Boot DOS so that the card specific driver gets run.
946 - Hit ctrl-alt-del (or use loadlin) to boot Linux. Don't
947 switch off power or press the reset button.
948 - If you use the same I/O, IRQ and DMA settings in Linux, the
949 card should work.
950
951If your card is both SB and MSS compatible, I recommend using the MSS mode.
952Most cards of this kind are not able to work in the SB and the MSS mode
953simultaneously. Using the MSS mode provides 16 bit recording and playback.
954
955ProAudioSpectrum 16 and compatibles
956-----------------------------------
957
958PAS16 has a SB emulation chip which can be used together with the native
959(16 bit) mode of the card. To enable this emulation you should configure
960the driver to have SB support too (this has been changed since version
9613.5-beta9 of this driver).
962
963With current driver versions it's also possible to use PAS16 together with
964another SB compatible card. In this case you should configure SB support
965for the other card and to disable the SB emulation of PAS16 (there is a
966separate questions about this).
967
968With PAS16 you can use two audio device files at the same time. /dev/dsp (and
969/dev/audio) is connected to the 8/16 bit native codec and the /dev/dsp1 (and
970/dev/audio1) is connected to the SB emulation (8 bit mono only).
971
972Gravis Ultrasound
973-----------------
974
975There are many different revisions of the Ultrasound card (GUS). The
976earliest ones (pre 3.7) don't have a hardware mixer. With these cards
977the driver uses a software emulation for synth and pcm playbacks. It's
978also possible to switch some of the inputs (line in, mic) off by setting
979mixer volume of the channel level below 10%. For recording you have
980to select the channel as a recording source and to use volume above 10%.
981
982GUS 3.7 has a hardware mixer.
983
984GUS MAX and the 16 bit sampling daughtercard have a CS4231 codec chip which
985also contains a mixer.
986
987Configuring GUS is simple. Just enable the GUS support and GUS MAX or
988the 16 bit daughtercard if you have them. Note that enabling the daughter
989card disables GUS MAX driver.
990
991NOTE for owners of the 16 bit daughtercard: By default the daughtercard
992uses /dev/dsp (and /dev/audio). Command "ln -sf /dev/dsp1 /dev/dsp"
993selects the daughter card as the default device.
994
995With just the standard GUS enabled the configuration program prompts
996for the I/O, IRQ and DMA numbers for the card. Use the same values than
997with DOS.
998
999With the daughter card option enabled you will be prompted for the I/O,
1000IRQ and DMA numbers for the daughter card. You have to use different I/O
1001and DMA values than for the standard GUS. The daughter card permits
1002simultaneous recording and playback. Use /dev/dsp (the daughtercard) for
1003recording and /dev/dsp1 (GUS GF1) for playback.
1004
1005GUS MAX uses the same I/O address and IRQ settings than the original GUS
1006(GUS MAX = GUS + a CS4231 codec). In addition an extra DMA channel may be used.
1007Using two DMA channels permits simultaneous playback using two devices
1008(dev/dsp0 and /dev/dsp1). The second DMA channel is required for
1009full duplex audio.
1010To enable the second DMA channels, give a valid DMA channel when the config
1011program asks for the GUS MAX DMA (entering -1 disables the second DMA).
1012Using 16 bit DMA channels (5,6 or 7) is recommended.
1013
1014If you have problems in recording with GUS MAX, you could try to use
1015just one 8 bit DMA channel. Recording will not work with one DMA
1016channel if it's a 16 bit one.
1017
1018Microphone input of GUS MAX is connected to mixer in little bit nonstandard
1019way. There is actually two microphone volume controls. Normal "mic" controls
1020only recording level. Mixer control "speaker" is used to control volume of
1021microphone signal connected directly to line/speaker out. So just decrease
1022volume of "speaker" if you have problems with microphone feedback.
1023
1024GUS ACE works too but any attempt to record or to use the MIDI port
1025will fail.
1026
1027GUS PnP (with RAM) is partially supported but it needs to be initialized using
1028DOS or isapnptools before starting the driver.
1029
1030MPU401 and Windows Sound System
1031-------------------------------
1032
1033Again. Don't enable these options in case your card is listed
1034somewhere else in this file.
1035
1036Configuring these cards is obvious (or it should be). With MSS
1037you should probably enable the OPL3 synth also since
1038most MSS compatible cards have it. However check that this is true
1039before enabling OPL3.
1040
1041Sound driver supports more than one MPU401 compatible cards at the same time
1042but the config program asks config info for just the first of them.
1043Adding the second or third MPU interfaces must be done manually by
1044editing sound/local.h (after running the config program). Add defines for
1045MPU2_BASE & MPU2_IRQ (and MPU3_BASE & MPU3_IRQ) to the file.
1046
1047CAUTION!
1048
1049The default I/O base of Adaptec AHA-1542 SCSI controller is 0x330 which
1050is also the default of the MPU401 driver. Don't configure the sound driver to
1051use 0x330 as the MPU401 base if you have a AHA1542. The kernel will not boot
1052if you make this mistake.
1053
1054PSS
1055---
1056
1057Even the PSS cards are compatible with SB, MSS and MPU401, you must not
1058enable these options when configuring the driver. The configuration
1059program handles these options itself. (You may use the SB, MPU and MSS options
1060together with PSS if you have another card on the system).
1061
1062The PSS driver enables MSS and MPU401 modes of the card. SB is not enabled
1063since it doesn't work concurrently with MSS. The driver loads also a
1064DSP algorithm which is used to for the general MIDI emulation. The
1065algorithm file (.ld) is read by the config program and written to a
1066file included when the pss.c is compiled. For this reason the config
1067program asks if you want to download the file. Use the genmidi.ld file
1068distributed with the DOS/Windows drivers of the card (don't use the mt32.ld).
1069With some cards the file is called 'synth.ld'. You must have access to
1070the file when configuring the driver. The easiest way is to mount the DOS
1071partition containing the file with Linux.
1072
1073It's possible to load your own DSP algorithms and run them with the card.
1074Look at the directory pss_test of snd-util-3.0.tar.gz for more info.
1075
1076AudioTrix Pro
1077-------------
1078
1079You have to enable the OPL3 and SB (not SB Pro or SB16) drivers in addition
1080to the native AudioTrix driver. Don't enable MSS or MPU drivers.
1081
1082Configuring ATP is little bit tricky since it uses so many I/O, IRQ and
1083DMA numbers. Using the same values than with DOS/Win is a good idea. Don't
1084attempt to use the same IRQ or DMA channels twice.
1085
1086The SB mode of ATP is implemented so the ATP driver just enables SB
1087in the proper address. The SB driver handles the rest. You have to configure
1088both the SB driver and the SB mode of ATP to use the same IRQ, DMA and I/O
1089settings.
1090
1091Also the ATP has a microcontroller for the General MIDI emulation (OPL4).
1092For this reason the driver asks for the name of a file containing the
1093microcode (TRXPRO.HEX). This file is usually located in the directory
1094where the DOS drivers were installed. You must have access to this file
1095when configuring the driver.
1096
1097If you have the effects daughtercard, it must be initialized by running
1098the setfx program of snd-util-3.0.tar.gz package. This step is not required
1099when using the (future) binary distribution version of the driver.
1100
1101Ensoniq SoundScape
1102------------------
1103
1104NOTE! The new PnP SoundScape is not supported yet. Soundscape compatible
1105 cards made by Reveal don't work with Linux. They use older revision
1106 of the Soundscape chipset which is not fully compatible with
1107 newer cards made by Ensoniq.
1108
1109The SoundScape driver handles initialization of MSS and MPU supports
1110itself so you don't need to enable other drivers than SoundScape
1111(enable also the /dev/dsp, /dev/sequencer and MIDI supports).
1112
1113!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1114!!!!! !!!!
1115!!!!! NOTE! Before version 3.5-beta6 there WERE two sets of audio !!!!
1116!!!!! device files (/dev/dsp0 and /dev/dsp1). The first one WAS !!!!
1117!!!!! used only for card initialization and the second for audio !!!!
1118!!!!! purposes. It WAS required to change /dev/dsp (a symlink) to !!!!
1119!!!!! point to /dev/dsp1. !!!!
1120!!!!! !!!!
1121!!!!! This is not required with OSS versions 3.5-beta6 and later !!!!
1122!!!!! since there is now just one audio device file. Please !!!!
1123!!!!! change /dev/dsp to point back to /dev/dsp0 if you are !!!!
1124!!!!! upgrading from an earlier driver version using !!!!
1125!!!!! (cd /dev;rm dsp;ln -s dsp0 dsp). !!!!
1126!!!!! !!!!
1127!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1128
1129The configuration program asks one DMA channel and two interrupts. One IRQ
1130and one DMA is used by the MSS codec. The second IRQ is required for the
1131MPU401 mode (you have to use different IRQs for both purposes).
1132There were earlier two DMA channels for SoundScape but the current driver
1133version requires just one.
1134
1135The SoundScape card has a Motorola microcontroller which must initialized
1136_after_ boot (the driver doesn't initialize it during boot).
1137The initialization is done by running the 'ssinit' program which is
1138distributed in the snd-util-3.0.tar.gz package. You have to edit two
1139defines in the ssinit.c and then compile the program. You may run ssinit
1140manually (after each boot) or add it to /etc/rc.d/rc.local.
1141
1142The ssinit program needs the microcode file that comes with the DOS/Windows
1143driver of the card. You will need to use version 1.30.00 or later
1144of the microcode file (sndscape.co0 or sndscape.co1 depending on
1145your card model). THE OLD sndscape.cod WILL NOT WORK. IT WILL HANG YOUR
1146MACHINE. The only way to get the new microcode file is to download
1147and install the DOS/Windows driver from ftp://ftp.ensoniq.com/pub.
1148
1149Then you have to select the proper microcode file to use: soundscape.co0
1150is the right one for most cards and sndscape.co1 is for few (older) cards
1151made by Reveal and/or Spea. The driver has capability to detect the card
1152version during boot. Look at the boot log messages in /var/adm/messages
1153and locate the sound driver initialization message for the SoundScape
1154card. If the driver displays string <Ensoniq Soundscape (old)>, you have
1155an old card and you will need to use sndscape.co1. For other cards use
1156soundscape.co0. New Soundscape revisions such as Elite and PnP use
1157code files with higher numbers (.co2, .co3, etc.).
1158
1159NOTE! Ensoniq Soundscape VIVO is not compatible with other Soundscape cards.
1160 Currently it's possible to use it in Linux only with OSS/Linux
1161 drivers.
1162
1163Check /var/adm/messages after running ssinit. The driver prints
1164the board version after downloading the microcode file. That version
1165number must match the number in the name of the microcode file (extension).
1166
1167Running ssinit with a wrong version of the sndscape.co? file is not
1168dangerous as long as you don't try to use a file called sndscape.cod.
1169If you have initialized the card using a wrong microcode file (sounds
1170are terrible), just modify ssinit.c to use another microcode file and try
1171again. It's possible to use an earlier version of sndscape.co[01] but it
1172may sound weird.
1173
1174MAD16 (Pro) and Mozart
1175----------------------
1176
1177You need to enable just the MAD16 /Mozart support when configuring
1178the driver. _Don't_ enable SB, MPU401 or MSS. However you will need the
1179/dev/audio, /dev/sequencer and MIDI supports.
1180
1181Mozart and OPTi 82C928 (the original MAD16) chips don't support
1182MPU401 mode so enter just 0 when the configuration program asks the
1183MPU/MIDI I/O base. The MAD16 Pro (OPTi 82C929) and 82C930 chips have MPU401
1184mode.
1185
1186TB Tropez is based on the 82C929 chip. It has two MIDI ports.
1187The one connected to the MAD16 chip is the second one (there is a second
1188MIDI connector/pins somewhere??). If you have not connected the second MIDI
1189port, just disable the MIDI port of MAD16. The 'Maui' compatible synth of
1190Tropez is jumper configurable and not connected to the MAD16 chip (the
1191Maui driver can be used with it).
1192
1193Some MAD16 based cards may cause feedback, whistle or terrible noise if the
1194line3 mixer channel is turned too high. This happens at least with Shuttle
1195Sound System. Current driver versions set volume of line3 low enough so
1196this should not be a problem.
1197
1198If you have a MAD16 card which have an OPL4 (FM + Wave table) synthesizer
1199chip (_not_ an OPL3), you have to append a line containing #define MAD16_OPL4
1200to the file linux/drivers/sound/local.h (after running make config).
1201
1202MAD16 cards having a CS4231 codec support full duplex mode. This mode
1203can be enabled by configuring the card to use two DMA channels. Possible
1204DMA channel pairs are: 0&1, 1&0 and 3&0.
1205
1206NOTE! Cards having an OPTi 82C924/82C925 chip work with OSS/Free only in
1207non-PnP mode (usually jumper selectable). The PnP mode is supported only
1208by OSS/Linux.
1209
1210MV Jazz (ProSonic)
1211------------------
1212
1213The Jazz16 driver is just a hack made to the SB Pro driver. However it works
1214fairly well. You have to enable SB, SB Pro (_not_ SB16) and MPU401 supports
1215when configuring the driver. The configuration program asks later if you
1216want support for MV Jazz16 based cards (after asking SB base address). Answer
1217'y' here and the driver asks the second (16 bit) DMA channel.
1218
1219The Jazz16 driver uses the MPU401 driver in a way which will cause
1220problems if you have another MPU401 compatible card. In this case you must
1221give address of the Jazz16 based MPU401 interface when the config
1222program prompts for the MPU401 information. Then look at the MPU401
1223specific section for instructions about configuring more than one MPU401 cards.
1224
1225Logitech Soundman Wave
1226----------------------
1227
1228Read the above MV Jazz specific instructions first.
1229
1230The Logitech SoundMan Wave (don't confuse this with the SM16 or SM Games) is
1231a MV Jazz based card which has an additional OPL4 based wave table
1232synthesizer. The OPL4 chip is handled by an on board microcontroller
1233which must be initialized during boot. The config program asks if
1234you have a SM Wave immediately after asking the second DMA channel of jazz16.
1235If you answer 'y', the config program will ask name of the file containing
1236code to be loaded to the microcontroller. The file is usually called
1237MIDI0001.BIN and it's located in the DOS/Windows driver directory. The file
1238may also be called as TSUNAMI.BIN or something else (older cards?).
1239
1240The OPL4 synth will be inaccessible without loading the microcontroller code.
1241
1242Also remember to enable SB MPU401 support if you want to use the OPL4 mode.
1243(Don't enable the 'normal' MPU401 device as with some earlier driver
1244versions (pre 3.5-alpha8)).
1245
1246NOTE! Don't answer 'y' when the driver asks about SM Games support
1247 (the next question after the MIDI0001.BIN name). However
1248 answering 'y' doesn't cause damage your computer so don't panic.
1249
1250Sound Galaxies
1251--------------
1252
1253There are many different Sound Galaxy cards made by Aztech. The 8 bit
1254ones are fully SB or SB Pro compatible and there should be no problems
1255with them.
1256
1257The older 16 bit cards (SG Pro16, SG NX Pro16, Nova and Lyra) have
1258an EEPROM chip for storing the configuration data. There is a microcontroller
1259which initializes the card to match the EEPROM settings when the machine
1260is powered on. These cards actually behave just like they have jumpers
1261for all of the settings. Configure driver for MSS, MPU, SB/SB Pro and OPL3
1262supports with these cards.
1263
1264There are some new Sound Galaxies in the market. I have no experience with
1265them so read the card's manual carefully.
1266
1267ESS ES1688 and ES688 'AudioDrive' based cards
1268---------------------------------------------
1269
1270Support for these two ESS chips is embedded in the SB driver.
1271Configure these cards just like SB. Enable the 'SB MPU401 MIDI port'
1272if you want to use MIDI features of ES1688. ES688 doesn't have MPU mode
1273so you don't need to enable it (the driver uses normal SB MIDI automatically
1274with ES688).
1275
1276NOTE! ESS cards are not compatible with MSS/WSS so don't worry if MSS support
1277of OSS doesn't work with it.
1278
1279There are some ES1688/688 based sound cards and (particularly) motherboards
1280which use software configurable I/O port relocation feature of the chip.
1281This ESS proprietary feature is supported only by OSS/Linux.
1282
1283There are ES1688 based cards which use different interrupt pin assignment than
1284recommended by ESS (5, 7, 9/2 and 10). In this case all IRQs don't work.
1285At least a card called (Pearl?) Hypersound 16 supports IRQ 15 but it doesn't
1286work.
1287
1288ES1868 is a PnP chip which is (supposed to be) compatible with ESS1688
1289probably works with OSS/Free after initialization using isapnptools.
1290
1291Reveal cards
1292------------
1293
1294There are several different cards made/marketed by Reveal. Some of them
1295are compatible with SoundScape and some use the MAD16 chip. You may have
1296to look at the card and try to identify its origin.
1297
1298Diamond
1299-------
1300
1301The oldest (Sierra Aria based) sound cards made by Diamond are not supported
1302(they may work if the card is initialized using DOS). The recent (LX?)
1303models are based on the MAD16 chip which is supported by the driver.
1304
1305Audio Excel DSP16
1306-----------------
1307
1308Support for this card is currently not functional. A new driver for it
1309should be available later this year.
1310
1311PCMCIA cards
1312------------
1313
1314Sorry, can't help. Some cards may work and some don't.
1315
1316TI TM4000M notebooks
1317--------------------
1318
1319These computers have a built in sound support based on the Jazz chipset.
1320Look at the instructions for MV Jazz (above). It's also important to note
1321that there is something wrong with the mouse port and sound at least on
1322some TM models. Don't enable the "C&T 82C710 mouse port support" when
1323configuring Linux. Having it enabled is likely to cause mysterious problems
1324and kernel failures when sound is used.
1325
1326miroSOUND
1327---------
1328
1329The miroSOUND PCM1-pro, PCM12 and PCM20 radio has been used
1330successfully. These cards are based on the MAD16, OPL4, and CS4231A chips
1331and everything said in the section about MAD16 cards applies here,
1332too. The only major difference between the PCMxx and other MAD16 cards
1333is that instead of the mixer in the CS4231 codec a separate mixer
1334controlled by an on-board 80C32 microcontroller is used. Control of
1335the mixer takes place via the ACI (miro's audio control interface)
1336protocol that is implemented in a separate lowlevel driver. Make sure
1337you compile this ACI driver together with the normal MAD16 support
1338when you use a miroSOUND PCMxx card. The ACI mixer is controlled by
1339/dev/mixer and the CS4231 mixer by /dev/mixer1 (depends on load
1340time). Only in special cases you want to change something regularly on
1341the CS4231 mixer.
1342
1343The miroSOUND PCM12 and PCM20 radio is capable of full duplex
1344operation (simultaneous PCM replay and recording), which allows you to
1345implement nice real-time signal processing audio effect software and
1346network telephones. The ACI mixer has to be switched into the "solo"
1347mode for duplex operation in order to avoid feedback caused by the
1348mixer (input hears output signal). You can de-/activate this mode
1349through toggling the record button for the wave controller with an
1350OSS-mixer.
1351
1352The PCM20 contains a radio tuner, which is also controlled by
1353ACI. This radio tuner is supported by the ACI driver together with the
1354miropcm20.o module. Also the 7-band equalizer is integrated
1355(limited by the OSS-design). Development has started and maybe
1356finished for the RDS decoder on this card, too. You will be able to
1357read RadioText, the Programme Service name, Programme TYpe and
1358others. Even the v4l radio module benefits from it with a refined
1359strength value. See aci.[ch] and miropcm20*.[ch] for more details.
1360
1361The following configuration parameters have worked fine for the PCM12
1362in Markus Kuhn's system, many other configurations might work, too:
1363CONFIG_MAD16_BASE=0x530, CONFIG_MAD16_IRQ=11, CONFIG_MAD16_DMA=3,
1364CONFIG_MAD16_DMA2=0, CONFIG_MAD16_MPU_BASE=0x330, CONFIG_MAD16_MPU_IRQ=10,
1365DSP_BUFFSIZE=65536, SELECTED_SOUND_OPTIONS=0x00281000.
1366
1367Bas van der Linden is using his PCM1-pro with a configuration that
1368differs in: CONFIG_MAD16_IRQ=7, CONFIG_MAD16_DMA=1, CONFIG_MAD16_MPU_IRQ=9
1369
1370Compaq Deskpro XL
1371-----------------
1372
1373The builtin sound hardware of Compaq Deskpro XL is now supported.
1374You need to configure the driver with MSS and OPL3 supports enabled.
1375In addition you need to manually edit linux/drivers/sound/local.h and
1376to add a line containing "#define DESKPROXL" if you used
1377make menuconfig/xconfig.
1378
1379Others?
1380-------
1381
1382Since there are so many different sound cards, it's likely that I have
1383forgotten to mention many of them. Please inform me if you know yet another
1384card which works with Linux, please inform me (or is anybody else
1385willing to maintain a database of supported cards (just like in XF86)?).
1386
1387Cards not supported yet
1388=======================
1389
1390Please check the version of sound driver you are using before
1391complaining that your card is not supported. It's possible you are
1392using a driver version which was released months before your card was
1393introduced.
1394
1395First of all, there is an easy way to make most sound cards work with Linux.
1396Just use the DOS based driver to initialize the card to a known state, then use
1397loadlin.exe to boot Linux. If Linux is configured to use the same I/O, IRQ and
1398DMA numbers as DOS, the card could work.
1399(ctrl-alt-del can be used in place of loadlin.exe but it doesn't work with
1400new motherboards). This method works also with all/most PnP sound cards.
1401
1402Don't get fooled with SB compatibility. Most cards are compatible with
1403SB but that may require a TSR which is not possible with Linux. If
1404the card is compatible with MSS, it's a better choice. Some cards
1405don't work in the SB and MSS modes at the same time.
1406
1407Then there are cards which are no longer manufactured and/or which
1408are relatively rarely used (such as the 8 bit ProAudioSpectrum
1409models). It's extremely unlikely that such cards ever get supported.
1410Adding support for a new card requires much work and increases time
1411required in maintaining the driver (some changes need to be done
1412to all low level drivers and be tested too, maybe with multiple
1413operating systems). For this reason I have made a decision to not support
1414obsolete cards. It's possible that someone else makes a separately
1415distributed driver (diffs) for the card.
1416
1417Writing a driver for a new card is not possible if there are no
1418programming information available about the card. If you don't
1419find your new card from this file, look from the home page
1420(http://www.opensound.com/ossfree). Then please contact
1421manufacturer of the card and ask if they have (or are willing to)
1422released technical details of the card. Do this before contacting me. I
1423can only answer 'no' if there are no programming information available.
1424
1425I have made decision to not accept code based on reverse engineering
1426to the driver. There are three main reasons: First I don't want to break
1427relationships to sound card manufacturers. The second reason is that
1428maintaining and supporting a driver without any specs will be a pain.
1429The third reason is that companies have freedom to refuse selling their
1430products to other than Windows users.
1431
1432Some companies don't give low level technical information about their
1433products to public or at least their require signing a NDA. It's not
1434possible to implement a freeware driver for them. However it's possible
1435that support for such cards become available in the commercial version
1436of this driver (see http://www.4Front-tech.com/oss.html for more info).
1437
1438There are some common audio chipsets that are not supported yet. For example
1439Sierra Aria and IBM Mwave. It's possible that these architectures
1440get some support in future but I can't make any promises. Just look
1441at the home page (http://www.opensound.com/ossfree/)
1442for latest info.
1443
1444Information about unsupported sound cards and chipsets is welcome as well
1445as free copies of sound cards, SDKs and operating systems.
1446
1447If you have any corrections and/or comments, please contact me.
1448
1449Hannu Savolainen
1450hannu@opensound.com
1451
1452home page of OSS/Free: http://www.opensound.com/ossfree
1453
1454home page of commercial OSS
1455(Open Sound System) drivers: http://www.opensound.com/oss.html
diff --git a/Documentation/sound/oss/README.modules b/Documentation/sound/oss/README.modules
deleted file mode 100644
index cdc039421a46..000000000000
--- a/Documentation/sound/oss/README.modules
+++ /dev/null
@@ -1,106 +0,0 @@
1Building a modular sound driver
2================================
3
4 The following information is current as of linux-2.1.85. Check the other
5readme files, especially README.OSS, for information not specific to
6making sound modular.
7
8 First, configure your kernel. This is an idea of what you should be
9setting in the sound section:
10
11<M> Sound card support
12
13<M> 100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support
14
15 I have SoundBlaster. Select your card from the list.
16
17<M> Generic OPL2/OPL3 FM synthesizer support
18<M> FM synthesizer (YM3812/OPL-3) support
19
20 If you don't set these, you will probably find you can play .wav files
21but not .midi. As the help for them says, set them unless you know your
22card does not use one of these chips for FM support.
23
24 Once you are configured, make zlilo, modules, modules_install; reboot.
25Note that it is no longer necessary or possible to configure sound in the
26drivers/sound dir. Now one simply configures and makes one's kernel and
27modules in the usual way.
28
29 Then, add to your /etc/modprobe.d/oss.conf something like:
30
31alias char-major-14-* sb
32install sb /sbin/modprobe -i sb && /sbin/modprobe adlib_card
33options sb io=0x220 irq=7 dma=1 dma16=5 mpu_io=0x330
34options adlib_card io=0x388 # FM synthesizer
35
36 Alternatively, if you have compiled in kernel level ISAPnP support:
37
38alias char-major-14 sb
39softdep sb post: adlib_card
40options adlib_card io=0x388
41
42 The effect of this is that the sound driver and all necessary bits and
43pieces autoload on demand, assuming you use kerneld (a sound choice) and
44autoclean when not in use. Also, options for the device drivers are
45set. They will not work without them. Change as appropriate for your card.
46If you are not yet using the very cool kerneld, you will have to "modprobe
47-k sb" yourself to get things going. Eventually things may be fixed so
48that this kludgery is not necessary; for the time being, it seems to work
49well.
50
51 Replace 'sb' with the driver for your card, and give it the right
52options. To find the filename of the driver, look in
53/lib/modules/<kernel-version>/misc. Mine looks like:
54
55adlib_card.o # This is the generic OPLx driver
56opl3.o # The OPL3 driver
57sb.o # <<The SoundBlaster driver. Yours may differ.>>
58sound.o # The sound driver
59uart401.o # Used by sb, maybe other cards
60
61 Whichever card you have, try feeding it the options that would be the
62default if you were making the driver wired, not as modules. You can
63look at function referred to by module_init() for the card to see what
64args are expected.
65
66 Note that at present there is no way to configure the io, irq and other
67parameters for the modular drivers as one does for the wired drivers.. One
68needs to pass the modules the necessary parameters as arguments, either
69with /etc/modprobe.d/*.conf or with command-line args to modprobe, e.g.
70
71modprobe sb io=0x220 irq=7 dma=1 dma16=5 mpu_io=0x330
72modprobe adlib_card io=0x388
73
74 recommend using /etc/modprobe.d/*.conf.
75
76Persistent DMA Buffers:
77
78The sound modules normally allocate DMA buffers during open() and
79deallocate them during close(). Linux can often have problems allocating
80DMA buffers for ISA cards on machines with more than 16MB RAM. This is
81because ISA DMA buffers must exist below the 16MB boundary and it is quite
82possible that we can't find a large enough free block in this region after
83the machine has been running for any amount of time. The way to avoid this
84problem is to allocate the DMA buffers during module load and deallocate
85them when the module is unloaded. For this to be effective we need to load
86the sound modules right after the kernel boots, either manually or by an
87init script, and keep them around until we shut down. This is a little
88wasteful of RAM, but it guarantees that sound always works.
89
90To make the sound driver use persistent DMA buffers we need to pass the
91sound.o module a "dmabuf=1" command-line argument. This is normally done
92in /etc/modprobe.d/*.conf files like so:
93
94options sound dmabuf=1
95
96If you have 16MB or less RAM or a PCI sound card, this is wasteful and
97unnecessary. It is possible that machine with 16MB or less RAM will find
98this option useful, but if your machine is so memory-starved that it
99cannot find a 64K block free, you will be wasting even more RAM by keeping
100the sound modules loaded and the DMA buffers allocated when they are not
101needed. The proper solution is to upgrade your RAM. But you do also have
102this improper solution as well. Use it wisely.
103
104 I'm afraid I know nothing about anything but my setup, being more of a
105text-mode guy anyway. If you have options for other cards or other helpful
106hints, send them to me, Jim Bray, jb@as220.org, http://as220.org/jb.
diff --git a/Documentation/sound/oss/README.ymfsb b/Documentation/sound/oss/README.ymfsb
deleted file mode 100644
index b6b77906b58d..000000000000
--- a/Documentation/sound/oss/README.ymfsb
+++ /dev/null
@@ -1,107 +0,0 @@
1Legacy audio driver for YMF7xx PCI cards.
2
3
4FIRST OF ALL
5============
6
7 This code references YAMAHA's sample codes and data sheets.
8 I respect and thank for all people they made open the information
9 about YMF7xx cards.
10
11 And this codes heavily based on Jeff Garzik <jgarzik@pobox.com>'s
12 old VIA 82Cxxx driver (via82cxxx.c). I also respect him.
13
14
15DISCLIMER
16=========
17
18 This driver is currently at early ALPHA stage. It may cause serious
19 damage to your computer when used.
20 PLEASE USE IT AT YOUR OWN RISK.
21
22
23ABOUT THIS DRIVER
24=================
25
26 This code enables you to use your YMF724[A-F], YMF740[A-C], YMF744, YMF754
27 cards. When enabled, your card acts as "SoundBlaster Pro" compatible card.
28 It can only play 22.05kHz / 8bit / Stereo samples, control external MIDI
29 port.
30 If you want to use your card as recent "16-bit" card, you should use
31 Alsa or OSS/Linux driver. Of course you can write native PCI driver for
32 your cards :)
33
34
35USAGE
36=====
37
38 # modprobe ymfsb (options)
39
40
41OPTIONS FOR MODULE
42==================
43
44 io : SB base address (0x220, 0x240, 0x260, 0x280)
45 synth_io : OPL3 base address (0x388, 0x398, 0x3a0, 0x3a8)
46 dma : DMA number (0,1,3)
47 master_volume: AC'97 PCM out Vol (0-100)
48 spdif_out : SPDIF-out flag (0:disable 1:enable)
49
50 These options will change in future...
51
52
53FREQUENCY
54=========
55
56 When playing sounds via this driver, you will hear its pitch is slightly
57 lower than original sounds. Since this driver recognizes your card acts
58 with 21.739kHz sample rates rather than 22.050kHz (I think it must be
59 hardware restriction). So many players become tone deafness.
60 To prevent this, you should express some options to your sound player
61 that specify correct sample frequency. For example, to play your MP3 file
62 correctly with mpg123, specify the frequency like following:
63
64 % mpg123 -r 21739 foo.mp3
65
66
67SPDIF OUT
68=========
69
70 With installing modules with option 'spdif_out=1', you can enjoy your
71 sounds from SPDIF-out of your card (if it had).
72 Its Fs is fixed to 48kHz (It never means the sample frequency become
73 up to 48kHz. All sounds via SPDIF-out also 22kHz samples). So your
74 digital-in capable components has to be able to handle 48kHz Fs.
75
76
77COPYING
78=======
79
80 This program is free software; you can redistribute it and/or modify
81 it under the terms of the GNU General Public License as published by
82 the Free Software Foundation; either version 2, or (at your option)
83 any later version.
84
85 This program is distributed in the hope that it will be useful, but
86 WITHOUT ANY WARRANTY; without even the implied warranty of
87 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
88 General Public License for more details.
89
90 You should have received a copy of the GNU General Public License
91 along with this program; if not, write to the Free Software
92 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
93
94
95TODO
96====
97 * support for multiple cards
98 (set the different SB_IO,MPU_IO,OPL_IO for each cards)
99
100 * support for OPL (dmfm) : There will be no requirements... :-<
101
102
103AUTHOR
104======
105
106 Daisuke Nagano <breeze.nagano@nifty.ne.jp>
107
diff --git a/Documentation/sound/oss/SoundPro b/Documentation/sound/oss/SoundPro
deleted file mode 100644
index 9d4db1f29d3c..000000000000
--- a/Documentation/sound/oss/SoundPro
+++ /dev/null
@@ -1,105 +0,0 @@
1Documentation for the SoundPro CMI8330 extensions in the WSS driver (ad1848.o)
2------------------------------------------------------------------------------
3
4( Be sure to read Documentation/sound/oss/CMI8330 too )
5
6Ion Badulescu, ionut@cs.columbia.edu
7February 24, 1999
8
9(derived from the OPL3-SA2 documentation by Scott Murray)
10
11The SoundPro CMI8330 (ISA) is a chip usually found on some Taiwanese
12motherboards. The official name in the documentation is CMI8330, SoundPro
13is the nickname and the big inscription on the chip itself.
14
15The chip emulates a WSS as well as a SB16, but it has certain differences
16in the mixer section which require separate support. It also emulates an
17MPU401 and an OPL3 synthesizer, so you probably want to enable support
18for these, too.
19
20The chip identifies itself as an AD1848, but its mixer is significantly
21more advanced than the original AD1848 one. If your system works with
22either WSS or SB16 and you are having problems with some mixer controls
23(no CD audio, no line-in, etc), you might want to give this driver a try.
24Detection should work, but it hasn't been widely tested, so it might still
25mis-identify the chip. You can still force soundpro=1 in the modprobe
26parameters for ad1848. Please let me know if it happens to you, so I can
27adjust the detection routine.
28
29The chip is capable of doing full-duplex, but since the driver sees it as an
30AD1848, it cannot take advantage of this. Moreover, the full-duplex mode is
31not achievable through the WSS interface, b/c it needs a dma16 line which is
32assigned only to the SB16 subdevice (with isapnp). Windows documentation
33says the user must use WSS Playback and SB16 Recording for full-duplex, so
34it might be possible to do the same thing under Linux. You can try loading
35up both ad1848 and sb then use one for playback and the other for
36recording. I don't know if this works, b/c I haven't tested it. Anyway, if
37you try it, be very careful: the SB16 mixer *mostly* works, but certain
38settings can have unexpected effects. Use the WSS mixer for best results.
39
40There is also a PCI SoundPro chip. I have not seen this chip, so I have
41no idea if the driver will work with it. I suspect it won't.
42
43As with PnP cards, some configuration is required. There are two ways
44of doing this. The most common is to use the isapnptools package to
45initialize the card, and use the kernel module form of the sound
46subsystem and sound drivers. Alternatively, some BIOS's allow manual
47configuration of installed PnP devices in a BIOS menu, which should
48allow using the non-modular sound drivers, i.e. built into the kernel.
49Since in this latter case you cannot use module parameters, you will
50have to enable support for the SoundPro at compile time.
51
52The IRQ and DMA values can be any that are considered acceptable for a
53WSS. Assuming you've got isapnp all happy, then you should be able to
54do something like the following (which *must* match the isapnp/BIOS
55configuration):
56
57modprobe ad1848 io=0x530 irq=11 dma=0 soundpro=1
58-and maybe-
59modprobe sb io=0x220 irq=5 dma=1 dma16=5
60
61-then-
62modprobe mpu401 io=0x330 irq=9
63modprobe opl3 io=0x388
64
65If all goes well and you see no error messages, you should be able to
66start using the sound capabilities of your system. If you get an
67error message while trying to insert the module(s), then make
68sure that the values of the various arguments match what you specified
69in your isapnp configuration file, and that there is no conflict with
70another device for an I/O port or interrupt. Checking the contents of
71/proc/ioports and /proc/interrupts can be useful to see if you're
72butting heads with another device.
73
74If you do not see the chipset version message, and none of the other
75messages present in the system log are helpful, try adding 'debug=1'
76to the ad1848 parameters, email me the syslog results and I'll do
77my best to help.
78
79Lastly, if you're using modules and want to set up automatic module
80loading with kmod, the kernel module loader, here is the section I
81currently use in my conf.modules file:
82
83# Sound
84post-install sound modprobe -k ad1848; modprobe -k mpu401; modprobe -k opl3
85options ad1848 io=0x530 irq=11 dma=0
86options sb io=0x220 irq=5 dma=1 dma16=5
87options mpu401 io=0x330 irq=9
88options opl3 io=0x388
89
90The above ensures that ad1848 will be loaded whenever the sound system
91is being used.
92
93Good luck.
94
95Ion
96
97NOT REALLY TESTED:
98- recording
99- recording device selection
100- full-duplex
101
102TODO:
103- implement mixer support for surround, loud, digital CD switches.
104- come up with a scheme which allows recording volumes for each subdevice.
105This is a major OSS API change.
diff --git a/Documentation/sound/oss/Soundblaster b/Documentation/sound/oss/Soundblaster
deleted file mode 100644
index b288d464ba8b..000000000000
--- a/Documentation/sound/oss/Soundblaster
+++ /dev/null
@@ -1,53 +0,0 @@
1modprobe sound
2insmod uart401
3insmod sb ...
4
5This loads the driver for the Sound Blaster and assorted clones. Cards that
6are covered by other drivers should not be using this driver.
7
8The Sound Blaster module takes the following arguments
9
10io I/O address of the Sound Blaster chip (0x220,0x240,0x260,0x280)
11irq IRQ of the Sound Blaster chip (5,7,9,10)
12dma 8-bit DMA channel for the Sound Blaster (0,1,3)
13dma16 16-bit DMA channel for SB16 and equivalent cards (5,6,7)
14mpu_io I/O for MPU chip if present (0x300,0x330)
15
16sm_games=1 Set if you have a Logitech soundman games
17acer=1 Set this to detect cards in some ACER notebooks
18mwave_bug=1 Set if you are trying to use this driver with mwave (see on)
19type Use this to specify a specific card type
20
21The following arguments are taken if ISAPnP support is compiled in
22
23isapnp=0 Set this to disable ISAPnP detection (use io=0xXXX etc. above)
24multiple=0 Set to disable detection of multiple Soundblaster cards.
25 Consider it a bug if this option is needed, and send in a
26 report.
27pnplegacy=1 Set this to be able to use a PnP card(s) along with a single
28 non-PnP (legacy) card. Above options for io, irq, etc. are
29 needed, and will apply only to the legacy card.
30reverse=1 Reverses the order of the search in the PnP table.
31uart401=1 Set to enable detection of mpu devices on some clones.
32isapnpjump=n Jumps to slot n in the driver's PnP table. Use the source,
33 Luke.
34
35You may well want to load the opl3 driver for synth music on most SB and
36clone SB devices
37
38insmod opl3 io=0x388
39
40Using Mwave
41
42To make this driver work with Mwave you must set mwave_bug. You also need
43to warm boot from DOS/Windows with the required firmware loaded under this
44OS. IBM are being difficult about documenting how to load this firmware.
45
46Avance Logic ALS007
47
48This card is supported; see the separate file ALS007 for full details.
49
50Avance Logic ALS100
51
52This card is supported; setup should be as for a standard Sound Blaster 16.
53The driver will identify the audio device as a "Sound Blaster 16 (ALS-100)".
diff --git a/Documentation/sound/oss/Tropez+ b/Documentation/sound/oss/Tropez+
deleted file mode 100644
index b93a6b734fc0..000000000000
--- a/Documentation/sound/oss/Tropez+
+++ /dev/null
@@ -1,26 +0,0 @@
1From: Paul Barton-Davis <pbd@op.net>
2
3Here is the configuration I use with a Tropez+ and my modular
4driver:
5
6 alias char-major-14 wavefront
7 alias synth0 wavefront
8 alias mixer0 cs4232
9 alias audio0 cs4232
10 pre-install wavefront modprobe "-k" "cs4232"
11 post-install wavefront modprobe "-k" "opl3"
12 options wavefront io=0x200 irq=9
13 options cs4232 synthirq=9 synthio=0x200 io=0x530 irq=5 dma=1 dma2=0
14 options opl3 io=0x388
15
16Things to note:
17
18 the wavefront options "io" and "irq" ***MUST*** match the "synthio"
19 and "synthirq" cs4232 options.
20
21 you can do without the opl3 module if you don't
22 want to use the OPL/[34] synth on the soundcard
23
24 the opl3 io parameter is conventionally not adjustable.
25
26Please see drivers/sound/README.wavefront for more details.
diff --git a/Documentation/sound/oss/VIBRA16 b/Documentation/sound/oss/VIBRA16
deleted file mode 100644
index 68a5a46beb88..000000000000
--- a/Documentation/sound/oss/VIBRA16
+++ /dev/null
@@ -1,80 +0,0 @@
1Sound Blaster 16X Vibra addendum
2--------------------------------
3by Marius Ilioaea <mariusi@protv.ro>
4 Stefan Laudat <stefan@asit.ro>
5
6Sat Mar 6 23:55:27 EET 1999
7
8 Hello again,
9
10 Playing with a SB Vibra 16x soundcard we found it very difficult
11to setup because the kernel reported a lot of DMA errors and wouldn't
12simply play any sound.
13 A good starting point is that the vibra16x chip full-duplex facility
14is neither still exploited by the sb driver found in the linux kernel
15(tried it with a 2.2.2-ac7), nor in the commercial OSS package (it reports
16it as half-duplex soundcard). Oh, I almost forgot, the RedHat sndconfig
17failed detecting it ;)
18 So, the big problem still remains, because the sb module wants a
198-bit and a 16-bit dma, which we could not allocate for vibra... it supports
20only two 8-bit dma channels, the second one will be passed to the module
21as a 16 bit channel, the kernel will yield about that but everything will
22be okay, trust us.
23 The only inconvenient you may find is that you will have
24some sound playing jitters if you have HDD dma support enabled - but this
25will happen with almost all soundcards...
26
27 A fully working isapnp.conf is just here:
28
29<snip here>
30
31(READPORT 0x0203)
32(ISOLATE PRESERVE)
33(IDENTIFY *)
34(VERBOSITY 2)
35(CONFLICT (IO FATAL)(IRQ FATAL)(DMA FATAL)(MEM FATAL)) # or WARNING
36# SB 16 and OPL3 devices
37(CONFIGURE CTL00f0/-1 (LD 0
38(INT 0 (IRQ 5 (MODE +E)))
39(DMA 0 (CHANNEL 1))
40(DMA 1 (CHANNEL 3))
41(IO 0 (SIZE 16) (BASE 0x0220))
42(IO 2 (SIZE 4) (BASE 0x0388))
43(NAME "CTL00f0/-1[0]{Audio }")
44(ACT Y)
45))
46
47# Joystick device - only if you need it :-/
48
49(CONFIGURE CTL00f0/-1 (LD 1
50(IO 0 (SIZE 1) (BASE 0x0200))
51(NAME "CTL00f0/-1[1]{Game }")
52(ACT Y)
53))
54(WAITFORKEY)
55
56<end of snipping>
57
58 So, after a good kernel modules compilation and a 'depmod -a kernel_ver'
59you may want to:
60
61modprobe sb io=0x220 irq=5 dma=1 dma16=3
62
63 Or, take the hard way:
64
65modprobe soundcore
66modprobe sound
67modprobe uart401
68modprobe sb io=0x220 irq=5 dma=1 dma16=3
69# do you need MIDI?
70modprobe opl3=0x388
71
72 Just in case, the kernel sound support should be:
73
74CONFIG_SOUND=m
75CONFIG_SOUND_OSS=m
76CONFIG_SOUND_SB=m
77
78 Enjoy your new noisy Linux box! ;)
79
80
diff --git a/Documentation/sound/oss/WaveArtist b/Documentation/sound/oss/WaveArtist
deleted file mode 100644
index f4f3407cd818..000000000000
--- a/Documentation/sound/oss/WaveArtist
+++ /dev/null
@@ -1,170 +0,0 @@
1
2 (the following is from the armlinux CVS)
3
4 WaveArtist mixer and volume levels can be accessed via these commands:
5
6 nn30 read registers nn, where nn = 00 - 09 for mixer settings
7 0a - 13 for channel volumes
8 mm31 write the volume setting in pairs, where mm = (nn - 10) / 2
9 rr32 write the mixer settings in pairs, where rr = nn/2
10 xx33 reset all settings to default
11 0y34 select mono source, y=0 = left, y=1 = right
12
13 bits
14 nn 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
15----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
16 00 | 0 | 0 0 1 1 | left line mixer gain | left aux1 mixer gain |lmute|
17----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
18 01 | 0 | 0 1 0 1 | left aux2 mixer gain | right 2 left mic gain |mmute|
19----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
20 02 | 0 | 0 1 1 1 | left mic mixer gain | left mic | left mixer gain |dith |
21----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
22 03 | 0 | 1 0 0 1 | left mixer input select |lrfg | left ADC gain |
23----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
24 04 | 0 | 1 0 1 1 | right line mixer gain | right aux1 mixer gain |rmute|
25----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
26 05 | 0 | 1 1 0 1 | right aux2 mixer gain | left 2 right mic gain |test |
27----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
28 06 | 0 | 1 1 1 1 | right mic mixer gain | right mic |right mixer gain |rbyps|
29----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
30 07 | 1 | 0 0 0 1 | right mixer select |rrfg | right ADC gain |
31----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
32 08 | 1 | 0 0 1 1 | mono mixer gain |right ADC mux sel|left ADC mux sel |
33----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
34 09 | 1 | 0 1 0 1 |loopb|left linout|loop|ADCch|TxFch|OffCD|test |loopb|loopb|osamp|
35----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
36 0a | 0 | left PCM channel volume |
37----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
38 0b | 0 | right PCM channel volume |
39----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
40 0c | 0 | left FM channel volume |
41----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
42 0d | 0 | right FM channel volume |
43----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
44 0e | 0 | left wavetable channel volume |
45----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
46 0f | 0 | right wavetable channel volume |
47----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
48 10 | 0 | left PCM expansion channel volume |
49----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
50 11 | 0 | right PCM expansion channel volume |
51----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
52 12 | 0 | left FM expansion channel volume |
53----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
54 13 | 0 | right FM expansion channel volume |
55----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
56
57 lmute: left mute
58 mmute: mono mute
59 dith: dithds
60 lrfg:
61 rmute: right mute
62 rbyps: right bypass
63 rrfg:
64 ADCch:
65 TxFch:
66 OffCD:
67 osamp:
68
69 And the following diagram is derived from the description in the CVS archive:
70
71 MIC L (mouthpiece)
72 +------+
73 -->PreAmp>-\
74 +--^---+ |
75 | |
76 r2b4-5 | +--------+
77 /----*-------------------------------->5 |
78 | | |
79 | /----------------------------------->4 |
80 | | | |
81 | | /--------------------------------->3 1of5 | +---+
82 | | | | mux >-->AMP>--> ADC L
83 | | | /------------------------------->2 | +-^-+
84 | | | | | | |
85 Line | | | | +----+ +------+ +---+ /---->1 | r3b3-0
86 ------------*->mute>--> Gain >--> | | | |
87 L | | | +----+ +------+ | | | *->0 |
88 | | | | | | +---^----+
89 Aux2 | | | +----+ +------+ | | | |
90 ----------*--->mute>--> Gain >--> M | | r8b0-2
91 L | | +----+ +------+ | | |
92 | | | | \------\
93 Aux1 | | +----+ +------+ | | |
94 --------*----->mute>--> Gain >--> I | |
95 L | +----+ +------+ | | |
96 | | | |
97 | +----+ +------+ | | +---+ |
98 *------->mute>--> Gain >--> X >-->AMP>--*
99 | +----+ +------+ | | +-^-+ |
100 | | | | |
101 | +----+ +------+ | | r2b1-3 |
102 | /----->mute>--> Gain >--> E | |
103 | | +----+ +------+ | | |
104 | | | | |
105 | | +----+ +------+ | | |
106 | | /--->mute>--> Gain >--> R | |
107 | | | +----+ +------+ | | |
108 | | | | | | r9b8-9
109 | | | +----+ +------+ | | | |
110 | | | /->mute>--> Gain >--> | | +---v---+
111 | | | | +----+ +------+ +---+ /-*->0 |
112 DAC | | | | | | |
113 ------------*----------------------------------->? | +----+
114 L | | | | | Mux >-->mute>--> L output
115 | | | | /->? | +--^-+
116 | | | | | | | |
117 | | | /--------->? | r0b0
118 | | | | | | +-------+
119 | | | | | |
120 Mono | | | | | | +-------+
121 ----------* | \---> | +----+
122 | | | | | | Mix >-->mute>--> Mono output
123 | | | | *-> | +--^-+
124 | | | | | +-------+ |
125 | | | | | r1b0
126 DAC | | | | | +-------+
127 ------------*-------------------------*--------->1 | +----+
128 R | | | | | | Mux >-->mute>--> R output
129 | | | | +----+ +------+ +---+ *->0 | +--^-+
130 | | | \->mute>--> Gain >--> | | +---^---+ |
131 | | | +----+ +------+ | | | | r5b0
132 | | | | | | r6b0
133 | | | +----+ +------+ | | |
134 | | \--->mute>--> Gain >--> M | |
135 | | +----+ +------+ | | |
136 | | | | |
137 | | +----+ +------+ | | |
138 | *----->mute>--> Gain >--> I | |
139 | | +----+ +------+ | | |
140 | | | | |
141 | | +----+ +------+ | | +---+ |
142 \------->mute>--> Gain >--> X >-->AMP>--*
143 | +----+ +------+ | | +-^-+ |
144 /--/ | | | |
145 Aux1 | +----+ +------+ | | r6b1-3 |
146 -------*------>mute>--> Gain >--> E | |
147 R | | +----+ +------+ | | |
148 | | | | |
149 Aux2 | | +----+ +------+ | | /------/
150 ---------*---->mute>--> Gain >--> R | |
151 R | | | +----+ +------+ | | |
152 | | | | | | +--------+
153 Line | | | +----+ +------+ | | | *->0 |
154 -----------*-->mute>--> Gain >--> | | | |
155 R | | | | +----+ +------+ +---+ \---->1 |
156 | | | | | |
157 | | | \-------------------------------->2 | +---+
158 | | | | Mux >-->AMP>--> ADC R
159 | | \---------------------------------->3 | +-^-+
160 | | | | |
161 | \------------------------------------>4 | r7b3-0
162 | | |
163 \-----*-------------------------------->5 |
164 | +---^----+
165 r6b4-5 | |
166 | | r8b3-5
167 +--v---+ |
168 -->PreAmp>-/
169 +------+
170 MIC R (electret mic)
diff --git a/Documentation/sound/oss/btaudio b/Documentation/sound/oss/btaudio
deleted file mode 100644
index effdb9a3f898..000000000000
--- a/Documentation/sound/oss/btaudio
+++ /dev/null
@@ -1,92 +0,0 @@
1
2Intro
3=====
4
5people start bugging me about this with questions, looks like I
6should write up some documentation for this beast. That way I
7don't have to answer that much mails I hope. Yes, I'm lazy...
8
9
10You might have noticed that the bt878 grabber cards have actually
11_two_ PCI functions:
12
13$ lspci
14[ ... ]
1500:0a.0 Multimedia video controller: Brooktree Corporation Bt878 (rev 02)
1600:0a.1 Multimedia controller: Brooktree Corporation Bt878 (rev 02)
17[ ... ]
18
19The first does video, it is backward compatible to the bt848. The second
20does audio. btaudio is a driver for the second function. It's a sound
21driver which can be used for recording sound (and _only_ recording, no
22playback). As most TV cards come with a short cable which can be plugged
23into your sound card's line-in you probably don't need this driver if all
24you want to do is just watching TV...
25
26
27Driver Status
28=============
29
30Still somewhat experimental. The driver should work stable, i.e. it
31should'nt crash your box. It might not work as expected, have bugs,
32not being fully OSS API compliant, ...
33
34Latest versions are available from http://bytesex.org/bttv/, the
35driver is in the bttv tarball. Kernel patches might be available too,
36have a look at http://bytesex.org/bttv/listing.html.
37
38The chip knows two different modes. btaudio registers two dsp
39devices, one for each mode. They can not be used at the same time.
40
41
42Digital audio mode
43==================
44
45The chip gives you 16 bit stereo sound. The sample rate depends on
46the external source which feeds the bt878 with digital sound via I2S
47interface. There is a insmod option (rate) to tell the driver which
48sample rate the hardware uses (32000 is the default).
49
50One possible source for digital sound is the msp34xx audio processor
51chip which provides digital sound via I2S with 32 kHz sample rate. My
52Hauppauge board works this way.
53
54The Osprey-200 reportly gives you digital sound with 44100 Hz sample
55rate. It is also possible that you get no sound at all.
56
57
58analog mode (A/D)
59=================
60
61You can tell the driver to use this mode with the insmod option "analog=1".
62The chip has three analog inputs. Consequently you'll get a mixer device
63to control these.
64
65The analog mode supports mono only. Both 8 + 16 bit. Both are _signed_
66int, which is uncommon for the 8 bit case. Sample rate range is 119 kHz
67to 448 kHz. Yes, the number of digits is correct. The driver supports
68downsampling by powers of two, so you can ask for more usual sample rates
69like 44 kHz too.
70
71With my Hauppauge I get noisy sound on the second input (mapped to line2
72by the mixer device). Others get a useable signal on line1.
73
74
75some examples
76=============
77
78* read audio data from btaudio (dsp2), send to es1730 (dsp,dsp1):
79 $ sox -w -r 32000 -t ossdsp /dev/dsp2 -t ossdsp /dev/dsp
80
81* read audio data from btaudio, send to esound daemon (which might be
82 running on another host):
83 $ sox -c 2 -w -r 32000 -t ossdsp /dev/dsp2 -t sw - | esdcat -r 32000
84 $ sox -c 1 -w -r 32000 -t ossdsp /dev/dsp2 -t sw - | esdcat -m -r 32000
85
86
87Have fun,
88
89 Gerd
90
91--
92Gerd Knorr <kraxel@bytesex.org>
diff --git a/Documentation/sound/oss/mwave b/Documentation/sound/oss/mwave
deleted file mode 100644
index 5fbcb1609275..000000000000
--- a/Documentation/sound/oss/mwave
+++ /dev/null
@@ -1,185 +0,0 @@
1 How to try to survive an IBM Mwave under Linux SB drivers
2
3
4+ IBM have now released documentation of sorts and Torsten is busy
5 trying to make the Mwave work. This is not however a trivial task.
6
7----------------------------------------------------------------------------
8
9OK, first thing - the IRQ problem IS a problem, whether the test is bypassed or
10not. It is NOT a Linux problem, but an MWAVE problem that is fixed with the
11latest MWAVE patches. So, in other words, don't bypass the test for MWAVES!
12
13I have Windows 95 on /dev/hda1, swap on /dev/hda2, and Red Hat 5 on /dev/hda3.
14
15The steps, then:
16
17 Boot to Linux.
18 Mount Windows 95 file system (assume mount point = /dos95).
19 mkdir /dos95/linux
20 mkdir /dos95/linux/boot
21 mkdir /dos95/linux/boot/parms
22
23 Copy the kernel, any initrd image, and loadlin to /dos95/linux/boot/.
24
25 Reboot to Windows 95.
26
27 Edit C:/msdos.sys and add or change the following:
28
29 Logo=0
30 BootGUI=0
31
32 Note that msdos.sys is a text file but it needs to be made 'unhidden',
33 readable and writable before it can be edited. This can be done with
34 DOS' "attrib" command.
35
36 Edit config.sys to have multiple config menus. I have one for windows 95 and
37 five for Linux, like this:
38------------
39[menu]
40menuitem=W95, Windows 95
41menuitem=LINTP, Linux - ThinkPad
42menuitem=LINTP3, Linux - ThinkPad Console
43menuitem=LINDOC, Linux - Docked
44menuitem=LINDOC3, Linux - Docked Console
45menuitem=LIN1, Linux - Single User Mode
46REM menudefault=W95,10
47
48[W95]
49
50[LINTP]
51
52[LINDOC]
53
54[LINTP3]
55
56[LINDOC3]
57
58[LIN1]
59
60[COMMON]
61FILES=30
62REM Please read README.TXT in C:\MWW subdirectory before changing the DOS= statement.
63DOS=HIGH,UMB
64DEVICE=C:\MWW\MANAGER\MWD50430.EXE
65SHELL=c:\command.com /e:2048
66-------------------
67
68The important things are the SHELL and DEVICE statements.
69
70 Then change autoexec.bat. Basically everything in there originally should be
71 done ONLY when Windows 95 is booted. Then you add new things specifically
72 for Linux. Mine is as follows
73
74---------------
75@ECHO OFF
76if "%CONFIG%" == "W95" goto W95
77
78REM
79REM Linux stuff
80REM
81SET MWPATH=C:\MWW\DLL;C:\MWW\MWGAMES;C:\MWW\DSP
82SET BLASTER=A220 I5 D1
83SET MWROOT=C:\MWW
84SET LIBPATH=C:\MWW\DLL
85SET PATH=C:\WINDOWS;C:\MWW\DLL;
86CALL MWAVE START NOSHOW
87c:\linux\boot\loadlin.exe @c:\linux\boot\parms\%CONFIG%.par
88
89:W95
90REM
91REM Windows 95 stuff
92REM
93c:\toolkit\guard
94SET MSINPUT=C:\MSINPUT
95SET MWPATH=C:\MWW\DLL;C:\MWW\MWGAMES;C:\MWW\DSP
96REM The following is used by DOS games to recognize Sound Blaster hardware.
97REM If hardware settings are changed, please change this line as well.
98REM See the Mwave README file for instructions.
99SET BLASTER=A220 I5 D1
100SET MWROOT=C:\MWW
101SET LIBPATH=C:\MWW\DLL
102SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;E:\ORAWIN95\BIN;f:\msdev\bin;e:\v30\bin.dbg;v:\devt\v30\bin;c:\JavaSDK\Bin;C:\MWW\DLL;
103SET INCLUDE=f:\MSDEV\INCLUDE;F:\MSDEV\MFC\INCLUDE
104SET LIB=F:\MSDEV\LIB;F:\MSDEV\MFC\LIB
105win
106
107------------------------
108
109Now build a file in c:\linux\boot\parms for each Linux config that you have.
110
111For example, my LINDOC3 config is for a docked Thinkpad at runlevel 3 with no
112initrd image, and has a parameter file named LINDOC3.PAR in c:\linux\boot\parms:
113
114-----------------------
115# LOADLIN @param_file image=other_image root=/dev/other
116#
117# Linux Console in docking station
118#
119c:\linux\boot\zImage.krn # First value must be filename of Linux kernel.
120root=/dev/hda3 # device which gets mounted as root FS
121ro # Other kernel arguments go here.
122apm=off
123doc=yes
1243
125-----------------------
126
127The doc=yes parameter is an environment variable used by my init scripts, not
128a kernel argument.
129
130However, the apm=off parameter IS a kernel argument! APM, at least in my setup,
131causes the kernel to crash when loaded via loadlin (but NOT when loaded via
132LILO). The APM stuff COULD be forced out of the kernel via the kernel compile
133options. Instead, I got an unofficial patch to the APM drivers that allows them
134to be dynamically deactivated via kernel arguments. Whatever you chose to
135document, APM, it seems, MUST be off for setups like mine.
136
137Now make sure C:\MWW\MWCONFIG.REF looks like this:
138
139----------------------
140[NativeDOS]
141Default=SB1.5
142SBInputSource=CD
143SYNTH=FM
144QSound=OFF
145Reverb=OFF
146Chorus=OFF
147ReverbDepth=5
148ChorusDepth=5
149SBInputVolume=5
150SBMainVolume=10
151SBWaveVolume=10
152SBSynthVolume=10
153WaveTableVolume=10
154AudioPowerDriver=ON
155
156[FastCFG]
157Show=No
158HideOption=Off
159-----------------------------
160
161OR the Default= line COULD be
162
163Default=SBPRO
164
165Reboot to Windows 95 and choose Linux. When booted, use sndconfig to configure
166the sound modules and voilà - ThinkPad sound with Linux.
167
168Now the gotchas - you can either have CD sound OR Mixers but not both. That's a
169problem with the SB1.5 (CD sound) or SBPRO (Mixers) settings. No one knows why
170this is!
171
172For some reason MPEG3 files, when played through mpg123, sound like they
173are playing at 1/8th speed - not very useful! If you have ANY insight
174on why this second thing might be happening, I would be grateful.
175
176===========================================================
177 _/ _/_/_/_/
178 _/_/ _/_/ _/
179 _/ _/_/ _/_/_/_/ Martin John Bartlett
180 _/ _/ _/ _/ (martin@nitram.demon.co.uk)
181_/ _/_/_/_/
182 _/
183_/ _/
184 _/_/
185===========================================================
diff --git a/Documentation/sound/oss/oss-parameters.txt b/Documentation/sound/oss/oss-parameters.txt
deleted file mode 100644
index cc675f25eee4..000000000000
--- a/Documentation/sound/oss/oss-parameters.txt
+++ /dev/null
@@ -1,51 +0,0 @@
1 OSS Kernel Parameters
2 ~~~~~~~~~~~~~~~~~~~~~
3
4See Documentation/admin-guide/kernel-parameters.rst for general information on
5specifying module parameters.
6
7This document may not be entirely up to date and comprehensive. The command
8"modinfo -p ${modulename}" shows a current list of all parameters of a loadable
9module. Loadable modules, after being loaded into the running kernel, also
10reveal their parameters in /sys/module/${modulename}/parameters/. Some of these
11parameters may be changed at runtime by the command
12"echo -n ${value} > /sys/module/${modulename}/parameters/${parm}".
13
14
15 ad1848= [HW,OSS]
16 Format: <io>,<irq>,<dma>,<dma2>,<type>
17
18 aedsp16= [HW,OSS] Audio Excel DSP 16
19 Format: <io>,<irq>,<dma>,<mss_io>,<mpu_io>,<mpu_irq>
20 See also header of sound/oss/aedsp16.c.
21
22 dmasound= [HW,OSS] Sound subsystem buffers
23
24 mpu401= [HW,OSS]
25 Format: <io>,<irq>
26
27 opl3= [HW,OSS]
28 Format: <io>
29
30 pas2= [HW,OSS] Format:
31 <io>,<irq>,<dma>,<dma16>,<sb_io>,<sb_irq>,<sb_dma>,<sb_dma16>
32
33 pss= [HW,OSS] Personal Sound System (ECHO ESC614)
34 Format:
35 <io>,<mss_io>,<mss_irq>,<mss_dma>,<mpu_io>,<mpu_irq>
36
37 sscape= [HW,OSS]
38 Format: <io>,<irq>,<dma>,<mpu_io>,<mpu_irq>
39
40 trix= [HW,OSS] MediaTrix AudioTrix Pro
41 Format:
42 <io>,<irq>,<dma>,<dma2>,<sb_io>,<sb_irq>,<sb_dma>,<mpu_io>,<mpu_irq>
43
44 uart401= [HW,OSS]
45 Format: <io>,<irq>
46
47 uart6850= [HW,OSS]
48 Format: <io>,<irq>
49
50 waveartist= [HW,OSS]
51 Format: <io>,<irq>,<dma>,<dma2>
diff --git a/Documentation/sound/oss/ultrasound b/Documentation/sound/oss/ultrasound
deleted file mode 100644
index eed331c738a3..000000000000
--- a/Documentation/sound/oss/ultrasound
+++ /dev/null
@@ -1,30 +0,0 @@
1modprobe sound
2insmod ad1848
3insmod gus io=* irq=* dma=* ...
4
5This loads the driver for the Gravis Ultrasound family of sound cards.
6
7The gus module takes the following arguments
8
9io I/O address of the Ultrasound card (eg. io=0x220)
10irq IRQ of the Sound Blaster card
11dma DMA channel for the Sound Blaster
12dma16 2nd DMA channel, only needed for full duplex operation
13type 1 for PnP card
14gus16 1 for using 16 bit sampling daughter board
15no_wave_dma Set to disable DMA usage for wavetable (see note)
16db16 ???
17
18
19no_wave_dma option
20
21This option defaults to a value of 0, which allows the Ultrasound wavetable
22DSP to use DMA for playback and downloading samples. This is the same
23as the old behaviour. If set to 1, no DMA is needed for downloading samples,
24and allows owners of a GUS MAX to make use of simultaneous digital audio
25(/dev/dsp), MIDI, and wavetable playback.
26
27
28If you have problems in recording with GUS MAX, you could try to use
29just one 8 bit DMA channel. Recording will not work with one DMA
30channel if it's a 16 bit one.
diff --git a/MAINTAINERS b/MAINTAINERS
index 2d3d750b19c0..01f0b76dcc06 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -527,11 +527,6 @@ W: http://ez.analog.com/community/linux-device-drivers
527S: Supported 527S: Supported
528F: drivers/input/misc/adxl34x.c 528F: drivers/input/misc/adxl34x.c
529 529
530AEDSP16 DRIVER
531M: Riccardo Facchetti <fizban@tin.it>
532S: Maintained
533F: sound/oss/aedsp16.c
534
535AF9013 MEDIA DRIVER 530AF9013 MEDIA DRIVER
536M: Antti Palosaari <crope@iki.fi> 531M: Antti Palosaari <crope@iki.fi>
537L: linux-media@vger.kernel.org 532L: linux-media@vger.kernel.org
@@ -9199,12 +9194,6 @@ F: include/linux/dt-bindings/mux/
9199F: include/linux/mux/ 9194F: include/linux/mux/
9200F: drivers/mux/ 9195F: drivers/mux/
9201 9196
9202MULTISOUND SOUND DRIVER
9203M: Andrew Veliath <andrewtv@usa.net>
9204S: Maintained
9205F: Documentation/sound/oss/MultiSound
9206F: sound/oss/msnd*
9207
9208MULTITECH MULTIPORT CARD (ISICOM) 9197MULTITECH MULTIPORT CARD (ISICOM)
9209S: Orphan 9198S: Orphan
9210F: drivers/tty/isicom.c 9199F: drivers/tty/isicom.c
diff --git a/sound/Kconfig b/sound/Kconfig
index d7d2aac9542e..b6d047985905 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -3,25 +3,7 @@ menuconfig SOUND
3 depends on HAS_IOMEM 3 depends on HAS_IOMEM
4 help 4 help
5 If you have a sound card in your computer, i.e. if it can say more 5 If you have a sound card in your computer, i.e. if it can say more
6 than an occasional beep, say Y. Be sure to have all the information 6 than an occasional beep, say Y.
7 about your sound card and its configuration down (I/O port,
8 interrupt and DMA channel), because you will be asked for it.
9
10 You want to read the Sound-HOWTO, available from
11 <http://www.tldp.org/docs.html#howto>. General information about
12 the modular sound system is contained in the files
13 <file:Documentation/sound/oss/Introduction>. The file
14 <file:Documentation/sound/oss/README.OSS> contains some slightly
15 outdated but still useful information as well. Newer sound
16 driver documentation is found in <file:Documentation/sound/alsa/*>.
17
18 If you have a PnP sound card and you want to configure it at boot
19 time using the ISA PnP tools (read
20 <http://www.roestock.demon.co.uk/isapnptools/>), then you need to
21 compile the sound card support as a module and load that module
22 after the PnP configuration is finished. To do this, choose M here
23 and read <file:Documentation/sound/oss/README.modules>; the module
24 will be called soundcore.
25 7
26if SOUND 8if SOUND
27 9
@@ -114,19 +96,6 @@ source "sound/synth/Kconfig"
114 96
115endif # SND 97endif # SND
116 98
117menuconfig SOUND_PRIME
118 tristate "Open Sound System (DEPRECATED)"
119 select SOUND_OSS_CORE
120 depends on BROKEN
121 help
122 Say 'Y' or 'M' to enable Open Sound System drivers.
123
124if SOUND_PRIME
125
126source "sound/oss/Kconfig"
127
128endif # SOUND_PRIME
129
130endif # !UML 99endif # !UML
131 100
132endif # SOUND 101endif # SOUND
diff --git a/sound/Makefile b/sound/Makefile
index 6de45d2c32f7..e5794fdd3d79 100644
--- a/sound/Makefile
+++ b/sound/Makefile
@@ -2,8 +2,7 @@
2# 2#
3 3
4obj-$(CONFIG_SOUND) += soundcore.o 4obj-$(CONFIG_SOUND) += soundcore.o
5obj-$(CONFIG_SOUND_PRIME) += oss/ 5obj-$(CONFIG_DMASOUND) += oss/dmasound/
6obj-$(CONFIG_DMASOUND) += oss/
7obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ 6obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
8 firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/ 7 firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/
9obj-$(CONFIG_SND_AOA) += aoa/ 8obj-$(CONFIG_SND_AOA) += aoa/
diff --git a/sound/oss/CHANGELOG b/sound/oss/CHANGELOG
deleted file mode 100644
index 8706cd66ca1f..000000000000
--- a/sound/oss/CHANGELOG
+++ /dev/null
@@ -1,369 +0,0 @@
1Note these changes relate to Hannu's code and don't include the changes
2made outside of this for modularising the sound
3
4Changelog for version 3.8o
5--------------------------
6
7Since 3.8h
8- Included support for OPL3-SA1 and SoftOSS
9
10Since 3.8
11- Fixed SNDCTL_DSP_GETOSPACE
12- Compatibility fixes for Linux 2.1.47
13
14Since 3.8-beta21
15- Fixed all known bugs (I think).
16
17Since 3.8-beta8
18- Lot of fixes to audio playback code in dmabuf.c
19
20Since 3.8-beta6
21- Fixed the famous Quake delay bug.
22
23Since 3.8-beta5
24- Fixed many bugs in audio playback.
25
26Since 3.8-beta4
27- Just minor changes.
28
29Since 3.8-beta1
30- Major rewrite of audio playback handling.
31- Added AWE32 support by Takashi Iwai (in ./lowlevel/).
32
33Since 3.7-beta#
34- Passing of ioctl() parameters between soundcard.c and other modules has been
35changed so that arg always points to kernel space.
36- Some bugfixes.
37
38Since 3.7-beta5
39- Disabled MIDI input with GUS PnP (Interwave). There seems to be constant
40stream of received 0x00 bytes when the MIDI receiver is enabled.
41
42Since 3.5
43- Changes almost everywhere.
44- Support for OPTi 82C924-based sound cards.
45
46Since 3.5.4-beta8
47- Fixed a bug in handling of non-fragment sized writes in 16 bit/stereo mode
48 with GUS.
49- Limited minimum fragment size with some audio devices (GUS=512 and
50 SB=32). These devices require more time to "recover" from processing
51 of each fragment.
52
53Since 3.5.4-beta6/7
54- There seems to be problems in the OPTi 82C930 so cards based on this
55 chip don't necessarily work yet. There are problems in detecting the
56 MIDI interface. Also mixer volumes may be seriously wrong on some systems.
57 You can safely use this driver version with C930 if it looks to work.
58 However please don't complain if you have problems with it. C930 support
59 should be fixed in future releases.
60- Got initialization of GUS PnP to work. With this version GUS PnP should
61 work in GUS compatible mode after initialization using isapnptools.
62- Fixed a bug in handling of full duplex cards in write only mode. This has
63 been causing "audio device opening" errors with RealAudio player.
64
65Since 3.5.4.beta5
66- Changes to OPTi 82C930 driver.
67- Major changes to the Soundscape driver. The driver requires now just one
68 DMA channel. The extra audio/dsp device (the "Not functional" one) used
69 for code download in the earlier versions has been eliminated. There is now
70 just one /dev/dsp# device which is used both for code download and audio.
71
72Since 3.5.4.beta4
73- Minor changes.
74
75Since 3.5.4-beta2
76- Fixed silent playback with ESS 688/1688.
77- Got SB16 to work without the 16 bit DMA channel (only the 8 bit one
78 is required for 8 and 16 bit modes).
79- Added the "lowlevel" subdirectory for additional low level drivers that
80 are not part of USS core. See lowlevel/README for more info.
81- Included support for ACI mixer (by Markus Kuhn). ACI is a mixer used in
82 miroPCM sound cards. See lowlevel/aci.readme for more info.
83- Support for Aztech Washington chipset (AZT2316 ASIC).
84
85Since 3.5.4-beta1
86- Reduced clicking with AD1848.
87- Support for OPTi 82C930. Only half duplex at this time. 16 bit playback
88 is sometimes just white noise (occurs randomly).
89
90Since 3.5.2
91- Major changes to the SB/Jazz16/ESS driver (most parts rewritten).
92 The most noticeable new feature is support for multiple SB cards at the same
93 time.
94- Renamed sb16_midi.c to uart401.c. Also modified it to work also with
95 other MPU401 UART compatible cards than SB16/ESS/Jazz.
96- Some changes which reduce clicking in audio playback.
97- Copying policy is now GPL.
98
99Since 3.5.1
100- TB Maui initialization support
101Since 3.5
102- Improved handling of playback underrun situations.
103
104Since 3.5-beta10
105- Bug fixing
106
107Since 3.5-beta9
108- Fixed for compatibility with Linux 1.3.70 and later.
109- Changed boot time passing of 16 bit DMA channel number to SB driver.
110
111Since 3.5-beta8
112- Minor changes
113
114Since 3.5-beta7
115- enhancements to configure program (by Jeff Tranter):
116 - prompts are in same format as 1.3.x Linux kernel config program
117 - on-line help for each question
118 - fixed some compile warnings detected by gcc/g++ -Wall
119 - minor grammatical changes to prompts
120
121Since 3.5-beta6
122- Fixed bugs in mmap() support.
123- Minor changes to Maui driver.
124
125Since 3.5-beta5
126- Fixed crash after recording with ESS688. It's generally a good
127 idea to stop inbound DMA transfers before freeing the memory
128 buffer.
129- Fixed handling of AD1845 codec (for example Shuttle Sound System).
130- Few other fixes.
131
132Since 3.5-beta4
133- Fixed bug in handling of uninitialized instruments with GUS.
134
135Since 3.5-beta3
136- Few changes which decrease popping at end/beginning of audio playback.
137
138Since 3.5-beta2
139- Removed MAD16+CS4231 hack made in previous version since it didn't
140 help.
141- Fixed the above bug in proper way and in proper place. Many thanks
142 to James Hightower.
143
144Since 3.5-beta1
145- Bug fixes.
146- Full duplex audio with MAD16+CS4231 may work now. The driver configures
147 SB DMA of MAD16 so that it doesn't conflict with codec's DMA channels.
148 The side effect is that all 8 bit DMA channels (0,1,3) are populated in
149 duplex mode.
150
151Since 3.5-alpha9
152- Bug fixes (mostly in Jazz16 and ESS1688/688 supports).
153- Temporarily disabled recording with ESS1688/688 since it causes crash.
154- Changed audio buffer partitioning algorithm so that it selects
155 smaller fragment size than earlier. This improves real time capabilities
156 of the driver and makes recording to disk to work better. Unfortunately
157 this change breaks some programs which assume that fragments cannot be
158 shorter than 4096 bytes.
159
160Since 3.5-alpha8
161- Bug fixes
162
163Since 3.5-alpha7
164- Linux kernel compatible configuration (_EXPERIMENTAL_). Enable
165 using command "cd /linux/drivers/sound;make script" and then
166 just run kernel's make config normally.
167- Minor fixes to the SB support. Hopefully the driver works with
168 all SB models now.
169- Added support for ESS ES1688 "AudioDrive" based cards.
170
171Since 3.5-alpha6
172- SB Pro and SB16 supports are no longer separately selectable options.
173 Enabling SB enables them too.
174- Changed all #ifndef EXCLUDE_xx stuff to #ifdef CONFIG_xx. Modified
175configure to handle this.
176- Removed initialization messages from the
177modularized version. They can be enabled by using init_trace=1 in
178the insmod command line (insmod sound init_trace=1).
179- More AIX stuff.
180- Added support for synchronizing dsp/audio devices with /dev/sequencer.
181- mmap() support for dsp/audio devices.
182
183Since 3.5-alpha5
184- AIX port.
185- Changed some xxx_PATCH macros in soundcard.h to work with
186 big endian machines.
187
188Since 3.5-alpha4
189- Removed the 'setfx' stuff from the version distributed with kernel
190 sources. Running 'setfx' is required again.
191
192Since 3.5-alpha3
193- Moved stuff from the 'setfx' program to the AudioTrix Pro driver.
194
195Since 3.5-alpha2
196- Modifications to makefile and configure.c. Unnecessary sources
197 are no longer compiled. Newly created local.h is also copied to
198 /etc/soundconf. "make oldconfig" reads /etc/soundconf and produces
199 new local.h which is compatible with current version of the driver.
200- Some fixes to the SB16 support.
201- Fixed random protection fault in gus_wave.c
202
203Since 3.5-alpha1
204- Modified to work with Linux-1.3.33 and later
205- Some minor changes
206
207Since 3.0.2
208- Support for CS4232 based PnP cards (AcerMagic S23 etc).
209- Full duplex support for some CS4231, CS4232 and AD1845 based cards
210(GUS MAX, AudioTrix Pro, AcerMagic S23 and many MAD16/Mozart cards
211having a codec mentioned above).
212- Almost fully rewritten loadable modules support.
213- Fixed some bugs.
214- Huge amount of testing (more testing is still required).
215- mmap() support (works with some cards). Requires much more testing.
216- Sample/patch/program loading for TB Maui/Tropez. No initialization
217since TB doesn't allow me to release that code.
218- Using CS4231 compatible codecs as timer for /dev/music.
219
220Since 3.0.1
221- Added allocation of I/O ports, DMA channels and interrupts
222to the initialization code. This may break modules support since
223the driver may not free some resources on unload. Should be fixed soon.
224
225Since 3.0
226- Some important bug fixes.
227- select() for /dev/dsp and /dev/audio (Linux only).
228(To use select() with read, you have to call read() to start
229the recording. Calling write() kills recording immediately so
230use select() carefully when you are writing a half duplex app.
231Full duplex mode is not implemented yet.) Select works also with
232/dev/sequencer and /dev/music. Maybe with /dev/midi## too.
233
234Since 3.0-beta2
235- Minor fixes.
236- Added Readme.cards
237
238Since 3.0-beta1
239- Minor fixes to the modules support.
240- Eliminated call to sb_free_irq() in ad1848.c
241- Rewritten MAD16&Mozart support (not tested with MAD16 Pro).
242- Fix to DMA initialization of PSS cards.
243- Some fixes to ad1848/cs42xx mixer support (GUS MAX, MSS, etc.)
244- Fixed some bugs in the PSS driver which caused I/O errors with
245 the MSS mode (/dev/dsp).
246
247Since 3.0-950506
248- Recording with GUS MAX fixed. It works when the driver is configured
249 to use two DMA channels with GUS MAX (16 bit ones recommended).
250
251Since 3.0-94xxxx
252- Too many changes
253
254Since 3.0-940818
255- Fixes for Linux 1.1.4x.
256- Disables Disney Sound System with SG NX Pro 16 (less noise).
257
258Since 2.90-2
259- Fixes to soundcard.h
260- Non blocking mode to /dev/sequencer
261- Experimental detection code for Ensoniq Soundscape.
262
263Since 2.90
264- Minor and major bug fixes
265
266Since pre-3.0-940712
267- GUS MAX support
268- Partially working MSS/WSS support (could work with some cards).
269- Hardware u-Law and A-Law support with AD1848/CS4248 and CS4231 codecs
270 (GUS MAX, GUS16, WSS etc). Hardware ADPCM is possible with GUS16 and
271 GUS MAX, but it doesn't work yet.
272Since pre-3.0-940426
273- AD1848/CS4248/CS4231 codec support (MSS, GUS MAX, Aztec, Orchid etc).
274This codec chip is used in various sound cards. This version is developed
275for the 16 bit daughtercard of GUS. It should work with other cards also
276if the following requirements are met:
277 - The I/O, IRQ and DMA settings are jumper selectable or
278 the card is initialized by booting DOS before booting Linux (etc.).
279 - You add the IO, IRQ and DMA settings manually to the local.h.
280 (Just define GUS16_BASE, GUS16_IRQ and GUS16_DMA). Note that
281 the base address bust be the base address of the codec chip not the
282 card itself. For the GUS16 these are the same but most MSS compatible
283 cards have the codec located at card_base+4.
284- Some minor changes
285
286Since 2.5 (******* MAJOR REWRITE ***********)
287
288This version is based on v2.3. I have tried to maintain two versions
289together so that this one should have the same features than v2.5.
290Something may still be missing. If you notice such things, please let me
291know.
292
293The Readme.v30 contains more details.
294
295- /dev/midi## devices.
296- /dev/sequencer2
297
298Since 2.5-beta2
299- Some fine tuning to the GUS v3.7 mixer code.
300- Fixed speed limits for the plain SB (1.0 to 2.0).
301
302Since 2.5-beta
303- Fixed OPL-3 detection with SB. Caused problems with PAS16.
304- GUS v3.7 mixer support.
305
306Since 2.4
307- Mixer support for Sound Galaxy NX Pro (define __SGNXPRO__ on your local.h).
308- Fixed truncated sound on /dev/dsp when the device is closed.
309- Linear volume mode for GUS
310- Pitch bends larger than +/- 2 octaves.
311- MIDI recording for SB and SB Pro. (Untested).
312- Some other fixes.
313- SB16 MIDI and DSP drivers only initialized if SB16 actually installed.
314- Implemented better detection for OPL-3. This should be useful if you
315 have an old SB Pro (the non-OPL-3 one) or a SB 2.0 clone which has a OPL-3.
316- SVR4.2 support by Ian Hartas. Initial ALPHA TEST version (untested).
317
318Since 2.3b
319- Fixed bug which made it impossible to make long recordings to disk.
320 Recording was not restarted after a buffer overflow situation.
321- Limited mixer support for GUS.
322- Numerous improvements to the GUS driver by Andrew Robinson. Including
323 some click removal etc.
324
325Since 2.3
326- Fixed some minor bugs in the SB16 driver.
327
328Since 2.2b
329- Full SB16 DSP support. 8/16 bit, mono/stereo
330- The SCO and FreeBSD versions should be in sync now. There are some
331 problems with SB16 and GUS in the FreeBSD versions.
332 The DMA buffer allocation of the SCO version has been polished but
333 there could still be some problems. At least it hogs memory.
334 The DMA channel
335 configuration method used in the SCO/System is a hack.
336- Support for the MPU emulation of the SB16.
337- Some big arrays are now allocated boot time. This makes the BSS segment
338 smaller which makes it possible to use the full driver with
339 NetBSD. These arrays are not allocated if no suitable sound card is available.
340- Fixed a bug in the compute_and_set_volume in gus_wave.c
341- Fixed the too fast mono playback problem of SB Pro and PAS16.
342
343Since 2.2
344- Stereo recording for SB Pro. Somehow it was missing and nobody
345 had noticed it earlier.
346- Minor polishing.
347- Interpreting of boot time arguments (sound=) for Linux.
348- Breakup of sb_dsp.c. Parts of the code has been moved to
349 sb_mixer.c and sb_midi.c
350
351Since 2.1
352- Preliminary support for SB16.
353 - The SB16 mixer is supported in its native mode.
354 - Digitized voice capability up to 44.1 kHz/8 bit/mono
355 (16 bit and stereo support coming in the next release).
356- Fixed some bugs in the digitized voice driver for PAS16.
357- Proper initialization of the SB emulation of latest PAS16 models.
358
359- Significantly improved /dev/dsp and /dev/audio support.
360 - Now supports half duplex mode. It's now possible to record and
361 playback without closing and reopening the device.
362 - It's possible to use smaller buffers than earlier. There is a new
363 ioctl(fd, SNDCTL_DSP_SUBDIVIDE, &n) where n should be 1, 2 or 4.
364 This call instructs the driver to use smaller buffers. The default
365 buffer size (0.5 to 1.0 seconds) is divided by n. Should be called
366 immediately after opening the device.
367
368Since 2.0
369Just cosmetic changes.
diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig
deleted file mode 100644
index 4033fe58f0cf..000000000000
--- a/sound/oss/Kconfig
+++ /dev/null
@@ -1,533 +0,0 @@
1# 18 Apr 1998, Michael Elizabeth Chastain, <mailto:mec@shout.net>
2# More hacking for modularisation.
3#
4# Prompt user for primary drivers.
5
6config SOUND_BCM_CS4297A
7 tristate "Crystal Sound CS4297a (for Swarm)"
8 depends on SIBYTE_SWARM
9 help
10 The BCM91250A has a Crystal CS4297a on synchronous serial
11 port B (in addition to the DB-9 serial port). Say Y or M
12 here to enable the sound chip instead of the UART. Also
13 note that CONFIG_KGDB should not be enabled at the same
14 time, since it also attempts to use this UART port.
15
16config SOUND_MSNDCLAS
17 tristate "Support for Turtle Beach MultiSound Classic, Tahiti, Monterey"
18 depends on (m || !STANDALONE) && ISA
19 help
20 Say M here if you have a Turtle Beach MultiSound Classic, Tahiti or
21 Monterey (not for the Pinnacle or Fiji).
22
23 See <file:Documentation/sound/oss/MultiSound> for important information
24 about this driver. Note that it has been discontinued, but the
25 Voyetra Turtle Beach knowledge base entry for it is still available
26 at <http://www.turtlebeach.com/site/kb_ftp/790.asp>.
27
28comment "Compiled-in MSND Classic support requires firmware during compilation."
29 depends on SOUND_PRIME && SOUND_MSNDCLAS=y
30
31config MSNDCLAS_HAVE_BOOT
32 bool
33 depends on SOUND_MSNDCLAS=y && !STANDALONE
34 default y
35
36config MSNDCLAS_INIT_FILE
37 string "Full pathname of MSNDINIT.BIN firmware file"
38 depends on SOUND_MSNDCLAS
39 default "/etc/sound/msndinit.bin"
40 help
41 The MultiSound cards have two firmware files which are required for
42 operation, and are not currently included. These files can be
43 obtained from Turtle Beach. See
44 <file:Documentation/sound/oss/MultiSound> for information on how to
45 obtain this.
46
47config MSNDCLAS_PERM_FILE
48 string "Full pathname of MSNDPERM.BIN firmware file"
49 depends on SOUND_MSNDCLAS
50 default "/etc/sound/msndperm.bin"
51 help
52 The MultiSound cards have two firmware files which are required for
53 operation, and are not currently included. These files can be
54 obtained from Turtle Beach. See
55 <file:Documentation/sound/oss/MultiSound> for information on how to
56 obtain this.
57
58config MSNDCLAS_IRQ
59 int "MSND Classic IRQ 5, 7, 9, 10, 11, 12"
60 depends on SOUND_MSNDCLAS=y
61 default "5"
62 help
63 Interrupt Request line for the MultiSound Classic and related cards.
64
65config MSNDCLAS_MEM
66 hex "MSND Classic memory B0000, C8000, D0000, D8000, E0000, E8000"
67 depends on SOUND_MSNDCLAS=y
68 default "D0000"
69 help
70 Memory-mapped I/O base address for the MultiSound Classic and
71 related cards.
72
73config MSNDCLAS_IO
74 hex "MSND Classic I/O 210, 220, 230, 240, 250, 260, 290, 3E0"
75 depends on SOUND_MSNDCLAS=y
76 default "290"
77 help
78 I/O port address for the MultiSound Classic and related cards.
79
80config SOUND_MSNDPIN
81 tristate "Support for Turtle Beach MultiSound Pinnacle, Fiji"
82 depends on (m || !STANDALONE) && ISA
83 help
84 Say M here if you have a Turtle Beach MultiSound Pinnacle or Fiji.
85 See <file:Documentation/sound/oss/MultiSound> for important information
86 about this driver. Note that it has been discontinued, but the
87 Voyetra Turtle Beach knowledge base entry for it is still available
88 at <http://www.turtlebeach.com/site/kb_ftp/600.asp>.
89
90comment "Compiled-in MSND Pinnacle support requires firmware during compilation."
91 depends on SOUND_PRIME && SOUND_MSNDPIN=y
92
93config MSNDPIN_HAVE_BOOT
94 bool
95 depends on SOUND_MSNDPIN=y
96 default y
97
98config MSNDPIN_INIT_FILE
99 string "Full pathname of PNDSPINI.BIN firmware file"
100 depends on SOUND_MSNDPIN
101 default "/etc/sound/pndspini.bin"
102 help
103 The MultiSound cards have two firmware files which are required
104 for operation, and are not currently included. These files can be
105 obtained from Turtle Beach. See
106 <file:Documentation/sound/oss/MultiSound> for information on how to
107 obtain this.
108
109config MSNDPIN_PERM_FILE
110 string "Full pathname of PNDSPERM.BIN firmware file"
111 depends on SOUND_MSNDPIN
112 default "/etc/sound/pndsperm.bin"
113 help
114 The MultiSound cards have two firmware files which are required for
115 operation, and are not currently included. These files can be
116 obtained from Turtle Beach. See
117 <file:Documentation/sound/oss/MultiSound> for information on how to
118 obtain this.
119
120config MSNDPIN_IRQ
121 int "MSND Pinnacle IRQ 5, 7, 9, 10, 11, 12"
122 depends on SOUND_MSNDPIN=y
123 default "5"
124 help
125 Interrupt request line for the primary synthesizer on MultiSound
126 Pinnacle and Fiji sound cards.
127
128config MSNDPIN_MEM
129 hex "MSND Pinnacle memory B0000, C8000, D0000, D8000, E0000, E8000"
130 depends on SOUND_MSNDPIN=y
131 default "D0000"
132 help
133 Memory-mapped I/O base address for the primary synthesizer on
134 MultiSound Pinnacle and Fiji sound cards.
135
136config MSNDPIN_IO
137 hex "MSND Pinnacle I/O 210, 220, 230, 240, 250, 260, 290, 3E0"
138 depends on SOUND_MSNDPIN=y
139 default "290"
140 help
141 Memory-mapped I/O base address for the primary synthesizer on
142 MultiSound Pinnacle and Fiji sound cards.
143
144config MSNDPIN_DIGITAL
145 bool "MSND Pinnacle has S/PDIF I/O"
146 depends on SOUND_MSNDPIN=y
147 help
148 If you have the S/PDIF daughter board for the Pinnacle or Fiji,
149 answer Y here; otherwise, say N. If you have this, you will be able
150 to play and record from the S/PDIF port (digital signal). See
151 <file:Documentation/sound/oss/MultiSound> for information on how to make
152 use of this capability.
153
154config MSNDPIN_NONPNP
155 bool "MSND Pinnacle non-PnP Mode"
156 depends on SOUND_MSNDPIN=y
157 help
158 The Pinnacle and Fiji card resources can be configured either with
159 PnP, or through a configuration port. Say Y here if your card is NOT
160 in PnP mode. For the Pinnacle, configuration in non-PnP mode allows
161 use of the IDE and joystick peripherals on the card as well; these
162 do not show up when the card is in PnP mode. Specifying zero for any
163 resource of a device will disable the device. If you are running the
164 card in PnP mode, you must say N here and use isapnptools to
165 configure the card's resources.
166
167comment "MSND Pinnacle DSP section will be configured to above parameters."
168 depends on SOUND_MSNDPIN=y && MSNDPIN_NONPNP
169
170config MSNDPIN_CFG
171 hex "MSND Pinnacle config port 250,260,270"
172 depends on MSNDPIN_NONPNP
173 default "250"
174 help
175 This is the port which the Pinnacle and Fiji uses to configure the
176 card's resources when not in PnP mode. If your card is in PnP mode,
177 then be sure to say N to the previous option, "MSND Pinnacle Non-PnP
178 Mode".
179
180comment "Pinnacle-specific Device Configuration (0 disables)"
181 depends on SOUND_MSNDPIN=y && MSNDPIN_NONPNP
182
183config MSNDPIN_MPU_IO
184 hex "MSND Pinnacle MPU I/O (e.g. 330)"
185 depends on MSNDPIN_NONPNP
186 default "0"
187 help
188 Memory-mapped I/O base address for the Kurzweil daughterboard
189 synthesizer on MultiSound Pinnacle and Fiji sound cards.
190
191config MSNDPIN_MPU_IRQ
192 int "MSND Pinnacle MPU IRQ (e.g. 9)"
193 depends on MSNDPIN_NONPNP
194 default "0"
195 help
196 Interrupt request number for the Kurzweil daughterboard
197 synthesizer on MultiSound Pinnacle and Fiji sound cards.
198
199config MSNDPIN_IDE_IO0
200 hex "MSND Pinnacle IDE I/O 0 (e.g. 170)"
201 depends on MSNDPIN_NONPNP
202 default "0"
203 help
204 CD-ROM drive 0 memory-mapped I/O base address for the MultiSound
205 Pinnacle and Fiji sound cards.
206
207config MSNDPIN_IDE_IO1
208 hex "MSND Pinnacle IDE I/O 1 (e.g. 376)"
209 depends on MSNDPIN_NONPNP
210 default "0"
211 help
212 CD-ROM drive 1 memory-mapped I/O base address for the MultiSound
213 Pinnacle and Fiji sound cards.
214
215config MSNDPIN_IDE_IRQ
216 int "MSND Pinnacle IDE IRQ (e.g. 15)"
217 depends on MSNDPIN_NONPNP
218 default "0"
219 help
220 Interrupt request number for the IDE CD-ROM interface on the
221 MultiSound Pinnacle and Fiji sound cards.
222
223config MSNDPIN_JOYSTICK_IO
224 hex "MSND Pinnacle joystick I/O (e.g. 200)"
225 depends on MSNDPIN_NONPNP
226 default "0"
227 help
228 Memory-mapped I/O base address for the joystick port on MultiSound
229 Pinnacle and Fiji sound cards.
230
231config MSND_FIFOSIZE
232 int "MSND buffer size (kB)"
233 depends on SOUND_MSNDPIN=y || SOUND_MSNDCLAS=y
234 default "128"
235 help
236 Configures the size of each audio buffer, in kilobytes, for
237 recording and playing in the MultiSound drivers (both the Classic
238 and Pinnacle). Larger values reduce the chance of data overruns at
239 the expense of overall latency. If unsure, use the default.
240
241menuconfig SOUND_OSS
242 tristate "OSS sound modules"
243 depends on ISA_DMA_API && (VIRT_TO_BUS || ARCH_RPC || ARCH_NETWINDER)
244 depends on !GENERIC_ISA_DMA_SUPPORT_BROKEN
245 help
246 OSS is the Open Sound System suite of sound card drivers. They make
247 sound programming easier since they provide a common API. Say Y or
248 M here (the module will be called sound) if you haven't found a
249 driver for your sound card above, then pick your driver from the
250 list below.
251
252if SOUND_OSS
253
254config SOUND_TRACEINIT
255 bool "Verbose initialisation"
256 help
257 Verbose soundcard initialization -- affects the format of autoprobe
258 and initialization messages at boot time.
259
260config SOUND_DMAP
261 bool "Persistent DMA buffers"
262 ---help---
263 Linux can often have problems allocating DMA buffers for ISA sound
264 cards on machines with more than 16MB of RAM. This is because ISA
265 DMA buffers must exist below the 16MB boundary and it is quite
266 possible that a large enough free block in this region cannot be
267 found after the machine has been running for a while. If you say Y
268 here the DMA buffers (64Kb) will be allocated at boot time and kept
269 until the shutdown. This option is only useful if you said Y to
270 "OSS sound modules", above. If you said M to "OSS sound modules"
271 then you can get the persistent DMA buffer functionality by passing
272 the command-line argument "dmabuf=1" to the sound module.
273
274 Say Y unless you have 16MB or more RAM or a PCI sound card.
275
276config SOUND_VMIDI
277 tristate "Loopback MIDI device support"
278 help
279 Support for MIDI loopback on port 1 or 2.
280
281config SOUND_TRIX
282 tristate "MediaTrix AudioTrix Pro support"
283 help
284 Answer Y if you have the AudioTriX Pro sound card manufactured
285 by MediaTrix.
286
287config TRIX_HAVE_BOOT
288 bool "Have TRXPRO.HEX firmware file"
289 depends on SOUND_TRIX=y && !STANDALONE
290 help
291 The MediaTrix AudioTrix Pro has an on-board microcontroller which
292 needs to be initialized by downloading the code from the file
293 TRXPRO.HEX in the DOS driver directory. If you don't have the
294 TRXPRO.HEX file handy you may skip this step. However, the SB and
295 MPU-401 modes of AudioTrix Pro will not work without this file!
296
297config TRIX_BOOT_FILE
298 string "Full pathname of TRXPRO.HEX firmware file"
299 depends on TRIX_HAVE_BOOT
300 default "/etc/sound/trxpro.hex"
301 help
302 Enter the full pathname of your TRXPRO.HEX file, starting from /.
303
304config SOUND_MSS
305 tristate "Microsoft Sound System support"
306 ---help---
307 Again think carefully before answering Y to this question. It's
308 safe to answer Y if you have the original Windows Sound System card
309 made by Microsoft or Aztech SG 16 Pro (or NX16 Pro). Also you may
310 say Y in case your card is NOT among these:
311
312 ATI Stereo F/X, AdLib, Audio Excell DSP16, Cardinal DSP16,
313 Ensoniq SoundScape (and compatibles made by Reveal and Spea),
314 Gravis Ultrasound, Gravis Ultrasound ACE, Gravis Ultrasound Max,
315 Gravis Ultrasound with 16 bit option, Logitech Sound Man 16,
316 Logitech SoundMan Games, Logitech SoundMan Wave, MAD16 Pro (OPTi
317 82C929), Media Vision Jazz16, MediaTriX AudioTriX Pro, Microsoft
318 Windows Sound System (MSS/WSS), Mozart (OAK OTI-601), Orchid
319 SW32, Personal Sound System (PSS), Pro Audio Spectrum 16, Pro
320 Audio Studio 16, Pro Sonic 16, Roland MPU-401 MIDI interface,
321 Sound Blaster 1.0, Sound Blaster 16, Sound Blaster 16ASP, Sound
322 Blaster 2.0, Sound Blaster AWE32, Sound Blaster Pro, TI TM4000M
323 notebook, ThunderBoard, Turtle Beach Tropez, Yamaha FM
324 synthesizers (OPL2, OPL3 and OPL4), 6850 UART MIDI Interface.
325
326 For cards having native support in VoxWare, consult the card
327 specific instructions in <file:Documentation/sound/oss/README.OSS>.
328 Some drivers have their own MSS support and saying Y to this option
329 will cause a conflict.
330
331 If you compile the driver into the kernel, you have to add
332 "ad1848=<io>,<irq>,<dma>,<dma2>[,<type>]" to the kernel command
333 line.
334
335config SOUND_MPU401
336 tristate "MPU-401 support (NOT for SB16)"
337 ---help---
338 Be careful with this question. The MPU401 interface is supported by
339 all sound cards. However, some natively supported cards have their
340 own driver for MPU401. Enabling this MPU401 option with these cards
341 will cause a conflict. Also, enabling MPU401 on a system that
342 doesn't really have a MPU401 could cause some trouble. If your card
343 was in the list of supported cards, look at the card specific
344 instructions in the <file:Documentation/sound/oss/README.OSS> file. It
345 is safe to answer Y if you have a true MPU401 MIDI interface card.
346
347 If you compile the driver into the kernel, you have to add
348 "mpu401=<io>,<irq>" to the kernel command line.
349
350config SOUND_PAS
351 tristate "ProAudioSpectrum 16 support"
352 ---help---
353 Answer Y only if you have a Pro Audio Spectrum 16, ProAudio Studio
354 16 or Logitech SoundMan 16 sound card. Answer N if you have some
355 other card made by Media Vision or Logitech since those are not
356 PAS16 compatible. Please read <file:Documentation/sound/oss/PAS16>.
357 It is not necessary to add Sound Blaster support separately; it
358 is included in PAS support.
359
360 If you compile the driver into the kernel, you have to add
361 "pas2=<io>,<irq>,<dma>,<dma2>,<sbio>,<sbirq>,<sbdma>,<sbdma2>
362 to the kernel command line.
363
364config PAS_JOYSTICK
365 bool "Enable PAS16 joystick port"
366 depends on SOUND_PAS=y
367 help
368 Say Y here to enable the Pro Audio Spectrum 16's auxiliary joystick
369 port.
370
371config SOUND_PSS
372 tristate "PSS (AD1848, ADSP-2115, ESC614) support"
373 help
374 Answer Y or M if you have an Orchid SW32, Cardinal DSP16, Beethoven
375 ADSP-16 or some other card based on the PSS chipset (AD1848 codec +
376 ADSP-2115 DSP chip + Echo ESC614 ASIC CHIP). For more information on
377 how to compile it into the kernel or as a module see the file
378 <file:Documentation/sound/oss/PSS>.
379
380 If you compile the driver into the kernel, you have to add
381 "pss=<io>,<mssio>,<mssirq>,<mssdma>,<mpuio>,<mpuirq>" to the kernel
382 command line.
383
384config PSS_MIXER
385 bool "Enable PSS mixer (Beethoven ADSP-16 and other compatible)"
386 depends on SOUND_PSS
387 help
388 Answer Y for Beethoven ADSP-16. You may try to say Y also for other
389 cards if they have master volume, bass, treble, and you can't
390 control it under Linux. If you answer N for Beethoven ADSP-16, you
391 can't control master volume, bass, treble and synth volume.
392
393 If you said M to "PSS support" above, you may enable or disable this
394 PSS mixer with the module parameter pss_mixer. For more information
395 see the file <file:Documentation/sound/oss/PSS>.
396
397config PSS_HAVE_BOOT
398 bool "Have DSPxxx.LD firmware file"
399 depends on SOUND_PSS && !STANDALONE
400 help
401 If you have the DSPxxx.LD file or SYNTH.LD file for you card, say Y
402 to include this file. Without this file the synth device (OPL) may
403 not work.
404
405config PSS_BOOT_FILE
406 string "Full pathname of DSPxxx.LD firmware file"
407 depends on PSS_HAVE_BOOT
408 default "/etc/sound/dsp001.ld"
409 help
410 Enter the full pathname of your DSPxxx.LD file or SYNTH.LD file,
411 starting from /.
412
413config SOUND_SB
414 tristate "100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support"
415 ---help---
416 Answer Y if you have an original Sound Blaster card made by Creative
417 Labs or a 100% hardware compatible clone (like the Thunderboard or
418 SM Games). For an unknown card you may answer Y if the card claims
419 to be Sound Blaster-compatible.
420
421 Please read the file <file:Documentation/sound/oss/Soundblaster>.
422
423 You should also say Y here for cards based on the Avance Logic
424 ALS-007 and ALS-1X0 chips (read <file:Documentation/sound/oss/ALS>) and
425 for cards based on ESS chips (read
426 <file:Documentation/sound/oss/ESS1868> and
427 <file:Documentation/sound/oss/ESS>). If you have an IBM Mwave
428 card, say Y here and read <file:Documentation/sound/oss/mwave>.
429
430 If you compile the driver into the kernel and don't want to use
431 isapnp, you have to add "sb=<io>,<irq>,<dma>,<dma2>" to the kernel
432 command line.
433
434 You can say M here to compile this driver as a module; the module is
435 called sb.
436
437config SOUND_YM3812
438 tristate "Yamaha FM synthesizer (YM3812/OPL-3) support"
439 ---help---
440 Answer Y if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
441 Answering Y is usually a safe and recommended choice, however some
442 cards may have software (TSR) FM emulation. Enabling FM support with
443 these cards may cause trouble (I don't currently know of any such
444 cards, however). Please read the file
445 <file:Documentation/sound/oss/OPL3> if your card has an OPL3 chip.
446
447 If you compile the driver into the kernel, you have to add
448 "opl3=<io>" to the kernel command line.
449
450 If unsure, say Y.
451
452config SOUND_UART6850
453 tristate "6850 UART support"
454 help
455 This option enables support for MIDI interfaces based on the 6850
456 UART chip. This interface is rarely found on sound cards. It's safe
457 to answer N to this question.
458
459 If you compile the driver into the kernel, you have to add
460 "uart6850=<io>,<irq>" to the kernel command line.
461
462config SOUND_AEDSP16
463 tristate "Gallant Audio Cards (SC-6000 and SC-6600 based)"
464 ---help---
465 Answer Y if you have a Gallant's Audio Excel DSP 16 card. This
466 driver supports Audio Excel DSP 16 but not the III nor PnP versions
467 of this card.
468
469 The Gallant's Audio Excel DSP 16 card can emulate either an SBPro or
470 a Microsoft Sound System card, so you should have said Y to either
471 "100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support"
472 or "Microsoft Sound System support", above, and you need to answer
473 the "MSS emulation" and "SBPro emulation" questions below
474 accordingly. You should say Y to one and only one of these two
475 questions.
476
477 Read the <file:Documentation/sound/oss/README.OSS> file and the head of
478 <file:sound/oss/aedsp16.c> as well as
479 <file:Documentation/sound/oss/AudioExcelDSP16> to get more information
480 about this driver and its configuration.
481
482config SC6600
483 bool "SC-6600 based audio cards (new Audio Excel DSP 16)"
484 depends on SOUND_AEDSP16
485 help
486 The SC6600 is the new version of DSP mounted on the Audio Excel DSP
487 16 cards. Find in the manual the FCC ID of your audio card and
488 answer Y if you have an SC6600 DSP.
489
490config SC6600_JOY
491 bool "Activate SC-6600 Joystick Interface"
492 depends on SC6600
493 help
494 Say Y here in order to use the joystick interface of the Audio Excel
495 DSP 16 card.
496
497config SC6600_CDROM
498 int "SC-6600 CDROM Interface (4=None, 3=IDE, 1=Panasonic, 0=?Sony?)"
499 depends on SC6600
500 default "4"
501 help
502 This is used to activate the CD-ROM interface of the Audio Excel
503 DSP 16 card. Enter: 0 for Sony, 1 for Panasonic, 2 for IDE, 4 for no
504 CD-ROM present.
505
506config SC6600_CDROMBASE
507 hex "SC-6600 CDROM Interface I/O Address"
508 depends on SC6600
509 default "0"
510 help
511 Base I/O port address for the CD-ROM interface of the Audio Excel
512 DSP 16 card.
513
514config SOUND_VIDC
515 tristate "VIDC 16-bit sound"
516 depends on ARM && ARCH_ACORN
517 help
518 16-bit support for the VIDC onboard sound hardware found on Acorn
519 machines.
520
521config SOUND_WAVEARTIST
522 tristate "Netwinder WaveArtist"
523 depends on ARM && ARCH_NETWINDER
524 help
525 Say Y here to include support for the Rockwell WaveArtist sound
526 system. This driver is mainly for the NetWinder.
527
528config SOUND_KAHLUA
529 tristate "XpressAudio Sound Blaster emulation"
530 depends on SOUND_SB
531
532endif # SOUND_OSS
533
diff --git a/sound/oss/Makefile b/sound/oss/Makefile
deleted file mode 100644
index 9bdbbde2173e..000000000000
--- a/sound/oss/Makefile
+++ /dev/null
@@ -1,107 +0,0 @@
1# Makefile for the Linux sound card driver
2#
3# 18 Apr 1998, Michael Elizabeth Chastain, <mailto:mec@shout.net>
4# Rewritten to use lists instead of if-statements.
5
6# Each configuration option enables a list of files.
7
8obj-$(CONFIG_SOUND_OSS) += sound.o
9
10# Please leave it as is, cause the link order is significant !
11
12obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o
13obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o
14obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o
15obj-$(CONFIG_SOUND_MSS) += ad1848.o
16obj-$(CONFIG_SOUND_PAS) += pas2.o sb.o sb_lib.o uart401.o
17obj-$(CONFIG_SOUND_SB) += sb.o sb_lib.o uart401.o
18obj-$(CONFIG_SOUND_KAHLUA) += kahlua.o
19obj-$(CONFIG_SOUND_MPU401) += mpu401.o
20obj-$(CONFIG_SOUND_UART6850) += uart6850.o
21obj-$(CONFIG_SOUND_YM3812) += opl3.o
22obj-$(CONFIG_SOUND_VMIDI) += v_midi.o
23obj-$(CONFIG_SOUND_VIDC) += vidc_mod.o
24obj-$(CONFIG_SOUND_WAVEARTIST) += waveartist.o
25obj-$(CONFIG_SOUND_MSNDCLAS) += msnd.o msnd_classic.o
26obj-$(CONFIG_SOUND_MSNDPIN) += msnd.o msnd_pinnacle.o
27obj-$(CONFIG_SOUND_BCM_CS4297A) += swarm_cs4297a.o
28
29obj-$(CONFIG_DMASOUND) += dmasound/
30
31# Declare multi-part drivers.
32
33sound-objs := \
34 dev_table.o soundcard.o \
35 audio.o dmabuf.o \
36 midi_synth.o midibuf.o \
37 sequencer.o sound_timer.o sys_timer.o
38
39pas2-objs := pas2_card.o pas2_midi.o pas2_mixer.o pas2_pcm.o
40sb-objs := sb_card.o
41sb_lib-objs := sb_common.o sb_audio.o sb_midi.o sb_mixer.o sb_ess.o
42vidc_mod-objs := vidc.o vidc_fill.o
43
44hostprogs-y := bin2hex hex2hex
45
46# Files generated that shall be removed upon make clean
47clean-files := msndperm.c msndinit.c pndsperm.c pndspini.c \
48 pss_boot.h trix_boot.h
49
50# Firmware files that need translation
51#
52# The translated files are protected by a file that keeps track
53# of what name was used to build them. If the name changes, they
54# will be forced to be remade.
55#
56
57# Turtle Beach MultiSound
58
59ifeq ($(CONFIG_MSNDCLAS_HAVE_BOOT),y)
60 $(obj)/msnd_classic.o: $(obj)/msndperm.c $(obj)/msndinit.c
61
62 $(obj)/msndperm.c: $(patsubst "%", %, $(CONFIG_MSNDCLAS_PERM_FILE)) $(obj)/bin2hex
63 $(obj)/bin2hex msndperm < $< > $@
64
65 $(obj)/msndinit.c: $(patsubst "%", %, $(CONFIG_MSNDCLAS_INIT_FILE)) $(obj)/bin2hex
66 $(obj)/bin2hex msndinit < $< > $@
67endif
68
69ifeq ($(CONFIG_MSNDPIN_HAVE_BOOT),y)
70 $(obj)/msnd_pinnacle.o: $(obj)/pndsperm.c $(obj)/pndspini.c
71
72 $(obj)/pndsperm.c: $(patsubst "%", %, $(CONFIG_MSNDPIN_PERM_FILE)) $(obj)/bin2hex
73 $(obj)/bin2hex pndsperm < $< > $@
74
75 $(obj)/pndspini.c: $(patsubst "%", %, $(CONFIG_MSNDPIN_INIT_FILE)) $(obj)/bin2hex
76 $(obj)/bin2hex pndspini < $< > $@
77endif
78
79# PSS (ECHO-ADI2111)
80
81$(obj)/pss.o: $(obj)/pss_boot.h
82
83ifeq ($(CONFIG_PSS_HAVE_BOOT),y)
84 $(obj)/pss_boot.h: $(patsubst "%", %, $(CONFIG_PSS_BOOT_FILE)) $(obj)/bin2hex
85 $(obj)/bin2hex pss_synth < $< > $@
86else
87 $(obj)/pss_boot.h:
88 $(Q)( \
89 echo 'static unsigned char * pss_synth = NULL;'; \
90 echo 'static int pss_synthLen = 0;'; \
91 ) > $@
92endif
93
94# MediaTrix AudioTrix Pro
95
96$(obj)/trix.o: $(obj)/trix_boot.h
97
98ifeq ($(CONFIG_TRIX_HAVE_BOOT),y)
99 $(obj)/trix_boot.h: $(patsubst "%", %, $(CONFIG_TRIX_BOOT_FILE)) $(obj)/hex2hex
100 $(obj)/hex2hex -i trix_boot < $< > $@
101else
102 $(obj)/trix_boot.h:
103 $(Q)( \
104 echo 'static unsigned char * trix_boot = NULL;'; \
105 echo 'static int trix_boot_len = 0;'; \
106 ) > $@
107endif
diff --git a/sound/oss/README.FIRST b/sound/oss/README.FIRST
deleted file mode 100644
index 90fdcf063d2d..000000000000
--- a/sound/oss/README.FIRST
+++ /dev/null
@@ -1,6 +0,0 @@
1The modular sound driver patches were funded by Red Hat Software
2(www.redhat.com). The sound driver here is thus a modified version of
3Hannu's code. Please bear that in mind when considering the appropriate
4forums for bug reporting.
5
6Alan Cox
diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
deleted file mode 100644
index 2421f59cf279..000000000000
--- a/sound/oss/ad1848.c
+++ /dev/null
@@ -1,3062 +0,0 @@
1/*
2 * sound/oss/ad1848.c
3 *
4 * The low level driver for the AD1848/CS4248 codec chip which
5 * is used for example in the MS Sound System.
6 *
7 * The CS4231 which is used in the GUS MAX and some other cards is
8 * upwards compatible with AD1848 and this driver is able to drive it.
9 *
10 * CS4231A and AD1845 are upward compatible with CS4231. However
11 * the new features of these chips are different.
12 *
13 * CS4232 is a PnP audio chip which contains a CS4231A (and SB, MPU).
14 * CS4232A is an improved version of CS4232.
15 *
16 *
17 *
18 * Copyright (C) by Hannu Savolainen 1993-1997
19 *
20 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
21 * Version 2 (June 1991). See the "COPYING" file distributed with this software
22 * for more info.
23 *
24 *
25 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
26 * general sleep/wakeup clean up.
27 * Alan Cox : reformatted. Fixed SMP bugs. Moved to kernel alloc/free
28 * of irqs. Use dev_id.
29 * Christoph Hellwig : adapted to module_init/module_exit
30 * Aki Laukkanen : added power management support
31 * Arnaldo C. de Melo : added missing restore_flags in ad1848_resume
32 * Miguel Freitas : added ISA PnP support
33 * Alan Cox : Added CS4236->4239 identification
34 * Daniel T. Cobra : Alernate config/mixer for later chips
35 * Alan Cox : Merged chip idents and config code
36 *
37 * TODO
38 * APM save restore assist code on IBM thinkpad
39 *
40 * Status:
41 * Tested. Believed fully functional.
42 */
43
44#include <linux/init.h>
45#include <linux/interrupt.h>
46#include <linux/module.h>
47#include <linux/stddef.h>
48#include <linux/slab.h>
49#include <linux/isapnp.h>
50#include <linux/pnp.h>
51#include <linux/spinlock.h>
52
53#include "sound_config.h"
54
55#include "ad1848.h"
56#include "ad1848_mixer.h"
57
58typedef struct
59{
60 spinlock_t lock;
61 int base;
62 int irq;
63 int dma1, dma2;
64 int dual_dma; /* 1, when two DMA channels allocated */
65 int subtype;
66 unsigned char MCE_bit;
67 unsigned char saved_regs[64]; /* Includes extended register space */
68 int debug_flag;
69
70 int audio_flags;
71 int record_dev, playback_dev;
72
73 int xfer_count;
74 int audio_mode;
75 int open_mode;
76 int intr_active;
77 char *chip_name, *name;
78 int model;
79#define MD_1848 1
80#define MD_4231 2
81#define MD_4231A 3
82#define MD_1845 4
83#define MD_4232 5
84#define MD_C930 6
85#define MD_IWAVE 7
86#define MD_4235 8 /* Crystal Audio CS4235 */
87#define MD_1845_SSCAPE 9 /* Ensoniq Soundscape PNP*/
88#define MD_4236 10 /* 4236 and higher */
89#define MD_42xB 11 /* CS 42xB */
90#define MD_4239 12 /* CS4239 */
91
92 /* Mixer parameters */
93 int recmask;
94 int supported_devices, orig_devices;
95 int supported_rec_devices, orig_rec_devices;
96 int *levels;
97 short mixer_reroute[32];
98 int dev_no;
99 volatile unsigned long timer_ticks;
100 int timer_running;
101 int irq_ok;
102 mixer_ents *mix_devices;
103 int mixer_output_port;
104} ad1848_info;
105
106typedef struct ad1848_port_info
107{
108 int open_mode;
109 int speed;
110 unsigned char speed_bits;
111 int channels;
112 int audio_format;
113 unsigned char format_bits;
114}
115ad1848_port_info;
116
117static struct address_info cfg;
118static int nr_ad1848_devs;
119
120static bool deskpro_xl;
121static bool deskpro_m;
122static bool soundpro;
123
124#ifndef EXCLUDE_TIMERS
125static int timer_installed = -1;
126#endif
127
128static int loaded;
129
130static int ad_format_mask[13 /*devc->model */ ] =
131{
132 0,
133 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW,
134 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
135 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
136 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW, /* AD1845 */
137 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
138 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
139 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
140 AFMT_U8 | AFMT_S16_LE /* CS4235 */,
141 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW /* Ensoniq Soundscape*/,
142 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
143 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
144 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM
145};
146
147static ad1848_info adev_info[MAX_AUDIO_DEV];
148
149#define io_Index_Addr(d) ((d)->base)
150#define io_Indexed_Data(d) ((d)->base+1)
151#define io_Status(d) ((d)->base+2)
152#define io_Polled_IO(d) ((d)->base+3)
153
154static struct {
155 unsigned char flags;
156#define CAP_F_TIMER 0x01
157} capabilities [10 /*devc->model */ ] = {
158 {0}
159 ,{0} /* MD_1848 */
160 ,{CAP_F_TIMER} /* MD_4231 */
161 ,{CAP_F_TIMER} /* MD_4231A */
162 ,{CAP_F_TIMER} /* MD_1845 */
163 ,{CAP_F_TIMER} /* MD_4232 */
164 ,{0} /* MD_C930 */
165 ,{CAP_F_TIMER} /* MD_IWAVE */
166 ,{0} /* MD_4235 */
167 ,{CAP_F_TIMER} /* MD_1845_SSCAPE */
168};
169
170#ifdef CONFIG_PNP
171static int isapnp = 1;
172static int isapnpjump;
173static bool reverse;
174
175static int audio_activated;
176#else
177static int isapnp;
178#endif
179
180
181
182static int ad1848_open(int dev, int mode);
183static void ad1848_close(int dev);
184static void ad1848_output_block(int dev, unsigned long buf, int count, int intrflag);
185static void ad1848_start_input(int dev, unsigned long buf, int count, int intrflag);
186static int ad1848_prepare_for_output(int dev, int bsize, int bcount);
187static int ad1848_prepare_for_input(int dev, int bsize, int bcount);
188static void ad1848_halt(int dev);
189static void ad1848_halt_input(int dev);
190static void ad1848_halt_output(int dev);
191static void ad1848_trigger(int dev, int bits);
192static irqreturn_t adintr(int irq, void *dev_id);
193
194#ifndef EXCLUDE_TIMERS
195static int ad1848_tmr_install(int dev);
196static void ad1848_tmr_reprogram(int dev);
197#endif
198
199static int ad_read(ad1848_info * devc, int reg)
200{
201 int x;
202 int timeout = 900000;
203
204 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
205 timeout--;
206
207 if(reg < 32)
208 {
209 outb(((unsigned char) (reg & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
210 x = inb(io_Indexed_Data(devc));
211 }
212 else
213 {
214 int xreg, xra;
215
216 xreg = (reg & 0xff) - 32;
217 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
218 outb(((unsigned char) (23 & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
219 outb(((unsigned char) (xra & 0xff)), io_Indexed_Data(devc));
220 x = inb(io_Indexed_Data(devc));
221 }
222
223 return x;
224}
225
226static void ad_write(ad1848_info * devc, int reg, int data)
227{
228 int timeout = 900000;
229
230 while (timeout > 0 && inb(devc->base) == 0x80) /* Are we initializing */
231 timeout--;
232
233 if(reg < 32)
234 {
235 outb(((unsigned char) (reg & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
236 outb(((unsigned char) (data & 0xff)), io_Indexed_Data(devc));
237 }
238 else
239 {
240 int xreg, xra;
241
242 xreg = (reg & 0xff) - 32;
243 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
244 outb(((unsigned char) (23 & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
245 outb(((unsigned char) (xra & 0xff)), io_Indexed_Data(devc));
246 outb((unsigned char) (data & 0xff), io_Indexed_Data(devc));
247 }
248}
249
250static void wait_for_calibration(ad1848_info * devc)
251{
252 int timeout;
253
254 /*
255 * Wait until the auto calibration process has finished.
256 *
257 * 1) Wait until the chip becomes ready (reads don't return 0x80).
258 * 2) Wait until the ACI bit of I11 gets on and then off.
259 */
260
261 timeout = 100000;
262 while (timeout > 0 && inb(devc->base) == 0x80)
263 timeout--;
264 if (inb(devc->base) & 0x80)
265 printk(KERN_WARNING "ad1848: Auto calibration timed out(1).\n");
266
267 timeout = 100;
268 while (timeout > 0 && !(ad_read(devc, 11) & 0x20))
269 timeout--;
270 if (!(ad_read(devc, 11) & 0x20))
271 return;
272
273 timeout = 80000;
274 while (timeout > 0 && (ad_read(devc, 11) & 0x20))
275 timeout--;
276 if (ad_read(devc, 11) & 0x20)
277 if ((devc->model != MD_1845) && (devc->model != MD_1845_SSCAPE))
278 printk(KERN_WARNING "ad1848: Auto calibration timed out(3).\n");
279}
280
281static void ad_mute(ad1848_info * devc)
282{
283 int i;
284 unsigned char prev;
285
286 /*
287 * Save old register settings and mute output channels
288 */
289
290 for (i = 6; i < 8; i++)
291 {
292 prev = devc->saved_regs[i] = ad_read(devc, i);
293 }
294
295}
296
297static void ad_unmute(ad1848_info * devc)
298{
299}
300
301static void ad_enter_MCE(ad1848_info * devc)
302{
303 int timeout = 1000;
304 unsigned short prev;
305
306 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
307 timeout--;
308
309 devc->MCE_bit = 0x40;
310 prev = inb(io_Index_Addr(devc));
311 if (prev & 0x40)
312 {
313 return;
314 }
315 outb((devc->MCE_bit), io_Index_Addr(devc));
316}
317
318static void ad_leave_MCE(ad1848_info * devc)
319{
320 unsigned char prev, acal;
321 int timeout = 1000;
322
323 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
324 timeout--;
325
326 acal = ad_read(devc, 9);
327
328 devc->MCE_bit = 0x00;
329 prev = inb(io_Index_Addr(devc));
330 outb((0x00), io_Index_Addr(devc)); /* Clear the MCE bit */
331
332 if ((prev & 0x40) == 0) /* Not in MCE mode */
333 {
334 return;
335 }
336 outb((0x00), io_Index_Addr(devc)); /* Clear the MCE bit */
337 if (acal & 0x08) /* Auto calibration is enabled */
338 wait_for_calibration(devc);
339}
340
341static int ad1848_set_recmask(ad1848_info * devc, int mask)
342{
343 unsigned char recdev;
344 int i, n;
345 unsigned long flags;
346
347 mask &= devc->supported_rec_devices;
348
349 /* Rename the mixer bits if necessary */
350 for (i = 0; i < 32; i++)
351 {
352 if (devc->mixer_reroute[i] != i)
353 {
354 if (mask & (1 << i))
355 {
356 mask &= ~(1 << i);
357 mask |= (1 << devc->mixer_reroute[i]);
358 }
359 }
360 }
361
362 n = 0;
363 for (i = 0; i < 32; i++) /* Count selected device bits */
364 if (mask & (1 << i))
365 n++;
366
367 spin_lock_irqsave(&devc->lock,flags);
368 if (!soundpro) {
369 if (n == 0)
370 mask = SOUND_MASK_MIC;
371 else if (n != 1) { /* Too many devices selected */
372 mask &= ~devc->recmask; /* Filter out active settings */
373
374 n = 0;
375 for (i = 0; i < 32; i++) /* Count selected device bits */
376 if (mask & (1 << i))
377 n++;
378
379 if (n != 1)
380 mask = SOUND_MASK_MIC;
381 }
382 switch (mask) {
383 case SOUND_MASK_MIC:
384 recdev = 2;
385 break;
386
387 case SOUND_MASK_LINE:
388 case SOUND_MASK_LINE3:
389 recdev = 0;
390 break;
391
392 case SOUND_MASK_CD:
393 case SOUND_MASK_LINE1:
394 recdev = 1;
395 break;
396
397 case SOUND_MASK_IMIX:
398 recdev = 3;
399 break;
400
401 default:
402 mask = SOUND_MASK_MIC;
403 recdev = 2;
404 }
405
406 recdev <<= 6;
407 ad_write(devc, 0, (ad_read(devc, 0) & 0x3f) | recdev);
408 ad_write(devc, 1, (ad_read(devc, 1) & 0x3f) | recdev);
409 } else { /* soundpro */
410 unsigned char val;
411 int set_rec_bit;
412 int j;
413
414 for (i = 0; i < 32; i++) { /* For each bit */
415 if ((devc->supported_rec_devices & (1 << i)) == 0)
416 continue; /* Device not supported */
417
418 for (j = LEFT_CHN; j <= RIGHT_CHN; j++) {
419 if (devc->mix_devices[i][j].nbits == 0) /* Inexistent channel */
420 continue;
421
422 /*
423 * This is tricky:
424 * set_rec_bit becomes 1 if the corresponding bit in mask is set
425 * then it gets flipped if the polarity is inverse
426 */
427 set_rec_bit = ((mask & (1 << i)) != 0) ^ devc->mix_devices[i][j].recpol;
428
429 val = ad_read(devc, devc->mix_devices[i][j].recreg);
430 val &= ~(1 << devc->mix_devices[i][j].recpos);
431 val |= (set_rec_bit << devc->mix_devices[i][j].recpos);
432 ad_write(devc, devc->mix_devices[i][j].recreg, val);
433 }
434 }
435 }
436 spin_unlock_irqrestore(&devc->lock,flags);
437
438 /* Rename the mixer bits back if necessary */
439 for (i = 0; i < 32; i++)
440 {
441 if (devc->mixer_reroute[i] != i)
442 {
443 if (mask & (1 << devc->mixer_reroute[i]))
444 {
445 mask &= ~(1 << devc->mixer_reroute[i]);
446 mask |= (1 << i);
447 }
448 }
449 }
450 devc->recmask = mask;
451 return mask;
452}
453
454static void oss_change_bits(ad1848_info *devc, unsigned char *regval,
455 unsigned char *muteval, int dev, int chn, int newval)
456{
457 unsigned char mask;
458 int shift;
459 int mute;
460 int mutemask;
461 int set_mute_bit;
462
463 set_mute_bit = (newval == 0) ^ devc->mix_devices[dev][chn].mutepol;
464
465 if (devc->mix_devices[dev][chn].polarity == 1) /* Reverse */
466 newval = 100 - newval;
467
468 mask = (1 << devc->mix_devices[dev][chn].nbits) - 1;
469 shift = devc->mix_devices[dev][chn].bitpos;
470
471 if (devc->mix_devices[dev][chn].mutepos == 8)
472 { /* if there is no mute bit */
473 mute = 0; /* No mute bit; do nothing special */
474 mutemask = ~0; /* No mute bit; do nothing special */
475 }
476 else
477 {
478 mute = (set_mute_bit << devc->mix_devices[dev][chn].mutepos);
479 mutemask = ~(1 << devc->mix_devices[dev][chn].mutepos);
480 }
481
482 newval = (int) ((newval * mask) + 50) / 100; /* Scale it */
483 *regval &= ~(mask << shift); /* Clear bits */
484 *regval |= (newval & mask) << shift; /* Set new value */
485
486 *muteval &= mutemask;
487 *muteval |= mute;
488}
489
490static int ad1848_mixer_get(ad1848_info * devc, int dev)
491{
492 if (!((1 << dev) & devc->supported_devices))
493 return -EINVAL;
494
495 dev = devc->mixer_reroute[dev];
496
497 return devc->levels[dev];
498}
499
500static void ad1848_mixer_set_channel(ad1848_info *devc, int dev, int value, int channel)
501{
502 int regoffs, muteregoffs;
503 unsigned char val, muteval;
504 unsigned long flags;
505
506 regoffs = devc->mix_devices[dev][channel].regno;
507 muteregoffs = devc->mix_devices[dev][channel].mutereg;
508 val = ad_read(devc, regoffs);
509
510 if (muteregoffs != regoffs) {
511 muteval = ad_read(devc, muteregoffs);
512 oss_change_bits(devc, &val, &muteval, dev, channel, value);
513 }
514 else
515 oss_change_bits(devc, &val, &val, dev, channel, value);
516
517 spin_lock_irqsave(&devc->lock,flags);
518 ad_write(devc, regoffs, val);
519 devc->saved_regs[regoffs] = val;
520 if (muteregoffs != regoffs) {
521 ad_write(devc, muteregoffs, muteval);
522 devc->saved_regs[muteregoffs] = muteval;
523 }
524 spin_unlock_irqrestore(&devc->lock,flags);
525}
526
527static int ad1848_mixer_set(ad1848_info * devc, int dev, int value)
528{
529 int left = value & 0x000000ff;
530 int right = (value & 0x0000ff00) >> 8;
531 int retvol;
532
533 if (dev > 31)
534 return -EINVAL;
535
536 if (!(devc->supported_devices & (1 << dev)))
537 return -EINVAL;
538
539 dev = devc->mixer_reroute[dev];
540
541 if (devc->mix_devices[dev][LEFT_CHN].nbits == 0)
542 return -EINVAL;
543
544 if (left > 100)
545 left = 100;
546 if (right > 100)
547 right = 100;
548
549 if (devc->mix_devices[dev][RIGHT_CHN].nbits == 0) /* Mono control */
550 right = left;
551
552 retvol = left | (right << 8);
553
554 /* Scale volumes */
555 left = mix_cvt[left];
556 right = mix_cvt[right];
557
558 devc->levels[dev] = retvol;
559
560 /*
561 * Set the left channel
562 */
563 ad1848_mixer_set_channel(devc, dev, left, LEFT_CHN);
564
565 /*
566 * Set the right channel
567 */
568 if (devc->mix_devices[dev][RIGHT_CHN].nbits == 0)
569 goto out;
570 ad1848_mixer_set_channel(devc, dev, right, RIGHT_CHN);
571
572 out:
573 return retvol;
574}
575
576static void ad1848_mixer_reset(ad1848_info * devc)
577{
578 int i;
579 char name[32];
580 unsigned long flags;
581
582 devc->mix_devices = &(ad1848_mix_devices[0]);
583
584 sprintf(name, "%s_%d", devc->chip_name, nr_ad1848_devs);
585
586 for (i = 0; i < 32; i++)
587 devc->mixer_reroute[i] = i;
588
589 devc->supported_rec_devices = MODE1_REC_DEVICES;
590
591 switch (devc->model)
592 {
593 case MD_4231:
594 case MD_4231A:
595 case MD_1845:
596 case MD_1845_SSCAPE:
597 devc->supported_devices = MODE2_MIXER_DEVICES;
598 break;
599
600 case MD_C930:
601 devc->supported_devices = C930_MIXER_DEVICES;
602 devc->mix_devices = &(c930_mix_devices[0]);
603 break;
604
605 case MD_IWAVE:
606 devc->supported_devices = MODE3_MIXER_DEVICES;
607 devc->mix_devices = &(iwave_mix_devices[0]);
608 break;
609
610 case MD_42xB:
611 case MD_4239:
612 devc->mix_devices = &(cs42xb_mix_devices[0]);
613 devc->supported_devices = MODE3_MIXER_DEVICES;
614 break;
615 case MD_4232:
616 case MD_4235:
617 case MD_4236:
618 devc->supported_devices = MODE3_MIXER_DEVICES;
619 break;
620
621 case MD_1848:
622 if (soundpro) {
623 devc->supported_devices = SPRO_MIXER_DEVICES;
624 devc->supported_rec_devices = SPRO_REC_DEVICES;
625 devc->mix_devices = &(spro_mix_devices[0]);
626 break;
627 }
628
629 default:
630 devc->supported_devices = MODE1_MIXER_DEVICES;
631 }
632
633 devc->orig_devices = devc->supported_devices;
634 devc->orig_rec_devices = devc->supported_rec_devices;
635
636 devc->levels = load_mixer_volumes(name, default_mixer_levels, 1);
637
638 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
639 {
640 if (devc->supported_devices & (1 << i))
641 ad1848_mixer_set(devc, i, devc->levels[i]);
642 }
643
644 ad1848_set_recmask(devc, SOUND_MASK_MIC);
645
646 devc->mixer_output_port = devc->levels[31] | AUDIO_HEADPHONE | AUDIO_LINE_OUT;
647
648 spin_lock_irqsave(&devc->lock,flags);
649 if (!soundpro) {
650 if (devc->mixer_output_port & AUDIO_SPEAKER)
651 ad_write(devc, 26, ad_read(devc, 26) & ~0x40); /* Unmute mono out */
652 else
653 ad_write(devc, 26, ad_read(devc, 26) | 0x40); /* Mute mono out */
654 } else {
655 /*
656 * From the "wouldn't it be nice if the mixer API had (better)
657 * support for custom stuff" category
658 */
659 /* Enable surround mode and SB16 mixer */
660 ad_write(devc, 16, 0x60);
661 }
662 spin_unlock_irqrestore(&devc->lock,flags);
663}
664
665static int ad1848_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
666{
667 ad1848_info *devc = mixer_devs[dev]->devc;
668 int val;
669
670 if (cmd == SOUND_MIXER_PRIVATE1)
671 {
672 if (get_user(val, (int __user *)arg))
673 return -EFAULT;
674
675 if (val != 0xffff)
676 {
677 unsigned long flags;
678 val &= (AUDIO_SPEAKER | AUDIO_HEADPHONE | AUDIO_LINE_OUT);
679 devc->mixer_output_port = val;
680 val |= AUDIO_HEADPHONE | AUDIO_LINE_OUT; /* Always on */
681 devc->mixer_output_port = val;
682 spin_lock_irqsave(&devc->lock,flags);
683 if (val & AUDIO_SPEAKER)
684 ad_write(devc, 26, ad_read(devc, 26) & ~0x40); /* Unmute mono out */
685 else
686 ad_write(devc, 26, ad_read(devc, 26) | 0x40); /* Mute mono out */
687 spin_unlock_irqrestore(&devc->lock,flags);
688 }
689 val = devc->mixer_output_port;
690 return put_user(val, (int __user *)arg);
691 }
692 if (cmd == SOUND_MIXER_PRIVATE2)
693 {
694 if (get_user(val, (int __user *)arg))
695 return -EFAULT;
696 return(ad1848_control(AD1848_MIXER_REROUTE, val));
697 }
698 if (((cmd >> 8) & 0xff) == 'M')
699 {
700 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
701 {
702 switch (cmd & 0xff)
703 {
704 case SOUND_MIXER_RECSRC:
705 if (get_user(val, (int __user *)arg))
706 return -EFAULT;
707 val = ad1848_set_recmask(devc, val);
708 break;
709
710 default:
711 if (get_user(val, (int __user *)arg))
712 return -EFAULT;
713 val = ad1848_mixer_set(devc, cmd & 0xff, val);
714 break;
715 }
716 return put_user(val, (int __user *)arg);
717 }
718 else
719 {
720 switch (cmd & 0xff)
721 {
722 /*
723 * Return parameters
724 */
725
726 case SOUND_MIXER_RECSRC:
727 val = devc->recmask;
728 break;
729
730 case SOUND_MIXER_DEVMASK:
731 val = devc->supported_devices;
732 break;
733
734 case SOUND_MIXER_STEREODEVS:
735 val = devc->supported_devices;
736 if (devc->model != MD_C930)
737 val &= ~(SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
738 break;
739
740 case SOUND_MIXER_RECMASK:
741 val = devc->supported_rec_devices;
742 break;
743
744 case SOUND_MIXER_CAPS:
745 val=SOUND_CAP_EXCL_INPUT;
746 break;
747
748 default:
749 val = ad1848_mixer_get(devc, cmd & 0xff);
750 break;
751 }
752 return put_user(val, (int __user *)arg);
753 }
754 }
755 else
756 return -EINVAL;
757}
758
759static int ad1848_set_speed(int dev, int arg)
760{
761 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
762 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
763
764 /*
765 * The sampling speed is encoded in the least significant nibble of I8. The
766 * LSB selects the clock source (0=24.576 MHz, 1=16.9344 MHz) and other
767 * three bits select the divisor (indirectly):
768 *
769 * The available speeds are in the following table. Keep the speeds in
770 * the increasing order.
771 */
772 typedef struct
773 {
774 int speed;
775 unsigned char bits;
776 }
777 speed_struct;
778
779 static speed_struct speed_table[] =
780 {
781 {5510, (0 << 1) | 1},
782 {5510, (0 << 1) | 1},
783 {6620, (7 << 1) | 1},
784 {8000, (0 << 1) | 0},
785 {9600, (7 << 1) | 0},
786 {11025, (1 << 1) | 1},
787 {16000, (1 << 1) | 0},
788 {18900, (2 << 1) | 1},
789 {22050, (3 << 1) | 1},
790 {27420, (2 << 1) | 0},
791 {32000, (3 << 1) | 0},
792 {33075, (6 << 1) | 1},
793 {37800, (4 << 1) | 1},
794 {44100, (5 << 1) | 1},
795 {48000, (6 << 1) | 0}
796 };
797
798 int i, n, selected = -1;
799
800 n = sizeof(speed_table) / sizeof(speed_struct);
801
802 if (arg <= 0)
803 return portc->speed;
804
805 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE) /* AD1845 has different timer than others */
806 {
807 if (arg < 4000)
808 arg = 4000;
809 if (arg > 50000)
810 arg = 50000;
811
812 portc->speed = arg;
813 portc->speed_bits = speed_table[3].bits;
814 return portc->speed;
815 }
816 if (arg < speed_table[0].speed)
817 selected = 0;
818 if (arg > speed_table[n - 1].speed)
819 selected = n - 1;
820
821 for (i = 1 /*really */ ; selected == -1 && i < n; i++)
822 {
823 if (speed_table[i].speed == arg)
824 selected = i;
825 else if (speed_table[i].speed > arg)
826 {
827 int diff1, diff2;
828
829 diff1 = arg - speed_table[i - 1].speed;
830 diff2 = speed_table[i].speed - arg;
831
832 if (diff1 < diff2)
833 selected = i - 1;
834 else
835 selected = i;
836 }
837 }
838 if (selected == -1)
839 {
840 printk(KERN_WARNING "ad1848: Can't find speed???\n");
841 selected = 3;
842 }
843 portc->speed = speed_table[selected].speed;
844 portc->speed_bits = speed_table[selected].bits;
845 return portc->speed;
846}
847
848static short ad1848_set_channels(int dev, short arg)
849{
850 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
851
852 if (arg != 1 && arg != 2)
853 return portc->channels;
854
855 portc->channels = arg;
856 return arg;
857}
858
859static unsigned int ad1848_set_bits(int dev, unsigned int arg)
860{
861 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
862 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
863
864 static struct format_tbl
865 {
866 int format;
867 unsigned char bits;
868 }
869 format2bits[] =
870 {
871 {
872 0, 0
873 }
874 ,
875 {
876 AFMT_MU_LAW, 1
877 }
878 ,
879 {
880 AFMT_A_LAW, 3
881 }
882 ,
883 {
884 AFMT_IMA_ADPCM, 5
885 }
886 ,
887 {
888 AFMT_U8, 0
889 }
890 ,
891 {
892 AFMT_S16_LE, 2
893 }
894 ,
895 {
896 AFMT_S16_BE, 6
897 }
898 ,
899 {
900 AFMT_S8, 0
901 }
902 ,
903 {
904 AFMT_U16_LE, 0
905 }
906 ,
907 {
908 AFMT_U16_BE, 0
909 }
910 };
911 int i, n = sizeof(format2bits) / sizeof(struct format_tbl);
912
913 if (arg == 0)
914 return portc->audio_format;
915
916 if (!(arg & ad_format_mask[devc->model]))
917 arg = AFMT_U8;
918
919 portc->audio_format = arg;
920
921 for (i = 0; i < n; i++)
922 if (format2bits[i].format == arg)
923 {
924 if ((portc->format_bits = format2bits[i].bits) == 0)
925 return portc->audio_format = AFMT_U8; /* Was not supported */
926
927 return arg;
928 }
929 /* Still hanging here. Something must be terribly wrong */
930 portc->format_bits = 0;
931 return portc->audio_format = AFMT_U8;
932}
933
934static struct audio_driver ad1848_audio_driver =
935{
936 .owner = THIS_MODULE,
937 .open = ad1848_open,
938 .close = ad1848_close,
939 .output_block = ad1848_output_block,
940 .start_input = ad1848_start_input,
941 .prepare_for_input = ad1848_prepare_for_input,
942 .prepare_for_output = ad1848_prepare_for_output,
943 .halt_io = ad1848_halt,
944 .halt_input = ad1848_halt_input,
945 .halt_output = ad1848_halt_output,
946 .trigger = ad1848_trigger,
947 .set_speed = ad1848_set_speed,
948 .set_bits = ad1848_set_bits,
949 .set_channels = ad1848_set_channels
950};
951
952static struct mixer_operations ad1848_mixer_operations =
953{
954 .owner = THIS_MODULE,
955 .id = "SOUNDPORT",
956 .name = "AD1848/CS4248/CS4231",
957 .ioctl = ad1848_mixer_ioctl
958};
959
960static int ad1848_open(int dev, int mode)
961{
962 ad1848_info *devc;
963 ad1848_port_info *portc;
964 unsigned long flags;
965
966 if (dev < 0 || dev >= num_audiodevs)
967 return -ENXIO;
968
969 devc = (ad1848_info *) audio_devs[dev]->devc;
970 portc = (ad1848_port_info *) audio_devs[dev]->portc;
971
972 /* here we don't have to protect against intr */
973 spin_lock(&devc->lock);
974 if (portc->open_mode || (devc->open_mode & mode))
975 {
976 spin_unlock(&devc->lock);
977 return -EBUSY;
978 }
979 devc->dual_dma = 0;
980
981 if (audio_devs[dev]->flags & DMA_DUPLEX)
982 {
983 devc->dual_dma = 1;
984 }
985 devc->intr_active = 0;
986 devc->audio_mode = 0;
987 devc->open_mode |= mode;
988 portc->open_mode = mode;
989 spin_unlock(&devc->lock);
990 ad1848_trigger(dev, 0);
991
992 if (mode & OPEN_READ)
993 devc->record_dev = dev;
994 if (mode & OPEN_WRITE)
995 devc->playback_dev = dev;
996/*
997 * Mute output until the playback really starts. This decreases clicking (hope so).
998 */
999 spin_lock_irqsave(&devc->lock,flags);
1000 ad_mute(devc);
1001 spin_unlock_irqrestore(&devc->lock,flags);
1002
1003 return 0;
1004}
1005
1006static void ad1848_close(int dev)
1007{
1008 unsigned long flags;
1009 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1010 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1011
1012 devc->intr_active = 0;
1013 ad1848_halt(dev);
1014
1015 spin_lock_irqsave(&devc->lock,flags);
1016
1017 devc->audio_mode = 0;
1018 devc->open_mode &= ~portc->open_mode;
1019 portc->open_mode = 0;
1020
1021 ad_unmute(devc);
1022 spin_unlock_irqrestore(&devc->lock,flags);
1023}
1024
1025static void ad1848_output_block(int dev, unsigned long buf, int count, int intrflag)
1026{
1027 unsigned long flags, cnt;
1028 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1029 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1030
1031 cnt = count;
1032
1033 if (portc->audio_format == AFMT_IMA_ADPCM)
1034 {
1035 cnt /= 4;
1036 }
1037 else
1038 {
1039 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
1040 cnt >>= 1;
1041 }
1042 if (portc->channels > 1)
1043 cnt >>= 1;
1044 cnt--;
1045
1046 if ((devc->audio_mode & PCM_ENABLE_OUTPUT) && (audio_devs[dev]->flags & DMA_AUTOMODE) &&
1047 intrflag &&
1048 cnt == devc->xfer_count)
1049 {
1050 devc->audio_mode |= PCM_ENABLE_OUTPUT;
1051 devc->intr_active = 1;
1052 return; /*
1053 * Auto DMA mode on. No need to react
1054 */
1055 }
1056 spin_lock_irqsave(&devc->lock,flags);
1057
1058 ad_write(devc, 15, (unsigned char) (cnt & 0xff));
1059 ad_write(devc, 14, (unsigned char) ((cnt >> 8) & 0xff));
1060
1061 devc->xfer_count = cnt;
1062 devc->audio_mode |= PCM_ENABLE_OUTPUT;
1063 devc->intr_active = 1;
1064 spin_unlock_irqrestore(&devc->lock,flags);
1065}
1066
1067static void ad1848_start_input(int dev, unsigned long buf, int count, int intrflag)
1068{
1069 unsigned long flags, cnt;
1070 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1071 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1072
1073 cnt = count;
1074 if (portc->audio_format == AFMT_IMA_ADPCM)
1075 {
1076 cnt /= 4;
1077 }
1078 else
1079 {
1080 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
1081 cnt >>= 1;
1082 }
1083 if (portc->channels > 1)
1084 cnt >>= 1;
1085 cnt--;
1086
1087 if ((devc->audio_mode & PCM_ENABLE_INPUT) && (audio_devs[dev]->flags & DMA_AUTOMODE) &&
1088 intrflag &&
1089 cnt == devc->xfer_count)
1090 {
1091 devc->audio_mode |= PCM_ENABLE_INPUT;
1092 devc->intr_active = 1;
1093 return; /*
1094 * Auto DMA mode on. No need to react
1095 */
1096 }
1097 spin_lock_irqsave(&devc->lock,flags);
1098
1099 if (devc->model == MD_1848)
1100 {
1101 ad_write(devc, 15, (unsigned char) (cnt & 0xff));
1102 ad_write(devc, 14, (unsigned char) ((cnt >> 8) & 0xff));
1103 }
1104 else
1105 {
1106 ad_write(devc, 31, (unsigned char) (cnt & 0xff));
1107 ad_write(devc, 30, (unsigned char) ((cnt >> 8) & 0xff));
1108 }
1109
1110 ad_unmute(devc);
1111
1112 devc->xfer_count = cnt;
1113 devc->audio_mode |= PCM_ENABLE_INPUT;
1114 devc->intr_active = 1;
1115 spin_unlock_irqrestore(&devc->lock,flags);
1116}
1117
1118static int ad1848_prepare_for_output(int dev, int bsize, int bcount)
1119{
1120 int timeout;
1121 unsigned char fs, old_fs, tmp = 0;
1122 unsigned long flags;
1123 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1124 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1125
1126 ad_mute(devc);
1127
1128 spin_lock_irqsave(&devc->lock,flags);
1129 fs = portc->speed_bits | (portc->format_bits << 5);
1130
1131 if (portc->channels > 1)
1132 fs |= 0x10;
1133
1134 ad_enter_MCE(devc); /* Enables changes to the format select reg */
1135
1136 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE) /* Use alternate speed select registers */
1137 {
1138 fs &= 0xf0; /* Mask off the rate select bits */
1139
1140 ad_write(devc, 22, (portc->speed >> 8) & 0xff); /* Speed MSB */
1141 ad_write(devc, 23, portc->speed & 0xff); /* Speed LSB */
1142 }
1143 old_fs = ad_read(devc, 8);
1144
1145 if (devc->model == MD_4232 || devc->model >= MD_4236)
1146 {
1147 tmp = ad_read(devc, 16);
1148 ad_write(devc, 16, tmp | 0x30);
1149 }
1150 if (devc->model == MD_IWAVE)
1151 ad_write(devc, 17, 0xc2); /* Disable variable frequency select */
1152
1153 ad_write(devc, 8, fs);
1154
1155 /*
1156 * Write to I8 starts resynchronization. Wait until it completes.
1157 */
1158
1159 timeout = 0;
1160 while (timeout < 100 && inb(devc->base) != 0x80)
1161 timeout++;
1162 timeout = 0;
1163 while (timeout < 10000 && inb(devc->base) == 0x80)
1164 timeout++;
1165
1166 if (devc->model >= MD_4232)
1167 ad_write(devc, 16, tmp & ~0x30);
1168
1169 ad_leave_MCE(devc); /*
1170 * Starts the calibration process.
1171 */
1172 spin_unlock_irqrestore(&devc->lock,flags);
1173 devc->xfer_count = 0;
1174
1175#ifndef EXCLUDE_TIMERS
1176 if (dev == timer_installed && devc->timer_running)
1177 if ((fs & 0x01) != (old_fs & 0x01))
1178 {
1179 ad1848_tmr_reprogram(dev);
1180 }
1181#endif
1182 ad1848_halt_output(dev);
1183 return 0;
1184}
1185
1186static int ad1848_prepare_for_input(int dev, int bsize, int bcount)
1187{
1188 int timeout;
1189 unsigned char fs, old_fs, tmp = 0;
1190 unsigned long flags;
1191 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1192 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1193
1194 if (devc->audio_mode)
1195 return 0;
1196
1197 spin_lock_irqsave(&devc->lock,flags);
1198 fs = portc->speed_bits | (portc->format_bits << 5);
1199
1200 if (portc->channels > 1)
1201 fs |= 0x10;
1202
1203 ad_enter_MCE(devc); /* Enables changes to the format select reg */
1204
1205 if ((devc->model == MD_1845) || (devc->model == MD_1845_SSCAPE)) /* Use alternate speed select registers */
1206 {
1207 fs &= 0xf0; /* Mask off the rate select bits */
1208
1209 ad_write(devc, 22, (portc->speed >> 8) & 0xff); /* Speed MSB */
1210 ad_write(devc, 23, portc->speed & 0xff); /* Speed LSB */
1211 }
1212 if (devc->model == MD_4232)
1213 {
1214 tmp = ad_read(devc, 16);
1215 ad_write(devc, 16, tmp | 0x30);
1216 }
1217 if (devc->model == MD_IWAVE)
1218 ad_write(devc, 17, 0xc2); /* Disable variable frequency select */
1219
1220 /*
1221 * If mode >= 2 (CS4231), set I28. It's the capture format register.
1222 */
1223
1224 if (devc->model != MD_1848)
1225 {
1226 old_fs = ad_read(devc, 28);
1227 ad_write(devc, 28, fs);
1228
1229 /*
1230 * Write to I28 starts resynchronization. Wait until it completes.
1231 */
1232
1233 timeout = 0;
1234 while (timeout < 100 && inb(devc->base) != 0x80)
1235 timeout++;
1236
1237 timeout = 0;
1238 while (timeout < 10000 && inb(devc->base) == 0x80)
1239 timeout++;
1240
1241 if (devc->model != MD_1848 && devc->model != MD_1845 && devc->model != MD_1845_SSCAPE)
1242 {
1243 /*
1244 * CS4231 compatible devices don't have separate sampling rate selection
1245 * register for recording an playback. The I8 register is shared so we have to
1246 * set the speed encoding bits of it too.
1247 */
1248 unsigned char tmp = portc->speed_bits | (ad_read(devc, 8) & 0xf0);
1249
1250 ad_write(devc, 8, tmp);
1251 /*
1252 * Write to I8 starts resynchronization. Wait until it completes.
1253 */
1254 timeout = 0;
1255 while (timeout < 100 && inb(devc->base) != 0x80)
1256 timeout++;
1257
1258 timeout = 0;
1259 while (timeout < 10000 && inb(devc->base) == 0x80)
1260 timeout++;
1261 }
1262 }
1263 else
1264 { /* For AD1848 set I8. */
1265
1266 old_fs = ad_read(devc, 8);
1267 ad_write(devc, 8, fs);
1268 /*
1269 * Write to I8 starts resynchronization. Wait until it completes.
1270 */
1271 timeout = 0;
1272 while (timeout < 100 && inb(devc->base) != 0x80)
1273 timeout++;
1274 timeout = 0;
1275 while (timeout < 10000 && inb(devc->base) == 0x80)
1276 timeout++;
1277 }
1278
1279 if (devc->model == MD_4232)
1280 ad_write(devc, 16, tmp & ~0x30);
1281
1282 ad_leave_MCE(devc); /*
1283 * Starts the calibration process.
1284 */
1285 spin_unlock_irqrestore(&devc->lock,flags);
1286 devc->xfer_count = 0;
1287
1288#ifndef EXCLUDE_TIMERS
1289 if (dev == timer_installed && devc->timer_running)
1290 {
1291 if ((fs & 0x01) != (old_fs & 0x01))
1292 {
1293 ad1848_tmr_reprogram(dev);
1294 }
1295 }
1296#endif
1297 ad1848_halt_input(dev);
1298 return 0;
1299}
1300
1301static void ad1848_halt(int dev)
1302{
1303 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1304 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1305
1306 unsigned char bits = ad_read(devc, 9);
1307
1308 if (bits & 0x01 && (portc->open_mode & OPEN_WRITE))
1309 ad1848_halt_output(dev);
1310
1311 if (bits & 0x02 && (portc->open_mode & OPEN_READ))
1312 ad1848_halt_input(dev);
1313 devc->audio_mode = 0;
1314}
1315
1316static void ad1848_halt_input(int dev)
1317{
1318 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1319 unsigned long flags;
1320
1321 if (!(ad_read(devc, 9) & 0x02))
1322 return; /* Capture not enabled */
1323
1324 spin_lock_irqsave(&devc->lock,flags);
1325
1326 ad_mute(devc);
1327
1328 {
1329 int tmout;
1330
1331 if(!isa_dma_bridge_buggy)
1332 disable_dma(audio_devs[dev]->dmap_in->dma);
1333
1334 for (tmout = 0; tmout < 100000; tmout++)
1335 if (ad_read(devc, 11) & 0x10)
1336 break;
1337 ad_write(devc, 9, ad_read(devc, 9) & ~0x02); /* Stop capture */
1338
1339 if(!isa_dma_bridge_buggy)
1340 enable_dma(audio_devs[dev]->dmap_in->dma);
1341 devc->audio_mode &= ~PCM_ENABLE_INPUT;
1342 }
1343
1344 outb(0, io_Status(devc)); /* Clear interrupt status */
1345 outb(0, io_Status(devc)); /* Clear interrupt status */
1346
1347 devc->audio_mode &= ~PCM_ENABLE_INPUT;
1348
1349 spin_unlock_irqrestore(&devc->lock,flags);
1350}
1351
1352static void ad1848_halt_output(int dev)
1353{
1354 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1355 unsigned long flags;
1356
1357 if (!(ad_read(devc, 9) & 0x01))
1358 return; /* Playback not enabled */
1359
1360 spin_lock_irqsave(&devc->lock,flags);
1361
1362 ad_mute(devc);
1363 {
1364 int tmout;
1365
1366 if(!isa_dma_bridge_buggy)
1367 disable_dma(audio_devs[dev]->dmap_out->dma);
1368
1369 for (tmout = 0; tmout < 100000; tmout++)
1370 if (ad_read(devc, 11) & 0x10)
1371 break;
1372 ad_write(devc, 9, ad_read(devc, 9) & ~0x01); /* Stop playback */
1373
1374 if(!isa_dma_bridge_buggy)
1375 enable_dma(audio_devs[dev]->dmap_out->dma);
1376
1377 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1378 }
1379
1380 outb((0), io_Status(devc)); /* Clear interrupt status */
1381 outb((0), io_Status(devc)); /* Clear interrupt status */
1382
1383 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1384
1385 spin_unlock_irqrestore(&devc->lock,flags);
1386}
1387
1388static void ad1848_trigger(int dev, int state)
1389{
1390 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1391 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1392 unsigned long flags;
1393 unsigned char tmp, old;
1394
1395 spin_lock_irqsave(&devc->lock,flags);
1396 state &= devc->audio_mode;
1397
1398 tmp = old = ad_read(devc, 9);
1399
1400 if (portc->open_mode & OPEN_READ)
1401 {
1402 if (state & PCM_ENABLE_INPUT)
1403 tmp |= 0x02;
1404 else
1405 tmp &= ~0x02;
1406 }
1407 if (portc->open_mode & OPEN_WRITE)
1408 {
1409 if (state & PCM_ENABLE_OUTPUT)
1410 tmp |= 0x01;
1411 else
1412 tmp &= ~0x01;
1413 }
1414 /* ad_mute(devc); */
1415 if (tmp != old)
1416 {
1417 ad_write(devc, 9, tmp);
1418 ad_unmute(devc);
1419 }
1420 spin_unlock_irqrestore(&devc->lock,flags);
1421}
1422
1423static void ad1848_init_hw(ad1848_info * devc)
1424{
1425 int i;
1426 int *init_values;
1427
1428 /*
1429 * Initial values for the indirect registers of CS4248/AD1848.
1430 */
1431 static int init_values_a[] =
1432 {
1433 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1434 0x00, 0x0c, 0x02, 0x00, 0x8a, 0x01, 0x00, 0x00,
1435
1436 /* Positions 16 to 31 just for CS4231/2 and ad1845 */
1437 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1439 };
1440
1441 static int init_values_b[] =
1442 {
1443 /*
1444 Values for the newer chips
1445 Some of the register initialization values were changed. In
1446 order to get rid of the click that preceded PCM playback,
1447 calibration was disabled on the 10th byte. On that same byte,
1448 dual DMA was enabled; on the 11th byte, ADC dithering was
1449 enabled, since that is theoretically desirable; on the 13th
1450 byte, Mode 3 was selected, to enable access to extended
1451 registers.
1452 */
1453 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1454 0x00, 0x00, 0x06, 0x00, 0xe0, 0x01, 0x00, 0x00,
1455 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1456 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1457 };
1458
1459 /*
1460 * Select initialisation data
1461 */
1462
1463 init_values = init_values_a;
1464 if(devc->model >= MD_4236)
1465 init_values = init_values_b;
1466
1467 for (i = 0; i < 16; i++)
1468 ad_write(devc, i, init_values[i]);
1469
1470
1471 ad_mute(devc); /* Initialize some variables */
1472 ad_unmute(devc); /* Leave it unmuted now */
1473
1474 if (devc->model > MD_1848)
1475 {
1476 if (devc->model == MD_1845_SSCAPE)
1477 ad_write(devc, 12, ad_read(devc, 12) | 0x50);
1478 else
1479 ad_write(devc, 12, ad_read(devc, 12) | 0x40); /* Mode2 = enabled */
1480
1481 if (devc->model == MD_IWAVE)
1482 ad_write(devc, 12, 0x6c); /* Select codec mode 3 */
1483
1484 if (devc->model != MD_1845_SSCAPE)
1485 for (i = 16; i < 32; i++)
1486 ad_write(devc, i, init_values[i]);
1487
1488 if (devc->model == MD_IWAVE)
1489 ad_write(devc, 16, 0x30); /* Playback and capture counters enabled */
1490 }
1491 if (devc->model > MD_1848)
1492 {
1493 if (devc->audio_flags & DMA_DUPLEX)
1494 ad_write(devc, 9, ad_read(devc, 9) & ~0x04); /* Dual DMA mode */
1495 else
1496 ad_write(devc, 9, ad_read(devc, 9) | 0x04); /* Single DMA mode */
1497
1498 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE)
1499 ad_write(devc, 27, ad_read(devc, 27) | 0x08); /* Alternate freq select enabled */
1500
1501 if (devc->model == MD_IWAVE)
1502 { /* Some magic Interwave specific initialization */
1503 ad_write(devc, 12, 0x6c); /* Select codec mode 3 */
1504 ad_write(devc, 16, 0x30); /* Playback and capture counters enabled */
1505 ad_write(devc, 17, 0xc2); /* Alternate feature enable */
1506 }
1507 }
1508 else
1509 {
1510 devc->audio_flags &= ~DMA_DUPLEX;
1511 ad_write(devc, 9, ad_read(devc, 9) | 0x04); /* Single DMA mode */
1512 if (soundpro)
1513 ad_write(devc, 12, ad_read(devc, 12) | 0x40); /* Mode2 = enabled */
1514 }
1515
1516 outb((0), io_Status(devc)); /* Clear pending interrupts */
1517
1518 /*
1519 * Toggle the MCE bit. It completes the initialization phase.
1520 */
1521
1522 ad_enter_MCE(devc); /* In case the bit was off */
1523 ad_leave_MCE(devc);
1524
1525 ad1848_mixer_reset(devc);
1526}
1527
1528int ad1848_detect(struct resource *ports, int *ad_flags, int *osp)
1529{
1530 unsigned char tmp;
1531 ad1848_info *devc = &adev_info[nr_ad1848_devs];
1532 unsigned char tmp1 = 0xff, tmp2 = 0xff;
1533 int optiC930 = 0; /* OPTi 82C930 flag */
1534 int interwave = 0;
1535 int ad1847_flag = 0;
1536 int cs4248_flag = 0;
1537 int sscape_flag = 0;
1538 int io_base = ports->start;
1539
1540 int i;
1541
1542 DDB(printk("ad1848_detect(%x)\n", io_base));
1543
1544 if (ad_flags)
1545 {
1546 if (*ad_flags == 0x12345678)
1547 {
1548 interwave = 1;
1549 *ad_flags = 0;
1550 }
1551
1552 if (*ad_flags == 0x87654321)
1553 {
1554 sscape_flag = 1;
1555 *ad_flags = 0;
1556 }
1557
1558 if (*ad_flags == 0x12345677)
1559 {
1560 cs4248_flag = 1;
1561 *ad_flags = 0;
1562 }
1563 }
1564 if (nr_ad1848_devs >= MAX_AUDIO_DEV)
1565 {
1566 printk(KERN_ERR "ad1848 - Too many audio devices\n");
1567 return 0;
1568 }
1569 spin_lock_init(&devc->lock);
1570 devc->base = io_base;
1571 devc->irq_ok = 0;
1572 devc->timer_running = 0;
1573 devc->MCE_bit = 0x40;
1574 devc->irq = 0;
1575 devc->open_mode = 0;
1576 devc->chip_name = devc->name = "AD1848";
1577 devc->model = MD_1848; /* AD1848 or CS4248 */
1578 devc->levels = NULL;
1579 devc->debug_flag = 0;
1580
1581 /*
1582 * Check that the I/O address is in use.
1583 *
1584 * The bit 0x80 of the base I/O port is known to be 0 after the
1585 * chip has performed its power on initialization. Just assume
1586 * this has happened before the OS is starting.
1587 *
1588 * If the I/O address is unused, it typically returns 0xff.
1589 */
1590
1591 if (inb(devc->base) == 0xff)
1592 {
1593 DDB(printk("ad1848_detect: The base I/O address appears to be dead\n"));
1594 }
1595
1596 /*
1597 * Wait for the device to stop initialization
1598 */
1599
1600 DDB(printk("ad1848_detect() - step 0\n"));
1601
1602 for (i = 0; i < 10000000; i++)
1603 {
1604 unsigned char x = inb(devc->base);
1605
1606 if (x == 0xff || !(x & 0x80))
1607 break;
1608 }
1609
1610 DDB(printk("ad1848_detect() - step A\n"));
1611
1612 if (inb(devc->base) == 0x80) /* Not ready. Let's wait */
1613 ad_leave_MCE(devc);
1614
1615 if ((inb(devc->base) & 0x80) != 0x00) /* Not a AD1848 */
1616 {
1617 DDB(printk("ad1848 detect error - step A (%02x)\n", (int) inb(devc->base)));
1618 return 0;
1619 }
1620
1621 /*
1622 * Test if it's possible to change contents of the indirect registers.
1623 * Registers 0 and 1 are ADC volume registers. The bit 0x10 is read only
1624 * so try to avoid using it.
1625 */
1626
1627 DDB(printk("ad1848_detect() - step B\n"));
1628 ad_write(devc, 0, 0xaa);
1629 ad_write(devc, 1, 0x45); /* 0x55 with bit 0x10 clear */
1630
1631 if ((tmp1 = ad_read(devc, 0)) != 0xaa || (tmp2 = ad_read(devc, 1)) != 0x45)
1632 {
1633 if (tmp2 == 0x65) /* AD1847 has couple of bits hardcoded to 1 */
1634 ad1847_flag = 1;
1635 else
1636 {
1637 DDB(printk("ad1848 detect error - step B (%x/%x)\n", tmp1, tmp2));
1638 return 0;
1639 }
1640 }
1641 DDB(printk("ad1848_detect() - step C\n"));
1642 ad_write(devc, 0, 0x45);
1643 ad_write(devc, 1, 0xaa);
1644
1645 if ((tmp1 = ad_read(devc, 0)) != 0x45 || (tmp2 = ad_read(devc, 1)) != 0xaa)
1646 {
1647 if (tmp2 == 0x8a) /* AD1847 has few bits hardcoded to 1 */
1648 ad1847_flag = 1;
1649 else
1650 {
1651 DDB(printk("ad1848 detect error - step C (%x/%x)\n", tmp1, tmp2));
1652 return 0;
1653 }
1654 }
1655
1656 /*
1657 * The indirect register I12 has some read only bits. Let's
1658 * try to change them.
1659 */
1660
1661 DDB(printk("ad1848_detect() - step D\n"));
1662 tmp = ad_read(devc, 12);
1663 ad_write(devc, 12, (~tmp) & 0x0f);
1664
1665 if ((tmp & 0x0f) != ((tmp1 = ad_read(devc, 12)) & 0x0f))
1666 {
1667 DDB(printk("ad1848 detect error - step D (%x)\n", tmp1));
1668 return 0;
1669 }
1670
1671 /*
1672 * NOTE! Last 4 bits of the reg I12 tell the chip revision.
1673 * 0x01=RevB and 0x0A=RevC.
1674 */
1675
1676 /*
1677 * The original AD1848/CS4248 has just 15 indirect registers. This means
1678 * that I0 and I16 should return the same value (etc.).
1679 * However this doesn't work with CS4248. Actually it seems to be impossible
1680 * to detect if the chip is a CS4231 or CS4248.
1681 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test fails
1682 * with CS4231.
1683 */
1684
1685 /*
1686 * OPTi 82C930 has mode2 control bit in another place. This test will fail
1687 * with it. Accept this situation as a possible indication of this chip.
1688 */
1689
1690 DDB(printk("ad1848_detect() - step F\n"));
1691 ad_write(devc, 12, 0); /* Mode2=disabled */
1692
1693 for (i = 0; i < 16; i++)
1694 {
1695 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16)))
1696 {
1697 DDB(printk("ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i, tmp1, tmp2));
1698 if (!ad1847_flag)
1699 optiC930 = 1;
1700 break;
1701 }
1702 }
1703
1704 /*
1705 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit (0x40).
1706 * The bit 0x80 is always 1 in CS4248 and CS4231.
1707 */
1708
1709 DDB(printk("ad1848_detect() - step G\n"));
1710
1711 if (ad_flags && *ad_flags == 400)
1712 *ad_flags = 0;
1713 else
1714 ad_write(devc, 12, 0x40); /* Set mode2, clear 0x80 */
1715
1716
1717 if (ad_flags)
1718 *ad_flags = 0;
1719
1720 tmp1 = ad_read(devc, 12);
1721 if (tmp1 & 0x80)
1722 {
1723 if (ad_flags)
1724 *ad_flags |= AD_F_CS4248;
1725
1726 devc->chip_name = "CS4248"; /* Our best knowledge just now */
1727 }
1728 if (optiC930 || (tmp1 & 0xc0) == (0x80 | 0x40))
1729 {
1730 /*
1731 * CS4231 detected - is it?
1732 *
1733 * Verify that setting I0 doesn't change I16.
1734 */
1735
1736 DDB(printk("ad1848_detect() - step H\n"));
1737 ad_write(devc, 16, 0); /* Set I16 to known value */
1738
1739 ad_write(devc, 0, 0x45);
1740 if ((tmp1 = ad_read(devc, 16)) != 0x45) /* No change -> CS4231? */
1741 {
1742 ad_write(devc, 0, 0xaa);
1743 if ((tmp1 = ad_read(devc, 16)) == 0xaa) /* Rotten bits? */
1744 {
1745 DDB(printk("ad1848 detect error - step H(%x)\n", tmp1));
1746 return 0;
1747 }
1748
1749 /*
1750 * Verify that some bits of I25 are read only.
1751 */
1752
1753 DDB(printk("ad1848_detect() - step I\n"));
1754 tmp1 = ad_read(devc, 25); /* Original bits */
1755 ad_write(devc, 25, ~tmp1); /* Invert all bits */
1756 if ((ad_read(devc, 25) & 0xe7) == (tmp1 & 0xe7))
1757 {
1758 int id;
1759
1760 /*
1761 * It's at least CS4231
1762 */
1763
1764 devc->chip_name = "CS4231";
1765 devc->model = MD_4231;
1766
1767 /*
1768 * It could be an AD1845 or CS4231A as well.
1769 * CS4231 and AD1845 report the same revision info in I25
1770 * while the CS4231A reports different.
1771 */
1772
1773 id = ad_read(devc, 25);
1774 if ((id & 0xe7) == 0x80) /* Device busy??? */
1775 id = ad_read(devc, 25);
1776 if ((id & 0xe7) == 0x80) /* Device still busy??? */
1777 id = ad_read(devc, 25);
1778 DDB(printk("ad1848_detect() - step J (%02x/%02x)\n", id, ad_read(devc, 25)));
1779
1780 if ((id & 0xe7) == 0x80) {
1781 /*
1782 * It must be a CS4231 or AD1845. The register I23 of
1783 * CS4231 is undefined and it appears to be read only.
1784 * AD1845 uses I23 for setting sample rate. Assume
1785 * the chip is AD1845 if I23 is changeable.
1786 */
1787
1788 unsigned char tmp = ad_read(devc, 23);
1789 ad_write(devc, 23, ~tmp);
1790
1791 if (interwave)
1792 {
1793 devc->model = MD_IWAVE;
1794 devc->chip_name = "IWave";
1795 }
1796 else if (ad_read(devc, 23) != tmp) /* AD1845 ? */
1797 {
1798 devc->chip_name = "AD1845";
1799 devc->model = MD_1845;
1800 }
1801 else if (cs4248_flag)
1802 {
1803 if (ad_flags)
1804 *ad_flags |= AD_F_CS4248;
1805 devc->chip_name = "CS4248";
1806 devc->model = MD_1848;
1807 ad_write(devc, 12, ad_read(devc, 12) & ~0x40); /* Mode2 off */
1808 }
1809 ad_write(devc, 23, tmp); /* Restore */
1810 }
1811 else
1812 {
1813 switch (id & 0x1f) {
1814 case 3: /* CS4236/CS4235/CS42xB/CS4239 */
1815 {
1816 int xid;
1817 ad_write(devc, 12, ad_read(devc, 12) | 0x60); /* switch to mode 3 */
1818 ad_write(devc, 23, 0x9c); /* select extended register 25 */
1819 xid = inb(io_Indexed_Data(devc));
1820 ad_write(devc, 12, ad_read(devc, 12) & ~0x60); /* back to mode 0 */
1821 switch (xid & 0x1f)
1822 {
1823 case 0x00:
1824 devc->chip_name = "CS4237B(B)";
1825 devc->model = MD_42xB;
1826 break;
1827 case 0x08:
1828 /* Seems to be a 4238 ?? */
1829 devc->chip_name = "CS4238";
1830 devc->model = MD_42xB;
1831 break;
1832 case 0x09:
1833 devc->chip_name = "CS4238B";
1834 devc->model = MD_42xB;
1835 break;
1836 case 0x0b:
1837 devc->chip_name = "CS4236B";
1838 devc->model = MD_4236;
1839 break;
1840 case 0x10:
1841 devc->chip_name = "CS4237B";
1842 devc->model = MD_42xB;
1843 break;
1844 case 0x1d:
1845 devc->chip_name = "CS4235";
1846 devc->model = MD_4235;
1847 break;
1848 case 0x1e:
1849 devc->chip_name = "CS4239";
1850 devc->model = MD_4239;
1851 break;
1852 default:
1853 printk("Chip ident is %X.\n", xid&0x1F);
1854 devc->chip_name = "CS42xx";
1855 devc->model = MD_4232;
1856 break;
1857 }
1858 }
1859 break;
1860
1861 case 2: /* CS4232/CS4232A */
1862 devc->chip_name = "CS4232";
1863 devc->model = MD_4232;
1864 break;
1865
1866 case 0:
1867 if ((id & 0xe0) == 0xa0)
1868 {
1869 devc->chip_name = "CS4231A";
1870 devc->model = MD_4231A;
1871 }
1872 else
1873 {
1874 devc->chip_name = "CS4321";
1875 devc->model = MD_4231;
1876 }
1877 break;
1878
1879 default: /* maybe */
1880 DDB(printk("ad1848: I25 = %02x/%02x\n", ad_read(devc, 25), ad_read(devc, 25) & 0xe7));
1881 if (optiC930)
1882 {
1883 devc->chip_name = "82C930";
1884 devc->model = MD_C930;
1885 }
1886 else
1887 {
1888 devc->chip_name = "CS4231";
1889 devc->model = MD_4231;
1890 }
1891 }
1892 }
1893 }
1894 ad_write(devc, 25, tmp1); /* Restore bits */
1895
1896 DDB(printk("ad1848_detect() - step K\n"));
1897 }
1898 } else if (tmp1 == 0x0a) {
1899 /*
1900 * Is it perhaps a SoundPro CMI8330?
1901 * If so, then we should be able to change indirect registers
1902 * greater than I15 after activating MODE2, even though reading
1903 * back I12 does not show it.
1904 */
1905
1906 /*
1907 * Let's try comparing register values
1908 */
1909 for (i = 0; i < 16; i++) {
1910 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16))) {
1911 DDB(printk("ad1848 detect step H(%d/%x/%x) - SoundPro chip?\n", i, tmp1, tmp2));
1912 soundpro = 1;
1913 devc->chip_name = "SoundPro CMI 8330";
1914 break;
1915 }
1916 }
1917 }
1918
1919 DDB(printk("ad1848_detect() - step L\n"));
1920 if (ad_flags)
1921 {
1922 if (devc->model != MD_1848)
1923 *ad_flags |= AD_F_CS4231;
1924 }
1925 DDB(printk("ad1848_detect() - Detected OK\n"));
1926
1927 if (devc->model == MD_1848 && ad1847_flag)
1928 devc->chip_name = "AD1847";
1929
1930
1931 if (sscape_flag == 1)
1932 devc->model = MD_1845_SSCAPE;
1933
1934 return 1;
1935}
1936
1937int ad1848_init (char *name, struct resource *ports, int irq, int dma_playback,
1938 int dma_capture, int share_dma, int *osp, struct module *owner)
1939{
1940 /*
1941 * NOTE! If irq < 0, there is another driver which has allocated the IRQ
1942 * so that this driver doesn't need to allocate/deallocate it.
1943 * The actually used IRQ is ABS(irq).
1944 */
1945
1946 int my_dev;
1947 char dev_name[100];
1948 int e;
1949
1950 ad1848_info *devc = &adev_info[nr_ad1848_devs];
1951
1952 ad1848_port_info *portc = NULL;
1953
1954 devc->irq = (irq > 0) ? irq : 0;
1955 devc->open_mode = 0;
1956 devc->timer_ticks = 0;
1957 devc->dma1 = dma_playback;
1958 devc->dma2 = dma_capture;
1959 devc->subtype = cfg.card_subtype;
1960 devc->audio_flags = DMA_AUTOMODE;
1961 devc->playback_dev = devc->record_dev = 0;
1962 if (name != NULL)
1963 devc->name = name;
1964
1965 if (name != NULL && name[0] != 0)
1966 sprintf(dev_name,
1967 "%s (%s)", name, devc->chip_name);
1968 else
1969 sprintf(dev_name,
1970 "Generic audio codec (%s)", devc->chip_name);
1971
1972 rename_region(ports, devc->name);
1973
1974 conf_printf2(dev_name, devc->base, devc->irq, dma_playback, dma_capture);
1975
1976 if (devc->model == MD_1848 || devc->model == MD_C930)
1977 devc->audio_flags |= DMA_HARDSTOP;
1978
1979 if (devc->model > MD_1848)
1980 {
1981 if (devc->dma1 == devc->dma2 || devc->dma2 == -1 || devc->dma1 == -1)
1982 devc->audio_flags &= ~DMA_DUPLEX;
1983 else
1984 devc->audio_flags |= DMA_DUPLEX;
1985 }
1986
1987 portc = kmalloc(sizeof(ad1848_port_info), GFP_KERNEL);
1988 if(portc==NULL) {
1989 release_region(devc->base, 4);
1990 return -1;
1991 }
1992
1993 if ((my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
1994 dev_name,
1995 &ad1848_audio_driver,
1996 sizeof(struct audio_driver),
1997 devc->audio_flags,
1998 ad_format_mask[devc->model],
1999 devc,
2000 dma_playback,
2001 dma_capture)) < 0)
2002 {
2003 release_region(devc->base, 4);
2004 kfree(portc);
2005 return -1;
2006 }
2007
2008 audio_devs[my_dev]->portc = portc;
2009 audio_devs[my_dev]->mixer_dev = -1;
2010 if (owner)
2011 audio_devs[my_dev]->d->owner = owner;
2012 memset((char *) portc, 0, sizeof(*portc));
2013
2014 nr_ad1848_devs++;
2015
2016 ad1848_init_hw(devc);
2017
2018 if (irq > 0)
2019 {
2020 devc->dev_no = my_dev;
2021 if (request_irq(devc->irq, adintr, 0, devc->name,
2022 (void *)(long)my_dev) < 0)
2023 {
2024 printk(KERN_WARNING "ad1848: Unable to allocate IRQ\n");
2025 /* Don't free it either then.. */
2026 devc->irq = 0;
2027 }
2028 if (capabilities[devc->model].flags & CAP_F_TIMER)
2029 {
2030#ifndef CONFIG_SMP
2031 int x;
2032 unsigned char tmp = ad_read(devc, 16);
2033#endif
2034
2035 devc->timer_ticks = 0;
2036
2037 ad_write(devc, 21, 0x00); /* Timer MSB */
2038 ad_write(devc, 20, 0x10); /* Timer LSB */
2039#ifndef CONFIG_SMP
2040 ad_write(devc, 16, tmp | 0x40); /* Enable timer */
2041 for (x = 0; x < 100000 && devc->timer_ticks == 0; x++);
2042 ad_write(devc, 16, tmp & ~0x40); /* Disable timer */
2043
2044 if (devc->timer_ticks == 0)
2045 printk(KERN_WARNING "ad1848: Interrupt test failed (IRQ%d)\n", irq);
2046 else
2047 {
2048 DDB(printk("Interrupt test OK\n"));
2049 devc->irq_ok = 1;
2050 }
2051#else
2052 devc->irq_ok = 1;
2053#endif
2054 }
2055 else
2056 devc->irq_ok = 1; /* Couldn't test. assume it's OK */
2057 } else if (irq < 0)
2058 devc->dev_no = my_dev;
2059
2060#ifndef EXCLUDE_TIMERS
2061 if ((capabilities[devc->model].flags & CAP_F_TIMER) &&
2062 devc->irq_ok)
2063 ad1848_tmr_install(my_dev);
2064#endif
2065
2066 if (!share_dma)
2067 {
2068 if (sound_alloc_dma(dma_playback, devc->name))
2069 printk(KERN_WARNING "ad1848.c: Can't allocate DMA%d\n", dma_playback);
2070
2071 if (dma_capture != dma_playback)
2072 if (sound_alloc_dma(dma_capture, devc->name))
2073 printk(KERN_WARNING "ad1848.c: Can't allocate DMA%d\n", dma_capture);
2074 }
2075
2076 if ((e = sound_install_mixer(MIXER_DRIVER_VERSION,
2077 dev_name,
2078 &ad1848_mixer_operations,
2079 sizeof(struct mixer_operations),
2080 devc)) >= 0)
2081 {
2082 audio_devs[my_dev]->mixer_dev = e;
2083 if (owner)
2084 mixer_devs[e]->owner = owner;
2085 }
2086 return my_dev;
2087}
2088
2089int ad1848_control(int cmd, int arg)
2090{
2091 ad1848_info *devc;
2092 unsigned long flags;
2093
2094 if (nr_ad1848_devs < 1)
2095 return -ENODEV;
2096
2097 devc = &adev_info[nr_ad1848_devs - 1];
2098
2099 switch (cmd)
2100 {
2101 case AD1848_SET_XTAL: /* Change clock frequency of AD1845 (only ) */
2102 if (devc->model != MD_1845 && devc->model != MD_1845_SSCAPE)
2103 return -EINVAL;
2104 spin_lock_irqsave(&devc->lock,flags);
2105 ad_enter_MCE(devc);
2106 ad_write(devc, 29, (ad_read(devc, 29) & 0x1f) | (arg << 5));
2107 ad_leave_MCE(devc);
2108 spin_unlock_irqrestore(&devc->lock,flags);
2109 break;
2110
2111 case AD1848_MIXER_REROUTE:
2112 {
2113 int o = (arg >> 8) & 0xff;
2114 int n = arg & 0xff;
2115
2116 if (o < 0 || o >= SOUND_MIXER_NRDEVICES)
2117 return -EINVAL;
2118
2119 if (!(devc->supported_devices & (1 << o)) &&
2120 !(devc->supported_rec_devices & (1 << o)))
2121 return -EINVAL;
2122
2123 if (n == SOUND_MIXER_NONE)
2124 { /* Just hide this control */
2125 ad1848_mixer_set(devc, o, 0); /* Shut up it */
2126 devc->supported_devices &= ~(1 << o);
2127 devc->supported_rec_devices &= ~(1 << o);
2128 break;
2129 }
2130
2131 /* Make the mixer control identified by o to appear as n */
2132 if (n < 0 || n >= SOUND_MIXER_NRDEVICES)
2133 return -EINVAL;
2134
2135 devc->mixer_reroute[n] = o; /* Rename the control */
2136 if (devc->supported_devices & (1 << o))
2137 devc->supported_devices |= (1 << n);
2138 if (devc->supported_rec_devices & (1 << o))
2139 devc->supported_rec_devices |= (1 << n);
2140
2141 devc->supported_devices &= ~(1 << o);
2142 devc->supported_rec_devices &= ~(1 << o);
2143 }
2144 break;
2145 }
2146 return 0;
2147}
2148
2149void ad1848_unload(int io_base, int irq, int dma_playback, int dma_capture, int share_dma)
2150{
2151 int i, mixer, dev = 0;
2152 ad1848_info *devc = NULL;
2153
2154 for (i = 0; devc == NULL && i < nr_ad1848_devs; i++)
2155 {
2156 if (adev_info[i].base == io_base)
2157 {
2158 devc = &adev_info[i];
2159 dev = devc->dev_no;
2160 }
2161 }
2162
2163 if (devc != NULL)
2164 {
2165 kfree(audio_devs[dev]->portc);
2166 release_region(devc->base, 4);
2167
2168 if (!share_dma)
2169 {
2170 if (devc->irq > 0) /* There is no point in freeing irq, if it wasn't allocated */
2171 free_irq(devc->irq, (void *)(long)devc->dev_no);
2172
2173 sound_free_dma(dma_playback);
2174
2175 if (dma_playback != dma_capture)
2176 sound_free_dma(dma_capture);
2177
2178 }
2179 mixer = audio_devs[devc->dev_no]->mixer_dev;
2180 if(mixer>=0)
2181 sound_unload_mixerdev(mixer);
2182
2183 nr_ad1848_devs--;
2184 for ( ; i < nr_ad1848_devs ; i++)
2185 adev_info[i] = adev_info[i+1];
2186 }
2187 else
2188 printk(KERN_ERR "ad1848: Can't find device to be unloaded. Base=%x\n", io_base);
2189}
2190
2191static irqreturn_t adintr(int irq, void *dev_id)
2192{
2193 unsigned char status;
2194 ad1848_info *devc;
2195 int dev;
2196 int alt_stat = 0xff;
2197 unsigned char c930_stat = 0;
2198 int cnt = 0;
2199
2200 dev = (long)dev_id;
2201 devc = (ad1848_info *) audio_devs[dev]->devc;
2202
2203interrupt_again: /* Jump back here if int status doesn't reset */
2204
2205 status = inb(io_Status(devc));
2206
2207 if (status == 0x80)
2208 printk(KERN_DEBUG "adintr: Why?\n");
2209 if (devc->model == MD_1848)
2210 outb((0), io_Status(devc)); /* Clear interrupt status */
2211
2212 if (status & 0x01)
2213 {
2214 if (devc->model == MD_C930)
2215 { /* 82C930 has interrupt status register in MAD16 register MC11 */
2216
2217 spin_lock(&devc->lock);
2218
2219 /* 0xe0e is C930 address port
2220 * 0xe0f is C930 data port
2221 */
2222 outb(11, 0xe0e);
2223 c930_stat = inb(0xe0f);
2224 outb((~c930_stat), 0xe0f);
2225
2226 spin_unlock(&devc->lock);
2227
2228 alt_stat = (c930_stat << 2) & 0x30;
2229 }
2230 else if (devc->model != MD_1848)
2231 {
2232 spin_lock(&devc->lock);
2233 alt_stat = ad_read(devc, 24);
2234 ad_write(devc, 24, ad_read(devc, 24) & ~alt_stat); /* Selective ack */
2235 spin_unlock(&devc->lock);
2236 }
2237
2238 if ((devc->open_mode & OPEN_READ) && (devc->audio_mode & PCM_ENABLE_INPUT) && (alt_stat & 0x20))
2239 {
2240 DMAbuf_inputintr(devc->record_dev);
2241 }
2242 if ((devc->open_mode & OPEN_WRITE) && (devc->audio_mode & PCM_ENABLE_OUTPUT) &&
2243 (alt_stat & 0x10))
2244 {
2245 DMAbuf_outputintr(devc->playback_dev, 1);
2246 }
2247 if (devc->model != MD_1848 && (alt_stat & 0x40)) /* Timer interrupt */
2248 {
2249 devc->timer_ticks++;
2250#ifndef EXCLUDE_TIMERS
2251 if (timer_installed == dev && devc->timer_running)
2252 sound_timer_interrupt();
2253#endif
2254 }
2255 }
2256/*
2257 * Sometimes playback or capture interrupts occur while a timer interrupt
2258 * is being handled. The interrupt will not be retriggered if we don't
2259 * handle it now. Check if an interrupt is still pending and restart
2260 * the handler in this case.
2261 */
2262 if (inb(io_Status(devc)) & 0x01 && cnt++ < 4)
2263 {
2264 goto interrupt_again;
2265 }
2266 return IRQ_HANDLED;
2267}
2268
2269/*
2270 * Experimental initialization sequence for the integrated sound system
2271 * of the Compaq Deskpro M.
2272 */
2273
2274static int init_deskpro_m(struct address_info *hw_config)
2275{
2276 unsigned char tmp;
2277
2278 if ((tmp = inb(0xc44)) == 0xff)
2279 {
2280 DDB(printk("init_deskpro_m: Dead port 0xc44\n"));
2281 return 0;
2282 }
2283
2284 outb(0x10, 0xc44);
2285 outb(0x40, 0xc45);
2286 outb(0x00, 0xc46);
2287 outb(0xe8, 0xc47);
2288 outb(0x14, 0xc44);
2289 outb(0x40, 0xc45);
2290 outb(0x00, 0xc46);
2291 outb(0xe8, 0xc47);
2292 outb(0x10, 0xc44);
2293
2294 return 1;
2295}
2296
2297/*
2298 * Experimental initialization sequence for the integrated sound system
2299 * of Compaq Deskpro XL.
2300 */
2301
2302static int init_deskpro(struct address_info *hw_config)
2303{
2304 unsigned char tmp;
2305
2306 if ((tmp = inb(0xc44)) == 0xff)
2307 {
2308 DDB(printk("init_deskpro: Dead port 0xc44\n"));
2309 return 0;
2310 }
2311 outb((tmp | 0x04), 0xc44); /* Select bank 1 */
2312 if (inb(0xc44) != 0x04)
2313 {
2314 DDB(printk("init_deskpro: Invalid bank1 signature in port 0xc44\n"));
2315 return 0;
2316 }
2317 /*
2318 * OK. It looks like a Deskpro so let's proceed.
2319 */
2320
2321 /*
2322 * I/O port 0xc44 Audio configuration register.
2323 *
2324 * bits 0xc0: Audio revision bits
2325 * 0x00 = Compaq Business Audio
2326 * 0x40 = MS Sound System Compatible (reset default)
2327 * 0x80 = Reserved
2328 * 0xc0 = Reserved
2329 * bit 0x20: No Wait State Enable
2330 * 0x00 = Disabled (reset default, DMA mode)
2331 * 0x20 = Enabled (programmed I/O mode)
2332 * bit 0x10: MS Sound System Decode Enable
2333 * 0x00 = Decoding disabled (reset default)
2334 * 0x10 = Decoding enabled
2335 * bit 0x08: FM Synthesis Decode Enable
2336 * 0x00 = Decoding Disabled (reset default)
2337 * 0x08 = Decoding enabled
2338 * bit 0x04 Bank select
2339 * 0x00 = Bank 0
2340 * 0x04 = Bank 1
2341 * bits 0x03 MSS Base address
2342 * 0x00 = 0x530 (reset default)
2343 * 0x01 = 0x604
2344 * 0x02 = 0xf40
2345 * 0x03 = 0xe80
2346 */
2347
2348#ifdef DEBUGXL
2349 /* Debug printing */
2350 printk("Port 0xc44 (before): ");
2351 outb((tmp & ~0x04), 0xc44);
2352 printk("%02x ", inb(0xc44));
2353 outb((tmp | 0x04), 0xc44);
2354 printk("%02x\n", inb(0xc44));
2355#endif
2356
2357 /* Set bank 1 of the register */
2358 tmp = 0x58; /* MSS Mode, MSS&FM decode enabled */
2359
2360 switch (hw_config->io_base)
2361 {
2362 case 0x530:
2363 tmp |= 0x00;
2364 break;
2365 case 0x604:
2366 tmp |= 0x01;
2367 break;
2368 case 0xf40:
2369 tmp |= 0x02;
2370 break;
2371 case 0xe80:
2372 tmp |= 0x03;
2373 break;
2374 default:
2375 DDB(printk("init_deskpro: Invalid MSS port %x\n", hw_config->io_base));
2376 return 0;
2377 }
2378 outb((tmp & ~0x04), 0xc44); /* Write to bank=0 */
2379
2380#ifdef DEBUGXL
2381 /* Debug printing */
2382 printk("Port 0xc44 (after): ");
2383 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2384 printk("%02x ", inb(0xc44));
2385 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2386 printk("%02x\n", inb(0xc44));
2387#endif
2388
2389 /*
2390 * I/O port 0xc45 FM Address Decode/MSS ID Register.
2391 *
2392 * bank=0, bits 0xfe: FM synthesis Decode Compare bits 7:1 (default=0x88)
2393 * bank=0, bit 0x01: SBIC Power Control Bit
2394 * 0x00 = Powered up
2395 * 0x01 = Powered down
2396 * bank=1, bits 0xfc: MSS ID (default=0x40)
2397 */
2398
2399#ifdef DEBUGXL
2400 /* Debug printing */
2401 printk("Port 0xc45 (before): ");
2402 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2403 printk("%02x ", inb(0xc45));
2404 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2405 printk("%02x\n", inb(0xc45));
2406#endif
2407
2408 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2409 outb((0x88), 0xc45); /* FM base 7:0 = 0x88 */
2410 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2411 outb((0x10), 0xc45); /* MSS ID = 0x10 (MSS port returns 0x04) */
2412
2413#ifdef DEBUGXL
2414 /* Debug printing */
2415 printk("Port 0xc45 (after): ");
2416 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2417 printk("%02x ", inb(0xc45));
2418 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2419 printk("%02x\n", inb(0xc45));
2420#endif
2421
2422
2423 /*
2424 * I/O port 0xc46 FM Address Decode/Address ASIC Revision Register.
2425 *
2426 * bank=0, bits 0xff: FM synthesis Decode Compare bits 15:8 (default=0x03)
2427 * bank=1, bits 0xff: Audio addressing ASIC id
2428 */
2429
2430#ifdef DEBUGXL
2431 /* Debug printing */
2432 printk("Port 0xc46 (before): ");
2433 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2434 printk("%02x ", inb(0xc46));
2435 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2436 printk("%02x\n", inb(0xc46));
2437#endif
2438
2439 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2440 outb((0x03), 0xc46); /* FM base 15:8 = 0x03 */
2441 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2442 outb((0x11), 0xc46); /* ASIC ID = 0x11 */
2443
2444#ifdef DEBUGXL
2445 /* Debug printing */
2446 printk("Port 0xc46 (after): ");
2447 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2448 printk("%02x ", inb(0xc46));
2449 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2450 printk("%02x\n", inb(0xc46));
2451#endif
2452
2453 /*
2454 * I/O port 0xc47 FM Address Decode Register.
2455 *
2456 * bank=0, bits 0xff: Decode enable selection for various FM address bits
2457 * bank=1, bits 0xff: Reserved
2458 */
2459
2460#ifdef DEBUGXL
2461 /* Debug printing */
2462 printk("Port 0xc47 (before): ");
2463 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2464 printk("%02x ", inb(0xc47));
2465 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2466 printk("%02x\n", inb(0xc47));
2467#endif
2468
2469 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2470 outb((0x7c), 0xc47); /* FM decode enable bits = 0x7c */
2471 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2472 outb((0x00), 0xc47); /* Reserved bank1 = 0x00 */
2473
2474#ifdef DEBUGXL
2475 /* Debug printing */
2476 printk("Port 0xc47 (after): ");
2477 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2478 printk("%02x ", inb(0xc47));
2479 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2480 printk("%02x\n", inb(0xc47));
2481#endif
2482
2483 /*
2484 * I/O port 0xc6f = Audio Disable Function Register
2485 */
2486
2487#ifdef DEBUGXL
2488 printk("Port 0xc6f (before) = %02x\n", inb(0xc6f));
2489#endif
2490
2491 outb((0x80), 0xc6f);
2492
2493#ifdef DEBUGXL
2494 printk("Port 0xc6f (after) = %02x\n", inb(0xc6f));
2495#endif
2496
2497 return 1;
2498}
2499
2500int probe_ms_sound(struct address_info *hw_config, struct resource *ports)
2501{
2502 unsigned char tmp;
2503
2504 DDB(printk("Entered probe_ms_sound(%x, %d)\n", hw_config->io_base, hw_config->card_subtype));
2505
2506 if (hw_config->card_subtype == 1) /* Has no IRQ/DMA registers */
2507 {
2508 /* check_opl3(0x388, hw_config); */
2509 return ad1848_detect(ports, NULL, hw_config->osp);
2510 }
2511
2512 if (deskpro_xl && hw_config->card_subtype == 2) /* Compaq Deskpro XL */
2513 {
2514 if (!init_deskpro(hw_config))
2515 return 0;
2516 }
2517
2518 if (deskpro_m) /* Compaq Deskpro M */
2519 {
2520 if (!init_deskpro_m(hw_config))
2521 return 0;
2522 }
2523
2524 /*
2525 * Check if the IO port returns valid signature. The original MS Sound
2526 * system returns 0x04 while some cards (AudioTrix Pro for example)
2527 * return 0x00 or 0x0f.
2528 */
2529
2530 if ((tmp = inb(hw_config->io_base + 3)) == 0xff) /* Bus float */
2531 {
2532 int ret;
2533
2534 DDB(printk("I/O address is inactive (%x)\n", tmp));
2535 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
2536 return 0;
2537 return 1;
2538 }
2539 DDB(printk("MSS signature = %x\n", tmp & 0x3f));
2540 if ((tmp & 0x3f) != 0x04 &&
2541 (tmp & 0x3f) != 0x0f &&
2542 (tmp & 0x3f) != 0x00)
2543 {
2544 int ret;
2545
2546 MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x (0x%x)\n", hw_config->io_base, (int) inb(hw_config->io_base + 3)));
2547 DDB(printk("Trying to detect codec anyway but IRQ/DMA may not work\n"));
2548 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
2549 return 0;
2550
2551 hw_config->card_subtype = 1;
2552 return 1;
2553 }
2554 if ((hw_config->irq != 5) &&
2555 (hw_config->irq != 7) &&
2556 (hw_config->irq != 9) &&
2557 (hw_config->irq != 10) &&
2558 (hw_config->irq != 11) &&
2559 (hw_config->irq != 12))
2560 {
2561 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
2562 return 0;
2563 }
2564 if (hw_config->dma != 0 && hw_config->dma != 1 && hw_config->dma != 3)
2565 {
2566 printk(KERN_ERR "MSS: Bad DMA %d\n", hw_config->dma);
2567 return 0;
2568 }
2569 /*
2570 * Check that DMA0 is not in use with a 8 bit board.
2571 */
2572
2573 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80)
2574 {
2575 printk(KERN_ERR "MSS: Can't use DMA0 with a 8 bit card/slot\n");
2576 return 0;
2577 }
2578 if (hw_config->irq > 7 && hw_config->irq != 9 && inb(hw_config->io_base + 3) & 0x80)
2579 {
2580 printk(KERN_ERR "MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->irq);
2581 return 0;
2582 }
2583 return ad1848_detect(ports, NULL, hw_config->osp);
2584}
2585
2586void attach_ms_sound(struct address_info *hw_config, struct resource *ports, struct module *owner)
2587{
2588 static signed char interrupt_bits[12] =
2589 {
2590 -1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20
2591 };
2592 signed char bits;
2593 char dma2_bit = 0;
2594
2595 static char dma_bits[4] =
2596 {
2597 1, 2, 0, 3
2598 };
2599
2600 int config_port = hw_config->io_base + 0;
2601 int version_port = hw_config->io_base + 3;
2602 int dma = hw_config->dma;
2603 int dma2 = hw_config->dma2;
2604
2605 if (hw_config->card_subtype == 1) /* Has no IRQ/DMA registers */
2606 {
2607 hw_config->slots[0] = ad1848_init("MS Sound System", ports,
2608 hw_config->irq,
2609 hw_config->dma,
2610 hw_config->dma2, 0,
2611 hw_config->osp,
2612 owner);
2613 return;
2614 }
2615 /*
2616 * Set the IRQ and DMA addresses.
2617 */
2618
2619 bits = interrupt_bits[hw_config->irq];
2620 if (bits == -1)
2621 {
2622 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
2623 release_region(ports->start, 4);
2624 release_region(ports->start - 4, 4);
2625 return;
2626 }
2627 outb((bits | 0x40), config_port);
2628 if ((inb(version_port) & 0x40) == 0)
2629 printk(KERN_ERR "[MSS: IRQ Conflict?]\n");
2630
2631/*
2632 * Handle the capture DMA channel
2633 */
2634
2635 if (dma2 != -1 && dma2 != dma)
2636 {
2637 if (!((dma == 0 && dma2 == 1) ||
2638 (dma == 1 && dma2 == 0) ||
2639 (dma == 3 && dma2 == 0)))
2640 { /* Unsupported combination. Try to swap channels */
2641 int tmp = dma;
2642
2643 dma = dma2;
2644 dma2 = tmp;
2645 }
2646 if ((dma == 0 && dma2 == 1) ||
2647 (dma == 1 && dma2 == 0) ||
2648 (dma == 3 && dma2 == 0))
2649 {
2650 dma2_bit = 0x04; /* Enable capture DMA */
2651 }
2652 else
2653 {
2654 printk(KERN_WARNING "MSS: Invalid capture DMA\n");
2655 dma2 = dma;
2656 }
2657 }
2658 else
2659 {
2660 dma2 = dma;
2661 }
2662
2663 hw_config->dma = dma;
2664 hw_config->dma2 = dma2;
2665
2666 outb((bits | dma_bits[dma] | dma2_bit), config_port); /* Write IRQ+DMA setup */
2667
2668 hw_config->slots[0] = ad1848_init("MS Sound System", ports,
2669 hw_config->irq,
2670 dma, dma2, 0,
2671 hw_config->osp,
2672 THIS_MODULE);
2673}
2674
2675void unload_ms_sound(struct address_info *hw_config)
2676{
2677 ad1848_unload(hw_config->io_base + 4,
2678 hw_config->irq,
2679 hw_config->dma,
2680 hw_config->dma2, 0);
2681 sound_unload_audiodev(hw_config->slots[0]);
2682 release_region(hw_config->io_base, 4);
2683}
2684
2685#ifndef EXCLUDE_TIMERS
2686
2687/*
2688 * Timer stuff (for /dev/music).
2689 */
2690
2691static unsigned int current_interval;
2692
2693static unsigned int ad1848_tmr_start(int dev, unsigned int usecs)
2694{
2695 unsigned long flags;
2696 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2697 unsigned long xtal_nsecs; /* nanoseconds per xtal oscillator tick */
2698 unsigned long divider;
2699
2700 spin_lock_irqsave(&devc->lock,flags);
2701
2702 /*
2703 * Length of the timer interval (in nanoseconds) depends on the
2704 * selected crystal oscillator. Check this from bit 0x01 of I8.
2705 *
2706 * AD1845 has just one oscillator which has cycle time of 10.050 us
2707 * (when a 24.576 MHz xtal oscillator is used).
2708 *
2709 * Convert requested interval to nanoseconds before computing
2710 * the timer divider.
2711 */
2712
2713 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE)
2714 xtal_nsecs = 10050;
2715 else if (ad_read(devc, 8) & 0x01)
2716 xtal_nsecs = 9920;
2717 else
2718 xtal_nsecs = 9969;
2719
2720 divider = (usecs * 1000 + xtal_nsecs / 2) / xtal_nsecs;
2721
2722 if (divider < 100) /* Don't allow shorter intervals than about 1ms */
2723 divider = 100;
2724
2725 if (divider > 65535) /* Overflow check */
2726 divider = 65535;
2727
2728 ad_write(devc, 21, (divider >> 8) & 0xff); /* Set upper bits */
2729 ad_write(devc, 20, divider & 0xff); /* Set lower bits */
2730 ad_write(devc, 16, ad_read(devc, 16) | 0x40); /* Start the timer */
2731 devc->timer_running = 1;
2732 spin_unlock_irqrestore(&devc->lock,flags);
2733
2734 return current_interval = (divider * xtal_nsecs + 500) / 1000;
2735}
2736
2737static void ad1848_tmr_reprogram(int dev)
2738{
2739 /*
2740 * Audio driver has changed sampling rate so that a different xtal
2741 * oscillator was selected. We have to reprogram the timer rate.
2742 */
2743
2744 ad1848_tmr_start(dev, current_interval);
2745 sound_timer_syncinterval(current_interval);
2746}
2747
2748static void ad1848_tmr_disable(int dev)
2749{
2750 unsigned long flags;
2751 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2752
2753 spin_lock_irqsave(&devc->lock,flags);
2754 ad_write(devc, 16, ad_read(devc, 16) & ~0x40);
2755 devc->timer_running = 0;
2756 spin_unlock_irqrestore(&devc->lock,flags);
2757}
2758
2759static void ad1848_tmr_restart(int dev)
2760{
2761 unsigned long flags;
2762 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2763
2764 if (current_interval == 0)
2765 return;
2766
2767 spin_lock_irqsave(&devc->lock,flags);
2768 ad_write(devc, 16, ad_read(devc, 16) | 0x40);
2769 devc->timer_running = 1;
2770 spin_unlock_irqrestore(&devc->lock,flags);
2771}
2772
2773static struct sound_lowlev_timer ad1848_tmr =
2774{
2775 0,
2776 2,
2777 ad1848_tmr_start,
2778 ad1848_tmr_disable,
2779 ad1848_tmr_restart
2780};
2781
2782static int ad1848_tmr_install(int dev)
2783{
2784 if (timer_installed != -1)
2785 return 0; /* Don't install another timer */
2786
2787 timer_installed = ad1848_tmr.dev = dev;
2788 sound_timer_init(&ad1848_tmr, audio_devs[dev]->name);
2789
2790 return 1;
2791}
2792#endif /* EXCLUDE_TIMERS */
2793
2794EXPORT_SYMBOL(ad1848_detect);
2795EXPORT_SYMBOL(ad1848_init);
2796EXPORT_SYMBOL(ad1848_unload);
2797EXPORT_SYMBOL(ad1848_control);
2798EXPORT_SYMBOL(probe_ms_sound);
2799EXPORT_SYMBOL(attach_ms_sound);
2800EXPORT_SYMBOL(unload_ms_sound);
2801
2802static int __initdata io = -1;
2803static int __initdata irq = -1;
2804static int __initdata dma = -1;
2805static int __initdata dma2 = -1;
2806static int __initdata type = 0;
2807
2808module_param_hw(io, int, ioport, 0); /* I/O for a raw AD1848 card */
2809module_param_hw(irq, int, irq, 0); /* IRQ to use */
2810module_param_hw(dma, int, dma, 0); /* First DMA channel */
2811module_param_hw(dma2, int, dma, 0); /* Second DMA channel */
2812module_param(type, int, 0); /* Card type */
2813module_param(deskpro_xl, bool, 0); /* Special magic for Deskpro XL boxen */
2814module_param(deskpro_m, bool, 0); /* Special magic for Deskpro M box */
2815module_param(soundpro, bool, 0); /* More special magic for SoundPro chips */
2816
2817#ifdef CONFIG_PNP
2818module_param(isapnp, int, 0);
2819module_param(isapnpjump, int, 0);
2820module_param(reverse, bool, 0);
2821MODULE_PARM_DESC(isapnp, "When set to 0, Plug & Play support will be disabled");
2822MODULE_PARM_DESC(isapnpjump, "Jumps to a specific slot in the driver's PnP table. Use the source, Luke.");
2823MODULE_PARM_DESC(reverse, "When set to 1, will reverse ISAPnP search order");
2824
2825static struct pnp_dev *ad1848_dev = NULL;
2826
2827/* Please add new entries at the end of the table */
2828static struct {
2829 char *name;
2830 unsigned short card_vendor, card_device,
2831 vendor, function;
2832 short mss_io, irq, dma, dma2; /* index into isapnp table */
2833 int type;
2834} ad1848_isapnp_list[] __initdata = {
2835 {"CMI 8330 SoundPRO",
2836 ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001),
2837 ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001),
2838 0, 0, 0,-1, 0},
2839 {"CS4232 based card",
2840 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2841 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000),
2842 0, 0, 0, 1, 0},
2843 {"CS4232 based card",
2844 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2845 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100),
2846 0, 0, 0, 1, 0},
2847 {"OPL3-SA2 WSS mode",
2848 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2849 ISAPNP_VENDOR('Y','M','H'), ISAPNP_FUNCTION(0x0021),
2850 1, 0, 0, 1, 1},
2851 {"Advanced Gravis InterWave Audio",
2852 ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
2853 ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000),
2854 0, 0, 0, 1, 0},
2855 {NULL}
2856};
2857
2858#ifdef MODULE
2859static struct isapnp_device_id id_table[] = {
2860 { ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001),
2861 ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001), 0 },
2862 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2863 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000), 0 },
2864 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2865 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100), 0 },
2866 /* The main driver for this card is opl3sa2
2867 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2868 ISAPNP_VENDOR('Y','M','H'), ISAPNP_FUNCTION(0x0021), 0 },
2869 */
2870 { ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
2871 ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000), 0 },
2872 {0}
2873};
2874
2875MODULE_DEVICE_TABLE(isapnp, id_table);
2876#endif
2877
2878static struct pnp_dev *activate_dev(char *devname, char *resname, struct pnp_dev *dev)
2879{
2880 int err;
2881
2882 err = pnp_device_attach(dev);
2883 if (err < 0)
2884 return(NULL);
2885
2886 if((err = pnp_activate_dev(dev)) < 0) {
2887 printk(KERN_ERR "ad1848: %s %s config failed (out of resources?)[%d]\n", devname, resname, err);
2888
2889 pnp_device_detach(dev);
2890
2891 return(NULL);
2892 }
2893 audio_activated = 1;
2894 return(dev);
2895}
2896
2897static struct pnp_dev __init *ad1848_init_generic(struct pnp_card *bus,
2898 struct address_info *hw_config, int slot)
2899{
2900
2901 /* Configure Audio device */
2902 if((ad1848_dev = pnp_find_dev(bus, ad1848_isapnp_list[slot].vendor, ad1848_isapnp_list[slot].function, NULL)))
2903 {
2904 if((ad1848_dev = activate_dev(ad1848_isapnp_list[slot].name, "ad1848", ad1848_dev)))
2905 {
2906 hw_config->io_base = pnp_port_start(ad1848_dev, ad1848_isapnp_list[slot].mss_io);
2907 hw_config->irq = pnp_irq(ad1848_dev, ad1848_isapnp_list[slot].irq);
2908 hw_config->dma = pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma);
2909 if(ad1848_isapnp_list[slot].dma2 != -1)
2910 hw_config->dma2 = pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma2);
2911 else
2912 hw_config->dma2 = -1;
2913 hw_config->card_subtype = ad1848_isapnp_list[slot].type;
2914 } else
2915 return(NULL);
2916 } else
2917 return(NULL);
2918
2919 return(ad1848_dev);
2920}
2921
2922static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pnp_card *bus, int slot)
2923{
2924 char *busname = bus->name[0] ? bus->name : ad1848_isapnp_list[slot].name;
2925
2926 /* Initialize this baby. */
2927
2928 if(ad1848_init_generic(bus, hw_config, slot)) {
2929 /* We got it. */
2930
2931 printk(KERN_NOTICE "ad1848: PnP reports '%s' at i/o %#x, irq %d, dma %d, %d\n",
2932 busname,
2933 hw_config->io_base, hw_config->irq, hw_config->dma,
2934 hw_config->dma2);
2935 return 1;
2936 }
2937 return 0;
2938}
2939
2940static int __init ad1848_isapnp_probe(struct address_info *hw_config)
2941{
2942 static int first = 1;
2943 int i;
2944
2945 /* Count entries in sb_isapnp_list */
2946 for (i = 0; ad1848_isapnp_list[i].card_vendor != 0; i++);
2947 i--;
2948
2949 /* Check and adjust isapnpjump */
2950 if( isapnpjump < 0 || isapnpjump > i) {
2951 isapnpjump = reverse ? i : 0;
2952 printk(KERN_ERR "ad1848: Valid range for isapnpjump is 0-%d. Adjusted to %d.\n", i, isapnpjump);
2953 }
2954
2955 if(!first || !reverse)
2956 i = isapnpjump;
2957 first = 0;
2958 while(ad1848_isapnp_list[i].card_vendor != 0) {
2959 static struct pnp_card *bus = NULL;
2960
2961 while ((bus = pnp_find_card(
2962 ad1848_isapnp_list[i].card_vendor,
2963 ad1848_isapnp_list[i].card_device,
2964 bus))) {
2965
2966 if(ad1848_isapnp_init(hw_config, bus, i)) {
2967 isapnpjump = i; /* start next search from here */
2968 return 0;
2969 }
2970 }
2971 i += reverse ? -1 : 1;
2972 }
2973
2974 return -ENODEV;
2975}
2976#endif
2977
2978
2979static int __init init_ad1848(void)
2980{
2981 printk(KERN_INFO "ad1848/cs4248 codec driver Copyright (C) by Hannu Savolainen 1993-1996\n");
2982
2983#ifdef CONFIG_PNP
2984 if(isapnp && (ad1848_isapnp_probe(&cfg) < 0) ) {
2985 printk(KERN_NOTICE "ad1848: No ISAPnP cards found, trying standard ones...\n");
2986 isapnp = 0;
2987 }
2988#endif
2989
2990 if(io != -1) {
2991 struct resource *ports;
2992 if( isapnp == 0 )
2993 {
2994 if(irq == -1 || dma == -1) {
2995 printk(KERN_WARNING "ad1848: must give I/O , IRQ and DMA.\n");
2996 return -EINVAL;
2997 }
2998
2999 cfg.irq = irq;
3000 cfg.io_base = io;
3001 cfg.dma = dma;
3002 cfg.dma2 = dma2;
3003 cfg.card_subtype = type;
3004 }
3005
3006 ports = request_region(io + 4, 4, "ad1848");
3007
3008 if (!ports)
3009 return -EBUSY;
3010
3011 if (!request_region(io, 4, "WSS config")) {
3012 release_region(io + 4, 4);
3013 return -EBUSY;
3014 }
3015
3016 if (!probe_ms_sound(&cfg, ports)) {
3017 release_region(io + 4, 4);
3018 release_region(io, 4);
3019 return -ENODEV;
3020 }
3021 attach_ms_sound(&cfg, ports, THIS_MODULE);
3022 loaded = 1;
3023 }
3024 return 0;
3025}
3026
3027static void __exit cleanup_ad1848(void)
3028{
3029 if(loaded)
3030 unload_ms_sound(&cfg);
3031
3032#ifdef CONFIG_PNP
3033 if(ad1848_dev){
3034 if(audio_activated)
3035 pnp_device_detach(ad1848_dev);
3036 }
3037#endif
3038}
3039
3040module_init(init_ad1848);
3041module_exit(cleanup_ad1848);
3042
3043#ifndef MODULE
3044static int __init setup_ad1848(char *str)
3045{
3046 /* io, irq, dma, dma2, type */
3047 int ints[6];
3048
3049 str = get_options(str, ARRAY_SIZE(ints), ints);
3050
3051 io = ints[1];
3052 irq = ints[2];
3053 dma = ints[3];
3054 dma2 = ints[4];
3055 type = ints[5];
3056
3057 return 1;
3058}
3059
3060__setup("ad1848=", setup_ad1848);
3061#endif
3062MODULE_LICENSE("GPL");
diff --git a/sound/oss/ad1848.h b/sound/oss/ad1848.h
deleted file mode 100644
index b95ebe28d426..000000000000
--- a/sound/oss/ad1848.h
+++ /dev/null
@@ -1,24 +0,0 @@
1
2#include <linux/interrupt.h>
3
4#define AD_F_CS4231 0x0001 /* Returned if a CS4232 (or compatible) detected */
5#define AD_F_CS4248 0x0001 /* Returned if a CS4248 (or compatible) detected */
6
7#define AD1848_SET_XTAL 1
8#define AD1848_MIXER_REROUTE 2
9
10#define AD1848_REROUTE(oldctl, newctl) \
11 ad1848_control(AD1848_MIXER_REROUTE, ((oldctl)<<8)|(newctl))
12
13
14int ad1848_init(char *name, struct resource *ports, int irq, int dma_playback,
15 int dma_capture, int share_dma, int *osp, struct module *owner);
16void ad1848_unload (int io_base, int irq, int dma_playback, int dma_capture, int share_dma);
17
18int ad1848_detect (struct resource *ports, int *flags, int *osp);
19int ad1848_control(int cmd, int arg);
20
21void attach_ms_sound(struct address_info * hw_config, struct resource *ports, struct module * owner);
22
23int probe_ms_sound(struct address_info *hw_config, struct resource *ports);
24void unload_ms_sound(struct address_info *hw_info);
diff --git a/sound/oss/ad1848_mixer.h b/sound/oss/ad1848_mixer.h
deleted file mode 100644
index 2cf719b5fbbc..000000000000
--- a/sound/oss/ad1848_mixer.h
+++ /dev/null
@@ -1,253 +0,0 @@
1/*
2 * sound/oss/ad1848_mixer.h
3 *
4 * Definitions for the mixer of AD1848 and compatible codecs.
5 */
6
7/*
8 * Copyright (C) by Hannu Savolainen 1993-1997
9 *
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
12 * for more info.
13 */
14
15
16/*
17 * The AD1848 codec has generic input lines called Line, Aux1 and Aux2.
18 * Sound card manufacturers have connected actual inputs (CD, synth, line,
19 * etc) to these inputs in different order. Therefore it's difficult
20 * to assign mixer channels to these inputs correctly. The following
21 * contains two alternative mappings. The first one is for GUS MAX and
22 * the second is just a generic one (line1, line2 and line3).
23 * (Actually this is not a mapping but rather some kind of interleaving
24 * solution).
25 */
26#define MODE1_REC_DEVICES (SOUND_MASK_LINE3 | SOUND_MASK_MIC | \
27 SOUND_MASK_LINE1 | SOUND_MASK_IMIX)
28
29#define SPRO_REC_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | \
30 SOUND_MASK_CD | SOUND_MASK_LINE1)
31
32#define MODE1_MIXER_DEVICES (SOUND_MASK_LINE1 | SOUND_MASK_MIC | \
33 SOUND_MASK_LINE2 | \
34 SOUND_MASK_IGAIN | \
35 SOUND_MASK_PCM | SOUND_MASK_IMIX)
36
37#define MODE2_MIXER_DEVICES (SOUND_MASK_LINE1 | SOUND_MASK_LINE2 | \
38 SOUND_MASK_MIC | \
39 SOUND_MASK_LINE3 | SOUND_MASK_SPEAKER | \
40 SOUND_MASK_IGAIN | \
41 SOUND_MASK_PCM | SOUND_MASK_IMIX)
42
43#define MODE3_MIXER_DEVICES (MODE2_MIXER_DEVICES | SOUND_MASK_VOLUME)
44
45/* OPTi 82C930 has no IMIX level control, but it can still be selected as an
46 * input
47 */
48#define C930_MIXER_DEVICES (SOUND_MASK_LINE1 | SOUND_MASK_LINE2 | \
49 SOUND_MASK_MIC | SOUND_MASK_VOLUME | \
50 SOUND_MASK_LINE3 | \
51 SOUND_MASK_IGAIN | SOUND_MASK_PCM)
52
53#define SPRO_MIXER_DEVICES (SOUND_MASK_VOLUME | SOUND_MASK_PCM | \
54 SOUND_MASK_LINE | SOUND_MASK_SYNTH | \
55 SOUND_MASK_CD | SOUND_MASK_MIC | \
56 SOUND_MASK_SPEAKER | SOUND_MASK_LINE1 | \
57 SOUND_MASK_OGAIN)
58
59struct mixer_def {
60 unsigned int regno:6; /* register number for volume */
61 unsigned int polarity:1; /* volume polarity: 0=normal, 1=reversed */
62 unsigned int bitpos:3; /* position of bits in register for volume */
63 unsigned int nbits:3; /* number of bits in register for volume */
64 unsigned int mutereg:6; /* register number for mute bit */
65 unsigned int mutepol:1; /* mute polarity: 0=normal, 1=reversed */
66 unsigned int mutepos:4; /* position of mute bit in register */
67 unsigned int recreg:6; /* register number for recording bit */
68 unsigned int recpol:1; /* recording polarity: 0=normal, 1=reversed */
69 unsigned int recpos:4; /* position of recording bit in register */
70};
71
72static char mix_cvt[101] = {
73 0, 0, 3, 7,10,13,16,19,21,23,26,28,30,32,34,35,37,39,40,42,
74 43,45,46,47,49,50,51,52,53,55,56,57,58,59,60,61,62,63,64,65,
75 65,66,67,68,69,70,70,71,72,73,73,74,75,75,76,77,77,78,79,79,
76 80,81,81,82,82,83,84,84,85,85,86,86,87,87,88,88,89,89,90,90,
77 91,91,92,92,93,93,94,94,95,95,96,96,96,97,97,98,98,98,99,99,
78 100
79};
80
81typedef struct mixer_def mixer_ent;
82typedef mixer_ent mixer_ents[2];
83
84/*
85 * Most of the mixer entries work in backwards. Setting the polarity field
86 * makes them to work correctly.
87 *
88 * The channel numbering used by individual sound cards is not fixed. Some
89 * cards have assigned different meanings for the AUX1, AUX2 and LINE inputs.
90 * The current version doesn't try to compensate this.
91 */
92
93#define MIX_ENT(name, reg_l, pola_l, pos_l, len_l, reg_r, pola_r, pos_r, len_r, mute_bit) \
94 [name] = {{reg_l, pola_l, pos_l, len_l, reg_l, 0, mute_bit, 0, 0, 8}, \
95 {reg_r, pola_r, pos_r, len_r, reg_r, 0, mute_bit, 0, 0, 8}}
96
97#define MIX_ENT2(name, reg_l, pola_l, pos_l, len_l, mute_reg_l, mute_pola_l, mute_pos_l, \
98 rec_reg_l, rec_pola_l, rec_pos_l, \
99 reg_r, pola_r, pos_r, len_r, mute_reg_r, mute_pola_r, mute_pos_r, \
100 rec_reg_r, rec_pola_r, rec_pos_r) \
101 [name] = {{reg_l, pola_l, pos_l, len_l, mute_reg_l, mute_pola_l, mute_pos_l, \
102 rec_reg_l, rec_pola_l, rec_pos_l}, \
103 {reg_r, pola_r, pos_r, len_r, mute_reg_r, mute_pola_r, mute_pos_r, \
104 rec_reg_r, rec_pola_r, rec_pos_r}}
105
106static mixer_ents ad1848_mix_devices[32] = {
107 MIX_ENT(SOUND_MIXER_VOLUME, 27, 1, 0, 4, 29, 1, 0, 4, 8),
108 MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
109 MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
110 MIX_ENT(SOUND_MIXER_SYNTH, 4, 1, 0, 5, 5, 1, 0, 5, 7),
111 MIX_ENT(SOUND_MIXER_PCM, 6, 1, 0, 6, 7, 1, 0, 6, 7),
112 MIX_ENT(SOUND_MIXER_SPEAKER, 26, 1, 0, 4, 0, 0, 0, 0, 8),
113 MIX_ENT(SOUND_MIXER_LINE, 18, 1, 0, 5, 19, 1, 0, 5, 7),
114 MIX_ENT(SOUND_MIXER_MIC, 0, 0, 5, 1, 1, 0, 5, 1, 8),
115 MIX_ENT(SOUND_MIXER_CD, 2, 1, 0, 5, 3, 1, 0, 5, 7),
116 MIX_ENT(SOUND_MIXER_IMIX, 13, 1, 2, 6, 0, 0, 0, 0, 8),
117 MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
118 MIX_ENT(SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
119 MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 4, 1, 0, 0, 4, 8),
120 MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
121 MIX_ENT(SOUND_MIXER_LINE1, 2, 1, 0, 5, 3, 1, 0, 5, 7),
122 MIX_ENT(SOUND_MIXER_LINE2, 4, 1, 0, 5, 5, 1, 0, 5, 7),
123 MIX_ENT(SOUND_MIXER_LINE3, 18, 1, 0, 5, 19, 1, 0, 5, 7)
124};
125
126static mixer_ents iwave_mix_devices[32] = {
127 MIX_ENT(SOUND_MIXER_VOLUME, 25, 1, 0, 5, 27, 1, 0, 5, 8),
128 MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
129 MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
130 MIX_ENT(SOUND_MIXER_SYNTH, 4, 1, 0, 5, 5, 1, 0, 5, 7),
131 MIX_ENT(SOUND_MIXER_PCM, 6, 1, 0, 6, 7, 1, 0, 6, 7),
132 MIX_ENT(SOUND_MIXER_SPEAKER, 26, 1, 0, 4, 0, 0, 0, 0, 8),
133 MIX_ENT(SOUND_MIXER_LINE, 18, 1, 0, 5, 19, 1, 0, 5, 7),
134 MIX_ENT(SOUND_MIXER_MIC, 0, 0, 5, 1, 1, 0, 5, 1, 8),
135 MIX_ENT(SOUND_MIXER_CD, 2, 1, 0, 5, 3, 1, 0, 5, 7),
136 MIX_ENT(SOUND_MIXER_IMIX, 16, 1, 0, 5, 17, 1, 0, 5, 8),
137 MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
138 MIX_ENT(SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
139 MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 4, 1, 0, 0, 4, 8),
140 MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
141 MIX_ENT(SOUND_MIXER_LINE1, 2, 1, 0, 5, 3, 1, 0, 5, 7),
142 MIX_ENT(SOUND_MIXER_LINE2, 4, 1, 0, 5, 5, 1, 0, 5, 7),
143 MIX_ENT(SOUND_MIXER_LINE3, 18, 1, 0, 5, 19, 1, 0, 5, 7)
144};
145
146static mixer_ents cs42xb_mix_devices[32] = {
147 /* Digital master volume actually has seven bits, but we only use
148 six to avoid the discontinuity when the analog gain kicks in. */
149 MIX_ENT(SOUND_MIXER_VOLUME, 46, 1, 0, 6, 47, 1, 0, 6, 7),
150 MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
151 MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
152 MIX_ENT(SOUND_MIXER_SYNTH, 4, 1, 0, 5, 5, 1, 0, 5, 7),
153 MIX_ENT(SOUND_MIXER_PCM, 6, 1, 0, 6, 7, 1, 0, 6, 7),
154 MIX_ENT(SOUND_MIXER_SPEAKER, 26, 1, 0, 4, 0, 0, 0, 0, 8),
155 MIX_ENT(SOUND_MIXER_LINE, 18, 1, 0, 5, 19, 1, 0, 5, 7),
156 MIX_ENT(SOUND_MIXER_MIC, 34, 1, 0, 5, 35, 1, 0, 5, 7),
157 MIX_ENT(SOUND_MIXER_CD, 2, 1, 0, 5, 3, 1, 0, 5, 7),
158 /* For the IMIX entry, it was not possible to use the MIX_ENT macro
159 because the mute bit is in different positions for the two
160 channels and requires reverse polarity. */
161 [SOUND_MIXER_IMIX] = {{13, 1, 2, 6, 13, 1, 0, 0, 0, 8},
162 {42, 1, 0, 6, 42, 1, 7, 0, 0, 8}},
163 MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
164 MIX_ENT(SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
165 MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 4, 1, 0, 0, 4, 8),
166 MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
167 MIX_ENT(SOUND_MIXER_LINE1, 2, 1, 0, 5, 3, 1, 0, 5, 7),
168 MIX_ENT(SOUND_MIXER_LINE2, 4, 1, 0, 5, 5, 1, 0, 5, 7),
169 MIX_ENT(SOUND_MIXER_LINE3, 38, 1, 0, 6, 39, 1, 0, 6, 7)
170};
171
172/* OPTi 82C930 has somewhat different port addresses.
173 * Note: VOLUME == SPEAKER, SYNTH == LINE2, LINE == LINE3, CD == LINE1
174 * VOLUME, SYNTH, LINE, CD are not enabled above.
175 * MIC is level of mic monitoring direct to output. Same for CD, LINE, etc.
176 */
177static mixer_ents c930_mix_devices[32] = {
178 MIX_ENT(SOUND_MIXER_VOLUME, 22, 1, 1, 5, 23, 1, 1, 5, 7),
179 MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
180 MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
181 MIX_ENT(SOUND_MIXER_SYNTH, 4, 1, 1, 4, 5, 1, 1, 4, 7),
182 MIX_ENT(SOUND_MIXER_PCM, 6, 1, 0, 5, 7, 1, 0, 5, 7),
183 MIX_ENT(SOUND_MIXER_SPEAKER, 22, 1, 1, 5, 23, 1, 1, 5, 7),
184 MIX_ENT(SOUND_MIXER_LINE, 18, 1, 1, 4, 19, 1, 1, 4, 7),
185 MIX_ENT(SOUND_MIXER_MIC, 20, 1, 1, 4, 21, 1, 1, 4, 7),
186 MIX_ENT(SOUND_MIXER_CD, 2, 1, 1, 4, 3, 1, 1, 4, 7),
187 MIX_ENT(SOUND_MIXER_IMIX, 0, 0, 0, 0, 0, 0, 0, 0, 8),
188 MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
189 MIX_ENT(SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
190 MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 4, 1, 0, 0, 4, 8),
191 MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
192 MIX_ENT(SOUND_MIXER_LINE1, 2, 1, 1, 4, 3, 1, 1, 4, 7),
193 MIX_ENT(SOUND_MIXER_LINE2, 4, 1, 1, 4, 5, 1, 1, 4, 7),
194 MIX_ENT(SOUND_MIXER_LINE3, 18, 1, 1, 4, 19, 1, 1, 4, 7)
195};
196
197static mixer_ents spro_mix_devices[32] = {
198 MIX_ENT (SOUND_MIXER_VOLUME, 19, 0, 4, 4, 19, 0, 0, 4, 8),
199 MIX_ENT (SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
200 MIX_ENT (SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
201 MIX_ENT2(SOUND_MIXER_SYNTH, 4, 1, 1, 4, 23, 0, 3, 0, 0, 8,
202 5, 1, 1, 4, 23, 0, 3, 0, 0, 8),
203 MIX_ENT (SOUND_MIXER_PCM, 6, 1, 1, 4, 7, 1, 1, 4, 8),
204 MIX_ENT (SOUND_MIXER_SPEAKER, 18, 0, 3, 2, 0, 0, 0, 0, 8),
205 MIX_ENT2(SOUND_MIXER_LINE, 20, 0, 4, 4, 17, 1, 4, 16, 0, 2,
206 20, 0, 0, 4, 17, 1, 3, 16, 0, 1),
207 MIX_ENT2(SOUND_MIXER_MIC, 18, 0, 0, 3, 17, 1, 0, 16, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
209 MIX_ENT2(SOUND_MIXER_CD, 21, 0, 4, 4, 17, 1, 2, 16, 0, 4,
210 21, 0, 0, 4, 17, 1, 1, 16, 0, 3),
211 MIX_ENT (SOUND_MIXER_IMIX, 0, 0, 0, 0, 0, 0, 0, 0, 8),
212 MIX_ENT (SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
213 MIX_ENT (SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
214 MIX_ENT (SOUND_MIXER_IGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
215 MIX_ENT (SOUND_MIXER_OGAIN, 17, 1, 6, 1, 0, 0, 0, 0, 8),
216 /* This is external wavetable */
217 MIX_ENT2(SOUND_MIXER_LINE1, 22, 0, 4, 4, 23, 1, 1, 23, 0, 4,
218 22, 0, 0, 4, 23, 1, 0, 23, 0, 5),
219};
220
221static int default_mixer_levels[32] =
222{
223 0x3232, /* Master Volume */
224 0x3232, /* Bass */
225 0x3232, /* Treble */
226 0x4b4b, /* FM */
227 0x3232, /* PCM */
228 0x1515, /* PC Speaker */
229 0x2020, /* Ext Line */
230 0x1010, /* Mic */
231 0x4b4b, /* CD */
232 0x0000, /* Recording monitor */
233 0x4b4b, /* Second PCM */
234 0x4b4b, /* Recording level */
235 0x4b4b, /* Input gain */
236 0x4b4b, /* Output gain */
237 0x2020, /* Line1 */
238 0x2020, /* Line2 */
239 0x1515 /* Line3 (usually line in)*/
240};
241
242#define LEFT_CHN 0
243#define RIGHT_CHN 1
244
245/*
246 * Channel enable bits for ioctl(SOUND_MIXER_PRIVATE1)
247 */
248
249#ifndef AUDIO_SPEAKER
250#define AUDIO_SPEAKER 0x01 /* Enable mono output */
251#define AUDIO_HEADPHONE 0x02 /* Sparc only */
252#define AUDIO_LINE_OUT 0x04 /* Sparc only */
253#endif
diff --git a/sound/oss/aedsp16.c b/sound/oss/aedsp16.c
deleted file mode 100644
index f058ed6bdb69..000000000000
--- a/sound/oss/aedsp16.c
+++ /dev/null
@@ -1,1373 +0,0 @@
1/*
2 sound/oss/aedsp16.c
3
4 Audio Excel DSP 16 software configuration routines
5 Copyright (C) 1995,1996,1997,1998 Riccardo Facchetti (fizban@tin.it)
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 */
22/*
23 * Include the main OSS Lite header file. It include all the os, OSS Lite, etc
24 * headers needed by this source.
25 */
26#include <linux/delay.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include "sound_config.h"
30
31/*
32
33 READ THIS
34
35 This module started to configure the Audio Excel DSP 16 Sound Card.
36 Now works with the SC-6000 (old aedsp16) and new SC-6600 based cards.
37
38 NOTE: I have NO idea about Audio Excel DSP 16 III. If someone owns this
39 audio card and want to see the kernel support for it, please contact me.
40
41 Audio Excel DSP 16 is an SB pro II, Microsoft Sound System and MPU-401
42 compatible card.
43 It is software-only configurable (no jumpers to hard-set irq/dma/mpu-irq),
44 so before this module, the only way to configure the DSP under linux was
45 boot the MS-DOS loading the sound.sys device driver (this driver soft-
46 configure the sound board hardware by massaging someone of its registers),
47 and then ctrl-alt-del to boot linux with the DSP configured by the DOS
48 driver.
49
50 This module works configuring your Audio Excel DSP 16's irq, dma and
51 mpu-401-irq. The OSS Lite routines rely on the fact that if the
52 hardware is there, they can detect it. The problem with AEDSP16 is
53 that no hardware can be found by the probe routines if the sound card
54 is not configured properly. Sometimes the kernel probe routines can find
55 an SBPRO even when the card is not configured (this is the standard setup
56 of the card), but the SBPRO emulation don't work well if the card is not
57 properly initialized. For this reason
58
59 aedsp16_init_board()
60
61 routine is called before the OSS Lite probe routines try to detect the
62 hardware.
63
64 NOTE (READ THE NOTE TOO, IT CONTAIN USEFUL INFORMATIONS)
65
66 NOTE: Now it works with SC-6000 and SC-6600 based audio cards. The new cards
67 have no jumper switch at all. No more WSS or MPU-401 I/O port switches. They
68 have to be configured by software.
69
70 NOTE: The driver is merged with the new OSS Lite sound driver. It works
71 as a lowlevel driver.
72
73 The Audio Excel DSP 16 Sound Card emulates both SBPRO and MSS;
74 the OSS Lite sound driver can be configured for SBPRO and MSS cards
75 at the same time, but the aedsp16 can't be two cards!!
76 When we configure it, we have to choose the SBPRO or the MSS emulation
77 for AEDSP16. We also can install a *REAL* card of the other type (see [1]).
78
79 NOTE: If someone can test the combination AEDSP16+MSS or AEDSP16+SBPRO
80 please let me know if it works.
81
82 The MPU-401 support can be compiled in together with one of the other
83 two operating modes.
84
85 NOTE: This is something like plug-and-play: we have only to plug
86 the AEDSP16 board in the socket, and then configure and compile
87 a kernel that uses the AEDSP16 software configuration capability.
88 No jumper setting is needed!
89
90 For example, if you want AEDSP16 to be an SBPro, on irq 10, dma 3
91 you have just to make config the OSS Lite package, configuring
92 the AEDSP16 sound card, then activating the SBPro emulation mode
93 and at last configuring IRQ and DMA.
94 Compile the kernel and run it.
95
96 NOTE: This means for SC-6000 cards that you can choose irq and dma,
97 but not the I/O addresses. To change I/O addresses you have to set
98 them with jumpers. For SC-6600 cards you have no jumpers so you have
99 to set up your full card configuration in the make config.
100
101 You can change the irq/dma/mirq settings WITHOUT THE NEED to open
102 your computer and massage the jumpers (there are no irq/dma/mirq
103 jumpers to be configured anyway, only I/O BASE values have to be
104 configured with jumpers)
105
106 For some ununderstandable reason, the card default of irq 7, dma 1,
107 don't work for me. Seems to be an IRQ or DMA conflict. Under heavy
108 HDD work, the kernel start to erupt out a lot of messages like:
109
110 'Sound: DMA timed out - IRQ/DRQ config error?'
111
112 For what I can say, I have NOT any conflict at irq 7 (under linux I'm
113 using the lp polling driver), and dma line 1 is unused as stated by
114 /proc/dma. I can suppose this is a bug of AEDSP16. I know my hardware so
115 I'm pretty sure I have not any conflict, but may be I'm wrong. Who knows!
116 Anyway a setting of irq 10, dma 3 works really fine.
117
118 NOTE: if someone can use AEDSP16 with irq 7, dma 1, please let me know
119 the emulation mode, all the installed hardware and the hardware
120 configuration (irq and dma settings of all the hardware).
121
122 This init module should work with SBPRO+MSS, when one of the two is
123 the AEDSP16 emulation and the other the real card. (see [1])
124 For example:
125
126 AEDSP16 (0x220) in SBPRO emu (0x220) + real MSS + other
127 AEDSP16 (0x220) in MSS emu + real SBPRO (0x240) + other
128
129 MPU401 should work. (see [2])
130
131 [1]
132 ---
133 Date: Mon, 29 Jul 1997 08:35:40 +0100
134 From: Mr S J Greenaway <sjg95@unixfe.rl.ac.uk>
135
136 [...]
137 Just to let you know got my Audio Excel (emulating a MSS) working
138 with my original SB16, thanks for the driver!
139 [...]
140 ---
141
142 [2] Not tested by me for lack of hardware.
143
144 TODO, WISHES AND TECH
145
146 - About I/O ports allocation -
147
148 Request the 2x0h region (port base) in any case if we are using this card.
149
150 NOTE: the "aedsp16 (base)" string with which we are requesting the aedsp16
151 port base region (see code) does not mean necessarily that we are emulating
152 sbpro. Even if this region is the sbpro I/O ports region, we use this
153 region to access the control registers of the card, and if emulating
154 sbpro, I/O sbpro registers too. If we are emulating MSS, the sbpro
155 registers are not used, in no way, to emulate an sbpro: they are
156 used only for configuration purposes.
157
158 Started Fri Mar 17 16:13:18 MET 1995
159
160 v0.1 (ALPHA, was a user-level program called AudioExcelDSP16.c)
161 - Initial code.
162 v0.2 (ALPHA)
163 - Cleanups.
164 - Integrated with Linux voxware v 2.90-2 kernel sound driver.
165 - SoundBlaster Pro mode configuration.
166 - Microsoft Sound System mode configuration.
167 - MPU-401 mode configuration.
168 v0.3 (ALPHA)
169 - Cleanups.
170 - Rearranged the code to let aedsp16_init_board be more general.
171 - Erased the REALLY_SLOW_IO. We don't need it. Erased the linux/io.h
172 inclusion too. We rely on os.h
173 - Used the to get a variable
174 len string (we are not sure about the len of Copyright string).
175 This works with any SB and compatible.
176 - Added the code to request_region at device init (should go in
177 the main body of voxware).
178 v0.4 (BETA)
179 - Better configure.c patch for aedsp16 configuration (better
180 logic of inclusion of AEDSP16 support)
181 - Modified the conditional compilation to better support more than
182 one sound card of the emulated type (read the NOTES above)
183 - Moved the sb init routine from the attach to the very first
184 probe in sb_card.c
185 - Rearrangements and cleanups
186 - Wiped out some unnecessary code and variables: this is kernel
187 code so it is better save some TEXT and DATA
188 - Fixed the request_region code. We must allocate the aedsp16 (sbpro)
189 I/O ports in any case because they are used to access the DSP
190 configuration registers and we can not allow anyone to get them.
191 v0.5
192 - cleanups on comments
193 - prep for diffs against v3.0-proto-950402
194 v0.6
195 - removed the request_region()s when compiling the MODULE sound.o
196 because we are not allowed (by the actual voxware structure) to
197 release_region()
198 v0.7 (pre ALPHA, not distributed)
199 - started porting this module to kernel 1.3.84. Dummy probe/attach
200 routines.
201 v0.8 (ALPHA)
202 - attached all the init routines.
203 v0.9 (BETA)
204 - Integrated with linux-pre2.0.7
205 - Integrated with configuration scripts.
206 - Cleaned up and beautyfied the code.
207 v0.9.9 (BETA)
208 - Thanks to Piercarlo Grandi: corrected the conditonal compilation code.
209 Now only the code configured is compiled in, with some memory saving.
210 v0.9.10
211 - Integration into the sound/lowlevel/ section of the sound driver.
212 - Re-organized the code.
213 v0.9.11 (not distributed)
214 - Rewritten the init interface-routines to initialize the AEDSP16 in
215 one shot.
216 - More cosmetics.
217 - SC-6600 support.
218 - More soft/hard configuration.
219 v0.9.12
220 - Refined the v0.9.11 code with conditional compilation to distinguish
221 between SC-6000 and SC-6600 code.
222 v1.0.0
223 - Prep for merging with OSS Lite and Linux kernel 2.1.13
224 - Corrected a bug in request/check/release region calls (thanks to the
225 new kernel exception handling).
226 v1.1
227 - Revamped for integration with new modularized sound drivers: to enhance
228 the flexibility of modular version, I have removed all the conditional
229 compilation for SBPRO, MPU and MSS code. Now it is all managed with
230 the ae_config structure.
231 v1.2
232 - Module informations added.
233 - Removed aedsp16_delay_10msec(), now using mdelay(10)
234 - All data and funcs moved to .*.init section.
235 v1.3
236 Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/09/27
237 - got rid of check_region
238
239 Known Problems:
240 - Audio Excel DSP 16 III don't work with this driver.
241
242 Credits:
243 Many thanks to Gerald Britton <gbritton@CapAccess.org>. He helped me a
244 lot in testing the 0.9.11 and 0.9.12 versions of this driver.
245
246 */
247
248
249#define VERSION "1.3" /* Version of Audio Excel DSP 16 driver */
250
251#undef AEDSP16_DEBUG /* Define this to 1 to enable debug code */
252#undef AEDSP16_DEBUG_MORE /* Define this to 1 to enable more debug */
253#undef AEDSP16_INFO /* Define this to 1 to enable info code */
254
255#if defined(AEDSP16_DEBUG)
256# define DBG(x) printk x
257# if defined(AEDSP16_DEBUG_MORE)
258# define DBG1(x) printk x
259# else
260# define DBG1(x)
261# endif
262#else
263# define DBG(x)
264# define DBG1(x)
265#endif
266
267/*
268 * Misc definitions
269 */
270#define TRUE 1
271#define FALSE 0
272
273/*
274 * Region Size for request/check/release region.
275 */
276#define IOBASE_REGION_SIZE 0x10
277
278/*
279 * Hardware related defaults
280 */
281#define DEF_AEDSP16_IOB 0x220 /* 0x220(default) 0x240 */
282#define DEF_AEDSP16_IRQ 7 /* 5 7(default) 9 10 11 */
283#define DEF_AEDSP16_MRQ 0 /* 5 7 9 10 0(default), 0 means disable */
284#define DEF_AEDSP16_DMA 1 /* 0 1(default) 3 */
285
286/*
287 * Commands of AEDSP16's DSP (SBPRO+special).
288 * Some of them are COMMAND_xx, in the future they may change.
289 */
290#define WRITE_MDIRQ_CFG 0x50 /* Set M&I&DRQ mask (the real config) */
291#define COMMAND_52 0x52 /* */
292#define READ_HARD_CFG 0x58 /* Read Hardware Config (I/O base etc) */
293#define COMMAND_5C 0x5c /* */
294#define COMMAND_60 0x60 /* */
295#define COMMAND_66 0x66 /* */
296#define COMMAND_6C 0x6c /* */
297#define COMMAND_6E 0x6e /* */
298#define COMMAND_88 0x88 /* */
299#define DSP_INIT_MSS 0x8c /* Enable Microsoft Sound System mode */
300#define COMMAND_C5 0xc5 /* */
301#define GET_DSP_VERSION 0xe1 /* Get DSP Version */
302#define GET_DSP_COPYRIGHT 0xe3 /* Get DSP Copyright */
303
304/*
305 * Offsets of AEDSP16 DSP I/O ports. The offset is added to base I/O port
306 * to have the actual I/O port.
307 * Register permissions are:
308 * (wo) == Write Only
309 * (ro) == Read Only
310 * (w-) == Write
311 * (r-) == Read
312 */
313#define DSP_RESET 0x06 /* offset of DSP RESET (wo) */
314#define DSP_READ 0x0a /* offset of DSP READ (ro) */
315#define DSP_WRITE 0x0c /* offset of DSP WRITE (w-) */
316#define DSP_COMMAND 0x0c /* offset of DSP COMMAND (w-) */
317#define DSP_STATUS 0x0c /* offset of DSP STATUS (r-) */
318#define DSP_DATAVAIL 0x0e /* offset of DSP DATA AVAILABLE (ro) */
319
320
321#define RETRY 10 /* Various retry values on I/O opera- */
322#define STATUSRETRY 1000 /* tions. Sometimes we have to */
323#define HARDRETRY 500000 /* wait for previous cmd to complete */
324
325/*
326 * Size of character arrays that store name and version of sound card
327 */
328#define CARDNAMELEN 15 /* Size of the card's name in chars */
329#define CARDVERLEN 10 /* Size of the card's version in chars */
330#define CARDVERDIGITS 2 /* Number of digits in the version */
331
332#if defined(CONFIG_SC6600)
333/*
334 * Bitmapped flags of hard configuration
335 */
336/*
337 * Decode macros (xl == low byte, xh = high byte)
338 */
339#define IOBASE(xl) ((xl & 0x01)?0x240:0x220)
340#define JOY(xl) (xl & 0x02)
341#define MPUADDR(xl) ( \
342 (xl & 0x0C)?0x330: \
343 (xl & 0x08)?0x320: \
344 (xl & 0x04)?0x310: \
345 0x300)
346#define WSSADDR(xl) ((xl & 0x10)?0xE80:0x530)
347#define CDROM(xh) (xh & 0x20)
348#define CDROMADDR(xh) (((xh & 0x1F) << 4) + 0x200)
349/*
350 * Encode macros
351 */
352#define BLDIOBASE(xl, val) { \
353 xl &= ~0x01; \
354 if (val == 0x240) \
355 xl |= 0x01; \
356 }
357#define BLDJOY(xl, val) { \
358 xl &= ~0x02; \
359 if (val == 1) \
360 xl |= 0x02; \
361 }
362#define BLDMPUADDR(xl, val) { \
363 xl &= ~0x0C; \
364 switch (val) { \
365 case 0x330: \
366 xl |= 0x0C; \
367 break; \
368 case 0x320: \
369 xl |= 0x08; \
370 break; \
371 case 0x310: \
372 xl |= 0x04; \
373 break; \
374 case 0x300: \
375 xl |= 0x00; \
376 break; \
377 default: \
378 xl |= 0x00; \
379 break; \
380 } \
381 }
382#define BLDWSSADDR(xl, val) { \
383 xl &= ~0x10; \
384 if (val == 0xE80) \
385 xl |= 0x10; \
386 }
387#define BLDCDROM(xh, val) { \
388 xh &= ~0x20; \
389 if (val == 1) \
390 xh |= 0x20; \
391 }
392#define BLDCDROMADDR(xh, val) { \
393 int tmp = val; \
394 tmp -= 0x200; \
395 tmp >>= 4; \
396 tmp &= 0x1F; \
397 xh |= tmp; \
398 xh &= 0x7F; \
399 xh |= 0x40; \
400 }
401#endif /* CONFIG_SC6600 */
402
403/*
404 * Bit mapped flags for calling aedsp16_init_board(), and saving the current
405 * emulation mode.
406 */
407#define INIT_NONE (0 )
408#define INIT_SBPRO (1<<0)
409#define INIT_MSS (1<<1)
410#define INIT_MPU401 (1<<2)
411
412static int soft_cfg __initdata = 0; /* bitmapped config */
413static int soft_cfg_mss __initdata = 0; /* bitmapped mss config */
414static int ver[CARDVERDIGITS] __initdata = {0, 0}; /* DSP Ver:
415 hi->ver[0] lo->ver[1] */
416
417#if defined(CONFIG_SC6600)
418static int hard_cfg[2] /* lo<-hard_cfg[0] hi<-hard_cfg[1] */
419 __initdata = { 0, 0};
420#endif /* CONFIG_SC6600 */
421
422#if defined(CONFIG_SC6600)
423/* Decoded hard configuration */
424struct d_hcfg {
425 int iobase;
426 int joystick;
427 int mpubase;
428 int wssbase;
429 int cdrom;
430 int cdrombase;
431};
432
433static struct d_hcfg decoded_hcfg __initdata = {0, };
434
435#endif /* CONFIG_SC6600 */
436
437/* orVals contain the values to be or'ed */
438struct orVals {
439 int val; /* irq|mirq|dma */
440 int or; /* soft_cfg |= TheStruct.or */
441};
442
443/* aedsp16_info contain the audio card configuration */
444struct aedsp16_info {
445 int base_io; /* base I/O address for accessing card */
446 int irq; /* irq value for DSP I/O */
447 int mpu_irq; /* irq for mpu401 interface I/O */
448 int dma; /* dma value for DSP I/O */
449 int mss_base; /* base I/O for Microsoft Sound System */
450 int mpu_base; /* base I/O for MPU-401 emulation */
451 int init; /* Initialization status of the card */
452};
453
454/*
455 * Magic values that the DSP will eat when configuring irq/mirq/dma
456 */
457/* DSP IRQ conversion array */
458static struct orVals orIRQ[] __initdata = {
459 {0x05, 0x28},
460 {0x07, 0x08},
461 {0x09, 0x10},
462 {0x0a, 0x18},
463 {0x0b, 0x20},
464 {0x00, 0x00}
465};
466
467/* MPU-401 IRQ conversion array */
468static struct orVals orMIRQ[] __initdata = {
469 {0x05, 0x04},
470 {0x07, 0x44},
471 {0x09, 0x84},
472 {0x0a, 0xc4},
473 {0x00, 0x00}
474};
475
476/* DMA Channels conversion array */
477static struct orVals orDMA[] __initdata = {
478 {0x00, 0x01},
479 {0x01, 0x02},
480 {0x03, 0x03},
481 {0x00, 0x00}
482};
483
484static struct aedsp16_info ae_config = {
485 .base_io = DEF_AEDSP16_IOB,
486 .irq = DEF_AEDSP16_IRQ,
487 .mpu_irq = DEF_AEDSP16_MRQ,
488 .dma = DEF_AEDSP16_DMA,
489 .mss_base = -1,
490 .mpu_base = -1,
491 .init = INIT_NONE
492};
493
494/*
495 * Buffers to store audio card informations
496 */
497static char DSPCopyright[CARDNAMELEN + 1] __initdata = {0, };
498static char DSPVersion[CARDVERLEN + 1] __initdata = {0, };
499
500static int __init aedsp16_wait_data(int port)
501{
502 int loop = STATUSRETRY;
503 unsigned char ret = 0;
504
505 DBG1(("aedsp16_wait_data (0x%x): ", port));
506
507 do {
508 ret = inb(port + DSP_DATAVAIL);
509 /*
510 * Wait for data available (bit 7 of ret == 1)
511 */
512 } while (!(ret & 0x80) && loop--);
513
514 if (ret & 0x80) {
515 DBG1(("success.\n"));
516 return TRUE;
517 }
518
519 DBG1(("failure.\n"));
520 return FALSE;
521}
522
523static int __init aedsp16_read(int port)
524{
525 int inbyte;
526
527 DBG((" Read DSP Byte (0x%x): ", port));
528
529 if (aedsp16_wait_data(port) == FALSE) {
530 DBG(("failure.\n"));
531 return -1;
532 }
533
534 inbyte = inb(port + DSP_READ);
535
536 DBG(("read [0x%x]/{%c}.\n", inbyte, inbyte));
537
538 return inbyte;
539}
540
541static int __init aedsp16_test_dsp(int port)
542{
543 return ((aedsp16_read(port) == 0xaa) ? TRUE : FALSE);
544}
545
546static int __init aedsp16_dsp_reset(int port)
547{
548 /*
549 * Reset DSP
550 */
551
552 DBG(("Reset DSP:\n"));
553
554 outb(1, (port + DSP_RESET));
555 udelay(10);
556 outb(0, (port + DSP_RESET));
557 udelay(10);
558 udelay(10);
559 if (aedsp16_test_dsp(port) == TRUE) {
560 DBG(("success.\n"));
561 return TRUE;
562 } else
563 DBG(("failure.\n"));
564 return FALSE;
565}
566
567static int __init aedsp16_write(int port, int cmd)
568{
569 unsigned char ret;
570 int loop = HARDRETRY;
571
572 DBG((" Write DSP Byte (0x%x) [0x%x]: ", port, cmd));
573
574 do {
575 ret = inb(port + DSP_STATUS);
576 /*
577 * DSP ready to receive data if bit 7 of ret == 0
578 */
579 if (!(ret & 0x80)) {
580 outb(cmd, port + DSP_COMMAND);
581 DBG(("success.\n"));
582 return 0;
583 }
584 } while (loop--);
585
586 DBG(("timeout.\n"));
587 printk("[AEDSP16] DSP Command (0x%x) timeout.\n", cmd);
588
589 return -1;
590}
591
592#if defined(CONFIG_SC6600)
593
594#if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
595void __init aedsp16_pinfo(void) {
596 DBG(("\n Base address: %x\n", decoded_hcfg.iobase));
597 DBG((" Joystick : %s present\n", decoded_hcfg.joystick?"":" not"));
598 DBG((" WSS addr : %x\n", decoded_hcfg.wssbase));
599 DBG((" MPU-401 addr: %x\n", decoded_hcfg.mpubase));
600 DBG((" CDROM : %s present\n", (decoded_hcfg.cdrom!=4)?"":" not"));
601 DBG((" CDROMADDR : %x\n\n", decoded_hcfg.cdrombase));
602}
603#endif
604
605static void __init aedsp16_hard_decode(void) {
606
607 DBG((" aedsp16_hard_decode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
608
609/*
610 * Decode Cfg Bytes.
611 */
612 decoded_hcfg.iobase = IOBASE(hard_cfg[0]);
613 decoded_hcfg.joystick = JOY(hard_cfg[0]);
614 decoded_hcfg.wssbase = WSSADDR(hard_cfg[0]);
615 decoded_hcfg.mpubase = MPUADDR(hard_cfg[0]);
616 decoded_hcfg.cdrom = CDROM(hard_cfg[1]);
617 decoded_hcfg.cdrombase = CDROMADDR(hard_cfg[1]);
618
619#if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
620 printk(" Original sound card configuration:\n");
621 aedsp16_pinfo();
622#endif
623
624/*
625 * Now set up the real kernel configuration.
626 */
627 decoded_hcfg.iobase = ae_config.base_io;
628 decoded_hcfg.wssbase = ae_config.mss_base;
629 decoded_hcfg.mpubase = ae_config.mpu_base;
630
631#if defined(CONFIG_SC6600_JOY)
632 decoded_hcfg.joystick = CONFIG_SC6600_JOY; /* Enable */
633#endif
634#if defined(CONFIG_SC6600_CDROM)
635 decoded_hcfg.cdrom = CONFIG_SC6600_CDROM; /* 4:N-3:I-2:G-1:P-0:S */
636#endif
637#if defined(CONFIG_SC6600_CDROMBASE)
638 decoded_hcfg.cdrombase = CONFIG_SC6600_CDROMBASE; /* 0 Disable */
639#endif
640
641#if defined(AEDSP16_DEBUG)
642 DBG((" New Values:\n"));
643 aedsp16_pinfo();
644#endif
645
646 DBG(("success.\n"));
647}
648
649static void __init aedsp16_hard_encode(void) {
650
651 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
652
653 hard_cfg[0] = 0;
654 hard_cfg[1] = 0;
655
656 hard_cfg[0] |= 0x20;
657
658 BLDIOBASE (hard_cfg[0], decoded_hcfg.iobase);
659 BLDWSSADDR(hard_cfg[0], decoded_hcfg.wssbase);
660 BLDMPUADDR(hard_cfg[0], decoded_hcfg.mpubase);
661 BLDJOY(hard_cfg[0], decoded_hcfg.joystick);
662 BLDCDROM(hard_cfg[1], decoded_hcfg.cdrom);
663 BLDCDROMADDR(hard_cfg[1], decoded_hcfg.cdrombase);
664
665#if defined(AEDSP16_DEBUG)
666 aedsp16_pinfo();
667#endif
668
669 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
670 DBG(("success.\n"));
671
672}
673
674static int __init aedsp16_hard_write(int port) {
675
676 DBG(("aedsp16_hard_write:\n"));
677
678 if (aedsp16_write(port, COMMAND_6C)) {
679 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6C);
680 DBG(("failure.\n"));
681 return FALSE;
682 }
683 if (aedsp16_write(port, COMMAND_5C)) {
684 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
685 DBG(("failure.\n"));
686 return FALSE;
687 }
688 if (aedsp16_write(port, hard_cfg[0])) {
689 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[0]);
690 DBG(("failure.\n"));
691 return FALSE;
692 }
693 if (aedsp16_write(port, hard_cfg[1])) {
694 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[1]);
695 DBG(("failure.\n"));
696 return FALSE;
697 }
698 if (aedsp16_write(port, COMMAND_C5)) {
699 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_C5);
700 DBG(("failure.\n"));
701 return FALSE;
702 }
703
704 DBG(("success.\n"));
705
706 return TRUE;
707}
708
709static int __init aedsp16_hard_read(int port) {
710
711 DBG(("aedsp16_hard_read:\n"));
712
713 if (aedsp16_write(port, READ_HARD_CFG)) {
714 printk("[AEDSP16] CMD 0x%x: failed!\n", READ_HARD_CFG);
715 DBG(("failure.\n"));
716 return FALSE;
717 }
718
719 if ((hard_cfg[0] = aedsp16_read(port)) == -1) {
720 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
721 READ_HARD_CFG);
722 DBG(("failure.\n"));
723 return FALSE;
724 }
725 if ((hard_cfg[1] = aedsp16_read(port)) == -1) {
726 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
727 READ_HARD_CFG);
728 DBG(("failure.\n"));
729 return FALSE;
730 }
731 if (aedsp16_read(port) == -1) {
732 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
733 READ_HARD_CFG);
734 DBG(("failure.\n"));
735 return FALSE;
736 }
737
738 DBG(("success.\n"));
739
740 return TRUE;
741}
742
743static int __init aedsp16_ext_cfg_write(int port) {
744
745 int extcfg, val;
746
747 if (aedsp16_write(port, COMMAND_66)) {
748 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_66);
749 return FALSE;
750 }
751
752 extcfg = 7;
753 if (decoded_hcfg.cdrom != 2)
754 extcfg = 0x0F;
755 if ((decoded_hcfg.cdrom == 4) ||
756 (decoded_hcfg.cdrom == 3))
757 extcfg &= ~2;
758 if (decoded_hcfg.cdrombase == 0)
759 extcfg &= ~2;
760 if (decoded_hcfg.mpubase == 0)
761 extcfg &= ~1;
762
763 if (aedsp16_write(port, extcfg)) {
764 printk("[AEDSP16] Write extcfg: failed!\n");
765 return FALSE;
766 }
767 if (aedsp16_write(port, 0)) {
768 printk("[AEDSP16] Write extcfg: failed!\n");
769 return FALSE;
770 }
771 if (decoded_hcfg.cdrom == 3) {
772 if (aedsp16_write(port, COMMAND_52)) {
773 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
774 return FALSE;
775 }
776 if ((val = aedsp16_read(port)) == -1) {
777 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n"
778 , COMMAND_52);
779 return FALSE;
780 }
781 val &= 0x7F;
782 if (aedsp16_write(port, COMMAND_60)) {
783 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
784 return FALSE;
785 }
786 if (aedsp16_write(port, val)) {
787 printk("[AEDSP16] Write val: failed!\n");
788 return FALSE;
789 }
790 }
791
792 return TRUE;
793}
794
795#endif /* CONFIG_SC6600 */
796
797static int __init aedsp16_cfg_write(int port) {
798 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
799 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
800 return FALSE;
801 }
802 if (aedsp16_write(port, soft_cfg)) {
803 printk("[AEDSP16] Initialization of (M)IRQ and DMA: failed!\n");
804 return FALSE;
805 }
806 return TRUE;
807}
808
809static int __init aedsp16_init_mss(int port)
810{
811 DBG(("aedsp16_init_mss:\n"));
812
813 mdelay(10);
814
815 if (aedsp16_write(port, DSP_INIT_MSS)) {
816 printk("[AEDSP16] aedsp16_init_mss [0x%x]: failed!\n",
817 DSP_INIT_MSS);
818 DBG(("failure.\n"));
819 return FALSE;
820 }
821
822 mdelay(10);
823
824 if (aedsp16_cfg_write(port) == FALSE)
825 return FALSE;
826
827 outb(soft_cfg_mss, ae_config.mss_base);
828
829 DBG(("success.\n"));
830
831 return TRUE;
832}
833
834static int __init aedsp16_setup_board(int port) {
835 int loop = RETRY;
836
837#if defined(CONFIG_SC6600)
838 int val = 0;
839
840 if (aedsp16_hard_read(port) == FALSE) {
841 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
842 return FALSE;
843 }
844
845 if (aedsp16_write(port, COMMAND_52)) {
846 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
847 return FALSE;
848 }
849
850 if ((val = aedsp16_read(port)) == -1) {
851 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
852 COMMAND_52);
853 return FALSE;
854 }
855#endif
856
857 do {
858 if (aedsp16_write(port, COMMAND_88)) {
859 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_88);
860 return FALSE;
861 }
862 mdelay(10);
863 } while ((aedsp16_wait_data(port) == FALSE) && loop--);
864
865 if (aedsp16_read(port) == -1) {
866 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
867 COMMAND_88);
868 return FALSE;
869 }
870
871#if !defined(CONFIG_SC6600)
872 if (aedsp16_write(port, COMMAND_5C)) {
873 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
874 return FALSE;
875 }
876#endif
877
878 if (aedsp16_cfg_write(port) == FALSE)
879 return FALSE;
880
881#if defined(CONFIG_SC6600)
882 if (aedsp16_write(port, COMMAND_60)) {
883 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
884 return FALSE;
885 }
886 if (aedsp16_write(port, val)) {
887 printk("[AEDSP16] DATA 0x%x: failed!\n", val);
888 return FALSE;
889 }
890 if (aedsp16_write(port, COMMAND_6E)) {
891 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6E);
892 return FALSE;
893 }
894 if (aedsp16_write(port, ver[0])) {
895 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[0]);
896 return FALSE;
897 }
898 if (aedsp16_write(port, ver[1])) {
899 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[1]);
900 return FALSE;
901 }
902
903 if (aedsp16_hard_write(port) == FALSE) {
904 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
905 return FALSE;
906 }
907
908 if (aedsp16_write(port, COMMAND_5C)) {
909 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
910 return FALSE;
911 }
912
913#if defined(THIS_IS_A_THING_I_HAVE_NOT_TESTED_YET)
914 if (aedsp16_cfg_write(port) == FALSE)
915 return FALSE;
916#endif
917
918#endif
919
920 return TRUE;
921}
922
923static int __init aedsp16_stdcfg(int port) {
924 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
925 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
926 return FALSE;
927 }
928 /*
929 * 0x0A == (IRQ 7, DMA 1, MIRQ 0)
930 */
931 if (aedsp16_write(port, 0x0A)) {
932 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
933 return FALSE;
934 }
935 return TRUE;
936}
937
938static int __init aedsp16_dsp_version(int port)
939{
940 int len = 0;
941 int ret;
942
943 DBG(("Get DSP Version:\n"));
944
945 if (aedsp16_write(ae_config.base_io, GET_DSP_VERSION)) {
946 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_VERSION);
947 DBG(("failed.\n"));
948 return FALSE;
949 }
950
951 do {
952 if ((ret = aedsp16_read(port)) == -1) {
953 DBG(("failed.\n"));
954 return FALSE;
955 }
956 /*
957 * We already know how many int are stored (2), so we know when the
958 * string is finished.
959 */
960 ver[len++] = ret;
961 } while (len < CARDVERDIGITS);
962 sprintf(DSPVersion, "%d.%d", ver[0], ver[1]);
963
964 DBG(("success.\n"));
965
966 return TRUE;
967}
968
969static int __init aedsp16_dsp_copyright(int port)
970{
971 int len = 0;
972 int ret;
973
974 DBG(("Get DSP Copyright:\n"));
975
976 if (aedsp16_write(ae_config.base_io, GET_DSP_COPYRIGHT)) {
977 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_COPYRIGHT);
978 DBG(("failed.\n"));
979 return FALSE;
980 }
981
982 do {
983 if ((ret = aedsp16_read(port)) == -1) {
984 /*
985 * If no more data available, return to the caller, no error if len>0.
986 * We have no other way to know when the string is finished.
987 */
988 if (len)
989 break;
990 else {
991 DBG(("failed.\n"));
992 return FALSE;
993 }
994 }
995
996 DSPCopyright[len++] = ret;
997
998 } while (len < CARDNAMELEN);
999
1000 DBG(("success.\n"));
1001
1002 return TRUE;
1003}
1004
1005static void __init aedsp16_init_tables(void)
1006{
1007 int i = 0;
1008
1009 memset(DSPCopyright, 0, CARDNAMELEN + 1);
1010 memset(DSPVersion, 0, CARDVERLEN + 1);
1011
1012 for (i = 0; orIRQ[i].or; i++)
1013 if (orIRQ[i].val == ae_config.irq) {
1014 soft_cfg |= orIRQ[i].or;
1015 soft_cfg_mss |= orIRQ[i].or;
1016 }
1017
1018 for (i = 0; orMIRQ[i].or; i++)
1019 if (orMIRQ[i].or == ae_config.mpu_irq)
1020 soft_cfg |= orMIRQ[i].or;
1021
1022 for (i = 0; orDMA[i].or; i++)
1023 if (orDMA[i].val == ae_config.dma) {
1024 soft_cfg |= orDMA[i].or;
1025 soft_cfg_mss |= orDMA[i].or;
1026 }
1027}
1028
1029static int __init aedsp16_init_board(void)
1030{
1031 aedsp16_init_tables();
1032
1033 if (aedsp16_dsp_reset(ae_config.base_io) == FALSE) {
1034 printk("[AEDSP16] aedsp16_dsp_reset: failed!\n");
1035 return FALSE;
1036 }
1037 if (aedsp16_dsp_copyright(ae_config.base_io) == FALSE) {
1038 printk("[AEDSP16] aedsp16_dsp_copyright: failed!\n");
1039 return FALSE;
1040 }
1041
1042 /*
1043 * My AEDSP16 card return SC-6000 in DSPCopyright, so
1044 * if we have something different, we have to be warned.
1045 */
1046 if (strcmp("SC-6000", DSPCopyright))
1047 printk("[AEDSP16] Warning: non SC-6000 audio card!\n");
1048
1049 if (aedsp16_dsp_version(ae_config.base_io) == FALSE) {
1050 printk("[AEDSP16] aedsp16_dsp_version: failed!\n");
1051 return FALSE;
1052 }
1053
1054 if (aedsp16_stdcfg(ae_config.base_io) == FALSE) {
1055 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
1056 return FALSE;
1057 }
1058
1059#if defined(CONFIG_SC6600)
1060 if (aedsp16_hard_read(ae_config.base_io) == FALSE) {
1061 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
1062 return FALSE;
1063 }
1064
1065 aedsp16_hard_decode();
1066
1067 aedsp16_hard_encode();
1068
1069 if (aedsp16_hard_write(ae_config.base_io) == FALSE) {
1070 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
1071 return FALSE;
1072 }
1073
1074 if (aedsp16_ext_cfg_write(ae_config.base_io) == FALSE) {
1075 printk("[AEDSP16] aedsp16_ext_cfg_write: failed!\n");
1076 return FALSE;
1077 }
1078#endif /* CONFIG_SC6600 */
1079
1080 if (aedsp16_setup_board(ae_config.base_io) == FALSE) {
1081 printk("[AEDSP16] aedsp16_setup_board: failed!\n");
1082 return FALSE;
1083 }
1084
1085 if (ae_config.mss_base != -1) {
1086 if (ae_config.init & INIT_MSS) {
1087 if (aedsp16_init_mss(ae_config.base_io) == FALSE) {
1088 printk("[AEDSP16] Can not initialize"
1089 "Microsoft Sound System mode.\n");
1090 return FALSE;
1091 }
1092 }
1093 }
1094
1095#if !defined(MODULE) || defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
1096
1097 printk("Audio Excel DSP 16 init v%s (%s %s) [",
1098 VERSION, DSPCopyright,
1099 DSPVersion);
1100
1101 if (ae_config.mpu_base != -1) {
1102 if (ae_config.init & INIT_MPU401) {
1103 printk("MPU401");
1104 if ((ae_config.init & INIT_MSS) ||
1105 (ae_config.init & INIT_SBPRO))
1106 printk(" ");
1107 }
1108 }
1109
1110 if (ae_config.mss_base == -1) {
1111 if (ae_config.init & INIT_SBPRO) {
1112 printk("SBPro");
1113 if (ae_config.init & INIT_MSS)
1114 printk(" ");
1115 }
1116 }
1117
1118 if (ae_config.mss_base != -1)
1119 if (ae_config.init & INIT_MSS)
1120 printk("MSS");
1121
1122 printk("]\n");
1123#endif /* MODULE || AEDSP16_INFO || AEDSP16_DEBUG */
1124
1125 mdelay(10);
1126
1127 return TRUE;
1128}
1129
1130static int __init init_aedsp16_sb(void)
1131{
1132 DBG(("init_aedsp16_sb: "));
1133
1134/*
1135 * If the card is already init'ed MSS, we can not init it to SBPRO too
1136 * because the board can not emulate simultaneously MSS and SBPRO.
1137 */
1138 if (ae_config.init & INIT_MSS)
1139 return FALSE;
1140 if (ae_config.init & INIT_SBPRO)
1141 return FALSE;
1142
1143 ae_config.init |= INIT_SBPRO;
1144
1145 DBG(("done.\n"));
1146
1147 return TRUE;
1148}
1149
1150static void uninit_aedsp16_sb(void)
1151{
1152 DBG(("uninit_aedsp16_sb: "));
1153
1154 ae_config.init &= ~INIT_SBPRO;
1155
1156 DBG(("done.\n"));
1157}
1158
1159static int __init init_aedsp16_mss(void)
1160{
1161 DBG(("init_aedsp16_mss: "));
1162
1163/*
1164 * If the card is already init'ed SBPRO, we can not init it to MSS too
1165 * because the board can not emulate simultaneously MSS and SBPRO.
1166 */
1167 if (ae_config.init & INIT_SBPRO)
1168 return FALSE;
1169 if (ae_config.init & INIT_MSS)
1170 return FALSE;
1171/*
1172 * We must allocate the CONFIG_AEDSP16_BASE region too because these are the
1173 * I/O ports to access card's control registers.
1174 */
1175 if (!(ae_config.init & INIT_MPU401)) {
1176 if (!request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1177 "aedsp16 (base)")) {
1178 printk(
1179 "AEDSP16 BASE I/O port region is already in use.\n");
1180 return FALSE;
1181 }
1182 }
1183
1184 ae_config.init |= INIT_MSS;
1185
1186 DBG(("done.\n"));
1187
1188 return TRUE;
1189}
1190
1191static void uninit_aedsp16_mss(void)
1192{
1193 DBG(("uninit_aedsp16_mss: "));
1194
1195 if ((!(ae_config.init & INIT_MPU401)) &&
1196 (ae_config.init & INIT_MSS)) {
1197 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1198 DBG(("AEDSP16 base region released.\n"));
1199 }
1200
1201 ae_config.init &= ~INIT_MSS;
1202 DBG(("done.\n"));
1203}
1204
1205static int __init init_aedsp16_mpu(void)
1206{
1207 DBG(("init_aedsp16_mpu: "));
1208
1209 if (ae_config.init & INIT_MPU401)
1210 return FALSE;
1211
1212/*
1213 * We must request the CONFIG_AEDSP16_BASE region too because these are the I/O
1214 * ports to access card's control registers.
1215 */
1216 if (!(ae_config.init & (INIT_MSS | INIT_SBPRO))) {
1217 if (!request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1218 "aedsp16 (base)")) {
1219 printk(
1220 "AEDSP16 BASE I/O port region is already in use.\n");
1221 return FALSE;
1222 }
1223 }
1224
1225 ae_config.init |= INIT_MPU401;
1226
1227 DBG(("done.\n"));
1228
1229 return TRUE;
1230}
1231
1232static void uninit_aedsp16_mpu(void)
1233{
1234 DBG(("uninit_aedsp16_mpu: "));
1235
1236 if ((!(ae_config.init & (INIT_MSS | INIT_SBPRO))) &&
1237 (ae_config.init & INIT_MPU401)) {
1238 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1239 DBG(("AEDSP16 base region released.\n"));
1240 }
1241
1242 ae_config.init &= ~INIT_MPU401;
1243
1244 DBG(("done.\n"));
1245}
1246
1247static int __init init_aedsp16(void)
1248{
1249 int initialized = FALSE;
1250
1251 DBG(("Initializing BASE[0x%x] IRQ[%d] DMA[%d] MIRQ[%d]\n",
1252 ae_config.base_io,ae_config.irq,ae_config.dma,ae_config.mpu_irq));
1253
1254 if (ae_config.mss_base == -1) {
1255 if (init_aedsp16_sb() == FALSE) {
1256 uninit_aedsp16_sb();
1257 } else {
1258 initialized = TRUE;
1259 }
1260 }
1261
1262 if (ae_config.mpu_base != -1) {
1263 if (init_aedsp16_mpu() == FALSE) {
1264 uninit_aedsp16_mpu();
1265 } else {
1266 initialized = TRUE;
1267 }
1268 }
1269
1270/*
1271 * In the sequence of init routines, the MSS init MUST be the last!
1272 * This because of the special register programming the MSS mode needs.
1273 * A board reset would disable the MSS mode restoring the default SBPRO
1274 * mode.
1275 */
1276 if (ae_config.mss_base != -1) {
1277 if (init_aedsp16_mss() == FALSE) {
1278 uninit_aedsp16_mss();
1279 } else {
1280 initialized = TRUE;
1281 }
1282 }
1283
1284 if (initialized)
1285 initialized = aedsp16_init_board();
1286 return initialized;
1287}
1288
1289static void __exit uninit_aedsp16(void)
1290{
1291 if (ae_config.mss_base != -1)
1292 uninit_aedsp16_mss();
1293 else
1294 uninit_aedsp16_sb();
1295 if (ae_config.mpu_base != -1)
1296 uninit_aedsp16_mpu();
1297}
1298
1299static int __initdata io = -1;
1300static int __initdata irq = -1;
1301static int __initdata dma = -1;
1302static int __initdata mpu_irq = -1;
1303static int __initdata mss_base = -1;
1304static int __initdata mpu_base = -1;
1305
1306module_param_hw(io, int, ioport, 0);
1307MODULE_PARM_DESC(io, "I/O base address (0x220 0x240)");
1308module_param_hw(irq, int, irq, 0);
1309MODULE_PARM_DESC(irq, "IRQ line (5 7 9 10 11)");
1310module_param_hw(dma, int, dma, 0);
1311MODULE_PARM_DESC(dma, "dma line (0 1 3)");
1312module_param_hw(mpu_irq, int, irq, 0);
1313MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ line (5 7 9 10 0)");
1314module_param_hw(mss_base, int, ioport, 0);
1315MODULE_PARM_DESC(mss_base, "MSS emulation I/O base address (0x530 0xE80)");
1316module_param_hw(mpu_base, int, ioport, 0);
1317MODULE_PARM_DESC(mpu_base,"MPU-401 I/O base address (0x300 0x310 0x320 0x330)");
1318MODULE_AUTHOR("Riccardo Facchetti <fizban@tin.it>");
1319MODULE_DESCRIPTION("Audio Excel DSP 16 Driver Version " VERSION);
1320MODULE_LICENSE("GPL");
1321
1322static int __init do_init_aedsp16(void) {
1323 printk("Audio Excel DSP 16 init driver Copyright (C) Riccardo Facchetti 1995-98\n");
1324 if (io == -1 || dma == -1 || irq == -1) {
1325 printk(KERN_INFO "aedsp16: I/O, IRQ and DMA are mandatory\n");
1326 return -EINVAL;
1327 }
1328
1329 ae_config.base_io = io;
1330 ae_config.irq = irq;
1331 ae_config.dma = dma;
1332
1333 ae_config.mss_base = mss_base;
1334 ae_config.mpu_base = mpu_base;
1335 ae_config.mpu_irq = mpu_irq;
1336
1337 if (init_aedsp16() == FALSE) {
1338 printk(KERN_ERR "aedsp16: initialization failed\n");
1339 /*
1340 * XXX
1341 * What error should we return here ?
1342 */
1343 return -EINVAL;
1344 }
1345 return 0;
1346}
1347
1348static void __exit cleanup_aedsp16(void) {
1349 uninit_aedsp16();
1350}
1351
1352module_init(do_init_aedsp16);
1353module_exit(cleanup_aedsp16);
1354
1355#ifndef MODULE
1356static int __init setup_aedsp16(char *str)
1357{
1358 /* io, irq, dma, mss_io, mpu_io, mpu_irq */
1359 int ints[7];
1360
1361 str = get_options(str, ARRAY_SIZE(ints), ints);
1362
1363 io = ints[1];
1364 irq = ints[2];
1365 dma = ints[3];
1366 mss_base = ints[4];
1367 mpu_base = ints[5];
1368 mpu_irq = ints[6];
1369 return 1;
1370}
1371
1372__setup("aedsp16=", setup_aedsp16);
1373#endif
diff --git a/sound/oss/audio.c b/sound/oss/audio.c
deleted file mode 100644
index 09c932f899b8..000000000000
--- a/sound/oss/audio.c
+++ /dev/null
@@ -1,985 +0,0 @@
1/*
2 * sound/oss/audio.c
3 *
4 * Device file manager for /dev/audio
5 */
6
7/*
8 * Copyright (C) by Hannu Savolainen 1993-1997
9 *
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
12 * for more info.
13 */
14/*
15 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
16 * Thomas Sailer : moved several static variables into struct audio_operations
17 * (which is grossly misnamed btw.) because they have the same
18 * lifetime as the rest in there and dynamic allocation saves
19 * 12k or so
20 * Thomas Sailer : use more logical O_NONBLOCK semantics
21 * Daniel Rodriksson: reworked the use of the device specific copy_user
22 * still generic
23 * Horst von Brand: Add missing #include <linux/string.h>
24 * Chris Rankin : Update the module-usage counter for the coprocessor,
25 * and decrement the counters again if we cannot open
26 * the audio device.
27 */
28
29#include <linux/stddef.h>
30#include <linux/string.h>
31#include <linux/kmod.h>
32
33#include "sound_config.h"
34#include "ulaw.h"
35#include "coproc.h"
36
37#define NEUTRAL8 0x80
38#define NEUTRAL16 0x00
39
40
41static int dma_ioctl(int dev, unsigned int cmd, void __user *arg);
42
43static int set_format(int dev, int fmt)
44{
45 if (fmt != AFMT_QUERY)
46 {
47 audio_devs[dev]->local_conversion = 0;
48
49 if (!(audio_devs[dev]->format_mask & fmt)) /* Not supported */
50 {
51 if (fmt == AFMT_MU_LAW)
52 {
53 fmt = AFMT_U8;
54 audio_devs[dev]->local_conversion = CNV_MU_LAW;
55 }
56 else
57 fmt = AFMT_U8; /* This is always supported */
58 }
59 audio_devs[dev]->audio_format = audio_devs[dev]->d->set_bits(dev, fmt);
60 audio_devs[dev]->local_format = fmt;
61 }
62 else
63 return audio_devs[dev]->local_format;
64
65 if (audio_devs[dev]->local_conversion)
66 return audio_devs[dev]->local_conversion;
67 else
68 return audio_devs[dev]->local_format;
69}
70
71int audio_open(int dev, struct file *file)
72{
73 int ret;
74 int bits;
75 int dev_type = dev & 0x0f;
76 int mode = translate_mode(file);
77 const struct audio_driver *driver;
78 const struct coproc_operations *coprocessor;
79
80 dev = dev >> 4;
81
82 if (dev_type == SND_DEV_DSP16)
83 bits = 16;
84 else
85 bits = 8;
86
87 if (dev < 0 || dev >= num_audiodevs)
88 return -ENXIO;
89
90 driver = audio_devs[dev]->d;
91
92 if (!try_module_get(driver->owner))
93 return -ENODEV;
94
95 if ((ret = DMAbuf_open(dev, mode)) < 0)
96 goto error_1;
97
98 if ( (coprocessor = audio_devs[dev]->coproc) != NULL ) {
99 if (!try_module_get(coprocessor->owner))
100 goto error_2;
101
102 if ((ret = coprocessor->open(coprocessor->devc, COPR_PCM)) < 0) {
103 printk(KERN_WARNING "Sound: Can't access coprocessor device\n");
104 goto error_3;
105 }
106 }
107
108 audio_devs[dev]->local_conversion = 0;
109
110 if (dev_type == SND_DEV_AUDIO)
111 set_format(dev, AFMT_MU_LAW);
112 else
113 set_format(dev, bits);
114
115 audio_devs[dev]->audio_mode = AM_NONE;
116
117 return 0;
118
119 /*
120 * Clean-up stack: this is what needs (un)doing if
121 * we can't open the audio device ...
122 */
123 error_3:
124 module_put(coprocessor->owner);
125
126 error_2:
127 DMAbuf_release(dev, mode);
128
129 error_1:
130 module_put(driver->owner);
131
132 return ret;
133}
134
135static void sync_output(int dev)
136{
137 int p, i;
138 int l;
139 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
140
141 if (dmap->fragment_size <= 0)
142 return;
143 dmap->flags |= DMA_POST;
144
145 /* Align the write pointer with fragment boundaries */
146
147 if ((l = dmap->user_counter % dmap->fragment_size) > 0)
148 {
149 int len;
150 unsigned long offs = dmap->user_counter % dmap->bytes_in_use;
151
152 len = dmap->fragment_size - l;
153 memset(dmap->raw_buf + offs, dmap->neutral_byte, len);
154 DMAbuf_move_wrpointer(dev, len);
155 }
156
157 /*
158 * Clean all unused buffer fragments.
159 */
160
161 p = dmap->qtail;
162 dmap->flags |= DMA_POST;
163
164 for (i = dmap->qlen + 1; i < dmap->nbufs; i++)
165 {
166 p = (p + 1) % dmap->nbufs;
167 if (((dmap->raw_buf + p * dmap->fragment_size) + dmap->fragment_size) >
168 (dmap->raw_buf + dmap->buffsize))
169 printk(KERN_ERR "audio: Buffer error 2\n");
170
171 memset(dmap->raw_buf + p * dmap->fragment_size,
172 dmap->neutral_byte,
173 dmap->fragment_size);
174 }
175
176 dmap->flags |= DMA_DIRTY;
177}
178
179void audio_release(int dev, struct file *file)
180{
181 const struct coproc_operations *coprocessor;
182 int mode = translate_mode(file);
183
184 dev = dev >> 4;
185
186 /*
187 * We do this in DMAbuf_release(). Why are we doing it
188 * here? Why don't we test the file mode before setting
189 * both flags? DMAbuf_release() does.
190 * ...pester...pester...pester...
191 */
192 audio_devs[dev]->dmap_out->closing = 1;
193 audio_devs[dev]->dmap_in->closing = 1;
194
195 /*
196 * We need to make sure we allocated the dmap_out buffer
197 * before we go mucking around with it in sync_output().
198 */
199 if (mode & OPEN_WRITE)
200 sync_output(dev);
201
202 if ( (coprocessor = audio_devs[dev]->coproc) != NULL ) {
203 coprocessor->close(coprocessor->devc, COPR_PCM);
204 module_put(coprocessor->owner);
205 }
206 DMAbuf_release(dev, mode);
207
208 module_put(audio_devs[dev]->d->owner);
209}
210
211static void translate_bytes(const unsigned char *table, unsigned char *buff, int n)
212{
213 unsigned long i;
214
215 if (n <= 0)
216 return;
217
218 for (i = 0; i < n; ++i)
219 buff[i] = table[buff[i]];
220}
221
222int audio_write(int dev, struct file *file, const char __user *buf, int count)
223{
224 int c, p, l, buf_size, used, returned;
225 int err;
226 char *dma_buf;
227
228 dev = dev >> 4;
229
230 p = 0;
231 c = count;
232
233 if(count < 0)
234 return -EINVAL;
235
236 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
237 return -EPERM;
238
239 if (audio_devs[dev]->flags & DMA_DUPLEX)
240 audio_devs[dev]->audio_mode |= AM_WRITE;
241 else
242 audio_devs[dev]->audio_mode = AM_WRITE;
243
244 if (!count) /* Flush output */
245 {
246 sync_output(dev);
247 return 0;
248 }
249
250 while (c)
251 {
252 if ((err = DMAbuf_getwrbuffer(dev, &dma_buf, &buf_size, !!(file->f_flags & O_NONBLOCK))) < 0)
253 {
254 /* Handle nonblocking mode */
255 if ((file->f_flags & O_NONBLOCK) && err == -EAGAIN)
256 return p? p : -EAGAIN; /* No more space. Return # of accepted bytes */
257 return err;
258 }
259 l = c;
260
261 if (l > buf_size)
262 l = buf_size;
263
264 returned = l;
265 used = l;
266 if (!audio_devs[dev]->d->copy_user)
267 {
268 if ((dma_buf + l) >
269 (audio_devs[dev]->dmap_out->raw_buf + audio_devs[dev]->dmap_out->buffsize))
270 {
271 printk(KERN_ERR "audio: Buffer error 3 (%lx,%d), (%lx, %d)\n", (long) dma_buf, l, (long) audio_devs[dev]->dmap_out->raw_buf, (int) audio_devs[dev]->dmap_out->buffsize);
272 return -EDOM;
273 }
274 if (dma_buf < audio_devs[dev]->dmap_out->raw_buf)
275 {
276 printk(KERN_ERR "audio: Buffer error 13 (%lx<%lx)\n", (long) dma_buf, (long) audio_devs[dev]->dmap_out->raw_buf);
277 return -EDOM;
278 }
279 if(copy_from_user(dma_buf, &(buf)[p], l))
280 return -EFAULT;
281 }
282 else audio_devs[dev]->d->copy_user (dev,
283 dma_buf, 0,
284 buf, p,
285 c, buf_size,
286 &used, &returned,
287 l);
288 l = returned;
289
290 if (audio_devs[dev]->local_conversion & CNV_MU_LAW)
291 {
292 translate_bytes(ulaw_dsp, (unsigned char *) dma_buf, l);
293 }
294 c -= used;
295 p += used;
296 DMAbuf_move_wrpointer(dev, l);
297
298 }
299
300 return count;
301}
302
303int audio_read(int dev, struct file *file, char __user *buf, int count)
304{
305 int c, p, l;
306 char *dmabuf;
307 int buf_no;
308
309 dev = dev >> 4;
310 p = 0;
311 c = count;
312
313 if (!(audio_devs[dev]->open_mode & OPEN_READ))
314 return -EPERM;
315
316 if ((audio_devs[dev]->audio_mode & AM_WRITE) && !(audio_devs[dev]->flags & DMA_DUPLEX))
317 sync_output(dev);
318
319 if (audio_devs[dev]->flags & DMA_DUPLEX)
320 audio_devs[dev]->audio_mode |= AM_READ;
321 else
322 audio_devs[dev]->audio_mode = AM_READ;
323
324 while(c)
325 {
326 if ((buf_no = DMAbuf_getrdbuffer(dev, &dmabuf, &l, !!(file->f_flags & O_NONBLOCK))) < 0)
327 {
328 /*
329 * Nonblocking mode handling. Return current # of bytes
330 */
331
332 if (p > 0) /* Avoid throwing away data */
333 return p; /* Return it instead */
334
335 if ((file->f_flags & O_NONBLOCK) && buf_no == -EAGAIN)
336 return -EAGAIN;
337
338 return buf_no;
339 }
340 if (l > c)
341 l = c;
342
343 /*
344 * Insert any local processing here.
345 */
346
347 if (audio_devs[dev]->local_conversion & CNV_MU_LAW)
348 {
349 translate_bytes(dsp_ulaw, (unsigned char *) dmabuf, l);
350 }
351
352 {
353 char *fixit = dmabuf;
354
355 if(copy_to_user(&(buf)[p], fixit, l))
356 return -EFAULT;
357 }
358
359 DMAbuf_rmchars(dev, buf_no, l);
360
361 p += l;
362 c -= l;
363 }
364
365 return count - c;
366}
367
368int audio_ioctl(int dev, struct file *file, unsigned int cmd, void __user *arg)
369{
370 int val, count;
371 unsigned long flags;
372 struct dma_buffparms *dmap;
373 int __user *p = arg;
374
375 dev = dev >> 4;
376
377 if (_IOC_TYPE(cmd) == 'C') {
378 if (audio_devs[dev]->coproc) /* Coprocessor ioctl */
379 return audio_devs[dev]->coproc->ioctl(audio_devs[dev]->coproc->devc, cmd, arg, 0);
380 /* else
381 printk(KERN_DEBUG"/dev/dsp%d: No coprocessor for this device\n", dev); */
382 return -ENXIO;
383 }
384 else switch (cmd)
385 {
386 case SNDCTL_DSP_SYNC:
387 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
388 return 0;
389 if (audio_devs[dev]->dmap_out->fragment_size == 0)
390 return 0;
391 sync_output(dev);
392 DMAbuf_sync(dev);
393 DMAbuf_reset(dev);
394 return 0;
395
396 case SNDCTL_DSP_POST:
397 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
398 return 0;
399 if (audio_devs[dev]->dmap_out->fragment_size == 0)
400 return 0;
401 audio_devs[dev]->dmap_out->flags |= DMA_POST | DMA_DIRTY;
402 sync_output(dev);
403 dma_ioctl(dev, SNDCTL_DSP_POST, NULL);
404 return 0;
405
406 case SNDCTL_DSP_RESET:
407 audio_devs[dev]->audio_mode = AM_NONE;
408 DMAbuf_reset(dev);
409 return 0;
410
411 case SNDCTL_DSP_GETFMTS:
412 val = audio_devs[dev]->format_mask | AFMT_MU_LAW;
413 break;
414
415 case SNDCTL_DSP_SETFMT:
416 if (get_user(val, p))
417 return -EFAULT;
418 val = set_format(dev, val);
419 break;
420
421 case SNDCTL_DSP_GETISPACE:
422 if (!(audio_devs[dev]->open_mode & OPEN_READ))
423 return 0;
424 if ((audio_devs[dev]->audio_mode & AM_WRITE) && !(audio_devs[dev]->flags & DMA_DUPLEX))
425 return -EBUSY;
426 return dma_ioctl(dev, cmd, arg);
427
428 case SNDCTL_DSP_GETOSPACE:
429 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
430 return -EPERM;
431 if ((audio_devs[dev]->audio_mode & AM_READ) && !(audio_devs[dev]->flags & DMA_DUPLEX))
432 return -EBUSY;
433 return dma_ioctl(dev, cmd, arg);
434
435 case SNDCTL_DSP_NONBLOCK:
436 spin_lock(&file->f_lock);
437 file->f_flags |= O_NONBLOCK;
438 spin_unlock(&file->f_lock);
439 return 0;
440
441 case SNDCTL_DSP_GETCAPS:
442 val = 1 | DSP_CAP_MMAP; /* Revision level of this ioctl() */
443 if (audio_devs[dev]->flags & DMA_DUPLEX &&
444 audio_devs[dev]->open_mode == OPEN_READWRITE)
445 val |= DSP_CAP_DUPLEX;
446 if (audio_devs[dev]->coproc)
447 val |= DSP_CAP_COPROC;
448 if (audio_devs[dev]->d->local_qlen) /* Device has hidden buffers */
449 val |= DSP_CAP_BATCH;
450 if (audio_devs[dev]->d->trigger) /* Supports SETTRIGGER */
451 val |= DSP_CAP_TRIGGER;
452 break;
453
454 case SOUND_PCM_WRITE_RATE:
455 if (get_user(val, p))
456 return -EFAULT;
457 val = audio_devs[dev]->d->set_speed(dev, val);
458 break;
459
460 case SOUND_PCM_READ_RATE:
461 val = audio_devs[dev]->d->set_speed(dev, 0);
462 break;
463
464 case SNDCTL_DSP_STEREO:
465 if (get_user(val, p))
466 return -EFAULT;
467 if (val > 1 || val < 0)
468 return -EINVAL;
469 val = audio_devs[dev]->d->set_channels(dev, val + 1) - 1;
470 break;
471
472 case SOUND_PCM_WRITE_CHANNELS:
473 if (get_user(val, p))
474 return -EFAULT;
475 val = audio_devs[dev]->d->set_channels(dev, val);
476 break;
477
478 case SOUND_PCM_READ_CHANNELS:
479 val = audio_devs[dev]->d->set_channels(dev, 0);
480 break;
481
482 case SOUND_PCM_READ_BITS:
483 val = audio_devs[dev]->d->set_bits(dev, 0);
484 break;
485
486 case SNDCTL_DSP_SETDUPLEX:
487 if (audio_devs[dev]->open_mode != OPEN_READWRITE)
488 return -EPERM;
489 return (audio_devs[dev]->flags & DMA_DUPLEX) ? 0 : -EIO;
490
491 case SNDCTL_DSP_PROFILE:
492 if (get_user(val, p))
493 return -EFAULT;
494 if (audio_devs[dev]->open_mode & OPEN_WRITE)
495 audio_devs[dev]->dmap_out->applic_profile = val;
496 if (audio_devs[dev]->open_mode & OPEN_READ)
497 audio_devs[dev]->dmap_in->applic_profile = val;
498 return 0;
499
500 case SNDCTL_DSP_GETODELAY:
501 dmap = audio_devs[dev]->dmap_out;
502 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
503 return -EINVAL;
504 if (!(dmap->flags & DMA_ALLOC_DONE))
505 {
506 val=0;
507 break;
508 }
509
510 spin_lock_irqsave(&dmap->lock,flags);
511 /* Compute number of bytes that have been played */
512 count = DMAbuf_get_buffer_pointer (dev, dmap, DMODE_OUTPUT);
513 if (count < dmap->fragment_size && dmap->qhead != 0)
514 count += dmap->bytes_in_use; /* Pointer wrap not handled yet */
515 count += dmap->byte_counter;
516
517 /* Subtract current count from the number of bytes written by app */
518 count = dmap->user_counter - count;
519 if (count < 0)
520 count = 0;
521 spin_unlock_irqrestore(&dmap->lock,flags);
522 val = count;
523 break;
524
525 default:
526 return dma_ioctl(dev, cmd, arg);
527 }
528 return put_user(val, p);
529}
530
531void audio_init_devices(void)
532{
533 /*
534 * NOTE! This routine could be called several times during boot.
535 */
536}
537
538void reorganize_buffers(int dev, struct dma_buffparms *dmap, int recording)
539{
540 /*
541 * This routine breaks the physical device buffers to logical ones.
542 */
543
544 struct audio_operations *dsp_dev = audio_devs[dev];
545
546 unsigned i, n;
547 unsigned sr, nc, sz, bsz;
548
549 sr = dsp_dev->d->set_speed(dev, 0);
550 nc = dsp_dev->d->set_channels(dev, 0);
551 sz = dsp_dev->d->set_bits(dev, 0);
552
553 if (sz == 8)
554 dmap->neutral_byte = NEUTRAL8;
555 else
556 dmap->neutral_byte = NEUTRAL16;
557
558 if (sr < 1 || nc < 1 || sz < 1)
559 {
560/* printk(KERN_DEBUG "Warning: Invalid PCM parameters[%d] sr=%d, nc=%d, sz=%d\n", dev, sr, nc, sz);*/
561 sr = DSP_DEFAULT_SPEED;
562 nc = 1;
563 sz = 8;
564 }
565
566 sz = sr * nc * sz;
567
568 sz /= 8; /* #bits -> #bytes */
569 dmap->data_rate = sz;
570
571 if (!dmap->needs_reorg)
572 return;
573 dmap->needs_reorg = 0;
574
575 if (dmap->fragment_size == 0)
576 {
577 /* Compute the fragment size using the default algorithm */
578
579 /*
580 * Compute a buffer size for time not exceeding 1 second.
581 * Usually this algorithm gives a buffer size for 0.5 to 1.0 seconds
582 * of sound (using the current speed, sample size and #channels).
583 */
584
585 bsz = dmap->buffsize;
586 while (bsz > sz)
587 bsz /= 2;
588
589 if (bsz == dmap->buffsize)
590 bsz /= 2; /* Needs at least 2 buffers */
591
592 /*
593 * Split the computed fragment to smaller parts. After 3.5a9
594 * the default subdivision is 4 which should give better
595 * results when recording.
596 */
597
598 if (dmap->subdivision == 0) /* Not already set */
599 {
600 dmap->subdivision = 4; /* Init to the default value */
601
602 if ((bsz / dmap->subdivision) > 4096)
603 dmap->subdivision *= 2;
604 if ((bsz / dmap->subdivision) < 4096)
605 dmap->subdivision = 1;
606 }
607 bsz /= dmap->subdivision;
608
609 if (bsz < 16)
610 bsz = 16; /* Just a sanity check */
611
612 dmap->fragment_size = bsz;
613 }
614 else
615 {
616 /*
617 * The process has specified the buffer size with SNDCTL_DSP_SETFRAGMENT or
618 * the buffer size computation has already been done.
619 */
620 if (dmap->fragment_size > (dmap->buffsize / 2))
621 dmap->fragment_size = (dmap->buffsize / 2);
622 bsz = dmap->fragment_size;
623 }
624
625 if (audio_devs[dev]->min_fragment)
626 if (bsz < (1 << audio_devs[dev]->min_fragment))
627 bsz = 1 << audio_devs[dev]->min_fragment;
628 if (audio_devs[dev]->max_fragment)
629 if (bsz > (1 << audio_devs[dev]->max_fragment))
630 bsz = 1 << audio_devs[dev]->max_fragment;
631 bsz &= ~0x07; /* Force size which is multiple of 8 bytes */
632#ifdef OS_DMA_ALIGN_CHECK
633 OS_DMA_ALIGN_CHECK(bsz);
634#endif
635
636 n = dmap->buffsize / bsz;
637 if (n > MAX_SUB_BUFFERS)
638 n = MAX_SUB_BUFFERS;
639 if (n > dmap->max_fragments)
640 n = dmap->max_fragments;
641
642 if (n < 2)
643 {
644 n = 2;
645 bsz /= 2;
646 }
647 dmap->nbufs = n;
648 dmap->bytes_in_use = n * bsz;
649 dmap->fragment_size = bsz;
650 dmap->max_byte_counter = (dmap->data_rate * 60 * 60) +
651 dmap->bytes_in_use; /* Approximately one hour */
652
653 if (dmap->raw_buf)
654 {
655 memset(dmap->raw_buf, dmap->neutral_byte, dmap->bytes_in_use);
656 }
657
658 for (i = 0; i < dmap->nbufs; i++)
659 {
660 dmap->counts[i] = 0;
661 }
662
663 dmap->flags |= DMA_ALLOC_DONE | DMA_EMPTY;
664}
665
666static int dma_subdivide(int dev, struct dma_buffparms *dmap, int fact)
667{
668 if (fact == 0)
669 {
670 fact = dmap->subdivision;
671 if (fact == 0)
672 fact = 1;
673 return fact;
674 }
675 if (dmap->subdivision != 0 || dmap->fragment_size) /* Too late to change */
676 return -EINVAL;
677
678 if (fact > MAX_REALTIME_FACTOR)
679 return -EINVAL;
680
681 if (fact != 1 && fact != 2 && fact != 4 && fact != 8 && fact != 16)
682 return -EINVAL;
683
684 dmap->subdivision = fact;
685 return fact;
686}
687
688static int dma_set_fragment(int dev, struct dma_buffparms *dmap, int fact)
689{
690 int bytes, count;
691
692 if (fact == 0)
693 return -EIO;
694
695 if (dmap->subdivision != 0 ||
696 dmap->fragment_size) /* Too late to change */
697 return -EINVAL;
698
699 bytes = fact & 0xffff;
700 count = (fact >> 16) & 0x7fff;
701
702 if (count == 0)
703 count = MAX_SUB_BUFFERS;
704 else if (count < MAX_SUB_BUFFERS)
705 count++;
706
707 if (bytes < 4 || bytes > 17) /* <16 || > 512k */
708 return -EINVAL;
709
710 if (count < 2)
711 return -EINVAL;
712
713 if (audio_devs[dev]->min_fragment > 0)
714 if (bytes < audio_devs[dev]->min_fragment)
715 bytes = audio_devs[dev]->min_fragment;
716
717 if (audio_devs[dev]->max_fragment > 0)
718 if (bytes > audio_devs[dev]->max_fragment)
719 bytes = audio_devs[dev]->max_fragment;
720
721#ifdef OS_DMA_MINBITS
722 if (bytes < OS_DMA_MINBITS)
723 bytes = OS_DMA_MINBITS;
724#endif
725
726 dmap->fragment_size = (1 << bytes);
727 dmap->max_fragments = count;
728
729 if (dmap->fragment_size > dmap->buffsize)
730 dmap->fragment_size = dmap->buffsize;
731
732 if (dmap->fragment_size == dmap->buffsize &&
733 audio_devs[dev]->flags & DMA_AUTOMODE)
734 dmap->fragment_size /= 2; /* Needs at least 2 buffers */
735
736 dmap->subdivision = 1; /* Disable SNDCTL_DSP_SUBDIVIDE */
737 return bytes | ((count - 1) << 16);
738}
739
740static int dma_ioctl(int dev, unsigned int cmd, void __user *arg)
741{
742 struct dma_buffparms *dmap_out = audio_devs[dev]->dmap_out;
743 struct dma_buffparms *dmap_in = audio_devs[dev]->dmap_in;
744 struct dma_buffparms *dmap;
745 audio_buf_info info;
746 count_info cinfo;
747 int fact, ret, changed, bits, count, err;
748 unsigned long flags;
749
750 switch (cmd)
751 {
752 case SNDCTL_DSP_SUBDIVIDE:
753 ret = 0;
754 if (get_user(fact, (int __user *)arg))
755 return -EFAULT;
756 if (audio_devs[dev]->open_mode & OPEN_WRITE)
757 ret = dma_subdivide(dev, dmap_out, fact);
758 if (ret < 0)
759 return ret;
760 if (audio_devs[dev]->open_mode != OPEN_WRITE ||
761 (audio_devs[dev]->flags & DMA_DUPLEX &&
762 audio_devs[dev]->open_mode & OPEN_READ))
763 ret = dma_subdivide(dev, dmap_in, fact);
764 if (ret < 0)
765 return ret;
766 break;
767
768 case SNDCTL_DSP_GETISPACE:
769 case SNDCTL_DSP_GETOSPACE:
770 dmap = dmap_out;
771 if (cmd == SNDCTL_DSP_GETISPACE && !(audio_devs[dev]->open_mode & OPEN_READ))
772 return -EINVAL;
773 if (cmd == SNDCTL_DSP_GETOSPACE && !(audio_devs[dev]->open_mode & OPEN_WRITE))
774 return -EINVAL;
775 if (cmd == SNDCTL_DSP_GETISPACE && audio_devs[dev]->flags & DMA_DUPLEX)
776 dmap = dmap_in;
777 if (dmap->mapping_flags & DMA_MAP_MAPPED)
778 return -EINVAL;
779 if (!(dmap->flags & DMA_ALLOC_DONE))
780 reorganize_buffers(dev, dmap, (cmd == SNDCTL_DSP_GETISPACE));
781 info.fragstotal = dmap->nbufs;
782 if (cmd == SNDCTL_DSP_GETISPACE)
783 info.fragments = dmap->qlen;
784 else
785 {
786 if (!DMAbuf_space_in_queue(dev))
787 info.fragments = 0;
788 else
789 {
790 info.fragments = DMAbuf_space_in_queue(dev);
791 if (audio_devs[dev]->d->local_qlen)
792 {
793 int tmp = audio_devs[dev]->d->local_qlen(dev);
794 if (tmp && info.fragments)
795 tmp--; /*
796 * This buffer has been counted twice
797 */
798 info.fragments -= tmp;
799 }
800 }
801 }
802 if (info.fragments < 0)
803 info.fragments = 0;
804 else if (info.fragments > dmap->nbufs)
805 info.fragments = dmap->nbufs;
806
807 info.fragsize = dmap->fragment_size;
808 info.bytes = info.fragments * dmap->fragment_size;
809
810 if (cmd == SNDCTL_DSP_GETISPACE && dmap->qlen)
811 info.bytes -= dmap->counts[dmap->qhead];
812 else
813 {
814 info.fragments = info.bytes / dmap->fragment_size;
815 info.bytes -= dmap->user_counter % dmap->fragment_size;
816 }
817 if (copy_to_user(arg, &info, sizeof(info)))
818 return -EFAULT;
819 return 0;
820
821 case SNDCTL_DSP_SETTRIGGER:
822 if (get_user(bits, (int __user *)arg))
823 return -EFAULT;
824 bits &= audio_devs[dev]->open_mode;
825 if (audio_devs[dev]->d->trigger == NULL)
826 return -EINVAL;
827 if (!(audio_devs[dev]->flags & DMA_DUPLEX) && (bits & PCM_ENABLE_INPUT) &&
828 (bits & PCM_ENABLE_OUTPUT))
829 return -EINVAL;
830
831 if (bits & PCM_ENABLE_INPUT)
832 {
833 spin_lock_irqsave(&dmap_in->lock,flags);
834 changed = (audio_devs[dev]->enable_bits ^ bits) & PCM_ENABLE_INPUT;
835 if (changed && audio_devs[dev]->go)
836 {
837 reorganize_buffers(dev, dmap_in, 1);
838 if ((err = audio_devs[dev]->d->prepare_for_input(dev,
839 dmap_in->fragment_size, dmap_in->nbufs)) < 0) {
840 spin_unlock_irqrestore(&dmap_in->lock,flags);
841 return err;
842 }
843 dmap_in->dma_mode = DMODE_INPUT;
844 audio_devs[dev]->enable_bits |= PCM_ENABLE_INPUT;
845 DMAbuf_activate_recording(dev, dmap_in);
846 } else
847 audio_devs[dev]->enable_bits &= ~PCM_ENABLE_INPUT;
848 spin_unlock_irqrestore(&dmap_in->lock,flags);
849 }
850 if (bits & PCM_ENABLE_OUTPUT)
851 {
852 spin_lock_irqsave(&dmap_out->lock,flags);
853 changed = (audio_devs[dev]->enable_bits ^ bits) & PCM_ENABLE_OUTPUT;
854 if (changed &&
855 (dmap_out->mapping_flags & DMA_MAP_MAPPED || dmap_out->qlen > 0) &&
856 audio_devs[dev]->go)
857 {
858 if (!(dmap_out->flags & DMA_ALLOC_DONE))
859 reorganize_buffers(dev, dmap_out, 0);
860 dmap_out->dma_mode = DMODE_OUTPUT;
861 audio_devs[dev]->enable_bits |= PCM_ENABLE_OUTPUT;
862 dmap_out->counts[dmap_out->qhead] = dmap_out->fragment_size;
863 DMAbuf_launch_output(dev, dmap_out);
864 } else
865 audio_devs[dev]->enable_bits &= ~PCM_ENABLE_OUTPUT;
866 spin_unlock_irqrestore(&dmap_out->lock,flags);
867 }
868#if 0
869 if (changed && audio_devs[dev]->d->trigger)
870 audio_devs[dev]->d->trigger(dev, bits * audio_devs[dev]->go);
871#endif
872 /* Falls through... */
873
874 case SNDCTL_DSP_GETTRIGGER:
875 ret = audio_devs[dev]->enable_bits;
876 break;
877
878 case SNDCTL_DSP_SETSYNCRO:
879 if (!audio_devs[dev]->d->trigger)
880 return -EINVAL;
881 audio_devs[dev]->d->trigger(dev, 0);
882 audio_devs[dev]->go = 0;
883 return 0;
884
885 case SNDCTL_DSP_GETIPTR:
886 if (!(audio_devs[dev]->open_mode & OPEN_READ))
887 return -EINVAL;
888 spin_lock_irqsave(&dmap_in->lock,flags);
889 cinfo.bytes = dmap_in->byte_counter;
890 cinfo.ptr = DMAbuf_get_buffer_pointer(dev, dmap_in, DMODE_INPUT) & ~3;
891 if (cinfo.ptr < dmap_in->fragment_size && dmap_in->qtail != 0)
892 cinfo.bytes += dmap_in->bytes_in_use; /* Pointer wrap not handled yet */
893 cinfo.blocks = dmap_in->qlen;
894 cinfo.bytes += cinfo.ptr;
895 if (dmap_in->mapping_flags & DMA_MAP_MAPPED)
896 dmap_in->qlen = 0; /* Reset interrupt counter */
897 spin_unlock_irqrestore(&dmap_in->lock,flags);
898 if (copy_to_user(arg, &cinfo, sizeof(cinfo)))
899 return -EFAULT;
900 return 0;
901
902 case SNDCTL_DSP_GETOPTR:
903 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
904 return -EINVAL;
905
906 spin_lock_irqsave(&dmap_out->lock,flags);
907 cinfo.bytes = dmap_out->byte_counter;
908 cinfo.ptr = DMAbuf_get_buffer_pointer(dev, dmap_out, DMODE_OUTPUT) & ~3;
909 if (cinfo.ptr < dmap_out->fragment_size && dmap_out->qhead != 0)
910 cinfo.bytes += dmap_out->bytes_in_use; /* Pointer wrap not handled yet */
911 cinfo.blocks = dmap_out->qlen;
912 cinfo.bytes += cinfo.ptr;
913 if (dmap_out->mapping_flags & DMA_MAP_MAPPED)
914 dmap_out->qlen = 0; /* Reset interrupt counter */
915 spin_unlock_irqrestore(&dmap_out->lock,flags);
916 if (copy_to_user(arg, &cinfo, sizeof(cinfo)))
917 return -EFAULT;
918 return 0;
919
920 case SNDCTL_DSP_GETODELAY:
921 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
922 return -EINVAL;
923 if (!(dmap_out->flags & DMA_ALLOC_DONE))
924 {
925 ret=0;
926 break;
927 }
928 spin_lock_irqsave(&dmap_out->lock,flags);
929 /* Compute number of bytes that have been played */
930 count = DMAbuf_get_buffer_pointer (dev, dmap_out, DMODE_OUTPUT);
931 if (count < dmap_out->fragment_size && dmap_out->qhead != 0)
932 count += dmap_out->bytes_in_use; /* Pointer wrap not handled yet */
933 count += dmap_out->byte_counter;
934 /* Subtract current count from the number of bytes written by app */
935 count = dmap_out->user_counter - count;
936 if (count < 0)
937 count = 0;
938 spin_unlock_irqrestore(&dmap_out->lock,flags);
939 ret = count;
940 break;
941
942 case SNDCTL_DSP_POST:
943 if (audio_devs[dev]->dmap_out->qlen > 0)
944 if (!(audio_devs[dev]->dmap_out->flags & DMA_ACTIVE))
945 DMAbuf_launch_output(dev, audio_devs[dev]->dmap_out);
946 return 0;
947
948 case SNDCTL_DSP_GETBLKSIZE:
949 dmap = dmap_out;
950 if (audio_devs[dev]->open_mode & OPEN_WRITE)
951 reorganize_buffers(dev, dmap_out, (audio_devs[dev]->open_mode == OPEN_READ));
952 if (audio_devs[dev]->open_mode == OPEN_READ ||
953 (audio_devs[dev]->flags & DMA_DUPLEX &&
954 audio_devs[dev]->open_mode & OPEN_READ))
955 reorganize_buffers(dev, dmap_in, (audio_devs[dev]->open_mode == OPEN_READ));
956 if (audio_devs[dev]->open_mode == OPEN_READ)
957 dmap = dmap_in;
958 ret = dmap->fragment_size;
959 break;
960
961 case SNDCTL_DSP_SETFRAGMENT:
962 ret = 0;
963 if (get_user(fact, (int __user *)arg))
964 return -EFAULT;
965 if (audio_devs[dev]->open_mode & OPEN_WRITE)
966 ret = dma_set_fragment(dev, dmap_out, fact);
967 if (ret < 0)
968 return ret;
969 if (audio_devs[dev]->open_mode == OPEN_READ ||
970 (audio_devs[dev]->flags & DMA_DUPLEX &&
971 audio_devs[dev]->open_mode & OPEN_READ))
972 ret = dma_set_fragment(dev, dmap_in, fact);
973 if (ret < 0)
974 return ret;
975 if (!arg) /* don't know what this is good for, but preserve old semantics */
976 return 0;
977 break;
978
979 default:
980 if (!audio_devs[dev]->d->ioctl)
981 return -EINVAL;
982 return audio_devs[dev]->d->ioctl(dev, cmd, arg);
983 }
984 return put_user(ret, (int __user *)arg);
985}
diff --git a/sound/oss/bin2hex.c b/sound/oss/bin2hex.c
deleted file mode 100644
index b59109eb0db4..000000000000
--- a/sound/oss/bin2hex.c
+++ /dev/null
@@ -1,39 +0,0 @@
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4
5int main( int argc, const char * argv [] )
6{
7 const char * varname;
8 int i = 0;
9 int c;
10 int id = 0;
11
12 if(argv[1] && strcmp(argv[1],"-i")==0)
13 {
14 argv++;
15 argc--;
16 id=1;
17 }
18
19 if(argc==1)
20 {
21 fprintf(stderr, "bin2hex: [-i] firmware\n");
22 exit(1);
23 }
24
25 varname = argv[1];
26 printf( "/* automatically generated by bin2hex */\n" );
27 printf( "static unsigned char %s [] %s =\n{\n", varname , id?"__initdata":"");
28
29 while ( ( c = getchar( ) ) != EOF )
30 {
31 if ( i != 0 && i % 10 == 0 )
32 printf( "\n" );
33 printf( "0x%02lx,", c & 0xFFl );
34 i++;
35 }
36
37 printf( "};\nstatic int %sLen = %d;\n", varname, i );
38 return 0;
39}
diff --git a/sound/oss/coproc.h b/sound/oss/coproc.h
deleted file mode 100644
index 7bec21bbdd88..000000000000
--- a/sound/oss/coproc.h
+++ /dev/null
@@ -1,12 +0,0 @@
1/*
2 * Definitions for various on board processors on the sound cards. For
3 * example DSP processors.
4 */
5
6/*
7 * Coprocessor access types
8 */
9#define COPR_CUSTOM 0x0001 /* Custom applications */
10#define COPR_MIDI 0x0002 /* MIDI (MPU-401) emulation */
11#define COPR_PCM 0x0004 /* Digitized voice applications */
12#define COPR_SYNTH 0x0008 /* Music synthesis */
diff --git a/sound/oss/dev_table.c b/sound/oss/dev_table.c
deleted file mode 100644
index 6dad51596b70..000000000000
--- a/sound/oss/dev_table.c
+++ /dev/null
@@ -1,256 +0,0 @@
1/*
2 * sound/oss/dev_table.c
3 *
4 * Device call tables.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13
14#include <linux/init.h>
15
16#include "sound_config.h"
17
18struct audio_operations *audio_devs[MAX_AUDIO_DEV];
19EXPORT_SYMBOL(audio_devs);
20
21int num_audiodevs;
22EXPORT_SYMBOL(num_audiodevs);
23
24struct mixer_operations *mixer_devs[MAX_MIXER_DEV];
25EXPORT_SYMBOL(mixer_devs);
26
27int num_mixers;
28EXPORT_SYMBOL(num_mixers);
29
30struct synth_operations *synth_devs[MAX_SYNTH_DEV+MAX_MIDI_DEV];
31EXPORT_SYMBOL(synth_devs);
32
33int num_synths;
34
35struct midi_operations *midi_devs[MAX_MIDI_DEV];
36EXPORT_SYMBOL(midi_devs);
37
38int num_midis;
39EXPORT_SYMBOL(num_midis);
40
41struct sound_timer_operations *sound_timer_devs[MAX_TIMER_DEV] = {
42 &default_sound_timer, NULL
43};
44EXPORT_SYMBOL(sound_timer_devs);
45
46int num_sound_timers = 1;
47
48
49static int sound_alloc_audiodev(void);
50
51int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
52 int driver_size, int flags, unsigned int format_mask,
53 void *devc, int dma1, int dma2)
54{
55 struct audio_driver *d;
56 struct audio_operations *op;
57 int num;
58
59 if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) {
60 printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name);
61 return -EINVAL;
62 }
63 num = sound_alloc_audiodev();
64
65 if (num == -1) {
66 printk(KERN_ERR "sound: Too many audio drivers\n");
67 return -EBUSY;
68 }
69 d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver)));
70 sound_nblocks++;
71 if (sound_nblocks >= MAX_MEM_BLOCKS)
72 sound_nblocks = MAX_MEM_BLOCKS - 1;
73
74 op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vzalloc(sizeof(struct audio_operations)));
75 sound_nblocks++;
76 if (sound_nblocks >= MAX_MEM_BLOCKS)
77 sound_nblocks = MAX_MEM_BLOCKS - 1;
78
79 if (d == NULL || op == NULL) {
80 printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name);
81 sound_unload_audiodev(num);
82 return -ENOMEM;
83 }
84 init_waitqueue_head(&op->in_sleeper);
85 init_waitqueue_head(&op->out_sleeper);
86 init_waitqueue_head(&op->poll_sleeper);
87 if (driver_size < sizeof(struct audio_driver))
88 memset((char *) d, 0, sizeof(struct audio_driver));
89
90 memcpy((char *) d, (char *) driver, driver_size);
91
92 op->d = d;
93 strlcpy(op->name, name, sizeof(op->name));
94 op->flags = flags;
95 op->format_mask = format_mask;
96 op->devc = devc;
97
98 /*
99 * Hardcoded defaults
100 */
101 audio_devs[num] = op;
102
103 DMAbuf_init(num, dma1, dma2);
104
105 audio_init_devices();
106 return num;
107}
108EXPORT_SYMBOL(sound_install_audiodrv);
109
110int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
111 int driver_size, void *devc)
112{
113 struct mixer_operations *op;
114
115 int n = sound_alloc_mixerdev();
116
117 if (n == -1) {
118 printk(KERN_ERR "Sound: Too many mixer drivers\n");
119 return -EBUSY;
120 }
121 if (vers != MIXER_DRIVER_VERSION ||
122 driver_size > sizeof(struct mixer_operations)) {
123 printk(KERN_ERR "Sound: Incompatible mixer driver for %s\n", name);
124 return -EINVAL;
125 }
126
127 /* FIXME: This leaks a mixer_operations struct every time its called
128 until you unload sound! */
129
130 op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vzalloc(sizeof(struct mixer_operations)));
131 sound_nblocks++;
132 if (sound_nblocks >= MAX_MEM_BLOCKS)
133 sound_nblocks = MAX_MEM_BLOCKS - 1;
134
135 if (op == NULL) {
136 printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name);
137 return -ENOMEM;
138 }
139 memcpy((char *) op, (char *) driver, driver_size);
140
141 strlcpy(op->name, name, sizeof(op->name));
142 op->devc = devc;
143
144 mixer_devs[n] = op;
145 return n;
146}
147EXPORT_SYMBOL(sound_install_mixer);
148
149void sound_unload_audiodev(int dev)
150{
151 if (dev != -1) {
152 DMAbuf_deinit(dev);
153 audio_devs[dev] = NULL;
154 unregister_sound_dsp((dev<<4)+3);
155 }
156}
157EXPORT_SYMBOL(sound_unload_audiodev);
158
159static int sound_alloc_audiodev(void)
160{
161 int i = register_sound_dsp(&oss_sound_fops, -1);
162 if(i==-1)
163 return i;
164 i>>=4;
165 if(i>=num_audiodevs)
166 num_audiodevs = i + 1;
167 return i;
168}
169
170int sound_alloc_mididev(void)
171{
172 int i = register_sound_midi(&oss_sound_fops, -1);
173 if(i==-1)
174 return i;
175 i>>=4;
176 if(i>=num_midis)
177 num_midis = i + 1;
178 return i;
179}
180EXPORT_SYMBOL(sound_alloc_mididev);
181
182int sound_alloc_synthdev(void)
183{
184 int i;
185
186 for (i = 0; i < MAX_SYNTH_DEV; i++) {
187 if (synth_devs[i] == NULL) {
188 if (i >= num_synths)
189 num_synths++;
190 return i;
191 }
192 }
193 return -1;
194}
195EXPORT_SYMBOL(sound_alloc_synthdev);
196
197int sound_alloc_mixerdev(void)
198{
199 int i = register_sound_mixer(&oss_sound_fops, -1);
200 if(i==-1)
201 return -1;
202 i>>=4;
203 if(i>=num_mixers)
204 num_mixers = i + 1;
205 return i;
206}
207EXPORT_SYMBOL(sound_alloc_mixerdev);
208
209int sound_alloc_timerdev(void)
210{
211 int i;
212
213 for (i = 0; i < MAX_TIMER_DEV; i++) {
214 if (sound_timer_devs[i] == NULL) {
215 if (i >= num_sound_timers)
216 num_sound_timers++;
217 return i;
218 }
219 }
220 return -1;
221}
222EXPORT_SYMBOL(sound_alloc_timerdev);
223
224void sound_unload_mixerdev(int dev)
225{
226 if (dev != -1) {
227 mixer_devs[dev] = NULL;
228 unregister_sound_mixer(dev<<4);
229 num_mixers--;
230 }
231}
232EXPORT_SYMBOL(sound_unload_mixerdev);
233
234void sound_unload_mididev(int dev)
235{
236 if (dev != -1) {
237 midi_devs[dev] = NULL;
238 unregister_sound_midi((dev<<4)+2);
239 }
240}
241EXPORT_SYMBOL(sound_unload_mididev);
242
243void sound_unload_synthdev(int dev)
244{
245 if (dev != -1)
246 synth_devs[dev] = NULL;
247}
248EXPORT_SYMBOL(sound_unload_synthdev);
249
250void sound_unload_timerdev(int dev)
251{
252 if (dev != -1)
253 sound_timer_devs[dev] = NULL;
254}
255EXPORT_SYMBOL(sound_unload_timerdev);
256
diff --git a/sound/oss/dev_table.h b/sound/oss/dev_table.h
deleted file mode 100644
index 0199a317c5a9..000000000000
--- a/sound/oss/dev_table.h
+++ /dev/null
@@ -1,390 +0,0 @@
1/*
2 * dev_table.h
3 *
4 * Global definitions for device call tables
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13
14
15#ifndef _DEV_TABLE_H_
16#define _DEV_TABLE_H_
17
18#include <linux/spinlock.h>
19/*
20 * Sound card numbers 27 to 999. (1 to 26 are defined in soundcard.h)
21 * Numbers 1000 to N are reserved for driver's internal use.
22 */
23
24#define SNDCARD_DESKPROXL 27 /* Compaq Deskpro XL */
25#define SNDCARD_VIDC 28 /* ARMs VIDC */
26#define SNDCARD_SBPNP 29
27#define SNDCARD_SOFTOSS 36
28#define SNDCARD_VMIDI 37
29#define SNDCARD_OPL3SA1 38 /* Note: clash in msnd.h */
30#define SNDCARD_OPL3SA1_SB 39
31#define SNDCARD_OPL3SA1_MPU 40
32#define SNDCARD_WAVEFRONT 41
33#define SNDCARD_OPL3SA2 42
34#define SNDCARD_OPL3SA2_MPU 43
35#define SNDCARD_WAVEARTIST 44 /* Waveartist */
36#define SNDCARD_OPL3SA2_MSS 45 /* Originally missed */
37#define SNDCARD_AD1816 88
38
39/*
40 * NOTE! NOTE! NOTE! NOTE!
41 *
42 * If you modify this file, please check the dev_table.c also.
43 *
44 * NOTE! NOTE! NOTE! NOTE!
45 */
46
47struct driver_info
48{
49 char *driver_id;
50 int card_subtype; /* Driver specific. Usually 0 */
51 int card_type; /* From soundcard.h */
52 char *name;
53 void (*attach) (struct address_info *hw_config);
54 int (*probe) (struct address_info *hw_config);
55 void (*unload) (struct address_info *hw_config);
56};
57
58struct card_info
59{
60 int card_type; /* Link (search key) to the driver list */
61 struct address_info config;
62 int enabled;
63 void *for_driver_use;
64};
65
66
67/*
68 * Device specific parameters (used only by dmabuf.c)
69 */
70#define MAX_SUB_BUFFERS (32*MAX_REALTIME_FACTOR)
71
72#define DMODE_NONE 0
73#define DMODE_OUTPUT PCM_ENABLE_OUTPUT
74#define DMODE_INPUT PCM_ENABLE_INPUT
75
76struct dma_buffparms
77{
78 int dma_mode; /* DMODE_INPUT, DMODE_OUTPUT or DMODE_NONE */
79 int closing;
80
81 /*
82 * Pointers to raw buffers
83 */
84
85 char *raw_buf;
86 unsigned long raw_buf_phys;
87 int buffsize;
88
89 /*
90 * Device state tables
91 */
92
93 unsigned long flags;
94#define DMA_BUSY 0x00000001
95#define DMA_RESTART 0x00000002
96#define DMA_ACTIVE 0x00000004
97#define DMA_STARTED 0x00000008
98#define DMA_EMPTY 0x00000010
99#define DMA_ALLOC_DONE 0x00000020
100#define DMA_SYNCING 0x00000040
101#define DMA_DIRTY 0x00000080
102#define DMA_POST 0x00000100
103#define DMA_NODMA 0x00000200
104#define DMA_NOTIMEOUT 0x00000400
105
106 int open_mode;
107
108 /*
109 * Queue parameters.
110 */
111 int qlen;
112 int qhead;
113 int qtail;
114 spinlock_t lock;
115
116 int cfrag; /* Current incomplete fragment (write) */
117
118 int nbufs;
119 int counts[MAX_SUB_BUFFERS];
120 int subdivision;
121
122 int fragment_size;
123 int needs_reorg;
124 int max_fragments;
125
126 int bytes_in_use;
127
128 int underrun_count;
129 unsigned long byte_counter;
130 unsigned long user_counter;
131 unsigned long max_byte_counter;
132 int data_rate; /* Bytes/second */
133
134 int mapping_flags;
135#define DMA_MAP_MAPPED 0x00000001
136 char neutral_byte;
137 int dma; /* DMA channel */
138
139 int applic_profile; /* Application profile (APF_*) */
140 /* Interrupt callback stuff */
141 void (*audio_callback) (int dev, int parm);
142 int callback_parm;
143
144 int buf_flags[MAX_SUB_BUFFERS];
145#define BUFF_EOF 0x00000001 /* Increment eof count */
146#define BUFF_DIRTY 0x00000002 /* Buffer written */
147};
148
149/*
150 * Structure for use with various microcontrollers and DSP processors
151 * in the recent sound cards.
152 */
153typedef struct coproc_operations
154{
155 char name[64];
156 struct module *owner;
157 int (*open) (void *devc, int sub_device);
158 void (*close) (void *devc, int sub_device);
159 int (*ioctl) (void *devc, unsigned int cmd, void __user * arg, int local);
160 void (*reset) (void *devc);
161
162 void *devc; /* Driver specific info */
163} coproc_operations;
164
165struct audio_driver
166{
167 struct module *owner;
168 int (*open) (int dev, int mode);
169 void (*close) (int dev);
170 void (*output_block) (int dev, unsigned long buf,
171 int count, int intrflag);
172 void (*start_input) (int dev, unsigned long buf,
173 int count, int intrflag);
174 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
175 int (*prepare_for_input) (int dev, int bufsize, int nbufs);
176 int (*prepare_for_output) (int dev, int bufsize, int nbufs);
177 void (*halt_io) (int dev);
178 int (*local_qlen)(int dev);
179 void (*copy_user) (int dev,
180 char *localbuf, int localoffs,
181 const char __user *userbuf, int useroffs,
182 int max_in, int max_out,
183 int *used, int *returned,
184 int len);
185 void (*halt_input) (int dev);
186 void (*halt_output) (int dev);
187 void (*trigger) (int dev, int bits);
188 int (*set_speed)(int dev, int speed);
189 unsigned int (*set_bits)(int dev, unsigned int bits);
190 short (*set_channels)(int dev, short channels);
191 void (*postprocess_write)(int dev); /* Device spesific postprocessing for written data */
192 void (*preprocess_read)(int dev); /* Device spesific preprocessing for read data */
193 void (*mmap)(int dev);
194};
195
196struct audio_operations
197{
198 char name[128];
199 int flags;
200#define NOTHING_SPECIAL 0x00
201#define NEEDS_RESTART 0x01
202#define DMA_AUTOMODE 0x02
203#define DMA_DUPLEX 0x04
204#define DMA_PSEUDO_AUTOMODE 0x08
205#define DMA_HARDSTOP 0x10
206#define DMA_EXACT 0x40
207#define DMA_NORESET 0x80
208 int format_mask; /* Bitmask for supported audio formats */
209 void *devc; /* Driver specific info */
210 struct audio_driver *d;
211 void *portc; /* Driver specific info */
212 struct dma_buffparms *dmap_in, *dmap_out;
213 struct coproc_operations *coproc;
214 int mixer_dev;
215 int enable_bits;
216 int open_mode;
217 int go;
218 int min_fragment; /* 0 == unlimited */
219 int max_fragment; /* 0 == unlimited */
220 int parent_dev; /* 0 -> no parent, 1 to n -> parent=parent_dev+1 */
221
222 /* fields formerly in dmabuf.c */
223 wait_queue_head_t in_sleeper;
224 wait_queue_head_t out_sleeper;
225 wait_queue_head_t poll_sleeper;
226
227 /* fields formerly in audio.c */
228 int audio_mode;
229
230#define AM_NONE 0
231#define AM_WRITE OPEN_WRITE
232#define AM_READ OPEN_READ
233
234 int local_format;
235 int audio_format;
236 int local_conversion;
237#define CNV_MU_LAW 0x00000001
238
239 /* large structures at the end to keep offsets small */
240 struct dma_buffparms dmaps[2];
241};
242
243int *load_mixer_volumes(char *name, int *levels, int present);
244
245struct mixer_operations
246{
247 struct module *owner;
248 char id[16];
249 char name[64];
250 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
251
252 void *devc;
253 int modify_counter;
254};
255
256struct synth_operations
257{
258 struct module *owner;
259 char *id; /* Unique identifier (ASCII) max 29 char */
260 struct synth_info *info;
261 int midi_dev;
262 int synth_type;
263 int synth_subtype;
264
265 int (*open) (int dev, int mode);
266 void (*close) (int dev);
267 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
268 int (*kill_note) (int dev, int voice, int note, int velocity);
269 int (*start_note) (int dev, int voice, int note, int velocity);
270 int (*set_instr) (int dev, int voice, int instr);
271 void (*reset) (int dev);
272 void (*hw_control) (int dev, unsigned char *event);
273 int (*load_patch) (int dev, int format, const char __user *addr,
274 int count, int pmgr_flag);
275 void (*aftertouch) (int dev, int voice, int pressure);
276 void (*controller) (int dev, int voice, int ctrl_num, int value);
277 void (*panning) (int dev, int voice, int value);
278 void (*volume_method) (int dev, int mode);
279 void (*bender) (int dev, int chn, int value);
280 int (*alloc_voice) (int dev, int chn, int note, struct voice_alloc_info *alloc);
281 void (*setup_voice) (int dev, int voice, int chn);
282 int (*send_sysex)(int dev, unsigned char *bytes, int len);
283
284 struct voice_alloc_info alloc;
285 struct channel_info chn_info[16];
286 int emulation;
287#define EMU_GM 1 /* General MIDI */
288#define EMU_XG 2 /* Yamaha XG */
289#define MAX_SYSEX_BUF 64
290 unsigned char sysex_buf[MAX_SYSEX_BUF];
291 int sysex_ptr;
292};
293
294struct midi_input_info
295{
296 /* MIDI input scanner variables */
297#define MI_MAX 10
298 volatile int m_busy;
299 unsigned char m_buf[MI_MAX];
300 unsigned char m_prev_status; /* For running status */
301 int m_ptr;
302#define MST_INIT 0
303#define MST_DATA 1
304#define MST_SYSEX 2
305 int m_state;
306 int m_left;
307};
308
309struct midi_operations
310{
311 struct module *owner;
312 struct midi_info info;
313 struct synth_operations *converter;
314 struct midi_input_info in_info;
315 int (*open) (int dev, int mode,
316 void (*inputintr)(int dev, unsigned char data),
317 void (*outputintr)(int dev)
318 );
319 void (*close) (int dev);
320 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
321 int (*outputc) (int dev, unsigned char data);
322 int (*start_read) (int dev);
323 int (*end_read) (int dev);
324 void (*kick)(int dev);
325 int (*command) (int dev, unsigned char *data);
326 int (*buffer_status) (int dev);
327 int (*prefix_cmd) (int dev, unsigned char status);
328 struct coproc_operations *coproc;
329 void *devc;
330};
331
332struct sound_lowlev_timer
333{
334 int dev;
335 int priority;
336 unsigned int (*tmr_start)(int dev, unsigned int usecs);
337 void (*tmr_disable)(int dev);
338 void (*tmr_restart)(int dev);
339};
340
341struct sound_timer_operations
342{
343 struct module *owner;
344 struct sound_timer_info info;
345 int priority;
346 int devlink;
347 int (*open)(int dev, int mode);
348 void (*close)(int dev);
349 int (*event)(int dev, unsigned char *ev);
350 unsigned long (*get_time)(int dev);
351 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
352 void (*arm_timer)(int dev, long time);
353};
354
355extern struct sound_timer_operations default_sound_timer;
356
357extern struct audio_operations *audio_devs[MAX_AUDIO_DEV];
358extern int num_audiodevs;
359extern struct mixer_operations *mixer_devs[MAX_MIXER_DEV];
360extern int num_mixers;
361extern struct synth_operations *synth_devs[MAX_SYNTH_DEV+MAX_MIDI_DEV];
362extern int num_synths;
363extern struct midi_operations *midi_devs[MAX_MIDI_DEV];
364extern int num_midis;
365extern struct sound_timer_operations * sound_timer_devs[MAX_TIMER_DEV];
366extern int num_sound_timers;
367
368extern int sound_map_buffer (int dev, struct dma_buffparms *dmap, buffmem_desc *info);
369void sound_timer_init (struct sound_lowlev_timer *t, char *name);
370void sound_dma_intr (int dev, struct dma_buffparms *dmap, int chan);
371
372#define AUDIO_DRIVER_VERSION 2
373#define MIXER_DRIVER_VERSION 2
374int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
375 int driver_size, int flags, unsigned int format_mask,
376 void *devc, int dma1, int dma2);
377int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
378 int driver_size, void *devc);
379
380void sound_unload_audiodev(int dev);
381void sound_unload_mixerdev(int dev);
382void sound_unload_mididev(int dev);
383void sound_unload_synthdev(int dev);
384void sound_unload_timerdev(int dev);
385int sound_alloc_mixerdev(void);
386int sound_alloc_timerdev(void);
387int sound_alloc_synthdev(void);
388int sound_alloc_mididev(void);
389#endif /* _DEV_TABLE_H_ */
390
diff --git a/sound/oss/dmabuf.c b/sound/oss/dmabuf.c
deleted file mode 100644
index c5dd396c66a2..000000000000
--- a/sound/oss/dmabuf.c
+++ /dev/null
@@ -1,1268 +0,0 @@
1/*
2 * sound/oss/dmabuf.c
3 *
4 * The DMA buffer manager for digitized voice applications
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 * Thomas Sailer : moved several static variables into struct audio_operations
14 * (which is grossly misnamed btw.) because they have the same
15 * lifetime as the rest in there and dynamic allocation saves
16 * 12k or so
17 * Thomas Sailer : remove {in,out}_sleep_flag. It was used for the sleeper to
18 * determine if it was woken up by the expiring timeout or by
19 * an explicit wake_up. The return value from schedule_timeout
20 * can be used instead; if 0, the wakeup was due to the timeout.
21 *
22 * Rob Riggs Added persistent DMA buffers (1998/10/17)
23 */
24
25#define BE_CONSERVATIVE
26#define SAMPLE_ROUNDUP 0
27
28#include <linux/mm.h>
29#include <linux/gfp.h>
30#include <linux/sched/signal.h>
31
32#include "sound_config.h"
33#include "sleep.h"
34
35#define DMAP_FREE_ON_CLOSE 0
36#define DMAP_KEEP_ON_CLOSE 1
37extern int sound_dmap_flag;
38
39static void dma_reset_output(int dev);
40static void dma_reset_input(int dev);
41static int local_start_dma(struct audio_operations *adev, unsigned long physaddr, int count, int dma_mode);
42
43
44
45static int debugmem; /* switched off by default */
46static int dma_buffsize = DSP_BUFFSIZE;
47
48static long dmabuf_timeout(struct dma_buffparms *dmap)
49{
50 long tmout;
51
52 tmout = (dmap->fragment_size * HZ) / dmap->data_rate;
53 tmout += HZ / 5; /* Some safety distance */
54 if (tmout < (HZ / 2))
55 tmout = HZ / 2;
56 if (tmout > 20 * HZ)
57 tmout = 20 * HZ;
58 return tmout;
59}
60
61static int sound_alloc_dmap(struct dma_buffparms *dmap)
62{
63 char *start_addr, *end_addr;
64 int dma_pagesize;
65 int sz, size;
66 struct page *page;
67
68 dmap->mapping_flags &= ~DMA_MAP_MAPPED;
69
70 if (dmap->raw_buf != NULL)
71 return 0; /* Already done */
72 if (dma_buffsize < 4096)
73 dma_buffsize = 4096;
74 dma_pagesize = (dmap->dma < 4) ? (64 * 1024) : (128 * 1024);
75
76 /*
77 * Now check for the Cyrix problem.
78 */
79
80 if(isa_dma_bridge_buggy==2)
81 dma_pagesize=32768;
82
83 dmap->raw_buf = NULL;
84 dmap->buffsize = dma_buffsize;
85 if (dmap->buffsize > dma_pagesize)
86 dmap->buffsize = dma_pagesize;
87 start_addr = NULL;
88 /*
89 * Now loop until we get a free buffer. Try to get smaller buffer if
90 * it fails. Don't accept smaller than 8k buffer for performance
91 * reasons.
92 */
93 while (start_addr == NULL && dmap->buffsize > PAGE_SIZE) {
94 for (sz = 0, size = PAGE_SIZE; size < dmap->buffsize; sz++, size <<= 1);
95 dmap->buffsize = PAGE_SIZE * (1 << sz);
96 start_addr = (char *) __get_free_pages(GFP_ATOMIC|GFP_DMA|__GFP_NOWARN, sz);
97 if (start_addr == NULL)
98 dmap->buffsize /= 2;
99 }
100
101 if (start_addr == NULL) {
102 printk(KERN_WARNING "Sound error: Couldn't allocate DMA buffer\n");
103 return -ENOMEM;
104 } else {
105 /* make some checks */
106 end_addr = start_addr + dmap->buffsize - 1;
107
108 if (debugmem)
109 printk(KERN_DEBUG "sound: start 0x%lx, end 0x%lx\n", (long) start_addr, (long) end_addr);
110
111 /* now check if it fits into the same dma-pagesize */
112
113 if (((long) start_addr & ~(dma_pagesize - 1)) != ((long) end_addr & ~(dma_pagesize - 1))
114 || end_addr >= (char *) (MAX_DMA_ADDRESS)) {
115 printk(KERN_ERR "sound: Got invalid address 0x%lx for %db DMA-buffer\n", (long) start_addr, dmap->buffsize);
116 return -EFAULT;
117 }
118 }
119 dmap->raw_buf = start_addr;
120 dmap->raw_buf_phys = dma_map_single(NULL, start_addr, dmap->buffsize, DMA_BIDIRECTIONAL);
121
122 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
123 SetPageReserved(page);
124 return 0;
125}
126
127static void sound_free_dmap(struct dma_buffparms *dmap)
128{
129 int sz, size;
130 struct page *page;
131 unsigned long start_addr, end_addr;
132
133 if (dmap->raw_buf == NULL)
134 return;
135 if (dmap->mapping_flags & DMA_MAP_MAPPED)
136 return; /* Don't free mmapped buffer. Will use it next time */
137 for (sz = 0, size = PAGE_SIZE; size < dmap->buffsize; sz++, size <<= 1);
138
139 start_addr = (unsigned long) dmap->raw_buf;
140 end_addr = start_addr + dmap->buffsize;
141
142 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
143 ClearPageReserved(page);
144
145 dma_unmap_single(NULL, dmap->raw_buf_phys, dmap->buffsize, DMA_BIDIRECTIONAL);
146 free_pages((unsigned long) dmap->raw_buf, sz);
147 dmap->raw_buf = NULL;
148}
149
150
151/* Intel version !!!!!!!!! */
152
153static int sound_start_dma(struct dma_buffparms *dmap, unsigned long physaddr, int count, int dma_mode)
154{
155 unsigned long flags;
156 int chan = dmap->dma;
157
158 /* printk( "Start DMA%d %d, %d\n", chan, (int)(physaddr-dmap->raw_buf_phys), count); */
159
160 flags = claim_dma_lock();
161 disable_dma(chan);
162 clear_dma_ff(chan);
163 set_dma_mode(chan, dma_mode);
164 set_dma_addr(chan, physaddr);
165 set_dma_count(chan, count);
166 enable_dma(chan);
167 release_dma_lock(flags);
168
169 return 0;
170}
171
172static void dma_init_buffers(struct dma_buffparms *dmap)
173{
174 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
175 dmap->byte_counter = 0;
176 dmap->max_byte_counter = 8000 * 60 * 60;
177 dmap->bytes_in_use = dmap->buffsize;
178
179 dmap->dma_mode = DMODE_NONE;
180 dmap->mapping_flags = 0;
181 dmap->neutral_byte = 0x80;
182 dmap->data_rate = 8000;
183 dmap->cfrag = -1;
184 dmap->closing = 0;
185 dmap->nbufs = 1;
186 dmap->flags = DMA_BUSY; /* Other flags off */
187}
188
189static int open_dmap(struct audio_operations *adev, int mode, struct dma_buffparms *dmap)
190{
191 int err;
192
193 if (dmap->flags & DMA_BUSY)
194 return -EBUSY;
195 if ((err = sound_alloc_dmap(dmap)) < 0)
196 return err;
197
198 if (dmap->raw_buf == NULL) {
199 printk(KERN_WARNING "Sound: DMA buffers not available\n");
200 return -ENOSPC; /* Memory allocation failed during boot */
201 }
202 if (dmap->dma >= 0 && sound_open_dma(dmap->dma, adev->name)) {
203 printk(KERN_WARNING "Unable to grab(2) DMA%d for the audio driver\n", dmap->dma);
204 return -EBUSY;
205 }
206 dma_init_buffers(dmap);
207 spin_lock_init(&dmap->lock);
208 dmap->open_mode = mode;
209 dmap->subdivision = dmap->underrun_count = 0;
210 dmap->fragment_size = 0;
211 dmap->max_fragments = 65536; /* Just a large value */
212 dmap->byte_counter = 0;
213 dmap->max_byte_counter = 8000 * 60 * 60;
214 dmap->applic_profile = APF_NORMAL;
215 dmap->needs_reorg = 1;
216 dmap->audio_callback = NULL;
217 dmap->callback_parm = 0;
218 return 0;
219}
220
221static void close_dmap(struct audio_operations *adev, struct dma_buffparms *dmap)
222{
223 unsigned long flags;
224
225 if (dmap->dma >= 0) {
226 sound_close_dma(dmap->dma);
227 flags=claim_dma_lock();
228 disable_dma(dmap->dma);
229 release_dma_lock(flags);
230 }
231 if (dmap->flags & DMA_BUSY)
232 dmap->dma_mode = DMODE_NONE;
233 dmap->flags &= ~DMA_BUSY;
234
235 if (sound_dmap_flag == DMAP_FREE_ON_CLOSE)
236 sound_free_dmap(dmap);
237}
238
239
240static unsigned int default_set_bits(int dev, unsigned int bits)
241{
242 mm_segment_t fs = get_fs();
243
244 set_fs(get_ds());
245 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_SETFMT, (void __user *)&bits);
246 set_fs(fs);
247 return bits;
248}
249
250static int default_set_speed(int dev, int speed)
251{
252 mm_segment_t fs = get_fs();
253
254 set_fs(get_ds());
255 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_SPEED, (void __user *)&speed);
256 set_fs(fs);
257 return speed;
258}
259
260static short default_set_channels(int dev, short channels)
261{
262 int c = channels;
263 mm_segment_t fs = get_fs();
264
265 set_fs(get_ds());
266 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_CHANNELS, (void __user *)&c);
267 set_fs(fs);
268 return c;
269}
270
271static void check_driver(struct audio_driver *d)
272{
273 if (d->set_speed == NULL)
274 d->set_speed = default_set_speed;
275 if (d->set_bits == NULL)
276 d->set_bits = default_set_bits;
277 if (d->set_channels == NULL)
278 d->set_channels = default_set_channels;
279}
280
281int DMAbuf_open(int dev, int mode)
282{
283 struct audio_operations *adev = audio_devs[dev];
284 int retval;
285 struct dma_buffparms *dmap_in = NULL;
286 struct dma_buffparms *dmap_out = NULL;
287
288 if (!adev)
289 return -ENXIO;
290 if (!(adev->flags & DMA_DUPLEX))
291 adev->dmap_in = adev->dmap_out;
292 check_driver(adev->d);
293
294 if ((retval = adev->d->open(dev, mode)) < 0)
295 return retval;
296 dmap_out = adev->dmap_out;
297 dmap_in = adev->dmap_in;
298 if (dmap_in == dmap_out)
299 adev->flags &= ~DMA_DUPLEX;
300
301 if (mode & OPEN_WRITE) {
302 if ((retval = open_dmap(adev, mode, dmap_out)) < 0) {
303 adev->d->close(dev);
304 return retval;
305 }
306 }
307 adev->enable_bits = mode;
308
309 if (mode == OPEN_READ || (mode != OPEN_WRITE && (adev->flags & DMA_DUPLEX))) {
310 if ((retval = open_dmap(adev, mode, dmap_in)) < 0) {
311 adev->d->close(dev);
312 if (mode & OPEN_WRITE)
313 close_dmap(adev, dmap_out);
314 return retval;
315 }
316 }
317 adev->open_mode = mode;
318 adev->go = 1;
319
320 adev->d->set_bits(dev, 8);
321 adev->d->set_channels(dev, 1);
322 adev->d->set_speed(dev, DSP_DEFAULT_SPEED);
323 if (adev->dmap_out->dma_mode == DMODE_OUTPUT)
324 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte,
325 adev->dmap_out->bytes_in_use);
326 return 0;
327}
328/* MUST not hold the spinlock */
329void DMAbuf_reset(int dev)
330{
331 if (audio_devs[dev]->open_mode & OPEN_WRITE)
332 dma_reset_output(dev);
333
334 if (audio_devs[dev]->open_mode & OPEN_READ)
335 dma_reset_input(dev);
336}
337
338static void dma_reset_output(int dev)
339{
340 struct audio_operations *adev = audio_devs[dev];
341 unsigned long flags,f ;
342 struct dma_buffparms *dmap = adev->dmap_out;
343
344 if (!(dmap->flags & DMA_STARTED)) /* DMA is not active */
345 return;
346
347 /*
348 * First wait until the current fragment has been played completely
349 */
350 spin_lock_irqsave(&dmap->lock,flags);
351 adev->dmap_out->flags |= DMA_SYNCING;
352
353 adev->dmap_out->underrun_count = 0;
354 if (!signal_pending(current) && adev->dmap_out->qlen &&
355 adev->dmap_out->underrun_count == 0){
356 spin_unlock_irqrestore(&dmap->lock,flags);
357 oss_broken_sleep_on(&adev->out_sleeper, dmabuf_timeout(dmap));
358 spin_lock_irqsave(&dmap->lock,flags);
359 }
360 adev->dmap_out->flags &= ~(DMA_SYNCING | DMA_ACTIVE);
361
362 /*
363 * Finally shut the device off
364 */
365 if (!(adev->flags & DMA_DUPLEX) || !adev->d->halt_output)
366 adev->d->halt_io(dev);
367 else
368 adev->d->halt_output(dev);
369 adev->dmap_out->flags &= ~DMA_STARTED;
370
371 f=claim_dma_lock();
372 clear_dma_ff(dmap->dma);
373 disable_dma(dmap->dma);
374 release_dma_lock(f);
375
376 dmap->byte_counter = 0;
377 reorganize_buffers(dev, adev->dmap_out, 0);
378 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
379 spin_unlock_irqrestore(&dmap->lock,flags);
380}
381
382static void dma_reset_input(int dev)
383{
384 struct audio_operations *adev = audio_devs[dev];
385 unsigned long flags;
386 struct dma_buffparms *dmap = adev->dmap_in;
387
388 spin_lock_irqsave(&dmap->lock,flags);
389 if (!(adev->flags & DMA_DUPLEX) || !adev->d->halt_input)
390 adev->d->halt_io(dev);
391 else
392 adev->d->halt_input(dev);
393 adev->dmap_in->flags &= ~DMA_STARTED;
394
395 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
396 dmap->byte_counter = 0;
397 reorganize_buffers(dev, adev->dmap_in, 1);
398 spin_unlock_irqrestore(&dmap->lock,flags);
399}
400/* MUST be called with holding the dmap->lock */
401void DMAbuf_launch_output(int dev, struct dma_buffparms *dmap)
402{
403 struct audio_operations *adev = audio_devs[dev];
404
405 if (!((adev->enable_bits * adev->go) & PCM_ENABLE_OUTPUT))
406 return; /* Don't start DMA yet */
407 dmap->dma_mode = DMODE_OUTPUT;
408
409 if (!(dmap->flags & DMA_ACTIVE) || !(adev->flags & DMA_AUTOMODE) || (dmap->flags & DMA_NODMA)) {
410 if (!(dmap->flags & DMA_STARTED)) {
411 reorganize_buffers(dev, dmap, 0);
412 if (adev->d->prepare_for_output(dev, dmap->fragment_size, dmap->nbufs))
413 return;
414 if (!(dmap->flags & DMA_NODMA))
415 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use,DMA_MODE_WRITE);
416 dmap->flags |= DMA_STARTED;
417 }
418 if (dmap->counts[dmap->qhead] == 0)
419 dmap->counts[dmap->qhead] = dmap->fragment_size;
420 dmap->dma_mode = DMODE_OUTPUT;
421 adev->d->output_block(dev, dmap->raw_buf_phys + dmap->qhead * dmap->fragment_size,
422 dmap->counts[dmap->qhead], 1);
423 if (adev->d->trigger)
424 adev->d->trigger(dev,adev->enable_bits * adev->go);
425 }
426 dmap->flags |= DMA_ACTIVE;
427}
428
429int DMAbuf_sync(int dev)
430{
431 struct audio_operations *adev = audio_devs[dev];
432 unsigned long flags;
433 int n = 0;
434 struct dma_buffparms *dmap;
435
436 if (!adev->go && !(adev->enable_bits & PCM_ENABLE_OUTPUT))
437 return 0;
438
439 if (adev->dmap_out->dma_mode == DMODE_OUTPUT) {
440 dmap = adev->dmap_out;
441 spin_lock_irqsave(&dmap->lock,flags);
442 if (dmap->qlen > 0 && !(dmap->flags & DMA_ACTIVE))
443 DMAbuf_launch_output(dev, dmap);
444 adev->dmap_out->flags |= DMA_SYNCING;
445 adev->dmap_out->underrun_count = 0;
446 while (!signal_pending(current) && n++ < adev->dmap_out->nbufs &&
447 adev->dmap_out->qlen && adev->dmap_out->underrun_count == 0) {
448 long t = dmabuf_timeout(dmap);
449 spin_unlock_irqrestore(&dmap->lock,flags);
450 /* FIXME: not safe may miss events */
451 t = oss_broken_sleep_on(&adev->out_sleeper, t);
452 spin_lock_irqsave(&dmap->lock,flags);
453 if (!t) {
454 adev->dmap_out->flags &= ~DMA_SYNCING;
455 spin_unlock_irqrestore(&dmap->lock,flags);
456 return adev->dmap_out->qlen;
457 }
458 }
459 adev->dmap_out->flags &= ~(DMA_SYNCING | DMA_ACTIVE);
460
461 /*
462 * Some devices such as GUS have huge amount of on board RAM for the
463 * audio data. We have to wait until the device has finished playing.
464 */
465
466 /* still holding the lock */
467 if (adev->d->local_qlen) { /* Device has hidden buffers */
468 while (!signal_pending(current) &&
469 adev->d->local_qlen(dev)){
470 spin_unlock_irqrestore(&dmap->lock,flags);
471 oss_broken_sleep_on(&adev->out_sleeper,
472 dmabuf_timeout(dmap));
473 spin_lock_irqsave(&dmap->lock,flags);
474 }
475 }
476 spin_unlock_irqrestore(&dmap->lock,flags);
477 }
478 adev->dmap_out->dma_mode = DMODE_NONE;
479 return adev->dmap_out->qlen;
480}
481
482int DMAbuf_release(int dev, int mode)
483{
484 struct audio_operations *adev = audio_devs[dev];
485 struct dma_buffparms *dmap;
486 unsigned long flags;
487
488 dmap = adev->dmap_out;
489 if (adev->open_mode & OPEN_WRITE)
490 adev->dmap_out->closing = 1;
491
492 if (adev->open_mode & OPEN_READ){
493 adev->dmap_in->closing = 1;
494 dmap = adev->dmap_in;
495 }
496 if (adev->open_mode & OPEN_WRITE)
497 if (!(adev->dmap_out->mapping_flags & DMA_MAP_MAPPED))
498 if (!signal_pending(current) && (adev->dmap_out->dma_mode == DMODE_OUTPUT))
499 DMAbuf_sync(dev);
500 if (adev->dmap_out->dma_mode == DMODE_OUTPUT)
501 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte, adev->dmap_out->bytes_in_use);
502
503 DMAbuf_reset(dev);
504 spin_lock_irqsave(&dmap->lock,flags);
505 adev->d->close(dev);
506
507 if (adev->open_mode & OPEN_WRITE)
508 close_dmap(adev, adev->dmap_out);
509
510 if (adev->open_mode == OPEN_READ ||
511 (adev->open_mode != OPEN_WRITE &&
512 (adev->flags & DMA_DUPLEX)))
513 close_dmap(adev, adev->dmap_in);
514 adev->open_mode = 0;
515 spin_unlock_irqrestore(&dmap->lock,flags);
516 return 0;
517}
518/* called with dmap->lock dold */
519int DMAbuf_activate_recording(int dev, struct dma_buffparms *dmap)
520{
521 struct audio_operations *adev = audio_devs[dev];
522 int err;
523
524 if (!(adev->open_mode & OPEN_READ))
525 return 0;
526 if (!(adev->enable_bits & PCM_ENABLE_INPUT))
527 return 0;
528 if (dmap->dma_mode == DMODE_OUTPUT) { /* Direction change */
529 /* release lock - it's not recursive */
530 spin_unlock_irq(&dmap->lock);
531 DMAbuf_sync(dev);
532 DMAbuf_reset(dev);
533 spin_lock_irq(&dmap->lock);
534 dmap->dma_mode = DMODE_NONE;
535 }
536 if (!dmap->dma_mode) {
537 reorganize_buffers(dev, dmap, 1);
538 if ((err = adev->d->prepare_for_input(dev,
539 dmap->fragment_size, dmap->nbufs)) < 0)
540 return err;
541 dmap->dma_mode = DMODE_INPUT;
542 }
543 if (!(dmap->flags & DMA_ACTIVE)) {
544 if (dmap->needs_reorg)
545 reorganize_buffers(dev, dmap, 0);
546 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use, DMA_MODE_READ);
547 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size,
548 dmap->fragment_size, 0);
549 dmap->flags |= DMA_ACTIVE;
550 if (adev->d->trigger)
551 adev->d->trigger(dev, adev->enable_bits * adev->go);
552 }
553 return 0;
554}
555/* acquires lock */
556int DMAbuf_getrdbuffer(int dev, char **buf, int *len, int dontblock)
557{
558 struct audio_operations *adev = audio_devs[dev];
559 unsigned long flags;
560 int err = 0, n = 0;
561 struct dma_buffparms *dmap = adev->dmap_in;
562
563 if (!(adev->open_mode & OPEN_READ))
564 return -EIO;
565 spin_lock_irqsave(&dmap->lock,flags);
566 if (dmap->needs_reorg)
567 reorganize_buffers(dev, dmap, 0);
568 if (adev->dmap_in->mapping_flags & DMA_MAP_MAPPED) {
569/* printk(KERN_WARNING "Sound: Can't read from mmapped device (1)\n");*/
570 spin_unlock_irqrestore(&dmap->lock,flags);
571 return -EINVAL;
572 } else while (dmap->qlen <= 0 && n++ < 10) {
573 long timeout = MAX_SCHEDULE_TIMEOUT;
574 if (!(adev->enable_bits & PCM_ENABLE_INPUT) || !adev->go) {
575 spin_unlock_irqrestore(&dmap->lock,flags);
576 return -EAGAIN;
577 }
578 if ((err = DMAbuf_activate_recording(dev, dmap)) < 0) {
579 spin_unlock_irqrestore(&dmap->lock,flags);
580 return err;
581 }
582 /* Wait for the next block */
583
584 if (dontblock) {
585 spin_unlock_irqrestore(&dmap->lock,flags);
586 return -EAGAIN;
587 }
588 if (adev->go)
589 timeout = dmabuf_timeout(dmap);
590
591 spin_unlock_irqrestore(&dmap->lock,flags);
592 timeout = oss_broken_sleep_on(&adev->in_sleeper, timeout);
593 if (!timeout) {
594 /* FIXME: include device name */
595 err = -EIO;
596 printk(KERN_WARNING "Sound: DMA (input) timed out - IRQ/DRQ config error?\n");
597 dma_reset_input(dev);
598 } else
599 err = -EINTR;
600 spin_lock_irqsave(&dmap->lock,flags);
601 }
602 spin_unlock_irqrestore(&dmap->lock,flags);
603
604 if (dmap->qlen <= 0)
605 return err ? err : -EINTR;
606 *buf = &dmap->raw_buf[dmap->qhead * dmap->fragment_size + dmap->counts[dmap->qhead]];
607 *len = dmap->fragment_size - dmap->counts[dmap->qhead];
608
609 return dmap->qhead;
610}
611
612int DMAbuf_rmchars(int dev, int buff_no, int c)
613{
614 struct audio_operations *adev = audio_devs[dev];
615 struct dma_buffparms *dmap = adev->dmap_in;
616 int p = dmap->counts[dmap->qhead] + c;
617
618 if (dmap->mapping_flags & DMA_MAP_MAPPED)
619 {
620/* printk("Sound: Can't read from mmapped device (2)\n");*/
621 return -EINVAL;
622 }
623 else if (dmap->qlen <= 0)
624 return -EIO;
625 else if (p >= dmap->fragment_size) { /* This buffer is completely empty */
626 dmap->counts[dmap->qhead] = 0;
627 dmap->qlen--;
628 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
629 }
630 else dmap->counts[dmap->qhead] = p;
631
632 return 0;
633}
634/* MUST be called with dmap->lock hold */
635int DMAbuf_get_buffer_pointer(int dev, struct dma_buffparms *dmap, int direction)
636{
637 /*
638 * Try to approximate the active byte position of the DMA pointer within the
639 * buffer area as well as possible.
640 */
641
642 int pos;
643 unsigned long f;
644
645 if (!(dmap->flags & DMA_ACTIVE))
646 pos = 0;
647 else {
648 int chan = dmap->dma;
649
650 f=claim_dma_lock();
651 clear_dma_ff(chan);
652
653 if(!isa_dma_bridge_buggy)
654 disable_dma(dmap->dma);
655
656 pos = get_dma_residue(chan);
657
658 pos = dmap->bytes_in_use - pos;
659
660 if (!(dmap->mapping_flags & DMA_MAP_MAPPED)) {
661 if (direction == DMODE_OUTPUT) {
662 if (dmap->qhead == 0)
663 if (pos > dmap->fragment_size)
664 pos = 0;
665 } else {
666 if (dmap->qtail == 0)
667 if (pos > dmap->fragment_size)
668 pos = 0;
669 }
670 }
671 if (pos < 0)
672 pos = 0;
673 if (pos >= dmap->bytes_in_use)
674 pos = 0;
675
676 if(!isa_dma_bridge_buggy)
677 enable_dma(dmap->dma);
678
679 release_dma_lock(f);
680 }
681 /* printk( "%04x ", pos); */
682
683 return pos;
684}
685
686/*
687 * DMAbuf_start_devices() is called by the /dev/music driver to start
688 * one or more audio devices at desired moment.
689 */
690
691void DMAbuf_start_devices(unsigned int devmask)
692{
693 struct audio_operations *adev;
694 int dev;
695
696 for (dev = 0; dev < num_audiodevs; dev++) {
697 if (!(devmask & (1 << dev)))
698 continue;
699 if (!(adev = audio_devs[dev]))
700 continue;
701 if (adev->open_mode == 0)
702 continue;
703 if (adev->go)
704 continue;
705 /* OK to start the device */
706 adev->go = 1;
707 if (adev->d->trigger)
708 adev->d->trigger(dev,adev->enable_bits * adev->go);
709 }
710}
711/* via poll called without a lock ?*/
712int DMAbuf_space_in_queue(int dev)
713{
714 struct audio_operations *adev = audio_devs[dev];
715 int len, max, tmp;
716 struct dma_buffparms *dmap = adev->dmap_out;
717 int lim = dmap->nbufs;
718
719 if (lim < 2)
720 lim = 2;
721
722 if (dmap->qlen >= lim) /* No space at all */
723 return 0;
724
725 /*
726 * Verify that there are no more pending buffers than the limit
727 * defined by the process.
728 */
729
730 max = dmap->max_fragments;
731 if (max > lim)
732 max = lim;
733 len = dmap->qlen;
734
735 if (adev->d->local_qlen) {
736 tmp = adev->d->local_qlen(dev);
737 if (tmp && len)
738 tmp--; /* This buffer has been counted twice */
739 len += tmp;
740 }
741 if (dmap->byte_counter % dmap->fragment_size) /* There is a partial fragment */
742 len = len + 1;
743
744 if (len >= max)
745 return 0;
746 return max - len;
747}
748/* MUST not hold the spinlock - this function may sleep */
749static int output_sleep(int dev, int dontblock)
750{
751 struct audio_operations *adev = audio_devs[dev];
752 int err = 0;
753 struct dma_buffparms *dmap = adev->dmap_out;
754 long timeout;
755 long timeout_value;
756
757 if (dontblock)
758 return -EAGAIN;
759 if (!(adev->enable_bits & PCM_ENABLE_OUTPUT))
760 return -EAGAIN;
761
762 /*
763 * Wait for free space
764 */
765 if (signal_pending(current))
766 return -EINTR;
767 timeout = (adev->go && !(dmap->flags & DMA_NOTIMEOUT));
768 if (timeout)
769 timeout_value = dmabuf_timeout(dmap);
770 else
771 timeout_value = MAX_SCHEDULE_TIMEOUT;
772 timeout_value = oss_broken_sleep_on(&adev->out_sleeper, timeout_value);
773 if (timeout != MAX_SCHEDULE_TIMEOUT && !timeout_value) {
774 printk(KERN_WARNING "Sound: DMA (output) timed out - IRQ/DRQ config error?\n");
775 dma_reset_output(dev);
776 } else {
777 if (signal_pending(current))
778 err = -EINTR;
779 }
780 return err;
781}
782/* called with the lock held */
783static int find_output_space(int dev, char **buf, int *size)
784{
785 struct audio_operations *adev = audio_devs[dev];
786 struct dma_buffparms *dmap = adev->dmap_out;
787 unsigned long active_offs;
788 long len, offs;
789 int maxfrags;
790 int occupied_bytes = (dmap->user_counter % dmap->fragment_size);
791
792 *buf = dmap->raw_buf;
793 if (!(maxfrags = DMAbuf_space_in_queue(dev)) && !occupied_bytes)
794 return 0;
795
796#ifdef BE_CONSERVATIVE
797 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size;
798#else
799 active_offs = max(DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT), 0);
800 /* Check for pointer wrapping situation */
801 if (active_offs >= dmap->bytes_in_use)
802 active_offs = 0;
803 active_offs += dmap->byte_counter;
804#endif
805
806 offs = (dmap->user_counter % dmap->bytes_in_use) & ~SAMPLE_ROUNDUP;
807 if (offs < 0 || offs >= dmap->bytes_in_use) {
808 printk(KERN_ERR "Sound: Got unexpected offs %ld. Giving up.\n", offs);
809 printk("Counter = %ld, bytes=%d\n", dmap->user_counter, dmap->bytes_in_use);
810 return 0;
811 }
812 *buf = dmap->raw_buf + offs;
813
814 len = active_offs + dmap->bytes_in_use - dmap->user_counter; /* Number of unused bytes in buffer */
815
816 if ((offs + len) > dmap->bytes_in_use)
817 len = dmap->bytes_in_use - offs;
818 if (len < 0) {
819 return 0;
820 }
821 if (len > ((maxfrags * dmap->fragment_size) - occupied_bytes))
822 len = (maxfrags * dmap->fragment_size) - occupied_bytes;
823 *size = len & ~SAMPLE_ROUNDUP;
824 return (*size > 0);
825}
826/* acquires lock */
827int DMAbuf_getwrbuffer(int dev, char **buf, int *size, int dontblock)
828{
829 struct audio_operations *adev = audio_devs[dev];
830 unsigned long flags;
831 int err = -EIO;
832 struct dma_buffparms *dmap = adev->dmap_out;
833
834 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
835/* printk(KERN_DEBUG "Sound: Can't write to mmapped device (3)\n");*/
836 return -EINVAL;
837 }
838 spin_lock_irqsave(&dmap->lock,flags);
839 if (dmap->needs_reorg)
840 reorganize_buffers(dev, dmap, 0);
841
842 if (dmap->dma_mode == DMODE_INPUT) { /* Direction change */
843 spin_unlock_irqrestore(&dmap->lock,flags);
844 DMAbuf_reset(dev);
845 spin_lock_irqsave(&dmap->lock,flags);
846 }
847 dmap->dma_mode = DMODE_OUTPUT;
848
849 while (find_output_space(dev, buf, size) <= 0) {
850 spin_unlock_irqrestore(&dmap->lock,flags);
851 if ((err = output_sleep(dev, dontblock)) < 0) {
852 return err;
853 }
854 spin_lock_irqsave(&dmap->lock,flags);
855 }
856
857 spin_unlock_irqrestore(&dmap->lock,flags);
858 return 0;
859}
860/* has to acquire dmap->lock */
861int DMAbuf_move_wrpointer(int dev, int l)
862{
863 struct audio_operations *adev = audio_devs[dev];
864 struct dma_buffparms *dmap = adev->dmap_out;
865 unsigned long ptr;
866 unsigned long end_ptr, p;
867 int post;
868 unsigned long flags;
869
870 spin_lock_irqsave(&dmap->lock,flags);
871 post= (dmap->flags & DMA_POST);
872 ptr = (dmap->user_counter / dmap->fragment_size) * dmap->fragment_size;
873
874 dmap->flags &= ~DMA_POST;
875 dmap->cfrag = -1;
876 dmap->user_counter += l;
877 dmap->flags |= DMA_DIRTY;
878
879 if (dmap->byte_counter >= dmap->max_byte_counter) {
880 /* Wrap the byte counters */
881 long decr = dmap->byte_counter;
882 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
883 decr -= dmap->byte_counter;
884 dmap->user_counter -= decr;
885 }
886 end_ptr = (dmap->user_counter / dmap->fragment_size) * dmap->fragment_size;
887
888 p = (dmap->user_counter - 1) % dmap->bytes_in_use;
889 dmap->neutral_byte = dmap->raw_buf[p];
890
891 /* Update the fragment based bookkeeping too */
892 while (ptr < end_ptr) {
893 dmap->counts[dmap->qtail] = dmap->fragment_size;
894 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
895 dmap->qlen++;
896 ptr += dmap->fragment_size;
897 }
898
899 dmap->counts[dmap->qtail] = dmap->user_counter - ptr;
900
901 /*
902 * Let the low level driver perform some postprocessing to
903 * the written data.
904 */
905 if (adev->d->postprocess_write)
906 adev->d->postprocess_write(dev);
907
908 if (!(dmap->flags & DMA_ACTIVE))
909 if (dmap->qlen > 1 || (dmap->qlen > 0 && (post || dmap->qlen >= dmap->nbufs - 1)))
910 DMAbuf_launch_output(dev, dmap);
911
912 spin_unlock_irqrestore(&dmap->lock,flags);
913 return 0;
914}
915
916int DMAbuf_start_dma(int dev, unsigned long physaddr, int count, int dma_mode)
917{
918 struct audio_operations *adev = audio_devs[dev];
919 struct dma_buffparms *dmap = (dma_mode == DMA_MODE_WRITE) ? adev->dmap_out : adev->dmap_in;
920
921 if (dmap->raw_buf == NULL) {
922 printk(KERN_ERR "sound: DMA buffer(1) == NULL\n");
923 printk("Device %d, chn=%s\n", dev, (dmap == adev->dmap_out) ? "out" : "in");
924 return 0;
925 }
926 if (dmap->dma < 0)
927 return 0;
928 sound_start_dma(dmap, physaddr, count, dma_mode);
929 return count;
930}
931EXPORT_SYMBOL(DMAbuf_start_dma);
932
933static int local_start_dma(struct audio_operations *adev, unsigned long physaddr, int count, int dma_mode)
934{
935 struct dma_buffparms *dmap = (dma_mode == DMA_MODE_WRITE) ? adev->dmap_out : adev->dmap_in;
936
937 if (dmap->raw_buf == NULL) {
938 printk(KERN_ERR "sound: DMA buffer(2) == NULL\n");
939 printk(KERN_ERR "Device %s, chn=%s\n", adev->name, (dmap == adev->dmap_out) ? "out" : "in");
940 return 0;
941 }
942 if (dmap->flags & DMA_NODMA)
943 return 1;
944 if (dmap->dma < 0)
945 return 0;
946 sound_start_dma(dmap, dmap->raw_buf_phys, dmap->bytes_in_use, dma_mode | DMA_AUTOINIT);
947 dmap->flags |= DMA_STARTED;
948 return count;
949}
950
951static void finish_output_interrupt(int dev, struct dma_buffparms *dmap)
952{
953 struct audio_operations *adev = audio_devs[dev];
954
955 if (dmap->audio_callback != NULL)
956 dmap->audio_callback(dev, dmap->callback_parm);
957 wake_up(&adev->out_sleeper);
958 wake_up(&adev->poll_sleeper);
959}
960/* called with dmap->lock held in irq context*/
961static void do_outputintr(int dev, int dummy)
962{
963 struct audio_operations *adev = audio_devs[dev];
964 struct dma_buffparms *dmap = adev->dmap_out;
965 int this_fragment;
966
967 if (dmap->raw_buf == NULL) {
968 printk(KERN_ERR "Sound: Error. Audio interrupt (%d) after freeing buffers.\n", dev);
969 return;
970 }
971 if (dmap->mapping_flags & DMA_MAP_MAPPED) { /* Virtual memory mapped access */
972 /* mmapped access */
973 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
974 if (dmap->qhead == 0) { /* Wrapped */
975 dmap->byte_counter += dmap->bytes_in_use;
976 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
977 long decr = dmap->byte_counter;
978 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
979 decr -= dmap->byte_counter;
980 dmap->user_counter -= decr;
981 }
982 }
983 dmap->qlen++; /* Yes increment it (don't decrement) */
984 if (!(adev->flags & DMA_AUTOMODE))
985 dmap->flags &= ~DMA_ACTIVE;
986 dmap->counts[dmap->qhead] = dmap->fragment_size;
987 DMAbuf_launch_output(dev, dmap);
988 finish_output_interrupt(dev, dmap);
989 return;
990 }
991
992 dmap->qlen--;
993 this_fragment = dmap->qhead;
994 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
995
996 if (dmap->qhead == 0) { /* Wrapped */
997 dmap->byte_counter += dmap->bytes_in_use;
998 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
999 long decr = dmap->byte_counter;
1000 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
1001 decr -= dmap->byte_counter;
1002 dmap->user_counter -= decr;
1003 }
1004 }
1005 if (!(adev->flags & DMA_AUTOMODE))
1006 dmap->flags &= ~DMA_ACTIVE;
1007
1008 /*
1009 * This is dmap->qlen <= 0 except when closing when
1010 * dmap->qlen < 0
1011 */
1012
1013 while (dmap->qlen <= -dmap->closing) {
1014 dmap->underrun_count++;
1015 dmap->qlen++;
1016 if ((dmap->flags & DMA_DIRTY) && dmap->applic_profile != APF_CPUINTENS) {
1017 dmap->flags &= ~DMA_DIRTY;
1018 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte,
1019 adev->dmap_out->buffsize);
1020 }
1021 dmap->user_counter += dmap->fragment_size;
1022 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1023 }
1024 if (dmap->qlen > 0)
1025 DMAbuf_launch_output(dev, dmap);
1026 finish_output_interrupt(dev, dmap);
1027}
1028/* called in irq context */
1029void DMAbuf_outputintr(int dev, int notify_only)
1030{
1031 struct audio_operations *adev = audio_devs[dev];
1032 unsigned long flags;
1033 struct dma_buffparms *dmap = adev->dmap_out;
1034
1035 spin_lock_irqsave(&dmap->lock,flags);
1036 if (!(dmap->flags & DMA_NODMA)) {
1037 int chan = dmap->dma, pos, n;
1038 unsigned long f;
1039
1040 f=claim_dma_lock();
1041
1042 if(!isa_dma_bridge_buggy)
1043 disable_dma(dmap->dma);
1044 clear_dma_ff(chan);
1045 pos = dmap->bytes_in_use - get_dma_residue(chan);
1046 if(!isa_dma_bridge_buggy)
1047 enable_dma(dmap->dma);
1048 release_dma_lock(f);
1049
1050 pos = pos / dmap->fragment_size; /* Actual qhead */
1051 if (pos < 0 || pos >= dmap->nbufs)
1052 pos = 0;
1053 n = 0;
1054 while (dmap->qhead != pos && n++ < dmap->nbufs)
1055 do_outputintr(dev, notify_only);
1056 }
1057 else
1058 do_outputintr(dev, notify_only);
1059 spin_unlock_irqrestore(&dmap->lock,flags);
1060}
1061EXPORT_SYMBOL(DMAbuf_outputintr);
1062
1063/* called with dmap->lock held in irq context */
1064static void do_inputintr(int dev)
1065{
1066 struct audio_operations *adev = audio_devs[dev];
1067 struct dma_buffparms *dmap = adev->dmap_in;
1068
1069 if (dmap->raw_buf == NULL) {
1070 printk(KERN_ERR "Sound: Fatal error. Audio interrupt after freeing buffers.\n");
1071 return;
1072 }
1073 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1074 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1075 if (dmap->qtail == 0) { /* Wrapped */
1076 dmap->byte_counter += dmap->bytes_in_use;
1077 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
1078 long decr = dmap->byte_counter;
1079 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use) + dmap->bytes_in_use;
1080 decr -= dmap->byte_counter;
1081 dmap->user_counter -= decr;
1082 }
1083 }
1084 dmap->qlen++;
1085
1086 if (!(adev->flags & DMA_AUTOMODE)) {
1087 if (dmap->needs_reorg)
1088 reorganize_buffers(dev, dmap, 0);
1089 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use,DMA_MODE_READ);
1090 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size,
1091 dmap->fragment_size, 1);
1092 if (adev->d->trigger)
1093 adev->d->trigger(dev, adev->enable_bits * adev->go);
1094 }
1095 dmap->flags |= DMA_ACTIVE;
1096 } else if (dmap->qlen >= (dmap->nbufs - 1)) {
1097 printk(KERN_WARNING "Sound: Recording overrun\n");
1098 dmap->underrun_count++;
1099
1100 /* Just throw away the oldest fragment but keep the engine running */
1101 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
1102 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1103 } else if (dmap->qlen >= 0 && dmap->qlen < dmap->nbufs) {
1104 dmap->qlen++;
1105 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1106 if (dmap->qtail == 0) { /* Wrapped */
1107 dmap->byte_counter += dmap->bytes_in_use;
1108 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
1109 long decr = dmap->byte_counter;
1110 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use) + dmap->bytes_in_use;
1111 decr -= dmap->byte_counter;
1112 dmap->user_counter -= decr;
1113 }
1114 }
1115 }
1116 if (!(adev->flags & DMA_AUTOMODE) || (dmap->flags & DMA_NODMA)) {
1117 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use, DMA_MODE_READ);
1118 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size, dmap->fragment_size, 1);
1119 if (adev->d->trigger)
1120 adev->d->trigger(dev,adev->enable_bits * adev->go);
1121 }
1122 dmap->flags |= DMA_ACTIVE;
1123 if (dmap->qlen > 0)
1124 {
1125 wake_up(&adev->in_sleeper);
1126 wake_up(&adev->poll_sleeper);
1127 }
1128}
1129/* called in irq context */
1130void DMAbuf_inputintr(int dev)
1131{
1132 struct audio_operations *adev = audio_devs[dev];
1133 struct dma_buffparms *dmap = adev->dmap_in;
1134 unsigned long flags;
1135
1136 spin_lock_irqsave(&dmap->lock,flags);
1137
1138 if (!(dmap->flags & DMA_NODMA)) {
1139 int chan = dmap->dma, pos, n;
1140 unsigned long f;
1141
1142 f=claim_dma_lock();
1143 if(!isa_dma_bridge_buggy)
1144 disable_dma(dmap->dma);
1145 clear_dma_ff(chan);
1146 pos = dmap->bytes_in_use - get_dma_residue(chan);
1147 if(!isa_dma_bridge_buggy)
1148 enable_dma(dmap->dma);
1149 release_dma_lock(f);
1150
1151 pos = pos / dmap->fragment_size; /* Actual qhead */
1152 if (pos < 0 || pos >= dmap->nbufs)
1153 pos = 0;
1154
1155 n = 0;
1156 while (dmap->qtail != pos && ++n < dmap->nbufs)
1157 do_inputintr(dev);
1158 } else
1159 do_inputintr(dev);
1160 spin_unlock_irqrestore(&dmap->lock,flags);
1161}
1162EXPORT_SYMBOL(DMAbuf_inputintr);
1163
1164void DMAbuf_init(int dev, int dma1, int dma2)
1165{
1166 struct audio_operations *adev = audio_devs[dev];
1167 /*
1168 * NOTE! This routine could be called several times.
1169 */
1170
1171 if (adev && adev->dmap_out == NULL) {
1172 if (adev->d == NULL)
1173 panic("OSS: audio_devs[%d]->d == NULL\n", dev);
1174
1175 if (adev->parent_dev) { /* Use DMA map of the parent dev */
1176 int parent = adev->parent_dev - 1;
1177 adev->dmap_out = audio_devs[parent]->dmap_out;
1178 adev->dmap_in = audio_devs[parent]->dmap_in;
1179 } else {
1180 adev->dmap_out = adev->dmap_in = &adev->dmaps[0];
1181 adev->dmap_out->dma = dma1;
1182 if (adev->flags & DMA_DUPLEX) {
1183 adev->dmap_in = &adev->dmaps[1];
1184 adev->dmap_in->dma = dma2;
1185 }
1186 }
1187 /* Persistent DMA buffers allocated here */
1188 if (sound_dmap_flag == DMAP_KEEP_ON_CLOSE) {
1189 if (adev->dmap_in->raw_buf == NULL)
1190 sound_alloc_dmap(adev->dmap_in);
1191 if (adev->dmap_out->raw_buf == NULL)
1192 sound_alloc_dmap(adev->dmap_out);
1193 }
1194 }
1195}
1196
1197/* No kernel lock - DMAbuf_activate_recording protected by global cli/sti */
1198static unsigned int poll_input(struct file * file, int dev, poll_table *wait)
1199{
1200 struct audio_operations *adev = audio_devs[dev];
1201 struct dma_buffparms *dmap = adev->dmap_in;
1202
1203 if (!(adev->open_mode & OPEN_READ))
1204 return 0;
1205 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1206 if (dmap->qlen)
1207 return POLLIN | POLLRDNORM;
1208 return 0;
1209 }
1210 if (dmap->dma_mode != DMODE_INPUT) {
1211 if (dmap->dma_mode == DMODE_NONE &&
1212 adev->enable_bits & PCM_ENABLE_INPUT &&
1213 !dmap->qlen && adev->go) {
1214 unsigned long flags;
1215
1216 spin_lock_irqsave(&dmap->lock,flags);
1217 DMAbuf_activate_recording(dev, dmap);
1218 spin_unlock_irqrestore(&dmap->lock,flags);
1219 }
1220 return 0;
1221 }
1222 if (!dmap->qlen)
1223 return 0;
1224 return POLLIN | POLLRDNORM;
1225}
1226
1227static unsigned int poll_output(struct file * file, int dev, poll_table *wait)
1228{
1229 struct audio_operations *adev = audio_devs[dev];
1230 struct dma_buffparms *dmap = adev->dmap_out;
1231
1232 if (!(adev->open_mode & OPEN_WRITE))
1233 return 0;
1234 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1235 if (dmap->qlen)
1236 return POLLOUT | POLLWRNORM;
1237 return 0;
1238 }
1239 if (dmap->dma_mode == DMODE_INPUT)
1240 return 0;
1241 if (dmap->dma_mode == DMODE_NONE)
1242 return POLLOUT | POLLWRNORM;
1243 if (!DMAbuf_space_in_queue(dev))
1244 return 0;
1245 return POLLOUT | POLLWRNORM;
1246}
1247
1248unsigned int DMAbuf_poll(struct file * file, int dev, poll_table *wait)
1249{
1250 struct audio_operations *adev = audio_devs[dev];
1251 poll_wait(file, &adev->poll_sleeper, wait);
1252 return poll_input(file, dev, wait) | poll_output(file, dev, wait);
1253}
1254
1255void DMAbuf_deinit(int dev)
1256{
1257 struct audio_operations *adev = audio_devs[dev];
1258 /* This routine is called when driver is being unloaded */
1259 if (!adev)
1260 return;
1261
1262 /* Persistent DMA buffers deallocated here */
1263 if (sound_dmap_flag == DMAP_KEEP_ON_CLOSE) {
1264 sound_free_dmap(adev->dmap_out);
1265 if (adev->flags & DMA_DUPLEX)
1266 sound_free_dmap(adev->dmap_in);
1267 }
1268}
diff --git a/sound/oss/hex2hex.c b/sound/oss/hex2hex.c
deleted file mode 100644
index 041ef5c52bc2..000000000000
--- a/sound/oss/hex2hex.c
+++ /dev/null
@@ -1,101 +0,0 @@
1/*
2 * hex2hex reads stdin in Intel HEX format and produces an
3 * (unsigned char) array which contains the bytes and writes it
4 * to stdout using C syntax
5 */
6
7#include <stdio.h>
8#include <string.h>
9#include <stdlib.h>
10
11#define ABANDON(why) { fprintf(stderr, "%s\n", why); exit(1); }
12#define MAX_SIZE (256*1024)
13unsigned char buf[MAX_SIZE];
14
15static int loadhex(FILE *inf, unsigned char *buf)
16{
17 int l=0, c, i;
18
19 while ((c=getc(inf))!=EOF)
20 {
21 if (c == ':') /* Sync with beginning of line */
22 {
23 int n, check;
24 unsigned char sum;
25 int addr;
26 int linetype;
27
28 if (fscanf(inf, "%02x", &n) != 1)
29 ABANDON("File format error");
30 sum = n;
31
32 if (fscanf(inf, "%04x", &addr) != 1)
33 ABANDON("File format error");
34 sum += addr/256;
35 sum += addr%256;
36
37 if (fscanf(inf, "%02x", &linetype) != 1)
38 ABANDON("File format error");
39 sum += linetype;
40
41 if (linetype != 0)
42 continue;
43
44 for (i=0;i<n;i++)
45 {
46 if (fscanf(inf, "%02x", &c) != 1)
47 ABANDON("File format error");
48 if (addr >= MAX_SIZE)
49 ABANDON("File too large");
50 buf[addr++] = c;
51 if (addr > l)
52 l = addr;
53 sum += c;
54 }
55
56 if (fscanf(inf, "%02x", &check) != 1)
57 ABANDON("File format error");
58
59 sum = ~sum + 1;
60 if (check != sum)
61 ABANDON("Line checksum error");
62 }
63 }
64
65 return l;
66}
67
68int main( int argc, const char * argv [] )
69{
70 const char * varline;
71 int i,l;
72 int id=0;
73
74 if(argv[1] && strcmp(argv[1], "-i")==0)
75 {
76 argv++;
77 argc--;
78 id=1;
79 }
80 if(argv[1]==NULL)
81 {
82 fprintf(stderr,"hex2hex: [-i] filename\n");
83 exit(1);
84 }
85 varline = argv[1];
86 l = loadhex(stdin, buf);
87
88 printf("/*\n *\t Computer generated file. Do not edit.\n */\n");
89 printf("static int %s_len = %d;\n", varline, l);
90 printf("static unsigned char %s[] %s = {\n", varline, id?"__initdata":"");
91
92 for (i=0;i<l;i++)
93 {
94 if (i) printf(",");
95 if (i && !(i % 16)) printf("\n");
96 printf("0x%02x", buf[i]);
97 }
98
99 printf("\n};\n\n");
100 return 0;
101}
diff --git a/sound/oss/kahlua.c b/sound/oss/kahlua.c
deleted file mode 100644
index c4b0434c7604..000000000000
--- a/sound/oss/kahlua.c
+++ /dev/null
@@ -1,229 +0,0 @@
1/*
2 * Initialisation code for Cyrix/NatSemi VSA1 softaudio
3 *
4 * (C) Copyright 2003 Red Hat Inc <alan@lxorguk.ukuu.org.uk>
5 *
6 * XpressAudio(tm) is used on the Cyrix MediaGX (now NatSemi Geode) systems.
7 * The older version (VSA1) provides fairly good soundblaster emulation
8 * although there are a couple of bugs: large DMA buffers break record,
9 * and the MPU event handling seems suspect. VSA2 allows the native driver
10 * to control the AC97 audio engine directly and requires a different driver.
11 *
12 * Thanks to National Semiconductor for providing the needed information
13 * on the XpressAudio(tm) internals.
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2, or (at your option) any
18 * later version.
19 *
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.
24 *
25 * TO DO:
26 * Investigate whether we can portably support Cognac (5520) in the
27 * same manner.
28 */
29
30#include <linux/delay.h>
31#include <linux/init.h>
32#include <linux/module.h>
33#include <linux/pci.h>
34#include <linux/slab.h>
35
36#include "sound_config.h"
37
38#include "sb.h"
39
40/*
41 * Read a soundblaster compatible mixer register.
42 * In this case we are actually reading an SMI trap
43 * not real hardware.
44 */
45
46static u8 mixer_read(unsigned long io, u8 reg)
47{
48 outb(reg, io + 4);
49 udelay(20);
50 reg = inb(io + 5);
51 udelay(20);
52 return reg;
53}
54
55static int probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
56{
57 struct address_info *hw_config;
58 unsigned long base;
59 void __iomem *mem;
60 unsigned long io;
61 u16 map;
62 u8 irq, dma8, dma16;
63 int oldquiet;
64 extern int sb_be_quiet;
65
66 base = pci_resource_start(pdev, 0);
67 if(base == 0UL)
68 return 1;
69
70 mem = ioremap(base, 128);
71 if (!mem)
72 return 1;
73 map = readw(mem + 0x18); /* Read the SMI enables */
74 iounmap(mem);
75
76 /* Map bits
77 0:1 * 0x20 + 0x200 = sb base
78 2 sb enable
79 3 adlib enable
80 5 MPU enable 0x330
81 6 MPU enable 0x300
82
83 The other bits may be used internally so must be masked */
84
85 io = 0x220 + 0x20 * (map & 3);
86
87 if(map & (1<<2))
88 printk(KERN_INFO "kahlua: XpressAudio at 0x%lx\n", io);
89 else
90 return 1;
91
92 if(map & (1<<5))
93 printk(KERN_INFO "kahlua: MPU at 0x300\n");
94 else if(map & (1<<6))
95 printk(KERN_INFO "kahlua: MPU at 0x330\n");
96
97 irq = mixer_read(io, 0x80) & 0x0F;
98 dma8 = mixer_read(io, 0x81);
99
100 // printk("IRQ=%x MAP=%x DMA=%x\n", irq, map, dma8);
101
102 if(dma8 & 0x20)
103 dma16 = 5;
104 else if(dma8 & 0x40)
105 dma16 = 6;
106 else if(dma8 & 0x80)
107 dma16 = 7;
108 else
109 {
110 printk(KERN_ERR "kahlua: No 16bit DMA enabled.\n");
111 return 1;
112 }
113
114 if(dma8 & 0x01)
115 dma8 = 0;
116 else if(dma8 & 0x02)
117 dma8 = 1;
118 else if(dma8 & 0x08)
119 dma8 = 3;
120 else
121 {
122 printk(KERN_ERR "kahlua: No 8bit DMA enabled.\n");
123 return 1;
124 }
125
126 if(irq & 1)
127 irq = 9;
128 else if(irq & 2)
129 irq = 5;
130 else if(irq & 4)
131 irq = 7;
132 else if(irq & 8)
133 irq = 10;
134 else
135 {
136 printk(KERN_ERR "kahlua: SB IRQ not set.\n");
137 return 1;
138 }
139
140 printk(KERN_INFO "kahlua: XpressAudio on IRQ %d, DMA %d, %d\n",
141 irq, dma8, dma16);
142
143 hw_config = kzalloc(sizeof(struct address_info), GFP_KERNEL);
144 if(hw_config == NULL)
145 {
146 printk(KERN_ERR "kahlua: out of memory.\n");
147 return 1;
148 }
149
150 pci_set_drvdata(pdev, hw_config);
151
152 hw_config->io_base = io;
153 hw_config->irq = irq;
154 hw_config->dma = dma8;
155 hw_config->dma2 = dma16;
156 hw_config->name = "Cyrix XpressAudio";
157 hw_config->driver_use_1 = SB_NO_MIDI | SB_PCI_IRQ;
158
159 if (!request_region(io, 16, "soundblaster"))
160 goto err_out_free;
161
162 if(sb_dsp_detect(hw_config, 0, 0, NULL)==0)
163 {
164 printk(KERN_ERR "kahlua: audio not responding.\n");
165 release_region(io, 16);
166 goto err_out_free;
167 }
168
169 oldquiet = sb_be_quiet;
170 sb_be_quiet = 1;
171 if(sb_dsp_init(hw_config, THIS_MODULE))
172 {
173 sb_be_quiet = oldquiet;
174 goto err_out_free;
175 }
176 sb_be_quiet = oldquiet;
177
178 return 0;
179
180err_out_free:
181 kfree(hw_config);
182 return 1;
183}
184
185static void remove_one(struct pci_dev *pdev)
186{
187 struct address_info *hw_config = pci_get_drvdata(pdev);
188 sb_dsp_unload(hw_config, 0);
189 kfree(hw_config);
190}
191
192MODULE_AUTHOR("Alan Cox");
193MODULE_DESCRIPTION("Kahlua VSA1 PCI Audio");
194MODULE_LICENSE("GPL");
195
196/*
197 * 5530 only. The 5510/5520 decode is different.
198 */
199
200static const struct pci_device_id id_tbl[] = {
201 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO), 0 },
202 { }
203};
204
205MODULE_DEVICE_TABLE(pci, id_tbl);
206
207static struct pci_driver kahlua_driver = {
208 .name = "kahlua",
209 .id_table = id_tbl,
210 .probe = probe_one,
211 .remove = remove_one,
212};
213
214
215static int __init kahlua_init_module(void)
216{
217 printk(KERN_INFO "Cyrix Kahlua VSA1 XpressAudio support (c) Copyright 2003 Red Hat Inc\n");
218 return pci_register_driver(&kahlua_driver);
219}
220
221static void kahlua_cleanup_module(void)
222{
223 pci_unregister_driver(&kahlua_driver);
224}
225
226
227module_init(kahlua_init_module);
228module_exit(kahlua_cleanup_module);
229
diff --git a/sound/oss/midi_ctrl.h b/sound/oss/midi_ctrl.h
deleted file mode 100644
index 3353e5a67c24..000000000000
--- a/sound/oss/midi_ctrl.h
+++ /dev/null
@@ -1,22 +0,0 @@
1static unsigned char ctrl_def_values[128] =
2{
3 0x40,0x00,0x40,0x40, 0x40,0x40,0x40,0x7f, /* 0 to 7 */
4 0x40,0x40,0x40,0x7f, 0x40,0x40,0x40,0x40, /* 8 to 15 */
5 0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40, /* 16 to 23 */
6 0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40, /* 24 to 31 */
7
8 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 32 to 39 */
9 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 40 to 47 */
10 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 48 to 55 */
11 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 56 to 63 */
12
13 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 64 to 71 */
14 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 72 to 79 */
15 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 80 to 87 */
16 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 88 to 95 */
17
18 0x00,0x00,0x7f,0x7f, 0x7f,0x7f,0x00,0x00, /* 96 to 103 */
19 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 104 to 111 */
20 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 112 to 119 */
21 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 120 to 127 */
22};
diff --git a/sound/oss/midi_synth.c b/sound/oss/midi_synth.c
deleted file mode 100644
index 2292c230d7e6..000000000000
--- a/sound/oss/midi_synth.c
+++ /dev/null
@@ -1,712 +0,0 @@
1/*
2 * sound/oss/midi_synth.c
3 *
4 * High level midi sequencer manager for dumb MIDI interfaces.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13/*
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * Andrew Veliath : fixed running status in MIDI input state machine
16 */
17#define USE_SEQ_MACROS
18#define USE_SIMPLE_MACROS
19
20#include "sound_config.h"
21
22#define _MIDI_SYNTH_C_
23
24#include "midi_synth.h"
25
26static int midi2synth[MAX_MIDI_DEV];
27static int sysex_state[MAX_MIDI_DEV] =
28{0};
29static unsigned char prev_out_status[MAX_MIDI_DEV];
30
31#define STORE(cmd) \
32{ \
33 int len; \
34 unsigned char obuf[8]; \
35 cmd; \
36 seq_input_event(obuf, len); \
37}
38
39#define _seqbuf obuf
40#define _seqbufptr 0
41#define _SEQ_ADVBUF(x) len=x
42
43void
44do_midi_msg(int synthno, unsigned char *msg, int mlen)
45{
46 switch (msg[0] & 0xf0)
47 {
48 case 0x90:
49 if (msg[2] != 0)
50 {
51 STORE(SEQ_START_NOTE(synthno, msg[0] & 0x0f, msg[1], msg[2]));
52 break;
53 }
54 msg[2] = 64;
55
56 case 0x80:
57 STORE(SEQ_STOP_NOTE(synthno, msg[0] & 0x0f, msg[1], msg[2]));
58 break;
59
60 case 0xA0:
61 STORE(SEQ_KEY_PRESSURE(synthno, msg[0] & 0x0f, msg[1], msg[2]));
62 break;
63
64 case 0xB0:
65 STORE(SEQ_CONTROL(synthno, msg[0] & 0x0f,
66 msg[1], msg[2]));
67 break;
68
69 case 0xC0:
70 STORE(SEQ_SET_PATCH(synthno, msg[0] & 0x0f, msg[1]));
71 break;
72
73 case 0xD0:
74 STORE(SEQ_CHN_PRESSURE(synthno, msg[0] & 0x0f, msg[1]));
75 break;
76
77 case 0xE0:
78 STORE(SEQ_BENDER(synthno, msg[0] & 0x0f,
79 (msg[1] & 0x7f) | ((msg[2] & 0x7f) << 7)));
80 break;
81
82 default:
83 /* printk( "MPU: Unknown midi channel message %02x\n", msg[0]); */
84 ;
85 }
86}
87EXPORT_SYMBOL(do_midi_msg);
88
89static void
90midi_outc(int midi_dev, int data)
91{
92 int timeout;
93
94 for (timeout = 0; timeout < 3200; timeout++)
95 if (midi_devs[midi_dev]->outputc(midi_dev, (unsigned char) (data & 0xff)))
96 {
97 if (data & 0x80) /*
98 * Status byte
99 */
100 prev_out_status[midi_dev] =
101 (unsigned char) (data & 0xff); /*
102 * Store for running status
103 */
104 return; /*
105 * Mission complete
106 */
107 }
108 /*
109 * Sorry! No space on buffers.
110 */
111 printk("Midi send timed out\n");
112}
113
114static int
115prefix_cmd(int midi_dev, unsigned char status)
116{
117 if ((char *) midi_devs[midi_dev]->prefix_cmd == NULL)
118 return 1;
119
120 return midi_devs[midi_dev]->prefix_cmd(midi_dev, status);
121}
122
123static void
124midi_synth_input(int orig_dev, unsigned char data)
125{
126 int dev;
127 struct midi_input_info *inc;
128
129 static unsigned char len_tab[] = /* # of data bytes following a status
130 */
131 {
132 2, /* 8x */
133 2, /* 9x */
134 2, /* Ax */
135 2, /* Bx */
136 1, /* Cx */
137 1, /* Dx */
138 2, /* Ex */
139 0 /* Fx */
140 };
141
142 if (orig_dev < 0 || orig_dev > num_midis || midi_devs[orig_dev] == NULL)
143 return;
144
145 if (data == 0xfe) /* Ignore active sensing */
146 return;
147
148 dev = midi2synth[orig_dev];
149 inc = &midi_devs[orig_dev]->in_info;
150
151 switch (inc->m_state)
152 {
153 case MST_INIT:
154 if (data & 0x80) /* MIDI status byte */
155 {
156 if ((data & 0xf0) == 0xf0) /* Common message */
157 {
158 switch (data)
159 {
160 case 0xf0: /* Sysex */
161 inc->m_state = MST_SYSEX;
162 break; /* Sysex */
163
164 case 0xf1: /* MTC quarter frame */
165 case 0xf3: /* Song select */
166 inc->m_state = MST_DATA;
167 inc->m_ptr = 1;
168 inc->m_left = 1;
169 inc->m_buf[0] = data;
170 break;
171
172 case 0xf2: /* Song position pointer */
173 inc->m_state = MST_DATA;
174 inc->m_ptr = 1;
175 inc->m_left = 2;
176 inc->m_buf[0] = data;
177 break;
178
179 default:
180 inc->m_buf[0] = data;
181 inc->m_ptr = 1;
182 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
183 inc->m_ptr = 0;
184 inc->m_left = 0;
185 }
186 } else
187 {
188 inc->m_state = MST_DATA;
189 inc->m_ptr = 1;
190 inc->m_left = len_tab[(data >> 4) - 8];
191 inc->m_buf[0] = inc->m_prev_status = data;
192 }
193 } else if (inc->m_prev_status & 0x80) {
194 /* Data byte (use running status) */
195 inc->m_ptr = 2;
196 inc->m_buf[1] = data;
197 inc->m_buf[0] = inc->m_prev_status;
198 inc->m_left = len_tab[(inc->m_buf[0] >> 4) - 8] - 1;
199 if (inc->m_left > 0)
200 inc->m_state = MST_DATA; /* Not done yet */
201 else {
202 inc->m_state = MST_INIT;
203 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
204 inc->m_ptr = 0;
205 }
206 }
207 break; /* MST_INIT */
208
209 case MST_DATA:
210 inc->m_buf[inc->m_ptr++] = data;
211 if (--inc->m_left <= 0)
212 {
213 inc->m_state = MST_INIT;
214 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
215 inc->m_ptr = 0;
216 }
217 break; /* MST_DATA */
218
219 case MST_SYSEX:
220 if (data == 0xf7) /* Sysex end */
221 {
222 inc->m_state = MST_INIT;
223 inc->m_left = 0;
224 inc->m_ptr = 0;
225 }
226 break; /* MST_SYSEX */
227
228 default:
229 printk("MIDI%d: Unexpected state %d (%02x)\n", orig_dev, inc->m_state, (int) data);
230 inc->m_state = MST_INIT;
231 }
232}
233
234static void
235leave_sysex(int dev)
236{
237 int orig_dev = synth_devs[dev]->midi_dev;
238 int timeout = 0;
239
240 if (!sysex_state[dev])
241 return;
242
243 sysex_state[dev] = 0;
244
245 while (!midi_devs[orig_dev]->outputc(orig_dev, 0xf7) &&
246 timeout < 1000)
247 timeout++;
248
249 sysex_state[dev] = 0;
250}
251
252static void
253midi_synth_output(int dev)
254{
255 /*
256 * Currently NOP
257 */
258}
259
260int midi_synth_ioctl(int dev, unsigned int cmd, void __user *arg)
261{
262 /*
263 * int orig_dev = synth_devs[dev]->midi_dev;
264 */
265
266 switch (cmd) {
267
268 case SNDCTL_SYNTH_INFO:
269 if (__copy_to_user(arg, synth_devs[dev]->info, sizeof(struct synth_info)))
270 return -EFAULT;
271 return 0;
272
273 case SNDCTL_SYNTH_MEMAVL:
274 return 0x7fffffff;
275
276 default:
277 return -EINVAL;
278 }
279}
280EXPORT_SYMBOL(midi_synth_ioctl);
281
282int
283midi_synth_kill_note(int dev, int channel, int note, int velocity)
284{
285 int orig_dev = synth_devs[dev]->midi_dev;
286 int msg, chn;
287
288 if (note < 0 || note > 127)
289 return 0;
290 if (channel < 0 || channel > 15)
291 return 0;
292 if (velocity < 0)
293 velocity = 0;
294 if (velocity > 127)
295 velocity = 127;
296
297 leave_sysex(dev);
298
299 msg = prev_out_status[orig_dev] & 0xf0;
300 chn = prev_out_status[orig_dev] & 0x0f;
301
302 if (chn == channel && ((msg == 0x90 && velocity == 64) || msg == 0x80))
303 { /*
304 * Use running status
305 */
306 if (!prefix_cmd(orig_dev, note))
307 return 0;
308
309 midi_outc(orig_dev, note);
310
311 if (msg == 0x90) /*
312 * Running status = Note on
313 */
314 midi_outc(orig_dev, 0); /*
315 * Note on with velocity 0 == note
316 * off
317 */
318 else
319 midi_outc(orig_dev, velocity);
320 } else
321 {
322 if (velocity == 64)
323 {
324 if (!prefix_cmd(orig_dev, 0x90 | (channel & 0x0f)))
325 return 0;
326 midi_outc(orig_dev, 0x90 | (channel & 0x0f)); /*
327 * Note on
328 */
329 midi_outc(orig_dev, note);
330 midi_outc(orig_dev, 0); /*
331 * Zero G
332 */
333 } else
334 {
335 if (!prefix_cmd(orig_dev, 0x80 | (channel & 0x0f)))
336 return 0;
337 midi_outc(orig_dev, 0x80 | (channel & 0x0f)); /*
338 * Note off
339 */
340 midi_outc(orig_dev, note);
341 midi_outc(orig_dev, velocity);
342 }
343 }
344
345 return 0;
346}
347EXPORT_SYMBOL(midi_synth_kill_note);
348
349int
350midi_synth_set_instr(int dev, int channel, int instr_no)
351{
352 int orig_dev = synth_devs[dev]->midi_dev;
353
354 if (instr_no < 0 || instr_no > 127)
355 instr_no = 0;
356 if (channel < 0 || channel > 15)
357 return 0;
358
359 leave_sysex(dev);
360
361 if (!prefix_cmd(orig_dev, 0xc0 | (channel & 0x0f)))
362 return 0;
363 midi_outc(orig_dev, 0xc0 | (channel & 0x0f)); /*
364 * Program change
365 */
366 midi_outc(orig_dev, instr_no);
367
368 return 0;
369}
370EXPORT_SYMBOL(midi_synth_set_instr);
371
372int
373midi_synth_start_note(int dev, int channel, int note, int velocity)
374{
375 int orig_dev = synth_devs[dev]->midi_dev;
376 int msg, chn;
377
378 if (note < 0 || note > 127)
379 return 0;
380 if (channel < 0 || channel > 15)
381 return 0;
382 if (velocity < 0)
383 velocity = 0;
384 if (velocity > 127)
385 velocity = 127;
386
387 leave_sysex(dev);
388
389 msg = prev_out_status[orig_dev] & 0xf0;
390 chn = prev_out_status[orig_dev] & 0x0f;
391
392 if (chn == channel && msg == 0x90)
393 { /*
394 * Use running status
395 */
396 if (!prefix_cmd(orig_dev, note))
397 return 0;
398 midi_outc(orig_dev, note);
399 midi_outc(orig_dev, velocity);
400 } else
401 {
402 if (!prefix_cmd(orig_dev, 0x90 | (channel & 0x0f)))
403 return 0;
404 midi_outc(orig_dev, 0x90 | (channel & 0x0f)); /*
405 * Note on
406 */
407 midi_outc(orig_dev, note);
408 midi_outc(orig_dev, velocity);
409 }
410 return 0;
411}
412EXPORT_SYMBOL(midi_synth_start_note);
413
414void
415midi_synth_reset(int dev)
416{
417
418 leave_sysex(dev);
419}
420EXPORT_SYMBOL(midi_synth_reset);
421
422int
423midi_synth_open(int dev, int mode)
424{
425 int orig_dev = synth_devs[dev]->midi_dev;
426 int err;
427 struct midi_input_info *inc;
428
429 if (orig_dev < 0 || orig_dev >= num_midis || midi_devs[orig_dev] == NULL)
430 return -ENXIO;
431
432 midi2synth[orig_dev] = dev;
433 sysex_state[dev] = 0;
434 prev_out_status[orig_dev] = 0;
435
436 if ((err = midi_devs[orig_dev]->open(orig_dev, mode,
437 midi_synth_input, midi_synth_output)) < 0)
438 return err;
439 inc = &midi_devs[orig_dev]->in_info;
440
441 /* save_flags(flags);
442 cli();
443 don't know against what irqhandler to protect*/
444 inc->m_busy = 0;
445 inc->m_state = MST_INIT;
446 inc->m_ptr = 0;
447 inc->m_left = 0;
448 inc->m_prev_status = 0x00;
449 /* restore_flags(flags); */
450
451 return 1;
452}
453EXPORT_SYMBOL(midi_synth_open);
454
455void
456midi_synth_close(int dev)
457{
458 int orig_dev = synth_devs[dev]->midi_dev;
459
460 leave_sysex(dev);
461
462 /*
463 * Shut up the synths by sending just single active sensing message.
464 */
465 midi_devs[orig_dev]->outputc(orig_dev, 0xfe);
466
467 midi_devs[orig_dev]->close(orig_dev);
468}
469EXPORT_SYMBOL(midi_synth_close);
470
471void
472midi_synth_hw_control(int dev, unsigned char *event)
473{
474}
475EXPORT_SYMBOL(midi_synth_hw_control);
476
477int
478midi_synth_load_patch(int dev, int format, const char __user *addr,
479 int count, int pmgr_flag)
480{
481 int orig_dev = synth_devs[dev]->midi_dev;
482
483 struct sysex_info sysex;
484 int i;
485 unsigned long left, src_offs, eox_seen = 0;
486 int first_byte = 1;
487 int hdr_size = (unsigned long) &sysex.data[0] - (unsigned long) &sysex;
488
489 leave_sysex(dev);
490
491 if (!prefix_cmd(orig_dev, 0xf0))
492 return 0;
493
494 /* Invalid patch format */
495 if (format != SYSEX_PATCH)
496 return -EINVAL;
497
498 /* Patch header too short */
499 if (count < hdr_size)
500 return -EINVAL;
501
502 count -= hdr_size;
503
504 /*
505 * Copy the header from user space
506 */
507
508 if (copy_from_user(&sysex, addr, hdr_size))
509 return -EFAULT;
510
511 /* Sysex record too short */
512 if ((unsigned)count < (unsigned)sysex.len)
513 sysex.len = count;
514
515 left = sysex.len;
516 src_offs = 0;
517
518 for (i = 0; i < left && !signal_pending(current); i++)
519 {
520 unsigned char data;
521
522 if (get_user(data,
523 (unsigned char __user *)(addr + hdr_size + i)))
524 return -EFAULT;
525
526 eox_seen = (i > 0 && data & 0x80); /* End of sysex */
527
528 if (eox_seen && data != 0xf7)
529 data = 0xf7;
530
531 if (i == 0)
532 {
533 if (data != 0xf0)
534 {
535 printk(KERN_WARNING "midi_synth: Sysex start missing\n");
536 return -EINVAL;
537 }
538 }
539 while (!midi_devs[orig_dev]->outputc(orig_dev, (unsigned char) (data & 0xff)) &&
540 !signal_pending(current))
541 schedule();
542
543 if (!first_byte && data & 0x80)
544 return 0;
545 first_byte = 0;
546 }
547
548 if (!eox_seen)
549 midi_outc(orig_dev, 0xf7);
550 return 0;
551}
552EXPORT_SYMBOL(midi_synth_load_patch);
553
554void midi_synth_panning(int dev, int channel, int pressure)
555{
556}
557EXPORT_SYMBOL(midi_synth_panning);
558
559void midi_synth_aftertouch(int dev, int channel, int pressure)
560{
561 int orig_dev = synth_devs[dev]->midi_dev;
562 int msg, chn;
563
564 if (pressure < 0 || pressure > 127)
565 return;
566 if (channel < 0 || channel > 15)
567 return;
568
569 leave_sysex(dev);
570
571 msg = prev_out_status[orig_dev] & 0xf0;
572 chn = prev_out_status[orig_dev] & 0x0f;
573
574 if (msg != 0xd0 || chn != channel) /*
575 * Test for running status
576 */
577 {
578 if (!prefix_cmd(orig_dev, 0xd0 | (channel & 0x0f)))
579 return;
580 midi_outc(orig_dev, 0xd0 | (channel & 0x0f)); /*
581 * Channel pressure
582 */
583 } else if (!prefix_cmd(orig_dev, pressure))
584 return;
585
586 midi_outc(orig_dev, pressure);
587}
588EXPORT_SYMBOL(midi_synth_aftertouch);
589
590void
591midi_synth_controller(int dev, int channel, int ctrl_num, int value)
592{
593 int orig_dev = synth_devs[dev]->midi_dev;
594 int chn, msg;
595
596 if (ctrl_num < 0 || ctrl_num > 127)
597 return;
598 if (channel < 0 || channel > 15)
599 return;
600
601 leave_sysex(dev);
602
603 msg = prev_out_status[orig_dev] & 0xf0;
604 chn = prev_out_status[orig_dev] & 0x0f;
605
606 if (msg != 0xb0 || chn != channel)
607 {
608 if (!prefix_cmd(orig_dev, 0xb0 | (channel & 0x0f)))
609 return;
610 midi_outc(orig_dev, 0xb0 | (channel & 0x0f));
611 } else if (!prefix_cmd(orig_dev, ctrl_num))
612 return;
613
614 midi_outc(orig_dev, ctrl_num);
615 midi_outc(orig_dev, value & 0x7f);
616}
617EXPORT_SYMBOL(midi_synth_controller);
618
619void
620midi_synth_bender(int dev, int channel, int value)
621{
622 int orig_dev = synth_devs[dev]->midi_dev;
623 int msg, prev_chn;
624
625 if (channel < 0 || channel > 15)
626 return;
627
628 if (value < 0 || value > 16383)
629 return;
630
631 leave_sysex(dev);
632
633 msg = prev_out_status[orig_dev] & 0xf0;
634 prev_chn = prev_out_status[orig_dev] & 0x0f;
635
636 if (msg != 0xd0 || prev_chn != channel) /*
637 * Test for running status
638 */
639 {
640 if (!prefix_cmd(orig_dev, 0xe0 | (channel & 0x0f)))
641 return;
642 midi_outc(orig_dev, 0xe0 | (channel & 0x0f));
643 } else if (!prefix_cmd(orig_dev, value & 0x7f))
644 return;
645
646 midi_outc(orig_dev, value & 0x7f);
647 midi_outc(orig_dev, (value >> 7) & 0x7f);
648}
649EXPORT_SYMBOL(midi_synth_bender);
650
651void
652midi_synth_setup_voice(int dev, int voice, int channel)
653{
654}
655EXPORT_SYMBOL(midi_synth_setup_voice);
656
657int
658midi_synth_send_sysex(int dev, unsigned char *bytes, int len)
659{
660 int orig_dev = synth_devs[dev]->midi_dev;
661 int i;
662
663 for (i = 0; i < len; i++)
664 {
665 switch (bytes[i])
666 {
667 case 0xf0: /* Start sysex */
668 if (!prefix_cmd(orig_dev, 0xf0))
669 return 0;
670 sysex_state[dev] = 1;
671 break;
672
673 case 0xf7: /* End sysex */
674 if (!sysex_state[dev]) /* Orphan sysex end */
675 return 0;
676 sysex_state[dev] = 0;
677 break;
678
679 default:
680 if (!sysex_state[dev])
681 return 0;
682
683 if (bytes[i] & 0x80) /* Error. Another message before sysex end */
684 {
685 bytes[i] = 0xf7; /* Sysex end */
686 sysex_state[dev] = 0;
687 }
688 }
689
690 if (!midi_devs[orig_dev]->outputc(orig_dev, bytes[i]))
691 {
692/*
693 * Hardware level buffer is full. Abort the sysex message.
694 */
695
696 int timeout = 0;
697
698 bytes[i] = 0xf7;
699 sysex_state[dev] = 0;
700
701 while (!midi_devs[orig_dev]->outputc(orig_dev, bytes[i]) &&
702 timeout < 1000)
703 timeout++;
704 }
705 if (!sysex_state[dev])
706 return 0;
707 }
708
709 return 0;
710}
711EXPORT_SYMBOL(midi_synth_send_sysex);
712
diff --git a/sound/oss/midi_synth.h b/sound/oss/midi_synth.h
deleted file mode 100644
index b64ddd6c4abc..000000000000
--- a/sound/oss/midi_synth.h
+++ /dev/null
@@ -1,47 +0,0 @@
1int midi_synth_ioctl (int dev,
2 unsigned int cmd, void __user * arg);
3int midi_synth_kill_note (int dev, int channel, int note, int velocity);
4int midi_synth_set_instr (int dev, int channel, int instr_no);
5int midi_synth_start_note (int dev, int channel, int note, int volume);
6void midi_synth_reset (int dev);
7int midi_synth_open (int dev, int mode);
8void midi_synth_close (int dev);
9void midi_synth_hw_control (int dev, unsigned char *event);
10int midi_synth_load_patch (int dev, int format, const char __user * addr,
11 int count, int pmgr_flag);
12void midi_synth_panning (int dev, int channel, int pressure);
13void midi_synth_aftertouch (int dev, int channel, int pressure);
14void midi_synth_controller (int dev, int channel, int ctrl_num, int value);
15void midi_synth_bender (int dev, int chn, int value);
16void midi_synth_setup_voice (int dev, int voice, int chn);
17int midi_synth_send_sysex(int dev, unsigned char *bytes,int len);
18
19#ifndef _MIDI_SYNTH_C_
20static struct synth_info std_synth_info =
21{MIDI_SYNTH_NAME, 0, SYNTH_TYPE_MIDI, 0, 0, 128, 0, 128, MIDI_SYNTH_CAPS};
22
23static struct synth_operations std_midi_synth =
24{
25 .owner = THIS_MODULE,
26 .id = "MIDI",
27 .info = &std_synth_info,
28 .midi_dev = 0,
29 .synth_type = SYNTH_TYPE_MIDI,
30 .synth_subtype = 0,
31 .open = midi_synth_open,
32 .close = midi_synth_close,
33 .ioctl = midi_synth_ioctl,
34 .kill_note = midi_synth_kill_note,
35 .start_note = midi_synth_start_note,
36 .set_instr = midi_synth_set_instr,
37 .reset = midi_synth_reset,
38 .hw_control = midi_synth_hw_control,
39 .load_patch = midi_synth_load_patch,
40 .aftertouch = midi_synth_aftertouch,
41 .controller = midi_synth_controller,
42 .panning = midi_synth_panning,
43 .bender = midi_synth_bender,
44 .setup_voice = midi_synth_setup_voice,
45 .send_sysex = midi_synth_send_sysex
46};
47#endif
diff --git a/sound/oss/midibuf.c b/sound/oss/midibuf.c
deleted file mode 100644
index 701c7625c971..000000000000
--- a/sound/oss/midibuf.c
+++ /dev/null
@@ -1,427 +0,0 @@
1/*
2 * sound/oss/midibuf.c
3 *
4 * Device file manager for /dev/midi#
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13/*
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 */
16#include <linux/stddef.h>
17#include <linux/kmod.h>
18#include <linux/spinlock.h>
19#include <linux/sched/signal.h>
20
21#define MIDIBUF_C
22
23#include "sound_config.h"
24
25
26/*
27 * Don't make MAX_QUEUE_SIZE larger than 4000
28 */
29
30#define MAX_QUEUE_SIZE 4000
31
32static wait_queue_head_t midi_sleeper[MAX_MIDI_DEV];
33static wait_queue_head_t input_sleeper[MAX_MIDI_DEV];
34
35struct midi_buf
36{
37 int len, head, tail;
38 unsigned char queue[MAX_QUEUE_SIZE];
39};
40
41struct midi_parms
42{
43 long prech_timeout; /*
44 * Timeout before the first ch
45 */
46};
47
48static struct midi_buf *midi_out_buf[MAX_MIDI_DEV] = {NULL};
49static struct midi_buf *midi_in_buf[MAX_MIDI_DEV] = {NULL};
50static struct midi_parms parms[MAX_MIDI_DEV];
51
52static void midi_poll(unsigned long dummy);
53
54
55static DEFINE_TIMER(poll_timer, midi_poll, 0, 0);
56
57static volatile int open_devs;
58static DEFINE_SPINLOCK(lock);
59
60#define DATA_AVAIL(q) (q->len)
61#define SPACE_AVAIL(q) (MAX_QUEUE_SIZE - q->len)
62
63#define QUEUE_BYTE(q, data) \
64 if (SPACE_AVAIL(q)) \
65 { \
66 unsigned long flags; \
67 spin_lock_irqsave(&lock, flags); \
68 q->queue[q->tail] = (data); \
69 q->len++; q->tail = (q->tail+1) % MAX_QUEUE_SIZE; \
70 spin_unlock_irqrestore(&lock, flags); \
71 }
72
73#define REMOVE_BYTE(q, data) \
74 if (DATA_AVAIL(q)) \
75 { \
76 unsigned long flags; \
77 spin_lock_irqsave(&lock, flags); \
78 data = q->queue[q->head]; \
79 q->len--; q->head = (q->head+1) % MAX_QUEUE_SIZE; \
80 spin_unlock_irqrestore(&lock, flags); \
81 }
82
83static void drain_midi_queue(int dev)
84{
85
86 /*
87 * Give the Midi driver time to drain its output queues
88 */
89
90 if (midi_devs[dev]->buffer_status != NULL)
91 wait_event_interruptible_timeout(midi_sleeper[dev],
92 !midi_devs[dev]->buffer_status(dev), HZ/10);
93}
94
95static void midi_input_intr(int dev, unsigned char data)
96{
97 if (midi_in_buf[dev] == NULL)
98 return;
99
100 if (data == 0xfe) /*
101 * Active sensing
102 */
103 return; /*
104 * Ignore
105 */
106
107 if (SPACE_AVAIL(midi_in_buf[dev])) {
108 QUEUE_BYTE(midi_in_buf[dev], data);
109 wake_up(&input_sleeper[dev]);
110 }
111}
112
113static void midi_output_intr(int dev)
114{
115 /*
116 * Currently NOP
117 */
118}
119
120static void midi_poll(unsigned long dummy)
121{
122 unsigned long flags;
123 int dev;
124
125 spin_lock_irqsave(&lock, flags);
126 if (open_devs)
127 {
128 for (dev = 0; dev < num_midis; dev++)
129 if (midi_devs[dev] != NULL && midi_out_buf[dev] != NULL)
130 {
131 while (DATA_AVAIL(midi_out_buf[dev]))
132 {
133 int ok;
134 int c = midi_out_buf[dev]->queue[midi_out_buf[dev]->head];
135
136 spin_unlock_irqrestore(&lock,flags);/* Give some time to others */
137 ok = midi_devs[dev]->outputc(dev, c);
138 spin_lock_irqsave(&lock, flags);
139 if (!ok)
140 break;
141 midi_out_buf[dev]->head = (midi_out_buf[dev]->head + 1) % MAX_QUEUE_SIZE;
142 midi_out_buf[dev]->len--;
143 }
144
145 if (DATA_AVAIL(midi_out_buf[dev]) < 100)
146 wake_up(&midi_sleeper[dev]);
147 }
148 poll_timer.expires = (1) + jiffies;
149 add_timer(&poll_timer);
150 /*
151 * Come back later
152 */
153 }
154 spin_unlock_irqrestore(&lock, flags);
155}
156
157int MIDIbuf_open(int dev, struct file *file)
158{
159 int mode, err;
160
161 dev = dev >> 4;
162 mode = translate_mode(file);
163
164 if (num_midis > MAX_MIDI_DEV)
165 {
166 printk(KERN_ERR "midi: Too many midi interfaces\n");
167 num_midis = MAX_MIDI_DEV;
168 }
169 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
170 return -ENXIO;
171 /*
172 * Interrupts disabled. Be careful
173 */
174
175 module_put(midi_devs[dev]->owner);
176
177 if ((err = midi_devs[dev]->open(dev, mode,
178 midi_input_intr, midi_output_intr)) < 0)
179 return err;
180
181 parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT;
182 midi_in_buf[dev] = vmalloc(sizeof(struct midi_buf));
183
184 if (midi_in_buf[dev] == NULL)
185 {
186 printk(KERN_WARNING "midi: Can't allocate buffer\n");
187 midi_devs[dev]->close(dev);
188 return -EIO;
189 }
190 midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0;
191
192 midi_out_buf[dev] = vmalloc(sizeof(struct midi_buf));
193
194 if (midi_out_buf[dev] == NULL)
195 {
196 printk(KERN_WARNING "midi: Can't allocate buffer\n");
197 midi_devs[dev]->close(dev);
198 vfree(midi_in_buf[dev]);
199 midi_in_buf[dev] = NULL;
200 return -EIO;
201 }
202 midi_out_buf[dev]->len = midi_out_buf[dev]->head = midi_out_buf[dev]->tail = 0;
203 open_devs++;
204
205 init_waitqueue_head(&midi_sleeper[dev]);
206 init_waitqueue_head(&input_sleeper[dev]);
207
208 if (open_devs < 2) /* This was first open */
209 {
210 poll_timer.expires = 1 + jiffies;
211 add_timer(&poll_timer); /* Start polling */
212 }
213 return err;
214}
215
216void MIDIbuf_release(int dev, struct file *file)
217{
218 int mode;
219
220 dev = dev >> 4;
221 mode = translate_mode(file);
222
223 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
224 return;
225
226 /*
227 * Wait until the queue is empty
228 */
229
230 if (mode != OPEN_READ)
231 {
232 midi_devs[dev]->outputc(dev, 0xfe); /*
233 * Active sensing to shut the
234 * devices
235 */
236
237 wait_event_interruptible(midi_sleeper[dev],
238 !DATA_AVAIL(midi_out_buf[dev]));
239 /*
240 * Sync
241 */
242
243 drain_midi_queue(dev); /*
244 * Ensure the output queues are empty
245 */
246 }
247
248 midi_devs[dev]->close(dev);
249
250 open_devs--;
251 if (open_devs == 0)
252 del_timer_sync(&poll_timer);
253 vfree(midi_in_buf[dev]);
254 vfree(midi_out_buf[dev]);
255 midi_in_buf[dev] = NULL;
256 midi_out_buf[dev] = NULL;
257
258 module_put(midi_devs[dev]->owner);
259}
260
261int MIDIbuf_write(int dev, struct file *file, const char __user *buf, int count)
262{
263 int c, n, i;
264 unsigned char tmp_data;
265
266 dev = dev >> 4;
267
268 if (!count)
269 return 0;
270
271 c = 0;
272
273 while (c < count)
274 {
275 n = SPACE_AVAIL(midi_out_buf[dev]);
276
277 if (n == 0) { /*
278 * No space just now.
279 */
280
281 if (file->f_flags & O_NONBLOCK) {
282 c = -EAGAIN;
283 goto out;
284 }
285
286 if (wait_event_interruptible(midi_sleeper[dev],
287 SPACE_AVAIL(midi_out_buf[dev])))
288 {
289 c = -EINTR;
290 goto out;
291 }
292 n = SPACE_AVAIL(midi_out_buf[dev]);
293 }
294 if (n > (count - c))
295 n = count - c;
296
297 for (i = 0; i < n; i++)
298 {
299 /* BROKE BROKE BROKE - CAN'T DO THIS WITH CLI !! */
300 /* yes, think the same, so I removed the cli() brackets
301 QUEUE_BYTE is protected against interrupts */
302 if (copy_from_user((char *) &tmp_data, &(buf)[c], 1)) {
303 c = -EFAULT;
304 goto out;
305 }
306 QUEUE_BYTE(midi_out_buf[dev], tmp_data);
307 c++;
308 }
309 }
310out:
311 return c;
312}
313
314
315int MIDIbuf_read(int dev, struct file *file, char __user *buf, int count)
316{
317 int n, c = 0;
318 unsigned char tmp_data;
319
320 dev = dev >> 4;
321
322 if (!DATA_AVAIL(midi_in_buf[dev])) { /*
323 * No data yet, wait
324 */
325 if (file->f_flags & O_NONBLOCK) {
326 c = -EAGAIN;
327 goto out;
328 }
329 wait_event_interruptible_timeout(input_sleeper[dev],
330 DATA_AVAIL(midi_in_buf[dev]),
331 parms[dev].prech_timeout);
332
333 if (signal_pending(current))
334 c = -EINTR; /* The user is getting restless */
335 }
336 if (c == 0 && DATA_AVAIL(midi_in_buf[dev])) /*
337 * Got some bytes
338 */
339 {
340 n = DATA_AVAIL(midi_in_buf[dev]);
341 if (n > count)
342 n = count;
343 c = 0;
344
345 while (c < n)
346 {
347 char *fixit;
348 REMOVE_BYTE(midi_in_buf[dev], tmp_data);
349 fixit = (char *) &tmp_data;
350 /* BROKE BROKE BROKE */
351 /* yes removed the cli() brackets again
352 should q->len,tail&head be atomic_t? */
353 if (copy_to_user(&(buf)[c], fixit, 1)) {
354 c = -EFAULT;
355 goto out;
356 }
357 c++;
358 }
359 }
360out:
361 return c;
362}
363
364int MIDIbuf_ioctl(int dev, struct file *file,
365 unsigned int cmd, void __user *arg)
366{
367 int val;
368
369 dev = dev >> 4;
370
371 if (((cmd >> 8) & 0xff) == 'C')
372 {
373 if (midi_devs[dev]->coproc) /* Coprocessor ioctl */
374 return midi_devs[dev]->coproc->ioctl(midi_devs[dev]->coproc->devc, cmd, arg, 0);
375/* printk("/dev/midi%d: No coprocessor for this device\n", dev);*/
376 return -ENXIO;
377 }
378 else
379 {
380 switch (cmd)
381 {
382 case SNDCTL_MIDI_PRETIME:
383 if (get_user(val, (int __user *)arg))
384 return -EFAULT;
385 if (val < 0)
386 val = 0;
387 val = (HZ * val) / 10;
388 parms[dev].prech_timeout = val;
389 return put_user(val, (int __user *)arg);
390
391 default:
392 if (!midi_devs[dev]->ioctl)
393 return -EINVAL;
394 return midi_devs[dev]->ioctl(dev, cmd, arg);
395 }
396 }
397}
398
399/* No kernel lock - fine */
400unsigned int MIDIbuf_poll(int dev, struct file *file, poll_table * wait)
401{
402 unsigned int mask = 0;
403
404 dev = dev >> 4;
405
406 /* input */
407 poll_wait(file, &input_sleeper[dev], wait);
408 if (DATA_AVAIL(midi_in_buf[dev]))
409 mask |= POLLIN | POLLRDNORM;
410
411 /* output */
412 poll_wait(file, &midi_sleeper[dev], wait);
413 if (!SPACE_AVAIL(midi_out_buf[dev]))
414 mask |= POLLOUT | POLLWRNORM;
415
416 return mask;
417}
418
419
420int MIDIbuf_avail(int dev)
421{
422 if (midi_in_buf[dev])
423 return DATA_AVAIL (midi_in_buf[dev]);
424 return 0;
425}
426EXPORT_SYMBOL(MIDIbuf_avail);
427
diff --git a/sound/oss/mpu401.c b/sound/oss/mpu401.c
deleted file mode 100644
index 20e8fa46f647..000000000000
--- a/sound/oss/mpu401.c
+++ /dev/null
@@ -1,1804 +0,0 @@
1/*
2 * sound/oss/mpu401.c
3 *
4 * The low level driver for Roland MPU-401 compatible Midi cards.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
15 * Alan Cox modularisation, use normal request_irq, use dev_id
16 * Bartlomiej Zolnierkiewicz removed some __init to allow using many drivers
17 * Chris Rankin Update the module-usage counter for the coprocessor
18 * Zwane Mwaikambo Changed attach/unload resource freeing
19 */
20
21#include <linux/module.h>
22#include <linux/slab.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/spinlock.h>
26#define USE_SEQ_MACROS
27#define USE_SIMPLE_MACROS
28
29#include "sound_config.h"
30
31#include "coproc.h"
32#include "mpu401.h"
33
34static int timer_mode = TMR_INTERNAL, timer_caps = TMR_INTERNAL;
35
36struct mpu_config
37{
38 int base; /*
39 * I/O base
40 */
41 int irq;
42 int opened; /*
43 * Open mode
44 */
45 int devno;
46 int synthno;
47 int uart_mode;
48 int initialized;
49 int mode;
50#define MODE_MIDI 1
51#define MODE_SYNTH 2
52 unsigned char version, revision;
53 unsigned int capabilities;
54#define MPU_CAP_INTLG 0x10000000
55#define MPU_CAP_SYNC 0x00000010
56#define MPU_CAP_FSK 0x00000020
57#define MPU_CAP_CLS 0x00000040
58#define MPU_CAP_SMPTE 0x00000080
59#define MPU_CAP_2PORT 0x00000001
60 int timer_flag;
61
62#define MBUF_MAX 10
63#define BUFTEST(dc) if (dc->m_ptr >= MBUF_MAX || dc->m_ptr < 0) \
64 {printk( "MPU: Invalid buffer pointer %d/%d, s=%d\n", dc->m_ptr, dc->m_left, dc->m_state);dc->m_ptr--;}
65 int m_busy;
66 unsigned char m_buf[MBUF_MAX];
67 int m_ptr;
68 int m_state;
69 int m_left;
70 unsigned char last_status;
71 void (*inputintr) (int dev, unsigned char data);
72 int shared_irq;
73 int *osp;
74 spinlock_t lock;
75 };
76
77#define DATAPORT(base) (base)
78#define COMDPORT(base) (base+1)
79#define STATPORT(base) (base+1)
80
81
82static void mpu401_close(int dev);
83
84static inline int mpu401_status(struct mpu_config *devc)
85{
86 return inb(STATPORT(devc->base));
87}
88
89#define input_avail(devc) (!(mpu401_status(devc)&INPUT_AVAIL))
90#define output_ready(devc) (!(mpu401_status(devc)&OUTPUT_READY))
91
92static inline void write_command(struct mpu_config *devc, unsigned char cmd)
93{
94 outb(cmd, COMDPORT(devc->base));
95}
96
97static inline int read_data(struct mpu_config *devc)
98{
99 return inb(DATAPORT(devc->base));
100}
101
102static inline void write_data(struct mpu_config *devc, unsigned char byte)
103{
104 outb(byte, DATAPORT(devc->base));
105}
106
107#define OUTPUT_READY 0x40
108#define INPUT_AVAIL 0x80
109#define MPU_ACK 0xFE
110#define MPU_RESET 0xFF
111#define UART_MODE_ON 0x3F
112
113static struct mpu_config dev_conf[MAX_MIDI_DEV];
114
115static int n_mpu_devs;
116
117static int reset_mpu401(struct mpu_config *devc);
118static void set_uart_mode(int dev, struct mpu_config *devc, int arg);
119
120static int mpu_timer_init(int midi_dev);
121static void mpu_timer_interrupt(void);
122static void timer_ext_event(struct mpu_config *devc, int event, int parm);
123
124static struct synth_info mpu_synth_info_proto = {
125 "MPU-401 MIDI interface",
126 0,
127 SYNTH_TYPE_MIDI,
128 MIDI_TYPE_MPU401,
129 0, 128,
130 0, 128,
131 SYNTH_CAP_INPUT
132};
133
134static struct synth_info mpu_synth_info[MAX_MIDI_DEV];
135
136/*
137 * States for the input scanner
138 */
139
140#define ST_INIT 0 /* Ready for timing byte or msg */
141#define ST_TIMED 1 /* Leading timing byte rcvd */
142#define ST_DATABYTE 2 /* Waiting for (nr_left) data bytes */
143
144#define ST_SYSMSG 100 /* System message (sysx etc). */
145#define ST_SYSEX 101 /* System exclusive msg */
146#define ST_MTC 102 /* Midi Time Code (MTC) qframe msg */
147#define ST_SONGSEL 103 /* Song select */
148#define ST_SONGPOS 104 /* Song position pointer */
149
150static unsigned char len_tab[] = /* # of data bytes following a status
151 */
152{
153 2, /* 8x */
154 2, /* 9x */
155 2, /* Ax */
156 2, /* Bx */
157 1, /* Cx */
158 1, /* Dx */
159 2, /* Ex */
160 0 /* Fx */
161};
162
163#define STORE(cmd) \
164{ \
165 int len; \
166 unsigned char obuf[8]; \
167 cmd; \
168 seq_input_event(obuf, len); \
169}
170
171#define _seqbuf obuf
172#define _seqbufptr 0
173#define _SEQ_ADVBUF(x) len=x
174
175static int mpu_input_scanner(struct mpu_config *devc, unsigned char midic)
176{
177
178 switch (devc->m_state)
179 {
180 case ST_INIT:
181 switch (midic)
182 {
183 case 0xf8:
184 /* Timer overflow */
185 break;
186
187 case 0xfc:
188 printk("<all end>");
189 break;
190
191 case 0xfd:
192 if (devc->timer_flag)
193 mpu_timer_interrupt();
194 break;
195
196 case 0xfe:
197 return MPU_ACK;
198
199 case 0xf0:
200 case 0xf1:
201 case 0xf2:
202 case 0xf3:
203 case 0xf4:
204 case 0xf5:
205 case 0xf6:
206 case 0xf7:
207 printk("<Trk data rq #%d>", midic & 0x0f);
208 break;
209
210 case 0xf9:
211 printk("<conductor rq>");
212 break;
213
214 case 0xff:
215 devc->m_state = ST_SYSMSG;
216 break;
217
218 default:
219 if (midic <= 0xef)
220 {
221 /* printk( "mpu time: %d ", midic); */
222 devc->m_state = ST_TIMED;
223 }
224 else
225 printk("<MPU: Unknown event %02x> ", midic);
226 }
227 break;
228
229 case ST_TIMED:
230 {
231 int msg = ((int) (midic & 0xf0) >> 4);
232
233 devc->m_state = ST_DATABYTE;
234
235 if (msg < 8) /* Data byte */
236 {
237 /* printk( "midi msg (running status) "); */
238 msg = ((int) (devc->last_status & 0xf0) >> 4);
239 msg -= 8;
240 devc->m_left = len_tab[msg] - 1;
241
242 devc->m_ptr = 2;
243 devc->m_buf[0] = devc->last_status;
244 devc->m_buf[1] = midic;
245
246 if (devc->m_left <= 0)
247 {
248 devc->m_state = ST_INIT;
249 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
250 devc->m_ptr = 0;
251 }
252 }
253 else if (msg == 0xf) /* MPU MARK */
254 {
255 devc->m_state = ST_INIT;
256
257 switch (midic)
258 {
259 case 0xf8:
260 /* printk( "NOP "); */
261 break;
262
263 case 0xf9:
264 /* printk( "meas end "); */
265 break;
266
267 case 0xfc:
268 /* printk( "data end "); */
269 break;
270
271 default:
272 printk("Unknown MPU mark %02x\n", midic);
273 }
274 }
275 else
276 {
277 devc->last_status = midic;
278 /* printk( "midi msg "); */
279 msg -= 8;
280 devc->m_left = len_tab[msg];
281
282 devc->m_ptr = 1;
283 devc->m_buf[0] = midic;
284
285 if (devc->m_left <= 0)
286 {
287 devc->m_state = ST_INIT;
288 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
289 devc->m_ptr = 0;
290 }
291 }
292 }
293 break;
294
295 case ST_SYSMSG:
296 switch (midic)
297 {
298 case 0xf0:
299 printk("<SYX>");
300 devc->m_state = ST_SYSEX;
301 break;
302
303 case 0xf1:
304 devc->m_state = ST_MTC;
305 break;
306
307 case 0xf2:
308 devc->m_state = ST_SONGPOS;
309 devc->m_ptr = 0;
310 break;
311
312 case 0xf3:
313 devc->m_state = ST_SONGSEL;
314 break;
315
316 case 0xf6:
317 /* printk( "tune_request\n"); */
318 devc->m_state = ST_INIT;
319 break;
320
321 /*
322 * Real time messages
323 */
324 case 0xf8:
325 /* midi clock */
326 devc->m_state = ST_INIT;
327 timer_ext_event(devc, TMR_CLOCK, 0);
328 break;
329
330 case 0xfA:
331 devc->m_state = ST_INIT;
332 timer_ext_event(devc, TMR_START, 0);
333 break;
334
335 case 0xFB:
336 devc->m_state = ST_INIT;
337 timer_ext_event(devc, TMR_CONTINUE, 0);
338 break;
339
340 case 0xFC:
341 devc->m_state = ST_INIT;
342 timer_ext_event(devc, TMR_STOP, 0);
343 break;
344
345 case 0xFE:
346 /* active sensing */
347 devc->m_state = ST_INIT;
348 break;
349
350 case 0xff:
351 /* printk( "midi hard reset"); */
352 devc->m_state = ST_INIT;
353 break;
354
355 default:
356 printk("unknown MIDI sysmsg %0x\n", midic);
357 devc->m_state = ST_INIT;
358 }
359 break;
360
361 case ST_MTC:
362 devc->m_state = ST_INIT;
363 printk("MTC frame %x02\n", midic);
364 break;
365
366 case ST_SYSEX:
367 if (midic == 0xf7)
368 {
369 printk("<EOX>");
370 devc->m_state = ST_INIT;
371 }
372 else
373 printk("%02x ", midic);
374 break;
375
376 case ST_SONGPOS:
377 BUFTEST(devc);
378 devc->m_buf[devc->m_ptr++] = midic;
379 if (devc->m_ptr == 2)
380 {
381 devc->m_state = ST_INIT;
382 devc->m_ptr = 0;
383 timer_ext_event(devc, TMR_SPP,
384 ((devc->m_buf[1] & 0x7f) << 7) |
385 (devc->m_buf[0] & 0x7f));
386 }
387 break;
388
389 case ST_DATABYTE:
390 BUFTEST(devc);
391 devc->m_buf[devc->m_ptr++] = midic;
392 if ((--devc->m_left) <= 0)
393 {
394 devc->m_state = ST_INIT;
395 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
396 devc->m_ptr = 0;
397 }
398 break;
399
400 default:
401 printk("Bad state %d ", devc->m_state);
402 devc->m_state = ST_INIT;
403 }
404 return 1;
405}
406
407static void mpu401_input_loop(struct mpu_config *devc)
408{
409 unsigned long flags;
410 int busy;
411 int n;
412
413 spin_lock_irqsave(&devc->lock,flags);
414 busy = devc->m_busy;
415 devc->m_busy = 1;
416 spin_unlock_irqrestore(&devc->lock,flags);
417
418 if (busy) /* Already inside the scanner */
419 return;
420
421 n = 50;
422
423 while (input_avail(devc) && n-- > 0)
424 {
425 unsigned char c = read_data(devc);
426
427 if (devc->mode == MODE_SYNTH)
428 {
429 mpu_input_scanner(devc, c);
430 }
431 else if (devc->opened & OPEN_READ && devc->inputintr != NULL)
432 devc->inputintr(devc->devno, c);
433 }
434 devc->m_busy = 0;
435}
436
437static irqreturn_t mpuintr(int irq, void *dev_id)
438{
439 struct mpu_config *devc;
440 int dev = (int)(unsigned long) dev_id;
441 int handled = 0;
442
443 devc = &dev_conf[dev];
444
445 if (input_avail(devc))
446 {
447 handled = 1;
448 if (devc->base != 0 && (devc->opened & OPEN_READ || devc->mode == MODE_SYNTH))
449 mpu401_input_loop(devc);
450 else
451 {
452 /* Dummy read (just to acknowledge the interrupt) */
453 read_data(devc);
454 }
455 }
456 return IRQ_RETVAL(handled);
457}
458
459static int mpu401_open(int dev, int mode,
460 void (*input) (int dev, unsigned char data),
461 void (*output) (int dev)
462)
463{
464 int err;
465 struct mpu_config *devc;
466 struct coproc_operations *coprocessor;
467
468 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
469 return -ENXIO;
470
471 devc = &dev_conf[dev];
472
473 if (devc->opened)
474 return -EBUSY;
475 /*
476 * Verify that the device is really running.
477 * Some devices (such as Ensoniq SoundScape don't
478 * work before the on board processor (OBP) is initialized
479 * by downloading its microcode.
480 */
481
482 if (!devc->initialized)
483 {
484 if (mpu401_status(devc) == 0xff) /* Bus float */
485 {
486 printk(KERN_ERR "mpu401: Device not initialized properly\n");
487 return -EIO;
488 }
489 reset_mpu401(devc);
490 }
491
492 if ( (coprocessor = midi_devs[dev]->coproc) != NULL )
493 {
494 if (!try_module_get(coprocessor->owner)) {
495 mpu401_close(dev);
496 return -ENODEV;
497 }
498
499 if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0)
500 {
501 printk(KERN_WARNING "MPU-401: Can't access coprocessor device\n");
502 mpu401_close(dev);
503 return err;
504 }
505 }
506
507 set_uart_mode(dev, devc, 1);
508 devc->mode = MODE_MIDI;
509 devc->synthno = 0;
510
511 mpu401_input_loop(devc);
512
513 devc->inputintr = input;
514 devc->opened = mode;
515
516 return 0;
517}
518
519static void mpu401_close(int dev)
520{
521 struct mpu_config *devc;
522 struct coproc_operations *coprocessor;
523
524 devc = &dev_conf[dev];
525 if (devc->uart_mode)
526 reset_mpu401(devc); /*
527 * This disables the UART mode
528 */
529 devc->mode = 0;
530 devc->inputintr = NULL;
531
532 coprocessor = midi_devs[dev]->coproc;
533 if (coprocessor) {
534 coprocessor->close(coprocessor->devc, COPR_MIDI);
535 module_put(coprocessor->owner);
536 }
537 devc->opened = 0;
538}
539
540static int mpu401_out(int dev, unsigned char midi_byte)
541{
542 int timeout;
543 unsigned long flags;
544
545 struct mpu_config *devc;
546
547 devc = &dev_conf[dev];
548
549 /*
550 * Sometimes it takes about 30000 loops before the output becomes ready
551 * (After reset). Normally it takes just about 10 loops.
552 */
553
554 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
555
556 spin_lock_irqsave(&devc->lock,flags);
557 if (!output_ready(devc))
558 {
559 printk(KERN_WARNING "mpu401: Send data timeout\n");
560 spin_unlock_irqrestore(&devc->lock,flags);
561 return 0;
562 }
563 write_data(devc, midi_byte);
564 spin_unlock_irqrestore(&devc->lock,flags);
565 return 1;
566}
567
568static int mpu401_command(int dev, mpu_command_rec * cmd)
569{
570 int i, timeout, ok;
571 unsigned long flags;
572 struct mpu_config *devc;
573
574 devc = &dev_conf[dev];
575
576 if (devc->uart_mode) /*
577 * Not possible in UART mode
578 */
579 {
580 printk(KERN_WARNING "mpu401: commands not possible in the UART mode\n");
581 return -EINVAL;
582 }
583 /*
584 * Test for input since pending input seems to block the output.
585 */
586 if (input_avail(devc))
587 mpu401_input_loop(devc);
588
589 /*
590 * Sometimes it takes about 50000 loops before the output becomes ready
591 * (After reset). Normally it takes just about 10 loops.
592 */
593
594 timeout = 50000;
595retry:
596 if (timeout-- <= 0)
597 {
598 printk(KERN_WARNING "mpu401: Command (0x%x) timeout\n", (int) cmd->cmd);
599 return -EIO;
600 }
601 spin_lock_irqsave(&devc->lock,flags);
602
603 if (!output_ready(devc))
604 {
605 spin_unlock_irqrestore(&devc->lock,flags);
606 goto retry;
607 }
608 write_command(devc, cmd->cmd);
609
610 ok = 0;
611 for (timeout = 50000; timeout > 0 && !ok; timeout--)
612 {
613 if (input_avail(devc))
614 {
615 if (devc->opened && devc->mode == MODE_SYNTH)
616 {
617 if (mpu_input_scanner(devc, read_data(devc)) == MPU_ACK)
618 ok = 1;
619 }
620 else
621 {
622 /* Device is not currently open. Use simpler method */
623 if (read_data(devc) == MPU_ACK)
624 ok = 1;
625 }
626 }
627 }
628 if (!ok)
629 {
630 spin_unlock_irqrestore(&devc->lock,flags);
631 return -EIO;
632 }
633 if (cmd->nr_args)
634 {
635 for (i = 0; i < cmd->nr_args; i++)
636 {
637 for (timeout = 3000; timeout > 0 && !output_ready(devc); timeout--);
638
639 if (!mpu401_out(dev, cmd->data[i]))
640 {
641 spin_unlock_irqrestore(&devc->lock,flags);
642 printk(KERN_WARNING "mpu401: Command (0x%x), parm send failed.\n", (int) cmd->cmd);
643 return -EIO;
644 }
645 }
646 }
647 cmd->data[0] = 0;
648
649 if (cmd->nr_returns)
650 {
651 for (i = 0; i < cmd->nr_returns; i++)
652 {
653 ok = 0;
654 for (timeout = 5000; timeout > 0 && !ok; timeout--)
655 if (input_avail(devc))
656 {
657 cmd->data[i] = read_data(devc);
658 ok = 1;
659 }
660 if (!ok)
661 {
662 spin_unlock_irqrestore(&devc->lock,flags);
663 return -EIO;
664 }
665 }
666 }
667 spin_unlock_irqrestore(&devc->lock,flags);
668 return 0;
669}
670
671static int mpu_cmd(int dev, int cmd, int data)
672{
673 int ret;
674
675 static mpu_command_rec rec;
676
677 rec.cmd = cmd & 0xff;
678 rec.nr_args = ((cmd & 0xf0) == 0xE0);
679 rec.nr_returns = ((cmd & 0xf0) == 0xA0);
680 rec.data[0] = data & 0xff;
681
682 if ((ret = mpu401_command(dev, &rec)) < 0)
683 return ret;
684 return (unsigned char) rec.data[0];
685}
686
687static int mpu401_prefix_cmd(int dev, unsigned char status)
688{
689 struct mpu_config *devc = &dev_conf[dev];
690
691 if (devc->uart_mode)
692 return 1;
693
694 if (status < 0xf0)
695 {
696 if (mpu_cmd(dev, 0xD0, 0) < 0)
697 return 0;
698 return 1;
699 }
700 switch (status)
701 {
702 case 0xF0:
703 if (mpu_cmd(dev, 0xDF, 0) < 0)
704 return 0;
705 return 1;
706
707 default:
708 return 0;
709 }
710}
711
712static int mpu401_start_read(int dev)
713{
714 return 0;
715}
716
717static int mpu401_end_read(int dev)
718{
719 return 0;
720}
721
722static int mpu401_ioctl(int dev, unsigned cmd, void __user *arg)
723{
724 struct mpu_config *devc;
725 mpu_command_rec rec;
726 int val, ret;
727
728 devc = &dev_conf[dev];
729 switch (cmd)
730 {
731 case SNDCTL_MIDI_MPUMODE:
732 if (!(devc->capabilities & MPU_CAP_INTLG)) { /* No intelligent mode */
733 printk(KERN_WARNING "mpu401: Intelligent mode not supported by the HW\n");
734 return -EINVAL;
735 }
736 if (get_user(val, (int __user *)arg))
737 return -EFAULT;
738 set_uart_mode(dev, devc, !val);
739 return 0;
740
741 case SNDCTL_MIDI_MPUCMD:
742 if (copy_from_user(&rec, arg, sizeof(rec)))
743 return -EFAULT;
744 if ((ret = mpu401_command(dev, &rec)) < 0)
745 return ret;
746 if (copy_to_user(arg, &rec, sizeof(rec)))
747 return -EFAULT;
748 return 0;
749
750 default:
751 return -EINVAL;
752 }
753}
754
755static void mpu401_kick(int dev)
756{
757}
758
759static int mpu401_buffer_status(int dev)
760{
761 return 0; /*
762 * No data in buffers
763 */
764}
765
766static int mpu_synth_ioctl(int dev, unsigned int cmd, void __user *arg)
767{
768 int midi_dev;
769 struct mpu_config *devc;
770
771 midi_dev = synth_devs[dev]->midi_dev;
772
773 if (midi_dev < 0 || midi_dev >= num_midis || midi_devs[midi_dev] == NULL)
774 return -ENXIO;
775
776 devc = &dev_conf[midi_dev];
777
778 switch (cmd)
779 {
780
781 case SNDCTL_SYNTH_INFO:
782 if (copy_to_user(arg, &mpu_synth_info[midi_dev],
783 sizeof(struct synth_info)))
784 return -EFAULT;
785 return 0;
786
787 case SNDCTL_SYNTH_MEMAVL:
788 return 0x7fffffff;
789
790 default:
791 return -EINVAL;
792 }
793}
794
795static int mpu_synth_open(int dev, int mode)
796{
797 int midi_dev, err;
798 struct mpu_config *devc;
799 struct coproc_operations *coprocessor;
800
801 midi_dev = synth_devs[dev]->midi_dev;
802
803 if (midi_dev < 0 || midi_dev > num_midis || midi_devs[midi_dev] == NULL)
804 return -ENXIO;
805
806 devc = &dev_conf[midi_dev];
807
808 /*
809 * Verify that the device is really running.
810 * Some devices (such as Ensoniq SoundScape don't
811 * work before the on board processor (OBP) is initialized
812 * by downloading its microcode.
813 */
814
815 if (!devc->initialized)
816 {
817 if (mpu401_status(devc) == 0xff) /* Bus float */
818 {
819 printk(KERN_ERR "mpu401: Device not initialized properly\n");
820 return -EIO;
821 }
822 reset_mpu401(devc);
823 }
824 if (devc->opened)
825 return -EBUSY;
826 devc->mode = MODE_SYNTH;
827 devc->synthno = dev;
828
829 devc->inputintr = NULL;
830
831 coprocessor = midi_devs[midi_dev]->coproc;
832 if (coprocessor) {
833 if (!try_module_get(coprocessor->owner))
834 return -ENODEV;
835
836 if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0)
837 {
838 printk(KERN_WARNING "mpu401: Can't access coprocessor device\n");
839 return err;
840 }
841 }
842 devc->opened = mode;
843 reset_mpu401(devc);
844
845 if (mode & OPEN_READ)
846 {
847 mpu_cmd(midi_dev, 0x8B, 0); /* Enable data in stop mode */
848 mpu_cmd(midi_dev, 0x34, 0); /* Return timing bytes in stop mode */
849 mpu_cmd(midi_dev, 0x87, 0); /* Enable pitch & controller */
850 }
851 return 0;
852}
853
854static void mpu_synth_close(int dev)
855{
856 int midi_dev;
857 struct mpu_config *devc;
858 struct coproc_operations *coprocessor;
859
860 midi_dev = synth_devs[dev]->midi_dev;
861
862 devc = &dev_conf[midi_dev];
863 mpu_cmd(midi_dev, 0x15, 0); /* Stop recording, playback and MIDI */
864 mpu_cmd(midi_dev, 0x8a, 0); /* Disable data in stopped mode */
865
866 devc->inputintr = NULL;
867
868 coprocessor = midi_devs[midi_dev]->coproc;
869 if (coprocessor) {
870 coprocessor->close(coprocessor->devc, COPR_MIDI);
871 module_put(coprocessor->owner);
872 }
873 devc->opened = 0;
874 devc->mode = 0;
875}
876
877#define MIDI_SYNTH_NAME "MPU-401 UART Midi"
878#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
879#include "midi_synth.h"
880
881static struct synth_operations mpu401_synth_proto =
882{
883 .owner = THIS_MODULE,
884 .id = "MPU401",
885 .info = NULL,
886 .midi_dev = 0,
887 .synth_type = SYNTH_TYPE_MIDI,
888 .synth_subtype = 0,
889 .open = mpu_synth_open,
890 .close = mpu_synth_close,
891 .ioctl = mpu_synth_ioctl,
892 .kill_note = midi_synth_kill_note,
893 .start_note = midi_synth_start_note,
894 .set_instr = midi_synth_set_instr,
895 .reset = midi_synth_reset,
896 .hw_control = midi_synth_hw_control,
897 .load_patch = midi_synth_load_patch,
898 .aftertouch = midi_synth_aftertouch,
899 .controller = midi_synth_controller,
900 .panning = midi_synth_panning,
901 .bender = midi_synth_bender,
902 .setup_voice = midi_synth_setup_voice,
903 .send_sysex = midi_synth_send_sysex
904};
905
906static struct synth_operations *mpu401_synth_operations[MAX_MIDI_DEV];
907
908static struct midi_operations mpu401_midi_proto =
909{
910 .owner = THIS_MODULE,
911 .info = {"MPU-401 Midi", 0, MIDI_CAP_MPU401, SNDCARD_MPU401},
912 .in_info = {0},
913 .open = mpu401_open,
914 .close = mpu401_close,
915 .ioctl = mpu401_ioctl,
916 .outputc = mpu401_out,
917 .start_read = mpu401_start_read,
918 .end_read = mpu401_end_read,
919 .kick = mpu401_kick,
920 .buffer_status = mpu401_buffer_status,
921 .prefix_cmd = mpu401_prefix_cmd
922};
923
924static struct midi_operations mpu401_midi_operations[MAX_MIDI_DEV];
925
926static void mpu401_chk_version(int n, struct mpu_config *devc)
927{
928 int tmp;
929
930 devc->version = devc->revision = 0;
931
932 tmp = mpu_cmd(n, 0xAC, 0);
933 if (tmp < 0)
934 return;
935 if ((tmp & 0xf0) > 0x20) /* Why it's larger than 2.x ??? */
936 return;
937 devc->version = tmp;
938
939 if ((tmp = mpu_cmd(n, 0xAD, 0)) < 0) {
940 devc->version = 0;
941 return;
942 }
943 devc->revision = tmp;
944}
945
946int attach_mpu401(struct address_info *hw_config, struct module *owner)
947{
948 unsigned long flags;
949 char revision_char;
950
951 int m, ret;
952 struct mpu_config *devc;
953
954 hw_config->slots[1] = -1;
955 m = sound_alloc_mididev();
956 if (m == -1)
957 {
958 printk(KERN_WARNING "MPU-401: Too many midi devices detected\n");
959 ret = -ENOMEM;
960 goto out_err;
961 }
962 devc = &dev_conf[m];
963 devc->base = hw_config->io_base;
964 devc->osp = hw_config->osp;
965 devc->irq = hw_config->irq;
966 devc->opened = 0;
967 devc->uart_mode = 0;
968 devc->initialized = 0;
969 devc->version = 0;
970 devc->revision = 0;
971 devc->capabilities = 0;
972 devc->timer_flag = 0;
973 devc->m_busy = 0;
974 devc->m_state = ST_INIT;
975 devc->shared_irq = hw_config->always_detect;
976 spin_lock_init(&devc->lock);
977
978 if (devc->irq < 0)
979 {
980 devc->irq *= -1;
981 devc->shared_irq = 1;
982 }
983
984 if (!hw_config->always_detect)
985 {
986 /* Verify the hardware again */
987 if (!reset_mpu401(devc))
988 {
989 printk(KERN_WARNING "mpu401: Device didn't respond\n");
990 ret = -ENODEV;
991 goto out_mididev;
992 }
993 if (!devc->shared_irq)
994 {
995 if (request_irq(devc->irq, mpuintr, 0, "mpu401",
996 hw_config) < 0)
997 {
998 printk(KERN_WARNING "mpu401: Failed to allocate IRQ%d\n", devc->irq);
999 ret = -ENOMEM;
1000 goto out_mididev;
1001 }
1002 }
1003 spin_lock_irqsave(&devc->lock,flags);
1004 mpu401_chk_version(m, devc);
1005 if (devc->version == 0)
1006 mpu401_chk_version(m, devc);
1007 spin_unlock_irqrestore(&devc->lock, flags);
1008 }
1009
1010 if (devc->version != 0)
1011 if (mpu_cmd(m, 0xC5, 0) >= 0) /* Set timebase OK */
1012 if (mpu_cmd(m, 0xE0, 120) >= 0) /* Set tempo OK */
1013 devc->capabilities |= MPU_CAP_INTLG; /* Supports intelligent mode */
1014
1015
1016 mpu401_synth_operations[m] = kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
1017
1018 if (mpu401_synth_operations[m] == NULL)
1019 {
1020 printk(KERN_ERR "mpu401: Can't allocate memory\n");
1021 ret = -ENOMEM;
1022 goto out_irq;
1023 }
1024 if (!(devc->capabilities & MPU_CAP_INTLG)) /* No intelligent mode */
1025 {
1026 memcpy((char *) mpu401_synth_operations[m],
1027 (char *) &std_midi_synth,
1028 sizeof(struct synth_operations));
1029 }
1030 else
1031 {
1032 memcpy((char *) mpu401_synth_operations[m],
1033 (char *) &mpu401_synth_proto,
1034 sizeof(struct synth_operations));
1035 }
1036 if (owner)
1037 mpu401_synth_operations[m]->owner = owner;
1038
1039 memcpy((char *) &mpu401_midi_operations[m],
1040 (char *) &mpu401_midi_proto,
1041 sizeof(struct midi_operations));
1042
1043 mpu401_midi_operations[m].converter = mpu401_synth_operations[m];
1044
1045 memcpy((char *) &mpu_synth_info[m],
1046 (char *) &mpu_synth_info_proto,
1047 sizeof(struct synth_info));
1048
1049 n_mpu_devs++;
1050
1051 if (devc->version == 0x20 && devc->revision >= 0x07) /* MusicQuest interface */
1052 {
1053 int ports = (devc->revision & 0x08) ? 32 : 16;
1054
1055 devc->capabilities |= MPU_CAP_SYNC | MPU_CAP_SMPTE |
1056 MPU_CAP_CLS | MPU_CAP_2PORT;
1057
1058 revision_char = (devc->revision == 0x7f) ? 'M' : ' ';
1059 sprintf(mpu_synth_info[m].name, "MQX-%d%c MIDI Interface #%d",
1060 ports,
1061 revision_char,
1062 n_mpu_devs);
1063 }
1064 else
1065 {
1066 revision_char = devc->revision ? devc->revision + '@' : ' ';
1067 if ((int) devc->revision > ('Z' - '@'))
1068 revision_char = '+';
1069
1070 devc->capabilities |= MPU_CAP_SYNC | MPU_CAP_FSK;
1071
1072 if (hw_config->name)
1073 sprintf(mpu_synth_info[m].name, "%s (MPU401)", hw_config->name);
1074 else
1075 sprintf(mpu_synth_info[m].name,
1076 "MPU-401 %d.%d%c MIDI #%d",
1077 (int) (devc->version & 0xf0) >> 4,
1078 devc->version & 0x0f,
1079 revision_char,
1080 n_mpu_devs);
1081 }
1082
1083 strcpy(mpu401_midi_operations[m].info.name,
1084 mpu_synth_info[m].name);
1085
1086 conf_printf(mpu_synth_info[m].name, hw_config);
1087
1088 mpu401_synth_operations[m]->midi_dev = devc->devno = m;
1089 mpu401_synth_operations[devc->devno]->info = &mpu_synth_info[devc->devno];
1090
1091 if (devc->capabilities & MPU_CAP_INTLG) /* Intelligent mode */
1092 hw_config->slots[2] = mpu_timer_init(m);
1093
1094 midi_devs[m] = &mpu401_midi_operations[devc->devno];
1095
1096 if (owner)
1097 midi_devs[m]->owner = owner;
1098
1099 hw_config->slots[1] = m;
1100 sequencer_init();
1101
1102 return 0;
1103
1104out_irq:
1105 free_irq(devc->irq, hw_config);
1106out_mididev:
1107 sound_unload_mididev(m);
1108out_err:
1109 release_region(hw_config->io_base, 2);
1110 return ret;
1111}
1112
1113static int reset_mpu401(struct mpu_config *devc)
1114{
1115 unsigned long flags;
1116 int ok, timeout, n;
1117 int timeout_limit;
1118
1119 /*
1120 * Send the RESET command. Try again if no success at the first time.
1121 * (If the device is in the UART mode, it will not ack the reset cmd).
1122 */
1123
1124 ok = 0;
1125
1126 timeout_limit = devc->initialized ? 30000 : 100000;
1127 devc->initialized = 1;
1128
1129 for (n = 0; n < 2 && !ok; n++)
1130 {
1131 for (timeout = timeout_limit; timeout > 0 && !ok; timeout--)
1132 ok = output_ready(devc);
1133
1134 write_command(devc, MPU_RESET); /*
1135 * Send MPU-401 RESET Command
1136 */
1137
1138 /*
1139 * Wait at least 25 msec. This method is not accurate so let's make the
1140 * loop bit longer. Cannot sleep since this is called during boot.
1141 */
1142
1143 for (timeout = timeout_limit * 2; timeout > 0 && !ok; timeout--)
1144 {
1145 spin_lock_irqsave(&devc->lock,flags);
1146 if (input_avail(devc))
1147 if (read_data(devc) == MPU_ACK)
1148 ok = 1;
1149 spin_unlock_irqrestore(&devc->lock,flags);
1150 }
1151
1152 }
1153
1154 devc->m_state = ST_INIT;
1155 devc->m_ptr = 0;
1156 devc->m_left = 0;
1157 devc->last_status = 0;
1158 devc->uart_mode = 0;
1159
1160 return ok;
1161}
1162
1163static void set_uart_mode(int dev, struct mpu_config *devc, int arg)
1164{
1165 if (!arg && (devc->capabilities & MPU_CAP_INTLG))
1166 return;
1167 if ((devc->uart_mode == 0) == (arg == 0))
1168 return; /* Already set */
1169 reset_mpu401(devc); /* This exits the uart mode */
1170
1171 if (arg)
1172 {
1173 if (mpu_cmd(dev, UART_MODE_ON, 0) < 0)
1174 {
1175 printk(KERN_ERR "mpu401: Can't enter UART mode\n");
1176 devc->uart_mode = 0;
1177 return;
1178 }
1179 }
1180 devc->uart_mode = arg;
1181
1182}
1183
1184int probe_mpu401(struct address_info *hw_config, struct resource *ports)
1185{
1186 int ok = 0;
1187 struct mpu_config tmp_devc;
1188
1189 tmp_devc.base = hw_config->io_base;
1190 tmp_devc.irq = hw_config->irq;
1191 tmp_devc.initialized = 0;
1192 tmp_devc.opened = 0;
1193 tmp_devc.osp = hw_config->osp;
1194
1195 if (hw_config->always_detect)
1196 return 1;
1197
1198 if (inb(hw_config->io_base + 1) == 0xff)
1199 {
1200 DDB(printk("MPU401: Port %x looks dead.\n", hw_config->io_base));
1201 return 0; /* Just bus float? */
1202 }
1203 ok = reset_mpu401(&tmp_devc);
1204
1205 if (!ok)
1206 {
1207 DDB(printk("MPU401: Reset failed on port %x\n", hw_config->io_base));
1208 }
1209 return ok;
1210}
1211
1212void unload_mpu401(struct address_info *hw_config)
1213{
1214 void *p;
1215 int n=hw_config->slots[1];
1216
1217 if (n != -1) {
1218 release_region(hw_config->io_base, 2);
1219 if (hw_config->always_detect == 0 && hw_config->irq > 0)
1220 free_irq(hw_config->irq, hw_config);
1221 p=mpu401_synth_operations[n];
1222 sound_unload_mididev(n);
1223 sound_unload_timerdev(hw_config->slots[2]);
1224 kfree(p);
1225 }
1226}
1227
1228/*****************************************************
1229 * Timer stuff
1230 ****************************************************/
1231
1232static volatile int timer_initialized = 0, timer_open = 0, tmr_running = 0;
1233static volatile int curr_tempo, curr_timebase, hw_timebase;
1234static int max_timebase = 8; /* 8*24=192 ppqn */
1235static volatile unsigned long next_event_time;
1236static volatile unsigned long curr_ticks, curr_clocks;
1237static unsigned long prev_event_time;
1238static int metronome_mode;
1239
1240static unsigned long clocks2ticks(unsigned long clocks)
1241{
1242 /*
1243 * The MPU-401 supports just a limited set of possible timebase values.
1244 * Since the applications require more choices, the driver has to
1245 * program the HW to do its best and to convert between the HW and
1246 * actual timebases.
1247 */
1248 return ((clocks * curr_timebase) + (hw_timebase / 2)) / hw_timebase;
1249}
1250
1251static void set_timebase(int midi_dev, int val)
1252{
1253 int hw_val;
1254
1255 if (val < 48)
1256 val = 48;
1257 if (val > 1000)
1258 val = 1000;
1259
1260 hw_val = val;
1261 hw_val = (hw_val + 12) / 24;
1262 if (hw_val > max_timebase)
1263 hw_val = max_timebase;
1264
1265 if (mpu_cmd(midi_dev, 0xC0 | (hw_val & 0x0f), 0) < 0)
1266 {
1267 printk(KERN_WARNING "mpu401: Can't set HW timebase to %d\n", hw_val * 24);
1268 return;
1269 }
1270 hw_timebase = hw_val * 24;
1271 curr_timebase = val;
1272
1273}
1274
1275static void tmr_reset(struct mpu_config *devc)
1276{
1277 unsigned long flags;
1278
1279 spin_lock_irqsave(&devc->lock,flags);
1280 next_event_time = (unsigned long) -1;
1281 prev_event_time = 0;
1282 curr_ticks = curr_clocks = 0;
1283 spin_unlock_irqrestore(&devc->lock,flags);
1284}
1285
1286static void set_timer_mode(int midi_dev)
1287{
1288 if (timer_mode & TMR_MODE_CLS)
1289 mpu_cmd(midi_dev, 0x3c, 0); /* Use CLS sync */
1290 else if (timer_mode & TMR_MODE_SMPTE)
1291 mpu_cmd(midi_dev, 0x3d, 0); /* Use SMPTE sync */
1292
1293 if (timer_mode & TMR_INTERNAL)
1294 {
1295 mpu_cmd(midi_dev, 0x80, 0); /* Use MIDI sync */
1296 }
1297 else
1298 {
1299 if (timer_mode & (TMR_MODE_MIDI | TMR_MODE_CLS))
1300 {
1301 mpu_cmd(midi_dev, 0x82, 0); /* Use MIDI sync */
1302 mpu_cmd(midi_dev, 0x91, 0); /* Enable ext MIDI ctrl */
1303 }
1304 else if (timer_mode & TMR_MODE_FSK)
1305 mpu_cmd(midi_dev, 0x81, 0); /* Use FSK sync */
1306 }
1307}
1308
1309static void stop_metronome(int midi_dev)
1310{
1311 mpu_cmd(midi_dev, 0x84, 0); /* Disable metronome */
1312}
1313
1314static void setup_metronome(int midi_dev)
1315{
1316 int numerator, denominator;
1317 int clks_per_click, num_32nds_per_beat;
1318 int beats_per_measure;
1319
1320 numerator = ((unsigned) metronome_mode >> 24) & 0xff;
1321 denominator = ((unsigned) metronome_mode >> 16) & 0xff;
1322 clks_per_click = ((unsigned) metronome_mode >> 8) & 0xff;
1323 num_32nds_per_beat = (unsigned) metronome_mode & 0xff;
1324 beats_per_measure = (numerator * 4) >> denominator;
1325
1326 if (!metronome_mode)
1327 mpu_cmd(midi_dev, 0x84, 0); /* Disable metronome */
1328 else
1329 {
1330 mpu_cmd(midi_dev, 0xE4, clks_per_click);
1331 mpu_cmd(midi_dev, 0xE6, beats_per_measure);
1332 mpu_cmd(midi_dev, 0x83, 0); /* Enable metronome without accents */
1333 }
1334}
1335
1336static int mpu_start_timer(int midi_dev)
1337{
1338 struct mpu_config *devc= &dev_conf[midi_dev];
1339
1340 tmr_reset(devc);
1341 set_timer_mode(midi_dev);
1342
1343 if (tmr_running)
1344 return TIMER_NOT_ARMED; /* Already running */
1345
1346 if (timer_mode & TMR_INTERNAL)
1347 {
1348 mpu_cmd(midi_dev, 0x02, 0); /* Send MIDI start */
1349 tmr_running = 1;
1350 return TIMER_NOT_ARMED;
1351 }
1352 else
1353 {
1354 mpu_cmd(midi_dev, 0x35, 0); /* Enable mode messages to PC */
1355 mpu_cmd(midi_dev, 0x38, 0); /* Enable sys common messages to PC */
1356 mpu_cmd(midi_dev, 0x39, 0); /* Enable real time messages to PC */
1357 mpu_cmd(midi_dev, 0x97, 0); /* Enable system exclusive messages to PC */
1358 }
1359 return TIMER_ARMED;
1360}
1361
1362static int mpu_timer_open(int dev, int mode)
1363{
1364 int midi_dev = sound_timer_devs[dev]->devlink;
1365 struct mpu_config *devc= &dev_conf[midi_dev];
1366
1367 if (timer_open)
1368 return -EBUSY;
1369
1370 tmr_reset(devc);
1371 curr_tempo = 50;
1372 mpu_cmd(midi_dev, 0xE0, 50);
1373 curr_timebase = hw_timebase = 120;
1374 set_timebase(midi_dev, 120);
1375 timer_open = 1;
1376 metronome_mode = 0;
1377 set_timer_mode(midi_dev);
1378
1379 mpu_cmd(midi_dev, 0xe7, 0x04); /* Send all clocks to host */
1380 mpu_cmd(midi_dev, 0x95, 0); /* Enable clock to host */
1381
1382 return 0;
1383}
1384
1385static void mpu_timer_close(int dev)
1386{
1387 int midi_dev = sound_timer_devs[dev]->devlink;
1388
1389 timer_open = tmr_running = 0;
1390 mpu_cmd(midi_dev, 0x15, 0); /* Stop all */
1391 mpu_cmd(midi_dev, 0x94, 0); /* Disable clock to host */
1392 mpu_cmd(midi_dev, 0x8c, 0); /* Disable measure end messages to host */
1393 stop_metronome(midi_dev);
1394}
1395
1396static int mpu_timer_event(int dev, unsigned char *event)
1397{
1398 unsigned char command = event[1];
1399 unsigned long parm = *(unsigned int *) &event[4];
1400 int midi_dev = sound_timer_devs[dev]->devlink;
1401
1402 switch (command)
1403 {
1404 case TMR_WAIT_REL:
1405 parm += prev_event_time;
1406 case TMR_WAIT_ABS:
1407 if (parm > 0)
1408 {
1409 long time;
1410
1411 if (parm <= curr_ticks) /* It's the time */
1412 return TIMER_NOT_ARMED;
1413 time = parm;
1414 next_event_time = prev_event_time = time;
1415
1416 return TIMER_ARMED;
1417 }
1418 break;
1419
1420 case TMR_START:
1421 if (tmr_running)
1422 break;
1423 return mpu_start_timer(midi_dev);
1424
1425 case TMR_STOP:
1426 mpu_cmd(midi_dev, 0x01, 0); /* Send MIDI stop */
1427 stop_metronome(midi_dev);
1428 tmr_running = 0;
1429 break;
1430
1431 case TMR_CONTINUE:
1432 if (tmr_running)
1433 break;
1434 mpu_cmd(midi_dev, 0x03, 0); /* Send MIDI continue */
1435 setup_metronome(midi_dev);
1436 tmr_running = 1;
1437 break;
1438
1439 case TMR_TEMPO:
1440 if (parm)
1441 {
1442 if (parm < 8)
1443 parm = 8;
1444 if (parm > 250)
1445 parm = 250;
1446 if (mpu_cmd(midi_dev, 0xE0, parm) < 0)
1447 printk(KERN_WARNING "mpu401: Can't set tempo to %d\n", (int) parm);
1448 curr_tempo = parm;
1449 }
1450 break;
1451
1452 case TMR_ECHO:
1453 seq_copy_to_input(event, 8);
1454 break;
1455
1456 case TMR_TIMESIG:
1457 if (metronome_mode) /* Metronome enabled */
1458 {
1459 metronome_mode = parm;
1460 setup_metronome(midi_dev);
1461 }
1462 break;
1463
1464 default:;
1465 }
1466 return TIMER_NOT_ARMED;
1467}
1468
1469static unsigned long mpu_timer_get_time(int dev)
1470{
1471 if (!timer_open)
1472 return 0;
1473
1474 return curr_ticks;
1475}
1476
1477static int mpu_timer_ioctl(int dev, unsigned int command, void __user *arg)
1478{
1479 int midi_dev = sound_timer_devs[dev]->devlink;
1480 int __user *p = (int __user *)arg;
1481
1482 switch (command)
1483 {
1484 case SNDCTL_TMR_SOURCE:
1485 {
1486 int parm;
1487
1488 if (get_user(parm, p))
1489 return -EFAULT;
1490 parm &= timer_caps;
1491
1492 if (parm != 0)
1493 {
1494 timer_mode = parm;
1495
1496 if (timer_mode & TMR_MODE_CLS)
1497 mpu_cmd(midi_dev, 0x3c, 0); /* Use CLS sync */
1498 else if (timer_mode & TMR_MODE_SMPTE)
1499 mpu_cmd(midi_dev, 0x3d, 0); /* Use SMPTE sync */
1500 }
1501 if (put_user(timer_mode, p))
1502 return -EFAULT;
1503 return timer_mode;
1504 }
1505 break;
1506
1507 case SNDCTL_TMR_START:
1508 mpu_start_timer(midi_dev);
1509 return 0;
1510
1511 case SNDCTL_TMR_STOP:
1512 tmr_running = 0;
1513 mpu_cmd(midi_dev, 0x01, 0); /* Send MIDI stop */
1514 stop_metronome(midi_dev);
1515 return 0;
1516
1517 case SNDCTL_TMR_CONTINUE:
1518 if (tmr_running)
1519 return 0;
1520 tmr_running = 1;
1521 mpu_cmd(midi_dev, 0x03, 0); /* Send MIDI continue */
1522 return 0;
1523
1524 case SNDCTL_TMR_TIMEBASE:
1525 {
1526 int val;
1527 if (get_user(val, p))
1528 return -EFAULT;
1529 if (val)
1530 set_timebase(midi_dev, val);
1531 if (put_user(curr_timebase, p))
1532 return -EFAULT;
1533 return curr_timebase;
1534 }
1535 break;
1536
1537 case SNDCTL_TMR_TEMPO:
1538 {
1539 int val;
1540 int ret;
1541
1542 if (get_user(val, p))
1543 return -EFAULT;
1544
1545 if (val)
1546 {
1547 if (val < 8)
1548 val = 8;
1549 if (val > 250)
1550 val = 250;
1551 if ((ret = mpu_cmd(midi_dev, 0xE0, val)) < 0)
1552 {
1553 printk(KERN_WARNING "mpu401: Can't set tempo to %d\n", (int) val);
1554 return ret;
1555 }
1556 curr_tempo = val;
1557 }
1558 if (put_user(curr_tempo, p))
1559 return -EFAULT;
1560 return curr_tempo;
1561 }
1562 break;
1563
1564 case SNDCTL_SEQ_CTRLRATE:
1565 {
1566 int val;
1567 if (get_user(val, p))
1568 return -EFAULT;
1569
1570 if (val != 0) /* Can't change */
1571 return -EINVAL;
1572 val = ((curr_tempo * curr_timebase) + 30)/60;
1573 if (put_user(val, p))
1574 return -EFAULT;
1575 return val;
1576 }
1577 break;
1578
1579 case SNDCTL_SEQ_GETTIME:
1580 if (put_user(curr_ticks, p))
1581 return -EFAULT;
1582 return curr_ticks;
1583
1584 case SNDCTL_TMR_METRONOME:
1585 if (get_user(metronome_mode, p))
1586 return -EFAULT;
1587 setup_metronome(midi_dev);
1588 return 0;
1589
1590 default:;
1591 }
1592 return -EINVAL;
1593}
1594
1595static void mpu_timer_arm(int dev, long time)
1596{
1597 if (time < 0)
1598 time = curr_ticks + 1;
1599 else if (time <= curr_ticks) /* It's the time */
1600 return;
1601 next_event_time = prev_event_time = time;
1602 return;
1603}
1604
1605static struct sound_timer_operations mpu_timer =
1606{
1607 .owner = THIS_MODULE,
1608 .info = {"MPU-401 Timer", 0},
1609 .priority = 10, /* Priority */
1610 .devlink = 0, /* Local device link */
1611 .open = mpu_timer_open,
1612 .close = mpu_timer_close,
1613 .event = mpu_timer_event,
1614 .get_time = mpu_timer_get_time,
1615 .ioctl = mpu_timer_ioctl,
1616 .arm_timer = mpu_timer_arm
1617};
1618
1619static void mpu_timer_interrupt(void)
1620{
1621 if (!timer_open)
1622 return;
1623
1624 if (!tmr_running)
1625 return;
1626
1627 curr_clocks++;
1628 curr_ticks = clocks2ticks(curr_clocks);
1629
1630 if (curr_ticks >= next_event_time)
1631 {
1632 next_event_time = (unsigned long) -1;
1633 sequencer_timer(0);
1634 }
1635}
1636
1637static void timer_ext_event(struct mpu_config *devc, int event, int parm)
1638{
1639 int midi_dev = devc->devno;
1640
1641 if (!devc->timer_flag)
1642 return;
1643
1644 switch (event)
1645 {
1646 case TMR_CLOCK:
1647 printk("<MIDI clk>");
1648 break;
1649
1650 case TMR_START:
1651 printk("Ext MIDI start\n");
1652 if (!tmr_running)
1653 {
1654 if (timer_mode & TMR_EXTERNAL)
1655 {
1656 tmr_running = 1;
1657 setup_metronome(midi_dev);
1658 next_event_time = 0;
1659 STORE(SEQ_START_TIMER());
1660 }
1661 }
1662 break;
1663
1664 case TMR_STOP:
1665 printk("Ext MIDI stop\n");
1666 if (timer_mode & TMR_EXTERNAL)
1667 {
1668 tmr_running = 0;
1669 stop_metronome(midi_dev);
1670 STORE(SEQ_STOP_TIMER());
1671 }
1672 break;
1673
1674 case TMR_CONTINUE:
1675 printk("Ext MIDI continue\n");
1676 if (timer_mode & TMR_EXTERNAL)
1677 {
1678 tmr_running = 1;
1679 setup_metronome(midi_dev);
1680 STORE(SEQ_CONTINUE_TIMER());
1681 }
1682 break;
1683
1684 case TMR_SPP:
1685 printk("Songpos: %d\n", parm);
1686 if (timer_mode & TMR_EXTERNAL)
1687 {
1688 STORE(SEQ_SONGPOS(parm));
1689 }
1690 break;
1691 }
1692}
1693
1694static int mpu_timer_init(int midi_dev)
1695{
1696 struct mpu_config *devc;
1697 int n;
1698
1699 devc = &dev_conf[midi_dev];
1700
1701 if (timer_initialized)
1702 return -1; /* There is already a similar timer */
1703
1704 timer_initialized = 1;
1705
1706 mpu_timer.devlink = midi_dev;
1707 dev_conf[midi_dev].timer_flag = 1;
1708
1709 n = sound_alloc_timerdev();
1710 if (n == -1)
1711 n = 0;
1712 sound_timer_devs[n] = &mpu_timer;
1713
1714 if (devc->version < 0x20) /* Original MPU-401 */
1715 timer_caps = TMR_INTERNAL | TMR_EXTERNAL | TMR_MODE_FSK | TMR_MODE_MIDI;
1716 else
1717 {
1718 /*
1719 * The version number 2.0 is used (at least) by the
1720 * MusicQuest cards and the Roland Super-MPU.
1721 *
1722 * MusicQuest has given a special meaning to the bits of the
1723 * revision number. The Super-MPU returns 0.
1724 */
1725
1726 if (devc->revision)
1727 timer_caps |= TMR_EXTERNAL | TMR_MODE_MIDI;
1728
1729 if (devc->revision & 0x02)
1730 timer_caps |= TMR_MODE_CLS;
1731
1732
1733 if (devc->revision & 0x40)
1734 max_timebase = 10; /* Has the 216 and 240 ppqn modes */
1735 }
1736
1737 timer_mode = (TMR_INTERNAL | TMR_MODE_MIDI) & timer_caps;
1738 return n;
1739
1740}
1741
1742EXPORT_SYMBOL(probe_mpu401);
1743EXPORT_SYMBOL(attach_mpu401);
1744EXPORT_SYMBOL(unload_mpu401);
1745
1746static struct address_info cfg;
1747
1748static int io = -1;
1749static int irq = -1;
1750
1751module_param_hw(irq, int, irq, 0);
1752module_param_hw(io, int, ioport, 0);
1753
1754static int __init init_mpu401(void)
1755{
1756 int ret;
1757 /* Can be loaded either for module use or to provide functions
1758 to others */
1759 if (io != -1 && irq != -1) {
1760 struct resource *ports;
1761 cfg.irq = irq;
1762 cfg.io_base = io;
1763 ports = request_region(io, 2, "mpu401");
1764 if (!ports)
1765 return -EBUSY;
1766 if (probe_mpu401(&cfg, ports) == 0) {
1767 release_region(io, 2);
1768 return -ENODEV;
1769 }
1770 if ((ret = attach_mpu401(&cfg, THIS_MODULE)))
1771 return ret;
1772 }
1773
1774 return 0;
1775}
1776
1777static void __exit cleanup_mpu401(void)
1778{
1779 if (io != -1 && irq != -1) {
1780 /* Check for use by, for example, sscape driver */
1781 unload_mpu401(&cfg);
1782 }
1783}
1784
1785module_init(init_mpu401);
1786module_exit(cleanup_mpu401);
1787
1788#ifndef MODULE
1789static int __init setup_mpu401(char *str)
1790{
1791 /* io, irq */
1792 int ints[3];
1793
1794 str = get_options(str, ARRAY_SIZE(ints), ints);
1795
1796 io = ints[1];
1797 irq = ints[2];
1798
1799 return 1;
1800}
1801
1802__setup("mpu401=", setup_mpu401);
1803#endif
1804MODULE_LICENSE("GPL");
diff --git a/sound/oss/mpu401.h b/sound/oss/mpu401.h
deleted file mode 100644
index 0ad1e9ee74f7..000000000000
--- a/sound/oss/mpu401.h
+++ /dev/null
@@ -1,11 +0,0 @@
1
2/* From uart401.c */
3int probe_uart401 (struct address_info *hw_config, struct module *owner);
4void unload_uart401 (struct address_info *hw_config);
5
6irqreturn_t uart401intr (int irq, void *dev_id);
7
8/* From mpu401.c */
9int probe_mpu401(struct address_info *hw_config, struct resource *ports);
10int attach_mpu401(struct address_info * hw_config, struct module *owner);
11void unload_mpu401(struct address_info *hw_info);
diff --git a/sound/oss/msnd.c b/sound/oss/msnd.c
deleted file mode 100644
index b63010ad22f1..000000000000
--- a/sound/oss/msnd.c
+++ /dev/null
@@ -1,413 +0,0 @@
1/*********************************************************************
2 *
3 * msnd.c - Driver Base
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Copyright (C) 1998 Andrew Veliath
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 ********************************************************************/
24
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/vmalloc.h>
28#include <linux/types.h>
29#include <linux/delay.h>
30#include <linux/mm.h>
31#include <linux/init.h>
32#include <linux/interrupt.h>
33
34#include <asm/io.h>
35#include <linux/uaccess.h>
36#include <linux/spinlock.h>
37#include <asm/irq.h>
38#include "msnd.h"
39
40#define LOGNAME "msnd"
41
42#define MSND_MAX_DEVS 4
43
44static multisound_dev_t *devs[MSND_MAX_DEVS];
45static int num_devs;
46
47int msnd_register(multisound_dev_t *dev)
48{
49 int i;
50
51 for (i = 0; i < MSND_MAX_DEVS; ++i)
52 if (devs[i] == NULL)
53 break;
54
55 if (i == MSND_MAX_DEVS)
56 return -ENOMEM;
57
58 devs[i] = dev;
59 ++num_devs;
60 return 0;
61}
62
63void msnd_unregister(multisound_dev_t *dev)
64{
65 int i;
66
67 for (i = 0; i < MSND_MAX_DEVS; ++i)
68 if (devs[i] == dev)
69 break;
70
71 if (i == MSND_MAX_DEVS) {
72 printk(KERN_WARNING LOGNAME ": Unregistering unknown device\n");
73 return;
74 }
75
76 devs[i] = NULL;
77 --num_devs;
78}
79
80void msnd_init_queue(void __iomem *base, int start, int size)
81{
82 writew(PCTODSP_BASED(start), base + JQS_wStart);
83 writew(PCTODSP_OFFSET(size) - 1, base + JQS_wSize);
84 writew(0, base + JQS_wHead);
85 writew(0, base + JQS_wTail);
86}
87
88void msnd_fifo_init(msnd_fifo *f)
89{
90 f->data = NULL;
91}
92
93void msnd_fifo_free(msnd_fifo *f)
94{
95 vfree(f->data);
96 f->data = NULL;
97}
98
99int msnd_fifo_alloc(msnd_fifo *f, size_t n)
100{
101 msnd_fifo_free(f);
102 f->data = vmalloc(n);
103 f->n = n;
104 f->tail = 0;
105 f->head = 0;
106 f->len = 0;
107
108 if (!f->data)
109 return -ENOMEM;
110
111 return 0;
112}
113
114void msnd_fifo_make_empty(msnd_fifo *f)
115{
116 f->len = f->tail = f->head = 0;
117}
118
119int msnd_fifo_write_io(msnd_fifo *f, char __iomem *buf, size_t len)
120{
121 int count = 0;
122
123 while ((count < len) && (f->len != f->n)) {
124
125 int nwritten;
126
127 if (f->head <= f->tail) {
128 nwritten = len - count;
129 if (nwritten > f->n - f->tail)
130 nwritten = f->n - f->tail;
131 }
132 else {
133 nwritten = f->head - f->tail;
134 if (nwritten > len - count)
135 nwritten = len - count;
136 }
137
138 memcpy_fromio(f->data + f->tail, buf, nwritten);
139
140 count += nwritten;
141 buf += nwritten;
142 f->len += nwritten;
143 f->tail += nwritten;
144 f->tail %= f->n;
145 }
146
147 return count;
148}
149
150int msnd_fifo_write(msnd_fifo *f, const char *buf, size_t len)
151{
152 int count = 0;
153
154 while ((count < len) && (f->len != f->n)) {
155
156 int nwritten;
157
158 if (f->head <= f->tail) {
159 nwritten = len - count;
160 if (nwritten > f->n - f->tail)
161 nwritten = f->n - f->tail;
162 }
163 else {
164 nwritten = f->head - f->tail;
165 if (nwritten > len - count)
166 nwritten = len - count;
167 }
168
169 memcpy(f->data + f->tail, buf, nwritten);
170
171 count += nwritten;
172 buf += nwritten;
173 f->len += nwritten;
174 f->tail += nwritten;
175 f->tail %= f->n;
176 }
177
178 return count;
179}
180
181int msnd_fifo_read_io(msnd_fifo *f, char __iomem *buf, size_t len)
182{
183 int count = 0;
184
185 while ((count < len) && (f->len > 0)) {
186
187 int nread;
188
189 if (f->tail <= f->head) {
190 nread = len - count;
191 if (nread > f->n - f->head)
192 nread = f->n - f->head;
193 }
194 else {
195 nread = f->tail - f->head;
196 if (nread > len - count)
197 nread = len - count;
198 }
199
200 memcpy_toio(buf, f->data + f->head, nread);
201
202 count += nread;
203 buf += nread;
204 f->len -= nread;
205 f->head += nread;
206 f->head %= f->n;
207 }
208
209 return count;
210}
211
212int msnd_fifo_read(msnd_fifo *f, char *buf, size_t len)
213{
214 int count = 0;
215
216 while ((count < len) && (f->len > 0)) {
217
218 int nread;
219
220 if (f->tail <= f->head) {
221 nread = len - count;
222 if (nread > f->n - f->head)
223 nread = f->n - f->head;
224 }
225 else {
226 nread = f->tail - f->head;
227 if (nread > len - count)
228 nread = len - count;
229 }
230
231 memcpy(buf, f->data + f->head, nread);
232
233 count += nread;
234 buf += nread;
235 f->len -= nread;
236 f->head += nread;
237 f->head %= f->n;
238 }
239
240 return count;
241}
242
243static int msnd_wait_TXDE(multisound_dev_t *dev)
244{
245 register unsigned int io = dev->io;
246 register int timeout = 1000;
247
248 while(timeout-- > 0)
249 if (msnd_inb(io + HP_ISR) & HPISR_TXDE)
250 return 0;
251
252 return -EIO;
253}
254
255static int msnd_wait_HC0(multisound_dev_t *dev)
256{
257 register unsigned int io = dev->io;
258 register int timeout = 1000;
259
260 while(timeout-- > 0)
261 if (!(msnd_inb(io + HP_CVR) & HPCVR_HC))
262 return 0;
263
264 return -EIO;
265}
266
267int msnd_send_dsp_cmd(multisound_dev_t *dev, BYTE cmd)
268{
269 unsigned long flags;
270
271 spin_lock_irqsave(&dev->lock, flags);
272 if (msnd_wait_HC0(dev) == 0) {
273 msnd_outb(cmd, dev->io + HP_CVR);
274 spin_unlock_irqrestore(&dev->lock, flags);
275 return 0;
276 }
277 spin_unlock_irqrestore(&dev->lock, flags);
278
279 printk(KERN_DEBUG LOGNAME ": Send DSP command timeout\n");
280
281 return -EIO;
282}
283
284int msnd_send_word(multisound_dev_t *dev, unsigned char high,
285 unsigned char mid, unsigned char low)
286{
287 register unsigned int io = dev->io;
288
289 if (msnd_wait_TXDE(dev) == 0) {
290 msnd_outb(high, io + HP_TXH);
291 msnd_outb(mid, io + HP_TXM);
292 msnd_outb(low, io + HP_TXL);
293 return 0;
294 }
295
296 printk(KERN_DEBUG LOGNAME ": Send host word timeout\n");
297
298 return -EIO;
299}
300
301int msnd_upload_host(multisound_dev_t *dev, char *bin, int len)
302{
303 int i;
304
305 if (len % 3 != 0) {
306 printk(KERN_WARNING LOGNAME ": Upload host data not multiple of 3!\n");
307 return -EINVAL;
308 }
309
310 for (i = 0; i < len; i += 3)
311 if (msnd_send_word(dev, bin[i], bin[i + 1], bin[i + 2]) != 0)
312 return -EIO;
313
314 msnd_inb(dev->io + HP_RXL);
315 msnd_inb(dev->io + HP_CVR);
316
317 return 0;
318}
319
320int msnd_enable_irq(multisound_dev_t *dev)
321{
322 unsigned long flags;
323
324 if (dev->irq_ref++)
325 return 0;
326
327 printk(KERN_DEBUG LOGNAME ": Enabling IRQ\n");
328
329 spin_lock_irqsave(&dev->lock, flags);
330 if (msnd_wait_TXDE(dev) == 0) {
331 msnd_outb(msnd_inb(dev->io + HP_ICR) | HPICR_TREQ, dev->io + HP_ICR);
332 if (dev->type == msndClassic)
333 msnd_outb(dev->irqid, dev->io + HP_IRQM);
334 msnd_outb(msnd_inb(dev->io + HP_ICR) & ~HPICR_TREQ, dev->io + HP_ICR);
335 msnd_outb(msnd_inb(dev->io + HP_ICR) | HPICR_RREQ, dev->io + HP_ICR);
336 enable_irq(dev->irq);
337 msnd_init_queue(dev->DSPQ, dev->dspq_data_buff, dev->dspq_buff_size);
338 spin_unlock_irqrestore(&dev->lock, flags);
339 return 0;
340 }
341 spin_unlock_irqrestore(&dev->lock, flags);
342
343 printk(KERN_DEBUG LOGNAME ": Enable IRQ failed\n");
344
345 return -EIO;
346}
347
348int msnd_disable_irq(multisound_dev_t *dev)
349{
350 unsigned long flags;
351
352 if (--dev->irq_ref > 0)
353 return 0;
354
355 if (dev->irq_ref < 0)
356 printk(KERN_DEBUG LOGNAME ": IRQ ref count is %d\n", dev->irq_ref);
357
358 printk(KERN_DEBUG LOGNAME ": Disabling IRQ\n");
359
360 spin_lock_irqsave(&dev->lock, flags);
361 if (msnd_wait_TXDE(dev) == 0) {
362 msnd_outb(msnd_inb(dev->io + HP_ICR) & ~HPICR_RREQ, dev->io + HP_ICR);
363 if (dev->type == msndClassic)
364 msnd_outb(HPIRQ_NONE, dev->io + HP_IRQM);
365 disable_irq(dev->irq);
366 spin_unlock_irqrestore(&dev->lock, flags);
367 return 0;
368 }
369 spin_unlock_irqrestore(&dev->lock, flags);
370
371 printk(KERN_DEBUG LOGNAME ": Disable IRQ failed\n");
372
373 return -EIO;
374}
375
376#ifndef LINUX20
377EXPORT_SYMBOL(msnd_register);
378EXPORT_SYMBOL(msnd_unregister);
379
380EXPORT_SYMBOL(msnd_init_queue);
381
382EXPORT_SYMBOL(msnd_fifo_init);
383EXPORT_SYMBOL(msnd_fifo_free);
384EXPORT_SYMBOL(msnd_fifo_alloc);
385EXPORT_SYMBOL(msnd_fifo_make_empty);
386EXPORT_SYMBOL(msnd_fifo_write_io);
387EXPORT_SYMBOL(msnd_fifo_read_io);
388EXPORT_SYMBOL(msnd_fifo_write);
389EXPORT_SYMBOL(msnd_fifo_read);
390
391EXPORT_SYMBOL(msnd_send_dsp_cmd);
392EXPORT_SYMBOL(msnd_send_word);
393EXPORT_SYMBOL(msnd_upload_host);
394
395EXPORT_SYMBOL(msnd_enable_irq);
396EXPORT_SYMBOL(msnd_disable_irq);
397#endif
398
399#ifdef MODULE
400MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
401MODULE_DESCRIPTION ("Turtle Beach MultiSound Driver Base");
402MODULE_LICENSE("GPL");
403
404
405int init_module(void)
406{
407 return 0;
408}
409
410void cleanup_module(void)
411{
412}
413#endif
diff --git a/sound/oss/msnd.h b/sound/oss/msnd.h
deleted file mode 100644
index c8be47ec2b7e..000000000000
--- a/sound/oss/msnd.h
+++ /dev/null
@@ -1,278 +0,0 @@
1/*********************************************************************
2 *
3 * msnd.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_H
29#define __MSND_H
30
31#define VERSION "0.8.3.1"
32
33#define DEFSAMPLERATE DSP_DEFAULT_SPEED
34#define DEFSAMPLESIZE AFMT_U8
35#define DEFCHANNELS 1
36
37#define DEFFIFOSIZE 128
38
39#define SNDCARD_MSND 38
40
41#define SRAM_BANK_SIZE 0x8000
42#define SRAM_CNTL_START 0x7F00
43
44#define DSP_BASE_ADDR 0x4000
45#define DSP_BANK_BASE 0x4000
46
47#define HP_ICR 0x00
48#define HP_CVR 0x01
49#define HP_ISR 0x02
50#define HP_IVR 0x03
51#define HP_NU 0x04
52#define HP_INFO 0x04
53#define HP_TXH 0x05
54#define HP_RXH 0x05
55#define HP_TXM 0x06
56#define HP_RXM 0x06
57#define HP_TXL 0x07
58#define HP_RXL 0x07
59
60#define HP_ICR_DEF 0x00
61#define HP_CVR_DEF 0x12
62#define HP_ISR_DEF 0x06
63#define HP_IVR_DEF 0x0f
64#define HP_NU_DEF 0x00
65
66#define HP_IRQM 0x09
67
68#define HPR_BLRC 0x08
69#define HPR_SPR1 0x09
70#define HPR_SPR2 0x0A
71#define HPR_TCL0 0x0B
72#define HPR_TCL1 0x0C
73#define HPR_TCL2 0x0D
74#define HPR_TCL3 0x0E
75#define HPR_TCL4 0x0F
76
77#define HPICR_INIT 0x80
78#define HPICR_HM1 0x40
79#define HPICR_HM0 0x20
80#define HPICR_HF1 0x10
81#define HPICR_HF0 0x08
82#define HPICR_TREQ 0x02
83#define HPICR_RREQ 0x01
84
85#define HPCVR_HC 0x80
86
87#define HPISR_HREQ 0x80
88#define HPISR_DMA 0x40
89#define HPISR_HF3 0x10
90#define HPISR_HF2 0x08
91#define HPISR_TRDY 0x04
92#define HPISR_TXDE 0x02
93#define HPISR_RXDF 0x01
94
95#define HPIO_290 0
96#define HPIO_260 1
97#define HPIO_250 2
98#define HPIO_240 3
99#define HPIO_230 4
100#define HPIO_220 5
101#define HPIO_210 6
102#define HPIO_3E0 7
103
104#define HPMEM_NONE 0
105#define HPMEM_B000 1
106#define HPMEM_C800 2
107#define HPMEM_D000 3
108#define HPMEM_D400 4
109#define HPMEM_D800 5
110#define HPMEM_E000 6
111#define HPMEM_E800 7
112
113#define HPIRQ_NONE 0
114#define HPIRQ_5 1
115#define HPIRQ_7 2
116#define HPIRQ_9 3
117#define HPIRQ_10 4
118#define HPIRQ_11 5
119#define HPIRQ_12 6
120#define HPIRQ_15 7
121
122#define HIMT_PLAY_DONE 0x00
123#define HIMT_RECORD_DONE 0x01
124#define HIMT_MIDI_EOS 0x02
125#define HIMT_MIDI_OUT 0x03
126
127#define HIMT_MIDI_IN_UCHAR 0x0E
128#define HIMT_DSP 0x0F
129
130#define HDEX_BASE 0x92
131#define HDEX_PLAY_START (0 + HDEX_BASE)
132#define HDEX_PLAY_STOP (1 + HDEX_BASE)
133#define HDEX_PLAY_PAUSE (2 + HDEX_BASE)
134#define HDEX_PLAY_RESUME (3 + HDEX_BASE)
135#define HDEX_RECORD_START (4 + HDEX_BASE)
136#define HDEX_RECORD_STOP (5 + HDEX_BASE)
137#define HDEX_MIDI_IN_START (6 + HDEX_BASE)
138#define HDEX_MIDI_IN_STOP (7 + HDEX_BASE)
139#define HDEX_MIDI_OUT_START (8 + HDEX_BASE)
140#define HDEX_MIDI_OUT_STOP (9 + HDEX_BASE)
141#define HDEX_AUX_REQ (10 + HDEX_BASE)
142
143#define HIWORD(l) ((WORD)((((DWORD)(l)) >> 16) & 0xFFFF))
144#define LOWORD(l) ((WORD)(DWORD)(l))
145#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
146#define LOBYTE(w) ((BYTE)(w))
147#define MAKELONG(low,hi) ((long)(((WORD)(low))|(((DWORD)((WORD)(hi)))<<16)))
148#define MAKEWORD(low,hi) ((WORD)(((BYTE)(low))|(((WORD)((BYTE)(hi)))<<8)))
149
150#define PCTODSP_OFFSET(w) (USHORT)((w)/2)
151#define PCTODSP_BASED(w) (USHORT)(((w)/2) + DSP_BASE_ADDR)
152#define DSPTOPC_BASED(w) (((w) - DSP_BASE_ADDR) * 2)
153
154#ifdef SLOWIO
155#define msnd_outb outb_p
156#define msnd_inb inb_p
157#else
158#define msnd_outb outb
159#define msnd_inb inb
160#endif
161
162/* JobQueueStruct */
163#define JQS_wStart 0x00
164#define JQS_wSize 0x02
165#define JQS_wHead 0x04
166#define JQS_wTail 0x06
167#define JQS__size 0x08
168
169/* DAQueueDataStruct */
170#define DAQDS_wStart 0x00
171#define DAQDS_wSize 0x02
172#define DAQDS_wFormat 0x04
173#define DAQDS_wSampleSize 0x06
174#define DAQDS_wChannels 0x08
175#define DAQDS_wSampleRate 0x0A
176#define DAQDS_wIntMsg 0x0C
177#define DAQDS_wFlags 0x0E
178#define DAQDS__size 0x10
179
180typedef u8 BYTE;
181typedef u16 USHORT;
182typedef u16 WORD;
183typedef u32 DWORD;
184typedef void __iomem * LPDAQD;
185
186/* Generic FIFO */
187typedef struct {
188 size_t n, len;
189 char *data;
190 int head, tail;
191} msnd_fifo;
192
193typedef struct multisound_dev {
194 /* Linux device info */
195 char *name;
196 int dsp_minor, mixer_minor;
197 int ext_midi_dev, hdr_midi_dev;
198
199 /* Hardware resources */
200 int io, numio;
201 int memid, irqid;
202 int irq, irq_ref;
203 unsigned char info;
204 void __iomem *base;
205
206 /* Motorola 56k DSP SMA */
207 void __iomem *SMA;
208 void __iomem *DAPQ, *DARQ, *MODQ, *MIDQ, *DSPQ;
209 void __iomem *pwDSPQData, *pwMIDQData, *pwMODQData;
210 int dspq_data_buff, dspq_buff_size;
211
212 /* State variables */
213 enum { msndClassic, msndPinnacle } type;
214 fmode_t mode;
215 unsigned long flags;
216#define F_RESETTING 0
217#define F_HAVEDIGITAL 1
218#define F_AUDIO_WRITE_INUSE 2
219#define F_WRITING 3
220#define F_WRITEBLOCK 4
221#define F_WRITEFLUSH 5
222#define F_AUDIO_READ_INUSE 6
223#define F_READING 7
224#define F_READBLOCK 8
225#define F_EXT_MIDI_INUSE 9
226#define F_HDR_MIDI_INUSE 10
227#define F_DISABLE_WRITE_NDELAY 11
228 wait_queue_head_t writeblock;
229 wait_queue_head_t readblock;
230 wait_queue_head_t writeflush;
231 spinlock_t lock;
232 int nresets;
233 unsigned long recsrc;
234 int left_levels[32];
235 int right_levels[32];
236 int mixer_mod_count;
237 int calibrate_signal;
238 int play_sample_size, play_sample_rate, play_channels;
239 int play_ndelay;
240 int rec_sample_size, rec_sample_rate, rec_channels;
241 int rec_ndelay;
242 BYTE bCurrentMidiPatch;
243
244 /* Digital audio FIFOs */
245 msnd_fifo DAPF, DARF;
246 int fifosize;
247 int last_playbank, last_recbank;
248
249 /* MIDI in callback */
250 void (*midi_in_interrupt)(struct multisound_dev *);
251} multisound_dev_t;
252
253#ifndef mdelay
254# define mdelay(a) udelay((a) * 1000)
255#endif
256
257int msnd_register(multisound_dev_t *dev);
258void msnd_unregister(multisound_dev_t *dev);
259
260void msnd_init_queue(void __iomem *, int start, int size);
261
262void msnd_fifo_init(msnd_fifo *f);
263void msnd_fifo_free(msnd_fifo *f);
264int msnd_fifo_alloc(msnd_fifo *f, size_t n);
265void msnd_fifo_make_empty(msnd_fifo *f);
266int msnd_fifo_write_io(msnd_fifo *f, char __iomem *buf, size_t len);
267int msnd_fifo_read_io(msnd_fifo *f, char __iomem *buf, size_t len);
268int msnd_fifo_write(msnd_fifo *f, const char *buf, size_t len);
269int msnd_fifo_read(msnd_fifo *f, char *buf, size_t len);
270
271int msnd_send_dsp_cmd(multisound_dev_t *dev, BYTE cmd);
272int msnd_send_word(multisound_dev_t *dev, unsigned char high,
273 unsigned char mid, unsigned char low);
274int msnd_upload_host(multisound_dev_t *dev, char *bin, int len);
275int msnd_enable_irq(multisound_dev_t *dev);
276int msnd_disable_irq(multisound_dev_t *dev);
277
278#endif /* __MSND_H */
diff --git a/sound/oss/msnd_classic.c b/sound/oss/msnd_classic.c
deleted file mode 100644
index 3b23a096fa4e..000000000000
--- a/sound/oss/msnd_classic.c
+++ /dev/null
@@ -1,3 +0,0 @@
1/* The work is in msnd_pinnacle.c, just define MSND_CLASSIC before it. */
2#define MSND_CLASSIC
3#include "msnd_pinnacle.c"
diff --git a/sound/oss/msnd_classic.h b/sound/oss/msnd_classic.h
deleted file mode 100644
index 1a17dde2f650..000000000000
--- a/sound/oss/msnd_classic.h
+++ /dev/null
@@ -1,185 +0,0 @@
1/*********************************************************************
2 *
3 * msnd_classic.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_CLASSIC_H
29#define __MSND_CLASSIC_H
30
31
32#define DSP_NUMIO 0x10
33
34#define HP_MEMM 0x08
35
36#define HP_BITM 0x0E
37#define HP_WAIT 0x0D
38#define HP_DSPR 0x0A
39#define HP_PROR 0x0B
40#define HP_BLKS 0x0C
41
42#define HPPRORESET_OFF 0
43#define HPPRORESET_ON 1
44
45#define HPDSPRESET_OFF 0
46#define HPDSPRESET_ON 1
47
48#define HPBLKSEL_0 0
49#define HPBLKSEL_1 1
50
51#define HPWAITSTATE_0 0
52#define HPWAITSTATE_1 1
53
54#define HPBITMODE_16 0
55#define HPBITMODE_8 1
56
57#define HIDSP_INT_PLAY_UNDER 0x00
58#define HIDSP_INT_RECORD_OVER 0x01
59#define HIDSP_INPUT_CLIPPING 0x02
60#define HIDSP_MIDI_IN_OVER 0x10
61#define HIDSP_MIDI_OVERRUN_ERR 0x13
62
63#define HDEXAR_CLEAR_PEAKS 1
64#define HDEXAR_IN_SET_POTS 2
65#define HDEXAR_AUX_SET_POTS 3
66#define HDEXAR_CAL_A_TO_D 4
67#define HDEXAR_RD_EXT_DSP_BITS 5
68
69#define TIME_PRO_RESET_DONE 0x028A
70#define TIME_PRO_SYSEX 0x0040
71#define TIME_PRO_RESET 0x0032
72
73#define AGND 0x01
74#define SIGNAL 0x02
75
76#define EXT_DSP_BIT_DCAL 0x0001
77#define EXT_DSP_BIT_MIDI_CON 0x0002
78
79#define BUFFSIZE 0x8000
80#define HOSTQ_SIZE 0x40
81
82#define SRAM_CNTL_START 0x7F00
83#define SMA_STRUCT_START 0x7F40
84
85#define DAP_BUFF_SIZE 0x2400
86#define DAR_BUFF_SIZE 0x2000
87
88#define DAPQ_STRUCT_SIZE 0x10
89#define DARQ_STRUCT_SIZE 0x10
90#define DAPQ_BUFF_SIZE (3 * 0x10)
91#define DARQ_BUFF_SIZE (3 * 0x10)
92#define MODQ_BUFF_SIZE 0x400
93#define MIDQ_BUFF_SIZE 0x200
94#define DSPQ_BUFF_SIZE 0x40
95
96#define DAPQ_DATA_BUFF 0x6C00
97#define DARQ_DATA_BUFF 0x6C30
98#define MODQ_DATA_BUFF 0x6C60
99#define MIDQ_DATA_BUFF 0x7060
100#define DSPQ_DATA_BUFF 0x7260
101
102#define DAPQ_OFFSET SRAM_CNTL_START
103#define DARQ_OFFSET (SRAM_CNTL_START + 0x08)
104#define MODQ_OFFSET (SRAM_CNTL_START + 0x10)
105#define MIDQ_OFFSET (SRAM_CNTL_START + 0x18)
106#define DSPQ_OFFSET (SRAM_CNTL_START + 0x20)
107
108#define MOP_SYNTH 0x10
109#define MOP_EXTOUT 0x32
110#define MOP_EXTTHRU 0x02
111#define MOP_OUTMASK 0x01
112
113#define MIP_EXTIN 0x01
114#define MIP_SYNTH 0x00
115#define MIP_INMASK 0x32
116
117/* Classic SMA Common Data */
118#define SMA_wCurrPlayBytes 0x0000
119#define SMA_wCurrRecordBytes 0x0002
120#define SMA_wCurrPlayVolLeft 0x0004
121#define SMA_wCurrPlayVolRight 0x0006
122#define SMA_wCurrInVolLeft 0x0008
123#define SMA_wCurrInVolRight 0x000a
124#define SMA_wUser_3 0x000c
125#define SMA_wUser_4 0x000e
126#define SMA_dwUser_5 0x0010
127#define SMA_dwUser_6 0x0014
128#define SMA_wUser_7 0x0018
129#define SMA_wReserved_A 0x001a
130#define SMA_wReserved_B 0x001c
131#define SMA_wReserved_C 0x001e
132#define SMA_wReserved_D 0x0020
133#define SMA_wReserved_E 0x0022
134#define SMA_wReserved_F 0x0024
135#define SMA_wReserved_G 0x0026
136#define SMA_wReserved_H 0x0028
137#define SMA_wCurrDSPStatusFlags 0x002a
138#define SMA_wCurrHostStatusFlags 0x002c
139#define SMA_wCurrInputTagBits 0x002e
140#define SMA_wCurrLeftPeak 0x0030
141#define SMA_wCurrRightPeak 0x0032
142#define SMA_wExtDSPbits 0x0034
143#define SMA_bExtHostbits 0x0036
144#define SMA_bBoardLevel 0x0037
145#define SMA_bInPotPosRight 0x0038
146#define SMA_bInPotPosLeft 0x0039
147#define SMA_bAuxPotPosRight 0x003a
148#define SMA_bAuxPotPosLeft 0x003b
149#define SMA_wCurrMastVolLeft 0x003c
150#define SMA_wCurrMastVolRight 0x003e
151#define SMA_bUser_12 0x0040
152#define SMA_bUser_13 0x0041
153#define SMA_wUser_14 0x0042
154#define SMA_wUser_15 0x0044
155#define SMA_wCalFreqAtoD 0x0046
156#define SMA_wUser_16 0x0048
157#define SMA_wUser_17 0x004a
158#define SMA__size 0x004c
159
160#ifdef HAVE_DSPCODEH
161# include "msndperm.c"
162# include "msndinit.c"
163# define PERMCODE msndperm
164# define INITCODE msndinit
165# define PERMCODESIZE sizeof(msndperm)
166# define INITCODESIZE sizeof(msndinit)
167#else
168# ifndef CONFIG_MSNDCLAS_INIT_FILE
169# define CONFIG_MSNDCLAS_INIT_FILE \
170 "/etc/sound/msndinit.bin"
171# endif
172# ifndef CONFIG_MSNDCLAS_PERM_FILE
173# define CONFIG_MSNDCLAS_PERM_FILE \
174 "/etc/sound/msndperm.bin"
175# endif
176# define PERMCODEFILE CONFIG_MSNDCLAS_PERM_FILE
177# define INITCODEFILE CONFIG_MSNDCLAS_INIT_FILE
178# define PERMCODE dspini
179# define INITCODE permini
180# define PERMCODESIZE sizeof_dspini
181# define INITCODESIZE sizeof_permini
182#endif
183#define LONGNAME "MultiSound (Classic/Monterey/Tahiti)"
184
185#endif /* __MSND_CLASSIC_H */
diff --git a/sound/oss/msnd_pinnacle.c b/sound/oss/msnd_pinnacle.c
deleted file mode 100644
index d2abc2cf3213..000000000000
--- a/sound/oss/msnd_pinnacle.c
+++ /dev/null
@@ -1,1941 +0,0 @@
1/*********************************************************************
2 *
3 * Turtle Beach MultiSound Sound Card Driver for Linux
4 * Linux 2.0/2.2 Version
5 *
6 * msnd_pinnacle.c / msnd_classic.c
7 *
8 * -- If MSND_CLASSIC is defined:
9 *
10 * -> driver for Turtle Beach Classic/Monterey/Tahiti
11 *
12 * -- Else
13 *
14 * -> driver for Turtle Beach Pinnacle/Fiji
15 *
16 * Copyright (C) 1998 Andrew Veliath
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *
32 * 12-3-2000 Modified IO port validation Steve Sycamore
33 *
34 ********************************************************************/
35
36#include <linux/kernel.h>
37#include <linux/module.h>
38#include <linux/types.h>
39#include <linux/delay.h>
40#include <linux/init.h>
41#include <linux/interrupt.h>
42#include <linux/mutex.h>
43#include <linux/gfp.h>
44#include <linux/sched/signal.h>
45
46#include <asm/irq.h>
47#include <asm/io.h>
48#include "sound_config.h"
49#include "sound_firmware.h"
50#ifdef MSND_CLASSIC
51# ifndef __alpha__
52# define SLOWIO
53# endif
54#endif
55#include "msnd.h"
56#ifdef MSND_CLASSIC
57# ifdef CONFIG_MSNDCLAS_HAVE_BOOT
58# define HAVE_DSPCODEH
59# endif
60# include "msnd_classic.h"
61# define LOGNAME "msnd_classic"
62#else
63# ifdef CONFIG_MSNDPIN_HAVE_BOOT
64# define HAVE_DSPCODEH
65# endif
66# include "msnd_pinnacle.h"
67# define LOGNAME "msnd_pinnacle"
68#endif
69
70#ifndef CONFIG_MSND_WRITE_NDELAY
71# define CONFIG_MSND_WRITE_NDELAY 1
72#endif
73
74#define get_play_delay_jiffies(size) ((size) * HZ * \
75 dev.play_sample_size / 8 / \
76 dev.play_sample_rate / \
77 dev.play_channels)
78
79#define get_rec_delay_jiffies(size) ((size) * HZ * \
80 dev.rec_sample_size / 8 / \
81 dev.rec_sample_rate / \
82 dev.rec_channels)
83
84static DEFINE_MUTEX(msnd_pinnacle_mutex);
85static multisound_dev_t dev;
86
87#ifndef HAVE_DSPCODEH
88static char *dspini, *permini;
89static int sizeof_dspini, sizeof_permini;
90#endif
91
92static int dsp_full_reset(void);
93static void dsp_write_flush(void);
94
95static __inline__ int chk_send_dsp_cmd(multisound_dev_t *dev, register BYTE cmd)
96{
97 if (msnd_send_dsp_cmd(dev, cmd) == 0)
98 return 0;
99 dsp_full_reset();
100 return msnd_send_dsp_cmd(dev, cmd);
101}
102
103static void reset_play_queue(void)
104{
105 int n;
106 LPDAQD lpDAQ;
107
108 dev.last_playbank = -1;
109 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DAPQ + JQS_wHead);
110 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DAPQ + JQS_wTail);
111
112 for (n = 0, lpDAQ = dev.base + DAPQ_DATA_BUFF; n < 3; ++n, lpDAQ += DAQDS__size) {
113 writew(PCTODSP_BASED((DWORD)(DAP_BUFF_SIZE * n)), lpDAQ + DAQDS_wStart);
114 writew(0, lpDAQ + DAQDS_wSize);
115 writew(1, lpDAQ + DAQDS_wFormat);
116 writew(dev.play_sample_size, lpDAQ + DAQDS_wSampleSize);
117 writew(dev.play_channels, lpDAQ + DAQDS_wChannels);
118 writew(dev.play_sample_rate, lpDAQ + DAQDS_wSampleRate);
119 writew(HIMT_PLAY_DONE * 0x100 + n, lpDAQ + DAQDS_wIntMsg);
120 writew(n, lpDAQ + DAQDS_wFlags);
121 }
122}
123
124static void reset_record_queue(void)
125{
126 int n;
127 LPDAQD lpDAQ;
128 unsigned long flags;
129
130 dev.last_recbank = 2;
131 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DARQ + JQS_wHead);
132 writew(PCTODSP_OFFSET(dev.last_recbank * DAQDS__size), dev.DARQ + JQS_wTail);
133
134 /* Critical section: bank 1 access */
135 spin_lock_irqsave(&dev.lock, flags);
136 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
137 memset_io(dev.base, 0, DAR_BUFF_SIZE * 3);
138 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
139 spin_unlock_irqrestore(&dev.lock, flags);
140
141 for (n = 0, lpDAQ = dev.base + DARQ_DATA_BUFF; n < 3; ++n, lpDAQ += DAQDS__size) {
142 writew(PCTODSP_BASED((DWORD)(DAR_BUFF_SIZE * n)) + 0x4000, lpDAQ + DAQDS_wStart);
143 writew(DAR_BUFF_SIZE, lpDAQ + DAQDS_wSize);
144 writew(1, lpDAQ + DAQDS_wFormat);
145 writew(dev.rec_sample_size, lpDAQ + DAQDS_wSampleSize);
146 writew(dev.rec_channels, lpDAQ + DAQDS_wChannels);
147 writew(dev.rec_sample_rate, lpDAQ + DAQDS_wSampleRate);
148 writew(HIMT_RECORD_DONE * 0x100 + n, lpDAQ + DAQDS_wIntMsg);
149 writew(n, lpDAQ + DAQDS_wFlags);
150 }
151}
152
153static void reset_queues(void)
154{
155 if (dev.mode & FMODE_WRITE) {
156 msnd_fifo_make_empty(&dev.DAPF);
157 reset_play_queue();
158 }
159 if (dev.mode & FMODE_READ) {
160 msnd_fifo_make_empty(&dev.DARF);
161 reset_record_queue();
162 }
163}
164
165static int dsp_set_format(struct file *file, int val)
166{
167 int data, i;
168 LPDAQD lpDAQ, lpDARQ;
169
170 lpDAQ = dev.base + DAPQ_DATA_BUFF;
171 lpDARQ = dev.base + DARQ_DATA_BUFF;
172
173 switch (val) {
174 case AFMT_U8:
175 case AFMT_S16_LE:
176 data = val;
177 break;
178 default:
179 data = DEFSAMPLESIZE;
180 break;
181 }
182
183 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
184 if (file->f_mode & FMODE_WRITE)
185 writew(data, lpDAQ + DAQDS_wSampleSize);
186 if (file->f_mode & FMODE_READ)
187 writew(data, lpDARQ + DAQDS_wSampleSize);
188 }
189 if (file->f_mode & FMODE_WRITE)
190 dev.play_sample_size = data;
191 if (file->f_mode & FMODE_READ)
192 dev.rec_sample_size = data;
193
194 return data;
195}
196
197static int dsp_get_frag_size(void)
198{
199 int size;
200 size = dev.fifosize / 4;
201 if (size > 32 * 1024)
202 size = 32 * 1024;
203 return size;
204}
205
206static int dsp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
207{
208 int val, i, data, tmp;
209 LPDAQD lpDAQ, lpDARQ;
210 audio_buf_info abinfo;
211 unsigned long flags;
212 int __user *p = (int __user *)arg;
213
214 lpDAQ = dev.base + DAPQ_DATA_BUFF;
215 lpDARQ = dev.base + DARQ_DATA_BUFF;
216
217 switch (cmd) {
218 case SNDCTL_DSP_SUBDIVIDE:
219 case SNDCTL_DSP_SETFRAGMENT:
220 case SNDCTL_DSP_SETDUPLEX:
221 case SNDCTL_DSP_POST:
222 return 0;
223
224 case SNDCTL_DSP_GETIPTR:
225 case SNDCTL_DSP_GETOPTR:
226 case SNDCTL_DSP_MAPINBUF:
227 case SNDCTL_DSP_MAPOUTBUF:
228 return -EINVAL;
229
230 case SNDCTL_DSP_GETOSPACE:
231 if (!(file->f_mode & FMODE_WRITE))
232 return -EINVAL;
233 spin_lock_irqsave(&dev.lock, flags);
234 abinfo.fragsize = dsp_get_frag_size();
235 abinfo.bytes = dev.DAPF.n - dev.DAPF.len;
236 abinfo.fragstotal = dev.DAPF.n / abinfo.fragsize;
237 abinfo.fragments = abinfo.bytes / abinfo.fragsize;
238 spin_unlock_irqrestore(&dev.lock, flags);
239 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
240
241 case SNDCTL_DSP_GETISPACE:
242 if (!(file->f_mode & FMODE_READ))
243 return -EINVAL;
244 spin_lock_irqsave(&dev.lock, flags);
245 abinfo.fragsize = dsp_get_frag_size();
246 abinfo.bytes = dev.DARF.n - dev.DARF.len;
247 abinfo.fragstotal = dev.DARF.n / abinfo.fragsize;
248 abinfo.fragments = abinfo.bytes / abinfo.fragsize;
249 spin_unlock_irqrestore(&dev.lock, flags);
250 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
251
252 case SNDCTL_DSP_RESET:
253 dev.nresets = 0;
254 reset_queues();
255 return 0;
256
257 case SNDCTL_DSP_SYNC:
258 dsp_write_flush();
259 return 0;
260
261 case SNDCTL_DSP_GETBLKSIZE:
262 tmp = dsp_get_frag_size();
263 if (put_user(tmp, p))
264 return -EFAULT;
265 return 0;
266
267 case SNDCTL_DSP_GETFMTS:
268 val = AFMT_S16_LE | AFMT_U8;
269 if (put_user(val, p))
270 return -EFAULT;
271 return 0;
272
273 case SNDCTL_DSP_SETFMT:
274 if (get_user(val, p))
275 return -EFAULT;
276
277 if (file->f_mode & FMODE_WRITE)
278 data = val == AFMT_QUERY
279 ? dev.play_sample_size
280 : dsp_set_format(file, val);
281 else
282 data = val == AFMT_QUERY
283 ? dev.rec_sample_size
284 : dsp_set_format(file, val);
285
286 if (put_user(data, p))
287 return -EFAULT;
288 return 0;
289
290 case SNDCTL_DSP_NONBLOCK:
291 if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags) &&
292 file->f_mode & FMODE_WRITE)
293 dev.play_ndelay = 1;
294 if (file->f_mode & FMODE_READ)
295 dev.rec_ndelay = 1;
296 return 0;
297
298 case SNDCTL_DSP_GETCAPS:
299 val = DSP_CAP_DUPLEX | DSP_CAP_BATCH;
300 if (put_user(val, p))
301 return -EFAULT;
302 return 0;
303
304 case SNDCTL_DSP_SPEED:
305 if (get_user(val, p))
306 return -EFAULT;
307
308 if (val < 8000)
309 val = 8000;
310
311 if (val > 48000)
312 val = 48000;
313
314 data = val;
315
316 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
317 if (file->f_mode & FMODE_WRITE)
318 writew(data, lpDAQ + DAQDS_wSampleRate);
319 if (file->f_mode & FMODE_READ)
320 writew(data, lpDARQ + DAQDS_wSampleRate);
321 }
322 if (file->f_mode & FMODE_WRITE)
323 dev.play_sample_rate = data;
324 if (file->f_mode & FMODE_READ)
325 dev.rec_sample_rate = data;
326
327 if (put_user(data, p))
328 return -EFAULT;
329 return 0;
330
331 case SNDCTL_DSP_CHANNELS:
332 case SNDCTL_DSP_STEREO:
333 if (get_user(val, p))
334 return -EFAULT;
335
336 if (cmd == SNDCTL_DSP_CHANNELS) {
337 switch (val) {
338 case 1:
339 case 2:
340 data = val;
341 break;
342 default:
343 val = data = 2;
344 break;
345 }
346 } else {
347 switch (val) {
348 case 0:
349 data = 1;
350 break;
351 default:
352 val = 1;
353 case 1:
354 data = 2;
355 break;
356 }
357 }
358
359 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
360 if (file->f_mode & FMODE_WRITE)
361 writew(data, lpDAQ + DAQDS_wChannels);
362 if (file->f_mode & FMODE_READ)
363 writew(data, lpDARQ + DAQDS_wChannels);
364 }
365 if (file->f_mode & FMODE_WRITE)
366 dev.play_channels = data;
367 if (file->f_mode & FMODE_READ)
368 dev.rec_channels = data;
369
370 if (put_user(val, p))
371 return -EFAULT;
372 return 0;
373 }
374
375 return -EINVAL;
376}
377
378static int mixer_get(int d)
379{
380 if (d > 31)
381 return -EINVAL;
382
383 switch (d) {
384 case SOUND_MIXER_VOLUME:
385 case SOUND_MIXER_PCM:
386 case SOUND_MIXER_LINE:
387 case SOUND_MIXER_IMIX:
388 case SOUND_MIXER_LINE1:
389#ifndef MSND_CLASSIC
390 case SOUND_MIXER_MIC:
391 case SOUND_MIXER_SYNTH:
392#endif
393 return (dev.left_levels[d] >> 8) * 100 / 0xff |
394 (((dev.right_levels[d] >> 8) * 100 / 0xff) << 8);
395 default:
396 return 0;
397 }
398}
399
400#define update_volm(a,b) \
401 writew((dev.left_levels[a] >> 1) * \
402 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
403 dev.SMA + SMA_##b##Left); \
404 writew((dev.right_levels[a] >> 1) * \
405 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
406 dev.SMA + SMA_##b##Right);
407
408#define update_potm(d,s,ar) \
409 writeb((dev.left_levels[d] >> 8) * \
410 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
411 dev.SMA + SMA_##s##Left); \
412 writeb((dev.right_levels[d] >> 8) * \
413 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
414 dev.SMA + SMA_##s##Right); \
415 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
416 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
417
418#define update_pot(d,s,ar) \
419 writeb(dev.left_levels[d] >> 8, \
420 dev.SMA + SMA_##s##Left); \
421 writeb(dev.right_levels[d] >> 8, \
422 dev.SMA + SMA_##s##Right); \
423 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
424 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
425
426static int mixer_set(int d, int value)
427{
428 int left = value & 0x000000ff;
429 int right = (value & 0x0000ff00) >> 8;
430 int bLeft, bRight;
431 int wLeft, wRight;
432 int updatemaster = 0;
433
434 if (d > 31)
435 return -EINVAL;
436
437 bLeft = left * 0xff / 100;
438 wLeft = left * 0xffff / 100;
439
440 bRight = right * 0xff / 100;
441 wRight = right * 0xffff / 100;
442
443 dev.left_levels[d] = wLeft;
444 dev.right_levels[d] = wRight;
445
446 switch (d) {
447 /* master volume unscaled controls */
448 case SOUND_MIXER_LINE: /* line pot control */
449 /* scaled by IMIX in digital mix */
450 writeb(bLeft, dev.SMA + SMA_bInPotPosLeft);
451 writeb(bRight, dev.SMA + SMA_bInPotPosRight);
452 if (msnd_send_word(&dev, 0, 0, HDEXAR_IN_SET_POTS) == 0)
453 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
454 break;
455#ifndef MSND_CLASSIC
456 case SOUND_MIXER_MIC: /* mic pot control */
457 /* scaled by IMIX in digital mix */
458 writeb(bLeft, dev.SMA + SMA_bMicPotPosLeft);
459 writeb(bRight, dev.SMA + SMA_bMicPotPosRight);
460 if (msnd_send_word(&dev, 0, 0, HDEXAR_MIC_SET_POTS) == 0)
461 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
462 break;
463#endif
464 case SOUND_MIXER_VOLUME: /* master volume */
465 writew(wLeft, dev.SMA + SMA_wCurrMastVolLeft);
466 writew(wRight, dev.SMA + SMA_wCurrMastVolRight);
467 /* fall through */
468
469 case SOUND_MIXER_LINE1: /* aux pot control */
470 /* scaled by master volume */
471 /* fall through */
472
473 /* digital controls */
474 case SOUND_MIXER_SYNTH: /* synth vol (dsp mix) */
475 case SOUND_MIXER_PCM: /* pcm vol (dsp mix) */
476 case SOUND_MIXER_IMIX: /* input monitor (dsp mix) */
477 /* scaled by master volume */
478 updatemaster = 1;
479 break;
480
481 default:
482 return 0;
483 }
484
485 if (updatemaster) {
486 /* update master volume scaled controls */
487 update_volm(SOUND_MIXER_PCM, wCurrPlayVol);
488 update_volm(SOUND_MIXER_IMIX, wCurrInVol);
489#ifndef MSND_CLASSIC
490 update_volm(SOUND_MIXER_SYNTH, wCurrMHdrVol);
491#endif
492 update_potm(SOUND_MIXER_LINE1, bAuxPotPos, HDEXAR_AUX_SET_POTS);
493 }
494
495 return mixer_get(d);
496}
497
498static void mixer_setup(void)
499{
500 update_pot(SOUND_MIXER_LINE, bInPotPos, HDEXAR_IN_SET_POTS);
501 update_potm(SOUND_MIXER_LINE1, bAuxPotPos, HDEXAR_AUX_SET_POTS);
502 update_volm(SOUND_MIXER_PCM, wCurrPlayVol);
503 update_volm(SOUND_MIXER_IMIX, wCurrInVol);
504#ifndef MSND_CLASSIC
505 update_pot(SOUND_MIXER_MIC, bMicPotPos, HDEXAR_MIC_SET_POTS);
506 update_volm(SOUND_MIXER_SYNTH, wCurrMHdrVol);
507#endif
508}
509
510static unsigned long set_recsrc(unsigned long recsrc)
511{
512 if (dev.recsrc == recsrc)
513 return dev.recsrc;
514#ifdef HAVE_NORECSRC
515 else if (recsrc == 0)
516 dev.recsrc = 0;
517#endif
518 else
519 dev.recsrc ^= recsrc;
520
521#ifndef MSND_CLASSIC
522 if (dev.recsrc & SOUND_MASK_IMIX) {
523 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_ANA_IN) == 0)
524 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
525 }
526 else if (dev.recsrc & SOUND_MASK_SYNTH) {
527 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_SYNTH_IN) == 0)
528 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
529 }
530 else if ((dev.recsrc & SOUND_MASK_DIGITAL1) && test_bit(F_HAVEDIGITAL, &dev.flags)) {
531 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_DAT_IN) == 0)
532 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
533 }
534 else {
535#ifdef HAVE_NORECSRC
536 /* Select no input (?) */
537 dev.recsrc = 0;
538#else
539 dev.recsrc = SOUND_MASK_IMIX;
540 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_ANA_IN) == 0)
541 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
542#endif
543 }
544#endif /* MSND_CLASSIC */
545
546 return dev.recsrc;
547}
548
549static unsigned long force_recsrc(unsigned long recsrc)
550{
551 dev.recsrc = 0;
552 return set_recsrc(recsrc);
553}
554
555#define set_mixer_info() \
556 memset(&info, 0, sizeof(info)); \
557 strlcpy(info.id, "MSNDMIXER", sizeof(info.id)); \
558 strlcpy(info.name, "MultiSound Mixer", sizeof(info.name));
559
560static int mixer_ioctl(unsigned int cmd, unsigned long arg)
561{
562 if (cmd == SOUND_MIXER_INFO) {
563 mixer_info info;
564 set_mixer_info();
565 info.modify_counter = dev.mixer_mod_count;
566 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
567 return -EFAULT;
568 return 0;
569 } else if (cmd == SOUND_OLD_MIXER_INFO) {
570 _old_mixer_info info;
571 set_mixer_info();
572 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
573 return -EFAULT;
574 return 0;
575 } else if (cmd == SOUND_MIXER_PRIVATE1) {
576 dev.nresets = 0;
577 dsp_full_reset();
578 return 0;
579 } else if (((cmd >> 8) & 0xff) == 'M') {
580 int val = 0;
581
582 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
583 switch (cmd & 0xff) {
584 case SOUND_MIXER_RECSRC:
585 if (get_user(val, (int __user *)arg))
586 return -EFAULT;
587 val = set_recsrc(val);
588 break;
589
590 default:
591 if (get_user(val, (int __user *)arg))
592 return -EFAULT;
593 val = mixer_set(cmd & 0xff, val);
594 break;
595 }
596 ++dev.mixer_mod_count;
597 return put_user(val, (int __user *)arg);
598 } else {
599 switch (cmd & 0xff) {
600 case SOUND_MIXER_RECSRC:
601 val = dev.recsrc;
602 break;
603
604 case SOUND_MIXER_DEVMASK:
605 case SOUND_MIXER_STEREODEVS:
606 val = SOUND_MASK_PCM |
607 SOUND_MASK_LINE |
608 SOUND_MASK_IMIX |
609 SOUND_MASK_LINE1 |
610#ifndef MSND_CLASSIC
611 SOUND_MASK_MIC |
612 SOUND_MASK_SYNTH |
613#endif
614 SOUND_MASK_VOLUME;
615 break;
616
617 case SOUND_MIXER_RECMASK:
618#ifdef MSND_CLASSIC
619 val = 0;
620#else
621 val = SOUND_MASK_IMIX |
622 SOUND_MASK_SYNTH;
623 if (test_bit(F_HAVEDIGITAL, &dev.flags))
624 val |= SOUND_MASK_DIGITAL1;
625#endif
626 break;
627
628 case SOUND_MIXER_CAPS:
629 val = SOUND_CAP_EXCL_INPUT;
630 break;
631
632 default:
633 if ((val = mixer_get(cmd & 0xff)) < 0)
634 return -EINVAL;
635 break;
636 }
637 }
638
639 return put_user(val, (int __user *)arg);
640 }
641
642 return -EINVAL;
643}
644
645static long dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
646{
647 int minor = iminor(file_inode(file));
648 int ret;
649
650 if (cmd == OSS_GETVERSION) {
651 int sound_version = SOUND_VERSION;
652 return put_user(sound_version, (int __user *)arg);
653 }
654
655 ret = -EINVAL;
656
657 mutex_lock(&msnd_pinnacle_mutex);
658 if (minor == dev.dsp_minor)
659 ret = dsp_ioctl(file, cmd, arg);
660 else if (minor == dev.mixer_minor)
661 ret = mixer_ioctl(cmd, arg);
662 mutex_unlock(&msnd_pinnacle_mutex);
663
664 return ret;
665}
666
667static void dsp_write_flush(void)
668{
669 int timeout = get_play_delay_jiffies(dev.DAPF.len);
670
671 if (!(dev.mode & FMODE_WRITE) || !test_bit(F_WRITING, &dev.flags))
672 return;
673 set_bit(F_WRITEFLUSH, &dev.flags);
674 wait_event_interruptible_timeout(
675 dev.writeflush,
676 !test_bit(F_WRITEFLUSH, &dev.flags),
677 timeout);
678 clear_bit(F_WRITEFLUSH, &dev.flags);
679 if (!signal_pending(current)) {
680 __set_current_state(TASK_INTERRUPTIBLE);
681 schedule_timeout(get_play_delay_jiffies(DAP_BUFF_SIZE));
682 }
683 clear_bit(F_WRITING, &dev.flags);
684}
685
686static void dsp_halt(struct file *file)
687{
688 if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
689 clear_bit(F_READING, &dev.flags);
690 chk_send_dsp_cmd(&dev, HDEX_RECORD_STOP);
691 msnd_disable_irq(&dev);
692 if (file) {
693 printk(KERN_DEBUG LOGNAME ": Stopping read for %p\n", file);
694 dev.mode &= ~FMODE_READ;
695 }
696 clear_bit(F_AUDIO_READ_INUSE, &dev.flags);
697 }
698 if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
699 if (test_bit(F_WRITING, &dev.flags)) {
700 dsp_write_flush();
701 chk_send_dsp_cmd(&dev, HDEX_PLAY_STOP);
702 }
703 msnd_disable_irq(&dev);
704 if (file) {
705 printk(KERN_DEBUG LOGNAME ": Stopping write for %p\n", file);
706 dev.mode &= ~FMODE_WRITE;
707 }
708 clear_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
709 }
710}
711
712static int dsp_release(struct file *file)
713{
714 dsp_halt(file);
715 return 0;
716}
717
718static int dsp_open(struct file *file)
719{
720 if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
721 set_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
722 clear_bit(F_WRITING, &dev.flags);
723 msnd_fifo_make_empty(&dev.DAPF);
724 reset_play_queue();
725 if (file) {
726 printk(KERN_DEBUG LOGNAME ": Starting write for %p\n", file);
727 dev.mode |= FMODE_WRITE;
728 }
729 msnd_enable_irq(&dev);
730 }
731 if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
732 set_bit(F_AUDIO_READ_INUSE, &dev.flags);
733 clear_bit(F_READING, &dev.flags);
734 msnd_fifo_make_empty(&dev.DARF);
735 reset_record_queue();
736 if (file) {
737 printk(KERN_DEBUG LOGNAME ": Starting read for %p\n", file);
738 dev.mode |= FMODE_READ;
739 }
740 msnd_enable_irq(&dev);
741 }
742 return 0;
743}
744
745static void set_default_play_audio_parameters(void)
746{
747 dev.play_sample_size = DEFSAMPLESIZE;
748 dev.play_sample_rate = DEFSAMPLERATE;
749 dev.play_channels = DEFCHANNELS;
750}
751
752static void set_default_rec_audio_parameters(void)
753{
754 dev.rec_sample_size = DEFSAMPLESIZE;
755 dev.rec_sample_rate = DEFSAMPLERATE;
756 dev.rec_channels = DEFCHANNELS;
757}
758
759static void set_default_audio_parameters(void)
760{
761 set_default_play_audio_parameters();
762 set_default_rec_audio_parameters();
763}
764
765static int dev_open(struct inode *inode, struct file *file)
766{
767 int minor = iminor(inode);
768 int err = 0;
769
770 mutex_lock(&msnd_pinnacle_mutex);
771 if (minor == dev.dsp_minor) {
772 if ((file->f_mode & FMODE_WRITE &&
773 test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) ||
774 (file->f_mode & FMODE_READ &&
775 test_bit(F_AUDIO_READ_INUSE, &dev.flags))) {
776 err = -EBUSY;
777 goto out;
778 }
779
780 if ((err = dsp_open(file)) >= 0) {
781 dev.nresets = 0;
782 if (file->f_mode & FMODE_WRITE) {
783 set_default_play_audio_parameters();
784 if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags))
785 dev.play_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
786 else
787 dev.play_ndelay = 0;
788 }
789 if (file->f_mode & FMODE_READ) {
790 set_default_rec_audio_parameters();
791 dev.rec_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
792 }
793 }
794 }
795 else if (minor == dev.mixer_minor) {
796 /* nothing */
797 } else
798 err = -EINVAL;
799out:
800 mutex_unlock(&msnd_pinnacle_mutex);
801 return err;
802}
803
804static int dev_release(struct inode *inode, struct file *file)
805{
806 int minor = iminor(inode);
807 int err = 0;
808
809 mutex_lock(&msnd_pinnacle_mutex);
810 if (minor == dev.dsp_minor)
811 err = dsp_release(file);
812 else if (minor == dev.mixer_minor) {
813 /* nothing */
814 } else
815 err = -EINVAL;
816 mutex_unlock(&msnd_pinnacle_mutex);
817 return err;
818}
819
820static __inline__ int pack_DARQ_to_DARF(register int bank)
821{
822 register int size, timeout = 3;
823 register WORD wTmp;
824 LPDAQD DAQD;
825
826 /* Increment the tail and check for queue wrap */
827 wTmp = readw(dev.DARQ + JQS_wTail) + PCTODSP_OFFSET(DAQDS__size);
828 if (wTmp > readw(dev.DARQ + JQS_wSize))
829 wTmp = 0;
830 while (wTmp == readw(dev.DARQ + JQS_wHead) && timeout--)
831 udelay(1);
832 writew(wTmp, dev.DARQ + JQS_wTail);
833
834 /* Get our digital audio queue struct */
835 DAQD = bank * DAQDS__size + dev.base + DARQ_DATA_BUFF;
836
837 /* Get length of data */
838 size = readw(DAQD + DAQDS_wSize);
839
840 /* Read data from the head (unprotected bank 1 access okay
841 since this is only called inside an interrupt) */
842 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
843 msnd_fifo_write_io(
844 &dev.DARF,
845 dev.base + bank * DAR_BUFF_SIZE,
846 size);
847 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
848
849 return 1;
850}
851
852static __inline__ int pack_DAPF_to_DAPQ(register int start)
853{
854 register WORD DAPQ_tail;
855 register int protect = start, nbanks = 0;
856 LPDAQD DAQD;
857
858 DAPQ_tail = readw(dev.DAPQ + JQS_wTail);
859 while (DAPQ_tail != readw(dev.DAPQ + JQS_wHead) || start) {
860 register int bank_num = DAPQ_tail / PCTODSP_OFFSET(DAQDS__size);
861 register int n;
862 unsigned long flags;
863
864 /* Write the data to the new tail */
865 if (protect) {
866 /* Critical section: protect fifo in non-interrupt */
867 spin_lock_irqsave(&dev.lock, flags);
868 n = msnd_fifo_read_io(
869 &dev.DAPF,
870 dev.base + bank_num * DAP_BUFF_SIZE,
871 DAP_BUFF_SIZE);
872 spin_unlock_irqrestore(&dev.lock, flags);
873 } else {
874 n = msnd_fifo_read_io(
875 &dev.DAPF,
876 dev.base + bank_num * DAP_BUFF_SIZE,
877 DAP_BUFF_SIZE);
878 }
879 if (!n)
880 break;
881
882 if (start)
883 start = 0;
884
885 /* Get our digital audio queue struct */
886 DAQD = bank_num * DAQDS__size + dev.base + DAPQ_DATA_BUFF;
887
888 /* Write size of this bank */
889 writew(n, DAQD + DAQDS_wSize);
890 ++nbanks;
891
892 /* Then advance the tail */
893 DAPQ_tail = (++bank_num % 3) * PCTODSP_OFFSET(DAQDS__size);
894 writew(DAPQ_tail, dev.DAPQ + JQS_wTail);
895 /* Tell the DSP to play the bank */
896 msnd_send_dsp_cmd(&dev, HDEX_PLAY_START);
897 }
898 return nbanks;
899}
900
901static int dsp_read(char __user *buf, size_t len)
902{
903 int count = len;
904 char *page = (char *)__get_free_page(GFP_KERNEL);
905 int timeout = get_rec_delay_jiffies(DAR_BUFF_SIZE);
906
907 if (!page)
908 return -ENOMEM;
909
910 while (count > 0) {
911 int n, k;
912 unsigned long flags;
913
914 k = PAGE_SIZE;
915 if (k > count)
916 k = count;
917
918 /* Critical section: protect fifo in non-interrupt */
919 spin_lock_irqsave(&dev.lock, flags);
920 n = msnd_fifo_read(&dev.DARF, page, k);
921 spin_unlock_irqrestore(&dev.lock, flags);
922 if (copy_to_user(buf, page, n)) {
923 free_page((unsigned long)page);
924 return -EFAULT;
925 }
926 buf += n;
927 count -= n;
928
929 if (n == k && count)
930 continue;
931
932 if (!test_bit(F_READING, &dev.flags) && dev.mode & FMODE_READ) {
933 dev.last_recbank = -1;
934 if (chk_send_dsp_cmd(&dev, HDEX_RECORD_START) == 0)
935 set_bit(F_READING, &dev.flags);
936 }
937
938 if (dev.rec_ndelay) {
939 free_page((unsigned long)page);
940 return count == len ? -EAGAIN : len - count;
941 }
942
943 if (count > 0) {
944 set_bit(F_READBLOCK, &dev.flags);
945 if (wait_event_interruptible_timeout(
946 dev.readblock,
947 test_bit(F_READBLOCK, &dev.flags),
948 timeout) <= 0)
949 clear_bit(F_READING, &dev.flags);
950 if (signal_pending(current)) {
951 free_page((unsigned long)page);
952 return -EINTR;
953 }
954 }
955 }
956 free_page((unsigned long)page);
957 return len - count;
958}
959
960static int dsp_write(const char __user *buf, size_t len)
961{
962 int count = len;
963 char *page = (char *)__get_free_page(GFP_KERNEL);
964 int timeout = get_play_delay_jiffies(DAP_BUFF_SIZE);
965
966 if (!page)
967 return -ENOMEM;
968
969 while (count > 0) {
970 int n, k;
971 unsigned long flags;
972
973 k = PAGE_SIZE;
974 if (k > count)
975 k = count;
976
977 if (copy_from_user(page, buf, k)) {
978 free_page((unsigned long)page);
979 return -EFAULT;
980 }
981
982 /* Critical section: protect fifo in non-interrupt */
983 spin_lock_irqsave(&dev.lock, flags);
984 n = msnd_fifo_write(&dev.DAPF, page, k);
985 spin_unlock_irqrestore(&dev.lock, flags);
986 buf += n;
987 count -= n;
988
989 if (count && n == k)
990 continue;
991
992 if (!test_bit(F_WRITING, &dev.flags) && (dev.mode & FMODE_WRITE)) {
993 dev.last_playbank = -1;
994 if (pack_DAPF_to_DAPQ(1) > 0)
995 set_bit(F_WRITING, &dev.flags);
996 }
997
998 if (dev.play_ndelay) {
999 free_page((unsigned long)page);
1000 return count == len ? -EAGAIN : len - count;
1001 }
1002
1003 if (count > 0) {
1004 set_bit(F_WRITEBLOCK, &dev.flags);
1005 wait_event_interruptible_timeout(
1006 dev.writeblock,
1007 test_bit(F_WRITEBLOCK, &dev.flags),
1008 timeout);
1009 if (signal_pending(current)) {
1010 free_page((unsigned long)page);
1011 return -EINTR;
1012 }
1013 }
1014 }
1015
1016 free_page((unsigned long)page);
1017 return len - count;
1018}
1019
1020static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_t *off)
1021{
1022 int minor = iminor(file_inode(file));
1023 if (minor == dev.dsp_minor)
1024 return dsp_read(buf, count);
1025 else
1026 return -EINVAL;
1027}
1028
1029static ssize_t dev_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
1030{
1031 int minor = iminor(file_inode(file));
1032 if (minor == dev.dsp_minor)
1033 return dsp_write(buf, count);
1034 else
1035 return -EINVAL;
1036}
1037
1038static __inline__ void eval_dsp_msg(register WORD wMessage)
1039{
1040 switch (HIBYTE(wMessage)) {
1041 case HIMT_PLAY_DONE:
1042 if (dev.last_playbank == LOBYTE(wMessage) || !test_bit(F_WRITING, &dev.flags))
1043 break;
1044 dev.last_playbank = LOBYTE(wMessage);
1045
1046 if (pack_DAPF_to_DAPQ(0) <= 0) {
1047 if (!test_bit(F_WRITEBLOCK, &dev.flags)) {
1048 if (test_and_clear_bit(F_WRITEFLUSH, &dev.flags))
1049 wake_up_interruptible(&dev.writeflush);
1050 }
1051 clear_bit(F_WRITING, &dev.flags);
1052 }
1053
1054 if (test_and_clear_bit(F_WRITEBLOCK, &dev.flags))
1055 wake_up_interruptible(&dev.writeblock);
1056 break;
1057
1058 case HIMT_RECORD_DONE:
1059 if (dev.last_recbank == LOBYTE(wMessage))
1060 break;
1061 dev.last_recbank = LOBYTE(wMessage);
1062
1063 pack_DARQ_to_DARF(dev.last_recbank);
1064
1065 if (test_and_clear_bit(F_READBLOCK, &dev.flags))
1066 wake_up_interruptible(&dev.readblock);
1067 break;
1068
1069 case HIMT_DSP:
1070 switch (LOBYTE(wMessage)) {
1071#ifndef MSND_CLASSIC
1072 case HIDSP_PLAY_UNDER:
1073#endif
1074 case HIDSP_INT_PLAY_UNDER:
1075/* printk(KERN_DEBUG LOGNAME ": Play underflow\n"); */
1076 clear_bit(F_WRITING, &dev.flags);
1077 break;
1078
1079 case HIDSP_INT_RECORD_OVER:
1080/* printk(KERN_DEBUG LOGNAME ": Record overflow\n"); */
1081 clear_bit(F_READING, &dev.flags);
1082 break;
1083
1084 default:
1085/* printk(KERN_DEBUG LOGNAME ": DSP message %d 0x%02x\n",
1086 LOBYTE(wMessage), LOBYTE(wMessage)); */
1087 break;
1088 }
1089 break;
1090
1091 case HIMT_MIDI_IN_UCHAR:
1092 if (dev.midi_in_interrupt)
1093 (*dev.midi_in_interrupt)(&dev);
1094 break;
1095
1096 default:
1097/* printk(KERN_DEBUG LOGNAME ": HIMT message %d 0x%02x\n", HIBYTE(wMessage), HIBYTE(wMessage)); */
1098 break;
1099 }
1100}
1101
1102static irqreturn_t intr(int irq, void *dev_id)
1103{
1104 /* Send ack to DSP */
1105 msnd_inb(dev.io + HP_RXL);
1106
1107 /* Evaluate queued DSP messages */
1108 while (readw(dev.DSPQ + JQS_wTail) != readw(dev.DSPQ + JQS_wHead)) {
1109 register WORD wTmp;
1110
1111 eval_dsp_msg(readw(dev.pwDSPQData + 2*readw(dev.DSPQ + JQS_wHead)));
1112
1113 if ((wTmp = readw(dev.DSPQ + JQS_wHead) + 1) > readw(dev.DSPQ + JQS_wSize))
1114 writew(0, dev.DSPQ + JQS_wHead);
1115 else
1116 writew(wTmp, dev.DSPQ + JQS_wHead);
1117 }
1118 return IRQ_HANDLED;
1119}
1120
1121static const struct file_operations dev_fileops = {
1122 .owner = THIS_MODULE,
1123 .read = dev_read,
1124 .write = dev_write,
1125 .unlocked_ioctl = dev_ioctl,
1126 .open = dev_open,
1127 .release = dev_release,
1128 .llseek = noop_llseek,
1129};
1130
1131static int reset_dsp(void)
1132{
1133 int timeout = 100;
1134
1135 msnd_outb(HPDSPRESET_ON, dev.io + HP_DSPR);
1136 mdelay(1);
1137#ifndef MSND_CLASSIC
1138 dev.info = msnd_inb(dev.io + HP_INFO);
1139#endif
1140 msnd_outb(HPDSPRESET_OFF, dev.io + HP_DSPR);
1141 mdelay(1);
1142 while (timeout-- > 0) {
1143 if (msnd_inb(dev.io + HP_CVR) == HP_CVR_DEF)
1144 return 0;
1145 mdelay(1);
1146 }
1147 printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
1148
1149 return -EIO;
1150}
1151
1152static int __init probe_multisound(void)
1153{
1154#ifndef MSND_CLASSIC
1155 char *xv, *rev = NULL;
1156 char *pin = "Pinnacle", *fiji = "Fiji";
1157 char *pinfiji = "Pinnacle/Fiji";
1158#endif
1159
1160 if (!request_region(dev.io, dev.numio, "probing")) {
1161 printk(KERN_ERR LOGNAME ": I/O port conflict\n");
1162 return -ENODEV;
1163 }
1164
1165 if (reset_dsp() < 0) {
1166 release_region(dev.io, dev.numio);
1167 return -ENODEV;
1168 }
1169
1170#ifdef MSND_CLASSIC
1171 dev.name = "Classic/Tahiti/Monterey";
1172 printk(KERN_INFO LOGNAME ": %s, "
1173#else
1174 switch (dev.info >> 4) {
1175 case 0xf: xv = "<= 1.15"; break;
1176 case 0x1: xv = "1.18/1.2"; break;
1177 case 0x2: xv = "1.3"; break;
1178 case 0x3: xv = "1.4"; break;
1179 default: xv = "unknown"; break;
1180 }
1181
1182 switch (dev.info & 0x7) {
1183 case 0x0: rev = "I"; dev.name = pin; break;
1184 case 0x1: rev = "F"; dev.name = pin; break;
1185 case 0x2: rev = "G"; dev.name = pin; break;
1186 case 0x3: rev = "H"; dev.name = pin; break;
1187 case 0x4: rev = "E"; dev.name = fiji; break;
1188 case 0x5: rev = "C"; dev.name = fiji; break;
1189 case 0x6: rev = "D"; dev.name = fiji; break;
1190 case 0x7:
1191 rev = "A-B (Fiji) or A-E (Pinnacle)";
1192 dev.name = pinfiji;
1193 break;
1194 }
1195 printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
1196#endif /* MSND_CLASSIC */
1197 "I/O 0x%x-0x%x, IRQ %d, memory mapped to %p-%p\n",
1198 dev.name,
1199#ifndef MSND_CLASSIC
1200 rev, xv,
1201#endif
1202 dev.io, dev.io + dev.numio - 1,
1203 dev.irq,
1204 dev.base, dev.base + 0x7fff);
1205
1206 release_region(dev.io, dev.numio);
1207 return 0;
1208}
1209
1210static int init_sma(void)
1211{
1212 static int initted;
1213 WORD mastVolLeft, mastVolRight;
1214 unsigned long flags;
1215
1216#ifdef MSND_CLASSIC
1217 msnd_outb(dev.memid, dev.io + HP_MEMM);
1218#endif
1219 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1220 if (initted) {
1221 mastVolLeft = readw(dev.SMA + SMA_wCurrMastVolLeft);
1222 mastVolRight = readw(dev.SMA + SMA_wCurrMastVolRight);
1223 } else
1224 mastVolLeft = mastVolRight = 0;
1225 memset_io(dev.base, 0, 0x8000);
1226
1227 /* Critical section: bank 1 access */
1228 spin_lock_irqsave(&dev.lock, flags);
1229 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
1230 memset_io(dev.base, 0, 0x8000);
1231 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1232 spin_unlock_irqrestore(&dev.lock, flags);
1233
1234 dev.pwDSPQData = (dev.base + DSPQ_DATA_BUFF);
1235 dev.pwMODQData = (dev.base + MODQ_DATA_BUFF);
1236 dev.pwMIDQData = (dev.base + MIDQ_DATA_BUFF);
1237
1238 /* Motorola 56k shared memory base */
1239 dev.SMA = dev.base + SMA_STRUCT_START;
1240
1241 /* Digital audio play queue */
1242 dev.DAPQ = dev.base + DAPQ_OFFSET;
1243 msnd_init_queue(dev.DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
1244
1245 /* Digital audio record queue */
1246 dev.DARQ = dev.base + DARQ_OFFSET;
1247 msnd_init_queue(dev.DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
1248
1249 /* MIDI out queue */
1250 dev.MODQ = dev.base + MODQ_OFFSET;
1251 msnd_init_queue(dev.MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
1252
1253 /* MIDI in queue */
1254 dev.MIDQ = dev.base + MIDQ_OFFSET;
1255 msnd_init_queue(dev.MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
1256
1257 /* DSP -> host message queue */
1258 dev.DSPQ = dev.base + DSPQ_OFFSET;
1259 msnd_init_queue(dev.DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
1260
1261 /* Setup some DSP values */
1262#ifndef MSND_CLASSIC
1263 writew(1, dev.SMA + SMA_wCurrPlayFormat);
1264 writew(dev.play_sample_size, dev.SMA + SMA_wCurrPlaySampleSize);
1265 writew(dev.play_channels, dev.SMA + SMA_wCurrPlayChannels);
1266 writew(dev.play_sample_rate, dev.SMA + SMA_wCurrPlaySampleRate);
1267#endif
1268 writew(dev.play_sample_rate, dev.SMA + SMA_wCalFreqAtoD);
1269 writew(mastVolLeft, dev.SMA + SMA_wCurrMastVolLeft);
1270 writew(mastVolRight, dev.SMA + SMA_wCurrMastVolRight);
1271#ifndef MSND_CLASSIC
1272 writel(0x00010000, dev.SMA + SMA_dwCurrPlayPitch);
1273 writel(0x00000001, dev.SMA + SMA_dwCurrPlayRate);
1274#endif
1275 writew(0x303, dev.SMA + SMA_wCurrInputTagBits);
1276
1277 initted = 1;
1278
1279 return 0;
1280}
1281
1282static int __init calibrate_adc(WORD srate)
1283{
1284 writew(srate, dev.SMA + SMA_wCalFreqAtoD);
1285 if (dev.calibrate_signal == 0)
1286 writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
1287 | 0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
1288 else
1289 writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
1290 & ~0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
1291 if (msnd_send_word(&dev, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
1292 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ) == 0) {
1293 schedule_timeout_interruptible(HZ / 3);
1294 return 0;
1295 }
1296 printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
1297
1298 return -EIO;
1299}
1300
1301static int upload_dsp_code(void)
1302{
1303 int ret = 0;
1304
1305 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1306#ifndef HAVE_DSPCODEH
1307 INITCODESIZE = mod_firmware_load(INITCODEFILE, &INITCODE);
1308 if (!INITCODE) {
1309 printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
1310 return -EBUSY;
1311 }
1312
1313 PERMCODESIZE = mod_firmware_load(PERMCODEFILE, &PERMCODE);
1314 if (!PERMCODE) {
1315 printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
1316 vfree(INITCODE);
1317 return -EBUSY;
1318 }
1319#endif
1320 memcpy_toio(dev.base, PERMCODE, PERMCODESIZE);
1321 if (msnd_upload_host(&dev, INITCODE, INITCODESIZE) < 0) {
1322 printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
1323 ret = -ENODEV;
1324 goto out;
1325 }
1326#ifdef HAVE_DSPCODEH
1327 printk(KERN_INFO LOGNAME ": DSP firmware uploaded (resident)\n");
1328#else
1329 printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
1330#endif
1331
1332out:
1333#ifndef HAVE_DSPCODEH
1334 vfree(INITCODE);
1335 vfree(PERMCODE);
1336#endif
1337
1338 return ret;
1339}
1340
1341#ifdef MSND_CLASSIC
1342static void reset_proteus(void)
1343{
1344 msnd_outb(HPPRORESET_ON, dev.io + HP_PROR);
1345 mdelay(TIME_PRO_RESET);
1346 msnd_outb(HPPRORESET_OFF, dev.io + HP_PROR);
1347 mdelay(TIME_PRO_RESET_DONE);
1348}
1349#endif
1350
1351static int initialize(void)
1352{
1353 int err, timeout;
1354
1355#ifdef MSND_CLASSIC
1356 msnd_outb(HPWAITSTATE_0, dev.io + HP_WAIT);
1357 msnd_outb(HPBITMODE_16, dev.io + HP_BITM);
1358
1359 reset_proteus();
1360#endif
1361 if ((err = init_sma()) < 0) {
1362 printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
1363 return err;
1364 }
1365
1366 if ((err = reset_dsp()) < 0)
1367 return err;
1368
1369 if ((err = upload_dsp_code()) < 0) {
1370 printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
1371 return err;
1372 }
1373
1374 timeout = 200;
1375 while (readw(dev.base)) {
1376 mdelay(1);
1377 if (!timeout--) {
1378 printk(KERN_DEBUG LOGNAME ": DSP reset timeout\n");
1379 return -EIO;
1380 }
1381 }
1382
1383 mixer_setup();
1384
1385 return 0;
1386}
1387
1388static int dsp_full_reset(void)
1389{
1390 int rv;
1391
1392 if (test_bit(F_RESETTING, &dev.flags) || ++dev.nresets > 10)
1393 return 0;
1394
1395 set_bit(F_RESETTING, &dev.flags);
1396 printk(KERN_INFO LOGNAME ": DSP reset\n");
1397 dsp_halt(NULL); /* Unconditionally halt */
1398 if ((rv = initialize()))
1399 printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
1400 force_recsrc(dev.recsrc);
1401 dsp_open(NULL);
1402 clear_bit(F_RESETTING, &dev.flags);
1403
1404 return rv;
1405}
1406
1407static int __init attach_multisound(void)
1408{
1409 int err;
1410
1411 if ((err = request_irq(dev.irq, intr, 0, dev.name, &dev)) < 0) {
1412 printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", dev.irq);
1413 return err;
1414 }
1415 if (request_region(dev.io, dev.numio, dev.name) == NULL) {
1416 free_irq(dev.irq, &dev);
1417 return -EBUSY;
1418 }
1419
1420 err = dsp_full_reset();
1421 if (err < 0) {
1422 release_region(dev.io, dev.numio);
1423 free_irq(dev.irq, &dev);
1424 return err;
1425 }
1426
1427 if ((err = msnd_register(&dev)) < 0) {
1428 printk(KERN_ERR LOGNAME ": Unable to register MultiSound\n");
1429 release_region(dev.io, dev.numio);
1430 free_irq(dev.irq, &dev);
1431 return err;
1432 }
1433
1434 if ((dev.dsp_minor = register_sound_dsp(&dev_fileops, -1)) < 0) {
1435 printk(KERN_ERR LOGNAME ": Unable to register DSP operations\n");
1436 msnd_unregister(&dev);
1437 release_region(dev.io, dev.numio);
1438 free_irq(dev.irq, &dev);
1439 return dev.dsp_minor;
1440 }
1441
1442 if ((dev.mixer_minor = register_sound_mixer(&dev_fileops, -1)) < 0) {
1443 printk(KERN_ERR LOGNAME ": Unable to register mixer operations\n");
1444 unregister_sound_mixer(dev.mixer_minor);
1445 msnd_unregister(&dev);
1446 release_region(dev.io, dev.numio);
1447 free_irq(dev.irq, &dev);
1448 return dev.mixer_minor;
1449 }
1450
1451 dev.ext_midi_dev = dev.hdr_midi_dev = -1;
1452
1453 disable_irq(dev.irq);
1454 calibrate_adc(dev.play_sample_rate);
1455#ifndef MSND_CLASSIC
1456 force_recsrc(SOUND_MASK_IMIX);
1457#endif
1458
1459 return 0;
1460}
1461
1462static void __exit unload_multisound(void)
1463{
1464 release_region(dev.io, dev.numio);
1465 free_irq(dev.irq, &dev);
1466 unregister_sound_mixer(dev.mixer_minor);
1467 unregister_sound_dsp(dev.dsp_minor);
1468 msnd_unregister(&dev);
1469}
1470
1471#ifndef MSND_CLASSIC
1472
1473/* Pinnacle/Fiji Logical Device Configuration */
1474
1475static int __init msnd_write_cfg(int cfg, int reg, int value)
1476{
1477 msnd_outb(reg, cfg);
1478 msnd_outb(value, cfg + 1);
1479 if (value != msnd_inb(cfg + 1)) {
1480 printk(KERN_ERR LOGNAME ": msnd_write_cfg: I/O error\n");
1481 return -EIO;
1482 }
1483 return 0;
1484}
1485
1486static int __init msnd_write_cfg_io0(int cfg, int num, WORD io)
1487{
1488 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1489 return -EIO;
1490 if (msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
1491 return -EIO;
1492 if (msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
1493 return -EIO;
1494 return 0;
1495}
1496
1497static int __init msnd_write_cfg_io1(int cfg, int num, WORD io)
1498{
1499 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1500 return -EIO;
1501 if (msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
1502 return -EIO;
1503 if (msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
1504 return -EIO;
1505 return 0;
1506}
1507
1508static int __init msnd_write_cfg_irq(int cfg, int num, WORD irq)
1509{
1510 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1511 return -EIO;
1512 if (msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
1513 return -EIO;
1514 if (msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
1515 return -EIO;
1516 return 0;
1517}
1518
1519static int __init msnd_write_cfg_mem(int cfg, int num, int mem)
1520{
1521 WORD wmem;
1522
1523 mem >>= 8;
1524 mem &= 0xfff;
1525 wmem = (WORD)mem;
1526 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1527 return -EIO;
1528 if (msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
1529 return -EIO;
1530 if (msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
1531 return -EIO;
1532 if (wmem && msnd_write_cfg(cfg, IREG_MEMCONTROL, (MEMTYPE_HIADDR | MEMTYPE_16BIT)))
1533 return -EIO;
1534 return 0;
1535}
1536
1537static int __init msnd_activate_logical(int cfg, int num)
1538{
1539 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1540 return -EIO;
1541 if (msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
1542 return -EIO;
1543 return 0;
1544}
1545
1546static int __init msnd_write_cfg_logical(int cfg, int num, WORD io0, WORD io1, WORD irq, int mem)
1547{
1548 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1549 return -EIO;
1550 if (msnd_write_cfg_io0(cfg, num, io0))
1551 return -EIO;
1552 if (msnd_write_cfg_io1(cfg, num, io1))
1553 return -EIO;
1554 if (msnd_write_cfg_irq(cfg, num, irq))
1555 return -EIO;
1556 if (msnd_write_cfg_mem(cfg, num, mem))
1557 return -EIO;
1558 if (msnd_activate_logical(cfg, num))
1559 return -EIO;
1560 return 0;
1561}
1562
1563typedef struct msnd_pinnacle_cfg_device {
1564 WORD io0, io1, irq;
1565 int mem;
1566} msnd_pinnacle_cfg_t[4];
1567
1568static int __init msnd_pinnacle_cfg_devices(int cfg, int reset, msnd_pinnacle_cfg_t device)
1569{
1570 int i;
1571
1572 /* Reset devices if told to */
1573 if (reset) {
1574 printk(KERN_INFO LOGNAME ": Resetting all devices\n");
1575 for (i = 0; i < 4; ++i)
1576 if (msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
1577 return -EIO;
1578 }
1579
1580 /* Configure specified devices */
1581 for (i = 0; i < 4; ++i) {
1582
1583 switch (i) {
1584 case 0: /* DSP */
1585 if (!(device[i].io0 && device[i].irq && device[i].mem))
1586 continue;
1587 break;
1588 case 1: /* MPU */
1589 if (!(device[i].io0 && device[i].irq))
1590 continue;
1591 printk(KERN_INFO LOGNAME
1592 ": Configuring MPU to I/O 0x%x IRQ %d\n",
1593 device[i].io0, device[i].irq);
1594 break;
1595 case 2: /* IDE */
1596 if (!(device[i].io0 && device[i].io1 && device[i].irq))
1597 continue;
1598 printk(KERN_INFO LOGNAME
1599 ": Configuring IDE to I/O 0x%x, 0x%x IRQ %d\n",
1600 device[i].io0, device[i].io1, device[i].irq);
1601 break;
1602 case 3: /* Joystick */
1603 if (!(device[i].io0))
1604 continue;
1605 printk(KERN_INFO LOGNAME
1606 ": Configuring joystick to I/O 0x%x\n",
1607 device[i].io0);
1608 break;
1609 }
1610
1611 /* Configure the device */
1612 if (msnd_write_cfg_logical(cfg, i, device[i].io0, device[i].io1, device[i].irq, device[i].mem))
1613 return -EIO;
1614 }
1615
1616 return 0;
1617}
1618#endif
1619
1620#ifdef MODULE
1621MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
1622MODULE_DESCRIPTION ("Turtle Beach " LONGNAME " Linux Driver");
1623MODULE_LICENSE("GPL");
1624
1625static int io __initdata = -1;
1626static int irq __initdata = -1;
1627static int mem __initdata = -1;
1628static int write_ndelay __initdata = -1;
1629
1630#ifndef MSND_CLASSIC
1631/* Pinnacle/Fiji non-PnP Config Port */
1632static int cfg __initdata = -1;
1633
1634/* Extra Peripheral Configuration */
1635static int reset __initdata = 0;
1636static int mpu_io __initdata = 0;
1637static int mpu_irq __initdata = 0;
1638static int ide_io0 __initdata = 0;
1639static int ide_io1 __initdata = 0;
1640static int ide_irq __initdata = 0;
1641static int joystick_io __initdata = 0;
1642
1643/* If we have the digital daugherboard... */
1644static bool digital __initdata = false;
1645#endif
1646
1647static int fifosize __initdata = DEFFIFOSIZE;
1648static int calibrate_signal __initdata = 0;
1649
1650#else /* not a module */
1651
1652static int write_ndelay __initdata = -1;
1653
1654#ifdef MSND_CLASSIC
1655static int io __initdata = CONFIG_MSNDCLAS_IO;
1656static int irq __initdata = CONFIG_MSNDCLAS_IRQ;
1657static int mem __initdata = CONFIG_MSNDCLAS_MEM;
1658#else /* Pinnacle/Fiji */
1659
1660static int io __initdata = CONFIG_MSNDPIN_IO;
1661static int irq __initdata = CONFIG_MSNDPIN_IRQ;
1662static int mem __initdata = CONFIG_MSNDPIN_MEM;
1663
1664/* Pinnacle/Fiji non-PnP Config Port */
1665#ifdef CONFIG_MSNDPIN_NONPNP
1666# ifndef CONFIG_MSNDPIN_CFG
1667# define CONFIG_MSNDPIN_CFG 0x250
1668# endif
1669#else
1670# ifdef CONFIG_MSNDPIN_CFG
1671# undef CONFIG_MSNDPIN_CFG
1672# endif
1673# define CONFIG_MSNDPIN_CFG -1
1674#endif
1675static int cfg __initdata = CONFIG_MSNDPIN_CFG;
1676/* If not a module, we don't need to bother with reset=1 */
1677static int reset;
1678
1679/* Extra Peripheral Configuration (Default: Disable) */
1680#ifndef CONFIG_MSNDPIN_MPU_IO
1681# define CONFIG_MSNDPIN_MPU_IO 0
1682#endif
1683static int mpu_io __initdata = CONFIG_MSNDPIN_MPU_IO;
1684
1685#ifndef CONFIG_MSNDPIN_MPU_IRQ
1686# define CONFIG_MSNDPIN_MPU_IRQ 0
1687#endif
1688static int mpu_irq __initdata = CONFIG_MSNDPIN_MPU_IRQ;
1689
1690#ifndef CONFIG_MSNDPIN_IDE_IO0
1691# define CONFIG_MSNDPIN_IDE_IO0 0
1692#endif
1693static int ide_io0 __initdata = CONFIG_MSNDPIN_IDE_IO0;
1694
1695#ifndef CONFIG_MSNDPIN_IDE_IO1
1696# define CONFIG_MSNDPIN_IDE_IO1 0
1697#endif
1698static int ide_io1 __initdata = CONFIG_MSNDPIN_IDE_IO1;
1699
1700#ifndef CONFIG_MSNDPIN_IDE_IRQ
1701# define CONFIG_MSNDPIN_IDE_IRQ 0
1702#endif
1703static int ide_irq __initdata = CONFIG_MSNDPIN_IDE_IRQ;
1704
1705#ifndef CONFIG_MSNDPIN_JOYSTICK_IO
1706# define CONFIG_MSNDPIN_JOYSTICK_IO 0
1707#endif
1708static int joystick_io __initdata = CONFIG_MSNDPIN_JOYSTICK_IO;
1709
1710/* Have SPDIF (Digital) Daughterboard */
1711#ifndef CONFIG_MSNDPIN_DIGITAL
1712# define CONFIG_MSNDPIN_DIGITAL 0
1713#endif
1714static bool digital __initdata = CONFIG_MSNDPIN_DIGITAL;
1715
1716#endif /* MSND_CLASSIC */
1717
1718#ifndef CONFIG_MSND_FIFOSIZE
1719# define CONFIG_MSND_FIFOSIZE DEFFIFOSIZE
1720#endif
1721static int fifosize __initdata = CONFIG_MSND_FIFOSIZE;
1722
1723#ifndef CONFIG_MSND_CALSIGNAL
1724# define CONFIG_MSND_CALSIGNAL 0
1725#endif
1726static int
1727calibrate_signal __initdata = CONFIG_MSND_CALSIGNAL;
1728#endif /* MODULE */
1729
1730module_param_hw (io, int, ioport, 0);
1731module_param_hw (irq, int, irq, 0);
1732module_param_hw (mem, int, iomem, 0);
1733module_param (write_ndelay, int, 0);
1734module_param (fifosize, int, 0);
1735module_param (calibrate_signal, int, 0);
1736#ifndef MSND_CLASSIC
1737module_param (digital, bool, 0);
1738module_param_hw (cfg, int, ioport, 0);
1739module_param (reset, int, 0);
1740module_param_hw (mpu_io, int, ioport, 0);
1741module_param_hw (mpu_irq, int, irq, 0);
1742module_param_hw (ide_io0, int, ioport, 0);
1743module_param_hw (ide_io1, int, ioport, 0);
1744module_param_hw (ide_irq, int, irq, 0);
1745module_param_hw (joystick_io, int, ioport, 0);
1746#endif
1747
1748static int __init msnd_init(void)
1749{
1750 int err;
1751#ifndef MSND_CLASSIC
1752 static msnd_pinnacle_cfg_t pinnacle_devs;
1753#endif /* MSND_CLASSIC */
1754
1755 printk(KERN_INFO LOGNAME ": Turtle Beach " LONGNAME " Linux Driver Version "
1756 VERSION ", Copyright (C) 1998 Andrew Veliath\n");
1757
1758 if (io == -1 || irq == -1 || mem == -1)
1759 printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
1760
1761#ifdef MSND_CLASSIC
1762 if (io == -1 ||
1763 !(io == 0x290 ||
1764 io == 0x260 ||
1765 io == 0x250 ||
1766 io == 0x240 ||
1767 io == 0x230 ||
1768 io == 0x220 ||
1769 io == 0x210 ||
1770 io == 0x3e0)) {
1771 printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, or 0x3E0\n");
1772 return -EINVAL;
1773 }
1774#else
1775 if (io == -1 ||
1776 io < 0x100 ||
1777 io > 0x3e0 ||
1778 (io % 0x10) != 0) {
1779 printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must within the range 0x100 to 0x3E0 and must be evenly divisible by 0x10\n");
1780 return -EINVAL;
1781 }
1782#endif /* MSND_CLASSIC */
1783
1784 if (irq == -1 ||
1785 !(irq == 5 ||
1786 irq == 7 ||
1787 irq == 9 ||
1788 irq == 10 ||
1789 irq == 11 ||
1790 irq == 12)) {
1791 printk(KERN_ERR LOGNAME ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
1792 return -EINVAL;
1793 }
1794
1795 if (mem == -1 ||
1796 !(mem == 0xb0000 ||
1797 mem == 0xc8000 ||
1798 mem == 0xd0000 ||
1799 mem == 0xd8000 ||
1800 mem == 0xe0000 ||
1801 mem == 0xe8000)) {
1802 printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
1803 "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
1804 return -EINVAL;
1805 }
1806
1807#ifdef MSND_CLASSIC
1808 switch (irq) {
1809 case 5: dev.irqid = HPIRQ_5; break;
1810 case 7: dev.irqid = HPIRQ_7; break;
1811 case 9: dev.irqid = HPIRQ_9; break;
1812 case 10: dev.irqid = HPIRQ_10; break;
1813 case 11: dev.irqid = HPIRQ_11; break;
1814 case 12: dev.irqid = HPIRQ_12; break;
1815 }
1816
1817 switch (mem) {
1818 case 0xb0000: dev.memid = HPMEM_B000; break;
1819 case 0xc8000: dev.memid = HPMEM_C800; break;
1820 case 0xd0000: dev.memid = HPMEM_D000; break;
1821 case 0xd8000: dev.memid = HPMEM_D800; break;
1822 case 0xe0000: dev.memid = HPMEM_E000; break;
1823 case 0xe8000: dev.memid = HPMEM_E800; break;
1824 }
1825#else
1826 if (cfg == -1) {
1827 printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
1828 } else if (cfg != 0x250 && cfg != 0x260 && cfg != 0x270) {
1829 printk(KERN_INFO LOGNAME ": Config port must be 0x250, 0x260 or 0x270 (or unspecified for PnP mode)\n");
1830 return -EINVAL;
1831 } else {
1832 printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%x\n", cfg);
1833
1834 /* DSP */
1835 pinnacle_devs[0].io0 = io;
1836 pinnacle_devs[0].irq = irq;
1837 pinnacle_devs[0].mem = mem;
1838
1839 /* The following are Pinnacle specific */
1840
1841 /* MPU */
1842 pinnacle_devs[1].io0 = mpu_io;
1843 pinnacle_devs[1].irq = mpu_irq;
1844
1845 /* IDE */
1846 pinnacle_devs[2].io0 = ide_io0;
1847 pinnacle_devs[2].io1 = ide_io1;
1848 pinnacle_devs[2].irq = ide_irq;
1849
1850 /* Joystick */
1851 pinnacle_devs[3].io0 = joystick_io;
1852
1853 if (!request_region(cfg, 2, "Pinnacle/Fiji Config")) {
1854 printk(KERN_ERR LOGNAME ": Config port 0x%x conflict\n", cfg);
1855 return -EIO;
1856 }
1857
1858 if (msnd_pinnacle_cfg_devices(cfg, reset, pinnacle_devs)) {
1859 printk(KERN_ERR LOGNAME ": Device configuration error\n");
1860 release_region(cfg, 2);
1861 return -EIO;
1862 }
1863 release_region(cfg, 2);
1864 }
1865#endif /* MSND_CLASSIC */
1866
1867 if (fifosize < 16)
1868 fifosize = 16;
1869
1870 if (fifosize > 1024)
1871 fifosize = 1024;
1872
1873 set_default_audio_parameters();
1874#ifdef MSND_CLASSIC
1875 dev.type = msndClassic;
1876#else
1877 dev.type = msndPinnacle;
1878#endif
1879 dev.io = io;
1880 dev.numio = DSP_NUMIO;
1881 dev.irq = irq;
1882 dev.base = ioremap(mem, 0x8000);
1883 dev.fifosize = fifosize * 1024;
1884 dev.calibrate_signal = calibrate_signal ? 1 : 0;
1885 dev.recsrc = 0;
1886 dev.dspq_data_buff = DSPQ_DATA_BUFF;
1887 dev.dspq_buff_size = DSPQ_BUFF_SIZE;
1888 if (write_ndelay == -1)
1889 write_ndelay = CONFIG_MSND_WRITE_NDELAY;
1890 if (write_ndelay)
1891 clear_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
1892 else
1893 set_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
1894#ifndef MSND_CLASSIC
1895 if (digital)
1896 set_bit(F_HAVEDIGITAL, &dev.flags);
1897#endif
1898 init_waitqueue_head(&dev.writeblock);
1899 init_waitqueue_head(&dev.readblock);
1900 init_waitqueue_head(&dev.writeflush);
1901 msnd_fifo_init(&dev.DAPF);
1902 msnd_fifo_init(&dev.DARF);
1903 spin_lock_init(&dev.lock);
1904 printk(KERN_INFO LOGNAME ": %u byte audio FIFOs (x2)\n", dev.fifosize);
1905 if ((err = msnd_fifo_alloc(&dev.DAPF, dev.fifosize)) < 0) {
1906 printk(KERN_ERR LOGNAME ": Couldn't allocate write FIFO\n");
1907 return err;
1908 }
1909
1910 if ((err = msnd_fifo_alloc(&dev.DARF, dev.fifosize)) < 0) {
1911 printk(KERN_ERR LOGNAME ": Couldn't allocate read FIFO\n");
1912 msnd_fifo_free(&dev.DAPF);
1913 return err;
1914 }
1915
1916 if ((err = probe_multisound()) < 0) {
1917 printk(KERN_ERR LOGNAME ": Probe failed\n");
1918 msnd_fifo_free(&dev.DAPF);
1919 msnd_fifo_free(&dev.DARF);
1920 return err;
1921 }
1922
1923 if ((err = attach_multisound()) < 0) {
1924 printk(KERN_ERR LOGNAME ": Attach failed\n");
1925 msnd_fifo_free(&dev.DAPF);
1926 msnd_fifo_free(&dev.DARF);
1927 return err;
1928 }
1929
1930 return 0;
1931}
1932
1933static void __exit msdn_cleanup(void)
1934{
1935 unload_multisound();
1936 msnd_fifo_free(&dev.DAPF);
1937 msnd_fifo_free(&dev.DARF);
1938}
1939
1940module_init(msnd_init);
1941module_exit(msdn_cleanup);
diff --git a/sound/oss/msnd_pinnacle.h b/sound/oss/msnd_pinnacle.h
deleted file mode 100644
index c18d66cbbe3f..000000000000
--- a/sound/oss/msnd_pinnacle.h
+++ /dev/null
@@ -1,246 +0,0 @@
1/*********************************************************************
2 *
3 * msnd_pinnacle.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_PINNACLE_H
29#define __MSND_PINNACLE_H
30
31
32#define DSP_NUMIO 0x08
33
34#define IREG_LOGDEVICE 0x07
35#define IREG_ACTIVATE 0x30
36#define LD_ACTIVATE 0x01
37#define LD_DISACTIVATE 0x00
38#define IREG_EECONTROL 0x3F
39#define IREG_MEMBASEHI 0x40
40#define IREG_MEMBASELO 0x41
41#define IREG_MEMCONTROL 0x42
42#define IREG_MEMRANGEHI 0x43
43#define IREG_MEMRANGELO 0x44
44#define MEMTYPE_8BIT 0x00
45#define MEMTYPE_16BIT 0x02
46#define MEMTYPE_RANGE 0x00
47#define MEMTYPE_HIADDR 0x01
48#define IREG_IO0_BASEHI 0x60
49#define IREG_IO0_BASELO 0x61
50#define IREG_IO1_BASEHI 0x62
51#define IREG_IO1_BASELO 0x63
52#define IREG_IRQ_NUMBER 0x70
53#define IREG_IRQ_TYPE 0x71
54#define IRQTYPE_HIGH 0x02
55#define IRQTYPE_LOW 0x00
56#define IRQTYPE_LEVEL 0x01
57#define IRQTYPE_EDGE 0x00
58
59#define HP_DSPR 0x04
60#define HP_BLKS 0x04
61
62#define HPDSPRESET_OFF 2
63#define HPDSPRESET_ON 0
64
65#define HPBLKSEL_0 2
66#define HPBLKSEL_1 3
67
68#define HIMT_DAT_OFF 0x03
69
70#define HIDSP_PLAY_UNDER 0x00
71#define HIDSP_INT_PLAY_UNDER 0x01
72#define HIDSP_SSI_TX_UNDER 0x02
73#define HIDSP_RECQ_OVERFLOW 0x08
74#define HIDSP_INT_RECORD_OVER 0x09
75#define HIDSP_SSI_RX_OVERFLOW 0x0a
76
77#define HIDSP_MIDI_IN_OVER 0x10
78
79#define HIDSP_MIDI_FRAME_ERR 0x11
80#define HIDSP_MIDI_PARITY_ERR 0x12
81#define HIDSP_MIDI_OVERRUN_ERR 0x13
82
83#define HIDSP_INPUT_CLIPPING 0x20
84#define HIDSP_MIX_CLIPPING 0x30
85#define HIDSP_DAT_IN_OFF 0x21
86
87#define HDEXAR_SET_ANA_IN 0
88#define HDEXAR_CLEAR_PEAKS 1
89#define HDEXAR_IN_SET_POTS 2
90#define HDEXAR_AUX_SET_POTS 3
91#define HDEXAR_CAL_A_TO_D 4
92#define HDEXAR_RD_EXT_DSP_BITS 5
93
94#define HDEXAR_SET_SYNTH_IN 4
95#define HDEXAR_READ_DAT_IN 5
96#define HDEXAR_MIC_SET_POTS 6
97#define HDEXAR_SET_DAT_IN 7
98
99#define HDEXAR_SET_SYNTH_48 8
100#define HDEXAR_SET_SYNTH_44 9
101
102#define TIME_PRO_RESET_DONE 0x028A
103#define TIME_PRO_SYSEX 0x001E
104#define TIME_PRO_RESET 0x0032
105
106#define AGND 0x01
107#define SIGNAL 0x02
108
109#define EXT_DSP_BIT_DCAL 0x0001
110#define EXT_DSP_BIT_MIDI_CON 0x0002
111
112#define BUFFSIZE 0x8000
113#define HOSTQ_SIZE 0x40
114
115#define SRAM_CNTL_START 0x7F00
116#define SMA_STRUCT_START 0x7F40
117
118#define DAP_BUFF_SIZE 0x2400
119#define DAR_BUFF_SIZE 0x2000
120
121#define DAPQ_STRUCT_SIZE 0x10
122#define DARQ_STRUCT_SIZE 0x10
123#define DAPQ_BUFF_SIZE (3 * 0x10)
124#define DARQ_BUFF_SIZE (3 * 0x10)
125#define MODQ_BUFF_SIZE 0x400
126#define MIDQ_BUFF_SIZE 0x800
127#define DSPQ_BUFF_SIZE 0x5A0
128
129#define DAPQ_DATA_BUFF 0x6C00
130#define DARQ_DATA_BUFF 0x6C30
131#define MODQ_DATA_BUFF 0x6C60
132#define MIDQ_DATA_BUFF 0x7060
133#define DSPQ_DATA_BUFF 0x7860
134
135#define DAPQ_OFFSET SRAM_CNTL_START
136#define DARQ_OFFSET (SRAM_CNTL_START + 0x08)
137#define MODQ_OFFSET (SRAM_CNTL_START + 0x10)
138#define MIDQ_OFFSET (SRAM_CNTL_START + 0x18)
139#define DSPQ_OFFSET (SRAM_CNTL_START + 0x20)
140
141#define MOP_WAVEHDR 0
142#define MOP_EXTOUT 1
143#define MOP_HWINIT 0xfe
144#define MOP_NONE 0xff
145#define MOP_MAX 1
146
147#define MIP_EXTIN 0
148#define MIP_WAVEHDR 1
149#define MIP_HWINIT 0xfe
150#define MIP_MAX 1
151
152/* Pinnacle/Fiji SMA Common Data */
153#define SMA_wCurrPlayBytes 0x0000
154#define SMA_wCurrRecordBytes 0x0002
155#define SMA_wCurrPlayVolLeft 0x0004
156#define SMA_wCurrPlayVolRight 0x0006
157#define SMA_wCurrInVolLeft 0x0008
158#define SMA_wCurrInVolRight 0x000a
159#define SMA_wCurrMHdrVolLeft 0x000c
160#define SMA_wCurrMHdrVolRight 0x000e
161#define SMA_dwCurrPlayPitch 0x0010
162#define SMA_dwCurrPlayRate 0x0014
163#define SMA_wCurrMIDIIOPatch 0x0018
164#define SMA_wCurrPlayFormat 0x001a
165#define SMA_wCurrPlaySampleSize 0x001c
166#define SMA_wCurrPlayChannels 0x001e
167#define SMA_wCurrPlaySampleRate 0x0020
168#define SMA_wCurrRecordFormat 0x0022
169#define SMA_wCurrRecordSampleSize 0x0024
170#define SMA_wCurrRecordChannels 0x0026
171#define SMA_wCurrRecordSampleRate 0x0028
172#define SMA_wCurrDSPStatusFlags 0x002a
173#define SMA_wCurrHostStatusFlags 0x002c
174#define SMA_wCurrInputTagBits 0x002e
175#define SMA_wCurrLeftPeak 0x0030
176#define SMA_wCurrRightPeak 0x0032
177#define SMA_bMicPotPosLeft 0x0034
178#define SMA_bMicPotPosRight 0x0035
179#define SMA_bMicPotMaxLeft 0x0036
180#define SMA_bMicPotMaxRight 0x0037
181#define SMA_bInPotPosLeft 0x0038
182#define SMA_bInPotPosRight 0x0039
183#define SMA_bAuxPotPosLeft 0x003a
184#define SMA_bAuxPotPosRight 0x003b
185#define SMA_bInPotMaxLeft 0x003c
186#define SMA_bInPotMaxRight 0x003d
187#define SMA_bAuxPotMaxLeft 0x003e
188#define SMA_bAuxPotMaxRight 0x003f
189#define SMA_bInPotMaxMethod 0x0040
190#define SMA_bAuxPotMaxMethod 0x0041
191#define SMA_wCurrMastVolLeft 0x0042
192#define SMA_wCurrMastVolRight 0x0044
193#define SMA_wCalFreqAtoD 0x0046
194#define SMA_wCurrAuxVolLeft 0x0048
195#define SMA_wCurrAuxVolRight 0x004a
196#define SMA_wCurrPlay1VolLeft 0x004c
197#define SMA_wCurrPlay1VolRight 0x004e
198#define SMA_wCurrPlay2VolLeft 0x0050
199#define SMA_wCurrPlay2VolRight 0x0052
200#define SMA_wCurrPlay3VolLeft 0x0054
201#define SMA_wCurrPlay3VolRight 0x0056
202#define SMA_wCurrPlay4VolLeft 0x0058
203#define SMA_wCurrPlay4VolRight 0x005a
204#define SMA_wCurrPlay1PeakLeft 0x005c
205#define SMA_wCurrPlay1PeakRight 0x005e
206#define SMA_wCurrPlay2PeakLeft 0x0060
207#define SMA_wCurrPlay2PeakRight 0x0062
208#define SMA_wCurrPlay3PeakLeft 0x0064
209#define SMA_wCurrPlay3PeakRight 0x0066
210#define SMA_wCurrPlay4PeakLeft 0x0068
211#define SMA_wCurrPlay4PeakRight 0x006a
212#define SMA_wCurrPlayPeakLeft 0x006c
213#define SMA_wCurrPlayPeakRight 0x006e
214#define SMA_wCurrDATSR 0x0070
215#define SMA_wCurrDATRXCHNL 0x0072
216#define SMA_wCurrDATTXCHNL 0x0074
217#define SMA_wCurrDATRXRate 0x0076
218#define SMA_dwDSPPlayCount 0x0078
219#define SMA__size 0x007c
220
221#ifdef HAVE_DSPCODEH
222# include "pndsperm.c"
223# include "pndspini.c"
224# define PERMCODE pndsperm
225# define INITCODE pndspini
226# define PERMCODESIZE sizeof(pndsperm)
227# define INITCODESIZE sizeof(pndspini)
228#else
229# ifndef CONFIG_MSNDPIN_INIT_FILE
230# define CONFIG_MSNDPIN_INIT_FILE \
231 "/etc/sound/pndspini.bin"
232# endif
233# ifndef CONFIG_MSNDPIN_PERM_FILE
234# define CONFIG_MSNDPIN_PERM_FILE \
235 "/etc/sound/pndsperm.bin"
236# endif
237# define PERMCODEFILE CONFIG_MSNDPIN_PERM_FILE
238# define INITCODEFILE CONFIG_MSNDPIN_INIT_FILE
239# define PERMCODE dspini
240# define INITCODE permini
241# define PERMCODESIZE sizeof_dspini
242# define INITCODESIZE sizeof_permini
243#endif
244#define LONGNAME "MultiSound (Pinnacle/Fiji)"
245
246#endif /* __MSND_PINNACLE_H */
diff --git a/sound/oss/opl3.c b/sound/oss/opl3.c
deleted file mode 100644
index f0f5b5be6314..000000000000
--- a/sound/oss/opl3.c
+++ /dev/null
@@ -1,1255 +0,0 @@
1/*
2 * sound/oss/opl3.c
3 *
4 * A low level driver for Yamaha YM3812 and OPL-3 -chips
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Changes
15 * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
16 * Alan Cox modularisation, fixed sound_mem allocs.
17 * Christoph Hellwig Adapted to module_init/module_exit
18 * Arnaldo C. de Melo get rid of check_region, use request_region for
19 * OPL4, release it on exit, some cleanups.
20 *
21 * Status
22 * Believed to work. Badly needs rewriting a bit to support multiple
23 * OPL3 devices.
24 */
25
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/module.h>
29#include <linux/delay.h>
30
31/*
32 * Major improvements to the FM handling 30AUG92 by Rob Hooft,
33 * hooft@chem.ruu.nl
34 */
35
36#include "sound_config.h"
37
38#include "opl3_hw.h"
39
40#define MAX_VOICE 18
41#define OFFS_4OP 11
42
43struct voice_info
44{
45 unsigned char keyon_byte;
46 long bender;
47 long bender_range;
48 unsigned long orig_freq;
49 unsigned long current_freq;
50 int volume;
51 int mode;
52 int panning; /* 0xffff means not set */
53};
54
55struct opl_devinfo
56{
57 int base;
58 int left_io, right_io;
59 int nr_voice;
60 int lv_map[MAX_VOICE];
61
62 struct voice_info voc[MAX_VOICE];
63 struct voice_alloc_info *v_alloc;
64 struct channel_info *chn_info;
65
66 struct sbi_instrument i_map[SBFM_MAXINSTR];
67 struct sbi_instrument *act_i[MAX_VOICE];
68
69 struct synth_info fm_info;
70
71 int busy;
72 int model;
73 unsigned char cmask;
74
75 int is_opl4;
76};
77
78static struct opl_devinfo *devc = NULL;
79
80static int detected_model;
81
82static int store_instr(int instr_no, struct sbi_instrument *instr);
83static void freq_to_fnum(int freq, int *block, int *fnum);
84static void opl3_command(int io_addr, unsigned int addr, unsigned int val);
85static int opl3_kill_note(int dev, int voice, int note, int velocity);
86
87static void enter_4op_mode(void)
88{
89 int i;
90 static int v4op[MAX_VOICE] = {
91 0, 1, 2, 9, 10, 11, 6, 7, 8, 15, 16, 17
92 };
93
94 devc->cmask = 0x3f; /* Connect all possible 4 OP voice operators */
95 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, 0x3f);
96
97 for (i = 0; i < 3; i++)
98 pv_map[i].voice_mode = 4;
99 for (i = 3; i < 6; i++)
100 pv_map[i].voice_mode = 0;
101
102 for (i = 9; i < 12; i++)
103 pv_map[i].voice_mode = 4;
104 for (i = 12; i < 15; i++)
105 pv_map[i].voice_mode = 0;
106
107 for (i = 0; i < 12; i++)
108 devc->lv_map[i] = v4op[i];
109 devc->v_alloc->max_voice = devc->nr_voice = 12;
110}
111
112static int opl3_ioctl(int dev, unsigned int cmd, void __user * arg)
113{
114 struct sbi_instrument ins;
115
116 switch (cmd) {
117 case SNDCTL_FM_LOAD_INSTR:
118 printk(KERN_WARNING "Warning: Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. Fix the program.\n");
119 if (copy_from_user(&ins, arg, sizeof(ins)))
120 return -EFAULT;
121 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR) {
122 printk(KERN_WARNING "FM Error: Invalid instrument number %d\n", ins.channel);
123 return -EINVAL;
124 }
125 return store_instr(ins.channel, &ins);
126
127 case SNDCTL_SYNTH_INFO:
128 devc->fm_info.nr_voices = (devc->nr_voice == 12) ? 6 : devc->nr_voice;
129 if (copy_to_user(arg, &devc->fm_info, sizeof(devc->fm_info)))
130 return -EFAULT;
131 return 0;
132
133 case SNDCTL_SYNTH_MEMAVL:
134 return 0x7fffffff;
135
136 case SNDCTL_FM_4OP_ENABLE:
137 if (devc->model == 2)
138 enter_4op_mode();
139 return 0;
140
141 default:
142 return -EINVAL;
143 }
144}
145
146static int opl3_detect(int ioaddr)
147{
148 /*
149 * This function returns 1 if the FM chip is present at the given I/O port
150 * The detection algorithm plays with the timer built in the FM chip and
151 * looks for a change in the status register.
152 *
153 * Note! The timers of the FM chip are not connected to AdLib (and compatible)
154 * boards.
155 *
156 * Note2! The chip is initialized if detected.
157 */
158
159 unsigned char stat1, signature;
160 int i;
161
162 if (devc != NULL)
163 {
164 printk(KERN_ERR "opl3: Only one OPL3 supported.\n");
165 return 0;
166 }
167
168 devc = kzalloc(sizeof(*devc), GFP_KERNEL);
169
170 if (devc == NULL)
171 {
172 printk(KERN_ERR "opl3: Can't allocate memory for the device control "
173 "structure \n ");
174 return 0;
175 }
176
177 strcpy(devc->fm_info.name, "OPL2");
178
179 if (!request_region(ioaddr, 4, devc->fm_info.name)) {
180 printk(KERN_WARNING "opl3: I/O port 0x%x already in use\n", ioaddr);
181 goto cleanup_devc;
182 }
183
184 devc->base = ioaddr;
185
186 /* Reset timers 1 and 2 */
187 opl3_command(ioaddr, TIMER_CONTROL_REGISTER, TIMER1_MASK | TIMER2_MASK);
188
189 /* Reset the IRQ of the FM chip */
190 opl3_command(ioaddr, TIMER_CONTROL_REGISTER, IRQ_RESET);
191
192 signature = stat1 = inb(ioaddr); /* Status register */
193
194 if (signature != 0x00 && signature != 0x06 && signature != 0x02 &&
195 signature != 0x0f)
196 {
197 MDB(printk(KERN_INFO "OPL3 not detected %x\n", signature));
198 goto cleanup_region;
199 }
200
201 if (signature == 0x06) /* OPL2 */
202 {
203 detected_model = 2;
204 }
205 else if (signature == 0x00 || signature == 0x0f) /* OPL3 or OPL4 */
206 {
207 unsigned char tmp;
208
209 detected_model = 3;
210
211 /*
212 * Detect availability of OPL4 (_experimental_). Works probably
213 * only after a cold boot. In addition the OPL4 port
214 * of the chip may not be connected to the PC bus at all.
215 */
216
217 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, 0x00);
218 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, OPL3_ENABLE | OPL4_ENABLE);
219
220 if ((tmp = inb(ioaddr)) == 0x02) /* Have a OPL4 */
221 {
222 detected_model = 4;
223 }
224
225 if (request_region(ioaddr - 8, 2, "OPL4")) /* OPL4 port was free */
226 {
227 int tmp;
228
229 outb((0x02), ioaddr - 8); /* Select OPL4 ID register */
230 udelay(10);
231 tmp = inb(ioaddr - 7); /* Read it */
232 udelay(10);
233
234 if (tmp == 0x20) /* OPL4 should return 0x20 here */
235 {
236 detected_model = 4;
237 outb((0xF8), ioaddr - 8); /* Select OPL4 FM mixer control */
238 udelay(10);
239 outb((0x1B), ioaddr - 7); /* Write value */
240 udelay(10);
241 }
242 else
243 { /* release OPL4 port */
244 release_region(ioaddr - 8, 2);
245 detected_model = 3;
246 }
247 }
248 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, 0);
249 }
250 for (i = 0; i < 9; i++)
251 opl3_command(ioaddr, KEYON_BLOCK + i, 0); /*
252 * Note off
253 */
254
255 opl3_command(ioaddr, TEST_REGISTER, ENABLE_WAVE_SELECT);
256 opl3_command(ioaddr, PERCOSSION_REGISTER, 0x00); /*
257 * Melodic mode.
258 */
259 return 1;
260cleanup_region:
261 release_region(ioaddr, 4);
262cleanup_devc:
263 kfree(devc);
264 devc = NULL;
265 return 0;
266}
267
268static int opl3_kill_note (int devno, int voice, int note, int velocity)
269{
270 struct physical_voice_info *map;
271
272 if (voice < 0 || voice >= devc->nr_voice)
273 return 0;
274
275 devc->v_alloc->map[voice] = 0;
276
277 map = &pv_map[devc->lv_map[voice]];
278
279 if (map->voice_mode == 0)
280 return 0;
281
282 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, devc->voc[voice].keyon_byte & ~0x20);
283 devc->voc[voice].keyon_byte = 0;
284 devc->voc[voice].bender = 0;
285 devc->voc[voice].volume = 64;
286 devc->voc[voice].panning = 0xffff; /* Not set */
287 devc->voc[voice].bender_range = 200;
288 devc->voc[voice].orig_freq = 0;
289 devc->voc[voice].current_freq = 0;
290 devc->voc[voice].mode = 0;
291 return 0;
292}
293
294#define HIHAT 0
295#define CYMBAL 1
296#define TOMTOM 2
297#define SNARE 3
298#define BDRUM 4
299#define UNDEFINED TOMTOM
300#define DEFAULT TOMTOM
301
302static int store_instr(int instr_no, struct sbi_instrument *instr)
303{
304 if (instr->key != FM_PATCH && (instr->key != OPL3_PATCH || devc->model != 2))
305 printk(KERN_WARNING "FM warning: Invalid patch format field (key) 0x%x\n", instr->key);
306 memcpy((char *) &(devc->i_map[instr_no]), (char *) instr, sizeof(*instr));
307 return 0;
308}
309
310static int opl3_set_instr (int dev, int voice, int instr_no)
311{
312 if (voice < 0 || voice >= devc->nr_voice)
313 return 0;
314 if (instr_no < 0 || instr_no >= SBFM_MAXINSTR)
315 instr_no = 0; /* Acoustic piano (usually) */
316
317 devc->act_i[voice] = &devc->i_map[instr_no];
318 return 0;
319}
320
321/*
322 * The next table looks magical, but it certainly is not. Its values have
323 * been calculated as table[i]=8*log(i/64)/log(2) with an obvious exception
324 * for i=0. This log-table converts a linear volume-scaling (0..127) to a
325 * logarithmic scaling as present in the FM-synthesizer chips. so : Volume
326 * 64 = 0 db = relative volume 0 and: Volume 32 = -6 db = relative
327 * volume -8 it was implemented as a table because it is only 128 bytes and
328 * it saves a lot of log() calculations. (RH)
329 */
330
331static char fm_volume_table[128] =
332{
333 -64, -48, -40, -35, -32, -29, -27, -26,
334 -24, -23, -21, -20, -19, -18, -18, -17,
335 -16, -15, -15, -14, -13, -13, -12, -12,
336 -11, -11, -10, -10, -10, -9, -9, -8,
337 -8, -8, -7, -7, -7, -6, -6, -6,
338 -5, -5, -5, -5, -4, -4, -4, -4,
339 -3, -3, -3, -3, -2, -2, -2, -2,
340 -2, -1, -1, -1, -1, 0, 0, 0,
341 0, 0, 0, 1, 1, 1, 1, 1,
342 1, 2, 2, 2, 2, 2, 2, 2,
343 3, 3, 3, 3, 3, 3, 3, 4,
344 4, 4, 4, 4, 4, 4, 4, 5,
345 5, 5, 5, 5, 5, 5, 5, 5,
346 6, 6, 6, 6, 6, 6, 6, 6,
347 6, 7, 7, 7, 7, 7, 7, 7,
348 7, 7, 7, 8, 8, 8, 8, 8
349};
350
351static void calc_vol(unsigned char *regbyte, int volume, int main_vol)
352{
353 int level = (~*regbyte & 0x3f);
354
355 if (main_vol > 127)
356 main_vol = 127;
357 volume = (volume * main_vol) / 127;
358
359 if (level)
360 level += fm_volume_table[volume];
361
362 if (level > 0x3f)
363 level = 0x3f;
364 if (level < 0)
365 level = 0;
366
367 *regbyte = (*regbyte & 0xc0) | (~level & 0x3f);
368}
369
370static void set_voice_volume(int voice, int volume, int main_vol)
371{
372 unsigned char vol1, vol2, vol3, vol4;
373 struct sbi_instrument *instr;
374 struct physical_voice_info *map;
375
376 if (voice < 0 || voice >= devc->nr_voice)
377 return;
378
379 map = &pv_map[devc->lv_map[voice]];
380 instr = devc->act_i[voice];
381
382 if (!instr)
383 instr = &devc->i_map[0];
384
385 if (instr->channel < 0)
386 return;
387
388 if (devc->voc[voice].mode == 0)
389 return;
390
391 if (devc->voc[voice].mode == 2)
392 {
393 vol1 = instr->operators[2];
394 vol2 = instr->operators[3];
395 if ((instr->operators[10] & 0x01))
396 {
397 calc_vol(&vol1, volume, main_vol);
398 calc_vol(&vol2, volume, main_vol);
399 }
400 else
401 {
402 calc_vol(&vol2, volume, main_vol);
403 }
404 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], vol1);
405 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], vol2);
406 }
407 else
408 { /*
409 * 4 OP voice
410 */
411 int connection;
412
413 vol1 = instr->operators[2];
414 vol2 = instr->operators[3];
415 vol3 = instr->operators[OFFS_4OP + 2];
416 vol4 = instr->operators[OFFS_4OP + 3];
417
418 /*
419 * The connection method for 4 OP devc->voc is defined by the rightmost
420 * bits at the offsets 10 and 10+OFFS_4OP
421 */
422
423 connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);
424
425 switch (connection)
426 {
427 case 0:
428 calc_vol(&vol4, volume, main_vol);
429 break;
430
431 case 1:
432 calc_vol(&vol2, volume, main_vol);
433 calc_vol(&vol4, volume, main_vol);
434 break;
435
436 case 2:
437 calc_vol(&vol1, volume, main_vol);
438 calc_vol(&vol4, volume, main_vol);
439 break;
440
441 case 3:
442 calc_vol(&vol1, volume, main_vol);
443 calc_vol(&vol3, volume, main_vol);
444 calc_vol(&vol4, volume, main_vol);
445 break;
446
447 default:
448 ;
449 }
450 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], vol1);
451 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], vol2);
452 opl3_command(map->ioaddr, KSL_LEVEL + map->op[2], vol3);
453 opl3_command(map->ioaddr, KSL_LEVEL + map->op[3], vol4);
454 }
455}
456
457static int opl3_start_note (int dev, int voice, int note, int volume)
458{
459 unsigned char data, fpc;
460 int block, fnum, freq, voice_mode, pan;
461 struct sbi_instrument *instr;
462 struct physical_voice_info *map;
463
464 if (voice < 0 || voice >= devc->nr_voice)
465 return 0;
466
467 map = &pv_map[devc->lv_map[voice]];
468 pan = devc->voc[voice].panning;
469
470 if (map->voice_mode == 0)
471 return 0;
472
473 if (note == 255) /*
474 * Just change the volume
475 */
476 {
477 set_voice_volume(voice, volume, devc->voc[voice].volume);
478 return 0;
479 }
480
481 /*
482 * Kill previous note before playing
483 */
484
485 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], 0xff); /*
486 * Carrier
487 * volume to
488 * min
489 */
490 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], 0xff); /*
491 * Modulator
492 * volume to
493 */
494
495 if (map->voice_mode == 4)
496 {
497 opl3_command(map->ioaddr, KSL_LEVEL + map->op[2], 0xff);
498 opl3_command(map->ioaddr, KSL_LEVEL + map->op[3], 0xff);
499 }
500
501 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, 0x00); /*
502 * Note
503 * off
504 */
505
506 instr = devc->act_i[voice];
507
508 if (!instr)
509 instr = &devc->i_map[0];
510
511 if (instr->channel < 0)
512 {
513 printk(KERN_WARNING "opl3: Initializing voice %d with undefined instrument\n", voice);
514 return 0;
515 }
516
517 if (map->voice_mode == 2 && instr->key == OPL3_PATCH)
518 return 0; /*
519 * Cannot play
520 */
521
522 voice_mode = map->voice_mode;
523
524 if (voice_mode == 4)
525 {
526 int voice_shift;
527
528 voice_shift = (map->ioaddr == devc->left_io) ? 0 : 3;
529 voice_shift += map->voice_num;
530
531 if (instr->key != OPL3_PATCH) /*
532 * Just 2 OP patch
533 */
534 {
535 voice_mode = 2;
536 devc->cmask &= ~(1 << voice_shift);
537 }
538 else
539 {
540 devc->cmask |= (1 << voice_shift);
541 }
542
543 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, devc->cmask);
544 }
545
546 /*
547 * Set Sound Characteristics
548 */
549
550 opl3_command(map->ioaddr, AM_VIB + map->op[0], instr->operators[0]);
551 opl3_command(map->ioaddr, AM_VIB + map->op[1], instr->operators[1]);
552
553 /*
554 * Set Attack/Decay
555 */
556
557 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[0], instr->operators[4]);
558 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[1], instr->operators[5]);
559
560 /*
561 * Set Sustain/Release
562 */
563
564 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[0], instr->operators[6]);
565 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[1], instr->operators[7]);
566
567 /*
568 * Set Wave Select
569 */
570
571 opl3_command(map->ioaddr, WAVE_SELECT + map->op[0], instr->operators[8]);
572 opl3_command(map->ioaddr, WAVE_SELECT + map->op[1], instr->operators[9]);
573
574 /*
575 * Set Feedback/Connection
576 */
577
578 fpc = instr->operators[10];
579
580 if (pan != 0xffff)
581 {
582 fpc &= ~STEREO_BITS;
583 if (pan < -64)
584 fpc |= VOICE_TO_LEFT;
585 else
586 if (pan > 64)
587 fpc |= VOICE_TO_RIGHT;
588 else
589 fpc |= (VOICE_TO_LEFT | VOICE_TO_RIGHT);
590 }
591
592 if (!(fpc & 0x30))
593 fpc |= 0x30; /*
594 * Ensure that at least one chn is enabled
595 */
596 opl3_command(map->ioaddr, FEEDBACK_CONNECTION + map->voice_num, fpc);
597
598 /*
599 * If the voice is a 4 OP one, initialize the operators 3 and 4 also
600 */
601
602 if (voice_mode == 4)
603 {
604 /*
605 * Set Sound Characteristics
606 */
607
608 opl3_command(map->ioaddr, AM_VIB + map->op[2], instr->operators[OFFS_4OP + 0]);
609 opl3_command(map->ioaddr, AM_VIB + map->op[3], instr->operators[OFFS_4OP + 1]);
610
611 /*
612 * Set Attack/Decay
613 */
614
615 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[2], instr->operators[OFFS_4OP + 4]);
616 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[3], instr->operators[OFFS_4OP + 5]);
617
618 /*
619 * Set Sustain/Release
620 */
621
622 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[2], instr->operators[OFFS_4OP + 6]);
623 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[3], instr->operators[OFFS_4OP + 7]);
624
625 /*
626 * Set Wave Select
627 */
628
629 opl3_command(map->ioaddr, WAVE_SELECT + map->op[2], instr->operators[OFFS_4OP + 8]);
630 opl3_command(map->ioaddr, WAVE_SELECT + map->op[3], instr->operators[OFFS_4OP + 9]);
631
632 /*
633 * Set Feedback/Connection
634 */
635
636 fpc = instr->operators[OFFS_4OP + 10];
637 if (!(fpc & 0x30))
638 fpc |= 0x30; /*
639 * Ensure that at least one chn is enabled
640 */
641 opl3_command(map->ioaddr, FEEDBACK_CONNECTION + map->voice_num + 3, fpc);
642 }
643
644 devc->voc[voice].mode = voice_mode;
645 set_voice_volume(voice, volume, devc->voc[voice].volume);
646
647 freq = devc->voc[voice].orig_freq = note_to_freq(note) / 1000;
648
649 /*
650 * Since the pitch bender may have been set before playing the note, we
651 * have to calculate the bending now.
652 */
653
654 freq = compute_finetune(devc->voc[voice].orig_freq, devc->voc[voice].bender, devc->voc[voice].bender_range, 0);
655 devc->voc[voice].current_freq = freq;
656
657 freq_to_fnum(freq, &block, &fnum);
658
659 /*
660 * Play note
661 */
662
663 data = fnum & 0xff; /*
664 * Least significant bits of fnumber
665 */
666 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data);
667
668 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
669 devc->voc[voice].keyon_byte = data;
670 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data);
671 if (voice_mode == 4)
672 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num + 3, data);
673
674 return 0;
675}
676
677static void freq_to_fnum (int freq, int *block, int *fnum)
678{
679 int f, octave;
680
681 /*
682 * Converts the note frequency to block and fnum values for the FM chip
683 */
684 /*
685 * First try to compute the block -value (octave) where the note belongs
686 */
687
688 f = freq;
689
690 octave = 5;
691
692 if (f == 0)
693 octave = 0;
694 else if (f < 261)
695 {
696 while (f < 261)
697 {
698 octave--;
699 f <<= 1;
700 }
701 }
702 else if (f > 493)
703 {
704 while (f > 493)
705 {
706 octave++;
707 f >>= 1;
708 }
709 }
710
711 if (octave > 7)
712 octave = 7;
713
714 *fnum = freq * (1 << (20 - octave)) / 49716;
715 *block = octave;
716}
717
718static void opl3_command (int io_addr, unsigned int addr, unsigned int val)
719{
720 int i;
721
722 /*
723 * The original 2-OP synth requires a quite long delay after writing to a
724 * register. The OPL-3 survives with just two INBs
725 */
726
727 outb(((unsigned char) (addr & 0xff)), io_addr);
728
729 if (devc->model != 2)
730 udelay(10);
731 else
732 for (i = 0; i < 2; i++)
733 inb(io_addr);
734
735 outb(((unsigned char) (val & 0xff)), io_addr + 1);
736
737 if (devc->model != 2)
738 udelay(30);
739 else
740 for (i = 0; i < 2; i++)
741 inb(io_addr);
742}
743
744static void opl3_reset(int devno)
745{
746 int i;
747
748 for (i = 0; i < 18; i++)
749 devc->lv_map[i] = i;
750
751 for (i = 0; i < devc->nr_voice; i++)
752 {
753 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
754 KSL_LEVEL + pv_map[devc->lv_map[i]].op[0], 0xff);
755
756 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
757 KSL_LEVEL + pv_map[devc->lv_map[i]].op[1], 0xff);
758
759 if (pv_map[devc->lv_map[i]].voice_mode == 4)
760 {
761 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
762 KSL_LEVEL + pv_map[devc->lv_map[i]].op[2], 0xff);
763
764 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
765 KSL_LEVEL + pv_map[devc->lv_map[i]].op[3], 0xff);
766 }
767
768 opl3_kill_note(devno, i, 0, 64);
769 }
770
771 if (devc->model == 2)
772 {
773 devc->v_alloc->max_voice = devc->nr_voice = 18;
774
775 for (i = 0; i < 18; i++)
776 pv_map[i].voice_mode = 2;
777
778 }
779}
780
781static int opl3_open(int dev, int mode)
782{
783 int i;
784
785 if (devc->busy)
786 return -EBUSY;
787 devc->busy = 1;
788
789 devc->v_alloc->max_voice = devc->nr_voice = (devc->model == 2) ? 18 : 9;
790 devc->v_alloc->timestamp = 0;
791
792 for (i = 0; i < 18; i++)
793 {
794 devc->v_alloc->map[i] = 0;
795 devc->v_alloc->alloc_times[i] = 0;
796 }
797
798 devc->cmask = 0x00; /*
799 * Just 2 OP mode
800 */
801 if (devc->model == 2)
802 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, devc->cmask);
803 return 0;
804}
805
806static void opl3_close(int dev)
807{
808 devc->busy = 0;
809 devc->v_alloc->max_voice = devc->nr_voice = (devc->model == 2) ? 18 : 9;
810
811 devc->fm_info.nr_drums = 0;
812 devc->fm_info.perc_mode = 0;
813
814 opl3_reset(dev);
815}
816
817static void opl3_hw_control(int dev, unsigned char *event)
818{
819}
820
821static int opl3_load_patch(int dev, int format, const char __user *addr,
822 int count, int pmgr_flag)
823{
824 struct sbi_instrument ins;
825
826 if (count <sizeof(ins))
827 {
828 printk(KERN_WARNING "FM Error: Patch record too short\n");
829 return -EINVAL;
830 }
831
832 if (copy_from_user(&ins, addr, sizeof(ins)))
833 return -EFAULT;
834
835 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR)
836 {
837 printk(KERN_WARNING "FM Error: Invalid instrument number %d\n", ins.channel);
838 return -EINVAL;
839 }
840 ins.key = format;
841
842 return store_instr(ins.channel, &ins);
843}
844
845static void opl3_panning(int dev, int voice, int value)
846{
847
848 if (voice < 0 || voice >= devc->nr_voice)
849 return;
850
851 devc->voc[voice].panning = value;
852}
853
854static void opl3_volume_method(int dev, int mode)
855{
856}
857
858#define SET_VIBRATO(cell) { \
859 tmp = instr->operators[(cell-1)+(((cell-1)/2)*OFFS_4OP)]; \
860 if (pressure > 110) \
861 tmp |= 0x40; /* Vibrato on */ \
862 opl3_command (map->ioaddr, AM_VIB + map->op[cell-1], tmp);}
863
864static void opl3_aftertouch(int dev, int voice, int pressure)
865{
866 int tmp;
867 struct sbi_instrument *instr;
868 struct physical_voice_info *map;
869
870 if (voice < 0 || voice >= devc->nr_voice)
871 return;
872
873 map = &pv_map[devc->lv_map[voice]];
874
875 if (map->voice_mode == 0)
876 return;
877
878 /*
879 * Adjust the amount of vibrato depending the pressure
880 */
881
882 instr = devc->act_i[voice];
883
884 if (!instr)
885 instr = &devc->i_map[0];
886
887 if (devc->voc[voice].mode == 4)
888 {
889 int connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);
890
891 switch (connection)
892 {
893 case 0:
894 SET_VIBRATO(4);
895 break;
896
897 case 1:
898 SET_VIBRATO(2);
899 SET_VIBRATO(4);
900 break;
901
902 case 2:
903 SET_VIBRATO(1);
904 SET_VIBRATO(4);
905 break;
906
907 case 3:
908 SET_VIBRATO(1);
909 SET_VIBRATO(3);
910 SET_VIBRATO(4);
911 break;
912
913 }
914 /*
915 * Not implemented yet
916 */
917 }
918 else
919 {
920 SET_VIBRATO(1);
921
922 if ((instr->operators[10] & 0x01)) /*
923 * Additive synthesis
924 */
925 SET_VIBRATO(2);
926 }
927}
928
929#undef SET_VIBRATO
930
931static void bend_pitch(int dev, int voice, int value)
932{
933 unsigned char data;
934 int block, fnum, freq;
935 struct physical_voice_info *map;
936
937 map = &pv_map[devc->lv_map[voice]];
938
939 if (map->voice_mode == 0)
940 return;
941
942 devc->voc[voice].bender = value;
943 if (!value)
944 return;
945 if (!(devc->voc[voice].keyon_byte & 0x20))
946 return; /*
947 * Not keyed on
948 */
949
950 freq = compute_finetune(devc->voc[voice].orig_freq, devc->voc[voice].bender, devc->voc[voice].bender_range, 0);
951 devc->voc[voice].current_freq = freq;
952
953 freq_to_fnum(freq, &block, &fnum);
954
955 data = fnum & 0xff; /*
956 * Least significant bits of fnumber
957 */
958 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data);
959
960 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
961 devc->voc[voice].keyon_byte = data;
962 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data);
963}
964
965static void opl3_controller (int dev, int voice, int ctrl_num, int value)
966{
967 if (voice < 0 || voice >= devc->nr_voice)
968 return;
969
970 switch (ctrl_num)
971 {
972 case CTRL_PITCH_BENDER:
973 bend_pitch(dev, voice, value);
974 break;
975
976 case CTRL_PITCH_BENDER_RANGE:
977 devc->voc[voice].bender_range = value;
978 break;
979
980 case CTL_MAIN_VOLUME:
981 devc->voc[voice].volume = value / 128;
982 break;
983
984 case CTL_PAN:
985 devc->voc[voice].panning = (value * 2) - 128;
986 break;
987 }
988}
989
990static void opl3_bender(int dev, int voice, int value)
991{
992 if (voice < 0 || voice >= devc->nr_voice)
993 return;
994
995 bend_pitch(dev, voice, value - 8192);
996}
997
998static int opl3_alloc_voice(int dev, int chn, int note, struct voice_alloc_info *alloc)
999{
1000 int i, p, best, first, avail, best_time = 0x7fffffff;
1001 struct sbi_instrument *instr;
1002 int is4op;
1003 int instr_no;
1004
1005 if (chn < 0 || chn > 15)
1006 instr_no = 0;
1007 else
1008 instr_no = devc->chn_info[chn].pgm_num;
1009
1010 instr = &devc->i_map[instr_no];
1011 if (instr->channel < 0 || /* Instrument not loaded */
1012 devc->nr_voice != 12) /* Not in 4 OP mode */
1013 is4op = 0;
1014 else if (devc->nr_voice == 12) /* 4 OP mode */
1015 is4op = (instr->key == OPL3_PATCH);
1016 else
1017 is4op = 0;
1018
1019 if (is4op)
1020 {
1021 first = p = 0;
1022 avail = 6;
1023 }
1024 else
1025 {
1026 if (devc->nr_voice == 12) /* 4 OP mode. Use the '2 OP only' operators first */
1027 first = p = 6;
1028 else
1029 first = p = 0;
1030 avail = devc->nr_voice;
1031 }
1032
1033 /*
1034 * Now try to find a free voice
1035 */
1036 best = first;
1037
1038 for (i = 0; i < avail; i++)
1039 {
1040 if (alloc->map[p] == 0)
1041 {
1042 return p;
1043 }
1044 if (alloc->alloc_times[p] < best_time) /* Find oldest playing note */
1045 {
1046 best_time = alloc->alloc_times[p];
1047 best = p;
1048 }
1049 p = (p + 1) % avail;
1050 }
1051
1052 /*
1053 * Insert some kind of priority mechanism here.
1054 */
1055
1056 if (best < 0)
1057 best = 0;
1058 if (best > devc->nr_voice)
1059 best -= devc->nr_voice;
1060
1061 return best; /* All devc->voc in use. Select the first one. */
1062}
1063
1064static void opl3_setup_voice(int dev, int voice, int chn)
1065{
1066 struct channel_info *info;
1067
1068 if (voice < 0 || voice >= devc->nr_voice)
1069 return;
1070
1071 if (chn < 0 || chn > 15)
1072 return;
1073
1074 info = &synth_devs[dev]->chn_info[chn];
1075
1076 opl3_set_instr(dev, voice, info->pgm_num);
1077
1078 devc->voc[voice].bender = 0;
1079 devc->voc[voice].bender_range = info->bender_range;
1080 devc->voc[voice].volume = info->controllers[CTL_MAIN_VOLUME];
1081 devc->voc[voice].panning = (info->controllers[CTL_PAN] * 2) - 128;
1082}
1083
1084static struct synth_operations opl3_operations =
1085{
1086 .owner = THIS_MODULE,
1087 .id = "OPL",
1088 .info = NULL,
1089 .midi_dev = 0,
1090 .synth_type = SYNTH_TYPE_FM,
1091 .synth_subtype = FM_TYPE_ADLIB,
1092 .open = opl3_open,
1093 .close = opl3_close,
1094 .ioctl = opl3_ioctl,
1095 .kill_note = opl3_kill_note,
1096 .start_note = opl3_start_note,
1097 .set_instr = opl3_set_instr,
1098 .reset = opl3_reset,
1099 .hw_control = opl3_hw_control,
1100 .load_patch = opl3_load_patch,
1101 .aftertouch = opl3_aftertouch,
1102 .controller = opl3_controller,
1103 .panning = opl3_panning,
1104 .volume_method = opl3_volume_method,
1105 .bender = opl3_bender,
1106 .alloc_voice = opl3_alloc_voice,
1107 .setup_voice = opl3_setup_voice
1108};
1109
1110static int opl3_init(int ioaddr, struct module *owner)
1111{
1112 int i;
1113 int me;
1114
1115 if (devc == NULL)
1116 {
1117 printk(KERN_ERR "opl3: Device control structure not initialized.\n");
1118 return -1;
1119 }
1120
1121 if ((me = sound_alloc_synthdev()) == -1)
1122 {
1123 printk(KERN_WARNING "opl3: Too many synthesizers\n");
1124 return -1;
1125 }
1126
1127 devc->nr_voice = 9;
1128
1129 devc->fm_info.device = 0;
1130 devc->fm_info.synth_type = SYNTH_TYPE_FM;
1131 devc->fm_info.synth_subtype = FM_TYPE_ADLIB;
1132 devc->fm_info.perc_mode = 0;
1133 devc->fm_info.nr_voices = 9;
1134 devc->fm_info.nr_drums = 0;
1135 devc->fm_info.instr_bank_size = SBFM_MAXINSTR;
1136 devc->fm_info.capabilities = 0;
1137 devc->left_io = ioaddr;
1138 devc->right_io = ioaddr + 2;
1139
1140 if (detected_model <= 2)
1141 devc->model = 1;
1142 else
1143 {
1144 devc->model = 2;
1145 if (detected_model == 4)
1146 devc->is_opl4 = 1;
1147 }
1148
1149 opl3_operations.info = &devc->fm_info;
1150
1151 synth_devs[me] = &opl3_operations;
1152
1153 if (owner)
1154 synth_devs[me]->owner = owner;
1155
1156 sequencer_init();
1157 devc->v_alloc = &opl3_operations.alloc;
1158 devc->chn_info = &opl3_operations.chn_info[0];
1159
1160 if (devc->model == 2)
1161 {
1162 if (devc->is_opl4)
1163 strcpy(devc->fm_info.name, "Yamaha OPL4/OPL3 FM");
1164 else
1165 strcpy(devc->fm_info.name, "Yamaha OPL3");
1166
1167 devc->v_alloc->max_voice = devc->nr_voice = 18;
1168 devc->fm_info.nr_drums = 0;
1169 devc->fm_info.synth_subtype = FM_TYPE_OPL3;
1170 devc->fm_info.capabilities |= SYNTH_CAP_OPL3;
1171
1172 for (i = 0; i < 18; i++)
1173 {
1174 if (pv_map[i].ioaddr == USE_LEFT)
1175 pv_map[i].ioaddr = devc->left_io;
1176 else
1177 pv_map[i].ioaddr = devc->right_io;
1178 }
1179 opl3_command(devc->right_io, OPL3_MODE_REGISTER, OPL3_ENABLE);
1180 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, 0x00);
1181 }
1182 else
1183 {
1184 strcpy(devc->fm_info.name, "Yamaha OPL2");
1185 devc->v_alloc->max_voice = devc->nr_voice = 9;
1186 devc->fm_info.nr_drums = 0;
1187
1188 for (i = 0; i < 18; i++)
1189 pv_map[i].ioaddr = devc->left_io;
1190 }
1191 conf_printf2(devc->fm_info.name, ioaddr, 0, -1, -1);
1192
1193 for (i = 0; i < SBFM_MAXINSTR; i++)
1194 devc->i_map[i].channel = -1;
1195
1196 return me;
1197}
1198
1199static int me;
1200
1201static int io = -1;
1202
1203module_param_hw(io, int, ioport, 0);
1204
1205static int __init init_opl3 (void)
1206{
1207 printk(KERN_INFO "YM3812 and OPL-3 driver Copyright (C) by Hannu Savolainen, Rob Hooft 1993-1996\n");
1208
1209 if (io != -1) /* User loading pure OPL3 module */
1210 {
1211 if (!opl3_detect(io))
1212 {
1213 return -ENODEV;
1214 }
1215
1216 me = opl3_init(io, THIS_MODULE);
1217 }
1218
1219 return 0;
1220}
1221
1222static void __exit cleanup_opl3(void)
1223{
1224 if (devc && io != -1)
1225 {
1226 if (devc->base) {
1227 release_region(devc->base,4);
1228 if (devc->is_opl4)
1229 release_region(devc->base - 8, 2);
1230 }
1231 kfree(devc);
1232 devc = NULL;
1233 sound_unload_synthdev(me);
1234 }
1235}
1236
1237module_init(init_opl3);
1238module_exit(cleanup_opl3);
1239
1240#ifndef MODULE
1241static int __init setup_opl3(char *str)
1242{
1243 /* io */
1244 int ints[2];
1245
1246 str = get_options(str, ARRAY_SIZE(ints), ints);
1247
1248 io = ints[1];
1249
1250 return 1;
1251}
1252
1253__setup("opl3=", setup_opl3);
1254#endif
1255MODULE_LICENSE("GPL");
diff --git a/sound/oss/opl3_hw.h b/sound/oss/opl3_hw.h
deleted file mode 100644
index 8b11c893e869..000000000000
--- a/sound/oss/opl3_hw.h
+++ /dev/null
@@ -1,246 +0,0 @@
1/*
2 * opl3_hw.h - Definitions of the OPL-3 registers
3 *
4 *
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 *
11 *
12 * The OPL-3 mode is switched on by writing 0x01, to the offset 5
13 * of the right side.
14 *
15 * Another special register at the right side is at offset 4. It contains
16 * a bit mask defining which voices are used as 4 OP voices.
17 *
18 * The percussive mode is implemented in the left side only.
19 *
20 * With the above exceptions the both sides can be operated independently.
21 *
22 * A 4 OP voice can be created by setting the corresponding
23 * bit at offset 4 of the right side.
24 *
25 * For example setting the rightmost bit (0x01) changes the
26 * first voice on the right side to the 4 OP mode. The fourth
27 * voice is made inaccessible.
28 *
29 * If a voice is set to the 2 OP mode, it works like 2 OP modes
30 * of the original YM3812 (AdLib). In addition the voice can
31 * be connected the left, right or both stereo channels. It can
32 * even be left unconnected. This works with 4 OP voices also.
33 *
34 * The stereo connection bits are located in the FEEDBACK_CONNECTION
35 * register of the voice (0xC0-0xC8). In 4 OP voices these bits are
36 * in the second half of the voice.
37 */
38
39/*
40 * Register numbers for the global registers
41 */
42
43#define TEST_REGISTER 0x01
44#define ENABLE_WAVE_SELECT 0x20
45
46#define TIMER1_REGISTER 0x02
47#define TIMER2_REGISTER 0x03
48#define TIMER_CONTROL_REGISTER 0x04 /* Left side */
49#define IRQ_RESET 0x80
50#define TIMER1_MASK 0x40
51#define TIMER2_MASK 0x20
52#define TIMER1_START 0x01
53#define TIMER2_START 0x02
54
55#define CONNECTION_SELECT_REGISTER 0x04 /* Right side */
56#define RIGHT_4OP_0 0x01
57#define RIGHT_4OP_1 0x02
58#define RIGHT_4OP_2 0x04
59#define LEFT_4OP_0 0x08
60#define LEFT_4OP_1 0x10
61#define LEFT_4OP_2 0x20
62
63#define OPL3_MODE_REGISTER 0x05 /* Right side */
64#define OPL3_ENABLE 0x01
65#define OPL4_ENABLE 0x02
66
67#define KBD_SPLIT_REGISTER 0x08 /* Left side */
68#define COMPOSITE_SINE_WAVE_MODE 0x80 /* Don't use with OPL-3? */
69#define KEYBOARD_SPLIT 0x40
70
71#define PERCOSSION_REGISTER 0xbd /* Left side only */
72#define TREMOLO_DEPTH 0x80
73#define VIBRATO_DEPTH 0x40
74#define PERCOSSION_ENABLE 0x20
75#define BASSDRUM_ON 0x10
76#define SNAREDRUM_ON 0x08
77#define TOMTOM_ON 0x04
78#define CYMBAL_ON 0x02
79#define HIHAT_ON 0x01
80
81/*
82 * Offsets to the register banks for operators. To get the
83 * register number just add the operator offset to the bank offset
84 *
85 * AM/VIB/EG/KSR/Multiple (0x20 to 0x35)
86 */
87#define AM_VIB 0x20
88#define TREMOLO_ON 0x80
89#define VIBRATO_ON 0x40
90#define SUSTAIN_ON 0x20
91#define KSR 0x10 /* Key scaling rate */
92#define MULTIPLE_MASK 0x0f /* Frequency multiplier */
93
94 /*
95 * KSL/Total level (0x40 to 0x55)
96 */
97#define KSL_LEVEL 0x40
98#define KSL_MASK 0xc0 /* Envelope scaling bits */
99#define TOTAL_LEVEL_MASK 0x3f /* Strength (volume) of OP */
100
101/*
102 * Attack / Decay rate (0x60 to 0x75)
103 */
104#define ATTACK_DECAY 0x60
105#define ATTACK_MASK 0xf0
106#define DECAY_MASK 0x0f
107
108/*
109 * Sustain level / Release rate (0x80 to 0x95)
110 */
111#define SUSTAIN_RELEASE 0x80
112#define SUSTAIN_MASK 0xf0
113#define RELEASE_MASK 0x0f
114
115/*
116 * Wave select (0xE0 to 0xF5)
117 */
118#define WAVE_SELECT 0xe0
119
120/*
121 * Offsets to the register banks for voices. Just add to the
122 * voice number to get the register number.
123 *
124 * F-Number low bits (0xA0 to 0xA8).
125 */
126#define FNUM_LOW 0xa0
127
128/*
129 * F-number high bits / Key on / Block (octave) (0xB0 to 0xB8)
130 */
131#define KEYON_BLOCK 0xb0
132#define KEYON_BIT 0x20
133#define BLOCKNUM_MASK 0x1c
134#define FNUM_HIGH_MASK 0x03
135
136/*
137 * Feedback / Connection (0xc0 to 0xc8)
138 *
139 * These registers have two new bits when the OPL-3 mode
140 * is selected. These bits controls connecting the voice
141 * to the stereo channels. For 4 OP voices this bit is
142 * defined in the second half of the voice (add 3 to the
143 * register offset).
144 *
145 * For 4 OP voices the connection bit is used in the
146 * both halves (gives 4 ways to connect the operators).
147 */
148#define FEEDBACK_CONNECTION 0xc0
149#define FEEDBACK_MASK 0x0e /* Valid just for 1st OP of a voice */
150#define CONNECTION_BIT 0x01
151/*
152 * In the 4 OP mode there is four possible configurations how the
153 * operators can be connected together (in 2 OP modes there is just
154 * AM or FM). The 4 OP connection mode is defined by the rightmost
155 * bit of the FEEDBACK_CONNECTION (0xC0-0xC8) on the both halves.
156 *
157 * First half Second half Mode
158 *
159 * +---+
160 * v |
161 * 0 0 >+-1-+--2--3--4-->
162 *
163 *
164 *
165 * +---+
166 * | |
167 * 0 1 >+-1-+--2-+
168 * |->
169 * >--3----4-+
170 *
171 * +---+
172 * | |
173 * 1 0 >+-1-+-----+
174 * |->
175 * >--2--3--4-+
176 *
177 * +---+
178 * | |
179 * 1 1 >+-1-+--+
180 * |
181 * >--2--3-+->
182 * |
183 * >--4----+
184 */
185#define STEREO_BITS 0x30 /* OPL-3 only */
186#define VOICE_TO_LEFT 0x10
187#define VOICE_TO_RIGHT 0x20
188
189/*
190 * Definition table for the physical voices
191 */
192
193struct physical_voice_info {
194 unsigned char voice_num;
195 unsigned char voice_mode; /* 0=unavailable, 2=2 OP, 4=4 OP */
196 unsigned short ioaddr; /* I/O port (left or right side) */
197 unsigned char op[4]; /* Operator offsets */
198 };
199
200/*
201 * There is 18 possible 2 OP voices
202 * (9 in the left and 9 in the right).
203 * The first OP is the modulator and 2nd is the carrier.
204 *
205 * The first three voices in the both sides may be connected
206 * with another voice to a 4 OP voice. For example voice 0
207 * can be connected with voice 3. The operators of voice 3 are
208 * used as operators 3 and 4 of the new 4 OP voice.
209 * In this case the 2 OP voice number 0 is the 'first half' and
210 * voice 3 is the second.
211 */
212
213#define USE_LEFT 0
214#define USE_RIGHT 1
215
216static struct physical_voice_info pv_map[18] =
217{
218/* No Mode Side OP1 OP2 OP3 OP4 */
219/* --------------------------------------------------- */
220 { 0, 2, USE_LEFT, {0x00, 0x03, 0x08, 0x0b}},
221 { 1, 2, USE_LEFT, {0x01, 0x04, 0x09, 0x0c}},
222 { 2, 2, USE_LEFT, {0x02, 0x05, 0x0a, 0x0d}},
223
224 { 3, 2, USE_LEFT, {0x08, 0x0b, 0x00, 0x00}},
225 { 4, 2, USE_LEFT, {0x09, 0x0c, 0x00, 0x00}},
226 { 5, 2, USE_LEFT, {0x0a, 0x0d, 0x00, 0x00}},
227
228 { 6, 2, USE_LEFT, {0x10, 0x13, 0x00, 0x00}}, /* Used by percussive voices */
229 { 7, 2, USE_LEFT, {0x11, 0x14, 0x00, 0x00}}, /* if the percussive mode */
230 { 8, 2, USE_LEFT, {0x12, 0x15, 0x00, 0x00}}, /* is selected */
231
232 { 0, 2, USE_RIGHT, {0x00, 0x03, 0x08, 0x0b}},
233 { 1, 2, USE_RIGHT, {0x01, 0x04, 0x09, 0x0c}},
234 { 2, 2, USE_RIGHT, {0x02, 0x05, 0x0a, 0x0d}},
235
236 { 3, 2, USE_RIGHT, {0x08, 0x0b, 0x00, 0x00}},
237 { 4, 2, USE_RIGHT, {0x09, 0x0c, 0x00, 0x00}},
238 { 5, 2, USE_RIGHT, {0x0a, 0x0d, 0x00, 0x00}},
239
240 { 6, 2, USE_RIGHT, {0x10, 0x13, 0x00, 0x00}},
241 { 7, 2, USE_RIGHT, {0x11, 0x14, 0x00, 0x00}},
242 { 8, 2, USE_RIGHT, {0x12, 0x15, 0x00, 0x00}}
243};
244/*
245 * DMA buffer calls
246 */
diff --git a/sound/oss/os.h b/sound/oss/os.h
deleted file mode 100644
index 0bf89e1d679c..000000000000
--- a/sound/oss/os.h
+++ /dev/null
@@ -1,45 +0,0 @@
1#define ALLOW_SELECT
2#undef NO_INLINE_ASM
3#define SHORT_BANNERS
4#define MANUAL_PNP
5#undef DO_TIMINGS
6
7#include <linux/module.h>
8
9#ifdef __KERNEL__
10#include <linux/string.h>
11#include <linux/fs.h>
12#include <asm/dma.h>
13#include <asm/io.h>
14#include <asm/param.h>
15#include <linux/sched.h>
16#include <linux/slab.h>
17#include <linux/ioport.h>
18#include <asm/page.h>
19#include <linux/vmalloc.h>
20#include <linux/uaccess.h>
21#include <linux/poll.h>
22#include <linux/pci.h>
23#endif
24
25#include <linux/soundcard.h>
26
27#define FALSE 0
28#define TRUE 1
29
30extern int sound_alloc_dma(int chn, char *deviceID);
31extern int sound_open_dma(int chn, char *deviceID);
32extern void sound_free_dma(int chn);
33extern void sound_close_dma(int chn);
34
35extern void reprogram_timer(void);
36
37#define USE_AUTOINIT_DMA
38
39extern void *sound_mem_blocks[1024];
40extern int sound_nblocks;
41
42#undef PSEUDO_DMA_AUTOINIT
43#define ALLOW_BUFFER_MAPPING
44
45extern const struct file_operations oss_sound_fops;
diff --git a/sound/oss/pas2.h b/sound/oss/pas2.h
deleted file mode 100644
index d19f757dbd79..000000000000
--- a/sound/oss/pas2.h
+++ /dev/null
@@ -1,20 +0,0 @@
1
2/* From pas_card.c */
3int pas_set_intr(int mask);
4int pas_remove_intr(int mask);
5unsigned char pas_read(int ioaddr);
6void pas_write(unsigned char data, int ioaddr);
7
8/* From pas_audio.c */
9void pas_pcm_interrupt(unsigned char status, int cause);
10void pas_pcm_init(struct address_info *hw_config);
11
12/* From pas_mixer.c */
13int pas_init_mixer(void);
14
15/* From pas_midi.c */
16void pas_midi_init(void);
17void pas_midi_interrupt(void);
18
19/* From pas2_mixer.c*/
20void mix_write(unsigned char data, int ioaddr);
diff --git a/sound/oss/pas2_card.c b/sound/oss/pas2_card.c
deleted file mode 100644
index 769fca692d2a..000000000000
--- a/sound/oss/pas2_card.c
+++ /dev/null
@@ -1,458 +0,0 @@
1/*
2 * sound/oss/pas2_card.c
3 *
4 * Detection routine for the Pro Audio Spectrum cards.
5 */
6
7#include <linux/init.h>
8#include <linux/interrupt.h>
9#include <linux/module.h>
10#include <linux/spinlock.h>
11#include "sound_config.h"
12
13#include "pas2.h"
14#include "sb.h"
15
16static unsigned char dma_bits[] = {
17 4, 1, 2, 3, 0, 5, 6, 7
18};
19
20static unsigned char irq_bits[] = {
21 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 7, 8, 9, 0, 10, 11
22};
23
24static unsigned char sb_irq_bits[] = {
25 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20,
26 0x00, 0x08, 0x28, 0x30, 0x38, 0, 0
27};
28
29static unsigned char sb_dma_bits[] = {
30 0x00, 0x40, 0x80, 0xC0, 0, 0, 0, 0
31};
32
33/*
34 * The Address Translation code is used to convert I/O register addresses to
35 * be relative to the given base -register
36 */
37
38int pas_translate_code = 0;
39static int pas_intr_mask;
40static int pas_irq;
41static int pas_sb_base;
42DEFINE_SPINLOCK(pas_lock);
43#ifndef CONFIG_PAS_JOYSTICK
44static bool joystick;
45#else
46static bool joystick = 1;
47#endif
48#ifdef SYMPHONY_PAS
49static bool symphony = 1;
50#else
51static bool symphony;
52#endif
53#ifdef BROKEN_BUS_CLOCK
54static bool broken_bus_clock = 1;
55#else
56static bool broken_bus_clock;
57#endif
58
59static struct address_info cfg;
60static struct address_info cfg2;
61
62char pas_model = 0;
63static char *pas_model_names[] = {
64 "",
65 "Pro AudioSpectrum+",
66 "CDPC",
67 "Pro AudioSpectrum 16",
68 "Pro AudioSpectrum 16D"
69};
70
71/*
72 * pas_read() and pas_write() are equivalents of inb and outb
73 * These routines perform the I/O address translation required
74 * to support other than the default base address
75 */
76
77unsigned char pas_read(int ioaddr)
78{
79 return inb(ioaddr + pas_translate_code);
80}
81
82void pas_write(unsigned char data, int ioaddr)
83{
84 outb((data), ioaddr + pas_translate_code);
85}
86
87/******************* Begin of the Interrupt Handler ********************/
88
89static irqreturn_t pasintr(int irq, void *dev_id)
90{
91 int status;
92
93 status = pas_read(0x0B89);
94 pas_write(status, 0x0B89); /* Clear interrupt */
95
96 if (status & 0x08)
97 {
98 pas_pcm_interrupt(status, 1);
99 status &= ~0x08;
100 }
101 if (status & 0x10)
102 {
103 pas_midi_interrupt();
104 status &= ~0x10;
105 }
106 return IRQ_HANDLED;
107}
108
109int pas_set_intr(int mask)
110{
111 if (!mask)
112 return 0;
113
114 pas_intr_mask |= mask;
115
116 pas_write(pas_intr_mask, 0x0B8B);
117 return 0;
118}
119
120int pas_remove_intr(int mask)
121{
122 if (!mask)
123 return 0;
124
125 pas_intr_mask &= ~mask;
126 pas_write(pas_intr_mask, 0x0B8B);
127
128 return 0;
129}
130
131/******************* End of the Interrupt handler **********************/
132
133/******************* Begin of the Initialization Code ******************/
134
135static int __init config_pas_hw(struct address_info *hw_config)
136{
137 char ok = 1;
138 unsigned int_ptrs; /* scsi/sound interrupt pointers */
139
140 pas_irq = hw_config->irq;
141
142 pas_write(0x00, 0x0B8B);
143 pas_write(0x36, 0x138B);
144 pas_write(0x36, 0x1388);
145 pas_write(0, 0x1388);
146 pas_write(0x74, 0x138B);
147 pas_write(0x74, 0x1389);
148 pas_write(0, 0x1389);
149
150 pas_write(0x80 | 0x40 | 0x20 | 1, 0x0B8A);
151 pas_write(0x80 | 0x20 | 0x10 | 0x08 | 0x01, 0xF8A);
152 pas_write(0x01 | 0x02 | 0x04 | 0x10 /*
153 * |
154 * 0x80
155 */ , 0xB88);
156
157 pas_write(0x80 | (joystick ? 0x40 : 0), 0xF388);
158
159 if (pas_irq < 0 || pas_irq > 15)
160 {
161 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
162 hw_config->irq=-1;
163 ok = 0;
164 }
165 else
166 {
167 int_ptrs = pas_read(0xF38A);
168 int_ptrs = (int_ptrs & 0xf0) | irq_bits[pas_irq];
169 pas_write(int_ptrs, 0xF38A);
170 if (!irq_bits[pas_irq])
171 {
172 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
173 hw_config->irq=-1;
174 ok = 0;
175 }
176 else
177 {
178 if (request_irq(pas_irq, pasintr, 0, "PAS16",hw_config) < 0) {
179 printk(KERN_ERR "PAS16: Cannot allocate IRQ %d\n",pas_irq);
180 hw_config->irq=-1;
181 ok = 0;
182 }
183 }
184 }
185
186 if (hw_config->dma < 0 || hw_config->dma > 7)
187 {
188 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
189 hw_config->dma=-1;
190 ok = 0;
191 }
192 else
193 {
194 pas_write(dma_bits[hw_config->dma], 0xF389);
195 if (!dma_bits[hw_config->dma])
196 {
197 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
198 hw_config->dma=-1;
199 ok = 0;
200 }
201 else
202 {
203 if (sound_alloc_dma(hw_config->dma, "PAS16"))
204 {
205 printk(KERN_ERR "pas2_card.c: Can't allocate DMA channel\n");
206 hw_config->dma=-1;
207 ok = 0;
208 }
209 }
210 }
211
212 /*
213 * This fixes the timing problems of the PAS due to the Symphony chipset
214 * as per Media Vision. Only define this if your PAS doesn't work correctly.
215 */
216
217 if(symphony)
218 {
219 outb((0x05), 0xa8);
220 outb((0x60), 0xa9);
221 }
222
223 if(broken_bus_clock)
224 pas_write(0x01 | 0x10 | 0x20 | 0x04, 0x8388);
225 else
226 /*
227 * pas_write(0x01, 0x8388);
228 */
229 pas_write(0x01 | 0x10 | 0x20, 0x8388);
230
231 pas_write(0x18, 0x838A); /* ??? */
232 pas_write(0x20 | 0x01, 0x0B8A); /* Mute off, filter = 17.897 kHz */
233 pas_write(8, 0xBF8A);
234
235 mix_write(0x80 | 5, 0x078B);
236 mix_write(5, 0x078B);
237
238 {
239 struct address_info *sb_config;
240
241 sb_config = &cfg2;
242 if (sb_config->io_base)
243 {
244 unsigned char irq_dma;
245
246 /*
247 * Turn on Sound Blaster compatibility
248 * bit 1 = SB emulation
249 * bit 0 = MPU401 emulation (CDPC only :-( )
250 */
251
252 pas_write(0x02, 0xF788);
253
254 /*
255 * "Emulation address"
256 */
257
258 pas_write((sb_config->io_base >> 4) & 0x0f, 0xF789);
259 pas_sb_base = sb_config->io_base;
260
261 if (!sb_dma_bits[sb_config->dma])
262 printk(KERN_ERR "PAS16 Warning: Invalid SB DMA %d\n\n", sb_config->dma);
263
264 if (!sb_irq_bits[sb_config->irq])
265 printk(KERN_ERR "PAS16 Warning: Invalid SB IRQ %d\n\n", sb_config->irq);
266
267 irq_dma = sb_dma_bits[sb_config->dma] |
268 sb_irq_bits[sb_config->irq];
269
270 pas_write(irq_dma, 0xFB8A);
271 }
272 else
273 pas_write(0x00, 0xF788);
274 }
275
276 if (!ok)
277 printk(KERN_WARNING "PAS16: Driver not enabled\n");
278
279 return ok;
280}
281
282static int __init detect_pas_hw(struct address_info *hw_config)
283{
284 unsigned char board_id, foo;
285
286 /*
287 * WARNING: Setting an option like W:1 or so that disables warm boot reset
288 * of the card will screw up this detect code something fierce. Adding code
289 * to handle this means possibly interfering with other cards on the bus if
290 * you have something on base port 0x388. SO be forewarned.
291 */
292
293 outb((0xBC), 0x9A01); /* Activate first board */
294 outb((hw_config->io_base >> 2), 0x9A01); /* Set base address */
295 pas_translate_code = hw_config->io_base - 0x388;
296 pas_write(1, 0xBF88); /* Select one wait states */
297
298 board_id = pas_read(0x0B8B);
299
300 if (board_id == 0xff)
301 return 0;
302
303 /*
304 * We probably have a PAS-series board, now check for a PAS16-series board
305 * by trying to change the board revision bits. PAS16-series hardware won't
306 * let you do this - the bits are read-only.
307 */
308
309 foo = board_id ^ 0xe0;
310
311 pas_write(foo, 0x0B8B);
312 foo = pas_read(0x0B8B);
313 pas_write(board_id, 0x0B8B);
314
315 if (board_id != foo)
316 return 0;
317
318 pas_model = pas_read(0xFF88);
319
320 return pas_model;
321}
322
323static void __init attach_pas_card(struct address_info *hw_config)
324{
325 pas_irq = hw_config->irq;
326
327 if (detect_pas_hw(hw_config))
328 {
329
330 if ((pas_model = pas_read(0xFF88)))
331 {
332 char temp[100];
333
334 if (pas_model < 0 ||
335 pas_model >= ARRAY_SIZE(pas_model_names)) {
336 printk(KERN_ERR "pas2 unrecognized model.\n");
337 return;
338 }
339 sprintf(temp,
340 "%s rev %d", pas_model_names[(int) pas_model],
341 pas_read(0x2789));
342 conf_printf(temp, hw_config);
343 }
344 if (config_pas_hw(hw_config))
345 {
346 pas_pcm_init(hw_config);
347 pas_midi_init();
348 pas_init_mixer();
349 }
350 }
351}
352
353static inline int __init probe_pas(struct address_info *hw_config)
354{
355 return detect_pas_hw(hw_config);
356}
357
358static void __exit unload_pas(struct address_info *hw_config)
359{
360 extern int pas_audiodev;
361 extern int pas2_mididev;
362
363 if (hw_config->dma>0)
364 sound_free_dma(hw_config->dma);
365 if (hw_config->irq>0)
366 free_irq(hw_config->irq, hw_config);
367
368 if(pas_audiodev!=-1)
369 sound_unload_mixerdev(audio_devs[pas_audiodev]->mixer_dev);
370 if(pas2_mididev!=-1)
371 sound_unload_mididev(pas2_mididev);
372 if(pas_audiodev!=-1)
373 sound_unload_audiodev(pas_audiodev);
374}
375
376static int __initdata io = -1;
377static int __initdata irq = -1;
378static int __initdata dma = -1;
379static int __initdata dma16 = -1; /* Set this for modules that need it */
380
381static int __initdata sb_io = 0;
382static int __initdata sb_irq = -1;
383static int __initdata sb_dma = -1;
384static int __initdata sb_dma16 = -1;
385
386module_param_hw(io, int, ioport, 0);
387module_param_hw(irq, int, irq, 0);
388module_param_hw(dma, int, dma, 0);
389module_param_hw(dma16, int, dma, 0);
390
391module_param_hw(sb_io, int, ioport, 0);
392module_param_hw(sb_irq, int, irq, 0);
393module_param_hw(sb_dma, int, dma, 0);
394module_param_hw(sb_dma16, int, dma, 0);
395
396module_param(joystick, bool, 0);
397module_param(symphony, bool, 0);
398module_param(broken_bus_clock, bool, 0);
399
400MODULE_LICENSE("GPL");
401
402static int __init init_pas2(void)
403{
404 printk(KERN_INFO "Pro Audio Spectrum driver Copyright (C) by Hannu Savolainen 1993-1996\n");
405
406 cfg.io_base = io;
407 cfg.irq = irq;
408 cfg.dma = dma;
409 cfg.dma2 = dma16;
410
411 cfg2.io_base = sb_io;
412 cfg2.irq = sb_irq;
413 cfg2.dma = sb_dma;
414 cfg2.dma2 = sb_dma16;
415
416 if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
417 printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
418 return -EINVAL;
419 }
420
421 if (!probe_pas(&cfg))
422 return -ENODEV;
423 attach_pas_card(&cfg);
424
425 return 0;
426}
427
428static void __exit cleanup_pas2(void)
429{
430 unload_pas(&cfg);
431}
432
433module_init(init_pas2);
434module_exit(cleanup_pas2);
435
436#ifndef MODULE
437static int __init setup_pas2(char *str)
438{
439 /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, sb_dma2 */
440 int ints[9];
441
442 str = get_options(str, ARRAY_SIZE(ints), ints);
443
444 io = ints[1];
445 irq = ints[2];
446 dma = ints[3];
447 dma16 = ints[4];
448
449 sb_io = ints[5];
450 sb_irq = ints[6];
451 sb_dma = ints[7];
452 sb_dma16 = ints[8];
453
454 return 1;
455}
456
457__setup("pas2=", setup_pas2);
458#endif
diff --git a/sound/oss/pas2_midi.c b/sound/oss/pas2_midi.c
deleted file mode 100644
index 1122d10a20c3..000000000000
--- a/sound/oss/pas2_midi.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/*
2 * sound/oss/pas2_midi.c
3 *
4 * The low level driver for the PAS Midi Interface.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 * Bartlomiej Zolnierkiewicz : Added __init to pas_init_mixer()
14 */
15
16#include <linux/init.h>
17#include <linux/spinlock.h>
18#include "sound_config.h"
19
20#include "pas2.h"
21
22extern spinlock_t pas_lock;
23
24static int midi_busy, input_opened;
25static int my_dev;
26
27int pas2_mididev=-1;
28
29static unsigned char tmp_queue[256];
30static volatile int qlen;
31static volatile unsigned char qhead, qtail;
32
33static void (*midi_input_intr) (int dev, unsigned char data);
34
35static int pas_midi_open(int dev, int mode,
36 void (*input) (int dev, unsigned char data),
37 void (*output) (int dev)
38)
39{
40 int err;
41 unsigned long flags;
42 unsigned char ctrl;
43
44
45 if (midi_busy)
46 return -EBUSY;
47
48 /*
49 * Reset input and output FIFO pointers
50 */
51 pas_write(0x20 | 0x40,
52 0x178b);
53
54 spin_lock_irqsave(&pas_lock, flags);
55
56 if ((err = pas_set_intr(0x10)) < 0)
57 {
58 spin_unlock_irqrestore(&pas_lock, flags);
59 return err;
60 }
61 /*
62 * Enable input available and output FIFO empty interrupts
63 */
64
65 ctrl = 0;
66 input_opened = 0;
67 midi_input_intr = input;
68
69 if (mode == OPEN_READ || mode == OPEN_READWRITE)
70 {
71 ctrl |= 0x04; /* Enable input */
72 input_opened = 1;
73 }
74 if (mode == OPEN_WRITE || mode == OPEN_READWRITE)
75 {
76 ctrl |= 0x08 | 0x10; /* Enable output */
77 }
78 pas_write(ctrl, 0x178b);
79
80 /*
81 * Acknowledge any pending interrupts
82 */
83
84 pas_write(0xff, 0x1B88);
85
86 spin_unlock_irqrestore(&pas_lock, flags);
87
88 midi_busy = 1;
89 qlen = qhead = qtail = 0;
90 return 0;
91}
92
93static void pas_midi_close(int dev)
94{
95
96 /*
97 * Reset FIFO pointers, disable intrs
98 */
99 pas_write(0x20 | 0x40, 0x178b);
100
101 pas_remove_intr(0x10);
102 midi_busy = 0;
103}
104
105static int dump_to_midi(unsigned char midi_byte)
106{
107 int fifo_space, x;
108
109 fifo_space = ((x = pas_read(0x1B89)) >> 4) & 0x0f;
110
111 /*
112 * The MIDI FIFO space register and it's documentation is nonunderstandable.
113 * There seem to be no way to differentiate between buffer full and buffer
114 * empty situations. For this reason we don't never write the buffer
115 * completely full. In this way we can assume that 0 (or is it 15)
116 * means that the buffer is empty.
117 */
118
119 if (fifo_space < 2 && fifo_space != 0) /* Full (almost) */
120 return 0; /* Ask upper layers to retry after some time */
121
122 pas_write(midi_byte, 0x178A);
123
124 return 1;
125}
126
127static int pas_midi_out(int dev, unsigned char midi_byte)
128{
129
130 unsigned long flags;
131
132 /*
133 * Drain the local queue first
134 */
135
136 spin_lock_irqsave(&pas_lock, flags);
137
138 while (qlen && dump_to_midi(tmp_queue[qhead]))
139 {
140 qlen--;
141 qhead++;
142 }
143
144 spin_unlock_irqrestore(&pas_lock, flags);
145
146 /*
147 * Output the byte if the local queue is empty.
148 */
149
150 if (!qlen)
151 if (dump_to_midi(midi_byte))
152 return 1;
153
154 /*
155 * Put to the local queue
156 */
157
158 if (qlen >= 256)
159 return 0; /* Local queue full */
160
161 spin_lock_irqsave(&pas_lock, flags);
162
163 tmp_queue[qtail] = midi_byte;
164 qlen++;
165 qtail++;
166
167 spin_unlock_irqrestore(&pas_lock, flags);
168
169 return 1;
170}
171
172static int pas_midi_start_read(int dev)
173{
174 return 0;
175}
176
177static int pas_midi_end_read(int dev)
178{
179 return 0;
180}
181
182static void pas_midi_kick(int dev)
183{
184}
185
186static int pas_buffer_status(int dev)
187{
188 return qlen;
189}
190
191#define MIDI_SYNTH_NAME "Pro Audio Spectrum Midi"
192#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
193#include "midi_synth.h"
194
195static struct midi_operations pas_midi_operations =
196{
197 .owner = THIS_MODULE,
198 .info = {"Pro Audio Spectrum", 0, 0, SNDCARD_PAS},
199 .converter = &std_midi_synth,
200 .in_info = {0},
201 .open = pas_midi_open,
202 .close = pas_midi_close,
203 .outputc = pas_midi_out,
204 .start_read = pas_midi_start_read,
205 .end_read = pas_midi_end_read,
206 .kick = pas_midi_kick,
207 .buffer_status = pas_buffer_status,
208};
209
210void __init pas_midi_init(void)
211{
212 int dev = sound_alloc_mididev();
213
214 if (dev == -1)
215 {
216 printk(KERN_WARNING "pas_midi_init: Too many midi devices detected\n");
217 return;
218 }
219 std_midi_synth.midi_dev = my_dev = dev;
220 midi_devs[dev] = &pas_midi_operations;
221 pas2_mididev = dev;
222 sequencer_init();
223}
224
225void pas_midi_interrupt(void)
226{
227 unsigned char stat;
228 int i, incount;
229
230 stat = pas_read(0x1B88);
231
232 if (stat & 0x04) /* Input data available */
233 {
234 incount = pas_read(0x1B89) & 0x0f; /* Input FIFO size */
235 if (!incount)
236 incount = 16;
237
238 for (i = 0; i < incount; i++)
239 if (input_opened)
240 {
241 midi_input_intr(my_dev, pas_read(0x178A));
242 } else
243 pas_read(0x178A); /* Flush */
244 }
245 if (stat & (0x08 | 0x10))
246 {
247 spin_lock(&pas_lock);/* called in irq context */
248
249 while (qlen && dump_to_midi(tmp_queue[qhead]))
250 {
251 qlen--;
252 qhead++;
253 }
254
255 spin_unlock(&pas_lock);
256 }
257 if (stat & 0x40)
258 {
259 printk(KERN_WARNING "MIDI output overrun %x,%x\n", pas_read(0x1B89), stat);
260 }
261 pas_write(stat, 0x1B88); /* Acknowledge interrupts */
262}
diff --git a/sound/oss/pas2_mixer.c b/sound/oss/pas2_mixer.c
deleted file mode 100644
index 50b5bd501247..000000000000
--- a/sound/oss/pas2_mixer.c
+++ /dev/null
@@ -1,327 +0,0 @@
1
2/*
3 * sound/oss/pas2_mixer.c
4 *
5 * Mixer routines for the Pro Audio Spectrum cards.
6 */
7
8/*
9 * Copyright (C) by Hannu Savolainen 1993-1997
10 *
11 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
12 * Version 2 (June 1991). See the "COPYING" file distributed with this software
13 * for more info.
14 */
15/*
16 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
17 * Bartlomiej Zolnierkiewicz : added __init to pas_init_mixer()
18 */
19#include <linux/init.h>
20#include "sound_config.h"
21
22#include "pas2.h"
23
24extern int pas_translate_code;
25extern char pas_model;
26extern int *pas_osp;
27extern int pas_audiodev;
28
29static int rec_devices = (SOUND_MASK_MIC); /* Default recording source */
30static int mode_control;
31
32#define POSSIBLE_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
33 SOUND_MASK_CD | SOUND_MASK_ALTPCM)
34
35#define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
36 SOUND_MASK_CD | SOUND_MASK_ALTPCM | SOUND_MASK_IMIX | \
37 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_RECLEV)
38
39static int *levels;
40
41static int default_levels[32] =
42{
43 0x3232, /* Master Volume */
44 0x3232, /* Bass */
45 0x3232, /* Treble */
46 0x5050, /* FM */
47 0x4b4b, /* PCM */
48 0x3232, /* PC Speaker */
49 0x4b4b, /* Ext Line */
50 0x4b4b, /* Mic */
51 0x4b4b, /* CD */
52 0x6464, /* Recording monitor */
53 0x4b4b, /* SB PCM */
54 0x6464 /* Recording level */
55};
56
57void
58mix_write(unsigned char data, int ioaddr)
59{
60 /*
61 * The Revision D cards have a problem with their MVA508 interface. The
62 * kludge-o-rama fix is to make a 16-bit quantity with identical LSB and
63 * MSBs out of the output byte and to do a 16-bit out to the mixer port -
64 * 1. We need to do this because it isn't timing problem but chip access
65 * sequence problem.
66 */
67
68 if (pas_model == 4)
69 {
70 outw(data | (data << 8), (ioaddr + pas_translate_code) - 1);
71 outb((0x80), 0);
72 } else
73 pas_write(data, ioaddr);
74}
75
76static int
77mixer_output(int right_vol, int left_vol, int div, int bits,
78 int mixer) /* Input or output mixer */
79{
80 int left = left_vol * div / 100;
81 int right = right_vol * div / 100;
82
83
84 if (bits & 0x10)
85 {
86 left |= mixer;
87 right |= mixer;
88 }
89 if (bits == 0x03 || bits == 0x04)
90 {
91 mix_write(0x80 | bits, 0x078B);
92 mix_write(left, 0x078B);
93 right_vol = left_vol;
94 } else
95 {
96 mix_write(0x80 | 0x20 | bits, 0x078B);
97 mix_write(left, 0x078B);
98 mix_write(0x80 | 0x40 | bits, 0x078B);
99 mix_write(right, 0x078B);
100 }
101
102 return (left_vol | (right_vol << 8));
103}
104
105static void
106set_mode(int new_mode)
107{
108 mix_write(0x80 | 0x05, 0x078B);
109 mix_write(new_mode, 0x078B);
110
111 mode_control = new_mode;
112}
113
114static int
115pas_mixer_set(int whichDev, unsigned int level)
116{
117 int left, right, devmask, changed, i, mixer = 0;
118
119 left = level & 0x7f;
120 right = (level & 0x7f00) >> 8;
121
122 if (whichDev < SOUND_MIXER_NRDEVICES) {
123 if ((1 << whichDev) & rec_devices)
124 mixer = 0x20;
125 else
126 mixer = 0x00;
127 }
128
129 switch (whichDev)
130 {
131 case SOUND_MIXER_VOLUME: /* Master volume (0-63) */
132 levels[whichDev] = mixer_output(right, left, 63, 0x01, 0);
133 break;
134
135 /*
136 * Note! Bass and Treble are mono devices. Will use just the left
137 * channel.
138 */
139 case SOUND_MIXER_BASS: /* Bass (0-12) */
140 levels[whichDev] = mixer_output(right, left, 12, 0x03, 0);
141 break;
142 case SOUND_MIXER_TREBLE: /* Treble (0-12) */
143 levels[whichDev] = mixer_output(right, left, 12, 0x04, 0);
144 break;
145
146 case SOUND_MIXER_SYNTH: /* Internal synthesizer (0-31) */
147 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x00, mixer);
148 break;
149 case SOUND_MIXER_PCM: /* PAS PCM (0-31) */
150 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x05, mixer);
151 break;
152 case SOUND_MIXER_ALTPCM: /* SB PCM (0-31) */
153 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x07, mixer);
154 break;
155 case SOUND_MIXER_SPEAKER: /* PC speaker (0-31) */
156 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x06, mixer);
157 break;
158 case SOUND_MIXER_LINE: /* External line (0-31) */
159 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x02, mixer);
160 break;
161 case SOUND_MIXER_CD: /* CD (0-31) */
162 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x03, mixer);
163 break;
164 case SOUND_MIXER_MIC: /* External microphone (0-31) */
165 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x04, mixer);
166 break;
167 case SOUND_MIXER_IMIX: /* Recording monitor (0-31) (Output mixer only) */
168 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x01,
169 0x00);
170 break;
171 case SOUND_MIXER_RECLEV: /* Recording level (0-15) */
172 levels[whichDev] = mixer_output(right, left, 15, 0x02, 0);
173 break;
174
175
176 case SOUND_MIXER_RECSRC:
177 devmask = level & POSSIBLE_RECORDING_DEVICES;
178
179 changed = devmask ^ rec_devices;
180 rec_devices = devmask;
181
182 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
183 if (changed & (1 << i))
184 {
185 pas_mixer_set(i, levels[i]);
186 }
187 return rec_devices;
188 break;
189
190 default:
191 return -EINVAL;
192 }
193
194 return (levels[whichDev]);
195}
196
197/*****/
198
199static void
200pas_mixer_reset(void)
201{
202 int foo;
203
204 for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++)
205 pas_mixer_set(foo, levels[foo]);
206
207 set_mode(0x04 | 0x01);
208}
209
210static int pas_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
211{
212 int level,v ;
213 int __user *p = (int __user *)arg;
214
215 if (cmd == SOUND_MIXER_PRIVATE1) { /* Set loudness bit */
216 if (get_user(level, p))
217 return -EFAULT;
218 if (level == -1) /* Return current settings */
219 level = (mode_control & 0x04);
220 else {
221 mode_control &= ~0x04;
222 if (level)
223 mode_control |= 0x04;
224 set_mode(mode_control);
225 }
226 level = !!level;
227 return put_user(level, p);
228 }
229 if (cmd == SOUND_MIXER_PRIVATE2) { /* Set enhance bit */
230 if (get_user(level, p))
231 return -EFAULT;
232 if (level == -1) { /* Return current settings */
233 if (!(mode_control & 0x03))
234 level = 0;
235 else
236 level = ((mode_control & 0x03) + 1) * 20;
237 } else {
238 int i = 0;
239
240 level &= 0x7f;
241 if (level)
242 i = (level / 20) - 1;
243 mode_control &= ~0x03;
244 mode_control |= i & 0x03;
245 set_mode(mode_control);
246 if (i)
247 i = (i + 1) * 20;
248 level = i;
249 }
250 return put_user(level, p);
251 }
252 if (cmd == SOUND_MIXER_PRIVATE3) { /* Set mute bit */
253 if (get_user(level, p))
254 return -EFAULT;
255 if (level == -1) /* Return current settings */
256 level = !(pas_read(0x0B8A) & 0x20);
257 else {
258 if (level)
259 pas_write(pas_read(0x0B8A) & (~0x20), 0x0B8A);
260 else
261 pas_write(pas_read(0x0B8A) | 0x20, 0x0B8A);
262
263 level = !(pas_read(0x0B8A) & 0x20);
264 }
265 return put_user(level, p);
266 }
267 if (((cmd >> 8) & 0xff) == 'M') {
268 if (get_user(v, p))
269 return -EFAULT;
270 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
271 v = pas_mixer_set(cmd & 0xff, v);
272 } else {
273 switch (cmd & 0xff) {
274 case SOUND_MIXER_RECSRC:
275 v = rec_devices;
276 break;
277
278 case SOUND_MIXER_STEREODEVS:
279 v = SUPPORTED_MIXER_DEVICES & ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE);
280 break;
281
282 case SOUND_MIXER_DEVMASK:
283 v = SUPPORTED_MIXER_DEVICES;
284 break;
285
286 case SOUND_MIXER_RECMASK:
287 v = POSSIBLE_RECORDING_DEVICES & SUPPORTED_MIXER_DEVICES;
288 break;
289
290 case SOUND_MIXER_CAPS:
291 v = 0; /* No special capabilities */
292 break;
293
294 default:
295 v = levels[cmd & 0xff];
296 break;
297 }
298 }
299 return put_user(v, p);
300 }
301 return -EINVAL;
302}
303
304static struct mixer_operations pas_mixer_operations =
305{
306 .owner = THIS_MODULE,
307 .id = "PAS16",
308 .name = "Pro Audio Spectrum 16",
309 .ioctl = pas_mixer_ioctl
310};
311
312int __init
313pas_init_mixer(void)
314{
315 int d;
316
317 levels = load_mixer_volumes("PAS16_1", default_levels, 1);
318
319 pas_mixer_reset();
320
321 if ((d = sound_alloc_mixerdev()) != -1)
322 {
323 audio_devs[pas_audiodev]->mixer_dev = d;
324 mixer_devs[d] = &pas_mixer_operations;
325 }
326 return 1;
327}
diff --git a/sound/oss/pas2_pcm.c b/sound/oss/pas2_pcm.c
deleted file mode 100644
index 474803b52f7d..000000000000
--- a/sound/oss/pas2_pcm.c
+++ /dev/null
@@ -1,419 +0,0 @@
1/*
2 * pas2_pcm.c Audio routines for PAS16
3 *
4 *
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 *
11 *
12 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
13 * Alan Cox : Swatted a double allocation of device bug. Made a few
14 * more things module options.
15 * Bartlomiej Zolnierkiewicz : Added __init to pas_pcm_init()
16 */
17
18#include <linux/init.h>
19#include <linux/spinlock.h>
20#include <linux/timex.h>
21#include "sound_config.h"
22
23#include "pas2.h"
24
25#define PAS_PCM_INTRBITS (0x08)
26/*
27 * Sample buffer timer interrupt enable
28 */
29
30#define PCM_NON 0
31#define PCM_DAC 1
32#define PCM_ADC 2
33
34static unsigned long pcm_speed; /* sampling rate */
35static unsigned char pcm_channels = 1; /* channels (1 or 2) */
36static unsigned char pcm_bits = 8; /* bits/sample (8 or 16) */
37static unsigned char pcm_filter; /* filter FLAG */
38static unsigned char pcm_mode = PCM_NON;
39static unsigned long pcm_count;
40static unsigned short pcm_bitsok = 8; /* mask of OK bits */
41static int pcm_busy;
42int pas_audiodev = -1;
43static int open_mode;
44
45extern spinlock_t pas_lock;
46
47static int pcm_set_speed(int arg)
48{
49 int foo, tmp;
50 unsigned long flags;
51
52 if (arg == 0)
53 return pcm_speed;
54
55 if (arg > 44100)
56 arg = 44100;
57 if (arg < 5000)
58 arg = 5000;
59
60 if (pcm_channels & 2)
61 {
62 foo = ((PIT_TICK_RATE / 2) + (arg / 2)) / arg;
63 arg = ((PIT_TICK_RATE / 2) + (foo / 2)) / foo;
64 }
65 else
66 {
67 foo = (PIT_TICK_RATE + (arg / 2)) / arg;
68 arg = (PIT_TICK_RATE + (foo / 2)) / foo;
69 }
70
71 pcm_speed = arg;
72
73 tmp = pas_read(0x0B8A);
74
75 /*
76 * Set anti-aliasing filters according to sample rate. You really *NEED*
77 * to enable this feature for all normal recording unless you want to
78 * experiment with aliasing effects.
79 * These filters apply to the selected "recording" source.
80 * I (pfw) don't know the encoding of these 5 bits. The values shown
81 * come from the SDK found on ftp.uwp.edu:/pub/msdos/proaudio/.
82 *
83 * I cleared bit 5 of these values, since that bit controls the master
84 * mute flag. (Olav Wölfelschneider)
85 *
86 */
87#if !defined NO_AUTO_FILTER_SET
88 tmp &= 0xe0;
89 if (pcm_speed >= 2 * 17897)
90 tmp |= 0x01;
91 else if (pcm_speed >= 2 * 15909)
92 tmp |= 0x02;
93 else if (pcm_speed >= 2 * 11931)
94 tmp |= 0x09;
95 else if (pcm_speed >= 2 * 8948)
96 tmp |= 0x11;
97 else if (pcm_speed >= 2 * 5965)
98 tmp |= 0x19;
99 else if (pcm_speed >= 2 * 2982)
100 tmp |= 0x04;
101 pcm_filter = tmp;
102#endif
103
104 spin_lock_irqsave(&pas_lock, flags);
105
106 pas_write(tmp & ~(0x40 | 0x80), 0x0B8A);
107 pas_write(0x00 | 0x30 | 0x04, 0x138B);
108 pas_write(foo & 0xff, 0x1388);
109 pas_write((foo >> 8) & 0xff, 0x1388);
110 pas_write(tmp, 0x0B8A);
111
112 spin_unlock_irqrestore(&pas_lock, flags);
113
114 return pcm_speed;
115}
116
117static int pcm_set_channels(int arg)
118{
119
120 if ((arg != 1) && (arg != 2))
121 return pcm_channels;
122
123 if (arg != pcm_channels)
124 {
125 pas_write(pas_read(0xF8A) ^ 0x20, 0xF8A);
126
127 pcm_channels = arg;
128 pcm_set_speed(pcm_speed); /* The speed must be reinitialized */
129 }
130 return pcm_channels;
131}
132
133static int pcm_set_bits(int arg)
134{
135 if (arg == 0)
136 return pcm_bits;
137
138 if ((arg & pcm_bitsok) != arg)
139 return pcm_bits;
140
141 if (arg != pcm_bits)
142 {
143 pas_write(pas_read(0x8389) ^ 0x04, 0x8389);
144
145 pcm_bits = arg;
146 }
147 return pcm_bits;
148}
149
150static int pas_audio_ioctl(int dev, unsigned int cmd, void __user *arg)
151{
152 int val, ret;
153 int __user *p = arg;
154
155 switch (cmd)
156 {
157 case SOUND_PCM_WRITE_RATE:
158 if (get_user(val, p))
159 return -EFAULT;
160 ret = pcm_set_speed(val);
161 break;
162
163 case SOUND_PCM_READ_RATE:
164 ret = pcm_speed;
165 break;
166
167 case SNDCTL_DSP_STEREO:
168 if (get_user(val, p))
169 return -EFAULT;
170 ret = pcm_set_channels(val + 1) - 1;
171 break;
172
173 case SOUND_PCM_WRITE_CHANNELS:
174 if (get_user(val, p))
175 return -EFAULT;
176 ret = pcm_set_channels(val);
177 break;
178
179 case SOUND_PCM_READ_CHANNELS:
180 ret = pcm_channels;
181 break;
182
183 case SNDCTL_DSP_SETFMT:
184 if (get_user(val, p))
185 return -EFAULT;
186 ret = pcm_set_bits(val);
187 break;
188
189 case SOUND_PCM_READ_BITS:
190 ret = pcm_bits;
191 break;
192
193 default:
194 return -EINVAL;
195 }
196 return put_user(ret, p);
197}
198
199static void pas_audio_reset(int dev)
200{
201 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A); /* Disable PCM */
202}
203
204static int pas_audio_open(int dev, int mode)
205{
206 int err;
207 unsigned long flags;
208
209 spin_lock_irqsave(&pas_lock, flags);
210 if (pcm_busy)
211 {
212 spin_unlock_irqrestore(&pas_lock, flags);
213 return -EBUSY;
214 }
215 pcm_busy = 1;
216 spin_unlock_irqrestore(&pas_lock, flags);
217
218 if ((err = pas_set_intr(PAS_PCM_INTRBITS)) < 0)
219 return err;
220
221
222 pcm_count = 0;
223 open_mode = mode;
224
225 return 0;
226}
227
228static void pas_audio_close(int dev)
229{
230 unsigned long flags;
231
232 spin_lock_irqsave(&pas_lock, flags);
233
234 pas_audio_reset(dev);
235 pas_remove_intr(PAS_PCM_INTRBITS);
236 pcm_mode = PCM_NON;
237
238 pcm_busy = 0;
239 spin_unlock_irqrestore(&pas_lock, flags);
240}
241
242static void pas_audio_output_block(int dev, unsigned long buf, int count,
243 int intrflag)
244{
245 unsigned long flags, cnt;
246
247 cnt = count;
248 if (audio_devs[dev]->dmap_out->dma > 3)
249 cnt >>= 1;
250
251 if (audio_devs[dev]->flags & DMA_AUTOMODE &&
252 intrflag &&
253 cnt == pcm_count)
254 return;
255
256 spin_lock_irqsave(&pas_lock, flags);
257
258 pas_write(pas_read(0xF8A) & ~0x40,
259 0xF8A);
260
261 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
262
263 if (audio_devs[dev]->dmap_out->dma > 3)
264 count >>= 1;
265
266 if (count != pcm_count)
267 {
268 pas_write(pas_read(0x0B8A) & ~0x80, 0x0B8A);
269 pas_write(0x40 | 0x30 | 0x04, 0x138B);
270 pas_write(count & 0xff, 0x1389);
271 pas_write((count >> 8) & 0xff, 0x1389);
272 pas_write(pas_read(0x0B8A) | 0x80, 0x0B8A);
273
274 pcm_count = count;
275 }
276 pas_write(pas_read(0x0B8A) | 0x80 | 0x40, 0x0B8A);
277#ifdef NO_TRIGGER
278 pas_write(pas_read(0xF8A) | 0x40 | 0x10, 0xF8A);
279#endif
280
281 pcm_mode = PCM_DAC;
282
283 spin_unlock_irqrestore(&pas_lock, flags);
284}
285
286static void pas_audio_start_input(int dev, unsigned long buf, int count,
287 int intrflag)
288{
289 unsigned long flags;
290 int cnt;
291
292 cnt = count;
293 if (audio_devs[dev]->dmap_out->dma > 3)
294 cnt >>= 1;
295
296 if (audio_devs[pas_audiodev]->flags & DMA_AUTOMODE &&
297 intrflag &&
298 cnt == pcm_count)
299 return;
300
301 spin_lock_irqsave(&pas_lock, flags);
302
303 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
304
305 if (audio_devs[dev]->dmap_out->dma > 3)
306 count >>= 1;
307
308 if (count != pcm_count)
309 {
310 pas_write(pas_read(0x0B8A) & ~0x80, 0x0B8A);
311 pas_write(0x40 | 0x30 | 0x04, 0x138B);
312 pas_write(count & 0xff, 0x1389);
313 pas_write((count >> 8) & 0xff, 0x1389);
314 pas_write(pas_read(0x0B8A) | 0x80, 0x0B8A);
315
316 pcm_count = count;
317 }
318 pas_write(pas_read(0x0B8A) | 0x80 | 0x40, 0x0B8A);
319#ifdef NO_TRIGGER
320 pas_write((pas_read(0xF8A) | 0x40) & ~0x10, 0xF8A);
321#endif
322
323 pcm_mode = PCM_ADC;
324
325 spin_unlock_irqrestore(&pas_lock, flags);
326}
327
328#ifndef NO_TRIGGER
329static void pas_audio_trigger(int dev, int state)
330{
331 unsigned long flags;
332
333 spin_lock_irqsave(&pas_lock, flags);
334 state &= open_mode;
335
336 if (state & PCM_ENABLE_OUTPUT)
337 pas_write(pas_read(0xF8A) | 0x40 | 0x10, 0xF8A);
338 else if (state & PCM_ENABLE_INPUT)
339 pas_write((pas_read(0xF8A) | 0x40) & ~0x10, 0xF8A);
340 else
341 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A);
342
343 spin_unlock_irqrestore(&pas_lock, flags);
344}
345#endif
346
347static int pas_audio_prepare_for_input(int dev, int bsize, int bcount)
348{
349 pas_audio_reset(dev);
350 return 0;
351}
352
353static int pas_audio_prepare_for_output(int dev, int bsize, int bcount)
354{
355 pas_audio_reset(dev);
356 return 0;
357}
358
359static struct audio_driver pas_audio_driver =
360{
361 .owner = THIS_MODULE,
362 .open = pas_audio_open,
363 .close = pas_audio_close,
364 .output_block = pas_audio_output_block,
365 .start_input = pas_audio_start_input,
366 .ioctl = pas_audio_ioctl,
367 .prepare_for_input = pas_audio_prepare_for_input,
368 .prepare_for_output = pas_audio_prepare_for_output,
369 .halt_io = pas_audio_reset,
370 .trigger = pas_audio_trigger
371};
372
373void __init pas_pcm_init(struct address_info *hw_config)
374{
375 pcm_bitsok = 8;
376 if (pas_read(0xEF8B) & 0x08)
377 pcm_bitsok |= 16;
378
379 pcm_set_speed(DSP_DEFAULT_SPEED);
380
381 if ((pas_audiodev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
382 "Pro Audio Spectrum",
383 &pas_audio_driver,
384 sizeof(struct audio_driver),
385 DMA_AUTOMODE,
386 AFMT_U8 | AFMT_S16_LE,
387 NULL,
388 hw_config->dma,
389 hw_config->dma)) < 0)
390 printk(KERN_WARNING "PAS16: Too many PCM devices available\n");
391}
392
393void pas_pcm_interrupt(unsigned char status, int cause)
394{
395 if (cause == 1)
396 {
397 /*
398 * Halt the PCM first. Otherwise we don't have time to start a new
399 * block before the PCM chip proceeds to the next sample
400 */
401
402 if (!(audio_devs[pas_audiodev]->flags & DMA_AUTOMODE))
403 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A);
404
405 switch (pcm_mode)
406 {
407 case PCM_DAC:
408 DMAbuf_outputintr(pas_audiodev, 1);
409 break;
410
411 case PCM_ADC:
412 DMAbuf_inputintr(pas_audiodev);
413 break;
414
415 default:
416 printk(KERN_WARNING "PAS: Unexpected PCM interrupt\n");
417 }
418 }
419}
diff --git a/sound/oss/pss.c b/sound/oss/pss.c
deleted file mode 100644
index 33c3a442e162..000000000000
--- a/sound/oss/pss.c
+++ /dev/null
@@ -1,1270 +0,0 @@
1/*
2 * sound/oss/pss.c
3 *
4 * The low level driver for the Personal Sound System (ECHO ESC614).
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
15 * Alan Cox modularisation, clean up.
16 *
17 * 98-02-21: Vladimir Michl <vladimir.michl@upol.cz>
18 * Added mixer device for Beethoven ADSP-16 (master volume,
19 * bass, treble, synth), only for speakers.
20 * Fixed bug in pss_write (exchange parameters)
21 * Fixed config port of SB
22 * Requested two regions for PSS (PSS mixer, PSS config)
23 * Modified pss_download_boot
24 * To probe_pss_mss added test for initialize AD1848
25 * 98-05-28: Vladimir Michl <vladimir.michl@upol.cz>
26 * Fixed computation of mixer volumes
27 * 04-05-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
28 * Added code that allows the user to enable his cdrom and/or
29 * joystick through the module parameters pss_cdrom_port and
30 * pss_enable_joystick. pss_cdrom_port takes a port address as its
31 * argument. pss_enable_joystick takes either a 0 or a non-0 as its
32 * argument.
33 * 04-06-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
34 * Separated some code into new functions for easier reuse.
35 * Cleaned up and streamlined new code. Added code to allow a user
36 * to only use this driver for enabling non-sound components
37 * through the new module parameter pss_no_sound (flag). Added
38 * code that would allow a user to decide whether the driver should
39 * reset the configured hardware settings for the PSS board through
40 * the module parameter pss_keep_settings (flag). This flag will
41 * allow a user to free up resources in use by this card if needbe,
42 * furthermore it allows him to use this driver to just enable the
43 * emulations and then be unloaded as it is no longer needed. Both
44 * new settings are only available to this driver if compiled as a
45 * module. The default settings of all new parameters are set to
46 * load the driver as it did in previous versions.
47 * 04-07-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
48 * Added module parameter pss_firmware to allow the user to tell
49 * the driver where the firmware file is located. The default
50 * setting is the previous hardcoded setting "/etc/sound/pss_synth".
51 * 00-03-03: Christoph Hellwig <chhellwig@infradead.org>
52 * Adapted to module_init/module_exit
53 * 11-10-2000: Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
54 * Added __init to probe_pss(), attach_pss() and probe_pss_mpu()
55 * 02-Jan-2001: Chris Rankin
56 * Specify that this module owns the coprocessor
57 */
58
59
60#include <linux/init.h>
61#include <linux/module.h>
62#include <linux/spinlock.h>
63
64#include "sound_config.h"
65#include "sound_firmware.h"
66
67#include "ad1848.h"
68#include "mpu401.h"
69
70/*
71 * PSS registers.
72 */
73#define REG(x) (devc->base+x)
74#define PSS_DATA 0
75#define PSS_STATUS 2
76#define PSS_CONTROL 2
77#define PSS_ID 4
78#define PSS_IRQACK 4
79#define PSS_PIO 0x1a
80
81/*
82 * Config registers
83 */
84#define CONF_PSS 0x10
85#define CONF_WSS 0x12
86#define CONF_SB 0x14
87#define CONF_CDROM 0x16
88#define CONF_MIDI 0x18
89
90/*
91 * Status bits.
92 */
93#define PSS_FLAG3 0x0800
94#define PSS_FLAG2 0x0400
95#define PSS_FLAG1 0x1000
96#define PSS_FLAG0 0x0800
97#define PSS_WRITE_EMPTY 0x8000
98#define PSS_READ_FULL 0x4000
99
100/*
101 * WSS registers
102 */
103#define WSS_INDEX 4
104#define WSS_DATA 5
105
106/*
107 * WSS status bits
108 */
109#define WSS_INITIALIZING 0x80
110#define WSS_AUTOCALIBRATION 0x20
111
112#define NO_WSS_MIXER -1
113
114#include "coproc.h"
115
116#include "pss_boot.h"
117
118/* If compiled into kernel, it enable or disable pss mixer */
119#ifdef CONFIG_PSS_MIXER
120static bool pss_mixer = 1;
121#else
122static bool pss_mixer;
123#endif
124
125
126struct pss_mixerdata {
127 unsigned int volume_l;
128 unsigned int volume_r;
129 unsigned int bass;
130 unsigned int treble;
131 unsigned int synth;
132};
133
134struct pss_confdata {
135 int base;
136 int irq;
137 int dma;
138 int *osp;
139 struct pss_mixerdata mixer;
140 int ad_mixer_dev;
141};
142
143static struct pss_confdata pss_data;
144static struct pss_confdata *devc = &pss_data;
145static DEFINE_SPINLOCK(lock);
146
147static int pss_initialized;
148static int nonstandard_microcode;
149static int pss_cdrom_port = -1; /* Parameter for the PSS cdrom port */
150static bool pss_enable_joystick; /* Parameter for enabling the joystick */
151static coproc_operations pss_coproc_operations;
152
153static void pss_write(struct pss_confdata *devc, int data)
154{
155 unsigned long i, limit;
156
157 limit = jiffies + HZ/10; /* The timeout is 0.1 seconds */
158 /*
159 * Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
160 * called while interrupts are disabled. This means that the timer is
161 * disabled also. However the timeout situation is a abnormal condition.
162 * Normally the DSP should be ready to accept commands after just couple of
163 * loops.
164 */
165
166 for (i = 0; i < 5000000 && time_before(jiffies, limit); i++)
167 {
168 if (inw(REG(PSS_STATUS)) & PSS_WRITE_EMPTY)
169 {
170 outw(data, REG(PSS_DATA));
171 return;
172 }
173 }
174 printk(KERN_WARNING "PSS: DSP Command (%04x) Timeout.\n", data);
175}
176
177static int __init probe_pss(struct address_info *hw_config)
178{
179 unsigned short id;
180 int irq, dma;
181
182 devc->base = hw_config->io_base;
183 irq = devc->irq = hw_config->irq;
184 dma = devc->dma = hw_config->dma;
185 devc->osp = hw_config->osp;
186
187 if (devc->base != 0x220 && devc->base != 0x240)
188 if (devc->base != 0x230 && devc->base != 0x250) /* Some cards use these */
189 return 0;
190
191 if (!request_region(devc->base, 0x10, "PSS mixer, SB emulation")) {
192 printk(KERN_ERR "PSS: I/O port conflict\n");
193 return 0;
194 }
195 id = inw(REG(PSS_ID));
196 if ((id >> 8) != 'E') {
197 printk(KERN_ERR "No PSS signature detected at 0x%x (0x%x)\n", devc->base, id);
198 release_region(devc->base, 0x10);
199 return 0;
200 }
201 if (!request_region(devc->base + 0x10, 0x9, "PSS config")) {
202 printk(KERN_ERR "PSS: I/O port conflict\n");
203 release_region(devc->base, 0x10);
204 return 0;
205 }
206 return 1;
207}
208
209static int set_irq(struct pss_confdata *devc, int dev, int irq)
210{
211 static unsigned short irq_bits[16] =
212 {
213 0x0000, 0x0000, 0x0000, 0x0008,
214 0x0000, 0x0010, 0x0000, 0x0018,
215 0x0000, 0x0020, 0x0028, 0x0030,
216 0x0038, 0x0000, 0x0000, 0x0000
217 };
218
219 unsigned short tmp, bits;
220
221 if (irq < 0 || irq > 15)
222 return 0;
223
224 tmp = inw(REG(dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
225
226 if ((bits = irq_bits[irq]) == 0 && irq != 0)
227 {
228 printk(KERN_ERR "PSS: Invalid IRQ %d\n", irq);
229 return 0;
230 }
231 outw(tmp | bits, REG(dev));
232 return 1;
233}
234
235static void set_io_base(struct pss_confdata *devc, int dev, int base)
236{
237 unsigned short tmp = inw(REG(dev)) & 0x003f;
238 unsigned short bits = (base & 0x0ffc) << 4;
239
240 outw(bits | tmp, REG(dev));
241}
242
243static int set_dma(struct pss_confdata *devc, int dev, int dma)
244{
245 static unsigned short dma_bits[8] =
246 {
247 0x0001, 0x0002, 0x0000, 0x0003,
248 0x0000, 0x0005, 0x0006, 0x0007
249 };
250
251 unsigned short tmp, bits;
252
253 if (dma < 0 || dma > 7)
254 return 0;
255
256 tmp = inw(REG(dev)) & ~0x07; /* Load confreg, mask DMA bits out */
257
258 if ((bits = dma_bits[dma]) == 0 && dma != 4)
259 {
260 printk(KERN_ERR "PSS: Invalid DMA %d\n", dma);
261 return 0;
262 }
263 outw(tmp | bits, REG(dev));
264 return 1;
265}
266
267static int pss_reset_dsp(struct pss_confdata *devc)
268{
269 unsigned long i, limit = jiffies + HZ/10;
270
271 outw(0x2000, REG(PSS_CONTROL));
272 for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
273 inw(REG(PSS_CONTROL));
274 outw(0x0000, REG(PSS_CONTROL));
275 return 1;
276}
277
278static int pss_put_dspword(struct pss_confdata *devc, unsigned short word)
279{
280 int i, val;
281
282 for (i = 0; i < 327680; i++)
283 {
284 val = inw(REG(PSS_STATUS));
285 if (val & PSS_WRITE_EMPTY)
286 {
287 outw(word, REG(PSS_DATA));
288 return 1;
289 }
290 }
291 return 0;
292}
293
294static int pss_get_dspword(struct pss_confdata *devc, unsigned short *word)
295{
296 int i, val;
297
298 for (i = 0; i < 327680; i++)
299 {
300 val = inw(REG(PSS_STATUS));
301 if (val & PSS_READ_FULL)
302 {
303 *word = inw(REG(PSS_DATA));
304 return 1;
305 }
306 }
307 return 0;
308}
309
310static int pss_download_boot(struct pss_confdata *devc, unsigned char *block,
311 int size, int flags)
312{
313 int i, val, count;
314 unsigned long limit;
315
316 if (flags & CPF_FIRST)
317 {
318/*_____ Warn DSP software that a boot is coming */
319 outw(0x00fe, REG(PSS_DATA));
320
321 limit = jiffies + HZ/10;
322 for (i = 0; i < 32768 && time_before(jiffies, limit); i++)
323 if (inw(REG(PSS_DATA)) == 0x5500)
324 break;
325
326 outw(*block++, REG(PSS_DATA));
327 pss_reset_dsp(devc);
328 }
329 count = 1;
330 while ((flags&CPF_LAST) || count<size )
331 {
332 int j;
333
334 for (j = 0; j < 327670; j++)
335 {
336/*_____ Wait for BG to appear */
337 if (inw(REG(PSS_STATUS)) & PSS_FLAG3)
338 break;
339 }
340
341 if (j == 327670)
342 {
343 /* It's ok we timed out when the file was empty */
344 if (count >= size && flags & CPF_LAST)
345 break;
346 else
347 {
348 printk("\n");
349 printk(KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
350 return 0;
351 }
352 }
353/*_____ Send the next byte */
354 if (count >= size)
355 {
356 /* If not data in block send 0xffff */
357 outw (0xffff, REG (PSS_DATA));
358 }
359 else
360 {
361 /*_____ Send the next byte */
362 outw (*block++, REG (PSS_DATA));
363 }
364 count++;
365 }
366
367 if (flags & CPF_LAST)
368 {
369/*_____ Why */
370 outw(0, REG(PSS_DATA));
371
372 limit = jiffies + HZ/10;
373 for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
374 val = inw(REG(PSS_STATUS));
375
376 limit = jiffies + HZ/10;
377 for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
378 {
379 val = inw(REG(PSS_STATUS));
380 if (val & 0x4000)
381 break;
382 }
383
384 /* now read the version */
385 for (i = 0; i < 32000; i++)
386 {
387 val = inw(REG(PSS_STATUS));
388 if (val & PSS_READ_FULL)
389 break;
390 }
391 if (i == 32000)
392 return 0;
393
394 val = inw(REG(PSS_DATA));
395 /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
396 }
397 return 1;
398}
399
400/* Mixer */
401static void set_master_volume(struct pss_confdata *devc, int left, int right)
402{
403 static unsigned char log_scale[101] = {
404 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
405 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
406 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
407 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
408 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
409 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
410 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
411 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
412 0xfe, 0xfe, 0xff, 0xff, 0xff
413 };
414 pss_write(devc, 0x0010);
415 pss_write(devc, log_scale[left] | 0x0000);
416 pss_write(devc, 0x0010);
417 pss_write(devc, log_scale[right] | 0x0100);
418}
419
420static void set_synth_volume(struct pss_confdata *devc, int volume)
421{
422 int vol = ((0x8000*volume)/100L);
423 pss_write(devc, 0x0080);
424 pss_write(devc, vol);
425 pss_write(devc, 0x0081);
426 pss_write(devc, vol);
427}
428
429static void set_bass(struct pss_confdata *devc, int level)
430{
431 int vol = (int)(((0xfd - 0xf0) * level)/100L) + 0xf0;
432 pss_write(devc, 0x0010);
433 pss_write(devc, vol | 0x0200);
434};
435
436static void set_treble(struct pss_confdata *devc, int level)
437{
438 int vol = (((0xfd - 0xf0) * level)/100L) + 0xf0;
439 pss_write(devc, 0x0010);
440 pss_write(devc, vol | 0x0300);
441};
442
443static void pss_mixer_reset(struct pss_confdata *devc)
444{
445 set_master_volume(devc, 33, 33);
446 set_bass(devc, 50);
447 set_treble(devc, 50);
448 set_synth_volume(devc, 30);
449 pss_write (devc, 0x0010);
450 pss_write (devc, 0x0800 | 0xce); /* Stereo */
451
452 if(pss_mixer)
453 {
454 devc->mixer.volume_l = devc->mixer.volume_r = 33;
455 devc->mixer.bass = 50;
456 devc->mixer.treble = 50;
457 devc->mixer.synth = 30;
458 }
459}
460
461static int set_volume_mono(unsigned __user *p, unsigned int *aleft)
462{
463 unsigned int left, volume;
464 if (get_user(volume, p))
465 return -EFAULT;
466
467 left = volume & 0xff;
468 if (left > 100)
469 left = 100;
470 *aleft = left;
471 return 0;
472}
473
474static int set_volume_stereo(unsigned __user *p,
475 unsigned int *aleft,
476 unsigned int *aright)
477{
478 unsigned int left, right, volume;
479 if (get_user(volume, p))
480 return -EFAULT;
481
482 left = volume & 0xff;
483 if (left > 100)
484 left = 100;
485 right = (volume >> 8) & 0xff;
486 if (right > 100)
487 right = 100;
488 *aleft = left;
489 *aright = right;
490 return 0;
491}
492
493static int ret_vol_mono(int left)
494{
495 return ((left << 8) | left);
496}
497
498static int ret_vol_stereo(int left, int right)
499{
500 return ((right << 8) | left);
501}
502
503static int call_ad_mixer(struct pss_confdata *devc, unsigned int cmd,
504 void __user *arg)
505{
506 if (devc->ad_mixer_dev != NO_WSS_MIXER)
507 return mixer_devs[devc->ad_mixer_dev]->ioctl(devc->ad_mixer_dev, cmd, arg);
508 else
509 return -EINVAL;
510}
511
512static int pss_mixer_ioctl (int dev, unsigned int cmd, void __user *arg)
513{
514 struct pss_confdata *devc = mixer_devs[dev]->devc;
515 int cmdf = cmd & 0xff;
516
517 if ((cmdf != SOUND_MIXER_VOLUME) && (cmdf != SOUND_MIXER_BASS) &&
518 (cmdf != SOUND_MIXER_TREBLE) && (cmdf != SOUND_MIXER_SYNTH) &&
519 (cmdf != SOUND_MIXER_DEVMASK) && (cmdf != SOUND_MIXER_STEREODEVS) &&
520 (cmdf != SOUND_MIXER_RECMASK) && (cmdf != SOUND_MIXER_CAPS) &&
521 (cmdf != SOUND_MIXER_RECSRC))
522 {
523 return call_ad_mixer(devc, cmd, arg);
524 }
525
526 if (((cmd >> 8) & 0xff) != 'M')
527 return -EINVAL;
528
529 if (_SIOC_DIR (cmd) & _SIOC_WRITE)
530 {
531 switch (cmdf)
532 {
533 case SOUND_MIXER_RECSRC:
534 if (devc->ad_mixer_dev != NO_WSS_MIXER)
535 return call_ad_mixer(devc, cmd, arg);
536 else
537 {
538 int v;
539 if (get_user(v, (int __user *)arg))
540 return -EFAULT;
541 if (v != 0)
542 return -EINVAL;
543 return 0;
544 }
545 case SOUND_MIXER_VOLUME:
546 if (set_volume_stereo(arg,
547 &devc->mixer.volume_l,
548 &devc->mixer.volume_r))
549 return -EFAULT;
550 set_master_volume(devc, devc->mixer.volume_l,
551 devc->mixer.volume_r);
552 return ret_vol_stereo(devc->mixer.volume_l,
553 devc->mixer.volume_r);
554
555 case SOUND_MIXER_BASS:
556 if (set_volume_mono(arg, &devc->mixer.bass))
557 return -EFAULT;
558 set_bass(devc, devc->mixer.bass);
559 return ret_vol_mono(devc->mixer.bass);
560
561 case SOUND_MIXER_TREBLE:
562 if (set_volume_mono(arg, &devc->mixer.treble))
563 return -EFAULT;
564 set_treble(devc, devc->mixer.treble);
565 return ret_vol_mono(devc->mixer.treble);
566
567 case SOUND_MIXER_SYNTH:
568 if (set_volume_mono(arg, &devc->mixer.synth))
569 return -EFAULT;
570 set_synth_volume(devc, devc->mixer.synth);
571 return ret_vol_mono(devc->mixer.synth);
572
573 default:
574 return -EINVAL;
575 }
576 }
577 else
578 {
579 int val, and_mask = 0, or_mask = 0;
580 /*
581 * Return parameters
582 */
583 switch (cmdf)
584 {
585 case SOUND_MIXER_DEVMASK:
586 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
587 break;
588 and_mask = ~0;
589 or_mask = SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_SYNTH;
590 break;
591
592 case SOUND_MIXER_STEREODEVS:
593 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
594 break;
595 and_mask = ~0;
596 or_mask = SOUND_MASK_VOLUME;
597 break;
598
599 case SOUND_MIXER_RECMASK:
600 if (devc->ad_mixer_dev != NO_WSS_MIXER)
601 return call_ad_mixer(devc, cmd, arg);
602 break;
603
604 case SOUND_MIXER_CAPS:
605 if (devc->ad_mixer_dev != NO_WSS_MIXER)
606 return call_ad_mixer(devc, cmd, arg);
607 or_mask = SOUND_CAP_EXCL_INPUT;
608 break;
609
610 case SOUND_MIXER_RECSRC:
611 if (devc->ad_mixer_dev != NO_WSS_MIXER)
612 return call_ad_mixer(devc, cmd, arg);
613 break;
614
615 case SOUND_MIXER_VOLUME:
616 or_mask = ret_vol_stereo(devc->mixer.volume_l, devc->mixer.volume_r);
617 break;
618
619 case SOUND_MIXER_BASS:
620 or_mask = ret_vol_mono(devc->mixer.bass);
621 break;
622
623 case SOUND_MIXER_TREBLE:
624 or_mask = ret_vol_mono(devc->mixer.treble);
625 break;
626
627 case SOUND_MIXER_SYNTH:
628 or_mask = ret_vol_mono(devc->mixer.synth);
629 break;
630 default:
631 return -EINVAL;
632 }
633 if (get_user(val, (int __user *)arg))
634 return -EFAULT;
635 val &= and_mask;
636 val |= or_mask;
637 if (put_user(val, (int __user *)arg))
638 return -EFAULT;
639 return val;
640 }
641}
642
643static struct mixer_operations pss_mixer_operations =
644{
645 .owner = THIS_MODULE,
646 .id = "SOUNDPORT",
647 .name = "PSS-AD1848",
648 .ioctl = pss_mixer_ioctl
649};
650
651static void disable_all_emulations(void)
652{
653 outw(0x0000, REG(CONF_PSS)); /* 0x0400 enables joystick */
654 outw(0x0000, REG(CONF_WSS));
655 outw(0x0000, REG(CONF_SB));
656 outw(0x0000, REG(CONF_MIDI));
657 outw(0x0000, REG(CONF_CDROM));
658}
659
660static void configure_nonsound_components(void)
661{
662 /* Configure Joystick port */
663
664 if(pss_enable_joystick)
665 {
666 outw(0x0400, REG(CONF_PSS)); /* 0x0400 enables joystick */
667 printk(KERN_INFO "PSS: joystick enabled.\n");
668 }
669 else
670 {
671 printk(KERN_INFO "PSS: joystick port not enabled.\n");
672 }
673
674 /* Configure CDROM port */
675
676 if (pss_cdrom_port == -1) { /* If cdrom port enablation wasn't requested */
677 printk(KERN_INFO "PSS: CDROM port not enabled.\n");
678 } else if (!request_region(pss_cdrom_port, 2, "PSS CDROM")) {
679 pss_cdrom_port = -1;
680 printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
681 } else {
682 set_io_base(devc, CONF_CDROM, pss_cdrom_port);
683 printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
684 }
685}
686
687static int __init attach_pss(struct address_info *hw_config)
688{
689 unsigned short id;
690 char tmp[100];
691
692 devc->base = hw_config->io_base;
693 devc->irq = hw_config->irq;
694 devc->dma = hw_config->dma;
695 devc->osp = hw_config->osp;
696 devc->ad_mixer_dev = NO_WSS_MIXER;
697
698 if (!probe_pss(hw_config))
699 return 0;
700
701 id = inw(REG(PSS_ID)) & 0x00ff;
702
703 /*
704 * Disable all emulations. Will be enabled later (if required).
705 */
706
707 disable_all_emulations();
708
709#ifdef YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
710 if (sound_alloc_dma(hw_config->dma, "PSS"))
711 {
712 printk("pss.c: Can't allocate DMA channel.\n");
713 release_region(hw_config->io_base, 0x10);
714 release_region(hw_config->io_base+0x10, 0x9);
715 return 0;
716 }
717 if (!set_irq(devc, CONF_PSS, devc->irq))
718 {
719 printk("PSS: IRQ allocation error.\n");
720 release_region(hw_config->io_base, 0x10);
721 release_region(hw_config->io_base+0x10, 0x9);
722 return 0;
723 }
724 if (!set_dma(devc, CONF_PSS, devc->dma))
725 {
726 printk(KERN_ERR "PSS: DMA allocation error\n");
727 release_region(hw_config->io_base, 0x10);
728 release_region(hw_config->io_base+0x10, 0x9);
729 return 0;
730 }
731#endif
732
733 configure_nonsound_components();
734 pss_initialized = 1;
735 sprintf(tmp, "ECHO-PSS Rev. %d", id);
736 conf_printf(tmp, hw_config);
737 return 1;
738}
739
740static int __init probe_pss_mpu(struct address_info *hw_config)
741{
742 struct resource *ports;
743 int timeout;
744
745 if (!pss_initialized)
746 return 0;
747
748 ports = request_region(hw_config->io_base, 2, "mpu401");
749
750 if (!ports) {
751 printk(KERN_ERR "PSS: MPU I/O port conflict\n");
752 return 0;
753 }
754 set_io_base(devc, CONF_MIDI, hw_config->io_base);
755 if (!set_irq(devc, CONF_MIDI, hw_config->irq)) {
756 printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
757 goto fail;
758 }
759 if (!pss_synthLen) {
760 printk(KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
761 goto fail;
762 }
763 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
764 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
765 goto fail;
766 }
767
768 /*
769 * Finally wait until the DSP algorithm has initialized itself and
770 * deactivates receive interrupt.
771 */
772
773 for (timeout = 900000; timeout > 0; timeout--)
774 {
775 if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
776 inb(hw_config->io_base); /* Discard it */
777 else
778 break; /* No more input */
779 }
780
781 if (!probe_mpu401(hw_config, ports))
782 goto fail;
783
784 attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
785 if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
786 midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
787 return 1;
788fail:
789 release_region(hw_config->io_base, 2);
790 return 0;
791}
792
793static int pss_coproc_open(void *dev_info, int sub_device)
794{
795 switch (sub_device)
796 {
797 case COPR_MIDI:
798 if (pss_synthLen == 0)
799 {
800 printk(KERN_ERR "PSS: MIDI synth microcode not available.\n");
801 return -EIO;
802 }
803 if (nonstandard_microcode)
804 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
805 {
806 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
807 return -EIO;
808 }
809 nonstandard_microcode = 0;
810 break;
811
812 default:
813 break;
814 }
815 return 0;
816}
817
818static void pss_coproc_close(void *dev_info, int sub_device)
819{
820 return;
821}
822
823static void pss_coproc_reset(void *dev_info)
824{
825 if (pss_synthLen)
826 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
827 {
828 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
829 }
830 nonstandard_microcode = 0;
831}
832
833static int download_boot_block(void *dev_info, copr_buffer * buf)
834{
835 if (buf->len <= 0 || buf->len > sizeof(buf->data))
836 return -EINVAL;
837
838 if (!pss_download_boot(devc, buf->data, buf->len, buf->flags))
839 {
840 printk(KERN_ERR "PSS: Unable to load microcode block to DSP.\n");
841 return -EIO;
842 }
843 nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
844 return 0;
845}
846
847static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
848{
849 copr_buffer *buf;
850 copr_msg *mbuf;
851 copr_debug_buf dbuf;
852 unsigned short tmp;
853 unsigned long flags;
854 unsigned short *data;
855 int i, err;
856 /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
857
858 switch (cmd)
859 {
860 case SNDCTL_COPR_RESET:
861 pss_coproc_reset(dev_info);
862 return 0;
863
864 case SNDCTL_COPR_LOAD:
865 buf = vmalloc(sizeof(copr_buffer));
866 if (buf == NULL)
867 return -ENOSPC;
868 if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
869 vfree(buf);
870 return -EFAULT;
871 }
872 err = download_boot_block(dev_info, buf);
873 vfree(buf);
874 return err;
875
876 case SNDCTL_COPR_SENDMSG:
877 mbuf = vmalloc(sizeof(copr_msg));
878 if (mbuf == NULL)
879 return -ENOSPC;
880 if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
881 vfree(mbuf);
882 return -EFAULT;
883 }
884 data = (unsigned short *)(mbuf->data);
885 spin_lock_irqsave(&lock, flags);
886 for (i = 0; i < mbuf->len; i++) {
887 if (!pss_put_dspword(devc, *data++)) {
888 spin_unlock_irqrestore(&lock,flags);
889 mbuf->len = i; /* feed back number of WORDs sent */
890 err = copy_to_user(arg, mbuf, sizeof(copr_msg));
891 vfree(mbuf);
892 return err ? -EFAULT : -EIO;
893 }
894 }
895 spin_unlock_irqrestore(&lock,flags);
896 vfree(mbuf);
897 return 0;
898
899 case SNDCTL_COPR_RCVMSG:
900 err = 0;
901 mbuf = vmalloc(sizeof(copr_msg));
902 if (mbuf == NULL)
903 return -ENOSPC;
904 data = (unsigned short *)mbuf->data;
905 spin_lock_irqsave(&lock, flags);
906 for (i = 0; i < sizeof(mbuf->data)/sizeof(unsigned short); i++) {
907 mbuf->len = i; /* feed back number of WORDs read */
908 if (!pss_get_dspword(devc, data++)) {
909 if (i == 0)
910 err = -EIO;
911 break;
912 }
913 }
914 spin_unlock_irqrestore(&lock,flags);
915 if (copy_to_user(arg, mbuf, sizeof(copr_msg)))
916 err = -EFAULT;
917 vfree(mbuf);
918 return err;
919
920 case SNDCTL_COPR_RDATA:
921 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
922 return -EFAULT;
923 spin_lock_irqsave(&lock, flags);
924 if (!pss_put_dspword(devc, 0x00d0)) {
925 spin_unlock_irqrestore(&lock,flags);
926 return -EIO;
927 }
928 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
929 spin_unlock_irqrestore(&lock,flags);
930 return -EIO;
931 }
932 if (!pss_get_dspword(devc, &tmp)) {
933 spin_unlock_irqrestore(&lock,flags);
934 return -EIO;
935 }
936 dbuf.parm1 = tmp;
937 spin_unlock_irqrestore(&lock,flags);
938 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
939 return -EFAULT;
940 return 0;
941
942 case SNDCTL_COPR_WDATA:
943 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
944 return -EFAULT;
945 spin_lock_irqsave(&lock, flags);
946 if (!pss_put_dspword(devc, 0x00d1)) {
947 spin_unlock_irqrestore(&lock,flags);
948 return -EIO;
949 }
950 if (!pss_put_dspword(devc, (unsigned short) (dbuf.parm1 & 0xffff))) {
951 spin_unlock_irqrestore(&lock,flags);
952 return -EIO;
953 }
954 tmp = (unsigned int)dbuf.parm2 & 0xffff;
955 if (!pss_put_dspword(devc, tmp)) {
956 spin_unlock_irqrestore(&lock,flags);
957 return -EIO;
958 }
959 spin_unlock_irqrestore(&lock,flags);
960 return 0;
961
962 case SNDCTL_COPR_WCODE:
963 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
964 return -EFAULT;
965 spin_lock_irqsave(&lock, flags);
966 if (!pss_put_dspword(devc, 0x00d3)) {
967 spin_unlock_irqrestore(&lock,flags);
968 return -EIO;
969 }
970 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
971 spin_unlock_irqrestore(&lock,flags);
972 return -EIO;
973 }
974 tmp = (unsigned int)dbuf.parm2 & 0x00ff;
975 if (!pss_put_dspword(devc, tmp)) {
976 spin_unlock_irqrestore(&lock,flags);
977 return -EIO;
978 }
979 tmp = ((unsigned int)dbuf.parm2 >> 8) & 0xffff;
980 if (!pss_put_dspword(devc, tmp)) {
981 spin_unlock_irqrestore(&lock,flags);
982 return -EIO;
983 }
984 spin_unlock_irqrestore(&lock,flags);
985 return 0;
986
987 case SNDCTL_COPR_RCODE:
988 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
989 return -EFAULT;
990 spin_lock_irqsave(&lock, flags);
991 if (!pss_put_dspword(devc, 0x00d2)) {
992 spin_unlock_irqrestore(&lock,flags);
993 return -EIO;
994 }
995 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
996 spin_unlock_irqrestore(&lock,flags);
997 return -EIO;
998 }
999 if (!pss_get_dspword(devc, &tmp)) { /* Read MSB */
1000 spin_unlock_irqrestore(&lock,flags);
1001 return -EIO;
1002 }
1003 dbuf.parm1 = tmp << 8;
1004 if (!pss_get_dspword(devc, &tmp)) { /* Read LSB */
1005 spin_unlock_irqrestore(&lock,flags);
1006 return -EIO;
1007 }
1008 dbuf.parm1 |= tmp & 0x00ff;
1009 spin_unlock_irqrestore(&lock,flags);
1010 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
1011 return -EFAULT;
1012 return 0;
1013
1014 default:
1015 return -EINVAL;
1016 }
1017 return -EINVAL;
1018}
1019
1020static coproc_operations pss_coproc_operations =
1021{
1022 "ADSP-2115",
1023 THIS_MODULE,
1024 pss_coproc_open,
1025 pss_coproc_close,
1026 pss_coproc_ioctl,
1027 pss_coproc_reset,
1028 &pss_data
1029};
1030
1031static int __init probe_pss_mss(struct address_info *hw_config)
1032{
1033 volatile int timeout;
1034 struct resource *ports;
1035 int my_mix = -999; /* gcc shut up */
1036
1037 if (!pss_initialized)
1038 return 0;
1039
1040 if (!request_region(hw_config->io_base, 4, "WSS config")) {
1041 printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
1042 return 0;
1043 }
1044 ports = request_region(hw_config->io_base + 4, 4, "ad1848");
1045 if (!ports) {
1046 printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
1047 release_region(hw_config->io_base, 4);
1048 return 0;
1049 }
1050 set_io_base(devc, CONF_WSS, hw_config->io_base);
1051 if (!set_irq(devc, CONF_WSS, hw_config->irq)) {
1052 printk("PSS: WSS IRQ allocation error.\n");
1053 goto fail;
1054 }
1055 if (!set_dma(devc, CONF_WSS, hw_config->dma)) {
1056 printk(KERN_ERR "PSS: WSS DMA allocation error\n");
1057 goto fail;
1058 }
1059 /*
1060 * For some reason the card returns 0xff in the WSS status register
1061 * immediately after boot. Probably MIDI+SB emulation algorithm
1062 * downloaded to the ADSP2115 spends some time initializing the card.
1063 * Let's try to wait until it finishes this task.
1064 */
1065 for (timeout = 0; timeout < 100000 && (inb(hw_config->io_base + WSS_INDEX) &
1066 WSS_INITIALIZING); timeout++)
1067 ;
1068
1069 outb((0x0b), hw_config->io_base + WSS_INDEX); /* Required by some cards */
1070
1071 for (timeout = 0; (inb(hw_config->io_base + WSS_DATA) & WSS_AUTOCALIBRATION) &&
1072 (timeout < 100000); timeout++)
1073 ;
1074
1075 if (!probe_ms_sound(hw_config, ports))
1076 goto fail;
1077
1078 devc->ad_mixer_dev = NO_WSS_MIXER;
1079 if (pss_mixer)
1080 {
1081 if ((my_mix = sound_install_mixer (MIXER_DRIVER_VERSION,
1082 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
1083 &pss_mixer_operations,
1084 sizeof (struct mixer_operations),
1085 devc)) < 0)
1086 {
1087 printk(KERN_ERR "Could not install PSS mixer\n");
1088 goto fail;
1089 }
1090 }
1091 pss_mixer_reset(devc);
1092 attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
1093
1094 if (hw_config->slots[0] != -1)
1095 {
1096 /* The MSS driver installed itself */
1097 audio_devs[hw_config->slots[0]]->coproc = &pss_coproc_operations;
1098 if (pss_mixer && (num_mixers == (my_mix + 2)))
1099 {
1100 /* The MSS mixer installed */
1101 devc->ad_mixer_dev = audio_devs[hw_config->slots[0]]->mixer_dev;
1102 }
1103 }
1104 return 1;
1105fail:
1106 release_region(hw_config->io_base + 4, 4);
1107 release_region(hw_config->io_base, 4);
1108 return 0;
1109}
1110
1111static inline void __exit unload_pss(struct address_info *hw_config)
1112{
1113 release_region(hw_config->io_base, 0x10);
1114 release_region(hw_config->io_base+0x10, 0x9);
1115}
1116
1117static inline void __exit unload_pss_mpu(struct address_info *hw_config)
1118{
1119 unload_mpu401(hw_config);
1120}
1121
1122static inline void __exit unload_pss_mss(struct address_info *hw_config)
1123{
1124 unload_ms_sound(hw_config);
1125}
1126
1127
1128static struct address_info cfg;
1129static struct address_info cfg2;
1130static struct address_info cfg_mpu;
1131
1132static int pss_io __initdata = -1;
1133static int mss_io __initdata = -1;
1134static int mss_irq __initdata = -1;
1135static int mss_dma __initdata = -1;
1136static int mpu_io __initdata = -1;
1137static int mpu_irq __initdata = -1;
1138static bool pss_no_sound = 0; /* Just configure non-sound components */
1139static bool pss_keep_settings = 1; /* Keep hardware settings at module exit */
1140static char *pss_firmware = "/etc/sound/pss_synth";
1141
1142module_param_hw(pss_io, int, ioport, 0);
1143MODULE_PARM_DESC(pss_io, "Set i/o base of PSS card (probably 0x220 or 0x240)");
1144module_param_hw(mss_io, int, ioport, 0);
1145MODULE_PARM_DESC(mss_io, "Set WSS (audio) i/o base (0x530, 0x604, 0xE80, 0xF40, or other. Address must end in 0 or 4 and must be from 0x100 to 0xFF4)");
1146module_param_hw(mss_irq, int, irq, 0);
1147MODULE_PARM_DESC(mss_irq, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
1148module_param_hw(mss_dma, int, dma, 0);
1149MODULE_PARM_DESC(mss_dma, "Set WSS (audio) DMA (0, 1, 3)");
1150module_param_hw(mpu_io, int, ioport, 0);
1151MODULE_PARM_DESC(mpu_io, "Set MIDI i/o base (0x330 or other. Address must be on 4 location boundaries and must be from 0x100 to 0xFFC)");
1152module_param_hw(mpu_irq, int, irq, 0);
1153MODULE_PARM_DESC(mpu_irq, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
1154module_param_hw(pss_cdrom_port, int, ioport, 0);
1155MODULE_PARM_DESC(pss_cdrom_port, "Set the PSS CDROM port i/o base (0x340 or other)");
1156module_param(pss_enable_joystick, bool, 0);
1157MODULE_PARM_DESC(pss_enable_joystick, "Enables the PSS joystick port (1 to enable, 0 to disable)");
1158module_param(pss_no_sound, bool, 0);
1159MODULE_PARM_DESC(pss_no_sound, "Configure sound compoents (0 - no, 1 - yes)");
1160module_param(pss_keep_settings, bool, 0);
1161MODULE_PARM_DESC(pss_keep_settings, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
1162module_param(pss_firmware, charp, 0);
1163MODULE_PARM_DESC(pss_firmware, "Location of the firmware file (default - /etc/sound/pss_synth)");
1164module_param(pss_mixer, bool, 0);
1165MODULE_PARM_DESC(pss_mixer, "Enable (1) or disable (0) PSS mixer (controlling of output volume, bass, treble, synth volume). The mixer is not available on all PSS cards.");
1166MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
1167MODULE_DESCRIPTION("Module for PSS sound cards (based on AD1848, ADSP-2115 and ESC614). This module includes control of output amplifier and synth volume of the Beethoven ADSP-16 card (this may work with other PSS cards).");
1168MODULE_LICENSE("GPL");
1169
1170
1171static int fw_load = 0;
1172static int pssmpu = 0, pssmss = 0;
1173
1174/*
1175 * Load a PSS sound card module
1176 */
1177
1178static int __init init_pss(void)
1179{
1180
1181 if(pss_no_sound) /* If configuring only nonsound components */
1182 {
1183 cfg.io_base = pss_io;
1184 if(!probe_pss(&cfg))
1185 return -ENODEV;
1186 printk(KERN_INFO "ECHO-PSS Rev. %d\n", inw(REG(PSS_ID)) & 0x00ff);
1187 printk(KERN_INFO "PSS: loading in no sound mode.\n");
1188 disable_all_emulations();
1189 configure_nonsound_components();
1190 release_region(pss_io, 0x10);
1191 release_region(pss_io + 0x10, 0x9);
1192 return 0;
1193 }
1194
1195 cfg.io_base = pss_io;
1196
1197 cfg2.io_base = mss_io;
1198 cfg2.irq = mss_irq;
1199 cfg2.dma = mss_dma;
1200
1201 cfg_mpu.io_base = mpu_io;
1202 cfg_mpu.irq = mpu_irq;
1203
1204 if (cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 || cfg.dma == -1) {
1205 printk(KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1206 return -EINVAL;
1207 }
1208
1209 if (!pss_synth) {
1210 fw_load = 1;
1211 pss_synthLen = mod_firmware_load(pss_firmware, (void *) &pss_synth);
1212 }
1213 if (!attach_pss(&cfg))
1214 return -ENODEV;
1215 /*
1216 * Attach stuff
1217 */
1218 if (probe_pss_mpu(&cfg_mpu))
1219 pssmpu = 1;
1220
1221 if (probe_pss_mss(&cfg2))
1222 pssmss = 1;
1223
1224 return 0;
1225}
1226
1227static void __exit cleanup_pss(void)
1228{
1229 if(!pss_no_sound)
1230 {
1231 if (fw_load)
1232 vfree(pss_synth);
1233 if(pssmss)
1234 unload_pss_mss(&cfg2);
1235 if(pssmpu)
1236 unload_pss_mpu(&cfg_mpu);
1237 unload_pss(&cfg);
1238 } else if (pss_cdrom_port != -1)
1239 release_region(pss_cdrom_port, 2);
1240
1241 if(!pss_keep_settings) /* Keep hardware settings if asked */
1242 {
1243 disable_all_emulations();
1244 printk(KERN_INFO "Resetting PSS sound card configurations.\n");
1245 }
1246}
1247
1248module_init(init_pss);
1249module_exit(cleanup_pss);
1250
1251#ifndef MODULE
1252static int __init setup_pss(char *str)
1253{
1254 /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
1255 int ints[7];
1256
1257 str = get_options(str, ARRAY_SIZE(ints), ints);
1258
1259 pss_io = ints[1];
1260 mss_io = ints[2];
1261 mss_irq = ints[3];
1262 mss_dma = ints[4];
1263 mpu_io = ints[5];
1264 mpu_irq = ints[6];
1265
1266 return 1;
1267}
1268
1269__setup("pss=", setup_pss);
1270#endif
diff --git a/sound/oss/sb.h b/sound/oss/sb.h
deleted file mode 100644
index 77e8891ce333..000000000000
--- a/sound/oss/sb.h
+++ /dev/null
@@ -1,185 +0,0 @@
1#define DSP_RESET (devc->base + 0x6)
2#define DSP_READ (devc->base + 0xA)
3#define DSP_WRITE (devc->base + 0xC)
4#define DSP_COMMAND (devc->base + 0xC)
5#define DSP_STATUS (devc->base + 0xC)
6#define DSP_DATA_AVAIL (devc->base + 0xE)
7#define DSP_DATA_AVL16 (devc->base + 0xF)
8#define MIXER_ADDR (devc->base + 0x4)
9#define MIXER_DATA (devc->base + 0x5)
10#define OPL3_LEFT (devc->base + 0x0)
11#define OPL3_RIGHT (devc->base + 0x2)
12#define OPL3_BOTH (devc->base + 0x8)
13/* DSP Commands */
14
15#define DSP_CMD_SPKON 0xD1
16#define DSP_CMD_SPKOFF 0xD3
17#define DSP_CMD_DMAON 0xD0
18#define DSP_CMD_DMAOFF 0xD4
19
20#define IMODE_NONE 0
21#define IMODE_OUTPUT PCM_ENABLE_OUTPUT
22#define IMODE_INPUT PCM_ENABLE_INPUT
23#define IMODE_INIT 3
24#define IMODE_MIDI 4
25
26#define NORMAL_MIDI 0
27#define UART_MIDI 1
28
29
30/*
31 * Device models
32 */
33#define MDL_NONE 0
34#define MDL_SB1 1 /* SB1.0 or 1.5 */
35#define MDL_SB2 2 /* SB2.0 */
36#define MDL_SB201 3 /* SB2.01 */
37#define MDL_SBPRO 4 /* SB Pro */
38#define MDL_SB16 5 /* SB16/32/AWE */
39#define MDL_SBPNP 6 /* SB16/32/AWE PnP */
40#define MDL_JAZZ 10 /* Media Vision Jazz16 */
41#define MDL_SMW 11 /* Logitech SoundMan Wave (Jazz16) */
42#define MDL_ESS 12 /* ESS ES688 and ES1688 */
43#define MDL_AZTECH 13 /* Aztech Sound Galaxy family */
44#define MDL_ES1868MIDI 14 /* MIDI port of ESS1868 */
45#define MDL_AEDSP 15 /* Audio Excel DSP 16 */
46#define MDL_ESSPCI 16 /* ESS PCI card */
47#define MDL_YMPCI 17 /* Yamaha PCI sb in emulation */
48
49#define SUBMDL_ALS007 42 /* ALS-007 differs from SB16 only in mixer */
50 /* register assignment */
51#define SUBMDL_ALS100 43 /* ALS-100 allows sampling rates of up */
52 /* to 48kHz */
53
54/*
55 * Config flags
56 */
57#define SB_NO_MIDI 0x00000001
58#define SB_NO_MIXER 0x00000002
59#define SB_NO_AUDIO 0x00000004
60#define SB_NO_RECORDING 0x00000008 /* No audio recording */
61#define SB_MIDI_ONLY (SB_NO_AUDIO|SB_NO_MIXER)
62#define SB_PCI_IRQ 0x00000010 /* PCI shared IRQ */
63
64struct mixer_def {
65 unsigned int regno: 8;
66 unsigned int bitoffs:4;
67 unsigned int nbits:4;
68};
69
70typedef struct mixer_def mixer_tab[32][2];
71typedef struct mixer_def mixer_ent;
72
73struct sb_module_options
74{
75 int esstype; /* ESS chip type */
76 int acer; /* Do acer notebook init? */
77 int sm_games; /* Logitech soundman games? */
78};
79
80typedef struct sb_devc {
81 int dev;
82
83 /* Hardware parameters */
84 int *osp;
85 int minor, major;
86 int type;
87 int model, submodel;
88 int caps;
89# define SBCAP_STEREO 0x00000001
90# define SBCAP_16BITS 0x00000002
91
92 /* Hardware resources */
93 int base;
94 int irq;
95 int dma8, dma16;
96
97 int pcibase; /* For ESS Maestro etc */
98
99 /* State variables */
100 int opened;
101 /* new audio fields for full duplex support */
102 int fullduplex;
103 int duplex;
104 int speed, bits, channels;
105 volatile int irq_ok;
106 volatile int intr_active, irq_mode;
107 /* duplicate audio fields for full duplex support */
108 volatile int intr_active_16, irq_mode_16;
109
110 /* Mixer fields */
111 int *levels;
112 mixer_tab *iomap;
113 size_t iomap_sz; /* number or records in the iomap table */
114 int mixer_caps, recmask, outmask, supported_devices;
115 int supported_rec_devices, supported_out_devices;
116 int my_mixerdev;
117 int sbmixnum;
118
119 /* Audio fields */
120 unsigned long trg_buf;
121 int trigger_bits;
122 int trg_bytes;
123 int trg_intrflag;
124 int trg_restart;
125 /* duplicate audio fields for full duplex support */
126 unsigned long trg_buf_16;
127 int trigger_bits_16;
128 int trg_bytes_16;
129 int trg_intrflag_16;
130 int trg_restart_16;
131
132 unsigned char tconst;
133
134 /* MIDI fields */
135 int my_mididev;
136 int input_opened;
137 int midi_broken;
138 void (*midi_input_intr) (int dev, unsigned char data);
139 void *midi_irq_cookie; /* IRQ cookie for the midi */
140
141 spinlock_t lock;
142
143 struct sb_module_options sbmo; /* Module options */
144
145 } sb_devc;
146
147/*
148 * PCI card types
149 */
150
151#define SB_PCI_ESSMAESTRO 1 /* ESS Maestro Legacy */
152#define SB_PCI_YAMAHA 2 /* Yamaha Legacy */
153
154/*
155 * Functions
156 */
157
158int sb_dsp_command (sb_devc *devc, unsigned char val);
159int sb_dsp_get_byte(sb_devc * devc);
160int sb_dsp_reset (sb_devc *devc);
161void sb_setmixer (sb_devc *devc, unsigned int port, unsigned int value);
162unsigned int sb_getmixer (sb_devc *devc, unsigned int port);
163int sb_dsp_detect (struct address_info *hw_config, int pci, int pciio, struct sb_module_options *sbmo);
164int sb_dsp_init (struct address_info *hw_config, struct module *owner);
165void sb_dsp_unload(struct address_info *hw_config, int sbmpu);
166int sb_mixer_init(sb_devc *devc, struct module *owner);
167void sb_mixer_unload(sb_devc *devc);
168void sb_mixer_set_stereo (sb_devc *devc, int mode);
169void smw_mixer_init(sb_devc *devc);
170void sb_dsp_midi_init (sb_devc *devc, struct module *owner);
171void sb_audio_init (sb_devc *devc, char *name, struct module *owner);
172void sb_midi_interrupt (sb_devc *devc);
173void sb_chgmixer (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val);
174int sb_common_mixer_set(sb_devc * devc, int dev, int left, int right);
175
176int sb_audio_open(int dev, int mode);
177void sb_audio_close(int dev);
178
179/* From sb_common.c */
180void sb_dsp_disable_midi(int port);
181int probe_sbmpu (struct address_info *hw_config, struct module *owner);
182void unload_sbmpu (struct address_info *hw_config);
183
184void unload_sb16(struct address_info *hw_info);
185void unload_sb16midi(struct address_info *hw_info);
diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
deleted file mode 100644
index dc91072f4d82..000000000000
--- a/sound/oss/sb_audio.c
+++ /dev/null
@@ -1,1097 +0,0 @@
1/*
2 * sound/oss/sb_audio.c
3 *
4 * Audio routines for Sound Blaster compatible cards.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 * Changes
14 * Alan Cox : Formatting and clean ups
15 *
16 * Status
17 * Mostly working. Weird uart bug causing irq storms
18 *
19 * Daniel J. Rodriksson: Changes to make sb16 work full duplex.
20 * Maybe other 16 bit cards in this code could behave
21 * the same.
22 * Chris Rankin: Use spinlocks instead of CLI/STI
23 */
24
25#include <linux/spinlock.h>
26
27#include "sound_config.h"
28
29#include "sb_mixer.h"
30#include "sb.h"
31
32#include "sb_ess.h"
33
34int sb_audio_open(int dev, int mode)
35{
36 sb_devc *devc = audio_devs[dev]->devc;
37 unsigned long flags;
38
39 if (devc == NULL)
40 {
41 printk(KERN_ERR "Sound Blaster: incomplete initialization.\n");
42 return -ENXIO;
43 }
44 if (devc->caps & SB_NO_RECORDING && mode & OPEN_READ)
45 {
46 if (mode == OPEN_READ)
47 return -EPERM;
48 }
49 spin_lock_irqsave(&devc->lock, flags);
50 if (devc->opened)
51 {
52 spin_unlock_irqrestore(&devc->lock, flags);
53 return -EBUSY;
54 }
55 if (devc->dma16 != -1 && devc->dma16 != devc->dma8 && !devc->duplex)
56 {
57 if (sound_open_dma(devc->dma16, "Sound Blaster 16 bit"))
58 {
59 spin_unlock_irqrestore(&devc->lock, flags);
60 return -EBUSY;
61 }
62 }
63 devc->opened = mode;
64 spin_unlock_irqrestore(&devc->lock, flags);
65
66 devc->irq_mode = IMODE_NONE;
67 devc->irq_mode_16 = IMODE_NONE;
68 devc->fullduplex = devc->duplex &&
69 ((mode & OPEN_READ) && (mode & OPEN_WRITE));
70 sb_dsp_reset(devc);
71
72 /* At first glance this check isn't enough, some ESS chips might not
73 * have a RECLEV. However if they don't common_mixer_set will refuse
74 * cause devc->iomap has no register mapping for RECLEV
75 */
76 if (devc->model == MDL_ESS) ess_mixer_reload (devc, SOUND_MIXER_RECLEV);
77
78 /* The ALS007 seems to require that the DSP be removed from the output */
79 /* in order for recording to be activated properly. This is done by */
80 /* setting the appropriate bits of the output control register 4ch to */
81 /* zero. This code assumes that the output control registers are not */
82 /* used anywhere else and therefore the DSP bits are *always* ON for */
83 /* output and OFF for sampling. */
84
85 if (devc->submodel == SUBMDL_ALS007)
86 {
87 if (mode & OPEN_READ)
88 sb_setmixer(devc,ALS007_OUTPUT_CTRL2,
89 sb_getmixer(devc,ALS007_OUTPUT_CTRL2) & 0xf9);
90 else
91 sb_setmixer(devc,ALS007_OUTPUT_CTRL2,
92 sb_getmixer(devc,ALS007_OUTPUT_CTRL2) | 0x06);
93 }
94 return 0;
95}
96
97void sb_audio_close(int dev)
98{
99 sb_devc *devc = audio_devs[dev]->devc;
100
101 /* fix things if mmap turned off fullduplex */
102 if(devc->duplex
103 && !devc->fullduplex
104 && (devc->opened & OPEN_READ) && (devc->opened & OPEN_WRITE))
105 swap(audio_devs[dev]->dmap_out, audio_devs[dev]->dmap_in);
106
107 audio_devs[dev]->dmap_out->dma = devc->dma8;
108 audio_devs[dev]->dmap_in->dma = ( devc->duplex ) ?
109 devc->dma16 : devc->dma8;
110
111 if (devc->dma16 != -1 && devc->dma16 != devc->dma8 && !devc->duplex)
112 sound_close_dma(devc->dma16);
113
114 /* For ALS007, turn DSP output back on if closing the device for read */
115
116 if ((devc->submodel == SUBMDL_ALS007) && (devc->opened & OPEN_READ))
117 {
118 sb_setmixer(devc,ALS007_OUTPUT_CTRL2,
119 sb_getmixer(devc,ALS007_OUTPUT_CTRL2) | 0x06);
120 }
121 devc->opened = 0;
122}
123
124static void sb_set_output_parms(int dev, unsigned long buf, int nr_bytes,
125 int intrflag)
126{
127 sb_devc *devc = audio_devs[dev]->devc;
128
129 if (!devc->fullduplex || devc->bits == AFMT_S16_LE)
130 {
131 devc->trg_buf = buf;
132 devc->trg_bytes = nr_bytes;
133 devc->trg_intrflag = intrflag;
134 devc->irq_mode = IMODE_OUTPUT;
135 }
136 else
137 {
138 devc->trg_buf_16 = buf;
139 devc->trg_bytes_16 = nr_bytes;
140 devc->trg_intrflag_16 = intrflag;
141 devc->irq_mode_16 = IMODE_OUTPUT;
142 }
143}
144
145static void sb_set_input_parms(int dev, unsigned long buf, int count, int intrflag)
146{
147 sb_devc *devc = audio_devs[dev]->devc;
148
149 if (!devc->fullduplex || devc->bits != AFMT_S16_LE)
150 {
151 devc->trg_buf = buf;
152 devc->trg_bytes = count;
153 devc->trg_intrflag = intrflag;
154 devc->irq_mode = IMODE_INPUT;
155 }
156 else
157 {
158 devc->trg_buf_16 = buf;
159 devc->trg_bytes_16 = count;
160 devc->trg_intrflag_16 = intrflag;
161 devc->irq_mode_16 = IMODE_INPUT;
162 }
163}
164
165/*
166 * SB1.x compatible routines
167 */
168
169static void sb1_audio_output_block(int dev, unsigned long buf, int nr_bytes, int intrflag)
170{
171 unsigned long flags;
172 int count = nr_bytes;
173 sb_devc *devc = audio_devs[dev]->devc;
174
175 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
176
177 if (audio_devs[dev]->dmap_out->dma > 3)
178 count >>= 1;
179 count--;
180
181 devc->irq_mode = IMODE_OUTPUT;
182
183 spin_lock_irqsave(&devc->lock, flags);
184 if (sb_dsp_command(devc, 0x14)) /* 8 bit DAC using DMA */
185 {
186 sb_dsp_command(devc, (unsigned char) (count & 0xff));
187 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
188 }
189 else
190 printk(KERN_WARNING "Sound Blaster: unable to start DAC.\n");
191 spin_unlock_irqrestore(&devc->lock, flags);
192 devc->intr_active = 1;
193}
194
195static void sb1_audio_start_input(int dev, unsigned long buf, int nr_bytes, int intrflag)
196{
197 unsigned long flags;
198 int count = nr_bytes;
199 sb_devc *devc = audio_devs[dev]->devc;
200
201 /*
202 * Start a DMA input to the buffer pointed by dmaqtail
203 */
204
205 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
206
207 if (audio_devs[dev]->dmap_out->dma > 3)
208 count >>= 1;
209 count--;
210
211 devc->irq_mode = IMODE_INPUT;
212
213 spin_lock_irqsave(&devc->lock, flags);
214 if (sb_dsp_command(devc, 0x24)) /* 8 bit ADC using DMA */
215 {
216 sb_dsp_command(devc, (unsigned char) (count & 0xff));
217 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
218 }
219 else
220 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
221 spin_unlock_irqrestore(&devc->lock, flags);
222
223 devc->intr_active = 1;
224}
225
226static void sb1_audio_trigger(int dev, int bits)
227{
228 sb_devc *devc = audio_devs[dev]->devc;
229
230 bits &= devc->irq_mode;
231
232 if (!bits)
233 sb_dsp_command(devc, 0xd0); /* Halt DMA */
234 else
235 {
236 switch (devc->irq_mode)
237 {
238 case IMODE_INPUT:
239 sb1_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
240 devc->trg_intrflag);
241 break;
242
243 case IMODE_OUTPUT:
244 sb1_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
245 devc->trg_intrflag);
246 break;
247 }
248 }
249 devc->trigger_bits = bits;
250}
251
252static int sb1_audio_prepare_for_input(int dev, int bsize, int bcount)
253{
254 sb_devc *devc = audio_devs[dev]->devc;
255 unsigned long flags;
256
257 spin_lock_irqsave(&devc->lock, flags);
258 if (sb_dsp_command(devc, 0x40))
259 sb_dsp_command(devc, devc->tconst);
260 sb_dsp_command(devc, DSP_CMD_SPKOFF);
261 spin_unlock_irqrestore(&devc->lock, flags);
262
263 devc->trigger_bits = 0;
264 return 0;
265}
266
267static int sb1_audio_prepare_for_output(int dev, int bsize, int bcount)
268{
269 sb_devc *devc = audio_devs[dev]->devc;
270 unsigned long flags;
271
272 spin_lock_irqsave(&devc->lock, flags);
273 if (sb_dsp_command(devc, 0x40))
274 sb_dsp_command(devc, devc->tconst);
275 sb_dsp_command(devc, DSP_CMD_SPKON);
276 spin_unlock_irqrestore(&devc->lock, flags);
277 devc->trigger_bits = 0;
278 return 0;
279}
280
281static int sb1_audio_set_speed(int dev, int speed)
282{
283 int max_speed = 23000;
284 sb_devc *devc = audio_devs[dev]->devc;
285 int tmp;
286
287 if (devc->opened & OPEN_READ)
288 max_speed = 13000;
289
290 if (speed > 0)
291 {
292 if (speed < 4000)
293 speed = 4000;
294
295 if (speed > max_speed)
296 speed = max_speed;
297
298 devc->tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
299 tmp = 256 - devc->tconst;
300 speed = (1000000 + tmp / 2) / tmp;
301
302 devc->speed = speed;
303 }
304 return devc->speed;
305}
306
307static short sb1_audio_set_channels(int dev, short channels)
308{
309 sb_devc *devc = audio_devs[dev]->devc;
310 return devc->channels = 1;
311}
312
313static unsigned int sb1_audio_set_bits(int dev, unsigned int bits)
314{
315 sb_devc *devc = audio_devs[dev]->devc;
316 return devc->bits = 8;
317}
318
319static void sb1_audio_halt_xfer(int dev)
320{
321 unsigned long flags;
322 sb_devc *devc = audio_devs[dev]->devc;
323
324 spin_lock_irqsave(&devc->lock, flags);
325 sb_dsp_reset(devc);
326 spin_unlock_irqrestore(&devc->lock, flags);
327}
328
329/*
330 * SB 2.0 and SB 2.01 compatible routines
331 */
332
333static void sb20_audio_output_block(int dev, unsigned long buf, int nr_bytes,
334 int intrflag)
335{
336 unsigned long flags;
337 int count = nr_bytes;
338 sb_devc *devc = audio_devs[dev]->devc;
339 unsigned char cmd;
340
341 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
342
343 if (audio_devs[dev]->dmap_out->dma > 3)
344 count >>= 1;
345 count--;
346
347 devc->irq_mode = IMODE_OUTPUT;
348
349 spin_lock_irqsave(&devc->lock, flags);
350 if (sb_dsp_command(devc, 0x48)) /* DSP Block size */
351 {
352 sb_dsp_command(devc, (unsigned char) (count & 0xff));
353 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
354
355 if (devc->speed * devc->channels <= 23000)
356 cmd = 0x1c; /* 8 bit PCM output */
357 else
358 cmd = 0x90; /* 8 bit high speed PCM output (SB2.01/Pro) */
359
360 if (!sb_dsp_command(devc, cmd))
361 printk(KERN_ERR "Sound Blaster: unable to start DAC.\n");
362 }
363 else
364 printk(KERN_ERR "Sound Blaster: unable to start DAC.\n");
365 spin_unlock_irqrestore(&devc->lock, flags);
366 devc->intr_active = 1;
367}
368
369static void sb20_audio_start_input(int dev, unsigned long buf, int nr_bytes, int intrflag)
370{
371 unsigned long flags;
372 int count = nr_bytes;
373 sb_devc *devc = audio_devs[dev]->devc;
374 unsigned char cmd;
375
376 /*
377 * Start a DMA input to the buffer pointed by dmaqtail
378 */
379
380 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
381
382 if (audio_devs[dev]->dmap_out->dma > 3)
383 count >>= 1;
384 count--;
385
386 devc->irq_mode = IMODE_INPUT;
387
388 spin_lock_irqsave(&devc->lock, flags);
389 if (sb_dsp_command(devc, 0x48)) /* DSP Block size */
390 {
391 sb_dsp_command(devc, (unsigned char) (count & 0xff));
392 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
393
394 if (devc->speed * devc->channels <= (devc->major == 3 ? 23000 : 13000))
395 cmd = 0x2c; /* 8 bit PCM input */
396 else
397 cmd = 0x98; /* 8 bit high speed PCM input (SB2.01/Pro) */
398
399 if (!sb_dsp_command(devc, cmd))
400 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
401 }
402 else
403 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
404 spin_unlock_irqrestore(&devc->lock, flags);
405 devc->intr_active = 1;
406}
407
408static void sb20_audio_trigger(int dev, int bits)
409{
410 sb_devc *devc = audio_devs[dev]->devc;
411 bits &= devc->irq_mode;
412
413 if (!bits)
414 sb_dsp_command(devc, 0xd0); /* Halt DMA */
415 else
416 {
417 switch (devc->irq_mode)
418 {
419 case IMODE_INPUT:
420 sb20_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
421 devc->trg_intrflag);
422 break;
423
424 case IMODE_OUTPUT:
425 sb20_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
426 devc->trg_intrflag);
427 break;
428 }
429 }
430 devc->trigger_bits = bits;
431}
432
433/*
434 * SB2.01 specific speed setup
435 */
436
437static int sb201_audio_set_speed(int dev, int speed)
438{
439 sb_devc *devc = audio_devs[dev]->devc;
440 int tmp;
441 int s;
442
443 if (speed > 0)
444 {
445 if (speed < 4000)
446 speed = 4000;
447 if (speed > 44100)
448 speed = 44100;
449 if (devc->opened & OPEN_READ && speed > 15000)
450 speed = 15000;
451 s = speed * devc->channels;
452 devc->tconst = (256 - ((1000000 + s / 2) / s)) & 0xff;
453 tmp = 256 - devc->tconst;
454 speed = ((1000000 + tmp / 2) / tmp) / devc->channels;
455
456 devc->speed = speed;
457 }
458 return devc->speed;
459}
460
461/*
462 * SB Pro specific routines
463 */
464
465static int sbpro_audio_prepare_for_input(int dev, int bsize, int bcount)
466{ /* For SB Pro and Jazz16 */
467 sb_devc *devc = audio_devs[dev]->devc;
468 unsigned long flags;
469 unsigned char bits = 0;
470
471 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
472 audio_devs[dev]->dmap_out->dma = audio_devs[dev]->dmap_in->dma =
473 devc->bits == 16 ? devc->dma16 : devc->dma8;
474
475 if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)
476 if (devc->bits == AFMT_S16_LE)
477 bits = 0x04; /* 16 bit mode */
478
479 spin_lock_irqsave(&devc->lock, flags);
480 if (sb_dsp_command(devc, 0x40))
481 sb_dsp_command(devc, devc->tconst);
482 sb_dsp_command(devc, DSP_CMD_SPKOFF);
483 if (devc->channels == 1)
484 sb_dsp_command(devc, 0xa0 | bits); /* Mono input */
485 else
486 sb_dsp_command(devc, 0xa8 | bits); /* Stereo input */
487 spin_unlock_irqrestore(&devc->lock, flags);
488
489 devc->trigger_bits = 0;
490 return 0;
491}
492
493static int sbpro_audio_prepare_for_output(int dev, int bsize, int bcount)
494{ /* For SB Pro and Jazz16 */
495 sb_devc *devc = audio_devs[dev]->devc;
496 unsigned long flags;
497 unsigned char tmp;
498 unsigned char bits = 0;
499
500 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
501 audio_devs[dev]->dmap_out->dma = audio_devs[dev]->dmap_in->dma = devc->bits == 16 ? devc->dma16 : devc->dma8;
502 if (devc->model == MDL_SBPRO)
503 sb_mixer_set_stereo(devc, devc->channels == 2);
504
505 spin_lock_irqsave(&devc->lock, flags);
506 if (sb_dsp_command(devc, 0x40))
507 sb_dsp_command(devc, devc->tconst);
508 sb_dsp_command(devc, DSP_CMD_SPKON);
509
510 if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)
511 {
512 if (devc->bits == AFMT_S16_LE)
513 bits = 0x04; /* 16 bit mode */
514
515 if (devc->channels == 1)
516 sb_dsp_command(devc, 0xa0 | bits); /* Mono output */
517 else
518 sb_dsp_command(devc, 0xa8 | bits); /* Stereo output */
519 spin_unlock_irqrestore(&devc->lock, flags);
520 }
521 else
522 {
523 spin_unlock_irqrestore(&devc->lock, flags);
524 tmp = sb_getmixer(devc, 0x0e);
525 if (devc->channels == 1)
526 tmp &= ~0x02;
527 else
528 tmp |= 0x02;
529 sb_setmixer(devc, 0x0e, tmp);
530 }
531 devc->trigger_bits = 0;
532 return 0;
533}
534
535static int sbpro_audio_set_speed(int dev, int speed)
536{
537 sb_devc *devc = audio_devs[dev]->devc;
538
539 if (speed > 0)
540 {
541 if (speed < 4000)
542 speed = 4000;
543 if (speed > 44100)
544 speed = 44100;
545 if (devc->channels > 1 && speed > 22050)
546 speed = 22050;
547 sb201_audio_set_speed(dev, speed);
548 }
549 return devc->speed;
550}
551
552static short sbpro_audio_set_channels(int dev, short channels)
553{
554 sb_devc *devc = audio_devs[dev]->devc;
555
556 if (channels == 1 || channels == 2)
557 {
558 if (channels != devc->channels)
559 {
560 devc->channels = channels;
561 if (devc->model == MDL_SBPRO && devc->channels == 2)
562 sbpro_audio_set_speed(dev, devc->speed);
563 }
564 }
565 return devc->channels;
566}
567
568static int jazz16_audio_set_speed(int dev, int speed)
569{
570 sb_devc *devc = audio_devs[dev]->devc;
571
572 if (speed > 0)
573 {
574 int tmp;
575 int s;
576
577 if (speed < 5000)
578 speed = 5000;
579 if (speed > 44100)
580 speed = 44100;
581
582 s = speed * devc->channels;
583
584 devc->tconst = (256 - ((1000000 + s / 2) / s)) & 0xff;
585
586 tmp = 256 - devc->tconst;
587 speed = ((1000000 + tmp / 2) / tmp) / devc->channels;
588
589 devc->speed = speed;
590 }
591 return devc->speed;
592}
593
594/*
595 * SB16 specific routines
596 */
597
598static int sb16_audio_set_speed(int dev, int speed)
599{
600 sb_devc *devc = audio_devs[dev]->devc;
601 int max_speed = devc->submodel == SUBMDL_ALS100 ? 48000 : 44100;
602
603 if (speed > 0)
604 {
605 if (speed < 5000)
606 speed = 5000;
607
608 if (speed > max_speed)
609 speed = max_speed;
610
611 devc->speed = speed;
612 }
613 return devc->speed;
614}
615
616static unsigned int sb16_audio_set_bits(int dev, unsigned int bits)
617{
618 sb_devc *devc = audio_devs[dev]->devc;
619
620 if (bits != 0)
621 {
622 if (bits == AFMT_U8 || bits == AFMT_S16_LE)
623 devc->bits = bits;
624 else
625 devc->bits = AFMT_U8;
626 }
627
628 return devc->bits;
629}
630
631static int sb16_audio_prepare_for_input(int dev, int bsize, int bcount)
632{
633 sb_devc *devc = audio_devs[dev]->devc;
634
635 if (!devc->fullduplex)
636 {
637 audio_devs[dev]->dmap_out->dma =
638 audio_devs[dev]->dmap_in->dma =
639 devc->bits == AFMT_S16_LE ?
640 devc->dma16 : devc->dma8;
641 }
642 else if (devc->bits == AFMT_S16_LE)
643 {
644 audio_devs[dev]->dmap_out->dma = devc->dma8;
645 audio_devs[dev]->dmap_in->dma = devc->dma16;
646 }
647 else
648 {
649 audio_devs[dev]->dmap_out->dma = devc->dma16;
650 audio_devs[dev]->dmap_in->dma = devc->dma8;
651 }
652
653 devc->trigger_bits = 0;
654 return 0;
655}
656
657static int sb16_audio_prepare_for_output(int dev, int bsize, int bcount)
658{
659 sb_devc *devc = audio_devs[dev]->devc;
660
661 if (!devc->fullduplex)
662 {
663 audio_devs[dev]->dmap_out->dma =
664 audio_devs[dev]->dmap_in->dma =
665 devc->bits == AFMT_S16_LE ?
666 devc->dma16 : devc->dma8;
667 }
668 else if (devc->bits == AFMT_S16_LE)
669 {
670 audio_devs[dev]->dmap_out->dma = devc->dma8;
671 audio_devs[dev]->dmap_in->dma = devc->dma16;
672 }
673 else
674 {
675 audio_devs[dev]->dmap_out->dma = devc->dma16;
676 audio_devs[dev]->dmap_in->dma = devc->dma8;
677 }
678
679 devc->trigger_bits = 0;
680 return 0;
681}
682
683static void sb16_audio_output_block(int dev, unsigned long buf, int count,
684 int intrflag)
685{
686 unsigned long flags, cnt;
687 sb_devc *devc = audio_devs[dev]->devc;
688 unsigned long bits;
689
690 if (!devc->fullduplex || devc->bits == AFMT_S16_LE)
691 {
692 devc->irq_mode = IMODE_OUTPUT;
693 devc->intr_active = 1;
694 }
695 else
696 {
697 devc->irq_mode_16 = IMODE_OUTPUT;
698 devc->intr_active_16 = 1;
699 }
700
701 /* save value */
702 spin_lock_irqsave(&devc->lock, flags);
703 bits = devc->bits;
704 if (devc->fullduplex)
705 devc->bits = (devc->bits == AFMT_S16_LE) ?
706 AFMT_U8 : AFMT_S16_LE;
707 spin_unlock_irqrestore(&devc->lock, flags);
708
709 cnt = count;
710 if (devc->bits == AFMT_S16_LE)
711 cnt >>= 1;
712 cnt--;
713
714 spin_lock_irqsave(&devc->lock, flags);
715
716 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
717
718 sb_dsp_command(devc, 0x41);
719 sb_dsp_command(devc, (unsigned char) ((devc->speed >> 8) & 0xff));
720 sb_dsp_command(devc, (unsigned char) (devc->speed & 0xff));
721
722 sb_dsp_command(devc, (devc->bits == AFMT_S16_LE ? 0xb6 : 0xc6));
723 sb_dsp_command(devc, ((devc->channels == 2 ? 0x20 : 0) +
724 (devc->bits == AFMT_S16_LE ? 0x10 : 0)));
725 sb_dsp_command(devc, (unsigned char) (cnt & 0xff));
726 sb_dsp_command(devc, (unsigned char) (cnt >> 8));
727
728 /* restore real value after all programming */
729 devc->bits = bits;
730 spin_unlock_irqrestore(&devc->lock, flags);
731}
732
733
734/*
735 * This fails on the Cyrix MediaGX. If you don't have the DMA enabled
736 * before the first sample arrives it locks up. However even if you
737 * do enable the DMA in time you just get DMA timeouts and missing
738 * interrupts and stuff, so for now I've not bothered fixing this either.
739 */
740
741static void sb16_audio_start_input(int dev, unsigned long buf, int count, int intrflag)
742{
743 unsigned long flags, cnt;
744 sb_devc *devc = audio_devs[dev]->devc;
745
746 if (!devc->fullduplex || devc->bits != AFMT_S16_LE)
747 {
748 devc->irq_mode = IMODE_INPUT;
749 devc->intr_active = 1;
750 }
751 else
752 {
753 devc->irq_mode_16 = IMODE_INPUT;
754 devc->intr_active_16 = 1;
755 }
756
757 cnt = count;
758 if (devc->bits == AFMT_S16_LE)
759 cnt >>= 1;
760 cnt--;
761
762 spin_lock_irqsave(&devc->lock, flags);
763
764 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
765
766 sb_dsp_command(devc, 0x42);
767 sb_dsp_command(devc, (unsigned char) ((devc->speed >> 8) & 0xff));
768 sb_dsp_command(devc, (unsigned char) (devc->speed & 0xff));
769
770 sb_dsp_command(devc, (devc->bits == AFMT_S16_LE ? 0xbe : 0xce));
771 sb_dsp_command(devc, ((devc->channels == 2 ? 0x20 : 0) +
772 (devc->bits == AFMT_S16_LE ? 0x10 : 0)));
773 sb_dsp_command(devc, (unsigned char) (cnt & 0xff));
774 sb_dsp_command(devc, (unsigned char) (cnt >> 8));
775
776 spin_unlock_irqrestore(&devc->lock, flags);
777}
778
779static void sb16_audio_trigger(int dev, int bits)
780{
781 sb_devc *devc = audio_devs[dev]->devc;
782
783 int bits_16 = bits & devc->irq_mode_16;
784 bits &= devc->irq_mode;
785
786 if (!bits && !bits_16)
787 sb_dsp_command(devc, 0xd0); /* Halt DMA */
788 else
789 {
790 if (bits)
791 {
792 switch (devc->irq_mode)
793 {
794 case IMODE_INPUT:
795 sb16_audio_start_input(dev,
796 devc->trg_buf,
797 devc->trg_bytes,
798 devc->trg_intrflag);
799 break;
800
801 case IMODE_OUTPUT:
802 sb16_audio_output_block(dev,
803 devc->trg_buf,
804 devc->trg_bytes,
805 devc->trg_intrflag);
806 break;
807 }
808 }
809 if (bits_16)
810 {
811 switch (devc->irq_mode_16)
812 {
813 case IMODE_INPUT:
814 sb16_audio_start_input(dev,
815 devc->trg_buf_16,
816 devc->trg_bytes_16,
817 devc->trg_intrflag_16);
818 break;
819
820 case IMODE_OUTPUT:
821 sb16_audio_output_block(dev,
822 devc->trg_buf_16,
823 devc->trg_bytes_16,
824 devc->trg_intrflag_16);
825 break;
826 }
827 }
828 }
829
830 devc->trigger_bits = bits | bits_16;
831}
832
833static unsigned char lbuf8[2048];
834static signed short *lbuf16 = (signed short *)lbuf8;
835#define LBUFCOPYSIZE 1024
836static void
837sb16_copy_from_user(int dev,
838 char *localbuf, int localoffs,
839 const char __user *userbuf, int useroffs,
840 int max_in, int max_out,
841 int *used, int *returned,
842 int len)
843{
844 sb_devc *devc = audio_devs[dev]->devc;
845 int i, c, p, locallen;
846 unsigned char *buf8;
847 signed short *buf16;
848
849 /* if not duplex no conversion */
850 if (!devc->fullduplex)
851 {
852 if (copy_from_user(localbuf + localoffs,
853 userbuf + useroffs, len))
854 return;
855 *used = len;
856 *returned = len;
857 }
858 else if (devc->bits == AFMT_S16_LE)
859 {
860 /* 16 -> 8 */
861 /* max_in >> 1, max number of samples in ( 16 bits ) */
862 /* max_out, max number of samples out ( 8 bits ) */
863 /* len, number of samples that will be taken ( 16 bits )*/
864 /* c, count of samples remaining in buffer ( 16 bits )*/
865 /* p, count of samples already processed ( 16 bits )*/
866 len = ( (max_in >> 1) > max_out) ? max_out : (max_in >> 1);
867 c = len;
868 p = 0;
869 buf8 = (unsigned char *)(localbuf + localoffs);
870 while (c)
871 {
872 locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
873 /* << 1 in order to get 16 bit samples */
874 if (copy_from_user(lbuf16,
875 userbuf + useroffs + (p << 1),
876 locallen << 1))
877 return;
878 for (i = 0; i < locallen; i++)
879 {
880 buf8[p+i] = ~((lbuf16[i] >> 8) & 0xff) ^ 0x80;
881 }
882 c -= locallen; p += locallen;
883 }
884 /* used = ( samples * 16 bits size ) */
885 *used = max_in > ( max_out << 1) ? (max_out << 1) : max_in;
886 /* returned = ( samples * 8 bits size ) */
887 *returned = len;
888 }
889 else
890 {
891 /* 8 -> 16 */
892 /* max_in, max number of samples in ( 8 bits ) */
893 /* max_out >> 1, max number of samples out ( 16 bits ) */
894 /* len, number of samples that will be taken ( 8 bits )*/
895 /* c, count of samples remaining in buffer ( 8 bits )*/
896 /* p, count of samples already processed ( 8 bits )*/
897 len = max_in > (max_out >> 1) ? (max_out >> 1) : max_in;
898 c = len;
899 p = 0;
900 buf16 = (signed short *)(localbuf + localoffs);
901 while (c)
902 {
903 locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
904 if (copy_from_user(lbuf8,
905 userbuf+useroffs + p,
906 locallen))
907 return;
908 for (i = 0; i < locallen; i++)
909 {
910 buf16[p+i] = (~lbuf8[i] ^ 0x80) << 8;
911 }
912 c -= locallen; p += locallen;
913 }
914 /* used = ( samples * 8 bits size ) */
915 *used = len;
916 /* returned = ( samples * 16 bits size ) */
917 *returned = len << 1;
918 }
919}
920
921static void
922sb16_audio_mmap(int dev)
923{
924 sb_devc *devc = audio_devs[dev]->devc;
925 devc->fullduplex = 0;
926}
927
928static struct audio_driver sb1_audio_driver = /* SB1.x */
929{
930 .owner = THIS_MODULE,
931 .open = sb_audio_open,
932 .close = sb_audio_close,
933 .output_block = sb_set_output_parms,
934 .start_input = sb_set_input_parms,
935 .prepare_for_input = sb1_audio_prepare_for_input,
936 .prepare_for_output = sb1_audio_prepare_for_output,
937 .halt_io = sb1_audio_halt_xfer,
938 .trigger = sb1_audio_trigger,
939 .set_speed = sb1_audio_set_speed,
940 .set_bits = sb1_audio_set_bits,
941 .set_channels = sb1_audio_set_channels
942};
943
944static struct audio_driver sb20_audio_driver = /* SB2.0 */
945{
946 .owner = THIS_MODULE,
947 .open = sb_audio_open,
948 .close = sb_audio_close,
949 .output_block = sb_set_output_parms,
950 .start_input = sb_set_input_parms,
951 .prepare_for_input = sb1_audio_prepare_for_input,
952 .prepare_for_output = sb1_audio_prepare_for_output,
953 .halt_io = sb1_audio_halt_xfer,
954 .trigger = sb20_audio_trigger,
955 .set_speed = sb1_audio_set_speed,
956 .set_bits = sb1_audio_set_bits,
957 .set_channels = sb1_audio_set_channels
958};
959
960static struct audio_driver sb201_audio_driver = /* SB2.01 */
961{
962 .owner = THIS_MODULE,
963 .open = sb_audio_open,
964 .close = sb_audio_close,
965 .output_block = sb_set_output_parms,
966 .start_input = sb_set_input_parms,
967 .prepare_for_input = sb1_audio_prepare_for_input,
968 .prepare_for_output = sb1_audio_prepare_for_output,
969 .halt_io = sb1_audio_halt_xfer,
970 .trigger = sb20_audio_trigger,
971 .set_speed = sb201_audio_set_speed,
972 .set_bits = sb1_audio_set_bits,
973 .set_channels = sb1_audio_set_channels
974};
975
976static struct audio_driver sbpro_audio_driver = /* SB Pro */
977{
978 .owner = THIS_MODULE,
979 .open = sb_audio_open,
980 .close = sb_audio_close,
981 .output_block = sb_set_output_parms,
982 .start_input = sb_set_input_parms,
983 .prepare_for_input = sbpro_audio_prepare_for_input,
984 .prepare_for_output = sbpro_audio_prepare_for_output,
985 .halt_io = sb1_audio_halt_xfer,
986 .trigger = sb20_audio_trigger,
987 .set_speed = sbpro_audio_set_speed,
988 .set_bits = sb1_audio_set_bits,
989 .set_channels = sbpro_audio_set_channels
990};
991
992static struct audio_driver jazz16_audio_driver = /* Jazz16 and SM Wave */
993{
994 .owner = THIS_MODULE,
995 .open = sb_audio_open,
996 .close = sb_audio_close,
997 .output_block = sb_set_output_parms,
998 .start_input = sb_set_input_parms,
999 .prepare_for_input = sbpro_audio_prepare_for_input,
1000 .prepare_for_output = sbpro_audio_prepare_for_output,
1001 .halt_io = sb1_audio_halt_xfer,
1002 .trigger = sb20_audio_trigger,
1003 .set_speed = jazz16_audio_set_speed,
1004 .set_bits = sb16_audio_set_bits,
1005 .set_channels = sbpro_audio_set_channels
1006};
1007
1008static struct audio_driver sb16_audio_driver = /* SB16 */
1009{
1010 .owner = THIS_MODULE,
1011 .open = sb_audio_open,
1012 .close = sb_audio_close,
1013 .output_block = sb_set_output_parms,
1014 .start_input = sb_set_input_parms,
1015 .prepare_for_input = sb16_audio_prepare_for_input,
1016 .prepare_for_output = sb16_audio_prepare_for_output,
1017 .halt_io = sb1_audio_halt_xfer,
1018 .copy_user = sb16_copy_from_user,
1019 .trigger = sb16_audio_trigger,
1020 .set_speed = sb16_audio_set_speed,
1021 .set_bits = sb16_audio_set_bits,
1022 .set_channels = sbpro_audio_set_channels,
1023 .mmap = sb16_audio_mmap
1024};
1025
1026void sb_audio_init(sb_devc * devc, char *name, struct module *owner)
1027{
1028 int audio_flags = 0;
1029 int format_mask = AFMT_U8;
1030
1031 struct audio_driver *driver = &sb1_audio_driver;
1032
1033 switch (devc->model)
1034 {
1035 case MDL_SB1: /* SB1.0 or SB 1.5 */
1036 DDB(printk("Will use standard SB1.x driver\n"));
1037 audio_flags = DMA_HARDSTOP;
1038 break;
1039
1040 case MDL_SB2:
1041 DDB(printk("Will use SB2.0 driver\n"));
1042 audio_flags = DMA_AUTOMODE;
1043 driver = &sb20_audio_driver;
1044 break;
1045
1046 case MDL_SB201:
1047 DDB(printk("Will use SB2.01 (high speed) driver\n"));
1048 audio_flags = DMA_AUTOMODE;
1049 driver = &sb201_audio_driver;
1050 break;
1051
1052 case MDL_JAZZ:
1053 case MDL_SMW:
1054 DDB(printk("Will use Jazz16 driver\n"));
1055 audio_flags = DMA_AUTOMODE;
1056 format_mask |= AFMT_S16_LE;
1057 driver = &jazz16_audio_driver;
1058 break;
1059
1060 case MDL_ESS:
1061 DDB(printk("Will use ESS ES688/1688 driver\n"));
1062 driver = ess_audio_init (devc, &audio_flags, &format_mask);
1063 break;
1064
1065 case MDL_SB16:
1066 DDB(printk("Will use SB16 driver\n"));
1067 audio_flags = DMA_AUTOMODE;
1068 format_mask |= AFMT_S16_LE;
1069 if (devc->dma8 != devc->dma16 && devc->dma16 != -1)
1070 {
1071 audio_flags |= DMA_DUPLEX;
1072 devc->duplex = 1;
1073 }
1074 driver = &sb16_audio_driver;
1075 break;
1076
1077 default:
1078 DDB(printk("Will use SB Pro driver\n"));
1079 audio_flags = DMA_AUTOMODE;
1080 driver = &sbpro_audio_driver;
1081 }
1082
1083 if (owner)
1084 driver->owner = owner;
1085
1086 if ((devc->dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
1087 name,driver, sizeof(struct audio_driver),
1088 audio_flags, format_mask, devc,
1089 devc->dma8,
1090 devc->duplex ? devc->dma16 : devc->dma8)) < 0)
1091 {
1092 printk(KERN_ERR "Sound Blaster: unable to install audio.\n");
1093 return;
1094 }
1095 audio_devs[devc->dev]->mixer_dev = devc->my_mixerdev;
1096 audio_devs[devc->dev]->min_fragment = 5;
1097}
diff --git a/sound/oss/sb_card.c b/sound/oss/sb_card.c
deleted file mode 100644
index 2a92cfe6cfe9..000000000000
--- a/sound/oss/sb_card.c
+++ /dev/null
@@ -1,354 +0,0 @@
1/*
2 * sound/oss/sb_card.c
3 *
4 * Detection routine for the ISA Sound Blaster and compatible sound
5 * cards.
6 *
7 * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this
9 * software for more info.
10 *
11 * This is a complete rewrite of the detection routines. This was
12 * prompted by the PnP API change during v2.5 and the ugly state the
13 * code was in.
14 *
15 * Copyright (C) by Paul Laufer 2002. Based on code originally by
16 * Hannu Savolainen which was modified by many others over the
17 * years. Authors specifically mentioned in the previous version were:
18 * Daniel Stone, Alessandro Zummo, Jeff Garzik, Arnaldo Carvalho de
19 * Melo, Daniel Church, and myself.
20 *
21 * 02-05-2003 Original Release, Paul Laufer <paul@laufernet.com>
22 * 02-07-2003 Bug made it into first release. Take two.
23 */
24
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/slab.h>
28#include <linux/init.h>
29#include "sound_config.h"
30#include "sb_mixer.h"
31#include "sb.h"
32#ifdef CONFIG_PNP
33#include <linux/pnp.h>
34#endif /* CONFIG_PNP */
35#include "sb_card.h"
36
37MODULE_DESCRIPTION("OSS Soundblaster ISA PnP and legacy sound driver");
38MODULE_LICENSE("GPL");
39
40extern void *smw_free;
41
42static int __initdata mpu_io = 0;
43static int __initdata io = -1;
44static int __initdata irq = -1;
45static int __initdata dma = -1;
46static int __initdata dma16 = -1;
47static int __initdata type = 0; /* Can set this to a specific card type */
48static int __initdata esstype = 0; /* ESS chip type */
49static int __initdata acer = 0; /* Do acer notebook init? */
50static int __initdata sm_games = 0; /* Logitech soundman games? */
51
52static struct sb_card_config *legacy = NULL;
53
54#ifdef CONFIG_PNP
55static int pnp_registered;
56static int __initdata pnp = 1;
57/*
58static int __initdata uart401 = 0;
59*/
60#else
61static int __initdata pnp = 0;
62#endif
63
64module_param_hw(io, int, ioport, 000);
65MODULE_PARM_DESC(io, "Soundblaster i/o base address (0x220,0x240,0x260,0x280)");
66module_param_hw(irq, int, irq, 000);
67MODULE_PARM_DESC(irq, "IRQ (5,7,9,10)");
68module_param_hw(dma, int, dma, 000);
69MODULE_PARM_DESC(dma, "8-bit DMA channel (0,1,3)");
70module_param_hw(dma16, int, dma, 000);
71MODULE_PARM_DESC(dma16, "16-bit DMA channel (5,6,7)");
72module_param_hw(mpu_io, int, ioport, 000);
73MODULE_PARM_DESC(mpu_io, "MPU base address");
74module_param(type, int, 000);
75MODULE_PARM_DESC(type, "You can set this to specific card type (doesn't " \
76 "work with pnp)");
77module_param(sm_games, int, 000);
78MODULE_PARM_DESC(sm_games, "Enable support for Logitech soundman games " \
79 "(doesn't work with pnp)");
80module_param(esstype, int, 000);
81MODULE_PARM_DESC(esstype, "ESS chip type (doesn't work with pnp)");
82module_param(acer, int, 000);
83MODULE_PARM_DESC(acer, "Set this to detect cards in some ACER notebooks "\
84 "(doesn't work with pnp)");
85
86#ifdef CONFIG_PNP
87module_param(pnp, int, 000);
88MODULE_PARM_DESC(pnp, "Went set to 0 will disable detection using PnP. "\
89 "Default is 1.\n");
90/* Not done yet.... */
91/*
92module_param(uart401, int, 000);
93MODULE_PARM_DESC(uart401, "When set to 1, will attempt to detect and enable"\
94 "the mpu on some clones");
95*/
96#endif /* CONFIG_PNP */
97
98/* OSS subsystem card registration shared by PnP and legacy routines */
99static int sb_register_oss(struct sb_card_config *scc, struct sb_module_options *sbmo)
100{
101 if (!request_region(scc->conf.io_base, 16, "soundblaster")) {
102 printk(KERN_ERR "sb: ports busy.\n");
103 kfree(scc);
104 return -EBUSY;
105 }
106
107 if (!sb_dsp_detect(&scc->conf, 0, 0, sbmo)) {
108 release_region(scc->conf.io_base, 16);
109 printk(KERN_ERR "sb: Failed DSP Detect.\n");
110 kfree(scc);
111 return -ENODEV;
112 }
113 if(!sb_dsp_init(&scc->conf, THIS_MODULE)) {
114 printk(KERN_ERR "sb: Failed DSP init.\n");
115 kfree(scc);
116 return -ENODEV;
117 }
118 if(scc->mpucnf.io_base > 0) {
119 scc->mpu = 1;
120 printk(KERN_INFO "sb: Turning on MPU\n");
121 if(!probe_sbmpu(&scc->mpucnf, THIS_MODULE))
122 scc->mpu = 0;
123 }
124
125 return 1;
126}
127
128static void sb_unload(struct sb_card_config *scc)
129{
130 sb_dsp_unload(&scc->conf, 0);
131 if(scc->mpu)
132 unload_sbmpu(&scc->mpucnf);
133 kfree(scc);
134}
135
136/* Register legacy card with OSS subsystem */
137static int __init sb_init_legacy(void)
138{
139 struct sb_module_options sbmo = {0};
140
141 if((legacy = kzalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
142 printk(KERN_ERR "sb: Error: Could not allocate memory\n");
143 return -ENOMEM;
144 }
145
146 legacy->conf.io_base = io;
147 legacy->conf.irq = irq;
148 legacy->conf.dma = dma;
149 legacy->conf.dma2 = dma16;
150 legacy->conf.card_subtype = type;
151
152 legacy->mpucnf.io_base = mpu_io;
153 legacy->mpucnf.irq = -1;
154 legacy->mpucnf.dma = -1;
155 legacy->mpucnf.dma2 = -1;
156
157 sbmo.esstype = esstype;
158 sbmo.sm_games = sm_games;
159 sbmo.acer = acer;
160
161 return sb_register_oss(legacy, &sbmo);
162}
163
164#ifdef CONFIG_PNP
165
166/* Populate the OSS subsystem structures with information from PnP */
167static void sb_dev2cfg(struct pnp_dev *dev, struct sb_card_config *scc)
168{
169 scc->conf.io_base = -1;
170 scc->conf.irq = -1;
171 scc->conf.dma = -1;
172 scc->conf.dma2 = -1;
173 scc->mpucnf.io_base = -1;
174 scc->mpucnf.irq = -1;
175 scc->mpucnf.dma = -1;
176 scc->mpucnf.dma2 = -1;
177
178 /* All clones layout their PnP tables differently and some use
179 different logical devices for the MPU */
180 if(!strncmp("CTL",scc->card_id,3)) {
181 scc->conf.io_base = pnp_port_start(dev,0);
182 scc->conf.irq = pnp_irq(dev,0);
183 scc->conf.dma = pnp_dma(dev,0);
184 scc->conf.dma2 = pnp_dma(dev,1);
185 scc->mpucnf.io_base = pnp_port_start(dev,1);
186 return;
187 }
188 if(!strncmp("tBA",scc->card_id,3)) {
189 scc->conf.io_base = pnp_port_start(dev,0);
190 scc->conf.irq = pnp_irq(dev,0);
191 scc->conf.dma = pnp_dma(dev,0);
192 scc->conf.dma2 = pnp_dma(dev,1);
193 return;
194 }
195 if(!strncmp("ESS",scc->card_id,3)) {
196 scc->conf.io_base = pnp_port_start(dev,0);
197 scc->conf.irq = pnp_irq(dev,0);
198 scc->conf.dma = pnp_dma(dev,0);
199 scc->conf.dma2 = pnp_dma(dev,1);
200 scc->mpucnf.io_base = pnp_port_start(dev,2);
201 return;
202 }
203 if(!strncmp("CMI",scc->card_id,3)) {
204 scc->conf.io_base = pnp_port_start(dev,0);
205 scc->conf.irq = pnp_irq(dev,0);
206 scc->conf.dma = pnp_dma(dev,0);
207 scc->conf.dma2 = pnp_dma(dev,1);
208 return;
209 }
210 if(!strncmp("RWB",scc->card_id,3)) {
211 scc->conf.io_base = pnp_port_start(dev,0);
212 scc->conf.irq = pnp_irq(dev,0);
213 scc->conf.dma = pnp_dma(dev,0);
214 return;
215 }
216 if(!strncmp("ALS",scc->card_id,3)) {
217 if(!strncmp("ALS0007",scc->card_id,7)) {
218 scc->conf.io_base = pnp_port_start(dev,0);
219 scc->conf.irq = pnp_irq(dev,0);
220 scc->conf.dma = pnp_dma(dev,0);
221 } else {
222 scc->conf.io_base = pnp_port_start(dev,0);
223 scc->conf.irq = pnp_irq(dev,0);
224 scc->conf.dma = pnp_dma(dev,1);
225 scc->conf.dma2 = pnp_dma(dev,0);
226 }
227 return;
228 }
229 if(!strncmp("RTL",scc->card_id,3)) {
230 scc->conf.io_base = pnp_port_start(dev,0);
231 scc->conf.irq = pnp_irq(dev,0);
232 scc->conf.dma = pnp_dma(dev,1);
233 scc->conf.dma2 = pnp_dma(dev,0);
234 }
235}
236
237static unsigned int sb_pnp_devices;
238
239/* Probe callback function for the PnP API */
240static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_device_id *card_id)
241{
242 struct sb_card_config *scc;
243 struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
244 struct pnp_dev *dev = pnp_request_card_device(card, card_id->devs[0].id, NULL);
245
246 if(!dev){
247 return -EBUSY;
248 }
249
250 if((scc = kzalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
251 printk(KERN_ERR "sb: Error: Could not allocate memory\n");
252 return -ENOMEM;
253 }
254
255 printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
256 "%s, Device PnP id = %s\n", card->card->name, card_id->id,
257 dev->id->id);
258
259 scc->card_id = card_id->id;
260 scc->dev_id = dev->id->id;
261 sb_dev2cfg(dev, scc);
262
263 printk(KERN_INFO "sb: PnP: Detected at: io=0x%x, irq=%d, " \
264 "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
265 scc->conf.dma, scc->conf.dma2);
266
267 pnp_set_card_drvdata(card, scc);
268 sb_pnp_devices++;
269
270 return sb_register_oss(scc, &sbmo);
271}
272
273static void sb_pnp_remove(struct pnp_card_link *card)
274{
275 struct sb_card_config *scc = pnp_get_card_drvdata(card);
276
277 if(!scc)
278 return;
279
280 printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
281
282 sb_unload(scc);
283}
284
285static struct pnp_card_driver sb_pnp_driver = {
286 .name = "OSS SndBlstr", /* 16 character limit */
287 .id_table = sb_pnp_card_table,
288 .probe = sb_pnp_probe,
289 .remove = sb_pnp_remove,
290};
291MODULE_DEVICE_TABLE(pnp_card, sb_pnp_card_table);
292#endif /* CONFIG_PNP */
293
294static void sb_unregister_all(void)
295{
296#ifdef CONFIG_PNP
297 if (pnp_registered)
298 pnp_unregister_card_driver(&sb_pnp_driver);
299#endif
300}
301
302static int __init sb_init(void)
303{
304 int lres = 0;
305 int pres = 0;
306
307 printk(KERN_INFO "sb: Init: Starting Probe...\n");
308
309 if(io != -1 && irq != -1 && dma != -1) {
310 printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
311 "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
312 lres = sb_init_legacy();
313 } else if((io != -1 || irq != -1 || dma != -1) ||
314 (!pnp && (io == -1 && irq == -1 && dma == -1)))
315 printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
316 "must be set for legacy cards.\n");
317
318#ifdef CONFIG_PNP
319 if(pnp) {
320 int err = pnp_register_card_driver(&sb_pnp_driver);
321 if (!err)
322 pnp_registered = 1;
323 pres = sb_pnp_devices;
324 }
325#endif
326 printk(KERN_INFO "sb: Init: Done\n");
327
328 /* If either PnP or Legacy registered a card then return
329 * success */
330 if (pres == 0 && lres <= 0) {
331 sb_unregister_all();
332 return -ENODEV;
333 }
334 return 0;
335}
336
337static void __exit sb_exit(void)
338{
339 printk(KERN_INFO "sb: Unloading...\n");
340
341 /* Unload legacy card */
342 if (legacy) {
343 printk (KERN_INFO "sb: Unloading legacy card\n");
344 sb_unload(legacy);
345 }
346
347 sb_unregister_all();
348
349 vfree(smw_free);
350 smw_free = NULL;
351}
352
353module_init(sb_init);
354module_exit(sb_exit);
diff --git a/sound/oss/sb_card.h b/sound/oss/sb_card.h
deleted file mode 100644
index 5535cff800df..000000000000
--- a/sound/oss/sb_card.h
+++ /dev/null
@@ -1,149 +0,0 @@
1/*
2 * sound/oss/sb_card.h
3 *
4 * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
5 * Version 2 (June 1991). See the "COPYING" file distributed with this
6 * software for more info.
7 *
8 * 02-05-2002 Original Release, Paul Laufer <paul@laufernet.com>
9 */
10
11struct sb_card_config {
12 struct address_info conf;
13 struct address_info mpucnf;
14 const char *card_id;
15 const char *dev_id;
16 int mpu;
17};
18
19#ifdef CONFIG_PNP
20
21/*
22 * SoundBlaster PnP tables and structures.
23 */
24
25/* Card PnP ID Table */
26static struct pnp_card_device_id sb_pnp_card_table[] = {
27 /* Sound Blaster 16 */
28 {.id = "CTL0024", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
29 /* Sound Blaster 16 */
30 {.id = "CTL0025", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
31 /* Sound Blaster 16 */
32 {.id = "CTL0026", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
33 /* Sound Blaster 16 */
34 {.id = "CTL0027", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
35 /* Sound Blaster 16 */
36 {.id = "CTL0028", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
37 /* Sound Blaster 16 */
38 {.id = "CTL0029", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
39 /* Sound Blaster 16 */
40 {.id = "CTL002a", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
41 /* Sound Blaster 16 */
42 {.id = "CTL002b", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
43 /* Sound Blaster 16 */
44 {.id = "CTL002c", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
45 /* Sound Blaster 16 */
46 {.id = "CTL00ed", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
47 /* Sound Blaster 16 */
48 {.id = "CTL0086", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
49 /* Sound Blaster Vibra16S */
50 {.id = "CTL0051", .driver_data = 0, .devs = { {.id="CTL0001"}, } },
51 /* Sound Blaster Vibra16C */
52 {.id = "CTL0070", .driver_data = 0, .devs = { {.id="CTL0001"}, } },
53 /* Sound Blaster Vibra16CL */
54 {.id = "CTL0080", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
55 /* Sound Blaster Vibra16CL */
56 {.id = "CTL00F0", .driver_data = 0, .devs = { {.id="CTL0043"}, } },
57 /* Sound Blaster AWE 32 */
58 {.id = "CTL0039", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
59 /* Sound Blaster AWE 32 */
60 {.id = "CTL0042", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
61 /* Sound Blaster AWE 32 */
62 {.id = "CTL0043", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
63 /* Sound Blaster AWE 32 */
64 {.id = "CTL0044", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
65 /* Sound Blaster AWE 32 */
66 {.id = "CTL0045", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
67 /* Sound Blaster AWE 32 */
68 {.id = "CTL0046", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
69 /* Sound Blaster AWE 32 */
70 {.id = "CTL0047", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
71 /* Sound Blaster AWE 32 */
72 {.id = "CTL0048", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
73 /* Sound Blaster AWE 32 */
74 {.id = "CTL0054", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
75 /* Sound Blaster AWE 32 */
76 {.id = "CTL009C", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
77 /* Createive SB32 PnP */
78 {.id = "CTL009F", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
79 /* Sound Blaster AWE 64 */
80 {.id = "CTL009D", .driver_data = 0, .devs = { {.id="CTL0042"}, } },
81 /* Sound Blaster AWE 64 Gold */
82 {.id = "CTL009E", .driver_data = 0, .devs = { {.id="CTL0044"}, } },
83 /* Sound Blaster AWE 64 Gold */
84 {.id = "CTL00B2", .driver_data = 0, .devs = { {.id="CTL0044"}, } },
85 /* Sound Blaster AWE 64 */
86 {.id = "CTL00C1", .driver_data = 0, .devs = { {.id="CTL0042"}, } },
87 /* Sound Blaster AWE 64 */
88 {.id = "CTL00C3", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
89 /* Sound Blaster AWE 64 */
90 {.id = "CTL00C5", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
91 /* Sound Blaster AWE 64 */
92 {.id = "CTL00C7", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
93 /* Sound Blaster AWE 64 */
94 {.id = "CTL00E4", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
95 /* Sound Blaster AWE 64 */
96 {.id = "CTL00E9", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
97 /* ESS 1868 */
98 {.id = "ESS0968", .driver_data = 0, .devs = { {.id="ESS0968"}, } },
99 /* ESS 1868 */
100 {.id = "ESS1868", .driver_data = 0, .devs = { {.id="ESS1868"}, } },
101 /* ESS 1868 */
102 {.id = "ESS1868", .driver_data = 0, .devs = { {.id="ESS8611"}, } },
103 /* ESS 1869 PnP AudioDrive */
104 {.id = "ESS0003", .driver_data = 0, .devs = { {.id="ESS1869"}, } },
105 /* ESS 1869 */
106 {.id = "ESS1869", .driver_data = 0, .devs = { {.id="ESS1869"}, } },
107 /* ESS 1878 */
108 {.id = "ESS1878", .driver_data = 0, .devs = { {.id="ESS1878"}, } },
109 /* ESS 1879 */
110 {.id = "ESS1879", .driver_data = 0, .devs = { {.id="ESS1879"}, } },
111 /* CMI 8330 SoundPRO */
112 {.id = "CMI0001", .driver_data = 0, .devs = { {.id="@X@0001"},
113 {.id="@H@0001"},
114 {.id="@@@0001"}, } },
115 /* Diamond DT0197H */
116 {.id = "RWR1688", .driver_data = 0, .devs = { {.id="@@@0001"},
117 {.id="@X@0001"},
118 {.id="@H@0001"}, } },
119 /* ALS007 */
120 {.id = "ALS0007", .driver_data = 0, .devs = { {.id="@@@0001"},
121 {.id="@X@0001"},
122 {.id="@H@0001"}, } },
123 /* ALS100 */
124 {.id = "ALS0001", .driver_data = 0, .devs = { {.id="@@@0001"},
125 {.id="@X@0001"},
126 {.id="@H@0001"}, } },
127 /* ALS110 */
128 {.id = "ALS0110", .driver_data = 0, .devs = { {.id="@@@1001"},
129 {.id="@X@1001"},
130 {.id="@H@0001"}, } },
131 /* ALS120 */
132 {.id = "ALS0120", .driver_data = 0, .devs = { {.id="@@@2001"},
133 {.id="@X@2001"},
134 {.id="@H@0001"}, } },
135 /* ALS200 */
136 {.id = "ALS0200", .driver_data = 0, .devs = { {.id="@@@0020"},
137 {.id="@X@0030"},
138 {.id="@H@0001"}, } },
139 /* ALS200 */
140 {.id = "RTL3000", .driver_data = 0, .devs = { {.id="@@@2001"},
141 {.id="@X@2001"},
142 {.id="@H@0001"}, } },
143 /* Sound Blaster 16 (Virtual PC 2004) */
144 {.id = "tBA03b0", .driver_data = 0, .devs = { {.id="PNPb003"}, } },
145 /* -end- */
146 {.id = "", }
147};
148
149#endif
diff --git a/sound/oss/sb_common.c b/sound/oss/sb_common.c
deleted file mode 100644
index 3d50fb4236ed..000000000000
--- a/sound/oss/sb_common.c
+++ /dev/null
@@ -1,1287 +0,0 @@
1/*
2 * sound/oss/sb_common.c
3 *
4 * Common routines for Sound Blaster compatible cards.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Daniel J. Rodriksson: Modified sbintr to handle 8 and 16 bit interrupts
15 * for full duplex support ( only sb16 by now )
16 * Rolf Fokkens: Added (BETA?) support for ES1887 chips.
17 * (fokkensr@vertis.nl) Which means: You can adjust the recording levels.
18 *
19 * 2000/01/18 - separated sb_card and sb_common -
20 * Jeff Garzik <jgarzik@pobox.com>
21 *
22 * 2000/09/18 - got rid of attach_uart401
23 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
24 *
25 * 2001/01/26 - replaced CLI/STI with spinlocks
26 * Chris Rankin <rankinc@zipworld.com.au>
27 */
28
29#include <linux/init.h>
30#include <linux/interrupt.h>
31#include <linux/module.h>
32#include <linux/delay.h>
33#include <linux/spinlock.h>
34#include <linux/slab.h>
35
36#include "sound_config.h"
37#include "sound_firmware.h"
38
39#include "mpu401.h"
40
41#include "sb_mixer.h"
42#include "sb.h"
43#include "sb_ess.h"
44
45/*
46 * global module flag
47 */
48
49int sb_be_quiet;
50
51static sb_devc *detected_devc; /* For communication from probe to init */
52static sb_devc *last_devc; /* For MPU401 initialization */
53
54static unsigned char jazz_irq_bits[] = {
55 0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6
56};
57
58static unsigned char jazz_dma_bits[] = {
59 0, 1, 0, 2, 0, 3, 0, 4
60};
61
62void *smw_free;
63
64/*
65 * Jazz16 chipset specific control variables
66 */
67
68static int jazz16_base; /* Not detected */
69static unsigned char jazz16_bits; /* I/O relocation bits */
70static DEFINE_SPINLOCK(jazz16_lock);
71
72/*
73 * Logitech Soundman Wave specific initialization code
74 */
75
76#ifdef SMW_MIDI0001_INCLUDED
77#include "smw-midi0001.h"
78#else
79static unsigned char *smw_ucode;
80static int smw_ucodeLen;
81
82#endif
83
84static sb_devc *last_sb; /* Last sb loaded */
85
86int sb_dsp_command(sb_devc * devc, unsigned char val)
87{
88 int i;
89 unsigned long limit;
90
91 limit = jiffies + HZ / 10; /* Timeout */
92
93 /*
94 * Note! the i<500000 is an emergency exit. The sb_dsp_command() is sometimes
95 * called while interrupts are disabled. This means that the timer is
96 * disabled also. However the timeout situation is a abnormal condition.
97 * Normally the DSP should be ready to accept commands after just couple of
98 * loops.
99 */
100
101 for (i = 0; i < 500000 && (limit-jiffies)>0; i++)
102 {
103 if ((inb(DSP_STATUS) & 0x80) == 0)
104 {
105 outb((val), DSP_COMMAND);
106 return 1;
107 }
108 }
109 printk(KERN_WARNING "Sound Blaster: DSP command(%x) timeout.\n", val);
110 return 0;
111}
112
113int sb_dsp_get_byte(sb_devc * devc)
114{
115 int i;
116
117 for (i = 1000; i; i--)
118 {
119 if (inb(DSP_DATA_AVAIL) & 0x80)
120 return inb(DSP_READ);
121 }
122 return 0xffff;
123}
124
125static void sb_intr (sb_devc *devc)
126{
127 int status;
128 unsigned char src = 0xff;
129
130 if (devc->model == MDL_SB16)
131 {
132 src = sb_getmixer(devc, IRQ_STAT); /* Interrupt source register */
133
134 if (src & 4) /* MPU401 interrupt */
135 if(devc->midi_irq_cookie)
136 uart401intr(devc->irq, devc->midi_irq_cookie);
137
138 if (!(src & 3))
139 return; /* Not a DSP interrupt */
140 }
141 if (devc->intr_active && (!devc->fullduplex || (src & 0x01)))
142 {
143 switch (devc->irq_mode)
144 {
145 case IMODE_OUTPUT:
146 DMAbuf_outputintr(devc->dev, 1);
147 break;
148
149 case IMODE_INPUT:
150 DMAbuf_inputintr(devc->dev);
151 break;
152
153 case IMODE_INIT:
154 break;
155
156 case IMODE_MIDI:
157 sb_midi_interrupt(devc);
158 break;
159
160 default:
161 /* printk(KERN_WARNING "Sound Blaster: Unexpected interrupt\n"); */
162 ;
163 }
164 }
165 else if (devc->intr_active_16 && (src & 0x02))
166 {
167 switch (devc->irq_mode_16)
168 {
169 case IMODE_OUTPUT:
170 DMAbuf_outputintr(devc->dev, 1);
171 break;
172
173 case IMODE_INPUT:
174 DMAbuf_inputintr(devc->dev);
175 break;
176
177 case IMODE_INIT:
178 break;
179
180 default:
181 /* printk(KERN_WARNING "Sound Blaster: Unexpected interrupt\n"); */
182 ;
183 }
184 }
185 /*
186 * Acknowledge interrupts
187 */
188
189 if (src & 0x01)
190 status = inb(DSP_DATA_AVAIL);
191
192 if (devc->model == MDL_SB16 && src & 0x02)
193 status = inb(DSP_DATA_AVL16);
194}
195
196static void pci_intr(sb_devc *devc)
197{
198 int src = inb(devc->pcibase+0x1A);
199 src&=3;
200 if(src)
201 sb_intr(devc);
202}
203
204static irqreturn_t sbintr(int irq, void *dev_id)
205{
206 sb_devc *devc = dev_id;
207
208 devc->irq_ok = 1;
209
210 switch (devc->model) {
211 case MDL_ESSPCI:
212 pci_intr (devc);
213 break;
214
215 case MDL_ESS:
216 ess_intr (devc);
217 break;
218 default:
219 sb_intr (devc);
220 break;
221 }
222 return IRQ_HANDLED;
223}
224
225int sb_dsp_reset(sb_devc * devc)
226{
227 int loopc;
228
229 if (devc->model == MDL_ESS) return ess_dsp_reset (devc);
230
231 /* This is only for non-ESS chips */
232
233 outb(1, DSP_RESET);
234
235 udelay(10);
236 outb(0, DSP_RESET);
237 udelay(30);
238
239 for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
240
241 if (inb(DSP_READ) != 0xAA)
242 {
243 DDB(printk("sb: No response to RESET\n"));
244 return 0; /* Sorry */
245 }
246
247 return 1;
248}
249
250static void dsp_get_vers(sb_devc * devc)
251{
252 int i;
253
254 unsigned long flags;
255
256 DDB(printk("Entered dsp_get_vers()\n"));
257 spin_lock_irqsave(&devc->lock, flags);
258 devc->major = devc->minor = 0;
259 sb_dsp_command(devc, 0xe1); /* Get version */
260
261 for (i = 100000; i; i--)
262 {
263 if (inb(DSP_DATA_AVAIL) & 0x80)
264 {
265 if (devc->major == 0)
266 devc->major = inb(DSP_READ);
267 else
268 {
269 devc->minor = inb(DSP_READ);
270 break;
271 }
272 }
273 }
274 spin_unlock_irqrestore(&devc->lock, flags);
275 DDB(printk("DSP version %d.%02d\n", devc->major, devc->minor));
276}
277
278static int sb16_set_dma_hw(sb_devc * devc)
279{
280 int bits;
281
282 if (devc->dma8 != 0 && devc->dma8 != 1 && devc->dma8 != 3)
283 {
284 printk(KERN_ERR "SB16: Invalid 8 bit DMA (%d)\n", devc->dma8);
285 return 0;
286 }
287 bits = (1 << devc->dma8);
288
289 if (devc->dma16 >= 5 && devc->dma16 <= 7)
290 bits |= (1 << devc->dma16);
291
292 sb_setmixer(devc, DMA_NR, bits);
293 return 1;
294}
295
296static void sb16_set_mpu_port(sb_devc * devc, struct address_info *hw_config)
297{
298 /*
299 * This routine initializes new MIDI port setup register of SB Vibra (CT2502).
300 */
301 unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
302
303 switch (hw_config->io_base)
304 {
305 case 0x300:
306 sb_setmixer(devc, 0x84, bits | 0x04);
307 break;
308
309 case 0x330:
310 sb_setmixer(devc, 0x84, bits | 0x00);
311 break;
312
313 default:
314 sb_setmixer(devc, 0x84, bits | 0x02); /* Disable MPU */
315 printk(KERN_ERR "SB16: Invalid MIDI I/O port %x\n", hw_config->io_base);
316 }
317}
318
319static int sb16_set_irq_hw(sb_devc * devc, int level)
320{
321 int ival;
322
323 switch (level)
324 {
325 case 5:
326 ival = 2;
327 break;
328 case 7:
329 ival = 4;
330 break;
331 case 9:
332 ival = 1;
333 break;
334 case 10:
335 ival = 8;
336 break;
337 default:
338 printk(KERN_ERR "SB16: Invalid IRQ%d\n", level);
339 return 0;
340 }
341 sb_setmixer(devc, IRQ_NR, ival);
342 return 1;
343}
344
345static void relocate_Jazz16(sb_devc * devc, struct address_info *hw_config)
346{
347 unsigned char bits = 0;
348 unsigned long flags;
349
350 if (jazz16_base != 0 && jazz16_base != hw_config->io_base)
351 return;
352
353 switch (hw_config->io_base)
354 {
355 case 0x220:
356 bits = 1;
357 break;
358 case 0x240:
359 bits = 2;
360 break;
361 case 0x260:
362 bits = 3;
363 break;
364 default:
365 return;
366 }
367 bits = jazz16_bits = bits << 5;
368 jazz16_base = hw_config->io_base;
369
370 /*
371 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
372 */
373 spin_lock_irqsave(&jazz16_lock, flags);
374 outb((0xAF), 0x201);
375 outb((0x50), 0x201);
376 outb((bits), 0x201);
377 spin_unlock_irqrestore(&jazz16_lock, flags);
378}
379
380static int init_Jazz16(sb_devc * devc, struct address_info *hw_config)
381{
382 char name[100];
383 /*
384 * First try to check that the card has Jazz16 chip. It identifies itself
385 * by returning 0x12 as response to DSP command 0xfa.
386 */
387
388 if (!sb_dsp_command(devc, 0xfa))
389 return 0;
390
391 if (sb_dsp_get_byte(devc) != 0x12)
392 return 0;
393
394 /*
395 * OK so far. Now configure the IRQ and DMA channel used by the card.
396 */
397 if (hw_config->irq < 1 || hw_config->irq > 15 || jazz_irq_bits[hw_config->irq] == 0)
398 {
399 printk(KERN_ERR "Jazz16: Invalid interrupt (IRQ%d)\n", hw_config->irq);
400 return 0;
401 }
402 if (hw_config->dma < 0 || hw_config->dma > 3 || jazz_dma_bits[hw_config->dma] == 0)
403 {
404 printk(KERN_ERR "Jazz16: Invalid 8 bit DMA (DMA%d)\n", hw_config->dma);
405 return 0;
406 }
407 if (hw_config->dma2 < 0)
408 {
409 printk(KERN_ERR "Jazz16: No 16 bit DMA channel defined\n");
410 return 0;
411 }
412 if (hw_config->dma2 < 5 || hw_config->dma2 > 7 || jazz_dma_bits[hw_config->dma2] == 0)
413 {
414 printk(KERN_ERR "Jazz16: Invalid 16 bit DMA (DMA%d)\n", hw_config->dma2);
415 return 0;
416 }
417 devc->dma16 = hw_config->dma2;
418
419 if (!sb_dsp_command(devc, 0xfb))
420 return 0;
421
422 if (!sb_dsp_command(devc, jazz_dma_bits[hw_config->dma] |
423 (jazz_dma_bits[hw_config->dma2] << 4)))
424 return 0;
425
426 if (!sb_dsp_command(devc, jazz_irq_bits[hw_config->irq]))
427 return 0;
428
429 /*
430 * Now we have configured a standard Jazz16 device.
431 */
432 devc->model = MDL_JAZZ;
433 strcpy(name, "Jazz16");
434
435 hw_config->name = "Jazz16";
436 devc->caps |= SB_NO_MIDI;
437 return 1;
438}
439
440static void relocate_ess1688(sb_devc * devc)
441{
442 unsigned char bits;
443
444 switch (devc->base)
445 {
446 case 0x220:
447 bits = 0x04;
448 break;
449 case 0x230:
450 bits = 0x05;
451 break;
452 case 0x240:
453 bits = 0x06;
454 break;
455 case 0x250:
456 bits = 0x07;
457 break;
458 default:
459 return; /* Wrong port */
460 }
461
462 DDB(printk("Doing ESS1688 address selection\n"));
463
464 /*
465 * ES1688 supports two alternative ways for software address config.
466 * First try the so called Read-Sequence-Key method.
467 */
468
469 /* Reset the sequence logic */
470 inb(0x229);
471 inb(0x229);
472 inb(0x229);
473
474 /* Perform the read sequence */
475 inb(0x22b);
476 inb(0x229);
477 inb(0x22b);
478 inb(0x229);
479 inb(0x229);
480 inb(0x22b);
481 inb(0x229);
482
483 /* Select the base address by reading from it. Then probe using the port. */
484 inb(devc->base);
485 if (sb_dsp_reset(devc)) /* Bingo */
486 return;
487
488#if 0 /* This causes system lockups (Nokia 386/25 at least) */
489 /*
490 * The last resort is the system control register method.
491 */
492
493 outb((0x00), 0xfb); /* 0xFB is the unlock register */
494 outb((0x00), 0xe0); /* Select index 0 */
495 outb((bits), 0xe1); /* Write the config bits */
496 outb((0x00), 0xf9); /* 0xFB is the lock register */
497#endif
498}
499
500int sb_dsp_detect(struct address_info *hw_config, int pci, int pciio, struct sb_module_options *sbmo)
501{
502 sb_devc sb_info;
503 sb_devc *devc = &sb_info;
504
505 memset((char *) &sb_info, 0, sizeof(sb_info)); /* Zero everything */
506
507 /* Copy module options in place */
508 if(sbmo) memcpy(&devc->sbmo, sbmo, sizeof(struct sb_module_options));
509
510 sb_info.my_mididev = -1;
511 sb_info.my_mixerdev = -1;
512 sb_info.dev = -1;
513
514 /*
515 * Initialize variables
516 */
517
518 DDB(printk("sb_dsp_detect(%x) entered\n", hw_config->io_base));
519
520 spin_lock_init(&devc->lock);
521 devc->type = hw_config->card_subtype;
522
523 devc->base = hw_config->io_base;
524 devc->irq = hw_config->irq;
525 devc->dma8 = hw_config->dma;
526
527 devc->dma16 = -1;
528 devc->pcibase = pciio;
529
530 if(pci == SB_PCI_ESSMAESTRO)
531 {
532 devc->model = MDL_ESSPCI;
533 devc->caps |= SB_PCI_IRQ;
534 hw_config->driver_use_1 |= SB_PCI_IRQ;
535 hw_config->card_subtype = MDL_ESSPCI;
536 }
537
538 if(pci == SB_PCI_YAMAHA)
539 {
540 devc->model = MDL_YMPCI;
541 devc->caps |= SB_PCI_IRQ;
542 hw_config->driver_use_1 |= SB_PCI_IRQ;
543 hw_config->card_subtype = MDL_YMPCI;
544
545 printk("Yamaha PCI mode.\n");
546 }
547
548 if (devc->sbmo.acer)
549 {
550 unsigned long flags;
551
552 spin_lock_irqsave(&devc->lock, flags);
553 inb(devc->base + 0x09);
554 inb(devc->base + 0x09);
555 inb(devc->base + 0x09);
556 inb(devc->base + 0x0b);
557 inb(devc->base + 0x09);
558 inb(devc->base + 0x0b);
559 inb(devc->base + 0x09);
560 inb(devc->base + 0x09);
561 inb(devc->base + 0x0b);
562 inb(devc->base + 0x09);
563 inb(devc->base + 0x00);
564 spin_unlock_irqrestore(&devc->lock, flags);
565 }
566 /*
567 * Detect the device
568 */
569
570 if (sb_dsp_reset(devc))
571 dsp_get_vers(devc);
572 else
573 devc->major = 0;
574
575 if (devc->type == 0 || devc->type == MDL_JAZZ || devc->type == MDL_SMW)
576 if (devc->major == 0 || (devc->major == 3 && devc->minor == 1))
577 relocate_Jazz16(devc, hw_config);
578
579 if (devc->major == 0 && (devc->type == MDL_ESS || devc->type == 0))
580 relocate_ess1688(devc);
581
582 if (!sb_dsp_reset(devc))
583 {
584 DDB(printk("SB reset failed\n"));
585#ifdef MODULE
586 printk(KERN_INFO "sb: dsp reset failed.\n");
587#endif
588 return 0;
589 }
590 if (devc->major == 0)
591 dsp_get_vers(devc);
592
593 if (devc->major == 3 && devc->minor == 1)
594 {
595 if (devc->type == MDL_AZTECH) /* SG Washington? */
596 {
597 if (sb_dsp_command(devc, 0x09))
598 if (sb_dsp_command(devc, 0x00)) /* Enter WSS mode */
599 {
600 int i;
601
602 /* Have some delay */
603 for (i = 0; i < 10000; i++)
604 inb(DSP_DATA_AVAIL);
605 devc->caps = SB_NO_AUDIO | SB_NO_MIDI; /* Mixer only */
606 devc->model = MDL_AZTECH;
607 }
608 }
609 }
610
611 if(devc->type == MDL_ESSPCI)
612 devc->model = MDL_ESSPCI;
613
614 if(devc->type == MDL_YMPCI)
615 {
616 printk("YMPCI selected\n");
617 devc->model = MDL_YMPCI;
618 }
619
620 /*
621 * Save device information for sb_dsp_init()
622 */
623
624
625 detected_devc = kmemdup(devc, sizeof(sb_devc), GFP_KERNEL);
626 if (detected_devc == NULL)
627 {
628 printk(KERN_ERR "sb: Can't allocate memory for device information\n");
629 return 0;
630 }
631 MDB(printk(KERN_INFO "SB %d.%02d detected OK (%x)\n", devc->major, devc->minor, hw_config->io_base));
632 return 1;
633}
634
635int sb_dsp_init(struct address_info *hw_config, struct module *owner)
636{
637 sb_devc *devc;
638 char name[100];
639 extern int sb_be_quiet;
640 int mixer22, mixer30;
641
642/*
643 * Check if we had detected a SB device earlier
644 */
645 DDB(printk("sb_dsp_init(%x) entered\n", hw_config->io_base));
646 name[0] = 0;
647
648 if (detected_devc == NULL)
649 {
650 MDB(printk("No detected device\n"));
651 return 0;
652 }
653 devc = detected_devc;
654 detected_devc = NULL;
655
656 if (devc->base != hw_config->io_base)
657 {
658 DDB(printk("I/O port mismatch\n"));
659 release_region(devc->base, 16);
660 return 0;
661 }
662 /*
663 * Now continue initialization of the device
664 */
665
666 devc->caps = hw_config->driver_use_1;
667
668 if (!((devc->caps & SB_NO_AUDIO) && (devc->caps & SB_NO_MIDI)) && hw_config->irq > 0)
669 { /* IRQ setup */
670
671 /*
672 * ESS PCI cards do shared PCI IRQ stuff. Since they
673 * will get shared PCI irq lines we must cope.
674 */
675
676 int i=(devc->caps&SB_PCI_IRQ)?IRQF_SHARED:0;
677
678 if (request_irq(hw_config->irq, sbintr, i, "soundblaster", devc) < 0)
679 {
680 printk(KERN_ERR "SB: Can't allocate IRQ%d\n", hw_config->irq);
681 release_region(devc->base, 16);
682 return 0;
683 }
684 devc->irq_ok = 0;
685
686 if (devc->major == 4)
687 if (!sb16_set_irq_hw(devc, devc->irq)) /* Unsupported IRQ */
688 {
689 free_irq(devc->irq, devc);
690 release_region(devc->base, 16);
691 return 0;
692 }
693 if ((devc->type == 0 || devc->type == MDL_ESS) &&
694 devc->major == 3 && devc->minor == 1)
695 { /* Handle various chipsets which claim they are SB Pro compatible */
696 if ((devc->type != 0 && devc->type != MDL_ESS) ||
697 !ess_init(devc, hw_config))
698 {
699 if ((devc->type != 0 && devc->type != MDL_JAZZ &&
700 devc->type != MDL_SMW) || !init_Jazz16(devc, hw_config))
701 {
702 DDB(printk("This is a genuine SB Pro\n"));
703 }
704 }
705 }
706 if (devc->major == 4 && devc->minor <= 11 ) /* Won't work */
707 devc->irq_ok = 1;
708 else
709 {
710 int n;
711
712 for (n = 0; n < 3 && devc->irq_ok == 0; n++)
713 {
714 if (sb_dsp_command(devc, 0xf2)) /* Cause interrupt immediately */
715 {
716 int i;
717
718 for (i = 0; !devc->irq_ok && i < 10000; i++);
719 }
720 }
721 if (!devc->irq_ok)
722 printk(KERN_WARNING "sb: Interrupt test on IRQ%d failed - Probable IRQ conflict\n", devc->irq);
723 else
724 {
725 DDB(printk("IRQ test OK (IRQ%d)\n", devc->irq));
726 }
727 }
728 } /* IRQ setup */
729
730 last_sb = devc;
731
732 switch (devc->major)
733 {
734 case 1: /* SB 1.0 or 1.5 */
735 devc->model = hw_config->card_subtype = MDL_SB1;
736 break;
737
738 case 2: /* SB 2.x */
739 if (devc->minor == 0)
740 devc->model = hw_config->card_subtype = MDL_SB2;
741 else
742 devc->model = hw_config->card_subtype = MDL_SB201;
743 break;
744
745 case 3: /* SB Pro and most clones */
746 switch (devc->model) {
747 case 0:
748 devc->model = hw_config->card_subtype = MDL_SBPRO;
749 if (hw_config->name == NULL)
750 hw_config->name = "Sound Blaster Pro (8 BIT ONLY)";
751 break;
752 case MDL_ESS:
753 ess_dsp_init(devc, hw_config);
754 break;
755 }
756 break;
757
758 case 4:
759 devc->model = hw_config->card_subtype = MDL_SB16;
760 /*
761 * ALS007 and ALS100 return DSP version 4.2 and have 2 post-reset !=0
762 * registers at 0x3c and 0x4c (output ctrl registers on ALS007) whereas
763 * a "standard" SB16 doesn't have a register at 0x4c. ALS100 actively
764 * updates register 0x22 whenever 0x30 changes, as per the SB16 spec.
765 * Since ALS007 doesn't, this can be used to differentiate the 2 cards.
766 */
767 if ((devc->minor == 2) && sb_getmixer(devc,0x3c) && sb_getmixer(devc,0x4c))
768 {
769 mixer30 = sb_getmixer(devc,0x30);
770 sb_setmixer(devc,0x22,(mixer22=sb_getmixer(devc,0x22)) & 0x0f);
771 sb_setmixer(devc,0x30,0xff);
772 /* ALS100 will force 0x30 to 0xf8 like SB16; ALS007 will allow 0xff. */
773 /* Register 0x22 & 0xf0 on ALS100 == 0xf0; on ALS007 it == 0x10. */
774 if ((sb_getmixer(devc,0x30) != 0xff) || ((sb_getmixer(devc,0x22) & 0xf0) != 0x10))
775 {
776 devc->submodel = SUBMDL_ALS100;
777 if (hw_config->name == NULL)
778 hw_config->name = "Sound Blaster 16 (ALS-100)";
779 }
780 else
781 {
782 sb_setmixer(devc,0x3c,0x1f); /* Enable all inputs */
783 sb_setmixer(devc,0x4c,0x1f);
784 sb_setmixer(devc,0x22,mixer22); /* Restore 0x22 to original value */
785 devc->submodel = SUBMDL_ALS007;
786 if (hw_config->name == NULL)
787 hw_config->name = "Sound Blaster 16 (ALS-007)";
788 }
789 sb_setmixer(devc,0x30,mixer30);
790 }
791 else if (hw_config->name == NULL)
792 hw_config->name = "Sound Blaster 16";
793
794 if (hw_config->dma2 == -1)
795 devc->dma16 = devc->dma8;
796 else if (hw_config->dma2 < 5 || hw_config->dma2 > 7)
797 {
798 printk(KERN_WARNING "SB16: Bad or missing 16 bit DMA channel\n");
799 devc->dma16 = devc->dma8;
800 }
801 else
802 devc->dma16 = hw_config->dma2;
803
804 if(!sb16_set_dma_hw(devc)) {
805 free_irq(devc->irq, devc);
806 release_region(hw_config->io_base, 16);
807 return 0;
808 }
809
810 devc->caps |= SB_NO_MIDI;
811 }
812
813 if (!(devc->caps & SB_NO_MIXER))
814 if (devc->major == 3 || devc->major == 4)
815 sb_mixer_init(devc, owner);
816
817 if (!(devc->caps & SB_NO_MIDI))
818 sb_dsp_midi_init(devc, owner);
819
820 if (hw_config->name == NULL)
821 hw_config->name = "Sound Blaster (8 BIT/MONO ONLY)";
822
823 sprintf(name, "%s (%d.%02d)", hw_config->name, devc->major, devc->minor);
824 conf_printf(name, hw_config);
825
826 /*
827 * Assuming that a sound card is Sound Blaster (compatible) is the most common
828 * configuration error and the mother of all problems. Usually sound cards
829 * emulate SB Pro but in addition they have a 16 bit native mode which should be
830 * used in Unix. See Readme.cards for more information about configuring OSS/Free
831 * properly.
832 */
833 if (devc->model <= MDL_SBPRO)
834 {
835 if (devc->major == 3 && devc->minor != 1) /* "True" SB Pro should have v3.1 (rare ones may have 3.2). */
836 {
837 printk(KERN_INFO "This sound card may not be fully Sound Blaster Pro compatible.\n");
838 printk(KERN_INFO "In many cases there is another way to configure OSS so that\n");
839 printk(KERN_INFO "it works properly with OSS (for example in 16 bit mode).\n");
840 printk(KERN_INFO "Please ignore this message if you _really_ have a SB Pro.\n");
841 }
842 else if (!sb_be_quiet && devc->model == MDL_SBPRO)
843 {
844 printk(KERN_INFO "SB DSP version is just %d.%02d which means that your card is\n", devc->major, devc->minor);
845 printk(KERN_INFO "several years old (8 bit only device) or alternatively the sound driver\n");
846 printk(KERN_INFO "is incorrectly configured.\n");
847 }
848 }
849 hw_config->card_subtype = devc->model;
850 hw_config->slots[0]=devc->dev;
851 last_devc = devc; /* For SB MPU detection */
852
853 if (!(devc->caps & SB_NO_AUDIO) && devc->dma8 >= 0)
854 {
855 if (sound_alloc_dma(devc->dma8, "SoundBlaster8"))
856 {
857 printk(KERN_WARNING "Sound Blaster: Can't allocate 8 bit DMA channel %d\n", devc->dma8);
858 }
859 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
860 {
861 if (sound_alloc_dma(devc->dma16, "SoundBlaster16"))
862 printk(KERN_WARNING "Sound Blaster: can't allocate 16 bit DMA channel %d.\n", devc->dma16);
863 }
864 sb_audio_init(devc, name, owner);
865 hw_config->slots[0]=devc->dev;
866 }
867 else
868 {
869 MDB(printk("Sound Blaster: no audio devices found.\n"));
870 }
871 return 1;
872}
873
874/* if (sbmpu) below we allow mpu401 to manage the midi devs
875 otherwise we have to unload them. (Andrzej Krzysztofowicz) */
876
877void sb_dsp_unload(struct address_info *hw_config, int sbmpu)
878{
879 sb_devc *devc;
880
881 devc = audio_devs[hw_config->slots[0]]->devc;
882
883 if (devc && devc->base == hw_config->io_base)
884 {
885 if ((devc->model & MDL_ESS) && devc->pcibase)
886 release_region(devc->pcibase, 8);
887
888 release_region(devc->base, 16);
889
890 if (!(devc->caps & SB_NO_AUDIO))
891 {
892 sound_free_dma(devc->dma8);
893 if (devc->dma16 >= 0)
894 sound_free_dma(devc->dma16);
895 }
896 if (!(devc->caps & SB_NO_AUDIO && devc->caps & SB_NO_MIDI))
897 {
898 if (devc->irq > 0)
899 free_irq(devc->irq, devc);
900
901 sb_mixer_unload(devc);
902 /* We don't have to do this bit any more the UART401 is its own
903 master -- Krzysztof Halasa */
904 /* But we have to do it, if UART401 is not detected */
905 if (!sbmpu)
906 sound_unload_mididev(devc->my_mididev);
907 sound_unload_audiodev(devc->dev);
908 }
909 kfree(devc);
910 }
911 else
912 release_region(hw_config->io_base, 16);
913
914 kfree(detected_devc);
915}
916
917/*
918 * Mixer access routines
919 *
920 * ES1887 modifications: some mixer registers reside in the
921 * range above 0xa0. These must be accessed in another way.
922 */
923
924void sb_setmixer(sb_devc * devc, unsigned int port, unsigned int value)
925{
926 unsigned long flags;
927
928 if (devc->model == MDL_ESS) {
929 ess_setmixer (devc, port, value);
930 return;
931 }
932
933 spin_lock_irqsave(&devc->lock, flags);
934
935 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
936 udelay(20);
937 outb(((unsigned char) (value & 0xff)), MIXER_DATA);
938 udelay(20);
939
940 spin_unlock_irqrestore(&devc->lock, flags);
941}
942
943unsigned int sb_getmixer(sb_devc * devc, unsigned int port)
944{
945 unsigned int val;
946 unsigned long flags;
947
948 if (devc->model == MDL_ESS) return ess_getmixer (devc, port);
949
950 spin_lock_irqsave(&devc->lock, flags);
951
952 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
953 udelay(20);
954 val = inb(MIXER_DATA);
955 udelay(20);
956
957 spin_unlock_irqrestore(&devc->lock, flags);
958
959 return val;
960}
961
962void sb_chgmixer
963 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
964{
965 int value;
966
967 value = sb_getmixer(devc, reg);
968 value = (value & ~mask) | (val & mask);
969 sb_setmixer(devc, reg, value);
970}
971
972/*
973 * MPU401 MIDI initialization.
974 */
975
976static void smw_putmem(sb_devc * devc, int base, int addr, unsigned char val)
977{
978 unsigned long flags;
979
980 spin_lock_irqsave(&jazz16_lock, flags); /* NOT the SB card? */
981
982 outb((addr & 0xff), base + 1); /* Low address bits */
983 outb((addr >> 8), base + 2); /* High address bits */
984 outb((val), base); /* Data */
985
986 spin_unlock_irqrestore(&jazz16_lock, flags);
987}
988
989static unsigned char smw_getmem(sb_devc * devc, int base, int addr)
990{
991 unsigned long flags;
992 unsigned char val;
993
994 spin_lock_irqsave(&jazz16_lock, flags); /* NOT the SB card? */
995
996 outb((addr & 0xff), base + 1); /* Low address bits */
997 outb((addr >> 8), base + 2); /* High address bits */
998 val = inb(base); /* Data */
999
1000 spin_unlock_irqrestore(&jazz16_lock, flags);
1001 return val;
1002}
1003
1004static int smw_midi_init(sb_devc * devc, struct address_info *hw_config)
1005{
1006 int mpu_base = hw_config->io_base;
1007 int mp_base = mpu_base + 4; /* Microcontroller base */
1008 int i;
1009 unsigned char control;
1010
1011
1012 /*
1013 * Reset the microcontroller so that the RAM can be accessed
1014 */
1015
1016 control = inb(mpu_base + 7);
1017 outb((control | 3), mpu_base + 7); /* Set last two bits to 1 (?) */
1018 outb(((control & 0xfe) | 2), mpu_base + 7); /* xxxxxxx0 resets the mc */
1019
1020 mdelay(3); /* Wait at least 1ms */
1021
1022 outb((control & 0xfc), mpu_base + 7); /* xxxxxx00 enables RAM */
1023
1024 /*
1025 * Detect microcontroller by probing the 8k RAM area
1026 */
1027 smw_putmem(devc, mp_base, 0, 0x00);
1028 smw_putmem(devc, mp_base, 1, 0xff);
1029 udelay(10);
1030
1031 if (smw_getmem(devc, mp_base, 0) != 0x00 || smw_getmem(devc, mp_base, 1) != 0xff)
1032 {
1033 DDB(printk("SM Wave: No microcontroller RAM detected (%02x, %02x)\n", smw_getmem(devc, mp_base, 0), smw_getmem(devc, mp_base, 1)));
1034 return 0; /* No RAM */
1035 }
1036 /*
1037 * There is RAM so assume it's really a SM Wave
1038 */
1039
1040 devc->model = MDL_SMW;
1041 smw_mixer_init(devc);
1042
1043#ifdef MODULE
1044 if (!smw_ucode)
1045 {
1046 smw_ucodeLen = mod_firmware_load("/etc/sound/midi0001.bin", (void *) &smw_ucode);
1047 smw_free = smw_ucode;
1048 }
1049#endif
1050 if (smw_ucodeLen > 0)
1051 {
1052 if (smw_ucodeLen != 8192)
1053 {
1054 printk(KERN_ERR "SM Wave: Invalid microcode (MIDI0001.BIN) length\n");
1055 return 1;
1056 }
1057 /*
1058 * Download microcode
1059 */
1060
1061 for (i = 0; i < 8192; i++)
1062 smw_putmem(devc, mp_base, i, smw_ucode[i]);
1063
1064 /*
1065 * Verify microcode
1066 */
1067
1068 for (i = 0; i < 8192; i++)
1069 if (smw_getmem(devc, mp_base, i) != smw_ucode[i])
1070 {
1071 printk(KERN_ERR "SM Wave: Microcode verification failed\n");
1072 return 0;
1073 }
1074 }
1075 control = 0;
1076#ifdef SMW_SCSI_IRQ
1077 /*
1078 * Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
1079 * is disabled by default.
1080 *
1081 * FIXME - make this a module option
1082 *
1083 * BTW the Zilog 5380 SCSI controller is located at MPU base + 0x10.
1084 */
1085 {
1086 static unsigned char scsi_irq_bits[] = {
1087 0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0
1088 };
1089 control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1090 }
1091#endif
1092
1093#ifdef SMW_OPL4_ENABLE
1094 /*
1095 * Make the OPL4 chip visible on the PC bus at 0x380.
1096 *
1097 * There is no need to enable this feature since this driver
1098 * doesn't support OPL4 yet. Also there is no RAM in SM Wave so
1099 * enabling OPL4 is pretty useless.
1100 */
1101 control |= 0x10; /* Uses IRQ12 if bit 0x20 == 0 */
1102 /* control |= 0x20; Uncomment this if you want to use IRQ7 */
1103#endif
1104 outb((control | 0x03), mpu_base + 7); /* xxxxxx11 restarts */
1105 hw_config->name = "SoundMan Wave";
1106 return 1;
1107}
1108
1109static int init_Jazz16_midi(sb_devc * devc, struct address_info *hw_config)
1110{
1111 int mpu_base = hw_config->io_base;
1112 int sb_base = devc->base;
1113 int irq = hw_config->irq;
1114
1115 unsigned char bits = 0;
1116 unsigned long flags;
1117
1118 if (irq < 0)
1119 irq *= -1;
1120
1121 if (irq < 1 || irq > 15 ||
1122 jazz_irq_bits[irq] == 0)
1123 {
1124 printk(KERN_ERR "Jazz16: Invalid MIDI interrupt (IRQ%d)\n", irq);
1125 return 0;
1126 }
1127 switch (sb_base)
1128 {
1129 case 0x220:
1130 bits = 1;
1131 break;
1132 case 0x240:
1133 bits = 2;
1134 break;
1135 case 0x260:
1136 bits = 3;
1137 break;
1138 default:
1139 return 0;
1140 }
1141 bits = jazz16_bits = bits << 5;
1142 switch (mpu_base)
1143 {
1144 case 0x310:
1145 bits |= 1;
1146 break;
1147 case 0x320:
1148 bits |= 2;
1149 break;
1150 case 0x330:
1151 bits |= 3;
1152 break;
1153 default:
1154 printk(KERN_ERR "Jazz16: Invalid MIDI I/O port %x\n", mpu_base);
1155 return 0;
1156 }
1157 /*
1158 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
1159 */
1160 spin_lock_irqsave(&jazz16_lock, flags);
1161 outb(0xAF, 0x201);
1162 outb(0x50, 0x201);
1163 outb(bits, 0x201);
1164 spin_unlock_irqrestore(&jazz16_lock, flags);
1165
1166 hw_config->name = "Jazz16";
1167 smw_midi_init(devc, hw_config);
1168
1169 if (!sb_dsp_command(devc, 0xfb))
1170 return 0;
1171
1172 if (!sb_dsp_command(devc, jazz_dma_bits[devc->dma8] |
1173 (jazz_dma_bits[devc->dma16] << 4)))
1174 return 0;
1175
1176 if (!sb_dsp_command(devc, jazz_irq_bits[devc->irq] |
1177 (jazz_irq_bits[irq] << 4)))
1178 return 0;
1179
1180 return 1;
1181}
1182
1183int probe_sbmpu(struct address_info *hw_config, struct module *owner)
1184{
1185 sb_devc *devc = last_devc;
1186 int ret;
1187
1188 if (last_devc == NULL)
1189 return 0;
1190
1191 last_devc = NULL;
1192
1193 if (hw_config->io_base <= 0)
1194 {
1195 /* The real vibra16 is fine about this, but we have to go
1196 wipe up after Cyrix again */
1197
1198 if(devc->model == MDL_SB16 && devc->minor >= 12)
1199 {
1200 unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
1201 sb_setmixer(devc, 0x84, bits | 0x02); /* Disable MPU */
1202 }
1203 return 0;
1204 }
1205
1206#if defined(CONFIG_SOUND_MPU401)
1207 if (devc->model == MDL_ESS)
1208 {
1209 struct resource *ports;
1210 ports = request_region(hw_config->io_base, 2, "mpu401");
1211 if (!ports) {
1212 printk(KERN_ERR "sbmpu: I/O port conflict (%x)\n", hw_config->io_base);
1213 return 0;
1214 }
1215 if (!ess_midi_init(devc, hw_config)) {
1216 release_region(hw_config->io_base, 2);
1217 return 0;
1218 }
1219 hw_config->name = "ESS1xxx MPU";
1220 devc->midi_irq_cookie = NULL;
1221 if (!probe_mpu401(hw_config, ports)) {
1222 release_region(hw_config->io_base, 2);
1223 return 0;
1224 }
1225 attach_mpu401(hw_config, owner);
1226 if (last_sb->irq == -hw_config->irq)
1227 last_sb->midi_irq_cookie =
1228 (void *)(long) hw_config->slots[1];
1229 return 1;
1230 }
1231#endif
1232
1233 switch (devc->model)
1234 {
1235 case MDL_SB16:
1236 if (hw_config->io_base != 0x300 && hw_config->io_base != 0x330)
1237 {
1238 printk(KERN_ERR "SB16: Invalid MIDI port %x\n", hw_config->io_base);
1239 return 0;
1240 }
1241 hw_config->name = "Sound Blaster 16";
1242 if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1243 hw_config->irq = -devc->irq;
1244 if (devc->minor > 12) /* What is Vibra's version??? */
1245 sb16_set_mpu_port(devc, hw_config);
1246 break;
1247
1248 case MDL_JAZZ:
1249 if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1250 hw_config->irq = -devc->irq;
1251 if (!init_Jazz16_midi(devc, hw_config))
1252 return 0;
1253 break;
1254
1255 case MDL_YMPCI:
1256 hw_config->name = "Yamaha PCI Legacy";
1257 printk("Yamaha PCI legacy UART401 check.\n");
1258 break;
1259 default:
1260 return 0;
1261 }
1262
1263 ret = probe_uart401(hw_config, owner);
1264 if (ret)
1265 last_sb->midi_irq_cookie=midi_devs[hw_config->slots[4]]->devc;
1266 return ret;
1267}
1268
1269void unload_sbmpu(struct address_info *hw_config)
1270{
1271#if defined(CONFIG_SOUND_MPU401)
1272 if (!strcmp (hw_config->name, "ESS1xxx MPU")) {
1273 unload_mpu401(hw_config);
1274 return;
1275 }
1276#endif
1277 unload_uart401(hw_config);
1278}
1279
1280EXPORT_SYMBOL(sb_dsp_init);
1281EXPORT_SYMBOL(sb_dsp_detect);
1282EXPORT_SYMBOL(sb_dsp_unload);
1283EXPORT_SYMBOL(sb_be_quiet);
1284EXPORT_SYMBOL(probe_sbmpu);
1285EXPORT_SYMBOL(unload_sbmpu);
1286EXPORT_SYMBOL(smw_free);
1287MODULE_LICENSE("GPL");
diff --git a/sound/oss/sb_ess.c b/sound/oss/sb_ess.c
deleted file mode 100644
index 57f7d25a2cd3..000000000000
--- a/sound/oss/sb_ess.c
+++ /dev/null
@@ -1,1822 +0,0 @@
1#undef FKS_LOGGING
2#undef FKS_TEST
3
4/*
5 * tabs should be 4 spaces, in vi(m): set tabstop=4
6 *
7 * TODO: consistency speed calculations!!
8 * cleanup!
9 * ????: Did I break MIDI support?
10 *
11 * History:
12 *
13 * Rolf Fokkens (Dec 20 1998): ES188x recording level support on a per
14 * fokkensr@vertis.nl input basis.
15 * (Dec 24 1998): Recognition of ES1788, ES1887, ES1888,
16 * ES1868, ES1869 and ES1878. Could be used for
17 * specific handling in the future. All except
18 * ES1887 and ES1888 and ES688 are handled like
19 * ES1688.
20 * (Dec 27 1998): RECLEV for all (?) ES1688+ chips. ES188x now
21 * have the "Dec 20" support + RECLEV
22 * (Jan 2 1999): Preparation for Full Duplex. This means
23 * Audio 2 is now used for playback when dma16
24 * is specified. The next step would be to use
25 * Audio 1 and Audio 2 at the same time.
26 * (Jan 9 1999): Put all ESS stuff into sb_ess.[ch], this
27 * includes both the ESS stuff that has been in
28 * sb_*[ch] before I touched it and the ESS support
29 * I added later
30 * (Jan 23 1999): Full Duplex seems to work. I wrote a small
31 * test proggy which works OK. Haven't found
32 * any applications to test it though. So why did
33 * I bother to create it anyway?? :) Just for
34 * fun.
35 * (May 2 1999): I tried to be too smart by "introducing"
36 * ess_calc_best_speed (). The idea was that two
37 * dividers could be used to setup a samplerate,
38 * ess_calc_best_speed () would choose the best.
39 * This works for playback, but results in
40 * recording problems for high samplerates. I
41 * fixed this by removing ess_calc_best_speed ()
42 * and just doing what the documentation says.
43 * Andy Sloane (Jun 4 1999): Stole some code from ALSA to fix the playback
44 * andy@guildsoftware.com speed on ES1869, ES1879, ES1887, and ES1888.
45 * 1879's were previously ignored by this driver;
46 * added (untested) support for those.
47 * Cvetan Ivanov (Oct 27 1999): Fixed ess_dsp_init to call ess_set_dma_hw for
48 * zezo@inet.bg _ALL_ ESS models, not only ES1887
49 *
50 * This files contains ESS chip specifics. It's based on the existing ESS
51 * handling as it resided in sb_common.c, sb_mixer.c and sb_audio.c. This
52 * file adds features like:
53 * - Chip Identification (as shown in /proc/sound)
54 * - RECLEV support for ES1688 and later
55 * - 6 bits playback level support chips later than ES1688
56 * - Recording level support on a per-device basis for ES1887
57 * - Full-Duplex for ES1887
58 *
59 * Full duplex is enabled by specifying dma16. While the normal dma must
60 * be one of 0, 1 or 3, dma16 can be one of 0, 1, 3 or 5. DMA 5 is a 16 bit
61 * DMA channel, while the others are 8 bit..
62 *
63 * ESS detection isn't full proof (yet). If it fails an additional module
64 * parameter esstype can be specified to be one of the following:
65 * -1, 0, 688, 1688, 1868, 1869, 1788, 1887, 1888
66 * -1 means: mimic 2.0 behaviour,
67 * 0 means: auto detect.
68 * others: explicitly specify chip
69 * -1 is default, cause auto detect still doesn't work.
70 */
71
72/*
73 * About the documentation
74 *
75 * I don't know if the chips all are OK, but the documentation is buggy. 'cause
76 * I don't have all the cips myself, there's a lot I cannot verify. I'll try to
77 * keep track of my latest insights about his here. If you have additional info,
78 * please enlighten me (fokkensr@vertis.nl)!
79 *
80 * I had the impression that ES1688 also has 6 bit master volume control. The
81 * documentation about ES1888 (rev C, october '95) claims that ES1888 has
82 * the following features ES1688 doesn't have:
83 * - 6 bit master volume
84 * - Full Duplex
85 * So ES1688 apparently doesn't have 6 bit master volume control, but the
86 * ES1688 does have RECLEV control. Makes me wonder: does ES688 have it too?
87 * Without RECLEV ES688 won't be much fun I guess.
88 *
89 * From the ES1888 (rev C, october '95) documentation I got the impression
90 * that registers 0x68 to 0x6e don't exist which means: no recording volume
91 * controls. To my surprise the ES888 documentation (1/14/96) claims that
92 * ES888 does have these record mixer registers, but that ES1888 doesn't have
93 * 0x69 and 0x6b. So the rest should be there.
94 *
95 * I'm trying to get ES1887 Full Duplex. Audio 2 is playback only, while Audio 2
96 * is both record and playback. I think I should use Audio 2 for all playback.
97 *
98 * The documentation is an adventure: it's close but not fully accurate. I
99 * found out that after a reset some registers are *NOT* reset, though the
100 * docs say the would be. Interesting ones are 0x7f, 0x7d and 0x7a. They are
101 * related to the Audio 2 channel. I also was surprised about the consequences
102 * of writing 0x00 to 0x7f (which should be done by reset): The ES1887 moves
103 * into ES1888 mode. This means that it claims IRQ 11, which happens to be my
104 * ISDN adapter. Needless to say it no longer worked. I now understand why
105 * after rebooting 0x7f already was 0x05, the value of my choice: the BIOS
106 * did it.
107 *
108 * Oh, and this is another trap: in ES1887 docs mixer register 0x70 is
109 * described as if it's exactly the same as register 0xa1. This is *NOT* true.
110 * The description of 0x70 in ES1869 docs is accurate however.
111 * Well, the assumption about ES1869 was wrong: register 0x70 is very much
112 * like register 0xa1, except that bit 7 is always 1, whatever you want
113 * it to be.
114 *
115 * When using audio 2 mixer register 0x72 seems te be meaningless. Only 0xa2
116 * has effect.
117 *
118 * Software reset not being able to reset all registers is great! Especially
119 * the fact that register 0x78 isn't reset is great when you wanna change back
120 * to single dma operation (simplex): audio 2 is still operational, and uses
121 * the same dma as audio 1: your ess changes into a funny echo machine.
122 *
123 * Received the news that ES1688 is detected as a ES1788. Did some thinking:
124 * the ES1887 detection scheme suggests in step 2 to try if bit 3 of register
125 * 0x64 can be changed. This is inaccurate, first I inverted the * check: "If
126 * can be modified, it's a 1688", which lead to a correct detection
127 * of my ES1887. It resulted however in bad detection of 1688 (reported by mail)
128 * and 1868 (if no PnP detection first): they result in a 1788 being detected.
129 * I don't have docs on 1688, but I do have docs on 1868: The documentation is
130 * probably inaccurate in the fact that I should check bit 2, not bit 3. This
131 * is what I do now.
132 */
133
134/*
135 * About recognition of ESS chips
136 *
137 * The distinction of ES688, ES1688, ES1788, ES1887 and ES1888 is described in
138 * a (preliminary ??) datasheet on ES1887. Its aim is to identify ES1887, but
139 * during detection the text claims that "this chip may be ..." when a step
140 * fails. This scheme is used to distinct between the above chips.
141 * It appears however that some PnP chips like ES1868 are recognized as ES1788
142 * by the ES1887 detection scheme. These PnP chips can be detected in another
143 * way however: ES1868, ES1869 and ES1878 can be recognized (full proof I think)
144 * by repeatedly reading mixer register 0x40. This is done by ess_identify in
145 * sb_common.c.
146 * This results in the following detection steps:
147 * - distinct between ES688 and ES1688+ (as always done in this driver)
148 * if ES688 we're ready
149 * - try to detect ES1868, ES1869 or ES1878
150 * if successful we're ready
151 * - try to detect ES1888, ES1887 or ES1788
152 * if successful we're ready
153 * - Dunno. Must be 1688. Will do in general
154 *
155 * About RECLEV support:
156 *
157 * The existing ES1688 support didn't take care of the ES1688+ recording
158 * levels very well. Whenever a device was selected (recmask) for recording
159 * its recording level was loud, and it couldn't be changed. The fact that
160 * internal register 0xb4 could take care of RECLEV, didn't work meaning until
161 * its value was restored every time the chip was reset; this reset the
162 * value of 0xb4 too. I guess that's what 4front also had (have?) trouble with.
163 *
164 * About ES1887 support:
165 *
166 * The ES1887 has separate registers to control the recording levels, for all
167 * inputs. The ES1887 specific software makes these levels the same as their
168 * corresponding playback levels, unless recmask says they aren't recorded. In
169 * the latter case the recording volumes are 0.
170 * Now recording levels of inputs can be controlled, by changing the playback
171 * levels. Furthermore several devices can be recorded together (which is not
172 * possible with the ES1688).
173 * Besides the separate recording level control for each input, the common
174 * recording level can also be controlled by RECLEV as described above.
175 *
176 * Not only ES1887 have this recording mixer. I know the following from the
177 * documentation:
178 * ES688 no
179 * ES1688 no
180 * ES1868 no
181 * ES1869 yes
182 * ES1878 no
183 * ES1879 yes
184 * ES1888 no/yes Contradicting documentation; most recent: yes
185 * ES1946 yes This is a PCI chip; not handled by this driver
186 */
187
188#include <linux/delay.h>
189#include <linux/interrupt.h>
190#include <linux/spinlock.h>
191
192#include "sound_config.h"
193#include "sb_mixer.h"
194#include "sb.h"
195
196#include "sb_ess.h"
197
198#define ESSTYPE_LIKE20 -1 /* Mimic 2.0 behaviour */
199#define ESSTYPE_DETECT 0 /* Mimic 2.0 behaviour */
200
201#define SUBMDL_ES1788 0x10 /* Subtype ES1788 for specific handling */
202#define SUBMDL_ES1868 0x11 /* Subtype ES1868 for specific handling */
203#define SUBMDL_ES1869 0x12 /* Subtype ES1869 for specific handling */
204#define SUBMDL_ES1878 0x13 /* Subtype ES1878 for specific handling */
205#define SUBMDL_ES1879 0x16 /* ES1879 was initially forgotten */
206#define SUBMDL_ES1887 0x14 /* Subtype ES1887 for specific handling */
207#define SUBMDL_ES1888 0x15 /* Subtype ES1888 for specific handling */
208
209#define SB_CAP_ES18XX_RATE 0x100
210
211#define ES1688_CLOCK1 795444 /* 128 - div */
212#define ES1688_CLOCK2 397722 /* 256 - div */
213#define ES18XX_CLOCK1 793800 /* 128 - div */
214#define ES18XX_CLOCK2 768000 /* 256 - div */
215
216#ifdef FKS_LOGGING
217static void ess_show_mixerregs (sb_devc *devc);
218#endif
219static int ess_read (sb_devc * devc, unsigned char reg);
220static int ess_write (sb_devc * devc, unsigned char reg, unsigned char data);
221static void ess_chgmixer
222 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val);
223
224/****************************************************************************
225 * *
226 * ESS audio *
227 * *
228 ****************************************************************************/
229
230struct ess_command {short cmd; short data;};
231
232/*
233 * Commands for initializing Audio 1 for input (record)
234 */
235static struct ess_command ess_i08m[] = /* input 8 bit mono */
236 { {0xb7, 0x51}, {0xb7, 0xd0}, {-1, 0} };
237static struct ess_command ess_i16m[] = /* input 16 bit mono */
238 { {0xb7, 0x71}, {0xb7, 0xf4}, {-1, 0} };
239static struct ess_command ess_i08s[] = /* input 8 bit stereo */
240 { {0xb7, 0x51}, {0xb7, 0x98}, {-1, 0} };
241static struct ess_command ess_i16s[] = /* input 16 bit stereo */
242 { {0xb7, 0x71}, {0xb7, 0xbc}, {-1, 0} };
243
244static struct ess_command *ess_inp_cmds[] =
245 { ess_i08m, ess_i16m, ess_i08s, ess_i16s };
246
247
248/*
249 * Commands for initializing Audio 1 for output (playback)
250 */
251static struct ess_command ess_o08m[] = /* output 8 bit mono */
252 { {0xb6, 0x80}, {0xb7, 0x51}, {0xb7, 0xd0}, {-1, 0} };
253static struct ess_command ess_o16m[] = /* output 16 bit mono */
254 { {0xb6, 0x00}, {0xb7, 0x71}, {0xb7, 0xf4}, {-1, 0} };
255static struct ess_command ess_o08s[] = /* output 8 bit stereo */
256 { {0xb6, 0x80}, {0xb7, 0x51}, {0xb7, 0x98}, {-1, 0} };
257static struct ess_command ess_o16s[] = /* output 16 bit stereo */
258 { {0xb6, 0x00}, {0xb7, 0x71}, {0xb7, 0xbc}, {-1, 0} };
259
260static struct ess_command *ess_out_cmds[] =
261 { ess_o08m, ess_o16m, ess_o08s, ess_o16s };
262
263static void ess_exec_commands
264 (sb_devc *devc, struct ess_command *cmdtab[])
265{
266 struct ess_command *cmd;
267
268 cmd = cmdtab [ ((devc->channels != 1) << 1) + (devc->bits != AFMT_U8) ];
269
270 while (cmd->cmd != -1) {
271 ess_write (devc, cmd->cmd, cmd->data);
272 cmd++;
273 }
274}
275
276static void ess_change
277 (sb_devc *devc, unsigned int reg, unsigned int mask, unsigned int val)
278{
279 int value;
280
281 value = ess_read (devc, reg);
282 value = (value & ~mask) | (val & mask);
283 ess_write (devc, reg, value);
284}
285
286static void ess_set_output_parms
287 (int dev, unsigned long buf, int nr_bytes, int intrflag)
288{
289 sb_devc *devc = audio_devs[dev]->devc;
290
291 if (devc->duplex) {
292 devc->trg_buf_16 = buf;
293 devc->trg_bytes_16 = nr_bytes;
294 devc->trg_intrflag_16 = intrflag;
295 devc->irq_mode_16 = IMODE_OUTPUT;
296 } else {
297 devc->trg_buf = buf;
298 devc->trg_bytes = nr_bytes;
299 devc->trg_intrflag = intrflag;
300 devc->irq_mode = IMODE_OUTPUT;
301 }
302}
303
304static void ess_set_input_parms
305 (int dev, unsigned long buf, int count, int intrflag)
306{
307 sb_devc *devc = audio_devs[dev]->devc;
308
309 devc->trg_buf = buf;
310 devc->trg_bytes = count;
311 devc->trg_intrflag = intrflag;
312 devc->irq_mode = IMODE_INPUT;
313}
314
315static int ess_calc_div (int clock, int revert, int *speedp, int *diffp)
316{
317 int divider;
318 int speed, diff;
319 int retval;
320
321 speed = *speedp;
322 divider = (clock + speed / 2) / speed;
323 retval = revert - divider;
324 if (retval > revert - 1) {
325 retval = revert - 1;
326 divider = revert - retval;
327 }
328 /* This line is suggested. Must be wrong I think
329 *speedp = (clock + divider / 2) / divider;
330 So I chose the next one */
331
332 *speedp = clock / divider;
333 diff = speed - *speedp;
334 if (diff < 0) diff =-diff;
335 *diffp = diff;
336
337 return retval;
338}
339
340static int ess_calc_best_speed
341 (int clock1, int rev1, int clock2, int rev2, int *divp, int *speedp)
342{
343 int speed1 = *speedp, speed2 = *speedp;
344 int div1, div2;
345 int diff1, diff2;
346 int retval;
347
348 div1 = ess_calc_div (clock1, rev1, &speed1, &diff1);
349 div2 = ess_calc_div (clock2, rev2, &speed2, &diff2);
350
351 if (diff1 < diff2) {
352 *divp = div1;
353 *speedp = speed1;
354 retval = 1;
355 } else {
356 /* *divp = div2; */
357 *divp = 0x80 | div2;
358 *speedp = speed2;
359 retval = 2;
360 }
361
362 return retval;
363}
364
365/*
366 * Depending on the audiochannel ESS devices can
367 * have different clock settings. These are made consistent for duplex
368 * however.
369 * callers of ess_speed only do an audionum suggestion, which means
370 * input suggests 1, output suggests 2. This suggestion is only true
371 * however when doing duplex.
372 */
373static void ess_common_speed (sb_devc *devc, int *speedp, int *divp)
374{
375 int diff = 0, div;
376
377 if (devc->duplex) {
378 /*
379 * The 0x80 is important for the first audio channel
380 */
381 if (devc->submodel == SUBMDL_ES1888) {
382 div = 0x80 | ess_calc_div (795500, 256, speedp, &diff);
383 } else {
384 div = 0x80 | ess_calc_div (795500, 128, speedp, &diff);
385 }
386 } else if(devc->caps & SB_CAP_ES18XX_RATE) {
387 if (devc->submodel == SUBMDL_ES1888) {
388 ess_calc_best_speed(397700, 128, 795500, 256,
389 &div, speedp);
390 } else {
391 ess_calc_best_speed(ES18XX_CLOCK1, 128, ES18XX_CLOCK2, 256,
392 &div, speedp);
393 }
394 } else {
395 if (*speedp > 22000) {
396 div = 0x80 | ess_calc_div (ES1688_CLOCK1, 256, speedp, &diff);
397 } else {
398 div = 0x00 | ess_calc_div (ES1688_CLOCK2, 128, speedp, &diff);
399 }
400 }
401 *divp = div;
402}
403
404static void ess_speed (sb_devc *devc, int audionum)
405{
406 int speed;
407 int div, div2;
408
409 ess_common_speed (devc, &(devc->speed), &div);
410
411#ifdef FKS_REG_LOGGING
412printk (KERN_INFO "FKS: ess_speed (%d) b speed = %d, div=%x\n", audionum, devc->speed, div);
413#endif
414
415 /* Set filter roll-off to 90% of speed/2 */
416 speed = (devc->speed * 9) / 20;
417
418 div2 = 256 - 7160000 / (speed * 82);
419
420 if (!devc->duplex) audionum = 1;
421
422 if (audionum == 1) {
423 /* Change behaviour of register A1 *
424 sb_chg_mixer(devc, 0x71, 0x20, 0x20)
425 * For ES1869 only??? */
426 ess_write (devc, 0xa1, div);
427 ess_write (devc, 0xa2, div2);
428 } else {
429 ess_setmixer (devc, 0x70, div);
430 /*
431 * FKS: fascinating: 0x72 doesn't seem to work.
432 */
433 ess_write (devc, 0xa2, div2);
434 ess_setmixer (devc, 0x72, div2);
435 }
436}
437
438static int ess_audio_prepare_for_input(int dev, int bsize, int bcount)
439{
440 sb_devc *devc = audio_devs[dev]->devc;
441
442 ess_speed(devc, 1);
443
444 sb_dsp_command(devc, DSP_CMD_SPKOFF);
445
446 ess_write (devc, 0xb8, 0x0e); /* Auto init DMA mode */
447 ess_change (devc, 0xa8, 0x03, 3 - devc->channels); /* Mono/stereo */
448 ess_write (devc, 0xb9, 2); /* Demand mode (4 bytes/DMA request) */
449
450 ess_exec_commands (devc, ess_inp_cmds);
451
452 ess_change (devc, 0xb1, 0xf0, 0x50);
453 ess_change (devc, 0xb2, 0xf0, 0x50);
454
455 devc->trigger_bits = 0;
456 return 0;
457}
458
459static int ess_audio_prepare_for_output_audio1 (int dev, int bsize, int bcount)
460{
461 sb_devc *devc = audio_devs[dev]->devc;
462
463 sb_dsp_reset(devc);
464 ess_speed(devc, 1);
465 ess_write (devc, 0xb8, 4); /* Auto init DMA mode */
466 ess_change (devc, 0xa8, 0x03, 3 - devc->channels); /* Mono/stereo */
467 ess_write (devc, 0xb9, 2); /* Demand mode (4 bytes/request) */
468
469 ess_exec_commands (devc, ess_out_cmds);
470
471 ess_change (devc, 0xb1, 0xf0, 0x50); /* Enable DMA */
472 ess_change (devc, 0xb2, 0xf0, 0x50); /* Enable IRQ */
473
474 sb_dsp_command(devc, DSP_CMD_SPKON); /* There be sound! */
475
476 devc->trigger_bits = 0;
477 return 0;
478}
479
480static int ess_audio_prepare_for_output_audio2 (int dev, int bsize, int bcount)
481{
482 sb_devc *devc = audio_devs[dev]->devc;
483 unsigned char bits;
484
485/* FKS: qqq
486 sb_dsp_reset(devc);
487*/
488
489 /*
490 * Auto-Initialize:
491 * DMA mode + demand mode (8 bytes/request, yes I want it all!)
492 * But leave 16-bit DMA bit untouched!
493 */
494 ess_chgmixer (devc, 0x78, 0xd0, 0xd0);
495
496 ess_speed(devc, 2);
497
498 /* bits 4:3 on ES1887 represent recording source. Keep them! */
499 bits = ess_getmixer (devc, 0x7a) & 0x18;
500
501 /* Set stereo/mono */
502 if (devc->channels != 1) bits |= 0x02;
503
504 /* Init DACs; UNSIGNED mode for 8 bit; SIGNED mode for 16 bit */
505 if (devc->bits != AFMT_U8) bits |= 0x05; /* 16 bit */
506
507 /* Enable DMA, IRQ will be shared (hopefully)*/
508 bits |= 0x60;
509
510 ess_setmixer (devc, 0x7a, bits);
511
512 ess_mixer_reload (devc, SOUND_MIXER_PCM); /* There be sound! */
513
514 devc->trigger_bits = 0;
515 return 0;
516}
517
518static int ess_audio_prepare_for_output(int dev, int bsize, int bcount)
519{
520 sb_devc *devc = audio_devs[dev]->devc;
521
522#ifdef FKS_REG_LOGGING
523printk(KERN_INFO "ess_audio_prepare_for_output: dma_out=%d,dma_in=%d\n"
524, audio_devs[dev]->dmap_out->dma, audio_devs[dev]->dmap_in->dma);
525#endif
526
527 if (devc->duplex) {
528 return ess_audio_prepare_for_output_audio2 (dev, bsize, bcount);
529 } else {
530 return ess_audio_prepare_for_output_audio1 (dev, bsize, bcount);
531 }
532}
533
534static void ess_audio_halt_xfer(int dev)
535{
536 unsigned long flags;
537 sb_devc *devc = audio_devs[dev]->devc;
538
539 spin_lock_irqsave(&devc->lock, flags);
540 sb_dsp_reset(devc);
541 spin_unlock_irqrestore(&devc->lock, flags);
542
543 /*
544 * Audio 2 may still be operational! Creates awful sounds!
545 */
546 if (devc->duplex) ess_chgmixer(devc, 0x78, 0x03, 0x00);
547}
548
549static void ess_audio_start_input
550 (int dev, unsigned long buf, int nr_bytes, int intrflag)
551{
552 int count = nr_bytes;
553 sb_devc *devc = audio_devs[dev]->devc;
554 short c = -nr_bytes;
555
556 /*
557 * Start a DMA input to the buffer pointed by dmaqtail
558 */
559
560 if (audio_devs[dev]->dmap_in->dma > 3) count >>= 1;
561 count--;
562
563 devc->irq_mode = IMODE_INPUT;
564
565 ess_write (devc, 0xa4, (unsigned char) ((unsigned short) c & 0xff));
566 ess_write (devc, 0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
567
568 ess_change (devc, 0xb8, 0x0f, 0x0f); /* Go */
569 devc->intr_active = 1;
570}
571
572static void ess_audio_output_block_audio1
573 (int dev, unsigned long buf, int nr_bytes, int intrflag)
574{
575 int count = nr_bytes;
576 sb_devc *devc = audio_devs[dev]->devc;
577 short c = -nr_bytes;
578
579 if (audio_devs[dev]->dmap_out->dma > 3)
580 count >>= 1;
581 count--;
582
583 devc->irq_mode = IMODE_OUTPUT;
584
585 ess_write (devc, 0xa4, (unsigned char) ((unsigned short) c & 0xff));
586 ess_write (devc, 0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
587
588 ess_change (devc, 0xb8, 0x05, 0x05); /* Go */
589 devc->intr_active = 1;
590}
591
592static void ess_audio_output_block_audio2
593 (int dev, unsigned long buf, int nr_bytes, int intrflag)
594{
595 int count = nr_bytes;
596 sb_devc *devc = audio_devs[dev]->devc;
597 short c = -nr_bytes;
598
599 if (audio_devs[dev]->dmap_out->dma > 3) count >>= 1;
600 count--;
601
602 ess_setmixer (devc, 0x74, (unsigned char) ((unsigned short) c & 0xff));
603 ess_setmixer (devc, 0x76, (unsigned char) (((unsigned short) c >> 8) & 0xff));
604 ess_chgmixer (devc, 0x78, 0x03, 0x03); /* Go */
605
606 devc->irq_mode_16 = IMODE_OUTPUT;
607 devc->intr_active_16 = 1;
608}
609
610static void ess_audio_output_block
611 (int dev, unsigned long buf, int nr_bytes, int intrflag)
612{
613 sb_devc *devc = audio_devs[dev]->devc;
614
615 if (devc->duplex) {
616 ess_audio_output_block_audio2 (dev, buf, nr_bytes, intrflag);
617 } else {
618 ess_audio_output_block_audio1 (dev, buf, nr_bytes, intrflag);
619 }
620}
621
622/*
623 * FKS: the if-statements for both bits and bits_16 are quite alike.
624 * Combine this...
625 */
626static void ess_audio_trigger(int dev, int bits)
627{
628 sb_devc *devc = audio_devs[dev]->devc;
629
630 int bits_16 = bits & devc->irq_mode_16;
631 bits &= devc->irq_mode;
632
633 if (!bits && !bits_16) {
634 /* FKS oh oh.... wrong?? for dma 16? */
635 sb_dsp_command(devc, 0xd0); /* Halt DMA */
636 }
637
638 if (bits) {
639 switch (devc->irq_mode)
640 {
641 case IMODE_INPUT:
642 ess_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
643 devc->trg_intrflag);
644 break;
645
646 case IMODE_OUTPUT:
647 ess_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
648 devc->trg_intrflag);
649 break;
650 }
651 }
652
653 if (bits_16) {
654 switch (devc->irq_mode_16) {
655 case IMODE_INPUT:
656 ess_audio_start_input(dev, devc->trg_buf_16, devc->trg_bytes_16,
657 devc->trg_intrflag_16);
658 break;
659
660 case IMODE_OUTPUT:
661 ess_audio_output_block(dev, devc->trg_buf_16, devc->trg_bytes_16,
662 devc->trg_intrflag_16);
663 break;
664 }
665 }
666
667 devc->trigger_bits = bits | bits_16;
668}
669
670static int ess_audio_set_speed(int dev, int speed)
671{
672 sb_devc *devc = audio_devs[dev]->devc;
673 int minspeed, maxspeed, dummydiv;
674
675 if (speed > 0) {
676 minspeed = (devc->duplex ? 6215 : 5000 );
677 maxspeed = (devc->duplex ? 44100 : 48000);
678 if (speed < minspeed) speed = minspeed;
679 if (speed > maxspeed) speed = maxspeed;
680
681 ess_common_speed (devc, &speed, &dummydiv);
682
683 devc->speed = speed;
684 }
685 return devc->speed;
686}
687
688/*
689 * FKS: This is a one-on-one copy of sb1_audio_set_bits
690 */
691static unsigned int ess_audio_set_bits(int dev, unsigned int bits)
692{
693 sb_devc *devc = audio_devs[dev]->devc;
694
695 if (bits != 0) {
696 if (bits == AFMT_U8 || bits == AFMT_S16_LE) {
697 devc->bits = bits;
698 } else {
699 devc->bits = AFMT_U8;
700 }
701 }
702
703 return devc->bits;
704}
705
706/*
707 * FKS: This is a one-on-one copy of sbpro_audio_set_channels
708 * (*) Modified it!!
709 */
710static short ess_audio_set_channels(int dev, short channels)
711{
712 sb_devc *devc = audio_devs[dev]->devc;
713
714 if (channels == 1 || channels == 2) devc->channels = channels;
715
716 return devc->channels;
717}
718
719static struct audio_driver ess_audio_driver = /* ESS ES688/1688 */
720{
721 .owner = THIS_MODULE,
722 .open = sb_audio_open,
723 .close = sb_audio_close,
724 .output_block = ess_set_output_parms,
725 .start_input = ess_set_input_parms,
726 .prepare_for_input = ess_audio_prepare_for_input,
727 .prepare_for_output = ess_audio_prepare_for_output,
728 .halt_io = ess_audio_halt_xfer,
729 .trigger = ess_audio_trigger,
730 .set_speed = ess_audio_set_speed,
731 .set_bits = ess_audio_set_bits,
732 .set_channels = ess_audio_set_channels
733};
734
735/*
736 * ess_audio_init must be called from sb_audio_init
737 */
738struct audio_driver *ess_audio_init
739 (sb_devc *devc, int *audio_flags, int *format_mask)
740{
741 *audio_flags = DMA_AUTOMODE;
742 *format_mask |= AFMT_S16_LE;
743
744 if (devc->duplex) {
745 int tmp_dma;
746 /*
747 * sb_audio_init thinks dma8 is for playback and
748 * dma16 is for record. Not now! So swap them.
749 */
750 tmp_dma = devc->dma16;
751 devc->dma16 = devc->dma8;
752 devc->dma8 = tmp_dma;
753
754 *audio_flags |= DMA_DUPLEX;
755 }
756
757 return &ess_audio_driver;
758}
759
760/****************************************************************************
761 * *
762 * ESS common *
763 * *
764 ****************************************************************************/
765static void ess_handle_channel
766 (char *channel, int dev, int intr_active, unsigned char flag, int irq_mode)
767{
768 if (!intr_active || !flag) return;
769#ifdef FKS_REG_LOGGING
770printk(KERN_INFO "FKS: ess_handle_channel %s irq_mode=%d\n", channel, irq_mode);
771#endif
772 switch (irq_mode) {
773 case IMODE_OUTPUT:
774 DMAbuf_outputintr (dev, 1);
775 break;
776
777 case IMODE_INPUT:
778 DMAbuf_inputintr (dev);
779 break;
780
781 case IMODE_INIT:
782 break;
783
784 default:;
785 /* printk(KERN_WARNING "ESS: Unexpected interrupt\n"); */
786 }
787}
788
789/*
790 * FKS: TODO!!! Finish this!
791 *
792 * I think midi stuff uses uart401, without interrupts.
793 * So IMODE_MIDI isn't a value for devc->irq_mode.
794 */
795void ess_intr (sb_devc *devc)
796{
797 int status;
798 unsigned char src;
799
800 if (devc->submodel == SUBMDL_ES1887) {
801 src = ess_getmixer (devc, 0x7f) >> 4;
802 } else {
803 src = 0xff;
804 }
805
806#ifdef FKS_REG_LOGGING
807printk(KERN_INFO "FKS: sbintr src=%x\n",(int)src);
808#endif
809 ess_handle_channel
810 ( "Audio 1"
811 , devc->dev, devc->intr_active , src & 0x01, devc->irq_mode );
812 ess_handle_channel
813 ( "Audio 2"
814 , devc->dev, devc->intr_active_16, src & 0x02, devc->irq_mode_16);
815 /*
816 * Acknowledge interrupts
817 */
818 if (devc->submodel == SUBMDL_ES1887 && (src & 0x02)) {
819 ess_chgmixer (devc, 0x7a, 0x80, 0x00);
820 }
821
822 if (src & 0x01) {
823 status = inb(DSP_DATA_AVAIL);
824 }
825}
826
827static void ess_extended (sb_devc * devc)
828{
829 /* Enable extended mode */
830
831 sb_dsp_command(devc, 0xc6);
832}
833
834static int ess_write (sb_devc * devc, unsigned char reg, unsigned char data)
835{
836#ifdef FKS_REG_LOGGING
837printk(KERN_INFO "FKS: write reg %x: %x\n", reg, data);
838#endif
839 /* Write a byte to an extended mode register of ES1688 */
840
841 if (!sb_dsp_command(devc, reg))
842 return 0;
843
844 return sb_dsp_command(devc, data);
845}
846
847static int ess_read (sb_devc * devc, unsigned char reg)
848{
849 /* Read a byte from an extended mode register of ES1688 */
850
851 /* Read register command */
852 if (!sb_dsp_command(devc, 0xc0)) return -1;
853
854 if (!sb_dsp_command(devc, reg )) return -1;
855
856 return sb_dsp_get_byte(devc);
857}
858
859int ess_dsp_reset(sb_devc * devc)
860{
861 int loopc;
862
863#ifdef FKS_REG_LOGGING
864printk(KERN_INFO "FKS: ess_dsp_reset 1\n");
865ess_show_mixerregs (devc);
866#endif
867
868 outb(3, DSP_RESET); /* Reset FIFO too */
869
870 udelay(10);
871 outb(0, DSP_RESET);
872 udelay(30);
873
874 for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
875
876 if (inb(DSP_READ) != 0xAA) {
877 DDB(printk("sb: No response to RESET\n"));
878 return 0; /* Sorry */
879 }
880 ess_extended (devc);
881
882#ifdef FKS_LOGGING
883printk(KERN_INFO "FKS: dsp_reset 2\n");
884ess_show_mixerregs (devc);
885#endif
886
887 return 1;
888}
889
890static int ess_irq_bits (int irq)
891{
892 switch (irq) {
893 case 2:
894 case 9:
895 return 0;
896
897 case 5:
898 return 1;
899
900 case 7:
901 return 2;
902
903 case 10:
904 return 3;
905
906 default:
907 printk(KERN_ERR "ESS1688: Invalid IRQ %d\n", irq);
908 return -1;
909 }
910}
911
912/*
913 * Set IRQ configuration register for all ESS models
914 */
915static int ess_common_set_irq_hw (sb_devc * devc)
916{
917 int irq_bits;
918
919 if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return 0;
920
921 if (!ess_write (devc, 0xb1, 0x50 | (irq_bits << 2))) {
922 printk(KERN_ERR "ES1688: Failed to write to IRQ config register\n");
923 return 0;
924 }
925 return 1;
926}
927
928/*
929 * I wanna use modern ES1887 mixer irq handling. Funny is the
930 * fact that my BIOS wants the same. But suppose someone's BIOS
931 * doesn't do this!
932 * This is independent of duplex. If there's a 1887 this will
933 * prevent it from going into 1888 mode.
934 */
935static void ess_es1887_set_irq_hw (sb_devc * devc)
936{
937 int irq_bits;
938
939 if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return;
940
941 ess_chgmixer (devc, 0x7f, 0x0f, 0x01 | ((irq_bits + 1) << 1));
942}
943
944static int ess_set_irq_hw (sb_devc * devc)
945{
946 if (devc->submodel == SUBMDL_ES1887) ess_es1887_set_irq_hw (devc);
947
948 return ess_common_set_irq_hw (devc);
949}
950
951#ifdef FKS_TEST
952
953/*
954 * FKS_test:
955 * for ES1887: 00, 18, non wr bits: 0001 1000
956 * for ES1868: 00, b8, non wr bits: 1011 1000
957 * for ES1888: 00, f8, non wr bits: 1111 1000
958 * for ES1688: 00, f8, non wr bits: 1111 1000
959 * + ES968
960 */
961
962static void FKS_test (sb_devc * devc)
963{
964 int val1, val2;
965 val1 = ess_getmixer (devc, 0x64);
966 ess_setmixer (devc, 0x64, ~val1);
967 val2 = ess_getmixer (devc, 0x64) ^ ~val1;
968 ess_setmixer (devc, 0x64, val1);
969 val1 ^= ess_getmixer (devc, 0x64);
970printk (KERN_INFO "FKS: FKS_test %02x, %02x\n", (val1 & 0x0ff), (val2 & 0x0ff));
971};
972#endif
973
974static unsigned int ess_identify (sb_devc * devc)
975{
976 unsigned int val;
977 unsigned long flags;
978
979 spin_lock_irqsave(&devc->lock, flags);
980 outb(((unsigned char) (0x40 & 0xff)), MIXER_ADDR);
981
982 udelay(20);
983 val = inb(MIXER_DATA) << 8;
984 udelay(20);
985 val |= inb(MIXER_DATA);
986 udelay(20);
987 spin_unlock_irqrestore(&devc->lock, flags);
988
989 return val;
990}
991
992/*
993 * ESS technology describes a detection scheme in their docs. It involves
994 * fiddling with the bits in certain mixer registers. ess_probe is supposed
995 * to help.
996 *
997 * FKS: tracing shows ess_probe writes wrong value to 0x64. Bit 3 reads 1, but
998 * should be written 0 only. Check this.
999 */
1000static int ess_probe (sb_devc * devc, int reg, int xorval)
1001{
1002 int val1, val2, val3;
1003
1004 val1 = ess_getmixer (devc, reg);
1005 val2 = val1 ^ xorval;
1006 ess_setmixer (devc, reg, val2);
1007 val3 = ess_getmixer (devc, reg);
1008 ess_setmixer (devc, reg, val1);
1009
1010 return (val2 == val3);
1011}
1012
1013int ess_init(sb_devc * devc, struct address_info *hw_config)
1014{
1015 unsigned char cfg;
1016 int ess_major = 0, ess_minor = 0;
1017 int i;
1018 static char name[100], modelname[10];
1019
1020 /*
1021 * Try to detect ESS chips.
1022 */
1023
1024 sb_dsp_command(devc, 0xe7); /* Return identification */
1025
1026 for (i = 1000; i; i--) {
1027 if (inb(DSP_DATA_AVAIL) & 0x80) {
1028 if (ess_major == 0) {
1029 ess_major = inb(DSP_READ);
1030 } else {
1031 ess_minor = inb(DSP_READ);
1032 break;
1033 }
1034 }
1035 }
1036
1037 if (ess_major == 0) return 0;
1038
1039 if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80) {
1040 sprintf(name, "ESS ES488 AudioDrive (rev %d)",
1041 ess_minor & 0x0f);
1042 hw_config->name = name;
1043 devc->model = MDL_SBPRO;
1044 return 1;
1045 }
1046
1047 /*
1048 * This the detection heuristic of ESS technology, though somewhat
1049 * changed to actually make it work.
1050 * This results in the following detection steps:
1051 * - distinct between ES688 and ES1688+ (as always done in this driver)
1052 * if ES688 we're ready
1053 * - try to detect ES1868, ES1869 or ES1878 (ess_identify)
1054 * if successful we're ready
1055 * - try to detect ES1888, ES1887 or ES1788 (aim: detect ES1887)
1056 * if successful we're ready
1057 * - Dunno. Must be 1688. Will do in general
1058 *
1059 * This is the most BETA part of the software: Will the detection
1060 * always work?
1061 */
1062 devc->model = MDL_ESS;
1063 devc->submodel = ess_minor & 0x0f;
1064
1065 if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80) {
1066 char *chip = NULL;
1067 int submodel = -1;
1068
1069 switch (devc->sbmo.esstype) {
1070 case ESSTYPE_DETECT:
1071 case ESSTYPE_LIKE20:
1072 break;
1073 case 688:
1074 submodel = 0x00;
1075 break;
1076 case 1688:
1077 submodel = 0x08;
1078 break;
1079 case 1868:
1080 submodel = SUBMDL_ES1868;
1081 break;
1082 case 1869:
1083 submodel = SUBMDL_ES1869;
1084 break;
1085 case 1788:
1086 submodel = SUBMDL_ES1788;
1087 break;
1088 case 1878:
1089 submodel = SUBMDL_ES1878;
1090 break;
1091 case 1879:
1092 submodel = SUBMDL_ES1879;
1093 break;
1094 case 1887:
1095 submodel = SUBMDL_ES1887;
1096 break;
1097 case 1888:
1098 submodel = SUBMDL_ES1888;
1099 break;
1100 default:
1101 printk (KERN_ERR "Invalid esstype=%d specified\n", devc->sbmo.esstype);
1102 return 0;
1103 }
1104 if (submodel != -1) {
1105 devc->submodel = submodel;
1106 sprintf (modelname, "ES%d", devc->sbmo.esstype);
1107 chip = modelname;
1108 }
1109 if (chip == NULL && (ess_minor & 0x0f) < 8) {
1110 chip = "ES688";
1111 }
1112#ifdef FKS_TEST
1113FKS_test (devc);
1114#endif
1115 /*
1116 * If Nothing detected yet, and we want 2.0 behaviour...
1117 * Then let's assume it's ES1688.
1118 */
1119 if (chip == NULL && devc->sbmo.esstype == ESSTYPE_LIKE20) {
1120 chip = "ES1688";
1121 }
1122
1123 if (chip == NULL) {
1124 int type;
1125
1126 type = ess_identify (devc);
1127
1128 switch (type) {
1129 case 0x1868:
1130 chip = "ES1868";
1131 devc->submodel = SUBMDL_ES1868;
1132 break;
1133 case 0x1869:
1134 chip = "ES1869";
1135 devc->submodel = SUBMDL_ES1869;
1136 break;
1137 case 0x1878:
1138 chip = "ES1878";
1139 devc->submodel = SUBMDL_ES1878;
1140 break;
1141 case 0x1879:
1142 chip = "ES1879";
1143 devc->submodel = SUBMDL_ES1879;
1144 break;
1145 default:
1146 if ((type & 0x00ff) != ((type >> 8) & 0x00ff)) {
1147 printk ("ess_init: Unrecognized %04x\n", type);
1148 }
1149 }
1150 }
1151#if 0
1152 /*
1153 * this one failed:
1154 * the probing of bit 4 is another thought: from ES1788 and up, all
1155 * chips seem to have hardware volume control. Bit 4 is readonly to
1156 * check if a hardware volume interrupt has fired.
1157 * Cause ES688/ES1688 don't have this feature, bit 4 might be writeable
1158 * for these chips.
1159 */
1160 if (chip == NULL && !ess_probe(devc, 0x64, (1 << 4))) {
1161#endif
1162 /*
1163 * the probing of bit 2 is my idea. The ES1887 docs want me to probe
1164 * bit 3. This results in ES1688 being detected as ES1788.
1165 * Bit 2 is for "Enable HWV IRQE", but as ES(1)688 chips don't have
1166 * HardWare Volume, I think they don't have this IRQE.
1167 */
1168 if (chip == NULL && ess_probe(devc, 0x64, (1 << 2))) {
1169 if (ess_probe (devc, 0x70, 0x7f)) {
1170 if (ess_probe (devc, 0x64, (1 << 5))) {
1171 chip = "ES1887";
1172 devc->submodel = SUBMDL_ES1887;
1173 } else {
1174 chip = "ES1888";
1175 devc->submodel = SUBMDL_ES1888;
1176 }
1177 } else {
1178 chip = "ES1788";
1179 devc->submodel = SUBMDL_ES1788;
1180 }
1181 }
1182 if (chip == NULL) {
1183 chip = "ES1688";
1184 }
1185
1186 printk(KERN_INFO "ESS chip %s %s%s\n", chip,
1187 (devc->sbmo.esstype == ESSTYPE_DETECT ||
1188 devc->sbmo.esstype == ESSTYPE_LIKE20) ?
1189 "detected" : "specified",
1190 devc->sbmo.esstype == ESSTYPE_LIKE20 ?
1191 " (kernel 2.0 compatible)" : "");
1192
1193 sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f);
1194 } else {
1195 strcpy(name, "Jazz16");
1196 }
1197
1198 /* AAS: info stolen from ALSA: these boards have different clocks */
1199 switch(devc->submodel) {
1200/* APPARENTLY NOT 1869 AND 1887
1201 case SUBMDL_ES1869:
1202 case SUBMDL_ES1887:
1203*/
1204 case SUBMDL_ES1888:
1205 devc->caps |= SB_CAP_ES18XX_RATE;
1206 break;
1207 }
1208
1209 hw_config->name = name;
1210 /* FKS: sb_dsp_reset to enable extended mode???? */
1211 sb_dsp_reset(devc); /* Turn on extended mode */
1212
1213 /*
1214 * Enable joystick and OPL3
1215 */
1216 cfg = ess_getmixer (devc, 0x40);
1217 ess_setmixer (devc, 0x40, cfg | 0x03);
1218 if (devc->submodel >= 8) { /* ES1688 */
1219 devc->caps |= SB_NO_MIDI; /* ES1688 uses MPU401 MIDI mode */
1220 }
1221 sb_dsp_reset (devc);
1222
1223 /*
1224 * This is important! If it's not done, the IRQ probe in sb_dsp_init
1225 * may fail.
1226 */
1227 return ess_set_irq_hw (devc);
1228}
1229
1230static int ess_set_dma_hw(sb_devc * devc)
1231{
1232 unsigned char cfg, dma_bits = 0, dma16_bits;
1233 int dma;
1234
1235#ifdef FKS_LOGGING
1236printk(KERN_INFO "ess_set_dma_hw: dma8=%d,dma16=%d,dup=%d\n"
1237, devc->dma8, devc->dma16, devc->duplex);
1238#endif
1239
1240 /*
1241 * FKS: It seems as if this duplex flag isn't set yet. Check it.
1242 */
1243 dma = devc->dma8;
1244
1245 if (dma > 3 || dma < 0 || dma == 2) {
1246 dma_bits = 0;
1247 printk(KERN_ERR "ESS1688: Invalid DMA8 %d\n", dma);
1248 return 0;
1249 } else {
1250 /* Extended mode DMA enable */
1251 cfg = 0x50;
1252
1253 if (dma == 3) {
1254 dma_bits = 3;
1255 } else {
1256 dma_bits = dma + 1;
1257 }
1258 }
1259
1260 if (!ess_write (devc, 0xb2, cfg | (dma_bits << 2))) {
1261 printk(KERN_ERR "ESS1688: Failed to write to DMA config register\n");
1262 return 0;
1263 }
1264
1265 if (devc->duplex) {
1266 dma = devc->dma16;
1267 dma16_bits = 0;
1268
1269 if (dma >= 0) {
1270 switch (dma) {
1271 case 0:
1272 dma_bits = 0x04;
1273 break;
1274 case 1:
1275 dma_bits = 0x05;
1276 break;
1277 case 3:
1278 dma_bits = 0x06;
1279 break;
1280 case 5:
1281 dma_bits = 0x07;
1282 dma16_bits = 0x20;
1283 break;
1284 default:
1285 printk(KERN_ERR "ESS1887: Invalid DMA16 %d\n", dma);
1286 return 0;
1287 }
1288 ess_chgmixer (devc, 0x78, 0x20, dma16_bits);
1289 ess_chgmixer (devc, 0x7d, 0x07, dma_bits);
1290 }
1291 }
1292 return 1;
1293}
1294
1295/*
1296 * This one is called from sb_dsp_init.
1297 *
1298 * Return values:
1299 * 0: Failed
1300 * 1: Succeeded or doesn't apply (not SUBMDL_ES1887)
1301 */
1302int ess_dsp_init (sb_devc *devc, struct address_info *hw_config)
1303{
1304 /*
1305 * Caller also checks this, but anyway
1306 */
1307 if (devc->model != MDL_ESS) {
1308 printk (KERN_INFO "ess_dsp_init for non ESS chip\n");
1309 return 1;
1310 }
1311 /*
1312 * This for ES1887 to run Full Duplex. Actually ES1888
1313 * is allowed to do so too. I have no idea yet if this
1314 * will work for ES1888 however.
1315 *
1316 * For SB16 having both dma8 and dma16 means enable
1317 * Full Duplex. Let's try this for ES1887 too
1318 *
1319 */
1320 if (devc->submodel == SUBMDL_ES1887) {
1321 if (hw_config->dma2 != -1) {
1322 devc->dma16 = hw_config->dma2;
1323 }
1324 /*
1325 * devc->duplex initialization is put here, cause
1326 * ess_set_dma_hw needs it.
1327 */
1328 if (devc->dma8 != devc->dma16 && devc->dma16 != -1) {
1329 devc->duplex = 1;
1330 }
1331 }
1332 if (!ess_set_dma_hw (devc)) {
1333 free_irq(devc->irq, devc);
1334 return 0;
1335 }
1336 return 1;
1337}
1338
1339/****************************************************************************
1340 * *
1341 * ESS mixer *
1342 * *
1343 ****************************************************************************/
1344
1345#define ES688_RECORDING_DEVICES \
1346 ( SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD )
1347#define ES688_MIXER_DEVICES \
1348 ( SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE \
1349 | SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME \
1350 | SOUND_MASK_LINE2 | SOUND_MASK_SPEAKER )
1351
1352#define ES1688_RECORDING_DEVICES \
1353 ( ES688_RECORDING_DEVICES )
1354#define ES1688_MIXER_DEVICES \
1355 ( ES688_MIXER_DEVICES | SOUND_MASK_RECLEV )
1356
1357#define ES1887_RECORDING_DEVICES \
1358 ( ES1688_RECORDING_DEVICES | SOUND_MASK_LINE2 | SOUND_MASK_SYNTH)
1359#define ES1887_MIXER_DEVICES \
1360 ( ES1688_MIXER_DEVICES )
1361
1362/*
1363 * Mixer registers of ES1887
1364 *
1365 * These registers specifically take care of recording levels. To make the
1366 * mapping from playback devices to recording devices every recording
1367 * devices = playback device + ES_REC_MIXER_RECDIFF
1368 */
1369#define ES_REC_MIXER_RECBASE (SOUND_MIXER_LINE3 + 1)
1370#define ES_REC_MIXER_RECDIFF (ES_REC_MIXER_RECBASE - SOUND_MIXER_SYNTH)
1371
1372#define ES_REC_MIXER_RECSYNTH (SOUND_MIXER_SYNTH + ES_REC_MIXER_RECDIFF)
1373#define ES_REC_MIXER_RECPCM (SOUND_MIXER_PCM + ES_REC_MIXER_RECDIFF)
1374#define ES_REC_MIXER_RECSPEAKER (SOUND_MIXER_SPEAKER + ES_REC_MIXER_RECDIFF)
1375#define ES_REC_MIXER_RECLINE (SOUND_MIXER_LINE + ES_REC_MIXER_RECDIFF)
1376#define ES_REC_MIXER_RECMIC (SOUND_MIXER_MIC + ES_REC_MIXER_RECDIFF)
1377#define ES_REC_MIXER_RECCD (SOUND_MIXER_CD + ES_REC_MIXER_RECDIFF)
1378#define ES_REC_MIXER_RECIMIX (SOUND_MIXER_IMIX + ES_REC_MIXER_RECDIFF)
1379#define ES_REC_MIXER_RECALTPCM (SOUND_MIXER_ALTPCM + ES_REC_MIXER_RECDIFF)
1380#define ES_REC_MIXER_RECRECLEV (SOUND_MIXER_RECLEV + ES_REC_MIXER_RECDIFF)
1381#define ES_REC_MIXER_RECIGAIN (SOUND_MIXER_IGAIN + ES_REC_MIXER_RECDIFF)
1382#define ES_REC_MIXER_RECOGAIN (SOUND_MIXER_OGAIN + ES_REC_MIXER_RECDIFF)
1383#define ES_REC_MIXER_RECLINE1 (SOUND_MIXER_LINE1 + ES_REC_MIXER_RECDIFF)
1384#define ES_REC_MIXER_RECLINE2 (SOUND_MIXER_LINE2 + ES_REC_MIXER_RECDIFF)
1385#define ES_REC_MIXER_RECLINE3 (SOUND_MIXER_LINE3 + ES_REC_MIXER_RECDIFF)
1386
1387static mixer_tab es688_mix = {
1388MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
1389MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1390MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1391MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1392MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1393MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1394MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1395MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1396MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1397MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1398MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1399MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0),
1400MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1401MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1402MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1403MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1404MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1405};
1406
1407/*
1408 * The ES1688 specifics... hopefully correct...
1409 * - 6 bit master volume
1410 * I was wrong, ES1888 docs say ES1688 didn't have it.
1411 * - RECLEV control
1412 * These may apply to ES688 too. I have no idea.
1413 */
1414static mixer_tab es1688_mix = {
1415MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
1416MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1417MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1418MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1419MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1420MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1421MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1422MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1423MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1424MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1425MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1426MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1427MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1428MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1429MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1430MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1431MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1432};
1433
1434static mixer_tab es1688later_mix = {
1435MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1436MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1437MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1438MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1439MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1440MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1441MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1442MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1443MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1444MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1445MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1446MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1447MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1448MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1449MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1450MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1451MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1452};
1453
1454/*
1455 * This one is for all ESS chips with a record mixer.
1456 * It's not used (yet) however
1457 */
1458static mixer_tab es_rec_mix = {
1459MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1460MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1461MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1462MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1463MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1464MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1465MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1466MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1467MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1468MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1469MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1470MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1471MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1472MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1473MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1474MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1475MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
1476MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
1477MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
1478MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
1479MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
1480MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
1481MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
1482MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
1483MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1484MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
1485MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
1486MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
1487MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
1488MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
1489MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
1490};
1491
1492/*
1493 * This one is for ES1887. It's little different from es_rec_mix: it
1494 * has 0x7c for PCM playback level. This is because ES1887 uses
1495 * Audio 2 for playback.
1496 */
1497static mixer_tab es1887_mix = {
1498MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1499MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1500MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1501MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1502MIX_ENT(SOUND_MIXER_PCM, 0x7c, 7, 4, 0x7c, 3, 4),
1503MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1504MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1505MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1506MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1507MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1508MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1509MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1510MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1511MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1512MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1513MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1514MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
1515MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
1516MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
1517MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
1518MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
1519MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
1520MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
1521MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
1522MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1523MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
1524MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
1525MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
1526MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
1527MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
1528MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
1529};
1530
1531static int ess_has_rec_mixer (int submodel)
1532{
1533 switch (submodel) {
1534 case SUBMDL_ES1887:
1535 return 1;
1536 default:
1537 return 0;
1538 }
1539};
1540
1541#ifdef FKS_LOGGING
1542static int ess_mixer_mon_regs[]
1543 = { 0x70, 0x71, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7d, 0x7f
1544 , 0xa1, 0xa2, 0xa4, 0xa5, 0xa8, 0xa9
1545 , 0xb1, 0xb2, 0xb4, 0xb5, 0xb6, 0xb7, 0xb9
1546 , 0x00};
1547
1548static void ess_show_mixerregs (sb_devc *devc)
1549{
1550 int *mp = ess_mixer_mon_regs;
1551
1552return;
1553
1554 while (*mp != 0) {
1555 printk (KERN_INFO "res (%x)=%x\n", *mp, (int)(ess_getmixer (devc, *mp)));
1556 mp++;
1557 }
1558}
1559#endif
1560
1561void ess_setmixer (sb_devc * devc, unsigned int port, unsigned int value)
1562{
1563 unsigned long flags;
1564
1565#ifdef FKS_LOGGING
1566printk(KERN_INFO "FKS: write mixer %x: %x\n", port, value);
1567#endif
1568
1569 spin_lock_irqsave(&devc->lock, flags);
1570 if (port >= 0xa0) {
1571 ess_write (devc, port, value);
1572 } else {
1573 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
1574
1575 udelay(20);
1576 outb(((unsigned char) (value & 0xff)), MIXER_DATA);
1577 udelay(20);
1578 }
1579 spin_unlock_irqrestore(&devc->lock, flags);
1580}
1581
1582unsigned int ess_getmixer (sb_devc * devc, unsigned int port)
1583{
1584 unsigned int val;
1585 unsigned long flags;
1586
1587 spin_lock_irqsave(&devc->lock, flags);
1588
1589 if (port >= 0xa0) {
1590 val = ess_read (devc, port);
1591 } else {
1592 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
1593
1594 udelay(20);
1595 val = inb(MIXER_DATA);
1596 udelay(20);
1597 }
1598 spin_unlock_irqrestore(&devc->lock, flags);
1599
1600 return val;
1601}
1602
1603static void ess_chgmixer
1604 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
1605{
1606 int value;
1607
1608 value = ess_getmixer (devc, reg);
1609 value = (value & ~mask) | (val & mask);
1610 ess_setmixer (devc, reg, value);
1611}
1612
1613/*
1614 * ess_mixer_init must be called from sb_mixer_init
1615 */
1616void ess_mixer_init (sb_devc * devc)
1617{
1618 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
1619
1620 /*
1621 * Take care of ES1887 specifics...
1622 */
1623 switch (devc->submodel) {
1624 case SUBMDL_ES1887:
1625 devc->supported_devices = ES1887_MIXER_DEVICES;
1626 devc->supported_rec_devices = ES1887_RECORDING_DEVICES;
1627#ifdef FKS_LOGGING
1628printk (KERN_INFO "FKS: ess_mixer_init dup = %d\n", devc->duplex);
1629#endif
1630 if (devc->duplex) {
1631 devc->iomap = &es1887_mix;
1632 devc->iomap_sz = ARRAY_SIZE(es1887_mix);
1633 } else {
1634 devc->iomap = &es_rec_mix;
1635 devc->iomap_sz = ARRAY_SIZE(es_rec_mix);
1636 }
1637 break;
1638 default:
1639 if (devc->submodel < 8) {
1640 devc->supported_devices = ES688_MIXER_DEVICES;
1641 devc->supported_rec_devices = ES688_RECORDING_DEVICES;
1642 devc->iomap = &es688_mix;
1643 devc->iomap_sz = ARRAY_SIZE(es688_mix);
1644 } else {
1645 /*
1646 * es1688 has 4 bits master vol.
1647 * later chips have 6 bits (?)
1648 */
1649 devc->supported_devices = ES1688_MIXER_DEVICES;
1650 devc->supported_rec_devices = ES1688_RECORDING_DEVICES;
1651 if (devc->submodel < 0x10) {
1652 devc->iomap = &es1688_mix;
1653 devc->iomap_sz = ARRAY_SIZE(es688_mix);
1654 } else {
1655 devc->iomap = &es1688later_mix;
1656 devc->iomap_sz = ARRAY_SIZE(es1688later_mix);
1657 }
1658 }
1659 }
1660}
1661
1662/*
1663 * Changing playback levels at an ESS chip with record mixer means having to
1664 * take care of recording levels of recorded inputs (devc->recmask) too!
1665 */
1666int ess_mixer_set(sb_devc *devc, int dev, int left, int right)
1667{
1668 if (ess_has_rec_mixer (devc->submodel) && (devc->recmask & (1 << dev))) {
1669 sb_common_mixer_set (devc, dev + ES_REC_MIXER_RECDIFF, left, right);
1670 }
1671 return sb_common_mixer_set (devc, dev, left, right);
1672}
1673
1674/*
1675 * After a sb_dsp_reset extended register 0xb4 (RECLEV) is reset too. After
1676 * sb_dsp_reset RECLEV has to be restored. This is where ess_mixer_reload
1677 * helps.
1678 */
1679void ess_mixer_reload (sb_devc *devc, int dev)
1680{
1681 int left, right, value;
1682
1683 value = devc->levels[dev];
1684 left = value & 0x000000ff;
1685 right = (value & 0x0000ff00) >> 8;
1686
1687 sb_common_mixer_set(devc, dev, left, right);
1688}
1689
1690static int es_rec_set_recmask(sb_devc * devc, int mask)
1691{
1692 int i, i_mask, cur_mask, diff_mask;
1693 int value, left, right;
1694
1695#ifdef FKS_LOGGING
1696printk (KERN_INFO "FKS: es_rec_set_recmask mask = %x\n", mask);
1697#endif
1698 /*
1699 * Changing the recmask on an ESS chip with recording mixer means:
1700 * (1) Find the differences
1701 * (2) For "turned-on" inputs: make the recording level the playback level
1702 * (3) For "turned-off" inputs: make the recording level zero
1703 */
1704 cur_mask = devc->recmask;
1705 diff_mask = (cur_mask ^ mask);
1706
1707 for (i = 0; i < 32; i++) {
1708 i_mask = (1 << i);
1709 if (diff_mask & i_mask) { /* Difference? (1) */
1710 if (mask & i_mask) { /* Turn it on (2) */
1711 value = devc->levels[i];
1712 left = value & 0x000000ff;
1713 right = (value & 0x0000ff00) >> 8;
1714 } else { /* Turn it off (3) */
1715 left = 0;
1716 right = 0;
1717 }
1718 sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right);
1719 }
1720 }
1721 return mask;
1722}
1723
1724int ess_set_recmask(sb_devc * devc, int *mask)
1725{
1726 /* This applies to ESS chips with record mixers only! */
1727
1728 if (ess_has_rec_mixer (devc->submodel)) {
1729 *mask = es_rec_set_recmask (devc, *mask);
1730 return 1; /* Applied */
1731 } else {
1732 return 0; /* Not applied */
1733 }
1734}
1735
1736/*
1737 * ess_mixer_reset must be called from sb_mixer_reset
1738 */
1739int ess_mixer_reset (sb_devc * devc)
1740{
1741 /*
1742 * Separate actions for ESS chips with a record mixer:
1743 */
1744 if (ess_has_rec_mixer (devc->submodel)) {
1745 switch (devc->submodel) {
1746 case SUBMDL_ES1887:
1747 /*
1748 * Separate actions for ES1887:
1749 * Change registers 7a and 1c to make the record mixer the
1750 * actual recording source.
1751 */
1752 ess_chgmixer(devc, 0x7a, 0x18, 0x08);
1753 ess_chgmixer(devc, 0x1c, 0x07, 0x07);
1754 break;
1755 }
1756 /*
1757 * Call set_recmask for proper initialization
1758 */
1759 devc->recmask = devc->supported_rec_devices;
1760 es_rec_set_recmask(devc, 0);
1761 devc->recmask = 0;
1762
1763 return 1; /* We took care of recmask. */
1764 } else {
1765 return 0; /* We didn't take care; caller do it */
1766 }
1767}
1768
1769/****************************************************************************
1770 * *
1771 * ESS midi *
1772 * *
1773 ****************************************************************************/
1774
1775/*
1776 * FKS: IRQ may be shared. Hm. And if so? Then What?
1777 */
1778int ess_midi_init(sb_devc * devc, struct address_info *hw_config)
1779{
1780 unsigned char cfg, tmp;
1781
1782 cfg = ess_getmixer (devc, 0x40) & 0x03;
1783
1784 if (devc->submodel < 8) {
1785 ess_setmixer (devc, 0x40, cfg | 0x03); /* Enable OPL3 & joystick */
1786 return 0; /* ES688 doesn't support MPU401 mode */
1787 }
1788 tmp = (hw_config->io_base & 0x0f0) >> 4;
1789
1790 if (tmp > 3) {
1791 ess_setmixer (devc, 0x40, cfg);
1792 return 0;
1793 }
1794 cfg |= tmp << 3;
1795
1796 tmp = 1; /* MPU enabled without interrupts */
1797
1798 /* May be shared: if so the value is -ve */
1799
1800 switch (abs(hw_config->irq)) {
1801 case 9:
1802 tmp = 0x4;
1803 break;
1804 case 5:
1805 tmp = 0x5;
1806 break;
1807 case 7:
1808 tmp = 0x6;
1809 break;
1810 case 10:
1811 tmp = 0x7;
1812 break;
1813 default:
1814 return 0;
1815 }
1816
1817 cfg |= tmp << 5;
1818 ess_setmixer (devc, 0x40, cfg | 0x03);
1819
1820 return 1;
1821}
1822
diff --git a/sound/oss/sb_ess.h b/sound/oss/sb_ess.h
deleted file mode 100644
index 38aa072e01f2..000000000000
--- a/sound/oss/sb_ess.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * Created: 9-Jan-1999 Rolf Fokkens
3 */
4
5extern void ess_intr
6 (sb_devc *devc);
7extern int ess_dsp_init
8 (sb_devc *devc, struct address_info *hw_config);
9
10extern struct audio_driver *ess_audio_init
11 (sb_devc *devc, int *audio_flags, int *format_mask);
12extern int ess_midi_init
13 (sb_devc *devc, struct address_info *hw_config);
14extern void ess_mixer_init
15 (sb_devc *devc);
16
17extern int ess_init
18 (sb_devc *devc, struct address_info *hw_config);
19extern int ess_dsp_reset
20 (sb_devc *devc);
21
22extern void ess_setmixer
23 (sb_devc *devc, unsigned int port, unsigned int value);
24extern unsigned int ess_getmixer
25 (sb_devc *devc, unsigned int port);
26extern int ess_mixer_set
27 (sb_devc *devc, int dev, int left, int right);
28extern int ess_mixer_reset
29 (sb_devc *devc);
30extern void ess_mixer_reload
31 (sb_devc * devc, int dev);
32extern int ess_set_recmask
33 (sb_devc *devc, int *mask);
34
diff --git a/sound/oss/sb_midi.c b/sound/oss/sb_midi.c
deleted file mode 100644
index 551ee7557b4e..000000000000
--- a/sound/oss/sb_midi.c
+++ /dev/null
@@ -1,206 +0,0 @@
1/*
2 * sound/oss/sb_midi.c
3 *
4 * The low level driver for the Sound Blaster DS chips.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13
14#include <linux/spinlock.h>
15#include <linux/slab.h>
16
17#include "sound_config.h"
18
19#include "sb.h"
20#undef SB_TEST_IRQ
21
22/*
23 * The DSP channel can be used either for input or output. Variable
24 * 'sb_irq_mode' will be set when the program calls read or write first time
25 * after open. Current version doesn't support mode changes without closing
26 * and reopening the device. Support for this feature may be implemented in a
27 * future version of this driver.
28 */
29
30
31static int sb_midi_open(int dev, int mode,
32 void (*input) (int dev, unsigned char data),
33 void (*output) (int dev)
34)
35{
36 sb_devc *devc = midi_devs[dev]->devc;
37 unsigned long flags;
38
39 if (devc == NULL)
40 return -ENXIO;
41
42 spin_lock_irqsave(&devc->lock, flags);
43 if (devc->opened)
44 {
45 spin_unlock_irqrestore(&devc->lock, flags);
46 return -EBUSY;
47 }
48 devc->opened = 1;
49 spin_unlock_irqrestore(&devc->lock, flags);
50
51 devc->irq_mode = IMODE_MIDI;
52 devc->midi_broken = 0;
53
54 sb_dsp_reset(devc);
55
56 if (!sb_dsp_command(devc, 0x35)) /* Start MIDI UART mode */
57 {
58 devc->opened = 0;
59 return -EIO;
60 }
61 devc->intr_active = 1;
62
63 if (mode & OPEN_READ)
64 {
65 devc->input_opened = 1;
66 devc->midi_input_intr = input;
67 }
68 return 0;
69}
70
71static void sb_midi_close(int dev)
72{
73 sb_devc *devc = midi_devs[dev]->devc;
74 unsigned long flags;
75
76 if (devc == NULL)
77 return;
78
79 spin_lock_irqsave(&devc->lock, flags);
80 sb_dsp_reset(devc);
81 devc->intr_active = 0;
82 devc->input_opened = 0;
83 devc->opened = 0;
84 spin_unlock_irqrestore(&devc->lock, flags);
85}
86
87static int sb_midi_out(int dev, unsigned char midi_byte)
88{
89 sb_devc *devc = midi_devs[dev]->devc;
90
91 if (devc == NULL)
92 return 1;
93
94 if (devc->midi_broken)
95 return 1;
96
97 if (!sb_dsp_command(devc, midi_byte))
98 {
99 devc->midi_broken = 1;
100 return 1;
101 }
102 return 1;
103}
104
105static int sb_midi_start_read(int dev)
106{
107 return 0;
108}
109
110static int sb_midi_end_read(int dev)
111{
112 sb_devc *devc = midi_devs[dev]->devc;
113
114 if (devc == NULL)
115 return -ENXIO;
116
117 sb_dsp_reset(devc);
118 devc->intr_active = 0;
119 return 0;
120}
121
122static int sb_midi_ioctl(int dev, unsigned cmd, void __user *arg)
123{
124 return -EINVAL;
125}
126
127void sb_midi_interrupt(sb_devc * devc)
128{
129 unsigned long flags;
130 unsigned char data;
131
132 if (devc == NULL)
133 return;
134
135 spin_lock_irqsave(&devc->lock, flags);
136
137 data = inb(DSP_READ);
138 if (devc->input_opened)
139 devc->midi_input_intr(devc->my_mididev, data);
140
141 spin_unlock_irqrestore(&devc->lock, flags);
142}
143
144#define MIDI_SYNTH_NAME "Sound Blaster Midi"
145#define MIDI_SYNTH_CAPS 0
146#include "midi_synth.h"
147
148static struct midi_operations sb_midi_operations =
149{
150 .owner = THIS_MODULE,
151 .info = {"Sound Blaster", 0, 0, SNDCARD_SB},
152 .converter = &std_midi_synth,
153 .in_info = {0},
154 .open = sb_midi_open,
155 .close = sb_midi_close,
156 .ioctl = sb_midi_ioctl,
157 .outputc = sb_midi_out,
158 .start_read = sb_midi_start_read,
159 .end_read = sb_midi_end_read,
160};
161
162void sb_dsp_midi_init(sb_devc * devc, struct module *owner)
163{
164 int dev;
165
166 if (devc->model < 2) /* No MIDI support for SB 1.x */
167 return;
168
169 dev = sound_alloc_mididev();
170
171 if (dev == -1)
172 {
173 printk(KERN_ERR "sb_midi: too many MIDI devices detected\n");
174 return;
175 }
176 std_midi_synth.midi_dev = devc->my_mididev = dev;
177 midi_devs[dev] = kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
178 if (midi_devs[dev] == NULL)
179 {
180 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
181 sound_unload_mididev(dev);
182 return;
183 }
184 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations,
185 sizeof(struct midi_operations));
186
187 if (owner)
188 midi_devs[dev]->owner = owner;
189
190 midi_devs[dev]->devc = devc;
191
192
193 midi_devs[dev]->converter = kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
194 if (midi_devs[dev]->converter == NULL)
195 {
196 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
197 kfree(midi_devs[dev]);
198 sound_unload_mididev(dev);
199 return;
200 }
201 memcpy((char *) midi_devs[dev]->converter, (char *) &std_midi_synth,
202 sizeof(struct synth_operations));
203
204 midi_devs[dev]->converter->id = "SBMIDI";
205 sequencer_init();
206}
diff --git a/sound/oss/sb_mixer.c b/sound/oss/sb_mixer.c
deleted file mode 100644
index acf7586aeb47..000000000000
--- a/sound/oss/sb_mixer.c
+++ /dev/null
@@ -1,770 +0,0 @@
1/*
2 * sound/oss/sb_mixer.c
3 *
4 * The low level mixer driver for the Sound Blaster compatible cards.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * Rolf Fokkens (Dec 20 1998) : Moved ESS stuff into sb_ess.[ch]
16 * Stanislav Voronyi <stas@esc.kharkov.com> : Support for AWE 3DSE device (Jun 7 1999)
17 */
18
19#include <linux/slab.h>
20
21#include "sound_config.h"
22
23#define __SB_MIXER_C__
24
25#include "sb.h"
26#include "sb_mixer.h"
27
28#include "sb_ess.h"
29
30#define SBPRO_RECORDING_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD)
31
32/* Same as SB Pro, unless I find otherwise */
33#define SGNXPRO_RECORDING_DEVICES SBPRO_RECORDING_DEVICES
34
35#define SBPRO_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE | SOUND_MASK_MIC | \
36 SOUND_MASK_CD | SOUND_MASK_VOLUME)
37
38/* SG NX Pro has treble and bass settings on the mixer. The 'speaker'
39 * channel is the COVOX/DisneySoundSource emulation volume control
40 * on the mixer. It does NOT control speaker volume. Should have own
41 * mask eventually?
42 */
43#define SGNXPRO_MIXER_DEVICES (SBPRO_MIXER_DEVICES|SOUND_MASK_BASS| \
44 SOUND_MASK_TREBLE|SOUND_MASK_SPEAKER )
45
46#define SB16_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_LINE | SOUND_MASK_MIC | \
47 SOUND_MASK_CD)
48
49#define SB16_OUTFILTER_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | \
50 SOUND_MASK_CD)
51
52#define SB16_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
53 SOUND_MASK_CD | \
54 SOUND_MASK_IGAIN | SOUND_MASK_OGAIN | \
55 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | \
56 SOUND_MASK_IMIX)
57
58/* These are the only devices that are working at the moment. Others could
59 * be added once they are identified and a method is found to control them.
60 */
61#define ALS007_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_LINE | \
62 SOUND_MASK_PCM | SOUND_MASK_MIC | \
63 SOUND_MASK_CD | \
64 SOUND_MASK_VOLUME)
65
66static mixer_tab sbpro_mix = {
67MIX_ENT(SOUND_MIXER_VOLUME, 0x22, 7, 4, 0x22, 3, 4),
68MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
69MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
70MIX_ENT(SOUND_MIXER_SYNTH, 0x26, 7, 4, 0x26, 3, 4),
71MIX_ENT(SOUND_MIXER_PCM, 0x04, 7, 4, 0x04, 3, 4),
72MIX_ENT(SOUND_MIXER_SPEAKER, 0x00, 0, 0, 0x00, 0, 0),
73MIX_ENT(SOUND_MIXER_LINE, 0x2e, 7, 4, 0x2e, 3, 4),
74MIX_ENT(SOUND_MIXER_MIC, 0x0a, 2, 3, 0x00, 0, 0),
75MIX_ENT(SOUND_MIXER_CD, 0x28, 7, 4, 0x28, 3, 4),
76MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
77MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
78MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0)
79};
80
81static mixer_tab sb16_mix = {
82MIX_ENT(SOUND_MIXER_VOLUME, 0x30, 7, 5, 0x31, 7, 5),
83MIX_ENT(SOUND_MIXER_BASS, 0x46, 7, 4, 0x47, 7, 4),
84MIX_ENT(SOUND_MIXER_TREBLE, 0x44, 7, 4, 0x45, 7, 4),
85MIX_ENT(SOUND_MIXER_SYNTH, 0x34, 7, 5, 0x35, 7, 5),
86MIX_ENT(SOUND_MIXER_PCM, 0x32, 7, 5, 0x33, 7, 5),
87MIX_ENT(SOUND_MIXER_SPEAKER, 0x3b, 7, 2, 0x00, 0, 0),
88MIX_ENT(SOUND_MIXER_LINE, 0x38, 7, 5, 0x39, 7, 5),
89MIX_ENT(SOUND_MIXER_MIC, 0x3a, 7, 5, 0x00, 0, 0),
90MIX_ENT(SOUND_MIXER_CD, 0x36, 7, 5, 0x37, 7, 5),
91MIX_ENT(SOUND_MIXER_IMIX, 0x3c, 0, 1, 0x00, 0, 0),
92MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
93MIX_ENT(SOUND_MIXER_RECLEV, 0x3f, 7, 2, 0x40, 7, 2), /* Obsolete. Use IGAIN */
94MIX_ENT(SOUND_MIXER_IGAIN, 0x3f, 7, 2, 0x40, 7, 2),
95MIX_ENT(SOUND_MIXER_OGAIN, 0x41, 7, 2, 0x42, 7, 2)
96};
97
98static mixer_tab als007_mix =
99{
100MIX_ENT(SOUND_MIXER_VOLUME, 0x62, 7, 4, 0x62, 3, 4),
101MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
102MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
103MIX_ENT(SOUND_MIXER_SYNTH, 0x66, 7, 4, 0x66, 3, 4),
104MIX_ENT(SOUND_MIXER_PCM, 0x64, 7, 4, 0x64, 3, 4),
105MIX_ENT(SOUND_MIXER_SPEAKER, 0x00, 0, 0, 0x00, 0, 0),
106MIX_ENT(SOUND_MIXER_LINE, 0x6e, 7, 4, 0x6e, 3, 4),
107MIX_ENT(SOUND_MIXER_MIC, 0x6a, 2, 3, 0x00, 0, 0),
108MIX_ENT(SOUND_MIXER_CD, 0x68, 7, 4, 0x68, 3, 4),
109MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
110MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
111MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0), /* Obsolete. Use IGAIN */
112MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
113MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0)
114};
115
116
117/* SM_GAMES Master volume is lower and PCM & FM volumes
118 higher than with SB Pro. This improves the
119 sound quality */
120
121static int smg_default_levels[32] =
122{
123 0x2020, /* Master Volume */
124 0x4b4b, /* Bass */
125 0x4b4b, /* Treble */
126 0x6464, /* FM */
127 0x6464, /* PCM */
128 0x4b4b, /* PC Speaker */
129 0x4b4b, /* Ext Line */
130 0x0000, /* Mic */
131 0x4b4b, /* CD */
132 0x4b4b, /* Recording monitor */
133 0x4b4b, /* SB PCM */
134 0x4b4b, /* Recording level */
135 0x4b4b, /* Input gain */
136 0x4b4b, /* Output gain */
137 0x4040, /* Line1 */
138 0x4040, /* Line2 */
139 0x1515 /* Line3 */
140};
141
142static int sb_default_levels[32] =
143{
144 0x5a5a, /* Master Volume */
145 0x4b4b, /* Bass */
146 0x4b4b, /* Treble */
147 0x4b4b, /* FM */
148 0x4b4b, /* PCM */
149 0x4b4b, /* PC Speaker */
150 0x4b4b, /* Ext Line */
151 0x1010, /* Mic */
152 0x4b4b, /* CD */
153 0x0000, /* Recording monitor */
154 0x4b4b, /* SB PCM */
155 0x4b4b, /* Recording level */
156 0x4b4b, /* Input gain */
157 0x4b4b, /* Output gain */
158 0x4040, /* Line1 */
159 0x4040, /* Line2 */
160 0x1515 /* Line3 */
161};
162
163static unsigned char sb16_recmasks_L[SOUND_MIXER_NRDEVICES] =
164{
165 0x00, /* SOUND_MIXER_VOLUME */
166 0x00, /* SOUND_MIXER_BASS */
167 0x00, /* SOUND_MIXER_TREBLE */
168 0x40, /* SOUND_MIXER_SYNTH */
169 0x00, /* SOUND_MIXER_PCM */
170 0x00, /* SOUND_MIXER_SPEAKER */
171 0x10, /* SOUND_MIXER_LINE */
172 0x01, /* SOUND_MIXER_MIC */
173 0x04, /* SOUND_MIXER_CD */
174 0x00, /* SOUND_MIXER_IMIX */
175 0x00, /* SOUND_MIXER_ALTPCM */
176 0x00, /* SOUND_MIXER_RECLEV */
177 0x00, /* SOUND_MIXER_IGAIN */
178 0x00 /* SOUND_MIXER_OGAIN */
179};
180
181static unsigned char sb16_recmasks_R[SOUND_MIXER_NRDEVICES] =
182{
183 0x00, /* SOUND_MIXER_VOLUME */
184 0x00, /* SOUND_MIXER_BASS */
185 0x00, /* SOUND_MIXER_TREBLE */
186 0x20, /* SOUND_MIXER_SYNTH */
187 0x00, /* SOUND_MIXER_PCM */
188 0x00, /* SOUND_MIXER_SPEAKER */
189 0x08, /* SOUND_MIXER_LINE */
190 0x01, /* SOUND_MIXER_MIC */
191 0x02, /* SOUND_MIXER_CD */
192 0x00, /* SOUND_MIXER_IMIX */
193 0x00, /* SOUND_MIXER_ALTPCM */
194 0x00, /* SOUND_MIXER_RECLEV */
195 0x00, /* SOUND_MIXER_IGAIN */
196 0x00 /* SOUND_MIXER_OGAIN */
197};
198
199static char smw_mix_regs[] = /* Left mixer registers */
200{
201 0x0b, /* SOUND_MIXER_VOLUME */
202 0x0d, /* SOUND_MIXER_BASS */
203 0x0d, /* SOUND_MIXER_TREBLE */
204 0x05, /* SOUND_MIXER_SYNTH */
205 0x09, /* SOUND_MIXER_PCM */
206 0x00, /* SOUND_MIXER_SPEAKER */
207 0x03, /* SOUND_MIXER_LINE */
208 0x01, /* SOUND_MIXER_MIC */
209 0x07, /* SOUND_MIXER_CD */
210 0x00, /* SOUND_MIXER_IMIX */
211 0x00, /* SOUND_MIXER_ALTPCM */
212 0x00, /* SOUND_MIXER_RECLEV */
213 0x00, /* SOUND_MIXER_IGAIN */
214 0x00, /* SOUND_MIXER_OGAIN */
215 0x00, /* SOUND_MIXER_LINE1 */
216 0x00, /* SOUND_MIXER_LINE2 */
217 0x00 /* SOUND_MIXER_LINE3 */
218};
219
220static int sbmixnum = 1;
221
222static void sb_mixer_reset(sb_devc * devc);
223
224void sb_mixer_set_stereo(sb_devc * devc, int mode)
225{
226 sb_chgmixer(devc, OUT_FILTER, STEREO_DAC, (mode ? STEREO_DAC : MONO_DAC));
227}
228
229static int detect_mixer(sb_devc * devc)
230{
231 /* Just trust the mixer is there */
232 return 1;
233}
234
235static void oss_change_bits(sb_devc *devc, unsigned char *regval, int dev, int chn, int newval)
236{
237 unsigned char mask;
238 int shift;
239
240 mask = (1 << (*devc->iomap)[dev][chn].nbits) - 1;
241 newval = (int) ((newval * mask) + 50) / 100; /* Scale */
242
243 shift = (*devc->iomap)[dev][chn].bitoffs - (*devc->iomap)[dev][LEFT_CHN].nbits + 1;
244
245 *regval &= ~(mask << shift); /* Mask out previous value */
246 *regval |= (newval & mask) << shift; /* Set the new value */
247}
248
249static int sb_mixer_get(sb_devc * devc, int dev)
250{
251 if (!((1 << dev) & devc->supported_devices))
252 return -EINVAL;
253 return devc->levels[dev];
254}
255
256void smw_mixer_init(sb_devc * devc)
257{
258 int i;
259
260 sb_setmixer(devc, 0x00, 0x18); /* Mute unused (Telephone) line */
261 sb_setmixer(devc, 0x10, 0x38); /* Config register 2 */
262
263 devc->supported_devices = 0;
264 for (i = 0; i < sizeof(smw_mix_regs); i++)
265 if (smw_mix_regs[i] != 0)
266 devc->supported_devices |= (1 << i);
267
268 devc->supported_rec_devices = devc->supported_devices &
269 ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_PCM | SOUND_MASK_VOLUME);
270 sb_mixer_reset(devc);
271}
272
273int sb_common_mixer_set(sb_devc * devc, int dev, int left, int right)
274{
275 int regoffs;
276 unsigned char val;
277
278 if ((dev < 0) || (dev >= devc->iomap_sz))
279 return -EINVAL;
280
281 regoffs = (*devc->iomap)[dev][LEFT_CHN].regno;
282
283 if (regoffs == 0)
284 return -EINVAL;
285
286 val = sb_getmixer(devc, regoffs);
287 oss_change_bits(devc, &val, dev, LEFT_CHN, left);
288
289 if ((*devc->iomap)[dev][RIGHT_CHN].regno != regoffs) /*
290 * Change register
291 */
292 {
293 sb_setmixer(devc, regoffs, val); /*
294 * Save the old one
295 */
296 regoffs = (*devc->iomap)[dev][RIGHT_CHN].regno;
297
298 if (regoffs == 0)
299 return left | (left << 8); /*
300 * Just left channel present
301 */
302
303 val = sb_getmixer(devc, regoffs); /*
304 * Read the new one
305 */
306 }
307 oss_change_bits(devc, &val, dev, RIGHT_CHN, right);
308
309 sb_setmixer(devc, regoffs, val);
310
311 return left | (right << 8);
312}
313
314static int smw_mixer_set(sb_devc * devc, int dev, int left, int right)
315{
316 int reg, val;
317
318 switch (dev)
319 {
320 case SOUND_MIXER_VOLUME:
321 sb_setmixer(devc, 0x0b, 96 - (96 * left / 100)); /* 96=mute, 0=max */
322 sb_setmixer(devc, 0x0c, 96 - (96 * right / 100));
323 break;
324
325 case SOUND_MIXER_BASS:
326 case SOUND_MIXER_TREBLE:
327 devc->levels[dev] = left | (right << 8);
328 /* Set left bass and treble values */
329 val = ((devc->levels[SOUND_MIXER_TREBLE] & 0xff) * 16 / (unsigned) 100) << 4;
330 val |= ((devc->levels[SOUND_MIXER_BASS] & 0xff) * 16 / (unsigned) 100) & 0x0f;
331 sb_setmixer(devc, 0x0d, val);
332
333 /* Set right bass and treble values */
334 val = (((devc->levels[SOUND_MIXER_TREBLE] >> 8) & 0xff) * 16 / (unsigned) 100) << 4;
335 val |= (((devc->levels[SOUND_MIXER_BASS] >> 8) & 0xff) * 16 / (unsigned) 100) & 0x0f;
336 sb_setmixer(devc, 0x0e, val);
337
338 break;
339
340 default:
341 /* bounds check */
342 if (dev < 0 || dev >= ARRAY_SIZE(smw_mix_regs))
343 return -EINVAL;
344 reg = smw_mix_regs[dev];
345 if (reg == 0)
346 return -EINVAL;
347 sb_setmixer(devc, reg, (24 - (24 * left / 100)) | 0x20); /* 24=mute, 0=max */
348 sb_setmixer(devc, reg + 1, (24 - (24 * right / 100)) | 0x40);
349 }
350
351 devc->levels[dev] = left | (right << 8);
352 return left | (right << 8);
353}
354
355static int sb_mixer_set(sb_devc * devc, int dev, int value)
356{
357 int left = value & 0x000000ff;
358 int right = (value & 0x0000ff00) >> 8;
359 int retval;
360
361 if (left > 100)
362 left = 100;
363 if (right > 100)
364 right = 100;
365
366 if ((dev < 0) || (dev > 31))
367 return -EINVAL;
368
369 if (!(devc->supported_devices & (1 << dev))) /*
370 * Not supported
371 */
372 return -EINVAL;
373
374 /* Differentiate depending on the chipsets */
375 switch (devc->model) {
376 case MDL_SMW:
377 retval = smw_mixer_set(devc, dev, left, right);
378 break;
379 case MDL_ESS:
380 retval = ess_mixer_set(devc, dev, left, right);
381 break;
382 default:
383 retval = sb_common_mixer_set(devc, dev, left, right);
384 }
385 if (retval >= 0) devc->levels[dev] = retval;
386
387 return retval;
388}
389
390/*
391 * set_recsrc doesn't apply to ES188x
392 */
393static void set_recsrc(sb_devc * devc, int src)
394{
395 sb_setmixer(devc, RECORD_SRC, (sb_getmixer(devc, RECORD_SRC) & ~7) | (src & 0x7));
396}
397
398static int set_recmask(sb_devc * devc, int mask)
399{
400 int devmask, i;
401 unsigned char regimageL, regimageR;
402
403 devmask = mask & devc->supported_rec_devices;
404
405 switch (devc->model)
406 {
407 case MDL_SBPRO:
408 case MDL_ESS:
409 case MDL_JAZZ:
410 case MDL_SMW:
411 if (devc->model == MDL_ESS && ess_set_recmask (devc, &devmask)) {
412 break;
413 }
414 if (devmask != SOUND_MASK_MIC &&
415 devmask != SOUND_MASK_LINE &&
416 devmask != SOUND_MASK_CD)
417 {
418 /*
419 * More than one device selected. Drop the
420 * previous selection
421 */
422 devmask &= ~devc->recmask;
423 }
424 if (devmask != SOUND_MASK_MIC &&
425 devmask != SOUND_MASK_LINE &&
426 devmask != SOUND_MASK_CD)
427 {
428 /*
429 * More than one device selected. Default to
430 * mic
431 */
432 devmask = SOUND_MASK_MIC;
433 }
434 if (devmask ^ devc->recmask) /*
435 * Input source changed
436 */
437 {
438 switch (devmask)
439 {
440 case SOUND_MASK_MIC:
441 set_recsrc(devc, SRC__MIC);
442 break;
443
444 case SOUND_MASK_LINE:
445 set_recsrc(devc, SRC__LINE);
446 break;
447
448 case SOUND_MASK_CD:
449 set_recsrc(devc, SRC__CD);
450 break;
451
452 default:
453 set_recsrc(devc, SRC__MIC);
454 }
455 }
456 break;
457
458 case MDL_SB16:
459 if (!devmask)
460 devmask = SOUND_MASK_MIC;
461
462 if (devc->submodel == SUBMDL_ALS007)
463 {
464 switch (devmask)
465 {
466 case SOUND_MASK_LINE:
467 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_LINE);
468 break;
469 case SOUND_MASK_CD:
470 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_CD);
471 break;
472 case SOUND_MASK_SYNTH:
473 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_SYNTH);
474 break;
475 default: /* Also takes care of SOUND_MASK_MIC case */
476 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_MIC);
477 break;
478 }
479 }
480 else
481 {
482 regimageL = regimageR = 0;
483 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
484 {
485 if ((1 << i) & devmask)
486 {
487 regimageL |= sb16_recmasks_L[i];
488 regimageR |= sb16_recmasks_R[i];
489 }
490 sb_setmixer (devc, SB16_IMASK_L, regimageL);
491 sb_setmixer (devc, SB16_IMASK_R, regimageR);
492 }
493 }
494 break;
495 }
496 devc->recmask = devmask;
497 return devc->recmask;
498}
499
500static int set_outmask(sb_devc * devc, int mask)
501{
502 int devmask, i;
503 unsigned char regimage;
504
505 devmask = mask & devc->supported_out_devices;
506
507 switch (devc->model)
508 {
509 case MDL_SB16:
510 if (devc->submodel == SUBMDL_ALS007)
511 break;
512 else
513 {
514 regimage = 0;
515 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
516 {
517 if ((1 << i) & devmask)
518 {
519 regimage |= (sb16_recmasks_L[i] | sb16_recmasks_R[i]);
520 }
521 sb_setmixer (devc, SB16_OMASK, regimage);
522 }
523 }
524 break;
525 default:
526 break;
527 }
528
529 devc->outmask = devmask;
530 return devc->outmask;
531}
532
533static int sb_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
534{
535 sb_devc *devc = mixer_devs[dev]->devc;
536 int val, ret;
537 int __user *p = arg;
538
539 /*
540 * Use ioctl(fd, SOUND_MIXER_AGC, &mode) to turn AGC off (0) or on (1).
541 * Use ioctl(fd, SOUND_MIXER_3DSE, &mode) to turn 3DSE off (0) or on (1)
542 * or mode==2 put 3DSE state to mode.
543 */
544 if (devc->model == MDL_SB16) {
545 if (cmd == SOUND_MIXER_AGC)
546 {
547 if (get_user(val, p))
548 return -EFAULT;
549 sb_setmixer(devc, 0x43, (~val) & 0x01);
550 return 0;
551 }
552 if (cmd == SOUND_MIXER_3DSE)
553 {
554 /* I put here 15, but I don't know the exact version.
555 At least my 4.13 havn't 3DSE, 4.16 has it. */
556 if (devc->minor < 15)
557 return -EINVAL;
558 if (get_user(val, p))
559 return -EFAULT;
560 if (val == 0 || val == 1)
561 sb_chgmixer(devc, AWE_3DSE, 0x01, val);
562 else if (val == 2)
563 {
564 ret = sb_getmixer(devc, AWE_3DSE)&0x01;
565 return put_user(ret, p);
566 }
567 else
568 return -EINVAL;
569 return 0;
570 }
571 }
572 if (((cmd >> 8) & 0xff) == 'M')
573 {
574 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
575 {
576 if (get_user(val, p))
577 return -EFAULT;
578 switch (cmd & 0xff)
579 {
580 case SOUND_MIXER_RECSRC:
581 ret = set_recmask(devc, val);
582 break;
583
584 case SOUND_MIXER_OUTSRC:
585 ret = set_outmask(devc, val);
586 break;
587
588 default:
589 ret = sb_mixer_set(devc, cmd & 0xff, val);
590 }
591 }
592 else switch (cmd & 0xff)
593 {
594 case SOUND_MIXER_RECSRC:
595 ret = devc->recmask;
596 break;
597
598 case SOUND_MIXER_OUTSRC:
599 ret = devc->outmask;
600 break;
601
602 case SOUND_MIXER_DEVMASK:
603 ret = devc->supported_devices;
604 break;
605
606 case SOUND_MIXER_STEREODEVS:
607 ret = devc->supported_devices;
608 /* The ESS seems to have stereo mic controls */
609 if (devc->model == MDL_ESS)
610 ret &= ~(SOUND_MASK_SPEAKER|SOUND_MASK_IMIX);
611 else if (devc->model != MDL_JAZZ && devc->model != MDL_SMW)
612 ret &= ~(SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
613 break;
614
615 case SOUND_MIXER_RECMASK:
616 ret = devc->supported_rec_devices;
617 break;
618
619 case SOUND_MIXER_OUTMASK:
620 ret = devc->supported_out_devices;
621 break;
622
623 case SOUND_MIXER_CAPS:
624 ret = devc->mixer_caps;
625 break;
626
627 default:
628 ret = sb_mixer_get(devc, cmd & 0xff);
629 break;
630 }
631 return put_user(ret, p);
632 } else
633 return -EINVAL;
634}
635
636static struct mixer_operations sb_mixer_operations =
637{
638 .owner = THIS_MODULE,
639 .id = "SB",
640 .name = "Sound Blaster",
641 .ioctl = sb_mixer_ioctl
642};
643
644static struct mixer_operations als007_mixer_operations =
645{
646 .owner = THIS_MODULE,
647 .id = "ALS007",
648 .name = "Avance ALS-007",
649 .ioctl = sb_mixer_ioctl
650};
651
652static void sb_mixer_reset(sb_devc * devc)
653{
654 char name[32];
655 int i;
656
657 sprintf(name, "SB_%d", devc->sbmixnum);
658
659 if (devc->sbmo.sm_games)
660 devc->levels = load_mixer_volumes(name, smg_default_levels, 1);
661 else
662 devc->levels = load_mixer_volumes(name, sb_default_levels, 1);
663
664 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
665 sb_mixer_set(devc, i, devc->levels[i]);
666
667 if (devc->model != MDL_ESS || !ess_mixer_reset (devc)) {
668 set_recmask(devc, SOUND_MASK_MIC);
669 }
670}
671
672int sb_mixer_init(sb_devc * devc, struct module *owner)
673{
674 int mixer_type = 0;
675 int m;
676
677 devc->sbmixnum = sbmixnum++;
678 devc->levels = NULL;
679
680 sb_setmixer(devc, 0x00, 0); /* Reset mixer */
681
682 if (!(mixer_type = detect_mixer(devc)))
683 return 0; /* No mixer. Why? */
684
685 switch (devc->model)
686 {
687 case MDL_ESSPCI:
688 case MDL_YMPCI:
689 case MDL_SBPRO:
690 case MDL_AZTECH:
691 case MDL_JAZZ:
692 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
693 devc->supported_devices = SBPRO_MIXER_DEVICES;
694 devc->supported_rec_devices = SBPRO_RECORDING_DEVICES;
695 devc->iomap = &sbpro_mix;
696 devc->iomap_sz = ARRAY_SIZE(sbpro_mix);
697 break;
698
699 case MDL_ESS:
700 ess_mixer_init (devc);
701 break;
702
703 case MDL_SMW:
704 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
705 devc->supported_devices = 0;
706 devc->supported_rec_devices = 0;
707 devc->iomap = &sbpro_mix;
708 devc->iomap_sz = ARRAY_SIZE(sbpro_mix);
709 smw_mixer_init(devc);
710 break;
711
712 case MDL_SB16:
713 devc->mixer_caps = 0;
714 devc->supported_rec_devices = SB16_RECORDING_DEVICES;
715 devc->supported_out_devices = SB16_OUTFILTER_DEVICES;
716 if (devc->submodel != SUBMDL_ALS007)
717 {
718 devc->supported_devices = SB16_MIXER_DEVICES;
719 devc->iomap = &sb16_mix;
720 devc->iomap_sz = ARRAY_SIZE(sb16_mix);
721 }
722 else
723 {
724 devc->supported_devices = ALS007_MIXER_DEVICES;
725 devc->iomap = &als007_mix;
726 devc->iomap_sz = ARRAY_SIZE(als007_mix);
727 }
728 break;
729
730 default:
731 printk(KERN_WARNING "sb_mixer: Unsupported mixer type %d\n", devc->model);
732 return 0;
733 }
734
735 m = sound_alloc_mixerdev();
736 if (m == -1)
737 return 0;
738
739 mixer_devs[m] = kmalloc(sizeof(struct mixer_operations), GFP_KERNEL);
740 if (mixer_devs[m] == NULL)
741 {
742 printk(KERN_ERR "sb_mixer: Can't allocate memory\n");
743 sound_unload_mixerdev(m);
744 return 0;
745 }
746
747 if (devc->submodel != SUBMDL_ALS007)
748 memcpy ((char *) mixer_devs[m], (char *) &sb_mixer_operations, sizeof (struct mixer_operations));
749 else
750 memcpy ((char *) mixer_devs[m], (char *) &als007_mixer_operations, sizeof (struct mixer_operations));
751
752 mixer_devs[m]->devc = devc;
753
754 if (owner)
755 mixer_devs[m]->owner = owner;
756
757 devc->my_mixerdev = m;
758 sb_mixer_reset(devc);
759 return 1;
760}
761
762void sb_mixer_unload(sb_devc *devc)
763{
764 if (devc->my_mixerdev == -1)
765 return;
766
767 kfree(mixer_devs[devc->my_mixerdev]);
768 sound_unload_mixerdev(devc->my_mixerdev);
769 sbmixnum--;
770}
diff --git a/sound/oss/sb_mixer.h b/sound/oss/sb_mixer.h
deleted file mode 100644
index 4b9425f085e3..000000000000
--- a/sound/oss/sb_mixer.h
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * sound/oss/sb_mixer.h
3 *
4 * Definitions for the SB Pro and SB16 mixers
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13
14/*
15 * Modified:
16 * Hunyue Yau Jan 6 1994
17 * Added defines for the Sound Galaxy NX Pro mixer.
18 *
19 * Rolf Fokkens Dec 20 1998
20 * Added defines for some ES188x chips.
21 *
22 * Rolf Fokkens Dec 27 1998
23 * Moved static stuff to sb_mixer.c
24 *
25 */
26/*
27 * Mixer registers
28 *
29 * NOTE! RECORD_SRC == IN_FILTER
30 */
31
32/*
33 * Mixer registers of SB Pro
34 */
35#define VOC_VOL 0x04
36#define MIC_VOL 0x0A
37#define MIC_MIX 0x0A
38#define RECORD_SRC 0x0C
39#define IN_FILTER 0x0C
40#define OUT_FILTER 0x0E
41#define MASTER_VOL 0x22
42#define FM_VOL 0x26
43#define CD_VOL 0x28
44#define LINE_VOL 0x2E
45#define IRQ_NR 0x80
46#define DMA_NR 0x81
47#define IRQ_STAT 0x82
48#define OPSW 0x3c
49
50/*
51 * Additional registers on the SG NX Pro
52 */
53#define COVOX_VOL 0x42
54#define TREBLE_LVL 0x44
55#define BASS_LVL 0x46
56
57#define FREQ_HI (1 << 3)/* Use High-frequency ANFI filters */
58#define FREQ_LOW 0 /* Use Low-frequency ANFI filters */
59#define FILT_ON 0 /* Yes, 0 to turn it on, 1 for off */
60#define FILT_OFF (1 << 5)
61
62#define MONO_DAC 0x00
63#define STEREO_DAC 0x02
64
65/*
66 * Mixer registers of SB16
67 */
68#define SB16_OMASK 0x3c
69#define SB16_IMASK_L 0x3d
70#define SB16_IMASK_R 0x3e
71
72#define LEFT_CHN 0
73#define RIGHT_CHN 1
74
75/*
76 * 3DSE register of AWE32/64
77 */
78#define AWE_3DSE 0x90
79
80/*
81 * Mixer registers of ALS007
82 */
83#define ALS007_RECORD_SRC 0x6c
84#define ALS007_OUTPUT_CTRL1 0x3c
85#define ALS007_OUTPUT_CTRL2 0x4c
86
87#define MIX_ENT(name, reg_l, bit_l, len_l, reg_r, bit_r, len_r) \
88 {{reg_l, bit_l, len_l}, {reg_r, bit_r, len_r}}
89
90/*
91 * Recording sources (SB Pro)
92 */
93
94#define SRC__MIC 1 /* Select Microphone recording source */
95#define SRC__CD 3 /* Select CD recording source */
96#define SRC__LINE 7 /* Use Line-in for recording source */
97
98/*
99 * Recording sources for ALS-007
100 */
101
102#define ALS007_MIC 4
103#define ALS007_LINE 6
104#define ALS007_CD 2
105#define ALS007_SYNTH 7
diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c
deleted file mode 100644
index f19da4b47c1d..000000000000
--- a/sound/oss/sequencer.c
+++ /dev/null
@@ -1,1661 +0,0 @@
1/*
2 * sound/oss/sequencer.c
3 *
4 * The sequencer personality manager.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13/*
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * Alan Cox : reformatted and fixed a pair of null pointer bugs
16 */
17#include <linux/kmod.h>
18#include <linux/spinlock.h>
19#include "sound_config.h"
20
21#include "midi_ctrl.h"
22#include "sleep.h"
23
24static int sequencer_ok;
25static struct sound_timer_operations *tmr;
26static int tmr_no = -1; /* Currently selected timer */
27static int pending_timer = -1; /* For timer change operation */
28extern unsigned long seq_time;
29
30static int obsolete_api_used;
31static DEFINE_SPINLOCK(lock);
32
33/*
34 * Local counts for number of synth and MIDI devices. These are initialized
35 * by the sequencer_open.
36 */
37static int max_mididev;
38static int max_synthdev;
39
40/*
41 * The seq_mode gives the operating mode of the sequencer:
42 * 1 = level1 (the default)
43 * 2 = level2 (extended capabilities)
44 */
45
46#define SEQ_1 1
47#define SEQ_2 2
48static int seq_mode = SEQ_1;
49
50static DECLARE_WAIT_QUEUE_HEAD(seq_sleeper);
51static DECLARE_WAIT_QUEUE_HEAD(midi_sleeper);
52
53static int midi_opened[MAX_MIDI_DEV];
54
55static int midi_written[MAX_MIDI_DEV];
56
57static unsigned long prev_input_time;
58static int prev_event_time;
59
60#include "tuning.h"
61
62#define EV_SZ 8
63#define IEV_SZ 8
64
65static unsigned char *queue;
66static unsigned char *iqueue;
67
68static volatile int qhead, qtail, qlen;
69static volatile int iqhead, iqtail, iqlen;
70static volatile int seq_playing;
71static volatile int sequencer_busy;
72static int output_threshold;
73static long pre_event_timeout;
74static unsigned synth_open_mask;
75
76static int seq_queue(unsigned char *note, char nonblock);
77static void seq_startplay(void);
78static int seq_sync(void);
79static void seq_reset(void);
80
81#if MAX_SYNTH_DEV > 15
82#error Too many synthesizer devices enabled.
83#endif
84
85int sequencer_read(int dev, struct file *file, char __user *buf, int count)
86{
87 int c = count, p = 0;
88 int ev_len;
89 unsigned long flags;
90
91 dev = dev >> 4;
92
93 ev_len = seq_mode == SEQ_1 ? 4 : 8;
94
95 spin_lock_irqsave(&lock,flags);
96
97 if (!iqlen)
98 {
99 spin_unlock_irqrestore(&lock,flags);
100 if (file->f_flags & O_NONBLOCK) {
101 return -EAGAIN;
102 }
103
104 oss_broken_sleep_on(&midi_sleeper, pre_event_timeout);
105 spin_lock_irqsave(&lock,flags);
106 if (!iqlen)
107 {
108 spin_unlock_irqrestore(&lock,flags);
109 return 0;
110 }
111 }
112 while (iqlen && c >= ev_len)
113 {
114 char *fixit = (char *) &iqueue[iqhead * IEV_SZ];
115 spin_unlock_irqrestore(&lock,flags);
116 if (copy_to_user(&(buf)[p], fixit, ev_len))
117 return count - c;
118 p += ev_len;
119 c -= ev_len;
120
121 spin_lock_irqsave(&lock,flags);
122 iqhead = (iqhead + 1) % SEQ_MAX_QUEUE;
123 iqlen--;
124 }
125 spin_unlock_irqrestore(&lock,flags);
126 return count - c;
127}
128
129static void sequencer_midi_output(int dev)
130{
131 /*
132 * Currently NOP
133 */
134}
135
136void seq_copy_to_input(unsigned char *event_rec, int len)
137{
138 unsigned long flags;
139
140 /*
141 * Verify that the len is valid for the current mode.
142 */
143
144 if (len != 4 && len != 8)
145 return;
146 if ((seq_mode == SEQ_1) != (len == 4))
147 return;
148
149 if (iqlen >= (SEQ_MAX_QUEUE - 1))
150 return; /* Overflow */
151
152 spin_lock_irqsave(&lock,flags);
153 memcpy(&iqueue[iqtail * IEV_SZ], event_rec, len);
154 iqlen++;
155 iqtail = (iqtail + 1) % SEQ_MAX_QUEUE;
156 wake_up(&midi_sleeper);
157 spin_unlock_irqrestore(&lock,flags);
158}
159EXPORT_SYMBOL(seq_copy_to_input);
160
161static void sequencer_midi_input(int dev, unsigned char data)
162{
163 unsigned int tstamp;
164 unsigned char event_rec[4];
165
166 if (data == 0xfe) /* Ignore active sensing */
167 return;
168
169 tstamp = jiffies - seq_time;
170
171 if (tstamp != prev_input_time)
172 {
173 tstamp = (tstamp << 8) | SEQ_WAIT;
174 seq_copy_to_input((unsigned char *) &tstamp, 4);
175 prev_input_time = tstamp;
176 }
177 event_rec[0] = SEQ_MIDIPUTC;
178 event_rec[1] = data;
179 event_rec[2] = dev;
180 event_rec[3] = 0;
181
182 seq_copy_to_input(event_rec, 4);
183}
184
185void seq_input_event(unsigned char *event_rec, int len)
186{
187 unsigned long this_time;
188
189 if (seq_mode == SEQ_2)
190 this_time = tmr->get_time(tmr_no);
191 else
192 this_time = jiffies - seq_time;
193
194 if (this_time != prev_input_time)
195 {
196 unsigned char tmp_event[8];
197
198 tmp_event[0] = EV_TIMING;
199 tmp_event[1] = TMR_WAIT_ABS;
200 tmp_event[2] = 0;
201 tmp_event[3] = 0;
202 *(unsigned int *) &tmp_event[4] = this_time;
203
204 seq_copy_to_input(tmp_event, 8);
205 prev_input_time = this_time;
206 }
207 seq_copy_to_input(event_rec, len);
208}
209EXPORT_SYMBOL(seq_input_event);
210
211int sequencer_write(int dev, struct file *file, const char __user *buf, int count)
212{
213 unsigned char event_rec[EV_SZ], ev_code;
214 int p = 0, c, ev_size;
215 int mode = translate_mode(file);
216
217 dev = dev >> 4;
218
219 if (mode == OPEN_READ)
220 return -EIO;
221
222 c = count;
223
224 while (c >= 4)
225 {
226 if (copy_from_user((char *) event_rec, &(buf)[p], 4))
227 goto out;
228 ev_code = event_rec[0];
229
230 if (ev_code == SEQ_FULLSIZE)
231 {
232 int err, fmt;
233
234 dev = *(unsigned short *) &event_rec[2];
235 if (dev < 0 || dev >= max_synthdev || synth_devs[dev] == NULL)
236 return -ENXIO;
237
238 if (!(synth_open_mask & (1 << dev)))
239 return -ENXIO;
240
241 fmt = (*(short *) &event_rec[0]) & 0xffff;
242 err = synth_devs[dev]->load_patch(dev, fmt, buf + p, c, 0);
243 if (err < 0)
244 return err;
245
246 return err;
247 }
248 if (ev_code >= 128)
249 {
250 if (seq_mode == SEQ_2 && ev_code == SEQ_EXTENDED)
251 {
252 printk(KERN_WARNING "Sequencer: Invalid level 2 event %x\n", ev_code);
253 return -EINVAL;
254 }
255 ev_size = 8;
256
257 if (c < ev_size)
258 {
259 if (!seq_playing)
260 seq_startplay();
261 return count - c;
262 }
263 if (copy_from_user((char *)&event_rec[4],
264 &(buf)[p + 4], 4))
265 goto out;
266
267 }
268 else
269 {
270 if (seq_mode == SEQ_2)
271 {
272 printk(KERN_WARNING "Sequencer: 4 byte event in level 2 mode\n");
273 return -EINVAL;
274 }
275 ev_size = 4;
276
277 if (event_rec[0] != SEQ_MIDIPUTC)
278 obsolete_api_used = 1;
279 }
280
281 if (event_rec[0] == SEQ_MIDIPUTC)
282 {
283 if (!midi_opened[event_rec[2]])
284 {
285 int err, mode;
286 int dev = event_rec[2];
287
288 if (dev >= max_mididev || midi_devs[dev]==NULL)
289 {
290 /*printk("Sequencer Error: Nonexistent MIDI device %d\n", dev);*/
291 return -ENXIO;
292 }
293 mode = translate_mode(file);
294
295 if ((err = midi_devs[dev]->open(dev, mode,
296 sequencer_midi_input, sequencer_midi_output)) < 0)
297 {
298 seq_reset();
299 printk(KERN_WARNING "Sequencer Error: Unable to open Midi #%d\n", dev);
300 return err;
301 }
302 midi_opened[dev] = 1;
303 }
304 }
305 if (!seq_queue(event_rec, (file->f_flags & (O_NONBLOCK) ? 1 : 0)))
306 {
307 int processed = count - c;
308
309 if (!seq_playing)
310 seq_startplay();
311
312 if (!processed && (file->f_flags & O_NONBLOCK))
313 return -EAGAIN;
314 else
315 return processed;
316 }
317 p += ev_size;
318 c -= ev_size;
319 }
320
321 if (!seq_playing)
322 seq_startplay();
323out:
324 return count;
325}
326
327static int seq_queue(unsigned char *note, char nonblock)
328{
329
330 /*
331 * Test if there is space in the queue
332 */
333
334 if (qlen >= SEQ_MAX_QUEUE)
335 if (!seq_playing)
336 seq_startplay(); /*
337 * Give chance to drain the queue
338 */
339
340 if (!nonblock && qlen >= SEQ_MAX_QUEUE && !waitqueue_active(&seq_sleeper)) {
341 /*
342 * Sleep until there is enough space on the queue
343 */
344 oss_broken_sleep_on(&seq_sleeper, MAX_SCHEDULE_TIMEOUT);
345 }
346 if (qlen >= SEQ_MAX_QUEUE)
347 {
348 return 0; /*
349 * To be sure
350 */
351 }
352 memcpy(&queue[qtail * EV_SZ], note, EV_SZ);
353
354 qtail = (qtail + 1) % SEQ_MAX_QUEUE;
355 qlen++;
356
357 return 1;
358}
359
360static int extended_event(unsigned char *q)
361{
362 int dev = q[2];
363
364 if (dev < 0 || dev >= max_synthdev)
365 return -ENXIO;
366
367 if (!(synth_open_mask & (1 << dev)))
368 return -ENXIO;
369
370 switch (q[1])
371 {
372 case SEQ_NOTEOFF:
373 synth_devs[dev]->kill_note(dev, q[3], q[4], q[5]);
374 break;
375
376 case SEQ_NOTEON:
377 if (q[4] > 127 && q[4] != 255)
378 return 0;
379
380 if (q[5] == 0)
381 {
382 synth_devs[dev]->kill_note(dev, q[3], q[4], q[5]);
383 break;
384 }
385 synth_devs[dev]->start_note(dev, q[3], q[4], q[5]);
386 break;
387
388 case SEQ_PGMCHANGE:
389 synth_devs[dev]->set_instr(dev, q[3], q[4]);
390 break;
391
392 case SEQ_AFTERTOUCH:
393 synth_devs[dev]->aftertouch(dev, q[3], q[4]);
394 break;
395
396 case SEQ_BALANCE:
397 synth_devs[dev]->panning(dev, q[3], (char) q[4]);
398 break;
399
400 case SEQ_CONTROLLER:
401 synth_devs[dev]->controller(dev, q[3], q[4], (short) (q[5] | (q[6] << 8)));
402 break;
403
404 case SEQ_VOLMODE:
405 if (synth_devs[dev]->volume_method != NULL)
406 synth_devs[dev]->volume_method(dev, q[3]);
407 break;
408
409 default:
410 return -EINVAL;
411 }
412 return 0;
413}
414
415static int find_voice(int dev, int chn, int note)
416{
417 unsigned short key;
418 int i;
419
420 key = (chn << 8) | (note + 1);
421 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
422 if (synth_devs[dev]->alloc.map[i] == key)
423 return i;
424 return -1;
425}
426
427static int alloc_voice(int dev, int chn, int note)
428{
429 unsigned short key;
430 int voice;
431
432 key = (chn << 8) | (note + 1);
433
434 voice = synth_devs[dev]->alloc_voice(dev, chn, note,
435 &synth_devs[dev]->alloc);
436 synth_devs[dev]->alloc.map[voice] = key;
437 synth_devs[dev]->alloc.alloc_times[voice] =
438 synth_devs[dev]->alloc.timestamp++;
439 return voice;
440}
441
442static void seq_chn_voice_event(unsigned char *event_rec)
443{
444#define dev event_rec[1]
445#define cmd event_rec[2]
446#define chn event_rec[3]
447#define note event_rec[4]
448#define parm event_rec[5]
449
450 int voice = -1;
451
452 if ((int) dev > max_synthdev || synth_devs[dev] == NULL)
453 return;
454 if (!(synth_open_mask & (1 << dev)))
455 return;
456 if (!synth_devs[dev])
457 return;
458
459 if (seq_mode == SEQ_2)
460 {
461 if (synth_devs[dev]->alloc_voice)
462 voice = find_voice(dev, chn, note);
463
464 if (cmd == MIDI_NOTEON && parm == 0)
465 {
466 cmd = MIDI_NOTEOFF;
467 parm = 64;
468 }
469 }
470
471 switch (cmd)
472 {
473 case MIDI_NOTEON:
474 if (note > 127 && note != 255) /* Not a seq2 feature */
475 return;
476
477 if (voice == -1 && seq_mode == SEQ_2 && synth_devs[dev]->alloc_voice)
478 {
479 /* Internal synthesizer (FM, GUS, etc) */
480 voice = alloc_voice(dev, chn, note);
481 }
482 if (voice == -1)
483 voice = chn;
484
485 if (seq_mode == SEQ_2 && (int) dev < num_synths)
486 {
487 /*
488 * The MIDI channel 10 is a percussive channel. Use the note
489 * number to select the proper patch (128 to 255) to play.
490 */
491
492 if (chn == 9)
493 {
494 synth_devs[dev]->set_instr(dev, voice, 128 + note);
495 synth_devs[dev]->chn_info[chn].pgm_num = 128 + note;
496 }
497 synth_devs[dev]->setup_voice(dev, voice, chn);
498 }
499 synth_devs[dev]->start_note(dev, voice, note, parm);
500 break;
501
502 case MIDI_NOTEOFF:
503 if (voice == -1)
504 voice = chn;
505 synth_devs[dev]->kill_note(dev, voice, note, parm);
506 break;
507
508 case MIDI_KEY_PRESSURE:
509 if (voice == -1)
510 voice = chn;
511 synth_devs[dev]->aftertouch(dev, voice, parm);
512 break;
513
514 default:;
515 }
516#undef dev
517#undef cmd
518#undef chn
519#undef note
520#undef parm
521}
522
523
524static void seq_chn_common_event(unsigned char *event_rec)
525{
526 unsigned char dev = event_rec[1];
527 unsigned char cmd = event_rec[2];
528 unsigned char chn = event_rec[3];
529 unsigned char p1 = event_rec[4];
530
531 /* unsigned char p2 = event_rec[5]; */
532 unsigned short w14 = *(short *) &event_rec[6];
533
534 if ((int) dev > max_synthdev || synth_devs[dev] == NULL)
535 return;
536 if (!(synth_open_mask & (1 << dev)))
537 return;
538 if (!synth_devs[dev])
539 return;
540
541 switch (cmd)
542 {
543 case MIDI_PGM_CHANGE:
544 if (seq_mode == SEQ_2)
545 {
546 if (chn > 15)
547 break;
548
549 synth_devs[dev]->chn_info[chn].pgm_num = p1;
550 if ((int) dev >= num_synths)
551 synth_devs[dev]->set_instr(dev, chn, p1);
552 }
553 else
554 synth_devs[dev]->set_instr(dev, chn, p1);
555
556 break;
557
558 case MIDI_CTL_CHANGE:
559 if (seq_mode == SEQ_2)
560 {
561 if (chn > 15 || p1 > 127)
562 break;
563
564 synth_devs[dev]->chn_info[chn].controllers[p1] = w14 & 0x7f;
565
566 if (p1 < 32) /* Setting MSB should clear LSB to 0 */
567 synth_devs[dev]->chn_info[chn].controllers[p1 + 32] = 0;
568
569 if ((int) dev < num_synths)
570 {
571 int val = w14 & 0x7f;
572 int i, key;
573
574 if (p1 < 64) /* Combine MSB and LSB */
575 {
576 val = ((synth_devs[dev]->
577 chn_info[chn].controllers[p1 & ~32] & 0x7f) << 7)
578 | (synth_devs[dev]->
579 chn_info[chn].controllers[p1 | 32] & 0x7f);
580 p1 &= ~32;
581 }
582 /* Handle all playing notes on this channel */
583
584 key = ((int) chn << 8);
585
586 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
587 if ((synth_devs[dev]->alloc.map[i] & 0xff00) == key)
588 synth_devs[dev]->controller(dev, i, p1, val);
589 }
590 else
591 synth_devs[dev]->controller(dev, chn, p1, w14);
592 }
593 else /* Mode 1 */
594 synth_devs[dev]->controller(dev, chn, p1, w14);
595 break;
596
597 case MIDI_PITCH_BEND:
598 if (seq_mode == SEQ_2)
599 {
600 if (chn > 15)
601 break;
602
603 synth_devs[dev]->chn_info[chn].bender_value = w14;
604
605 if ((int) dev < num_synths)
606 {
607 /* Handle all playing notes on this channel */
608 int i, key;
609
610 key = (chn << 8);
611
612 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
613 if ((synth_devs[dev]->alloc.map[i] & 0xff00) == key)
614 synth_devs[dev]->bender(dev, i, w14);
615 }
616 else
617 synth_devs[dev]->bender(dev, chn, w14);
618 }
619 else /* MODE 1 */
620 synth_devs[dev]->bender(dev, chn, w14);
621 break;
622
623 default:;
624 }
625}
626
627static int seq_timing_event(unsigned char *event_rec)
628{
629 unsigned char cmd = event_rec[1];
630 unsigned int parm = *(int *) &event_rec[4];
631
632 if (seq_mode == SEQ_2)
633 {
634 int ret;
635
636 if ((ret = tmr->event(tmr_no, event_rec)) == TIMER_ARMED)
637 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
638 wake_up(&seq_sleeper);
639 return ret;
640 }
641 switch (cmd)
642 {
643 case TMR_WAIT_REL:
644 parm += prev_event_time;
645
646 /*
647 * NOTE! No break here. Execution of TMR_WAIT_REL continues in the
648 * next case (TMR_WAIT_ABS)
649 */
650
651 case TMR_WAIT_ABS:
652 if (parm > 0)
653 {
654 long time;
655
656 time = parm;
657 prev_event_time = time;
658
659 seq_playing = 1;
660 request_sound_timer(time);
661
662 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
663 wake_up(&seq_sleeper);
664 return TIMER_ARMED;
665 }
666 break;
667
668 case TMR_START:
669 seq_time = jiffies;
670 prev_input_time = 0;
671 prev_event_time = 0;
672 break;
673
674 case TMR_STOP:
675 break;
676
677 case TMR_CONTINUE:
678 break;
679
680 case TMR_TEMPO:
681 break;
682
683 case TMR_ECHO:
684 parm = (parm << 8 | SEQ_ECHO);
685 seq_copy_to_input((unsigned char *) &parm, 4);
686 break;
687
688 default:;
689 }
690
691 return TIMER_NOT_ARMED;
692}
693
694static void seq_local_event(unsigned char *event_rec)
695{
696 unsigned char cmd = event_rec[1];
697 unsigned int parm = *((unsigned int *) &event_rec[4]);
698
699 switch (cmd)
700 {
701 case LOCL_STARTAUDIO:
702 DMAbuf_start_devices(parm);
703 break;
704
705 default:;
706 }
707}
708
709static void seq_sysex_message(unsigned char *event_rec)
710{
711 unsigned int dev = event_rec[1];
712 int i, l = 0;
713 unsigned char *buf = &event_rec[2];
714
715 if (dev > max_synthdev)
716 return;
717 if (!(synth_open_mask & (1 << dev)))
718 return;
719 if (!synth_devs[dev])
720 return;
721
722 l = 0;
723 for (i = 0; i < 6 && buf[i] != 0xff; i++)
724 l = i + 1;
725
726 if (!synth_devs[dev]->send_sysex)
727 return;
728 if (l > 0)
729 synth_devs[dev]->send_sysex(dev, buf, l);
730}
731
732static int play_event(unsigned char *q)
733{
734 /*
735 * NOTE! This routine returns
736 * 0 = normal event played.
737 * 1 = Timer armed. Suspend playback until timer callback.
738 * 2 = MIDI output buffer full. Restore queue and suspend until timer
739 */
740 unsigned int *delay;
741
742 switch (q[0])
743 {
744 case SEQ_NOTEOFF:
745 if (synth_open_mask & (1 << 0))
746 if (synth_devs[0])
747 synth_devs[0]->kill_note(0, q[1], 255, q[3]);
748 break;
749
750 case SEQ_NOTEON:
751 if (q[4] < 128 || q[4] == 255)
752 if (synth_open_mask & (1 << 0))
753 if (synth_devs[0])
754 synth_devs[0]->start_note(0, q[1], q[2], q[3]);
755 break;
756
757 case SEQ_WAIT:
758 delay = (unsigned int *) q; /*
759 * Bytes 1 to 3 are containing the *
760 * delay in 'ticks'
761 */
762 *delay = (*delay >> 8) & 0xffffff;
763
764 if (*delay > 0)
765 {
766 long time;
767
768 seq_playing = 1;
769 time = *delay;
770 prev_event_time = time;
771
772 request_sound_timer(time);
773
774 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
775 wake_up(&seq_sleeper);
776 /*
777 * The timer is now active and will reinvoke this function
778 * after the timer expires. Return to the caller now.
779 */
780 return 1;
781 }
782 break;
783
784 case SEQ_PGMCHANGE:
785 if (synth_open_mask & (1 << 0))
786 if (synth_devs[0])
787 synth_devs[0]->set_instr(0, q[1], q[2]);
788 break;
789
790 case SEQ_SYNCTIMER: /*
791 * Reset timer
792 */
793 seq_time = jiffies;
794 prev_input_time = 0;
795 prev_event_time = 0;
796 break;
797
798 case SEQ_MIDIPUTC: /*
799 * Put a midi character
800 */
801 if (midi_opened[q[2]])
802 {
803 int dev;
804
805 dev = q[2];
806
807 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
808 break;
809
810 if (!midi_devs[dev]->outputc(dev, q[1]))
811 {
812 /*
813 * Output FIFO is full. Wait one timer cycle and try again.
814 */
815
816 seq_playing = 1;
817 request_sound_timer(-1);
818 return 2;
819 }
820 else
821 midi_written[dev] = 1;
822 }
823 break;
824
825 case SEQ_ECHO:
826 seq_copy_to_input(q, 4); /*
827 * Echo back to the process
828 */
829 break;
830
831 case SEQ_PRIVATE:
832 if ((int) q[1] < max_synthdev)
833 synth_devs[q[1]]->hw_control(q[1], q);
834 break;
835
836 case SEQ_EXTENDED:
837 extended_event(q);
838 break;
839
840 case EV_CHN_VOICE:
841 seq_chn_voice_event(q);
842 break;
843
844 case EV_CHN_COMMON:
845 seq_chn_common_event(q);
846 break;
847
848 case EV_TIMING:
849 if (seq_timing_event(q) == TIMER_ARMED)
850 {
851 return 1;
852 }
853 break;
854
855 case EV_SEQ_LOCAL:
856 seq_local_event(q);
857 break;
858
859 case EV_SYSEX:
860 seq_sysex_message(q);
861 break;
862
863 default:;
864 }
865 return 0;
866}
867
868/* called also as timer in irq context */
869static void seq_startplay(void)
870{
871 int this_one, action;
872 unsigned long flags;
873
874 while (qlen > 0)
875 {
876
877 spin_lock_irqsave(&lock,flags);
878 qhead = ((this_one = qhead) + 1) % SEQ_MAX_QUEUE;
879 qlen--;
880 spin_unlock_irqrestore(&lock,flags);
881
882 seq_playing = 1;
883
884 if ((action = play_event(&queue[this_one * EV_SZ])))
885 { /* Suspend playback. Next timer routine invokes this routine again */
886 if (action == 2)
887 {
888 qlen++;
889 qhead = this_one;
890 }
891 return;
892 }
893 }
894
895 seq_playing = 0;
896
897 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
898 wake_up(&seq_sleeper);
899}
900
901static void reset_controllers(int dev, unsigned char *controller, int update_dev)
902{
903 int i;
904 for (i = 0; i < 128; i++)
905 controller[i] = ctrl_def_values[i];
906}
907
908static void setup_mode2(void)
909{
910 int dev;
911
912 max_synthdev = num_synths;
913
914 for (dev = 0; dev < num_midis; dev++)
915 {
916 if (midi_devs[dev] && midi_devs[dev]->converter != NULL)
917 {
918 synth_devs[max_synthdev++] = midi_devs[dev]->converter;
919 }
920 }
921
922 for (dev = 0; dev < max_synthdev; dev++)
923 {
924 int chn;
925
926 synth_devs[dev]->sysex_ptr = 0;
927 synth_devs[dev]->emulation = 0;
928
929 for (chn = 0; chn < 16; chn++)
930 {
931 synth_devs[dev]->chn_info[chn].pgm_num = 0;
932 reset_controllers(dev,
933 synth_devs[dev]->chn_info[chn].controllers,0);
934 synth_devs[dev]->chn_info[chn].bender_value = (1 << 7); /* Neutral */
935 synth_devs[dev]->chn_info[chn].bender_range = 200;
936 }
937 }
938 max_mididev = 0;
939 seq_mode = SEQ_2;
940}
941
942int sequencer_open(int dev, struct file *file)
943{
944 int retval, mode, i;
945 int level, tmp;
946
947 if (!sequencer_ok)
948 sequencer_init();
949
950 level = ((dev & 0x0f) == SND_DEV_SEQ2) ? 2 : 1;
951
952 dev = dev >> 4;
953 mode = translate_mode(file);
954
955 if (!sequencer_ok)
956 {
957/* printk("Sound card: sequencer not initialized\n");*/
958 return -ENXIO;
959 }
960 if (dev) /* Patch manager device (obsolete) */
961 return -ENXIO;
962
963 if(synth_devs[dev] == NULL)
964 request_module("synth0");
965
966 if (mode == OPEN_READ)
967 {
968 if (!num_midis)
969 {
970 /*printk("Sequencer: No MIDI devices. Input not possible\n");*/
971 sequencer_busy = 0;
972 return -ENXIO;
973 }
974 }
975 if (sequencer_busy)
976 {
977 return -EBUSY;
978 }
979 sequencer_busy = 1;
980 obsolete_api_used = 0;
981
982 max_mididev = num_midis;
983 max_synthdev = num_synths;
984 pre_event_timeout = MAX_SCHEDULE_TIMEOUT;
985 seq_mode = SEQ_1;
986
987 if (pending_timer != -1)
988 {
989 tmr_no = pending_timer;
990 pending_timer = -1;
991 }
992 if (tmr_no == -1) /* Not selected yet */
993 {
994 int i, best;
995
996 best = -1;
997 for (i = 0; i < num_sound_timers; i++)
998 if (sound_timer_devs[i] && sound_timer_devs[i]->priority > best)
999 {
1000 tmr_no = i;
1001 best = sound_timer_devs[i]->priority;
1002 }
1003 if (tmr_no == -1) /* Should not be */
1004 tmr_no = 0;
1005 }
1006 tmr = sound_timer_devs[tmr_no];
1007
1008 if (level == 2)
1009 {
1010 if (tmr == NULL)
1011 {
1012 /*printk("sequencer: No timer for level 2\n");*/
1013 sequencer_busy = 0;
1014 return -ENXIO;
1015 }
1016 setup_mode2();
1017 }
1018 if (!max_synthdev && !max_mididev)
1019 {
1020 sequencer_busy=0;
1021 return -ENXIO;
1022 }
1023
1024 synth_open_mask = 0;
1025
1026 for (i = 0; i < max_mididev; i++)
1027 {
1028 midi_opened[i] = 0;
1029 midi_written[i] = 0;
1030 }
1031
1032 for (i = 0; i < max_synthdev; i++)
1033 {
1034 if (synth_devs[i]==NULL)
1035 continue;
1036
1037 if (!try_module_get(synth_devs[i]->owner))
1038 continue;
1039
1040 if ((tmp = synth_devs[i]->open(i, mode)) < 0)
1041 {
1042 printk(KERN_WARNING "Sequencer: Warning! Cannot open synth device #%d (%d)\n", i, tmp);
1043 if (synth_devs[i]->midi_dev)
1044 printk(KERN_WARNING "(Maps to MIDI dev #%d)\n", synth_devs[i]->midi_dev);
1045 }
1046 else
1047 {
1048 synth_open_mask |= (1 << i);
1049 if (synth_devs[i]->midi_dev)
1050 midi_opened[synth_devs[i]->midi_dev] = 1;
1051 }
1052 }
1053
1054 seq_time = jiffies;
1055
1056 prev_input_time = 0;
1057 prev_event_time = 0;
1058
1059 if (seq_mode == SEQ_1 && (mode == OPEN_READ || mode == OPEN_READWRITE))
1060 {
1061 /*
1062 * Initialize midi input devices
1063 */
1064
1065 for (i = 0; i < max_mididev; i++)
1066 if (!midi_opened[i] && midi_devs[i])
1067 {
1068 if (!try_module_get(midi_devs[i]->owner))
1069 continue;
1070
1071 if ((retval = midi_devs[i]->open(i, mode,
1072 sequencer_midi_input, sequencer_midi_output)) >= 0)
1073 {
1074 midi_opened[i] = 1;
1075 }
1076 }
1077 }
1078
1079 if (seq_mode == SEQ_2) {
1080 if (try_module_get(tmr->owner))
1081 tmr->open(tmr_no, seq_mode);
1082 }
1083
1084 init_waitqueue_head(&seq_sleeper);
1085 init_waitqueue_head(&midi_sleeper);
1086 output_threshold = SEQ_MAX_QUEUE / 2;
1087
1088 return 0;
1089}
1090
1091static void seq_drain_midi_queues(void)
1092{
1093 int i, n;
1094
1095 /*
1096 * Give the Midi drivers time to drain their output queues
1097 */
1098
1099 n = 1;
1100
1101 while (!signal_pending(current) && n)
1102 {
1103 n = 0;
1104
1105 for (i = 0; i < max_mididev; i++)
1106 if (midi_opened[i] && midi_written[i])
1107 if (midi_devs[i]->buffer_status != NULL)
1108 if (midi_devs[i]->buffer_status(i))
1109 n++;
1110
1111 /*
1112 * Let's have a delay
1113 */
1114
1115 if (n)
1116 oss_broken_sleep_on(&seq_sleeper, HZ/10);
1117 }
1118}
1119
1120void sequencer_release(int dev, struct file *file)
1121{
1122 int i;
1123 int mode = translate_mode(file);
1124
1125 dev = dev >> 4;
1126
1127 /*
1128 * Wait until the queue is empty (if we don't have nonblock)
1129 */
1130
1131 if (mode != OPEN_READ && !(file->f_flags & O_NONBLOCK))
1132 {
1133 while (!signal_pending(current) && qlen > 0)
1134 {
1135 seq_sync();
1136 oss_broken_sleep_on(&seq_sleeper, 3*HZ);
1137 /* Extra delay */
1138 }
1139 }
1140
1141 if (mode != OPEN_READ)
1142 seq_drain_midi_queues(); /*
1143 * Ensure the output queues are empty
1144 */
1145 seq_reset();
1146 if (mode != OPEN_READ)
1147 seq_drain_midi_queues(); /*
1148 * Flush the all notes off messages
1149 */
1150
1151 for (i = 0; i < max_synthdev; i++)
1152 {
1153 if (synth_open_mask & (1 << i)) /*
1154 * Actually opened
1155 */
1156 if (synth_devs[i])
1157 {
1158 synth_devs[i]->close(i);
1159
1160 module_put(synth_devs[i]->owner);
1161
1162 if (synth_devs[i]->midi_dev)
1163 midi_opened[synth_devs[i]->midi_dev] = 0;
1164 }
1165 }
1166
1167 for (i = 0; i < max_mididev; i++)
1168 {
1169 if (midi_opened[i]) {
1170 midi_devs[i]->close(i);
1171 module_put(midi_devs[i]->owner);
1172 }
1173 }
1174
1175 if (seq_mode == SEQ_2) {
1176 tmr->close(tmr_no);
1177 module_put(tmr->owner);
1178 }
1179
1180 if (obsolete_api_used)
1181 printk(KERN_WARNING "/dev/music: Obsolete (4 byte) API was used by %s\n", current->comm);
1182 sequencer_busy = 0;
1183}
1184
1185static int seq_sync(void)
1186{
1187 if (qlen && !seq_playing && !signal_pending(current))
1188 seq_startplay();
1189
1190 if (qlen > 0)
1191 oss_broken_sleep_on(&seq_sleeper, HZ);
1192 return qlen;
1193}
1194
1195static void midi_outc(int dev, unsigned char data)
1196{
1197 /*
1198 * NOTE! Calls sleep(). Don't call this from interrupt.
1199 */
1200
1201 int n;
1202 unsigned long flags;
1203
1204 /*
1205 * This routine sends one byte to the Midi channel.
1206 * If the output FIFO is full, it waits until there
1207 * is space in the queue
1208 */
1209
1210 n = 3 * HZ; /* Timeout */
1211
1212 spin_lock_irqsave(&lock,flags);
1213 while (n && !midi_devs[dev]->outputc(dev, data)) {
1214 oss_broken_sleep_on(&seq_sleeper, HZ/25);
1215 n--;
1216 }
1217 spin_unlock_irqrestore(&lock,flags);
1218}
1219
1220static void seq_reset(void)
1221{
1222 /*
1223 * NOTE! Calls sleep(). Don't call this from interrupt.
1224 */
1225
1226 int i;
1227 int chn;
1228 unsigned long flags;
1229
1230 sound_stop_timer();
1231
1232 seq_time = jiffies;
1233 prev_input_time = 0;
1234 prev_event_time = 0;
1235
1236 qlen = qhead = qtail = 0;
1237 iqlen = iqhead = iqtail = 0;
1238
1239 for (i = 0; i < max_synthdev; i++)
1240 if (synth_open_mask & (1 << i))
1241 if (synth_devs[i])
1242 synth_devs[i]->reset(i);
1243
1244 if (seq_mode == SEQ_2)
1245 {
1246 for (chn = 0; chn < 16; chn++)
1247 for (i = 0; i < max_synthdev; i++)
1248 if (synth_open_mask & (1 << i))
1249 if (synth_devs[i])
1250 {
1251 synth_devs[i]->controller(i, chn, 123, 0); /* All notes off */
1252 synth_devs[i]->controller(i, chn, 121, 0); /* Reset all ctl */
1253 synth_devs[i]->bender(i, chn, 1 << 13); /* Bender off */
1254 }
1255 }
1256 else /* seq_mode == SEQ_1 */
1257 {
1258 for (i = 0; i < max_mididev; i++)
1259 if (midi_written[i]) /*
1260 * Midi used. Some notes may still be playing
1261 */
1262 {
1263 /*
1264 * Sending just a ACTIVE SENSING message should be enough to stop all
1265 * playing notes. Since there are devices not recognizing the
1266 * active sensing, we have to send some all notes off messages also.
1267 */
1268 midi_outc(i, 0xfe);
1269
1270 for (chn = 0; chn < 16; chn++)
1271 {
1272 midi_outc(i, (unsigned char) (0xb0 + (chn & 0x0f))); /* control change */
1273 midi_outc(i, 0x7b); /* All notes off */
1274 midi_outc(i, 0); /* Dummy parameter */
1275 }
1276
1277 midi_devs[i]->close(i);
1278
1279 midi_written[i] = 0;
1280 midi_opened[i] = 0;
1281 }
1282 }
1283
1284 seq_playing = 0;
1285
1286 spin_lock_irqsave(&lock,flags);
1287
1288 if (waitqueue_active(&seq_sleeper)) {
1289 /* printk( "Sequencer Warning: Unexpected sleeping process - Waking up\n"); */
1290 wake_up(&seq_sleeper);
1291 }
1292 spin_unlock_irqrestore(&lock,flags);
1293}
1294
1295static void seq_panic(void)
1296{
1297 /*
1298 * This routine is called by the application in case the user
1299 * wants to reset the system to the default state.
1300 */
1301
1302 seq_reset();
1303
1304 /*
1305 * Since some of the devices don't recognize the active sensing and
1306 * all notes off messages, we have to shut all notes manually.
1307 *
1308 * TO BE IMPLEMENTED LATER
1309 */
1310
1311 /*
1312 * Also return the controllers to their default states
1313 */
1314}
1315
1316int sequencer_ioctl(int dev, struct file *file, unsigned int cmd, void __user *arg)
1317{
1318 int midi_dev, orig_dev, val, err;
1319 int mode = translate_mode(file);
1320 struct synth_info inf;
1321 struct seq_event_rec event_rec;
1322 int __user *p = arg;
1323
1324 orig_dev = dev = dev >> 4;
1325
1326 switch (cmd)
1327 {
1328 case SNDCTL_TMR_TIMEBASE:
1329 case SNDCTL_TMR_TEMPO:
1330 case SNDCTL_TMR_START:
1331 case SNDCTL_TMR_STOP:
1332 case SNDCTL_TMR_CONTINUE:
1333 case SNDCTL_TMR_METRONOME:
1334 case SNDCTL_TMR_SOURCE:
1335 if (seq_mode != SEQ_2)
1336 return -EINVAL;
1337 return tmr->ioctl(tmr_no, cmd, arg);
1338
1339 case SNDCTL_TMR_SELECT:
1340 if (seq_mode != SEQ_2)
1341 return -EINVAL;
1342 if (get_user(pending_timer, p))
1343 return -EFAULT;
1344 if (pending_timer < 0 || pending_timer >= num_sound_timers || sound_timer_devs[pending_timer] == NULL)
1345 {
1346 pending_timer = -1;
1347 return -EINVAL;
1348 }
1349 val = pending_timer;
1350 break;
1351
1352 case SNDCTL_SEQ_PANIC:
1353 seq_panic();
1354 return -EINVAL;
1355
1356 case SNDCTL_SEQ_SYNC:
1357 if (mode == OPEN_READ)
1358 return 0;
1359 while (qlen > 0 && !signal_pending(current))
1360 seq_sync();
1361 return qlen ? -EINTR : 0;
1362
1363 case SNDCTL_SEQ_RESET:
1364 seq_reset();
1365 return 0;
1366
1367 case SNDCTL_SEQ_TESTMIDI:
1368 if (__get_user(midi_dev, p))
1369 return -EFAULT;
1370 if (midi_dev < 0 || midi_dev >= max_mididev || !midi_devs[midi_dev])
1371 return -ENXIO;
1372
1373 if (!midi_opened[midi_dev] &&
1374 (err = midi_devs[midi_dev]->open(midi_dev, mode, sequencer_midi_input,
1375 sequencer_midi_output)) < 0)
1376 return err;
1377 midi_opened[midi_dev] = 1;
1378 return 0;
1379
1380 case SNDCTL_SEQ_GETINCOUNT:
1381 if (mode == OPEN_WRITE)
1382 return 0;
1383 val = iqlen;
1384 break;
1385
1386 case SNDCTL_SEQ_GETOUTCOUNT:
1387 if (mode == OPEN_READ)
1388 return 0;
1389 val = SEQ_MAX_QUEUE - qlen;
1390 break;
1391
1392 case SNDCTL_SEQ_GETTIME:
1393 if (seq_mode == SEQ_2)
1394 return tmr->ioctl(tmr_no, cmd, arg);
1395 val = jiffies - seq_time;
1396 break;
1397
1398 case SNDCTL_SEQ_CTRLRATE:
1399 /*
1400 * If *arg == 0, just return the current rate
1401 */
1402 if (seq_mode == SEQ_2)
1403 return tmr->ioctl(tmr_no, cmd, arg);
1404
1405 if (get_user(val, p))
1406 return -EFAULT;
1407 if (val != 0)
1408 return -EINVAL;
1409 val = HZ;
1410 break;
1411
1412 case SNDCTL_SEQ_RESETSAMPLES:
1413 case SNDCTL_SYNTH_REMOVESAMPLE:
1414 case SNDCTL_SYNTH_CONTROL:
1415 if (get_user(dev, p))
1416 return -EFAULT;
1417 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1418 return -ENXIO;
1419 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1420 return -EBUSY;
1421 return synth_devs[dev]->ioctl(dev, cmd, arg);
1422
1423 case SNDCTL_SEQ_NRSYNTHS:
1424 val = max_synthdev;
1425 break;
1426
1427 case SNDCTL_SEQ_NRMIDIS:
1428 val = max_mididev;
1429 break;
1430
1431 case SNDCTL_SYNTH_MEMAVL:
1432 if (get_user(dev, p))
1433 return -EFAULT;
1434 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1435 return -ENXIO;
1436 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1437 return -EBUSY;
1438 val = synth_devs[dev]->ioctl(dev, cmd, arg);
1439 break;
1440
1441 case SNDCTL_FM_4OP_ENABLE:
1442 if (get_user(dev, p))
1443 return -EFAULT;
1444 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1445 return -ENXIO;
1446 if (!(synth_open_mask & (1 << dev)))
1447 return -ENXIO;
1448 synth_devs[dev]->ioctl(dev, cmd, arg);
1449 return 0;
1450
1451 case SNDCTL_SYNTH_INFO:
1452 if (get_user(dev, &((struct synth_info __user *)arg)->device))
1453 return -EFAULT;
1454 if (dev < 0 || dev >= max_synthdev)
1455 return -ENXIO;
1456 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1457 return -EBUSY;
1458 return synth_devs[dev]->ioctl(dev, cmd, arg);
1459
1460 /* Like SYNTH_INFO but returns ID in the name field */
1461 case SNDCTL_SYNTH_ID:
1462 if (get_user(dev, &((struct synth_info __user *)arg)->device))
1463 return -EFAULT;
1464 if (dev < 0 || dev >= max_synthdev)
1465 return -ENXIO;
1466 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1467 return -EBUSY;
1468 memcpy(&inf, synth_devs[dev]->info, sizeof(inf));
1469 strlcpy(inf.name, synth_devs[dev]->id, sizeof(inf.name));
1470 inf.device = dev;
1471 return copy_to_user(arg, &inf, sizeof(inf))?-EFAULT:0;
1472
1473 case SNDCTL_SEQ_OUTOFBAND:
1474 if (copy_from_user(&event_rec, arg, sizeof(event_rec)))
1475 return -EFAULT;
1476 play_event(event_rec.arr);
1477 return 0;
1478
1479 case SNDCTL_MIDI_INFO:
1480 if (get_user(dev, &((struct midi_info __user *)arg)->device))
1481 return -EFAULT;
1482 if (dev < 0 || dev >= max_mididev || !midi_devs[dev])
1483 return -ENXIO;
1484 midi_devs[dev]->info.device = dev;
1485 return copy_to_user(arg, &midi_devs[dev]->info, sizeof(struct midi_info))?-EFAULT:0;
1486
1487 case SNDCTL_SEQ_THRESHOLD:
1488 if (get_user(val, p))
1489 return -EFAULT;
1490 if (val < 1)
1491 val = 1;
1492 if (val >= SEQ_MAX_QUEUE)
1493 val = SEQ_MAX_QUEUE - 1;
1494 output_threshold = val;
1495 return 0;
1496
1497 case SNDCTL_MIDI_PRETIME:
1498 if (get_user(val, p))
1499 return -EFAULT;
1500 if (val < 0)
1501 val = 0;
1502 val = (HZ * val) / 10;
1503 pre_event_timeout = val;
1504 break;
1505
1506 default:
1507 if (mode == OPEN_READ)
1508 return -EIO;
1509 if (!synth_devs[0])
1510 return -ENXIO;
1511 if (!(synth_open_mask & (1 << 0)))
1512 return -ENXIO;
1513 if (!synth_devs[0]->ioctl)
1514 return -EINVAL;
1515 return synth_devs[0]->ioctl(0, cmd, arg);
1516 }
1517 return put_user(val, p);
1518}
1519
1520/* No kernel lock - we're using the global irq lock here */
1521unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait)
1522{
1523 unsigned long flags;
1524 unsigned int mask = 0;
1525
1526 dev = dev >> 4;
1527
1528 spin_lock_irqsave(&lock,flags);
1529 /* input */
1530 poll_wait(file, &midi_sleeper, wait);
1531 if (iqlen)
1532 mask |= POLLIN | POLLRDNORM;
1533
1534 /* output */
1535 poll_wait(file, &seq_sleeper, wait);
1536 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
1537 mask |= POLLOUT | POLLWRNORM;
1538 spin_unlock_irqrestore(&lock,flags);
1539 return mask;
1540}
1541
1542
1543void sequencer_timer(unsigned long dummy)
1544{
1545 seq_startplay();
1546}
1547EXPORT_SYMBOL(sequencer_timer);
1548
1549int note_to_freq(int note_num)
1550{
1551
1552 /*
1553 * This routine converts a midi note to a frequency (multiplied by 1000)
1554 */
1555
1556 int note, octave, note_freq;
1557 static int notes[] =
1558 {
1559 261632, 277189, 293671, 311132, 329632, 349232,
1560 369998, 391998, 415306, 440000, 466162, 493880
1561 };
1562
1563#define BASE_OCTAVE 5
1564
1565 octave = note_num / 12;
1566 note = note_num % 12;
1567
1568 note_freq = notes[note];
1569
1570 if (octave < BASE_OCTAVE)
1571 note_freq >>= (BASE_OCTAVE - octave);
1572 else if (octave > BASE_OCTAVE)
1573 note_freq <<= (octave - BASE_OCTAVE);
1574
1575 /*
1576 * note_freq >>= 1;
1577 */
1578
1579 return note_freq;
1580}
1581EXPORT_SYMBOL(note_to_freq);
1582
1583unsigned long compute_finetune(unsigned long base_freq, int bend, int range,
1584 int vibrato_cents)
1585{
1586 unsigned long amount;
1587 int negative, semitones, cents, multiplier = 1;
1588
1589 if (!bend)
1590 return base_freq;
1591 if (!range)
1592 return base_freq;
1593
1594 if (!base_freq)
1595 return base_freq;
1596
1597 if (range >= 8192)
1598 range = 8192;
1599
1600 bend = bend * range / 8192; /* Convert to cents */
1601 bend += vibrato_cents;
1602
1603 if (!bend)
1604 return base_freq;
1605
1606 negative = bend < 0 ? 1 : 0;
1607
1608 if (bend < 0)
1609 bend *= -1;
1610 if (bend > range)
1611 bend = range;
1612
1613 /*
1614 if (bend > 2399)
1615 bend = 2399;
1616 */
1617 while (bend > 2399)
1618 {
1619 multiplier *= 4;
1620 bend -= 2400;
1621 }
1622
1623 semitones = bend / 100;
1624 cents = bend % 100;
1625
1626 amount = (int) (semitone_tuning[semitones] * multiplier * cent_tuning[cents]) / 10000;
1627
1628 if (negative)
1629 return (base_freq * 10000) / amount; /* Bend down */
1630 else
1631 return (base_freq * amount) / 10000; /* Bend up */
1632}
1633EXPORT_SYMBOL(compute_finetune);
1634
1635void sequencer_init(void)
1636{
1637 if (sequencer_ok)
1638 return;
1639 queue = vmalloc(SEQ_MAX_QUEUE * EV_SZ);
1640 if (queue == NULL)
1641 {
1642 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer output queue\n");
1643 return;
1644 }
1645 iqueue = vmalloc(SEQ_MAX_QUEUE * IEV_SZ);
1646 if (iqueue == NULL)
1647 {
1648 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer input queue\n");
1649 vfree(queue);
1650 return;
1651 }
1652 sequencer_ok = 1;
1653}
1654EXPORT_SYMBOL(sequencer_init);
1655
1656void sequencer_unload(void)
1657{
1658 vfree(queue);
1659 vfree(iqueue);
1660 queue = iqueue = NULL;
1661}
diff --git a/sound/oss/sleep.h b/sound/oss/sleep.h
deleted file mode 100644
index a20fc925a5ce..000000000000
--- a/sound/oss/sleep.h
+++ /dev/null
@@ -1,18 +0,0 @@
1#include <linux/wait.h>
2
3/*
4 * Do not use. This is a replacement for the old
5 * "interruptible_sleep_on_timeout" function that has been
6 * deprecated for ages. All users should instead try to use
7 * wait_event_interruptible_timeout.
8 */
9
10static inline long
11oss_broken_sleep_on(wait_queue_head_t *q, long timeout)
12{
13 DEFINE_WAIT(wait);
14 prepare_to_wait(q, &wait, TASK_INTERRUPTIBLE);
15 timeout = schedule_timeout(timeout);
16 finish_wait(q, &wait);
17 return timeout;
18}
diff --git a/sound/oss/sound_calls.h b/sound/oss/sound_calls.h
deleted file mode 100644
index 87d8ad4a0340..000000000000
--- a/sound/oss/sound_calls.h
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * DMA buffer calls
3 */
4
5int DMAbuf_open(int dev, int mode);
6int DMAbuf_release(int dev, int mode);
7int DMAbuf_getwrbuffer(int dev, char **buf, int *size, int dontblock);
8int DMAbuf_getrdbuffer(int dev, char **buf, int *len, int dontblock);
9int DMAbuf_rmchars(int dev, int buff_no, int c);
10int DMAbuf_start_output(int dev, int buff_no, int l);
11int DMAbuf_move_wrpointer(int dev, int l);
12/* int DMAbuf_ioctl(int dev, unsigned int cmd, void __user *arg, int local); */
13void DMAbuf_init(int dev, int dma1, int dma2);
14void DMAbuf_deinit(int dev);
15int DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode);
16void DMAbuf_inputintr(int dev);
17void DMAbuf_outputintr(int dev, int underflow_flag);
18struct dma_buffparms;
19int DMAbuf_space_in_queue (int dev);
20int DMAbuf_activate_recording (int dev, struct dma_buffparms *dmap);
21int DMAbuf_get_buffer_pointer (int dev, struct dma_buffparms *dmap, int direction);
22void DMAbuf_launch_output(int dev, struct dma_buffparms *dmap);
23unsigned int DMAbuf_poll(struct file *file, int dev, poll_table *wait);
24void DMAbuf_start_devices(unsigned int devmask);
25void DMAbuf_reset (int dev);
26int DMAbuf_sync (int dev);
27
28/*
29 * System calls for /dev/dsp and /dev/audio (audio.c)
30 */
31
32int audio_read (int dev, struct file *file, char __user *buf, int count);
33int audio_write (int dev, struct file *file, const char __user *buf, int count);
34int audio_open (int dev, struct file *file);
35void audio_release (int dev, struct file *file);
36int audio_ioctl (int dev, struct file *file,
37 unsigned int cmd, void __user *arg);
38void audio_init_devices (void);
39void reorganize_buffers (int dev, struct dma_buffparms *dmap, int recording);
40
41/*
42 * System calls for the /dev/sequencer
43 */
44
45int sequencer_read (int dev, struct file *file, char __user *buf, int count);
46int sequencer_write (int dev, struct file *file, const char __user *buf, int count);
47int sequencer_open (int dev, struct file *file);
48void sequencer_release (int dev, struct file *file);
49int sequencer_ioctl (int dev, struct file *file, unsigned int cmd, void __user *arg);
50unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait);
51
52void sequencer_init (void);
53void sequencer_unload (void);
54void sequencer_timer(unsigned long dummy);
55int note_to_freq(int note_num);
56unsigned long compute_finetune(unsigned long base_freq, int bend, int range,
57 int vibrato_bend);
58void seq_input_event(unsigned char *event, int len);
59void seq_copy_to_input (unsigned char *event, int len);
60
61/*
62 * System calls for the /dev/midi
63 */
64
65int MIDIbuf_read (int dev, struct file *file, char __user *buf, int count);
66int MIDIbuf_write (int dev, struct file *file, const char __user *buf, int count);
67int MIDIbuf_open (int dev, struct file *file);
68void MIDIbuf_release (int dev, struct file *file);
69int MIDIbuf_ioctl (int dev, struct file *file, unsigned int cmd, void __user *arg);
70unsigned int MIDIbuf_poll(int dev, struct file *file, poll_table * wait);
71int MIDIbuf_avail(int dev);
72
73void MIDIbuf_bytes_received(int dev, unsigned char *buf, int count);
74
75
76/* From soundcard.c */
77void request_sound_timer (int count);
78void sound_stop_timer(void);
79void conf_printf(char *name, struct address_info *hw_config);
80void conf_printf2(char *name, int base, int irq, int dma, int dma2);
81
82/* From sound_timer.c */
83void sound_timer_interrupt(void);
84void sound_timer_syncinterval(unsigned int new_usecs);
85
86/* From midi_synth.c */
87void do_midi_msg (int synthno, unsigned char *msg, int mlen);
diff --git a/sound/oss/sound_config.h b/sound/oss/sound_config.h
deleted file mode 100644
index 5253b0a70437..000000000000
--- a/sound/oss/sound_config.h
+++ /dev/null
@@ -1,144 +0,0 @@
1/* sound_config.h
2 *
3 * A driver for sound cards, misc. configuration parameters.
4 */
5/*
6 * Copyright (C) by Hannu Savolainen 1993-1997
7 *
8 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
9 * Version 2 (June 1991). See the "COPYING" file distributed with this software
10 * for more info.
11 */
12
13
14#ifndef _SOUND_CONFIG_H_
15#define _SOUND_CONFIG_H_
16
17#include <linux/fs.h>
18#include <linux/sound.h>
19#include <linux/sched/signal.h>
20
21#include "os.h"
22#include "soundvers.h"
23
24
25#ifndef SND_DEFAULT_ENABLE
26#define SND_DEFAULT_ENABLE 1
27#endif
28
29#ifndef MAX_REALTIME_FACTOR
30#define MAX_REALTIME_FACTOR 4
31#endif
32
33/*
34 * Use always 64k buffer size. There is no reason to use shorter.
35 */
36#undef DSP_BUFFSIZE
37#define DSP_BUFFSIZE (64*1024)
38
39#ifndef DSP_BUFFCOUNT
40#define DSP_BUFFCOUNT 1 /* 1 is recommended. */
41#endif
42
43#define FM_MONO 0x388 /* This is the I/O address used by AdLib */
44
45#ifndef CONFIG_PAS_BASE
46#define CONFIG_PAS_BASE 0x388
47#endif
48
49/* SEQ_MAX_QUEUE is the maximum number of sequencer events buffered by the
50 driver. (There is no need to alter this) */
51#define SEQ_MAX_QUEUE 1024
52
53#define SBFM_MAXINSTR (256) /* Size of the FM Instrument bank */
54/* 128 instruments for general MIDI setup and 16 unassigned */
55
56#define SND_NDEVS 256 /* Number of supported devices */
57
58#define DSP_DEFAULT_SPEED 8000
59
60#define MAX_AUDIO_DEV 5
61#define MAX_MIXER_DEV 5
62#define MAX_SYNTH_DEV 5
63#define MAX_MIDI_DEV 6
64#define MAX_TIMER_DEV 4
65
66struct address_info {
67 int io_base;
68 int irq;
69 int dma;
70 int dma2;
71 int always_detect; /* 1=Trust me, it's there */
72 char *name;
73 int driver_use_1; /* Driver defined field 1 */
74 int driver_use_2; /* Driver defined field 2 */
75 int *osp; /* OS specific info */
76 int card_subtype; /* Driver specific. Usually 0 */
77 void *memptr; /* Module memory chainer */
78 int slots[6]; /* To remember driver slot ids */
79};
80
81#define SYNTH_MAX_VOICES 32
82
83struct voice_alloc_info {
84 int max_voice;
85 int used_voices;
86 int ptr; /* For device specific use */
87 unsigned short map[SYNTH_MAX_VOICES]; /* (ch << 8) | (note+1) */
88 int timestamp;
89 int alloc_times[SYNTH_MAX_VOICES];
90 };
91
92struct channel_info {
93 int pgm_num;
94 int bender_value;
95 int bender_range;
96 unsigned char controllers[128];
97 };
98
99/*
100 * Process wakeup reasons
101 */
102#define WK_NONE 0x00
103#define WK_WAKEUP 0x01
104#define WK_TIMEOUT 0x02
105#define WK_SIGNAL 0x04
106#define WK_SLEEP 0x08
107#define WK_SELECT 0x10
108#define WK_ABORT 0x20
109
110#define OPEN_READ PCM_ENABLE_INPUT
111#define OPEN_WRITE PCM_ENABLE_OUTPUT
112#define OPEN_READWRITE (OPEN_READ|OPEN_WRITE)
113
114static inline int translate_mode(struct file *file)
115{
116 if (OPEN_READ == (__force int)FMODE_READ &&
117 OPEN_WRITE == (__force int)FMODE_WRITE)
118 return (__force int)(file->f_mode & (FMODE_READ | FMODE_WRITE));
119 else
120 return ((file->f_mode & FMODE_READ) ? OPEN_READ : 0) |
121 ((file->f_mode & FMODE_WRITE) ? OPEN_WRITE : 0);
122}
123
124#include "sound_calls.h"
125#include "dev_table.h"
126
127#ifndef DDB
128#define DDB(x) do {} while (0)
129#endif
130
131#ifndef MDB
132#ifdef MODULE
133#define MDB(x) x
134#else
135#define MDB(x)
136#endif
137#endif
138
139#define TIMER_ARMED 121234
140#define TIMER_NOT_ARMED 1
141
142#define MAX_MEM_BLOCKS 1024
143
144#endif
diff --git a/sound/oss/sound_firmware.h b/sound/oss/sound_firmware.h
deleted file mode 100644
index 2be465277ba0..000000000000
--- a/sound/oss/sound_firmware.h
+++ /dev/null
@@ -1,29 +0,0 @@
1#include <linux/fs.h>
2
3/**
4 * mod_firmware_load - load sound driver firmware
5 * @fn: filename
6 * @fp: return for the buffer.
7 *
8 * Load the firmware for a sound module (up to 128K) into a buffer.
9 * The buffer is returned in *fp. It is allocated with vmalloc so is
10 * virtually linear and not DMAable. The caller should free it with
11 * vfree when finished.
12 *
13 * The length of the buffer is returned on a successful load, the
14 * value zero on a failure.
15 *
16 * Caution: This API is not recommended. Firmware should be loaded via
17 * request_firmware.
18 */
19static inline int mod_firmware_load(const char *fn, char **fp)
20{
21 loff_t size;
22 int err;
23
24 err = kernel_read_file_from_path(fn, (void **)fp, &size,
25 131072, READING_FIRMWARE);
26 if (err < 0)
27 return 0;
28 return size;
29}
diff --git a/sound/oss/sound_timer.c b/sound/oss/sound_timer.c
deleted file mode 100644
index 3a444a6f10eb..000000000000
--- a/sound/oss/sound_timer.c
+++ /dev/null
@@ -1,327 +0,0 @@
1/*
2 * sound/oss/sound_timer.c
3 */
4/*
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 */
11/*
12 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
13 */
14#include <linux/string.h>
15#include <linux/spinlock.h>
16
17#include "sound_config.h"
18
19static volatile int initialized, opened, tmr_running;
20static volatile unsigned int tmr_offs, tmr_ctr;
21static volatile unsigned long ticks_offs;
22static volatile int curr_tempo, curr_timebase;
23static volatile unsigned long curr_ticks;
24static volatile unsigned long next_event_time;
25static unsigned long prev_event_time;
26static volatile unsigned long usecs_per_tmr; /* Length of the current interval */
27
28static struct sound_lowlev_timer *tmr;
29static DEFINE_SPINLOCK(lock);
30
31static unsigned long tmr2ticks(int tmr_value)
32{
33 /*
34 * Convert timer ticks to MIDI ticks
35 */
36
37 unsigned long tmp;
38 unsigned long scale;
39
40 tmp = tmr_value * usecs_per_tmr; /* Convert to usecs */
41 scale = (60 * 1000000) / (curr_tempo * curr_timebase); /* usecs per MIDI tick */
42 return (tmp + (scale / 2)) / scale;
43}
44
45void reprogram_timer(void)
46{
47 unsigned long usecs_per_tick;
48
49 /*
50 * The user is changing the timer rate before setting a timer
51 * slap, bad bad not allowed.
52 */
53
54 if(!tmr)
55 return;
56
57 usecs_per_tick = (60 * 1000000) / (curr_tempo * curr_timebase);
58
59 /*
60 * Don't kill the system by setting too high timer rate
61 */
62 if (usecs_per_tick < 2000)
63 usecs_per_tick = 2000;
64
65 usecs_per_tmr = tmr->tmr_start(tmr->dev, usecs_per_tick);
66}
67
68void sound_timer_syncinterval(unsigned int new_usecs)
69{
70 /*
71 * This routine is called by the hardware level if
72 * the clock frequency has changed for some reason.
73 */
74 tmr_offs = tmr_ctr;
75 ticks_offs += tmr2ticks(tmr_ctr);
76 tmr_ctr = 0;
77 usecs_per_tmr = new_usecs;
78}
79EXPORT_SYMBOL(sound_timer_syncinterval);
80
81static void tmr_reset(void)
82{
83 unsigned long flags;
84
85 spin_lock_irqsave(&lock,flags);
86 tmr_offs = 0;
87 ticks_offs = 0;
88 tmr_ctr = 0;
89 next_event_time = (unsigned long) -1;
90 prev_event_time = 0;
91 curr_ticks = 0;
92 spin_unlock_irqrestore(&lock,flags);
93}
94
95static int timer_open(int dev, int mode)
96{
97 if (opened)
98 return -EBUSY;
99 tmr_reset();
100 curr_tempo = 60;
101 curr_timebase = 100;
102 opened = 1;
103 reprogram_timer();
104 return 0;
105}
106
107static void timer_close(int dev)
108{
109 opened = tmr_running = 0;
110 tmr->tmr_disable(tmr->dev);
111}
112
113static int timer_event(int dev, unsigned char *event)
114{
115 unsigned char cmd = event[1];
116 unsigned long parm = *(int *) &event[4];
117
118 switch (cmd)
119 {
120 case TMR_WAIT_REL:
121 parm += prev_event_time;
122 case TMR_WAIT_ABS:
123 if (parm > 0)
124 {
125 long time;
126
127 if (parm <= curr_ticks) /* It's the time */
128 return TIMER_NOT_ARMED;
129 time = parm;
130 next_event_time = prev_event_time = time;
131 return TIMER_ARMED;
132 }
133 break;
134
135 case TMR_START:
136 tmr_reset();
137 tmr_running = 1;
138 reprogram_timer();
139 break;
140
141 case TMR_STOP:
142 tmr_running = 0;
143 break;
144
145 case TMR_CONTINUE:
146 tmr_running = 1;
147 reprogram_timer();
148 break;
149
150 case TMR_TEMPO:
151 if (parm)
152 {
153 if (parm < 8)
154 parm = 8;
155 if (parm > 250)
156 parm = 250;
157 tmr_offs = tmr_ctr;
158 ticks_offs += tmr2ticks(tmr_ctr);
159 tmr_ctr = 0;
160 curr_tempo = parm;
161 reprogram_timer();
162 }
163 break;
164
165 case TMR_ECHO:
166 seq_copy_to_input(event, 8);
167 break;
168
169 default:;
170 }
171 return TIMER_NOT_ARMED;
172}
173
174static unsigned long timer_get_time(int dev)
175{
176 if (!opened)
177 return 0;
178 return curr_ticks;
179}
180
181static int timer_ioctl(int dev, unsigned int cmd, void __user *arg)
182{
183 int __user *p = arg;
184 int val;
185
186 switch (cmd)
187 {
188 case SNDCTL_TMR_SOURCE:
189 val = TMR_INTERNAL;
190 break;
191
192 case SNDCTL_TMR_START:
193 tmr_reset();
194 tmr_running = 1;
195 return 0;
196
197 case SNDCTL_TMR_STOP:
198 tmr_running = 0;
199 return 0;
200
201 case SNDCTL_TMR_CONTINUE:
202 tmr_running = 1;
203 return 0;
204
205 case SNDCTL_TMR_TIMEBASE:
206 if (get_user(val, p))
207 return -EFAULT;
208 if (val)
209 {
210 if (val < 1)
211 val = 1;
212 if (val > 1000)
213 val = 1000;
214 curr_timebase = val;
215 }
216 val = curr_timebase;
217 break;
218
219 case SNDCTL_TMR_TEMPO:
220 if (get_user(val, p))
221 return -EFAULT;
222 if (val)
223 {
224 if (val < 8)
225 val = 8;
226 if (val > 250)
227 val = 250;
228 tmr_offs = tmr_ctr;
229 ticks_offs += tmr2ticks(tmr_ctr);
230 tmr_ctr = 0;
231 curr_tempo = val;
232 reprogram_timer();
233 }
234 val = curr_tempo;
235 break;
236
237 case SNDCTL_SEQ_CTRLRATE:
238 if (get_user(val, p))
239 return -EFAULT;
240 if (val != 0) /* Can't change */
241 return -EINVAL;
242 val = ((curr_tempo * curr_timebase) + 30) / 60;
243 break;
244
245 case SNDCTL_SEQ_GETTIME:
246 val = curr_ticks;
247 break;
248
249 case SNDCTL_TMR_METRONOME:
250 default:
251 return -EINVAL;
252 }
253 return put_user(val, p);
254}
255
256static void timer_arm(int dev, long time)
257{
258 if (time < 0)
259 time = curr_ticks + 1;
260 else if (time <= curr_ticks) /* It's the time */
261 return;
262
263 next_event_time = prev_event_time = time;
264 return;
265}
266
267static struct sound_timer_operations sound_timer =
268{
269 .owner = THIS_MODULE,
270 .info = {"Sound Timer", 0},
271 .priority = 1, /* Priority */
272 .devlink = 0, /* Local device link */
273 .open = timer_open,
274 .close = timer_close,
275 .event = timer_event,
276 .get_time = timer_get_time,
277 .ioctl = timer_ioctl,
278 .arm_timer = timer_arm
279};
280
281void sound_timer_interrupt(void)
282{
283 unsigned long flags;
284
285 if (!opened)
286 return;
287
288 tmr->tmr_restart(tmr->dev);
289
290 if (!tmr_running)
291 return;
292
293 spin_lock_irqsave(&lock,flags);
294 tmr_ctr++;
295 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
296
297 if (curr_ticks >= next_event_time)
298 {
299 next_event_time = (unsigned long) -1;
300 sequencer_timer(0);
301 }
302 spin_unlock_irqrestore(&lock,flags);
303}
304EXPORT_SYMBOL(sound_timer_interrupt);
305
306void sound_timer_init(struct sound_lowlev_timer *t, char *name)
307{
308 int n;
309
310 if (initialized)
311 {
312 if (t->priority <= tmr->priority)
313 return; /* There is already a similar or better timer */
314 tmr = t;
315 return;
316 }
317 initialized = 1;
318 tmr = t;
319
320 n = sound_alloc_timerdev();
321 if (n == -1)
322 n = 0; /* Overwrite the system timer */
323 strlcpy(sound_timer.info.name, name, sizeof(sound_timer.info.name));
324 sound_timer_devs[n] = &sound_timer;
325}
326EXPORT_SYMBOL(sound_timer_init);
327
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
deleted file mode 100644
index b70c7c8f9c5d..000000000000
--- a/sound/oss/soundcard.c
+++ /dev/null
@@ -1,733 +0,0 @@
1/*
2 * linux/sound/oss/soundcard.c
3 *
4 * Sound card driver for Linux
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * integrated sound_switch.c
16 * Stefan Reinauer : integrated /proc/sound (equals to /dev/sndstat,
17 * which should disappear in the near future)
18 * Eric Dumas : devfs support (22-Jan-98) <dumas@linux.eu.org> with
19 * fixups by C. Scott Ananian <cananian@alumni.princeton.edu>
20 * Richard Gooch : moved common (non OSS-specific) devices to sound_core.c
21 * Rob Riggs : Added persistent DMA buffers support (1998/10/17)
22 * Christoph Hellwig : Some cleanup work (2000/03/01)
23 */
24
25
26#include "sound_config.h"
27#include <linux/init.h>
28#include <linux/types.h>
29#include <linux/errno.h>
30#include <linux/signal.h>
31#include <linux/fcntl.h>
32#include <linux/ctype.h>
33#include <linux/stddef.h>
34#include <linux/kmod.h>
35#include <linux/kernel.h>
36#include <asm/dma.h>
37#include <asm/io.h>
38#include <linux/wait.h>
39#include <linux/ioport.h>
40#include <linux/major.h>
41#include <linux/delay.h>
42#include <linux/proc_fs.h>
43#include <linux/mutex.h>
44#include <linux/module.h>
45#include <linux/mm.h>
46#include <linux/device.h>
47
48/*
49 * This ought to be moved into include/asm/dma.h
50 */
51#ifndef valid_dma
52#define valid_dma(n) ((n) >= 0 && (n) < MAX_DMA_CHANNELS && (n) != 4)
53#endif
54
55/*
56 * Table for permanently allocated memory (used when unloading the module)
57 */
58void * sound_mem_blocks[MAX_MEM_BLOCKS];
59static DEFINE_MUTEX(soundcard_mutex);
60int sound_nblocks = 0;
61
62/* Persistent DMA buffers */
63#ifdef CONFIG_SOUND_DMAP
64int sound_dmap_flag = 1;
65#else
66int sound_dmap_flag = 0;
67#endif
68
69static char dma_alloc_map[MAX_DMA_CHANNELS];
70
71#define DMA_MAP_UNAVAIL 0
72#define DMA_MAP_FREE 1
73#define DMA_MAP_BUSY 2
74
75
76unsigned long seq_time = 0; /* Time for /dev/sequencer */
77extern struct class *sound_class;
78
79/*
80 * Table for configurable mixer volume handling
81 */
82static mixer_vol_table mixer_vols[MAX_MIXER_DEV];
83static int num_mixer_volumes;
84
85int *load_mixer_volumes(char *name, int *levels, int present)
86{
87 int i, n;
88
89 for (i = 0; i < num_mixer_volumes; i++) {
90 if (strncmp(name, mixer_vols[i].name, 32) == 0) {
91 if (present)
92 mixer_vols[i].num = i;
93 return mixer_vols[i].levels;
94 }
95 }
96 if (num_mixer_volumes >= MAX_MIXER_DEV) {
97 printk(KERN_ERR "Sound: Too many mixers (%s)\n", name);
98 return levels;
99 }
100 n = num_mixer_volumes++;
101
102 strncpy(mixer_vols[n].name, name, 32);
103
104 if (present)
105 mixer_vols[n].num = n;
106 else
107 mixer_vols[n].num = -1;
108
109 for (i = 0; i < 32; i++)
110 mixer_vols[n].levels[i] = levels[i];
111 return mixer_vols[n].levels;
112}
113EXPORT_SYMBOL(load_mixer_volumes);
114
115static int set_mixer_levels(void __user * arg)
116{
117 /* mixer_vol_table is 174 bytes, so IMHO no reason to not allocate it on the stack */
118 mixer_vol_table buf;
119
120 if (__copy_from_user(&buf, arg, sizeof(buf)))
121 return -EFAULT;
122 load_mixer_volumes(buf.name, buf.levels, 0);
123 if (__copy_to_user(arg, &buf, sizeof(buf)))
124 return -EFAULT;
125 return 0;
126}
127
128static int get_mixer_levels(void __user * arg)
129{
130 int n;
131
132 if (__get_user(n, (int __user *)(&(((mixer_vol_table __user *)arg)->num))))
133 return -EFAULT;
134 if (n < 0 || n >= num_mixer_volumes)
135 return -EINVAL;
136 if (__copy_to_user(arg, &mixer_vols[n], sizeof(mixer_vol_table)))
137 return -EFAULT;
138 return 0;
139}
140
141/* 4K page size but our output routines use some slack for overruns */
142#define PROC_BLOCK_SIZE (3*1024)
143
144static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
145{
146 int dev = iminor(file_inode(file));
147 int ret = -EINVAL;
148
149 /*
150 * The OSS drivers aren't remotely happy without this locking,
151 * and unless someone fixes them when they are about to bite the
152 * big one anyway, we might as well bandage here..
153 */
154
155 mutex_lock(&soundcard_mutex);
156
157 switch (dev & 0x0f) {
158 case SND_DEV_DSP:
159 case SND_DEV_DSP16:
160 case SND_DEV_AUDIO:
161 ret = audio_read(dev, file, buf, count);
162 break;
163
164 case SND_DEV_SEQ:
165 case SND_DEV_SEQ2:
166 ret = sequencer_read(dev, file, buf, count);
167 break;
168
169 case SND_DEV_MIDIN:
170 ret = MIDIbuf_read(dev, file, buf, count);
171 }
172 mutex_unlock(&soundcard_mutex);
173 return ret;
174}
175
176static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
177{
178 int dev = iminor(file_inode(file));
179 int ret = -EINVAL;
180
181 mutex_lock(&soundcard_mutex);
182 switch (dev & 0x0f) {
183 case SND_DEV_SEQ:
184 case SND_DEV_SEQ2:
185 ret = sequencer_write(dev, file, buf, count);
186 break;
187
188 case SND_DEV_DSP:
189 case SND_DEV_DSP16:
190 case SND_DEV_AUDIO:
191 ret = audio_write(dev, file, buf, count);
192 break;
193
194 case SND_DEV_MIDIN:
195 ret = MIDIbuf_write(dev, file, buf, count);
196 break;
197 }
198 mutex_unlock(&soundcard_mutex);
199 return ret;
200}
201
202static int sound_open(struct inode *inode, struct file *file)
203{
204 int dev = iminor(inode);
205 int retval;
206
207 if ((dev >= SND_NDEVS) || (dev < 0)) {
208 printk(KERN_ERR "Invalid minor device %d\n", dev);
209 return -ENXIO;
210 }
211 mutex_lock(&soundcard_mutex);
212 switch (dev & 0x0f) {
213 case SND_DEV_CTL:
214 dev >>= 4;
215 if (dev >= 0 && dev < MAX_MIXER_DEV && mixer_devs[dev] == NULL) {
216 request_module("mixer%d", dev);
217 }
218 retval = -ENXIO;
219 if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL))
220 break;
221
222 if (!try_module_get(mixer_devs[dev]->owner))
223 break;
224
225 retval = 0;
226 break;
227
228 case SND_DEV_SEQ:
229 case SND_DEV_SEQ2:
230 retval = sequencer_open(dev, file);
231 break;
232
233 case SND_DEV_MIDIN:
234 retval = MIDIbuf_open(dev, file);
235 break;
236
237 case SND_DEV_DSP:
238 case SND_DEV_DSP16:
239 case SND_DEV_AUDIO:
240 retval = audio_open(dev, file);
241 break;
242
243 default:
244 printk(KERN_ERR "Invalid minor device %d\n", dev);
245 retval = -ENXIO;
246 }
247
248 mutex_unlock(&soundcard_mutex);
249 return retval;
250}
251
252static int sound_release(struct inode *inode, struct file *file)
253{
254 int dev = iminor(inode);
255
256 mutex_lock(&soundcard_mutex);
257 switch (dev & 0x0f) {
258 case SND_DEV_CTL:
259 module_put(mixer_devs[dev >> 4]->owner);
260 break;
261
262 case SND_DEV_SEQ:
263 case SND_DEV_SEQ2:
264 sequencer_release(dev, file);
265 break;
266
267 case SND_DEV_MIDIN:
268 MIDIbuf_release(dev, file);
269 break;
270
271 case SND_DEV_DSP:
272 case SND_DEV_DSP16:
273 case SND_DEV_AUDIO:
274 audio_release(dev, file);
275 break;
276
277 default:
278 printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev);
279 }
280 mutex_unlock(&soundcard_mutex);
281
282 return 0;
283}
284
285static int get_mixer_info(int dev, void __user *arg)
286{
287 mixer_info info;
288 memset(&info, 0, sizeof(info));
289 strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
290 strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
291 info.modify_counter = mixer_devs[dev]->modify_counter;
292 if (__copy_to_user(arg, &info, sizeof(info)))
293 return -EFAULT;
294 return 0;
295}
296
297static int get_old_mixer_info(int dev, void __user *arg)
298{
299 _old_mixer_info info;
300 memset(&info, 0, sizeof(info));
301 strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
302 strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
303 if (copy_to_user(arg, &info, sizeof(info)))
304 return -EFAULT;
305 return 0;
306}
307
308static int sound_mixer_ioctl(int mixdev, unsigned int cmd, void __user *arg)
309{
310 if (mixdev < 0 || mixdev >= MAX_MIXER_DEV)
311 return -ENXIO;
312 /* Try to load the mixer... */
313 if (mixer_devs[mixdev] == NULL) {
314 request_module("mixer%d", mixdev);
315 }
316 if (mixdev >= num_mixers || !mixer_devs[mixdev])
317 return -ENXIO;
318 if (cmd == SOUND_MIXER_INFO)
319 return get_mixer_info(mixdev, arg);
320 if (cmd == SOUND_OLD_MIXER_INFO)
321 return get_old_mixer_info(mixdev, arg);
322 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
323 mixer_devs[mixdev]->modify_counter++;
324 if (!mixer_devs[mixdev]->ioctl)
325 return -EINVAL;
326 return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg);
327}
328
329static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
330{
331 int len = 0, dtype;
332 int dev = iminor(file_inode(file));
333 long ret = -EINVAL;
334 void __user *p = (void __user *)arg;
335
336 if (_SIOC_DIR(cmd) != _SIOC_NONE && _SIOC_DIR(cmd) != 0) {
337 /*
338 * Have to validate the address given by the process.
339 */
340 len = _SIOC_SIZE(cmd);
341 if (len < 1 || len > 65536 || !p)
342 return -EFAULT;
343 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
344 if (!access_ok(VERIFY_READ, p, len))
345 return -EFAULT;
346 if (_SIOC_DIR(cmd) & _SIOC_READ)
347 if (!access_ok(VERIFY_WRITE, p, len))
348 return -EFAULT;
349 }
350 if (cmd == OSS_GETVERSION)
351 return __put_user(SOUND_VERSION, (int __user *)p);
352
353 mutex_lock(&soundcard_mutex);
354 if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */
355 (dev & 0x0f) != SND_DEV_CTL) {
356 dtype = dev & 0x0f;
357 switch (dtype) {
358 case SND_DEV_DSP:
359 case SND_DEV_DSP16:
360 case SND_DEV_AUDIO:
361 ret = sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
362 cmd, p);
363 break;
364 default:
365 ret = sound_mixer_ioctl(dev >> 4, cmd, p);
366 break;
367 }
368 mutex_unlock(&soundcard_mutex);
369 return ret;
370 }
371
372 switch (dev & 0x0f) {
373 case SND_DEV_CTL:
374 if (cmd == SOUND_MIXER_GETLEVELS)
375 ret = get_mixer_levels(p);
376 else if (cmd == SOUND_MIXER_SETLEVELS)
377 ret = set_mixer_levels(p);
378 else
379 ret = sound_mixer_ioctl(dev >> 4, cmd, p);
380 break;
381
382 case SND_DEV_SEQ:
383 case SND_DEV_SEQ2:
384 ret = sequencer_ioctl(dev, file, cmd, p);
385 break;
386
387 case SND_DEV_DSP:
388 case SND_DEV_DSP16:
389 case SND_DEV_AUDIO:
390 ret = audio_ioctl(dev, file, cmd, p);
391 break;
392
393 case SND_DEV_MIDIN:
394 ret = MIDIbuf_ioctl(dev, file, cmd, p);
395 break;
396
397 }
398 mutex_unlock(&soundcard_mutex);
399 return ret;
400}
401
402static unsigned int sound_poll(struct file *file, poll_table * wait)
403{
404 struct inode *inode = file_inode(file);
405 int dev = iminor(inode);
406
407 switch (dev & 0x0f) {
408 case SND_DEV_SEQ:
409 case SND_DEV_SEQ2:
410 return sequencer_poll(dev, file, wait);
411
412 case SND_DEV_MIDIN:
413 return MIDIbuf_poll(dev, file, wait);
414
415 case SND_DEV_DSP:
416 case SND_DEV_DSP16:
417 case SND_DEV_AUDIO:
418 return DMAbuf_poll(file, dev >> 4, wait);
419 }
420 return 0;
421}
422
423static int sound_mmap(struct file *file, struct vm_area_struct *vma)
424{
425 int dev_class;
426 unsigned long size;
427 struct dma_buffparms *dmap = NULL;
428 int dev = iminor(file_inode(file));
429
430 dev_class = dev & 0x0f;
431 dev >>= 4;
432
433 if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) {
434 printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n");
435 return -EINVAL;
436 }
437 mutex_lock(&soundcard_mutex);
438 if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */
439 dmap = audio_devs[dev]->dmap_out;
440 else if (vma->vm_flags & VM_READ)
441 dmap = audio_devs[dev]->dmap_in;
442 else {
443 printk(KERN_ERR "Sound: Undefined mmap() access\n");
444 mutex_unlock(&soundcard_mutex);
445 return -EINVAL;
446 }
447
448 if (dmap == NULL) {
449 printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n");
450 mutex_unlock(&soundcard_mutex);
451 return -EIO;
452 }
453 if (dmap->raw_buf == NULL) {
454 printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n");
455 mutex_unlock(&soundcard_mutex);
456 return -EIO;
457 }
458 if (dmap->mapping_flags) {
459 printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n");
460 mutex_unlock(&soundcard_mutex);
461 return -EIO;
462 }
463 if (vma->vm_pgoff != 0) {
464 printk(KERN_ERR "Sound: mmap() offset must be 0.\n");
465 mutex_unlock(&soundcard_mutex);
466 return -EINVAL;
467 }
468 size = vma->vm_end - vma->vm_start;
469
470 if (size != dmap->bytes_in_use) {
471 printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use);
472 }
473 if (remap_pfn_range(vma, vma->vm_start,
474 virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT,
475 vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
476 mutex_unlock(&soundcard_mutex);
477 return -EAGAIN;
478 }
479
480 dmap->mapping_flags |= DMA_MAP_MAPPED;
481
482 if( audio_devs[dev]->d->mmap)
483 audio_devs[dev]->d->mmap(dev);
484
485 memset(dmap->raw_buf,
486 dmap->neutral_byte,
487 dmap->bytes_in_use);
488 mutex_unlock(&soundcard_mutex);
489 return 0;
490}
491
492const struct file_operations oss_sound_fops = {
493 .owner = THIS_MODULE,
494 .llseek = no_llseek,
495 .read = sound_read,
496 .write = sound_write,
497 .poll = sound_poll,
498 .unlocked_ioctl = sound_ioctl,
499 .mmap = sound_mmap,
500 .open = sound_open,
501 .release = sound_release,
502};
503
504/*
505 * Create the required special subdevices
506 */
507
508static int create_special_devices(void)
509{
510 int seq1,seq2;
511 seq1=register_sound_special(&oss_sound_fops, 1);
512 if(seq1==-1)
513 goto bad;
514 seq2=register_sound_special(&oss_sound_fops, 8);
515 if(seq2!=-1)
516 return 0;
517 unregister_sound_special(1);
518bad:
519 return -1;
520}
521
522
523static int dmabuf;
524static int dmabug;
525
526module_param(dmabuf, int, 0444);
527module_param(dmabug, int, 0444);
528
529/* additional minors for compatibility */
530struct oss_minor_dev {
531 unsigned short minor;
532 unsigned int enabled;
533} dev_list[] = {
534 { SND_DEV_DSP16 },
535 { SND_DEV_AUDIO },
536};
537
538static int __init oss_init(void)
539{
540 int err;
541 int i, j;
542
543#ifdef CONFIG_PCI
544 if(dmabug)
545 isa_dma_bridge_buggy = dmabug;
546#endif
547
548 err = create_special_devices();
549 if (err) {
550 printk(KERN_ERR "sound: driver already loaded/included in kernel\n");
551 return err;
552 }
553
554 /* Protecting the innocent */
555 sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
556
557 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
558 j = 0;
559 do {
560 unsigned short minor = dev_list[i].minor + j * 0x10;
561 if (!register_sound_special(&oss_sound_fops, minor))
562 dev_list[i].enabled = (1 << j);
563 } while (++j < num_audiodevs);
564 }
565
566 if (sound_nblocks >= MAX_MEM_BLOCKS - 1)
567 printk(KERN_ERR "Sound warning: Deallocation table was too small.\n");
568
569 return 0;
570}
571
572static void __exit oss_cleanup(void)
573{
574 int i, j;
575
576 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
577 j = 0;
578 do {
579 if (dev_list[i].enabled & (1 << j))
580 unregister_sound_special(dev_list[i].minor);
581 } while (++j < num_audiodevs);
582 }
583
584 unregister_sound_special(1);
585 unregister_sound_special(8);
586
587 sound_stop_timer();
588
589 sequencer_unload();
590
591 for (i = 0; i < MAX_DMA_CHANNELS; i++)
592 if (dma_alloc_map[i] != DMA_MAP_UNAVAIL) {
593 printk(KERN_ERR "Sound: Hmm, DMA%d was left allocated - fixed\n", i);
594 sound_free_dma(i);
595 }
596
597 for (i = 0; i < sound_nblocks; i++)
598 vfree(sound_mem_blocks[i]);
599
600}
601
602module_init(oss_init);
603module_exit(oss_cleanup);
604MODULE_LICENSE("GPL");
605MODULE_DESCRIPTION("OSS Sound subsystem");
606MODULE_AUTHOR("Hannu Savolainen, et al.");
607
608
609int sound_alloc_dma(int chn, char *deviceID)
610{
611 int err;
612
613 if ((err = request_dma(chn, deviceID)) != 0)
614 return err;
615
616 dma_alloc_map[chn] = DMA_MAP_FREE;
617
618 return 0;
619}
620EXPORT_SYMBOL(sound_alloc_dma);
621
622int sound_open_dma(int chn, char *deviceID)
623{
624 if (!valid_dma(chn)) {
625 printk(KERN_ERR "sound_open_dma: Invalid DMA channel %d\n", chn);
626 return 1;
627 }
628
629 if (dma_alloc_map[chn] != DMA_MAP_FREE) {
630 printk("sound_open_dma: DMA channel %d busy or not allocated (%d)\n", chn, dma_alloc_map[chn]);
631 return 1;
632 }
633 dma_alloc_map[chn] = DMA_MAP_BUSY;
634 return 0;
635}
636EXPORT_SYMBOL(sound_open_dma);
637
638void sound_free_dma(int chn)
639{
640 if (dma_alloc_map[chn] == DMA_MAP_UNAVAIL) {
641 /* printk( "sound_free_dma: Bad access to DMA channel %d\n", chn); */
642 return;
643 }
644 free_dma(chn);
645 dma_alloc_map[chn] = DMA_MAP_UNAVAIL;
646}
647EXPORT_SYMBOL(sound_free_dma);
648
649void sound_close_dma(int chn)
650{
651 if (dma_alloc_map[chn] != DMA_MAP_BUSY) {
652 printk(KERN_ERR "sound_close_dma: Bad access to DMA channel %d\n", chn);
653 return;
654 }
655 dma_alloc_map[chn] = DMA_MAP_FREE;
656}
657EXPORT_SYMBOL(sound_close_dma);
658
659static void do_sequencer_timer(unsigned long dummy)
660{
661 sequencer_timer(0);
662}
663
664
665static DEFINE_TIMER(seq_timer, do_sequencer_timer, 0, 0);
666
667void request_sound_timer(int count)
668{
669 extern unsigned long seq_time;
670
671 if (count < 0) {
672 seq_timer.expires = (-count) + jiffies;
673 add_timer(&seq_timer);
674 return;
675 }
676 count += seq_time;
677
678 count -= jiffies;
679
680 if (count < 1)
681 count = 1;
682
683 seq_timer.expires = (count) + jiffies;
684 add_timer(&seq_timer);
685}
686
687void sound_stop_timer(void)
688{
689 del_timer(&seq_timer);
690}
691
692void conf_printf(char *name, struct address_info *hw_config)
693{
694#ifndef CONFIG_SOUND_TRACEINIT
695 return;
696#else
697 printk("<%s> at 0x%03x", name, hw_config->io_base);
698
699 if (hw_config->irq)
700 printk(" irq %d", (hw_config->irq > 0) ? hw_config->irq : -hw_config->irq);
701
702 if (hw_config->dma != -1 || hw_config->dma2 != -1)
703 {
704 printk(" dma %d", hw_config->dma);
705 if (hw_config->dma2 != -1)
706 printk(",%d", hw_config->dma2);
707 }
708 printk("\n");
709#endif
710}
711EXPORT_SYMBOL(conf_printf);
712
713void conf_printf2(char *name, int base, int irq, int dma, int dma2)
714{
715#ifndef CONFIG_SOUND_TRACEINIT
716 return;
717#else
718 printk("<%s> at 0x%03x", name, base);
719
720 if (irq)
721 printk(" irq %d", (irq > 0) ? irq : -irq);
722
723 if (dma != -1 || dma2 != -1)
724 {
725 printk(" dma %d", dma);
726 if (dma2 != -1)
727 printk(",%d", dma2);
728 }
729 printk("\n");
730#endif
731}
732EXPORT_SYMBOL(conf_printf2);
733
diff --git a/sound/oss/soundvers.h b/sound/oss/soundvers.h
deleted file mode 100644
index e9084d2f46a9..000000000000
--- a/sound/oss/soundvers.h
+++ /dev/null
@@ -1,2 +0,0 @@
1#define SOUND_VERSION_STRING "3.8s2++-971130"
2#define SOUND_INTERNAL_VERSION 0x030804
diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
deleted file mode 100644
index 97899352b15f..000000000000
--- a/sound/oss/swarm_cs4297a.c
+++ /dev/null
@@ -1,2781 +0,0 @@
1/*******************************************************************************
2*
3* "swarm_cs4297a.c" -- Cirrus Logic-Crystal CS4297a linux audio driver.
4*
5* Copyright (C) 2001 Broadcom Corporation.
6* Copyright (C) 2000,2001 Cirrus Logic Corp.
7* -- adapted from drivers by Thomas Sailer,
8* -- but don't bug him; Problems should go to:
9* -- tom woller (twoller@crystal.cirrus.com) or
10* (audio@crystal.cirrus.com).
11* -- adapted from cs4281 PCI driver for cs4297a on
12* BCM1250 Synchronous Serial interface
13* (Kip Walker, Broadcom Corp.)
14* Copyright (C) 2004 Maciej W. Rozycki
15* Copyright (C) 2005 Ralf Baechle (ralf@linux-mips.org)
16*
17* This program is free software; you can redistribute it and/or modify
18* it under the terms of the GNU General Public License as published by
19* the Free Software Foundation; either version 2 of the License, or
20* (at your option) any later version.
21*
22* This program is distributed in the hope that it will be useful,
23* but WITHOUT ANY WARRANTY; without even the implied warranty of
24* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25* GNU General Public License for more details.
26*
27* You should have received a copy of the GNU General Public License
28* along with this program; if not, write to the Free Software
29* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30*
31* Module command line parameters:
32* none
33*
34* Supported devices:
35* /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
36* /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
37* /dev/midi simple MIDI UART interface, no ioctl
38*
39* Modification History
40* 08/20/00 trw - silence and no stopping DAC until release
41* 08/23/00 trw - added CS_DBG statements, fix interrupt hang issue on DAC stop.
42* 09/18/00 trw - added 16bit only record with conversion
43* 09/24/00 trw - added Enhanced Full duplex (separate simultaneous
44* capture/playback rates)
45* 10/03/00 trw - fixed mmap (fixed GRECORD and the XMMS mmap test plugin
46* libOSSm.so)
47* 10/11/00 trw - modified for 2.4.0-test9 kernel enhancements (NR_MAP removal)
48* 11/03/00 trw - fixed interrupt loss/stutter, added debug.
49* 11/10/00 bkz - added __devinit to cs4297a_hw_init()
50* 11/10/00 trw - fixed SMP and capture spinlock hang.
51* 12/04/00 trw - cleaned up CSDEBUG flags and added "defaultorder" moduleparm.
52* 12/05/00 trw - fixed polling (myth2), and added underrun swptr fix.
53* 12/08/00 trw - added PM support.
54* 12/14/00 trw - added wrapper code, builds under 2.4.0, 2.2.17-20, 2.2.17-8
55* (RH/Dell base), 2.2.18, 2.2.12. cleaned up code mods by ident.
56* 12/19/00 trw - added PM support for 2.2 base (apm_callback). other PM cleanup.
57* 12/21/00 trw - added fractional "defaultorder" inputs. if >100 then use
58* defaultorder-100 as power of 2 for the buffer size. example:
59* 106 = 2^(106-100) = 2^6 = 64 bytes for the buffer size.
60*
61*******************************************************************************/
62
63#include <linux/list.h>
64#include <linux/module.h>
65#include <linux/string.h>
66#include <linux/ioport.h>
67#include <linux/sched/signal.h>
68#include <linux/delay.h>
69#include <linux/sound.h>
70#include <linux/slab.h>
71#include <linux/soundcard.h>
72#include <linux/pci.h>
73#include <linux/bitops.h>
74#include <linux/interrupt.h>
75#include <linux/init.h>
76#include <linux/poll.h>
77#include <linux/mutex.h>
78#include <linux/kernel.h>
79
80#include <asm/byteorder.h>
81#include <asm/dma.h>
82#include <asm/io.h>
83#include <linux/uaccess.h>
84
85#include <asm/sibyte/sb1250_regs.h>
86#include <asm/sibyte/sb1250_int.h>
87#include <asm/sibyte/sb1250_dma.h>
88#include <asm/sibyte/sb1250_scd.h>
89#include <asm/sibyte/sb1250_syncser.h>
90#include <asm/sibyte/sb1250_mac.h>
91#include <asm/sibyte/sb1250.h>
92
93#include "sleep.h"
94
95struct cs4297a_state;
96
97static DEFINE_MUTEX(swarm_cs4297a_mutex);
98static void stop_dac(struct cs4297a_state *s);
99static void stop_adc(struct cs4297a_state *s);
100static void start_dac(struct cs4297a_state *s);
101static void start_adc(struct cs4297a_state *s);
102#undef OSS_DOCUMENTED_MIXER_SEMANTICS
103
104// ---------------------------------------------------------------------
105
106#define CS4297a_MAGIC 0xf00beef1
107
108// buffer order determines the size of the dma buffer for the driver.
109// under Linux, a smaller buffer allows more responsiveness from many of the
110// applications (e.g. games). A larger buffer allows some of the apps (esound)
111// to not underrun the dma buffer as easily. As default, use 32k (order=3)
112// rather than 64k as some of the games work more responsively.
113// log base 2( buff sz = 32k).
114
115//
116// Turn on/off debugging compilation by commenting out "#define CSDEBUG"
117//
118#define CSDEBUG 0
119#if CSDEBUG
120#define CSDEBUG_INTERFACE 1
121#else
122#undef CSDEBUG_INTERFACE
123#endif
124//
125// cs_debugmask areas
126//
127#define CS_INIT 0x00000001 // initialization and probe functions
128#define CS_ERROR 0x00000002 // tmp debugging bit placeholder
129#define CS_INTERRUPT 0x00000004 // interrupt handler (separate from all other)
130#define CS_FUNCTION 0x00000008 // enter/leave functions
131#define CS_WAVE_WRITE 0x00000010 // write information for wave
132#define CS_WAVE_READ 0x00000020 // read information for wave
133#define CS_AC97 0x00000040 // AC97 register access
134#define CS_DESCR 0x00000080 // descriptor management
135#define CS_OPEN 0x00000400 // all open functions in the driver
136#define CS_RELEASE 0x00000800 // all release functions in the driver
137#define CS_PARMS 0x00001000 // functional and operational parameters
138#define CS_IOCTL 0x00002000 // ioctl (non-mixer)
139#define CS_TMP 0x10000000 // tmp debug mask bit
140
141//
142// CSDEBUG is usual mode is set to 1, then use the
143// cs_debuglevel and cs_debugmask to turn on or off debugging.
144// Debug level of 1 has been defined to be kernel errors and info
145// that should be printed on any released driver.
146//
147#if CSDEBUG
148#define CS_DBGOUT(mask,level,x) if((cs_debuglevel >= (level)) && ((mask) & cs_debugmask) ) {x;}
149#else
150#define CS_DBGOUT(mask,level,x)
151#endif
152
153#if CSDEBUG
154static unsigned long cs_debuglevel = 4; // levels range from 1-9
155static unsigned long cs_debugmask = CS_INIT /*| CS_IOCTL*/;
156module_param(cs_debuglevel, int, 0);
157module_param(cs_debugmask, int, 0);
158#endif
159#define CS_TRUE 1
160#define CS_FALSE 0
161
162#define CS_TYPE_ADC 0
163#define CS_TYPE_DAC 1
164
165#define SER_BASE (A_SER_BASE_1 + KSEG1)
166#define SS_CSR(t) (SER_BASE+t)
167#define SS_TXTBL(t) (SER_BASE+R_SER_TX_TABLE_BASE+(t*8))
168#define SS_RXTBL(t) (SER_BASE+R_SER_RX_TABLE_BASE+(t*8))
169
170#define FRAME_BYTES 32
171#define FRAME_SAMPLE_BYTES 4
172
173/* Should this be variable? */
174#define SAMPLE_BUF_SIZE (16*1024)
175#define SAMPLE_FRAME_COUNT (SAMPLE_BUF_SIZE / FRAME_SAMPLE_BYTES)
176/* The driver can explode/shrink the frames to/from a smaller sample
177 buffer */
178#define DMA_BLOAT_FACTOR 1
179#define DMA_DESCR (SAMPLE_FRAME_COUNT / DMA_BLOAT_FACTOR)
180#define DMA_BUF_SIZE (DMA_DESCR * FRAME_BYTES)
181
182/* Use the maxmium count (255 == 5.1 ms between interrupts) */
183#define DMA_INT_CNT ((1 << S_DMA_INT_PKTCNT) - 1)
184
185/* Figure this out: how many TX DMAs ahead to schedule a reg access */
186#define REG_LATENCY 150
187
188#define FRAME_TX_US 20
189
190#define SERDMA_NEXTBUF(d,f) (((d)->f+1) % (d)->ringsz)
191
192static const char invalid_magic[] =
193 KERN_CRIT "cs4297a: invalid magic value\n";
194
195#define VALIDATE_STATE(s) \
196({ \
197 if (!(s) || (s)->magic != CS4297a_MAGIC) { \
198 printk(invalid_magic); \
199 return -ENXIO; \
200 } \
201})
202
203/* AC97 registers */
204#define AC97_MASTER_VOL_STEREO 0x0002 /* Line Out */
205#define AC97_PCBEEP_VOL 0x000a /* none */
206#define AC97_PHONE_VOL 0x000c /* TAD Input (mono) */
207#define AC97_MIC_VOL 0x000e /* MIC Input (mono) */
208#define AC97_LINEIN_VOL 0x0010 /* Line Input (stereo) */
209#define AC97_CD_VOL 0x0012 /* CD Input (stereo) */
210#define AC97_AUX_VOL 0x0016 /* Aux Input (stereo) */
211#define AC97_PCMOUT_VOL 0x0018 /* Wave Output (stereo) */
212#define AC97_RECORD_SELECT 0x001a /* */
213#define AC97_RECORD_GAIN 0x001c
214#define AC97_GENERAL_PURPOSE 0x0020
215#define AC97_3D_CONTROL 0x0022
216#define AC97_POWER_CONTROL 0x0026
217#define AC97_VENDOR_ID1 0x007c
218
219struct list_head cs4297a_devs = { &cs4297a_devs, &cs4297a_devs };
220
221typedef struct serdma_descr_s {
222 u64 descr_a;
223 u64 descr_b;
224} serdma_descr_t;
225
226typedef unsigned long paddr_t;
227
228typedef struct serdma_s {
229 unsigned ringsz;
230 serdma_descr_t *descrtab;
231 serdma_descr_t *descrtab_end;
232 paddr_t descrtab_phys;
233
234 serdma_descr_t *descr_add;
235 serdma_descr_t *descr_rem;
236
237 u64 *dma_buf; // buffer for DMA contents (frames)
238 paddr_t dma_buf_phys;
239 u16 *sample_buf; // tmp buffer for sample conversions
240 u16 *sb_swptr;
241 u16 *sb_hwptr;
242 u16 *sb_end;
243
244 dma_addr_t dmaaddr;
245// unsigned buforder; // Log base 2 of 'dma_buf' size in bytes..
246 unsigned numfrag; // # of 'fragments' in the buffer.
247 unsigned fragshift; // Log base 2 of fragment size.
248 unsigned hwptr, swptr;
249 unsigned total_bytes; // # bytes process since open.
250 unsigned blocks; // last returned blocks value GETOPTR
251 unsigned wakeup; // interrupt occurred on block
252 int count;
253 unsigned underrun; // underrun flag
254 unsigned error; // over/underrun
255 wait_queue_head_t wait;
256 wait_queue_head_t reg_wait;
257 // redundant, but makes calculations easier
258 unsigned fragsize; // 2**fragshift..
259 unsigned sbufsz; // 2**buforder.
260 unsigned fragsamples;
261 // OSS stuff
262 unsigned mapped:1; // Buffer mapped in cs4297a_mmap()?
263 unsigned ready:1; // prog_dmabuf_dac()/adc() successful?
264 unsigned endcleared:1;
265 unsigned type:1; // adc or dac buffer (CS_TYPE_XXX)
266 unsigned ossfragshift;
267 int ossmaxfrags;
268 unsigned subdivision;
269} serdma_t;
270
271struct cs4297a_state {
272 // magic
273 unsigned int magic;
274
275 struct list_head list;
276
277 // soundcore stuff
278 int dev_audio;
279 int dev_mixer;
280
281 // hardware resources
282 unsigned int irq;
283
284 struct {
285 unsigned int rx_ovrrn; /* FIFO */
286 unsigned int rx_overflow; /* staging buffer */
287 unsigned int tx_underrun;
288 unsigned int rx_bad;
289 unsigned int rx_good;
290 } stats;
291
292 // mixer registers
293 struct {
294 unsigned short vol[10];
295 unsigned int recsrc;
296 unsigned int modcnt;
297 unsigned short micpreamp;
298 } mix;
299
300 // wave stuff
301 struct properties {
302 unsigned fmt;
303 unsigned fmt_original; // original requested format
304 unsigned channels;
305 unsigned rate;
306 } prop_dac, prop_adc;
307 unsigned conversion:1; // conversion from 16 to 8 bit in progress
308 unsigned ena;
309 spinlock_t lock;
310 struct mutex open_mutex;
311 struct mutex open_sem_adc;
312 struct mutex open_sem_dac;
313 fmode_t open_mode;
314 wait_queue_head_t open_wait;
315 wait_queue_head_t open_wait_adc;
316 wait_queue_head_t open_wait_dac;
317
318 dma_addr_t dmaaddr_sample_buf;
319 unsigned buforder_sample_buf; // Log base 2 of 'dma_buf' size in bytes..
320
321 serdma_t dma_dac, dma_adc;
322
323 volatile u16 read_value;
324 volatile u16 read_reg;
325 volatile u64 reg_request;
326};
327
328#if 1
329#define prog_codec(a,b)
330#define dealloc_dmabuf(a,b);
331#endif
332
333static int prog_dmabuf_adc(struct cs4297a_state *s)
334{
335 s->dma_adc.ready = 1;
336 return 0;
337}
338
339
340static int prog_dmabuf_dac(struct cs4297a_state *s)
341{
342 s->dma_dac.ready = 1;
343 return 0;
344}
345
346static void clear_advance(void *buf, unsigned bsize, unsigned bptr,
347 unsigned len, unsigned char c)
348{
349 if (bptr + len > bsize) {
350 unsigned x = bsize - bptr;
351 memset(((char *) buf) + bptr, c, x);
352 bptr = 0;
353 len -= x;
354 }
355 CS_DBGOUT(CS_WAVE_WRITE, 4, printk(KERN_INFO
356 "cs4297a: clear_advance(): memset %d at 0x%.8x for %d size \n",
357 (unsigned)c, (unsigned)((char *) buf) + bptr, len));
358 memset(((char *) buf) + bptr, c, len);
359}
360
361#if CSDEBUG
362
363// DEBUG ROUTINES
364
365#define SOUND_MIXER_CS_GETDBGLEVEL _SIOWR('M',120, int)
366#define SOUND_MIXER_CS_SETDBGLEVEL _SIOWR('M',121, int)
367#define SOUND_MIXER_CS_GETDBGMASK _SIOWR('M',122, int)
368#define SOUND_MIXER_CS_SETDBGMASK _SIOWR('M',123, int)
369
370static void cs_printioctl(unsigned int x)
371{
372 unsigned int i;
373 unsigned char vidx;
374 // Index of mixtable1[] member is Device ID
375 // and must be <= SOUND_MIXER_NRDEVICES.
376 // Value of array member is index into s->mix.vol[]
377 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
378 [SOUND_MIXER_PCM] = 1, // voice
379 [SOUND_MIXER_LINE1] = 2, // AUX
380 [SOUND_MIXER_CD] = 3, // CD
381 [SOUND_MIXER_LINE] = 4, // Line
382 [SOUND_MIXER_SYNTH] = 5, // FM
383 [SOUND_MIXER_MIC] = 6, // Mic
384 [SOUND_MIXER_SPEAKER] = 7, // Speaker
385 [SOUND_MIXER_RECLEV] = 8, // Recording level
386 [SOUND_MIXER_VOLUME] = 9 // Master Volume
387 };
388
389 switch (x) {
390 case SOUND_MIXER_CS_GETDBGMASK:
391 CS_DBGOUT(CS_IOCTL, 4,
392 printk("SOUND_MIXER_CS_GETDBGMASK:\n"));
393 break;
394 case SOUND_MIXER_CS_GETDBGLEVEL:
395 CS_DBGOUT(CS_IOCTL, 4,
396 printk("SOUND_MIXER_CS_GETDBGLEVEL:\n"));
397 break;
398 case SOUND_MIXER_CS_SETDBGMASK:
399 CS_DBGOUT(CS_IOCTL, 4,
400 printk("SOUND_MIXER_CS_SETDBGMASK:\n"));
401 break;
402 case SOUND_MIXER_CS_SETDBGLEVEL:
403 CS_DBGOUT(CS_IOCTL, 4,
404 printk("SOUND_MIXER_CS_SETDBGLEVEL:\n"));
405 break;
406 case OSS_GETVERSION:
407 CS_DBGOUT(CS_IOCTL, 4, printk("OSS_GETVERSION:\n"));
408 break;
409 case SNDCTL_DSP_SYNC:
410 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SYNC:\n"));
411 break;
412 case SNDCTL_DSP_SETDUPLEX:
413 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETDUPLEX:\n"));
414 break;
415 case SNDCTL_DSP_GETCAPS:
416 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETCAPS:\n"));
417 break;
418 case SNDCTL_DSP_RESET:
419 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_RESET:\n"));
420 break;
421 case SNDCTL_DSP_SPEED:
422 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SPEED:\n"));
423 break;
424 case SNDCTL_DSP_STEREO:
425 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_STEREO:\n"));
426 break;
427 case SNDCTL_DSP_CHANNELS:
428 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_CHANNELS:\n"));
429 break;
430 case SNDCTL_DSP_GETFMTS:
431 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETFMTS:\n"));
432 break;
433 case SNDCTL_DSP_SETFMT:
434 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETFMT:\n"));
435 break;
436 case SNDCTL_DSP_POST:
437 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_POST:\n"));
438 break;
439 case SNDCTL_DSP_GETTRIGGER:
440 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETTRIGGER:\n"));
441 break;
442 case SNDCTL_DSP_SETTRIGGER:
443 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETTRIGGER:\n"));
444 break;
445 case SNDCTL_DSP_GETOSPACE:
446 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOSPACE:\n"));
447 break;
448 case SNDCTL_DSP_GETISPACE:
449 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETISPACE:\n"));
450 break;
451 case SNDCTL_DSP_NONBLOCK:
452 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_NONBLOCK:\n"));
453 break;
454 case SNDCTL_DSP_GETODELAY:
455 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETODELAY:\n"));
456 break;
457 case SNDCTL_DSP_GETIPTR:
458 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETIPTR:\n"));
459 break;
460 case SNDCTL_DSP_GETOPTR:
461 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOPTR:\n"));
462 break;
463 case SNDCTL_DSP_GETBLKSIZE:
464 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETBLKSIZE:\n"));
465 break;
466 case SNDCTL_DSP_SETFRAGMENT:
467 CS_DBGOUT(CS_IOCTL, 4,
468 printk("SNDCTL_DSP_SETFRAGMENT:\n"));
469 break;
470 case SNDCTL_DSP_SUBDIVIDE:
471 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SUBDIVIDE:\n"));
472 break;
473 case SOUND_PCM_READ_RATE:
474 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_RATE:\n"));
475 break;
476 case SOUND_PCM_READ_CHANNELS:
477 CS_DBGOUT(CS_IOCTL, 4,
478 printk("SOUND_PCM_READ_CHANNELS:\n"));
479 break;
480 case SOUND_PCM_READ_BITS:
481 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_BITS:\n"));
482 break;
483 case SOUND_PCM_WRITE_FILTER:
484 CS_DBGOUT(CS_IOCTL, 4,
485 printk("SOUND_PCM_WRITE_FILTER:\n"));
486 break;
487 case SNDCTL_DSP_SETSYNCRO:
488 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETSYNCRO:\n"));
489 break;
490 case SOUND_PCM_READ_FILTER:
491 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_FILTER:\n"));
492 break;
493 case SOUND_MIXER_PRIVATE1:
494 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE1:\n"));
495 break;
496 case SOUND_MIXER_PRIVATE2:
497 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE2:\n"));
498 break;
499 case SOUND_MIXER_PRIVATE3:
500 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE3:\n"));
501 break;
502 case SOUND_MIXER_PRIVATE4:
503 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE4:\n"));
504 break;
505 case SOUND_MIXER_PRIVATE5:
506 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE5:\n"));
507 break;
508 case SOUND_MIXER_INFO:
509 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_INFO:\n"));
510 break;
511 case SOUND_OLD_MIXER_INFO:
512 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_OLD_MIXER_INFO:\n"));
513 break;
514
515 default:
516 switch (_IOC_NR(x)) {
517 case SOUND_MIXER_VOLUME:
518 CS_DBGOUT(CS_IOCTL, 4,
519 printk("SOUND_MIXER_VOLUME:\n"));
520 break;
521 case SOUND_MIXER_SPEAKER:
522 CS_DBGOUT(CS_IOCTL, 4,
523 printk("SOUND_MIXER_SPEAKER:\n"));
524 break;
525 case SOUND_MIXER_RECLEV:
526 CS_DBGOUT(CS_IOCTL, 4,
527 printk("SOUND_MIXER_RECLEV:\n"));
528 break;
529 case SOUND_MIXER_MIC:
530 CS_DBGOUT(CS_IOCTL, 4,
531 printk("SOUND_MIXER_MIC:\n"));
532 break;
533 case SOUND_MIXER_SYNTH:
534 CS_DBGOUT(CS_IOCTL, 4,
535 printk("SOUND_MIXER_SYNTH:\n"));
536 break;
537 case SOUND_MIXER_RECSRC:
538 CS_DBGOUT(CS_IOCTL, 4,
539 printk("SOUND_MIXER_RECSRC:\n"));
540 break;
541 case SOUND_MIXER_DEVMASK:
542 CS_DBGOUT(CS_IOCTL, 4,
543 printk("SOUND_MIXER_DEVMASK:\n"));
544 break;
545 case SOUND_MIXER_RECMASK:
546 CS_DBGOUT(CS_IOCTL, 4,
547 printk("SOUND_MIXER_RECMASK:\n"));
548 break;
549 case SOUND_MIXER_STEREODEVS:
550 CS_DBGOUT(CS_IOCTL, 4,
551 printk("SOUND_MIXER_STEREODEVS:\n"));
552 break;
553 case SOUND_MIXER_CAPS:
554 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CAPS:\n"));
555 break;
556 default:
557 i = _IOC_NR(x);
558 if (i >= SOUND_MIXER_NRDEVICES
559 || !(vidx = mixtable1[i])) {
560 CS_DBGOUT(CS_IOCTL, 4, printk
561 ("UNKNOWN IOCTL: 0x%.8x NR=%d\n",
562 x, i));
563 } else {
564 CS_DBGOUT(CS_IOCTL, 4, printk
565 ("SOUND_MIXER_IOCTL AC9x: 0x%.8x NR=%d\n",
566 x, i));
567 }
568 break;
569 }
570 }
571}
572#endif
573
574
575static int ser_init(struct cs4297a_state *s)
576{
577 int i;
578
579 CS_DBGOUT(CS_INIT, 2,
580 printk(KERN_INFO "cs4297a: Setting up serial parameters\n"));
581
582 __raw_writeq(M_SYNCSER_CMD_RX_RESET | M_SYNCSER_CMD_TX_RESET, SS_CSR(R_SER_CMD));
583
584 __raw_writeq(M_SYNCSER_MSB_FIRST, SS_CSR(R_SER_MODE));
585 __raw_writeq(32, SS_CSR(R_SER_MINFRM_SZ));
586 __raw_writeq(32, SS_CSR(R_SER_MAXFRM_SZ));
587
588 __raw_writeq(1, SS_CSR(R_SER_TX_RD_THRSH));
589 __raw_writeq(4, SS_CSR(R_SER_TX_WR_THRSH));
590 __raw_writeq(8, SS_CSR(R_SER_RX_RD_THRSH));
591
592 /* This looks good from experimentation */
593 __raw_writeq((M_SYNCSER_TXSYNC_INT | V_SYNCSER_TXSYNC_DLY(0) | M_SYNCSER_TXCLK_EXT |
594 M_SYNCSER_RXSYNC_INT | V_SYNCSER_RXSYNC_DLY(1) | M_SYNCSER_RXCLK_EXT | M_SYNCSER_RXSYNC_EDGE),
595 SS_CSR(R_SER_LINE_MODE));
596
597 /* This looks good from experimentation */
598 __raw_writeq(V_SYNCSER_SEQ_COUNT(14) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE,
599 SS_TXTBL(0));
600 __raw_writeq(V_SYNCSER_SEQ_COUNT(15) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
601 SS_TXTBL(1));
602 __raw_writeq(V_SYNCSER_SEQ_COUNT(13) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
603 SS_TXTBL(2));
604 __raw_writeq(V_SYNCSER_SEQ_COUNT( 0) | M_SYNCSER_SEQ_ENABLE |
605 M_SYNCSER_SEQ_STROBE | M_SYNCSER_SEQ_LAST, SS_TXTBL(3));
606
607 __raw_writeq(V_SYNCSER_SEQ_COUNT(14) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE,
608 SS_RXTBL(0));
609 __raw_writeq(V_SYNCSER_SEQ_COUNT(15) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
610 SS_RXTBL(1));
611 __raw_writeq(V_SYNCSER_SEQ_COUNT(13) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
612 SS_RXTBL(2));
613 __raw_writeq(V_SYNCSER_SEQ_COUNT( 0) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE |
614 M_SYNCSER_SEQ_LAST, SS_RXTBL(3));
615
616 for (i=4; i<16; i++) {
617 /* Just in case... */
618 __raw_writeq(M_SYNCSER_SEQ_LAST, SS_TXTBL(i));
619 __raw_writeq(M_SYNCSER_SEQ_LAST, SS_RXTBL(i));
620 }
621
622 return 0;
623}
624
625static int init_serdma(serdma_t *dma)
626{
627 CS_DBGOUT(CS_INIT, 2,
628 printk(KERN_ERR "cs4297a: desc - %d sbufsize - %d dbufsize - %d\n",
629 DMA_DESCR, SAMPLE_BUF_SIZE, DMA_BUF_SIZE));
630
631 /* Descriptors */
632 dma->ringsz = DMA_DESCR;
633 dma->descrtab = kzalloc(dma->ringsz * sizeof(serdma_descr_t), GFP_KERNEL);
634 if (!dma->descrtab) {
635 printk(KERN_ERR "cs4297a: kzalloc descrtab failed\n");
636 return -1;
637 }
638 dma->descrtab_end = dma->descrtab + dma->ringsz;
639 /* XXX bloddy mess, use proper DMA API here ... */
640 dma->descrtab_phys = CPHYSADDR((long)dma->descrtab);
641 dma->descr_add = dma->descr_rem = dma->descrtab;
642
643 /* Frame buffer area */
644 dma->dma_buf = kzalloc(DMA_BUF_SIZE, GFP_KERNEL);
645 if (!dma->dma_buf) {
646 printk(KERN_ERR "cs4297a: kzalloc dma_buf failed\n");
647 kfree(dma->descrtab);
648 return -1;
649 }
650 dma->dma_buf_phys = CPHYSADDR((long)dma->dma_buf);
651
652 /* Samples buffer area */
653 dma->sbufsz = SAMPLE_BUF_SIZE;
654 dma->sample_buf = kmalloc(dma->sbufsz, GFP_KERNEL);
655 if (!dma->sample_buf) {
656 printk(KERN_ERR "cs4297a: kmalloc sample_buf failed\n");
657 kfree(dma->descrtab);
658 kfree(dma->dma_buf);
659 return -1;
660 }
661 dma->sb_swptr = dma->sb_hwptr = dma->sample_buf;
662 dma->sb_end = (u16 *)((void *)dma->sample_buf + dma->sbufsz);
663 dma->fragsize = dma->sbufsz >> 1;
664
665 CS_DBGOUT(CS_INIT, 4,
666 printk(KERN_ERR "cs4297a: descrtab - %08x dma_buf - %x sample_buf - %x\n",
667 (int)dma->descrtab, (int)dma->dma_buf,
668 (int)dma->sample_buf));
669
670 return 0;
671}
672
673static int dma_init(struct cs4297a_state *s)
674{
675 int i;
676
677 CS_DBGOUT(CS_INIT, 2,
678 printk(KERN_INFO "cs4297a: Setting up DMA\n"));
679
680 if (init_serdma(&s->dma_adc) ||
681 init_serdma(&s->dma_dac))
682 return -1;
683
684 if (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_RX))||
685 __raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX))) {
686 panic("DMA state corrupted?!");
687 }
688
689 /* Initialize now - the descr/buffer pairings will never
690 change... */
691 for (i=0; i<DMA_DESCR; i++) {
692 s->dma_dac.descrtab[i].descr_a = M_DMA_SERRX_SOP | V_DMA_DSCRA_A_SIZE(1) |
693 (s->dma_dac.dma_buf_phys + i*FRAME_BYTES);
694 s->dma_dac.descrtab[i].descr_b = V_DMA_DSCRB_PKT_SIZE(FRAME_BYTES);
695 s->dma_adc.descrtab[i].descr_a = V_DMA_DSCRA_A_SIZE(1) |
696 (s->dma_adc.dma_buf_phys + i*FRAME_BYTES);
697 s->dma_adc.descrtab[i].descr_b = 0;
698 }
699
700 __raw_writeq((M_DMA_EOP_INT_EN | V_DMA_INT_PKTCNT(DMA_INT_CNT) |
701 V_DMA_RINGSZ(DMA_DESCR) | M_DMA_TDX_EN),
702 SS_CSR(R_SER_DMA_CONFIG0_RX));
703 __raw_writeq(M_DMA_L2CA, SS_CSR(R_SER_DMA_CONFIG1_RX));
704 __raw_writeq(s->dma_adc.descrtab_phys, SS_CSR(R_SER_DMA_DSCR_BASE_RX));
705
706 __raw_writeq(V_DMA_RINGSZ(DMA_DESCR), SS_CSR(R_SER_DMA_CONFIG0_TX));
707 __raw_writeq(M_DMA_L2CA | M_DMA_NO_DSCR_UPDT, SS_CSR(R_SER_DMA_CONFIG1_TX));
708 __raw_writeq(s->dma_dac.descrtab_phys, SS_CSR(R_SER_DMA_DSCR_BASE_TX));
709
710 /* Prep the receive DMA descriptor ring */
711 __raw_writeq(DMA_DESCR, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
712
713 __raw_writeq(M_SYNCSER_DMA_RX_EN | M_SYNCSER_DMA_TX_EN, SS_CSR(R_SER_DMA_ENABLE));
714
715 __raw_writeq((M_SYNCSER_RX_SYNC_ERR | M_SYNCSER_RX_OVERRUN | M_SYNCSER_RX_EOP_COUNT),
716 SS_CSR(R_SER_INT_MASK));
717
718 /* Enable the rx/tx; let the codec warm up to the sync and
719 start sending good frames before the receive FIFO is
720 enabled */
721 __raw_writeq(M_SYNCSER_CMD_TX_EN, SS_CSR(R_SER_CMD));
722 udelay(1000);
723 __raw_writeq(M_SYNCSER_CMD_RX_EN | M_SYNCSER_CMD_TX_EN, SS_CSR(R_SER_CMD));
724
725 /* XXXKW is this magic? (the "1" part) */
726 while ((__raw_readq(SS_CSR(R_SER_STATUS)) & 0xf1) != 1)
727 ;
728
729 CS_DBGOUT(CS_INIT, 4,
730 printk(KERN_INFO "cs4297a: status: %08x\n",
731 (unsigned int)(__raw_readq(SS_CSR(R_SER_STATUS)) & 0xffffffff)));
732
733 return 0;
734}
735
736static int serdma_reg_access(struct cs4297a_state *s, u64 data)
737{
738 serdma_t *d = &s->dma_dac;
739 u64 *data_p;
740 unsigned swptr;
741 unsigned long flags;
742 serdma_descr_t *descr;
743
744 if (s->reg_request) {
745 printk(KERN_ERR "cs4297a: attempt to issue multiple reg_access\n");
746 return -1;
747 }
748
749 if (s->ena & FMODE_WRITE) {
750 /* Since a writer has the DSP open, we have to mux the
751 request in */
752 s->reg_request = data;
753 oss_broken_sleep_on(&s->dma_dac.reg_wait, MAX_SCHEDULE_TIMEOUT);
754 /* XXXKW how can I deal with the starvation case where
755 the opener isn't writing? */
756 } else {
757 /* Be safe when changing ring pointers */
758 spin_lock_irqsave(&s->lock, flags);
759 if (d->hwptr != d->swptr) {
760 printk(KERN_ERR "cs4297a: reg access found bookkeeping error (hw/sw = %d/%d\n",
761 d->hwptr, d->swptr);
762 spin_unlock_irqrestore(&s->lock, flags);
763 return -1;
764 }
765 swptr = d->swptr;
766 d->hwptr = d->swptr = (d->swptr + 1) % d->ringsz;
767 spin_unlock_irqrestore(&s->lock, flags);
768
769 descr = &d->descrtab[swptr];
770 data_p = &d->dma_buf[swptr * 4];
771 *data_p = cpu_to_be64(data);
772 __raw_writeq(1, SS_CSR(R_SER_DMA_DSCR_COUNT_TX));
773 CS_DBGOUT(CS_DESCR, 4,
774 printk(KERN_INFO "cs4297a: add_tx %p (%x -> %x)\n",
775 data_p, swptr, d->hwptr));
776 }
777
778 CS_DBGOUT(CS_FUNCTION, 6,
779 printk(KERN_INFO "cs4297a: serdma_reg_access()-\n"));
780
781 return 0;
782}
783
784//****************************************************************************
785// "cs4297a_read_ac97" -- Reads an AC97 register
786//****************************************************************************
787static int cs4297a_read_ac97(struct cs4297a_state *s, u32 offset,
788 u32 * value)
789{
790 CS_DBGOUT(CS_AC97, 1,
791 printk(KERN_INFO "cs4297a: read reg %2x\n", offset));
792 if (serdma_reg_access(s, (0xCLL << 60) | (1LL << 47) | ((u64)(offset & 0x7F) << 40)))
793 return -1;
794
795 oss_broken_sleep_on(&s->dma_adc.reg_wait, MAX_SCHEDULE_TIMEOUT);
796 *value = s->read_value;
797 CS_DBGOUT(CS_AC97, 2,
798 printk(KERN_INFO "cs4297a: rdr reg %x -> %x\n", s->read_reg, s->read_value));
799
800 return 0;
801}
802
803
804//****************************************************************************
805// "cs4297a_write_ac97()"-- writes an AC97 register
806//****************************************************************************
807static int cs4297a_write_ac97(struct cs4297a_state *s, u32 offset,
808 u32 value)
809{
810 CS_DBGOUT(CS_AC97, 1,
811 printk(KERN_INFO "cs4297a: write reg %2x -> %04x\n", offset, value));
812 return (serdma_reg_access(s, (0xELL << 60) | ((u64)(offset & 0x7F) << 40) | ((value & 0xffff) << 12)));
813}
814
815static void stop_dac(struct cs4297a_state *s)
816{
817 unsigned long flags;
818
819 CS_DBGOUT(CS_WAVE_WRITE, 3, printk(KERN_INFO "cs4297a: stop_dac():\n"));
820 spin_lock_irqsave(&s->lock, flags);
821 s->ena &= ~FMODE_WRITE;
822#if 0
823 /* XXXKW what do I really want here? My theory for now is
824 that I just flip the "ena" bit, and the interrupt handler
825 will stop processing the xmit channel */
826 __raw_writeq((s->ena & FMODE_READ) ? M_SYNCSER_DMA_RX_EN : 0,
827 SS_CSR(R_SER_DMA_ENABLE));
828#endif
829
830 spin_unlock_irqrestore(&s->lock, flags);
831}
832
833
834static void start_dac(struct cs4297a_state *s)
835{
836 unsigned long flags;
837
838 CS_DBGOUT(CS_FUNCTION, 3, printk(KERN_INFO "cs4297a: start_dac()+\n"));
839 spin_lock_irqsave(&s->lock, flags);
840 if (!(s->ena & FMODE_WRITE) && (s->dma_dac.mapped ||
841 (s->dma_dac.count > 0
842 && s->dma_dac.ready))) {
843 s->ena |= FMODE_WRITE;
844 /* XXXKW what do I really want here? My theory for
845 now is that I just flip the "ena" bit, and the
846 interrupt handler will start processing the xmit
847 channel */
848
849 CS_DBGOUT(CS_WAVE_WRITE | CS_PARMS, 8, printk(KERN_INFO
850 "cs4297a: start_dac(): start dma\n"));
851
852 }
853 spin_unlock_irqrestore(&s->lock, flags);
854 CS_DBGOUT(CS_FUNCTION, 3,
855 printk(KERN_INFO "cs4297a: start_dac()-\n"));
856}
857
858
859static void stop_adc(struct cs4297a_state *s)
860{
861 unsigned long flags;
862
863 CS_DBGOUT(CS_FUNCTION, 3,
864 printk(KERN_INFO "cs4297a: stop_adc()+\n"));
865
866 spin_lock_irqsave(&s->lock, flags);
867 s->ena &= ~FMODE_READ;
868
869 if (s->conversion == 1) {
870 s->conversion = 0;
871 s->prop_adc.fmt = s->prop_adc.fmt_original;
872 }
873 /* Nothing to do really, I need to keep the DMA going
874 XXXKW when do I get here, and is there more I should do? */
875 spin_unlock_irqrestore(&s->lock, flags);
876 CS_DBGOUT(CS_FUNCTION, 3,
877 printk(KERN_INFO "cs4297a: stop_adc()-\n"));
878}
879
880
881static void start_adc(struct cs4297a_state *s)
882{
883 unsigned long flags;
884
885 CS_DBGOUT(CS_FUNCTION, 2,
886 printk(KERN_INFO "cs4297a: start_adc()+\n"));
887
888 if (!(s->ena & FMODE_READ) &&
889 (s->dma_adc.mapped || s->dma_adc.count <=
890 (signed) (s->dma_adc.sbufsz - 2 * s->dma_adc.fragsize))
891 && s->dma_adc.ready) {
892 if (s->prop_adc.fmt & AFMT_S8 || s->prop_adc.fmt & AFMT_U8) {
893 //
894 // now only use 16 bit capture, due to truncation issue
895 // in the chip, noticeable distortion occurs.
896 // allocate buffer and then convert from 16 bit to
897 // 8 bit for the user buffer.
898 //
899 s->prop_adc.fmt_original = s->prop_adc.fmt;
900 if (s->prop_adc.fmt & AFMT_S8) {
901 s->prop_adc.fmt &= ~AFMT_S8;
902 s->prop_adc.fmt |= AFMT_S16_LE;
903 }
904 if (s->prop_adc.fmt & AFMT_U8) {
905 s->prop_adc.fmt &= ~AFMT_U8;
906 s->prop_adc.fmt |= AFMT_U16_LE;
907 }
908 //
909 // prog_dmabuf_adc performs a stop_adc() but that is
910 // ok since we really haven't started the DMA yet.
911 //
912 prog_codec(s, CS_TYPE_ADC);
913
914 prog_dmabuf_adc(s);
915 s->conversion = 1;
916 }
917 spin_lock_irqsave(&s->lock, flags);
918 s->ena |= FMODE_READ;
919 /* Nothing to do really, I am probably already
920 DMAing... XXXKW when do I get here, and is there
921 more I should do? */
922 spin_unlock_irqrestore(&s->lock, flags);
923
924 CS_DBGOUT(CS_PARMS, 6, printk(KERN_INFO
925 "cs4297a: start_adc(): start adc\n"));
926 }
927 CS_DBGOUT(CS_FUNCTION, 2,
928 printk(KERN_INFO "cs4297a: start_adc()-\n"));
929
930}
931
932
933// call with spinlock held!
934static void cs4297a_update_ptr(struct cs4297a_state *s, int intflag)
935{
936 int good_diff, diff, diff2;
937 u64 *data_p, data;
938 u32 *s_ptr;
939 unsigned hwptr;
940 u32 status;
941 serdma_t *d;
942 serdma_descr_t *descr;
943
944 // update ADC pointer
945 status = intflag ? __raw_readq(SS_CSR(R_SER_STATUS)) : 0;
946
947 if ((s->ena & FMODE_READ) || (status & (M_SYNCSER_RX_EOP_COUNT))) {
948 d = &s->dma_adc;
949 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
950 d->descrtab_phys) / sizeof(serdma_descr_t));
951
952 if (s->ena & FMODE_READ) {
953 CS_DBGOUT(CS_FUNCTION, 2,
954 printk(KERN_INFO "cs4297a: upd_rcv sw->hw->hw %x/%x/%x (int-%d)n",
955 d->swptr, d->hwptr, hwptr, intflag));
956 /* Number of DMA buffers available for software: */
957 diff2 = diff = (d->ringsz + hwptr - d->hwptr) % d->ringsz;
958 d->hwptr = hwptr;
959 good_diff = 0;
960 s_ptr = (u32 *)&(d->dma_buf[d->swptr*4]);
961 descr = &d->descrtab[d->swptr];
962 while (diff2--) {
963 u64 data = be64_to_cpu(*(u64 *)s_ptr);
964 u64 descr_a;
965 u16 left, right;
966 descr_a = descr->descr_a;
967 descr->descr_a &= ~M_DMA_SERRX_SOP;
968 if ((descr_a & M_DMA_DSCRA_A_ADDR) != CPHYSADDR((long)s_ptr)) {
969 printk(KERN_ERR "cs4297a: RX Bad address (read)\n");
970 }
971 if (((data & 0x9800000000000000) != 0x9800000000000000) ||
972 (!(descr_a & M_DMA_SERRX_SOP)) ||
973 (G_DMA_DSCRB_PKT_SIZE(descr->descr_b) != FRAME_BYTES)) {
974 s->stats.rx_bad++;
975 printk(KERN_DEBUG "cs4297a: RX Bad attributes (read)\n");
976 continue;
977 }
978 s->stats.rx_good++;
979 if ((data >> 61) == 7) {
980 s->read_value = (data >> 12) & 0xffff;
981 s->read_reg = (data >> 40) & 0x7f;
982 wake_up(&d->reg_wait);
983 }
984 if (d->count && (d->sb_hwptr == d->sb_swptr)) {
985 s->stats.rx_overflow++;
986 printk(KERN_DEBUG "cs4297a: RX overflow\n");
987 continue;
988 }
989 good_diff++;
990 left = ((be32_to_cpu(s_ptr[1]) & 0xff) << 8) |
991 ((be32_to_cpu(s_ptr[2]) >> 24) & 0xff);
992 right = (be32_to_cpu(s_ptr[2]) >> 4) & 0xffff;
993 *d->sb_hwptr++ = cpu_to_be16(left);
994 *d->sb_hwptr++ = cpu_to_be16(right);
995 if (d->sb_hwptr == d->sb_end)
996 d->sb_hwptr = d->sample_buf;
997 descr++;
998 if (descr == d->descrtab_end) {
999 descr = d->descrtab;
1000 s_ptr = (u32 *)s->dma_adc.dma_buf;
1001 } else {
1002 s_ptr += 8;
1003 }
1004 }
1005 d->total_bytes += good_diff * FRAME_SAMPLE_BYTES;
1006 d->count += good_diff * FRAME_SAMPLE_BYTES;
1007 if (d->count > d->sbufsz) {
1008 printk(KERN_ERR "cs4297a: bogus receive overflow!!\n");
1009 }
1010 d->swptr = (d->swptr + diff) % d->ringsz;
1011 __raw_writeq(diff, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
1012 if (d->mapped) {
1013 if (d->count >= (signed) d->fragsize)
1014 wake_up(&d->wait);
1015 } else {
1016 if (d->count > 0) {
1017 CS_DBGOUT(CS_WAVE_READ, 4,
1018 printk(KERN_INFO
1019 "cs4297a: update count -> %d\n", d->count));
1020 wake_up(&d->wait);
1021 }
1022 }
1023 } else {
1024 /* Receive is going even if no one is
1025 listening (for register accesses and to
1026 avoid FIFO overrun) */
1027 diff2 = diff = (hwptr + d->ringsz - d->hwptr) % d->ringsz;
1028 if (!diff) {
1029 printk(KERN_ERR "cs4297a: RX full or empty?\n");
1030 }
1031
1032 descr = &d->descrtab[d->swptr];
1033 data_p = &d->dma_buf[d->swptr*4];
1034
1035 /* Force this to happen at least once; I got
1036 here because of an interrupt, so there must
1037 be a buffer to process. */
1038 do {
1039 data = be64_to_cpu(*data_p);
1040 if ((descr->descr_a & M_DMA_DSCRA_A_ADDR) != CPHYSADDR((long)data_p)) {
1041 printk(KERN_ERR "cs4297a: RX Bad address %d (%llx %lx)\n", d->swptr,
1042 (long long)(descr->descr_a & M_DMA_DSCRA_A_ADDR),
1043 (long)CPHYSADDR((long)data_p));
1044 }
1045 if (!(data & (1LL << 63)) ||
1046 !(descr->descr_a & M_DMA_SERRX_SOP) ||
1047 (G_DMA_DSCRB_PKT_SIZE(descr->descr_b) != FRAME_BYTES)) {
1048 s->stats.rx_bad++;
1049 printk(KERN_DEBUG "cs4297a: RX Bad attributes\n");
1050 } else {
1051 s->stats.rx_good++;
1052 if ((data >> 61) == 7) {
1053 s->read_value = (data >> 12) & 0xffff;
1054 s->read_reg = (data >> 40) & 0x7f;
1055 wake_up(&d->reg_wait);
1056 }
1057 }
1058 descr->descr_a &= ~M_DMA_SERRX_SOP;
1059 descr++;
1060 d->swptr++;
1061 data_p += 4;
1062 if (descr == d->descrtab_end) {
1063 descr = d->descrtab;
1064 d->swptr = 0;
1065 data_p = d->dma_buf;
1066 }
1067 __raw_writeq(1, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
1068 } while (--diff);
1069 d->hwptr = hwptr;
1070
1071 CS_DBGOUT(CS_DESCR, 6,
1072 printk(KERN_INFO "cs4297a: hw/sw %x/%x\n", d->hwptr, d->swptr));
1073 }
1074
1075 CS_DBGOUT(CS_PARMS, 8, printk(KERN_INFO
1076 "cs4297a: cs4297a_update_ptr(): s=0x%.8x hwptr=%d total_bytes=%d count=%d \n",
1077 (unsigned)s, d->hwptr,
1078 d->total_bytes, d->count));
1079 }
1080
1081 /* XXXKW worry about s->reg_request -- there is a starvation
1082 case if s->ena has FMODE_WRITE on, but the client isn't
1083 doing writes */
1084
1085 // update DAC pointer
1086 //
1087 // check for end of buffer, means that we are going to wait for another interrupt
1088 // to allow silence to fill the fifos on the part, to keep pops down to a minimum.
1089 //
1090 if (s->ena & FMODE_WRITE) {
1091 serdma_t *d = &s->dma_dac;
1092 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1093 d->descrtab_phys) / sizeof(serdma_descr_t));
1094 diff = (d->ringsz + hwptr - d->hwptr) % d->ringsz;
1095 CS_DBGOUT(CS_WAVE_WRITE, 4, printk(KERN_INFO
1096 "cs4297a: cs4297a_update_ptr(): hw/hw/sw %x/%x/%x diff %d count %d\n",
1097 d->hwptr, hwptr, d->swptr, diff, d->count));
1098 d->hwptr = hwptr;
1099 /* XXXKW stereo? conversion? Just assume 2 16-bit samples for now */
1100 d->total_bytes += diff * FRAME_SAMPLE_BYTES;
1101 if (d->mapped) {
1102 d->count += diff * FRAME_SAMPLE_BYTES;
1103 if (d->count >= d->fragsize) {
1104 d->wakeup = 1;
1105 wake_up(&d->wait);
1106 if (d->count > d->sbufsz)
1107 d->count &= d->sbufsz - 1;
1108 }
1109 } else {
1110 d->count -= diff * FRAME_SAMPLE_BYTES;
1111 if (d->count <= 0) {
1112 //
1113 // fill with silence, and do not shut down the DAC.
1114 // Continue to play silence until the _release.
1115 //
1116 CS_DBGOUT(CS_WAVE_WRITE, 6, printk(KERN_INFO
1117 "cs4297a: cs4297a_update_ptr(): memset %d at 0x%.8x for %d size \n",
1118 (unsigned)(s->prop_dac.fmt &
1119 (AFMT_U8 | AFMT_U16_LE)) ? 0x80 : 0,
1120 (unsigned)d->dma_buf,
1121 d->ringsz));
1122 memset(d->dma_buf, 0, d->ringsz * FRAME_BYTES);
1123 if (d->count < 0) {
1124 d->underrun = 1;
1125 s->stats.tx_underrun++;
1126 d->count = 0;
1127 CS_DBGOUT(CS_ERROR, 9, printk(KERN_INFO
1128 "cs4297a: cs4297a_update_ptr(): underrun\n"));
1129 }
1130 } else if (d->count <=
1131 (signed) d->fragsize
1132 && !d->endcleared) {
1133 /* XXXKW what is this for? */
1134 clear_advance(d->dma_buf,
1135 d->sbufsz,
1136 d->swptr,
1137 d->fragsize,
1138 0);
1139 d->endcleared = 1;
1140 }
1141 if ( (d->count <= (signed) d->sbufsz/2) || intflag)
1142 {
1143 CS_DBGOUT(CS_WAVE_WRITE, 4,
1144 printk(KERN_INFO
1145 "cs4297a: update count -> %d\n", d->count));
1146 wake_up(&d->wait);
1147 }
1148 }
1149 CS_DBGOUT(CS_PARMS, 8, printk(KERN_INFO
1150 "cs4297a: cs4297a_update_ptr(): s=0x%.8x hwptr=%d total_bytes=%d count=%d \n",
1151 (unsigned) s, d->hwptr,
1152 d->total_bytes, d->count));
1153 }
1154}
1155
1156static int mixer_ioctl(struct cs4297a_state *s, unsigned int cmd,
1157 unsigned long arg)
1158{
1159 // Index to mixer_src[] is value of AC97 Input Mux Select Reg.
1160 // Value of array member is recording source Device ID Mask.
1161 static const unsigned int mixer_src[8] = {
1162 SOUND_MASK_MIC, SOUND_MASK_CD, 0, SOUND_MASK_LINE1,
1163 SOUND_MASK_LINE, SOUND_MASK_VOLUME, 0, 0
1164 };
1165
1166 // Index of mixtable1[] member is Device ID
1167 // and must be <= SOUND_MIXER_NRDEVICES.
1168 // Value of array member is index into s->mix.vol[]
1169 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
1170 [SOUND_MIXER_PCM] = 1, // voice
1171 [SOUND_MIXER_LINE1] = 2, // AUX
1172 [SOUND_MIXER_CD] = 3, // CD
1173 [SOUND_MIXER_LINE] = 4, // Line
1174 [SOUND_MIXER_SYNTH] = 5, // FM
1175 [SOUND_MIXER_MIC] = 6, // Mic
1176 [SOUND_MIXER_SPEAKER] = 7, // Speaker
1177 [SOUND_MIXER_RECLEV] = 8, // Recording level
1178 [SOUND_MIXER_VOLUME] = 9 // Master Volume
1179 };
1180
1181 static const unsigned mixreg[] = {
1182 AC97_PCMOUT_VOL,
1183 AC97_AUX_VOL,
1184 AC97_CD_VOL,
1185 AC97_LINEIN_VOL
1186 };
1187 unsigned char l, r, rl, rr, vidx;
1188 unsigned char attentbl[11] =
1189 { 63, 42, 26, 17, 14, 11, 8, 6, 4, 2, 0 };
1190 unsigned temp1;
1191 int i, val;
1192
1193 VALIDATE_STATE(s);
1194 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
1195 "cs4297a: mixer_ioctl(): s=0x%.8x cmd=0x%.8x\n",
1196 (unsigned) s, cmd));
1197#if CSDEBUG
1198 cs_printioctl(cmd);
1199#endif
1200#if CSDEBUG_INTERFACE
1201
1202 if ((cmd == SOUND_MIXER_CS_GETDBGMASK) ||
1203 (cmd == SOUND_MIXER_CS_SETDBGMASK) ||
1204 (cmd == SOUND_MIXER_CS_GETDBGLEVEL) ||
1205 (cmd == SOUND_MIXER_CS_SETDBGLEVEL))
1206 {
1207 switch (cmd) {
1208
1209 case SOUND_MIXER_CS_GETDBGMASK:
1210 return put_user(cs_debugmask,
1211 (unsigned long *) arg);
1212
1213 case SOUND_MIXER_CS_GETDBGLEVEL:
1214 return put_user(cs_debuglevel,
1215 (unsigned long *) arg);
1216
1217 case SOUND_MIXER_CS_SETDBGMASK:
1218 if (get_user(val, (unsigned long *) arg))
1219 return -EFAULT;
1220 cs_debugmask = val;
1221 return 0;
1222
1223 case SOUND_MIXER_CS_SETDBGLEVEL:
1224 if (get_user(val, (unsigned long *) arg))
1225 return -EFAULT;
1226 cs_debuglevel = val;
1227 return 0;
1228 default:
1229 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
1230 "cs4297a: mixer_ioctl(): ERROR unknown debug cmd\n"));
1231 return 0;
1232 }
1233 }
1234#endif
1235
1236 if (cmd == SOUND_MIXER_PRIVATE1) {
1237 return -EINVAL;
1238 }
1239 if (cmd == SOUND_MIXER_PRIVATE2) {
1240 // enable/disable/query spatializer
1241 if (get_user(val, (int *) arg))
1242 return -EFAULT;
1243 if (val != -1) {
1244 temp1 = (val & 0x3f) >> 2;
1245 cs4297a_write_ac97(s, AC97_3D_CONTROL, temp1);
1246 cs4297a_read_ac97(s, AC97_GENERAL_PURPOSE,
1247 &temp1);
1248 cs4297a_write_ac97(s, AC97_GENERAL_PURPOSE,
1249 temp1 | 0x2000);
1250 }
1251 cs4297a_read_ac97(s, AC97_3D_CONTROL, &temp1);
1252 return put_user((temp1 << 2) | 3, (int *) arg);
1253 }
1254 if (cmd == SOUND_MIXER_INFO) {
1255 mixer_info info;
1256 memset(&info, 0, sizeof(info));
1257 strlcpy(info.id, "CS4297a", sizeof(info.id));
1258 strlcpy(info.name, "Crystal CS4297a", sizeof(info.name));
1259 info.modify_counter = s->mix.modcnt;
1260 if (copy_to_user((void *) arg, &info, sizeof(info)))
1261 return -EFAULT;
1262 return 0;
1263 }
1264 if (cmd == SOUND_OLD_MIXER_INFO) {
1265 _old_mixer_info info;
1266 memset(&info, 0, sizeof(info));
1267 strlcpy(info.id, "CS4297a", sizeof(info.id));
1268 strlcpy(info.name, "Crystal CS4297a", sizeof(info.name));
1269 if (copy_to_user((void *) arg, &info, sizeof(info)))
1270 return -EFAULT;
1271 return 0;
1272 }
1273 if (cmd == OSS_GETVERSION)
1274 return put_user(SOUND_VERSION, (int *) arg);
1275
1276 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
1277 return -EINVAL;
1278
1279 // If ioctl has only the SIOC_READ bit(bit 31)
1280 // on, process the only-read commands.
1281 if (_SIOC_DIR(cmd) == _SIOC_READ) {
1282 switch (_IOC_NR(cmd)) {
1283 case SOUND_MIXER_RECSRC: // Arg contains a bit for each recording source
1284 cs4297a_read_ac97(s, AC97_RECORD_SELECT,
1285 &temp1);
1286 return put_user(mixer_src[temp1 & 7], (int *) arg);
1287
1288 case SOUND_MIXER_DEVMASK: // Arg contains a bit for each supported device
1289 return put_user(SOUND_MASK_PCM | SOUND_MASK_LINE |
1290 SOUND_MASK_VOLUME | SOUND_MASK_RECLEV,
1291 (int *) arg);
1292
1293 case SOUND_MIXER_RECMASK: // Arg contains a bit for each supported recording source
1294 return put_user(SOUND_MASK_LINE | SOUND_MASK_VOLUME,
1295 (int *) arg);
1296
1297 case SOUND_MIXER_STEREODEVS: // Mixer channels supporting stereo
1298 return put_user(SOUND_MASK_PCM | SOUND_MASK_LINE |
1299 SOUND_MASK_VOLUME | SOUND_MASK_RECLEV,
1300 (int *) arg);
1301
1302 case SOUND_MIXER_CAPS:
1303 return put_user(SOUND_CAP_EXCL_INPUT, (int *) arg);
1304
1305 default:
1306 i = _IOC_NR(cmd);
1307 if (i >= SOUND_MIXER_NRDEVICES
1308 || !(vidx = mixtable1[i]))
1309 return -EINVAL;
1310 return put_user(s->mix.vol[vidx - 1], (int *) arg);
1311 }
1312 }
1313 // If ioctl doesn't have both the SIOC_READ and
1314 // the SIOC_WRITE bit set, return invalid.
1315 if (_SIOC_DIR(cmd) != (_SIOC_READ | _SIOC_WRITE))
1316 return -EINVAL;
1317
1318 // Increment the count of volume writes.
1319 s->mix.modcnt++;
1320
1321 // Isolate the command; it must be a write.
1322 switch (_IOC_NR(cmd)) {
1323
1324 case SOUND_MIXER_RECSRC: // Arg contains a bit for each recording source
1325 if (get_user(val, (int *) arg))
1326 return -EFAULT;
1327 i = hweight32(val); // i = # bits on in val.
1328 if (i != 1) // One & only 1 bit must be on.
1329 return 0;
1330 for (i = 0; i < sizeof(mixer_src) / sizeof(int); i++) {
1331 if (val == mixer_src[i]) {
1332 temp1 = (i << 8) | i;
1333 cs4297a_write_ac97(s,
1334 AC97_RECORD_SELECT,
1335 temp1);
1336 return 0;
1337 }
1338 }
1339 return 0;
1340
1341 case SOUND_MIXER_VOLUME:
1342 if (get_user(val, (int *) arg))
1343 return -EFAULT;
1344 l = val & 0xff;
1345 if (l > 100)
1346 l = 100; // Max soundcard.h vol is 100.
1347 if (l < 6) {
1348 rl = 63;
1349 l = 0;
1350 } else
1351 rl = attentbl[(10 * l) / 100]; // Convert 0-100 vol to 63-0 atten.
1352
1353 r = (val >> 8) & 0xff;
1354 if (r > 100)
1355 r = 100; // Max right volume is 100, too
1356 if (r < 6) {
1357 rr = 63;
1358 r = 0;
1359 } else
1360 rr = attentbl[(10 * r) / 100]; // Convert volume to attenuation.
1361
1362 if ((rl > 60) && (rr > 60)) // If both l & r are 'low',
1363 temp1 = 0x8000; // turn on the mute bit.
1364 else
1365 temp1 = 0;
1366
1367 temp1 |= (rl << 8) | rr;
1368
1369 cs4297a_write_ac97(s, AC97_MASTER_VOL_STEREO, temp1);
1370 cs4297a_write_ac97(s, AC97_PHONE_VOL, temp1);
1371
1372#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1373 s->mix.vol[8] = ((unsigned int) r << 8) | l;
1374#else
1375 s->mix.vol[8] = val;
1376#endif
1377 return put_user(s->mix.vol[8], (int *) arg);
1378
1379 case SOUND_MIXER_SPEAKER:
1380 if (get_user(val, (int *) arg))
1381 return -EFAULT;
1382 l = val & 0xff;
1383 if (l > 100)
1384 l = 100;
1385 if (l < 3) {
1386 rl = 0;
1387 l = 0;
1388 } else {
1389 rl = (l * 2 - 5) / 13; // Convert 0-100 range to 0-15.
1390 l = (rl * 13 + 5) / 2;
1391 }
1392
1393 if (rl < 3) {
1394 temp1 = 0x8000;
1395 rl = 0;
1396 } else
1397 temp1 = 0;
1398 rl = 15 - rl; // Convert volume to attenuation.
1399 temp1 |= rl << 1;
1400 cs4297a_write_ac97(s, AC97_PCBEEP_VOL, temp1);
1401
1402#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1403 s->mix.vol[6] = l << 8;
1404#else
1405 s->mix.vol[6] = val;
1406#endif
1407 return put_user(s->mix.vol[6], (int *) arg);
1408
1409 case SOUND_MIXER_RECLEV:
1410 if (get_user(val, (int *) arg))
1411 return -EFAULT;
1412 l = val & 0xff;
1413 if (l > 100)
1414 l = 100;
1415 r = (val >> 8) & 0xff;
1416 if (r > 100)
1417 r = 100;
1418 rl = (l * 2 - 5) / 13; // Convert 0-100 scale to 0-15.
1419 rr = (r * 2 - 5) / 13;
1420 if (rl < 3 && rr < 3)
1421 temp1 = 0x8000;
1422 else
1423 temp1 = 0;
1424
1425 temp1 = temp1 | (rl << 8) | rr;
1426 cs4297a_write_ac97(s, AC97_RECORD_GAIN, temp1);
1427
1428#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1429 s->mix.vol[7] = ((unsigned int) r << 8) | l;
1430#else
1431 s->mix.vol[7] = val;
1432#endif
1433 return put_user(s->mix.vol[7], (int *) arg);
1434
1435 case SOUND_MIXER_MIC:
1436 if (get_user(val, (int *) arg))
1437 return -EFAULT;
1438 l = val & 0xff;
1439 if (l > 100)
1440 l = 100;
1441 if (l < 1) {
1442 l = 0;
1443 rl = 0;
1444 } else {
1445 rl = ((unsigned) l * 5 - 4) / 16; // Convert 0-100 range to 0-31.
1446 l = (rl * 16 + 4) / 5;
1447 }
1448 cs4297a_read_ac97(s, AC97_MIC_VOL, &temp1);
1449 temp1 &= 0x40; // Isolate 20db gain bit.
1450 if (rl < 3) {
1451 temp1 |= 0x8000;
1452 rl = 0;
1453 }
1454 rl = 31 - rl; // Convert volume to attenuation.
1455 temp1 |= rl;
1456 cs4297a_write_ac97(s, AC97_MIC_VOL, temp1);
1457
1458#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1459 s->mix.vol[5] = val << 8;
1460#else
1461 s->mix.vol[5] = val;
1462#endif
1463 return put_user(s->mix.vol[5], (int *) arg);
1464
1465
1466 case SOUND_MIXER_SYNTH:
1467 if (get_user(val, (int *) arg))
1468 return -EFAULT;
1469 l = val & 0xff;
1470 if (l > 100)
1471 l = 100;
1472 if (get_user(val, (int *) arg))
1473 return -EFAULT;
1474 r = (val >> 8) & 0xff;
1475 if (r > 100)
1476 r = 100;
1477 rl = (l * 2 - 11) / 3; // Convert 0-100 range to 0-63.
1478 rr = (r * 2 - 11) / 3;
1479 if (rl < 3) // If l is low, turn on
1480 temp1 = 0x0080; // the mute bit.
1481 else
1482 temp1 = 0;
1483
1484 rl = 63 - rl; // Convert vol to attenuation.
1485// writel(temp1 | rl, s->pBA0 + FMLVC);
1486 if (rr < 3) // If rr is low, turn on
1487 temp1 = 0x0080; // the mute bit.
1488 else
1489 temp1 = 0;
1490 rr = 63 - rr; // Convert vol to attenuation.
1491// writel(temp1 | rr, s->pBA0 + FMRVC);
1492
1493#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1494 s->mix.vol[4] = (r << 8) | l;
1495#else
1496 s->mix.vol[4] = val;
1497#endif
1498 return put_user(s->mix.vol[4], (int *) arg);
1499
1500
1501 default:
1502 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
1503 "cs4297a: mixer_ioctl(): default\n"));
1504
1505 i = _IOC_NR(cmd);
1506 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i]))
1507 return -EINVAL;
1508 if (get_user(val, (int *) arg))
1509 return -EFAULT;
1510 l = val & 0xff;
1511 if (l > 100)
1512 l = 100;
1513 if (l < 1) {
1514 l = 0;
1515 rl = 31;
1516 } else
1517 rl = (attentbl[(l * 10) / 100]) >> 1;
1518
1519 r = (val >> 8) & 0xff;
1520 if (r > 100)
1521 r = 100;
1522 if (r < 1) {
1523 r = 0;
1524 rr = 31;
1525 } else
1526 rr = (attentbl[(r * 10) / 100]) >> 1;
1527 if ((rl > 30) && (rr > 30))
1528 temp1 = 0x8000;
1529 else
1530 temp1 = 0;
1531 temp1 = temp1 | (rl << 8) | rr;
1532 cs4297a_write_ac97(s, mixreg[vidx - 1], temp1);
1533
1534#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1535 s->mix.vol[vidx - 1] = ((unsigned int) r << 8) | l;
1536#else
1537 s->mix.vol[vidx - 1] = val;
1538#endif
1539 return put_user(s->mix.vol[vidx - 1], (int *) arg);
1540 }
1541}
1542
1543
1544// ---------------------------------------------------------------------
1545
1546static int cs4297a_open_mixdev(struct inode *inode, struct file *file)
1547{
1548 int minor = iminor(inode);
1549 struct cs4297a_state *s=NULL;
1550 struct list_head *entry;
1551
1552 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
1553 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()+\n"));
1554
1555 mutex_lock(&swarm_cs4297a_mutex);
1556 list_for_each(entry, &cs4297a_devs)
1557 {
1558 s = list_entry(entry, struct cs4297a_state, list);
1559 if(s->dev_mixer == minor)
1560 break;
1561 }
1562 if (!s)
1563 {
1564 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
1565 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- -ENODEV\n"));
1566
1567 mutex_unlock(&swarm_cs4297a_mutex);
1568 return -ENODEV;
1569 }
1570 VALIDATE_STATE(s);
1571 file->private_data = s;
1572
1573 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
1574 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- 0\n"));
1575 mutex_unlock(&swarm_cs4297a_mutex);
1576
1577 return nonseekable_open(inode, file);
1578}
1579
1580
1581static int cs4297a_release_mixdev(struct inode *inode, struct file *file)
1582{
1583 struct cs4297a_state *s =
1584 (struct cs4297a_state *) file->private_data;
1585
1586 VALIDATE_STATE(s);
1587 return 0;
1588}
1589
1590
1591static int cs4297a_ioctl_mixdev(struct file *file,
1592 unsigned int cmd, unsigned long arg)
1593{
1594 int ret;
1595 mutex_lock(&swarm_cs4297a_mutex);
1596 ret = mixer_ioctl((struct cs4297a_state *) file->private_data, cmd,
1597 arg);
1598 mutex_unlock(&swarm_cs4297a_mutex);
1599 return ret;
1600}
1601
1602
1603// ******************************************************************************************
1604// Mixer file operations struct.
1605// ******************************************************************************************
1606static const struct file_operations cs4297a_mixer_fops = {
1607 .owner = THIS_MODULE,
1608 .llseek = no_llseek,
1609 .unlocked_ioctl = cs4297a_ioctl_mixdev,
1610 .open = cs4297a_open_mixdev,
1611 .release = cs4297a_release_mixdev,
1612};
1613
1614// ---------------------------------------------------------------------
1615
1616
1617static int drain_adc(struct cs4297a_state *s, int nonblock)
1618{
1619 /* This routine serves no purpose currently - any samples
1620 sitting in the receive queue will just be processed by the
1621 background consumer. This would be different if DMA
1622 actually stopped when there were no clients. */
1623 return 0;
1624}
1625
1626static int drain_dac(struct cs4297a_state *s, int nonblock)
1627{
1628 DECLARE_WAITQUEUE(wait, current);
1629 unsigned long flags;
1630 unsigned hwptr;
1631 unsigned tmo;
1632 int count;
1633
1634 if (s->dma_dac.mapped)
1635 return 0;
1636 if (nonblock)
1637 return -EBUSY;
1638 add_wait_queue(&s->dma_dac.wait, &wait);
1639 while ((count = __raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX))) ||
1640 (s->dma_dac.count > 0)) {
1641 if (!signal_pending(current)) {
1642 set_current_state(TASK_INTERRUPTIBLE);
1643 /* XXXKW is this calculation working? */
1644 tmo = ((count * FRAME_TX_US) * HZ) / 1000000;
1645 schedule_timeout(tmo + 1);
1646 } else {
1647 /* XXXKW do I care if there is a signal pending? */
1648 }
1649 }
1650 spin_lock_irqsave(&s->lock, flags);
1651 /* Reset the bookkeeping */
1652 hwptr = (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1653 s->dma_dac.descrtab_phys) / sizeof(serdma_descr_t));
1654 s->dma_dac.hwptr = s->dma_dac.swptr = hwptr;
1655 spin_unlock_irqrestore(&s->lock, flags);
1656 remove_wait_queue(&s->dma_dac.wait, &wait);
1657 __set_current_state(TASK_RUNNING);
1658 return 0;
1659}
1660
1661
1662// ---------------------------------------------------------------------
1663
1664static ssize_t cs4297a_read(struct file *file, char *buffer, size_t count,
1665 loff_t * ppos)
1666{
1667 struct cs4297a_state *s =
1668 (struct cs4297a_state *) file->private_data;
1669 ssize_t ret;
1670 unsigned long flags;
1671 int cnt, count_fr, cnt_by;
1672 unsigned copied = 0;
1673
1674 CS_DBGOUT(CS_FUNCTION | CS_WAVE_READ, 2,
1675 printk(KERN_INFO "cs4297a: cs4297a_read()+ %d \n", count));
1676
1677 VALIDATE_STATE(s);
1678 if (s->dma_adc.mapped)
1679 return -ENXIO;
1680 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1681 return ret;
1682 if (!access_ok(VERIFY_WRITE, buffer, count))
1683 return -EFAULT;
1684 ret = 0;
1685//
1686// "count" is the amount of bytes to read (from app), is decremented each loop
1687// by the amount of bytes that have been returned to the user buffer.
1688// "cnt" is the running total of each read from the buffer (changes each loop)
1689// "buffer" points to the app's buffer
1690// "ret" keeps a running total of the amount of bytes that have been copied
1691// to the user buffer.
1692// "copied" is the total bytes copied into the user buffer for each loop.
1693//
1694 while (count > 0) {
1695 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
1696 "_read() count>0 count=%d .count=%d .swptr=%d .hwptr=%d \n",
1697 count, s->dma_adc.count,
1698 s->dma_adc.swptr, s->dma_adc.hwptr));
1699 spin_lock_irqsave(&s->lock, flags);
1700
1701 /* cnt will be the number of available samples (16-bit
1702 stereo); it starts out as the maxmimum consequetive
1703 samples */
1704 cnt = (s->dma_adc.sb_end - s->dma_adc.sb_swptr) / 2;
1705 count_fr = s->dma_adc.count / FRAME_SAMPLE_BYTES;
1706
1707 // dma_adc.count is the current total bytes that have not been read.
1708 // if the amount of unread bytes from the current sw pointer to the
1709 // end of the buffer is greater than the current total bytes that
1710 // have not been read, then set the "cnt" (unread bytes) to the
1711 // amount of unread bytes.
1712
1713 if (count_fr < cnt)
1714 cnt = count_fr;
1715 cnt_by = cnt * FRAME_SAMPLE_BYTES;
1716 spin_unlock_irqrestore(&s->lock, flags);
1717 //
1718 // if we are converting from 8/16 then we need to copy
1719 // twice the number of 16 bit bytes then 8 bit bytes.
1720 //
1721 if (s->conversion) {
1722 if (cnt_by > (count * 2)) {
1723 cnt = (count * 2) / FRAME_SAMPLE_BYTES;
1724 cnt_by = count * 2;
1725 }
1726 } else {
1727 if (cnt_by > count) {
1728 cnt = count / FRAME_SAMPLE_BYTES;
1729 cnt_by = count;
1730 }
1731 }
1732 //
1733 // "cnt" NOW is the smaller of the amount that will be read,
1734 // and the amount that is requested in this read (or partial).
1735 // if there are no bytes in the buffer to read, then start the
1736 // ADC and wait for the interrupt handler to wake us up.
1737 //
1738 if (cnt <= 0) {
1739
1740 // start up the dma engine and then continue back to the top of
1741 // the loop when wake up occurs.
1742 start_adc(s);
1743 if (file->f_flags & O_NONBLOCK)
1744 return ret ? ret : -EAGAIN;
1745 oss_broken_sleep_on(&s->dma_adc.wait, MAX_SCHEDULE_TIMEOUT);
1746 if (signal_pending(current))
1747 return ret ? ret : -ERESTARTSYS;
1748 continue;
1749 }
1750 // there are bytes in the buffer to read.
1751 // copy from the hw buffer over to the user buffer.
1752 // user buffer is designated by "buffer"
1753 // virtual address to copy from is dma_buf+swptr
1754 // the "cnt" is the number of bytes to read.
1755
1756 CS_DBGOUT(CS_WAVE_READ, 2, printk(KERN_INFO
1757 "_read() copy_to cnt=%d count=%d ", cnt_by, count));
1758 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
1759 " .sbufsz=%d .count=%d buffer=0x%.8x ret=%d\n",
1760 s->dma_adc.sbufsz, s->dma_adc.count,
1761 (unsigned) buffer, ret));
1762
1763 if (copy_to_user (buffer, ((void *)s->dma_adc.sb_swptr), cnt_by))
1764 return ret ? ret : -EFAULT;
1765 copied = cnt_by;
1766
1767 /* Return the descriptors */
1768 spin_lock_irqsave(&s->lock, flags);
1769 CS_DBGOUT(CS_FUNCTION, 2,
1770 printk(KERN_INFO "cs4297a: upd_rcv sw->hw %x/%x\n", s->dma_adc.swptr, s->dma_adc.hwptr));
1771 s->dma_adc.count -= cnt_by;
1772 s->dma_adc.sb_swptr += cnt * 2;
1773 if (s->dma_adc.sb_swptr == s->dma_adc.sb_end)
1774 s->dma_adc.sb_swptr = s->dma_adc.sample_buf;
1775 spin_unlock_irqrestore(&s->lock, flags);
1776 count -= copied;
1777 buffer += copied;
1778 ret += copied;
1779 start_adc(s);
1780 }
1781 CS_DBGOUT(CS_FUNCTION | CS_WAVE_READ, 2,
1782 printk(KERN_INFO "cs4297a: cs4297a_read()- %d\n", ret));
1783 return ret;
1784}
1785
1786
1787static ssize_t cs4297a_write(struct file *file, const char *buffer,
1788 size_t count, loff_t * ppos)
1789{
1790 struct cs4297a_state *s =
1791 (struct cs4297a_state *) file->private_data;
1792 ssize_t ret;
1793 unsigned long flags;
1794 unsigned swptr, hwptr;
1795 int cnt;
1796
1797 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE, 2,
1798 printk(KERN_INFO "cs4297a: cs4297a_write()+ count=%d\n",
1799 count));
1800 VALIDATE_STATE(s);
1801
1802 if (s->dma_dac.mapped)
1803 return -ENXIO;
1804 if (!s->dma_dac.ready && (ret = prog_dmabuf_dac(s)))
1805 return ret;
1806 if (!access_ok(VERIFY_READ, buffer, count))
1807 return -EFAULT;
1808 ret = 0;
1809 while (count > 0) {
1810 serdma_t *d = &s->dma_dac;
1811 int copy_cnt;
1812 u32 *s_tmpl;
1813 u32 *t_tmpl;
1814 u32 left, right;
1815 int swap = (s->prop_dac.fmt == AFMT_S16_LE) || (s->prop_dac.fmt == AFMT_U16_LE);
1816
1817 /* XXXXXX this is broken for BLOAT_FACTOR */
1818 spin_lock_irqsave(&s->lock, flags);
1819 if (d->count < 0) {
1820 d->count = 0;
1821 d->swptr = d->hwptr;
1822 }
1823 if (d->underrun) {
1824 d->underrun = 0;
1825 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1826 d->descrtab_phys) / sizeof(serdma_descr_t));
1827 d->swptr = d->hwptr = hwptr;
1828 }
1829 swptr = d->swptr;
1830 cnt = d->sbufsz - (swptr * FRAME_SAMPLE_BYTES);
1831 /* Will this write fill up the buffer? */
1832 if (d->count + cnt > d->sbufsz)
1833 cnt = d->sbufsz - d->count;
1834 spin_unlock_irqrestore(&s->lock, flags);
1835 if (cnt > count)
1836 cnt = count;
1837 if (cnt <= 0) {
1838 start_dac(s);
1839 if (file->f_flags & O_NONBLOCK)
1840 return ret ? ret : -EAGAIN;
1841 oss_broken_sleep_on(&d->wait, MAX_SCHEDULE_TIMEOUT);
1842 if (signal_pending(current))
1843 return ret ? ret : -ERESTARTSYS;
1844 continue;
1845 }
1846 if (copy_from_user(d->sample_buf, buffer, cnt))
1847 return ret ? ret : -EFAULT;
1848
1849 copy_cnt = cnt;
1850 s_tmpl = (u32 *)d->sample_buf;
1851 t_tmpl = (u32 *)(d->dma_buf + (swptr * 4));
1852
1853 /* XXXKW assuming 16-bit stereo! */
1854 do {
1855 u32 tmp;
1856
1857 t_tmpl[0] = cpu_to_be32(0x98000000);
1858
1859 tmp = be32_to_cpu(s_tmpl[0]);
1860 left = tmp & 0xffff;
1861 right = tmp >> 16;
1862 if (swap) {
1863 left = swab16(left);
1864 right = swab16(right);
1865 }
1866 t_tmpl[1] = cpu_to_be32(left >> 8);
1867 t_tmpl[2] = cpu_to_be32(((left & 0xff) << 24) |
1868 (right << 4));
1869
1870 s_tmpl++;
1871 t_tmpl += 8;
1872 copy_cnt -= 4;
1873 } while (copy_cnt);
1874
1875 /* Mux in any pending read/write accesses */
1876 if (s->reg_request) {
1877 *(u64 *)(d->dma_buf + (swptr * 4)) |=
1878 cpu_to_be64(s->reg_request);
1879 s->reg_request = 0;
1880 wake_up(&s->dma_dac.reg_wait);
1881 }
1882
1883 CS_DBGOUT(CS_WAVE_WRITE, 4,
1884 printk(KERN_INFO
1885 "cs4297a: copy in %d to swptr %x\n", cnt, swptr));
1886
1887 swptr = (swptr + (cnt/FRAME_SAMPLE_BYTES)) % d->ringsz;
1888 __raw_writeq(cnt/FRAME_SAMPLE_BYTES, SS_CSR(R_SER_DMA_DSCR_COUNT_TX));
1889 spin_lock_irqsave(&s->lock, flags);
1890 d->swptr = swptr;
1891 d->count += cnt;
1892 d->endcleared = 0;
1893 spin_unlock_irqrestore(&s->lock, flags);
1894 count -= cnt;
1895 buffer += cnt;
1896 ret += cnt;
1897 start_dac(s);
1898 }
1899 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE, 2,
1900 printk(KERN_INFO "cs4297a: cs4297a_write()- %d\n", ret));
1901 return ret;
1902}
1903
1904
1905static unsigned int cs4297a_poll(struct file *file,
1906 struct poll_table_struct *wait)
1907{
1908 struct cs4297a_state *s =
1909 (struct cs4297a_state *) file->private_data;
1910 unsigned long flags;
1911 unsigned int mask = 0;
1912
1913 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1914 printk(KERN_INFO "cs4297a: cs4297a_poll()+\n"));
1915 VALIDATE_STATE(s);
1916 if (file->f_mode & FMODE_WRITE) {
1917 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1918 printk(KERN_INFO
1919 "cs4297a: cs4297a_poll() wait on FMODE_WRITE\n"));
1920 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
1921 return 0;
1922 poll_wait(file, &s->dma_dac.wait, wait);
1923 }
1924 if (file->f_mode & FMODE_READ) {
1925 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1926 printk(KERN_INFO
1927 "cs4297a: cs4297a_poll() wait on FMODE_READ\n"));
1928 if(!s->dma_dac.ready && prog_dmabuf_adc(s))
1929 return 0;
1930 poll_wait(file, &s->dma_adc.wait, wait);
1931 }
1932 spin_lock_irqsave(&s->lock, flags);
1933 cs4297a_update_ptr(s,CS_FALSE);
1934 if (file->f_mode & FMODE_WRITE) {
1935 if (s->dma_dac.mapped) {
1936 if (s->dma_dac.count >=
1937 (signed) s->dma_dac.fragsize) {
1938 if (s->dma_dac.wakeup)
1939 mask |= POLLOUT | POLLWRNORM;
1940 else
1941 mask = 0;
1942 s->dma_dac.wakeup = 0;
1943 }
1944 } else {
1945 if ((signed) (s->dma_dac.sbufsz/2) >= s->dma_dac.count)
1946 mask |= POLLOUT | POLLWRNORM;
1947 }
1948 } else if (file->f_mode & FMODE_READ) {
1949 if (s->dma_adc.mapped) {
1950 if (s->dma_adc.count >= (signed) s->dma_adc.fragsize)
1951 mask |= POLLIN | POLLRDNORM;
1952 } else {
1953 if (s->dma_adc.count > 0)
1954 mask |= POLLIN | POLLRDNORM;
1955 }
1956 }
1957 spin_unlock_irqrestore(&s->lock, flags);
1958 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1959 printk(KERN_INFO "cs4297a: cs4297a_poll()- 0x%.8x\n",
1960 mask));
1961 return mask;
1962}
1963
1964
1965static int cs4297a_mmap(struct file *file, struct vm_area_struct *vma)
1966{
1967 /* XXXKW currently no mmap support */
1968 return -EINVAL;
1969 return 0;
1970}
1971
1972
1973static int cs4297a_ioctl(struct file *file,
1974 unsigned int cmd, unsigned long arg)
1975{
1976 struct cs4297a_state *s =
1977 (struct cs4297a_state *) file->private_data;
1978 unsigned long flags;
1979 audio_buf_info abinfo;
1980 count_info cinfo;
1981 int val, mapped, ret;
1982
1983 CS_DBGOUT(CS_FUNCTION|CS_IOCTL, 4, printk(KERN_INFO
1984 "cs4297a: cs4297a_ioctl(): file=0x%.8x cmd=0x%.8x\n",
1985 (unsigned) file, cmd));
1986#if CSDEBUG
1987 cs_printioctl(cmd);
1988#endif
1989 VALIDATE_STATE(s);
1990 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1991 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1992 switch (cmd) {
1993 case OSS_GETVERSION:
1994 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
1995 "cs4297a: cs4297a_ioctl(): SOUND_VERSION=0x%.8x\n",
1996 SOUND_VERSION));
1997 return put_user(SOUND_VERSION, (int *) arg);
1998
1999 case SNDCTL_DSP_SYNC:
2000 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
2001 "cs4297a: cs4297a_ioctl(): DSP_SYNC\n"));
2002 if (file->f_mode & FMODE_WRITE)
2003 return drain_dac(s,
2004 0 /*file->f_flags & O_NONBLOCK */
2005 );
2006 return 0;
2007
2008 case SNDCTL_DSP_SETDUPLEX:
2009 return 0;
2010
2011 case SNDCTL_DSP_GETCAPS:
2012 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
2013 DSP_CAP_TRIGGER | DSP_CAP_MMAP,
2014 (int *) arg);
2015
2016 case SNDCTL_DSP_RESET:
2017 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
2018 "cs4297a: cs4297a_ioctl(): DSP_RESET\n"));
2019 if (file->f_mode & FMODE_WRITE) {
2020 stop_dac(s);
2021 synchronize_irq(s->irq);
2022 s->dma_dac.count = s->dma_dac.total_bytes =
2023 s->dma_dac.blocks = s->dma_dac.wakeup = 0;
2024 s->dma_dac.swptr = s->dma_dac.hwptr =
2025 (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
2026 s->dma_dac.descrtab_phys) / sizeof(serdma_descr_t));
2027 }
2028 if (file->f_mode & FMODE_READ) {
2029 stop_adc(s);
2030 synchronize_irq(s->irq);
2031 s->dma_adc.count = s->dma_adc.total_bytes =
2032 s->dma_adc.blocks = s->dma_dac.wakeup = 0;
2033 s->dma_adc.swptr = s->dma_adc.hwptr =
2034 (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
2035 s->dma_adc.descrtab_phys) / sizeof(serdma_descr_t));
2036 }
2037 return 0;
2038
2039 case SNDCTL_DSP_SPEED:
2040 if (get_user(val, (int *) arg))
2041 return -EFAULT;
2042 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2043 "cs4297a: cs4297a_ioctl(): DSP_SPEED val=%d -> 48000\n", val));
2044 val = 48000;
2045 return put_user(val, (int *) arg);
2046
2047 case SNDCTL_DSP_STEREO:
2048 if (get_user(val, (int *) arg))
2049 return -EFAULT;
2050 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2051 "cs4297a: cs4297a_ioctl(): DSP_STEREO val=%d\n", val));
2052 if (file->f_mode & FMODE_READ) {
2053 stop_adc(s);
2054 s->dma_adc.ready = 0;
2055 s->prop_adc.channels = val ? 2 : 1;
2056 }
2057 if (file->f_mode & FMODE_WRITE) {
2058 stop_dac(s);
2059 s->dma_dac.ready = 0;
2060 s->prop_dac.channels = val ? 2 : 1;
2061 }
2062 return 0;
2063
2064 case SNDCTL_DSP_CHANNELS:
2065 if (get_user(val, (int *) arg))
2066 return -EFAULT;
2067 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2068 "cs4297a: cs4297a_ioctl(): DSP_CHANNELS val=%d\n",
2069 val));
2070 if (val != 0) {
2071 if (file->f_mode & FMODE_READ) {
2072 stop_adc(s);
2073 s->dma_adc.ready = 0;
2074 if (val >= 2)
2075 s->prop_adc.channels = 2;
2076 else
2077 s->prop_adc.channels = 1;
2078 }
2079 if (file->f_mode & FMODE_WRITE) {
2080 stop_dac(s);
2081 s->dma_dac.ready = 0;
2082 if (val >= 2)
2083 s->prop_dac.channels = 2;
2084 else
2085 s->prop_dac.channels = 1;
2086 }
2087 }
2088
2089 if (file->f_mode & FMODE_WRITE)
2090 val = s->prop_dac.channels;
2091 else if (file->f_mode & FMODE_READ)
2092 val = s->prop_adc.channels;
2093
2094 return put_user(val, (int *) arg);
2095
2096 case SNDCTL_DSP_GETFMTS: // Returns a mask
2097 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2098 "cs4297a: cs4297a_ioctl(): DSP_GETFMT val=0x%.8x\n",
2099 AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
2100 AFMT_U8));
2101 return put_user(AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
2102 AFMT_U8, (int *) arg);
2103
2104 case SNDCTL_DSP_SETFMT:
2105 if (get_user(val, (int *) arg))
2106 return -EFAULT;
2107 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2108 "cs4297a: cs4297a_ioctl(): DSP_SETFMT val=0x%.8x\n",
2109 val));
2110 if (val != AFMT_QUERY) {
2111 if (file->f_mode & FMODE_READ) {
2112 stop_adc(s);
2113 s->dma_adc.ready = 0;
2114 if (val != AFMT_S16_LE
2115 && val != AFMT_U16_LE && val != AFMT_S8
2116 && val != AFMT_U8)
2117 val = AFMT_U8;
2118 s->prop_adc.fmt = val;
2119 s->prop_adc.fmt_original = s->prop_adc.fmt;
2120 }
2121 if (file->f_mode & FMODE_WRITE) {
2122 stop_dac(s);
2123 s->dma_dac.ready = 0;
2124 if (val != AFMT_S16_LE
2125 && val != AFMT_U16_LE && val != AFMT_S8
2126 && val != AFMT_U8)
2127 val = AFMT_U8;
2128 s->prop_dac.fmt = val;
2129 s->prop_dac.fmt_original = s->prop_dac.fmt;
2130 }
2131 } else {
2132 if (file->f_mode & FMODE_WRITE)
2133 val = s->prop_dac.fmt_original;
2134 else if (file->f_mode & FMODE_READ)
2135 val = s->prop_adc.fmt_original;
2136 }
2137 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2138 "cs4297a: cs4297a_ioctl(): DSP_SETFMT return val=0x%.8x\n",
2139 val));
2140 return put_user(val, (int *) arg);
2141
2142 case SNDCTL_DSP_POST:
2143 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
2144 "cs4297a: cs4297a_ioctl(): DSP_POST\n"));
2145 return 0;
2146
2147 case SNDCTL_DSP_GETTRIGGER:
2148 val = 0;
2149 if (file->f_mode & s->ena & FMODE_READ)
2150 val |= PCM_ENABLE_INPUT;
2151 if (file->f_mode & s->ena & FMODE_WRITE)
2152 val |= PCM_ENABLE_OUTPUT;
2153 return put_user(val, (int *) arg);
2154
2155 case SNDCTL_DSP_SETTRIGGER:
2156 if (get_user(val, (int *) arg))
2157 return -EFAULT;
2158 if (file->f_mode & FMODE_READ) {
2159 if (val & PCM_ENABLE_INPUT) {
2160 if (!s->dma_adc.ready
2161 && (ret = prog_dmabuf_adc(s)))
2162 return ret;
2163 start_adc(s);
2164 } else
2165 stop_adc(s);
2166 }
2167 if (file->f_mode & FMODE_WRITE) {
2168 if (val & PCM_ENABLE_OUTPUT) {
2169 if (!s->dma_dac.ready
2170 && (ret = prog_dmabuf_dac(s)))
2171 return ret;
2172 start_dac(s);
2173 } else
2174 stop_dac(s);
2175 }
2176 return 0;
2177
2178 case SNDCTL_DSP_GETOSPACE:
2179 if (!(file->f_mode & FMODE_WRITE))
2180 return -EINVAL;
2181 if (!s->dma_dac.ready && (val = prog_dmabuf_dac(s)))
2182 return val;
2183 spin_lock_irqsave(&s->lock, flags);
2184 cs4297a_update_ptr(s,CS_FALSE);
2185 abinfo.fragsize = s->dma_dac.fragsize;
2186 if (s->dma_dac.mapped)
2187 abinfo.bytes = s->dma_dac.sbufsz;
2188 else
2189 abinfo.bytes =
2190 s->dma_dac.sbufsz - s->dma_dac.count;
2191 abinfo.fragstotal = s->dma_dac.numfrag;
2192 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
2193 CS_DBGOUT(CS_FUNCTION | CS_PARMS, 4, printk(KERN_INFO
2194 "cs4297a: cs4297a_ioctl(): GETOSPACE .fragsize=%d .bytes=%d .fragstotal=%d .fragments=%d\n",
2195 abinfo.fragsize,abinfo.bytes,abinfo.fragstotal,
2196 abinfo.fragments));
2197 spin_unlock_irqrestore(&s->lock, flags);
2198 return copy_to_user((void *) arg, &abinfo,
2199 sizeof(abinfo)) ? -EFAULT : 0;
2200
2201 case SNDCTL_DSP_GETISPACE:
2202 if (!(file->f_mode & FMODE_READ))
2203 return -EINVAL;
2204 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)))
2205 return val;
2206 spin_lock_irqsave(&s->lock, flags);
2207 cs4297a_update_ptr(s,CS_FALSE);
2208 if (s->conversion) {
2209 abinfo.fragsize = s->dma_adc.fragsize / 2;
2210 abinfo.bytes = s->dma_adc.count / 2;
2211 abinfo.fragstotal = s->dma_adc.numfrag;
2212 abinfo.fragments =
2213 abinfo.bytes >> (s->dma_adc.fragshift - 1);
2214 } else {
2215 abinfo.fragsize = s->dma_adc.fragsize;
2216 abinfo.bytes = s->dma_adc.count;
2217 abinfo.fragstotal = s->dma_adc.numfrag;
2218 abinfo.fragments =
2219 abinfo.bytes >> s->dma_adc.fragshift;
2220 }
2221 spin_unlock_irqrestore(&s->lock, flags);
2222 return copy_to_user((void *) arg, &abinfo,
2223 sizeof(abinfo)) ? -EFAULT : 0;
2224
2225 case SNDCTL_DSP_NONBLOCK:
2226 spin_lock(&file->f_lock);
2227 file->f_flags |= O_NONBLOCK;
2228 spin_unlock(&file->f_lock);
2229 return 0;
2230
2231 case SNDCTL_DSP_GETODELAY:
2232 if (!(file->f_mode & FMODE_WRITE))
2233 return -EINVAL;
2234 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
2235 return 0;
2236 spin_lock_irqsave(&s->lock, flags);
2237 cs4297a_update_ptr(s,CS_FALSE);
2238 val = s->dma_dac.count;
2239 spin_unlock_irqrestore(&s->lock, flags);
2240 return put_user(val, (int *) arg);
2241
2242 case SNDCTL_DSP_GETIPTR:
2243 if (!(file->f_mode & FMODE_READ))
2244 return -EINVAL;
2245 if(!s->dma_adc.ready && prog_dmabuf_adc(s))
2246 return 0;
2247 spin_lock_irqsave(&s->lock, flags);
2248 cs4297a_update_ptr(s,CS_FALSE);
2249 cinfo.bytes = s->dma_adc.total_bytes;
2250 if (s->dma_adc.mapped) {
2251 cinfo.blocks =
2252 (cinfo.bytes >> s->dma_adc.fragshift) -
2253 s->dma_adc.blocks;
2254 s->dma_adc.blocks =
2255 cinfo.bytes >> s->dma_adc.fragshift;
2256 } else {
2257 if (s->conversion) {
2258 cinfo.blocks =
2259 s->dma_adc.count /
2260 2 >> (s->dma_adc.fragshift - 1);
2261 } else
2262 cinfo.blocks =
2263 s->dma_adc.count >> s->dma_adc.
2264 fragshift;
2265 }
2266 if (s->conversion)
2267 cinfo.ptr = s->dma_adc.hwptr / 2;
2268 else
2269 cinfo.ptr = s->dma_adc.hwptr;
2270 if (s->dma_adc.mapped)
2271 s->dma_adc.count &= s->dma_adc.fragsize - 1;
2272 spin_unlock_irqrestore(&s->lock, flags);
2273 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2274
2275 case SNDCTL_DSP_GETOPTR:
2276 if (!(file->f_mode & FMODE_WRITE))
2277 return -EINVAL;
2278 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
2279 return 0;
2280 spin_lock_irqsave(&s->lock, flags);
2281 cs4297a_update_ptr(s,CS_FALSE);
2282 cinfo.bytes = s->dma_dac.total_bytes;
2283 if (s->dma_dac.mapped) {
2284 cinfo.blocks =
2285 (cinfo.bytes >> s->dma_dac.fragshift) -
2286 s->dma_dac.blocks;
2287 s->dma_dac.blocks =
2288 cinfo.bytes >> s->dma_dac.fragshift;
2289 } else {
2290 cinfo.blocks =
2291 s->dma_dac.count >> s->dma_dac.fragshift;
2292 }
2293 cinfo.ptr = s->dma_dac.hwptr;
2294 if (s->dma_dac.mapped)
2295 s->dma_dac.count &= s->dma_dac.fragsize - 1;
2296 spin_unlock_irqrestore(&s->lock, flags);
2297 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2298
2299 case SNDCTL_DSP_GETBLKSIZE:
2300 if (file->f_mode & FMODE_WRITE) {
2301 if ((val = prog_dmabuf_dac(s)))
2302 return val;
2303 return put_user(s->dma_dac.fragsize, (int *) arg);
2304 }
2305 if ((val = prog_dmabuf_adc(s)))
2306 return val;
2307 if (s->conversion)
2308 return put_user(s->dma_adc.fragsize / 2,
2309 (int *) arg);
2310 else
2311 return put_user(s->dma_adc.fragsize, (int *) arg);
2312
2313 case SNDCTL_DSP_SETFRAGMENT:
2314 if (get_user(val, (int *) arg))
2315 return -EFAULT;
2316 return 0; // Say OK, but do nothing.
2317
2318 case SNDCTL_DSP_SUBDIVIDE:
2319 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision)
2320 || (file->f_mode & FMODE_WRITE
2321 && s->dma_dac.subdivision)) return -EINVAL;
2322 if (get_user(val, (int *) arg))
2323 return -EFAULT;
2324 if (val != 1 && val != 2 && val != 4)
2325 return -EINVAL;
2326 if (file->f_mode & FMODE_READ)
2327 s->dma_adc.subdivision = val;
2328 else if (file->f_mode & FMODE_WRITE)
2329 s->dma_dac.subdivision = val;
2330 return 0;
2331
2332 case SOUND_PCM_READ_RATE:
2333 if (file->f_mode & FMODE_READ)
2334 return put_user(s->prop_adc.rate, (int *) arg);
2335 else if (file->f_mode & FMODE_WRITE)
2336 return put_user(s->prop_dac.rate, (int *) arg);
2337
2338 case SOUND_PCM_READ_CHANNELS:
2339 if (file->f_mode & FMODE_READ)
2340 return put_user(s->prop_adc.channels, (int *) arg);
2341 else if (file->f_mode & FMODE_WRITE)
2342 return put_user(s->prop_dac.channels, (int *) arg);
2343
2344 case SOUND_PCM_READ_BITS:
2345 if (file->f_mode & FMODE_READ)
2346 return
2347 put_user(
2348 (s->prop_adc.
2349 fmt & (AFMT_S8 | AFMT_U8)) ? 8 : 16,
2350 (int *) arg);
2351 else if (file->f_mode & FMODE_WRITE)
2352 return
2353 put_user(
2354 (s->prop_dac.
2355 fmt & (AFMT_S8 | AFMT_U8)) ? 8 : 16,
2356 (int *) arg);
2357
2358 case SOUND_PCM_WRITE_FILTER:
2359 case SNDCTL_DSP_SETSYNCRO:
2360 case SOUND_PCM_READ_FILTER:
2361 return -EINVAL;
2362 }
2363 return mixer_ioctl(s, cmd, arg);
2364}
2365
2366static long cs4297a_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
2367{
2368 int ret;
2369
2370 mutex_lock(&swarm_cs4297a_mutex);
2371 ret = cs4297a_ioctl(file, cmd, arg);
2372 mutex_unlock(&swarm_cs4297a_mutex);
2373
2374 return ret;
2375}
2376
2377static int cs4297a_release(struct inode *inode, struct file *file)
2378{
2379 struct cs4297a_state *s =
2380 (struct cs4297a_state *) file->private_data;
2381
2382 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 2, printk(KERN_INFO
2383 "cs4297a: cs4297a_release(): inode=0x%.8x file=0x%.8x f_mode=0x%x\n",
2384 (unsigned) inode, (unsigned) file, file->f_mode));
2385 VALIDATE_STATE(s);
2386
2387 if (file->f_mode & FMODE_WRITE) {
2388 drain_dac(s, file->f_flags & O_NONBLOCK);
2389 mutex_lock(&s->open_sem_dac);
2390 stop_dac(s);
2391 dealloc_dmabuf(s, &s->dma_dac);
2392 s->open_mode &= ~FMODE_WRITE;
2393 mutex_unlock(&s->open_sem_dac);
2394 wake_up(&s->open_wait_dac);
2395 }
2396 if (file->f_mode & FMODE_READ) {
2397 drain_adc(s, file->f_flags & O_NONBLOCK);
2398 mutex_lock(&s->open_sem_adc);
2399 stop_adc(s);
2400 dealloc_dmabuf(s, &s->dma_adc);
2401 s->open_mode &= ~FMODE_READ;
2402 mutex_unlock(&s->open_sem_adc);
2403 wake_up(&s->open_wait_adc);
2404 }
2405 return 0;
2406}
2407
2408static int cs4297a_locked_open(struct inode *inode, struct file *file)
2409{
2410 int minor = iminor(inode);
2411 struct cs4297a_state *s=NULL;
2412 struct list_head *entry;
2413
2414 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2415 "cs4297a: cs4297a_open(): inode=0x%.8x file=0x%.8x f_mode=0x%x\n",
2416 (unsigned) inode, (unsigned) file, file->f_mode));
2417 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2418 "cs4297a: status = %08x\n", (int)__raw_readq(SS_CSR(R_SER_STATUS_DEBUG))));
2419
2420 list_for_each(entry, &cs4297a_devs)
2421 {
2422 s = list_entry(entry, struct cs4297a_state, list);
2423
2424 if (!((s->dev_audio ^ minor) & ~0xf))
2425 break;
2426 }
2427 if (entry == &cs4297a_devs)
2428 return -ENODEV;
2429 if (!s) {
2430 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2431 "cs4297a: cs4297a_open(): Error - unable to find audio state struct\n"));
2432 return -ENODEV;
2433 }
2434 VALIDATE_STATE(s);
2435 file->private_data = s;
2436
2437 // wait for device to become free
2438 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) {
2439 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2, printk(KERN_INFO
2440 "cs4297a: cs4297a_open(): Error - must open READ and/or WRITE\n"));
2441 return -ENODEV;
2442 }
2443 if (file->f_mode & FMODE_WRITE) {
2444 if (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX)) != 0) {
2445 printk(KERN_ERR "cs4297a: TX pipe needs to drain\n");
2446 while (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX)))
2447 ;
2448 }
2449
2450 mutex_lock(&s->open_sem_dac);
2451 while (s->open_mode & FMODE_WRITE) {
2452 if (file->f_flags & O_NONBLOCK) {
2453 mutex_unlock(&s->open_sem_dac);
2454 return -EBUSY;
2455 }
2456 mutex_unlock(&s->open_sem_dac);
2457 oss_broken_sleep_on(&s->open_wait_dac, MAX_SCHEDULE_TIMEOUT);
2458
2459 if (signal_pending(current)) {
2460 printk("open - sig pending\n");
2461 return -ERESTARTSYS;
2462 }
2463 mutex_lock(&s->open_sem_dac);
2464 }
2465 }
2466 if (file->f_mode & FMODE_READ) {
2467 mutex_lock(&s->open_sem_adc);
2468 while (s->open_mode & FMODE_READ) {
2469 if (file->f_flags & O_NONBLOCK) {
2470 mutex_unlock(&s->open_sem_adc);
2471 return -EBUSY;
2472 }
2473 mutex_unlock(&s->open_sem_adc);
2474 oss_broken_sleep_on(&s->open_wait_adc, MAX_SCHEDULE_TIMEOUT);
2475
2476 if (signal_pending(current)) {
2477 printk("open - sig pending\n");
2478 return -ERESTARTSYS;
2479 }
2480 mutex_lock(&s->open_sem_adc);
2481 }
2482 }
2483 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2484 if (file->f_mode & FMODE_READ) {
2485 s->prop_adc.fmt = AFMT_S16_BE;
2486 s->prop_adc.fmt_original = s->prop_adc.fmt;
2487 s->prop_adc.channels = 2;
2488 s->prop_adc.rate = 48000;
2489 s->conversion = 0;
2490 s->ena &= ~FMODE_READ;
2491 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
2492 s->dma_adc.subdivision = 0;
2493 mutex_unlock(&s->open_sem_adc);
2494
2495 if (prog_dmabuf_adc(s)) {
2496 CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
2497 "cs4297a: adc Program dmabufs failed.\n"));
2498 cs4297a_release(inode, file);
2499 return -ENOMEM;
2500 }
2501 }
2502 if (file->f_mode & FMODE_WRITE) {
2503 s->prop_dac.fmt = AFMT_S16_BE;
2504 s->prop_dac.fmt_original = s->prop_dac.fmt;
2505 s->prop_dac.channels = 2;
2506 s->prop_dac.rate = 48000;
2507 s->conversion = 0;
2508 s->ena &= ~FMODE_WRITE;
2509 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
2510 s->dma_dac.subdivision = 0;
2511 mutex_unlock(&s->open_sem_dac);
2512
2513 if (prog_dmabuf_dac(s)) {
2514 CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
2515 "cs4297a: dac Program dmabufs failed.\n"));
2516 cs4297a_release(inode, file);
2517 return -ENOMEM;
2518 }
2519 }
2520 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2,
2521 printk(KERN_INFO "cs4297a: cs4297a_open()- 0\n"));
2522 return nonseekable_open(inode, file);
2523}
2524
2525static int cs4297a_open(struct inode *inode, struct file *file)
2526{
2527 int ret;
2528
2529 mutex_lock(&swarm_cs4297a_mutex);
2530 ret = cs4297a_open(inode, file);
2531 mutex_unlock(&swarm_cs4297a_mutex);
2532
2533 return ret;
2534}
2535
2536// ******************************************************************************************
2537// Wave (audio) file operations struct.
2538// ******************************************************************************************
2539static const struct file_operations cs4297a_audio_fops = {
2540 .owner = THIS_MODULE,
2541 .llseek = no_llseek,
2542 .read = cs4297a_read,
2543 .write = cs4297a_write,
2544 .poll = cs4297a_poll,
2545 .unlocked_ioctl = cs4297a_unlocked_ioctl,
2546 .mmap = cs4297a_mmap,
2547 .open = cs4297a_open,
2548 .release = cs4297a_release,
2549};
2550
2551static void cs4297a_interrupt(int irq, void *dev_id)
2552{
2553 struct cs4297a_state *s = (struct cs4297a_state *) dev_id;
2554 u32 status;
2555
2556 status = __raw_readq(SS_CSR(R_SER_STATUS_DEBUG));
2557
2558 CS_DBGOUT(CS_INTERRUPT, 6, printk(KERN_INFO
2559 "cs4297a: cs4297a_interrupt() HISR=0x%.8x\n", status));
2560
2561#if 0
2562 /* XXXKW what check *should* be done here? */
2563 if (!(status & (M_SYNCSER_RX_EOP_COUNT | M_SYNCSER_RX_OVERRUN | M_SYNCSER_RX_SYNC_ERR))) {
2564 status = __raw_readq(SS_CSR(R_SER_STATUS));
2565 printk(KERN_ERR "cs4297a: unexpected interrupt (status %08x)\n", status);
2566 return;
2567 }
2568#endif
2569
2570 if (status & M_SYNCSER_RX_SYNC_ERR) {
2571 status = __raw_readq(SS_CSR(R_SER_STATUS));
2572 printk(KERN_ERR "cs4297a: rx sync error (status %08x)\n", status);
2573 return;
2574 }
2575
2576 if (status & M_SYNCSER_RX_OVERRUN) {
2577 int newptr, i;
2578 s->stats.rx_ovrrn++;
2579 printk(KERN_ERR "cs4297a: receive FIFO overrun\n");
2580
2581 /* Fix things up: get the receive descriptor pool
2582 clean and give them back to the hardware */
2583 while (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_RX)))
2584 ;
2585 newptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
2586 s->dma_adc.descrtab_phys) / sizeof(serdma_descr_t));
2587 for (i=0; i<DMA_DESCR; i++) {
2588 s->dma_adc.descrtab[i].descr_a &= ~M_DMA_SERRX_SOP;
2589 }
2590 s->dma_adc.swptr = s->dma_adc.hwptr = newptr;
2591 s->dma_adc.count = 0;
2592 s->dma_adc.sb_swptr = s->dma_adc.sb_hwptr = s->dma_adc.sample_buf;
2593 __raw_writeq(DMA_DESCR, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
2594 }
2595
2596 spin_lock(&s->lock);
2597 cs4297a_update_ptr(s,CS_TRUE);
2598 spin_unlock(&s->lock);
2599
2600 CS_DBGOUT(CS_INTERRUPT, 6, printk(KERN_INFO
2601 "cs4297a: cs4297a_interrupt()-\n"));
2602}
2603
2604#if 0
2605static struct initvol {
2606 int mixch;
2607 int vol;
2608} initvol[] __initdata = {
2609
2610 {SOUND_MIXER_WRITE_VOLUME, 0x4040},
2611 {SOUND_MIXER_WRITE_PCM, 0x4040},
2612 {SOUND_MIXER_WRITE_SYNTH, 0x4040},
2613 {SOUND_MIXER_WRITE_CD, 0x4040},
2614 {SOUND_MIXER_WRITE_LINE, 0x4040},
2615 {SOUND_MIXER_WRITE_LINE1, 0x4040},
2616 {SOUND_MIXER_WRITE_RECLEV, 0x0000},
2617 {SOUND_MIXER_WRITE_SPEAKER, 0x4040},
2618 {SOUND_MIXER_WRITE_MIC, 0x0000}
2619};
2620#endif
2621
2622static int __init cs4297a_init(void)
2623{
2624 struct cs4297a_state *s;
2625 u32 pwr, id;
2626 mm_segment_t fs;
2627 int rval;
2628 u64 cfg;
2629 int mdio_val;
2630
2631 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
2632 "cs4297a: cs4297a_init_module()+ \n"));
2633
2634 mdio_val = __raw_readq(KSEG1 + A_MAC_REGISTER(2, R_MAC_MDIO)) &
2635 (M_MAC_MDIO_DIR|M_MAC_MDIO_OUT);
2636
2637 /* Check syscfg for synchronous serial on port 1 */
2638 cfg = __raw_readq(KSEG1 + A_SCD_SYSTEM_CFG);
2639 if (!(cfg & M_SYS_SER1_ENABLE)) {
2640 __raw_writeq(cfg | M_SYS_SER1_ENABLE, KSEG1+A_SCD_SYSTEM_CFG);
2641 cfg = __raw_readq(KSEG1 + A_SCD_SYSTEM_CFG);
2642 if (!(cfg & M_SYS_SER1_ENABLE)) {
2643 printk(KERN_INFO "cs4297a: serial port 1 not configured for synchronous operation\n");
2644 return -1;
2645 }
2646
2647 printk(KERN_INFO "cs4297a: serial port 1 switching to synchronous operation\n");
2648
2649 /* Force the codec (on SWARM) to reset by clearing
2650 GENO, preserving MDIO (no effect on CSWARM) */
2651 __raw_writeq(mdio_val, KSEG1+A_MAC_REGISTER(2, R_MAC_MDIO));
2652 udelay(10);
2653 }
2654
2655 /* Now set GENO */
2656 __raw_writeq(mdio_val | M_MAC_GENC, KSEG1+A_MAC_REGISTER(2, R_MAC_MDIO));
2657 /* Give the codec some time to finish resetting (start the bit clock) */
2658 udelay(100);
2659
2660 if (!(s = kzalloc(sizeof(struct cs4297a_state), GFP_KERNEL))) {
2661 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
2662 "cs4297a: probe() no memory for state struct.\n"));
2663 return -1;
2664 }
2665 s->magic = CS4297a_MAGIC;
2666 init_waitqueue_head(&s->dma_adc.wait);
2667 init_waitqueue_head(&s->dma_dac.wait);
2668 init_waitqueue_head(&s->dma_adc.reg_wait);
2669 init_waitqueue_head(&s->dma_dac.reg_wait);
2670 init_waitqueue_head(&s->open_wait);
2671 init_waitqueue_head(&s->open_wait_adc);
2672 init_waitqueue_head(&s->open_wait_dac);
2673 mutex_init(&s->open_sem_adc);
2674 mutex_init(&s->open_sem_dac);
2675 spin_lock_init(&s->lock);
2676
2677 s->irq = K_INT_SER_1;
2678
2679 if (request_irq
2680 (s->irq, cs4297a_interrupt, 0, "Crystal CS4297a", s)) {
2681 CS_DBGOUT(CS_INIT | CS_ERROR, 1,
2682 printk(KERN_ERR "cs4297a: irq %u in use\n", s->irq));
2683 goto err_irq;
2684 }
2685 if ((s->dev_audio = register_sound_dsp(&cs4297a_audio_fops, -1)) <
2686 0) {
2687 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2688 "cs4297a: probe() register_sound_dsp() failed.\n"));
2689 goto err_dev1;
2690 }
2691 if ((s->dev_mixer = register_sound_mixer(&cs4297a_mixer_fops, -1)) <
2692 0) {
2693 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2694 "cs4297a: probe() register_sound_mixer() failed.\n"));
2695 goto err_dev2;
2696 }
2697
2698 if (ser_init(s) || dma_init(s)) {
2699 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2700 "cs4297a: ser_init failed.\n"));
2701 goto err_dev3;
2702 }
2703
2704 do {
2705 udelay(4000);
2706 rval = cs4297a_read_ac97(s, AC97_POWER_CONTROL, &pwr);
2707 } while (!rval && (pwr != 0xf));
2708
2709 if (!rval) {
2710 char *sb1250_duart_present;
2711
2712 fs = get_fs();
2713 set_fs(KERNEL_DS);
2714#if 0
2715 val = SOUND_MASK_LINE;
2716 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
2717 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
2718 val = initvol[i].vol;
2719 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
2720 }
2721// cs4297a_write_ac97(s, 0x18, 0x0808);
2722#else
2723 // cs4297a_write_ac97(s, 0x5e, 0x180);
2724 cs4297a_write_ac97(s, 0x02, 0x0808);
2725 cs4297a_write_ac97(s, 0x18, 0x0808);
2726#endif
2727 set_fs(fs);
2728
2729 list_add(&s->list, &cs4297a_devs);
2730
2731 cs4297a_read_ac97(s, AC97_VENDOR_ID1, &id);
2732
2733 sb1250_duart_present = symbol_get(sb1250_duart_present);
2734 if (sb1250_duart_present)
2735 sb1250_duart_present[1] = 0;
2736
2737 printk(KERN_INFO "cs4297a: initialized (vendor id = %x)\n", id);
2738
2739 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
2740 printk(KERN_INFO "cs4297a: cs4297a_init_module()-\n"));
2741
2742 return 0;
2743 }
2744
2745 err_dev3:
2746 unregister_sound_mixer(s->dev_mixer);
2747 err_dev2:
2748 unregister_sound_dsp(s->dev_audio);
2749 err_dev1:
2750 free_irq(s->irq, s);
2751 err_irq:
2752 kfree(s);
2753
2754 printk(KERN_INFO "cs4297a: initialization failed\n");
2755
2756 return -1;
2757}
2758
2759static void __exit cs4297a_cleanup(void)
2760{
2761 /*
2762 XXXKW
2763 disable_irq, free_irq
2764 drain DMA queue
2765 disable DMA
2766 disable TX/RX
2767 free memory
2768 */
2769 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
2770 printk(KERN_INFO "cs4297a: cleanup_cs4297a() finished\n"));
2771}
2772
2773// ---------------------------------------------------------------------
2774
2775MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
2776MODULE_DESCRIPTION("Cirrus Logic CS4297a Driver for Broadcom SWARM board");
2777
2778// ---------------------------------------------------------------------
2779
2780module_init(cs4297a_init);
2781module_exit(cs4297a_cleanup);
diff --git a/sound/oss/sys_timer.c b/sound/oss/sys_timer.c
deleted file mode 100644
index d17019d25b99..000000000000
--- a/sound/oss/sys_timer.c
+++ /dev/null
@@ -1,280 +0,0 @@
1/*
2 * sound/oss/sys_timer.c
3 *
4 * The default timer for the Level 2 sequencer interface
5 * Uses the (1/HZ sec) timer of kernel.
6 */
7/*
8 * Copyright (C) by Hannu Savolainen 1993-1997
9 *
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
12 * for more info.
13 */
14/*
15 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
16 * Andrew Veliath : adapted tmr2ticks from level 1 sequencer (avoid overflow)
17 */
18#include <linux/spinlock.h>
19#include "sound_config.h"
20
21static volatile int opened, tmr_running;
22static volatile unsigned int tmr_offs, tmr_ctr;
23static volatile unsigned long ticks_offs;
24static volatile int curr_tempo, curr_timebase;
25static volatile unsigned long curr_ticks;
26static volatile unsigned long next_event_time;
27static unsigned long prev_event_time;
28
29static void poll_def_tmr(unsigned long dummy);
30static DEFINE_SPINLOCK(lock);
31static DEFINE_TIMER(def_tmr, poll_def_tmr, 0, 0);
32
33static unsigned long
34tmr2ticks(int tmr_value)
35{
36 /*
37 * Convert timer ticks to MIDI ticks
38 */
39
40 unsigned long tmp;
41 unsigned long scale;
42
43 /* tmr_value (ticks per sec) *
44 1000000 (usecs per sec) / HZ (ticks per sec) -=> usecs */
45 tmp = tmr_value * (1000000 / HZ);
46 scale = (60 * 1000000) / (curr_tempo * curr_timebase); /* usecs per MIDI tick */
47 return (tmp + scale / 2) / scale;
48}
49
50static void
51poll_def_tmr(unsigned long dummy)
52{
53 if (!opened)
54 return;
55 def_tmr.expires = (1) + jiffies;
56 add_timer(&def_tmr);
57
58 if (!tmr_running)
59 return;
60
61 spin_lock(&lock);
62 tmr_ctr++;
63 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
64
65 if (curr_ticks >= next_event_time) {
66 next_event_time = (unsigned long) -1;
67 sequencer_timer(0);
68 }
69
70 spin_unlock(&lock);
71}
72
73static void
74tmr_reset(void)
75{
76 unsigned long flags;
77
78 spin_lock_irqsave(&lock,flags);
79 tmr_offs = 0;
80 ticks_offs = 0;
81 tmr_ctr = 0;
82 next_event_time = (unsigned long) -1;
83 prev_event_time = 0;
84 curr_ticks = 0;
85 spin_unlock_irqrestore(&lock,flags);
86}
87
88static int
89def_tmr_open(int dev, int mode)
90{
91 if (opened)
92 return -EBUSY;
93
94 tmr_reset();
95 curr_tempo = 60;
96 curr_timebase = 100;
97 opened = 1;
98 {
99 def_tmr.expires = (1) + jiffies;
100 add_timer(&def_tmr);
101 }
102
103 return 0;
104}
105
106static void
107def_tmr_close(int dev)
108{
109 opened = tmr_running = 0;
110 del_timer(&def_tmr);
111}
112
113static int
114def_tmr_event(int dev, unsigned char *event)
115{
116 unsigned char cmd = event[1];
117 unsigned long parm = *(int *) &event[4];
118
119 switch (cmd)
120 {
121 case TMR_WAIT_REL:
122 parm += prev_event_time;
123 case TMR_WAIT_ABS:
124 if (parm > 0)
125 {
126 long time;
127
128 if (parm <= curr_ticks) /* It's the time */
129 return TIMER_NOT_ARMED;
130
131 time = parm;
132 next_event_time = prev_event_time = time;
133
134 return TIMER_ARMED;
135 }
136 break;
137
138 case TMR_START:
139 tmr_reset();
140 tmr_running = 1;
141 break;
142
143 case TMR_STOP:
144 tmr_running = 0;
145 break;
146
147 case TMR_CONTINUE:
148 tmr_running = 1;
149 break;
150
151 case TMR_TEMPO:
152 if (parm)
153 {
154 if (parm < 8)
155 parm = 8;
156 if (parm > 360)
157 parm = 360;
158 tmr_offs = tmr_ctr;
159 ticks_offs += tmr2ticks(tmr_ctr);
160 tmr_ctr = 0;
161 curr_tempo = parm;
162 }
163 break;
164
165 case TMR_ECHO:
166 seq_copy_to_input(event, 8);
167 break;
168
169 default:;
170 }
171
172 return TIMER_NOT_ARMED;
173}
174
175static unsigned long
176def_tmr_get_time(int dev)
177{
178 if (!opened)
179 return 0;
180
181 return curr_ticks;
182}
183
184/* same as sound_timer.c:timer_ioctl!? */
185static int def_tmr_ioctl(int dev, unsigned int cmd, void __user *arg)
186{
187 int __user *p = arg;
188 int val;
189
190 switch (cmd) {
191 case SNDCTL_TMR_SOURCE:
192 return __put_user(TMR_INTERNAL, p);
193
194 case SNDCTL_TMR_START:
195 tmr_reset();
196 tmr_running = 1;
197 return 0;
198
199 case SNDCTL_TMR_STOP:
200 tmr_running = 0;
201 return 0;
202
203 case SNDCTL_TMR_CONTINUE:
204 tmr_running = 1;
205 return 0;
206
207 case SNDCTL_TMR_TIMEBASE:
208 if (__get_user(val, p))
209 return -EFAULT;
210 if (val) {
211 if (val < 1)
212 val = 1;
213 if (val > 1000)
214 val = 1000;
215 curr_timebase = val;
216 }
217 return __put_user(curr_timebase, p);
218
219 case SNDCTL_TMR_TEMPO:
220 if (__get_user(val, p))
221 return -EFAULT;
222 if (val) {
223 if (val < 8)
224 val = 8;
225 if (val > 250)
226 val = 250;
227 tmr_offs = tmr_ctr;
228 ticks_offs += tmr2ticks(tmr_ctr);
229 tmr_ctr = 0;
230 curr_tempo = val;
231 reprogram_timer();
232 }
233 return __put_user(curr_tempo, p);
234
235 case SNDCTL_SEQ_CTRLRATE:
236 if (__get_user(val, p))
237 return -EFAULT;
238 if (val != 0) /* Can't change */
239 return -EINVAL;
240 val = ((curr_tempo * curr_timebase) + 30) / 60;
241 return __put_user(val, p);
242
243 case SNDCTL_SEQ_GETTIME:
244 return __put_user(curr_ticks, p);
245
246 case SNDCTL_TMR_METRONOME:
247 /* NOP */
248 break;
249
250 default:;
251 }
252 return -EINVAL;
253}
254
255static void
256def_tmr_arm(int dev, long time)
257{
258 if (time < 0)
259 time = curr_ticks + 1;
260 else if (time <= curr_ticks) /* It's the time */
261 return;
262
263 next_event_time = prev_event_time = time;
264
265 return;
266}
267
268struct sound_timer_operations default_sound_timer =
269{
270 .owner = THIS_MODULE,
271 .info = {"System clock", 0},
272 .priority = 0, /* Priority */
273 .devlink = 0, /* Local device link */
274 .open = def_tmr_open,
275 .close = def_tmr_close,
276 .event = def_tmr_event,
277 .get_time = def_tmr_get_time,
278 .ioctl = def_tmr_ioctl,
279 .arm_timer = def_tmr_arm
280};
diff --git a/sound/oss/trix.c b/sound/oss/trix.c
deleted file mode 100644
index a57bc635d758..000000000000
--- a/sound/oss/trix.c
+++ /dev/null
@@ -1,525 +0,0 @@
1/*
2 * sound/oss/trix.c
3 *
4 * Low level driver for the MediaTrix AudioTrix Pro
5 * (MT-0002-PC Control Chip)
6 *
7 *
8 * Copyright (C) by Hannu Savolainen 1993-1997
9 *
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
12 * for more info.
13 *
14 * Changes
15 * Alan Cox Modularisation, cleanup.
16 * Christoph Hellwig Adapted to module_init/module_exit
17 * Arnaldo C. de Melo Got rid of attach_uart401
18 */
19
20#include <linux/init.h>
21#include <linux/module.h>
22
23#include "sound_config.h"
24#include "sb.h"
25#include "sound_firmware.h"
26
27#include "ad1848.h"
28#include "mpu401.h"
29
30#include "trix_boot.h"
31
32static int mpu;
33
34static bool joystick;
35
36static unsigned char trix_read(int addr)
37{
38 outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */
39 return inb(0x391); /* MT-0002-PC ASIC data */
40}
41
42static void trix_write(int addr, int data)
43{
44 outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */
45 outb(((unsigned char) data), 0x391); /* MT-0002-PC ASIC data */
46}
47
48static void download_boot(int base)
49{
50 int i = 0, n = trix_boot_len;
51
52 if (trix_boot_len == 0)
53 return;
54
55 trix_write(0xf8, 0x00); /* ??????? */
56 outb((0x01), base + 6); /* Clear the internal data pointer */
57 outb((0x00), base + 6); /* Restart */
58
59 /*
60 * Write the boot code to the RAM upload/download register.
61 * Each write increments the internal data pointer.
62 */
63 outb((0x01), base + 6); /* Clear the internal data pointer */
64 outb((0x1A), 0x390); /* Select RAM download/upload port */
65
66 for (i = 0; i < n; i++)
67 outb((trix_boot[i]), 0x391);
68 for (i = n; i < 10016; i++) /* Clear up to first 16 bytes of data RAM */
69 outb((0x00), 0x391);
70 outb((0x00), base + 6); /* Reset */
71 outb((0x50), 0x390); /* ?????? */
72
73}
74
75static int trix_set_wss_port(struct address_info *hw_config)
76{
77 unsigned char addr_bits;
78
79 if (trix_read(0x15) != 0x71) /* No ASIC signature */
80 {
81 MDB(printk(KERN_ERR "No AudioTrix ASIC signature found\n"));
82 return 0;
83 }
84
85 /*
86 * Reset some registers.
87 */
88
89 trix_write(0x13, 0);
90 trix_write(0x14, 0);
91
92 /*
93 * Configure the ASIC to place the codec to the proper I/O location
94 */
95
96 switch (hw_config->io_base)
97 {
98 case 0x530:
99 addr_bits = 0;
100 break;
101 case 0x604:
102 addr_bits = 1;
103 break;
104 case 0xE80:
105 addr_bits = 2;
106 break;
107 case 0xF40:
108 addr_bits = 3;
109 break;
110 default:
111 return 0;
112 }
113
114 trix_write(0x19, (trix_read(0x19) & 0x03) | addr_bits);
115 return 1;
116}
117
118/*
119 * Probe and attach routines for the Windows Sound System mode of
120 * AudioTrix Pro
121 */
122
123static int __init init_trix_wss(struct address_info *hw_config)
124{
125 static unsigned char dma_bits[4] = {
126 1, 2, 0, 3
127 };
128 struct resource *ports;
129 int config_port = hw_config->io_base + 0;
130 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
131 int old_num_mixers = num_mixers;
132 u8 config, bits;
133 int ret;
134
135 switch(hw_config->irq) {
136 case 7:
137 bits = 8;
138 break;
139 case 9:
140 bits = 0x10;
141 break;
142 case 10:
143 bits = 0x18;
144 break;
145 case 11:
146 bits = 0x20;
147 break;
148 default:
149 printk(KERN_ERR "AudioTrix: Bad WSS IRQ %d\n", hw_config->irq);
150 return 0;
151 }
152
153 switch (dma1) {
154 case 0:
155 case 1:
156 case 3:
157 break;
158 default:
159 printk(KERN_ERR "AudioTrix: Bad WSS DMA %d\n", dma1);
160 return 0;
161 }
162
163 switch (dma2) {
164 case -1:
165 case 0:
166 case 1:
167 case 3:
168 break;
169 default:
170 printk(KERN_ERR "AudioTrix: Bad capture DMA %d\n", dma2);
171 return 0;
172 }
173
174 /*
175 * Check if the IO port returns valid signature. The original MS Sound
176 * system returns 0x04 while some cards (AudioTrix Pro for example)
177 * return 0x00.
178 */
179 ports = request_region(hw_config->io_base + 4, 4, "ad1848");
180 if (!ports) {
181 printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base);
182 return 0;
183 }
184
185 if (!request_region(hw_config->io_base, 4, "MSS config")) {
186 printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base);
187 release_region(hw_config->io_base + 4, 4);
188 return 0;
189 }
190
191 if (!trix_set_wss_port(hw_config))
192 goto fail;
193
194 config = inb(hw_config->io_base + 3);
195
196 if ((config & 0x3f) != 0x00)
197 {
198 MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x\n", hw_config->io_base));
199 goto fail;
200 }
201
202 /*
203 * Check that DMA0 is not in use with a 8 bit board.
204 */
205
206 if (dma1 == 0 && config & 0x80)
207 {
208 printk(KERN_ERR "AudioTrix: Can't use DMA0 with a 8 bit card slot\n");
209 goto fail;
210 }
211 if (hw_config->irq > 9 && config & 0x80)
212 {
213 printk(KERN_ERR "AudioTrix: Can't use IRQ%d with a 8 bit card slot\n", hw_config->irq);
214 goto fail;
215 }
216
217 ret = ad1848_detect(ports, NULL, hw_config->osp);
218 if (!ret)
219 goto fail;
220
221 if (joystick==1)
222 trix_write(0x15, 0x80);
223
224 /*
225 * Set the IRQ and DMA addresses.
226 */
227
228 outb((bits | 0x40), config_port);
229
230 if (dma2 == -1 || dma2 == dma1)
231 {
232 bits |= dma_bits[dma1];
233 dma2 = dma1;
234 }
235 else
236 {
237 unsigned char tmp;
238
239 tmp = trix_read(0x13) & ~30;
240 trix_write(0x13, tmp | 0x80 | (dma1 << 4));
241
242 tmp = trix_read(0x14) & ~30;
243 trix_write(0x14, tmp | 0x80 | (dma2 << 4));
244 }
245
246 outb((bits), config_port); /* Write IRQ+DMA setup */
247
248 hw_config->slots[0] = ad1848_init("AudioTrix Pro", ports,
249 hw_config->irq,
250 dma1,
251 dma2,
252 0,
253 hw_config->osp,
254 THIS_MODULE);
255
256 if (num_mixers > old_num_mixers) /* Mixer got installed */
257 {
258 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE); /* Line in */
259 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD);
260 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_SYNTH); /* OPL4 */
261 AD1848_REROUTE(SOUND_MIXER_SPEAKER, SOUND_MIXER_ALTPCM); /* SB */
262 }
263 return 1;
264
265fail:
266 release_region(hw_config->io_base, 4);
267 release_region(hw_config->io_base + 4, 4);
268 return 0;
269}
270
271static int __init probe_trix_sb(struct address_info *hw_config)
272{
273
274 int tmp;
275 unsigned char conf;
276 extern int sb_be_quiet;
277 int old_quiet;
278 static signed char irq_translate[] = {
279 -1, -1, -1, 0, 1, 2, -1, 3
280 };
281
282 if (trix_boot_len == 0)
283 return 0; /* No boot code -> no fun */
284
285 if ((hw_config->io_base & 0xffffff8f) != 0x200)
286 return 0;
287
288 tmp = hw_config->irq;
289 if (tmp > 7)
290 return 0;
291 if (irq_translate[tmp] == -1)
292 return 0;
293
294 tmp = hw_config->dma;
295 if (tmp != 1 && tmp != 3)
296 return 0;
297
298 if (!request_region(hw_config->io_base, 16, "soundblaster")) {
299 printk(KERN_ERR "AudioTrix: SB I/O port conflict (%x)\n", hw_config->io_base);
300 return 0;
301 }
302
303 conf = 0x84; /* DMA and IRQ enable */
304 conf |= hw_config->io_base & 0x70; /* I/O address bits */
305 conf |= irq_translate[hw_config->irq];
306 if (hw_config->dma == 3)
307 conf |= 0x08;
308 trix_write(0x1b, conf);
309
310 download_boot(hw_config->io_base);
311
312 hw_config->name = "AudioTrix SB";
313 if (!sb_dsp_detect(hw_config, 0, 0, NULL)) {
314 release_region(hw_config->io_base, 16);
315 return 0;
316 }
317
318 hw_config->driver_use_1 = SB_NO_MIDI | SB_NO_MIXER | SB_NO_RECORDING;
319
320 /* Prevent false alarms */
321 old_quiet = sb_be_quiet;
322 sb_be_quiet = 1;
323
324 sb_dsp_init(hw_config, THIS_MODULE);
325
326 sb_be_quiet = old_quiet;
327 return 1;
328}
329
330static int __init probe_trix_mpu(struct address_info *hw_config)
331{
332 unsigned char conf;
333 static int irq_bits[] = {
334 -1, -1, -1, 1, 2, 3, -1, 4, -1, 5
335 };
336
337 if (hw_config->irq > 9)
338 {
339 printk(KERN_ERR "AudioTrix: Bad MPU IRQ %d\n", hw_config->irq);
340 return 0;
341 }
342 if (irq_bits[hw_config->irq] == -1)
343 {
344 printk(KERN_ERR "AudioTrix: Bad MPU IRQ %d\n", hw_config->irq);
345 return 0;
346 }
347 switch (hw_config->io_base)
348 {
349 case 0x330:
350 conf = 0x00;
351 break;
352 case 0x370:
353 conf = 0x04;
354 break;
355 case 0x3b0:
356 conf = 0x08;
357 break;
358 case 0x3f0:
359 conf = 0x0c;
360 break;
361 default:
362 return 0; /* Invalid port */
363 }
364
365 conf |= irq_bits[hw_config->irq] << 4;
366 trix_write(0x19, (trix_read(0x19) & 0x83) | conf);
367 hw_config->name = "AudioTrix Pro";
368 return probe_uart401(hw_config, THIS_MODULE);
369}
370
371static void __exit unload_trix_wss(struct address_info *hw_config)
372{
373 int dma2 = hw_config->dma2;
374
375 if (dma2 == -1)
376 dma2 = hw_config->dma;
377
378 release_region(0x390, 2);
379 release_region(hw_config->io_base, 4);
380
381 ad1848_unload(hw_config->io_base + 4,
382 hw_config->irq,
383 hw_config->dma,
384 dma2,
385 0);
386 sound_unload_audiodev(hw_config->slots[0]);
387}
388
389static inline void __exit unload_trix_mpu(struct address_info *hw_config)
390{
391 unload_uart401(hw_config);
392}
393
394static inline void __exit unload_trix_sb(struct address_info *hw_config)
395{
396 sb_dsp_unload(hw_config, mpu);
397}
398
399static struct address_info cfg;
400static struct address_info cfg2;
401static struct address_info cfg_mpu;
402
403static int sb;
404static int fw_load;
405
406static int __initdata io = -1;
407static int __initdata irq = -1;
408static int __initdata dma = -1;
409static int __initdata dma2 = -1; /* Set this for modules that need it */
410static int __initdata sb_io = -1;
411static int __initdata sb_dma = -1;
412static int __initdata sb_irq = -1;
413static int __initdata mpu_io = -1;
414static int __initdata mpu_irq = -1;
415
416module_param_hw(io, int, ioport, 0);
417module_param_hw(irq, int, irq, 0);
418module_param_hw(dma, int, dma, 0);
419module_param_hw(dma2, int, dma, 0);
420module_param_hw(sb_io, int, ioport, 0);
421module_param_hw(sb_dma, int, dma, 0);
422module_param_hw(sb_irq, int, irq, 0);
423module_param_hw(mpu_io, int, ioport, 0);
424module_param_hw(mpu_irq, int, irq, 0);
425module_param(joystick, bool, 0);
426
427static int __init init_trix(void)
428{
429 printk(KERN_INFO "MediaTrix audio driver Copyright (C) by Hannu Savolainen 1993-1996\n");
430
431 cfg.io_base = io;
432 cfg.irq = irq;
433 cfg.dma = dma;
434 cfg.dma2 = dma2;
435
436 cfg2.io_base = sb_io;
437 cfg2.irq = sb_irq;
438 cfg2.dma = sb_dma;
439
440 cfg_mpu.io_base = mpu_io;
441 cfg_mpu.irq = mpu_irq;
442
443 if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
444 printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
445 return -EINVAL;
446 }
447
448 if (cfg2.io_base != -1 && (cfg2.irq == -1 || cfg2.dma == -1)) {
449 printk(KERN_INFO "CONFIG_SB_IRQ and CONFIG_SB_DMA must be specified if SB_IO is set.\n");
450 return -EINVAL;
451 }
452 if (cfg_mpu.io_base != -1 && cfg_mpu.irq == -1) {
453 printk(KERN_INFO "CONFIG_MPU_IRQ must be specified if MPU_IO is set.\n");
454 return -EINVAL;
455 }
456 if (!trix_boot)
457 {
458 fw_load = 1;
459 trix_boot_len = mod_firmware_load("/etc/sound/trxpro.bin",
460 (char **) &trix_boot);
461 }
462
463 if (!request_region(0x390, 2, "AudioTrix")) {
464 printk(KERN_ERR "AudioTrix: Config port I/O conflict\n");
465 return -ENODEV;
466 }
467
468 if (!init_trix_wss(&cfg)) {
469 release_region(0x390, 2);
470 return -ENODEV;
471 }
472
473 /*
474 * We must attach in the right order to get the firmware
475 * loaded up in time.
476 */
477
478 if (cfg2.io_base != -1) {
479 sb = probe_trix_sb(&cfg2);
480 }
481
482 if (cfg_mpu.io_base != -1)
483 mpu = probe_trix_mpu(&cfg_mpu);
484
485 return 0;
486}
487
488static void __exit cleanup_trix(void)
489{
490 if (fw_load)
491 vfree(trix_boot);
492 if (sb)
493 unload_trix_sb(&cfg2);
494 if (mpu)
495 unload_trix_mpu(&cfg_mpu);
496 unload_trix_wss(&cfg);
497}
498
499module_init(init_trix);
500module_exit(cleanup_trix);
501
502#ifndef MODULE
503static int __init setup_trix (char *str)
504{
505 /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, mpu_io, mpu_irq */
506 int ints[9];
507
508 str = get_options(str, ARRAY_SIZE(ints), ints);
509
510 io = ints[1];
511 irq = ints[2];
512 dma = ints[3];
513 dma2 = ints[4];
514 sb_io = ints[5];
515 sb_irq = ints[6];
516 sb_dma = ints[6];
517 mpu_io = ints[7];
518 mpu_irq = ints[8];
519
520 return 1;
521}
522
523__setup("trix=", setup_trix);
524#endif
525MODULE_LICENSE("GPL");
diff --git a/sound/oss/tuning.h b/sound/oss/tuning.h
deleted file mode 100644
index a73e3dd39f9a..000000000000
--- a/sound/oss/tuning.h
+++ /dev/null
@@ -1,23 +0,0 @@
1static unsigned short semitone_tuning[24] =
2{
3/* 0 */ 10000, 10595, 11225, 11892, 12599, 13348, 14142, 14983,
4/* 8 */ 15874, 16818, 17818, 18877, 20000, 21189, 22449, 23784,
5/* 16 */ 25198, 26697, 28284, 29966, 31748, 33636, 35636, 37755
6};
7
8static unsigned short cent_tuning[100] =
9{
10/* 0 */ 10000, 10006, 10012, 10017, 10023, 10029, 10035, 10041,
11/* 8 */ 10046, 10052, 10058, 10064, 10070, 10075, 10081, 10087,
12/* 16 */ 10093, 10099, 10105, 10110, 10116, 10122, 10128, 10134,
13/* 24 */ 10140, 10145, 10151, 10157, 10163, 10169, 10175, 10181,
14/* 32 */ 10187, 10192, 10198, 10204, 10210, 10216, 10222, 10228,
15/* 40 */ 10234, 10240, 10246, 10251, 10257, 10263, 10269, 10275,
16/* 48 */ 10281, 10287, 10293, 10299, 10305, 10311, 10317, 10323,
17/* 56 */ 10329, 10335, 10341, 10347, 10353, 10359, 10365, 10371,
18/* 64 */ 10377, 10383, 10389, 10395, 10401, 10407, 10413, 10419,
19/* 72 */ 10425, 10431, 10437, 10443, 10449, 10455, 10461, 10467,
20/* 80 */ 10473, 10479, 10485, 10491, 10497, 10503, 10509, 10515,
21/* 88 */ 10521, 10528, 10534, 10540, 10546, 10552, 10558, 10564,
22/* 96 */ 10570, 10576, 10582, 10589
23};
diff --git a/sound/oss/uart401.c b/sound/oss/uart401.c
deleted file mode 100644
index 83dcc85b8688..000000000000
--- a/sound/oss/uart401.c
+++ /dev/null
@@ -1,477 +0,0 @@
1/*
2 * sound/oss/uart401.c
3 *
4 * MPU-401 UART driver (formerly uart401_midi.c)
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 * Changes:
14 * Alan Cox Reformatted, removed sound_mem usage, use normal Linux
15 * interrupt allocation. Protect against bogus unload
16 * Fixed to allow IRQ > 15
17 * Christoph Hellwig Adapted to module_init/module_exit
18 * Arnaldo C. de Melo got rid of check_region
19 *
20 * Status:
21 * Untested
22 */
23
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/spinlock.h>
29#include "sound_config.h"
30
31#include "mpu401.h"
32
33struct uart401_devc
34{
35 int base;
36 int irq;
37 int *osp;
38 void (*midi_input_intr) (int dev, unsigned char data);
39 int opened, disabled;
40 volatile unsigned char input_byte;
41 int my_dev;
42 int share_irq;
43 spinlock_t lock;
44};
45
46#define DATAPORT (devc->base)
47#define COMDPORT (devc->base+1)
48#define STATPORT (devc->base+1)
49
50static int uart401_status(struct uart401_devc *devc)
51{
52 return inb(STATPORT);
53}
54
55#define input_avail(devc) (!(uart401_status(devc)&INPUT_AVAIL))
56#define output_ready(devc) (!(uart401_status(devc)&OUTPUT_READY))
57
58static void uart401_cmd(struct uart401_devc *devc, unsigned char cmd)
59{
60 outb((cmd), COMDPORT);
61}
62
63static int uart401_read(struct uart401_devc *devc)
64{
65 return inb(DATAPORT);
66}
67
68static void uart401_write(struct uart401_devc *devc, unsigned char byte)
69{
70 outb((byte), DATAPORT);
71}
72
73#define OUTPUT_READY 0x40
74#define INPUT_AVAIL 0x80
75#define MPU_ACK 0xFE
76#define MPU_RESET 0xFF
77#define UART_MODE_ON 0x3F
78
79static int reset_uart401(struct uart401_devc *devc);
80static void enter_uart_mode(struct uart401_devc *devc);
81
82static void uart401_input_loop(struct uart401_devc *devc)
83{
84 int work_limit=30000;
85
86 while (input_avail(devc) && --work_limit)
87 {
88 unsigned char c = uart401_read(devc);
89
90 if (c == MPU_ACK)
91 devc->input_byte = c;
92 else if (devc->opened & OPEN_READ && devc->midi_input_intr)
93 devc->midi_input_intr(devc->my_dev, c);
94 }
95 if(work_limit==0)
96 printk(KERN_WARNING "Too much work in interrupt on uart401 (0x%X). UART jabbering ??\n", devc->base);
97}
98
99irqreturn_t uart401intr(int irq, void *dev_id)
100{
101 struct uart401_devc *devc = dev_id;
102
103 if (devc == NULL)
104 {
105 printk(KERN_ERR "uart401: bad devc\n");
106 return IRQ_NONE;
107 }
108
109 if (input_avail(devc))
110 uart401_input_loop(devc);
111 return IRQ_HANDLED;
112}
113
114static int
115uart401_open(int dev, int mode,
116 void (*input) (int dev, unsigned char data),
117 void (*output) (int dev)
118)
119{
120 struct uart401_devc *devc = (struct uart401_devc *)
121 midi_devs[dev]->devc;
122
123 if (devc->opened)
124 return -EBUSY;
125
126 /* Flush the UART */
127
128 while (input_avail(devc))
129 uart401_read(devc);
130
131 devc->midi_input_intr = input;
132 devc->opened = mode;
133 enter_uart_mode(devc);
134 devc->disabled = 0;
135
136 return 0;
137}
138
139static void uart401_close(int dev)
140{
141 struct uart401_devc *devc = (struct uart401_devc *)
142 midi_devs[dev]->devc;
143
144 reset_uart401(devc);
145 devc->opened = 0;
146}
147
148static int uart401_out(int dev, unsigned char midi_byte)
149{
150 int timeout;
151 unsigned long flags;
152 struct uart401_devc *devc = (struct uart401_devc *)
153 midi_devs[dev]->devc;
154
155 if (devc->disabled)
156 return 1;
157 /*
158 * Test for input since pending input seems to block the output.
159 */
160
161 spin_lock_irqsave(&devc->lock,flags);
162 if (input_avail(devc))
163 uart401_input_loop(devc);
164
165 spin_unlock_irqrestore(&devc->lock,flags);
166
167 /*
168 * Sometimes it takes about 13000 loops before the output becomes ready
169 * (After reset). Normally it takes just about 10 loops.
170 */
171
172 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
173
174 if (!output_ready(devc))
175 {
176 printk(KERN_WARNING "uart401: Timeout - Device not responding\n");
177 devc->disabled = 1;
178 reset_uart401(devc);
179 enter_uart_mode(devc);
180 return 1;
181 }
182 uart401_write(devc, midi_byte);
183 return 1;
184}
185
186static inline int uart401_start_read(int dev)
187{
188 return 0;
189}
190
191static inline int uart401_end_read(int dev)
192{
193 return 0;
194}
195
196static inline void uart401_kick(int dev)
197{
198}
199
200static inline int uart401_buffer_status(int dev)
201{
202 return 0;
203}
204
205#define MIDI_SYNTH_NAME "MPU-401 UART"
206#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
207#include "midi_synth.h"
208
209static const struct midi_operations uart401_operations =
210{
211 .owner = THIS_MODULE,
212 .info = {"MPU-401 (UART) MIDI", 0, 0, SNDCARD_MPU401},
213 .converter = &std_midi_synth,
214 .in_info = {0},
215 .open = uart401_open,
216 .close = uart401_close,
217 .outputc = uart401_out,
218 .start_read = uart401_start_read,
219 .end_read = uart401_end_read,
220 .kick = uart401_kick,
221 .buffer_status = uart401_buffer_status,
222};
223
224static void enter_uart_mode(struct uart401_devc *devc)
225{
226 int ok, timeout;
227 unsigned long flags;
228
229 spin_lock_irqsave(&devc->lock,flags);
230 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
231
232 devc->input_byte = 0;
233 uart401_cmd(devc, UART_MODE_ON);
234
235 ok = 0;
236 for (timeout = 50000; timeout > 0 && !ok; timeout--)
237 if (devc->input_byte == MPU_ACK)
238 ok = 1;
239 else if (input_avail(devc))
240 if (uart401_read(devc) == MPU_ACK)
241 ok = 1;
242
243 spin_unlock_irqrestore(&devc->lock,flags);
244}
245
246static int reset_uart401(struct uart401_devc *devc)
247{
248 int ok, timeout, n;
249
250 /*
251 * Send the RESET command. Try again if no success at the first time.
252 */
253
254 ok = 0;
255
256 for (n = 0; n < 2 && !ok; n++)
257 {
258 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
259 devc->input_byte = 0;
260 uart401_cmd(devc, MPU_RESET);
261
262 /*
263 * Wait at least 25 msec. This method is not accurate so let's make the
264 * loop bit longer. Cannot sleep since this is called during boot.
265 */
266
267 for (timeout = 50000; timeout > 0 && !ok; timeout--)
268 {
269 if (devc->input_byte == MPU_ACK) /* Interrupt */
270 ok = 1;
271 else if (input_avail(devc))
272 {
273 if (uart401_read(devc) == MPU_ACK)
274 ok = 1;
275 }
276 }
277 }
278
279 /* Flush input before enabling interrupts */
280 if (ok)
281 uart401_input_loop(devc);
282 else
283 DDB(printk("Reset UART401 failed - No hardware detected.\n"));
284
285 return ok;
286}
287
288int probe_uart401(struct address_info *hw_config, struct module *owner)
289{
290 struct uart401_devc *devc;
291 char *name = "MPU-401 (UART) MIDI";
292 int ok = 0;
293 unsigned long flags;
294
295 DDB(printk("Entered probe_uart401()\n"));
296
297 /* Default to "not found" */
298 hw_config->slots[4] = -1;
299
300 if (!request_region(hw_config->io_base, 4, "MPU-401 UART")) {
301 printk(KERN_INFO "uart401: could not request_region(%d, 4)\n", hw_config->io_base);
302 return 0;
303 }
304
305 devc = kmalloc(sizeof(struct uart401_devc), GFP_KERNEL);
306 if (!devc) {
307 printk(KERN_WARNING "uart401: Can't allocate memory\n");
308 goto cleanup_region;
309 }
310
311 devc->base = hw_config->io_base;
312 devc->irq = hw_config->irq;
313 devc->osp = hw_config->osp;
314 devc->midi_input_intr = NULL;
315 devc->opened = 0;
316 devc->input_byte = 0;
317 devc->my_dev = 0;
318 devc->share_irq = 0;
319 spin_lock_init(&devc->lock);
320
321 spin_lock_irqsave(&devc->lock,flags);
322 ok = reset_uart401(devc);
323 spin_unlock_irqrestore(&devc->lock,flags);
324
325 if (!ok)
326 goto cleanup_devc;
327
328 if (hw_config->name)
329 name = hw_config->name;
330
331 if (devc->irq < 0) {
332 devc->share_irq = 1;
333 devc->irq *= -1;
334 } else
335 devc->share_irq = 0;
336
337 if (!devc->share_irq)
338 if (request_irq(devc->irq, uart401intr, 0, "MPU-401 UART", devc) < 0) {
339 printk(KERN_WARNING "uart401: Failed to allocate IRQ%d\n", devc->irq);
340 devc->share_irq = 1;
341 }
342 devc->my_dev = sound_alloc_mididev();
343 enter_uart_mode(devc);
344
345 if (devc->my_dev == -1) {
346 printk(KERN_INFO "uart401: Too many midi devices detected\n");
347 goto cleanup_irq;
348 }
349 conf_printf(name, hw_config);
350 midi_devs[devc->my_dev] = kmemdup(&uart401_operations,
351 sizeof(struct midi_operations),
352 GFP_KERNEL);
353 if (!midi_devs[devc->my_dev]) {
354 printk(KERN_ERR "uart401: Failed to allocate memory\n");
355 goto cleanup_unload_mididev;
356 }
357
358 if (owner)
359 midi_devs[devc->my_dev]->owner = owner;
360
361 midi_devs[devc->my_dev]->devc = devc;
362 midi_devs[devc->my_dev]->converter = kmemdup(&std_midi_synth,
363 sizeof(struct synth_operations),
364 GFP_KERNEL);
365
366 if (!midi_devs[devc->my_dev]->converter) {
367 printk(KERN_WARNING "uart401: Failed to allocate memory\n");
368 goto cleanup_midi_devs;
369 }
370 strcpy(midi_devs[devc->my_dev]->info.name, name);
371 midi_devs[devc->my_dev]->converter->id = "UART401";
372 midi_devs[devc->my_dev]->converter->midi_dev = devc->my_dev;
373
374 if (owner)
375 midi_devs[devc->my_dev]->converter->owner = owner;
376
377 hw_config->slots[4] = devc->my_dev;
378 sequencer_init();
379 devc->opened = 0;
380 return 1;
381cleanup_midi_devs:
382 kfree(midi_devs[devc->my_dev]);
383cleanup_unload_mididev:
384 sound_unload_mididev(devc->my_dev);
385cleanup_irq:
386 if (!devc->share_irq)
387 free_irq(devc->irq, devc);
388cleanup_devc:
389 kfree(devc);
390cleanup_region:
391 release_region(hw_config->io_base, 4);
392 return 0;
393}
394
395void unload_uart401(struct address_info *hw_config)
396{
397 struct uart401_devc *devc;
398 int n=hw_config->slots[4];
399
400 /* Not set up */
401 if(n==-1 || midi_devs[n]==NULL)
402 return;
403
404 /* Not allocated (erm ??) */
405
406 devc = midi_devs[hw_config->slots[4]]->devc;
407 if (devc == NULL)
408 return;
409
410 reset_uart401(devc);
411 release_region(hw_config->io_base, 4);
412
413 if (!devc->share_irq)
414 free_irq(devc->irq, devc);
415 kfree(midi_devs[devc->my_dev]->converter);
416 kfree(midi_devs[devc->my_dev]);
417 kfree(devc);
418
419 /* This kills midi_devs[x] */
420 sound_unload_mididev(hw_config->slots[4]);
421}
422
423EXPORT_SYMBOL(probe_uart401);
424EXPORT_SYMBOL(unload_uart401);
425EXPORT_SYMBOL(uart401intr);
426
427static struct address_info cfg_mpu;
428
429static int io = -1;
430static int irq = -1;
431
432module_param_hw(io, int, ioport, 0444);
433module_param_hw(irq, int, irq, 0444);
434
435
436static int __init init_uart401(void)
437{
438 cfg_mpu.irq = irq;
439 cfg_mpu.io_base = io;
440
441 /* Can be loaded either for module use or to provide functions
442 to others */
443 if (cfg_mpu.io_base != -1 && cfg_mpu.irq != -1) {
444 printk(KERN_INFO "MPU-401 UART driver Copyright (C) Hannu Savolainen 1993-1997");
445 if (!probe_uart401(&cfg_mpu, THIS_MODULE))
446 return -ENODEV;
447 }
448
449 return 0;
450}
451
452static void __exit cleanup_uart401(void)
453{
454 if (cfg_mpu.io_base != -1 && cfg_mpu.irq != -1)
455 unload_uart401(&cfg_mpu);
456}
457
458module_init(init_uart401);
459module_exit(cleanup_uart401);
460
461#ifndef MODULE
462static int __init setup_uart401(char *str)
463{
464 /* io, irq */
465 int ints[3];
466
467 str = get_options(str, ARRAY_SIZE(ints), ints);
468
469 io = ints[1];
470 irq = ints[2];
471
472 return 1;
473}
474
475__setup("uart401=", setup_uart401);
476#endif
477MODULE_LICENSE("GPL");
diff --git a/sound/oss/uart6850.c b/sound/oss/uart6850.c
deleted file mode 100644
index eda32d7eddbd..000000000000
--- a/sound/oss/uart6850.c
+++ /dev/null
@@ -1,361 +0,0 @@
1/*
2 * sound/oss/uart6850.c
3 *
4 *
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 * Extended by Alan Cox for Red Hat Software. Now a loadable MIDI driver.
11 * 28/4/97 - (C) Copyright Alan Cox. Released under the GPL version 2.
12 *
13 * Alan Cox: Updated for new modular code. Removed snd_* irq handling. Now
14 * uses native linux resources
15 * Christoph Hellwig: Adapted to module_init/module_exit
16 * Jeff Garzik: Made it work again, in theory
17 * FIXME: If the request_irq() succeeds, the probe succeeds. Ug.
18 *
19 * Status: Testing required (no shit -jgarzik)
20 *
21 *
22 */
23
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/module.h>
27#include <linux/spinlock.h>
28/* Mon Nov 22 22:38:35 MET 1993 marco@driq.home.usn.nl:
29 * added 6850 support, used with COVOX SoundMaster II and custom cards.
30 */
31
32#include "sound_config.h"
33
34static int uart6850_base = 0x330;
35
36static int *uart6850_osp;
37
38#define DATAPORT (uart6850_base)
39#define COMDPORT (uart6850_base+1)
40#define STATPORT (uart6850_base+1)
41
42static int uart6850_status(void)
43{
44 return inb(STATPORT);
45}
46
47#define input_avail() (uart6850_status()&INPUT_AVAIL)
48#define output_ready() (uart6850_status()&OUTPUT_READY)
49
50static void uart6850_cmd(unsigned char cmd)
51{
52 outb(cmd, COMDPORT);
53}
54
55static int uart6850_read(void)
56{
57 return inb(DATAPORT);
58}
59
60static void uart6850_write(unsigned char byte)
61{
62 outb(byte, DATAPORT);
63}
64
65#define OUTPUT_READY 0x02 /* Mask for data ready Bit */
66#define INPUT_AVAIL 0x01 /* Mask for Data Send Ready Bit */
67
68#define UART_RESET 0x95
69#define UART_MODE_ON 0x03
70
71static int uart6850_opened;
72static int uart6850_irq;
73static int uart6850_detected;
74static int my_dev;
75static DEFINE_SPINLOCK(lock);
76
77static void (*midi_input_intr) (int dev, unsigned char data);
78static void poll_uart6850(unsigned long dummy);
79
80
81static DEFINE_TIMER(uart6850_timer, poll_uart6850, 0, 0);
82
83static void uart6850_input_loop(void)
84{
85 int count = 10;
86
87 while (count)
88 {
89 /*
90 * Not timed out
91 */
92 if (input_avail())
93 {
94 unsigned char c = uart6850_read();
95 count = 100;
96 if (uart6850_opened & OPEN_READ)
97 midi_input_intr(my_dev, c);
98 }
99 else
100 {
101 while (!input_avail() && count)
102 count--;
103 }
104 }
105}
106
107static irqreturn_t m6850intr(int irq, void *dev_id)
108{
109 if (input_avail())
110 uart6850_input_loop();
111 return IRQ_HANDLED;
112}
113
114/*
115 * It looks like there is no input interrupts in the UART mode. Let's try
116 * polling.
117 */
118
119static void poll_uart6850(unsigned long dummy)
120{
121 unsigned long flags;
122
123 if (!(uart6850_opened & OPEN_READ))
124 return; /* Device has been closed */
125
126 spin_lock_irqsave(&lock,flags);
127 if (input_avail())
128 uart6850_input_loop();
129
130 uart6850_timer.expires = 1 + jiffies;
131 add_timer(&uart6850_timer);
132
133 /*
134 * Come back later
135 */
136
137 spin_unlock_irqrestore(&lock,flags);
138}
139
140static int uart6850_open(int dev, int mode,
141 void (*input) (int dev, unsigned char data),
142 void (*output) (int dev)
143)
144{
145 if (uart6850_opened)
146 {
147/* printk("Midi6850: Midi busy\n");*/
148 return -EBUSY;
149 }
150
151 uart6850_cmd(UART_RESET);
152 uart6850_input_loop();
153 midi_input_intr = input;
154 uart6850_opened = mode;
155 poll_uart6850(0); /*
156 * Enable input polling
157 */
158
159 return 0;
160}
161
162static void uart6850_close(int dev)
163{
164 uart6850_cmd(UART_MODE_ON);
165 del_timer(&uart6850_timer);
166 uart6850_opened = 0;
167}
168
169static int uart6850_out(int dev, unsigned char midi_byte)
170{
171 int timeout;
172 unsigned long flags;
173
174 /*
175 * Test for input since pending input seems to block the output.
176 */
177
178 spin_lock_irqsave(&lock,flags);
179
180 if (input_avail())
181 uart6850_input_loop();
182
183 spin_unlock_irqrestore(&lock,flags);
184
185 /*
186 * Sometimes it takes about 13000 loops before the output becomes ready
187 * (After reset). Normally it takes just about 10 loops.
188 */
189
190 for (timeout = 30000; timeout > 0 && !output_ready(); timeout--); /*
191 * Wait
192 */
193 if (!output_ready())
194 {
195 printk(KERN_WARNING "Midi6850: Timeout\n");
196 return 0;
197 }
198 uart6850_write(midi_byte);
199 return 1;
200}
201
202static inline int uart6850_command(int dev, unsigned char *midi_byte)
203{
204 return 1;
205}
206
207static inline int uart6850_start_read(int dev)
208{
209 return 0;
210}
211
212static inline int uart6850_end_read(int dev)
213{
214 return 0;
215}
216
217static inline void uart6850_kick(int dev)
218{
219}
220
221static inline int uart6850_buffer_status(int dev)
222{
223 return 0; /*
224 * No data in buffers
225 */
226}
227
228#define MIDI_SYNTH_NAME "6850 UART Midi"
229#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
230#include "midi_synth.h"
231
232static struct midi_operations uart6850_operations =
233{
234 .owner = THIS_MODULE,
235 .info = {"6850 UART", 0, 0, SNDCARD_UART6850},
236 .converter = &std_midi_synth,
237 .in_info = {0},
238 .open = uart6850_open,
239 .close = uart6850_close,
240 .outputc = uart6850_out,
241 .start_read = uart6850_start_read,
242 .end_read = uart6850_end_read,
243 .kick = uart6850_kick,
244 .command = uart6850_command,
245 .buffer_status = uart6850_buffer_status
246};
247
248
249static void __init attach_uart6850(struct address_info *hw_config)
250{
251 int ok, timeout;
252 unsigned long flags;
253
254 if (!uart6850_detected)
255 return;
256
257 if ((my_dev = sound_alloc_mididev()) == -1)
258 {
259 printk(KERN_INFO "uart6850: Too many midi devices detected\n");
260 return;
261 }
262 uart6850_base = hw_config->io_base;
263 uart6850_osp = hw_config->osp;
264 uart6850_irq = hw_config->irq;
265
266 spin_lock_irqsave(&lock,flags);
267
268 for (timeout = 30000; timeout > 0 && !output_ready(); timeout--); /*
269 * Wait
270 */
271 uart6850_cmd(UART_MODE_ON);
272 ok = 1;
273 spin_unlock_irqrestore(&lock,flags);
274
275 conf_printf("6850 Midi Interface", hw_config);
276
277 std_midi_synth.midi_dev = my_dev;
278 hw_config->slots[4] = my_dev;
279 midi_devs[my_dev] = &uart6850_operations;
280 sequencer_init();
281}
282
283static inline int reset_uart6850(void)
284{
285 uart6850_read();
286 return 1; /*
287 * OK
288 */
289}
290
291static int __init probe_uart6850(struct address_info *hw_config)
292{
293 int ok;
294
295 uart6850_osp = hw_config->osp;
296 uart6850_base = hw_config->io_base;
297 uart6850_irq = hw_config->irq;
298
299 if (request_irq(uart6850_irq, m6850intr, 0, "MIDI6850", NULL) < 0)
300 return 0;
301
302 ok = reset_uart6850();
303 uart6850_detected = ok;
304 return ok;
305}
306
307static void __exit unload_uart6850(struct address_info *hw_config)
308{
309 free_irq(hw_config->irq, NULL);
310 sound_unload_mididev(hw_config->slots[4]);
311}
312
313static struct address_info cfg_mpu;
314
315static int __initdata io = -1;
316static int __initdata irq = -1;
317
318module_param_hw(io, int, ioport, 0);
319module_param_hw(irq, int, irq, 0);
320
321static int __init init_uart6850(void)
322{
323 cfg_mpu.io_base = io;
324 cfg_mpu.irq = irq;
325
326 if (cfg_mpu.io_base == -1 || cfg_mpu.irq == -1) {
327 printk(KERN_INFO "uart6850: irq and io must be set.\n");
328 return -EINVAL;
329 }
330
331 if (probe_uart6850(&cfg_mpu))
332 return -ENODEV;
333 attach_uart6850(&cfg_mpu);
334
335 return 0;
336}
337
338static void __exit cleanup_uart6850(void)
339{
340 unload_uart6850(&cfg_mpu);
341}
342
343module_init(init_uart6850);
344module_exit(cleanup_uart6850);
345
346#ifndef MODULE
347static int __init setup_uart6850(char *str)
348{
349 /* io, irq */
350 int ints[3];
351
352 str = get_options(str, ARRAY_SIZE(ints), ints);
353
354 io = ints[1];
355 irq = ints[2];
356
357 return 1;
358}
359__setup("uart6850=", setup_uart6850);
360#endif
361MODULE_LICENSE("GPL");
diff --git a/sound/oss/ulaw.h b/sound/oss/ulaw.h
deleted file mode 100644
index 0ff8c0a3bda0..000000000000
--- a/sound/oss/ulaw.h
+++ /dev/null
@@ -1,69 +0,0 @@
1static unsigned char ulaw_dsp[] = {
2 3, 7, 11, 15, 19, 23, 27, 31,
3 35, 39, 43, 47, 51, 55, 59, 63,
4 66, 68, 70, 72, 74, 76, 78, 80,
5 82, 84, 86, 88, 90, 92, 94, 96,
6 98, 99, 100, 101, 102, 103, 104, 105,
7 106, 107, 108, 109, 110, 111, 112, 113,
8 113, 114, 114, 115, 115, 116, 116, 117,
9 117, 118, 118, 119, 119, 120, 120, 121,
10 121, 121, 122, 122, 122, 122, 123, 123,
11 123, 123, 124, 124, 124, 124, 125, 125,
12 125, 125, 125, 125, 126, 126, 126, 126,
13 126, 126, 126, 126, 127, 127, 127, 127,
14 127, 127, 127, 127, 127, 127, 127, 127,
15 128, 128, 128, 128, 128, 128, 128, 128,
16 128, 128, 128, 128, 128, 128, 128, 128,
17 128, 128, 128, 128, 128, 128, 128, 128,
18 253, 249, 245, 241, 237, 233, 229, 225,
19 221, 217, 213, 209, 205, 201, 197, 193,
20 190, 188, 186, 184, 182, 180, 178, 176,
21 174, 172, 170, 168, 166, 164, 162, 160,
22 158, 157, 156, 155, 154, 153, 152, 151,
23 150, 149, 148, 147, 146, 145, 144, 143,
24 143, 142, 142, 141, 141, 140, 140, 139,
25 139, 138, 138, 137, 137, 136, 136, 135,
26 135, 135, 134, 134, 134, 134, 133, 133,
27 133, 133, 132, 132, 132, 132, 131, 131,
28 131, 131, 131, 131, 130, 130, 130, 130,
29 130, 130, 130, 130, 129, 129, 129, 129,
30 129, 129, 129, 129, 129, 129, 129, 129,
31 128, 128, 128, 128, 128, 128, 128, 128,
32 128, 128, 128, 128, 128, 128, 128, 128,
33 128, 128, 128, 128, 128, 128, 128, 128,
34};
35
36static unsigned char dsp_ulaw[] = {
37 0, 0, 0, 0, 0, 1, 1, 1,
38 1, 2, 2, 2, 2, 3, 3, 3,
39 3, 4, 4, 4, 4, 5, 5, 5,
40 5, 6, 6, 6, 6, 7, 7, 7,
41 7, 8, 8, 8, 8, 9, 9, 9,
42 9, 10, 10, 10, 10, 11, 11, 11,
43 11, 12, 12, 12, 12, 13, 13, 13,
44 13, 14, 14, 14, 14, 15, 15, 15,
45 15, 16, 16, 17, 17, 18, 18, 19,
46 19, 20, 20, 21, 21, 22, 22, 23,
47 23, 24, 24, 25, 25, 26, 26, 27,
48 27, 28, 28, 29, 29, 30, 30, 31,
49 31, 32, 33, 34, 35, 36, 37, 38,
50 39, 40, 41, 42, 43, 44, 45, 46,
51 47, 49, 51, 53, 55, 57, 59, 61,
52 63, 66, 70, 74, 78, 84, 92, 104,
53 254, 231, 219, 211, 205, 201, 197, 193,
54 190, 188, 186, 184, 182, 180, 178, 176,
55 175, 174, 173, 172, 171, 170, 169, 168,
56 167, 166, 165, 164, 163, 162, 161, 160,
57 159, 159, 158, 158, 157, 157, 156, 156,
58 155, 155, 154, 154, 153, 153, 152, 152,
59 151, 151, 150, 150, 149, 149, 148, 148,
60 147, 147, 146, 146, 145, 145, 144, 144,
61 143, 143, 143, 143, 142, 142, 142, 142,
62 141, 141, 141, 141, 140, 140, 140, 140,
63 139, 139, 139, 139, 138, 138, 138, 138,
64 137, 137, 137, 137, 136, 136, 136, 136,
65 135, 135, 135, 135, 134, 134, 134, 134,
66 133, 133, 133, 133, 132, 132, 132, 132,
67 131, 131, 131, 131, 130, 130, 130, 130,
68 129, 129, 129, 129, 128, 128, 128, 128,
69};
diff --git a/sound/oss/v_midi.c b/sound/oss/v_midi.c
deleted file mode 100644
index fc0ba276cc8f..000000000000
--- a/sound/oss/v_midi.c
+++ /dev/null
@@ -1,290 +0,0 @@
1/*
2 * sound/oss/v_midi.c
3 *
4 * The low level driver for the Sound Blaster DS chips.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1996
8 *
9 * USS/Lite for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 * ??
13 *
14 * Changes
15 * Alan Cox Modularisation, changed memory allocations
16 * Christoph Hellwig Adapted to module_init/module_exit
17 *
18 * Status
19 * Untested
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/spinlock.h>
26#include "sound_config.h"
27
28#include "v_midi.h"
29
30static vmidi_devc *v_devc[2] = { NULL, NULL};
31static int midi1,midi2;
32static void *midi_mem = NULL;
33
34/*
35 * The DSP channel can be used either for input or output. Variable
36 * 'sb_irq_mode' will be set when the program calls read or write first time
37 * after open. Current version doesn't support mode changes without closing
38 * and reopening the device. Support for this feature may be implemented in a
39 * future version of this driver.
40 */
41
42
43static int v_midi_open (int dev, int mode,
44 void (*input) (int dev, unsigned char data),
45 void (*output) (int dev)
46)
47{
48 vmidi_devc *devc = midi_devs[dev]->devc;
49 unsigned long flags;
50
51 if (devc == NULL)
52 return -ENXIO;
53
54 spin_lock_irqsave(&devc->lock,flags);
55 if (devc->opened)
56 {
57 spin_unlock_irqrestore(&devc->lock,flags);
58 return -EBUSY;
59 }
60 devc->opened = 1;
61 spin_unlock_irqrestore(&devc->lock,flags);
62
63 devc->intr_active = 1;
64
65 if (mode & OPEN_READ)
66 {
67 devc->input_opened = 1;
68 devc->midi_input_intr = input;
69 }
70
71 return 0;
72}
73
74static void v_midi_close (int dev)
75{
76 vmidi_devc *devc = midi_devs[dev]->devc;
77 unsigned long flags;
78
79 if (devc == NULL)
80 return;
81
82 spin_lock_irqsave(&devc->lock,flags);
83 devc->intr_active = 0;
84 devc->input_opened = 0;
85 devc->opened = 0;
86 spin_unlock_irqrestore(&devc->lock,flags);
87}
88
89static int v_midi_out (int dev, unsigned char midi_byte)
90{
91 vmidi_devc *devc = midi_devs[dev]->devc;
92 vmidi_devc *pdevc;
93
94 if (devc == NULL)
95 return -ENXIO;
96
97 pdevc = midi_devs[devc->pair_mididev]->devc;
98 if (pdevc->input_opened > 0){
99 if (MIDIbuf_avail(pdevc->my_mididev) > 500)
100 return 0;
101 pdevc->midi_input_intr (pdevc->my_mididev, midi_byte);
102 }
103 return 1;
104}
105
106static inline int v_midi_start_read (int dev)
107{
108 return 0;
109}
110
111static int v_midi_end_read (int dev)
112{
113 vmidi_devc *devc = midi_devs[dev]->devc;
114 if (devc == NULL)
115 return -ENXIO;
116
117 devc->intr_active = 0;
118 return 0;
119}
120
121/* why -EPERM and not -EINVAL?? */
122
123static inline int v_midi_ioctl (int dev, unsigned cmd, void __user *arg)
124{
125 return -EPERM;
126}
127
128
129#define MIDI_SYNTH_NAME "Loopback MIDI"
130#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
131
132#include "midi_synth.h"
133
134static struct midi_operations v_midi_operations =
135{
136 .owner = THIS_MODULE,
137 .info = {"Loopback MIDI Port 1", 0, 0, SNDCARD_VMIDI},
138 .converter = &std_midi_synth,
139 .in_info = {0},
140 .open = v_midi_open,
141 .close = v_midi_close,
142 .ioctl = v_midi_ioctl,
143 .outputc = v_midi_out,
144 .start_read = v_midi_start_read,
145 .end_read = v_midi_end_read,
146};
147
148static struct midi_operations v_midi_operations2 =
149{
150 .owner = THIS_MODULE,
151 .info = {"Loopback MIDI Port 2", 0, 0, SNDCARD_VMIDI},
152 .converter = &std_midi_synth,
153 .in_info = {0},
154 .open = v_midi_open,
155 .close = v_midi_close,
156 .ioctl = v_midi_ioctl,
157 .outputc = v_midi_out,
158 .start_read = v_midi_start_read,
159 .end_read = v_midi_end_read,
160};
161
162/*
163 * We kmalloc just one of these - it makes life simpler and the code
164 * cleaner and the memory handling far more efficient
165 */
166
167struct vmidi_memory
168{
169 /* Must be first */
170 struct midi_operations m_ops[2];
171 struct synth_operations s_ops[2];
172 struct vmidi_devc v_ops[2];
173};
174
175static void __init attach_v_midi (struct address_info *hw_config)
176{
177 struct vmidi_memory *m;
178 /* printk("Attaching v_midi device.....\n"); */
179
180 midi1 = sound_alloc_mididev();
181 if (midi1 == -1)
182 {
183 printk(KERN_ERR "v_midi: Too many midi devices detected\n");
184 return;
185 }
186
187 m = kmalloc(sizeof(struct vmidi_memory), GFP_KERNEL);
188 if (m == NULL)
189 {
190 printk(KERN_WARNING "Loopback MIDI: Failed to allocate memory\n");
191 sound_unload_mididev(midi1);
192 return;
193 }
194
195 midi_mem = m;
196
197 midi_devs[midi1] = &m->m_ops[0];
198
199
200 midi2 = sound_alloc_mididev();
201 if (midi2 == -1)
202 {
203 printk (KERN_ERR "v_midi: Too many midi devices detected\n");
204 kfree(m);
205 sound_unload_mididev(midi1);
206 return;
207 }
208
209 midi_devs[midi2] = &m->m_ops[1];
210
211 /* printk("VMIDI1: %d VMIDI2: %d\n",midi1,midi2); */
212
213 /* for MIDI-1 */
214 v_devc[0] = &m->v_ops[0];
215 memcpy ((char *) midi_devs[midi1], (char *) &v_midi_operations,
216 sizeof (struct midi_operations));
217
218 v_devc[0]->my_mididev = midi1;
219 v_devc[0]->pair_mididev = midi2;
220 v_devc[0]->opened = v_devc[0]->input_opened = 0;
221 v_devc[0]->intr_active = 0;
222 v_devc[0]->midi_input_intr = NULL;
223 spin_lock_init(&v_devc[0]->lock);
224
225 midi_devs[midi1]->devc = v_devc[0];
226
227 midi_devs[midi1]->converter = &m->s_ops[0];
228 std_midi_synth.midi_dev = midi1;
229 memcpy ((char *) midi_devs[midi1]->converter, (char *) &std_midi_synth,
230 sizeof (struct synth_operations));
231 midi_devs[midi1]->converter->id = "V_MIDI 1";
232
233 /* for MIDI-2 */
234 v_devc[1] = &m->v_ops[1];
235
236 memcpy ((char *) midi_devs[midi2], (char *) &v_midi_operations2,
237 sizeof (struct midi_operations));
238
239 v_devc[1]->my_mididev = midi2;
240 v_devc[1]->pair_mididev = midi1;
241 v_devc[1]->opened = v_devc[1]->input_opened = 0;
242 v_devc[1]->intr_active = 0;
243 v_devc[1]->midi_input_intr = NULL;
244 spin_lock_init(&v_devc[1]->lock);
245
246 midi_devs[midi2]->devc = v_devc[1];
247 midi_devs[midi2]->converter = &m->s_ops[1];
248
249 std_midi_synth.midi_dev = midi2;
250 memcpy ((char *) midi_devs[midi2]->converter, (char *) &std_midi_synth,
251 sizeof (struct synth_operations));
252 midi_devs[midi2]->converter->id = "V_MIDI 2";
253
254 sequencer_init();
255 /* printk("Attached v_midi device\n"); */
256}
257
258static inline int __init probe_v_midi(struct address_info *hw_config)
259{
260 return(1); /* always OK */
261}
262
263
264static void __exit unload_v_midi(struct address_info *hw_config)
265{
266 sound_unload_mididev(midi1);
267 sound_unload_mididev(midi2);
268 kfree(midi_mem);
269}
270
271static struct address_info cfg; /* dummy */
272
273static int __init init_vmidi(void)
274{
275 printk("MIDI Loopback device driver\n");
276 if (!probe_v_midi(&cfg))
277 return -ENODEV;
278 attach_v_midi(&cfg);
279
280 return 0;
281}
282
283static void __exit cleanup_vmidi(void)
284{
285 unload_v_midi(&cfg);
286}
287
288module_init(init_vmidi);
289module_exit(cleanup_vmidi);
290MODULE_LICENSE("GPL");
diff --git a/sound/oss/v_midi.h b/sound/oss/v_midi.h
deleted file mode 100644
index 08e2185ee816..000000000000
--- a/sound/oss/v_midi.h
+++ /dev/null
@@ -1,14 +0,0 @@
1typedef struct vmidi_devc {
2 int dev;
3
4 /* State variables */
5 int opened;
6 spinlock_t lock;
7
8 /* MIDI fields */
9 int my_mididev;
10 int pair_mididev;
11 int input_opened;
12 int intr_active;
13 void (*midi_input_intr) (int dev, unsigned char data);
14 } vmidi_devc;
diff --git a/sound/oss/vidc.c b/sound/oss/vidc.c
deleted file mode 100644
index 92ca5bee1860..000000000000
--- a/sound/oss/vidc.c
+++ /dev/null
@@ -1,557 +0,0 @@
1/*
2 * linux/drivers/sound/vidc.c
3 *
4 * Copyright (C) 1997-2000 by Russell King <rmk@arm.linux.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * VIDC20 audio driver.
11 *
12 * The VIDC20 sound hardware consists of the VIDC20 itself, a DAC and a DMA
13 * engine. The DMA transfers fixed-format (16-bit little-endian linear)
14 * samples to the VIDC20, which then transfers this data serially to the
15 * DACs. The samplerate is controlled by the VIDC.
16 *
17 * We currently support a mixer device, but it is currently non-functional.
18 */
19
20#include <linux/gfp.h>
21#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/interrupt.h>
25
26#include <mach/hardware.h>
27#include <asm/dma.h>
28#include <asm/io.h>
29#include <asm/hardware/iomd.h>
30#include <asm/irq.h>
31
32#include "sound_config.h"
33#include "vidc.h"
34
35#ifndef _SIOC_TYPE
36#define _SIOC_TYPE(x) _IOC_TYPE(x)
37#endif
38#ifndef _SIOC_NR
39#define _SIOC_NR(x) _IOC_NR(x)
40#endif
41
42#define VIDC_SOUND_CLOCK (250000)
43#define VIDC_SOUND_CLOCK_EXT (176400)
44
45/*
46 * When using SERIAL SOUND mode (external DAC), the number of physical
47 * channels is fixed at 2.
48 */
49static int vidc_busy;
50static int vidc_adev;
51static int vidc_audio_rate;
52static char vidc_audio_format;
53static char vidc_audio_channels;
54
55static unsigned char vidc_level_l[SOUND_MIXER_NRDEVICES] = {
56 85, /* master */
57 50, /* bass */
58 50, /* treble */
59 0, /* synth */
60 75, /* pcm */
61 0, /* speaker */
62 100, /* ext line */
63 0, /* mic */
64 100, /* CD */
65 0,
66};
67
68static unsigned char vidc_level_r[SOUND_MIXER_NRDEVICES] = {
69 85, /* master */
70 50, /* bass */
71 50, /* treble */
72 0, /* synth */
73 75, /* pcm */
74 0, /* speaker */
75 100, /* ext line */
76 0, /* mic */
77 100, /* CD */
78 0,
79};
80
81static unsigned int vidc_audio_volume_l; /* left PCM vol, 0 - 65536 */
82static unsigned int vidc_audio_volume_r; /* right PCM vol, 0 - 65536 */
83
84extern void vidc_update_filler(int bits, int channels);
85extern int softoss_dev;
86
87static void
88vidc_mixer_set(int mdev, unsigned int level)
89{
90 unsigned int lev_l = level & 0x007f;
91 unsigned int lev_r = (level & 0x7f00) >> 8;
92 unsigned int mlev_l, mlev_r;
93
94 if (lev_l > 100)
95 lev_l = 100;
96 if (lev_r > 100)
97 lev_r = 100;
98
99#define SCALE(lev,master) ((lev) * (master) * 65536 / 10000)
100
101 mlev_l = vidc_level_l[SOUND_MIXER_VOLUME];
102 mlev_r = vidc_level_r[SOUND_MIXER_VOLUME];
103
104 switch (mdev) {
105 case SOUND_MIXER_VOLUME:
106 case SOUND_MIXER_PCM:
107 vidc_level_l[mdev] = lev_l;
108 vidc_level_r[mdev] = lev_r;
109
110 vidc_audio_volume_l = SCALE(lev_l, mlev_l);
111 vidc_audio_volume_r = SCALE(lev_r, mlev_r);
112/*printk("VIDC: PCM vol %05X %05X\n", vidc_audio_volume_l, vidc_audio_volume_r);*/
113 break;
114 }
115#undef SCALE
116}
117
118static int vidc_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
119{
120 unsigned int val;
121 unsigned int mdev;
122
123 if (_SIOC_TYPE(cmd) != 'M')
124 return -EINVAL;
125
126 mdev = _SIOC_NR(cmd);
127
128 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
129 if (get_user(val, (unsigned int __user *)arg))
130 return -EFAULT;
131
132 if (mdev < SOUND_MIXER_NRDEVICES)
133 vidc_mixer_set(mdev, val);
134 else
135 return -EINVAL;
136 }
137
138 /*
139 * Return parameters
140 */
141 switch (mdev) {
142 case SOUND_MIXER_RECSRC:
143 val = 0;
144 break;
145
146 case SOUND_MIXER_DEVMASK:
147 val = SOUND_MASK_VOLUME | SOUND_MASK_PCM | SOUND_MASK_SYNTH;
148 break;
149
150 case SOUND_MIXER_STEREODEVS:
151 val = SOUND_MASK_VOLUME | SOUND_MASK_PCM | SOUND_MASK_SYNTH;
152 break;
153
154 case SOUND_MIXER_RECMASK:
155 val = 0;
156 break;
157
158 case SOUND_MIXER_CAPS:
159 val = 0;
160 break;
161
162 default:
163 if (mdev < SOUND_MIXER_NRDEVICES)
164 val = vidc_level_l[mdev] | vidc_level_r[mdev] << 8;
165 else
166 return -EINVAL;
167 }
168
169 return put_user(val, (unsigned int __user *)arg) ? -EFAULT : 0;
170}
171
172static unsigned int vidc_audio_set_format(int dev, unsigned int fmt)
173{
174 switch (fmt) {
175 default:
176 fmt = AFMT_S16_LE;
177 case AFMT_U8:
178 case AFMT_S8:
179 case AFMT_S16_LE:
180 vidc_audio_format = fmt;
181 vidc_update_filler(vidc_audio_format, vidc_audio_channels);
182 case AFMT_QUERY:
183 break;
184 }
185 return vidc_audio_format;
186}
187
188#define my_abs(i) ((i)<0 ? -(i) : (i))
189
190static int vidc_audio_set_speed(int dev, int rate)
191{
192 if (rate) {
193 unsigned int hwctrl, hwrate, hwrate_ext, rate_int, rate_ext;
194 unsigned int diff_int, diff_ext;
195 unsigned int newsize, new2size;
196
197 hwctrl = 0x00000003;
198
199 /* Using internal clock */
200 hwrate = (((VIDC_SOUND_CLOCK * 2) / rate) + 1) >> 1;
201 if (hwrate < 3)
202 hwrate = 3;
203 if (hwrate > 255)
204 hwrate = 255;
205
206 /* Using exernal clock */
207 hwrate_ext = (((VIDC_SOUND_CLOCK_EXT * 2) / rate) + 1) >> 1;
208 if (hwrate_ext < 3)
209 hwrate_ext = 3;
210 if (hwrate_ext > 255)
211 hwrate_ext = 255;
212
213 rate_int = VIDC_SOUND_CLOCK / hwrate;
214 rate_ext = VIDC_SOUND_CLOCK_EXT / hwrate_ext;
215
216 /* Chose between external and internal clock */
217 diff_int = my_abs(rate_ext-rate);
218 diff_ext = my_abs(rate_int-rate);
219 if (diff_ext < diff_int) {
220 /*printk("VIDC: external %d %d %d\n", rate, rate_ext, hwrate_ext);*/
221 hwrate=hwrate_ext;
222 hwctrl=0x00000002;
223 /* Allow roughly 0.4% tolerance */
224 if (diff_ext > (rate/256))
225 rate=rate_ext;
226 } else {
227 /*printk("VIDC: internal %d %d %d\n", rate, rate_int, hwrate);*/
228 hwctrl=0x00000003;
229 /* Allow roughly 0.4% tolerance */
230 if (diff_int > (rate/256))
231 rate=rate_int;
232 }
233
234 vidc_writel(0xb0000000 | (hwrate - 2));
235 vidc_writel(0xb1000000 | hwctrl);
236
237 newsize = (10000 / hwrate) & ~3;
238 if (newsize < 208)
239 newsize = 208;
240 if (newsize > 4096)
241 newsize = 4096;
242 for (new2size = 128; new2size < newsize; new2size <<= 1);
243 if (new2size - newsize > newsize - (new2size >> 1))
244 new2size >>= 1;
245 if (new2size > 4096) {
246 printk(KERN_ERR "VIDC: error: dma buffer (%d) %d > 4K\n",
247 newsize, new2size);
248 new2size = 4096;
249 }
250 /*printk("VIDC: dma size %d\n", new2size);*/
251 dma_bufsize = new2size;
252 vidc_audio_rate = rate;
253 }
254 return vidc_audio_rate;
255}
256
257static short vidc_audio_set_channels(int dev, short channels)
258{
259 switch (channels) {
260 default:
261 channels = 2;
262 case 1:
263 case 2:
264 vidc_audio_channels = channels;
265 vidc_update_filler(vidc_audio_format, vidc_audio_channels);
266 case 0:
267 break;
268 }
269 return vidc_audio_channels;
270}
271
272/*
273 * Open the device
274 */
275static int vidc_audio_open(int dev, int mode)
276{
277 /* This audio device does not have recording capability */
278 if (mode == OPEN_READ)
279 return -EPERM;
280
281 if (vidc_busy)
282 return -EBUSY;
283
284 vidc_busy = 1;
285 return 0;
286}
287
288/*
289 * Close the device
290 */
291static void vidc_audio_close(int dev)
292{
293 vidc_busy = 0;
294}
295
296/*
297 * Output a block via DMA to sound device.
298 *
299 * We just set the DMA start and count; the DMA interrupt routine
300 * will take care of formatting the samples (via the appropriate
301 * vidc_filler routine), and flag via vidc_audio_dma_interrupt when
302 * more data is required.
303 */
304static void
305vidc_audio_output_block(int dev, unsigned long buf, int total_count, int one)
306{
307 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
308 unsigned long flags;
309
310 local_irq_save(flags);
311 dma_start = buf - (unsigned long)dmap->raw_buf_phys + (unsigned long)dmap->raw_buf;
312 dma_count = total_count;
313 local_irq_restore(flags);
314}
315
316static void
317vidc_audio_start_input(int dev, unsigned long buf, int count, int intrflag)
318{
319}
320
321static int vidc_audio_prepare_for_input(int dev, int bsize, int bcount)
322{
323 return -EINVAL;
324}
325
326static irqreturn_t vidc_audio_dma_interrupt(void)
327{
328 DMAbuf_outputintr(vidc_adev, 1);
329 return IRQ_HANDLED;
330}
331
332/*
333 * Prepare for outputting samples.
334 *
335 * Each buffer that will be passed will be `bsize' bytes long,
336 * with a total of `bcount' buffers.
337 */
338static int vidc_audio_prepare_for_output(int dev, int bsize, int bcount)
339{
340 struct audio_operations *adev = audio_devs[dev];
341
342 dma_interrupt = NULL;
343 adev->dmap_out->flags |= DMA_NODMA;
344
345 return 0;
346}
347
348/*
349 * Stop our current operation.
350 */
351static void vidc_audio_reset(int dev)
352{
353 dma_interrupt = NULL;
354}
355
356static int vidc_audio_local_qlen(int dev)
357{
358 return /*dma_count !=*/ 0;
359}
360
361static void vidc_audio_trigger(int dev, int enable_bits)
362{
363 struct audio_operations *adev = audio_devs[dev];
364
365 if (enable_bits & PCM_ENABLE_OUTPUT) {
366 if (!(adev->dmap_out->flags & DMA_ACTIVE)) {
367 unsigned long flags;
368
369 local_irq_save(flags);
370
371 /* prevent recusion */
372 adev->dmap_out->flags |= DMA_ACTIVE;
373
374 dma_interrupt = vidc_audio_dma_interrupt;
375 vidc_sound_dma_irq(0, NULL);
376 iomd_writeb(DMA_CR_E | 0x10, IOMD_SD0CR);
377
378 local_irq_restore(flags);
379 }
380 }
381}
382
383static struct audio_driver vidc_audio_driver =
384{
385 .owner = THIS_MODULE,
386 .open = vidc_audio_open,
387 .close = vidc_audio_close,
388 .output_block = vidc_audio_output_block,
389 .start_input = vidc_audio_start_input,
390 .prepare_for_input = vidc_audio_prepare_for_input,
391 .prepare_for_output = vidc_audio_prepare_for_output,
392 .halt_io = vidc_audio_reset,
393 .local_qlen = vidc_audio_local_qlen,
394 .trigger = vidc_audio_trigger,
395 .set_speed = vidc_audio_set_speed,
396 .set_bits = vidc_audio_set_format,
397 .set_channels = vidc_audio_set_channels
398};
399
400static struct mixer_operations vidc_mixer_operations = {
401 .owner = THIS_MODULE,
402 .id = "VIDC",
403 .name = "VIDCsound",
404 .ioctl = vidc_mixer_ioctl
405};
406
407void vidc_update_filler(int format, int channels)
408{
409#define TYPE(fmt,ch) (((fmt)<<2) | ((ch)&3))
410
411 switch (TYPE(format, channels)) {
412 default:
413 case TYPE(AFMT_U8, 1):
414 vidc_filler = vidc_fill_1x8_u;
415 break;
416
417 case TYPE(AFMT_U8, 2):
418 vidc_filler = vidc_fill_2x8_u;
419 break;
420
421 case TYPE(AFMT_S8, 1):
422 vidc_filler = vidc_fill_1x8_s;
423 break;
424
425 case TYPE(AFMT_S8, 2):
426 vidc_filler = vidc_fill_2x8_s;
427 break;
428
429 case TYPE(AFMT_S16_LE, 1):
430 vidc_filler = vidc_fill_1x16_s;
431 break;
432
433 case TYPE(AFMT_S16_LE, 2):
434 vidc_filler = vidc_fill_2x16_s;
435 break;
436 }
437}
438
439static void __init attach_vidc(struct address_info *hw_config)
440{
441 char name[32];
442 int i, adev;
443
444 sprintf(name, "VIDC %d-bit sound", hw_config->card_subtype);
445 conf_printf(name, hw_config);
446 memset(dma_buf, 0, sizeof(dma_buf));
447
448 adev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, name,
449 &vidc_audio_driver, sizeof(vidc_audio_driver),
450 DMA_AUTOMODE, AFMT_U8 | AFMT_S8 | AFMT_S16_LE,
451 NULL, hw_config->dma, hw_config->dma2);
452
453 if (adev < 0)
454 goto audio_failed;
455
456 /*
457 * 1024 bytes => 64 buffers
458 */
459 audio_devs[adev]->min_fragment = 10;
460 audio_devs[adev]->mixer_dev = num_mixers;
461
462 audio_devs[adev]->mixer_dev =
463 sound_install_mixer(MIXER_DRIVER_VERSION,
464 name, &vidc_mixer_operations,
465 sizeof(vidc_mixer_operations), NULL);
466
467 if (audio_devs[adev]->mixer_dev < 0)
468 goto mixer_failed;
469
470 for (i = 0; i < 2; i++) {
471 dma_buf[i] = get_zeroed_page(GFP_KERNEL);
472 if (!dma_buf[i]) {
473 printk(KERN_ERR "%s: can't allocate required buffers\n",
474 name);
475 goto mem_failed;
476 }
477 dma_pbuf[i] = virt_to_phys((void *)dma_buf[i]);
478 }
479
480 if (sound_alloc_dma(hw_config->dma, hw_config->name)) {
481 printk(KERN_ERR "%s: DMA %d is in use\n", name, hw_config->dma);
482 goto dma_failed;
483 }
484
485 if (request_irq(hw_config->irq, vidc_sound_dma_irq, 0,
486 hw_config->name, &dma_start)) {
487 printk(KERN_ERR "%s: IRQ %d is in use\n", name, hw_config->irq);
488 goto irq_failed;
489 }
490 vidc_adev = adev;
491 vidc_mixer_set(SOUND_MIXER_VOLUME, (85 | 85 << 8));
492
493 return;
494
495irq_failed:
496 sound_free_dma(hw_config->dma);
497dma_failed:
498mem_failed:
499 for (i = 0; i < 2; i++)
500 free_page(dma_buf[i]);
501 sound_unload_mixerdev(audio_devs[adev]->mixer_dev);
502mixer_failed:
503 sound_unload_audiodev(adev);
504audio_failed:
505 return;
506}
507
508static int __init probe_vidc(struct address_info *hw_config)
509{
510 hw_config->irq = IRQ_DMAS0;
511 hw_config->dma = DMA_VIRTUAL_SOUND;
512 hw_config->dma2 = -1;
513 hw_config->card_subtype = 16;
514 hw_config->name = "VIDC20";
515 return 1;
516}
517
518static void __exit unload_vidc(struct address_info *hw_config)
519{
520 int i, adev = vidc_adev;
521
522 vidc_adev = -1;
523
524 free_irq(hw_config->irq, &dma_start);
525 sound_free_dma(hw_config->dma);
526
527 if (adev >= 0) {
528 sound_unload_mixerdev(audio_devs[adev]->mixer_dev);
529 sound_unload_audiodev(adev);
530 for (i = 0; i < 2; i++)
531 free_page(dma_buf[i]);
532 }
533}
534
535static struct address_info cfg;
536
537static int __init init_vidc(void)
538{
539 if (probe_vidc(&cfg) == 0)
540 return -ENODEV;
541
542 attach_vidc(&cfg);
543
544 return 0;
545}
546
547static void __exit cleanup_vidc(void)
548{
549 unload_vidc(&cfg);
550}
551
552module_init(init_vidc);
553module_exit(cleanup_vidc);
554
555MODULE_AUTHOR("Russell King");
556MODULE_DESCRIPTION("VIDC20 audio driver");
557MODULE_LICENSE("GPL");
diff --git a/sound/oss/vidc.h b/sound/oss/vidc.h
deleted file mode 100644
index 0d1424751ecd..000000000000
--- a/sound/oss/vidc.h
+++ /dev/null
@@ -1,63 +0,0 @@
1/*
2 * linux/drivers/sound/vidc.h
3 *
4 * Copyright (C) 1997 Russell King <rmk@arm.linux.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * VIDC sound function prototypes
11 */
12
13/* vidc_fill.S */
14
15/*
16 * Filler routines for different channels and sample sizes
17 */
18
19extern unsigned long vidc_fill_1x8_u(unsigned long ibuf, unsigned long iend,
20 unsigned long obuf, int mask);
21extern unsigned long vidc_fill_2x8_u(unsigned long ibuf, unsigned long iend,
22 unsigned long obuf, int mask);
23extern unsigned long vidc_fill_1x8_s(unsigned long ibuf, unsigned long iend,
24 unsigned long obuf, int mask);
25extern unsigned long vidc_fill_2x8_s(unsigned long ibuf, unsigned long iend,
26 unsigned long obuf, int mask);
27extern unsigned long vidc_fill_1x16_s(unsigned long ibuf, unsigned long iend,
28 unsigned long obuf, int mask);
29extern unsigned long vidc_fill_2x16_s(unsigned long ibuf, unsigned long iend,
30 unsigned long obuf, int mask);
31
32/*
33 * DMA Interrupt handler
34 */
35
36extern irqreturn_t vidc_sound_dma_irq(int irqnr, void *ref);
37
38/*
39 * Filler routine pointer
40 */
41
42extern unsigned long (*vidc_filler) (unsigned long ibuf, unsigned long iend,
43 unsigned long obuf, int mask);
44
45/*
46 * Virtual DMA buffer exhausted
47 */
48
49extern irqreturn_t (*dma_interrupt) (void);
50
51/*
52 * Virtual DMA buffer addresses
53 */
54
55extern unsigned long dma_start, dma_count, dma_bufsize;
56extern unsigned long dma_buf[2], dma_pbuf[2];
57
58/* vidc_synth.c */
59
60extern void vidc_synth_init(struct address_info *hw_config);
61extern void vidc_synth_exit(struct address_info *hw_config);
62extern int vidc_synth_get_volume(void);
63extern int vidc_synth_set_volume(int vol);
diff --git a/sound/oss/vidc_fill.S b/sound/oss/vidc_fill.S
deleted file mode 100644
index bed34921d176..000000000000
--- a/sound/oss/vidc_fill.S
+++ /dev/null
@@ -1,218 +0,0 @@
1/*
2 * linux/drivers/sound/vidc_fill.S
3 *
4 * Copyright (C) 1997 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Filler routines for DMA buffers
11 */
12#include <linux/linkage.h>
13#include <asm/assembler.h>
14#include <mach/hardware.h>
15#include <asm/hardware/iomd.h>
16
17 .text
18
19ENTRY(vidc_fill_1x8_u)
20 mov ip, #0xff00
211: cmp r0, r1
22 bge vidc_clear
23 ldrb r4, [r0], #1
24 eor r4, r4, #0x80
25 and r4, ip, r4, lsl #8
26 orr r4, r4, r4, lsl #16
27 str r4, [r2], #4
28 cmp r2, r3
29 blt 1b
30 mov pc, lr
31
32ENTRY(vidc_fill_2x8_u)
33 mov ip, #0xff00
341: cmp r0, r1
35 bge vidc_clear
36 ldr r4, [r0], #2
37 and r5, r4, ip
38 and r4, ip, r4, lsl #8
39 orr r4, r4, r5, lsl #16
40 orr r4, r4, r4, lsr #8
41 str r4, [r2], #4
42 cmp r2, r3
43 blt 1b
44 mov pc, lr
45
46ENTRY(vidc_fill_1x8_s)
47 mov ip, #0xff00
481: cmp r0, r1
49 bge vidc_clear
50 ldrb r4, [r0], #1
51 and r4, ip, r4, lsl #8
52 orr r4, r4, r4, lsl #16
53 str r4, [r2], #4
54 cmp r2, r3
55 blt 1b
56 mov pc, lr
57
58ENTRY(vidc_fill_2x8_s)
59 mov ip, #0xff00
601: cmp r0, r1
61 bge vidc_clear
62 ldr r4, [r0], #2
63 and r5, r4, ip
64 and r4, ip, r4, lsl #8
65 orr r4, r4, r5, lsl #16
66 orr r4, r4, r4, lsr #8
67 str r4, [r2], #4
68 cmp r2, r3
69 blt 1b
70 mov pc, lr
71
72ENTRY(vidc_fill_1x16_s)
73 mov ip, #0xff00
74 orr ip, ip, ip, lsr #8
751: cmp r0, r1
76 bge vidc_clear
77 ldr r5, [r0], #2
78 and r4, r5, ip
79 orr r4, r4, r4, lsl #16
80 str r4, [r2], #4
81 cmp r0, r1
82 addlt r0, r0, #2
83 andlt r4, r5, ip, lsl #16
84 orrlt r4, r4, r4, lsr #16
85 strlt r4, [r2], #4
86 cmp r2, r3
87 blt 1b
88 mov pc, lr
89
90ENTRY(vidc_fill_2x16_s)
91 mov ip, #0xff00
92 orr ip, ip, ip, lsr #8
931: cmp r0, r1
94 bge vidc_clear
95 ldr r4, [r0], #4
96 str r4, [r2], #4
97 cmp r0, r1
98 ldrlt r4, [r0], #4
99 strlt r4, [r2], #4
100 cmp r2, r3
101 blt 1b
102 mov pc, lr
103
104ENTRY(vidc_fill_noaudio)
105 mov r0, #0
106 mov r1, #0
1072: mov r4, #0
108 mov r5, #0
1091: cmp r2, r3
110 stmltia r2!, {r0, r1, r4, r5}
111 blt 1b
112 mov pc, lr
113
114ENTRY(vidc_clear)
115 mov r0, #0
116 mov r1, #0
117 tst r2, #4
118 str r0, [r2], #4
119 tst r2, #8
120 stmia r2!, {r0, r1}
121 b 2b
122
123/*
124 * Call filler routines with:
125 * r0 = phys address
126 * r1 = phys end
127 * r2 = buffer
128 * Returns:
129 * r0 = new buffer address
130 * r2 = new buffer finish
131 * r4 = corrupted
132 * r5 = corrupted
133 * ip = corrupted
134 */
135
136ENTRY(vidc_sound_dma_irq)
137 stmfd sp!, {r4 - r8, lr}
138 ldr r8, =dma_start
139 ldmia r8, {r0, r1, r2, r3, r4, r5}
140 teq r1, #0
141 adreq r4, vidc_fill_noaudio
142 moveq r7, #1 << 31
143 movne r7, #0
144 mov ip, #IOMD_BASE & 0xff000000
145 orr ip, ip, #IOMD_BASE & 0x00ff0000
146 ldrb r6, [ip, #IOMD_SD0ST]
147 tst r6, #DMA_ST_OFL @ Check for overrun
148 eorne r6, r6, #DMA_ST_AB
149 tst r6, #DMA_ST_AB
150 moveq r2, r3 @ DMAing A, update B
151 add r3, r2, r5 @ End of DMA buffer
152 add r1, r1, r0 @ End of virtual DMA buffer
153 mov lr, pc
154 mov pc, r4 @ Call fill routine (uses r4, ip)
155 sub r1, r1, r0 @ Remaining length
156 stmia r8, {r0, r1}
157 mov r0, #0
158 tst r2, #4 @ Round buffer up to 4 words
159 strne r0, [r2], #4
160 tst r2, #8
161 strne r0, [r2], #4
162 strne r0, [r2], #4
163 sub r2, r2, #16
164 mov r2, r2, lsl #20
165 movs r2, r2, lsr #20
166 orreq r2, r2, #1 << 30 @ Set L bit
167 orr r2, r2, r7
168 ldmdb r8, {r3, r4, r5}
169 tst r6, #DMA_ST_AB
170 mov ip, #IOMD_BASE & 0xff000000
171 orr ip, ip, #IOMD_BASE & 0x00ff0000
172 streq r4, [ip, #IOMD_SD0CURB]
173 strne r5, [ip, #IOMD_SD0CURA]
174 streq r2, [ip, #IOMD_SD0ENDB]
175 strne r2, [ip, #IOMD_SD0ENDA]
176 ldr lr, [ip, #IOMD_SD0ST]
177 tst lr, #DMA_ST_OFL
178 bne 1f
179 tst r6, #DMA_ST_AB
180 strne r4, [ip, #IOMD_SD0CURB]
181 streq r5, [ip, #IOMD_SD0CURA]
182 strne r2, [ip, #IOMD_SD0ENDB]
183 streq r2, [ip, #IOMD_SD0ENDA]
1841: teq r7, #0
185 mov r0, #0x10
186 strneb r0, [ip, #IOMD_SD0CR]
187 ldmfd sp!, {r4 - r8, lr}
188 mov r0, #1 @ IRQ_HANDLED
189 teq r1, #0 @ If we have no more
190 movne pc, lr
191 teq r3, #0
192 movne pc, r3 @ Call interrupt routine
193 mov pc, lr
194
195 .data
196 .globl dma_interrupt
197dma_interrupt:
198 .long 0 @ r3
199 .globl dma_pbuf
200dma_pbuf:
201 .long 0 @ r4
202 .long 0 @ r5
203 .globl dma_start
204dma_start:
205 .long 0 @ r0
206 .globl dma_count
207dma_count:
208 .long 0 @ r1
209 .globl dma_buf
210dma_buf:
211 .long 0 @ r2
212 .long 0 @ r3
213 .globl vidc_filler
214vidc_filler:
215 .long vidc_fill_noaudio @ r4
216 .globl dma_bufsize
217dma_bufsize:
218 .long 0x1000 @ r5
diff --git a/sound/oss/waveartist.c b/sound/oss/waveartist.c
deleted file mode 100644
index 4f0c3a232e41..000000000000
--- a/sound/oss/waveartist.c
+++ /dev/null
@@ -1,2043 +0,0 @@
1/*
2 * linux/sound/oss/waveartist.c
3 *
4 * The low level driver for the RWA010 Rockwell Wave Artist
5 * codec chip used in the Rebel.com NetWinder.
6 *
7 * Cleaned up and integrated into 2.1 by Russell King (rmk@arm.linux.org.uk)
8 * and Pat Beirne (patb@corel.ca)
9 *
10 *
11 * Copyright (C) by Rebel.com 1998-1999
12 *
13 * RWA010 specs received under NDA from Rockwell
14 *
15 * Copyright (C) by Hannu Savolainen 1993-1997
16 *
17 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
18 * Version 2 (June 1991). See the "COPYING" file distributed with this software
19 * for more info.
20 *
21 * Changes:
22 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
23 * Added __init to waveartist_init()
24 */
25
26/* Debugging */
27#define DEBUG_CMD 1
28#define DEBUG_OUT 2
29#define DEBUG_IN 4
30#define DEBUG_INTR 8
31#define DEBUG_MIXER 16
32#define DEBUG_TRIGGER 32
33
34#define debug_flg (0)
35
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/slab.h>
39#include <linux/sched.h>
40#include <linux/interrupt.h>
41#include <linux/delay.h>
42#include <linux/spinlock.h>
43#include <linux/bitops.h>
44
45
46#include "sound_config.h"
47#include "waveartist.h"
48
49#ifdef CONFIG_ARM
50#include <mach/hardware.h>
51#include <asm/mach-types.h>
52#endif
53
54#ifndef NO_DMA
55#define NO_DMA 255
56#endif
57
58#define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
59 SOUND_MASK_PCM |\
60 SOUND_MASK_LINE |\
61 SOUND_MASK_MIC |\
62 SOUND_MASK_LINE1 |\
63 SOUND_MASK_RECLEV |\
64 SOUND_MASK_VOLUME |\
65 SOUND_MASK_IMIX)
66
67static unsigned short levels[SOUND_MIXER_NRDEVICES] = {
68 0x5555, /* Master Volume */
69 0x0000, /* Bass */
70 0x0000, /* Treble */
71 0x2323, /* Synth (FM) */
72 0x4b4b, /* PCM */
73 0x6464, /* PC Speaker */
74 0x0000, /* Ext Line */
75 0x0000, /* Mic */
76 0x0000, /* CD */
77 0x6464, /* Recording monitor */
78 0x0000, /* SB PCM (ALT PCM) */
79 0x0000, /* Recording level */
80 0x6464, /* Input gain */
81 0x6464, /* Output gain */
82 0x0000, /* Line1 (Aux1) */
83 0x0000, /* Line2 (Aux2) */
84 0x0000, /* Line3 (Aux3) */
85 0x0000, /* Digital1 */
86 0x0000, /* Digital2 */
87 0x0000, /* Digital3 */
88 0x0000, /* Phone In */
89 0x6464, /* Phone Out */
90 0x0000, /* Video */
91 0x0000, /* Radio */
92 0x0000 /* Monitor */
93};
94
95struct wavnc_info {
96 struct address_info hw; /* hardware */
97 char *chip_name;
98
99 int xfer_count;
100 int audio_mode;
101 int open_mode;
102 int audio_flags;
103 int record_dev;
104 int playback_dev;
105 int dev_no;
106
107 /* Mixer parameters */
108 const struct waveartist_mixer_info *mix;
109
110 unsigned short *levels; /* cache of volume settings */
111 int recmask; /* currently enabled recording device! */
112
113#ifdef CONFIG_ARCH_NETWINDER
114 signed int slider_vol; /* hardware slider volume */
115 unsigned int handset_detect :1;
116 unsigned int telephone_detect:1;
117 unsigned int no_autoselect :1;/* handset/telephone autoselects a path */
118 unsigned int spkr_mute_state :1;/* set by ioctl or autoselect */
119 unsigned int line_mute_state :1;/* set by ioctl or autoselect */
120 unsigned int use_slider :1;/* use slider setting for o/p vol */
121#endif
122};
123
124/*
125 * This is the implementation specific mixer information.
126 */
127struct waveartist_mixer_info {
128 unsigned int supported_devs; /* Supported devices */
129 unsigned int recording_devs; /* Recordable devies */
130 unsigned int stereo_devs; /* Stereo devices */
131
132 unsigned int (*select_input)(struct wavnc_info *, unsigned int,
133 unsigned char *, unsigned char *);
134 int (*decode_mixer)(struct wavnc_info *, int,
135 unsigned char, unsigned char);
136 int (*get_mixer)(struct wavnc_info *, int);
137};
138
139struct wavnc_port_info {
140 int open_mode;
141 int speed;
142 int channels;
143 int audio_format;
144};
145
146static int nr_waveartist_devs;
147static struct wavnc_info adev_info[MAX_AUDIO_DEV];
148static DEFINE_SPINLOCK(waveartist_lock);
149
150#ifndef CONFIG_ARCH_NETWINDER
151#define machine_is_netwinder() 0
152#else
153static struct timer_list vnc_timer;
154static void vnc_configure_mixer(struct wavnc_info *devc,
155 unsigned int input_mask);
156static int vnc_private_ioctl(int dev, unsigned int cmd, int __user *arg);
157static void vnc_slider_tick(unsigned long data);
158#endif
159
160static inline void
161waveartist_set_ctlr(struct address_info *hw, unsigned char clear, unsigned char set)
162{
163 unsigned int ctlr_port = hw->io_base + CTLR;
164
165 clear = ~clear & inb(ctlr_port);
166
167 outb(clear | set, ctlr_port);
168}
169
170/* Toggle IRQ acknowledge line
171 */
172static inline void
173waveartist_iack(struct wavnc_info *devc)
174{
175 unsigned int ctlr_port = devc->hw.io_base + CTLR;
176 int old_ctlr;
177
178 old_ctlr = inb(ctlr_port) & ~IRQ_ACK;
179
180 outb(old_ctlr | IRQ_ACK, ctlr_port);
181 outb(old_ctlr, ctlr_port);
182}
183
184static inline int
185waveartist_sleep(int timeout_ms)
186{
187 unsigned int timeout = msecs_to_jiffies(timeout_ms*100);
188 return schedule_timeout_interruptible(timeout);
189}
190
191static int
192waveartist_reset(struct wavnc_info *devc)
193{
194 struct address_info *hw = &devc->hw;
195 unsigned int timeout, res = -1;
196
197 waveartist_set_ctlr(hw, -1, RESET);
198 waveartist_sleep(2);
199 waveartist_set_ctlr(hw, RESET, 0);
200
201 timeout = 500;
202 do {
203 mdelay(2);
204
205 if (inb(hw->io_base + STATR) & CMD_RF) {
206 res = inw(hw->io_base + CMDR);
207 if (res == 0x55aa)
208 break;
209 }
210 } while (--timeout);
211
212 if (timeout == 0) {
213 printk(KERN_WARNING "WaveArtist: reset timeout ");
214 if (res != (unsigned int)-1)
215 printk("(res=%04X)", res);
216 printk("\n");
217 return 1;
218 }
219 return 0;
220}
221
222/* Helper function to send and receive words
223 * from WaveArtist. It handles all the handshaking
224 * and can send or receive multiple words.
225 */
226static int
227waveartist_cmd(struct wavnc_info *devc,
228 int nr_cmd, unsigned int *cmd,
229 int nr_resp, unsigned int *resp)
230{
231 unsigned int io_base = devc->hw.io_base;
232 unsigned int timed_out = 0;
233 unsigned int i;
234
235 if (debug_flg & DEBUG_CMD) {
236 printk("waveartist_cmd: cmd=");
237
238 for (i = 0; i < nr_cmd; i++)
239 printk("%04X ", cmd[i]);
240
241 printk("\n");
242 }
243
244 if (inb(io_base + STATR) & CMD_RF) {
245 int old_data;
246
247 /* flush the port
248 */
249
250 old_data = inw(io_base + CMDR);
251
252 if (debug_flg & DEBUG_CMD)
253 printk("flushed %04X...", old_data);
254
255 udelay(10);
256 }
257
258 for (i = 0; !timed_out && i < nr_cmd; i++) {
259 int count;
260
261 for (count = 5000; count; count--)
262 if (inb(io_base + STATR) & CMD_WE)
263 break;
264
265 if (!count)
266 timed_out = 1;
267 else
268 outw(cmd[i], io_base + CMDR);
269 }
270
271 for (i = 0; !timed_out && i < nr_resp; i++) {
272 int count;
273
274 for (count = 5000; count; count--)
275 if (inb(io_base + STATR) & CMD_RF)
276 break;
277
278 if (!count)
279 timed_out = 1;
280 else
281 resp[i] = inw(io_base + CMDR);
282 }
283
284 if (debug_flg & DEBUG_CMD) {
285 if (!timed_out) {
286 printk("waveartist_cmd: resp=");
287
288 for (i = 0; i < nr_resp; i++)
289 printk("%04X ", resp[i]);
290
291 printk("\n");
292 } else
293 printk("waveartist_cmd: timed out\n");
294 }
295
296 return timed_out ? 1 : 0;
297}
298
299/*
300 * Send one command word
301 */
302static inline int
303waveartist_cmd1(struct wavnc_info *devc, unsigned int cmd)
304{
305 return waveartist_cmd(devc, 1, &cmd, 0, NULL);
306}
307
308/*
309 * Send one command, receive one word
310 */
311static inline unsigned int
312waveartist_cmd1_r(struct wavnc_info *devc, unsigned int cmd)
313{
314 unsigned int ret;
315
316 waveartist_cmd(devc, 1, &cmd, 1, &ret);
317
318 return ret;
319}
320
321/*
322 * Send a double command, receive one
323 * word (and throw it away)
324 */
325static inline int
326waveartist_cmd2(struct wavnc_info *devc, unsigned int cmd, unsigned int arg)
327{
328 unsigned int vals[2];
329
330 vals[0] = cmd;
331 vals[1] = arg;
332
333 return waveartist_cmd(devc, 2, vals, 1, vals);
334}
335
336/*
337 * Send a triple command
338 */
339static inline int
340waveartist_cmd3(struct wavnc_info *devc, unsigned int cmd,
341 unsigned int arg1, unsigned int arg2)
342{
343 unsigned int vals[3];
344
345 vals[0] = cmd;
346 vals[1] = arg1;
347 vals[2] = arg2;
348
349 return waveartist_cmd(devc, 3, vals, 0, NULL);
350}
351
352static int
353waveartist_getrev(struct wavnc_info *devc, char *rev)
354{
355 unsigned int temp[2];
356 unsigned int cmd = WACMD_GETREV;
357
358 waveartist_cmd(devc, 1, &cmd, 2, temp);
359
360 rev[0] = temp[0] >> 8;
361 rev[1] = temp[0] & 255;
362 rev[2] = '\0';
363
364 return temp[0];
365}
366
367static void waveartist_halt_output(int dev);
368static void waveartist_halt_input(int dev);
369static void waveartist_halt(int dev);
370static void waveartist_trigger(int dev, int state);
371
372static int
373waveartist_open(int dev, int mode)
374{
375 struct wavnc_info *devc;
376 struct wavnc_port_info *portc;
377 unsigned long flags;
378
379 if (dev < 0 || dev >= num_audiodevs)
380 return -ENXIO;
381
382 devc = (struct wavnc_info *) audio_devs[dev]->devc;
383 portc = (struct wavnc_port_info *) audio_devs[dev]->portc;
384
385 spin_lock_irqsave(&waveartist_lock, flags);
386 if (portc->open_mode || (devc->open_mode & mode)) {
387 spin_unlock_irqrestore(&waveartist_lock, flags);
388 return -EBUSY;
389 }
390
391 devc->audio_mode = 0;
392 devc->open_mode |= mode;
393 portc->open_mode = mode;
394 waveartist_trigger(dev, 0);
395
396 if (mode & OPEN_READ)
397 devc->record_dev = dev;
398 if (mode & OPEN_WRITE)
399 devc->playback_dev = dev;
400 spin_unlock_irqrestore(&waveartist_lock, flags);
401
402 return 0;
403}
404
405static void
406waveartist_close(int dev)
407{
408 struct wavnc_info *devc = (struct wavnc_info *)
409 audio_devs[dev]->devc;
410 struct wavnc_port_info *portc = (struct wavnc_port_info *)
411 audio_devs[dev]->portc;
412 unsigned long flags;
413
414 spin_lock_irqsave(&waveartist_lock, flags);
415
416 waveartist_halt(dev);
417
418 devc->audio_mode = 0;
419 devc->open_mode &= ~portc->open_mode;
420 portc->open_mode = 0;
421
422 spin_unlock_irqrestore(&waveartist_lock, flags);
423}
424
425static void
426waveartist_output_block(int dev, unsigned long buf, int __count, int intrflag)
427{
428 struct wavnc_port_info *portc = (struct wavnc_port_info *)
429 audio_devs[dev]->portc;
430 struct wavnc_info *devc = (struct wavnc_info *)
431 audio_devs[dev]->devc;
432 unsigned long flags;
433 unsigned int count = __count;
434
435 if (debug_flg & DEBUG_OUT)
436 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
437 buf, count);
438 /*
439 * 16 bit data
440 */
441 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
442 count >>= 1;
443
444 if (portc->channels > 1)
445 count >>= 1;
446
447 count -= 1;
448
449 if (devc->audio_mode & PCM_ENABLE_OUTPUT &&
450 audio_devs[dev]->flags & DMA_AUTOMODE &&
451 intrflag &&
452 count == devc->xfer_count) {
453 devc->audio_mode |= PCM_ENABLE_OUTPUT;
454 return; /*
455 * Auto DMA mode on. No need to react
456 */
457 }
458
459 spin_lock_irqsave(&waveartist_lock, flags);
460
461 /*
462 * set sample count
463 */
464 waveartist_cmd2(devc, WACMD_OUTPUTSIZE, count);
465
466 devc->xfer_count = count;
467 devc->audio_mode |= PCM_ENABLE_OUTPUT;
468
469 spin_unlock_irqrestore(&waveartist_lock, flags);
470}
471
472static void
473waveartist_start_input(int dev, unsigned long buf, int __count, int intrflag)
474{
475 struct wavnc_port_info *portc = (struct wavnc_port_info *)
476 audio_devs[dev]->portc;
477 struct wavnc_info *devc = (struct wavnc_info *)
478 audio_devs[dev]->devc;
479 unsigned long flags;
480 unsigned int count = __count;
481
482 if (debug_flg & DEBUG_IN)
483 printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
484 buf, count);
485
486 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
487 count >>= 1;
488
489 if (portc->channels > 1)
490 count >>= 1;
491
492 count -= 1;
493
494 if (devc->audio_mode & PCM_ENABLE_INPUT &&
495 audio_devs[dev]->flags & DMA_AUTOMODE &&
496 intrflag &&
497 count == devc->xfer_count) {
498 devc->audio_mode |= PCM_ENABLE_INPUT;
499 return; /*
500 * Auto DMA mode on. No need to react
501 */
502 }
503
504 spin_lock_irqsave(&waveartist_lock, flags);
505
506 /*
507 * set sample count
508 */
509 waveartist_cmd2(devc, WACMD_INPUTSIZE, count);
510
511 devc->xfer_count = count;
512 devc->audio_mode |= PCM_ENABLE_INPUT;
513
514 spin_unlock_irqrestore(&waveartist_lock, flags);
515}
516
517static int
518waveartist_ioctl(int dev, unsigned int cmd, void __user * arg)
519{
520 return -EINVAL;
521}
522
523static unsigned int
524waveartist_get_speed(struct wavnc_port_info *portc)
525{
526 unsigned int speed;
527
528 /*
529 * program the speed, channels, bits
530 */
531 if (portc->speed == 8000)
532 speed = 0x2E71;
533 else if (portc->speed == 11025)
534 speed = 0x4000;
535 else if (portc->speed == 22050)
536 speed = 0x8000;
537 else if (portc->speed == 44100)
538 speed = 0x0;
539 else {
540 /*
541 * non-standard - just calculate
542 */
543 speed = portc->speed << 16;
544
545 speed = (speed / 44100) & 65535;
546 }
547
548 return speed;
549}
550
551static unsigned int
552waveartist_get_bits(struct wavnc_port_info *portc)
553{
554 unsigned int bits;
555
556 if (portc->audio_format == AFMT_S16_LE)
557 bits = 1;
558 else if (portc->audio_format == AFMT_S8)
559 bits = 0;
560 else
561 bits = 2; //default AFMT_U8
562
563 return bits;
564}
565
566static int
567waveartist_prepare_for_input(int dev, int bsize, int bcount)
568{
569 unsigned long flags;
570 struct wavnc_info *devc = (struct wavnc_info *)
571 audio_devs[dev]->devc;
572 struct wavnc_port_info *portc = (struct wavnc_port_info *)
573 audio_devs[dev]->portc;
574 unsigned int speed, bits;
575
576 if (devc->audio_mode)
577 return 0;
578
579 speed = waveartist_get_speed(portc);
580 bits = waveartist_get_bits(portc);
581
582 spin_lock_irqsave(&waveartist_lock, flags);
583
584 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
585 printk(KERN_WARNING "waveartist: error setting the "
586 "record format to %d\n", portc->audio_format);
587
588 if (waveartist_cmd2(devc, WACMD_INPUTCHANNELS, portc->channels))
589 printk(KERN_WARNING "waveartist: error setting record "
590 "to %d channels\n", portc->channels);
591
592 /*
593 * write cmd SetSampleSpeedTimeConstant
594 */
595 if (waveartist_cmd2(devc, WACMD_INPUTSPEED, speed))
596 printk(KERN_WARNING "waveartist: error setting the record "
597 "speed to %dHz.\n", portc->speed);
598
599 if (waveartist_cmd2(devc, WACMD_INPUTDMA, 1))
600 printk(KERN_WARNING "waveartist: error setting the record "
601 "data path to 0x%X\n", 1);
602
603 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
604 printk(KERN_WARNING "waveartist: error setting the record "
605 "format to %d\n", portc->audio_format);
606
607 devc->xfer_count = 0;
608 spin_unlock_irqrestore(&waveartist_lock, flags);
609 waveartist_halt_input(dev);
610
611 if (debug_flg & DEBUG_INTR) {
612 printk("WA CTLR reg: 0x%02X.\n",
613 inb(devc->hw.io_base + CTLR));
614 printk("WA STAT reg: 0x%02X.\n",
615 inb(devc->hw.io_base + STATR));
616 printk("WA IRQS reg: 0x%02X.\n",
617 inb(devc->hw.io_base + IRQSTAT));
618 }
619
620 return 0;
621}
622
623static int
624waveartist_prepare_for_output(int dev, int bsize, int bcount)
625{
626 unsigned long flags;
627 struct wavnc_info *devc = (struct wavnc_info *)
628 audio_devs[dev]->devc;
629 struct wavnc_port_info *portc = (struct wavnc_port_info *)
630 audio_devs[dev]->portc;
631 unsigned int speed, bits;
632
633 /*
634 * program the speed, channels, bits
635 */
636 speed = waveartist_get_speed(portc);
637 bits = waveartist_get_bits(portc);
638
639 spin_lock_irqsave(&waveartist_lock, flags);
640
641 if (waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed) &&
642 waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed))
643 printk(KERN_WARNING "waveartist: error setting the playback "
644 "speed to %dHz.\n", portc->speed);
645
646 if (waveartist_cmd2(devc, WACMD_OUTPUTCHANNELS, portc->channels))
647 printk(KERN_WARNING "waveartist: error setting the playback "
648 "to %d channels\n", portc->channels);
649
650 if (waveartist_cmd2(devc, WACMD_OUTPUTDMA, 0))
651 printk(KERN_WARNING "waveartist: error setting the playback "
652 "data path to 0x%X\n", 0);
653
654 if (waveartist_cmd2(devc, WACMD_OUTPUTFORMAT, bits))
655 printk(KERN_WARNING "waveartist: error setting the playback "
656 "format to %d\n", portc->audio_format);
657
658 devc->xfer_count = 0;
659 spin_unlock_irqrestore(&waveartist_lock, flags);
660 waveartist_halt_output(dev);
661
662 if (debug_flg & DEBUG_INTR) {
663 printk("WA CTLR reg: 0x%02X.\n",inb(devc->hw.io_base + CTLR));
664 printk("WA STAT reg: 0x%02X.\n",inb(devc->hw.io_base + STATR));
665 printk("WA IRQS reg: 0x%02X.\n",inb(devc->hw.io_base + IRQSTAT));
666 }
667
668 return 0;
669}
670
671static void
672waveartist_halt(int dev)
673{
674 struct wavnc_port_info *portc = (struct wavnc_port_info *)
675 audio_devs[dev]->portc;
676 struct wavnc_info *devc;
677
678 if (portc->open_mode & OPEN_WRITE)
679 waveartist_halt_output(dev);
680
681 if (portc->open_mode & OPEN_READ)
682 waveartist_halt_input(dev);
683
684 devc = (struct wavnc_info *) audio_devs[dev]->devc;
685 devc->audio_mode = 0;
686}
687
688static void
689waveartist_halt_input(int dev)
690{
691 struct wavnc_info *devc = (struct wavnc_info *)
692 audio_devs[dev]->devc;
693 unsigned long flags;
694
695 spin_lock_irqsave(&waveartist_lock, flags);
696
697 /*
698 * Stop capture
699 */
700 waveartist_cmd1(devc, WACMD_INPUTSTOP);
701
702 devc->audio_mode &= ~PCM_ENABLE_INPUT;
703
704 /*
705 * Clear interrupt by toggling
706 * the IRQ_ACK bit in CTRL
707 */
708 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
709 waveartist_iack(devc);
710
711// devc->audio_mode &= ~PCM_ENABLE_INPUT;
712
713 spin_unlock_irqrestore(&waveartist_lock, flags);
714}
715
716static void
717waveartist_halt_output(int dev)
718{
719 struct wavnc_info *devc = (struct wavnc_info *)
720 audio_devs[dev]->devc;
721 unsigned long flags;
722
723 spin_lock_irqsave(&waveartist_lock, flags);
724
725 waveartist_cmd1(devc, WACMD_OUTPUTSTOP);
726
727 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
728
729 /*
730 * Clear interrupt by toggling
731 * the IRQ_ACK bit in CTRL
732 */
733 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
734 waveartist_iack(devc);
735
736// devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
737
738 spin_unlock_irqrestore(&waveartist_lock, flags);
739}
740
741static void
742waveartist_trigger(int dev, int state)
743{
744 struct wavnc_info *devc = (struct wavnc_info *)
745 audio_devs[dev]->devc;
746 struct wavnc_port_info *portc = (struct wavnc_port_info *)
747 audio_devs[dev]->portc;
748 unsigned long flags;
749
750 if (debug_flg & DEBUG_TRIGGER) {
751 printk("wavnc: audio trigger ");
752 if (state & PCM_ENABLE_INPUT)
753 printk("in ");
754 if (state & PCM_ENABLE_OUTPUT)
755 printk("out");
756 printk("\n");
757 }
758
759 spin_lock_irqsave(&waveartist_lock, flags);
760
761 state &= devc->audio_mode;
762
763 if (portc->open_mode & OPEN_READ &&
764 state & PCM_ENABLE_INPUT)
765 /*
766 * enable ADC Data Transfer to PC
767 */
768 waveartist_cmd1(devc, WACMD_INPUTSTART);
769
770 if (portc->open_mode & OPEN_WRITE &&
771 state & PCM_ENABLE_OUTPUT)
772 /*
773 * enable DAC data transfer from PC
774 */
775 waveartist_cmd1(devc, WACMD_OUTPUTSTART);
776
777 spin_unlock_irqrestore(&waveartist_lock, flags);
778}
779
780static int
781waveartist_set_speed(int dev, int arg)
782{
783 struct wavnc_port_info *portc = (struct wavnc_port_info *)
784 audio_devs[dev]->portc;
785
786 if (arg <= 0)
787 return portc->speed;
788
789 if (arg < 5000)
790 arg = 5000;
791 if (arg > 44100)
792 arg = 44100;
793
794 portc->speed = arg;
795 return portc->speed;
796
797}
798
799static short
800waveartist_set_channels(int dev, short arg)
801{
802 struct wavnc_port_info *portc = (struct wavnc_port_info *)
803 audio_devs[dev]->portc;
804
805 if (arg != 1 && arg != 2)
806 return portc->channels;
807
808 portc->channels = arg;
809 return arg;
810}
811
812static unsigned int
813waveartist_set_bits(int dev, unsigned int arg)
814{
815 struct wavnc_port_info *portc = (struct wavnc_port_info *)
816 audio_devs[dev]->portc;
817
818 if (arg == 0)
819 return portc->audio_format;
820
821 if ((arg != AFMT_U8) && (arg != AFMT_S16_LE) && (arg != AFMT_S8))
822 arg = AFMT_U8;
823
824 portc->audio_format = arg;
825
826 return arg;
827}
828
829static struct audio_driver waveartist_audio_driver = {
830 .owner = THIS_MODULE,
831 .open = waveartist_open,
832 .close = waveartist_close,
833 .output_block = waveartist_output_block,
834 .start_input = waveartist_start_input,
835 .ioctl = waveartist_ioctl,
836 .prepare_for_input = waveartist_prepare_for_input,
837 .prepare_for_output = waveartist_prepare_for_output,
838 .halt_io = waveartist_halt,
839 .halt_input = waveartist_halt_input,
840 .halt_output = waveartist_halt_output,
841 .trigger = waveartist_trigger,
842 .set_speed = waveartist_set_speed,
843 .set_bits = waveartist_set_bits,
844 .set_channels = waveartist_set_channels
845};
846
847
848static irqreturn_t
849waveartist_intr(int irq, void *dev_id)
850{
851 struct wavnc_info *devc = dev_id;
852 int irqstatus, status;
853
854 spin_lock(&waveartist_lock);
855 irqstatus = inb(devc->hw.io_base + IRQSTAT);
856 status = inb(devc->hw.io_base + STATR);
857
858 if (debug_flg & DEBUG_INTR)
859 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
860 status, irqstatus);
861
862 if (status & IRQ_REQ) /* Clear interrupt */
863 waveartist_iack(devc);
864 else
865 printk(KERN_WARNING "waveartist: unexpected interrupt\n");
866
867 if (irqstatus & 0x01) {
868 int temp = 1;
869
870 /* PCM buffer done
871 */
872 if ((status & DMA0) && (devc->audio_mode & PCM_ENABLE_OUTPUT)) {
873 DMAbuf_outputintr(devc->playback_dev, 1);
874 temp = 0;
875 }
876 if ((status & DMA1) && (devc->audio_mode & PCM_ENABLE_INPUT)) {
877 DMAbuf_inputintr(devc->record_dev);
878 temp = 0;
879 }
880 if (temp) //default:
881 printk(KERN_WARNING "waveartist: Unknown interrupt\n");
882 }
883 if (irqstatus & 0x2)
884 // We do not use SB mode natively...
885 printk(KERN_WARNING "waveartist: Unexpected SB interrupt...\n");
886 spin_unlock(&waveartist_lock);
887 return IRQ_HANDLED;
888}
889
890/* -------------------------------------------------------------------------
891 * Mixer stuff
892 */
893struct mix_ent {
894 unsigned char reg_l;
895 unsigned char reg_r;
896 unsigned char shift;
897 unsigned char max;
898};
899
900static const struct mix_ent mix_devs[SOUND_MIXER_NRDEVICES] = {
901 { 2, 6, 1, 7 }, /* SOUND_MIXER_VOLUME */
902 { 0, 0, 0, 0 }, /* SOUND_MIXER_BASS */
903 { 0, 0, 0, 0 }, /* SOUND_MIXER_TREBLE */
904 { 0, 0, 0, 0 }, /* SOUND_MIXER_SYNTH */
905 { 0, 0, 0, 0 }, /* SOUND_MIXER_PCM */
906 { 0, 0, 0, 0 }, /* SOUND_MIXER_SPEAKER */
907 { 0, 4, 6, 31 }, /* SOUND_MIXER_LINE */
908 { 2, 6, 4, 3 }, /* SOUND_MIXER_MIC */
909 { 0, 0, 0, 0 }, /* SOUND_MIXER_CD */
910 { 0, 0, 0, 0 }, /* SOUND_MIXER_IMIX */
911 { 0, 0, 0, 0 }, /* SOUND_MIXER_ALTPCM */
912#if 0
913 { 3, 7, 0, 10 }, /* SOUND_MIXER_RECLEV */
914 { 0, 0, 0, 0 }, /* SOUND_MIXER_IGAIN */
915#else
916 { 0, 0, 0, 0 }, /* SOUND_MIXER_RECLEV */
917 { 3, 7, 0, 7 }, /* SOUND_MIXER_IGAIN */
918#endif
919 { 0, 0, 0, 0 }, /* SOUND_MIXER_OGAIN */
920 { 0, 4, 1, 31 }, /* SOUND_MIXER_LINE1 */
921 { 1, 5, 6, 31 }, /* SOUND_MIXER_LINE2 */
922 { 0, 0, 0, 0 }, /* SOUND_MIXER_LINE3 */
923 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL1 */
924 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL2 */
925 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL3 */
926 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEIN */
927 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEOUT */
928 { 0, 0, 0, 0 }, /* SOUND_MIXER_VIDEO */
929 { 0, 0, 0, 0 }, /* SOUND_MIXER_RADIO */
930 { 0, 0, 0, 0 } /* SOUND_MIXER_MONITOR */
931};
932
933static void
934waveartist_mixer_update(struct wavnc_info *devc, int whichDev)
935{
936 unsigned int lev_left, lev_right;
937
938 lev_left = devc->levels[whichDev] & 0xff;
939 lev_right = devc->levels[whichDev] >> 8;
940
941 if (lev_left > 100)
942 lev_left = 100;
943 if (lev_right > 100)
944 lev_right = 100;
945
946#define SCALE(lev,max) ((lev) * (max) / 100)
947
948 if (machine_is_netwinder() && whichDev == SOUND_MIXER_PHONEOUT)
949 whichDev = SOUND_MIXER_VOLUME;
950
951 if (mix_devs[whichDev].reg_l || mix_devs[whichDev].reg_r) {
952 const struct mix_ent *mix = mix_devs + whichDev;
953 unsigned int mask, left, right;
954
955 mask = mix->max << mix->shift;
956 lev_left = SCALE(lev_left, mix->max) << mix->shift;
957 lev_right = SCALE(lev_right, mix->max) << mix->shift;
958
959 /* read left setting */
960 left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
961 mix->reg_l << 8);
962
963 /* read right setting */
964 right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
965 mix->reg_r << 8);
966
967 left = (left & ~mask) | (lev_left & mask);
968 right = (right & ~mask) | (lev_right & mask);
969
970 /* write left,right back */
971 waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
972 } else {
973 switch(whichDev) {
974 case SOUND_MIXER_PCM:
975 waveartist_cmd3(devc, WACMD_SET_LEVEL,
976 SCALE(lev_left, 32767),
977 SCALE(lev_right, 32767));
978 break;
979
980 case SOUND_MIXER_SYNTH:
981 waveartist_cmd3(devc, 0x0100 | WACMD_SET_LEVEL,
982 SCALE(lev_left, 32767),
983 SCALE(lev_right, 32767));
984 break;
985 }
986 }
987}
988
989/*
990 * Set the ADC MUX to the specified values. We do NOT do any
991 * checking of the values passed, since we assume that the
992 * relevant *_select_input function has done that for us.
993 */
994static void
995waveartist_set_adc_mux(struct wavnc_info *devc, char left_dev,
996 char right_dev)
997{
998 unsigned int reg_08, reg_09;
999
1000 reg_08 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0800);
1001 reg_09 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0900);
1002
1003 reg_08 = (reg_08 & ~0x3f) | right_dev << 3 | left_dev;
1004
1005 waveartist_cmd3(devc, WACMD_SET_MIXER, reg_08, reg_09);
1006}
1007
1008/*
1009 * Decode a recording mask into a mixer selection as follows:
1010 *
1011 * OSS Source WA Source Actual source
1012 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1013 * SOUND_MASK_LINE Line Line in
1014 * SOUND_MASK_LINE1 Aux 1 Aux 1 in
1015 * SOUND_MASK_LINE2 Aux 2 Aux 2 in
1016 * SOUND_MASK_MIC Mic Microphone
1017 */
1018static unsigned int
1019waveartist_select_input(struct wavnc_info *devc, unsigned int recmask,
1020 unsigned char *dev_l, unsigned char *dev_r)
1021{
1022 unsigned int recdev = ADC_MUX_NONE;
1023
1024 if (recmask & SOUND_MASK_IMIX) {
1025 recmask = SOUND_MASK_IMIX;
1026 recdev = ADC_MUX_MIXER;
1027 } else if (recmask & SOUND_MASK_LINE2) {
1028 recmask = SOUND_MASK_LINE2;
1029 recdev = ADC_MUX_AUX2;
1030 } else if (recmask & SOUND_MASK_LINE1) {
1031 recmask = SOUND_MASK_LINE1;
1032 recdev = ADC_MUX_AUX1;
1033 } else if (recmask & SOUND_MASK_LINE) {
1034 recmask = SOUND_MASK_LINE;
1035 recdev = ADC_MUX_LINE;
1036 } else if (recmask & SOUND_MASK_MIC) {
1037 recmask = SOUND_MASK_MIC;
1038 recdev = ADC_MUX_MIC;
1039 }
1040
1041 *dev_l = *dev_r = recdev;
1042
1043 return recmask;
1044}
1045
1046static int
1047waveartist_decode_mixer(struct wavnc_info *devc, int dev,
1048 unsigned char lev_l,
1049 unsigned char lev_r)
1050{
1051 switch (dev) {
1052 case SOUND_MIXER_VOLUME:
1053 case SOUND_MIXER_SYNTH:
1054 case SOUND_MIXER_PCM:
1055 case SOUND_MIXER_LINE:
1056 case SOUND_MIXER_MIC:
1057 case SOUND_MIXER_IGAIN:
1058 case SOUND_MIXER_LINE1:
1059 case SOUND_MIXER_LINE2:
1060 devc->levels[dev] = lev_l | lev_r << 8;
1061 break;
1062
1063 case SOUND_MIXER_IMIX:
1064 break;
1065
1066 default:
1067 dev = -EINVAL;
1068 break;
1069 }
1070
1071 return dev;
1072}
1073
1074static int waveartist_get_mixer(struct wavnc_info *devc, int dev)
1075{
1076 return devc->levels[dev];
1077}
1078
1079static const struct waveartist_mixer_info waveartist_mixer = {
1080 .supported_devs = SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN,
1081 .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
1082 SOUND_MASK_LINE1 | SOUND_MASK_LINE2 |
1083 SOUND_MASK_IMIX,
1084 .stereo_devs = (SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN) & ~
1085 (SOUND_MASK_SPEAKER | SOUND_MASK_IMIX),
1086 .select_input = waveartist_select_input,
1087 .decode_mixer = waveartist_decode_mixer,
1088 .get_mixer = waveartist_get_mixer,
1089};
1090
1091static void
1092waveartist_set_recmask(struct wavnc_info *devc, unsigned int recmask)
1093{
1094 unsigned char dev_l, dev_r;
1095
1096 recmask &= devc->mix->recording_devs;
1097
1098 /*
1099 * If more than one recording device selected,
1100 * disable the device that is currently in use.
1101 */
1102 if (hweight32(recmask) > 1)
1103 recmask &= ~devc->recmask;
1104
1105 /*
1106 * Translate the recording device mask into
1107 * the ADC multiplexer settings.
1108 */
1109 devc->recmask = devc->mix->select_input(devc, recmask,
1110 &dev_l, &dev_r);
1111
1112 waveartist_set_adc_mux(devc, dev_l, dev_r);
1113}
1114
1115static int
1116waveartist_set_mixer(struct wavnc_info *devc, int dev, unsigned int level)
1117{
1118 unsigned int lev_left = level & 0x00ff;
1119 unsigned int lev_right = (level & 0xff00) >> 8;
1120
1121 if (lev_left > 100)
1122 lev_left = 100;
1123 if (lev_right > 100)
1124 lev_right = 100;
1125
1126 /*
1127 * Mono devices have their right volume forced to their
1128 * left volume. (from ALSA driver OSS emulation).
1129 */
1130 if (!(devc->mix->stereo_devs & (1 << dev)))
1131 lev_right = lev_left;
1132
1133 dev = devc->mix->decode_mixer(devc, dev, lev_left, lev_right);
1134
1135 if (dev >= 0)
1136 waveartist_mixer_update(devc, dev);
1137
1138 return dev < 0 ? dev : 0;
1139}
1140
1141static int
1142waveartist_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
1143{
1144 struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
1145 int ret = 0, val, nr;
1146
1147 /*
1148 * All SOUND_MIXER_* ioctls use type 'M'
1149 */
1150 if (((cmd >> 8) & 255) != 'M')
1151 return -ENOIOCTLCMD;
1152
1153#ifdef CONFIG_ARCH_NETWINDER
1154 if (machine_is_netwinder()) {
1155 ret = vnc_private_ioctl(dev, cmd, arg);
1156 if (ret != -ENOIOCTLCMD)
1157 return ret;
1158 else
1159 ret = 0;
1160 }
1161#endif
1162
1163 nr = cmd & 0xff;
1164
1165 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1166 if (get_user(val, (int __user *)arg))
1167 return -EFAULT;
1168
1169 switch (nr) {
1170 case SOUND_MIXER_RECSRC:
1171 waveartist_set_recmask(devc, val);
1172 break;
1173
1174 default:
1175 ret = -EINVAL;
1176 if (nr < SOUND_MIXER_NRDEVICES &&
1177 devc->mix->supported_devs & (1 << nr))
1178 ret = waveartist_set_mixer(devc, nr, val);
1179 }
1180 }
1181
1182 if (ret == 0 && _SIOC_DIR(cmd) & _SIOC_READ) {
1183 ret = -EINVAL;
1184
1185 switch (nr) {
1186 case SOUND_MIXER_RECSRC:
1187 ret = devc->recmask;
1188 break;
1189
1190 case SOUND_MIXER_DEVMASK:
1191 ret = devc->mix->supported_devs;
1192 break;
1193
1194 case SOUND_MIXER_STEREODEVS:
1195 ret = devc->mix->stereo_devs;
1196 break;
1197
1198 case SOUND_MIXER_RECMASK:
1199 ret = devc->mix->recording_devs;
1200 break;
1201
1202 case SOUND_MIXER_CAPS:
1203 ret = SOUND_CAP_EXCL_INPUT;
1204 break;
1205
1206 default:
1207 if (nr < SOUND_MIXER_NRDEVICES)
1208 ret = devc->mix->get_mixer(devc, nr);
1209 break;
1210 }
1211
1212 if (ret >= 0)
1213 ret = put_user(ret, (int __user *)arg) ? -EFAULT : 0;
1214 }
1215
1216 return ret;
1217}
1218
1219static struct mixer_operations waveartist_mixer_operations =
1220{
1221 .owner = THIS_MODULE,
1222 .id = "WaveArtist",
1223 .name = "WaveArtist",
1224 .ioctl = waveartist_mixer_ioctl
1225};
1226
1227static void
1228waveartist_mixer_reset(struct wavnc_info *devc)
1229{
1230 int i;
1231
1232 if (debug_flg & DEBUG_MIXER)
1233 printk("%s: mixer_reset\n", devc->hw.name);
1234
1235 /*
1236 * reset mixer cmd
1237 */
1238 waveartist_cmd1(devc, WACMD_RST_MIXER);
1239
1240 /*
1241 * set input for ADC to come from 'quiet'
1242 * turn on default modes
1243 */
1244 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x9800, 0xa836);
1245
1246 /*
1247 * set mixer input select to none, RX filter gains 0 dB
1248 */
1249 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x4c00, 0x8c00);
1250
1251 /*
1252 * set bit 0 reg 2 to 1 - unmute MonoOut
1253 */
1254 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x2801, 0x6800);
1255
1256 /* set default input device = internal mic
1257 * current recording device = none
1258 */
1259 waveartist_set_recmask(devc, 0);
1260
1261 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1262 waveartist_mixer_update(devc, i);
1263}
1264
1265static int __init waveartist_init(struct wavnc_info *devc)
1266{
1267 struct wavnc_port_info *portc;
1268 char rev[3], dev_name[64];
1269 int my_dev;
1270
1271 if (waveartist_reset(devc))
1272 return -ENODEV;
1273
1274 sprintf(dev_name, "%s (%s", devc->hw.name, devc->chip_name);
1275
1276 if (waveartist_getrev(devc, rev)) {
1277 strcat(dev_name, " rev. ");
1278 strcat(dev_name, rev);
1279 }
1280 strcat(dev_name, ")");
1281
1282 conf_printf2(dev_name, devc->hw.io_base, devc->hw.irq,
1283 devc->hw.dma, devc->hw.dma2);
1284
1285 portc = kzalloc(sizeof(struct wavnc_port_info), GFP_KERNEL);
1286 if (portc == NULL)
1287 goto nomem;
1288
1289 my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, dev_name,
1290 &waveartist_audio_driver, sizeof(struct audio_driver),
1291 devc->audio_flags, AFMT_U8 | AFMT_S16_LE | AFMT_S8,
1292 devc, devc->hw.dma, devc->hw.dma2);
1293
1294 if (my_dev < 0)
1295 goto free;
1296
1297 audio_devs[my_dev]->portc = portc;
1298
1299 waveartist_mixer_reset(devc);
1300
1301 /*
1302 * clear any pending interrupt
1303 */
1304 waveartist_iack(devc);
1305
1306 if (request_irq(devc->hw.irq, waveartist_intr, 0, devc->hw.name, devc) < 0) {
1307 printk(KERN_ERR "%s: IRQ %d in use\n",
1308 devc->hw.name, devc->hw.irq);
1309 goto uninstall;
1310 }
1311
1312 if (sound_alloc_dma(devc->hw.dma, devc->hw.name)) {
1313 printk(KERN_ERR "%s: Can't allocate DMA%d\n",
1314 devc->hw.name, devc->hw.dma);
1315 goto uninstall_irq;
1316 }
1317
1318 if (devc->hw.dma != devc->hw.dma2 && devc->hw.dma2 != NO_DMA)
1319 if (sound_alloc_dma(devc->hw.dma2, devc->hw.name)) {
1320 printk(KERN_ERR "%s: can't allocate DMA%d\n",
1321 devc->hw.name, devc->hw.dma2);
1322 goto uninstall_dma;
1323 }
1324
1325 waveartist_set_ctlr(&devc->hw, 0, DMA1_IE | DMA0_IE);
1326
1327 audio_devs[my_dev]->mixer_dev =
1328 sound_install_mixer(MIXER_DRIVER_VERSION,
1329 dev_name,
1330 &waveartist_mixer_operations,
1331 sizeof(struct mixer_operations),
1332 devc);
1333
1334 return my_dev;
1335
1336uninstall_dma:
1337 sound_free_dma(devc->hw.dma);
1338
1339uninstall_irq:
1340 free_irq(devc->hw.irq, devc);
1341
1342uninstall:
1343 sound_unload_audiodev(my_dev);
1344
1345free:
1346 kfree(portc);
1347
1348nomem:
1349 return -1;
1350}
1351
1352static int __init probe_waveartist(struct address_info *hw_config)
1353{
1354 struct wavnc_info *devc = &adev_info[nr_waveartist_devs];
1355
1356 if (nr_waveartist_devs >= MAX_AUDIO_DEV) {
1357 printk(KERN_WARNING "waveartist: too many audio devices\n");
1358 return 0;
1359 }
1360
1361 if (!request_region(hw_config->io_base, 15, hw_config->name)) {
1362 printk(KERN_WARNING "WaveArtist: I/O port conflict\n");
1363 return 0;
1364 }
1365
1366 if (hw_config->irq > 15 || hw_config->irq < 0) {
1367 release_region(hw_config->io_base, 15);
1368 printk(KERN_WARNING "WaveArtist: Bad IRQ %d\n",
1369 hw_config->irq);
1370 return 0;
1371 }
1372
1373 if (hw_config->dma != 3) {
1374 release_region(hw_config->io_base, 15);
1375 printk(KERN_WARNING "WaveArtist: Bad DMA %d\n",
1376 hw_config->dma);
1377 return 0;
1378 }
1379
1380 hw_config->name = "WaveArtist";
1381 devc->hw = *hw_config;
1382 devc->open_mode = 0;
1383 devc->chip_name = "RWA-010";
1384
1385 return 1;
1386}
1387
1388static void __init
1389attach_waveartist(struct address_info *hw, const struct waveartist_mixer_info *mix)
1390{
1391 struct wavnc_info *devc = &adev_info[nr_waveartist_devs];
1392
1393 /*
1394 * NOTE! If irq < 0, there is another driver which has allocated the
1395 * IRQ so that this driver doesn't need to allocate/deallocate it.
1396 * The actually used IRQ is ABS(irq).
1397 */
1398 devc->hw = *hw;
1399 devc->hw.irq = (hw->irq > 0) ? hw->irq : 0;
1400 devc->open_mode = 0;
1401 devc->playback_dev = 0;
1402 devc->record_dev = 0;
1403 devc->audio_flags = DMA_AUTOMODE;
1404 devc->levels = levels;
1405
1406 if (hw->dma != hw->dma2 && hw->dma2 != NO_DMA)
1407 devc->audio_flags |= DMA_DUPLEX;
1408
1409 devc->mix = mix;
1410 devc->dev_no = waveartist_init(devc);
1411
1412 if (devc->dev_no < 0)
1413 release_region(hw->io_base, 15);
1414 else {
1415#ifdef CONFIG_ARCH_NETWINDER
1416 if (machine_is_netwinder()) {
1417 setup_timer(&vnc_timer, vnc_slider_tick,
1418 nr_waveartist_devs);
1419 mod_timer(&vnc_timer, jiffies);
1420
1421 vnc_configure_mixer(devc, 0);
1422
1423 devc->no_autoselect = 1;
1424 }
1425#endif
1426 nr_waveartist_devs += 1;
1427 }
1428}
1429
1430static void __exit unload_waveartist(struct address_info *hw)
1431{
1432 struct wavnc_info *devc = NULL;
1433 int i;
1434
1435 for (i = 0; i < nr_waveartist_devs; i++)
1436 if (hw->io_base == adev_info[i].hw.io_base) {
1437 devc = adev_info + i;
1438 break;
1439 }
1440
1441 if (devc != NULL) {
1442 int mixer;
1443
1444#ifdef CONFIG_ARCH_NETWINDER
1445 if (machine_is_netwinder())
1446 del_timer(&vnc_timer);
1447#endif
1448
1449 release_region(devc->hw.io_base, 15);
1450
1451 waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
1452
1453 if (devc->hw.irq >= 0)
1454 free_irq(devc->hw.irq, devc);
1455
1456 sound_free_dma(devc->hw.dma);
1457
1458 if (devc->hw.dma != devc->hw.dma2 &&
1459 devc->hw.dma2 != NO_DMA)
1460 sound_free_dma(devc->hw.dma2);
1461
1462 mixer = audio_devs[devc->dev_no]->mixer_dev;
1463
1464 if (mixer >= 0)
1465 sound_unload_mixerdev(mixer);
1466
1467 if (devc->dev_no >= 0)
1468 sound_unload_audiodev(devc->dev_no);
1469
1470 nr_waveartist_devs -= 1;
1471
1472 for (; i < nr_waveartist_devs; i++)
1473 adev_info[i] = adev_info[i + 1];
1474 } else
1475 printk(KERN_WARNING "waveartist: can't find device "
1476 "to unload\n");
1477}
1478
1479#ifdef CONFIG_ARCH_NETWINDER
1480
1481/*
1482 * Rebel.com Netwinder specifics...
1483 */
1484
1485#include <asm/hardware/dec21285.h>
1486
1487#define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1488
1489#define MIXER_PRIVATE3_RESET 0x53570000
1490#define MIXER_PRIVATE3_READ 0x53570001
1491#define MIXER_PRIVATE3_WRITE 0x53570002
1492
1493#define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
1494#define VNC_MUTE_LINE_OUT 0x10
1495#define VNC_PHONE_DETECT 0x20
1496#define VNC_HANDSET_DETECT 0x40
1497#define VNC_DISABLE_AUTOSWITCH 0x80
1498
1499static inline void
1500vnc_mute_spkr(struct wavnc_info *devc)
1501{
1502 unsigned long flags;
1503
1504 raw_spin_lock_irqsave(&nw_gpio_lock, flags);
1505 nw_cpld_modify(CPLD_UNMUTE, devc->spkr_mute_state ? 0 : CPLD_UNMUTE);
1506 raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
1507}
1508
1509static void
1510vnc_mute_lout(struct wavnc_info *devc)
1511{
1512 unsigned int left, right;
1513
1514 left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL);
1515 right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x400);
1516
1517 if (devc->line_mute_state) {
1518 left &= ~1;
1519 right &= ~1;
1520 } else {
1521 left |= 1;
1522 right |= 1;
1523 }
1524 waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
1525
1526}
1527
1528static int
1529vnc_volume_slider(struct wavnc_info *devc)
1530{
1531 static signed int old_slider_volume;
1532 unsigned long flags;
1533 signed int volume = 255;
1534
1535 *CSR_TIMER1_LOAD = 0x00ffffff;
1536
1537 spin_lock_irqsave(&waveartist_lock, flags);
1538
1539 outb(0xFF, 0x201);
1540 *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
1541
1542 while (volume && (inb(0x201) & 0x01))
1543 volume--;
1544
1545 *CSR_TIMER1_CNTL = 0;
1546
1547 spin_unlock_irqrestore(&waveartist_lock,flags);
1548
1549 volume = 0x00ffffff - *CSR_TIMER1_VALUE;
1550
1551
1552#ifndef REVERSE
1553 volume = 150 - (volume >> 5);
1554#else
1555 volume = (volume >> 6) - 25;
1556#endif
1557
1558 if (volume < 0)
1559 volume = 0;
1560
1561 if (volume > 100)
1562 volume = 100;
1563
1564 /*
1565 * slider quite often reads +-8, so debounce this random noise
1566 */
1567 if (abs(volume - old_slider_volume) > 7) {
1568 old_slider_volume = volume;
1569
1570 if (debug_flg & DEBUG_MIXER)
1571 printk(KERN_DEBUG "Slider volume: %d.\n", volume);
1572 }
1573
1574 return old_slider_volume;
1575}
1576
1577/*
1578 * Decode a recording mask into a mixer selection on the NetWinder
1579 * as follows:
1580 *
1581 * OSS Source WA Source Actual source
1582 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1583 * SOUND_MASK_LINE Line Line in
1584 * SOUND_MASK_LINE1 Left Mic Handset
1585 * SOUND_MASK_PHONEIN Left Aux Telephone microphone
1586 * SOUND_MASK_MIC Right Mic Builtin microphone
1587 */
1588static unsigned int
1589netwinder_select_input(struct wavnc_info *devc, unsigned int recmask,
1590 unsigned char *dev_l, unsigned char *dev_r)
1591{
1592 unsigned int recdev_l = ADC_MUX_NONE, recdev_r = ADC_MUX_NONE;
1593
1594 if (recmask & SOUND_MASK_IMIX) {
1595 recmask = SOUND_MASK_IMIX;
1596 recdev_l = ADC_MUX_MIXER;
1597 recdev_r = ADC_MUX_MIXER;
1598 } else if (recmask & SOUND_MASK_LINE) {
1599 recmask = SOUND_MASK_LINE;
1600 recdev_l = ADC_MUX_LINE;
1601 recdev_r = ADC_MUX_LINE;
1602 } else if (recmask & SOUND_MASK_LINE1) {
1603 recmask = SOUND_MASK_LINE1;
1604 waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
1605 recdev_l = ADC_MUX_MIC;
1606 recdev_r = ADC_MUX_NONE;
1607 } else if (recmask & SOUND_MASK_PHONEIN) {
1608 recmask = SOUND_MASK_PHONEIN;
1609 waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
1610 recdev_l = ADC_MUX_AUX1;
1611 recdev_r = ADC_MUX_NONE;
1612 } else if (recmask & SOUND_MASK_MIC) {
1613 recmask = SOUND_MASK_MIC;
1614 waveartist_cmd1(devc, WACMD_SET_MONO | 0x100); /* right */
1615 recdev_l = ADC_MUX_NONE;
1616 recdev_r = ADC_MUX_MIC;
1617 }
1618
1619 *dev_l = recdev_l;
1620 *dev_r = recdev_r;
1621
1622 return recmask;
1623}
1624
1625static int
1626netwinder_decode_mixer(struct wavnc_info *devc, int dev, unsigned char lev_l,
1627 unsigned char lev_r)
1628{
1629 switch (dev) {
1630 case SOUND_MIXER_VOLUME:
1631 case SOUND_MIXER_SYNTH:
1632 case SOUND_MIXER_PCM:
1633 case SOUND_MIXER_LINE:
1634 case SOUND_MIXER_IGAIN:
1635 devc->levels[dev] = lev_l | lev_r << 8;
1636 break;
1637
1638 case SOUND_MIXER_MIC: /* right mic only */
1639 devc->levels[SOUND_MIXER_MIC] &= 0xff;
1640 devc->levels[SOUND_MIXER_MIC] |= lev_l << 8;
1641 break;
1642
1643 case SOUND_MIXER_LINE1: /* left mic only */
1644 devc->levels[SOUND_MIXER_MIC] &= 0xff00;
1645 devc->levels[SOUND_MIXER_MIC] |= lev_l;
1646 dev = SOUND_MIXER_MIC;
1647 break;
1648
1649 case SOUND_MIXER_PHONEIN: /* left aux only */
1650 devc->levels[SOUND_MIXER_LINE1] = lev_l;
1651 dev = SOUND_MIXER_LINE1;
1652 break;
1653
1654 case SOUND_MIXER_IMIX:
1655 case SOUND_MIXER_PHONEOUT:
1656 break;
1657
1658 default:
1659 dev = -EINVAL;
1660 break;
1661 }
1662 return dev;
1663}
1664
1665static int netwinder_get_mixer(struct wavnc_info *devc, int dev)
1666{
1667 int levels;
1668
1669 switch (dev) {
1670 case SOUND_MIXER_VOLUME:
1671 case SOUND_MIXER_SYNTH:
1672 case SOUND_MIXER_PCM:
1673 case SOUND_MIXER_LINE:
1674 case SOUND_MIXER_IGAIN:
1675 levels = devc->levels[dev];
1676 break;
1677
1678 case SOUND_MIXER_MIC: /* builtin mic: right mic only */
1679 levels = devc->levels[SOUND_MIXER_MIC] >> 8;
1680 levels |= levels << 8;
1681 break;
1682
1683 case SOUND_MIXER_LINE1: /* handset mic: left mic only */
1684 levels = devc->levels[SOUND_MIXER_MIC] & 0xff;
1685 levels |= levels << 8;
1686 break;
1687
1688 case SOUND_MIXER_PHONEIN: /* phone mic: left aux1 only */
1689 levels = devc->levels[SOUND_MIXER_LINE1] & 0xff;
1690 levels |= levels << 8;
1691 break;
1692
1693 default:
1694 levels = 0;
1695 }
1696
1697 return levels;
1698}
1699
1700/*
1701 * Waveartist specific mixer information.
1702 */
1703static const struct waveartist_mixer_info netwinder_mixer = {
1704 .supported_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
1705 SOUND_MASK_PCM | SOUND_MASK_SPEAKER |
1706 SOUND_MASK_LINE | SOUND_MASK_MIC |
1707 SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
1708 SOUND_MASK_PHONEIN | SOUND_MASK_PHONEOUT|
1709 SOUND_MASK_IGAIN,
1710
1711 .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
1712 SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
1713 SOUND_MASK_PHONEIN,
1714
1715 .stereo_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
1716 SOUND_MASK_PCM | SOUND_MASK_LINE |
1717 SOUND_MASK_IMIX | SOUND_MASK_IGAIN,
1718
1719 .select_input = netwinder_select_input,
1720 .decode_mixer = netwinder_decode_mixer,
1721 .get_mixer = netwinder_get_mixer,
1722};
1723
1724static void
1725vnc_configure_mixer(struct wavnc_info *devc, unsigned int recmask)
1726{
1727 if (!devc->no_autoselect) {
1728 if (devc->handset_detect) {
1729 recmask = SOUND_MASK_LINE1;
1730 devc->spkr_mute_state = devc->line_mute_state = 1;
1731 } else if (devc->telephone_detect) {
1732 recmask = SOUND_MASK_PHONEIN;
1733 devc->spkr_mute_state = devc->line_mute_state = 1;
1734 } else {
1735 /* unless someone has asked for LINE-IN,
1736 * we default to MIC
1737 */
1738 if ((devc->recmask & SOUND_MASK_LINE) == 0)
1739 devc->recmask = SOUND_MASK_MIC;
1740 devc->spkr_mute_state = devc->line_mute_state = 0;
1741 }
1742 vnc_mute_spkr(devc);
1743 vnc_mute_lout(devc);
1744
1745 if (recmask != devc->recmask)
1746 waveartist_set_recmask(devc, recmask);
1747 }
1748}
1749
1750static int
1751vnc_slider(struct wavnc_info *devc)
1752{
1753 signed int slider_volume;
1754 unsigned int temp, old_hs, old_td;
1755
1756 /*
1757 * read the "buttons" state.
1758 * Bit 4 = 0 means handset present
1759 * Bit 5 = 1 means phone offhook
1760 */
1761 temp = inb(0x201);
1762
1763 old_hs = devc->handset_detect;
1764 old_td = devc->telephone_detect;
1765
1766 devc->handset_detect = !(temp & 0x10);
1767 devc->telephone_detect = !!(temp & 0x20);
1768
1769 if (!devc->no_autoselect &&
1770 (old_hs != devc->handset_detect ||
1771 old_td != devc->telephone_detect))
1772 vnc_configure_mixer(devc, devc->recmask);
1773
1774 slider_volume = vnc_volume_slider(devc);
1775
1776 /*
1777 * If we're using software controlled volume, and
1778 * the slider moves by more than 20%, then we
1779 * switch back to slider controlled volume.
1780 */
1781 if (abs(devc->slider_vol - slider_volume) > 20)
1782 devc->use_slider = 1;
1783
1784 /*
1785 * use only left channel
1786 */
1787 temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
1788
1789 if (slider_volume != temp && devc->use_slider) {
1790 devc->slider_vol = slider_volume;
1791
1792 waveartist_set_mixer(devc, SOUND_MIXER_VOLUME,
1793 slider_volume | slider_volume << 8);
1794
1795 return 1;
1796 }
1797
1798 return 0;
1799}
1800
1801static void
1802vnc_slider_tick(unsigned long data)
1803{
1804 int next_timeout;
1805
1806 if (vnc_slider(adev_info + data))
1807 next_timeout = 5; // mixer reported change
1808 else
1809 next_timeout = VNC_TIMER_PERIOD;
1810
1811 mod_timer(&vnc_timer, jiffies + next_timeout);
1812}
1813
1814static int
1815vnc_private_ioctl(int dev, unsigned int cmd, int __user * arg)
1816{
1817 struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
1818 int val;
1819
1820 switch (cmd) {
1821 case SOUND_MIXER_PRIVATE1:
1822 {
1823 u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
1824 int val;
1825
1826 if (get_user(val, arg))
1827 return -EFAULT;
1828
1829 /* check if parameter is logical */
1830 if (val & ~(VNC_MUTE_INTERNAL_SPKR |
1831 VNC_MUTE_LINE_OUT |
1832 VNC_DISABLE_AUTOSWITCH))
1833 return -EINVAL;
1834
1835 prev_auto_state = devc->no_autoselect;
1836 prev_spkr_mute = devc->spkr_mute_state;
1837 prev_line_mute = devc->line_mute_state;
1838
1839 devc->no_autoselect = (val & VNC_DISABLE_AUTOSWITCH) ? 1 : 0;
1840 devc->spkr_mute_state = (val & VNC_MUTE_INTERNAL_SPKR) ? 1 : 0;
1841 devc->line_mute_state = (val & VNC_MUTE_LINE_OUT) ? 1 : 0;
1842
1843 if (prev_spkr_mute != devc->spkr_mute_state)
1844 vnc_mute_spkr(devc);
1845
1846 if (prev_line_mute != devc->line_mute_state)
1847 vnc_mute_lout(devc);
1848
1849 if (prev_auto_state != devc->no_autoselect)
1850 vnc_configure_mixer(devc, devc->recmask);
1851
1852 return 0;
1853 }
1854
1855 case SOUND_MIXER_PRIVATE2:
1856 if (get_user(val, arg))
1857 return -EFAULT;
1858
1859 switch (val) {
1860#define VNC_SOUND_PAUSE 0x53 //to pause the DSP
1861#define VNC_SOUND_RESUME 0x57 //to unpause the DSP
1862 case VNC_SOUND_PAUSE:
1863 waveartist_cmd1(devc, 0x16);
1864 break;
1865
1866 case VNC_SOUND_RESUME:
1867 waveartist_cmd1(devc, 0x18);
1868 break;
1869
1870 default:
1871 return -EINVAL;
1872 }
1873 return 0;
1874
1875 /* private ioctl to allow bulk access to waveartist */
1876 case SOUND_MIXER_PRIVATE3:
1877 {
1878 unsigned long flags;
1879 int mixer_reg[15], i, val;
1880
1881 if (get_user(val, arg))
1882 return -EFAULT;
1883 if (copy_from_user(mixer_reg, (void *)val, sizeof(mixer_reg)))
1884 return -EFAULT;
1885
1886 switch (mixer_reg[14]) {
1887 case MIXER_PRIVATE3_RESET:
1888 waveartist_mixer_reset(devc);
1889 break;
1890
1891 case MIXER_PRIVATE3_WRITE:
1892 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[0], mixer_reg[4]);
1893 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[1], mixer_reg[5]);
1894 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[2], mixer_reg[6]);
1895 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[3], mixer_reg[7]);
1896 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[8], mixer_reg[9]);
1897
1898 waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[10], mixer_reg[11]);
1899 waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[12], mixer_reg[13]);
1900 break;
1901
1902 case MIXER_PRIVATE3_READ:
1903 spin_lock_irqsave(&waveartist_lock, flags);
1904
1905 for (i = 0x30; i < 14 << 8; i += 1 << 8)
1906 waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
1907
1908 spin_unlock_irqrestore(&waveartist_lock, flags);
1909
1910 if (copy_to_user((void *)val, mixer_reg, sizeof(mixer_reg)))
1911 return -EFAULT;
1912 break;
1913
1914 default:
1915 return -EINVAL;
1916 }
1917 return 0;
1918 }
1919
1920 /* read back the state from PRIVATE1 */
1921 case SOUND_MIXER_PRIVATE4:
1922 val = (devc->spkr_mute_state ? VNC_MUTE_INTERNAL_SPKR : 0) |
1923 (devc->line_mute_state ? VNC_MUTE_LINE_OUT : 0) |
1924 (devc->handset_detect ? VNC_HANDSET_DETECT : 0) |
1925 (devc->telephone_detect ? VNC_PHONE_DETECT : 0) |
1926 (devc->no_autoselect ? VNC_DISABLE_AUTOSWITCH : 0);
1927
1928 return put_user(val, arg) ? -EFAULT : 0;
1929 }
1930
1931 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1932 /*
1933 * special case for master volume: if we
1934 * received this call - switch from hw
1935 * volume control to a software volume
1936 * control, till the hw volume is modified
1937 * to signal that user wants to be back in
1938 * hardware...
1939 */
1940 if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
1941 devc->use_slider = 0;
1942
1943 /* speaker output */
1944 if ((cmd & 0xff) == SOUND_MIXER_SPEAKER) {
1945 unsigned int val, l, r;
1946
1947 if (get_user(val, arg))
1948 return -EFAULT;
1949
1950 l = val & 0x7f;
1951 r = (val & 0x7f00) >> 8;
1952 val = (l + r) / 2;
1953 devc->levels[SOUND_MIXER_SPEAKER] = val | (val << 8);
1954 devc->spkr_mute_state = (val <= 50);
1955 vnc_mute_spkr(devc);
1956 return 0;
1957 }
1958 }
1959
1960 return -ENOIOCTLCMD;
1961}
1962
1963#endif
1964
1965static struct address_info cfg;
1966
1967static int attached;
1968
1969static int __initdata io = 0;
1970static int __initdata irq = 0;
1971static int __initdata dma = 0;
1972static int __initdata dma2 = 0;
1973
1974
1975static int __init init_waveartist(void)
1976{
1977 const struct waveartist_mixer_info *mix;
1978
1979 if (!io && machine_is_netwinder()) {
1980 /*
1981 * The NetWinder WaveArtist is at a fixed address.
1982 * If the user does not supply an address, use the
1983 * well-known parameters.
1984 */
1985 io = 0x250;
1986 irq = 12;
1987 dma = 3;
1988 dma2 = 7;
1989 }
1990
1991 mix = &waveartist_mixer;
1992#ifdef CONFIG_ARCH_NETWINDER
1993 if (machine_is_netwinder())
1994 mix = &netwinder_mixer;
1995#endif
1996
1997 cfg.io_base = io;
1998 cfg.irq = irq;
1999 cfg.dma = dma;
2000 cfg.dma2 = dma2;
2001
2002 if (!probe_waveartist(&cfg))
2003 return -ENODEV;
2004
2005 attach_waveartist(&cfg, mix);
2006 attached = 1;
2007
2008 return 0;
2009}
2010
2011static void __exit cleanup_waveartist(void)
2012{
2013 if (attached)
2014 unload_waveartist(&cfg);
2015}
2016
2017module_init(init_waveartist);
2018module_exit(cleanup_waveartist);
2019
2020#ifndef MODULE
2021static int __init setup_waveartist(char *str)
2022{
2023 /* io, irq, dma, dma2 */
2024 int ints[5];
2025
2026 str = get_options(str, ARRAY_SIZE(ints), ints);
2027
2028 io = ints[1];
2029 irq = ints[2];
2030 dma = ints[3];
2031 dma2 = ints[4];
2032
2033 return 1;
2034}
2035__setup("waveartist=", setup_waveartist);
2036#endif
2037
2038MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
2039module_param_hw(io, int, ioport, 0); /* IO base */
2040module_param_hw(irq, int, irq, 0); /* IRQ */
2041module_param_hw(dma, int, dma, 0); /* DMA */
2042module_param_hw(dma2, int, dma, 0); /* DMA2 */
2043MODULE_LICENSE("GPL");
diff --git a/sound/oss/waveartist.h b/sound/oss/waveartist.h
deleted file mode 100644
index dac4ca910d95..000000000000
--- a/sound/oss/waveartist.h
+++ /dev/null
@@ -1,92 +0,0 @@
1/*
2 * linux/sound/oss/waveartist.h
3 *
4 * def file for Rockwell RWA010 chip set, as installed in Rebel.com NetWinder
5 */
6
7//registers
8#define CMDR 0
9#define DATR 2
10#define CTLR 4
11#define STATR 5
12#define IRQSTAT 12
13
14//bit defs
15//reg STATR
16#define CMD_WE 0x80
17#define CMD_RF 0x40
18#define DAT_WE 0x20
19#define DAT_RF 0x10
20
21#define IRQ_REQ 0x08
22#define DMA1 0x04
23#define DMA0 0x02
24
25//bit defs
26//reg CTLR
27#define CMD_WEIE 0x80
28#define CMD_RFIE 0x40
29#define DAT_WEIE 0x20
30#define DAT_RFIE 0x10
31
32#define RESET 0x08
33#define DMA1_IE 0x04
34#define DMA0_IE 0x02
35#define IRQ_ACK 0x01
36
37//commands
38
39#define WACMD_SYSTEMID 0x00
40#define WACMD_GETREV 0x00
41#define WACMD_INPUTFORMAT 0x10 //0-8S, 1-16S, 2-8U
42#define WACMD_INPUTCHANNELS 0x11 //1-Mono, 2-Stereo
43#define WACMD_INPUTSPEED 0x12 //sampling rate
44#define WACMD_INPUTDMA 0x13 //0-8bit, 1-16bit, 2-PIO
45#define WACMD_INPUTSIZE 0x14 //samples to interrupt
46#define WACMD_INPUTSTART 0x15 //start ADC
47#define WACMD_INPUTPAUSE 0x16 //pause ADC
48#define WACMD_INPUTSTOP 0x17 //stop ADC
49#define WACMD_INPUTRESUME 0x18 //resume ADC
50#define WACMD_INPUTPIO 0x19 //PIO ADC
51
52#define WACMD_OUTPUTFORMAT 0x20 //0-8S, 1-16S, 2-8U
53#define WACMD_OUTPUTCHANNELS 0x21 //1-Mono, 2-Stereo
54#define WACMD_OUTPUTSPEED 0x22 //sampling rate
55#define WACMD_OUTPUTDMA 0x23 //0-8bit, 1-16bit, 2-PIO
56#define WACMD_OUTPUTSIZE 0x24 //samples to interrupt
57#define WACMD_OUTPUTSTART 0x25 //start ADC
58#define WACMD_OUTPUTPAUSE 0x26 //pause ADC
59#define WACMD_OUTPUTSTOP 0x27 //stop ADC
60#define WACMD_OUTPUTRESUME 0x28 //resume ADC
61#define WACMD_OUTPUTPIO 0x29 //PIO ADC
62
63#define WACMD_GET_LEVEL 0x30
64#define WACMD_SET_LEVEL 0x31
65#define WACMD_SET_MIXER 0x32
66#define WACMD_RST_MIXER 0x33
67#define WACMD_SET_MONO 0x34
68
69/*
70 * Definitions for left/right recording input mux
71 */
72#define ADC_MUX_NONE 0
73#define ADC_MUX_MIXER 1
74#define ADC_MUX_LINE 2
75#define ADC_MUX_AUX2 3
76#define ADC_MUX_AUX1 4
77#define ADC_MUX_MIC 5
78
79/*
80 * Definitions for mixer gain settings
81 */
82#define MIX_GAIN_LINE 0 /* line in */
83#define MIX_GAIN_AUX1 1 /* aux1 */
84#define MIX_GAIN_AUX2 2 /* aux2 */
85#define MIX_GAIN_XMIC 3 /* crossover mic */
86#define MIX_GAIN_MIC 4 /* normal mic */
87#define MIX_GAIN_PREMIC 5 /* preamp mic */
88#define MIX_GAIN_OUT 6 /* output */
89#define MIX_GAIN_MONO 7 /* mono in */
90
91int wa_sendcmd(unsigned int cmd);
92int wa_writecmd(unsigned int cmd, unsigned int arg);