aboutsummaryrefslogtreecommitdiffstats
path: root/sound/oss
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /sound/oss
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'sound/oss')
-rw-r--r--sound/oss/CHANGELOG369
-rw-r--r--sound/oss/COPYING339
-rw-r--r--sound/oss/Kconfig1120
-rw-r--r--sound/oss/Makefile187
-rw-r--r--sound/oss/README.FIRST6
-rw-r--r--sound/oss/ac97.c452
-rw-r--r--sound/oss/ac97.h204
-rw-r--r--sound/oss/ac97_codec.c1576
-rw-r--r--sound/oss/ac97_plugin_ad1980.c126
-rw-r--r--sound/oss/aci.c711
-rw-r--r--sound/oss/aci.h57
-rw-r--r--sound/oss/ad1816.c1369
-rw-r--r--sound/oss/ad1848.c3159
-rw-r--r--sound/oss/ad1848.h25
-rw-r--r--sound/oss/ad1848_mixer.h253
-rw-r--r--sound/oss/ad1889.c1103
-rw-r--r--sound/oss/ad1889.h134
-rw-r--r--sound/oss/adlib_card.c73
-rw-r--r--sound/oss/aedsp16.c1381
-rw-r--r--sound/oss/ali5455.c3733
-rw-r--r--sound/oss/au1000.c2214
-rw-r--r--sound/oss/au1550_ac97.c2119
-rw-r--r--sound/oss/audio.c983
-rw-r--r--sound/oss/audio_syms.c16
-rw-r--r--sound/oss/awe_hw.h99
-rw-r--r--sound/oss/awe_wave.c6147
-rw-r--r--sound/oss/awe_wave.h77
-rw-r--r--sound/oss/bin2hex.c39
-rw-r--r--sound/oss/btaudio.c1136
-rw-r--r--sound/oss/cmpci.c3378
-rw-r--r--sound/oss/coproc.h12
-rw-r--r--sound/oss/cs4232.c520
-rw-r--r--sound/oss/cs4281/Makefile6
-rw-r--r--sound/oss/cs4281/cs4281_hwdefs.h1234
-rw-r--r--sound/oss/cs4281/cs4281_wrapper-24.c41
-rw-r--r--sound/oss/cs4281/cs4281m.c4505
-rw-r--r--sound/oss/cs4281/cs4281pm-24.c84
-rw-r--r--sound/oss/cs4281/cs4281pm.h74
-rw-r--r--sound/oss/cs461x.h1691
-rw-r--r--sound/oss/cs461x_image.h322
-rw-r--r--sound/oss/cs46xx.c5794
-rw-r--r--sound/oss/cs46xx_wrapper-24.h56
-rw-r--r--sound/oss/cs46xxpm-24.h52
-rw-r--r--sound/oss/cs46xxpm.h70
-rw-r--r--sound/oss/dev_table.c214
-rw-r--r--sound/oss/dev_table.h405
-rw-r--r--sound/oss/dm.h79
-rw-r--r--sound/oss/dmabuf.c1298
-rw-r--r--sound/oss/dmasound/Kconfig58
-rw-r--r--sound/oss/dmasound/Makefile13
-rw-r--r--sound/oss/dmasound/awacs_defs.h251
-rw-r--r--sound/oss/dmasound/dac3550a.c210
-rw-r--r--sound/oss/dmasound/dmasound.h277
-rw-r--r--sound/oss/dmasound/dmasound_atari.c1600
-rw-r--r--sound/oss/dmasound/dmasound_awacs.c3176
-rw-r--r--sound/oss/dmasound/dmasound_core.c1829
-rw-r--r--sound/oss/dmasound/dmasound_paula.c743
-rw-r--r--sound/oss/dmasound/dmasound_q40.c634
-rw-r--r--sound/oss/dmasound/tas3001c.c850
-rw-r--r--sound/oss/dmasound/tas3001c.h64
-rw-r--r--sound/oss/dmasound/tas3001c_tables.c375
-rw-r--r--sound/oss/dmasound/tas3004.c1140
-rw-r--r--sound/oss/dmasound/tas3004.h77
-rw-r--r--sound/oss/dmasound/tas3004_tables.c301
-rw-r--r--sound/oss/dmasound/tas_common.c214
-rw-r--r--sound/oss/dmasound/tas_common.h284
-rw-r--r--sound/oss/dmasound/tas_eq_prefs.h24
-rw-r--r--sound/oss/dmasound/tas_ioctl.h24
-rw-r--r--sound/oss/dmasound/trans_16.c897
-rw-r--r--sound/oss/emu10k1/8010.h737
-rw-r--r--sound/oss/emu10k1/Makefile17
-rw-r--r--sound/oss/emu10k1/audio.c1588
-rw-r--r--sound/oss/emu10k1/audio.h44
-rw-r--r--sound/oss/emu10k1/cardmi.c832
-rw-r--r--sound/oss/emu10k1/cardmi.h97
-rw-r--r--sound/oss/emu10k1/cardmo.c229
-rw-r--r--sound/oss/emu10k1/cardmo.h62
-rw-r--r--sound/oss/emu10k1/cardwi.c373
-rw-r--r--sound/oss/emu10k1/cardwi.h91
-rw-r--r--sound/oss/emu10k1/cardwo.c643
-rw-r--r--sound/oss/emu10k1/cardwo.h90
-rw-r--r--sound/oss/emu10k1/ecard.c157
-rw-r--r--sound/oss/emu10k1/ecard.h113
-rw-r--r--sound/oss/emu10k1/efxmgr.c220
-rw-r--r--sound/oss/emu10k1/efxmgr.h270
-rw-r--r--sound/oss/emu10k1/emuadxmg.c104
-rw-r--r--sound/oss/emu10k1/hwaccess.c507
-rw-r--r--sound/oss/emu10k1/hwaccess.h247
-rw-r--r--sound/oss/emu10k1/icardmid.h163
-rw-r--r--sound/oss/emu10k1/icardwav.h53
-rw-r--r--sound/oss/emu10k1/irqmgr.c113
-rw-r--r--sound/oss/emu10k1/irqmgr.h52
-rw-r--r--sound/oss/emu10k1/main.c1475
-rw-r--r--sound/oss/emu10k1/midi.c613
-rw-r--r--sound/oss/emu10k1/midi.h78
-rw-r--r--sound/oss/emu10k1/mixer.c690
-rw-r--r--sound/oss/emu10k1/passthrough.c236
-rw-r--r--sound/oss/emu10k1/passthrough.h99
-rw-r--r--sound/oss/emu10k1/recmgr.c147
-rw-r--r--sound/oss/emu10k1/recmgr.h48
-rw-r--r--sound/oss/emu10k1/timer.c176
-rw-r--r--sound/oss/emu10k1/timer.h54
-rw-r--r--sound/oss/emu10k1/voicemgr.c398
-rw-r--r--sound/oss/emu10k1/voicemgr.h103
-rw-r--r--sound/oss/es1370.c2789
-rw-r--r--sound/oss/es1371.c3097
-rw-r--r--sound/oss/esssolo1.c2497
-rw-r--r--sound/oss/forte.c2137
-rw-r--r--sound/oss/gus.h24
-rw-r--r--sound/oss/gus_card.c293
-rw-r--r--sound/oss/gus_hw.h50
-rw-r--r--sound/oss/gus_linearvol.h18
-rw-r--r--sound/oss/gus_midi.c256
-rw-r--r--sound/oss/gus_vol.c153
-rw-r--r--sound/oss/gus_wave.c3464
-rw-r--r--sound/oss/hal2.c1557
-rw-r--r--sound/oss/hal2.h248
-rw-r--r--sound/oss/harmony.c1330
-rw-r--r--sound/oss/hex2hex.c101
-rw-r--r--sound/oss/i810_audio.c3658
-rw-r--r--sound/oss/ics2101.c247
-rw-r--r--sound/oss/ite8172.c2259
-rw-r--r--sound/oss/iwmem.h36
-rw-r--r--sound/oss/kahlua.c232
-rw-r--r--sound/oss/mad16.c1097
-rw-r--r--sound/oss/maestro.c3832
-rw-r--r--sound/oss/maestro.h60
-rw-r--r--sound/oss/maestro3.c2973
-rw-r--r--sound/oss/maestro3.h821
-rw-r--r--sound/oss/maui.c478
-rw-r--r--sound/oss/midi_ctrl.h22
-rw-r--r--sound/oss/midi_syms.c29
-rw-r--r--sound/oss/midi_synth.c697
-rw-r--r--sound/oss/midi_synth.h47
-rw-r--r--sound/oss/midibuf.c431
-rw-r--r--sound/oss/mpu401.c1826
-rw-r--r--sound/oss/mpu401.h14
-rw-r--r--sound/oss/msnd.c419
-rw-r--r--sound/oss/msnd.h280
-rw-r--r--sound/oss/msnd_classic.c3
-rw-r--r--sound/oss/msnd_classic.h188
-rw-r--r--sound/oss/msnd_pinnacle.c1922
-rw-r--r--sound/oss/msnd_pinnacle.h249
-rw-r--r--sound/oss/nec_vrc5477.c2059
-rw-r--r--sound/oss/nm256.h295
-rw-r--r--sound/oss/nm256_audio.c1707
-rw-r--r--sound/oss/nm256_coeff.h4697
-rw-r--r--sound/oss/opl3.c1257
-rw-r--r--sound/oss/opl3.h5
-rw-r--r--sound/oss/opl3_hw.h246
-rw-r--r--sound/oss/opl3sa.c329
-rw-r--r--sound/oss/opl3sa2.c1129
-rw-r--r--sound/oss/os.h51
-rw-r--r--sound/oss/pas2.h17
-rw-r--r--sound/oss/pas2_card.c458
-rw-r--r--sound/oss/pas2_midi.c262
-rw-r--r--sound/oss/pas2_mixer.c336
-rw-r--r--sound/oss/pas2_pcm.c437
-rw-r--r--sound/oss/pss.c1283
-rw-r--r--sound/oss/rme96xx.c1861
-rw-r--r--sound/oss/rme96xx.h78
-rw-r--r--sound/oss/sb.h185
-rw-r--r--sound/oss/sb_audio.c1098
-rw-r--r--sound/oss/sb_card.c347
-rw-r--r--sound/oss/sb_card.h149
-rw-r--r--sound/oss/sb_common.c1291
-rw-r--r--sound/oss/sb_ess.c1832
-rw-r--r--sound/oss/sb_ess.h34
-rw-r--r--sound/oss/sb_midi.c205
-rw-r--r--sound/oss/sb_mixer.c768
-rw-r--r--sound/oss/sb_mixer.h105
-rw-r--r--sound/oss/sequencer.c1684
-rw-r--r--sound/oss/sequencer_syms.c30
-rw-r--r--sound/oss/sgalaxy.c207
-rw-r--r--sound/oss/sh_dac_audio.c325
-rw-r--r--sound/oss/skeleton.c219
-rw-r--r--sound/oss/sonicvibes.c2792
-rw-r--r--sound/oss/sound_calls.h90
-rw-r--r--sound/oss/sound_config.h154
-rw-r--r--sound/oss/sound_firmware.h2
-rw-r--r--sound/oss/sound_syms.c50
-rw-r--r--sound/oss/sound_timer.c323
-rw-r--r--sound/oss/soundcard.c751
-rw-r--r--sound/oss/soundvers.h2
-rw-r--r--sound/oss/sscape.c1485
-rw-r--r--sound/oss/swarm_cs4297a.c2742
-rw-r--r--sound/oss/sys_timer.c289
-rw-r--r--sound/oss/trident.c4628
-rw-r--r--sound/oss/trident.h358
-rw-r--r--sound/oss/trix.c525
-rw-r--r--sound/oss/tuning.h29
-rw-r--r--sound/oss/uart401.c481
-rw-r--r--sound/oss/uart6850.c362
-rw-r--r--sound/oss/ulaw.h69
-rw-r--r--sound/oss/v_midi.c291
-rw-r--r--sound/oss/v_midi.h15
-rw-r--r--sound/oss/via82cxxx_audio.c3615
-rw-r--r--sound/oss/vidc.c561
-rw-r--r--sound/oss/vidc.h67
-rw-r--r--sound/oss/vidc_fill.S218
-rw-r--r--sound/oss/vwsnd.c3486
-rw-r--r--sound/oss/waveartist.c2035
-rw-r--r--sound/oss/waveartist.h92
-rw-r--r--sound/oss/wavfront.c3538
-rw-r--r--sound/oss/wf_midi.c880
-rw-r--r--sound/oss/ymfpci.c2691
-rw-r--r--sound/oss/ymfpci.h360
-rw-r--r--sound/oss/ymfpci_image.h1565
-rw-r--r--sound/oss/yss225.c319
-rw-r--r--sound/oss/yss225.h24
210 files changed, 172711 insertions, 0 deletions
diff --git a/sound/oss/CHANGELOG b/sound/oss/CHANGELOG
new file mode 100644
index 000000000000..8706cd66ca1f
--- /dev/null
+++ b/sound/oss/CHANGELOG
@@ -0,0 +1,369 @@
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/COPYING b/sound/oss/COPYING
new file mode 100644
index 000000000000..916d1f0f2842
--- /dev/null
+++ b/sound/oss/COPYING
@@ -0,0 +1,339 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 2, June 1991
3
4 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9 Preamble
10
11 The licenses for most software are designed to take away your
12freedom to share and change it. By contrast, the GNU General Public
13License is intended to guarantee your freedom to share and change free
14software--to make sure the software is free for all its users. This
15General Public License applies to most of the Free Software
16Foundation's software and to any other program whose authors commit to
17using it. (Some other Free Software Foundation software is covered by
18the GNU Library General Public License instead.) You can apply it to
19your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22price. Our General Public Licenses are designed to make sure that you
23have the freedom to distribute copies of free software (and charge for
24this service if you wish), that you receive source code or can get it
25if you want it, that you can change the software or use pieces of it
26in new free programs; and that you know you can do these things.
27
28 To protect your rights, we need to make restrictions that forbid
29anyone to deny you these rights or to ask you to surrender the rights.
30These restrictions translate to certain responsibilities for you if you
31distribute copies of the software, or if you modify it.
32
33 For example, if you distribute copies of such a program, whether
34gratis or for a fee, you must give the recipients all the rights that
35you have. You must make sure that they, too, receive or can get the
36source code. And you must show them these terms so they know their
37rights.
38
39 We protect your rights with two steps: (1) copyright the software, and
40(2) offer you this license which gives you legal permission to copy,
41distribute and/or modify the software.
42
43 Also, for each author's protection and ours, we want to make certain
44that everyone understands that there is no warranty for this free
45software. If the software is modified by someone else and passed on, we
46want its recipients to know that what they have is not the original, so
47that any problems introduced by others will not reflect on the original
48authors' reputations.
49
50 Finally, any free program is threatened constantly by software
51patents. We wish to avoid the danger that redistributors of a free
52program will individually obtain patent licenses, in effect making the
53program proprietary. To prevent this, we have made it clear that any
54patent must be licensed for everyone's free use or not licensed at all.
55
56 The precise terms and conditions for copying, distribution and
57modification follow.
58
59 GNU GENERAL PUBLIC LICENSE
60 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
62 0. This License applies to any program or other work which contains
63a notice placed by the copyright holder saying it may be distributed
64under the terms of this General Public License. The "Program", below,
65refers to any such program or work, and a "work based on the Program"
66means either the Program or any derivative work under copyright law:
67that is to say, a work containing the Program or a portion of it,
68either verbatim or with modifications and/or translated into another
69language. (Hereinafter, translation is included without limitation in
70the term "modification".) Each licensee is addressed as "you".
71
72Activities other than copying, distribution and modification are not
73covered by this License; they are outside its scope. The act of
74running the Program is not restricted, and the output from the Program
75is covered only if its contents constitute a work based on the
76Program (independent of having been made by running the Program).
77Whether that is true depends on what the Program does.
78
79 1. You may copy and distribute verbatim copies of the Program's
80source code as you receive it, in any medium, provided that you
81conspicuously and appropriately publish on each copy an appropriate
82copyright notice and disclaimer of warranty; keep intact all the
83notices that refer to this License and to the absence of any warranty;
84and give any other recipients of the Program a copy of this License
85along with the Program.
86
87You may charge a fee for the physical act of transferring a copy, and
88you may at your option offer warranty protection in exchange for a fee.
89
90 2. You may modify your copy or copies of the Program or any portion
91of it, thus forming a work based on the Program, and copy and
92distribute such modifications or work under the terms of Section 1
93above, provided that you also meet all of these conditions:
94
95 a) You must cause the modified files to carry prominent notices
96 stating that you changed the files and the date of any change.
97
98 b) You must cause any work that you distribute or publish, that in
99 whole or in part contains or is derived from the Program or any
100 part thereof, to be licensed as a whole at no charge to all third
101 parties under the terms of this License.
102
103 c) If the modified program normally reads commands interactively
104 when run, you must cause it, when started running for such
105 interactive use in the most ordinary way, to print or display an
106 announcement including an appropriate copyright notice and a
107 notice that there is no warranty (or else, saying that you provide
108 a warranty) and that users may redistribute the program under
109 these conditions, and telling the user how to view a copy of this
110 License. (Exception: if the Program itself is interactive but
111 does not normally print such an announcement, your work based on
112 the Program is not required to print an announcement.)
113
114These requirements apply to the modified work as a whole. If
115identifiable sections of that work are not derived from the Program,
116and can be reasonably considered independent and separate works in
117themselves, then this License, and its terms, do not apply to those
118sections when you distribute them as separate works. But when you
119distribute the same sections as part of a whole which is a work based
120on the Program, the distribution of the whole must be on the terms of
121this License, whose permissions for other licensees extend to the
122entire whole, and thus to each and every part regardless of who wrote it.
123
124Thus, it is not the intent of this section to claim rights or contest
125your rights to work written entirely by you; rather, the intent is to
126exercise the right to control the distribution of derivative or
127collective works based on the Program.
128
129In addition, mere aggregation of another work not based on the Program
130with the Program (or with a work based on the Program) on a volume of
131a storage or distribution medium does not bring the other work under
132the scope of this License.
133
134 3. You may copy and distribute the Program (or a work based on it,
135under Section 2) in object code or executable form under the terms of
136Sections 1 and 2 above provided that you also do one of the following:
137
138 a) Accompany it with the complete corresponding machine-readable
139 source code, which must be distributed under the terms of Sections
140 1 and 2 above on a medium customarily used for software interchange; or,
141
142 b) Accompany it with a written offer, valid for at least three
143 years, to give any third party, for a charge no more than your
144 cost of physically performing source distribution, a complete
145 machine-readable copy of the corresponding source code, to be
146 distributed under the terms of Sections 1 and 2 above on a medium
147 customarily used for software interchange; or,
148
149 c) Accompany it with the information you received as to the offer
150 to distribute corresponding source code. (This alternative is
151 allowed only for noncommercial distribution and only if you
152 received the program in object code or executable form with such
153 an offer, in accord with Subsection b above.)
154
155The source code for a work means the preferred form of the work for
156making modifications to it. For an executable work, complete source
157code means all the source code for all modules it contains, plus any
158associated interface definition files, plus the scripts used to
159control compilation and installation of the executable. However, as a
160special exception, the source code distributed need not include
161anything that is normally distributed (in either source or binary
162form) with the major components (compiler, kernel, and so on) of the
163operating system on which the executable runs, unless that component
164itself accompanies the executable.
165
166If distribution of executable or object code is made by offering
167access to copy from a designated place, then offering equivalent
168access to copy the source code from the same place counts as
169distribution of the source code, even though third parties are not
170compelled to copy the source along with the object code.
171
172 4. You may not copy, modify, sublicense, or distribute the Program
173except as expressly provided under this License. Any attempt
174otherwise to copy, modify, sublicense or distribute the Program is
175void, and will automatically terminate your rights under this License.
176However, parties who have received copies, or rights, from you under
177this License will not have their licenses terminated so long as such
178parties remain in full compliance.
179
180 5. You are not required to accept this License, since you have not
181signed it. However, nothing else grants you permission to modify or
182distribute the Program or its derivative works. These actions are
183prohibited by law if you do not accept this License. Therefore, by
184modifying or distributing the Program (or any work based on the
185Program), you indicate your acceptance of this License to do so, and
186all its terms and conditions for copying, distributing or modifying
187the Program or works based on it.
188
189 6. Each time you redistribute the Program (or any work based on the
190Program), the recipient automatically receives a license from the
191original licensor to copy, distribute or modify the Program subject to
192these terms and conditions. You may not impose any further
193restrictions on the recipients' exercise of the rights granted herein.
194You are not responsible for enforcing compliance by third parties to
195this License.
196
197 7. If, as a consequence of a court judgment or allegation of patent
198infringement or for any other reason (not limited to patent issues),
199conditions are imposed on you (whether by court order, agreement or
200otherwise) that contradict the conditions of this License, they do not
201excuse you from the conditions of this License. If you cannot
202distribute so as to satisfy simultaneously your obligations under this
203License and any other pertinent obligations, then as a consequence you
204may not distribute the Program at all. For example, if a patent
205license would not permit royalty-free redistribution of the Program by
206all those who receive copies directly or indirectly through you, then
207the only way you could satisfy both it and this License would be to
208refrain entirely from distribution of the Program.
209
210If any portion of this section is held invalid or unenforceable under
211any particular circumstance, the balance of the section is intended to
212apply and the section as a whole is intended to apply in other
213circumstances.
214
215It is not the purpose of this section to induce you to infringe any
216patents or other property right claims or to contest validity of any
217such claims; this section has the sole purpose of protecting the
218integrity of the free software distribution system, which is
219implemented by public license practices. Many people have made
220generous contributions to the wide range of software distributed
221through that system in reliance on consistent application of that
222system; it is up to the author/donor to decide if he or she is willing
223to distribute software through any other system and a licensee cannot
224impose that choice.
225
226This section is intended to make thoroughly clear what is believed to
227be a consequence of the rest of this License.
228
229 8. If the distribution and/or use of the Program is restricted in
230certain countries either by patents or by copyrighted interfaces, the
231original copyright holder who places the Program under this License
232may add an explicit geographical distribution limitation excluding
233those countries, so that distribution is permitted only in or among
234countries not thus excluded. In such case, this License incorporates
235the limitation as if written in the body of this License.
236
237 9. The Free Software Foundation may publish revised and/or new versions
238of the General Public License from time to time. Such new versions will
239be similar in spirit to the present version, but may differ in detail to
240address new problems or concerns.
241
242Each version is given a distinguishing version number. If the Program
243specifies a version number of this License which applies to it and "any
244later version", you have the option of following the terms and conditions
245either of that version or of any later version published by the Free
246Software Foundation. If the Program does not specify a version number of
247this License, you may choose any version ever published by the Free Software
248Foundation.
249
250 10. If you wish to incorporate parts of the Program into other free
251programs whose distribution conditions are different, write to the author
252to ask for permission. For software which is copyrighted by the Free
253Software Foundation, write to the Free Software Foundation; we sometimes
254make exceptions for this. Our decision will be guided by the two goals
255of preserving the free status of all derivatives of our free software and
256of promoting the sharing and reuse of software generally.
257
258 NO WARRANTY
259
260 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268REPAIR OR CORRECTION.
269
270 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278POSSIBILITY OF SUCH DAMAGES.
279
280 END OF TERMS AND CONDITIONS
281
282 Appendix: How to Apply These Terms to Your New Programs
283
284 If you develop a new program, and you want it to be of the greatest
285possible use to the public, the best way to achieve this is to make it
286free software which everyone can redistribute and change under these terms.
287
288 To do so, attach the following notices to the program. It is safest
289to attach them to the start of each source file to most effectively
290convey the exclusion of warranty; and each file should have at least
291the "copyright" line and a pointer to where the full notice is found.
292
293 <one line to give the program's name and a brief idea of what it does.>
294 Copyright (C) 19yy <name of author>
295
296 This program is free software; you can redistribute it and/or modify
297 it under the terms of the GNU General Public License as published by
298 the Free Software Foundation; either version 2 of the License, or
299 (at your option) any later version.
300
301 This program is distributed in the hope that it will be useful,
302 but WITHOUT ANY WARRANTY; without even the implied warranty of
303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 GNU General Public License for more details.
305
306 You should have received a copy of the GNU General Public License
307 along with this program; if not, write to the Free Software
308 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
309
310Also add information on how to contact you by electronic and paper mail.
311
312If the program is interactive, make it output a short notice like this
313when it starts in an interactive mode:
314
315 Gnomovision version 69, Copyright (C) 19yy name of author
316 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 This is free software, and you are welcome to redistribute it
318 under certain conditions; type `show c' for details.
319
320The hypothetical commands `show w' and `show c' should show the appropriate
321parts of the General Public License. Of course, the commands you use may
322be called something other than `show w' and `show c'; they could even be
323mouse-clicks or menu items--whatever suits your program.
324
325You should also get your employer (if you work as a programmer) or your
326school, if any, to sign a "copyright disclaimer" for the program, if
327necessary. Here is a sample; alter the names:
328
329 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
332 <signature of Ty Coon>, 1 April 1989
333 Ty Coon, President of Vice
334
335This General Public License does not permit incorporating your program into
336proprietary programs. If your program is a subroutine library, you may
337consider it more useful to permit linking proprietary applications with the
338library. If this is what you want to do, use the GNU Library General
339Public License instead of this License.
diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig
new file mode 100644
index 000000000000..d303c2ed6e5a
--- /dev/null
+++ b/sound/oss/Kconfig
@@ -0,0 +1,1120 @@
1# drivers/sound/Config.in
2#
3# 18 Apr 1998, Michael Elizabeth Chastain, <mailto:mec@shout.net>
4# More hacking for modularisation.
5#
6# Prompt user for primary drivers.
7config SOUND_BT878
8 tristate "BT878 audio dma"
9 depends on SOUND_PRIME!=n && SOUND
10 ---help---
11 Audio DMA support for bt878 based grabber boards. As you might have
12 already noticed, bt878 is listed with two functions in /proc/pci.
13 Function 0 does the video stuff (bt848 compatible), function 1 does
14 the same for audio data. This is a driver for the audio part of
15 the chip. If you say 'Y' here you get a oss-compatible dsp device
16 where you can record from. If you want just watch TV you probably
17 don't need this driver as most TV cards handle sound with a short
18 cable from the TV card to your sound card's line-in.
19
20 To compile this driver as a module, choose M here: the module will
21 be called btaudio.
22
23config SOUND_CMPCI
24 tristate "C-Media PCI (CMI8338/8738)"
25 depends on SOUND_PRIME!=n && SOUND && PCI
26 help
27 Say Y or M if you have a PCI sound card using the CMI8338
28 or the CMI8738 chipset. Data on these chips are available at
29 <http://www.cmedia.com.tw/>.
30
31 A userspace utility to control some internal registers of these
32 chips is available at
33 <http://member.nifty.ne.jp/Breeze/softwares/unix/cmictl-e.html>.
34
35config SOUND_CMPCI_FM
36 bool "Enable legacy FM"
37 depends on SOUND_CMPCI && X86
38 help
39 Say Y here to enable the legacy FM (frequency-modulation) synthesizer
40 support on a card using the CMI8338 or CMI8378 chipset. Even it is
41 enabled, you need to set fmio as proper value to enable it.
42 Say N here if you don't need this.
43
44config SOUND_CMPCI_MIDI
45 bool "Enable legacy MPU-401"
46 depends on SOUND_CMPCI && X86
47 help
48 Say Y here to enable the legacy MPU401 MIDI synthesizer support on a
49 card using the CMI8338 or CMI8378 chipset. Even it is enabled,
50 you need to set mpuio as proper value to enable it.
51 Say N here if you don't need this.
52
53config SOUND_CMPCI_JOYSTICK
54 bool "Enable joystick"
55 depends on SOUND_CMPCI && X86
56 help
57 Say Y here in order to enable the joystick port on a sound card using
58 the CMI8338 or the CMI8738 chipset. You need to config the
59 gameport support and set joystick parameter as 1 to use it.
60 Say N here if you don't need this.
61
62config SOUND_EMU10K1
63 tristate "Creative SBLive! (EMU10K1)"
64 depends on SOUND_PRIME!=n && SOUND && PCI
65 ---help---
66 Say Y or M if you have a PCI sound card using the EMU10K1 chipset,
67 such as the Creative SBLive!, SB PCI512 or Emu-APS.
68
69 For more information on this driver and the degree of support for
70 the different card models please check:
71
72 <http://sourceforge.net/projects/emu10k1/>
73
74 It is now possible to load dsp microcode patches into the EMU10K1
75 chip. These patches are used to implement real time sound
76 processing effects which include for example: signal routing,
77 bass/treble control, AC3 passthrough, ...
78 Userspace tools to create new patches and load/unload them can be
79 found in the emu-tools package at the above URL.
80
81config MIDI_EMU10K1
82 bool "Creative SBLive! MIDI (EXPERIMENTAL)"
83 depends on SOUND_EMU10K1 && EXPERIMENTAL
84 help
85 Say Y if you want to be able to use the OSS /dev/sequencer
86 interface. This code is still experimental.
87
88config SOUND_FUSION
89 tristate "Crystal SoundFusion (CS4280/461x)"
90 depends on SOUND_PRIME!=n && SOUND
91 help
92 This module drives the Crystal SoundFusion devices (CS4280/46xx
93 series) when wired as native sound drivers with AC97 codecs. If
94 this driver does not work try the CS4232 driver.
95
96config SOUND_CS4281
97 tristate "Crystal Sound CS4281"
98 depends on SOUND_PRIME!=n && SOUND
99 help
100 Picture and feature list at
101 <http://www.pcbroker.com/crystal4281.html>.
102
103config SOUND_BCM_CS4297A
104 tristate "Crystal Sound CS4297a (for Swarm)"
105 depends on SOUND_PRIME!=n && SIBYTE_SWARM && SOUND
106 help
107 The BCM91250A has a Crystal CS4297a on synchronous serial
108 port B (in addition to the DB-9 serial port). Say Y or M
109 here to enable the sound chip instead of the UART. Also
110 note that CONFIG_KGDB should not be enabled at the same
111 time, since it also attempts to use this UART port.
112
113config SOUND_ES1370
114 tristate "Ensoniq AudioPCI (ES1370)"
115 depends on SOUND_PRIME!=n && SOUND && PCI && SOUND_GAMEPORT
116 help
117 Say Y or M if you have a PCI sound card utilizing the Ensoniq
118 ES1370 chipset, such as Ensoniq's AudioPCI (non-97). To find
119 out if your sound card uses an ES1370 without removing your
120 computer's cover, use lspci -n and look for the PCI ID
121 1274:5000. Since Ensoniq was bought by Creative Labs,
122 Sound Blaster 64/PCI models are either ES1370 or ES1371 based.
123 This driver differs slightly from OSS/Free, so PLEASE READ
124 <file:Documentation/sound/oss/es1370>.
125
126config SOUND_ES1371
127 tristate "Creative Ensoniq AudioPCI 97 (ES1371)"
128 depends on SOUND_PRIME!=n && SOUND && PCI && SOUND_GAMEPORT
129 help
130 Say Y or M if you have a PCI sound card utilizing the Ensoniq
131 ES1371 chipset, such as Ensoniq's AudioPCI97. To find out if
132 your sound card uses an ES1371 without removing your computer's
133 cover, use lspci -n and look for the PCI ID 1274:1371. Since
134 Ensoniq was bought by Creative Labs, Sound Blaster 64/PCI
135 models are either ES1370 or ES1371 based. This driver differs
136 slightly from OSS/Free, so PLEASE READ
137 <file:Documentation/sound/oss/es1371>.
138
139config SOUND_ESSSOLO1
140 tristate "ESS Technology Solo1"
141 depends on SOUND_PRIME!=n && SOUND && SOUND_GAMEPORT && PCI
142 help
143 Say Y or M if you have a PCI sound card utilizing the ESS Technology
144 Solo1 chip. To find out if your sound card uses a
145 Solo1 chip without removing your computer's cover, use
146 lspci -n and look for the PCI ID 125D:1969. This driver
147 differs slightly from OSS/Free, so PLEASE READ
148 <file:Documentation/sound/oss/solo1>.
149
150config SOUND_MAESTRO
151 tristate "ESS Maestro, Maestro2, Maestro2E driver"
152 depends on SOUND_PRIME!=n && SOUND && PCI
153 help
154 Say Y or M if you have a sound system driven by ESS's Maestro line
155 of PCI sound chips. These include the Maestro 1, Maestro 2, and
156 Maestro 2E. See <file:Documentation/sound/oss/Maestro> for more
157 details.
158
159config SOUND_MAESTRO3
160 tristate "ESS Maestro3/Allegro driver (EXPERIMENTAL)"
161 depends on SOUND_PRIME!=n && SOUND && PCI && EXPERIMENTAL
162 help
163 Say Y or M if you have a sound system driven by ESS's Maestro 3
164 PCI sound chip.
165
166config SOUND_ICH
167 tristate "Intel ICH (i8xx) audio support"
168 depends on SOUND_PRIME!=n && PCI
169 help
170 Support for integral audio in Intel's I/O Controller Hub (ICH)
171 chipset, as used on the 810/820/840 motherboards.
172
173config SOUND_HARMONY
174 tristate "PA Harmony audio driver"
175 depends on GSC_LASI && SOUND_PRIME!=n
176 help
177 Say 'Y' or 'M' to include support for Harmony soundchip
178 on HP 712, 715/new and many other GSC based machines.
179
180config SOUND_SONICVIBES
181 tristate "S3 SonicVibes"
182 depends on SOUND_PRIME!=n && SOUND && SOUND_GAMEPORT
183 help
184 Say Y or M if you have a PCI sound card utilizing the S3
185 SonicVibes chipset. To find out if your sound card uses a
186 SonicVibes chip without removing your computer's cover, use
187 lspci -n and look for the PCI ID 5333:CA00. This driver
188 differs slightly from OSS/Free, so PLEASE READ
189 <file:Documentation/sound/oss/sonicvibes>.
190
191config SOUND_VWSND
192 tristate "SGI Visual Workstation Sound"
193 depends on SOUND_PRIME!=n && X86_VISWS && SOUND
194 help
195 Say Y or M if you have an SGI Visual Workstation and you want to be
196 able to use its on-board audio. Read
197 <file:Documentation/sound/oss/vwsnd> for more info on this driver's
198 capabilities.
199
200config SOUND_HAL2
201 tristate "SGI HAL2 sound (EXPERIMENTAL)"
202 depends on SOUND_PRIME!=n && SOUND && SGI_IP22 && EXPERIMENTAL
203 help
204 Say Y or M if you have an SGI Indy system and want to be able to
205 use it's on-board A2 audio system.
206
207config SOUND_IT8172
208 tristate "IT8172G Sound"
209 depends on SOUND_PRIME!=n && (MIPS_ITE8172 || MIPS_IVR) && SOUND
210
211config SOUND_VRC5477
212 tristate "NEC Vrc5477 AC97 sound"
213 depends on SOUND_PRIME!=n && DDB5477 && SOUND
214 help
215 Say Y here to enable sound support for the NEC Vrc5477 chip, an
216 integrated, multi-function controller chip for MIPS CPUs. Works
217 with the AC97 codec.
218
219config SOUND_AU1000
220 tristate "Au1000 Sound"
221 depends on SOUND_PRIME!=n && (SOC_AU1000 || SOC_AU1100 || SOC_AU1500) && SOUND
222
223config SOUND_AU1550_AC97
224 tristate "Au1550 AC97 Sound"
225 depends on SOUND_PRIME!=n && SOC_AU1550 && SOUND
226
227config SOUND_TRIDENT
228 tristate "Trident 4DWave DX/NX, SiS 7018 or ALi 5451 PCI Audio Core"
229 depends on SOUND_PRIME!=n && SOUND && SOUND_GAMEPORT
230 ---help---
231 Say Y or M if you have a PCI sound card utilizing the Trident
232 4DWave-DX/NX chipset or your mother board chipset has SiS 7018
233 or ALi 5451 built-in. The SiS 7018 PCI Audio Core is embedded
234 in SiS960 Super South Bridge and SiS540/630 Single Chipset.
235 The ALi 5451 PCI Audio Core is embedded in ALi M1535, M1535D,
236 M1535+ or M1535D+ South Bridge.
237
238 Use lspci -n to find out if your sound card or chipset uses
239 Trident 4DWave or SiS 7018. PCI ID 1023:2000 or 1023:2001 stands
240 for Trident 4Dwave. PCI ID 1039:7018 stands for SiS7018. PCI ID
241 10B9:5451 stands for ALi5451.
242
243 This driver supports S/PDIF in/out (record/playback) for ALi 5451
244 embedded in ALi M1535+ and M1535D+. Note that they aren't all
245 enabled by default; you can enable them by saying Y to "/proc file
246 system support" and "Sysctl support", and after the /proc file
247 system has been mounted, executing the command
248
249 command what is enabled
250
251 echo 0>/proc/ALi5451 pcm out is also set to S/PDIF out. (Default).
252
253 echo 1>/proc/ALi5451 use S/PDIF out to output pcm data.
254
255 echo 2>/proc/ALi5451 use S/PDIF out to output non-pcm data.
256 (AC3...).
257
258 echo 3>/proc/ALi5451 record from Ac97 in(MIC, Line in...).
259 (Default).
260
261 echo 4>/proc/ALi5451 no matter Ac97 settings, record from S/PDIF
262 in.
263
264
265 This driver differs slightly from OSS/Free, so PLEASE READ the
266 comments at the top of <file:drivers/sound/trident.c>.
267
268config SOUND_MSNDCLAS
269 tristate "Support for Turtle Beach MultiSound Classic, Tahiti, Monterey"
270 depends on SOUND_PRIME!=n && SOUND && (m || !STANDALONE)
271 help
272 Say M here if you have a Turtle Beach MultiSound Classic, Tahiti or
273 Monterey (not for the Pinnacle or Fiji).
274
275 See <file:Documentation/sound/oss/MultiSound> for important information
276 about this driver. Note that it has been discontinued, but the
277 Voyetra Turtle Beach knowledge base entry for it is still available
278 at <http://www.turtlebeach.com/site/kb_ftp/790.asp>.
279
280comment "Compiled-in MSND Classic support requires firmware during compilation."
281 depends on SOUND_PRIME && SOUND_MSNDCLAS=y
282
283config MSNDCLAS_HAVE_BOOT
284 bool
285 depends on SOUND_MSNDCLAS=y && !STANDALONE
286 default y
287
288config MSNDCLAS_INIT_FILE
289 string "Full pathname of MSNDINIT.BIN firmware file"
290 depends on SOUND_MSNDCLAS
291 default "/etc/sound/msndinit.bin"
292 help
293 The MultiSound cards have two firmware files which are required for
294 operation, and are not currently included. These files can be
295 obtained from Turtle Beach. See
296 <file:Documentation/sound/oss/MultiSound> for information on how to
297 obtain this.
298
299config MSNDCLAS_PERM_FILE
300 string "Full pathname of MSNDPERM.BIN firmware file"
301 depends on SOUND_MSNDCLAS
302 default "/etc/sound/msndperm.bin"
303 help
304 The MultiSound cards have two firmware files which are required for
305 operation, and are not currently included. These files can be
306 obtained from Turtle Beach. See
307 <file:Documentation/sound/oss/MultiSound> for information on how to
308 obtain this.
309
310config MSNDCLAS_IRQ
311 int "MSND Classic IRQ 5, 7, 9, 10, 11, 12"
312 depends on SOUND_MSNDCLAS=y
313 default "5"
314 help
315 Interrupt Request line for the MultiSound Classic and related cards.
316
317config MSNDCLAS_MEM
318 hex "MSND Classic memory B0000, C8000, D0000, D8000, E0000, E8000"
319 depends on SOUND_MSNDCLAS=y
320 default "D0000"
321 help
322 Memory-mapped I/O base address for the MultiSound Classic and
323 related cards.
324
325config MSNDCLAS_IO
326 hex "MSND Classic I/O 210, 220, 230, 240, 250, 260, 290, 3E0"
327 depends on SOUND_MSNDCLAS=y
328 default "290"
329 help
330 I/O port address for the MultiSound Classic and related cards.
331
332config SOUND_MSNDPIN
333 tristate "Support for Turtle Beach MultiSound Pinnacle, Fiji"
334 depends on SOUND_PRIME!=n && SOUND && (m || !STANDALONE)
335 help
336 Say M here if you have a Turtle Beach MultiSound Pinnacle or Fiji.
337 See <file:Documentation/sound/oss/MultiSound> for important information
338 about this driver. Note that it has been discontinued, but the
339 Voyetra Turtle Beach knowledge base entry for it is still available
340 at <http://www.turtlebeach.com/site/kb_ftp/600.asp>.
341
342comment "Compiled-in MSND Pinnacle support requires firmware during compilation."
343 depends on SOUND_PRIME && SOUND_MSNDPIN=y
344
345config MSNDPIN_HAVE_BOOT
346 bool
347 depends on SOUND_MSNDPIN=y
348 default y
349
350config MSNDPIN_INIT_FILE
351 string "Full pathname of PNDSPINI.BIN firmware file"
352 depends on SOUND_MSNDPIN
353 default "/etc/sound/pndspini.bin"
354 help
355 The MultiSound cards have two firmware files which are required
356 for operation, and are not currently included. These files can be
357 obtained from Turtle Beach. See
358 <file:Documentation/sound/oss/MultiSound> for information on how to
359 obtain this.
360
361config MSNDPIN_PERM_FILE
362 string "Full pathname of PNDSPERM.BIN firmware file"
363 depends on SOUND_MSNDPIN
364 default "/etc/sound/pndsperm.bin"
365 help
366 The MultiSound cards have two firmware files which are required for
367 operation, and are not currently included. These files can be
368 obtained from Turtle Beach. See
369 <file:Documentation/sound/oss/MultiSound> for information on how to
370 obtain this.
371
372config MSNDPIN_IRQ
373 int "MSND Pinnacle IRQ 5, 7, 9, 10, 11, 12"
374 depends on SOUND_MSNDPIN=y
375 default "5"
376 help
377 Interrupt request line for the primary synthesizer on MultiSound
378 Pinnacle and Fiji sound cards.
379
380config MSNDPIN_MEM
381 hex "MSND Pinnacle memory B0000, C8000, D0000, D8000, E0000, E8000"
382 depends on SOUND_MSNDPIN=y
383 default "D0000"
384 help
385 Memory-mapped I/O base address for the primary synthesizer on
386 MultiSound Pinnacle and Fiji sound cards.
387
388config MSNDPIN_IO
389 hex "MSND Pinnacle I/O 210, 220, 230, 240, 250, 260, 290, 3E0"
390 depends on SOUND_MSNDPIN=y
391 default "290"
392 help
393 Memory-mapped I/O base address for the primary synthesizer on
394 MultiSound Pinnacle and Fiji sound cards.
395
396config MSNDPIN_DIGITAL
397 bool "MSND Pinnacle has S/PDIF I/O"
398 depends on SOUND_MSNDPIN=y
399 help
400 If you have the S/PDIF daughter board for the Pinnacle or Fiji,
401 answer Y here; otherwise, say N. If you have this, you will be able
402 to play and record from the S/PDIF port (digital signal). See
403 <file:Documentation/sound/oss/MultiSound> for information on how to make
404 use of this capability.
405
406config MSNDPIN_NONPNP
407 bool "MSND Pinnacle non-PnP Mode"
408 depends on SOUND_MSNDPIN=y
409 help
410 The Pinnacle and Fiji card resources can be configured either with
411 PnP, or through a configuration port. Say Y here if your card is NOT
412 in PnP mode. For the Pinnacle, configuration in non-PnP mode allows
413 use of the IDE and joystick peripherals on the card as well; these
414 do not show up when the card is in PnP mode. Specifying zero for any
415 resource of a device will disable the device. If you are running the
416 card in PnP mode, you must say N here and use isapnptools to
417 configure the card's resources.
418
419comment "MSND Pinnacle DSP section will be configured to above parameters."
420 depends on SOUND_PRIME && SOUND_MSNDPIN=y && MSNDPIN_NONPNP
421
422config MSNDPIN_CFG
423 hex "MSND Pinnacle config port 250,260,270"
424 depends on MSNDPIN_NONPNP
425 default "250"
426 help
427 This is the port which the Pinnacle and Fiji uses to configure the
428 card's resources when not in PnP mode. If your card is in PnP mode,
429 then be sure to say N to the previous option, "MSND Pinnacle Non-PnP
430 Mode".
431
432comment "Pinnacle-specific Device Configuration (0 disables)"
433 depends on SOUND_PRIME && SOUND_MSNDPIN=y && MSNDPIN_NONPNP
434
435config MSNDPIN_MPU_IO
436 hex "MSND Pinnacle MPU I/O (e.g. 330)"
437 depends on MSNDPIN_NONPNP
438 default "0"
439 help
440 Memory-mapped I/O base address for the Kurzweil daughterboard
441 synthesizer on MultiSound Pinnacle and Fiji sound cards.
442
443config MSNDPIN_MPU_IRQ
444 int "MSND Pinnacle MPU IRQ (e.g. 9)"
445 depends on MSNDPIN_NONPNP
446 default "0"
447 help
448 Interrupt request number for the Kurzweil daughterboard
449 synthesizer on MultiSound Pinnacle and Fiji sound cards.
450
451config MSNDPIN_IDE_IO0
452 hex "MSND Pinnacle IDE I/O 0 (e.g. 170)"
453 depends on MSNDPIN_NONPNP
454 default "0"
455 help
456 CD-ROM drive 0 memory-mapped I/O base address for the MultiSound
457 Pinnacle and Fiji sound cards.
458
459config MSNDPIN_IDE_IO1
460 hex "MSND Pinnacle IDE I/O 1 (e.g. 376)"
461 depends on MSNDPIN_NONPNP
462 default "0"
463 help
464 CD-ROM drive 1 memory-mapped I/O base address for the MultiSound
465 Pinnacle and Fiji sound cards.
466
467config MSNDPIN_IDE_IRQ
468 int "MSND Pinnacle IDE IRQ (e.g. 15)"
469 depends on MSNDPIN_NONPNP
470 default "0"
471 help
472 Interrupt request number for the IDE CD-ROM interface on the
473 MultiSound Pinnacle and Fiji sound cards.
474
475config MSNDPIN_JOYSTICK_IO
476 hex "MSND Pinnacle joystick I/O (e.g. 200)"
477 depends on MSNDPIN_NONPNP
478 default "0"
479 help
480 Memory-mapped I/O base address for the joystick port on MultiSound
481 Pinnacle and Fiji sound cards.
482
483config MSND_FIFOSIZE
484 int "MSND buffer size (kB)"
485 depends on SOUND_PRIME && (SOUND_MSNDPIN=y || SOUND_MSNDCLAS=y)
486 default "128"
487 help
488 Configures the size of each audio buffer, in kilobytes, for
489 recording and playing in the MultiSound drivers (both the Classic
490 and Pinnacle). Larger values reduce the chance of data overruns at
491 the expense of overall latency. If unsure, use the default.
492
493config SOUND_VIA82CXXX
494 tristate "VIA 82C686 Audio Codec"
495 depends on SOUND_PRIME!=n && PCI
496 help
497 Say Y here to include support for the audio codec found on VIA
498 82Cxxx-based chips. Typically these are built into a motherboard.
499
500 DO NOT select Sound Blaster or Adlib with this driver, unless
501 you have a Sound Blaster or Adlib card in addition to your VIA
502 audio chip.
503
504config MIDI_VIA82CXXX
505 bool "VIA 82C686 MIDI"
506 depends on SOUND_VIA82CXXX
507 help
508 Answer Y to use the MIDI interface of the Via686. You may need to
509 enable this in the BIOS before it will work. This is for connection
510 to external MIDI hardware, and is not required for software playback
511 of MIDI files.
512
513config SOUND_OSS
514 tristate "OSS sound modules"
515 depends on SOUND_PRIME!=n && SOUND
516 help
517 OSS is the Open Sound System suite of sound card drivers. They make
518 sound programming easier since they provide a common API. Say Y or
519 M here (the module will be called sound) if you haven't found a
520 driver for your sound card above, then pick your driver from the
521 list below.
522
523config SOUND_TRACEINIT
524 bool "Verbose initialisation"
525 depends on SOUND_OSS
526 help
527 Verbose soundcard initialization -- affects the format of autoprobe
528 and initialization messages at boot time.
529
530config SOUND_DMAP
531 bool "Persistent DMA buffers"
532 depends on SOUND_OSS
533 ---help---
534 Linux can often have problems allocating DMA buffers for ISA sound
535 cards on machines with more than 16MB of RAM. This is because ISA
536 DMA buffers must exist below the 16MB boundary and it is quite
537 possible that a large enough free block in this region cannot be
538 found after the machine has been running for a while. If you say Y
539 here the DMA buffers (64Kb) will be allocated at boot time and kept
540 until the shutdown. This option is only useful if you said Y to
541 "OSS sound modules", above. If you said M to "OSS sound modules"
542 then you can get the persistent DMA buffer functionality by passing
543 the command-line argument "dmabuf=1" to the sound module.
544
545 Say Y unless you have 16MB or more RAM or a PCI sound card.
546
547config SOUND_AD1816
548 tristate "AD1816(A) based cards (EXPERIMENTAL)"
549 depends on EXPERIMENTAL && SOUND_OSS
550 help
551 Say M here if you have a sound card based on the Analog Devices
552 AD1816(A) chip.
553
554 If you compile the driver into the kernel, you have to add
555 "ad1816=<io>,<irq>,<dma>,<dma2>" to the kernel command line.
556
557config SOUND_AD1889
558 tristate "AD1889 based cards (AD1819 codec) (EXPERIMENTAL)"
559 depends on EXPERIMENTAL && SOUND_OSS
560 help
561 Say M here if you have a sound card based on the Analog Devices
562 AD1889 chip.
563
564config SOUND_SGALAXY
565 tristate "Aztech Sound Galaxy (non-PnP) cards"
566 depends on SOUND_OSS
567 help
568 This module initializes the older non Plug and Play sound galaxy
569 cards from Aztech. It supports the Waverider Pro 32 - 3D and the
570 Galaxy Washington 16.
571
572 If you compile the driver into the kernel, you have to add
573 "sgalaxy=<io>,<irq>,<dma>,<dma2>,<sgbase>" to the kernel command
574 line.
575
576config SOUND_ADLIB
577 tristate "Adlib Cards"
578 depends on SOUND_OSS
579 help
580 Includes ASB 64 4D. Information on programming AdLib cards is
581 available at <http://www.itsnet.com/home/ldragon/Specs/adlib.html>.
582
583config SOUND_ACI_MIXER
584 tristate "ACI mixer (miroSOUND PCM1-pro/PCM12/PCM20)"
585 depends on SOUND_OSS
586 ---help---
587 ACI (Audio Command Interface) is a protocol used to communicate with
588 the microcontroller on some sound cards produced by miro and
589 Cardinal Technologies. The main function of the ACI is to control
590 the mixer and to get a product identification.
591
592 This VoxWare ACI driver currently supports the ACI functions on the
593 miroSOUND PCM1-pro, PCM12 and PCM20 radio. On the PCM20 radio, ACI
594 also controls the radio tuner. This is supported in the video4linux
595 miropcm20 driver (say M or Y here and go back to "Multimedia
596 devices" -> "Radio Adapters").
597
598 This driver is also available as a module and will be called aci.
599
600config SOUND_CS4232
601 tristate "Crystal CS4232 based (PnP) cards"
602 depends on SOUND_OSS
603 help
604 Say Y here if you have a card based on the Crystal CS4232 chip set,
605 which uses its own Plug and Play protocol.
606
607 If you compile the driver into the kernel, you have to add
608 "cs4232=<io>,<irq>,<dma>,<dma2>,<mpuio>,<mpuirq>" to the kernel
609 command line.
610
611 See <file:Documentation/sound/oss/CS4232> for more information on
612 configuring this card.
613
614config SOUND_SSCAPE
615 tristate "Ensoniq SoundScape support"
616 depends on SOUND_OSS
617 help
618 Answer Y if you have a sound card based on the Ensoniq SoundScape
619 chipset. Such cards are being manufactured at least by Ensoniq, Spea
620 and Reveal (Reveal makes also other cards).
621
622 If you compile the driver into the kernel, you have to add
623 "sscape=<io>,<irq>,<dma>,<mpuio>,<mpuirq>" to the kernel command
624 line.
625
626config SOUND_GUS
627 tristate "Gravis Ultrasound support"
628 depends on SOUND_OSS
629 help
630 Say Y here for any type of Gravis Ultrasound card, including the GUS
631 or GUS MAX. See also <file:Documentation/sound/oss/ultrasound> for more
632 information on configuring this card with modules.
633
634 If you compile the driver into the kernel, you have to add
635 "gus=<io>,<irq>,<dma>,<dma2>" to the kernel command line.
636
637config SOUND_GUS16
638 bool "16 bit sampling option of GUS (_NOT_ GUS MAX)"
639 depends on SOUND_GUS
640 help
641 Support for Gravis Ulstrasound (GUS) cards (other than the GUS),
642 sampling at 16-bit width.
643
644config SOUND_GUSMAX
645 bool "GUS MAX support"
646 depends on SOUND_GUS
647 help
648 Support for Gravis Ulstrasound MAX.
649
650config SOUND_VMIDI
651 tristate "Loopback MIDI device support"
652 depends on SOUND_OSS
653 help
654 Support for MIDI loopback on port 1 or 2.
655
656config SOUND_TRIX
657 tristate "MediaTrix AudioTrix Pro support"
658 depends on SOUND_OSS
659 help
660 Answer Y if you have the AudioTriX Pro sound card manufactured
661 by MediaTrix.
662
663config TRIX_HAVE_BOOT
664 bool "Have TRXPRO.HEX firmware file"
665 depends on SOUND_TRIX=y && !STANDALONE
666 help
667 The MediaTrix AudioTrix Pro has an on-board microcontroller which
668 needs to be initialized by downloading the code from the file
669 TRXPRO.HEX in the DOS driver directory. If you don't have the
670 TRXPRO.HEX file handy you may skip this step. However, the SB and
671 MPU-401 modes of AudioTrix Pro will not work without this file!
672
673config TRIX_BOOT_FILE
674 string "Full pathname of TRXPRO.HEX firmware file"
675 depends on TRIX_HAVE_BOOT
676 default "/etc/sound/trxpro.hex"
677 help
678 Enter the full pathname of your TRXPRO.HEX file, starting from /.
679
680config SOUND_MSS
681 tristate "Microsoft Sound System support"
682 depends on SOUND_OSS
683 ---help---
684 Again think carefully before answering Y to this question. It's
685 safe to answer Y if you have the original Windows Sound System card
686 made by Microsoft or Aztech SG 16 Pro (or NX16 Pro). Also you may
687 say Y in case your card is NOT among these:
688
689 ATI Stereo F/X, AdLib, Audio Excell DSP16, Cardinal DSP16,
690 Ensoniq SoundScape (and compatibles made by Reveal and Spea),
691 Gravis Ultrasound, Gravis Ultrasound ACE, Gravis Ultrasound Max,
692 Gravis Ultrasound with 16 bit option, Logitech Sound Man 16,
693 Logitech SoundMan Games, Logitech SoundMan Wave, MAD16 Pro (OPTi
694 82C929), Media Vision Jazz16, MediaTriX AudioTriX Pro, Microsoft
695 Windows Sound System (MSS/WSS), Mozart (OAK OTI-601), Orchid
696 SW32, Personal Sound System (PSS), Pro Audio Spectrum 16, Pro
697 Audio Studio 16, Pro Sonic 16, Roland MPU-401 MIDI interface,
698 Sound Blaster 1.0, Sound Blaster 16, Sound Blaster 16ASP, Sound
699 Blaster 2.0, Sound Blaster AWE32, Sound Blaster Pro, TI TM4000M
700 notebook, ThunderBoard, Turtle Beach Tropez, Yamaha FM
701 synthesizers (OPL2, OPL3 and OPL4), 6850 UART MIDI Interface.
702
703 For cards having native support in VoxWare, consult the card
704 specific instructions in <file:Documentation/sound/oss/README.OSS>.
705 Some drivers have their own MSS support and saying Y to this option
706 will cause a conflict.
707
708 If you compile the driver into the kernel, you have to add
709 "ad1848=<io>,<irq>,<dma>,<dma2>[,<type>]" to the kernel command
710 line.
711
712config SOUND_MPU401
713 tristate "MPU-401 support (NOT for SB16)"
714 depends on SOUND_OSS
715 ---help---
716 Be careful with this question. The MPU401 interface is supported by
717 all sound cards. However, some natively supported cards have their
718 own driver for MPU401. Enabling this MPU401 option with these cards
719 will cause a conflict. Also, enabling MPU401 on a system that
720 doesn't really have a MPU401 could cause some trouble. If your card
721 was in the list of supported cards, look at the card specific
722 instructions in the <file:Documentation/sound/oss/README.OSS> file. It
723 is safe to answer Y if you have a true MPU401 MIDI interface card.
724
725 If you compile the driver into the kernel, you have to add
726 "mpu401=<io>,<irq>" to the kernel command line.
727
728config SOUND_NM256
729 tristate "NM256AV/NM256ZX audio support"
730 depends on SOUND_OSS
731 help
732 Say M here to include audio support for the NeoMagic 256AV/256ZX
733 chipsets. These are the audio chipsets found in the Sony
734 Z505S/SX/DX, some Sony F-series, and the Dell Latitude CPi and CPt
735 laptops. It includes support for an AC97-compatible mixer and an
736 apparently proprietary sound engine.
737
738 See <file:Documentation/sound/oss/NM256> for further information.
739
740config SOUND_MAD16
741 tristate "OPTi MAD16 and/or Mozart based cards"
742 depends on SOUND_OSS && SOUND_GAMEPORT
743 ---help---
744 Answer Y if your card has a Mozart (OAK OTI-601) or MAD16 (OPTi
745 82C928 or 82C929 or 82C931) audio interface chip. These chips are
746 quite common so it's possible that many no-name cards have one of
747 them. In addition the MAD16 chip is used in some cards made by known
748 manufacturers such as Turtle Beach (Tropez), Reveal (some models)
749 and Diamond (latest ones). Note however that the Tropez sound cards
750 have their own driver; if you have one of those, say N here and Y or
751 M to "Full support for Turtle Beach WaveFront", below.
752
753 If you compile the driver into the kernel, you have to add
754 "mad16=<io>,<irq>,<dma>,<dma2>,<mpuio>,<mpuirq>" to the
755 kernel command line.
756
757 See also <file:Documentation/sound/oss/Opti> and
758 <file:Documentation/sound/oss/MAD16> for more information on setting
759 these cards up as modules.
760
761config MAD16_OLDCARD
762 bool "Support MIDI in older MAD16 based cards (requires SB)"
763 depends on SOUND_MAD16
764 help
765 Answer Y (or M) if you have an older card based on the C928 or
766 Mozart chipset and you want to have MIDI support. If you enable this
767 option you also need to enable support for Sound Blaster.
768
769config SOUND_PAS
770 tristate "ProAudioSpectrum 16 support"
771 depends on SOUND_OSS
772 ---help---
773 Answer Y only if you have a Pro Audio Spectrum 16, ProAudio Studio
774 16 or Logitech SoundMan 16 sound card. Answer N if you have some
775 other card made by Media Vision or Logitech since those are not
776 PAS16 compatible. Please read <file:Documentation/sound/oss/PAS16>.
777 It is not necessary to add Sound Blaster support separately; it
778 is included in PAS support.
779
780 If you compile the driver into the kernel, you have to add
781 "pas2=<io>,<irq>,<dma>,<dma2>,<sbio>,<sbirq>,<sbdma>,<sbdma2>
782 to the kernel command line.
783
784config PAS_JOYSTICK
785 bool "Enable PAS16 joystick port"
786 depends on SOUND_PAS=y
787 help
788 Say Y here to enable the Pro Audio Spectrum 16's auxiliary joystick
789 port.
790
791config SOUND_PSS
792 tristate "PSS (AD1848, ADSP-2115, ESC614) support"
793 depends on SOUND_OSS
794 help
795 Answer Y or M if you have an Orchid SW32, Cardinal DSP16, Beethoven
796 ADSP-16 or some other card based on the PSS chipset (AD1848 codec +
797 ADSP-2115 DSP chip + Echo ESC614 ASIC CHIP). For more information on
798 how to compile it into the kernel or as a module see the file
799 <file:Documentation/sound/oss/PSS>.
800
801 If you compile the driver into the kernel, you have to add
802 "pss=<io>,<mssio>,<mssirq>,<mssdma>,<mpuio>,<mpuirq>" to the kernel
803 command line.
804
805config PSS_MIXER
806 bool "Enable PSS mixer (Beethoven ADSP-16 and other compatibile)"
807 depends on SOUND_PSS
808 help
809 Answer Y for Beethoven ADSP-16. You may try to say Y also for other
810 cards if they have master volume, bass, treble, and you can't
811 control it under Linux. If you answer N for Beethoven ADSP-16, you
812 can't control master volume, bass, treble and synth volume.
813
814 If you said M to "PSS support" above, you may enable or disable this
815 PSS mixer with the module parameter pss_mixer. For more information
816 see the file <file:Documentation/sound/oss/PSS>.
817
818config PSS_HAVE_BOOT
819 bool "Have DSPxxx.LD firmware file"
820 depends on SOUND_PSS && !STANDALONE
821 help
822 If you have the DSPxxx.LD file or SYNTH.LD file for you card, say Y
823 to include this file. Without this file the synth device (OPL) may
824 not work.
825
826config PSS_BOOT_FILE
827 string "Full pathname of DSPxxx.LD firmware file"
828 depends on PSS_HAVE_BOOT
829 default "/etc/sound/dsp001.ld"
830 help
831 Enter the full pathname of your DSPxxx.LD file or SYNTH.LD file,
832 starting from /.
833
834config SOUND_SB
835 tristate "100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support"
836 depends on SOUND_OSS
837 ---help---
838 Answer Y if you have an original Sound Blaster card made by Creative
839 Labs or a 100% hardware compatible clone (like the Thunderboard or
840 SM Games). For an unknown card you may answer Y if the card claims
841 to be Sound Blaster-compatible.
842
843 Please read the file <file:Documentation/sound/oss/Soundblaster>.
844
845 You should also say Y here for cards based on the Avance Logic
846 ALS-007 and ALS-1X0 chips (read <file:Documentation/sound/oss/ALS>) and
847 for cards based on ESS chips (read
848 <file:Documentation/sound/oss/ESS1868> and
849 <file:Documentation/sound/oss/ESS>). If you have an SB AWE 32 or SB AWE
850 64, say Y here and also to "AWE32 synth" below and read
851 <file:Documentation/sound/oss/INSTALL.awe>. If you have an IBM Mwave
852 card, say Y here and read <file:Documentation/sound/oss/mwave>.
853
854 If you compile the driver into the kernel and don't want to use
855 isapnp, you have to add "sb=<io>,<irq>,<dma>,<dma2>" to the kernel
856 command line.
857
858 You can say M here to compile this driver as a module; the module is
859 called sb.
860
861config SOUND_AWE32_SYNTH
862 tristate "AWE32 synth"
863 depends on SOUND_OSS
864 help
865 Say Y here if you have a Sound Blaster SB32, AWE32-PnP, SB AWE64 or
866 similar sound card. See <file:Documentation/sound/oss/README.awe>,
867 <file:Documentation/sound/oss/AWE32> and the Soundblaster-AWE
868 mini-HOWTO, available from <http://www.tldp.org/docs.html#howto>
869 for more info.
870
871config SOUND_WAVEFRONT
872 tristate "Full support for Turtle Beach WaveFront (Tropez Plus, Tropez, Maui) synth/soundcards"
873 depends on SOUND_OSS && m
874 help
875 Answer Y or M if you have a Tropez Plus, Tropez or Maui sound card
876 and read the files <file:Documentation/sound/oss/Wavefront> and
877 <file:Documentation/sound/oss/Tropez+>.
878
879config SOUND_MAUI
880 tristate "Limited support for Turtle Beach Wave Front (Maui, Tropez) synthesizers"
881 depends on SOUND_OSS
882 help
883 Say Y here if you have a Turtle Beach Wave Front, Maui, or Tropez
884 sound card.
885
886 If you compile the driver into the kernel, you have to add
887 "maui=<io>,<irq>" to the kernel command line.
888
889config MAUI_HAVE_BOOT
890 bool "Have OSWF.MOT firmware file"
891 depends on SOUND_MAUI=y && !STANDALONE
892 help
893 Turtle Beach Maui and Tropez sound cards have a microcontroller
894 which needs to be initialized prior to use. OSWF.MOT is a file
895 distributed with the card's DOS/Windows drivers. Answer Y if you
896 have this file.
897
898config MAUI_BOOT_FILE
899 string "Full pathname of OSWF.MOT firmware file"
900 depends on MAUI_HAVE_BOOT
901 default "/etc/sound/oswf.mot"
902 help
903 Enter the full pathname of your OSWF.MOT file, starting from /.
904
905config SOUND_YM3812
906 tristate "Yamaha FM synthesizer (YM3812/OPL-3) support"
907 depends on SOUND_OSS
908 ---help---
909 Answer Y if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
910 Answering Y is usually a safe and recommended choice, however some
911 cards may have software (TSR) FM emulation. Enabling FM support with
912 these cards may cause trouble (I don't currently know of any such
913 cards, however). Please read the file
914 <file:Documentation/sound/oss/OPL3> if your card has an OPL3 chip.
915
916 If you compile the driver into the kernel, you have to add
917 "opl3=<io>" to the kernel command line.
918
919 If unsure, say Y.
920
921config SOUND_OPL3SA1
922 tristate "Yamaha OPL3-SA1 audio controller"
923 depends on SOUND_OSS
924 help
925 Say Y or M if you have a Yamaha OPL3-SA1 sound chip, which is
926 usually built into motherboards. Read
927 <file:Documentation/sound/oss/OPL3-SA> for details.
928
929 If you compile the driver into the kernel, you have to add
930 "opl3sa=<io>,<irq>,<dma>,<dma2>,<mpuio>,<mpuirq>" to the kernel
931 command line.
932
933config SOUND_OPL3SA2
934 tristate "Yamaha OPL3-SA2 and SA3 based PnP cards"
935 depends on SOUND_OSS
936 help
937 Say Y or M if you have a card based on one of these Yamaha sound
938 chipsets or the "SAx", which is actually a SA3. Read
939 <file:Documentation/sound/oss/OPL3-SA2> for more information on
940 configuring these cards.
941
942 If you compile the driver into the kernel and do not also
943 configure in the optional ISA PnP support, you will have to add
944 "opl3sa2=<io>,<irq>,<dma>,<dma2>,<mssio>,<mpuio>" to the kernel
945 command line.
946
947config SOUND_YMFPCI
948 tristate "Yamaha YMF7xx PCI audio (native mode)"
949 depends on SOUND_OSS && PCI
950 help
951 Support for Yamaha cards including the YMF711, YMF715, YMF718,
952 YMF719, YMF724, Waveforce 192XG, and Waveforce 192 Digital.
953
954config SOUND_YMFPCI_LEGACY
955 bool "Yamaha PCI legacy ports support"
956 depends on SOUND_YMFPCI
957 help
958 Support for YMF7xx PCI cards emulating an MP401.
959
960config SOUND_UART6850
961 tristate "6850 UART support"
962 depends on SOUND_OSS
963 help
964 This option enables support for MIDI interfaces based on the 6850
965 UART chip. This interface is rarely found on sound cards. It's safe
966 to answer N to this question.
967
968 If you compile the driver into the kernel, you have to add
969 "uart6850=<io>,<irq>" to the kernel command line.
970
971config SOUND_AEDSP16
972 tristate "Gallant Audio Cards (SC-6000 and SC-6600 based)"
973 depends on SOUND_OSS
974 ---help---
975 Answer Y if you have a Gallant's Audio Excel DSP 16 card. This
976 driver supports Audio Excel DSP 16 but not the III nor PnP versions
977 of this card.
978
979 The Gallant's Audio Excel DSP 16 card can emulate either an SBPro or
980 a Microsoft Sound System card, so you should have said Y to either
981 "100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support"
982 or "Microsoft Sound System support", above, and you need to answer
983 the "MSS emulation" and "SBPro emulation" questions below
984 accordingly. You should say Y to one and only one of these two
985 questions.
986
987 Read the <file:Documentation/sound/oss/README.OSS> file and the head of
988 <file:drivers/sound/aedsp16.c> as well as
989 <file:Documentation/sound/oss/AudioExcelDSP16> to get more information
990 about this driver and its configuration.
991
992config SC6600
993 bool "SC-6600 based audio cards (new Audio Excel DSP 16)"
994 depends on SOUND_AEDSP16
995 help
996 The SC6600 is the new version of DSP mounted on the Audio Excel DSP
997 16 cards. Find in the manual the FCC ID of your audio card and
998 answer Y if you have an SC6600 DSP.
999
1000config SC6600_JOY
1001 bool "Activate SC-6600 Joystick Interface"
1002 depends on SC6600
1003 help
1004 Say Y here in order to use the joystick interface of the Audio Excel
1005 DSP 16 card.
1006
1007config SC6600_CDROM
1008 int "SC-6600 CDROM Interface (4=None, 3=IDE, 1=Panasonic, 0=?Sony?)"
1009 depends on SC6600
1010 default "4"
1011 help
1012 This is used to activate the CD-ROM interface of the Audio Excel
1013 DSP 16 card. Enter: 0 for Sony, 1 for Panasonic, 2 for IDE, 4 for no
1014 CD-ROM present.
1015
1016config SC6600_CDROMBASE
1017 hex "SC-6600 CDROM Interface I/O Address"
1018 depends on SC6600
1019 default "0"
1020 help
1021 Base I/O port address for the CD-ROM interface of the Audio Excel
1022 DSP 16 card.
1023
1024choice
1025 prompt "Audio Excel DSP 16"
1026 optional
1027 depends on SOUND_AEDSP16
1028
1029config AEDSP16_MSS
1030 bool "MSS emulation"
1031 depends on SOUND_MSS
1032 help
1033 Answer Y if you want your audio card to emulate Microsoft Sound
1034 System. You should then say Y to "Microsoft Sound System support"
1035 and say N to "Audio Excel DSP 16 (SBPro emulation)".
1036
1037config AEDSP16_SBPRO
1038 bool "SBPro emulation"
1039 depends on SOUND_SB
1040 help
1041 Answer Y if you want your audio card to emulate Sound Blaster Pro.
1042 You should then say Y to "100% Sound Blaster compatibles
1043 (SB16/32/64, ESS, Jazz16) support" and N to "Audio Excel DSP 16 (MSS
1044 emulation)".
1045
1046 If you compile the driver into the kernel, you have to add
1047 "aedsp16=<io>,<irq>,<dma>,<mssio>,<mpuio>,<mouirq>" to the kernel
1048 command line.
1049
1050endchoice
1051
1052config AEDSP16_MPU401
1053 bool "Audio Excel DSP 16 (MPU401 emulation)"
1054 depends on SOUND_AEDSP16 && SOUND_MPU401
1055 help
1056 Answer Y if you want your audio card to emulate the MPU-401 midi
1057 interface. You should then also say Y to "MPU-401 support".
1058
1059 Note that the I/O base for MPU-401 support of aedsp16 is the same
1060 you have selected for "MPU-401 support". If you are using this
1061 driver as a module you have to specify the MPU I/O base address with
1062 the parameter 'mpu_base=0xNNN'.
1063
1064config SOUND_VIDC
1065 tristate "VIDC 16-bit sound"
1066 depends on ARM && (ARCH_ACORN || ARCH_CLPS7500) && SOUND_OSS
1067 help
1068 16-bit support for the VIDC onboard sound hardware found on Acorn
1069 machines.
1070
1071config SOUND_WAVEARTIST
1072 tristate "Netwinder WaveArtist"
1073 depends on ARM && SOUND_OSS && ARCH_NETWINDER
1074 help
1075 Say Y here to include support for the Rockwell WaveArtist sound
1076 system. This driver is mainly for the NetWinder.
1077
1078config SOUND_TVMIXER
1079 tristate "TV card (bt848) mixer support"
1080 depends on SOUND_PRIME!=n && SOUND && I2C
1081 help
1082 Support for audio mixer facilities on the BT848 TV frame-grabber
1083 card.
1084
1085config SOUND_KAHLUA
1086 tristate "XpressAudio Sound Blaster emulation"
1087 depends on SOUND_SB
1088
1089config SOUND_ALI5455
1090 tristate "ALi5455 audio support"
1091 depends on SOUND_PRIME!=n && PCI
1092
1093config SOUND_FORTE
1094 tristate "ForteMedia FM801 driver"
1095 depends on SOUND_PRIME!=n && PCI
1096 help
1097 Say Y or M if you want driver support for the ForteMedia FM801 PCI
1098 audio controller (Abit AU10, Genius Sound Maker, HP Workstation
1099 zx2000, and others).
1100
1101config SOUND_RME96XX
1102 tristate "RME Hammerfall (RME96XX) support"
1103 depends on SOUND_PRIME!=n && PCI
1104 help
1105 Say Y or M if you have a Hammerfall or Hammerfall light
1106 multichannel card from RME. If you want to access advanced
1107 features of the card, read <file:Documentation/sound/oss/rme96xx>.
1108
1109config SOUND_AD1980
1110 tristate "AD1980 front/back switch plugin"
1111 depends on SOUND_PRIME!=n
1112
1113config SOUND_SH_DAC_AUDIO
1114 tristate "SuperH DAC audio support"
1115 depends on SOUND_PRIME!=n && SOUND && CPU_SH3
1116
1117config SOUND_SH_DAC_AUDIO_CHANNEL
1118 int " DAC channel"
1119 default "1"
1120 depends on SOUND_SH_DAC_AUDIO
diff --git a/sound/oss/Makefile b/sound/oss/Makefile
new file mode 100644
index 000000000000..db9afb61d6ff
--- /dev/null
+++ b/sound/oss/Makefile
@@ -0,0 +1,187 @@
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
9obj-$(CONFIG_SOUND_CS4232) += cs4232.o ad1848.o
10
11# Please leave it as is, cause the link order is significant !
12
13obj-$(CONFIG_SOUND_SH_DAC_AUDIO) += sh_dac_audio.o
14obj-$(CONFIG_SOUND_HAL2) += hal2.o
15obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o
16obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o
17obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o
18obj-$(CONFIG_SOUND_OPL3SA1) += opl3sa.o ad1848.o uart401.o
19obj-$(CONFIG_SOUND_SSCAPE) += sscape.o ad1848.o mpu401.o
20obj-$(CONFIG_SOUND_MAD16) += mad16.o ad1848.o sb_lib.o uart401.o
21obj-$(CONFIG_SOUND_CS4232) += cs4232.o uart401.o
22obj-$(CONFIG_SOUND_MSS) += ad1848.o
23obj-$(CONFIG_SOUND_OPL3SA2) += opl3sa2.o ad1848.o mpu401.o
24obj-$(CONFIG_SOUND_PAS) += pas2.o sb.o sb_lib.o uart401.o
25obj-$(CONFIG_SOUND_SB) += sb.o sb_lib.o uart401.o
26obj-$(CONFIG_SOUND_KAHLUA) += kahlua.o
27obj-$(CONFIG_SOUND_WAVEFRONT) += wavefront.o
28obj-$(CONFIG_SOUND_MAUI) += maui.o mpu401.o
29obj-$(CONFIG_SOUND_MPU401) += mpu401.o
30obj-$(CONFIG_SOUND_UART6850) += uart6850.o
31obj-$(CONFIG_SOUND_GUS) += gus.o ad1848.o
32obj-$(CONFIG_SOUND_ADLIB) += adlib_card.o opl3.o
33obj-$(CONFIG_SOUND_YM3812) += opl3.o
34obj-$(CONFIG_SOUND_VMIDI) += v_midi.o
35obj-$(CONFIG_SOUND_VIDC) += vidc_mod.o
36obj-$(CONFIG_SOUND_WAVEARTIST) += waveartist.o
37obj-$(CONFIG_SOUND_SGALAXY) += sgalaxy.o ad1848.o
38obj-$(CONFIG_SOUND_AD1816) += ad1816.o
39obj-$(CONFIG_SOUND_AD1889) += ad1889.o ac97_codec.o
40obj-$(CONFIG_SOUND_ACI_MIXER) += aci.o
41obj-$(CONFIG_SOUND_AWE32_SYNTH) += awe_wave.o
42
43obj-$(CONFIG_SOUND_VIA82CXXX) += via82cxxx_audio.o ac97_codec.o
44ifeq ($(CONFIG_MIDI_VIA82CXXX),y)
45 obj-$(CONFIG_SOUND_VIA82CXXX) += sound.o uart401.o
46endif
47obj-$(CONFIG_SOUND_YMFPCI) += ymfpci.o ac97_codec.o
48ifeq ($(CONFIG_SOUND_YMFPCI_LEGACY),y)
49 obj-$(CONFIG_SOUND_YMFPCI) += opl3.o uart401.o
50endif
51obj-$(CONFIG_SOUND_MSNDCLAS) += msnd.o msnd_classic.o
52obj-$(CONFIG_SOUND_MSNDPIN) += msnd.o msnd_pinnacle.o
53obj-$(CONFIG_SOUND_VWSND) += vwsnd.o
54obj-$(CONFIG_SOUND_NM256) += nm256_audio.o ac97.o
55obj-$(CONFIG_SOUND_ICH) += i810_audio.o ac97_codec.o
56obj-$(CONFIG_SOUND_SONICVIBES) += sonicvibes.o
57obj-$(CONFIG_SOUND_CMPCI) += cmpci.o
58ifeq ($(CONFIG_SOUND_CMPCI_FM),y)
59 obj-$(CONFIG_SOUND_CMPCI) += sound.o opl3.o
60endif
61ifeq ($(CONFIG_SOUND_CMPCI_MIDI),y)
62 obj-$(CONFIG_SOUND_CMPCI) += sound.o mpu401.o
63endif
64obj-$(CONFIG_SOUND_ES1370) += es1370.o
65obj-$(CONFIG_SOUND_ES1371) += es1371.o ac97_codec.o
66obj-$(CONFIG_SOUND_VRC5477) += nec_vrc5477.o ac97_codec.o
67obj-$(CONFIG_SOUND_AU1000) += au1000.o ac97_codec.o
68obj-$(CONFIG_SOUND_AU1550_AC97) += au1550_ac97.o ac97_codec.o
69obj-$(CONFIG_SOUND_ESSSOLO1) += esssolo1.o
70obj-$(CONFIG_SOUND_FUSION) += cs46xx.o ac97_codec.o
71obj-$(CONFIG_SOUND_MAESTRO) += maestro.o
72obj-$(CONFIG_SOUND_MAESTRO3) += maestro3.o ac97_codec.o
73obj-$(CONFIG_SOUND_TRIDENT) += trident.o ac97_codec.o
74obj-$(CONFIG_SOUND_HARMONY) += harmony.o
75obj-$(CONFIG_SOUND_EMU10K1) += ac97_codec.o
76obj-$(CONFIG_SOUND_BCM_CS4297A) += swarm_cs4297a.o
77obj-$(CONFIG_SOUND_RME96XX) += rme96xx.o
78obj-$(CONFIG_SOUND_BT878) += btaudio.o
79obj-$(CONFIG_SOUND_ALI5455) += ali5455.o ac97_codec.o
80obj-$(CONFIG_SOUND_IT8172) += ite8172.o ac97_codec.o
81obj-$(CONFIG_SOUND_FORTE) += forte.o ac97_codec.o
82
83obj-$(CONFIG_SOUND_AD1980) += ac97_plugin_ad1980.o
84obj-$(CONFIG_SOUND_WM97XX) += ac97_plugin_wm97xx.o
85
86ifeq ($(CONFIG_MIDI_EMU10K1),y)
87 obj-$(CONFIG_SOUND_EMU10K1) += sound.o
88endif
89
90obj-$(CONFIG_SOUND_EMU10K1) += emu10k1/
91obj-$(CONFIG_SOUND_CS4281) += cs4281/
92obj-$(CONFIG_DMASOUND) += dmasound/
93
94# Declare multi-part drivers.
95
96sound-objs := \
97 dev_table.o soundcard.o sound_syms.o \
98 audio.o audio_syms.o dmabuf.o \
99 midi_syms.o midi_synth.o midibuf.o \
100 sequencer.o sequencer_syms.o sound_timer.o sys_timer.o
101
102gus-objs := gus_card.o gus_midi.o gus_vol.o gus_wave.o ics2101.o
103pas2-objs := pas2_card.o pas2_midi.o pas2_mixer.o pas2_pcm.o
104sb-objs := sb_card.o
105sb_lib-objs := sb_common.o sb_audio.o sb_midi.o sb_mixer.o sb_ess.o
106vidc_mod-objs := vidc.o vidc_fill.o
107wavefront-objs := wavfront.o wf_midi.o yss225.o
108
109hostprogs-y := bin2hex hex2hex
110
111# Files generated that shall be removed upon make clean
112clean-files := maui_boot.h msndperm.c msndinit.c pndsperm.c pndspini.c \
113 pss_boot.h trix_boot.h
114
115# Firmware files that need translation
116#
117# The translated files are protected by a file that keeps track
118# of what name was used to build them. If the name changes, they
119# will be forced to be remade.
120#
121
122# Turtle Beach Maui / Tropez
123
124$(obj)/maui.o: $(obj)/maui_boot.h
125
126ifeq ($(CONFIG_MAUI_HAVE_BOOT),y)
127 $(obj)/maui_boot.h: $(patsubst "%", %, $(CONFIG_MAUI_BOOT_FILE)) $(obj)/bin2hex
128 $(obj)/bin2hex -i maui_os < $< > $@
129else
130 $(obj)/maui_boot.h:
131 ( \
132 echo 'static unsigned char * maui_os = NULL;'; \
133 echo 'static int maui_osLen = 0;'; \
134 ) > $@
135endif
136
137# Turtle Beach MultiSound
138
139ifeq ($(CONFIG_MSNDCLAS_HAVE_BOOT),y)
140 $(obj)/msnd_classic.o: $(obj)/msndperm.c $(obj)/msndinit.c
141
142 $(obj)/msndperm.c: $(patsubst "%", %, $(CONFIG_MSNDCLAS_PERM_FILE)) $(obj)/bin2hex
143 $(obj)/bin2hex msndperm < $< > $@
144
145 $(obj)/msndinit.c: $(patsubst "%", %, $(CONFIG_MSNDCLAS_INIT_FILE)) $(obj)/bin2hex
146 $(obj)/bin2hex msndinit < $< > $@
147endif
148
149ifeq ($(CONFIG_MSNDPIN_HAVE_BOOT),y)
150 $(obj)/msnd_pinnacle.o: $(obj)/pndsperm.c $(obj)/pndspini.c
151
152 $(obj)/pndsperm.c: $(patsubst "%", %, $(CONFIG_MSNDPIN_PERM_FILE)) $(obj)/bin2hex
153 $(obj)/bin2hex pndsperm < $< > $@
154
155 $(obj)/pndspini.c: $(patsubst "%", %, $(CONFIG_MSNDPIN_INIT_FILE)) $(obj)/bin2hex
156 $(obj)/bin2hex pndspini < $< > $@
157endif
158
159# PSS (ECHO-ADI2111)
160
161$(obj)/pss.o: $(obj)/pss_boot.h
162
163ifeq ($(CONFIG_PSS_HAVE_BOOT),y)
164 $(obj)/pss_boot.h: $(patsubst "%", %, $(CONFIG_PSS_BOOT_FILE)) $(obj)/bin2hex
165 $(obj)/bin2hex pss_synth < $< > $@
166else
167 $(obj)/pss_boot.h:
168 ( \
169 echo 'static unsigned char * pss_synth = NULL;'; \
170 echo 'static int pss_synthLen = 0;'; \
171 ) > $@
172endif
173
174# MediaTrix AudioTrix Pro
175
176$(obj)/trix.o: $(obj)/trix_boot.h
177
178ifeq ($(CONFIG_TRIX_HAVE_BOOT),y)
179 $(obj)/trix_boot.h: $(patsubst "%", %, $(CONFIG_TRIX_BOOT_FILE)) $(obj)/hex2hex
180 $(obj)/hex2hex -i trix_boot < $< > $@
181else
182 $(obj)/trix_boot.h:
183 ( \
184 echo 'static unsigned char * trix_boot = NULL;'; \
185 echo 'static int trix_boot_len = 0;'; \
186 ) > $@
187endif
diff --git a/sound/oss/README.FIRST b/sound/oss/README.FIRST
new file mode 100644
index 000000000000..90fdcf063d2d
--- /dev/null
+++ b/sound/oss/README.FIRST
@@ -0,0 +1,6 @@
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/ac97.c b/sound/oss/ac97.c
new file mode 100644
index 000000000000..3ba6d91e891d
--- /dev/null
+++ b/sound/oss/ac97.c
@@ -0,0 +1,452 @@
1#include <linux/module.h>
2#include <linux/kernel.h>
3#include <linux/init.h>
4#include "ac97.h"
5
6/* Flag for mono controls. */
7#define MO 0
8/* And for stereo. */
9#define ST 1
10
11/* Whether or not the bits in the channel are inverted. */
12#define INV 1
13#define NINV 0
14
15static struct ac97_chn_desc {
16 int ac97_regnum;
17 int oss_channel;
18 int maxval;
19 int is_stereo;
20 int oss_mask;
21 int recordNum;
22 u16 regmask;
23 int is_inverted;
24} mixerRegs[] = {
25 { AC97_MASTER_VOL_STEREO, SOUND_MIXER_VOLUME, 0x3f, ST, SOUND_MASK_VOLUME, 5, 0x0000, INV },
26 { AC97_MASTER_VOL_MONO, SOUND_MIXER_PHONEOUT, 0x3f, MO, SOUND_MASK_PHONEOUT, 6, 0x0000, INV },
27 { AC97_MASTER_TONE, SOUND_MIXER_TREBLE, 0x0f, MO, SOUND_MASK_TREBLE, -1, 0x00ff, INV },
28 { AC97_MASTER_TONE, SOUND_MIXER_BASS, 0x0f, MO, SOUND_MASK_BASS, -1, 0xff00, INV },
29 { AC97_PCBEEP_VOL, SOUND_MIXER_SPEAKER, 0x0f, MO, SOUND_MASK_SPEAKER, -1, 0x001e, INV },
30 { AC97_PHONE_VOL, SOUND_MIXER_PHONEIN, 0x1f, MO, SOUND_MASK_PHONEIN, 7, 0x0000, INV },
31 { AC97_MIC_VOL, SOUND_MIXER_MIC, 0x1f, MO, SOUND_MASK_MIC, 0, 0x0000, INV },
32 { AC97_LINEIN_VOL, SOUND_MIXER_LINE, 0x1f, ST, SOUND_MASK_LINE, 4, 0x0000, INV },
33 { AC97_CD_VOL, SOUND_MIXER_CD, 0x1f, ST, SOUND_MASK_CD, 1, 0x0000, INV },
34 { AC97_VIDEO_VOL, SOUND_MIXER_VIDEO, 0x1f, ST, SOUND_MASK_VIDEO, 2, 0x0000, INV },
35 { AC97_AUX_VOL, SOUND_MIXER_LINE1, 0x1f, ST, SOUND_MASK_LINE1, 3, 0x0000, INV },
36 { AC97_PCMOUT_VOL, SOUND_MIXER_PCM, 0x1f, ST, SOUND_MASK_PCM, -1, 0x0000, INV },
37 { AC97_RECORD_GAIN, SOUND_MIXER_IGAIN, 0x0f, ST, SOUND_MASK_IGAIN, -1, 0x0000, NINV },
38 { -1, -1, 0xff, 0, 0, -1, 0x0000, 0 },
39};
40
41static struct ac97_chn_desc *
42ac97_find_chndesc (struct ac97_hwint *dev, int oss_channel)
43{
44 int x;
45
46 for (x = 0; mixerRegs[x].oss_channel != -1; x++) {
47 if (mixerRegs[x].oss_channel == oss_channel)
48 return mixerRegs + x;
49 }
50
51 return NULL;
52}
53
54static inline int
55ac97_is_valid_channel (struct ac97_hwint *dev, struct ac97_chn_desc *chn)
56{
57 return (dev->last_written_mixer_values[chn->ac97_regnum / 2]
58 != AC97_REG_UNSUPPORTED);
59}
60
61int
62ac97_init (struct ac97_hwint *dev)
63{
64 int x;
65 int reg0;
66
67 /* Clear out the arrays of cached values. */
68 for (x = 0; x < AC97_REG_CNT; x++)
69 dev->last_written_mixer_values[x] = AC97_REGVAL_UNKNOWN;
70
71 for (x = 0; x < SOUND_MIXER_NRDEVICES; x++)
72 dev->last_written_OSS_values[x] = AC97_REGVAL_UNKNOWN;
73
74 /* Clear the device masks. */
75 dev->mixer_devmask = 0;
76 dev->mixer_stereomask = 0;
77 dev->mixer_recmask = 0;
78
79 /* ??? Do a "standard reset" via register 0? */
80
81 /* Hardware-dependent reset. */
82 if (dev->reset_device (dev))
83 return -1;
84
85 /* Check the mixer device capabilities. */
86 reg0 = dev->read_reg (dev, AC97_RESET);
87
88 if (reg0 < 0)
89 return -1;
90
91 /* Check for support for treble/bass controls. */
92 if (! (reg0 & 4)) {
93 dev->last_written_mixer_values[AC97_MASTER_TONE / 2]
94 = AC97_REG_UNSUPPORTED;
95 }
96
97 /* ??? There may be other tests here? */
98
99 /* Fill in the device masks. */
100 for (x = 0; mixerRegs[x].ac97_regnum != -1; x++) {
101 if (ac97_is_valid_channel (dev, mixerRegs + x)) {
102 dev->mixer_devmask |= mixerRegs[x].oss_mask;
103
104 if (mixerRegs[x].is_stereo)
105 dev->mixer_stereomask |= mixerRegs[x].oss_mask;
106
107 if (mixerRegs[x].recordNum != -1)
108 dev->mixer_recmask |= mixerRegs[x].oss_mask;
109 }
110 }
111
112 return 0;
113}
114
115/* Reset the mixer to the currently saved settings. */
116int
117ac97_reset (struct ac97_hwint *dev)
118{
119 int x;
120
121 if (dev->reset_device (dev))
122 return -1;
123
124 /* Now set the registers back to their last-written values. */
125 for (x = 0; mixerRegs[x].ac97_regnum != -1; x++) {
126 int regnum = mixerRegs[x].ac97_regnum;
127 int value = dev->last_written_mixer_values [regnum / 2];
128 if (value >= 0)
129 ac97_put_register (dev, regnum, value);
130 }
131 return 0;
132}
133
134/* Return the contents of register REG; use the cache if the value in it
135 is valid. Returns a negative error code on failure. */
136static int
137ac97_get_register (struct ac97_hwint *dev, u8 reg)
138{
139 if (reg > 127 || (reg & 1))
140 return -EINVAL;
141
142 /* See if it's in the cache, or if it's just plain invalid. */
143 switch (dev->last_written_mixer_values[reg / 2]) {
144 case AC97_REG_UNSUPPORTED:
145 return -EINVAL;
146 break;
147 case AC97_REGVAL_UNKNOWN:
148 dev->last_written_mixer_values[reg / 2] = dev->read_reg (dev, reg);
149 break;
150 default:
151 break;
152 }
153 return dev->last_written_mixer_values[reg / 2];
154}
155
156/* Write VALUE to AC97 register REG, and cache its value in the last-written
157 cache. Returns a negative error code on failure, or 0 on success. */
158int
159ac97_put_register (struct ac97_hwint *dev, u8 reg, u16 value)
160{
161 if (reg > 127 || (reg & 1))
162 return -EINVAL;
163
164 if (dev->last_written_mixer_values[reg / 2] == AC97_REG_UNSUPPORTED)
165 return -EINVAL;
166 else {
167 int res = dev->write_reg (dev, reg, value);
168 if (res >= 0) {
169 dev->last_written_mixer_values[reg / 2] = value;
170 return 0;
171 }
172 else
173 return res;
174 }
175}
176
177/* Scale VALUE (a value fro 0 to MAXVAL) to a value from 0-100. If
178 IS_STEREO is set, VALUE is a stereo value; the left channel value
179 is in the lower 8 bits, and the right channel value is in the upper
180 8 bits.
181
182 A negative error code is returned on failure, or the unsigned
183 scaled value on success. */
184
185static int
186ac97_scale_to_oss_val (int value, int maxval, int is_stereo, int inv)
187{
188 /* Muted? */
189 if (value & AC97_MUTE)
190 return 0;
191
192 if (is_stereo)
193 return (ac97_scale_to_oss_val (value & 255, maxval, 0, inv) << 8)
194 | (ac97_scale_to_oss_val ((value >> 8) & 255, maxval, 0, inv) << 0);
195 else {
196 int i;
197
198 /* Inverted. */
199 if (inv)
200 value = maxval - value;
201
202 i = (value * 100 + (maxval / 2)) / maxval;
203 if (i > 100)
204 i = 100;
205 if (i < 0)
206 i = 0;
207 return i;
208 }
209}
210
211static int
212ac97_scale_from_oss_val (int value, int maxval, int is_stereo, int inv)
213{
214 if (is_stereo)
215 return (ac97_scale_from_oss_val (value & 255, maxval, 0, inv) << 8)
216 | (ac97_scale_from_oss_val ((value >> 8) & 255, maxval, 0, inv) << 0);
217 else {
218 int i = ((value & 255) * maxval + 50) / 100;
219 if (inv)
220 i = maxval - i;
221 if (i < 0)
222 i = 0;
223 if (i > maxval)
224 i = maxval;
225 return i;
226 }
227}
228
229static int
230ac97_set_mixer (struct ac97_hwint *dev, int oss_channel, u16 oss_value)
231{
232 int scaled_value;
233 struct ac97_chn_desc *channel = ac97_find_chndesc (dev, oss_channel);
234 int result;
235
236 if (channel == NULL)
237 return -ENODEV;
238 if (! ac97_is_valid_channel (dev, channel))
239 return -ENODEV;
240 scaled_value = ac97_scale_from_oss_val (oss_value, channel->maxval,
241 channel->is_stereo,
242 channel->is_inverted);
243 if (scaled_value < 0)
244 return scaled_value;
245
246 if (channel->regmask != 0) {
247 int mv;
248
249 int oldval = ac97_get_register (dev, channel->ac97_regnum);
250 if (oldval < 0)
251 return oldval;
252
253 for (mv = channel->regmask; ! (mv & 1); mv >>= 1)
254 scaled_value <<= 1;
255
256 scaled_value &= channel->regmask;
257 scaled_value |= (oldval & ~channel->regmask);
258 }
259 result = ac97_put_register (dev, channel->ac97_regnum, scaled_value);
260 if (result == 0)
261 dev->last_written_OSS_values[oss_channel] = oss_value;
262 return result;
263}
264
265static int
266ac97_get_mixer_scaled (struct ac97_hwint *dev, int oss_channel)
267{
268 struct ac97_chn_desc *channel = ac97_find_chndesc (dev, oss_channel);
269 int regval;
270
271 if (channel == NULL)
272 return -ENODEV;
273
274 if (! ac97_is_valid_channel (dev, channel))
275 return -ENODEV;
276
277 regval = ac97_get_register (dev, channel->ac97_regnum);
278
279 if (regval < 0)
280 return regval;
281
282 if (channel->regmask != 0) {
283 int mv;
284
285 regval &= channel->regmask;
286
287 for (mv = channel->regmask; ! (mv & 1); mv >>= 1)
288 regval >>= 1;
289 }
290 return ac97_scale_to_oss_val (regval, channel->maxval,
291 channel->is_stereo,
292 channel->is_inverted);
293}
294
295static int
296ac97_get_recmask (struct ac97_hwint *dev)
297{
298 int recReg = ac97_get_register (dev, AC97_RECORD_SELECT);
299
300 if (recReg < 0)
301 return recReg;
302 else {
303 int x;
304 for (x = 0; mixerRegs[x].ac97_regnum >= 0; x++) {
305 if (mixerRegs[x].recordNum == (recReg & 7))
306 return mixerRegs[x].oss_mask;
307 }
308 return -ENODEV;
309 }
310}
311
312static int
313ac97_set_recmask (struct ac97_hwint *dev, int oss_recmask)
314{
315 int x;
316
317 if (oss_recmask == 0)
318 oss_recmask = SOUND_MIXER_MIC;
319
320 for (x = 0; mixerRegs[x].ac97_regnum >= 0; x++) {
321 if ((mixerRegs[x].recordNum >= 0)
322 && (oss_recmask & mixerRegs[x].oss_mask))
323 break;
324 }
325 if (mixerRegs[x].ac97_regnum < 0)
326 return -ENODEV;
327 else {
328 int regval = (mixerRegs[x].recordNum << 8) | mixerRegs[x].recordNum;
329 int res = ac97_put_register (dev, AC97_RECORD_SELECT, regval);
330 if (res == 0)
331 return ac97_get_recmask (dev);
332 else
333 return res;
334 }
335}
336
337/* Set the mixer DEV to the list of values in VALUE_LIST. Return 0 on
338 success, or a negative error code. */
339int
340ac97_set_values (struct ac97_hwint *dev,
341 struct ac97_mixer_value_list *value_list)
342{
343 int x;
344
345 for (x = 0; value_list[x].oss_channel != -1; x++) {
346 int chnum = value_list[x].oss_channel;
347 struct ac97_chn_desc *chent = ac97_find_chndesc (dev, chnum);
348 if (chent != NULL) {
349 u16 val;
350 int res;
351
352 if (chent->is_stereo)
353 val = (value_list[x].value.stereo.right << 8)
354 | value_list[x].value.stereo.left;
355 else {
356 /* We do this so the returned value looks OK in the
357 mixer app. It's not necessary otherwise. */
358 val = (value_list[x].value.mono << 8)
359 | value_list[x].value.mono;
360 }
361 res = ac97_set_mixer (dev, chnum, val);
362 if (res < 0)
363 return res;
364 }
365 else
366 return -ENODEV;
367 }
368 return 0;
369}
370
371int
372ac97_mixer_ioctl (struct ac97_hwint *dev, unsigned int cmd, void __user *arg)
373{
374 int ret;
375
376 switch (cmd) {
377 case SOUND_MIXER_READ_RECSRC:
378 ret = ac97_get_recmask (dev);
379 break;
380
381 case SOUND_MIXER_WRITE_RECSRC:
382 {
383 if (get_user (ret, (int __user *) arg))
384 ret = -EFAULT;
385 else
386 ret = ac97_set_recmask (dev, ret);
387 }
388 break;
389
390 case SOUND_MIXER_READ_CAPS:
391 ret = SOUND_CAP_EXCL_INPUT;
392 break;
393
394 case SOUND_MIXER_READ_DEVMASK:
395 ret = dev->mixer_devmask;
396 break;
397
398 case SOUND_MIXER_READ_RECMASK:
399 ret = dev->mixer_recmask;
400 break;
401
402 case SOUND_MIXER_READ_STEREODEVS:
403 ret = dev->mixer_stereomask;
404 break;
405
406 default:
407 /* Read or write request. */
408 ret = -EINVAL;
409 if (_IOC_TYPE (cmd) == 'M') {
410 int dir = _SIOC_DIR (cmd);
411 int channel = _IOC_NR (cmd);
412
413 if (channel >= 0 && channel < SOUND_MIXER_NRDEVICES) {
414 ret = 0;
415 if (dir & _SIOC_WRITE) {
416 int val;
417 if (get_user (val, (int __user *) arg) == 0)
418 ret = ac97_set_mixer (dev, channel, val);
419 else
420 ret = -EFAULT;
421 }
422 if (ret >= 0 && (dir & _SIOC_READ)) {
423 if (dev->last_written_OSS_values[channel]
424 == AC97_REGVAL_UNKNOWN)
425 dev->last_written_OSS_values[channel]
426 = ac97_get_mixer_scaled (dev, channel);
427 ret = dev->last_written_OSS_values[channel];
428 }
429 }
430 }
431 break;
432 }
433
434 if (ret < 0)
435 return ret;
436 else
437 return put_user(ret, (int __user *) arg);
438}
439
440EXPORT_SYMBOL(ac97_init);
441EXPORT_SYMBOL(ac97_set_values);
442EXPORT_SYMBOL(ac97_put_register);
443EXPORT_SYMBOL(ac97_mixer_ioctl);
444EXPORT_SYMBOL(ac97_reset);
445MODULE_LICENSE("GPL");
446
447
448/*
449 * Local variables:
450 * c-basic-offset: 4
451 * End:
452 */
diff --git a/sound/oss/ac97.h b/sound/oss/ac97.h
new file mode 100644
index 000000000000..77d454ea3202
--- /dev/null
+++ b/sound/oss/ac97.h
@@ -0,0 +1,204 @@
1/*
2 * ac97.h
3 *
4 * definitions for the AC97, Intel's Audio Codec 97 Spec
5 * also includes support for a generic AC97 interface
6 */
7
8#ifndef _AC97_H_
9#define _AC97_H_
10#include "sound_config.h"
11#include "sound_calls.h"
12
13#define AC97_RESET 0x0000 //
14#define AC97_MASTER_VOL_STEREO 0x0002 // Line Out
15#define AC97_HEADPHONE_VOL 0x0004 //
16#define AC97_MASTER_VOL_MONO 0x0006 // TAD Output
17#define AC97_MASTER_TONE 0x0008 //
18#define AC97_PCBEEP_VOL 0x000a // none
19#define AC97_PHONE_VOL 0x000c // TAD Input (mono)
20#define AC97_MIC_VOL 0x000e // MIC Input (mono)
21#define AC97_LINEIN_VOL 0x0010 // Line Input (stereo)
22#define AC97_CD_VOL 0x0012 // CD Input (stereo)
23#define AC97_VIDEO_VOL 0x0014 // none
24#define AC97_AUX_VOL 0x0016 // Aux Input (stereo)
25#define AC97_PCMOUT_VOL 0x0018 // Wave Output (stereo)
26#define AC97_RECORD_SELECT 0x001a //
27#define AC97_RECORD_GAIN 0x001c
28#define AC97_RECORD_GAIN_MIC 0x001e
29#define AC97_GENERAL_PURPOSE 0x0020
30#define AC97_3D_CONTROL 0x0022
31#define AC97_MODEM_RATE 0x0024
32#define AC97_POWER_CONTROL 0x0026
33
34/* registers 0x0028 - 0x0058 are reserved */
35
36/* AC'97 2.0 */
37#define AC97_EXTENDED_ID 0x0028 /* Extended Audio ID */
38#define AC97_EXTENDED_STATUS 0x002A /* Extended Audio Status */
39#define AC97_PCM_FRONT_DAC_RATE 0x002C /* PCM Front DAC Rate */
40#define AC97_PCM_SURR_DAC_RATE 0x002E /* PCM Surround DAC Rate */
41#define AC97_PCM_LFE_DAC_RATE 0x0030 /* PCM LFE DAC Rate */
42#define AC97_PCM_LR_ADC_RATE 0x0032 /* PCM LR DAC Rate */
43#define AC97_PCM_MIC_ADC_RATE 0x0034 /* PCM MIC ADC Rate */
44#define AC97_CENTER_LFE_MASTER 0x0036 /* Center + LFE Master Volume */
45#define AC97_SURROUND_MASTER 0x0038 /* Surround (Rear) Master Volume */
46#define AC97_RESERVED_3A 0x003A /* Reserved */
47/* range 0x3c-0x58 - MODEM */
48
49/* registers 0x005a - 0x007a are vendor reserved */
50
51#define AC97_VENDOR_ID1 0x007c
52#define AC97_VENDOR_ID2 0x007e
53
54/* volume control bit defines */
55
56#define AC97_MUTE 0x8000
57#define AC97_MICBOOST 0x0040
58#define AC97_LEFTVOL 0x3f00
59#define AC97_RIGHTVOL 0x003f
60
61/* record mux defines */
62
63#define AC97_RECMUX_MIC 0x0000
64#define AC97_RECMUX_CD 0x0101
65#define AC97_RECMUX_VIDEO 0x0202 /* not used */
66#define AC97_RECMUX_AUX 0x0303
67#define AC97_RECMUX_LINE 0x0404
68#define AC97_RECMUX_STEREO_MIX 0x0505
69#define AC97_RECMUX_MONO_MIX 0x0606
70#define AC97_RECMUX_PHONE 0x0707
71
72
73/* general purpose register bit defines */
74
75#define AC97_GP_LPBK 0x0080 /* Loopback mode */
76#define AC97_GP_MS 0x0100 /* Mic Select 0=Mic1, 1=Mic2 */
77#define AC97_GP_MIX 0x0200 /* Mono output select 0=Mix, 1=Mic */
78#define AC97_GP_RLBK 0x0400 /* Remote Loopback - Modem line codec */
79#define AC97_GP_LLBK 0x0800 /* Local Loopback - Modem Line codec */
80#define AC97_GP_LD 0x1000 /* Loudness 1=on */
81#define AC97_GP_3D 0x2000 /* 3D Enhancement 1=on */
82#define AC97_GP_ST 0x4000 /* Stereo Enhancement 1=on */
83#define AC97_GP_POP 0x8000 /* Pcm Out Path, 0=pre 3D, 1=post 3D */
84
85
86/* powerdown control and status bit defines */
87
88/* status */
89#define AC97_PWR_MDM 0x0010 /* Modem section ready */
90#define AC97_PWR_REF 0x0008 /* Vref nominal */
91#define AC97_PWR_ANL 0x0004 /* Analog section ready */
92#define AC97_PWR_DAC 0x0002 /* DAC section ready */
93#define AC97_PWR_ADC 0x0001 /* ADC section ready */
94
95/* control */
96#define AC97_PWR_PR0 0x0100 /* ADC and Mux powerdown */
97#define AC97_PWR_PR1 0x0200 /* DAC powerdown */
98#define AC97_PWR_PR2 0x0400 /* Output mixer powerdown (Vref on) */
99#define AC97_PWR_PR3 0x0800 /* Output mixer powerdown (Vref off) */
100#define AC97_PWR_PR4 0x1000 /* AC-link powerdown */
101#define AC97_PWR_PR5 0x2000 /* Internal Clk disable */
102#define AC97_PWR_PR6 0x4000 /* HP amp powerdown */
103#define AC97_PWR_PR7 0x8000 /* Modem off - if supported */
104
105/* useful power states */
106#define AC97_PWR_D0 0x0000 /* everything on */
107#define AC97_PWR_D1 AC97_PWR_PR0|AC97_PWR_PR1|AC97_PWR_PR4
108#define AC97_PWR_D2 AC97_PWR_PR0|AC97_PWR_PR1|AC97_PWR_PR2|AC97_PWR_PR3|AC97_PWR_PR4
109#define AC97_PWR_D3 AC97_PWR_PR0|AC97_PWR_PR1|AC97_PWR_PR2|AC97_PWR_PR3|AC97_PWR_PR4
110#define AC97_PWR_ANLOFF AC97_PWR_PR2|AC97_PWR_PR3 /* analog section off */
111
112/* Total number of defined registers. */
113#define AC97_REG_CNT 64
114
115/* Generic AC97 mixer interface. */
116
117/* Structure describing access to the hardware. */
118struct ac97_hwint
119{
120 /* Perform any hardware-specific reset and initialization. Returns
121 0 on success, or a negative error code. */
122 int (*reset_device) (struct ac97_hwint *dev);
123
124 /* Returns the contents of the specified register REG. The caller
125 should check to see if the desired contents are available in
126 the cache first, if applicable. Returns a positive unsigned value
127 representing the contents of the register, or a negative error
128 code. */
129 int (*read_reg) (struct ac97_hwint *dev, u8 reg);
130
131 /* Writes VALUE to register REG. Returns 0 on success, or a
132 negative error code. */
133 int (*write_reg) (struct ac97_hwint *dev, u8 reg, u16 value);
134
135 /* Hardware-specific information. */
136 void *driver_private;
137
138 /* Three OSS masks. */
139 int mixer_devmask;
140 int mixer_stereomask;
141 int mixer_recmask;
142
143 /* The mixer cache. The indices correspond to the AC97 hardware register
144 number / 2, since the register numbers are always an even number.
145
146 Unknown values are set to -1; unsupported registers contain a
147 -2. */
148 int last_written_mixer_values[AC97_REG_CNT];
149
150 /* A cache of values written via OSS; we need these so we can return
151 the values originally written by the user.
152
153 Why the original user values? Because the real-world hardware
154 has less precision, and some existing applications assume that
155 they will get back the exact value that they wrote (aumix).
156
157 A -1 value indicates that no value has been written to this mixer
158 channel via OSS. */
159 int last_written_OSS_values[SOUND_MIXER_NRDEVICES];
160};
161
162/* Values stored in the register cache. */
163#define AC97_REGVAL_UNKNOWN -1
164#define AC97_REG_UNSUPPORTED -2
165
166struct ac97_mixer_value_list
167{
168 /* Mixer channel to set. List is terminated by a value of -1. */
169 int oss_channel;
170 /* The scaled value to set it to; values generally range from 0-100. */
171 union {
172 struct {
173 u8 left, right;
174 } stereo;
175 u8 mono;
176 } value;
177};
178
179/* Initialize the ac97 mixer by resetting it. */
180extern int ac97_init (struct ac97_hwint *dev);
181
182/* Sets the mixer DEV to the values in VALUE_LIST. Returns 0 on success,
183 or a negative error code. */
184extern int ac97_set_values (struct ac97_hwint *dev,
185 struct ac97_mixer_value_list *value_list);
186
187/* Writes the specified VALUE to the AC97 register REG in the mixer.
188 Takes care of setting the last-written cache as well. */
189extern int ac97_put_register (struct ac97_hwint *dev, u8 reg, u16 value);
190
191/* Default ioctl. */
192extern int ac97_mixer_ioctl (struct ac97_hwint *dev, unsigned int cmd,
193 void __user * arg);
194
195/* Do a complete reset on the AC97 mixer, restoring all mixer registers to
196 the current values. Normally used after an APM resume event. */
197extern int ac97_reset (struct ac97_hwint *dev);
198#endif
199
200/*
201 * Local variables:
202 * c-basic-offset: 4
203 * End:
204 */
diff --git a/sound/oss/ac97_codec.c b/sound/oss/ac97_codec.c
new file mode 100644
index 000000000000..124b1e10a13d
--- /dev/null
+++ b/sound/oss/ac97_codec.c
@@ -0,0 +1,1576 @@
1/*
2 * ac97_codec.c: Generic AC97 mixer/modem module
3 *
4 * Derived from ac97 mixer in maestro and trident driver.
5 *
6 * Copyright 2000 Silicon Integrated System Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 **************************************************************************
23 *
24 * The Intel Audio Codec '97 specification is available at the Intel
25 * audio homepage: http://developer.intel.com/ial/scalableplatforms/audio/
26 *
27 * The specification itself is currently available at:
28 * ftp://download.intel.com/ial/scalableplatforms/ac97r22.pdf
29 *
30 **************************************************************************
31 *
32 * History
33 * May 02, 2003 Liam Girdwood <liam.girdwood@wolfsonmicro.com>
34 * Removed non existant WM9700
35 * Added support for WM9705, WM9708, WM9709, WM9710, WM9711
36 * WM9712 and WM9717
37 * Mar 28, 2002 Randolph Bentson <bentson@holmsjoen.com>
38 * corrections to support WM9707 in ViewPad 1000
39 * v0.4 Mar 15 2000 Ollie Lho
40 * dual codecs support verified with 4 channels output
41 * v0.3 Feb 22 2000 Ollie Lho
42 * bug fix for record mask setting
43 * v0.2 Feb 10 2000 Ollie Lho
44 * add ac97_read_proc for /proc/driver/{vendor}/ac97
45 * v0.1 Jan 14 2000 Ollie Lho <ollie@sis.com.tw>
46 * Isolated from trident.c to support multiple ac97 codec
47 */
48#include <linux/module.h>
49#include <linux/kernel.h>
50#include <linux/slab.h>
51#include <linux/string.h>
52#include <linux/errno.h>
53#include <linux/bitops.h>
54#include <linux/delay.h>
55#include <linux/pci.h>
56#include <linux/ac97_codec.h>
57#include <asm/uaccess.h>
58
59#define CODEC_ID_BUFSZ 14
60
61static int ac97_read_mixer(struct ac97_codec *codec, int oss_channel);
62static void ac97_write_mixer(struct ac97_codec *codec, int oss_channel,
63 unsigned int left, unsigned int right);
64static void ac97_set_mixer(struct ac97_codec *codec, unsigned int oss_mixer, unsigned int val );
65static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask);
66static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg);
67
68static int ac97_init_mixer(struct ac97_codec *codec);
69
70static int wolfson_init03(struct ac97_codec * codec);
71static int wolfson_init04(struct ac97_codec * codec);
72static int wolfson_init05(struct ac97_codec * codec);
73static int wolfson_init11(struct ac97_codec * codec);
74static int wolfson_init13(struct ac97_codec * codec);
75static int tritech_init(struct ac97_codec * codec);
76static int tritech_maestro_init(struct ac97_codec * codec);
77static int sigmatel_9708_init(struct ac97_codec *codec);
78static int sigmatel_9721_init(struct ac97_codec *codec);
79static int sigmatel_9744_init(struct ac97_codec *codec);
80static int ad1886_init(struct ac97_codec *codec);
81static int eapd_control(struct ac97_codec *codec, int);
82static int crystal_digital_control(struct ac97_codec *codec, int slots, int rate, int mode);
83static int cmedia_init(struct ac97_codec * codec);
84static int cmedia_digital_control(struct ac97_codec *codec, int slots, int rate, int mode);
85static int generic_digital_control(struct ac97_codec *codec, int slots, int rate, int mode);
86
87
88/*
89 * AC97 operations.
90 *
91 * If you are adding a codec then you should be able to use
92 * eapd_ops - any codec that supports EAPD amp control (most)
93 * null_ops - any ancient codec that supports nothing
94 *
95 * The three functions are
96 * init - used for non AC97 standard initialisation
97 * amplifier - used to do amplifier control (1=on 0=off)
98 * digital - switch to digital modes (0 = analog)
99 *
100 * Not all codecs support all features, not all drivers use all the
101 * operations yet
102 */
103
104static struct ac97_ops null_ops = { NULL, NULL, NULL };
105static struct ac97_ops default_ops = { NULL, eapd_control, NULL };
106static struct ac97_ops default_digital_ops = { NULL, eapd_control, generic_digital_control};
107static struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
108static struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
109static struct ac97_ops wolfson_ops05 = { wolfson_init05, NULL, NULL };
110static struct ac97_ops wolfson_ops11 = { wolfson_init11, NULL, NULL };
111static struct ac97_ops wolfson_ops13 = { wolfson_init13, NULL, NULL };
112static struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
113static struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
114static struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
115static struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
116static struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
117static struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
118static struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
119static struct ac97_ops cmedia_ops = { NULL, eapd_control, NULL};
120static struct ac97_ops cmedia_digital_ops = { cmedia_init, eapd_control, cmedia_digital_control};
121
122/* sorted by vendor/device id */
123static const struct {
124 u32 id;
125 char *name;
126 struct ac97_ops *ops;
127 int flags;
128} ac97_codec_ids[] = {
129 {0x41445303, "Analog Devices AD1819", &null_ops},
130 {0x41445340, "Analog Devices AD1881", &null_ops},
131 {0x41445348, "Analog Devices AD1881A", &null_ops},
132 {0x41445360, "Analog Devices AD1885", &default_ops},
133 {0x41445361, "Analog Devices AD1886", &ad1886_ops},
134 {0x41445370, "Analog Devices AD1981", &null_ops},
135 {0x41445372, "Analog Devices AD1981A", &null_ops},
136 {0x41445374, "Analog Devices AD1981B", &null_ops},
137 {0x41445460, "Analog Devices AD1885", &default_ops},
138 {0x41445461, "Analog Devices AD1886", &ad1886_ops},
139 {0x414B4D00, "Asahi Kasei AK4540", &null_ops},
140 {0x414B4D01, "Asahi Kasei AK4542", &null_ops},
141 {0x414B4D02, "Asahi Kasei AK4543", &null_ops},
142 {0x414C4326, "ALC100P", &null_ops},
143 {0x414C4710, "ALC200/200P", &null_ops},
144 {0x414C4720, "ALC650", &default_digital_ops},
145 {0x434D4941, "CMedia", &cmedia_ops, AC97_NO_PCM_VOLUME },
146 {0x434D4942, "CMedia", &cmedia_ops, AC97_NO_PCM_VOLUME },
147 {0x434D4961, "CMedia", &cmedia_digital_ops, AC97_NO_PCM_VOLUME },
148 {0x43525900, "Cirrus Logic CS4297", &default_ops},
149 {0x43525903, "Cirrus Logic CS4297", &default_ops},
150 {0x43525913, "Cirrus Logic CS4297A rev A", &default_ops},
151 {0x43525914, "Cirrus Logic CS4297A rev B", &default_ops},
152 {0x43525923, "Cirrus Logic CS4298", &null_ops},
153 {0x4352592B, "Cirrus Logic CS4294", &null_ops},
154 {0x4352592D, "Cirrus Logic CS4294", &null_ops},
155 {0x43525931, "Cirrus Logic CS4299 rev A", &crystal_digital_ops},
156 {0x43525933, "Cirrus Logic CS4299 rev C", &crystal_digital_ops},
157 {0x43525934, "Cirrus Logic CS4299 rev D", &crystal_digital_ops},
158 {0x43585442, "CXT66", &default_ops, AC97_DELUDED_MODEM },
159 {0x44543031, "Diamond Technology DT0893", &default_ops},
160 {0x45838308, "ESS Allegro ES1988", &null_ops},
161 {0x49434511, "ICE1232", &null_ops}, /* I hope --jk */
162 {0x4e534331, "National Semiconductor LM4549", &null_ops},
163 {0x53494c22, "Silicon Laboratory Si3036", &null_ops},
164 {0x53494c23, "Silicon Laboratory Si3038", &null_ops},
165 {0x545200FF, "TriTech TR?????", &tritech_m_ops},
166 {0x54524102, "TriTech TR28022", &null_ops},
167 {0x54524103, "TriTech TR28023", &null_ops},
168 {0x54524106, "TriTech TR28026", &null_ops},
169 {0x54524108, "TriTech TR28028", &tritech_ops},
170 {0x54524123, "TriTech TR A5", &null_ops},
171 {0x574D4C03, "Wolfson WM9703/07/08/17", &wolfson_ops03},
172 {0x574D4C04, "Wolfson WM9704M/WM9704Q", &wolfson_ops04},
173 {0x574D4C05, "Wolfson WM9705/WM9710", &wolfson_ops05},
174 {0x574D4C09, "Wolfson WM9709", &null_ops},
175 {0x574D4C12, "Wolfson WM9711/9712", &wolfson_ops11},
176 {0x574D4C13, "Wolfson WM9713", &wolfson_ops13, AC97_DEFAULT_POWER_OFF},
177 {0x83847600, "SigmaTel STAC????", &null_ops},
178 {0x83847604, "SigmaTel STAC9701/3/4/5", &null_ops},
179 {0x83847605, "SigmaTel STAC9704", &null_ops},
180 {0x83847608, "SigmaTel STAC9708", &sigmatel_9708_ops},
181 {0x83847609, "SigmaTel STAC9721/23", &sigmatel_9721_ops},
182 {0x83847644, "SigmaTel STAC9744/45", &sigmatel_9744_ops},
183 {0x83847652, "SigmaTel STAC9752/53", &default_ops},
184 {0x83847656, "SigmaTel STAC9756/57", &sigmatel_9744_ops},
185 {0x83847666, "SigmaTel STAC9750T", &sigmatel_9744_ops},
186 {0x83847684, "SigmaTel STAC9783/84?", &null_ops},
187 {0x57454301, "Winbond 83971D", &null_ops},
188};
189
190static const char *ac97_stereo_enhancements[] =
191{
192 /* 0 */ "No 3D Stereo Enhancement",
193 /* 1 */ "Analog Devices Phat Stereo",
194 /* 2 */ "Creative Stereo Enhancement",
195 /* 3 */ "National Semi 3D Stereo Enhancement",
196 /* 4 */ "YAMAHA Ymersion",
197 /* 5 */ "BBE 3D Stereo Enhancement",
198 /* 6 */ "Crystal Semi 3D Stereo Enhancement",
199 /* 7 */ "Qsound QXpander",
200 /* 8 */ "Spatializer 3D Stereo Enhancement",
201 /* 9 */ "SRS 3D Stereo Enhancement",
202 /* 10 */ "Platform Tech 3D Stereo Enhancement",
203 /* 11 */ "AKM 3D Audio",
204 /* 12 */ "Aureal Stereo Enhancement",
205 /* 13 */ "Aztech 3D Enhancement",
206 /* 14 */ "Binaura 3D Audio Enhancement",
207 /* 15 */ "ESS Technology Stereo Enhancement",
208 /* 16 */ "Harman International VMAx",
209 /* 17 */ "Nvidea 3D Stereo Enhancement",
210 /* 18 */ "Philips Incredible Sound",
211 /* 19 */ "Texas Instruments 3D Stereo Enhancement",
212 /* 20 */ "VLSI Technology 3D Stereo Enhancement",
213 /* 21 */ "TriTech 3D Stereo Enhancement",
214 /* 22 */ "Realtek 3D Stereo Enhancement",
215 /* 23 */ "Samsung 3D Stereo Enhancement",
216 /* 24 */ "Wolfson Microelectronics 3D Enhancement",
217 /* 25 */ "Delta Integration 3D Enhancement",
218 /* 26 */ "SigmaTel 3D Enhancement",
219 /* 27 */ "Winbond 3D Stereo Enhancement",
220 /* 28 */ "Rockwell 3D Stereo Enhancement",
221 /* 29 */ "Reserved 29",
222 /* 30 */ "Reserved 30",
223 /* 31 */ "Reserved 31"
224};
225
226/* this table has default mixer values for all OSS mixers. */
227static struct mixer_defaults {
228 int mixer;
229 unsigned int value;
230} mixer_defaults[SOUND_MIXER_NRDEVICES] = {
231 /* all values 0 -> 100 in bytes */
232 {SOUND_MIXER_VOLUME, 0x4343},
233 {SOUND_MIXER_BASS, 0x4343},
234 {SOUND_MIXER_TREBLE, 0x4343},
235 {SOUND_MIXER_PCM, 0x4343},
236 {SOUND_MIXER_SPEAKER, 0x4343},
237 {SOUND_MIXER_LINE, 0x4343},
238 {SOUND_MIXER_MIC, 0x0000},
239 {SOUND_MIXER_CD, 0x4343},
240 {SOUND_MIXER_ALTPCM, 0x4343},
241 {SOUND_MIXER_IGAIN, 0x4343},
242 {SOUND_MIXER_LINE1, 0x4343},
243 {SOUND_MIXER_PHONEIN, 0x4343},
244 {SOUND_MIXER_PHONEOUT, 0x4343},
245 {SOUND_MIXER_VIDEO, 0x4343},
246 {-1,0}
247};
248
249/* table to scale scale from OSS mixer value to AC97 mixer register value */
250static struct ac97_mixer_hw {
251 unsigned char offset;
252 int scale;
253} ac97_hw[SOUND_MIXER_NRDEVICES]= {
254 [SOUND_MIXER_VOLUME] = {AC97_MASTER_VOL_STEREO,64},
255 [SOUND_MIXER_BASS] = {AC97_MASTER_TONE, 16},
256 [SOUND_MIXER_TREBLE] = {AC97_MASTER_TONE, 16},
257 [SOUND_MIXER_PCM] = {AC97_PCMOUT_VOL, 32},
258 [SOUND_MIXER_SPEAKER] = {AC97_PCBEEP_VOL, 16},
259 [SOUND_MIXER_LINE] = {AC97_LINEIN_VOL, 32},
260 [SOUND_MIXER_MIC] = {AC97_MIC_VOL, 32},
261 [SOUND_MIXER_CD] = {AC97_CD_VOL, 32},
262 [SOUND_MIXER_ALTPCM] = {AC97_HEADPHONE_VOL, 64},
263 [SOUND_MIXER_IGAIN] = {AC97_RECORD_GAIN, 16},
264 [SOUND_MIXER_LINE1] = {AC97_AUX_VOL, 32},
265 [SOUND_MIXER_PHONEIN] = {AC97_PHONE_VOL, 32},
266 [SOUND_MIXER_PHONEOUT] = {AC97_MASTER_VOL_MONO, 64},
267 [SOUND_MIXER_VIDEO] = {AC97_VIDEO_VOL, 32},
268};
269
270/* the following tables allow us to go from OSS <-> ac97 quickly. */
271enum ac97_recsettings {
272 AC97_REC_MIC=0,
273 AC97_REC_CD,
274 AC97_REC_VIDEO,
275 AC97_REC_AUX,
276 AC97_REC_LINE,
277 AC97_REC_STEREO, /* combination of all enabled outputs.. */
278 AC97_REC_MONO, /*.. or the mono equivalent */
279 AC97_REC_PHONE
280};
281
282static const unsigned int ac97_rm2oss[] = {
283 [AC97_REC_MIC] = SOUND_MIXER_MIC,
284 [AC97_REC_CD] = SOUND_MIXER_CD,
285 [AC97_REC_VIDEO] = SOUND_MIXER_VIDEO,
286 [AC97_REC_AUX] = SOUND_MIXER_LINE1,
287 [AC97_REC_LINE] = SOUND_MIXER_LINE,
288 [AC97_REC_STEREO]= SOUND_MIXER_IGAIN,
289 [AC97_REC_PHONE] = SOUND_MIXER_PHONEIN
290};
291
292/* indexed by bit position */
293static const unsigned int ac97_oss_rm[] = {
294 [SOUND_MIXER_MIC] = AC97_REC_MIC,
295 [SOUND_MIXER_CD] = AC97_REC_CD,
296 [SOUND_MIXER_VIDEO] = AC97_REC_VIDEO,
297 [SOUND_MIXER_LINE1] = AC97_REC_AUX,
298 [SOUND_MIXER_LINE] = AC97_REC_LINE,
299 [SOUND_MIXER_IGAIN] = AC97_REC_STEREO,
300 [SOUND_MIXER_PHONEIN] = AC97_REC_PHONE
301};
302
303static LIST_HEAD(codecs);
304static LIST_HEAD(codec_drivers);
305static DECLARE_MUTEX(codec_sem);
306
307/* reads the given OSS mixer from the ac97 the caller must have insured that the ac97 knows
308 about that given mixer, and should be holding a spinlock for the card */
309static int ac97_read_mixer(struct ac97_codec *codec, int oss_channel)
310{
311 u16 val;
312 int ret = 0;
313 int scale;
314 struct ac97_mixer_hw *mh = &ac97_hw[oss_channel];
315
316 val = codec->codec_read(codec , mh->offset);
317
318 if (val & AC97_MUTE) {
319 ret = 0;
320 } else if (AC97_STEREO_MASK & (1 << oss_channel)) {
321 /* nice stereo mixers .. */
322 int left,right;
323
324 left = (val >> 8) & 0x7f;
325 right = val & 0x7f;
326
327 if (oss_channel == SOUND_MIXER_IGAIN) {
328 right = (right * 100) / mh->scale;
329 left = (left * 100) / mh->scale;
330 } else {
331 /* these may have 5 or 6 bit resolution */
332 if(oss_channel == SOUND_MIXER_VOLUME || oss_channel == SOUND_MIXER_ALTPCM)
333 scale = (1 << codec->bit_resolution);
334 else
335 scale = mh->scale;
336
337 right = 100 - ((right * 100) / scale);
338 left = 100 - ((left * 100) / scale);
339 }
340 ret = left | (right << 8);
341 } else if (oss_channel == SOUND_MIXER_SPEAKER) {
342 ret = 100 - ((((val & 0x1e)>>1) * 100) / mh->scale);
343 } else if (oss_channel == SOUND_MIXER_PHONEIN) {
344 ret = 100 - (((val & 0x1f) * 100) / mh->scale);
345 } else if (oss_channel == SOUND_MIXER_PHONEOUT) {
346 scale = (1 << codec->bit_resolution);
347 ret = 100 - (((val & 0x1f) * 100) / scale);
348 } else if (oss_channel == SOUND_MIXER_MIC) {
349 ret = 100 - (((val & 0x1f) * 100) / mh->scale);
350 /* the low bit is optional in the tone sliders and masking
351 it lets us avoid the 0xf 'bypass'.. */
352 } else if (oss_channel == SOUND_MIXER_BASS) {
353 ret = 100 - ((((val >> 8) & 0xe) * 100) / mh->scale);
354 } else if (oss_channel == SOUND_MIXER_TREBLE) {
355 ret = 100 - (((val & 0xe) * 100) / mh->scale);
356 }
357
358#ifdef DEBUG
359 printk("ac97_codec: read OSS mixer %2d (%s ac97 register 0x%02x), "
360 "0x%04x -> 0x%04x\n",
361 oss_channel, codec->id ? "Secondary" : "Primary",
362 mh->offset, val, ret);
363#endif
364
365 return ret;
366}
367
368/* write the OSS encoded volume to the given OSS encoded mixer, again caller's job to
369 make sure all is well in arg land, call with spinlock held */
370static void ac97_write_mixer(struct ac97_codec *codec, int oss_channel,
371 unsigned int left, unsigned int right)
372{
373 u16 val = 0;
374 int scale;
375 struct ac97_mixer_hw *mh = &ac97_hw[oss_channel];
376
377#ifdef DEBUG
378 printk("ac97_codec: wrote OSS mixer %2d (%s ac97 register 0x%02x), "
379 "left vol:%2d, right vol:%2d:",
380 oss_channel, codec->id ? "Secondary" : "Primary",
381 mh->offset, left, right);
382#endif
383
384 if (AC97_STEREO_MASK & (1 << oss_channel)) {
385 /* stereo mixers */
386 if (left == 0 && right == 0) {
387 val = AC97_MUTE;
388 } else {
389 if (oss_channel == SOUND_MIXER_IGAIN) {
390 right = (right * mh->scale) / 100;
391 left = (left * mh->scale) / 100;
392 if (right >= mh->scale)
393 right = mh->scale-1;
394 if (left >= mh->scale)
395 left = mh->scale-1;
396 } else {
397 /* these may have 5 or 6 bit resolution */
398 if (oss_channel == SOUND_MIXER_VOLUME ||
399 oss_channel == SOUND_MIXER_ALTPCM)
400 scale = (1 << codec->bit_resolution);
401 else
402 scale = mh->scale;
403
404 right = ((100 - right) * scale) / 100;
405 left = ((100 - left) * scale) / 100;
406 if (right >= scale)
407 right = scale-1;
408 if (left >= scale)
409 left = scale-1;
410 }
411 val = (left << 8) | right;
412 }
413 } else if (oss_channel == SOUND_MIXER_BASS) {
414 val = codec->codec_read(codec , mh->offset) & ~0x0f00;
415 left = ((100 - left) * mh->scale) / 100;
416 if (left >= mh->scale)
417 left = mh->scale-1;
418 val |= (left << 8) & 0x0e00;
419 } else if (oss_channel == SOUND_MIXER_TREBLE) {
420 val = codec->codec_read(codec , mh->offset) & ~0x000f;
421 left = ((100 - left) * mh->scale) / 100;
422 if (left >= mh->scale)
423 left = mh->scale-1;
424 val |= left & 0x000e;
425 } else if(left == 0) {
426 val = AC97_MUTE;
427 } else if (oss_channel == SOUND_MIXER_SPEAKER) {
428 left = ((100 - left) * mh->scale) / 100;
429 if (left >= mh->scale)
430 left = mh->scale-1;
431 val = left << 1;
432 } else if (oss_channel == SOUND_MIXER_PHONEIN) {
433 left = ((100 - left) * mh->scale) / 100;
434 if (left >= mh->scale)
435 left = mh->scale-1;
436 val = left;
437 } else if (oss_channel == SOUND_MIXER_PHONEOUT) {
438 scale = (1 << codec->bit_resolution);
439 left = ((100 - left) * scale) / 100;
440 if (left >= mh->scale)
441 left = mh->scale-1;
442 val = left;
443 } else if (oss_channel == SOUND_MIXER_MIC) {
444 val = codec->codec_read(codec , mh->offset) & ~0x801f;
445 left = ((100 - left) * mh->scale) / 100;
446 if (left >= mh->scale)
447 left = mh->scale-1;
448 val |= left;
449 /* the low bit is optional in the tone sliders and masking
450 it lets us avoid the 0xf 'bypass'.. */
451 }
452#ifdef DEBUG
453 printk(" 0x%04x", val);
454#endif
455
456 codec->codec_write(codec, mh->offset, val);
457
458#ifdef DEBUG
459 val = codec->codec_read(codec, mh->offset);
460 printk(" -> 0x%04x\n", val);
461#endif
462}
463
464/* a thin wrapper for write_mixer */
465static void ac97_set_mixer(struct ac97_codec *codec, unsigned int oss_mixer, unsigned int val )
466{
467 unsigned int left,right;
468
469 /* cleanse input a little */
470 right = ((val >> 8) & 0xff) ;
471 left = (val & 0xff) ;
472
473 if (right > 100) right = 100;
474 if (left > 100) left = 100;
475
476 codec->mixer_state[oss_mixer] = (right << 8) | left;
477 codec->write_mixer(codec, oss_mixer, left, right);
478}
479
480/* read or write the recmask, the ac97 can really have left and right recording
481 inputs independantly set, but OSS doesn't seem to want us to express that to
482 the user. the caller guarantees that we have a supported bit set, and they
483 must be holding the card's spinlock */
484static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask)
485{
486 unsigned int val;
487
488 if (rw) {
489 /* read it from the card */
490 val = codec->codec_read(codec, AC97_RECORD_SELECT);
491#ifdef DEBUG
492 printk("ac97_codec: ac97 recmask to set to 0x%04x\n", val);
493#endif
494 return (1 << ac97_rm2oss[val & 0x07]);
495 }
496
497 /* else, write the first set in the mask as the
498 output */
499 /* clear out current set value first (AC97 supports only 1 input!) */
500 val = (1 << ac97_rm2oss[codec->codec_read(codec, AC97_RECORD_SELECT) & 0x07]);
501 if (mask != val)
502 mask &= ~val;
503
504 val = ffs(mask);
505 val = ac97_oss_rm[val-1];
506 val |= val << 8; /* set both channels */
507
508#ifdef DEBUG
509 printk("ac97_codec: setting ac97 recmask to 0x%04x\n", val);
510#endif
511
512 codec->codec_write(codec, AC97_RECORD_SELECT, val);
513
514 return 0;
515};
516
517static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg)
518{
519 int i, val = 0;
520
521 if (cmd == SOUND_MIXER_INFO) {
522 mixer_info info;
523 memset(&info, 0, sizeof(info));
524 strlcpy(info.id, codec->name, sizeof(info.id));
525 strlcpy(info.name, codec->name, sizeof(info.name));
526 info.modify_counter = codec->modcnt;
527 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
528 return -EFAULT;
529 return 0;
530 }
531 if (cmd == SOUND_OLD_MIXER_INFO) {
532 _old_mixer_info info;
533 memset(&info, 0, sizeof(info));
534 strlcpy(info.id, codec->name, sizeof(info.id));
535 strlcpy(info.name, codec->name, sizeof(info.name));
536 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
537 return -EFAULT;
538 return 0;
539 }
540
541 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
542 return -EINVAL;
543
544 if (cmd == OSS_GETVERSION)
545 return put_user(SOUND_VERSION, (int __user *)arg);
546
547 if (_SIOC_DIR(cmd) == _SIOC_READ) {
548 switch (_IOC_NR(cmd)) {
549 case SOUND_MIXER_RECSRC: /* give them the current record source */
550 if (!codec->recmask_io) {
551 val = 0;
552 } else {
553 val = codec->recmask_io(codec, 1, 0);
554 }
555 break;
556
557 case SOUND_MIXER_DEVMASK: /* give them the supported mixers */
558 val = codec->supported_mixers;
559 break;
560
561 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
562 val = codec->record_sources;
563 break;
564
565 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
566 val = codec->stereo_mixers;
567 break;
568
569 case SOUND_MIXER_CAPS:
570 val = SOUND_CAP_EXCL_INPUT;
571 break;
572
573 default: /* read a specific mixer */
574 i = _IOC_NR(cmd);
575
576 if (!supported_mixer(codec, i))
577 return -EINVAL;
578
579 /* do we ever want to touch the hardware? */
580 /* val = codec->read_mixer(codec, i); */
581 val = codec->mixer_state[i];
582 break;
583 }
584 return put_user(val, (int __user *)arg);
585 }
586
587 if (_SIOC_DIR(cmd) == (_SIOC_WRITE|_SIOC_READ)) {
588 codec->modcnt++;
589 if (get_user(val, (int __user *)arg))
590 return -EFAULT;
591
592 switch (_IOC_NR(cmd)) {
593 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
594 if (!codec->recmask_io) return -EINVAL;
595 if (!val) return 0;
596 if (!(val &= codec->record_sources)) return -EINVAL;
597
598 codec->recmask_io(codec, 0, val);
599
600 return 0;
601 default: /* write a specific mixer */
602 i = _IOC_NR(cmd);
603
604 if (!supported_mixer(codec, i))
605 return -EINVAL;
606
607 ac97_set_mixer(codec, i, val);
608
609 return 0;
610 }
611 }
612 return -EINVAL;
613}
614
615/* entry point for /proc/driver/controller_vendor/ac97/%d */
616int ac97_read_proc (char *page, char **start, off_t off,
617 int count, int *eof, void *data)
618{
619 int len = 0, cap, extid, val, id1, id2;
620 struct ac97_codec *codec;
621 int is_ac97_20 = 0;
622
623 if ((codec = data) == NULL)
624 return -ENODEV;
625
626 id1 = codec->codec_read(codec, AC97_VENDOR_ID1);
627 id2 = codec->codec_read(codec, AC97_VENDOR_ID2);
628 len += sprintf (page+len, "Vendor name : %s\n", codec->name);
629 len += sprintf (page+len, "Vendor id : %04X %04X\n", id1, id2);
630
631 extid = codec->codec_read(codec, AC97_EXTENDED_ID);
632 extid &= ~((1<<2)|(1<<4)|(1<<5)|(1<<10)|(1<<11)|(1<<12)|(1<<13));
633 len += sprintf (page+len, "AC97 Version : %s\n",
634 extid ? "2.0 or later" : "1.0");
635 if (extid) is_ac97_20 = 1;
636
637 cap = codec->codec_read(codec, AC97_RESET);
638 len += sprintf (page+len, "Capabilities :%s%s%s%s%s%s\n",
639 cap & 0x0001 ? " -dedicated MIC PCM IN channel-" : "",
640 cap & 0x0002 ? " -reserved1-" : "",
641 cap & 0x0004 ? " -bass & treble-" : "",
642 cap & 0x0008 ? " -simulated stereo-" : "",
643 cap & 0x0010 ? " -headphone out-" : "",
644 cap & 0x0020 ? " -loudness-" : "");
645 val = cap & 0x00c0;
646 len += sprintf (page+len, "DAC resolutions :%s%s%s\n",
647 " -16-bit-",
648 val & 0x0040 ? " -18-bit-" : "",
649 val & 0x0080 ? " -20-bit-" : "");
650 val = cap & 0x0300;
651 len += sprintf (page+len, "ADC resolutions :%s%s%s\n",
652 " -16-bit-",
653 val & 0x0100 ? " -18-bit-" : "",
654 val & 0x0200 ? " -20-bit-" : "");
655 len += sprintf (page+len, "3D enhancement : %s\n",
656 ac97_stereo_enhancements[(cap >> 10) & 0x1f]);
657
658 val = codec->codec_read(codec, AC97_GENERAL_PURPOSE);
659 len += sprintf (page+len, "POP path : %s 3D\n"
660 "Sim. stereo : %s\n"
661 "3D enhancement : %s\n"
662 "Loudness : %s\n"
663 "Mono output : %s\n"
664 "MIC select : %s\n"
665 "ADC/DAC loopback : %s\n",
666 val & 0x8000 ? "post" : "pre",
667 val & 0x4000 ? "on" : "off",
668 val & 0x2000 ? "on" : "off",
669 val & 0x1000 ? "on" : "off",
670 val & 0x0200 ? "MIC" : "MIX",
671 val & 0x0100 ? "MIC2" : "MIC1",
672 val & 0x0080 ? "on" : "off");
673
674 extid = codec->codec_read(codec, AC97_EXTENDED_ID);
675 cap = extid;
676 len += sprintf (page+len, "Ext Capabilities :%s%s%s%s%s%s%s\n",
677 cap & 0x0001 ? " -var rate PCM audio-" : "",
678 cap & 0x0002 ? " -2x PCM audio out-" : "",
679 cap & 0x0008 ? " -var rate MIC in-" : "",
680 cap & 0x0040 ? " -PCM center DAC-" : "",
681 cap & 0x0080 ? " -PCM surround DAC-" : "",
682 cap & 0x0100 ? " -PCM LFE DAC-" : "",
683 cap & 0x0200 ? " -slot/DAC mappings-" : "");
684 if (is_ac97_20) {
685 len += sprintf (page+len, "Front DAC rate : %d\n",
686 codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE));
687 }
688
689 return len;
690}
691
692/**
693 * codec_id - Turn id1/id2 into a PnP string
694 * @id1: Vendor ID1
695 * @id2: Vendor ID2
696 * @buf: CODEC_ID_BUFSZ byte buffer
697 *
698 * Fills buf with a zero terminated PnP ident string for the id1/id2
699 * pair. For convenience the return is the passed in buffer pointer.
700 */
701
702static char *codec_id(u16 id1, u16 id2, char *buf)
703{
704 if(id1&0x8080) {
705 snprintf(buf, CODEC_ID_BUFSZ, "0x%04x:0x%04x", id1, id2);
706 } else {
707 buf[0] = (id1 >> 8);
708 buf[1] = (id1 & 0xFF);
709 buf[2] = (id2 >> 8);
710 snprintf(buf+3, CODEC_ID_BUFSZ - 3, "%d", id2&0xFF);
711 }
712 return buf;
713}
714
715/**
716 * ac97_check_modem - Check if the Codec is a modem
717 * @codec: codec to check
718 *
719 * Return true if the device is an AC97 1.0 or AC97 2.0 modem
720 */
721
722static int ac97_check_modem(struct ac97_codec *codec)
723{
724 /* Check for an AC97 1.0 soft modem (ID1) */
725 if(codec->codec_read(codec, AC97_RESET) & 2)
726 return 1;
727 /* Check for an AC97 2.x soft modem */
728 codec->codec_write(codec, AC97_EXTENDED_MODEM_ID, 0L);
729 if(codec->codec_read(codec, AC97_EXTENDED_MODEM_ID) & 1)
730 return 1;
731 return 0;
732}
733
734
735/**
736 * ac97_alloc_codec - Allocate an AC97 codec
737 *
738 * Returns a new AC97 codec structure. AC97 codecs may become
739 * refcounted soon so this interface is needed. Returns with
740 * one reference taken.
741 */
742
743struct ac97_codec *ac97_alloc_codec(void)
744{
745 struct ac97_codec *codec = kmalloc(sizeof(struct ac97_codec), GFP_KERNEL);
746 if(!codec)
747 return NULL;
748
749 memset(codec, 0, sizeof(*codec));
750 spin_lock_init(&codec->lock);
751 INIT_LIST_HEAD(&codec->list);
752 return codec;
753}
754
755EXPORT_SYMBOL(ac97_alloc_codec);
756
757/**
758 * ac97_release_codec - Release an AC97 codec
759 * @codec: codec to release
760 *
761 * Release an allocated AC97 codec. This will be refcounted in
762 * time but for the moment is trivial. Calls the unregister
763 * handler if the codec is now defunct.
764 */
765
766void ac97_release_codec(struct ac97_codec *codec)
767{
768 /* Remove from the list first, we don't want to be
769 "rediscovered" */
770 down(&codec_sem);
771 list_del(&codec->list);
772 up(&codec_sem);
773 /*
774 * The driver needs to deal with internal
775 * locking to avoid accidents here.
776 */
777 if(codec->driver)
778 codec->driver->remove(codec, codec->driver);
779 kfree(codec);
780}
781
782EXPORT_SYMBOL(ac97_release_codec);
783
784/**
785 * ac97_probe_codec - Initialize and setup AC97-compatible codec
786 * @codec: (in/out) Kernel info for a single AC97 codec
787 *
788 * Reset the AC97 codec, then initialize the mixer and
789 * the rest of the @codec structure.
790 *
791 * The codec_read and codec_write fields of @codec are
792 * required to be setup and working when this function
793 * is called. All other fields are set by this function.
794 *
795 * codec_wait field of @codec can optionally be provided
796 * when calling this function. If codec_wait is not %NULL,
797 * this function will call codec_wait any time it is
798 * necessary to wait for the audio chip to reach the
799 * codec-ready state. If codec_wait is %NULL, then
800 * the default behavior is to call schedule_timeout.
801 * Currently codec_wait is used to wait for AC97 codec
802 * reset to complete.
803 *
804 * Some codecs will power down when a register reset is
805 * performed. We now check for such codecs.
806 *
807 * Returns 1 (true) on success, or 0 (false) on failure.
808 */
809
810int ac97_probe_codec(struct ac97_codec *codec)
811{
812 u16 id1, id2;
813 u16 audio;
814 int i;
815 char cidbuf[CODEC_ID_BUFSZ];
816 u16 f;
817 struct list_head *l;
818 struct ac97_driver *d;
819
820 /* wait for codec-ready state */
821 if (codec->codec_wait)
822 codec->codec_wait(codec);
823 else
824 udelay(10);
825
826 /* will the codec power down if register reset ? */
827 id1 = codec->codec_read(codec, AC97_VENDOR_ID1);
828 id2 = codec->codec_read(codec, AC97_VENDOR_ID2);
829 codec->name = NULL;
830 codec->codec_ops = &null_ops;
831 for (i = 0; i < ARRAY_SIZE(ac97_codec_ids); i++) {
832 if (ac97_codec_ids[i].id == ((id1 << 16) | id2)) {
833 codec->type = ac97_codec_ids[i].id;
834 codec->name = ac97_codec_ids[i].name;
835 codec->codec_ops = ac97_codec_ids[i].ops;
836 codec->flags = ac97_codec_ids[i].flags;
837 break;
838 }
839 }
840
841 codec->model = (id1 << 16) | id2;
842 if ((codec->flags & AC97_DEFAULT_POWER_OFF) == 0) {
843 /* reset codec and wait for the ready bit before we continue */
844 codec->codec_write(codec, AC97_RESET, 0L);
845 if (codec->codec_wait)
846 codec->codec_wait(codec);
847 else
848 udelay(10);
849 }
850
851 /* probing AC97 codec, AC97 2.0 says that bit 15 of register 0x00 (reset) should
852 * be read zero.
853 *
854 * FIXME: is the following comment outdated? -jgarzik
855 * Probing of AC97 in this way is not reliable, it is not even SAFE !!
856 */
857 if ((audio = codec->codec_read(codec, AC97_RESET)) & 0x8000) {
858 printk(KERN_ERR "ac97_codec: %s ac97 codec not present\n",
859 (codec->id & 0x2) ? (codec->id&1 ? "4th" : "Tertiary")
860 : (codec->id&1 ? "Secondary": "Primary"));
861 return 0;
862 }
863
864 /* probe for Modem Codec */
865 codec->modem = ac97_check_modem(codec);
866
867 /* enable SPDIF */
868 f = codec->codec_read(codec, AC97_EXTENDED_STATUS);
869 if((codec->codec_ops == &null_ops) && (f & 4))
870 codec->codec_ops = &default_digital_ops;
871
872 /* A device which thinks its a modem but isnt */
873 if(codec->flags & AC97_DELUDED_MODEM)
874 codec->modem = 0;
875
876 if (codec->name == NULL)
877 codec->name = "Unknown";
878 printk(KERN_INFO "ac97_codec: AC97 %s codec, id: %s (%s)\n",
879 codec->modem ? "Modem" : (audio ? "Audio" : ""),
880 codec_id(id1, id2, cidbuf), codec->name);
881
882 if(!ac97_init_mixer(codec))
883 return 0;
884
885 /*
886 * Attach last so the caller can override the mixer
887 * callbacks.
888 */
889
890 down(&codec_sem);
891 list_add(&codec->list, &codecs);
892
893 list_for_each(l, &codec_drivers) {
894 d = list_entry(l, struct ac97_driver, list);
895 if ((codec->model ^ d->codec_id) & d->codec_mask)
896 continue;
897 if(d->probe(codec, d) == 0)
898 {
899 codec->driver = d;
900 break;
901 }
902 }
903
904 up(&codec_sem);
905 return 1;
906}
907
908static int ac97_init_mixer(struct ac97_codec *codec)
909{
910 u16 cap;
911 int i;
912
913 cap = codec->codec_read(codec, AC97_RESET);
914
915 /* mixer masks */
916 codec->supported_mixers = AC97_SUPPORTED_MASK;
917 codec->stereo_mixers = AC97_STEREO_MASK;
918 codec->record_sources = AC97_RECORD_MASK;
919 if (!(cap & 0x04))
920 codec->supported_mixers &= ~(SOUND_MASK_BASS|SOUND_MASK_TREBLE);
921 if (!(cap & 0x10))
922 codec->supported_mixers &= ~SOUND_MASK_ALTPCM;
923
924
925 /* detect bit resolution */
926 codec->codec_write(codec, AC97_MASTER_VOL_STEREO, 0x2020);
927 if(codec->codec_read(codec, AC97_MASTER_VOL_STEREO) == 0x2020)
928 codec->bit_resolution = 6;
929 else
930 codec->bit_resolution = 5;
931
932 /* generic OSS to AC97 wrapper */
933 codec->read_mixer = ac97_read_mixer;
934 codec->write_mixer = ac97_write_mixer;
935 codec->recmask_io = ac97_recmask_io;
936 codec->mixer_ioctl = ac97_mixer_ioctl;
937
938 /* initialize mixer channel volumes */
939 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
940 struct mixer_defaults *md = &mixer_defaults[i];
941 if (md->mixer == -1)
942 break;
943 if (!supported_mixer(codec, md->mixer))
944 continue;
945 ac97_set_mixer(codec, md->mixer, md->value);
946 }
947
948 /* codec specific initialization for 4-6 channel output or secondary codec stuff */
949 if (codec->codec_ops->init != NULL) {
950 codec->codec_ops->init(codec);
951 }
952
953 /*
954 * Volume is MUTE only on this device. We have to initialise
955 * it but its useless beyond that.
956 */
957 if(codec->flags & AC97_NO_PCM_VOLUME)
958 {
959 codec->supported_mixers &= ~SOUND_MASK_PCM;
960 printk(KERN_WARNING "AC97 codec does not have proper volume support.\n");
961 }
962 return 1;
963}
964
965#define AC97_SIGMATEL_ANALOG 0x6c /* Analog Special */
966#define AC97_SIGMATEL_DAC2INVERT 0x6e
967#define AC97_SIGMATEL_BIAS1 0x70
968#define AC97_SIGMATEL_BIAS2 0x72
969#define AC97_SIGMATEL_MULTICHN 0x74 /* Multi-Channel programming */
970#define AC97_SIGMATEL_CIC1 0x76
971#define AC97_SIGMATEL_CIC2 0x78
972
973
974static int sigmatel_9708_init(struct ac97_codec * codec)
975{
976 u16 codec72, codec6c;
977
978 codec72 = codec->codec_read(codec, AC97_SIGMATEL_BIAS2) & 0x8000;
979 codec6c = codec->codec_read(codec, AC97_SIGMATEL_ANALOG);
980
981 if ((codec72==0) && (codec6c==0)) {
982 codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
983 codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x1000);
984 codec->codec_write(codec, AC97_SIGMATEL_BIAS1, 0xabba);
985 codec->codec_write(codec, AC97_SIGMATEL_BIAS2, 0x0007);
986 } else if ((codec72==0x8000) && (codec6c==0)) {
987 codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
988 codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x1001);
989 codec->codec_write(codec, AC97_SIGMATEL_DAC2INVERT, 0x0008);
990 } else if ((codec72==0x8000) && (codec6c==0x0080)) {
991 /* nothing */
992 }
993 codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x0000);
994 return 0;
995}
996
997
998static int sigmatel_9721_init(struct ac97_codec * codec)
999{
1000 /* Only set up secondary codec */
1001 if (codec->id == 0)
1002 return 0;
1003
1004 codec->codec_write(codec, AC97_SURROUND_MASTER, 0L);
1005
1006 /* initialize SigmaTel STAC9721/23 as secondary codec, decoding AC link
1007 sloc 3,4 = 0x01, slot 7,8 = 0x00, */
1008 codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x00);
1009
1010 /* we don't have the crystal when we are on an AMR card, so use
1011 BIT_CLK as our clock source. Write the magic word ABBA and read
1012 back to enable register 0x78 */
1013 codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
1014 codec->codec_read(codec, AC97_SIGMATEL_CIC1);
1015
1016 /* sync all the clocks*/
1017 codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x3802);
1018
1019 return 0;
1020}
1021
1022
1023static int sigmatel_9744_init(struct ac97_codec * codec)
1024{
1025 // patch for SigmaTel
1026 codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
1027 codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x0000); // is this correct? --jk
1028 codec->codec_write(codec, AC97_SIGMATEL_BIAS1, 0xabba);
1029 codec->codec_write(codec, AC97_SIGMATEL_BIAS2, 0x0002);
1030 codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x0000);
1031 return 0;
1032}
1033
1034static int cmedia_init(struct ac97_codec *codec)
1035{
1036 /* Initialise the CMedia 9739 */
1037 /*
1038 We could set various options here
1039 Register 0x20 bit 0x100 sets mic as center bass
1040 Also do multi_channel_ctrl &=~0x3000 |=0x1000
1041
1042 For now we set up the GPIO and PC beep
1043 */
1044
1045 u16 v;
1046
1047 /* MIC */
1048 codec->codec_write(codec, 0x64, 0x3000);
1049 v = codec->codec_read(codec, 0x64);
1050 v &= ~0x8000;
1051 codec->codec_write(codec, 0x64, v);
1052 codec->codec_write(codec, 0x70, 0x0100);
1053 codec->codec_write(codec, 0x72, 0x0020);
1054 return 0;
1055}
1056
1057#define AC97_WM97XX_FMIXER_VOL 0x72
1058#define AC97_WM97XX_RMIXER_VOL 0x74
1059#define AC97_WM97XX_TEST 0x5a
1060#define AC97_WM9704_RPCM_VOL 0x70
1061#define AC97_WM9711_OUT3VOL 0x16
1062
1063static int wolfson_init03(struct ac97_codec * codec)
1064{
1065 /* this is known to work for the ViewSonic ViewPad 1000 */
1066 codec->codec_write(codec, AC97_WM97XX_FMIXER_VOL, 0x0808);
1067 codec->codec_write(codec, AC97_GENERAL_PURPOSE, 0x8000);
1068 return 0;
1069}
1070
1071static int wolfson_init04(struct ac97_codec * codec)
1072{
1073 codec->codec_write(codec, AC97_WM97XX_FMIXER_VOL, 0x0808);
1074 codec->codec_write(codec, AC97_WM97XX_RMIXER_VOL, 0x0808);
1075
1076 // patch for DVD noise
1077 codec->codec_write(codec, AC97_WM97XX_TEST, 0x0200);
1078
1079 // init vol as PCM vol
1080 codec->codec_write(codec, AC97_WM9704_RPCM_VOL,
1081 codec->codec_read(codec, AC97_PCMOUT_VOL));
1082
1083 /* set rear surround volume */
1084 codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000);
1085 return 0;
1086}
1087
1088/* WM9705, WM9710 */
1089static int wolfson_init05(struct ac97_codec * codec)
1090{
1091 /* set front mixer volume */
1092 codec->codec_write(codec, AC97_WM97XX_FMIXER_VOL, 0x0808);
1093 return 0;
1094}
1095
1096/* WM9711, WM9712 */
1097static int wolfson_init11(struct ac97_codec * codec)
1098{
1099 /* stop pop's during suspend/resume */
1100 codec->codec_write(codec, AC97_WM97XX_TEST,
1101 codec->codec_read(codec, AC97_WM97XX_TEST) & 0xffbf);
1102
1103 /* set out3 volume */
1104 codec->codec_write(codec, AC97_WM9711_OUT3VOL, 0x0808);
1105 return 0;
1106}
1107
1108/* WM9713 */
1109static int wolfson_init13(struct ac97_codec * codec)
1110{
1111 codec->codec_write(codec, AC97_RECORD_GAIN, 0x00a0);
1112 codec->codec_write(codec, AC97_POWER_CONTROL, 0x0000);
1113 codec->codec_write(codec, AC97_EXTENDED_MODEM_ID, 0xDA00);
1114 codec->codec_write(codec, AC97_EXTEND_MODEM_STAT, 0x3810);
1115 codec->codec_write(codec, AC97_PHONE_VOL, 0x0808);
1116 codec->codec_write(codec, AC97_PCBEEP_VOL, 0x0808);
1117
1118 return 0;
1119}
1120
1121static int tritech_init(struct ac97_codec * codec)
1122{
1123 codec->codec_write(codec, 0x26, 0x0300);
1124 codec->codec_write(codec, 0x26, 0x0000);
1125 codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000);
1126 codec->codec_write(codec, AC97_RESERVED_3A, 0x0000);
1127 return 0;
1128}
1129
1130
1131/* copied from drivers/sound/maestro.c */
1132static int tritech_maestro_init(struct ac97_codec * codec)
1133{
1134 /* no idea what this does */
1135 codec->codec_write(codec, 0x2A, 0x0001);
1136 codec->codec_write(codec, 0x2C, 0x0000);
1137 codec->codec_write(codec, 0x2C, 0XFFFF);
1138 return 0;
1139}
1140
1141
1142
1143/*
1144 * Presario700 workaround
1145 * for Jack Sense/SPDIF Register mis-setting causing
1146 * no audible output
1147 * by Santiago Nullo 04/05/2002
1148 */
1149
1150#define AC97_AD1886_JACK_SENSE 0x72
1151
1152static int ad1886_init(struct ac97_codec * codec)
1153{
1154 /* from AD1886 Specs */
1155 codec->codec_write(codec, AC97_AD1886_JACK_SENSE, 0x0010);
1156 return 0;
1157}
1158
1159
1160
1161
1162/*
1163 * This is basically standard AC97. It should work as a default for
1164 * almost all modern codecs. Note that some cards wire EAPD *backwards*
1165 * That side of it is up to the card driver not us to cope with.
1166 *
1167 */
1168
1169static int eapd_control(struct ac97_codec * codec, int on)
1170{
1171 if(on)
1172 codec->codec_write(codec, AC97_POWER_CONTROL,
1173 codec->codec_read(codec, AC97_POWER_CONTROL)|0x8000);
1174 else
1175 codec->codec_write(codec, AC97_POWER_CONTROL,
1176 codec->codec_read(codec, AC97_POWER_CONTROL)&~0x8000);
1177 return 0;
1178}
1179
1180static int generic_digital_control(struct ac97_codec *codec, int slots, int rate, int mode)
1181{
1182 u16 reg;
1183
1184 reg = codec->codec_read(codec, AC97_SPDIF_CONTROL);
1185
1186 switch(rate)
1187 {
1188 /* Off by default */
1189 default:
1190 case 0:
1191 reg = codec->codec_read(codec, AC97_EXTENDED_STATUS);
1192 codec->codec_write(codec, AC97_EXTENDED_STATUS, (reg & ~AC97_EA_SPDIF));
1193 if(rate == 0)
1194 return 0;
1195 return -EINVAL;
1196 case 1:
1197 reg = (reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_48K;
1198 break;
1199 case 2:
1200 reg = (reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_44K;
1201 break;
1202 case 3:
1203 reg = (reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_32K;
1204 break;
1205 }
1206
1207 reg &= ~AC97_SC_CC_MASK;
1208 reg |= (mode & AUDIO_CCMASK) << 6;
1209
1210 if(mode & AUDIO_DIGITAL)
1211 reg |= 2;
1212 if(mode & AUDIO_PRO)
1213 reg |= 1;
1214 if(mode & AUDIO_DRS)
1215 reg |= 0x4000;
1216
1217 codec->codec_write(codec, AC97_SPDIF_CONTROL, reg);
1218
1219 reg = codec->codec_read(codec, AC97_EXTENDED_STATUS);
1220 reg &= (AC97_EA_SLOT_MASK);
1221 reg |= AC97_EA_VRA | AC97_EA_SPDIF | slots;
1222 codec->codec_write(codec, AC97_EXTENDED_STATUS, reg);
1223
1224 reg = codec->codec_read(codec, AC97_EXTENDED_STATUS);
1225 if(!(reg & 0x0400))
1226 {
1227 codec->codec_write(codec, AC97_EXTENDED_STATUS, reg & ~ AC97_EA_SPDIF);
1228 return -EINVAL;
1229 }
1230 return 0;
1231}
1232
1233/*
1234 * Crystal digital audio control (CS4299)
1235 */
1236
1237static int crystal_digital_control(struct ac97_codec *codec, int slots, int rate, int mode)
1238{
1239 u16 cv;
1240
1241 if(mode & AUDIO_DIGITAL)
1242 return -EINVAL;
1243
1244 switch(rate)
1245 {
1246 case 0: cv = 0x0; break; /* SPEN off */
1247 case 48000: cv = 0x8004; break; /* 48KHz digital */
1248 case 44100: cv = 0x8104; break; /* 44.1KHz digital */
1249 case 32768: /* 32Khz */
1250 default:
1251 return -EINVAL;
1252 }
1253 codec->codec_write(codec, 0x68, cv);
1254 return 0;
1255}
1256
1257/*
1258 * CMedia digital audio control
1259 * Needs more work.
1260 */
1261
1262static int cmedia_digital_control(struct ac97_codec *codec, int slots, int rate, int mode)
1263{
1264 u16 cv;
1265
1266 if(mode & AUDIO_DIGITAL)
1267 return -EINVAL;
1268
1269 switch(rate)
1270 {
1271 case 0: cv = 0x0001; break; /* SPEN off */
1272 case 48000: cv = 0x0009; break; /* 48KHz digital */
1273 default:
1274 return -EINVAL;
1275 }
1276 codec->codec_write(codec, 0x2A, 0x05c4);
1277 codec->codec_write(codec, 0x6C, cv);
1278
1279 /* Switch on mix to surround */
1280 cv = codec->codec_read(codec, 0x64);
1281 cv &= ~0x0200;
1282 if(mode)
1283 cv |= 0x0200;
1284 codec->codec_write(codec, 0x64, cv);
1285 return 0;
1286}
1287
1288
1289/* copied from drivers/sound/maestro.c */
1290#if 0 /* there has been 1 person on the planet with a pt101 that we
1291 know of. If they care, they can put this back in :) */
1292static int pt101_init(struct ac97_codec * codec)
1293{
1294 printk(KERN_INFO "ac97_codec: PT101 Codec detected, initializing but _not_ installing mixer device.\n");
1295 /* who knows.. */
1296 codec->codec_write(codec, 0x2A, 0x0001);
1297 codec->codec_write(codec, 0x2C, 0x0000);
1298 codec->codec_write(codec, 0x2C, 0xFFFF);
1299 codec->codec_write(codec, 0x10, 0x9F1F);
1300 codec->codec_write(codec, 0x12, 0x0808);
1301 codec->codec_write(codec, 0x14, 0x9F1F);
1302 codec->codec_write(codec, 0x16, 0x9F1F);
1303 codec->codec_write(codec, 0x18, 0x0404);
1304 codec->codec_write(codec, 0x1A, 0x0000);
1305 codec->codec_write(codec, 0x1C, 0x0000);
1306 codec->codec_write(codec, 0x02, 0x0404);
1307 codec->codec_write(codec, 0x04, 0x0808);
1308 codec->codec_write(codec, 0x0C, 0x801F);
1309 codec->codec_write(codec, 0x0E, 0x801F);
1310 return 0;
1311}
1312#endif
1313
1314
1315EXPORT_SYMBOL(ac97_read_proc);
1316EXPORT_SYMBOL(ac97_probe_codec);
1317
1318/*
1319 * AC97 library support routines
1320 */
1321
1322/**
1323 * ac97_set_dac_rate - set codec rate adaption
1324 * @codec: ac97 code
1325 * @rate: rate in hertz
1326 *
1327 * Set the DAC rate. Assumes the codec supports VRA. The caller is
1328 * expected to have checked this little detail.
1329 */
1330
1331unsigned int ac97_set_dac_rate(struct ac97_codec *codec, unsigned int rate)
1332{
1333 unsigned int new_rate = rate;
1334 u32 dacp;
1335 u32 mast_vol, phone_vol, mono_vol, pcm_vol;
1336 u32 mute_vol = 0x8000; /* The mute volume? */
1337
1338 if(rate != codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE))
1339 {
1340 /* Mute several registers */
1341 mast_vol = codec->codec_read(codec, AC97_MASTER_VOL_STEREO);
1342 mono_vol = codec->codec_read(codec, AC97_MASTER_VOL_MONO);
1343 phone_vol = codec->codec_read(codec, AC97_HEADPHONE_VOL);
1344 pcm_vol = codec->codec_read(codec, AC97_PCMOUT_VOL);
1345 codec->codec_write(codec, AC97_MASTER_VOL_STEREO, mute_vol);
1346 codec->codec_write(codec, AC97_MASTER_VOL_MONO, mute_vol);
1347 codec->codec_write(codec, AC97_HEADPHONE_VOL, mute_vol);
1348 codec->codec_write(codec, AC97_PCMOUT_VOL, mute_vol);
1349
1350 /* Power down the DAC */
1351 dacp=codec->codec_read(codec, AC97_POWER_CONTROL);
1352 codec->codec_write(codec, AC97_POWER_CONTROL, dacp|0x0200);
1353 /* Load the rate and read the effective rate */
1354 codec->codec_write(codec, AC97_PCM_FRONT_DAC_RATE, rate);
1355 new_rate=codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE);
1356 /* Power it back up */
1357 codec->codec_write(codec, AC97_POWER_CONTROL, dacp);
1358
1359 /* Restore volumes */
1360 codec->codec_write(codec, AC97_MASTER_VOL_STEREO, mast_vol);
1361 codec->codec_write(codec, AC97_MASTER_VOL_MONO, mono_vol);
1362 codec->codec_write(codec, AC97_HEADPHONE_VOL, phone_vol);
1363 codec->codec_write(codec, AC97_PCMOUT_VOL, pcm_vol);
1364 }
1365 return new_rate;
1366}
1367
1368EXPORT_SYMBOL(ac97_set_dac_rate);
1369
1370/**
1371 * ac97_set_adc_rate - set codec rate adaption
1372 * @codec: ac97 code
1373 * @rate: rate in hertz
1374 *
1375 * Set the ADC rate. Assumes the codec supports VRA. The caller is
1376 * expected to have checked this little detail.
1377 */
1378
1379unsigned int ac97_set_adc_rate(struct ac97_codec *codec, unsigned int rate)
1380{
1381 unsigned int new_rate = rate;
1382 u32 dacp;
1383
1384 if(rate != codec->codec_read(codec, AC97_PCM_LR_ADC_RATE))
1385 {
1386 /* Power down the ADC */
1387 dacp=codec->codec_read(codec, AC97_POWER_CONTROL);
1388 codec->codec_write(codec, AC97_POWER_CONTROL, dacp|0x0100);
1389 /* Load the rate and read the effective rate */
1390 codec->codec_write(codec, AC97_PCM_LR_ADC_RATE, rate);
1391 new_rate=codec->codec_read(codec, AC97_PCM_LR_ADC_RATE);
1392 /* Power it back up */
1393 codec->codec_write(codec, AC97_POWER_CONTROL, dacp);
1394 }
1395 return new_rate;
1396}
1397
1398EXPORT_SYMBOL(ac97_set_adc_rate);
1399
1400int ac97_save_state(struct ac97_codec *codec)
1401{
1402 return 0;
1403}
1404
1405EXPORT_SYMBOL(ac97_save_state);
1406
1407int ac97_restore_state(struct ac97_codec *codec)
1408{
1409 int i;
1410 unsigned int left, right, val;
1411
1412 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1413 if (!supported_mixer(codec, i))
1414 continue;
1415
1416 val = codec->mixer_state[i];
1417 right = val >> 8;
1418 left = val & 0xff;
1419 codec->write_mixer(codec, i, left, right);
1420 }
1421 return 0;
1422}
1423
1424EXPORT_SYMBOL(ac97_restore_state);
1425
1426/**
1427 * ac97_register_driver - register a codec helper
1428 * @driver: Driver handler
1429 *
1430 * Register a handler for codecs matching the codec id. The handler
1431 * attach function is called for all present codecs and will be
1432 * called when new codecs are discovered.
1433 */
1434
1435int ac97_register_driver(struct ac97_driver *driver)
1436{
1437 struct list_head *l;
1438 struct ac97_codec *c;
1439
1440 down(&codec_sem);
1441 INIT_LIST_HEAD(&driver->list);
1442 list_add(&driver->list, &codec_drivers);
1443
1444 list_for_each(l, &codecs)
1445 {
1446 c = list_entry(l, struct ac97_codec, list);
1447 if(c->driver != NULL || ((c->model ^ driver->codec_id) & driver->codec_mask))
1448 continue;
1449 if(driver->probe(c, driver))
1450 continue;
1451 c->driver = driver;
1452 }
1453 up(&codec_sem);
1454 return 0;
1455}
1456
1457EXPORT_SYMBOL_GPL(ac97_register_driver);
1458
1459/**
1460 * ac97_unregister_driver - unregister a codec helper
1461 * @driver: Driver handler
1462 *
1463 * Unregister a handler for codecs matching the codec id. The handler
1464 * remove function is called for all matching codecs.
1465 */
1466
1467void ac97_unregister_driver(struct ac97_driver *driver)
1468{
1469 struct list_head *l;
1470 struct ac97_codec *c;
1471
1472 down(&codec_sem);
1473 list_del_init(&driver->list);
1474
1475 list_for_each(l, &codecs)
1476 {
1477 c = list_entry(l, struct ac97_codec, list);
1478 if (c->driver == driver) {
1479 driver->remove(c, driver);
1480 c->driver = NULL;
1481 }
1482 }
1483
1484 up(&codec_sem);
1485}
1486
1487EXPORT_SYMBOL_GPL(ac97_unregister_driver);
1488
1489static int swap_headphone(int remove_master)
1490{
1491 struct list_head *l;
1492 struct ac97_codec *c;
1493
1494 if (remove_master) {
1495 down(&codec_sem);
1496 list_for_each(l, &codecs)
1497 {
1498 c = list_entry(l, struct ac97_codec, list);
1499 if (supported_mixer(c, SOUND_MIXER_PHONEOUT))
1500 c->supported_mixers &= ~SOUND_MASK_PHONEOUT;
1501 }
1502 up(&codec_sem);
1503 } else
1504 ac97_hw[SOUND_MIXER_PHONEOUT].offset = AC97_MASTER_VOL_STEREO;
1505
1506 /* Scale values already match */
1507 ac97_hw[SOUND_MIXER_VOLUME].offset = AC97_MASTER_VOL_MONO;
1508 return 0;
1509}
1510
1511static int apply_quirk(int quirk)
1512{
1513 switch (quirk) {
1514 case AC97_TUNE_NONE:
1515 return 0;
1516 case AC97_TUNE_HP_ONLY:
1517 return swap_headphone(1);
1518 case AC97_TUNE_SWAP_HP:
1519 return swap_headphone(0);
1520 case AC97_TUNE_SWAP_SURROUND:
1521 return -ENOSYS; /* not yet implemented */
1522 case AC97_TUNE_AD_SHARING:
1523 return -ENOSYS; /* not yet implemented */
1524 case AC97_TUNE_ALC_JACK:
1525 return -ENOSYS; /* not yet implemented */
1526 }
1527 return -EINVAL;
1528}
1529
1530/**
1531 * ac97_tune_hardware - tune up the hardware
1532 * @pdev: pci_dev pointer
1533 * @quirk: quirk list
1534 * @override: explicit quirk value (overrides if not AC97_TUNE_DEFAULT)
1535 *
1536 * Do some workaround for each pci device, such as renaming of the
1537 * headphone (true line-out) control as "Master".
1538 * The quirk-list must be terminated with a zero-filled entry.
1539 *
1540 * Returns zero if successful, or a negative error code on failure.
1541 */
1542
1543int ac97_tune_hardware(struct pci_dev *pdev, struct ac97_quirk *quirk, int override)
1544{
1545 int result;
1546
1547 if (!quirk)
1548 return -EINVAL;
1549
1550 if (override != AC97_TUNE_DEFAULT) {
1551 result = apply_quirk(override);
1552 if (result < 0)
1553 printk(KERN_ERR "applying quirk type %d failed (%d)\n", override, result);
1554 return result;
1555 }
1556
1557 for (; quirk->vendor; quirk++) {
1558 if (quirk->vendor != pdev->subsystem_vendor)
1559 continue;
1560 if ((! quirk->mask && quirk->device == pdev->subsystem_device) ||
1561 quirk->device == (quirk->mask & pdev->subsystem_device)) {
1562#ifdef DEBUG
1563 printk("ac97 quirk for %s (%04x:%04x)\n", quirk->name, ac97->subsystem_vendor, pdev->subsystem_device);
1564#endif
1565 result = apply_quirk(quirk->type);
1566 if (result < 0)
1567 printk(KERN_ERR "applying quirk type %d for %s failed (%d)\n", quirk->type, quirk->name, result);
1568 return result;
1569 }
1570 }
1571 return 0;
1572}
1573
1574EXPORT_SYMBOL_GPL(ac97_tune_hardware);
1575
1576MODULE_LICENSE("GPL");
diff --git a/sound/oss/ac97_plugin_ad1980.c b/sound/oss/ac97_plugin_ad1980.c
new file mode 100644
index 000000000000..24a9acd28160
--- /dev/null
+++ b/sound/oss/ac97_plugin_ad1980.c
@@ -0,0 +1,126 @@
1/*
2 ac97_plugin_ad1980.c Copyright (C) 2003 Red Hat, Inc. All rights reserved.
3
4 The contents of this file are subject to the Open Software License version 1.1
5 that can be found at http://www.opensource.org/licenses/osl-1.1.txt and is
6 included herein by reference.
7
8 Alternatively, the contents of this file may be used under the
9 terms of the GNU General Public License version 2 (the "GPL") as
10 distributed in the kernel source COPYING file, in which
11 case the provisions of the GPL are applicable instead of the
12 above. If you wish to allow the use of your version of this file
13 only under the terms of the GPL and not to allow others to use
14 your version of this file under the OSL, indicate your decision
15 by deleting the provisions above and replace them with the notice
16 and other provisions required by the GPL. If you do not delete
17 the provisions above, a recipient may use your version of this
18 file under either the OSL or the GPL.
19
20 Authors: Alan Cox <alan@redhat.com>
21
22 This is an example codec plugin. This one switches the connections
23 around to match the setups some vendors use with audio switched to
24 non standard front connectors not the normal rear ones
25
26 This code primarily exists to demonstrate how to use the codec
27 interface
28
29*/
30
31#include <linux/config.h>
32#include <linux/module.h>
33#include <linux/init.h>
34#include <linux/kernel.h>
35#include <linux/ac97_codec.h>
36
37/**
38 * ad1980_remove - codec remove callback
39 * @codec: The codec that is being removed
40 *
41 * This callback occurs when an AC97 codec is being removed. A
42 * codec remove call will not occur for a codec during that codec
43 * probe callback.
44 *
45 * Most drivers will need to lock their remove versus their
46 * use of the codec after the probe function.
47 */
48
49static void __devexit ad1980_remove(struct ac97_codec *codec, struct ac97_driver *driver)
50{
51 /* Nothing to do in the simple example */
52}
53
54
55/**
56 * ad1980_probe - codec found callback
57 * @codec: ac97 codec matching the idents
58 * @driver: ac97_driver it matched
59 *
60 * This entry point is called when a codec is found which matches
61 * the driver. At the point it is called the codec is basically
62 * operational, mixer operations have been initialised and can
63 * be overriden. Called in process context. The field driver_private
64 * is available for the driver to use to store stuff.
65 *
66 * The caller can claim the device by returning zero, or return
67 * a negative error code.
68 */
69
70static int ad1980_probe(struct ac97_codec *codec, struct ac97_driver *driver)
71{
72 u16 control;
73
74#define AC97_AD_MISC 0x76
75
76 /* Switch the inputs/outputs over (from Dell code) */
77 control = codec->codec_read(codec, AC97_AD_MISC);
78 codec->codec_write(codec, AC97_AD_MISC, control | 0x4420);
79
80 /* We could refuse the device since we dont need to hang around,
81 but we will claim it */
82 return 0;
83}
84
85
86static struct ac97_driver ad1980_driver = {
87 .codec_id = 0x41445370,
88 .codec_mask = 0xFFFFFFFF,
89 .name = "AD1980 example",
90 .probe = ad1980_probe,
91 .remove = __devexit_p(ad1980_remove),
92};
93
94/**
95 * ad1980_exit - module exit path
96 *
97 * Our module is being unloaded. At this point unregister_driver
98 * will call back our remove handler for any existing codecs. You
99 * may not unregister_driver from interrupt context or from a
100 * probe/remove callback.
101 */
102
103static void ad1980_exit(void)
104{
105 ac97_unregister_driver(&ad1980_driver);
106}
107
108/**
109 * ad1980_init - set up ad1980 handlers
110 *
111 * After we call the register function it will call our probe
112 * function for each existing matching device before returning to us.
113 * Any devices appearing afterwards whose id's match the codec_id
114 * will also cause the probe function to be called.
115 * You may not register_driver from interrupt context or from a
116 * probe/remove callback.
117 */
118
119static int ad1980_init(void)
120{
121 return ac97_register_driver(&ad1980_driver);
122}
123
124module_init(ad1980_init);
125module_exit(ad1980_exit);
126MODULE_LICENSE("GPL");
diff --git a/sound/oss/aci.c b/sound/oss/aci.c
new file mode 100644
index 000000000000..3928c2802cc4
--- /dev/null
+++ b/sound/oss/aci.c
@@ -0,0 +1,711 @@
1/*
2 * Audio Command Interface (ACI) driver (sound/aci.c)
3 *
4 * ACI is a protocol used to communicate with the microcontroller on
5 * some sound cards produced by miro, e.g. the miroSOUND PCM12 and
6 * PCM20. The ACI has been developed for miro by Norberto Pellicci
7 * <pellicci@home.com>. Special thanks to both him and miro for
8 * providing the ACI specification.
9 *
10 * The main function of the ACI is to control the mixer and to get a
11 * product identification. On the PCM20, ACI also controls the radio
12 * tuner on this card, this is supported in the Video for Linux
13 * miropcm20 driver.
14 * -
15 * This is a fullfeatured implementation. Unsupported features
16 * are bugs... (:
17 *
18 * It is not longer necessary to load the mad16 module first. The
19 * user is currently responsible to set the mad16 mixer correctly.
20 *
21 * To toggle the solo mode for full duplex operation just use the OSS
22 * record switch for the pcm ('wave') controller. Robert
23 * -
24 *
25 * Revision history:
26 *
27 * 1995-11-10 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
28 * First version written.
29 * 1995-12-31 Markus Kuhn
30 * Second revision, general code cleanup.
31 * 1996-05-16 Hannu Savolainen
32 * Integrated with other parts of the driver.
33 * 1996-05-28 Markus Kuhn
34 * Initialize CS4231A mixer, make ACI first mixer,
35 * use new private mixer API for solo mode.
36 * 1998-08-18 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl>
37 * Small modification to export ACI functions and
38 * complete modularisation.
39 * 2000-06-20 Robert Siemer <Robert.Siemer@gmx.de>
40 * Don't initialize the CS4231A mixer anymore, so the code is
41 * working again, and other small changes to fit in todays
42 * kernels.
43 * 2000-08-26 Robert Siemer
44 * Clean up and rewrite for 2.4.x. Maybe it's SMP safe now... (:
45 * ioctl bugfix, and integration of solo-mode into OSS-API,
46 * added (OSS-limited) equalizer support, return value bugfix,
47 * changed param aci_reset to reset, new params: ide, wss.
48 * 2001-04-20 Robert Siemer
49 * even more cleanups...
50 * 2001-10-08 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
51 * Get rid of check_region, .bss optimizations, use set_current_state
52 */
53
54#include <linux/kernel.h>
55#include <linux/init.h>
56#include <linux/module.h>
57#include <linux/proc_fs.h>
58#include <linux/slab.h>
59#include <asm/semaphore.h>
60#include <asm/io.h>
61#include <asm/uaccess.h>
62#include "sound_config.h"
63
64int aci_port; /* as determined by bit 4 in the OPTi 929 MC4 register */
65static int aci_idcode[2]; /* manufacturer and product ID */
66int aci_version; /* ACI firmware version */
67
68EXPORT_SYMBOL(aci_port);
69EXPORT_SYMBOL(aci_version);
70
71#include "aci.h"
72
73
74static int aci_solo; /* status bit of the card that can't be *
75 * checked with ACI versions prior to 0xb0 */
76static int aci_amp; /* status bit for power-amp/line-out level
77 but I have no docs about what is what... */
78static int aci_micpreamp=3; /* microphone preamp-level that can't be *
79 * checked with ACI versions prior to 0xb0 */
80
81static int mixer_device;
82static struct semaphore aci_sem;
83
84#ifdef MODULE
85static int reset;
86module_param(reset, bool, 0);
87MODULE_PARM_DESC(reset,"When set to 1, reset aci mixer.");
88#else
89static int reset = 1;
90#endif
91
92static int ide=-1;
93module_param(ide, int, 0);
94MODULE_PARM_DESC(ide,"1 enable, 0 disable ide-port - untested"
95 " default: do nothing");
96static int wss=-1;
97module_param(wss, int, 0);
98MODULE_PARM_DESC(wss,"change between ACI/WSS-mixer; use 0 and 1 - untested"
99 " default: do nothing; for PCM1-pro only");
100
101#ifdef DEBUG
102static void print_bits(unsigned char c)
103{
104 int j;
105 printk(KERN_DEBUG "aci: ");
106
107 for (j=7; j>=0; j--) {
108 printk("%d", (c >> j) & 0x1);
109 }
110
111 printk("\n");
112}
113#endif
114
115/*
116 * This busy wait code normally requires less than 15 loops and
117 * practically always less than 100 loops on my i486/DX2 66 MHz.
118 *
119 * Warning: Waiting on the general status flag after reseting the MUTE
120 * function can take a VERY long time, because the PCM12 does some kind
121 * of fade-in effect. For this reason, access to the MUTE function has
122 * not been implemented at all.
123 *
124 * - The OSS interface has no mute option. It takes about 3 seconds to
125 * fade-in on my PCM20. busy_wait() handles it great now... Robert
126 */
127
128static int busy_wait(void)
129{
130 #define MINTIME 500
131 long timeout;
132 unsigned char byte;
133
134 for (timeout = 1; timeout <= MINTIME+30; timeout++) {
135 if (((byte=inb(BUSY_REGISTER)) & 1) == 0) {
136 if (timeout >= MINTIME)
137 printk(KERN_DEBUG "aci: Got READYFLAG in round %ld.\n", timeout-MINTIME);
138 return byte;
139 }
140 if (timeout >= MINTIME) {
141 long out=10*HZ;
142 switch (timeout-MINTIME) {
143 case 0 ... 9:
144 out /= 10;
145 case 10 ... 19:
146 out /= 10;
147 case 20 ... 30:
148 out /= 10;
149 default:
150 set_current_state(TASK_UNINTERRUPTIBLE);
151 schedule_timeout(out);
152 break;
153 }
154 }
155 }
156 printk(KERN_WARNING "aci: busy_wait() time out.\n");
157 return -EBUSY;
158}
159
160/* The four ACI command types are fucked up. [-:
161 * implied is: 1w - special case for INIT
162 * write is: 2w1r
163 * read is: x(1w1r) where x is 1 or 2 (1 CHECK_SIG, 1 CHECK_STER,
164 * 1 VERSION, 2 IDCODE)
165 * the command is only in the first write, rest is protocol overhead
166 *
167 * indexed is technically a write and used for STATUS
168 * and the special case for TUNE is: 3w1r
169 *
170 * Here the new general sheme: TUNE --> aci_rw_cmd(x, y, z)
171 * indexed and write --> aci_rw_cmd(x, y, -1)
172 * implied and read (x=1) --> aci_rw_cmd(x, -1, -1)
173 *
174 * Read (x>=2) is not implemented (only used during initialization).
175 * Use aci_idcode[2] and aci_version... Robert
176 */
177
178/* Some notes for error detection: theoretically it is possible.
179 * But it doubles the I/O-traffic from ww(r) to wwwrw(r) in the normal
180 * case and doesn't seem to be designed for that... Robert
181 */
182
183static inline int aci_rawwrite(unsigned char byte)
184{
185 if (busy_wait() >= 0) {
186#ifdef DEBUG
187 printk(KERN_DEBUG "aci_rawwrite(%d)\n", byte);
188#endif
189 outb(byte, COMMAND_REGISTER);
190 return 0;
191 } else
192 return -EBUSY;
193}
194
195static inline int aci_rawread(void)
196{
197 unsigned char byte;
198
199 if (busy_wait() >= 0) {
200 byte=inb(STATUS_REGISTER);
201#ifdef DEBUG
202 printk(KERN_DEBUG "%d = aci_rawread()\n", byte);
203#endif
204 return byte;
205 } else
206 return -EBUSY;
207}
208
209
210int aci_rw_cmd(int write1, int write2, int write3)
211{
212 int write[] = {write1, write2, write3};
213 int read = -EINTR, i;
214
215 if (down_interruptible(&aci_sem))
216 goto out;
217
218 for (i=0; i<3; i++) {
219 if (write[i]< 0 || write[i] > 255)
220 break;
221 else {
222 read = aci_rawwrite(write[i]);
223 if (read < 0)
224 goto out_up;
225 }
226
227 }
228
229 read = aci_rawread();
230out_up: up(&aci_sem);
231out: return read;
232}
233
234EXPORT_SYMBOL(aci_rw_cmd);
235
236static int setvolume(int __user *arg,
237 unsigned char left_index, unsigned char right_index)
238{
239 int vol, ret, uservol, buf;
240
241 __get_user(uservol, arg);
242
243 /* left channel */
244 vol = uservol & 0xff;
245 if (vol > 100)
246 vol = 100;
247 vol = SCALE(100, 0x20, vol);
248 if ((buf=aci_write_cmd(left_index, 0x20 - vol))<0)
249 return buf;
250 ret = SCALE(0x20, 100, vol);
251
252
253 /* right channel */
254 vol = (uservol >> 8) & 0xff;
255 if (vol > 100)
256 vol = 100;
257 vol = SCALE(100, 0x20, vol);
258 if ((buf=aci_write_cmd(right_index, 0x20 - vol))<0)
259 return buf;
260 ret |= SCALE(0x20, 100, vol) << 8;
261
262 __put_user(ret, arg);
263
264 return 0;
265}
266
267static int getvolume(int __user *arg,
268 unsigned char left_index, unsigned char right_index)
269{
270 int vol;
271 int buf;
272
273 /* left channel */
274 if ((buf=aci_indexed_cmd(ACI_STATUS, left_index))<0)
275 return buf;
276 vol = SCALE(0x20, 100, buf < 0x20 ? 0x20-buf : 0);
277
278 /* right channel */
279 if ((buf=aci_indexed_cmd(ACI_STATUS, right_index))<0)
280 return buf;
281 vol |= SCALE(0x20, 100, buf < 0x20 ? 0x20-buf : 0) << 8;
282
283 __put_user(vol, arg);
284
285 return 0;
286}
287
288
289/* The equalizer is somewhat strange on the ACI. From -12dB to +12dB
290 * write: 0xff..down.to..0x80==0x00..up.to..0x7f
291 */
292
293static inline unsigned int eq_oss2aci(unsigned int vol)
294{
295 int boost=0;
296 unsigned int ret;
297
298 if (vol > 100)
299 vol = 100;
300 if (vol > 50) {
301 vol -= 51;
302 boost=1;
303 }
304 if (boost)
305 ret=SCALE(49, 0x7e, vol)+1;
306 else
307 ret=0xff - SCALE(50, 0x7f, vol);
308 return ret;
309}
310
311static inline unsigned int eq_aci2oss(unsigned int vol)
312{
313 if (vol < 0x80)
314 return SCALE(0x7f, 50, vol) + 50;
315 else
316 return SCALE(0x7f, 50, 0xff-vol);
317}
318
319
320static int setequalizer(int __user *arg,
321 unsigned char left_index, unsigned char right_index)
322{
323 int buf;
324 unsigned int vol;
325
326 __get_user(vol, arg);
327
328 /* left channel */
329 if ((buf=aci_write_cmd(left_index, eq_oss2aci(vol & 0xff)))<0)
330 return buf;
331
332 /* right channel */
333 if ((buf=aci_write_cmd(right_index, eq_oss2aci((vol>>8) & 0xff)))<0)
334 return buf;
335
336 /* the ACI equalizer is more precise */
337 return 0;
338}
339
340static int getequalizer(int __user *arg,
341 unsigned char left_index, unsigned char right_index)
342{
343 int buf;
344 unsigned int vol;
345
346 /* left channel */
347 if ((buf=aci_indexed_cmd(ACI_STATUS, left_index))<0)
348 return buf;
349 vol = eq_aci2oss(buf);
350
351 /* right channel */
352 if ((buf=aci_indexed_cmd(ACI_STATUS, right_index))<0)
353 return buf;
354 vol |= eq_aci2oss(buf) << 8;
355
356 __put_user(vol, arg);
357
358 return 0;
359}
360
361static int aci_mixer_ioctl (int dev, unsigned int cmd, void __user * arg)
362{
363 int vol, buf;
364 int __user *p = arg;
365
366 switch (cmd) {
367 case SOUND_MIXER_WRITE_VOLUME:
368 return setvolume(p, 0x01, 0x00);
369 case SOUND_MIXER_WRITE_CD:
370 return setvolume(p, 0x3c, 0x34);
371 case SOUND_MIXER_WRITE_MIC:
372 return setvolume(p, 0x38, 0x30);
373 case SOUND_MIXER_WRITE_LINE:
374 return setvolume(p, 0x39, 0x31);
375 case SOUND_MIXER_WRITE_SYNTH:
376 return setvolume(p, 0x3b, 0x33);
377 case SOUND_MIXER_WRITE_PCM:
378 return setvolume(p, 0x3a, 0x32);
379 case MIXER_WRITE(SOUND_MIXER_RADIO): /* fall through */
380 case SOUND_MIXER_WRITE_LINE1: /* AUX1 or radio */
381 return setvolume(p, 0x3d, 0x35);
382 case SOUND_MIXER_WRITE_LINE2: /* AUX2 */
383 return setvolume(p, 0x3e, 0x36);
384 case SOUND_MIXER_WRITE_BASS: /* set band one and two */
385 if (aci_idcode[1]=='C') {
386 if ((buf=setequalizer(p, 0x48, 0x40)) ||
387 (buf=setequalizer(p, 0x49, 0x41)));
388 return buf;
389 }
390 break;
391 case SOUND_MIXER_WRITE_TREBLE: /* set band six and seven */
392 if (aci_idcode[1]=='C') {
393 if ((buf=setequalizer(p, 0x4d, 0x45)) ||
394 (buf=setequalizer(p, 0x4e, 0x46)));
395 return buf;
396 }
397 break;
398 case SOUND_MIXER_WRITE_IGAIN: /* MIC pre-amp */
399 if (aci_idcode[1]=='B' || aci_idcode[1]=='C') {
400 __get_user(vol, p);
401 vol = vol & 0xff;
402 if (vol > 100)
403 vol = 100;
404 vol = SCALE(100, 3, vol);
405 if ((buf=aci_write_cmd(ACI_WRITE_IGAIN, vol))<0)
406 return buf;
407 aci_micpreamp = vol;
408 vol = SCALE(3, 100, vol);
409 vol |= (vol << 8);
410 __put_user(vol, p);
411 return 0;
412 }
413 break;
414 case SOUND_MIXER_WRITE_OGAIN: /* Power-amp/line-out level */
415 if (aci_idcode[1]=='A' || aci_idcode[1]=='B') {
416 __get_user(buf, p);
417 buf = buf & 0xff;
418 if (buf > 50)
419 vol = 1;
420 else
421 vol = 0;
422 if ((buf=aci_write_cmd(ACI_SET_POWERAMP, vol))<0)
423 return buf;
424 aci_amp = vol;
425 if (aci_amp)
426 buf = (100 || 100<<8);
427 else
428 buf = 0;
429 __put_user(buf, p);
430 return 0;
431 }
432 break;
433 case SOUND_MIXER_WRITE_RECSRC:
434 /* handle solo mode control */
435 __get_user(buf, p);
436 /* unset solo when RECSRC for PCM is requested */
437 if (aci_idcode[1]=='B' || aci_idcode[1]=='C') {
438 vol = !(buf & SOUND_MASK_PCM);
439 if ((buf=aci_write_cmd(ACI_SET_SOLOMODE, vol))<0)
440 return buf;
441 aci_solo = vol;
442 }
443 buf = (SOUND_MASK_CD| SOUND_MASK_MIC| SOUND_MASK_LINE|
444 SOUND_MASK_SYNTH| SOUND_MASK_LINE2);
445 if (aci_idcode[1] == 'C') /* PCM20 radio */
446 buf |= SOUND_MASK_RADIO;
447 else
448 buf |= SOUND_MASK_LINE1;
449 if (!aci_solo)
450 buf |= SOUND_MASK_PCM;
451 __put_user(buf, p);
452 return 0;
453 case SOUND_MIXER_READ_DEVMASK:
454 buf = (SOUND_MASK_VOLUME | SOUND_MASK_CD |
455 SOUND_MASK_MIC | SOUND_MASK_LINE |
456 SOUND_MASK_SYNTH | SOUND_MASK_PCM |
457 SOUND_MASK_LINE2);
458 switch (aci_idcode[1]) {
459 case 'C': /* PCM20 radio */
460 buf |= (SOUND_MASK_RADIO | SOUND_MASK_IGAIN |
461 SOUND_MASK_BASS | SOUND_MASK_TREBLE);
462 break;
463 case 'B': /* PCM12 */
464 buf |= (SOUND_MASK_LINE1 | SOUND_MASK_IGAIN |
465 SOUND_MASK_OGAIN);
466 break;
467 case 'A': /* PCM1-pro */
468 buf |= (SOUND_MASK_LINE1 | SOUND_MASK_OGAIN);
469 break;
470 default:
471 buf |= SOUND_MASK_LINE1;
472 }
473 __put_user(buf, p);
474 return 0;
475 case SOUND_MIXER_READ_STEREODEVS:
476 buf = (SOUND_MASK_VOLUME | SOUND_MASK_CD |
477 SOUND_MASK_MIC | SOUND_MASK_LINE |
478 SOUND_MASK_SYNTH | SOUND_MASK_PCM |
479 SOUND_MASK_LINE2);
480 switch (aci_idcode[1]) {
481 case 'C': /* PCM20 radio */
482 buf |= (SOUND_MASK_RADIO |
483 SOUND_MASK_BASS | SOUND_MASK_TREBLE);
484 break;
485 default:
486 buf |= SOUND_MASK_LINE1;
487 }
488 __put_user(buf, p);
489 return 0;
490 case SOUND_MIXER_READ_RECMASK:
491 buf = (SOUND_MASK_CD| SOUND_MASK_MIC| SOUND_MASK_LINE|
492 SOUND_MASK_SYNTH| SOUND_MASK_LINE2| SOUND_MASK_PCM);
493 if (aci_idcode[1] == 'C') /* PCM20 radio */
494 buf |= SOUND_MASK_RADIO;
495 else
496 buf |= SOUND_MASK_LINE1;
497
498 __put_user(buf, p);
499 return 0;
500 case SOUND_MIXER_READ_RECSRC:
501 buf = (SOUND_MASK_CD | SOUND_MASK_MIC | SOUND_MASK_LINE |
502 SOUND_MASK_SYNTH | SOUND_MASK_LINE2);
503 /* do we need aci_solo or can I get it from the ACI? */
504 switch (aci_idcode[1]) {
505 case 'B': /* PCM12 */
506 case 'C': /* PCM20 radio */
507 if (aci_version >= 0xb0) {
508 if ((vol=aci_rw_cmd(ACI_STATUS,
509 ACI_S_GENERAL, -1))<0)
510 return vol;
511 if (vol & 0x20)
512 buf |= SOUND_MASK_PCM;
513 }
514 else
515 if (!aci_solo)
516 buf |= SOUND_MASK_PCM;
517 break;
518 default:
519 buf |= SOUND_MASK_PCM;
520 }
521 if (aci_idcode[1] == 'C') /* PCM20 radio */
522 buf |= SOUND_MASK_RADIO;
523 else
524 buf |= SOUND_MASK_LINE1;
525
526 __put_user(buf, p);
527 return 0;
528 case SOUND_MIXER_READ_CAPS:
529 __put_user(0, p);
530 return 0;
531 case SOUND_MIXER_READ_VOLUME:
532 return getvolume(p, 0x04, 0x03);
533 case SOUND_MIXER_READ_CD:
534 return getvolume(p, 0x0a, 0x09);
535 case SOUND_MIXER_READ_MIC:
536 return getvolume(p, 0x06, 0x05);
537 case SOUND_MIXER_READ_LINE:
538 return getvolume(p, 0x08, 0x07);
539 case SOUND_MIXER_READ_SYNTH:
540 return getvolume(p, 0x0c, 0x0b);
541 case SOUND_MIXER_READ_PCM:
542 return getvolume(p, 0x0e, 0x0d);
543 case MIXER_READ(SOUND_MIXER_RADIO): /* fall through */
544 case SOUND_MIXER_READ_LINE1: /* AUX1 */
545 return getvolume(p, 0x11, 0x10);
546 case SOUND_MIXER_READ_LINE2: /* AUX2 */
547 return getvolume(p, 0x13, 0x12);
548 case SOUND_MIXER_READ_BASS: /* get band one */
549 if (aci_idcode[1]=='C') {
550 return getequalizer(p, 0x23, 0x22);
551 }
552 break;
553 case SOUND_MIXER_READ_TREBLE: /* get band seven */
554 if (aci_idcode[1]=='C') {
555 return getequalizer(p, 0x2f, 0x2e);
556 }
557 break;
558 case SOUND_MIXER_READ_IGAIN: /* MIC pre-amp */
559 if (aci_idcode[1]=='B' || aci_idcode[1]=='C') {
560 /* aci_micpreamp or ACI? */
561 if (aci_version >= 0xb0) {
562 if ((buf=aci_indexed_cmd(ACI_STATUS,
563 ACI_S_READ_IGAIN))<0)
564 return buf;
565 }
566 else
567 buf=aci_micpreamp;
568 vol = SCALE(3, 100, buf <= 3 ? buf : 3);
569 vol |= vol << 8;
570 __put_user(vol, p);
571 return 0;
572 }
573 break;
574 case SOUND_MIXER_READ_OGAIN:
575 if (aci_amp)
576 buf = (100 || 100<<8);
577 else
578 buf = 0;
579 __put_user(buf, p);
580 return 0;
581 }
582 return -EINVAL;
583}
584
585static struct mixer_operations aci_mixer_operations =
586{
587 .owner = THIS_MODULE,
588 .id = "ACI",
589 .ioctl = aci_mixer_ioctl
590};
591
592/*
593 * There is also an internal mixer in the codec (CS4231A or AD1845),
594 * that deserves no purpose in an ACI based system which uses an
595 * external ACI controlled stereo mixer. Make sure that this codec
596 * mixer has the AUX1 input selected as the recording source, that the
597 * input gain is set near maximum and that the other channels going
598 * from the inputs to the codec output are muted.
599 */
600
601static int __init attach_aci(void)
602{
603 char *boardname;
604 int i, rc = -EBUSY;
605
606 init_MUTEX(&aci_sem);
607
608 outb(0xE3, 0xf8f); /* Write MAD16 password */
609 aci_port = (inb(0xf90) & 0x10) ?
610 0x344: 0x354; /* Get aci_port from MC4_PORT */
611
612 if (!request_region(aci_port, 3, "sound mixer (ACI)")) {
613 printk(KERN_NOTICE
614 "aci: I/O area 0x%03x-0x%03x already used.\n",
615 aci_port, aci_port+2);
616 goto out;
617 }
618
619 /* force ACI into a known state */
620 rc = -EFAULT;
621 for (i=0; i<3; i++)
622 if (aci_rw_cmd(ACI_ERROR_OP, -1, -1)<0)
623 goto out_release_region;
624
625 /* official this is one aci read call: */
626 rc = -EFAULT;
627 if ((aci_idcode[0]=aci_rw_cmd(ACI_READ_IDCODE, -1, -1))<0 ||
628 (aci_idcode[1]=aci_rw_cmd(ACI_READ_IDCODE, -1, -1))<0) {
629 printk(KERN_ERR "aci: Failed to read idcode on 0x%03x.\n",
630 aci_port);
631 goto out_release_region;
632 }
633
634 if ((aci_version=aci_rw_cmd(ACI_READ_VERSION, -1, -1))<0) {
635 printk(KERN_ERR "aci: Failed to read version on 0x%03x.\n",
636 aci_port);
637 goto out_release_region;
638 }
639
640 if (aci_idcode[0] == 'm') {
641 /* It looks like a miro sound card. */
642 switch (aci_idcode[1]) {
643 case 'A':
644 boardname = "PCM1 pro / early PCM12";
645 break;
646 case 'B':
647 boardname = "PCM12";
648 break;
649 case 'C':
650 boardname = "PCM20 radio";
651 break;
652 default:
653 boardname = "unknown miro";
654 }
655 } else {
656 printk(KERN_WARNING "aci: Warning: unsupported card! - "
657 "no hardware, no specs...\n");
658 boardname = "unknown Cardinal Technologies";
659 }
660
661 printk(KERN_INFO "<ACI 0x%02x, id %02x/%02x \"%c/%c\", (%s)> at 0x%03x\n",
662 aci_version,
663 aci_idcode[0], aci_idcode[1],
664 aci_idcode[0], aci_idcode[1],
665 boardname, aci_port);
666
667 rc = -EBUSY;
668 if (reset) {
669 /* first write()s after reset fail with my PCM20 */
670 if (aci_rw_cmd(ACI_INIT, -1, -1)<0 ||
671 aci_rw_cmd(ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP)<0 ||
672 aci_rw_cmd(ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP)<0)
673 goto out_release_region;
674 }
675
676 /* the PCM20 is muted after reset (and reboot) */
677 if (aci_rw_cmd(ACI_SET_MUTE, 0x00, -1)<0)
678 goto out_release_region;
679
680 if (ide>=0)
681 if (aci_rw_cmd(ACI_SET_IDE, !ide, -1)<0)
682 goto out_release_region;
683
684 if (wss>=0 && aci_idcode[1]=='A')
685 if (aci_rw_cmd(ACI_SET_WSS, !!wss, -1)<0)
686 goto out_release_region;
687
688 mixer_device = sound_install_mixer(MIXER_DRIVER_VERSION, boardname,
689 &aci_mixer_operations,
690 sizeof(aci_mixer_operations), NULL);
691 rc = 0;
692 if (mixer_device < 0) {
693 printk(KERN_ERR "aci: Failed to install mixer.\n");
694 rc = mixer_device;
695 goto out_release_region;
696 } /* else Maybe initialize the CS4231A mixer here... */
697out: return rc;
698out_release_region:
699 release_region(aci_port, 3);
700 goto out;
701}
702
703static void __exit unload_aci(void)
704{
705 sound_unload_mixerdev(mixer_device);
706 release_region(aci_port, 3);
707}
708
709module_init(attach_aci);
710module_exit(unload_aci);
711MODULE_LICENSE("GPL");
diff --git a/sound/oss/aci.h b/sound/oss/aci.h
new file mode 100644
index 000000000000..20102ee088eb
--- /dev/null
+++ b/sound/oss/aci.h
@@ -0,0 +1,57 @@
1#ifndef _ACI_H_
2#define _ACI_H_
3
4extern int aci_port;
5extern int aci_version; /* ACI firmware version */
6extern int aci_rw_cmd(int write1, int write2, int write3);
7
8#define aci_indexed_cmd(a, b) aci_rw_cmd(a, b, -1)
9#define aci_write_cmd(a, b) aci_rw_cmd(a, b, -1)
10#define aci_read_cmd(a) aci_rw_cmd(a,-1, -1)
11
12#define COMMAND_REGISTER (aci_port) /* write register */
13#define STATUS_REGISTER (aci_port + 1) /* read register */
14#define BUSY_REGISTER (aci_port + 2) /* also used for rds */
15
16#define RDS_REGISTER BUSY_REGISTER
17
18#define ACI_SET_MUTE 0x0d
19#define ACI_SET_POWERAMP 0x0f
20#define ACI_SET_TUNERMUTE 0xa3
21#define ACI_SET_TUNERMONO 0xa4
22#define ACI_SET_IDE 0xd0
23#define ACI_SET_WSS 0xd1
24#define ACI_SET_SOLOMODE 0xd2
25#define ACI_WRITE_IGAIN 0x03
26#define ACI_WRITE_TUNE 0xa7
27#define ACI_READ_TUNERSTEREO 0xa8
28#define ACI_READ_TUNERSTATION 0xa9
29#define ACI_READ_VERSION 0xf1
30#define ACI_READ_IDCODE 0xf2
31#define ACI_INIT 0xff
32#define ACI_STATUS 0xf0
33#define ACI_S_GENERAL 0x00
34#define ACI_S_READ_IGAIN 0x21
35#define ACI_ERROR_OP 0xdf
36
37/*
38 * The following macro SCALE can be used to scale one integer volume
39 * value into another one using only integer arithmetic. If the input
40 * value x is in the range 0 <= x <= xmax, then the result will be in
41 * the range 0 <= SCALE(xmax,ymax,x) <= ymax.
42 *
43 * This macro has for all xmax, ymax > 0 and all 0 <= x <= xmax the
44 * following nice properties:
45 *
46 * - SCALE(xmax,ymax,xmax) = ymax
47 * - SCALE(xmax,ymax,0) = 0
48 * - SCALE(xmax,ymax,SCALE(ymax,xmax,SCALE(xmax,ymax,x))) = SCALE(xmax,ymax,x)
49 *
50 * In addition, the rounding error is minimal and nicely distributed.
51 * The proofs are left as an exercise to the reader.
52 */
53
54#define SCALE(xmax,ymax,x) (((x)*(ymax)+(xmax)/2)/(xmax))
55
56
57#endif /* _ACI_H_ */
diff --git a/sound/oss/ad1816.c b/sound/oss/ad1816.c
new file mode 100644
index 000000000000..22dae5d0fda3
--- /dev/null
+++ b/sound/oss/ad1816.c
@@ -0,0 +1,1369 @@
1/*
2 *
3 * AD1816 lowlevel sound driver for Linux 2.6.0 and above
4 *
5 * Copyright (C) 1998-2003 by Thorsten Knabe <linux@thorsten-knabe.de>
6 *
7 * Based on the CS4232/AD1848 driver Copyright (C) by Hannu Savolainen 1993-1996
8 *
9 *
10 * version: 1.5
11 * status: beta
12 * date: 2003/07/15
13 *
14 * Changes:
15 * Oleg Drokin: Some cleanup of load/unload functions. 1998/11/24
16 *
17 * Thorsten Knabe: attach and unload rewritten,
18 * some argument checks added 1998/11/30
19 *
20 * Thorsten Knabe: Buggy isa bridge workaround added 1999/01/16
21 *
22 * David Moews/Thorsten Knabe: Introduced options
23 * parameter. Added slightly modified patch from
24 * David Moews to disable dsp audio sources by setting
25 * bit 0 of options parameter. This seems to be
26 * required by some Aztech/Newcom SC-16 cards. 1999/04/18
27 *
28 * Christoph Hellwig: Adapted to module_init/module_exit. 2000/03/03
29 *
30 * Christoph Hellwig: Added isapnp support 2000/03/15
31 *
32 * Arnaldo Carvalho de Melo: get rid of check_region 2001/10/07
33 *
34 * Thorsten Knabe: Compiling with CONFIG_PNP enabled
35 * works again. It is now possible to use more than one
36 * AD1816 sound card. Sample rate now may be changed during
37 * playback/capture. printk() uses log levels everywhere.
38 * SMP fixes. DMA handling fixes.
39 * Other minor code cleanup. 2003/07/15
40 *
41 */
42
43
44#include <linux/config.h>
45#include <linux/module.h>
46#include <linux/init.h>
47#include <linux/interrupt.h>
48#include <linux/isapnp.h>
49#include <linux/stddef.h>
50#include <linux/spinlock.h>
51#include "sound_config.h"
52
53#define DEBUGNOISE(x)
54
55#define CHECK_FOR_POWER { int timeout=100; \
56 while (timeout > 0 && (inb(devc->base)&0x80)!= 0x80) {\
57 timeout--; \
58 } \
59 if (timeout==0) {\
60 printk(KERN_WARNING "ad1816: Check for power failed in %s line: %d\n",__FILE__,__LINE__); \
61 } \
62}
63
64/* structure to hold device specific information */
65typedef struct
66{
67 int base; /* set in attach */
68 int irq;
69 int dma_playback;
70 int dma_capture;
71
72 int opened; /* open */
73 int speed;
74 int channels;
75 int audio_format;
76 int audio_mode;
77
78 int recmask; /* setup */
79 unsigned char format_bits;
80 int supported_devices;
81 int supported_rec_devices;
82 unsigned short levels[SOUND_MIXER_NRDEVICES];
83 /* misc */
84 struct pnp_dev *pnpdev; /* configured via pnp */
85 int dev_no; /* this is the # in audio_devs and NOT
86 in ad1816_info */
87 spinlock_t lock;
88} ad1816_info;
89
90static int nr_ad1816_devs;
91static int ad1816_clockfreq = 33000;
92static int options;
93
94/* supported audio formats */
95static int ad_format_mask =
96AFMT_U8 | AFMT_S16_LE | AFMT_S16_BE | AFMT_MU_LAW | AFMT_A_LAW;
97
98/* array of device info structures */
99static ad1816_info dev_info[MAX_AUDIO_DEV];
100
101
102/* ------------------------------------------------------------------- */
103
104/* functions for easier access to inderect registers */
105
106static int ad_read (ad1816_info * devc, int reg)
107{
108 int result;
109
110 CHECK_FOR_POWER;
111 outb ((unsigned char) (reg & 0x3f), devc->base+0);
112 result = inb(devc->base+2);
113 result+= inb(devc->base+3)<<8;
114 return (result);
115}
116
117
118static void ad_write (ad1816_info * devc, int reg, int data)
119{
120 CHECK_FOR_POWER;
121 outb ((unsigned char) (reg & 0xff), devc->base+0);
122 outb ((unsigned char) (data & 0xff),devc->base+2);
123 outb ((unsigned char) ((data>>8)&0xff),devc->base+3);
124}
125
126/* ------------------------------------------------------------------- */
127
128/* function interface required by struct audio_driver */
129
130static void ad1816_halt_input (int dev)
131{
132 unsigned long flags;
133 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
134 unsigned char buffer;
135
136 DEBUGNOISE(printk(KERN_DEBUG "ad1816: halt_input called\n"));
137
138 spin_lock_irqsave(&devc->lock,flags);
139
140 if(!isa_dma_bridge_buggy) {
141 disable_dma(audio_devs[dev]->dmap_in->dma);
142 }
143
144 buffer=inb(devc->base+9);
145 if (buffer & 0x01) {
146 /* disable capture */
147 outb(buffer & ~0x01,devc->base+9);
148 }
149
150 if(!isa_dma_bridge_buggy) {
151 enable_dma(audio_devs[dev]->dmap_in->dma);
152 }
153
154 /* Clear interrupt status */
155 outb (~0x40, devc->base+1);
156
157 devc->audio_mode &= ~PCM_ENABLE_INPUT;
158 spin_unlock_irqrestore(&devc->lock,flags);
159}
160
161static void ad1816_halt_output (int dev)
162{
163 unsigned long flags;
164 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
165
166 unsigned char buffer;
167
168 DEBUGNOISE(printk(KERN_DEBUG "ad1816: halt_output called!\n"));
169
170 spin_lock_irqsave(&devc->lock,flags);
171 /* Mute pcm output */
172 ad_write(devc, 4, ad_read(devc,4)|0x8080);
173
174 if(!isa_dma_bridge_buggy) {
175 disable_dma(audio_devs[dev]->dmap_out->dma);
176 }
177
178 buffer=inb(devc->base+8);
179 if (buffer & 0x01) {
180 /* disable capture */
181 outb(buffer & ~0x01,devc->base+8);
182 }
183
184 if(!isa_dma_bridge_buggy) {
185 enable_dma(audio_devs[dev]->dmap_out->dma);
186 }
187
188 /* Clear interrupt status */
189 outb ((unsigned char)~0x80, devc->base+1);
190
191 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
192 spin_unlock_irqrestore(&devc->lock,flags);
193}
194
195static void ad1816_output_block (int dev, unsigned long buf,
196 int count, int intrflag)
197{
198 unsigned long flags;
199 unsigned long cnt;
200 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
201
202 DEBUGNOISE(printk(KERN_DEBUG "ad1816: output_block called buf=%ld count=%d flags=%d\n",buf,count,intrflag));
203
204 cnt = count/4 - 1;
205
206 spin_lock_irqsave(&devc->lock,flags);
207
208 /* set transfer count */
209 ad_write (devc, 8, cnt & 0xffff);
210
211 devc->audio_mode |= PCM_ENABLE_OUTPUT;
212 spin_unlock_irqrestore(&devc->lock,flags);
213}
214
215
216static void ad1816_start_input (int dev, unsigned long buf, int count,
217 int intrflag)
218{
219 unsigned long flags;
220 unsigned long cnt;
221 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
222
223 DEBUGNOISE(printk(KERN_DEBUG "ad1816: start_input called buf=%ld count=%d flags=%d\n",buf,count,intrflag));
224
225 cnt = count/4 - 1;
226
227 spin_lock_irqsave(&devc->lock,flags);
228
229 /* set transfer count */
230 ad_write (devc, 10, cnt & 0xffff);
231 devc->audio_mode |= PCM_ENABLE_INPUT;
232 spin_unlock_irqrestore(&devc->lock,flags);
233}
234
235static int ad1816_prepare_for_input (int dev, int bsize, int bcount)
236{
237 unsigned long flags;
238 unsigned int freq;
239 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
240 unsigned char fmt_bits;
241
242 DEBUGNOISE(printk(KERN_DEBUG "ad1816: prepare_for_input called: bsize=%d bcount=%d\n",bsize,bcount));
243
244 spin_lock_irqsave(&devc->lock,flags);
245 fmt_bits= (devc->format_bits&0x7)<<3;
246
247 /* set mono/stereo mode */
248 if (devc->channels > 1) {
249 fmt_bits |=0x4;
250 }
251 /* set Mono/Stereo in playback/capture register */
252 outb( (inb(devc->base+8) & ~0x3C)|fmt_bits, devc->base+8);
253 outb( (inb(devc->base+9) & ~0x3C)|fmt_bits, devc->base+9);
254
255 freq=((unsigned int)devc->speed*33000)/ad1816_clockfreq;
256
257 /* write playback/capture speeds */
258 ad_write (devc, 2, freq & 0xffff);
259 ad_write (devc, 3, freq & 0xffff);
260
261 spin_unlock_irqrestore(&devc->lock,flags);
262
263 ad1816_halt_input(dev);
264 return 0;
265}
266
267static int ad1816_prepare_for_output (int dev, int bsize, int bcount)
268{
269 unsigned long flags;
270 unsigned int freq;
271 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
272 unsigned char fmt_bits;
273
274 DEBUGNOISE(printk(KERN_DEBUG "ad1816: prepare_for_output called: bsize=%d bcount=%d\n",bsize,bcount));
275
276 spin_lock_irqsave(&devc->lock,flags);
277
278 fmt_bits= (devc->format_bits&0x7)<<3;
279 /* set mono/stereo mode */
280 if (devc->channels > 1) {
281 fmt_bits |=0x4;
282 }
283
284 /* write format bits to playback/capture registers */
285 outb( (inb(devc->base+8) & ~0x3C)|fmt_bits, devc->base+8);
286 outb( (inb(devc->base+9) & ~0x3C)|fmt_bits, devc->base+9);
287
288 freq=((unsigned int)devc->speed*33000)/ad1816_clockfreq;
289
290 /* write playback/capture speeds */
291 ad_write (devc, 2, freq & 0xffff);
292 ad_write (devc, 3, freq & 0xffff);
293
294 spin_unlock_irqrestore(&devc->lock,flags);
295
296 ad1816_halt_output(dev);
297 return 0;
298
299}
300
301static void ad1816_trigger (int dev, int state)
302{
303 unsigned long flags;
304 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
305
306 DEBUGNOISE(printk(KERN_DEBUG "ad1816: trigger called! (devc=%d,devc->base=%d\n", devc, devc->base));
307
308 /* mode may have changed */
309
310 spin_lock_irqsave(&devc->lock,flags);
311
312 /* mask out modes not specified on open call */
313 state &= devc->audio_mode;
314
315 /* setup soundchip to new io-mode */
316 if (state & PCM_ENABLE_INPUT) {
317 /* enable capture */
318 outb(inb(devc->base+9)|0x01, devc->base+9);
319 } else {
320 /* disable capture */
321 outb(inb(devc->base+9)&~0x01, devc->base+9);
322 }
323
324 if (state & PCM_ENABLE_OUTPUT) {
325 /* enable playback */
326 outb(inb(devc->base+8)|0x01, devc->base+8);
327 /* unmute pcm output */
328 ad_write(devc, 4, ad_read(devc,4)&~0x8080);
329 } else {
330 /* mute pcm output */
331 ad_write(devc, 4, ad_read(devc,4)|0x8080);
332 /* disable capture */
333 outb(inb(devc->base+8)&~0x01, devc->base+8);
334 }
335 spin_unlock_irqrestore(&devc->lock,flags);
336}
337
338
339/* halt input & output */
340static void ad1816_halt (int dev)
341{
342 ad1816_halt_input(dev);
343 ad1816_halt_output(dev);
344}
345
346static void ad1816_reset (int dev)
347{
348 ad1816_halt (dev);
349}
350
351/* set playback speed */
352static int ad1816_set_speed (int dev, int arg)
353{
354 unsigned long flags;
355 unsigned int freq;
356 int ret;
357
358 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
359
360 spin_lock_irqsave(&devc->lock, flags);
361 if (arg == 0) {
362 ret = devc->speed;
363 spin_unlock_irqrestore(&devc->lock, flags);
364 return ret;
365 }
366 /* range checking */
367 if (arg < 4000) {
368 arg = 4000;
369 }
370 if (arg > 55000) {
371 arg = 55000;
372 }
373 devc->speed = arg;
374
375 /* change speed during playback */
376 freq=((unsigned int)devc->speed*33000)/ad1816_clockfreq;
377 /* write playback/capture speeds */
378 ad_write (devc, 2, freq & 0xffff);
379 ad_write (devc, 3, freq & 0xffff);
380
381 ret = devc->speed;
382 spin_unlock_irqrestore(&devc->lock, flags);
383 return ret;
384
385}
386
387static unsigned int ad1816_set_bits (int dev, unsigned int arg)
388{
389 unsigned long flags;
390 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
391
392 static struct format_tbl {
393 int format;
394 unsigned char bits;
395 } format2bits[] = {
396 { 0, 0 },
397 { AFMT_MU_LAW, 1 },
398 { AFMT_A_LAW, 3 },
399 { AFMT_IMA_ADPCM, 0 },
400 { AFMT_U8, 0 },
401 { AFMT_S16_LE, 2 },
402 { AFMT_S16_BE, 6 },
403 { AFMT_S8, 0 },
404 { AFMT_U16_LE, 0 },
405 { AFMT_U16_BE, 0 }
406 };
407
408 int i, n = sizeof (format2bits) / sizeof (struct format_tbl);
409
410 spin_lock_irqsave(&devc->lock, flags);
411 /* return current format */
412 if (arg == 0) {
413 arg = devc->audio_format;
414 spin_unlock_irqrestore(&devc->lock, flags);
415 return arg;
416 }
417 devc->audio_format = arg;
418
419 /* search matching format bits */
420 for (i = 0; i < n; i++)
421 if (format2bits[i].format == arg) {
422 devc->format_bits = format2bits[i].bits;
423 devc->audio_format = arg;
424 spin_unlock_irqrestore(&devc->lock, flags);
425 return arg;
426 }
427
428 /* Still hanging here. Something must be terribly wrong */
429 devc->format_bits = 0;
430 devc->audio_format = AFMT_U8;
431 spin_unlock_irqrestore(&devc->lock, flags);
432 return(AFMT_U8);
433}
434
435static short ad1816_set_channels (int dev, short arg)
436{
437 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
438
439 if (arg != 1 && arg != 2)
440 return devc->channels;
441
442 devc->channels = arg;
443 return arg;
444}
445
446/* open device */
447static int ad1816_open (int dev, int mode)
448{
449 ad1816_info *devc = NULL;
450 unsigned long flags;
451
452 /* is device number valid ? */
453 if (dev < 0 || dev >= num_audiodevs)
454 return -(ENXIO);
455
456 /* get device info of this dev */
457 devc = (ad1816_info *) audio_devs[dev]->devc;
458
459 /* make check if device already open atomic */
460 spin_lock_irqsave(&devc->lock,flags);
461
462 if (devc->opened) {
463 spin_unlock_irqrestore(&devc->lock,flags);
464 return -(EBUSY);
465 }
466
467 /* mark device as open */
468 devc->opened = 1;
469
470 devc->audio_mode = 0;
471 devc->speed = 8000;
472 devc->audio_format=AFMT_U8;
473 devc->channels=1;
474 spin_unlock_irqrestore(&devc->lock,flags);
475 ad1816_reset(devc->dev_no); /* halt all pending output */
476 return 0;
477}
478
479static void ad1816_close (int dev) /* close device */
480{
481 unsigned long flags;
482 ad1816_info *devc = (ad1816_info *) audio_devs[dev]->devc;
483
484 /* halt all pending output */
485 ad1816_reset(devc->dev_no);
486
487 spin_lock_irqsave(&devc->lock,flags);
488 devc->opened = 0;
489 devc->audio_mode = 0;
490 devc->speed = 8000;
491 devc->audio_format=AFMT_U8;
492 devc->format_bits = 0;
493 spin_unlock_irqrestore(&devc->lock,flags);
494}
495
496
497/* ------------------------------------------------------------------- */
498
499/* Audio driver structure */
500
501static struct audio_driver ad1816_audio_driver =
502{
503 .owner = THIS_MODULE,
504 .open = ad1816_open,
505 .close = ad1816_close,
506 .output_block = ad1816_output_block,
507 .start_input = ad1816_start_input,
508 .prepare_for_input = ad1816_prepare_for_input,
509 .prepare_for_output = ad1816_prepare_for_output,
510 .halt_io = ad1816_halt,
511 .halt_input = ad1816_halt_input,
512 .halt_output = ad1816_halt_output,
513 .trigger = ad1816_trigger,
514 .set_speed = ad1816_set_speed,
515 .set_bits = ad1816_set_bits,
516 .set_channels = ad1816_set_channels,
517};
518
519
520/* ------------------------------------------------------------------- */
521
522/* Interrupt handler */
523
524
525static irqreturn_t ad1816_interrupt (int irq, void *dev_id, struct pt_regs *dummy)
526{
527 unsigned char status;
528 ad1816_info *devc = (ad1816_info *)dev_id;
529
530 if (irq < 0 || irq > 15) {
531 printk(KERN_WARNING "ad1816: Got bogus interrupt %d\n", irq);
532 return IRQ_NONE;
533 }
534
535 spin_lock(&devc->lock);
536
537 /* read interrupt register */
538 status = inb (devc->base+1);
539 /* Clear all interrupt */
540 outb (~status, devc->base+1);
541
542 DEBUGNOISE(printk(KERN_DEBUG "ad1816: Got interrupt subclass %d\n",status));
543
544 if (status == 0) {
545 DEBUGNOISE(printk(KERN_DEBUG "ad1816: interrupt: Got interrupt, but no source.\n"));
546 spin_unlock(&devc->lock);
547 return IRQ_NONE;
548 }
549
550 if (devc->opened && (devc->audio_mode & PCM_ENABLE_INPUT) && (status&64))
551 DMAbuf_inputintr (devc->dev_no);
552
553 if (devc->opened && (devc->audio_mode & PCM_ENABLE_OUTPUT) && (status & 128))
554 DMAbuf_outputintr (devc->dev_no, 1);
555
556 spin_unlock(&devc->lock);
557 return IRQ_HANDLED;
558}
559
560/* ------------------------------------------------------------------- */
561
562/* Mixer stuff */
563
564struct mixer_def {
565 unsigned int regno: 7;
566 unsigned int polarity:1; /* 0=normal, 1=reversed */
567 unsigned int bitpos:4;
568 unsigned int nbits:4;
569};
570
571static char mix_cvt[101] = {
572 0, 0, 3, 7,10,13,16,19,21,23,26,28,30,32,34,35,37,39,40,42,
573 43,45,46,47,49,50,51,52,53,55,56,57,58,59,60,61,62,63,64,65,
574 65,66,67,68,69,70,70,71,72,73,73,74,75,75,76,77,77,78,79,79,
575 80,81,81,82,82,83,84,84,85,85,86,86,87,87,88,88,89,89,90,90,
576 91,91,92,92,93,93,94,94,95,95,96,96,96,97,97,98,98,98,99,99,
577 100
578};
579
580typedef struct mixer_def mixer_ent;
581
582/*
583 * Most of the mixer entries work in backwards. Setting the polarity field
584 * makes them to work correctly.
585 *
586 * The channel numbering used by individual soundcards is not fixed. Some
587 * cards have assigned different meanings for the AUX1, AUX2 and LINE inputs.
588 * The current version doesn't try to compensate this.
589 */
590
591#define MIX_ENT(name, reg_l, pola_l, pos_l, len_l, reg_r, pola_r, pos_r, len_r) \
592 {{reg_l, pola_l, pos_l, len_l}, {reg_r, pola_r, pos_r, len_r}}
593
594
595mixer_ent mix_devices[SOUND_MIXER_NRDEVICES][2] = {
596MIX_ENT(SOUND_MIXER_VOLUME, 14, 1, 8, 5, 14, 1, 0, 5),
597MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0),
598MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0),
599MIX_ENT(SOUND_MIXER_SYNTH, 5, 1, 8, 6, 5, 1, 0, 6),
600MIX_ENT(SOUND_MIXER_PCM, 4, 1, 8, 6, 4, 1, 0, 6),
601MIX_ENT(SOUND_MIXER_SPEAKER, 0, 0, 0, 0, 0, 0, 0, 0),
602MIX_ENT(SOUND_MIXER_LINE, 18, 1, 8, 5, 18, 1, 0, 5),
603MIX_ENT(SOUND_MIXER_MIC, 19, 1, 8, 5, 19, 1, 0, 5),
604MIX_ENT(SOUND_MIXER_CD, 15, 1, 8, 5, 15, 1, 0, 5),
605MIX_ENT(SOUND_MIXER_IMIX, 0, 0, 0, 0, 0, 0, 0, 0),
606MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0),
607MIX_ENT(SOUND_MIXER_RECLEV, 20, 0, 8, 4, 20, 0, 0, 4),
608MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 0, 0, 0, 0, 0),
609MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0),
610MIX_ENT(SOUND_MIXER_LINE1, 17, 1, 8, 5, 17, 1, 0, 5),
611MIX_ENT(SOUND_MIXER_LINE2, 16, 1, 8, 5, 16, 1, 0, 5),
612MIX_ENT(SOUND_MIXER_LINE3, 39, 0, 9, 4, 39, 1, 0, 5)
613};
614
615
616static unsigned short default_mixer_levels[SOUND_MIXER_NRDEVICES] =
617{
618 0x4343, /* Master Volume */
619 0x3232, /* Bass */
620 0x3232, /* Treble */
621 0x0000, /* FM */
622 0x4343, /* PCM */
623 0x0000, /* PC Speaker */
624 0x0000, /* Ext Line */
625 0x0000, /* Mic */
626 0x0000, /* CD */
627 0x0000, /* Recording monitor */
628 0x0000, /* SB PCM */
629 0x0000, /* Recording level */
630 0x0000, /* Input gain */
631 0x0000, /* Output gain */
632 0x0000, /* Line1 */
633 0x0000, /* Line2 */
634 0x0000 /* Line3 (usually line in)*/
635};
636
637#define LEFT_CHN 0
638#define RIGHT_CHN 1
639
640
641
642static int
643ad1816_set_recmask (ad1816_info * devc, int mask)
644{
645 unsigned long flags;
646 unsigned char recdev;
647 int i, n;
648
649 spin_lock_irqsave(&devc->lock, flags);
650 mask &= devc->supported_rec_devices;
651
652 n = 0;
653 /* Count selected device bits */
654 for (i = 0; i < 32; i++)
655 if (mask & (1 << i))
656 n++;
657
658 if (n == 0)
659 mask = SOUND_MASK_MIC;
660 else if (n != 1) { /* Too many devices selected */
661 /* Filter out active settings */
662 mask &= ~devc->recmask;
663
664 n = 0;
665 /* Count selected device bits */
666 for (i = 0; i < 32; i++)
667 if (mask & (1 << i))
668 n++;
669
670 if (n != 1)
671 mask = SOUND_MASK_MIC;
672 }
673
674 switch (mask) {
675 case SOUND_MASK_MIC:
676 recdev = 5;
677 break;
678
679 case SOUND_MASK_LINE:
680 recdev = 0;
681 break;
682
683 case SOUND_MASK_CD:
684 recdev = 2;
685 break;
686
687 case SOUND_MASK_LINE1:
688 recdev = 4;
689 break;
690
691 case SOUND_MASK_LINE2:
692 recdev = 3;
693 break;
694
695 case SOUND_MASK_VOLUME:
696 recdev = 1;
697 break;
698
699 default:
700 mask = SOUND_MASK_MIC;
701 recdev = 5;
702 }
703
704 recdev <<= 4;
705 ad_write (devc, 20,
706 (ad_read (devc, 20) & 0x8f8f) | recdev | (recdev<<8));
707
708 devc->recmask = mask;
709 spin_unlock_irqrestore(&devc->lock, flags);
710 return mask;
711}
712
713static void
714change_bits (int *regval, int dev, int chn, int newval)
715{
716 unsigned char mask;
717 int shift;
718
719 /* Reverse polarity*/
720
721 if (mix_devices[dev][chn].polarity == 1)
722 newval = 100 - newval;
723
724 mask = (1 << mix_devices[dev][chn].nbits) - 1;
725 shift = mix_devices[dev][chn].bitpos;
726 /* Scale it */
727 newval = (int) ((newval * mask) + 50) / 100;
728 /* Clear bits */
729 *regval &= ~(mask << shift);
730 /* Set new value */
731 *regval |= (newval & mask) << shift;
732}
733
734static int
735ad1816_mixer_get (ad1816_info * devc, int dev)
736{
737 DEBUGNOISE(printk(KERN_DEBUG "ad1816: mixer_get called!\n"));
738
739 /* range check + supported mixer check */
740 if (dev < 0 || dev >= SOUND_MIXER_NRDEVICES )
741 return (-(EINVAL));
742 if (!((1 << dev) & devc->supported_devices))
743 return -(EINVAL);
744
745 return devc->levels[dev];
746}
747
748static int
749ad1816_mixer_set (ad1816_info * devc, int dev, int value)
750{
751 int left = value & 0x000000ff;
752 int right = (value & 0x0000ff00) >> 8;
753 int retvol;
754
755 int regoffs;
756 int val;
757 int valmute;
758 unsigned long flags;
759
760 DEBUGNOISE(printk(KERN_DEBUG "ad1816: mixer_set called!\n"));
761
762 if (dev < 0 || dev >= SOUND_MIXER_NRDEVICES )
763 return -(EINVAL);
764
765 if (left > 100)
766 left = 100;
767 if (left < 0)
768 left = 0;
769 if (right > 100)
770 right = 100;
771 if (right < 0)
772 right = 0;
773
774 /* Mono control */
775 if (mix_devices[dev][RIGHT_CHN].nbits == 0)
776 right = left;
777 retvol = left | (right << 8);
778
779 /* Scale it */
780
781 left = mix_cvt[left];
782 right = mix_cvt[right];
783
784 /* reject all mixers that are not supported */
785 if (!(devc->supported_devices & (1 << dev)))
786 return -(EINVAL);
787
788 /* sanity check */
789 if (mix_devices[dev][LEFT_CHN].nbits == 0)
790 return -(EINVAL);
791 spin_lock_irqsave(&devc->lock, flags);
792
793 /* keep precise volume internal */
794 devc->levels[dev] = retvol;
795
796 /* Set the left channel */
797 regoffs = mix_devices[dev][LEFT_CHN].regno;
798 val = ad_read (devc, regoffs);
799 change_bits (&val, dev, LEFT_CHN, left);
800
801 valmute=val;
802
803 /* Mute bit masking on some registers */
804 if ( regoffs==5 || regoffs==14 || regoffs==15 ||
805 regoffs==16 || regoffs==17 || regoffs==18 ||
806 regoffs==19 || regoffs==39) {
807 if (left==0)
808 valmute |= 0x8000;
809 else
810 valmute &= ~0x8000;
811 }
812 ad_write (devc, regoffs, valmute); /* mute */
813
814 /*
815 * Set the right channel
816 */
817
818 /* Was just a mono channel */
819 if (mix_devices[dev][RIGHT_CHN].nbits == 0) {
820 spin_unlock_irqrestore(&devc->lock, flags);
821 return retvol;
822 }
823
824 regoffs = mix_devices[dev][RIGHT_CHN].regno;
825 val = ad_read (devc, regoffs);
826 change_bits (&val, dev, RIGHT_CHN, right);
827
828 valmute=val;
829 if ( regoffs==5 || regoffs==14 || regoffs==15 ||
830 regoffs==16 || regoffs==17 || regoffs==18 ||
831 regoffs==19 || regoffs==39) {
832 if (right==0)
833 valmute |= 0x80;
834 else
835 valmute &= ~0x80;
836 }
837 ad_write (devc, regoffs, valmute); /* mute */
838 spin_unlock_irqrestore(&devc->lock, flags);
839 return retvol;
840}
841
842#define MIXER_DEVICES ( SOUND_MASK_VOLUME | \
843 SOUND_MASK_SYNTH | \
844 SOUND_MASK_PCM | \
845 SOUND_MASK_LINE | \
846 SOUND_MASK_LINE1 | \
847 SOUND_MASK_LINE2 | \
848 SOUND_MASK_LINE3 | \
849 SOUND_MASK_MIC | \
850 SOUND_MASK_CD | \
851 SOUND_MASK_RECLEV \
852 )
853#define REC_DEVICES ( SOUND_MASK_LINE2 |\
854 SOUND_MASK_LINE |\
855 SOUND_MASK_LINE1 |\
856 SOUND_MASK_MIC |\
857 SOUND_MASK_CD |\
858 SOUND_MASK_VOLUME \
859 )
860
861static void
862ad1816_mixer_reset (ad1816_info * devc)
863{
864 int i;
865
866 devc->supported_devices = MIXER_DEVICES;
867
868 devc->supported_rec_devices = REC_DEVICES;
869
870 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
871 if (devc->supported_devices & (1 << i))
872 ad1816_mixer_set (devc, i, default_mixer_levels[i]);
873 ad1816_set_recmask (devc, SOUND_MASK_MIC);
874}
875
876static int
877ad1816_mixer_ioctl (int dev, unsigned int cmd, void __user * arg)
878{
879 ad1816_info *devc = mixer_devs[dev]->devc;
880 int val;
881 int __user *p = arg;
882
883 DEBUGNOISE(printk(KERN_DEBUG "ad1816: mixer_ioctl called!\n"));
884
885 /* Mixer ioctl */
886 if (((cmd >> 8) & 0xff) == 'M') {
887
888 /* set ioctl */
889 if (_SIOC_DIR (cmd) & _SIOC_WRITE) {
890 switch (cmd & 0xff){
891 case SOUND_MIXER_RECSRC:
892
893 if (get_user(val, p))
894 return -EFAULT;
895 val=ad1816_set_recmask (devc, val);
896 return put_user(val, p);
897 break;
898
899 default:
900 if (get_user(val, p))
901 return -EFAULT;
902 if ((val=ad1816_mixer_set (devc, cmd & 0xff, val))<0)
903 return val;
904 else
905 return put_user(val, p);
906 }
907 } else {
908 /* read ioctl */
909 switch (cmd & 0xff) {
910
911 case SOUND_MIXER_RECSRC:
912 val=devc->recmask;
913 return put_user(val, p);
914 break;
915
916 case SOUND_MIXER_DEVMASK:
917 val=devc->supported_devices;
918 return put_user(val, p);
919 break;
920
921 case SOUND_MIXER_STEREODEVS:
922 val=devc->supported_devices & ~(SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
923 return put_user(val, p);
924 break;
925
926 case SOUND_MIXER_RECMASK:
927 val=devc->supported_rec_devices;
928 return put_user(val, p);
929 break;
930
931 case SOUND_MIXER_CAPS:
932 val=SOUND_CAP_EXCL_INPUT;
933 return put_user(val, p);
934 break;
935
936 default:
937 if ((val=ad1816_mixer_get (devc, cmd & 0xff))<0)
938 return val;
939 else
940 return put_user(val, p);
941 }
942 }
943 } else
944 /* not for mixer */
945 return -(EINVAL);
946}
947
948/* ------------------------------------------------------------------- */
949
950/* Mixer structure */
951
952static struct mixer_operations ad1816_mixer_operations = {
953 .owner = THIS_MODULE,
954 .id = "AD1816",
955 .name = "AD1816 Mixer",
956 .ioctl = ad1816_mixer_ioctl
957};
958
959
960/* ------------------------------------------------------------------- */
961
962/* stuff for card recognition, init and unloading PNP ...*/
963
964
965/* check if AD1816 present at specified hw_config and register device with OS
966 * return 1 if initialization was successful, 0 otherwise
967 */
968static int __init ad1816_init_card (struct address_info *hw_config,
969 struct pnp_dev *pnp)
970{
971 ad1816_info *devc = NULL;
972 int tmp;
973 int oss_devno = -1;
974
975 printk(KERN_INFO "ad1816: initializing card: io=0x%x, irq=%d, dma=%d, "
976 "dma2=%d, clockfreq=%d, options=%d isadmabug=%d "
977 "%s\n",
978 hw_config->io_base,
979 hw_config->irq,
980 hw_config->dma,
981 hw_config->dma2,
982 ad1816_clockfreq,
983 options,
984 isa_dma_bridge_buggy,
985 pnp?"(PNP)":"");
986
987 /* ad1816_info structure remaining ? */
988 if (nr_ad1816_devs >= MAX_AUDIO_DEV) {
989 printk(KERN_WARNING "ad1816: no more ad1816_info structures "
990 "left\n");
991 goto out;
992 }
993
994 devc = &dev_info[nr_ad1816_devs];
995 devc->base = hw_config->io_base;
996 devc->irq = hw_config->irq;
997 devc->dma_playback=hw_config->dma;
998 devc->dma_capture=hw_config->dma2;
999 devc->opened = 0;
1000 devc->pnpdev = pnp;
1001 spin_lock_init(&devc->lock);
1002
1003 if (!request_region(devc->base, 16, "AD1816 Sound")) {
1004 printk(KERN_WARNING "ad1816: I/O port 0x%03x not free\n",
1005 devc->base);
1006 goto out;
1007 }
1008
1009 printk(KERN_INFO "ad1816: Examining AD1816 at address 0x%03x.\n",
1010 devc->base);
1011
1012
1013 /* tests for ad1816 */
1014 /* base+0: bit 1 must be set but not 255 */
1015 tmp=inb(devc->base);
1016 if ( (tmp&0x80)==0 || tmp==255 ) {
1017 printk (KERN_INFO "ad1816: Chip is not an AD1816 or chip "
1018 "is not active (Test 0)\n");
1019 goto out_release_region;
1020 }
1021
1022 /* writes to ireg 8 are copied to ireg 9 */
1023 ad_write(devc,8,12345);
1024 if (ad_read(devc,9)!=12345) {
1025 printk(KERN_INFO "ad1816: Chip is not an AD1816 (Test 1)\n");
1026 goto out_release_region;
1027 }
1028
1029 /* writes to ireg 8 are copied to ireg 9 */
1030 ad_write(devc,8,54321);
1031 if (ad_read(devc,9)!=54321) {
1032 printk(KERN_INFO "ad1816: Chip is not an AD1816 (Test 2)\n");
1033 goto out_release_region;
1034 }
1035
1036 /* writes to ireg 10 are copied to ireg 11 */
1037 ad_write(devc,10,54321);
1038 if (ad_read(devc,11)!=54321) {
1039 printk (KERN_INFO "ad1816: Chip is not an AD1816 (Test 3)\n");
1040 goto out_release_region;
1041 }
1042
1043 /* writes to ireg 10 are copied to ireg 11 */
1044 ad_write(devc,10,12345);
1045 if (ad_read(devc,11)!=12345) {
1046 printk (KERN_INFO "ad1816: Chip is not an AD1816 (Test 4)\n");
1047 goto out_release_region;
1048 }
1049
1050 /* bit in base +1 cannot be set to 1 */
1051 tmp=inb(devc->base+1);
1052 outb(0xff,devc->base+1);
1053 if (inb(devc->base+1)!=tmp) {
1054 printk(KERN_INFO "ad1816: Chip is not an AD1816 (Test 5)\n");
1055 goto out_release_region;
1056 }
1057
1058 printk(KERN_INFO "ad1816: AD1816 (version %d) successfully detected!\n",
1059 ad_read(devc,45));
1060
1061 /* disable all interrupts */
1062 ad_write(devc,1,0);
1063
1064 /* Clear pending interrupts */
1065 outb (0, devc->base+1);
1066
1067 /* allocate irq */
1068 if (devc->irq < 0 || devc->irq > 15)
1069 goto out_release_region;
1070 if (request_irq(devc->irq, ad1816_interrupt,0,
1071 "SoundPort", devc) < 0) {
1072 printk(KERN_WARNING "ad1816: IRQ in use\n");
1073 goto out_release_region;
1074 }
1075
1076 /* DMA stuff */
1077 if (sound_alloc_dma (devc->dma_playback, "Sound System")) {
1078 printk(KERN_WARNING "ad1816: Can't allocate DMA%d\n",
1079 devc->dma_playback);
1080 goto out_free_irq;
1081 }
1082
1083 if ( devc->dma_capture >= 0 &&
1084 devc->dma_capture != devc->dma_playback) {
1085 if (sound_alloc_dma(devc->dma_capture,
1086 "Sound System (capture)")) {
1087 printk(KERN_WARNING "ad1816: Can't allocate DMA%d\n",
1088 devc->dma_capture);
1089 goto out_free_dma;
1090 }
1091 devc->audio_mode=DMA_AUTOMODE|DMA_DUPLEX;
1092 } else {
1093 printk(KERN_WARNING "ad1816: Only one DMA channel "
1094 "available/configured. No duplex operation possible\n");
1095 devc->audio_mode=DMA_AUTOMODE;
1096 }
1097
1098 conf_printf2 ("AD1816 audio driver",
1099 devc->base, devc->irq, devc->dma_playback,
1100 devc->dma_capture);
1101
1102 /* register device */
1103 if ((oss_devno = sound_install_audiodrv (AUDIO_DRIVER_VERSION,
1104 "AD1816 audio driver",
1105 &ad1816_audio_driver,
1106 sizeof (struct audio_driver),
1107 devc->audio_mode,
1108 ad_format_mask,
1109 devc,
1110 devc->dma_playback,
1111 devc->dma_capture)) < 0) {
1112 printk(KERN_WARNING "ad1816: Can't install sound driver\n");
1113 goto out_free_dma_2;
1114 }
1115
1116
1117 ad_write(devc,32,0x80f0); /* sound system mode */
1118 if (options&1) {
1119 ad_write(devc,33,0); /* disable all audiosources for dsp */
1120 } else {
1121 ad_write(devc,33,0x03f8); /* enable all audiosources for dsp */
1122 }
1123 ad_write(devc,4,0x8080); /* default values for volumes (muted)*/
1124 ad_write(devc,5,0x8080);
1125 ad_write(devc,6,0x8080);
1126 ad_write(devc,7,0x8080);
1127 ad_write(devc,15,0x8888);
1128 ad_write(devc,16,0x8888);
1129 ad_write(devc,17,0x8888);
1130 ad_write(devc,18,0x8888);
1131 ad_write(devc,19,0xc888); /* +20db mic active */
1132 ad_write(devc,14,0x0000); /* Master volume unmuted */
1133 ad_write(devc,39,0x009f); /* 3D effect on 0% phone out muted */
1134 ad_write(devc,44,0x0080); /* everything on power, 3d enabled for d/a */
1135 outb(0x10,devc->base+8); /* set dma mode */
1136 outb(0x10,devc->base+9);
1137
1138 /* enable capture + playback interrupt */
1139 ad_write(devc,1,0xc000);
1140
1141 /* set mixer defaults */
1142 ad1816_mixer_reset (devc);
1143
1144 /* register mixer */
1145 if ((audio_devs[oss_devno]->mixer_dev=sound_install_mixer(
1146 MIXER_DRIVER_VERSION,
1147 "AD1816 audio driver",
1148 &ad1816_mixer_operations,
1149 sizeof (struct mixer_operations),
1150 devc)) < 0) {
1151 printk(KERN_WARNING "Can't install mixer\n");
1152 }
1153 /* make ad1816_info active */
1154 nr_ad1816_devs++;
1155 printk(KERN_INFO "ad1816: card successfully installed!\n");
1156 return 1;
1157 /* error handling */
1158out_free_dma_2:
1159 if (devc->dma_capture >= 0 && devc->dma_capture != devc->dma_playback)
1160 sound_free_dma(devc->dma_capture);
1161out_free_dma:
1162 sound_free_dma(devc->dma_playback);
1163out_free_irq:
1164 free_irq(devc->irq, devc);
1165out_release_region:
1166 release_region(devc->base, 16);
1167out:
1168 return 0;
1169}
1170
1171static void __exit unload_card(ad1816_info *devc)
1172{
1173 int mixer, dev = 0;
1174
1175 if (devc != NULL) {
1176 printk("ad1816: Unloading card at address 0x%03x\n",devc->base);
1177
1178 dev = devc->dev_no;
1179 mixer = audio_devs[dev]->mixer_dev;
1180
1181 /* unreg mixer*/
1182 if(mixer>=0) {
1183 sound_unload_mixerdev(mixer);
1184 }
1185 /* unreg audiodev */
1186 sound_unload_audiodev(dev);
1187
1188 /* free dma channels */
1189 if (devc->dma_capture>=0 &&
1190 devc->dma_capture != devc->dma_playback) {
1191 sound_free_dma(devc->dma_capture);
1192 }
1193 sound_free_dma (devc->dma_playback);
1194 /* free irq */
1195 free_irq(devc->irq, devc);
1196 /* free io */
1197 release_region (devc->base, 16);
1198#ifdef __ISAPNP__
1199 if (devc->pnpdev) {
1200 pnp_disable_dev(devc->pnpdev);
1201 pnp_device_detach(devc->pnpdev);
1202 }
1203#endif
1204
1205 } else
1206 printk(KERN_WARNING "ad1816: no device/card specified\n");
1207}
1208
1209static int __initdata io = -1;
1210static int __initdata irq = -1;
1211static int __initdata dma = -1;
1212static int __initdata dma2 = -1;
1213
1214#ifdef __ISAPNP__
1215/* use isapnp for configuration */
1216static int isapnp = 1;
1217static int isapnpjump;
1218module_param(isapnp, bool, 0);
1219module_param(isapnpjump, int, 0);
1220#endif
1221
1222module_param(io, int, 0);
1223module_param(irq, int, 0);
1224module_param(dma, int, 0);
1225module_param(dma2, int, 0);
1226module_param(ad1816_clockfreq, int, 0);
1227module_param(options, int, 0);
1228
1229#ifdef __ISAPNP__
1230static struct {
1231 unsigned short card_vendor, card_device;
1232 unsigned short vendor;
1233 unsigned short function;
1234 struct ad1816_data *data;
1235} isapnp_ad1816_list[] __initdata = {
1236 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
1237 ISAPNP_VENDOR('A','D','S'), ISAPNP_FUNCTION(0x7150),
1238 NULL },
1239 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
1240 ISAPNP_VENDOR('A','D','S'), ISAPNP_FUNCTION(0x7180),
1241 NULL },
1242 {0}
1243};
1244
1245MODULE_DEVICE_TABLE(isapnp, isapnp_ad1816_list);
1246
1247
1248static void __init ad1816_config_pnp_card(struct pnp_card *card,
1249 unsigned short vendor,
1250 unsigned short function)
1251{
1252 struct address_info cfg;
1253 struct pnp_dev *card_dev = pnp_find_dev(card, vendor, function, NULL);
1254 if (!card_dev) return;
1255 if (pnp_device_attach(card_dev) < 0) {
1256 printk(KERN_WARNING "ad1816: Failed to attach PnP device\n");
1257 return;
1258 }
1259 if (pnp_activate_dev(card_dev) < 0) {
1260 printk(KERN_WARNING "ad1816: Failed to activate PnP device\n");
1261 pnp_device_detach(card_dev);
1262 return;
1263 }
1264 cfg.io_base = pnp_port_start(card_dev, 2);
1265 cfg.irq = pnp_irq(card_dev, 0);
1266 cfg.dma = pnp_irq(card_dev, 0);
1267 cfg.dma2 = pnp_irq(card_dev, 1);
1268 if (!ad1816_init_card(&cfg, card_dev)) {
1269 pnp_disable_dev(card_dev);
1270 pnp_device_detach(card_dev);
1271 }
1272}
1273
1274static void __init ad1816_config_pnp_cards(void)
1275{
1276 int nr_pnp_cfg;
1277 int i;
1278
1279 /* Count entries in isapnp_ad1816_list */
1280 for (nr_pnp_cfg = 0; isapnp_ad1816_list[nr_pnp_cfg].card_vendor != 0;
1281 nr_pnp_cfg++);
1282 /* Check and adjust isapnpjump */
1283 if( isapnpjump < 0 || isapnpjump >= nr_pnp_cfg) {
1284 printk(KERN_WARNING
1285 "ad1816: Valid range for isapnpjump is 0-%d. "
1286 "Adjusted to 0.\n", nr_pnp_cfg-1);
1287 isapnpjump = 0;
1288 }
1289 for (i = isapnpjump; isapnp_ad1816_list[i].card_vendor != 0; i++) {
1290 struct pnp_card *card = NULL;
1291 /* iterate over all pnp cards */
1292 while ((card = pnp_find_card(isapnp_ad1816_list[i].card_vendor,
1293 isapnp_ad1816_list[i].card_device, card)))
1294 ad1816_config_pnp_card(card,
1295 isapnp_ad1816_list[i].vendor,
1296 isapnp_ad1816_list[i].function);
1297 }
1298}
1299#endif
1300
1301/* module initialization */
1302static int __init init_ad1816(void)
1303{
1304 printk(KERN_INFO "ad1816: AD1816 sounddriver "
1305 "Copyright (C) 1998-2003 by Thorsten Knabe and "
1306 "others\n");
1307#ifdef AD1816_CLOCK
1308 /* set ad1816_clockfreq if set during compilation */
1309 ad1816_clockfreq=AD1816_CLOCK;
1310#endif
1311 if (ad1816_clockfreq<5000 || ad1816_clockfreq>100000) {
1312 ad1816_clockfreq=33000;
1313 }
1314
1315#ifdef __ISAPNP__
1316 /* configure PnP cards */
1317 if(isapnp) ad1816_config_pnp_cards();
1318#endif
1319 /* configure card by module params */
1320 if (io != -1 && irq != -1 && dma != -1) {
1321 struct address_info cfg;
1322 cfg.io_base = io;
1323 cfg.irq = irq;
1324 cfg.dma = dma;
1325 cfg.dma2 = dma2;
1326 ad1816_init_card(&cfg, NULL);
1327 }
1328 if (nr_ad1816_devs <= 0)
1329 return -ENODEV;
1330 return 0;
1331}
1332
1333/* module cleanup */
1334static void __exit cleanup_ad1816 (void)
1335{
1336 int i;
1337 ad1816_info *devc = NULL;
1338
1339 /* remove any soundcard */
1340 for (i = 0; i < nr_ad1816_devs; i++) {
1341 devc = &dev_info[i];
1342 unload_card(devc);
1343 }
1344 nr_ad1816_devs=0;
1345 printk(KERN_INFO "ad1816: driver unloaded!\n");
1346}
1347
1348module_init(init_ad1816);
1349module_exit(cleanup_ad1816);
1350
1351#ifndef MODULE
1352/* kernel command line parameter evaluation */
1353static int __init setup_ad1816(char *str)
1354{
1355 /* io, irq, dma, dma2 */
1356 int ints[5];
1357
1358 str = get_options(str, ARRAY_SIZE(ints), ints);
1359
1360 io = ints[1];
1361 irq = ints[2];
1362 dma = ints[3];
1363 dma2 = ints[4];
1364 return 1;
1365}
1366
1367__setup("ad1816=", setup_ad1816);
1368#endif
1369MODULE_LICENSE("GPL");
diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
new file mode 100644
index 000000000000..4384dac3f794
--- /dev/null
+++ b/sound/oss/ad1848.c
@@ -0,0 +1,3159 @@
1/*
2 * sound/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/config.h>
45#include <linux/init.h>
46#include <linux/interrupt.h>
47#include <linux/module.h>
48#include <linux/stddef.h>
49#include <linux/pm.h>
50#include <linux/isapnp.h>
51#include <linux/pnp.h>
52#include <linux/spinlock.h>
53
54#define DEB(x)
55#define DEB1(x)
56#include "sound_config.h"
57
58#include "ad1848.h"
59#include "ad1848_mixer.h"
60
61typedef struct
62{
63 spinlock_t lock;
64 int base;
65 int irq;
66 int dma1, dma2;
67 int dual_dma; /* 1, when two DMA channels allocated */
68 int subtype;
69 unsigned char MCE_bit;
70 unsigned char saved_regs[64]; /* Includes extended register space */
71 int debug_flag;
72
73 int audio_flags;
74 int record_dev, playback_dev;
75
76 int xfer_count;
77 int audio_mode;
78 int open_mode;
79 int intr_active;
80 char *chip_name, *name;
81 int model;
82#define MD_1848 1
83#define MD_4231 2
84#define MD_4231A 3
85#define MD_1845 4
86#define MD_4232 5
87#define MD_C930 6
88#define MD_IWAVE 7
89#define MD_4235 8 /* Crystal Audio CS4235 */
90#define MD_1845_SSCAPE 9 /* Ensoniq Soundscape PNP*/
91#define MD_4236 10 /* 4236 and higher */
92#define MD_42xB 11 /* CS 42xB */
93#define MD_4239 12 /* CS4239 */
94
95 /* Mixer parameters */
96 int recmask;
97 int supported_devices, orig_devices;
98 int supported_rec_devices, orig_rec_devices;
99 int *levels;
100 short mixer_reroute[32];
101 int dev_no;
102 volatile unsigned long timer_ticks;
103 int timer_running;
104 int irq_ok;
105 mixer_ents *mix_devices;
106 int mixer_output_port;
107
108 /* Power management */
109 struct pm_dev *pmdev;
110} ad1848_info;
111
112typedef struct ad1848_port_info
113{
114 int open_mode;
115 int speed;
116 unsigned char speed_bits;
117 int channels;
118 int audio_format;
119 unsigned char format_bits;
120}
121ad1848_port_info;
122
123static struct address_info cfg;
124static int nr_ad1848_devs;
125
126static int deskpro_xl;
127static int deskpro_m;
128static int soundpro;
129
130static volatile signed char irq2dev[17] = {
131 -1, -1, -1, -1, -1, -1, -1, -1,
132 -1, -1, -1, -1, -1, -1, -1, -1, -1
133};
134
135#ifndef EXCLUDE_TIMERS
136static int timer_installed = -1;
137#endif
138
139static int loaded;
140
141static int ad_format_mask[13 /*devc->model */ ] =
142{
143 0,
144 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW,
145 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
146 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
147 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW, /* AD1845 */
148 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
149 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
150 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
151 AFMT_U8 | AFMT_S16_LE /* CS4235 */,
152 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW /* Ensoniq Soundscape*/,
153 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
154 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
155 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM
156};
157
158static ad1848_info adev_info[MAX_AUDIO_DEV];
159
160#define io_Index_Addr(d) ((d)->base)
161#define io_Indexed_Data(d) ((d)->base+1)
162#define io_Status(d) ((d)->base+2)
163#define io_Polled_IO(d) ((d)->base+3)
164
165static struct {
166 unsigned char flags;
167#define CAP_F_TIMER 0x01
168} capabilities [10 /*devc->model */ ] = {
169 {0}
170 ,{0} /* MD_1848 */
171 ,{CAP_F_TIMER} /* MD_4231 */
172 ,{CAP_F_TIMER} /* MD_4231A */
173 ,{CAP_F_TIMER} /* MD_1845 */
174 ,{CAP_F_TIMER} /* MD_4232 */
175 ,{0} /* MD_C930 */
176 ,{CAP_F_TIMER} /* MD_IWAVE */
177 ,{0} /* MD_4235 */
178 ,{CAP_F_TIMER} /* MD_1845_SSCAPE */
179};
180
181#ifdef CONFIG_PNP
182static int isapnp = 1;
183static int isapnpjump;
184static int reverse;
185
186static int audio_activated;
187#else
188static int isapnp;
189#endif
190
191
192
193static int ad1848_open(int dev, int mode);
194static void ad1848_close(int dev);
195static void ad1848_output_block(int dev, unsigned long buf, int count, int intrflag);
196static void ad1848_start_input(int dev, unsigned long buf, int count, int intrflag);
197static int ad1848_prepare_for_output(int dev, int bsize, int bcount);
198static int ad1848_prepare_for_input(int dev, int bsize, int bcount);
199static void ad1848_halt(int dev);
200static void ad1848_halt_input(int dev);
201static void ad1848_halt_output(int dev);
202static void ad1848_trigger(int dev, int bits);
203static int ad1848_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data);
204
205#ifndef EXCLUDE_TIMERS
206static int ad1848_tmr_install(int dev);
207static void ad1848_tmr_reprogram(int dev);
208#endif
209
210static int ad_read(ad1848_info * devc, int reg)
211{
212 int x;
213 int timeout = 900000;
214
215 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
216 timeout--;
217
218 if(reg < 32)
219 {
220 outb(((unsigned char) (reg & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
221 x = inb(io_Indexed_Data(devc));
222 }
223 else
224 {
225 int xreg, xra;
226
227 xreg = (reg & 0xff) - 32;
228 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
229 outb(((unsigned char) (23 & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
230 outb(((unsigned char) (xra & 0xff)), io_Indexed_Data(devc));
231 x = inb(io_Indexed_Data(devc));
232 }
233
234 return x;
235}
236
237static void ad_write(ad1848_info * devc, int reg, int data)
238{
239 int timeout = 900000;
240
241 while (timeout > 0 && inb(devc->base) == 0x80) /* Are we initializing */
242 timeout--;
243
244 if(reg < 32)
245 {
246 outb(((unsigned char) (reg & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
247 outb(((unsigned char) (data & 0xff)), io_Indexed_Data(devc));
248 }
249 else
250 {
251 int xreg, xra;
252
253 xreg = (reg & 0xff) - 32;
254 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
255 outb(((unsigned char) (23 & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
256 outb(((unsigned char) (xra & 0xff)), io_Indexed_Data(devc));
257 outb((unsigned char) (data & 0xff), io_Indexed_Data(devc));
258 }
259}
260
261static void wait_for_calibration(ad1848_info * devc)
262{
263 int timeout = 0;
264
265 /*
266 * Wait until the auto calibration process has finished.
267 *
268 * 1) Wait until the chip becomes ready (reads don't return 0x80).
269 * 2) Wait until the ACI bit of I11 gets on and then off.
270 */
271
272 timeout = 100000;
273 while (timeout > 0 && inb(devc->base) == 0x80)
274 timeout--;
275 if (inb(devc->base) & 0x80)
276 printk(KERN_WARNING "ad1848: Auto calibration timed out(1).\n");
277
278 timeout = 100;
279 while (timeout > 0 && !(ad_read(devc, 11) & 0x20))
280 timeout--;
281 if (!(ad_read(devc, 11) & 0x20))
282 return;
283
284 timeout = 80000;
285 while (timeout > 0 && (ad_read(devc, 11) & 0x20))
286 timeout--;
287 if (ad_read(devc, 11) & 0x20)
288 if ( (devc->model != MD_1845) || (devc->model != MD_1845_SSCAPE))
289 printk(KERN_WARNING "ad1848: Auto calibration timed out(3).\n");
290}
291
292static void ad_mute(ad1848_info * devc)
293{
294 int i;
295 unsigned char prev;
296
297 /*
298 * Save old register settings and mute output channels
299 */
300
301 for (i = 6; i < 8; i++)
302 {
303 prev = devc->saved_regs[i] = ad_read(devc, i);
304 }
305
306}
307
308static void ad_unmute(ad1848_info * devc)
309{
310}
311
312static void ad_enter_MCE(ad1848_info * devc)
313{
314 int timeout = 1000;
315 unsigned short prev;
316
317 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
318 timeout--;
319
320 devc->MCE_bit = 0x40;
321 prev = inb(io_Index_Addr(devc));
322 if (prev & 0x40)
323 {
324 return;
325 }
326 outb((devc->MCE_bit), io_Index_Addr(devc));
327}
328
329static void ad_leave_MCE(ad1848_info * devc)
330{
331 unsigned char prev, acal;
332 int timeout = 1000;
333
334 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
335 timeout--;
336
337 acal = ad_read(devc, 9);
338
339 devc->MCE_bit = 0x00;
340 prev = inb(io_Index_Addr(devc));
341 outb((0x00), io_Index_Addr(devc)); /* Clear the MCE bit */
342
343 if ((prev & 0x40) == 0) /* Not in MCE mode */
344 {
345 return;
346 }
347 outb((0x00), io_Index_Addr(devc)); /* Clear the MCE bit */
348 if (acal & 0x08) /* Auto calibration is enabled */
349 wait_for_calibration(devc);
350}
351
352static int ad1848_set_recmask(ad1848_info * devc, int mask)
353{
354 unsigned char recdev;
355 int i, n;
356 unsigned long flags;
357
358 mask &= devc->supported_rec_devices;
359
360 /* Rename the mixer bits if necessary */
361 for (i = 0; i < 32; i++)
362 {
363 if (devc->mixer_reroute[i] != i)
364 {
365 if (mask & (1 << i))
366 {
367 mask &= ~(1 << i);
368 mask |= (1 << devc->mixer_reroute[i]);
369 }
370 }
371 }
372
373 n = 0;
374 for (i = 0; i < 32; i++) /* Count selected device bits */
375 if (mask & (1 << i))
376 n++;
377
378 spin_lock_irqsave(&devc->lock,flags);
379 if (!soundpro) {
380 if (n == 0)
381 mask = SOUND_MASK_MIC;
382 else if (n != 1) { /* Too many devices selected */
383 mask &= ~devc->recmask; /* Filter out active settings */
384
385 n = 0;
386 for (i = 0; i < 32; i++) /* Count selected device bits */
387 if (mask & (1 << i))
388 n++;
389
390 if (n != 1)
391 mask = SOUND_MASK_MIC;
392 }
393 switch (mask) {
394 case SOUND_MASK_MIC:
395 recdev = 2;
396 break;
397
398 case SOUND_MASK_LINE:
399 case SOUND_MASK_LINE3:
400 recdev = 0;
401 break;
402
403 case SOUND_MASK_CD:
404 case SOUND_MASK_LINE1:
405 recdev = 1;
406 break;
407
408 case SOUND_MASK_IMIX:
409 recdev = 3;
410 break;
411
412 default:
413 mask = SOUND_MASK_MIC;
414 recdev = 2;
415 }
416
417 recdev <<= 6;
418 ad_write(devc, 0, (ad_read(devc, 0) & 0x3f) | recdev);
419 ad_write(devc, 1, (ad_read(devc, 1) & 0x3f) | recdev);
420 } else { /* soundpro */
421 unsigned char val;
422 int set_rec_bit;
423 int j;
424
425 for (i = 0; i < 32; i++) { /* For each bit */
426 if ((devc->supported_rec_devices & (1 << i)) == 0)
427 continue; /* Device not supported */
428
429 for (j = LEFT_CHN; j <= RIGHT_CHN; j++) {
430 if (devc->mix_devices[i][j].nbits == 0) /* Inexistent channel */
431 continue;
432
433 /*
434 * This is tricky:
435 * set_rec_bit becomes 1 if the corresponding bit in mask is set
436 * then it gets flipped if the polarity is inverse
437 */
438 set_rec_bit = ((mask & (1 << i)) != 0) ^ devc->mix_devices[i][j].recpol;
439
440 val = ad_read(devc, devc->mix_devices[i][j].recreg);
441 val &= ~(1 << devc->mix_devices[i][j].recpos);
442 val |= (set_rec_bit << devc->mix_devices[i][j].recpos);
443 ad_write(devc, devc->mix_devices[i][j].recreg, val);
444 }
445 }
446 }
447 spin_unlock_irqrestore(&devc->lock,flags);
448
449 /* Rename the mixer bits back if necessary */
450 for (i = 0; i < 32; i++)
451 {
452 if (devc->mixer_reroute[i] != i)
453 {
454 if (mask & (1 << devc->mixer_reroute[i]))
455 {
456 mask &= ~(1 << devc->mixer_reroute[i]);
457 mask |= (1 << i);
458 }
459 }
460 }
461 devc->recmask = mask;
462 return mask;
463}
464
465static void change_bits(ad1848_info * devc, unsigned char *regval,
466 unsigned char *muteval, int dev, int chn, int newval)
467{
468 unsigned char mask;
469 int shift;
470 int mute;
471 int mutemask;
472 int set_mute_bit;
473
474 set_mute_bit = (newval == 0) ^ devc->mix_devices[dev][chn].mutepol;
475
476 if (devc->mix_devices[dev][chn].polarity == 1) /* Reverse */
477 newval = 100 - newval;
478
479 mask = (1 << devc->mix_devices[dev][chn].nbits) - 1;
480 shift = devc->mix_devices[dev][chn].bitpos;
481
482 if (devc->mix_devices[dev][chn].mutepos == 8)
483 { /* if there is no mute bit */
484 mute = 0; /* No mute bit; do nothing special */
485 mutemask = ~0; /* No mute bit; do nothing special */
486 }
487 else
488 {
489 mute = (set_mute_bit << devc->mix_devices[dev][chn].mutepos);
490 mutemask = ~(1 << devc->mix_devices[dev][chn].mutepos);
491 }
492
493 newval = (int) ((newval * mask) + 50) / 100; /* Scale it */
494 *regval &= ~(mask << shift); /* Clear bits */
495 *regval |= (newval & mask) << shift; /* Set new value */
496
497 *muteval &= mutemask;
498 *muteval |= mute;
499}
500
501static int ad1848_mixer_get(ad1848_info * devc, int dev)
502{
503 if (!((1 << dev) & devc->supported_devices))
504 return -EINVAL;
505
506 dev = devc->mixer_reroute[dev];
507
508 return devc->levels[dev];
509}
510
511static void ad1848_mixer_set_channel(ad1848_info *devc, int dev, int value, int channel)
512{
513 int regoffs, muteregoffs;
514 unsigned char val, muteval;
515 unsigned long flags;
516
517 regoffs = devc->mix_devices[dev][channel].regno;
518 muteregoffs = devc->mix_devices[dev][channel].mutereg;
519 val = ad_read(devc, regoffs);
520
521 if (muteregoffs != regoffs) {
522 muteval = ad_read(devc, muteregoffs);
523 change_bits(devc, &val, &muteval, dev, channel, value);
524 }
525 else
526 change_bits(devc, &val, &val, dev, channel, value);
527
528 spin_lock_irqsave(&devc->lock,flags);
529 ad_write(devc, regoffs, val);
530 devc->saved_regs[regoffs] = val;
531 if (muteregoffs != regoffs) {
532 ad_write(devc, muteregoffs, muteval);
533 devc->saved_regs[muteregoffs] = muteval;
534 }
535 spin_unlock_irqrestore(&devc->lock,flags);
536}
537
538static int ad1848_mixer_set(ad1848_info * devc, int dev, int value)
539{
540 int left = value & 0x000000ff;
541 int right = (value & 0x0000ff00) >> 8;
542 int retvol;
543
544 if (dev > 31)
545 return -EINVAL;
546
547 if (!(devc->supported_devices & (1 << dev)))
548 return -EINVAL;
549
550 dev = devc->mixer_reroute[dev];
551
552 if (devc->mix_devices[dev][LEFT_CHN].nbits == 0)
553 return -EINVAL;
554
555 if (left > 100)
556 left = 100;
557 if (right > 100)
558 right = 100;
559
560 if (devc->mix_devices[dev][RIGHT_CHN].nbits == 0) /* Mono control */
561 right = left;
562
563 retvol = left | (right << 8);
564
565 /* Scale volumes */
566 left = mix_cvt[left];
567 right = mix_cvt[right];
568
569 devc->levels[dev] = retvol;
570
571 /*
572 * Set the left channel
573 */
574 ad1848_mixer_set_channel(devc, dev, left, LEFT_CHN);
575
576 /*
577 * Set the right channel
578 */
579 if (devc->mix_devices[dev][RIGHT_CHN].nbits == 0)
580 goto out;
581 ad1848_mixer_set_channel(devc, dev, right, RIGHT_CHN);
582
583 out:
584 return retvol;
585}
586
587static void ad1848_mixer_reset(ad1848_info * devc)
588{
589 int i;
590 char name[32];
591 unsigned long flags;
592
593 devc->mix_devices = &(ad1848_mix_devices[0]);
594
595 sprintf(name, "%s_%d", devc->chip_name, nr_ad1848_devs);
596
597 for (i = 0; i < 32; i++)
598 devc->mixer_reroute[i] = i;
599
600 devc->supported_rec_devices = MODE1_REC_DEVICES;
601
602 switch (devc->model)
603 {
604 case MD_4231:
605 case MD_4231A:
606 case MD_1845:
607 case MD_1845_SSCAPE:
608 devc->supported_devices = MODE2_MIXER_DEVICES;
609 break;
610
611 case MD_C930:
612 devc->supported_devices = C930_MIXER_DEVICES;
613 devc->mix_devices = &(c930_mix_devices[0]);
614 break;
615
616 case MD_IWAVE:
617 devc->supported_devices = MODE3_MIXER_DEVICES;
618 devc->mix_devices = &(iwave_mix_devices[0]);
619 break;
620
621 case MD_42xB:
622 case MD_4239:
623 devc->mix_devices = &(cs42xb_mix_devices[0]);
624 devc->supported_devices = MODE3_MIXER_DEVICES;
625 break;
626 case MD_4232:
627 case MD_4235:
628 case MD_4236:
629 devc->supported_devices = MODE3_MIXER_DEVICES;
630 break;
631
632 case MD_1848:
633 if (soundpro) {
634 devc->supported_devices = SPRO_MIXER_DEVICES;
635 devc->supported_rec_devices = SPRO_REC_DEVICES;
636 devc->mix_devices = &(spro_mix_devices[0]);
637 break;
638 }
639
640 default:
641 devc->supported_devices = MODE1_MIXER_DEVICES;
642 }
643
644 devc->orig_devices = devc->supported_devices;
645 devc->orig_rec_devices = devc->supported_rec_devices;
646
647 devc->levels = load_mixer_volumes(name, default_mixer_levels, 1);
648
649 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
650 {
651 if (devc->supported_devices & (1 << i))
652 ad1848_mixer_set(devc, i, devc->levels[i]);
653 }
654
655 ad1848_set_recmask(devc, SOUND_MASK_MIC);
656
657 devc->mixer_output_port = devc->levels[31] | AUDIO_HEADPHONE | AUDIO_LINE_OUT;
658
659 spin_lock_irqsave(&devc->lock,flags);
660 if (!soundpro) {
661 if (devc->mixer_output_port & AUDIO_SPEAKER)
662 ad_write(devc, 26, ad_read(devc, 26) & ~0x40); /* Unmute mono out */
663 else
664 ad_write(devc, 26, ad_read(devc, 26) | 0x40); /* Mute mono out */
665 } else {
666 /*
667 * From the "wouldn't it be nice if the mixer API had (better)
668 * support for custom stuff" category
669 */
670 /* Enable surround mode and SB16 mixer */
671 ad_write(devc, 16, 0x60);
672 }
673 spin_unlock_irqrestore(&devc->lock,flags);
674}
675
676static int ad1848_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
677{
678 ad1848_info *devc = mixer_devs[dev]->devc;
679 int val;
680
681 if (cmd == SOUND_MIXER_PRIVATE1)
682 {
683 if (get_user(val, (int __user *)arg))
684 return -EFAULT;
685
686 if (val != 0xffff)
687 {
688 unsigned long flags;
689 val &= (AUDIO_SPEAKER | AUDIO_HEADPHONE | AUDIO_LINE_OUT);
690 devc->mixer_output_port = val;
691 val |= AUDIO_HEADPHONE | AUDIO_LINE_OUT; /* Always on */
692 devc->mixer_output_port = val;
693 spin_lock_irqsave(&devc->lock,flags);
694 if (val & AUDIO_SPEAKER)
695 ad_write(devc, 26, ad_read(devc, 26) & ~0x40); /* Unmute mono out */
696 else
697 ad_write(devc, 26, ad_read(devc, 26) | 0x40); /* Mute mono out */
698 spin_unlock_irqrestore(&devc->lock,flags);
699 }
700 val = devc->mixer_output_port;
701 return put_user(val, (int __user *)arg);
702 }
703 if (cmd == SOUND_MIXER_PRIVATE2)
704 {
705 if (get_user(val, (int __user *)arg))
706 return -EFAULT;
707 return(ad1848_control(AD1848_MIXER_REROUTE, val));
708 }
709 if (((cmd >> 8) & 0xff) == 'M')
710 {
711 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
712 {
713 switch (cmd & 0xff)
714 {
715 case SOUND_MIXER_RECSRC:
716 if (get_user(val, (int __user *)arg))
717 return -EFAULT;
718 val = ad1848_set_recmask(devc, val);
719 break;
720
721 default:
722 if (get_user(val, (int __user *)arg))
723 return -EFAULT;
724 val = ad1848_mixer_set(devc, cmd & 0xff, val);
725 break;
726 }
727 return put_user(val, (int __user *)arg);
728 }
729 else
730 {
731 switch (cmd & 0xff)
732 {
733 /*
734 * Return parameters
735 */
736
737 case SOUND_MIXER_RECSRC:
738 val = devc->recmask;
739 break;
740
741 case SOUND_MIXER_DEVMASK:
742 val = devc->supported_devices;
743 break;
744
745 case SOUND_MIXER_STEREODEVS:
746 val = devc->supported_devices;
747 if (devc->model != MD_C930)
748 val &= ~(SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
749 break;
750
751 case SOUND_MIXER_RECMASK:
752 val = devc->supported_rec_devices;
753 break;
754
755 case SOUND_MIXER_CAPS:
756 val=SOUND_CAP_EXCL_INPUT;
757 break;
758
759 default:
760 val = ad1848_mixer_get(devc, cmd & 0xff);
761 break;
762 }
763 return put_user(val, (int __user *)arg);
764 }
765 }
766 else
767 return -EINVAL;
768}
769
770static int ad1848_set_speed(int dev, int arg)
771{
772 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
773 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
774
775 /*
776 * The sampling speed is encoded in the least significant nibble of I8. The
777 * LSB selects the clock source (0=24.576 MHz, 1=16.9344 MHz) and other
778 * three bits select the divisor (indirectly):
779 *
780 * The available speeds are in the following table. Keep the speeds in
781 * the increasing order.
782 */
783 typedef struct
784 {
785 int speed;
786 unsigned char bits;
787 }
788 speed_struct;
789
790 static speed_struct speed_table[] =
791 {
792 {5510, (0 << 1) | 1},
793 {5510, (0 << 1) | 1},
794 {6620, (7 << 1) | 1},
795 {8000, (0 << 1) | 0},
796 {9600, (7 << 1) | 0},
797 {11025, (1 << 1) | 1},
798 {16000, (1 << 1) | 0},
799 {18900, (2 << 1) | 1},
800 {22050, (3 << 1) | 1},
801 {27420, (2 << 1) | 0},
802 {32000, (3 << 1) | 0},
803 {33075, (6 << 1) | 1},
804 {37800, (4 << 1) | 1},
805 {44100, (5 << 1) | 1},
806 {48000, (6 << 1) | 0}
807 };
808
809 int i, n, selected = -1;
810
811 n = sizeof(speed_table) / sizeof(speed_struct);
812
813 if (arg <= 0)
814 return portc->speed;
815
816 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE) /* AD1845 has different timer than others */
817 {
818 if (arg < 4000)
819 arg = 4000;
820 if (arg > 50000)
821 arg = 50000;
822
823 portc->speed = arg;
824 portc->speed_bits = speed_table[3].bits;
825 return portc->speed;
826 }
827 if (arg < speed_table[0].speed)
828 selected = 0;
829 if (arg > speed_table[n - 1].speed)
830 selected = n - 1;
831
832 for (i = 1 /*really */ ; selected == -1 && i < n; i++)
833 {
834 if (speed_table[i].speed == arg)
835 selected = i;
836 else if (speed_table[i].speed > arg)
837 {
838 int diff1, diff2;
839
840 diff1 = arg - speed_table[i - 1].speed;
841 diff2 = speed_table[i].speed - arg;
842
843 if (diff1 < diff2)
844 selected = i - 1;
845 else
846 selected = i;
847 }
848 }
849 if (selected == -1)
850 {
851 printk(KERN_WARNING "ad1848: Can't find speed???\n");
852 selected = 3;
853 }
854 portc->speed = speed_table[selected].speed;
855 portc->speed_bits = speed_table[selected].bits;
856 return portc->speed;
857}
858
859static short ad1848_set_channels(int dev, short arg)
860{
861 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
862
863 if (arg != 1 && arg != 2)
864 return portc->channels;
865
866 portc->channels = arg;
867 return arg;
868}
869
870static unsigned int ad1848_set_bits(int dev, unsigned int arg)
871{
872 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
873 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
874
875 static struct format_tbl
876 {
877 int format;
878 unsigned char bits;
879 }
880 format2bits[] =
881 {
882 {
883 0, 0
884 }
885 ,
886 {
887 AFMT_MU_LAW, 1
888 }
889 ,
890 {
891 AFMT_A_LAW, 3
892 }
893 ,
894 {
895 AFMT_IMA_ADPCM, 5
896 }
897 ,
898 {
899 AFMT_U8, 0
900 }
901 ,
902 {
903 AFMT_S16_LE, 2
904 }
905 ,
906 {
907 AFMT_S16_BE, 6
908 }
909 ,
910 {
911 AFMT_S8, 0
912 }
913 ,
914 {
915 AFMT_U16_LE, 0
916 }
917 ,
918 {
919 AFMT_U16_BE, 0
920 }
921 };
922 int i, n = sizeof(format2bits) / sizeof(struct format_tbl);
923
924 if (arg == 0)
925 return portc->audio_format;
926
927 if (!(arg & ad_format_mask[devc->model]))
928 arg = AFMT_U8;
929
930 portc->audio_format = arg;
931
932 for (i = 0; i < n; i++)
933 if (format2bits[i].format == arg)
934 {
935 if ((portc->format_bits = format2bits[i].bits) == 0)
936 return portc->audio_format = AFMT_U8; /* Was not supported */
937
938 return arg;
939 }
940 /* Still hanging here. Something must be terribly wrong */
941 portc->format_bits = 0;
942 return portc->audio_format = AFMT_U8;
943}
944
945static struct audio_driver ad1848_audio_driver =
946{
947 .owner = THIS_MODULE,
948 .open = ad1848_open,
949 .close = ad1848_close,
950 .output_block = ad1848_output_block,
951 .start_input = ad1848_start_input,
952 .prepare_for_input = ad1848_prepare_for_input,
953 .prepare_for_output = ad1848_prepare_for_output,
954 .halt_io = ad1848_halt,
955 .halt_input = ad1848_halt_input,
956 .halt_output = ad1848_halt_output,
957 .trigger = ad1848_trigger,
958 .set_speed = ad1848_set_speed,
959 .set_bits = ad1848_set_bits,
960 .set_channels = ad1848_set_channels
961};
962
963static struct mixer_operations ad1848_mixer_operations =
964{
965 .owner = THIS_MODULE,
966 .id = "SOUNDPORT",
967 .name = "AD1848/CS4248/CS4231",
968 .ioctl = ad1848_mixer_ioctl
969};
970
971static int ad1848_open(int dev, int mode)
972{
973 ad1848_info *devc;
974 ad1848_port_info *portc;
975 unsigned long flags;
976
977 if (dev < 0 || dev >= num_audiodevs)
978 return -ENXIO;
979
980 devc = (ad1848_info *) audio_devs[dev]->devc;
981 portc = (ad1848_port_info *) audio_devs[dev]->portc;
982
983 /* here we don't have to protect against intr */
984 spin_lock(&devc->lock);
985 if (portc->open_mode || (devc->open_mode & mode))
986 {
987 spin_unlock(&devc->lock);
988 return -EBUSY;
989 }
990 devc->dual_dma = 0;
991
992 if (audio_devs[dev]->flags & DMA_DUPLEX)
993 {
994 devc->dual_dma = 1;
995 }
996 devc->intr_active = 0;
997 devc->audio_mode = 0;
998 devc->open_mode |= mode;
999 portc->open_mode = mode;
1000 spin_unlock(&devc->lock);
1001 ad1848_trigger(dev, 0);
1002
1003 if (mode & OPEN_READ)
1004 devc->record_dev = dev;
1005 if (mode & OPEN_WRITE)
1006 devc->playback_dev = dev;
1007/*
1008 * Mute output until the playback really starts. This decreases clicking (hope so).
1009 */
1010 spin_lock_irqsave(&devc->lock,flags);
1011 ad_mute(devc);
1012 spin_unlock_irqrestore(&devc->lock,flags);
1013
1014 return 0;
1015}
1016
1017static void ad1848_close(int dev)
1018{
1019 unsigned long flags;
1020 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1021 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1022
1023 DEB(printk("ad1848_close(void)\n"));
1024
1025 devc->intr_active = 0;
1026 ad1848_halt(dev);
1027
1028 spin_lock_irqsave(&devc->lock,flags);
1029
1030 devc->audio_mode = 0;
1031 devc->open_mode &= ~portc->open_mode;
1032 portc->open_mode = 0;
1033
1034 ad_unmute(devc);
1035 spin_unlock_irqrestore(&devc->lock,flags);
1036}
1037
1038static void ad1848_output_block(int dev, unsigned long buf, int count, int intrflag)
1039{
1040 unsigned long flags, cnt;
1041 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1042 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1043
1044 cnt = count;
1045
1046 if (portc->audio_format == AFMT_IMA_ADPCM)
1047 {
1048 cnt /= 4;
1049 }
1050 else
1051 {
1052 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
1053 cnt >>= 1;
1054 }
1055 if (portc->channels > 1)
1056 cnt >>= 1;
1057 cnt--;
1058
1059 if ((devc->audio_mode & PCM_ENABLE_OUTPUT) && (audio_devs[dev]->flags & DMA_AUTOMODE) &&
1060 intrflag &&
1061 cnt == devc->xfer_count)
1062 {
1063 devc->audio_mode |= PCM_ENABLE_OUTPUT;
1064 devc->intr_active = 1;
1065 return; /*
1066 * Auto DMA mode on. No need to react
1067 */
1068 }
1069 spin_lock_irqsave(&devc->lock,flags);
1070
1071 ad_write(devc, 15, (unsigned char) (cnt & 0xff));
1072 ad_write(devc, 14, (unsigned char) ((cnt >> 8) & 0xff));
1073
1074 devc->xfer_count = cnt;
1075 devc->audio_mode |= PCM_ENABLE_OUTPUT;
1076 devc->intr_active = 1;
1077 spin_unlock_irqrestore(&devc->lock,flags);
1078}
1079
1080static void ad1848_start_input(int dev, unsigned long buf, int count, int intrflag)
1081{
1082 unsigned long flags, cnt;
1083 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1084 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1085
1086 cnt = count;
1087 if (portc->audio_format == AFMT_IMA_ADPCM)
1088 {
1089 cnt /= 4;
1090 }
1091 else
1092 {
1093 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
1094 cnt >>= 1;
1095 }
1096 if (portc->channels > 1)
1097 cnt >>= 1;
1098 cnt--;
1099
1100 if ((devc->audio_mode & PCM_ENABLE_INPUT) && (audio_devs[dev]->flags & DMA_AUTOMODE) &&
1101 intrflag &&
1102 cnt == devc->xfer_count)
1103 {
1104 devc->audio_mode |= PCM_ENABLE_INPUT;
1105 devc->intr_active = 1;
1106 return; /*
1107 * Auto DMA mode on. No need to react
1108 */
1109 }
1110 spin_lock_irqsave(&devc->lock,flags);
1111
1112 if (devc->model == MD_1848)
1113 {
1114 ad_write(devc, 15, (unsigned char) (cnt & 0xff));
1115 ad_write(devc, 14, (unsigned char) ((cnt >> 8) & 0xff));
1116 }
1117 else
1118 {
1119 ad_write(devc, 31, (unsigned char) (cnt & 0xff));
1120 ad_write(devc, 30, (unsigned char) ((cnt >> 8) & 0xff));
1121 }
1122
1123 ad_unmute(devc);
1124
1125 devc->xfer_count = cnt;
1126 devc->audio_mode |= PCM_ENABLE_INPUT;
1127 devc->intr_active = 1;
1128 spin_unlock_irqrestore(&devc->lock,flags);
1129}
1130
1131static int ad1848_prepare_for_output(int dev, int bsize, int bcount)
1132{
1133 int timeout;
1134 unsigned char fs, old_fs, tmp = 0;
1135 unsigned long flags;
1136 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1137 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1138
1139 ad_mute(devc);
1140
1141 spin_lock_irqsave(&devc->lock,flags);
1142 fs = portc->speed_bits | (portc->format_bits << 5);
1143
1144 if (portc->channels > 1)
1145 fs |= 0x10;
1146
1147 ad_enter_MCE(devc); /* Enables changes to the format select reg */
1148
1149 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE) /* Use alternate speed select registers */
1150 {
1151 fs &= 0xf0; /* Mask off the rate select bits */
1152
1153 ad_write(devc, 22, (portc->speed >> 8) & 0xff); /* Speed MSB */
1154 ad_write(devc, 23, portc->speed & 0xff); /* Speed LSB */
1155 }
1156 old_fs = ad_read(devc, 8);
1157
1158 if (devc->model == MD_4232 || devc->model >= MD_4236)
1159 {
1160 tmp = ad_read(devc, 16);
1161 ad_write(devc, 16, tmp | 0x30);
1162 }
1163 if (devc->model == MD_IWAVE)
1164 ad_write(devc, 17, 0xc2); /* Disable variable frequency select */
1165
1166 ad_write(devc, 8, fs);
1167
1168 /*
1169 * Write to I8 starts resynchronization. Wait until it completes.
1170 */
1171
1172 timeout = 0;
1173 while (timeout < 100 && inb(devc->base) != 0x80)
1174 timeout++;
1175 timeout = 0;
1176 while (timeout < 10000 && inb(devc->base) == 0x80)
1177 timeout++;
1178
1179 if (devc->model >= MD_4232)
1180 ad_write(devc, 16, tmp & ~0x30);
1181
1182 ad_leave_MCE(devc); /*
1183 * Starts the calibration process.
1184 */
1185 spin_unlock_irqrestore(&devc->lock,flags);
1186 devc->xfer_count = 0;
1187
1188#ifndef EXCLUDE_TIMERS
1189 if (dev == timer_installed && devc->timer_running)
1190 if ((fs & 0x01) != (old_fs & 0x01))
1191 {
1192 ad1848_tmr_reprogram(dev);
1193 }
1194#endif
1195 ad1848_halt_output(dev);
1196 return 0;
1197}
1198
1199static int ad1848_prepare_for_input(int dev, int bsize, int bcount)
1200{
1201 int timeout;
1202 unsigned char fs, old_fs, tmp = 0;
1203 unsigned long flags;
1204 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1205 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1206
1207 if (devc->audio_mode)
1208 return 0;
1209
1210 spin_lock_irqsave(&devc->lock,flags);
1211 fs = portc->speed_bits | (portc->format_bits << 5);
1212
1213 if (portc->channels > 1)
1214 fs |= 0x10;
1215
1216 ad_enter_MCE(devc); /* Enables changes to the format select reg */
1217
1218 if ((devc->model == MD_1845) || (devc->model == MD_1845_SSCAPE)) /* Use alternate speed select registers */
1219 {
1220 fs &= 0xf0; /* Mask off the rate select bits */
1221
1222 ad_write(devc, 22, (portc->speed >> 8) & 0xff); /* Speed MSB */
1223 ad_write(devc, 23, portc->speed & 0xff); /* Speed LSB */
1224 }
1225 if (devc->model == MD_4232)
1226 {
1227 tmp = ad_read(devc, 16);
1228 ad_write(devc, 16, tmp | 0x30);
1229 }
1230 if (devc->model == MD_IWAVE)
1231 ad_write(devc, 17, 0xc2); /* Disable variable frequency select */
1232
1233 /*
1234 * If mode >= 2 (CS4231), set I28. It's the capture format register.
1235 */
1236
1237 if (devc->model != MD_1848)
1238 {
1239 old_fs = ad_read(devc, 28);
1240 ad_write(devc, 28, fs);
1241
1242 /*
1243 * Write to I28 starts resynchronization. Wait until it completes.
1244 */
1245
1246 timeout = 0;
1247 while (timeout < 100 && inb(devc->base) != 0x80)
1248 timeout++;
1249
1250 timeout = 0;
1251 while (timeout < 10000 && inb(devc->base) == 0x80)
1252 timeout++;
1253
1254 if (devc->model != MD_1848 && devc->model != MD_1845 && devc->model != MD_1845_SSCAPE)
1255 {
1256 /*
1257 * CS4231 compatible devices don't have separate sampling rate selection
1258 * register for recording an playback. The I8 register is shared so we have to
1259 * set the speed encoding bits of it too.
1260 */
1261 unsigned char tmp = portc->speed_bits | (ad_read(devc, 8) & 0xf0);
1262
1263 ad_write(devc, 8, tmp);
1264 /*
1265 * Write to I8 starts resynchronization. Wait until it completes.
1266 */
1267 timeout = 0;
1268 while (timeout < 100 && inb(devc->base) != 0x80)
1269 timeout++;
1270
1271 timeout = 0;
1272 while (timeout < 10000 && inb(devc->base) == 0x80)
1273 timeout++;
1274 }
1275 }
1276 else
1277 { /* For AD1848 set I8. */
1278
1279 old_fs = ad_read(devc, 8);
1280 ad_write(devc, 8, fs);
1281 /*
1282 * Write to I8 starts resynchronization. Wait until it completes.
1283 */
1284 timeout = 0;
1285 while (timeout < 100 && inb(devc->base) != 0x80)
1286 timeout++;
1287 timeout = 0;
1288 while (timeout < 10000 && inb(devc->base) == 0x80)
1289 timeout++;
1290 }
1291
1292 if (devc->model == MD_4232)
1293 ad_write(devc, 16, tmp & ~0x30);
1294
1295 ad_leave_MCE(devc); /*
1296 * Starts the calibration process.
1297 */
1298 spin_unlock_irqrestore(&devc->lock,flags);
1299 devc->xfer_count = 0;
1300
1301#ifndef EXCLUDE_TIMERS
1302 if (dev == timer_installed && devc->timer_running)
1303 {
1304 if ((fs & 0x01) != (old_fs & 0x01))
1305 {
1306 ad1848_tmr_reprogram(dev);
1307 }
1308 }
1309#endif
1310 ad1848_halt_input(dev);
1311 return 0;
1312}
1313
1314static void ad1848_halt(int dev)
1315{
1316 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1317 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1318
1319 unsigned char bits = ad_read(devc, 9);
1320
1321 if (bits & 0x01 && (portc->open_mode & OPEN_WRITE))
1322 ad1848_halt_output(dev);
1323
1324 if (bits & 0x02 && (portc->open_mode & OPEN_READ))
1325 ad1848_halt_input(dev);
1326 devc->audio_mode = 0;
1327}
1328
1329static void ad1848_halt_input(int dev)
1330{
1331 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1332 unsigned long flags;
1333
1334 if (!(ad_read(devc, 9) & 0x02))
1335 return; /* Capture not enabled */
1336
1337 spin_lock_irqsave(&devc->lock,flags);
1338
1339 ad_mute(devc);
1340
1341 {
1342 int tmout;
1343
1344 if(!isa_dma_bridge_buggy)
1345 disable_dma(audio_devs[dev]->dmap_in->dma);
1346
1347 for (tmout = 0; tmout < 100000; tmout++)
1348 if (ad_read(devc, 11) & 0x10)
1349 break;
1350 ad_write(devc, 9, ad_read(devc, 9) & ~0x02); /* Stop capture */
1351
1352 if(!isa_dma_bridge_buggy)
1353 enable_dma(audio_devs[dev]->dmap_in->dma);
1354 devc->audio_mode &= ~PCM_ENABLE_INPUT;
1355 }
1356
1357 outb(0, io_Status(devc)); /* Clear interrupt status */
1358 outb(0, io_Status(devc)); /* Clear interrupt status */
1359
1360 devc->audio_mode &= ~PCM_ENABLE_INPUT;
1361
1362 spin_unlock_irqrestore(&devc->lock,flags);
1363}
1364
1365static void ad1848_halt_output(int dev)
1366{
1367 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1368 unsigned long flags;
1369
1370 if (!(ad_read(devc, 9) & 0x01))
1371 return; /* Playback not enabled */
1372
1373 spin_lock_irqsave(&devc->lock,flags);
1374
1375 ad_mute(devc);
1376 {
1377 int tmout;
1378
1379 if(!isa_dma_bridge_buggy)
1380 disable_dma(audio_devs[dev]->dmap_out->dma);
1381
1382 for (tmout = 0; tmout < 100000; tmout++)
1383 if (ad_read(devc, 11) & 0x10)
1384 break;
1385 ad_write(devc, 9, ad_read(devc, 9) & ~0x01); /* Stop playback */
1386
1387 if(!isa_dma_bridge_buggy)
1388 enable_dma(audio_devs[dev]->dmap_out->dma);
1389
1390 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1391 }
1392
1393 outb((0), io_Status(devc)); /* Clear interrupt status */
1394 outb((0), io_Status(devc)); /* Clear interrupt status */
1395
1396 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1397
1398 spin_unlock_irqrestore(&devc->lock,flags);
1399}
1400
1401static void ad1848_trigger(int dev, int state)
1402{
1403 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1404 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1405 unsigned long flags;
1406 unsigned char tmp, old;
1407
1408 spin_lock_irqsave(&devc->lock,flags);
1409 state &= devc->audio_mode;
1410
1411 tmp = old = ad_read(devc, 9);
1412
1413 if (portc->open_mode & OPEN_READ)
1414 {
1415 if (state & PCM_ENABLE_INPUT)
1416 tmp |= 0x02;
1417 else
1418 tmp &= ~0x02;
1419 }
1420 if (portc->open_mode & OPEN_WRITE)
1421 {
1422 if (state & PCM_ENABLE_OUTPUT)
1423 tmp |= 0x01;
1424 else
1425 tmp &= ~0x01;
1426 }
1427 /* ad_mute(devc); */
1428 if (tmp != old)
1429 {
1430 ad_write(devc, 9, tmp);
1431 ad_unmute(devc);
1432 }
1433 spin_unlock_irqrestore(&devc->lock,flags);
1434}
1435
1436static void ad1848_init_hw(ad1848_info * devc)
1437{
1438 int i;
1439 int *init_values;
1440
1441 /*
1442 * Initial values for the indirect registers of CS4248/AD1848.
1443 */
1444 static int init_values_a[] =
1445 {
1446 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1447 0x00, 0x0c, 0x02, 0x00, 0x8a, 0x01, 0x00, 0x00,
1448
1449 /* Positions 16 to 31 just for CS4231/2 and ad1845 */
1450 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1451 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1452 };
1453
1454 static int init_values_b[] =
1455 {
1456 /*
1457 Values for the newer chips
1458 Some of the register initialization values were changed. In
1459 order to get rid of the click that preceded PCM playback,
1460 calibration was disabled on the 10th byte. On that same byte,
1461 dual DMA was enabled; on the 11th byte, ADC dithering was
1462 enabled, since that is theoretically desirable; on the 13th
1463 byte, Mode 3 was selected, to enable access to extended
1464 registers.
1465 */
1466 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1467 0x00, 0x00, 0x06, 0x00, 0xe0, 0x01, 0x00, 0x00,
1468 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1469 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1470 };
1471
1472 /*
1473 * Select initialisation data
1474 */
1475
1476 init_values = init_values_a;
1477 if(devc->model >= MD_4236)
1478 init_values = init_values_b;
1479
1480 for (i = 0; i < 16; i++)
1481 ad_write(devc, i, init_values[i]);
1482
1483
1484 ad_mute(devc); /* Initialize some variables */
1485 ad_unmute(devc); /* Leave it unmuted now */
1486
1487 if (devc->model > MD_1848)
1488 {
1489 if (devc->model == MD_1845_SSCAPE)
1490 ad_write(devc, 12, ad_read(devc, 12) | 0x50);
1491 else
1492 ad_write(devc, 12, ad_read(devc, 12) | 0x40); /* Mode2 = enabled */
1493
1494 if (devc->model == MD_IWAVE)
1495 ad_write(devc, 12, 0x6c); /* Select codec mode 3 */
1496
1497 if (devc->model != MD_1845_SSCAPE)
1498 for (i = 16; i < 32; i++)
1499 ad_write(devc, i, init_values[i]);
1500
1501 if (devc->model == MD_IWAVE)
1502 ad_write(devc, 16, 0x30); /* Playback and capture counters enabled */
1503 }
1504 if (devc->model > MD_1848)
1505 {
1506 if (devc->audio_flags & DMA_DUPLEX)
1507 ad_write(devc, 9, ad_read(devc, 9) & ~0x04); /* Dual DMA mode */
1508 else
1509 ad_write(devc, 9, ad_read(devc, 9) | 0x04); /* Single DMA mode */
1510
1511 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE)
1512 ad_write(devc, 27, ad_read(devc, 27) | 0x08); /* Alternate freq select enabled */
1513
1514 if (devc->model == MD_IWAVE)
1515 { /* Some magic Interwave specific initialization */
1516 ad_write(devc, 12, 0x6c); /* Select codec mode 3 */
1517 ad_write(devc, 16, 0x30); /* Playback and capture counters enabled */
1518 ad_write(devc, 17, 0xc2); /* Alternate feature enable */
1519 }
1520 }
1521 else
1522 {
1523 devc->audio_flags &= ~DMA_DUPLEX;
1524 ad_write(devc, 9, ad_read(devc, 9) | 0x04); /* Single DMA mode */
1525 if (soundpro)
1526 ad_write(devc, 12, ad_read(devc, 12) | 0x40); /* Mode2 = enabled */
1527 }
1528
1529 outb((0), io_Status(devc)); /* Clear pending interrupts */
1530
1531 /*
1532 * Toggle the MCE bit. It completes the initialization phase.
1533 */
1534
1535 ad_enter_MCE(devc); /* In case the bit was off */
1536 ad_leave_MCE(devc);
1537
1538 ad1848_mixer_reset(devc);
1539}
1540
1541int ad1848_detect(struct resource *ports, int *ad_flags, int *osp)
1542{
1543 unsigned char tmp;
1544 ad1848_info *devc = &adev_info[nr_ad1848_devs];
1545 unsigned char tmp1 = 0xff, tmp2 = 0xff;
1546 int optiC930 = 0; /* OPTi 82C930 flag */
1547 int interwave = 0;
1548 int ad1847_flag = 0;
1549 int cs4248_flag = 0;
1550 int sscape_flag = 0;
1551 int io_base = ports->start;
1552
1553 int i;
1554
1555 DDB(printk("ad1848_detect(%x)\n", io_base));
1556
1557 if (ad_flags)
1558 {
1559 if (*ad_flags == 0x12345678)
1560 {
1561 interwave = 1;
1562 *ad_flags = 0;
1563 }
1564
1565 if (*ad_flags == 0x87654321)
1566 {
1567 sscape_flag = 1;
1568 *ad_flags = 0;
1569 }
1570
1571 if (*ad_flags == 0x12345677)
1572 {
1573 cs4248_flag = 1;
1574 *ad_flags = 0;
1575 }
1576 }
1577 if (nr_ad1848_devs >= MAX_AUDIO_DEV)
1578 {
1579 printk(KERN_ERR "ad1848 - Too many audio devices\n");
1580 return 0;
1581 }
1582 spin_lock_init(&devc->lock);
1583 devc->base = io_base;
1584 devc->irq_ok = 0;
1585 devc->timer_running = 0;
1586 devc->MCE_bit = 0x40;
1587 devc->irq = 0;
1588 devc->open_mode = 0;
1589 devc->chip_name = devc->name = "AD1848";
1590 devc->model = MD_1848; /* AD1848 or CS4248 */
1591 devc->levels = NULL;
1592 devc->debug_flag = 0;
1593
1594 /*
1595 * Check that the I/O address is in use.
1596 *
1597 * The bit 0x80 of the base I/O port is known to be 0 after the
1598 * chip has performed its power on initialization. Just assume
1599 * this has happened before the OS is starting.
1600 *
1601 * If the I/O address is unused, it typically returns 0xff.
1602 */
1603
1604 if (inb(devc->base) == 0xff)
1605 {
1606 DDB(printk("ad1848_detect: The base I/O address appears to be dead\n"));
1607 }
1608
1609 /*
1610 * Wait for the device to stop initialization
1611 */
1612
1613 DDB(printk("ad1848_detect() - step 0\n"));
1614
1615 for (i = 0; i < 10000000; i++)
1616 {
1617 unsigned char x = inb(devc->base);
1618
1619 if (x == 0xff || !(x & 0x80))
1620 break;
1621 }
1622
1623 DDB(printk("ad1848_detect() - step A\n"));
1624
1625 if (inb(devc->base) == 0x80) /* Not ready. Let's wait */
1626 ad_leave_MCE(devc);
1627
1628 if ((inb(devc->base) & 0x80) != 0x00) /* Not a AD1848 */
1629 {
1630 DDB(printk("ad1848 detect error - step A (%02x)\n", (int) inb(devc->base)));
1631 return 0;
1632 }
1633
1634 /*
1635 * Test if it's possible to change contents of the indirect registers.
1636 * Registers 0 and 1 are ADC volume registers. The bit 0x10 is read only
1637 * so try to avoid using it.
1638 */
1639
1640 DDB(printk("ad1848_detect() - step B\n"));
1641 ad_write(devc, 0, 0xaa);
1642 ad_write(devc, 1, 0x45); /* 0x55 with bit 0x10 clear */
1643
1644 if ((tmp1 = ad_read(devc, 0)) != 0xaa || (tmp2 = ad_read(devc, 1)) != 0x45)
1645 {
1646 if (tmp2 == 0x65) /* AD1847 has couple of bits hardcoded to 1 */
1647 ad1847_flag = 1;
1648 else
1649 {
1650 DDB(printk("ad1848 detect error - step B (%x/%x)\n", tmp1, tmp2));
1651 return 0;
1652 }
1653 }
1654 DDB(printk("ad1848_detect() - step C\n"));
1655 ad_write(devc, 0, 0x45);
1656 ad_write(devc, 1, 0xaa);
1657
1658 if ((tmp1 = ad_read(devc, 0)) != 0x45 || (tmp2 = ad_read(devc, 1)) != 0xaa)
1659 {
1660 if (tmp2 == 0x8a) /* AD1847 has few bits hardcoded to 1 */
1661 ad1847_flag = 1;
1662 else
1663 {
1664 DDB(printk("ad1848 detect error - step C (%x/%x)\n", tmp1, tmp2));
1665 return 0;
1666 }
1667 }
1668
1669 /*
1670 * The indirect register I12 has some read only bits. Let's
1671 * try to change them.
1672 */
1673
1674 DDB(printk("ad1848_detect() - step D\n"));
1675 tmp = ad_read(devc, 12);
1676 ad_write(devc, 12, (~tmp) & 0x0f);
1677
1678 if ((tmp & 0x0f) != ((tmp1 = ad_read(devc, 12)) & 0x0f))
1679 {
1680 DDB(printk("ad1848 detect error - step D (%x)\n", tmp1));
1681 return 0;
1682 }
1683
1684 /*
1685 * NOTE! Last 4 bits of the reg I12 tell the chip revision.
1686 * 0x01=RevB and 0x0A=RevC.
1687 */
1688
1689 /*
1690 * The original AD1848/CS4248 has just 15 indirect registers. This means
1691 * that I0 and I16 should return the same value (etc.).
1692 * However this doesn't work with CS4248. Actually it seems to be impossible
1693 * to detect if the chip is a CS4231 or CS4248.
1694 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test fails
1695 * with CS4231.
1696 */
1697
1698 /*
1699 * OPTi 82C930 has mode2 control bit in another place. This test will fail
1700 * with it. Accept this situation as a possible indication of this chip.
1701 */
1702
1703 DDB(printk("ad1848_detect() - step F\n"));
1704 ad_write(devc, 12, 0); /* Mode2=disabled */
1705
1706 for (i = 0; i < 16; i++)
1707 {
1708 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16)))
1709 {
1710 DDB(printk("ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i, tmp1, tmp2));
1711 if (!ad1847_flag)
1712 optiC930 = 1;
1713 break;
1714 }
1715 }
1716
1717 /*
1718 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit (0x40).
1719 * The bit 0x80 is always 1 in CS4248 and CS4231.
1720 */
1721
1722 DDB(printk("ad1848_detect() - step G\n"));
1723
1724 if (ad_flags && *ad_flags == 400)
1725 *ad_flags = 0;
1726 else
1727 ad_write(devc, 12, 0x40); /* Set mode2, clear 0x80 */
1728
1729
1730 if (ad_flags)
1731 *ad_flags = 0;
1732
1733 tmp1 = ad_read(devc, 12);
1734 if (tmp1 & 0x80)
1735 {
1736 if (ad_flags)
1737 *ad_flags |= AD_F_CS4248;
1738
1739 devc->chip_name = "CS4248"; /* Our best knowledge just now */
1740 }
1741 if (optiC930 || (tmp1 & 0xc0) == (0x80 | 0x40))
1742 {
1743 /*
1744 * CS4231 detected - is it?
1745 *
1746 * Verify that setting I0 doesn't change I16.
1747 */
1748
1749 DDB(printk("ad1848_detect() - step H\n"));
1750 ad_write(devc, 16, 0); /* Set I16 to known value */
1751
1752 ad_write(devc, 0, 0x45);
1753 if ((tmp1 = ad_read(devc, 16)) != 0x45) /* No change -> CS4231? */
1754 {
1755 ad_write(devc, 0, 0xaa);
1756 if ((tmp1 = ad_read(devc, 16)) == 0xaa) /* Rotten bits? */
1757 {
1758 DDB(printk("ad1848 detect error - step H(%x)\n", tmp1));
1759 return 0;
1760 }
1761
1762 /*
1763 * Verify that some bits of I25 are read only.
1764 */
1765
1766 DDB(printk("ad1848_detect() - step I\n"));
1767 tmp1 = ad_read(devc, 25); /* Original bits */
1768 ad_write(devc, 25, ~tmp1); /* Invert all bits */
1769 if ((ad_read(devc, 25) & 0xe7) == (tmp1 & 0xe7))
1770 {
1771 int id;
1772
1773 /*
1774 * It's at least CS4231
1775 */
1776
1777 devc->chip_name = "CS4231";
1778 devc->model = MD_4231;
1779
1780 /*
1781 * It could be an AD1845 or CS4231A as well.
1782 * CS4231 and AD1845 report the same revision info in I25
1783 * while the CS4231A reports different.
1784 */
1785
1786 id = ad_read(devc, 25);
1787 if ((id & 0xe7) == 0x80) /* Device busy??? */
1788 id = ad_read(devc, 25);
1789 if ((id & 0xe7) == 0x80) /* Device still busy??? */
1790 id = ad_read(devc, 25);
1791 DDB(printk("ad1848_detect() - step J (%02x/%02x)\n", id, ad_read(devc, 25)));
1792
1793 if ((id & 0xe7) == 0x80) {
1794 /*
1795 * It must be a CS4231 or AD1845. The register I23 of
1796 * CS4231 is undefined and it appears to be read only.
1797 * AD1845 uses I23 for setting sample rate. Assume
1798 * the chip is AD1845 if I23 is changeable.
1799 */
1800
1801 unsigned char tmp = ad_read(devc, 23);
1802 ad_write(devc, 23, ~tmp);
1803
1804 if (interwave)
1805 {
1806 devc->model = MD_IWAVE;
1807 devc->chip_name = "IWave";
1808 }
1809 else if (ad_read(devc, 23) != tmp) /* AD1845 ? */
1810 {
1811 devc->chip_name = "AD1845";
1812 devc->model = MD_1845;
1813 }
1814 else if (cs4248_flag)
1815 {
1816 if (ad_flags)
1817 *ad_flags |= AD_F_CS4248;
1818 devc->chip_name = "CS4248";
1819 devc->model = MD_1848;
1820 ad_write(devc, 12, ad_read(devc, 12) & ~0x40); /* Mode2 off */
1821 }
1822 ad_write(devc, 23, tmp); /* Restore */
1823 }
1824 else
1825 {
1826 switch (id & 0x1f) {
1827 case 3: /* CS4236/CS4235/CS42xB/CS4239 */
1828 {
1829 int xid;
1830 ad_write(devc, 12, ad_read(devc, 12) | 0x60); /* switch to mode 3 */
1831 ad_write(devc, 23, 0x9c); /* select extended register 25 */
1832 xid = inb(io_Indexed_Data(devc));
1833 ad_write(devc, 12, ad_read(devc, 12) & ~0x60); /* back to mode 0 */
1834 switch (xid & 0x1f)
1835 {
1836 case 0x00:
1837 devc->chip_name = "CS4237B(B)";
1838 devc->model = MD_42xB;
1839 break;
1840 case 0x08:
1841 /* Seems to be a 4238 ?? */
1842 devc->chip_name = "CS4238";
1843 devc->model = MD_42xB;
1844 break;
1845 case 0x09:
1846 devc->chip_name = "CS4238B";
1847 devc->model = MD_42xB;
1848 break;
1849 case 0x0b:
1850 devc->chip_name = "CS4236B";
1851 devc->model = MD_4236;
1852 break;
1853 case 0x10:
1854 devc->chip_name = "CS4237B";
1855 devc->model = MD_42xB;
1856 break;
1857 case 0x1d:
1858 devc->chip_name = "CS4235";
1859 devc->model = MD_4235;
1860 break;
1861 case 0x1e:
1862 devc->chip_name = "CS4239";
1863 devc->model = MD_4239;
1864 break;
1865 default:
1866 printk("Chip ident is %X.\n", xid&0x1F);
1867 devc->chip_name = "CS42xx";
1868 devc->model = MD_4232;
1869 break;
1870 }
1871 }
1872 break;
1873
1874 case 2: /* CS4232/CS4232A */
1875 devc->chip_name = "CS4232";
1876 devc->model = MD_4232;
1877 break;
1878
1879 case 0:
1880 if ((id & 0xe0) == 0xa0)
1881 {
1882 devc->chip_name = "CS4231A";
1883 devc->model = MD_4231A;
1884 }
1885 else
1886 {
1887 devc->chip_name = "CS4321";
1888 devc->model = MD_4231;
1889 }
1890 break;
1891
1892 default: /* maybe */
1893 DDB(printk("ad1848: I25 = %02x/%02x\n", ad_read(devc, 25), ad_read(devc, 25) & 0xe7));
1894 if (optiC930)
1895 {
1896 devc->chip_name = "82C930";
1897 devc->model = MD_C930;
1898 }
1899 else
1900 {
1901 devc->chip_name = "CS4231";
1902 devc->model = MD_4231;
1903 }
1904 }
1905 }
1906 }
1907 ad_write(devc, 25, tmp1); /* Restore bits */
1908
1909 DDB(printk("ad1848_detect() - step K\n"));
1910 }
1911 } else if (tmp1 == 0x0a) {
1912 /*
1913 * Is it perhaps a SoundPro CMI8330?
1914 * If so, then we should be able to change indirect registers
1915 * greater than I15 after activating MODE2, even though reading
1916 * back I12 does not show it.
1917 */
1918
1919 /*
1920 * Let's try comparing register values
1921 */
1922 for (i = 0; i < 16; i++) {
1923 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16))) {
1924 DDB(printk("ad1848 detect step H(%d/%x/%x) - SoundPro chip?\n", i, tmp1, tmp2));
1925 soundpro = 1;
1926 devc->chip_name = "SoundPro CMI 8330";
1927 break;
1928 }
1929 }
1930 }
1931
1932 DDB(printk("ad1848_detect() - step L\n"));
1933 if (ad_flags)
1934 {
1935 if (devc->model != MD_1848)
1936 *ad_flags |= AD_F_CS4231;
1937 }
1938 DDB(printk("ad1848_detect() - Detected OK\n"));
1939
1940 if (devc->model == MD_1848 && ad1847_flag)
1941 devc->chip_name = "AD1847";
1942
1943
1944 if (sscape_flag == 1)
1945 devc->model = MD_1845_SSCAPE;
1946
1947 return 1;
1948}
1949
1950int ad1848_init (char *name, struct resource *ports, int irq, int dma_playback,
1951 int dma_capture, int share_dma, int *osp, struct module *owner)
1952{
1953 /*
1954 * NOTE! If irq < 0, there is another driver which has allocated the IRQ
1955 * so that this driver doesn't need to allocate/deallocate it.
1956 * The actually used IRQ is ABS(irq).
1957 */
1958
1959 int my_dev;
1960 char dev_name[100];
1961 int e;
1962
1963 ad1848_info *devc = &adev_info[nr_ad1848_devs];
1964
1965 ad1848_port_info *portc = NULL;
1966
1967 devc->irq = (irq > 0) ? irq : 0;
1968 devc->open_mode = 0;
1969 devc->timer_ticks = 0;
1970 devc->dma1 = dma_playback;
1971 devc->dma2 = dma_capture;
1972 devc->subtype = cfg.card_subtype;
1973 devc->audio_flags = DMA_AUTOMODE;
1974 devc->playback_dev = devc->record_dev = 0;
1975 if (name != NULL)
1976 devc->name = name;
1977
1978 if (name != NULL && name[0] != 0)
1979 sprintf(dev_name,
1980 "%s (%s)", name, devc->chip_name);
1981 else
1982 sprintf(dev_name,
1983 "Generic audio codec (%s)", devc->chip_name);
1984
1985 rename_region(ports, devc->name);
1986
1987 conf_printf2(dev_name, devc->base, devc->irq, dma_playback, dma_capture);
1988
1989 if (devc->model == MD_1848 || devc->model == MD_C930)
1990 devc->audio_flags |= DMA_HARDSTOP;
1991
1992 if (devc->model > MD_1848)
1993 {
1994 if (devc->dma1 == devc->dma2 || devc->dma2 == -1 || devc->dma1 == -1)
1995 devc->audio_flags &= ~DMA_DUPLEX;
1996 else
1997 devc->audio_flags |= DMA_DUPLEX;
1998 }
1999
2000 portc = (ad1848_port_info *) kmalloc(sizeof(ad1848_port_info), GFP_KERNEL);
2001 if(portc==NULL) {
2002 release_region(devc->base, 4);
2003 return -1;
2004 }
2005
2006 if ((my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
2007 dev_name,
2008 &ad1848_audio_driver,
2009 sizeof(struct audio_driver),
2010 devc->audio_flags,
2011 ad_format_mask[devc->model],
2012 devc,
2013 dma_playback,
2014 dma_capture)) < 0)
2015 {
2016 release_region(devc->base, 4);
2017 kfree(portc);
2018 return -1;
2019 }
2020
2021 audio_devs[my_dev]->portc = portc;
2022 audio_devs[my_dev]->mixer_dev = -1;
2023 if (owner)
2024 audio_devs[my_dev]->d->owner = owner;
2025 memset((char *) portc, 0, sizeof(*portc));
2026
2027 nr_ad1848_devs++;
2028
2029 devc->pmdev = pm_register(PM_ISA_DEV, my_dev, ad1848_pm_callback);
2030 if (devc->pmdev)
2031 devc->pmdev->data = devc;
2032
2033 ad1848_init_hw(devc);
2034
2035 if (irq > 0)
2036 {
2037 devc->dev_no = my_dev;
2038 if (request_irq(devc->irq, adintr, 0, devc->name, (void *)my_dev) < 0)
2039 {
2040 printk(KERN_WARNING "ad1848: Unable to allocate IRQ\n");
2041 /* Don't free it either then.. */
2042 devc->irq = 0;
2043 }
2044 if (capabilities[devc->model].flags & CAP_F_TIMER)
2045 {
2046#ifndef CONFIG_SMP
2047 int x;
2048 unsigned char tmp = ad_read(devc, 16);
2049#endif
2050
2051 devc->timer_ticks = 0;
2052
2053 ad_write(devc, 21, 0x00); /* Timer MSB */
2054 ad_write(devc, 20, 0x10); /* Timer LSB */
2055#ifndef CONFIG_SMP
2056 ad_write(devc, 16, tmp | 0x40); /* Enable timer */
2057 for (x = 0; x < 100000 && devc->timer_ticks == 0; x++);
2058 ad_write(devc, 16, tmp & ~0x40); /* Disable timer */
2059
2060 if (devc->timer_ticks == 0)
2061 printk(KERN_WARNING "ad1848: Interrupt test failed (IRQ%d)\n", irq);
2062 else
2063 {
2064 DDB(printk("Interrupt test OK\n"));
2065 devc->irq_ok = 1;
2066 }
2067#else
2068 devc->irq_ok = 1;
2069#endif
2070 }
2071 else
2072 devc->irq_ok = 1; /* Couldn't test. assume it's OK */
2073 } else if (irq < 0)
2074 irq2dev[-irq] = devc->dev_no = my_dev;
2075
2076#ifndef EXCLUDE_TIMERS
2077 if ((capabilities[devc->model].flags & CAP_F_TIMER) &&
2078 devc->irq_ok)
2079 ad1848_tmr_install(my_dev);
2080#endif
2081
2082 if (!share_dma)
2083 {
2084 if (sound_alloc_dma(dma_playback, devc->name))
2085 printk(KERN_WARNING "ad1848.c: Can't allocate DMA%d\n", dma_playback);
2086
2087 if (dma_capture != dma_playback)
2088 if (sound_alloc_dma(dma_capture, devc->name))
2089 printk(KERN_WARNING "ad1848.c: Can't allocate DMA%d\n", dma_capture);
2090 }
2091
2092 if ((e = sound_install_mixer(MIXER_DRIVER_VERSION,
2093 dev_name,
2094 &ad1848_mixer_operations,
2095 sizeof(struct mixer_operations),
2096 devc)) >= 0)
2097 {
2098 audio_devs[my_dev]->mixer_dev = e;
2099 if (owner)
2100 mixer_devs[e]->owner = owner;
2101 }
2102 return my_dev;
2103}
2104
2105int ad1848_control(int cmd, int arg)
2106{
2107 ad1848_info *devc;
2108 unsigned long flags;
2109
2110 if (nr_ad1848_devs < 1)
2111 return -ENODEV;
2112
2113 devc = &adev_info[nr_ad1848_devs - 1];
2114
2115 switch (cmd)
2116 {
2117 case AD1848_SET_XTAL: /* Change clock frequency of AD1845 (only ) */
2118 if (devc->model != MD_1845 || devc->model != MD_1845_SSCAPE)
2119 return -EINVAL;
2120 spin_lock_irqsave(&devc->lock,flags);
2121 ad_enter_MCE(devc);
2122 ad_write(devc, 29, (ad_read(devc, 29) & 0x1f) | (arg << 5));
2123 ad_leave_MCE(devc);
2124 spin_unlock_irqrestore(&devc->lock,flags);
2125 break;
2126
2127 case AD1848_MIXER_REROUTE:
2128 {
2129 int o = (arg >> 8) & 0xff;
2130 int n = arg & 0xff;
2131
2132 if (o < 0 || o >= SOUND_MIXER_NRDEVICES)
2133 return -EINVAL;
2134
2135 if (!(devc->supported_devices & (1 << o)) &&
2136 !(devc->supported_rec_devices & (1 << o)))
2137 return -EINVAL;
2138
2139 if (n == SOUND_MIXER_NONE)
2140 { /* Just hide this control */
2141 ad1848_mixer_set(devc, o, 0); /* Shut up it */
2142 devc->supported_devices &= ~(1 << o);
2143 devc->supported_rec_devices &= ~(1 << o);
2144 break;
2145 }
2146
2147 /* Make the mixer control identified by o to appear as n */
2148 if (n < 0 || n >= SOUND_MIXER_NRDEVICES)
2149 return -EINVAL;
2150
2151 devc->mixer_reroute[n] = o; /* Rename the control */
2152 if (devc->supported_devices & (1 << o))
2153 devc->supported_devices |= (1 << n);
2154 if (devc->supported_rec_devices & (1 << o))
2155 devc->supported_rec_devices |= (1 << n);
2156
2157 devc->supported_devices &= ~(1 << o);
2158 devc->supported_rec_devices &= ~(1 << o);
2159 }
2160 break;
2161 }
2162 return 0;
2163}
2164
2165void ad1848_unload(int io_base, int irq, int dma_playback, int dma_capture, int share_dma)
2166{
2167 int i, mixer, dev = 0;
2168 ad1848_info *devc = NULL;
2169
2170 for (i = 0; devc == NULL && i < nr_ad1848_devs; i++)
2171 {
2172 if (adev_info[i].base == io_base)
2173 {
2174 devc = &adev_info[i];
2175 dev = devc->dev_no;
2176 }
2177 }
2178
2179 if (devc != NULL)
2180 {
2181 if(audio_devs[dev]->portc!=NULL)
2182 kfree(audio_devs[dev]->portc);
2183 release_region(devc->base, 4);
2184
2185 if (!share_dma)
2186 {
2187 if (devc->irq > 0) /* There is no point in freeing irq, if it wasn't allocated */
2188 free_irq(devc->irq, (void *)devc->dev_no);
2189
2190 sound_free_dma(dma_playback);
2191
2192 if (dma_playback != dma_capture)
2193 sound_free_dma(dma_capture);
2194
2195 }
2196 mixer = audio_devs[devc->dev_no]->mixer_dev;
2197 if(mixer>=0)
2198 sound_unload_mixerdev(mixer);
2199
2200 if (devc->pmdev)
2201 pm_unregister(devc->pmdev);
2202
2203 nr_ad1848_devs--;
2204 for ( ; i < nr_ad1848_devs ; i++)
2205 adev_info[i] = adev_info[i+1];
2206 }
2207 else
2208 printk(KERN_ERR "ad1848: Can't find device to be unloaded. Base=%x\n", io_base);
2209}
2210
2211irqreturn_t adintr(int irq, void *dev_id, struct pt_regs *dummy)
2212{
2213 unsigned char status;
2214 ad1848_info *devc;
2215 int dev;
2216 int alt_stat = 0xff;
2217 unsigned char c930_stat = 0;
2218 int cnt = 0;
2219
2220 dev = (int)dev_id;
2221 devc = (ad1848_info *) audio_devs[dev]->devc;
2222
2223interrupt_again: /* Jump back here if int status doesn't reset */
2224
2225 status = inb(io_Status(devc));
2226
2227 if (status == 0x80)
2228 printk(KERN_DEBUG "adintr: Why?\n");
2229 if (devc->model == MD_1848)
2230 outb((0), io_Status(devc)); /* Clear interrupt status */
2231
2232 if (status & 0x01)
2233 {
2234 if (devc->model == MD_C930)
2235 { /* 82C930 has interrupt status register in MAD16 register MC11 */
2236
2237 spin_lock(&devc->lock);
2238
2239 /* 0xe0e is C930 address port
2240 * 0xe0f is C930 data port
2241 */
2242 outb(11, 0xe0e);
2243 c930_stat = inb(0xe0f);
2244 outb((~c930_stat), 0xe0f);
2245
2246 spin_unlock(&devc->lock);
2247
2248 alt_stat = (c930_stat << 2) & 0x30;
2249 }
2250 else if (devc->model != MD_1848)
2251 {
2252 spin_lock(&devc->lock);
2253 alt_stat = ad_read(devc, 24);
2254 ad_write(devc, 24, ad_read(devc, 24) & ~alt_stat); /* Selective ack */
2255 spin_unlock(&devc->lock);
2256 }
2257
2258 if ((devc->open_mode & OPEN_READ) && (devc->audio_mode & PCM_ENABLE_INPUT) && (alt_stat & 0x20))
2259 {
2260 DMAbuf_inputintr(devc->record_dev);
2261 }
2262 if ((devc->open_mode & OPEN_WRITE) && (devc->audio_mode & PCM_ENABLE_OUTPUT) &&
2263 (alt_stat & 0x10))
2264 {
2265 DMAbuf_outputintr(devc->playback_dev, 1);
2266 }
2267 if (devc->model != MD_1848 && (alt_stat & 0x40)) /* Timer interrupt */
2268 {
2269 devc->timer_ticks++;
2270#ifndef EXCLUDE_TIMERS
2271 if (timer_installed == dev && devc->timer_running)
2272 sound_timer_interrupt();
2273#endif
2274 }
2275 }
2276/*
2277 * Sometimes playback or capture interrupts occur while a timer interrupt
2278 * is being handled. The interrupt will not be retriggered if we don't
2279 * handle it now. Check if an interrupt is still pending and restart
2280 * the handler in this case.
2281 */
2282 if (inb(io_Status(devc)) & 0x01 && cnt++ < 4)
2283 {
2284 goto interrupt_again;
2285 }
2286 return IRQ_HANDLED;
2287}
2288
2289/*
2290 * Experimental initialization sequence for the integrated sound system
2291 * of the Compaq Deskpro M.
2292 */
2293
2294static int init_deskpro_m(struct address_info *hw_config)
2295{
2296 unsigned char tmp;
2297
2298 if ((tmp = inb(0xc44)) == 0xff)
2299 {
2300 DDB(printk("init_deskpro_m: Dead port 0xc44\n"));
2301 return 0;
2302 }
2303
2304 outb(0x10, 0xc44);
2305 outb(0x40, 0xc45);
2306 outb(0x00, 0xc46);
2307 outb(0xe8, 0xc47);
2308 outb(0x14, 0xc44);
2309 outb(0x40, 0xc45);
2310 outb(0x00, 0xc46);
2311 outb(0xe8, 0xc47);
2312 outb(0x10, 0xc44);
2313
2314 return 1;
2315}
2316
2317/*
2318 * Experimental initialization sequence for the integrated sound system
2319 * of Compaq Deskpro XL.
2320 */
2321
2322static int init_deskpro(struct address_info *hw_config)
2323{
2324 unsigned char tmp;
2325
2326 if ((tmp = inb(0xc44)) == 0xff)
2327 {
2328 DDB(printk("init_deskpro: Dead port 0xc44\n"));
2329 return 0;
2330 }
2331 outb((tmp | 0x04), 0xc44); /* Select bank 1 */
2332 if (inb(0xc44) != 0x04)
2333 {
2334 DDB(printk("init_deskpro: Invalid bank1 signature in port 0xc44\n"));
2335 return 0;
2336 }
2337 /*
2338 * OK. It looks like a Deskpro so let's proceed.
2339 */
2340
2341 /*
2342 * I/O port 0xc44 Audio configuration register.
2343 *
2344 * bits 0xc0: Audio revision bits
2345 * 0x00 = Compaq Business Audio
2346 * 0x40 = MS Sound System Compatible (reset default)
2347 * 0x80 = Reserved
2348 * 0xc0 = Reserved
2349 * bit 0x20: No Wait State Enable
2350 * 0x00 = Disabled (reset default, DMA mode)
2351 * 0x20 = Enabled (programmed I/O mode)
2352 * bit 0x10: MS Sound System Decode Enable
2353 * 0x00 = Decoding disabled (reset default)
2354 * 0x10 = Decoding enabled
2355 * bit 0x08: FM Synthesis Decode Enable
2356 * 0x00 = Decoding Disabled (reset default)
2357 * 0x08 = Decoding enabled
2358 * bit 0x04 Bank select
2359 * 0x00 = Bank 0
2360 * 0x04 = Bank 1
2361 * bits 0x03 MSS Base address
2362 * 0x00 = 0x530 (reset default)
2363 * 0x01 = 0x604
2364 * 0x02 = 0xf40
2365 * 0x03 = 0xe80
2366 */
2367
2368#ifdef DEBUGXL
2369 /* Debug printing */
2370 printk("Port 0xc44 (before): ");
2371 outb((tmp & ~0x04), 0xc44);
2372 printk("%02x ", inb(0xc44));
2373 outb((tmp | 0x04), 0xc44);
2374 printk("%02x\n", inb(0xc44));
2375#endif
2376
2377 /* Set bank 1 of the register */
2378 tmp = 0x58; /* MSS Mode, MSS&FM decode enabled */
2379
2380 switch (hw_config->io_base)
2381 {
2382 case 0x530:
2383 tmp |= 0x00;
2384 break;
2385 case 0x604:
2386 tmp |= 0x01;
2387 break;
2388 case 0xf40:
2389 tmp |= 0x02;
2390 break;
2391 case 0xe80:
2392 tmp |= 0x03;
2393 break;
2394 default:
2395 DDB(printk("init_deskpro: Invalid MSS port %x\n", hw_config->io_base));
2396 return 0;
2397 }
2398 outb((tmp & ~0x04), 0xc44); /* Write to bank=0 */
2399
2400#ifdef DEBUGXL
2401 /* Debug printing */
2402 printk("Port 0xc44 (after): ");
2403 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2404 printk("%02x ", inb(0xc44));
2405 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2406 printk("%02x\n", inb(0xc44));
2407#endif
2408
2409 /*
2410 * I/O port 0xc45 FM Address Decode/MSS ID Register.
2411 *
2412 * bank=0, bits 0xfe: FM synthesis Decode Compare bits 7:1 (default=0x88)
2413 * bank=0, bit 0x01: SBIC Power Control Bit
2414 * 0x00 = Powered up
2415 * 0x01 = Powered down
2416 * bank=1, bits 0xfc: MSS ID (default=0x40)
2417 */
2418
2419#ifdef DEBUGXL
2420 /* Debug printing */
2421 printk("Port 0xc45 (before): ");
2422 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2423 printk("%02x ", inb(0xc45));
2424 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2425 printk("%02x\n", inb(0xc45));
2426#endif
2427
2428 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2429 outb((0x88), 0xc45); /* FM base 7:0 = 0x88 */
2430 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2431 outb((0x10), 0xc45); /* MSS ID = 0x10 (MSS port returns 0x04) */
2432
2433#ifdef DEBUGXL
2434 /* Debug printing */
2435 printk("Port 0xc45 (after): ");
2436 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2437 printk("%02x ", inb(0xc45));
2438 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2439 printk("%02x\n", inb(0xc45));
2440#endif
2441
2442
2443 /*
2444 * I/O port 0xc46 FM Address Decode/Address ASIC Revision Register.
2445 *
2446 * bank=0, bits 0xff: FM synthesis Decode Compare bits 15:8 (default=0x03)
2447 * bank=1, bits 0xff: Audio addressing ASIC id
2448 */
2449
2450#ifdef DEBUGXL
2451 /* Debug printing */
2452 printk("Port 0xc46 (before): ");
2453 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2454 printk("%02x ", inb(0xc46));
2455 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2456 printk("%02x\n", inb(0xc46));
2457#endif
2458
2459 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2460 outb((0x03), 0xc46); /* FM base 15:8 = 0x03 */
2461 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2462 outb((0x11), 0xc46); /* ASIC ID = 0x11 */
2463
2464#ifdef DEBUGXL
2465 /* Debug printing */
2466 printk("Port 0xc46 (after): ");
2467 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2468 printk("%02x ", inb(0xc46));
2469 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2470 printk("%02x\n", inb(0xc46));
2471#endif
2472
2473 /*
2474 * I/O port 0xc47 FM Address Decode Register.
2475 *
2476 * bank=0, bits 0xff: Decode enable selection for various FM address bits
2477 * bank=1, bits 0xff: Reserved
2478 */
2479
2480#ifdef DEBUGXL
2481 /* Debug printing */
2482 printk("Port 0xc47 (before): ");
2483 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2484 printk("%02x ", inb(0xc47));
2485 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2486 printk("%02x\n", inb(0xc47));
2487#endif
2488
2489 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2490 outb((0x7c), 0xc47); /* FM decode enable bits = 0x7c */
2491 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2492 outb((0x00), 0xc47); /* Reserved bank1 = 0x00 */
2493
2494#ifdef DEBUGXL
2495 /* Debug printing */
2496 printk("Port 0xc47 (after): ");
2497 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2498 printk("%02x ", inb(0xc47));
2499 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2500 printk("%02x\n", inb(0xc47));
2501#endif
2502
2503 /*
2504 * I/O port 0xc6f = Audio Disable Function Register
2505 */
2506
2507#ifdef DEBUGXL
2508 printk("Port 0xc6f (before) = %02x\n", inb(0xc6f));
2509#endif
2510
2511 outb((0x80), 0xc6f);
2512
2513#ifdef DEBUGXL
2514 printk("Port 0xc6f (after) = %02x\n", inb(0xc6f));
2515#endif
2516
2517 return 1;
2518}
2519
2520int probe_ms_sound(struct address_info *hw_config, struct resource *ports)
2521{
2522 unsigned char tmp;
2523
2524 DDB(printk("Entered probe_ms_sound(%x, %d)\n", hw_config->io_base, hw_config->card_subtype));
2525
2526 if (hw_config->card_subtype == 1) /* Has no IRQ/DMA registers */
2527 {
2528 /* check_opl3(0x388, hw_config); */
2529 return ad1848_detect(ports, NULL, hw_config->osp);
2530 }
2531
2532 if (deskpro_xl && hw_config->card_subtype == 2) /* Compaq Deskpro XL */
2533 {
2534 if (!init_deskpro(hw_config))
2535 return 0;
2536 }
2537
2538 if (deskpro_m) /* Compaq Deskpro M */
2539 {
2540 if (!init_deskpro_m(hw_config))
2541 return 0;
2542 }
2543
2544 /*
2545 * Check if the IO port returns valid signature. The original MS Sound
2546 * system returns 0x04 while some cards (AudioTrix Pro for example)
2547 * return 0x00 or 0x0f.
2548 */
2549
2550 if ((tmp = inb(hw_config->io_base + 3)) == 0xff) /* Bus float */
2551 {
2552 int ret;
2553
2554 DDB(printk("I/O address is inactive (%x)\n", tmp));
2555 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
2556 return 0;
2557 return 1;
2558 }
2559 DDB(printk("MSS signature = %x\n", tmp & 0x3f));
2560 if ((tmp & 0x3f) != 0x04 &&
2561 (tmp & 0x3f) != 0x0f &&
2562 (tmp & 0x3f) != 0x00)
2563 {
2564 int ret;
2565
2566 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)));
2567 DDB(printk("Trying to detect codec anyway but IRQ/DMA may not work\n"));
2568 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
2569 return 0;
2570
2571 hw_config->card_subtype = 1;
2572 return 1;
2573 }
2574 if ((hw_config->irq != 5) &&
2575 (hw_config->irq != 7) &&
2576 (hw_config->irq != 9) &&
2577 (hw_config->irq != 10) &&
2578 (hw_config->irq != 11) &&
2579 (hw_config->irq != 12))
2580 {
2581 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
2582 return 0;
2583 }
2584 if (hw_config->dma != 0 && hw_config->dma != 1 && hw_config->dma != 3)
2585 {
2586 printk(KERN_ERR "MSS: Bad DMA %d\n", hw_config->dma);
2587 return 0;
2588 }
2589 /*
2590 * Check that DMA0 is not in use with a 8 bit board.
2591 */
2592
2593 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80)
2594 {
2595 printk(KERN_ERR "MSS: Can't use DMA0 with a 8 bit card/slot\n");
2596 return 0;
2597 }
2598 if (hw_config->irq > 7 && hw_config->irq != 9 && inb(hw_config->io_base + 3) & 0x80)
2599 {
2600 printk(KERN_ERR "MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->irq);
2601 return 0;
2602 }
2603 return ad1848_detect(ports, NULL, hw_config->osp);
2604}
2605
2606void attach_ms_sound(struct address_info *hw_config, struct resource *ports, struct module *owner)
2607{
2608 static signed char interrupt_bits[12] =
2609 {
2610 -1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20
2611 };
2612 signed char bits;
2613 char dma2_bit = 0;
2614
2615 static char dma_bits[4] =
2616 {
2617 1, 2, 0, 3
2618 };
2619
2620 int config_port = hw_config->io_base + 0;
2621 int version_port = hw_config->io_base + 3;
2622 int dma = hw_config->dma;
2623 int dma2 = hw_config->dma2;
2624
2625 if (hw_config->card_subtype == 1) /* Has no IRQ/DMA registers */
2626 {
2627 hw_config->slots[0] = ad1848_init("MS Sound System", ports,
2628 hw_config->irq,
2629 hw_config->dma,
2630 hw_config->dma2, 0,
2631 hw_config->osp,
2632 owner);
2633 return;
2634 }
2635 /*
2636 * Set the IRQ and DMA addresses.
2637 */
2638
2639 bits = interrupt_bits[hw_config->irq];
2640 if (bits == -1)
2641 {
2642 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
2643 release_region(ports->start, 4);
2644 release_region(ports->start - 4, 4);
2645 return;
2646 }
2647 outb((bits | 0x40), config_port);
2648 if ((inb(version_port) & 0x40) == 0)
2649 printk(KERN_ERR "[MSS: IRQ Conflict?]\n");
2650
2651/*
2652 * Handle the capture DMA channel
2653 */
2654
2655 if (dma2 != -1 && dma2 != dma)
2656 {
2657 if (!((dma == 0 && dma2 == 1) ||
2658 (dma == 1 && dma2 == 0) ||
2659 (dma == 3 && dma2 == 0)))
2660 { /* Unsupported combination. Try to swap channels */
2661 int tmp = dma;
2662
2663 dma = dma2;
2664 dma2 = tmp;
2665 }
2666 if ((dma == 0 && dma2 == 1) ||
2667 (dma == 1 && dma2 == 0) ||
2668 (dma == 3 && dma2 == 0))
2669 {
2670 dma2_bit = 0x04; /* Enable capture DMA */
2671 }
2672 else
2673 {
2674 printk(KERN_WARNING "MSS: Invalid capture DMA\n");
2675 dma2 = dma;
2676 }
2677 }
2678 else
2679 {
2680 dma2 = dma;
2681 }
2682
2683 hw_config->dma = dma;
2684 hw_config->dma2 = dma2;
2685
2686 outb((bits | dma_bits[dma] | dma2_bit), config_port); /* Write IRQ+DMA setup */
2687
2688 hw_config->slots[0] = ad1848_init("MS Sound System", ports,
2689 hw_config->irq,
2690 dma, dma2, 0,
2691 hw_config->osp,
2692 THIS_MODULE);
2693}
2694
2695void unload_ms_sound(struct address_info *hw_config)
2696{
2697 ad1848_unload(hw_config->io_base + 4,
2698 hw_config->irq,
2699 hw_config->dma,
2700 hw_config->dma2, 0);
2701 sound_unload_audiodev(hw_config->slots[0]);
2702 release_region(hw_config->io_base, 4);
2703}
2704
2705#ifndef EXCLUDE_TIMERS
2706
2707/*
2708 * Timer stuff (for /dev/music).
2709 */
2710
2711static unsigned int current_interval;
2712
2713static unsigned int ad1848_tmr_start(int dev, unsigned int usecs)
2714{
2715 unsigned long flags;
2716 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2717 unsigned long xtal_nsecs; /* nanoseconds per xtal oscillator tick */
2718 unsigned long divider;
2719
2720 spin_lock_irqsave(&devc->lock,flags);
2721
2722 /*
2723 * Length of the timer interval (in nanoseconds) depends on the
2724 * selected crystal oscillator. Check this from bit 0x01 of I8.
2725 *
2726 * AD1845 has just one oscillator which has cycle time of 10.050 us
2727 * (when a 24.576 MHz xtal oscillator is used).
2728 *
2729 * Convert requested interval to nanoseconds before computing
2730 * the timer divider.
2731 */
2732
2733 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE)
2734 xtal_nsecs = 10050;
2735 else if (ad_read(devc, 8) & 0x01)
2736 xtal_nsecs = 9920;
2737 else
2738 xtal_nsecs = 9969;
2739
2740 divider = (usecs * 1000 + xtal_nsecs / 2) / xtal_nsecs;
2741
2742 if (divider < 100) /* Don't allow shorter intervals than about 1ms */
2743 divider = 100;
2744
2745 if (divider > 65535) /* Overflow check */
2746 divider = 65535;
2747
2748 ad_write(devc, 21, (divider >> 8) & 0xff); /* Set upper bits */
2749 ad_write(devc, 20, divider & 0xff); /* Set lower bits */
2750 ad_write(devc, 16, ad_read(devc, 16) | 0x40); /* Start the timer */
2751 devc->timer_running = 1;
2752 spin_unlock_irqrestore(&devc->lock,flags);
2753
2754 return current_interval = (divider * xtal_nsecs + 500) / 1000;
2755}
2756
2757static void ad1848_tmr_reprogram(int dev)
2758{
2759 /*
2760 * Audio driver has changed sampling rate so that a different xtal
2761 * oscillator was selected. We have to reprogram the timer rate.
2762 */
2763
2764 ad1848_tmr_start(dev, current_interval);
2765 sound_timer_syncinterval(current_interval);
2766}
2767
2768static void ad1848_tmr_disable(int dev)
2769{
2770 unsigned long flags;
2771 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2772
2773 spin_lock_irqsave(&devc->lock,flags);
2774 ad_write(devc, 16, ad_read(devc, 16) & ~0x40);
2775 devc->timer_running = 0;
2776 spin_unlock_irqrestore(&devc->lock,flags);
2777}
2778
2779static void ad1848_tmr_restart(int dev)
2780{
2781 unsigned long flags;
2782 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2783
2784 if (current_interval == 0)
2785 return;
2786
2787 spin_lock_irqsave(&devc->lock,flags);
2788 ad_write(devc, 16, ad_read(devc, 16) | 0x40);
2789 devc->timer_running = 1;
2790 spin_unlock_irqrestore(&devc->lock,flags);
2791}
2792
2793static struct sound_lowlev_timer ad1848_tmr =
2794{
2795 0,
2796 2,
2797 ad1848_tmr_start,
2798 ad1848_tmr_disable,
2799 ad1848_tmr_restart
2800};
2801
2802static int ad1848_tmr_install(int dev)
2803{
2804 if (timer_installed != -1)
2805 return 0; /* Don't install another timer */
2806
2807 timer_installed = ad1848_tmr.dev = dev;
2808 sound_timer_init(&ad1848_tmr, audio_devs[dev]->name);
2809
2810 return 1;
2811}
2812#endif /* EXCLUDE_TIMERS */
2813
2814static int ad1848_suspend(ad1848_info *devc)
2815{
2816 unsigned long flags;
2817
2818 spin_lock_irqsave(&devc->lock,flags);
2819
2820 ad_mute(devc);
2821
2822 spin_unlock_irqrestore(&devc->lock,flags);
2823 return 0;
2824}
2825
2826static int ad1848_resume(ad1848_info *devc)
2827{
2828 int mixer_levels[32], i;
2829
2830 /* Thinkpad is a bit more of PITA than normal. The BIOS tends to
2831 restore it in a different config to the one we use. Need to
2832 fix this somehow */
2833
2834 /* store old mixer levels */
2835 memcpy(mixer_levels, devc->levels, sizeof (mixer_levels));
2836 ad1848_init_hw(devc);
2837
2838 /* restore mixer levels */
2839 for (i = 0; i < 32; i++)
2840 ad1848_mixer_set(devc, devc->dev_no, mixer_levels[i]);
2841
2842 if (!devc->subtype) {
2843 static signed char interrupt_bits[12] = { -1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20 };
2844 static char dma_bits[4] = { 1, 2, 0, 3 };
2845 unsigned long flags;
2846 signed char bits;
2847 char dma2_bit = 0;
2848
2849 int config_port = devc->base + 0;
2850
2851 bits = interrupt_bits[devc->irq];
2852 if (bits == -1) {
2853 printk(KERN_ERR "MSS: Bad IRQ %d\n", devc->irq);
2854 return -1;
2855 }
2856
2857 spin_lock_irqsave(&devc->lock,flags);
2858
2859 outb((bits | 0x40), config_port);
2860
2861 if (devc->dma2 != -1 && devc->dma2 != devc->dma1)
2862 if ( (devc->dma1 == 0 && devc->dma2 == 1) ||
2863 (devc->dma1 == 1 && devc->dma2 == 0) ||
2864 (devc->dma1 == 3 && devc->dma2 == 0))
2865 dma2_bit = 0x04;
2866
2867 outb((bits | dma_bits[devc->dma1] | dma2_bit), config_port);
2868 spin_unlock_irqrestore(&devc->lock,flags);
2869 }
2870
2871 return 0;
2872}
2873
2874static int ad1848_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
2875{
2876 ad1848_info *devc = dev->data;
2877 if (devc) {
2878 DEB(printk("ad1848: pm event received: 0x%x\n", rqst));
2879
2880 switch (rqst) {
2881 case PM_SUSPEND:
2882 ad1848_suspend(devc);
2883 break;
2884 case PM_RESUME:
2885 ad1848_resume(devc);
2886 break;
2887 }
2888 }
2889 return 0;
2890}
2891
2892
2893EXPORT_SYMBOL(ad1848_detect);
2894EXPORT_SYMBOL(ad1848_init);
2895EXPORT_SYMBOL(ad1848_unload);
2896EXPORT_SYMBOL(ad1848_control);
2897EXPORT_SYMBOL(adintr);
2898EXPORT_SYMBOL(probe_ms_sound);
2899EXPORT_SYMBOL(attach_ms_sound);
2900EXPORT_SYMBOL(unload_ms_sound);
2901
2902static int __initdata io = -1;
2903static int __initdata irq = -1;
2904static int __initdata dma = -1;
2905static int __initdata dma2 = -1;
2906static int __initdata type = 0;
2907
2908module_param(io, int, 0); /* I/O for a raw AD1848 card */
2909module_param(irq, int, 0); /* IRQ to use */
2910module_param(dma, int, 0); /* First DMA channel */
2911module_param(dma2, int, 0); /* Second DMA channel */
2912module_param(type, int, 0); /* Card type */
2913module_param(deskpro_xl, bool, 0); /* Special magic for Deskpro XL boxen */
2914module_param(deskpro_m, bool, 0); /* Special magic for Deskpro M box */
2915module_param(soundpro, bool, 0); /* More special magic for SoundPro chips */
2916
2917#ifdef CONFIG_PNP
2918module_param(isapnp, int, 0);
2919module_param(isapnpjump, int, 0);
2920module_param(reverse, bool, 0);
2921MODULE_PARM_DESC(isapnp, "When set to 0, Plug & Play support will be disabled");
2922MODULE_PARM_DESC(isapnpjump, "Jumps to a specific slot in the driver's PnP table. Use the source, Luke.");
2923MODULE_PARM_DESC(reverse, "When set to 1, will reverse ISAPnP search order");
2924
2925static struct pnp_dev *ad1848_dev = NULL;
2926
2927/* Please add new entries at the end of the table */
2928static struct {
2929 char *name;
2930 unsigned short card_vendor, card_device,
2931 vendor, function;
2932 short mss_io, irq, dma, dma2; /* index into isapnp table */
2933 int type;
2934} ad1848_isapnp_list[] __initdata = {
2935 {"CMI 8330 SoundPRO",
2936 ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001),
2937 ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001),
2938 0, 0, 0,-1, 0},
2939 {"CS4232 based card",
2940 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2941 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000),
2942 0, 0, 0, 1, 0},
2943 {"CS4232 based card",
2944 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2945 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100),
2946 0, 0, 0, 1, 0},
2947 {"OPL3-SA2 WSS mode",
2948 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2949 ISAPNP_VENDOR('Y','M','H'), ISAPNP_FUNCTION(0x0021),
2950 1, 0, 0, 1, 1},
2951 {"Advanced Gravis InterWave Audio",
2952 ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
2953 ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000),
2954 0, 0, 0, 1, 0},
2955 {NULL}
2956};
2957
2958static struct isapnp_device_id id_table[] __devinitdata = {
2959 { ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001),
2960 ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001), 0 },
2961 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2962 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000), 0 },
2963 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2964 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100), 0 },
2965 /* The main driver for this card is opl3sa2
2966 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2967 ISAPNP_VENDOR('Y','M','H'), ISAPNP_FUNCTION(0x0021), 0 },
2968 */
2969 { ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
2970 ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000), 0 },
2971 {0}
2972};
2973
2974MODULE_DEVICE_TABLE(isapnp, id_table);
2975
2976static struct pnp_dev *activate_dev(char *devname, char *resname, struct pnp_dev *dev)
2977{
2978 int err;
2979
2980 err = pnp_device_attach(dev);
2981 if (err < 0)
2982 return(NULL);
2983
2984 if((err = pnp_activate_dev(dev)) < 0) {
2985 printk(KERN_ERR "ad1848: %s %s config failed (out of resources?)[%d]\n", devname, resname, err);
2986
2987 pnp_device_detach(dev);
2988
2989 return(NULL);
2990 }
2991 audio_activated = 1;
2992 return(dev);
2993}
2994
2995static struct pnp_dev *ad1848_init_generic(struct pnp_card *bus, struct address_info *hw_config, int slot)
2996{
2997
2998 /* Configure Audio device */
2999 if((ad1848_dev = pnp_find_dev(bus, ad1848_isapnp_list[slot].vendor, ad1848_isapnp_list[slot].function, NULL)))
3000 {
3001 if((ad1848_dev = activate_dev(ad1848_isapnp_list[slot].name, "ad1848", ad1848_dev)))
3002 {
3003 hw_config->io_base = pnp_port_start(ad1848_dev, ad1848_isapnp_list[slot].mss_io);
3004 hw_config->irq = pnp_irq(ad1848_dev, ad1848_isapnp_list[slot].irq);
3005 hw_config->dma = pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma);
3006 if(ad1848_isapnp_list[slot].dma2 != -1)
3007 hw_config->dma2 = pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma2);
3008 else
3009 hw_config->dma2 = -1;
3010 hw_config->card_subtype = ad1848_isapnp_list[slot].type;
3011 } else
3012 return(NULL);
3013 } else
3014 return(NULL);
3015
3016 return(ad1848_dev);
3017}
3018
3019static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pnp_card *bus, int slot)
3020{
3021 char *busname = bus->name[0] ? bus->name : ad1848_isapnp_list[slot].name;
3022
3023 /* Initialize this baby. */
3024
3025 if(ad1848_init_generic(bus, hw_config, slot)) {
3026 /* We got it. */
3027
3028 printk(KERN_NOTICE "ad1848: PnP reports '%s' at i/o %#x, irq %d, dma %d, %d\n",
3029 busname,
3030 hw_config->io_base, hw_config->irq, hw_config->dma,
3031 hw_config->dma2);
3032 return 1;
3033 }
3034 return 0;
3035}
3036
3037static int __init ad1848_isapnp_probe(struct address_info *hw_config)
3038{
3039 static int first = 1;
3040 int i;
3041
3042 /* Count entries in sb_isapnp_list */
3043 for (i = 0; ad1848_isapnp_list[i].card_vendor != 0; i++);
3044 i--;
3045
3046 /* Check and adjust isapnpjump */
3047 if( isapnpjump < 0 || isapnpjump > i) {
3048 isapnpjump = reverse ? i : 0;
3049 printk(KERN_ERR "ad1848: Valid range for isapnpjump is 0-%d. Adjusted to %d.\n", i, isapnpjump);
3050 }
3051
3052 if(!first || !reverse)
3053 i = isapnpjump;
3054 first = 0;
3055 while(ad1848_isapnp_list[i].card_vendor != 0) {
3056 static struct pnp_card *bus = NULL;
3057
3058 while ((bus = pnp_find_card(
3059 ad1848_isapnp_list[i].card_vendor,
3060 ad1848_isapnp_list[i].card_device,
3061 bus))) {
3062
3063 if(ad1848_isapnp_init(hw_config, bus, i)) {
3064 isapnpjump = i; /* start next search from here */
3065 return 0;
3066 }
3067 }
3068 i += reverse ? -1 : 1;
3069 }
3070
3071 return -ENODEV;
3072}
3073#endif
3074
3075
3076static int __init init_ad1848(void)
3077{
3078 printk(KERN_INFO "ad1848/cs4248 codec driver Copyright (C) by Hannu Savolainen 1993-1996\n");
3079
3080#ifdef CONFIG_PNP
3081 if(isapnp && (ad1848_isapnp_probe(&cfg) < 0) ) {
3082 printk(KERN_NOTICE "ad1848: No ISAPnP cards found, trying standard ones...\n");
3083 isapnp = 0;
3084 }
3085#endif
3086
3087 if(io != -1) {
3088 struct resource *ports;
3089 if( isapnp == 0 )
3090 {
3091 if(irq == -1 || dma == -1) {
3092 printk(KERN_WARNING "ad1848: must give I/O , IRQ and DMA.\n");
3093 return -EINVAL;
3094 }
3095
3096 cfg.irq = irq;
3097 cfg.io_base = io;
3098 cfg.dma = dma;
3099 cfg.dma2 = dma2;
3100 cfg.card_subtype = type;
3101 }
3102
3103 ports = request_region(io + 4, 4, "ad1848");
3104
3105 if (!ports)
3106 return -EBUSY;
3107
3108 if (!request_region(io, 4, "WSS config")) {
3109 release_region(io + 4, 4);
3110 return -EBUSY;
3111 }
3112
3113 if (!probe_ms_sound(&cfg, ports)) {
3114 release_region(io + 4, 4);
3115 release_region(io, 4);
3116 return -ENODEV;
3117 }
3118 attach_ms_sound(&cfg, ports, THIS_MODULE);
3119 loaded = 1;
3120 }
3121 return 0;
3122}
3123
3124static void __exit cleanup_ad1848(void)
3125{
3126 if(loaded)
3127 unload_ms_sound(&cfg);
3128
3129#ifdef CONFIG_PNP
3130 if(ad1848_dev){
3131 if(audio_activated)
3132 pnp_device_detach(ad1848_dev);
3133 }
3134#endif
3135}
3136
3137module_init(init_ad1848);
3138module_exit(cleanup_ad1848);
3139
3140#ifndef MODULE
3141static int __init setup_ad1848(char *str)
3142{
3143 /* io, irq, dma, dma2, type */
3144 int ints[6];
3145
3146 str = get_options(str, ARRAY_SIZE(ints), ints);
3147
3148 io = ints[1];
3149 irq = ints[2];
3150 dma = ints[3];
3151 dma2 = ints[4];
3152 type = ints[5];
3153
3154 return 1;
3155}
3156
3157__setup("ad1848=", setup_ad1848);
3158#endif
3159MODULE_LICENSE("GPL");
diff --git a/sound/oss/ad1848.h b/sound/oss/ad1848.h
new file mode 100644
index 000000000000..d0573b023973
--- /dev/null
+++ b/sound/oss/ad1848.h
@@ -0,0 +1,25 @@
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
21irqreturn_t adintr(int irq, void *dev_id, struct pt_regs * dummy);
22void attach_ms_sound(struct address_info * hw_config, struct resource *ports, struct module * owner);
23
24int probe_ms_sound(struct address_info *hw_config, struct resource *ports);
25void unload_ms_sound(struct address_info *hw_info);
diff --git a/sound/oss/ad1848_mixer.h b/sound/oss/ad1848_mixer.h
new file mode 100644
index 000000000000..f9231c6cd4e1
--- /dev/null
+++ b/sound/oss/ad1848_mixer.h
@@ -0,0 +1,253 @@
1/*
2 * sound/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/ad1889.c b/sound/oss/ad1889.c
new file mode 100644
index 000000000000..b767c621fd09
--- /dev/null
+++ b/sound/oss/ad1889.c
@@ -0,0 +1,1103 @@
1/*
2 * Copyright 2001-2004 Randolph Chung <tausq@debian.org>
3 *
4 * Analog Devices 1889 PCI audio driver (AD1819 AC97-compatible codec)
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Notes:
21 * 1. Only flat DMA is supported; s-g is not supported right now
22 *
23 *
24<jsm> tausq: Anyway, to set up sample rates for D to A, you just use the sample rate on the codec. For A to D, you need to set the codec always to 48K (using the split sample rate feature on the codec) and then set the resampler on the AD1889 to the sample rate you want.
25<jsm> Also, when changing the sample rate on the codec you need to power it down and re power it up for the change to take effect!
26 *
27 * $Id: ad1889.c,v 1.3 2002/10/19 21:31:44 grundler Exp $
28 */
29#include <linux/config.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/ioport.h>
33#include <linux/pci.h>
34#include <linux/poll.h>
35#include <linux/proc_fs.h>
36#include <linux/slab.h>
37#include <linux/soundcard.h>
38#include <linux/ac97_codec.h>
39#include <linux/sound.h>
40#include <linux/interrupt.h>
41
42#include <asm/delay.h>
43#include <asm/io.h>
44#include <asm/dma.h>
45#include <asm/uaccess.h>
46
47#include "ad1889.h"
48
49#define DBG(fmt, arg...) printk(fmt, ##arg)
50#define DEVNAME "ad1889"
51
52#define NR_HW_CH 4
53#define DAC_RUNNING 1
54#define ADC_RUNNING 2
55
56#define UNDERRUN(dev) (0)
57
58#define AD1889_READW(dev,reg) readw(dev->regbase + reg)
59#define AD1889_WRITEW(dev,reg,val) writew((val), dev->regbase + reg)
60#define AD1889_READL(dev,reg) readl(dev->regbase + reg)
61#define AD1889_WRITEL(dev,reg,val) writel((val), dev->regbase + reg)
62
63//now 100ms
64/* #define WAIT_10MS() schedule_timeout(HZ/10) */
65#define WAIT_10MS() do { int __i; for (__i = 0; __i < 100; __i++) udelay(1000); } while(0)
66
67/* currently only support a single device */
68static ad1889_dev_t *ad1889_dev = NULL;
69
70/************************* helper routines ***************************** */
71static inline void ad1889_set_wav_rate(ad1889_dev_t *dev, int rate)
72{
73 struct ac97_codec *ac97_codec = dev->ac97_codec;
74
75 DBG("Setting WAV rate to %d\n", rate);
76 dev->state[AD_WAV_STATE].dmabuf.rate = rate;
77 AD1889_WRITEW(dev, AD_DSWAS, rate);
78
79 /* Cycle the DAC to enable the new rate */
80 ac97_codec->codec_write(dev->ac97_codec, AC97_POWER_CONTROL, 0x0200);
81 WAIT_10MS();
82 ac97_codec->codec_write(dev->ac97_codec, AC97_POWER_CONTROL, 0);
83}
84
85static inline void ad1889_set_wav_fmt(ad1889_dev_t *dev, int fmt)
86{
87 u16 tmp;
88
89 DBG("Setting WAV format to 0x%x\n", fmt);
90
91 tmp = AD1889_READW(ad1889_dev, AD_DSWSMC);
92 if (fmt & AFMT_S16_LE) {
93 //tmp |= 0x0100; /* set WA16 */
94 tmp |= 0x0300; /* set WA16 stereo */
95 } else if (fmt & AFMT_U8) {
96 tmp &= ~0x0100; /* clear WA16 */
97 }
98 AD1889_WRITEW(ad1889_dev, AD_DSWSMC, tmp);
99}
100
101static inline void ad1889_set_adc_fmt(ad1889_dev_t *dev, int fmt)
102{
103 u16 tmp;
104
105 DBG("Setting ADC format to 0x%x\n", fmt);
106
107 tmp = AD1889_READW(ad1889_dev, AD_DSRAMC);
108 if (fmt & AFMT_S16_LE) {
109 tmp |= 0x0100; /* set WA16 */
110 } else if (fmt & AFMT_U8) {
111 tmp &= ~0x0100; /* clear WA16 */
112 }
113 AD1889_WRITEW(ad1889_dev, AD_DSRAMC, tmp);
114}
115
116static void ad1889_start_wav(ad1889_state_t *state)
117{
118 unsigned long flags;
119 struct dmabuf *dmabuf = &state->dmabuf;
120 int cnt;
121 u16 tmp;
122
123 spin_lock_irqsave(&state->card->lock, flags);
124
125 if (dmabuf->dma_len) /* DMA already in flight */
126 goto skip_dma;
127
128 /* setup dma */
129 cnt = dmabuf->wr_ptr - dmabuf->rd_ptr;
130 if (cnt == 0) /* done - don't need to do anything */
131 goto skip_dma;
132
133 /* If the wr_ptr has wrapped, only map to the end */
134 if (cnt < 0)
135 cnt = DMA_SIZE - dmabuf->rd_ptr;
136
137 dmabuf->dma_handle = pci_map_single(ad1889_dev->pci,
138 dmabuf->rawbuf + dmabuf->rd_ptr,
139 cnt, PCI_DMA_TODEVICE);
140 dmabuf->dma_len = cnt;
141 dmabuf->ready = 1;
142
143 DBG("Starting playback at 0x%p for %ld bytes\n", dmabuf->rawbuf +
144 dmabuf->rd_ptr, dmabuf->dma_len);
145
146 /* load up the current register set */
147 AD1889_WRITEL(ad1889_dev, AD_DMAWAVCC, cnt);
148 AD1889_WRITEL(ad1889_dev, AD_DMAWAVICC, cnt);
149 AD1889_WRITEL(ad1889_dev, AD_DMAWAVCA, dmabuf->dma_handle);
150
151 /* TODO: for now we load the base registers with the same thing */
152 AD1889_WRITEL(ad1889_dev, AD_DMAWAVBC, cnt);
153 AD1889_WRITEL(ad1889_dev, AD_DMAWAVIBC, cnt);
154 AD1889_WRITEL(ad1889_dev, AD_DMAWAVBA, dmabuf->dma_handle);
155
156 /* and we're off to the races... */
157 AD1889_WRITEL(ad1889_dev, AD_DMACHSS, 0x8);
158 tmp = AD1889_READW(ad1889_dev, AD_DSWSMC);
159 tmp |= 0x0400; /* set WAEN */
160 AD1889_WRITEW(ad1889_dev, AD_DSWSMC, tmp);
161 (void) AD1889_READW(ad1889_dev, AD_DSWSMC); /* flush posted PCI write */
162
163 dmabuf->enable |= DAC_RUNNING;
164
165skip_dma:
166 spin_unlock_irqrestore(&state->card->lock, flags);
167}
168
169
170static void ad1889_stop_wav(ad1889_state_t *state)
171{
172 unsigned long flags;
173 struct dmabuf *dmabuf = &state->dmabuf;
174
175 spin_lock_irqsave(&state->card->lock, flags);
176
177 if (dmabuf->enable & DAC_RUNNING) {
178 u16 tmp;
179 unsigned long cnt = dmabuf->dma_len;
180
181 tmp = AD1889_READW(ad1889_dev, AD_DSWSMC);
182 tmp &= ~0x0400; /* clear WAEN */
183 AD1889_WRITEW(ad1889_dev, AD_DSWSMC, tmp);
184 (void) AD1889_READW(ad1889_dev, AD_DSWSMC); /* flush posted PCI write */
185 pci_unmap_single(ad1889_dev->pci, dmabuf->dma_handle,
186 cnt, PCI_DMA_TODEVICE);
187
188 dmabuf->enable &= ~DAC_RUNNING;
189
190 /* update dma pointers */
191 dmabuf->rd_ptr += cnt;
192 dmabuf->rd_ptr &= (DMA_SIZE - 1);
193
194 dmabuf->dma_handle = 0;
195 dmabuf->dma_len = 0;
196 dmabuf->ready = 0;
197
198 wake_up(&dmabuf->wait);
199 }
200
201 spin_unlock_irqrestore(&state->card->lock, flags);
202}
203
204
205#if 0
206static void ad1889_startstop_adc(ad1889_state_t *state, int start)
207{
208 u16 tmp;
209 unsigned long flags;
210
211 spin_lock_irqsave(&state->card->lock, flags);
212
213 tmp = AD1889_READW(ad1889_dev, AD_DSRAMC);
214 if (start) {
215 state->dmabuf.enable |= ADC_RUNNING;
216 tmp |= 0x0004; /* set ADEN */
217 } else {
218 state->dmabuf.enable &= ~ADC_RUNNING;
219 tmp &= ~0x0004; /* clear ADEN */
220 }
221 AD1889_WRITEW(ad1889_dev, AD_DSRAMC, tmp);
222
223 spin_unlock_irqrestore(&state->card->lock, flags);
224}
225#endif
226
227static ad1889_dev_t *ad1889_alloc_dev(struct pci_dev *pci)
228{
229 ad1889_dev_t *dev;
230 struct dmabuf *dmabuf;
231 int i;
232
233 if ((dev = kmalloc(sizeof(ad1889_dev_t), GFP_KERNEL)) == NULL)
234 return NULL;
235 memset(dev, 0, sizeof(ad1889_dev_t));
236 spin_lock_init(&dev->lock);
237 dev->pci = pci;
238
239 for (i = 0; i < AD_MAX_STATES; i++) {
240 dev->state[i].card = dev;
241 init_MUTEX(&dev->state[i].sem);
242 init_waitqueue_head(&dev->state[i].dmabuf.wait);
243 }
244
245 /* allocate dma buffer */
246
247 for (i = 0; i < AD_MAX_STATES; i++) {
248 dmabuf = &dev->state[i].dmabuf;
249 dmabuf->rawbuf = kmalloc(DMA_SIZE, GFP_KERNEL|GFP_DMA);
250 if (!dmabuf->rawbuf)
251 goto err_free_dmabuf;
252 dmabuf->rawbuf_size = DMA_SIZE;
253 dmabuf->dma_handle = 0;
254 dmabuf->rd_ptr = dmabuf->wr_ptr = dmabuf->dma_len = 0UL;
255 dmabuf->ready = 0;
256 dmabuf->rate = 48000;
257 }
258 return dev;
259
260err_free_dmabuf:
261 while (--i >= 0)
262 kfree(dev->state[i].dmabuf.rawbuf);
263 kfree(dev);
264 return NULL;
265}
266
267static void ad1889_free_dev(ad1889_dev_t *dev)
268{
269 int j;
270 struct dmabuf *dmabuf;
271
272 if (dev == NULL)
273 return;
274
275 if (dev->ac97_codec)
276 ac97_release_codec(dev->ac97_codec);
277
278 for (j = 0; j < AD_MAX_STATES; j++) {
279 dmabuf = &dev->state[j].dmabuf;
280 if (dmabuf->rawbuf != NULL)
281 kfree(dmabuf->rawbuf);
282 }
283
284 kfree(dev);
285}
286
287static inline void ad1889_trigger_playback(ad1889_dev_t *dev)
288{
289#if 0
290 u32 val;
291 struct dmabuf *dmabuf = &dev->state[AD_WAV_STATE].dmabuf;
292#endif
293
294 ad1889_start_wav(&dev->state[AD_WAV_STATE]);
295}
296
297static int ad1889_read_proc (char *page, char **start, off_t off,
298 int count, int *eof, void *data)
299{
300 char *out = page;
301 int len, i;
302 ad1889_dev_t *dev = data;
303 ad1889_reg_t regs[] = {
304 { "WSMC", AD_DSWSMC, 16 },
305 { "RAMC", AD_DSRAMC, 16 },
306 { "WADA", AD_DSWADA, 16 },
307 { "SYDA", AD_DSSYDA, 16 },
308 { "WAS", AD_DSWAS, 16 },
309 { "RES", AD_DSRES, 16 },
310 { "CCS", AD_DSCCS, 16 },
311 { "ADCBA", AD_DMAADCBA, 32 },
312 { "ADCCA", AD_DMAADCCA, 32 },
313 { "ADCBC", AD_DMAADCBC, 32 },
314 { "ADCCC", AD_DMAADCCC, 32 },
315 { "ADCIBC", AD_DMAADCIBC, 32 },
316 { "ADCICC", AD_DMAADCICC, 32 },
317 { "ADCCTRL", AD_DMAADCCTRL, 16 },
318 { "WAVBA", AD_DMAWAVBA, 32 },
319 { "WAVCA", AD_DMAWAVCA, 32 },
320 { "WAVBC", AD_DMAWAVBC, 32 },
321 { "WAVCC", AD_DMAWAVCC, 32 },
322 { "WAVIBC", AD_DMAWAVIBC, 32 },
323 { "WAVICC", AD_DMAWAVICC, 32 },
324 { "WAVCTRL", AD_DMAWAVCTRL, 16 },
325 { "DISR", AD_DMADISR, 32 },
326 { "CHSS", AD_DMACHSS, 32 },
327 { "IPC", AD_GPIOIPC, 16 },
328 { "OP", AD_GPIOOP, 16 },
329 { "IP", AD_GPIOIP, 16 },
330 { "ACIC", AD_ACIC, 16 },
331 { "AC97_RESET", 0x100 + AC97_RESET, 16 },
332 { "AC97_MASTER_VOL_STEREO", 0x100 + AC97_MASTER_VOL_STEREO, 16 },
333 { "AC97_HEADPHONE_VOL", 0x100 + AC97_HEADPHONE_VOL, 16 },
334 { "AC97_MASTER_VOL_MONO", 0x100 + AC97_MASTER_VOL_MONO, 16 },
335 { "AC97_MASTER_TONE", 0x100 + AC97_MASTER_TONE, 16 },
336 { "AC97_PCBEEP_VOL", 0x100 + AC97_PCBEEP_VOL, 16 },
337 { "AC97_PHONE_VOL", 0x100 + AC97_PHONE_VOL, 16 },
338 { "AC97_MIC_VOL", 0x100 + AC97_MIC_VOL, 16 },
339 { "AC97_LINEIN_VOL", 0x100 + AC97_LINEIN_VOL, 16 },
340 { "AC97_CD_VOL", 0x100 + AC97_CD_VOL, 16 },
341 { "AC97_VIDEO_VOL", 0x100 + AC97_VIDEO_VOL, 16 },
342 { "AC97_AUX_VOL", 0x100 + AC97_AUX_VOL, 16 },
343 { "AC97_PCMOUT_VOL", 0x100 + AC97_PCMOUT_VOL, 16 },
344 { "AC97_RECORD_SELECT", 0x100 + AC97_RECORD_SELECT, 16 },
345 { "AC97_RECORD_GAIN", 0x100 + AC97_RECORD_GAIN, 16 },
346 { "AC97_RECORD_GAIN_MIC", 0x100 + AC97_RECORD_GAIN_MIC, 16 },
347 { "AC97_GENERAL_PURPOSE", 0x100 + AC97_GENERAL_PURPOSE, 16 },
348 { "AC97_3D_CONTROL", 0x100 + AC97_3D_CONTROL, 16 },
349 { "AC97_MODEM_RATE", 0x100 + AC97_MODEM_RATE, 16 },
350 { "AC97_POWER_CONTROL", 0x100 + AC97_POWER_CONTROL, 16 },
351 { NULL }
352 };
353
354 if (dev == NULL)
355 return -ENODEV;
356
357 for (i = 0; regs[i].name != 0; i++)
358 out += sprintf(out, "%s: 0x%0*x\n", regs[i].name,
359 regs[i].width >> 2,
360 (regs[i].width == 16
361 ? AD1889_READW(dev, regs[i].offset)
362 : AD1889_READL(dev, regs[i].offset)));
363
364 for (i = 0; i < AD_MAX_STATES; i++) {
365 out += sprintf(out, "DMA status for %s:\n",
366 (i == AD_WAV_STATE ? "WAV" : "ADC"));
367 out += sprintf(out, "\t\t0x%p (IOVA: 0x%llu)\n",
368 dev->state[i].dmabuf.rawbuf,
369 (unsigned long long)dev->state[i].dmabuf.dma_handle);
370
371 out += sprintf(out, "\tread ptr: offset %u\n",
372 (unsigned int)dev->state[i].dmabuf.rd_ptr);
373 out += sprintf(out, "\twrite ptr: offset %u\n",
374 (unsigned int)dev->state[i].dmabuf.wr_ptr);
375 out += sprintf(out, "\tdma len: offset %u\n",
376 (unsigned int)dev->state[i].dmabuf.dma_len);
377 }
378
379 len = out - page - off;
380 if (len < count) {
381 *eof = 1;
382 if (len <= 0) return 0;
383 } else {
384 len = count;
385 }
386 *start = page + off;
387 return len;
388}
389
390/***************************** DMA interfaces ************************** */
391#if 0
392static inline unsigned long ad1889_get_dma_addr(ad1889_state_t *state)
393{
394 struct dmabuf *dmabuf = &state->dmabuf;
395 u32 offset;
396
397 if (!(dmabuf->enable & (DAC_RUNNING | ADC_RUNNING))) {
398 printk(KERN_ERR DEVNAME ": get_dma_addr called without dma enabled\n");
399 return 0;
400 }
401
402 if (dmabuf->enable & DAC_RUNNING)
403 offset = le32_to_cpu(AD1889_READL(state->card, AD_DMAWAVBA));
404 else
405 offset = le32_to_cpu(AD1889_READL(state->card, AD_DMAADCBA));
406
407 return (unsigned long)bus_to_virt((unsigned long)offset) - (unsigned long)dmabuf->rawbuf;
408}
409
410static void ad1889_update_ptr(ad1889_dev_t *dev, int wake)
411{
412 ad1889_state_t *state;
413 struct dmabuf *dmabuf;
414 unsigned long hwptr;
415 int diff;
416
417 /* check ADC first */
418 state = &dev->adc_state;
419 dmabuf = &state->dmabuf;
420 if (dmabuf->enable & ADC_RUNNING) {
421 hwptr = ad1889_get_dma_addr(state);
422 diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize;
423
424 dmabuf->hwptr = hwptr;
425 dmabuf->total_bytes += diff;
426 dmabuf->count += diff;
427 if (dmabuf->count > dmabuf->dmasize)
428 dmabuf->count = dmabuf->dmasize;
429
430 if (dmabuf->mapped) {
431 if (wake & dmabuf->count >= dmabuf->fragsize)
432 wake_up(&dmabuf->wait);
433 } else {
434 if (wake & dmabuf->count > 0)
435 wake_up(&dmabuf->wait);
436 }
437 }
438
439 /* check DAC */
440 state = &dev->wav_state;
441 dmabuf = &state->dmabuf;
442 if (dmabuf->enable & DAC_RUNNING) {
443XXX
444
445}
446#endif
447
448/************************* /dev/dsp interfaces ************************* */
449
450static ssize_t ad1889_read(struct file *file, char __user *buffer, size_t count,
451 loff_t *ppos)
452{
453 return 0;
454}
455
456static ssize_t ad1889_write(struct file *file, const char __user *buffer, size_t count,
457 loff_t *ppos)
458{
459 ad1889_dev_t *dev = (ad1889_dev_t *)file->private_data;
460 ad1889_state_t *state = &dev->state[AD_WAV_STATE];
461 volatile struct dmabuf *dmabuf = &state->dmabuf;
462 ssize_t ret = 0;
463 DECLARE_WAITQUEUE(wait, current);
464
465 down(&state->sem);
466#if 0
467 if (dmabuf->mapped) {
468 ret = -ENXIO;
469 goto err1;
470 }
471#endif
472 if (!access_ok(VERIFY_READ, buffer, count)) {
473 ret = -EFAULT;
474 goto err1;
475 }
476
477 add_wait_queue(&state->dmabuf.wait, &wait);
478
479 /* start filling dma buffer.... */
480 while (count > 0) {
481 long rem;
482 long cnt = count;
483 unsigned long flags;
484
485 for (;;) {
486 long used_bytes;
487 long timeout; /* max time for DMA in jiffies */
488
489 /* buffer is full if wr catches up to rd */
490 spin_lock_irqsave(&state->card->lock, flags);
491 used_bytes = dmabuf->wr_ptr - dmabuf->rd_ptr;
492 timeout = (dmabuf->dma_len * HZ) / dmabuf->rate;
493 spin_unlock_irqrestore(&state->card->lock, flags);
494
495 /* adjust for buffer wrap around */
496 used_bytes = (used_bytes + DMA_SIZE) & (DMA_SIZE - 1);
497
498 /* If at least one page unused */
499 if (used_bytes < (DMA_SIZE - 0x1000))
500 break;
501
502 /* dma buffer full */
503
504 if (file->f_flags & O_NONBLOCK) {
505 ret = -EAGAIN;
506 goto err2;
507 }
508
509 set_current_state(TASK_INTERRUPTIBLE);
510 schedule_timeout(timeout + 1);
511 if (signal_pending(current)) {
512 ret = -ERESTARTSYS;
513 goto err2;
514 }
515 }
516
517 /* watch out for wrapping around static buffer */
518 spin_lock_irqsave(&state->card->lock, flags);
519 rem = DMA_SIZE - dmabuf->wr_ptr;
520 if (cnt > rem)
521 cnt = rem;
522
523 rem = dmabuf->wr_ptr;
524
525 /* update dma pointers */
526 dmabuf->wr_ptr += cnt;
527 dmabuf->wr_ptr &= DMA_SIZE - 1; /* wrap ptr if necessary */
528 spin_unlock_irqrestore(&state->card->lock, flags);
529
530 /* transfer unwrapped chunk */
531 if (copy_from_user(dmabuf->rawbuf + rem, buffer, cnt)) {
532 ret = -EFAULT;
533 goto err2;
534 }
535
536 DBG("Writing 0x%lx bytes to +0x%lx\n", cnt, rem);
537
538 /* update counters */
539 count -= cnt;
540 buffer += cnt;
541 ret += cnt;
542
543 /* we have something to play - go play it! */
544 ad1889_trigger_playback(dev);
545 }
546
547err2:
548 remove_wait_queue(&state->dmabuf.wait, &wait);
549err1:
550 up(&state->sem);
551 return ret;
552}
553
554static unsigned int ad1889_poll(struct file *file, struct poll_table_struct *wait)
555{
556 unsigned int mask = 0;
557#if 0
558 ad1889_dev_t *dev = (ad1889_dev_t *)file->private_data;
559 ad1889_state_t *state = NULL;
560 struct dmabuf *dmabuf;
561 unsigned long flags;
562
563 if (!(file->f_mode & (FMODE_READ | FMODE_WRITE)))
564 return -EINVAL;
565
566 if (file->f_mode & FMODE_WRITE) {
567 state = &dev->state[AD_WAV_STATE];
568 if (!state) return 0;
569 dmabuf = &state->dmabuf;
570 poll_wait(file, &dmabuf->wait, wait);
571 }
572
573 if (file->f_mode & FMODE_READ) {
574 state = &dev->state[AD_ADC_STATE];
575 if (!state) return 0;
576 dmabuf = &state->dmabuf;
577 poll_wait(file, &dmabuf->wait, wait);
578 }
579
580 spin_lock_irqsave(&dev->lock, flags);
581 ad1889_update_ptr(dev, 0);
582
583 if (file->f_mode & FMODE_WRITE) {
584 state = &dev->state[WAV_STATE];
585 dmabuf = &state->dmabuf;
586 if (dmabuf->mapped) {
587 if (dmabuf->count >= (int)dmabuf->fragsize)
588 mask |= POLLOUT | POLLWRNORM;
589 } else {
590 if ((int)dmabuf->dmasize >= dmabuf->count +
591 (int)dmabuf->fragsize)
592 mask |= POLLOUT | POLLWRNORM;
593 }
594 }
595
596 if (file ->f_mode & FMODE_READ) {
597 state = &dev->state[AD_ADC_STATE];
598 dmabuf = &state->dmabuf;
599 if (dmabuf->count >= (int)dmabuf->fragsize)
600 mask |= POLLIN | POLLRDNORM;
601 }
602 spin_unlock_irqrestore(&dev->lock, flags);
603
604#endif
605 return mask;
606}
607
608static int ad1889_mmap(struct file *file, struct vm_area_struct *vma)
609{
610 return 0;
611}
612
613static int ad1889_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
614 unsigned long arg)
615{
616 int val = 0;
617 ad1889_dev_t *dev = (ad1889_dev_t *)file->private_data;
618 struct dmabuf *dmabuf;
619 audio_buf_info abinfo;
620 int __user *p = (int __user *)arg;
621
622 DBG("ad1889_ioctl cmd 0x%x arg %lu\n", cmd, arg);
623
624 switch (cmd)
625 {
626 case OSS_GETVERSION:
627 return put_user(SOUND_VERSION, p);
628
629 case SNDCTL_DSP_RESET:
630 break;
631
632 case SNDCTL_DSP_SYNC:
633 break;
634
635 case SNDCTL_DSP_SPEED:
636 /* set sampling rate */
637 if (get_user(val, p))
638 return -EFAULT;
639 if (val > 5400 && val < 48000)
640 {
641 if (file->f_mode & FMODE_WRITE)
642 AD1889_WRITEW(ad1889_dev, AD_DSWAS, val);
643 if (file->f_mode & FMODE_READ)
644 AD1889_WRITEW(ad1889_dev, AD_DSRES, val);
645 }
646 return 0;
647
648 case SNDCTL_DSP_STEREO: /* undocumented? */
649 if (get_user(val, p))
650 return -EFAULT;
651 if (file->f_mode & FMODE_READ) {
652 val = AD1889_READW(ad1889_dev, AD_DSWSMC);
653 if (val) {
654 val |= 0x0200; /* set WAST */
655 } else {
656 val &= ~0x0200; /* clear WAST */
657 }
658 AD1889_WRITEW(ad1889_dev, AD_DSWSMC, val);
659 }
660 if (file->f_mode & FMODE_WRITE) {
661 val = AD1889_READW(ad1889_dev, AD_DSRAMC);
662 if (val) {
663 val |= 0x0002; /* set ADST */
664 } else {
665 val &= ~0x0002; /* clear ADST */
666 }
667 AD1889_WRITEW(ad1889_dev, AD_DSRAMC, val);
668 }
669
670 return 0;
671
672 case SNDCTL_DSP_GETBLKSIZE:
673 return put_user(DMA_SIZE, p);
674
675 case SNDCTL_DSP_GETFMTS:
676 return put_user(AFMT_S16_LE|AFMT_U8, p);
677
678 case SNDCTL_DSP_SETFMT:
679 if (get_user(val, p))
680 return -EFAULT;
681
682 if (val == 0) {
683 if (file->f_mode & FMODE_READ)
684 ad1889_set_adc_fmt(dev, val);
685
686 if (file->f_mode & FMODE_WRITE)
687 ad1889_set_wav_fmt(dev, val);
688 } else {
689 val = AFMT_S16_LE | AFMT_U8;
690 }
691
692 return put_user(val, p);
693
694 case SNDCTL_DSP_CHANNELS:
695 break;
696
697 case SNDCTL_DSP_POST:
698 /* send all data to device */
699 break;
700
701 case SNDCTL_DSP_SUBDIVIDE:
702 break;
703
704 case SNDCTL_DSP_SETFRAGMENT:
705 /* not supported; uses fixed fragment sizes */
706 return put_user(DMA_SIZE, p);
707
708 case SNDCTL_DSP_GETOSPACE:
709 case SNDCTL_DSP_GETISPACE:
710 /* space left in dma buffers */
711 if (cmd == SNDCTL_DSP_GETOSPACE)
712 dmabuf = &dev->state[AD_WAV_STATE].dmabuf;
713 else
714 dmabuf = &dev->state[AD_ADC_STATE].dmabuf;
715 abinfo.fragments = 1;
716 abinfo.fragstotal = 1;
717 abinfo.fragsize = DMA_SIZE;
718 abinfo.bytes = DMA_SIZE;
719 return copy_to_user(p, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
720 case SNDCTL_DSP_NONBLOCK:
721 file->f_flags |= O_NONBLOCK;
722 return 0;
723
724 case SNDCTL_DSP_GETCAPS:
725 return put_user(0, p);
726
727 case SNDCTL_DSP_GETTRIGGER:
728 case SNDCTL_DSP_SETTRIGGER:
729 break;
730
731 case SNDCTL_DSP_GETIPTR:
732 case SNDCTL_DSP_GETOPTR:
733 break;
734
735 case SNDCTL_DSP_SETDUPLEX:
736 break;
737
738 case SNDCTL_DSP_GETODELAY:
739 break;
740
741 case SOUND_PCM_READ_RATE:
742 return put_user(AD1889_READW(ad1889_dev, AD_DSWAS), p);
743
744 case SOUND_PCM_READ_CHANNELS:
745 case SOUND_PCM_READ_BITS:
746 break;
747
748 case SNDCTL_DSP_MAPINBUF:
749 case SNDCTL_DSP_MAPOUTBUF:
750 case SNDCTL_DSP_SETSYNCRO:
751 case SOUND_PCM_WRITE_FILTER:
752 case SOUND_PCM_READ_FILTER:
753 break;
754
755 default:
756 break;
757 }
758
759 return -ENOTTY;
760}
761
762static int ad1889_open(struct inode *inode, struct file *file)
763{
764 /* check minor; only support /dev/dsp atm */
765 if (iminor(inode) != 3)
766 return -ENXIO;
767
768 file->private_data = ad1889_dev;
769
770 ad1889_set_wav_rate(ad1889_dev, 48000);
771 ad1889_set_wav_fmt(ad1889_dev, AFMT_S16_LE);
772 AD1889_WRITEW(ad1889_dev, AD_DSWADA, 0x0404); /* attenuation */
773 return nonseekable_open(inode, file);
774}
775
776static int ad1889_release(struct inode *inode, struct file *file)
777{
778 /* if we have state free it here */
779 return 0;
780}
781
782static struct file_operations ad1889_fops = {
783 .owner = THIS_MODULE,
784 .llseek = no_llseek,
785 .read = ad1889_read,
786 .write = ad1889_write,
787 .poll = ad1889_poll,
788 .ioctl = ad1889_ioctl,
789 .mmap = ad1889_mmap,
790 .open = ad1889_open,
791 .release = ad1889_release,
792};
793
794/************************* /dev/mixer interfaces ************************ */
795static int ad1889_mixer_open(struct inode *inode, struct file *file)
796{
797 if (ad1889_dev->ac97_codec->dev_mixer != iminor(inode))
798 return -ENODEV;
799
800 file->private_data = ad1889_dev->ac97_codec;
801 return 0;
802}
803
804static int ad1889_mixer_release(struct inode *inode, struct file *file)
805{
806 return 0;
807}
808
809static int ad1889_mixer_ioctl(struct inode *inode, struct file *file,
810 unsigned int cmd, unsigned long arg)
811{
812 struct ac97_codec *codec = (struct ac97_codec *)file->private_data;
813 return codec->mixer_ioctl(codec, cmd, arg);
814}
815
816static struct file_operations ad1889_mixer_fops = {
817 .owner = THIS_MODULE,
818 .llseek = no_llseek,
819 .ioctl = ad1889_mixer_ioctl,
820 .open = ad1889_mixer_open,
821 .release = ad1889_mixer_release,
822};
823
824/************************* AC97 interfaces ****************************** */
825static void ad1889_codec_write(struct ac97_codec *ac97, u8 reg, u16 val)
826{
827 ad1889_dev_t *dev = ac97->private_data;
828
829 //DBG("Writing 0x%x to 0x%lx\n", val, dev->regbase + 0x100 + reg);
830 AD1889_WRITEW(dev, 0x100 + reg, val);
831}
832
833static u16 ad1889_codec_read(struct ac97_codec *ac97, u8 reg)
834{
835 ad1889_dev_t *dev = ac97->private_data;
836 //DBG("Reading from 0x%lx\n", dev->regbase + 0x100 + reg);
837 return AD1889_READW(dev, 0x100 + reg);
838}
839
840static int ad1889_ac97_init(ad1889_dev_t *dev, int id)
841{
842 struct ac97_codec *ac97;
843 u16 eid;
844
845 if ((ac97 = ac97_alloc_codec()) == NULL)
846 return -ENOMEM;
847
848 ac97->private_data = dev;
849 ac97->id = id;
850
851 ac97->codec_read = ad1889_codec_read;
852 ac97->codec_write = ad1889_codec_write;
853
854 if (ac97_probe_codec(ac97) == 0) {
855 printk(DEVNAME ": ac97_probe_codec failed\n");
856 goto out_free;
857 }
858
859 eid = ad1889_codec_read(ac97, AC97_EXTENDED_ID);
860 if (eid == 0xffff) {
861 printk(KERN_WARNING DEVNAME ": no codec attached?\n");
862 goto out_free;
863 }
864
865 dev->ac97_features = eid;
866
867 if ((ac97->dev_mixer = register_sound_mixer(&ad1889_mixer_fops, -1)) < 0) {
868 printk(KERN_ERR DEVNAME ": cannot register mixer\n");
869 goto out_free;
870 }
871
872 dev->ac97_codec = ac97;
873 return 0;
874
875out_free:
876 ac97_release_codec(ac97);
877 return -ENODEV;
878}
879
880static int ad1889_aclink_reset(struct pci_dev * pcidev)
881{
882 u16 stat;
883 int retry = 200;
884 ad1889_dev_t *dev = pci_get_drvdata(pcidev);
885
886 AD1889_WRITEW(dev, AD_DSCCS, 0x8000); /* turn on clock */
887 AD1889_READW(dev, AD_DSCCS);
888
889 WAIT_10MS();
890
891 stat = AD1889_READW(dev, AD_ACIC);
892 stat |= 0x0002; /* Reset Disable */
893 AD1889_WRITEW(dev, AD_ACIC, stat);
894 (void) AD1889_READW(dev, AD_ACIC); /* flush posted write */
895
896 udelay(10);
897
898 stat = AD1889_READW(dev, AD_ACIC);
899 stat |= 0x0001; /* Interface Enable */
900 AD1889_WRITEW(dev, AD_ACIC, stat);
901
902 do {
903 if (AD1889_READW(dev, AD_ACIC) & 0x8000) /* Ready */
904 break;
905 WAIT_10MS();
906 retry--;
907 } while (retry > 0);
908
909 if (!retry) {
910 printk(KERN_ERR "ad1889_aclink_reset: codec is not ready [0x%x]\n",
911 AD1889_READW(dev, AD_ACIC));
912 return -EBUSY;
913 }
914
915 /* TODO reset AC97 codec */
916 /* TODO set wave/adc pci ctrl status */
917
918 stat = AD1889_READW(dev, AD_ACIC);
919 stat |= 0x0004; /* Audio Stream Output Enable */
920 AD1889_WRITEW(dev, AD_ACIC, stat);
921 return 0;
922}
923
924/************************* PCI interfaces ****************************** */
925/* PCI device table */
926static struct pci_device_id ad1889_id_tbl[] = {
927 { PCI_VENDOR_ID_ANALOG_DEVICES, PCI_DEVICE_ID_AD1889JS, PCI_ANY_ID,
928 PCI_ANY_ID, 0, 0, (unsigned long)DEVNAME },
929 { },
930};
931MODULE_DEVICE_TABLE(pci, ad1889_id_tbl);
932
933static irqreturn_t ad1889_interrupt(int irq, void *dev_id, struct pt_regs *regs)
934{
935 u32 stat;
936 ad1889_dev_t *dev = (ad1889_dev_t *)dev_id;
937
938 stat = AD1889_READL(dev, AD_DMADISR);
939
940 /* clear ISR */
941 AD1889_WRITEL(dev, AD_DMADISR, stat);
942
943 if (stat & 0x8) { /* WAVI */
944 DBG("WAV interrupt\n");
945 dev->stats.wav_intrs++;
946 if (dev->state[AD_WAV_STATE].dmabuf.ready) {
947 ad1889_stop_wav(&dev->state[AD_WAV_STATE]); /* clean up */
948 ad1889_start_wav(&dev->state[AD_WAV_STATE]); /* start new */
949 }
950 }
951
952 if ((stat & 0x2) && dev->state[AD_ADC_STATE].dmabuf.ready) { /* ADCI */
953 DBG("ADC interrupt\n");
954 dev->stats.adc_intrs++;
955 }
956 if(stat)
957 return IRQ_HANDLED;
958 return IRQ_NONE;
959}
960
961static void ad1889_initcfg(ad1889_dev_t *dev)
962{
963 u16 tmp16;
964 u32 tmp32;
965
966 /* make sure the interrupt bits are setup the way we want */
967 tmp32 = AD1889_READL(dev, AD_DMAWAVCTRL);
968 tmp32 &= ~0xff; /* flat dma, no sg, mask out the intr bits */
969 tmp32 |= 0x6; /* intr on count, loop */
970 AD1889_WRITEL(dev, AD_DMAWAVCTRL, tmp32);
971
972 /* unmute... */
973 tmp16 = AD1889_READW(dev, AD_DSWADA);
974 tmp16 &= ~0x8080;
975 AD1889_WRITEW(dev, AD_DSWADA, tmp16);
976}
977
978static int __devinit ad1889_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
979{
980 int err;
981 ad1889_dev_t *dev;
982 unsigned long bar;
983 struct proc_dir_entry *proc_root = NULL;
984
985 if ((err = pci_enable_device(pcidev)) != 0) {
986 printk(KERN_ERR DEVNAME ": pci_enable_device failed\n");
987 return err;
988 }
989
990 pci_set_master(pcidev);
991 if ((dev = ad1889_alloc_dev(pcidev)) == NULL) {
992 printk(KERN_ERR DEVNAME ": cannot allocate memory for device\n");
993 return -ENOMEM;
994 }
995 pci_set_drvdata(pcidev, dev);
996 bar = pci_resource_start(pcidev, 0);
997
998 if (!(pci_resource_flags(pcidev, 0) & IORESOURCE_MEM)) {
999 printk(KERN_ERR DEVNAME ": memory region not assigned\n");
1000 goto out1;
1001 }
1002
1003 if (pci_request_region(pcidev, 0, DEVNAME)) {
1004 printk(KERN_ERR DEVNAME ": unable to request memory region\n");
1005 goto out1;
1006 }
1007
1008 dev->regbase = ioremap_nocache(bar, AD_DSIOMEMSIZE);
1009 if (!dev->regbase) {
1010 printk(KERN_ERR DEVNAME ": unable to remap iomem\n");
1011 goto out2;
1012 }
1013
1014 if (request_irq(pcidev->irq, ad1889_interrupt, SA_SHIRQ, DEVNAME, dev) != 0) {
1015 printk(KERN_ERR DEVNAME ": unable to request interrupt\n");
1016 goto out3;
1017 }
1018
1019 printk(KERN_INFO DEVNAME ": %s at %p IRQ %d\n",
1020 (char *)ent->driver_data, dev->regbase, pcidev->irq);
1021
1022 if (ad1889_aclink_reset(pcidev) != 0)
1023 goto out4;
1024
1025 /* register /dev/dsp */
1026 if ((dev->dev_audio = register_sound_dsp(&ad1889_fops, -1)) < 0) {
1027 printk(KERN_ERR DEVNAME ": cannot register /dev/dsp\n");
1028 goto out4;
1029 }
1030
1031 if ((err = ad1889_ac97_init(dev, 0)) != 0)
1032 goto out5;
1033
1034 /* XXX: cleanups */
1035 if (((proc_root = proc_mkdir("driver/ad1889", NULL)) == NULL) ||
1036 create_proc_read_entry("ac97", S_IFREG|S_IRUGO, proc_root, ac97_read_proc, dev->ac97_codec) == NULL ||
1037 create_proc_read_entry("info", S_IFREG|S_IRUGO, proc_root, ad1889_read_proc, dev) == NULL)
1038 goto out5;
1039
1040 ad1889_initcfg(dev);
1041
1042 //DBG(DEVNAME ": Driver initialization done!\n");
1043
1044 ad1889_dev = dev;
1045
1046 return 0;
1047
1048out5:
1049 unregister_sound_dsp(dev->dev_audio);
1050out4:
1051 free_irq(pcidev->irq, dev);
1052out3:
1053 iounmap(dev->regbase);
1054out2:
1055 pci_release_region(pcidev, 0);
1056out1:
1057 ad1889_free_dev(dev);
1058 pci_set_drvdata(pcidev, NULL);
1059
1060 return -ENODEV;
1061}
1062
1063static void __devexit ad1889_remove(struct pci_dev *pcidev)
1064{
1065 ad1889_dev_t *dev = pci_get_drvdata(pcidev);
1066
1067 if (dev == NULL) return;
1068
1069 unregister_sound_mixer(dev->ac97_codec->dev_mixer);
1070 unregister_sound_dsp(dev->dev_audio);
1071 free_irq(pcidev->irq, dev);
1072 iounmap(dev->regbase);
1073 pci_release_region(pcidev, 0);
1074
1075 /* any hw programming needed? */
1076 ad1889_free_dev(dev);
1077 pci_set_drvdata(pcidev, NULL);
1078}
1079
1080MODULE_AUTHOR("Randolph Chung");
1081MODULE_DESCRIPTION("Analog Devices AD1889 PCI Audio");
1082MODULE_LICENSE("GPL");
1083
1084static struct pci_driver ad1889_driver = {
1085 .name = DEVNAME,
1086 .id_table = ad1889_id_tbl,
1087 .probe = ad1889_probe,
1088 .remove = __devexit_p(ad1889_remove),
1089};
1090
1091static int __init ad1889_init_module(void)
1092{
1093 return pci_module_init(&ad1889_driver);
1094}
1095
1096static void ad1889_exit_module(void)
1097{
1098 pci_unregister_driver(&ad1889_driver);
1099 return;
1100}
1101
1102module_init(ad1889_init_module);
1103module_exit(ad1889_exit_module);
diff --git a/sound/oss/ad1889.h b/sound/oss/ad1889.h
new file mode 100644
index 000000000000..e04affce1dd1
--- /dev/null
+++ b/sound/oss/ad1889.h
@@ -0,0 +1,134 @@
1#ifndef _AD1889_H_
2#define _AD1889_H_
3
4#define AD_DSWSMC 0x00 /* DMA input wave/syn mixer control */
5#define AD_DSRAMC 0x02 /* DMA output resamp/ADC mixer control */
6#define AD_DSWADA 0x04 /* DMA input wave attenuation */
7#define AD_DSSYDA 0x06 /* DMA input syn attentuation */
8#define AD_DSWAS 0x08 /* wave input sample rate */
9#define AD_DSRES 0x0a /* resampler output sample rate */
10#define AD_DSCCS 0x0c /* chip control/status */
11
12#define AD_DMARESBA 0x40 /* RES base addr */
13#define AD_DMARESCA 0x44 /* RES current addr */
14#define AD_DMARESBC 0x48 /* RES base cnt */
15#define AD_DMARESCC 0x4c /* RES current count */
16#define AD_DMAADCBA 0x50 /* ADC */
17#define AD_DMAADCCA 0x54
18#define AD_DMAADCBC 0x58
19#define AD_DMAADCCC 0x5c
20#define AD_DMASYNBA 0x60 /* SYN */
21#define AD_DMASYNCA 0x64
22#define AD_DMASYNBC 0x68
23#define AD_DMASYNCC 0x6c
24#define AD_DMAWAVBA 0x70 /* WAV */
25#define AD_DMAWAVCA 0x74
26#define AD_DMAWAVBC 0x78
27#define AD_DMAWAVCC 0x7c
28#define AD_DMARESICC 0x80 /* RES interrupt current count */
29#define AD_DMARESIBC 0x84 /* RES interrupt base count */
30#define AD_DMAADCICC 0x88 /* ADC interrupt current count */
31#define AD_DMAADCIBC 0x8c /* ADC interrupt base count */
32#define AD_DMASYNICC 0x90 /* SYN interrupt current count */
33#define AD_DMASYNIBC 0x94 /* SYN interrupt base count */
34#define AD_DMAWAVICC 0x98 /* WAV interrupt current count */
35#define AD_DMAWAVIBC 0x9c /* WAV interrupt base count */
36#define AD_DMARESCTRL 0xa0 /* RES PCI control/status */
37#define AD_DMAADCCTRL 0xa8 /* ADC PCI control/status */
38#define AD_DMASYNCTRL 0xb0 /* SYN PCI control/status */
39#define AD_DMAWAVCTRL 0xb8 /* WAV PCI control/status */
40#define AD_DMADISR 0xc0 /* PCI DMA intr status */
41#define AD_DMACHSS 0xc4 /* PCI DMA channel stop status */
42
43#define AD_GPIOIPC 0xc8 /* IO port ctrl */
44#define AD_GPIOOP 0xca /* IO output status */
45#define AD_GPIOIP 0xcc /* IO input status */
46
47/* AC97 registers, 0x100 - 0x17f; see ac97.h */
48#define AD_ACIC 0x180 /* AC Link interface ctrl */
49
50/* OPL3; BAR1 */
51#define AD_OPLM0AS 0x00 /* Music0 address/status */
52#define AD_OPLM0DATA 0x01 /* Music0 data */
53#define AD_OPLM1A 0x02 /* Music1 address */
54#define AD_OPLM1DATA 0x03 /* Music1 data */
55/* 0x04-0x0f reserved */
56
57/* MIDI; BAR2 */
58#define AD_MIDA 0x00 /* MIDI data */
59#define AD_MISC 0x01 /* MIDI status/cmd */
60/* 0x02-0xff reserved */
61
62#define AD_DSIOMEMSIZE 512
63#define AD_OPLMEMSIZE 16
64#define AD_MIDIMEMSIZE 16
65
66#define AD_WAV_STATE 0
67#define AD_ADC_STATE 1
68#define AD_MAX_STATES 2
69
70#define DMA_SIZE (128*1024)
71
72#define DMA_FLAG_MAPPED 1
73
74struct ad1889_dev;
75
76typedef struct ad1889_state {
77 struct ad1889_dev *card;
78
79 mode_t open_mode;
80 struct dmabuf {
81 unsigned int rate;
82 unsigned char fmt, enable;
83
84 /* buf management */
85 size_t rawbuf_size;
86 void *rawbuf;
87 dma_addr_t dma_handle; /* mapped address */
88 unsigned long dma_len; /* number of bytes mapped */
89
90 /* indexes into rawbuf for setting up DMA engine */
91 volatile unsigned long rd_ptr, wr_ptr;
92
93 wait_queue_head_t wait; /* to wait for buf servicing */
94
95 /* OSS bits */
96 unsigned int mapped:1;
97 unsigned int ready:1;
98 unsigned int ossfragshift;
99 int ossmaxfrags;
100 unsigned int subdivision;
101 } dmabuf;
102
103 struct semaphore sem;
104} ad1889_state_t;
105
106typedef struct ad1889_dev {
107 void __iomem *regbase;
108 struct pci_dev *pci;
109
110 spinlock_t lock;
111
112 int dev_audio;
113
114 /* states; one per channel; right now only WAV and ADC */
115 struct ad1889_state state[AD_MAX_STATES];
116
117 /* AC97 codec */
118 struct ac97_codec *ac97_codec;
119 u16 ac97_features;
120
121 /* debugging stuff */
122 struct stats {
123 unsigned int wav_intrs, adc_intrs;
124 unsigned int blocks, underrun, error;
125 } stats;
126} ad1889_dev_t;
127
128typedef struct ad1889_reg {
129 const char *name;
130 int offset;
131 int width;
132} ad1889_reg_t;
133
134#endif
diff --git a/sound/oss/adlib_card.c b/sound/oss/adlib_card.c
new file mode 100644
index 000000000000..6414ceb8f072
--- /dev/null
+++ b/sound/oss/adlib_card.c
@@ -0,0 +1,73 @@
1/*
2 * sound/adlib_card.c
3 *
4 * Detection routine for the AdLib card.
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#include <linux/module.h>
14#include <linux/init.h>
15
16#include "sound_config.h"
17
18#include "opl3.h"
19
20static void __init attach_adlib_card(struct address_info *hw_config)
21{
22 hw_config->slots[0] = opl3_init(hw_config->io_base, hw_config->osp, THIS_MODULE);
23}
24
25static int __init probe_adlib(struct address_info *hw_config)
26{
27 return opl3_detect(hw_config->io_base, hw_config->osp);
28}
29
30static struct address_info cfg;
31
32static int __initdata io = -1;
33
34module_param(io, int, 0);
35
36static int __init init_adlib(void)
37{
38 cfg.io_base = io;
39
40 if (cfg.io_base == -1) {
41 printk(KERN_ERR "adlib: must specify I/O address.\n");
42 return -EINVAL;
43 }
44 if (probe_adlib(&cfg) == 0)
45 return -ENODEV;
46 attach_adlib_card(&cfg);
47
48 return 0;
49}
50
51static void __exit cleanup_adlib(void)
52{
53 sound_unload_synthdev(cfg.slots[0]);
54
55}
56
57module_init(init_adlib);
58module_exit(cleanup_adlib);
59
60#ifndef MODULE
61static int __init setup_adlib(char *str)
62{
63 /* io */
64 int ints[2];
65 str = get_options(str, ARRAY_SIZE(ints), ints);
66
67 io = ints[1];
68
69 return 1;
70}
71__setup("adlib=", setup_adlib);
72#endif
73MODULE_LICENSE("GPL");
diff --git a/sound/oss/aedsp16.c b/sound/oss/aedsp16.c
new file mode 100644
index 000000000000..b556263a57f5
--- /dev/null
+++ b/sound/oss/aedsp16.c
@@ -0,0 +1,1381 @@
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/config.h>
27#include <linux/delay.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include "sound_config.h"
31
32/*
33 * Sanity checks
34 */
35
36#if defined(CONFIG_SOUND_AEDSP16_SBPRO) && defined(CONFIG_SOUND_AEDSP16_MSS)
37#error You have to enable only one of the MSS and SBPRO emulations.
38#endif
39
40/*
41
42 READ THIS
43
44 This module started to configure the Audio Excel DSP 16 Sound Card.
45 Now works with the SC-6000 (old aedsp16) and new SC-6600 based cards.
46
47 NOTE: I have NO idea about Audio Excel DSP 16 III. If someone owns this
48 audio card and want to see the kernel support for it, please contact me.
49
50 Audio Excel DSP 16 is an SB pro II, Microsoft Sound System and MPU-401
51 compatible card.
52 It is software-only configurable (no jumpers to hard-set irq/dma/mpu-irq),
53 so before this module, the only way to configure the DSP under linux was
54 boot the MS-DOS loading the sound.sys device driver (this driver soft-
55 configure the sound board hardware by massaging someone of its registers),
56 and then ctrl-alt-del to boot linux with the DSP configured by the DOS
57 driver.
58
59 This module works configuring your Audio Excel DSP 16's irq, dma and
60 mpu-401-irq. The OSS Lite routines rely on the fact that if the
61 hardware is there, they can detect it. The problem with AEDSP16 is
62 that no hardware can be found by the probe routines if the sound card
63 is not configured properly. Sometimes the kernel probe routines can find
64 an SBPRO even when the card is not configured (this is the standard setup
65 of the card), but the SBPRO emulation don't work well if the card is not
66 properly initialized. For this reason
67
68 aedsp16_init_board()
69
70 routine is called before the OSS Lite probe routines try to detect the
71 hardware.
72
73 NOTE (READ THE NOTE TOO, IT CONTAIN USEFUL INFORMATIONS)
74
75 NOTE: Now it works with SC-6000 and SC-6600 based audio cards. The new cards
76 have no jumper switch at all. No more WSS or MPU-401 I/O port switches. They
77 have to be configured by software.
78
79 NOTE: The driver is merged with the new OSS Lite sound driver. It works
80 as a lowlevel driver.
81
82 The Audio Excel DSP 16 Sound Card emulates both SBPRO and MSS;
83 the OSS Lite sound driver can be configured for SBPRO and MSS cards
84 at the same time, but the aedsp16 can't be two cards!!
85 When we configure it, we have to choose the SBPRO or the MSS emulation
86 for AEDSP16. We also can install a *REAL* card of the other type (see [1]).
87
88 NOTE: If someone can test the combination AEDSP16+MSS or AEDSP16+SBPRO
89 please let me know if it works.
90
91 The MPU-401 support can be compiled in together with one of the other
92 two operating modes.
93
94 NOTE: This is something like plug-and-play: we have only to plug
95 the AEDSP16 board in the socket, and then configure and compile
96 a kernel that uses the AEDSP16 software configuration capability.
97 No jumper setting is needed!
98
99 For example, if you want AEDSP16 to be an SBPro, on irq 10, dma 3
100 you have just to make config the OSS Lite package, configuring
101 the AEDSP16 sound card, then activating the SBPro emulation mode
102 and at last configuring IRQ and DMA.
103 Compile the kernel and run it.
104
105 NOTE: This means for SC-6000 cards that you can choose irq and dma,
106 but not the I/O addresses. To change I/O addresses you have to set
107 them with jumpers. For SC-6600 cards you have no jumpers so you have
108 to set up your full card configuration in the make config.
109
110 You can change the irq/dma/mirq settings WITHOUT THE NEED to open
111 your computer and massage the jumpers (there are no irq/dma/mirq
112 jumpers to be configured anyway, only I/O BASE values have to be
113 configured with jumpers)
114
115 For some ununderstandable reason, the card default of irq 7, dma 1,
116 don't work for me. Seems to be an IRQ or DMA conflict. Under heavy
117 HDD work, the kernel start to erupt out a lot of messages like:
118
119 'Sound: DMA timed out - IRQ/DRQ config error?'
120
121 For what I can say, I have NOT any conflict at irq 7 (under linux I'm
122 using the lp polling driver), and dma line 1 is unused as stated by
123 /proc/dma. I can suppose this is a bug of AEDSP16. I know my hardware so
124 I'm pretty sure I have not any conflict, but may be I'm wrong. Who knows!
125 Anyway a setting of irq 10, dma 3 works really fine.
126
127 NOTE: if someone can use AEDSP16 with irq 7, dma 1, please let me know
128 the emulation mode, all the installed hardware and the hardware
129 configuration (irq and dma settings of all the hardware).
130
131 This init module should work with SBPRO+MSS, when one of the two is
132 the AEDSP16 emulation and the other the real card. (see [1])
133 For example:
134
135 AEDSP16 (0x220) in SBPRO emu (0x220) + real MSS + other
136 AEDSP16 (0x220) in MSS emu + real SBPRO (0x240) + other
137
138 MPU401 should work. (see [2])
139
140 [1]
141 ---
142 Date: Mon, 29 Jul 1997 08:35:40 +0100
143 From: Mr S J Greenaway <sjg95@unixfe.rl.ac.uk>
144
145 [...]
146 Just to let you know got my Audio Excel (emulating a MSS) working
147 with my original SB16, thanks for the driver!
148 [...]
149 ---
150
151 [2] Not tested by me for lack of hardware.
152
153 TODO, WISHES AND TECH
154
155 - About I/O ports allocation -
156
157 Request the 2x0h region (port base) in any case if we are using this card.
158
159 NOTE: the "aedsp16 (base)" string with which we are requesting the aedsp16
160 port base region (see code) does not mean necessarily that we are emulating
161 sbpro. Even if this region is the sbpro I/O ports region, we use this
162 region to access the control registers of the card, and if emulating
163 sbpro, I/O sbpro registers too. If we are emulating MSS, the sbpro
164 registers are not used, in no way, to emulate an sbpro: they are
165 used only for configuration purposes.
166
167 Started Fri Mar 17 16:13:18 MET 1995
168
169 v0.1 (ALPHA, was an user-level program called AudioExcelDSP16.c)
170 - Initial code.
171 v0.2 (ALPHA)
172 - Cleanups.
173 - Integrated with Linux voxware v 2.90-2 kernel sound driver.
174 - SoundBlaster Pro mode configuration.
175 - Microsoft Sound System mode configuration.
176 - MPU-401 mode configuration.
177 v0.3 (ALPHA)
178 - Cleanups.
179 - Rearranged the code to let aedsp16_init_board be more general.
180 - Erased the REALLY_SLOW_IO. We don't need it. Erased the linux/io.h
181 inclusion too. We rely on os.h
182 - Used the to get a variable
183 len string (we are not sure about the len of Copyright string).
184 This works with any SB and compatible.
185 - Added the code to request_region at device init (should go in
186 the main body of voxware).
187 v0.4 (BETA)
188 - Better configure.c patch for aedsp16 configuration (better
189 logic of inclusion of AEDSP16 support)
190 - Modified the conditional compilation to better support more than
191 one sound card of the emulated type (read the NOTES above)
192 - Moved the sb init routine from the attach to the very first
193 probe in sb_card.c
194 - Rearrangements and cleanups
195 - Wiped out some unnecessary code and variables: this is kernel
196 code so it is better save some TEXT and DATA
197 - Fixed the request_region code. We must allocate the aedsp16 (sbpro)
198 I/O ports in any case because they are used to access the DSP
199 configuration registers and we can not allow anyone to get them.
200 v0.5
201 - cleanups on comments
202 - prep for diffs against v3.0-proto-950402
203 v0.6
204 - removed the request_region()s when compiling the MODULE sound.o
205 because we are not allowed (by the actual voxware structure) to
206 release_region()
207 v0.7 (pre ALPHA, not distributed)
208 - started porting this module to kernel 1.3.84. Dummy probe/attach
209 routines.
210 v0.8 (ALPHA)
211 - attached all the init routines.
212 v0.9 (BETA)
213 - Integrated with linux-pre2.0.7
214 - Integrated with configuration scripts.
215 - Cleaned up and beautyfied the code.
216 v0.9.9 (BETA)
217 - Thanks to Piercarlo Grandi: corrected the conditonal compilation code.
218 Now only the code configured is compiled in, with some memory saving.
219 v0.9.10
220 - Integration into the sound/lowlevel/ section of the sound driver.
221 - Re-organized the code.
222 v0.9.11 (not distributed)
223 - Rewritten the init interface-routines to initialize the AEDSP16 in
224 one shot.
225 - More cosmetics.
226 - SC-6600 support.
227 - More soft/hard configuration.
228 v0.9.12
229 - Refined the v0.9.11 code with conditional compilation to distinguish
230 between SC-6000 and SC-6600 code.
231 v1.0.0
232 - Prep for merging with OSS Lite and Linux kernel 2.1.13
233 - Corrected a bug in request/check/release region calls (thanks to the
234 new kernel exception handling).
235 v1.1
236 - Revamped for integration with new modularized sound drivers: to enhance
237 the flexibility of modular version, I have removed all the conditional
238 compilation for SBPRO, MPU and MSS code. Now it is all managed with
239 the ae_config structure.
240 v1.2
241 - Module informations added.
242 - Removed aedsp16_delay_10msec(), now using mdelay(10)
243 - All data and funcs moved to .*.init section.
244 v1.3
245 Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/09/27
246 - got rid of check_region
247
248 Known Problems:
249 - Audio Excel DSP 16 III don't work with this driver.
250
251 Credits:
252 Many thanks to Gerald Britton <gbritton@CapAccess.org>. He helped me a
253 lot in testing the 0.9.11 and 0.9.12 versions of this driver.
254
255 */
256
257
258#define VERSION "1.3" /* Version of Audio Excel DSP 16 driver */
259
260#undef AEDSP16_DEBUG /* Define this to 1 to enable debug code */
261#undef AEDSP16_DEBUG_MORE /* Define this to 1 to enable more debug */
262#undef AEDSP16_INFO /* Define this to 1 to enable info code */
263
264#if defined(AEDSP16_DEBUG)
265# define DBG(x) printk x
266# if defined(AEDSP16_DEBUG_MORE)
267# define DBG1(x) printk x
268# else
269# define DBG1(x)
270# endif
271#else
272# define DBG(x)
273# define DBG1(x)
274#endif
275
276/*
277 * Misc definitions
278 */
279#define TRUE 1
280#define FALSE 0
281
282/*
283 * Region Size for request/check/release region.
284 */
285#define IOBASE_REGION_SIZE 0x10
286
287/*
288 * Hardware related defaults
289 */
290#define DEF_AEDSP16_IOB 0x220 /* 0x220(default) 0x240 */
291#define DEF_AEDSP16_IRQ 7 /* 5 7(default) 9 10 11 */
292#define DEF_AEDSP16_MRQ 0 /* 5 7 9 10 0(default), 0 means disable */
293#define DEF_AEDSP16_DMA 1 /* 0 1(default) 3 */
294
295/*
296 * Commands of AEDSP16's DSP (SBPRO+special).
297 * Some of them are COMMAND_xx, in the future they may change.
298 */
299#define WRITE_MDIRQ_CFG 0x50 /* Set M&I&DRQ mask (the real config) */
300#define COMMAND_52 0x52 /* */
301#define READ_HARD_CFG 0x58 /* Read Hardware Config (I/O base etc) */
302#define COMMAND_5C 0x5c /* */
303#define COMMAND_60 0x60 /* */
304#define COMMAND_66 0x66 /* */
305#define COMMAND_6C 0x6c /* */
306#define COMMAND_6E 0x6e /* */
307#define COMMAND_88 0x88 /* */
308#define DSP_INIT_MSS 0x8c /* Enable Microsoft Sound System mode */
309#define COMMAND_C5 0xc5 /* */
310#define GET_DSP_VERSION 0xe1 /* Get DSP Version */
311#define GET_DSP_COPYRIGHT 0xe3 /* Get DSP Copyright */
312
313/*
314 * Offsets of AEDSP16 DSP I/O ports. The offset is added to base I/O port
315 * to have the actual I/O port.
316 * Register permissions are:
317 * (wo) == Write Only
318 * (ro) == Read Only
319 * (w-) == Write
320 * (r-) == Read
321 */
322#define DSP_RESET 0x06 /* offset of DSP RESET (wo) */
323#define DSP_READ 0x0a /* offset of DSP READ (ro) */
324#define DSP_WRITE 0x0c /* offset of DSP WRITE (w-) */
325#define DSP_COMMAND 0x0c /* offset of DSP COMMAND (w-) */
326#define DSP_STATUS 0x0c /* offset of DSP STATUS (r-) */
327#define DSP_DATAVAIL 0x0e /* offset of DSP DATA AVAILABLE (ro) */
328
329
330#define RETRY 10 /* Various retry values on I/O opera- */
331#define STATUSRETRY 1000 /* tions. Sometimes we have to */
332#define HARDRETRY 500000 /* wait for previous cmd to complete */
333
334/*
335 * Size of character arrays that store name and version of sound card
336 */
337#define CARDNAMELEN 15 /* Size of the card's name in chars */
338#define CARDVERLEN 2 /* Size of the card's version in chars */
339
340#if defined(CONFIG_SC6600)
341/*
342 * Bitmapped flags of hard configuration
343 */
344/*
345 * Decode macros (xl == low byte, xh = high byte)
346 */
347#define IOBASE(xl) ((xl & 0x01)?0x240:0x220)
348#define JOY(xl) (xl & 0x02)
349#define MPUADDR(xl) ( \
350 (xl & 0x0C)?0x330: \
351 (xl & 0x08)?0x320: \
352 (xl & 0x04)?0x310: \
353 0x300)
354#define WSSADDR(xl) ((xl & 0x10)?0xE80:0x530)
355#define CDROM(xh) (xh & 0x20)
356#define CDROMADDR(xh) (((xh & 0x1F) << 4) + 0x200)
357/*
358 * Encode macros
359 */
360#define BLDIOBASE(xl, val) { \
361 xl &= ~0x01; \
362 if (val == 0x240) \
363 xl |= 0x01; \
364 }
365#define BLDJOY(xl, val) { \
366 xl &= ~0x02; \
367 if (val == 1) \
368 xl |= 0x02; \
369 }
370#define BLDMPUADDR(xl, val) { \
371 xl &= ~0x0C; \
372 switch (val) { \
373 case 0x330: \
374 xl |= 0x0C; \
375 break; \
376 case 0x320: \
377 xl |= 0x08; \
378 break; \
379 case 0x310: \
380 xl |= 0x04; \
381 break; \
382 case 0x300: \
383 xl |= 0x00; \
384 break; \
385 default: \
386 xl |= 0x00; \
387 break; \
388 } \
389 }
390#define BLDWSSADDR(xl, val) { \
391 xl &= ~0x10; \
392 if (val == 0xE80) \
393 xl |= 0x10; \
394 }
395#define BLDCDROM(xh, val) { \
396 xh &= ~0x20; \
397 if (val == 1) \
398 xh |= 0x20; \
399 }
400#define BLDCDROMADDR(xh, val) { \
401 int tmp = val; \
402 tmp -= 0x200; \
403 tmp >>= 4; \
404 tmp &= 0x1F; \
405 xh |= tmp; \
406 xh &= 0x7F; \
407 xh |= 0x40; \
408 }
409#endif /* CONFIG_SC6600 */
410
411/*
412 * Bit mapped flags for calling aedsp16_init_board(), and saving the current
413 * emulation mode.
414 */
415#define INIT_NONE (0 )
416#define INIT_SBPRO (1<<0)
417#define INIT_MSS (1<<1)
418#define INIT_MPU401 (1<<2)
419
420static int soft_cfg __initdata = 0; /* bitmapped config */
421static int soft_cfg_mss __initdata = 0; /* bitmapped mss config */
422static int ver[CARDVERLEN] __initdata = {0, 0}; /* DSP Ver:
423 hi->ver[0] lo->ver[1] */
424
425#if defined(CONFIG_SC6600)
426static int hard_cfg[2] /* lo<-hard_cfg[0] hi<-hard_cfg[1] */
427 __initdata = { 0, 0};
428#endif /* CONFIG_SC6600 */
429
430#if defined(CONFIG_SC6600)
431/* Decoded hard configuration */
432struct d_hcfg {
433 int iobase;
434 int joystick;
435 int mpubase;
436 int wssbase;
437 int cdrom;
438 int cdrombase;
439};
440
441static struct d_hcfg decoded_hcfg __initdata = {0, };
442
443#endif /* CONFIG_SC6600 */
444
445/* orVals contain the values to be or'ed */
446struct orVals {
447 int val; /* irq|mirq|dma */
448 int or; /* soft_cfg |= TheStruct.or */
449};
450
451/* aedsp16_info contain the audio card configuration */
452struct aedsp16_info {
453 int base_io; /* base I/O address for accessing card */
454 int irq; /* irq value for DSP I/O */
455 int mpu_irq; /* irq for mpu401 interface I/O */
456 int dma; /* dma value for DSP I/O */
457 int mss_base; /* base I/O for Microsoft Sound System */
458 int mpu_base; /* base I/O for MPU-401 emulation */
459 int init; /* Initialization status of the card */
460};
461
462/*
463 * Magic values that the DSP will eat when configuring irq/mirq/dma
464 */
465/* DSP IRQ conversion array */
466static struct orVals orIRQ[] __initdata = {
467 {0x05, 0x28},
468 {0x07, 0x08},
469 {0x09, 0x10},
470 {0x0a, 0x18},
471 {0x0b, 0x20},
472 {0x00, 0x00}
473};
474
475/* MPU-401 IRQ conversion array */
476static struct orVals orMIRQ[] __initdata = {
477 {0x05, 0x04},
478 {0x07, 0x44},
479 {0x09, 0x84},
480 {0x0a, 0xc4},
481 {0x00, 0x00}
482};
483
484/* DMA Channels conversion array */
485static struct orVals orDMA[] __initdata = {
486 {0x00, 0x01},
487 {0x01, 0x02},
488 {0x03, 0x03},
489 {0x00, 0x00}
490};
491
492static struct aedsp16_info ae_config = {
493 DEF_AEDSP16_IOB,
494 DEF_AEDSP16_IRQ,
495 DEF_AEDSP16_MRQ,
496 DEF_AEDSP16_DMA,
497 -1,
498 -1,
499 INIT_NONE
500};
501
502/*
503 * Buffers to store audio card informations
504 */
505static char DSPCopyright[CARDNAMELEN + 1] __initdata = {0, };
506static char DSPVersion[CARDVERLEN + 1] __initdata = {0, };
507
508static int __init aedsp16_wait_data(int port)
509{
510 int loop = STATUSRETRY;
511 unsigned char ret = 0;
512
513 DBG1(("aedsp16_wait_data (0x%x): ", port));
514
515 do {
516 ret = inb(port + DSP_DATAVAIL);
517 /*
518 * Wait for data available (bit 7 of ret == 1)
519 */
520 } while (!(ret & 0x80) && loop--);
521
522 if (ret & 0x80) {
523 DBG1(("success.\n"));
524 return TRUE;
525 }
526
527 DBG1(("failure.\n"));
528 return FALSE;
529}
530
531static int __init aedsp16_read(int port)
532{
533 int inbyte;
534
535 DBG((" Read DSP Byte (0x%x): ", port));
536
537 if (aedsp16_wait_data(port) == FALSE) {
538 DBG(("failure.\n"));
539 return -1;
540 }
541
542 inbyte = inb(port + DSP_READ);
543
544 DBG(("read [0x%x]/{%c}.\n", inbyte, inbyte));
545
546 return inbyte;
547}
548
549static int __init aedsp16_test_dsp(int port)
550{
551 return ((aedsp16_read(port) == 0xaa) ? TRUE : FALSE);
552}
553
554static int __init aedsp16_dsp_reset(int port)
555{
556 /*
557 * Reset DSP
558 */
559
560 DBG(("Reset DSP:\n"));
561
562 outb(1, (port + DSP_RESET));
563 udelay(10);
564 outb(0, (port + DSP_RESET));
565 udelay(10);
566 udelay(10);
567 if (aedsp16_test_dsp(port) == TRUE) {
568 DBG(("success.\n"));
569 return TRUE;
570 } else
571 DBG(("failure.\n"));
572 return FALSE;
573}
574
575static int __init aedsp16_write(int port, int cmd)
576{
577 unsigned char ret;
578 int loop = HARDRETRY;
579
580 DBG((" Write DSP Byte (0x%x) [0x%x]: ", port, cmd));
581
582 do {
583 ret = inb(port + DSP_STATUS);
584 /*
585 * DSP ready to receive data if bit 7 of ret == 0
586 */
587 if (!(ret & 0x80)) {
588 outb(cmd, port + DSP_COMMAND);
589 DBG(("success.\n"));
590 return 0;
591 }
592 } while (loop--);
593
594 DBG(("timeout.\n"));
595 printk("[AEDSP16] DSP Command (0x%x) timeout.\n", cmd);
596
597 return -1;
598}
599
600#if defined(CONFIG_SC6600)
601
602#if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
603void __init aedsp16_pinfo(void) {
604 DBG(("\n Base address: %x\n", decoded_hcfg.iobase));
605 DBG((" Joystick : %s present\n", decoded_hcfg.joystick?"":" not"));
606 DBG((" WSS addr : %x\n", decoded_hcfg.wssbase));
607 DBG((" MPU-401 addr: %x\n", decoded_hcfg.mpubase));
608 DBG((" CDROM : %s present\n", (decoded_hcfg.cdrom!=4)?"":" not"));
609 DBG((" CDROMADDR : %x\n\n", decoded_hcfg.cdrombase));
610}
611#endif
612
613static void __init aedsp16_hard_decode(void) {
614
615 DBG((" aedsp16_hard_decode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
616
617/*
618 * Decode Cfg Bytes.
619 */
620 decoded_hcfg.iobase = IOBASE(hard_cfg[0]);
621 decoded_hcfg.joystick = JOY(hard_cfg[0]);
622 decoded_hcfg.wssbase = WSSADDR(hard_cfg[0]);
623 decoded_hcfg.mpubase = MPUADDR(hard_cfg[0]);
624 decoded_hcfg.cdrom = CDROM(hard_cfg[1]);
625 decoded_hcfg.cdrombase = CDROMADDR(hard_cfg[1]);
626
627#if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
628 printk(" Original sound card configuration:\n");
629 aedsp16_pinfo();
630#endif
631
632/*
633 * Now set up the real kernel configuration.
634 */
635 decoded_hcfg.iobase = ae_config.base_io;
636 decoded_hcfg.wssbase = ae_config.mss_base;
637 decoded_hcfg.mpubase = ae_config.mpu_base;
638
639#if defined(CONFIG_SC6600_JOY)
640 decoded_hcfg.joystick = CONFIG_SC6600_JOY; /* Enable */
641#endif
642#if defined(CONFIG_SC6600_CDROM)
643 decoded_hcfg.cdrom = CONFIG_SC6600_CDROM; /* 4:N-3:I-2:G-1:P-0:S */
644#endif
645#if defined(CONFIG_SC6600_CDROMBASE)
646 decoded_hcfg.cdrombase = CONFIG_SC6600_CDROMBASE; /* 0 Disable */
647#endif
648
649#if defined(AEDSP16_DEBUG)
650 DBG((" New Values:\n"));
651 aedsp16_pinfo();
652#endif
653
654 DBG(("success.\n"));
655}
656
657static void __init aedsp16_hard_encode(void) {
658
659 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
660
661 hard_cfg[0] = 0;
662 hard_cfg[1] = 0;
663
664 hard_cfg[0] |= 0x20;
665
666 BLDIOBASE (hard_cfg[0], decoded_hcfg.iobase);
667 BLDWSSADDR(hard_cfg[0], decoded_hcfg.wssbase);
668 BLDMPUADDR(hard_cfg[0], decoded_hcfg.mpubase);
669 BLDJOY(hard_cfg[0], decoded_hcfg.joystick);
670 BLDCDROM(hard_cfg[1], decoded_hcfg.cdrom);
671 BLDCDROMADDR(hard_cfg[1], decoded_hcfg.cdrombase);
672
673#if defined(AEDSP16_DEBUG)
674 aedsp16_pinfo();
675#endif
676
677 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
678 DBG(("success.\n"));
679
680}
681
682static int __init aedsp16_hard_write(int port) {
683
684 DBG(("aedsp16_hard_write:\n"));
685
686 if (aedsp16_write(port, COMMAND_6C)) {
687 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6C);
688 DBG(("failure.\n"));
689 return FALSE;
690 }
691 if (aedsp16_write(port, COMMAND_5C)) {
692 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
693 DBG(("failure.\n"));
694 return FALSE;
695 }
696 if (aedsp16_write(port, hard_cfg[0])) {
697 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[0]);
698 DBG(("failure.\n"));
699 return FALSE;
700 }
701 if (aedsp16_write(port, hard_cfg[1])) {
702 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[1]);
703 DBG(("failure.\n"));
704 return FALSE;
705 }
706 if (aedsp16_write(port, COMMAND_C5)) {
707 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_C5);
708 DBG(("failure.\n"));
709 return FALSE;
710 }
711
712 DBG(("success.\n"));
713
714 return TRUE;
715}
716
717static int __init aedsp16_hard_read(int port) {
718
719 DBG(("aedsp16_hard_read:\n"));
720
721 if (aedsp16_write(port, READ_HARD_CFG)) {
722 printk("[AEDSP16] CMD 0x%x: failed!\n", READ_HARD_CFG);
723 DBG(("failure.\n"));
724 return FALSE;
725 }
726
727 if ((hard_cfg[0] = aedsp16_read(port)) == -1) {
728 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
729 READ_HARD_CFG);
730 DBG(("failure.\n"));
731 return FALSE;
732 }
733 if ((hard_cfg[1] = aedsp16_read(port)) == -1) {
734 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
735 READ_HARD_CFG);
736 DBG(("failure.\n"));
737 return FALSE;
738 }
739 if (aedsp16_read(port) == -1) {
740 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
741 READ_HARD_CFG);
742 DBG(("failure.\n"));
743 return FALSE;
744 }
745
746 DBG(("success.\n"));
747
748 return TRUE;
749}
750
751static int __init aedsp16_ext_cfg_write(int port) {
752
753 int extcfg, val;
754
755 if (aedsp16_write(port, COMMAND_66)) {
756 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_66);
757 return FALSE;
758 }
759
760 extcfg = 7;
761 if (decoded_hcfg.cdrom != 2)
762 extcfg = 0x0F;
763 if ((decoded_hcfg.cdrom == 4) ||
764 (decoded_hcfg.cdrom == 3))
765 extcfg &= ~2;
766 if (decoded_hcfg.cdrombase == 0)
767 extcfg &= ~2;
768 if (decoded_hcfg.mpubase == 0)
769 extcfg &= ~1;
770
771 if (aedsp16_write(port, extcfg)) {
772 printk("[AEDSP16] Write extcfg: failed!\n");
773 return FALSE;
774 }
775 if (aedsp16_write(port, 0)) {
776 printk("[AEDSP16] Write extcfg: failed!\n");
777 return FALSE;
778 }
779 if (decoded_hcfg.cdrom == 3) {
780 if (aedsp16_write(port, COMMAND_52)) {
781 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
782 return FALSE;
783 }
784 if ((val = aedsp16_read(port)) == -1) {
785 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n"
786 , COMMAND_52);
787 return FALSE;
788 }
789 val &= 0x7F;
790 if (aedsp16_write(port, COMMAND_60)) {
791 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
792 return FALSE;
793 }
794 if (aedsp16_write(port, val)) {
795 printk("[AEDSP16] Write val: failed!\n");
796 return FALSE;
797 }
798 }
799
800 return TRUE;
801}
802
803#endif /* CONFIG_SC6600 */
804
805static int __init aedsp16_cfg_write(int port) {
806 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
807 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
808 return FALSE;
809 }
810 if (aedsp16_write(port, soft_cfg)) {
811 printk("[AEDSP16] Initialization of (M)IRQ and DMA: failed!\n");
812 return FALSE;
813 }
814 return TRUE;
815}
816
817static int __init aedsp16_init_mss(int port)
818{
819 DBG(("aedsp16_init_mss:\n"));
820
821 mdelay(10);
822
823 if (aedsp16_write(port, DSP_INIT_MSS)) {
824 printk("[AEDSP16] aedsp16_init_mss [0x%x]: failed!\n",
825 DSP_INIT_MSS);
826 DBG(("failure.\n"));
827 return FALSE;
828 }
829
830 mdelay(10);
831
832 if (aedsp16_cfg_write(port) == FALSE)
833 return FALSE;
834
835 outb(soft_cfg_mss, ae_config.mss_base);
836
837 DBG(("success.\n"));
838
839 return TRUE;
840}
841
842static int __init aedsp16_setup_board(int port) {
843 int loop = RETRY;
844
845#if defined(CONFIG_SC6600)
846 int val = 0;
847
848 if (aedsp16_hard_read(port) == FALSE) {
849 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
850 return FALSE;
851 }
852
853 if (aedsp16_write(port, COMMAND_52)) {
854 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
855 return FALSE;
856 }
857
858 if ((val = aedsp16_read(port)) == -1) {
859 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
860 COMMAND_52);
861 return FALSE;
862 }
863#endif
864
865 do {
866 if (aedsp16_write(port, COMMAND_88)) {
867 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_88);
868 return FALSE;
869 }
870 mdelay(10);
871 } while ((aedsp16_wait_data(port) == FALSE) && loop--);
872
873 if (aedsp16_read(port) == -1) {
874 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
875 COMMAND_88);
876 return FALSE;
877 }
878
879#if !defined(CONFIG_SC6600)
880 if (aedsp16_write(port, COMMAND_5C)) {
881 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
882 return FALSE;
883 }
884#endif
885
886 if (aedsp16_cfg_write(port) == FALSE)
887 return FALSE;
888
889#if defined(CONFIG_SC6600)
890 if (aedsp16_write(port, COMMAND_60)) {
891 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
892 return FALSE;
893 }
894 if (aedsp16_write(port, val)) {
895 printk("[AEDSP16] DATA 0x%x: failed!\n", val);
896 return FALSE;
897 }
898 if (aedsp16_write(port, COMMAND_6E)) {
899 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6E);
900 return FALSE;
901 }
902 if (aedsp16_write(port, ver[0])) {
903 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[0]);
904 return FALSE;
905 }
906 if (aedsp16_write(port, ver[1])) {
907 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[1]);
908 return FALSE;
909 }
910
911 if (aedsp16_hard_write(port) == FALSE) {
912 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
913 return FALSE;
914 }
915
916 if (aedsp16_write(port, COMMAND_5C)) {
917 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
918 return FALSE;
919 }
920
921#if defined(THIS_IS_A_THING_I_HAVE_NOT_TESTED_YET)
922 if (aedsp16_cfg_write(port) == FALSE)
923 return FALSE;
924#endif
925
926#endif
927
928 return TRUE;
929}
930
931static int __init aedsp16_stdcfg(int port) {
932 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
933 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
934 return FALSE;
935 }
936 /*
937 * 0x0A == (IRQ 7, DMA 1, MIRQ 0)
938 */
939 if (aedsp16_write(port, 0x0A)) {
940 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
941 return FALSE;
942 }
943 return TRUE;
944}
945
946static int __init aedsp16_dsp_version(int port)
947{
948 int len = 0;
949 int ret;
950
951 DBG(("Get DSP Version:\n"));
952
953 if (aedsp16_write(ae_config.base_io, GET_DSP_VERSION)) {
954 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_VERSION);
955 DBG(("failed.\n"));
956 return FALSE;
957 }
958
959 do {
960 if ((ret = aedsp16_read(port)) == -1) {
961 DBG(("failed.\n"));
962 return FALSE;
963 }
964 /*
965 * We already know how many int are stored (2), so we know when the
966 * string is finished.
967 */
968 ver[len++] = ret;
969 } while (len < CARDVERLEN);
970 sprintf(DSPVersion, "%d.%d", ver[0], ver[1]);
971
972 DBG(("success.\n"));
973
974 return TRUE;
975}
976
977static int __init aedsp16_dsp_copyright(int port)
978{
979 int len = 0;
980 int ret;
981
982 DBG(("Get DSP Copyright:\n"));
983
984 if (aedsp16_write(ae_config.base_io, GET_DSP_COPYRIGHT)) {
985 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_COPYRIGHT);
986 DBG(("failed.\n"));
987 return FALSE;
988 }
989
990 do {
991 if ((ret = aedsp16_read(port)) == -1) {
992 /*
993 * If no more data available, return to the caller, no error if len>0.
994 * We have no other way to know when the string is finished.
995 */
996 if (len)
997 break;
998 else {
999 DBG(("failed.\n"));
1000 return FALSE;
1001 }
1002 }
1003
1004 DSPCopyright[len++] = ret;
1005
1006 } while (len < CARDNAMELEN);
1007
1008 DBG(("success.\n"));
1009
1010 return TRUE;
1011}
1012
1013static void __init aedsp16_init_tables(void)
1014{
1015 int i = 0;
1016
1017 memset(DSPCopyright, 0, CARDNAMELEN + 1);
1018 memset(DSPVersion, 0, CARDVERLEN + 1);
1019
1020 for (i = 0; orIRQ[i].or; i++)
1021 if (orIRQ[i].val == ae_config.irq) {
1022 soft_cfg |= orIRQ[i].or;
1023 soft_cfg_mss |= orIRQ[i].or;
1024 }
1025
1026 for (i = 0; orMIRQ[i].or; i++)
1027 if (orMIRQ[i].or == ae_config.mpu_irq)
1028 soft_cfg |= orMIRQ[i].or;
1029
1030 for (i = 0; orDMA[i].or; i++)
1031 if (orDMA[i].val == ae_config.dma) {
1032 soft_cfg |= orDMA[i].or;
1033 soft_cfg_mss |= orDMA[i].or;
1034 }
1035}
1036
1037static int __init aedsp16_init_board(void)
1038{
1039 aedsp16_init_tables();
1040
1041 if (aedsp16_dsp_reset(ae_config.base_io) == FALSE) {
1042 printk("[AEDSP16] aedsp16_dsp_reset: failed!\n");
1043 return FALSE;
1044 }
1045 if (aedsp16_dsp_copyright(ae_config.base_io) == FALSE) {
1046 printk("[AEDSP16] aedsp16_dsp_copyright: failed!\n");
1047 return FALSE;
1048 }
1049
1050 /*
1051 * My AEDSP16 card return SC-6000 in DSPCopyright, so
1052 * if we have something different, we have to be warned.
1053 */
1054 if (strcmp("SC-6000", DSPCopyright))
1055 printk("[AEDSP16] Warning: non SC-6000 audio card!\n");
1056
1057 if (aedsp16_dsp_version(ae_config.base_io) == FALSE) {
1058 printk("[AEDSP16] aedsp16_dsp_version: failed!\n");
1059 return FALSE;
1060 }
1061
1062 if (aedsp16_stdcfg(ae_config.base_io) == FALSE) {
1063 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
1064 return FALSE;
1065 }
1066
1067#if defined(CONFIG_SC6600)
1068 if (aedsp16_hard_read(ae_config.base_io) == FALSE) {
1069 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
1070 return FALSE;
1071 }
1072
1073 aedsp16_hard_decode();
1074
1075 aedsp16_hard_encode();
1076
1077 if (aedsp16_hard_write(ae_config.base_io) == FALSE) {
1078 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
1079 return FALSE;
1080 }
1081
1082 if (aedsp16_ext_cfg_write(ae_config.base_io) == FALSE) {
1083 printk("[AEDSP16] aedsp16_ext_cfg_write: failed!\n");
1084 return FALSE;
1085 }
1086#endif /* CONFIG_SC6600 */
1087
1088 if (aedsp16_setup_board(ae_config.base_io) == FALSE) {
1089 printk("[AEDSP16] aedsp16_setup_board: failed!\n");
1090 return FALSE;
1091 }
1092
1093 if (ae_config.mss_base != -1) {
1094 if (ae_config.init & INIT_MSS) {
1095 if (aedsp16_init_mss(ae_config.base_io) == FALSE) {
1096 printk("[AEDSP16] Can not initialize"
1097 "Microsoft Sound System mode.\n");
1098 return FALSE;
1099 }
1100 }
1101 }
1102
1103#if !defined(MODULE) || defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
1104
1105 printk("Audio Excel DSP 16 init v%s (%s %s) [",
1106 VERSION, DSPCopyright,
1107 DSPVersion);
1108
1109 if (ae_config.mpu_base != -1) {
1110 if (ae_config.init & INIT_MPU401) {
1111 printk("MPU401");
1112 if ((ae_config.init & INIT_MSS) ||
1113 (ae_config.init & INIT_SBPRO))
1114 printk(" ");
1115 }
1116 }
1117
1118 if (ae_config.mss_base == -1) {
1119 if (ae_config.init & INIT_SBPRO) {
1120 printk("SBPro");
1121 if (ae_config.init & INIT_MSS)
1122 printk(" ");
1123 }
1124 }
1125
1126 if (ae_config.mss_base != -1)
1127 if (ae_config.init & INIT_MSS)
1128 printk("MSS");
1129
1130 printk("]\n");
1131#endif /* MODULE || AEDSP16_INFO || AEDSP16_DEBUG */
1132
1133 mdelay(10);
1134
1135 return TRUE;
1136}
1137
1138static int __init init_aedsp16_sb(void)
1139{
1140 DBG(("init_aedsp16_sb: "));
1141
1142/*
1143 * If the card is already init'ed MSS, we can not init it to SBPRO too
1144 * because the board can not emulate simultaneously MSS and SBPRO.
1145 */
1146 if (ae_config.init & INIT_MSS)
1147 return FALSE;
1148 if (ae_config.init & INIT_SBPRO)
1149 return FALSE;
1150
1151 ae_config.init |= INIT_SBPRO;
1152
1153 DBG(("done.\n"));
1154
1155 return TRUE;
1156}
1157
1158static void uninit_aedsp16_sb(void)
1159{
1160 DBG(("uninit_aedsp16_sb: "));
1161
1162 ae_config.init &= ~INIT_SBPRO;
1163
1164 DBG(("done.\n"));
1165}
1166
1167static int __init init_aedsp16_mss(void)
1168{
1169 DBG(("init_aedsp16_mss: "));
1170
1171/*
1172 * If the card is already init'ed SBPRO, we can not init it to MSS too
1173 * because the board can not emulate simultaneously MSS and SBPRO.
1174 */
1175 if (ae_config.init & INIT_SBPRO)
1176 return FALSE;
1177 if (ae_config.init & INIT_MSS)
1178 return FALSE;
1179/*
1180 * We must allocate the CONFIG_AEDSP16_BASE region too because these are the
1181 * I/O ports to access card's control registers.
1182 */
1183 if (!(ae_config.init & INIT_MPU401)) {
1184 if (!request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1185 "aedsp16 (base)")) {
1186 printk(
1187 "AEDSP16 BASE I/O port region is already in use.\n");
1188 return FALSE;
1189 }
1190 }
1191
1192 ae_config.init |= INIT_MSS;
1193
1194 DBG(("done.\n"));
1195
1196 return TRUE;
1197}
1198
1199static void uninit_aedsp16_mss(void)
1200{
1201 DBG(("uninit_aedsp16_mss: "));
1202
1203 if ((!(ae_config.init & INIT_MPU401)) &&
1204 (ae_config.init & INIT_MSS)) {
1205 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1206 DBG(("AEDSP16 base region released.\n"));
1207 }
1208
1209 ae_config.init &= ~INIT_MSS;
1210 DBG(("done.\n"));
1211}
1212
1213static int __init init_aedsp16_mpu(void)
1214{
1215 DBG(("init_aedsp16_mpu: "));
1216
1217 if (ae_config.init & INIT_MPU401)
1218 return FALSE;
1219
1220/*
1221 * We must request the CONFIG_AEDSP16_BASE region too because these are the I/O
1222 * ports to access card's control registers.
1223 */
1224 if (!(ae_config.init & (INIT_MSS | INIT_SBPRO))) {
1225 if (!request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1226 "aedsp16 (base)")) {
1227 printk(
1228 "AEDSP16 BASE I/O port region is already in use.\n");
1229 return FALSE;
1230 }
1231 }
1232
1233 ae_config.init |= INIT_MPU401;
1234
1235 DBG(("done.\n"));
1236
1237 return TRUE;
1238}
1239
1240static void uninit_aedsp16_mpu(void)
1241{
1242 DBG(("uninit_aedsp16_mpu: "));
1243
1244 if ((!(ae_config.init & (INIT_MSS | INIT_SBPRO))) &&
1245 (ae_config.init & INIT_MPU401)) {
1246 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1247 DBG(("AEDSP16 base region released.\n"));
1248 }
1249
1250 ae_config.init &= ~INIT_MPU401;
1251
1252 DBG(("done.\n"));
1253}
1254
1255static int __init init_aedsp16(void)
1256{
1257 int initialized = FALSE;
1258
1259 DBG(("Initializing BASE[0x%x] IRQ[%d] DMA[%d] MIRQ[%d]\n",
1260 ae_config.base_io,ae_config.irq,ae_config.dma,ae_config.mpu_irq));
1261
1262 if (ae_config.mss_base == -1) {
1263 if (init_aedsp16_sb() == FALSE) {
1264 uninit_aedsp16_sb();
1265 } else {
1266 initialized = TRUE;
1267 }
1268 }
1269
1270 if (ae_config.mpu_base != -1) {
1271 if (init_aedsp16_mpu() == FALSE) {
1272 uninit_aedsp16_mpu();
1273 } else {
1274 initialized = TRUE;
1275 }
1276 }
1277
1278/*
1279 * In the sequence of init routines, the MSS init MUST be the last!
1280 * This because of the special register programming the MSS mode needs.
1281 * A board reset would disable the MSS mode restoring the default SBPRO
1282 * mode.
1283 */
1284 if (ae_config.mss_base != -1) {
1285 if (init_aedsp16_mss() == FALSE) {
1286 uninit_aedsp16_mss();
1287 } else {
1288 initialized = TRUE;
1289 }
1290 }
1291
1292 if (initialized)
1293 initialized = aedsp16_init_board();
1294 return initialized;
1295}
1296
1297static void __exit uninit_aedsp16(void)
1298{
1299 if (ae_config.mss_base != -1)
1300 uninit_aedsp16_mss();
1301 else
1302 uninit_aedsp16_sb();
1303 if (ae_config.mpu_base != -1)
1304 uninit_aedsp16_mpu();
1305}
1306
1307static int __initdata io = -1;
1308static int __initdata irq = -1;
1309static int __initdata dma = -1;
1310static int __initdata mpu_irq = -1;
1311static int __initdata mss_base = -1;
1312static int __initdata mpu_base = -1;
1313
1314module_param(io, int, 0);
1315MODULE_PARM_DESC(io, "I/O base address (0x220 0x240)");
1316module_param(irq, int, 0);
1317MODULE_PARM_DESC(irq, "IRQ line (5 7 9 10 11)");
1318module_param(dma, int, 0);
1319MODULE_PARM_DESC(dma, "dma line (0 1 3)");
1320module_param(mpu_irq, int, 0);
1321MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ line (5 7 9 10 0)");
1322module_param(mss_base, int, 0);
1323MODULE_PARM_DESC(mss_base, "MSS emulation I/O base address (0x530 0xE80)");
1324module_param(mpu_base, int, 0);
1325MODULE_PARM_DESC(mpu_base,"MPU-401 I/O base address (0x300 0x310 0x320 0x330)");
1326MODULE_AUTHOR("Riccardo Facchetti <fizban@tin.it>");
1327MODULE_DESCRIPTION("Audio Excel DSP 16 Driver Version " VERSION);
1328MODULE_LICENSE("GPL");
1329
1330static int __init do_init_aedsp16(void) {
1331 printk("Audio Excel DSP 16 init driver Copyright (C) Riccardo Facchetti 1995-98\n");
1332 if (io == -1 || dma == -1 || irq == -1) {
1333 printk(KERN_INFO "aedsp16: I/O, IRQ and DMA are mandatory\n");
1334 return -EINVAL;
1335 }
1336
1337 ae_config.base_io = io;
1338 ae_config.irq = irq;
1339 ae_config.dma = dma;
1340
1341 ae_config.mss_base = mss_base;
1342 ae_config.mpu_base = mpu_base;
1343 ae_config.mpu_irq = mpu_irq;
1344
1345 if (init_aedsp16() == FALSE) {
1346 printk(KERN_ERR "aedsp16: initialization failed\n");
1347 /*
1348 * XXX
1349 * What error should we return here ?
1350 */
1351 return -EINVAL;
1352 }
1353 return 0;
1354}
1355
1356static void __exit cleanup_aedsp16(void) {
1357 uninit_aedsp16();
1358}
1359
1360module_init(do_init_aedsp16);
1361module_exit(cleanup_aedsp16);
1362
1363#ifndef MODULE
1364static int __init setup_aedsp16(char *str)
1365{
1366 /* io, irq, dma, mss_io, mpu_io, mpu_irq */
1367 int ints[7];
1368
1369 str = get_options(str, ARRAY_SIZE(ints), ints);
1370
1371 io = ints[1];
1372 irq = ints[2];
1373 dma = ints[3];
1374 mss_base = ints[4];
1375 mpu_base = ints[5];
1376 mpu_irq = ints[6];
1377 return 1;
1378}
1379
1380__setup("aedsp16=", setup_aedsp16);
1381#endif
diff --git a/sound/oss/ali5455.c b/sound/oss/ali5455.c
new file mode 100644
index 000000000000..9c9e6c0410f2
--- /dev/null
+++ b/sound/oss/ali5455.c
@@ -0,0 +1,3733 @@
1/*
2 * ALI ali5455 and friends ICH driver for Linux
3 * LEI HU <Lei_Hu@ali.com.tw>
4 *
5 * Built from:
6 * drivers/sound/i810_audio
7 *
8 * The ALi 5455 is similar but not quite identical to the Intel ICH
9 * series of controllers. Its easier to keep the driver separated from
10 * the i810 driver.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 *
27 * ALi 5455 theory of operation
28 *
29 * The chipset provides three DMA channels that talk to an AC97
30 * CODEC (AC97 is a digital/analog mixer standard). At its simplest
31 * you get 48Khz audio with basic volume and mixer controls. At the
32 * best you get rate adaption in the codec. We set the card up so
33 * that we never take completion interrupts but instead keep the card
34 * chasing its tail around a ring buffer. This is needed for mmap
35 * mode audio and happens to work rather well for non-mmap modes too.
36 *
37 * The board has one output channel for PCM audio (supported) and
38 * a stereo line in and mono microphone input. Again these are normally
39 * locked to 48Khz only. Right now recording is not finished.
40 *
41 * There is no midi support, no synth support. Use timidity. To get
42 * esd working you need to use esd -r 48000 as it won't probe 48KHz
43 * by default. mpg123 can't handle 48Khz only audio so use xmms.
44 *
45 * If you need to force a specific rate set the clocking= option
46 *
47 */
48
49#include <linux/module.h>
50#include <linux/string.h>
51#include <linux/ctype.h>
52#include <linux/ioport.h>
53#include <linux/sched.h>
54#include <linux/delay.h>
55#include <linux/sound.h>
56#include <linux/slab.h>
57#include <linux/soundcard.h>
58#include <linux/pci.h>
59#include <asm/io.h>
60#include <asm/dma.h>
61#include <linux/init.h>
62#include <linux/poll.h>
63#include <linux/spinlock.h>
64#include <linux/smp_lock.h>
65#include <linux/ac97_codec.h>
66#include <linux/interrupt.h>
67#include <asm/uaccess.h>
68
69#ifndef PCI_DEVICE_ID_ALI_5455
70#define PCI_DEVICE_ID_ALI_5455 0x5455
71#endif
72
73#ifndef PCI_VENDOR_ID_ALI
74#define PCI_VENDOR_ID_ALI 0x10b9
75#endif
76
77static int strict_clocking = 0;
78static unsigned int clocking = 0;
79static unsigned int codec_pcmout_share_spdif_locked = 0;
80static unsigned int codec_independent_spdif_locked = 0;
81static unsigned int controller_pcmout_share_spdif_locked = 0;
82static unsigned int controller_independent_spdif_locked = 0;
83static unsigned int globel = 0;
84
85#define ADC_RUNNING 1
86#define DAC_RUNNING 2
87#define CODEC_SPDIFOUT_RUNNING 8
88#define CONTROLLER_SPDIFOUT_RUNNING 4
89
90#define SPDIF_ENABLE_OUTPUT 4 /* bits 0,1 are PCM */
91
92#define ALI5455_FMT_16BIT 1
93#define ALI5455_FMT_STEREO 2
94#define ALI5455_FMT_MASK 3
95
96#define SPDIF_ON 0x0004
97#define SURR_ON 0x0010
98#define CENTER_LFE_ON 0x0020
99#define VOL_MUTED 0x8000
100
101
102#define ALI_SPDIF_OUT_CH_STATUS 0xbf
103/* the 810's array of pointers to data buffers */
104
105struct sg_item {
106#define BUSADDR_MASK 0xFFFFFFFE
107 u32 busaddr;
108#define CON_IOC 0x80000000 /* interrupt on completion */
109#define CON_BUFPAD 0x40000000 /* pad underrun with last sample, else 0 */
110#define CON_BUFLEN_MASK 0x0000ffff /* buffer length in samples */
111 u32 control;
112};
113
114/* an instance of the ali channel */
115#define SG_LEN 32
116struct ali_channel {
117 /* these sg guys should probably be allocated
118 separately as nocache. Must be 8 byte aligned */
119 struct sg_item sg[SG_LEN]; /* 32*8 */
120 u32 offset; /* 4 */
121 u32 port; /* 4 */
122 u32 used;
123 u32 num;
124};
125
126/*
127 * we have 3 separate dma engines. pcm in, pcm out, and mic.
128 * each dma engine has controlling registers. These goofy
129 * names are from the datasheet, but make it easy to write
130 * code while leafing through it.
131 */
132
133#define ENUM_ENGINE(PRE,DIG) \
134enum { \
135 PRE##_BDBAR = 0x##DIG##0, /* Buffer Descriptor list Base Address */ \
136 PRE##_CIV = 0x##DIG##4, /* Current Index Value */ \
137 PRE##_LVI = 0x##DIG##5, /* Last Valid Index */ \
138 PRE##_SR = 0x##DIG##6, /* Status Register */ \
139 PRE##_PICB = 0x##DIG##8, /* Position In Current Buffer */ \
140 PRE##_CR = 0x##DIG##b /* Control Register */ \
141}
142
143ENUM_ENGINE(OFF, 0); /* Offsets */
144ENUM_ENGINE(PI, 4); /* PCM In */
145ENUM_ENGINE(PO, 5); /* PCM Out */
146ENUM_ENGINE(MC, 6); /* Mic In */
147ENUM_ENGINE(CODECSPDIFOUT, 7); /* CODEC SPDIF OUT */
148ENUM_ENGINE(CONTROLLERSPDIFIN, A); /* CONTROLLER SPDIF In */
149ENUM_ENGINE(CONTROLLERSPDIFOUT, B); /* CONTROLLER SPDIF OUT */
150
151
152enum {
153 ALI_SCR = 0x00, /* System Control Register */
154 ALI_SSR = 0x04, /* System Status Register */
155 ALI_DMACR = 0x08, /* DMA Control Register */
156 ALI_FIFOCR1 = 0x0c, /* FIFO Control Register 1 */
157 ALI_INTERFACECR = 0x10, /* Interface Control Register */
158 ALI_INTERRUPTCR = 0x14, /* Interrupt control Register */
159 ALI_INTERRUPTSR = 0x18, /* Interrupt Status Register */
160 ALI_FIFOCR2 = 0x1c, /* FIFO Control Register 2 */
161 ALI_CPR = 0x20, /* Command Port Register */
162 ALI_SPR = 0x24, /* Status Port Register */
163 ALI_FIFOCR3 = 0x2c, /* FIFO Control Register 3 */
164 ALI_TTSR = 0x30, /* Transmit Tag Slot Register */
165 ALI_RTSR = 0x34, /* Receive Tag Slot Register */
166 ALI_CSPSR = 0x38, /* Command/Status Port Status Register */
167 ALI_CAS = 0x3c, /* Codec Write Semaphore Register */
168 ALI_SPDIFCSR = 0xf8, /* spdif channel status register */
169 ALI_SPDIFICS = 0xfc /* spdif interface control/status */
170};
171
172// x-status register(x:pcm in ,pcm out, mic in,)
173/* interrupts for a dma engine */
174#define DMA_INT_FIFO (1<<4) /* fifo under/over flow */
175#define DMA_INT_COMPLETE (1<<3) /* buffer read/write complete and ioc set */
176#define DMA_INT_LVI (1<<2) /* last valid done */
177#define DMA_INT_CELV (1<<1) /* last valid is current */
178#define DMA_INT_DCH (1) /* DMA Controller Halted (happens on LVI interrupts) */ //not eqult intel
179#define DMA_INT_MASK (DMA_INT_FIFO|DMA_INT_COMPLETE|DMA_INT_LVI)
180
181/* interrupts for the whole chip */// by interrupt status register finish
182
183#define INT_SPDIFOUT (1<<23) /* controller spdif out INTERRUPT */
184#define INT_SPDIFIN (1<<22)
185#define INT_CODECSPDIFOUT (1<<19)
186#define INT_MICIN (1<<18)
187#define INT_PCMOUT (1<<17)
188#define INT_PCMIN (1<<16)
189#define INT_CPRAIS (1<<7)
190#define INT_SPRAIS (1<<5)
191#define INT_GPIO (1<<1)
192#define INT_MASK (INT_SPDIFOUT|INT_CODECSPDIFOUT|INT_MICIN|INT_PCMOUT|INT_PCMIN)
193
194#define DRIVER_VERSION "0.02ac"
195
196/* magic numbers to protect our data structures */
197#define ALI5455_CARD_MAGIC 0x5072696E /* "Prin" */
198#define ALI5455_STATE_MAGIC 0x63657373 /* "cess" */
199#define ALI5455_DMA_MASK 0xffffffff /* DMA buffer mask for pci_alloc_consist */
200#define NR_HW_CH 5 //I think 5 channel
201
202/* maxinum number of AC97 codecs connected, AC97 2.0 defined 4 */
203#define NR_AC97 2
204
205/* Please note that an 8bit mono stream is not valid on this card, you must have a 16bit */
206/* stream at a minimum for this card to be happy */
207static const unsigned sample_size[] = { 1, 2, 2, 4 };
208/* Samples are 16bit values, so we are shifting to a word, not to a byte, hence shift */
209/* values are one less than might be expected */
210static const unsigned sample_shift[] = { -1, 0, 0, 1 };
211
212#define ALI5455
213static char *card_names[] = {
214 "ALI 5455"
215};
216
217static struct pci_device_id ali_pci_tbl[] = {
218 {PCI_VENDOR_ID_ALI, PCI_DEVICE_ID_ALI_5455,
219 PCI_ANY_ID, PCI_ANY_ID, 0, 0, ALI5455},
220 {0,}
221};
222
223MODULE_DEVICE_TABLE(pci, ali_pci_tbl);
224
225#ifdef CONFIG_PM
226#define PM_SUSPENDED(card) (card->pm_suspended)
227#else
228#define PM_SUSPENDED(card) (0)
229#endif
230
231/* "software" or virtual channel, an instance of opened /dev/dsp */
232struct ali_state {
233 unsigned int magic;
234 struct ali_card *card; /* Card info */
235
236 /* single open lock mechanism, only used for recording */
237 struct semaphore open_sem;
238 wait_queue_head_t open_wait;
239
240 /* file mode */
241 mode_t open_mode;
242
243 /* virtual channel number */
244 int virt;
245
246#ifdef CONFIG_PM
247 unsigned int pm_saved_dac_rate, pm_saved_adc_rate;
248#endif
249 struct dmabuf {
250 /* wave sample stuff */
251 unsigned int rate;
252 unsigned char fmt, enable, trigger;
253
254 /* hardware channel */
255 struct ali_channel *read_channel;
256 struct ali_channel *write_channel;
257 struct ali_channel *codec_spdifout_channel;
258 struct ali_channel *controller_spdifout_channel;
259
260 /* OSS buffer management stuff */
261 void *rawbuf;
262 dma_addr_t dma_handle;
263 unsigned buforder;
264 unsigned numfrag;
265 unsigned fragshift;
266
267 /* our buffer acts like a circular ring */
268 unsigned hwptr; /* where dma last started, updated by update_ptr */
269 unsigned swptr; /* where driver last clear/filled, updated by read/write */
270 int count; /* bytes to be consumed or been generated by dma machine */
271 unsigned total_bytes; /* total bytes dmaed by hardware */
272
273 unsigned error; /* number of over/underruns */
274 wait_queue_head_t wait; /* put process on wait queue when no more space in buffer */
275
276 /* redundant, but makes calculations easier */
277 /* what the hardware uses */
278 unsigned dmasize;
279 unsigned fragsize;
280 unsigned fragsamples;
281
282 /* what we tell the user to expect */
283 unsigned userfrags;
284 unsigned userfragsize;
285
286 /* OSS stuff */
287 unsigned mapped:1;
288 unsigned ready:1;
289 unsigned update_flag;
290 unsigned ossfragsize;
291 unsigned ossmaxfrags;
292 unsigned subdivision;
293 } dmabuf;
294};
295
296
297struct ali_card {
298 struct ali_channel channel[5];
299 unsigned int magic;
300
301 /* We keep ali5455 cards in a linked list */
302 struct ali_card *next;
303
304 /* The ali has a certain amount of cross channel interaction
305 so we use a single per card lock */
306 spinlock_t lock;
307 spinlock_t ac97_lock;
308
309 /* PCI device stuff */
310 struct pci_dev *pci_dev;
311 u16 pci_id;
312#ifdef CONFIG_PM
313 u16 pm_suspended;
314 int pm_saved_mixer_settings[SOUND_MIXER_NRDEVICES][NR_AC97];
315#endif
316 /* soundcore stuff */
317 int dev_audio;
318
319 /* structures for abstraction of hardware facilities, codecs, banks and channels */
320 struct ac97_codec *ac97_codec[NR_AC97];
321 struct ali_state *states[NR_HW_CH];
322
323 u16 ac97_features;
324 u16 ac97_status;
325 u16 channels;
326
327 /* hardware resources */
328 unsigned long iobase;
329
330 u32 irq;
331
332 /* Function support */
333 struct ali_channel *(*alloc_pcm_channel) (struct ali_card *);
334 struct ali_channel *(*alloc_rec_pcm_channel) (struct ali_card *);
335 struct ali_channel *(*alloc_rec_mic_channel) (struct ali_card *);
336 struct ali_channel *(*alloc_codec_spdifout_channel) (struct ali_card *);
337 struct ali_channel *(*alloc_controller_spdifout_channel) (struct ali_card *);
338 void (*free_pcm_channel) (struct ali_card *, int chan);
339
340 /* We have a *very* long init time possibly, so use this to block */
341 /* attempts to open our devices before we are ready (stops oops'es) */
342 int initializing;
343};
344
345
346static struct ali_card *devs = NULL;
347
348static int ali_open_mixdev(struct inode *inode, struct file *file);
349static int ali_ioctl_mixdev(struct inode *inode, struct file *file,
350 unsigned int cmd, unsigned long arg);
351static u16 ali_ac97_get(struct ac97_codec *dev, u8 reg);
352static void ali_ac97_set(struct ac97_codec *dev, u8 reg, u16 data);
353
354static struct ali_channel *ali_alloc_pcm_channel(struct ali_card *card)
355{
356 if (card->channel[1].used == 1)
357 return NULL;
358 card->channel[1].used = 1;
359 return &card->channel[1];
360}
361
362static struct ali_channel *ali_alloc_rec_pcm_channel(struct ali_card *card)
363{
364 if (card->channel[0].used == 1)
365 return NULL;
366 card->channel[0].used = 1;
367 return &card->channel[0];
368}
369
370static struct ali_channel *ali_alloc_rec_mic_channel(struct ali_card *card)
371{
372 if (card->channel[2].used == 1)
373 return NULL;
374 card->channel[2].used = 1;
375 return &card->channel[2];
376}
377
378static struct ali_channel *ali_alloc_codec_spdifout_channel(struct ali_card *card)
379{
380 if (card->channel[3].used == 1)
381 return NULL;
382 card->channel[3].used = 1;
383 return &card->channel[3];
384}
385
386static struct ali_channel *ali_alloc_controller_spdifout_channel(struct ali_card *card)
387{
388 if (card->channel[4].used == 1)
389 return NULL;
390 card->channel[4].used = 1;
391 return &card->channel[4];
392}
393static void ali_free_pcm_channel(struct ali_card *card, int channel)
394{
395 card->channel[channel].used = 0;
396}
397
398
399//add support codec spdif out
400static int ali_valid_spdif_rate(struct ac97_codec *codec, int rate)
401{
402 unsigned long id = 0L;
403
404 id = (ali_ac97_get(codec, AC97_VENDOR_ID1) << 16);
405 id |= ali_ac97_get(codec, AC97_VENDOR_ID2) & 0xffff;
406 switch (id) {
407 case 0x41445361: /* AD1886 */
408 if (rate == 48000) {
409 return 1;
410 }
411 break;
412 case 0x414c4720: /* ALC650 */
413 if (rate == 48000) {
414 return 1;
415 }
416 break;
417 default: /* all other codecs, until we know otherwiae */
418 if (rate == 48000 || rate == 44100 || rate == 32000) {
419 return 1;
420 }
421 break;
422 }
423 return (0);
424}
425
426/* ali_set_spdif_output
427 *
428 * Configure the S/PDIF output transmitter. When we turn on
429 * S/PDIF, we turn off the analog output. This may not be
430 * the right thing to do.
431 *
432 * Assumptions:
433 * The DSP sample rate must already be set to a supported
434 * S/PDIF rate (32kHz, 44.1kHz, or 48kHz) or we abort.
435 */
436static void ali_set_spdif_output(struct ali_state *state, int slots,
437 int rate)
438{
439 int vol;
440 int aud_reg;
441 struct ac97_codec *codec = state->card->ac97_codec[0];
442
443 if (!(state->card->ac97_features & 4)) {
444 state->card->ac97_status &= ~SPDIF_ON;
445 } else {
446 if (slots == -1) { /* Turn off S/PDIF */
447 aud_reg = ali_ac97_get(codec, AC97_EXTENDED_STATUS);
448 ali_ac97_set(codec, AC97_EXTENDED_STATUS, (aud_reg & ~AC97_EA_SPDIF));
449
450 /* If the volume wasn't muted before we turned on S/PDIF, unmute it */
451 if (!(state->card->ac97_status & VOL_MUTED)) {
452 aud_reg = ali_ac97_get(codec, AC97_MASTER_VOL_STEREO);
453 ali_ac97_set(codec, AC97_MASTER_VOL_STEREO,
454 (aud_reg & ~VOL_MUTED));
455 }
456 state->card->ac97_status &= ~(VOL_MUTED | SPDIF_ON);
457 return;
458 }
459
460 vol = ali_ac97_get(codec, AC97_MASTER_VOL_STEREO);
461 state->card->ac97_status = vol & VOL_MUTED;
462
463 /* Set S/PDIF transmitter sample rate */
464 aud_reg = ali_ac97_get(codec, AC97_SPDIF_CONTROL);
465 switch (rate) {
466 case 32000:
467 aud_reg = (aud_reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_32K;
468 break;
469 case 44100:
470 aud_reg = (aud_reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_44K;
471 break;
472 case 48000:
473 aud_reg = (aud_reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_48K;
474 break;
475 default:
476 /* turn off S/PDIF */
477 aud_reg = ali_ac97_get(codec, AC97_EXTENDED_STATUS);
478 ali_ac97_set(codec, AC97_EXTENDED_STATUS, (aud_reg & ~AC97_EA_SPDIF));
479 state->card->ac97_status &= ~SPDIF_ON;
480 return;
481 }
482
483 ali_ac97_set(codec, AC97_SPDIF_CONTROL, aud_reg);
484
485 aud_reg = ali_ac97_get(codec, AC97_EXTENDED_STATUS);
486 aud_reg = (aud_reg & AC97_EA_SLOT_MASK) | slots | AC97_EA_SPDIF;
487 ali_ac97_set(codec, AC97_EXTENDED_STATUS, aud_reg);
488
489 aud_reg = ali_ac97_get(codec, AC97_POWER_CONTROL);
490 aud_reg |= 0x0002;
491 ali_ac97_set(codec, AC97_POWER_CONTROL, aud_reg);
492 udelay(1);
493
494 state->card->ac97_status |= SPDIF_ON;
495
496 /* Check to make sure the configuration is valid */
497 aud_reg = ali_ac97_get(codec, AC97_EXTENDED_STATUS);
498 if (!(aud_reg & 0x0400)) {
499 /* turn off S/PDIF */
500 ali_ac97_set(codec, AC97_EXTENDED_STATUS, (aud_reg & ~AC97_EA_SPDIF));
501 state->card->ac97_status &= ~SPDIF_ON;
502 return;
503 }
504 if (codec_independent_spdif_locked > 0) {
505 aud_reg = ali_ac97_get(codec, 0x6a);
506 ali_ac97_set(codec, 0x6a, (aud_reg & 0xefff));
507 }
508 /* Mute the analog output */
509 /* Should this only mute the PCM volume??? */
510 }
511}
512
513/* ali_set_dac_channels
514 *
515 * Configure the codec's multi-channel DACs
516 *
517 * The logic is backwards. Setting the bit to 1 turns off the DAC.
518 *
519 * What about the ICH? We currently configure it using the
520 * SNDCTL_DSP_CHANNELS ioctl. If we're turnning on the DAC,
521 * does that imply that we want the ICH set to support
522 * these channels?
523 *
524 * TODO:
525 * vailidate that the codec really supports these DACs
526 * before turning them on.
527 */
528static void ali_set_dac_channels(struct ali_state *state, int channel)
529{
530 int aud_reg;
531 struct ac97_codec *codec = state->card->ac97_codec[0];
532
533 aud_reg = ali_ac97_get(codec, AC97_EXTENDED_STATUS);
534 aud_reg |= AC97_EA_PRI | AC97_EA_PRJ | AC97_EA_PRK;
535 state->card->ac97_status &= ~(SURR_ON | CENTER_LFE_ON);
536
537 switch (channel) {
538 case 2: /* always enabled */
539 break;
540 case 4:
541 aud_reg &= ~AC97_EA_PRJ;
542 state->card->ac97_status |= SURR_ON;
543 break;
544 case 6:
545 aud_reg &= ~(AC97_EA_PRJ | AC97_EA_PRI | AC97_EA_PRK);
546 state->card->ac97_status |= SURR_ON | CENTER_LFE_ON;
547 break;
548 default:
549 break;
550 }
551 ali_ac97_set(codec, AC97_EXTENDED_STATUS, aud_reg);
552
553}
554
555/* set playback sample rate */
556static unsigned int ali_set_dac_rate(struct ali_state *state,
557 unsigned int rate)
558{
559 struct dmabuf *dmabuf = &state->dmabuf;
560 u32 new_rate;
561 struct ac97_codec *codec = state->card->ac97_codec[0];
562
563 if (!(state->card->ac97_features & 0x0001)) {
564 dmabuf->rate = clocking;
565 return clocking;
566 }
567
568 if (rate > 48000)
569 rate = 48000;
570 if (rate < 8000)
571 rate = 8000;
572 dmabuf->rate = rate;
573
574 /*
575 * Adjust for misclocked crap
576 */
577
578 rate = (rate * clocking) / 48000;
579
580 if (strict_clocking && rate < 8000) {
581 rate = 8000;
582 dmabuf->rate = (rate * 48000) / clocking;
583 }
584
585 new_rate = ac97_set_dac_rate(codec, rate);
586 if (new_rate != rate) {
587 dmabuf->rate = (new_rate * 48000) / clocking;
588 }
589 rate = new_rate;
590 return dmabuf->rate;
591}
592
593/* set recording sample rate */
594static unsigned int ali_set_adc_rate(struct ali_state *state,
595 unsigned int rate)
596{
597 struct dmabuf *dmabuf = &state->dmabuf;
598 u32 new_rate;
599 struct ac97_codec *codec = state->card->ac97_codec[0];
600
601 if (!(state->card->ac97_features & 0x0001)) {
602 dmabuf->rate = clocking;
603 return clocking;
604 }
605
606 if (rate > 48000)
607 rate = 48000;
608 if (rate < 8000)
609 rate = 8000;
610 dmabuf->rate = rate;
611
612 /*
613 * Adjust for misclocked crap
614 */
615
616 rate = (rate * clocking) / 48000;
617 if (strict_clocking && rate < 8000) {
618 rate = 8000;
619 dmabuf->rate = (rate * 48000) / clocking;
620 }
621
622 new_rate = ac97_set_adc_rate(codec, rate);
623
624 if (new_rate != rate) {
625 dmabuf->rate = (new_rate * 48000) / clocking;
626 rate = new_rate;
627 }
628 return dmabuf->rate;
629}
630
631/* set codec independent spdifout sample rate */
632static unsigned int ali_set_codecspdifout_rate(struct ali_state *state,
633 unsigned int rate)
634{
635 struct dmabuf *dmabuf = &state->dmabuf;
636
637 if (!(state->card->ac97_features & 0x0001)) {
638 dmabuf->rate = clocking;
639 return clocking;
640 }
641
642 if (rate > 48000)
643 rate = 48000;
644 if (rate < 8000)
645 rate = 8000;
646 dmabuf->rate = rate;
647
648 return dmabuf->rate;
649}
650
651/* set controller independent spdif out function sample rate */
652static void ali_set_spdifout_rate(struct ali_state *state,
653 unsigned int rate)
654{
655 unsigned char ch_st_sel;
656 unsigned short status_rate;
657
658 switch (rate) {
659 case 44100:
660 status_rate = 0;
661 break;
662 case 32000:
663 status_rate = 0x300;
664 break;
665 case 48000:
666 default:
667 status_rate = 0x200;
668 break;
669 }
670
671 ch_st_sel = inb(state->card->iobase + ALI_SPDIFICS) & ALI_SPDIF_OUT_CH_STATUS; //select spdif_out
672
673 ch_st_sel |= 0x80; //select right
674 outb(ch_st_sel, (state->card->iobase + ALI_SPDIFICS));
675 outb(status_rate | 0x20, (state->card->iobase + ALI_SPDIFCSR + 2));
676
677 ch_st_sel &= (~0x80); //select left
678 outb(ch_st_sel, (state->card->iobase + ALI_SPDIFICS));
679 outw(status_rate | 0x10, (state->card->iobase + ALI_SPDIFCSR + 2));
680}
681
682/* get current playback/recording dma buffer pointer (byte offset from LBA),
683 called with spinlock held! */
684
685static inline unsigned ali_get_dma_addr(struct ali_state *state, int rec)
686{
687 struct dmabuf *dmabuf = &state->dmabuf;
688 unsigned int civ, offset, port, port_picb;
689 unsigned int data;
690
691 if (!dmabuf->enable)
692 return 0;
693
694 if (rec == 1)
695 port = state->card->iobase + dmabuf->read_channel->port;
696 else if (rec == 2)
697 port = state->card->iobase + dmabuf->codec_spdifout_channel->port;
698 else if (rec == 3)
699 port = state->card->iobase + dmabuf->controller_spdifout_channel->port;
700 else
701 port = state->card->iobase + dmabuf->write_channel->port;
702
703 port_picb = port + OFF_PICB;
704
705 do {
706 civ = inb(port + OFF_CIV) & 31;
707 offset = inw(port_picb);
708 /* Must have a delay here! */
709 if (offset == 0)
710 udelay(1);
711
712 /* Reread both registers and make sure that that total
713 * offset from the first reading to the second is 0.
714 * There is an issue with SiS hardware where it will count
715 * picb down to 0, then update civ to the next value,
716 * then set the new picb to fragsize bytes. We can catch
717 * it between the civ update and the picb update, making
718 * it look as though we are 1 fragsize ahead of where we
719 * are. The next to we get the address though, it will
720 * be back in thdelay is more than long enough
721 * that we won't have to worry about the chip still being
722 * out of sync with reality ;-)
723 */
724 } while (civ != (inb(port + OFF_CIV) & 31) || offset != inw(port_picb));
725
726 data = ((civ + 1) * dmabuf->fragsize - (2 * offset)) % dmabuf->dmasize;
727 if (inw(port_picb) == 0)
728 data -= 2048;
729
730 return data;
731}
732
733/* Stop recording (lock held) */
734static inline void __stop_adc(struct ali_state *state)
735{
736 struct dmabuf *dmabuf = &state->dmabuf;
737 struct ali_card *card = state->card;
738
739 dmabuf->enable &= ~ADC_RUNNING;
740
741 outl((1 << 18) | (1 << 16), card->iobase + ALI_DMACR);
742 udelay(1);
743
744 outb(0, card->iobase + PI_CR);
745 while (inb(card->iobase + PI_CR) != 0);
746
747 // now clear any latent interrupt bits (like the halt bit)
748 outb(inb(card->iobase + PI_SR) | 0x001e, card->iobase + PI_SR);
749 outl(inl(card->iobase + ALI_INTERRUPTSR) & INT_PCMIN, card->iobase + ALI_INTERRUPTSR);
750}
751
752static void stop_adc(struct ali_state *state)
753{
754 struct ali_card *card = state->card;
755 unsigned long flags;
756 spin_lock_irqsave(&card->lock, flags);
757 __stop_adc(state);
758 spin_unlock_irqrestore(&card->lock, flags);
759}
760
761static inline void __start_adc(struct ali_state *state)
762{
763 struct dmabuf *dmabuf = &state->dmabuf;
764
765 if (dmabuf->count < dmabuf->dmasize && dmabuf->ready
766 && !dmabuf->enable && (dmabuf->trigger & PCM_ENABLE_INPUT)) {
767 dmabuf->enable |= ADC_RUNNING;
768 outb((1 << 4) | (1 << 2), state->card->iobase + PI_CR);
769 if (state->card->channel[0].used == 1)
770 outl(1, state->card->iobase + ALI_DMACR); // DMA CONTROL REGISTRER
771 udelay(100);
772 if (state->card->channel[2].used == 1)
773 outl((1 << 2), state->card->iobase + ALI_DMACR); //DMA CONTROL REGISTER
774 udelay(100);
775 }
776}
777
778static void start_adc(struct ali_state *state)
779{
780 struct ali_card *card = state->card;
781 unsigned long flags;
782
783 spin_lock_irqsave(&card->lock, flags);
784 __start_adc(state);
785 spin_unlock_irqrestore(&card->lock, flags);
786}
787
788/* stop playback (lock held) */
789static inline void __stop_dac(struct ali_state *state)
790{
791 struct dmabuf *dmabuf = &state->dmabuf;
792 struct ali_card *card = state->card;
793
794 dmabuf->enable &= ~DAC_RUNNING;
795 outl(0x00020000, card->iobase + 0x08);
796 outb(0, card->iobase + PO_CR);
797 while (inb(card->iobase + PO_CR) != 0)
798 cpu_relax();
799
800 outb(inb(card->iobase + PO_SR) | 0x001e, card->iobase + PO_SR);
801
802 outl(inl(card->iobase + ALI_INTERRUPTSR) & INT_PCMOUT, card->iobase + ALI_INTERRUPTSR);
803}
804
805static void stop_dac(struct ali_state *state)
806{
807 struct ali_card *card = state->card;
808 unsigned long flags;
809 spin_lock_irqsave(&card->lock, flags);
810 __stop_dac(state);
811 spin_unlock_irqrestore(&card->lock, flags);
812}
813
814static inline void __start_dac(struct ali_state *state)
815{
816 struct dmabuf *dmabuf = &state->dmabuf;
817 if (dmabuf->count > 0 && dmabuf->ready && !dmabuf->enable &&
818 (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
819 dmabuf->enable |= DAC_RUNNING;
820 outb((1 << 4) | (1 << 2), state->card->iobase + PO_CR);
821 outl((1 << 1), state->card->iobase + 0x08); //dma control register
822 }
823}
824
825static void start_dac(struct ali_state *state)
826{
827 struct ali_card *card = state->card;
828 unsigned long flags;
829 spin_lock_irqsave(&card->lock, flags);
830 __start_dac(state);
831 spin_unlock_irqrestore(&card->lock, flags);
832}
833
834/* stop codec and controller spdif out (lock held) */
835static inline void __stop_spdifout(struct ali_state *state)
836{
837 struct dmabuf *dmabuf = &state->dmabuf;
838 struct ali_card *card = state->card;
839
840 if (codec_independent_spdif_locked > 0) {
841 dmabuf->enable &= ~CODEC_SPDIFOUT_RUNNING;
842 outl((1 << 19), card->iobase + 0x08);
843 outb(0, card->iobase + CODECSPDIFOUT_CR);
844
845 while (inb(card->iobase + CODECSPDIFOUT_CR) != 0)
846 cpu_relax();
847
848 outb(inb(card->iobase + CODECSPDIFOUT_SR) | 0x001e, card->iobase + CODECSPDIFOUT_SR);
849 outl(inl(card->iobase + ALI_INTERRUPTSR) & INT_CODECSPDIFOUT, card->iobase + ALI_INTERRUPTSR);
850 } else {
851 if (controller_independent_spdif_locked > 0) {
852 dmabuf->enable &= ~CONTROLLER_SPDIFOUT_RUNNING;
853 outl((1 << 23), card->iobase + 0x08);
854 outb(0, card->iobase + CONTROLLERSPDIFOUT_CR);
855 while (inb(card->iobase + CONTROLLERSPDIFOUT_CR) != 0)
856 cpu_relax();
857 outb(inb(card->iobase + CONTROLLERSPDIFOUT_SR) | 0x001e, card->iobase + CONTROLLERSPDIFOUT_SR);
858 outl(inl(card->iobase + ALI_INTERRUPTSR) & INT_SPDIFOUT, card->iobase + ALI_INTERRUPTSR);
859 }
860 }
861}
862
863static void stop_spdifout(struct ali_state *state)
864{
865 struct ali_card *card = state->card;
866 unsigned long flags;
867 spin_lock_irqsave(&card->lock, flags);
868 __stop_spdifout(state);
869 spin_unlock_irqrestore(&card->lock, flags);
870}
871
872static inline void __start_spdifout(struct ali_state *state)
873{
874 struct dmabuf *dmabuf = &state->dmabuf;
875 if (dmabuf->count > 0 && dmabuf->ready && !dmabuf->enable &&
876 (dmabuf->trigger & SPDIF_ENABLE_OUTPUT)) {
877 if (codec_independent_spdif_locked > 0) {
878 dmabuf->enable |= CODEC_SPDIFOUT_RUNNING;
879 outb((1 << 4) | (1 << 2), state->card->iobase + CODECSPDIFOUT_CR);
880 outl((1 << 3), state->card->iobase + 0x08); //dma control register
881 } else {
882 if (controller_independent_spdif_locked > 0) {
883 dmabuf->enable |= CONTROLLER_SPDIFOUT_RUNNING;
884 outb((1 << 4) | (1 << 2), state->card->iobase + CONTROLLERSPDIFOUT_CR);
885 outl((1 << 7), state->card->iobase + 0x08); //dma control register
886 }
887 }
888 }
889}
890
891static void start_spdifout(struct ali_state *state)
892{
893 struct ali_card *card = state->card;
894 unsigned long flags;
895 spin_lock_irqsave(&card->lock, flags);
896 __start_spdifout(state);
897 spin_unlock_irqrestore(&card->lock, flags);
898}
899
900#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT)
901#define DMABUF_MINORDER 1
902
903/* allocate DMA buffer, playback , recording,spdif out buffer should be allocated separately */
904static int alloc_dmabuf(struct ali_state *state)
905{
906 struct dmabuf *dmabuf = &state->dmabuf;
907 void *rawbuf = NULL;
908 int order, size;
909 struct page *page, *pend;
910
911 /* If we don't have any oss frag params, then use our default ones */
912 if (dmabuf->ossmaxfrags == 0)
913 dmabuf->ossmaxfrags = 4;
914 if (dmabuf->ossfragsize == 0)
915 dmabuf->ossfragsize = (PAGE_SIZE << DMABUF_DEFAULTORDER) / dmabuf->ossmaxfrags;
916 size = dmabuf->ossfragsize * dmabuf->ossmaxfrags;
917
918 if (dmabuf->rawbuf && (PAGE_SIZE << dmabuf->buforder) == size)
919 return 0;
920 /* alloc enough to satisfy the oss params */
921 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--) {
922 if ((PAGE_SIZE << order) > size)
923 continue;
924 if ((rawbuf = pci_alloc_consistent(state->card->pci_dev,
925 PAGE_SIZE << order,
926 &dmabuf->dma_handle)))
927 break;
928 }
929 if (!rawbuf)
930 return -ENOMEM;
931
932 dmabuf->ready = dmabuf->mapped = 0;
933 dmabuf->rawbuf = rawbuf;
934 dmabuf->buforder = order;
935
936 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
937 pend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1);
938 for (page = virt_to_page(rawbuf); page <= pend; page++)
939 SetPageReserved(page);
940 return 0;
941}
942
943/* free DMA buffer */
944static void dealloc_dmabuf(struct ali_state *state)
945{
946 struct dmabuf *dmabuf = &state->dmabuf;
947 struct page *page, *pend;
948
949 if (dmabuf->rawbuf) {
950 /* undo marking the pages as reserved */
951 pend = virt_to_page(dmabuf->rawbuf + (PAGE_SIZE << dmabuf->buforder) - 1);
952 for (page = virt_to_page(dmabuf->rawbuf); page <= pend; page++)
953 ClearPageReserved(page);
954 pci_free_consistent(state->card->pci_dev,
955 PAGE_SIZE << dmabuf->buforder,
956 dmabuf->rawbuf, dmabuf->dma_handle);
957 }
958 dmabuf->rawbuf = NULL;
959 dmabuf->mapped = dmabuf->ready = 0;
960}
961
962static int prog_dmabuf(struct ali_state *state, unsigned rec)
963{
964 struct dmabuf *dmabuf = &state->dmabuf;
965 struct ali_channel *c = NULL;
966 struct sg_item *sg;
967 unsigned long flags;
968 int ret;
969 unsigned fragint;
970 int i;
971
972 spin_lock_irqsave(&state->card->lock, flags);
973 if (dmabuf->enable & DAC_RUNNING)
974 __stop_dac(state);
975 if (dmabuf->enable & ADC_RUNNING)
976 __stop_adc(state);
977 if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING)
978 __stop_spdifout(state);
979 if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)
980 __stop_spdifout(state);
981
982 dmabuf->total_bytes = 0;
983 dmabuf->count = dmabuf->error = 0;
984 dmabuf->swptr = dmabuf->hwptr = 0;
985 spin_unlock_irqrestore(&state->card->lock, flags);
986
987 /* allocate DMA buffer, let alloc_dmabuf determine if we are already
988 * allocated well enough or if we should replace the current buffer
989 * (assuming one is already allocated, if it isn't, then allocate it).
990 */
991 if ((ret = alloc_dmabuf(state)))
992 return ret;
993
994 /* FIXME: figure out all this OSS fragment stuff */
995 /* I did, it now does what it should according to the OSS API. DL */
996 /* We may not have realloced our dmabuf, but the fragment size to
997 * fragment number ratio may have changed, so go ahead and reprogram
998 * things
999 */
1000
1001 dmabuf->dmasize = PAGE_SIZE << dmabuf->buforder;
1002 dmabuf->numfrag = SG_LEN;
1003 dmabuf->fragsize = dmabuf->dmasize / dmabuf->numfrag;
1004 dmabuf->fragsamples = dmabuf->fragsize >> 1;
1005 dmabuf->userfragsize = dmabuf->ossfragsize;
1006 dmabuf->userfrags = dmabuf->dmasize / dmabuf->ossfragsize;
1007
1008 memset(dmabuf->rawbuf, 0, dmabuf->dmasize);
1009
1010 if (dmabuf->ossmaxfrags == 4) {
1011 fragint = 8;
1012 dmabuf->fragshift = 2;
1013 } else if (dmabuf->ossmaxfrags == 8) {
1014 fragint = 4;
1015 dmabuf->fragshift = 3;
1016 } else if (dmabuf->ossmaxfrags == 16) {
1017 fragint = 2;
1018 dmabuf->fragshift = 4;
1019 } else {
1020 fragint = 1;
1021 dmabuf->fragshift = 5;
1022 }
1023 /*
1024 * Now set up the ring
1025 */
1026
1027 if (rec == 1)
1028 c = dmabuf->read_channel;
1029 else if (rec == 2)
1030 c = dmabuf->codec_spdifout_channel;
1031 else if (rec == 3)
1032 c = dmabuf->controller_spdifout_channel;
1033 else if (rec == 0)
1034 c = dmabuf->write_channel;
1035 if (c != NULL) {
1036 sg = &c->sg[0];
1037 /*
1038 * Load up 32 sg entries and take an interrupt at half
1039 * way (we might want more interrupts later..)
1040 */
1041 for (i = 0; i < dmabuf->numfrag; i++) {
1042 sg->busaddr =
1043 virt_to_bus(dmabuf->rawbuf +
1044 dmabuf->fragsize * i);
1045 // the card will always be doing 16bit stereo
1046 sg->control = dmabuf->fragsamples;
1047 sg->control |= CON_BUFPAD; //I modify
1048 // set us up to get IOC interrupts as often as needed to
1049 // satisfy numfrag requirements, no more
1050 if (((i + 1) % fragint) == 0) {
1051 sg->control |= CON_IOC;
1052 }
1053 sg++;
1054 }
1055 spin_lock_irqsave(&state->card->lock, flags);
1056 outb(2, state->card->iobase + c->port + OFF_CR); /* reset DMA machine */
1057 outl(virt_to_bus(&c->sg[0]), state->card->iobase + c->port + OFF_BDBAR);
1058 outb(0, state->card->iobase + c->port + OFF_CIV);
1059 outb(0, state->card->iobase + c->port + OFF_LVI);
1060 spin_unlock_irqrestore(&state->card->lock, flags);
1061 }
1062 /* set the ready flag for the dma buffer */
1063 dmabuf->ready = 1;
1064 return 0;
1065}
1066
1067static void __ali_update_lvi(struct ali_state *state, int rec)
1068{
1069 struct dmabuf *dmabuf = &state->dmabuf;
1070 int x, port;
1071 port = state->card->iobase;
1072 if (rec == 1)
1073 port += dmabuf->read_channel->port;
1074 else if (rec == 2)
1075 port += dmabuf->codec_spdifout_channel->port;
1076 else if (rec == 3)
1077 port += dmabuf->controller_spdifout_channel->port;
1078 else if (rec == 0)
1079 port += dmabuf->write_channel->port;
1080 /* if we are currently stopped, then our CIV is actually set to our
1081 * *last* sg segment and we are ready to wrap to the next. However,
1082 * if we set our LVI to the last sg segment, then it won't wrap to
1083 * the next sg segment, it won't even get a start. So, instead, when
1084 * we are stopped, we set both the LVI value and also we increment
1085 * the CIV value to the next sg segment to be played so that when
1086 * we call start_{dac,adc}, things will operate properly
1087 */
1088 if (!dmabuf->enable && dmabuf->ready) {
1089 if (rec && dmabuf->count < dmabuf->dmasize && (dmabuf->trigger & PCM_ENABLE_INPUT)) {
1090 outb((inb(port + OFF_CIV) + 1) & 31, port + OFF_LVI);
1091 __start_adc(state);
1092 while (! (inb(port + OFF_CR) & ((1 << 4) | (1 << 2))))
1093 cpu_relax();
1094 } else if (!rec && dmabuf->count && (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
1095 outb((inb(port + OFF_CIV) + 1) & 31, port + OFF_LVI);
1096 __start_dac(state);
1097 while (!(inb(port + OFF_CR) & ((1 << 4) | (1 << 2))))
1098 cpu_relax();
1099 } else if (rec && dmabuf->count && (dmabuf->trigger & SPDIF_ENABLE_OUTPUT)) {
1100 if (codec_independent_spdif_locked > 0) {
1101 // outb((inb(port+OFF_CIV))&31, port+OFF_LVI);
1102 outb((inb(port + OFF_CIV) + 1) & 31, port + OFF_LVI);
1103 __start_spdifout(state);
1104 while (!(inb(port + OFF_CR) & ((1 << 4) | (1 << 2))))
1105 cpu_relax();
1106 } else {
1107 if (controller_independent_spdif_locked > 0) {
1108 outb((inb(port + OFF_CIV) + 1) & 31, port + OFF_LVI);
1109 __start_spdifout(state);
1110 while (!(inb(port + OFF_CR) & ((1 << 4) | (1 << 2))))
1111 cpu_relax();
1112 }
1113 }
1114 }
1115 }
1116
1117 /* swptr - 1 is the tail of our transfer */
1118 x = (dmabuf->dmasize + dmabuf->swptr - 1) % dmabuf->dmasize;
1119 x /= dmabuf->fragsize;
1120 outb(x, port + OFF_LVI);
1121}
1122
1123static void ali_update_lvi(struct ali_state *state, int rec)
1124{
1125 struct dmabuf *dmabuf = &state->dmabuf;
1126 unsigned long flags;
1127 if (!dmabuf->ready)
1128 return;
1129 spin_lock_irqsave(&state->card->lock, flags);
1130 __ali_update_lvi(state, rec);
1131 spin_unlock_irqrestore(&state->card->lock, flags);
1132}
1133
1134/* update buffer manangement pointers, especially, dmabuf->count and dmabuf->hwptr */
1135static void ali_update_ptr(struct ali_state *state)
1136{
1137 struct dmabuf *dmabuf = &state->dmabuf;
1138 unsigned hwptr;
1139 int diff;
1140
1141 /* error handling and process wake up for DAC */
1142 if (dmabuf->enable == ADC_RUNNING) {
1143 /* update hardware pointer */
1144 hwptr = ali_get_dma_addr(state, 1);
1145 diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize;
1146 dmabuf->hwptr = hwptr;
1147 dmabuf->total_bytes += diff;
1148 dmabuf->count += diff;
1149 if (dmabuf->count > dmabuf->dmasize) {
1150 /* buffer underrun or buffer overrun */
1151 /* this is normal for the end of a read */
1152 /* only give an error if we went past the */
1153 /* last valid sg entry */
1154 if ((inb(state->card->iobase + PI_CIV) & 31) != (inb(state->card->iobase + PI_LVI) & 31)) {
1155 printk(KERN_WARNING "ali_audio: DMA overrun on read\n");
1156 dmabuf->error++;
1157 }
1158 }
1159 if (dmabuf->count > dmabuf->userfragsize)
1160 wake_up(&dmabuf->wait);
1161 }
1162 /* error handling and process wake up for DAC */
1163 if (dmabuf->enable == DAC_RUNNING) {
1164 /* update hardware pointer */
1165 hwptr = ali_get_dma_addr(state, 0);
1166 diff =
1167 (dmabuf->dmasize + hwptr -
1168 dmabuf->hwptr) % dmabuf->dmasize;
1169#if defined(DEBUG_INTERRUPTS) || defined(DEBUG_MMAP)
1170 printk("DAC HWP %d,%d,%d\n", hwptr, dmabuf->hwptr, diff);
1171#endif
1172 dmabuf->hwptr = hwptr;
1173 dmabuf->total_bytes += diff;
1174 dmabuf->count -= diff;
1175 if (dmabuf->count < 0) {
1176 /* buffer underrun or buffer overrun */
1177 /* this is normal for the end of a write */
1178 /* only give an error if we went past the */
1179 /* last valid sg entry */
1180 if ((inb(state->card->iobase + PO_CIV) & 31) != (inb(state->card->iobase + PO_LVI) & 31)) {
1181 printk(KERN_WARNING "ali_audio: DMA overrun on write\n");
1182 printk(KERN_DEBUG "ali_audio: CIV %d, LVI %d, hwptr %x, count %d\n",
1183 inb(state->card->iobase + PO_CIV) & 31,
1184 inb(state->card->iobase + PO_LVI) & 31,
1185 dmabuf->hwptr,
1186 dmabuf->count);
1187 dmabuf->error++;
1188 }
1189 }
1190 if (dmabuf->count < (dmabuf->dmasize - dmabuf->userfragsize))
1191 wake_up(&dmabuf->wait);
1192 }
1193
1194 /* error handling and process wake up for CODEC SPDIF OUT */
1195 if (dmabuf->enable == CODEC_SPDIFOUT_RUNNING) {
1196 /* update hardware pointer */
1197 hwptr = ali_get_dma_addr(state, 2);
1198 diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize;
1199 dmabuf->hwptr = hwptr;
1200 dmabuf->total_bytes += diff;
1201 dmabuf->count -= diff;
1202 if (dmabuf->count < 0) {
1203 /* buffer underrun or buffer overrun */
1204 /* this is normal for the end of a write */
1205 /* only give an error if we went past the */
1206 /* last valid sg entry */
1207 if ((inb(state->card->iobase + CODECSPDIFOUT_CIV) & 31) != (inb(state->card->iobase + CODECSPDIFOUT_LVI) & 31)) {
1208 printk(KERN_WARNING "ali_audio: DMA overrun on write\n");
1209 printk(KERN_DEBUG "ali_audio: CIV %d, LVI %d, hwptr %x, count %d\n",
1210 inb(state->card->iobase + CODECSPDIFOUT_CIV) & 31,
1211 inb(state->card->iobase + CODECSPDIFOUT_LVI) & 31,
1212 dmabuf->hwptr, dmabuf->count);
1213 dmabuf->error++;
1214 }
1215 }
1216 if (dmabuf->count < (dmabuf->dmasize - dmabuf->userfragsize))
1217 wake_up(&dmabuf->wait);
1218 }
1219 /* error handling and process wake up for CONTROLLER SPDIF OUT */
1220 if (dmabuf->enable == CONTROLLER_SPDIFOUT_RUNNING) {
1221 /* update hardware pointer */
1222 hwptr = ali_get_dma_addr(state, 3);
1223 diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize;
1224 dmabuf->hwptr = hwptr;
1225 dmabuf->total_bytes += diff;
1226 dmabuf->count -= diff;
1227 if (dmabuf->count < 0) {
1228 /* buffer underrun or buffer overrun */
1229 /* this is normal for the end of a write */
1230 /* only give an error if we went past the */
1231 /* last valid sg entry */
1232 if ((inb(state->card->iobase + CONTROLLERSPDIFOUT_CIV) & 31) != (inb(state->card->iobase + CONTROLLERSPDIFOUT_LVI) & 31)) {
1233 printk(KERN_WARNING
1234 "ali_audio: DMA overrun on write\n");
1235 printk("ali_audio: CIV %d, LVI %d, hwptr %x, "
1236 "count %d\n",
1237 inb(state->card->iobase + CONTROLLERSPDIFOUT_CIV) & 31,
1238 inb(state->card->iobase + CONTROLLERSPDIFOUT_LVI) & 31,
1239 dmabuf->hwptr, dmabuf->count);
1240 dmabuf->error++;
1241 }
1242 }
1243 if (dmabuf->count < (dmabuf->dmasize - dmabuf->userfragsize))
1244 wake_up(&dmabuf->wait);
1245 }
1246}
1247
1248static inline int ali_get_free_write_space(struct
1249 ali_state
1250 *state)
1251{
1252 struct dmabuf *dmabuf = &state->dmabuf;
1253 int free;
1254
1255 if (dmabuf->count < 0) {
1256 dmabuf->count = 0;
1257 dmabuf->swptr = dmabuf->hwptr;
1258 }
1259 free = dmabuf->dmasize - dmabuf->swptr;
1260 if ((dmabuf->count + free) > dmabuf->dmasize){
1261 free = dmabuf->dmasize - dmabuf->count;
1262 }
1263 return free;
1264}
1265
1266static inline int ali_get_available_read_data(struct
1267 ali_state
1268 *state)
1269{
1270 struct dmabuf *dmabuf = &state->dmabuf;
1271 int avail;
1272 ali_update_ptr(state);
1273 // catch overruns during record
1274 if (dmabuf->count > dmabuf->dmasize) {
1275 dmabuf->count = dmabuf->dmasize;
1276 dmabuf->swptr = dmabuf->hwptr;
1277 }
1278 avail = dmabuf->count;
1279 avail -= (dmabuf->hwptr % dmabuf->fragsize);
1280 if (avail < 0)
1281 return (0);
1282 return (avail);
1283}
1284
1285static int drain_dac(struct ali_state *state, int signals_allowed)
1286{
1287
1288 DECLARE_WAITQUEUE(wait, current);
1289 struct dmabuf *dmabuf = &state->dmabuf;
1290 unsigned long flags;
1291 unsigned long tmo;
1292 int count;
1293 if (!dmabuf->ready)
1294 return 0;
1295 if (dmabuf->mapped) {
1296 stop_dac(state);
1297 return 0;
1298 }
1299 add_wait_queue(&dmabuf->wait, &wait);
1300 for (;;) {
1301
1302 spin_lock_irqsave(&state->card->lock, flags);
1303 ali_update_ptr(state);
1304 count = dmabuf->count;
1305 spin_unlock_irqrestore(&state->card->lock, flags);
1306 if (count <= 0)
1307 break;
1308 /*
1309 * This will make sure that our LVI is correct, that our
1310 * pointer is updated, and that the DAC is running. We
1311 * have to force the setting of dmabuf->trigger to avoid
1312 * any possible deadlocks.
1313 */
1314 if (!dmabuf->enable) {
1315 dmabuf->trigger = PCM_ENABLE_OUTPUT;
1316 ali_update_lvi(state, 0);
1317 }
1318 if (signal_pending(current) && signals_allowed) {
1319 break;
1320 }
1321
1322 /* It seems that we have to set the current state to
1323 * TASK_INTERRUPTIBLE every time to make the process
1324 * really go to sleep. This also has to be *after* the
1325 * update_ptr() call because update_ptr is likely to
1326 * do a wake_up() which will unset this before we ever
1327 * try to sleep, resuling in a tight loop in this code
1328 * instead of actually sleeping and waiting for an
1329 * interrupt to wake us up!
1330 */
1331 set_current_state(TASK_INTERRUPTIBLE);
1332 /*
1333 * set the timeout to significantly longer than it *should*
1334 * take for the DAC to drain the DMA buffer
1335 */
1336 tmo = (count * HZ) / (dmabuf->rate);
1337 if (!schedule_timeout(tmo >= 2 ? tmo : 2)) {
1338 printk(KERN_ERR "ali_audio: drain_dac, dma timeout?\n");
1339 count = 0;
1340 break;
1341 }
1342 }
1343 set_current_state(TASK_RUNNING);
1344 remove_wait_queue(&dmabuf->wait, &wait);
1345 if (count > 0 && signal_pending(current) && signals_allowed)
1346 return -ERESTARTSYS;
1347 stop_dac(state);
1348 return 0;
1349}
1350
1351
1352static int drain_spdifout(struct ali_state *state, int signals_allowed)
1353{
1354
1355 DECLARE_WAITQUEUE(wait, current);
1356 struct dmabuf *dmabuf = &state->dmabuf;
1357 unsigned long flags;
1358 unsigned long tmo;
1359 int count;
1360 if (!dmabuf->ready)
1361 return 0;
1362 if (dmabuf->mapped) {
1363 stop_spdifout(state);
1364 return 0;
1365 }
1366 add_wait_queue(&dmabuf->wait, &wait);
1367 for (;;) {
1368
1369 spin_lock_irqsave(&state->card->lock, flags);
1370 ali_update_ptr(state);
1371 count = dmabuf->count;
1372 spin_unlock_irqrestore(&state->card->lock, flags);
1373 if (count <= 0)
1374 break;
1375 /*
1376 * This will make sure that our LVI is correct, that our
1377 * pointer is updated, and that the DAC is running. We
1378 * have to force the setting of dmabuf->trigger to avoid
1379 * any possible deadlocks.
1380 */
1381 if (!dmabuf->enable) {
1382 if (codec_independent_spdif_locked > 0) {
1383 dmabuf->trigger = SPDIF_ENABLE_OUTPUT;
1384 ali_update_lvi(state, 2);
1385 } else {
1386 if (controller_independent_spdif_locked > 0) {
1387 dmabuf->trigger = SPDIF_ENABLE_OUTPUT;
1388 ali_update_lvi(state, 3);
1389 }
1390 }
1391 }
1392 if (signal_pending(current) && signals_allowed) {
1393 break;
1394 }
1395
1396 /* It seems that we have to set the current state to
1397 * TASK_INTERRUPTIBLE every time to make the process
1398 * really go to sleep. This also has to be *after* the
1399 * update_ptr() call because update_ptr is likely to
1400 * do a wake_up() which will unset this before we ever
1401 * try to sleep, resuling in a tight loop in this code
1402 * instead of actually sleeping and waiting for an
1403 * interrupt to wake us up!
1404 */
1405 set_current_state(TASK_INTERRUPTIBLE);
1406 /*
1407 * set the timeout to significantly longer than it *should*
1408 * take for the DAC to drain the DMA buffer
1409 */
1410 tmo = (count * HZ) / (dmabuf->rate);
1411 if (!schedule_timeout(tmo >= 2 ? tmo : 2)) {
1412 printk(KERN_ERR "ali_audio: drain_spdifout, dma timeout?\n");
1413 count = 0;
1414 break;
1415 }
1416 }
1417 set_current_state(TASK_RUNNING);
1418 remove_wait_queue(&dmabuf->wait, &wait);
1419 if (count > 0 && signal_pending(current) && signals_allowed)
1420 return -ERESTARTSYS;
1421 stop_spdifout(state);
1422 return 0;
1423}
1424
1425static void ali_channel_interrupt(struct ali_card *card)
1426{
1427 int i, count;
1428
1429 for (i = 0; i < NR_HW_CH; i++) {
1430 struct ali_state *state = card->states[i];
1431 struct ali_channel *c = NULL;
1432 struct dmabuf *dmabuf;
1433 unsigned long port = card->iobase;
1434 u16 status;
1435 if (!state)
1436 continue;
1437 if (!state->dmabuf.ready)
1438 continue;
1439 dmabuf = &state->dmabuf;
1440 if (codec_independent_spdif_locked > 0) {
1441 if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING) {
1442 c = dmabuf->codec_spdifout_channel;
1443 }
1444 } else {
1445 if (controller_independent_spdif_locked > 0) {
1446 if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)
1447 c = dmabuf->controller_spdifout_channel;
1448 } else {
1449 if (dmabuf->enable & DAC_RUNNING) {
1450 c = dmabuf->write_channel;
1451 } else if (dmabuf->enable & ADC_RUNNING) {
1452 c = dmabuf->read_channel;
1453 } else
1454 continue;
1455 }
1456 }
1457 port += c->port;
1458
1459 status = inw(port + OFF_SR);
1460
1461 if (status & DMA_INT_COMPLETE) {
1462 /* only wake_up() waiters if this interrupt signals
1463 * us being beyond a userfragsize of data open or
1464 * available, and ali_update_ptr() does that for
1465 * us
1466 */
1467 ali_update_ptr(state);
1468 }
1469
1470 if (status & DMA_INT_LVI) {
1471 ali_update_ptr(state);
1472 wake_up(&dmabuf->wait);
1473
1474 if (dmabuf->enable & DAC_RUNNING)
1475 count = dmabuf->count;
1476 else if (dmabuf->enable & ADC_RUNNING)
1477 count = dmabuf->dmasize - dmabuf->count;
1478 else if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING)
1479 count = dmabuf->count;
1480 else if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)
1481 count = dmabuf->count;
1482 else count = 0;
1483
1484 if (count > 0) {
1485 if (dmabuf->enable & DAC_RUNNING)
1486 outl((1 << 1), state->card->iobase + ALI_DMACR);
1487 else if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING)
1488 outl((1 << 3), state->card->iobase + ALI_DMACR);
1489 else if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)
1490 outl((1 << 7), state->card->iobase + ALI_DMACR);
1491 } else {
1492 if (dmabuf->enable & DAC_RUNNING)
1493 __stop_dac(state);
1494 if (dmabuf->enable & ADC_RUNNING)
1495 __stop_adc(state);
1496 if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING)
1497 __stop_spdifout(state);
1498 if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)
1499 __stop_spdifout(state);
1500 dmabuf->enable = 0;
1501 wake_up(&dmabuf->wait);
1502 }
1503
1504 }
1505 if (!(status & DMA_INT_DCH)) {
1506 ali_update_ptr(state);
1507 wake_up(&dmabuf->wait);
1508 if (dmabuf->enable & DAC_RUNNING)
1509 count = dmabuf->count;
1510 else if (dmabuf->enable & ADC_RUNNING)
1511 count = dmabuf->dmasize - dmabuf->count;
1512 else if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING)
1513 count = dmabuf->count;
1514 else if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)
1515 count = dmabuf->count;
1516 else
1517 count = 0;
1518
1519 if (count > 0) {
1520 if (dmabuf->enable & DAC_RUNNING)
1521 outl((1 << 1), state->card->iobase + ALI_DMACR);
1522 else if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING)
1523 outl((1 << 3), state->card->iobase + ALI_DMACR);
1524 else if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)
1525 outl((1 << 7), state->card->iobase + ALI_DMACR);
1526 } else {
1527 if (dmabuf->enable & DAC_RUNNING)
1528 __stop_dac(state);
1529 if (dmabuf->enable & ADC_RUNNING)
1530 __stop_adc(state);
1531 if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING)
1532 __stop_spdifout(state);
1533 if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)
1534 __stop_spdifout(state);
1535 dmabuf->enable = 0;
1536 wake_up(&dmabuf->wait);
1537 }
1538 }
1539 outw(status & DMA_INT_MASK, port + OFF_SR);
1540 }
1541}
1542
1543static irqreturn_t ali_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1544{
1545 struct ali_card *card = (struct ali_card *) dev_id;
1546 u32 status;
1547 u16 status2;
1548
1549 spin_lock(&card->lock);
1550 status = inl(card->iobase + ALI_INTERRUPTSR);
1551 if (!(status & INT_MASK)) {
1552 spin_unlock(&card->lock);
1553 return IRQ_NONE; /* not for us */
1554 }
1555
1556 if (codec_independent_spdif_locked > 0) {
1557 if (globel == 0) {
1558 globel += 1;
1559 status2 = inw(card->iobase + 0x76);
1560 outw(status2 | 0x000c, card->iobase + 0x76);
1561 } else {
1562 if (status & (INT_PCMOUT | INT_PCMIN | INT_MICIN | INT_SPDIFOUT | INT_CODECSPDIFOUT))
1563 ali_channel_interrupt(card);
1564 }
1565 } else {
1566 if (status & (INT_PCMOUT | INT_PCMIN | INT_MICIN | INT_SPDIFOUT | INT_CODECSPDIFOUT))
1567 ali_channel_interrupt(card);
1568 }
1569
1570 /* clear 'em */
1571 outl(status & INT_MASK, card->iobase + ALI_INTERRUPTSR);
1572 spin_unlock(&card->lock);
1573 return IRQ_HANDLED;
1574}
1575
1576/* in this loop, dmabuf.count signifies the amount of data that is
1577 waiting to be copied to the user's buffer. It is filled by the dma
1578 machine and drained by this loop. */
1579
1580static ssize_t ali_read(struct file *file, char __user *buffer,
1581 size_t count, loff_t * ppos)
1582{
1583 struct ali_state *state = (struct ali_state *) file->private_data;
1584 struct ali_card *card = state ? state->card : NULL;
1585 struct dmabuf *dmabuf = &state->dmabuf;
1586 ssize_t ret;
1587 unsigned long flags;
1588 unsigned int swptr;
1589 int cnt;
1590 DECLARE_WAITQUEUE(waita, current);
1591#ifdef DEBUG2
1592 printk("ali_audio: ali_read called, count = %d\n", count);
1593#endif
1594 if (dmabuf->mapped)
1595 return -ENXIO;
1596 if (dmabuf->enable & DAC_RUNNING)
1597 return -ENODEV;
1598 if (!dmabuf->read_channel) {
1599 dmabuf->ready = 0;
1600 dmabuf->read_channel = card->alloc_rec_pcm_channel(card);
1601 if (!dmabuf->read_channel) {
1602 return -EBUSY;
1603 }
1604 }
1605 if (!dmabuf->ready && (ret = prog_dmabuf(state, 1)))
1606 return ret;
1607 if (!access_ok(VERIFY_WRITE, buffer, count))
1608 return -EFAULT;
1609 ret = 0;
1610 add_wait_queue(&dmabuf->wait, &waita);
1611 while (count > 0) {
1612 set_current_state(TASK_INTERRUPTIBLE);
1613 spin_lock_irqsave(&card->lock, flags);
1614 if (PM_SUSPENDED(card)) {
1615 spin_unlock_irqrestore(&card->lock, flags);
1616 schedule();
1617 if (signal_pending(current)) {
1618 if (!ret)
1619 ret = -EAGAIN;
1620 break;
1621 }
1622 continue;
1623 }
1624 swptr = dmabuf->swptr;
1625 cnt = ali_get_available_read_data(state);
1626 // this is to make the copy_to_user simpler below
1627 if (cnt > (dmabuf->dmasize - swptr))
1628 cnt = dmabuf->dmasize - swptr;
1629 spin_unlock_irqrestore(&card->lock, flags);
1630 if (cnt > count)
1631 cnt = count;
1632 /* Lop off the last two bits to force the code to always
1633 * write in full samples. This keeps software that sets
1634 * O_NONBLOCK but doesn't check the return value of the
1635 * write call from getting things out of state where they
1636 * think a full 4 byte sample was written when really only
1637 * a portion was, resulting in odd sound and stereo
1638 * hysteresis.
1639 */
1640 cnt &= ~0x3;
1641 if (cnt <= 0) {
1642 unsigned long tmo;
1643 /*
1644 * Don't let us deadlock. The ADC won't start if
1645 * dmabuf->trigger isn't set. A call to SETTRIGGER
1646 * could have turned it off after we set it to on
1647 * previously.
1648 */
1649 dmabuf->trigger = PCM_ENABLE_INPUT;
1650 /*
1651 * This does three things. Updates LVI to be correct,
1652 * makes sure the ADC is running, and updates the
1653 * hwptr.
1654 */
1655 ali_update_lvi(state, 1);
1656 if (file->f_flags & O_NONBLOCK) {
1657 if (!ret)
1658 ret = -EAGAIN;
1659 goto done;
1660 }
1661 /* Set the timeout to how long it would take to fill
1662 * two of our buffers. If we haven't been woke up
1663 * by then, then we know something is wrong.
1664 */
1665 tmo = (dmabuf->dmasize * HZ * 2) / (dmabuf->rate * 4);
1666
1667 /* There are two situations when sleep_on_timeout returns, one is when
1668 the interrupt is serviced correctly and the process is waked up by
1669 ISR ON TIME. Another is when timeout is expired, which means that
1670 either interrupt is NOT serviced correctly (pending interrupt) or it
1671 is TOO LATE for the process to be scheduled to run (scheduler latency)
1672 which results in a (potential) buffer overrun. And worse, there is
1673 NOTHING we can do to prevent it. */
1674 if (!schedule_timeout(tmo >= 2 ? tmo : 2)) {
1675 printk(KERN_ERR
1676 "ali_audio: recording schedule timeout, "
1677 "dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1678 dmabuf->dmasize, dmabuf->fragsize,
1679 dmabuf->count, dmabuf->hwptr,
1680 dmabuf->swptr);
1681 /* a buffer overrun, we delay the recovery until next time the
1682 while loop begin and we REALLY have space to record */
1683 }
1684 if (signal_pending(current)) {
1685 ret = ret ? ret : -ERESTARTSYS;
1686 goto done;
1687 }
1688 continue;
1689 }
1690
1691 if (copy_to_user(buffer, dmabuf->rawbuf + swptr, cnt)) {
1692 if (!ret)
1693 ret = -EFAULT;
1694 goto done;
1695 }
1696
1697 swptr = (swptr + cnt) % dmabuf->dmasize;
1698 spin_lock_irqsave(&card->lock, flags);
1699 if (PM_SUSPENDED(card)) {
1700 spin_unlock_irqrestore(&card->lock, flags);
1701 continue;
1702 }
1703 dmabuf->swptr = swptr;
1704 dmabuf->count -= cnt;
1705 spin_unlock_irqrestore(&card->lock, flags);
1706 count -= cnt;
1707 buffer += cnt;
1708 ret += cnt;
1709 }
1710done:
1711 ali_update_lvi(state, 1);
1712 set_current_state(TASK_RUNNING);
1713 remove_wait_queue(&dmabuf->wait, &waita);
1714 return ret;
1715}
1716
1717/* in this loop, dmabuf.count signifies the amount of data that is waiting to be dma to
1718 the soundcard. it is drained by the dma machine and filled by this loop. */
1719static ssize_t ali_write(struct file *file,
1720 const char __user *buffer, size_t count, loff_t * ppos)
1721{
1722 struct ali_state *state = (struct ali_state *) file->private_data;
1723 struct ali_card *card = state ? state->card : NULL;
1724 struct dmabuf *dmabuf = &state->dmabuf;
1725 ssize_t ret;
1726 unsigned long flags;
1727 unsigned int swptr = 0;
1728 int cnt, x;
1729 DECLARE_WAITQUEUE(waita, current);
1730#ifdef DEBUG2
1731 printk("ali_audio: ali_write called, count = %d\n", count);
1732#endif
1733 if (dmabuf->mapped)
1734 return -ENXIO;
1735 if (dmabuf->enable & ADC_RUNNING)
1736 return -ENODEV;
1737 if (codec_independent_spdif_locked > 0) {
1738 if (!dmabuf->codec_spdifout_channel) {
1739 dmabuf->ready = 0;
1740 dmabuf->codec_spdifout_channel = card->alloc_codec_spdifout_channel(card);
1741 if (!dmabuf->codec_spdifout_channel)
1742 return -EBUSY;
1743 }
1744 } else {
1745 if (controller_independent_spdif_locked > 0) {
1746 if (!dmabuf->controller_spdifout_channel) {
1747 dmabuf->ready = 0;
1748 dmabuf->controller_spdifout_channel = card->alloc_controller_spdifout_channel(card);
1749 if (!dmabuf->controller_spdifout_channel)
1750 return -EBUSY;
1751 }
1752 } else {
1753 if (!dmabuf->write_channel) {
1754 dmabuf->ready = 0;
1755 dmabuf->write_channel =
1756 card->alloc_pcm_channel(card);
1757 if (!dmabuf->write_channel)
1758 return -EBUSY;
1759 }
1760 }
1761 }
1762
1763 if (codec_independent_spdif_locked > 0) {
1764 if (!dmabuf->ready && (ret = prog_dmabuf(state, 2)))
1765 return ret;
1766 } else {
1767 if (controller_independent_spdif_locked > 0) {
1768 if (!dmabuf->ready && (ret = prog_dmabuf(state, 3)))
1769 return ret;
1770 } else {
1771
1772 if (!dmabuf->ready && (ret = prog_dmabuf(state, 0)))
1773 return ret;
1774 }
1775 }
1776 if (!access_ok(VERIFY_READ, buffer, count))
1777 return -EFAULT;
1778 ret = 0;
1779 add_wait_queue(&dmabuf->wait, &waita);
1780 while (count > 0) {
1781 set_current_state(TASK_INTERRUPTIBLE);
1782 spin_lock_irqsave(&state->card->lock, flags);
1783 if (PM_SUSPENDED(card)) {
1784 spin_unlock_irqrestore(&card->lock, flags);
1785 schedule();
1786 if (signal_pending(current)) {
1787 if (!ret)
1788 ret = -EAGAIN;
1789 break;
1790 }
1791 continue;
1792 }
1793
1794 swptr = dmabuf->swptr;
1795 cnt = ali_get_free_write_space(state);
1796 /* Bound the maximum size to how much we can copy to the
1797 * dma buffer before we hit the end. If we have more to
1798 * copy then it will get done in a second pass of this
1799 * loop starting from the beginning of the buffer.
1800 */
1801 if (cnt > (dmabuf->dmasize - swptr))
1802 cnt = dmabuf->dmasize - swptr;
1803 spin_unlock_irqrestore(&state->card->lock, flags);
1804#ifdef DEBUG2
1805 printk(KERN_INFO
1806 "ali_audio: ali_write: %d bytes available space\n",
1807 cnt);
1808#endif
1809 if (cnt > count)
1810 cnt = count;
1811 /* Lop off the last two bits to force the code to always
1812 * write in full samples. This keeps software that sets
1813 * O_NONBLOCK but doesn't check the return value of the
1814 * write call from getting things out of state where they
1815 * think a full 4 byte sample was written when really only
1816 * a portion was, resulting in odd sound and stereo
1817 * hysteresis.
1818 */
1819 cnt &= ~0x3;
1820 if (cnt <= 0) {
1821 unsigned long tmo;
1822 // There is data waiting to be played
1823 /*
1824 * Force the trigger setting since we would
1825 * deadlock with it set any other way
1826 */
1827 if (codec_independent_spdif_locked > 0) {
1828 dmabuf->trigger = SPDIF_ENABLE_OUTPUT;
1829 ali_update_lvi(state, 2);
1830 } else {
1831 if (controller_independent_spdif_locked > 0) {
1832 dmabuf->trigger = SPDIF_ENABLE_OUTPUT;
1833 ali_update_lvi(state, 3);
1834 } else {
1835
1836 dmabuf->trigger = PCM_ENABLE_OUTPUT;
1837 ali_update_lvi(state, 0);
1838 }
1839 }
1840 if (file->f_flags & O_NONBLOCK) {
1841 if (!ret)
1842 ret = -EAGAIN;
1843 goto ret;
1844 }
1845 /* Not strictly correct but works */
1846 tmo = (dmabuf->dmasize * HZ * 2) / (dmabuf->rate * 4);
1847 /* There are two situations when sleep_on_timeout returns, one is when
1848 the interrupt is serviced correctly and the process is waked up by
1849 ISR ON TIME. Another is when timeout is expired, which means that
1850 either interrupt is NOT serviced correctly (pending interrupt) or it
1851 is TOO LATE for the process to be scheduled to run (scheduler latency)
1852 which results in a (potential) buffer underrun. And worse, there is
1853 NOTHING we can do to prevent it. */
1854
1855 /* FIXME - do timeout handling here !! */
1856 schedule_timeout(tmo >= 2 ? tmo : 2);
1857
1858 if (signal_pending(current)) {
1859 if (!ret)
1860 ret = -ERESTARTSYS;
1861 goto ret;
1862 }
1863 continue;
1864 }
1865 if (copy_from_user(dmabuf->rawbuf + swptr, buffer, cnt)) {
1866 if (!ret)
1867 ret = -EFAULT;
1868 goto ret;
1869 }
1870
1871 swptr = (swptr + cnt) % dmabuf->dmasize;
1872 spin_lock_irqsave(&state->card->lock, flags);
1873 if (PM_SUSPENDED(card)) {
1874 spin_unlock_irqrestore(&card->lock, flags);
1875 continue;
1876 }
1877
1878 dmabuf->swptr = swptr;
1879 dmabuf->count += cnt;
1880 count -= cnt;
1881 buffer += cnt;
1882 ret += cnt;
1883 spin_unlock_irqrestore(&state->card->lock, flags);
1884 }
1885 if (swptr % dmabuf->fragsize) {
1886 x = dmabuf->fragsize - (swptr % dmabuf->fragsize);
1887 memset(dmabuf->rawbuf + swptr, '\0', x);
1888 }
1889ret:
1890 if (codec_independent_spdif_locked > 0) {
1891 ali_update_lvi(state, 2);
1892 } else {
1893 if (controller_independent_spdif_locked > 0) {
1894 ali_update_lvi(state, 3);
1895 } else {
1896 ali_update_lvi(state, 0);
1897 }
1898 }
1899 set_current_state(TASK_RUNNING);
1900 remove_wait_queue(&dmabuf->wait, &waita);
1901 return ret;
1902}
1903
1904/* No kernel lock - we have our own spinlock */
1905static unsigned int ali_poll(struct file *file, struct poll_table_struct
1906 *wait)
1907{
1908 struct ali_state *state = (struct ali_state *) file->private_data;
1909 struct dmabuf *dmabuf = &state->dmabuf;
1910 unsigned long flags;
1911 unsigned int mask = 0;
1912 if (!dmabuf->ready)
1913 return 0;
1914 poll_wait(file, &dmabuf->wait, wait);
1915 spin_lock_irqsave(&state->card->lock, flags);
1916 ali_update_ptr(state);
1917 if (file->f_mode & FMODE_READ && dmabuf->enable & ADC_RUNNING) {
1918 if (dmabuf->count >= (signed) dmabuf->fragsize)
1919 mask |= POLLIN | POLLRDNORM;
1920 }
1921 if (file->f_mode & FMODE_WRITE && (dmabuf->enable & (DAC_RUNNING|CODEC_SPDIFOUT_RUNNING|CONTROLLER_SPDIFOUT_RUNNING))) {
1922 if ((signed) dmabuf->dmasize >= dmabuf->count + (signed) dmabuf->fragsize)
1923 mask |= POLLOUT | POLLWRNORM;
1924 }
1925 spin_unlock_irqrestore(&state->card->lock, flags);
1926 return mask;
1927}
1928
1929static int ali_mmap(struct file *file, struct vm_area_struct *vma)
1930{
1931 struct ali_state *state = (struct ali_state *) file->private_data;
1932 struct dmabuf *dmabuf = &state->dmabuf;
1933 int ret = -EINVAL;
1934 unsigned long size;
1935 lock_kernel();
1936 if (vma->vm_flags & VM_WRITE) {
1937 if (!dmabuf->write_channel && (dmabuf->write_channel = state->card->alloc_pcm_channel(state->card)) == NULL) {
1938 ret = -EBUSY;
1939 goto out;
1940 }
1941 }
1942 if (vma->vm_flags & VM_READ) {
1943 if (!dmabuf->read_channel && (dmabuf->read_channel = state->card->alloc_rec_pcm_channel(state->card)) == NULL) {
1944 ret = -EBUSY;
1945 goto out;
1946 }
1947 }
1948 if ((ret = prog_dmabuf(state, 0)) != 0)
1949 goto out;
1950 ret = -EINVAL;
1951 if (vma->vm_pgoff != 0)
1952 goto out;
1953 size = vma->vm_end - vma->vm_start;
1954 if (size > (PAGE_SIZE << dmabuf->buforder))
1955 goto out;
1956 ret = -EAGAIN;
1957 if (remap_pfn_range(vma, vma->vm_start,
1958 virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT,
1959 size, vma->vm_page_prot))
1960 goto out;
1961 dmabuf->mapped = 1;
1962 dmabuf->trigger = 0;
1963 ret = 0;
1964out:
1965 unlock_kernel();
1966 return ret;
1967}
1968
1969static int ali_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1970{
1971 struct ali_state *state = (struct ali_state *) file->private_data;
1972 struct ali_channel *c = NULL;
1973 struct dmabuf *dmabuf = &state->dmabuf;
1974 unsigned long flags;
1975 audio_buf_info abinfo;
1976 count_info cinfo;
1977 unsigned int i_scr;
1978 int val = 0, ret;
1979 struct ac97_codec *codec = state->card->ac97_codec[0];
1980 void __user *argp = (void __user *)arg;
1981 int __user *p = argp;
1982
1983#ifdef DEBUG
1984 printk("ali_audio: ali_ioctl, arg=0x%x, cmd=",
1985 arg ? *p : 0);
1986#endif
1987 switch (cmd) {
1988 case OSS_GETVERSION:
1989#ifdef DEBUG
1990 printk("OSS_GETVERSION\n");
1991#endif
1992 return put_user(SOUND_VERSION, p);
1993 case SNDCTL_DSP_RESET:
1994#ifdef DEBUG
1995 printk("SNDCTL_DSP_RESET\n");
1996#endif
1997 spin_lock_irqsave(&state->card->lock, flags);
1998 if (dmabuf->enable == DAC_RUNNING) {
1999 c = dmabuf->write_channel;
2000 __stop_dac(state);
2001 }
2002 if (dmabuf->enable == ADC_RUNNING) {
2003 c = dmabuf->read_channel;
2004 __stop_adc(state);
2005 }
2006 if (dmabuf->enable == CODEC_SPDIFOUT_RUNNING) {
2007 c = dmabuf->codec_spdifout_channel;
2008 __stop_spdifout(state);
2009 }
2010 if (dmabuf->enable == CONTROLLER_SPDIFOUT_RUNNING) {
2011 c = dmabuf->controller_spdifout_channel;
2012 __stop_spdifout(state);
2013 }
2014 if (c != NULL) {
2015 outb(2, state->card->iobase + c->port + OFF_CR); /* reset DMA machine */
2016 outl(virt_to_bus(&c->sg[0]),
2017 state->card->iobase + c->port + OFF_BDBAR);
2018 outb(0, state->card->iobase + c->port + OFF_CIV);
2019 outb(0, state->card->iobase + c->port + OFF_LVI);
2020 }
2021
2022 spin_unlock_irqrestore(&state->card->lock, flags);
2023 synchronize_irq(state->card->pci_dev->irq);
2024 dmabuf->ready = 0;
2025 dmabuf->swptr = dmabuf->hwptr = 0;
2026 dmabuf->count = dmabuf->total_bytes = 0;
2027 return 0;
2028 case SNDCTL_DSP_SYNC:
2029#ifdef DEBUG
2030 printk("SNDCTL_DSP_SYNC\n");
2031#endif
2032 if (codec_independent_spdif_locked > 0) {
2033 if (dmabuf->enable != CODEC_SPDIFOUT_RUNNING
2034 || file->f_flags & O_NONBLOCK)
2035 return 0;
2036 if ((val = drain_spdifout(state, 1)))
2037 return val;
2038 } else {
2039 if (controller_independent_spdif_locked > 0) {
2040 if (dmabuf->enable !=
2041 CONTROLLER_SPDIFOUT_RUNNING
2042 || file->f_flags & O_NONBLOCK)
2043 return 0;
2044 if ((val = drain_spdifout(state, 1)))
2045 return val;
2046 } else {
2047 if (dmabuf->enable != DAC_RUNNING
2048 || file->f_flags & O_NONBLOCK)
2049 return 0;
2050 if ((val = drain_dac(state, 1)))
2051 return val;
2052 }
2053 }
2054 dmabuf->total_bytes = 0;
2055 return 0;
2056 case SNDCTL_DSP_SPEED: /* set smaple rate */
2057#ifdef DEBUG
2058 printk("SNDCTL_DSP_SPEED\n");
2059#endif
2060 if (get_user(val, p))
2061 return -EFAULT;
2062 if (val >= 0) {
2063 if (file->f_mode & FMODE_WRITE) {
2064 if ((state->card->ac97_status & SPDIF_ON)) { /* S/PDIF Enabled */
2065 /* RELTEK ALC650 only support 48000, need to check that */
2066 if (ali_valid_spdif_rate(codec, val)) {
2067 if (codec_independent_spdif_locked > 0) {
2068 ali_set_spdif_output(state, -1, 0);
2069 stop_spdifout(state);
2070 dmabuf->ready = 0;
2071 /* I add test codec independent spdif out */
2072 spin_lock_irqsave(&state->card->lock, flags);
2073 ali_set_codecspdifout_rate(state, val); // I modified
2074 spin_unlock_irqrestore(&state->card->lock, flags);
2075 /* Set S/PDIF transmitter rate. */
2076 i_scr = inl(state->card->iobase + ALI_SCR);
2077 if ((i_scr & 0x00300000) == 0x00100000) {
2078 ali_set_spdif_output(state, AC97_EA_SPSA_7_8, codec_independent_spdif_locked);
2079 } else {
2080 if ((i_scr&0x00300000) == 0x00200000)
2081 {
2082 ali_set_spdif_output(state, AC97_EA_SPSA_6_9, codec_independent_spdif_locked);
2083 } else {
2084 if ((i_scr & 0x00300000) == 0x00300000) {
2085 ali_set_spdif_output(state, AC97_EA_SPSA_10_11, codec_independent_spdif_locked);
2086 } else {
2087 ali_set_spdif_output(state, AC97_EA_SPSA_7_8, codec_independent_spdif_locked);
2088 }
2089 }
2090 }
2091
2092 if (!(state->card->ac97_status & SPDIF_ON)) {
2093 val = dmabuf->rate;
2094 }
2095 } else {
2096 if (controller_independent_spdif_locked > 0)
2097 {
2098 stop_spdifout(state);
2099 dmabuf->ready = 0;
2100 spin_lock_irqsave(&state->card->lock, flags);
2101 ali_set_spdifout_rate(state, controller_independent_spdif_locked);
2102 spin_unlock_irqrestore(&state->card->lock, flags);
2103 } else {
2104 /* Set DAC rate */
2105 ali_set_spdif_output(state, -1, 0);
2106 stop_dac(state);
2107 dmabuf->ready = 0;
2108 spin_lock_irqsave(&state->card->lock, flags);
2109 ali_set_dac_rate(state, val);
2110 spin_unlock_irqrestore(&state->card->lock, flags);
2111 /* Set S/PDIF transmitter rate. */
2112 ali_set_spdif_output(state, AC97_EA_SPSA_3_4, val);
2113 if (!(state->card->ac97_status & SPDIF_ON))
2114 {
2115 val = dmabuf->rate;
2116 }
2117 }
2118 }
2119 } else { /* Not a valid rate for S/PDIF, ignore it */
2120 val = dmabuf->rate;
2121 }
2122 } else {
2123 stop_dac(state);
2124 dmabuf->ready = 0;
2125 spin_lock_irqsave(&state->card->lock, flags);
2126 ali_set_dac_rate(state, val);
2127 spin_unlock_irqrestore(&state->card->lock, flags);
2128 }
2129 }
2130 if (file->f_mode & FMODE_READ) {
2131 stop_adc(state);
2132 dmabuf->ready = 0;
2133 spin_lock_irqsave(&state->card->lock, flags);
2134 ali_set_adc_rate(state, val);
2135 spin_unlock_irqrestore(&state->card->lock, flags);
2136 }
2137 }
2138 return put_user(dmabuf->rate, p);
2139 case SNDCTL_DSP_STEREO: /* set stereo or mono channel */
2140#ifdef DEBUG
2141 printk("SNDCTL_DSP_STEREO\n");
2142#endif
2143 if (dmabuf->enable & DAC_RUNNING) {
2144 stop_dac(state);
2145 }
2146 if (dmabuf->enable & ADC_RUNNING) {
2147 stop_adc(state);
2148 }
2149 if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING) {
2150 stop_spdifout(state);
2151 }
2152 if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING) {
2153 stop_spdifout(state);
2154 }
2155 return put_user(1, p);
2156 case SNDCTL_DSP_GETBLKSIZE:
2157 if (file->f_mode & FMODE_WRITE) {
2158 if (codec_independent_spdif_locked > 0) {
2159 if (!dmabuf->ready && (val = prog_dmabuf(state, 2)))
2160 return val;
2161 } else {
2162 if (controller_independent_spdif_locked > 0) {
2163 if (!dmabuf->ready && (val = prog_dmabuf(state, 3)))
2164 return val;
2165 } else {
2166 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)))
2167 return val;
2168 }
2169 }
2170 }
2171
2172 if (file->f_mode & FMODE_READ) {
2173 if (!dmabuf->ready && (val = prog_dmabuf(state, 1)))
2174 return val;
2175 }
2176#ifdef DEBUG
2177 printk("SNDCTL_DSP_GETBLKSIZE %d\n", dmabuf->userfragsize);
2178#endif
2179 return put_user(dmabuf->userfragsize, p);
2180 case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format */
2181#ifdef DEBUG
2182 printk("SNDCTL_DSP_GETFMTS\n");
2183#endif
2184 return put_user(AFMT_S16_LE, p);
2185 case SNDCTL_DSP_SETFMT: /* Select sample format */
2186#ifdef DEBUG
2187 printk("SNDCTL_DSP_SETFMT\n");
2188#endif
2189 return put_user(AFMT_S16_LE, p);
2190 case SNDCTL_DSP_CHANNELS: // add support 4,6 channel
2191#ifdef DEBUG
2192 printk("SNDCTL_DSP_CHANNELS\n");
2193#endif
2194 if (get_user(val, p))
2195 return -EFAULT;
2196 if (val > 0) {
2197 if (dmabuf->enable & DAC_RUNNING) {
2198 stop_dac(state);
2199 }
2200 if (dmabuf->enable & CODEC_SPDIFOUT_RUNNING) {
2201 stop_spdifout(state);
2202 }
2203 if (dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING) {
2204 stop_spdifout(state);
2205 }
2206 if (dmabuf->enable & ADC_RUNNING) {
2207 stop_adc(state);
2208 }
2209 } else {
2210 return put_user(state->card->channels, p);
2211 }
2212
2213 i_scr = inl(state->card->iobase + ALI_SCR);
2214 /* Current # of channels enabled */
2215 if (i_scr & 0x00000100)
2216 ret = 4;
2217 else if (i_scr & 0x00000200)
2218 ret = 6;
2219 else
2220 ret = 2;
2221 switch (val) {
2222 case 2: /* 2 channels is always supported */
2223 if (codec_independent_spdif_locked > 0) {
2224 outl(((i_scr & 0xfffffcff) | 0x00100000), (state->card->iobase + ALI_SCR));
2225 } else
2226 outl((i_scr & 0xfffffcff), (state->card->iobase + ALI_SCR));
2227 /* Do we need to change mixer settings???? */
2228 break;
2229 case 4: /* Supported on some chipsets, better check first */
2230 if (codec_independent_spdif_locked > 0) {
2231 outl(((i_scr & 0xfffffcff) | 0x00000100 | 0x00200000), (state->card->iobase + ALI_SCR));
2232 } else
2233 outl(((i_scr & 0xfffffcff) | 0x00000100), (state->card->iobase + ALI_SCR));
2234 break;
2235 case 6: /* Supported on some chipsets, better check first */
2236 if (codec_independent_spdif_locked > 0) {
2237 outl(((i_scr & 0xfffffcff) | 0x00000200 | 0x00008000 | 0x00300000), (state->card->iobase + ALI_SCR));
2238 } else
2239 outl(((i_scr & 0xfffffcff) | 0x00000200 | 0x00008000), (state->card->iobase + ALI_SCR));
2240 break;
2241 default: /* nothing else is ever supported by the chipset */
2242 val = ret;
2243 break;
2244 }
2245 return put_user(val, p);
2246 case SNDCTL_DSP_POST: /* the user has sent all data and is notifying us */
2247 /* we update the swptr to the end of the last sg segment then return */
2248#ifdef DEBUG
2249 printk("SNDCTL_DSP_POST\n");
2250#endif
2251 if (codec_independent_spdif_locked > 0) {
2252 if (!dmabuf->ready || (dmabuf->enable != CODEC_SPDIFOUT_RUNNING))
2253 return 0;
2254 } else {
2255 if (controller_independent_spdif_locked > 0) {
2256 if (!dmabuf->ready || (dmabuf->enable != CONTROLLER_SPDIFOUT_RUNNING))
2257 return 0;
2258 } else {
2259 if (!dmabuf->ready || (dmabuf->enable != DAC_RUNNING))
2260 return 0;
2261 }
2262 }
2263 if ((dmabuf->swptr % dmabuf->fragsize) != 0) {
2264 val = dmabuf->fragsize - (dmabuf->swptr % dmabuf->fragsize);
2265 dmabuf->swptr += val;
2266 dmabuf->count += val;
2267 }
2268 return 0;
2269 case SNDCTL_DSP_SUBDIVIDE:
2270 if (dmabuf->subdivision)
2271 return -EINVAL;
2272 if (get_user(val, p))
2273 return -EFAULT;
2274 if (val != 1 && val != 2 && val != 4)
2275 return -EINVAL;
2276#ifdef DEBUG
2277 printk("SNDCTL_DSP_SUBDIVIDE %d\n", val);
2278#endif
2279 dmabuf->subdivision = val;
2280 dmabuf->ready = 0;
2281 return 0;
2282 case SNDCTL_DSP_SETFRAGMENT:
2283 if (get_user(val, p))
2284 return -EFAULT;
2285 dmabuf->ossfragsize = 1 << (val & 0xffff);
2286 dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
2287 if (!dmabuf->ossfragsize || !dmabuf->ossmaxfrags)
2288 return -EINVAL;
2289 /*
2290 * Bound the frag size into our allowed range of 256 - 4096
2291 */
2292 if (dmabuf->ossfragsize < 256)
2293 dmabuf->ossfragsize = 256;
2294 else if (dmabuf->ossfragsize > 4096)
2295 dmabuf->ossfragsize = 4096;
2296 /*
2297 * The numfrags could be something reasonable, or it could
2298 * be 0xffff meaning "Give me as much as possible". So,
2299 * we check the numfrags * fragsize doesn't exceed our
2300 * 64k buffer limit, nor is it less than our 8k minimum.
2301 * If it fails either one of these checks, then adjust the
2302 * number of fragments, not the size of them. It's OK if
2303 * our number of fragments doesn't equal 32 or anything
2304 * like our hardware based number now since we are using
2305 * a different frag count for the hardware. Before we get
2306 * into this though, bound the maxfrags to avoid overflow
2307 * issues. A reasonable bound would be 64k / 256 since our
2308 * maximum buffer size is 64k and our minimum frag size is
2309 * 256. On the other end, our minimum buffer size is 8k and
2310 * our maximum frag size is 4k, so the lower bound should
2311 * be 2.
2312 */
2313 if (dmabuf->ossmaxfrags > 256)
2314 dmabuf->ossmaxfrags = 256;
2315 else if (dmabuf->ossmaxfrags < 2)
2316 dmabuf->ossmaxfrags = 2;
2317 val = dmabuf->ossfragsize * dmabuf->ossmaxfrags;
2318 while (val < 8192) {
2319 val <<= 1;
2320 dmabuf->ossmaxfrags <<= 1;
2321 }
2322 while (val > 65536) {
2323 val >>= 1;
2324 dmabuf->ossmaxfrags >>= 1;
2325 }
2326 dmabuf->ready = 0;
2327#ifdef DEBUG
2328 printk("SNDCTL_DSP_SETFRAGMENT 0x%x, %d, %d\n", val,
2329 dmabuf->ossfragsize, dmabuf->ossmaxfrags);
2330#endif
2331 return 0;
2332 case SNDCTL_DSP_GETOSPACE:
2333 if (!(file->f_mode & FMODE_WRITE))
2334 return -EINVAL;
2335 if (codec_independent_spdif_locked > 0) {
2336 if (!dmabuf->ready && (val = prog_dmabuf(state, 2)) != 0)
2337 return val;
2338 } else {
2339 if (controller_independent_spdif_locked > 0) {
2340 if (!dmabuf->ready && (val = prog_dmabuf(state, 3)) != 0)
2341 return val;
2342 } else {
2343 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
2344 return val;
2345 }
2346 }
2347 spin_lock_irqsave(&state->card->lock, flags);
2348 ali_update_ptr(state);
2349 abinfo.fragsize = dmabuf->userfragsize;
2350 abinfo.fragstotal = dmabuf->userfrags;
2351 if (dmabuf->mapped)
2352 abinfo.bytes = dmabuf->dmasize;
2353 else
2354 abinfo.bytes = ali_get_free_write_space(state);
2355 abinfo.fragments = abinfo.bytes / dmabuf->userfragsize;
2356 spin_unlock_irqrestore(&state->card->lock, flags);
2357#if defined(DEBUG) || defined(DEBUG_MMAP)
2358 printk("SNDCTL_DSP_GETOSPACE %d, %d, %d, %d\n",
2359 abinfo.bytes, abinfo.fragsize, abinfo.fragments,
2360 abinfo.fragstotal);
2361#endif
2362 return copy_to_user(argp, &abinfo,
2363 sizeof(abinfo)) ? -EFAULT : 0;
2364 case SNDCTL_DSP_GETOPTR:
2365 if (!(file->f_mode & FMODE_WRITE))
2366 return -EINVAL;
2367 if (codec_independent_spdif_locked > 0) {
2368 if (!dmabuf->ready && (val = prog_dmabuf(state, 2)) != 0)
2369 return val;
2370 } else {
2371 if (controller_independent_spdif_locked > 0) {
2372 if (!dmabuf->ready && (val = prog_dmabuf(state, 3)) != 0)
2373 return val;
2374 } else {
2375 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
2376 return val;
2377 }
2378 }
2379 spin_lock_irqsave(&state->card->lock, flags);
2380 val = ali_get_free_write_space(state);
2381 cinfo.bytes = dmabuf->total_bytes;
2382 cinfo.ptr = dmabuf->hwptr;
2383 cinfo.blocks = val / dmabuf->userfragsize;
2384 if (codec_independent_spdif_locked > 0) {
2385 if (dmabuf->mapped && (dmabuf->trigger & SPDIF_ENABLE_OUTPUT)) {
2386 dmabuf->count += val;
2387 dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
2388 __ali_update_lvi(state, 2);
2389 }
2390 } else {
2391 if (controller_independent_spdif_locked > 0) {
2392 if (dmabuf->mapped && (dmabuf->trigger & SPDIF_ENABLE_OUTPUT)) {
2393 dmabuf->count += val;
2394 dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
2395 __ali_update_lvi(state, 3);
2396 }
2397 } else {
2398 if (dmabuf->mapped && (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
2399 dmabuf->count += val;
2400 dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
2401 __ali_update_lvi(state, 0);
2402 }
2403 }
2404 }
2405 spin_unlock_irqrestore(&state->card->lock, flags);
2406#if defined(DEBUG) || defined(DEBUG_MMAP)
2407 printk("SNDCTL_DSP_GETOPTR %d, %d, %d, %d\n", cinfo.bytes,
2408 cinfo.blocks, cinfo.ptr, dmabuf->count);
2409#endif
2410 return copy_to_user(argp, &cinfo, sizeof(cinfo))? -EFAULT : 0;
2411 case SNDCTL_DSP_GETISPACE:
2412 if (!(file->f_mode & FMODE_READ))
2413 return -EINVAL;
2414 if (!dmabuf->ready && (val = prog_dmabuf(state, 1)) != 0)
2415 return val;
2416 spin_lock_irqsave(&state->card->lock, flags);
2417 abinfo.bytes = ali_get_available_read_data(state);
2418 abinfo.fragsize = dmabuf->userfragsize;
2419 abinfo.fragstotal = dmabuf->userfrags;
2420 abinfo.fragments = abinfo.bytes / dmabuf->userfragsize;
2421 spin_unlock_irqrestore(&state->card->lock, flags);
2422#if defined(DEBUG) || defined(DEBUG_MMAP)
2423 printk("SNDCTL_DSP_GETISPACE %d, %d, %d, %d\n",
2424 abinfo.bytes, abinfo.fragsize, abinfo.fragments,
2425 abinfo.fragstotal);
2426#endif
2427 return copy_to_user(argp, &abinfo,
2428 sizeof(abinfo)) ? -EFAULT : 0;
2429 case SNDCTL_DSP_GETIPTR:
2430 if (!(file->f_mode & FMODE_READ))
2431 return -EINVAL;
2432 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
2433 return val;
2434 spin_lock_irqsave(&state->card->lock, flags);
2435 val = ali_get_available_read_data(state);
2436 cinfo.bytes = dmabuf->total_bytes;
2437 cinfo.blocks = val / dmabuf->userfragsize;
2438 cinfo.ptr = dmabuf->hwptr;
2439 if (dmabuf->mapped && (dmabuf->trigger & PCM_ENABLE_INPUT)) {
2440 dmabuf->count -= val;
2441 dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
2442 __ali_update_lvi(state, 1);
2443 }
2444 spin_unlock_irqrestore(&state->card->lock, flags);
2445#if defined(DEBUG) || defined(DEBUG_MMAP)
2446 printk("SNDCTL_DSP_GETIPTR %d, %d, %d, %d\n", cinfo.bytes,
2447 cinfo.blocks, cinfo.ptr, dmabuf->count);
2448#endif
2449 return copy_to_user(argp, &cinfo, sizeof(cinfo))? -EFAULT: 0;
2450 case SNDCTL_DSP_NONBLOCK:
2451#ifdef DEBUG
2452 printk("SNDCTL_DSP_NONBLOCK\n");
2453#endif
2454 file->f_flags |= O_NONBLOCK;
2455 return 0;
2456 case SNDCTL_DSP_GETCAPS:
2457#ifdef DEBUG
2458 printk("SNDCTL_DSP_GETCAPS\n");
2459#endif
2460 return put_user(DSP_CAP_REALTIME | DSP_CAP_TRIGGER |
2461 DSP_CAP_MMAP | DSP_CAP_BIND, p);
2462 case SNDCTL_DSP_GETTRIGGER:
2463 val = 0;
2464#ifdef DEBUG
2465 printk("SNDCTL_DSP_GETTRIGGER 0x%x\n", dmabuf->trigger);
2466#endif
2467 return put_user(dmabuf->trigger, p);
2468 case SNDCTL_DSP_SETTRIGGER:
2469 if (get_user(val, p))
2470 return -EFAULT;
2471#if defined(DEBUG) || defined(DEBUG_MMAP)
2472 printk("SNDCTL_DSP_SETTRIGGER 0x%x\n", val);
2473#endif
2474 if (!(val & PCM_ENABLE_INPUT) && dmabuf->enable == ADC_RUNNING) {
2475 stop_adc(state);
2476 }
2477 if (!(val & PCM_ENABLE_OUTPUT) && dmabuf->enable == DAC_RUNNING) {
2478 stop_dac(state);
2479 }
2480 if (!(val & SPDIF_ENABLE_OUTPUT) && dmabuf->enable == CODEC_SPDIFOUT_RUNNING) {
2481 stop_spdifout(state);
2482 }
2483 if (!(val & SPDIF_ENABLE_OUTPUT) && dmabuf->enable == CONTROLLER_SPDIFOUT_RUNNING) {
2484 stop_spdifout(state);
2485 }
2486 dmabuf->trigger = val;
2487 if (val & PCM_ENABLE_OUTPUT && !(dmabuf->enable & DAC_RUNNING)) {
2488 if (!dmabuf->write_channel) {
2489 dmabuf->ready = 0;
2490 dmabuf->write_channel = state->card->alloc_pcm_channel(state->card);
2491 if (!dmabuf->write_channel)
2492 return -EBUSY;
2493 }
2494 if (!dmabuf->ready && (ret = prog_dmabuf(state, 0)))
2495 return ret;
2496 if (dmabuf->mapped) {
2497 spin_lock_irqsave(&state->card->lock, flags);
2498 ali_update_ptr(state);
2499 dmabuf->count = 0;
2500 dmabuf->swptr = dmabuf->hwptr;
2501 dmabuf->count = ali_get_free_write_space(state);
2502 dmabuf->swptr = (dmabuf->swptr + dmabuf->count) % dmabuf->dmasize;
2503 __ali_update_lvi(state, 0);
2504 spin_unlock_irqrestore(&state->card->lock,
2505 flags);
2506 } else
2507 start_dac(state);
2508 }
2509 if (val & SPDIF_ENABLE_OUTPUT && !(dmabuf->enable & CODEC_SPDIFOUT_RUNNING)) {
2510 if (!dmabuf->codec_spdifout_channel) {
2511 dmabuf->ready = 0;
2512 dmabuf->codec_spdifout_channel = state->card->alloc_codec_spdifout_channel(state->card);
2513 if (!dmabuf->codec_spdifout_channel)
2514 return -EBUSY;
2515 }
2516 if (!dmabuf->ready && (ret = prog_dmabuf(state, 2)))
2517 return ret;
2518 if (dmabuf->mapped) {
2519 spin_lock_irqsave(&state->card->lock, flags);
2520 ali_update_ptr(state);
2521 dmabuf->count = 0;
2522 dmabuf->swptr = dmabuf->hwptr;
2523 dmabuf->count = ali_get_free_write_space(state);
2524 dmabuf->swptr = (dmabuf->swptr + dmabuf->count) % dmabuf->dmasize;
2525 __ali_update_lvi(state, 2);
2526 spin_unlock_irqrestore(&state->card->lock,
2527 flags);
2528 } else
2529 start_spdifout(state);
2530 }
2531 if (val & SPDIF_ENABLE_OUTPUT && !(dmabuf->enable & CONTROLLER_SPDIFOUT_RUNNING)) {
2532 if (!dmabuf->controller_spdifout_channel) {
2533 dmabuf->ready = 0;
2534 dmabuf->controller_spdifout_channel = state->card->alloc_controller_spdifout_channel(state->card);
2535 if (!dmabuf->controller_spdifout_channel)
2536 return -EBUSY;
2537 }
2538 if (!dmabuf->ready && (ret = prog_dmabuf(state, 3)))
2539 return ret;
2540 if (dmabuf->mapped) {
2541 spin_lock_irqsave(&state->card->lock, flags);
2542 ali_update_ptr(state);
2543 dmabuf->count = 0;
2544 dmabuf->swptr = dmabuf->hwptr;
2545 dmabuf->count = ali_get_free_write_space(state);
2546 dmabuf->swptr = (dmabuf->swptr + dmabuf->count) % dmabuf->dmasize;
2547 __ali_update_lvi(state, 3);
2548 spin_unlock_irqrestore(&state->card->lock, flags);
2549 } else
2550 start_spdifout(state);
2551 }
2552 if (val & PCM_ENABLE_INPUT && !(dmabuf->enable & ADC_RUNNING)) {
2553 if (!dmabuf->read_channel) {
2554 dmabuf->ready = 0;
2555 dmabuf->read_channel = state->card->alloc_rec_pcm_channel(state->card);
2556 if (!dmabuf->read_channel)
2557 return -EBUSY;
2558 }
2559 if (!dmabuf->ready && (ret = prog_dmabuf(state, 1)))
2560 return ret;
2561 if (dmabuf->mapped) {
2562 spin_lock_irqsave(&state->card->lock,
2563 flags);
2564 ali_update_ptr(state);
2565 dmabuf->swptr = dmabuf->hwptr;
2566 dmabuf->count = 0;
2567 spin_unlock_irqrestore(&state->card->lock, flags);
2568 }
2569 ali_update_lvi(state, 1);
2570 start_adc(state);
2571 }
2572 return 0;
2573 case SNDCTL_DSP_SETDUPLEX:
2574#ifdef DEBUG
2575 printk("SNDCTL_DSP_SETDUPLEX\n");
2576#endif
2577 return -EINVAL;
2578 case SNDCTL_DSP_GETODELAY:
2579 if (!(file->f_mode & FMODE_WRITE))
2580 return -EINVAL;
2581 spin_lock_irqsave(&state->card->lock, flags);
2582 ali_update_ptr(state);
2583 val = dmabuf->count;
2584 spin_unlock_irqrestore(&state->card->lock, flags);
2585#ifdef DEBUG
2586 printk("SNDCTL_DSP_GETODELAY %d\n", dmabuf->count);
2587#endif
2588 return put_user(val, p);
2589 case SOUND_PCM_READ_RATE:
2590#ifdef DEBUG
2591 printk("SOUND_PCM_READ_RATE %d\n", dmabuf->rate);
2592#endif
2593 return put_user(dmabuf->rate, p);
2594 case SOUND_PCM_READ_CHANNELS:
2595#ifdef DEBUG
2596 printk("SOUND_PCM_READ_CHANNELS\n");
2597#endif
2598 return put_user(2, p);
2599 case SOUND_PCM_READ_BITS:
2600#ifdef DEBUG
2601 printk("SOUND_PCM_READ_BITS\n");
2602#endif
2603 return put_user(AFMT_S16_LE, p);
2604 case SNDCTL_DSP_SETSPDIF: /* Set S/PDIF Control register */
2605#ifdef DEBUG
2606 printk("SNDCTL_DSP_SETSPDIF\n");
2607#endif
2608 if (get_user(val, p))
2609 return -EFAULT;
2610 /* Check to make sure the codec supports S/PDIF transmitter */
2611 if ((state->card->ac97_features & 4)) {
2612 /* mask out the transmitter speed bits so the user can't set them */
2613 val &= ~0x3000;
2614 /* Add the current transmitter speed bits to the passed value */
2615 ret = ali_ac97_get(codec, AC97_SPDIF_CONTROL);
2616 val |= (ret & 0x3000);
2617 ali_ac97_set(codec, AC97_SPDIF_CONTROL, val);
2618 if (ali_ac97_get(codec, AC97_SPDIF_CONTROL) != val) {
2619 printk(KERN_ERR "ali_audio: Unable to set S/PDIF configuration to 0x%04x.\n", val);
2620 return -EFAULT;
2621 }
2622 }
2623#ifdef DEBUG
2624 else
2625 printk(KERN_WARNING "ali_audio: S/PDIF transmitter not avalible.\n");
2626#endif
2627 return put_user(val, p);
2628 case SNDCTL_DSP_GETSPDIF: /* Get S/PDIF Control register */
2629#ifdef DEBUG
2630 printk("SNDCTL_DSP_GETSPDIF\n");
2631#endif
2632 if (get_user(val, p))
2633 return -EFAULT;
2634 /* Check to make sure the codec supports S/PDIF transmitter */
2635 if (!(state->card->ac97_features & 4)) {
2636#ifdef DEBUG
2637 printk(KERN_WARNING "ali_audio: S/PDIF transmitter not avalible.\n");
2638#endif
2639 val = 0;
2640 } else {
2641 val = ali_ac97_get(codec, AC97_SPDIF_CONTROL);
2642 }
2643
2644 return put_user(val, p);
2645//end add support spdif out
2646//add support 4,6 channel
2647 case SNDCTL_DSP_GETCHANNELMASK:
2648#ifdef DEBUG
2649 printk("SNDCTL_DSP_GETCHANNELMASK\n");
2650#endif
2651 if (get_user(val, p))
2652 return -EFAULT;
2653 /* Based on AC'97 DAC support, not ICH hardware */
2654 val = DSP_BIND_FRONT;
2655 if (state->card->ac97_features & 0x0004)
2656 val |= DSP_BIND_SPDIF;
2657 if (state->card->ac97_features & 0x0080)
2658 val |= DSP_BIND_SURR;
2659 if (state->card->ac97_features & 0x0140)
2660 val |= DSP_BIND_CENTER_LFE;
2661 return put_user(val, p);
2662 case SNDCTL_DSP_BIND_CHANNEL:
2663#ifdef DEBUG
2664 printk("SNDCTL_DSP_BIND_CHANNEL\n");
2665#endif
2666 if (get_user(val, p))
2667 return -EFAULT;
2668 if (val == DSP_BIND_QUERY) {
2669 val = DSP_BIND_FRONT; /* Always report this as being enabled */
2670 if (state->card->ac97_status & SPDIF_ON)
2671 val |= DSP_BIND_SPDIF;
2672 else {
2673 if (state->card->ac97_status & SURR_ON)
2674 val |= DSP_BIND_SURR;
2675 if (state->card->
2676 ac97_status & CENTER_LFE_ON)
2677 val |= DSP_BIND_CENTER_LFE;
2678 }
2679 } else { /* Not a query, set it */
2680 if (!(file->f_mode & FMODE_WRITE))
2681 return -EINVAL;
2682 if (dmabuf->enable == DAC_RUNNING) {
2683 stop_dac(state);
2684 }
2685 if (val & DSP_BIND_SPDIF) { /* Turn on SPDIF */
2686 /* Ok, this should probably define what slots
2687 * to use. For now, we'll only set it to the
2688 * defaults:
2689 *
2690 * non multichannel codec maps to slots 3&4
2691 * 2 channel codec maps to slots 7&8
2692 * 4 channel codec maps to slots 6&9
2693 * 6 channel codec maps to slots 10&11
2694 *
2695 * there should be some way for the app to
2696 * select the slot assignment.
2697 */
2698 i_scr = inl(state->card->iobase + ALI_SCR);
2699 if (codec_independent_spdif_locked > 0) {
2700
2701 if ((i_scr & 0x00300000) == 0x00100000) {
2702 ali_set_spdif_output(state, AC97_EA_SPSA_7_8, codec_independent_spdif_locked);
2703 } else {
2704 if ((i_scr & 0x00300000) == 0x00200000) {
2705 ali_set_spdif_output(state, AC97_EA_SPSA_6_9, codec_independent_spdif_locked);
2706 } else {
2707 if ((i_scr & 0x00300000) == 0x00300000) {
2708 ali_set_spdif_output(state, AC97_EA_SPSA_10_11, codec_independent_spdif_locked);
2709 }
2710 }
2711 }
2712 } else { /* codec spdif out (pcm out share ) */
2713 ali_set_spdif_output(state, AC97_EA_SPSA_3_4, dmabuf->rate); //I do not modify
2714 }
2715
2716 if (!(state->card->ac97_status & SPDIF_ON))
2717 val &= ~DSP_BIND_SPDIF;
2718 } else {
2719 int mask;
2720 int channels;
2721 /* Turn off S/PDIF if it was on */
2722 if (state->card->ac97_status & SPDIF_ON)
2723 ali_set_spdif_output(state, -1, 0);
2724 mask =
2725 val & (DSP_BIND_FRONT | DSP_BIND_SURR |
2726 DSP_BIND_CENTER_LFE);
2727 switch (mask) {
2728 case DSP_BIND_FRONT:
2729 channels = 2;
2730 break;
2731 case DSP_BIND_FRONT | DSP_BIND_SURR:
2732 channels = 4;
2733 break;
2734 case DSP_BIND_FRONT | DSP_BIND_SURR | DSP_BIND_CENTER_LFE:
2735 channels = 6;
2736 break;
2737 default:
2738 val = DSP_BIND_FRONT;
2739 channels = 2;
2740 break;
2741 }
2742 ali_set_dac_channels(state, channels);
2743 /* check that they really got turned on */
2744 if (!state->card->ac97_status & SURR_ON)
2745 val &= ~DSP_BIND_SURR;
2746 if (!state->card->
2747 ac97_status & CENTER_LFE_ON)
2748 val &= ~DSP_BIND_CENTER_LFE;
2749 }
2750 }
2751 return put_user(val, p);
2752 case SNDCTL_DSP_MAPINBUF:
2753 case SNDCTL_DSP_MAPOUTBUF:
2754 case SNDCTL_DSP_SETSYNCRO:
2755 case SOUND_PCM_WRITE_FILTER:
2756 case SOUND_PCM_READ_FILTER:
2757 return -EINVAL;
2758 }
2759 return -EINVAL;
2760}
2761
2762static int ali_open(struct inode *inode, struct file *file)
2763{
2764 int i = 0;
2765 struct ali_card *card = devs;
2766 struct ali_state *state = NULL;
2767 struct dmabuf *dmabuf = NULL;
2768 unsigned int i_scr;
2769
2770 /* find an available virtual channel (instance of /dev/dsp) */
2771
2772 while (card != NULL) {
2773
2774 /*
2775 * If we are initializing and then fail, card could go
2776 * away unuexpectedly while we are in the for() loop.
2777 * So, check for card on each iteration before we check
2778 * for card->initializing to avoid a possible oops.
2779 * This usually only matters for times when the driver is
2780 * autoloaded by kmod.
2781 */
2782 for (i = 0; i < 50 && card && card->initializing; i++) {
2783 set_current_state(TASK_UNINTERRUPTIBLE);
2784 schedule_timeout(HZ / 20);
2785 }
2786
2787 for (i = 0; i < NR_HW_CH && card && !card->initializing; i++) {
2788 if (card->states[i] == NULL) {
2789 state = card->states[i] = (struct ali_state *) kmalloc(sizeof(struct ali_state), GFP_KERNEL);
2790 if (state == NULL)
2791 return -ENOMEM;
2792 memset(state, 0, sizeof(struct ali_state));
2793 dmabuf = &state->dmabuf;
2794 goto found_virt;
2795 }
2796 }
2797 card = card->next;
2798 }
2799
2800 /* no more virtual channel avaiable */
2801 if (!state)
2802 return -ENODEV;
2803found_virt:
2804 /* initialize the virtual channel */
2805
2806 state->virt = i;
2807 state->card = card;
2808 state->magic = ALI5455_STATE_MAGIC;
2809 init_waitqueue_head(&dmabuf->wait);
2810 init_MUTEX(&state->open_sem);
2811 file->private_data = state;
2812 dmabuf->trigger = 0;
2813 /* allocate hardware channels */
2814 if (file->f_mode & FMODE_READ) {
2815 if ((dmabuf->read_channel =
2816 card->alloc_rec_pcm_channel(card)) == NULL) {
2817 kfree(card->states[i]);
2818 card->states[i] = NULL;
2819 return -EBUSY;
2820 }
2821 dmabuf->trigger |= PCM_ENABLE_INPUT;
2822 ali_set_adc_rate(state, 8000);
2823 }
2824 if (file->f_mode & FMODE_WRITE) {
2825 if (codec_independent_spdif_locked > 0) {
2826 if ((dmabuf->codec_spdifout_channel = card->alloc_codec_spdifout_channel(card)) == NULL) {
2827 kfree(card->states[i]);
2828 card->states[i] = NULL;
2829 return -EBUSY;
2830 }
2831 dmabuf->trigger |= SPDIF_ENABLE_OUTPUT;
2832 ali_set_codecspdifout_rate(state, codec_independent_spdif_locked); //It must add
2833 i_scr = inl(state->card->iobase + ALI_SCR);
2834 if ((i_scr & 0x00300000) == 0x00100000) {
2835 ali_set_spdif_output(state, AC97_EA_SPSA_7_8, codec_independent_spdif_locked);
2836 } else {
2837 if ((i_scr & 0x00300000) == 0x00200000) {
2838 ali_set_spdif_output(state, AC97_EA_SPSA_6_9, codec_independent_spdif_locked);
2839 } else {
2840 if ((i_scr & 0x00300000) == 0x00300000) {
2841 ali_set_spdif_output(state, AC97_EA_SPSA_10_11, codec_independent_spdif_locked);
2842 } else {
2843 ali_set_spdif_output(state, AC97_EA_SPSA_7_8, codec_independent_spdif_locked);
2844 }
2845 }
2846
2847 }
2848 } else {
2849 if (controller_independent_spdif_locked > 0) {
2850 if ((dmabuf->controller_spdifout_channel = card->alloc_controller_spdifout_channel(card)) == NULL) {
2851 kfree(card->states[i]);
2852 card->states[i] = NULL;
2853 return -EBUSY;
2854 }
2855 dmabuf->trigger |= SPDIF_ENABLE_OUTPUT;
2856 ali_set_spdifout_rate(state, controller_independent_spdif_locked);
2857 } else {
2858 if ((dmabuf->write_channel = card->alloc_pcm_channel(card)) == NULL) {
2859 kfree(card->states[i]);
2860 card->states[i] = NULL;
2861 return -EBUSY;
2862 }
2863 /* Initialize to 8kHz? What if we don't support 8kHz? */
2864 /* Let's change this to check for S/PDIF stuff */
2865
2866 dmabuf->trigger |= PCM_ENABLE_OUTPUT;
2867 if (codec_pcmout_share_spdif_locked) {
2868 ali_set_dac_rate(state, codec_pcmout_share_spdif_locked);
2869 ali_set_spdif_output(state, AC97_EA_SPSA_3_4, codec_pcmout_share_spdif_locked);
2870 } else {
2871 ali_set_dac_rate(state, 8000);
2872 }
2873 }
2874
2875 }
2876 }
2877
2878 /* set default sample format. According to OSS Programmer's Guide /dev/dsp
2879 should be default to unsigned 8-bits, mono, with sample rate 8kHz and
2880 /dev/dspW will accept 16-bits sample, but we don't support those so we
2881 set it immediately to stereo and 16bit, which is all we do support */
2882 dmabuf->fmt |= ALI5455_FMT_16BIT | ALI5455_FMT_STEREO;
2883 dmabuf->ossfragsize = 0;
2884 dmabuf->ossmaxfrags = 0;
2885 dmabuf->subdivision = 0;
2886 state->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2887 outl(0x00000000, card->iobase + ALI_INTERRUPTCR);
2888 outl(0x00000000, card->iobase + ALI_INTERRUPTSR);
2889 return nonseekable_open(inode, file);
2890}
2891
2892static int ali_release(struct inode *inode, struct file *file)
2893{
2894 struct ali_state *state = (struct ali_state *) file->private_data;
2895 struct ali_card *card = state->card;
2896 struct dmabuf *dmabuf = &state->dmabuf;
2897 unsigned long flags;
2898 lock_kernel();
2899
2900 /* stop DMA state machine and free DMA buffers/channels */
2901 if (dmabuf->trigger & PCM_ENABLE_OUTPUT)
2902 drain_dac(state, 0);
2903
2904 if (dmabuf->trigger & SPDIF_ENABLE_OUTPUT)
2905 drain_spdifout(state, 0);
2906
2907 if (dmabuf->trigger & PCM_ENABLE_INPUT)
2908 stop_adc(state);
2909
2910 spin_lock_irqsave(&card->lock, flags);
2911 dealloc_dmabuf(state);
2912 if (file->f_mode & FMODE_WRITE) {
2913 if (codec_independent_spdif_locked > 0) {
2914 state->card->free_pcm_channel(state->card, dmabuf->codec_spdifout_channel->num);
2915 } else {
2916 if (controller_independent_spdif_locked > 0)
2917 state->card->free_pcm_channel(state->card,
2918 dmabuf->controller_spdifout_channel->num);
2919 else state->card->free_pcm_channel(state->card,
2920 dmabuf->write_channel->num);
2921 }
2922 }
2923 if (file->f_mode & FMODE_READ)
2924 state->card->free_pcm_channel(state->card, dmabuf->read_channel->num);
2925
2926 state->card->states[state->virt] = NULL;
2927 kfree(state);
2928 spin_unlock_irqrestore(&card->lock, flags);
2929 unlock_kernel();
2930 return 0;
2931}
2932
2933static /*const */ struct file_operations ali_audio_fops = {
2934 .owner = THIS_MODULE,
2935 .llseek = no_llseek,
2936 .read = ali_read,
2937 .write = ali_write,
2938 .poll = ali_poll,
2939 .ioctl = ali_ioctl,
2940 .mmap = ali_mmap,
2941 .open = ali_open,
2942 .release = ali_release,
2943};
2944
2945/* Read AC97 codec registers */
2946static u16 ali_ac97_get(struct ac97_codec *dev, u8 reg)
2947{
2948 struct ali_card *card = dev->private_data;
2949 int count1 = 100;
2950 char val;
2951 unsigned short int data = 0, count, addr1, addr2 = 0;
2952
2953 spin_lock(&card->ac97_lock);
2954 while (count1-- && (inl(card->iobase + ALI_CAS) & 0x80000000))
2955 udelay(1);
2956
2957 addr1 = reg;
2958 reg |= 0x0080;
2959 for (count = 0; count < 0x7f; count++) {
2960 val = inb(card->iobase + ALI_CSPSR);
2961 if (val & 0x08)
2962 break;
2963 }
2964 if (count == 0x7f)
2965 {
2966 spin_unlock(&card->ac97_lock);
2967 return -1;
2968 }
2969 outw(reg, (card->iobase + ALI_CPR) + 2);
2970 for (count = 0; count < 0x7f; count++) {
2971 val = inb(card->iobase + ALI_CSPSR);
2972 if (val & 0x02) {
2973 data = inw(card->iobase + ALI_SPR);
2974 addr2 = inw((card->iobase + ALI_SPR) + 2);
2975 break;
2976 }
2977 }
2978 spin_unlock(&card->ac97_lock);
2979 if (count == 0x7f)
2980 return -1;
2981 if (addr2 != addr1)
2982 return -1;
2983 return ((u16) data);
2984}
2985
2986/* write ac97 codec register */
2987
2988static void ali_ac97_set(struct ac97_codec *dev, u8 reg, u16 data)
2989{
2990 struct ali_card *card = dev->private_data;
2991 int count1 = 100;
2992 char val;
2993 unsigned short int count;
2994
2995 spin_lock(&card->ac97_lock);
2996 while (count1-- && (inl(card->iobase + ALI_CAS) & 0x80000000))
2997 udelay(1);
2998
2999 for (count = 0; count < 0x7f; count++) {
3000 val = inb(card->iobase + ALI_CSPSR);
3001 if (val & 0x08)
3002 break;
3003 }
3004 if (count == 0x7f) {
3005 printk(KERN_WARNING "ali_ac97_set: AC97 codec register access timed out. \n");
3006 spin_unlock(&card->ac97_lock);
3007 return;
3008 }
3009 outw(data, (card->iobase + ALI_CPR));
3010 outb(reg, (card->iobase + ALI_CPR) + 2);
3011 for (count = 0; count < 0x7f; count++) {
3012 val = inb(card->iobase + ALI_CSPSR);
3013 if (val & 0x01)
3014 break;
3015 }
3016 spin_unlock(&card->ac97_lock);
3017 if (count == 0x7f)
3018 printk(KERN_WARNING "ali_ac97_set: AC97 codec register access timed out. \n");
3019 return;
3020}
3021
3022/* OSS /dev/mixer file operation methods */
3023
3024static int ali_open_mixdev(struct inode *inode, struct file *file)
3025{
3026 int i;
3027 int minor = iminor(inode);
3028 struct ali_card *card = devs;
3029 for (card = devs; card != NULL; card = card->next) {
3030 /*
3031 * If we are initializing and then fail, card could go
3032 * away unuexpectedly while we are in the for() loop.
3033 * So, check for card on each iteration before we check
3034 * for card->initializing to avoid a possible oops.
3035 * This usually only matters for times when the driver is
3036 * autoloaded by kmod.
3037 */
3038 for (i = 0; i < 50 && card && card->initializing; i++) {
3039 set_current_state(TASK_UNINTERRUPTIBLE);
3040 schedule_timeout(HZ / 20);
3041 }
3042 for (i = 0; i < NR_AC97 && card && !card->initializing; i++)
3043 if (card->ac97_codec[i] != NULL
3044 && card->ac97_codec[i]->dev_mixer == minor) {
3045 file->private_data = card->ac97_codec[i];
3046 return nonseekable_open(inode, file);
3047 }
3048 }
3049 return -ENODEV;
3050}
3051
3052static int ali_ioctl_mixdev(struct inode *inode,
3053 struct file *file,
3054 unsigned int cmd, unsigned long arg)
3055{
3056 struct ac97_codec *codec = (struct ac97_codec *) file->private_data;
3057 return codec->mixer_ioctl(codec, cmd, arg);
3058}
3059
3060static /*const */ struct file_operations ali_mixer_fops = {
3061 .owner = THIS_MODULE,
3062 .llseek = no_llseek,
3063 .ioctl = ali_ioctl_mixdev,
3064 .open = ali_open_mixdev,
3065};
3066
3067/* AC97 codec initialisation. These small functions exist so we don't
3068 duplicate code between module init and apm resume */
3069
3070static inline int ali_ac97_exists(struct ali_card *card, int ac97_number)
3071{
3072 unsigned int i = 1;
3073 u32 reg = inl(card->iobase + ALI_RTSR);
3074 if (ac97_number) {
3075 while (i < 100) {
3076
3077 reg = inl(card->iobase + ALI_RTSR);
3078 if (reg & 0x40) {
3079 break;
3080 } else {
3081 outl(reg | 0x00000040,
3082 card->iobase + 0x34);
3083 udelay(1);
3084 }
3085 i++;
3086 }
3087
3088 } else {
3089 while (i < 100) {
3090 reg = inl(card->iobase + ALI_RTSR);
3091 if (reg & 0x80) {
3092 break;
3093 } else {
3094 outl(reg | 0x00000080,
3095 card->iobase + 0x34);
3096 udelay(1);
3097 }
3098 i++;
3099 }
3100 }
3101
3102 if (ac97_number)
3103 return reg & 0x40;
3104 else
3105 return reg & 0x80;
3106}
3107
3108static inline int ali_ac97_enable_variable_rate(struct ac97_codec *codec)
3109{
3110 ali_ac97_set(codec, AC97_EXTENDED_STATUS, 9);
3111 ali_ac97_set(codec, AC97_EXTENDED_STATUS, ali_ac97_get(codec, AC97_EXTENDED_STATUS) | 0xE800);
3112 return (ali_ac97_get(codec, AC97_EXTENDED_STATUS) & 1);
3113}
3114
3115
3116static int ali_ac97_probe_and_powerup(struct ali_card *card, struct ac97_codec *codec)
3117{
3118 /* Returns 0 on failure */
3119 int i;
3120 u16 addr;
3121 if (ac97_probe_codec(codec) == 0)
3122 return 0;
3123 /* ac97_probe_codec is success ,then begin to init codec */
3124 ali_ac97_set(codec, AC97_RESET, 0xffff);
3125 if (card->channel[0].used == 1) {
3126 ali_ac97_set(codec, AC97_RECORD_SELECT, 0x0000);
3127 ali_ac97_set(codec, AC97_LINEIN_VOL, 0x0808);
3128 ali_ac97_set(codec, AC97_RECORD_GAIN, 0x0F0F);
3129 }
3130
3131 if (card->channel[2].used == 1) //if MICin then init codec
3132 {
3133 ali_ac97_set(codec, AC97_RECORD_SELECT, 0x0000);
3134 ali_ac97_set(codec, AC97_MIC_VOL, 0x8808);
3135 ali_ac97_set(codec, AC97_RECORD_GAIN, 0x0F0F);
3136 ali_ac97_set(codec, AC97_RECORD_GAIN_MIC, 0x0000);
3137 }
3138
3139 ali_ac97_set(codec, AC97_MASTER_VOL_STEREO, 0x0000);
3140 ali_ac97_set(codec, AC97_HEADPHONE_VOL, 0x0000);
3141 ali_ac97_set(codec, AC97_PCMOUT_VOL, 0x0000);
3142 ali_ac97_set(codec, AC97_CD_VOL, 0x0808);
3143 ali_ac97_set(codec, AC97_VIDEO_VOL, 0x0808);
3144 ali_ac97_set(codec, AC97_AUX_VOL, 0x0808);
3145 ali_ac97_set(codec, AC97_PHONE_VOL, 0x8048);
3146 ali_ac97_set(codec, AC97_PCBEEP_VOL, 0x0000);
3147 ali_ac97_set(codec, AC97_GENERAL_PURPOSE, AC97_GP_MIX);
3148 ali_ac97_set(codec, AC97_MASTER_VOL_MONO, 0x0000);
3149 ali_ac97_set(codec, 0x38, 0x0000);
3150 addr = ali_ac97_get(codec, 0x2a);
3151 ali_ac97_set(codec, 0x2a, addr | 0x0001);
3152 addr = ali_ac97_get(codec, 0x2a);
3153 addr = ali_ac97_get(codec, 0x28);
3154 ali_ac97_set(codec, 0x2c, 0xbb80);
3155 addr = ali_ac97_get(codec, 0x2c);
3156 /* power it all up */
3157 ali_ac97_set(codec, AC97_POWER_CONTROL,
3158 ali_ac97_get(codec, AC97_POWER_CONTROL) & ~0x7f00);
3159 /* wait for analog ready */
3160 for (i = 10; i && ((ali_ac97_get(codec, AC97_POWER_CONTROL) & 0xf) != 0xf); i--) {
3161 set_current_state(TASK_UNINTERRUPTIBLE);
3162 schedule_timeout(HZ / 20);
3163 }
3164 /* FIXME !! */
3165 i++;
3166 return i;
3167}
3168
3169
3170/* I clone ali5455(2.4.7 ) not clone i810_audio(2.4.18) */
3171
3172static int ali_reset_5455(struct ali_card *card)
3173{
3174 outl(0x80000003, card->iobase + ALI_SCR);
3175 outl(0x83838383, card->iobase + ALI_FIFOCR1);
3176 outl(0x83838383, card->iobase + ALI_FIFOCR2);
3177 if (controller_pcmout_share_spdif_locked > 0) {
3178 outl((inl(card->iobase + ALI_SPDIFICS) | 0x00000001),
3179 card->iobase + ALI_SPDIFICS);
3180 outl(0x0408000a, card->iobase + ALI_INTERFACECR);
3181 } else {
3182 if (codec_independent_spdif_locked > 0) {
3183 outl((inl(card->iobase + ALI_SCR) | 0x00100000), card->iobase + ALI_SCR); // now I select slot 7 & 8
3184 outl(0x00200000, card->iobase + ALI_INTERFACECR); //enable codec independent spdifout
3185 } else
3186 outl(0x04080002, card->iobase + ALI_INTERFACECR);
3187 }
3188
3189 outl(0x00000000, card->iobase + ALI_INTERRUPTCR);
3190 outl(0x00000000, card->iobase + ALI_INTERRUPTSR);
3191 if (controller_independent_spdif_locked > 0)
3192 outl((inl(card->iobase + ALI_SPDIFICS) | 0x00000001),
3193 card->iobase + ALI_SPDIFICS);
3194 return 1;
3195}
3196
3197
3198static int ali_ac97_random_init_stuff(struct ali_card
3199 *card)
3200{
3201 u32 reg = inl(card->iobase + ALI_SCR);
3202 int i = 0;
3203 reg = inl(card->iobase + ALI_SCR);
3204 if ((reg & 2) == 0) /* Cold required */
3205 reg |= 2;
3206 else
3207 reg |= 1; /* Warm */
3208 reg &= ~0x80000000; /* ACLink on */
3209 outl(reg, card->iobase + ALI_SCR);
3210
3211 while (i < 10) {
3212 if ((inl(card->iobase + 0x18) & (1 << 1)) == 0)
3213 break;
3214 current->state = TASK_UNINTERRUPTIBLE;
3215 schedule_timeout(HZ / 20);
3216 i++;
3217 }
3218 if (i == 10) {
3219 printk(KERN_ERR "ali_audio: AC'97 reset failed.\n");
3220 return 0;
3221 }
3222
3223 set_current_state(TASK_UNINTERRUPTIBLE);
3224 schedule_timeout(HZ / 2);
3225 return 1;
3226}
3227
3228/* AC97 codec initialisation. */
3229
3230static int __devinit ali_ac97_init(struct ali_card *card)
3231{
3232 int num_ac97 = 0;
3233 int total_channels = 0;
3234 struct ac97_codec *codec;
3235 u16 eid;
3236
3237 if (!ali_ac97_random_init_stuff(card))
3238 return 0;
3239
3240 /* Number of channels supported */
3241 /* What about the codec? Just because the ICH supports */
3242 /* multiple channels doesn't mean the codec does. */
3243 /* we'll have to modify this in the codec section below */
3244 /* to reflect what the codec has. */
3245 /* ICH and ICH0 only support 2 channels so don't bother */
3246 /* to check.... */
3247 inl(card->iobase + ALI_CPR);
3248 card->channels = 2;
3249
3250 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
3251
3252 /* Assume codec isn't available until we go through the
3253 * gauntlet below */
3254 card->ac97_codec[num_ac97] = NULL;
3255 /* The ICH programmer's reference says you should */
3256 /* check the ready status before probing. So we chk */
3257 /* What do we do if it's not ready? Wait and try */
3258 /* again, or abort? */
3259 if (!ali_ac97_exists(card, num_ac97)) {
3260 if (num_ac97 == 0)
3261 printk(KERN_ERR "ali_audio: Primary codec not ready.\n");
3262 break;
3263 }
3264
3265 if ((codec = ac97_alloc_codec()) == NULL)
3266 return -ENOMEM;
3267 /* initialize some basic codec information, other fields will be filled
3268 in ac97_probe_codec */
3269 codec->private_data = card;
3270 codec->id = num_ac97;
3271 codec->codec_read = ali_ac97_get;
3272 codec->codec_write = ali_ac97_set;
3273 if (!ali_ac97_probe_and_powerup(card, codec)) {
3274 printk(KERN_ERR "ali_audio: timed out waiting for codec %d analog ready",
3275 num_ac97);
3276 kfree(codec);
3277 break; /* it didn't work */
3278 }
3279
3280 /* Store state information about S/PDIF transmitter */
3281 card->ac97_status = 0;
3282 /* Don't attempt to get eid until powerup is complete */
3283 eid = ali_ac97_get(codec, AC97_EXTENDED_ID);
3284 if (eid == 0xFFFF) {
3285 printk(KERN_ERR "ali_audio: no codec attached ?\n");
3286 kfree(codec);
3287 break;
3288 }
3289
3290 card->ac97_features = eid;
3291 /* Now check the codec for useful features to make up for
3292 the dumbness of the ali5455 hardware engine */
3293 if (!(eid & 0x0001))
3294 printk(KERN_WARNING
3295 "ali_audio: only 48Khz playback available.\n");
3296 else {
3297 if (!ali_ac97_enable_variable_rate(codec)) {
3298 printk(KERN_WARNING
3299 "ali_audio: Codec refused to allow VRA, using 48Khz only.\n");
3300 card->ac97_features &= ~1;
3301 }
3302 }
3303
3304 /* Determine how many channels the codec(s) support */
3305 /* - The primary codec always supports 2 */
3306 /* - If the codec supports AMAP, surround DACs will */
3307 /* automaticlly get assigned to slots. */
3308 /* * Check for surround DACs and increment if */
3309 /* found. */
3310 /* - Else check if the codec is revision 2.2 */
3311 /* * If surround DACs exist, assign them to slots */
3312 /* and increment channel count. */
3313
3314 /* All of this only applies to ICH2 and above. ICH */
3315 /* and ICH0 only support 2 channels. ICH2 will only */
3316 /* support multiple codecs in a "split audio" config. */
3317 /* as described above. */
3318
3319 /* TODO: Remove all the debugging messages! */
3320
3321 if ((eid & 0xc000) == 0) /* primary codec */
3322 total_channels += 2;
3323 if ((codec->dev_mixer = register_sound_mixer(&ali_mixer_fops, -1)) < 0) {
3324 printk(KERN_ERR "ali_audio: couldn't register mixer!\n");
3325 kfree(codec);
3326 break;
3327 }
3328 card->ac97_codec[num_ac97] = codec;
3329 }
3330 /* pick the minimum of channels supported by ICHx or codec(s) */
3331 card->channels = (card->channels > total_channels) ? total_channels : card->channels;
3332 return num_ac97;
3333}
3334
3335static void __devinit ali_configure_clocking(void)
3336{
3337 struct ali_card *card;
3338 struct ali_state *state;
3339 struct dmabuf *dmabuf;
3340 unsigned int i, offset, new_offset;
3341 unsigned long flags;
3342 card = devs;
3343
3344 /* We could try to set the clocking for multiple cards, but can you even have
3345 * more than one ali in a machine? Besides, clocking is global, so unless
3346 * someone actually thinks more than one ali in a machine is possible and
3347 * decides to rewrite that little bit, setting the rate for more than one card
3348 * is a waste of time.
3349 */
3350 if (card != NULL) {
3351 state = card->states[0] = (struct ali_state *)
3352 kmalloc(sizeof(struct ali_state), GFP_KERNEL);
3353 if (state == NULL)
3354 return;
3355 memset(state, 0, sizeof(struct ali_state));
3356 dmabuf = &state->dmabuf;
3357 dmabuf->write_channel = card->alloc_pcm_channel(card);
3358 state->virt = 0;
3359 state->card = card;
3360 state->magic = ALI5455_STATE_MAGIC;
3361 init_waitqueue_head(&dmabuf->wait);
3362 init_MUTEX(&state->open_sem);
3363 dmabuf->fmt = ALI5455_FMT_STEREO | ALI5455_FMT_16BIT;
3364 dmabuf->trigger = PCM_ENABLE_OUTPUT;
3365 ali_set_dac_rate(state, 48000);
3366 if (prog_dmabuf(state, 0) != 0)
3367 goto config_out_nodmabuf;
3368
3369 if (dmabuf->dmasize < 16384)
3370 goto config_out;
3371
3372 dmabuf->count = dmabuf->dmasize;
3373 outb(31, card->iobase + dmabuf->write_channel->port + OFF_LVI);
3374
3375 local_irq_save(flags);
3376 start_dac(state);
3377 offset = ali_get_dma_addr(state, 0);
3378 mdelay(50);
3379 new_offset = ali_get_dma_addr(state, 0);
3380 stop_dac(state);
3381
3382 outb(2, card->iobase + dmabuf->write_channel->port + OFF_CR);
3383 local_irq_restore(flags);
3384
3385 i = new_offset - offset;
3386
3387 if (i == 0)
3388 goto config_out;
3389 i = i / 4 * 20;
3390 if (i > 48500 || i < 47500) {
3391 clocking = clocking * clocking / i;
3392 }
3393config_out:
3394 dealloc_dmabuf(state);
3395config_out_nodmabuf:
3396 state->card->free_pcm_channel(state->card, state->dmabuf. write_channel->num);
3397 kfree(state);
3398 card->states[0] = NULL;
3399 }
3400}
3401
3402/* install the driver, we do not allocate hardware channel nor DMA buffer now, they are defered
3403 until "ACCESS" time (in prog_dmabuf called by open/read/write/ioctl/mmap) */
3404
3405static int __devinit ali_probe(struct pci_dev *pci_dev,
3406 const struct pci_device_id *pci_id)
3407{
3408 struct ali_card *card;
3409 if (pci_enable_device(pci_dev))
3410 return -EIO;
3411 if (pci_set_dma_mask(pci_dev, ALI5455_DMA_MASK)) {
3412 printk(KERN_ERR "ali5455: architecture does not support"
3413 " 32bit PCI busmaster DMA\n");
3414 return -ENODEV;
3415 }
3416
3417 if ((card = kmalloc(sizeof(struct ali_card), GFP_KERNEL)) == NULL) {
3418 printk(KERN_ERR "ali_audio: out of memory\n");
3419 return -ENOMEM;
3420 }
3421 memset(card, 0, sizeof(*card));
3422 card->initializing = 1;
3423 card->iobase = pci_resource_start(pci_dev, 0);
3424 card->pci_dev = pci_dev;
3425 card->pci_id = pci_id->device;
3426 card->irq = pci_dev->irq;
3427 card->next = devs;
3428 card->magic = ALI5455_CARD_MAGIC;
3429#ifdef CONFIG_PM
3430 card->pm_suspended = 0;
3431#endif
3432 spin_lock_init(&card->lock);
3433 spin_lock_init(&card->ac97_lock);
3434 devs = card;
3435 pci_set_master(pci_dev);
3436 printk(KERN_INFO "ali: %s found at IO 0x%04lx, IRQ %d\n",
3437 card_names[pci_id->driver_data], card->iobase, card->irq);
3438 card->alloc_pcm_channel = ali_alloc_pcm_channel;
3439 card->alloc_rec_pcm_channel = ali_alloc_rec_pcm_channel;
3440 card->alloc_rec_mic_channel = ali_alloc_rec_mic_channel;
3441 card->alloc_codec_spdifout_channel = ali_alloc_codec_spdifout_channel;
3442 card->alloc_controller_spdifout_channel = ali_alloc_controller_spdifout_channel;
3443 card->free_pcm_channel = ali_free_pcm_channel;
3444 card->channel[0].offset = 0;
3445 card->channel[0].port = 0x40;
3446 card->channel[0].num = 0;
3447 card->channel[1].offset = 0;
3448 card->channel[1].port = 0x50;
3449 card->channel[1].num = 1;
3450 card->channel[2].offset = 0;
3451 card->channel[2].port = 0x60;
3452 card->channel[2].num = 2;
3453 card->channel[3].offset = 0;
3454 card->channel[3].port = 0x70;
3455 card->channel[3].num = 3;
3456 card->channel[4].offset = 0;
3457 card->channel[4].port = 0xb0;
3458 card->channel[4].num = 4;
3459 /* claim our iospace and irq */
3460 request_region(card->iobase, 256, card_names[pci_id->driver_data]);
3461 if (request_irq(card->irq, &ali_interrupt, SA_SHIRQ,
3462 card_names[pci_id->driver_data], card)) {
3463 printk(KERN_ERR "ali_audio: unable to allocate irq %d\n",
3464 card->irq);
3465 release_region(card->iobase, 256);
3466 kfree(card);
3467 return -ENODEV;
3468 }
3469
3470 if (ali_reset_5455(card) <= 0) {
3471 unregister_sound_dsp(card->dev_audio);
3472 release_region(card->iobase, 256);
3473 free_irq(card->irq, card);
3474 kfree(card);
3475 return -ENODEV;
3476 }
3477
3478 /* initialize AC97 codec and register /dev/mixer */
3479 if (ali_ac97_init(card) < 0) {
3480 release_region(card->iobase, 256);
3481 free_irq(card->irq, card);
3482 kfree(card);
3483 return -ENODEV;
3484 }
3485
3486 pci_set_drvdata(pci_dev, card);
3487
3488 if (clocking == 0) {
3489 clocking = 48000;
3490 ali_configure_clocking();
3491 }
3492
3493 /* register /dev/dsp */
3494 if ((card->dev_audio = register_sound_dsp(&ali_audio_fops, -1)) < 0) {
3495 int i;
3496 printk(KERN_ERR"ali_audio: couldn't register DSP device!\n");
3497 release_region(card->iobase, 256);
3498 free_irq(card->irq, card);
3499 for (i = 0; i < NR_AC97; i++)
3500 if (card->ac97_codec[i] != NULL) {
3501 unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
3502 kfree(card->ac97_codec[i]);
3503 }
3504 kfree(card);
3505 return -ENODEV;
3506 }
3507 card->initializing = 0;
3508 return 0;
3509}
3510
3511static void __devexit ali_remove(struct pci_dev *pci_dev)
3512{
3513 int i;
3514 struct ali_card *card = pci_get_drvdata(pci_dev);
3515 /* free hardware resources */
3516 free_irq(card->irq, devs);
3517 release_region(card->iobase, 256);
3518 /* unregister audio devices */
3519 for (i = 0; i < NR_AC97; i++)
3520 if (card->ac97_codec[i] != NULL) {
3521 unregister_sound_mixer(card->ac97_codec[i]->
3522 dev_mixer);
3523 ac97_release_codec(card->ac97_codec[i]);
3524 card->ac97_codec[i] = NULL;
3525 }
3526 unregister_sound_dsp(card->dev_audio);
3527 kfree(card);
3528}
3529
3530#ifdef CONFIG_PM
3531static int ali_pm_suspend(struct pci_dev *dev, pm_message_t pm_state)
3532{
3533 struct ali_card *card = pci_get_drvdata(dev);
3534 struct ali_state *state;
3535 unsigned long flags;
3536 struct dmabuf *dmabuf;
3537 int i, num_ac97;
3538
3539 if (!card)
3540 return 0;
3541 spin_lock_irqsave(&card->lock, flags);
3542 card->pm_suspended = 1;
3543 for (i = 0; i < NR_HW_CH; i++) {
3544 state = card->states[i];
3545 if (!state)
3546 continue;
3547 /* this happens only if there are open files */
3548 dmabuf = &state->dmabuf;
3549 if (dmabuf->enable & DAC_RUNNING ||
3550 (dmabuf->count
3551 && (dmabuf->trigger & PCM_ENABLE_OUTPUT))) {
3552 state->pm_saved_dac_rate = dmabuf->rate;
3553 stop_dac(state);
3554 } else {
3555 state->pm_saved_dac_rate = 0;
3556 }
3557 if (dmabuf->enable & ADC_RUNNING) {
3558 state->pm_saved_adc_rate = dmabuf->rate;
3559 stop_adc(state);
3560 } else {
3561 state->pm_saved_adc_rate = 0;
3562 }
3563 dmabuf->ready = 0;
3564 dmabuf->swptr = dmabuf->hwptr = 0;
3565 dmabuf->count = dmabuf->total_bytes = 0;
3566 }
3567
3568 spin_unlock_irqrestore(&card->lock, flags);
3569 /* save mixer settings */
3570 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
3571 struct ac97_codec *codec = card->ac97_codec[num_ac97];
3572 if (!codec)
3573 continue;
3574 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
3575 if ((supported_mixer(codec, i)) && (codec->read_mixer)) {
3576 card->pm_saved_mixer_settings[i][num_ac97] = codec->read_mixer(codec, i);
3577 }
3578 }
3579 }
3580 pci_save_state(dev); /* XXX do we need this? */
3581 pci_disable_device(dev); /* disable busmastering */
3582 pci_set_power_state(dev, 3); /* Zzz. */
3583 return 0;
3584}
3585
3586
3587static int ali_pm_resume(struct pci_dev *dev)
3588{
3589 int num_ac97, i = 0;
3590 struct ali_card *card = pci_get_drvdata(dev);
3591 pci_enable_device(dev);
3592 pci_restore_state(dev);
3593 /* observation of a toshiba portege 3440ct suggests that the
3594 hardware has to be more or less completely reinitialized from
3595 scratch after an apm suspend. Works For Me. -dan */
3596 ali_ac97_random_init_stuff(card);
3597 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
3598 struct ac97_codec *codec = card->ac97_codec[num_ac97];
3599 /* check they haven't stolen the hardware while we were
3600 away */
3601 if (!codec || !ali_ac97_exists(card, num_ac97)) {
3602 if (num_ac97)
3603 continue;
3604 else
3605 BUG();
3606 }
3607 if (!ali_ac97_probe_and_powerup(card, codec))
3608 BUG();
3609 if ((card->ac97_features & 0x0001)) {
3610 /* at probe time we found we could do variable
3611 rates, but APM suspend has made it forget
3612 its magical powers */
3613 if (!ali_ac97_enable_variable_rate(codec))
3614 BUG();
3615 }
3616 /* we lost our mixer settings, so restore them */
3617 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
3618 if (supported_mixer(codec, i)) {
3619 int val = card->pm_saved_mixer_settings[i][num_ac97];
3620 codec->mixer_state[i] = val;
3621 codec->write_mixer(codec, i,
3622 (val & 0xff),
3623 ((val >> 8) & 0xff));
3624 }
3625 }
3626 }
3627
3628 /* we need to restore the sample rate from whatever it was */
3629 for (i = 0; i < NR_HW_CH; i++) {
3630 struct ali_state *state = card->states[i];
3631 if (state) {
3632 if (state->pm_saved_adc_rate)
3633 ali_set_adc_rate(state, state->pm_saved_adc_rate);
3634 if (state->pm_saved_dac_rate)
3635 ali_set_dac_rate(state, state->pm_saved_dac_rate);
3636 }
3637 }
3638
3639 card->pm_suspended = 0;
3640 /* any processes that were reading/writing during the suspend
3641 probably ended up here */
3642 for (i = 0; i < NR_HW_CH; i++) {
3643 struct ali_state *state = card->states[i];
3644 if (state)
3645 wake_up(&state->dmabuf.wait);
3646 }
3647 return 0;
3648}
3649#endif /* CONFIG_PM */
3650
3651MODULE_AUTHOR("");
3652MODULE_DESCRIPTION("ALI 5455 audio support");
3653MODULE_LICENSE("GPL");
3654module_param(clocking, int, 0);
3655/* FIXME: bool? */
3656module_param(strict_clocking, uint, 0);
3657module_param(codec_pcmout_share_spdif_locked, uint, 0);
3658module_param(codec_independent_spdif_locked, uint, 0);
3659module_param(controller_pcmout_share_spdif_locked, uint, 0);
3660module_param(controller_independent_spdif_locked, uint, 0);
3661#define ALI5455_MODULE_NAME "ali5455"
3662static struct pci_driver ali_pci_driver = {
3663 .name = ALI5455_MODULE_NAME,
3664 .id_table = ali_pci_tbl,
3665 .probe = ali_probe,
3666 .remove = __devexit_p(ali_remove),
3667#ifdef CONFIG_PM
3668 .suspend = ali_pm_suspend,
3669 .resume = ali_pm_resume,
3670#endif /* CONFIG_PM */
3671};
3672
3673static int __init ali_init_module(void)
3674{
3675 printk(KERN_INFO "ALI 5455 + AC97 Audio, version "
3676 DRIVER_VERSION ", " __TIME__ " " __DATE__ "\n");
3677
3678 if (codec_independent_spdif_locked > 0) {
3679 if (codec_independent_spdif_locked == 32000
3680 || codec_independent_spdif_locked == 44100
3681 || codec_independent_spdif_locked == 48000) {
3682 printk(KERN_INFO "ali_audio: Enabling S/PDIF at sample rate %dHz.\n", codec_independent_spdif_locked);
3683 } else {
3684 printk(KERN_INFO "ali_audio: S/PDIF can only be locked to 32000, 44100, or 48000Hz.\n");
3685 codec_independent_spdif_locked = 0;
3686 }
3687 }
3688 if (controller_independent_spdif_locked > 0) {
3689 if (controller_independent_spdif_locked == 32000
3690 || controller_independent_spdif_locked == 44100
3691 || controller_independent_spdif_locked == 48000) {
3692 printk(KERN_INFO "ali_audio: Enabling S/PDIF at sample rate %dHz.\n", controller_independent_spdif_locked);
3693 } else {
3694 printk(KERN_INFO "ali_audio: S/PDIF can only be locked to 32000, 44100, or 48000Hz.\n");
3695 controller_independent_spdif_locked = 0;
3696 }
3697 }
3698
3699 if (codec_pcmout_share_spdif_locked > 0) {
3700 if (codec_pcmout_share_spdif_locked == 32000
3701 || codec_pcmout_share_spdif_locked == 44100
3702 || codec_pcmout_share_spdif_locked == 48000) {
3703 printk(KERN_INFO "ali_audio: Enabling S/PDIF at sample rate %dHz.\n", codec_pcmout_share_spdif_locked);
3704 } else {
3705 printk(KERN_INFO "ali_audio: S/PDIF can only be locked to 32000, 44100, or 48000Hz.\n");
3706 codec_pcmout_share_spdif_locked = 0;
3707 }
3708 }
3709 if (controller_pcmout_share_spdif_locked > 0) {
3710 if (controller_pcmout_share_spdif_locked == 32000
3711 || controller_pcmout_share_spdif_locked == 44100
3712 || controller_pcmout_share_spdif_locked == 48000) {
3713 printk(KERN_INFO "ali_audio: Enabling controller S/PDIF at sample rate %dHz.\n", controller_pcmout_share_spdif_locked);
3714 } else {
3715 printk(KERN_INFO "ali_audio: S/PDIF can only be locked to 32000, 44100, or 48000Hz.\n");
3716 controller_pcmout_share_spdif_locked = 0;
3717 }
3718 }
3719 return pci_register_driver(&ali_pci_driver);
3720}
3721
3722static void __exit ali_cleanup_module(void)
3723{
3724 pci_unregister_driver(&ali_pci_driver);
3725}
3726
3727module_init(ali_init_module);
3728module_exit(ali_cleanup_module);
3729/*
3730Local Variables:
3731c-basic-offset: 8
3732End:
3733*/
diff --git a/sound/oss/au1000.c b/sound/oss/au1000.c
new file mode 100644
index 000000000000..4491733c9e4e
--- /dev/null
+++ b/sound/oss/au1000.c
@@ -0,0 +1,2214 @@
1/*
2 * au1000.c -- Sound driver for Alchemy Au1000 MIPS Internet Edge
3 * Processor.
4 *
5 * Copyright 2001 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc.
7 * stevel@mvista.com or source@mvista.com
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
20 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 *
30 * Module command line parameters:
31 *
32 * Supported devices:
33 * /dev/dsp standard OSS /dev/dsp device
34 * /dev/mixer standard OSS /dev/mixer device
35 *
36 * Notes:
37 *
38 * 1. Much of the OSS buffer allocation, ioctl's, and mmap'ing are
39 * taken, slightly modified or not at all, from the ES1371 driver,
40 * so refer to the credits in es1371.c for those. The rest of the
41 * code (probe, open, read, write, the ISR, etc.) is new.
42 *
43 * Revision history
44 * 06.27.2001 Initial version
45 * 03.20.2002 Added mutex locks around read/write methods, to prevent
46 * simultaneous access on SMP or preemptible kernels. Also
47 * removed the counter/pointer fragment aligning at the end
48 * of read/write methods [stevel].
49 * 03.21.2002 Add support for coherent DMA on the audio read/write DMA
50 * channels [stevel].
51 *
52 */
53#include <linux/module.h>
54#include <linux/string.h>
55#include <linux/ioport.h>
56#include <linux/sched.h>
57#include <linux/delay.h>
58#include <linux/sound.h>
59#include <linux/slab.h>
60#include <linux/soundcard.h>
61#include <linux/init.h>
62#include <linux/page-flags.h>
63#include <linux/poll.h>
64#include <linux/pci.h>
65#include <linux/bitops.h>
66#include <linux/proc_fs.h>
67#include <linux/spinlock.h>
68#include <linux/smp_lock.h>
69#include <linux/ac97_codec.h>
70#include <linux/interrupt.h>
71#include <asm/io.h>
72#include <asm/uaccess.h>
73#include <asm/mach-au1x00/au1000.h>
74#include <asm/mach-au1x00/au1000_dma.h>
75
76/* --------------------------------------------------------------------- */
77
78#undef OSS_DOCUMENTED_MIXER_SEMANTICS
79#undef AU1000_DEBUG
80#undef AU1000_VERBOSE_DEBUG
81
82#define AU1000_MODULE_NAME "Au1000 audio"
83#define PFX AU1000_MODULE_NAME
84
85#ifdef AU1000_DEBUG
86#define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
87#else
88#define dbg(format, arg...) do {} while (0)
89#endif
90#define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
91#define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
92#define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
93
94
95/* misc stuff */
96#define POLL_COUNT 0x5000
97#define AC97_EXT_DACS (AC97_EXTID_SDAC | AC97_EXTID_CDAC | AC97_EXTID_LDAC)
98
99/* Boot options */
100static int vra = 0; // 0 = no VRA, 1 = use VRA if codec supports it
101MODULE_PARM(vra, "i");
102MODULE_PARM_DESC(vra, "if 1 use VRA if codec supports it");
103
104
105/* --------------------------------------------------------------------- */
106
107struct au1000_state {
108 /* soundcore stuff */
109 int dev_audio;
110
111#ifdef AU1000_DEBUG
112 /* debug /proc entry */
113 struct proc_dir_entry *ps;
114 struct proc_dir_entry *ac97_ps;
115#endif /* AU1000_DEBUG */
116
117 struct ac97_codec codec;
118 unsigned codec_base_caps;// AC'97 reg 00h, "Reset Register"
119 unsigned codec_ext_caps; // AC'97 reg 28h, "Extended Audio ID"
120 int no_vra; // do not use VRA
121
122 spinlock_t lock;
123 struct semaphore open_sem;
124 struct semaphore sem;
125 mode_t open_mode;
126 wait_queue_head_t open_wait;
127
128 struct dmabuf {
129 unsigned int dmanr; // DMA Channel number
130 unsigned sample_rate; // Hz
131 unsigned src_factor; // SRC interp/decimation (no vra)
132 unsigned sample_size; // 8 or 16
133 int num_channels; // 1 = mono, 2 = stereo, 4, 6
134 int dma_bytes_per_sample;// DMA bytes per audio sample frame
135 int user_bytes_per_sample;// User bytes per audio sample frame
136 int cnt_factor; // user-to-DMA bytes per audio
137 // sample frame
138 void *rawbuf;
139 dma_addr_t dmaaddr;
140 unsigned buforder;
141 unsigned numfrag; // # of DMA fragments in DMA buffer
142 unsigned fragshift;
143 void *nextIn; // ptr to next-in to DMA buffer
144 void *nextOut;// ptr to next-out from DMA buffer
145 int count; // current byte count in DMA buffer
146 unsigned total_bytes; // total bytes written or read
147 unsigned error; // over/underrun
148 wait_queue_head_t wait;
149 /* redundant, but makes calculations easier */
150 unsigned fragsize; // user perception of fragment size
151 unsigned dma_fragsize; // DMA (real) fragment size
152 unsigned dmasize; // Total DMA buffer size
153 // (mult. of DMA fragsize)
154 /* OSS stuff */
155 unsigned mapped:1;
156 unsigned ready:1;
157 unsigned stopped:1;
158 unsigned ossfragshift;
159 int ossmaxfrags;
160 unsigned subdivision;
161 } dma_dac , dma_adc;
162} au1000_state;
163
164/* --------------------------------------------------------------------- */
165
166
167static inline unsigned ld2(unsigned int x)
168{
169 unsigned r = 0;
170
171 if (x >= 0x10000) {
172 x >>= 16;
173 r += 16;
174 }
175 if (x >= 0x100) {
176 x >>= 8;
177 r += 8;
178 }
179 if (x >= 0x10) {
180 x >>= 4;
181 r += 4;
182 }
183 if (x >= 4) {
184 x >>= 2;
185 r += 2;
186 }
187 if (x >= 2)
188 r++;
189 return r;
190}
191
192/* --------------------------------------------------------------------- */
193
194static void au1000_delay(int msec)
195{
196 unsigned long tmo;
197 signed long tmo2;
198
199 if (in_interrupt())
200 return;
201
202 tmo = jiffies + (msec * HZ) / 1000;
203 for (;;) {
204 tmo2 = tmo - jiffies;
205 if (tmo2 <= 0)
206 break;
207 schedule_timeout(tmo2);
208 }
209}
210
211
212/* --------------------------------------------------------------------- */
213
214static u16 rdcodec(struct ac97_codec *codec, u8 addr)
215{
216 struct au1000_state *s = (struct au1000_state *)codec->private_data;
217 unsigned long flags;
218 u32 cmd;
219 u16 data;
220 int i;
221
222 spin_lock_irqsave(&s->lock, flags);
223
224 for (i = 0; i < POLL_COUNT; i++)
225 if (!(au_readl(AC97C_STATUS) & AC97C_CP))
226 break;
227 if (i == POLL_COUNT)
228 err("rdcodec: codec cmd pending expired!");
229
230 cmd = (u32) addr & AC97C_INDEX_MASK;
231 cmd |= AC97C_READ; // read command
232 au_writel(cmd, AC97C_CMD);
233
234 /* now wait for the data */
235 for (i = 0; i < POLL_COUNT; i++)
236 if (!(au_readl(AC97C_STATUS) & AC97C_CP))
237 break;
238 if (i == POLL_COUNT) {
239 err("rdcodec: read poll expired!");
240 return 0;
241 }
242
243 data = au_readl(AC97C_CMD) & 0xffff;
244
245 spin_unlock_irqrestore(&s->lock, flags);
246
247 return data;
248}
249
250
251static void wrcodec(struct ac97_codec *codec, u8 addr, u16 data)
252{
253 struct au1000_state *s = (struct au1000_state *)codec->private_data;
254 unsigned long flags;
255 u32 cmd;
256 int i;
257
258 spin_lock_irqsave(&s->lock, flags);
259
260 for (i = 0; i < POLL_COUNT; i++)
261 if (!(au_readl(AC97C_STATUS) & AC97C_CP))
262 break;
263 if (i == POLL_COUNT)
264 err("wrcodec: codec cmd pending expired!");
265
266 cmd = (u32) addr & AC97C_INDEX_MASK;
267 cmd &= ~AC97C_READ; // write command
268 cmd |= ((u32) data << AC97C_WD_BIT); // OR in the data word
269 au_writel(cmd, AC97C_CMD);
270
271 spin_unlock_irqrestore(&s->lock, flags);
272}
273
274static void waitcodec(struct ac97_codec *codec)
275{
276 u16 temp;
277 int i;
278
279 /* codec_wait is used to wait for a ready state after
280 an AC97C_RESET. */
281 au1000_delay(10);
282
283 // first poll the CODEC_READY tag bit
284 for (i = 0; i < POLL_COUNT; i++)
285 if (au_readl(AC97C_STATUS) & AC97C_READY)
286 break;
287 if (i == POLL_COUNT) {
288 err("waitcodec: CODEC_READY poll expired!");
289 return;
290 }
291 // get AC'97 powerdown control/status register
292 temp = rdcodec(codec, AC97_POWER_CONTROL);
293
294 // If anything is powered down, power'em up
295 if (temp & 0x7f00) {
296 // Power on
297 wrcodec(codec, AC97_POWER_CONTROL, 0);
298 au1000_delay(100);
299 // Reread
300 temp = rdcodec(codec, AC97_POWER_CONTROL);
301 }
302
303 // Check if Codec REF,ANL,DAC,ADC ready
304 if ((temp & 0x7f0f) != 0x000f)
305 err("codec reg 26 status (0x%x) not ready!!", temp);
306}
307
308
309/* --------------------------------------------------------------------- */
310
311/* stop the ADC before calling */
312static void set_adc_rate(struct au1000_state *s, unsigned rate)
313{
314 struct dmabuf *adc = &s->dma_adc;
315 struct dmabuf *dac = &s->dma_dac;
316 unsigned adc_rate, dac_rate;
317 u16 ac97_extstat;
318
319 if (s->no_vra) {
320 // calc SRC factor
321 adc->src_factor = ((96000 / rate) + 1) >> 1;
322 adc->sample_rate = 48000 / adc->src_factor;
323 return;
324 }
325
326 adc->src_factor = 1;
327
328 ac97_extstat = rdcodec(&s->codec, AC97_EXTENDED_STATUS);
329
330 rate = rate > 48000 ? 48000 : rate;
331
332 // enable VRA
333 wrcodec(&s->codec, AC97_EXTENDED_STATUS,
334 ac97_extstat | AC97_EXTSTAT_VRA);
335 // now write the sample rate
336 wrcodec(&s->codec, AC97_PCM_LR_ADC_RATE, (u16) rate);
337 // read it back for actual supported rate
338 adc_rate = rdcodec(&s->codec, AC97_PCM_LR_ADC_RATE);
339
340#ifdef AU1000_VERBOSE_DEBUG
341 dbg("%s: set to %d Hz", __FUNCTION__, adc_rate);
342#endif
343
344 // some codec's don't allow unequal DAC and ADC rates, in which case
345 // writing one rate reg actually changes both.
346 dac_rate = rdcodec(&s->codec, AC97_PCM_FRONT_DAC_RATE);
347 if (dac->num_channels > 2)
348 wrcodec(&s->codec, AC97_PCM_SURR_DAC_RATE, dac_rate);
349 if (dac->num_channels > 4)
350 wrcodec(&s->codec, AC97_PCM_LFE_DAC_RATE, dac_rate);
351
352 adc->sample_rate = adc_rate;
353 dac->sample_rate = dac_rate;
354}
355
356/* stop the DAC before calling */
357static void set_dac_rate(struct au1000_state *s, unsigned rate)
358{
359 struct dmabuf *dac = &s->dma_dac;
360 struct dmabuf *adc = &s->dma_adc;
361 unsigned adc_rate, dac_rate;
362 u16 ac97_extstat;
363
364 if (s->no_vra) {
365 // calc SRC factor
366 dac->src_factor = ((96000 / rate) + 1) >> 1;
367 dac->sample_rate = 48000 / dac->src_factor;
368 return;
369 }
370
371 dac->src_factor = 1;
372
373 ac97_extstat = rdcodec(&s->codec, AC97_EXTENDED_STATUS);
374
375 rate = rate > 48000 ? 48000 : rate;
376
377 // enable VRA
378 wrcodec(&s->codec, AC97_EXTENDED_STATUS,
379 ac97_extstat | AC97_EXTSTAT_VRA);
380 // now write the sample rate
381 wrcodec(&s->codec, AC97_PCM_FRONT_DAC_RATE, (u16) rate);
382 // I don't support different sample rates for multichannel,
383 // so make these channels the same.
384 if (dac->num_channels > 2)
385 wrcodec(&s->codec, AC97_PCM_SURR_DAC_RATE, (u16) rate);
386 if (dac->num_channels > 4)
387 wrcodec(&s->codec, AC97_PCM_LFE_DAC_RATE, (u16) rate);
388 // read it back for actual supported rate
389 dac_rate = rdcodec(&s->codec, AC97_PCM_FRONT_DAC_RATE);
390
391#ifdef AU1000_VERBOSE_DEBUG
392 dbg("%s: set to %d Hz", __FUNCTION__, dac_rate);
393#endif
394
395 // some codec's don't allow unequal DAC and ADC rates, in which case
396 // writing one rate reg actually changes both.
397 adc_rate = rdcodec(&s->codec, AC97_PCM_LR_ADC_RATE);
398
399 dac->sample_rate = dac_rate;
400 adc->sample_rate = adc_rate;
401}
402
403static void stop_dac(struct au1000_state *s)
404{
405 struct dmabuf *db = &s->dma_dac;
406 unsigned long flags;
407
408 if (db->stopped)
409 return;
410
411 spin_lock_irqsave(&s->lock, flags);
412
413 disable_dma(db->dmanr);
414
415 db->stopped = 1;
416
417 spin_unlock_irqrestore(&s->lock, flags);
418}
419
420static void stop_adc(struct au1000_state *s)
421{
422 struct dmabuf *db = &s->dma_adc;
423 unsigned long flags;
424
425 if (db->stopped)
426 return;
427
428 spin_lock_irqsave(&s->lock, flags);
429
430 disable_dma(db->dmanr);
431
432 db->stopped = 1;
433
434 spin_unlock_irqrestore(&s->lock, flags);
435}
436
437
438static void set_xmit_slots(int num_channels)
439{
440 u32 ac97_config = au_readl(AC97C_CONFIG) & ~AC97C_XMIT_SLOTS_MASK;
441
442 switch (num_channels) {
443 case 1: // mono
444 case 2: // stereo, slots 3,4
445 ac97_config |= (0x3 << AC97C_XMIT_SLOTS_BIT);
446 break;
447 case 4: // stereo with surround, slots 3,4,7,8
448 ac97_config |= (0x33 << AC97C_XMIT_SLOTS_BIT);
449 break;
450 case 6: // stereo with surround and center/LFE, slots 3,4,6,7,8,9
451 ac97_config |= (0x7b << AC97C_XMIT_SLOTS_BIT);
452 break;
453 }
454
455 au_writel(ac97_config, AC97C_CONFIG);
456}
457
458static void set_recv_slots(int num_channels)
459{
460 u32 ac97_config = au_readl(AC97C_CONFIG) & ~AC97C_RECV_SLOTS_MASK;
461
462 /*
463 * Always enable slots 3 and 4 (stereo). Slot 6 is
464 * optional Mic ADC, which I don't support yet.
465 */
466 ac97_config |= (0x3 << AC97C_RECV_SLOTS_BIT);
467
468 au_writel(ac97_config, AC97C_CONFIG);
469}
470
471static void start_dac(struct au1000_state *s)
472{
473 struct dmabuf *db = &s->dma_dac;
474 unsigned long flags;
475 unsigned long buf1, buf2;
476
477 if (!db->stopped)
478 return;
479
480 spin_lock_irqsave(&s->lock, flags);
481
482 au_readl(AC97C_STATUS); // read status to clear sticky bits
483
484 // reset Buffer 1 and 2 pointers to nextOut and nextOut+dma_fragsize
485 buf1 = virt_to_phys(db->nextOut);
486 buf2 = buf1 + db->dma_fragsize;
487 if (buf2 >= db->dmaaddr + db->dmasize)
488 buf2 -= db->dmasize;
489
490 set_xmit_slots(db->num_channels);
491
492 init_dma(db->dmanr);
493 if (get_dma_active_buffer(db->dmanr) == 0) {
494 clear_dma_done0(db->dmanr); // clear DMA done bit
495 set_dma_addr0(db->dmanr, buf1);
496 set_dma_addr1(db->dmanr, buf2);
497 } else {
498 clear_dma_done1(db->dmanr); // clear DMA done bit
499 set_dma_addr1(db->dmanr, buf1);
500 set_dma_addr0(db->dmanr, buf2);
501 }
502 set_dma_count(db->dmanr, db->dma_fragsize>>1);
503 enable_dma_buffers(db->dmanr);
504
505 start_dma(db->dmanr);
506
507#ifdef AU1000_VERBOSE_DEBUG
508 dump_au1000_dma_channel(db->dmanr);
509#endif
510
511 db->stopped = 0;
512
513 spin_unlock_irqrestore(&s->lock, flags);
514}
515
516static void start_adc(struct au1000_state *s)
517{
518 struct dmabuf *db = &s->dma_adc;
519 unsigned long flags;
520 unsigned long buf1, buf2;
521
522 if (!db->stopped)
523 return;
524
525 spin_lock_irqsave(&s->lock, flags);
526
527 au_readl(AC97C_STATUS); // read status to clear sticky bits
528
529 // reset Buffer 1 and 2 pointers to nextIn and nextIn+dma_fragsize
530 buf1 = virt_to_phys(db->nextIn);
531 buf2 = buf1 + db->dma_fragsize;
532 if (buf2 >= db->dmaaddr + db->dmasize)
533 buf2 -= db->dmasize;
534
535 set_recv_slots(db->num_channels);
536
537 init_dma(db->dmanr);
538 if (get_dma_active_buffer(db->dmanr) == 0) {
539 clear_dma_done0(db->dmanr); // clear DMA done bit
540 set_dma_addr0(db->dmanr, buf1);
541 set_dma_addr1(db->dmanr, buf2);
542 } else {
543 clear_dma_done1(db->dmanr); // clear DMA done bit
544 set_dma_addr1(db->dmanr, buf1);
545 set_dma_addr0(db->dmanr, buf2);
546 }
547 set_dma_count(db->dmanr, db->dma_fragsize>>1);
548 enable_dma_buffers(db->dmanr);
549
550 start_dma(db->dmanr);
551
552#ifdef AU1000_VERBOSE_DEBUG
553 dump_au1000_dma_channel(db->dmanr);
554#endif
555
556 db->stopped = 0;
557
558 spin_unlock_irqrestore(&s->lock, flags);
559}
560
561/* --------------------------------------------------------------------- */
562
563#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
564#define DMABUF_MINORDER 1
565
566extern inline void dealloc_dmabuf(struct au1000_state *s, struct dmabuf *db)
567{
568 struct page *page, *pend;
569
570 if (db->rawbuf) {
571 /* undo marking the pages as reserved */
572 pend = virt_to_page(db->rawbuf +
573 (PAGE_SIZE << db->buforder) - 1);
574 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
575 ClearPageReserved(page);
576 dma_free_noncoherent(NULL,
577 PAGE_SIZE << db->buforder,
578 db->rawbuf,
579 db->dmaaddr);
580 }
581 db->rawbuf = db->nextIn = db->nextOut = NULL;
582 db->mapped = db->ready = 0;
583}
584
585static int prog_dmabuf(struct au1000_state *s, struct dmabuf *db)
586{
587 int order;
588 unsigned user_bytes_per_sec;
589 unsigned bufs;
590 struct page *page, *pend;
591 unsigned rate = db->sample_rate;
592
593 if (!db->rawbuf) {
594 db->ready = db->mapped = 0;
595 for (order = DMABUF_DEFAULTORDER;
596 order >= DMABUF_MINORDER; order--)
597 if ((db->rawbuf = dma_alloc_noncoherent(NULL,
598 PAGE_SIZE << order,
599 &db->dmaaddr,
600 0)))
601 break;
602 if (!db->rawbuf)
603 return -ENOMEM;
604 db->buforder = order;
605 /* now mark the pages as reserved;
606 otherwise remap_pfn_range doesn't do what we want */
607 pend = virt_to_page(db->rawbuf +
608 (PAGE_SIZE << db->buforder) - 1);
609 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
610 SetPageReserved(page);
611 }
612
613 db->cnt_factor = 1;
614 if (db->sample_size == 8)
615 db->cnt_factor *= 2;
616 if (db->num_channels == 1)
617 db->cnt_factor *= 2;
618 db->cnt_factor *= db->src_factor;
619
620 db->count = 0;
621 db->nextIn = db->nextOut = db->rawbuf;
622
623 db->user_bytes_per_sample = (db->sample_size>>3) * db->num_channels;
624 db->dma_bytes_per_sample = 2 * ((db->num_channels == 1) ?
625 2 : db->num_channels);
626
627 user_bytes_per_sec = rate * db->user_bytes_per_sample;
628 bufs = PAGE_SIZE << db->buforder;
629 if (db->ossfragshift) {
630 if ((1000 << db->ossfragshift) < user_bytes_per_sec)
631 db->fragshift = ld2(user_bytes_per_sec/1000);
632 else
633 db->fragshift = db->ossfragshift;
634 } else {
635 db->fragshift = ld2(user_bytes_per_sec / 100 /
636 (db->subdivision ? db->subdivision : 1));
637 if (db->fragshift < 3)
638 db->fragshift = 3;
639 }
640
641 db->fragsize = 1 << db->fragshift;
642 db->dma_fragsize = db->fragsize * db->cnt_factor;
643 db->numfrag = bufs / db->dma_fragsize;
644
645 while (db->numfrag < 4 && db->fragshift > 3) {
646 db->fragshift--;
647 db->fragsize = 1 << db->fragshift;
648 db->dma_fragsize = db->fragsize * db->cnt_factor;
649 db->numfrag = bufs / db->dma_fragsize;
650 }
651
652 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
653 db->numfrag = db->ossmaxfrags;
654
655 db->dmasize = db->dma_fragsize * db->numfrag;
656 memset(db->rawbuf, 0, bufs);
657
658#ifdef AU1000_VERBOSE_DEBUG
659 dbg("rate=%d, samplesize=%d, channels=%d",
660 rate, db->sample_size, db->num_channels);
661 dbg("fragsize=%d, cnt_factor=%d, dma_fragsize=%d",
662 db->fragsize, db->cnt_factor, db->dma_fragsize);
663 dbg("numfrag=%d, dmasize=%d", db->numfrag, db->dmasize);
664#endif
665
666 db->ready = 1;
667 return 0;
668}
669
670extern inline int prog_dmabuf_adc(struct au1000_state *s)
671{
672 stop_adc(s);
673 return prog_dmabuf(s, &s->dma_adc);
674
675}
676
677extern inline int prog_dmabuf_dac(struct au1000_state *s)
678{
679 stop_dac(s);
680 return prog_dmabuf(s, &s->dma_dac);
681}
682
683
684/* hold spinlock for the following */
685static irqreturn_t dac_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
686{
687 struct au1000_state *s = (struct au1000_state *) dev_id;
688 struct dmabuf *dac = &s->dma_dac;
689 unsigned long newptr;
690 u32 ac97c_stat, buff_done;
691
692 ac97c_stat = au_readl(AC97C_STATUS);
693#ifdef AU1000_VERBOSE_DEBUG
694 if (ac97c_stat & (AC97C_XU | AC97C_XO | AC97C_TE))
695 dbg("AC97C status = 0x%08x", ac97c_stat);
696#endif
697
698 if ((buff_done = get_dma_buffer_done(dac->dmanr)) == 0) {
699 /* fastpath out, to ease interrupt sharing */
700 return IRQ_HANDLED;
701 }
702
703 spin_lock(&s->lock);
704
705 if (buff_done != (DMA_D0 | DMA_D1)) {
706 dac->nextOut += dac->dma_fragsize;
707 if (dac->nextOut >= dac->rawbuf + dac->dmasize)
708 dac->nextOut -= dac->dmasize;
709
710 /* update playback pointers */
711 newptr = virt_to_phys(dac->nextOut) + dac->dma_fragsize;
712 if (newptr >= dac->dmaaddr + dac->dmasize)
713 newptr -= dac->dmasize;
714
715 dac->count -= dac->dma_fragsize;
716 dac->total_bytes += dac->dma_fragsize;
717
718 if (dac->count <= 0) {
719#ifdef AU1000_VERBOSE_DEBUG
720 dbg("dac underrun");
721#endif
722 spin_unlock(&s->lock);
723 stop_dac(s);
724 spin_lock(&s->lock);
725 dac->count = 0;
726 dac->nextIn = dac->nextOut;
727 } else if (buff_done == DMA_D0) {
728 clear_dma_done0(dac->dmanr); // clear DMA done bit
729 set_dma_count0(dac->dmanr, dac->dma_fragsize>>1);
730 set_dma_addr0(dac->dmanr, newptr);
731 enable_dma_buffer0(dac->dmanr); // reenable
732 } else {
733 clear_dma_done1(dac->dmanr); // clear DMA done bit
734 set_dma_count1(dac->dmanr, dac->dma_fragsize>>1);
735 set_dma_addr1(dac->dmanr, newptr);
736 enable_dma_buffer1(dac->dmanr); // reenable
737 }
738 } else {
739 // both done bits set, we missed an interrupt
740 spin_unlock(&s->lock);
741 stop_dac(s);
742 spin_lock(&s->lock);
743
744 dac->nextOut += 2*dac->dma_fragsize;
745 if (dac->nextOut >= dac->rawbuf + dac->dmasize)
746 dac->nextOut -= dac->dmasize;
747
748 dac->count -= 2*dac->dma_fragsize;
749 dac->total_bytes += 2*dac->dma_fragsize;
750
751 if (dac->count > 0) {
752 spin_unlock(&s->lock);
753 start_dac(s);
754 spin_lock(&s->lock);
755 }
756 }
757
758 /* wake up anybody listening */
759 if (waitqueue_active(&dac->wait))
760 wake_up(&dac->wait);
761
762 spin_unlock(&s->lock);
763
764 return IRQ_HANDLED;
765}
766
767
768static irqreturn_t adc_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
769{
770 struct au1000_state *s = (struct au1000_state *) dev_id;
771 struct dmabuf *adc = &s->dma_adc;
772 unsigned long newptr;
773 u32 ac97c_stat, buff_done;
774
775 ac97c_stat = au_readl(AC97C_STATUS);
776#ifdef AU1000_VERBOSE_DEBUG
777 if (ac97c_stat & (AC97C_RU | AC97C_RO))
778 dbg("AC97C status = 0x%08x", ac97c_stat);
779#endif
780
781 if ((buff_done = get_dma_buffer_done(adc->dmanr)) == 0) {
782 /* fastpath out, to ease interrupt sharing */
783 return IRQ_HANDLED;
784 }
785
786 spin_lock(&s->lock);
787
788 if (buff_done != (DMA_D0 | DMA_D1)) {
789 if (adc->count + adc->dma_fragsize > adc->dmasize) {
790 // Overrun. Stop ADC and log the error
791 spin_unlock(&s->lock);
792 stop_adc(s);
793 adc->error++;
794 err("adc overrun");
795 return IRQ_NONE;
796 }
797
798 adc->nextIn += adc->dma_fragsize;
799 if (adc->nextIn >= adc->rawbuf + adc->dmasize)
800 adc->nextIn -= adc->dmasize;
801
802 /* update capture pointers */
803 newptr = virt_to_phys(adc->nextIn) + adc->dma_fragsize;
804 if (newptr >= adc->dmaaddr + adc->dmasize)
805 newptr -= adc->dmasize;
806
807 adc->count += adc->dma_fragsize;
808 adc->total_bytes += adc->dma_fragsize;
809
810 if (buff_done == DMA_D0) {
811 clear_dma_done0(adc->dmanr); // clear DMA done bit
812 set_dma_count0(adc->dmanr, adc->dma_fragsize>>1);
813 set_dma_addr0(adc->dmanr, newptr);
814 enable_dma_buffer0(adc->dmanr); // reenable
815 } else {
816 clear_dma_done1(adc->dmanr); // clear DMA done bit
817 set_dma_count1(adc->dmanr, adc->dma_fragsize>>1);
818 set_dma_addr1(adc->dmanr, newptr);
819 enable_dma_buffer1(adc->dmanr); // reenable
820 }
821 } else {
822 // both done bits set, we missed an interrupt
823 spin_unlock(&s->lock);
824 stop_adc(s);
825 spin_lock(&s->lock);
826
827 if (adc->count + 2*adc->dma_fragsize > adc->dmasize) {
828 // Overrun. Log the error
829 adc->error++;
830 err("adc overrun");
831 spin_unlock(&s->lock);
832 return IRQ_NONE;
833 }
834
835 adc->nextIn += 2*adc->dma_fragsize;
836 if (adc->nextIn >= adc->rawbuf + adc->dmasize)
837 adc->nextIn -= adc->dmasize;
838
839 adc->count += 2*adc->dma_fragsize;
840 adc->total_bytes += 2*adc->dma_fragsize;
841
842 spin_unlock(&s->lock);
843 start_adc(s);
844 spin_lock(&s->lock);
845 }
846
847 /* wake up anybody listening */
848 if (waitqueue_active(&adc->wait))
849 wake_up(&adc->wait);
850
851 spin_unlock(&s->lock);
852
853 return IRQ_HANDLED;
854}
855
856/* --------------------------------------------------------------------- */
857
858static loff_t au1000_llseek(struct file *file, loff_t offset, int origin)
859{
860 return -ESPIPE;
861}
862
863
864static int au1000_open_mixdev(struct inode *inode, struct file *file)
865{
866 file->private_data = &au1000_state;
867 return nonseekable_open(inode, file);
868}
869
870static int au1000_release_mixdev(struct inode *inode, struct file *file)
871{
872 return 0;
873}
874
875static int mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd,
876 unsigned long arg)
877{
878 return codec->mixer_ioctl(codec, cmd, arg);
879}
880
881static int au1000_ioctl_mixdev(struct inode *inode, struct file *file,
882 unsigned int cmd, unsigned long arg)
883{
884 struct au1000_state *s = (struct au1000_state *)file->private_data;
885 struct ac97_codec *codec = &s->codec;
886
887 return mixdev_ioctl(codec, cmd, arg);
888}
889
890static /*const */ struct file_operations au1000_mixer_fops = {
891 .owner = THIS_MODULE,
892 .llseek = au1000_llseek,
893 .ioctl = au1000_ioctl_mixdev,
894 .open = au1000_open_mixdev,
895 .release = au1000_release_mixdev,
896};
897
898/* --------------------------------------------------------------------- */
899
900static int drain_dac(struct au1000_state *s, int nonblock)
901{
902 unsigned long flags;
903 int count, tmo;
904
905 if (s->dma_dac.mapped || !s->dma_dac.ready || s->dma_dac.stopped)
906 return 0;
907
908 for (;;) {
909 spin_lock_irqsave(&s->lock, flags);
910 count = s->dma_dac.count;
911 spin_unlock_irqrestore(&s->lock, flags);
912 if (count <= 0)
913 break;
914 if (signal_pending(current))
915 break;
916 if (nonblock)
917 return -EBUSY;
918 tmo = 1000 * count / (s->no_vra ?
919 48000 : s->dma_dac.sample_rate);
920 tmo /= s->dma_dac.dma_bytes_per_sample;
921 au1000_delay(tmo);
922 }
923 if (signal_pending(current))
924 return -ERESTARTSYS;
925 return 0;
926}
927
928/* --------------------------------------------------------------------- */
929
930static inline u8 S16_TO_U8(s16 ch)
931{
932 return (u8) (ch >> 8) + 0x80;
933}
934static inline s16 U8_TO_S16(u8 ch)
935{
936 return (s16) (ch - 0x80) << 8;
937}
938
939/*
940 * Translates user samples to dma buffer suitable for AC'97 DAC data:
941 * If mono, copy left channel to right channel in dma buffer.
942 * If 8 bit samples, cvt to 16-bit before writing to dma buffer.
943 * If interpolating (no VRA), duplicate every audio frame src_factor times.
944 */
945static int translate_from_user(struct dmabuf *db,
946 char* dmabuf,
947 char* userbuf,
948 int dmacount)
949{
950 int sample, i;
951 int interp_bytes_per_sample;
952 int num_samples;
953 int mono = (db->num_channels == 1);
954 char usersample[12];
955 s16 ch, dmasample[6];
956
957 if (db->sample_size == 16 && !mono && db->src_factor == 1) {
958 // no translation necessary, just copy
959 if (copy_from_user(dmabuf, userbuf, dmacount))
960 return -EFAULT;
961 return dmacount;
962 }
963
964 interp_bytes_per_sample = db->dma_bytes_per_sample * db->src_factor;
965 num_samples = dmacount / interp_bytes_per_sample;
966
967 for (sample = 0; sample < num_samples; sample++) {
968 if (copy_from_user(usersample, userbuf,
969 db->user_bytes_per_sample)) {
970 dbg("%s: fault", __FUNCTION__);
971 return -EFAULT;
972 }
973
974 for (i = 0; i < db->num_channels; i++) {
975 if (db->sample_size == 8)
976 ch = U8_TO_S16(usersample[i]);
977 else
978 ch = *((s16 *) (&usersample[i * 2]));
979 dmasample[i] = ch;
980 if (mono)
981 dmasample[i + 1] = ch; // right channel
982 }
983
984 // duplicate every audio frame src_factor times
985 for (i = 0; i < db->src_factor; i++)
986 memcpy(dmabuf, dmasample, db->dma_bytes_per_sample);
987
988 userbuf += db->user_bytes_per_sample;
989 dmabuf += interp_bytes_per_sample;
990 }
991
992 return num_samples * interp_bytes_per_sample;
993}
994
995/*
996 * Translates AC'97 ADC samples to user buffer:
997 * If mono, send only left channel to user buffer.
998 * If 8 bit samples, cvt from 16 to 8 bit before writing to user buffer.
999 * If decimating (no VRA), skip over src_factor audio frames.
1000 */
1001static int translate_to_user(struct dmabuf *db,
1002 char* userbuf,
1003 char* dmabuf,
1004 int dmacount)
1005{
1006 int sample, i;
1007 int interp_bytes_per_sample;
1008 int num_samples;
1009 int mono = (db->num_channels == 1);
1010 char usersample[12];
1011
1012 if (db->sample_size == 16 && !mono && db->src_factor == 1) {
1013 // no translation necessary, just copy
1014 if (copy_to_user(userbuf, dmabuf, dmacount))
1015 return -EFAULT;
1016 return dmacount;
1017 }
1018
1019 interp_bytes_per_sample = db->dma_bytes_per_sample * db->src_factor;
1020 num_samples = dmacount / interp_bytes_per_sample;
1021
1022 for (sample = 0; sample < num_samples; sample++) {
1023 for (i = 0; i < db->num_channels; i++) {
1024 if (db->sample_size == 8)
1025 usersample[i] =
1026 S16_TO_U8(*((s16 *) (&dmabuf[i * 2])));
1027 else
1028 *((s16 *) (&usersample[i * 2])) =
1029 *((s16 *) (&dmabuf[i * 2]));
1030 }
1031
1032 if (copy_to_user(userbuf, usersample,
1033 db->user_bytes_per_sample)) {
1034 dbg("%s: fault", __FUNCTION__);
1035 return -EFAULT;
1036 }
1037
1038 userbuf += db->user_bytes_per_sample;
1039 dmabuf += interp_bytes_per_sample;
1040 }
1041
1042 return num_samples * interp_bytes_per_sample;
1043}
1044
1045/*
1046 * Copy audio data to/from user buffer from/to dma buffer, taking care
1047 * that we wrap when reading/writing the dma buffer. Returns actual byte
1048 * count written to or read from the dma buffer.
1049 */
1050static int copy_dmabuf_user(struct dmabuf *db, char* userbuf,
1051 int count, int to_user)
1052{
1053 char *bufptr = to_user ? db->nextOut : db->nextIn;
1054 char *bufend = db->rawbuf + db->dmasize;
1055 int cnt, ret;
1056
1057 if (bufptr + count > bufend) {
1058 int partial = (int) (bufend - bufptr);
1059 if (to_user) {
1060 if ((cnt = translate_to_user(db, userbuf,
1061 bufptr, partial)) < 0)
1062 return cnt;
1063 ret = cnt;
1064 if ((cnt = translate_to_user(db, userbuf + partial,
1065 db->rawbuf,
1066 count - partial)) < 0)
1067 return cnt;
1068 ret += cnt;
1069 } else {
1070 if ((cnt = translate_from_user(db, bufptr, userbuf,
1071 partial)) < 0)
1072 return cnt;
1073 ret = cnt;
1074 if ((cnt = translate_from_user(db, db->rawbuf,
1075 userbuf + partial,
1076 count - partial)) < 0)
1077 return cnt;
1078 ret += cnt;
1079 }
1080 } else {
1081 if (to_user)
1082 ret = translate_to_user(db, userbuf, bufptr, count);
1083 else
1084 ret = translate_from_user(db, bufptr, userbuf, count);
1085 }
1086
1087 return ret;
1088}
1089
1090
1091static ssize_t au1000_read(struct file *file, char *buffer,
1092 size_t count, loff_t *ppos)
1093{
1094 struct au1000_state *s = (struct au1000_state *)file->private_data;
1095 struct dmabuf *db = &s->dma_adc;
1096 DECLARE_WAITQUEUE(wait, current);
1097 ssize_t ret;
1098 unsigned long flags;
1099 int cnt, usercnt, avail;
1100
1101 if (db->mapped)
1102 return -ENXIO;
1103 if (!access_ok(VERIFY_WRITE, buffer, count))
1104 return -EFAULT;
1105 ret = 0;
1106
1107 count *= db->cnt_factor;
1108
1109 down(&s->sem);
1110 add_wait_queue(&db->wait, &wait);
1111
1112 while (count > 0) {
1113 // wait for samples in ADC dma buffer
1114 do {
1115 if (db->stopped)
1116 start_adc(s);
1117 spin_lock_irqsave(&s->lock, flags);
1118 avail = db->count;
1119 if (avail <= 0)
1120 __set_current_state(TASK_INTERRUPTIBLE);
1121 spin_unlock_irqrestore(&s->lock, flags);
1122 if (avail <= 0) {
1123 if (file->f_flags & O_NONBLOCK) {
1124 if (!ret)
1125 ret = -EAGAIN;
1126 goto out;
1127 }
1128 up(&s->sem);
1129 schedule();
1130 if (signal_pending(current)) {
1131 if (!ret)
1132 ret = -ERESTARTSYS;
1133 goto out2;
1134 }
1135 down(&s->sem);
1136 }
1137 } while (avail <= 0);
1138
1139 // copy from nextOut to user
1140 if ((cnt = copy_dmabuf_user(db, buffer,
1141 count > avail ?
1142 avail : count, 1)) < 0) {
1143 if (!ret)
1144 ret = -EFAULT;
1145 goto out;
1146 }
1147
1148 spin_lock_irqsave(&s->lock, flags);
1149 db->count -= cnt;
1150 db->nextOut += cnt;
1151 if (db->nextOut >= db->rawbuf + db->dmasize)
1152 db->nextOut -= db->dmasize;
1153 spin_unlock_irqrestore(&s->lock, flags);
1154
1155 count -= cnt;
1156 usercnt = cnt / db->cnt_factor;
1157 buffer += usercnt;
1158 ret += usercnt;
1159 } // while (count > 0)
1160
1161out:
1162 up(&s->sem);
1163out2:
1164 remove_wait_queue(&db->wait, &wait);
1165 set_current_state(TASK_RUNNING);
1166 return ret;
1167}
1168
1169static ssize_t au1000_write(struct file *file, const char *buffer,
1170 size_t count, loff_t * ppos)
1171{
1172 struct au1000_state *s = (struct au1000_state *)file->private_data;
1173 struct dmabuf *db = &s->dma_dac;
1174 DECLARE_WAITQUEUE(wait, current);
1175 ssize_t ret = 0;
1176 unsigned long flags;
1177 int cnt, usercnt, avail;
1178
1179#ifdef AU1000_VERBOSE_DEBUG
1180 dbg("write: count=%d", count);
1181#endif
1182
1183 if (db->mapped)
1184 return -ENXIO;
1185 if (!access_ok(VERIFY_READ, buffer, count))
1186 return -EFAULT;
1187
1188 count *= db->cnt_factor;
1189
1190 down(&s->sem);
1191 add_wait_queue(&db->wait, &wait);
1192
1193 while (count > 0) {
1194 // wait for space in playback buffer
1195 do {
1196 spin_lock_irqsave(&s->lock, flags);
1197 avail = (int) db->dmasize - db->count;
1198 if (avail <= 0)
1199 __set_current_state(TASK_INTERRUPTIBLE);
1200 spin_unlock_irqrestore(&s->lock, flags);
1201 if (avail <= 0) {
1202 if (file->f_flags & O_NONBLOCK) {
1203 if (!ret)
1204 ret = -EAGAIN;
1205 goto out;
1206 }
1207 up(&s->sem);
1208 schedule();
1209 if (signal_pending(current)) {
1210 if (!ret)
1211 ret = -ERESTARTSYS;
1212 goto out2;
1213 }
1214 down(&s->sem);
1215 }
1216 } while (avail <= 0);
1217
1218 // copy from user to nextIn
1219 if ((cnt = copy_dmabuf_user(db, (char *) buffer,
1220 count > avail ?
1221 avail : count, 0)) < 0) {
1222 if (!ret)
1223 ret = -EFAULT;
1224 goto out;
1225 }
1226
1227 spin_lock_irqsave(&s->lock, flags);
1228 db->count += cnt;
1229 db->nextIn += cnt;
1230 if (db->nextIn >= db->rawbuf + db->dmasize)
1231 db->nextIn -= db->dmasize;
1232 spin_unlock_irqrestore(&s->lock, flags);
1233 if (db->stopped)
1234 start_dac(s);
1235
1236 count -= cnt;
1237 usercnt = cnt / db->cnt_factor;
1238 buffer += usercnt;
1239 ret += usercnt;
1240 } // while (count > 0)
1241
1242out:
1243 up(&s->sem);
1244out2:
1245 remove_wait_queue(&db->wait, &wait);
1246 set_current_state(TASK_RUNNING);
1247 return ret;
1248}
1249
1250
1251/* No kernel lock - we have our own spinlock */
1252static unsigned int au1000_poll(struct file *file,
1253 struct poll_table_struct *wait)
1254{
1255 struct au1000_state *s = (struct au1000_state *)file->private_data;
1256 unsigned long flags;
1257 unsigned int mask = 0;
1258
1259 if (file->f_mode & FMODE_WRITE) {
1260 if (!s->dma_dac.ready)
1261 return 0;
1262 poll_wait(file, &s->dma_dac.wait, wait);
1263 }
1264 if (file->f_mode & FMODE_READ) {
1265 if (!s->dma_adc.ready)
1266 return 0;
1267 poll_wait(file, &s->dma_adc.wait, wait);
1268 }
1269
1270 spin_lock_irqsave(&s->lock, flags);
1271
1272 if (file->f_mode & FMODE_READ) {
1273 if (s->dma_adc.count >= (signed)s->dma_adc.dma_fragsize)
1274 mask |= POLLIN | POLLRDNORM;
1275 }
1276 if (file->f_mode & FMODE_WRITE) {
1277 if (s->dma_dac.mapped) {
1278 if (s->dma_dac.count >=
1279 (signed)s->dma_dac.dma_fragsize)
1280 mask |= POLLOUT | POLLWRNORM;
1281 } else {
1282 if ((signed) s->dma_dac.dmasize >=
1283 s->dma_dac.count + (signed)s->dma_dac.dma_fragsize)
1284 mask |= POLLOUT | POLLWRNORM;
1285 }
1286 }
1287 spin_unlock_irqrestore(&s->lock, flags);
1288 return mask;
1289}
1290
1291static int au1000_mmap(struct file *file, struct vm_area_struct *vma)
1292{
1293 struct au1000_state *s = (struct au1000_state *)file->private_data;
1294 struct dmabuf *db;
1295 unsigned long size;
1296 int ret = 0;
1297
1298 dbg(__FUNCTION__);
1299
1300 lock_kernel();
1301 down(&s->sem);
1302 if (vma->vm_flags & VM_WRITE)
1303 db = &s->dma_dac;
1304 else if (vma->vm_flags & VM_READ)
1305 db = &s->dma_adc;
1306 else {
1307 ret = -EINVAL;
1308 goto out;
1309 }
1310 if (vma->vm_pgoff != 0) {
1311 ret = -EINVAL;
1312 goto out;
1313 }
1314 size = vma->vm_end - vma->vm_start;
1315 if (size > (PAGE_SIZE << db->buforder)) {
1316 ret = -EINVAL;
1317 goto out;
1318 }
1319 if (remap_pfn_range(vma, vma->vm_start, virt_to_phys(db->rawbuf),
1320 size, vma->vm_page_prot)) {
1321 ret = -EAGAIN;
1322 goto out;
1323 }
1324 vma->vm_flags &= ~VM_IO;
1325 db->mapped = 1;
1326out:
1327 up(&s->sem);
1328 unlock_kernel();
1329 return ret;
1330}
1331
1332
1333#ifdef AU1000_VERBOSE_DEBUG
1334static struct ioctl_str_t {
1335 unsigned int cmd;
1336 const char *str;
1337} ioctl_str[] = {
1338 {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"},
1339 {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"},
1340 {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"},
1341 {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"},
1342 {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"},
1343 {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"},
1344 {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"},
1345 {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"},
1346 {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"},
1347 {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"},
1348 {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"},
1349 {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"},
1350 {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"},
1351 {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"},
1352 {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"},
1353 {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"},
1354 {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"},
1355 {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"},
1356 {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"},
1357 {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"},
1358 {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"},
1359 {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"},
1360 {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"},
1361 {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"},
1362 {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"},
1363 {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"},
1364 {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"},
1365 {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"},
1366 {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"},
1367 {OSS_GETVERSION, "OSS_GETVERSION"},
1368 {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"},
1369 {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"},
1370 {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"},
1371 {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"}
1372};
1373#endif
1374
1375// Need to hold a spin-lock before calling this!
1376static int dma_count_done(struct dmabuf *db)
1377{
1378 if (db->stopped)
1379 return 0;
1380
1381 return db->dma_fragsize - get_dma_residue(db->dmanr);
1382}
1383
1384
1385static int au1000_ioctl(struct inode *inode, struct file *file,
1386 unsigned int cmd, unsigned long arg)
1387{
1388 struct au1000_state *s = (struct au1000_state *)file->private_data;
1389 unsigned long flags;
1390 audio_buf_info abinfo;
1391 count_info cinfo;
1392 int count;
1393 int val, mapped, ret, diff;
1394
1395 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1396 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1397
1398#ifdef AU1000_VERBOSE_DEBUG
1399 for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
1400 if (ioctl_str[count].cmd == cmd)
1401 break;
1402 }
1403 if (count < sizeof(ioctl_str) / sizeof(ioctl_str[0]))
1404 dbg("ioctl %s, arg=0x%lx", ioctl_str[count].str, arg);
1405 else
1406 dbg("ioctl 0x%x unknown, arg=0x%lx", cmd, arg);
1407#endif
1408
1409 switch (cmd) {
1410 case OSS_GETVERSION:
1411 return put_user(SOUND_VERSION, (int *) arg);
1412
1413 case SNDCTL_DSP_SYNC:
1414 if (file->f_mode & FMODE_WRITE)
1415 return drain_dac(s, file->f_flags & O_NONBLOCK);
1416 return 0;
1417
1418 case SNDCTL_DSP_SETDUPLEX:
1419 return 0;
1420
1421 case SNDCTL_DSP_GETCAPS:
1422 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
1423 DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg);
1424
1425 case SNDCTL_DSP_RESET:
1426 if (file->f_mode & FMODE_WRITE) {
1427 stop_dac(s);
1428 synchronize_irq();
1429 s->dma_dac.count = s->dma_dac.total_bytes = 0;
1430 s->dma_dac.nextIn = s->dma_dac.nextOut =
1431 s->dma_dac.rawbuf;
1432 }
1433 if (file->f_mode & FMODE_READ) {
1434 stop_adc(s);
1435 synchronize_irq();
1436 s->dma_adc.count = s->dma_adc.total_bytes = 0;
1437 s->dma_adc.nextIn = s->dma_adc.nextOut =
1438 s->dma_adc.rawbuf;
1439 }
1440 return 0;
1441
1442 case SNDCTL_DSP_SPEED:
1443 if (get_user(val, (int *) arg))
1444 return -EFAULT;
1445 if (val >= 0) {
1446 if (file->f_mode & FMODE_READ) {
1447 stop_adc(s);
1448 set_adc_rate(s, val);
1449 }
1450 if (file->f_mode & FMODE_WRITE) {
1451 stop_dac(s);
1452 set_dac_rate(s, val);
1453 }
1454 if (s->open_mode & FMODE_READ)
1455 if ((ret = prog_dmabuf_adc(s)))
1456 return ret;
1457 if (s->open_mode & FMODE_WRITE)
1458 if ((ret = prog_dmabuf_dac(s)))
1459 return ret;
1460 }
1461 return put_user((file->f_mode & FMODE_READ) ?
1462 s->dma_adc.sample_rate :
1463 s->dma_dac.sample_rate,
1464 (int *)arg);
1465
1466 case SNDCTL_DSP_STEREO:
1467 if (get_user(val, (int *) arg))
1468 return -EFAULT;
1469 if (file->f_mode & FMODE_READ) {
1470 stop_adc(s);
1471 s->dma_adc.num_channels = val ? 2 : 1;
1472 if ((ret = prog_dmabuf_adc(s)))
1473 return ret;
1474 }
1475 if (file->f_mode & FMODE_WRITE) {
1476 stop_dac(s);
1477 s->dma_dac.num_channels = val ? 2 : 1;
1478 if (s->codec_ext_caps & AC97_EXT_DACS) {
1479 // disable surround and center/lfe in AC'97
1480 u16 ext_stat = rdcodec(&s->codec,
1481 AC97_EXTENDED_STATUS);
1482 wrcodec(&s->codec, AC97_EXTENDED_STATUS,
1483 ext_stat | (AC97_EXTSTAT_PRI |
1484 AC97_EXTSTAT_PRJ |
1485 AC97_EXTSTAT_PRK));
1486 }
1487 if ((ret = prog_dmabuf_dac(s)))
1488 return ret;
1489 }
1490 return 0;
1491
1492 case SNDCTL_DSP_CHANNELS:
1493 if (get_user(val, (int *) arg))
1494 return -EFAULT;
1495 if (val != 0) {
1496 if (file->f_mode & FMODE_READ) {
1497 if (val < 0 || val > 2)
1498 return -EINVAL;
1499 stop_adc(s);
1500 s->dma_adc.num_channels = val;
1501 if ((ret = prog_dmabuf_adc(s)))
1502 return ret;
1503 }
1504 if (file->f_mode & FMODE_WRITE) {
1505 switch (val) {
1506 case 1:
1507 case 2:
1508 break;
1509 case 3:
1510 case 5:
1511 return -EINVAL;
1512 case 4:
1513 if (!(s->codec_ext_caps &
1514 AC97_EXTID_SDAC))
1515 return -EINVAL;
1516 break;
1517 case 6:
1518 if ((s->codec_ext_caps &
1519 AC97_EXT_DACS) != AC97_EXT_DACS)
1520 return -EINVAL;
1521 break;
1522 default:
1523 return -EINVAL;
1524 }
1525
1526 stop_dac(s);
1527 if (val <= 2 &&
1528 (s->codec_ext_caps & AC97_EXT_DACS)) {
1529 // disable surround and center/lfe
1530 // channels in AC'97
1531 u16 ext_stat =
1532 rdcodec(&s->codec,
1533 AC97_EXTENDED_STATUS);
1534 wrcodec(&s->codec,
1535 AC97_EXTENDED_STATUS,
1536 ext_stat | (AC97_EXTSTAT_PRI |
1537 AC97_EXTSTAT_PRJ |
1538 AC97_EXTSTAT_PRK));
1539 } else if (val >= 4) {
1540 // enable surround, center/lfe
1541 // channels in AC'97
1542 u16 ext_stat =
1543 rdcodec(&s->codec,
1544 AC97_EXTENDED_STATUS);
1545 ext_stat &= ~AC97_EXTSTAT_PRJ;
1546 if (val == 6)
1547 ext_stat &=
1548 ~(AC97_EXTSTAT_PRI |
1549 AC97_EXTSTAT_PRK);
1550 wrcodec(&s->codec,
1551 AC97_EXTENDED_STATUS,
1552 ext_stat);
1553 }
1554
1555 s->dma_dac.num_channels = val;
1556 if ((ret = prog_dmabuf_dac(s)))
1557 return ret;
1558 }
1559 }
1560 return put_user(val, (int *) arg);
1561
1562 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1563 return put_user(AFMT_S16_LE | AFMT_U8, (int *) arg);
1564
1565 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */
1566 if (get_user(val, (int *) arg))
1567 return -EFAULT;
1568 if (val != AFMT_QUERY) {
1569 if (file->f_mode & FMODE_READ) {
1570 stop_adc(s);
1571 if (val == AFMT_S16_LE)
1572 s->dma_adc.sample_size = 16;
1573 else {
1574 val = AFMT_U8;
1575 s->dma_adc.sample_size = 8;
1576 }
1577 if ((ret = prog_dmabuf_adc(s)))
1578 return ret;
1579 }
1580 if (file->f_mode & FMODE_WRITE) {
1581 stop_dac(s);
1582 if (val == AFMT_S16_LE)
1583 s->dma_dac.sample_size = 16;
1584 else {
1585 val = AFMT_U8;
1586 s->dma_dac.sample_size = 8;
1587 }
1588 if ((ret = prog_dmabuf_dac(s)))
1589 return ret;
1590 }
1591 } else {
1592 if (file->f_mode & FMODE_READ)
1593 val = (s->dma_adc.sample_size == 16) ?
1594 AFMT_S16_LE : AFMT_U8;
1595 else
1596 val = (s->dma_dac.sample_size == 16) ?
1597 AFMT_S16_LE : AFMT_U8;
1598 }
1599 return put_user(val, (int *) arg);
1600
1601 case SNDCTL_DSP_POST:
1602 return 0;
1603
1604 case SNDCTL_DSP_GETTRIGGER:
1605 val = 0;
1606 spin_lock_irqsave(&s->lock, flags);
1607 if (file->f_mode & FMODE_READ && !s->dma_adc.stopped)
1608 val |= PCM_ENABLE_INPUT;
1609 if (file->f_mode & FMODE_WRITE && !s->dma_dac.stopped)
1610 val |= PCM_ENABLE_OUTPUT;
1611 spin_unlock_irqrestore(&s->lock, flags);
1612 return put_user(val, (int *) arg);
1613
1614 case SNDCTL_DSP_SETTRIGGER:
1615 if (get_user(val, (int *) arg))
1616 return -EFAULT;
1617 if (file->f_mode & FMODE_READ) {
1618 if (val & PCM_ENABLE_INPUT)
1619 start_adc(s);
1620 else
1621 stop_adc(s);
1622 }
1623 if (file->f_mode & FMODE_WRITE) {
1624 if (val & PCM_ENABLE_OUTPUT)
1625 start_dac(s);
1626 else
1627 stop_dac(s);
1628 }
1629 return 0;
1630
1631 case SNDCTL_DSP_GETOSPACE:
1632 if (!(file->f_mode & FMODE_WRITE))
1633 return -EINVAL;
1634 abinfo.fragsize = s->dma_dac.fragsize;
1635 spin_lock_irqsave(&s->lock, flags);
1636 count = s->dma_dac.count;
1637 count -= dma_count_done(&s->dma_dac);
1638 spin_unlock_irqrestore(&s->lock, flags);
1639 if (count < 0)
1640 count = 0;
1641 abinfo.bytes = (s->dma_dac.dmasize - count) /
1642 s->dma_dac.cnt_factor;
1643 abinfo.fragstotal = s->dma_dac.numfrag;
1644 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
1645#ifdef AU1000_VERBOSE_DEBUG
1646 dbg("bytes=%d, fragments=%d", abinfo.bytes, abinfo.fragments);
1647#endif
1648 return copy_to_user((void *) arg, &abinfo,
1649 sizeof(abinfo)) ? -EFAULT : 0;
1650
1651 case SNDCTL_DSP_GETISPACE:
1652 if (!(file->f_mode & FMODE_READ))
1653 return -EINVAL;
1654 abinfo.fragsize = s->dma_adc.fragsize;
1655 spin_lock_irqsave(&s->lock, flags);
1656 count = s->dma_adc.count;
1657 count += dma_count_done(&s->dma_adc);
1658 spin_unlock_irqrestore(&s->lock, flags);
1659 if (count < 0)
1660 count = 0;
1661 abinfo.bytes = count / s->dma_adc.cnt_factor;
1662 abinfo.fragstotal = s->dma_adc.numfrag;
1663 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1664 return copy_to_user((void *) arg, &abinfo,
1665 sizeof(abinfo)) ? -EFAULT : 0;
1666
1667 case SNDCTL_DSP_NONBLOCK:
1668 file->f_flags |= O_NONBLOCK;
1669 return 0;
1670
1671 case SNDCTL_DSP_GETODELAY:
1672 if (!(file->f_mode & FMODE_WRITE))
1673 return -EINVAL;
1674 spin_lock_irqsave(&s->lock, flags);
1675 count = s->dma_dac.count;
1676 count -= dma_count_done(&s->dma_dac);
1677 spin_unlock_irqrestore(&s->lock, flags);
1678 if (count < 0)
1679 count = 0;
1680 count /= s->dma_dac.cnt_factor;
1681 return put_user(count, (int *) arg);
1682
1683 case SNDCTL_DSP_GETIPTR:
1684 if (!(file->f_mode & FMODE_READ))
1685 return -EINVAL;
1686 spin_lock_irqsave(&s->lock, flags);
1687 cinfo.bytes = s->dma_adc.total_bytes;
1688 count = s->dma_adc.count;
1689 if (!s->dma_adc.stopped) {
1690 diff = dma_count_done(&s->dma_adc);
1691 count += diff;
1692 cinfo.bytes += diff;
1693 cinfo.ptr = virt_to_phys(s->dma_adc.nextIn) + diff -
1694 s->dma_adc.dmaaddr;
1695 } else
1696 cinfo.ptr = virt_to_phys(s->dma_adc.nextIn) -
1697 s->dma_adc.dmaaddr;
1698 if (s->dma_adc.mapped)
1699 s->dma_adc.count &= (s->dma_adc.dma_fragsize-1);
1700 spin_unlock_irqrestore(&s->lock, flags);
1701 if (count < 0)
1702 count = 0;
1703 cinfo.blocks = count >> s->dma_adc.fragshift;
1704 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
1705
1706 case SNDCTL_DSP_GETOPTR:
1707 if (!(file->f_mode & FMODE_READ))
1708 return -EINVAL;
1709 spin_lock_irqsave(&s->lock, flags);
1710 cinfo.bytes = s->dma_dac.total_bytes;
1711 count = s->dma_dac.count;
1712 if (!s->dma_dac.stopped) {
1713 diff = dma_count_done(&s->dma_dac);
1714 count -= diff;
1715 cinfo.bytes += diff;
1716 cinfo.ptr = virt_to_phys(s->dma_dac.nextOut) + diff -
1717 s->dma_dac.dmaaddr;
1718 } else
1719 cinfo.ptr = virt_to_phys(s->dma_dac.nextOut) -
1720 s->dma_dac.dmaaddr;
1721 if (s->dma_dac.mapped)
1722 s->dma_dac.count &= (s->dma_dac.dma_fragsize-1);
1723 spin_unlock_irqrestore(&s->lock, flags);
1724 if (count < 0)
1725 count = 0;
1726 cinfo.blocks = count >> s->dma_dac.fragshift;
1727 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
1728
1729 case SNDCTL_DSP_GETBLKSIZE:
1730 if (file->f_mode & FMODE_WRITE)
1731 return put_user(s->dma_dac.fragsize, (int *) arg);
1732 else
1733 return put_user(s->dma_adc.fragsize, (int *) arg);
1734
1735 case SNDCTL_DSP_SETFRAGMENT:
1736 if (get_user(val, (int *) arg))
1737 return -EFAULT;
1738 if (file->f_mode & FMODE_READ) {
1739 stop_adc(s);
1740 s->dma_adc.ossfragshift = val & 0xffff;
1741 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1742 if (s->dma_adc.ossfragshift < 4)
1743 s->dma_adc.ossfragshift = 4;
1744 if (s->dma_adc.ossfragshift > 15)
1745 s->dma_adc.ossfragshift = 15;
1746 if (s->dma_adc.ossmaxfrags < 4)
1747 s->dma_adc.ossmaxfrags = 4;
1748 if ((ret = prog_dmabuf_adc(s)))
1749 return ret;
1750 }
1751 if (file->f_mode & FMODE_WRITE) {
1752 stop_dac(s);
1753 s->dma_dac.ossfragshift = val & 0xffff;
1754 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
1755 if (s->dma_dac.ossfragshift < 4)
1756 s->dma_dac.ossfragshift = 4;
1757 if (s->dma_dac.ossfragshift > 15)
1758 s->dma_dac.ossfragshift = 15;
1759 if (s->dma_dac.ossmaxfrags < 4)
1760 s->dma_dac.ossmaxfrags = 4;
1761 if ((ret = prog_dmabuf_dac(s)))
1762 return ret;
1763 }
1764 return 0;
1765
1766 case SNDCTL_DSP_SUBDIVIDE:
1767 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1768 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
1769 return -EINVAL;
1770 if (get_user(val, (int *) arg))
1771 return -EFAULT;
1772 if (val != 1 && val != 2 && val != 4)
1773 return -EINVAL;
1774 if (file->f_mode & FMODE_READ) {
1775 stop_adc(s);
1776 s->dma_adc.subdivision = val;
1777 if ((ret = prog_dmabuf_adc(s)))
1778 return ret;
1779 }
1780 if (file->f_mode & FMODE_WRITE) {
1781 stop_dac(s);
1782 s->dma_dac.subdivision = val;
1783 if ((ret = prog_dmabuf_dac(s)))
1784 return ret;
1785 }
1786 return 0;
1787
1788 case SOUND_PCM_READ_RATE:
1789 return put_user((file->f_mode & FMODE_READ) ?
1790 s->dma_adc.sample_rate :
1791 s->dma_dac.sample_rate,
1792 (int *)arg);
1793
1794 case SOUND_PCM_READ_CHANNELS:
1795 if (file->f_mode & FMODE_READ)
1796 return put_user(s->dma_adc.num_channels, (int *)arg);
1797 else
1798 return put_user(s->dma_dac.num_channels, (int *)arg);
1799
1800 case SOUND_PCM_READ_BITS:
1801 if (file->f_mode & FMODE_READ)
1802 return put_user(s->dma_adc.sample_size, (int *)arg);
1803 else
1804 return put_user(s->dma_dac.sample_size, (int *)arg);
1805
1806 case SOUND_PCM_WRITE_FILTER:
1807 case SNDCTL_DSP_SETSYNCRO:
1808 case SOUND_PCM_READ_FILTER:
1809 return -EINVAL;
1810 }
1811
1812 return mixdev_ioctl(&s->codec, cmd, arg);
1813}
1814
1815
1816static int au1000_open(struct inode *inode, struct file *file)
1817{
1818 int minor = iminor(inode);
1819 DECLARE_WAITQUEUE(wait, current);
1820 struct au1000_state *s = &au1000_state;
1821 int ret;
1822
1823#ifdef AU1000_VERBOSE_DEBUG
1824 if (file->f_flags & O_NONBLOCK)
1825 dbg("%s: non-blocking", __FUNCTION__);
1826 else
1827 dbg("%s: blocking", __FUNCTION__);
1828#endif
1829
1830 file->private_data = s;
1831 /* wait for device to become free */
1832 down(&s->open_sem);
1833 while (s->open_mode & file->f_mode) {
1834 if (file->f_flags & O_NONBLOCK) {
1835 up(&s->open_sem);
1836 return -EBUSY;
1837 }
1838 add_wait_queue(&s->open_wait, &wait);
1839 __set_current_state(TASK_INTERRUPTIBLE);
1840 up(&s->open_sem);
1841 schedule();
1842 remove_wait_queue(&s->open_wait, &wait);
1843 set_current_state(TASK_RUNNING);
1844 if (signal_pending(current))
1845 return -ERESTARTSYS;
1846 down(&s->open_sem);
1847 }
1848
1849 stop_dac(s);
1850 stop_adc(s);
1851
1852 if (file->f_mode & FMODE_READ) {
1853 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
1854 s->dma_adc.subdivision = s->dma_adc.total_bytes = 0;
1855 s->dma_adc.num_channels = 1;
1856 s->dma_adc.sample_size = 8;
1857 set_adc_rate(s, 8000);
1858 if ((minor & 0xf) == SND_DEV_DSP16)
1859 s->dma_adc.sample_size = 16;
1860 }
1861
1862 if (file->f_mode & FMODE_WRITE) {
1863 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
1864 s->dma_dac.subdivision = s->dma_dac.total_bytes = 0;
1865 s->dma_dac.num_channels = 1;
1866 s->dma_dac.sample_size = 8;
1867 set_dac_rate(s, 8000);
1868 if ((minor & 0xf) == SND_DEV_DSP16)
1869 s->dma_dac.sample_size = 16;
1870 }
1871
1872 if (file->f_mode & FMODE_READ) {
1873 if ((ret = prog_dmabuf_adc(s)))
1874 return ret;
1875 }
1876 if (file->f_mode & FMODE_WRITE) {
1877 if ((ret = prog_dmabuf_dac(s)))
1878 return ret;
1879 }
1880
1881 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1882 up(&s->open_sem);
1883 init_MUTEX(&s->sem);
1884 return nonseekable_open(inode, file);
1885}
1886
1887static int au1000_release(struct inode *inode, struct file *file)
1888{
1889 struct au1000_state *s = (struct au1000_state *)file->private_data;
1890
1891 lock_kernel();
1892
1893 if (file->f_mode & FMODE_WRITE) {
1894 unlock_kernel();
1895 drain_dac(s, file->f_flags & O_NONBLOCK);
1896 lock_kernel();
1897 }
1898
1899 down(&s->open_sem);
1900 if (file->f_mode & FMODE_WRITE) {
1901 stop_dac(s);
1902 dealloc_dmabuf(s, &s->dma_dac);
1903 }
1904 if (file->f_mode & FMODE_READ) {
1905 stop_adc(s);
1906 dealloc_dmabuf(s, &s->dma_adc);
1907 }
1908 s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
1909 up(&s->open_sem);
1910 wake_up(&s->open_wait);
1911 unlock_kernel();
1912 return 0;
1913}
1914
1915static /*const */ struct file_operations au1000_audio_fops = {
1916 .owner = THIS_MODULE,
1917 .llseek = au1000_llseek,
1918 .read = au1000_read,
1919 .write = au1000_write,
1920 .poll = au1000_poll,
1921 .ioctl = au1000_ioctl,
1922 .mmap = au1000_mmap,
1923 .open = au1000_open,
1924 .release = au1000_release,
1925};
1926
1927
1928/* --------------------------------------------------------------------- */
1929
1930
1931/* --------------------------------------------------------------------- */
1932
1933/*
1934 * for debugging purposes, we'll create a proc device that dumps the
1935 * CODEC chipstate
1936 */
1937
1938#ifdef AU1000_DEBUG
1939static int proc_au1000_dump(char *buf, char **start, off_t fpos,
1940 int length, int *eof, void *data)
1941{
1942 struct au1000_state *s = &au1000_state;
1943 int cnt, len = 0;
1944
1945 /* print out header */
1946 len += sprintf(buf + len, "\n\t\tAU1000 Audio Debug\n\n");
1947
1948 // print out digital controller state
1949 len += sprintf(buf + len, "AU1000 Audio Controller registers\n");
1950 len += sprintf(buf + len, "---------------------------------\n");
1951 len += sprintf (buf + len, "AC97C_CONFIG = %08x\n",
1952 au_readl(AC97C_CONFIG));
1953 len += sprintf (buf + len, "AC97C_STATUS = %08x\n",
1954 au_readl(AC97C_STATUS));
1955 len += sprintf (buf + len, "AC97C_CNTRL = %08x\n",
1956 au_readl(AC97C_CNTRL));
1957
1958 /* print out CODEC state */
1959 len += sprintf(buf + len, "\nAC97 CODEC registers\n");
1960 len += sprintf(buf + len, "----------------------\n");
1961 for (cnt = 0; cnt <= 0x7e; cnt += 2)
1962 len += sprintf(buf + len, "reg %02x = %04x\n",
1963 cnt, rdcodec(&s->codec, cnt));
1964
1965 if (fpos >= len) {
1966 *start = buf;
1967 *eof = 1;
1968 return 0;
1969 }
1970 *start = buf + fpos;
1971 if ((len -= fpos) > length)
1972 return length;
1973 *eof = 1;
1974 return len;
1975
1976}
1977#endif /* AU1000_DEBUG */
1978
1979/* --------------------------------------------------------------------- */
1980
1981MODULE_AUTHOR("Monta Vista Software, stevel@mvista.com");
1982MODULE_DESCRIPTION("Au1000 Audio Driver");
1983
1984/* --------------------------------------------------------------------- */
1985
1986static int __devinit au1000_probe(void)
1987{
1988 struct au1000_state *s = &au1000_state;
1989 int val;
1990#ifdef AU1000_DEBUG
1991 char proc_str[80];
1992#endif
1993
1994 memset(s, 0, sizeof(struct au1000_state));
1995
1996 init_waitqueue_head(&s->dma_adc.wait);
1997 init_waitqueue_head(&s->dma_dac.wait);
1998 init_waitqueue_head(&s->open_wait);
1999 init_MUTEX(&s->open_sem);
2000 spin_lock_init(&s->lock);
2001 s->codec.private_data = s;
2002 s->codec.id = 0;
2003 s->codec.codec_read = rdcodec;
2004 s->codec.codec_write = wrcodec;
2005 s->codec.codec_wait = waitcodec;
2006
2007 if (!request_mem_region(CPHYSADDR(AC97C_CONFIG),
2008 0x14, AU1000_MODULE_NAME)) {
2009 err("AC'97 ports in use");
2010 return -1;
2011 }
2012 // Allocate the DMA Channels
2013 if ((s->dma_dac.dmanr = request_au1000_dma(DMA_ID_AC97C_TX,
2014 "audio DAC",
2015 dac_dma_interrupt,
2016 SA_INTERRUPT, s)) < 0) {
2017 err("Can't get DAC DMA");
2018 goto err_dma1;
2019 }
2020 if ((s->dma_adc.dmanr = request_au1000_dma(DMA_ID_AC97C_RX,
2021 "audio ADC",
2022 adc_dma_interrupt,
2023 SA_INTERRUPT, s)) < 0) {
2024 err("Can't get ADC DMA");
2025 goto err_dma2;
2026 }
2027
2028 info("DAC: DMA%d/IRQ%d, ADC: DMA%d/IRQ%d",
2029 s->dma_dac.dmanr, get_dma_done_irq(s->dma_dac.dmanr),
2030 s->dma_adc.dmanr, get_dma_done_irq(s->dma_adc.dmanr));
2031
2032 // enable DMA coherency in read/write DMA channels
2033 set_dma_mode(s->dma_dac.dmanr,
2034 get_dma_mode(s->dma_dac.dmanr) & ~DMA_NC);
2035 set_dma_mode(s->dma_adc.dmanr,
2036 get_dma_mode(s->dma_adc.dmanr) & ~DMA_NC);
2037
2038 /* register devices */
2039
2040 if ((s->dev_audio = register_sound_dsp(&au1000_audio_fops, -1)) < 0)
2041 goto err_dev1;
2042 if ((s->codec.dev_mixer =
2043 register_sound_mixer(&au1000_mixer_fops, -1)) < 0)
2044 goto err_dev2;
2045
2046#ifdef AU1000_DEBUG
2047 /* intialize the debug proc device */
2048 s->ps = create_proc_read_entry(AU1000_MODULE_NAME, 0, NULL,
2049 proc_au1000_dump, NULL);
2050#endif /* AU1000_DEBUG */
2051
2052 // configure pins for AC'97
2053 au_writel(au_readl(SYS_PINFUNC) & ~0x02, SYS_PINFUNC);
2054
2055 // Assert reset for 10msec to the AC'97 controller, and enable clock
2056 au_writel(AC97C_RS | AC97C_CE, AC97C_CNTRL);
2057 au1000_delay(10);
2058 au_writel(AC97C_CE, AC97C_CNTRL);
2059 au1000_delay(10); // wait for clock to stabilize
2060
2061 /* cold reset the AC'97 */
2062 au_writel(AC97C_RESET, AC97C_CONFIG);
2063 au1000_delay(10);
2064 au_writel(0, AC97C_CONFIG);
2065 /* need to delay around 500msec(bleech) to give
2066 some CODECs enough time to wakeup */
2067 au1000_delay(500);
2068
2069 /* warm reset the AC'97 to start the bitclk */
2070 au_writel(AC97C_SG | AC97C_SYNC, AC97C_CONFIG);
2071 udelay(100);
2072 au_writel(0, AC97C_CONFIG);
2073
2074 /* codec init */
2075 if (!ac97_probe_codec(&s->codec))
2076 goto err_dev3;
2077
2078 s->codec_base_caps = rdcodec(&s->codec, AC97_RESET);
2079 s->codec_ext_caps = rdcodec(&s->codec, AC97_EXTENDED_ID);
2080 info("AC'97 Base/Extended ID = %04x/%04x",
2081 s->codec_base_caps, s->codec_ext_caps);
2082
2083 /*
2084 * On the Pb1000, audio playback is on the AUX_OUT
2085 * channel (which defaults to LNLVL_OUT in AC'97
2086 * rev 2.2) so make sure this channel is listed
2087 * as supported (soundcard.h calls this channel
2088 * ALTPCM). ac97_codec.c does not handle detection
2089 * of this channel correctly.
2090 */
2091 s->codec.supported_mixers |= SOUND_MASK_ALTPCM;
2092 /*
2093 * Now set AUX_OUT's default volume.
2094 */
2095 val = 0x4343;
2096 mixdev_ioctl(&s->codec, SOUND_MIXER_WRITE_ALTPCM,
2097 (unsigned long) &val);
2098
2099 if (!(s->codec_ext_caps & AC97_EXTID_VRA)) {
2100 // codec does not support VRA
2101 s->no_vra = 1;
2102 } else if (!vra) {
2103 // Boot option says disable VRA
2104 u16 ac97_extstat = rdcodec(&s->codec, AC97_EXTENDED_STATUS);
2105 wrcodec(&s->codec, AC97_EXTENDED_STATUS,
2106 ac97_extstat & ~AC97_EXTSTAT_VRA);
2107 s->no_vra = 1;
2108 }
2109 if (s->no_vra)
2110 info("no VRA, interpolating and decimating");
2111
2112 /* set mic to be the recording source */
2113 val = SOUND_MASK_MIC;
2114 mixdev_ioctl(&s->codec, SOUND_MIXER_WRITE_RECSRC,
2115 (unsigned long) &val);
2116
2117#ifdef AU1000_DEBUG
2118 sprintf(proc_str, "driver/%s/%d/ac97", AU1000_MODULE_NAME,
2119 s->codec.id);
2120 s->ac97_ps = create_proc_read_entry (proc_str, 0, NULL,
2121 ac97_read_proc, &s->codec);
2122#endif
2123
2124#ifdef CONFIG_MIPS_XXS1500
2125 /* deassert eapd */
2126 wrcodec(&s->codec, AC97_POWER_CONTROL,
2127 rdcodec(&s->codec, AC97_POWER_CONTROL) & ~0x8000);
2128 /* mute a number of signals which seem to be causing problems
2129 * if not muted.
2130 */
2131 wrcodec(&s->codec, AC97_PCBEEP_VOL, 0x8000);
2132 wrcodec(&s->codec, AC97_PHONE_VOL, 0x8008);
2133 wrcodec(&s->codec, AC97_MIC_VOL, 0x8008);
2134 wrcodec(&s->codec, AC97_LINEIN_VOL, 0x8808);
2135 wrcodec(&s->codec, AC97_CD_VOL, 0x8808);
2136 wrcodec(&s->codec, AC97_VIDEO_VOL, 0x8808);
2137 wrcodec(&s->codec, AC97_AUX_VOL, 0x8808);
2138 wrcodec(&s->codec, AC97_PCMOUT_VOL, 0x0808);
2139 wrcodec(&s->codec, AC97_GENERAL_PURPOSE, 0x2000);
2140#endif
2141
2142 return 0;
2143
2144 err_dev3:
2145 unregister_sound_mixer(s->codec.dev_mixer);
2146 err_dev2:
2147 unregister_sound_dsp(s->dev_audio);
2148 err_dev1:
2149 free_au1000_dma(s->dma_adc.dmanr);
2150 err_dma2:
2151 free_au1000_dma(s->dma_dac.dmanr);
2152 err_dma1:
2153 release_mem_region(CPHYSADDR(AC97C_CONFIG), 0x14);
2154 return -1;
2155}
2156
2157static void au1000_remove(void)
2158{
2159 struct au1000_state *s = &au1000_state;
2160
2161 if (!s)
2162 return;
2163#ifdef AU1000_DEBUG
2164 if (s->ps)
2165 remove_proc_entry(AU1000_MODULE_NAME, NULL);
2166#endif /* AU1000_DEBUG */
2167 synchronize_irq();
2168 free_au1000_dma(s->dma_adc.dmanr);
2169 free_au1000_dma(s->dma_dac.dmanr);
2170 release_mem_region(CPHYSADDR(AC97C_CONFIG), 0x14);
2171 unregister_sound_dsp(s->dev_audio);
2172 unregister_sound_mixer(s->codec.dev_mixer);
2173}
2174
2175static int __init init_au1000(void)
2176{
2177 info("stevel@mvista.com, built " __TIME__ " on " __DATE__);
2178 return au1000_probe();
2179}
2180
2181static void __exit cleanup_au1000(void)
2182{
2183 info("unloading");
2184 au1000_remove();
2185}
2186
2187module_init(init_au1000);
2188module_exit(cleanup_au1000);
2189
2190/* --------------------------------------------------------------------- */
2191
2192#ifndef MODULE
2193
2194static int __init au1000_setup(char *options)
2195{
2196 char *this_opt;
2197
2198 if (!options || !*options)
2199 return 0;
2200
2201 while ((this_opt = strsep(&options, ","))) {
2202 if (!*this_opt)
2203 continue;
2204 if (!strncmp(this_opt, "vra", 3)) {
2205 vra = 1;
2206 }
2207 }
2208
2209 return 1;
2210}
2211
2212__setup("au1000_audio=", au1000_setup);
2213
2214#endif /* MODULE */
diff --git a/sound/oss/au1550_ac97.c b/sound/oss/au1550_ac97.c
new file mode 100644
index 000000000000..a78e48d412d2
--- /dev/null
+++ b/sound/oss/au1550_ac97.c
@@ -0,0 +1,2119 @@
1/*
2 * au1550_ac97.c -- Sound driver for Alchemy Au1550 MIPS Internet Edge
3 * Processor.
4 *
5 * Copyright 2004 Embedded Edge, LLC
6 * dan@embeddededge.com
7 *
8 * Mostly copied from the au1000.c driver and some from the
9 * PowerMac dbdma driver.
10 * We assume the processor can do memory coherent DMA.
11 *
12 * Ported to 2.6 by Matt Porter <mporter@kernel.crashing.org>
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 *
34 */
35
36#undef DEBUG
37
38#include <linux/version.h>
39#include <linux/module.h>
40#include <linux/string.h>
41#include <linux/ioport.h>
42#include <linux/sched.h>
43#include <linux/delay.h>
44#include <linux/sound.h>
45#include <linux/slab.h>
46#include <linux/soundcard.h>
47#include <linux/init.h>
48#include <linux/interrupt.h>
49#include <linux/kernel.h>
50#include <linux/poll.h>
51#include <linux/pci.h>
52#include <linux/bitops.h>
53#include <linux/spinlock.h>
54#include <linux/smp_lock.h>
55#include <linux/ac97_codec.h>
56#include <asm/io.h>
57#include <asm/uaccess.h>
58#include <asm/hardirq.h>
59#include <asm/mach-au1x00/au1000.h>
60#include <asm/mach-au1x00/au1xxx_psc.h>
61#include <asm/mach-au1x00/au1xxx_dbdma.h>
62
63#undef OSS_DOCUMENTED_MIXER_SEMANTICS
64
65/* misc stuff */
66#define POLL_COUNT 0x50000
67#define AC97_EXT_DACS (AC97_EXTID_SDAC | AC97_EXTID_CDAC | AC97_EXTID_LDAC)
68
69/* The number of DBDMA ring descriptors to allocate. No sense making
70 * this too large....if you can't keep up with a few you aren't likely
71 * to be able to with lots of them, either.
72 */
73#define NUM_DBDMA_DESCRIPTORS 4
74
75#define err(format, arg...) printk(KERN_ERR format "\n" , ## arg)
76
77/* Boot options
78 * 0 = no VRA, 1 = use VRA if codec supports it
79 */
80static int vra = 1;
81MODULE_PARM(vra, "i");
82MODULE_PARM_DESC(vra, "if 1 use VRA if codec supports it");
83
84static struct au1550_state {
85 /* soundcore stuff */
86 int dev_audio;
87
88 struct ac97_codec *codec;
89 unsigned codec_base_caps; /* AC'97 reg 00h, "Reset Register" */
90 unsigned codec_ext_caps; /* AC'97 reg 28h, "Extended Audio ID" */
91 int no_vra; /* do not use VRA */
92
93 spinlock_t lock;
94 struct semaphore open_sem;
95 struct semaphore sem;
96 mode_t open_mode;
97 wait_queue_head_t open_wait;
98
99 struct dmabuf {
100 u32 dmanr;
101 unsigned sample_rate;
102 unsigned src_factor;
103 unsigned sample_size;
104 int num_channels;
105 int dma_bytes_per_sample;
106 int user_bytes_per_sample;
107 int cnt_factor;
108
109 void *rawbuf;
110 unsigned buforder;
111 unsigned numfrag;
112 unsigned fragshift;
113 void *nextIn;
114 void *nextOut;
115 int count;
116 unsigned total_bytes;
117 unsigned error;
118 wait_queue_head_t wait;
119
120 /* redundant, but makes calculations easier */
121 unsigned fragsize;
122 unsigned dma_fragsize;
123 unsigned dmasize;
124 unsigned dma_qcount;
125
126 /* OSS stuff */
127 unsigned mapped:1;
128 unsigned ready:1;
129 unsigned stopped:1;
130 unsigned ossfragshift;
131 int ossmaxfrags;
132 unsigned subdivision;
133 } dma_dac, dma_adc;
134} au1550_state;
135
136static unsigned
137ld2(unsigned int x)
138{
139 unsigned r = 0;
140
141 if (x >= 0x10000) {
142 x >>= 16;
143 r += 16;
144 }
145 if (x >= 0x100) {
146 x >>= 8;
147 r += 8;
148 }
149 if (x >= 0x10) {
150 x >>= 4;
151 r += 4;
152 }
153 if (x >= 4) {
154 x >>= 2;
155 r += 2;
156 }
157 if (x >= 2)
158 r++;
159 return r;
160}
161
162static void
163au1550_delay(int msec)
164{
165 unsigned long tmo;
166 signed long tmo2;
167
168 if (in_interrupt())
169 return;
170
171 tmo = jiffies + (msec * HZ) / 1000;
172 for (;;) {
173 tmo2 = tmo - jiffies;
174 if (tmo2 <= 0)
175 break;
176 schedule_timeout(tmo2);
177 }
178}
179
180static u16
181rdcodec(struct ac97_codec *codec, u8 addr)
182{
183 struct au1550_state *s = (struct au1550_state *)codec->private_data;
184 unsigned long flags;
185 u32 cmd, val;
186 u16 data;
187 int i;
188
189 spin_lock_irqsave(&s->lock, flags);
190
191 for (i = 0; i < POLL_COUNT; i++) {
192 val = au_readl(PSC_AC97STAT);
193 au_sync();
194 if (!(val & PSC_AC97STAT_CP))
195 break;
196 }
197 if (i == POLL_COUNT)
198 err("rdcodec: codec cmd pending expired!");
199
200 cmd = (u32)PSC_AC97CDC_INDX(addr);
201 cmd |= PSC_AC97CDC_RD; /* read command */
202 au_writel(cmd, PSC_AC97CDC);
203 au_sync();
204
205 /* now wait for the data
206 */
207 for (i = 0; i < POLL_COUNT; i++) {
208 val = au_readl(PSC_AC97STAT);
209 au_sync();
210 if (!(val & PSC_AC97STAT_CP))
211 break;
212 }
213 if (i == POLL_COUNT) {
214 err("rdcodec: read poll expired!");
215 return 0;
216 }
217
218 /* wait for command done?
219 */
220 for (i = 0; i < POLL_COUNT; i++) {
221 val = au_readl(PSC_AC97EVNT);
222 au_sync();
223 if (val & PSC_AC97EVNT_CD)
224 break;
225 }
226 if (i == POLL_COUNT) {
227 err("rdcodec: read cmdwait expired!");
228 return 0;
229 }
230
231 data = au_readl(PSC_AC97CDC) & 0xffff;
232 au_sync();
233
234 /* Clear command done event.
235 */
236 au_writel(PSC_AC97EVNT_CD, PSC_AC97EVNT);
237 au_sync();
238
239 spin_unlock_irqrestore(&s->lock, flags);
240
241 return data;
242}
243
244
245static void
246wrcodec(struct ac97_codec *codec, u8 addr, u16 data)
247{
248 struct au1550_state *s = (struct au1550_state *)codec->private_data;
249 unsigned long flags;
250 u32 cmd, val;
251 int i;
252
253 spin_lock_irqsave(&s->lock, flags);
254
255 for (i = 0; i < POLL_COUNT; i++) {
256 val = au_readl(PSC_AC97STAT);
257 au_sync();
258 if (!(val & PSC_AC97STAT_CP))
259 break;
260 }
261 if (i == POLL_COUNT)
262 err("wrcodec: codec cmd pending expired!");
263
264 cmd = (u32)PSC_AC97CDC_INDX(addr);
265 cmd |= (u32)data;
266 au_writel(cmd, PSC_AC97CDC);
267 au_sync();
268
269 for (i = 0; i < POLL_COUNT; i++) {
270 val = au_readl(PSC_AC97STAT);
271 au_sync();
272 if (!(val & PSC_AC97STAT_CP))
273 break;
274 }
275 if (i == POLL_COUNT)
276 err("wrcodec: codec cmd pending expired!");
277
278 for (i = 0; i < POLL_COUNT; i++) {
279 val = au_readl(PSC_AC97EVNT);
280 au_sync();
281 if (val & PSC_AC97EVNT_CD)
282 break;
283 }
284 if (i == POLL_COUNT)
285 err("wrcodec: read cmdwait expired!");
286
287 /* Clear command done event.
288 */
289 au_writel(PSC_AC97EVNT_CD, PSC_AC97EVNT);
290 au_sync();
291
292 spin_unlock_irqrestore(&s->lock, flags);
293}
294
295static void
296waitcodec(struct ac97_codec *codec)
297{
298 u16 temp;
299 u32 val;
300 int i;
301
302 /* codec_wait is used to wait for a ready state after
303 * an AC97C_RESET.
304 */
305 au1550_delay(10);
306
307 /* first poll the CODEC_READY tag bit
308 */
309 for (i = 0; i < POLL_COUNT; i++) {
310 val = au_readl(PSC_AC97STAT);
311 au_sync();
312 if (val & PSC_AC97STAT_CR)
313 break;
314 }
315 if (i == POLL_COUNT) {
316 err("waitcodec: CODEC_READY poll expired!");
317 return;
318 }
319
320 /* get AC'97 powerdown control/status register
321 */
322 temp = rdcodec(codec, AC97_POWER_CONTROL);
323
324 /* If anything is powered down, power'em up
325 */
326 if (temp & 0x7f00) {
327 /* Power on
328 */
329 wrcodec(codec, AC97_POWER_CONTROL, 0);
330 au1550_delay(100);
331
332 /* Reread
333 */
334 temp = rdcodec(codec, AC97_POWER_CONTROL);
335 }
336
337 /* Check if Codec REF,ANL,DAC,ADC ready
338 */
339 if ((temp & 0x7f0f) != 0x000f)
340 err("codec reg 26 status (0x%x) not ready!!", temp);
341}
342
343/* stop the ADC before calling */
344static void
345set_adc_rate(struct au1550_state *s, unsigned rate)
346{
347 struct dmabuf *adc = &s->dma_adc;
348 struct dmabuf *dac = &s->dma_dac;
349 unsigned adc_rate, dac_rate;
350 u16 ac97_extstat;
351
352 if (s->no_vra) {
353 /* calc SRC factor
354 */
355 adc->src_factor = ((96000 / rate) + 1) >> 1;
356 adc->sample_rate = 48000 / adc->src_factor;
357 return;
358 }
359
360 adc->src_factor = 1;
361
362 ac97_extstat = rdcodec(s->codec, AC97_EXTENDED_STATUS);
363
364 rate = rate > 48000 ? 48000 : rate;
365
366 /* enable VRA
367 */
368 wrcodec(s->codec, AC97_EXTENDED_STATUS,
369 ac97_extstat | AC97_EXTSTAT_VRA);
370
371 /* now write the sample rate
372 */
373 wrcodec(s->codec, AC97_PCM_LR_ADC_RATE, (u16) rate);
374
375 /* read it back for actual supported rate
376 */
377 adc_rate = rdcodec(s->codec, AC97_PCM_LR_ADC_RATE);
378
379 pr_debug("set_adc_rate: set to %d Hz\n", adc_rate);
380
381 /* some codec's don't allow unequal DAC and ADC rates, in which case
382 * writing one rate reg actually changes both.
383 */
384 dac_rate = rdcodec(s->codec, AC97_PCM_FRONT_DAC_RATE);
385 if (dac->num_channels > 2)
386 wrcodec(s->codec, AC97_PCM_SURR_DAC_RATE, dac_rate);
387 if (dac->num_channels > 4)
388 wrcodec(s->codec, AC97_PCM_LFE_DAC_RATE, dac_rate);
389
390 adc->sample_rate = adc_rate;
391 dac->sample_rate = dac_rate;
392}
393
394/* stop the DAC before calling */
395static void
396set_dac_rate(struct au1550_state *s, unsigned rate)
397{
398 struct dmabuf *dac = &s->dma_dac;
399 struct dmabuf *adc = &s->dma_adc;
400 unsigned adc_rate, dac_rate;
401 u16 ac97_extstat;
402
403 if (s->no_vra) {
404 /* calc SRC factor
405 */
406 dac->src_factor = ((96000 / rate) + 1) >> 1;
407 dac->sample_rate = 48000 / dac->src_factor;
408 return;
409 }
410
411 dac->src_factor = 1;
412
413 ac97_extstat = rdcodec(s->codec, AC97_EXTENDED_STATUS);
414
415 rate = rate > 48000 ? 48000 : rate;
416
417 /* enable VRA
418 */
419 wrcodec(s->codec, AC97_EXTENDED_STATUS,
420 ac97_extstat | AC97_EXTSTAT_VRA);
421
422 /* now write the sample rate
423 */
424 wrcodec(s->codec, AC97_PCM_FRONT_DAC_RATE, (u16) rate);
425
426 /* I don't support different sample rates for multichannel,
427 * so make these channels the same.
428 */
429 if (dac->num_channels > 2)
430 wrcodec(s->codec, AC97_PCM_SURR_DAC_RATE, (u16) rate);
431 if (dac->num_channels > 4)
432 wrcodec(s->codec, AC97_PCM_LFE_DAC_RATE, (u16) rate);
433 /* read it back for actual supported rate
434 */
435 dac_rate = rdcodec(s->codec, AC97_PCM_FRONT_DAC_RATE);
436
437 pr_debug("set_dac_rate: set to %d Hz\n", dac_rate);
438
439 /* some codec's don't allow unequal DAC and ADC rates, in which case
440 * writing one rate reg actually changes both.
441 */
442 adc_rate = rdcodec(s->codec, AC97_PCM_LR_ADC_RATE);
443
444 dac->sample_rate = dac_rate;
445 adc->sample_rate = adc_rate;
446}
447
448static void
449stop_dac(struct au1550_state *s)
450{
451 struct dmabuf *db = &s->dma_dac;
452 u32 stat;
453 unsigned long flags;
454
455 if (db->stopped)
456 return;
457
458 spin_lock_irqsave(&s->lock, flags);
459
460 au_writel(PSC_AC97PCR_TP, PSC_AC97PCR);
461 au_sync();
462
463 /* Wait for Transmit Busy to show disabled.
464 */
465 do {
466 stat = readl((void *)PSC_AC97STAT);
467 au_sync();
468 } while ((stat & PSC_AC97STAT_TB) != 0);
469
470 au1xxx_dbdma_reset(db->dmanr);
471
472 db->stopped = 1;
473
474 spin_unlock_irqrestore(&s->lock, flags);
475}
476
477static void
478stop_adc(struct au1550_state *s)
479{
480 struct dmabuf *db = &s->dma_adc;
481 unsigned long flags;
482 u32 stat;
483
484 if (db->stopped)
485 return;
486
487 spin_lock_irqsave(&s->lock, flags);
488
489 au_writel(PSC_AC97PCR_RP, PSC_AC97PCR);
490 au_sync();
491
492 /* Wait for Receive Busy to show disabled.
493 */
494 do {
495 stat = readl((void *)PSC_AC97STAT);
496 au_sync();
497 } while ((stat & PSC_AC97STAT_RB) != 0);
498
499 au1xxx_dbdma_reset(db->dmanr);
500
501 db->stopped = 1;
502
503 spin_unlock_irqrestore(&s->lock, flags);
504}
505
506
507static void
508set_xmit_slots(int num_channels)
509{
510 u32 ac97_config, stat;
511
512 ac97_config = au_readl(PSC_AC97CFG);
513 au_sync();
514 ac97_config &= ~(PSC_AC97CFG_TXSLOT_MASK | PSC_AC97CFG_DE_ENABLE);
515 au_writel(ac97_config, PSC_AC97CFG);
516 au_sync();
517
518 switch (num_channels) {
519 case 6: /* stereo with surround and center/LFE,
520 * slots 3,4,6,7,8,9
521 */
522 ac97_config |= PSC_AC97CFG_TXSLOT_ENA(6);
523 ac97_config |= PSC_AC97CFG_TXSLOT_ENA(9);
524
525 case 4: /* stereo with surround, slots 3,4,7,8 */
526 ac97_config |= PSC_AC97CFG_TXSLOT_ENA(7);
527 ac97_config |= PSC_AC97CFG_TXSLOT_ENA(8);
528
529 case 2: /* stereo, slots 3,4 */
530 case 1: /* mono */
531 ac97_config |= PSC_AC97CFG_TXSLOT_ENA(3);
532 ac97_config |= PSC_AC97CFG_TXSLOT_ENA(4);
533 }
534
535 au_writel(ac97_config, PSC_AC97CFG);
536 au_sync();
537
538 ac97_config |= PSC_AC97CFG_DE_ENABLE;
539 au_writel(ac97_config, PSC_AC97CFG);
540 au_sync();
541
542 /* Wait for Device ready.
543 */
544 do {
545 stat = readl((void *)PSC_AC97STAT);
546 au_sync();
547 } while ((stat & PSC_AC97STAT_DR) == 0);
548}
549
550static void
551set_recv_slots(int num_channels)
552{
553 u32 ac97_config, stat;
554
555 ac97_config = au_readl(PSC_AC97CFG);
556 au_sync();
557 ac97_config &= ~(PSC_AC97CFG_RXSLOT_MASK | PSC_AC97CFG_DE_ENABLE);
558 au_writel(ac97_config, PSC_AC97CFG);
559 au_sync();
560
561 /* Always enable slots 3 and 4 (stereo). Slot 6 is
562 * optional Mic ADC, which we don't support yet.
563 */
564 ac97_config |= PSC_AC97CFG_RXSLOT_ENA(3);
565 ac97_config |= PSC_AC97CFG_RXSLOT_ENA(4);
566
567 au_writel(ac97_config, PSC_AC97CFG);
568 au_sync();
569
570 ac97_config |= PSC_AC97CFG_DE_ENABLE;
571 au_writel(ac97_config, PSC_AC97CFG);
572 au_sync();
573
574 /* Wait for Device ready.
575 */
576 do {
577 stat = readl((void *)PSC_AC97STAT);
578 au_sync();
579 } while ((stat & PSC_AC97STAT_DR) == 0);
580}
581
582static void
583start_dac(struct au1550_state *s)
584{
585 struct dmabuf *db = &s->dma_dac;
586 unsigned long flags;
587
588 if (!db->stopped)
589 return;
590
591 spin_lock_irqsave(&s->lock, flags);
592
593 set_xmit_slots(db->num_channels);
594 au_writel(PSC_AC97PCR_TC, PSC_AC97PCR);
595 au_sync();
596 au_writel(PSC_AC97PCR_TS, PSC_AC97PCR);
597 au_sync();
598
599 au1xxx_dbdma_start(db->dmanr);
600
601 db->stopped = 0;
602
603 spin_unlock_irqrestore(&s->lock, flags);
604}
605
606static void
607start_adc(struct au1550_state *s)
608{
609 struct dmabuf *db = &s->dma_adc;
610 int i;
611
612 if (!db->stopped)
613 return;
614
615 /* Put two buffers on the ring to get things started.
616 */
617 for (i=0; i<2; i++) {
618 au1xxx_dbdma_put_dest(db->dmanr, db->nextIn, db->dma_fragsize);
619
620 db->nextIn += db->dma_fragsize;
621 if (db->nextIn >= db->rawbuf + db->dmasize)
622 db->nextIn -= db->dmasize;
623 }
624
625 set_recv_slots(db->num_channels);
626 au1xxx_dbdma_start(db->dmanr);
627 au_writel(PSC_AC97PCR_RC, PSC_AC97PCR);
628 au_sync();
629 au_writel(PSC_AC97PCR_RS, PSC_AC97PCR);
630 au_sync();
631
632 db->stopped = 0;
633}
634
635static int
636prog_dmabuf(struct au1550_state *s, struct dmabuf *db)
637{
638 unsigned user_bytes_per_sec;
639 unsigned bufs;
640 unsigned rate = db->sample_rate;
641
642 if (!db->rawbuf) {
643 db->ready = db->mapped = 0;
644 db->buforder = 5; /* 32 * PAGE_SIZE */
645 db->rawbuf = kmalloc((PAGE_SIZE << db->buforder), GFP_KERNEL);
646 if (!db->rawbuf)
647 return -ENOMEM;
648 }
649
650 db->cnt_factor = 1;
651 if (db->sample_size == 8)
652 db->cnt_factor *= 2;
653 if (db->num_channels == 1)
654 db->cnt_factor *= 2;
655 db->cnt_factor *= db->src_factor;
656
657 db->count = 0;
658 db->dma_qcount = 0;
659 db->nextIn = db->nextOut = db->rawbuf;
660
661 db->user_bytes_per_sample = (db->sample_size>>3) * db->num_channels;
662 db->dma_bytes_per_sample = 2 * ((db->num_channels == 1) ?
663 2 : db->num_channels);
664
665 user_bytes_per_sec = rate * db->user_bytes_per_sample;
666 bufs = PAGE_SIZE << db->buforder;
667 if (db->ossfragshift) {
668 if ((1000 << db->ossfragshift) < user_bytes_per_sec)
669 db->fragshift = ld2(user_bytes_per_sec/1000);
670 else
671 db->fragshift = db->ossfragshift;
672 } else {
673 db->fragshift = ld2(user_bytes_per_sec / 100 /
674 (db->subdivision ? db->subdivision : 1));
675 if (db->fragshift < 3)
676 db->fragshift = 3;
677 }
678
679 db->fragsize = 1 << db->fragshift;
680 db->dma_fragsize = db->fragsize * db->cnt_factor;
681 db->numfrag = bufs / db->dma_fragsize;
682
683 while (db->numfrag < 4 && db->fragshift > 3) {
684 db->fragshift--;
685 db->fragsize = 1 << db->fragshift;
686 db->dma_fragsize = db->fragsize * db->cnt_factor;
687 db->numfrag = bufs / db->dma_fragsize;
688 }
689
690 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
691 db->numfrag = db->ossmaxfrags;
692
693 db->dmasize = db->dma_fragsize * db->numfrag;
694 memset(db->rawbuf, 0, bufs);
695
696 pr_debug("prog_dmabuf: rate=%d, samplesize=%d, channels=%d\n",
697 rate, db->sample_size, db->num_channels);
698 pr_debug("prog_dmabuf: fragsize=%d, cnt_factor=%d, dma_fragsize=%d\n",
699 db->fragsize, db->cnt_factor, db->dma_fragsize);
700 pr_debug("prog_dmabuf: numfrag=%d, dmasize=%d\n", db->numfrag, db->dmasize);
701
702 db->ready = 1;
703 return 0;
704}
705
706static int
707prog_dmabuf_adc(struct au1550_state *s)
708{
709 stop_adc(s);
710 return prog_dmabuf(s, &s->dma_adc);
711
712}
713
714static int
715prog_dmabuf_dac(struct au1550_state *s)
716{
717 stop_dac(s);
718 return prog_dmabuf(s, &s->dma_dac);
719}
720
721
722/* hold spinlock for the following */
723static void
724dac_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
725{
726 struct au1550_state *s = (struct au1550_state *) dev_id;
727 struct dmabuf *db = &s->dma_dac;
728 u32 ac97c_stat;
729
730 ac97c_stat = au_readl(PSC_AC97STAT);
731 if (ac97c_stat & (AC97C_XU | AC97C_XO | AC97C_TE))
732 pr_debug("AC97C status = 0x%08x\n", ac97c_stat);
733 db->dma_qcount--;
734
735 if (db->count >= db->fragsize) {
736 if (au1xxx_dbdma_put_source(db->dmanr, db->nextOut,
737 db->fragsize) == 0) {
738 err("qcount < 2 and no ring room!");
739 }
740 db->nextOut += db->fragsize;
741 if (db->nextOut >= db->rawbuf + db->dmasize)
742 db->nextOut -= db->dmasize;
743 db->count -= db->fragsize;
744 db->total_bytes += db->dma_fragsize;
745 db->dma_qcount++;
746 }
747
748 /* wake up anybody listening */
749 if (waitqueue_active(&db->wait))
750 wake_up(&db->wait);
751}
752
753
754static void
755adc_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
756{
757 struct au1550_state *s = (struct au1550_state *)dev_id;
758 struct dmabuf *dp = &s->dma_adc;
759 u32 obytes;
760 char *obuf;
761
762 /* Pull the buffer from the dma queue.
763 */
764 au1xxx_dbdma_get_dest(dp->dmanr, (void *)(&obuf), &obytes);
765
766 if ((dp->count + obytes) > dp->dmasize) {
767 /* Overrun. Stop ADC and log the error
768 */
769 stop_adc(s);
770 dp->error++;
771 err("adc overrun");
772 return;
773 }
774
775 /* Put a new empty buffer on the destination DMA.
776 */
777 au1xxx_dbdma_put_dest(dp->dmanr, dp->nextIn, dp->dma_fragsize);
778
779 dp->nextIn += dp->dma_fragsize;
780 if (dp->nextIn >= dp->rawbuf + dp->dmasize)
781 dp->nextIn -= dp->dmasize;
782
783 dp->count += obytes;
784 dp->total_bytes += obytes;
785
786 /* wake up anybody listening
787 */
788 if (waitqueue_active(&dp->wait))
789 wake_up(&dp->wait);
790
791}
792
793static loff_t
794au1550_llseek(struct file *file, loff_t offset, int origin)
795{
796 return -ESPIPE;
797}
798
799
800static int
801au1550_open_mixdev(struct inode *inode, struct file *file)
802{
803 file->private_data = &au1550_state;
804 return 0;
805}
806
807static int
808au1550_release_mixdev(struct inode *inode, struct file *file)
809{
810 return 0;
811}
812
813static int
814mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd,
815 unsigned long arg)
816{
817 return codec->mixer_ioctl(codec, cmd, arg);
818}
819
820static int
821au1550_ioctl_mixdev(struct inode *inode, struct file *file,
822 unsigned int cmd, unsigned long arg)
823{
824 struct au1550_state *s = (struct au1550_state *)file->private_data;
825 struct ac97_codec *codec = s->codec;
826
827 return mixdev_ioctl(codec, cmd, arg);
828}
829
830static /*const */ struct file_operations au1550_mixer_fops = {
831 owner:THIS_MODULE,
832 llseek:au1550_llseek,
833 ioctl:au1550_ioctl_mixdev,
834 open:au1550_open_mixdev,
835 release:au1550_release_mixdev,
836};
837
838static int
839drain_dac(struct au1550_state *s, int nonblock)
840{
841 unsigned long flags;
842 int count, tmo;
843
844 if (s->dma_dac.mapped || !s->dma_dac.ready || s->dma_dac.stopped)
845 return 0;
846
847 for (;;) {
848 spin_lock_irqsave(&s->lock, flags);
849 count = s->dma_dac.count;
850 spin_unlock_irqrestore(&s->lock, flags);
851 if (count <= s->dma_dac.fragsize)
852 break;
853 if (signal_pending(current))
854 break;
855 if (nonblock)
856 return -EBUSY;
857 tmo = 1000 * count / (s->no_vra ?
858 48000 : s->dma_dac.sample_rate);
859 tmo /= s->dma_dac.dma_bytes_per_sample;
860 au1550_delay(tmo);
861 }
862 if (signal_pending(current))
863 return -ERESTARTSYS;
864 return 0;
865}
866
867static inline u8 S16_TO_U8(s16 ch)
868{
869 return (u8) (ch >> 8) + 0x80;
870}
871static inline s16 U8_TO_S16(u8 ch)
872{
873 return (s16) (ch - 0x80) << 8;
874}
875
876/*
877 * Translates user samples to dma buffer suitable for AC'97 DAC data:
878 * If mono, copy left channel to right channel in dma buffer.
879 * If 8 bit samples, cvt to 16-bit before writing to dma buffer.
880 * If interpolating (no VRA), duplicate every audio frame src_factor times.
881 */
882static int
883translate_from_user(struct dmabuf *db, char* dmabuf, char* userbuf,
884 int dmacount)
885{
886 int sample, i;
887 int interp_bytes_per_sample;
888 int num_samples;
889 int mono = (db->num_channels == 1);
890 char usersample[12];
891 s16 ch, dmasample[6];
892
893 if (db->sample_size == 16 && !mono && db->src_factor == 1) {
894 /* no translation necessary, just copy
895 */
896 if (copy_from_user(dmabuf, userbuf, dmacount))
897 return -EFAULT;
898 return dmacount;
899 }
900
901 interp_bytes_per_sample = db->dma_bytes_per_sample * db->src_factor;
902 num_samples = dmacount / interp_bytes_per_sample;
903
904 for (sample = 0; sample < num_samples; sample++) {
905 if (copy_from_user(usersample, userbuf,
906 db->user_bytes_per_sample)) {
907 return -EFAULT;
908 }
909
910 for (i = 0; i < db->num_channels; i++) {
911 if (db->sample_size == 8)
912 ch = U8_TO_S16(usersample[i]);
913 else
914 ch = *((s16 *) (&usersample[i * 2]));
915 dmasample[i] = ch;
916 if (mono)
917 dmasample[i + 1] = ch; /* right channel */
918 }
919
920 /* duplicate every audio frame src_factor times
921 */
922 for (i = 0; i < db->src_factor; i++)
923 memcpy(dmabuf, dmasample, db->dma_bytes_per_sample);
924
925 userbuf += db->user_bytes_per_sample;
926 dmabuf += interp_bytes_per_sample;
927 }
928
929 return num_samples * interp_bytes_per_sample;
930}
931
932/*
933 * Translates AC'97 ADC samples to user buffer:
934 * If mono, send only left channel to user buffer.
935 * If 8 bit samples, cvt from 16 to 8 bit before writing to user buffer.
936 * If decimating (no VRA), skip over src_factor audio frames.
937 */
938static int
939translate_to_user(struct dmabuf *db, char* userbuf, char* dmabuf,
940 int dmacount)
941{
942 int sample, i;
943 int interp_bytes_per_sample;
944 int num_samples;
945 int mono = (db->num_channels == 1);
946 char usersample[12];
947
948 if (db->sample_size == 16 && !mono && db->src_factor == 1) {
949 /* no translation necessary, just copy
950 */
951 if (copy_to_user(userbuf, dmabuf, dmacount))
952 return -EFAULT;
953 return dmacount;
954 }
955
956 interp_bytes_per_sample = db->dma_bytes_per_sample * db->src_factor;
957 num_samples = dmacount / interp_bytes_per_sample;
958
959 for (sample = 0; sample < num_samples; sample++) {
960 for (i = 0; i < db->num_channels; i++) {
961 if (db->sample_size == 8)
962 usersample[i] =
963 S16_TO_U8(*((s16 *) (&dmabuf[i * 2])));
964 else
965 *((s16 *) (&usersample[i * 2])) =
966 *((s16 *) (&dmabuf[i * 2]));
967 }
968
969 if (copy_to_user(userbuf, usersample,
970 db->user_bytes_per_sample)) {
971 return -EFAULT;
972 }
973
974 userbuf += db->user_bytes_per_sample;
975 dmabuf += interp_bytes_per_sample;
976 }
977
978 return num_samples * interp_bytes_per_sample;
979}
980
981/*
982 * Copy audio data to/from user buffer from/to dma buffer, taking care
983 * that we wrap when reading/writing the dma buffer. Returns actual byte
984 * count written to or read from the dma buffer.
985 */
986static int
987copy_dmabuf_user(struct dmabuf *db, char* userbuf, int count, int to_user)
988{
989 char *bufptr = to_user ? db->nextOut : db->nextIn;
990 char *bufend = db->rawbuf + db->dmasize;
991 int cnt, ret;
992
993 if (bufptr + count > bufend) {
994 int partial = (int) (bufend - bufptr);
995 if (to_user) {
996 if ((cnt = translate_to_user(db, userbuf,
997 bufptr, partial)) < 0)
998 return cnt;
999 ret = cnt;
1000 if ((cnt = translate_to_user(db, userbuf + partial,
1001 db->rawbuf,
1002 count - partial)) < 0)
1003 return cnt;
1004 ret += cnt;
1005 } else {
1006 if ((cnt = translate_from_user(db, bufptr, userbuf,
1007 partial)) < 0)
1008 return cnt;
1009 ret = cnt;
1010 if ((cnt = translate_from_user(db, db->rawbuf,
1011 userbuf + partial,
1012 count - partial)) < 0)
1013 return cnt;
1014 ret += cnt;
1015 }
1016 } else {
1017 if (to_user)
1018 ret = translate_to_user(db, userbuf, bufptr, count);
1019 else
1020 ret = translate_from_user(db, bufptr, userbuf, count);
1021 }
1022
1023 return ret;
1024}
1025
1026
1027static ssize_t
1028au1550_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
1029{
1030 struct au1550_state *s = (struct au1550_state *)file->private_data;
1031 struct dmabuf *db = &s->dma_adc;
1032 DECLARE_WAITQUEUE(wait, current);
1033 ssize_t ret;
1034 unsigned long flags;
1035 int cnt, usercnt, avail;
1036
1037 if (db->mapped)
1038 return -ENXIO;
1039 if (!access_ok(VERIFY_WRITE, buffer, count))
1040 return -EFAULT;
1041 ret = 0;
1042
1043 count *= db->cnt_factor;
1044
1045 down(&s->sem);
1046 add_wait_queue(&db->wait, &wait);
1047
1048 while (count > 0) {
1049 /* wait for samples in ADC dma buffer
1050 */
1051 do {
1052 if (db->stopped)
1053 start_adc(s);
1054 spin_lock_irqsave(&s->lock, flags);
1055 avail = db->count;
1056 if (avail <= 0)
1057 __set_current_state(TASK_INTERRUPTIBLE);
1058 spin_unlock_irqrestore(&s->lock, flags);
1059 if (avail <= 0) {
1060 if (file->f_flags & O_NONBLOCK) {
1061 if (!ret)
1062 ret = -EAGAIN;
1063 goto out;
1064 }
1065 up(&s->sem);
1066 schedule();
1067 if (signal_pending(current)) {
1068 if (!ret)
1069 ret = -ERESTARTSYS;
1070 goto out2;
1071 }
1072 down(&s->sem);
1073 }
1074 } while (avail <= 0);
1075
1076 /* copy from nextOut to user
1077 */
1078 if ((cnt = copy_dmabuf_user(db, buffer,
1079 count > avail ?
1080 avail : count, 1)) < 0) {
1081 if (!ret)
1082 ret = -EFAULT;
1083 goto out;
1084 }
1085
1086 spin_lock_irqsave(&s->lock, flags);
1087 db->count -= cnt;
1088 db->nextOut += cnt;
1089 if (db->nextOut >= db->rawbuf + db->dmasize)
1090 db->nextOut -= db->dmasize;
1091 spin_unlock_irqrestore(&s->lock, flags);
1092
1093 count -= cnt;
1094 usercnt = cnt / db->cnt_factor;
1095 buffer += usercnt;
1096 ret += usercnt;
1097 } /* while (count > 0) */
1098
1099out:
1100 up(&s->sem);
1101out2:
1102 remove_wait_queue(&db->wait, &wait);
1103 set_current_state(TASK_RUNNING);
1104 return ret;
1105}
1106
1107static ssize_t
1108au1550_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
1109{
1110 struct au1550_state *s = (struct au1550_state *)file->private_data;
1111 struct dmabuf *db = &s->dma_dac;
1112 DECLARE_WAITQUEUE(wait, current);
1113 ssize_t ret = 0;
1114 unsigned long flags;
1115 int cnt, usercnt, avail;
1116
1117 pr_debug("write: count=%d\n", count);
1118
1119 if (db->mapped)
1120 return -ENXIO;
1121 if (!access_ok(VERIFY_READ, buffer, count))
1122 return -EFAULT;
1123
1124 count *= db->cnt_factor;
1125
1126 down(&s->sem);
1127 add_wait_queue(&db->wait, &wait);
1128
1129 while (count > 0) {
1130 /* wait for space in playback buffer
1131 */
1132 do {
1133 spin_lock_irqsave(&s->lock, flags);
1134 avail = (int) db->dmasize - db->count;
1135 if (avail <= 0)
1136 __set_current_state(TASK_INTERRUPTIBLE);
1137 spin_unlock_irqrestore(&s->lock, flags);
1138 if (avail <= 0) {
1139 if (file->f_flags & O_NONBLOCK) {
1140 if (!ret)
1141 ret = -EAGAIN;
1142 goto out;
1143 }
1144 up(&s->sem);
1145 schedule();
1146 if (signal_pending(current)) {
1147 if (!ret)
1148 ret = -ERESTARTSYS;
1149 goto out2;
1150 }
1151 down(&s->sem);
1152 }
1153 } while (avail <= 0);
1154
1155 /* copy from user to nextIn
1156 */
1157 if ((cnt = copy_dmabuf_user(db, (char *) buffer,
1158 count > avail ?
1159 avail : count, 0)) < 0) {
1160 if (!ret)
1161 ret = -EFAULT;
1162 goto out;
1163 }
1164
1165 spin_lock_irqsave(&s->lock, flags);
1166 db->count += cnt;
1167 db->nextIn += cnt;
1168 if (db->nextIn >= db->rawbuf + db->dmasize)
1169 db->nextIn -= db->dmasize;
1170
1171 /* If the data is available, we want to keep two buffers
1172 * on the dma queue. If the queue count reaches zero,
1173 * we know the dma has stopped.
1174 */
1175 while ((db->dma_qcount < 2) && (db->count >= db->fragsize)) {
1176 if (au1xxx_dbdma_put_source(db->dmanr, db->nextOut,
1177 db->fragsize) == 0) {
1178 err("qcount < 2 and no ring room!");
1179 }
1180 db->nextOut += db->fragsize;
1181 if (db->nextOut >= db->rawbuf + db->dmasize)
1182 db->nextOut -= db->dmasize;
1183 db->total_bytes += db->dma_fragsize;
1184 if (db->dma_qcount == 0)
1185 start_dac(s);
1186 db->dma_qcount++;
1187 }
1188 spin_unlock_irqrestore(&s->lock, flags);
1189
1190 count -= cnt;
1191 usercnt = cnt / db->cnt_factor;
1192 buffer += usercnt;
1193 ret += usercnt;
1194 } /* while (count > 0) */
1195
1196out:
1197 up(&s->sem);
1198out2:
1199 remove_wait_queue(&db->wait, &wait);
1200 set_current_state(TASK_RUNNING);
1201 return ret;
1202}
1203
1204
1205/* No kernel lock - we have our own spinlock */
1206static unsigned int
1207au1550_poll(struct file *file, struct poll_table_struct *wait)
1208{
1209 struct au1550_state *s = (struct au1550_state *)file->private_data;
1210 unsigned long flags;
1211 unsigned int mask = 0;
1212
1213 if (file->f_mode & FMODE_WRITE) {
1214 if (!s->dma_dac.ready)
1215 return 0;
1216 poll_wait(file, &s->dma_dac.wait, wait);
1217 }
1218 if (file->f_mode & FMODE_READ) {
1219 if (!s->dma_adc.ready)
1220 return 0;
1221 poll_wait(file, &s->dma_adc.wait, wait);
1222 }
1223
1224 spin_lock_irqsave(&s->lock, flags);
1225
1226 if (file->f_mode & FMODE_READ) {
1227 if (s->dma_adc.count >= (signed)s->dma_adc.dma_fragsize)
1228 mask |= POLLIN | POLLRDNORM;
1229 }
1230 if (file->f_mode & FMODE_WRITE) {
1231 if (s->dma_dac.mapped) {
1232 if (s->dma_dac.count >=
1233 (signed)s->dma_dac.dma_fragsize)
1234 mask |= POLLOUT | POLLWRNORM;
1235 } else {
1236 if ((signed) s->dma_dac.dmasize >=
1237 s->dma_dac.count + (signed)s->dma_dac.dma_fragsize)
1238 mask |= POLLOUT | POLLWRNORM;
1239 }
1240 }
1241 spin_unlock_irqrestore(&s->lock, flags);
1242 return mask;
1243}
1244
1245static int
1246au1550_mmap(struct file *file, struct vm_area_struct *vma)
1247{
1248 struct au1550_state *s = (struct au1550_state *)file->private_data;
1249 struct dmabuf *db;
1250 unsigned long size;
1251 int ret = 0;
1252
1253 lock_kernel();
1254 down(&s->sem);
1255 if (vma->vm_flags & VM_WRITE)
1256 db = &s->dma_dac;
1257 else if (vma->vm_flags & VM_READ)
1258 db = &s->dma_adc;
1259 else {
1260 ret = -EINVAL;
1261 goto out;
1262 }
1263 if (vma->vm_pgoff != 0) {
1264 ret = -EINVAL;
1265 goto out;
1266 }
1267 size = vma->vm_end - vma->vm_start;
1268 if (size > (PAGE_SIZE << db->buforder)) {
1269 ret = -EINVAL;
1270 goto out;
1271 }
1272 if (remap_pfn_range(vma, vma->vm_start, page_to_pfn(virt_to_page(db->rawbuf)),
1273 size, vma->vm_page_prot)) {
1274 ret = -EAGAIN;
1275 goto out;
1276 }
1277 vma->vm_flags &= ~VM_IO;
1278 db->mapped = 1;
1279out:
1280 up(&s->sem);
1281 unlock_kernel();
1282 return ret;
1283}
1284
1285#ifdef DEBUG
1286static struct ioctl_str_t {
1287 unsigned int cmd;
1288 const char *str;
1289} ioctl_str[] = {
1290 {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"},
1291 {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"},
1292 {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"},
1293 {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"},
1294 {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"},
1295 {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"},
1296 {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"},
1297 {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"},
1298 {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"},
1299 {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"},
1300 {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"},
1301 {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"},
1302 {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"},
1303 {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"},
1304 {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"},
1305 {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"},
1306 {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"},
1307 {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"},
1308 {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"},
1309 {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"},
1310 {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"},
1311 {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"},
1312 {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"},
1313 {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"},
1314 {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"},
1315 {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"},
1316 {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"},
1317 {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"},
1318 {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"},
1319 {OSS_GETVERSION, "OSS_GETVERSION"},
1320 {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"},
1321 {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"},
1322 {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"},
1323 {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"}
1324};
1325#endif
1326
1327static int
1328dma_count_done(struct dmabuf *db)
1329{
1330 if (db->stopped)
1331 return 0;
1332
1333 return db->dma_fragsize - au1xxx_get_dma_residue(db->dmanr);
1334}
1335
1336
1337static int
1338au1550_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
1339 unsigned long arg)
1340{
1341 struct au1550_state *s = (struct au1550_state *)file->private_data;
1342 unsigned long flags;
1343 audio_buf_info abinfo;
1344 count_info cinfo;
1345 int count;
1346 int val, mapped, ret, diff;
1347
1348 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1349 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1350
1351#ifdef DEBUG
1352 for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
1353 if (ioctl_str[count].cmd == cmd)
1354 break;
1355 }
1356 if (count < sizeof(ioctl_str) / sizeof(ioctl_str[0]))
1357 pr_debug("ioctl %s, arg=0x%lxn", ioctl_str[count].str, arg);
1358 else
1359 pr_debug("ioctl 0x%x unknown, arg=0x%lx\n", cmd, arg);
1360#endif
1361
1362 switch (cmd) {
1363 case OSS_GETVERSION:
1364 return put_user(SOUND_VERSION, (int *) arg);
1365
1366 case SNDCTL_DSP_SYNC:
1367 if (file->f_mode & FMODE_WRITE)
1368 return drain_dac(s, file->f_flags & O_NONBLOCK);
1369 return 0;
1370
1371 case SNDCTL_DSP_SETDUPLEX:
1372 return 0;
1373
1374 case SNDCTL_DSP_GETCAPS:
1375 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
1376 DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg);
1377
1378 case SNDCTL_DSP_RESET:
1379 if (file->f_mode & FMODE_WRITE) {
1380 stop_dac(s);
1381 synchronize_irq();
1382 s->dma_dac.count = s->dma_dac.total_bytes = 0;
1383 s->dma_dac.nextIn = s->dma_dac.nextOut =
1384 s->dma_dac.rawbuf;
1385 }
1386 if (file->f_mode & FMODE_READ) {
1387 stop_adc(s);
1388 synchronize_irq();
1389 s->dma_adc.count = s->dma_adc.total_bytes = 0;
1390 s->dma_adc.nextIn = s->dma_adc.nextOut =
1391 s->dma_adc.rawbuf;
1392 }
1393 return 0;
1394
1395 case SNDCTL_DSP_SPEED:
1396 if (get_user(val, (int *) arg))
1397 return -EFAULT;
1398 if (val >= 0) {
1399 if (file->f_mode & FMODE_READ) {
1400 stop_adc(s);
1401 set_adc_rate(s, val);
1402 }
1403 if (file->f_mode & FMODE_WRITE) {
1404 stop_dac(s);
1405 set_dac_rate(s, val);
1406 }
1407 if (s->open_mode & FMODE_READ)
1408 if ((ret = prog_dmabuf_adc(s)))
1409 return ret;
1410 if (s->open_mode & FMODE_WRITE)
1411 if ((ret = prog_dmabuf_dac(s)))
1412 return ret;
1413 }
1414 return put_user((file->f_mode & FMODE_READ) ?
1415 s->dma_adc.sample_rate :
1416 s->dma_dac.sample_rate,
1417 (int *)arg);
1418
1419 case SNDCTL_DSP_STEREO:
1420 if (get_user(val, (int *) arg))
1421 return -EFAULT;
1422 if (file->f_mode & FMODE_READ) {
1423 stop_adc(s);
1424 s->dma_adc.num_channels = val ? 2 : 1;
1425 if ((ret = prog_dmabuf_adc(s)))
1426 return ret;
1427 }
1428 if (file->f_mode & FMODE_WRITE) {
1429 stop_dac(s);
1430 s->dma_dac.num_channels = val ? 2 : 1;
1431 if (s->codec_ext_caps & AC97_EXT_DACS) {
1432 /* disable surround and center/lfe in AC'97
1433 */
1434 u16 ext_stat = rdcodec(s->codec,
1435 AC97_EXTENDED_STATUS);
1436 wrcodec(s->codec, AC97_EXTENDED_STATUS,
1437 ext_stat | (AC97_EXTSTAT_PRI |
1438 AC97_EXTSTAT_PRJ |
1439 AC97_EXTSTAT_PRK));
1440 }
1441 if ((ret = prog_dmabuf_dac(s)))
1442 return ret;
1443 }
1444 return 0;
1445
1446 case SNDCTL_DSP_CHANNELS:
1447 if (get_user(val, (int *) arg))
1448 return -EFAULT;
1449 if (val != 0) {
1450 if (file->f_mode & FMODE_READ) {
1451 if (val < 0 || val > 2)
1452 return -EINVAL;
1453 stop_adc(s);
1454 s->dma_adc.num_channels = val;
1455 if ((ret = prog_dmabuf_adc(s)))
1456 return ret;
1457 }
1458 if (file->f_mode & FMODE_WRITE) {
1459 switch (val) {
1460 case 1:
1461 case 2:
1462 break;
1463 case 3:
1464 case 5:
1465 return -EINVAL;
1466 case 4:
1467 if (!(s->codec_ext_caps &
1468 AC97_EXTID_SDAC))
1469 return -EINVAL;
1470 break;
1471 case 6:
1472 if ((s->codec_ext_caps &
1473 AC97_EXT_DACS) != AC97_EXT_DACS)
1474 return -EINVAL;
1475 break;
1476 default:
1477 return -EINVAL;
1478 }
1479
1480 stop_dac(s);
1481 if (val <= 2 &&
1482 (s->codec_ext_caps & AC97_EXT_DACS)) {
1483 /* disable surround and center/lfe
1484 * channels in AC'97
1485 */
1486 u16 ext_stat =
1487 rdcodec(s->codec,
1488 AC97_EXTENDED_STATUS);
1489 wrcodec(s->codec,
1490 AC97_EXTENDED_STATUS,
1491 ext_stat | (AC97_EXTSTAT_PRI |
1492 AC97_EXTSTAT_PRJ |
1493 AC97_EXTSTAT_PRK));
1494 } else if (val >= 4) {
1495 /* enable surround, center/lfe
1496 * channels in AC'97
1497 */
1498 u16 ext_stat =
1499 rdcodec(s->codec,
1500 AC97_EXTENDED_STATUS);
1501 ext_stat &= ~AC97_EXTSTAT_PRJ;
1502 if (val == 6)
1503 ext_stat &=
1504 ~(AC97_EXTSTAT_PRI |
1505 AC97_EXTSTAT_PRK);
1506 wrcodec(s->codec,
1507 AC97_EXTENDED_STATUS,
1508 ext_stat);
1509 }
1510
1511 s->dma_dac.num_channels = val;
1512 if ((ret = prog_dmabuf_dac(s)))
1513 return ret;
1514 }
1515 }
1516 return put_user(val, (int *) arg);
1517
1518 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1519 return put_user(AFMT_S16_LE | AFMT_U8, (int *) arg);
1520
1521 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */
1522 if (get_user(val, (int *) arg))
1523 return -EFAULT;
1524 if (val != AFMT_QUERY) {
1525 if (file->f_mode & FMODE_READ) {
1526 stop_adc(s);
1527 if (val == AFMT_S16_LE)
1528 s->dma_adc.sample_size = 16;
1529 else {
1530 val = AFMT_U8;
1531 s->dma_adc.sample_size = 8;
1532 }
1533 if ((ret = prog_dmabuf_adc(s)))
1534 return ret;
1535 }
1536 if (file->f_mode & FMODE_WRITE) {
1537 stop_dac(s);
1538 if (val == AFMT_S16_LE)
1539 s->dma_dac.sample_size = 16;
1540 else {
1541 val = AFMT_U8;
1542 s->dma_dac.sample_size = 8;
1543 }
1544 if ((ret = prog_dmabuf_dac(s)))
1545 return ret;
1546 }
1547 } else {
1548 if (file->f_mode & FMODE_READ)
1549 val = (s->dma_adc.sample_size == 16) ?
1550 AFMT_S16_LE : AFMT_U8;
1551 else
1552 val = (s->dma_dac.sample_size == 16) ?
1553 AFMT_S16_LE : AFMT_U8;
1554 }
1555 return put_user(val, (int *) arg);
1556
1557 case SNDCTL_DSP_POST:
1558 return 0;
1559
1560 case SNDCTL_DSP_GETTRIGGER:
1561 val = 0;
1562 spin_lock_irqsave(&s->lock, flags);
1563 if (file->f_mode & FMODE_READ && !s->dma_adc.stopped)
1564 val |= PCM_ENABLE_INPUT;
1565 if (file->f_mode & FMODE_WRITE && !s->dma_dac.stopped)
1566 val |= PCM_ENABLE_OUTPUT;
1567 spin_unlock_irqrestore(&s->lock, flags);
1568 return put_user(val, (int *) arg);
1569
1570 case SNDCTL_DSP_SETTRIGGER:
1571 if (get_user(val, (int *) arg))
1572 return -EFAULT;
1573 if (file->f_mode & FMODE_READ) {
1574 if (val & PCM_ENABLE_INPUT)
1575 start_adc(s);
1576 else
1577 stop_adc(s);
1578 }
1579 if (file->f_mode & FMODE_WRITE) {
1580 if (val & PCM_ENABLE_OUTPUT)
1581 start_dac(s);
1582 else
1583 stop_dac(s);
1584 }
1585 return 0;
1586
1587 case SNDCTL_DSP_GETOSPACE:
1588 if (!(file->f_mode & FMODE_WRITE))
1589 return -EINVAL;
1590 abinfo.fragsize = s->dma_dac.fragsize;
1591 spin_lock_irqsave(&s->lock, flags);
1592 count = s->dma_dac.count;
1593 count -= dma_count_done(&s->dma_dac);
1594 spin_unlock_irqrestore(&s->lock, flags);
1595 if (count < 0)
1596 count = 0;
1597 abinfo.bytes = (s->dma_dac.dmasize - count) /
1598 s->dma_dac.cnt_factor;
1599 abinfo.fragstotal = s->dma_dac.numfrag;
1600 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
1601 pr_debug("ioctl SNDCTL_DSP_GETOSPACE: bytes=%d, fragments=%d\n", abinfo.bytes, abinfo.fragments);
1602 return copy_to_user((void *) arg, &abinfo,
1603 sizeof(abinfo)) ? -EFAULT : 0;
1604
1605 case SNDCTL_DSP_GETISPACE:
1606 if (!(file->f_mode & FMODE_READ))
1607 return -EINVAL;
1608 abinfo.fragsize = s->dma_adc.fragsize;
1609 spin_lock_irqsave(&s->lock, flags);
1610 count = s->dma_adc.count;
1611 count += dma_count_done(&s->dma_adc);
1612 spin_unlock_irqrestore(&s->lock, flags);
1613 if (count < 0)
1614 count = 0;
1615 abinfo.bytes = count / s->dma_adc.cnt_factor;
1616 abinfo.fragstotal = s->dma_adc.numfrag;
1617 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1618 return copy_to_user((void *) arg, &abinfo,
1619 sizeof(abinfo)) ? -EFAULT : 0;
1620
1621 case SNDCTL_DSP_NONBLOCK:
1622 file->f_flags |= O_NONBLOCK;
1623 return 0;
1624
1625 case SNDCTL_DSP_GETODELAY:
1626 if (!(file->f_mode & FMODE_WRITE))
1627 return -EINVAL;
1628 spin_lock_irqsave(&s->lock, flags);
1629 count = s->dma_dac.count;
1630 count -= dma_count_done(&s->dma_dac);
1631 spin_unlock_irqrestore(&s->lock, flags);
1632 if (count < 0)
1633 count = 0;
1634 count /= s->dma_dac.cnt_factor;
1635 return put_user(count, (int *) arg);
1636
1637 case SNDCTL_DSP_GETIPTR:
1638 if (!(file->f_mode & FMODE_READ))
1639 return -EINVAL;
1640 spin_lock_irqsave(&s->lock, flags);
1641 cinfo.bytes = s->dma_adc.total_bytes;
1642 count = s->dma_adc.count;
1643 if (!s->dma_adc.stopped) {
1644 diff = dma_count_done(&s->dma_adc);
1645 count += diff;
1646 cinfo.bytes += diff;
1647 cinfo.ptr = virt_to_phys(s->dma_adc.nextIn) + diff -
1648 virt_to_phys(s->dma_adc.rawbuf);
1649 } else
1650 cinfo.ptr = virt_to_phys(s->dma_adc.nextIn) -
1651 virt_to_phys(s->dma_adc.rawbuf);
1652 if (s->dma_adc.mapped)
1653 s->dma_adc.count &= (s->dma_adc.dma_fragsize-1);
1654 spin_unlock_irqrestore(&s->lock, flags);
1655 if (count < 0)
1656 count = 0;
1657 cinfo.blocks = count >> s->dma_adc.fragshift;
1658 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo));
1659
1660 case SNDCTL_DSP_GETOPTR:
1661 if (!(file->f_mode & FMODE_READ))
1662 return -EINVAL;
1663 spin_lock_irqsave(&s->lock, flags);
1664 cinfo.bytes = s->dma_dac.total_bytes;
1665 count = s->dma_dac.count;
1666 if (!s->dma_dac.stopped) {
1667 diff = dma_count_done(&s->dma_dac);
1668 count -= diff;
1669 cinfo.bytes += diff;
1670 cinfo.ptr = virt_to_phys(s->dma_dac.nextOut) + diff -
1671 virt_to_phys(s->dma_dac.rawbuf);
1672 } else
1673 cinfo.ptr = virt_to_phys(s->dma_dac.nextOut) -
1674 virt_to_phys(s->dma_dac.rawbuf);
1675 if (s->dma_dac.mapped)
1676 s->dma_dac.count &= (s->dma_dac.dma_fragsize-1);
1677 spin_unlock_irqrestore(&s->lock, flags);
1678 if (count < 0)
1679 count = 0;
1680 cinfo.blocks = count >> s->dma_dac.fragshift;
1681 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo));
1682
1683 case SNDCTL_DSP_GETBLKSIZE:
1684 if (file->f_mode & FMODE_WRITE)
1685 return put_user(s->dma_dac.fragsize, (int *) arg);
1686 else
1687 return put_user(s->dma_adc.fragsize, (int *) arg);
1688
1689 case SNDCTL_DSP_SETFRAGMENT:
1690 if (get_user(val, (int *) arg))
1691 return -EFAULT;
1692 if (file->f_mode & FMODE_READ) {
1693 stop_adc(s);
1694 s->dma_adc.ossfragshift = val & 0xffff;
1695 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1696 if (s->dma_adc.ossfragshift < 4)
1697 s->dma_adc.ossfragshift = 4;
1698 if (s->dma_adc.ossfragshift > 15)
1699 s->dma_adc.ossfragshift = 15;
1700 if (s->dma_adc.ossmaxfrags < 4)
1701 s->dma_adc.ossmaxfrags = 4;
1702 if ((ret = prog_dmabuf_adc(s)))
1703 return ret;
1704 }
1705 if (file->f_mode & FMODE_WRITE) {
1706 stop_dac(s);
1707 s->dma_dac.ossfragshift = val & 0xffff;
1708 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
1709 if (s->dma_dac.ossfragshift < 4)
1710 s->dma_dac.ossfragshift = 4;
1711 if (s->dma_dac.ossfragshift > 15)
1712 s->dma_dac.ossfragshift = 15;
1713 if (s->dma_dac.ossmaxfrags < 4)
1714 s->dma_dac.ossmaxfrags = 4;
1715 if ((ret = prog_dmabuf_dac(s)))
1716 return ret;
1717 }
1718 return 0;
1719
1720 case SNDCTL_DSP_SUBDIVIDE:
1721 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1722 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
1723 return -EINVAL;
1724 if (get_user(val, (int *) arg))
1725 return -EFAULT;
1726 if (val != 1 && val != 2 && val != 4)
1727 return -EINVAL;
1728 if (file->f_mode & FMODE_READ) {
1729 stop_adc(s);
1730 s->dma_adc.subdivision = val;
1731 if ((ret = prog_dmabuf_adc(s)))
1732 return ret;
1733 }
1734 if (file->f_mode & FMODE_WRITE) {
1735 stop_dac(s);
1736 s->dma_dac.subdivision = val;
1737 if ((ret = prog_dmabuf_dac(s)))
1738 return ret;
1739 }
1740 return 0;
1741
1742 case SOUND_PCM_READ_RATE:
1743 return put_user((file->f_mode & FMODE_READ) ?
1744 s->dma_adc.sample_rate :
1745 s->dma_dac.sample_rate,
1746 (int *)arg);
1747
1748 case SOUND_PCM_READ_CHANNELS:
1749 if (file->f_mode & FMODE_READ)
1750 return put_user(s->dma_adc.num_channels, (int *)arg);
1751 else
1752 return put_user(s->dma_dac.num_channels, (int *)arg);
1753
1754 case SOUND_PCM_READ_BITS:
1755 if (file->f_mode & FMODE_READ)
1756 return put_user(s->dma_adc.sample_size, (int *)arg);
1757 else
1758 return put_user(s->dma_dac.sample_size, (int *)arg);
1759
1760 case SOUND_PCM_WRITE_FILTER:
1761 case SNDCTL_DSP_SETSYNCRO:
1762 case SOUND_PCM_READ_FILTER:
1763 return -EINVAL;
1764 }
1765
1766 return mixdev_ioctl(s->codec, cmd, arg);
1767}
1768
1769
1770static int
1771au1550_open(struct inode *inode, struct file *file)
1772{
1773 int minor = MINOR(inode->i_rdev);
1774 DECLARE_WAITQUEUE(wait, current);
1775 struct au1550_state *s = &au1550_state;
1776 int ret;
1777
1778#ifdef DEBUG
1779 if (file->f_flags & O_NONBLOCK)
1780 pr_debug("open: non-blocking\n");
1781 else
1782 pr_debug("open: blocking\n");
1783#endif
1784
1785 file->private_data = s;
1786 /* wait for device to become free */
1787 down(&s->open_sem);
1788 while (s->open_mode & file->f_mode) {
1789 if (file->f_flags & O_NONBLOCK) {
1790 up(&s->open_sem);
1791 return -EBUSY;
1792 }
1793 add_wait_queue(&s->open_wait, &wait);
1794 __set_current_state(TASK_INTERRUPTIBLE);
1795 up(&s->open_sem);
1796 schedule();
1797 remove_wait_queue(&s->open_wait, &wait);
1798 set_current_state(TASK_RUNNING);
1799 if (signal_pending(current))
1800 return -ERESTARTSYS;
1801 down(&s->open_sem);
1802 }
1803
1804 stop_dac(s);
1805 stop_adc(s);
1806
1807 if (file->f_mode & FMODE_READ) {
1808 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
1809 s->dma_adc.subdivision = s->dma_adc.total_bytes = 0;
1810 s->dma_adc.num_channels = 1;
1811 s->dma_adc.sample_size = 8;
1812 set_adc_rate(s, 8000);
1813 if ((minor & 0xf) == SND_DEV_DSP16)
1814 s->dma_adc.sample_size = 16;
1815 }
1816
1817 if (file->f_mode & FMODE_WRITE) {
1818 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
1819 s->dma_dac.subdivision = s->dma_dac.total_bytes = 0;
1820 s->dma_dac.num_channels = 1;
1821 s->dma_dac.sample_size = 8;
1822 set_dac_rate(s, 8000);
1823 if ((minor & 0xf) == SND_DEV_DSP16)
1824 s->dma_dac.sample_size = 16;
1825 }
1826
1827 if (file->f_mode & FMODE_READ) {
1828 if ((ret = prog_dmabuf_adc(s)))
1829 return ret;
1830 }
1831 if (file->f_mode & FMODE_WRITE) {
1832 if ((ret = prog_dmabuf_dac(s)))
1833 return ret;
1834 }
1835
1836 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1837 up(&s->open_sem);
1838 init_MUTEX(&s->sem);
1839 return 0;
1840}
1841
1842static int
1843au1550_release(struct inode *inode, struct file *file)
1844{
1845 struct au1550_state *s = (struct au1550_state *)file->private_data;
1846
1847 lock_kernel();
1848
1849 if (file->f_mode & FMODE_WRITE) {
1850 unlock_kernel();
1851 drain_dac(s, file->f_flags & O_NONBLOCK);
1852 lock_kernel();
1853 }
1854
1855 down(&s->open_sem);
1856 if (file->f_mode & FMODE_WRITE) {
1857 stop_dac(s);
1858 kfree(s->dma_dac.rawbuf);
1859 s->dma_dac.rawbuf = NULL;
1860 }
1861 if (file->f_mode & FMODE_READ) {
1862 stop_adc(s);
1863 kfree(s->dma_adc.rawbuf);
1864 s->dma_adc.rawbuf = NULL;
1865 }
1866 s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
1867 up(&s->open_sem);
1868 wake_up(&s->open_wait);
1869 unlock_kernel();
1870 return 0;
1871}
1872
1873static /*const */ struct file_operations au1550_audio_fops = {
1874 owner: THIS_MODULE,
1875 llseek: au1550_llseek,
1876 read: au1550_read,
1877 write: au1550_write,
1878 poll: au1550_poll,
1879 ioctl: au1550_ioctl,
1880 mmap: au1550_mmap,
1881 open: au1550_open,
1882 release: au1550_release,
1883};
1884
1885MODULE_AUTHOR("Advanced Micro Devices (AMD), dan@embeddededge.com");
1886MODULE_DESCRIPTION("Au1550 AC97 Audio Driver");
1887
1888static int __devinit
1889au1550_probe(void)
1890{
1891 struct au1550_state *s = &au1550_state;
1892 int val;
1893
1894 memset(s, 0, sizeof(struct au1550_state));
1895
1896 init_waitqueue_head(&s->dma_adc.wait);
1897 init_waitqueue_head(&s->dma_dac.wait);
1898 init_waitqueue_head(&s->open_wait);
1899 init_MUTEX(&s->open_sem);
1900 spin_lock_init(&s->lock);
1901
1902 s->codec = ac97_alloc_codec();
1903 if(s->codec == NULL) {
1904 err("Out of memory");
1905 return -1;
1906 }
1907 s->codec->private_data = s;
1908 s->codec->id = 0;
1909 s->codec->codec_read = rdcodec;
1910 s->codec->codec_write = wrcodec;
1911 s->codec->codec_wait = waitcodec;
1912
1913 if (!request_mem_region(CPHYSADDR(AC97_PSC_SEL),
1914 0x30, "Au1550 AC97")) {
1915 err("AC'97 ports in use");
1916 }
1917
1918 /* Allocate the DMA Channels
1919 */
1920 if ((s->dma_dac.dmanr = au1xxx_dbdma_chan_alloc(DBDMA_MEM_CHAN,
1921 DBDMA_AC97_TX_CHAN, dac_dma_interrupt, (void *)s)) == 0) {
1922 err("Can't get DAC DMA");
1923 goto err_dma1;
1924 }
1925 au1xxx_dbdma_set_devwidth(s->dma_dac.dmanr, 16);
1926 if (au1xxx_dbdma_ring_alloc(s->dma_dac.dmanr,
1927 NUM_DBDMA_DESCRIPTORS) == 0) {
1928 err("Can't get DAC DMA descriptors");
1929 goto err_dma1;
1930 }
1931
1932 if ((s->dma_adc.dmanr = au1xxx_dbdma_chan_alloc(DBDMA_AC97_RX_CHAN,
1933 DBDMA_MEM_CHAN, adc_dma_interrupt, (void *)s)) == 0) {
1934 err("Can't get ADC DMA");
1935 goto err_dma2;
1936 }
1937 au1xxx_dbdma_set_devwidth(s->dma_adc.dmanr, 16);
1938 if (au1xxx_dbdma_ring_alloc(s->dma_adc.dmanr,
1939 NUM_DBDMA_DESCRIPTORS) == 0) {
1940 err("Can't get ADC DMA descriptors");
1941 goto err_dma2;
1942 }
1943
1944 pr_info("DAC: DMA%d, ADC: DMA%d", DBDMA_AC97_TX_CHAN, DBDMA_AC97_RX_CHAN);
1945
1946 /* register devices */
1947
1948 if ((s->dev_audio = register_sound_dsp(&au1550_audio_fops, -1)) < 0)
1949 goto err_dev1;
1950 if ((s->codec->dev_mixer =
1951 register_sound_mixer(&au1550_mixer_fops, -1)) < 0)
1952 goto err_dev2;
1953
1954 /* The GPIO for the appropriate PSC was configured by the
1955 * board specific start up.
1956 *
1957 * configure PSC for AC'97
1958 */
1959 au_writel(0, AC97_PSC_CTRL); /* Disable PSC */
1960 au_sync();
1961 au_writel((PSC_SEL_CLK_SERCLK | PSC_SEL_PS_AC97MODE), AC97_PSC_SEL);
1962 au_sync();
1963
1964 /* cold reset the AC'97
1965 */
1966 au_writel(PSC_AC97RST_RST, PSC_AC97RST);
1967 au_sync();
1968 au1550_delay(10);
1969 au_writel(0, PSC_AC97RST);
1970 au_sync();
1971
1972 /* need to delay around 500msec(bleech) to give
1973 some CODECs enough time to wakeup */
1974 au1550_delay(500);
1975
1976 /* warm reset the AC'97 to start the bitclk
1977 */
1978 au_writel(PSC_AC97RST_SNC, PSC_AC97RST);
1979 au_sync();
1980 udelay(100);
1981 au_writel(0, PSC_AC97RST);
1982 au_sync();
1983
1984 /* Enable PSC
1985 */
1986 au_writel(PSC_CTRL_ENABLE, AC97_PSC_CTRL);
1987 au_sync();
1988
1989 /* Wait for PSC ready.
1990 */
1991 do {
1992 val = readl((void *)PSC_AC97STAT);
1993 au_sync();
1994 } while ((val & PSC_AC97STAT_SR) == 0);
1995
1996 /* Configure AC97 controller.
1997 * Deep FIFO, 16-bit sample, DMA, make sure DMA matches fifo size.
1998 */
1999 val = PSC_AC97CFG_SET_LEN(16);
2000 val |= PSC_AC97CFG_RT_FIFO8 | PSC_AC97CFG_TT_FIFO8;
2001
2002 /* Enable device so we can at least
2003 * talk over the AC-link.
2004 */
2005 au_writel(val, PSC_AC97CFG);
2006 au_writel(PSC_AC97MSK_ALLMASK, PSC_AC97MSK);
2007 au_sync();
2008 val |= PSC_AC97CFG_DE_ENABLE;
2009 au_writel(val, PSC_AC97CFG);
2010 au_sync();
2011
2012 /* Wait for Device ready.
2013 */
2014 do {
2015 val = readl((void *)PSC_AC97STAT);
2016 au_sync();
2017 } while ((val & PSC_AC97STAT_DR) == 0);
2018
2019 /* codec init */
2020 if (!ac97_probe_codec(s->codec))
2021 goto err_dev3;
2022
2023 s->codec_base_caps = rdcodec(s->codec, AC97_RESET);
2024 s->codec_ext_caps = rdcodec(s->codec, AC97_EXTENDED_ID);
2025 pr_info("AC'97 Base/Extended ID = %04x/%04x",
2026 s->codec_base_caps, s->codec_ext_caps);
2027
2028 if (!(s->codec_ext_caps & AC97_EXTID_VRA)) {
2029 /* codec does not support VRA
2030 */
2031 s->no_vra = 1;
2032 } else if (!vra) {
2033 /* Boot option says disable VRA
2034 */
2035 u16 ac97_extstat = rdcodec(s->codec, AC97_EXTENDED_STATUS);
2036 wrcodec(s->codec, AC97_EXTENDED_STATUS,
2037 ac97_extstat & ~AC97_EXTSTAT_VRA);
2038 s->no_vra = 1;
2039 }
2040 if (s->no_vra)
2041 pr_info("no VRA, interpolating and decimating");
2042
2043 /* set mic to be the recording source */
2044 val = SOUND_MASK_MIC;
2045 mixdev_ioctl(s->codec, SOUND_MIXER_WRITE_RECSRC,
2046 (unsigned long) &val);
2047
2048 return 0;
2049
2050 err_dev3:
2051 unregister_sound_mixer(s->codec->dev_mixer);
2052 err_dev2:
2053 unregister_sound_dsp(s->dev_audio);
2054 err_dev1:
2055 au1xxx_dbdma_chan_free(s->dma_adc.dmanr);
2056 err_dma2:
2057 au1xxx_dbdma_chan_free(s->dma_dac.dmanr);
2058 err_dma1:
2059 release_mem_region(CPHYSADDR(AC97_PSC_SEL), 0x30);
2060
2061 ac97_release_codec(s->codec);
2062 return -1;
2063}
2064
2065static void __devinit
2066au1550_remove(void)
2067{
2068 struct au1550_state *s = &au1550_state;
2069
2070 if (!s)
2071 return;
2072 synchronize_irq();
2073 au1xxx_dbdma_chan_free(s->dma_adc.dmanr);
2074 au1xxx_dbdma_chan_free(s->dma_dac.dmanr);
2075 release_mem_region(CPHYSADDR(AC97_PSC_SEL), 0x30);
2076 unregister_sound_dsp(s->dev_audio);
2077 unregister_sound_mixer(s->codec->dev_mixer);
2078 ac97_release_codec(s->codec);
2079}
2080
2081static int __init
2082init_au1550(void)
2083{
2084 return au1550_probe();
2085}
2086
2087static void __exit
2088cleanup_au1550(void)
2089{
2090 au1550_remove();
2091}
2092
2093module_init(init_au1550);
2094module_exit(cleanup_au1550);
2095
2096#ifndef MODULE
2097
2098static int __init
2099au1550_setup(char *options)
2100{
2101 char *this_opt;
2102
2103 if (!options || !*options)
2104 return 0;
2105
2106 while ((this_opt = strsep(&options, ","))) {
2107 if (!*this_opt)
2108 continue;
2109 if (!strncmp(this_opt, "vra", 3)) {
2110 vra = 1;
2111 }
2112 }
2113
2114 return 1;
2115}
2116
2117__setup("au1550_audio=", au1550_setup);
2118
2119#endif /* MODULE */
diff --git a/sound/oss/audio.c b/sound/oss/audio.c
new file mode 100644
index 000000000000..22dd63c36816
--- /dev/null
+++ b/sound/oss/audio.c
@@ -0,0 +1,983 @@
1/*
2 * sound/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 file->f_flags |= O_NONBLOCK;
437 return 0;
438
439 case SNDCTL_DSP_GETCAPS:
440 val = 1 | DSP_CAP_MMAP; /* Revision level of this ioctl() */
441 if (audio_devs[dev]->flags & DMA_DUPLEX &&
442 audio_devs[dev]->open_mode == OPEN_READWRITE)
443 val |= DSP_CAP_DUPLEX;
444 if (audio_devs[dev]->coproc)
445 val |= DSP_CAP_COPROC;
446 if (audio_devs[dev]->d->local_qlen) /* Device has hidden buffers */
447 val |= DSP_CAP_BATCH;
448 if (audio_devs[dev]->d->trigger) /* Supports SETTRIGGER */
449 val |= DSP_CAP_TRIGGER;
450 break;
451
452 case SOUND_PCM_WRITE_RATE:
453 if (get_user(val, p))
454 return -EFAULT;
455 val = audio_devs[dev]->d->set_speed(dev, val);
456 break;
457
458 case SOUND_PCM_READ_RATE:
459 val = audio_devs[dev]->d->set_speed(dev, 0);
460 break;
461
462 case SNDCTL_DSP_STEREO:
463 if (get_user(val, p))
464 return -EFAULT;
465 if (val > 1 || val < 0)
466 return -EINVAL;
467 val = audio_devs[dev]->d->set_channels(dev, val + 1) - 1;
468 break;
469
470 case SOUND_PCM_WRITE_CHANNELS:
471 if (get_user(val, p))
472 return -EFAULT;
473 val = audio_devs[dev]->d->set_channels(dev, val);
474 break;
475
476 case SOUND_PCM_READ_CHANNELS:
477 val = audio_devs[dev]->d->set_channels(dev, 0);
478 break;
479
480 case SOUND_PCM_READ_BITS:
481 val = audio_devs[dev]->d->set_bits(dev, 0);
482 break;
483
484 case SNDCTL_DSP_SETDUPLEX:
485 if (audio_devs[dev]->open_mode != OPEN_READWRITE)
486 return -EPERM;
487 return (audio_devs[dev]->flags & DMA_DUPLEX) ? 0 : -EIO;
488
489 case SNDCTL_DSP_PROFILE:
490 if (get_user(val, p))
491 return -EFAULT;
492 if (audio_devs[dev]->open_mode & OPEN_WRITE)
493 audio_devs[dev]->dmap_out->applic_profile = val;
494 if (audio_devs[dev]->open_mode & OPEN_READ)
495 audio_devs[dev]->dmap_in->applic_profile = val;
496 return 0;
497
498 case SNDCTL_DSP_GETODELAY:
499 dmap = audio_devs[dev]->dmap_out;
500 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
501 return -EINVAL;
502 if (!(dmap->flags & DMA_ALLOC_DONE))
503 {
504 val=0;
505 break;
506 }
507
508 spin_lock_irqsave(&dmap->lock,flags);
509 /* Compute number of bytes that have been played */
510 count = DMAbuf_get_buffer_pointer (dev, dmap, DMODE_OUTPUT);
511 if (count < dmap->fragment_size && dmap->qhead != 0)
512 count += dmap->bytes_in_use; /* Pointer wrap not handled yet */
513 count += dmap->byte_counter;
514
515 /* Substract current count from the number of bytes written by app */
516 count = dmap->user_counter - count;
517 if (count < 0)
518 count = 0;
519 spin_unlock_irqrestore(&dmap->lock,flags);
520 val = count;
521 break;
522
523 default:
524 return dma_ioctl(dev, cmd, arg);
525 }
526 return put_user(val, p);
527}
528
529void audio_init_devices(void)
530{
531 /*
532 * NOTE! This routine could be called several times during boot.
533 */
534}
535
536void reorganize_buffers(int dev, struct dma_buffparms *dmap, int recording)
537{
538 /*
539 * This routine breaks the physical device buffers to logical ones.
540 */
541
542 struct audio_operations *dsp_dev = audio_devs[dev];
543
544 unsigned i, n;
545 unsigned sr, nc, sz, bsz;
546
547 sr = dsp_dev->d->set_speed(dev, 0);
548 nc = dsp_dev->d->set_channels(dev, 0);
549 sz = dsp_dev->d->set_bits(dev, 0);
550
551 if (sz == 8)
552 dmap->neutral_byte = NEUTRAL8;
553 else
554 dmap->neutral_byte = NEUTRAL16;
555
556 if (sr < 1 || nc < 1 || sz < 1)
557 {
558/* printk(KERN_DEBUG "Warning: Invalid PCM parameters[%d] sr=%d, nc=%d, sz=%d\n", dev, sr, nc, sz);*/
559 sr = DSP_DEFAULT_SPEED;
560 nc = 1;
561 sz = 8;
562 }
563
564 sz = sr * nc * sz;
565
566 sz /= 8; /* #bits -> #bytes */
567 dmap->data_rate = sz;
568
569 if (!dmap->needs_reorg)
570 return;
571 dmap->needs_reorg = 0;
572
573 if (dmap->fragment_size == 0)
574 {
575 /* Compute the fragment size using the default algorithm */
576
577 /*
578 * Compute a buffer size for time not exceeding 1 second.
579 * Usually this algorithm gives a buffer size for 0.5 to 1.0 seconds
580 * of sound (using the current speed, sample size and #channels).
581 */
582
583 bsz = dmap->buffsize;
584 while (bsz > sz)
585 bsz /= 2;
586
587 if (bsz == dmap->buffsize)
588 bsz /= 2; /* Needs at least 2 buffers */
589
590 /*
591 * Split the computed fragment to smaller parts. After 3.5a9
592 * the default subdivision is 4 which should give better
593 * results when recording.
594 */
595
596 if (dmap->subdivision == 0) /* Not already set */
597 {
598 dmap->subdivision = 4; /* Init to the default value */
599
600 if ((bsz / dmap->subdivision) > 4096)
601 dmap->subdivision *= 2;
602 if ((bsz / dmap->subdivision) < 4096)
603 dmap->subdivision = 1;
604 }
605 bsz /= dmap->subdivision;
606
607 if (bsz < 16)
608 bsz = 16; /* Just a sanity check */
609
610 dmap->fragment_size = bsz;
611 }
612 else
613 {
614 /*
615 * The process has specified the buffer size with SNDCTL_DSP_SETFRAGMENT or
616 * the buffer size computation has already been done.
617 */
618 if (dmap->fragment_size > (dmap->buffsize / 2))
619 dmap->fragment_size = (dmap->buffsize / 2);
620 bsz = dmap->fragment_size;
621 }
622
623 if (audio_devs[dev]->min_fragment)
624 if (bsz < (1 << audio_devs[dev]->min_fragment))
625 bsz = 1 << audio_devs[dev]->min_fragment;
626 if (audio_devs[dev]->max_fragment)
627 if (bsz > (1 << audio_devs[dev]->max_fragment))
628 bsz = 1 << audio_devs[dev]->max_fragment;
629 bsz &= ~0x07; /* Force size which is multiple of 8 bytes */
630#ifdef OS_DMA_ALIGN_CHECK
631 OS_DMA_ALIGN_CHECK(bsz);
632#endif
633
634 n = dmap->buffsize / bsz;
635 if (n > MAX_SUB_BUFFERS)
636 n = MAX_SUB_BUFFERS;
637 if (n > dmap->max_fragments)
638 n = dmap->max_fragments;
639
640 if (n < 2)
641 {
642 n = 2;
643 bsz /= 2;
644 }
645 dmap->nbufs = n;
646 dmap->bytes_in_use = n * bsz;
647 dmap->fragment_size = bsz;
648 dmap->max_byte_counter = (dmap->data_rate * 60 * 60) +
649 dmap->bytes_in_use; /* Approximately one hour */
650
651 if (dmap->raw_buf)
652 {
653 memset(dmap->raw_buf, dmap->neutral_byte, dmap->bytes_in_use);
654 }
655
656 for (i = 0; i < dmap->nbufs; i++)
657 {
658 dmap->counts[i] = 0;
659 }
660
661 dmap->flags |= DMA_ALLOC_DONE | DMA_EMPTY;
662}
663
664static int dma_subdivide(int dev, struct dma_buffparms *dmap, int fact)
665{
666 if (fact == 0)
667 {
668 fact = dmap->subdivision;
669 if (fact == 0)
670 fact = 1;
671 return fact;
672 }
673 if (dmap->subdivision != 0 || dmap->fragment_size) /* Too late to change */
674 return -EINVAL;
675
676 if (fact > MAX_REALTIME_FACTOR)
677 return -EINVAL;
678
679 if (fact != 1 && fact != 2 && fact != 4 && fact != 8 && fact != 16)
680 return -EINVAL;
681
682 dmap->subdivision = fact;
683 return fact;
684}
685
686static int dma_set_fragment(int dev, struct dma_buffparms *dmap, int fact)
687{
688 int bytes, count;
689
690 if (fact == 0)
691 return -EIO;
692
693 if (dmap->subdivision != 0 ||
694 dmap->fragment_size) /* Too late to change */
695 return -EINVAL;
696
697 bytes = fact & 0xffff;
698 count = (fact >> 16) & 0x7fff;
699
700 if (count == 0)
701 count = MAX_SUB_BUFFERS;
702 else if (count < MAX_SUB_BUFFERS)
703 count++;
704
705 if (bytes < 4 || bytes > 17) /* <16 || > 512k */
706 return -EINVAL;
707
708 if (count < 2)
709 return -EINVAL;
710
711 if (audio_devs[dev]->min_fragment > 0)
712 if (bytes < audio_devs[dev]->min_fragment)
713 bytes = audio_devs[dev]->min_fragment;
714
715 if (audio_devs[dev]->max_fragment > 0)
716 if (bytes > audio_devs[dev]->max_fragment)
717 bytes = audio_devs[dev]->max_fragment;
718
719#ifdef OS_DMA_MINBITS
720 if (bytes < OS_DMA_MINBITS)
721 bytes = OS_DMA_MINBITS;
722#endif
723
724 dmap->fragment_size = (1 << bytes);
725 dmap->max_fragments = count;
726
727 if (dmap->fragment_size > dmap->buffsize)
728 dmap->fragment_size = dmap->buffsize;
729
730 if (dmap->fragment_size == dmap->buffsize &&
731 audio_devs[dev]->flags & DMA_AUTOMODE)
732 dmap->fragment_size /= 2; /* Needs at least 2 buffers */
733
734 dmap->subdivision = 1; /* Disable SNDCTL_DSP_SUBDIVIDE */
735 return bytes | ((count - 1) << 16);
736}
737
738static int dma_ioctl(int dev, unsigned int cmd, void __user *arg)
739{
740 struct dma_buffparms *dmap_out = audio_devs[dev]->dmap_out;
741 struct dma_buffparms *dmap_in = audio_devs[dev]->dmap_in;
742 struct dma_buffparms *dmap;
743 audio_buf_info info;
744 count_info cinfo;
745 int fact, ret, changed, bits, count, err;
746 unsigned long flags;
747
748 switch (cmd)
749 {
750 case SNDCTL_DSP_SUBDIVIDE:
751 ret = 0;
752 if (get_user(fact, (int __user *)arg))
753 return -EFAULT;
754 if (audio_devs[dev]->open_mode & OPEN_WRITE)
755 ret = dma_subdivide(dev, dmap_out, fact);
756 if (ret < 0)
757 return ret;
758 if (audio_devs[dev]->open_mode != OPEN_WRITE ||
759 (audio_devs[dev]->flags & DMA_DUPLEX &&
760 audio_devs[dev]->open_mode & OPEN_READ))
761 ret = dma_subdivide(dev, dmap_in, fact);
762 if (ret < 0)
763 return ret;
764 break;
765
766 case SNDCTL_DSP_GETISPACE:
767 case SNDCTL_DSP_GETOSPACE:
768 dmap = dmap_out;
769 if (cmd == SNDCTL_DSP_GETISPACE && !(audio_devs[dev]->open_mode & OPEN_READ))
770 return -EINVAL;
771 if (cmd == SNDCTL_DSP_GETOSPACE && !(audio_devs[dev]->open_mode & OPEN_WRITE))
772 return -EINVAL;
773 if (cmd == SNDCTL_DSP_GETISPACE && audio_devs[dev]->flags & DMA_DUPLEX)
774 dmap = dmap_in;
775 if (dmap->mapping_flags & DMA_MAP_MAPPED)
776 return -EINVAL;
777 if (!(dmap->flags & DMA_ALLOC_DONE))
778 reorganize_buffers(dev, dmap, (cmd == SNDCTL_DSP_GETISPACE));
779 info.fragstotal = dmap->nbufs;
780 if (cmd == SNDCTL_DSP_GETISPACE)
781 info.fragments = dmap->qlen;
782 else
783 {
784 if (!DMAbuf_space_in_queue(dev))
785 info.fragments = 0;
786 else
787 {
788 info.fragments = DMAbuf_space_in_queue(dev);
789 if (audio_devs[dev]->d->local_qlen)
790 {
791 int tmp = audio_devs[dev]->d->local_qlen(dev);
792 if (tmp && info.fragments)
793 tmp--; /*
794 * This buffer has been counted twice
795 */
796 info.fragments -= tmp;
797 }
798 }
799 }
800 if (info.fragments < 0)
801 info.fragments = 0;
802 else if (info.fragments > dmap->nbufs)
803 info.fragments = dmap->nbufs;
804
805 info.fragsize = dmap->fragment_size;
806 info.bytes = info.fragments * dmap->fragment_size;
807
808 if (cmd == SNDCTL_DSP_GETISPACE && dmap->qlen)
809 info.bytes -= dmap->counts[dmap->qhead];
810 else
811 {
812 info.fragments = info.bytes / dmap->fragment_size;
813 info.bytes -= dmap->user_counter % dmap->fragment_size;
814 }
815 if (copy_to_user(arg, &info, sizeof(info)))
816 return -EFAULT;
817 return 0;
818
819 case SNDCTL_DSP_SETTRIGGER:
820 if (get_user(bits, (int __user *)arg))
821 return -EFAULT;
822 bits &= audio_devs[dev]->open_mode;
823 if (audio_devs[dev]->d->trigger == NULL)
824 return -EINVAL;
825 if (!(audio_devs[dev]->flags & DMA_DUPLEX) && (bits & PCM_ENABLE_INPUT) &&
826 (bits & PCM_ENABLE_OUTPUT))
827 return -EINVAL;
828
829 if (bits & PCM_ENABLE_INPUT)
830 {
831 spin_lock_irqsave(&dmap_in->lock,flags);
832 changed = (audio_devs[dev]->enable_bits ^ bits) & PCM_ENABLE_INPUT;
833 if (changed && audio_devs[dev]->go)
834 {
835 reorganize_buffers(dev, dmap_in, 1);
836 if ((err = audio_devs[dev]->d->prepare_for_input(dev,
837 dmap_in->fragment_size, dmap_in->nbufs)) < 0) {
838 spin_unlock_irqrestore(&dmap_in->lock,flags);
839 return -err;
840 }
841 dmap_in->dma_mode = DMODE_INPUT;
842 audio_devs[dev]->enable_bits |= PCM_ENABLE_INPUT;
843 DMAbuf_activate_recording(dev, dmap_in);
844 } else
845 audio_devs[dev]->enable_bits &= ~PCM_ENABLE_INPUT;
846 spin_unlock_irqrestore(&dmap_in->lock,flags);
847 }
848 if (bits & PCM_ENABLE_OUTPUT)
849 {
850 spin_lock_irqsave(&dmap_out->lock,flags);
851 changed = (audio_devs[dev]->enable_bits ^ bits) & PCM_ENABLE_OUTPUT;
852 if (changed &&
853 (dmap_out->mapping_flags & DMA_MAP_MAPPED || dmap_out->qlen > 0) &&
854 audio_devs[dev]->go)
855 {
856 if (!(dmap_out->flags & DMA_ALLOC_DONE))
857 reorganize_buffers(dev, dmap_out, 0);
858 dmap_out->dma_mode = DMODE_OUTPUT;
859 audio_devs[dev]->enable_bits |= PCM_ENABLE_OUTPUT;
860 dmap_out->counts[dmap_out->qhead] = dmap_out->fragment_size;
861 DMAbuf_launch_output(dev, dmap_out);
862 } else
863 audio_devs[dev]->enable_bits &= ~PCM_ENABLE_OUTPUT;
864 spin_unlock_irqrestore(&dmap_out->lock,flags);
865 }
866#if 0
867 if (changed && audio_devs[dev]->d->trigger)
868 audio_devs[dev]->d->trigger(dev, bits * audio_devs[dev]->go);
869#endif
870 /* Falls through... */
871
872 case SNDCTL_DSP_GETTRIGGER:
873 ret = audio_devs[dev]->enable_bits;
874 break;
875
876 case SNDCTL_DSP_SETSYNCRO:
877 if (!audio_devs[dev]->d->trigger)
878 return -EINVAL;
879 audio_devs[dev]->d->trigger(dev, 0);
880 audio_devs[dev]->go = 0;
881 return 0;
882
883 case SNDCTL_DSP_GETIPTR:
884 if (!(audio_devs[dev]->open_mode & OPEN_READ))
885 return -EINVAL;
886 spin_lock_irqsave(&dmap_in->lock,flags);
887 cinfo.bytes = dmap_in->byte_counter;
888 cinfo.ptr = DMAbuf_get_buffer_pointer(dev, dmap_in, DMODE_INPUT) & ~3;
889 if (cinfo.ptr < dmap_in->fragment_size && dmap_in->qtail != 0)
890 cinfo.bytes += dmap_in->bytes_in_use; /* Pointer wrap not handled yet */
891 cinfo.blocks = dmap_in->qlen;
892 cinfo.bytes += cinfo.ptr;
893 if (dmap_in->mapping_flags & DMA_MAP_MAPPED)
894 dmap_in->qlen = 0; /* Reset interrupt counter */
895 spin_unlock_irqrestore(&dmap_in->lock,flags);
896 if (copy_to_user(arg, &cinfo, sizeof(cinfo)))
897 return -EFAULT;
898 return 0;
899
900 case SNDCTL_DSP_GETOPTR:
901 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
902 return -EINVAL;
903
904 spin_lock_irqsave(&dmap_out->lock,flags);
905 cinfo.bytes = dmap_out->byte_counter;
906 cinfo.ptr = DMAbuf_get_buffer_pointer(dev, dmap_out, DMODE_OUTPUT) & ~3;
907 if (cinfo.ptr < dmap_out->fragment_size && dmap_out->qhead != 0)
908 cinfo.bytes += dmap_out->bytes_in_use; /* Pointer wrap not handled yet */
909 cinfo.blocks = dmap_out->qlen;
910 cinfo.bytes += cinfo.ptr;
911 if (dmap_out->mapping_flags & DMA_MAP_MAPPED)
912 dmap_out->qlen = 0; /* Reset interrupt counter */
913 spin_unlock_irqrestore(&dmap_out->lock,flags);
914 if (copy_to_user(arg, &cinfo, sizeof(cinfo)))
915 return -EFAULT;
916 return 0;
917
918 case SNDCTL_DSP_GETODELAY:
919 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
920 return -EINVAL;
921 if (!(dmap_out->flags & DMA_ALLOC_DONE))
922 {
923 ret=0;
924 break;
925 }
926 spin_lock_irqsave(&dmap_out->lock,flags);
927 /* Compute number of bytes that have been played */
928 count = DMAbuf_get_buffer_pointer (dev, dmap_out, DMODE_OUTPUT);
929 if (count < dmap_out->fragment_size && dmap_out->qhead != 0)
930 count += dmap_out->bytes_in_use; /* Pointer wrap not handled yet */
931 count += dmap_out->byte_counter;
932 /* Substract current count from the number of bytes written by app */
933 count = dmap_out->user_counter - count;
934 if (count < 0)
935 count = 0;
936 spin_unlock_irqrestore(&dmap_out->lock,flags);
937 ret = count;
938 break;
939
940 case SNDCTL_DSP_POST:
941 if (audio_devs[dev]->dmap_out->qlen > 0)
942 if (!(audio_devs[dev]->dmap_out->flags & DMA_ACTIVE))
943 DMAbuf_launch_output(dev, audio_devs[dev]->dmap_out);
944 return 0;
945
946 case SNDCTL_DSP_GETBLKSIZE:
947 dmap = dmap_out;
948 if (audio_devs[dev]->open_mode & OPEN_WRITE)
949 reorganize_buffers(dev, dmap_out, (audio_devs[dev]->open_mode == OPEN_READ));
950 if (audio_devs[dev]->open_mode == OPEN_READ ||
951 (audio_devs[dev]->flags & DMA_DUPLEX &&
952 audio_devs[dev]->open_mode & OPEN_READ))
953 reorganize_buffers(dev, dmap_in, (audio_devs[dev]->open_mode == OPEN_READ));
954 if (audio_devs[dev]->open_mode == OPEN_READ)
955 dmap = dmap_in;
956 ret = dmap->fragment_size;
957 break;
958
959 case SNDCTL_DSP_SETFRAGMENT:
960 ret = 0;
961 if (get_user(fact, (int __user *)arg))
962 return -EFAULT;
963 if (audio_devs[dev]->open_mode & OPEN_WRITE)
964 ret = dma_set_fragment(dev, dmap_out, fact);
965 if (ret < 0)
966 return ret;
967 if (audio_devs[dev]->open_mode == OPEN_READ ||
968 (audio_devs[dev]->flags & DMA_DUPLEX &&
969 audio_devs[dev]->open_mode & OPEN_READ))
970 ret = dma_set_fragment(dev, dmap_in, fact);
971 if (ret < 0)
972 return ret;
973 if (!arg) /* don't know what this is good for, but preserve old semantics */
974 return 0;
975 break;
976
977 default:
978 if (!audio_devs[dev]->d->ioctl)
979 return -EINVAL;
980 return audio_devs[dev]->d->ioctl(dev, cmd, arg);
981 }
982 return put_user(ret, (int __user *)arg);
983}
diff --git a/sound/oss/audio_syms.c b/sound/oss/audio_syms.c
new file mode 100644
index 000000000000..5da217fcbedd
--- /dev/null
+++ b/sound/oss/audio_syms.c
@@ -0,0 +1,16 @@
1/*
2 * Exported symbols for audio driver.
3 */
4
5#include <linux/module.h>
6
7char audio_syms_symbol;
8
9#include "sound_config.h"
10#include "sound_calls.h"
11
12EXPORT_SYMBOL(DMAbuf_start_dma);
13EXPORT_SYMBOL(DMAbuf_open_dma);
14EXPORT_SYMBOL(DMAbuf_close_dma);
15EXPORT_SYMBOL(DMAbuf_inputintr);
16EXPORT_SYMBOL(DMAbuf_outputintr);
diff --git a/sound/oss/awe_hw.h b/sound/oss/awe_hw.h
new file mode 100644
index 000000000000..7e403ad68152
--- /dev/null
+++ b/sound/oss/awe_hw.h
@@ -0,0 +1,99 @@
1/*
2 * sound/awe_hw.h
3 *
4 * Access routines and definitions for the low level driver for the
5 * Creative AWE32/SB32/AWE64 wave table synth.
6 * version 0.4.4; Jan. 4, 2000
7 *
8 * Copyright (C) 1996-2000 Takashi Iwai
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#ifndef AWE_HW_H_DEF
26#define AWE_HW_H_DEF
27
28/*
29 * Emu-8000 control registers
30 * name(channel) reg, port
31 */
32
33#define awe_cmd_idx(reg,ch) (((reg)<< 5) | (ch))
34
35#define Data0 0 /* 0x620: doubleword r/w */
36#define Data1 1 /* 0xA20: doubleword r/w */
37#define Data2 2 /* 0xA22: word r/w */
38#define Data3 3 /* 0xE20: word r/w */
39#define Pointer 4 /* 0xE22 register pointer r/w */
40
41#define AWE_CPF(ch) awe_cmd_idx(0,ch), Data0 /* DW: current pitch and fractional address */
42#define AWE_PTRX(ch) awe_cmd_idx(1,ch), Data0 /* DW: pitch target and reverb send */
43#define AWE_CVCF(ch) awe_cmd_idx(2,ch), Data0 /* DW: current volume and filter cutoff */
44#define AWE_VTFT(ch) awe_cmd_idx(3,ch), Data0 /* DW: volume and filter cutoff targets */
45#define AWE_0080(ch) awe_cmd_idx(4,ch), Data0 /* DW: ?? */
46#define AWE_00A0(ch) awe_cmd_idx(5,ch), Data0 /* DW: ?? */
47#define AWE_PSST(ch) awe_cmd_idx(6,ch), Data0 /* DW: pan send and loop start address */
48#define AWE_CSL(ch) awe_cmd_idx(7,ch), Data0 /* DW: chorus send and loop end address */
49#define AWE_CCCA(ch) awe_cmd_idx(0,ch), Data1 /* DW: Q, control bits, and current address */
50#define AWE_HWCF4 awe_cmd_idx(1,9), Data1 /* DW: config dw 4 */
51#define AWE_HWCF5 awe_cmd_idx(1,10), Data1 /* DW: config dw 5 */
52#define AWE_HWCF6 awe_cmd_idx(1,13), Data1 /* DW: config dw 6 */
53#define AWE_HWCF7 awe_cmd_idx(1,14), Data1 /* DW: config dw 7? (not documented) */
54#define AWE_SMALR awe_cmd_idx(1,20), Data1 /* DW: sound memory address for left read */
55#define AWE_SMARR awe_cmd_idx(1,21), Data1 /* DW: for right read */
56#define AWE_SMALW awe_cmd_idx(1,22), Data1 /* DW: sound memory address for left write */
57#define AWE_SMARW awe_cmd_idx(1,23), Data1 /* DW: for right write */
58#define AWE_SMLD awe_cmd_idx(1,26), Data1 /* W: sound memory left data */
59#define AWE_SMRD awe_cmd_idx(1,26), Data2 /* W: right data */
60#define AWE_WC awe_cmd_idx(1,27), Data2 /* W: sample counter */
61#define AWE_WC_Cmd awe_cmd_idx(1,27)
62#define AWE_WC_Port Data2
63#define AWE_HWCF1 awe_cmd_idx(1,29), Data1 /* W: config w 1 */
64#define AWE_HWCF2 awe_cmd_idx(1,30), Data1 /* W: config w 2 */
65#define AWE_HWCF3 awe_cmd_idx(1,31), Data1 /* W: config w 3 */
66#define AWE_INIT1(ch) awe_cmd_idx(2,ch), Data1 /* W: init array 1 */
67#define AWE_INIT2(ch) awe_cmd_idx(2,ch), Data2 /* W: init array 2 */
68#define AWE_INIT3(ch) awe_cmd_idx(3,ch), Data1 /* W: init array 3 */
69#define AWE_INIT4(ch) awe_cmd_idx(3,ch), Data2 /* W: init array 4 */
70#define AWE_ENVVOL(ch) awe_cmd_idx(4,ch), Data1 /* W: volume envelope delay */
71#define AWE_DCYSUSV(ch) awe_cmd_idx(5,ch), Data1 /* W: volume envelope sustain and decay */
72#define AWE_ENVVAL(ch) awe_cmd_idx(6,ch), Data1 /* W: modulation envelope delay */
73#define AWE_DCYSUS(ch) awe_cmd_idx(7,ch), Data1 /* W: modulation envelope sustain and decay */
74#define AWE_ATKHLDV(ch) awe_cmd_idx(4,ch), Data2 /* W: volume envelope attack and hold */
75#define AWE_LFO1VAL(ch) awe_cmd_idx(5,ch), Data2 /* W: LFO#1 Delay */
76#define AWE_ATKHLD(ch) awe_cmd_idx(6,ch), Data2 /* W: modulation envelope attack and hold */
77#define AWE_LFO2VAL(ch) awe_cmd_idx(7,ch), Data2 /* W: LFO#2 Delay */
78#define AWE_IP(ch) awe_cmd_idx(0,ch), Data3 /* W: initial pitch */
79#define AWE_IFATN(ch) awe_cmd_idx(1,ch), Data3 /* W: initial filter cutoff and attenuation */
80#define AWE_PEFE(ch) awe_cmd_idx(2,ch), Data3 /* W: pitch and filter envelope heights */
81#define AWE_FMMOD(ch) awe_cmd_idx(3,ch), Data3 /* W: vibrato and filter modulation freq */
82#define AWE_TREMFRQ(ch) awe_cmd_idx(4,ch), Data3 /* W: LFO#1 tremolo amount and freq */
83#define AWE_FM2FRQ2(ch) awe_cmd_idx(5,ch), Data3 /* W: LFO#2 vibrato amount and freq */
84
85/* used during detection (returns ROM version?; not documented in ADIP) */
86#define AWE_U1 0xE0, Data3 /* (R)(W) used in initialization */
87#define AWE_U2(ch) 0xC0+(ch), Data3 /* (W)(W) used in init envelope */
88
89
90#define AWE_MAX_VOICES 32
91#define AWE_NORMAL_VOICES 30 /*30&31 are reserved for DRAM refresh*/
92
93#define AWE_MAX_CHANNELS 32 /* max midi channels (must >= voices) */
94#define AWE_MAX_LAYERS AWE_MAX_VOICES /* maximum number of multiple layers */
95
96#define AWE_DRAM_OFFSET 0x200000
97#define AWE_MAX_DRAM_SIZE (28 * 1024) /* 28 MB is max onboard memory */
98
99#endif
diff --git a/sound/oss/awe_wave.c b/sound/oss/awe_wave.c
new file mode 100644
index 000000000000..d2b9beda8ace
--- /dev/null
+++ b/sound/oss/awe_wave.c
@@ -0,0 +1,6147 @@
1/*
2 * sound/awe_wave.c
3 *
4 * The low level driver for the AWE32/SB32/AWE64 wave table synth.
5 * version 0.4.4; Jan. 4, 2000
6 *
7 * Copyright (C) 1996-2000 Takashi Iwai
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 * Changelog:
26 * Aug 18, 2003, Adam Belay <ambx1@neo.rr.com>
27 * - detection code rewrite
28 */
29
30#include <linux/awe_voice.h>
31#include <linux/config.h>
32#include <linux/init.h>
33#include <linux/module.h>
34#include <linux/string.h>
35#include <linux/pnp.h>
36
37#include "sound_config.h"
38
39#include "awe_wave.h"
40#include "awe_hw.h"
41
42#ifdef AWE_HAS_GUS_COMPATIBILITY
43#include "tuning.h"
44#include <linux/ultrasound.h>
45#endif
46
47/*
48 * debug message
49 */
50
51#ifdef AWE_DEBUG_ON
52#define DEBUG(LVL,XXX) {if (ctrls[AWE_MD_DEBUG_MODE] > LVL) { XXX; }}
53#define ERRMSG(XXX) {if (ctrls[AWE_MD_DEBUG_MODE]) { XXX; }}
54#define FATALERR(XXX) XXX
55#else
56#define DEBUG(LVL,XXX) /**/
57#define ERRMSG(XXX) XXX
58#define FATALERR(XXX) XXX
59#endif
60
61/*
62 * bank and voice record
63 */
64
65typedef struct _sf_list sf_list;
66typedef struct _awe_voice_list awe_voice_list;
67typedef struct _awe_sample_list awe_sample_list;
68
69/* soundfont record */
70struct _sf_list {
71 unsigned short sf_id; /* id number */
72 unsigned short type; /* lock & shared flags */
73 int num_info; /* current info table index */
74 int num_sample; /* current sample table index */
75 int mem_ptr; /* current word byte pointer */
76 awe_voice_list *infos, *last_infos; /* instruments */
77 awe_sample_list *samples, *last_samples; /* samples */
78#ifdef AWE_ALLOW_SAMPLE_SHARING
79 sf_list *shared; /* shared list */
80 unsigned char name[AWE_PATCH_NAME_LEN]; /* sharing id */
81#endif
82 sf_list *next, *prev;
83};
84
85/* instrument list */
86struct _awe_voice_list {
87 awe_voice_info v; /* instrument information */
88 sf_list *holder; /* parent sf_list of this record */
89 unsigned char bank, instr; /* preset number information */
90 char type, disabled; /* type=normal/mapped, disabled=boolean */
91 awe_voice_list *next; /* linked list with same sf_id */
92 awe_voice_list *next_instr; /* instrument list */
93 awe_voice_list *next_bank; /* hash table list */
94};
95
96/* voice list type */
97#define V_ST_NORMAL 0
98#define V_ST_MAPPED 1
99
100/* sample list */
101struct _awe_sample_list {
102 awe_sample_info v; /* sample information */
103 sf_list *holder; /* parent sf_list of this record */
104 awe_sample_list *next; /* linked list with same sf_id */
105};
106
107/* sample and information table */
108static int current_sf_id; /* current number of fonts */
109static int locked_sf_id; /* locked position */
110static sf_list *sfhead, *sftail; /* linked-lists */
111
112#define awe_free_mem_ptr() (sftail ? sftail->mem_ptr : 0)
113#define awe_free_info() (sftail ? sftail->num_info : 0)
114#define awe_free_sample() (sftail ? sftail->num_sample : 0)
115
116#define AWE_MAX_PRESETS 256
117#define AWE_DEFAULT_PRESET 0
118#define AWE_DEFAULT_BANK 0
119#define AWE_DEFAULT_DRUM 0
120#define AWE_DRUM_BANK 128
121
122#define MAX_LAYERS AWE_MAX_VOICES
123
124/* preset table index */
125static awe_voice_list *preset_table[AWE_MAX_PRESETS];
126
127/*
128 * voice table
129 */
130
131/* effects table */
132typedef struct FX_Rec { /* channel effects */
133 unsigned char flags[AWE_FX_END];
134 short val[AWE_FX_END];
135} FX_Rec;
136
137
138/* channel parameters */
139typedef struct _awe_chan_info {
140 int channel; /* channel number */
141 int bank; /* current tone bank */
142 int instr; /* current program */
143 int bender; /* midi pitchbend (-8192 - 8192) */
144 int bender_range; /* midi bender range (x100) */
145 int panning; /* panning (0-127) */
146 int main_vol; /* channel volume (0-127) */
147 int expression_vol; /* midi expression (0-127) */
148 int chan_press; /* channel pressure */
149 int sustained; /* sustain status in MIDI */
150 FX_Rec fx; /* effects */
151 FX_Rec fx_layer[MAX_LAYERS]; /* layer effects */
152} awe_chan_info;
153
154/* voice parameters */
155typedef struct _voice_info {
156 int state;
157#define AWE_ST_OFF (1<<0) /* no sound */
158#define AWE_ST_ON (1<<1) /* playing */
159#define AWE_ST_STANDBY (1<<2) /* stand by for playing */
160#define AWE_ST_SUSTAINED (1<<3) /* sustained */
161#define AWE_ST_MARK (1<<4) /* marked for allocation */
162#define AWE_ST_DRAM (1<<5) /* DRAM read/write */
163#define AWE_ST_FM (1<<6) /* reserved for FM */
164#define AWE_ST_RELEASED (1<<7) /* released */
165
166 int ch; /* midi channel */
167 int key; /* internal key for search */
168 int layer; /* layer number (for channel mode only) */
169 int time; /* allocated time */
170 awe_chan_info *cinfo; /* channel info */
171
172 int note; /* midi key (0-127) */
173 int velocity; /* midi velocity (0-127) */
174 int sostenuto; /* sostenuto on/off */
175 awe_voice_info *sample; /* assigned voice */
176
177 /* EMU8000 parameters */
178 int apitch; /* pitch parameter */
179 int avol; /* volume parameter */
180 int apan; /* panning parameter */
181 int acutoff; /* cutoff parameter */
182 short aaux; /* aux word */
183} voice_info;
184
185/* voice information */
186static voice_info voices[AWE_MAX_VOICES];
187
188#define IS_NO_SOUND(v) (voices[v].state & (AWE_ST_OFF|AWE_ST_RELEASED|AWE_ST_STANDBY|AWE_ST_SUSTAINED))
189#define IS_NO_EFFECT(v) (voices[v].state != AWE_ST_ON)
190#define IS_PLAYING(v) (voices[v].state & (AWE_ST_ON|AWE_ST_SUSTAINED|AWE_ST_RELEASED))
191#define IS_EMPTY(v) (voices[v].state & (AWE_ST_OFF|AWE_ST_MARK|AWE_ST_DRAM|AWE_ST_FM))
192
193
194/* MIDI channel effects information (for hw control) */
195static awe_chan_info channels[AWE_MAX_CHANNELS];
196
197
198/*
199 * global variables
200 */
201
202#ifndef AWE_DEFAULT_BASE_ADDR
203#define AWE_DEFAULT_BASE_ADDR 0 /* autodetect */
204#endif
205
206#ifndef AWE_DEFAULT_MEM_SIZE
207#define AWE_DEFAULT_MEM_SIZE -1 /* autodetect */
208#endif
209
210static int io = AWE_DEFAULT_BASE_ADDR; /* Emu8000 base address */
211static int memsize = AWE_DEFAULT_MEM_SIZE; /* memory size in Kbytes */
212#ifdef CONFIG_PNP
213static int isapnp = -1;
214#else
215static int isapnp;
216#endif
217
218MODULE_AUTHOR("Takashi Iwai <iwai@ww.uni-erlangen.de>");
219MODULE_DESCRIPTION("SB AWE32/64 WaveTable driver");
220MODULE_LICENSE("GPL");
221
222module_param(io, int, 0);
223MODULE_PARM_DESC(io, "base i/o port of Emu8000");
224module_param(memsize, int, 0);
225MODULE_PARM_DESC(memsize, "onboard DRAM size in Kbytes");
226module_param(isapnp, bool, 0);
227MODULE_PARM_DESC(isapnp, "use ISAPnP detection");
228
229/* DRAM start offset */
230static int awe_mem_start = AWE_DRAM_OFFSET;
231
232/* maximum channels for playing */
233static int awe_max_voices = AWE_MAX_VOICES;
234
235static int patch_opened; /* sample already loaded? */
236
237static char atten_relative = FALSE;
238static short atten_offset;
239
240static int awe_present = FALSE; /* awe device present? */
241static int awe_busy = FALSE; /* awe device opened? */
242
243static int my_dev = -1;
244
245#define DEFAULT_DRUM_FLAGS ((1 << 9) | (1 << 25))
246#define IS_DRUM_CHANNEL(c) (drum_flags & (1 << (c)))
247#define DRUM_CHANNEL_ON(c) (drum_flags |= (1 << (c)))
248#define DRUM_CHANNEL_OFF(c) (drum_flags &= ~(1 << (c)))
249static unsigned int drum_flags = DEFAULT_DRUM_FLAGS; /* channel flags */
250
251static int playing_mode = AWE_PLAY_INDIRECT;
252#define SINGLE_LAYER_MODE() (playing_mode == AWE_PLAY_INDIRECT || playing_mode == AWE_PLAY_DIRECT)
253#define MULTI_LAYER_MODE() (playing_mode == AWE_PLAY_MULTI || playing_mode == AWE_PLAY_MULTI2)
254
255static int current_alloc_time; /* voice allocation index for channel mode */
256
257static struct synth_info awe_info = {
258 "AWE32 Synth", /* name */
259 0, /* device */
260 SYNTH_TYPE_SAMPLE, /* synth_type */
261 SAMPLE_TYPE_AWE32, /* synth_subtype */
262 0, /* perc_mode (obsolete) */
263 AWE_MAX_VOICES, /* nr_voices */
264 0, /* nr_drums (obsolete) */
265 400 /* instr_bank_size */
266};
267
268
269static struct voice_alloc_info *voice_alloc; /* set at initialization */
270
271
272/*
273 * function prototypes
274 */
275
276static int awe_request_region(void);
277static void awe_release_region(void);
278
279static void awe_reset_samples(void);
280/* emu8000 chip i/o access */
281static void setup_ports(int p1, int p2, int p3);
282static void awe_poke(unsigned short cmd, unsigned short port, unsigned short data);
283static void awe_poke_dw(unsigned short cmd, unsigned short port, unsigned int data);
284static unsigned short awe_peek(unsigned short cmd, unsigned short port);
285static unsigned int awe_peek_dw(unsigned short cmd, unsigned short port);
286static void awe_wait(unsigned short delay);
287
288/* initialize emu8000 chip */
289static void awe_initialize(void);
290
291/* set voice parameters */
292static void awe_init_ctrl_parms(int init_all);
293static void awe_init_voice_info(awe_voice_info *vp);
294static void awe_init_voice_parm(awe_voice_parm *pp);
295#ifdef AWE_HAS_GUS_COMPATIBILITY
296static int freq_to_note(int freq);
297static int calc_rate_offset(int Hz);
298/*static int calc_parm_delay(int msec);*/
299static int calc_parm_hold(int msec);
300static int calc_parm_attack(int msec);
301static int calc_parm_decay(int msec);
302static int calc_parm_search(int msec, short *table);
303#endif /* gus compat */
304
305/* turn on/off note */
306static void awe_note_on(int voice);
307static void awe_note_off(int voice);
308static void awe_terminate(int voice);
309static void awe_exclusive_off(int voice);
310static void awe_note_off_all(int do_sustain);
311
312/* calculate voice parameters */
313typedef void (*fx_affect_func)(int voice, int forced);
314static void awe_set_pitch(int voice, int forced);
315static void awe_set_voice_pitch(int voice, int forced);
316static void awe_set_volume(int voice, int forced);
317static void awe_set_voice_vol(int voice, int forced);
318static void awe_set_pan(int voice, int forced);
319static void awe_fx_fmmod(int voice, int forced);
320static void awe_fx_tremfrq(int voice, int forced);
321static void awe_fx_fm2frq2(int voice, int forced);
322static void awe_fx_filterQ(int voice, int forced);
323static void awe_calc_pitch(int voice);
324#ifdef AWE_HAS_GUS_COMPATIBILITY
325static void awe_calc_pitch_from_freq(int voice, int freq);
326#endif
327static void awe_calc_volume(int voice);
328static void awe_update_volume(void);
329static void awe_change_master_volume(short val);
330static void awe_voice_init(int voice, int init_all);
331static void awe_channel_init(int ch, int init_all);
332static void awe_fx_init(int ch);
333static void awe_send_effect(int voice, int layer, int type, int val);
334static void awe_modwheel_change(int voice, int value);
335
336/* sequencer interface */
337static int awe_open(int dev, int mode);
338static void awe_close(int dev);
339static int awe_ioctl(int dev, unsigned int cmd, void __user * arg);
340static int awe_kill_note(int dev, int voice, int note, int velocity);
341static int awe_start_note(int dev, int v, int note_num, int volume);
342static int awe_set_instr(int dev, int voice, int instr_no);
343static int awe_set_instr_2(int dev, int voice, int instr_no);
344static void awe_reset(int dev);
345static void awe_hw_control(int dev, unsigned char *event);
346static int awe_load_patch(int dev, int format, const char __user *addr,
347 int offs, int count, int pmgr_flag);
348static void awe_aftertouch(int dev, int voice, int pressure);
349static void awe_controller(int dev, int voice, int ctrl_num, int value);
350static void awe_panning(int dev, int voice, int value);
351static void awe_volume_method(int dev, int mode);
352static void awe_bender(int dev, int voice, int value);
353static int awe_alloc(int dev, int chn, int note, struct voice_alloc_info *alloc);
354static void awe_setup_voice(int dev, int voice, int chn);
355
356#define awe_key_pressure(dev,voice,key,press) awe_start_note(dev,voice,(key)+128,press)
357
358/* hardware controls */
359#ifdef AWE_HAS_GUS_COMPATIBILITY
360static void awe_hw_gus_control(int dev, int cmd, unsigned char *event);
361#endif
362static void awe_hw_awe_control(int dev, int cmd, unsigned char *event);
363static void awe_voice_change(int voice, fx_affect_func func);
364static void awe_sostenuto_on(int voice, int forced);
365static void awe_sustain_off(int voice, int forced);
366static void awe_terminate_and_init(int voice, int forced);
367
368/* voice search */
369static int awe_search_key(int bank, int preset, int note);
370static awe_voice_list *awe_search_instr(int bank, int preset, int note);
371static int awe_search_multi_voices(awe_voice_list *rec, int note, int velocity, awe_voice_info **vlist);
372static void awe_alloc_multi_voices(int ch, int note, int velocity, int key);
373static void awe_alloc_one_voice(int voice, int note, int velocity);
374static int awe_clear_voice(void);
375
376/* load / remove patches */
377static int awe_open_patch(awe_patch_info *patch, const char __user *addr, int count);
378static int awe_close_patch(awe_patch_info *patch, const char __user *addr, int count);
379static int awe_unload_patch(awe_patch_info *patch, const char __user *addr, int count);
380static int awe_load_info(awe_patch_info *patch, const char __user *addr, int count);
381static int awe_remove_info(awe_patch_info *patch, const char __user *addr, int count);
382static int awe_load_data(awe_patch_info *patch, const char __user *addr, int count);
383static int awe_replace_data(awe_patch_info *patch, const char __user *addr, int count);
384static int awe_load_map(awe_patch_info *patch, const char __user *addr, int count);
385#ifdef AWE_HAS_GUS_COMPATIBILITY
386static int awe_load_guspatch(const char __user *addr, int offs, int size, int pmgr_flag);
387#endif
388/*static int awe_probe_info(awe_patch_info *patch, const char __user *addr, int count);*/
389static int awe_probe_data(awe_patch_info *patch, const char __user *addr, int count);
390static sf_list *check_patch_opened(int type, char *name);
391static int awe_write_wave_data(const char __user *addr, int offset, awe_sample_list *sp, int channels);
392static int awe_create_sf(int type, char *name);
393static void awe_free_sf(sf_list *sf);
394static void add_sf_info(sf_list *sf, awe_voice_list *rec);
395static void add_sf_sample(sf_list *sf, awe_sample_list *smp);
396static void purge_old_list(awe_voice_list *rec, awe_voice_list *next);
397static void add_info_list(awe_voice_list *rec);
398static void awe_remove_samples(int sf_id);
399static void rebuild_preset_list(void);
400static short awe_set_sample(awe_voice_list *rec);
401static awe_sample_list *search_sample_index(sf_list *sf, int sample);
402
403static int is_identical_holder(sf_list *sf1, sf_list *sf2);
404#ifdef AWE_ALLOW_SAMPLE_SHARING
405static int is_identical_name(unsigned char *name, sf_list *p);
406static int is_shared_sf(unsigned char *name);
407static int info_duplicated(sf_list *sf, awe_voice_list *rec);
408#endif /* allow sharing */
409
410/* lowlevel functions */
411static void awe_init_audio(void);
412static void awe_init_dma(void);
413static void awe_init_array(void);
414static void awe_send_array(unsigned short *data);
415static void awe_tweak_voice(int voice);
416static void awe_tweak(void);
417static void awe_init_fm(void);
418static int awe_open_dram_for_write(int offset, int channels);
419static void awe_open_dram_for_check(void);
420static void awe_close_dram(void);
421/*static void awe_write_dram(unsigned short c);*/
422static int awe_detect_base(int addr);
423static int awe_detect(void);
424static void awe_check_dram(void);
425static int awe_load_chorus_fx(awe_patch_info *patch, const char __user *addr, int count);
426static void awe_set_chorus_mode(int mode);
427static void awe_update_chorus_mode(void);
428static int awe_load_reverb_fx(awe_patch_info *patch, const char __user *addr, int count);
429static void awe_set_reverb_mode(int mode);
430static void awe_update_reverb_mode(void);
431static void awe_equalizer(int bass, int treble);
432static void awe_update_equalizer(void);
433
434#ifdef CONFIG_AWE32_MIXER
435static void attach_mixer(void);
436static void unload_mixer(void);
437#endif
438
439#ifdef CONFIG_AWE32_MIDIEMU
440static void attach_midiemu(void);
441static void unload_midiemu(void);
442#endif
443
444#define limitvalue(x, a, b) if ((x) < (a)) (x) = (a); else if ((x) > (b)) (x) = (b)
445
446/*
447 * control parameters
448 */
449
450
451#ifdef AWE_USE_NEW_VOLUME_CALC
452#define DEF_VOLUME_CALC TRUE
453#else
454#define DEF_VOLUME_CALC FALSE
455#endif /* new volume */
456
457#define DEF_ZERO_ATTEN 32 /* 12dB below */
458#define DEF_MOD_SENSE 18
459#define DEF_CHORUS_MODE 2
460#define DEF_REVERB_MODE 4
461#define DEF_BASS_LEVEL 5
462#define DEF_TREBLE_LEVEL 9
463
464static struct CtrlParmsDef {
465 int value;
466 int init_each_time;
467 void (*update)(void);
468} ctrl_parms[AWE_MD_END] = {
469 {0,0, NULL}, {0,0, NULL}, /* <-- not used */
470 {AWE_VERSION_NUMBER, FALSE, NULL},
471 {TRUE, FALSE, NULL}, /* exclusive */
472 {TRUE, FALSE, NULL}, /* realpan */
473 {AWE_DEFAULT_BANK, FALSE, NULL}, /* gusbank */
474 {FALSE, TRUE, NULL}, /* keep effect */
475 {DEF_ZERO_ATTEN, FALSE, awe_update_volume}, /* zero_atten */
476 {FALSE, FALSE, NULL}, /* chn_prior */
477 {DEF_MOD_SENSE, FALSE, NULL}, /* modwheel sense */
478 {AWE_DEFAULT_PRESET, FALSE, NULL}, /* def_preset */
479 {AWE_DEFAULT_BANK, FALSE, NULL}, /* def_bank */
480 {AWE_DEFAULT_DRUM, FALSE, NULL}, /* def_drum */
481 {FALSE, FALSE, NULL}, /* toggle_drum_bank */
482 {DEF_VOLUME_CALC, FALSE, awe_update_volume}, /* new_volume_calc */
483 {DEF_CHORUS_MODE, FALSE, awe_update_chorus_mode}, /* chorus mode */
484 {DEF_REVERB_MODE, FALSE, awe_update_reverb_mode}, /* reverb mode */
485 {DEF_BASS_LEVEL, FALSE, awe_update_equalizer}, /* bass level */
486 {DEF_TREBLE_LEVEL, FALSE, awe_update_equalizer}, /* treble level */
487 {0, FALSE, NULL}, /* debug mode */
488 {FALSE, FALSE, NULL}, /* pan exchange */
489};
490
491static int ctrls[AWE_MD_END];
492
493
494/*
495 * synth operation table
496 */
497
498static struct synth_operations awe_operations =
499{
500 .owner = THIS_MODULE,
501 .id = "EMU8K",
502 .info = &awe_info,
503 .midi_dev = 0,
504 .synth_type = SYNTH_TYPE_SAMPLE,
505 .synth_subtype = SAMPLE_TYPE_AWE32,
506 .open = awe_open,
507 .close = awe_close,
508 .ioctl = awe_ioctl,
509 .kill_note = awe_kill_note,
510 .start_note = awe_start_note,
511 .set_instr = awe_set_instr_2,
512 .reset = awe_reset,
513 .hw_control = awe_hw_control,
514 .load_patch = awe_load_patch,
515 .aftertouch = awe_aftertouch,
516 .controller = awe_controller,
517 .panning = awe_panning,
518 .volume_method = awe_volume_method,
519 .bender = awe_bender,
520 .alloc_voice = awe_alloc,
521 .setup_voice = awe_setup_voice
522};
523
524static void free_tables(void)
525{
526 if (sftail) {
527 sf_list *p, *prev;
528 for (p = sftail; p; p = prev) {
529 prev = p->prev;
530 awe_free_sf(p);
531 }
532 }
533 sfhead = sftail = NULL;
534}
535
536/*
537 * clear sample tables
538 */
539
540static void
541awe_reset_samples(void)
542{
543 /* free all bank tables */
544 memset(preset_table, 0, sizeof(preset_table));
545 free_tables();
546
547 current_sf_id = 0;
548 locked_sf_id = 0;
549 patch_opened = 0;
550}
551
552
553/*
554 * EMU register access
555 */
556
557/* select a given AWE32 pointer */
558static int awe_ports[5];
559static int port_setuped = FALSE;
560static int awe_cur_cmd = -1;
561#define awe_set_cmd(cmd) \
562if (awe_cur_cmd != cmd) { outw(cmd, awe_ports[Pointer]); awe_cur_cmd = cmd; }
563
564/* write 16bit data */
565static void
566awe_poke(unsigned short cmd, unsigned short port, unsigned short data)
567{
568 awe_set_cmd(cmd);
569 outw(data, awe_ports[port]);
570}
571
572/* write 32bit data */
573static void
574awe_poke_dw(unsigned short cmd, unsigned short port, unsigned int data)
575{
576 unsigned short addr = awe_ports[port];
577 awe_set_cmd(cmd);
578 outw(data, addr); /* write lower 16 bits */
579 outw(data >> 16, addr + 2); /* write higher 16 bits */
580}
581
582/* read 16bit data */
583static unsigned short
584awe_peek(unsigned short cmd, unsigned short port)
585{
586 unsigned short k;
587 awe_set_cmd(cmd);
588 k = inw(awe_ports[port]);
589 return k;
590}
591
592/* read 32bit data */
593static unsigned int
594awe_peek_dw(unsigned short cmd, unsigned short port)
595{
596 unsigned int k1, k2;
597 unsigned short addr = awe_ports[port];
598 awe_set_cmd(cmd);
599 k1 = inw(addr);
600 k2 = inw(addr + 2);
601 k1 |= k2 << 16;
602 return k1;
603}
604
605/* wait delay number of AWE32 44100Hz clocks */
606#ifdef WAIT_BY_LOOP /* wait by loop -- that's not good.. */
607static void
608awe_wait(unsigned short delay)
609{
610 unsigned short clock, target;
611 unsigned short port = awe_ports[AWE_WC_Port];
612 int counter;
613
614 /* sample counter */
615 awe_set_cmd(AWE_WC_Cmd);
616 clock = (unsigned short)inw(port);
617 target = clock + delay;
618 counter = 0;
619 if (target < clock) {
620 for (; (unsigned short)inw(port) > target; counter++)
621 if (counter > 65536)
622 break;
623 }
624 for (; (unsigned short)inw(port) < target; counter++)
625 if (counter > 65536)
626 break;
627}
628#else
629
630static void awe_wait(unsigned short delay)
631{
632 current->state = TASK_INTERRUPTIBLE;
633 schedule_timeout((HZ*(unsigned long)delay + 44099)/44100);
634}
635/*
636static void awe_wait(unsigned short delay)
637{
638 udelay(((unsigned long)delay * 1000000L + 44099) / 44100);
639}
640*/
641#endif /* wait by loop */
642
643/* write a word data */
644#define awe_write_dram(c) awe_poke(AWE_SMLD, c)
645
646/*
647 * AWE32 voice parameters
648 */
649
650/* initialize voice_info record */
651static void
652awe_init_voice_info(awe_voice_info *vp)
653{
654 vp->sample = 0;
655 vp->rate_offset = 0;
656
657 vp->start = 0;
658 vp->end = 0;
659 vp->loopstart = 0;
660 vp->loopend = 0;
661 vp->mode = 0;
662 vp->root = 60;
663 vp->tune = 0;
664 vp->low = 0;
665 vp->high = 127;
666 vp->vellow = 0;
667 vp->velhigh = 127;
668
669 vp->fixkey = -1;
670 vp->fixvel = -1;
671 vp->fixpan = -1;
672 vp->pan = -1;
673
674 vp->exclusiveClass = 0;
675 vp->amplitude = 127;
676 vp->attenuation = 0;
677 vp->scaleTuning = 100;
678
679 awe_init_voice_parm(&vp->parm);
680}
681
682/* initialize voice_parm record:
683 * Env1/2: delay=0, attack=0, hold=0, sustain=0, decay=0, release=0.
684 * Vibrato and Tremolo effects are zero.
685 * Cutoff is maximum.
686 * Chorus and Reverb effects are zero.
687 */
688static void
689awe_init_voice_parm(awe_voice_parm *pp)
690{
691 pp->moddelay = 0x8000;
692 pp->modatkhld = 0x7f7f;
693 pp->moddcysus = 0x7f7f;
694 pp->modrelease = 0x807f;
695 pp->modkeyhold = 0;
696 pp->modkeydecay = 0;
697
698 pp->voldelay = 0x8000;
699 pp->volatkhld = 0x7f7f;
700 pp->voldcysus = 0x7f7f;
701 pp->volrelease = 0x807f;
702 pp->volkeyhold = 0;
703 pp->volkeydecay = 0;
704
705 pp->lfo1delay = 0x8000;
706 pp->lfo2delay = 0x8000;
707 pp->pefe = 0;
708
709 pp->fmmod = 0;
710 pp->tremfrq = 0;
711 pp->fm2frq2 = 0;
712
713 pp->cutoff = 0xff;
714 pp->filterQ = 0;
715
716 pp->chorus = 0;
717 pp->reverb = 0;
718}
719
720
721#ifdef AWE_HAS_GUS_COMPATIBILITY
722
723/* convert frequency mHz to abstract cents (= midi key * 100) */
724static int
725freq_to_note(int mHz)
726{
727 /* abscents = log(mHz/8176) / log(2) * 1200 */
728 unsigned int max_val = (unsigned int)0xffffffff / 10000;
729 int i, times;
730 unsigned int base;
731 unsigned int freq;
732 int note, tune;
733
734 if (mHz == 0)
735 return 0;
736 if (mHz < 0)
737 return 12799; /* maximum */
738
739 freq = mHz;
740 note = 0;
741 for (base = 8176 * 2; freq >= base; base *= 2) {
742 note += 12;
743 if (note >= 128) /* over maximum */
744 return 12799;
745 }
746 base /= 2;
747
748 /* to avoid overflow... */
749 times = 10000;
750 while (freq > max_val) {
751 max_val *= 10;
752 times /= 10;
753 base /= 10;
754 }
755
756 freq = freq * times / base;
757 for (i = 0; i < 12; i++) {
758 if (freq < semitone_tuning[i+1])
759 break;
760 note++;
761 }
762
763 tune = 0;
764 freq = freq * 10000 / semitone_tuning[i];
765 for (i = 0; i < 100; i++) {
766 if (freq < cent_tuning[i+1])
767 break;
768 tune++;
769 }
770
771 return note * 100 + tune;
772}
773
774
775/* convert Hz to AWE32 rate offset:
776 * sample pitch offset for the specified sample rate
777 * rate=44100 is no offset, each 4096 is 1 octave (twice).
778 * eg, when rate is 22050, this offset becomes -4096.
779 */
780static int
781calc_rate_offset(int Hz)
782{
783 /* offset = log(Hz / 44100) / log(2) * 4096 */
784 int freq, base, i;
785
786 /* maybe smaller than max (44100Hz) */
787 if (Hz <= 0 || Hz >= 44100) return 0;
788
789 base = 0;
790 for (freq = Hz * 2; freq < 44100; freq *= 2)
791 base++;
792 base *= 1200;
793
794 freq = 44100 * 10000 / (freq/2);
795 for (i = 0; i < 12; i++) {
796 if (freq < semitone_tuning[i+1])
797 break;
798 base += 100;
799 }
800 freq = freq * 10000 / semitone_tuning[i];
801 for (i = 0; i < 100; i++) {
802 if (freq < cent_tuning[i+1])
803 break;
804 base++;
805 }
806 return -base * 4096 / 1200;
807}
808
809
810/*
811 * convert envelope time parameter to AWE32 raw parameter
812 */
813
814/* attack & decay/release time table (msec) */
815static short attack_time_tbl[128] = {
81632767, 32767, 5989, 4235, 2994, 2518, 2117, 1780, 1497, 1373, 1259, 1154, 1058, 970, 890, 816,
817707, 691, 662, 634, 607, 581, 557, 533, 510, 489, 468, 448, 429, 411, 393, 377,
818361, 345, 331, 317, 303, 290, 278, 266, 255, 244, 234, 224, 214, 205, 196, 188,
819180, 172, 165, 158, 151, 145, 139, 133, 127, 122, 117, 112, 107, 102, 98, 94,
82090, 86, 82, 79, 75, 72, 69, 66, 63, 61, 58, 56, 53, 51, 49, 47,
82145, 43, 41, 39, 37, 36, 34, 33, 31, 30, 29, 28, 26, 25, 24, 23,
82222, 21, 20, 19, 19, 18, 17, 16, 16, 15, 15, 14, 13, 13, 12, 12,
82311, 11, 10, 10, 10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 6, 0,
824};
825
826static short decay_time_tbl[128] = {
82732767, 32767, 22614, 15990, 11307, 9508, 7995, 6723, 5653, 5184, 4754, 4359, 3997, 3665, 3361, 3082,
8282828, 2765, 2648, 2535, 2428, 2325, 2226, 2132, 2042, 1955, 1872, 1793, 1717, 1644, 1574, 1507,
8291443, 1382, 1324, 1267, 1214, 1162, 1113, 1066, 978, 936, 897, 859, 822, 787, 754, 722,
830691, 662, 634, 607, 581, 557, 533, 510, 489, 468, 448, 429, 411, 393, 377, 361,
831345, 331, 317, 303, 290, 278, 266, 255, 244, 234, 224, 214, 205, 196, 188, 180,
832172, 165, 158, 151, 145, 139, 133, 127, 122, 117, 112, 107, 102, 98, 94, 90,
83386, 82, 79, 75, 72, 69, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45,
83443, 41, 39, 37, 36, 34, 33, 31, 30, 29, 28, 26, 25, 24, 23, 22,
835};
836
837#define calc_parm_delay(msec) (0x8000 - (msec) * 1000 / 725);
838
839/* delay time = 0x8000 - msec/92 */
840static int
841calc_parm_hold(int msec)
842{
843 int val = (0x7f * 92 - msec) / 92;
844 if (val < 1) val = 1;
845 if (val > 127) val = 127;
846 return val;
847}
848
849/* attack time: search from time table */
850static int
851calc_parm_attack(int msec)
852{
853 return calc_parm_search(msec, attack_time_tbl);
854}
855
856/* decay/release time: search from time table */
857static int
858calc_parm_decay(int msec)
859{
860 return calc_parm_search(msec, decay_time_tbl);
861}
862
863/* search an index for specified time from given time table */
864static int
865calc_parm_search(int msec, short *table)
866{
867 int left = 1, right = 127, mid;
868 while (left < right) {
869 mid = (left + right) / 2;
870 if (msec < (int)table[mid])
871 left = mid + 1;
872 else
873 right = mid;
874 }
875 return left;
876}
877#endif /* AWE_HAS_GUS_COMPATIBILITY */
878
879
880/*
881 * effects table
882 */
883
884/* set an effect value */
885#define FX_FLAG_OFF 0
886#define FX_FLAG_SET 1
887#define FX_FLAG_ADD 2
888
889#define FX_SET(rec,type,value) \
890 ((rec)->flags[type] = FX_FLAG_SET, (rec)->val[type] = (value))
891#define FX_ADD(rec,type,value) \
892 ((rec)->flags[type] = FX_FLAG_ADD, (rec)->val[type] = (value))
893#define FX_UNSET(rec,type) \
894 ((rec)->flags[type] = FX_FLAG_OFF, (rec)->val[type] = 0)
895
896/* check the effect value is set */
897#define FX_ON(rec,type) ((rec)->flags[type])
898
899#define PARM_BYTE 0
900#define PARM_WORD 1
901#define PARM_SIGN 2
902
903static struct PARM_DEFS {
904 int type; /* byte or word */
905 int low, high; /* value range */
906 fx_affect_func realtime; /* realtime paramater change */
907} parm_defs[] = {
908 {PARM_WORD, 0, 0x8000, NULL}, /* env1 delay */
909 {PARM_BYTE, 1, 0x7f, NULL}, /* env1 attack */
910 {PARM_BYTE, 0, 0x7e, NULL}, /* env1 hold */
911 {PARM_BYTE, 1, 0x7f, NULL}, /* env1 decay */
912 {PARM_BYTE, 1, 0x7f, NULL}, /* env1 release */
913 {PARM_BYTE, 0, 0x7f, NULL}, /* env1 sustain */
914 {PARM_BYTE, 0, 0xff, NULL}, /* env1 pitch */
915 {PARM_BYTE, 0, 0xff, NULL}, /* env1 cutoff */
916
917 {PARM_WORD, 0, 0x8000, NULL}, /* env2 delay */
918 {PARM_BYTE, 1, 0x7f, NULL}, /* env2 attack */
919 {PARM_BYTE, 0, 0x7e, NULL}, /* env2 hold */
920 {PARM_BYTE, 1, 0x7f, NULL}, /* env2 decay */
921 {PARM_BYTE, 1, 0x7f, NULL}, /* env2 release */
922 {PARM_BYTE, 0, 0x7f, NULL}, /* env2 sustain */
923
924 {PARM_WORD, 0, 0x8000, NULL}, /* lfo1 delay */
925 {PARM_BYTE, 0, 0xff, awe_fx_tremfrq}, /* lfo1 freq */
926 {PARM_SIGN, -128, 127, awe_fx_tremfrq}, /* lfo1 volume */
927 {PARM_SIGN, -128, 127, awe_fx_fmmod}, /* lfo1 pitch */
928 {PARM_BYTE, 0, 0xff, awe_fx_fmmod}, /* lfo1 cutoff */
929
930 {PARM_WORD, 0, 0x8000, NULL}, /* lfo2 delay */
931 {PARM_BYTE, 0, 0xff, awe_fx_fm2frq2}, /* lfo2 freq */
932 {PARM_SIGN, -128, 127, awe_fx_fm2frq2}, /* lfo2 pitch */
933
934 {PARM_WORD, 0, 0xffff, awe_set_voice_pitch}, /* initial pitch */
935 {PARM_BYTE, 0, 0xff, NULL}, /* chorus */
936 {PARM_BYTE, 0, 0xff, NULL}, /* reverb */
937 {PARM_BYTE, 0, 0xff, awe_set_volume}, /* initial cutoff */
938 {PARM_BYTE, 0, 15, awe_fx_filterQ}, /* initial resonance */
939
940 {PARM_WORD, 0, 0xffff, NULL}, /* sample start */
941 {PARM_WORD, 0, 0xffff, NULL}, /* loop start */
942 {PARM_WORD, 0, 0xffff, NULL}, /* loop end */
943 {PARM_WORD, 0, 0xffff, NULL}, /* coarse sample start */
944 {PARM_WORD, 0, 0xffff, NULL}, /* coarse loop start */
945 {PARM_WORD, 0, 0xffff, NULL}, /* coarse loop end */
946 {PARM_BYTE, 0, 0xff, awe_set_volume}, /* initial attenuation */
947};
948
949
950static unsigned char
951FX_BYTE(FX_Rec *rec, FX_Rec *lay, int type, unsigned char value)
952{
953 int effect = 0;
954 int on = 0;
955 if (lay && (on = FX_ON(lay, type)) != 0)
956 effect = lay->val[type];
957 if (!on && (on = FX_ON(rec, type)) != 0)
958 effect = rec->val[type];
959 if (on == FX_FLAG_ADD) {
960 if (parm_defs[type].type == PARM_SIGN) {
961 if (value > 0x7f)
962 effect += (int)value - 0x100;
963 else
964 effect += (int)value;
965 } else {
966 effect += (int)value;
967 }
968 }
969 if (on) {
970 if (effect < parm_defs[type].low)
971 effect = parm_defs[type].low;
972 else if (effect > parm_defs[type].high)
973 effect = parm_defs[type].high;
974 return (unsigned char)effect;
975 }
976 return value;
977}
978
979/* get word effect value */
980static unsigned short
981FX_WORD(FX_Rec *rec, FX_Rec *lay, int type, unsigned short value)
982{
983 int effect = 0;
984 int on = 0;
985 if (lay && (on = FX_ON(lay, type)) != 0)
986 effect = lay->val[type];
987 if (!on && (on = FX_ON(rec, type)) != 0)
988 effect = rec->val[type];
989 if (on == FX_FLAG_ADD)
990 effect += (int)value;
991 if (on) {
992 if (effect < parm_defs[type].low)
993 effect = parm_defs[type].low;
994 else if (effect > parm_defs[type].high)
995 effect = parm_defs[type].high;
996 return (unsigned short)effect;
997 }
998 return value;
999}
1000
1001/* get word (upper=type1/lower=type2) effect value */
1002static unsigned short
1003FX_COMB(FX_Rec *rec, FX_Rec *lay, int type1, int type2, unsigned short value)
1004{
1005 unsigned short tmp;
1006 tmp = FX_BYTE(rec, lay, type1, (unsigned char)(value >> 8));
1007 tmp <<= 8;
1008 tmp |= FX_BYTE(rec, lay, type2, (unsigned char)(value & 0xff));
1009 return tmp;
1010}
1011
1012/* address offset */
1013static int
1014FX_OFFSET(FX_Rec *rec, FX_Rec *lay, int lo, int hi, int mode)
1015{
1016 int addr = 0;
1017 if (lay && FX_ON(lay, hi))
1018 addr = (short)lay->val[hi];
1019 else if (FX_ON(rec, hi))
1020 addr = (short)rec->val[hi];
1021 addr = addr << 15;
1022 if (lay && FX_ON(lay, lo))
1023 addr += (short)lay->val[lo];
1024 else if (FX_ON(rec, lo))
1025 addr += (short)rec->val[lo];
1026 if (!(mode & AWE_SAMPLE_8BITS))
1027 addr /= 2;
1028 return addr;
1029}
1030
1031
1032/*
1033 * turn on/off sample
1034 */
1035
1036/* table for volume target calculation */
1037static unsigned short voltarget[16] = {
1038 0xEAC0, 0XE0C8, 0XD740, 0XCE20, 0XC560, 0XBD08, 0XB500, 0XAD58,
1039 0XA5F8, 0X9EF0, 0X9830, 0X91C0, 0X8B90, 0X85A8, 0X8000, 0X7A90
1040};
1041
1042static void
1043awe_note_on(int voice)
1044{
1045 unsigned int temp;
1046 int addr;
1047 int vtarget, ftarget, ptarget, pitch;
1048 awe_voice_info *vp;
1049 awe_voice_parm_block *parm;
1050 FX_Rec *fx = &voices[voice].cinfo->fx;
1051 FX_Rec *fx_lay = NULL;
1052 if (voices[voice].layer < MAX_LAYERS)
1053 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1054
1055 /* A voice sample must assigned before calling */
1056 if ((vp = voices[voice].sample) == NULL || vp->index == 0)
1057 return;
1058
1059 parm = (awe_voice_parm_block*)&vp->parm;
1060
1061 /* channel to be silent and idle */
1062 awe_poke(AWE_DCYSUSV(voice), 0x0080);
1063 awe_poke(AWE_VTFT(voice), 0x0000FFFF);
1064 awe_poke(AWE_CVCF(voice), 0x0000FFFF);
1065 awe_poke(AWE_PTRX(voice), 0);
1066 awe_poke(AWE_CPF(voice), 0);
1067
1068 /* set pitch offset */
1069 awe_set_pitch(voice, TRUE);
1070
1071 /* modulation & volume envelope */
1072 if (parm->modatk >= 0x80 && parm->moddelay >= 0x8000) {
1073 awe_poke(AWE_ENVVAL(voice), 0xBFFF);
1074 pitch = (parm->env1pit<<4) + voices[voice].apitch;
1075 if (pitch > 0xffff) pitch = 0xffff;
1076 /* calculate filter target */
1077 ftarget = parm->cutoff + parm->env1fc;
1078 limitvalue(ftarget, 0, 255);
1079 ftarget <<= 8;
1080 } else {
1081 awe_poke(AWE_ENVVAL(voice),
1082 FX_WORD(fx, fx_lay, AWE_FX_ENV1_DELAY, parm->moddelay));
1083 ftarget = parm->cutoff;
1084 ftarget <<= 8;
1085 pitch = voices[voice].apitch;
1086 }
1087
1088 /* calcualte pitch target */
1089 if (pitch != 0xffff) {
1090 ptarget = 1 << (pitch >> 12);
1091 if (pitch & 0x800) ptarget += (ptarget*0x102e)/0x2710;
1092 if (pitch & 0x400) ptarget += (ptarget*0x764)/0x2710;
1093 if (pitch & 0x200) ptarget += (ptarget*0x389)/0x2710;
1094 ptarget += (ptarget>>1);
1095 if (ptarget > 0xffff) ptarget = 0xffff;
1096
1097 } else ptarget = 0xffff;
1098 if (parm->modatk >= 0x80)
1099 awe_poke(AWE_ATKHLD(voice),
1100 FX_BYTE(fx, fx_lay, AWE_FX_ENV1_HOLD, parm->modhld) << 8 | 0x7f);
1101 else
1102 awe_poke(AWE_ATKHLD(voice),
1103 FX_COMB(fx, fx_lay, AWE_FX_ENV1_HOLD, AWE_FX_ENV1_ATTACK,
1104 vp->parm.modatkhld));
1105 awe_poke(AWE_DCYSUS(voice),
1106 FX_COMB(fx, fx_lay, AWE_FX_ENV1_SUSTAIN, AWE_FX_ENV1_DECAY,
1107 vp->parm.moddcysus));
1108
1109 if (parm->volatk >= 0x80 && parm->voldelay >= 0x8000) {
1110 awe_poke(AWE_ENVVOL(voice), 0xBFFF);
1111 vtarget = voltarget[voices[voice].avol%0x10]>>(voices[voice].avol>>4);
1112 } else {
1113 awe_poke(AWE_ENVVOL(voice),
1114 FX_WORD(fx, fx_lay, AWE_FX_ENV2_DELAY, vp->parm.voldelay));
1115 vtarget = 0;
1116 }
1117 if (parm->volatk >= 0x80)
1118 awe_poke(AWE_ATKHLDV(voice),
1119 FX_BYTE(fx, fx_lay, AWE_FX_ENV2_HOLD, parm->volhld) << 8 | 0x7f);
1120 else
1121 awe_poke(AWE_ATKHLDV(voice),
1122 FX_COMB(fx, fx_lay, AWE_FX_ENV2_HOLD, AWE_FX_ENV2_ATTACK,
1123 vp->parm.volatkhld));
1124 /* decay/sustain parameter for volume envelope must be set at last */
1125
1126 /* cutoff and volume */
1127 awe_set_volume(voice, TRUE);
1128
1129 /* modulation envelope heights */
1130 awe_poke(AWE_PEFE(voice),
1131 FX_COMB(fx, fx_lay, AWE_FX_ENV1_PITCH, AWE_FX_ENV1_CUTOFF,
1132 vp->parm.pefe));
1133
1134 /* lfo1/2 delay */
1135 awe_poke(AWE_LFO1VAL(voice),
1136 FX_WORD(fx, fx_lay, AWE_FX_LFO1_DELAY, vp->parm.lfo1delay));
1137 awe_poke(AWE_LFO2VAL(voice),
1138 FX_WORD(fx, fx_lay, AWE_FX_LFO2_DELAY, vp->parm.lfo2delay));
1139
1140 /* lfo1 pitch & cutoff shift */
1141 awe_fx_fmmod(voice, TRUE);
1142 /* lfo1 volume & freq */
1143 awe_fx_tremfrq(voice, TRUE);
1144 /* lfo2 pitch & freq */
1145 awe_fx_fm2frq2(voice, TRUE);
1146 /* pan & loop start */
1147 awe_set_pan(voice, TRUE);
1148
1149 /* chorus & loop end (chorus 8bit, MSB) */
1150 addr = vp->loopend - 1;
1151 addr += FX_OFFSET(fx, fx_lay, AWE_FX_LOOP_END,
1152 AWE_FX_COARSE_LOOP_END, vp->mode);
1153 temp = FX_BYTE(fx, fx_lay, AWE_FX_CHORUS, vp->parm.chorus);
1154 temp = (temp <<24) | (unsigned int)addr;
1155 awe_poke_dw(AWE_CSL(voice), temp);
1156 DEBUG(4,printk("AWE32: [-- loopend=%x/%x]\n", vp->loopend, addr));
1157
1158 /* Q & current address (Q 4bit value, MSB) */
1159 addr = vp->start - 1;
1160 addr += FX_OFFSET(fx, fx_lay, AWE_FX_SAMPLE_START,
1161 AWE_FX_COARSE_SAMPLE_START, vp->mode);
1162 temp = FX_BYTE(fx, fx_lay, AWE_FX_FILTERQ, vp->parm.filterQ);
1163 temp = (temp<<28) | (unsigned int)addr;
1164 awe_poke_dw(AWE_CCCA(voice), temp);
1165 DEBUG(4,printk("AWE32: [-- startaddr=%x/%x]\n", vp->start, addr));
1166
1167 /* clear unknown registers */
1168 awe_poke_dw(AWE_00A0(voice), 0);
1169 awe_poke_dw(AWE_0080(voice), 0);
1170
1171 /* reset volume */
1172 awe_poke_dw(AWE_VTFT(voice), (vtarget<<16)|ftarget);
1173 awe_poke_dw(AWE_CVCF(voice), (vtarget<<16)|ftarget);
1174
1175 /* set reverb */
1176 temp = FX_BYTE(fx, fx_lay, AWE_FX_REVERB, vp->parm.reverb);
1177 temp = (temp << 8) | (ptarget << 16) | voices[voice].aaux;
1178 awe_poke_dw(AWE_PTRX(voice), temp);
1179 awe_poke_dw(AWE_CPF(voice), ptarget << 16);
1180 /* turn on envelope */
1181 awe_poke(AWE_DCYSUSV(voice),
1182 FX_COMB(fx, fx_lay, AWE_FX_ENV2_SUSTAIN, AWE_FX_ENV2_DECAY,
1183 vp->parm.voldcysus));
1184
1185 voices[voice].state = AWE_ST_ON;
1186
1187 /* clear voice position for the next note on this channel */
1188 if (SINGLE_LAYER_MODE()) {
1189 FX_UNSET(fx, AWE_FX_SAMPLE_START);
1190 FX_UNSET(fx, AWE_FX_COARSE_SAMPLE_START);
1191 }
1192}
1193
1194
1195/* turn off the voice */
1196static void
1197awe_note_off(int voice)
1198{
1199 awe_voice_info *vp;
1200 unsigned short tmp;
1201 FX_Rec *fx = &voices[voice].cinfo->fx;
1202 FX_Rec *fx_lay = NULL;
1203 if (voices[voice].layer < MAX_LAYERS)
1204 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1205
1206 if ((vp = voices[voice].sample) == NULL) {
1207 voices[voice].state = AWE_ST_OFF;
1208 return;
1209 }
1210
1211 tmp = 0x8000 | FX_BYTE(fx, fx_lay, AWE_FX_ENV1_RELEASE,
1212 (unsigned char)vp->parm.modrelease);
1213 awe_poke(AWE_DCYSUS(voice), tmp);
1214 tmp = 0x8000 | FX_BYTE(fx, fx_lay, AWE_FX_ENV2_RELEASE,
1215 (unsigned char)vp->parm.volrelease);
1216 awe_poke(AWE_DCYSUSV(voice), tmp);
1217 voices[voice].state = AWE_ST_RELEASED;
1218}
1219
1220/* force to terminate the voice (no releasing echo) */
1221static void
1222awe_terminate(int voice)
1223{
1224 awe_poke(AWE_DCYSUSV(voice), 0x807F);
1225 awe_tweak_voice(voice);
1226 voices[voice].state = AWE_ST_OFF;
1227}
1228
1229/* turn off other voices with the same exclusive class (for drums) */
1230static void
1231awe_exclusive_off(int voice)
1232{
1233 int i, exclass;
1234
1235 if (voices[voice].sample == NULL)
1236 return;
1237 if ((exclass = voices[voice].sample->exclusiveClass) == 0)
1238 return; /* not exclusive */
1239
1240 /* turn off voices with the same class */
1241 for (i = 0; i < awe_max_voices; i++) {
1242 if (i != voice && IS_PLAYING(i) &&
1243 voices[i].sample && voices[i].ch == voices[voice].ch &&
1244 voices[i].sample->exclusiveClass == exclass) {
1245 DEBUG(4,printk("AWE32: [exoff(%d)]\n", i));
1246 awe_terminate(i);
1247 awe_voice_init(i, TRUE);
1248 }
1249 }
1250}
1251
1252
1253/*
1254 * change the parameters of an audible voice
1255 */
1256
1257/* change pitch */
1258static void
1259awe_set_pitch(int voice, int forced)
1260{
1261 if (IS_NO_EFFECT(voice) && !forced) return;
1262 awe_poke(AWE_IP(voice), voices[voice].apitch);
1263 DEBUG(3,printk("AWE32: [-- pitch=%x]\n", voices[voice].apitch));
1264}
1265
1266/* calculate & change pitch */
1267static void
1268awe_set_voice_pitch(int voice, int forced)
1269{
1270 awe_calc_pitch(voice);
1271 awe_set_pitch(voice, forced);
1272}
1273
1274/* change volume & cutoff */
1275static void
1276awe_set_volume(int voice, int forced)
1277{
1278 awe_voice_info *vp;
1279 unsigned short tmp2;
1280 FX_Rec *fx = &voices[voice].cinfo->fx;
1281 FX_Rec *fx_lay = NULL;
1282 if (voices[voice].layer < MAX_LAYERS)
1283 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1284
1285 if (!IS_PLAYING(voice) && !forced) return;
1286 if ((vp = voices[voice].sample) == NULL || vp->index == 0)
1287 return;
1288
1289 tmp2 = FX_BYTE(fx, fx_lay, AWE_FX_CUTOFF,
1290 (unsigned char)voices[voice].acutoff);
1291 tmp2 = (tmp2 << 8);
1292 tmp2 |= FX_BYTE(fx, fx_lay, AWE_FX_ATTEN,
1293 (unsigned char)voices[voice].avol);
1294 awe_poke(AWE_IFATN(voice), tmp2);
1295}
1296
1297/* calculate & change volume */
1298static void
1299awe_set_voice_vol(int voice, int forced)
1300{
1301 if (IS_EMPTY(voice))
1302 return;
1303 awe_calc_volume(voice);
1304 awe_set_volume(voice, forced);
1305}
1306
1307
1308/* change pan; this could make a click noise.. */
1309static void
1310awe_set_pan(int voice, int forced)
1311{
1312 unsigned int temp;
1313 int addr;
1314 awe_voice_info *vp;
1315 FX_Rec *fx = &voices[voice].cinfo->fx;
1316 FX_Rec *fx_lay = NULL;
1317 if (voices[voice].layer < MAX_LAYERS)
1318 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1319
1320 if (IS_NO_EFFECT(voice) && !forced) return;
1321 if ((vp = voices[voice].sample) == NULL || vp->index == 0)
1322 return;
1323
1324 /* pan & loop start (pan 8bit, MSB, 0:right, 0xff:left) */
1325 if (vp->fixpan > 0) /* 0-127 */
1326 temp = 255 - (int)vp->fixpan * 2;
1327 else {
1328 int pos = 0;
1329 if (vp->pan >= 0) /* 0-127 */
1330 pos = (int)vp->pan * 2 - 128;
1331 pos += voices[voice].cinfo->panning; /* -128 - 127 */
1332 temp = 127 - pos;
1333 }
1334 limitvalue(temp, 0, 255);
1335 if (ctrls[AWE_MD_PAN_EXCHANGE]) {
1336 temp = 255 - temp;
1337 }
1338 if (forced || temp != voices[voice].apan) {
1339 voices[voice].apan = temp;
1340 if (temp == 0)
1341 voices[voice].aaux = 0xff;
1342 else
1343 voices[voice].aaux = (-temp) & 0xff;
1344 addr = vp->loopstart - 1;
1345 addr += FX_OFFSET(fx, fx_lay, AWE_FX_LOOP_START,
1346 AWE_FX_COARSE_LOOP_START, vp->mode);
1347 temp = (temp<<24) | (unsigned int)addr;
1348 awe_poke_dw(AWE_PSST(voice), temp);
1349 DEBUG(4,printk("AWE32: [-- loopstart=%x/%x]\n", vp->loopstart, addr));
1350 }
1351}
1352
1353/* effects change during playing */
1354static void
1355awe_fx_fmmod(int voice, int forced)
1356{
1357 awe_voice_info *vp;
1358 FX_Rec *fx = &voices[voice].cinfo->fx;
1359 FX_Rec *fx_lay = NULL;
1360 if (voices[voice].layer < MAX_LAYERS)
1361 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1362
1363 if (IS_NO_EFFECT(voice) && !forced) return;
1364 if ((vp = voices[voice].sample) == NULL || vp->index == 0)
1365 return;
1366 awe_poke(AWE_FMMOD(voice),
1367 FX_COMB(fx, fx_lay, AWE_FX_LFO1_PITCH, AWE_FX_LFO1_CUTOFF,
1368 vp->parm.fmmod));
1369}
1370
1371/* set tremolo (lfo1) volume & frequency */
1372static void
1373awe_fx_tremfrq(int voice, int forced)
1374{
1375 awe_voice_info *vp;
1376 FX_Rec *fx = &voices[voice].cinfo->fx;
1377 FX_Rec *fx_lay = NULL;
1378 if (voices[voice].layer < MAX_LAYERS)
1379 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1380
1381 if (IS_NO_EFFECT(voice) && !forced) return;
1382 if ((vp = voices[voice].sample) == NULL || vp->index == 0)
1383 return;
1384 awe_poke(AWE_TREMFRQ(voice),
1385 FX_COMB(fx, fx_lay, AWE_FX_LFO1_VOLUME, AWE_FX_LFO1_FREQ,
1386 vp->parm.tremfrq));
1387}
1388
1389/* set lfo2 pitch & frequency */
1390static void
1391awe_fx_fm2frq2(int voice, int forced)
1392{
1393 awe_voice_info *vp;
1394 FX_Rec *fx = &voices[voice].cinfo->fx;
1395 FX_Rec *fx_lay = NULL;
1396 if (voices[voice].layer < MAX_LAYERS)
1397 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1398
1399 if (IS_NO_EFFECT(voice) && !forced) return;
1400 if ((vp = voices[voice].sample) == NULL || vp->index == 0)
1401 return;
1402 awe_poke(AWE_FM2FRQ2(voice),
1403 FX_COMB(fx, fx_lay, AWE_FX_LFO2_PITCH, AWE_FX_LFO2_FREQ,
1404 vp->parm.fm2frq2));
1405}
1406
1407
1408/* Q & current address (Q 4bit value, MSB) */
1409static void
1410awe_fx_filterQ(int voice, int forced)
1411{
1412 unsigned int addr;
1413 awe_voice_info *vp;
1414 FX_Rec *fx = &voices[voice].cinfo->fx;
1415 FX_Rec *fx_lay = NULL;
1416 if (voices[voice].layer < MAX_LAYERS)
1417 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1418
1419 if (IS_NO_EFFECT(voice) && !forced) return;
1420 if ((vp = voices[voice].sample) == NULL || vp->index == 0)
1421 return;
1422
1423 addr = awe_peek_dw(AWE_CCCA(voice)) & 0xffffff;
1424 addr |= (FX_BYTE(fx, fx_lay, AWE_FX_FILTERQ, vp->parm.filterQ) << 28);
1425 awe_poke_dw(AWE_CCCA(voice), addr);
1426}
1427
1428/*
1429 * calculate pitch offset
1430 *
1431 * 0xE000 is no pitch offset at 44100Hz sample.
1432 * Every 4096 is one octave.
1433 */
1434
1435static void
1436awe_calc_pitch(int voice)
1437{
1438 voice_info *vp = &voices[voice];
1439 awe_voice_info *ap;
1440 awe_chan_info *cp = voices[voice].cinfo;
1441 int offset;
1442
1443 /* search voice information */
1444 if ((ap = vp->sample) == NULL)
1445 return;
1446 if (ap->index == 0) {
1447 DEBUG(3,printk("AWE32: set sample (%d)\n", ap->sample));
1448 if (awe_set_sample((awe_voice_list*)ap) == 0)
1449 return;
1450 }
1451
1452 /* calculate offset */
1453 if (ap->fixkey >= 0) {
1454 DEBUG(3,printk("AWE32: p-> fixkey(%d) tune(%d)\n", ap->fixkey, ap->tune));
1455 offset = (ap->fixkey - ap->root) * 4096 / 12;
1456 } else {
1457 DEBUG(3,printk("AWE32: p(%d)-> root(%d) tune(%d)\n", vp->note, ap->root, ap->tune));
1458 offset = (vp->note - ap->root) * 4096 / 12;
1459 DEBUG(4,printk("AWE32: p-> ofs=%d\n", offset));
1460 }
1461 offset = (offset * ap->scaleTuning) / 100;
1462 DEBUG(4,printk("AWE32: p-> scale* ofs=%d\n", offset));
1463 offset += ap->tune * 4096 / 1200;
1464 DEBUG(4,printk("AWE32: p-> tune+ ofs=%d\n", offset));
1465 if (cp->bender != 0) {
1466 DEBUG(3,printk("AWE32: p-> bend(%d) %d\n", voice, cp->bender));
1467 /* (819200: 1 semitone) ==> (4096: 12 semitones) */
1468 offset += cp->bender * cp->bender_range / 2400;
1469 }
1470
1471 /* add initial pitch correction */
1472 if (FX_ON(&cp->fx_layer[vp->layer], AWE_FX_INIT_PITCH))
1473 offset += cp->fx_layer[vp->layer].val[AWE_FX_INIT_PITCH];
1474 else if (FX_ON(&cp->fx, AWE_FX_INIT_PITCH))
1475 offset += cp->fx.val[AWE_FX_INIT_PITCH];
1476
1477 /* 0xe000: root pitch */
1478 vp->apitch = 0xe000 + ap->rate_offset + offset;
1479 DEBUG(4,printk("AWE32: p-> sum aofs=%x, rate_ofs=%d\n", vp->apitch, ap->rate_offset));
1480 if (vp->apitch > 0xffff)
1481 vp->apitch = 0xffff;
1482 if (vp->apitch < 0)
1483 vp->apitch = 0;
1484}
1485
1486
1487#ifdef AWE_HAS_GUS_COMPATIBILITY
1488/* calculate MIDI key and semitone from the specified frequency */
1489static void
1490awe_calc_pitch_from_freq(int voice, int freq)
1491{
1492 voice_info *vp = &voices[voice];
1493 awe_voice_info *ap;
1494 FX_Rec *fx = &voices[voice].cinfo->fx;
1495 FX_Rec *fx_lay = NULL;
1496 int offset;
1497 int note;
1498
1499 if (voices[voice].layer < MAX_LAYERS)
1500 fx_lay = &voices[voice].cinfo->fx_layer[voices[voice].layer];
1501
1502 /* search voice information */
1503 if ((ap = vp->sample) == NULL)
1504 return;
1505 if (ap->index == 0) {
1506 DEBUG(3,printk("AWE32: set sample (%d)\n", ap->sample));
1507 if (awe_set_sample((awe_voice_list*)ap) == 0)
1508 return;
1509 }
1510 note = freq_to_note(freq);
1511 offset = (note - ap->root * 100 + ap->tune) * 4096 / 1200;
1512 offset = (offset * ap->scaleTuning) / 100;
1513 if (fx_lay && FX_ON(fx_lay, AWE_FX_INIT_PITCH))
1514 offset += fx_lay->val[AWE_FX_INIT_PITCH];
1515 else if (FX_ON(fx, AWE_FX_INIT_PITCH))
1516 offset += fx->val[AWE_FX_INIT_PITCH];
1517 vp->apitch = 0xe000 + ap->rate_offset + offset;
1518 if (vp->apitch > 0xffff)
1519 vp->apitch = 0xffff;
1520 if (vp->apitch < 0)
1521 vp->apitch = 0;
1522}
1523#endif /* AWE_HAS_GUS_COMPATIBILITY */
1524
1525
1526/*
1527 * calculate volume attenuation
1528 *
1529 * Voice volume is controlled by volume attenuation parameter.
1530 * So volume becomes maximum when avol is 0 (no attenuation), and
1531 * minimum when 255 (-96dB or silence).
1532 */
1533
1534static int vol_table[128] = {
1535 255,111,95,86,79,74,70,66,63,61,58,56,54,52,50,49,
1536 47,46,45,43,42,41,40,39,38,37,36,35,34,34,33,32,
1537 31,31,30,29,29,28,27,27,26,26,25,24,24,23,23,22,
1538 22,21,21,21,20,20,19,19,18,18,18,17,17,16,16,16,
1539 15,15,15,14,14,14,13,13,13,12,12,12,11,11,11,10,
1540 10,10,10,9,9,9,8,8,8,8,7,7,7,7,6,6,
1541 6,6,5,5,5,5,5,4,4,4,4,3,3,3,3,3,
1542 2,2,2,2,2,1,1,1,1,1,0,0,0,0,0,0,
1543};
1544
1545/* tables for volume->attenuation calculation */
1546static unsigned char voltab1[128] = {
1547 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
1548 0x63, 0x2b, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22,
1549 0x21, 0x20, 0x1f, 0x1e, 0x1e, 0x1d, 0x1c, 0x1b, 0x1b, 0x1a,
1550 0x19, 0x19, 0x18, 0x17, 0x17, 0x16, 0x16, 0x15, 0x15, 0x14,
1551 0x14, 0x13, 0x13, 0x13, 0x12, 0x12, 0x11, 0x11, 0x11, 0x10,
1552 0x10, 0x10, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0e, 0x0d,
1553 0x0d, 0x0d, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b,
1554 0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09,
1555 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x06,
1556 0x06, 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04,
1557 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02,
1558 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01,
1559 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1560};
1561
1562static unsigned char voltab2[128] = {
1563 0x32, 0x31, 0x30, 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x2a,
1564 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x24, 0x23, 0x22, 0x21,
1565 0x21, 0x20, 0x1f, 0x1e, 0x1e, 0x1d, 0x1c, 0x1c, 0x1b, 0x1a,
1566 0x1a, 0x19, 0x19, 0x18, 0x18, 0x17, 0x16, 0x16, 0x15, 0x15,
1567 0x14, 0x14, 0x13, 0x13, 0x13, 0x12, 0x12, 0x11, 0x11, 0x10,
1568 0x10, 0x10, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0d, 0x0d,
1569 0x0d, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a, 0x0a,
1570 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08,
1571 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,
1572 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
1573 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03,
1574 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01,
1575 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
1576};
1577
1578static unsigned char expressiontab[128] = {
1579 0x7f, 0x6c, 0x62, 0x5a, 0x54, 0x50, 0x4b, 0x48, 0x45, 0x42,
1580 0x40, 0x3d, 0x3b, 0x39, 0x38, 0x36, 0x34, 0x33, 0x31, 0x30,
1581 0x2f, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 0x25,
1582 0x24, 0x24, 0x23, 0x22, 0x21, 0x21, 0x20, 0x1f, 0x1e, 0x1e,
1583 0x1d, 0x1d, 0x1c, 0x1b, 0x1b, 0x1a, 0x1a, 0x19, 0x18, 0x18,
1584 0x17, 0x17, 0x16, 0x16, 0x15, 0x15, 0x15, 0x14, 0x14, 0x13,
1585 0x13, 0x12, 0x12, 0x11, 0x11, 0x11, 0x10, 0x10, 0x0f, 0x0f,
1586 0x0f, 0x0e, 0x0e, 0x0e, 0x0d, 0x0d, 0x0d, 0x0c, 0x0c, 0x0c,
1587 0x0b, 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09,
1588 0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,
1589 0x06, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03,
1590 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
1591 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1592};
1593
1594static void
1595awe_calc_volume(int voice)
1596{
1597 voice_info *vp = &voices[voice];
1598 awe_voice_info *ap;
1599 awe_chan_info *cp = voices[voice].cinfo;
1600 int vol;
1601
1602 /* search voice information */
1603 if ((ap = vp->sample) == NULL)
1604 return;
1605
1606 ap = vp->sample;
1607 if (ap->index == 0) {
1608 DEBUG(3,printk("AWE32: set sample (%d)\n", ap->sample));
1609 if (awe_set_sample((awe_voice_list*)ap) == 0)
1610 return;
1611 }
1612
1613 if (ctrls[AWE_MD_NEW_VOLUME_CALC]) {
1614 int main_vol = cp->main_vol * ap->amplitude / 127;
1615 limitvalue(vp->velocity, 0, 127);
1616 limitvalue(main_vol, 0, 127);
1617 limitvalue(cp->expression_vol, 0, 127);
1618
1619 vol = voltab1[main_vol] + voltab2[vp->velocity];
1620 vol = (vol * 8) / 3;
1621 vol += ap->attenuation;
1622 if (cp->expression_vol < 127)
1623 vol += ((0x100 - vol) * expressiontab[cp->expression_vol])/128;
1624 vol += atten_offset;
1625 if (atten_relative)
1626 vol += ctrls[AWE_MD_ZERO_ATTEN];
1627 limitvalue(vol, 0, 255);
1628 vp->avol = vol;
1629
1630 } else {
1631 /* 0 - 127 */
1632 vol = (vp->velocity * cp->main_vol * cp->expression_vol) / (127*127);
1633 vol = vol * ap->amplitude / 127;
1634
1635 if (vol < 0) vol = 0;
1636 if (vol > 127) vol = 127;
1637
1638 /* calc to attenuation */
1639 vol = vol_table[vol];
1640 vol += (int)ap->attenuation;
1641 vol += atten_offset;
1642 if (atten_relative)
1643 vol += ctrls[AWE_MD_ZERO_ATTEN];
1644 if (vol > 255) vol = 255;
1645
1646 vp->avol = vol;
1647 }
1648 if (cp->bank != AWE_DRUM_BANK && ((awe_voice_parm_block*)(&ap->parm))->volatk < 0x7d) {
1649 int atten;
1650 if (vp->velocity < 70) atten = 70;
1651 else atten = vp->velocity;
1652 vp->acutoff = (atten * ap->parm.cutoff + 0xa0) >> 7;
1653 } else {
1654 vp->acutoff = ap->parm.cutoff;
1655 }
1656 DEBUG(3,printk("AWE32: [-- voice(%d) vol=%x]\n", voice, vol));
1657}
1658
1659/* change master volume */
1660static void
1661awe_change_master_volume(short val)
1662{
1663 limitvalue(val, 0, 127);
1664 atten_offset = vol_table[val];
1665 atten_relative = TRUE;
1666 awe_update_volume();
1667}
1668
1669/* update volumes of all available channels */
1670static void awe_update_volume(void)
1671{
1672 int i;
1673 for (i = 0; i < awe_max_voices; i++)
1674 awe_set_voice_vol(i, TRUE);
1675}
1676
1677/* set sostenuto on */
1678static void awe_sostenuto_on(int voice, int forced)
1679{
1680 if (IS_NO_EFFECT(voice) && !forced) return;
1681 voices[voice].sostenuto = 127;
1682}
1683
1684
1685/* drop sustain */
1686static void awe_sustain_off(int voice, int forced)
1687{
1688 if (voices[voice].state == AWE_ST_SUSTAINED) {
1689 awe_note_off(voice);
1690 awe_fx_init(voices[voice].ch);
1691 awe_voice_init(voice, FALSE);
1692 }
1693}
1694
1695
1696/* terminate and initialize voice */
1697static void awe_terminate_and_init(int voice, int forced)
1698{
1699 awe_terminate(voice);
1700 awe_fx_init(voices[voice].ch);
1701 awe_voice_init(voice, TRUE);
1702}
1703
1704
1705/*
1706 * synth operation routines
1707 */
1708
1709#define AWE_VOICE_KEY(v) (0x8000 | (v))
1710#define AWE_CHAN_KEY(c,n) (((c) << 8) | ((n) + 1))
1711#define KEY_CHAN_MATCH(key,c) (((key) >> 8) == (c))
1712
1713/* initialize the voice */
1714static void
1715awe_voice_init(int voice, int init_all)
1716{
1717 voice_info *vp = &voices[voice];
1718
1719 /* reset voice search key */
1720 if (playing_mode == AWE_PLAY_DIRECT)
1721 vp->key = AWE_VOICE_KEY(voice);
1722 else
1723 vp->key = 0;
1724
1725 /* clear voice mapping */
1726 voice_alloc->map[voice] = 0;
1727
1728 /* touch the timing flag */
1729 vp->time = current_alloc_time;
1730
1731 /* initialize other parameters if necessary */
1732 if (init_all) {
1733 vp->note = -1;
1734 vp->velocity = 0;
1735 vp->sostenuto = 0;
1736
1737 vp->sample = NULL;
1738 vp->cinfo = &channels[voice];
1739 vp->ch = voice;
1740 vp->state = AWE_ST_OFF;
1741
1742 /* emu8000 parameters */
1743 vp->apitch = 0;
1744 vp->avol = 255;
1745 vp->apan = -1;
1746 }
1747}
1748
1749/* clear effects */
1750static void awe_fx_init(int ch)
1751{
1752 if (SINGLE_LAYER_MODE() && !ctrls[AWE_MD_KEEP_EFFECT]) {
1753 memset(&channels[ch].fx, 0, sizeof(channels[ch].fx));
1754 memset(&channels[ch].fx_layer, 0, sizeof(&channels[ch].fx_layer));
1755 }
1756}
1757
1758/* initialize channel info */
1759static void awe_channel_init(int ch, int init_all)
1760{
1761 awe_chan_info *cp = &channels[ch];
1762 cp->channel = ch;
1763 if (init_all) {
1764 cp->panning = 0; /* zero center */
1765 cp->bender_range = 200; /* sense * 100 */
1766 cp->main_vol = 127;
1767 if (MULTI_LAYER_MODE() && IS_DRUM_CHANNEL(ch)) {
1768 cp->instr = ctrls[AWE_MD_DEF_DRUM];
1769 cp->bank = AWE_DRUM_BANK;
1770 } else {
1771 cp->instr = ctrls[AWE_MD_DEF_PRESET];
1772 cp->bank = ctrls[AWE_MD_DEF_BANK];
1773 }
1774 }
1775
1776 cp->bender = 0; /* zero tune skew */
1777 cp->expression_vol = 127;
1778 cp->chan_press = 0;
1779 cp->sustained = 0;
1780
1781 if (! ctrls[AWE_MD_KEEP_EFFECT]) {
1782 memset(&cp->fx, 0, sizeof(cp->fx));
1783 memset(&cp->fx_layer, 0, sizeof(cp->fx_layer));
1784 }
1785}
1786
1787
1788/* change the voice parameters; voice = channel */
1789static void awe_voice_change(int voice, fx_affect_func func)
1790{
1791 int i;
1792 switch (playing_mode) {
1793 case AWE_PLAY_DIRECT:
1794 func(voice, FALSE);
1795 break;
1796 case AWE_PLAY_INDIRECT:
1797 for (i = 0; i < awe_max_voices; i++)
1798 if (voices[i].key == AWE_VOICE_KEY(voice))
1799 func(i, FALSE);
1800 break;
1801 default:
1802 for (i = 0; i < awe_max_voices; i++)
1803 if (KEY_CHAN_MATCH(voices[i].key, voice))
1804 func(i, FALSE);
1805 break;
1806 }
1807}
1808
1809
1810/*
1811 * device open / close
1812 */
1813
1814/* open device:
1815 * reset status of all voices, and clear sample position flag
1816 */
1817static int
1818awe_open(int dev, int mode)
1819{
1820 if (awe_busy)
1821 return -EBUSY;
1822
1823 awe_busy = TRUE;
1824
1825 /* set default mode */
1826 awe_init_ctrl_parms(FALSE);
1827 atten_relative = TRUE;
1828 atten_offset = 0;
1829 drum_flags = DEFAULT_DRUM_FLAGS;
1830 playing_mode = AWE_PLAY_INDIRECT;
1831
1832 /* reset voices & channels */
1833 awe_reset(dev);
1834
1835 patch_opened = 0;
1836
1837 return 0;
1838}
1839
1840
1841/* close device:
1842 * reset all voices again (terminate sounds)
1843 */
1844static void
1845awe_close(int dev)
1846{
1847 awe_reset(dev);
1848 awe_busy = FALSE;
1849}
1850
1851
1852/* set miscellaneous mode parameters
1853 */
1854static void
1855awe_init_ctrl_parms(int init_all)
1856{
1857 int i;
1858 for (i = 0; i < AWE_MD_END; i++) {
1859 if (init_all || ctrl_parms[i].init_each_time)
1860 ctrls[i] = ctrl_parms[i].value;
1861 }
1862}
1863
1864
1865/* sequencer I/O control:
1866 */
1867static int
1868awe_ioctl(int dev, unsigned int cmd, void __user *arg)
1869{
1870 switch (cmd) {
1871 case SNDCTL_SYNTH_INFO:
1872 if (playing_mode == AWE_PLAY_DIRECT)
1873 awe_info.nr_voices = awe_max_voices;
1874 else
1875 awe_info.nr_voices = AWE_MAX_CHANNELS;
1876 if (copy_to_user(arg, &awe_info, sizeof(awe_info)))
1877 return -EFAULT;
1878 return 0;
1879 break;
1880
1881 case SNDCTL_SEQ_RESETSAMPLES:
1882 awe_reset(dev);
1883 awe_reset_samples();
1884 return 0;
1885 break;
1886
1887 case SNDCTL_SEQ_PERCMODE:
1888 /* what's this? */
1889 return 0;
1890 break;
1891
1892 case SNDCTL_SYNTH_MEMAVL:
1893 return memsize - awe_free_mem_ptr() * 2;
1894 break;
1895
1896 default:
1897 printk(KERN_WARNING "AWE32: unsupported ioctl %d\n", cmd);
1898 return -EINVAL;
1899 break;
1900 }
1901}
1902
1903
1904static int voice_in_range(int voice)
1905{
1906 if (playing_mode == AWE_PLAY_DIRECT) {
1907 if (voice < 0 || voice >= awe_max_voices)
1908 return FALSE;
1909 } else {
1910 if (voice < 0 || voice >= AWE_MAX_CHANNELS)
1911 return FALSE;
1912 }
1913 return TRUE;
1914}
1915
1916static void release_voice(int voice, int do_sustain)
1917{
1918 if (IS_NO_SOUND(voice))
1919 return;
1920 if (do_sustain && (voices[voice].cinfo->sustained == 127 ||
1921 voices[voice].sostenuto == 127))
1922 voices[voice].state = AWE_ST_SUSTAINED;
1923 else {
1924 awe_note_off(voice);
1925 awe_fx_init(voices[voice].ch);
1926 awe_voice_init(voice, FALSE);
1927 }
1928}
1929
1930/* release all notes */
1931static void awe_note_off_all(int do_sustain)
1932{
1933 int i;
1934 for (i = 0; i < awe_max_voices; i++)
1935 release_voice(i, do_sustain);
1936}
1937
1938/* kill a voice:
1939 * not terminate, just release the voice.
1940 */
1941static int
1942awe_kill_note(int dev, int voice, int note, int velocity)
1943{
1944 int i, v2, key;
1945
1946 DEBUG(2,printk("AWE32: [off(%d) nt=%d vl=%d]\n", voice, note, velocity));
1947 if (! voice_in_range(voice))
1948 return -EINVAL;
1949
1950 switch (playing_mode) {
1951 case AWE_PLAY_DIRECT:
1952 case AWE_PLAY_INDIRECT:
1953 key = AWE_VOICE_KEY(voice);
1954 break;
1955
1956 case AWE_PLAY_MULTI2:
1957 v2 = voice_alloc->map[voice] >> 8;
1958 voice_alloc->map[voice] = 0;
1959 voice = v2;
1960 if (voice < 0 || voice >= AWE_MAX_CHANNELS)
1961 return -EINVAL;
1962 /* continue to below */
1963 default:
1964 key = AWE_CHAN_KEY(voice, note);
1965 break;
1966 }
1967
1968 for (i = 0; i < awe_max_voices; i++) {
1969 if (voices[i].key == key)
1970 release_voice(i, TRUE);
1971 }
1972 return 0;
1973}
1974
1975
1976static void start_or_volume_change(int voice, int velocity)
1977{
1978 voices[voice].velocity = velocity;
1979 awe_calc_volume(voice);
1980 if (voices[voice].state == AWE_ST_STANDBY)
1981 awe_note_on(voice);
1982 else if (voices[voice].state == AWE_ST_ON)
1983 awe_set_volume(voice, FALSE);
1984}
1985
1986static void set_and_start_voice(int voice, int state)
1987{
1988 /* calculate pitch & volume parameters */
1989 voices[voice].state = state;
1990 awe_calc_pitch(voice);
1991 awe_calc_volume(voice);
1992 if (state == AWE_ST_ON)
1993 awe_note_on(voice);
1994}
1995
1996/* start a voice:
1997 * if note is 255, identical with aftertouch function.
1998 * Otherwise, start a voice with specified not and volume.
1999 */
2000static int
2001awe_start_note(int dev, int voice, int note, int velocity)
2002{
2003 int i, key, state, volonly;
2004
2005 DEBUG(2,printk("AWE32: [on(%d) nt=%d vl=%d]\n", voice, note, velocity));
2006 if (! voice_in_range(voice))
2007 return -EINVAL;
2008
2009 if (velocity == 0)
2010 state = AWE_ST_STANDBY; /* stand by for playing */
2011 else
2012 state = AWE_ST_ON; /* really play */
2013 volonly = FALSE;
2014
2015 switch (playing_mode) {
2016 case AWE_PLAY_DIRECT:
2017 case AWE_PLAY_INDIRECT:
2018 key = AWE_VOICE_KEY(voice);
2019 if (note == 255)
2020 volonly = TRUE;
2021 break;
2022
2023 case AWE_PLAY_MULTI2:
2024 voice = voice_alloc->map[voice] >> 8;
2025 if (voice < 0 || voice >= AWE_MAX_CHANNELS)
2026 return -EINVAL;
2027 /* continue to below */
2028 default:
2029 if (note >= 128) { /* key volume mode */
2030 note -= 128;
2031 volonly = TRUE;
2032 }
2033 key = AWE_CHAN_KEY(voice, note);
2034 break;
2035 }
2036
2037 /* dynamic volume change */
2038 if (volonly) {
2039 for (i = 0; i < awe_max_voices; i++) {
2040 if (voices[i].key == key)
2041 start_or_volume_change(i, velocity);
2042 }
2043 return 0;
2044 }
2045
2046 /* if the same note still playing, stop it */
2047 if (playing_mode != AWE_PLAY_DIRECT || ctrls[AWE_MD_EXCLUSIVE_SOUND]) {
2048 for (i = 0; i < awe_max_voices; i++)
2049 if (voices[i].key == key) {
2050 if (voices[i].state == AWE_ST_ON) {
2051 awe_note_off(i);
2052 awe_voice_init(i, FALSE);
2053 } else if (voices[i].state == AWE_ST_STANDBY)
2054 awe_voice_init(i, TRUE);
2055 }
2056 }
2057
2058 /* allocate voices */
2059 if (playing_mode == AWE_PLAY_DIRECT)
2060 awe_alloc_one_voice(voice, note, velocity);
2061 else
2062 awe_alloc_multi_voices(voice, note, velocity, key);
2063
2064 /* turn off other voices exlusively (for drums) */
2065 for (i = 0; i < awe_max_voices; i++)
2066 if (voices[i].key == key)
2067 awe_exclusive_off(i);
2068
2069 /* set up pitch and volume parameters */
2070 for (i = 0; i < awe_max_voices; i++) {
2071 if (voices[i].key == key && voices[i].state == AWE_ST_OFF)
2072 set_and_start_voice(i, state);
2073 }
2074
2075 return 0;
2076}
2077
2078
2079/* calculate hash key */
2080static int
2081awe_search_key(int bank, int preset, int note)
2082{
2083 unsigned int key;
2084
2085#if 1 /* new hash table */
2086 if (bank == AWE_DRUM_BANK)
2087 key = preset + note + 128;
2088 else
2089 key = bank + preset;
2090#else
2091 key = preset;
2092#endif
2093 key %= AWE_MAX_PRESETS;
2094
2095 return (int)key;
2096}
2097
2098
2099/* search instrument from hash table */
2100static awe_voice_list *
2101awe_search_instr(int bank, int preset, int note)
2102{
2103 awe_voice_list *p;
2104 int key, key2;
2105
2106 key = awe_search_key(bank, preset, note);
2107 for (p = preset_table[key]; p; p = p->next_bank) {
2108 if (p->instr == preset && p->bank == bank)
2109 return p;
2110 }
2111 key2 = awe_search_key(bank, preset, 0); /* search default */
2112 if (key == key2)
2113 return NULL;
2114 for (p = preset_table[key2]; p; p = p->next_bank) {
2115 if (p->instr == preset && p->bank == bank)
2116 return p;
2117 }
2118 return NULL;
2119}
2120
2121
2122/* assign the instrument to a voice */
2123static int
2124awe_set_instr_2(int dev, int voice, int instr_no)
2125{
2126 if (playing_mode == AWE_PLAY_MULTI2) {
2127 voice = voice_alloc->map[voice] >> 8;
2128 if (voice < 0 || voice >= AWE_MAX_CHANNELS)
2129 return -EINVAL;
2130 }
2131 return awe_set_instr(dev, voice, instr_no);
2132}
2133
2134/* assign the instrument to a channel; voice is the channel number */
2135static int
2136awe_set_instr(int dev, int voice, int instr_no)
2137{
2138 awe_chan_info *cinfo;
2139
2140 if (! voice_in_range(voice))
2141 return -EINVAL;
2142
2143 if (instr_no < 0 || instr_no >= AWE_MAX_PRESETS)
2144 return -EINVAL;
2145
2146 cinfo = &channels[voice];
2147 cinfo->instr = instr_no;
2148 DEBUG(2,printk("AWE32: [program(%d) %d]\n", voice, instr_no));
2149
2150 return 0;
2151}
2152
2153
2154/* reset all voices; terminate sounds and initialize parameters */
2155static void
2156awe_reset(int dev)
2157{
2158 int i;
2159 current_alloc_time = 0;
2160 /* don't turn off voice 31 and 32. they are used also for FM voices */
2161 for (i = 0; i < awe_max_voices; i++) {
2162 awe_terminate(i);
2163 awe_voice_init(i, TRUE);
2164 }
2165 for (i = 0; i < AWE_MAX_CHANNELS; i++)
2166 awe_channel_init(i, TRUE);
2167 for (i = 0; i < 16; i++) {
2168 awe_operations.chn_info[i].controllers[CTL_MAIN_VOLUME] = 127;
2169 awe_operations.chn_info[i].controllers[CTL_EXPRESSION] = 127;
2170 }
2171 awe_init_fm();
2172 awe_tweak();
2173}
2174
2175
2176/* hardware specific control:
2177 * GUS specific and AWE32 specific controls are available.
2178 */
2179static void
2180awe_hw_control(int dev, unsigned char *event)
2181{
2182 int cmd = event[2];
2183 if (cmd & _AWE_MODE_FLAG)
2184 awe_hw_awe_control(dev, cmd & _AWE_MODE_VALUE_MASK, event);
2185#ifdef AWE_HAS_GUS_COMPATIBILITY
2186 else
2187 awe_hw_gus_control(dev, cmd & _AWE_MODE_VALUE_MASK, event);
2188#endif
2189}
2190
2191
2192#ifdef AWE_HAS_GUS_COMPATIBILITY
2193
2194/* GUS compatible controls */
2195static void
2196awe_hw_gus_control(int dev, int cmd, unsigned char *event)
2197{
2198 int voice, i, key;
2199 unsigned short p1;
2200 short p2;
2201 int plong;
2202
2203 if (MULTI_LAYER_MODE())
2204 return;
2205 if (cmd == _GUS_NUMVOICES)
2206 return;
2207
2208 voice = event[3];
2209 if (! voice_in_range(voice))
2210 return;
2211
2212 p1 = *(unsigned short *) &event[4];
2213 p2 = *(short *) &event[6];
2214 plong = *(int*) &event[4];
2215
2216 switch (cmd) {
2217 case _GUS_VOICESAMPLE:
2218 awe_set_instr(dev, voice, p1);
2219 return;
2220
2221 case _GUS_VOICEBALA:
2222 /* 0 to 15 --> -128 to 127 */
2223 awe_panning(dev, voice, ((int)p1 << 4) - 128);
2224 return;
2225
2226 case _GUS_VOICEVOL:
2227 case _GUS_VOICEVOL2:
2228 /* not supported yet */
2229 return;
2230
2231 case _GUS_RAMPRANGE:
2232 case _GUS_RAMPRATE:
2233 case _GUS_RAMPMODE:
2234 case _GUS_RAMPON:
2235 case _GUS_RAMPOFF:
2236 /* volume ramping not supported */
2237 return;
2238
2239 case _GUS_VOLUME_SCALE:
2240 return;
2241
2242 case _GUS_VOICE_POS:
2243 FX_SET(&channels[voice].fx, AWE_FX_SAMPLE_START,
2244 (short)(plong & 0x7fff));
2245 FX_SET(&channels[voice].fx, AWE_FX_COARSE_SAMPLE_START,
2246 (plong >> 15) & 0xffff);
2247 return;
2248 }
2249
2250 key = AWE_VOICE_KEY(voice);
2251 for (i = 0; i < awe_max_voices; i++) {
2252 if (voices[i].key == key) {
2253 switch (cmd) {
2254 case _GUS_VOICEON:
2255 awe_note_on(i);
2256 break;
2257
2258 case _GUS_VOICEOFF:
2259 awe_terminate(i);
2260 awe_fx_init(voices[i].ch);
2261 awe_voice_init(i, TRUE);
2262 break;
2263
2264 case _GUS_VOICEFADE:
2265 awe_note_off(i);
2266 awe_fx_init(voices[i].ch);
2267 awe_voice_init(i, FALSE);
2268 break;
2269
2270 case _GUS_VOICEFREQ:
2271 awe_calc_pitch_from_freq(i, plong);
2272 break;
2273 }
2274 }
2275 }
2276}
2277
2278#endif /* gus_compat */
2279
2280
2281/* AWE32 specific controls */
2282static void
2283awe_hw_awe_control(int dev, int cmd, unsigned char *event)
2284{
2285 int voice;
2286 unsigned short p1;
2287 short p2;
2288 int i;
2289
2290 voice = event[3];
2291 if (! voice_in_range(voice))
2292 return;
2293
2294 if (playing_mode == AWE_PLAY_MULTI2) {
2295 voice = voice_alloc->map[voice] >> 8;
2296 if (voice < 0 || voice >= AWE_MAX_CHANNELS)
2297 return;
2298 }
2299
2300 p1 = *(unsigned short *) &event[4];
2301 p2 = *(short *) &event[6];
2302
2303 switch (cmd) {
2304 case _AWE_DEBUG_MODE:
2305 ctrls[AWE_MD_DEBUG_MODE] = p1;
2306 printk(KERN_DEBUG "AWE32: debug mode = %d\n", ctrls[AWE_MD_DEBUG_MODE]);
2307 break;
2308 case _AWE_REVERB_MODE:
2309 ctrls[AWE_MD_REVERB_MODE] = p1;
2310 awe_update_reverb_mode();
2311 break;
2312
2313 case _AWE_CHORUS_MODE:
2314 ctrls[AWE_MD_CHORUS_MODE] = p1;
2315 awe_update_chorus_mode();
2316 break;
2317
2318 case _AWE_REMOVE_LAST_SAMPLES:
2319 DEBUG(0,printk("AWE32: remove last samples\n"));
2320 awe_reset(0);
2321 if (locked_sf_id > 0)
2322 awe_remove_samples(locked_sf_id);
2323 break;
2324
2325 case _AWE_INITIALIZE_CHIP:
2326 awe_initialize();
2327 break;
2328
2329 case _AWE_SEND_EFFECT:
2330 i = -1;
2331 if (p1 >= 0x100) {
2332 i = (p1 >> 8);
2333 if (i < 0 || i >= MAX_LAYERS)
2334 break;
2335 }
2336 awe_send_effect(voice, i, p1, p2);
2337 break;
2338
2339 case _AWE_RESET_CHANNEL:
2340 awe_channel_init(voice, !p1);
2341 break;
2342
2343 case _AWE_TERMINATE_ALL:
2344 awe_reset(0);
2345 break;
2346
2347 case _AWE_TERMINATE_CHANNEL:
2348 awe_voice_change(voice, awe_terminate_and_init);
2349 break;
2350
2351 case _AWE_RELEASE_ALL:
2352 awe_note_off_all(FALSE);
2353 break;
2354 case _AWE_NOTEOFF_ALL:
2355 awe_note_off_all(TRUE);
2356 break;
2357
2358 case _AWE_INITIAL_VOLUME:
2359 DEBUG(0,printk("AWE32: init attenuation %d\n", p1));
2360 atten_relative = (char)p2;
2361 atten_offset = (short)p1;
2362 awe_update_volume();
2363 break;
2364
2365 case _AWE_CHN_PRESSURE:
2366 channels[voice].chan_press = p1;
2367 awe_modwheel_change(voice, p1);
2368 break;
2369
2370 case _AWE_CHANNEL_MODE:
2371 DEBUG(0,printk("AWE32: channel mode = %d\n", p1));
2372 playing_mode = p1;
2373 awe_reset(0);
2374 break;
2375
2376 case _AWE_DRUM_CHANNELS:
2377 DEBUG(0,printk("AWE32: drum flags = %x\n", p1));
2378 drum_flags = *(unsigned int*)&event[4];
2379 break;
2380
2381 case _AWE_MISC_MODE:
2382 DEBUG(0,printk("AWE32: ctrl parms = %d %d\n", p1, p2));
2383 if (p1 > AWE_MD_VERSION && p1 < AWE_MD_END) {
2384 ctrls[p1] = p2;
2385 if (ctrl_parms[p1].update)
2386 ctrl_parms[p1].update();
2387 }
2388 break;
2389
2390 case _AWE_EQUALIZER:
2391 ctrls[AWE_MD_BASS_LEVEL] = p1;
2392 ctrls[AWE_MD_TREBLE_LEVEL] = p2;
2393 awe_update_equalizer();
2394 break;
2395
2396 default:
2397 DEBUG(0,printk("AWE32: hw control cmd=%d voice=%d\n", cmd, voice));
2398 break;
2399 }
2400}
2401
2402
2403/* change effects */
2404static void
2405awe_send_effect(int voice, int layer, int type, int val)
2406{
2407 awe_chan_info *cinfo;
2408 FX_Rec *fx;
2409 int mode;
2410
2411 cinfo = &channels[voice];
2412 if (layer >= 0 && layer < MAX_LAYERS)
2413 fx = &cinfo->fx_layer[layer];
2414 else
2415 fx = &cinfo->fx;
2416
2417 if (type & 0x40)
2418 mode = FX_FLAG_OFF;
2419 else if (type & 0x80)
2420 mode = FX_FLAG_ADD;
2421 else
2422 mode = FX_FLAG_SET;
2423 type &= 0x3f;
2424
2425 if (type >= 0 && type < AWE_FX_END) {
2426 DEBUG(2,printk("AWE32: effects (%d) %d %d\n", voice, type, val));
2427 if (mode == FX_FLAG_SET)
2428 FX_SET(fx, type, val);
2429 else if (mode == FX_FLAG_ADD)
2430 FX_ADD(fx, type, val);
2431 else
2432 FX_UNSET(fx, type);
2433 if (mode != FX_FLAG_OFF && parm_defs[type].realtime) {
2434 DEBUG(2,printk("AWE32: fx_realtime (%d)\n", voice));
2435 awe_voice_change(voice, parm_defs[type].realtime);
2436 }
2437 }
2438}
2439
2440
2441/* change modulation wheel; voice is already mapped on multi2 mode */
2442static void
2443awe_modwheel_change(int voice, int value)
2444{
2445 int i;
2446 awe_chan_info *cinfo;
2447
2448 cinfo = &channels[voice];
2449 i = value * ctrls[AWE_MD_MOD_SENSE] / 1200;
2450 FX_ADD(&cinfo->fx, AWE_FX_LFO1_PITCH, i);
2451 awe_voice_change(voice, awe_fx_fmmod);
2452 FX_ADD(&cinfo->fx, AWE_FX_LFO2_PITCH, i);
2453 awe_voice_change(voice, awe_fx_fm2frq2);
2454}
2455
2456
2457/* voice pressure change */
2458static void
2459awe_aftertouch(int dev, int voice, int pressure)
2460{
2461 int note;
2462
2463 DEBUG(2,printk("AWE32: [after(%d) %d]\n", voice, pressure));
2464 if (! voice_in_range(voice))
2465 return;
2466
2467 switch (playing_mode) {
2468 case AWE_PLAY_DIRECT:
2469 case AWE_PLAY_INDIRECT:
2470 awe_start_note(dev, voice, 255, pressure);
2471 break;
2472 case AWE_PLAY_MULTI2:
2473 note = (voice_alloc->map[voice] & 0xff) - 1;
2474 awe_key_pressure(dev, voice, note + 0x80, pressure);
2475 break;
2476 }
2477}
2478
2479
2480/* voice control change */
2481static void
2482awe_controller(int dev, int voice, int ctrl_num, int value)
2483{
2484 awe_chan_info *cinfo;
2485
2486 if (! voice_in_range(voice))
2487 return;
2488
2489 if (playing_mode == AWE_PLAY_MULTI2) {
2490 voice = voice_alloc->map[voice] >> 8;
2491 if (voice < 0 || voice >= AWE_MAX_CHANNELS)
2492 return;
2493 }
2494
2495 cinfo = &channels[voice];
2496
2497 switch (ctrl_num) {
2498 case CTL_BANK_SELECT: /* MIDI control #0 */
2499 DEBUG(2,printk("AWE32: [bank(%d) %d]\n", voice, value));
2500 if (MULTI_LAYER_MODE() && IS_DRUM_CHANNEL(voice) &&
2501 !ctrls[AWE_MD_TOGGLE_DRUM_BANK])
2502 break;
2503 if (value < 0 || value > 255)
2504 break;
2505 cinfo->bank = value;
2506 if (cinfo->bank == AWE_DRUM_BANK)
2507 DRUM_CHANNEL_ON(cinfo->channel);
2508 else
2509 DRUM_CHANNEL_OFF(cinfo->channel);
2510 awe_set_instr(dev, voice, cinfo->instr);
2511 break;
2512
2513 case CTL_MODWHEEL: /* MIDI control #1 */
2514 DEBUG(2,printk("AWE32: [modwheel(%d) %d]\n", voice, value));
2515 awe_modwheel_change(voice, value);
2516 break;
2517
2518 case CTRL_PITCH_BENDER: /* SEQ1 V2 contorl */
2519 DEBUG(2,printk("AWE32: [bend(%d) %d]\n", voice, value));
2520 /* zero centered */
2521 cinfo->bender = value;
2522 awe_voice_change(voice, awe_set_voice_pitch);
2523 break;
2524
2525 case CTRL_PITCH_BENDER_RANGE: /* SEQ1 V2 control */
2526 DEBUG(2,printk("AWE32: [range(%d) %d]\n", voice, value));
2527 /* value = sense x 100 */
2528 cinfo->bender_range = value;
2529 /* no audible pitch change yet.. */
2530 break;
2531
2532 case CTL_EXPRESSION: /* MIDI control #11 */
2533 if (SINGLE_LAYER_MODE())
2534 value /= 128;
2535 case CTRL_EXPRESSION: /* SEQ1 V2 control */
2536 DEBUG(2,printk("AWE32: [expr(%d) %d]\n", voice, value));
2537 /* 0 - 127 */
2538 cinfo->expression_vol = value;
2539 awe_voice_change(voice, awe_set_voice_vol);
2540 break;
2541
2542 case CTL_PAN: /* MIDI control #10 */
2543 DEBUG(2,printk("AWE32: [pan(%d) %d]\n", voice, value));
2544 /* (0-127) -> signed 8bit */
2545 cinfo->panning = value * 2 - 128;
2546 if (ctrls[AWE_MD_REALTIME_PAN])
2547 awe_voice_change(voice, awe_set_pan);
2548 break;
2549
2550 case CTL_MAIN_VOLUME: /* MIDI control #7 */
2551 if (SINGLE_LAYER_MODE())
2552 value = (value * 100) / 16383;
2553 case CTRL_MAIN_VOLUME: /* SEQ1 V2 control */
2554 DEBUG(2,printk("AWE32: [mainvol(%d) %d]\n", voice, value));
2555 /* 0 - 127 */
2556 cinfo->main_vol = value;
2557 awe_voice_change(voice, awe_set_voice_vol);
2558 break;
2559
2560 case CTL_EXT_EFF_DEPTH: /* reverb effects: 0-127 */
2561 DEBUG(2,printk("AWE32: [reverb(%d) %d]\n", voice, value));
2562 FX_SET(&cinfo->fx, AWE_FX_REVERB, value * 2);
2563 break;
2564
2565 case CTL_CHORUS_DEPTH: /* chorus effects: 0-127 */
2566 DEBUG(2,printk("AWE32: [chorus(%d) %d]\n", voice, value));
2567 FX_SET(&cinfo->fx, AWE_FX_CHORUS, value * 2);
2568 break;
2569
2570 case 120: /* all sounds off */
2571 awe_note_off_all(FALSE);
2572 break;
2573 case 123: /* all notes off */
2574 awe_note_off_all(TRUE);
2575 break;
2576
2577 case CTL_SUSTAIN: /* MIDI control #64 */
2578 cinfo->sustained = value;
2579 if (value != 127)
2580 awe_voice_change(voice, awe_sustain_off);
2581 break;
2582
2583 case CTL_SOSTENUTO: /* MIDI control #66 */
2584 if (value == 127)
2585 awe_voice_change(voice, awe_sostenuto_on);
2586 else
2587 awe_voice_change(voice, awe_sustain_off);
2588 break;
2589
2590 default:
2591 DEBUG(0,printk("AWE32: [control(%d) ctrl=%d val=%d]\n",
2592 voice, ctrl_num, value));
2593 break;
2594 }
2595}
2596
2597
2598/* voice pan change (value = -128 - 127) */
2599static void
2600awe_panning(int dev, int voice, int value)
2601{
2602 awe_chan_info *cinfo;
2603
2604 if (! voice_in_range(voice))
2605 return;
2606
2607 if (playing_mode == AWE_PLAY_MULTI2) {
2608 voice = voice_alloc->map[voice] >> 8;
2609 if (voice < 0 || voice >= AWE_MAX_CHANNELS)
2610 return;
2611 }
2612
2613 cinfo = &channels[voice];
2614 cinfo->panning = value;
2615 DEBUG(2,printk("AWE32: [pan(%d) %d]\n", voice, cinfo->panning));
2616 if (ctrls[AWE_MD_REALTIME_PAN])
2617 awe_voice_change(voice, awe_set_pan);
2618}
2619
2620
2621/* volume mode change */
2622static void
2623awe_volume_method(int dev, int mode)
2624{
2625 /* not impremented */
2626 DEBUG(0,printk("AWE32: [volmethod mode=%d]\n", mode));
2627}
2628
2629
2630/* pitch wheel change: 0-16384 */
2631static void
2632awe_bender(int dev, int voice, int value)
2633{
2634 awe_chan_info *cinfo;
2635
2636 if (! voice_in_range(voice))
2637 return;
2638
2639 if (playing_mode == AWE_PLAY_MULTI2) {
2640 voice = voice_alloc->map[voice] >> 8;
2641 if (voice < 0 || voice >= AWE_MAX_CHANNELS)
2642 return;
2643 }
2644
2645 /* convert to zero centered value */
2646 cinfo = &channels[voice];
2647 cinfo->bender = value - 8192;
2648 DEBUG(2,printk("AWE32: [bend(%d) %d]\n", voice, cinfo->bender));
2649 awe_voice_change(voice, awe_set_voice_pitch);
2650}
2651
2652
2653/*
2654 * load a sound patch:
2655 * three types of patches are accepted: AWE, GUS, and SYSEX.
2656 */
2657
2658static int
2659awe_load_patch(int dev, int format, const char __user *addr,
2660 int offs, int count, int pmgr_flag)
2661{
2662 awe_patch_info patch;
2663 int rc = 0;
2664
2665#ifdef AWE_HAS_GUS_COMPATIBILITY
2666 if (format == GUS_PATCH) {
2667 return awe_load_guspatch(addr, offs, count, pmgr_flag);
2668 } else
2669#endif
2670 if (format == SYSEX_PATCH) {
2671 /* no system exclusive message supported yet */
2672 return 0;
2673 } else if (format != AWE_PATCH) {
2674 printk(KERN_WARNING "AWE32 Error: Invalid patch format (key) 0x%x\n", format);
2675 return -EINVAL;
2676 }
2677
2678 if (count < AWE_PATCH_INFO_SIZE) {
2679 printk(KERN_WARNING "AWE32 Error: Patch header too short\n");
2680 return -EINVAL;
2681 }
2682 if (copy_from_user(((char*)&patch) + offs, addr + offs,
2683 AWE_PATCH_INFO_SIZE - offs))
2684 return -EFAULT;
2685
2686 count -= AWE_PATCH_INFO_SIZE;
2687 if (count < patch.len) {
2688 printk(KERN_WARNING "AWE32: sample: Patch record too short (%d<%d)\n",
2689 count, patch.len);
2690 return -EINVAL;
2691 }
2692
2693 switch (patch.type) {
2694 case AWE_LOAD_INFO:
2695 rc = awe_load_info(&patch, addr, count);
2696 break;
2697 case AWE_LOAD_DATA:
2698 rc = awe_load_data(&patch, addr, count);
2699 break;
2700 case AWE_OPEN_PATCH:
2701 rc = awe_open_patch(&patch, addr, count);
2702 break;
2703 case AWE_CLOSE_PATCH:
2704 rc = awe_close_patch(&patch, addr, count);
2705 break;
2706 case AWE_UNLOAD_PATCH:
2707 rc = awe_unload_patch(&patch, addr, count);
2708 break;
2709 case AWE_REPLACE_DATA:
2710 rc = awe_replace_data(&patch, addr, count);
2711 break;
2712 case AWE_MAP_PRESET:
2713 rc = awe_load_map(&patch, addr, count);
2714 break;
2715 /* case AWE_PROBE_INFO:
2716 rc = awe_probe_info(&patch, addr, count);
2717 break;*/
2718 case AWE_PROBE_DATA:
2719 rc = awe_probe_data(&patch, addr, count);
2720 break;
2721 case AWE_REMOVE_INFO:
2722 rc = awe_remove_info(&patch, addr, count);
2723 break;
2724 case AWE_LOAD_CHORUS_FX:
2725 rc = awe_load_chorus_fx(&patch, addr, count);
2726 break;
2727 case AWE_LOAD_REVERB_FX:
2728 rc = awe_load_reverb_fx(&patch, addr, count);
2729 break;
2730
2731 default:
2732 printk(KERN_WARNING "AWE32 Error: unknown patch format type %d\n",
2733 patch.type);
2734 rc = -EINVAL;
2735 }
2736
2737 return rc;
2738}
2739
2740
2741/* create an sf list record */
2742static int
2743awe_create_sf(int type, char *name)
2744{
2745 sf_list *rec;
2746
2747 /* terminate sounds */
2748 awe_reset(0);
2749 rec = (sf_list *)kmalloc(sizeof(*rec), GFP_KERNEL);
2750 if (rec == NULL)
2751 return 1; /* no memory */
2752 rec->sf_id = current_sf_id + 1;
2753 rec->type = type;
2754 if (/*current_sf_id == 0 ||*/ (type & AWE_PAT_LOCKED) != 0)
2755 locked_sf_id = current_sf_id + 1;
2756 rec->num_info = awe_free_info();
2757 rec->num_sample = awe_free_sample();
2758 rec->mem_ptr = awe_free_mem_ptr();
2759 rec->infos = rec->last_infos = NULL;
2760 rec->samples = rec->last_samples = NULL;
2761
2762 /* add to linked-list */
2763 rec->next = NULL;
2764 rec->prev = sftail;
2765 if (sftail)
2766 sftail->next = rec;
2767 else
2768 sfhead = rec;
2769 sftail = rec;
2770 current_sf_id++;
2771
2772#ifdef AWE_ALLOW_SAMPLE_SHARING
2773 rec->shared = NULL;
2774 if (name)
2775 memcpy(rec->name, name, AWE_PATCH_NAME_LEN);
2776 else
2777 strcpy(rec->name, "*TEMPORARY*");
2778 if (current_sf_id > 1 && name && (type & AWE_PAT_SHARED) != 0) {
2779 /* is the current font really a shared font? */
2780 if (is_shared_sf(rec->name)) {
2781 /* check if the shared font is already installed */
2782 sf_list *p;
2783 for (p = rec->prev; p; p = p->prev) {
2784 if (is_identical_name(rec->name, p)) {
2785 rec->shared = p;
2786 break;
2787 }
2788 }
2789 }
2790 }
2791#endif /* allow sharing */
2792
2793 return 0;
2794}
2795
2796
2797#ifdef AWE_ALLOW_SAMPLE_SHARING
2798
2799/* check if the given name is a valid shared name */
2800#define ASC_TO_KEY(c) ((c) - 'A' + 1)
2801static int is_shared_sf(unsigned char *name)
2802{
2803 static unsigned char id_head[4] = {
2804 ASC_TO_KEY('A'), ASC_TO_KEY('W'), ASC_TO_KEY('E'),
2805 AWE_MAJOR_VERSION,
2806 };
2807 if (memcmp(name, id_head, 4) == 0)
2808 return TRUE;
2809 return FALSE;
2810}
2811
2812/* check if the given name matches to the existing list */
2813static int is_identical_name(unsigned char *name, sf_list *p)
2814{
2815 char *id = p->name;
2816 if (is_shared_sf(id) && memcmp(id, name, AWE_PATCH_NAME_LEN) == 0)
2817 return TRUE;
2818 return FALSE;
2819}
2820
2821/* check if the given voice info exists */
2822static int info_duplicated(sf_list *sf, awe_voice_list *rec)
2823{
2824 /* search for all sharing lists */
2825 for (; sf; sf = sf->shared) {
2826 awe_voice_list *p;
2827 for (p = sf->infos; p; p = p->next) {
2828 if (p->type == V_ST_NORMAL &&
2829 p->bank == rec->bank &&
2830 p->instr == rec->instr &&
2831 p->v.low == rec->v.low &&
2832 p->v.high == rec->v.high &&
2833 p->v.sample == rec->v.sample)
2834 return TRUE;
2835 }
2836 }
2837 return FALSE;
2838}
2839
2840#endif /* AWE_ALLOW_SAMPLE_SHARING */
2841
2842
2843/* free sf_list record */
2844/* linked-list in this function is not cared */
2845static void
2846awe_free_sf(sf_list *sf)
2847{
2848 if (sf->infos) {
2849 awe_voice_list *p, *next;
2850 for (p = sf->infos; p; p = next) {
2851 next = p->next;
2852 kfree(p);
2853 }
2854 }
2855 if (sf->samples) {
2856 awe_sample_list *p, *next;
2857 for (p = sf->samples; p; p = next) {
2858 next = p->next;
2859 kfree(p);
2860 }
2861 }
2862 kfree(sf);
2863}
2864
2865
2866/* open patch; create sf list and set opened flag */
2867static int
2868awe_open_patch(awe_patch_info *patch, const char __user *addr, int count)
2869{
2870 awe_open_parm parm;
2871 int shared;
2872
2873 if (copy_from_user(&parm, addr + AWE_PATCH_INFO_SIZE, sizeof(parm)))
2874 return -EFAULT;
2875 shared = FALSE;
2876
2877#ifdef AWE_ALLOW_SAMPLE_SHARING
2878 if (sftail && (parm.type & AWE_PAT_SHARED) != 0) {
2879 /* is the previous font the same font? */
2880 if (is_identical_name(parm.name, sftail)) {
2881 /* then append to the previous */
2882 shared = TRUE;
2883 awe_reset(0);
2884 if (parm.type & AWE_PAT_LOCKED)
2885 locked_sf_id = current_sf_id;
2886 }
2887 }
2888#endif /* allow sharing */
2889 if (! shared) {
2890 if (awe_create_sf(parm.type, parm.name)) {
2891 printk(KERN_ERR "AWE32: can't open: failed to alloc new list\n");
2892 return -ENOMEM;
2893 }
2894 }
2895 patch_opened = TRUE;
2896 return current_sf_id;
2897}
2898
2899/* check if the patch is already opened */
2900static sf_list *
2901check_patch_opened(int type, char *name)
2902{
2903 if (! patch_opened) {
2904 if (awe_create_sf(type, name)) {
2905 printk(KERN_ERR "AWE32: failed to alloc new list\n");
2906 return NULL;
2907 }
2908 patch_opened = TRUE;
2909 return sftail;
2910 }
2911 return sftail;
2912}
2913
2914/* close the patch; if no voice is loaded, remove the patch */
2915static int
2916awe_close_patch(awe_patch_info *patch, const char __user *addr, int count)
2917{
2918 if (patch_opened && sftail) {
2919 /* if no voice is loaded, release the current patch */
2920 if (sftail->infos == NULL) {
2921 awe_reset(0);
2922 awe_remove_samples(current_sf_id - 1);
2923 }
2924 }
2925 patch_opened = 0;
2926 return 0;
2927}
2928
2929
2930/* remove the latest patch */
2931static int
2932awe_unload_patch(awe_patch_info *patch, const char __user *addr, int count)
2933{
2934 if (current_sf_id > 0 && current_sf_id > locked_sf_id) {
2935 awe_reset(0);
2936 awe_remove_samples(current_sf_id - 1);
2937 }
2938 return 0;
2939}
2940
2941/* allocate voice info list records */
2942static awe_voice_list *
2943alloc_new_info(void)
2944{
2945 awe_voice_list *newlist;
2946
2947 newlist = (awe_voice_list *)kmalloc(sizeof(*newlist), GFP_KERNEL);
2948 if (newlist == NULL) {
2949 printk(KERN_ERR "AWE32: can't alloc info table\n");
2950 return NULL;
2951 }
2952 return newlist;
2953}
2954
2955/* allocate sample info list records */
2956static awe_sample_list *
2957alloc_new_sample(void)
2958{
2959 awe_sample_list *newlist;
2960
2961 newlist = (awe_sample_list *)kmalloc(sizeof(*newlist), GFP_KERNEL);
2962 if (newlist == NULL) {
2963 printk(KERN_ERR "AWE32: can't alloc sample table\n");
2964 return NULL;
2965 }
2966 return newlist;
2967}
2968
2969/* load voice map */
2970static int
2971awe_load_map(awe_patch_info *patch, const char __user *addr, int count)
2972{
2973 awe_voice_map map;
2974 awe_voice_list *rec, *p;
2975 sf_list *sf;
2976
2977 /* get the link info */
2978 if (count < sizeof(map)) {
2979 printk(KERN_WARNING "AWE32 Error: invalid patch info length\n");
2980 return -EINVAL;
2981 }
2982 if (copy_from_user(&map, addr + AWE_PATCH_INFO_SIZE, sizeof(map)))
2983 return -EFAULT;
2984
2985 /* check if the identical mapping already exists */
2986 p = awe_search_instr(map.map_bank, map.map_instr, map.map_key);
2987 for (; p; p = p->next_instr) {
2988 if (p->type == V_ST_MAPPED &&
2989 p->v.start == map.src_instr &&
2990 p->v.end == map.src_bank &&
2991 p->v.fixkey == map.src_key)
2992 return 0; /* already present! */
2993 }
2994
2995 if ((sf = check_patch_opened(AWE_PAT_TYPE_MAP, NULL)) == NULL)
2996 return -ENOMEM;
2997
2998 if ((rec = alloc_new_info()) == NULL)
2999 return -ENOMEM;
3000
3001 rec->bank = map.map_bank;
3002 rec->instr = map.map_instr;
3003 rec->type = V_ST_MAPPED;
3004 rec->disabled = FALSE;
3005 awe_init_voice_info(&rec->v);
3006 if (map.map_key >= 0) {
3007 rec->v.low = map.map_key;
3008 rec->v.high = map.map_key;
3009 }
3010 rec->v.start = map.src_instr;
3011 rec->v.end = map.src_bank;
3012 rec->v.fixkey = map.src_key;
3013 add_sf_info(sf, rec);
3014 add_info_list(rec);
3015
3016 return 0;
3017}
3018
3019#if 0
3020/* probe preset in the current list -- nothing to be loaded */
3021static int
3022awe_probe_info(awe_patch_info *patch, const char __user *addr, int count)
3023{
3024#ifdef AWE_ALLOW_SAMPLE_SHARING
3025 awe_voice_map map;
3026 awe_voice_list *p;
3027
3028 if (! patch_opened)
3029 return -EINVAL;
3030
3031 /* get the link info */
3032 if (count < sizeof(map)) {
3033 printk(KERN_WARNING "AWE32 Error: invalid patch info length\n");
3034 return -EINVAL;
3035 }
3036 if (copy_from_user(&map, addr + AWE_PATCH_INFO_SIZE, sizeof(map)))
3037 return -EFAULT;
3038
3039 /* check if the identical mapping already exists */
3040 if (sftail == NULL)
3041 return -EINVAL;
3042 p = awe_search_instr(map.src_bank, map.src_instr, map.src_key);
3043 for (; p; p = p->next_instr) {
3044 if (p->type == V_ST_NORMAL &&
3045 is_identical_holder(p->holder, sftail) &&
3046 p->v.low <= map.src_key &&
3047 p->v.high >= map.src_key)
3048 return 0; /* already present! */
3049 }
3050#endif /* allow sharing */
3051 return -EINVAL;
3052}
3053#endif
3054
3055/* probe sample in the current list -- nothing to be loaded */
3056static int
3057awe_probe_data(awe_patch_info *patch, const char __user *addr, int count)
3058{
3059#ifdef AWE_ALLOW_SAMPLE_SHARING
3060 if (! patch_opened)
3061 return -EINVAL;
3062
3063 /* search the specified sample by optarg */
3064 if (search_sample_index(sftail, patch->optarg) != NULL)
3065 return 0;
3066#endif /* allow sharing */
3067 return -EINVAL;
3068}
3069
3070
3071/* remove the present instrument layers */
3072static int
3073remove_info(sf_list *sf, int bank, int instr)
3074{
3075 awe_voice_list *prev, *next, *p;
3076 int removed = 0;
3077
3078 prev = NULL;
3079 for (p = sf->infos; p; p = next) {
3080 next = p->next;
3081 if (p->type == V_ST_NORMAL &&
3082 p->bank == bank && p->instr == instr) {
3083 /* remove this layer */
3084 if (prev)
3085 prev->next = next;
3086 else
3087 sf->infos = next;
3088 if (p == sf->last_infos)
3089 sf->last_infos = prev;
3090 sf->num_info--;
3091 removed++;
3092 kfree(p);
3093 } else
3094 prev = p;
3095 }
3096 if (removed)
3097 rebuild_preset_list();
3098 return removed;
3099}
3100
3101/* load voice information data */
3102static int
3103awe_load_info(awe_patch_info *patch, const char __user *addr, int count)
3104{
3105 int offset;
3106 awe_voice_rec_hdr hdr;
3107 int i;
3108 int total_size;
3109 sf_list *sf;
3110 awe_voice_list *rec;
3111
3112 if (count < AWE_VOICE_REC_SIZE) {
3113 printk(KERN_WARNING "AWE32 Error: invalid patch info length\n");
3114 return -EINVAL;
3115 }
3116
3117 offset = AWE_PATCH_INFO_SIZE;
3118 if (copy_from_user((char*)&hdr, addr + offset, AWE_VOICE_REC_SIZE))
3119 return -EFAULT;
3120 offset += AWE_VOICE_REC_SIZE;
3121
3122 if (hdr.nvoices <= 0 || hdr.nvoices >= 100) {
3123 printk(KERN_WARNING "AWE32 Error: Invalid voice number %d\n", hdr.nvoices);
3124 return -EINVAL;
3125 }
3126 total_size = AWE_VOICE_REC_SIZE + AWE_VOICE_INFO_SIZE * hdr.nvoices;
3127 if (count < total_size) {
3128 printk(KERN_WARNING "AWE32 Error: patch length(%d) is smaller than nvoices(%d)\n",
3129 count, hdr.nvoices);
3130 return -EINVAL;
3131 }
3132
3133 if ((sf = check_patch_opened(AWE_PAT_TYPE_MISC, NULL)) == NULL)
3134 return -ENOMEM;
3135
3136 switch (hdr.write_mode) {
3137 case AWE_WR_EXCLUSIVE:
3138 /* exclusive mode - if the instrument already exists,
3139 return error */
3140 for (rec = sf->infos; rec; rec = rec->next) {
3141 if (rec->type == V_ST_NORMAL &&
3142 rec->bank == hdr.bank &&
3143 rec->instr == hdr.instr)
3144 return -EINVAL;
3145 }
3146 break;
3147 case AWE_WR_REPLACE:
3148 /* replace mode - remove the instrument if it already exists */
3149 remove_info(sf, hdr.bank, hdr.instr);
3150 break;
3151 }
3152
3153 /* append new layers */
3154 for (i = 0; i < hdr.nvoices; i++) {
3155 rec = alloc_new_info();
3156 if (rec == NULL)
3157 return -ENOMEM;
3158
3159 rec->bank = hdr.bank;
3160 rec->instr = hdr.instr;
3161 rec->type = V_ST_NORMAL;
3162 rec->disabled = FALSE;
3163
3164 /* copy awe_voice_info parameters */
3165 if (copy_from_user(&rec->v, addr + offset, AWE_VOICE_INFO_SIZE)) {
3166 kfree(rec);
3167 return -EFAULT;
3168 }
3169 offset += AWE_VOICE_INFO_SIZE;
3170#ifdef AWE_ALLOW_SAMPLE_SHARING
3171 if (sf && sf->shared) {
3172 if (info_duplicated(sf, rec)) {
3173 kfree(rec);
3174 continue;
3175 }
3176 }
3177#endif /* allow sharing */
3178 if (rec->v.mode & AWE_MODE_INIT_PARM)
3179 awe_init_voice_parm(&rec->v.parm);
3180 add_sf_info(sf, rec);
3181 awe_set_sample(rec);
3182 add_info_list(rec);
3183 }
3184
3185 return 0;
3186}
3187
3188
3189/* remove instrument layers */
3190static int
3191awe_remove_info(awe_patch_info *patch, const char __user *addr, int count)
3192{
3193 unsigned char bank, instr;
3194 sf_list *sf;
3195
3196 if (! patch_opened || (sf = sftail) == NULL) {
3197 printk(KERN_WARNING "AWE32: remove_info: patch not opened\n");
3198 return -EINVAL;
3199 }
3200
3201 bank = ((unsigned short)patch->optarg >> 8) & 0xff;
3202 instr = (unsigned short)patch->optarg & 0xff;
3203 if (! remove_info(sf, bank, instr))
3204 return -EINVAL;
3205 return 0;
3206}
3207
3208
3209/* load wave sample data */
3210static int
3211awe_load_data(awe_patch_info *patch, const char __user *addr, int count)
3212{
3213 int offset, size;
3214 int rc;
3215 awe_sample_info tmprec;
3216 awe_sample_list *rec;
3217 sf_list *sf;
3218
3219 if ((sf = check_patch_opened(AWE_PAT_TYPE_MISC, NULL)) == NULL)
3220 return -ENOMEM;
3221
3222 size = (count - AWE_SAMPLE_INFO_SIZE) / 2;
3223 offset = AWE_PATCH_INFO_SIZE;
3224 if (copy_from_user(&tmprec, addr + offset, AWE_SAMPLE_INFO_SIZE))
3225 return -EFAULT;
3226 offset += AWE_SAMPLE_INFO_SIZE;
3227 if (size != tmprec.size) {
3228 printk(KERN_WARNING "AWE32: load: sample size differed (%d != %d)\n",
3229 tmprec.size, size);
3230 return -EINVAL;
3231 }
3232
3233 if (search_sample_index(sf, tmprec.sample) != NULL) {
3234#ifdef AWE_ALLOW_SAMPLE_SHARING
3235 /* if shared sample, skip this data */
3236 if (sf->type & AWE_PAT_SHARED)
3237 return 0;
3238#endif /* allow sharing */
3239 DEBUG(1,printk("AWE32: sample data %d already present\n", tmprec.sample));
3240 return -EINVAL;
3241 }
3242
3243 if ((rec = alloc_new_sample()) == NULL)
3244 return -ENOMEM;
3245
3246 memcpy(&rec->v, &tmprec, sizeof(tmprec));
3247
3248 if (rec->v.size > 0) {
3249 if ((rc = awe_write_wave_data(addr, offset, rec, -1)) < 0) {
3250 kfree(rec);
3251 return rc;
3252 }
3253 sf->mem_ptr += rc;
3254 }
3255
3256 add_sf_sample(sf, rec);
3257 return 0;
3258}
3259
3260
3261/* replace wave sample data */
3262static int
3263awe_replace_data(awe_patch_info *patch, const char __user *addr, int count)
3264{
3265 int offset;
3266 int size;
3267 int rc;
3268 int channels;
3269 awe_sample_info cursmp;
3270 int save_mem_ptr;
3271 sf_list *sf;
3272 awe_sample_list *rec;
3273
3274 if (! patch_opened || (sf = sftail) == NULL) {
3275 printk(KERN_WARNING "AWE32: replace: patch not opened\n");
3276 return -EINVAL;
3277 }
3278
3279 size = (count - AWE_SAMPLE_INFO_SIZE) / 2;
3280 offset = AWE_PATCH_INFO_SIZE;
3281 if (copy_from_user(&cursmp, addr + offset, AWE_SAMPLE_INFO_SIZE))
3282 return -EFAULT;
3283 offset += AWE_SAMPLE_INFO_SIZE;
3284 if (cursmp.size == 0 || size != cursmp.size) {
3285 printk(KERN_WARNING "AWE32: replace: invalid sample size (%d!=%d)\n",
3286 cursmp.size, size);
3287 return -EINVAL;
3288 }
3289 channels = patch->optarg;
3290 if (channels <= 0 || channels > AWE_NORMAL_VOICES) {
3291 printk(KERN_WARNING "AWE32: replace: invalid channels %d\n", channels);
3292 return -EINVAL;
3293 }
3294
3295 for (rec = sf->samples; rec; rec = rec->next) {
3296 if (rec->v.sample == cursmp.sample)
3297 break;
3298 }
3299 if (rec == NULL) {
3300 printk(KERN_WARNING "AWE32: replace: cannot find existing sample data %d\n",
3301 cursmp.sample);
3302 return -EINVAL;
3303 }
3304
3305 if (rec->v.size != cursmp.size) {
3306 printk(KERN_WARNING "AWE32: replace: exiting size differed (%d!=%d)\n",
3307 rec->v.size, cursmp.size);
3308 return -EINVAL;
3309 }
3310
3311 save_mem_ptr = awe_free_mem_ptr();
3312 sftail->mem_ptr = rec->v.start - awe_mem_start;
3313 memcpy(&rec->v, &cursmp, sizeof(cursmp));
3314 rec->v.sf_id = current_sf_id;
3315 if ((rc = awe_write_wave_data(addr, offset, rec, channels)) < 0)
3316 return rc;
3317 sftail->mem_ptr = save_mem_ptr;
3318
3319 return 0;
3320}
3321
3322
3323/*----------------------------------------------------------------*/
3324
3325static const char __user *readbuf_addr;
3326static int readbuf_offs;
3327static int readbuf_flags;
3328
3329/* initialize read buffer */
3330static int
3331readbuf_init(const char __user *addr, int offset, awe_sample_info *sp)
3332{
3333 readbuf_addr = addr;
3334 readbuf_offs = offset;
3335 readbuf_flags = sp->mode_flags;
3336 return 0;
3337}
3338
3339/* read directly from user buffer */
3340static unsigned short
3341readbuf_word(int pos)
3342{
3343 unsigned short c;
3344 /* read from user buffer */
3345 if (readbuf_flags & AWE_SAMPLE_8BITS) {
3346 unsigned char cc;
3347 get_user(cc, (unsigned char __user *)(readbuf_addr + readbuf_offs + pos));
3348 c = (unsigned short)cc << 8; /* convert 8bit -> 16bit */
3349 } else {
3350 get_user(c, (unsigned short __user *)(readbuf_addr + readbuf_offs + pos * 2));
3351 }
3352 if (readbuf_flags & AWE_SAMPLE_UNSIGNED)
3353 c ^= 0x8000; /* unsigned -> signed */
3354 return c;
3355}
3356
3357#define readbuf_word_cache readbuf_word
3358#define readbuf_end() /**/
3359
3360/*----------------------------------------------------------------*/
3361
3362#define BLANK_LOOP_START 8
3363#define BLANK_LOOP_END 40
3364#define BLANK_LOOP_SIZE 48
3365
3366/* loading onto memory - return the actual written size */
3367static int
3368awe_write_wave_data(const char __user *addr, int offset, awe_sample_list *list, int channels)
3369{
3370 int i, truesize, dram_offset;
3371 awe_sample_info *sp = &list->v;
3372 int rc;
3373
3374 /* be sure loop points start < end */
3375 if (sp->loopstart > sp->loopend) {
3376 int tmp = sp->loopstart;
3377 sp->loopstart = sp->loopend;
3378 sp->loopend = tmp;
3379 }
3380
3381 /* compute true data size to be loaded */
3382 truesize = sp->size;
3383 if (sp->mode_flags & (AWE_SAMPLE_BIDIR_LOOP|AWE_SAMPLE_REVERSE_LOOP))
3384 truesize += sp->loopend - sp->loopstart;
3385 if (sp->mode_flags & AWE_SAMPLE_NO_BLANK)
3386 truesize += BLANK_LOOP_SIZE;
3387 if (awe_free_mem_ptr() + truesize >= memsize/2) {
3388 DEBUG(-1,printk("AWE32 Error: Sample memory full\n"));
3389 return -ENOSPC;
3390 }
3391
3392 /* recalculate address offset */
3393 sp->end -= sp->start;
3394 sp->loopstart -= sp->start;
3395 sp->loopend -= sp->start;
3396
3397 dram_offset = awe_free_mem_ptr() + awe_mem_start;
3398 sp->start = dram_offset;
3399 sp->end += dram_offset;
3400 sp->loopstart += dram_offset;
3401 sp->loopend += dram_offset;
3402
3403 /* set the total size (store onto obsolete checksum value) */
3404 if (sp->size == 0)
3405 sp->checksum = 0;
3406 else
3407 sp->checksum = truesize;
3408
3409 if ((rc = awe_open_dram_for_write(dram_offset, channels)) != 0)
3410 return rc;
3411
3412 if (readbuf_init(addr, offset, sp) < 0)
3413 return -ENOSPC;
3414
3415 for (i = 0; i < sp->size; i++) {
3416 unsigned short c;
3417 c = readbuf_word(i);
3418 awe_write_dram(c);
3419 if (i == sp->loopend &&
3420 (sp->mode_flags & (AWE_SAMPLE_BIDIR_LOOP|AWE_SAMPLE_REVERSE_LOOP))) {
3421 int looplen = sp->loopend - sp->loopstart;
3422 /* copy reverse loop */
3423 int k;
3424 for (k = 1; k <= looplen; k++) {
3425 c = readbuf_word_cache(i - k);
3426 awe_write_dram(c);
3427 }
3428 if (sp->mode_flags & AWE_SAMPLE_BIDIR_LOOP) {
3429 sp->end += looplen;
3430 } else {
3431 sp->start += looplen;
3432 sp->end += looplen;
3433 }
3434 }
3435 }
3436 readbuf_end();
3437
3438 /* if no blank loop is attached in the sample, add it */
3439 if (sp->mode_flags & AWE_SAMPLE_NO_BLANK) {
3440 for (i = 0; i < BLANK_LOOP_SIZE; i++)
3441 awe_write_dram(0);
3442 if (sp->mode_flags & AWE_SAMPLE_SINGLESHOT) {
3443 sp->loopstart = sp->end + BLANK_LOOP_START;
3444 sp->loopend = sp->end + BLANK_LOOP_END;
3445 }
3446 }
3447
3448 awe_close_dram();
3449
3450 /* initialize FM */
3451 awe_init_fm();
3452
3453 return truesize;
3454}
3455
3456
3457/*----------------------------------------------------------------*/
3458
3459#ifdef AWE_HAS_GUS_COMPATIBILITY
3460
3461/* calculate GUS envelope time:
3462 * is this correct? i have no idea..
3463 */
3464static int
3465calc_gus_envelope_time(int rate, int start, int end)
3466{
3467 int r, p, t;
3468 r = (3 - ((rate >> 6) & 3)) * 3;
3469 p = rate & 0x3f;
3470 t = end - start;
3471 if (t < 0) t = -t;
3472 if (13 > r)
3473 t = t << (13 - r);
3474 else
3475 t = t >> (r - 13);
3476 return (t * 10) / (p * 441);
3477}
3478
3479#define calc_gus_sustain(val) (0x7f - vol_table[(val)/2])
3480#define calc_gus_attenuation(val) vol_table[(val)/2]
3481
3482/* load GUS patch */
3483static int
3484awe_load_guspatch(const char __user *addr, int offs, int size, int pmgr_flag)
3485{
3486 struct patch_info patch;
3487 awe_voice_info *rec;
3488 awe_sample_info *smp;
3489 awe_voice_list *vrec;
3490 awe_sample_list *smprec;
3491 int sizeof_patch;
3492 int note, rc;
3493 sf_list *sf;
3494
3495 sizeof_patch = (int)((long)&patch.data[0] - (long)&patch); /* header size */
3496 if (size < sizeof_patch) {
3497 printk(KERN_WARNING "AWE32 Error: Patch header too short\n");
3498 return -EINVAL;
3499 }
3500 if (copy_from_user(((char*)&patch) + offs, addr + offs, sizeof_patch - offs))
3501 return -EFAULT;
3502 size -= sizeof_patch;
3503 if (size < patch.len) {
3504 printk(KERN_WARNING "AWE32 Error: Patch record too short (%d<%d)\n",
3505 size, patch.len);
3506 return -EINVAL;
3507 }
3508 if ((sf = check_patch_opened(AWE_PAT_TYPE_GUS, NULL)) == NULL)
3509 return -ENOMEM;
3510 if ((smprec = alloc_new_sample()) == NULL)
3511 return -ENOMEM;
3512 if ((vrec = alloc_new_info()) == NULL) {
3513 kfree(smprec);
3514 return -ENOMEM;
3515 }
3516
3517 smp = &smprec->v;
3518 smp->sample = sf->num_sample;
3519 smp->start = 0;
3520 smp->end = patch.len;
3521 smp->loopstart = patch.loop_start;
3522 smp->loopend = patch.loop_end;
3523 smp->size = patch.len;
3524
3525 /* set up mode flags */
3526 smp->mode_flags = 0;
3527 if (!(patch.mode & WAVE_16_BITS))
3528 smp->mode_flags |= AWE_SAMPLE_8BITS;
3529 if (patch.mode & WAVE_UNSIGNED)
3530 smp->mode_flags |= AWE_SAMPLE_UNSIGNED;
3531 smp->mode_flags |= AWE_SAMPLE_NO_BLANK;
3532 if (!(patch.mode & (WAVE_LOOPING|WAVE_BIDIR_LOOP|WAVE_LOOP_BACK)))
3533 smp->mode_flags |= AWE_SAMPLE_SINGLESHOT;
3534 if (patch.mode & WAVE_BIDIR_LOOP)
3535 smp->mode_flags |= AWE_SAMPLE_BIDIR_LOOP;
3536 if (patch.mode & WAVE_LOOP_BACK)
3537 smp->mode_flags |= AWE_SAMPLE_REVERSE_LOOP;
3538
3539 DEBUG(0,printk("AWE32: [sample %d mode %x]\n", patch.instr_no, smp->mode_flags));
3540 if (patch.mode & WAVE_16_BITS) {
3541 /* convert to word offsets */
3542 smp->size /= 2;
3543 smp->end /= 2;
3544 smp->loopstart /= 2;
3545 smp->loopend /= 2;
3546 }
3547 smp->checksum_flag = 0;
3548 smp->checksum = 0;
3549
3550 if ((rc = awe_write_wave_data(addr, sizeof_patch, smprec, -1)) < 0)
3551 return rc;
3552 sf->mem_ptr += rc;
3553 add_sf_sample(sf, smprec);
3554
3555 /* set up voice info */
3556 rec = &vrec->v;
3557 awe_init_voice_info(rec);
3558 rec->sample = sf->num_info; /* the last sample */
3559 rec->rate_offset = calc_rate_offset(patch.base_freq);
3560 note = freq_to_note(patch.base_note);
3561 rec->root = note / 100;
3562 rec->tune = -(note % 100);
3563 rec->low = freq_to_note(patch.low_note) / 100;
3564 rec->high = freq_to_note(patch.high_note) / 100;
3565 DEBUG(1,printk("AWE32: [gus base offset=%d, note=%d, range=%d-%d(%d-%d)]\n",
3566 rec->rate_offset, note,
3567 rec->low, rec->high,
3568 patch.low_note, patch.high_note));
3569 /* panning position; -128 - 127 => 0-127 */
3570 rec->pan = (patch.panning + 128) / 2;
3571
3572 /* detuning is ignored */
3573 /* 6points volume envelope */
3574 if (patch.mode & WAVE_ENVELOPES) {
3575 int attack, hold, decay, release;
3576 attack = calc_gus_envelope_time
3577 (patch.env_rate[0], 0, patch.env_offset[0]);
3578 hold = calc_gus_envelope_time
3579 (patch.env_rate[1], patch.env_offset[0],
3580 patch.env_offset[1]);
3581 decay = calc_gus_envelope_time
3582 (patch.env_rate[2], patch.env_offset[1],
3583 patch.env_offset[2]);
3584 release = calc_gus_envelope_time
3585 (patch.env_rate[3], patch.env_offset[1],
3586 patch.env_offset[4]);
3587 release += calc_gus_envelope_time
3588 (patch.env_rate[4], patch.env_offset[3],
3589 patch.env_offset[4]);
3590 release += calc_gus_envelope_time
3591 (patch.env_rate[5], patch.env_offset[4],
3592 patch.env_offset[5]);
3593 rec->parm.volatkhld = (calc_parm_hold(hold) << 8) |
3594 calc_parm_attack(attack);
3595 rec->parm.voldcysus = (calc_gus_sustain(patch.env_offset[2]) << 8) |
3596 calc_parm_decay(decay);
3597 rec->parm.volrelease = 0x8000 | calc_parm_decay(release);
3598 DEBUG(2,printk("AWE32: [gusenv atk=%d, hld=%d, dcy=%d, rel=%d]\n", attack, hold, decay, release));
3599 rec->attenuation = calc_gus_attenuation(patch.env_offset[0]);
3600 }
3601
3602 /* tremolo effect */
3603 if (patch.mode & WAVE_TREMOLO) {
3604 int rate = (patch.tremolo_rate * 1000 / 38) / 42;
3605 rec->parm.tremfrq = ((patch.tremolo_depth / 2) << 8) | rate;
3606 DEBUG(2,printk("AWE32: [gusenv tremolo rate=%d, dep=%d, tremfrq=%x]\n",
3607 patch.tremolo_rate, patch.tremolo_depth,
3608 rec->parm.tremfrq));
3609 }
3610 /* vibrato effect */
3611 if (patch.mode & WAVE_VIBRATO) {
3612 int rate = (patch.vibrato_rate * 1000 / 38) / 42;
3613 rec->parm.fm2frq2 = ((patch.vibrato_depth / 6) << 8) | rate;
3614 DEBUG(2,printk("AWE32: [gusenv vibrato rate=%d, dep=%d, tremfrq=%x]\n",
3615 patch.tremolo_rate, patch.tremolo_depth,
3616 rec->parm.tremfrq));
3617 }
3618
3619 /* scale_freq, scale_factor, volume, and fractions not implemented */
3620
3621 /* append to the tail of the list */
3622 vrec->bank = ctrls[AWE_MD_GUS_BANK];
3623 vrec->instr = patch.instr_no;
3624 vrec->disabled = FALSE;
3625 vrec->type = V_ST_NORMAL;
3626
3627 add_sf_info(sf, vrec);
3628 add_info_list(vrec);
3629
3630 /* set the voice index */
3631 awe_set_sample(vrec);
3632
3633 return 0;
3634}
3635
3636#endif /* AWE_HAS_GUS_COMPATIBILITY */
3637
3638/*
3639 * sample and voice list handlers
3640 */
3641
3642/* append this to the current sf list */
3643static void add_sf_info(sf_list *sf, awe_voice_list *rec)
3644{
3645 if (sf == NULL)
3646 return;
3647 rec->holder = sf;
3648 rec->v.sf_id = sf->sf_id;
3649 if (sf->last_infos)
3650 sf->last_infos->next = rec;
3651 else
3652 sf->infos = rec;
3653 sf->last_infos = rec;
3654 rec->next = NULL;
3655 sf->num_info++;
3656}
3657
3658/* prepend this sample to sf list */
3659static void add_sf_sample(sf_list *sf, awe_sample_list *rec)
3660{
3661 if (sf == NULL)
3662 return;
3663 rec->holder = sf;
3664 rec->v.sf_id = sf->sf_id;
3665 if (sf->last_samples)
3666 sf->last_samples->next = rec;
3667 else
3668 sf->samples = rec;
3669 sf->last_samples = rec;
3670 rec->next = NULL;
3671 sf->num_sample++;
3672}
3673
3674/* purge the old records which don't belong with the same file id */
3675static void purge_old_list(awe_voice_list *rec, awe_voice_list *next)
3676{
3677 rec->next_instr = next;
3678 if (rec->bank == AWE_DRUM_BANK) {
3679 /* remove samples with the same note range */
3680 awe_voice_list *cur, *prev = rec;
3681 int low = rec->v.low;
3682 int high = rec->v.high;
3683 for (cur = next; cur; cur = cur->next_instr) {
3684 if (cur->v.low == low &&
3685 cur->v.high == high &&
3686 ! is_identical_holder(cur->holder, rec->holder))
3687 prev->next_instr = cur->next_instr;
3688 else
3689 prev = cur;
3690 }
3691 } else {
3692 if (! is_identical_holder(next->holder, rec->holder))
3693 /* remove all samples */
3694 rec->next_instr = NULL;
3695 }
3696}
3697
3698/* prepend to top of the preset table */
3699static void add_info_list(awe_voice_list *rec)
3700{
3701 awe_voice_list *prev, *cur;
3702 int key;
3703
3704 if (rec->disabled)
3705 return;
3706
3707 key = awe_search_key(rec->bank, rec->instr, rec->v.low);
3708 prev = NULL;
3709 for (cur = preset_table[key]; cur; cur = cur->next_bank) {
3710 /* search the first record with the same bank number */
3711 if (cur->instr == rec->instr && cur->bank == rec->bank) {
3712 /* replace the list with the new record */
3713 rec->next_bank = cur->next_bank;
3714 if (prev)
3715 prev->next_bank = rec;
3716 else
3717 preset_table[key] = rec;
3718 purge_old_list(rec, cur);
3719 return;
3720 }
3721 prev = cur;
3722 }
3723
3724 /* this is the first bank record.. just add this */
3725 rec->next_instr = NULL;
3726 rec->next_bank = preset_table[key];
3727 preset_table[key] = rec;
3728}
3729
3730/* remove samples later than the specified sf_id */
3731static void
3732awe_remove_samples(int sf_id)
3733{
3734 sf_list *p, *prev;
3735
3736 if (sf_id <= 0) {
3737 awe_reset_samples();
3738 return;
3739 }
3740 /* already removed? */
3741 if (current_sf_id <= sf_id)
3742 return;
3743
3744 for (p = sftail; p; p = prev) {
3745 if (p->sf_id <= sf_id)
3746 break;
3747 prev = p->prev;
3748 awe_free_sf(p);
3749 }
3750 sftail = p;
3751 if (sftail) {
3752 sf_id = sftail->sf_id;
3753 sftail->next = NULL;
3754 } else {
3755 sf_id = 0;
3756 sfhead = NULL;
3757 }
3758 current_sf_id = sf_id;
3759 if (locked_sf_id > sf_id)
3760 locked_sf_id = sf_id;
3761
3762 rebuild_preset_list();
3763}
3764
3765/* rebuild preset search list */
3766static void rebuild_preset_list(void)
3767{
3768 sf_list *p;
3769 awe_voice_list *rec;
3770
3771 memset(preset_table, 0, sizeof(preset_table));
3772
3773 for (p = sfhead; p; p = p->next) {
3774 for (rec = p->infos; rec; rec = rec->next)
3775 add_info_list(rec);
3776 }
3777}
3778
3779/* compare the given sf_id pair */
3780static int is_identical_holder(sf_list *sf1, sf_list *sf2)
3781{
3782 if (sf1 == NULL || sf2 == NULL)
3783 return FALSE;
3784 if (sf1 == sf2)
3785 return TRUE;
3786#ifdef AWE_ALLOW_SAMPLE_SHARING
3787 {
3788 /* compare with the sharing id */
3789 sf_list *p;
3790 int counter = 0;
3791 if (sf1->sf_id < sf2->sf_id) { /* make sure id1 > id2 */
3792 sf_list *tmp; tmp = sf1; sf1 = sf2; sf2 = tmp;
3793 }
3794 for (p = sf1->shared; p; p = p->shared) {
3795 if (counter++ > current_sf_id)
3796 break; /* strange sharing loop.. quit */
3797 if (p == sf2)
3798 return TRUE;
3799 }
3800 }
3801#endif /* allow sharing */
3802 return FALSE;
3803}
3804
3805/* search the sample index matching with the given sample id */
3806static awe_sample_list *
3807search_sample_index(sf_list *sf, int sample)
3808{
3809 awe_sample_list *p;
3810#ifdef AWE_ALLOW_SAMPLE_SHARING
3811 int counter = 0;
3812 while (sf) {
3813 for (p = sf->samples; p; p = p->next) {
3814 if (p->v.sample == sample)
3815 return p;
3816 }
3817 sf = sf->shared;
3818 if (counter++ > current_sf_id)
3819 break; /* strange sharing loop.. quit */
3820 }
3821#else
3822 if (sf) {
3823 for (p = sf->samples; p; p = p->next) {
3824 if (p->v.sample == sample)
3825 return p;
3826 }
3827 }
3828#endif
3829 return NULL;
3830}
3831
3832/* search the specified sample */
3833/* non-zero = found */
3834static short
3835awe_set_sample(awe_voice_list *rec)
3836{
3837 awe_sample_list *smp;
3838 awe_voice_info *vp = &rec->v;
3839
3840 vp->index = 0;
3841 if ((smp = search_sample_index(rec->holder, vp->sample)) == NULL)
3842 return 0;
3843
3844 /* set the actual sample offsets */
3845 vp->start += smp->v.start;
3846 vp->end += smp->v.end;
3847 vp->loopstart += smp->v.loopstart;
3848 vp->loopend += smp->v.loopend;
3849 /* copy mode flags */
3850 vp->mode = smp->v.mode_flags;
3851 /* set flag */
3852 vp->index = 1;
3853
3854 return 1;
3855}
3856
3857
3858/*
3859 * voice allocation
3860 */
3861
3862/* look for all voices associated with the specified note & velocity */
3863static int
3864awe_search_multi_voices(awe_voice_list *rec, int note, int velocity,
3865 awe_voice_info **vlist)
3866{
3867 int nvoices;
3868
3869 nvoices = 0;
3870 for (; rec; rec = rec->next_instr) {
3871 if (note >= rec->v.low &&
3872 note <= rec->v.high &&
3873 velocity >= rec->v.vellow &&
3874 velocity <= rec->v.velhigh) {
3875 if (rec->type == V_ST_MAPPED) {
3876 /* mapper */
3877 vlist[0] = &rec->v;
3878 return -1;
3879 }
3880 vlist[nvoices++] = &rec->v;
3881 if (nvoices >= AWE_MAX_VOICES)
3882 break;
3883 }
3884 }
3885 return nvoices;
3886}
3887
3888/* store the voice list from the specified note and velocity.
3889 if the preset is mapped, seek for the destination preset, and rewrite
3890 the note number if necessary.
3891 */
3892static int
3893really_alloc_voices(int bank, int instr, int *note, int velocity, awe_voice_info **vlist)
3894{
3895 int nvoices;
3896 awe_voice_list *vrec;
3897 int level = 0;
3898
3899 for (;;) {
3900 vrec = awe_search_instr(bank, instr, *note);
3901 nvoices = awe_search_multi_voices(vrec, *note, velocity, vlist);
3902 if (nvoices == 0) {
3903 if (bank == AWE_DRUM_BANK)
3904 /* search default drumset */
3905 vrec = awe_search_instr(bank, ctrls[AWE_MD_DEF_DRUM], *note);
3906 else
3907 /* search default preset */
3908 vrec = awe_search_instr(ctrls[AWE_MD_DEF_BANK], instr, *note);
3909 nvoices = awe_search_multi_voices(vrec, *note, velocity, vlist);
3910 }
3911 if (nvoices == 0) {
3912 if (bank == AWE_DRUM_BANK && ctrls[AWE_MD_DEF_DRUM] != 0)
3913 /* search default drumset */
3914 vrec = awe_search_instr(bank, 0, *note);
3915 else if (bank != AWE_DRUM_BANK && ctrls[AWE_MD_DEF_BANK] != 0)
3916 /* search default preset */
3917 vrec = awe_search_instr(0, instr, *note);
3918 nvoices = awe_search_multi_voices(vrec, *note, velocity, vlist);
3919 }
3920 if (nvoices < 0) { /* mapping */
3921 int key = vlist[0]->fixkey;
3922 instr = vlist[0]->start;
3923 bank = vlist[0]->end;
3924 if (level++ > 5) {
3925 printk(KERN_ERR "AWE32: too deep mapping level\n");
3926 return 0;
3927 }
3928 if (key >= 0)
3929 *note = key;
3930 } else
3931 break;
3932 }
3933
3934 return nvoices;
3935}
3936
3937/* allocate voices corresponding note and velocity; supports multiple insts. */
3938static void
3939awe_alloc_multi_voices(int ch, int note, int velocity, int key)
3940{
3941 int i, v, nvoices, bank;
3942 awe_voice_info *vlist[AWE_MAX_VOICES];
3943
3944 if (MULTI_LAYER_MODE() && IS_DRUM_CHANNEL(ch))
3945 bank = AWE_DRUM_BANK; /* always search drumset */
3946 else
3947 bank = channels[ch].bank;
3948
3949 /* check the possible voices; note may be changeable if mapped */
3950 nvoices = really_alloc_voices(bank, channels[ch].instr,
3951 &note, velocity, vlist);
3952
3953 /* set the voices */
3954 current_alloc_time++;
3955 for (i = 0; i < nvoices; i++) {
3956 v = awe_clear_voice();
3957 voices[v].key = key;
3958 voices[v].ch = ch;
3959 voices[v].note = note;
3960 voices[v].velocity = velocity;
3961 voices[v].time = current_alloc_time;
3962 voices[v].cinfo = &channels[ch];
3963 voices[v].sample = vlist[i];
3964 voices[v].state = AWE_ST_MARK;
3965 voices[v].layer = nvoices - i - 1; /* in reverse order */
3966 }
3967
3968 /* clear the mark in allocated voices */
3969 for (i = 0; i < awe_max_voices; i++) {
3970 if (voices[i].state == AWE_ST_MARK)
3971 voices[i].state = AWE_ST_OFF;
3972
3973 }
3974}
3975
3976
3977/* search an empty voice.
3978 if no empty voice is found, at least terminate a voice
3979 */
3980static int
3981awe_clear_voice(void)
3982{
3983 enum {
3984 OFF=0, RELEASED, SUSTAINED, PLAYING, END
3985 };
3986 struct voice_candidate_t {
3987 int best;
3988 int time;
3989 int vtarget;
3990 } candidate[END];
3991 int i, type, vtarget;
3992
3993 vtarget = 0xffff;
3994 for (type = OFF; type < END; type++) {
3995 candidate[type].best = -1;
3996 candidate[type].time = current_alloc_time + 1;
3997 candidate[type].vtarget = vtarget;
3998 }
3999
4000 for (i = 0; i < awe_max_voices; i++) {
4001 if (voices[i].state & AWE_ST_OFF)
4002 type = OFF;
4003 else if (voices[i].state & AWE_ST_RELEASED)
4004 type = RELEASED;
4005 else if (voices[i].state & AWE_ST_SUSTAINED)
4006 type = SUSTAINED;
4007 else if (voices[i].state & ~AWE_ST_MARK)
4008 type = PLAYING;
4009 else
4010 continue;
4011#ifdef AWE_CHECK_VTARGET
4012 /* get current volume */
4013 vtarget = (awe_peek_dw(AWE_VTFT(i)) >> 16) & 0xffff;
4014#endif
4015 if (candidate[type].best < 0 ||
4016 vtarget < candidate[type].vtarget ||
4017 (vtarget == candidate[type].vtarget &&
4018 voices[i].time < candidate[type].time)) {
4019 candidate[type].best = i;
4020 candidate[type].time = voices[i].time;
4021 candidate[type].vtarget = vtarget;
4022 }
4023 }
4024
4025 for (type = OFF; type < END; type++) {
4026 if ((i = candidate[type].best) >= 0) {
4027 if (voices[i].state != AWE_ST_OFF)
4028 awe_terminate(i);
4029 awe_voice_init(i, TRUE);
4030 return i;
4031 }
4032 }
4033 return 0;
4034}
4035
4036
4037/* search sample for the specified note & velocity and set it on the voice;
4038 * note that voice is the voice index (not channel index)
4039 */
4040static void
4041awe_alloc_one_voice(int voice, int note, int velocity)
4042{
4043 int ch, nvoices, bank;
4044 awe_voice_info *vlist[AWE_MAX_VOICES];
4045
4046 ch = voices[voice].ch;
4047 if (MULTI_LAYER_MODE() && IS_DRUM_CHANNEL(voice))
4048 bank = AWE_DRUM_BANK; /* always search drumset */
4049 else
4050 bank = voices[voice].cinfo->bank;
4051
4052 nvoices = really_alloc_voices(bank, voices[voice].cinfo->instr,
4053 &note, velocity, vlist);
4054 if (nvoices > 0) {
4055 voices[voice].time = ++current_alloc_time;
4056 voices[voice].sample = vlist[0]; /* use the first one */
4057 voices[voice].layer = 0;
4058 voices[voice].note = note;
4059 voices[voice].velocity = velocity;
4060 }
4061}
4062
4063
4064/*
4065 * sequencer2 functions
4066 */
4067
4068/* search an empty voice; used by sequencer2 */
4069static int
4070awe_alloc(int dev, int chn, int note, struct voice_alloc_info *alloc)
4071{
4072 playing_mode = AWE_PLAY_MULTI2;
4073 awe_info.nr_voices = AWE_MAX_CHANNELS;
4074 return awe_clear_voice();
4075}
4076
4077
4078/* set up voice; used by sequencer2 */
4079static void
4080awe_setup_voice(int dev, int voice, int chn)
4081{
4082 struct channel_info *info;
4083 if (synth_devs[dev] == NULL ||
4084 (info = &synth_devs[dev]->chn_info[chn]) == NULL)
4085 return;
4086
4087 if (voice < 0 || voice >= awe_max_voices)
4088 return;
4089
4090 DEBUG(2,printk("AWE32: [setup(%d) ch=%d]\n", voice, chn));
4091 channels[chn].expression_vol = info->controllers[CTL_EXPRESSION];
4092 channels[chn].main_vol = info->controllers[CTL_MAIN_VOLUME];
4093 channels[chn].panning =
4094 info->controllers[CTL_PAN] * 2 - 128; /* signed 8bit */
4095 channels[chn].bender = info->bender_value; /* zero center */
4096 channels[chn].bank = info->controllers[CTL_BANK_SELECT];
4097 channels[chn].sustained = info->controllers[CTL_SUSTAIN];
4098 if (info->controllers[CTL_EXT_EFF_DEPTH]) {
4099 FX_SET(&channels[chn].fx, AWE_FX_REVERB,
4100 info->controllers[CTL_EXT_EFF_DEPTH] * 2);
4101 }
4102 if (info->controllers[CTL_CHORUS_DEPTH]) {
4103 FX_SET(&channels[chn].fx, AWE_FX_CHORUS,
4104 info->controllers[CTL_CHORUS_DEPTH] * 2);
4105 }
4106 awe_set_instr(dev, chn, info->pgm_num);
4107}
4108
4109
4110#ifdef CONFIG_AWE32_MIXER
4111/*
4112 * AWE32 mixer device control
4113 */
4114
4115static int awe_mixer_ioctl(int dev, unsigned int cmd, void __user *arg);
4116
4117static int my_mixerdev = -1;
4118
4119static struct mixer_operations awe_mixer_operations = {
4120 .owner = THIS_MODULE,
4121 .id = "AWE",
4122 .name = "AWE32 Equalizer",
4123 .ioctl = awe_mixer_ioctl,
4124};
4125
4126static void __init attach_mixer(void)
4127{
4128 if ((my_mixerdev = sound_alloc_mixerdev()) >= 0) {
4129 mixer_devs[my_mixerdev] = &awe_mixer_operations;
4130 }
4131}
4132
4133static void unload_mixer(void)
4134{
4135 if (my_mixerdev >= 0)
4136 sound_unload_mixerdev(my_mixerdev);
4137}
4138
4139static int
4140awe_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
4141{
4142 int i, level, value;
4143
4144 if (((cmd >> 8) & 0xff) != 'M')
4145 return -EINVAL;
4146
4147 if (get_user(level, (int __user *)arg))
4148 return -EFAULT;
4149 level = ((level & 0xff) + (level >> 8)) / 2;
4150 DEBUG(0,printk("AWEMix: cmd=%x val=%d\n", cmd & 0xff, level));
4151
4152 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
4153 switch (cmd & 0xff) {
4154 case SOUND_MIXER_BASS:
4155 value = level * 12 / 100;
4156 if (value >= 12)
4157 value = 11;
4158 ctrls[AWE_MD_BASS_LEVEL] = value;
4159 awe_update_equalizer();
4160 break;
4161 case SOUND_MIXER_TREBLE:
4162 value = level * 12 / 100;
4163 if (value >= 12)
4164 value = 11;
4165 ctrls[AWE_MD_TREBLE_LEVEL] = value;
4166 awe_update_equalizer();
4167 break;
4168 case SOUND_MIXER_VOLUME:
4169 level = level * 127 / 100;
4170 if (level >= 128) level = 127;
4171 atten_relative = FALSE;
4172 atten_offset = vol_table[level];
4173 awe_update_volume();
4174 break;
4175 }
4176 }
4177 switch (cmd & 0xff) {
4178 case SOUND_MIXER_BASS:
4179 level = ctrls[AWE_MD_BASS_LEVEL] * 100 / 24;
4180 level = (level << 8) | level;
4181 break;
4182 case SOUND_MIXER_TREBLE:
4183 level = ctrls[AWE_MD_TREBLE_LEVEL] * 100 / 24;
4184 level = (level << 8) | level;
4185 break;
4186 case SOUND_MIXER_VOLUME:
4187 value = atten_offset;
4188 if (atten_relative)
4189 value += ctrls[AWE_MD_ZERO_ATTEN];
4190 for (i = 127; i > 0; i--) {
4191 if (value <= vol_table[i])
4192 break;
4193 }
4194 level = i * 100 / 127;
4195 level = (level << 8) | level;
4196 break;
4197 case SOUND_MIXER_DEVMASK:
4198 level = SOUND_MASK_BASS|SOUND_MASK_TREBLE|SOUND_MASK_VOLUME;
4199 break;
4200 default:
4201 level = 0;
4202 break;
4203 }
4204 if (put_user(level, (int __user *)arg))
4205 return -EFAULT;
4206 return level;
4207}
4208#endif /* CONFIG_AWE32_MIXER */
4209
4210
4211/*
4212 * initialization of Emu8000
4213 */
4214
4215/* intiailize audio channels */
4216static void
4217awe_init_audio(void)
4218{
4219 int ch;
4220
4221 /* turn off envelope engines */
4222 for (ch = 0; ch < AWE_MAX_VOICES; ch++) {
4223 awe_poke(AWE_DCYSUSV(ch), 0x80);
4224 }
4225
4226 /* reset all other parameters to zero */
4227 for (ch = 0; ch < AWE_MAX_VOICES; ch++) {
4228 awe_poke(AWE_ENVVOL(ch), 0);
4229 awe_poke(AWE_ENVVAL(ch), 0);
4230 awe_poke(AWE_DCYSUS(ch), 0);
4231 awe_poke(AWE_ATKHLDV(ch), 0);
4232 awe_poke(AWE_LFO1VAL(ch), 0);
4233 awe_poke(AWE_ATKHLD(ch), 0);
4234 awe_poke(AWE_LFO2VAL(ch), 0);
4235 awe_poke(AWE_IP(ch), 0);
4236 awe_poke(AWE_IFATN(ch), 0);
4237 awe_poke(AWE_PEFE(ch), 0);
4238 awe_poke(AWE_FMMOD(ch), 0);
4239 awe_poke(AWE_TREMFRQ(ch), 0);
4240 awe_poke(AWE_FM2FRQ2(ch), 0);
4241 awe_poke_dw(AWE_PTRX(ch), 0);
4242 awe_poke_dw(AWE_VTFT(ch), 0);
4243 awe_poke_dw(AWE_PSST(ch), 0);
4244 awe_poke_dw(AWE_CSL(ch), 0);
4245 awe_poke_dw(AWE_CCCA(ch), 0);
4246 }
4247
4248 for (ch = 0; ch < AWE_MAX_VOICES; ch++) {
4249 awe_poke_dw(AWE_CPF(ch), 0);
4250 awe_poke_dw(AWE_CVCF(ch), 0);
4251 }
4252}
4253
4254
4255/* initialize DMA address */
4256static void
4257awe_init_dma(void)
4258{
4259 awe_poke_dw(AWE_SMALR, 0);
4260 awe_poke_dw(AWE_SMARR, 0);
4261 awe_poke_dw(AWE_SMALW, 0);
4262 awe_poke_dw(AWE_SMARW, 0);
4263}
4264
4265
4266/* initialization arrays; from ADIP */
4267
4268static unsigned short init1[128] = {
4269 0x03ff, 0x0030, 0x07ff, 0x0130, 0x0bff, 0x0230, 0x0fff, 0x0330,
4270 0x13ff, 0x0430, 0x17ff, 0x0530, 0x1bff, 0x0630, 0x1fff, 0x0730,
4271 0x23ff, 0x0830, 0x27ff, 0x0930, 0x2bff, 0x0a30, 0x2fff, 0x0b30,
4272 0x33ff, 0x0c30, 0x37ff, 0x0d30, 0x3bff, 0x0e30, 0x3fff, 0x0f30,
4273
4274 0x43ff, 0x0030, 0x47ff, 0x0130, 0x4bff, 0x0230, 0x4fff, 0x0330,
4275 0x53ff, 0x0430, 0x57ff, 0x0530, 0x5bff, 0x0630, 0x5fff, 0x0730,
4276 0x63ff, 0x0830, 0x67ff, 0x0930, 0x6bff, 0x0a30, 0x6fff, 0x0b30,
4277 0x73ff, 0x0c30, 0x77ff, 0x0d30, 0x7bff, 0x0e30, 0x7fff, 0x0f30,
4278
4279 0x83ff, 0x0030, 0x87ff, 0x0130, 0x8bff, 0x0230, 0x8fff, 0x0330,
4280 0x93ff, 0x0430, 0x97ff, 0x0530, 0x9bff, 0x0630, 0x9fff, 0x0730,
4281 0xa3ff, 0x0830, 0xa7ff, 0x0930, 0xabff, 0x0a30, 0xafff, 0x0b30,
4282 0xb3ff, 0x0c30, 0xb7ff, 0x0d30, 0xbbff, 0x0e30, 0xbfff, 0x0f30,
4283
4284 0xc3ff, 0x0030, 0xc7ff, 0x0130, 0xcbff, 0x0230, 0xcfff, 0x0330,
4285 0xd3ff, 0x0430, 0xd7ff, 0x0530, 0xdbff, 0x0630, 0xdfff, 0x0730,
4286 0xe3ff, 0x0830, 0xe7ff, 0x0930, 0xebff, 0x0a30, 0xefff, 0x0b30,
4287 0xf3ff, 0x0c30, 0xf7ff, 0x0d30, 0xfbff, 0x0e30, 0xffff, 0x0f30,
4288};
4289
4290static unsigned short init2[128] = {
4291 0x03ff, 0x8030, 0x07ff, 0x8130, 0x0bff, 0x8230, 0x0fff, 0x8330,
4292 0x13ff, 0x8430, 0x17ff, 0x8530, 0x1bff, 0x8630, 0x1fff, 0x8730,
4293 0x23ff, 0x8830, 0x27ff, 0x8930, 0x2bff, 0x8a30, 0x2fff, 0x8b30,
4294 0x33ff, 0x8c30, 0x37ff, 0x8d30, 0x3bff, 0x8e30, 0x3fff, 0x8f30,
4295
4296 0x43ff, 0x8030, 0x47ff, 0x8130, 0x4bff, 0x8230, 0x4fff, 0x8330,
4297 0x53ff, 0x8430, 0x57ff, 0x8530, 0x5bff, 0x8630, 0x5fff, 0x8730,
4298 0x63ff, 0x8830, 0x67ff, 0x8930, 0x6bff, 0x8a30, 0x6fff, 0x8b30,
4299 0x73ff, 0x8c30, 0x77ff, 0x8d30, 0x7bff, 0x8e30, 0x7fff, 0x8f30,
4300
4301 0x83ff, 0x8030, 0x87ff, 0x8130, 0x8bff, 0x8230, 0x8fff, 0x8330,
4302 0x93ff, 0x8430, 0x97ff, 0x8530, 0x9bff, 0x8630, 0x9fff, 0x8730,
4303 0xa3ff, 0x8830, 0xa7ff, 0x8930, 0xabff, 0x8a30, 0xafff, 0x8b30,
4304 0xb3ff, 0x8c30, 0xb7ff, 0x8d30, 0xbbff, 0x8e30, 0xbfff, 0x8f30,
4305
4306 0xc3ff, 0x8030, 0xc7ff, 0x8130, 0xcbff, 0x8230, 0xcfff, 0x8330,
4307 0xd3ff, 0x8430, 0xd7ff, 0x8530, 0xdbff, 0x8630, 0xdfff, 0x8730,
4308 0xe3ff, 0x8830, 0xe7ff, 0x8930, 0xebff, 0x8a30, 0xefff, 0x8b30,
4309 0xf3ff, 0x8c30, 0xf7ff, 0x8d30, 0xfbff, 0x8e30, 0xffff, 0x8f30,
4310};
4311
4312static unsigned short init3[128] = {
4313 0x0C10, 0x8470, 0x14FE, 0xB488, 0x167F, 0xA470, 0x18E7, 0x84B5,
4314 0x1B6E, 0x842A, 0x1F1D, 0x852A, 0x0DA3, 0x8F7C, 0x167E, 0xF254,
4315 0x0000, 0x842A, 0x0001, 0x852A, 0x18E6, 0x8BAA, 0x1B6D, 0xF234,
4316 0x229F, 0x8429, 0x2746, 0x8529, 0x1F1C, 0x86E7, 0x229E, 0xF224,
4317
4318 0x0DA4, 0x8429, 0x2C29, 0x8529, 0x2745, 0x87F6, 0x2C28, 0xF254,
4319 0x383B, 0x8428, 0x320F, 0x8528, 0x320E, 0x8F02, 0x1341, 0xF264,
4320 0x3EB6, 0x8428, 0x3EB9, 0x8528, 0x383A, 0x8FA9, 0x3EB5, 0xF294,
4321 0x3EB7, 0x8474, 0x3EBA, 0x8575, 0x3EB8, 0xC4C3, 0x3EBB, 0xC5C3,
4322
4323 0x0000, 0xA404, 0x0001, 0xA504, 0x141F, 0x8671, 0x14FD, 0x8287,
4324 0x3EBC, 0xE610, 0x3EC8, 0x8C7B, 0x031A, 0x87E6, 0x3EC8, 0x86F7,
4325 0x3EC0, 0x821E, 0x3EBE, 0xD208, 0x3EBD, 0x821F, 0x3ECA, 0x8386,
4326 0x3EC1, 0x8C03, 0x3EC9, 0x831E, 0x3ECA, 0x8C4C, 0x3EBF, 0x8C55,
4327
4328 0x3EC9, 0xC208, 0x3EC4, 0xBC84, 0x3EC8, 0x8EAD, 0x3EC8, 0xD308,
4329 0x3EC2, 0x8F7E, 0x3ECB, 0x8219, 0x3ECB, 0xD26E, 0x3EC5, 0x831F,
4330 0x3EC6, 0xC308, 0x3EC3, 0xB2FF, 0x3EC9, 0x8265, 0x3EC9, 0x8319,
4331 0x1342, 0xD36E, 0x3EC7, 0xB3FF, 0x0000, 0x8365, 0x1420, 0x9570,
4332};
4333
4334static unsigned short init4[128] = {
4335 0x0C10, 0x8470, 0x14FE, 0xB488, 0x167F, 0xA470, 0x18E7, 0x84B5,
4336 0x1B6E, 0x842A, 0x1F1D, 0x852A, 0x0DA3, 0x0F7C, 0x167E, 0x7254,
4337 0x0000, 0x842A, 0x0001, 0x852A, 0x18E6, 0x0BAA, 0x1B6D, 0x7234,
4338 0x229F, 0x8429, 0x2746, 0x8529, 0x1F1C, 0x06E7, 0x229E, 0x7224,
4339
4340 0x0DA4, 0x8429, 0x2C29, 0x8529, 0x2745, 0x07F6, 0x2C28, 0x7254,
4341 0x383B, 0x8428, 0x320F, 0x8528, 0x320E, 0x0F02, 0x1341, 0x7264,
4342 0x3EB6, 0x8428, 0x3EB9, 0x8528, 0x383A, 0x0FA9, 0x3EB5, 0x7294,
4343 0x3EB7, 0x8474, 0x3EBA, 0x8575, 0x3EB8, 0x44C3, 0x3EBB, 0x45C3,
4344
4345 0x0000, 0xA404, 0x0001, 0xA504, 0x141F, 0x0671, 0x14FD, 0x0287,
4346 0x3EBC, 0xE610, 0x3EC8, 0x0C7B, 0x031A, 0x07E6, 0x3EC8, 0x86F7,
4347 0x3EC0, 0x821E, 0x3EBE, 0xD208, 0x3EBD, 0x021F, 0x3ECA, 0x0386,
4348 0x3EC1, 0x0C03, 0x3EC9, 0x031E, 0x3ECA, 0x8C4C, 0x3EBF, 0x0C55,
4349
4350 0x3EC9, 0xC208, 0x3EC4, 0xBC84, 0x3EC8, 0x0EAD, 0x3EC8, 0xD308,
4351 0x3EC2, 0x8F7E, 0x3ECB, 0x0219, 0x3ECB, 0xD26E, 0x3EC5, 0x031F,
4352 0x3EC6, 0xC308, 0x3EC3, 0x32FF, 0x3EC9, 0x0265, 0x3EC9, 0x8319,
4353 0x1342, 0xD36E, 0x3EC7, 0x33FF, 0x0000, 0x8365, 0x1420, 0x9570,
4354};
4355
4356
4357/* send initialization arrays to start up */
4358static void
4359awe_init_array(void)
4360{
4361 awe_send_array(init1);
4362 awe_wait(1024);
4363 awe_send_array(init2);
4364 awe_send_array(init3);
4365 awe_poke_dw(AWE_HWCF4, 0);
4366 awe_poke_dw(AWE_HWCF5, 0x83);
4367 awe_poke_dw(AWE_HWCF6, 0x8000);
4368 awe_send_array(init4);
4369}
4370
4371/* send an initialization array */
4372static void
4373awe_send_array(unsigned short *data)
4374{
4375 int i;
4376 unsigned short *p;
4377
4378 p = data;
4379 for (i = 0; i < AWE_MAX_VOICES; i++, p++)
4380 awe_poke(AWE_INIT1(i), *p);
4381 for (i = 0; i < AWE_MAX_VOICES; i++, p++)
4382 awe_poke(AWE_INIT2(i), *p);
4383 for (i = 0; i < AWE_MAX_VOICES; i++, p++)
4384 awe_poke(AWE_INIT3(i), *p);
4385 for (i = 0; i < AWE_MAX_VOICES; i++, p++)
4386 awe_poke(AWE_INIT4(i), *p);
4387}
4388
4389
4390/*
4391 * set up awe32 channels to some known state.
4392 */
4393
4394/* set the envelope & LFO parameters to the default values; see ADIP */
4395static void
4396awe_tweak_voice(int i)
4397{
4398 /* set all mod/vol envelope shape to minimum */
4399 awe_poke(AWE_ENVVOL(i), 0x8000);
4400 awe_poke(AWE_ENVVAL(i), 0x8000);
4401 awe_poke(AWE_DCYSUS(i), 0x7F7F);
4402 awe_poke(AWE_ATKHLDV(i), 0x7F7F);
4403 awe_poke(AWE_ATKHLD(i), 0x7F7F);
4404 awe_poke(AWE_PEFE(i), 0); /* mod envelope height to zero */
4405 awe_poke(AWE_LFO1VAL(i), 0x8000); /* no delay for LFO1 */
4406 awe_poke(AWE_LFO2VAL(i), 0x8000);
4407 awe_poke(AWE_IP(i), 0xE000); /* no pitch shift */
4408 awe_poke(AWE_IFATN(i), 0xFF00); /* volume to minimum */
4409 awe_poke(AWE_FMMOD(i), 0);
4410 awe_poke(AWE_TREMFRQ(i), 0);
4411 awe_poke(AWE_FM2FRQ2(i), 0);
4412}
4413
4414static void
4415awe_tweak(void)
4416{
4417 int i;
4418 /* reset all channels */
4419 for (i = 0; i < awe_max_voices; i++)
4420 awe_tweak_voice(i);
4421}
4422
4423
4424/*
4425 * initializes the FM section of AWE32;
4426 * see Vince Vu's unofficial AWE32 programming guide
4427 */
4428
4429static void
4430awe_init_fm(void)
4431{
4432#ifndef AWE_ALWAYS_INIT_FM
4433 /* if no extended memory is on board.. */
4434 if (memsize <= 0)
4435 return;
4436#endif
4437 DEBUG(3,printk("AWE32: initializing FM\n"));
4438
4439 /* Initialize the last two channels for DRAM refresh and producing
4440 the reverb and chorus effects for Yamaha OPL-3 synthesizer */
4441
4442 /* 31: FM left channel, 0xffffe0-0xffffe8 */
4443 awe_poke(AWE_DCYSUSV(30), 0x80);
4444 awe_poke_dw(AWE_PSST(30), 0xFFFFFFE0); /* full left */
4445 awe_poke_dw(AWE_CSL(30), 0x00FFFFE8 |
4446 (DEF_FM_CHORUS_DEPTH << 24));
4447 awe_poke_dw(AWE_PTRX(30), (DEF_FM_REVERB_DEPTH << 8));
4448 awe_poke_dw(AWE_CPF(30), 0);
4449 awe_poke_dw(AWE_CCCA(30), 0x00FFFFE3);
4450
4451 /* 32: FM right channel, 0xfffff0-0xfffff8 */
4452 awe_poke(AWE_DCYSUSV(31), 0x80);
4453 awe_poke_dw(AWE_PSST(31), 0x00FFFFF0); /* full right */
4454 awe_poke_dw(AWE_CSL(31), 0x00FFFFF8 |
4455 (DEF_FM_CHORUS_DEPTH << 24));
4456 awe_poke_dw(AWE_PTRX(31), (DEF_FM_REVERB_DEPTH << 8));
4457 awe_poke_dw(AWE_CPF(31), 0x8000);
4458 awe_poke_dw(AWE_CCCA(31), 0x00FFFFF3);
4459
4460 /* skew volume & cutoff */
4461 awe_poke_dw(AWE_VTFT(30), 0x8000FFFF);
4462 awe_poke_dw(AWE_VTFT(31), 0x8000FFFF);
4463
4464 voices[30].state = AWE_ST_FM;
4465 voices[31].state = AWE_ST_FM;
4466
4467 /* change maximum channels to 30 */
4468 awe_max_voices = AWE_NORMAL_VOICES;
4469 if (playing_mode == AWE_PLAY_DIRECT)
4470 awe_info.nr_voices = awe_max_voices;
4471 else
4472 awe_info.nr_voices = AWE_MAX_CHANNELS;
4473 voice_alloc->max_voice = awe_max_voices;
4474}
4475
4476/*
4477 * AWE32 DRAM access routines
4478 */
4479
4480/* open DRAM write accessing mode */
4481static int
4482awe_open_dram_for_write(int offset, int channels)
4483{
4484 int vidx[AWE_NORMAL_VOICES];
4485 int i;
4486
4487 if (channels < 0 || channels >= AWE_NORMAL_VOICES) {
4488 channels = AWE_NORMAL_VOICES;
4489 for (i = 0; i < AWE_NORMAL_VOICES; i++)
4490 vidx[i] = i;
4491 } else {
4492 for (i = 0; i < channels; i++) {
4493 vidx[i] = awe_clear_voice();
4494 voices[vidx[i]].state = AWE_ST_MARK;
4495 }
4496 }
4497
4498 /* use all channels for DMA transfer */
4499 for (i = 0; i < channels; i++) {
4500 if (vidx[i] < 0) continue;
4501 awe_poke(AWE_DCYSUSV(vidx[i]), 0x80);
4502 awe_poke_dw(AWE_VTFT(vidx[i]), 0);
4503 awe_poke_dw(AWE_CVCF(vidx[i]), 0);
4504 awe_poke_dw(AWE_PTRX(vidx[i]), 0x40000000);
4505 awe_poke_dw(AWE_CPF(vidx[i]), 0x40000000);
4506 awe_poke_dw(AWE_PSST(vidx[i]), 0);
4507 awe_poke_dw(AWE_CSL(vidx[i]), 0);
4508 awe_poke_dw(AWE_CCCA(vidx[i]), 0x06000000);
4509 voices[vidx[i]].state = AWE_ST_DRAM;
4510 }
4511 /* point channels 31 & 32 to ROM samples for DRAM refresh */
4512 awe_poke_dw(AWE_VTFT(30), 0);
4513 awe_poke_dw(AWE_PSST(30), 0x1d8);
4514 awe_poke_dw(AWE_CSL(30), 0x1e0);
4515 awe_poke_dw(AWE_CCCA(30), 0x1d8);
4516 awe_poke_dw(AWE_VTFT(31), 0);
4517 awe_poke_dw(AWE_PSST(31), 0x1d8);
4518 awe_poke_dw(AWE_CSL(31), 0x1e0);
4519 awe_poke_dw(AWE_CCCA(31), 0x1d8);
4520 voices[30].state = AWE_ST_FM;
4521 voices[31].state = AWE_ST_FM;
4522
4523 /* if full bit is on, not ready to write on */
4524 if (awe_peek_dw(AWE_SMALW) & 0x80000000) {
4525 for (i = 0; i < channels; i++) {
4526 awe_poke_dw(AWE_CCCA(vidx[i]), 0);
4527 voices[vidx[i]].state = AWE_ST_OFF;
4528 }
4529 printk("awe: not ready to write..\n");
4530 return -EPERM;
4531 }
4532
4533 /* set address to write */
4534 awe_poke_dw(AWE_SMALW, offset);
4535
4536 return 0;
4537}
4538
4539/* open DRAM for RAM size detection */
4540static void
4541awe_open_dram_for_check(void)
4542{
4543 int i;
4544 for (i = 0; i < AWE_NORMAL_VOICES; i++) {
4545 awe_poke(AWE_DCYSUSV(i), 0x80);
4546 awe_poke_dw(AWE_VTFT(i), 0);
4547 awe_poke_dw(AWE_CVCF(i), 0);
4548 awe_poke_dw(AWE_PTRX(i), 0x40000000);
4549 awe_poke_dw(AWE_CPF(i), 0x40000000);
4550 awe_poke_dw(AWE_PSST(i), 0);
4551 awe_poke_dw(AWE_CSL(i), 0);
4552 if (i & 1) /* DMA write */
4553 awe_poke_dw(AWE_CCCA(i), 0x06000000);
4554 else /* DMA read */
4555 awe_poke_dw(AWE_CCCA(i), 0x04000000);
4556 voices[i].state = AWE_ST_DRAM;
4557 }
4558}
4559
4560
4561/* close dram access */
4562static void
4563awe_close_dram(void)
4564{
4565 int i;
4566 /* wait until FULL bit in SMAxW register be false */
4567 for (i = 0; i < 10000; i++) {
4568 if (!(awe_peek_dw(AWE_SMALW) & 0x80000000))
4569 break;
4570 awe_wait(10);
4571 }
4572
4573 for (i = 0; i < AWE_NORMAL_VOICES; i++) {
4574 if (voices[i].state == AWE_ST_DRAM) {
4575 awe_poke_dw(AWE_CCCA(i), 0);
4576 awe_poke(AWE_DCYSUSV(i), 0x807F);
4577 voices[i].state = AWE_ST_OFF;
4578 }
4579 }
4580}
4581
4582
4583/*
4584 * check dram size on AWE board
4585 */
4586
4587/* any three numbers you like */
4588#define UNIQUE_ID1 0x1234
4589#define UNIQUE_ID2 0x4321
4590#define UNIQUE_ID3 0xABCD
4591
4592static void __init
4593awe_check_dram(void)
4594{
4595 if (awe_present) /* already initialized */
4596 return;
4597
4598 if (memsize >= 0) { /* given by config file or module option */
4599 memsize *= 1024; /* convert to Kbytes */
4600 return;
4601 }
4602
4603 awe_open_dram_for_check();
4604
4605 memsize = 0;
4606
4607 /* set up unique two id numbers */
4608 awe_poke_dw(AWE_SMALW, AWE_DRAM_OFFSET);
4609 awe_poke(AWE_SMLD, UNIQUE_ID1);
4610 awe_poke(AWE_SMLD, UNIQUE_ID2);
4611
4612 while (memsize < AWE_MAX_DRAM_SIZE) {
4613 awe_wait(5);
4614 /* read a data on the DRAM start address */
4615 awe_poke_dw(AWE_SMALR, AWE_DRAM_OFFSET);
4616 awe_peek(AWE_SMLD); /* discard stale data */
4617 if (awe_peek(AWE_SMLD) != UNIQUE_ID1)
4618 break;
4619 if (awe_peek(AWE_SMLD) != UNIQUE_ID2)
4620 break;
4621 memsize += 512; /* increment 512kbytes */
4622 /* Write a unique data on the test address;
4623 * if the address is out of range, the data is written on
4624 * 0x200000(=AWE_DRAM_OFFSET). Then the two id words are
4625 * broken by this data.
4626 */
4627 awe_poke_dw(AWE_SMALW, AWE_DRAM_OFFSET + memsize*512L);
4628 awe_poke(AWE_SMLD, UNIQUE_ID3);
4629 awe_wait(5);
4630 /* read a data on the just written DRAM address */
4631 awe_poke_dw(AWE_SMALR, AWE_DRAM_OFFSET + memsize*512L);
4632 awe_peek(AWE_SMLD); /* discard stale data */
4633 if (awe_peek(AWE_SMLD) != UNIQUE_ID3)
4634 break;
4635 }
4636 awe_close_dram();
4637
4638 DEBUG(0,printk("AWE32: %d Kbytes memory detected\n", memsize));
4639
4640 /* convert to Kbytes */
4641 memsize *= 1024;
4642}
4643
4644
4645/*----------------------------------------------------------------*/
4646
4647/*
4648 * chorus and reverb controls; from VV's guide
4649 */
4650
4651/* 5 parameters for each chorus mode; 3 x 16bit, 2 x 32bit */
4652static char chorus_defined[AWE_CHORUS_NUMBERS];
4653static awe_chorus_fx_rec chorus_parm[AWE_CHORUS_NUMBERS] = {
4654 {0xE600, 0x03F6, 0xBC2C ,0x00000000, 0x0000006D}, /* chorus 1 */
4655 {0xE608, 0x031A, 0xBC6E, 0x00000000, 0x0000017C}, /* chorus 2 */
4656 {0xE610, 0x031A, 0xBC84, 0x00000000, 0x00000083}, /* chorus 3 */
4657 {0xE620, 0x0269, 0xBC6E, 0x00000000, 0x0000017C}, /* chorus 4 */
4658 {0xE680, 0x04D3, 0xBCA6, 0x00000000, 0x0000005B}, /* feedback */
4659 {0xE6E0, 0x044E, 0xBC37, 0x00000000, 0x00000026}, /* flanger */
4660 {0xE600, 0x0B06, 0xBC00, 0x0000E000, 0x00000083}, /* short delay */
4661 {0xE6C0, 0x0B06, 0xBC00, 0x0000E000, 0x00000083}, /* short delay + feedback */
4662};
4663
4664static int
4665awe_load_chorus_fx(awe_patch_info *patch, const char __user *addr, int count)
4666{
4667 if (patch->optarg < AWE_CHORUS_PREDEFINED || patch->optarg >= AWE_CHORUS_NUMBERS) {
4668 printk(KERN_WARNING "AWE32 Error: invalid chorus mode %d for uploading\n", patch->optarg);
4669 return -EINVAL;
4670 }
4671 if (count < sizeof(awe_chorus_fx_rec)) {
4672 printk(KERN_WARNING "AWE32 Error: too short chorus fx parameters\n");
4673 return -EINVAL;
4674 }
4675 if (copy_from_user(&chorus_parm[patch->optarg], addr + AWE_PATCH_INFO_SIZE,
4676 sizeof(awe_chorus_fx_rec)))
4677 return -EFAULT;
4678 chorus_defined[patch->optarg] = TRUE;
4679 return 0;
4680}
4681
4682static void
4683awe_set_chorus_mode(int effect)
4684{
4685 if (effect < 0 || effect >= AWE_CHORUS_NUMBERS ||
4686 (effect >= AWE_CHORUS_PREDEFINED && !chorus_defined[effect]))
4687 return;
4688 awe_poke(AWE_INIT3(9), chorus_parm[effect].feedback);
4689 awe_poke(AWE_INIT3(12), chorus_parm[effect].delay_offset);
4690 awe_poke(AWE_INIT4(3), chorus_parm[effect].lfo_depth);
4691 awe_poke_dw(AWE_HWCF4, chorus_parm[effect].delay);
4692 awe_poke_dw(AWE_HWCF5, chorus_parm[effect].lfo_freq);
4693 awe_poke_dw(AWE_HWCF6, 0x8000);
4694 awe_poke_dw(AWE_HWCF7, 0x0000);
4695}
4696
4697static void
4698awe_update_chorus_mode(void)
4699{
4700 awe_set_chorus_mode(ctrls[AWE_MD_CHORUS_MODE]);
4701}
4702
4703/*----------------------------------------------------------------*/
4704
4705/* reverb mode settings; write the following 28 data of 16 bit length
4706 * on the corresponding ports in the reverb_cmds array
4707 */
4708static char reverb_defined[AWE_CHORUS_NUMBERS];
4709static awe_reverb_fx_rec reverb_parm[AWE_REVERB_NUMBERS] = {
4710{{ /* room 1 */
4711 0xB488, 0xA450, 0x9550, 0x84B5, 0x383A, 0x3EB5, 0x72F4,
4712 0x72A4, 0x7254, 0x7204, 0x7204, 0x7204, 0x4416, 0x4516,
4713 0xA490, 0xA590, 0x842A, 0x852A, 0x842A, 0x852A, 0x8429,
4714 0x8529, 0x8429, 0x8529, 0x8428, 0x8528, 0x8428, 0x8528,
4715}},
4716{{ /* room 2 */
4717 0xB488, 0xA458, 0x9558, 0x84B5, 0x383A, 0x3EB5, 0x7284,
4718 0x7254, 0x7224, 0x7224, 0x7254, 0x7284, 0x4448, 0x4548,
4719 0xA440, 0xA540, 0x842A, 0x852A, 0x842A, 0x852A, 0x8429,
4720 0x8529, 0x8429, 0x8529, 0x8428, 0x8528, 0x8428, 0x8528,
4721}},
4722{{ /* room 3 */
4723 0xB488, 0xA460, 0x9560, 0x84B5, 0x383A, 0x3EB5, 0x7284,
4724 0x7254, 0x7224, 0x7224, 0x7254, 0x7284, 0x4416, 0x4516,
4725 0xA490, 0xA590, 0x842C, 0x852C, 0x842C, 0x852C, 0x842B,
4726 0x852B, 0x842B, 0x852B, 0x842A, 0x852A, 0x842A, 0x852A,
4727}},
4728{{ /* hall 1 */
4729 0xB488, 0xA470, 0x9570, 0x84B5, 0x383A, 0x3EB5, 0x7284,
4730 0x7254, 0x7224, 0x7224, 0x7254, 0x7284, 0x4448, 0x4548,
4731 0xA440, 0xA540, 0x842B, 0x852B, 0x842B, 0x852B, 0x842A,
4732 0x852A, 0x842A, 0x852A, 0x8429, 0x8529, 0x8429, 0x8529,
4733}},
4734{{ /* hall 2 */
4735 0xB488, 0xA470, 0x9570, 0x84B5, 0x383A, 0x3EB5, 0x7254,
4736 0x7234, 0x7224, 0x7254, 0x7264, 0x7294, 0x44C3, 0x45C3,
4737 0xA404, 0xA504, 0x842A, 0x852A, 0x842A, 0x852A, 0x8429,
4738 0x8529, 0x8429, 0x8529, 0x8428, 0x8528, 0x8428, 0x8528,
4739}},
4740{{ /* plate */
4741 0xB4FF, 0xA470, 0x9570, 0x84B5, 0x383A, 0x3EB5, 0x7234,
4742 0x7234, 0x7234, 0x7234, 0x7234, 0x7234, 0x4448, 0x4548,
4743 0xA440, 0xA540, 0x842A, 0x852A, 0x842A, 0x852A, 0x8429,
4744 0x8529, 0x8429, 0x8529, 0x8428, 0x8528, 0x8428, 0x8528,
4745}},
4746{{ /* delay */
4747 0xB4FF, 0xA470, 0x9500, 0x84B5, 0x333A, 0x39B5, 0x7204,
4748 0x7204, 0x7204, 0x7204, 0x7204, 0x72F4, 0x4400, 0x4500,
4749 0xA4FF, 0xA5FF, 0x8420, 0x8520, 0x8420, 0x8520, 0x8420,
4750 0x8520, 0x8420, 0x8520, 0x8420, 0x8520, 0x8420, 0x8520,
4751}},
4752{{ /* panning delay */
4753 0xB4FF, 0xA490, 0x9590, 0x8474, 0x333A, 0x39B5, 0x7204,
4754 0x7204, 0x7204, 0x7204, 0x7204, 0x72F4, 0x4400, 0x4500,
4755 0xA4FF, 0xA5FF, 0x8420, 0x8520, 0x8420, 0x8520, 0x8420,
4756 0x8520, 0x8420, 0x8520, 0x8420, 0x8520, 0x8420, 0x8520,
4757}},
4758};
4759
4760static struct ReverbCmdPair {
4761 unsigned short cmd, port;
4762} reverb_cmds[28] = {
4763 {AWE_INIT1(0x03)}, {AWE_INIT1(0x05)}, {AWE_INIT4(0x1F)}, {AWE_INIT1(0x07)},
4764 {AWE_INIT2(0x14)}, {AWE_INIT2(0x16)}, {AWE_INIT1(0x0F)}, {AWE_INIT1(0x17)},
4765 {AWE_INIT1(0x1F)}, {AWE_INIT2(0x07)}, {AWE_INIT2(0x0F)}, {AWE_INIT2(0x17)},
4766 {AWE_INIT2(0x1D)}, {AWE_INIT2(0x1F)}, {AWE_INIT3(0x01)}, {AWE_INIT3(0x03)},
4767 {AWE_INIT1(0x09)}, {AWE_INIT1(0x0B)}, {AWE_INIT1(0x11)}, {AWE_INIT1(0x13)},
4768 {AWE_INIT1(0x19)}, {AWE_INIT1(0x1B)}, {AWE_INIT2(0x01)}, {AWE_INIT2(0x03)},
4769 {AWE_INIT2(0x09)}, {AWE_INIT2(0x0B)}, {AWE_INIT2(0x11)}, {AWE_INIT2(0x13)},
4770};
4771
4772static int
4773awe_load_reverb_fx(awe_patch_info *patch, const char __user *addr, int count)
4774{
4775 if (patch->optarg < AWE_REVERB_PREDEFINED || patch->optarg >= AWE_REVERB_NUMBERS) {
4776 printk(KERN_WARNING "AWE32 Error: invalid reverb mode %d for uploading\n", patch->optarg);
4777 return -EINVAL;
4778 }
4779 if (count < sizeof(awe_reverb_fx_rec)) {
4780 printk(KERN_WARNING "AWE32 Error: too short reverb fx parameters\n");
4781 return -EINVAL;
4782 }
4783 if (copy_from_user(&reverb_parm[patch->optarg], addr + AWE_PATCH_INFO_SIZE,
4784 sizeof(awe_reverb_fx_rec)))
4785 return -EFAULT;
4786 reverb_defined[patch->optarg] = TRUE;
4787 return 0;
4788}
4789
4790static void
4791awe_set_reverb_mode(int effect)
4792{
4793 int i;
4794 if (effect < 0 || effect >= AWE_REVERB_NUMBERS ||
4795 (effect >= AWE_REVERB_PREDEFINED && !reverb_defined[effect]))
4796 return;
4797 for (i = 0; i < 28; i++)
4798 awe_poke(reverb_cmds[i].cmd, reverb_cmds[i].port,
4799 reverb_parm[effect].parms[i]);
4800}
4801
4802static void
4803awe_update_reverb_mode(void)
4804{
4805 awe_set_reverb_mode(ctrls[AWE_MD_REVERB_MODE]);
4806}
4807
4808/*
4809 * treble/bass equalizer control
4810 */
4811
4812static unsigned short bass_parm[12][3] = {
4813 {0xD26A, 0xD36A, 0x0000}, /* -12 dB */
4814 {0xD25B, 0xD35B, 0x0000}, /* -8 */
4815 {0xD24C, 0xD34C, 0x0000}, /* -6 */
4816 {0xD23D, 0xD33D, 0x0000}, /* -4 */
4817 {0xD21F, 0xD31F, 0x0000}, /* -2 */
4818 {0xC208, 0xC308, 0x0001}, /* 0 (HW default) */
4819 {0xC219, 0xC319, 0x0001}, /* +2 */
4820 {0xC22A, 0xC32A, 0x0001}, /* +4 */
4821 {0xC24C, 0xC34C, 0x0001}, /* +6 */
4822 {0xC26E, 0xC36E, 0x0001}, /* +8 */
4823 {0xC248, 0xC348, 0x0002}, /* +10 */
4824 {0xC26A, 0xC36A, 0x0002}, /* +12 dB */
4825};
4826
4827static unsigned short treble_parm[12][9] = {
4828 {0x821E, 0xC26A, 0x031E, 0xC36A, 0x021E, 0xD208, 0x831E, 0xD308, 0x0001}, /* -12 dB */
4829 {0x821E, 0xC25B, 0x031E, 0xC35B, 0x021E, 0xD208, 0x831E, 0xD308, 0x0001},
4830 {0x821E, 0xC24C, 0x031E, 0xC34C, 0x021E, 0xD208, 0x831E, 0xD308, 0x0001},
4831 {0x821E, 0xC23D, 0x031E, 0xC33D, 0x021E, 0xD208, 0x831E, 0xD308, 0x0001},
4832 {0x821E, 0xC21F, 0x031E, 0xC31F, 0x021E, 0xD208, 0x831E, 0xD308, 0x0001},
4833 {0x821E, 0xD208, 0x031E, 0xD308, 0x021E, 0xD208, 0x831E, 0xD308, 0x0002},
4834 {0x821E, 0xD208, 0x031E, 0xD308, 0x021D, 0xD219, 0x831D, 0xD319, 0x0002},
4835 {0x821E, 0xD208, 0x031E, 0xD308, 0x021C, 0xD22A, 0x831C, 0xD32A, 0x0002},
4836 {0x821E, 0xD208, 0x031E, 0xD308, 0x021A, 0xD24C, 0x831A, 0xD34C, 0x0002},
4837 {0x821E, 0xD208, 0x031E, 0xD308, 0x0219, 0xD26E, 0x8319, 0xD36E, 0x0002}, /* +8 (HW default) */
4838 {0x821D, 0xD219, 0x031D, 0xD319, 0x0219, 0xD26E, 0x8319, 0xD36E, 0x0002},
4839 {0x821C, 0xD22A, 0x031C, 0xD32A, 0x0219, 0xD26E, 0x8319, 0xD36E, 0x0002}, /* +12 dB */
4840};
4841
4842
4843/*
4844 * set Emu8000 digital equalizer; from 0 to 11 [-12dB - 12dB]
4845 */
4846static void
4847awe_equalizer(int bass, int treble)
4848{
4849 unsigned short w;
4850
4851 if (bass < 0 || bass > 11 || treble < 0 || treble > 11)
4852 return;
4853 awe_poke(AWE_INIT4(0x01), bass_parm[bass][0]);
4854 awe_poke(AWE_INIT4(0x11), bass_parm[bass][1]);
4855 awe_poke(AWE_INIT3(0x11), treble_parm[treble][0]);
4856 awe_poke(AWE_INIT3(0x13), treble_parm[treble][1]);
4857 awe_poke(AWE_INIT3(0x1B), treble_parm[treble][2]);
4858 awe_poke(AWE_INIT4(0x07), treble_parm[treble][3]);
4859 awe_poke(AWE_INIT4(0x0B), treble_parm[treble][4]);
4860 awe_poke(AWE_INIT4(0x0D), treble_parm[treble][5]);
4861 awe_poke(AWE_INIT4(0x17), treble_parm[treble][6]);
4862 awe_poke(AWE_INIT4(0x19), treble_parm[treble][7]);
4863 w = bass_parm[bass][2] + treble_parm[treble][8];
4864 awe_poke(AWE_INIT4(0x15), (unsigned short)(w + 0x0262));
4865 awe_poke(AWE_INIT4(0x1D), (unsigned short)(w + 0x8362));
4866}
4867
4868static void awe_update_equalizer(void)
4869{
4870 awe_equalizer(ctrls[AWE_MD_BASS_LEVEL], ctrls[AWE_MD_TREBLE_LEVEL]);
4871}
4872
4873
4874/*----------------------------------------------------------------*/
4875
4876#ifdef CONFIG_AWE32_MIDIEMU
4877
4878/*
4879 * Emu8000 MIDI Emulation
4880 */
4881
4882/*
4883 * midi queue record
4884 */
4885
4886/* queue type */
4887enum { Q_NONE, Q_VARLEN, Q_READ, Q_SYSEX, };
4888
4889#define MAX_MIDIBUF 64
4890
4891/* midi status */
4892typedef struct MidiStatus {
4893 int queue; /* queue type */
4894 int qlen; /* queue length */
4895 int read; /* chars read */
4896 int status; /* current status */
4897 int chan; /* current channel */
4898 unsigned char buf[MAX_MIDIBUF];
4899} MidiStatus;
4900
4901/* MIDI mode type */
4902enum { MODE_GM, MODE_GS, MODE_XG, };
4903
4904/* NRPN / CC -> Emu8000 parameter converter */
4905typedef struct {
4906 int control;
4907 int awe_effect;
4908 unsigned short (*convert)(int val);
4909} ConvTable;
4910
4911
4912/*
4913 * prototypes
4914 */
4915
4916static int awe_midi_open(int dev, int mode, void (*input)(int,unsigned char), void (*output)(int));
4917static void awe_midi_close(int dev);
4918static int awe_midi_ioctl(int dev, unsigned cmd, void __user * arg);
4919static int awe_midi_outputc(int dev, unsigned char midi_byte);
4920
4921static void init_midi_status(MidiStatus *st);
4922static void clear_rpn(void);
4923static void get_midi_char(MidiStatus *st, int c);
4924/*static void queue_varlen(MidiStatus *st, int c);*/
4925static void special_event(MidiStatus *st, int c);
4926static void queue_read(MidiStatus *st, int c);
4927static void midi_note_on(MidiStatus *st);
4928static void midi_note_off(MidiStatus *st);
4929static void midi_key_pressure(MidiStatus *st);
4930static void midi_channel_pressure(MidiStatus *st);
4931static void midi_pitch_wheel(MidiStatus *st);
4932static void midi_program_change(MidiStatus *st);
4933static void midi_control_change(MidiStatus *st);
4934static void midi_select_bank(MidiStatus *st, int val);
4935static void midi_nrpn_event(MidiStatus *st);
4936static void midi_rpn_event(MidiStatus *st);
4937static void midi_detune(int chan, int coarse, int fine);
4938static void midi_system_exclusive(MidiStatus *st);
4939static int send_converted_effect(ConvTable *table, int num_tables, MidiStatus *st, int type, int val);
4940static int add_converted_effect(ConvTable *table, int num_tables, MidiStatus *st, int type, int val);
4941static int xg_control_change(MidiStatus *st, int cmd, int val);
4942
4943#define numberof(ary) (sizeof(ary)/sizeof(ary[0]))
4944
4945
4946/*
4947 * OSS Midi device record
4948 */
4949
4950static struct midi_operations awe_midi_operations =
4951{
4952 .owner = THIS_MODULE,
4953 .info = {"AWE Midi Emu", 0, 0, SNDCARD_SB},
4954 .in_info = {0},
4955 .open = awe_midi_open, /*open*/
4956 .close = awe_midi_close, /*close*/
4957 .ioctl = awe_midi_ioctl, /*ioctl*/
4958 .outputc = awe_midi_outputc, /*outputc*/
4959};
4960
4961static int my_mididev = -1;
4962
4963static void __init attach_midiemu(void)
4964{
4965 if ((my_mididev = sound_alloc_mididev()) < 0)
4966 printk ("Sound: Too many midi devices detected\n");
4967 else
4968 midi_devs[my_mididev] = &awe_midi_operations;
4969}
4970
4971static void unload_midiemu(void)
4972{
4973 if (my_mididev >= 0)
4974 sound_unload_mididev(my_mididev);
4975}
4976
4977
4978/*
4979 * open/close midi device
4980 */
4981
4982static int midi_opened = FALSE;
4983
4984static int midi_mode;
4985static int coarsetune, finetune;
4986
4987static int xg_mapping = TRUE;
4988static int xg_bankmode;
4989
4990/* effect sensitivity */
4991
4992#define FX_CUTOFF 0
4993#define FX_RESONANCE 1
4994#define FX_ATTACK 2
4995#define FX_RELEASE 3
4996#define FX_VIBRATE 4
4997#define FX_VIBDEPTH 5
4998#define FX_VIBDELAY 6
4999#define FX_NUMS 7
5000
5001#define DEF_FX_CUTOFF 170
5002#define DEF_FX_RESONANCE 6
5003#define DEF_FX_ATTACK 50
5004#define DEF_FX_RELEASE 50
5005#define DEF_FX_VIBRATE 30
5006#define DEF_FX_VIBDEPTH 4
5007#define DEF_FX_VIBDELAY 1500
5008
5009/* effect sense: */
5010static int gs_sense[] =
5011{
5012 DEF_FX_CUTOFF, DEF_FX_RESONANCE, DEF_FX_ATTACK, DEF_FX_RELEASE,
5013 DEF_FX_VIBRATE, DEF_FX_VIBDEPTH, DEF_FX_VIBDELAY
5014};
5015static int xg_sense[] =
5016{
5017 DEF_FX_CUTOFF, DEF_FX_RESONANCE, DEF_FX_ATTACK, DEF_FX_RELEASE,
5018 DEF_FX_VIBRATE, DEF_FX_VIBDEPTH, DEF_FX_VIBDELAY
5019};
5020
5021
5022/* current status */
5023static MidiStatus curst;
5024
5025
5026static int
5027awe_midi_open (int dev, int mode,
5028 void (*input)(int,unsigned char),
5029 void (*output)(int))
5030{
5031 if (midi_opened)
5032 return -EBUSY;
5033
5034 midi_opened = TRUE;
5035
5036 midi_mode = MODE_GM;
5037
5038 curst.queue = Q_NONE;
5039 curst.qlen = 0;
5040 curst.read = 0;
5041 curst.status = 0;
5042 curst.chan = 0;
5043 memset(curst.buf, 0, sizeof(curst.buf));
5044
5045 init_midi_status(&curst);
5046
5047 return 0;
5048}
5049
5050static void
5051awe_midi_close (int dev)
5052{
5053 midi_opened = FALSE;
5054}
5055
5056
5057static int
5058awe_midi_ioctl (int dev, unsigned cmd, void __user *arg)
5059{
5060 return -EPERM;
5061}
5062
5063static int
5064awe_midi_outputc (int dev, unsigned char midi_byte)
5065{
5066 if (! midi_opened)
5067 return 1;
5068
5069 /* force to change playing mode */
5070 playing_mode = AWE_PLAY_MULTI;
5071
5072 get_midi_char(&curst, midi_byte);
5073 return 1;
5074}
5075
5076
5077/*
5078 * initialize
5079 */
5080
5081static void init_midi_status(MidiStatus *st)
5082{
5083 clear_rpn();
5084 coarsetune = 0;
5085 finetune = 0;
5086}
5087
5088
5089/*
5090 * RPN & NRPN
5091 */
5092
5093#define MAX_MIDI_CHANNELS 16
5094
5095/* RPN & NRPN */
5096static unsigned char nrpn[MAX_MIDI_CHANNELS]; /* current event is NRPN? */
5097static int msb_bit; /* current event is msb for RPN/NRPN */
5098/* RPN & NRPN indeces */
5099static unsigned char rpn_msb[MAX_MIDI_CHANNELS], rpn_lsb[MAX_MIDI_CHANNELS];
5100/* RPN & NRPN values */
5101static int rpn_val[MAX_MIDI_CHANNELS];
5102
5103static void clear_rpn(void)
5104{
5105 int i;
5106 for (i = 0; i < MAX_MIDI_CHANNELS; i++) {
5107 nrpn[i] = 0;
5108 rpn_msb[i] = 127;
5109 rpn_lsb[i] = 127;
5110 rpn_val[i] = 0;
5111 }
5112 msb_bit = 0;
5113}
5114
5115
5116/*
5117 * process midi queue
5118 */
5119
5120/* status event types */
5121typedef void (*StatusEvent)(MidiStatus *st);
5122static struct StatusEventList {
5123 StatusEvent process;
5124 int qlen;
5125} status_event[8] = {
5126 {midi_note_off, 2},
5127 {midi_note_on, 2},
5128 {midi_key_pressure, 2},
5129 {midi_control_change, 2},
5130 {midi_program_change, 1},
5131 {midi_channel_pressure, 1},
5132 {midi_pitch_wheel, 2},
5133 {NULL, 0},
5134};
5135
5136
5137/* read a char from fifo and process it */
5138static void get_midi_char(MidiStatus *st, int c)
5139{
5140 if (c == 0xfe) {
5141 /* ignore active sense */
5142 st->queue = Q_NONE;
5143 return;
5144 }
5145
5146 switch (st->queue) {
5147 /* case Q_VARLEN: queue_varlen(st, c); break;*/
5148 case Q_READ:
5149 case Q_SYSEX:
5150 queue_read(st, c);
5151 break;
5152 case Q_NONE:
5153 st->read = 0;
5154 if ((c & 0xf0) == 0xf0) {
5155 special_event(st, c);
5156 } else if (c & 0x80) { /* status change */
5157 st->status = (c >> 4) & 0x07;
5158 st->chan = c & 0x0f;
5159 st->queue = Q_READ;
5160 st->qlen = status_event[st->status].qlen;
5161 if (st->qlen == 0)
5162 st->queue = Q_NONE;
5163 }
5164 break;
5165 }
5166}
5167
5168/* 0xfx events */
5169static void special_event(MidiStatus *st, int c)
5170{
5171 switch (c) {
5172 case 0xf0: /* system exclusive */
5173 st->queue = Q_SYSEX;
5174 st->qlen = 0;
5175 break;
5176 case 0xf1: /* MTC quarter frame */
5177 case 0xf3: /* song select */
5178 st->queue = Q_READ;
5179 st->qlen = 1;
5180 break;
5181 case 0xf2: /* song position */
5182 st->queue = Q_READ;
5183 st->qlen = 2;
5184 break;
5185 }
5186}
5187
5188#if 0
5189/* read variable length value */
5190static void queue_varlen(MidiStatus *st, int c)
5191{
5192 st->qlen += (c & 0x7f);
5193 if (c & 0x80) {
5194 st->qlen <<= 7;
5195 return;
5196 }
5197 if (st->qlen <= 0) {
5198 st->qlen = 0;
5199 st->queue = Q_NONE;
5200 }
5201 st->queue = Q_READ;
5202 st->read = 0;
5203}
5204#endif
5205
5206
5207/* read a char */
5208static void queue_read(MidiStatus *st, int c)
5209{
5210 if (st->read < MAX_MIDIBUF) {
5211 if (st->queue != Q_SYSEX)
5212 c &= 0x7f;
5213 st->buf[st->read] = (unsigned char)c;
5214 }
5215 st->read++;
5216 if (st->queue == Q_SYSEX && c == 0xf7) {
5217 midi_system_exclusive(st);
5218 st->queue = Q_NONE;
5219 } else if (st->queue == Q_READ && st->read >= st->qlen) {
5220 if (status_event[st->status].process)
5221 status_event[st->status].process(st);
5222 st->queue = Q_NONE;
5223 }
5224}
5225
5226
5227/*
5228 * status events
5229 */
5230
5231/* note on */
5232static void midi_note_on(MidiStatus *st)
5233{
5234 DEBUG(2,printk("midi: note_on (%d) %d %d\n", st->chan, st->buf[0], st->buf[1]));
5235 if (st->buf[1] == 0)
5236 midi_note_off(st);
5237 else
5238 awe_start_note(0, st->chan, st->buf[0], st->buf[1]);
5239}
5240
5241/* note off */
5242static void midi_note_off(MidiStatus *st)
5243{
5244 DEBUG(2,printk("midi: note_off (%d) %d %d\n", st->chan, st->buf[0], st->buf[1]));
5245 awe_kill_note(0, st->chan, st->buf[0], st->buf[1]);
5246}
5247
5248/* key pressure change */
5249static void midi_key_pressure(MidiStatus *st)
5250{
5251 awe_key_pressure(0, st->chan, st->buf[0], st->buf[1]);
5252}
5253
5254/* channel pressure change */
5255static void midi_channel_pressure(MidiStatus *st)
5256{
5257 channels[st->chan].chan_press = st->buf[0];
5258 awe_modwheel_change(st->chan, st->buf[0]);
5259}
5260
5261/* pitch wheel change */
5262static void midi_pitch_wheel(MidiStatus *st)
5263{
5264 int val = (int)st->buf[1] * 128 + st->buf[0];
5265 awe_bender(0, st->chan, val);
5266}
5267
5268/* program change */
5269static void midi_program_change(MidiStatus *st)
5270{
5271 int preset;
5272 preset = st->buf[0];
5273 if (midi_mode == MODE_GS && IS_DRUM_CHANNEL(st->chan) && preset == 127)
5274 preset = 0;
5275 else if (midi_mode == MODE_XG && xg_mapping && IS_DRUM_CHANNEL(st->chan))
5276 preset += 64;
5277
5278 awe_set_instr(0, st->chan, preset);
5279}
5280
5281#define send_effect(chan,type,val) awe_send_effect(chan,-1,type,val)
5282#define add_effect(chan,type,val) awe_send_effect(chan,-1,(type)|0x80,val)
5283#define unset_effect(chan,type) awe_send_effect(chan,-1,(type)|0x40,0)
5284
5285/* midi control change */
5286static void midi_control_change(MidiStatus *st)
5287{
5288 int cmd = st->buf[0];
5289 int val = st->buf[1];
5290
5291 DEBUG(2,printk("midi: control (%d) %d %d\n", st->chan, cmd, val));
5292 if (midi_mode == MODE_XG) {
5293 if (xg_control_change(st, cmd, val))
5294 return;
5295 }
5296
5297 /* controls #31 - #64 are LSB of #0 - #31 */
5298 msb_bit = 1;
5299 if (cmd >= 0x20 && cmd < 0x40) {
5300 msb_bit = 0;
5301 cmd -= 0x20;
5302 }
5303
5304 switch (cmd) {
5305 case CTL_SOFT_PEDAL:
5306 if (val == 127)
5307 add_effect(st->chan, AWE_FX_CUTOFF, -160);
5308 else
5309 unset_effect(st->chan, AWE_FX_CUTOFF);
5310 break;
5311
5312 case CTL_BANK_SELECT:
5313 midi_select_bank(st, val);
5314 break;
5315
5316 /* set RPN/NRPN parameter */
5317 case CTL_REGIST_PARM_NUM_MSB:
5318 nrpn[st->chan]=0; rpn_msb[st->chan]=val;
5319 break;
5320 case CTL_REGIST_PARM_NUM_LSB:
5321 nrpn[st->chan]=0; rpn_lsb[st->chan]=val;
5322 break;
5323 case CTL_NONREG_PARM_NUM_MSB:
5324 nrpn[st->chan]=1; rpn_msb[st->chan]=val;
5325 break;
5326 case CTL_NONREG_PARM_NUM_LSB:
5327 nrpn[st->chan]=1; rpn_lsb[st->chan]=val;
5328 break;
5329
5330 /* send RPN/NRPN entry */
5331 case CTL_DATA_ENTRY:
5332 if (msb_bit)
5333 rpn_val[st->chan] = val * 128;
5334 else
5335 rpn_val[st->chan] |= val;
5336 if (nrpn[st->chan])
5337 midi_nrpn_event(st);
5338 else
5339 midi_rpn_event(st);
5340 break;
5341
5342 /* increase/decrease data entry */
5343 case CTL_DATA_INCREMENT:
5344 rpn_val[st->chan]++;
5345 midi_rpn_event(st);
5346 break;
5347 case CTL_DATA_DECREMENT:
5348 rpn_val[st->chan]--;
5349 midi_rpn_event(st);
5350 break;
5351
5352 /* default */
5353 default:
5354 awe_controller(0, st->chan, cmd, val);
5355 break;
5356 }
5357}
5358
5359/* tone bank change */
5360static void midi_select_bank(MidiStatus *st, int val)
5361{
5362 if (midi_mode == MODE_XG && msb_bit) {
5363 xg_bankmode = val;
5364 /* XG MSB value; not normal bank selection */
5365 switch (val) {
5366 case 127: /* remap to drum channel */
5367 awe_controller(0, st->chan, CTL_BANK_SELECT, 128);
5368 break;
5369 default: /* remap to normal channel */
5370 awe_controller(0, st->chan, CTL_BANK_SELECT, val);
5371 break;
5372 }
5373 return;
5374 } else if (midi_mode == MODE_GS && !msb_bit)
5375 /* ignore LSB bank in GS mode (used for mapping) */
5376 return;
5377
5378 /* normal bank controls; accept both MSB and LSB */
5379 if (! IS_DRUM_CHANNEL(st->chan)) {
5380 if (midi_mode == MODE_XG) {
5381 if (xg_bankmode) return;
5382 if (val == 64 || val == 126)
5383 val = 0;
5384 } else if (midi_mode == MODE_GS && val == 127)
5385 val = 0;
5386 awe_controller(0, st->chan, CTL_BANK_SELECT, val);
5387 }
5388}
5389
5390
5391/*
5392 * RPN events
5393 */
5394
5395static void midi_rpn_event(MidiStatus *st)
5396{
5397 int type;
5398 type = (rpn_msb[st->chan]<<8) | rpn_lsb[st->chan];
5399 switch (type) {
5400 case 0x0000: /* Pitch bend sensitivity */
5401 /* MSB only / 1 semitone per 128 */
5402 if (msb_bit) {
5403 channels[st->chan].bender_range =
5404 rpn_val[st->chan] * 100 / 128;
5405 }
5406 break;
5407
5408 case 0x0001: /* fine tuning: */
5409 /* MSB/LSB, 8192=center, 100/8192 cent step */
5410 finetune = rpn_val[st->chan] - 8192;
5411 midi_detune(st->chan, coarsetune, finetune);
5412 break;
5413
5414 case 0x0002: /* coarse tuning */
5415 /* MSB only / 8192=center, 1 semitone per 128 */
5416 if (msb_bit) {
5417 coarsetune = rpn_val[st->chan] - 8192;
5418 midi_detune(st->chan, coarsetune, finetune);
5419 }
5420 break;
5421
5422 case 0x7F7F: /* "lock-in" RPN */
5423 break;
5424 }
5425}
5426
5427
5428/* tuning:
5429 * coarse = -8192 to 8192 (100 cent per 128)
5430 * fine = -8192 to 8192 (max=100cent)
5431 */
5432static void midi_detune(int chan, int coarse, int fine)
5433{
5434 /* 4096 = 1200 cents in AWE parameter */
5435 int val;
5436 val = coarse * 4096 / (12 * 128);
5437 val += fine / 24;
5438 if (val)
5439 send_effect(chan, AWE_FX_INIT_PITCH, val);
5440 else
5441 unset_effect(chan, AWE_FX_INIT_PITCH);
5442}
5443
5444
5445/*
5446 * system exclusive message
5447 * GM/GS/XG macros are accepted
5448 */
5449
5450static void midi_system_exclusive(MidiStatus *st)
5451{
5452 /* GM on */
5453 static unsigned char gm_on_macro[] = {
5454 0x7e,0x7f,0x09,0x01,
5455 };
5456 /* XG on */
5457 static unsigned char xg_on_macro[] = {
5458 0x43,0x10,0x4c,0x00,0x00,0x7e,0x00,
5459 };
5460 /* GS prefix
5461 * drum channel: XX=0x1?(channel), YY=0x15, ZZ=on/off
5462 * reverb mode: XX=0x01, YY=0x30, ZZ=0-7
5463 * chorus mode: XX=0x01, YY=0x38, ZZ=0-7
5464 */
5465 static unsigned char gs_pfx_macro[] = {
5466 0x41,0x10,0x42,0x12,0x40,/*XX,YY,ZZ*/
5467 };
5468
5469#if 0
5470 /* SC88 system mode set
5471 * single module mode: XX=1
5472 * double module mode: XX=0
5473 */
5474 static unsigned char gs_mode_macro[] = {
5475 0x41,0x10,0x42,0x12,0x00,0x00,0x7F,/*ZZ*/
5476 };
5477 /* SC88 display macro: XX=01:bitmap, 00:text
5478 */
5479 static unsigned char gs_disp_macro[] = {
5480 0x41,0x10,0x45,0x12,0x10,/*XX,00*/
5481 };
5482#endif
5483
5484 /* GM on */
5485 if (memcmp(st->buf, gm_on_macro, sizeof(gm_on_macro)) == 0) {
5486 if (midi_mode != MODE_GS && midi_mode != MODE_XG)
5487 midi_mode = MODE_GM;
5488 init_midi_status(st);
5489 }
5490
5491 /* GS macros */
5492 else if (memcmp(st->buf, gs_pfx_macro, sizeof(gs_pfx_macro)) == 0) {
5493 if (midi_mode != MODE_GS && midi_mode != MODE_XG)
5494 midi_mode = MODE_GS;
5495
5496 if (st->buf[5] == 0x00 && st->buf[6] == 0x7f && st->buf[7] == 0x00) {
5497 /* GS reset */
5498 init_midi_status(st);
5499 }
5500
5501 else if ((st->buf[5] & 0xf0) == 0x10 && st->buf[6] == 0x15) {
5502 /* drum pattern */
5503 int p = st->buf[5] & 0x0f;
5504 if (p == 0) p = 9;
5505 else if (p < 10) p--;
5506 if (st->buf[7] == 0)
5507 DRUM_CHANNEL_OFF(p);
5508 else
5509 DRUM_CHANNEL_ON(p);
5510
5511 } else if ((st->buf[5] & 0xf0) == 0x10 && st->buf[6] == 0x21) {
5512 /* program */
5513 int p = st->buf[5] & 0x0f;
5514 if (p == 0) p = 9;
5515 else if (p < 10) p--;
5516 if (! IS_DRUM_CHANNEL(p))
5517 awe_set_instr(0, p, st->buf[7]);
5518
5519 } else if (st->buf[5] == 0x01 && st->buf[6] == 0x30) {
5520 /* reverb mode */
5521 awe_set_reverb_mode(st->buf[7]);
5522
5523 } else if (st->buf[5] == 0x01 && st->buf[6] == 0x38) {
5524 /* chorus mode */
5525 awe_set_chorus_mode(st->buf[7]);
5526
5527 } else if (st->buf[5] == 0x00 && st->buf[6] == 0x04) {
5528 /* master volume */
5529 awe_change_master_volume(st->buf[7]);
5530
5531 }
5532 }
5533
5534 /* XG on */
5535 else if (memcmp(st->buf, xg_on_macro, sizeof(xg_on_macro)) == 0) {
5536 midi_mode = MODE_XG;
5537 xg_mapping = TRUE;
5538 xg_bankmode = 0;
5539 }
5540}
5541
5542
5543/*----------------------------------------------------------------*/
5544
5545/*
5546 * convert NRPN/control values
5547 */
5548
5549static int send_converted_effect(ConvTable *table, int num_tables, MidiStatus *st, int type, int val)
5550{
5551 int i, cval;
5552 for (i = 0; i < num_tables; i++) {
5553 if (table[i].control == type) {
5554 cval = table[i].convert(val);
5555 send_effect(st->chan, table[i].awe_effect, cval);
5556 return TRUE;
5557 }
5558 }
5559 return FALSE;
5560}
5561
5562static int add_converted_effect(ConvTable *table, int num_tables, MidiStatus *st, int type, int val)
5563{
5564 int i, cval;
5565 for (i = 0; i < num_tables; i++) {
5566 if (table[i].control == type) {
5567 cval = table[i].convert(val);
5568 add_effect(st->chan, table[i].awe_effect|0x80, cval);
5569 return TRUE;
5570 }
5571 }
5572 return FALSE;
5573}
5574
5575
5576/*
5577 * AWE32 NRPN effects
5578 */
5579
5580static unsigned short fx_delay(int val);
5581static unsigned short fx_attack(int val);
5582static unsigned short fx_hold(int val);
5583static unsigned short fx_decay(int val);
5584static unsigned short fx_the_value(int val);
5585static unsigned short fx_twice_value(int val);
5586static unsigned short fx_conv_pitch(int val);
5587static unsigned short fx_conv_Q(int val);
5588
5589/* function for each NRPN */ /* [range] units */
5590#define fx_env1_delay fx_delay /* [0,5900] 4msec */
5591#define fx_env1_attack fx_attack /* [0,5940] 1msec */
5592#define fx_env1_hold fx_hold /* [0,8191] 1msec */
5593#define fx_env1_decay fx_decay /* [0,5940] 4msec */
5594#define fx_env1_release fx_decay /* [0,5940] 4msec */
5595#define fx_env1_sustain fx_the_value /* [0,127] 0.75dB */
5596#define fx_env1_pitch fx_the_value /* [-127,127] 9.375cents */
5597#define fx_env1_cutoff fx_the_value /* [-127,127] 56.25cents */
5598
5599#define fx_env2_delay fx_delay /* [0,5900] 4msec */
5600#define fx_env2_attack fx_attack /* [0,5940] 1msec */
5601#define fx_env2_hold fx_hold /* [0,8191] 1msec */
5602#define fx_env2_decay fx_decay /* [0,5940] 4msec */
5603#define fx_env2_release fx_decay /* [0,5940] 4msec */
5604#define fx_env2_sustain fx_the_value /* [0,127] 0.75dB */
5605
5606#define fx_lfo1_delay fx_delay /* [0,5900] 4msec */
5607#define fx_lfo1_freq fx_twice_value /* [0,127] 84mHz */
5608#define fx_lfo1_volume fx_twice_value /* [0,127] 0.1875dB */
5609#define fx_lfo1_pitch fx_the_value /* [-127,127] 9.375cents */
5610#define fx_lfo1_cutoff fx_twice_value /* [-64,63] 56.25cents */
5611
5612#define fx_lfo2_delay fx_delay /* [0,5900] 4msec */
5613#define fx_lfo2_freq fx_twice_value /* [0,127] 84mHz */
5614#define fx_lfo2_pitch fx_the_value /* [-127,127] 9.375cents */
5615
5616#define fx_init_pitch fx_conv_pitch /* [-8192,8192] cents */
5617#define fx_chorus fx_the_value /* [0,255] -- */
5618#define fx_reverb fx_the_value /* [0,255] -- */
5619#define fx_cutoff fx_twice_value /* [0,127] 62Hz */
5620#define fx_filterQ fx_conv_Q /* [0,127] -- */
5621
5622static unsigned short fx_delay(int val)
5623{
5624 return (unsigned short)calc_parm_delay(val);
5625}
5626
5627static unsigned short fx_attack(int val)
5628{
5629 return (unsigned short)calc_parm_attack(val);
5630}
5631
5632static unsigned short fx_hold(int val)
5633{
5634 return (unsigned short)calc_parm_hold(val);
5635}
5636
5637static unsigned short fx_decay(int val)
5638{
5639 return (unsigned short)calc_parm_decay(val);
5640}
5641
5642static unsigned short fx_the_value(int val)
5643{
5644 return (unsigned short)(val & 0xff);
5645}
5646
5647static unsigned short fx_twice_value(int val)
5648{
5649 return (unsigned short)((val * 2) & 0xff);
5650}
5651
5652static unsigned short fx_conv_pitch(int val)
5653{
5654 return (short)(val * 4096 / 1200);
5655}
5656
5657static unsigned short fx_conv_Q(int val)
5658{
5659 return (unsigned short)((val / 8) & 0xff);
5660}
5661
5662
5663static ConvTable awe_effects[] =
5664{
5665 { 0, AWE_FX_LFO1_DELAY, fx_lfo1_delay},
5666 { 1, AWE_FX_LFO1_FREQ, fx_lfo1_freq},
5667 { 2, AWE_FX_LFO2_DELAY, fx_lfo2_delay},
5668 { 3, AWE_FX_LFO2_FREQ, fx_lfo2_freq},
5669
5670 { 4, AWE_FX_ENV1_DELAY, fx_env1_delay},
5671 { 5, AWE_FX_ENV1_ATTACK,fx_env1_attack},
5672 { 6, AWE_FX_ENV1_HOLD, fx_env1_hold},
5673 { 7, AWE_FX_ENV1_DECAY, fx_env1_decay},
5674 { 8, AWE_FX_ENV1_SUSTAIN, fx_env1_sustain},
5675 { 9, AWE_FX_ENV1_RELEASE, fx_env1_release},
5676
5677 {10, AWE_FX_ENV2_DELAY, fx_env2_delay},
5678 {11, AWE_FX_ENV2_ATTACK, fx_env2_attack},
5679 {12, AWE_FX_ENV2_HOLD, fx_env2_hold},
5680 {13, AWE_FX_ENV2_DECAY, fx_env2_decay},
5681 {14, AWE_FX_ENV2_SUSTAIN, fx_env2_sustain},
5682 {15, AWE_FX_ENV2_RELEASE, fx_env2_release},
5683
5684 {16, AWE_FX_INIT_PITCH, fx_init_pitch},
5685 {17, AWE_FX_LFO1_PITCH, fx_lfo1_pitch},
5686 {18, AWE_FX_LFO2_PITCH, fx_lfo2_pitch},
5687 {19, AWE_FX_ENV1_PITCH, fx_env1_pitch},
5688 {20, AWE_FX_LFO1_VOLUME, fx_lfo1_volume},
5689 {21, AWE_FX_CUTOFF, fx_cutoff},
5690 {22, AWE_FX_FILTERQ, fx_filterQ},
5691 {23, AWE_FX_LFO1_CUTOFF, fx_lfo1_cutoff},
5692 {24, AWE_FX_ENV1_CUTOFF, fx_env1_cutoff},
5693 {25, AWE_FX_CHORUS, fx_chorus},
5694 {26, AWE_FX_REVERB, fx_reverb},
5695};
5696
5697static int num_awe_effects = numberof(awe_effects);
5698
5699
5700/*
5701 * GS(SC88) NRPN effects; still experimental
5702 */
5703
5704/* cutoff: quarter semitone step, max=255 */
5705static unsigned short gs_cutoff(int val)
5706{
5707 return (val - 64) * gs_sense[FX_CUTOFF] / 50;
5708}
5709
5710/* resonance: 0 to 15(max) */
5711static unsigned short gs_filterQ(int val)
5712{
5713 return (val - 64) * gs_sense[FX_RESONANCE] / 50;
5714}
5715
5716/* attack: */
5717static unsigned short gs_attack(int val)
5718{
5719 return -(val - 64) * gs_sense[FX_ATTACK] / 50;
5720}
5721
5722/* decay: */
5723static unsigned short gs_decay(int val)
5724{
5725 return -(val - 64) * gs_sense[FX_RELEASE] / 50;
5726}
5727
5728/* release: */
5729static unsigned short gs_release(int val)
5730{
5731 return -(val - 64) * gs_sense[FX_RELEASE] / 50;
5732}
5733
5734/* vibrato freq: 0.042Hz step, max=255 */
5735static unsigned short gs_vib_rate(int val)
5736{
5737 return (val - 64) * gs_sense[FX_VIBRATE] / 50;
5738}
5739
5740/* vibrato depth: max=127, 1 octave */
5741static unsigned short gs_vib_depth(int val)
5742{
5743 return (val - 64) * gs_sense[FX_VIBDEPTH] / 50;
5744}
5745
5746/* vibrato delay: -0.725msec step */
5747static unsigned short gs_vib_delay(int val)
5748{
5749 return -(val - 64) * gs_sense[FX_VIBDELAY] / 50;
5750}
5751
5752static ConvTable gs_effects[] =
5753{
5754 {32, AWE_FX_CUTOFF, gs_cutoff},
5755 {33, AWE_FX_FILTERQ, gs_filterQ},
5756 {99, AWE_FX_ENV2_ATTACK, gs_attack},
5757 {100, AWE_FX_ENV2_DECAY, gs_decay},
5758 {102, AWE_FX_ENV2_RELEASE, gs_release},
5759 {8, AWE_FX_LFO1_FREQ, gs_vib_rate},
5760 {9, AWE_FX_LFO1_VOLUME, gs_vib_depth},
5761 {10, AWE_FX_LFO1_DELAY, gs_vib_delay},
5762};
5763
5764static int num_gs_effects = numberof(gs_effects);
5765
5766
5767/*
5768 * NRPN events: accept as AWE32/SC88 specific controls
5769 */
5770
5771static void midi_nrpn_event(MidiStatus *st)
5772{
5773 if (rpn_msb[st->chan] == 127 && rpn_lsb[st->chan] <= 26) {
5774 if (! msb_bit) /* both MSB/LSB necessary */
5775 send_converted_effect(awe_effects, num_awe_effects,
5776 st, rpn_lsb[st->chan],
5777 rpn_val[st->chan] - 8192);
5778 } else if (rpn_msb[st->chan] == 1) {
5779 if (msb_bit) /* only MSB is valid */
5780 add_converted_effect(gs_effects, num_gs_effects,
5781 st, rpn_lsb[st->chan],
5782 rpn_val[st->chan] / 128);
5783 }
5784}
5785
5786
5787/*
5788 * XG control effects; still experimental
5789 */
5790
5791/* cutoff: quarter semitone step, max=255 */
5792static unsigned short xg_cutoff(int val)
5793{
5794 return (val - 64) * xg_sense[FX_CUTOFF] / 64;
5795}
5796
5797/* resonance: 0(open) to 15(most nasal) */
5798static unsigned short xg_filterQ(int val)
5799{
5800 return (val - 64) * xg_sense[FX_RESONANCE] / 64;
5801}
5802
5803/* attack: */
5804static unsigned short xg_attack(int val)
5805{
5806 return -(val - 64) * xg_sense[FX_ATTACK] / 64;
5807}
5808
5809/* release: */
5810static unsigned short xg_release(int val)
5811{
5812 return -(val - 64) * xg_sense[FX_RELEASE] / 64;
5813}
5814
5815static ConvTable xg_effects[] =
5816{
5817 {71, AWE_FX_CUTOFF, xg_cutoff},
5818 {74, AWE_FX_FILTERQ, xg_filterQ},
5819 {72, AWE_FX_ENV2_RELEASE, xg_release},
5820 {73, AWE_FX_ENV2_ATTACK, xg_attack},
5821};
5822
5823static int num_xg_effects = numberof(xg_effects);
5824
5825static int xg_control_change(MidiStatus *st, int cmd, int val)
5826{
5827 return add_converted_effect(xg_effects, num_xg_effects, st, cmd, val);
5828}
5829
5830#endif /* CONFIG_AWE32_MIDIEMU */
5831
5832
5833/*----------------------------------------------------------------*/
5834
5835
5836/*
5837 * initialization of AWE driver
5838 */
5839
5840static void
5841awe_initialize(void)
5842{
5843 DEBUG(0,printk("AWE32: initializing..\n"));
5844
5845 /* initialize hardware configuration */
5846 awe_poke(AWE_HWCF1, 0x0059);
5847 awe_poke(AWE_HWCF2, 0x0020);
5848
5849 /* disable audio; this seems to reduce a clicking noise a bit.. */
5850 awe_poke(AWE_HWCF3, 0);
5851
5852 /* initialize audio channels */
5853 awe_init_audio();
5854
5855 /* initialize DMA */
5856 awe_init_dma();
5857
5858 /* initialize init array */
5859 awe_init_array();
5860
5861 /* check DRAM memory size */
5862 awe_check_dram();
5863
5864 /* initialize the FM section of the AWE32 */
5865 awe_init_fm();
5866
5867 /* set up voice envelopes */
5868 awe_tweak();
5869
5870 /* enable audio */
5871 awe_poke(AWE_HWCF3, 0x0004);
5872
5873 /* set default values */
5874 awe_init_ctrl_parms(TRUE);
5875
5876 /* set equalizer */
5877 awe_update_equalizer();
5878
5879 /* set reverb & chorus modes */
5880 awe_update_reverb_mode();
5881 awe_update_chorus_mode();
5882}
5883
5884
5885/*
5886 * Core Device Management Functions
5887 */
5888
5889/* store values to i/o port array */
5890static void setup_ports(int port1, int port2, int port3)
5891{
5892 awe_ports[0] = port1;
5893 if (port2 == 0)
5894 port2 = port1 + 0x400;
5895 awe_ports[1] = port2;
5896 awe_ports[2] = port2 + 2;
5897 if (port3 == 0)
5898 port3 = port1 + 0x800;
5899 awe_ports[3] = port3;
5900 awe_ports[4] = port3 + 2;
5901
5902 port_setuped = TRUE;
5903}
5904
5905/*
5906 * port request
5907 * 0x620-623, 0xA20-A23, 0xE20-E23
5908 */
5909
5910static int
5911awe_request_region(void)
5912{
5913 if (! port_setuped)
5914 return 0;
5915 if (! request_region(awe_ports[0], 4, "sound driver (AWE32)"))
5916 return 0;
5917 if (! request_region(awe_ports[1], 4, "sound driver (AWE32)"))
5918 goto err_out;
5919 if (! request_region(awe_ports[3], 4, "sound driver (AWE32)"))
5920 goto err_out1;
5921 return 1;
5922err_out1:
5923 release_region(awe_ports[1], 4);
5924err_out:
5925 release_region(awe_ports[0], 4);
5926 return 0;
5927}
5928
5929static void
5930awe_release_region(void)
5931{
5932 if (! port_setuped) return;
5933 release_region(awe_ports[0], 4);
5934 release_region(awe_ports[1], 4);
5935 release_region(awe_ports[3], 4);
5936}
5937
5938static int awe_attach_device(void)
5939{
5940 if (awe_present) return 0; /* for OSS38.. called twice? */
5941
5942 /* reserve I/O ports for awedrv */
5943 if (! awe_request_region()) {
5944 printk(KERN_ERR "AWE32: I/O area already used.\n");
5945 return 0;
5946 }
5947
5948 /* set buffers to NULL */
5949 sfhead = sftail = NULL;
5950
5951 my_dev = sound_alloc_synthdev();
5952 if (my_dev == -1) {
5953 printk(KERN_ERR "AWE32 Error: too many synthesizers\n");
5954 awe_release_region();
5955 return 0;
5956 }
5957
5958 voice_alloc = &awe_operations.alloc;
5959 voice_alloc->max_voice = awe_max_voices;
5960 synth_devs[my_dev] = &awe_operations;
5961
5962#ifdef CONFIG_AWE32_MIXER
5963 attach_mixer();
5964#endif
5965#ifdef CONFIG_AWE32_MIDIEMU
5966 attach_midiemu();
5967#endif
5968
5969 /* clear all samples */
5970 awe_reset_samples();
5971
5972 /* initialize AWE32 hardware */
5973 awe_initialize();
5974
5975 sprintf(awe_info.name, "AWE32-%s (RAM%dk)",
5976 AWEDRV_VERSION, memsize/1024);
5977 printk(KERN_INFO "<SoundBlaster EMU8000 (RAM%dk)>\n", memsize/1024);
5978
5979 awe_present = TRUE;
5980
5981 return 1;
5982}
5983
5984static void awe_dettach_device(void)
5985{
5986 if (awe_present) {
5987 awe_reset_samples();
5988 awe_release_region();
5989 free_tables();
5990#ifdef CONFIG_AWE32_MIXER
5991 unload_mixer();
5992#endif
5993#ifdef CONFIG_AWE32_MIDIEMU
5994 unload_midiemu();
5995#endif
5996 sound_unload_synthdev(my_dev);
5997 awe_present = FALSE;
5998 }
5999}
6000
6001
6002/*
6003 * Legacy device Probing
6004 */
6005
6006/* detect emu8000 chip on the specified address; from VV's guide */
6007
6008static int __init
6009awe_detect_base(int addr)
6010{
6011 setup_ports(addr, 0, 0);
6012 if ((awe_peek(AWE_U1) & 0x000F) != 0x000C)
6013 return 0;
6014 if ((awe_peek(AWE_HWCF1) & 0x007E) != 0x0058)
6015 return 0;
6016 if ((awe_peek(AWE_HWCF2) & 0x0003) != 0x0003)
6017 return 0;
6018 DEBUG(0,printk("AWE32 found at %x\n", addr));
6019 return 1;
6020}
6021
6022static int __init awe_detect_legacy_devices(void)
6023{
6024 int base;
6025 for (base = 0x620; base <= 0x680; base += 0x20)
6026 if (awe_detect_base(base)) {
6027 awe_attach_device();
6028 return 1;
6029 }
6030 DEBUG(0,printk("AWE32 Legacy detection failed\n"));
6031 return 0;
6032}
6033
6034
6035/*
6036 * PnP device Probing
6037 */
6038
6039static struct pnp_device_id awe_pnp_ids[] = {
6040 {.id = "CTL0021", .driver_data = 0}, /* AWE32 WaveTable */
6041 {.id = "CTL0022", .driver_data = 0}, /* AWE64 WaveTable */
6042 {.id = "CTL0023", .driver_data = 0}, /* AWE64 Gold WaveTable */
6043 { } /* terminator */
6044};
6045
6046MODULE_DEVICE_TABLE(pnp, awe_pnp_ids);
6047
6048static int awe_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
6049{
6050 int io1, io2, io3;
6051
6052 if (awe_present) {
6053 printk(KERN_ERR "AWE32: This driver only supports one AWE32 device, skipping.\n");
6054 }
6055
6056 if (!pnp_port_valid(dev,0) ||
6057 !pnp_port_valid(dev,1) ||
6058 !pnp_port_valid(dev,2)) {
6059 printk(KERN_ERR "AWE32: The PnP device does not have the required resources.\n");
6060 return -EINVAL;
6061 }
6062 io1 = pnp_port_start(dev,0);
6063 io2 = pnp_port_start(dev,1);
6064 io3 = pnp_port_start(dev,2);
6065 printk(KERN_INFO "AWE32: A PnP Wave Table was detected at IO's %#x,%#x,%#x\n.",
6066 io1, io2, io3);
6067 setup_ports(io1, io2, io3);
6068
6069 awe_attach_device();
6070 return 0;
6071}
6072
6073static void awe_pnp_remove(struct pnp_dev *dev)
6074{
6075 awe_dettach_device();
6076}
6077
6078static struct pnp_driver awe_pnp_driver = {
6079 .name = "AWE32",
6080 .id_table = awe_pnp_ids,
6081 .probe = awe_pnp_probe,
6082 .remove = awe_pnp_remove,
6083};
6084
6085static int __init awe_detect_pnp_devices(void)
6086{
6087 int ret;
6088
6089 ret = pnp_register_driver(&awe_pnp_driver);
6090 if (ret<0)
6091 printk(KERN_ERR "AWE32: PnP support is unavailable.\n");
6092 return ret;
6093}
6094
6095
6096/*
6097 * device / lowlevel (module) interface
6098 */
6099
6100static int __init
6101awe_detect(void)
6102{
6103 printk(KERN_INFO "AWE32: Probing for WaveTable...\n");
6104 if (isapnp) {
6105 if (awe_detect_pnp_devices()>=0)
6106 return 1;
6107 } else
6108 printk(KERN_INFO "AWE32: Skipping PnP detection.\n");
6109
6110 if (awe_detect_legacy_devices())
6111 return 1;
6112
6113 return 0;
6114}
6115
6116static int __init attach_awe(void)
6117{
6118 return awe_detect() ? 0 : -ENODEV;
6119}
6120
6121static void __exit unload_awe(void)
6122{
6123 pnp_unregister_driver(&awe_pnp_driver);
6124 awe_dettach_device();
6125}
6126
6127
6128module_init(attach_awe);
6129module_exit(unload_awe);
6130
6131#ifndef MODULE
6132static int __init setup_awe(char *str)
6133{
6134 /* io, memsize, isapnp */
6135 int ints[4];
6136
6137 str = get_options(str, ARRAY_SIZE(ints), ints);
6138
6139 io = ints[1];
6140 memsize = ints[2];
6141 isapnp = ints[3];
6142
6143 return 1;
6144}
6145
6146__setup("awe=", setup_awe);
6147#endif
diff --git a/sound/oss/awe_wave.h b/sound/oss/awe_wave.h
new file mode 100644
index 000000000000..a3aa018118bd
--- /dev/null
+++ b/sound/oss/awe_wave.h
@@ -0,0 +1,77 @@
1/*
2 * sound/awe_config.h
3 *
4 * Configuration of AWE32/SB32/AWE64 wave table synth driver.
5 * version 0.4.4; Jan. 4, 2000
6 *
7 * Copyright (C) 1996-1998 Takashi Iwai
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 * chorus & reverb effects send for FM chip: from 0 to 0xff
26 * larger numbers often cause weird sounds.
27 */
28
29#define DEF_FM_CHORUS_DEPTH 0x10
30#define DEF_FM_REVERB_DEPTH 0x10
31
32
33/*
34 * other compile conditions
35 */
36
37/* initialize FM passthrough even without extended RAM */
38#undef AWE_ALWAYS_INIT_FM
39
40/* debug on */
41#define AWE_DEBUG_ON
42
43/* GUS compatible mode */
44#define AWE_HAS_GUS_COMPATIBILITY
45
46/* add MIDI emulation by wavetable */
47#define CONFIG_AWE32_MIDIEMU
48
49/* add mixer control of emu8000 equalizer */
50#undef CONFIG_AWE32_MIXER
51
52/* use new volume calculation method as default */
53#define AWE_USE_NEW_VOLUME_CALC
54
55/* check current volume target for searching empty voices */
56#define AWE_CHECK_VTARGET
57
58/* allow sample sharing */
59#define AWE_ALLOW_SAMPLE_SHARING
60
61/*
62 * AWE32 card configuration:
63 * uncomment the following lines *ONLY* when auto detection doesn't
64 * work properly on your machine.
65 */
66
67/*#define AWE_DEFAULT_BASE_ADDR 0x620*/ /* base port address */
68/*#define AWE_DEFAULT_MEM_SIZE 512*/ /* kbytes */
69
70/*
71 * AWE driver version number
72 */
73#define AWE_MAJOR_VERSION 0
74#define AWE_MINOR_VERSION 4
75#define AWE_TINY_VERSION 4
76#define AWE_VERSION_NUMBER ((AWE_MAJOR_VERSION<<16)|(AWE_MINOR_VERSION<<8)|AWE_TINY_VERSION)
77#define AWEDRV_VERSION "0.4.4"
diff --git a/sound/oss/bin2hex.c b/sound/oss/bin2hex.c
new file mode 100644
index 000000000000..b59109eb0db4
--- /dev/null
+++ b/sound/oss/bin2hex.c
@@ -0,0 +1,39 @@
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/btaudio.c b/sound/oss/btaudio.c
new file mode 100644
index 000000000000..a85093fec7be
--- /dev/null
+++ b/sound/oss/btaudio.c
@@ -0,0 +1,1136 @@
1/*
2 btaudio - bt878 audio dma driver for linux 2.4.x
3
4 (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
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 as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20*/
21
22#include <linux/module.h>
23#include <linux/errno.h>
24#include <linux/pci.h>
25#include <linux/sched.h>
26#include <linux/signal.h>
27#include <linux/types.h>
28#include <linux/interrupt.h>
29#include <linux/init.h>
30#include <linux/poll.h>
31#include <linux/sound.h>
32#include <linux/soundcard.h>
33#include <linux/slab.h>
34#include <linux/kdev_t.h>
35#include <asm/uaccess.h>
36#include <asm/io.h>
37
38
39/* mmio access */
40#define btwrite(dat,adr) writel((dat), (bta->mmio+(adr)))
41#define btread(adr) readl(bta->mmio+(adr))
42
43#define btand(dat,adr) btwrite((dat) & btread(adr), adr)
44#define btor(dat,adr) btwrite((dat) | btread(adr), adr)
45#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
46
47/* registers (shifted because bta->mmio is long) */
48#define REG_INT_STAT (0x100 >> 2)
49#define REG_INT_MASK (0x104 >> 2)
50#define REG_GPIO_DMA_CTL (0x10c >> 2)
51#define REG_PACKET_LEN (0x110 >> 2)
52#define REG_RISC_STRT_ADD (0x114 >> 2)
53#define REG_RISC_COUNT (0x120 >> 2)
54
55/* IRQ bits - REG_INT_(STAT|MASK) */
56#define IRQ_SCERR (1 << 19)
57#define IRQ_OCERR (1 << 18)
58#define IRQ_PABORT (1 << 17)
59#define IRQ_RIPERR (1 << 16)
60#define IRQ_PPERR (1 << 15)
61#define IRQ_FDSR (1 << 14)
62#define IRQ_FTRGT (1 << 13)
63#define IRQ_FBUS (1 << 12)
64#define IRQ_RISCI (1 << 11)
65#define IRQ_OFLOW (1 << 3)
66
67#define IRQ_BTAUDIO (IRQ_SCERR | IRQ_OCERR | IRQ_PABORT | IRQ_RIPERR |\
68 IRQ_PPERR | IRQ_FDSR | IRQ_FTRGT | IRQ_FBUS |\
69 IRQ_RISCI)
70
71/* REG_GPIO_DMA_CTL bits */
72#define DMA_CTL_A_PWRDN (1 << 26)
73#define DMA_CTL_DA_SBR (1 << 14)
74#define DMA_CTL_DA_ES2 (1 << 13)
75#define DMA_CTL_ACAP_EN (1 << 4)
76#define DMA_CTL_RISC_EN (1 << 1)
77#define DMA_CTL_FIFO_EN (1 << 0)
78
79/* RISC instructions */
80#define RISC_WRITE (0x01 << 28)
81#define RISC_JUMP (0x07 << 28)
82#define RISC_SYNC (0x08 << 28)
83
84/* RISC bits */
85#define RISC_WR_SOL (1 << 27)
86#define RISC_WR_EOL (1 << 26)
87#define RISC_IRQ (1 << 24)
88#define RISC_SYNC_RESYNC (1 << 15)
89#define RISC_SYNC_FM1 0x06
90#define RISC_SYNC_VRO 0x0c
91
92#define HWBASE_AD (448000)
93
94/* -------------------------------------------------------------- */
95
96struct btaudio {
97 /* linked list */
98 struct btaudio *next;
99
100 /* device info */
101 int dsp_digital;
102 int dsp_analog;
103 int mixer_dev;
104 struct pci_dev *pci;
105 unsigned int irq;
106 unsigned long mem;
107 unsigned long __iomem *mmio;
108
109 /* locking */
110 int users;
111 struct semaphore lock;
112
113 /* risc instructions */
114 unsigned int risc_size;
115 unsigned long *risc_cpu;
116 dma_addr_t risc_dma;
117
118 /* audio data */
119 unsigned int buf_size;
120 unsigned char *buf_cpu;
121 dma_addr_t buf_dma;
122
123 /* buffer setup */
124 int line_bytes;
125 int line_count;
126 int block_bytes;
127 int block_count;
128
129 /* read fifo management */
130 int recording;
131 int dma_block;
132 int read_offset;
133 int read_count;
134 wait_queue_head_t readq;
135
136 /* settings */
137 int gain[3];
138 int source;
139 int bits;
140 int decimation;
141 int mixcount;
142 int sampleshift;
143 int channels;
144 int analog;
145 int rate;
146};
147
148struct cardinfo {
149 char *name;
150 int rate;
151};
152
153static struct btaudio *btaudios;
154static unsigned int debug;
155static unsigned int irq_debug;
156
157/* -------------------------------------------------------------- */
158
159#define BUF_DEFAULT 128*1024
160#define BUF_MIN 8192
161
162static int alloc_buffer(struct btaudio *bta)
163{
164 if (NULL == bta->buf_cpu) {
165 for (bta->buf_size = BUF_DEFAULT; bta->buf_size >= BUF_MIN;
166 bta->buf_size = bta->buf_size >> 1) {
167 bta->buf_cpu = pci_alloc_consistent
168 (bta->pci, bta->buf_size, &bta->buf_dma);
169 if (NULL != bta->buf_cpu)
170 break;
171 }
172 if (NULL == bta->buf_cpu)
173 return -ENOMEM;
174 memset(bta->buf_cpu,0,bta->buf_size);
175 }
176 if (NULL == bta->risc_cpu) {
177 bta->risc_size = PAGE_SIZE;
178 bta->risc_cpu = pci_alloc_consistent
179 (bta->pci, bta->risc_size, &bta->risc_dma);
180 if (NULL == bta->risc_cpu) {
181 pci_free_consistent(bta->pci, bta->buf_size, bta->buf_cpu, bta->buf_dma);
182 bta->buf_cpu = NULL;
183 return -ENOMEM;
184 }
185 }
186 return 0;
187}
188
189static void free_buffer(struct btaudio *bta)
190{
191 if (NULL != bta->buf_cpu) {
192 pci_free_consistent(bta->pci, bta->buf_size,
193 bta->buf_cpu, bta->buf_dma);
194 bta->buf_cpu = NULL;
195 }
196 if (NULL != bta->risc_cpu) {
197 pci_free_consistent(bta->pci, bta->risc_size,
198 bta->risc_cpu, bta->risc_dma);
199 bta->risc_cpu = NULL;
200 }
201}
202
203static int make_risc(struct btaudio *bta)
204{
205 int rp, bp, line, block;
206 unsigned long risc;
207
208 bta->block_bytes = bta->buf_size >> 4;
209 bta->block_count = 1 << 4;
210 bta->line_bytes = bta->block_bytes;
211 bta->line_count = bta->block_count;
212 while (bta->line_bytes > 4095) {
213 bta->line_bytes >>= 1;
214 bta->line_count <<= 1;
215 }
216 if (bta->line_count > 255)
217 return -EINVAL;
218 if (debug)
219 printk(KERN_DEBUG
220 "btaudio: bufsize=%d - bs=%d bc=%d - ls=%d, lc=%d\n",
221 bta->buf_size,bta->block_bytes,bta->block_count,
222 bta->line_bytes,bta->line_count);
223 rp = 0; bp = 0;
224 block = 0;
225 bta->risc_cpu[rp++] = cpu_to_le32(RISC_SYNC|RISC_SYNC_FM1);
226 bta->risc_cpu[rp++] = cpu_to_le32(0);
227 for (line = 0; line < bta->line_count; line++) {
228 risc = RISC_WRITE | RISC_WR_SOL | RISC_WR_EOL;
229 risc |= bta->line_bytes;
230 if (0 == (bp & (bta->block_bytes-1))) {
231 risc |= RISC_IRQ;
232 risc |= (block & 0x0f) << 16;
233 risc |= (~block & 0x0f) << 20;
234 block++;
235 }
236 bta->risc_cpu[rp++] = cpu_to_le32(risc);
237 bta->risc_cpu[rp++] = cpu_to_le32(bta->buf_dma + bp);
238 bp += bta->line_bytes;
239 }
240 bta->risc_cpu[rp++] = cpu_to_le32(RISC_SYNC|RISC_SYNC_VRO);
241 bta->risc_cpu[rp++] = cpu_to_le32(0);
242 bta->risc_cpu[rp++] = cpu_to_le32(RISC_JUMP);
243 bta->risc_cpu[rp++] = cpu_to_le32(bta->risc_dma);
244 return 0;
245}
246
247static int start_recording(struct btaudio *bta)
248{
249 int ret;
250
251 if (0 != (ret = alloc_buffer(bta)))
252 return ret;
253 if (0 != (ret = make_risc(bta)))
254 return ret;
255
256 btwrite(bta->risc_dma, REG_RISC_STRT_ADD);
257 btwrite((bta->line_count << 16) | bta->line_bytes,
258 REG_PACKET_LEN);
259 btwrite(IRQ_BTAUDIO, REG_INT_MASK);
260 if (bta->analog) {
261 btwrite(DMA_CTL_ACAP_EN |
262 DMA_CTL_RISC_EN |
263 DMA_CTL_FIFO_EN |
264 DMA_CTL_DA_ES2 |
265 ((bta->bits == 8) ? DMA_CTL_DA_SBR : 0) |
266 (bta->gain[bta->source] << 28) |
267 (bta->source << 24) |
268 (bta->decimation << 8),
269 REG_GPIO_DMA_CTL);
270 } else {
271 btwrite(DMA_CTL_ACAP_EN |
272 DMA_CTL_RISC_EN |
273 DMA_CTL_FIFO_EN |
274 DMA_CTL_DA_ES2 |
275 DMA_CTL_A_PWRDN |
276 (1 << 6) |
277 ((bta->bits == 8) ? DMA_CTL_DA_SBR : 0) |
278 (bta->gain[bta->source] << 28) |
279 (bta->source << 24) |
280 (bta->decimation << 8),
281 REG_GPIO_DMA_CTL);
282 }
283 bta->dma_block = 0;
284 bta->read_offset = 0;
285 bta->read_count = 0;
286 bta->recording = 1;
287 if (debug)
288 printk(KERN_DEBUG "btaudio: recording started\n");
289 return 0;
290}
291
292static void stop_recording(struct btaudio *bta)
293{
294 btand(~15, REG_GPIO_DMA_CTL);
295 bta->recording = 0;
296 if (debug)
297 printk(KERN_DEBUG "btaudio: recording stopped\n");
298}
299
300
301/* -------------------------------------------------------------- */
302
303static int btaudio_mixer_open(struct inode *inode, struct file *file)
304{
305 int minor = iminor(inode);
306 struct btaudio *bta;
307
308 for (bta = btaudios; bta != NULL; bta = bta->next)
309 if (bta->mixer_dev == minor)
310 break;
311 if (NULL == bta)
312 return -ENODEV;
313
314 if (debug)
315 printk("btaudio: open mixer [%d]\n",minor);
316 file->private_data = bta;
317 return 0;
318}
319
320static int btaudio_mixer_release(struct inode *inode, struct file *file)
321{
322 return 0;
323}
324
325static int btaudio_mixer_ioctl(struct inode *inode, struct file *file,
326 unsigned int cmd, unsigned long arg)
327{
328 struct btaudio *bta = file->private_data;
329 int ret,val=0,i=0;
330 void __user *argp = (void __user *)arg;
331
332 if (cmd == SOUND_MIXER_INFO) {
333 mixer_info info;
334 memset(&info,0,sizeof(info));
335 strlcpy(info.id,"bt878",sizeof(info.id));
336 strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name));
337 info.modify_counter = bta->mixcount;
338 if (copy_to_user(argp, &info, sizeof(info)))
339 return -EFAULT;
340 return 0;
341 }
342 if (cmd == SOUND_OLD_MIXER_INFO) {
343 _old_mixer_info info;
344 memset(&info,0,sizeof(info));
345 strlcpy(info.id,"bt878",sizeof(info.id)-1);
346 strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name));
347 if (copy_to_user(argp, &info, sizeof(info)))
348 return -EFAULT;
349 return 0;
350 }
351 if (cmd == OSS_GETVERSION)
352 return put_user(SOUND_VERSION, (int __user *)argp);
353
354 /* read */
355 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
356 if (get_user(val, (int __user *)argp))
357 return -EFAULT;
358
359 switch (cmd) {
360 case MIXER_READ(SOUND_MIXER_CAPS):
361 ret = SOUND_CAP_EXCL_INPUT;
362 break;
363 case MIXER_READ(SOUND_MIXER_STEREODEVS):
364 ret = 0;
365 break;
366 case MIXER_READ(SOUND_MIXER_RECMASK):
367 case MIXER_READ(SOUND_MIXER_DEVMASK):
368 ret = SOUND_MASK_LINE1|SOUND_MASK_LINE2|SOUND_MASK_LINE3;
369 break;
370
371 case MIXER_WRITE(SOUND_MIXER_RECSRC):
372 if (val & SOUND_MASK_LINE1 && bta->source != 0)
373 bta->source = 0;
374 else if (val & SOUND_MASK_LINE2 && bta->source != 1)
375 bta->source = 1;
376 else if (val & SOUND_MASK_LINE3 && bta->source != 2)
377 bta->source = 2;
378 btaor((bta->gain[bta->source] << 28) |
379 (bta->source << 24),
380 0x0cffffff, REG_GPIO_DMA_CTL);
381 case MIXER_READ(SOUND_MIXER_RECSRC):
382 switch (bta->source) {
383 case 0: ret = SOUND_MASK_LINE1; break;
384 case 1: ret = SOUND_MASK_LINE2; break;
385 case 2: ret = SOUND_MASK_LINE3; break;
386 default: ret = 0;
387 }
388 break;
389
390 case MIXER_WRITE(SOUND_MIXER_LINE1):
391 case MIXER_WRITE(SOUND_MIXER_LINE2):
392 case MIXER_WRITE(SOUND_MIXER_LINE3):
393 if (MIXER_WRITE(SOUND_MIXER_LINE1) == cmd)
394 i = 0;
395 if (MIXER_WRITE(SOUND_MIXER_LINE2) == cmd)
396 i = 1;
397 if (MIXER_WRITE(SOUND_MIXER_LINE3) == cmd)
398 i = 2;
399 bta->gain[i] = (val & 0xff) * 15 / 100;
400 if (bta->gain[i] > 15) bta->gain[i] = 15;
401 if (bta->gain[i] < 0) bta->gain[i] = 0;
402 if (i == bta->source)
403 btaor((bta->gain[bta->source]<<28),
404 0x0fffffff, REG_GPIO_DMA_CTL);
405 ret = bta->gain[i] * 100 / 15;
406 ret |= ret << 8;
407 break;
408
409 case MIXER_READ(SOUND_MIXER_LINE1):
410 case MIXER_READ(SOUND_MIXER_LINE2):
411 case MIXER_READ(SOUND_MIXER_LINE3):
412 if (MIXER_READ(SOUND_MIXER_LINE1) == cmd)
413 i = 0;
414 if (MIXER_READ(SOUND_MIXER_LINE2) == cmd)
415 i = 1;
416 if (MIXER_READ(SOUND_MIXER_LINE3) == cmd)
417 i = 2;
418 ret = bta->gain[i] * 100 / 15;
419 ret |= ret << 8;
420 break;
421
422 default:
423 return -EINVAL;
424 }
425 if (put_user(ret, (int __user *)argp))
426 return -EFAULT;
427 return 0;
428}
429
430static struct file_operations btaudio_mixer_fops = {
431 .owner = THIS_MODULE,
432 .llseek = no_llseek,
433 .open = btaudio_mixer_open,
434 .release = btaudio_mixer_release,
435 .ioctl = btaudio_mixer_ioctl,
436};
437
438/* -------------------------------------------------------------- */
439
440static int btaudio_dsp_open(struct inode *inode, struct file *file,
441 struct btaudio *bta, int analog)
442{
443 down(&bta->lock);
444 if (bta->users)
445 goto busy;
446 bta->users++;
447 file->private_data = bta;
448
449 bta->analog = analog;
450 bta->dma_block = 0;
451 bta->read_offset = 0;
452 bta->read_count = 0;
453 bta->sampleshift = 0;
454
455 up(&bta->lock);
456 return 0;
457
458 busy:
459 up(&bta->lock);
460 return -EBUSY;
461}
462
463static int btaudio_dsp_open_digital(struct inode *inode, struct file *file)
464{
465 int minor = iminor(inode);
466 struct btaudio *bta;
467
468 for (bta = btaudios; bta != NULL; bta = bta->next)
469 if (bta->dsp_digital == minor)
470 break;
471 if (NULL == bta)
472 return -ENODEV;
473
474 if (debug)
475 printk("btaudio: open digital dsp [%d]\n",minor);
476 return btaudio_dsp_open(inode,file,bta,0);
477}
478
479static int btaudio_dsp_open_analog(struct inode *inode, struct file *file)
480{
481 int minor = iminor(inode);
482 struct btaudio *bta;
483
484 for (bta = btaudios; bta != NULL; bta = bta->next)
485 if (bta->dsp_analog == minor)
486 break;
487 if (NULL == bta)
488 return -ENODEV;
489
490 if (debug)
491 printk("btaudio: open analog dsp [%d]\n",minor);
492 return btaudio_dsp_open(inode,file,bta,1);
493}
494
495static int btaudio_dsp_release(struct inode *inode, struct file *file)
496{
497 struct btaudio *bta = file->private_data;
498
499 down(&bta->lock);
500 if (bta->recording)
501 stop_recording(bta);
502 bta->users--;
503 up(&bta->lock);
504 return 0;
505}
506
507static ssize_t btaudio_dsp_read(struct file *file, char __user *buffer,
508 size_t swcount, loff_t *ppos)
509{
510 struct btaudio *bta = file->private_data;
511 int hwcount = swcount << bta->sampleshift;
512 int nsrc, ndst, err, ret = 0;
513 DECLARE_WAITQUEUE(wait, current);
514
515 add_wait_queue(&bta->readq, &wait);
516 down(&bta->lock);
517 while (swcount > 0) {
518 if (0 == bta->read_count) {
519 if (!bta->recording) {
520 if (0 != (err = start_recording(bta))) {
521 if (0 == ret)
522 ret = err;
523 break;
524 }
525 }
526 if (file->f_flags & O_NONBLOCK) {
527 if (0 == ret)
528 ret = -EAGAIN;
529 break;
530 }
531 up(&bta->lock);
532 current->state = TASK_INTERRUPTIBLE;
533 schedule();
534 down(&bta->lock);
535 if(signal_pending(current)) {
536 if (0 == ret)
537 ret = -EINTR;
538 break;
539 }
540 }
541 nsrc = (bta->read_count < hwcount) ? bta->read_count : hwcount;
542 if (nsrc > bta->buf_size - bta->read_offset)
543 nsrc = bta->buf_size - bta->read_offset;
544 ndst = nsrc >> bta->sampleshift;
545
546 if ((bta->analog && 0 == bta->sampleshift) ||
547 (!bta->analog && 2 == bta->channels)) {
548 /* just copy */
549 if (copy_to_user(buffer + ret, bta->buf_cpu + bta->read_offset, nsrc)) {
550 if (0 == ret)
551 ret = -EFAULT;
552 break;
553 }
554
555 } else if (!bta->analog) {
556 /* stereo => mono (digital audio) */
557 __s16 *src = (__s16*)(bta->buf_cpu + bta->read_offset);
558 __s16 __user *dst = (__s16 __user *)(buffer + ret);
559 __s16 avg;
560 int n = ndst>>1;
561 if (!access_ok(VERIFY_WRITE, dst, ndst)) {
562 if (0 == ret)
563 ret = -EFAULT;
564 break;
565 }
566 for (; n; n--, dst++) {
567 avg = (__s16)le16_to_cpu(*src) / 2; src++;
568 avg += (__s16)le16_to_cpu(*src) / 2; src++;
569 __put_user(cpu_to_le16(avg),dst);
570 }
571
572 } else if (8 == bta->bits) {
573 /* copy + byte downsampling (audio A/D) */
574 __u8 *src = bta->buf_cpu + bta->read_offset;
575 __u8 __user *dst = buffer + ret;
576 int n = ndst;
577 if (!access_ok(VERIFY_WRITE, dst, ndst)) {
578 if (0 == ret)
579 ret = -EFAULT;
580 break;
581 }
582 for (; n; n--, src += (1 << bta->sampleshift), dst++)
583 __put_user(*src, dst);
584
585 } else {
586 /* copy + word downsampling (audio A/D) */
587 __u16 *src = (__u16*)(bta->buf_cpu + bta->read_offset);
588 __u16 __user *dst = (__u16 __user *)(buffer + ret);
589 int n = ndst>>1;
590 if (!access_ok(VERIFY_WRITE,dst,ndst)) {
591 if (0 == ret)
592 ret = -EFAULT;
593 break;
594 }
595 for (; n; n--, src += (1 << bta->sampleshift), dst++)
596 __put_user(*src, dst);
597 }
598
599 ret += ndst;
600 swcount -= ndst;
601 hwcount -= nsrc;
602 bta->read_count -= nsrc;
603 bta->read_offset += nsrc;
604 if (bta->read_offset == bta->buf_size)
605 bta->read_offset = 0;
606 }
607 up(&bta->lock);
608 remove_wait_queue(&bta->readq, &wait);
609 current->state = TASK_RUNNING;
610 return ret;
611}
612
613static ssize_t btaudio_dsp_write(struct file *file, const char __user *buffer,
614 size_t count, loff_t *ppos)
615{
616 return -EINVAL;
617}
618
619static int btaudio_dsp_ioctl(struct inode *inode, struct file *file,
620 unsigned int cmd, unsigned long arg)
621{
622 struct btaudio *bta = file->private_data;
623 int s, i, ret, val = 0;
624 void __user *argp = (void __user *)arg;
625 int __user *p = argp;
626
627 switch (cmd) {
628 case OSS_GETVERSION:
629 return put_user(SOUND_VERSION, p);
630 case SNDCTL_DSP_GETCAPS:
631 return 0;
632
633 case SNDCTL_DSP_SPEED:
634 if (get_user(val, p))
635 return -EFAULT;
636 if (bta->analog) {
637 for (s = 0; s < 16; s++)
638 if (val << s >= HWBASE_AD*4/15)
639 break;
640 for (i = 15; i >= 5; i--)
641 if (val << s <= HWBASE_AD*4/i)
642 break;
643 bta->sampleshift = s;
644 bta->decimation = i;
645 if (debug)
646 printk(KERN_DEBUG "btaudio: rate: req=%d "
647 "dec=%d shift=%d hwrate=%d swrate=%d\n",
648 val,i,s,(HWBASE_AD*4/i),(HWBASE_AD*4/i)>>s);
649 } else {
650 bta->sampleshift = (bta->channels == 2) ? 0 : 1;
651 bta->decimation = 0;
652 }
653 if (bta->recording) {
654 down(&bta->lock);
655 stop_recording(bta);
656 start_recording(bta);
657 up(&bta->lock);
658 }
659 /* fall through */
660 case SOUND_PCM_READ_RATE:
661 if (bta->analog) {
662 return put_user(HWBASE_AD*4/bta->decimation>>bta->sampleshift, p);
663 } else {
664 return put_user(bta->rate, p);
665 }
666
667 case SNDCTL_DSP_STEREO:
668 if (!bta->analog) {
669 if (get_user(val, p))
670 return -EFAULT;
671 bta->channels = (val > 0) ? 2 : 1;
672 bta->sampleshift = (bta->channels == 2) ? 0 : 1;
673 if (debug)
674 printk(KERN_INFO
675 "btaudio: stereo=%d channels=%d\n",
676 val,bta->channels);
677 } else {
678 if (val == 1)
679 return -EFAULT;
680 else {
681 bta->channels = 1;
682 if (debug)
683 printk(KERN_INFO
684 "btaudio: stereo=0 channels=1\n");
685 }
686 }
687 return put_user((bta->channels)-1, p);
688
689 case SNDCTL_DSP_CHANNELS:
690 if (!bta->analog) {
691 if (get_user(val, p))
692 return -EFAULT;
693 bta->channels = (val > 1) ? 2 : 1;
694 bta->sampleshift = (bta->channels == 2) ? 0 : 1;
695 if (debug)
696 printk(KERN_DEBUG
697 "btaudio: val=%d channels=%d\n",
698 val,bta->channels);
699 }
700 /* fall through */
701 case SOUND_PCM_READ_CHANNELS:
702 return put_user(bta->channels, p);
703
704 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
705 if (bta->analog)
706 return put_user(AFMT_S16_LE|AFMT_S8, p);
707 else
708 return put_user(AFMT_S16_LE, p);
709
710 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
711 if (get_user(val, p))
712 return -EFAULT;
713 if (val != AFMT_QUERY) {
714 if (bta->analog)
715 bta->bits = (val == AFMT_S8) ? 8 : 16;
716 else
717 bta->bits = 16;
718 if (bta->recording) {
719 down(&bta->lock);
720 stop_recording(bta);
721 start_recording(bta);
722 up(&bta->lock);
723 }
724 }
725 if (debug)
726 printk(KERN_DEBUG "btaudio: fmt: bits=%d\n",bta->bits);
727 return put_user((bta->bits==16) ? AFMT_S16_LE : AFMT_S8,
728 p);
729 break;
730 case SOUND_PCM_READ_BITS:
731 return put_user(bta->bits, p);
732
733 case SNDCTL_DSP_NONBLOCK:
734 file->f_flags |= O_NONBLOCK;
735 return 0;
736
737 case SNDCTL_DSP_RESET:
738 if (bta->recording) {
739 down(&bta->lock);
740 stop_recording(bta);
741 up(&bta->lock);
742 }
743 return 0;
744 case SNDCTL_DSP_GETBLKSIZE:
745 if (!bta->recording) {
746 if (0 != (ret = alloc_buffer(bta)))
747 return ret;
748 if (0 != (ret = make_risc(bta)))
749 return ret;
750 }
751 return put_user(bta->block_bytes>>bta->sampleshift,p);
752
753 case SNDCTL_DSP_SYNC:
754 /* NOP */
755 return 0;
756 case SNDCTL_DSP_GETISPACE:
757 {
758 audio_buf_info info;
759 if (!bta->recording)
760 return -EINVAL;
761 info.fragsize = bta->block_bytes>>bta->sampleshift;
762 info.fragstotal = bta->block_count;
763 info.bytes = bta->read_count;
764 info.fragments = info.bytes / info.fragsize;
765 if (debug)
766 printk(KERN_DEBUG "btaudio: SNDCTL_DSP_GETISPACE "
767 "returns %d/%d/%d/%d\n",
768 info.fragsize, info.fragstotal,
769 info.bytes, info.fragments);
770 if (copy_to_user(argp, &info, sizeof(info)))
771 return -EFAULT;
772 return 0;
773 }
774#if 0 /* TODO */
775 case SNDCTL_DSP_GETTRIGGER:
776 case SNDCTL_DSP_SETTRIGGER:
777 case SNDCTL_DSP_SETFRAGMENT:
778#endif
779 default:
780 return -EINVAL;
781 }
782}
783
784static unsigned int btaudio_dsp_poll(struct file *file, struct poll_table_struct *wait)
785{
786 struct btaudio *bta = file->private_data;
787 unsigned int mask = 0;
788
789 poll_wait(file, &bta->readq, wait);
790
791 if (0 != bta->read_count)
792 mask |= (POLLIN | POLLRDNORM);
793
794 return mask;
795}
796
797static struct file_operations btaudio_digital_dsp_fops = {
798 .owner = THIS_MODULE,
799 .llseek = no_llseek,
800 .open = btaudio_dsp_open_digital,
801 .release = btaudio_dsp_release,
802 .read = btaudio_dsp_read,
803 .write = btaudio_dsp_write,
804 .ioctl = btaudio_dsp_ioctl,
805 .poll = btaudio_dsp_poll,
806};
807
808static struct file_operations btaudio_analog_dsp_fops = {
809 .owner = THIS_MODULE,
810 .llseek = no_llseek,
811 .open = btaudio_dsp_open_analog,
812 .release = btaudio_dsp_release,
813 .read = btaudio_dsp_read,
814 .write = btaudio_dsp_write,
815 .ioctl = btaudio_dsp_ioctl,
816 .poll = btaudio_dsp_poll,
817};
818
819/* -------------------------------------------------------------- */
820
821static char *irq_name[] = { "", "", "", "OFLOW", "", "", "", "", "", "", "",
822 "RISCI", "FBUS", "FTRGT", "FDSR", "PPERR",
823 "RIPERR", "PABORT", "OCERR", "SCERR" };
824
825static irqreturn_t btaudio_irq(int irq, void *dev_id, struct pt_regs * regs)
826{
827 int count = 0;
828 u32 stat,astat;
829 struct btaudio *bta = dev_id;
830 int handled = 0;
831
832 for (;;) {
833 count++;
834 stat = btread(REG_INT_STAT);
835 astat = stat & btread(REG_INT_MASK);
836 if (!astat)
837 return IRQ_RETVAL(handled);
838 handled = 1;
839 btwrite(astat,REG_INT_STAT);
840
841 if (irq_debug) {
842 int i;
843 printk(KERN_DEBUG "btaudio: irq loop=%d risc=%x, bits:",
844 count, stat>>28);
845 for (i = 0; i < (sizeof(irq_name)/sizeof(char*)); i++) {
846 if (stat & (1 << i))
847 printk(" %s",irq_name[i]);
848 if (astat & (1 << i))
849 printk("*");
850 }
851 printk("\n");
852 }
853 if (stat & IRQ_RISCI) {
854 int blocks;
855 blocks = (stat >> 28) - bta->dma_block;
856 if (blocks < 0)
857 blocks += bta->block_count;
858 bta->dma_block = stat >> 28;
859 if (bta->read_count + 2*bta->block_bytes > bta->buf_size) {
860 stop_recording(bta);
861 printk(KERN_INFO "btaudio: buffer overrun\n");
862 }
863 if (blocks > 0) {
864 bta->read_count += blocks * bta->block_bytes;
865 wake_up_interruptible(&bta->readq);
866 }
867 }
868 if (count > 10) {
869 printk(KERN_WARNING
870 "btaudio: Oops - irq mask cleared\n");
871 btwrite(0, REG_INT_MASK);
872 }
873 }
874 return IRQ_NONE;
875}
876
877/* -------------------------------------------------------------- */
878
879static unsigned int dsp1 = -1;
880static unsigned int dsp2 = -1;
881static unsigned int mixer = -1;
882static int latency = -1;
883static int digital = 1;
884static int analog = 1;
885static int rate;
886
887#define BTA_OSPREY200 1
888
889static struct cardinfo cards[] = {
890 [0] = {
891 .name = "default",
892 .rate = 32000,
893 },
894 [BTA_OSPREY200] = {
895 .name = "Osprey 200",
896 .rate = 44100,
897 },
898};
899
900static int __devinit btaudio_probe(struct pci_dev *pci_dev,
901 const struct pci_device_id *pci_id)
902{
903 struct btaudio *bta;
904 struct cardinfo *card = &cards[pci_id->driver_data];
905 unsigned char revision,lat;
906 int rc = -EBUSY;
907
908 if (pci_enable_device(pci_dev))
909 return -EIO;
910 if (!request_mem_region(pci_resource_start(pci_dev,0),
911 pci_resource_len(pci_dev,0),
912 "btaudio")) {
913 return -EBUSY;
914 }
915
916 bta = kmalloc(sizeof(*bta),GFP_ATOMIC);
917 if (!bta) {
918 rc = -ENOMEM;
919 goto fail0;
920 }
921 memset(bta,0,sizeof(*bta));
922
923 bta->pci = pci_dev;
924 bta->irq = pci_dev->irq;
925 bta->mem = pci_resource_start(pci_dev,0);
926 bta->mmio = ioremap(pci_resource_start(pci_dev,0),
927 pci_resource_len(pci_dev,0));
928
929 bta->source = 1;
930 bta->bits = 8;
931 bta->channels = 1;
932 if (bta->analog) {
933 bta->decimation = 15;
934 } else {
935 bta->decimation = 0;
936 bta->sampleshift = 1;
937 }
938
939 /* sample rate */
940 bta->rate = card->rate;
941 if (rate)
942 bta->rate = rate;
943
944 init_MUTEX(&bta->lock);
945 init_waitqueue_head(&bta->readq);
946
947 if (-1 != latency) {
948 printk(KERN_INFO "btaudio: setting pci latency timer to %d\n",
949 latency);
950 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
951 }
952 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &revision);
953 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &lat);
954 printk(KERN_INFO "btaudio: Bt%x (rev %d) at %02x:%02x.%x, ",
955 pci_dev->device,revision,pci_dev->bus->number,
956 PCI_SLOT(pci_dev->devfn),PCI_FUNC(pci_dev->devfn));
957 printk("irq: %d, latency: %d, mmio: 0x%lx\n",
958 bta->irq, lat, bta->mem);
959 printk("btaudio: using card config \"%s\"\n", card->name);
960
961 /* init hw */
962 btwrite(0, REG_GPIO_DMA_CTL);
963 btwrite(0, REG_INT_MASK);
964 btwrite(~0U, REG_INT_STAT);
965 pci_set_master(pci_dev);
966
967 if ((rc = request_irq(bta->irq, btaudio_irq, SA_SHIRQ|SA_INTERRUPT,
968 "btaudio",(void *)bta)) < 0) {
969 printk(KERN_WARNING
970 "btaudio: can't request irq (rc=%d)\n",rc);
971 goto fail1;
972 }
973
974 /* register devices */
975 if (digital) {
976 rc = bta->dsp_digital =
977 register_sound_dsp(&btaudio_digital_dsp_fops,dsp1);
978 if (rc < 0) {
979 printk(KERN_WARNING
980 "btaudio: can't register digital dsp (rc=%d)\n",rc);
981 goto fail2;
982 }
983 printk(KERN_INFO "btaudio: registered device dsp%d [digital]\n",
984 bta->dsp_digital >> 4);
985 }
986 if (analog) {
987 rc = bta->dsp_analog =
988 register_sound_dsp(&btaudio_analog_dsp_fops,dsp2);
989 if (rc < 0) {
990 printk(KERN_WARNING
991 "btaudio: can't register analog dsp (rc=%d)\n",rc);
992 goto fail3;
993 }
994 printk(KERN_INFO "btaudio: registered device dsp%d [analog]\n",
995 bta->dsp_analog >> 4);
996 rc = bta->mixer_dev = register_sound_mixer(&btaudio_mixer_fops,mixer);
997 if (rc < 0) {
998 printk(KERN_WARNING
999 "btaudio: can't register mixer (rc=%d)\n",rc);
1000 goto fail4;
1001 }
1002 printk(KERN_INFO "btaudio: registered device mixer%d\n",
1003 bta->mixer_dev >> 4);
1004 }
1005
1006 /* hook into linked list */
1007 bta->next = btaudios;
1008 btaudios = bta;
1009
1010 pci_set_drvdata(pci_dev,bta);
1011 return 0;
1012
1013 fail4:
1014 unregister_sound_dsp(bta->dsp_analog);
1015 fail3:
1016 if (digital)
1017 unregister_sound_dsp(bta->dsp_digital);
1018 fail2:
1019 free_irq(bta->irq,bta);
1020 fail1:
1021 kfree(bta);
1022 fail0:
1023 release_mem_region(pci_resource_start(pci_dev,0),
1024 pci_resource_len(pci_dev,0));
1025 return rc;
1026}
1027
1028static void __devexit btaudio_remove(struct pci_dev *pci_dev)
1029{
1030 struct btaudio *bta = pci_get_drvdata(pci_dev);
1031 struct btaudio *walk;
1032
1033 /* turn off all DMA / IRQs */
1034 btand(~15, REG_GPIO_DMA_CTL);
1035 btwrite(0, REG_INT_MASK);
1036 btwrite(~0U, REG_INT_STAT);
1037
1038 /* unregister devices */
1039 if (digital) {
1040 unregister_sound_dsp(bta->dsp_digital);
1041 }
1042 if (analog) {
1043 unregister_sound_dsp(bta->dsp_analog);
1044 unregister_sound_mixer(bta->mixer_dev);
1045 }
1046
1047 /* free resources */
1048 free_buffer(bta);
1049 free_irq(bta->irq,bta);
1050 release_mem_region(pci_resource_start(pci_dev,0),
1051 pci_resource_len(pci_dev,0));
1052
1053 /* remove from linked list */
1054 if (bta == btaudios) {
1055 btaudios = NULL;
1056 } else {
1057 for (walk = btaudios; walk->next != bta; walk = walk->next)
1058 ; /* if (NULL == walk->next) BUG(); */
1059 walk->next = bta->next;
1060 }
1061
1062 pci_set_drvdata(pci_dev, NULL);
1063 kfree(bta);
1064 return;
1065}
1066
1067/* -------------------------------------------------------------- */
1068
1069static struct pci_device_id btaudio_pci_tbl[] = {
1070 {
1071 .vendor = PCI_VENDOR_ID_BROOKTREE,
1072 .device = 0x0878,
1073 .subvendor = 0x0070,
1074 .subdevice = 0xff01,
1075 .driver_data = BTA_OSPREY200,
1076 },{
1077 .vendor = PCI_VENDOR_ID_BROOKTREE,
1078 .device = 0x0878,
1079 .subvendor = PCI_ANY_ID,
1080 .subdevice = PCI_ANY_ID,
1081 },{
1082 .vendor = PCI_VENDOR_ID_BROOKTREE,
1083 .device = 0x0878,
1084 .subvendor = PCI_ANY_ID,
1085 .subdevice = PCI_ANY_ID,
1086 },{
1087 /* --- end of list --- */
1088 }
1089};
1090
1091static struct pci_driver btaudio_pci_driver = {
1092 .name = "btaudio",
1093 .id_table = btaudio_pci_tbl,
1094 .probe = btaudio_probe,
1095 .remove = __devexit_p(btaudio_remove),
1096};
1097
1098static int btaudio_init_module(void)
1099{
1100 printk(KERN_INFO "btaudio: driver version 0.7 loaded [%s%s%s]\n",
1101 digital ? "digital" : "",
1102 analog && digital ? "+" : "",
1103 analog ? "analog" : "");
1104 return pci_module_init(&btaudio_pci_driver);
1105}
1106
1107static void btaudio_cleanup_module(void)
1108{
1109 pci_unregister_driver(&btaudio_pci_driver);
1110 return;
1111}
1112
1113module_init(btaudio_init_module);
1114module_exit(btaudio_cleanup_module);
1115
1116module_param(dsp1, int, S_IRUGO);
1117module_param(dsp2, int, S_IRUGO);
1118module_param(mixer, int, S_IRUGO);
1119module_param(debug, int, S_IRUGO | S_IWUSR);
1120module_param(irq_debug, int, S_IRUGO | S_IWUSR);
1121module_param(digital, int, S_IRUGO);
1122module_param(analog, int, S_IRUGO);
1123module_param(rate, int, S_IRUGO);
1124module_param(latency, int, S_IRUGO);
1125MODULE_PARM_DESC(latency,"pci latency timer");
1126
1127MODULE_DEVICE_TABLE(pci, btaudio_pci_tbl);
1128MODULE_DESCRIPTION("bt878 audio dma driver");
1129MODULE_AUTHOR("Gerd Knorr");
1130MODULE_LICENSE("GPL");
1131
1132/*
1133 * Local variables:
1134 * c-basic-offset: 8
1135 * End:
1136 */
diff --git a/sound/oss/cmpci.c b/sound/oss/cmpci.c
new file mode 100644
index 000000000000..34720e66dae1
--- /dev/null
+++ b/sound/oss/cmpci.c
@@ -0,0 +1,3378 @@
1/*
2 * cmpci.c -- C-Media PCI audio driver.
3 *
4 * Copyright (C) 1999 C-media support (support@cmedia.com.tw)
5 *
6 * Based on the PCI drivers by Thomas Sailer (sailer@ife.ee.ethz.ch)
7 *
8 * For update, visit:
9 * http://www.cmedia.com.tw
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * Special thanks to David C. Niemi, Jan Pfeifer
26 *
27 *
28 * Module command line parameters:
29 * none so far
30 *
31 *
32 * Supported devices:
33 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
34 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
35 * /dev/midi simple MIDI UART interface, no ioctl
36 *
37 * The card has both an FM and a Wavetable synth, but I have to figure
38 * out first how to drive them...
39 *
40 * Revision history
41 * 06.05.98 0.1 Initial release
42 * 10.05.98 0.2 Fixed many bugs, esp. ADC rate calculation
43 * First stab at a simple midi interface (no bells&whistles)
44 * 13.05.98 0.3 Fix stupid cut&paste error: set_adc_rate was called instead of
45 * set_dac_rate in the FMODE_WRITE case in cm_open
46 * Fix hwptr out of bounds (now mpg123 works)
47 * 14.05.98 0.4 Don't allow excessive interrupt rates
48 * 08.06.98 0.5 First release using Alan Cox' soundcore instead of miscdevice
49 * 03.08.98 0.6 Do not include modversions.h
50 * Now mixer behaviour can basically be selected between
51 * "OSS documented" and "OSS actual" behaviour
52 * 31.08.98 0.7 Fix realplayer problems - dac.count issues
53 * 10.12.98 0.8 Fix drain_dac trying to wait on not yet initialized DMA
54 * 16.12.98 0.9 Fix a few f_file & FMODE_ bugs
55 * 06.01.99 0.10 remove the silly SA_INTERRUPT flag.
56 * hopefully killed the egcs section type conflict
57 * 12.03.99 0.11 cinfo.blocks should be reset after GETxPTR ioctl.
58 * reported by Johan Maes <joma@telindus.be>
59 * 22.03.99 0.12 return EAGAIN instead of EBUSY when O_NONBLOCK
60 * read/write cannot be executed
61 * 18.08.99 1.5 Only deallocate DMA buffer when unloading.
62 * 02.09.99 1.6 Enable SPDIF LOOP
63 * Change the mixer read back
64 * 21.09.99 2.33 Use RCS version as driver version.
65 * Add support for modem, S/PDIF loop and 4 channels.
66 * (8738 only)
67 * Fix bug cause x11amp cannot play.
68 *
69 * Fixes:
70 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
71 * 18/05/2001 - .bss nitpicks, fix a bug in set_dac_channels where it
72 * was calling prog_dmabuf with s->lock held, call missing
73 * unlock_kernel in cm_midi_release
74 * 08/10/2001 - use set_current_state in some more places
75 *
76 * Carlos Eduardo Gorges <carlos@techlinux.com.br>
77 * Fri May 25 2001
78 * - SMP support ( spin[un]lock* revision )
79 * - speaker mixer support
80 * Mon Aug 13 2001
81 * - optimizations and cleanups
82 *
83 * 03/01/2003 - open_mode fixes from Georg Acher <acher@in.tum.de>
84 * Simon Braunschmidt <brasimon@web.de>
85 * Sat Jan 31 2004
86 * - provide support for opl3 FM by releasing IO range after initialization
87 *
88 * ChenLi Tien <cltien@cmedia.com.tw>
89 * Mar 9 2004
90 * - Fix S/PDIF out if spdif_loop enabled
91 * - Load opl3 driver if enabled (fmio in proper range)
92 * - Load mpu401 if enabled (mpuio in proper range)
93 * Apr 5 2004
94 * - Fix DUAL_DAC dma synchronization bug
95 * - Check exist FM/MPU401 I/O before activate.
96 * - Add AFTM_S16_BE format support, so MPlayer/Xine can play AC3/mutlichannel
97 * on Mac
98 * - Change to support kernel 2.6 so only small patch needed
99 * - All parameters default to 0
100 * - Add spdif_out to send PCM through S/PDIF out jack
101 * - Add hw_copy to get 4-spaker output for general PCM/analog output
102 *
103 * Stefan Thater <stefan.thaeter@gmx.de>
104 * Apr 5 2004
105 * - Fix mute single channel for CD/Line-in/AUX-in
106 */
107/*****************************************************************************/
108
109#include <linux/config.h>
110#include <linux/module.h>
111#include <linux/string.h>
112#include <linux/interrupt.h>
113#include <linux/ioport.h>
114#include <linux/sched.h>
115#include <linux/delay.h>
116#include <linux/sound.h>
117#include <linux/slab.h>
118#include <linux/soundcard.h>
119#include <linux/pci.h>
120#include <linux/init.h>
121#include <linux/poll.h>
122#include <linux/spinlock.h>
123#include <linux/smp_lock.h>
124#include <linux/bitops.h>
125#include <linux/wait.h>
126
127#include <asm/io.h>
128#include <asm/page.h>
129#include <asm/uaccess.h>
130
131#ifdef CONFIG_SOUND_CMPCI_MIDI
132#include "sound_config.h"
133#include "mpu401.h"
134#endif
135#ifdef CONFIG_SOUND_CMPCI_FM
136#include "opl3.h"
137#endif
138#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
139#include <linux/gameport.h>
140#endif
141
142/* --------------------------------------------------------------------- */
143#undef OSS_DOCUMENTED_MIXER_SEMANTICS
144#undef DMABYTEIO
145#define DBG(x) {}
146/* --------------------------------------------------------------------- */
147
148#define CM_MAGIC ((PCI_VENDOR_ID_CMEDIA<<16)|PCI_DEVICE_ID_CMEDIA_CM8338A)
149
150/* CM8338 registers definition ****************/
151
152#define CODEC_CMI_FUNCTRL0 (0x00)
153#define CODEC_CMI_FUNCTRL1 (0x04)
154#define CODEC_CMI_CHFORMAT (0x08)
155#define CODEC_CMI_INT_HLDCLR (0x0C)
156#define CODEC_CMI_INT_STATUS (0x10)
157#define CODEC_CMI_LEGACY_CTRL (0x14)
158#define CODEC_CMI_MISC_CTRL (0x18)
159#define CODEC_CMI_TDMA_POS (0x1C)
160#define CODEC_CMI_MIXER (0x20)
161#define CODEC_SB16_DATA (0x22)
162#define CODEC_SB16_ADDR (0x23)
163#define CODEC_CMI_MIXER1 (0x24)
164#define CODEC_CMI_MIXER2 (0x25)
165#define CODEC_CMI_AUX_VOL (0x26)
166#define CODEC_CMI_MISC (0x27)
167#define CODEC_CMI_AC97 (0x28)
168
169#define CODEC_CMI_CH0_FRAME1 (0x80)
170#define CODEC_CMI_CH0_FRAME2 (0x84)
171#define CODEC_CMI_CH1_FRAME1 (0x88)
172#define CODEC_CMI_CH1_FRAME2 (0x8C)
173
174#define CODEC_CMI_SPDIF_CTRL (0x90)
175#define CODEC_CMI_MISC_CTRL2 (0x92)
176
177#define CODEC_CMI_EXT_REG (0xF0)
178
179/* Mixer registers for SB16 ******************/
180
181#define DSP_MIX_DATARESETIDX ((unsigned char)(0x00))
182
183#define DSP_MIX_MASTERVOLIDX_L ((unsigned char)(0x30))
184#define DSP_MIX_MASTERVOLIDX_R ((unsigned char)(0x31))
185#define DSP_MIX_VOICEVOLIDX_L ((unsigned char)(0x32))
186#define DSP_MIX_VOICEVOLIDX_R ((unsigned char)(0x33))
187#define DSP_MIX_FMVOLIDX_L ((unsigned char)(0x34))
188#define DSP_MIX_FMVOLIDX_R ((unsigned char)(0x35))
189#define DSP_MIX_CDVOLIDX_L ((unsigned char)(0x36))
190#define DSP_MIX_CDVOLIDX_R ((unsigned char)(0x37))
191#define DSP_MIX_LINEVOLIDX_L ((unsigned char)(0x38))
192#define DSP_MIX_LINEVOLIDX_R ((unsigned char)(0x39))
193
194#define DSP_MIX_MICVOLIDX ((unsigned char)(0x3A))
195#define DSP_MIX_SPKRVOLIDX ((unsigned char)(0x3B))
196
197#define DSP_MIX_OUTMIXIDX ((unsigned char)(0x3C))
198
199#define DSP_MIX_ADCMIXIDX_L ((unsigned char)(0x3D))
200#define DSP_MIX_ADCMIXIDX_R ((unsigned char)(0x3E))
201
202#define DSP_MIX_INGAINIDX_L ((unsigned char)(0x3F))
203#define DSP_MIX_INGAINIDX_R ((unsigned char)(0x40))
204#define DSP_MIX_OUTGAINIDX_L ((unsigned char)(0x41))
205#define DSP_MIX_OUTGAINIDX_R ((unsigned char)(0x42))
206
207#define DSP_MIX_AGCIDX ((unsigned char)(0x43))
208
209#define DSP_MIX_TREBLEIDX_L ((unsigned char)(0x44))
210#define DSP_MIX_TREBLEIDX_R ((unsigned char)(0x45))
211#define DSP_MIX_BASSIDX_L ((unsigned char)(0x46))
212#define DSP_MIX_BASSIDX_R ((unsigned char)(0x47))
213#define DSP_MIX_EXTENSION ((unsigned char)(0xf0))
214// pseudo register for AUX
215#define DSP_MIX_AUXVOL_L ((unsigned char)(0x50))
216#define DSP_MIX_AUXVOL_R ((unsigned char)(0x51))
217
218// I/O length
219#define CM_EXTENT_CODEC 0x100
220#define CM_EXTENT_MIDI 0x2
221#define CM_EXTENT_SYNTH 0x4
222#define CM_EXTENT_GAME 0x8
223
224// Function Control Register 0 (00h)
225#define CHADC0 0x01
226#define CHADC1 0x02
227#define PAUSE0 0x04
228#define PAUSE1 0x08
229
230// Function Control Register 0+2 (02h)
231#define CHEN0 0x01
232#define CHEN1 0x02
233#define RST_CH0 0x04
234#define RST_CH1 0x08
235
236// Function Control Register 1 (04h)
237#define JYSTK_EN 0x02
238#define UART_EN 0x04
239#define SPDO2DAC 0x40
240#define SPDFLOOP 0x80
241
242// Function Control Register 1+1 (05h)
243#define SPDF_0 0x01
244#define SPDF_1 0x02
245#define ASFC 0x1c
246#define DSFC 0xe0
247#define SPDIF2DAC (SPDF_1 << 8 | SPDO2DAC)
248
249// Channel Format Register (08h)
250#define CM_CFMT_STEREO 0x01
251#define CM_CFMT_16BIT 0x02
252#define CM_CFMT_MASK 0x03
253#define POLVALID 0x20
254#define INVSPDIFI 0x80
255
256// Channel Format Register+2 (0ah)
257#define SPD24SEL 0x20
258
259// Channel Format Register+3 (0bh)
260#define CHB3D 0x20
261#define CHB3D5C 0x80
262
263// Interrupt Hold/Clear Register+2 (0eh)
264#define CH0_INT_EN 0x01
265#define CH1_INT_EN 0x02
266
267// Interrupt Register (10h)
268#define CHINT0 0x01
269#define CHINT1 0x02
270#define CH0BUSY 0x04
271#define CH1BUSY 0x08
272
273// Legacy Control/Status Register+1 (15h)
274#define EXBASEN 0x10
275#define BASE2LIN 0x20
276#define CENTR2LIN 0x40
277#define CB2LIN (BASE2LIN | CENTR2LIN)
278#define CHB3D6C 0x80
279
280// Legacy Control/Status Register+2 (16h)
281#define DAC2SPDO 0x20
282#define SPDCOPYRHT 0x40
283#define ENSPDOUT 0x80
284
285// Legacy Control/Status Register+3 (17h)
286#define FMSEL 0x03
287#define VSBSEL 0x0c
288#define VMPU 0x60
289#define NXCHG 0x80
290
291// Miscellaneous Control Register (18h)
292#define REAR2LIN 0x20
293#define MUTECH1 0x40
294#define ENCENTER 0x80
295
296// Miscellaneous Control Register+1 (19h)
297#define SELSPDIFI2 0x01
298#define SPDF_AC97 0x80
299
300// Miscellaneous Control Register+2 (1ah)
301#define AC3_EN 0x04
302#define FM_EN 0x08
303#define SPD32SEL 0x20
304#define XCHGDAC 0x40
305#define ENDBDAC 0x80
306
307// Miscellaneous Control Register+3 (1bh)
308#define SPDIFI48K 0x01
309#define SPDO5V 0x02
310#define N4SPK3D 0x04
311#define RESET 0x40
312#define PWD 0x80
313#define SPDIF48K (SPDIFI48K << 24 | SPDF_AC97 << 8)
314
315// Mixer1 (24h)
316#define CDPLAY 0x01
317#define X3DEN 0x02
318#define REAR2FRONT 0x10
319#define SPK4 0x20
320#define WSMUTE 0x40
321#define FMMUTE 0x80
322
323// Miscellaneous Register (27h)
324#define SPDVALID 0x02
325#define CENTR2MIC 0x04
326
327// Miscellaneous Register2 (92h)
328#define SPD32KFMT 0x10
329
330#define CM_CFMT_DACSHIFT 2
331#define CM_CFMT_ADCSHIFT 0
332#define CM_FREQ_DACSHIFT 5
333#define CM_FREQ_ADCSHIFT 2
334#define RSTDAC RST_CH1
335#define RSTADC RST_CH0
336#define ENDAC CHEN1
337#define ENADC CHEN0
338#define PAUSEDAC PAUSE1
339#define PAUSEADC PAUSE0
340#define CODEC_CMI_ADC_FRAME1 CODEC_CMI_CH0_FRAME1
341#define CODEC_CMI_ADC_FRAME2 CODEC_CMI_CH0_FRAME2
342#define CODEC_CMI_DAC_FRAME1 CODEC_CMI_CH1_FRAME1
343#define CODEC_CMI_DAC_FRAME2 CODEC_CMI_CH1_FRAME2
344#define DACINT CHINT1
345#define ADCINT CHINT0
346#define DACBUSY CH1BUSY
347#define ADCBUSY CH0BUSY
348#define ENDACINT CH1_INT_EN
349#define ENADCINT CH0_INT_EN
350
351static const unsigned sample_size[] = { 1, 2, 2, 4 };
352static const unsigned sample_shift[] = { 0, 1, 1, 2 };
353
354#define SND_DEV_DSP16 5
355
356#define NR_DEVICE 3 /* maximum number of devices */
357
358#define set_dac1_rate set_adc_rate
359#define set_dac1_rate_unlocked set_adc_rate_unlocked
360#define stop_dac1 stop_adc
361#define stop_dac1_unlocked stop_adc_unlocked
362#define get_dmadac1 get_dmaadc
363
364static unsigned int devindex = 0;
365
366//*********************************************/
367
368struct cm_state {
369 /* magic */
370 unsigned int magic;
371
372 /* list of cmedia devices */
373 struct list_head devs;
374
375 /* the corresponding pci_dev structure */
376 struct pci_dev *dev;
377
378 int dev_audio; /* soundcore stuff */
379 int dev_mixer;
380
381 unsigned int iosb, iobase, iosynth,
382 iomidi, iogame, irq; /* hardware resources */
383 unsigned short deviceid; /* pci_id */
384
385 struct { /* mixer stuff */
386 unsigned int modcnt;
387 unsigned short vol[13];
388 } mix;
389
390 unsigned int rateadc, ratedac; /* wave stuff */
391 unsigned char fmt, enable;
392
393 spinlock_t lock;
394 struct semaphore open_sem;
395 mode_t open_mode;
396 wait_queue_head_t open_wait;
397
398 struct dmabuf {
399 void *rawbuf;
400 dma_addr_t dmaaddr;
401 unsigned buforder;
402 unsigned numfrag;
403 unsigned fragshift;
404 unsigned hwptr, swptr;
405 unsigned total_bytes;
406 int count;
407 unsigned error; /* over/underrun */
408 wait_queue_head_t wait;
409
410 unsigned fragsize; /* redundant, but makes calculations easier */
411 unsigned dmasize;
412 unsigned fragsamples;
413 unsigned dmasamples;
414
415 unsigned mapped:1; /* OSS stuff */
416 unsigned ready:1;
417 unsigned endcleared:1;
418 unsigned enabled:1;
419 unsigned ossfragshift;
420 int ossmaxfrags;
421 unsigned subdivision;
422 } dma_dac, dma_adc;
423
424#ifdef CONFIG_SOUND_CMPCI_MIDI
425 int midi_devc;
426 struct address_info mpu_data;
427#endif
428#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
429 struct gameport *gameport;
430#endif
431
432 int chip_version;
433 int max_channels;
434 int curr_channels;
435 int capability; /* HW capability, various for chip versions */
436
437 int status; /* HW or SW state */
438
439 int spdif_counter; /* spdif frame counter */
440};
441
442/* flags used for capability */
443#define CAN_AC3_HW 0x00000001 /* 037 or later */
444#define CAN_AC3_SW 0x00000002 /* 033 or later */
445#define CAN_AC3 (CAN_AC3_HW | CAN_AC3_SW)
446#define CAN_DUAL_DAC 0x00000004 /* 033 or later */
447#define CAN_MULTI_CH_HW 0x00000008 /* 039 or later */
448#define CAN_MULTI_CH (CAN_MULTI_CH_HW | CAN_DUAL_DAC)
449#define CAN_LINE_AS_REAR 0x00000010 /* 033 or later */
450#define CAN_LINE_AS_BASS 0x00000020 /* 039 or later */
451#define CAN_MIC_AS_BASS 0x00000040 /* 039 or later */
452
453/* flags used for status */
454#define DO_AC3_HW 0x00000001
455#define DO_AC3_SW 0x00000002
456#define DO_AC3 (DO_AC3_HW | DO_AC3_SW)
457#define DO_DUAL_DAC 0x00000004
458#define DO_MULTI_CH_HW 0x00000008
459#define DO_MULTI_CH (DO_MULTI_CH_HW | DO_DUAL_DAC)
460#define DO_LINE_AS_REAR 0x00000010 /* 033 or later */
461#define DO_LINE_AS_BASS 0x00000020 /* 039 or later */
462#define DO_MIC_AS_BASS 0x00000040 /* 039 or later */
463#define DO_SPDIF_OUT 0x00000100
464#define DO_SPDIF_IN 0x00000200
465#define DO_SPDIF_LOOP 0x00000400
466#define DO_BIGENDIAN_W 0x00001000 /* used in PowerPC */
467#define DO_BIGENDIAN_R 0x00002000 /* used in PowerPC */
468
469static LIST_HEAD(devs);
470
471static int mpuio;
472static int fmio;
473static int joystick;
474static int spdif_inverse;
475static int spdif_loop;
476static int spdif_out;
477static int use_line_as_rear;
478static int use_line_as_bass;
479static int use_mic_as_bass;
480static int mic_boost;
481static int hw_copy;
482module_param(mpuio, int, 0);
483module_param(fmio, int, 0);
484module_param(joystick, bool, 0);
485module_param(spdif_inverse, bool, 0);
486module_param(spdif_loop, bool, 0);
487module_param(spdif_out, bool, 0);
488module_param(use_line_as_rear, bool, 0);
489module_param(use_line_as_bass, bool, 0);
490module_param(use_mic_as_bass, bool, 0);
491module_param(mic_boost, bool, 0);
492module_param(hw_copy, bool, 0);
493MODULE_PARM_DESC(mpuio, "(0x330, 0x320, 0x310, 0x300) Base of MPU-401, 0 to disable");
494MODULE_PARM_DESC(fmio, "(0x388, 0x3C8, 0x3E0) Base of OPL3, 0 to disable");
495MODULE_PARM_DESC(joystick, "(1/0) Enable joystick interface, still need joystick driver");
496MODULE_PARM_DESC(spdif_inverse, "(1/0) Invert S/PDIF-in signal");
497MODULE_PARM_DESC(spdif_loop, "(1/0) Route S/PDIF-in to S/PDIF-out directly");
498MODULE_PARM_DESC(spdif_out, "(1/0) Send PCM to S/PDIF-out (PCM volume will not function)");
499MODULE_PARM_DESC(use_line_as_rear, "(1/0) Use line-in jack as rear-out");
500MODULE_PARM_DESC(use_line_as_bass, "(1/0) Use line-in jack as bass/center");
501MODULE_PARM_DESC(use_mic_as_bass, "(1/0) Use mic-in jack as bass/center");
502MODULE_PARM_DESC(mic_boost, "(1/0) Enable microphone boost");
503MODULE_PARM_DESC(hw_copy, "Copy front channel to surround channel");
504
505/* --------------------------------------------------------------------- */
506
507static inline unsigned ld2(unsigned int x)
508{
509 unsigned exp=16,l=5,r=0;
510 static const unsigned num[]={0x2,0x4,0x10,0x100,0x10000};
511
512 /* num: 2, 4, 16, 256, 65536 */
513 /* exp: 1, 2, 4, 8, 16 */
514
515 while(l--) {
516 if( x >= num[l] ) {
517 if(num[l]>2) x >>= exp;
518 r+=exp;
519 }
520 exp>>=1;
521 }
522
523 return r;
524}
525
526/* --------------------------------------------------------------------- */
527
528static void maskb(unsigned int addr, unsigned int mask, unsigned int value)
529{
530 outb((inb(addr) & mask) | value, addr);
531}
532
533static void maskw(unsigned int addr, unsigned int mask, unsigned int value)
534{
535 outw((inw(addr) & mask) | value, addr);
536}
537
538static void maskl(unsigned int addr, unsigned int mask, unsigned int value)
539{
540 outl((inl(addr) & mask) | value, addr);
541}
542
543static void set_dmadac1(struct cm_state *s, unsigned int addr, unsigned int count)
544{
545 if (addr)
546 outl(addr, s->iobase + CODEC_CMI_ADC_FRAME1);
547 outw(count - 1, s->iobase + CODEC_CMI_ADC_FRAME2);
548 maskb(s->iobase + CODEC_CMI_FUNCTRL0, ~CHADC0, 0);
549}
550
551static void set_dmaadc(struct cm_state *s, unsigned int addr, unsigned int count)
552{
553 outl(addr, s->iobase + CODEC_CMI_ADC_FRAME1);
554 outw(count - 1, s->iobase + CODEC_CMI_ADC_FRAME2);
555 maskb(s->iobase + CODEC_CMI_FUNCTRL0, ~0, CHADC0);
556}
557
558static void set_dmadac(struct cm_state *s, unsigned int addr, unsigned int count)
559{
560 outl(addr, s->iobase + CODEC_CMI_DAC_FRAME1);
561 outw(count - 1, s->iobase + CODEC_CMI_DAC_FRAME2);
562 maskb(s->iobase + CODEC_CMI_FUNCTRL0, ~CHADC1, 0);
563 if (s->status & DO_DUAL_DAC)
564 set_dmadac1(s, 0, count);
565}
566
567static void set_countadc(struct cm_state *s, unsigned count)
568{
569 outw(count - 1, s->iobase + CODEC_CMI_ADC_FRAME2 + 2);
570}
571
572static void set_countdac(struct cm_state *s, unsigned count)
573{
574 outw(count - 1, s->iobase + CODEC_CMI_DAC_FRAME2 + 2);
575 if (s->status & DO_DUAL_DAC)
576 set_countadc(s, count);
577}
578
579static unsigned get_dmadac(struct cm_state *s)
580{
581 unsigned int curr_addr;
582
583 curr_addr = inw(s->iobase + CODEC_CMI_DAC_FRAME2) + 1;
584 curr_addr <<= sample_shift[(s->fmt >> CM_CFMT_DACSHIFT) & CM_CFMT_MASK];
585 curr_addr = s->dma_dac.dmasize - curr_addr;
586
587 return curr_addr;
588}
589
590static unsigned get_dmaadc(struct cm_state *s)
591{
592 unsigned int curr_addr;
593
594 curr_addr = inw(s->iobase + CODEC_CMI_ADC_FRAME2) + 1;
595 curr_addr <<= sample_shift[(s->fmt >> CM_CFMT_ADCSHIFT) & CM_CFMT_MASK];
596 curr_addr = s->dma_adc.dmasize - curr_addr;
597
598 return curr_addr;
599}
600
601static void wrmixer(struct cm_state *s, unsigned char idx, unsigned char data)
602{
603 unsigned char regval, pseudo;
604
605 // pseudo register
606 if (idx == DSP_MIX_AUXVOL_L) {
607 data >>= 4;
608 data &= 0x0f;
609 regval = inb(s->iobase + CODEC_CMI_AUX_VOL) & ~0x0f;
610 outb(regval | data, s->iobase + CODEC_CMI_AUX_VOL);
611 return;
612 }
613 if (idx == DSP_MIX_AUXVOL_R) {
614 data &= 0xf0;
615 regval = inb(s->iobase + CODEC_CMI_AUX_VOL) & ~0xf0;
616 outb(regval | data, s->iobase + CODEC_CMI_AUX_VOL);
617 return;
618 }
619 outb(idx, s->iobase + CODEC_SB16_ADDR);
620 udelay(10);
621 // pseudo bits
622 if (idx == DSP_MIX_OUTMIXIDX) {
623 pseudo = data & ~0x1f;
624 pseudo >>= 1;
625 regval = inb(s->iobase + CODEC_CMI_MIXER2) & ~0x30;
626 outb(regval | pseudo, s->iobase + CODEC_CMI_MIXER2);
627 }
628 if (idx == DSP_MIX_ADCMIXIDX_L) {
629 pseudo = data & 0x80;
630 pseudo >>= 1;
631 regval = inb(s->iobase + CODEC_CMI_MIXER2) & ~0x40;
632 outb(regval | pseudo, s->iobase + CODEC_CMI_MIXER2);
633 }
634 if (idx == DSP_MIX_ADCMIXIDX_R) {
635 pseudo = data & 0x80;
636 regval = inb(s->iobase + CODEC_CMI_MIXER2) & ~0x80;
637 outb(regval | pseudo, s->iobase + CODEC_CMI_MIXER2);
638 }
639 outb(data, s->iobase + CODEC_SB16_DATA);
640 udelay(10);
641}
642
643static unsigned char rdmixer(struct cm_state *s, unsigned char idx)
644{
645 unsigned char v, pseudo;
646
647 // pseudo register
648 if (idx == DSP_MIX_AUXVOL_L) {
649 v = inb(s->iobase + CODEC_CMI_AUX_VOL) & 0x0f;
650 v <<= 4;
651 return v;
652 }
653 if (idx == DSP_MIX_AUXVOL_L) {
654 v = inb(s->iobase + CODEC_CMI_AUX_VOL) & 0xf0;
655 return v;
656 }
657 outb(idx, s->iobase + CODEC_SB16_ADDR);
658 udelay(10);
659 v = inb(s->iobase + CODEC_SB16_DATA);
660 udelay(10);
661 // pseudo bits
662 if (idx == DSP_MIX_OUTMIXIDX) {
663 pseudo = inb(s->iobase + CODEC_CMI_MIXER2) & 0x30;
664 pseudo <<= 1;
665 v |= pseudo;
666 }
667 if (idx == DSP_MIX_ADCMIXIDX_L) {
668 pseudo = inb(s->iobase + CODEC_CMI_MIXER2) & 0x40;
669 pseudo <<= 1;
670 v |= pseudo;
671 }
672 if (idx == DSP_MIX_ADCMIXIDX_R) {
673 pseudo = inb(s->iobase + CODEC_CMI_MIXER2) & 0x80;
674 v |= pseudo;
675 }
676 return v;
677}
678
679static void set_fmt_unlocked(struct cm_state *s, unsigned char mask, unsigned char data)
680{
681 if (mask && s->chip_version > 0) { /* 8338 cannot keep this */
682 s->fmt = inb(s->iobase + CODEC_CMI_CHFORMAT);
683 udelay(10);
684 }
685 s->fmt = (s->fmt & mask) | data;
686 outb(s->fmt, s->iobase + CODEC_CMI_CHFORMAT);
687 udelay(10);
688}
689
690static void set_fmt(struct cm_state *s, unsigned char mask, unsigned char data)
691{
692 unsigned long flags;
693
694 spin_lock_irqsave(&s->lock, flags);
695 set_fmt_unlocked(s,mask,data);
696 spin_unlock_irqrestore(&s->lock, flags);
697}
698
699static void frobindir(struct cm_state *s, unsigned char idx, unsigned char mask, unsigned char data)
700{
701 outb(idx, s->iobase + CODEC_SB16_ADDR);
702 udelay(10);
703 outb((inb(s->iobase + CODEC_SB16_DATA) & mask) | data, s->iobase + CODEC_SB16_DATA);
704 udelay(10);
705}
706
707static struct {
708 unsigned rate;
709 unsigned lower;
710 unsigned upper;
711 unsigned char freq;
712} rate_lookup[] =
713{
714 { 5512, (0 + 5512) / 2, (5512 + 8000) / 2, 0 },
715 { 8000, (5512 + 8000) / 2, (8000 + 11025) / 2, 4 },
716 { 11025, (8000 + 11025) / 2, (11025 + 16000) / 2, 1 },
717 { 16000, (11025 + 16000) / 2, (16000 + 22050) / 2, 5 },
718 { 22050, (16000 + 22050) / 2, (22050 + 32000) / 2, 2 },
719 { 32000, (22050 + 32000) / 2, (32000 + 44100) / 2, 6 },
720 { 44100, (32000 + 44100) / 2, (44100 + 48000) / 2, 3 },
721 { 48000, (44100 + 48000) / 2, 48000, 7 }
722};
723
724static void set_spdif_copyright(struct cm_state *s, int spdif_copyright)
725{
726 /* enable SPDIF-in Copyright */
727 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 2, ~SPDCOPYRHT, spdif_copyright ? SPDCOPYRHT : 0);
728}
729
730static void set_spdif_loop(struct cm_state *s, int spdif_loop)
731{
732 /* enable SPDIF loop */
733 if (spdif_loop) {
734 s->status |= DO_SPDIF_LOOP;
735 /* turn on spdif-in to spdif-out */
736 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, SPDFLOOP);
737 } else {
738 s->status &= ~DO_SPDIF_LOOP;
739 /* turn off spdif-in to spdif-out */
740 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~SPDFLOOP, 0);
741 }
742}
743
744static void set_spdif_monitor(struct cm_state *s, int channel)
745{
746 // SPDO2DAC
747 maskw(s->iobase + CODEC_CMI_FUNCTRL1, ~SPDO2DAC, channel == 2 ? SPDO2DAC : 0);
748 // CDPLAY
749 if (s->chip_version >= 39)
750 maskb(s->iobase + CODEC_CMI_MIXER1, ~CDPLAY, channel ? CDPLAY : 0);
751}
752
753static void set_spdifout_level(struct cm_state *s, int level5v)
754{
755 /* SPDO5V */
756 if (s->chip_version > 0)
757 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 3, ~SPDO5V, level5v ? SPDO5V : 0);
758}
759
760static void set_spdifin_inverse(struct cm_state *s, int spdif_inverse)
761{
762 if (s->chip_version == 0) /* 8338 has not this feature */
763 return;
764 if (spdif_inverse) {
765 /* turn on spdif-in inverse */
766 if (s->chip_version >= 39)
767 maskb(s->iobase + CODEC_CMI_CHFORMAT, ~0, INVSPDIFI);
768 else
769 maskb(s->iobase + CODEC_CMI_CHFORMAT + 2, ~0, 1);
770 } else {
771 /* turn off spdif-ininverse */
772 if (s->chip_version >= 39)
773 maskb(s->iobase + CODEC_CMI_CHFORMAT, ~INVSPDIFI, 0);
774 else
775 maskb(s->iobase + CODEC_CMI_CHFORMAT + 2, ~1, 0);
776 }
777}
778
779static void set_spdifin_channel2(struct cm_state *s, int channel2)
780{
781 /* SELSPDIFI2 */
782 if (s->chip_version >= 39)
783 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 1, ~SELSPDIFI2, channel2 ? SELSPDIFI2 : 0);
784}
785
786static void set_spdifin_valid(struct cm_state *s, int valid)
787{
788 /* SPDVALID */
789 maskb(s->iobase + CODEC_CMI_MISC, ~SPDVALID, valid ? SPDVALID : 0);
790}
791
792static void set_spdifout_unlocked(struct cm_state *s, unsigned rate)
793{
794 if (rate != 48000 && rate != 44100)
795 rate = 0;
796 if (rate == 48000 || rate == 44100) {
797 set_spdif_loop(s, 0);
798 // SPDF_1
799 maskb(s->iobase + CODEC_CMI_FUNCTRL1 + 1, ~0, SPDF_1);
800 // SPDIFI48K SPDF_AC97
801 maskl(s->iobase + CODEC_CMI_MISC_CTRL, ~SPDIF48K, rate == 48000 ? SPDIF48K : 0);
802 if (s->chip_version >= 55)
803 // SPD32KFMT
804 maskb(s->iobase + CODEC_CMI_MISC_CTRL2, ~SPD32KFMT, rate == 48000 ? SPD32KFMT : 0);
805 if (s->chip_version > 0)
806 // ENSPDOUT
807 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 2, ~0, ENSPDOUT);
808 // monitor SPDIF out
809 set_spdif_monitor(s, 2);
810 s->status |= DO_SPDIF_OUT;
811 } else {
812 maskb(s->iobase + CODEC_CMI_FUNCTRL1 + 1, ~SPDF_1, 0);
813 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 2, ~ENSPDOUT, 0);
814 // monitor none
815 set_spdif_monitor(s, 0);
816 s->status &= ~DO_SPDIF_OUT;
817 }
818}
819
820static void set_spdifout(struct cm_state *s, unsigned rate)
821{
822 unsigned long flags;
823
824 spin_lock_irqsave(&s->lock, flags);
825 set_spdifout_unlocked(s,rate);
826 spin_unlock_irqrestore(&s->lock, flags);
827}
828
829static void set_spdifin_unlocked(struct cm_state *s, unsigned rate)
830{
831 if (rate == 48000 || rate == 44100) {
832 // SPDF_1
833 maskb(s->iobase + CODEC_CMI_FUNCTRL1 + 1, ~0, SPDF_1);
834 // SPDIFI48K SPDF_AC97
835 maskl(s->iobase + CODEC_CMI_MISC_CTRL, ~SPDIF48K, rate == 48000 ? SPDIF48K : 0);
836 s->status |= DO_SPDIF_IN;
837 } else {
838 maskb(s->iobase + CODEC_CMI_FUNCTRL1 + 1, ~SPDF_1, 0);
839 s->status &= ~DO_SPDIF_IN;
840 }
841}
842
843static void set_spdifin(struct cm_state *s, unsigned rate)
844{
845 unsigned long flags;
846
847 spin_lock_irqsave(&s->lock, flags);
848 set_spdifin_unlocked(s,rate);
849 spin_unlock_irqrestore(&s->lock, flags);
850}
851
852/* find parity for bit 4~30 */
853static unsigned parity(unsigned data)
854{
855 unsigned parity = 0;
856 int counter = 4;
857
858 data >>= 4; // start from bit 4
859 while (counter <= 30) {
860 if (data & 1)
861 parity++;
862 data >>= 1;
863 counter++;
864 }
865 return parity & 1;
866}
867
868static void set_ac3_unlocked(struct cm_state *s, unsigned rate)
869{
870 if (!(s->capability & CAN_AC3))
871 return;
872 /* enable AC3 */
873 if (rate && rate != 44100)
874 rate = 48000;
875 if (rate == 48000 || rate == 44100) {
876 // mute DAC
877 maskb(s->iobase + CODEC_CMI_MIXER1, ~0, WSMUTE);
878 if (s->chip_version >= 39)
879 maskb(s->iobase + CODEC_CMI_MISC_CTRL, ~0, MUTECH1);
880 // AC3EN for 039, 0x04
881 if (s->chip_version >= 39) {
882 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~0, AC3_EN);
883 if (s->chip_version == 55)
884 maskb(s->iobase + CODEC_CMI_SPDIF_CTRL, ~2, 0);
885 // AC3EN for 037, 0x10
886 } else if (s->chip_version == 37)
887 maskb(s->iobase + CODEC_CMI_CHFORMAT + 2, ~0, 0x10);
888 if (s->capability & CAN_AC3_HW) {
889 // SPD24SEL for 039, 0x20, but cannot be set
890 if (s->chip_version == 39)
891 maskb(s->iobase + CODEC_CMI_CHFORMAT + 2, ~0, SPD24SEL);
892 // SPD24SEL for 037, 0x02
893 else if (s->chip_version == 37)
894 maskb(s->iobase + CODEC_CMI_CHFORMAT + 2, ~0, 0x02);
895 if (s->chip_version >= 39)
896 maskb(s->iobase + CODEC_CMI_MIXER1, ~CDPLAY, 0);
897
898 s->status |= DO_AC3_HW;
899 } else {
900 // SPD32SEL for 037 & 039
901 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~0, SPD32SEL);
902 // set 176K sample rate to fix 033 HW bug
903 if (s->chip_version == 33) {
904 if (rate == 48000)
905 maskb(s->iobase + CODEC_CMI_CHFORMAT + 1, ~0, 0x08);
906 else
907 maskb(s->iobase + CODEC_CMI_CHFORMAT + 1, ~0x08, 0);
908 }
909 s->status |= DO_AC3_SW;
910 }
911 } else {
912 maskb(s->iobase + CODEC_CMI_MIXER1, ~WSMUTE, 0);
913 if (s->chip_version >= 39)
914 maskb(s->iobase + CODEC_CMI_MISC_CTRL, ~MUTECH1, 0);
915 maskb(s->iobase + CODEC_CMI_CHFORMAT + 2, ~(SPD24SEL|0x12), 0);
916 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~(SPD32SEL|AC3_EN), 0);
917 if (s->chip_version == 33)
918 maskb(s->iobase + CODEC_CMI_CHFORMAT + 1, ~0x08, 0);
919 if (s->chip_version >= 39)
920 maskb(s->iobase + CODEC_CMI_MIXER1, ~0, CDPLAY);
921 s->status &= ~DO_AC3;
922 }
923 s->spdif_counter = 0;
924}
925
926static void set_line_as_rear(struct cm_state *s, int use_line_as_rear)
927{
928 if (!(s->capability & CAN_LINE_AS_REAR))
929 return;
930 if (use_line_as_rear) {
931 maskb(s->iobase + CODEC_CMI_MIXER1, ~0, SPK4);
932 s->status |= DO_LINE_AS_REAR;
933 } else {
934 maskb(s->iobase + CODEC_CMI_MIXER1, ~SPK4, 0);
935 s->status &= ~DO_LINE_AS_REAR;
936 }
937}
938
939static void set_line_as_bass(struct cm_state *s, int use_line_as_bass)
940{
941 if (!(s->capability & CAN_LINE_AS_BASS))
942 return;
943 if (use_line_as_bass) {
944 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 1, ~0, CB2LIN);
945 s->status |= DO_LINE_AS_BASS;
946 } else {
947 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 1, ~CB2LIN, 0);
948 s->status &= ~DO_LINE_AS_BASS;
949 }
950}
951
952static void set_mic_as_bass(struct cm_state *s, int use_mic_as_bass)
953{
954 if (!(s->capability & CAN_MIC_AS_BASS))
955 return;
956 if (use_mic_as_bass) {
957 maskb(s->iobase + CODEC_CMI_MISC, ~0, 0x04);
958 s->status |= DO_MIC_AS_BASS;
959 } else {
960 maskb(s->iobase + CODEC_CMI_MISC, ~0x04, 0);
961 s->status &= ~DO_MIC_AS_BASS;
962 }
963}
964
965static void set_hw_copy(struct cm_state *s, int hw_copy)
966{
967 if (s->max_channels > 2 && hw_copy)
968 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 3, ~0, N4SPK3D);
969 else
970 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 3, ~N4SPK3D, 0);
971}
972
973static void set_ac3(struct cm_state *s, unsigned rate)
974{
975 unsigned long flags;
976
977 spin_lock_irqsave(&s->lock, flags);
978 set_spdifout_unlocked(s, rate);
979 set_ac3_unlocked(s, rate);
980 spin_unlock_irqrestore(&s->lock, flags);
981}
982
983static int trans_ac3(struct cm_state *s, void *dest, const char __user *source, int size)
984{
985 int i = size / 2;
986 unsigned long data;
987 unsigned short data16;
988 unsigned long *dst = (unsigned long *) dest;
989 unsigned short __user *src = (unsigned short __user *)source;
990 int err;
991
992 do {
993 if ((err = __get_user(data16, src++)))
994 return err;
995 data = (unsigned long)le16_to_cpu(data16);
996 data <<= 12; // ok for 16-bit data
997 if (s->spdif_counter == 2 || s->spdif_counter == 3)
998 data |= 0x40000000; // indicate AC-3 raw data
999 if (parity(data))
1000 data |= 0x80000000; // parity
1001 if (s->spdif_counter == 0)
1002 data |= 3; // preamble 'M'
1003 else if (s->spdif_counter & 1)
1004 data |= 5; // odd, 'W'
1005 else
1006 data |= 9; // even, 'M'
1007 *dst++ = cpu_to_le32(data);
1008 s->spdif_counter++;
1009 if (s->spdif_counter == 384)
1010 s->spdif_counter = 0;
1011 } while (--i);
1012
1013 return 0;
1014}
1015
1016static void set_adc_rate_unlocked(struct cm_state *s, unsigned rate)
1017{
1018 unsigned char freq = 4;
1019 int i;
1020
1021 if (rate > 48000)
1022 rate = 48000;
1023 if (rate < 8000)
1024 rate = 8000;
1025 for (i = 0; i < sizeof(rate_lookup) / sizeof(rate_lookup[0]); i++) {
1026 if (rate > rate_lookup[i].lower && rate <= rate_lookup[i].upper) {
1027 rate = rate_lookup[i].rate;
1028 freq = rate_lookup[i].freq;
1029 break;
1030 }
1031 }
1032 s->rateadc = rate;
1033 freq <<= CM_FREQ_ADCSHIFT;
1034
1035 maskb(s->iobase + CODEC_CMI_FUNCTRL1 + 1, ~ASFC, freq);
1036}
1037
1038static void set_adc_rate(struct cm_state *s, unsigned rate)
1039{
1040 unsigned long flags;
1041 unsigned char freq = 4;
1042 int i;
1043
1044 if (rate > 48000)
1045 rate = 48000;
1046 if (rate < 8000)
1047 rate = 8000;
1048 for (i = 0; i < sizeof(rate_lookup) / sizeof(rate_lookup[0]); i++) {
1049 if (rate > rate_lookup[i].lower && rate <= rate_lookup[i].upper) {
1050 rate = rate_lookup[i].rate;
1051 freq = rate_lookup[i].freq;
1052 break;
1053 }
1054 }
1055 s->rateadc = rate;
1056 freq <<= CM_FREQ_ADCSHIFT;
1057
1058 spin_lock_irqsave(&s->lock, flags);
1059 maskb(s->iobase + CODEC_CMI_FUNCTRL1 + 1, ~ASFC, freq);
1060 spin_unlock_irqrestore(&s->lock, flags);
1061}
1062
1063static void set_dac_rate(struct cm_state *s, unsigned rate)
1064{
1065 unsigned long flags;
1066 unsigned char freq = 4;
1067 int i;
1068
1069 if (rate > 48000)
1070 rate = 48000;
1071 if (rate < 8000)
1072 rate = 8000;
1073 for (i = 0; i < sizeof(rate_lookup) / sizeof(rate_lookup[0]); i++) {
1074 if (rate > rate_lookup[i].lower && rate <= rate_lookup[i].upper) {
1075 rate = rate_lookup[i].rate;
1076 freq = rate_lookup[i].freq;
1077 break;
1078 }
1079 }
1080 s->ratedac = rate;
1081 freq <<= CM_FREQ_DACSHIFT;
1082
1083 spin_lock_irqsave(&s->lock, flags);
1084 maskb(s->iobase + CODEC_CMI_FUNCTRL1 + 1, ~DSFC, freq);
1085 spin_unlock_irqrestore(&s->lock, flags);
1086
1087 if (s->curr_channels <= 2 && spdif_out)
1088 set_spdifout(s, rate);
1089 if (s->status & DO_DUAL_DAC)
1090 set_dac1_rate(s, rate);
1091}
1092
1093/* --------------------------------------------------------------------- */
1094static inline void reset_adc(struct cm_state *s)
1095{
1096 /* reset bus master */
1097 outb(s->enable | RSTADC, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
1098 udelay(10);
1099 outb(s->enable & ~RSTADC, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
1100}
1101
1102static inline void reset_dac(struct cm_state *s)
1103{
1104 /* reset bus master */
1105 outb(s->enable | RSTDAC, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
1106 udelay(10);
1107 outb(s->enable & ~RSTDAC, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
1108 if (s->status & DO_DUAL_DAC)
1109 reset_adc(s);
1110}
1111
1112static inline void pause_adc(struct cm_state *s)
1113{
1114 maskb(s->iobase + CODEC_CMI_FUNCTRL0, ~0, PAUSEADC);
1115}
1116
1117static inline void pause_dac(struct cm_state *s)
1118{
1119 maskb(s->iobase + CODEC_CMI_FUNCTRL0, ~0, PAUSEDAC);
1120 if (s->status & DO_DUAL_DAC)
1121 pause_adc(s);
1122}
1123
1124static inline void disable_adc(struct cm_state *s)
1125{
1126 /* disable channel */
1127 s->enable &= ~ENADC;
1128 outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
1129 reset_adc(s);
1130}
1131
1132static inline void disable_dac(struct cm_state *s)
1133{
1134 /* disable channel */
1135 s->enable &= ~ENDAC;
1136 outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
1137 reset_dac(s);
1138 if (s->status & DO_DUAL_DAC)
1139 disable_adc(s);
1140}
1141
1142static inline void enable_adc(struct cm_state *s)
1143{
1144 if (!(s->enable & ENADC)) {
1145 /* enable channel */
1146 s->enable |= ENADC;
1147 outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
1148 }
1149 maskb(s->iobase + CODEC_CMI_FUNCTRL0, ~PAUSEADC, 0);
1150}
1151
1152static inline void enable_dac_unlocked(struct cm_state *s)
1153{
1154 if (!(s->enable & ENDAC)) {
1155 /* enable channel */
1156 s->enable |= ENDAC;
1157 outb(s->enable, s->iobase + CODEC_CMI_FUNCTRL0 + 2);
1158 }
1159 maskb(s->iobase + CODEC_CMI_FUNCTRL0, ~PAUSEDAC, 0);
1160
1161 if (s->status & DO_DUAL_DAC)
1162 enable_adc(s);
1163}
1164
1165static inline void stop_adc_unlocked(struct cm_state *s)
1166{
1167 if (s->enable & ENADC) {
1168 /* disable interrupt */
1169 maskb(s->iobase + CODEC_CMI_INT_HLDCLR + 2, ~ENADCINT, 0);
1170 disable_adc(s);
1171 }
1172}
1173
1174static inline void stop_adc(struct cm_state *s)
1175{
1176 unsigned long flags;
1177
1178 spin_lock_irqsave(&s->lock, flags);
1179 stop_adc_unlocked(s);
1180 spin_unlock_irqrestore(&s->lock, flags);
1181
1182}
1183
1184static inline void stop_dac_unlocked(struct cm_state *s)
1185{
1186 if (s->enable & ENDAC) {
1187 /* disable interrupt */
1188 maskb(s->iobase + CODEC_CMI_INT_HLDCLR + 2, ~ENDACINT, 0);
1189 disable_dac(s);
1190 }
1191 if (s->status & DO_DUAL_DAC)
1192 stop_dac1_unlocked(s);
1193}
1194
1195static inline void stop_dac(struct cm_state *s)
1196{
1197 unsigned long flags;
1198
1199 spin_lock_irqsave(&s->lock, flags);
1200 stop_dac_unlocked(s);
1201 spin_unlock_irqrestore(&s->lock, flags);
1202}
1203
1204static inline void start_adc_unlocked(struct cm_state *s)
1205{
1206 if ((s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
1207 && s->dma_adc.ready) {
1208 /* enable interrupt */
1209 maskb(s->iobase + CODEC_CMI_INT_HLDCLR + 2, ~0, ENADCINT);
1210 enable_adc(s);
1211 }
1212}
1213
1214static void start_adc(struct cm_state *s)
1215{
1216 unsigned long flags;
1217
1218 spin_lock_irqsave(&s->lock, flags);
1219 start_adc_unlocked(s);
1220 spin_unlock_irqrestore(&s->lock, flags);
1221}
1222
1223static void start_dac1_unlocked(struct cm_state *s)
1224{
1225 if ((s->dma_adc.mapped || s->dma_adc.count > 0) && s->dma_adc.ready) {
1226 /* enable interrupt */
1227 maskb(s->iobase + CODEC_CMI_INT_HLDCLR + 2, ~0, ENADCINT);
1228 enable_dac_unlocked(s);
1229 }
1230}
1231
1232static void start_dac_unlocked(struct cm_state *s)
1233{
1234 if ((s->dma_dac.mapped || s->dma_dac.count > 0) && s->dma_dac.ready) {
1235 /* enable interrupt */
1236 maskb(s->iobase + CODEC_CMI_INT_HLDCLR + 2, ~0, ENDACINT);
1237 enable_dac_unlocked(s);
1238 }
1239 if (s->status & DO_DUAL_DAC)
1240 start_dac1_unlocked(s);
1241}
1242
1243static void start_dac(struct cm_state *s)
1244{
1245 unsigned long flags;
1246
1247 spin_lock_irqsave(&s->lock, flags);
1248 start_dac_unlocked(s);
1249 spin_unlock_irqrestore(&s->lock, flags);
1250}
1251
1252static int prog_dmabuf(struct cm_state *s, unsigned rec);
1253
1254static int set_dac_channels(struct cm_state *s, int channels)
1255{
1256 unsigned long flags;
1257 static unsigned int fmmute = 0;
1258
1259 spin_lock_irqsave(&s->lock, flags);
1260
1261 if ((channels > 2) && (channels <= s->max_channels)
1262 && (((s->fmt >> CM_CFMT_DACSHIFT) & CM_CFMT_MASK) == (CM_CFMT_STEREO | CM_CFMT_16BIT))) {
1263 set_spdifout_unlocked(s, 0);
1264 if (s->capability & CAN_MULTI_CH_HW) {
1265 // NXCHG
1266 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 3, ~0, NXCHG);
1267 // CHB3D or CHB3D5C
1268 maskb(s->iobase + CODEC_CMI_CHFORMAT + 3, ~(CHB3D5C|CHB3D), channels > 4 ? CHB3D5C : CHB3D);
1269 // CHB3D6C
1270 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 1, ~CHB3D6C, channels == 6 ? CHB3D6C : 0);
1271 // ENCENTER
1272 maskb(s->iobase + CODEC_CMI_MISC_CTRL, ~ENCENTER, channels == 6 ? ENCENTER : 0);
1273 s->status |= DO_MULTI_CH_HW;
1274 } else if (s->capability & CAN_DUAL_DAC) {
1275 unsigned char fmtm = ~0, fmts = 0;
1276 ssize_t ret;
1277
1278 // ENDBDAC, turn on double DAC mode
1279 // XCHGDAC, CH0 -> back, CH1->front
1280 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~0, ENDBDAC|XCHGDAC);
1281 // mute FM
1282 fmmute = inb(s->iobase + CODEC_CMI_MIXER1) & FMMUTE;
1283 maskb(s->iobase + CODEC_CMI_MIXER1, ~0, FMMUTE);
1284 s->status |= DO_DUAL_DAC;
1285 // prepare secondary buffer
1286 spin_unlock_irqrestore(&s->lock, flags);
1287 ret = prog_dmabuf(s, 1);
1288 if (ret) return ret;
1289 spin_lock_irqsave(&s->lock, flags);
1290
1291 // copy the hw state
1292 fmtm &= ~((CM_CFMT_STEREO | CM_CFMT_16BIT) << CM_CFMT_DACSHIFT);
1293 fmtm &= ~((CM_CFMT_STEREO | CM_CFMT_16BIT) << CM_CFMT_ADCSHIFT);
1294 // the HW only support 16-bit stereo
1295 fmts |= CM_CFMT_16BIT << CM_CFMT_DACSHIFT;
1296 fmts |= CM_CFMT_16BIT << CM_CFMT_ADCSHIFT;
1297 fmts |= CM_CFMT_STEREO << CM_CFMT_DACSHIFT;
1298 fmts |= CM_CFMT_STEREO << CM_CFMT_ADCSHIFT;
1299
1300 set_fmt_unlocked(s, fmtm, fmts);
1301 set_adc_rate_unlocked(s, s->ratedac);
1302 }
1303 // disable 4 speaker mode (analog duplicate)
1304 set_hw_copy(s, 0);
1305 s->curr_channels = channels;
1306
1307 // enable jack redirect
1308 set_line_as_rear(s, use_line_as_rear);
1309 if (channels > 4) {
1310 set_line_as_bass(s, use_line_as_bass);
1311 set_mic_as_bass(s, use_mic_as_bass);
1312 }
1313 } else {
1314 if (s->status & DO_MULTI_CH_HW) {
1315 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 3, ~NXCHG, 0);
1316 maskb(s->iobase + CODEC_CMI_CHFORMAT + 3, ~(CHB3D5C|CHB3D), 0);
1317 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 1, ~CHB3D6C, 0);
1318 } else if (s->status & DO_DUAL_DAC) {
1319 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~ENDBDAC, 0);
1320 maskb(s->iobase + CODEC_CMI_MIXER1, ~FMMUTE, fmmute);
1321 }
1322 // enable 4 speaker mode (analog duplicate)
1323 set_hw_copy(s, hw_copy);
1324 s->status &= ~DO_MULTI_CH;
1325 s->curr_channels = s->fmt & (CM_CFMT_STEREO << CM_CFMT_DACSHIFT) ? 2 : 1;
1326 // disable jack redirect
1327 set_line_as_rear(s, hw_copy ? use_line_as_rear : 0);
1328 set_line_as_bass(s, 0);
1329 set_mic_as_bass(s, 0);
1330 }
1331 spin_unlock_irqrestore(&s->lock, flags);
1332 return s->curr_channels;
1333}
1334
1335/* --------------------------------------------------------------------- */
1336
1337#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT)
1338#define DMABUF_MINORDER 1
1339
1340static void dealloc_dmabuf(struct cm_state *s, struct dmabuf *db)
1341{
1342 struct page *pstart, *pend;
1343
1344 if (db->rawbuf) {
1345 /* undo marking the pages as reserved */
1346 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
1347 for (pstart = virt_to_page(db->rawbuf); pstart <= pend; pstart++)
1348 ClearPageReserved(pstart);
1349 pci_free_consistent(s->dev, PAGE_SIZE << db->buforder, db->rawbuf, db->dmaaddr);
1350 }
1351 db->rawbuf = NULL;
1352 db->mapped = db->ready = 0;
1353}
1354
1355/* Ch1 is used for playback, Ch0 is used for recording */
1356
1357static int prog_dmabuf(struct cm_state *s, unsigned rec)
1358{
1359 struct dmabuf *db = rec ? &s->dma_adc : &s->dma_dac;
1360 unsigned rate = rec ? s->rateadc : s->ratedac;
1361 int order;
1362 unsigned bytepersec;
1363 unsigned bufs;
1364 struct page *pstart, *pend;
1365 unsigned char fmt;
1366 unsigned long flags;
1367
1368 fmt = s->fmt;
1369 if (rec) {
1370 stop_adc(s);
1371 fmt >>= CM_CFMT_ADCSHIFT;
1372 } else {
1373 stop_dac(s);
1374 fmt >>= CM_CFMT_DACSHIFT;
1375 }
1376
1377 fmt &= CM_CFMT_MASK;
1378 db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
1379 if (!db->rawbuf) {
1380 db->ready = db->mapped = 0;
1381 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--)
1382 if ((db->rawbuf = pci_alloc_consistent(s->dev, PAGE_SIZE << order, &db->dmaaddr)))
1383 break;
1384 if (!db->rawbuf || !db->dmaaddr)
1385 return -ENOMEM;
1386 db->buforder = order;
1387 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
1388 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
1389 for (pstart = virt_to_page(db->rawbuf); pstart <= pend; pstart++)
1390 SetPageReserved(pstart);
1391 }
1392 bytepersec = rate << sample_shift[fmt];
1393 bufs = PAGE_SIZE << db->buforder;
1394 if (db->ossfragshift) {
1395 if ((1000 << db->ossfragshift) < bytepersec)
1396 db->fragshift = ld2(bytepersec/1000);
1397 else
1398 db->fragshift = db->ossfragshift;
1399 } else {
1400 db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
1401 if (db->fragshift < 3)
1402 db->fragshift = 3;
1403 }
1404 db->numfrag = bufs >> db->fragshift;
1405 while (db->numfrag < 4 && db->fragshift > 3) {
1406 db->fragshift--;
1407 db->numfrag = bufs >> db->fragshift;
1408 }
1409 db->fragsize = 1 << db->fragshift;
1410 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
1411 db->numfrag = db->ossmaxfrags;
1412 /* to make fragsize >= 4096 */
1413 db->fragsamples = db->fragsize >> sample_shift[fmt];
1414 db->dmasize = db->numfrag << db->fragshift;
1415 db->dmasamples = db->dmasize >> sample_shift[fmt];
1416 memset(db->rawbuf, (fmt & CM_CFMT_16BIT) ? 0 : 0x80, db->dmasize);
1417 spin_lock_irqsave(&s->lock, flags);
1418 if (rec) {
1419 if (s->status & DO_DUAL_DAC)
1420 set_dmadac1(s, db->dmaaddr, db->dmasize >> sample_shift[fmt]);
1421 else
1422 set_dmaadc(s, db->dmaaddr, db->dmasize >> sample_shift[fmt]);
1423 /* program sample counts */
1424 set_countdac(s, db->fragsamples);
1425 } else {
1426 set_dmadac(s, db->dmaaddr, db->dmasize >> sample_shift[fmt]);
1427 /* program sample counts */
1428 set_countdac(s, db->fragsamples);
1429 }
1430 spin_unlock_irqrestore(&s->lock, flags);
1431 db->enabled = 1;
1432 db->ready = 1;
1433 return 0;
1434}
1435
1436static inline void clear_advance(struct cm_state *s)
1437{
1438 unsigned char c = (s->fmt & (CM_CFMT_16BIT << CM_CFMT_DACSHIFT)) ? 0 : 0x80;
1439 unsigned char *buf = s->dma_dac.rawbuf;
1440 unsigned char *buf1 = s->dma_adc.rawbuf;
1441 unsigned bsize = s->dma_dac.dmasize;
1442 unsigned bptr = s->dma_dac.swptr;
1443 unsigned len = s->dma_dac.fragsize;
1444
1445 if (bptr + len > bsize) {
1446 unsigned x = bsize - bptr;
1447 memset(buf + bptr, c, x);
1448 if (s->status & DO_DUAL_DAC)
1449 memset(buf1 + bptr, c, x);
1450 bptr = 0;
1451 len -= x;
1452 }
1453 memset(buf + bptr, c, len);
1454 if (s->status & DO_DUAL_DAC)
1455 memset(buf1 + bptr, c, len);
1456}
1457
1458/* call with spinlock held! */
1459static void cm_update_ptr(struct cm_state *s)
1460{
1461 unsigned hwptr;
1462 int diff;
1463
1464 /* update ADC pointer */
1465 if (s->dma_adc.ready) {
1466 if (s->status & DO_DUAL_DAC) {
1467 /* the dac part will finish for this */
1468 } else {
1469 hwptr = get_dmaadc(s) % s->dma_adc.dmasize;
1470 diff = (s->dma_adc.dmasize + hwptr - s->dma_adc.hwptr) % s->dma_adc.dmasize;
1471 s->dma_adc.hwptr = hwptr;
1472 s->dma_adc.total_bytes += diff;
1473 s->dma_adc.count += diff;
1474 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1475 wake_up(&s->dma_adc.wait);
1476 if (!s->dma_adc.mapped) {
1477 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
1478 pause_adc(s);
1479 s->dma_adc.error++;
1480 }
1481 }
1482 }
1483 }
1484 /* update DAC pointer */
1485 if (s->dma_dac.ready) {
1486 hwptr = get_dmadac(s) % s->dma_dac.dmasize;
1487 diff = (s->dma_dac.dmasize + hwptr - s->dma_dac.hwptr) % s->dma_dac.dmasize;
1488 s->dma_dac.hwptr = hwptr;
1489 s->dma_dac.total_bytes += diff;
1490 if (s->status & DO_DUAL_DAC) {
1491 s->dma_adc.hwptr = hwptr;
1492 s->dma_adc.total_bytes += diff;
1493 }
1494 if (s->dma_dac.mapped) {
1495 s->dma_dac.count += diff;
1496 if (s->status & DO_DUAL_DAC)
1497 s->dma_adc.count += diff;
1498 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
1499 wake_up(&s->dma_dac.wait);
1500 } else {
1501 s->dma_dac.count -= diff;
1502 if (s->status & DO_DUAL_DAC)
1503 s->dma_adc.count -= diff;
1504 if (s->dma_dac.count <= 0) {
1505 pause_dac(s);
1506 s->dma_dac.error++;
1507 } else if (s->dma_dac.count <= (signed)s->dma_dac.fragsize && !s->dma_dac.endcleared) {
1508 clear_advance(s);
1509 s->dma_dac.endcleared = 1;
1510 if (s->status & DO_DUAL_DAC)
1511 s->dma_adc.endcleared = 1;
1512 }
1513 if (s->dma_dac.count + (signed)s->dma_dac.fragsize <= (signed)s->dma_dac.dmasize)
1514 wake_up(&s->dma_dac.wait);
1515 }
1516 }
1517}
1518
1519static irqreturn_t cm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1520{
1521 struct cm_state *s = (struct cm_state *)dev_id;
1522 unsigned int intsrc, intstat;
1523 unsigned char mask = 0;
1524
1525 /* fastpath out, to ease interrupt sharing */
1526 intsrc = inl(s->iobase + CODEC_CMI_INT_STATUS);
1527 if (!(intsrc & 0x80000000))
1528 return IRQ_NONE;
1529 spin_lock(&s->lock);
1530 intstat = inb(s->iobase + CODEC_CMI_INT_HLDCLR + 2);
1531 /* acknowledge interrupt */
1532 if (intsrc & ADCINT)
1533 mask |= ENADCINT;
1534 if (intsrc & DACINT)
1535 mask |= ENDACINT;
1536 outb(intstat & ~mask, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
1537 outb(intstat | mask, s->iobase + CODEC_CMI_INT_HLDCLR + 2);
1538 cm_update_ptr(s);
1539 spin_unlock(&s->lock);
1540#ifdef CONFIG_SOUND_CMPCI_MIDI
1541 if (intsrc & 0x00010000) { // UART interrupt
1542 if (s->midi_devc && intchk_mpu401((void *)s->midi_devc))
1543 mpuintr(irq, (void *)s->midi_devc, regs);
1544 else
1545 inb(s->iomidi);// dummy read
1546 }
1547#endif
1548 return IRQ_HANDLED;
1549}
1550
1551/* --------------------------------------------------------------------- */
1552
1553static const char invalid_magic[] = KERN_CRIT "cmpci: invalid magic value\n";
1554
1555#define VALIDATE_STATE(s) \
1556({ \
1557 if (!(s) || (s)->magic != CM_MAGIC) { \
1558 printk(invalid_magic); \
1559 return -ENXIO; \
1560 } \
1561})
1562
1563/* --------------------------------------------------------------------- */
1564
1565#define MT_4 1
1566#define MT_5MUTE 2
1567#define MT_4MUTEMONO 3
1568#define MT_6MUTE 4
1569#define MT_5MUTEMONO 5
1570
1571static const struct {
1572 unsigned left;
1573 unsigned right;
1574 unsigned type;
1575 unsigned rec;
1576 unsigned play;
1577} mixtable[SOUND_MIXER_NRDEVICES] = {
1578 [SOUND_MIXER_CD] = { DSP_MIX_CDVOLIDX_L, DSP_MIX_CDVOLIDX_R, MT_5MUTE, 0x04, 0x06 },
1579 [SOUND_MIXER_LINE] = { DSP_MIX_LINEVOLIDX_L, DSP_MIX_LINEVOLIDX_R, MT_5MUTE, 0x10, 0x18 },
1580 [SOUND_MIXER_MIC] = { DSP_MIX_MICVOLIDX, DSP_MIX_MICVOLIDX, MT_5MUTEMONO, 0x01, 0x01 },
1581 [SOUND_MIXER_SYNTH] = { DSP_MIX_FMVOLIDX_L, DSP_MIX_FMVOLIDX_R, MT_5MUTE, 0x40, 0x00 },
1582 [SOUND_MIXER_VOLUME] = { DSP_MIX_MASTERVOLIDX_L, DSP_MIX_MASTERVOLIDX_R, MT_5MUTE, 0x00, 0x00 },
1583 [SOUND_MIXER_PCM] = { DSP_MIX_VOICEVOLIDX_L, DSP_MIX_VOICEVOLIDX_R, MT_5MUTE, 0x00, 0x00 },
1584 [SOUND_MIXER_LINE1] = { DSP_MIX_AUXVOL_L, DSP_MIX_AUXVOL_R, MT_5MUTE, 0x80, 0x60 },
1585 [SOUND_MIXER_SPEAKER]= { DSP_MIX_SPKRVOLIDX, DSP_MIX_SPKRVOLIDX, MT_5MUTEMONO, 0x00, 0x01 }
1586};
1587
1588static const unsigned char volidx[SOUND_MIXER_NRDEVICES] =
1589{
1590 [SOUND_MIXER_CD] = 1,
1591 [SOUND_MIXER_LINE] = 2,
1592 [SOUND_MIXER_MIC] = 3,
1593 [SOUND_MIXER_SYNTH] = 4,
1594 [SOUND_MIXER_VOLUME] = 5,
1595 [SOUND_MIXER_PCM] = 6,
1596 [SOUND_MIXER_LINE1] = 7,
1597 [SOUND_MIXER_SPEAKER]= 8
1598};
1599
1600static unsigned mixer_outmask(struct cm_state *s)
1601{
1602 unsigned long flags;
1603 int i, j, k;
1604
1605 spin_lock_irqsave(&s->lock, flags);
1606 j = rdmixer(s, DSP_MIX_OUTMIXIDX);
1607 spin_unlock_irqrestore(&s->lock, flags);
1608 for (k = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1609 if (j & mixtable[i].play)
1610 k |= 1 << i;
1611 return k;
1612}
1613
1614static unsigned mixer_recmask(struct cm_state *s)
1615{
1616 unsigned long flags;
1617 int i, j, k;
1618
1619 spin_lock_irqsave(&s->lock, flags);
1620 j = rdmixer(s, DSP_MIX_ADCMIXIDX_L);
1621 spin_unlock_irqrestore(&s->lock, flags);
1622 for (k = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1623 if (j & mixtable[i].rec)
1624 k |= 1 << i;
1625 return k;
1626}
1627
1628static int mixer_ioctl(struct cm_state *s, unsigned int cmd, unsigned long arg)
1629{
1630 unsigned long flags;
1631 int i, val, j;
1632 unsigned char l, r, rl, rr;
1633 void __user *argp = (void __user *)arg;
1634 int __user *p = argp;
1635
1636 VALIDATE_STATE(s);
1637 if (cmd == SOUND_MIXER_INFO) {
1638 mixer_info info;
1639 memset(&info, 0, sizeof(info));
1640 strlcpy(info.id, "cmpci", sizeof(info.id));
1641 strlcpy(info.name, "C-Media PCI", sizeof(info.name));
1642 info.modify_counter = s->mix.modcnt;
1643 if (copy_to_user(argp, &info, sizeof(info)))
1644 return -EFAULT;
1645 return 0;
1646 }
1647 if (cmd == SOUND_OLD_MIXER_INFO) {
1648 _old_mixer_info info;
1649 memset(&info, 0, sizeof(info));
1650 strlcpy(info.id, "cmpci", sizeof(info.id));
1651 strlcpy(info.name, "C-Media cmpci", sizeof(info.name));
1652 if (copy_to_user(argp, &info, sizeof(info)))
1653 return -EFAULT;
1654 return 0;
1655 }
1656 if (cmd == OSS_GETVERSION)
1657 return put_user(SOUND_VERSION, p);
1658 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
1659 return -EINVAL;
1660 if (_SIOC_DIR(cmd) == _SIOC_READ) {
1661 switch (_IOC_NR(cmd)) {
1662 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
1663 val = mixer_recmask(s);
1664 return put_user(val, p);
1665
1666 case SOUND_MIXER_OUTSRC: /* Arg contains a bit for each recording source */
1667 val = mixer_outmask(s);
1668 return put_user(val, p);
1669
1670 case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
1671 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1672 if (mixtable[i].type)
1673 val |= 1 << i;
1674 return put_user(val, p);
1675
1676 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
1677 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1678 if (mixtable[i].rec)
1679 val |= 1 << i;
1680 return put_user(val, p);
1681
1682 case SOUND_MIXER_OUTMASK: /* Arg contains a bit for each supported recording source */
1683 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1684 if (mixtable[i].play)
1685 val |= 1 << i;
1686 return put_user(val, p);
1687
1688 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
1689 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1690 if (mixtable[i].type && mixtable[i].type != MT_4MUTEMONO)
1691 val |= 1 << i;
1692 return put_user(val, p);
1693
1694 case SOUND_MIXER_CAPS:
1695 return put_user(0, p);
1696
1697 default:
1698 i = _IOC_NR(cmd);
1699 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
1700 return -EINVAL;
1701 if (!volidx[i])
1702 return -EINVAL;
1703 return put_user(s->mix.vol[volidx[i]-1], p);
1704 }
1705 }
1706 if (_SIOC_DIR(cmd) != (_SIOC_READ|_SIOC_WRITE))
1707 return -EINVAL;
1708 s->mix.modcnt++;
1709 switch (_IOC_NR(cmd)) {
1710 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
1711 if (get_user(val, p))
1712 return -EFAULT;
1713 i = generic_hweight32(val);
1714 for (j = i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1715 if (!(val & (1 << i)))
1716 continue;
1717 if (!mixtable[i].rec) {
1718 val &= ~(1 << i);
1719 continue;
1720 }
1721 j |= mixtable[i].rec;
1722 }
1723 spin_lock_irqsave(&s->lock, flags);
1724 wrmixer(s, DSP_MIX_ADCMIXIDX_L, j);
1725 wrmixer(s, DSP_MIX_ADCMIXIDX_R, (j & 1) | (j>>1) | (j & 0x80));
1726 spin_unlock_irqrestore(&s->lock, flags);
1727 return 0;
1728
1729 case SOUND_MIXER_OUTSRC: /* Arg contains a bit for each recording source */
1730 if (get_user(val, p))
1731 return -EFAULT;
1732 for (j = i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1733 if (!(val & (1 << i)))
1734 continue;
1735 if (!mixtable[i].play) {
1736 val &= ~(1 << i);
1737 continue;
1738 }
1739 j |= mixtable[i].play;
1740 }
1741 spin_lock_irqsave(&s->lock, flags);
1742 wrmixer(s, DSP_MIX_OUTMIXIDX, j);
1743 spin_unlock_irqrestore(&s->lock, flags);
1744 return 0;
1745
1746 default:
1747 i = _IOC_NR(cmd);
1748 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
1749 return -EINVAL;
1750 if (get_user(val, p))
1751 return -EFAULT;
1752 l = val & 0xff;
1753 r = (val >> 8) & 0xff;
1754 if (l > 100)
1755 l = 100;
1756 if (r > 100)
1757 r = 100;
1758 spin_lock_irqsave(&s->lock, flags);
1759 switch (mixtable[i].type) {
1760 case MT_4:
1761 if (l >= 10)
1762 l -= 10;
1763 if (r >= 10)
1764 r -= 10;
1765 frobindir(s, mixtable[i].left, 0xf0, l / 6);
1766 frobindir(s, mixtable[i].right, 0xf0, l / 6);
1767 break;
1768
1769 case MT_4MUTEMONO:
1770 rl = (l < 4 ? 0 : (l - 5) / 3) & 31;
1771 rr = (rl >> 2) & 7;
1772 wrmixer(s, mixtable[i].left, rl<<3);
1773 if (i == SOUND_MIXER_MIC)
1774 maskb(s->iobase + CODEC_CMI_MIXER2, ~0x0e, rr<<1);
1775 break;
1776
1777 case MT_5MUTEMONO:
1778 rl = l < 4 ? 0 : (l - 5) / 3;
1779 wrmixer(s, mixtable[i].left, rl<<3);
1780 l = rdmixer(s, DSP_MIX_OUTMIXIDX) & ~mixtable[i].play;
1781 r = rl ? mixtable[i].play : 0;
1782 wrmixer(s, DSP_MIX_OUTMIXIDX, l | r);
1783 /* for recording */
1784 if (i == SOUND_MIXER_MIC) {
1785 if (s->chip_version >= 37) {
1786 rr = rl >> 1;
1787 maskb(s->iobase + CODEC_CMI_MIXER2, ~0x0e, (rr&0x07)<<1);
1788 frobindir(s, DSP_MIX_EXTENSION, ~0x01, rr>>3);
1789 } else {
1790 rr = rl >> 2;
1791 maskb(s->iobase + CODEC_CMI_MIXER2, ~0x0e, rr<<1);
1792 }
1793 }
1794 break;
1795
1796 case MT_5MUTE:
1797 rl = l < 4 ? 0 : (l - 5) / 3;
1798 rr = r < 4 ? 0 : (r - 5) / 3;
1799 wrmixer(s, mixtable[i].left, rl<<3);
1800 wrmixer(s, mixtable[i].right, rr<<3);
1801 l = rdmixer(s, DSP_MIX_OUTMIXIDX);
1802 l &= ~mixtable[i].play;
1803 r = (rl|rr) ? mixtable[i].play : 0;
1804 wrmixer(s, DSP_MIX_OUTMIXIDX, l | r);
1805 break;
1806
1807 case MT_6MUTE:
1808 if (l < 6)
1809 rl = 0x00;
1810 else
1811 rl = l * 2 / 3;
1812 if (r < 6)
1813 rr = 0x00;
1814 else
1815 rr = r * 2 / 3;
1816 wrmixer(s, mixtable[i].left, rl);
1817 wrmixer(s, mixtable[i].right, rr);
1818 break;
1819 }
1820 spin_unlock_irqrestore(&s->lock, flags);
1821
1822 if (!volidx[i])
1823 return -EINVAL;
1824 s->mix.vol[volidx[i]-1] = val;
1825 return put_user(s->mix.vol[volidx[i]-1], p);
1826 }
1827}
1828
1829/* --------------------------------------------------------------------- */
1830
1831static int cm_open_mixdev(struct inode *inode, struct file *file)
1832{
1833 int minor = iminor(inode);
1834 struct list_head *list;
1835 struct cm_state *s;
1836
1837 for (list = devs.next; ; list = list->next) {
1838 if (list == &devs)
1839 return -ENODEV;
1840 s = list_entry(list, struct cm_state, devs);
1841 if (s->dev_mixer == minor)
1842 break;
1843 }
1844 VALIDATE_STATE(s);
1845 file->private_data = s;
1846 return nonseekable_open(inode, file);
1847}
1848
1849static int cm_release_mixdev(struct inode *inode, struct file *file)
1850{
1851 struct cm_state *s = (struct cm_state *)file->private_data;
1852
1853 VALIDATE_STATE(s);
1854 return 0;
1855}
1856
1857static int cm_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1858{
1859 return mixer_ioctl((struct cm_state *)file->private_data, cmd, arg);
1860}
1861
1862static /*const*/ struct file_operations cm_mixer_fops = {
1863 .owner = THIS_MODULE,
1864 .llseek = no_llseek,
1865 .ioctl = cm_ioctl_mixdev,
1866 .open = cm_open_mixdev,
1867 .release = cm_release_mixdev,
1868};
1869
1870
1871/* --------------------------------------------------------------------- */
1872
1873static int drain_dac(struct cm_state *s, int nonblock)
1874{
1875 DECLARE_WAITQUEUE(wait, current);
1876 unsigned long flags;
1877 int count, tmo;
1878
1879 if (s->dma_dac.mapped || !s->dma_dac.ready)
1880 return 0;
1881 add_wait_queue(&s->dma_dac.wait, &wait);
1882 for (;;) {
1883 __set_current_state(TASK_INTERRUPTIBLE);
1884 spin_lock_irqsave(&s->lock, flags);
1885 count = s->dma_dac.count;
1886 spin_unlock_irqrestore(&s->lock, flags);
1887 if (count <= 0)
1888 break;
1889 if (signal_pending(current))
1890 break;
1891 if (nonblock) {
1892 remove_wait_queue(&s->dma_dac.wait, &wait);
1893 set_current_state(TASK_RUNNING);
1894 return -EBUSY;
1895 }
1896 tmo = 3 * HZ * (count + s->dma_dac.fragsize) / 2 / s->ratedac;
1897 tmo >>= sample_shift[(s->fmt >> CM_CFMT_DACSHIFT) & CM_CFMT_MASK];
1898 if (!schedule_timeout(tmo + 1))
1899 DBG(printk(KERN_DEBUG "cmpci: dma timed out??\n");)
1900 }
1901 remove_wait_queue(&s->dma_dac.wait, &wait);
1902 set_current_state(TASK_RUNNING);
1903 if (signal_pending(current))
1904 return -ERESTARTSYS;
1905 return 0;
1906}
1907
1908/* --------------------------------------------------------------------- */
1909
1910static ssize_t cm_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1911{
1912 struct cm_state *s = (struct cm_state *)file->private_data;
1913 DECLARE_WAITQUEUE(wait, current);
1914 ssize_t ret;
1915 unsigned long flags;
1916 unsigned swptr;
1917 int cnt;
1918
1919 VALIDATE_STATE(s);
1920 if (s->dma_adc.mapped)
1921 return -ENXIO;
1922 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
1923 return ret;
1924 if (!access_ok(VERIFY_WRITE, buffer, count))
1925 return -EFAULT;
1926 ret = 0;
1927
1928 add_wait_queue(&s->dma_adc.wait, &wait);
1929 while (count > 0) {
1930 spin_lock_irqsave(&s->lock, flags);
1931 swptr = s->dma_adc.swptr;
1932 cnt = s->dma_adc.dmasize-swptr;
1933 if (s->dma_adc.count < cnt)
1934 cnt = s->dma_adc.count;
1935 if (cnt <= 0)
1936 __set_current_state(TASK_INTERRUPTIBLE);
1937 spin_unlock_irqrestore(&s->lock, flags);
1938 if (cnt > count)
1939 cnt = count;
1940 if (cnt <= 0) {
1941 if (s->dma_adc.enabled)
1942 start_adc(s);
1943 if (file->f_flags & O_NONBLOCK) {
1944 if (!ret)
1945 ret = -EAGAIN;
1946 goto out;
1947 }
1948 if (!schedule_timeout(HZ)) {
1949 printk(KERN_DEBUG "cmpci: read: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1950 s->dma_adc.dmasize, s->dma_adc.fragsize, s->dma_adc.count,
1951 s->dma_adc.hwptr, s->dma_adc.swptr);
1952 spin_lock_irqsave(&s->lock, flags);
1953 stop_adc_unlocked(s);
1954 set_dmaadc(s, s->dma_adc.dmaaddr, s->dma_adc.dmasamples);
1955 /* program sample counts */
1956 set_countadc(s, s->dma_adc.fragsamples);
1957 s->dma_adc.count = s->dma_adc.hwptr = s->dma_adc.swptr = 0;
1958 spin_unlock_irqrestore(&s->lock, flags);
1959 }
1960 if (signal_pending(current)) {
1961 if (!ret)
1962 ret = -ERESTARTSYS;
1963 goto out;
1964 }
1965 continue;
1966 }
1967 if (s->status & DO_BIGENDIAN_R) {
1968 int i, err;
1969 unsigned char *src;
1970 char __user *dst = buffer;
1971 unsigned char data[2];
1972
1973 src = (unsigned char *) (s->dma_adc.rawbuf + swptr);
1974 // copy left/right sample at one time
1975 for (i = 0; i < cnt / 2; i++) {
1976 data[0] = src[1];
1977 data[1] = src[0];
1978 if ((err = __put_user(data[0], dst++))) {
1979 ret = err;
1980 goto out;
1981 }
1982 if ((err = __put_user(data[1], dst++))) {
1983 ret = err;
1984 goto out;
1985 }
1986 src += 2;
1987 }
1988 } else if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
1989 if (!ret)
1990 ret = -EFAULT;
1991 goto out;
1992 }
1993 swptr = (swptr + cnt) % s->dma_adc.dmasize;
1994 spin_lock_irqsave(&s->lock, flags);
1995 s->dma_adc.swptr = swptr;
1996 s->dma_adc.count -= cnt;
1997 count -= cnt;
1998 buffer += cnt;
1999 ret += cnt;
2000 if (s->dma_adc.enabled)
2001 start_adc_unlocked(s);
2002 spin_unlock_irqrestore(&s->lock, flags);
2003 }
2004out:
2005 remove_wait_queue(&s->dma_adc.wait, &wait);
2006 set_current_state(TASK_RUNNING);
2007 return ret;
2008}
2009
2010static ssize_t cm_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2011{
2012 struct cm_state *s = (struct cm_state *)file->private_data;
2013 DECLARE_WAITQUEUE(wait, current);
2014 ssize_t ret;
2015 unsigned long flags;
2016 unsigned swptr;
2017 int cnt;
2018
2019 VALIDATE_STATE(s);
2020 if (s->dma_dac.mapped)
2021 return -ENXIO;
2022 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
2023 return ret;
2024 if (!access_ok(VERIFY_READ, buffer, count))
2025 return -EFAULT;
2026 if (s->status & DO_DUAL_DAC) {
2027 if (s->dma_adc.mapped)
2028 return -ENXIO;
2029 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
2030 return ret;
2031 }
2032 if (!access_ok(VERIFY_READ, buffer, count))
2033 return -EFAULT;
2034 ret = 0;
2035
2036 add_wait_queue(&s->dma_dac.wait, &wait);
2037 while (count > 0) {
2038 spin_lock_irqsave(&s->lock, flags);
2039 if (s->dma_dac.count < 0) {
2040 s->dma_dac.count = 0;
2041 s->dma_dac.swptr = s->dma_dac.hwptr;
2042 }
2043 if (s->status & DO_DUAL_DAC) {
2044 s->dma_adc.swptr = s->dma_dac.swptr;
2045 s->dma_adc.count = s->dma_dac.count;
2046 s->dma_adc.endcleared = s->dma_dac.endcleared;
2047 }
2048 swptr = s->dma_dac.swptr;
2049 cnt = s->dma_dac.dmasize-swptr;
2050 if (s->status & DO_AC3_SW) {
2051 if (s->dma_dac.count + 2 * cnt > s->dma_dac.dmasize)
2052 cnt = (s->dma_dac.dmasize - s->dma_dac.count) / 2;
2053 } else {
2054 if (s->dma_dac.count + cnt > s->dma_dac.dmasize)
2055 cnt = s->dma_dac.dmasize - s->dma_dac.count;
2056 }
2057 if (cnt <= 0)
2058 __set_current_state(TASK_INTERRUPTIBLE);
2059 spin_unlock_irqrestore(&s->lock, flags);
2060 if (cnt > count)
2061 cnt = count;
2062 if ((s->status & DO_DUAL_DAC) && (cnt > count / 2))
2063 cnt = count / 2;
2064 if (cnt <= 0) {
2065 if (s->dma_dac.enabled)
2066 start_dac(s);
2067 if (file->f_flags & O_NONBLOCK) {
2068 if (!ret)
2069 ret = -EAGAIN;
2070 goto out;
2071 }
2072 if (!schedule_timeout(HZ)) {
2073 printk(KERN_DEBUG "cmpci: write: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
2074 s->dma_dac.dmasize, s->dma_dac.fragsize, s->dma_dac.count,
2075 s->dma_dac.hwptr, s->dma_dac.swptr);
2076 spin_lock_irqsave(&s->lock, flags);
2077 stop_dac_unlocked(s);
2078 set_dmadac(s, s->dma_dac.dmaaddr, s->dma_dac.dmasamples);
2079 /* program sample counts */
2080 set_countdac(s, s->dma_dac.fragsamples);
2081 s->dma_dac.count = s->dma_dac.hwptr = s->dma_dac.swptr = 0;
2082 if (s->status & DO_DUAL_DAC) {
2083 set_dmadac1(s, s->dma_adc.dmaaddr, s->dma_adc.dmasamples);
2084 s->dma_adc.count = s->dma_adc.hwptr = s->dma_adc.swptr = 0;
2085 }
2086 spin_unlock_irqrestore(&s->lock, flags);
2087 }
2088 if (signal_pending(current)) {
2089 if (!ret)
2090 ret = -ERESTARTSYS;
2091 goto out;
2092 }
2093 continue;
2094 }
2095 if (s->status & DO_AC3_SW) {
2096 int err;
2097
2098 // clip exceeded data, caught by 033 and 037
2099 if (swptr + 2 * cnt > s->dma_dac.dmasize)
2100 cnt = (s->dma_dac.dmasize - swptr) / 2;
2101 if ((err = trans_ac3(s, s->dma_dac.rawbuf + swptr, buffer, cnt))) {
2102 ret = err;
2103 goto out;
2104 }
2105 swptr = (swptr + 2 * cnt) % s->dma_dac.dmasize;
2106 } else if ((s->status & DO_DUAL_DAC) && (s->status & DO_BIGENDIAN_W)) {
2107 int i, err;
2108 const char __user *src = buffer;
2109 unsigned char *dst0, *dst1;
2110 unsigned char data[8];
2111
2112 dst0 = (unsigned char *) (s->dma_dac.rawbuf + swptr);
2113 dst1 = (unsigned char *) (s->dma_adc.rawbuf + swptr);
2114 // copy left/right sample at one time
2115 for (i = 0; i < cnt / 4; i++) {
2116 if ((err = __get_user(data[0], src++))) {
2117 ret = err;
2118 goto out;
2119 }
2120 if ((err = __get_user(data[1], src++))) {
2121 ret = err;
2122 goto out;
2123 }
2124 if ((err = __get_user(data[2], src++))) {
2125 ret = err;
2126 goto out;
2127 }
2128 if ((err = __get_user(data[3], src++))) {
2129 ret = err;
2130 goto out;
2131 }
2132 if ((err = __get_user(data[4], src++))) {
2133 ret = err;
2134 goto out;
2135 }
2136 if ((err = __get_user(data[5], src++))) {
2137 ret = err;
2138 goto out;
2139 }
2140 if ((err = __get_user(data[6], src++))) {
2141 ret = err;
2142 goto out;
2143 }
2144 if ((err = __get_user(data[7], src++))) {
2145 ret = err;
2146 goto out;
2147 }
2148 dst0[0] = data[1];
2149 dst0[1] = data[0];
2150 dst0[2] = data[3];
2151 dst0[3] = data[2];
2152 dst1[0] = data[5];
2153 dst1[1] = data[4];
2154 dst1[2] = data[7];
2155 dst1[3] = data[6];
2156 dst0 += 4;
2157 dst1 += 4;
2158 }
2159 swptr = (swptr + cnt) % s->dma_dac.dmasize;
2160 } else if (s->status & DO_DUAL_DAC) {
2161 int i, err;
2162 unsigned long __user *src = (unsigned long __user *) buffer;
2163 unsigned long *dst0, *dst1;
2164
2165 dst0 = (unsigned long *) (s->dma_dac.rawbuf + swptr);
2166 dst1 = (unsigned long *) (s->dma_adc.rawbuf + swptr);
2167 // copy left/right sample at one time
2168 for (i = 0; i < cnt / 4; i++) {
2169 if ((err = __get_user(*dst0++, src++))) {
2170 ret = err;
2171 goto out;
2172 }
2173 if ((err = __get_user(*dst1++, src++))) {
2174 ret = err;
2175 goto out;
2176 }
2177 }
2178 swptr = (swptr + cnt) % s->dma_dac.dmasize;
2179 } else if (s->status & DO_BIGENDIAN_W) {
2180 int i, err;
2181 const char __user *src = buffer;
2182 unsigned char *dst;
2183 unsigned char data[2];
2184
2185 dst = (unsigned char *) (s->dma_dac.rawbuf + swptr);
2186 // swap hi/lo bytes for each sample
2187 for (i = 0; i < cnt / 2; i++) {
2188 if ((err = __get_user(data[0], src++))) {
2189 ret = err;
2190 goto out;
2191 }
2192 if ((err = __get_user(data[1], src++))) {
2193 ret = err;
2194 goto out;
2195 }
2196 dst[0] = data[1];
2197 dst[1] = data[0];
2198 dst += 2;
2199 }
2200 swptr = (swptr + cnt) % s->dma_dac.dmasize;
2201 } else {
2202 if (copy_from_user(s->dma_dac.rawbuf + swptr, buffer, cnt)) {
2203 if (!ret)
2204 ret = -EFAULT;
2205 goto out;
2206 }
2207 swptr = (swptr + cnt) % s->dma_dac.dmasize;
2208 }
2209 spin_lock_irqsave(&s->lock, flags);
2210 s->dma_dac.swptr = swptr;
2211 s->dma_dac.count += cnt;
2212 if (s->status & DO_AC3_SW)
2213 s->dma_dac.count += cnt;
2214 s->dma_dac.endcleared = 0;
2215 spin_unlock_irqrestore(&s->lock, flags);
2216 count -= cnt;
2217 buffer += cnt;
2218 ret += cnt;
2219 if (s->status & DO_DUAL_DAC) {
2220 count -= cnt;
2221 buffer += cnt;
2222 ret += cnt;
2223 }
2224 if (s->dma_dac.enabled)
2225 start_dac(s);
2226 }
2227out:
2228 remove_wait_queue(&s->dma_dac.wait, &wait);
2229 set_current_state(TASK_RUNNING);
2230 return ret;
2231}
2232
2233static unsigned int cm_poll(struct file *file, struct poll_table_struct *wait)
2234{
2235 struct cm_state *s = (struct cm_state *)file->private_data;
2236 unsigned long flags;
2237 unsigned int mask = 0;
2238
2239 VALIDATE_STATE(s);
2240 if (file->f_mode & FMODE_WRITE) {
2241 if (!s->dma_dac.ready && prog_dmabuf(s, 0))
2242 return 0;
2243 poll_wait(file, &s->dma_dac.wait, wait);
2244 }
2245 if (file->f_mode & FMODE_READ) {
2246 if (!s->dma_adc.ready && prog_dmabuf(s, 1))
2247 return 0;
2248 poll_wait(file, &s->dma_adc.wait, wait);
2249 }
2250 spin_lock_irqsave(&s->lock, flags);
2251 cm_update_ptr(s);
2252 if (file->f_mode & FMODE_READ) {
2253 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
2254 mask |= POLLIN | POLLRDNORM;
2255 }
2256 if (file->f_mode & FMODE_WRITE) {
2257 if (s->dma_dac.mapped) {
2258 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
2259 mask |= POLLOUT | POLLWRNORM;
2260 } else {
2261 if ((signed)s->dma_dac.dmasize >= s->dma_dac.count + (signed)s->dma_dac.fragsize)
2262 mask |= POLLOUT | POLLWRNORM;
2263 }
2264 }
2265 spin_unlock_irqrestore(&s->lock, flags);
2266 return mask;
2267}
2268
2269static int cm_mmap(struct file *file, struct vm_area_struct *vma)
2270{
2271 struct cm_state *s = (struct cm_state *)file->private_data;
2272 struct dmabuf *db;
2273 int ret = -EINVAL;
2274 unsigned long size;
2275
2276 VALIDATE_STATE(s);
2277 lock_kernel();
2278 if (vma->vm_flags & VM_WRITE) {
2279 if ((ret = prog_dmabuf(s, 0)) != 0)
2280 goto out;
2281 db = &s->dma_dac;
2282 } else if (vma->vm_flags & VM_READ) {
2283 if ((ret = prog_dmabuf(s, 1)) != 0)
2284 goto out;
2285 db = &s->dma_adc;
2286 } else
2287 goto out;
2288 ret = -EINVAL;
2289 if (vma->vm_pgoff != 0)
2290 goto out;
2291 size = vma->vm_end - vma->vm_start;
2292 if (size > (PAGE_SIZE << db->buforder))
2293 goto out;
2294 ret = -EINVAL;
2295 if (remap_pfn_range(vma, vma->vm_start,
2296 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
2297 size, vma->vm_page_prot))
2298 goto out;
2299 db->mapped = 1;
2300 ret = 0;
2301out:
2302 unlock_kernel();
2303 return ret;
2304}
2305
2306#define SNDCTL_SPDIF_COPYRIGHT _SIOW('S', 0, int) // set/reset S/PDIF copy protection
2307#define SNDCTL_SPDIF_LOOP _SIOW('S', 1, int) // set/reset S/PDIF loop
2308#define SNDCTL_SPDIF_MONITOR _SIOW('S', 2, int) // set S/PDIF monitor
2309#define SNDCTL_SPDIF_LEVEL _SIOW('S', 3, int) // set/reset S/PDIF out level
2310#define SNDCTL_SPDIF_INV _SIOW('S', 4, int) // set/reset S/PDIF in inverse
2311#define SNDCTL_SPDIF_SEL2 _SIOW('S', 5, int) // set S/PDIF in #2
2312#define SNDCTL_SPDIF_VALID _SIOW('S', 6, int) // set S/PDIF valid
2313#define SNDCTL_SPDIFOUT _SIOW('S', 7, int) // set S/PDIF out
2314#define SNDCTL_SPDIFIN _SIOW('S', 8, int) // set S/PDIF out
2315
2316static int cm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2317{
2318 struct cm_state *s = (struct cm_state *)file->private_data;
2319 unsigned long flags;
2320 audio_buf_info abinfo;
2321 count_info cinfo;
2322 int val, mapped, ret;
2323 unsigned char fmtm, fmtd;
2324 void __user *argp = (void __user *)arg;
2325 int __user *p = argp;
2326
2327 VALIDATE_STATE(s);
2328 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
2329 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
2330 switch (cmd) {
2331 case OSS_GETVERSION:
2332 return put_user(SOUND_VERSION, p);
2333
2334 case SNDCTL_DSP_SYNC:
2335 if (file->f_mode & FMODE_WRITE)
2336 return drain_dac(s, 0/*file->f_flags & O_NONBLOCK*/);
2337 return 0;
2338
2339 case SNDCTL_DSP_SETDUPLEX:
2340 return 0;
2341
2342 case SNDCTL_DSP_GETCAPS:
2343 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP | DSP_CAP_BIND, p);
2344
2345 case SNDCTL_DSP_RESET:
2346 if (file->f_mode & FMODE_WRITE) {
2347 stop_dac(s);
2348 synchronize_irq(s->irq);
2349 s->dma_dac.swptr = s->dma_dac.hwptr = s->dma_dac.count = s->dma_dac.total_bytes = 0;
2350 if (s->status & DO_DUAL_DAC)
2351 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
2352 }
2353 if (file->f_mode & FMODE_READ) {
2354 stop_adc(s);
2355 synchronize_irq(s->irq);
2356 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
2357 }
2358 return 0;
2359
2360 case SNDCTL_DSP_SPEED:
2361 if (get_user(val, p))
2362 return -EFAULT;
2363 if (val >= 0) {
2364 if (file->f_mode & FMODE_READ) {
2365 spin_lock_irqsave(&s->lock, flags);
2366 stop_adc_unlocked(s);
2367 s->dma_adc.ready = 0;
2368 set_adc_rate_unlocked(s, val);
2369 spin_unlock_irqrestore(&s->lock, flags);
2370 }
2371 if (file->f_mode & FMODE_WRITE) {
2372 stop_dac(s);
2373 s->dma_dac.ready = 0;
2374 if (s->status & DO_DUAL_DAC)
2375 s->dma_adc.ready = 0;
2376 set_dac_rate(s, val);
2377 }
2378 }
2379 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
2380
2381 case SNDCTL_DSP_STEREO:
2382 if (get_user(val, p))
2383 return -EFAULT;
2384 fmtd = 0;
2385 fmtm = ~0;
2386 if (file->f_mode & FMODE_READ) {
2387 stop_adc(s);
2388 s->dma_adc.ready = 0;
2389 if (val)
2390 fmtd |= CM_CFMT_STEREO << CM_CFMT_ADCSHIFT;
2391 else
2392 fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_ADCSHIFT);
2393 }
2394 if (file->f_mode & FMODE_WRITE) {
2395 stop_dac(s);
2396 s->dma_dac.ready = 0;
2397 if (val)
2398 fmtd |= CM_CFMT_STEREO << CM_CFMT_DACSHIFT;
2399 else
2400 fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_DACSHIFT);
2401 if (s->status & DO_DUAL_DAC) {
2402 s->dma_adc.ready = 0;
2403 if (val)
2404 fmtd |= CM_CFMT_STEREO << CM_CFMT_ADCSHIFT;
2405 else
2406 fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_ADCSHIFT);
2407 }
2408 }
2409 set_fmt(s, fmtm, fmtd);
2410 return 0;
2411
2412 case SNDCTL_DSP_CHANNELS:
2413 if (get_user(val, p))
2414 return -EFAULT;
2415 if (val != 0) {
2416 fmtd = 0;
2417 fmtm = ~0;
2418 if (file->f_mode & FMODE_READ) {
2419 stop_adc(s);
2420 s->dma_adc.ready = 0;
2421 if (val >= 2)
2422 fmtd |= CM_CFMT_STEREO << CM_CFMT_ADCSHIFT;
2423 else
2424 fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_ADCSHIFT);
2425 }
2426 if (file->f_mode & FMODE_WRITE) {
2427 stop_dac(s);
2428 s->dma_dac.ready = 0;
2429 if (val >= 2)
2430 fmtd |= CM_CFMT_STEREO << CM_CFMT_DACSHIFT;
2431 else
2432 fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_DACSHIFT);
2433 if (s->status & DO_DUAL_DAC) {
2434 s->dma_adc.ready = 0;
2435 if (val >= 2)
2436 fmtd |= CM_CFMT_STEREO << CM_CFMT_ADCSHIFT;
2437 else
2438 fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_ADCSHIFT);
2439 }
2440 }
2441 set_fmt(s, fmtm, fmtd);
2442 if ((s->capability & CAN_MULTI_CH)
2443 && (file->f_mode & FMODE_WRITE)) {
2444 val = set_dac_channels(s, val);
2445 return put_user(val, p);
2446 }
2447 }
2448 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_STEREO << CM_CFMT_ADCSHIFT)
2449 : (CM_CFMT_STEREO << CM_CFMT_DACSHIFT))) ? 2 : 1, p);
2450
2451 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
2452 return put_user(AFMT_S16_BE|AFMT_S16_LE|AFMT_U8|
2453 ((s->capability & CAN_AC3) ? AFMT_AC3 : 0), p);
2454
2455 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
2456 if (get_user(val, p))
2457 return -EFAULT;
2458 if (val != AFMT_QUERY) {
2459 fmtd = 0;
2460 fmtm = ~0;
2461 if (file->f_mode & FMODE_READ) {
2462 stop_adc(s);
2463 s->dma_adc.ready = 0;
2464 if (val == AFMT_S16_BE || val == AFMT_S16_LE)
2465 fmtd |= CM_CFMT_16BIT << CM_CFMT_ADCSHIFT;
2466 else
2467 fmtm &= ~(CM_CFMT_16BIT << CM_CFMT_ADCSHIFT);
2468 if (val == AFMT_S16_BE)
2469 s->status |= DO_BIGENDIAN_R;
2470 else
2471 s->status &= ~DO_BIGENDIAN_R;
2472 }
2473 if (file->f_mode & FMODE_WRITE) {
2474 stop_dac(s);
2475 s->dma_dac.ready = 0;
2476 if (val == AFMT_S16_BE || val == AFMT_S16_LE || val == AFMT_AC3)
2477 fmtd |= CM_CFMT_16BIT << CM_CFMT_DACSHIFT;
2478 else
2479 fmtm &= ~(CM_CFMT_16BIT << CM_CFMT_DACSHIFT);
2480 if (val == AFMT_AC3) {
2481 fmtd |= CM_CFMT_STEREO << CM_CFMT_DACSHIFT;
2482 set_ac3(s, 48000);
2483 } else
2484 set_ac3(s, 0);
2485 if (s->status & DO_DUAL_DAC) {
2486 s->dma_adc.ready = 0;
2487 if (val == AFMT_S16_BE || val == AFMT_S16_LE)
2488 fmtd |= CM_CFMT_STEREO << CM_CFMT_ADCSHIFT;
2489 else
2490 fmtm &= ~(CM_CFMT_STEREO << CM_CFMT_ADCSHIFT);
2491 }
2492 if (val == AFMT_S16_BE)
2493 s->status |= DO_BIGENDIAN_W;
2494 else
2495 s->status &= ~DO_BIGENDIAN_W;
2496 }
2497 set_fmt(s, fmtm, fmtd);
2498 }
2499 if (s->status & DO_AC3) return put_user(AFMT_AC3, p);
2500 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_16BIT << CM_CFMT_ADCSHIFT)
2501 : (CM_CFMT_16BIT << CM_CFMT_DACSHIFT))) ? val : AFMT_U8, p);
2502
2503 case SNDCTL_DSP_POST:
2504 return 0;
2505
2506 case SNDCTL_DSP_GETTRIGGER:
2507 val = 0;
2508 if (s->status & DO_DUAL_DAC) {
2509 if (file->f_mode & FMODE_WRITE &&
2510 (s->enable & ENDAC) &&
2511 (s->enable & ENADC))
2512 val |= PCM_ENABLE_OUTPUT;
2513 return put_user(val, p);
2514 }
2515 if (file->f_mode & FMODE_READ && s->enable & ENADC)
2516 val |= PCM_ENABLE_INPUT;
2517 if (file->f_mode & FMODE_WRITE && s->enable & ENDAC)
2518 val |= PCM_ENABLE_OUTPUT;
2519 return put_user(val, p);
2520
2521 case SNDCTL_DSP_SETTRIGGER:
2522 if (get_user(val, p))
2523 return -EFAULT;
2524 if (file->f_mode & FMODE_READ) {
2525 if (val & PCM_ENABLE_INPUT) {
2526 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
2527 return ret;
2528 s->dma_adc.enabled = 1;
2529 start_adc(s);
2530 } else {
2531 s->dma_adc.enabled = 0;
2532 stop_adc(s);
2533 }
2534 }
2535 if (file->f_mode & FMODE_WRITE) {
2536 if (val & PCM_ENABLE_OUTPUT) {
2537 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
2538 return ret;
2539 if (s->status & DO_DUAL_DAC) {
2540 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
2541 return ret;
2542 }
2543 s->dma_dac.enabled = 1;
2544 start_dac(s);
2545 } else {
2546 s->dma_dac.enabled = 0;
2547 stop_dac(s);
2548 }
2549 }
2550 return 0;
2551
2552 case SNDCTL_DSP_GETOSPACE:
2553 if (!(file->f_mode & FMODE_WRITE))
2554 return -EINVAL;
2555 if (!(s->enable & ENDAC) && (val = prog_dmabuf(s, 0)) != 0)
2556 return val;
2557 spin_lock_irqsave(&s->lock, flags);
2558 cm_update_ptr(s);
2559 abinfo.fragsize = s->dma_dac.fragsize;
2560 abinfo.bytes = s->dma_dac.dmasize - s->dma_dac.count;
2561 abinfo.fragstotal = s->dma_dac.numfrag;
2562 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
2563 spin_unlock_irqrestore(&s->lock, flags);
2564 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2565
2566 case SNDCTL_DSP_GETISPACE:
2567 if (!(file->f_mode & FMODE_READ))
2568 return -EINVAL;
2569 if (!(s->enable & ENADC) && (val = prog_dmabuf(s, 1)) != 0)
2570 return val;
2571 spin_lock_irqsave(&s->lock, flags);
2572 cm_update_ptr(s);
2573 abinfo.fragsize = s->dma_adc.fragsize;
2574 abinfo.bytes = s->dma_adc.count;
2575 abinfo.fragstotal = s->dma_adc.numfrag;
2576 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
2577 spin_unlock_irqrestore(&s->lock, flags);
2578 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2579
2580 case SNDCTL_DSP_NONBLOCK:
2581 file->f_flags |= O_NONBLOCK;
2582 return 0;
2583
2584 case SNDCTL_DSP_GETODELAY:
2585 if (!(file->f_mode & FMODE_WRITE))
2586 return -EINVAL;
2587 spin_lock_irqsave(&s->lock, flags);
2588 cm_update_ptr(s);
2589 val = s->dma_dac.count;
2590 spin_unlock_irqrestore(&s->lock, flags);
2591 return put_user(val, p);
2592
2593 case SNDCTL_DSP_GETIPTR:
2594 if (!(file->f_mode & FMODE_READ))
2595 return -EINVAL;
2596 spin_lock_irqsave(&s->lock, flags);
2597 cm_update_ptr(s);
2598 cinfo.bytes = s->dma_adc.total_bytes;
2599 cinfo.blocks = s->dma_adc.count >> s->dma_adc.fragshift;
2600 cinfo.ptr = s->dma_adc.hwptr;
2601 if (s->dma_adc.mapped)
2602 s->dma_adc.count &= s->dma_adc.fragsize-1;
2603 spin_unlock_irqrestore(&s->lock, flags);
2604 return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2605
2606 case SNDCTL_DSP_GETOPTR:
2607 if (!(file->f_mode & FMODE_WRITE))
2608 return -EINVAL;
2609 spin_lock_irqsave(&s->lock, flags);
2610 cm_update_ptr(s);
2611 cinfo.bytes = s->dma_dac.total_bytes;
2612 cinfo.blocks = s->dma_dac.count >> s->dma_dac.fragshift;
2613 cinfo.ptr = s->dma_dac.hwptr;
2614 if (s->dma_dac.mapped)
2615 s->dma_dac.count &= s->dma_dac.fragsize-1;
2616 if (s->status & DO_DUAL_DAC) {
2617 if (s->dma_adc.mapped)
2618 s->dma_adc.count &= s->dma_adc.fragsize-1;
2619 }
2620 spin_unlock_irqrestore(&s->lock, flags);
2621 return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2622
2623 case SNDCTL_DSP_GETBLKSIZE:
2624 if (file->f_mode & FMODE_WRITE) {
2625 if ((val = prog_dmabuf(s, 0)))
2626 return val;
2627 if (s->status & DO_DUAL_DAC) {
2628 if ((val = prog_dmabuf(s, 1)))
2629 return val;
2630 return put_user(2 * s->dma_dac.fragsize, p);
2631 }
2632 return put_user(s->dma_dac.fragsize, p);
2633 }
2634 if ((val = prog_dmabuf(s, 1)))
2635 return val;
2636 return put_user(s->dma_adc.fragsize, p);
2637
2638 case SNDCTL_DSP_SETFRAGMENT:
2639 if (get_user(val, p))
2640 return -EFAULT;
2641 if (file->f_mode & FMODE_READ) {
2642 s->dma_adc.ossfragshift = val & 0xffff;
2643 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
2644 if (s->dma_adc.ossfragshift < 4)
2645 s->dma_adc.ossfragshift = 4;
2646 if (s->dma_adc.ossfragshift > 15)
2647 s->dma_adc.ossfragshift = 15;
2648 if (s->dma_adc.ossmaxfrags < 4)
2649 s->dma_adc.ossmaxfrags = 4;
2650 }
2651 if (file->f_mode & FMODE_WRITE) {
2652 s->dma_dac.ossfragshift = val & 0xffff;
2653 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
2654 if (s->dma_dac.ossfragshift < 4)
2655 s->dma_dac.ossfragshift = 4;
2656 if (s->dma_dac.ossfragshift > 15)
2657 s->dma_dac.ossfragshift = 15;
2658 if (s->dma_dac.ossmaxfrags < 4)
2659 s->dma_dac.ossmaxfrags = 4;
2660 if (s->status & DO_DUAL_DAC) {
2661 s->dma_adc.ossfragshift = s->dma_dac.ossfragshift;
2662 s->dma_adc.ossmaxfrags = s->dma_dac.ossmaxfrags;
2663 }
2664 }
2665 return 0;
2666
2667 case SNDCTL_DSP_SUBDIVIDE:
2668 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
2669 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
2670 return -EINVAL;
2671 if (get_user(val, p))
2672 return -EFAULT;
2673 if (val != 1 && val != 2 && val != 4)
2674 return -EINVAL;
2675 if (file->f_mode & FMODE_READ)
2676 s->dma_adc.subdivision = val;
2677 if (file->f_mode & FMODE_WRITE) {
2678 s->dma_dac.subdivision = val;
2679 if (s->status & DO_DUAL_DAC)
2680 s->dma_adc.subdivision = val;
2681 }
2682 return 0;
2683
2684 case SOUND_PCM_READ_RATE:
2685 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
2686
2687 case SOUND_PCM_READ_CHANNELS:
2688 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_STEREO << CM_CFMT_ADCSHIFT) : (CM_CFMT_STEREO << CM_CFMT_DACSHIFT))) ? 2 : 1, p);
2689
2690 case SOUND_PCM_READ_BITS:
2691 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_16BIT << CM_CFMT_ADCSHIFT) : (CM_CFMT_16BIT << CM_CFMT_DACSHIFT))) ? 16 : 8, p);
2692
2693 case SOUND_PCM_READ_FILTER:
2694 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
2695
2696 case SNDCTL_DSP_GETCHANNELMASK:
2697 return put_user(DSP_BIND_FRONT|DSP_BIND_SURR|DSP_BIND_CENTER_LFE|DSP_BIND_SPDIF, p);
2698
2699 case SNDCTL_DSP_BIND_CHANNEL:
2700 if (get_user(val, p))
2701 return -EFAULT;
2702 if (val == DSP_BIND_QUERY) {
2703 val = DSP_BIND_FRONT;
2704 if (s->status & DO_SPDIF_OUT)
2705 val |= DSP_BIND_SPDIF;
2706 else {
2707 if (s->curr_channels == 4)
2708 val |= DSP_BIND_SURR;
2709 if (s->curr_channels > 4)
2710 val |= DSP_BIND_CENTER_LFE;
2711 }
2712 } else {
2713 if (file->f_mode & FMODE_READ) {
2714 stop_adc(s);
2715 s->dma_adc.ready = 0;
2716 if (val & DSP_BIND_SPDIF) {
2717 set_spdifin(s, s->rateadc);
2718 if (!(s->status & DO_SPDIF_OUT))
2719 val &= ~DSP_BIND_SPDIF;
2720 }
2721 }
2722 if (file->f_mode & FMODE_WRITE) {
2723 stop_dac(s);
2724 s->dma_dac.ready = 0;
2725 if (val & DSP_BIND_SPDIF) {
2726 set_spdifout(s, s->ratedac);
2727 set_dac_channels(s, s->fmt & (CM_CFMT_STEREO << CM_CFMT_DACSHIFT) ? 2 : 1);
2728 if (!(s->status & DO_SPDIF_OUT))
2729 val &= ~DSP_BIND_SPDIF;
2730 } else {
2731 int channels;
2732 int mask;
2733
2734 mask = val & (DSP_BIND_FRONT|DSP_BIND_SURR|DSP_BIND_CENTER_LFE);
2735 switch (mask) {
2736 case DSP_BIND_FRONT:
2737 channels = 2;
2738 break;
2739 case DSP_BIND_FRONT|DSP_BIND_SURR:
2740 channels = 4;
2741 break;
2742 case DSP_BIND_FRONT|DSP_BIND_SURR|DSP_BIND_CENTER_LFE:
2743 channels = 6;
2744 break;
2745 default:
2746 channels = s->fmt & (CM_CFMT_STEREO << CM_CFMT_DACSHIFT) ? 2 : 1;
2747 break;
2748 }
2749 set_dac_channels(s, channels);
2750 }
2751 }
2752 }
2753 return put_user(val, p);
2754
2755 case SOUND_PCM_WRITE_FILTER:
2756 case SNDCTL_DSP_MAPINBUF:
2757 case SNDCTL_DSP_MAPOUTBUF:
2758 case SNDCTL_DSP_SETSYNCRO:
2759 return -EINVAL;
2760 case SNDCTL_SPDIF_COPYRIGHT:
2761 if (get_user(val, p))
2762 return -EFAULT;
2763 set_spdif_copyright(s, val);
2764 return 0;
2765 case SNDCTL_SPDIF_LOOP:
2766 if (get_user(val, p))
2767 return -EFAULT;
2768 set_spdif_loop(s, val);
2769 return 0;
2770 case SNDCTL_SPDIF_MONITOR:
2771 if (get_user(val, p))
2772 return -EFAULT;
2773 set_spdif_monitor(s, val);
2774 return 0;
2775 case SNDCTL_SPDIF_LEVEL:
2776 if (get_user(val, p))
2777 return -EFAULT;
2778 set_spdifout_level(s, val);
2779 return 0;
2780 case SNDCTL_SPDIF_INV:
2781 if (get_user(val, p))
2782 return -EFAULT;
2783 set_spdifin_inverse(s, val);
2784 return 0;
2785 case SNDCTL_SPDIF_SEL2:
2786 if (get_user(val, p))
2787 return -EFAULT;
2788 set_spdifin_channel2(s, val);
2789 return 0;
2790 case SNDCTL_SPDIF_VALID:
2791 if (get_user(val, p))
2792 return -EFAULT;
2793 set_spdifin_valid(s, val);
2794 return 0;
2795 case SNDCTL_SPDIFOUT:
2796 if (get_user(val, p))
2797 return -EFAULT;
2798 set_spdifout(s, val ? s->ratedac : 0);
2799 return 0;
2800 case SNDCTL_SPDIFIN:
2801 if (get_user(val, p))
2802 return -EFAULT;
2803 set_spdifin(s, val ? s->rateadc : 0);
2804 return 0;
2805 }
2806 return mixer_ioctl(s, cmd, arg);
2807}
2808
2809static int cm_open(struct inode *inode, struct file *file)
2810{
2811 int minor = iminor(inode);
2812 DECLARE_WAITQUEUE(wait, current);
2813 unsigned char fmtm = ~0, fmts = 0;
2814 struct list_head *list;
2815 struct cm_state *s;
2816
2817 for (list = devs.next; ; list = list->next) {
2818 if (list == &devs)
2819 return -ENODEV;
2820 s = list_entry(list, struct cm_state, devs);
2821 if (!((s->dev_audio ^ minor) & ~0xf))
2822 break;
2823 }
2824 VALIDATE_STATE(s);
2825 file->private_data = s;
2826 /* wait for device to become free */
2827 down(&s->open_sem);
2828 while (s->open_mode & file->f_mode) {
2829 if (file->f_flags & O_NONBLOCK) {
2830 up(&s->open_sem);
2831 return -EBUSY;
2832 }
2833 add_wait_queue(&s->open_wait, &wait);
2834 __set_current_state(TASK_INTERRUPTIBLE);
2835 up(&s->open_sem);
2836 schedule();
2837 remove_wait_queue(&s->open_wait, &wait);
2838 set_current_state(TASK_RUNNING);
2839 if (signal_pending(current))
2840 return -ERESTARTSYS;
2841 down(&s->open_sem);
2842 }
2843 if (file->f_mode & FMODE_READ) {
2844 s->status &= ~DO_BIGENDIAN_R;
2845 fmtm &= ~((CM_CFMT_STEREO | CM_CFMT_16BIT) << CM_CFMT_ADCSHIFT);
2846 if ((minor & 0xf) == SND_DEV_DSP16)
2847 fmts |= CM_CFMT_16BIT << CM_CFMT_ADCSHIFT;
2848 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
2849 s->dma_adc.enabled = 1;
2850 set_adc_rate(s, 8000);
2851 // spdif-in is turnned off by default
2852 set_spdifin(s, 0);
2853 }
2854 if (file->f_mode & FMODE_WRITE) {
2855 s->status &= ~DO_BIGENDIAN_W;
2856 fmtm &= ~((CM_CFMT_STEREO | CM_CFMT_16BIT) << CM_CFMT_DACSHIFT);
2857 if ((minor & 0xf) == SND_DEV_DSP16)
2858 fmts |= CM_CFMT_16BIT << CM_CFMT_DACSHIFT;
2859 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = s->dma_dac.subdivision = 0;
2860 s->dma_dac.enabled = 1;
2861 set_dac_rate(s, 8000);
2862 // clear previous multichannel, spdif, ac3 state
2863 set_spdifout(s, 0);
2864 set_ac3(s, 0);
2865 set_dac_channels(s, 1);
2866 }
2867 set_fmt(s, fmtm, fmts);
2868 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2869 up(&s->open_sem);
2870 return nonseekable_open(inode, file);
2871}
2872
2873static int cm_release(struct inode *inode, struct file *file)
2874{
2875 struct cm_state *s = (struct cm_state *)file->private_data;
2876
2877 VALIDATE_STATE(s);
2878 lock_kernel();
2879 if (file->f_mode & FMODE_WRITE)
2880 drain_dac(s, file->f_flags & O_NONBLOCK);
2881 down(&s->open_sem);
2882 if (file->f_mode & FMODE_WRITE) {
2883 stop_dac(s);
2884
2885 dealloc_dmabuf(s, &s->dma_dac);
2886 if (s->status & DO_DUAL_DAC)
2887 dealloc_dmabuf(s, &s->dma_adc);
2888
2889 if (s->status & DO_MULTI_CH)
2890 set_dac_channels(s, 1);
2891 if (s->status & DO_AC3)
2892 set_ac3(s, 0);
2893 if (s->status & DO_SPDIF_OUT)
2894 set_spdifout(s, 0);
2895 /* enable SPDIF loop */
2896 set_spdif_loop(s, spdif_loop);
2897 s->status &= ~DO_BIGENDIAN_W;
2898 }
2899 if (file->f_mode & FMODE_READ) {
2900 stop_adc(s);
2901 dealloc_dmabuf(s, &s->dma_adc);
2902 s->status &= ~DO_BIGENDIAN_R;
2903 }
2904 s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
2905 up(&s->open_sem);
2906 wake_up(&s->open_wait);
2907 unlock_kernel();
2908 return 0;
2909}
2910
2911static /*const*/ struct file_operations cm_audio_fops = {
2912 .owner = THIS_MODULE,
2913 .llseek = no_llseek,
2914 .read = cm_read,
2915 .write = cm_write,
2916 .poll = cm_poll,
2917 .ioctl = cm_ioctl,
2918 .mmap = cm_mmap,
2919 .open = cm_open,
2920 .release = cm_release,
2921};
2922
2923/* --------------------------------------------------------------------- */
2924
2925static struct initvol {
2926 int mixch;
2927 int vol;
2928} initvol[] __devinitdata = {
2929 { SOUND_MIXER_WRITE_CD, 0x4f4f },
2930 { SOUND_MIXER_WRITE_LINE, 0x4f4f },
2931 { SOUND_MIXER_WRITE_MIC, 0x4f4f },
2932 { SOUND_MIXER_WRITE_SYNTH, 0x4f4f },
2933 { SOUND_MIXER_WRITE_VOLUME, 0x4f4f },
2934 { SOUND_MIXER_WRITE_PCM, 0x4f4f }
2935};
2936
2937/* check chip version and capability */
2938static int query_chip(struct cm_state *s)
2939{
2940 int ChipVersion = -1;
2941 unsigned char RegValue;
2942
2943 // check reg 0Ch, bit 24-31
2944 RegValue = inb(s->iobase + CODEC_CMI_INT_HLDCLR + 3);
2945 if (RegValue == 0) {
2946 // check reg 08h, bit 24-28
2947 RegValue = inb(s->iobase + CODEC_CMI_CHFORMAT + 3);
2948 RegValue &= 0x1f;
2949 if (RegValue == 0) {
2950 ChipVersion = 33;
2951 s->max_channels = 4;
2952 s->capability |= CAN_AC3_SW;
2953 s->capability |= CAN_DUAL_DAC;
2954 } else {
2955 ChipVersion = 37;
2956 s->max_channels = 4;
2957 s->capability |= CAN_AC3_HW;
2958 s->capability |= CAN_DUAL_DAC;
2959 }
2960 } else {
2961 // check reg 0Ch, bit 26
2962 if (RegValue & (1 << (26-24))) {
2963 ChipVersion = 39;
2964 if (RegValue & (1 << (24-24)))
2965 s->max_channels = 6;
2966 else
2967 s->max_channels = 4;
2968 s->capability |= CAN_AC3_HW;
2969 s->capability |= CAN_DUAL_DAC;
2970 s->capability |= CAN_MULTI_CH_HW;
2971 s->capability |= CAN_LINE_AS_BASS;
2972 s->capability |= CAN_MIC_AS_BASS;
2973 } else {
2974 ChipVersion = 55; // 4 or 6 channels
2975 s->max_channels = 6;
2976 s->capability |= CAN_AC3_HW;
2977 s->capability |= CAN_DUAL_DAC;
2978 s->capability |= CAN_MULTI_CH_HW;
2979 s->capability |= CAN_LINE_AS_BASS;
2980 s->capability |= CAN_MIC_AS_BASS;
2981 }
2982 }
2983 s->capability |= CAN_LINE_AS_REAR;
2984 return ChipVersion;
2985}
2986
2987#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
2988static int __devinit cm_create_gameport(struct cm_state *s, int io_port)
2989{
2990 struct gameport *gp;
2991
2992 if (!request_region(io_port, CM_EXTENT_GAME, "cmpci GAME")) {
2993 printk(KERN_ERR "cmpci: gameport io ports 0x%#x in use\n", io_port);
2994 return -EBUSY;
2995 }
2996
2997 if (!(s->gameport = gp = gameport_allocate_port())) {
2998 printk(KERN_ERR "cmpci: can not allocate memory for gameport\n");
2999 release_region(io_port, CM_EXTENT_GAME);
3000 return -ENOMEM;
3001 }
3002
3003 gameport_set_name(gp, "C-Media GP");
3004 gameport_set_phys(gp, "pci%s/gameport0", pci_name(s->dev));
3005 gp->dev.parent = &s->dev->dev;
3006 gp->io = io_port;
3007
3008 /* enable joystick */
3009 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x02);
3010
3011 gameport_register_port(gp);
3012
3013 return 0;
3014}
3015
3016static void __devexit cm_free_gameport(struct cm_state *s)
3017{
3018 if (s->gameport) {
3019 int gpio = s->gameport->io;
3020
3021 gameport_unregister_port(s->gameport);
3022 s->gameport = NULL;
3023 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
3024 release_region(gpio, CM_EXTENT_GAME);
3025 }
3026}
3027#else
3028static inline int cm_create_gameport(struct cm_state *s, int io_port) { return -ENOSYS; }
3029static inline void cm_free_gameport(struct cm_state *s) { }
3030#endif
3031
3032#define echo_option(x)\
3033if (x) strcat(options, "" #x " ")
3034
3035static int __devinit cm_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
3036{
3037 struct cm_state *s;
3038 mm_segment_t fs;
3039 int i, val, ret;
3040 unsigned char reg_mask;
3041 int timeout;
3042 struct resource *ports;
3043 struct {
3044 unsigned short deviceid;
3045 char *devicename;
3046 } devicetable[] = {
3047 { PCI_DEVICE_ID_CMEDIA_CM8338A, "CM8338A" },
3048 { PCI_DEVICE_ID_CMEDIA_CM8338B, "CM8338B" },
3049 { PCI_DEVICE_ID_CMEDIA_CM8738, "CM8738" },
3050 { PCI_DEVICE_ID_CMEDIA_CM8738B, "CM8738B" },
3051 };
3052 char *devicename = "unknown";
3053 char options[256];
3054
3055 if ((ret = pci_enable_device(pcidev)))
3056 return ret;
3057 if (!(pci_resource_flags(pcidev, 0) & IORESOURCE_IO))
3058 return -ENODEV;
3059 if (pcidev->irq == 0)
3060 return -ENODEV;
3061 i = pci_set_dma_mask(pcidev, 0xffffffff);
3062 if (i) {
3063 printk(KERN_WARNING "cmpci: architecture does not support 32bit PCI busmaster DMA\n");
3064 return i;
3065 }
3066 s = kmalloc(sizeof(*s), GFP_KERNEL);
3067 if (!s) {
3068 printk(KERN_WARNING "cmpci: out of memory\n");
3069 return -ENOMEM;
3070 }
3071 /* search device name */
3072 for (i = 0; i < sizeof(devicetable) / sizeof(devicetable[0]); i++) {
3073 if (devicetable[i].deviceid == pcidev->device) {
3074 devicename = devicetable[i].devicename;
3075 break;
3076 }
3077 }
3078 memset(s, 0, sizeof(struct cm_state));
3079 init_waitqueue_head(&s->dma_adc.wait);
3080 init_waitqueue_head(&s->dma_dac.wait);
3081 init_waitqueue_head(&s->open_wait);
3082 init_MUTEX(&s->open_sem);
3083 spin_lock_init(&s->lock);
3084 s->magic = CM_MAGIC;
3085 s->dev = pcidev;
3086 s->iobase = pci_resource_start(pcidev, 0);
3087 s->iosynth = fmio;
3088 s->iomidi = mpuio;
3089#ifdef CONFIG_SOUND_CMPCI_MIDI
3090 s->midi_devc = 0;
3091#endif
3092 s->status = 0;
3093 if (s->iobase == 0)
3094 return -ENODEV;
3095 s->irq = pcidev->irq;
3096
3097 if (!request_region(s->iobase, CM_EXTENT_CODEC, "cmpci")) {
3098 printk(KERN_ERR "cmpci: io ports %#x-%#x in use\n", s->iobase, s->iobase+CM_EXTENT_CODEC-1);
3099 ret = -EBUSY;
3100 goto err_region5;
3101 }
3102 /* dump parameters */
3103 strcpy(options, "cmpci: ");
3104 echo_option(joystick);
3105 echo_option(spdif_inverse);
3106 echo_option(spdif_loop);
3107 echo_option(spdif_out);
3108 echo_option(use_line_as_rear);
3109 echo_option(use_line_as_bass);
3110 echo_option(use_mic_as_bass);
3111 echo_option(mic_boost);
3112 echo_option(hw_copy);
3113 printk(KERN_INFO "%s\n", options);
3114
3115 /* initialize codec registers */
3116 outb(0, s->iobase + CODEC_CMI_INT_HLDCLR + 2); /* disable ints */
3117 outb(0, s->iobase + CODEC_CMI_FUNCTRL0 + 2); /* disable channels */
3118 /* reset mixer */
3119 wrmixer(s, DSP_MIX_DATARESETIDX, 0);
3120
3121 /* request irq */
3122 if ((ret = request_irq(s->irq, cm_interrupt, SA_SHIRQ, "cmpci", s))) {
3123 printk(KERN_ERR "cmpci: irq %u in use\n", s->irq);
3124 goto err_irq;
3125 }
3126 printk(KERN_INFO "cmpci: found %s adapter at io %#x irq %u\n",
3127 devicename, s->iobase, s->irq);
3128 /* register devices */
3129 if ((s->dev_audio = register_sound_dsp(&cm_audio_fops, -1)) < 0) {
3130 ret = s->dev_audio;
3131 goto err_dev1;
3132 }
3133 if ((s->dev_mixer = register_sound_mixer(&cm_mixer_fops, -1)) < 0) {
3134 ret = s->dev_mixer;
3135 goto err_dev2;
3136 }
3137 pci_set_master(pcidev); /* enable bus mastering */
3138 /* initialize the chips */
3139 fs = get_fs();
3140 set_fs(KERNEL_DS);
3141 /* set mixer output */
3142 frobindir(s, DSP_MIX_OUTMIXIDX, 0x1f, 0x1f);
3143 /* set mixer input */
3144 val = SOUND_MASK_LINE|SOUND_MASK_SYNTH|SOUND_MASK_CD|SOUND_MASK_MIC;
3145 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
3146 for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
3147 val = initvol[i].vol;
3148 mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val);
3149 }
3150 set_fs(fs);
3151 /* use channel 1 for playback, channel 0 for record */
3152 maskb(s->iobase + CODEC_CMI_FUNCTRL0, ~CHADC1, CHADC0);
3153 /* turn off VMIC3 - mic boost */
3154 if (mic_boost)
3155 maskb(s->iobase + CODEC_CMI_MIXER2, ~1, 0);
3156 else
3157 maskb(s->iobase + CODEC_CMI_MIXER2, ~0, 1);
3158 s->deviceid = pcidev->device;
3159
3160 if (pcidev->device == PCI_DEVICE_ID_CMEDIA_CM8738
3161 || pcidev->device == PCI_DEVICE_ID_CMEDIA_CM8738B) {
3162
3163 /* chip version and hw capability check */
3164 s->chip_version = query_chip(s);
3165 printk(KERN_INFO "cmpci: chip version = 0%d\n", s->chip_version);
3166
3167 /* set SPDIF-in inverse before enable SPDIF loop */
3168 set_spdifin_inverse(s, spdif_inverse);
3169
3170 /* use SPDIF in #1 */
3171 set_spdifin_channel2(s, 0);
3172 } else {
3173 s->chip_version = 0;
3174 /* 8338 will fall here */
3175 s->max_channels = 4;
3176 s->capability |= CAN_DUAL_DAC;
3177 s->capability |= CAN_LINE_AS_REAR;
3178 }
3179 /* enable SPDIF loop */
3180 set_spdif_loop(s, spdif_loop);
3181
3182 // enable 4 speaker mode (analog duplicate)
3183 set_hw_copy(s, hw_copy);
3184
3185 reg_mask = 0;
3186#ifdef CONFIG_SOUND_CMPCI_FM
3187 /* disable FM */
3188 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~8, 0);
3189 if (s->iosynth) {
3190 /* don't enable OPL3 if there is one */
3191 if (opl3_detect(s->iosynth, NULL)) {
3192 s->iosynth = 0;
3193 } else {
3194 /* set IO based at 0x388 */
3195 switch (s->iosynth) {
3196 case 0x388:
3197 reg_mask = 0;
3198 break;
3199 case 0x3C8:
3200 reg_mask = 0x01;
3201 break;
3202 case 0x3E0:
3203 reg_mask = 0x02;
3204 break;
3205 case 0x3E8:
3206 reg_mask = 0x03;
3207 break;
3208 default:
3209 s->iosynth = 0;
3210 break;
3211 }
3212 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 3, ~0x03, reg_mask);
3213 /* enable FM */
3214 if (s->iosynth) {
3215 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~0, 8);
3216 if (opl3_detect(s->iosynth, NULL))
3217 ret = opl3_init(s->iosynth, NULL, THIS_MODULE);
3218 else {
3219 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~8, 0);
3220 s->iosynth = 0;
3221 }
3222 }
3223 }
3224 }
3225#endif
3226#ifdef CONFIG_SOUND_CMPCI_MIDI
3227 switch (s->iomidi) {
3228 case 0x330:
3229 reg_mask = 0;
3230 break;
3231 case 0x320:
3232 reg_mask = 0x20;
3233 break;
3234 case 0x310:
3235 reg_mask = 0x40;
3236 break;
3237 case 0x300:
3238 reg_mask = 0x60;
3239 break;
3240 default:
3241 s->iomidi = 0;
3242 goto skip_mpu;
3243 }
3244 ports = request_region(s->iomidi, 2, "mpu401");
3245 if (!ports)
3246 goto skip_mpu;
3247 /* disable MPU-401 */
3248 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x04, 0);
3249 s->mpu_data.name = "cmpci mpu";
3250 s->mpu_data.io_base = s->iomidi;
3251 s->mpu_data.irq = -s->irq; // tell mpu401 to share irq
3252 if (probe_mpu401(&s->mpu_data, ports)) {
3253 release_region(s->iomidi, 2);
3254 s->iomidi = 0;
3255 goto skip_mpu;
3256 }
3257 maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 3, ~0x60, reg_mask);
3258 /* enable MPU-401 */
3259 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04);
3260 /* clear all previously received interrupt */
3261 for (timeout = 900000; timeout > 0; timeout--) {
3262 if ((inb(s->iomidi + 1) && 0x80) == 0)
3263 inb(s->iomidi);
3264 else
3265 break;
3266 }
3267 if (!probe_mpu401(&s->mpu_data, ports)) {
3268 release_region(s->iomidi, 2);
3269 s->iomidi = 0;
3270 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04);
3271 } else {
3272 attach_mpu401(&s->mpu_data, THIS_MODULE);
3273 s->midi_devc = s->mpu_data.slots[1];
3274 }
3275skip_mpu:
3276#endif
3277 /* disable joystick port */
3278 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
3279 if (joystick)
3280 cm_create_gameport(s, 0x200);
3281
3282 /* store it in the driver field */
3283 pci_set_drvdata(pcidev, s);
3284 /* put it into driver list */
3285 list_add_tail(&s->devs, &devs);
3286 /* increment devindex */
3287 if (devindex < NR_DEVICE-1)
3288 devindex++;
3289 return 0;
3290
3291err_dev2:
3292 unregister_sound_dsp(s->dev_audio);
3293err_dev1:
3294 printk(KERN_ERR "cmpci: cannot register misc device\n");
3295 free_irq(s->irq, s);
3296err_irq:
3297 release_region(s->iobase, CM_EXTENT_CODEC);
3298err_region5:
3299 kfree(s);
3300 return ret;
3301}
3302
3303/* --------------------------------------------------------------------- */
3304
3305MODULE_AUTHOR("ChenLi Tien, cltien@cmedia.com.tw");
3306MODULE_DESCRIPTION("CM8x38 Audio Driver");
3307MODULE_LICENSE("GPL");
3308
3309static void __devexit cm_remove(struct pci_dev *dev)
3310{
3311 struct cm_state *s = pci_get_drvdata(dev);
3312
3313 if (!s)
3314 return;
3315
3316 cm_free_gameport(s);
3317
3318#ifdef CONFIG_SOUND_CMPCI_FM
3319 if (s->iosynth) {
3320 /* disable FM */
3321 maskb(s->iobase + CODEC_CMI_MISC_CTRL + 2, ~8, 0);
3322 }
3323#endif
3324#ifdef CONFIG_SOUND_CMPCI_MIDI
3325 if (s->iomidi) {
3326 unload_mpu401(&s->mpu_data);
3327 /* disable MPU-401 */
3328 maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x04, 0);
3329 }
3330#endif
3331 set_spdif_loop(s, 0);
3332 list_del(&s->devs);
3333 outb(0, s->iobase + CODEC_CMI_INT_HLDCLR + 2); /* disable ints */
3334 synchronize_irq(s->irq);
3335 outb(0, s->iobase + CODEC_CMI_FUNCTRL0 + 2); /* disable channels */
3336 free_irq(s->irq, s);
3337
3338 /* reset mixer */
3339 wrmixer(s, DSP_MIX_DATARESETIDX, 0);
3340
3341 release_region(s->iobase, CM_EXTENT_CODEC);
3342 unregister_sound_dsp(s->dev_audio);
3343 unregister_sound_mixer(s->dev_mixer);
3344 kfree(s);
3345 pci_set_drvdata(dev, NULL);
3346}
3347
3348static struct pci_device_id id_table[] __devinitdata = {
3349 { PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738B, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
3350 { PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
3351 { PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
3352 { PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
3353 { 0, }
3354};
3355
3356MODULE_DEVICE_TABLE(pci, id_table);
3357
3358static struct pci_driver cm_driver = {
3359 .name = "cmpci",
3360 .id_table = id_table,
3361 .probe = cm_probe,
3362 .remove = __devexit_p(cm_remove)
3363};
3364
3365static int __init init_cmpci(void)
3366{
3367 printk(KERN_INFO "cmpci: version $Revision: 6.82 $ time " __TIME__ " " __DATE__ "\n");
3368 return pci_module_init(&cm_driver);
3369}
3370
3371static void __exit cleanup_cmpci(void)
3372{
3373 printk(KERN_INFO "cmpci: unloading\n");
3374 pci_unregister_driver(&cm_driver);
3375}
3376
3377module_init(init_cmpci);
3378module_exit(cleanup_cmpci);
diff --git a/sound/oss/coproc.h b/sound/oss/coproc.h
new file mode 100644
index 000000000000..7306346e9ac4
--- /dev/null
+++ b/sound/oss/coproc.h
@@ -0,0 +1,12 @@
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/cs4232.c b/sound/oss/cs4232.c
new file mode 100644
index 000000000000..6ec308f5d935
--- /dev/null
+++ b/sound/oss/cs4232.c
@@ -0,0 +1,520 @@
1/*
2 * Copyright (C) by Hannu Savolainen 1993-1997
3 *
4 * cs4232.c
5 *
6 * The low level driver for Crystal CS4232 based cards. The CS4232 is
7 * a PnP compatible chip which contains a CS4231A codec, SB emulation,
8 * a MPU401 compatible MIDI port, joystick and synthesizer and IDE CD-ROM
9 * interfaces. This is just a temporary driver until full PnP support
10 * gets implemented. Just the WSS codec, FM synth and the MIDI ports are
11 * supported. Other interfaces are left uninitialized.
12 *
13 * ifdef ...WAVEFRONT...
14 *
15 * Support is provided for initializing the WaveFront synth
16 * interface as well, which is logical device #4. Note that if
17 * you have a Tropez+ card, you probably don't need to setup
18 * the CS4232-supported MIDI interface, since it corresponds to
19 * the internal 26-pin header that's hard to access. Using this
20 * requires an additional IRQ, a resource none too plentiful in
21 * this environment. Just don't set module parameters mpuio and
22 * mpuirq, and the MIDI port will be left uninitialized. You can
23 * still use the ICS2115 hosted MIDI interface which corresponds
24 * to the 9-pin D connector on the back of the card.
25 *
26 * endif ...WAVEFRONT...
27 *
28 * Supported chips are:
29 * CS4232
30 * CS4236
31 * CS4236B
32 *
33 * Note: You will need a PnP config setup to initialise some CS4232 boards
34 * anyway.
35 *
36 * Changes
37 * John Rood Added Bose Sound System Support.
38 * Toshio Spoor
39 * Alan Cox Modularisation, Basic cleanups.
40 * Paul Barton-Davis Separated MPU configuration, added
41 * Tropez+ (WaveFront) support
42 * Christoph Hellwig Adapted to module_init/module_exit,
43 * simple cleanups
44 * Arnaldo C. de Melo got rid of attach_uart401
45 * Bartlomiej Zolnierkiewicz
46 * Added some __init/__initdata/__exit
47 * Marcus Meissner Added ISA PnP support.
48 */
49
50#include <linux/config.h>
51#include <linux/pnp.h>
52#include <linux/module.h>
53#include <linux/init.h>
54
55#include "sound_config.h"
56
57#include "ad1848.h"
58#include "mpu401.h"
59
60#define KEY_PORT 0x279 /* Same as LPT1 status port */
61#define CSN_NUM 0x99 /* Just a random number */
62#define INDEX_ADDRESS 0x00 /* (R0) Index Address Register */
63#define INDEX_DATA 0x01 /* (R1) Indexed Data Register */
64#define PIN_CONTROL 0x0a /* (I10) Pin Control */
65#define ENABLE_PINS 0xc0 /* XCTRL0/XCTRL1 enable */
66
67static void CS_OUT(unsigned char a)
68{
69 outb(a, KEY_PORT);
70}
71
72#define CS_OUT2(a, b) {CS_OUT(a);CS_OUT(b);}
73#define CS_OUT3(a, b, c) {CS_OUT(a);CS_OUT(b);CS_OUT(c);}
74
75static int __initdata bss = 0;
76static int mpu_base, mpu_irq;
77static int synth_base, synth_irq;
78static int mpu_detected;
79
80static int probe_cs4232_mpu(struct address_info *hw_config)
81{
82 /*
83 * Just write down the config values.
84 */
85
86 mpu_base = hw_config->io_base;
87 mpu_irq = hw_config->irq;
88
89 return 1;
90}
91
92static unsigned char crystal_key[] = /* A 32 byte magic key sequence */
93{
94 0x96, 0x35, 0x9a, 0xcd, 0xe6, 0xf3, 0x79, 0xbc,
95 0x5e, 0xaf, 0x57, 0x2b, 0x15, 0x8a, 0xc5, 0xe2,
96 0xf1, 0xf8, 0x7c, 0x3e, 0x9f, 0x4f, 0x27, 0x13,
97 0x09, 0x84, 0x42, 0xa1, 0xd0, 0x68, 0x34, 0x1a
98};
99
100static void sleep(unsigned howlong)
101{
102 current->state = TASK_INTERRUPTIBLE;
103 schedule_timeout(howlong);
104}
105
106static void enable_xctrl(int baseio)
107{
108 unsigned char regd;
109
110 /*
111 * Some IBM Aptiva's have the Bose Sound System. By default
112 * the Bose Amplifier is disabled. The amplifier will be
113 * activated, by setting the XCTRL0 and XCTRL1 bits.
114 * Volume of the monitor bose speakers/woofer, can then
115 * be set by changing the PCM volume.
116 *
117 */
118
119 printk("cs4232: enabling Bose Sound System Amplifier.\n");
120
121 /* Switch to Pin Control Address */
122 regd = inb(baseio + INDEX_ADDRESS) & 0xe0;
123 outb(((unsigned char) (PIN_CONTROL | regd)), baseio + INDEX_ADDRESS );
124
125 /* Activate the XCTRL0 and XCTRL1 Pins */
126 regd = inb(baseio + INDEX_DATA);
127 outb(((unsigned char) (ENABLE_PINS | regd)), baseio + INDEX_DATA );
128}
129
130static int __init probe_cs4232(struct address_info *hw_config, int isapnp_configured)
131{
132 int i, n;
133 int base = hw_config->io_base, irq = hw_config->irq;
134 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
135 struct resource *ports;
136
137 if (base == -1 || irq == -1 || dma1 == -1) {
138 printk(KERN_ERR "cs4232: dma, irq and io must be set.\n");
139 return 0;
140 }
141
142 /*
143 * Verify that the I/O port range is free.
144 */
145
146 ports = request_region(base, 4, "ad1848");
147 if (!ports) {
148 printk(KERN_ERR "cs4232.c: I/O port 0x%03x not free\n", base);
149 return 0;
150 }
151 if (ad1848_detect(ports, NULL, hw_config->osp)) {
152 goto got_it; /* The card is already active */
153 }
154 if (isapnp_configured) {
155 printk(KERN_ERR "cs4232.c: ISA PnP configured, but not detected?\n");
156 goto fail;
157 }
158
159 /*
160 * This version of the driver doesn't use the PnP method when configuring
161 * the card but a simplified method defined by Crystal. This means that
162 * just one CS4232 compatible device can exist on the system. Also this
163 * method conflicts with possible PnP support in the OS. For this reason
164 * driver is just a temporary kludge.
165 *
166 * Also the Cirrus/Crystal method doesn't always work. Try ISA PnP first ;)
167 */
168
169 /*
170 * Repeat initialization few times since it doesn't always succeed in
171 * first time.
172 */
173
174 for (n = 0; n < 4; n++)
175 {
176 /*
177 * Wake up the card by sending a 32 byte Crystal key to the key port.
178 */
179
180 for (i = 0; i < 32; i++)
181 CS_OUT(crystal_key[i]);
182
183 sleep(HZ / 10);
184
185 /*
186 * Now set the CSN (Card Select Number).
187 */
188
189 CS_OUT2(0x06, CSN_NUM);
190
191 /*
192 * Then set some config bytes. First logical device 0
193 */
194
195 CS_OUT2(0x15, 0x00); /* Select logical device 0 (WSS/SB/FM) */
196 CS_OUT3(0x47, (base >> 8) & 0xff, base & 0xff); /* WSS base */
197
198 if (check_region(0x388, 4)) /* Not free */
199 CS_OUT3(0x48, 0x00, 0x00) /* FM base off */
200 else
201 CS_OUT3(0x48, 0x03, 0x88); /* FM base 0x388 */
202
203 CS_OUT3(0x42, 0x00, 0x00); /* SB base off */
204 CS_OUT2(0x22, irq); /* SB+WSS IRQ */
205 CS_OUT2(0x2a, dma1); /* SB+WSS DMA */
206
207 if (dma2 != -1)
208 CS_OUT2(0x25, dma2) /* WSS DMA2 */
209 else
210 CS_OUT2(0x25, 4); /* No WSS DMA2 */
211
212 CS_OUT2(0x33, 0x01); /* Activate logical dev 0 */
213
214 sleep(HZ / 10);
215
216 /*
217 * Initialize logical device 3 (MPU)
218 */
219
220 if (mpu_base != 0 && mpu_irq != 0)
221 {
222 CS_OUT2(0x15, 0x03); /* Select logical device 3 (MPU) */
223 CS_OUT3(0x47, (mpu_base >> 8) & 0xff, mpu_base & 0xff); /* MPU base */
224 CS_OUT2(0x22, mpu_irq); /* MPU IRQ */
225 CS_OUT2(0x33, 0x01); /* Activate logical dev 3 */
226 }
227
228 if(synth_base != 0)
229 {
230 CS_OUT2 (0x15, 0x04); /* logical device 4 (WaveFront) */
231 CS_OUT3 (0x47, (synth_base >> 8) & 0xff,
232 synth_base & 0xff); /* base */
233 CS_OUT2 (0x22, synth_irq); /* IRQ */
234 CS_OUT2 (0x33, 0x01); /* Activate logical dev 4 */
235 }
236
237 /*
238 * Finally activate the chip
239 */
240
241 CS_OUT(0x79);
242
243 sleep(HZ / 5);
244
245 /*
246 * Then try to detect the codec part of the chip
247 */
248
249 if (ad1848_detect(ports, NULL, hw_config->osp))
250 goto got_it;
251
252 sleep(HZ);
253 }
254fail:
255 release_region(base, 4);
256 return 0;
257
258got_it:
259 if (dma2 == -1)
260 dma2 = dma1;
261
262 hw_config->slots[0] = ad1848_init("Crystal audio controller", ports,
263 irq,
264 dma1, /* Playback DMA */
265 dma2, /* Capture DMA */
266 0,
267 hw_config->osp,
268 THIS_MODULE);
269
270 if (hw_config->slots[0] != -1 &&
271 audio_devs[hw_config->slots[0]]->mixer_dev!=-1)
272 {
273 /* Assume the mixer map is as suggested in the CS4232 databook */
274 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE);
275 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD);
276 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_SYNTH); /* FM synth */
277 }
278 if (mpu_base != 0 && mpu_irq != 0)
279 {
280 static struct address_info hw_config2 = {
281 0
282 }; /* Ensure it's initialized */
283
284 hw_config2.io_base = mpu_base;
285 hw_config2.irq = mpu_irq;
286 hw_config2.dma = -1;
287 hw_config2.dma2 = -1;
288 hw_config2.always_detect = 0;
289 hw_config2.name = NULL;
290 hw_config2.driver_use_1 = 0;
291 hw_config2.driver_use_2 = 0;
292 hw_config2.card_subtype = 0;
293
294 if (probe_uart401(&hw_config2, THIS_MODULE))
295 {
296 mpu_detected = 1;
297 }
298 else
299 {
300 mpu_base = mpu_irq = 0;
301 }
302 hw_config->slots[1] = hw_config2.slots[1];
303 }
304
305 if (bss)
306 enable_xctrl(base);
307
308 return 1;
309}
310
311static void __devexit unload_cs4232(struct address_info *hw_config)
312{
313 int base = hw_config->io_base, irq = hw_config->irq;
314 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
315
316 if (dma2 == -1)
317 dma2 = dma1;
318
319 ad1848_unload(base,
320 irq,
321 dma1, /* Playback DMA */
322 dma2, /* Capture DMA */
323 0);
324
325 sound_unload_audiodev(hw_config->slots[0]);
326 if (mpu_base != 0 && mpu_irq != 0 && mpu_detected)
327 {
328 static struct address_info hw_config2 =
329 {
330 0
331 }; /* Ensure it's initialized */
332
333 hw_config2.io_base = mpu_base;
334 hw_config2.irq = mpu_irq;
335 hw_config2.dma = -1;
336 hw_config2.dma2 = -1;
337 hw_config2.always_detect = 0;
338 hw_config2.name = NULL;
339 hw_config2.driver_use_1 = 0;
340 hw_config2.driver_use_2 = 0;
341 hw_config2.card_subtype = 0;
342 hw_config2.slots[1] = hw_config->slots[1];
343
344 unload_uart401(&hw_config2);
345 }
346}
347
348static struct address_info cfg;
349static struct address_info cfg_mpu;
350
351static int __initdata io = -1;
352static int __initdata irq = -1;
353static int __initdata dma = -1;
354static int __initdata dma2 = -1;
355static int __initdata mpuio = -1;
356static int __initdata mpuirq = -1;
357static int __initdata synthio = -1;
358static int __initdata synthirq = -1;
359static int __initdata isapnp = 1;
360
361MODULE_DESCRIPTION("CS4232 based soundcard driver");
362MODULE_AUTHOR("Hannu Savolainen, Paul Barton-Davis");
363MODULE_LICENSE("GPL");
364
365module_param(io, int, 0);
366MODULE_PARM_DESC(io,"base I/O port for AD1848");
367module_param(irq, int, 0);
368MODULE_PARM_DESC(irq,"IRQ for AD1848 chip");
369module_param(dma, int, 0);
370MODULE_PARM_DESC(dma,"8 bit DMA for AD1848 chip");
371module_param(dma2, int, 0);
372MODULE_PARM_DESC(dma2,"16 bit DMA for AD1848 chip");
373module_param(mpuio, int, 0);
374MODULE_PARM_DESC(mpuio,"MPU 401 base address");
375module_param(mpuirq, int, 0);
376MODULE_PARM_DESC(mpuirq,"MPU 401 IRQ");
377module_param(synthio, int, 0);
378MODULE_PARM_DESC(synthio,"Maui WaveTable base I/O port");
379module_param(synthirq, int, 0);
380MODULE_PARM_DESC(synthirq,"Maui WaveTable IRQ");
381module_param(isapnp, bool, 0);
382MODULE_PARM_DESC(isapnp,"Enable ISAPnP probing (default 1)");
383module_param(bss, bool, 0);
384MODULE_PARM_DESC(bss,"Enable Bose Sound System Support (default 0)");
385
386/*
387 * Install a CS4232 based card. Need to have ad1848 and mpu401
388 * loaded ready.
389 */
390
391/* All cs4232 based cards have the main ad1848 card either as CSC0000 or
392 * CSC0100. */
393static const struct pnp_device_id cs4232_pnp_table[] = {
394 { .id = "CSC0100", .driver_data = 0 },
395 { .id = "CSC0000", .driver_data = 0 },
396 /* Guillemot Turtlebeach something appears to be cs4232 compatible
397 * (untested) */
398 { .id = "GIM0100", .driver_data = 0 },
399 { .id = ""}
400};
401
402MODULE_DEVICE_TABLE(pnp, cs4232_pnp_table);
403
404static int cs4232_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
405{
406 struct address_info *isapnpcfg;
407
408 isapnpcfg=(struct address_info*)kmalloc(sizeof(*isapnpcfg),GFP_KERNEL);
409 if (!isapnpcfg)
410 return -ENOMEM;
411
412 isapnpcfg->irq = pnp_irq(dev, 0);
413 isapnpcfg->dma = pnp_dma(dev, 0);
414 isapnpcfg->dma2 = pnp_dma(dev, 1);
415 isapnpcfg->io_base = pnp_port_start(dev, 0);
416 if (probe_cs4232(isapnpcfg,TRUE) == 0) {
417 printk(KERN_ERR "cs4232: ISA PnP card found, but not detected?\n");
418 kfree(isapnpcfg);
419 return -ENODEV;
420 }
421 pnp_set_drvdata(dev,isapnpcfg);
422 return 0;
423}
424
425static void __devexit cs4232_pnp_remove(struct pnp_dev *dev)
426{
427 struct address_info *cfg = pnp_get_drvdata(dev);
428 if (cfg) {
429 unload_cs4232(cfg);
430 kfree(cfg);
431 }
432}
433
434static struct pnp_driver cs4232_driver = {
435 .name = "cs4232",
436 .id_table = cs4232_pnp_table,
437 .probe = cs4232_pnp_probe,
438 .remove = __devexit_p(cs4232_pnp_remove),
439};
440
441static int __init init_cs4232(void)
442{
443#ifdef CONFIG_SOUND_WAVEFRONT_MODULE
444 if(synthio == -1)
445 printk(KERN_INFO "cs4232: set synthio and synthirq to use the wavefront facilities.\n");
446 else {
447 synth_base = synthio;
448 synth_irq = synthirq;
449 }
450#else
451 if(synthio != -1)
452 printk(KERN_WARNING "cs4232: wavefront support not enabled in this driver.\n");
453#endif
454 cfg.irq = -1;
455
456 if (isapnp &&
457 (pnp_register_driver(&cs4232_driver) > 0)
458 )
459 return 0;
460
461 if(io==-1||irq==-1||dma==-1)
462 {
463 printk(KERN_ERR "cs4232: Must set io, irq and dma.\n");
464 return -ENODEV;
465 }
466
467 cfg.io_base = io;
468 cfg.irq = irq;
469 cfg.dma = dma;
470 cfg.dma2 = dma2;
471
472 cfg_mpu.io_base = -1;
473 cfg_mpu.irq = -1;
474
475 if (mpuio != -1 && mpuirq != -1) {
476 cfg_mpu.io_base = mpuio;
477 cfg_mpu.irq = mpuirq;
478 probe_cs4232_mpu(&cfg_mpu); /* Bug always returns 0 not OK -- AC */
479 }
480
481 if (probe_cs4232(&cfg,FALSE) == 0)
482 return -ENODEV;
483
484 return 0;
485}
486
487static void __exit cleanup_cs4232(void)
488{
489 pnp_unregister_driver(&cs4232_driver);
490 if (cfg.irq != -1)
491 unload_cs4232(&cfg); /* Unloads global MPU as well, if needed */
492}
493
494module_init(init_cs4232);
495module_exit(cleanup_cs4232);
496
497#ifndef MODULE
498static int __init setup_cs4232(char *str)
499{
500 /* io, irq, dma, dma2 mpuio, mpuirq*/
501 int ints[7];
502
503 /* If we have isapnp cards, no need for options */
504 if (pnp_register_driver(&cs4232_driver) > 0)
505 return 1;
506
507 str = get_options(str, ARRAY_SIZE(ints), ints);
508
509 io = ints[1];
510 irq = ints[2];
511 dma = ints[3];
512 dma2 = ints[4];
513 mpuio = ints[5];
514 mpuirq = ints[6];
515
516 return 1;
517}
518
519__setup("cs4232=", setup_cs4232);
520#endif
diff --git a/sound/oss/cs4281/Makefile b/sound/oss/cs4281/Makefile
new file mode 100644
index 000000000000..6d527e8530d6
--- /dev/null
+++ b/sound/oss/cs4281/Makefile
@@ -0,0 +1,6 @@
1# Makefile for Cirrus Logic-Crystal CS4281
2#
3
4obj-$(CONFIG_SOUND_CS4281) += cs4281.o
5
6cs4281-objs += cs4281m.o
diff --git a/sound/oss/cs4281/cs4281_hwdefs.h b/sound/oss/cs4281/cs4281_hwdefs.h
new file mode 100644
index 000000000000..701d595e33f5
--- /dev/null
+++ b/sound/oss/cs4281/cs4281_hwdefs.h
@@ -0,0 +1,1234 @@
1//****************************************************************************
2//
3// HWDEFS.H - Definitions of the registers and data structures used by the
4// CS4281
5//
6// Copyright (c) 1999,2000,2001 Crystal Semiconductor Corp.
7//
8//****************************************************************************
9
10#ifndef _H_HWDEFS
11#define _H_HWDEFS
12
13//****************************************************************************
14//
15// The following define the offsets of the registers located in the PCI
16// configuration space of the CS4281 part.
17//
18//****************************************************************************
19#define PCICONFIG_DEVID_VENID 0x00000000L
20#define PCICONFIG_STATUS_COMMAND 0x00000004L
21#define PCICONFIG_CLASS_REVISION 0x00000008L
22#define PCICONFIG_LATENCY_TIMER 0x0000000CL
23#define PCICONFIG_BA0 0x00000010L
24#define PCICONFIG_BA1 0x00000014L
25#define PCICONFIG_SUBSYSID_SUBSYSVENID 0x0000002CL
26#define PCICONFIG_INTERRUPT 0x0000003CL
27
28//****************************************************************************
29//
30// The following define the offsets of the registers accessed via base address
31// register zero on the CS4281 part.
32//
33//****************************************************************************
34#define BA0_HISR 0x00000000L
35#define BA0_HICR 0x00000008L
36#define BA0_HIMR 0x0000000CL
37#define BA0_IIER 0x00000010L
38#define BA0_HDSR0 0x000000F0L
39#define BA0_HDSR1 0x000000F4L
40#define BA0_HDSR2 0x000000F8L
41#define BA0_HDSR3 0x000000FCL
42#define BA0_DCA0 0x00000110L
43#define BA0_DCC0 0x00000114L
44#define BA0_DBA0 0x00000118L
45#define BA0_DBC0 0x0000011CL
46#define BA0_DCA1 0x00000120L
47#define BA0_DCC1 0x00000124L
48#define BA0_DBA1 0x00000128L
49#define BA0_DBC1 0x0000012CL
50#define BA0_DCA2 0x00000130L
51#define BA0_DCC2 0x00000134L
52#define BA0_DBA2 0x00000138L
53#define BA0_DBC2 0x0000013CL
54#define BA0_DCA3 0x00000140L
55#define BA0_DCC3 0x00000144L
56#define BA0_DBA3 0x00000148L
57#define BA0_DBC3 0x0000014CL
58#define BA0_DMR0 0x00000150L
59#define BA0_DCR0 0x00000154L
60#define BA0_DMR1 0x00000158L
61#define BA0_DCR1 0x0000015CL
62#define BA0_DMR2 0x00000160L
63#define BA0_DCR2 0x00000164L
64#define BA0_DMR3 0x00000168L
65#define BA0_DCR3 0x0000016CL
66#define BA0_DLMR 0x00000170L
67#define BA0_DLSR 0x00000174L
68#define BA0_FCR0 0x00000180L
69#define BA0_FCR1 0x00000184L
70#define BA0_FCR2 0x00000188L
71#define BA0_FCR3 0x0000018CL
72#define BA0_FPDR0 0x00000190L
73#define BA0_FPDR1 0x00000194L
74#define BA0_FPDR2 0x00000198L
75#define BA0_FPDR3 0x0000019CL
76#define BA0_FCHS 0x0000020CL
77#define BA0_FSIC0 0x00000210L
78#define BA0_FSIC1 0x00000214L
79#define BA0_FSIC2 0x00000218L
80#define BA0_FSIC3 0x0000021CL
81#define BA0_PCICFG00 0x00000300L
82#define BA0_PCICFG04 0x00000304L
83#define BA0_PCICFG08 0x00000308L
84#define BA0_PCICFG0C 0x0000030CL
85#define BA0_PCICFG10 0x00000310L
86#define BA0_PCICFG14 0x00000314L
87#define BA0_PCICFG18 0x00000318L
88#define BA0_PCICFG1C 0x0000031CL
89#define BA0_PCICFG20 0x00000320L
90#define BA0_PCICFG24 0x00000324L
91#define BA0_PCICFG28 0x00000328L
92#define BA0_PCICFG2C 0x0000032CL
93#define BA0_PCICFG30 0x00000330L
94#define BA0_PCICFG34 0x00000334L
95#define BA0_PCICFG38 0x00000338L
96#define BA0_PCICFG3C 0x0000033CL
97#define BA0_PCICFG40 0x00000340L
98#define BA0_PMCS 0x00000344L
99#define BA0_CWPR 0x000003E0L
100#define BA0_EPPMC 0x000003E4L
101#define BA0_GPIOR 0x000003E8L
102#define BA0_SPMC 0x000003ECL
103#define BA0_CFLR 0x000003F0L
104#define BA0_IISR 0x000003F4L
105#define BA0_TMS 0x000003F8L
106#define BA0_SSVID 0x000003FCL
107#define BA0_CLKCR1 0x00000400L
108#define BA0_FRR 0x00000410L
109#define BA0_SLT12O 0x0000041CL
110#define BA0_SERMC 0x00000420L
111#define BA0_SERC1 0x00000428L
112#define BA0_SERC2 0x0000042CL
113#define BA0_SLT12M 0x0000045CL
114#define BA0_ACCTL 0x00000460L
115#define BA0_ACSTS 0x00000464L
116#define BA0_ACOSV 0x00000468L
117#define BA0_ACCAD 0x0000046CL
118#define BA0_ACCDA 0x00000470L
119#define BA0_ACISV 0x00000474L
120#define BA0_ACSAD 0x00000478L
121#define BA0_ACSDA 0x0000047CL
122#define BA0_JSPT 0x00000480L
123#define BA0_JSCTL 0x00000484L
124#define BA0_MIDCR 0x00000490L
125#define BA0_MIDCMD 0x00000494L
126#define BA0_MIDSR 0x00000494L
127#define BA0_MIDWP 0x00000498L
128#define BA0_MIDRP 0x0000049CL
129#define BA0_AODSD1 0x000004A8L
130#define BA0_AODSD2 0x000004ACL
131#define BA0_CFGI 0x000004B0L
132#define BA0_SLT12M2 0x000004DCL
133#define BA0_ACSTS2 0x000004E4L
134#define BA0_ACISV2 0x000004F4L
135#define BA0_ACSAD2 0x000004F8L
136#define BA0_ACSDA2 0x000004FCL
137#define BA0_IOTGP 0x00000500L
138#define BA0_IOTSB 0x00000504L
139#define BA0_IOTFM 0x00000508L
140#define BA0_IOTDMA 0x0000050CL
141#define BA0_IOTAC0 0x00000500L
142#define BA0_IOTAC1 0x00000504L
143#define BA0_IOTAC2 0x00000508L
144#define BA0_IOTAC3 0x0000050CL
145#define BA0_IOTPCP 0x0000052CL
146#define BA0_IOTCC 0x00000530L
147#define BA0_IOTCR 0x0000058CL
148#define BA0_PCPRR 0x00000600L
149#define BA0_PCPGR 0x00000604L
150#define BA0_PCPCR 0x00000608L
151#define BA0_PCPCIEN 0x00000608L
152#define BA0_SBMAR 0x00000700L
153#define BA0_SBMDR 0x00000704L
154#define BA0_SBRR 0x00000708L
155#define BA0_SBRDP 0x0000070CL
156#define BA0_SBWDP 0x00000710L
157#define BA0_SBWBS 0x00000710L
158#define BA0_SBRBS 0x00000714L
159#define BA0_FMSR 0x00000730L
160#define BA0_B0AP 0x00000730L
161#define BA0_FMDP 0x00000734L
162#define BA0_B1AP 0x00000738L
163#define BA0_B1DP 0x0000073CL
164#define BA0_SSPM 0x00000740L
165#define BA0_DACSR 0x00000744L
166#define BA0_ADCSR 0x00000748L
167#define BA0_SSCR 0x0000074CL
168#define BA0_FMLVC 0x00000754L
169#define BA0_FMRVC 0x00000758L
170#define BA0_SRCSA 0x0000075CL
171#define BA0_PPLVC 0x00000760L
172#define BA0_PPRVC 0x00000764L
173#define BA0_PASR 0x00000768L
174#define BA0_CASR 0x0000076CL
175
176//****************************************************************************
177//
178// The following define the offsets of the AC97 shadow registers, which appear
179// as a virtual extension to the base address register zero memory range.
180//
181//****************************************************************************
182#define AC97_REG_OFFSET_MASK 0x0000007EL
183#define AC97_CODEC_NUMBER_MASK 0x00003000L
184
185#define BA0_AC97_RESET 0x00001000L
186#define BA0_AC97_MASTER_VOLUME 0x00001002L
187#define BA0_AC97_HEADPHONE_VOLUME 0x00001004L
188#define BA0_AC97_MASTER_VOLUME_MONO 0x00001006L
189#define BA0_AC97_MASTER_TONE 0x00001008L
190#define BA0_AC97_PC_BEEP_VOLUME 0x0000100AL
191#define BA0_AC97_PHONE_VOLUME 0x0000100CL
192#define BA0_AC97_MIC_VOLUME 0x0000100EL
193#define BA0_AC97_LINE_IN_VOLUME 0x00001010L
194#define BA0_AC97_CD_VOLUME 0x00001012L
195#define BA0_AC97_VIDEO_VOLUME 0x00001014L
196#define BA0_AC97_AUX_VOLUME 0x00001016L
197#define BA0_AC97_PCM_OUT_VOLUME 0x00001018L
198#define BA0_AC97_RECORD_SELECT 0x0000101AL
199#define BA0_AC97_RECORD_GAIN 0x0000101CL
200#define BA0_AC97_RECORD_GAIN_MIC 0x0000101EL
201#define BA0_AC97_GENERAL_PURPOSE 0x00001020L
202#define BA0_AC97_3D_CONTROL 0x00001022L
203#define BA0_AC97_MODEM_RATE 0x00001024L
204#define BA0_AC97_POWERDOWN 0x00001026L
205#define BA0_AC97_EXT_AUDIO_ID 0x00001028L
206#define BA0_AC97_EXT_AUDIO_POWER 0x0000102AL
207#define BA0_AC97_PCM_FRONT_DAC_RATE 0x0000102CL
208#define BA0_AC97_PCM_SURR_DAC_RATE 0x0000102EL
209#define BA0_AC97_PCM_LFE_DAC_RATE 0x00001030L
210#define BA0_AC97_PCM_LR_ADC_RATE 0x00001032L
211#define BA0_AC97_MIC_ADC_RATE 0x00001034L
212#define BA0_AC97_6CH_VOL_C_LFE 0x00001036L
213#define BA0_AC97_6CH_VOL_SURROUND 0x00001038L
214#define BA0_AC97_RESERVED_3A 0x0000103AL
215#define BA0_AC97_EXT_MODEM_ID 0x0000103CL
216#define BA0_AC97_EXT_MODEM_POWER 0x0000103EL
217#define BA0_AC97_LINE1_CODEC_RATE 0x00001040L
218#define BA0_AC97_LINE2_CODEC_RATE 0x00001042L
219#define BA0_AC97_HANDSET_CODEC_RATE 0x00001044L
220#define BA0_AC97_LINE1_CODEC_LEVEL 0x00001046L
221#define BA0_AC97_LINE2_CODEC_LEVEL 0x00001048L
222#define BA0_AC97_HANDSET_CODEC_LEVEL 0x0000104AL
223#define BA0_AC97_GPIO_PIN_CONFIG 0x0000104CL
224#define BA0_AC97_GPIO_PIN_TYPE 0x0000104EL
225#define BA0_AC97_GPIO_PIN_STICKY 0x00001050L
226#define BA0_AC97_GPIO_PIN_WAKEUP 0x00001052L
227#define BA0_AC97_GPIO_PIN_STATUS 0x00001054L
228#define BA0_AC97_MISC_MODEM_AFE_STAT 0x00001056L
229#define BA0_AC97_RESERVED_58 0x00001058L
230#define BA0_AC97_CRYSTAL_REV_N_FAB_ID 0x0000105AL
231#define BA0_AC97_TEST_AND_MISC_CTRL 0x0000105CL
232#define BA0_AC97_AC_MODE 0x0000105EL
233#define BA0_AC97_MISC_CRYSTAL_CONTROL 0x00001060L
234#define BA0_AC97_LINE1_HYPRID_CTRL 0x00001062L
235#define BA0_AC97_VENDOR_RESERVED_64 0x00001064L
236#define BA0_AC97_VENDOR_RESERVED_66 0x00001066L
237#define BA0_AC97_SPDIF_CONTROL 0x00001068L
238#define BA0_AC97_VENDOR_RESERVED_6A 0x0000106AL
239#define BA0_AC97_VENDOR_RESERVED_6C 0x0000106CL
240#define BA0_AC97_VENDOR_RESERVED_6E 0x0000106EL
241#define BA0_AC97_VENDOR_RESERVED_70 0x00001070L
242#define BA0_AC97_VENDOR_RESERVED_72 0x00001072L
243#define BA0_AC97_VENDOR_RESERVED_74 0x00001074L
244#define BA0_AC97_CAL_ADDRESS 0x00001076L
245#define BA0_AC97_CAL_DATA 0x00001078L
246#define BA0_AC97_VENDOR_RESERVED_7A 0x0000107AL
247#define BA0_AC97_VENDOR_ID1 0x0000107CL
248#define BA0_AC97_VENDOR_ID2 0x0000107EL
249
250//****************************************************************************
251//
252// The following define the offsets of the registers and memories accessed via
253// base address register one on the CS4281 part.
254//
255//****************************************************************************
256
257//****************************************************************************
258//
259// The following defines are for the flags in the PCI device ID/vendor ID
260// register.
261//
262//****************************************************************************
263#define PDV_VENID_MASK 0x0000FFFFL
264#define PDV_DEVID_MASK 0xFFFF0000L
265#define PDV_VENID_SHIFT 0L
266#define PDV_DEVID_SHIFT 16L
267#define VENID_CIRRUS_LOGIC 0x1013L
268#define DEVID_CS4281 0x6005L
269
270//****************************************************************************
271//
272// The following defines are for the flags in the PCI status and command
273// register.
274//
275//****************************************************************************
276#define PSC_IO_SPACE_ENABLE 0x00000001L
277#define PSC_MEMORY_SPACE_ENABLE 0x00000002L
278#define PSC_BUS_MASTER_ENABLE 0x00000004L
279#define PSC_SPECIAL_CYCLES 0x00000008L
280#define PSC_MWI_ENABLE 0x00000010L
281#define PSC_VGA_PALETTE_SNOOP 0x00000020L
282#define PSC_PARITY_RESPONSE 0x00000040L
283#define PSC_WAIT_CONTROL 0x00000080L
284#define PSC_SERR_ENABLE 0x00000100L
285#define PSC_FAST_B2B_ENABLE 0x00000200L
286#define PSC_UDF_MASK 0x007F0000L
287#define PSC_FAST_B2B_CAPABLE 0x00800000L
288#define PSC_PARITY_ERROR_DETECTED 0x01000000L
289#define PSC_DEVSEL_TIMING_MASK 0x06000000L
290#define PSC_TARGET_ABORT_SIGNALLED 0x08000000L
291#define PSC_RECEIVED_TARGET_ABORT 0x10000000L
292#define PSC_RECEIVED_MASTER_ABORT 0x20000000L
293#define PSC_SIGNALLED_SERR 0x40000000L
294#define PSC_DETECTED_PARITY_ERROR 0x80000000L
295#define PSC_UDF_SHIFT 16L
296#define PSC_DEVSEL_TIMING_SHIFT 25L
297
298//****************************************************************************
299//
300// The following defines are for the flags in the PCI class/revision ID
301// register.
302//
303//****************************************************************************
304#define PCR_REVID_MASK 0x000000FFL
305#define PCR_INTERFACE_MASK 0x0000FF00L
306#define PCR_SUBCLASS_MASK 0x00FF0000L
307#define PCR_CLASS_MASK 0xFF000000L
308#define PCR_REVID_SHIFT 0L
309#define PCR_INTERFACE_SHIFT 8L
310#define PCR_SUBCLASS_SHIFT 16L
311#define PCR_CLASS_SHIFT 24L
312
313//****************************************************************************
314//
315// The following defines are for the flags in the PCI latency timer register.
316//
317//****************************************************************************
318#define PLT_CACHE_LINE_SIZE_MASK 0x000000FFL
319#define PLT_LATENCY_TIMER_MASK 0x0000FF00L
320#define PLT_HEADER_TYPE_MASK 0x00FF0000L
321#define PLT_BIST_MASK 0xFF000000L
322#define PLT_CACHE_LINE_SIZE_SHIFT 0L
323#define PLT_LATENCY_TIMER_SHIFT 8L
324#define PLT_HEADER_TYPE_SHIFT 16L
325#define PLT_BIST_SHIFT 24L
326
327//****************************************************************************
328//
329// The following defines are for the flags in the PCI base address registers.
330//
331//****************************************************************************
332#define PBAR_MEMORY_SPACE_INDICATOR 0x00000001L
333#define PBAR_LOCATION_TYPE_MASK 0x00000006L
334#define PBAR_NOT_PREFETCHABLE 0x00000008L
335#define PBAR_ADDRESS_MASK 0xFFFFFFF0L
336#define PBAR_LOCATION_TYPE_SHIFT 1L
337
338//****************************************************************************
339//
340// The following defines are for the flags in the PCI subsystem ID/subsystem
341// vendor ID register.
342//
343//****************************************************************************
344#define PSS_SUBSYSTEM_VENDOR_ID_MASK 0x0000FFFFL
345#define PSS_SUBSYSTEM_ID_MASK 0xFFFF0000L
346#define PSS_SUBSYSTEM_VENDOR_ID_SHIFT 0L
347#define PSS_SUBSYSTEM_ID_SHIFT 16L
348
349//****************************************************************************
350//
351// The following defines are for the flags in the PCI interrupt register.
352//
353//****************************************************************************
354#define PI_LINE_MASK 0x000000FFL
355#define PI_PIN_MASK 0x0000FF00L
356#define PI_MIN_GRANT_MASK 0x00FF0000L
357#define PI_MAX_LATENCY_MASK 0xFF000000L
358#define PI_LINE_SHIFT 0L
359#define PI_PIN_SHIFT 8L
360#define PI_MIN_GRANT_SHIFT 16L
361#define PI_MAX_LATENCY_SHIFT 24L
362
363//****************************************************************************
364//
365// The following defines are for the flags in the host interrupt status
366// register.
367//
368//****************************************************************************
369#define HISR_HVOLMASK 0x00000003L
370#define HISR_VDNI 0x00000001L
371#define HISR_VUPI 0x00000002L
372#define HISR_GP1I 0x00000004L
373#define HISR_GP3I 0x00000008L
374#define HISR_GPSI 0x00000010L
375#define HISR_GPPI 0x00000020L
376#define HISR_DMAI 0x00040000L
377#define HISR_FIFOI 0x00100000L
378#define HISR_HVOL 0x00200000L
379#define HISR_MIDI 0x00400000L
380#define HISR_SBINT 0x00800000L
381#define HISR_INTENA 0x80000000L
382#define HISR_DMA_MASK 0x00000F00L
383#define HISR_FIFO_MASK 0x0000F000L
384#define HISR_DMA_SHIFT 8L
385#define HISR_FIFO_SHIFT 12L
386#define HISR_FIFO0 0x00001000L
387#define HISR_FIFO1 0x00002000L
388#define HISR_FIFO2 0x00004000L
389#define HISR_FIFO3 0x00008000L
390#define HISR_DMA0 0x00000100L
391#define HISR_DMA1 0x00000200L
392#define HISR_DMA2 0x00000400L
393#define HISR_DMA3 0x00000800L
394#define HISR_RESERVED 0x40000000L
395
396//****************************************************************************
397//
398// The following defines are for the flags in the host interrupt control
399// register.
400//
401//****************************************************************************
402#define HICR_IEV 0x00000001L
403#define HICR_CHGM 0x00000002L
404
405//****************************************************************************
406//
407// The following defines are for the flags in the DMA Mode Register n
408// (DMRn)
409//
410//****************************************************************************
411#define DMRn_TR_MASK 0x0000000CL
412#define DMRn_TR_SHIFT 2L
413#define DMRn_AUTO 0x00000010L
414#define DMRn_TR_READ 0x00000008L
415#define DMRn_TR_WRITE 0x00000004L
416#define DMRn_TYPE_MASK 0x000000C0L
417#define DMRn_TYPE_SHIFT 6L
418#define DMRn_SIZE8 0x00010000L
419#define DMRn_MONO 0x00020000L
420#define DMRn_BEND 0x00040000L
421#define DMRn_USIGN 0x00080000L
422#define DMRn_SIZE20 0x00100000L
423#define DMRn_SWAPC 0x00400000L
424#define DMRn_CBC 0x01000000L
425#define DMRn_TBC 0x02000000L
426#define DMRn_POLL 0x10000000L
427#define DMRn_DMA 0x20000000L
428#define DMRn_FSEL_MASK 0xC0000000L
429#define DMRn_FSEL_SHIFT 30L
430#define DMRn_FSEL0 0x00000000L
431#define DMRn_FSEL1 0x40000000L
432#define DMRn_FSEL2 0x80000000L
433#define DMRn_FSEL3 0xC0000000L
434
435//****************************************************************************
436//
437// The following defines are for the flags in the DMA Command Register n
438// (DCRn)
439//
440//****************************************************************************
441#define DCRn_HTCIE 0x00020000L
442#define DCRn_TCIE 0x00010000L
443#define DCRn_MSK 0x00000001L
444
445//****************************************************************************
446//
447// The following defines are for the flags in the FIFO Control
448// register n.(FCRn)
449//
450//****************************************************************************
451#define FCRn_OF_MASK 0x0000007FL
452#define FCRn_OF_SHIFT 0L
453#define FCRn_SZ_MASK 0x00007F00L
454#define FCRn_SZ_SHIFT 8L
455#define FCRn_LS_MASK 0x001F0000L
456#define FCRn_LS_SHIFT 16L
457#define FCRn_RS_MASK 0x1F000000L
458#define FCRn_RS_SHIFT 24L
459#define FCRn_FEN 0x80000000L
460#define FCRn_PSH 0x20000000L
461#define FCRn_DACZ 0x40000000L
462
463//****************************************************************************
464//
465// The following defines are for the flags in the serial port Power Management
466// control register.(SPMC)
467//
468//****************************************************************************
469#define SPMC_RSTN 0x00000001L
470#define SPMC_ASYN 0x00000002L
471#define SPMC_WUP1 0x00000004L
472#define SPMC_WUP2 0x00000008L
473#define SPMC_ASDI2E 0x00000100L
474#define SPMC_ESSPD 0x00000200L
475#define SPMC_GISPEN 0x00004000L
476#define SPMC_GIPPEN 0x00008000L
477
478//****************************************************************************
479//
480// The following defines are for the flags in the Configuration Load register.
481// (CFLR)
482//
483//****************************************************************************
484#define CFLR_CLOCK_SOURCE_MASK 0x00000003L
485#define CFLR_CLOCK_SOURCE_AC97 0x00000001L
486
487#define CFLR_CB0_MASK 0x000000FFL
488#define CFLR_CB1_MASK 0x0000FF00L
489#define CFLR_CB2_MASK 0x00FF0000L
490#define CFLR_CB3_MASK 0xFF000000L
491#define CFLR_CB0_SHIFT 0L
492#define CFLR_CB1_SHIFT 8L
493#define CFLR_CB2_SHIFT 16L
494#define CFLR_CB3_SHIFT 24L
495
496#define IOTCR_DMA0 0x00000000L
497#define IOTCR_DMA1 0x00000400L
498#define IOTCR_DMA2 0x00000800L
499#define IOTCR_DMA3 0x00000C00L
500#define IOTCR_CCLS 0x00000100L
501#define IOTCR_PCPCI 0x00000200L
502#define IOTCR_DDMA 0x00000300L
503
504#define SBWBS_WBB 0x00000080L
505
506//****************************************************************************
507//
508// The following defines are for the flags in the SRC Slot Assignment Register
509// (SRCSA)
510//
511//****************************************************************************
512#define SRCSA_PLSS_MASK 0x0000001FL
513#define SRCSA_PLSS_SHIFT 0L
514#define SRCSA_PRSS_MASK 0x00001F00L
515#define SRCSA_PRSS_SHIFT 8L
516#define SRCSA_CLSS_MASK 0x001F0000L
517#define SRCSA_CLSS_SHIFT 16L
518#define SRCSA_CRSS_MASK 0x1F000000L
519#define SRCSA_CRSS_SHIFT 24L
520
521//****************************************************************************
522//
523// The following defines are for the flags in the Sound System Power Management
524// register.(SSPM)
525//
526//****************************************************************************
527#define SSPM_FPDN 0x00000080L
528#define SSPM_MIXEN 0x00000040L
529#define SSPM_CSRCEN 0x00000020L
530#define SSPM_PSRCEN 0x00000010L
531#define SSPM_JSEN 0x00000008L
532#define SSPM_ACLEN 0x00000004L
533#define SSPM_FMEN 0x00000002L
534
535//****************************************************************************
536//
537// The following defines are for the flags in the Sound System Control
538// Register. (SSCR)
539//
540//****************************************************************************
541#define SSCR_SB 0x00000004L
542#define SSCR_HVC 0x00000008L
543#define SSCR_LPFIFO 0x00000040L
544#define SSCR_LPSRC 0x00000080L
545#define SSCR_XLPSRC 0x00000100L
546#define SSCR_MVMD 0x00010000L
547#define SSCR_MVAD 0x00020000L
548#define SSCR_MVLD 0x00040000L
549#define SSCR_MVCS 0x00080000L
550
551//****************************************************************************
552//
553// The following defines are for the flags in the Clock Control Register 1.
554// (CLKCR1)
555//
556//****************************************************************************
557#define CLKCR1_DLLSS_MASK 0x0000000CL
558#define CLKCR1_DLLSS_SHIFT 2L
559#define CLKCR1_DLLP 0x00000010L
560#define CLKCR1_SWCE 0x00000020L
561#define CLKCR1_DLLOS 0x00000040L
562#define CLKCR1_CKRA 0x00010000L
563#define CLKCR1_CKRN 0x00020000L
564#define CLKCR1_DLLRDY 0x01000000L
565#define CLKCR1_CLKON 0x02000000L
566
567//****************************************************************************
568//
569// The following defines are for the flags in the Sound Blaster Read Buffer
570// Status.(SBRBS)
571//
572//****************************************************************************
573#define SBRBS_RD_MASK 0x0000007FL
574#define SBRBS_RD_SHIFT 0L
575#define SBRBS_RBF 0x00000080L
576
577//****************************************************************************
578//
579// The following defines are for the flags in the serial port master control
580// register.(SERMC)
581//
582//****************************************************************************
583#define SERMC_MSPE 0x00000001L
584#define SERMC_PTC_MASK 0x0000000EL
585#define SERMC_PTC_SHIFT 1L
586#define SERMC_PTC_AC97 0x00000002L
587#define SERMC_PLB 0x00000010L
588#define SERMC_PXLB 0x00000020L
589#define SERMC_LOFV 0x00080000L
590#define SERMC_SLB 0x00100000L
591#define SERMC_SXLB 0x00200000L
592#define SERMC_ODSEN1 0x01000000L
593#define SERMC_ODSEN2 0x02000000L
594
595//****************************************************************************
596//
597// The following defines are for the flags in the General Purpose I/O Register.
598// (GPIOR)
599//
600//****************************************************************************
601#define GPIOR_VDNS 0x00000001L
602#define GPIOR_VUPS 0x00000002L
603#define GPIOR_GP1S 0x00000004L
604#define GPIOR_GP3S 0x00000008L
605#define GPIOR_GPSS 0x00000010L
606#define GPIOR_GPPS 0x00000020L
607#define GPIOR_GP1D 0x00000400L
608#define GPIOR_GP3D 0x00000800L
609#define GPIOR_VDNLT 0x00010000L
610#define GPIOR_VDNPO 0x00020000L
611#define GPIOR_VDNST 0x00040000L
612#define GPIOR_VDNW 0x00080000L
613#define GPIOR_VUPLT 0x00100000L
614#define GPIOR_VUPPO 0x00200000L
615#define GPIOR_VUPST 0x00400000L
616#define GPIOR_VUPW 0x00800000L
617#define GPIOR_GP1OE 0x01000000L
618#define GPIOR_GP1PT 0x02000000L
619#define GPIOR_GP1ST 0x04000000L
620#define GPIOR_GP1W 0x08000000L
621#define GPIOR_GP3OE 0x10000000L
622#define GPIOR_GP3PT 0x20000000L
623#define GPIOR_GP3ST 0x40000000L
624#define GPIOR_GP3W 0x80000000L
625
626//****************************************************************************
627//
628// The following defines are for the flags in the clock control register 1.
629//
630//****************************************************************************
631#define CLKCR1_PLLSS_MASK 0x0000000CL
632#define CLKCR1_PLLSS_SERIAL 0x00000000L
633#define CLKCR1_PLLSS_CRYSTAL 0x00000004L
634#define CLKCR1_PLLSS_PCI 0x00000008L
635#define CLKCR1_PLLSS_RESERVED 0x0000000CL
636#define CLKCR1_PLLP 0x00000010L
637#define CLKCR1_SWCE 0x00000020L
638#define CLKCR1_PLLOS 0x00000040L
639
640//****************************************************************************
641//
642// The following defines are for the flags in the feature reporting register.
643//
644//****************************************************************************
645#define FRR_FAB_MASK 0x00000003L
646#define FRR_MASK_MASK 0x0000001CL
647#define FRR_ID_MASK 0x00003000L
648#define FRR_FAB_SHIFT 0L
649#define FRR_MASK_SHIFT 2L
650#define FRR_ID_SHIFT 12L
651
652//****************************************************************************
653//
654// The following defines are for the flags in the serial port 1 configuration
655// register.
656//
657//****************************************************************************
658#define SERC1_VALUE 0x00000003L
659#define SERC1_SO1EN 0x00000001L
660#define SERC1_SO1F_MASK 0x0000000EL
661#define SERC1_SO1F_CS423X 0x00000000L
662#define SERC1_SO1F_AC97 0x00000002L
663#define SERC1_SO1F_DAC 0x00000004L
664#define SERC1_SO1F_SPDIF 0x00000006L
665
666//****************************************************************************
667//
668// The following defines are for the flags in the serial port 2 configuration
669// register.
670//
671//****************************************************************************
672#define SERC2_VALUE 0x00000003L
673#define SERC2_SI1EN 0x00000001L
674#define SERC2_SI1F_MASK 0x0000000EL
675#define SERC2_SI1F_CS423X 0x00000000L
676#define SERC2_SI1F_AC97 0x00000002L
677#define SERC2_SI1F_ADC 0x00000004L
678#define SERC2_SI1F_SPDIF 0x00000006L
679
680//****************************************************************************
681//
682// The following defines are for the flags in the AC97 control register.
683//
684//****************************************************************************
685#define ACCTL_ESYN 0x00000002L
686#define ACCTL_VFRM 0x00000004L
687#define ACCTL_DCV 0x00000008L
688#define ACCTL_CRW 0x00000010L
689#define ACCTL_TC 0x00000040L
690
691//****************************************************************************
692//
693// The following defines are for the flags in the AC97 status register.
694//
695//****************************************************************************
696#define ACSTS_CRDY 0x00000001L
697#define ACSTS_VSTS 0x00000002L
698
699//****************************************************************************
700//
701// The following defines are for the flags in the AC97 output slot valid
702// register.
703//
704//****************************************************************************
705#define ACOSV_SLV3 0x00000001L
706#define ACOSV_SLV4 0x00000002L
707#define ACOSV_SLV5 0x00000004L
708#define ACOSV_SLV6 0x00000008L
709#define ACOSV_SLV7 0x00000010L
710#define ACOSV_SLV8 0x00000020L
711#define ACOSV_SLV9 0x00000040L
712#define ACOSV_SLV10 0x00000080L
713#define ACOSV_SLV11 0x00000100L
714#define ACOSV_SLV12 0x00000200L
715
716//****************************************************************************
717//
718// The following defines are for the flags in the AC97 command address
719// register.
720//
721//****************************************************************************
722#define ACCAD_CI_MASK 0x0000007FL
723#define ACCAD_CI_SHIFT 0L
724
725//****************************************************************************
726//
727// The following defines are for the flags in the AC97 command data register.
728//
729//****************************************************************************
730#define ACCDA_CD_MASK 0x0000FFFFL
731#define ACCDA_CD_SHIFT 0L
732
733//****************************************************************************
734//
735// The following defines are for the flags in the AC97 input slot valid
736// register.
737//
738//****************************************************************************
739#define ACISV_ISV3 0x00000001L
740#define ACISV_ISV4 0x00000002L
741#define ACISV_ISV5 0x00000004L
742#define ACISV_ISV6 0x00000008L
743#define ACISV_ISV7 0x00000010L
744#define ACISV_ISV8 0x00000020L
745#define ACISV_ISV9 0x00000040L
746#define ACISV_ISV10 0x00000080L
747#define ACISV_ISV11 0x00000100L
748#define ACISV_ISV12 0x00000200L
749
750//****************************************************************************
751//
752// The following defines are for the flags in the AC97 status address
753// register.
754//
755//****************************************************************************
756#define ACSAD_SI_MASK 0x0000007FL
757#define ACSAD_SI_SHIFT 0L
758
759//****************************************************************************
760//
761// The following defines are for the flags in the AC97 status data register.
762//
763//****************************************************************************
764#define ACSDA_SD_MASK 0x0000FFFFL
765#define ACSDA_SD_SHIFT 0L
766
767//****************************************************************************
768//
769// The following defines are for the flags in the I/O trap address and control
770// registers (all 12).
771//
772//****************************************************************************
773#define IOTAC_SA_MASK 0x0000FFFFL
774#define IOTAC_MSK_MASK 0x000F0000L
775#define IOTAC_IODC_MASK 0x06000000L
776#define IOTAC_IODC_16_BIT 0x00000000L
777#define IOTAC_IODC_10_BIT 0x02000000L
778#define IOTAC_IODC_12_BIT 0x04000000L
779#define IOTAC_WSPI 0x08000000L
780#define IOTAC_RSPI 0x10000000L
781#define IOTAC_WSE 0x20000000L
782#define IOTAC_WE 0x40000000L
783#define IOTAC_RE 0x80000000L
784#define IOTAC_SA_SHIFT 0L
785#define IOTAC_MSK_SHIFT 16L
786
787//****************************************************************************
788//
789// The following defines are for the flags in the PC/PCI master enable
790// register.
791//
792//****************************************************************************
793#define PCPCIEN_EN 0x00000001L
794
795//****************************************************************************
796//
797// The following defines are for the flags in the joystick poll/trigger
798// register.
799//
800//****************************************************************************
801#define JSPT_CAX 0x00000001L
802#define JSPT_CAY 0x00000002L
803#define JSPT_CBX 0x00000004L
804#define JSPT_CBY 0x00000008L
805#define JSPT_BA1 0x00000010L
806#define JSPT_BA2 0x00000020L
807#define JSPT_BB1 0x00000040L
808#define JSPT_BB2 0x00000080L
809
810//****************************************************************************
811//
812// The following defines are for the flags in the joystick control register.
813// The TBF bit has been moved from MIDSR register to JSCTL register bit 8.
814//
815//****************************************************************************
816#define JSCTL_SP_MASK 0x00000003L
817#define JSCTL_SP_SLOW 0x00000000L
818#define JSCTL_SP_MEDIUM_SLOW 0x00000001L
819#define JSCTL_SP_MEDIUM_FAST 0x00000002L
820#define JSCTL_SP_FAST 0x00000003L
821#define JSCTL_ARE 0x00000004L
822#define JSCTL_TBF 0x00000100L
823
824
825//****************************************************************************
826//
827// The following defines are for the flags in the MIDI control register.
828//
829//****************************************************************************
830#define MIDCR_TXE 0x00000001L
831#define MIDCR_RXE 0x00000002L
832#define MIDCR_RIE 0x00000004L
833#define MIDCR_TIE 0x00000008L
834#define MIDCR_MLB 0x00000010L
835#define MIDCR_MRST 0x00000020L
836
837//****************************************************************************
838//
839// The following defines are for the flags in the MIDI status register.
840//
841//****************************************************************************
842#define MIDSR_RBE 0x00000080L
843#define MIDSR_RDA 0x00008000L
844
845//****************************************************************************
846//
847// The following defines are for the flags in the MIDI write port register.
848//
849//****************************************************************************
850#define MIDWP_MWD_MASK 0x000000FFL
851#define MIDWP_MWD_SHIFT 0L
852
853//****************************************************************************
854//
855// The following defines are for the flags in the MIDI read port register.
856//
857//****************************************************************************
858#define MIDRP_MRD_MASK 0x000000FFL
859#define MIDRP_MRD_SHIFT 0L
860
861//****************************************************************************
862//
863// The following defines are for the flags in the configuration interface
864// register.
865//
866//****************************************************************************
867#define CFGI_CLK 0x00000001L
868#define CFGI_DOUT 0x00000002L
869#define CFGI_DIN_EEN 0x00000004L
870#define CFGI_EELD 0x00000008L
871
872//****************************************************************************
873//
874// The following defines are for the flags in the subsystem ID and vendor ID
875// register.
876//
877//****************************************************************************
878#define SSVID_VID_MASK 0x0000FFFFL
879#define SSVID_SID_MASK 0xFFFF0000L
880#define SSVID_VID_SHIFT 0L
881#define SSVID_SID_SHIFT 16L
882
883//****************************************************************************
884//
885// The following defines are for the flags in the GPIO pin interface register.
886//
887//****************************************************************************
888#define GPIOR_VOLDN 0x00000001L
889#define GPIOR_VOLUP 0x00000002L
890#define GPIOR_SI2D 0x00000004L
891#define GPIOR_SI2OE 0x00000008L
892
893//****************************************************************************
894//
895// The following defines are for the flags in the AC97 status register 2.
896//
897//****************************************************************************
898#define ACSTS2_CRDY 0x00000001L
899#define ACSTS2_VSTS 0x00000002L
900
901//****************************************************************************
902//
903// The following defines are for the flags in the AC97 input slot valid
904// register 2.
905//
906//****************************************************************************
907#define ACISV2_ISV3 0x00000001L
908#define ACISV2_ISV4 0x00000002L
909#define ACISV2_ISV5 0x00000004L
910#define ACISV2_ISV6 0x00000008L
911#define ACISV2_ISV7 0x00000010L
912#define ACISV2_ISV8 0x00000020L
913#define ACISV2_ISV9 0x00000040L
914#define ACISV2_ISV10 0x00000080L
915#define ACISV2_ISV11 0x00000100L
916#define ACISV2_ISV12 0x00000200L
917
918//****************************************************************************
919//
920// The following defines are for the flags in the AC97 status address
921// register 2.
922//
923//****************************************************************************
924#define ACSAD2_SI_MASK 0x0000007FL
925#define ACSAD2_SI_SHIFT 0L
926
927//****************************************************************************
928//
929// The following defines are for the flags in the AC97 status data register 2.
930//
931//****************************************************************************
932#define ACSDA2_SD_MASK 0x0000FFFFL
933#define ACSDA2_SD_SHIFT 0L
934
935//****************************************************************************
936//
937// The following defines are for the flags in the I/O trap control register.
938//
939//****************************************************************************
940#define IOTCR_ITD 0x00000001L
941#define IOTCR_HRV 0x00000002L
942#define IOTCR_SRV 0x00000004L
943#define IOTCR_DTI 0x00000008L
944#define IOTCR_DFI 0x00000010L
945#define IOTCR_DDP 0x00000020L
946#define IOTCR_JTE 0x00000040L
947#define IOTCR_PPE 0x00000080L
948
949//****************************************************************************
950//
951// The following defines are for the flags in the I/O trap address and control
952// registers for Hardware Master Volume.
953//
954//****************************************************************************
955#define IOTGP_SA_MASK 0x0000FFFFL
956#define IOTGP_MSK_MASK 0x000F0000L
957#define IOTGP_IODC_MASK 0x06000000L
958#define IOTGP_IODC_16_BIT 0x00000000L
959#define IOTGP_IODC_10_BIT 0x02000000L
960#define IOTGP_IODC_12_BIT 0x04000000L
961#define IOTGP_WSPI 0x08000000L
962#define IOTGP_RSPI 0x10000000L
963#define IOTGP_WSE 0x20000000L
964#define IOTGP_WE 0x40000000L
965#define IOTGP_RE 0x80000000L
966#define IOTGP_SA_SHIFT 0L
967#define IOTGP_MSK_SHIFT 16L
968
969//****************************************************************************
970//
971// The following defines are for the flags in the I/O trap address and control
972// registers for Sound Blaster
973//
974//****************************************************************************
975#define IOTSB_SA_MASK 0x0000FFFFL
976#define IOTSB_MSK_MASK 0x000F0000L
977#define IOTSB_IODC_MASK 0x06000000L
978#define IOTSB_IODC_16_BIT 0x00000000L
979#define IOTSB_IODC_10_BIT 0x02000000L
980#define IOTSB_IODC_12_BIT 0x04000000L
981#define IOTSB_WSPI 0x08000000L
982#define IOTSB_RSPI 0x10000000L
983#define IOTSB_WSE 0x20000000L
984#define IOTSB_WE 0x40000000L
985#define IOTSB_RE 0x80000000L
986#define IOTSB_SA_SHIFT 0L
987#define IOTSB_MSK_SHIFT 16L
988
989//****************************************************************************
990//
991// The following defines are for the flags in the I/O trap address and control
992// registers for FM.
993//
994//****************************************************************************
995#define IOTFM_SA_MASK 0x0000FFFFL
996#define IOTFM_MSK_MASK 0x000F0000L
997#define IOTFM_IODC_MASK 0x06000000L
998#define IOTFM_IODC_16_BIT 0x00000000L
999#define IOTFM_IODC_10_BIT 0x02000000L
1000#define IOTFM_IODC_12_BIT 0x04000000L
1001#define IOTFM_WSPI 0x08000000L
1002#define IOTFM_RSPI 0x10000000L
1003#define IOTFM_WSE 0x20000000L
1004#define IOTFM_WE 0x40000000L
1005#define IOTFM_RE 0x80000000L
1006#define IOTFM_SA_SHIFT 0L
1007#define IOTFM_MSK_SHIFT 16L
1008
1009//****************************************************************************
1010//
1011// The following defines are for the flags in the PC/PCI request register.
1012//
1013//****************************************************************************
1014#define PCPRR_RDC_MASK 0x00000007L
1015#define PCPRR_REQ 0x00008000L
1016#define PCPRR_RDC_SHIFT 0L
1017
1018//****************************************************************************
1019//
1020// The following defines are for the flags in the PC/PCI grant register.
1021//
1022//****************************************************************************
1023#define PCPGR_GDC_MASK 0x00000007L
1024#define PCPGR_VL 0x00008000L
1025#define PCPGR_GDC_SHIFT 0L
1026
1027//****************************************************************************
1028//
1029// The following defines are for the flags in the PC/PCI Control Register.
1030//
1031//****************************************************************************
1032#define PCPCR_EN 0x00000001L
1033
1034//****************************************************************************
1035//
1036// The following defines are for the flags in the debug index register.
1037//
1038//****************************************************************************
1039#define DREG_REGID_MASK 0x0000007FL
1040#define DREG_DEBUG 0x00000080L
1041#define DREG_RGBK_MASK 0x00000700L
1042#define DREG_TRAP 0x00000800L
1043#if !defined(NO_CS4612)
1044#if !defined(NO_CS4615)
1045#define DREG_TRAPX 0x00001000L
1046#endif
1047#endif
1048#define DREG_REGID_SHIFT 0L
1049#define DREG_RGBK_SHIFT 8L
1050#define DREG_RGBK_REGID_MASK 0x0000077FL
1051#define DREG_REGID_R0 0x00000010L
1052#define DREG_REGID_R1 0x00000011L
1053#define DREG_REGID_R2 0x00000012L
1054#define DREG_REGID_R3 0x00000013L
1055#define DREG_REGID_R4 0x00000014L
1056#define DREG_REGID_R5 0x00000015L
1057#define DREG_REGID_R6 0x00000016L
1058#define DREG_REGID_R7 0x00000017L
1059#define DREG_REGID_R8 0x00000018L
1060#define DREG_REGID_R9 0x00000019L
1061#define DREG_REGID_RA 0x0000001AL
1062#define DREG_REGID_RB 0x0000001BL
1063#define DREG_REGID_RC 0x0000001CL
1064#define DREG_REGID_RD 0x0000001DL
1065#define DREG_REGID_RE 0x0000001EL
1066#define DREG_REGID_RF 0x0000001FL
1067#define DREG_REGID_RA_BUS_LOW 0x00000020L
1068#define DREG_REGID_RA_BUS_HIGH 0x00000038L
1069#define DREG_REGID_YBUS_LOW 0x00000050L
1070#define DREG_REGID_YBUS_HIGH 0x00000058L
1071#define DREG_REGID_TRAP_0 0x00000100L
1072#define DREG_REGID_TRAP_1 0x00000101L
1073#define DREG_REGID_TRAP_2 0x00000102L
1074#define DREG_REGID_TRAP_3 0x00000103L
1075#define DREG_REGID_TRAP_4 0x00000104L
1076#define DREG_REGID_TRAP_5 0x00000105L
1077#define DREG_REGID_TRAP_6 0x00000106L
1078#define DREG_REGID_TRAP_7 0x00000107L
1079#define DREG_REGID_INDIRECT_ADDRESS 0x0000010EL
1080#define DREG_REGID_TOP_OF_STACK 0x0000010FL
1081#if !defined(NO_CS4612)
1082#if !defined(NO_CS4615)
1083#define DREG_REGID_TRAP_8 0x00000110L
1084#define DREG_REGID_TRAP_9 0x00000111L
1085#define DREG_REGID_TRAP_10 0x00000112L
1086#define DREG_REGID_TRAP_11 0x00000113L
1087#define DREG_REGID_TRAP_12 0x00000114L
1088#define DREG_REGID_TRAP_13 0x00000115L
1089#define DREG_REGID_TRAP_14 0x00000116L
1090#define DREG_REGID_TRAP_15 0x00000117L
1091#define DREG_REGID_TRAP_16 0x00000118L
1092#define DREG_REGID_TRAP_17 0x00000119L
1093#define DREG_REGID_TRAP_18 0x0000011AL
1094#define DREG_REGID_TRAP_19 0x0000011BL
1095#define DREG_REGID_TRAP_20 0x0000011CL
1096#define DREG_REGID_TRAP_21 0x0000011DL
1097#define DREG_REGID_TRAP_22 0x0000011EL
1098#define DREG_REGID_TRAP_23 0x0000011FL
1099#endif
1100#endif
1101#define DREG_REGID_RSA0_LOW 0x00000200L
1102#define DREG_REGID_RSA0_HIGH 0x00000201L
1103#define DREG_REGID_RSA1_LOW 0x00000202L
1104#define DREG_REGID_RSA1_HIGH 0x00000203L
1105#define DREG_REGID_RSA2 0x00000204L
1106#define DREG_REGID_RSA3 0x00000205L
1107#define DREG_REGID_RSI0_LOW 0x00000206L
1108#define DREG_REGID_RSI0_HIGH 0x00000207L
1109#define DREG_REGID_RSI1 0x00000208L
1110#define DREG_REGID_RSI2 0x00000209L
1111#define DREG_REGID_SAGUSTATUS 0x0000020AL
1112#define DREG_REGID_RSCONFIG01_LOW 0x0000020BL
1113#define DREG_REGID_RSCONFIG01_HIGH 0x0000020CL
1114#define DREG_REGID_RSCONFIG23_LOW 0x0000020DL
1115#define DREG_REGID_RSCONFIG23_HIGH 0x0000020EL
1116#define DREG_REGID_RSDMA01E 0x0000020FL
1117#define DREG_REGID_RSDMA23E 0x00000210L
1118#define DREG_REGID_RSD0_LOW 0x00000211L
1119#define DREG_REGID_RSD0_HIGH 0x00000212L
1120#define DREG_REGID_RSD1_LOW 0x00000213L
1121#define DREG_REGID_RSD1_HIGH 0x00000214L
1122#define DREG_REGID_RSD2_LOW 0x00000215L
1123#define DREG_REGID_RSD2_HIGH 0x00000216L
1124#define DREG_REGID_RSD3_LOW 0x00000217L
1125#define DREG_REGID_RSD3_HIGH 0x00000218L
1126#define DREG_REGID_SRAR_HIGH 0x0000021AL
1127#define DREG_REGID_SRAR_LOW 0x0000021BL
1128#define DREG_REGID_DMA_STATE 0x0000021CL
1129#define DREG_REGID_CURRENT_DMA_STREAM 0x0000021DL
1130#define DREG_REGID_NEXT_DMA_STREAM 0x0000021EL
1131#define DREG_REGID_CPU_STATUS 0x00000300L
1132#define DREG_REGID_MAC_MODE 0x00000301L
1133#define DREG_REGID_STACK_AND_REPEAT 0x00000302L
1134#define DREG_REGID_INDEX0 0x00000304L
1135#define DREG_REGID_INDEX1 0x00000305L
1136#define DREG_REGID_DMA_STATE_0_3 0x00000400L
1137#define DREG_REGID_DMA_STATE_4_7 0x00000404L
1138#define DREG_REGID_DMA_STATE_8_11 0x00000408L
1139#define DREG_REGID_DMA_STATE_12_15 0x0000040CL
1140#define DREG_REGID_DMA_STATE_16_19 0x00000410L
1141#define DREG_REGID_DMA_STATE_20_23 0x00000414L
1142#define DREG_REGID_DMA_STATE_24_27 0x00000418L
1143#define DREG_REGID_DMA_STATE_28_31 0x0000041CL
1144#define DREG_REGID_DMA_STATE_32_35 0x00000420L
1145#define DREG_REGID_DMA_STATE_36_39 0x00000424L
1146#define DREG_REGID_DMA_STATE_40_43 0x00000428L
1147#define DREG_REGID_DMA_STATE_44_47 0x0000042CL
1148#define DREG_REGID_DMA_STATE_48_51 0x00000430L
1149#define DREG_REGID_DMA_STATE_52_55 0x00000434L
1150#define DREG_REGID_DMA_STATE_56_59 0x00000438L
1151#define DREG_REGID_DMA_STATE_60_63 0x0000043CL
1152#define DREG_REGID_DMA_STATE_64_67 0x00000440L
1153#define DREG_REGID_DMA_STATE_68_71 0x00000444L
1154#define DREG_REGID_DMA_STATE_72_75 0x00000448L
1155#define DREG_REGID_DMA_STATE_76_79 0x0000044CL
1156#define DREG_REGID_DMA_STATE_80_83 0x00000450L
1157#define DREG_REGID_DMA_STATE_84_87 0x00000454L
1158#define DREG_REGID_DMA_STATE_88_91 0x00000458L
1159#define DREG_REGID_DMA_STATE_92_95 0x0000045CL
1160#define DREG_REGID_TRAP_SELECT 0x00000500L
1161#define DREG_REGID_TRAP_WRITE_0 0x00000500L
1162#define DREG_REGID_TRAP_WRITE_1 0x00000501L
1163#define DREG_REGID_TRAP_WRITE_2 0x00000502L
1164#define DREG_REGID_TRAP_WRITE_3 0x00000503L
1165#define DREG_REGID_TRAP_WRITE_4 0x00000504L
1166#define DREG_REGID_TRAP_WRITE_5 0x00000505L
1167#define DREG_REGID_TRAP_WRITE_6 0x00000506L
1168#define DREG_REGID_TRAP_WRITE_7 0x00000507L
1169#if !defined(NO_CS4612)
1170#if !defined(NO_CS4615)
1171#define DREG_REGID_TRAP_WRITE_8 0x00000510L
1172#define DREG_REGID_TRAP_WRITE_9 0x00000511L
1173#define DREG_REGID_TRAP_WRITE_10 0x00000512L
1174#define DREG_REGID_TRAP_WRITE_11 0x00000513L
1175#define DREG_REGID_TRAP_WRITE_12 0x00000514L
1176#define DREG_REGID_TRAP_WRITE_13 0x00000515L
1177#define DREG_REGID_TRAP_WRITE_14 0x00000516L
1178#define DREG_REGID_TRAP_WRITE_15 0x00000517L
1179#define DREG_REGID_TRAP_WRITE_16 0x00000518L
1180#define DREG_REGID_TRAP_WRITE_17 0x00000519L
1181#define DREG_REGID_TRAP_WRITE_18 0x0000051AL
1182#define DREG_REGID_TRAP_WRITE_19 0x0000051BL
1183#define DREG_REGID_TRAP_WRITE_20 0x0000051CL
1184#define DREG_REGID_TRAP_WRITE_21 0x0000051DL
1185#define DREG_REGID_TRAP_WRITE_22 0x0000051EL
1186#define DREG_REGID_TRAP_WRITE_23 0x0000051FL
1187#endif
1188#endif
1189#define DREG_REGID_MAC0_ACC0_LOW 0x00000600L
1190#define DREG_REGID_MAC0_ACC1_LOW 0x00000601L
1191#define DREG_REGID_MAC0_ACC2_LOW 0x00000602L
1192#define DREG_REGID_MAC0_ACC3_LOW 0x00000603L
1193#define DREG_REGID_MAC1_ACC0_LOW 0x00000604L
1194#define DREG_REGID_MAC1_ACC1_LOW 0x00000605L
1195#define DREG_REGID_MAC1_ACC2_LOW 0x00000606L
1196#define DREG_REGID_MAC1_ACC3_LOW 0x00000607L
1197#define DREG_REGID_MAC0_ACC0_MID 0x00000608L
1198#define DREG_REGID_MAC0_ACC1_MID 0x00000609L
1199#define DREG_REGID_MAC0_ACC2_MID 0x0000060AL
1200#define DREG_REGID_MAC0_ACC3_MID 0x0000060BL
1201#define DREG_REGID_MAC1_ACC0_MID 0x0000060CL
1202#define DREG_REGID_MAC1_ACC1_MID 0x0000060DL
1203#define DREG_REGID_MAC1_ACC2_MID 0x0000060EL
1204#define DREG_REGID_MAC1_ACC3_MID 0x0000060FL
1205#define DREG_REGID_MAC0_ACC0_HIGH 0x00000610L
1206#define DREG_REGID_MAC0_ACC1_HIGH 0x00000611L
1207#define DREG_REGID_MAC0_ACC2_HIGH 0x00000612L
1208#define DREG_REGID_MAC0_ACC3_HIGH 0x00000613L
1209#define DREG_REGID_MAC1_ACC0_HIGH 0x00000614L
1210#define DREG_REGID_MAC1_ACC1_HIGH 0x00000615L
1211#define DREG_REGID_MAC1_ACC2_HIGH 0x00000616L
1212#define DREG_REGID_MAC1_ACC3_HIGH 0x00000617L
1213#define DREG_REGID_RSHOUT_LOW 0x00000620L
1214#define DREG_REGID_RSHOUT_MID 0x00000628L
1215#define DREG_REGID_RSHOUT_HIGH 0x00000630L
1216
1217//****************************************************************************
1218//
1219// The following defines are for the flags in the AC97 S/PDIF Control register.
1220//
1221//****************************************************************************
1222#define SPDIF_CONTROL_SPDIF_EN 0x00008000L
1223#define SPDIF_CONTROL_VAL 0x00004000L
1224#define SPDIF_CONTROL_COPY 0x00000004L
1225#define SPDIF_CONTROL_CC0 0x00000010L
1226#define SPDIF_CONTROL_CC1 0x00000020L
1227#define SPDIF_CONTROL_CC2 0x00000040L
1228#define SPDIF_CONTROL_CC3 0x00000080L
1229#define SPDIF_CONTROL_CC4 0x00000100L
1230#define SPDIF_CONTROL_CC5 0x00000200L
1231#define SPDIF_CONTROL_CC6 0x00000400L
1232#define SPDIF_CONTROL_L 0x00000800L
1233
1234#endif // _H_HWDEFS
diff --git a/sound/oss/cs4281/cs4281_wrapper-24.c b/sound/oss/cs4281/cs4281_wrapper-24.c
new file mode 100644
index 000000000000..4559f02c9969
--- /dev/null
+++ b/sound/oss/cs4281/cs4281_wrapper-24.c
@@ -0,0 +1,41 @@
1/*******************************************************************************
2*
3* "cs4281_wrapper.c" -- Cirrus Logic-Crystal CS4281 linux audio driver.
4*
5* Copyright (C) 2000,2001 Cirrus Logic Corp.
6* -- tom woller (twoller@crystal.cirrus.com) or
7* (audio@crystal.cirrus.com).
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* 12/20/00 trw - new file.
24*
25*******************************************************************************/
26
27#include <linux/spinlock.h>
28
29static int cs4281_resume_null(struct pci_dev *pcidev) { return 0; }
30static int cs4281_suspend_null(struct pci_dev *pcidev, pm_message_t state) { return 0; }
31
32#define free_dmabuf(state, dmabuf) \
33 pci_free_consistent(state->pcidev, \
34 PAGE_SIZE << (dmabuf)->buforder, \
35 (dmabuf)->rawbuf, (dmabuf)->dmaaddr);
36#define free_dmabuf2(state, dmabuf) \
37 pci_free_consistent((state)->pcidev, \
38 PAGE_SIZE << (state)->buforder_tmpbuff, \
39 (state)->tmpbuff, (state)->dmaaddr_tmpbuff);
40#define cs4x_pgoff(vma) ((vma)->vm_pgoff)
41
diff --git a/sound/oss/cs4281/cs4281m.c b/sound/oss/cs4281/cs4281m.c
new file mode 100644
index 000000000000..d0d3963e1b83
--- /dev/null
+++ b/sound/oss/cs4281/cs4281m.c
@@ -0,0 +1,4505 @@
1/*******************************************************************************
2*
3* "cs4281.c" -- Cirrus Logic-Crystal CS4281 linux audio driver.
4*
5* Copyright (C) 2000,2001 Cirrus Logic Corp.
6* -- adapted from drivers by Thomas Sailer,
7* -- but don't bug him; Problems should go to:
8* -- tom woller (twoller@crystal.cirrus.com) or
9* (audio@crystal.cirrus.com).
10*
11* This program is free software; you can redistribute it and/or modify
12* it under the terms of the GNU General Public License as published by
13* the Free Software Foundation; either version 2 of the License, or
14* (at your option) any later version.
15*
16* This program is distributed in the hope that it will be useful,
17* but WITHOUT ANY WARRANTY; without even the implied warranty of
18* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19* GNU General Public License for more details.
20*
21* You should have received a copy of the GNU General Public License
22* along with this program; if not, write to the Free Software
23* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*
25* Module command line parameters:
26* none
27*
28* Supported devices:
29* /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
30* /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
31* /dev/midi simple MIDI UART interface, no ioctl
32*
33* Modification History
34* 08/20/00 trw - silence and no stopping DAC until release
35* 08/23/00 trw - added CS_DBG statements, fix interrupt hang issue on DAC stop.
36* 09/18/00 trw - added 16bit only record with conversion
37* 09/24/00 trw - added Enhanced Full duplex (separate simultaneous
38* capture/playback rates)
39* 10/03/00 trw - fixed mmap (fixed GRECORD and the XMMS mmap test plugin
40* libOSSm.so)
41* 10/11/00 trw - modified for 2.4.0-test9 kernel enhancements (NR_MAP removal)
42* 11/03/00 trw - fixed interrupt loss/stutter, added debug.
43* 11/10/00 bkz - added __devinit to cs4281_hw_init()
44* 11/10/00 trw - fixed SMP and capture spinlock hang.
45* 12/04/00 trw - cleaned up CSDEBUG flags and added "defaultorder" moduleparm.
46* 12/05/00 trw - fixed polling (myth2), and added underrun swptr fix.
47* 12/08/00 trw - added PM support.
48* 12/14/00 trw - added wrapper code, builds under 2.4.0, 2.2.17-20, 2.2.17-8
49* (RH/Dell base), 2.2.18, 2.2.12. cleaned up code mods by ident.
50* 12/19/00 trw - added PM support for 2.2 base (apm_callback). other PM cleanup.
51* 12/21/00 trw - added fractional "defaultorder" inputs. if >100 then use
52* defaultorder-100 as power of 2 for the buffer size. example:
53* 106 = 2^(106-100) = 2^6 = 64 bytes for the buffer size.
54*
55*******************************************************************************/
56
57/* uncomment the following line to disable building PM support into the driver */
58//#define NOT_CS4281_PM 1
59
60#include <linux/list.h>
61#include <linux/module.h>
62#include <linux/string.h>
63#include <linux/ioport.h>
64#include <linux/sched.h>
65#include <linux/delay.h>
66#include <linux/sound.h>
67#include <linux/slab.h>
68#include <linux/soundcard.h>
69#include <linux/pci.h>
70#include <linux/bitops.h>
71#include <linux/init.h>
72#include <linux/interrupt.h>
73#include <linux/poll.h>
74#include <linux/fs.h>
75#include <linux/wait.h>
76
77#include <asm/current.h>
78#include <asm/io.h>
79#include <asm/dma.h>
80#include <asm/page.h>
81#include <asm/uaccess.h>
82
83//#include "cs_dm.h"
84#include "cs4281_hwdefs.h"
85#include "cs4281pm.h"
86
87struct cs4281_state;
88
89static void stop_dac(struct cs4281_state *s);
90static void stop_adc(struct cs4281_state *s);
91static void start_dac(struct cs4281_state *s);
92static void start_adc(struct cs4281_state *s);
93#undef OSS_DOCUMENTED_MIXER_SEMANTICS
94
95// ---------------------------------------------------------------------
96
97#ifndef PCI_VENDOR_ID_CIRRUS
98#define PCI_VENDOR_ID_CIRRUS 0x1013
99#endif
100#ifndef PCI_DEVICE_ID_CRYSTAL_CS4281
101#define PCI_DEVICE_ID_CRYSTAL_CS4281 0x6005
102#endif
103
104#define CS4281_MAGIC ((PCI_DEVICE_ID_CRYSTAL_CS4281<<16) | PCI_VENDOR_ID_CIRRUS)
105#define CS4281_CFLR_DEFAULT 0x00000001 /* CFLR must be in AC97 link mode */
106
107// buffer order determines the size of the dma buffer for the driver.
108// under Linux, a smaller buffer allows more responsiveness from many of the
109// applications (e.g. games). A larger buffer allows some of the apps (esound)
110// to not underrun the dma buffer as easily. As default, use 32k (order=3)
111// rather than 64k as some of the games work more responsively.
112// log base 2( buff sz = 32k).
113static unsigned long defaultorder = 3;
114module_param(defaultorder, ulong, 0);
115
116//
117// Turn on/off debugging compilation by commenting out "#define CSDEBUG"
118//
119#define CSDEBUG 1
120#if CSDEBUG
121#define CSDEBUG_INTERFACE 1
122#else
123#undef CSDEBUG_INTERFACE
124#endif
125//
126// cs_debugmask areas
127//
128#define CS_INIT 0x00000001 // initialization and probe functions
129#define CS_ERROR 0x00000002 // tmp debugging bit placeholder
130#define CS_INTERRUPT 0x00000004 // interrupt handler (separate from all other)
131#define CS_FUNCTION 0x00000008 // enter/leave functions
132#define CS_WAVE_WRITE 0x00000010 // write information for wave
133#define CS_WAVE_READ 0x00000020 // read information for wave
134#define CS_MIDI_WRITE 0x00000040 // write information for midi
135#define CS_MIDI_READ 0x00000080 // read information for midi
136#define CS_MPU401_WRITE 0x00000100 // write information for mpu401
137#define CS_MPU401_READ 0x00000200 // read information for mpu401
138#define CS_OPEN 0x00000400 // all open functions in the driver
139#define CS_RELEASE 0x00000800 // all release functions in the driver
140#define CS_PARMS 0x00001000 // functional and operational parameters
141#define CS_IOCTL 0x00002000 // ioctl (non-mixer)
142#define CS_PM 0x00004000 // power management
143#define CS_TMP 0x10000000 // tmp debug mask bit
144
145#define CS_IOCTL_CMD_SUSPEND 0x1 // suspend
146#define CS_IOCTL_CMD_RESUME 0x2 // resume
147//
148// CSDEBUG is usual mode is set to 1, then use the
149// cs_debuglevel and cs_debugmask to turn on or off debugging.
150// Debug level of 1 has been defined to be kernel errors and info
151// that should be printed on any released driver.
152//
153#if CSDEBUG
154#define CS_DBGOUT(mask,level,x) if((cs_debuglevel >= (level)) && ((mask) & cs_debugmask) ) {x;}
155#else
156#define CS_DBGOUT(mask,level,x)
157#endif
158
159#if CSDEBUG
160static unsigned long cs_debuglevel = 1; // levels range from 1-9
161static unsigned long cs_debugmask = CS_INIT | CS_ERROR; // use CS_DBGOUT with various mask values
162module_param(cs_debuglevel, ulong, 0);
163module_param(cs_debugmask, ulong, 0);
164#endif
165#define CS_TRUE 1
166#define CS_FALSE 0
167
168// MIDI buffer sizes
169#define MIDIINBUF 500
170#define MIDIOUTBUF 500
171
172#define FMODE_MIDI_SHIFT 3
173#define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
174#define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
175
176#define CS4281_MAJOR_VERSION 1
177#define CS4281_MINOR_VERSION 13
178#ifdef __ia64__
179#define CS4281_ARCH 64 //architecture key
180#else
181#define CS4281_ARCH 32 //architecture key
182#endif
183
184#define CS_TYPE_ADC 0
185#define CS_TYPE_DAC 1
186
187
188static const char invalid_magic[] =
189 KERN_CRIT "cs4281: invalid magic value\n";
190
191#define VALIDATE_STATE(s) \
192({ \
193 if (!(s) || (s)->magic != CS4281_MAGIC) { \
194 printk(invalid_magic); \
195 return -ENXIO; \
196 } \
197})
198
199//LIST_HEAD(cs4281_devs);
200static struct list_head cs4281_devs = { &cs4281_devs, &cs4281_devs };
201
202struct cs4281_state;
203
204#include "cs4281_wrapper-24.c"
205
206struct cs4281_state {
207 // magic
208 unsigned int magic;
209
210 // we keep the cards in a linked list
211 struct cs4281_state *next;
212
213 // pcidev is needed to turn off the DDMA controller at driver shutdown
214 struct pci_dev *pcidev;
215 struct list_head list;
216
217 // soundcore stuff
218 int dev_audio;
219 int dev_mixer;
220 int dev_midi;
221
222 // hardware resources
223 unsigned int pBA0phys, pBA1phys;
224 char __iomem *pBA0;
225 char __iomem *pBA1;
226 unsigned int irq;
227
228 // mixer registers
229 struct {
230 unsigned short vol[10];
231 unsigned int recsrc;
232 unsigned int modcnt;
233 unsigned short micpreamp;
234 } mix;
235
236 // wave stuff
237 struct properties {
238 unsigned fmt;
239 unsigned fmt_original; // original requested format
240 unsigned channels;
241 unsigned rate;
242 unsigned char clkdiv;
243 } prop_dac, prop_adc;
244 unsigned conversion:1; // conversion from 16 to 8 bit in progress
245 void *tmpbuff; // tmp buffer for sample conversions
246 unsigned ena;
247 spinlock_t lock;
248 struct semaphore open_sem;
249 struct semaphore open_sem_adc;
250 struct semaphore open_sem_dac;
251 mode_t open_mode;
252 wait_queue_head_t open_wait;
253 wait_queue_head_t open_wait_adc;
254 wait_queue_head_t open_wait_dac;
255
256 dma_addr_t dmaaddr_tmpbuff;
257 unsigned buforder_tmpbuff; // Log base 2 of 'rawbuf' size in bytes..
258 struct dmabuf {
259 void *rawbuf; // Physical address of
260 dma_addr_t dmaaddr;
261 unsigned buforder; // Log base 2 of 'rawbuf' size in bytes..
262 unsigned numfrag; // # of 'fragments' in the buffer.
263 unsigned fragshift; // Log base 2 of fragment size.
264 unsigned hwptr, swptr;
265 unsigned total_bytes; // # bytes process since open.
266 unsigned blocks; // last returned blocks value GETOPTR
267 unsigned wakeup; // interrupt occurred on block
268 int count;
269 unsigned underrun; // underrun flag
270 unsigned error; // over/underrun
271 wait_queue_head_t wait;
272 // redundant, but makes calculations easier
273 unsigned fragsize; // 2**fragshift..
274 unsigned dmasize; // 2**buforder.
275 unsigned fragsamples;
276 // OSS stuff
277 unsigned mapped:1; // Buffer mapped in cs4281_mmap()?
278 unsigned ready:1; // prog_dmabuf_dac()/adc() successful?
279 unsigned endcleared:1;
280 unsigned type:1; // adc or dac buffer (CS_TYPE_XXX)
281 unsigned ossfragshift;
282 int ossmaxfrags;
283 unsigned subdivision;
284 } dma_dac, dma_adc;
285
286 // midi stuff
287 struct {
288 unsigned ird, iwr, icnt;
289 unsigned ord, owr, ocnt;
290 wait_queue_head_t iwait;
291 wait_queue_head_t owait;
292 struct timer_list timer;
293 unsigned char ibuf[MIDIINBUF];
294 unsigned char obuf[MIDIOUTBUF];
295 } midi;
296
297 struct cs4281_pm pm;
298 struct cs4281_pipeline pl[CS4281_NUMBER_OF_PIPELINES];
299};
300
301#include "cs4281pm-24.c"
302
303#if CSDEBUG
304
305// DEBUG ROUTINES
306
307#define SOUND_MIXER_CS_GETDBGLEVEL _SIOWR('M',120, int)
308#define SOUND_MIXER_CS_SETDBGLEVEL _SIOWR('M',121, int)
309#define SOUND_MIXER_CS_GETDBGMASK _SIOWR('M',122, int)
310#define SOUND_MIXER_CS_SETDBGMASK _SIOWR('M',123, int)
311
312#define SOUND_MIXER_CS_APM _SIOWR('M',124, int)
313
314
315static void cs_printioctl(unsigned int x)
316{
317 unsigned int i;
318 unsigned char vidx;
319 // Index of mixtable1[] member is Device ID
320 // and must be <= SOUND_MIXER_NRDEVICES.
321 // Value of array member is index into s->mix.vol[]
322 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
323 [SOUND_MIXER_PCM] = 1, // voice
324 [SOUND_MIXER_LINE1] = 2, // AUX
325 [SOUND_MIXER_CD] = 3, // CD
326 [SOUND_MIXER_LINE] = 4, // Line
327 [SOUND_MIXER_SYNTH] = 5, // FM
328 [SOUND_MIXER_MIC] = 6, // Mic
329 [SOUND_MIXER_SPEAKER] = 7, // Speaker
330 [SOUND_MIXER_RECLEV] = 8, // Recording level
331 [SOUND_MIXER_VOLUME] = 9 // Master Volume
332 };
333
334 switch (x) {
335 case SOUND_MIXER_CS_GETDBGMASK:
336 CS_DBGOUT(CS_IOCTL, 4,
337 printk("SOUND_MIXER_CS_GETDBGMASK:\n"));
338 break;
339 case SOUND_MIXER_CS_GETDBGLEVEL:
340 CS_DBGOUT(CS_IOCTL, 4,
341 printk("SOUND_MIXER_CS_GETDBGLEVEL:\n"));
342 break;
343 case SOUND_MIXER_CS_SETDBGMASK:
344 CS_DBGOUT(CS_IOCTL, 4,
345 printk("SOUND_MIXER_CS_SETDBGMASK:\n"));
346 break;
347 case SOUND_MIXER_CS_SETDBGLEVEL:
348 CS_DBGOUT(CS_IOCTL, 4,
349 printk("SOUND_MIXER_CS_SETDBGLEVEL:\n"));
350 break;
351 case OSS_GETVERSION:
352 CS_DBGOUT(CS_IOCTL, 4, printk("OSS_GETVERSION:\n"));
353 break;
354 case SNDCTL_DSP_SYNC:
355 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SYNC:\n"));
356 break;
357 case SNDCTL_DSP_SETDUPLEX:
358 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETDUPLEX:\n"));
359 break;
360 case SNDCTL_DSP_GETCAPS:
361 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETCAPS:\n"));
362 break;
363 case SNDCTL_DSP_RESET:
364 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_RESET:\n"));
365 break;
366 case SNDCTL_DSP_SPEED:
367 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SPEED:\n"));
368 break;
369 case SNDCTL_DSP_STEREO:
370 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_STEREO:\n"));
371 break;
372 case SNDCTL_DSP_CHANNELS:
373 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_CHANNELS:\n"));
374 break;
375 case SNDCTL_DSP_GETFMTS:
376 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETFMTS:\n"));
377 break;
378 case SNDCTL_DSP_SETFMT:
379 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETFMT:\n"));
380 break;
381 case SNDCTL_DSP_POST:
382 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_POST:\n"));
383 break;
384 case SNDCTL_DSP_GETTRIGGER:
385 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETTRIGGER:\n"));
386 break;
387 case SNDCTL_DSP_SETTRIGGER:
388 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETTRIGGER:\n"));
389 break;
390 case SNDCTL_DSP_GETOSPACE:
391 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOSPACE:\n"));
392 break;
393 case SNDCTL_DSP_GETISPACE:
394 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETISPACE:\n"));
395 break;
396 case SNDCTL_DSP_NONBLOCK:
397 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_NONBLOCK:\n"));
398 break;
399 case SNDCTL_DSP_GETODELAY:
400 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETODELAY:\n"));
401 break;
402 case SNDCTL_DSP_GETIPTR:
403 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETIPTR:\n"));
404 break;
405 case SNDCTL_DSP_GETOPTR:
406 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOPTR:\n"));
407 break;
408 case SNDCTL_DSP_GETBLKSIZE:
409 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETBLKSIZE:\n"));
410 break;
411 case SNDCTL_DSP_SETFRAGMENT:
412 CS_DBGOUT(CS_IOCTL, 4,
413 printk("SNDCTL_DSP_SETFRAGMENT:\n"));
414 break;
415 case SNDCTL_DSP_SUBDIVIDE:
416 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SUBDIVIDE:\n"));
417 break;
418 case SOUND_PCM_READ_RATE:
419 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_RATE:\n"));
420 break;
421 case SOUND_PCM_READ_CHANNELS:
422 CS_DBGOUT(CS_IOCTL, 4,
423 printk("SOUND_PCM_READ_CHANNELS:\n"));
424 break;
425 case SOUND_PCM_READ_BITS:
426 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_BITS:\n"));
427 break;
428 case SOUND_PCM_WRITE_FILTER:
429 CS_DBGOUT(CS_IOCTL, 4,
430 printk("SOUND_PCM_WRITE_FILTER:\n"));
431 break;
432 case SNDCTL_DSP_SETSYNCRO:
433 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETSYNCRO:\n"));
434 break;
435 case SOUND_PCM_READ_FILTER:
436 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_FILTER:\n"));
437 break;
438 case SOUND_MIXER_PRIVATE1:
439 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE1:\n"));
440 break;
441 case SOUND_MIXER_PRIVATE2:
442 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE2:\n"));
443 break;
444 case SOUND_MIXER_PRIVATE3:
445 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE3:\n"));
446 break;
447 case SOUND_MIXER_PRIVATE4:
448 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE4:\n"));
449 break;
450 case SOUND_MIXER_PRIVATE5:
451 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE5:\n"));
452 break;
453 case SOUND_MIXER_INFO:
454 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_INFO:\n"));
455 break;
456 case SOUND_OLD_MIXER_INFO:
457 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_OLD_MIXER_INFO:\n"));
458 break;
459
460 default:
461 switch (_IOC_NR(x)) {
462 case SOUND_MIXER_VOLUME:
463 CS_DBGOUT(CS_IOCTL, 4,
464 printk("SOUND_MIXER_VOLUME:\n"));
465 break;
466 case SOUND_MIXER_SPEAKER:
467 CS_DBGOUT(CS_IOCTL, 4,
468 printk("SOUND_MIXER_SPEAKER:\n"));
469 break;
470 case SOUND_MIXER_RECLEV:
471 CS_DBGOUT(CS_IOCTL, 4,
472 printk("SOUND_MIXER_RECLEV:\n"));
473 break;
474 case SOUND_MIXER_MIC:
475 CS_DBGOUT(CS_IOCTL, 4,
476 printk("SOUND_MIXER_MIC:\n"));
477 break;
478 case SOUND_MIXER_SYNTH:
479 CS_DBGOUT(CS_IOCTL, 4,
480 printk("SOUND_MIXER_SYNTH:\n"));
481 break;
482 case SOUND_MIXER_RECSRC:
483 CS_DBGOUT(CS_IOCTL, 4,
484 printk("SOUND_MIXER_RECSRC:\n"));
485 break;
486 case SOUND_MIXER_DEVMASK:
487 CS_DBGOUT(CS_IOCTL, 4,
488 printk("SOUND_MIXER_DEVMASK:\n"));
489 break;
490 case SOUND_MIXER_RECMASK:
491 CS_DBGOUT(CS_IOCTL, 4,
492 printk("SOUND_MIXER_RECMASK:\n"));
493 break;
494 case SOUND_MIXER_STEREODEVS:
495 CS_DBGOUT(CS_IOCTL, 4,
496 printk("SOUND_MIXER_STEREODEVS:\n"));
497 break;
498 case SOUND_MIXER_CAPS:
499 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CAPS:\n"));
500 break;
501 default:
502 i = _IOC_NR(x);
503 if (i >= SOUND_MIXER_NRDEVICES
504 || !(vidx = mixtable1[i])) {
505 CS_DBGOUT(CS_IOCTL, 4, printk
506 ("UNKNOWN IOCTL: 0x%.8x NR=%d\n",
507 x, i));
508 } else {
509 CS_DBGOUT(CS_IOCTL, 4, printk
510 ("SOUND_MIXER_IOCTL AC9x: 0x%.8x NR=%d\n",
511 x, i));
512 }
513 break;
514 }
515 }
516}
517#endif
518static int prog_dmabuf_adc(struct cs4281_state *s);
519static void prog_codec(struct cs4281_state *s, unsigned type);
520
521// ---------------------------------------------------------------------
522//
523// Hardware Interfaces For the CS4281
524//
525
526
527//******************************************************************************
528// "delayus()-- Delay for the specified # of microseconds.
529//******************************************************************************
530static void delayus(struct cs4281_state *s, u32 delay)
531{
532 u32 j;
533 if ((delay > 9999) && (s->pm.flags & CS4281_PM_IDLE)) {
534 j = (delay * HZ) / 1000000; /* calculate delay in jiffies */
535 if (j < 1)
536 j = 1; /* minimum one jiffy. */
537 current->state = TASK_UNINTERRUPTIBLE;
538 schedule_timeout(j);
539 } else
540 udelay(delay);
541 return;
542}
543
544
545//******************************************************************************
546// "cs4281_read_ac97" -- Reads a word from the specified location in the
547// CS4281's address space(based on the BA0 register).
548//
549// 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
550// 2. Write ACCDA = Command Data Register = 470h for data to write to AC97 register,
551// 0h for reads.
552// 3. Write ACCTL = Control Register = 460h for initiating the write
553// 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 17h
554// 5. if DCV not cleared, break and return error
555// 6. Read ACSTS = Status Register = 464h, check VSTS bit
556//****************************************************************************
557static int cs4281_read_ac97(struct cs4281_state *card, u32 offset,
558 u32 * value)
559{
560 u32 count, status;
561
562 // Make sure that there is not data sitting
563 // around from a previous uncompleted access.
564 // ACSDA = Status Data Register = 47Ch
565 status = readl(card->pBA0 + BA0_ACSDA);
566
567 // Setup the AC97 control registers on the CS4281 to send the
568 // appropriate command to the AC97 to perform the read.
569 // ACCAD = Command Address Register = 46Ch
570 // ACCDA = Command Data Register = 470h
571 // ACCTL = Control Register = 460h
572 // bit DCV - will clear when process completed
573 // bit CRW - Read command
574 // bit VFRM - valid frame enabled
575 // bit ESYN - ASYNC generation enabled
576
577 // Get the actual AC97 register from the offset
578 writel(offset - BA0_AC97_RESET, card->pBA0 + BA0_ACCAD);
579 writel(0, card->pBA0 + BA0_ACCDA);
580 writel(ACCTL_DCV | ACCTL_CRW | ACCTL_VFRM | ACCTL_ESYN,
581 card->pBA0 + BA0_ACCTL);
582
583 // Wait for the read to occur.
584 for (count = 0; count < 10; count++) {
585 // First, we want to wait for a short time.
586 udelay(25);
587
588 // Now, check to see if the read has completed.
589 // ACCTL = 460h, DCV should be reset by now and 460h = 17h
590 if (!(readl(card->pBA0 + BA0_ACCTL) & ACCTL_DCV))
591 break;
592 }
593
594 // Make sure the read completed.
595 if (readl(card->pBA0 + BA0_ACCTL) & ACCTL_DCV)
596 return 1;
597
598 // Wait for the valid status bit to go active.
599 for (count = 0; count < 10; count++) {
600 // Read the AC97 status register.
601 // ACSTS = Status Register = 464h
602 status = readl(card->pBA0 + BA0_ACSTS);
603
604 // See if we have valid status.
605 // VSTS - Valid Status
606 if (status & ACSTS_VSTS)
607 break;
608 // Wait for a short while.
609 udelay(25);
610 }
611
612 // Make sure we got valid status.
613 if (!(status & ACSTS_VSTS))
614 return 1;
615
616 // Read the data returned from the AC97 register.
617 // ACSDA = Status Data Register = 474h
618 *value = readl(card->pBA0 + BA0_ACSDA);
619
620 // Success.
621 return (0);
622}
623
624
625//****************************************************************************
626//
627// "cs4281_write_ac97()"-- writes a word to the specified location in the
628// CS461x's address space (based on the part's base address zero register).
629//
630// 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
631// 2. Write ACCDA = Command Data Register = 470h for data to write to AC97 reg.
632// 3. Write ACCTL = Control Register = 460h for initiating the write
633// 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 07h
634// 5. if DCV not cleared, break and return error
635//
636//****************************************************************************
637static int cs4281_write_ac97(struct cs4281_state *card, u32 offset,
638 u32 value)
639{
640 u32 count, status=0;
641
642 CS_DBGOUT(CS_FUNCTION, 2,
643 printk(KERN_INFO "cs4281: cs_4281_write_ac97()+ \n"));
644
645 // Setup the AC97 control registers on the CS4281 to send the
646 // appropriate command to the AC97 to perform the read.
647 // ACCAD = Command Address Register = 46Ch
648 // ACCDA = Command Data Register = 470h
649 // ACCTL = Control Register = 460h
650 // set DCV - will clear when process completed
651 // reset CRW - Write command
652 // set VFRM - valid frame enabled
653 // set ESYN - ASYNC generation enabled
654 // set RSTN - ARST# inactive, AC97 codec not reset
655
656 // Get the actual AC97 register from the offset
657
658 writel(offset - BA0_AC97_RESET, card->pBA0 + BA0_ACCAD);
659 writel(value, card->pBA0 + BA0_ACCDA);
660 writel(ACCTL_DCV | ACCTL_VFRM | ACCTL_ESYN,
661 card->pBA0 + BA0_ACCTL);
662
663 // Wait for the write to occur.
664 for (count = 0; count < 100; count++) {
665 // First, we want to wait for a short time.
666 udelay(25);
667 // Now, check to see if the write has completed.
668 // ACCTL = 460h, DCV should be reset by now and 460h = 07h
669 status = readl(card->pBA0 + BA0_ACCTL);
670 if (!(status & ACCTL_DCV))
671 break;
672 }
673
674 // Make sure the write completed.
675 if (status & ACCTL_DCV) {
676 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
677 "cs4281: cs_4281_write_ac97()- unable to write. ACCTL_DCV active\n"));
678 return 1;
679 }
680 CS_DBGOUT(CS_FUNCTION, 2,
681 printk(KERN_INFO "cs4281: cs_4281_write_ac97()- 0\n"));
682 // Success.
683 return 0;
684}
685
686
687//******************************************************************************
688// "Init4281()" -- Bring up the part.
689//******************************************************************************
690static __devinit int cs4281_hw_init(struct cs4281_state *card)
691{
692 u32 ac97_slotid;
693 u32 temp1, temp2;
694
695 CS_DBGOUT(CS_FUNCTION, 2,
696 printk(KERN_INFO "cs4281: cs4281_hw_init()+ \n"));
697#ifndef NOT_CS4281_PM
698 if(!card)
699 return 1;
700#endif
701 temp2 = readl(card->pBA0 + BA0_CFLR);
702 CS_DBGOUT(CS_INIT | CS_ERROR | CS_PARMS, 4, printk(KERN_INFO
703 "cs4281: cs4281_hw_init() CFLR 0x%x\n", temp2));
704 if(temp2 != CS4281_CFLR_DEFAULT)
705 {
706 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_INFO
707 "cs4281: cs4281_hw_init() CFLR invalid - resetting from 0x%x to 0x%x\n",
708 temp2,CS4281_CFLR_DEFAULT));
709 writel(CS4281_CFLR_DEFAULT, card->pBA0 + BA0_CFLR);
710 temp2 = readl(card->pBA0 + BA0_CFLR);
711 if(temp2 != CS4281_CFLR_DEFAULT)
712 {
713 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_INFO
714 "cs4281: cs4281_hw_init() Invalid hardware - unable to configure CFLR\n"));
715 return 1;
716 }
717 }
718
719 //***************************************7
720 // Set up the Sound System Configuration
721 //***************************************
722
723 // Set the 'Configuration Write Protect' register
724 // to 4281h. Allows vendor-defined configuration
725 // space between 0e4h and 0ffh to be written.
726
727 writel(0x4281, card->pBA0 + BA0_CWPR); // (3e0h)
728
729 // (0), Blast the clock control register to zero so that the
730 // PLL starts out in a known state, and blast the master serial
731 // port control register to zero so that the serial ports also
732 // start out in a known state.
733
734 writel(0, card->pBA0 + BA0_CLKCR1); // (400h)
735 writel(0, card->pBA0 + BA0_SERMC); // (420h)
736
737
738 // (1), Make ESYN go to zero to turn off
739 // the Sync pulse on the AC97 link.
740
741 writel(0, card->pBA0 + BA0_ACCTL);
742 udelay(50);
743
744
745 // (2) Drive the ARST# pin low for a minimum of 1uS (as defined in
746 // the AC97 spec) and then drive it high. This is done for non
747 // AC97 modes since there might be logic external to the CS461x
748 // that uses the ARST# line for a reset.
749
750 writel(0, card->pBA0 + BA0_SPMC); // (3ech)
751 udelay(100);
752 writel(SPMC_RSTN, card->pBA0 + BA0_SPMC);
753 delayus(card,50000); // Wait 50 ms for ABITCLK to become stable.
754
755 // (3) Turn on the Sound System Clocks.
756 writel(CLKCR1_PLLP, card->pBA0 + BA0_CLKCR1); // (400h)
757 delayus(card,50000); // Wait for the PLL to stabilize.
758 // Turn on clocking of the core (CLKCR1(400h) = 0x00000030)
759 writel(CLKCR1_PLLP | CLKCR1_SWCE, card->pBA0 + BA0_CLKCR1);
760
761 // (4) Power on everything for now..
762 writel(0x7E, card->pBA0 + BA0_SSPM); // (740h)
763
764 // (5) Wait for clock stabilization.
765 for (temp1 = 0; temp1 < 1000; temp1++) {
766 udelay(1000);
767 if (readl(card->pBA0 + BA0_CLKCR1) & CLKCR1_DLLRDY)
768 break;
769 }
770 if (!(readl(card->pBA0 + BA0_CLKCR1) & CLKCR1_DLLRDY)) {
771 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
772 "cs4281: DLLRDY failed!\n"));
773 return -EIO;
774 }
775 // (6) Enable ASYNC generation.
776 writel(ACCTL_ESYN, card->pBA0 + BA0_ACCTL); // (460h)
777
778 // Now wait 'for a short while' to allow the AC97
779 // part to start generating bit clock. (so we don't
780 // Try to start the PLL without an input clock.)
781 delayus(card,50000);
782
783 // Set the serial port timing configuration, so that the
784 // clock control circuit gets its clock from the right place.
785 writel(SERMC_PTC_AC97, card->pBA0 + BA0_SERMC); // (420h)=2.
786
787 // (7) Wait for the codec ready signal from the AC97 codec.
788
789 for (temp1 = 0; temp1 < 1000; temp1++) {
790 // Delay a mil to let things settle out and
791 // to prevent retrying the read too quickly.
792 udelay(1000);
793 if (readl(card->pBA0 + BA0_ACSTS) & ACSTS_CRDY) // If ready, (464h)
794 break; // exit the 'for' loop.
795 }
796 if (!(readl(card->pBA0 + BA0_ACSTS) & ACSTS_CRDY)) // If never came ready,
797 {
798 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_ERR
799 "cs4281: ACSTS never came ready!\n"));
800 return -EIO; // exit initialization.
801 }
802 // (8) Assert the 'valid frame' signal so we can
803 // begin sending commands to the AC97 codec.
804 writel(ACCTL_VFRM | ACCTL_ESYN, card->pBA0 + BA0_ACCTL); // (460h)
805
806 // (9), Wait until CODEC calibration is finished.
807 // Print an error message if it doesn't.
808 for (temp1 = 0; temp1 < 1000; temp1++) {
809 delayus(card,10000);
810 // Read the AC97 Powerdown Control/Status Register.
811 cs4281_read_ac97(card, BA0_AC97_POWERDOWN, &temp2);
812 if ((temp2 & 0x0000000F) == 0x0000000F)
813 break;
814 }
815 if ((temp2 & 0x0000000F) != 0x0000000F) {
816 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_ERR
817 "cs4281: Codec failed to calibrate. Status = %.8x.\n",
818 temp2));
819 return -EIO;
820 }
821 // (10), Set the serial port timing configuration, so that the
822 // clock control circuit gets its clock from the right place.
823 writel(SERMC_PTC_AC97, card->pBA0 + BA0_SERMC); // (420h)=2.
824
825
826 // (11) Wait until we've sampled input slots 3 & 4 as valid, meaning
827 // that the codec is pumping ADC data across the AC link.
828 for (temp1 = 0; temp1 < 1000; temp1++) {
829 // Delay a mil to let things settle out and
830 // to prevent retrying the read too quickly.
831 delayus(card,1000); //(test)
832
833 // Read the input slot valid register; See
834 // if input slots 3 and 4 are valid yet.
835 if (
836 (readl(card->pBA0 + BA0_ACISV) &
837 (ACISV_ISV3 | ACISV_ISV4)) ==
838 (ACISV_ISV3 | ACISV_ISV4)) break; // Exit the 'for' if slots are valid.
839 }
840 // If we never got valid data, exit initialization.
841 if ((readl(card->pBA0 + BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4))
842 != (ACISV_ISV3 | ACISV_ISV4)) {
843 CS_DBGOUT(CS_FUNCTION, 2,
844 printk(KERN_ERR
845 "cs4281: Never got valid data!\n"));
846 return -EIO; // If no valid data, exit initialization.
847 }
848 // (12), Start digital data transfer of audio data to the codec.
849 writel(ACOSV_SLV3 | ACOSV_SLV4, card->pBA0 + BA0_ACOSV); // (468h)
850
851
852 //**************************************
853 // Unmute the Master and Alternate
854 // (headphone) volumes. Set to max.
855 //**************************************
856 cs4281_write_ac97(card, BA0_AC97_HEADPHONE_VOLUME, 0);
857 cs4281_write_ac97(card, BA0_AC97_MASTER_VOLUME, 0);
858
859 //******************************************
860 // Power on the DAC(AddDACUser()from main())
861 //******************************************
862 cs4281_read_ac97(card, BA0_AC97_POWERDOWN, &temp1);
863 cs4281_write_ac97(card, BA0_AC97_POWERDOWN, temp1 &= 0xfdff);
864
865 // Wait until we sample a DAC ready state.
866 for (temp2 = 0; temp2 < 32; temp2++) {
867 // Let's wait a mil to let things settle.
868 delayus(card,1000);
869 // Read the current state of the power control reg.
870 cs4281_read_ac97(card, BA0_AC97_POWERDOWN, &temp1);
871 // If the DAC ready state bit is set, stop waiting.
872 if (temp1 & 0x2)
873 break;
874 }
875
876 //******************************************
877 // Power on the ADC(AddADCUser()from main())
878 //******************************************
879 cs4281_read_ac97(card, BA0_AC97_POWERDOWN, &temp1);
880 cs4281_write_ac97(card, BA0_AC97_POWERDOWN, temp1 &= 0xfeff);
881
882 // Wait until we sample ADC ready state.
883 for (temp2 = 0; temp2 < 32; temp2++) {
884 // Let's wait a mil to let things settle.
885 delayus(card,1000);
886 // Read the current state of the power control reg.
887 cs4281_read_ac97(card, BA0_AC97_POWERDOWN, &temp1);
888 // If the ADC ready state bit is set, stop waiting.
889 if (temp1 & 0x1)
890 break;
891 }
892 // Set up 4281 Register contents that
893 // don't change for boot duration.
894
895 // For playback, we map AC97 slot 3 and 4(Left
896 // & Right PCM playback) to DMA Channel 0.
897 // Set the fifo to be 15 bytes at offset zero.
898
899 ac97_slotid = 0x01000f00; // FCR0.RS[4:0]=1(=>slot4, right PCM playback).
900 // FCR0.LS[4:0]=0(=>slot3, left PCM playback).
901 // FCR0.SZ[6-0]=15; FCR0.OF[6-0]=0.
902 writel(ac97_slotid, card->pBA0 + BA0_FCR0); // (180h)
903 writel(ac97_slotid | FCRn_FEN, card->pBA0 + BA0_FCR0); // Turn on FIFO Enable.
904
905 // For capture, we map AC97 slot 10 and 11(Left
906 // and Right PCM Record) to DMA Channel 1.
907 // Set the fifo to be 15 bytes at offset sixteen.
908 ac97_slotid = 0x0B0A0f10; // FCR1.RS[4:0]=11(=>slot11, right PCM record).
909 // FCR1.LS[4:0]=10(=>slot10, left PCM record).
910 // FCR1.SZ[6-0]=15; FCR1.OF[6-0]=16.
911 writel(ac97_slotid | FCRn_PSH, card->pBA0 + BA0_FCR1); // (184h)
912 writel(ac97_slotid | FCRn_FEN, card->pBA0 + BA0_FCR1); // Turn on FIFO Enable.
913
914 // Map the Playback SRC to the same AC97 slots(3 & 4--
915 // --Playback left & right)as DMA channel 0.
916 // Map the record SRC to the same AC97 slots(10 & 11--
917 // -- Record left & right) as DMA channel 1.
918
919 ac97_slotid = 0x0b0a0100; // SCRSA.PRSS[4:0]=1(=>slot4, right PCM playback).
920 // SCRSA.PLSS[4:0]=0(=>slot3, left PCM playback).
921 // SCRSA.CRSS[4:0]=11(=>slot11, right PCM record)
922 // SCRSA.CLSS[4:0]=10(=>slot10, left PCM record).
923 writel(ac97_slotid, card->pBA0 + BA0_SRCSA); // (75ch)
924
925 // Set 'Half Terminal Count Interrupt Enable' and 'Terminal
926 // Count Interrupt Enable' in DMA Control Registers 0 & 1.
927 // Set 'MSK' flag to 1 to keep the DMA engines paused.
928 temp1 = (DCRn_HTCIE | DCRn_TCIE | DCRn_MSK); // (00030001h)
929 writel(temp1, card->pBA0 + BA0_DCR0); // (154h
930 writel(temp1, card->pBA0 + BA0_DCR1); // (15ch)
931
932 // Set 'Auto-Initialize Control' to 'enabled'; For playback,
933 // set 'Transfer Type Control'(TR[1:0]) to 'read transfer',
934 // for record, set Transfer Type Control to 'write transfer'.
935 // All other bits set to zero; Some will be changed @ transfer start.
936 temp1 = (DMRn_DMA | DMRn_AUTO | DMRn_TR_READ); // (20000018h)
937 writel(temp1, card->pBA0 + BA0_DMR0); // (150h)
938 temp1 = (DMRn_DMA | DMRn_AUTO | DMRn_TR_WRITE); // (20000014h)
939 writel(temp1, card->pBA0 + BA0_DMR1); // (158h)
940
941 // Enable DMA interrupts generally, and
942 // DMA0 & DMA1 interrupts specifically.
943 temp1 = readl(card->pBA0 + BA0_HIMR) & 0xfffbfcff;
944 writel(temp1, card->pBA0 + BA0_HIMR);
945
946 CS_DBGOUT(CS_FUNCTION, 2,
947 printk(KERN_INFO "cs4281: cs4281_hw_init()- 0\n"));
948 return 0;
949}
950
951#ifndef NOT_CS4281_PM
952static void printpm(struct cs4281_state *s)
953{
954 CS_DBGOUT(CS_PM, 9, printk("pm struct:\n"));
955 CS_DBGOUT(CS_PM, 9, printk("flags:0x%x u32CLKCR1_SAVE: 0%x u32SSPMValue: 0x%x\n",
956 (unsigned)s->pm.flags,s->pm.u32CLKCR1_SAVE,s->pm.u32SSPMValue));
957 CS_DBGOUT(CS_PM, 9, printk("u32PPLVCvalue: 0x%x u32PPRVCvalue: 0x%x\n",
958 s->pm.u32PPLVCvalue,s->pm.u32PPRVCvalue));
959 CS_DBGOUT(CS_PM, 9, printk("u32FMLVCvalue: 0x%x u32FMRVCvalue: 0x%x\n",
960 s->pm.u32FMLVCvalue,s->pm.u32FMRVCvalue));
961 CS_DBGOUT(CS_PM, 9, printk("u32GPIORvalue: 0x%x u32JSCTLvalue: 0x%x\n",
962 s->pm.u32GPIORvalue,s->pm.u32JSCTLvalue));
963 CS_DBGOUT(CS_PM, 9, printk("u32SSCR: 0x%x u32SRCSA: 0x%x\n",
964 s->pm.u32SSCR,s->pm.u32SRCSA));
965 CS_DBGOUT(CS_PM, 9, printk("u32DacASR: 0x%x u32AdcASR: 0x%x\n",
966 s->pm.u32DacASR,s->pm.u32AdcASR));
967 CS_DBGOUT(CS_PM, 9, printk("u32DacSR: 0x%x u32AdcSR: 0x%x\n",
968 s->pm.u32DacSR,s->pm.u32AdcSR));
969 CS_DBGOUT(CS_PM, 9, printk("u32MIDCR_Save: 0x%x\n",
970 s->pm.u32MIDCR_Save));
971
972}
973static void printpipe(struct cs4281_pipeline *pl)
974{
975
976 CS_DBGOUT(CS_PM, 9, printk("pm struct:\n"));
977 CS_DBGOUT(CS_PM, 9, printk("flags:0x%x number: 0%x\n",
978 (unsigned)pl->flags,pl->number));
979 CS_DBGOUT(CS_PM, 9, printk("u32DBAnValue: 0%x u32DBCnValue: 0x%x\n",
980 pl->u32DBAnValue,pl->u32DBCnValue));
981 CS_DBGOUT(CS_PM, 9, printk("u32DMRnValue: 0x%x u32DCRnValue: 0x%x\n",
982 pl->u32DMRnValue,pl->u32DCRnValue));
983 CS_DBGOUT(CS_PM, 9, printk("u32DBAnAddress: 0x%x u32DBCnAddress: 0x%x\n",
984 pl->u32DBAnAddress,pl->u32DBCnAddress));
985 CS_DBGOUT(CS_PM, 9, printk("u32DCAnAddress: 0x%x u32DCCnAddress: 0x%x\n",
986 pl->u32DCCnAddress,pl->u32DCCnAddress));
987 CS_DBGOUT(CS_PM, 9, printk("u32DMRnAddress: 0x%x u32DCRnAddress: 0x%x\n",
988 pl->u32DMRnAddress,pl->u32DCRnAddress));
989 CS_DBGOUT(CS_PM, 9, printk("u32HDSRnAddress: 0x%x u32DBAn_Save: 0x%x\n",
990 pl->u32HDSRnAddress,pl->u32DBAn_Save));
991 CS_DBGOUT(CS_PM, 9, printk("u32DBCn_Save: 0x%x u32DMRn_Save: 0x%x\n",
992 pl->u32DBCn_Save,pl->u32DMRn_Save));
993 CS_DBGOUT(CS_PM, 9, printk("u32DCRn_Save: 0x%x u32DCCn_Save: 0x%x\n",
994 pl->u32DCRn_Save,pl->u32DCCn_Save));
995 CS_DBGOUT(CS_PM, 9, printk("u32DCAn_Save: 0x%x\n",
996 pl->u32DCAn_Save));
997 CS_DBGOUT(CS_PM, 9, printk("u32FCRn_Save: 0x%x u32FSICn_Save: 0x%x\n",
998 pl->u32FCRn_Save,pl->u32FSICn_Save));
999 CS_DBGOUT(CS_PM, 9, printk("u32FCRnValue: 0x%x u32FSICnValue: 0x%x\n",
1000 pl->u32FCRnValue,pl->u32FSICnValue));
1001 CS_DBGOUT(CS_PM, 9, printk("u32FCRnAddress: 0x%x u32FSICnAddress: 0x%x\n",
1002 pl->u32FCRnAddress,pl->u32FSICnAddress));
1003 CS_DBGOUT(CS_PM, 9, printk("u32FPDRnValue: 0x%x u32FPDRnAddress: 0x%x\n",
1004 pl->u32FPDRnValue,pl->u32FPDRnAddress));
1005}
1006static void printpipelines(struct cs4281_state *s)
1007{
1008 int i;
1009 for(i=0;i<CS4281_NUMBER_OF_PIPELINES;i++)
1010 {
1011 if(s->pl[i].flags & CS4281_PIPELINE_VALID)
1012 {
1013 printpipe(&s->pl[i]);
1014 }
1015 }
1016}
1017/****************************************************************************
1018*
1019* Suspend - save the ac97 regs, mute the outputs and power down the part.
1020*
1021****************************************************************************/
1022static void cs4281_ac97_suspend(struct cs4281_state *s)
1023{
1024 int Count,i;
1025
1026 CS_DBGOUT(CS_PM, 9, printk("cs4281: cs4281_ac97_suspend()+\n"));
1027/*
1028* change the state, save the current hwptr, then stop the dac/adc
1029*/
1030 s->pm.flags &= ~CS4281_PM_IDLE;
1031 s->pm.flags |= CS4281_PM_SUSPENDING;
1032 s->pm.u32hwptr_playback = readl(s->pBA0 + BA0_DCA0);
1033 s->pm.u32hwptr_capture = readl(s->pBA0 + BA0_DCA1);
1034 stop_dac(s);
1035 stop_adc(s);
1036
1037 for(Count = 0x2, i=0; (Count <= CS4281_AC97_HIGHESTREGTORESTORE)
1038 && (i < CS4281_AC97_NUMBER_RESTORE_REGS);
1039 Count += 2, i++)
1040 {
1041 cs4281_read_ac97(s, BA0_AC97_RESET + Count, &s->pm.ac97[i]);
1042 }
1043/*
1044* Save the ac97 volume registers as well as the current powerdown state.
1045* Now, mute the all the outputs (master, headphone, and mono), as well
1046* as the PCM volume, in preparation for powering down the entire part.
1047*/
1048 cs4281_read_ac97(s, BA0_AC97_MASTER_VOLUME, &s->pm.u32AC97_master_volume);
1049 cs4281_read_ac97(s, BA0_AC97_HEADPHONE_VOLUME, &s->pm.u32AC97_headphone_volume);
1050 cs4281_read_ac97(s, BA0_AC97_MASTER_VOLUME_MONO, &s->pm.u32AC97_master_volume_mono);
1051 cs4281_read_ac97(s, BA0_AC97_PCM_OUT_VOLUME, &s->pm.u32AC97_pcm_out_volume);
1052
1053 cs4281_write_ac97(s, BA0_AC97_MASTER_VOLUME, 0x8000);
1054 cs4281_write_ac97(s, BA0_AC97_HEADPHONE_VOLUME, 0x8000);
1055 cs4281_write_ac97(s, BA0_AC97_MASTER_VOLUME_MONO, 0x8000);
1056 cs4281_write_ac97(s, BA0_AC97_PCM_OUT_VOLUME, 0x8000);
1057
1058 cs4281_read_ac97(s, BA0_AC97_POWERDOWN, &s->pm.u32AC97_powerdown);
1059 cs4281_read_ac97(s, BA0_AC97_GENERAL_PURPOSE, &s->pm.u32AC97_general_purpose);
1060
1061/*
1062* And power down everything on the AC97 codec.
1063*/
1064 cs4281_write_ac97(s, BA0_AC97_POWERDOWN, 0xff00);
1065 CS_DBGOUT(CS_PM, 9, printk("cs4281: cs4281_ac97_suspend()-\n"));
1066}
1067
1068/****************************************************************************
1069*
1070* Resume - power up the part and restore its registers..
1071*
1072****************************************************************************/
1073static void cs4281_ac97_resume(struct cs4281_state *s)
1074{
1075 int Count,i;
1076
1077 CS_DBGOUT(CS_PM, 9, printk("cs4281: cs4281_ac97_resume()+\n"));
1078
1079/* do not save the power state registers at this time
1080 //
1081 // If we saved away the power control registers, write them into the
1082 // shadows so those saved values get restored instead of the current
1083 // shadowed value.
1084 //
1085 if( bPowerStateSaved )
1086 {
1087 PokeShadow( 0x26, ulSaveReg0x26 );
1088 bPowerStateSaved = FALSE;
1089 }
1090*/
1091
1092//
1093// First, we restore the state of the general purpose register. This
1094// contains the mic select (mic1 or mic2) and if we restore this after
1095// we restore the mic volume/boost state and mic2 was selected at
1096// suspend time, we will end up with a brief period of time where mic1
1097// is selected with the volume/boost settings for mic2, causing
1098// acoustic feedback. So we restore the general purpose register
1099// first, thereby getting the correct mic selected before we restore
1100// the mic volume/boost.
1101//
1102 cs4281_write_ac97(s, BA0_AC97_GENERAL_PURPOSE, s->pm.u32AC97_general_purpose);
1103
1104//
1105// Now, while the outputs are still muted, restore the state of power
1106// on the AC97 part.
1107//
1108 cs4281_write_ac97(s, BA0_AC97_POWERDOWN, s->pm.u32AC97_powerdown);
1109
1110/*
1111* Restore just the first set of registers, from register number
1112* 0x02 to the register number that ulHighestRegToRestore specifies.
1113*/
1114 for( Count = 0x2, i=0;
1115 (Count <= CS4281_AC97_HIGHESTREGTORESTORE)
1116 && (i < CS4281_AC97_NUMBER_RESTORE_REGS);
1117 Count += 2, i++)
1118 {
1119 cs4281_write_ac97(s, BA0_AC97_RESET + Count, s->pm.ac97[i]);
1120 }
1121 CS_DBGOUT(CS_PM, 9, printk("cs4281: cs4281_ac97_resume()-\n"));
1122}
1123
1124/* do not save the power state registers at this time
1125****************************************************************************
1126*
1127* SavePowerState - Save the power registers away.
1128*
1129****************************************************************************
1130void
1131HWAC97codec::SavePowerState(void)
1132{
1133 ENTRY(TM_OBJECTCALLS, "HWAC97codec::SavePowerState()\r\n");
1134
1135 ulSaveReg0x26 = PeekShadow(0x26);
1136
1137 //
1138 // Note that we have saved registers that need to be restored during a
1139 // resume instead of ulAC97Regs[].
1140 //
1141 bPowerStateSaved = TRUE;
1142
1143} // SavePowerState
1144*/
1145
1146static void cs4281_SuspendFIFO(struct cs4281_state *s, struct cs4281_pipeline *pl)
1147{
1148 /*
1149 * We need to save the contents of the BASIC FIFO Registers.
1150 */
1151 pl->u32FCRn_Save = readl(s->pBA0 + pl->u32FCRnAddress);
1152 pl->u32FSICn_Save = readl(s->pBA0 + pl->u32FSICnAddress);
1153}
1154static void cs4281_ResumeFIFO(struct cs4281_state *s, struct cs4281_pipeline *pl)
1155{
1156 /*
1157 * We need to restore the contents of the BASIC FIFO Registers.
1158 */
1159 writel(pl->u32FCRn_Save,s->pBA0 + pl->u32FCRnAddress);
1160 writel(pl->u32FSICn_Save,s->pBA0 + pl->u32FSICnAddress);
1161}
1162static void cs4281_SuspendDMAengine(struct cs4281_state *s, struct cs4281_pipeline *pl)
1163{
1164 //
1165 // We need to save the contents of the BASIC DMA Registers.
1166 //
1167 pl->u32DBAn_Save = readl(s->pBA0 + pl->u32DBAnAddress);
1168 pl->u32DBCn_Save = readl(s->pBA0 + pl->u32DBCnAddress);
1169 pl->u32DMRn_Save = readl(s->pBA0 + pl->u32DMRnAddress);
1170 pl->u32DCRn_Save = readl(s->pBA0 + pl->u32DCRnAddress);
1171 pl->u32DCCn_Save = readl(s->pBA0 + pl->u32DCCnAddress);
1172 pl->u32DCAn_Save = readl(s->pBA0 + pl->u32DCAnAddress);
1173}
1174static void cs4281_ResumeDMAengine(struct cs4281_state *s, struct cs4281_pipeline *pl)
1175{
1176 //
1177 // We need to save the contents of the BASIC DMA Registers.
1178 //
1179 writel( pl->u32DBAn_Save, s->pBA0 + pl->u32DBAnAddress);
1180 writel( pl->u32DBCn_Save, s->pBA0 + pl->u32DBCnAddress);
1181 writel( pl->u32DMRn_Save, s->pBA0 + pl->u32DMRnAddress);
1182 writel( pl->u32DCRn_Save, s->pBA0 + pl->u32DCRnAddress);
1183 writel( pl->u32DCCn_Save, s->pBA0 + pl->u32DCCnAddress);
1184 writel( pl->u32DCAn_Save, s->pBA0 + pl->u32DCAnAddress);
1185}
1186
1187static int cs4281_suspend(struct cs4281_state *s)
1188{
1189 int i;
1190 u32 u32CLKCR1;
1191 struct cs4281_pm *pm = &s->pm;
1192 CS_DBGOUT(CS_PM | CS_FUNCTION, 9,
1193 printk("cs4281: cs4281_suspend()+ flags=%d\n",
1194 (unsigned)s->pm.flags));
1195/*
1196* check the current state, only suspend if IDLE
1197*/
1198 if(!(s->pm.flags & CS4281_PM_IDLE))
1199 {
1200 CS_DBGOUT(CS_PM | CS_ERROR, 2,
1201 printk("cs4281: cs4281_suspend() unable to suspend, not IDLE\n"));
1202 return 1;
1203 }
1204 s->pm.flags &= ~CS4281_PM_IDLE;
1205 s->pm.flags |= CS4281_PM_SUSPENDING;
1206
1207//
1208// Gershwin CLKRUN - Set CKRA
1209//
1210 u32CLKCR1 = readl(s->pBA0 + BA0_CLKCR1);
1211
1212 pm->u32CLKCR1_SAVE = u32CLKCR1;
1213 if(!(u32CLKCR1 & 0x00010000 ) )
1214 writel(u32CLKCR1 | 0x00010000, s->pBA0 + BA0_CLKCR1);
1215
1216//
1217// First, turn on the clocks (yikes) to the devices, so that they will
1218// respond when we try to save their state.
1219//
1220 if(!(u32CLKCR1 & CLKCR1_SWCE))
1221 {
1222 writel(u32CLKCR1 | CLKCR1_SWCE , s->pBA0 + BA0_CLKCR1);
1223 }
1224
1225 //
1226 // Save the power state
1227 //
1228 pm->u32SSPMValue = readl(s->pBA0 + BA0_SSPM);
1229
1230 //
1231 // Disable interrupts.
1232 //
1233 writel(HICR_CHGM, s->pBA0 + BA0_HICR);
1234
1235 //
1236 // Save the PCM Playback Left and Right Volume Control.
1237 //
1238 pm->u32PPLVCvalue = readl(s->pBA0 + BA0_PPLVC);
1239 pm->u32PPRVCvalue = readl(s->pBA0 + BA0_PPRVC);
1240
1241 //
1242 // Save the FM Synthesis Left and Right Volume Control.
1243 //
1244 pm->u32FMLVCvalue = readl(s->pBA0 + BA0_FMLVC);
1245 pm->u32FMRVCvalue = readl(s->pBA0 + BA0_FMRVC);
1246
1247 //
1248 // Save the GPIOR value.
1249 //
1250 pm->u32GPIORvalue = readl(s->pBA0 + BA0_GPIOR);
1251
1252 //
1253 // Save the JSCTL value.
1254 //
1255 pm->u32JSCTLvalue = readl(s->pBA0 + BA0_GPIOR);
1256
1257 //
1258 // Save Sound System Control Register
1259 //
1260 pm->u32SSCR = readl(s->pBA0 + BA0_SSCR);
1261
1262 //
1263 // Save SRC Slot Assinment register
1264 //
1265 pm->u32SRCSA = readl(s->pBA0 + BA0_SRCSA);
1266
1267 //
1268 // Save sample rate
1269 //
1270 pm->u32DacASR = readl(s->pBA0 + BA0_PASR);
1271 pm->u32AdcASR = readl(s->pBA0 + BA0_CASR);
1272 pm->u32DacSR = readl(s->pBA0 + BA0_DACSR);
1273 pm->u32AdcSR = readl(s->pBA0 + BA0_ADCSR);
1274
1275 //
1276 // Loop through all of the PipeLines
1277 //
1278 for(i = 0; i < CS4281_NUMBER_OF_PIPELINES; i++)
1279 {
1280 if(s->pl[i].flags & CS4281_PIPELINE_VALID)
1281 {
1282 //
1283 // Ask the DMAengines and FIFOs to Suspend.
1284 //
1285 cs4281_SuspendDMAengine(s,&s->pl[i]);
1286 cs4281_SuspendFIFO(s,&s->pl[i]);
1287 }
1288 }
1289 //
1290 // We need to save the contents of the Midi Control Register.
1291 //
1292 pm->u32MIDCR_Save = readl(s->pBA0 + BA0_MIDCR);
1293/*
1294* save off the AC97 part information
1295*/
1296 cs4281_ac97_suspend(s);
1297
1298 //
1299 // Turn off the serial ports.
1300 //
1301 writel(0, s->pBA0 + BA0_SERMC);
1302
1303 //
1304 // Power off FM, Joystick, AC link,
1305 //
1306 writel(0, s->pBA0 + BA0_SSPM);
1307
1308 //
1309 // DLL off.
1310 //
1311 writel(0, s->pBA0 + BA0_CLKCR1);
1312
1313 //
1314 // AC link off.
1315 //
1316 writel(0, s->pBA0 + BA0_SPMC);
1317
1318 //
1319 // Put the chip into D3(hot) state.
1320 //
1321 // PokeBA0(BA0_PMCS, 0x00000003);
1322
1323 //
1324 // Gershwin CLKRUN - Clear CKRA
1325 //
1326 u32CLKCR1 = readl(s->pBA0 + BA0_CLKCR1);
1327 writel(u32CLKCR1 & 0xFFFEFFFF, s->pBA0 + BA0_CLKCR1);
1328
1329#ifdef CSDEBUG
1330 printpm(s);
1331 printpipelines(s);
1332#endif
1333
1334 s->pm.flags &= ~CS4281_PM_SUSPENDING;
1335 s->pm.flags |= CS4281_PM_SUSPENDED;
1336
1337 CS_DBGOUT(CS_PM | CS_FUNCTION, 9,
1338 printk("cs4281: cs4281_suspend()- flags=%d\n",
1339 (unsigned)s->pm.flags));
1340 return 0;
1341}
1342
1343static int cs4281_resume(struct cs4281_state *s)
1344{
1345 int i;
1346 unsigned temp1;
1347 u32 u32CLKCR1;
1348 struct cs4281_pm *pm = &s->pm;
1349 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
1350 printk( "cs4281: cs4281_resume()+ flags=%d\n",
1351 (unsigned)s->pm.flags));
1352 if(!(s->pm.flags & CS4281_PM_SUSPENDED))
1353 {
1354 CS_DBGOUT(CS_PM | CS_ERROR, 2,
1355 printk("cs4281: cs4281_resume() unable to resume, not SUSPENDED\n"));
1356 return 1;
1357 }
1358 s->pm.flags &= ~CS4281_PM_SUSPENDED;
1359 s->pm.flags |= CS4281_PM_RESUMING;
1360
1361//
1362// Gershwin CLKRUN - Set CKRA
1363//
1364 u32CLKCR1 = readl(s->pBA0 + BA0_CLKCR1);
1365 writel(u32CLKCR1 | 0x00010000, s->pBA0 + BA0_CLKCR1);
1366
1367 //
1368 // set the power state.
1369 //
1370 //old PokeBA0(BA0_PMCS, 0);
1371
1372 //
1373 // Program the clock circuit and serial ports.
1374 //
1375 temp1 = cs4281_hw_init(s);
1376 if (temp1) {
1377 CS_DBGOUT(CS_ERROR | CS_INIT, 1,
1378 printk(KERN_ERR
1379 "cs4281: resume cs4281_hw_init() error.\n"));
1380 return -1;
1381 }
1382
1383 //
1384 // restore the Power state
1385 //
1386 writel(pm->u32SSPMValue, s->pBA0 + BA0_SSPM);
1387
1388 //
1389 // Set post SRC mix setting (FM or ALT48K)
1390 //
1391 writel(pm->u32SSPM_BITS, s->pBA0 + BA0_SSPM);
1392
1393 //
1394 // Loop through all of the PipeLines
1395 //
1396 for(i = 0; i < CS4281_NUMBER_OF_PIPELINES; i++)
1397 {
1398 if(s->pl[i].flags & CS4281_PIPELINE_VALID)
1399 {
1400 //
1401 // Ask the DMAengines and FIFOs to Resume.
1402 //
1403 cs4281_ResumeDMAengine(s,&s->pl[i]);
1404 cs4281_ResumeFIFO(s,&s->pl[i]);
1405 }
1406 }
1407 //
1408 // We need to restore the contents of the Midi Control Register.
1409 //
1410 writel(pm->u32MIDCR_Save, s->pBA0 + BA0_MIDCR);
1411
1412 cs4281_ac97_resume(s);
1413 //
1414 // Restore the PCM Playback Left and Right Volume Control.
1415 //
1416 writel(pm->u32PPLVCvalue, s->pBA0 + BA0_PPLVC);
1417 writel(pm->u32PPRVCvalue, s->pBA0 + BA0_PPRVC);
1418
1419 //
1420 // Restore the FM Synthesis Left and Right Volume Control.
1421 //
1422 writel(pm->u32FMLVCvalue, s->pBA0 + BA0_FMLVC);
1423 writel(pm->u32FMRVCvalue, s->pBA0 + BA0_FMRVC);
1424
1425 //
1426 // Restore the JSCTL value.
1427 //
1428 writel(pm->u32JSCTLvalue, s->pBA0 + BA0_JSCTL);
1429
1430 //
1431 // Restore the GPIOR register value.
1432 //
1433 writel(pm->u32GPIORvalue, s->pBA0 + BA0_GPIOR);
1434
1435 //
1436 // Restore Sound System Control Register
1437 //
1438 writel(pm->u32SSCR, s->pBA0 + BA0_SSCR);
1439
1440 //
1441 // Restore SRC Slot Assignment register
1442 //
1443 writel(pm->u32SRCSA, s->pBA0 + BA0_SRCSA);
1444
1445 //
1446 // Restore sample rate
1447 //
1448 writel(pm->u32DacASR, s->pBA0 + BA0_PASR);
1449 writel(pm->u32AdcASR, s->pBA0 + BA0_CASR);
1450 writel(pm->u32DacSR, s->pBA0 + BA0_DACSR);
1451 writel(pm->u32AdcSR, s->pBA0 + BA0_ADCSR);
1452
1453 //
1454 // Restore CFL1/2 registers we saved to compensate for OEM bugs.
1455 //
1456 // PokeBA0(BA0_CFLR, ulConfig);
1457
1458 //
1459 // Gershwin CLKRUN - Clear CKRA
1460 //
1461 writel(pm->u32CLKCR1_SAVE, s->pBA0 + BA0_CLKCR1);
1462
1463 //
1464 // Enable interrupts on the part.
1465 //
1466 writel(HICR_IEV | HICR_CHGM, s->pBA0 + BA0_HICR);
1467
1468#ifdef CSDEBUG
1469 printpm(s);
1470 printpipelines(s);
1471#endif
1472/*
1473* change the state, restore the current hwptrs, then stop the dac/adc
1474*/
1475 s->pm.flags |= CS4281_PM_IDLE;
1476 s->pm.flags &= ~(CS4281_PM_SUSPENDING | CS4281_PM_SUSPENDED
1477 | CS4281_PM_RESUMING | CS4281_PM_RESUMED);
1478
1479 writel(s->pm.u32hwptr_playback, s->pBA0 + BA0_DCA0);
1480 writel(s->pm.u32hwptr_capture, s->pBA0 + BA0_DCA1);
1481 start_dac(s);
1482 start_adc(s);
1483
1484 CS_DBGOUT(CS_PM | CS_FUNCTION, 9, printk("cs4281: cs4281_resume()- flags=%d\n",
1485 (unsigned)s->pm.flags));
1486 return 0;
1487}
1488
1489#endif
1490
1491//******************************************************************************
1492// "cs4281_play_rate()" --
1493//******************************************************************************
1494static void cs4281_play_rate(struct cs4281_state *card, u32 playrate)
1495{
1496 u32 DACSRvalue = 1;
1497
1498 // Based on the sample rate, program the DACSR register.
1499 if (playrate == 8000)
1500 DACSRvalue = 5;
1501 if (playrate == 11025)
1502 DACSRvalue = 4;
1503 else if (playrate == 22050)
1504 DACSRvalue = 2;
1505 else if (playrate == 44100)
1506 DACSRvalue = 1;
1507 else if ((playrate <= 48000) && (playrate >= 6023))
1508 DACSRvalue = 24576000 / (playrate * 16);
1509 else if (playrate < 6023)
1510 // Not allowed by open.
1511 return;
1512 else if (playrate > 48000)
1513 // Not allowed by open.
1514 return;
1515 CS_DBGOUT(CS_WAVE_WRITE | CS_PARMS, 2, printk(KERN_INFO
1516 "cs4281: cs4281_play_rate(): DACSRvalue=0x%.8x playrate=%d\n",
1517 DACSRvalue, playrate));
1518 // Write the 'sample rate select code'
1519 // to the 'DAC Sample Rate' register.
1520 writel(DACSRvalue, card->pBA0 + BA0_DACSR); // (744h)
1521}
1522
1523//******************************************************************************
1524// "cs4281_record_rate()" -- Initialize the record sample rate converter.
1525//******************************************************************************
1526static void cs4281_record_rate(struct cs4281_state *card, u32 outrate)
1527{
1528 u32 ADCSRvalue = 1;
1529
1530 //
1531 // Based on the sample rate, program the ADCSR register
1532 //
1533 if (outrate == 8000)
1534 ADCSRvalue = 5;
1535 if (outrate == 11025)
1536 ADCSRvalue = 4;
1537 else if (outrate == 22050)
1538 ADCSRvalue = 2;
1539 else if (outrate == 44100)
1540 ADCSRvalue = 1;
1541 else if ((outrate <= 48000) && (outrate >= 6023))
1542 ADCSRvalue = 24576000 / (outrate * 16);
1543 else if (outrate < 6023) {
1544 // Not allowed by open.
1545 return;
1546 } else if (outrate > 48000) {
1547 // Not allowed by open.
1548 return;
1549 }
1550 CS_DBGOUT(CS_WAVE_READ | CS_PARMS, 2, printk(KERN_INFO
1551 "cs4281: cs4281_record_rate(): ADCSRvalue=0x%.8x outrate=%d\n",
1552 ADCSRvalue, outrate));
1553 // Write the 'sample rate select code
1554 // to the 'ADC Sample Rate' register.
1555 writel(ADCSRvalue, card->pBA0 + BA0_ADCSR); // (748h)
1556}
1557
1558
1559
1560static void stop_dac(struct cs4281_state *s)
1561{
1562 unsigned long flags;
1563 unsigned temp1;
1564
1565 CS_DBGOUT(CS_WAVE_WRITE, 3, printk(KERN_INFO "cs4281: stop_dac():\n"));
1566 spin_lock_irqsave(&s->lock, flags);
1567 s->ena &= ~FMODE_WRITE;
1568 temp1 = readl(s->pBA0 + BA0_DCR0) | DCRn_MSK;
1569 writel(temp1, s->pBA0 + BA0_DCR0);
1570
1571 spin_unlock_irqrestore(&s->lock, flags);
1572}
1573
1574
1575static void start_dac(struct cs4281_state *s)
1576{
1577 unsigned long flags;
1578 unsigned temp1;
1579
1580 CS_DBGOUT(CS_FUNCTION, 3, printk(KERN_INFO "cs4281: start_dac()+\n"));
1581 spin_lock_irqsave(&s->lock, flags);
1582 if (!(s->ena & FMODE_WRITE) && (s->dma_dac.mapped ||
1583 (s->dma_dac.count > 0
1584 && s->dma_dac.ready))
1585#ifndef NOT_CS4281_PM
1586 && (s->pm.flags & CS4281_PM_IDLE))
1587#else
1588)
1589#endif
1590 {
1591 s->ena |= FMODE_WRITE;
1592 temp1 = readl(s->pBA0 + BA0_DCR0) & ~DCRn_MSK; // Clear DMA0 channel mask.
1593 writel(temp1, s->pBA0 + BA0_DCR0); // Start DMA'ing.
1594 writel(HICR_IEV | HICR_CHGM, s->pBA0 + BA0_HICR); // Enable interrupts.
1595
1596 writel(7, s->pBA0 + BA0_PPRVC);
1597 writel(7, s->pBA0 + BA0_PPLVC);
1598 CS_DBGOUT(CS_WAVE_WRITE | CS_PARMS, 8, printk(KERN_INFO
1599 "cs4281: start_dac(): writel 0x%x start dma\n", temp1));
1600
1601 }
1602 spin_unlock_irqrestore(&s->lock, flags);
1603 CS_DBGOUT(CS_FUNCTION, 3,
1604 printk(KERN_INFO "cs4281: start_dac()-\n"));
1605}
1606
1607
1608static void stop_adc(struct cs4281_state *s)
1609{
1610 unsigned long flags;
1611 unsigned temp1;
1612
1613 CS_DBGOUT(CS_FUNCTION, 3,
1614 printk(KERN_INFO "cs4281: stop_adc()+\n"));
1615
1616 spin_lock_irqsave(&s->lock, flags);
1617 s->ena &= ~FMODE_READ;
1618
1619 if (s->conversion == 1) {
1620 s->conversion = 0;
1621 s->prop_adc.fmt = s->prop_adc.fmt_original;
1622 }
1623 temp1 = readl(s->pBA0 + BA0_DCR1) | DCRn_MSK;
1624 writel(temp1, s->pBA0 + BA0_DCR1);
1625 spin_unlock_irqrestore(&s->lock, flags);
1626 CS_DBGOUT(CS_FUNCTION, 3,
1627 printk(KERN_INFO "cs4281: stop_adc()-\n"));
1628}
1629
1630
1631static void start_adc(struct cs4281_state *s)
1632{
1633 unsigned long flags;
1634 unsigned temp1;
1635
1636 CS_DBGOUT(CS_FUNCTION, 2,
1637 printk(KERN_INFO "cs4281: start_adc()+\n"));
1638
1639 if (!(s->ena & FMODE_READ) &&
1640 (s->dma_adc.mapped || s->dma_adc.count <=
1641 (signed) (s->dma_adc.dmasize - 2 * s->dma_adc.fragsize))
1642 && s->dma_adc.ready
1643#ifndef NOT_CS4281_PM
1644 && (s->pm.flags & CS4281_PM_IDLE))
1645#else
1646)
1647#endif
1648 {
1649 if (s->prop_adc.fmt & AFMT_S8 || s->prop_adc.fmt & AFMT_U8) {
1650 //
1651 // now only use 16 bit capture, due to truncation issue
1652 // in the chip, noticable distortion occurs.
1653 // allocate buffer and then convert from 16 bit to
1654 // 8 bit for the user buffer.
1655 //
1656 s->prop_adc.fmt_original = s->prop_adc.fmt;
1657 if (s->prop_adc.fmt & AFMT_S8) {
1658 s->prop_adc.fmt &= ~AFMT_S8;
1659 s->prop_adc.fmt |= AFMT_S16_LE;
1660 }
1661 if (s->prop_adc.fmt & AFMT_U8) {
1662 s->prop_adc.fmt &= ~AFMT_U8;
1663 s->prop_adc.fmt |= AFMT_U16_LE;
1664 }
1665 //
1666 // prog_dmabuf_adc performs a stop_adc() but that is
1667 // ok since we really haven't started the DMA yet.
1668 //
1669 prog_codec(s, CS_TYPE_ADC);
1670
1671 if (prog_dmabuf_adc(s) != 0) {
1672 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
1673 "cs4281: start_adc(): error in prog_dmabuf_adc\n"));
1674 }
1675 s->conversion = 1;
1676 }
1677 spin_lock_irqsave(&s->lock, flags);
1678 s->ena |= FMODE_READ;
1679 temp1 = readl(s->pBA0 + BA0_DCR1) & ~DCRn_MSK; // Clear DMA1 channel mask bit.
1680 writel(temp1, s->pBA0 + BA0_DCR1); // Start recording
1681 writel(HICR_IEV | HICR_CHGM, s->pBA0 + BA0_HICR); // Enable interrupts.
1682 spin_unlock_irqrestore(&s->lock, flags);
1683
1684 CS_DBGOUT(CS_PARMS, 6, printk(KERN_INFO
1685 "cs4281: start_adc(): writel 0x%x \n", temp1));
1686 }
1687 CS_DBGOUT(CS_FUNCTION, 2,
1688 printk(KERN_INFO "cs4281: start_adc()-\n"));
1689
1690}
1691
1692
1693// ---------------------------------------------------------------------
1694
1695#define DMABUF_MINORDER 1 // ==> min buffer size = 8K.
1696
1697
1698static void dealloc_dmabuf(struct cs4281_state *s, struct dmabuf *db)
1699{
1700 struct page *map, *mapend;
1701
1702 if (db->rawbuf) {
1703 // Undo prog_dmabuf()'s marking the pages as reserved
1704 mapend =
1705 virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) -
1706 1);
1707 for (map = virt_to_page(db->rawbuf); map <= mapend; map++)
1708 ClearPageReserved(map);
1709 free_dmabuf(s, db);
1710 }
1711 if (s->tmpbuff && (db->type == CS_TYPE_ADC)) {
1712 // Undo prog_dmabuf()'s marking the pages as reserved
1713 mapend =
1714 virt_to_page(s->tmpbuff +
1715 (PAGE_SIZE << s->buforder_tmpbuff) - 1);
1716 for (map = virt_to_page(s->tmpbuff); map <= mapend; map++)
1717 ClearPageReserved(map);
1718 free_dmabuf2(s, db);
1719 }
1720 s->tmpbuff = NULL;
1721 db->rawbuf = NULL;
1722 db->mapped = db->ready = 0;
1723}
1724
1725static int prog_dmabuf(struct cs4281_state *s, struct dmabuf *db)
1726{
1727 int order;
1728 unsigned bytespersec, temp1;
1729 unsigned bufs, sample_shift = 0;
1730 struct page *map, *mapend;
1731 unsigned long df;
1732
1733 CS_DBGOUT(CS_FUNCTION, 2,
1734 printk(KERN_INFO "cs4281: prog_dmabuf()+\n"));
1735 db->hwptr = db->swptr = db->total_bytes = db->count = db->error =
1736 db->endcleared = db->blocks = db->wakeup = db->underrun = 0;
1737/*
1738* check for order within limits, but do not overwrite value, check
1739* later for a fractional defaultorder (i.e. 100+).
1740*/
1741 if((defaultorder > 0) && (defaultorder < 12))
1742 df = defaultorder;
1743 else
1744 df = 1;
1745
1746 if (!db->rawbuf) {
1747 db->ready = db->mapped = 0;
1748 for (order = df; order >= DMABUF_MINORDER; order--)
1749 if ( (db->rawbuf = (void *) pci_alloc_consistent(
1750 s->pcidev, PAGE_SIZE << order, &db-> dmaaddr)))
1751 break;
1752 if (!db->rawbuf) {
1753 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
1754 "cs4281: prog_dmabuf(): unable to allocate rawbuf\n"));
1755 return -ENOMEM;
1756 }
1757 db->buforder = order;
1758 // Now mark the pages as reserved; otherwise the
1759 // remap_pfn_range() in cs4281_mmap doesn't work.
1760 // 1. get index to last page in mem_map array for rawbuf.
1761 mapend = virt_to_page(db->rawbuf +
1762 (PAGE_SIZE << db->buforder) - 1);
1763
1764 // 2. mark each physical page in range as 'reserved'.
1765 for (map = virt_to_page(db->rawbuf); map <= mapend; map++)
1766 SetPageReserved(map);
1767 }
1768 if (!s->tmpbuff && (db->type == CS_TYPE_ADC)) {
1769 for (order = df; order >= DMABUF_MINORDER;
1770 order--)
1771 if ( (s->tmpbuff = (void *) pci_alloc_consistent(
1772 s->pcidev, PAGE_SIZE << order,
1773 &s->dmaaddr_tmpbuff)))
1774 break;
1775 if (!s->tmpbuff) {
1776 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
1777 "cs4281: prog_dmabuf(): unable to allocate tmpbuff\n"));
1778 return -ENOMEM;
1779 }
1780 s->buforder_tmpbuff = order;
1781 // Now mark the pages as reserved; otherwise the
1782 // remap_pfn_range() in cs4281_mmap doesn't work.
1783 // 1. get index to last page in mem_map array for rawbuf.
1784 mapend = virt_to_page(s->tmpbuff +
1785 (PAGE_SIZE << s->buforder_tmpbuff) - 1);
1786
1787 // 2. mark each physical page in range as 'reserved'.
1788 for (map = virt_to_page(s->tmpbuff); map <= mapend; map++)
1789 SetPageReserved(map);
1790 }
1791 if (db->type == CS_TYPE_DAC) {
1792 if (s->prop_dac.fmt & (AFMT_S16_LE | AFMT_U16_LE))
1793 sample_shift++;
1794 if (s->prop_dac.channels > 1)
1795 sample_shift++;
1796 bytespersec = s->prop_dac.rate << sample_shift;
1797 } else // CS_TYPE_ADC
1798 {
1799 if (s->prop_adc.fmt & (AFMT_S16_LE | AFMT_U16_LE))
1800 sample_shift++;
1801 if (s->prop_adc.channels > 1)
1802 sample_shift++;
1803 bytespersec = s->prop_adc.rate << sample_shift;
1804 }
1805 bufs = PAGE_SIZE << db->buforder;
1806
1807/*
1808* added fractional "defaultorder" inputs. if >100 then use
1809* defaultorder-100 as power of 2 for the buffer size. example:
1810* 106 = 2^(106-100) = 2^6 = 64 bytes for the buffer size.
1811*/
1812 if(defaultorder >= 100)
1813 {
1814 bufs = 1 << (defaultorder-100);
1815 }
1816
1817#define INTERRUPT_RATE_MS 100 // Interrupt rate in milliseconds.
1818 db->numfrag = 2;
1819/*
1820* Nominal frag size(bytes/interrupt)
1821*/
1822 temp1 = bytespersec / (1000 / INTERRUPT_RATE_MS);
1823 db->fragshift = 8; // Min 256 bytes.
1824 while (1 << db->fragshift < temp1) // Calc power of 2 frag size.
1825 db->fragshift += 1;
1826 db->fragsize = 1 << db->fragshift;
1827 db->dmasize = db->fragsize * 2;
1828 db->fragsamples = db->fragsize >> sample_shift; // # samples/fragment.
1829
1830// If the calculated size is larger than the allocated
1831// buffer, divide the allocated buffer into 2 fragments.
1832 if (db->dmasize > bufs) {
1833
1834 db->numfrag = 2; // Two fragments.
1835 db->fragsize = bufs >> 1; // Each 1/2 the alloc'ed buffer.
1836 db->fragsamples = db->fragsize >> sample_shift; // # samples/fragment.
1837 db->dmasize = bufs; // Use all the alloc'ed buffer.
1838
1839 db->fragshift = 0; // Calculate 'fragshift'.
1840 temp1 = db->fragsize; // update_ptr() uses it
1841 while ((temp1 >>= 1) > 1) // to calc 'total-bytes'
1842 db->fragshift += 1; // returned in DSP_GETI/OPTR.
1843 }
1844 CS_DBGOUT(CS_PARMS, 3, printk(KERN_INFO
1845 "cs4281: prog_dmabuf(): numfrag=%d fragsize=%d fragsamples=%d fragshift=%d bufs=%d fmt=0x%x ch=%d\n",
1846 db->numfrag, db->fragsize, db->fragsamples,
1847 db->fragshift, bufs,
1848 (db->type == CS_TYPE_DAC) ? s->prop_dac.fmt :
1849 s->prop_adc.fmt,
1850 (db->type == CS_TYPE_DAC) ? s->prop_dac.channels :
1851 s->prop_adc.channels));
1852 CS_DBGOUT(CS_FUNCTION, 2,
1853 printk(KERN_INFO "cs4281: prog_dmabuf()-\n"));
1854 return 0;
1855}
1856
1857
1858static int prog_dmabuf_adc(struct cs4281_state *s)
1859{
1860 unsigned long va;
1861 unsigned count;
1862 int c;
1863 stop_adc(s);
1864 s->dma_adc.type = CS_TYPE_ADC;
1865 if ((c = prog_dmabuf(s, &s->dma_adc)))
1866 return c;
1867
1868 if (s->dma_adc.rawbuf) {
1869 memset(s->dma_adc.rawbuf,
1870 (s->prop_adc.
1871 fmt & (AFMT_U8 | AFMT_U16_LE)) ? 0x80 : 0,
1872 s->dma_adc.dmasize);
1873 }
1874 if (s->tmpbuff) {
1875 memset(s->tmpbuff,
1876 (s->prop_adc.
1877 fmt & (AFMT_U8 | AFMT_U16_LE)) ? 0x80 : 0,
1878 PAGE_SIZE << s->buforder_tmpbuff);
1879 }
1880
1881 va = virt_to_bus(s->dma_adc.rawbuf);
1882
1883 count = s->dma_adc.dmasize;
1884
1885 if (s->prop_adc.
1886 fmt & (AFMT_S16_LE | AFMT_U16_LE | AFMT_S16_BE | AFMT_U16_BE))
1887 count /= 2; // 16-bit.
1888
1889 if (s->prop_adc.channels > 1)
1890 count /= 2; // Assume stereo.
1891
1892 CS_DBGOUT(CS_WAVE_READ, 3, printk(KERN_INFO
1893 "cs4281: prog_dmabuf_adc(): count=%d va=0x%.8x\n",
1894 count, (unsigned) va));
1895
1896 writel(va, s->pBA0 + BA0_DBA1); // Set buffer start address.
1897 writel(count - 1, s->pBA0 + BA0_DBC1); // Set count.
1898 s->dma_adc.ready = 1;
1899 return 0;
1900}
1901
1902
1903static int prog_dmabuf_dac(struct cs4281_state *s)
1904{
1905 unsigned long va;
1906 unsigned count;
1907 int c;
1908 stop_dac(s);
1909 s->dma_dac.type = CS_TYPE_DAC;
1910 if ((c = prog_dmabuf(s, &s->dma_dac)))
1911 return c;
1912 memset(s->dma_dac.rawbuf,
1913 (s->prop_dac.fmt & (AFMT_U8 | AFMT_U16_LE)) ? 0x80 : 0,
1914 s->dma_dac.dmasize);
1915
1916 va = virt_to_bus(s->dma_dac.rawbuf);
1917
1918 count = s->dma_dac.dmasize;
1919 if (s->prop_dac.
1920 fmt & (AFMT_S16_LE | AFMT_U16_LE | AFMT_S16_BE | AFMT_U16_BE))
1921 count /= 2; // 16-bit.
1922
1923 if (s->prop_dac.channels > 1)
1924 count /= 2; // Assume stereo.
1925
1926 writel(va, s->pBA0 + BA0_DBA0); // Set buffer start address.
1927 writel(count - 1, s->pBA0 + BA0_DBC0); // Set count.
1928
1929 CS_DBGOUT(CS_WAVE_WRITE, 3, printk(KERN_INFO
1930 "cs4281: prog_dmabuf_dac(): count=%d va=0x%.8x\n",
1931 count, (unsigned) va));
1932
1933 s->dma_dac.ready = 1;
1934 return 0;
1935}
1936
1937
1938static void clear_advance(void *buf, unsigned bsize, unsigned bptr,
1939 unsigned len, unsigned char c)
1940{
1941 if (bptr + len > bsize) {
1942 unsigned x = bsize - bptr;
1943 memset(((char *) buf) + bptr, c, x);
1944 bptr = 0;
1945 len -= x;
1946 }
1947 CS_DBGOUT(CS_WAVE_WRITE, 4, printk(KERN_INFO
1948 "cs4281: clear_advance(): memset %d at %p for %d size \n",
1949 (unsigned)c, ((char *) buf) + bptr, len));
1950 memset(((char *) buf) + bptr, c, len);
1951}
1952
1953
1954
1955// call with spinlock held!
1956static void cs4281_update_ptr(struct cs4281_state *s, int intflag)
1957{
1958 int diff;
1959 unsigned hwptr, va;
1960
1961 // update ADC pointer
1962 if (s->ena & FMODE_READ) {
1963 hwptr = readl(s->pBA0 + BA0_DCA1); // Read capture DMA address.
1964 va = virt_to_bus(s->dma_adc.rawbuf);
1965 hwptr -= (unsigned) va;
1966 diff =
1967 (s->dma_adc.dmasize + hwptr -
1968 s->dma_adc.hwptr) % s->dma_adc.dmasize;
1969 s->dma_adc.hwptr = hwptr;
1970 s->dma_adc.total_bytes += diff;
1971 s->dma_adc.count += diff;
1972 if (s->dma_adc.count > s->dma_adc.dmasize)
1973 s->dma_adc.count = s->dma_adc.dmasize;
1974 if (s->dma_adc.mapped) {
1975 if (s->dma_adc.count >=
1976 (signed) s->dma_adc.fragsize) wake_up(&s->
1977 dma_adc.
1978 wait);
1979 } else {
1980 if (s->dma_adc.count > 0)
1981 wake_up(&s->dma_adc.wait);
1982 }
1983 CS_DBGOUT(CS_PARMS, 8, printk(KERN_INFO
1984 "cs4281: cs4281_update_ptr(): s=%p hwptr=%d total_bytes=%d count=%d \n",
1985 s, s->dma_adc.hwptr, s->dma_adc.total_bytes, s->dma_adc.count));
1986 }
1987 // update DAC pointer
1988 //
1989 // check for end of buffer, means that we are going to wait for another interrupt
1990 // to allow silence to fill the fifos on the part, to keep pops down to a minimum.
1991 //
1992 if (s->ena & FMODE_WRITE) {
1993 hwptr = readl(s->pBA0 + BA0_DCA0); // Read play DMA address.
1994 va = virt_to_bus(s->dma_dac.rawbuf);
1995 hwptr -= (unsigned) va;
1996 diff = (s->dma_dac.dmasize + hwptr -
1997 s->dma_dac.hwptr) % s->dma_dac.dmasize;
1998 s->dma_dac.hwptr = hwptr;
1999 s->dma_dac.total_bytes += diff;
2000 if (s->dma_dac.mapped) {
2001 s->dma_dac.count += diff;
2002 if (s->dma_dac.count >= s->dma_dac.fragsize) {
2003 s->dma_dac.wakeup = 1;
2004 wake_up(&s->dma_dac.wait);
2005 if (s->dma_dac.count > s->dma_dac.dmasize)
2006 s->dma_dac.count &=
2007 s->dma_dac.dmasize - 1;
2008 }
2009 } else {
2010 s->dma_dac.count -= diff;
2011 if (s->dma_dac.count <= 0) {
2012 //
2013 // fill with silence, and do not shut down the DAC.
2014 // Continue to play silence until the _release.
2015 //
2016 CS_DBGOUT(CS_WAVE_WRITE, 6, printk(KERN_INFO
2017 "cs4281: cs4281_update_ptr(): memset %d at %p for %d size \n",
2018 (unsigned)(s->prop_dac.fmt &
2019 (AFMT_U8 | AFMT_U16_LE)) ? 0x80 : 0,
2020 s->dma_dac.rawbuf, s->dma_dac.dmasize));
2021 memset(s->dma_dac.rawbuf,
2022 (s->prop_dac.
2023 fmt & (AFMT_U8 | AFMT_U16_LE)) ?
2024 0x80 : 0, s->dma_dac.dmasize);
2025 if (s->dma_dac.count < 0) {
2026 s->dma_dac.underrun = 1;
2027 s->dma_dac.count = 0;
2028 CS_DBGOUT(CS_ERROR, 9, printk(KERN_INFO
2029 "cs4281: cs4281_update_ptr(): underrun\n"));
2030 }
2031 } else if (s->dma_dac.count <=
2032 (signed) s->dma_dac.fragsize
2033 && !s->dma_dac.endcleared) {
2034 clear_advance(s->dma_dac.rawbuf,
2035 s->dma_dac.dmasize,
2036 s->dma_dac.swptr,
2037 s->dma_dac.fragsize,
2038 (s->prop_dac.
2039 fmt & (AFMT_U8 |
2040 AFMT_U16_LE)) ? 0x80
2041 : 0);
2042 s->dma_dac.endcleared = 1;
2043 }
2044 if ( (s->dma_dac.count <= (signed) s->dma_dac.dmasize/2) ||
2045 intflag)
2046 {
2047 wake_up(&s->dma_dac.wait);
2048 }
2049 }
2050 CS_DBGOUT(CS_PARMS, 8, printk(KERN_INFO
2051 "cs4281: cs4281_update_ptr(): s=%p hwptr=%d total_bytes=%d count=%d \n",
2052 s, s->dma_dac.hwptr, s->dma_dac.total_bytes, s->dma_dac.count));
2053 }
2054}
2055
2056
2057// ---------------------------------------------------------------------
2058
2059static void prog_codec(struct cs4281_state *s, unsigned type)
2060{
2061 unsigned long flags;
2062 unsigned temp1, format;
2063
2064 CS_DBGOUT(CS_FUNCTION, 2,
2065 printk(KERN_INFO "cs4281: prog_codec()+ \n"));
2066
2067 spin_lock_irqsave(&s->lock, flags);
2068 if (type == CS_TYPE_ADC) {
2069 temp1 = readl(s->pBA0 + BA0_DCR1);
2070 writel(temp1 | DCRn_MSK, s->pBA0 + BA0_DCR1); // Stop capture DMA, if active.
2071
2072 // program sampling rates
2073 // Note, for CS4281, capture & play rates can be set independently.
2074 cs4281_record_rate(s, s->prop_adc.rate);
2075
2076 // program ADC parameters
2077 format = DMRn_DMA | DMRn_AUTO | DMRn_TR_WRITE;
2078 if (s->prop_adc.
2079 fmt & (AFMT_S16_LE | AFMT_U16_LE | AFMT_S16_BE | AFMT_U16_BE)) { // 16-bit
2080 if (s->prop_adc.fmt & (AFMT_S16_BE | AFMT_U16_BE)) // Big-endian?
2081 format |= DMRn_BEND;
2082 if (s->prop_adc.fmt & (AFMT_U16_LE | AFMT_U16_BE))
2083 format |= DMRn_USIGN; // Unsigned.
2084 } else
2085 format |= DMRn_SIZE8 | DMRn_USIGN; // 8-bit, unsigned
2086 if (s->prop_adc.channels < 2)
2087 format |= DMRn_MONO;
2088
2089 writel(format, s->pBA0 + BA0_DMR1);
2090
2091 CS_DBGOUT(CS_PARMS, 2, printk(KERN_INFO
2092 "cs4281: prog_codec(): adc %s %s %s rate=%d DMR0 format=0x%.8x\n",
2093 (format & DMRn_SIZE8) ? "8" : "16",
2094 (format & DMRn_USIGN) ? "Unsigned" : "Signed",
2095 (format & DMRn_MONO) ? "Mono" : "Stereo",
2096 s->prop_adc.rate, format));
2097
2098 s->ena &= ~FMODE_READ; // not capturing data yet
2099 }
2100
2101
2102 if (type == CS_TYPE_DAC) {
2103 temp1 = readl(s->pBA0 + BA0_DCR0);
2104 writel(temp1 | DCRn_MSK, s->pBA0 + BA0_DCR0); // Stop play DMA, if active.
2105
2106 // program sampling rates
2107 // Note, for CS4281, capture & play rates can be set independently.
2108 cs4281_play_rate(s, s->prop_dac.rate);
2109
2110 // program DAC parameters
2111 format = DMRn_DMA | DMRn_AUTO | DMRn_TR_READ;
2112 if (s->prop_dac.
2113 fmt & (AFMT_S16_LE | AFMT_U16_LE | AFMT_S16_BE | AFMT_U16_BE)) { // 16-bit
2114 if (s->prop_dac.fmt & (AFMT_S16_BE | AFMT_U16_BE))
2115 format |= DMRn_BEND; // Big Endian.
2116 if (s->prop_dac.fmt & (AFMT_U16_LE | AFMT_U16_BE))
2117 format |= DMRn_USIGN; // Unsigned.
2118 } else
2119 format |= DMRn_SIZE8 | DMRn_USIGN; // 8-bit, unsigned
2120
2121 if (s->prop_dac.channels < 2)
2122 format |= DMRn_MONO;
2123
2124 writel(format, s->pBA0 + BA0_DMR0);
2125
2126
2127 CS_DBGOUT(CS_PARMS, 2, printk(KERN_INFO
2128 "cs4281: prog_codec(): dac %s %s %s rate=%d DMR0 format=0x%.8x\n",
2129 (format & DMRn_SIZE8) ? "8" : "16",
2130 (format & DMRn_USIGN) ? "Unsigned" : "Signed",
2131 (format & DMRn_MONO) ? "Mono" : "Stereo",
2132 s->prop_dac.rate, format));
2133
2134 s->ena &= ~FMODE_WRITE; // not capturing data yet
2135
2136 }
2137 spin_unlock_irqrestore(&s->lock, flags);
2138 CS_DBGOUT(CS_FUNCTION, 2,
2139 printk(KERN_INFO "cs4281: prog_codec()- \n"));
2140}
2141
2142
2143static int mixer_ioctl(struct cs4281_state *s, unsigned int cmd,
2144 unsigned long arg)
2145{
2146 // Index to mixer_src[] is value of AC97 Input Mux Select Reg.
2147 // Value of array member is recording source Device ID Mask.
2148 static const unsigned int mixer_src[8] = {
2149 SOUND_MASK_MIC, SOUND_MASK_CD, 0, SOUND_MASK_LINE1,
2150 SOUND_MASK_LINE, SOUND_MASK_VOLUME, 0, 0
2151 };
2152 void __user *argp = (void __user *)arg;
2153
2154 // Index of mixtable1[] member is Device ID
2155 // and must be <= SOUND_MIXER_NRDEVICES.
2156 // Value of array member is index into s->mix.vol[]
2157 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
2158 [SOUND_MIXER_PCM] = 1, // voice
2159 [SOUND_MIXER_LINE1] = 2, // AUX
2160 [SOUND_MIXER_CD] = 3, // CD
2161 [SOUND_MIXER_LINE] = 4, // Line
2162 [SOUND_MIXER_SYNTH] = 5, // FM
2163 [SOUND_MIXER_MIC] = 6, // Mic
2164 [SOUND_MIXER_SPEAKER] = 7, // Speaker
2165 [SOUND_MIXER_RECLEV] = 8, // Recording level
2166 [SOUND_MIXER_VOLUME] = 9 // Master Volume
2167 };
2168
2169
2170 static const unsigned mixreg[] = {
2171 BA0_AC97_PCM_OUT_VOLUME,
2172 BA0_AC97_AUX_VOLUME,
2173 BA0_AC97_CD_VOLUME,
2174 BA0_AC97_LINE_IN_VOLUME
2175 };
2176 unsigned char l, r, rl, rr, vidx;
2177 unsigned char attentbl[11] =
2178 { 63, 42, 26, 17, 14, 11, 8, 6, 4, 2, 0 };
2179 unsigned temp1;
2180 int i, val;
2181
2182 VALIDATE_STATE(s);
2183 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
2184 "cs4281: mixer_ioctl(): s=%p cmd=0x%.8x\n", s, cmd));
2185#if CSDEBUG
2186 cs_printioctl(cmd);
2187#endif
2188#if CSDEBUG_INTERFACE
2189
2190 if ((cmd == SOUND_MIXER_CS_GETDBGMASK) ||
2191 (cmd == SOUND_MIXER_CS_SETDBGMASK) ||
2192 (cmd == SOUND_MIXER_CS_GETDBGLEVEL) ||
2193 (cmd == SOUND_MIXER_CS_SETDBGLEVEL) ||
2194 (cmd == SOUND_MIXER_CS_APM))
2195 {
2196 switch (cmd) {
2197
2198 case SOUND_MIXER_CS_GETDBGMASK:
2199 return put_user(cs_debugmask,
2200 (unsigned long __user *) argp);
2201
2202 case SOUND_MIXER_CS_GETDBGLEVEL:
2203 return put_user(cs_debuglevel,
2204 (unsigned long __user *) argp);
2205
2206 case SOUND_MIXER_CS_SETDBGMASK:
2207 if (get_user(val, (unsigned long __user *) argp))
2208 return -EFAULT;
2209 cs_debugmask = val;
2210 return 0;
2211
2212 case SOUND_MIXER_CS_SETDBGLEVEL:
2213 if (get_user(val, (unsigned long __user *) argp))
2214 return -EFAULT;
2215 cs_debuglevel = val;
2216 return 0;
2217#ifndef NOT_CS4281_PM
2218 case SOUND_MIXER_CS_APM:
2219 if (get_user(val, (unsigned long __user *) argp))
2220 return -EFAULT;
2221 if(val == CS_IOCTL_CMD_SUSPEND)
2222 cs4281_suspend(s);
2223 else if(val == CS_IOCTL_CMD_RESUME)
2224 cs4281_resume(s);
2225 else
2226 {
2227 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
2228 "cs4281: mixer_ioctl(): invalid APM cmd (%d)\n",
2229 val));
2230 }
2231 return 0;
2232#endif
2233 default:
2234 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
2235 "cs4281: mixer_ioctl(): ERROR unknown debug cmd\n"));
2236 return 0;
2237 }
2238 }
2239#endif
2240
2241 if (cmd == SOUND_MIXER_PRIVATE1) {
2242 // enable/disable/query mixer preamp
2243 if (get_user(val, (int __user *) argp))
2244 return -EFAULT;
2245 if (val != -1) {
2246 cs4281_read_ac97(s, BA0_AC97_MIC_VOLUME, &temp1);
2247 temp1 = val ? (temp1 | 0x40) : (temp1 & 0xffbf);
2248 cs4281_write_ac97(s, BA0_AC97_MIC_VOLUME, temp1);
2249 }
2250 cs4281_read_ac97(s, BA0_AC97_MIC_VOLUME, &temp1);
2251 val = (temp1 & 0x40) ? 1 : 0;
2252 return put_user(val, (int __user *) argp);
2253 }
2254 if (cmd == SOUND_MIXER_PRIVATE2) {
2255 // enable/disable/query spatializer
2256 if (get_user(val, (int __user *)argp))
2257 return -EFAULT;
2258 if (val != -1) {
2259 temp1 = (val & 0x3f) >> 2;
2260 cs4281_write_ac97(s, BA0_AC97_3D_CONTROL, temp1);
2261 cs4281_read_ac97(s, BA0_AC97_GENERAL_PURPOSE,
2262 &temp1);
2263 cs4281_write_ac97(s, BA0_AC97_GENERAL_PURPOSE,
2264 temp1 | 0x2000);
2265 }
2266 cs4281_read_ac97(s, BA0_AC97_3D_CONTROL, &temp1);
2267 return put_user((temp1 << 2) | 3, (int __user *)argp);
2268 }
2269 if (cmd == SOUND_MIXER_INFO) {
2270 mixer_info info;
2271 strlcpy(info.id, "CS4281", sizeof(info.id));
2272 strlcpy(info.name, "Crystal CS4281", sizeof(info.name));
2273 info.modify_counter = s->mix.modcnt;
2274 if (copy_to_user(argp, &info, sizeof(info)))
2275 return -EFAULT;
2276 return 0;
2277 }
2278 if (cmd == SOUND_OLD_MIXER_INFO) {
2279 _old_mixer_info info;
2280 strlcpy(info.id, "CS4281", sizeof(info.id));
2281 strlcpy(info.name, "Crystal CS4281", sizeof(info.name));
2282 if (copy_to_user(argp, &info, sizeof(info)))
2283 return -EFAULT;
2284 return 0;
2285 }
2286 if (cmd == OSS_GETVERSION)
2287 return put_user(SOUND_VERSION, (int __user *) argp);
2288
2289 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
2290 return -EINVAL;
2291
2292 // If ioctl has only the SIOC_READ bit(bit 31)
2293 // on, process the only-read commands.
2294 if (_SIOC_DIR(cmd) == _SIOC_READ) {
2295 switch (_IOC_NR(cmd)) {
2296 case SOUND_MIXER_RECSRC: // Arg contains a bit for each recording source
2297 cs4281_read_ac97(s, BA0_AC97_RECORD_SELECT, &temp1);
2298 return put_user(mixer_src[temp1&7], (int __user *)argp);
2299
2300 case SOUND_MIXER_DEVMASK: // Arg contains a bit for each supported device
2301 return put_user(SOUND_MASK_PCM | SOUND_MASK_SYNTH |
2302 SOUND_MASK_CD | SOUND_MASK_LINE |
2303 SOUND_MASK_LINE1 | SOUND_MASK_MIC |
2304 SOUND_MASK_VOLUME |
2305 SOUND_MASK_RECLEV |
2306 SOUND_MASK_SPEAKER, (int __user *)argp);
2307
2308 case SOUND_MIXER_RECMASK: // Arg contains a bit for each supported recording source
2309 return put_user(SOUND_MASK_LINE | SOUND_MASK_MIC |
2310 SOUND_MASK_CD | SOUND_MASK_VOLUME |
2311 SOUND_MASK_LINE1, (int __user *) argp);
2312
2313 case SOUND_MIXER_STEREODEVS: // Mixer channels supporting stereo
2314 return put_user(SOUND_MASK_PCM | SOUND_MASK_SYNTH |
2315 SOUND_MASK_CD | SOUND_MASK_LINE |
2316 SOUND_MASK_LINE1 | SOUND_MASK_MIC |
2317 SOUND_MASK_VOLUME |
2318 SOUND_MASK_RECLEV, (int __user *)argp);
2319
2320 case SOUND_MIXER_CAPS:
2321 return put_user(SOUND_CAP_EXCL_INPUT, (int __user *)argp);
2322
2323 default:
2324 i = _IOC_NR(cmd);
2325 if (i >= SOUND_MIXER_NRDEVICES
2326 || !(vidx = mixtable1[i]))
2327 return -EINVAL;
2328 return put_user(s->mix.vol[vidx - 1], (int __user *)argp);
2329 }
2330 }
2331 // If ioctl doesn't have both the SIOC_READ and
2332 // the SIOC_WRITE bit set, return invalid.
2333 if (_SIOC_DIR(cmd) != (_SIOC_READ | _SIOC_WRITE))
2334 return -EINVAL;
2335
2336 // Increment the count of volume writes.
2337 s->mix.modcnt++;
2338
2339 // Isolate the command; it must be a write.
2340 switch (_IOC_NR(cmd)) {
2341
2342 case SOUND_MIXER_RECSRC: // Arg contains a bit for each recording source
2343 if (get_user(val, (int __user *)argp))
2344 return -EFAULT;
2345 i = hweight32(val); // i = # bits on in val.
2346 if (i != 1) // One & only 1 bit must be on.
2347 return 0;
2348 for (i = 0; i < sizeof(mixer_src) / sizeof(int); i++) {
2349 if (val == mixer_src[i]) {
2350 temp1 = (i << 8) | i;
2351 cs4281_write_ac97(s,
2352 BA0_AC97_RECORD_SELECT,
2353 temp1);
2354 return 0;
2355 }
2356 }
2357 return 0;
2358
2359 case SOUND_MIXER_VOLUME:
2360 if (get_user(val, (int __user *)argp))
2361 return -EFAULT;
2362 l = val & 0xff;
2363 if (l > 100)
2364 l = 100; // Max soundcard.h vol is 100.
2365 if (l < 6) {
2366 rl = 63;
2367 l = 0;
2368 } else
2369 rl = attentbl[(10 * l) / 100]; // Convert 0-100 vol to 63-0 atten.
2370
2371 r = (val >> 8) & 0xff;
2372 if (r > 100)
2373 r = 100; // Max right volume is 100, too
2374 if (r < 6) {
2375 rr = 63;
2376 r = 0;
2377 } else
2378 rr = attentbl[(10 * r) / 100]; // Convert volume to attenuation.
2379
2380 if ((rl > 60) && (rr > 60)) // If both l & r are 'low',
2381 temp1 = 0x8000; // turn on the mute bit.
2382 else
2383 temp1 = 0;
2384
2385 temp1 |= (rl << 8) | rr;
2386
2387 cs4281_write_ac97(s, BA0_AC97_MASTER_VOLUME, temp1);
2388 cs4281_write_ac97(s, BA0_AC97_HEADPHONE_VOLUME, temp1);
2389
2390#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
2391 s->mix.vol[8] = ((unsigned int) r << 8) | l;
2392#else
2393 s->mix.vol[8] = val;
2394#endif
2395 return put_user(s->mix.vol[8], (int __user *)argp);
2396
2397 case SOUND_MIXER_SPEAKER:
2398 if (get_user(val, (int __user *)argp))
2399 return -EFAULT;
2400 l = val & 0xff;
2401 if (l > 100)
2402 l = 100;
2403 if (l < 3) {
2404 rl = 0;
2405 l = 0;
2406 } else {
2407 rl = (l * 2 - 5) / 13; // Convert 0-100 range to 0-15.
2408 l = (rl * 13 + 5) / 2;
2409 }
2410
2411 if (rl < 3) {
2412 temp1 = 0x8000;
2413 rl = 0;
2414 } else
2415 temp1 = 0;
2416 rl = 15 - rl; // Convert volume to attenuation.
2417 temp1 |= rl << 1;
2418 cs4281_write_ac97(s, BA0_AC97_PC_BEEP_VOLUME, temp1);
2419
2420#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
2421 s->mix.vol[6] = l << 8;
2422#else
2423 s->mix.vol[6] = val;
2424#endif
2425 return put_user(s->mix.vol[6], (int __user *)argp);
2426
2427 case SOUND_MIXER_RECLEV:
2428 if (get_user(val, (int __user *)argp))
2429 return -EFAULT;
2430 l = val & 0xff;
2431 if (l > 100)
2432 l = 100;
2433 r = (val >> 8) & 0xff;
2434 if (r > 100)
2435 r = 100;
2436 rl = (l * 2 - 5) / 13; // Convert 0-100 scale to 0-15.
2437 rr = (r * 2 - 5) / 13;
2438 if (rl < 3 && rr < 3)
2439 temp1 = 0x8000;
2440 else
2441 temp1 = 0;
2442
2443 temp1 = temp1 | (rl << 8) | rr;
2444 cs4281_write_ac97(s, BA0_AC97_RECORD_GAIN, temp1);
2445
2446#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
2447 s->mix.vol[7] = ((unsigned int) r << 8) | l;
2448#else
2449 s->mix.vol[7] = val;
2450#endif
2451 return put_user(s->mix.vol[7], (int __user *)argp);
2452
2453 case SOUND_MIXER_MIC:
2454 if (get_user(val, (int __user *)argp))
2455 return -EFAULT;
2456 l = val & 0xff;
2457 if (l > 100)
2458 l = 100;
2459 if (l < 1) {
2460 l = 0;
2461 rl = 0;
2462 } else {
2463 rl = ((unsigned) l * 5 - 4) / 16; // Convert 0-100 range to 0-31.
2464 l = (rl * 16 + 4) / 5;
2465 }
2466 cs4281_read_ac97(s, BA0_AC97_MIC_VOLUME, &temp1);
2467 temp1 &= 0x40; // Isolate 20db gain bit.
2468 if (rl < 3) {
2469 temp1 |= 0x8000;
2470 rl = 0;
2471 }
2472 rl = 31 - rl; // Convert volume to attenuation.
2473 temp1 |= rl;
2474 cs4281_write_ac97(s, BA0_AC97_MIC_VOLUME, temp1);
2475
2476#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
2477 s->mix.vol[5] = val << 8;
2478#else
2479 s->mix.vol[5] = val;
2480#endif
2481 return put_user(s->mix.vol[5], (int __user *)argp);
2482
2483
2484 case SOUND_MIXER_SYNTH:
2485 if (get_user(val, (int __user *)argp))
2486 return -EFAULT;
2487 l = val & 0xff;
2488 if (l > 100)
2489 l = 100;
2490 if (get_user(val, (int __user *)argp))
2491 return -EFAULT;
2492 r = (val >> 8) & 0xff;
2493 if (r > 100)
2494 r = 100;
2495 rl = (l * 2 - 11) / 3; // Convert 0-100 range to 0-63.
2496 rr = (r * 2 - 11) / 3;
2497 if (rl < 3) // If l is low, turn on
2498 temp1 = 0x0080; // the mute bit.
2499 else
2500 temp1 = 0;
2501
2502 rl = 63 - rl; // Convert vol to attenuation.
2503 writel(temp1 | rl, s->pBA0 + BA0_FMLVC);
2504 if (rr < 3) // If rr is low, turn on
2505 temp1 = 0x0080; // the mute bit.
2506 else
2507 temp1 = 0;
2508 rr = 63 - rr; // Convert vol to attenuation.
2509 writel(temp1 | rr, s->pBA0 + BA0_FMRVC);
2510
2511#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
2512 s->mix.vol[4] = (r << 8) | l;
2513#else
2514 s->mix.vol[4] = val;
2515#endif
2516 return put_user(s->mix.vol[4], (int __user *)argp);
2517
2518
2519 default:
2520 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
2521 "cs4281: mixer_ioctl(): default\n"));
2522
2523 i = _IOC_NR(cmd);
2524 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i]))
2525 return -EINVAL;
2526 if (get_user(val, (int __user *)argp))
2527 return -EFAULT;
2528 l = val & 0xff;
2529 if (l > 100)
2530 l = 100;
2531 if (l < 1) {
2532 l = 0;
2533 rl = 31;
2534 } else
2535 rl = (attentbl[(l * 10) / 100]) >> 1;
2536
2537 r = (val >> 8) & 0xff;
2538 if (r > 100)
2539 r = 100;
2540 if (r < 1) {
2541 r = 0;
2542 rr = 31;
2543 } else
2544 rr = (attentbl[(r * 10) / 100]) >> 1;
2545 if ((rl > 30) && (rr > 30))
2546 temp1 = 0x8000;
2547 else
2548 temp1 = 0;
2549 temp1 = temp1 | (rl << 8) | rr;
2550 cs4281_write_ac97(s, mixreg[vidx - 1], temp1);
2551
2552#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
2553 s->mix.vol[vidx - 1] = ((unsigned int) r << 8) | l;
2554#else
2555 s->mix.vol[vidx - 1] = val;
2556#endif
2557#ifndef NOT_CS4281_PM
2558 CS_DBGOUT(CS_PM, 9, printk(KERN_INFO
2559 "write ac97 mixreg[%d]=0x%x mix.vol[]=0x%x\n",
2560 vidx-1,temp1,s->mix.vol[vidx-1]));
2561#endif
2562 return put_user(s->mix.vol[vidx - 1], (int __user *)argp);
2563 }
2564}
2565
2566
2567// ---------------------------------------------------------------------
2568
2569static int cs4281_open_mixdev(struct inode *inode, struct file *file)
2570{
2571 unsigned int minor = iminor(inode);
2572 struct cs4281_state *s=NULL;
2573 struct list_head *entry;
2574
2575 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
2576 printk(KERN_INFO "cs4281: cs4281_open_mixdev()+\n"));
2577
2578 list_for_each(entry, &cs4281_devs)
2579 {
2580 s = list_entry(entry, struct cs4281_state, list);
2581 if(s->dev_mixer == minor)
2582 break;
2583 }
2584 if (!s)
2585 {
2586 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
2587 printk(KERN_INFO "cs4281: cs4281_open_mixdev()- -ENODEV\n"));
2588 return -ENODEV;
2589 }
2590 VALIDATE_STATE(s);
2591 file->private_data = s;
2592
2593 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
2594 printk(KERN_INFO "cs4281: cs4281_open_mixdev()- 0\n"));
2595
2596 return nonseekable_open(inode, file);
2597}
2598
2599
2600static int cs4281_release_mixdev(struct inode *inode, struct file *file)
2601{
2602 struct cs4281_state *s =
2603 (struct cs4281_state *) file->private_data;
2604
2605 VALIDATE_STATE(s);
2606 return 0;
2607}
2608
2609
2610static int cs4281_ioctl_mixdev(struct inode *inode, struct file *file,
2611 unsigned int cmd, unsigned long arg)
2612{
2613 return mixer_ioctl((struct cs4281_state *) file->private_data, cmd,
2614 arg);
2615}
2616
2617
2618// ******************************************************************************************
2619// Mixer file operations struct.
2620// ******************************************************************************************
2621static /*const */ struct file_operations cs4281_mixer_fops = {
2622 .owner = THIS_MODULE,
2623 .llseek = no_llseek,
2624 .ioctl = cs4281_ioctl_mixdev,
2625 .open = cs4281_open_mixdev,
2626 .release = cs4281_release_mixdev,
2627};
2628
2629// ---------------------------------------------------------------------
2630
2631
2632static int drain_adc(struct cs4281_state *s, int nonblock)
2633{
2634 DECLARE_WAITQUEUE(wait, current);
2635 unsigned long flags;
2636 int count;
2637 unsigned tmo;
2638
2639 if (s->dma_adc.mapped)
2640 return 0;
2641 add_wait_queue(&s->dma_adc.wait, &wait);
2642 for (;;) {
2643 set_current_state(TASK_INTERRUPTIBLE);
2644 spin_lock_irqsave(&s->lock, flags);
2645 count = s->dma_adc.count;
2646 CS_DBGOUT(CS_FUNCTION, 2,
2647 printk(KERN_INFO "cs4281: drain_adc() %d\n", count));
2648 spin_unlock_irqrestore(&s->lock, flags);
2649 if (count <= 0) {
2650 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO
2651 "cs4281: drain_adc() count<0\n"));
2652 break;
2653 }
2654 if (signal_pending(current))
2655 break;
2656 if (nonblock) {
2657 remove_wait_queue(&s->dma_adc.wait, &wait);
2658 current->state = TASK_RUNNING;
2659 return -EBUSY;
2660 }
2661 tmo =
2662 3 * HZ * (count +
2663 s->dma_adc.fragsize) / 2 / s->prop_adc.rate;
2664 if (s->prop_adc.fmt & (AFMT_S16_LE | AFMT_U16_LE))
2665 tmo >>= 1;
2666 if (s->prop_adc.channels > 1)
2667 tmo >>= 1;
2668 if (!schedule_timeout(tmo + 1))
2669 printk(KERN_DEBUG "cs4281: dma timed out??\n");
2670 }
2671 remove_wait_queue(&s->dma_adc.wait, &wait);
2672 current->state = TASK_RUNNING;
2673 if (signal_pending(current))
2674 return -ERESTARTSYS;
2675 return 0;
2676}
2677
2678static int drain_dac(struct cs4281_state *s, int nonblock)
2679{
2680 DECLARE_WAITQUEUE(wait, current);
2681 unsigned long flags;
2682 int count;
2683 unsigned tmo;
2684
2685 if (s->dma_dac.mapped)
2686 return 0;
2687 add_wait_queue(&s->dma_dac.wait, &wait);
2688 for (;;) {
2689 set_current_state(TASK_INTERRUPTIBLE);
2690 spin_lock_irqsave(&s->lock, flags);
2691 count = s->dma_dac.count;
2692 spin_unlock_irqrestore(&s->lock, flags);
2693 if (count <= 0)
2694 break;
2695 if (signal_pending(current))
2696 break;
2697 if (nonblock) {
2698 remove_wait_queue(&s->dma_dac.wait, &wait);
2699 current->state = TASK_RUNNING;
2700 return -EBUSY;
2701 }
2702 tmo =
2703 3 * HZ * (count +
2704 s->dma_dac.fragsize) / 2 / s->prop_dac.rate;
2705 if (s->prop_dac.fmt & (AFMT_S16_LE | AFMT_U16_LE))
2706 tmo >>= 1;
2707 if (s->prop_dac.channels > 1)
2708 tmo >>= 1;
2709 if (!schedule_timeout(tmo + 1))
2710 printk(KERN_DEBUG "cs4281: dma timed out??\n");
2711 }
2712 remove_wait_queue(&s->dma_dac.wait, &wait);
2713 current->state = TASK_RUNNING;
2714 if (signal_pending(current))
2715 return -ERESTARTSYS;
2716 return 0;
2717}
2718
2719//****************************************************************************
2720//
2721// CopySamples copies 16-bit stereo samples from the source to the
2722// destination, possibly converting down to either 8-bit or mono or both.
2723// count specifies the number of output bytes to write.
2724//
2725// Arguments:
2726//
2727// dst - Pointer to a destination buffer.
2728// src - Pointer to a source buffer
2729// count - The number of bytes to copy into the destination buffer.
2730// iChannels - Stereo - 2
2731// Mono - 1
2732// fmt - AFMT_xxx (soundcard.h formats)
2733//
2734// NOTES: only call this routine for conversion to 8bit from 16bit
2735//
2736//****************************************************************************
2737static void CopySamples(char *dst, char *src, int count, int iChannels,
2738 unsigned fmt)
2739{
2740
2741 unsigned short *psSrc;
2742 long lAudioSample;
2743
2744 CS_DBGOUT(CS_FUNCTION, 2,
2745 printk(KERN_INFO "cs4281: CopySamples()+ "));
2746 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
2747 " dst=%p src=%p count=%d iChannels=%d fmt=0x%x\n",
2748 dst, src, (unsigned) count, (unsigned) iChannels, (unsigned) fmt));
2749
2750 // Gershwin does format conversion in hardware so normally
2751 // we don't do any host based coversion. The data formatter
2752 // truncates 16 bit data to 8 bit and that causes some hiss.
2753 // We have already forced the HW to do 16 bit sampling and
2754 // 2 channel so that we can use software to round instead
2755 // of truncate
2756
2757 //
2758 // See if the data should be output as 8-bit unsigned stereo.
2759 // or if the data should be output at 8-bit unsigned mono.
2760 //
2761 if ( ((iChannels == 2) && (fmt & AFMT_U8)) ||
2762 ((iChannels == 1) && (fmt & AFMT_U8)) ) {
2763 //
2764 // Convert each 16-bit unsigned stereo sample to 8-bit unsigned
2765 // stereo using rounding.
2766 //
2767 psSrc = (unsigned short *) src;
2768 count = count / 2;
2769 while (count--) {
2770 lAudioSample = (long) psSrc[count] + (long) 0x80;
2771 if (lAudioSample > 0xffff) {
2772 lAudioSample = 0xffff;
2773 }
2774 dst[count] = (char) (lAudioSample >> 8);
2775 }
2776 }
2777 //
2778 // check for 8-bit signed stereo.
2779 //
2780 else if ((iChannels == 2) && (fmt & AFMT_S8)) {
2781 //
2782 // Convert each 16-bit stereo sample to 8-bit stereo using rounding.
2783 //
2784 psSrc = (short *) src;
2785 while (count--) {
2786 lAudioSample =
2787 (((long) psSrc[0] + (long) psSrc[1]) / 2);
2788 psSrc += 2;
2789 *dst++ = (char) ((short) lAudioSample >> 8);
2790 }
2791 }
2792 //
2793 // Otherwise, the data should be output as 8-bit signed mono.
2794 //
2795 else if ((iChannels == 1) && (fmt & AFMT_S8)) {
2796 //
2797 // Convert each 16-bit signed mono sample to 8-bit signed mono
2798 // using rounding.
2799 //
2800 psSrc = (short *) src;
2801 count = count / 2;
2802 while (count--) {
2803 lAudioSample =
2804 (((long) psSrc[0] + (long) psSrc[1]) / 2);
2805 if (lAudioSample > 0x7fff) {
2806 lAudioSample = 0x7fff;
2807 }
2808 psSrc += 2;
2809 *dst++ = (char) ((short) lAudioSample >> 8);
2810 }
2811 }
2812}
2813
2814//
2815// cs_copy_to_user()
2816// replacement for the standard copy_to_user, to allow for a conversion from
2817// 16 bit to 8 bit if the record conversion is active. the cs4281 has some
2818// issues with 8 bit capture, so the driver always captures data in 16 bit
2819// and then if the user requested 8 bit, converts from 16 to 8 bit.
2820//
2821static unsigned cs_copy_to_user(struct cs4281_state *s, void __user *dest,
2822 unsigned *hwsrc, unsigned cnt,
2823 unsigned *copied)
2824{
2825 void *src = hwsrc; //default to the standard destination buffer addr
2826
2827 CS_DBGOUT(CS_FUNCTION, 6, printk(KERN_INFO
2828 "cs_copy_to_user()+ fmt=0x%x fmt_o=0x%x cnt=%d dest=%p\n",
2829 s->prop_adc.fmt, s->prop_adc.fmt_original,
2830 (unsigned) cnt, dest));
2831
2832 if (cnt > s->dma_adc.dmasize) {
2833 cnt = s->dma_adc.dmasize;
2834 }
2835 if (!cnt) {
2836 *copied = 0;
2837 return 0;
2838 }
2839 if (s->conversion) {
2840 if (!s->tmpbuff) {
2841 *copied = cnt / 2;
2842 return 0;
2843 }
2844 CopySamples(s->tmpbuff, (void *) hwsrc, cnt,
2845 (unsigned) s->prop_adc.channels,
2846 s->prop_adc.fmt_original);
2847 src = s->tmpbuff;
2848 cnt = cnt / 2;
2849 }
2850
2851 if (copy_to_user(dest, src, cnt)) {
2852 *copied = 0;
2853 return -EFAULT;
2854 }
2855 *copied = cnt;
2856 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO
2857 "cs4281: cs_copy_to_user()- copied bytes is %d \n", cnt));
2858 return 0;
2859}
2860
2861// ---------------------------------------------------------------------
2862
2863static ssize_t cs4281_read(struct file *file, char __user *buffer, size_t count,
2864 loff_t * ppos)
2865{
2866 struct cs4281_state *s =
2867 (struct cs4281_state *) file->private_data;
2868 ssize_t ret;
2869 unsigned long flags;
2870 unsigned swptr;
2871 int cnt;
2872 unsigned copied = 0;
2873
2874 CS_DBGOUT(CS_FUNCTION | CS_WAVE_READ, 2,
2875 printk(KERN_INFO "cs4281: cs4281_read()+ %Zu \n", count));
2876
2877 VALIDATE_STATE(s);
2878 if (s->dma_adc.mapped)
2879 return -ENXIO;
2880 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
2881 return ret;
2882 if (!access_ok(VERIFY_WRITE, buffer, count))
2883 return -EFAULT;
2884 ret = 0;
2885//
2886// "count" is the amount of bytes to read (from app), is decremented each loop
2887// by the amount of bytes that have been returned to the user buffer.
2888// "cnt" is the running total of each read from the buffer (changes each loop)
2889// "buffer" points to the app's buffer
2890// "ret" keeps a running total of the amount of bytes that have been copied
2891// to the user buffer.
2892// "copied" is the total bytes copied into the user buffer for each loop.
2893//
2894 while (count > 0) {
2895 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
2896 "_read() count>0 count=%Zu .count=%d .swptr=%d .hwptr=%d \n",
2897 count, s->dma_adc.count,
2898 s->dma_adc.swptr, s->dma_adc.hwptr));
2899 spin_lock_irqsave(&s->lock, flags);
2900
2901 // get the current copy point of the sw buffer
2902 swptr = s->dma_adc.swptr;
2903
2904 // cnt is the amount of unread bytes from the end of the
2905 // hw buffer to the current sw pointer
2906 cnt = s->dma_adc.dmasize - swptr;
2907
2908 // dma_adc.count is the current total bytes that have not been read.
2909 // if the amount of unread bytes from the current sw pointer to the
2910 // end of the buffer is greater than the current total bytes that
2911 // have not been read, then set the "cnt" (unread bytes) to the
2912 // amount of unread bytes.
2913
2914 if (s->dma_adc.count < cnt)
2915 cnt = s->dma_adc.count;
2916 spin_unlock_irqrestore(&s->lock, flags);
2917 //
2918 // if we are converting from 8/16 then we need to copy
2919 // twice the number of 16 bit bytes then 8 bit bytes.
2920 //
2921 if (s->conversion) {
2922 if (cnt > (count * 2))
2923 cnt = (count * 2);
2924 } else {
2925 if (cnt > count)
2926 cnt = count;
2927 }
2928 //
2929 // "cnt" NOW is the smaller of the amount that will be read,
2930 // and the amount that is requested in this read (or partial).
2931 // if there are no bytes in the buffer to read, then start the
2932 // ADC and wait for the interrupt handler to wake us up.
2933 //
2934 if (cnt <= 0) {
2935
2936 // start up the dma engine and then continue back to the top of
2937 // the loop when wake up occurs.
2938 start_adc(s);
2939 if (file->f_flags & O_NONBLOCK)
2940 return ret ? ret : -EAGAIN;
2941 interruptible_sleep_on(&s->dma_adc.wait);
2942 if (signal_pending(current))
2943 return ret ? ret : -ERESTARTSYS;
2944 continue;
2945 }
2946 // there are bytes in the buffer to read.
2947 // copy from the hw buffer over to the user buffer.
2948 // user buffer is designated by "buffer"
2949 // virtual address to copy from is rawbuf+swptr
2950 // the "cnt" is the number of bytes to read.
2951
2952 CS_DBGOUT(CS_WAVE_READ, 2, printk(KERN_INFO
2953 "_read() copy_to cnt=%d count=%Zu ", cnt, count));
2954 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
2955 " .dmasize=%d .count=%d buffer=%p ret=%Zd\n",
2956 s->dma_adc.dmasize, s->dma_adc.count, buffer, ret));
2957
2958 if (cs_copy_to_user
2959 (s, buffer, s->dma_adc.rawbuf + swptr, cnt, &copied))
2960 return ret ? ret : -EFAULT;
2961 swptr = (swptr + cnt) % s->dma_adc.dmasize;
2962 spin_lock_irqsave(&s->lock, flags);
2963 s->dma_adc.swptr = swptr;
2964 s->dma_adc.count -= cnt;
2965 spin_unlock_irqrestore(&s->lock, flags);
2966 count -= copied;
2967 buffer += copied;
2968 ret += copied;
2969 start_adc(s);
2970 }
2971 CS_DBGOUT(CS_FUNCTION | CS_WAVE_READ, 2,
2972 printk(KERN_INFO "cs4281: cs4281_read()- %Zd\n", ret));
2973 return ret;
2974}
2975
2976
2977static ssize_t cs4281_write(struct file *file, const char __user *buffer,
2978 size_t count, loff_t * ppos)
2979{
2980 struct cs4281_state *s =
2981 (struct cs4281_state *) file->private_data;
2982 ssize_t ret;
2983 unsigned long flags;
2984 unsigned swptr, hwptr, busaddr;
2985 int cnt;
2986
2987 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE, 2,
2988 printk(KERN_INFO "cs4281: cs4281_write()+ count=%Zu\n",
2989 count));
2990 VALIDATE_STATE(s);
2991
2992 if (s->dma_dac.mapped)
2993 return -ENXIO;
2994 if (!s->dma_dac.ready && (ret = prog_dmabuf_dac(s)))
2995 return ret;
2996 if (!access_ok(VERIFY_READ, buffer, count))
2997 return -EFAULT;
2998 ret = 0;
2999 while (count > 0) {
3000 spin_lock_irqsave(&s->lock, flags);
3001 if (s->dma_dac.count < 0) {
3002 s->dma_dac.count = 0;
3003 s->dma_dac.swptr = s->dma_dac.hwptr;
3004 }
3005 if (s->dma_dac.underrun) {
3006 s->dma_dac.underrun = 0;
3007 hwptr = readl(s->pBA0 + BA0_DCA0);
3008 busaddr = virt_to_bus(s->dma_dac.rawbuf);
3009 hwptr -= (unsigned) busaddr;
3010 s->dma_dac.swptr = s->dma_dac.hwptr = hwptr;
3011 }
3012 swptr = s->dma_dac.swptr;
3013 cnt = s->dma_dac.dmasize - swptr;
3014 if (s->dma_dac.count + cnt > s->dma_dac.dmasize)
3015 cnt = s->dma_dac.dmasize - s->dma_dac.count;
3016 spin_unlock_irqrestore(&s->lock, flags);
3017 if (cnt > count)
3018 cnt = count;
3019 if (cnt <= 0) {
3020 start_dac(s);
3021 if (file->f_flags & O_NONBLOCK)
3022 return ret ? ret : -EAGAIN;
3023 interruptible_sleep_on(&s->dma_dac.wait);
3024 if (signal_pending(current))
3025 return ret ? ret : -ERESTARTSYS;
3026 continue;
3027 }
3028 if (copy_from_user(s->dma_dac.rawbuf + swptr, buffer, cnt))
3029 return ret ? ret : -EFAULT;
3030 swptr = (swptr + cnt) % s->dma_dac.dmasize;
3031 spin_lock_irqsave(&s->lock, flags);
3032 s->dma_dac.swptr = swptr;
3033 s->dma_dac.count += cnt;
3034 s->dma_dac.endcleared = 0;
3035 spin_unlock_irqrestore(&s->lock, flags);
3036 count -= cnt;
3037 buffer += cnt;
3038 ret += cnt;
3039 start_dac(s);
3040 }
3041 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE, 2,
3042 printk(KERN_INFO "cs4281: cs4281_write()- %Zd\n", ret));
3043 return ret;
3044}
3045
3046
3047static unsigned int cs4281_poll(struct file *file,
3048 struct poll_table_struct *wait)
3049{
3050 struct cs4281_state *s =
3051 (struct cs4281_state *) file->private_data;
3052 unsigned long flags;
3053 unsigned int mask = 0;
3054
3055 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
3056 printk(KERN_INFO "cs4281: cs4281_poll()+\n"));
3057 VALIDATE_STATE(s);
3058 if (file->f_mode & FMODE_WRITE) {
3059 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
3060 printk(KERN_INFO
3061 "cs4281: cs4281_poll() wait on FMODE_WRITE\n"));
3062 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
3063 return 0;
3064 poll_wait(file, &s->dma_dac.wait, wait);
3065 }
3066 if (file->f_mode & FMODE_READ) {
3067 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
3068 printk(KERN_INFO
3069 "cs4281: cs4281_poll() wait on FMODE_READ\n"));
3070 if(!s->dma_dac.ready && prog_dmabuf_adc(s))
3071 return 0;
3072 poll_wait(file, &s->dma_adc.wait, wait);
3073 }
3074 spin_lock_irqsave(&s->lock, flags);
3075 cs4281_update_ptr(s,CS_FALSE);
3076 if (file->f_mode & FMODE_WRITE) {
3077 if (s->dma_dac.mapped) {
3078 if (s->dma_dac.count >=
3079 (signed) s->dma_dac.fragsize) {
3080 if (s->dma_dac.wakeup)
3081 mask |= POLLOUT | POLLWRNORM;
3082 else
3083 mask = 0;
3084 s->dma_dac.wakeup = 0;
3085 }
3086 } else {
3087 if ((signed) (s->dma_dac.dmasize/2) >= s->dma_dac.count)
3088 mask |= POLLOUT | POLLWRNORM;
3089 }
3090 } else if (file->f_mode & FMODE_READ) {
3091 if (s->dma_adc.mapped) {
3092 if (s->dma_adc.count >= (signed) s->dma_adc.fragsize)
3093 mask |= POLLIN | POLLRDNORM;
3094 } else {
3095 if (s->dma_adc.count > 0)
3096 mask |= POLLIN | POLLRDNORM;
3097 }
3098 }
3099 spin_unlock_irqrestore(&s->lock, flags);
3100 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
3101 printk(KERN_INFO "cs4281: cs4281_poll()- 0x%.8x\n",
3102 mask));
3103 return mask;
3104}
3105
3106
3107static int cs4281_mmap(struct file *file, struct vm_area_struct *vma)
3108{
3109 struct cs4281_state *s =
3110 (struct cs4281_state *) file->private_data;
3111 struct dmabuf *db;
3112 int ret;
3113 unsigned long size;
3114
3115 CS_DBGOUT(CS_FUNCTION | CS_PARMS | CS_OPEN, 4,
3116 printk(KERN_INFO "cs4281: cs4281_mmap()+\n"));
3117
3118 VALIDATE_STATE(s);
3119 if (vma->vm_flags & VM_WRITE) {
3120 if ((ret = prog_dmabuf_dac(s)) != 0)
3121 return ret;
3122 db = &s->dma_dac;
3123 } else if (vma->vm_flags & VM_READ) {
3124 if ((ret = prog_dmabuf_adc(s)) != 0)
3125 return ret;
3126 db = &s->dma_adc;
3127 } else
3128 return -EINVAL;
3129//
3130// only support PLAYBACK for now
3131//
3132 db = &s->dma_dac;
3133
3134 if (cs4x_pgoff(vma) != 0)
3135 return -EINVAL;
3136 size = vma->vm_end - vma->vm_start;
3137 if (size > (PAGE_SIZE << db->buforder))
3138 return -EINVAL;
3139 if (remap_pfn_range(vma, vma->vm_start,
3140 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
3141 size, vma->vm_page_prot))
3142 return -EAGAIN;
3143 db->mapped = 1;
3144
3145 CS_DBGOUT(CS_FUNCTION | CS_PARMS | CS_OPEN, 4,
3146 printk(KERN_INFO "cs4281: cs4281_mmap()- 0 size=%d\n",
3147 (unsigned) size));
3148
3149 return 0;
3150}
3151
3152
3153static int cs4281_ioctl(struct inode *inode, struct file *file,
3154 unsigned int cmd, unsigned long arg)
3155{
3156 struct cs4281_state *s =
3157 (struct cs4281_state *) file->private_data;
3158 unsigned long flags;
3159 audio_buf_info abinfo;
3160 count_info cinfo;
3161 int val, mapped, ret;
3162 int __user *p = (int __user *)arg;
3163
3164 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
3165 "cs4281: cs4281_ioctl(): file=%p cmd=0x%.8x\n", file, cmd));
3166#if CSDEBUG
3167 cs_printioctl(cmd);
3168#endif
3169 VALIDATE_STATE(s);
3170 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
3171 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
3172 switch (cmd) {
3173 case OSS_GETVERSION:
3174 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
3175 "cs4281: cs4281_ioctl(): SOUND_VERSION=0x%.8x\n",
3176 SOUND_VERSION));
3177 return put_user(SOUND_VERSION, p);
3178
3179 case SNDCTL_DSP_SYNC:
3180 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
3181 "cs4281: cs4281_ioctl(): DSP_SYNC\n"));
3182 if (file->f_mode & FMODE_WRITE)
3183 return drain_dac(s,
3184 0 /*file->f_flags & O_NONBLOCK */
3185 );
3186 return 0;
3187
3188 case SNDCTL_DSP_SETDUPLEX:
3189 return 0;
3190
3191 case SNDCTL_DSP_GETCAPS:
3192 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
3193 DSP_CAP_TRIGGER | DSP_CAP_MMAP,
3194 p);
3195
3196 case SNDCTL_DSP_RESET:
3197 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
3198 "cs4281: cs4281_ioctl(): DSP_RESET\n"));
3199 if (file->f_mode & FMODE_WRITE) {
3200 stop_dac(s);
3201 synchronize_irq(s->irq);
3202 s->dma_dac.swptr = s->dma_dac.hwptr =
3203 s->dma_dac.count = s->dma_dac.total_bytes =
3204 s->dma_dac.blocks = s->dma_dac.wakeup = 0;
3205 prog_codec(s, CS_TYPE_DAC);
3206 }
3207 if (file->f_mode & FMODE_READ) {
3208 stop_adc(s);
3209 synchronize_irq(s->irq);
3210 s->dma_adc.swptr = s->dma_adc.hwptr =
3211 s->dma_adc.count = s->dma_adc.total_bytes =
3212 s->dma_adc.blocks = s->dma_dac.wakeup = 0;
3213 prog_codec(s, CS_TYPE_ADC);
3214 }
3215 return 0;
3216
3217 case SNDCTL_DSP_SPEED:
3218 if (get_user(val, p))
3219 return -EFAULT;
3220 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
3221 "cs4281: cs4281_ioctl(): DSP_SPEED val=%d\n", val));
3222 //
3223 // support independent capture and playback channels
3224 // assume that the file mode bit determines the
3225 // direction of the data flow.
3226 //
3227 if (file->f_mode & FMODE_READ) {
3228 if (val >= 0) {
3229 stop_adc(s);
3230 s->dma_adc.ready = 0;
3231 // program sampling rates
3232 if (val > 48000)
3233 val = 48000;
3234 if (val < 6300)
3235 val = 6300;
3236 s->prop_adc.rate = val;
3237 prog_codec(s, CS_TYPE_ADC);
3238 }
3239 }
3240 if (file->f_mode & FMODE_WRITE) {
3241 if (val >= 0) {
3242 stop_dac(s);
3243 s->dma_dac.ready = 0;
3244 // program sampling rates
3245 if (val > 48000)
3246 val = 48000;
3247 if (val < 6300)
3248 val = 6300;
3249 s->prop_dac.rate = val;
3250 prog_codec(s, CS_TYPE_DAC);
3251 }
3252 }
3253
3254 if (file->f_mode & FMODE_WRITE)
3255 val = s->prop_dac.rate;
3256 else if (file->f_mode & FMODE_READ)
3257 val = s->prop_adc.rate;
3258
3259 return put_user(val, p);
3260
3261 case SNDCTL_DSP_STEREO:
3262 if (get_user(val, p))
3263 return -EFAULT;
3264 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
3265 "cs4281: cs4281_ioctl(): DSP_STEREO val=%d\n", val));
3266 if (file->f_mode & FMODE_READ) {
3267 stop_adc(s);
3268 s->dma_adc.ready = 0;
3269 s->prop_adc.channels = val ? 2 : 1;
3270 prog_codec(s, CS_TYPE_ADC);
3271 }
3272 if (file->f_mode & FMODE_WRITE) {
3273 stop_dac(s);
3274 s->dma_dac.ready = 0;
3275 s->prop_dac.channels = val ? 2 : 1;
3276 prog_codec(s, CS_TYPE_DAC);
3277 }
3278 return 0;
3279
3280 case SNDCTL_DSP_CHANNELS:
3281 if (get_user(val, p))
3282 return -EFAULT;
3283 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
3284 "cs4281: cs4281_ioctl(): DSP_CHANNELS val=%d\n",
3285 val));
3286 if (val != 0) {
3287 if (file->f_mode & FMODE_READ) {
3288 stop_adc(s);
3289 s->dma_adc.ready = 0;
3290 if (val >= 2)
3291 s->prop_adc.channels = 2;
3292 else
3293 s->prop_adc.channels = 1;
3294 prog_codec(s, CS_TYPE_ADC);
3295 }
3296 if (file->f_mode & FMODE_WRITE) {
3297 stop_dac(s);
3298 s->dma_dac.ready = 0;
3299 if (val >= 2)
3300 s->prop_dac.channels = 2;
3301 else
3302 s->prop_dac.channels = 1;
3303 prog_codec(s, CS_TYPE_DAC);
3304 }
3305 }
3306
3307 if (file->f_mode & FMODE_WRITE)
3308 val = s->prop_dac.channels;
3309 else if (file->f_mode & FMODE_READ)
3310 val = s->prop_adc.channels;
3311
3312 return put_user(val, p);
3313
3314 case SNDCTL_DSP_GETFMTS: // Returns a mask
3315 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
3316 "cs4281: cs4281_ioctl(): DSP_GETFMT val=0x%.8x\n",
3317 AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
3318 AFMT_U8));
3319 return put_user(AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
3320 AFMT_U8, p);
3321
3322 case SNDCTL_DSP_SETFMT:
3323 if (get_user(val, p))
3324 return -EFAULT;
3325 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
3326 "cs4281: cs4281_ioctl(): DSP_SETFMT val=0x%.8x\n",
3327 val));
3328 if (val != AFMT_QUERY) {
3329 if (file->f_mode & FMODE_READ) {
3330 stop_adc(s);
3331 s->dma_adc.ready = 0;
3332 if (val != AFMT_S16_LE
3333 && val != AFMT_U16_LE && val != AFMT_S8
3334 && val != AFMT_U8)
3335 val = AFMT_U8;
3336 s->prop_adc.fmt = val;
3337 s->prop_adc.fmt_original = s->prop_adc.fmt;
3338 prog_codec(s, CS_TYPE_ADC);
3339 }
3340 if (file->f_mode & FMODE_WRITE) {
3341 stop_dac(s);
3342 s->dma_dac.ready = 0;
3343 if (val != AFMT_S16_LE
3344 && val != AFMT_U16_LE && val != AFMT_S8
3345 && val != AFMT_U8)
3346 val = AFMT_U8;
3347 s->prop_dac.fmt = val;
3348 s->prop_dac.fmt_original = s->prop_dac.fmt;
3349 prog_codec(s, CS_TYPE_DAC);
3350 }
3351 } else {
3352 if (file->f_mode & FMODE_WRITE)
3353 val = s->prop_dac.fmt_original;
3354 else if (file->f_mode & FMODE_READ)
3355 val = s->prop_adc.fmt_original;
3356 }
3357 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
3358 "cs4281: cs4281_ioctl(): DSP_SETFMT return val=0x%.8x\n",
3359 val));
3360 return put_user(val, p);
3361
3362 case SNDCTL_DSP_POST:
3363 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
3364 "cs4281: cs4281_ioctl(): DSP_POST\n"));
3365 return 0;
3366
3367 case SNDCTL_DSP_GETTRIGGER:
3368 val = 0;
3369 if (file->f_mode & s->ena & FMODE_READ)
3370 val |= PCM_ENABLE_INPUT;
3371 if (file->f_mode & s->ena & FMODE_WRITE)
3372 val |= PCM_ENABLE_OUTPUT;
3373 return put_user(val, p);
3374
3375 case SNDCTL_DSP_SETTRIGGER:
3376 if (get_user(val, p))
3377 return -EFAULT;
3378 if (file->f_mode & FMODE_READ) {
3379 if (val & PCM_ENABLE_INPUT) {
3380 if (!s->dma_adc.ready
3381 && (ret = prog_dmabuf_adc(s)))
3382 return ret;
3383 start_adc(s);
3384 } else
3385 stop_adc(s);
3386 }
3387 if (file->f_mode & FMODE_WRITE) {
3388 if (val & PCM_ENABLE_OUTPUT) {
3389 if (!s->dma_dac.ready
3390 && (ret = prog_dmabuf_dac(s)))
3391 return ret;
3392 start_dac(s);
3393 } else
3394 stop_dac(s);
3395 }
3396 return 0;
3397
3398 case SNDCTL_DSP_GETOSPACE:
3399 if (!(file->f_mode & FMODE_WRITE))
3400 return -EINVAL;
3401 if (!s->dma_dac.ready && (val = prog_dmabuf_dac(s)))
3402 return val;
3403 spin_lock_irqsave(&s->lock, flags);
3404 cs4281_update_ptr(s,CS_FALSE);
3405 abinfo.fragsize = s->dma_dac.fragsize;
3406 if (s->dma_dac.mapped)
3407 abinfo.bytes = s->dma_dac.dmasize;
3408 else
3409 abinfo.bytes =
3410 s->dma_dac.dmasize - s->dma_dac.count;
3411 abinfo.fragstotal = s->dma_dac.numfrag;
3412 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
3413 CS_DBGOUT(CS_FUNCTION | CS_PARMS, 4, printk(KERN_INFO
3414 "cs4281: cs4281_ioctl(): GETOSPACE .fragsize=%d .bytes=%d .fragstotal=%d .fragments=%d\n",
3415 abinfo.fragsize,abinfo.bytes,abinfo.fragstotal,
3416 abinfo.fragments));
3417 spin_unlock_irqrestore(&s->lock, flags);
3418 return copy_to_user(p, &abinfo,
3419 sizeof(abinfo)) ? -EFAULT : 0;
3420
3421 case SNDCTL_DSP_GETISPACE:
3422 if (!(file->f_mode & FMODE_READ))
3423 return -EINVAL;
3424 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)))
3425 return val;
3426 spin_lock_irqsave(&s->lock, flags);
3427 cs4281_update_ptr(s,CS_FALSE);
3428 if (s->conversion) {
3429 abinfo.fragsize = s->dma_adc.fragsize / 2;
3430 abinfo.bytes = s->dma_adc.count / 2;
3431 abinfo.fragstotal = s->dma_adc.numfrag;
3432 abinfo.fragments =
3433 abinfo.bytes >> (s->dma_adc.fragshift - 1);
3434 } else {
3435 abinfo.fragsize = s->dma_adc.fragsize;
3436 abinfo.bytes = s->dma_adc.count;
3437 abinfo.fragstotal = s->dma_adc.numfrag;
3438 abinfo.fragments =
3439 abinfo.bytes >> s->dma_adc.fragshift;
3440 }
3441 spin_unlock_irqrestore(&s->lock, flags);
3442 return copy_to_user(p, &abinfo,
3443 sizeof(abinfo)) ? -EFAULT : 0;
3444
3445 case SNDCTL_DSP_NONBLOCK:
3446 file->f_flags |= O_NONBLOCK;
3447 return 0;
3448
3449 case SNDCTL_DSP_GETODELAY:
3450 if (!(file->f_mode & FMODE_WRITE))
3451 return -EINVAL;
3452 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
3453 return 0;
3454 spin_lock_irqsave(&s->lock, flags);
3455 cs4281_update_ptr(s,CS_FALSE);
3456 val = s->dma_dac.count;
3457 spin_unlock_irqrestore(&s->lock, flags);
3458 return put_user(val, p);
3459
3460 case SNDCTL_DSP_GETIPTR:
3461 if (!(file->f_mode & FMODE_READ))
3462 return -EINVAL;
3463 if(!s->dma_adc.ready && prog_dmabuf_adc(s))
3464 return 0;
3465 spin_lock_irqsave(&s->lock, flags);
3466 cs4281_update_ptr(s,CS_FALSE);
3467 cinfo.bytes = s->dma_adc.total_bytes;
3468 if (s->dma_adc.mapped) {
3469 cinfo.blocks =
3470 (cinfo.bytes >> s->dma_adc.fragshift) -
3471 s->dma_adc.blocks;
3472 s->dma_adc.blocks =
3473 cinfo.bytes >> s->dma_adc.fragshift;
3474 } else {
3475 if (s->conversion) {
3476 cinfo.blocks =
3477 s->dma_adc.count /
3478 2 >> (s->dma_adc.fragshift - 1);
3479 } else
3480 cinfo.blocks =
3481 s->dma_adc.count >> s->dma_adc.
3482 fragshift;
3483 }
3484 if (s->conversion)
3485 cinfo.ptr = s->dma_adc.hwptr / 2;
3486 else
3487 cinfo.ptr = s->dma_adc.hwptr;
3488 if (s->dma_adc.mapped)
3489 s->dma_adc.count &= s->dma_adc.fragsize - 1;
3490 spin_unlock_irqrestore(&s->lock, flags);
3491 if (copy_to_user(p, &cinfo, sizeof(cinfo)))
3492 return -EFAULT;
3493 return 0;
3494
3495 case SNDCTL_DSP_GETOPTR:
3496 if (!(file->f_mode & FMODE_WRITE))
3497 return -EINVAL;
3498 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
3499 return 0;
3500 spin_lock_irqsave(&s->lock, flags);
3501 cs4281_update_ptr(s,CS_FALSE);
3502 cinfo.bytes = s->dma_dac.total_bytes;
3503 if (s->dma_dac.mapped) {
3504 cinfo.blocks =
3505 (cinfo.bytes >> s->dma_dac.fragshift) -
3506 s->dma_dac.blocks;
3507 s->dma_dac.blocks =
3508 cinfo.bytes >> s->dma_dac.fragshift;
3509 } else {
3510 cinfo.blocks =
3511 s->dma_dac.count >> s->dma_dac.fragshift;
3512 }
3513 cinfo.ptr = s->dma_dac.hwptr;
3514 if (s->dma_dac.mapped)
3515 s->dma_dac.count &= s->dma_dac.fragsize - 1;
3516 spin_unlock_irqrestore(&s->lock, flags);
3517 if (copy_to_user(p, &cinfo, sizeof(cinfo)))
3518 return -EFAULT;
3519 return 0;
3520
3521 case SNDCTL_DSP_GETBLKSIZE:
3522 if (file->f_mode & FMODE_WRITE) {
3523 if ((val = prog_dmabuf_dac(s)))
3524 return val;
3525 return put_user(s->dma_dac.fragsize, p);
3526 }
3527 if ((val = prog_dmabuf_adc(s)))
3528 return val;
3529 if (s->conversion)
3530 return put_user(s->dma_adc.fragsize / 2, p);
3531 else
3532 return put_user(s->dma_adc.fragsize, p);
3533
3534 case SNDCTL_DSP_SETFRAGMENT:
3535 if (get_user(val, p))
3536 return -EFAULT;
3537 return 0; // Say OK, but do nothing.
3538
3539 case SNDCTL_DSP_SUBDIVIDE:
3540 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision)
3541 || (file->f_mode & FMODE_WRITE
3542 && s->dma_dac.subdivision)) return -EINVAL;
3543 if (get_user(val, p))
3544 return -EFAULT;
3545 if (val != 1 && val != 2 && val != 4)
3546 return -EINVAL;
3547 if (file->f_mode & FMODE_READ)
3548 s->dma_adc.subdivision = val;
3549 else if (file->f_mode & FMODE_WRITE)
3550 s->dma_dac.subdivision = val;
3551 return 0;
3552
3553 case SOUND_PCM_READ_RATE:
3554 if (file->f_mode & FMODE_READ)
3555 return put_user(s->prop_adc.rate, p);
3556 else if (file->f_mode & FMODE_WRITE)
3557 return put_user(s->prop_dac.rate, p);
3558
3559 case SOUND_PCM_READ_CHANNELS:
3560 if (file->f_mode & FMODE_READ)
3561 return put_user(s->prop_adc.channels, p);
3562 else if (file->f_mode & FMODE_WRITE)
3563 return put_user(s->prop_dac.channels, p);
3564
3565 case SOUND_PCM_READ_BITS:
3566 if (file->f_mode & FMODE_READ)
3567 return
3568 put_user(
3569 (s->prop_adc.
3570 fmt & (AFMT_S8 | AFMT_U8)) ? 8 : 16,
3571 p);
3572 else if (file->f_mode & FMODE_WRITE)
3573 return
3574 put_user(
3575 (s->prop_dac.
3576 fmt & (AFMT_S8 | AFMT_U8)) ? 8 : 16,
3577 p);
3578
3579 case SOUND_PCM_WRITE_FILTER:
3580 case SNDCTL_DSP_SETSYNCRO:
3581 case SOUND_PCM_READ_FILTER:
3582 return -EINVAL;
3583 }
3584 return mixer_ioctl(s, cmd, arg);
3585}
3586
3587
3588static int cs4281_release(struct inode *inode, struct file *file)
3589{
3590 struct cs4281_state *s =
3591 (struct cs4281_state *) file->private_data;
3592
3593 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 2, printk(KERN_INFO
3594 "cs4281: cs4281_release(): inode=%p file=%p f_mode=%d\n",
3595 inode, file, file->f_mode));
3596
3597 VALIDATE_STATE(s);
3598
3599 if (file->f_mode & FMODE_WRITE) {
3600 drain_dac(s, file->f_flags & O_NONBLOCK);
3601 down(&s->open_sem_dac);
3602 stop_dac(s);
3603 dealloc_dmabuf(s, &s->dma_dac);
3604 s->open_mode &= ~FMODE_WRITE;
3605 up(&s->open_sem_dac);
3606 wake_up(&s->open_wait_dac);
3607 }
3608 if (file->f_mode & FMODE_READ) {
3609 drain_adc(s, file->f_flags & O_NONBLOCK);
3610 down(&s->open_sem_adc);
3611 stop_adc(s);
3612 dealloc_dmabuf(s, &s->dma_adc);
3613 s->open_mode &= ~FMODE_READ;
3614 up(&s->open_sem_adc);
3615 wake_up(&s->open_wait_adc);
3616 }
3617 return 0;
3618}
3619
3620static int cs4281_open(struct inode *inode, struct file *file)
3621{
3622 unsigned int minor = iminor(inode);
3623 struct cs4281_state *s=NULL;
3624 struct list_head *entry;
3625
3626 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
3627 "cs4281: cs4281_open(): inode=%p file=%p f_mode=0x%x\n",
3628 inode, file, file->f_mode));
3629
3630 list_for_each(entry, &cs4281_devs)
3631 {
3632 s = list_entry(entry, struct cs4281_state, list);
3633
3634 if (!((s->dev_audio ^ minor) & ~0xf))
3635 break;
3636 }
3637 if (entry == &cs4281_devs)
3638 return -ENODEV;
3639 if (!s) {
3640 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
3641 "cs4281: cs4281_open(): Error - unable to find audio state struct\n"));
3642 return -ENODEV;
3643 }
3644 VALIDATE_STATE(s);
3645 file->private_data = s;
3646
3647 // wait for device to become free
3648 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) {
3649 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2, printk(KERN_INFO
3650 "cs4281: cs4281_open(): Error - must open READ and/or WRITE\n"));
3651 return -ENODEV;
3652 }
3653 if (file->f_mode & FMODE_WRITE) {
3654 down(&s->open_sem_dac);
3655 while (s->open_mode & FMODE_WRITE) {
3656 if (file->f_flags & O_NONBLOCK) {
3657 up(&s->open_sem_dac);
3658 return -EBUSY;
3659 }
3660 up(&s->open_sem_dac);
3661 interruptible_sleep_on(&s->open_wait_dac);
3662
3663 if (signal_pending(current))
3664 return -ERESTARTSYS;
3665 down(&s->open_sem_dac);
3666 }
3667 }
3668 if (file->f_mode & FMODE_READ) {
3669 down(&s->open_sem_adc);
3670 while (s->open_mode & FMODE_READ) {
3671 if (file->f_flags & O_NONBLOCK) {
3672 up(&s->open_sem_adc);
3673 return -EBUSY;
3674 }
3675 up(&s->open_sem_adc);
3676 interruptible_sleep_on(&s->open_wait_adc);
3677
3678 if (signal_pending(current))
3679 return -ERESTARTSYS;
3680 down(&s->open_sem_adc);
3681 }
3682 }
3683 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
3684 if (file->f_mode & FMODE_READ) {
3685 s->prop_adc.fmt = AFMT_U8;
3686 s->prop_adc.fmt_original = s->prop_adc.fmt;
3687 s->prop_adc.channels = 1;
3688 s->prop_adc.rate = 8000;
3689 s->prop_adc.clkdiv = 96 | 0x80;
3690 s->conversion = 0;
3691 s->ena &= ~FMODE_READ;
3692 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
3693 s->dma_adc.subdivision = 0;
3694 up(&s->open_sem_adc);
3695
3696 if (prog_dmabuf_adc(s)) {
3697 CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
3698 "cs4281: adc Program dmabufs failed.\n"));
3699 cs4281_release(inode, file);
3700 return -ENOMEM;
3701 }
3702 prog_codec(s, CS_TYPE_ADC);
3703 }
3704 if (file->f_mode & FMODE_WRITE) {
3705 s->prop_dac.fmt = AFMT_U8;
3706 s->prop_dac.fmt_original = s->prop_dac.fmt;
3707 s->prop_dac.channels = 1;
3708 s->prop_dac.rate = 8000;
3709 s->prop_dac.clkdiv = 96 | 0x80;
3710 s->conversion = 0;
3711 s->ena &= ~FMODE_WRITE;
3712 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
3713 s->dma_dac.subdivision = 0;
3714 up(&s->open_sem_dac);
3715
3716 if (prog_dmabuf_dac(s)) {
3717 CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
3718 "cs4281: dac Program dmabufs failed.\n"));
3719 cs4281_release(inode, file);
3720 return -ENOMEM;
3721 }
3722 prog_codec(s, CS_TYPE_DAC);
3723 }
3724 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2,
3725 printk(KERN_INFO "cs4281: cs4281_open()- 0\n"));
3726 return nonseekable_open(inode, file);
3727}
3728
3729
3730// ******************************************************************************************
3731// Wave (audio) file operations struct.
3732// ******************************************************************************************
3733static /*const */ struct file_operations cs4281_audio_fops = {
3734 .owner = THIS_MODULE,
3735 .llseek = no_llseek,
3736 .read = cs4281_read,
3737 .write = cs4281_write,
3738 .poll = cs4281_poll,
3739 .ioctl = cs4281_ioctl,
3740 .mmap = cs4281_mmap,
3741 .open = cs4281_open,
3742 .release = cs4281_release,
3743};
3744
3745// ---------------------------------------------------------------------
3746
3747// hold spinlock for the following!
3748static void cs4281_handle_midi(struct cs4281_state *s)
3749{
3750 unsigned char ch;
3751 int wake;
3752 unsigned temp1;
3753
3754 wake = 0;
3755 while (!(readl(s->pBA0 + BA0_MIDSR) & 0x80)) {
3756 ch = readl(s->pBA0 + BA0_MIDRP);
3757 if (s->midi.icnt < MIDIINBUF) {
3758 s->midi.ibuf[s->midi.iwr] = ch;
3759 s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF;
3760 s->midi.icnt++;
3761 }
3762 wake = 1;
3763 }
3764 if (wake)
3765 wake_up(&s->midi.iwait);
3766 wake = 0;
3767 while (!(readl(s->pBA0 + BA0_MIDSR) & 0x40) && s->midi.ocnt > 0) {
3768 temp1 = (s->midi.obuf[s->midi.ord]) & 0x000000ff;
3769 writel(temp1, s->pBA0 + BA0_MIDWP);
3770 s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF;
3771 s->midi.ocnt--;
3772 if (s->midi.ocnt < MIDIOUTBUF - 16)
3773 wake = 1;
3774 }
3775 if (wake)
3776 wake_up(&s->midi.owait);
3777}
3778
3779
3780
3781static irqreturn_t cs4281_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3782{
3783 struct cs4281_state *s = (struct cs4281_state *) dev_id;
3784 unsigned int temp1;
3785
3786 // fastpath out, to ease interrupt sharing
3787 temp1 = readl(s->pBA0 + BA0_HISR); // Get Int Status reg.
3788
3789 CS_DBGOUT(CS_INTERRUPT, 6, printk(KERN_INFO
3790 "cs4281: cs4281_interrupt() BA0_HISR=0x%.8x\n", temp1));
3791/*
3792* If not DMA or MIDI interrupt, then just return.
3793*/
3794 if (!(temp1 & (HISR_DMA0 | HISR_DMA1 | HISR_MIDI))) {
3795 writel(HICR_IEV | HICR_CHGM, s->pBA0 + BA0_HICR);
3796 CS_DBGOUT(CS_INTERRUPT, 9, printk(KERN_INFO
3797 "cs4281: cs4281_interrupt(): returning not cs4281 interrupt.\n"));
3798 return IRQ_NONE;
3799 }
3800
3801 if (temp1 & HISR_DMA0) // If play interrupt,
3802 readl(s->pBA0 + BA0_HDSR0); // clear the source.
3803
3804 if (temp1 & HISR_DMA1) // Same for play.
3805 readl(s->pBA0 + BA0_HDSR1);
3806 writel(HICR_IEV | HICR_CHGM, s->pBA0 + BA0_HICR); // Local EOI
3807
3808 spin_lock(&s->lock);
3809 cs4281_update_ptr(s,CS_TRUE);
3810 cs4281_handle_midi(s);
3811 spin_unlock(&s->lock);
3812 return IRQ_HANDLED;
3813}
3814
3815// **************************************************************************
3816
3817static void cs4281_midi_timer(unsigned long data)
3818{
3819 struct cs4281_state *s = (struct cs4281_state *) data;
3820 unsigned long flags;
3821
3822 spin_lock_irqsave(&s->lock, flags);
3823 cs4281_handle_midi(s);
3824 spin_unlock_irqrestore(&s->lock, flags);
3825 s->midi.timer.expires = jiffies + 1;
3826 add_timer(&s->midi.timer);
3827}
3828
3829
3830// ---------------------------------------------------------------------
3831
3832static ssize_t cs4281_midi_read(struct file *file, char __user *buffer,
3833 size_t count, loff_t * ppos)
3834{
3835 struct cs4281_state *s =
3836 (struct cs4281_state *) file->private_data;
3837 ssize_t ret;
3838 unsigned long flags;
3839 unsigned ptr;
3840 int cnt;
3841
3842 VALIDATE_STATE(s);
3843 if (!access_ok(VERIFY_WRITE, buffer, count))
3844 return -EFAULT;
3845 ret = 0;
3846 while (count > 0) {
3847 spin_lock_irqsave(&s->lock, flags);
3848 ptr = s->midi.ird;
3849 cnt = MIDIINBUF - ptr;
3850 if (s->midi.icnt < cnt)
3851 cnt = s->midi.icnt;
3852 spin_unlock_irqrestore(&s->lock, flags);
3853 if (cnt > count)
3854 cnt = count;
3855 if (cnt <= 0) {
3856 if (file->f_flags & O_NONBLOCK)
3857 return ret ? ret : -EAGAIN;
3858 interruptible_sleep_on(&s->midi.iwait);
3859 if (signal_pending(current))
3860 return ret ? ret : -ERESTARTSYS;
3861 continue;
3862 }
3863 if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt))
3864 return ret ? ret : -EFAULT;
3865 ptr = (ptr + cnt) % MIDIINBUF;
3866 spin_lock_irqsave(&s->lock, flags);
3867 s->midi.ird = ptr;
3868 s->midi.icnt -= cnt;
3869 spin_unlock_irqrestore(&s->lock, flags);
3870 count -= cnt;
3871 buffer += cnt;
3872 ret += cnt;
3873 }
3874 return ret;
3875}
3876
3877
3878static ssize_t cs4281_midi_write(struct file *file, const char __user *buffer,
3879 size_t count, loff_t * ppos)
3880{
3881 struct cs4281_state *s =
3882 (struct cs4281_state *) file->private_data;
3883 ssize_t ret;
3884 unsigned long flags;
3885 unsigned ptr;
3886 int cnt;
3887
3888 VALIDATE_STATE(s);
3889 if (!access_ok(VERIFY_READ, buffer, count))
3890 return -EFAULT;
3891 ret = 0;
3892 while (count > 0) {
3893 spin_lock_irqsave(&s->lock, flags);
3894 ptr = s->midi.owr;
3895 cnt = MIDIOUTBUF - ptr;
3896 if (s->midi.ocnt + cnt > MIDIOUTBUF)
3897 cnt = MIDIOUTBUF - s->midi.ocnt;
3898 if (cnt <= 0)
3899 cs4281_handle_midi(s);
3900 spin_unlock_irqrestore(&s->lock, flags);
3901 if (cnt > count)
3902 cnt = count;
3903 if (cnt <= 0) {
3904 if (file->f_flags & O_NONBLOCK)
3905 return ret ? ret : -EAGAIN;
3906 interruptible_sleep_on(&s->midi.owait);
3907 if (signal_pending(current))
3908 return ret ? ret : -ERESTARTSYS;
3909 continue;
3910 }
3911 if (copy_from_user(s->midi.obuf + ptr, buffer, cnt))
3912 return ret ? ret : -EFAULT;
3913 ptr = (ptr + cnt) % MIDIOUTBUF;
3914 spin_lock_irqsave(&s->lock, flags);
3915 s->midi.owr = ptr;
3916 s->midi.ocnt += cnt;
3917 spin_unlock_irqrestore(&s->lock, flags);
3918 count -= cnt;
3919 buffer += cnt;
3920 ret += cnt;
3921 spin_lock_irqsave(&s->lock, flags);
3922 cs4281_handle_midi(s);
3923 spin_unlock_irqrestore(&s->lock, flags);
3924 }
3925 return ret;
3926}
3927
3928
3929static unsigned int cs4281_midi_poll(struct file *file,
3930 struct poll_table_struct *wait)
3931{
3932 struct cs4281_state *s =
3933 (struct cs4281_state *) file->private_data;
3934 unsigned long flags;
3935 unsigned int mask = 0;
3936
3937 VALIDATE_STATE(s);
3938 if (file->f_flags & FMODE_WRITE)
3939 poll_wait(file, &s->midi.owait, wait);
3940 if (file->f_flags & FMODE_READ)
3941 poll_wait(file, &s->midi.iwait, wait);
3942 spin_lock_irqsave(&s->lock, flags);
3943 if (file->f_flags & FMODE_READ) {
3944 if (s->midi.icnt > 0)
3945 mask |= POLLIN | POLLRDNORM;
3946 }
3947 if (file->f_flags & FMODE_WRITE) {
3948 if (s->midi.ocnt < MIDIOUTBUF)
3949 mask |= POLLOUT | POLLWRNORM;
3950 }
3951 spin_unlock_irqrestore(&s->lock, flags);
3952 return mask;
3953}
3954
3955
3956static int cs4281_midi_open(struct inode *inode, struct file *file)
3957{
3958 unsigned long flags, temp1;
3959 unsigned int minor = iminor(inode);
3960 struct cs4281_state *s=NULL;
3961 struct list_head *entry;
3962 list_for_each(entry, &cs4281_devs)
3963 {
3964 s = list_entry(entry, struct cs4281_state, list);
3965
3966 if (s->dev_midi == minor)
3967 break;
3968 }
3969
3970 if (entry == &cs4281_devs)
3971 return -ENODEV;
3972 if (!s)
3973 {
3974 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
3975 "cs4281: cs4281_open(): Error - unable to find audio state struct\n"));
3976 return -ENODEV;
3977 }
3978 VALIDATE_STATE(s);
3979 file->private_data = s;
3980 // wait for device to become free
3981 down(&s->open_sem);
3982 while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
3983 if (file->f_flags & O_NONBLOCK) {
3984 up(&s->open_sem);
3985 return -EBUSY;
3986 }
3987 up(&s->open_sem);
3988 interruptible_sleep_on(&s->open_wait);
3989 if (signal_pending(current))
3990 return -ERESTARTSYS;
3991 down(&s->open_sem);
3992 }
3993 spin_lock_irqsave(&s->lock, flags);
3994 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
3995 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
3996 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
3997 writel(1, s->pBA0 + BA0_MIDCR); // Reset the interface.
3998 writel(0, s->pBA0 + BA0_MIDCR); // Return to normal mode.
3999 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
4000 writel(0x0000000f, s->pBA0 + BA0_MIDCR); // Enable transmit, record, ints.
4001 temp1 = readl(s->pBA0 + BA0_HIMR);
4002 writel(temp1 & 0xffbfffff, s->pBA0 + BA0_HIMR); // Enable midi int. recognition.
4003 writel(HICR_IEV | HICR_CHGM, s->pBA0 + BA0_HICR); // Enable interrupts
4004 init_timer(&s->midi.timer);
4005 s->midi.timer.expires = jiffies + 1;
4006 s->midi.timer.data = (unsigned long) s;
4007 s->midi.timer.function = cs4281_midi_timer;
4008 add_timer(&s->midi.timer);
4009 }
4010 if (file->f_mode & FMODE_READ) {
4011 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
4012 }
4013 if (file->f_mode & FMODE_WRITE) {
4014 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
4015 }
4016 spin_unlock_irqrestore(&s->lock, flags);
4017 s->open_mode |=
4018 (file->
4019 f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ |
4020 FMODE_MIDI_WRITE);
4021 up(&s->open_sem);
4022 return nonseekable_open(inode, file);
4023}
4024
4025
4026static int cs4281_midi_release(struct inode *inode, struct file *file)
4027{
4028 struct cs4281_state *s =
4029 (struct cs4281_state *) file->private_data;
4030 DECLARE_WAITQUEUE(wait, current);
4031 unsigned long flags;
4032 unsigned count, tmo;
4033
4034 VALIDATE_STATE(s);
4035
4036 if (file->f_mode & FMODE_WRITE) {
4037 add_wait_queue(&s->midi.owait, &wait);
4038 for (;;) {
4039 set_current_state(TASK_INTERRUPTIBLE);
4040 spin_lock_irqsave(&s->lock, flags);
4041 count = s->midi.ocnt;
4042 spin_unlock_irqrestore(&s->lock, flags);
4043 if (count <= 0)
4044 break;
4045 if (signal_pending(current))
4046 break;
4047 if (file->f_flags & O_NONBLOCK) {
4048 remove_wait_queue(&s->midi.owait, &wait);
4049 current->state = TASK_RUNNING;
4050 return -EBUSY;
4051 }
4052 tmo = (count * HZ) / 3100;
4053 if (!schedule_timeout(tmo ? : 1) && tmo)
4054 printk(KERN_DEBUG
4055 "cs4281: midi timed out??\n");
4056 }
4057 remove_wait_queue(&s->midi.owait, &wait);
4058 current->state = TASK_RUNNING;
4059 }
4060 down(&s->open_sem);
4061 s->open_mode &=
4062 (~(file->f_mode << FMODE_MIDI_SHIFT)) & (FMODE_MIDI_READ |
4063 FMODE_MIDI_WRITE);
4064 spin_lock_irqsave(&s->lock, flags);
4065 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
4066 writel(0, s->pBA0 + BA0_MIDCR); // Disable Midi interrupts.
4067 del_timer(&s->midi.timer);
4068 }
4069 spin_unlock_irqrestore(&s->lock, flags);
4070 up(&s->open_sem);
4071 wake_up(&s->open_wait);
4072 return 0;
4073}
4074
4075// ******************************************************************************************
4076// Midi file operations struct.
4077// ******************************************************************************************
4078static /*const */ struct file_operations cs4281_midi_fops = {
4079 .owner = THIS_MODULE,
4080 .llseek = no_llseek,
4081 .read = cs4281_midi_read,
4082 .write = cs4281_midi_write,
4083 .poll = cs4281_midi_poll,
4084 .open = cs4281_midi_open,
4085 .release = cs4281_midi_release,
4086};
4087
4088
4089// ---------------------------------------------------------------------
4090
4091// maximum number of devices
4092#define NR_DEVICE 8 // Only eight devices supported currently.
4093
4094// ---------------------------------------------------------------------
4095
4096static struct initvol {
4097 int mixch;
4098 int vol;
4099} initvol[] __devinitdata = {
4100
4101 {
4102 SOUND_MIXER_WRITE_VOLUME, 0x4040}, {
4103 SOUND_MIXER_WRITE_PCM, 0x4040}, {
4104 SOUND_MIXER_WRITE_SYNTH, 0x4040}, {
4105 SOUND_MIXER_WRITE_CD, 0x4040}, {
4106 SOUND_MIXER_WRITE_LINE, 0x4040}, {
4107 SOUND_MIXER_WRITE_LINE1, 0x4040}, {
4108 SOUND_MIXER_WRITE_RECLEV, 0x0000}, {
4109 SOUND_MIXER_WRITE_SPEAKER, 0x4040}, {
4110 SOUND_MIXER_WRITE_MIC, 0x0000}
4111};
4112
4113
4114#ifndef NOT_CS4281_PM
4115static void __devinit cs4281_BuildFIFO(
4116 struct cs4281_pipeline *p,
4117 struct cs4281_state *s)
4118{
4119 switch(p->number)
4120 {
4121 case 0: /* playback */
4122 {
4123 p->u32FCRnAddress = BA0_FCR0;
4124 p->u32FSICnAddress = BA0_FSIC0;
4125 p->u32FPDRnAddress = BA0_FPDR0;
4126 break;
4127 }
4128 case 1: /* capture */
4129 {
4130 p->u32FCRnAddress = BA0_FCR1;
4131 p->u32FSICnAddress = BA0_FSIC1;
4132 p->u32FPDRnAddress = BA0_FPDR1;
4133 break;
4134 }
4135
4136 case 2:
4137 {
4138 p->u32FCRnAddress = BA0_FCR2;
4139 p->u32FSICnAddress = BA0_FSIC2;
4140 p->u32FPDRnAddress = BA0_FPDR2;
4141 break;
4142 }
4143 case 3:
4144 {
4145 p->u32FCRnAddress = BA0_FCR3;
4146 p->u32FSICnAddress = BA0_FSIC3;
4147 p->u32FPDRnAddress = BA0_FPDR3;
4148 break;
4149 }
4150 default:
4151 break;
4152 }
4153 //
4154 // first read the hardware to initialize the member variables
4155 //
4156 p->u32FCRnValue = readl(s->pBA0 + p->u32FCRnAddress);
4157 p->u32FSICnValue = readl(s->pBA0 + p->u32FSICnAddress);
4158 p->u32FPDRnValue = readl(s->pBA0 + p->u32FPDRnAddress);
4159
4160}
4161
4162static void __devinit cs4281_BuildDMAengine(
4163 struct cs4281_pipeline *p,
4164 struct cs4281_state *s)
4165{
4166/*
4167* initialize all the addresses of this pipeline dma info.
4168*/
4169 switch(p->number)
4170 {
4171 case 0: /* playback */
4172 {
4173 p->u32DBAnAddress = BA0_DBA0;
4174 p->u32DCAnAddress = BA0_DCA0;
4175 p->u32DBCnAddress = BA0_DBC0;
4176 p->u32DCCnAddress = BA0_DCC0;
4177 p->u32DMRnAddress = BA0_DMR0;
4178 p->u32DCRnAddress = BA0_DCR0;
4179 p->u32HDSRnAddress = BA0_HDSR0;
4180 break;
4181 }
4182
4183 case 1: /* capture */
4184 {
4185 p->u32DBAnAddress = BA0_DBA1;
4186 p->u32DCAnAddress = BA0_DCA1;
4187 p->u32DBCnAddress = BA0_DBC1;
4188 p->u32DCCnAddress = BA0_DCC1;
4189 p->u32DMRnAddress = BA0_DMR1;
4190 p->u32DCRnAddress = BA0_DCR1;
4191 p->u32HDSRnAddress = BA0_HDSR1;
4192 break;
4193 }
4194
4195 case 2:
4196 {
4197 p->u32DBAnAddress = BA0_DBA2;
4198 p->u32DCAnAddress = BA0_DCA2;
4199 p->u32DBCnAddress = BA0_DBC2;
4200 p->u32DCCnAddress = BA0_DCC2;
4201 p->u32DMRnAddress = BA0_DMR2;
4202 p->u32DCRnAddress = BA0_DCR2;
4203 p->u32HDSRnAddress = BA0_HDSR2;
4204 break;
4205 }
4206
4207 case 3:
4208 {
4209 p->u32DBAnAddress = BA0_DBA3;
4210 p->u32DCAnAddress = BA0_DCA3;
4211 p->u32DBCnAddress = BA0_DBC3;
4212 p->u32DCCnAddress = BA0_DCC3;
4213 p->u32DMRnAddress = BA0_DMR3;
4214 p->u32DCRnAddress = BA0_DCR3;
4215 p->u32HDSRnAddress = BA0_HDSR3;
4216 break;
4217 }
4218 default:
4219 break;
4220 }
4221
4222//
4223// Initialize the dma values for this pipeline
4224//
4225 p->u32DBAnValue = readl(s->pBA0 + p->u32DBAnAddress);
4226 p->u32DBCnValue = readl(s->pBA0 + p->u32DBCnAddress);
4227 p->u32DMRnValue = readl(s->pBA0 + p->u32DMRnAddress);
4228 p->u32DCRnValue = readl(s->pBA0 + p->u32DCRnAddress);
4229
4230}
4231
4232static void __devinit cs4281_InitPM(struct cs4281_state *s)
4233{
4234 int i;
4235 struct cs4281_pipeline *p;
4236
4237 for(i=0;i<CS4281_NUMBER_OF_PIPELINES;i++)
4238 {
4239 p = &s->pl[i];
4240 p->number = i;
4241 cs4281_BuildDMAengine(p,s);
4242 cs4281_BuildFIFO(p,s);
4243 /*
4244 * currently only 2 pipelines are used
4245 * so, only set the valid bit on the playback and capture.
4246 */
4247 if( (i == CS4281_PLAYBACK_PIPELINE_NUMBER) ||
4248 (i == CS4281_CAPTURE_PIPELINE_NUMBER))
4249 p->flags |= CS4281_PIPELINE_VALID;
4250 }
4251 s->pm.u32SSPM_BITS = 0x7e; /* rev c, use 0x7c for rev a or b */
4252}
4253#endif
4254
4255static int __devinit cs4281_probe(struct pci_dev *pcidev,
4256 const struct pci_device_id *pciid)
4257{
4258#ifndef NOT_CS4281_PM
4259 struct pm_dev *pmdev;
4260#endif
4261 struct cs4281_state *s;
4262 dma_addr_t dma_mask;
4263 mm_segment_t fs;
4264 int i, val;
4265 unsigned int temp1, temp2;
4266
4267 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2,
4268 printk(KERN_INFO "cs4281: probe()+\n"));
4269
4270 if (pci_enable_device(pcidev)) {
4271 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
4272 "cs4281: pci_enable_device() failed\n"));
4273 return -1;
4274 }
4275 if (!(pci_resource_flags(pcidev, 0) & IORESOURCE_MEM) ||
4276 !(pci_resource_flags(pcidev, 1) & IORESOURCE_MEM)) {
4277 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
4278 "cs4281: probe()- Memory region not assigned\n"));
4279 return -ENODEV;
4280 }
4281 if (pcidev->irq == 0) {
4282 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
4283 "cs4281: probe() IRQ not assigned\n"));
4284 return -ENODEV;
4285 }
4286 dma_mask = 0xffffffff; /* this enables playback and recording */
4287 i = pci_set_dma_mask(pcidev, dma_mask);
4288 if (i) {
4289 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
4290 "cs4281: probe() architecture does not support 32bit PCI busmaster DMA\n"));
4291 return i;
4292 }
4293 if (!(s = kmalloc(sizeof(struct cs4281_state), GFP_KERNEL))) {
4294 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
4295 "cs4281: probe() no memory for state struct.\n"));
4296 return -1;
4297 }
4298 memset(s, 0, sizeof(struct cs4281_state));
4299 init_waitqueue_head(&s->dma_adc.wait);
4300 init_waitqueue_head(&s->dma_dac.wait);
4301 init_waitqueue_head(&s->open_wait);
4302 init_waitqueue_head(&s->open_wait_adc);
4303 init_waitqueue_head(&s->open_wait_dac);
4304 init_waitqueue_head(&s->midi.iwait);
4305 init_waitqueue_head(&s->midi.owait);
4306 init_MUTEX(&s->open_sem);
4307 init_MUTEX(&s->open_sem_adc);
4308 init_MUTEX(&s->open_sem_dac);
4309 spin_lock_init(&s->lock);
4310 s->pBA0phys = pci_resource_start(pcidev, 0);
4311 s->pBA1phys = pci_resource_start(pcidev, 1);
4312
4313 /* Convert phys to linear. */
4314 s->pBA0 = ioremap_nocache(s->pBA0phys, 4096);
4315 if (!s->pBA0) {
4316 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_ERR
4317 "cs4281: BA0 I/O mapping failed. Skipping part.\n"));
4318 goto err_free;
4319 }
4320 s->pBA1 = ioremap_nocache(s->pBA1phys, 65536);
4321 if (!s->pBA1) {
4322 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_ERR
4323 "cs4281: BA1 I/O mapping failed. Skipping part.\n"));
4324 goto err_unmap;
4325 }
4326
4327 temp1 = readl(s->pBA0 + BA0_PCICFG00);
4328 temp2 = readl(s->pBA0 + BA0_PCICFG04);
4329
4330 CS_DBGOUT(CS_INIT, 2,
4331 printk(KERN_INFO
4332 "cs4281: probe() BA0=0x%.8x BA1=0x%.8x pBA0=%p pBA1=%p \n",
4333 (unsigned) temp1, (unsigned) temp2, s->pBA0, s->pBA1));
4334 CS_DBGOUT(CS_INIT, 2,
4335 printk(KERN_INFO
4336 "cs4281: probe() pBA0phys=0x%.8x pBA1phys=0x%.8x\n",
4337 (unsigned) s->pBA0phys, (unsigned) s->pBA1phys));
4338
4339#ifndef NOT_CS4281_PM
4340 s->pm.flags = CS4281_PM_IDLE;
4341#endif
4342 temp1 = cs4281_hw_init(s);
4343 if (temp1) {
4344 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_ERR
4345 "cs4281: cs4281_hw_init() failed. Skipping part.\n"));
4346 goto err_irq;
4347 }
4348 s->magic = CS4281_MAGIC;
4349 s->pcidev = pcidev;
4350 s->irq = pcidev->irq;
4351 if (request_irq
4352 (s->irq, cs4281_interrupt, SA_SHIRQ, "Crystal CS4281", s)) {
4353 CS_DBGOUT(CS_INIT | CS_ERROR, 1,
4354 printk(KERN_ERR "cs4281: irq %u in use\n", s->irq));
4355 goto err_irq;
4356 }
4357 if ((s->dev_audio = register_sound_dsp(&cs4281_audio_fops, -1)) <
4358 0) {
4359 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
4360 "cs4281: probe() register_sound_dsp() failed.\n"));
4361 goto err_dev1;
4362 }
4363 if ((s->dev_mixer = register_sound_mixer(&cs4281_mixer_fops, -1)) <
4364 0) {
4365 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
4366 "cs4281: probe() register_sound_mixer() failed.\n"));
4367 goto err_dev2;
4368 }
4369 if ((s->dev_midi = register_sound_midi(&cs4281_midi_fops, -1)) < 0) {
4370 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
4371 "cs4281: probe() register_sound_midi() failed.\n"));
4372 goto err_dev3;
4373 }
4374#ifndef NOT_CS4281_PM
4375 cs4281_InitPM(s);
4376 pmdev = cs_pm_register(PM_PCI_DEV, PM_PCI_ID(pcidev), cs4281_pm_callback);
4377 if (pmdev)
4378 {
4379 CS_DBGOUT(CS_INIT | CS_PM, 4, printk(KERN_INFO
4380 "cs4281: probe() pm_register() succeeded (%p).\n", pmdev));
4381 pmdev->data = s;
4382 }
4383 else
4384 {
4385 CS_DBGOUT(CS_INIT | CS_PM | CS_ERROR, 0, printk(KERN_INFO
4386 "cs4281: probe() pm_register() failed (%p).\n", pmdev));
4387 s->pm.flags |= CS4281_PM_NOT_REGISTERED;
4388 }
4389#endif
4390
4391 pci_set_master(pcidev); // enable bus mastering
4392
4393 fs = get_fs();
4394 set_fs(KERNEL_DS);
4395 val = SOUND_MASK_LINE;
4396 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
4397 for (i = 0; i < sizeof(initvol) / sizeof(initvol[0]); i++) {
4398 val = initvol[i].vol;
4399 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
4400 }
4401 val = 1; // enable mic preamp
4402 mixer_ioctl(s, SOUND_MIXER_PRIVATE1, (unsigned long) &val);
4403 set_fs(fs);
4404
4405 pci_set_drvdata(pcidev, s);
4406 list_add(&s->list, &cs4281_devs);
4407 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
4408 "cs4281: probe()- device allocated successfully\n"));
4409 return 0;
4410
4411 err_dev3:
4412 unregister_sound_mixer(s->dev_mixer);
4413 err_dev2:
4414 unregister_sound_dsp(s->dev_audio);
4415 err_dev1:
4416 free_irq(s->irq, s);
4417 err_irq:
4418 iounmap(s->pBA1);
4419 err_unmap:
4420 iounmap(s->pBA0);
4421 err_free:
4422 kfree(s);
4423
4424 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_INFO
4425 "cs4281: probe()- no device allocated\n"));
4426 return -ENODEV;
4427} // probe_cs4281
4428
4429
4430// ---------------------------------------------------------------------
4431
4432static void __devexit cs4281_remove(struct pci_dev *pci_dev)
4433{
4434 struct cs4281_state *s = pci_get_drvdata(pci_dev);
4435 // stop DMA controller
4436 synchronize_irq(s->irq);
4437 free_irq(s->irq, s);
4438 unregister_sound_dsp(s->dev_audio);
4439 unregister_sound_mixer(s->dev_mixer);
4440 unregister_sound_midi(s->dev_midi);
4441 iounmap(s->pBA1);
4442 iounmap(s->pBA0);
4443 pci_set_drvdata(pci_dev,NULL);
4444 list_del(&s->list);
4445 kfree(s);
4446 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
4447 "cs4281: cs4281_remove()-: remove successful\n"));
4448}
4449
4450static struct pci_device_id cs4281_pci_tbl[] = {
4451 {
4452 .vendor = PCI_VENDOR_ID_CIRRUS,
4453 .device = PCI_DEVICE_ID_CRYSTAL_CS4281,
4454 .subvendor = PCI_ANY_ID,
4455 .subdevice = PCI_ANY_ID,
4456 },
4457 { 0, },
4458};
4459
4460MODULE_DEVICE_TABLE(pci, cs4281_pci_tbl);
4461
4462static struct pci_driver cs4281_pci_driver = {
4463 .name = "cs4281",
4464 .id_table = cs4281_pci_tbl,
4465 .probe = cs4281_probe,
4466 .remove = __devexit_p(cs4281_remove),
4467 .suspend = CS4281_SUSPEND_TBL,
4468 .resume = CS4281_RESUME_TBL,
4469};
4470
4471static int __init cs4281_init_module(void)
4472{
4473 int rtn = 0;
4474 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
4475 "cs4281: cs4281_init_module()+ \n"));
4476 printk(KERN_INFO "cs4281: version v%d.%02d.%d time " __TIME__ " "
4477 __DATE__ "\n", CS4281_MAJOR_VERSION, CS4281_MINOR_VERSION,
4478 CS4281_ARCH);
4479 rtn = pci_module_init(&cs4281_pci_driver);
4480
4481 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
4482 printk(KERN_INFO "cs4281: cs4281_init_module()- (%d)\n",rtn));
4483 return rtn;
4484}
4485
4486static void __exit cs4281_cleanup_module(void)
4487{
4488 pci_unregister_driver(&cs4281_pci_driver);
4489#ifndef NOT_CS4281_PM
4490 cs_pm_unregister_all(cs4281_pm_callback);
4491#endif
4492 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
4493 printk(KERN_INFO "cs4281: cleanup_cs4281() finished\n"));
4494}
4495// ---------------------------------------------------------------------
4496
4497MODULE_AUTHOR("gw boynton, audio@crystal.cirrus.com");
4498MODULE_DESCRIPTION("Cirrus Logic CS4281 Driver");
4499MODULE_LICENSE("GPL");
4500
4501// ---------------------------------------------------------------------
4502
4503module_init(cs4281_init_module);
4504module_exit(cs4281_cleanup_module);
4505
diff --git a/sound/oss/cs4281/cs4281pm-24.c b/sound/oss/cs4281/cs4281pm-24.c
new file mode 100644
index 000000000000..d2a453aff0aa
--- /dev/null
+++ b/sound/oss/cs4281/cs4281pm-24.c
@@ -0,0 +1,84 @@
1/*******************************************************************************
2*
3* "cs4281pm.c" -- Cirrus Logic-Crystal CS4281 linux audio driver.
4*
5* Copyright (C) 2000,2001 Cirrus Logic Corp.
6* -- tom woller (twoller@crystal.cirrus.com) or
7* (audio@crystal.cirrus.com).
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* 12/22/00 trw - new file.
24*
25*******************************************************************************/
26
27#ifndef NOT_CS4281_PM
28#include <linux/pm.h>
29
30#define cs_pm_register(a, b, c) pm_register((a), (b), (c));
31#define cs_pm_unregister_all(a) pm_unregister_all((a));
32
33static int cs4281_suspend(struct cs4281_state *s);
34static int cs4281_resume(struct cs4281_state *s);
35/*
36* for now (12/22/00) only enable the pm_register PM support.
37* allow these table entries to be null.
38#define CS4281_SUSPEND_TBL cs4281_suspend_tbl
39#define CS4281_RESUME_TBL cs4281_resume_tbl
40*/
41#define CS4281_SUSPEND_TBL cs4281_suspend_null
42#define CS4281_RESUME_TBL cs4281_resume_null
43
44static int cs4281_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
45{
46 struct cs4281_state *state;
47
48 CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
49 "cs4281: cs4281_pm_callback dev=%p rqst=0x%x state=%p\n",
50 dev,(unsigned)rqst,data));
51 state = (struct cs4281_state *) dev->data;
52 if (state) {
53 switch(rqst) {
54 case PM_SUSPEND:
55 CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
56 "cs4281: PM suspend request\n"));
57 if(cs4281_suspend(state))
58 {
59 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
60 "cs4281: PM suspend request refused\n"));
61 return 1;
62 }
63 break;
64 case PM_RESUME:
65 CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
66 "cs4281: PM resume request\n"));
67 if(cs4281_resume(state))
68 {
69 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
70 "cs4281: PM resume request refused\n"));
71 return 1;
72 }
73 break;
74 }
75 }
76
77 return 0;
78}
79
80#else /* CS4281_PM */
81#define CS4281_SUSPEND_TBL cs4281_suspend_null
82#define CS4281_RESUME_TBL cs4281_resume_null
83#endif /* CS4281_PM */
84
diff --git a/sound/oss/cs4281/cs4281pm.h b/sound/oss/cs4281/cs4281pm.h
new file mode 100644
index 000000000000..b44fdc9ce002
--- /dev/null
+++ b/sound/oss/cs4281/cs4281pm.h
@@ -0,0 +1,74 @@
1#ifndef NOT_CS4281_PM
2/*******************************************************************************
3*
4* "cs4281pm.h" -- Cirrus Logic-Crystal CS4281 linux audio driver.
5*
6* Copyright (C) 2000,2001 Cirrus Logic Corp.
7* -- tom woller (twoller@crystal.cirrus.com) or
8* (audio@crystal.cirrus.com).
9*
10* This program is free software; you can redistribute it and/or modify
11* it under the terms of the GNU General Public License as published by
12* the Free Software Foundation; either version 2 of the License, or
13* (at your option) any later version.
14*
15* This program is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with this program; if not, write to the Free Software
22* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23*
24* 12/22/00 trw - new file.
25*
26*******************************************************************************/
27/* general pm definitions */
28#define CS4281_AC97_HIGHESTREGTORESTORE 0x26
29#define CS4281_AC97_NUMBER_RESTORE_REGS (CS4281_AC97_HIGHESTREGTORESTORE/2-1)
30
31/* pipeline definitions */
32#define CS4281_NUMBER_OF_PIPELINES 4
33#define CS4281_PIPELINE_VALID 0x0001
34#define CS4281_PLAYBACK_PIPELINE_NUMBER 0x0000
35#define CS4281_CAPTURE_PIPELINE_NUMBER 0x0001
36
37/* PM state defintions */
38#define CS4281_PM_NOT_REGISTERED 0x1000
39#define CS4281_PM_IDLE 0x0001
40#define CS4281_PM_SUSPENDING 0x0002
41#define CS4281_PM_SUSPENDED 0x0004
42#define CS4281_PM_RESUMING 0x0008
43#define CS4281_PM_RESUMED 0x0010
44
45struct cs4281_pm {
46 unsigned long flags;
47 u32 u32CLKCR1_SAVE,u32SSPMValue,u32PPLVCvalue,u32PPRVCvalue;
48 u32 u32FMLVCvalue,u32FMRVCvalue,u32GPIORvalue,u32JSCTLvalue,u32SSCR;
49 u32 u32SRCSA,u32DacASR,u32AdcASR,u32DacSR,u32AdcSR,u32MIDCR_Save;
50 u32 u32SSPM_BITS;
51 u32 ac97[CS4281_AC97_NUMBER_RESTORE_REGS];
52 u32 u32AC97_master_volume, u32AC97_headphone_volume, u32AC97_master_volume_mono;
53 u32 u32AC97_pcm_out_volume, u32AC97_powerdown, u32AC97_general_purpose;
54 u32 u32hwptr_playback,u32hwptr_capture;
55};
56
57struct cs4281_pipeline {
58 unsigned flags;
59 unsigned number;
60 u32 u32DBAnValue,u32DBCnValue,u32DMRnValue,u32DCRnValue;
61 u32 u32DBAnAddress,u32DCAnAddress,u32DBCnAddress,u32DCCnAddress;
62 u32 u32DMRnAddress,u32DCRnAddress,u32HDSRnAddress;
63 u32 u32DBAn_Save,u32DBCn_Save,u32DMRn_Save,u32DCRn_Save;
64 u32 u32DCCn_Save,u32DCAn_Save;
65/*
66* technically, these are fifo variables, but just map the
67* first fifo with the first pipeline and then use the fifo
68* variables inside of the pipeline struct.
69*/
70 u32 u32FCRn_Save,u32FSICn_Save;
71 u32 u32FCRnValue,u32FCRnAddress,u32FSICnValue,u32FSICnAddress;
72 u32 u32FPDRnValue,u32FPDRnAddress;
73};
74#endif
diff --git a/sound/oss/cs461x.h b/sound/oss/cs461x.h
new file mode 100644
index 000000000000..0ce41338e6dd
--- /dev/null
+++ b/sound/oss/cs461x.h
@@ -0,0 +1,1691 @@
1#ifndef __CS461X_H
2#define __CS461X_H
3
4/*
5 * Copyright (c) by Cirrus Logic Corporation <pcaudio@crystal.cirrus.com>
6 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
7 * Definitions for Cirrus Logic CS461x chips
8 *
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26#ifndef PCI_VENDOR_ID_CIRRUS
27#define PCI_VENDOR_ID_CIRRUS 0x1013
28#endif
29#ifndef PCI_DEVICE_ID_CIRRUS_4610
30#define PCI_DEVICE_ID_CIRRUS_4610 0x6001
31#endif
32#ifndef PCI_DEVICE_ID_CIRRUS_4612
33#define PCI_DEVICE_ID_CIRRUS_4612 0x6003
34#endif
35#ifndef PCI_DEVICE_ID_CIRRUS_4615
36#define PCI_DEVICE_ID_CIRRUS_4615 0x6004
37#endif
38
39/*
40 * Direct registers
41 */
42
43/*
44 * The following define the offsets of the registers accessed via base address
45 * register zero on the CS461x part.
46 */
47#define BA0_HISR 0x00000000
48#define BA0_HSR0 0x00000004
49#define BA0_HICR 0x00000008
50#define BA0_DMSR 0x00000100
51#define BA0_HSAR 0x00000110
52#define BA0_HDAR 0x00000114
53#define BA0_HDMR 0x00000118
54#define BA0_HDCR 0x0000011C
55#define BA0_PFMC 0x00000200
56#define BA0_PFCV1 0x00000204
57#define BA0_PFCV2 0x00000208
58#define BA0_PCICFG00 0x00000300
59#define BA0_PCICFG04 0x00000304
60#define BA0_PCICFG08 0x00000308
61#define BA0_PCICFG0C 0x0000030C
62#define BA0_PCICFG10 0x00000310
63#define BA0_PCICFG14 0x00000314
64#define BA0_PCICFG18 0x00000318
65#define BA0_PCICFG1C 0x0000031C
66#define BA0_PCICFG20 0x00000320
67#define BA0_PCICFG24 0x00000324
68#define BA0_PCICFG28 0x00000328
69#define BA0_PCICFG2C 0x0000032C
70#define BA0_PCICFG30 0x00000330
71#define BA0_PCICFG34 0x00000334
72#define BA0_PCICFG38 0x00000338
73#define BA0_PCICFG3C 0x0000033C
74#define BA0_CLKCR1 0x00000400
75#define BA0_CLKCR2 0x00000404
76#define BA0_PLLM 0x00000408
77#define BA0_PLLCC 0x0000040C
78#define BA0_FRR 0x00000410
79#define BA0_CFL1 0x00000414
80#define BA0_CFL2 0x00000418
81#define BA0_SERMC1 0x00000420
82#define BA0_SERMC2 0x00000424
83#define BA0_SERC1 0x00000428
84#define BA0_SERC2 0x0000042C
85#define BA0_SERC3 0x00000430
86#define BA0_SERC4 0x00000434
87#define BA0_SERC5 0x00000438
88#define BA0_SERBSP 0x0000043C
89#define BA0_SERBST 0x00000440
90#define BA0_SERBCM 0x00000444
91#define BA0_SERBAD 0x00000448
92#define BA0_SERBCF 0x0000044C
93#define BA0_SERBWP 0x00000450
94#define BA0_SERBRP 0x00000454
95#ifndef NO_CS4612
96#define BA0_ASER_FADDR 0x00000458
97#endif
98#define BA0_ACCTL 0x00000460
99#define BA0_ACSTS 0x00000464
100#define BA0_ACOSV 0x00000468
101#define BA0_ACCAD 0x0000046C
102#define BA0_ACCDA 0x00000470
103#define BA0_ACISV 0x00000474
104#define BA0_ACSAD 0x00000478
105#define BA0_ACSDA 0x0000047C
106#define BA0_JSPT 0x00000480
107#define BA0_JSCTL 0x00000484
108#define BA0_JSC1 0x00000488
109#define BA0_JSC2 0x0000048C
110#define BA0_MIDCR 0x00000490
111#define BA0_MIDSR 0x00000494
112#define BA0_MIDWP 0x00000498
113#define BA0_MIDRP 0x0000049C
114#define BA0_JSIO 0x000004A0
115#ifndef NO_CS4612
116#define BA0_ASER_MASTER 0x000004A4
117#endif
118#define BA0_CFGI 0x000004B0
119#define BA0_SSVID 0x000004B4
120#define BA0_GPIOR 0x000004B8
121#ifndef NO_CS4612
122#define BA0_EGPIODR 0x000004BC
123#define BA0_EGPIOPTR 0x000004C0
124#define BA0_EGPIOTR 0x000004C4
125#define BA0_EGPIOWR 0x000004C8
126#define BA0_EGPIOSR 0x000004CC
127#define BA0_SERC6 0x000004D0
128#define BA0_SERC7 0x000004D4
129#define BA0_SERACC 0x000004D8
130#define BA0_ACCTL2 0x000004E0
131#define BA0_ACSTS2 0x000004E4
132#define BA0_ACOSV2 0x000004E8
133#define BA0_ACCAD2 0x000004EC
134#define BA0_ACCDA2 0x000004F0
135#define BA0_ACISV2 0x000004F4
136#define BA0_ACSAD2 0x000004F8
137#define BA0_ACSDA2 0x000004FC
138#define BA0_IOTAC0 0x00000500
139#define BA0_IOTAC1 0x00000504
140#define BA0_IOTAC2 0x00000508
141#define BA0_IOTAC3 0x0000050C
142#define BA0_IOTAC4 0x00000510
143#define BA0_IOTAC5 0x00000514
144#define BA0_IOTAC6 0x00000518
145#define BA0_IOTAC7 0x0000051C
146#define BA0_IOTAC8 0x00000520
147#define BA0_IOTAC9 0x00000524
148#define BA0_IOTAC10 0x00000528
149#define BA0_IOTAC11 0x0000052C
150#define BA0_IOTFR0 0x00000540
151#define BA0_IOTFR1 0x00000544
152#define BA0_IOTFR2 0x00000548
153#define BA0_IOTFR3 0x0000054C
154#define BA0_IOTFR4 0x00000550
155#define BA0_IOTFR5 0x00000554
156#define BA0_IOTFR6 0x00000558
157#define BA0_IOTFR7 0x0000055C
158#define BA0_IOTFIFO 0x00000580
159#define BA0_IOTRRD 0x00000584
160#define BA0_IOTFP 0x00000588
161#define BA0_IOTCR 0x0000058C
162#define BA0_DPCID 0x00000590
163#define BA0_DPCIA 0x00000594
164#define BA0_DPCIC 0x00000598
165#define BA0_PCPCIR 0x00000600
166#define BA0_PCPCIG 0x00000604
167#define BA0_PCPCIEN 0x00000608
168#define BA0_EPCIPMC 0x00000610
169#endif
170
171/*
172 * The following define the offsets of the registers and memories accessed via
173 * base address register one on the CS461x part.
174 */
175#define BA1_SP_DMEM0 0x00000000
176#define BA1_SP_DMEM1 0x00010000
177#define BA1_SP_PMEM 0x00020000
178#define BA1_SP_REG 0x00030000
179#define BA1_SPCR 0x00030000
180#define BA1_DREG 0x00030004
181#define BA1_DSRWP 0x00030008
182#define BA1_TWPR 0x0003000C
183#define BA1_SPWR 0x00030010
184#define BA1_SPIR 0x00030014
185#define BA1_FGR1 0x00030020
186#define BA1_SPCS 0x00030028
187#define BA1_SDSR 0x0003002C
188#define BA1_FRMT 0x00030030
189#define BA1_FRCC 0x00030034
190#define BA1_FRSC 0x00030038
191#define BA1_OMNI_MEM 0x000E0000
192
193/*
194 * The following defines are for the flags in the host interrupt status
195 * register.
196 */
197#define HISR_VC_MASK 0x0000FFFF
198#define HISR_VC0 0x00000001
199#define HISR_VC1 0x00000002
200#define HISR_VC2 0x00000004
201#define HISR_VC3 0x00000008
202#define HISR_VC4 0x00000010
203#define HISR_VC5 0x00000020
204#define HISR_VC6 0x00000040
205#define HISR_VC7 0x00000080
206#define HISR_VC8 0x00000100
207#define HISR_VC9 0x00000200
208#define HISR_VC10 0x00000400
209#define HISR_VC11 0x00000800
210#define HISR_VC12 0x00001000
211#define HISR_VC13 0x00002000
212#define HISR_VC14 0x00004000
213#define HISR_VC15 0x00008000
214#define HISR_INT0 0x00010000
215#define HISR_INT1 0x00020000
216#define HISR_DMAI 0x00040000
217#define HISR_FROVR 0x00080000
218#define HISR_MIDI 0x00100000
219#ifdef NO_CS4612
220#define HISR_RESERVED 0x0FE00000
221#else
222#define HISR_SBINT 0x00200000
223#define HISR_RESERVED 0x0FC00000
224#endif
225#define HISR_H0P 0x40000000
226#define HISR_INTENA 0x80000000
227
228/*
229 * The following defines are for the flags in the host signal register 0.
230 */
231#define HSR0_VC_MASK 0xFFFFFFFF
232#define HSR0_VC16 0x00000001
233#define HSR0_VC17 0x00000002
234#define HSR0_VC18 0x00000004
235#define HSR0_VC19 0x00000008
236#define HSR0_VC20 0x00000010
237#define HSR0_VC21 0x00000020
238#define HSR0_VC22 0x00000040
239#define HSR0_VC23 0x00000080
240#define HSR0_VC24 0x00000100
241#define HSR0_VC25 0x00000200
242#define HSR0_VC26 0x00000400
243#define HSR0_VC27 0x00000800
244#define HSR0_VC28 0x00001000
245#define HSR0_VC29 0x00002000
246#define HSR0_VC30 0x00004000
247#define HSR0_VC31 0x00008000
248#define HSR0_VC32 0x00010000
249#define HSR0_VC33 0x00020000
250#define HSR0_VC34 0x00040000
251#define HSR0_VC35 0x00080000
252#define HSR0_VC36 0x00100000
253#define HSR0_VC37 0x00200000
254#define HSR0_VC38 0x00400000
255#define HSR0_VC39 0x00800000
256#define HSR0_VC40 0x01000000
257#define HSR0_VC41 0x02000000
258#define HSR0_VC42 0x04000000
259#define HSR0_VC43 0x08000000
260#define HSR0_VC44 0x10000000
261#define HSR0_VC45 0x20000000
262#define HSR0_VC46 0x40000000
263#define HSR0_VC47 0x80000000
264
265/*
266 * The following defines are for the flags in the host interrupt control
267 * register.
268 */
269#define HICR_IEV 0x00000001
270#define HICR_CHGM 0x00000002
271
272/*
273 * The following defines are for the flags in the DMA status register.
274 */
275#define DMSR_HP 0x00000001
276#define DMSR_HR 0x00000002
277#define DMSR_SP 0x00000004
278#define DMSR_SR 0x00000008
279
280/*
281 * The following defines are for the flags in the host DMA source address
282 * register.
283 */
284#define HSAR_HOST_ADDR_MASK 0xFFFFFFFF
285#define HSAR_DSP_ADDR_MASK 0x0000FFFF
286#define HSAR_MEMID_MASK 0x000F0000
287#define HSAR_MEMID_SP_DMEM0 0x00000000
288#define HSAR_MEMID_SP_DMEM1 0x00010000
289#define HSAR_MEMID_SP_PMEM 0x00020000
290#define HSAR_MEMID_SP_DEBUG 0x00030000
291#define HSAR_MEMID_OMNI_MEM 0x000E0000
292#define HSAR_END 0x40000000
293#define HSAR_ERR 0x80000000
294
295/*
296 * The following defines are for the flags in the host DMA destination address
297 * register.
298 */
299#define HDAR_HOST_ADDR_MASK 0xFFFFFFFF
300#define HDAR_DSP_ADDR_MASK 0x0000FFFF
301#define HDAR_MEMID_MASK 0x000F0000
302#define HDAR_MEMID_SP_DMEM0 0x00000000
303#define HDAR_MEMID_SP_DMEM1 0x00010000
304#define HDAR_MEMID_SP_PMEM 0x00020000
305#define HDAR_MEMID_SP_DEBUG 0x00030000
306#define HDAR_MEMID_OMNI_MEM 0x000E0000
307#define HDAR_END 0x40000000
308#define HDAR_ERR 0x80000000
309
310/*
311 * The following defines are for the flags in the host DMA control register.
312 */
313#define HDMR_AC_MASK 0x0000F000
314#define HDMR_AC_8_16 0x00001000
315#define HDMR_AC_M_S 0x00002000
316#define HDMR_AC_B_L 0x00004000
317#define HDMR_AC_S_U 0x00008000
318
319/*
320 * The following defines are for the flags in the host DMA control register.
321 */
322#define HDCR_COUNT_MASK 0x000003FF
323#define HDCR_DONE 0x00004000
324#define HDCR_OPT 0x00008000
325#define HDCR_WBD 0x00400000
326#define HDCR_WBS 0x00800000
327#define HDCR_DMS_MASK 0x07000000
328#define HDCR_DMS_LINEAR 0x00000000
329#define HDCR_DMS_16_DWORDS 0x01000000
330#define HDCR_DMS_32_DWORDS 0x02000000
331#define HDCR_DMS_64_DWORDS 0x03000000
332#define HDCR_DMS_128_DWORDS 0x04000000
333#define HDCR_DMS_256_DWORDS 0x05000000
334#define HDCR_DMS_512_DWORDS 0x06000000
335#define HDCR_DMS_1024_DWORDS 0x07000000
336#define HDCR_DH 0x08000000
337#define HDCR_SMS_MASK 0x70000000
338#define HDCR_SMS_LINEAR 0x00000000
339#define HDCR_SMS_16_DWORDS 0x10000000
340#define HDCR_SMS_32_DWORDS 0x20000000
341#define HDCR_SMS_64_DWORDS 0x30000000
342#define HDCR_SMS_128_DWORDS 0x40000000
343#define HDCR_SMS_256_DWORDS 0x50000000
344#define HDCR_SMS_512_DWORDS 0x60000000
345#define HDCR_SMS_1024_DWORDS 0x70000000
346#define HDCR_SH 0x80000000
347#define HDCR_COUNT_SHIFT 0
348
349/*
350 * The following defines are for the flags in the performance monitor control
351 * register.
352 */
353#define PFMC_C1SS_MASK 0x0000001F
354#define PFMC_C1EV 0x00000020
355#define PFMC_C1RS 0x00008000
356#define PFMC_C2SS_MASK 0x001F0000
357#define PFMC_C2EV 0x00200000
358#define PFMC_C2RS 0x80000000
359#define PFMC_C1SS_SHIFT 0
360#define PFMC_C2SS_SHIFT 16
361#define PFMC_BUS_GRANT 0
362#define PFMC_GRANT_AFTER_REQ 1
363#define PFMC_TRANSACTION 2
364#define PFMC_DWORD_TRANSFER 3
365#define PFMC_SLAVE_READ 4
366#define PFMC_SLAVE_WRITE 5
367#define PFMC_PREEMPTION 6
368#define PFMC_DISCONNECT_RETRY 7
369#define PFMC_INTERRUPT 8
370#define PFMC_BUS_OWNERSHIP 9
371#define PFMC_TRANSACTION_LAG 10
372#define PFMC_PCI_CLOCK 11
373#define PFMC_SERIAL_CLOCK 12
374#define PFMC_SP_CLOCK 13
375
376/*
377 * The following defines are for the flags in the performance counter value 1
378 * register.
379 */
380#define PFCV1_PC1V_MASK 0xFFFFFFFF
381#define PFCV1_PC1V_SHIFT 0
382
383/*
384 * The following defines are for the flags in the performance counter value 2
385 * register.
386 */
387#define PFCV2_PC2V_MASK 0xFFFFFFFF
388#define PFCV2_PC2V_SHIFT 0
389
390/*
391 * The following defines are for the flags in the clock control register 1.
392 */
393#define CLKCR1_OSCS 0x00000001
394#define CLKCR1_OSCP 0x00000002
395#define CLKCR1_PLLSS_MASK 0x0000000C
396#define CLKCR1_PLLSS_SERIAL 0x00000000
397#define CLKCR1_PLLSS_CRYSTAL 0x00000004
398#define CLKCR1_PLLSS_PCI 0x00000008
399#define CLKCR1_PLLSS_RESERVED 0x0000000C
400#define CLKCR1_PLLP 0x00000010
401#define CLKCR1_SWCE 0x00000020
402#define CLKCR1_PLLOS 0x00000040
403
404/*
405 * The following defines are for the flags in the clock control register 2.
406 */
407#define CLKCR2_PDIVS_MASK 0x0000000F
408#define CLKCR2_PDIVS_1 0x00000001
409#define CLKCR2_PDIVS_2 0x00000002
410#define CLKCR2_PDIVS_4 0x00000004
411#define CLKCR2_PDIVS_7 0x00000007
412#define CLKCR2_PDIVS_8 0x00000008
413#define CLKCR2_PDIVS_16 0x00000000
414
415/*
416 * The following defines are for the flags in the PLL multiplier register.
417 */
418#define PLLM_MASK 0x000000FF
419#define PLLM_SHIFT 0
420
421/*
422 * The following defines are for the flags in the PLL capacitor coefficient
423 * register.
424 */
425#define PLLCC_CDR_MASK 0x00000007
426#ifndef NO_CS4610
427#define PLLCC_CDR_240_350_MHZ 0x00000000
428#define PLLCC_CDR_184_265_MHZ 0x00000001
429#define PLLCC_CDR_144_205_MHZ 0x00000002
430#define PLLCC_CDR_111_160_MHZ 0x00000003
431#define PLLCC_CDR_87_123_MHZ 0x00000004
432#define PLLCC_CDR_67_96_MHZ 0x00000005
433#define PLLCC_CDR_52_74_MHZ 0x00000006
434#define PLLCC_CDR_45_58_MHZ 0x00000007
435#endif
436#ifndef NO_CS4612
437#define PLLCC_CDR_271_398_MHZ 0x00000000
438#define PLLCC_CDR_227_330_MHZ 0x00000001
439#define PLLCC_CDR_167_239_MHZ 0x00000002
440#define PLLCC_CDR_150_215_MHZ 0x00000003
441#define PLLCC_CDR_107_154_MHZ 0x00000004
442#define PLLCC_CDR_98_140_MHZ 0x00000005
443#define PLLCC_CDR_73_104_MHZ 0x00000006
444#define PLLCC_CDR_63_90_MHZ 0x00000007
445#endif
446#define PLLCC_LPF_MASK 0x000000F8
447#ifndef NO_CS4610
448#define PLLCC_LPF_23850_60000_KHZ 0x00000000
449#define PLLCC_LPF_7960_26290_KHZ 0x00000008
450#define PLLCC_LPF_4160_10980_KHZ 0x00000018
451#define PLLCC_LPF_1740_4580_KHZ 0x00000038
452#define PLLCC_LPF_724_1910_KHZ 0x00000078
453#define PLLCC_LPF_317_798_KHZ 0x000000F8
454#endif
455#ifndef NO_CS4612
456#define PLLCC_LPF_25580_64530_KHZ 0x00000000
457#define PLLCC_LPF_14360_37270_KHZ 0x00000008
458#define PLLCC_LPF_6100_16020_KHZ 0x00000018
459#define PLLCC_LPF_2540_6690_KHZ 0x00000038
460#define PLLCC_LPF_1050_2780_KHZ 0x00000078
461#define PLLCC_LPF_450_1160_KHZ 0x000000F8
462#endif
463
464/*
465 * The following defines are for the flags in the feature reporting register.
466 */
467#define FRR_FAB_MASK 0x00000003
468#define FRR_MASK_MASK 0x0000001C
469#ifdef NO_CS4612
470#define FRR_CFOP_MASK 0x000000E0
471#else
472#define FRR_CFOP_MASK 0x00000FE0
473#endif
474#define FRR_CFOP_NOT_DVD 0x00000020
475#define FRR_CFOP_A3D 0x00000040
476#define FRR_CFOP_128_PIN 0x00000080
477#ifndef NO_CS4612
478#define FRR_CFOP_CS4280 0x00000800
479#endif
480#define FRR_FAB_SHIFT 0
481#define FRR_MASK_SHIFT 2
482#define FRR_CFOP_SHIFT 5
483
484/*
485 * The following defines are for the flags in the configuration load 1
486 * register.
487 */
488#define CFL1_CLOCK_SOURCE_MASK 0x00000003
489#define CFL1_CLOCK_SOURCE_CS423X 0x00000000
490#define CFL1_CLOCK_SOURCE_AC97 0x00000001
491#define CFL1_CLOCK_SOURCE_CRYSTAL 0x00000002
492#define CFL1_CLOCK_SOURCE_DUAL_AC97 0x00000003
493#define CFL1_VALID_DATA_MASK 0x000000FF
494
495/*
496 * The following defines are for the flags in the configuration load 2
497 * register.
498 */
499#define CFL2_VALID_DATA_MASK 0x000000FF
500
501/*
502 * The following defines are for the flags in the serial port master control
503 * register 1.
504 */
505#define SERMC1_MSPE 0x00000001
506#define SERMC1_PTC_MASK 0x0000000E
507#define SERMC1_PTC_CS423X 0x00000000
508#define SERMC1_PTC_AC97 0x00000002
509#define SERMC1_PTC_DAC 0x00000004
510#define SERMC1_PLB 0x00000010
511#define SERMC1_XLB 0x00000020
512
513/*
514 * The following defines are for the flags in the serial port master control
515 * register 2.
516 */
517#define SERMC2_LROE 0x00000001
518#define SERMC2_MCOE 0x00000002
519#define SERMC2_MCDIV 0x00000004
520
521/*
522 * The following defines are for the flags in the serial port 1 configuration
523 * register.
524 */
525#define SERC1_SO1EN 0x00000001
526#define SERC1_SO1F_MASK 0x0000000E
527#define SERC1_SO1F_CS423X 0x00000000
528#define SERC1_SO1F_AC97 0x00000002
529#define SERC1_SO1F_DAC 0x00000004
530#define SERC1_SO1F_SPDIF 0x00000006
531
532/*
533 * The following defines are for the flags in the serial port 2 configuration
534 * register.
535 */
536#define SERC2_SI1EN 0x00000001
537#define SERC2_SI1F_MASK 0x0000000E
538#define SERC2_SI1F_CS423X 0x00000000
539#define SERC2_SI1F_AC97 0x00000002
540#define SERC2_SI1F_ADC 0x00000004
541#define SERC2_SI1F_SPDIF 0x00000006
542
543/*
544 * The following defines are for the flags in the serial port 3 configuration
545 * register.
546 */
547#define SERC3_SO2EN 0x00000001
548#define SERC3_SO2F_MASK 0x00000006
549#define SERC3_SO2F_DAC 0x00000000
550#define SERC3_SO2F_SPDIF 0x00000002
551
552/*
553 * The following defines are for the flags in the serial port 4 configuration
554 * register.
555 */
556#define SERC4_SO3EN 0x00000001
557#define SERC4_SO3F_MASK 0x00000006
558#define SERC4_SO3F_DAC 0x00000000
559#define SERC4_SO3F_SPDIF 0x00000002
560
561/*
562 * The following defines are for the flags in the serial port 5 configuration
563 * register.
564 */
565#define SERC5_SI2EN 0x00000001
566#define SERC5_SI2F_MASK 0x00000006
567#define SERC5_SI2F_ADC 0x00000000
568#define SERC5_SI2F_SPDIF 0x00000002
569
570/*
571 * The following defines are for the flags in the serial port backdoor sample
572 * pointer register.
573 */
574#define SERBSP_FSP_MASK 0x0000000F
575#define SERBSP_FSP_SHIFT 0
576
577/*
578 * The following defines are for the flags in the serial port backdoor status
579 * register.
580 */
581#define SERBST_RRDY 0x00000001
582#define SERBST_WBSY 0x00000002
583
584/*
585 * The following defines are for the flags in the serial port backdoor command
586 * register.
587 */
588#define SERBCM_RDC 0x00000001
589#define SERBCM_WRC 0x00000002
590
591/*
592 * The following defines are for the flags in the serial port backdoor address
593 * register.
594 */
595#ifdef NO_CS4612
596#define SERBAD_FAD_MASK 0x000000FF
597#else
598#define SERBAD_FAD_MASK 0x000001FF
599#endif
600#define SERBAD_FAD_SHIFT 0
601
602/*
603 * The following defines are for the flags in the serial port backdoor
604 * configuration register.
605 */
606#define SERBCF_HBP 0x00000001
607
608/*
609 * The following defines are for the flags in the serial port backdoor write
610 * port register.
611 */
612#define SERBWP_FWD_MASK 0x000FFFFF
613#define SERBWP_FWD_SHIFT 0
614
615/*
616 * The following defines are for the flags in the serial port backdoor read
617 * port register.
618 */
619#define SERBRP_FRD_MASK 0x000FFFFF
620#define SERBRP_FRD_SHIFT 0
621
622/*
623 * The following defines are for the flags in the async FIFO address register.
624 */
625#ifndef NO_CS4612
626#define ASER_FADDR_A1_MASK 0x000001FF
627#define ASER_FADDR_EN1 0x00008000
628#define ASER_FADDR_A2_MASK 0x01FF0000
629#define ASER_FADDR_EN2 0x80000000
630#define ASER_FADDR_A1_SHIFT 0
631#define ASER_FADDR_A2_SHIFT 16
632#endif
633
634/*
635 * The following defines are for the flags in the AC97 control register.
636 */
637#define ACCTL_RSTN 0x00000001
638#define ACCTL_ESYN 0x00000002
639#define ACCTL_VFRM 0x00000004
640#define ACCTL_DCV 0x00000008
641#define ACCTL_CRW 0x00000010
642#define ACCTL_ASYN 0x00000020
643#ifndef NO_CS4612
644#define ACCTL_TC 0x00000040
645#endif
646
647/*
648 * The following defines are for the flags in the AC97 status register.
649 */
650#define ACSTS_CRDY 0x00000001
651#define ACSTS_VSTS 0x00000002
652#ifndef NO_CS4612
653#define ACSTS_WKUP 0x00000004
654#endif
655
656/*
657 * The following defines are for the flags in the AC97 output slot valid
658 * register.
659 */
660#define ACOSV_SLV3 0x00000001
661#define ACOSV_SLV4 0x00000002
662#define ACOSV_SLV5 0x00000004
663#define ACOSV_SLV6 0x00000008
664#define ACOSV_SLV7 0x00000010
665#define ACOSV_SLV8 0x00000020
666#define ACOSV_SLV9 0x00000040
667#define ACOSV_SLV10 0x00000080
668#define ACOSV_SLV11 0x00000100
669#define ACOSV_SLV12 0x00000200
670
671/*
672 * The following defines are for the flags in the AC97 command address
673 * register.
674 */
675#define ACCAD_CI_MASK 0x0000007F
676#define ACCAD_CI_SHIFT 0
677
678/*
679 * The following defines are for the flags in the AC97 command data register.
680 */
681#define ACCDA_CD_MASK 0x0000FFFF
682#define ACCDA_CD_SHIFT 0
683
684/*
685 * The following defines are for the flags in the AC97 input slot valid
686 * register.
687 */
688#define ACISV_ISV3 0x00000001
689#define ACISV_ISV4 0x00000002
690#define ACISV_ISV5 0x00000004
691#define ACISV_ISV6 0x00000008
692#define ACISV_ISV7 0x00000010
693#define ACISV_ISV8 0x00000020
694#define ACISV_ISV9 0x00000040
695#define ACISV_ISV10 0x00000080
696#define ACISV_ISV11 0x00000100
697#define ACISV_ISV12 0x00000200
698
699/*
700 * The following defines are for the flags in the AC97 status address
701 * register.
702 */
703#define ACSAD_SI_MASK 0x0000007F
704#define ACSAD_SI_SHIFT 0
705
706/*
707 * The following defines are for the flags in the AC97 status data register.
708 */
709#define ACSDA_SD_MASK 0x0000FFFF
710#define ACSDA_SD_SHIFT 0
711
712/*
713 * The following defines are for the flags in the joystick poll/trigger
714 * register.
715 */
716#define JSPT_CAX 0x00000001
717#define JSPT_CAY 0x00000002
718#define JSPT_CBX 0x00000004
719#define JSPT_CBY 0x00000008
720#define JSPT_BA1 0x00000010
721#define JSPT_BA2 0x00000020
722#define JSPT_BB1 0x00000040
723#define JSPT_BB2 0x00000080
724
725/*
726 * The following defines are for the flags in the joystick control register.
727 */
728#define JSCTL_SP_MASK 0x00000003
729#define JSCTL_SP_SLOW 0x00000000
730#define JSCTL_SP_MEDIUM_SLOW 0x00000001
731#define JSCTL_SP_MEDIUM_FAST 0x00000002
732#define JSCTL_SP_FAST 0x00000003
733#define JSCTL_ARE 0x00000004
734
735/*
736 * The following defines are for the flags in the joystick coordinate pair 1
737 * readback register.
738 */
739#define JSC1_Y1V_MASK 0x0000FFFF
740#define JSC1_X1V_MASK 0xFFFF0000
741#define JSC1_Y1V_SHIFT 0
742#define JSC1_X1V_SHIFT 16
743
744/*
745 * The following defines are for the flags in the joystick coordinate pair 2
746 * readback register.
747 */
748#define JSC2_Y2V_MASK 0x0000FFFF
749#define JSC2_X2V_MASK 0xFFFF0000
750#define JSC2_Y2V_SHIFT 0
751#define JSC2_X2V_SHIFT 16
752
753/*
754 * The following defines are for the flags in the MIDI control register.
755 */
756#define MIDCR_TXE 0x00000001 /* Enable transmitting. */
757#define MIDCR_RXE 0x00000002 /* Enable receiving. */
758#define MIDCR_RIE 0x00000004 /* Interrupt upon tx ready. */
759#define MIDCR_TIE 0x00000008 /* Interrupt upon rx ready. */
760#define MIDCR_MLB 0x00000010 /* Enable midi loopback. */
761#define MIDCR_MRST 0x00000020 /* Reset interface. */
762
763/*
764 * The following defines are for the flags in the MIDI status register.
765 */
766#define MIDSR_TBF 0x00000001 /* Tx FIFO is full. */
767#define MIDSR_RBE 0x00000002 /* Rx FIFO is empty. */
768
769/*
770 * The following defines are for the flags in the MIDI write port register.
771 */
772#define MIDWP_MWD_MASK 0x000000FF
773#define MIDWP_MWD_SHIFT 0
774
775/*
776 * The following defines are for the flags in the MIDI read port register.
777 */
778#define MIDRP_MRD_MASK 0x000000FF
779#define MIDRP_MRD_SHIFT 0
780
781/*
782 * The following defines are for the flags in the joystick GPIO register.
783 */
784#define JSIO_DAX 0x00000001
785#define JSIO_DAY 0x00000002
786#define JSIO_DBX 0x00000004
787#define JSIO_DBY 0x00000008
788#define JSIO_AXOE 0x00000010
789#define JSIO_AYOE 0x00000020
790#define JSIO_BXOE 0x00000040
791#define JSIO_BYOE 0x00000080
792
793/*
794 * The following defines are for the flags in the master async/sync serial
795 * port enable register.
796 */
797#ifndef NO_CS4612
798#define ASER_MASTER_ME 0x00000001
799#endif
800
801/*
802 * The following defines are for the flags in the configuration interface
803 * register.
804 */
805#define CFGI_CLK 0x00000001
806#define CFGI_DOUT 0x00000002
807#define CFGI_DIN_EEN 0x00000004
808#define CFGI_EELD 0x00000008
809
810/*
811 * The following defines are for the flags in the subsystem ID and vendor ID
812 * register.
813 */
814#define SSVID_VID_MASK 0x0000FFFF
815#define SSVID_SID_MASK 0xFFFF0000
816#define SSVID_VID_SHIFT 0
817#define SSVID_SID_SHIFT 16
818
819/*
820 * The following defines are for the flags in the GPIO pin interface register.
821 */
822#define GPIOR_VOLDN 0x00000001
823#define GPIOR_VOLUP 0x00000002
824#define GPIOR_SI2D 0x00000004
825#define GPIOR_SI2OE 0x00000008
826
827/*
828 * The following defines are for the flags in the extended GPIO pin direction
829 * register.
830 */
831#ifndef NO_CS4612
832#define EGPIODR_GPOE0 0x00000001
833#define EGPIODR_GPOE1 0x00000002
834#define EGPIODR_GPOE2 0x00000004
835#define EGPIODR_GPOE3 0x00000008
836#define EGPIODR_GPOE4 0x00000010
837#define EGPIODR_GPOE5 0x00000020
838#define EGPIODR_GPOE6 0x00000040
839#define EGPIODR_GPOE7 0x00000080
840#define EGPIODR_GPOE8 0x00000100
841#endif
842
843/*
844 * The following defines are for the flags in the extended GPIO pin polarity/
845 * type register.
846 */
847#ifndef NO_CS4612
848#define EGPIOPTR_GPPT0 0x00000001
849#define EGPIOPTR_GPPT1 0x00000002
850#define EGPIOPTR_GPPT2 0x00000004
851#define EGPIOPTR_GPPT3 0x00000008
852#define EGPIOPTR_GPPT4 0x00000010
853#define EGPIOPTR_GPPT5 0x00000020
854#define EGPIOPTR_GPPT6 0x00000040
855#define EGPIOPTR_GPPT7 0x00000080
856#define EGPIOPTR_GPPT8 0x00000100
857#endif
858
859/*
860 * The following defines are for the flags in the extended GPIO pin sticky
861 * register.
862 */
863#ifndef NO_CS4612
864#define EGPIOTR_GPS0 0x00000001
865#define EGPIOTR_GPS1 0x00000002
866#define EGPIOTR_GPS2 0x00000004
867#define EGPIOTR_GPS3 0x00000008
868#define EGPIOTR_GPS4 0x00000010
869#define EGPIOTR_GPS5 0x00000020
870#define EGPIOTR_GPS6 0x00000040
871#define EGPIOTR_GPS7 0x00000080
872#define EGPIOTR_GPS8 0x00000100
873#endif
874
875/*
876 * The following defines are for the flags in the extended GPIO ping wakeup
877 * register.
878 */
879#ifndef NO_CS4612
880#define EGPIOWR_GPW0 0x00000001
881#define EGPIOWR_GPW1 0x00000002
882#define EGPIOWR_GPW2 0x00000004
883#define EGPIOWR_GPW3 0x00000008
884#define EGPIOWR_GPW4 0x00000010
885#define EGPIOWR_GPW5 0x00000020
886#define EGPIOWR_GPW6 0x00000040
887#define EGPIOWR_GPW7 0x00000080
888#define EGPIOWR_GPW8 0x00000100
889#endif
890
891/*
892 * The following defines are for the flags in the extended GPIO pin status
893 * register.
894 */
895#ifndef NO_CS4612
896#define EGPIOSR_GPS0 0x00000001
897#define EGPIOSR_GPS1 0x00000002
898#define EGPIOSR_GPS2 0x00000004
899#define EGPIOSR_GPS3 0x00000008
900#define EGPIOSR_GPS4 0x00000010
901#define EGPIOSR_GPS5 0x00000020
902#define EGPIOSR_GPS6 0x00000040
903#define EGPIOSR_GPS7 0x00000080
904#define EGPIOSR_GPS8 0x00000100
905#endif
906
907/*
908 * The following defines are for the flags in the serial port 6 configuration
909 * register.
910 */
911#ifndef NO_CS4612
912#define SERC6_ASDO2EN 0x00000001
913#endif
914
915/*
916 * The following defines are for the flags in the serial port 7 configuration
917 * register.
918 */
919#ifndef NO_CS4612
920#define SERC7_ASDI2EN 0x00000001
921#define SERC7_POSILB 0x00000002
922#define SERC7_SIPOLB 0x00000004
923#define SERC7_SOSILB 0x00000008
924#define SERC7_SISOLB 0x00000010
925#endif
926
927/*
928 * The following defines are for the flags in the serial port AC link
929 * configuration register.
930 */
931#ifndef NO_CS4612
932#define SERACC_CODEC_TYPE_MASK 0x00000001
933#define SERACC_CODEC_TYPE_1_03 0x00000000
934#define SERACC_CODEC_TYPE_2_0 0x00000001
935#define SERACC_TWO_CODECS 0x00000002
936#define SERACC_MDM 0x00000004
937#define SERACC_HSP 0x00000008
938#endif
939
940/*
941 * The following defines are for the flags in the AC97 control register 2.
942 */
943#ifndef NO_CS4612
944#define ACCTL2_RSTN 0x00000001
945#define ACCTL2_ESYN 0x00000002
946#define ACCTL2_VFRM 0x00000004
947#define ACCTL2_DCV 0x00000008
948#define ACCTL2_CRW 0x00000010
949#define ACCTL2_ASYN 0x00000020
950#endif
951
952/*
953 * The following defines are for the flags in the AC97 status register 2.
954 */
955#ifndef NO_CS4612
956#define ACSTS2_CRDY 0x00000001
957#define ACSTS2_VSTS 0x00000002
958#endif
959
960/*
961 * The following defines are for the flags in the AC97 output slot valid
962 * register 2.
963 */
964#ifndef NO_CS4612
965#define ACOSV2_SLV3 0x00000001
966#define ACOSV2_SLV4 0x00000002
967#define ACOSV2_SLV5 0x00000004
968#define ACOSV2_SLV6 0x00000008
969#define ACOSV2_SLV7 0x00000010
970#define ACOSV2_SLV8 0x00000020
971#define ACOSV2_SLV9 0x00000040
972#define ACOSV2_SLV10 0x00000080
973#define ACOSV2_SLV11 0x00000100
974#define ACOSV2_SLV12 0x00000200
975#endif
976
977/*
978 * The following defines are for the flags in the AC97 command address
979 * register 2.
980 */
981#ifndef NO_CS4612
982#define ACCAD2_CI_MASK 0x0000007F
983#define ACCAD2_CI_SHIFT 0
984#endif
985
986/*
987 * The following defines are for the flags in the AC97 command data register
988 * 2.
989 */
990#ifndef NO_CS4612
991#define ACCDA2_CD_MASK 0x0000FFFF
992#define ACCDA2_CD_SHIFT 0
993#endif
994
995/*
996 * The following defines are for the flags in the AC97 input slot valid
997 * register 2.
998 */
999#ifndef NO_CS4612
1000#define ACISV2_ISV3 0x00000001
1001#define ACISV2_ISV4 0x00000002
1002#define ACISV2_ISV5 0x00000004
1003#define ACISV2_ISV6 0x00000008
1004#define ACISV2_ISV7 0x00000010
1005#define ACISV2_ISV8 0x00000020
1006#define ACISV2_ISV9 0x00000040
1007#define ACISV2_ISV10 0x00000080
1008#define ACISV2_ISV11 0x00000100
1009#define ACISV2_ISV12 0x00000200
1010#endif
1011
1012/*
1013 * The following defines are for the flags in the AC97 status address
1014 * register 2.
1015 */
1016#ifndef NO_CS4612
1017#define ACSAD2_SI_MASK 0x0000007F
1018#define ACSAD2_SI_SHIFT 0
1019#endif
1020
1021/*
1022 * The following defines are for the flags in the AC97 status data register 2.
1023 */
1024#ifndef NO_CS4612
1025#define ACSDA2_SD_MASK 0x0000FFFF
1026#define ACSDA2_SD_SHIFT 0
1027#endif
1028
1029/*
1030 * The following defines are for the flags in the I/O trap address and control
1031 * registers (all 12).
1032 */
1033#ifndef NO_CS4612
1034#define IOTAC_SA_MASK 0x0000FFFF
1035#define IOTAC_MSK_MASK 0x000F0000
1036#define IOTAC_IODC_MASK 0x06000000
1037#define IOTAC_IODC_16_BIT 0x00000000
1038#define IOTAC_IODC_10_BIT 0x02000000
1039#define IOTAC_IODC_12_BIT 0x04000000
1040#define IOTAC_WSPI 0x08000000
1041#define IOTAC_RSPI 0x10000000
1042#define IOTAC_WSE 0x20000000
1043#define IOTAC_WE 0x40000000
1044#define IOTAC_RE 0x80000000
1045#define IOTAC_SA_SHIFT 0
1046#define IOTAC_MSK_SHIFT 16
1047#endif
1048
1049/*
1050 * The following defines are for the flags in the I/O trap fast read registers
1051 * (all 8).
1052 */
1053#ifndef NO_CS4612
1054#define IOTFR_D_MASK 0x0000FFFF
1055#define IOTFR_A_MASK 0x000F0000
1056#define IOTFR_R_MASK 0x0F000000
1057#define IOTFR_ALL 0x40000000
1058#define IOTFR_VL 0x80000000
1059#define IOTFR_D_SHIFT 0
1060#define IOTFR_A_SHIFT 16
1061#define IOTFR_R_SHIFT 24
1062#endif
1063
1064/*
1065 * The following defines are for the flags in the I/O trap FIFO register.
1066 */
1067#ifndef NO_CS4612
1068#define IOTFIFO_BA_MASK 0x00003FFF
1069#define IOTFIFO_S_MASK 0x00FF0000
1070#define IOTFIFO_OF 0x40000000
1071#define IOTFIFO_SPIOF 0x80000000
1072#define IOTFIFO_BA_SHIFT 0
1073#define IOTFIFO_S_SHIFT 16
1074#endif
1075
1076/*
1077 * The following defines are for the flags in the I/O trap retry read data
1078 * register.
1079 */
1080#ifndef NO_CS4612
1081#define IOTRRD_D_MASK 0x0000FFFF
1082#define IOTRRD_RDV 0x80000000
1083#define IOTRRD_D_SHIFT 0
1084#endif
1085
1086/*
1087 * The following defines are for the flags in the I/O trap FIFO pointer
1088 * register.
1089 */
1090#ifndef NO_CS4612
1091#define IOTFP_CA_MASK 0x00003FFF
1092#define IOTFP_PA_MASK 0x3FFF0000
1093#define IOTFP_CA_SHIFT 0
1094#define IOTFP_PA_SHIFT 16
1095#endif
1096
1097/*
1098 * The following defines are for the flags in the I/O trap control register.
1099 */
1100#ifndef NO_CS4612
1101#define IOTCR_ITD 0x00000001
1102#define IOTCR_HRV 0x00000002
1103#define IOTCR_SRV 0x00000004
1104#define IOTCR_DTI 0x00000008
1105#define IOTCR_DFI 0x00000010
1106#define IOTCR_DDP 0x00000020
1107#define IOTCR_JTE 0x00000040
1108#define IOTCR_PPE 0x00000080
1109#endif
1110
1111/*
1112 * The following defines are for the flags in the direct PCI data register.
1113 */
1114#ifndef NO_CS4612
1115#define DPCID_D_MASK 0xFFFFFFFF
1116#define DPCID_D_SHIFT 0
1117#endif
1118
1119/*
1120 * The following defines are for the flags in the direct PCI address register.
1121 */
1122#ifndef NO_CS4612
1123#define DPCIA_A_MASK 0xFFFFFFFF
1124#define DPCIA_A_SHIFT 0
1125#endif
1126
1127/*
1128 * The following defines are for the flags in the direct PCI command register.
1129 */
1130#ifndef NO_CS4612
1131#define DPCIC_C_MASK 0x0000000F
1132#define DPCIC_C_IOREAD 0x00000002
1133#define DPCIC_C_IOWRITE 0x00000003
1134#define DPCIC_BE_MASK 0x000000F0
1135#endif
1136
1137/*
1138 * The following defines are for the flags in the PC/PCI request register.
1139 */
1140#ifndef NO_CS4612
1141#define PCPCIR_RDC_MASK 0x00000007
1142#define PCPCIR_C_MASK 0x00007000
1143#define PCPCIR_REQ 0x00008000
1144#define PCPCIR_RDC_SHIFT 0
1145#define PCPCIR_C_SHIFT 12
1146#endif
1147
1148/*
1149 * The following defines are for the flags in the PC/PCI grant register.
1150 */
1151#ifndef NO_CS4612
1152#define PCPCIG_GDC_MASK 0x00000007
1153#define PCPCIG_VL 0x00008000
1154#define PCPCIG_GDC_SHIFT 0
1155#endif
1156
1157/*
1158 * The following defines are for the flags in the PC/PCI master enable
1159 * register.
1160 */
1161#ifndef NO_CS4612
1162#define PCPCIEN_EN 0x00000001
1163#endif
1164
1165/*
1166 * The following defines are for the flags in the extended PCI power
1167 * management control register.
1168 */
1169#ifndef NO_CS4612
1170#define EPCIPMC_GWU 0x00000001
1171#define EPCIPMC_FSPC 0x00000002
1172#endif
1173
1174/*
1175 * The following defines are for the flags in the SP control register.
1176 */
1177#define SPCR_RUN 0x00000001
1178#define SPCR_STPFR 0x00000002
1179#define SPCR_RUNFR 0x00000004
1180#define SPCR_TICK 0x00000008
1181#define SPCR_DRQEN 0x00000020
1182#define SPCR_RSTSP 0x00000040
1183#define SPCR_OREN 0x00000080
1184#ifndef NO_CS4612
1185#define SPCR_PCIINT 0x00000100
1186#define SPCR_OINTD 0x00000200
1187#define SPCR_CRE 0x00008000
1188#endif
1189
1190/*
1191 * The following defines are for the flags in the debug index register.
1192 */
1193#define DREG_REGID_MASK 0x0000007F
1194#define DREG_DEBUG 0x00000080
1195#define DREG_RGBK_MASK 0x00000700
1196#define DREG_TRAP 0x00000800
1197#if !defined(NO_CS4612)
1198#if !defined(NO_CS4615)
1199#define DREG_TRAPX 0x00001000
1200#endif
1201#endif
1202#define DREG_REGID_SHIFT 0
1203#define DREG_RGBK_SHIFT 8
1204#define DREG_RGBK_REGID_MASK 0x0000077F
1205#define DREG_REGID_R0 0x00000010
1206#define DREG_REGID_R1 0x00000011
1207#define DREG_REGID_R2 0x00000012
1208#define DREG_REGID_R3 0x00000013
1209#define DREG_REGID_R4 0x00000014
1210#define DREG_REGID_R5 0x00000015
1211#define DREG_REGID_R6 0x00000016
1212#define DREG_REGID_R7 0x00000017
1213#define DREG_REGID_R8 0x00000018
1214#define DREG_REGID_R9 0x00000019
1215#define DREG_REGID_RA 0x0000001A
1216#define DREG_REGID_RB 0x0000001B
1217#define DREG_REGID_RC 0x0000001C
1218#define DREG_REGID_RD 0x0000001D
1219#define DREG_REGID_RE 0x0000001E
1220#define DREG_REGID_RF 0x0000001F
1221#define DREG_REGID_RA_BUS_LOW 0x00000020
1222#define DREG_REGID_RA_BUS_HIGH 0x00000038
1223#define DREG_REGID_YBUS_LOW 0x00000050
1224#define DREG_REGID_YBUS_HIGH 0x00000058
1225#define DREG_REGID_TRAP_0 0x00000100
1226#define DREG_REGID_TRAP_1 0x00000101
1227#define DREG_REGID_TRAP_2 0x00000102
1228#define DREG_REGID_TRAP_3 0x00000103
1229#define DREG_REGID_TRAP_4 0x00000104
1230#define DREG_REGID_TRAP_5 0x00000105
1231#define DREG_REGID_TRAP_6 0x00000106
1232#define DREG_REGID_TRAP_7 0x00000107
1233#define DREG_REGID_INDIRECT_ADDRESS 0x0000010E
1234#define DREG_REGID_TOP_OF_STACK 0x0000010F
1235#if !defined(NO_CS4612)
1236#if !defined(NO_CS4615)
1237#define DREG_REGID_TRAP_8 0x00000110
1238#define DREG_REGID_TRAP_9 0x00000111
1239#define DREG_REGID_TRAP_10 0x00000112
1240#define DREG_REGID_TRAP_11 0x00000113
1241#define DREG_REGID_TRAP_12 0x00000114
1242#define DREG_REGID_TRAP_13 0x00000115
1243#define DREG_REGID_TRAP_14 0x00000116
1244#define DREG_REGID_TRAP_15 0x00000117
1245#define DREG_REGID_TRAP_16 0x00000118
1246#define DREG_REGID_TRAP_17 0x00000119
1247#define DREG_REGID_TRAP_18 0x0000011A
1248#define DREG_REGID_TRAP_19 0x0000011B
1249#define DREG_REGID_TRAP_20 0x0000011C
1250#define DREG_REGID_TRAP_21 0x0000011D
1251#define DREG_REGID_TRAP_22 0x0000011E
1252#define DREG_REGID_TRAP_23 0x0000011F
1253#endif
1254#endif
1255#define DREG_REGID_RSA0_LOW 0x00000200
1256#define DREG_REGID_RSA0_HIGH 0x00000201
1257#define DREG_REGID_RSA1_LOW 0x00000202
1258#define DREG_REGID_RSA1_HIGH 0x00000203
1259#define DREG_REGID_RSA2 0x00000204
1260#define DREG_REGID_RSA3 0x00000205
1261#define DREG_REGID_RSI0_LOW 0x00000206
1262#define DREG_REGID_RSI0_HIGH 0x00000207
1263#define DREG_REGID_RSI1 0x00000208
1264#define DREG_REGID_RSI2 0x00000209
1265#define DREG_REGID_SAGUSTATUS 0x0000020A
1266#define DREG_REGID_RSCONFIG01_LOW 0x0000020B
1267#define DREG_REGID_RSCONFIG01_HIGH 0x0000020C
1268#define DREG_REGID_RSCONFIG23_LOW 0x0000020D
1269#define DREG_REGID_RSCONFIG23_HIGH 0x0000020E
1270#define DREG_REGID_RSDMA01E 0x0000020F
1271#define DREG_REGID_RSDMA23E 0x00000210
1272#define DREG_REGID_RSD0_LOW 0x00000211
1273#define DREG_REGID_RSD0_HIGH 0x00000212
1274#define DREG_REGID_RSD1_LOW 0x00000213
1275#define DREG_REGID_RSD1_HIGH 0x00000214
1276#define DREG_REGID_RSD2_LOW 0x00000215
1277#define DREG_REGID_RSD2_HIGH 0x00000216
1278#define DREG_REGID_RSD3_LOW 0x00000217
1279#define DREG_REGID_RSD3_HIGH 0x00000218
1280#define DREG_REGID_SRAR_HIGH 0x0000021A
1281#define DREG_REGID_SRAR_LOW 0x0000021B
1282#define DREG_REGID_DMA_STATE 0x0000021C
1283#define DREG_REGID_CURRENT_DMA_STREAM 0x0000021D
1284#define DREG_REGID_NEXT_DMA_STREAM 0x0000021E
1285#define DREG_REGID_CPU_STATUS 0x00000300
1286#define DREG_REGID_MAC_MODE 0x00000301
1287#define DREG_REGID_STACK_AND_REPEAT 0x00000302
1288#define DREG_REGID_INDEX0 0x00000304
1289#define DREG_REGID_INDEX1 0x00000305
1290#define DREG_REGID_DMA_STATE_0_3 0x00000400
1291#define DREG_REGID_DMA_STATE_4_7 0x00000404
1292#define DREG_REGID_DMA_STATE_8_11 0x00000408
1293#define DREG_REGID_DMA_STATE_12_15 0x0000040C
1294#define DREG_REGID_DMA_STATE_16_19 0x00000410
1295#define DREG_REGID_DMA_STATE_20_23 0x00000414
1296#define DREG_REGID_DMA_STATE_24_27 0x00000418
1297#define DREG_REGID_DMA_STATE_28_31 0x0000041C
1298#define DREG_REGID_DMA_STATE_32_35 0x00000420
1299#define DREG_REGID_DMA_STATE_36_39 0x00000424
1300#define DREG_REGID_DMA_STATE_40_43 0x00000428
1301#define DREG_REGID_DMA_STATE_44_47 0x0000042C
1302#define DREG_REGID_DMA_STATE_48_51 0x00000430
1303#define DREG_REGID_DMA_STATE_52_55 0x00000434
1304#define DREG_REGID_DMA_STATE_56_59 0x00000438
1305#define DREG_REGID_DMA_STATE_60_63 0x0000043C
1306#define DREG_REGID_DMA_STATE_64_67 0x00000440
1307#define DREG_REGID_DMA_STATE_68_71 0x00000444
1308#define DREG_REGID_DMA_STATE_72_75 0x00000448
1309#define DREG_REGID_DMA_STATE_76_79 0x0000044C
1310#define DREG_REGID_DMA_STATE_80_83 0x00000450
1311#define DREG_REGID_DMA_STATE_84_87 0x00000454
1312#define DREG_REGID_DMA_STATE_88_91 0x00000458
1313#define DREG_REGID_DMA_STATE_92_95 0x0000045C
1314#define DREG_REGID_TRAP_SELECT 0x00000500
1315#define DREG_REGID_TRAP_WRITE_0 0x00000500
1316#define DREG_REGID_TRAP_WRITE_1 0x00000501
1317#define DREG_REGID_TRAP_WRITE_2 0x00000502
1318#define DREG_REGID_TRAP_WRITE_3 0x00000503
1319#define DREG_REGID_TRAP_WRITE_4 0x00000504
1320#define DREG_REGID_TRAP_WRITE_5 0x00000505
1321#define DREG_REGID_TRAP_WRITE_6 0x00000506
1322#define DREG_REGID_TRAP_WRITE_7 0x00000507
1323#if !defined(NO_CS4612)
1324#if !defined(NO_CS4615)
1325#define DREG_REGID_TRAP_WRITE_8 0x00000510
1326#define DREG_REGID_TRAP_WRITE_9 0x00000511
1327#define DREG_REGID_TRAP_WRITE_10 0x00000512
1328#define DREG_REGID_TRAP_WRITE_11 0x00000513
1329#define DREG_REGID_TRAP_WRITE_12 0x00000514
1330#define DREG_REGID_TRAP_WRITE_13 0x00000515
1331#define DREG_REGID_TRAP_WRITE_14 0x00000516
1332#define DREG_REGID_TRAP_WRITE_15 0x00000517
1333#define DREG_REGID_TRAP_WRITE_16 0x00000518
1334#define DREG_REGID_TRAP_WRITE_17 0x00000519
1335#define DREG_REGID_TRAP_WRITE_18 0x0000051A
1336#define DREG_REGID_TRAP_WRITE_19 0x0000051B
1337#define DREG_REGID_TRAP_WRITE_20 0x0000051C
1338#define DREG_REGID_TRAP_WRITE_21 0x0000051D
1339#define DREG_REGID_TRAP_WRITE_22 0x0000051E
1340#define DREG_REGID_TRAP_WRITE_23 0x0000051F
1341#endif
1342#endif
1343#define DREG_REGID_MAC0_ACC0_LOW 0x00000600
1344#define DREG_REGID_MAC0_ACC1_LOW 0x00000601
1345#define DREG_REGID_MAC0_ACC2_LOW 0x00000602
1346#define DREG_REGID_MAC0_ACC3_LOW 0x00000603
1347#define DREG_REGID_MAC1_ACC0_LOW 0x00000604
1348#define DREG_REGID_MAC1_ACC1_LOW 0x00000605
1349#define DREG_REGID_MAC1_ACC2_LOW 0x00000606
1350#define DREG_REGID_MAC1_ACC3_LOW 0x00000607
1351#define DREG_REGID_MAC0_ACC0_MID 0x00000608
1352#define DREG_REGID_MAC0_ACC1_MID 0x00000609
1353#define DREG_REGID_MAC0_ACC2_MID 0x0000060A
1354#define DREG_REGID_MAC0_ACC3_MID 0x0000060B
1355#define DREG_REGID_MAC1_ACC0_MID 0x0000060C
1356#define DREG_REGID_MAC1_ACC1_MID 0x0000060D
1357#define DREG_REGID_MAC1_ACC2_MID 0x0000060E
1358#define DREG_REGID_MAC1_ACC3_MID 0x0000060F
1359#define DREG_REGID_MAC0_ACC0_HIGH 0x00000610
1360#define DREG_REGID_MAC0_ACC1_HIGH 0x00000611
1361#define DREG_REGID_MAC0_ACC2_HIGH 0x00000612
1362#define DREG_REGID_MAC0_ACC3_HIGH 0x00000613
1363#define DREG_REGID_MAC1_ACC0_HIGH 0x00000614
1364#define DREG_REGID_MAC1_ACC1_HIGH 0x00000615
1365#define DREG_REGID_MAC1_ACC2_HIGH 0x00000616
1366#define DREG_REGID_MAC1_ACC3_HIGH 0x00000617
1367#define DREG_REGID_RSHOUT_LOW 0x00000620
1368#define DREG_REGID_RSHOUT_MID 0x00000628
1369#define DREG_REGID_RSHOUT_HIGH 0x00000630
1370
1371/*
1372 * The following defines are for the flags in the DMA stream requestor write
1373 */
1374#define DSRWP_DSR_MASK 0x0000000F
1375#define DSRWP_DSR_BG_RQ 0x00000001
1376#define DSRWP_DSR_PRIORITY_MASK 0x00000006
1377#define DSRWP_DSR_PRIORITY_0 0x00000000
1378#define DSRWP_DSR_PRIORITY_1 0x00000002
1379#define DSRWP_DSR_PRIORITY_2 0x00000004
1380#define DSRWP_DSR_PRIORITY_3 0x00000006
1381#define DSRWP_DSR_RQ_PENDING 0x00000008
1382
1383/*
1384 * The following defines are for the flags in the trap write port register.
1385 */
1386#define TWPR_TW_MASK 0x0000FFFF
1387#define TWPR_TW_SHIFT 0
1388
1389/*
1390 * The following defines are for the flags in the stack pointer write
1391 * register.
1392 */
1393#define SPWR_STKP_MASK 0x0000000F
1394#define SPWR_STKP_SHIFT 0
1395
1396/*
1397 * The following defines are for the flags in the SP interrupt register.
1398 */
1399#define SPIR_FRI 0x00000001
1400#define SPIR_DOI 0x00000002
1401#define SPIR_GPI2 0x00000004
1402#define SPIR_GPI3 0x00000008
1403#define SPIR_IP0 0x00000010
1404#define SPIR_IP1 0x00000020
1405#define SPIR_IP2 0x00000040
1406#define SPIR_IP3 0x00000080
1407
1408/*
1409 * The following defines are for the flags in the functional group 1 register.
1410 */
1411#define FGR1_F1S_MASK 0x0000FFFF
1412#define FGR1_F1S_SHIFT 0
1413
1414/*
1415 * The following defines are for the flags in the SP clock status register.
1416 */
1417#define SPCS_FRI 0x00000001
1418#define SPCS_DOI 0x00000002
1419#define SPCS_GPI2 0x00000004
1420#define SPCS_GPI3 0x00000008
1421#define SPCS_IP0 0x00000010
1422#define SPCS_IP1 0x00000020
1423#define SPCS_IP2 0x00000040
1424#define SPCS_IP3 0x00000080
1425#define SPCS_SPRUN 0x00000100
1426#define SPCS_SLEEP 0x00000200
1427#define SPCS_FG 0x00000400
1428#define SPCS_ORUN 0x00000800
1429#define SPCS_IRQ 0x00001000
1430#define SPCS_FGN_MASK 0x0000E000
1431#define SPCS_FGN_SHIFT 13
1432
1433/*
1434 * The following defines are for the flags in the SP DMA requestor status
1435 * register.
1436 */
1437#define SDSR_DCS_MASK 0x000000FF
1438#define SDSR_DCS_SHIFT 0
1439#define SDSR_DCS_NONE 0x00000007
1440
1441/*
1442 * The following defines are for the flags in the frame timer register.
1443 */
1444#define FRMT_FTV_MASK 0x0000FFFF
1445#define FRMT_FTV_SHIFT 0
1446
1447/*
1448 * The following defines are for the flags in the frame timer current count
1449 * register.
1450 */
1451#define FRCC_FCC_MASK 0x0000FFFF
1452#define FRCC_FCC_SHIFT 0
1453
1454/*
1455 * The following defines are for the flags in the frame timer save count
1456 * register.
1457 */
1458#define FRSC_FCS_MASK 0x0000FFFF
1459#define FRSC_FCS_SHIFT 0
1460
1461/*
1462 * The following define the various flags stored in the scatter/gather
1463 * descriptors.
1464 */
1465#define DMA_SG_NEXT_ENTRY_MASK 0x00000FF8
1466#define DMA_SG_SAMPLE_END_MASK 0x0FFF0000
1467#define DMA_SG_SAMPLE_END_FLAG 0x10000000
1468#define DMA_SG_LOOP_END_FLAG 0x20000000
1469#define DMA_SG_SIGNAL_END_FLAG 0x40000000
1470#define DMA_SG_SIGNAL_PAGE_FLAG 0x80000000
1471#define DMA_SG_NEXT_ENTRY_SHIFT 3
1472#define DMA_SG_SAMPLE_END_SHIFT 16
1473
1474/*
1475 * The following define the offsets of the fields within the on-chip generic
1476 * DMA requestor.
1477 */
1478#define DMA_RQ_CONTROL1 0x00000000
1479#define DMA_RQ_CONTROL2 0x00000004
1480#define DMA_RQ_SOURCE_ADDR 0x00000008
1481#define DMA_RQ_DESTINATION_ADDR 0x0000000C
1482#define DMA_RQ_NEXT_PAGE_ADDR 0x00000010
1483#define DMA_RQ_NEXT_PAGE_SGDESC 0x00000014
1484#define DMA_RQ_LOOP_START_ADDR 0x00000018
1485#define DMA_RQ_POST_LOOP_ADDR 0x0000001C
1486#define DMA_RQ_PAGE_MAP_ADDR 0x00000020
1487
1488/*
1489 * The following defines are for the flags in the first control word of the
1490 * on-chip generic DMA requestor.
1491 */
1492#define DMA_RQ_C1_COUNT_MASK 0x000003FF
1493#define DMA_RQ_C1_DESTINATION_SCATTER 0x00001000
1494#define DMA_RQ_C1_SOURCE_GATHER 0x00002000
1495#define DMA_RQ_C1_DONE_FLAG 0x00004000
1496#define DMA_RQ_C1_OPTIMIZE_STATE 0x00008000
1497#define DMA_RQ_C1_SAMPLE_END_STATE_MASK 0x00030000
1498#define DMA_RQ_C1_FULL_PAGE 0x00000000
1499#define DMA_RQ_C1_BEFORE_SAMPLE_END 0x00010000
1500#define DMA_RQ_C1_PAGE_MAP_ERROR 0x00020000
1501#define DMA_RQ_C1_AT_SAMPLE_END 0x00030000
1502#define DMA_RQ_C1_LOOP_END_STATE_MASK 0x000C0000
1503#define DMA_RQ_C1_NOT_LOOP_END 0x00000000
1504#define DMA_RQ_C1_BEFORE_LOOP_END 0x00040000
1505#define DMA_RQ_C1_2PAGE_LOOP_BEGIN 0x00080000
1506#define DMA_RQ_C1_LOOP_BEGIN 0x000C0000
1507#define DMA_RQ_C1_PAGE_MAP_MASK 0x00300000
1508#define DMA_RQ_C1_PM_NONE_PENDING 0x00000000
1509#define DMA_RQ_C1_PM_NEXT_PENDING 0x00100000
1510#define DMA_RQ_C1_PM_RESERVED 0x00200000
1511#define DMA_RQ_C1_PM_LOOP_NEXT_PENDING 0x00300000
1512#define DMA_RQ_C1_WRITEBACK_DEST_FLAG 0x00400000
1513#define DMA_RQ_C1_WRITEBACK_SRC_FLAG 0x00800000
1514#define DMA_RQ_C1_DEST_SIZE_MASK 0x07000000
1515#define DMA_RQ_C1_DEST_LINEAR 0x00000000
1516#define DMA_RQ_C1_DEST_MOD16 0x01000000
1517#define DMA_RQ_C1_DEST_MOD32 0x02000000
1518#define DMA_RQ_C1_DEST_MOD64 0x03000000
1519#define DMA_RQ_C1_DEST_MOD128 0x04000000
1520#define DMA_RQ_C1_DEST_MOD256 0x05000000
1521#define DMA_RQ_C1_DEST_MOD512 0x06000000
1522#define DMA_RQ_C1_DEST_MOD1024 0x07000000
1523#define DMA_RQ_C1_DEST_ON_HOST 0x08000000
1524#define DMA_RQ_C1_SOURCE_SIZE_MASK 0x70000000
1525#define DMA_RQ_C1_SOURCE_LINEAR 0x00000000
1526#define DMA_RQ_C1_SOURCE_MOD16 0x10000000
1527#define DMA_RQ_C1_SOURCE_MOD32 0x20000000
1528#define DMA_RQ_C1_SOURCE_MOD64 0x30000000
1529#define DMA_RQ_C1_SOURCE_MOD128 0x40000000
1530#define DMA_RQ_C1_SOURCE_MOD256 0x50000000
1531#define DMA_RQ_C1_SOURCE_MOD512 0x60000000
1532#define DMA_RQ_C1_SOURCE_MOD1024 0x70000000
1533#define DMA_RQ_C1_SOURCE_ON_HOST 0x80000000
1534#define DMA_RQ_C1_COUNT_SHIFT 0
1535
1536/*
1537 * The following defines are for the flags in the second control word of the
1538 * on-chip generic DMA requestor.
1539 */
1540#define DMA_RQ_C2_VIRTUAL_CHANNEL_MASK 0x0000003F
1541#define DMA_RQ_C2_VIRTUAL_SIGNAL_MASK 0x00000300
1542#define DMA_RQ_C2_NO_VIRTUAL_SIGNAL 0x00000000
1543#define DMA_RQ_C2_SIGNAL_EVERY_DMA 0x00000100
1544#define DMA_RQ_C2_SIGNAL_SOURCE_PINGPONG 0x00000200
1545#define DMA_RQ_C2_SIGNAL_DEST_PINGPONG 0x00000300
1546#define DMA_RQ_C2_AUDIO_CONVERT_MASK 0x0000F000
1547#define DMA_RQ_C2_AC_NONE 0x00000000
1548#define DMA_RQ_C2_AC_8_TO_16_BIT 0x00001000
1549#define DMA_RQ_C2_AC_MONO_TO_STEREO 0x00002000
1550#define DMA_RQ_C2_AC_ENDIAN_CONVERT 0x00004000
1551#define DMA_RQ_C2_AC_SIGNED_CONVERT 0x00008000
1552#define DMA_RQ_C2_LOOP_END_MASK 0x0FFF0000
1553#define DMA_RQ_C2_LOOP_MASK 0x30000000
1554#define DMA_RQ_C2_NO_LOOP 0x00000000
1555#define DMA_RQ_C2_ONE_PAGE_LOOP 0x10000000
1556#define DMA_RQ_C2_TWO_PAGE_LOOP 0x20000000
1557#define DMA_RQ_C2_MULTI_PAGE_LOOP 0x30000000
1558#define DMA_RQ_C2_SIGNAL_LOOP_BACK 0x40000000
1559#define DMA_RQ_C2_SIGNAL_POST_BEGIN_PAGE 0x80000000
1560#define DMA_RQ_C2_VIRTUAL_CHANNEL_SHIFT 0
1561#define DMA_RQ_C2_LOOP_END_SHIFT 16
1562
1563/*
1564 * The following defines are for the flags in the source and destination words
1565 * of the on-chip generic DMA requestor.
1566 */
1567#define DMA_RQ_SD_ADDRESS_MASK 0x0000FFFF
1568#define DMA_RQ_SD_MEMORY_ID_MASK 0x000F0000
1569#define DMA_RQ_SD_SP_PARAM_ADDR 0x00000000
1570#define DMA_RQ_SD_SP_SAMPLE_ADDR 0x00010000
1571#define DMA_RQ_SD_SP_PROGRAM_ADDR 0x00020000
1572#define DMA_RQ_SD_SP_DEBUG_ADDR 0x00030000
1573#define DMA_RQ_SD_OMNIMEM_ADDR 0x000E0000
1574#define DMA_RQ_SD_END_FLAG 0x40000000
1575#define DMA_RQ_SD_ERROR_FLAG 0x80000000
1576#define DMA_RQ_SD_ADDRESS_SHIFT 0
1577
1578/*
1579 * The following defines are for the flags in the page map address word of the
1580 * on-chip generic DMA requestor.
1581 */
1582#define DMA_RQ_PMA_LOOP_THIRD_PAGE_ENTRY_MASK 0x00000FF8
1583#define DMA_RQ_PMA_PAGE_TABLE_MASK 0xFFFFF000
1584#define DMA_RQ_PMA_LOOP_THIRD_PAGE_ENTRY_SHIFT 3
1585#define DMA_RQ_PMA_PAGE_TABLE_SHIFT 12
1586
1587#define BA1_VARIDEC_BUF_1 0x000
1588
1589#define BA1_PDTC 0x0c0 /* BA1_PLAY_DMA_TRANSACTION_COUNT_REG */
1590#define BA1_PFIE 0x0c4 /* BA1_PLAY_FORMAT_&_INTERRUPT_ENABLE_REG */
1591#define BA1_PBA 0x0c8 /* BA1_PLAY_BUFFER_ADDRESS */
1592#define BA1_PVOL 0x0f8 /* BA1_PLAY_VOLUME_REG */
1593#define BA1_PSRC 0x288 /* BA1_PLAY_SAMPLE_RATE_CORRECTION_REG */
1594#define BA1_PCTL 0x2a4 /* BA1_PLAY_CONTROL_REG */
1595#define BA1_PPI 0x2b4 /* BA1_PLAY_PHASE_INCREMENT_REG */
1596
1597#define BA1_CCTL 0x064 /* BA1_CAPTURE_CONTROL_REG */
1598#define BA1_CIE 0x104 /* BA1_CAPTURE_INTERRUPT_ENABLE_REG */
1599#define BA1_CBA 0x10c /* BA1_CAPTURE_BUFFER_ADDRESS */
1600#define BA1_CSRC 0x2c8 /* BA1_CAPTURE_SAMPLE_RATE_CORRECTION_REG */
1601#define BA1_CCI 0x2d8 /* BA1_CAPTURE_COEFFICIENT_INCREMENT_REG */
1602#define BA1_CD 0x2e0 /* BA1_CAPTURE_DELAY_REG */
1603#define BA1_CPI 0x2f4 /* BA1_CAPTURE_PHASE_INCREMENT_REG */
1604#define BA1_CVOL 0x2f8 /* BA1_CAPTURE_VOLUME_REG */
1605
1606#define BA1_CFG1 0x134 /* BA1_CAPTURE_FRAME_GROUP_1_REG */
1607#define BA1_CFG2 0x138 /* BA1_CAPTURE_FRAME_GROUP_2_REG */
1608#define BA1_CCST 0x13c /* BA1_CAPTURE_CONSTANT_REG */
1609#define BA1_CSPB 0x340 /* BA1_CAPTURE_SPB_ADDRESS */
1610
1611/*
1612 *
1613 */
1614
1615#define CS461X_MODE_OUTPUT (1<<0) /* MIDI UART - output */
1616#define CS461X_MODE_INPUT (1<<1) /* MIDI UART - input */
1617
1618//****************************************************************************
1619//
1620// The following define the offsets of the AC97 shadow registers, which appear
1621// as a virtual extension to the base address register zero memory range.
1622//
1623//****************************************************************************
1624#define AC97_REG_OFFSET_MASK 0x0000007EL
1625#define AC97_CODEC_NUMBER_MASK 0x00003000L
1626
1627#define BA0_AC97_RESET 0x00001000L
1628#define BA0_AC97_MASTER_VOLUME 0x00001002L
1629#define BA0_AC97_HEADPHONE_VOLUME 0x00001004L
1630#define BA0_AC97_MASTER_VOLUME_MONO 0x00001006L
1631#define BA0_AC97_MASTER_TONE 0x00001008L
1632#define BA0_AC97_PC_BEEP_VOLUME 0x0000100AL
1633#define BA0_AC97_PHONE_VOLUME 0x0000100CL
1634#define BA0_AC97_MIC_VOLUME 0x0000100EL
1635#define BA0_AC97_LINE_IN_VOLUME 0x00001010L
1636#define BA0_AC97_CD_VOLUME 0x00001012L
1637#define BA0_AC97_VIDEO_VOLUME 0x00001014L
1638#define BA0_AC97_AUX_VOLUME 0x00001016L
1639#define BA0_AC97_PCM_OUT_VOLUME 0x00001018L
1640#define BA0_AC97_RECORD_SELECT 0x0000101AL
1641#define BA0_AC97_RECORD_GAIN 0x0000101CL
1642#define BA0_AC97_RECORD_GAIN_MIC 0x0000101EL
1643#define BA0_AC97_GENERAL_PURPOSE 0x00001020L
1644#define BA0_AC97_3D_CONTROL 0x00001022L
1645#define BA0_AC97_MODEM_RATE 0x00001024L
1646#define BA0_AC97_POWERDOWN 0x00001026L
1647#define BA0_AC97_EXT_AUDIO_ID 0x00001028L
1648#define BA0_AC97_EXT_AUDIO_POWER 0x0000102AL
1649#define BA0_AC97_PCM_FRONT_DAC_RATE 0x0000102CL
1650#define BA0_AC97_PCM_SURR_DAC_RATE 0x0000102EL
1651#define BA0_AC97_PCM_LFE_DAC_RATE 0x00001030L
1652#define BA0_AC97_PCM_LR_ADC_RATE 0x00001032L
1653#define BA0_AC97_MIC_ADC_RATE 0x00001034L
1654#define BA0_AC97_6CH_VOL_C_LFE 0x00001036L
1655#define BA0_AC97_6CH_VOL_SURROUND 0x00001038L
1656#define BA0_AC97_RESERVED_3A 0x0000103AL
1657#define BA0_AC97_EXT_MODEM_ID 0x0000103CL
1658#define BA0_AC97_EXT_MODEM_POWER 0x0000103EL
1659#define BA0_AC97_LINE1_CODEC_RATE 0x00001040L
1660#define BA0_AC97_LINE2_CODEC_RATE 0x00001042L
1661#define BA0_AC97_HANDSET_CODEC_RATE 0x00001044L
1662#define BA0_AC97_LINE1_CODEC_LEVEL 0x00001046L
1663#define BA0_AC97_LINE2_CODEC_LEVEL 0x00001048L
1664#define BA0_AC97_HANDSET_CODEC_LEVEL 0x0000104AL
1665#define BA0_AC97_GPIO_PIN_CONFIG 0x0000104CL
1666#define BA0_AC97_GPIO_PIN_TYPE 0x0000104EL
1667#define BA0_AC97_GPIO_PIN_STICKY 0x00001050L
1668#define BA0_AC97_GPIO_PIN_WAKEUP 0x00001052L
1669#define BA0_AC97_GPIO_PIN_STATUS 0x00001054L
1670#define BA0_AC97_MISC_MODEM_AFE_STAT 0x00001056L
1671#define BA0_AC97_RESERVED_58 0x00001058L
1672#define BA0_AC97_CRYSTAL_REV_N_FAB_ID 0x0000105AL
1673#define BA0_AC97_TEST_AND_MISC_CTRL 0x0000105CL
1674#define BA0_AC97_AC_MODE 0x0000105EL
1675#define BA0_AC97_MISC_CRYSTAL_CONTROL 0x00001060L
1676#define BA0_AC97_LINE1_HYPRID_CTRL 0x00001062L
1677#define BA0_AC97_VENDOR_RESERVED_64 0x00001064L
1678#define BA0_AC97_VENDOR_RESERVED_66 0x00001066L
1679#define BA0_AC97_SPDIF_CONTROL 0x00001068L
1680#define BA0_AC97_VENDOR_RESERVED_6A 0x0000106AL
1681#define BA0_AC97_VENDOR_RESERVED_6C 0x0000106CL
1682#define BA0_AC97_VENDOR_RESERVED_6E 0x0000106EL
1683#define BA0_AC97_VENDOR_RESERVED_70 0x00001070L
1684#define BA0_AC97_VENDOR_RESERVED_72 0x00001072L
1685#define BA0_AC97_VENDOR_RESERVED_74 0x00001074L
1686#define BA0_AC97_CAL_ADDRESS 0x00001076L
1687#define BA0_AC97_CAL_DATA 0x00001078L
1688#define BA0_AC97_VENDOR_RESERVED_7A 0x0000107AL
1689#define BA0_AC97_VENDOR_ID1 0x0000107CL
1690#define BA0_AC97_VENDOR_ID2 0x0000107EL
1691#endif /* __CS461X_H */
diff --git a/sound/oss/cs461x_image.h b/sound/oss/cs461x_image.h
new file mode 100644
index 000000000000..b5c5a46d3423
--- /dev/null
+++ b/sound/oss/cs461x_image.h
@@ -0,0 +1,322 @@
1/****************************************************************************
2 * "CWCIMAGE.H"-- For CS46XX. Ver 1.04
3 * Copyright 1998-2001 (c) Cirrus Logic Corp.
4 * Version 1.04
5 ****************************************************************************
6 */
7#ifndef __CS_IMAGE_H
8#define __CS_IMAGE_H
9
10#define CLEAR__COUNT 3
11#define FILL__COUNT 4
12#define BA1__DWORD_SIZE 13*1024+512
13
14static struct
15{
16 unsigned BA1__DestByteOffset;
17 unsigned BA1__SourceSize;
18} ClrStat[CLEAR__COUNT] ={ {0x00000000, 0x00003000 },
19 {0x00010000, 0x00003800 },
20 {0x00020000, 0x00007000 } };
21
22static u32 FillArray1[]={
230x00000000,0x00000000,0x00000000,0x00000000,
240x00000000,0x00000000,0x00000000,0x00000000,
250x00000000,0x00000000,0x00000163,0x00000000,
260x00000000,0x00000000,0x00000000,0x00000000,
270x00000000,0x00000000,0x00000000,0x00000000,
280x00000000,0x00000000,0x00000000,0x00000000,
290x00000000,0x00200040,0x00008010,0x00000000,
300x00000000,0x80000001,0x00000001,0x00060000,
310x00000000,0x00000000,0x00000000,0x00000000,
320x00000000,0x00000000,0x00000000,0x00000000,
330x00000000,0x00900080,0x00000173,0x00000000,
340x00000000,0x00000010,0x00800000,0x00900000,
350xf2c0000f,0x00000200,0x00000000,0x00010600,
360x00000000,0x00000000,0x00000000,0x00000000,
370x00000000,0x00000000,0x00000163,0x330300c2,
380x06000000,0x00000000,0x80008000,0x80008000,
390x3fc0000f,0x00000301,0x00010400,0x00000000,
400x00000000,0x00000000,0x00000000,0x00000000,
410x00000000,0x00b00000,0x00d0806d,0x330480c3,
420x04800000,0x00000001,0x00800001,0x0000ffff,
430x00000000,0x00000000,0x00000000,0x00000000,
440x00000000,0x00000000,0x00000000,0x00000000,
450x00000000,0x00000000,0x00000000,0x00000000,
460x00000000,0x00000000,0x00000000,0x00000000,
470x00000000,0x00000000,0x00000000,0x00000000,
480x00000000,0x00000000,0x00000000,0x00000000,
490x00000000,0x00000000,0x00000000,0x00000000,
500x00000000,0x00000000,0x00000000,0x00000000,
510x066a0600,0x06350070,0x0000929d,0x929d929d,
520x00000000,0x0000735a,0x00000600,0x00000000,
530x929d735a,0x00000000,0x00010000,0x735a735a,
540xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
550x00000000,0x00000000,0x00000000,0x00000000,
560x00000000,0x00000000,0x00000000,0x00000000,
570x00000000,0x00000000,0x0000804f,0x000000c3,
580x05000000,0x00a00010,0x00000000,0x80008000,
590x00000000,0x00000000,0x00000700,0x00000000,
600x00000000,0x00000000,0x00000000,0x00000000,
610x00000080,0x00a00000,0x0000809a,0x000000c2,
620x07400000,0x00000000,0x80008000,0xffffffff,
630x00c80028,0x00005555,0x00000000,0x000107a0,
640x00c80028,0x000000c2,0x06800000,0x00000000,
650x06e00080,0x00300000,0x000080bb,0x000000c9,
660x07a00000,0x04000000,0x80008000,0xffffffff,
670x00c80028,0x00005555,0x00000000,0x00000780,
680x00c80028,0x000000c5,0xff800000,0x00000000,
690x00640080,0x00c00000,0x00008197,0x000000c9,
700x07800000,0x04000000,0x80008000,0xffffffff,
710x00000000,0x00000000,0x00000000,0x00000000,
720x00000000,0x00000000,0x00000000,0x00000000,
730x00000000,0x00000000,0x0000805e,0x000000c1,
740x00000000,0x00800000,0x80008000,0x80008000,
750x00020000,0x0000ffff,0x00000000,0x00000000};
76
77static u32 FillArray2[]={
780x929d0600,0x929d929d,0x929d929d,0x929d0000,
790x929d929d,0x929d929d,0x929d929d,0x929d929d,
800x929d929d,0x00100635,0x060b013f,0x00000004,
810x00000001,0x007a0002,0x00000000,0x066e0610,
820x0105929d,0x929d929d,0x929d929d,0x929d929d,
830x929d929d,0xa431ac75,0x0001735a,0xa431ac75,
840xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
850xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
860xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
870xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
880xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
890xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
900xa431ac75,0xa431ac75,0xa431ac75,0x735a0051,
910x00000000,0x929d929d,0x929d929d,0x929d929d,
920x929d929d,0x929d929d,0x929d929d,0x929d929d,
930x929d929d,0x929d929d,0x00000000,0x06400136,
940x0000270f,0x00010000,0x007a0000,0x00000000,
950x068e0645,0x0105929d,0x929d929d,0x929d929d,
960x929d929d,0x929d929d,0xa431ac75,0x0001735a,
970xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
980xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
990xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
1000xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
1010xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
1020xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
1030xa431ac75,0xa431ac75,0xa431ac75,0xa431ac75,
1040x735a0100,0x00000000,0x00000000,0x00000000};
105
106static u32 FillArray3[]={
1070x00000000,0x00000000,0x00000000,0x00010004};
108
109static u32 FillArray4[]={
1100x00040730,0x00001002,0x000f619e,0x00001003,
1110x00001705,0x00001400,0x000a411e,0x00001003,
1120x00040730,0x00001002,0x000f619e,0x00001003,
1130x00009705,0x00001400,0x000a411e,0x00001003,
1140x00040730,0x00001002,0x000f619e,0x00001003,
1150x00011705,0x00001400,0x000a411e,0x00001003,
1160x00040730,0x00001002,0x000f619e,0x00001003,
1170x00019705,0x00001400,0x000a411e,0x00001003,
1180x00040730,0x00001002,0x000f619e,0x00001003,
1190x00021705,0x00001400,0x000a411e,0x00001003,
1200x00040730,0x00001002,0x000f619e,0x00001003,
1210x00029705,0x00001400,0x000a411e,0x00001003,
1220x00040730,0x00001002,0x000f619e,0x00001003,
1230x00031705,0x00001400,0x000a411e,0x00001003,
1240x00040730,0x00001002,0x000f619e,0x00001003,
1250x00039705,0x00001400,0x000a411e,0x00001003,
1260x000fe19e,0x00001003,0x0009c730,0x00001003,
1270x0008e19c,0x00001003,0x000083c1,0x00093040,
1280x00098730,0x00001002,0x000ee19e,0x00001003,
1290x00009705,0x00001400,0x000a211e,0x00001003,
1300x00098730,0x00001002,0x000ee19e,0x00001003,
1310x00011705,0x00001400,0x000a211e,0x00001003,
1320x00098730,0x00001002,0x000ee19e,0x00001003,
1330x00019705,0x00001400,0x000a211e,0x00001003,
1340x00098730,0x00001002,0x000ee19e,0x00001003,
1350x00021705,0x00001400,0x000a211e,0x00001003,
1360x00098730,0x00001002,0x000ee19e,0x00001003,
1370x00029705,0x00001400,0x000a211e,0x00001003,
1380x00098730,0x00001002,0x000ee19e,0x00001003,
1390x00031705,0x00001400,0x000a211e,0x00001003,
1400x00098730,0x00001002,0x000ee19e,0x00001003,
1410x00039705,0x00001400,0x000a211e,0x00001003,
1420x0000a730,0x00001008,0x000e2730,0x00001002,
1430x0000a731,0x00001002,0x0000a731,0x00001002,
1440x0000a731,0x00001002,0x0000a731,0x00001002,
1450x0000a731,0x00001002,0x0000a731,0x00001002,
1460x00000000,0x00000000,0x000f619c,0x00001003,
1470x0007f801,0x000c0000,0x00000037,0x00001000,
1480x00000000,0x00000000,0x00000000,0x00000000,
1490x00000000,0x00000000,0x00000000,0x00000000,
1500x00000000,0x000c0000,0x00000000,0x00000000,
1510x0000373c,0x00001000,0x00000000,0x00000000,
1520x000ee19c,0x00001003,0x0007f801,0x000c0000,
1530x00000037,0x00001000,0x00000000,0x00000000,
1540x00000000,0x00000000,0x00000000,0x00000000,
1550x00000000,0x00000000,0x0000273c,0x00001000,
1560x00000033,0x00001000,0x000e679e,0x00001003,
1570x00007705,0x00001400,0x000ac71e,0x00001003,
1580x00087fc1,0x000c3be0,0x0007f801,0x000c0000,
1590x00000037,0x00001000,0x00000000,0x00000000,
1600x00000000,0x00000000,0x00000000,0x00000000,
1610x00000000,0x00000000,0x0000a730,0x00001003,
1620x00000033,0x00001000,0x0007f801,0x000c0000,
1630x00000037,0x00001000,0x00000000,0x00000000,
1640x00000000,0x00000000,0x00000000,0x00000000,
1650x00000000,0x00000000,0x00000000,0x000c0000,
1660x00000032,0x00001000,0x0000273d,0x00001000,
1670x0004a730,0x00001003,0x00000f41,0x00097140,
1680x0000a841,0x0009b240,0x0000a0c1,0x0009f040,
1690x0001c641,0x00093540,0x0001cec1,0x0009b5c0,
1700x00000000,0x00000000,0x0001bf05,0x0003fc40,
1710x00002725,0x000aa400,0x00013705,0x00093a00,
1720x0000002e,0x0009d6c0,0x00038630,0x00001004,
1730x0004ef0a,0x000eb785,0x0003fc8a,0x00000000,
1740x00000000,0x000c70e0,0x0007d182,0x0002c640,
1750x00000630,0x00001004,0x000799b8,0x0002c6c0,
1760x00031705,0x00092240,0x00039f05,0x000932c0,
1770x0003520a,0x00000000,0x00040731,0x0000100b,
1780x00010705,0x000b20c0,0x00000000,0x000eba44,
1790x00032108,0x000c60c4,0x00065208,0x000c2917,
1800x000406b0,0x00001007,0x00012f05,0x00036880,
1810x0002818e,0x000c0000,0x0004410a,0x00000000,
1820x00040630,0x00001007,0x00029705,0x000c0000,
1830x00000000,0x00000000,0x00003fc1,0x0003fc40,
1840x000037c1,0x00091b40,0x00003fc1,0x000911c0,
1850x000037c1,0x000957c0,0x00003fc1,0x000951c0,
1860x000037c1,0x00000000,0x00003fc1,0x000991c0,
1870x000037c1,0x00000000,0x00003fc1,0x0009d1c0,
1880x000037c1,0x00000000,0x0001ccc1,0x000915c0,
1890x0001c441,0x0009d800,0x0009cdc1,0x00091240,
1900x0001c541,0x00091d00,0x0009cfc1,0x00095240,
1910x0001c741,0x00095c80,0x000e8ca9,0x00099240,
1920x000e85ad,0x00095640,0x00069ca9,0x00099d80,
1930x000e952d,0x00099640,0x000eaca9,0x0009d6c0,
1940x000ea5ad,0x00091a40,0x0006bca9,0x0009de80,
1950x000eb52d,0x00095a40,0x000ecca9,0x00099ac0,
1960x000ec5ad,0x0009da40,0x000edca9,0x0009d300,
1970x000a6e0a,0x00001000,0x000ed52d,0x00091e40,
1980x000eeca9,0x00095ec0,0x000ee5ad,0x00099e40,
1990x0006fca9,0x00002500,0x000fb208,0x000c59a0,
2000x000ef52d,0x0009de40,0x00068ca9,0x000912c1,
2010x000683ad,0x00095241,0x00020f05,0x000991c1,
2020x00000000,0x00000000,0x00086f88,0x00001000,
2030x0009cf81,0x000b5340,0x0009c701,0x000b92c0,
2040x0009de81,0x000bd300,0x0009d601,0x000b1700,
2050x0001fd81,0x000b9d80,0x0009f501,0x000b57c0,
2060x000a0f81,0x000bd740,0x00020701,0x000b5c80,
2070x000a1681,0x000b97c0,0x00021601,0x00002500,
2080x000a0701,0x000b9b40,0x000a0f81,0x000b1bc0,
2090x00021681,0x00002d00,0x00020f81,0x000bd800,
2100x000a0701,0x000b5bc0,0x00021601,0x00003500,
2110x000a0f81,0x000b5f40,0x000a0701,0x000bdbc0,
2120x00021681,0x00003d00,0x00020f81,0x000b1d00,
2130x000a0701,0x000b1fc0,0x00021601,0x00020500,
2140x00020f81,0x000b1341,0x000a0701,0x000b9fc0,
2150x00021681,0x00020d00,0x00020f81,0x000bde80,
2160x000a0701,0x000bdfc0,0x00021601,0x00021500,
2170x00020f81,0x000b9341,0x00020701,0x000b53c1,
2180x00021681,0x00021d00,0x000a0f81,0x000d0380,
2190x0000b601,0x000b15c0,0x00007b01,0x00000000,
2200x00007b81,0x000bd1c0,0x00007b01,0x00000000,
2210x00007b81,0x000b91c0,0x00007b01,0x000b57c0,
2220x00007b81,0x000b51c0,0x00007b01,0x000b1b40,
2230x00007b81,0x000b11c0,0x00087b01,0x000c3dc0,
2240x0007e488,0x000d7e45,0x00000000,0x000d7a44,
2250x0007e48a,0x00000000,0x00011f05,0x00084080,
2260x00000000,0x00000000,0x00001705,0x000b3540,
2270x00008a01,0x000bf040,0x00007081,0x000bb5c0,
2280x00055488,0x00000000,0x0000d482,0x0003fc40,
2290x0003fc88,0x00000000,0x0001e401,0x000b3a00,
2300x0001ec81,0x000bd6c0,0x0004ef08,0x000eb784,
2310x000c86b0,0x00001007,0x00008281,0x000bb240,
2320x0000b801,0x000b7140,0x00007888,0x00000000,
2330x0000073c,0x00001000,0x0007f188,0x000c0000,
2340x00000000,0x00000000,0x00055288,0x000c555c,
2350x0005528a,0x000c0000,0x0009fa88,0x000c5d00,
2360x0000fa88,0x00000000,0x00000032,0x00001000,
2370x0000073d,0x00001000,0x0007f188,0x000c0000,
2380x00000000,0x00000000,0x0008c01c,0x00001003,
2390x00002705,0x00001008,0x0008b201,0x000c1392,
2400x0000ba01,0x00000000,0x00008731,0x00001400,
2410x0004c108,0x000fe0c4,0x00057488,0x00000000,
2420x000a6388,0x00001001,0x0008b334,0x000bc141,
2430x0003020e,0x00000000,0x000886b0,0x00001008,
2440x00003625,0x000c5dfa,0x000a638a,0x00001001,
2450x0008020e,0x00001002,0x0008a6b0,0x00001008,
2460x0007f301,0x00000000,0x00000000,0x00000000,
2470x00002725,0x000a8c40,0x000000ae,0x00000000,
2480x000d8630,0x00001008,0x00000000,0x000c74e0,
2490x0007d182,0x0002d640,0x000a8630,0x00001008,
2500x000799b8,0x0002d6c0,0x0000748a,0x000c3ec5,
2510x0007420a,0x000c0000,0x00062208,0x000c4117,
2520x00070630,0x00001009,0x00000000,0x000c0000,
2530x0001022e,0x00000000,0x0003a630,0x00001009,
2540x00000000,0x000c0000,0x00000036,0x00001000,
2550x00000000,0x00000000,0x00000000,0x00000000,
2560x00000000,0x00000000,0x00000000,0x00000000,
2570x0002a730,0x00001008,0x0007f801,0x000c0000,
2580x00000037,0x00001000,0x00000000,0x00000000,
2590x00000000,0x00000000,0x00000000,0x00000000,
2600x00000000,0x00000000,0x0002a730,0x00001008,
2610x00000033,0x00001000,0x0002a705,0x00001008,
2620x00007a01,0x000c0000,0x000e6288,0x000d550a,
2630x0006428a,0x00000000,0x00060730,0x0000100a,
2640x00000000,0x000c0000,0x00000000,0x00000000,
2650x0007aab0,0x00034880,0x00078fb0,0x0000100b,
2660x00057488,0x00000000,0x00033b94,0x00081140,
2670x000183ae,0x00000000,0x000786b0,0x0000100b,
2680x00022f05,0x000c3545,0x0000eb8a,0x00000000,
2690x00042731,0x00001003,0x0007aab0,0x00034880,
2700x00048fb0,0x0000100a,0x00057488,0x00000000,
2710x00033b94,0x00081140,0x000183ae,0x00000000,
2720x000806b0,0x0000100b,0x00022f05,0x00000000,
2730x00007401,0x00091140,0x00048f05,0x000951c0,
2740x00042731,0x00001003,0x0000473d,0x00001000,
2750x000f19b0,0x000bbc47,0x00080000,0x000bffc7,
2760x000fe19e,0x00001003,0x00000000,0x00000000,
2770x0008e19c,0x00001003,0x000083c1,0x00093040,
2780x00000f41,0x00097140,0x0000a841,0x0009b240,
2790x0000a0c1,0x0009f040,0x0001c641,0x00093540,
2800x0001cec1,0x0009b5c0,0x00000000,0x000fdc44,
2810x00055208,0x00000000,0x00010705,0x000a2880,
2820x0000a23a,0x00093a00,0x0003fc8a,0x000df6c5,
2830x0004ef0a,0x000c0000,0x00012f05,0x00036880,
2840x00065308,0x000c2997,0x000d86b0,0x0000100a,
2850x0004410a,0x000d40c7,0x00000000,0x00000000,
2860x00080730,0x00001004,0x00056f0a,0x000ea105,
2870x00000000,0x00000000,0x0000473d,0x00001000,
2880x000f19b0,0x000bbc47,0x00080000,0x000bffc7,
2890x0000273d,0x00001000,0x00000000,0x000eba44,
2900x00048f05,0x0000f440,0x00007401,0x0000f7c0,
2910x00000734,0x00001000,0x00010705,0x000a6880,
2920x00006a88,0x000c75c4,0x00000000,0x000e5084,
2930x00000000,0x000eba44,0x00087401,0x000e4782,
2940x00000734,0x00001000,0x00010705,0x000a6880,
2950x00006a88,0x000c75c4,0x0007c108,0x000c0000,
2960x0007e721,0x000bed40,0x00005f25,0x000badc0,
2970x0003ba97,0x000beb80,0x00065590,0x000b2e00,
2980x00033217,0x00003ec0,0x00065590,0x000b8e40,
2990x0003ed80,0x000491c0,0x00073fb0,0x00074c80,
3000x000283a0,0x0000100c,0x000ee388,0x00042970,
3010x00008301,0x00021ef2,0x000b8f14,0x0000000f,
3020x000c4d8d,0x0000001b,0x000d6dc2,0x000e06c6,
3030x000032ac,0x000c3916,0x0004edc2,0x00074c80,
3040x00078898,0x00001000,0x00038894,0x00000032,
3050x000c4d8d,0x00092e1b,0x000d6dc2,0x000e06c6,
3060x0004edc2,0x000c1956,0x0000722c,0x00034a00,
3070x00041705,0x0009ed40,0x00058730,0x00001400,
3080x000d7488,0x000c3a00,0x00048f05,0x00000000};
309
310static struct
311{ u32 Offset;
312 u32 Size;
313 u32 *pFill;
314} FillStat[FILL__COUNT] = {
315 {0x00000000, sizeof(FillArray1), FillArray1},
316 {0x00001800, sizeof(FillArray2), FillArray2},
317 {0x000137f0, sizeof(FillArray3), FillArray3},
318 {0x00020000, sizeof(FillArray4), FillArray4}
319 };
320
321
322#endif
diff --git a/sound/oss/cs46xx.c b/sound/oss/cs46xx.c
new file mode 100644
index 000000000000..8ce6b48f1881
--- /dev/null
+++ b/sound/oss/cs46xx.c
@@ -0,0 +1,5794 @@
1/*
2 * Crystal SoundFusion CS46xx driver
3 *
4 * Copyright 1998-2001 Cirrus Logic Corporation <pcaudio@crystal.cirrus.com>
5 * <twoller@crystal.cirrus.com>
6 * Copyright 1999-2000 Jaroslav Kysela <perex@suse.cz>
7 * Copyright 2000 Alan Cox <alan@redhat.com>
8 *
9 * The core of this code is taken from the ALSA project driver by
10 * Jaroslav. Please send Jaroslav the credit for the driver and
11 * report bugs in this port to <alan@redhat.com>
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 * Current maintainers:
27 * Cirrus Logic Corporation, Thomas Woller (tw)
28 * <twoller@crystal.cirrus.com>
29 * Nils Faerber (nf)
30 * <nils@kernelconcepts.de>
31 * Thanks to David Pollard for testing.
32 *
33 * Changes:
34 * 20000909-nf Changed cs_read, cs_write and drain_dac
35 * 20001025-tw Separate Playback/Capture structs and buffers.
36 * Added Scatter/Gather support for Playback.
37 * Added Capture.
38 * 20001027-nf Port to kernel 2.4.0-test9, some clean-ups
39 * Start of powermanagement support (CS46XX_PM).
40 * 20001128-tw Add module parm for default buffer order.
41 * added DMA_GFP flag to kmalloc dma buffer allocs.
42 * backfill silence to eliminate stuttering on
43 * underruns.
44 * 20001201-tw add resyncing of swptr on underruns.
45 * 20001205-tw-nf fixed GETOSPACE ioctl() after open()
46 * 20010113-tw patch from Hans Grobler general cleanup.
47 * 20010117-tw 2.4.0 pci cleanup, wrapper code for 2.2.16-2.4.0
48 * 20010118-tw basic PM support for 2.2.16+ and 2.4.0/2.4.2.
49 * 20010228-dh patch from David Huggins - cs_update_ptr recursion.
50 * 20010409-tw add hercules game theatre XP amp code.
51 * 20010420-tw cleanup powerdown/up code.
52 * 20010521-tw eliminate pops, and fixes for powerdown.
53 * 20010525-tw added fixes for thinkpads with powerdown logic.
54 * 20010723-sh patch from Horms (Simon Horman) -
55 * SOUND_PCM_READ_BITS returns bits as set in driver
56 * rather than a logical or of the possible values.
57 * Various ioctls handle the case where the device
58 * is open for reading or writing but not both better.
59 *
60 * Status:
61 * Playback/Capture supported from 8k-48k.
62 * 16Bit Signed LE & 8Bit Unsigned, with Mono or Stereo supported.
63 *
64 * APM/PM - 2.2.x APM is enabled and functioning fine. APM can also
65 * be enabled for 2.4.x by modifying the CS46XX_ACPI_SUPPORT macro
66 * definition.
67 *
68 * Hercules Game Theatre XP - the EGPIO2 pin controls the external Amp,
69 * so, use the drain/polarity to enable.
70 * hercules_egpio_disable set to 1, will force a 0 to EGPIODR.
71 *
72 * VTB Santa Cruz - the GPIO7/GPIO8 on the Secondary Codec control
73 * the external amplifier for the "back" speakers, since we do not
74 * support the secondary codec then this external amp is also not
75 * turned on.
76 */
77
78#include <linux/interrupt.h>
79#include <linux/list.h>
80#include <linux/module.h>
81#include <linux/string.h>
82#include <linux/ioport.h>
83#include <linux/sched.h>
84#include <linux/delay.h>
85#include <linux/sound.h>
86#include <linux/slab.h>
87#include <linux/soundcard.h>
88#include <linux/pci.h>
89#include <linux/bitops.h>
90#include <linux/init.h>
91#include <linux/poll.h>
92#include <linux/ac97_codec.h>
93
94#include <asm/io.h>
95#include <asm/dma.h>
96#include <asm/uaccess.h>
97
98#include "cs46xxpm-24.h"
99#include "cs46xx_wrapper-24.h"
100#include "cs461x.h"
101
102/* MIDI buffer sizes */
103#define CS_MIDIINBUF 500
104#define CS_MIDIOUTBUF 500
105
106#define ADC_RUNNING 1
107#define DAC_RUNNING 2
108
109#define CS_FMT_16BIT 1 /* These are fixed in fact */
110#define CS_FMT_STEREO 2
111#define CS_FMT_MASK 3
112
113#define CS_TYPE_ADC 1
114#define CS_TYPE_DAC 2
115
116#define CS_TRUE 1
117#define CS_FALSE 0
118
119#define CS_INC_USE_COUNT(m) (atomic_inc(m))
120#define CS_DEC_USE_COUNT(m) (atomic_dec(m))
121#define CS_DEC_AND_TEST(m) (atomic_dec_and_test(m))
122#define CS_IN_USE(m) (atomic_read(m) != 0)
123
124#define CS_DBGBREAKPOINT {__asm__("INT $3");}
125/*
126 * CS461x definitions
127 */
128
129#define CS461X_BA0_SIZE 0x2000
130#define CS461X_BA1_DATA0_SIZE 0x3000
131#define CS461X_BA1_DATA1_SIZE 0x3800
132#define CS461X_BA1_PRG_SIZE 0x7000
133#define CS461X_BA1_REG_SIZE 0x0100
134
135#define GOF_PER_SEC 200
136
137#define CSDEBUG_INTERFACE 1
138#define CSDEBUG 1
139/*
140 * Turn on/off debugging compilation by using 1/0 respectively for CSDEBUG
141 *
142 *
143 * CSDEBUG is usual mode is set to 1, then use the
144 * cs_debuglevel and cs_debugmask to turn on or off debugging.
145 * Debug level of 1 has been defined to be kernel errors and info
146 * that should be printed on any released driver.
147 */
148#if CSDEBUG
149#define CS_DBGOUT(mask,level,x) if((cs_debuglevel >= (level)) && ((mask) & cs_debugmask)) {x;}
150#else
151#define CS_DBGOUT(mask,level,x)
152#endif
153/*
154 * cs_debugmask areas
155 */
156#define CS_INIT 0x00000001 /* initialization and probe functions */
157#define CS_ERROR 0x00000002 /* tmp debugging bit placeholder */
158#define CS_INTERRUPT 0x00000004 /* interrupt handler (separate from all other) */
159#define CS_FUNCTION 0x00000008 /* enter/leave functions */
160#define CS_WAVE_WRITE 0x00000010 /* write information for wave */
161#define CS_WAVE_READ 0x00000020 /* read information for wave */
162#define CS_MIDI_WRITE 0x00000040 /* write information for midi */
163#define CS_MIDI_READ 0x00000080 /* read information for midi */
164#define CS_MPU401_WRITE 0x00000100 /* write information for mpu401 */
165#define CS_MPU401_READ 0x00000200 /* read information for mpu401 */
166#define CS_OPEN 0x00000400 /* all open functions in the driver */
167#define CS_RELEASE 0x00000800 /* all release functions in the driver */
168#define CS_PARMS 0x00001000 /* functional and operational parameters */
169#define CS_IOCTL 0x00002000 /* ioctl (non-mixer) */
170#define CS_PM 0x00004000 /* PM */
171#define CS_TMP 0x10000000 /* tmp debug mask bit */
172
173#define CS_IOCTL_CMD_SUSPEND 0x1 // suspend
174#define CS_IOCTL_CMD_RESUME 0x2 // resume
175
176#if CSDEBUG
177static unsigned long cs_debuglevel=1; /* levels range from 1-9 */
178module_param(cs_debuglevel, ulong, 0644);
179static unsigned long cs_debugmask=CS_INIT | CS_ERROR; /* use CS_DBGOUT with various mask values */
180module_param(cs_debugmask, ulong, 0644);
181#endif
182static unsigned long hercules_egpio_disable; /* if non-zero set all EGPIO to 0 */
183module_param(hercules_egpio_disable, ulong, 0);
184static unsigned long initdelay=700; /* PM delay in millisecs */
185module_param(initdelay, ulong, 0);
186static unsigned long powerdown=-1; /* turn on/off powerdown processing in driver */
187module_param(powerdown, ulong, 0);
188#define DMABUF_DEFAULTORDER 3
189static unsigned long defaultorder=DMABUF_DEFAULTORDER;
190module_param(defaultorder, ulong, 0);
191
192static int external_amp;
193module_param(external_amp, bool, 0);
194static int thinkpad;
195module_param(thinkpad, bool, 0);
196
197/*
198* set the powerdown module parm to 0 to disable all
199* powerdown. also set thinkpad to 1 to disable powerdown,
200* but also to enable the clkrun functionality.
201*/
202static unsigned cs_powerdown=1;
203static unsigned cs_laptop_wait=1;
204
205/* An instance of the 4610 channel */
206struct cs_channel
207{
208 int used;
209 int num;
210 void *state;
211};
212
213#define CS46XX_MAJOR_VERSION "1"
214#define CS46XX_MINOR_VERSION "28"
215
216#ifdef __ia64__
217#define CS46XX_ARCH "64" //architecture key
218#else
219#define CS46XX_ARCH "32" //architecture key
220#endif
221
222static struct list_head cs46xx_devs = { &cs46xx_devs, &cs46xx_devs };
223
224/* magic numbers to protect our data structures */
225#define CS_CARD_MAGIC 0x43525553 /* "CRUS" */
226#define CS_STATE_MAGIC 0x4c4f4749 /* "LOGI" */
227#define NR_HW_CH 3
228
229/* maxinum number of AC97 codecs connected, AC97 2.0 defined 4 */
230#define NR_AC97 2
231
232static const unsigned sample_size[] = { 1, 2, 2, 4 };
233static const unsigned sample_shift[] = { 0, 1, 1, 2 };
234
235/* "software" or virtual channel, an instance of opened /dev/dsp */
236struct cs_state {
237 unsigned int magic;
238 struct cs_card *card; /* Card info */
239
240 /* single open lock mechanism, only used for recording */
241 struct semaphore open_sem;
242 wait_queue_head_t open_wait;
243
244 /* file mode */
245 mode_t open_mode;
246
247 /* virtual channel number */
248 int virt;
249
250 struct dmabuf {
251 /* wave sample stuff */
252 unsigned int rate;
253 unsigned char fmt, enable;
254
255 /* hardware channel */
256 struct cs_channel *channel;
257 int pringbuf; /* Software ring slot */
258 void *pbuf; /* 4K hardware DMA buffer */
259
260 /* OSS buffer management stuff */
261 void *rawbuf;
262 dma_addr_t dma_handle;
263 unsigned buforder;
264 unsigned numfrag;
265 unsigned fragshift;
266 unsigned divisor;
267 unsigned type;
268 void *tmpbuff; /* tmp buffer for sample conversions */
269 dma_addr_t dmaaddr;
270 dma_addr_t dmaaddr_tmpbuff;
271 unsigned buforder_tmpbuff; /* Log base 2 of size in bytes.. */
272
273 /* our buffer acts like a circular ring */
274 unsigned hwptr; /* where dma last started, updated by update_ptr */
275 unsigned swptr; /* where driver last clear/filled, updated by read/write */
276 int count; /* bytes to be comsumed or been generated by dma machine */
277 unsigned total_bytes; /* total bytes dmaed by hardware */
278 unsigned blocks; /* total blocks */
279
280 unsigned error; /* number of over/underruns */
281 unsigned underrun; /* underrun pending before next write has occurred */
282 wait_queue_head_t wait; /* put process on wait queue when no more space in buffer */
283
284 /* redundant, but makes calculations easier */
285 unsigned fragsize;
286 unsigned dmasize;
287 unsigned fragsamples;
288
289 /* OSS stuff */
290 unsigned mapped:1;
291 unsigned ready:1;
292 unsigned endcleared:1;
293 unsigned SGok:1;
294 unsigned update_flag;
295 unsigned ossfragshift;
296 int ossmaxfrags;
297 unsigned subdivision;
298 } dmabuf;
299 /* Guard against mmap/write/read races */
300 struct semaphore sem;
301};
302
303struct cs_card {
304 struct cs_channel channel[2];
305 unsigned int magic;
306
307 /* We keep cs461x cards in a linked list */
308 struct cs_card *next;
309
310 /* The cs461x has a certain amount of cross channel interaction
311 so we use a single per card lock */
312 spinlock_t lock;
313
314 /* Keep AC97 sane */
315 spinlock_t ac97_lock;
316
317 /* mixer use count */
318 atomic_t mixer_use_cnt;
319
320 /* PCI device stuff */
321 struct pci_dev * pci_dev;
322 struct list_head list;
323
324 unsigned int pctl, cctl; /* Hardware DMA flag sets */
325
326 /* soundcore stuff */
327 int dev_audio;
328 int dev_midi;
329
330 /* structures for abstraction of hardware facilities, codecs, banks and channels*/
331 struct ac97_codec *ac97_codec[NR_AC97];
332 struct cs_state *states[2];
333
334 u16 ac97_features;
335
336 int amplifier; /* Amplifier control */
337 void (*amplifier_ctrl)(struct cs_card *, int);
338 void (*amp_init)(struct cs_card *);
339
340 int active; /* Active clocking */
341 void (*active_ctrl)(struct cs_card *, int);
342
343 /* hardware resources */
344 unsigned long ba0_addr;
345 unsigned long ba1_addr;
346 u32 irq;
347
348 /* mappings */
349 void __iomem *ba0;
350 union
351 {
352 struct
353 {
354 u8 __iomem *data0;
355 u8 __iomem *data1;
356 u8 __iomem *pmem;
357 u8 __iomem *reg;
358 } name;
359 u8 __iomem *idx[4];
360 } ba1;
361
362 /* Function support */
363 struct cs_channel *(*alloc_pcm_channel)(struct cs_card *);
364 struct cs_channel *(*alloc_rec_pcm_channel)(struct cs_card *);
365 void (*free_pcm_channel)(struct cs_card *, int chan);
366
367 /* /dev/midi stuff */
368 struct {
369 unsigned ird, iwr, icnt;
370 unsigned ord, owr, ocnt;
371 wait_queue_head_t open_wait;
372 wait_queue_head_t iwait;
373 wait_queue_head_t owait;
374 spinlock_t lock;
375 unsigned char ibuf[CS_MIDIINBUF];
376 unsigned char obuf[CS_MIDIOUTBUF];
377 mode_t open_mode;
378 struct semaphore open_sem;
379 } midi;
380 struct cs46xx_pm pm;
381};
382
383static int cs_open_mixdev(struct inode *inode, struct file *file);
384static int cs_release_mixdev(struct inode *inode, struct file *file);
385static int cs_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
386 unsigned long arg);
387static int cs_hardware_init(struct cs_card *card);
388static int cs46xx_powerup(struct cs_card *card, unsigned int type);
389static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspendflag);
390static void cs461x_clear_serial_FIFOs(struct cs_card *card, int type);
391static int cs46xx_suspend_tbl(struct pci_dev *pcidev, pm_message_t state);
392static int cs46xx_resume_tbl(struct pci_dev *pcidev);
393
394#ifndef CS46XX_ACPI_SUPPORT
395static int cs46xx_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data);
396#endif
397
398#if CSDEBUG
399
400/* DEBUG ROUTINES */
401
402#define SOUND_MIXER_CS_GETDBGLEVEL _SIOWR('M',120, int)
403#define SOUND_MIXER_CS_SETDBGLEVEL _SIOWR('M',121, int)
404#define SOUND_MIXER_CS_GETDBGMASK _SIOWR('M',122, int)
405#define SOUND_MIXER_CS_SETDBGMASK _SIOWR('M',123, int)
406#define SOUND_MIXER_CS_APM _SIOWR('M',124, int)
407
408static void printioctl(unsigned int x)
409{
410 unsigned int i;
411 unsigned char vidx;
412 /* these values are incorrect for the ac97 driver, fix.
413 * Index of mixtable1[] member is Device ID
414 * and must be <= SOUND_MIXER_NRDEVICES.
415 * Value of array member is index into s->mix.vol[]
416 */
417 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
418 [SOUND_MIXER_PCM] = 1, /* voice */
419 [SOUND_MIXER_LINE1] = 2, /* AUX */
420 [SOUND_MIXER_CD] = 3, /* CD */
421 [SOUND_MIXER_LINE] = 4, /* Line */
422 [SOUND_MIXER_SYNTH] = 5, /* FM */
423 [SOUND_MIXER_MIC] = 6, /* Mic */
424 [SOUND_MIXER_SPEAKER] = 7, /* Speaker */
425 [SOUND_MIXER_RECLEV] = 8, /* Recording level */
426 [SOUND_MIXER_VOLUME] = 9 /* Master Volume */
427 };
428
429 switch(x)
430 {
431 case SOUND_MIXER_CS_GETDBGMASK:
432 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CS_GETDBGMASK: ") );
433 break;
434 case SOUND_MIXER_CS_GETDBGLEVEL:
435 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CS_GETDBGLEVEL: ") );
436 break;
437 case SOUND_MIXER_CS_SETDBGMASK:
438 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CS_SETDBGMASK: ") );
439 break;
440 case SOUND_MIXER_CS_SETDBGLEVEL:
441 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CS_SETDBGLEVEL: ") );
442 break;
443 case OSS_GETVERSION:
444 CS_DBGOUT(CS_IOCTL, 4, printk("OSS_GETVERSION: ") );
445 break;
446 case SNDCTL_DSP_SYNC:
447 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SYNC: ") );
448 break;
449 case SNDCTL_DSP_SETDUPLEX:
450 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETDUPLEX: ") );
451 break;
452 case SNDCTL_DSP_GETCAPS:
453 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETCAPS: ") );
454 break;
455 case SNDCTL_DSP_RESET:
456 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_RESET: ") );
457 break;
458 case SNDCTL_DSP_SPEED:
459 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SPEED: ") );
460 break;
461 case SNDCTL_DSP_STEREO:
462 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_STEREO: ") );
463 break;
464 case SNDCTL_DSP_CHANNELS:
465 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_CHANNELS: ") );
466 break;
467 case SNDCTL_DSP_GETFMTS:
468 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETFMTS: ") );
469 break;
470 case SNDCTL_DSP_SETFMT:
471 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETFMT: ") );
472 break;
473 case SNDCTL_DSP_POST:
474 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_POST: ") );
475 break;
476 case SNDCTL_DSP_GETTRIGGER:
477 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETTRIGGER: ") );
478 break;
479 case SNDCTL_DSP_SETTRIGGER:
480 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETTRIGGER: ") );
481 break;
482 case SNDCTL_DSP_GETOSPACE:
483 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOSPACE: ") );
484 break;
485 case SNDCTL_DSP_GETISPACE:
486 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETISPACE: ") );
487 break;
488 case SNDCTL_DSP_NONBLOCK:
489 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_NONBLOCK: ") );
490 break;
491 case SNDCTL_DSP_GETODELAY:
492 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETODELAY: ") );
493 break;
494 case SNDCTL_DSP_GETIPTR:
495 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETIPTR: ") );
496 break;
497 case SNDCTL_DSP_GETOPTR:
498 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOPTR: ") );
499 break;
500 case SNDCTL_DSP_GETBLKSIZE:
501 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETBLKSIZE: ") );
502 break;
503 case SNDCTL_DSP_SETFRAGMENT:
504 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETFRAGMENT: ") );
505 break;
506 case SNDCTL_DSP_SUBDIVIDE:
507 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SUBDIVIDE: ") );
508 break;
509 case SOUND_PCM_READ_RATE:
510 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_RATE: ") );
511 break;
512 case SOUND_PCM_READ_CHANNELS:
513 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_CHANNELS: ") );
514 break;
515 case SOUND_PCM_READ_BITS:
516 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_BITS: ") );
517 break;
518 case SOUND_PCM_WRITE_FILTER:
519 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_WRITE_FILTER: ") );
520 break;
521 case SNDCTL_DSP_SETSYNCRO:
522 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETSYNCRO: ") );
523 break;
524 case SOUND_PCM_READ_FILTER:
525 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_FILTER: ") );
526 break;
527
528 case SOUND_MIXER_PRIVATE1:
529 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE1: ") );
530 break;
531 case SOUND_MIXER_PRIVATE2:
532 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE2: ") );
533 break;
534 case SOUND_MIXER_PRIVATE3:
535 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE3: ") );
536 break;
537 case SOUND_MIXER_PRIVATE4:
538 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE4: ") );
539 break;
540 case SOUND_MIXER_PRIVATE5:
541 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE5: ") );
542 break;
543 case SOUND_MIXER_INFO:
544 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_INFO: ") );
545 break;
546 case SOUND_OLD_MIXER_INFO:
547 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_OLD_MIXER_INFO: ") );
548 break;
549
550 default:
551 switch (_IOC_NR(x))
552 {
553 case SOUND_MIXER_VOLUME:
554 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_VOLUME: ") );
555 break;
556 case SOUND_MIXER_SPEAKER:
557 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_SPEAKER: ") );
558 break;
559 case SOUND_MIXER_RECLEV:
560 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_RECLEV: ") );
561 break;
562 case SOUND_MIXER_MIC:
563 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_MIC: ") );
564 break;
565 case SOUND_MIXER_SYNTH:
566 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_SYNTH: ") );
567 break;
568 case SOUND_MIXER_RECSRC:
569 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_RECSRC: ") );
570 break;
571 case SOUND_MIXER_DEVMASK:
572 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_DEVMASK: ") );
573 break;
574 case SOUND_MIXER_RECMASK:
575 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_RECMASK: ") );
576 break;
577 case SOUND_MIXER_STEREODEVS:
578 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_STEREODEVS: ") );
579 break;
580 case SOUND_MIXER_CAPS:
581 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CAPS:") );
582 break;
583 default:
584 i = _IOC_NR(x);
585 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i]))
586 {
587 CS_DBGOUT(CS_IOCTL, 4, printk("UNKNOWN IOCTL: 0x%.8x NR=%d ",x,i) );
588 }
589 else
590 {
591 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_IOCTL AC9x: 0x%.8x NR=%d ",
592 x,i) );
593 }
594 break;
595 }
596 }
597 CS_DBGOUT(CS_IOCTL, 4, printk("command = 0x%x IOC_NR=%d\n",x, _IOC_NR(x)) );
598}
599#endif
600
601/*
602 * common I/O routines
603 */
604
605static void cs461x_poke(struct cs_card *codec, unsigned long reg, unsigned int val)
606{
607 writel(val, codec->ba1.idx[(reg >> 16) & 3]+(reg&0xffff));
608}
609
610static unsigned int cs461x_peek(struct cs_card *codec, unsigned long reg)
611{
612 return readl(codec->ba1.idx[(reg >> 16) & 3]+(reg&0xffff));
613}
614
615static void cs461x_pokeBA0(struct cs_card *codec, unsigned long reg, unsigned int val)
616{
617 writel(val, codec->ba0+reg);
618}
619
620static unsigned int cs461x_peekBA0(struct cs_card *codec, unsigned long reg)
621{
622 return readl(codec->ba0+reg);
623}
624
625
626static u16 cs_ac97_get(struct ac97_codec *dev, u8 reg);
627static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 data);
628
629static struct cs_channel *cs_alloc_pcm_channel(struct cs_card *card)
630{
631 if(card->channel[1].used==1)
632 return NULL;
633 card->channel[1].used=1;
634 card->channel[1].num=1;
635 return &card->channel[1];
636}
637
638static struct cs_channel *cs_alloc_rec_pcm_channel(struct cs_card *card)
639{
640 if(card->channel[0].used==1)
641 return NULL;
642 card->channel[0].used=1;
643 card->channel[0].num=0;
644 return &card->channel[0];
645}
646
647static void cs_free_pcm_channel(struct cs_card *card, int channel)
648{
649 card->channel[channel].state = NULL;
650 card->channel[channel].used=0;
651}
652
653/*
654 * setup a divisor value to help with conversion from
655 * 16bit Stereo, down to 8bit stereo/mono or 16bit mono.
656 * assign a divisor of 1 if using 16bit Stereo as that is
657 * the only format that the static image will capture.
658 */
659static void cs_set_divisor(struct dmabuf *dmabuf)
660{
661 if(dmabuf->type == CS_TYPE_DAC)
662 dmabuf->divisor = 1;
663 else if( !(dmabuf->fmt & CS_FMT_STEREO) &&
664 (dmabuf->fmt & CS_FMT_16BIT))
665 dmabuf->divisor = 2;
666 else if( (dmabuf->fmt & CS_FMT_STEREO) &&
667 !(dmabuf->fmt & CS_FMT_16BIT))
668 dmabuf->divisor = 2;
669 else if( !(dmabuf->fmt & CS_FMT_STEREO) &&
670 !(dmabuf->fmt & CS_FMT_16BIT))
671 dmabuf->divisor = 4;
672 else
673 dmabuf->divisor = 1;
674
675 CS_DBGOUT(CS_PARMS | CS_FUNCTION, 8, printk(
676 "cs46xx: cs_set_divisor()- %s %d\n",
677 (dmabuf->type == CS_TYPE_ADC) ? "ADC" : "DAC",
678 dmabuf->divisor) );
679}
680
681/*
682* mute some of the more prevalent registers to avoid popping.
683*/
684static void cs_mute(struct cs_card *card, int state)
685{
686 struct ac97_codec *dev=card->ac97_codec[0];
687
688 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: cs_mute()+ %s\n",
689 (state == CS_TRUE) ? "Muting" : "UnMuting") );
690
691 if(state == CS_TRUE)
692 {
693 /*
694 * fix pops when powering up on thinkpads
695 */
696 card->pm.u32AC97_master_volume = (u32)cs_ac97_get( dev,
697 (u8)BA0_AC97_MASTER_VOLUME);
698 card->pm.u32AC97_headphone_volume = (u32)cs_ac97_get(dev,
699 (u8)BA0_AC97_HEADPHONE_VOLUME);
700 card->pm.u32AC97_master_volume_mono = (u32)cs_ac97_get(dev,
701 (u8)BA0_AC97_MASTER_VOLUME_MONO);
702 card->pm.u32AC97_pcm_out_volume = (u32)cs_ac97_get(dev,
703 (u8)BA0_AC97_PCM_OUT_VOLUME);
704
705 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME, 0x8000);
706 cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, 0x8000);
707 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, 0x8000);
708 cs_ac97_set(dev, (u8)BA0_AC97_PCM_OUT_VOLUME, 0x8000);
709 }
710 else
711 {
712 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME, card->pm.u32AC97_master_volume);
713 cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, card->pm.u32AC97_headphone_volume);
714 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, card->pm.u32AC97_master_volume_mono);
715 cs_ac97_set(dev, (u8)BA0_AC97_PCM_OUT_VOLUME, card->pm.u32AC97_pcm_out_volume);
716 }
717 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: cs_mute()-\n"));
718}
719
720/* set playback sample rate */
721static unsigned int cs_set_dac_rate(struct cs_state * state, unsigned int rate)
722{
723 struct dmabuf *dmabuf = &state->dmabuf;
724 unsigned int tmp1, tmp2;
725 unsigned int phiIncr;
726 unsigned int correctionPerGOF, correctionPerSec;
727 unsigned long flags;
728
729 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_set_dac_rate()+ %d\n",rate) );
730
731 /*
732 * Compute the values used to drive the actual sample rate conversion.
733 * The following formulas are being computed, using inline assembly
734 * since we need to use 64 bit arithmetic to compute the values:
735 *
736 * phiIncr = floor((Fs,in * 2^26) / Fs,out)
737 * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) /
738 * GOF_PER_SEC)
739 * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M
740 * GOF_PER_SEC * correctionPerGOF
741 *
742 * i.e.
743 *
744 * phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out)
745 * correctionPerGOF:correctionPerSec =
746 * dividend:remainder(ulOther / GOF_PER_SEC)
747 */
748 tmp1 = rate << 16;
749 phiIncr = tmp1 / 48000;
750 tmp1 -= phiIncr * 48000;
751 tmp1 <<= 10;
752 phiIncr <<= 10;
753 tmp2 = tmp1 / 48000;
754 phiIncr += tmp2;
755 tmp1 -= tmp2 * 48000;
756 correctionPerGOF = tmp1 / GOF_PER_SEC;
757 tmp1 -= correctionPerGOF * GOF_PER_SEC;
758 correctionPerSec = tmp1;
759
760 /*
761 * Fill in the SampleRateConverter control block.
762 */
763
764 spin_lock_irqsave(&state->card->lock, flags);
765 cs461x_poke(state->card, BA1_PSRC,
766 ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF));
767 cs461x_poke(state->card, BA1_PPI, phiIncr);
768 spin_unlock_irqrestore(&state->card->lock, flags);
769 dmabuf->rate = rate;
770
771 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_set_dac_rate()- %d\n",rate) );
772 return rate;
773}
774
775/* set recording sample rate */
776static unsigned int cs_set_adc_rate(struct cs_state * state, unsigned int rate)
777{
778 struct dmabuf *dmabuf = &state->dmabuf;
779 struct cs_card *card = state->card;
780 unsigned int phiIncr, coeffIncr, tmp1, tmp2;
781 unsigned int correctionPerGOF, correctionPerSec, initialDelay;
782 unsigned int frameGroupLength, cnt;
783 unsigned long flags;
784 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_set_adc_rate()+ %d\n",rate) );
785
786 /*
787 * We can only decimate by up to a factor of 1/9th the hardware rate.
788 * Correct the value if an attempt is made to stray outside that limit.
789 */
790 if ((rate * 9) < 48000)
791 rate = 48000 / 9;
792
793 /*
794 * We can not capture at at rate greater than the Input Rate (48000).
795 * Return an error if an attempt is made to stray outside that limit.
796 */
797 if (rate > 48000)
798 rate = 48000;
799
800 /*
801 * Compute the values used to drive the actual sample rate conversion.
802 * The following formulas are being computed, using inline assembly
803 * since we need to use 64 bit arithmetic to compute the values:
804 *
805 * coeffIncr = -floor((Fs,out * 2^23) / Fs,in)
806 * phiIncr = floor((Fs,in * 2^26) / Fs,out)
807 * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) /
808 * GOF_PER_SEC)
809 * correctionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -
810 * GOF_PER_SEC * correctionPerGOF
811 * initialDelay = ceil((24 * Fs,in) / Fs,out)
812 *
813 * i.e.
814 *
815 * coeffIncr = neg(dividend((Fs,out * 2^23) / Fs,in))
816 * phiIncr:ulOther = dividend:remainder((Fs,in * 2^26) / Fs,out)
817 * correctionPerGOF:correctionPerSec =
818 * dividend:remainder(ulOther / GOF_PER_SEC)
819 * initialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out)
820 */
821
822 tmp1 = rate << 16;
823 coeffIncr = tmp1 / 48000;
824 tmp1 -= coeffIncr * 48000;
825 tmp1 <<= 7;
826 coeffIncr <<= 7;
827 coeffIncr += tmp1 / 48000;
828 coeffIncr ^= 0xFFFFFFFF;
829 coeffIncr++;
830 tmp1 = 48000 << 16;
831 phiIncr = tmp1 / rate;
832 tmp1 -= phiIncr * rate;
833 tmp1 <<= 10;
834 phiIncr <<= 10;
835 tmp2 = tmp1 / rate;
836 phiIncr += tmp2;
837 tmp1 -= tmp2 * rate;
838 correctionPerGOF = tmp1 / GOF_PER_SEC;
839 tmp1 -= correctionPerGOF * GOF_PER_SEC;
840 correctionPerSec = tmp1;
841 initialDelay = ((48000 * 24) + rate - 1) / rate;
842
843 /*
844 * Fill in the VariDecimate control block.
845 */
846 spin_lock_irqsave(&card->lock, flags);
847 cs461x_poke(card, BA1_CSRC,
848 ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF));
849 cs461x_poke(card, BA1_CCI, coeffIncr);
850 cs461x_poke(card, BA1_CD,
851 (((BA1_VARIDEC_BUF_1 + (initialDelay << 2)) << 16) & 0xFFFF0000) | 0x80);
852 cs461x_poke(card, BA1_CPI, phiIncr);
853 spin_unlock_irqrestore(&card->lock, flags);
854
855 /*
856 * Figure out the frame group length for the write back task. Basically,
857 * this is just the factors of 24000 (2^6*3*5^3) that are not present in
858 * the output sample rate.
859 */
860 frameGroupLength = 1;
861 for (cnt = 2; cnt <= 64; cnt *= 2) {
862 if (((rate / cnt) * cnt) != rate)
863 frameGroupLength *= 2;
864 }
865 if (((rate / 3) * 3) != rate) {
866 frameGroupLength *= 3;
867 }
868 for (cnt = 5; cnt <= 125; cnt *= 5) {
869 if (((rate / cnt) * cnt) != rate)
870 frameGroupLength *= 5;
871 }
872
873 /*
874 * Fill in the WriteBack control block.
875 */
876 spin_lock_irqsave(&card->lock, flags);
877 cs461x_poke(card, BA1_CFG1, frameGroupLength);
878 cs461x_poke(card, BA1_CFG2, (0x00800000 | frameGroupLength));
879 cs461x_poke(card, BA1_CCST, 0x0000FFFF);
880 cs461x_poke(card, BA1_CSPB, ((65536 * rate) / 24000));
881 cs461x_poke(card, (BA1_CSPB + 4), 0x0000FFFF);
882 spin_unlock_irqrestore(&card->lock, flags);
883 dmabuf->rate = rate;
884 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_set_adc_rate()- %d\n",rate) );
885 return rate;
886}
887
888/* prepare channel attributes for playback */
889static void cs_play_setup(struct cs_state *state)
890{
891 struct dmabuf *dmabuf = &state->dmabuf;
892 struct cs_card *card = state->card;
893 unsigned int tmp, Count, playFormat;
894
895 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_play_setup()+\n") );
896 cs461x_poke(card, BA1_PVOL, 0x80008000);
897 if(!dmabuf->SGok)
898 cs461x_poke(card, BA1_PBA, virt_to_bus(dmabuf->pbuf));
899
900 Count = 4;
901 playFormat=cs461x_peek(card, BA1_PFIE);
902 if ((dmabuf->fmt & CS_FMT_STEREO)) {
903 playFormat &= ~DMA_RQ_C2_AC_MONO_TO_STEREO;
904 Count *= 2;
905 }
906 else
907 playFormat |= DMA_RQ_C2_AC_MONO_TO_STEREO;
908
909 if ((dmabuf->fmt & CS_FMT_16BIT)) {
910 playFormat &= ~(DMA_RQ_C2_AC_8_TO_16_BIT
911 | DMA_RQ_C2_AC_SIGNED_CONVERT);
912 Count *= 2;
913 }
914 else
915 playFormat |= (DMA_RQ_C2_AC_8_TO_16_BIT
916 | DMA_RQ_C2_AC_SIGNED_CONVERT);
917
918 cs461x_poke(card, BA1_PFIE, playFormat);
919
920 tmp = cs461x_peek(card, BA1_PDTC);
921 tmp &= 0xfffffe00;
922 cs461x_poke(card, BA1_PDTC, tmp | --Count);
923
924 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_play_setup()-\n") );
925
926}
927
928static struct InitStruct
929{
930 u32 off;
931 u32 val;
932} InitArray[] = { {0x00000040, 0x3fc0000f},
933 {0x0000004c, 0x04800000},
934
935 {0x000000b3, 0x00000780},
936 {0x000000b7, 0x00000000},
937 {0x000000bc, 0x07800000},
938
939 {0x000000cd, 0x00800000},
940 };
941
942/*
943 * "SetCaptureSPValues()" -- Initialize record task values before each
944 * capture startup.
945 */
946static void SetCaptureSPValues(struct cs_card *card)
947{
948 unsigned i, offset;
949 CS_DBGOUT(CS_FUNCTION, 8, printk("cs46xx: SetCaptureSPValues()+\n") );
950 for(i=0; i<sizeof(InitArray)/sizeof(struct InitStruct); i++)
951 {
952 offset = InitArray[i].off*4; /* 8bit to 32bit offset value */
953 cs461x_poke(card, offset, InitArray[i].val );
954 }
955 CS_DBGOUT(CS_FUNCTION, 8, printk("cs46xx: SetCaptureSPValues()-\n") );
956}
957
958/* prepare channel attributes for recording */
959static void cs_rec_setup(struct cs_state *state)
960{
961 struct cs_card *card = state->card;
962 struct dmabuf *dmabuf = &state->dmabuf;
963 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_rec_setup()+\n") );
964
965 SetCaptureSPValues(card);
966
967 /*
968 * set the attenuation to 0dB
969 */
970 cs461x_poke(card, BA1_CVOL, 0x80008000);
971
972 /*
973 * set the physical address of the capture buffer into the SP
974 */
975 cs461x_poke(card, BA1_CBA, virt_to_bus(dmabuf->rawbuf));
976
977 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_rec_setup()-\n") );
978}
979
980
981/* get current playback/recording dma buffer pointer (byte offset from LBA),
982 called with spinlock held! */
983
984static inline unsigned cs_get_dma_addr(struct cs_state *state)
985{
986 struct dmabuf *dmabuf = &state->dmabuf;
987 u32 offset;
988
989 if ( (!(dmabuf->enable & DAC_RUNNING)) &&
990 (!(dmabuf->enable & ADC_RUNNING) ) )
991 {
992 CS_DBGOUT(CS_ERROR, 2, printk(
993 "cs46xx: ERROR cs_get_dma_addr(): not enabled \n") );
994 return 0;
995 }
996
997 /*
998 * granularity is byte boundary, good part.
999 */
1000 if(dmabuf->enable & DAC_RUNNING)
1001 {
1002 offset = cs461x_peek(state->card, BA1_PBA);
1003 }
1004 else /* ADC_RUNNING must be set */
1005 {
1006 offset = cs461x_peek(state->card, BA1_CBA);
1007 }
1008 CS_DBGOUT(CS_PARMS | CS_FUNCTION, 9,
1009 printk("cs46xx: cs_get_dma_addr() %d\n",offset) );
1010 offset = (u32)bus_to_virt((unsigned long)offset) - (u32)dmabuf->rawbuf;
1011 CS_DBGOUT(CS_PARMS | CS_FUNCTION, 8,
1012 printk("cs46xx: cs_get_dma_addr()- %d\n",offset) );
1013 return offset;
1014}
1015
1016static void resync_dma_ptrs(struct cs_state *state)
1017{
1018 struct dmabuf *dmabuf;
1019
1020 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: resync_dma_ptrs()+ \n") );
1021 if(state)
1022 {
1023 dmabuf = &state->dmabuf;
1024 dmabuf->hwptr=dmabuf->swptr = 0;
1025 dmabuf->pringbuf = 0;
1026 }
1027 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: resync_dma_ptrs()- \n") );
1028}
1029
1030/* Stop recording (lock held) */
1031static inline void __stop_adc(struct cs_state *state)
1032{
1033 struct dmabuf *dmabuf = &state->dmabuf;
1034 struct cs_card *card = state->card;
1035 unsigned int tmp;
1036
1037 dmabuf->enable &= ~ADC_RUNNING;
1038
1039 tmp = cs461x_peek(card, BA1_CCTL);
1040 tmp &= 0xFFFF0000;
1041 cs461x_poke(card, BA1_CCTL, tmp );
1042}
1043
1044static void stop_adc(struct cs_state *state)
1045{
1046 unsigned long flags;
1047
1048 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: stop_adc()+ \n") );
1049 spin_lock_irqsave(&state->card->lock, flags);
1050 __stop_adc(state);
1051 spin_unlock_irqrestore(&state->card->lock, flags);
1052 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: stop_adc()- \n") );
1053}
1054
1055static void start_adc(struct cs_state *state)
1056{
1057 struct dmabuf *dmabuf = &state->dmabuf;
1058 struct cs_card *card = state->card;
1059 unsigned long flags;
1060 unsigned int tmp;
1061
1062 spin_lock_irqsave(&card->lock, flags);
1063 if (!(dmabuf->enable & ADC_RUNNING) &&
1064 ((dmabuf->mapped || dmabuf->count < (signed)dmabuf->dmasize)
1065 && dmabuf->ready) &&
1066 ((card->pm.flags & CS46XX_PM_IDLE) ||
1067 (card->pm.flags & CS46XX_PM_RESUMED)) )
1068 {
1069 dmabuf->enable |= ADC_RUNNING;
1070 cs_set_divisor(dmabuf);
1071 tmp = cs461x_peek(card, BA1_CCTL);
1072 tmp &= 0xFFFF0000;
1073 tmp |= card->cctl;
1074 CS_DBGOUT(CS_FUNCTION, 2, printk(
1075 "cs46xx: start_adc() poke 0x%x \n",tmp) );
1076 cs461x_poke(card, BA1_CCTL, tmp);
1077 }
1078 spin_unlock_irqrestore(&card->lock, flags);
1079}
1080
1081/* stop playback (lock held) */
1082static inline void __stop_dac(struct cs_state *state)
1083{
1084 struct dmabuf *dmabuf = &state->dmabuf;
1085 struct cs_card *card = state->card;
1086 unsigned int tmp;
1087
1088 dmabuf->enable &= ~DAC_RUNNING;
1089
1090 tmp=cs461x_peek(card, BA1_PCTL);
1091 tmp&=0xFFFF;
1092 cs461x_poke(card, BA1_PCTL, tmp);
1093}
1094
1095static void stop_dac(struct cs_state *state)
1096{
1097 unsigned long flags;
1098
1099 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: stop_dac()+ \n") );
1100 spin_lock_irqsave(&state->card->lock, flags);
1101 __stop_dac(state);
1102 spin_unlock_irqrestore(&state->card->lock, flags);
1103 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: stop_dac()- \n") );
1104}
1105
1106static void start_dac(struct cs_state *state)
1107{
1108 struct dmabuf *dmabuf = &state->dmabuf;
1109 struct cs_card *card = state->card;
1110 unsigned long flags;
1111 int tmp;
1112
1113 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: start_dac()+ \n") );
1114 spin_lock_irqsave(&card->lock, flags);
1115 if (!(dmabuf->enable & DAC_RUNNING) &&
1116 ((dmabuf->mapped || dmabuf->count > 0) && dmabuf->ready) &&
1117 ((card->pm.flags & CS46XX_PM_IDLE) ||
1118 (card->pm.flags & CS46XX_PM_RESUMED)) )
1119 {
1120 dmabuf->enable |= DAC_RUNNING;
1121 tmp = cs461x_peek(card, BA1_PCTL);
1122 tmp &= 0xFFFF;
1123 tmp |= card->pctl;
1124 CS_DBGOUT(CS_PARMS, 6, printk(
1125 "cs46xx: start_dac() poke card=%p tmp=0x%.08x addr=%p \n",
1126 card, (unsigned)tmp,
1127 card->ba1.idx[(BA1_PCTL >> 16) & 3]+(BA1_PCTL&0xffff) ) );
1128 cs461x_poke(card, BA1_PCTL, tmp);
1129 }
1130 spin_unlock_irqrestore(&card->lock, flags);
1131 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: start_dac()- \n") );
1132}
1133
1134#define DMABUF_MINORDER 1
1135
1136/*
1137 * allocate DMA buffer, playback and recording buffers are separate.
1138 */
1139static int alloc_dmabuf(struct cs_state *state)
1140{
1141
1142 struct cs_card *card=state->card;
1143 struct dmabuf *dmabuf = &state->dmabuf;
1144 void *rawbuf = NULL;
1145 void *tmpbuff = NULL;
1146 int order;
1147 struct page *map, *mapend;
1148 unsigned long df;
1149
1150 dmabuf->ready = dmabuf->mapped = 0;
1151 dmabuf->SGok = 0;
1152/*
1153* check for order within limits, but do not overwrite value.
1154*/
1155 if((defaultorder > 1) && (defaultorder < 12))
1156 df = defaultorder;
1157 else
1158 df = 2;
1159
1160 for (order = df; order >= DMABUF_MINORDER; order--)
1161 if ( (rawbuf = (void *) pci_alloc_consistent(
1162 card->pci_dev, PAGE_SIZE << order, &dmabuf->dmaaddr)))
1163 break;
1164 if (!rawbuf) {
1165 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
1166 "cs46xx: alloc_dmabuf(): unable to allocate rawbuf\n"));
1167 return -ENOMEM;
1168 }
1169 dmabuf->buforder = order;
1170 dmabuf->rawbuf = rawbuf;
1171 // Now mark the pages as reserved; otherwise the
1172 // remap_pfn_range() in cs46xx_mmap doesn't work.
1173 // 1. get index to last page in mem_map array for rawbuf.
1174 mapend = virt_to_page(dmabuf->rawbuf +
1175 (PAGE_SIZE << dmabuf->buforder) - 1);
1176
1177 // 2. mark each physical page in range as 'reserved'.
1178 for (map = virt_to_page(dmabuf->rawbuf); map <= mapend; map++)
1179 cs4x_mem_map_reserve(map);
1180
1181 CS_DBGOUT(CS_PARMS, 9, printk("cs46xx: alloc_dmabuf(): allocated %ld (order = %d) bytes at %p\n",
1182 PAGE_SIZE << order, order, rawbuf) );
1183
1184/*
1185* only allocate the conversion buffer for the ADC
1186*/
1187 if(dmabuf->type == CS_TYPE_DAC)
1188 {
1189 dmabuf->tmpbuff = NULL;
1190 dmabuf->buforder_tmpbuff = 0;
1191 return 0;
1192 }
1193/*
1194 * now the temp buffer for 16/8 conversions
1195 */
1196
1197 tmpbuff = (void *) pci_alloc_consistent(
1198 card->pci_dev, PAGE_SIZE << order, &dmabuf->dmaaddr_tmpbuff);
1199
1200 if (!tmpbuff)
1201 return -ENOMEM;
1202 CS_DBGOUT(CS_PARMS, 9, printk("cs46xx: allocated %ld (order = %d) bytes at %p\n",
1203 PAGE_SIZE << order, order, tmpbuff) );
1204
1205 dmabuf->tmpbuff = tmpbuff;
1206 dmabuf->buforder_tmpbuff = order;
1207
1208 // Now mark the pages as reserved; otherwise the
1209 // remap_pfn_range() in cs46xx_mmap doesn't work.
1210 // 1. get index to last page in mem_map array for rawbuf.
1211 mapend = virt_to_page(dmabuf->tmpbuff +
1212 (PAGE_SIZE << dmabuf->buforder_tmpbuff) - 1);
1213
1214 // 2. mark each physical page in range as 'reserved'.
1215 for (map = virt_to_page(dmabuf->tmpbuff); map <= mapend; map++)
1216 cs4x_mem_map_reserve(map);
1217 return 0;
1218}
1219
1220/* free DMA buffer */
1221static void dealloc_dmabuf(struct cs_state *state)
1222{
1223 struct dmabuf *dmabuf = &state->dmabuf;
1224 struct page *map, *mapend;
1225
1226 if (dmabuf->rawbuf) {
1227 // Undo prog_dmabuf()'s marking the pages as reserved
1228 mapend = virt_to_page(dmabuf->rawbuf +
1229 (PAGE_SIZE << dmabuf->buforder) - 1);
1230 for (map = virt_to_page(dmabuf->rawbuf); map <= mapend; map++)
1231 cs4x_mem_map_unreserve(map);
1232 free_dmabuf(state->card, dmabuf);
1233 }
1234
1235 if (dmabuf->tmpbuff) {
1236 // Undo prog_dmabuf()'s marking the pages as reserved
1237 mapend = virt_to_page(dmabuf->tmpbuff +
1238 (PAGE_SIZE << dmabuf->buforder_tmpbuff) - 1);
1239 for (map = virt_to_page(dmabuf->tmpbuff); map <= mapend; map++)
1240 cs4x_mem_map_unreserve(map);
1241 free_dmabuf2(state->card, dmabuf);
1242 }
1243
1244 dmabuf->rawbuf = NULL;
1245 dmabuf->tmpbuff = NULL;
1246 dmabuf->mapped = dmabuf->ready = 0;
1247 dmabuf->SGok = 0;
1248}
1249
1250static int __prog_dmabuf(struct cs_state *state)
1251{
1252 struct dmabuf *dmabuf = &state->dmabuf;
1253 unsigned long flags;
1254 unsigned long allocated_pages, allocated_bytes;
1255 unsigned long tmp1, tmp2, fmt=0;
1256 unsigned long *ptmp = (unsigned long *) dmabuf->pbuf;
1257 unsigned long SGarray[9], nSGpages=0;
1258 int ret;
1259
1260 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()+ \n"));
1261/*
1262 * check for CAPTURE and use only non-sg for initial release
1263 */
1264 if(dmabuf->type == CS_TYPE_ADC)
1265 {
1266 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf() ADC\n"));
1267 /*
1268 * add in non-sg support for capture.
1269 */
1270 spin_lock_irqsave(&state->card->lock, flags);
1271 /* add code to reset the rawbuf memory. TRW */
1272 resync_dma_ptrs(state);
1273 dmabuf->total_bytes = dmabuf->blocks = 0;
1274 dmabuf->count = dmabuf->error = dmabuf->underrun = 0;
1275
1276 dmabuf->SGok = 0;
1277
1278 spin_unlock_irqrestore(&state->card->lock, flags);
1279
1280 /* allocate DMA buffer if not allocated yet */
1281 if (!dmabuf->rawbuf || !dmabuf->tmpbuff)
1282 if ((ret = alloc_dmabuf(state)))
1283 return ret;
1284 /*
1285 * static image only supports 16Bit signed, stereo - hard code fmt
1286 */
1287 fmt = CS_FMT_16BIT | CS_FMT_STEREO;
1288
1289 dmabuf->numfrag = 2;
1290 dmabuf->fragsize = 2048;
1291 dmabuf->fragsamples = 2048 >> sample_shift[fmt];
1292 dmabuf->dmasize = 4096;
1293 dmabuf->fragshift = 11;
1294
1295 memset(dmabuf->rawbuf, (fmt & CS_FMT_16BIT) ? 0 : 0x80,
1296 dmabuf->dmasize);
1297 memset(dmabuf->tmpbuff, (fmt & CS_FMT_16BIT) ? 0 : 0x80,
1298 PAGE_SIZE<<dmabuf->buforder_tmpbuff);
1299
1300 /*
1301 * Now set up the ring
1302 */
1303
1304 spin_lock_irqsave(&state->card->lock, flags);
1305 cs_rec_setup(state);
1306 spin_unlock_irqrestore(&state->card->lock, flags);
1307
1308 /* set the ready flag for the dma buffer */
1309 dmabuf->ready = 1;
1310
1311 CS_DBGOUT(CS_PARMS, 4, printk(
1312 "cs46xx: prog_dmabuf(): CAPTURE rate=%d fmt=0x%x numfrag=%d "
1313 "fragsize=%d dmasize=%d\n",
1314 dmabuf->rate, dmabuf->fmt, dmabuf->numfrag,
1315 dmabuf->fragsize, dmabuf->dmasize) );
1316
1317 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- 0 \n"));
1318 return 0;
1319 }
1320 else if (dmabuf->type == CS_TYPE_DAC)
1321 {
1322 /*
1323 * Must be DAC
1324 */
1325 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf() DAC\n"));
1326 spin_lock_irqsave(&state->card->lock, flags);
1327 resync_dma_ptrs(state);
1328 dmabuf->total_bytes = dmabuf->blocks = 0;
1329 dmabuf->count = dmabuf->error = dmabuf->underrun = 0;
1330
1331 dmabuf->SGok = 0;
1332
1333 spin_unlock_irqrestore(&state->card->lock, flags);
1334
1335 /* allocate DMA buffer if not allocated yet */
1336 if (!dmabuf->rawbuf)
1337 if ((ret = alloc_dmabuf(state)))
1338 return ret;
1339
1340 allocated_pages = 1 << dmabuf->buforder;
1341 allocated_bytes = allocated_pages*PAGE_SIZE;
1342
1343 if(allocated_pages < 2)
1344 {
1345 CS_DBGOUT(CS_FUNCTION, 4, printk(
1346 "cs46xx: prog_dmabuf() Error: allocated_pages too small (%d)\n",
1347 (unsigned)allocated_pages));
1348 return -ENOMEM;
1349 }
1350
1351 /* Use all the pages allocated, fragsize 4k. */
1352 /* Use 'pbuf' for S/G page map table. */
1353 dmabuf->SGok = 1; /* Use S/G. */
1354
1355 nSGpages = allocated_bytes/4096; /* S/G pages always 4k. */
1356
1357 /* Set up S/G variables. */
1358 *ptmp = virt_to_bus(dmabuf->rawbuf);
1359 *(ptmp+1) = 0x00000008;
1360 for(tmp1= 1; tmp1 < nSGpages; tmp1++) {
1361 *(ptmp+2*tmp1) = virt_to_bus( (dmabuf->rawbuf)+4096*tmp1);
1362 if( tmp1 == nSGpages-1)
1363 tmp2 = 0xbfff0000;
1364 else
1365 tmp2 = 0x80000000+8*(tmp1+1);
1366 *(ptmp+2*tmp1+1) = tmp2;
1367 }
1368 SGarray[0] = 0x82c0200d;
1369 SGarray[1] = 0xffff0000;
1370 SGarray[2] = *ptmp;
1371 SGarray[3] = 0x00010600;
1372 SGarray[4] = *(ptmp+2);
1373 SGarray[5] = 0x80000010;
1374 SGarray[6] = *ptmp;
1375 SGarray[7] = *(ptmp+2);
1376 SGarray[8] = (virt_to_bus(dmabuf->pbuf) & 0xffff000) | 0x10;
1377
1378 if (dmabuf->SGok) {
1379 dmabuf->numfrag = nSGpages;
1380 dmabuf->fragsize = 4096;
1381 dmabuf->fragsamples = 4096 >> sample_shift[dmabuf->fmt];
1382 dmabuf->fragshift = 12;
1383 dmabuf->dmasize = dmabuf->numfrag*4096;
1384 }
1385 else {
1386 SGarray[0] = 0xf2c0000f;
1387 SGarray[1] = 0x00000200;
1388 SGarray[2] = 0;
1389 SGarray[3] = 0x00010600;
1390 SGarray[4]=SGarray[5]=SGarray[6]=SGarray[7]=SGarray[8] = 0;
1391 dmabuf->numfrag = 2;
1392 dmabuf->fragsize = 2048;
1393 dmabuf->fragsamples = 2048 >> sample_shift[dmabuf->fmt];
1394 dmabuf->dmasize = 4096;
1395 dmabuf->fragshift = 11;
1396 }
1397 for(tmp1 = 0; tmp1 < sizeof(SGarray)/4; tmp1++)
1398 cs461x_poke( state->card, BA1_PDTC+tmp1*4, SGarray[tmp1]);
1399
1400 memset(dmabuf->rawbuf, (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80,
1401 dmabuf->dmasize);
1402
1403 /*
1404 * Now set up the ring
1405 */
1406
1407 spin_lock_irqsave(&state->card->lock, flags);
1408 cs_play_setup(state);
1409 spin_unlock_irqrestore(&state->card->lock, flags);
1410
1411 /* set the ready flag for the dma buffer */
1412 dmabuf->ready = 1;
1413
1414 CS_DBGOUT(CS_PARMS, 4, printk(
1415 "cs46xx: prog_dmabuf(): PLAYBACK rate=%d fmt=0x%x numfrag=%d "
1416 "fragsize=%d dmasize=%d\n",
1417 dmabuf->rate, dmabuf->fmt, dmabuf->numfrag,
1418 dmabuf->fragsize, dmabuf->dmasize) );
1419
1420 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- \n"));
1421 return 0;
1422 }
1423 else
1424 {
1425 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- Invalid Type %d\n",
1426 dmabuf->type));
1427 }
1428 return 1;
1429}
1430
1431static int prog_dmabuf(struct cs_state *state)
1432{
1433 int ret;
1434
1435 down(&state->sem);
1436 ret = __prog_dmabuf(state);
1437 up(&state->sem);
1438
1439 return ret;
1440}
1441
1442static void cs_clear_tail(struct cs_state *state)
1443{
1444}
1445
1446static int drain_dac(struct cs_state *state, int nonblock)
1447{
1448 DECLARE_WAITQUEUE(wait, current);
1449 struct dmabuf *dmabuf = &state->dmabuf;
1450 struct cs_card *card=state->card;
1451 unsigned long flags;
1452 unsigned long tmo;
1453 int count;
1454
1455 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: drain_dac()+ \n"));
1456 if (dmabuf->mapped || !dmabuf->ready)
1457 {
1458 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: drain_dac()- 0, not ready\n"));
1459 return 0;
1460 }
1461
1462 add_wait_queue(&dmabuf->wait, &wait);
1463 for (;;) {
1464 /* It seems that we have to set the current state to TASK_INTERRUPTIBLE
1465 every time to make the process really go to sleep */
1466 current->state = TASK_INTERRUPTIBLE;
1467
1468 spin_lock_irqsave(&state->card->lock, flags);
1469 count = dmabuf->count;
1470 spin_unlock_irqrestore(&state->card->lock, flags);
1471
1472 if (count <= 0)
1473 break;
1474
1475 if (signal_pending(current))
1476 break;
1477
1478 if (nonblock) {
1479 remove_wait_queue(&dmabuf->wait, &wait);
1480 current->state = TASK_RUNNING;
1481 return -EBUSY;
1482 }
1483
1484 tmo = (dmabuf->dmasize * HZ) / dmabuf->rate;
1485 tmo >>= sample_shift[dmabuf->fmt];
1486 tmo += (2048*HZ)/dmabuf->rate;
1487
1488 if (!schedule_timeout(tmo ? tmo : 1) && tmo){
1489 printk(KERN_ERR "cs46xx: drain_dac, dma timeout? %d\n", count);
1490 break;
1491 }
1492 }
1493 remove_wait_queue(&dmabuf->wait, &wait);
1494 current->state = TASK_RUNNING;
1495 if (signal_pending(current))
1496 {
1497 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: drain_dac()- -ERESTARTSYS\n"));
1498 /*
1499 * set to silence and let that clear the fifos.
1500 */
1501 cs461x_clear_serial_FIFOs(card, CS_TYPE_DAC);
1502 return -ERESTARTSYS;
1503 }
1504
1505 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: drain_dac()- 0\n"));
1506 return 0;
1507}
1508
1509
1510/* update buffer manangement pointers, especially, dmabuf->count and dmabuf->hwptr */
1511static void cs_update_ptr(struct cs_card *card, int wake)
1512{
1513 struct cs_state *state;
1514 struct dmabuf *dmabuf;
1515 unsigned hwptr;
1516 int diff;
1517
1518 /* error handling and process wake up for ADC */
1519 state = card->states[0];
1520 if(state)
1521 {
1522 dmabuf = &state->dmabuf;
1523 if (dmabuf->enable & ADC_RUNNING) {
1524 /* update hardware pointer */
1525 hwptr = cs_get_dma_addr(state);
1526
1527 diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize;
1528 CS_DBGOUT(CS_PARMS, 9, printk(
1529 "cs46xx: cs_update_ptr()+ ADC hwptr=%d diff=%d\n",
1530 hwptr,diff) );
1531 dmabuf->hwptr = hwptr;
1532 dmabuf->total_bytes += diff;
1533 dmabuf->count += diff;
1534 if (dmabuf->count > dmabuf->dmasize)
1535 dmabuf->count = dmabuf->dmasize;
1536
1537 if(dmabuf->mapped)
1538 {
1539 if (wake && dmabuf->count >= (signed)dmabuf->fragsize)
1540 wake_up(&dmabuf->wait);
1541 } else
1542 {
1543 if (wake && dmabuf->count > 0)
1544 wake_up(&dmabuf->wait);
1545 }
1546 }
1547 }
1548
1549/*
1550 * Now the DAC
1551 */
1552 state = card->states[1];
1553 if(state)
1554 {
1555 dmabuf = &state->dmabuf;
1556 /* error handling and process wake up for DAC */
1557 if (dmabuf->enable & DAC_RUNNING) {
1558 /* update hardware pointer */
1559 hwptr = cs_get_dma_addr(state);
1560
1561 diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize;
1562 CS_DBGOUT(CS_PARMS, 9, printk(
1563 "cs46xx: cs_update_ptr()+ DAC hwptr=%d diff=%d\n",
1564 hwptr,diff) );
1565 dmabuf->hwptr = hwptr;
1566 dmabuf->total_bytes += diff;
1567 if (dmabuf->mapped) {
1568 dmabuf->count += diff;
1569 if (wake && dmabuf->count >= (signed)dmabuf->fragsize)
1570 wake_up(&dmabuf->wait);
1571 /*
1572 * other drivers use fragsize, but don't see any sense
1573 * in that, since dmasize is the buffer asked for
1574 * via mmap.
1575 */
1576 if( dmabuf->count > dmabuf->dmasize)
1577 dmabuf->count &= dmabuf->dmasize-1;
1578 } else {
1579 dmabuf->count -= diff;
1580 /*
1581 * backfill with silence and clear out the last
1582 * "diff" number of bytes.
1583 */
1584 if(hwptr >= diff)
1585 {
1586 memset(dmabuf->rawbuf + hwptr - diff,
1587 (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80, diff);
1588 }
1589 else
1590 {
1591 memset(dmabuf->rawbuf,
1592 (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80,
1593 (unsigned)hwptr);
1594 memset((char *)dmabuf->rawbuf +
1595 dmabuf->dmasize + hwptr - diff,
1596 (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80,
1597 diff - hwptr);
1598 }
1599
1600 if (dmabuf->count < 0 || dmabuf->count > dmabuf->dmasize) {
1601 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
1602 "cs46xx: ERROR DAC count<0 or count > dmasize (%d)\n",
1603 dmabuf->count));
1604 /*
1605 * buffer underrun or buffer overrun, reset the
1606 * count of bytes written back to 0.
1607 */
1608 if(dmabuf->count < 0)
1609 dmabuf->underrun=1;
1610 dmabuf->count = 0;
1611 dmabuf->error++;
1612 }
1613 if (wake && dmabuf->count < (signed)dmabuf->dmasize/2)
1614 wake_up(&dmabuf->wait);
1615 }
1616 }
1617 }
1618}
1619
1620
1621/* hold spinlock for the following! */
1622static void cs_handle_midi(struct cs_card *card)
1623{
1624 unsigned char ch;
1625 int wake;
1626 unsigned temp1;
1627
1628 wake = 0;
1629 while (!(cs461x_peekBA0(card, BA0_MIDSR) & MIDSR_RBE)) {
1630 ch = cs461x_peekBA0(card, BA0_MIDRP);
1631 if (card->midi.icnt < CS_MIDIINBUF) {
1632 card->midi.ibuf[card->midi.iwr] = ch;
1633 card->midi.iwr = (card->midi.iwr + 1) % CS_MIDIINBUF;
1634 card->midi.icnt++;
1635 }
1636 wake = 1;
1637 }
1638 if (wake)
1639 wake_up(&card->midi.iwait);
1640 wake = 0;
1641 while (!(cs461x_peekBA0(card, BA0_MIDSR) & MIDSR_TBF) && card->midi.ocnt > 0) {
1642 temp1 = ( card->midi.obuf[card->midi.ord] ) & 0x000000ff;
1643 cs461x_pokeBA0(card, BA0_MIDWP,temp1);
1644 card->midi.ord = (card->midi.ord + 1) % CS_MIDIOUTBUF;
1645 card->midi.ocnt--;
1646 if (card->midi.ocnt < CS_MIDIOUTBUF-16)
1647 wake = 1;
1648 }
1649 if (wake)
1650 wake_up(&card->midi.owait);
1651}
1652
1653static irqreturn_t cs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1654{
1655 struct cs_card *card = (struct cs_card *)dev_id;
1656 /* Single channel card */
1657 struct cs_state *recstate = card->channel[0].state;
1658 struct cs_state *playstate = card->channel[1].state;
1659 u32 status;
1660
1661 CS_DBGOUT(CS_INTERRUPT, 9, printk("cs46xx: cs_interrupt()+ \n"));
1662
1663 spin_lock(&card->lock);
1664
1665 status = cs461x_peekBA0(card, BA0_HISR);
1666
1667 if ((status & 0x7fffffff) == 0)
1668 {
1669 cs461x_pokeBA0(card, BA0_HICR, HICR_CHGM|HICR_IEV);
1670 spin_unlock(&card->lock);
1671 return IRQ_HANDLED; /* Might be IRQ_NONE.. */
1672 }
1673
1674 /*
1675 * check for playback or capture interrupt only
1676 */
1677 if( ((status & HISR_VC0) && playstate && playstate->dmabuf.ready) ||
1678 (((status & HISR_VC1) && recstate && recstate->dmabuf.ready)) )
1679 {
1680 CS_DBGOUT(CS_INTERRUPT, 8, printk(
1681 "cs46xx: cs_interrupt() interrupt bit(s) set (0x%x)\n",status));
1682 cs_update_ptr(card, CS_TRUE);
1683 }
1684
1685 if( status & HISR_MIDI )
1686 cs_handle_midi(card);
1687
1688 /* clear 'em */
1689 cs461x_pokeBA0(card, BA0_HICR, HICR_CHGM|HICR_IEV);
1690 spin_unlock(&card->lock);
1691 CS_DBGOUT(CS_INTERRUPT, 9, printk("cs46xx: cs_interrupt()- \n"));
1692 return IRQ_HANDLED;
1693}
1694
1695
1696/**********************************************************************/
1697
1698static ssize_t cs_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1699{
1700 struct cs_card *card = (struct cs_card *)file->private_data;
1701 ssize_t ret;
1702 unsigned long flags;
1703 unsigned ptr;
1704 int cnt;
1705
1706 if (!access_ok(VERIFY_WRITE, buffer, count))
1707 return -EFAULT;
1708 ret = 0;
1709 while (count > 0) {
1710 spin_lock_irqsave(&card->lock, flags);
1711 ptr = card->midi.ird;
1712 cnt = CS_MIDIINBUF - ptr;
1713 if (card->midi.icnt < cnt)
1714 cnt = card->midi.icnt;
1715 spin_unlock_irqrestore(&card->lock, flags);
1716 if (cnt > count)
1717 cnt = count;
1718 if (cnt <= 0) {
1719 if (file->f_flags & O_NONBLOCK)
1720 return ret ? ret : -EAGAIN;
1721 interruptible_sleep_on(&card->midi.iwait);
1722 if (signal_pending(current))
1723 return ret ? ret : -ERESTARTSYS;
1724 continue;
1725 }
1726 if (copy_to_user(buffer, card->midi.ibuf + ptr, cnt))
1727 return ret ? ret : -EFAULT;
1728 ptr = (ptr + cnt) % CS_MIDIINBUF;
1729 spin_lock_irqsave(&card->lock, flags);
1730 card->midi.ird = ptr;
1731 card->midi.icnt -= cnt;
1732 spin_unlock_irqrestore(&card->lock, flags);
1733 count -= cnt;
1734 buffer += cnt;
1735 ret += cnt;
1736 }
1737 return ret;
1738}
1739
1740
1741static ssize_t cs_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1742{
1743 struct cs_card *card = (struct cs_card *)file->private_data;
1744 ssize_t ret;
1745 unsigned long flags;
1746 unsigned ptr;
1747 int cnt;
1748
1749 if (!access_ok(VERIFY_READ, buffer, count))
1750 return -EFAULT;
1751 ret = 0;
1752 while (count > 0) {
1753 spin_lock_irqsave(&card->lock, flags);
1754 ptr = card->midi.owr;
1755 cnt = CS_MIDIOUTBUF - ptr;
1756 if (card->midi.ocnt + cnt > CS_MIDIOUTBUF)
1757 cnt = CS_MIDIOUTBUF - card->midi.ocnt;
1758 if (cnt <= 0)
1759 cs_handle_midi(card);
1760 spin_unlock_irqrestore(&card->lock, flags);
1761 if (cnt > count)
1762 cnt = count;
1763 if (cnt <= 0) {
1764 if (file->f_flags & O_NONBLOCK)
1765 return ret ? ret : -EAGAIN;
1766 interruptible_sleep_on(&card->midi.owait);
1767 if (signal_pending(current))
1768 return ret ? ret : -ERESTARTSYS;
1769 continue;
1770 }
1771 if (copy_from_user(card->midi.obuf + ptr, buffer, cnt))
1772 return ret ? ret : -EFAULT;
1773 ptr = (ptr + cnt) % CS_MIDIOUTBUF;
1774 spin_lock_irqsave(&card->lock, flags);
1775 card->midi.owr = ptr;
1776 card->midi.ocnt += cnt;
1777 spin_unlock_irqrestore(&card->lock, flags);
1778 count -= cnt;
1779 buffer += cnt;
1780 ret += cnt;
1781 spin_lock_irqsave(&card->lock, flags);
1782 cs_handle_midi(card);
1783 spin_unlock_irqrestore(&card->lock, flags);
1784 }
1785 return ret;
1786}
1787
1788
1789static unsigned int cs_midi_poll(struct file *file, struct poll_table_struct *wait)
1790{
1791 struct cs_card *card = (struct cs_card *)file->private_data;
1792 unsigned long flags;
1793 unsigned int mask = 0;
1794
1795 if (file->f_flags & FMODE_WRITE)
1796 poll_wait(file, &card->midi.owait, wait);
1797 if (file->f_flags & FMODE_READ)
1798 poll_wait(file, &card->midi.iwait, wait);
1799 spin_lock_irqsave(&card->lock, flags);
1800 if (file->f_flags & FMODE_READ) {
1801 if (card->midi.icnt > 0)
1802 mask |= POLLIN | POLLRDNORM;
1803 }
1804 if (file->f_flags & FMODE_WRITE) {
1805 if (card->midi.ocnt < CS_MIDIOUTBUF)
1806 mask |= POLLOUT | POLLWRNORM;
1807 }
1808 spin_unlock_irqrestore(&card->lock, flags);
1809 return mask;
1810}
1811
1812
1813static int cs_midi_open(struct inode *inode, struct file *file)
1814{
1815 unsigned int minor = iminor(inode);
1816 struct cs_card *card=NULL;
1817 unsigned long flags;
1818 struct list_head *entry;
1819
1820 list_for_each(entry, &cs46xx_devs)
1821 {
1822 card = list_entry(entry, struct cs_card, list);
1823 if (card->dev_midi == minor)
1824 break;
1825 }
1826
1827 if (entry == &cs46xx_devs)
1828 return -ENODEV;
1829 if (!card)
1830 {
1831 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
1832 "cs46xx: cs46xx_midi_open(): Error - unable to find card struct\n"));
1833 return -ENODEV;
1834 }
1835
1836 file->private_data = card;
1837 /* wait for device to become free */
1838 down(&card->midi.open_sem);
1839 while (card->midi.open_mode & file->f_mode) {
1840 if (file->f_flags & O_NONBLOCK) {
1841 up(&card->midi.open_sem);
1842 return -EBUSY;
1843 }
1844 up(&card->midi.open_sem);
1845 interruptible_sleep_on(&card->midi.open_wait);
1846 if (signal_pending(current))
1847 return -ERESTARTSYS;
1848 down(&card->midi.open_sem);
1849 }
1850 spin_lock_irqsave(&card->midi.lock, flags);
1851 if (!(card->midi.open_mode & (FMODE_READ | FMODE_WRITE))) {
1852 card->midi.ird = card->midi.iwr = card->midi.icnt = 0;
1853 card->midi.ord = card->midi.owr = card->midi.ocnt = 0;
1854 card->midi.ird = card->midi.iwr = card->midi.icnt = 0;
1855 cs461x_pokeBA0(card, BA0_MIDCR, 0x0000000f); /* Enable xmit, rcv. */
1856 cs461x_pokeBA0(card, BA0_HICR, HICR_IEV | HICR_CHGM); /* Enable interrupts */
1857 }
1858 if (file->f_mode & FMODE_READ) {
1859 card->midi.ird = card->midi.iwr = card->midi.icnt = 0;
1860 }
1861 if (file->f_mode & FMODE_WRITE) {
1862 card->midi.ord = card->midi.owr = card->midi.ocnt = 0;
1863 }
1864 spin_unlock_irqrestore(&card->midi.lock, flags);
1865 card->midi.open_mode |= (file->f_mode & (FMODE_READ | FMODE_WRITE));
1866 up(&card->midi.open_sem);
1867 return 0;
1868}
1869
1870
1871static int cs_midi_release(struct inode *inode, struct file *file)
1872{
1873 struct cs_card *card = (struct cs_card *)file->private_data;
1874 DECLARE_WAITQUEUE(wait, current);
1875 unsigned long flags;
1876 unsigned count, tmo;
1877
1878 if (file->f_mode & FMODE_WRITE) {
1879 current->state = TASK_INTERRUPTIBLE;
1880 add_wait_queue(&card->midi.owait, &wait);
1881 for (;;) {
1882 spin_lock_irqsave(&card->midi.lock, flags);
1883 count = card->midi.ocnt;
1884 spin_unlock_irqrestore(&card->midi.lock, flags);
1885 if (count <= 0)
1886 break;
1887 if (signal_pending(current))
1888 break;
1889 if (file->f_flags & O_NONBLOCK)
1890 break;
1891 tmo = (count * HZ) / 3100;
1892 if (!schedule_timeout(tmo ? : 1) && tmo)
1893 printk(KERN_DEBUG "cs46xx: midi timed out??\n");
1894 }
1895 remove_wait_queue(&card->midi.owait, &wait);
1896 current->state = TASK_RUNNING;
1897 }
1898 down(&card->midi.open_sem);
1899 card->midi.open_mode &= (~(file->f_mode & (FMODE_READ | FMODE_WRITE)));
1900 up(&card->midi.open_sem);
1901 wake_up(&card->midi.open_wait);
1902 return 0;
1903}
1904
1905/*
1906 * Midi file operations struct.
1907 */
1908static /*const*/ struct file_operations cs_midi_fops = {
1909 CS_OWNER CS_THIS_MODULE
1910 .llseek = no_llseek,
1911 .read = cs_midi_read,
1912 .write = cs_midi_write,
1913 .poll = cs_midi_poll,
1914 .open = cs_midi_open,
1915 .release = cs_midi_release,
1916};
1917
1918/*
1919 *
1920 * CopySamples copies 16-bit stereo signed samples from the source to the
1921 * destination, possibly converting down to unsigned 8-bit and/or mono.
1922 * count specifies the number of output bytes to write.
1923 *
1924 * Arguments:
1925 *
1926 * dst - Pointer to a destination buffer.
1927 * src - Pointer to a source buffer
1928 * count - The number of bytes to copy into the destination buffer.
1929 * fmt - CS_FMT_16BIT and/or CS_FMT_STEREO bits
1930 * dmabuf - pointer to the dma buffer structure
1931 *
1932 * NOTES: only call this routine if the output desired is not 16 Signed Stereo
1933 *
1934 *
1935 */
1936static void CopySamples(char *dst, char *src, int count, unsigned fmt,
1937 struct dmabuf *dmabuf)
1938{
1939
1940 s32 s32AudioSample;
1941 s16 *psSrc=(s16 *)src;
1942 s16 *psDst=(s16 *)dst;
1943 u8 *pucDst=(u8 *)dst;
1944
1945 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: CopySamples()+ ") );
1946 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
1947 " dst=%p src=%p count=%d fmt=0x%x\n",
1948 dst,src,count,fmt) );
1949
1950 /*
1951 * See if the data should be output as 8-bit unsigned stereo.
1952 */
1953 if((fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT))
1954 {
1955 /*
1956 * Convert each 16-bit signed stereo sample to 8-bit unsigned
1957 * stereo using rounding.
1958 */
1959 psSrc = (s16 *)src;
1960 count = count/2;
1961 while(count--)
1962 {
1963 *(pucDst++) = (u8)(((s16)(*psSrc++) + (s16)0x8000) >> 8);
1964 }
1965 }
1966 /*
1967 * See if the data should be output at 8-bit unsigned mono.
1968 */
1969 else if(!(fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT))
1970 {
1971 /*
1972 * Convert each 16-bit signed stereo sample to 8-bit unsigned
1973 * mono using averaging and rounding.
1974 */
1975 psSrc = (s16 *)src;
1976 count = count/2;
1977 while(count--)
1978 {
1979 s32AudioSample = ((*psSrc)+(*(psSrc + 1)))/2 + (s32)0x80;
1980 if(s32AudioSample > 0x7fff)
1981 s32AudioSample = 0x7fff;
1982 *(pucDst++) = (u8)(((s16)s32AudioSample + (s16)0x8000) >> 8);
1983 psSrc += 2;
1984 }
1985 }
1986 /*
1987 * See if the data should be output at 16-bit signed mono.
1988 */
1989 else if(!(fmt & CS_FMT_STEREO) && (fmt & CS_FMT_16BIT))
1990 {
1991 /*
1992 * Convert each 16-bit signed stereo sample to 16-bit signed
1993 * mono using averaging.
1994 */
1995 psSrc = (s16 *)src;
1996 count = count/2;
1997 while(count--)
1998 {
1999 *(psDst++) = (s16)((*psSrc)+(*(psSrc + 1)))/2;
2000 psSrc += 2;
2001 }
2002 }
2003}
2004
2005/*
2006 * cs_copy_to_user()
2007 * replacement for the standard copy_to_user, to allow for a conversion from
2008 * 16 bit to 8 bit and from stereo to mono, if the record conversion is active.
2009 * The current CS46xx/CS4280 static image only records in 16bit unsigned Stereo,
2010 * so we convert from any of the other format combinations.
2011 */
2012static unsigned cs_copy_to_user(
2013 struct cs_state *s,
2014 void __user *dest,
2015 void *hwsrc,
2016 unsigned cnt,
2017 unsigned *copied)
2018{
2019 struct dmabuf *dmabuf = &s->dmabuf;
2020 void *src = hwsrc; /* default to the standard destination buffer addr */
2021
2022 CS_DBGOUT(CS_FUNCTION, 6, printk(KERN_INFO
2023 "cs_copy_to_user()+ fmt=0x%x cnt=%d dest=%p\n",
2024 dmabuf->fmt,(unsigned)cnt,dest) );
2025
2026 if(cnt > dmabuf->dmasize)
2027 {
2028 cnt = dmabuf->dmasize;
2029 }
2030 if(!cnt)
2031 {
2032 *copied = 0;
2033 return 0;
2034 }
2035 if(dmabuf->divisor != 1)
2036 {
2037 if(!dmabuf->tmpbuff)
2038 {
2039 *copied = cnt/dmabuf->divisor;
2040 return 0;
2041 }
2042
2043 CopySamples((char *)dmabuf->tmpbuff, (char *)hwsrc, cnt,
2044 dmabuf->fmt, dmabuf);
2045 src = dmabuf->tmpbuff;
2046 cnt = cnt/dmabuf->divisor;
2047 }
2048 if (copy_to_user(dest, src, cnt))
2049 {
2050 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_ERR
2051 "cs46xx: cs_copy_to_user()- fault dest=%p src=%p cnt=%d\n",
2052 dest,src,cnt) );
2053 *copied = 0;
2054 return -EFAULT;
2055 }
2056 *copied = cnt;
2057 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO
2058 "cs46xx: cs_copy_to_user()- copied bytes is %d \n",cnt) );
2059 return 0;
2060}
2061
2062/* in this loop, dmabuf.count signifies the amount of data that is waiting to be copied to
2063 the user's buffer. it is filled by the dma machine and drained by this loop. */
2064static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2065{
2066 struct cs_card *card = (struct cs_card *) file->private_data;
2067 struct cs_state *state;
2068 DECLARE_WAITQUEUE(wait, current);
2069 struct dmabuf *dmabuf;
2070 ssize_t ret = 0;
2071 unsigned long flags;
2072 unsigned swptr;
2073 int cnt;
2074 unsigned copied=0;
2075
2076 CS_DBGOUT(CS_WAVE_READ | CS_FUNCTION, 4,
2077 printk("cs46xx: cs_read()+ %zd\n",count) );
2078 state = (struct cs_state *)card->states[0];
2079 if(!state)
2080 return -ENODEV;
2081 dmabuf = &state->dmabuf;
2082
2083 if (dmabuf->mapped)
2084 return -ENXIO;
2085 if (!access_ok(VERIFY_WRITE, buffer, count))
2086 return -EFAULT;
2087
2088 down(&state->sem);
2089 if (!dmabuf->ready && (ret = __prog_dmabuf(state)))
2090 goto out2;
2091
2092 add_wait_queue(&state->dmabuf.wait, &wait);
2093 while (count > 0) {
2094 while(!(card->pm.flags & CS46XX_PM_IDLE))
2095 {
2096 schedule();
2097 if (signal_pending(current)) {
2098 if(!ret) ret = -ERESTARTSYS;
2099 goto out;
2100 }
2101 }
2102 spin_lock_irqsave(&state->card->lock, flags);
2103 swptr = dmabuf->swptr;
2104 cnt = dmabuf->dmasize - swptr;
2105 if (dmabuf->count < cnt)
2106 cnt = dmabuf->count;
2107 if (cnt <= 0)
2108 __set_current_state(TASK_INTERRUPTIBLE);
2109 spin_unlock_irqrestore(&state->card->lock, flags);
2110
2111 if (cnt > (count * dmabuf->divisor))
2112 cnt = count * dmabuf->divisor;
2113 if (cnt <= 0) {
2114 /* buffer is empty, start the dma machine and wait for data to be
2115 recorded */
2116 start_adc(state);
2117 if (file->f_flags & O_NONBLOCK) {
2118 if (!ret) ret = -EAGAIN;
2119 goto out;
2120 }
2121 up(&state->sem);
2122 schedule();
2123 if (signal_pending(current)) {
2124 if(!ret) ret = -ERESTARTSYS;
2125 goto out;
2126 }
2127 down(&state->sem);
2128 if (dmabuf->mapped)
2129 {
2130 if(!ret)
2131 ret = -ENXIO;
2132 goto out;
2133 }
2134 continue;
2135 }
2136
2137 CS_DBGOUT(CS_WAVE_READ, 2, printk(KERN_INFO
2138 "_read() copy_to cnt=%d count=%zd ", cnt,count) );
2139 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
2140 " .dmasize=%d .count=%d buffer=%p ret=%zd\n",
2141 dmabuf->dmasize,dmabuf->count,buffer,ret) );
2142
2143 if (cs_copy_to_user(state, buffer,
2144 (char *)dmabuf->rawbuf + swptr, cnt, &copied))
2145 {
2146 if (!ret) ret = -EFAULT;
2147 goto out;
2148 }
2149 swptr = (swptr + cnt) % dmabuf->dmasize;
2150 spin_lock_irqsave(&card->lock, flags);
2151 dmabuf->swptr = swptr;
2152 dmabuf->count -= cnt;
2153 spin_unlock_irqrestore(&card->lock, flags);
2154 count -= copied;
2155 buffer += copied;
2156 ret += copied;
2157 start_adc(state);
2158 }
2159out:
2160 remove_wait_queue(&state->dmabuf.wait, &wait);
2161out2:
2162 up(&state->sem);
2163 set_current_state(TASK_RUNNING);
2164 CS_DBGOUT(CS_WAVE_READ | CS_FUNCTION, 4,
2165 printk("cs46xx: cs_read()- %zd\n",ret) );
2166 return ret;
2167}
2168
2169/* in this loop, dmabuf.count signifies the amount of data that is waiting to be dma to
2170 the soundcard. it is drained by the dma machine and filled by this loop. */
2171static ssize_t cs_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2172{
2173 struct cs_card *card = (struct cs_card *) file->private_data;
2174 struct cs_state *state;
2175 DECLARE_WAITQUEUE(wait, current);
2176 struct dmabuf *dmabuf;
2177 ssize_t ret;
2178 unsigned long flags;
2179 unsigned swptr;
2180 int cnt;
2181
2182 CS_DBGOUT(CS_WAVE_WRITE | CS_FUNCTION, 4,
2183 printk("cs46xx: cs_write called, count = %zd\n", count) );
2184 state = (struct cs_state *)card->states[1];
2185 if(!state)
2186 return -ENODEV;
2187 if (!access_ok(VERIFY_READ, buffer, count))
2188 return -EFAULT;
2189 dmabuf = &state->dmabuf;
2190
2191 down(&state->sem);
2192 if (dmabuf->mapped)
2193 {
2194 ret = -ENXIO;
2195 goto out;
2196 }
2197
2198 if (!dmabuf->ready && (ret = __prog_dmabuf(state)))
2199 goto out;
2200 add_wait_queue(&state->dmabuf.wait, &wait);
2201 ret = 0;
2202/*
2203* Start the loop to read from the user's buffer and write to the dma buffer.
2204* check for PM events and underrun/overrun in the loop.
2205*/
2206 while (count > 0) {
2207 while(!(card->pm.flags & CS46XX_PM_IDLE))
2208 {
2209 schedule();
2210 if (signal_pending(current)) {
2211 if(!ret) ret = -ERESTARTSYS;
2212 goto out;
2213 }
2214 }
2215 spin_lock_irqsave(&state->card->lock, flags);
2216 if (dmabuf->count < 0) {
2217 /* buffer underrun, we are recovering from sleep_on_timeout,
2218 resync hwptr and swptr */
2219 dmabuf->count = 0;
2220 dmabuf->swptr = dmabuf->hwptr;
2221 }
2222 if (dmabuf->underrun)
2223 {
2224 dmabuf->underrun = 0;
2225 dmabuf->hwptr = cs_get_dma_addr(state);
2226 dmabuf->swptr = dmabuf->hwptr;
2227 }
2228
2229 swptr = dmabuf->swptr;
2230 cnt = dmabuf->dmasize - swptr;
2231 if (dmabuf->count + cnt > dmabuf->dmasize)
2232 cnt = dmabuf->dmasize - dmabuf->count;
2233 if (cnt <= 0)
2234 __set_current_state(TASK_INTERRUPTIBLE);
2235 spin_unlock_irqrestore(&state->card->lock, flags);
2236
2237 if (cnt > count)
2238 cnt = count;
2239 if (cnt <= 0) {
2240 /* buffer is full, start the dma machine and wait for data to be
2241 played */
2242 start_dac(state);
2243 if (file->f_flags & O_NONBLOCK) {
2244 if (!ret) ret = -EAGAIN;
2245 goto out;
2246 }
2247 up(&state->sem);
2248 schedule();
2249 if (signal_pending(current)) {
2250 if(!ret) ret = -ERESTARTSYS;
2251 goto out;
2252 }
2253 down(&state->sem);
2254 if (dmabuf->mapped)
2255 {
2256 if(!ret)
2257 ret = -ENXIO;
2258 goto out;
2259 }
2260 continue;
2261 }
2262 if (copy_from_user(dmabuf->rawbuf + swptr, buffer, cnt)) {
2263 if (!ret) ret = -EFAULT;
2264 goto out;
2265 }
2266 spin_lock_irqsave(&state->card->lock, flags);
2267 swptr = (swptr + cnt) % dmabuf->dmasize;
2268 dmabuf->swptr = swptr;
2269 dmabuf->count += cnt;
2270 if(dmabuf->count > dmabuf->dmasize)
2271 {
2272 CS_DBGOUT(CS_WAVE_WRITE | CS_ERROR, 2, printk(
2273 "cs46xx: cs_write() d->count > dmasize - resetting\n"));
2274 dmabuf->count = dmabuf->dmasize;
2275 }
2276 dmabuf->endcleared = 0;
2277 spin_unlock_irqrestore(&state->card->lock, flags);
2278
2279 count -= cnt;
2280 buffer += cnt;
2281 ret += cnt;
2282 start_dac(state);
2283 }
2284out:
2285 up(&state->sem);
2286 remove_wait_queue(&state->dmabuf.wait, &wait);
2287 set_current_state(TASK_RUNNING);
2288
2289 CS_DBGOUT(CS_WAVE_WRITE | CS_FUNCTION, 2,
2290 printk("cs46xx: cs_write()- ret=%zd\n", ret) );
2291 return ret;
2292}
2293
2294static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait)
2295{
2296 struct cs_card *card = (struct cs_card *)file->private_data;
2297 struct dmabuf *dmabuf;
2298 struct cs_state *state;
2299
2300 unsigned long flags;
2301 unsigned int mask = 0;
2302
2303 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_poll()+ \n"));
2304 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ)))
2305 {
2306 return -EINVAL;
2307 }
2308 if (file->f_mode & FMODE_WRITE)
2309 {
2310 state = card->states[1];
2311 if(state)
2312 {
2313 dmabuf = &state->dmabuf;
2314 poll_wait(file, &dmabuf->wait, wait);
2315 }
2316 }
2317 if (file->f_mode & FMODE_READ)
2318 {
2319 state = card->states[0];
2320 if(state)
2321 {
2322 dmabuf = &state->dmabuf;
2323 poll_wait(file, &dmabuf->wait, wait);
2324 }
2325 }
2326
2327 spin_lock_irqsave(&card->lock, flags);
2328 cs_update_ptr(card, CS_FALSE);
2329 if (file->f_mode & FMODE_READ) {
2330 state = card->states[0];
2331 if(state)
2332 {
2333 dmabuf = &state->dmabuf;
2334 if (dmabuf->count >= (signed)dmabuf->fragsize)
2335 mask |= POLLIN | POLLRDNORM;
2336 }
2337 }
2338 if (file->f_mode & FMODE_WRITE) {
2339 state = card->states[1];
2340 if(state)
2341 {
2342 dmabuf = &state->dmabuf;
2343 if (dmabuf->mapped) {
2344 if (dmabuf->count >= (signed)dmabuf->fragsize)
2345 mask |= POLLOUT | POLLWRNORM;
2346 } else {
2347 if ((signed)dmabuf->dmasize >= dmabuf->count
2348 + (signed)dmabuf->fragsize)
2349 mask |= POLLOUT | POLLWRNORM;
2350 }
2351 }
2352 }
2353 spin_unlock_irqrestore(&card->lock, flags);
2354
2355 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_poll()- (0x%x) \n",
2356 mask));
2357 return mask;
2358}
2359
2360/*
2361 * We let users mmap the ring buffer. Its not the real DMA buffer but
2362 * that side of the code is hidden in the IRQ handling. We do a software
2363 * emulation of DMA from a 64K or so buffer into a 2K FIFO.
2364 * (the hardware probably deserves a moan here but Crystal send me nice
2365 * toys ;)).
2366 */
2367
2368static int cs_mmap(struct file *file, struct vm_area_struct *vma)
2369{
2370 struct cs_card *card = (struct cs_card *)file->private_data;
2371 struct cs_state *state;
2372 struct dmabuf *dmabuf;
2373 int ret = 0;
2374 unsigned long size;
2375
2376 CS_DBGOUT(CS_FUNCTION | CS_PARMS, 2, printk("cs46xx: cs_mmap()+ file=%p %s %s\n",
2377 file, vma->vm_flags & VM_WRITE ? "VM_WRITE" : "",
2378 vma->vm_flags & VM_READ ? "VM_READ" : "") );
2379
2380 if (vma->vm_flags & VM_WRITE) {
2381 state = card->states[1];
2382 if(state)
2383 {
2384 CS_DBGOUT(CS_OPEN, 2, printk(
2385 "cs46xx: cs_mmap() VM_WRITE - state TRUE prog_dmabuf DAC\n") );
2386 if ((ret = prog_dmabuf(state)) != 0)
2387 return ret;
2388 }
2389 } else if (vma->vm_flags & VM_READ) {
2390 state = card->states[0];
2391 if(state)
2392 {
2393 CS_DBGOUT(CS_OPEN, 2, printk(
2394 "cs46xx: cs_mmap() VM_READ - state TRUE prog_dmabuf ADC\n") );
2395 if ((ret = prog_dmabuf(state)) != 0)
2396 return ret;
2397 }
2398 } else {
2399 CS_DBGOUT(CS_ERROR, 2, printk(
2400 "cs46xx: cs_mmap() return -EINVAL\n") );
2401 return -EINVAL;
2402 }
2403
2404/*
2405 * For now ONLY support playback, but seems like the only way to use
2406 * mmap() is to open an FD with RDWR, just read or just write access
2407 * does not function, get an error back from the kernel.
2408 * Also, QuakeIII opens with RDWR! So, there must be something
2409 * to needing read/write access mapping. So, allow read/write but
2410 * use the DAC only.
2411 */
2412 state = card->states[1];
2413 if (!state) {
2414 ret = -EINVAL;
2415 goto out;
2416 }
2417
2418 down(&state->sem);
2419 dmabuf = &state->dmabuf;
2420 if (cs4x_pgoff(vma) != 0)
2421 {
2422 ret = -EINVAL;
2423 goto out;
2424 }
2425 size = vma->vm_end - vma->vm_start;
2426
2427 CS_DBGOUT(CS_PARMS, 2, printk("cs46xx: cs_mmap(): size=%d\n",(unsigned)size) );
2428
2429 if (size > (PAGE_SIZE << dmabuf->buforder))
2430 {
2431 ret = -EINVAL;
2432 goto out;
2433 }
2434 if (remap_pfn_range(vma, vma->vm_start,
2435 virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT,
2436 size, vma->vm_page_prot))
2437 {
2438 ret = -EAGAIN;
2439 goto out;
2440 }
2441 dmabuf->mapped = 1;
2442
2443 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_mmap()-\n") );
2444out:
2445 up(&state->sem);
2446 return ret;
2447}
2448
2449static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2450{
2451 struct cs_card *card = (struct cs_card *)file->private_data;
2452 struct cs_state *state;
2453 struct dmabuf *dmabuf=NULL;
2454 unsigned long flags;
2455 audio_buf_info abinfo;
2456 count_info cinfo;
2457 int val, valsave, mapped, ret;
2458 void __user *argp = (void __user *)arg;
2459 int __user *p = argp;
2460
2461 state = (struct cs_state *)card->states[0];
2462 if(state)
2463 {
2464 dmabuf = &state->dmabuf;
2465 mapped = (file->f_mode & FMODE_READ) && dmabuf->mapped;
2466 }
2467 state = (struct cs_state *)card->states[1];
2468 if(state)
2469 {
2470 dmabuf = &state->dmabuf;
2471 mapped |= (file->f_mode & FMODE_WRITE) && dmabuf->mapped;
2472 }
2473
2474#if CSDEBUG
2475 printioctl(cmd);
2476#endif
2477
2478 switch (cmd)
2479 {
2480 case OSS_GETVERSION:
2481 return put_user(SOUND_VERSION, p);
2482
2483 case SNDCTL_DSP_RESET:
2484 /* FIXME: spin_lock ? */
2485 if (file->f_mode & FMODE_WRITE) {
2486 state = (struct cs_state *)card->states[1];
2487 if(state)
2488 {
2489 dmabuf = &state->dmabuf;
2490 stop_dac(state);
2491 synchronize_irq(card->irq);
2492 dmabuf->ready = 0;
2493 resync_dma_ptrs(state);
2494 dmabuf->swptr = dmabuf->hwptr = 0;
2495 dmabuf->count = dmabuf->total_bytes = 0;
2496 dmabuf->blocks = 0;
2497 dmabuf->SGok = 0;
2498 }
2499 }
2500 if (file->f_mode & FMODE_READ) {
2501 state = (struct cs_state *)card->states[0];
2502 if(state)
2503 {
2504 dmabuf = &state->dmabuf;
2505 stop_adc(state);
2506 synchronize_irq(card->irq);
2507 resync_dma_ptrs(state);
2508 dmabuf->ready = 0;
2509 dmabuf->swptr = dmabuf->hwptr = 0;
2510 dmabuf->count = dmabuf->total_bytes = 0;
2511 dmabuf->blocks = 0;
2512 dmabuf->SGok = 0;
2513 }
2514 }
2515 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_RESET()-\n") );
2516 return 0;
2517
2518 case SNDCTL_DSP_SYNC:
2519 if (file->f_mode & FMODE_WRITE)
2520 return drain_dac(state, file->f_flags & O_NONBLOCK);
2521 return 0;
2522
2523 case SNDCTL_DSP_SPEED: /* set sample rate */
2524 if (get_user(val, p))
2525 return -EFAULT;
2526 if (val >= 0) {
2527 if (file->f_mode & FMODE_READ) {
2528 state = (struct cs_state *)card->states[0];
2529 if(state)
2530 {
2531 dmabuf = &state->dmabuf;
2532 stop_adc(state);
2533 dmabuf->ready = 0;
2534 dmabuf->SGok = 0;
2535 cs_set_adc_rate(state, val);
2536 cs_set_divisor(dmabuf);
2537 }
2538 }
2539 if (file->f_mode & FMODE_WRITE) {
2540 state = (struct cs_state *)card->states[1];
2541 if(state)
2542 {
2543 dmabuf = &state->dmabuf;
2544 stop_dac(state);
2545 dmabuf->ready = 0;
2546 dmabuf->SGok = 0;
2547 cs_set_dac_rate(state, val);
2548 cs_set_divisor(dmabuf);
2549 }
2550 }
2551 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(
2552 "cs46xx: cs_ioctl() DSP_SPEED %s %s %d\n",
2553 file->f_mode & FMODE_WRITE ? "DAC" : "",
2554 file->f_mode & FMODE_READ ? "ADC" : "",
2555 dmabuf->rate ) );
2556 return put_user(dmabuf->rate, p);
2557 }
2558 return put_user(0, p);
2559
2560 case SNDCTL_DSP_STEREO: /* set stereo or mono channel */
2561 if (get_user(val, p))
2562 return -EFAULT;
2563 if (file->f_mode & FMODE_WRITE) {
2564 state = (struct cs_state *)card->states[1];
2565 if(state)
2566 {
2567 dmabuf = &state->dmabuf;
2568 stop_dac(state);
2569 dmabuf->ready = 0;
2570 dmabuf->SGok = 0;
2571 if(val)
2572 dmabuf->fmt |= CS_FMT_STEREO;
2573 else
2574 dmabuf->fmt &= ~CS_FMT_STEREO;
2575 cs_set_divisor(dmabuf);
2576 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(
2577 "cs46xx: DSP_STEREO() DAC %s\n",
2578 (dmabuf->fmt & CS_FMT_STEREO) ?
2579 "STEREO":"MONO") );
2580 }
2581 }
2582 if (file->f_mode & FMODE_READ) {
2583 state = (struct cs_state *)card->states[0];
2584 if(state)
2585 {
2586 dmabuf = &state->dmabuf;
2587 stop_adc(state);
2588 dmabuf->ready = 0;
2589 dmabuf->SGok = 0;
2590 if(val)
2591 dmabuf->fmt |= CS_FMT_STEREO;
2592 else
2593 dmabuf->fmt &= ~CS_FMT_STEREO;
2594 cs_set_divisor(dmabuf);
2595 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(
2596 "cs46xx: DSP_STEREO() ADC %s\n",
2597 (dmabuf->fmt & CS_FMT_STEREO) ?
2598 "STEREO":"MONO") );
2599 }
2600 }
2601 return 0;
2602
2603 case SNDCTL_DSP_GETBLKSIZE:
2604 if (file->f_mode & FMODE_WRITE) {
2605 state = (struct cs_state *)card->states[1];
2606 if(state)
2607 {
2608 dmabuf = &state->dmabuf;
2609 if ((val = prog_dmabuf(state)))
2610 return val;
2611 return put_user(dmabuf->fragsize, p);
2612 }
2613 }
2614 if (file->f_mode & FMODE_READ) {
2615 state = (struct cs_state *)card->states[0];
2616 if(state)
2617 {
2618 dmabuf = &state->dmabuf;
2619 if ((val = prog_dmabuf(state)))
2620 return val;
2621 return put_user(dmabuf->fragsize/dmabuf->divisor,
2622 p);
2623 }
2624 }
2625 return put_user(0, p);
2626
2627 case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format*/
2628 return put_user(AFMT_S16_LE | AFMT_U8, p);
2629
2630 case SNDCTL_DSP_SETFMT: /* Select sample format */
2631 if (get_user(val, p))
2632 return -EFAULT;
2633 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(
2634 "cs46xx: cs_ioctl() DSP_SETFMT %s %s %s %s\n",
2635 file->f_mode & FMODE_WRITE ? "DAC" : "",
2636 file->f_mode & FMODE_READ ? "ADC" : "",
2637 val == AFMT_S16_LE ? "16Bit Signed" : "",
2638 val == AFMT_U8 ? "8Bit Unsigned" : "") );
2639 valsave = val;
2640 if (val != AFMT_QUERY) {
2641 if(val==AFMT_S16_LE || val==AFMT_U8)
2642 {
2643 if (file->f_mode & FMODE_WRITE) {
2644 state = (struct cs_state *)card->states[1];
2645 if(state)
2646 {
2647 dmabuf = &state->dmabuf;
2648 stop_dac(state);
2649 dmabuf->ready = 0;
2650 dmabuf->SGok = 0;
2651 if(val==AFMT_S16_LE)
2652 dmabuf->fmt |= CS_FMT_16BIT;
2653 else
2654 dmabuf->fmt &= ~CS_FMT_16BIT;
2655 cs_set_divisor(dmabuf);
2656 if((ret = prog_dmabuf(state)))
2657 return ret;
2658 }
2659 }
2660 if (file->f_mode & FMODE_READ) {
2661 val = valsave;
2662 state = (struct cs_state *)card->states[0];
2663 if(state)
2664 {
2665 dmabuf = &state->dmabuf;
2666 stop_adc(state);
2667 dmabuf->ready = 0;
2668 dmabuf->SGok = 0;
2669 if(val==AFMT_S16_LE)
2670 dmabuf->fmt |= CS_FMT_16BIT;
2671 else
2672 dmabuf->fmt &= ~CS_FMT_16BIT;
2673 cs_set_divisor(dmabuf);
2674 if((ret = prog_dmabuf(state)))
2675 return ret;
2676 }
2677 }
2678 }
2679 else
2680 {
2681 CS_DBGOUT(CS_IOCTL | CS_ERROR, 2, printk(
2682 "cs46xx: DSP_SETFMT() Unsupported format (0x%x)\n",
2683 valsave) );
2684 }
2685 }
2686 else
2687 {
2688 if(file->f_mode & FMODE_WRITE)
2689 {
2690 state = (struct cs_state *)card->states[1];
2691 if(state)
2692 dmabuf = &state->dmabuf;
2693 }
2694 else if(file->f_mode & FMODE_READ)
2695 {
2696 state = (struct cs_state *)card->states[0];
2697 if(state)
2698 dmabuf = &state->dmabuf;
2699 }
2700 }
2701 if(dmabuf)
2702 {
2703 if(dmabuf->fmt & CS_FMT_16BIT)
2704 return put_user(AFMT_S16_LE, p);
2705 else
2706 return put_user(AFMT_U8, p);
2707 }
2708 return put_user(0, p);
2709
2710 case SNDCTL_DSP_CHANNELS:
2711 if (get_user(val, p))
2712 return -EFAULT;
2713 if (val != 0) {
2714 if (file->f_mode & FMODE_WRITE) {
2715 state = (struct cs_state *)card->states[1];
2716 if(state)
2717 {
2718 dmabuf = &state->dmabuf;
2719 stop_dac(state);
2720 dmabuf->ready = 0;
2721 dmabuf->SGok = 0;
2722 if(val>1)
2723 dmabuf->fmt |= CS_FMT_STEREO;
2724 else
2725 dmabuf->fmt &= ~CS_FMT_STEREO;
2726 cs_set_divisor(dmabuf);
2727 if (prog_dmabuf(state))
2728 return 0;
2729 }
2730 }
2731 if (file->f_mode & FMODE_READ) {
2732 state = (struct cs_state *)card->states[0];
2733 if(state)
2734 {
2735 dmabuf = &state->dmabuf;
2736 stop_adc(state);
2737 dmabuf->ready = 0;
2738 dmabuf->SGok = 0;
2739 if(val>1)
2740 dmabuf->fmt |= CS_FMT_STEREO;
2741 else
2742 dmabuf->fmt &= ~CS_FMT_STEREO;
2743 cs_set_divisor(dmabuf);
2744 if (prog_dmabuf(state))
2745 return 0;
2746 }
2747 }
2748 }
2749 return put_user((dmabuf->fmt & CS_FMT_STEREO) ? 2 : 1,
2750 p);
2751
2752 case SNDCTL_DSP_POST:
2753 /*
2754 * There will be a longer than normal pause in the data.
2755 * so... do nothing, because there is nothing that we can do.
2756 */
2757 return 0;
2758
2759 case SNDCTL_DSP_SUBDIVIDE:
2760 if (file->f_mode & FMODE_WRITE) {
2761 state = (struct cs_state *)card->states[1];
2762 if(state)
2763 {
2764 dmabuf = &state->dmabuf;
2765 if (dmabuf->subdivision)
2766 return -EINVAL;
2767 if (get_user(val, p))
2768 return -EFAULT;
2769 if (val != 1 && val != 2)
2770 return -EINVAL;
2771 dmabuf->subdivision = val;
2772 }
2773 }
2774 if (file->f_mode & FMODE_READ) {
2775 state = (struct cs_state *)card->states[0];
2776 if(state)
2777 {
2778 dmabuf = &state->dmabuf;
2779 if (dmabuf->subdivision)
2780 return -EINVAL;
2781 if (get_user(val, p))
2782 return -EFAULT;
2783 if (val != 1 && val != 2)
2784 return -EINVAL;
2785 dmabuf->subdivision = val;
2786 }
2787 }
2788 return 0;
2789
2790 case SNDCTL_DSP_SETFRAGMENT:
2791 if (get_user(val, p))
2792 return -EFAULT;
2793
2794 if (file->f_mode & FMODE_WRITE) {
2795 state = (struct cs_state *)card->states[1];
2796 if(state)
2797 {
2798 dmabuf = &state->dmabuf;
2799 dmabuf->ossfragshift = val & 0xffff;
2800 dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
2801 }
2802 }
2803 if (file->f_mode & FMODE_READ) {
2804 state = (struct cs_state *)card->states[0];
2805 if(state)
2806 {
2807 dmabuf = &state->dmabuf;
2808 dmabuf->ossfragshift = val & 0xffff;
2809 dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
2810 }
2811 }
2812 return 0;
2813
2814 case SNDCTL_DSP_GETOSPACE:
2815 if (!(file->f_mode & FMODE_WRITE))
2816 return -EINVAL;
2817 state = (struct cs_state *)card->states[1];
2818 if(state)
2819 {
2820 dmabuf = &state->dmabuf;
2821 spin_lock_irqsave(&state->card->lock, flags);
2822 cs_update_ptr(card, CS_TRUE);
2823 abinfo.fragsize = dmabuf->fragsize;
2824 abinfo.fragstotal = dmabuf->numfrag;
2825 /*
2826 * for mmap we always have total space available
2827 */
2828 if (dmabuf->mapped)
2829 abinfo.bytes = dmabuf->dmasize;
2830 else
2831 abinfo.bytes = dmabuf->dmasize - dmabuf->count;
2832
2833 abinfo.fragments = abinfo.bytes >> dmabuf->fragshift;
2834 spin_unlock_irqrestore(&state->card->lock, flags);
2835 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2836 }
2837 return -ENODEV;
2838
2839 case SNDCTL_DSP_GETISPACE:
2840 if (!(file->f_mode & FMODE_READ))
2841 return -EINVAL;
2842 state = (struct cs_state *)card->states[0];
2843 if(state)
2844 {
2845 dmabuf = &state->dmabuf;
2846 spin_lock_irqsave(&state->card->lock, flags);
2847 cs_update_ptr(card, CS_TRUE);
2848 abinfo.fragsize = dmabuf->fragsize/dmabuf->divisor;
2849 abinfo.bytes = dmabuf->count/dmabuf->divisor;
2850 abinfo.fragstotal = dmabuf->numfrag;
2851 abinfo.fragments = abinfo.bytes >> dmabuf->fragshift;
2852 spin_unlock_irqrestore(&state->card->lock, flags);
2853 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2854 }
2855 return -ENODEV;
2856
2857 case SNDCTL_DSP_NONBLOCK:
2858 file->f_flags |= O_NONBLOCK;
2859 return 0;
2860
2861 case SNDCTL_DSP_GETCAPS:
2862 return put_user(DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP,
2863 p);
2864
2865 case SNDCTL_DSP_GETTRIGGER:
2866 val = 0;
2867 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_GETTRIGGER()+\n") );
2868 if (file->f_mode & FMODE_WRITE)
2869 {
2870 state = (struct cs_state *)card->states[1];
2871 if(state)
2872 {
2873 dmabuf = &state->dmabuf;
2874 if(dmabuf->enable & DAC_RUNNING)
2875 val |= PCM_ENABLE_INPUT;
2876 }
2877 }
2878 if (file->f_mode & FMODE_READ)
2879 {
2880 if(state)
2881 {
2882 state = (struct cs_state *)card->states[0];
2883 dmabuf = &state->dmabuf;
2884 if(dmabuf->enable & ADC_RUNNING)
2885 val |= PCM_ENABLE_OUTPUT;
2886 }
2887 }
2888 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_GETTRIGGER()- val=0x%x\n",val) );
2889 return put_user(val, p);
2890
2891 case SNDCTL_DSP_SETTRIGGER:
2892 if (get_user(val, p))
2893 return -EFAULT;
2894 if (file->f_mode & FMODE_READ) {
2895 state = (struct cs_state *)card->states[0];
2896 if(state)
2897 {
2898 dmabuf = &state->dmabuf;
2899 if (val & PCM_ENABLE_INPUT) {
2900 if (!dmabuf->ready && (ret = prog_dmabuf(state)))
2901 return ret;
2902 start_adc(state);
2903 } else
2904 stop_adc(state);
2905 }
2906 }
2907 if (file->f_mode & FMODE_WRITE) {
2908 state = (struct cs_state *)card->states[1];
2909 if(state)
2910 {
2911 dmabuf = &state->dmabuf;
2912 if (val & PCM_ENABLE_OUTPUT) {
2913 if (!dmabuf->ready && (ret = prog_dmabuf(state)))
2914 return ret;
2915 start_dac(state);
2916 } else
2917 stop_dac(state);
2918 }
2919 }
2920 return 0;
2921
2922 case SNDCTL_DSP_GETIPTR:
2923 if (!(file->f_mode & FMODE_READ))
2924 return -EINVAL;
2925 state = (struct cs_state *)card->states[0];
2926 if(state)
2927 {
2928 dmabuf = &state->dmabuf;
2929 spin_lock_irqsave(&state->card->lock, flags);
2930 cs_update_ptr(card, CS_TRUE);
2931 cinfo.bytes = dmabuf->total_bytes/dmabuf->divisor;
2932 cinfo.blocks = dmabuf->count/dmabuf->divisor >> dmabuf->fragshift;
2933 cinfo.ptr = dmabuf->hwptr/dmabuf->divisor;
2934 spin_unlock_irqrestore(&state->card->lock, flags);
2935 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
2936 return -EFAULT;
2937 return 0;
2938 }
2939 return -ENODEV;
2940
2941 case SNDCTL_DSP_GETOPTR:
2942 if (!(file->f_mode & FMODE_WRITE))
2943 return -EINVAL;
2944 state = (struct cs_state *)card->states[1];
2945 if(state)
2946 {
2947 dmabuf = &state->dmabuf;
2948 spin_lock_irqsave(&state->card->lock, flags);
2949 cs_update_ptr(card, CS_TRUE);
2950 cinfo.bytes = dmabuf->total_bytes;
2951 if (dmabuf->mapped)
2952 {
2953 cinfo.blocks = (cinfo.bytes >> dmabuf->fragshift)
2954 - dmabuf->blocks;
2955 CS_DBGOUT(CS_PARMS, 8,
2956 printk("total_bytes=%d blocks=%d dmabuf->blocks=%d\n",
2957 cinfo.bytes,cinfo.blocks,dmabuf->blocks) );
2958 dmabuf->blocks = cinfo.bytes >> dmabuf->fragshift;
2959 }
2960 else
2961 {
2962 cinfo.blocks = dmabuf->count >> dmabuf->fragshift;
2963 }
2964 cinfo.ptr = dmabuf->hwptr;
2965
2966 CS_DBGOUT(CS_PARMS, 4, printk(
2967 "cs46xx: GETOPTR bytes=%d blocks=%d ptr=%d\n",
2968 cinfo.bytes,cinfo.blocks,cinfo.ptr) );
2969 spin_unlock_irqrestore(&state->card->lock, flags);
2970 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
2971 return -EFAULT;
2972 return 0;
2973 }
2974 return -ENODEV;
2975
2976 case SNDCTL_DSP_SETDUPLEX:
2977 return 0;
2978
2979 case SNDCTL_DSP_GETODELAY:
2980 if (!(file->f_mode & FMODE_WRITE))
2981 return -EINVAL;
2982 state = (struct cs_state *)card->states[1];
2983 if(state)
2984 {
2985 dmabuf = &state->dmabuf;
2986 spin_lock_irqsave(&state->card->lock, flags);
2987 cs_update_ptr(card, CS_TRUE);
2988 val = dmabuf->count;
2989 spin_unlock_irqrestore(&state->card->lock, flags);
2990 }
2991 else
2992 val = 0;
2993 return put_user(val, p);
2994
2995 case SOUND_PCM_READ_RATE:
2996 if(file->f_mode & FMODE_READ)
2997 state = (struct cs_state *)card->states[0];
2998 else
2999 state = (struct cs_state *)card->states[1];
3000 if(state)
3001 {
3002 dmabuf = &state->dmabuf;
3003 return put_user(dmabuf->rate, p);
3004 }
3005 return put_user(0, p);
3006
3007
3008 case SOUND_PCM_READ_CHANNELS:
3009 if(file->f_mode & FMODE_READ)
3010 state = (struct cs_state *)card->states[0];
3011 else
3012 state = (struct cs_state *)card->states[1];
3013 if(state)
3014 {
3015 dmabuf = &state->dmabuf;
3016 return put_user((dmabuf->fmt & CS_FMT_STEREO) ? 2 : 1,
3017 p);
3018 }
3019 return put_user(0, p);
3020
3021 case SOUND_PCM_READ_BITS:
3022 if(file->f_mode & FMODE_READ)
3023 state = (struct cs_state *)card->states[0];
3024 else
3025 state = (struct cs_state *)card->states[1];
3026 if(state)
3027 {
3028 dmabuf = &state->dmabuf;
3029 return put_user((dmabuf->fmt & CS_FMT_16BIT) ?
3030 AFMT_S16_LE : AFMT_U8, p);
3031
3032 }
3033 return put_user(0, p);
3034
3035 case SNDCTL_DSP_MAPINBUF:
3036 case SNDCTL_DSP_MAPOUTBUF:
3037 case SNDCTL_DSP_SETSYNCRO:
3038 case SOUND_PCM_WRITE_FILTER:
3039 case SOUND_PCM_READ_FILTER:
3040 return -EINVAL;
3041 }
3042 return -EINVAL;
3043}
3044
3045
3046/*
3047 * AMP control - null AMP
3048 */
3049
3050static void amp_none(struct cs_card *card, int change)
3051{
3052}
3053
3054/*
3055 * Crystal EAPD mode
3056 */
3057
3058static void amp_voyetra(struct cs_card *card, int change)
3059{
3060 /* Manage the EAPD bit on the Crystal 4297
3061 and the Analog AD1885 */
3062
3063 int old=card->amplifier;
3064
3065 card->amplifier+=change;
3066 if(card->amplifier && !old)
3067 {
3068 /* Turn the EAPD amp on */
3069 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL,
3070 cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) |
3071 0x8000);
3072 }
3073 else if(old && !card->amplifier)
3074 {
3075 /* Turn the EAPD amp off */
3076 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL,
3077 cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
3078 ~0x8000);
3079 }
3080}
3081
3082
3083/*
3084 * Game Theatre XP card - EGPIO[2] is used to enable the external amp.
3085 */
3086
3087static void amp_hercules(struct cs_card *card, int change)
3088{
3089 int old=card->amplifier;
3090 if(!card)
3091 {
3092 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
3093 "cs46xx: amp_hercules() called before initialized.\n"));
3094 return;
3095 }
3096 card->amplifier+=change;
3097 if( (card->amplifier && !old) && !(hercules_egpio_disable))
3098 {
3099 CS_DBGOUT(CS_PARMS, 4, printk(KERN_INFO
3100 "cs46xx: amp_hercules() external amp enabled\n"));
3101 cs461x_pokeBA0(card, BA0_EGPIODR,
3102 EGPIODR_GPOE2); /* enable EGPIO2 output */
3103 cs461x_pokeBA0(card, BA0_EGPIOPTR,
3104 EGPIOPTR_GPPT2); /* open-drain on output */
3105 }
3106 else if(old && !card->amplifier)
3107 {
3108 CS_DBGOUT(CS_PARMS, 4, printk(KERN_INFO
3109 "cs46xx: amp_hercules() external amp disabled\n"));
3110 cs461x_pokeBA0(card, BA0_EGPIODR, 0); /* disable */
3111 cs461x_pokeBA0(card, BA0_EGPIOPTR, 0); /* disable */
3112 }
3113}
3114
3115/*
3116 * Handle the CLKRUN on a thinkpad. We must disable CLKRUN support
3117 * whenever we need to beat on the chip.
3118 *
3119 * The original idea and code for this hack comes from David Kaiser at
3120 * Linuxcare. Perhaps one day Crystal will document their chips well
3121 * enough to make them useful.
3122 */
3123
3124static void clkrun_hack(struct cs_card *card, int change)
3125{
3126 struct pci_dev *acpi_dev;
3127 u16 control;
3128 u8 pp;
3129 unsigned long port;
3130 int old=card->active;
3131
3132 card->active+=change;
3133
3134 acpi_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
3135 if(acpi_dev == NULL)
3136 return; /* Not a thinkpad thats for sure */
3137
3138 /* Find the control port */
3139 pci_read_config_byte(acpi_dev, 0x41, &pp);
3140 port=pp<<8;
3141
3142 /* Read ACPI port */
3143 control=inw(port+0x10);
3144
3145 /* Flip CLKRUN off while running */
3146 if(!card->active && old)
3147 {
3148 CS_DBGOUT(CS_PARMS , 9, printk( KERN_INFO
3149 "cs46xx: clkrun() enable clkrun - change=%d active=%d\n",
3150 change,card->active));
3151 outw(control|0x2000, port+0x10);
3152 }
3153 else
3154 {
3155 /*
3156 * sometimes on a resume the bit is set, so always reset the bit.
3157 */
3158 CS_DBGOUT(CS_PARMS , 9, printk( KERN_INFO
3159 "cs46xx: clkrun() disable clkrun - change=%d active=%d\n",
3160 change,card->active));
3161 outw(control&~0x2000, port+0x10);
3162 }
3163}
3164
3165
3166static int cs_open(struct inode *inode, struct file *file)
3167{
3168 struct cs_card *card = (struct cs_card *)file->private_data;
3169 struct cs_state *state = NULL;
3170 struct dmabuf *dmabuf = NULL;
3171 struct list_head *entry;
3172 unsigned int minor = iminor(inode);
3173 int ret=0;
3174 unsigned int tmp;
3175
3176 CS_DBGOUT(CS_OPEN | CS_FUNCTION, 2, printk("cs46xx: cs_open()+ file=%p %s %s\n",
3177 file, file->f_mode & FMODE_WRITE ? "FMODE_WRITE" : "",
3178 file->f_mode & FMODE_READ ? "FMODE_READ" : "") );
3179
3180 list_for_each(entry, &cs46xx_devs)
3181 {
3182 card = list_entry(entry, struct cs_card, list);
3183
3184 if (!((card->dev_audio ^ minor) & ~0xf))
3185 break;
3186 }
3187 if (entry == &cs46xx_devs)
3188 return -ENODEV;
3189 if (!card) {
3190 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
3191 "cs46xx: cs_open(): Error - unable to find audio card struct\n"));
3192 return -ENODEV;
3193 }
3194
3195 /*
3196 * hardcode state[0] for capture, [1] for playback
3197 */
3198 if(file->f_mode & FMODE_READ)
3199 {
3200 CS_DBGOUT(CS_WAVE_READ, 2, printk("cs46xx: cs_open() FMODE_READ\n") );
3201 if (card->states[0] == NULL) {
3202 state = card->states[0] = (struct cs_state *)
3203 kmalloc(sizeof(struct cs_state), GFP_KERNEL);
3204 if (state == NULL)
3205 return -ENOMEM;
3206 memset(state, 0, sizeof(struct cs_state));
3207 init_MUTEX(&state->sem);
3208 dmabuf = &state->dmabuf;
3209 dmabuf->pbuf = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
3210 if(dmabuf->pbuf==NULL)
3211 {
3212 kfree(state);
3213 card->states[0]=NULL;
3214 return -ENOMEM;
3215 }
3216 }
3217 else
3218 {
3219 state = card->states[0];
3220 if(state->open_mode & FMODE_READ)
3221 return -EBUSY;
3222 }
3223 dmabuf->channel = card->alloc_rec_pcm_channel(card);
3224
3225 if (dmabuf->channel == NULL) {
3226 kfree (card->states[0]);
3227 card->states[0] = NULL;
3228 return -ENODEV;
3229 }
3230
3231 /* Now turn on external AMP if needed */
3232 state->card = card;
3233 state->card->active_ctrl(state->card,1);
3234 state->card->amplifier_ctrl(state->card,1);
3235
3236 if( (tmp = cs46xx_powerup(card, CS_POWER_ADC)) )
3237 {
3238 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
3239 "cs46xx: cs46xx_powerup of ADC failed (0x%x)\n",tmp) );
3240 return -EIO;
3241 }
3242
3243 dmabuf->channel->state = state;
3244 /* initialize the virtual channel */
3245 state->virt = 0;
3246 state->magic = CS_STATE_MAGIC;
3247 init_waitqueue_head(&dmabuf->wait);
3248 init_MUTEX(&state->open_sem);
3249 file->private_data = card;
3250
3251 down(&state->open_sem);
3252
3253 /* set default sample format. According to OSS Programmer's Guide /dev/dsp
3254 should be default to unsigned 8-bits, mono, with sample rate 8kHz and
3255 /dev/dspW will accept 16-bits sample */
3256
3257 /* Default input is 8bit mono */
3258 dmabuf->fmt &= ~CS_FMT_MASK;
3259 dmabuf->type = CS_TYPE_ADC;
3260 dmabuf->ossfragshift = 0;
3261 dmabuf->ossmaxfrags = 0;
3262 dmabuf->subdivision = 0;
3263 cs_set_adc_rate(state, 8000);
3264 cs_set_divisor(dmabuf);
3265
3266 state->open_mode |= FMODE_READ;
3267 up(&state->open_sem);
3268 }
3269 if(file->f_mode & FMODE_WRITE)
3270 {
3271 CS_DBGOUT(CS_OPEN, 2, printk("cs46xx: cs_open() FMODE_WRITE\n") );
3272 if (card->states[1] == NULL) {
3273 state = card->states[1] = (struct cs_state *)
3274 kmalloc(sizeof(struct cs_state), GFP_KERNEL);
3275 if (state == NULL)
3276 return -ENOMEM;
3277 memset(state, 0, sizeof(struct cs_state));
3278 init_MUTEX(&state->sem);
3279 dmabuf = &state->dmabuf;
3280 dmabuf->pbuf = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
3281 if(dmabuf->pbuf==NULL)
3282 {
3283 kfree(state);
3284 card->states[1]=NULL;
3285 return -ENOMEM;
3286 }
3287 }
3288 else
3289 {
3290 state = card->states[1];
3291 if(state->open_mode & FMODE_WRITE)
3292 return -EBUSY;
3293 }
3294 dmabuf->channel = card->alloc_pcm_channel(card);
3295
3296 if (dmabuf->channel == NULL) {
3297 kfree (card->states[1]);
3298 card->states[1] = NULL;
3299 return -ENODEV;
3300 }
3301
3302 /* Now turn on external AMP if needed */
3303 state->card = card;
3304 state->card->active_ctrl(state->card,1);
3305 state->card->amplifier_ctrl(state->card,1);
3306
3307 if( (tmp = cs46xx_powerup(card, CS_POWER_DAC)) )
3308 {
3309 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
3310 "cs46xx: cs46xx_powerup of DAC failed (0x%x)\n",tmp) );
3311 return -EIO;
3312 }
3313
3314 dmabuf->channel->state = state;
3315 /* initialize the virtual channel */
3316 state->virt = 1;
3317 state->magic = CS_STATE_MAGIC;
3318 init_waitqueue_head(&dmabuf->wait);
3319 init_MUTEX(&state->open_sem);
3320 file->private_data = card;
3321
3322 down(&state->open_sem);
3323
3324 /* set default sample format. According to OSS Programmer's Guide /dev/dsp
3325 should be default to unsigned 8-bits, mono, with sample rate 8kHz and
3326 /dev/dspW will accept 16-bits sample */
3327
3328 /* Default output is 8bit mono. */
3329 dmabuf->fmt &= ~CS_FMT_MASK;
3330 dmabuf->type = CS_TYPE_DAC;
3331 dmabuf->ossfragshift = 0;
3332 dmabuf->ossmaxfrags = 0;
3333 dmabuf->subdivision = 0;
3334 cs_set_dac_rate(state, 8000);
3335 cs_set_divisor(dmabuf);
3336
3337 state->open_mode |= FMODE_WRITE;
3338 up(&state->open_sem);
3339 if((ret = prog_dmabuf(state)))
3340 return ret;
3341 }
3342 CS_DBGOUT(CS_OPEN | CS_FUNCTION, 2, printk("cs46xx: cs_open()- 0\n") );
3343 return nonseekable_open(inode, file);
3344}
3345
3346static int cs_release(struct inode *inode, struct file *file)
3347{
3348 struct cs_card *card = (struct cs_card *)file->private_data;
3349 struct dmabuf *dmabuf;
3350 struct cs_state *state;
3351 unsigned int tmp;
3352 CS_DBGOUT(CS_RELEASE | CS_FUNCTION, 2, printk("cs46xx: cs_release()+ file=%p %s %s\n",
3353 file, file->f_mode & FMODE_WRITE ? "FMODE_WRITE" : "",
3354 file->f_mode & FMODE_READ ? "FMODE_READ" : "") );
3355
3356 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ)))
3357 {
3358 return -EINVAL;
3359 }
3360 state = card->states[1];
3361 if(state)
3362 {
3363 if ( (state->open_mode & FMODE_WRITE) & (file->f_mode & FMODE_WRITE) )
3364 {
3365 CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_WRITE\n") );
3366 dmabuf = &state->dmabuf;
3367 cs_clear_tail(state);
3368 drain_dac(state, file->f_flags & O_NONBLOCK);
3369 /* stop DMA state machine and free DMA buffers/channels */
3370 down(&state->open_sem);
3371 stop_dac(state);
3372 dealloc_dmabuf(state);
3373 state->card->free_pcm_channel(state->card, dmabuf->channel->num);
3374 free_page((unsigned long)state->dmabuf.pbuf);
3375
3376 /* we're covered by the open_sem */
3377 up(&state->open_sem);
3378 state->card->states[state->virt] = NULL;
3379 state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
3380
3381 if( (tmp = cs461x_powerdown(card, CS_POWER_DAC, CS_FALSE )) )
3382 {
3383 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
3384 "cs46xx: cs_release_mixdev() powerdown DAC failure (0x%x)\n",tmp) );
3385 }
3386
3387 /* Now turn off external AMP if needed */
3388 state->card->amplifier_ctrl(state->card, -1);
3389 state->card->active_ctrl(state->card, -1);
3390
3391 kfree(state);
3392 }
3393 }
3394
3395 state = card->states[0];
3396 if(state)
3397 {
3398 if ( (state->open_mode & FMODE_READ) & (file->f_mode & FMODE_READ) )
3399 {
3400 CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_READ\n") );
3401 dmabuf = &state->dmabuf;
3402 down(&state->open_sem);
3403 stop_adc(state);
3404 dealloc_dmabuf(state);
3405 state->card->free_pcm_channel(state->card, dmabuf->channel->num);
3406 free_page((unsigned long)state->dmabuf.pbuf);
3407
3408 /* we're covered by the open_sem */
3409 up(&state->open_sem);
3410 state->card->states[state->virt] = NULL;
3411 state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
3412
3413 if( (tmp = cs461x_powerdown(card, CS_POWER_ADC, CS_FALSE )) )
3414 {
3415 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
3416 "cs46xx: cs_release_mixdev() powerdown ADC failure (0x%x)\n",tmp) );
3417 }
3418
3419 /* Now turn off external AMP if needed */
3420 state->card->amplifier_ctrl(state->card, -1);
3421 state->card->active_ctrl(state->card, -1);
3422
3423 kfree(state);
3424 }
3425 }
3426
3427 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 2, printk("cs46xx: cs_release()- 0\n") );
3428 return 0;
3429}
3430
3431static void printpm(struct cs_card *s)
3432{
3433 CS_DBGOUT(CS_PM, 9, printk("pm struct:\n"));
3434 CS_DBGOUT(CS_PM, 9, printk("flags:0x%x u32CLKCR1_SAVE: 0%x u32SSPMValue: 0x%x\n",
3435 (unsigned)s->pm.flags,s->pm.u32CLKCR1_SAVE,s->pm.u32SSPMValue));
3436 CS_DBGOUT(CS_PM, 9, printk("u32PPLVCvalue: 0x%x u32PPRVCvalue: 0x%x\n",
3437 s->pm.u32PPLVCvalue,s->pm.u32PPRVCvalue));
3438 CS_DBGOUT(CS_PM, 9, printk("u32FMLVCvalue: 0x%x u32FMRVCvalue: 0x%x\n",
3439 s->pm.u32FMLVCvalue,s->pm.u32FMRVCvalue));
3440 CS_DBGOUT(CS_PM, 9, printk("u32GPIORvalue: 0x%x u32JSCTLvalue: 0x%x\n",
3441 s->pm.u32GPIORvalue,s->pm.u32JSCTLvalue));
3442 CS_DBGOUT(CS_PM, 9, printk("u32SSCR: 0x%x u32SRCSA: 0x%x\n",
3443 s->pm.u32SSCR,s->pm.u32SRCSA));
3444 CS_DBGOUT(CS_PM, 9, printk("u32DacASR: 0x%x u32AdcASR: 0x%x\n",
3445 s->pm.u32DacASR,s->pm.u32AdcASR));
3446 CS_DBGOUT(CS_PM, 9, printk("u32DacSR: 0x%x u32AdcSR: 0x%x\n",
3447 s->pm.u32DacSR,s->pm.u32AdcSR));
3448 CS_DBGOUT(CS_PM, 9, printk("u32MIDCR_Save: 0x%x\n",
3449 s->pm.u32MIDCR_Save));
3450 CS_DBGOUT(CS_PM, 9, printk("u32AC97_powerdown: 0x%x _general_purpose 0x%x\n",
3451 s->pm.u32AC97_powerdown,s->pm.u32AC97_general_purpose));
3452 CS_DBGOUT(CS_PM, 9, printk("u32AC97_master_volume: 0x%x\n",
3453 s->pm.u32AC97_master_volume));
3454 CS_DBGOUT(CS_PM, 9, printk("u32AC97_headphone_volume: 0x%x\n",
3455 s->pm.u32AC97_headphone_volume));
3456 CS_DBGOUT(CS_PM, 9, printk("u32AC97_master_volume_mono: 0x%x\n",
3457 s->pm.u32AC97_master_volume_mono));
3458 CS_DBGOUT(CS_PM, 9, printk("u32AC97_pcm_out_volume: 0x%x\n",
3459 s->pm.u32AC97_pcm_out_volume));
3460 CS_DBGOUT(CS_PM, 9, printk("dmabuf_swptr_play: 0x%x dmabuf_count_play: %d\n",
3461 s->pm.dmabuf_swptr_play,s->pm.dmabuf_count_play));
3462 CS_DBGOUT(CS_PM, 9, printk("dmabuf_swptr_capture: 0x%x dmabuf_count_capture: %d\n",
3463 s->pm.dmabuf_swptr_capture,s->pm.dmabuf_count_capture));
3464
3465}
3466
3467/****************************************************************************
3468*
3469* Suspend - save the ac97 regs, mute the outputs and power down the part.
3470*
3471****************************************************************************/
3472static void cs46xx_ac97_suspend(struct cs_card *card)
3473{
3474 int Count,i;
3475 struct ac97_codec *dev=card->ac97_codec[0];
3476 unsigned int tmp;
3477
3478 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_suspend()+\n"));
3479
3480 if(card->states[1])
3481 {
3482 stop_dac(card->states[1]);
3483 resync_dma_ptrs(card->states[1]);
3484 }
3485 if(card->states[0])
3486 {
3487 stop_adc(card->states[0]);
3488 resync_dma_ptrs(card->states[0]);
3489 }
3490
3491 for(Count = 0x2, i=0; (Count <= CS46XX_AC97_HIGHESTREGTORESTORE)
3492 && (i < CS46XX_AC97_NUMBER_RESTORE_REGS);
3493 Count += 2, i++)
3494 {
3495 card->pm.ac97[i] = cs_ac97_get(dev, BA0_AC97_RESET + Count);
3496 }
3497/*
3498* Save the ac97 volume registers as well as the current powerdown state.
3499* Now, mute the all the outputs (master, headphone, and mono), as well
3500* as the PCM volume, in preparation for powering down the entire part.
3501 card->pm.u32AC97_master_volume = (u32)cs_ac97_get( dev,
3502 (u8)BA0_AC97_MASTER_VOLUME);
3503 card->pm.u32AC97_headphone_volume = (u32)cs_ac97_get(dev,
3504 (u8)BA0_AC97_HEADPHONE_VOLUME);
3505 card->pm.u32AC97_master_volume_mono = (u32)cs_ac97_get(dev,
3506 (u8)BA0_AC97_MASTER_VOLUME_MONO);
3507 card->pm.u32AC97_pcm_out_volume = (u32)cs_ac97_get(dev,
3508 (u8)BA0_AC97_PCM_OUT_VOLUME);
3509*/
3510/*
3511* mute the outputs
3512*/
3513 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME, 0x8000);
3514 cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, 0x8000);
3515 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, 0x8000);
3516 cs_ac97_set(dev, (u8)BA0_AC97_PCM_OUT_VOLUME, 0x8000);
3517
3518/*
3519* save the registers that cause pops
3520*/
3521 card->pm.u32AC97_powerdown = (u32)cs_ac97_get(dev, (u8)AC97_POWER_CONTROL);
3522 card->pm.u32AC97_general_purpose = (u32)cs_ac97_get(dev, (u8)BA0_AC97_GENERAL_PURPOSE);
3523/*
3524* And power down everything on the AC97 codec.
3525* well, for now, only power down the DAC/ADC and MIXER VREFON components.
3526* trouble with removing VREF.
3527*/
3528 if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
3529 CS_POWER_MIXVON, CS_TRUE )) )
3530 {
3531 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
3532 "cs46xx: cs46xx_ac97_suspend() failure (0x%x)\n",tmp) );
3533 }
3534
3535 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_suspend()-\n"));
3536}
3537
3538/****************************************************************************
3539*
3540* Resume - power up the part and restore its registers..
3541*
3542****************************************************************************/
3543static void cs46xx_ac97_resume(struct cs_card *card)
3544{
3545 int Count,i;
3546 struct ac97_codec *dev=card->ac97_codec[0];
3547
3548 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_resume()+\n"));
3549
3550/*
3551* First, we restore the state of the general purpose register. This
3552* contains the mic select (mic1 or mic2) and if we restore this after
3553* we restore the mic volume/boost state and mic2 was selected at
3554* suspend time, we will end up with a brief period of time where mic1
3555* is selected with the volume/boost settings for mic2, causing
3556* acoustic feedback. So we restore the general purpose register
3557* first, thereby getting the correct mic selected before we restore
3558* the mic volume/boost.
3559*/
3560 cs_ac97_set(dev, (u8)BA0_AC97_GENERAL_PURPOSE,
3561 (u16)card->pm.u32AC97_general_purpose);
3562/*
3563* Now, while the outputs are still muted, restore the state of power
3564* on the AC97 part.
3565*/
3566 cs_ac97_set(dev, (u8)BA0_AC97_POWERDOWN, (u16)card->pm.u32AC97_powerdown);
3567 mdelay(5 * cs_laptop_wait);
3568/*
3569* Restore just the first set of registers, from register number
3570* 0x02 to the register number that ulHighestRegToRestore specifies.
3571*/
3572 for( Count = 0x2, i=0;
3573 (Count <= CS46XX_AC97_HIGHESTREGTORESTORE)
3574 && (i < CS46XX_AC97_NUMBER_RESTORE_REGS);
3575 Count += 2, i++)
3576 {
3577 cs_ac97_set(dev, (u8)(BA0_AC97_RESET + Count), (u16)card->pm.ac97[i]);
3578 }
3579
3580 /* Check if we have to init the amplifier */
3581 if(card->amp_init)
3582 card->amp_init(card);
3583
3584 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_resume()-\n"));
3585}
3586
3587
3588static int cs46xx_restart_part(struct cs_card *card)
3589{
3590 struct dmabuf *dmabuf;
3591 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
3592 printk( "cs46xx: cs46xx_restart_part()+\n"));
3593 if(card->states[1])
3594 {
3595 dmabuf = &card->states[1]->dmabuf;
3596 dmabuf->ready = 0;
3597 resync_dma_ptrs(card->states[1]);
3598 cs_set_divisor(dmabuf);
3599 if(__prog_dmabuf(card->states[1]))
3600 {
3601 CS_DBGOUT(CS_PM | CS_ERROR, 1,
3602 printk("cs46xx: cs46xx_restart_part()- (-1) prog_dmabuf() dac error\n"));
3603 return -1;
3604 }
3605 cs_set_dac_rate(card->states[1], dmabuf->rate);
3606 }
3607 if(card->states[0])
3608 {
3609 dmabuf = &card->states[0]->dmabuf;
3610 dmabuf->ready = 0;
3611 resync_dma_ptrs(card->states[0]);
3612 cs_set_divisor(dmabuf);
3613 if(__prog_dmabuf(card->states[0]))
3614 {
3615 CS_DBGOUT(CS_PM | CS_ERROR, 1,
3616 printk("cs46xx: cs46xx_restart_part()- (-1) prog_dmabuf() adc error\n"));
3617 return -1;
3618 }
3619 cs_set_adc_rate(card->states[0], dmabuf->rate);
3620 }
3621 card->pm.flags |= CS46XX_PM_RESUMED;
3622 if(card->states[0])
3623 start_adc(card->states[0]);
3624 if(card->states[1])
3625 start_dac(card->states[1]);
3626
3627 card->pm.flags |= CS46XX_PM_IDLE;
3628 card->pm.flags &= ~(CS46XX_PM_SUSPENDING | CS46XX_PM_SUSPENDED
3629 | CS46XX_PM_RESUMING | CS46XX_PM_RESUMED);
3630 if(card->states[0])
3631 wake_up(&card->states[0]->dmabuf.wait);
3632 if(card->states[1])
3633 wake_up(&card->states[1]->dmabuf.wait);
3634
3635 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
3636 printk( "cs46xx: cs46xx_restart_part()-\n"));
3637 return 0;
3638}
3639
3640
3641static void cs461x_reset(struct cs_card *card);
3642static void cs461x_proc_stop(struct cs_card *card);
3643static int cs46xx_suspend(struct cs_card *card, u32 state)
3644{
3645 unsigned int tmp;
3646 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
3647 printk("cs46xx: cs46xx_suspend()+ flags=0x%x s=%p\n",
3648 (unsigned)card->pm.flags,card));
3649/*
3650* check the current state, only suspend if IDLE
3651*/
3652 if(!(card->pm.flags & CS46XX_PM_IDLE))
3653 {
3654 CS_DBGOUT(CS_PM | CS_ERROR, 2,
3655 printk("cs46xx: cs46xx_suspend() unable to suspend, not IDLE\n"));
3656 return 1;
3657 }
3658 card->pm.flags &= ~CS46XX_PM_IDLE;
3659 card->pm.flags |= CS46XX_PM_SUSPENDING;
3660
3661 card->active_ctrl(card,1);
3662
3663 tmp = cs461x_peek(card, BA1_PFIE);
3664 tmp &= ~0x0000f03f;
3665 tmp |= 0x00000010;
3666 cs461x_poke(card, BA1_PFIE, tmp); /* playback interrupt disable */
3667
3668 tmp = cs461x_peek(card, BA1_CIE);
3669 tmp &= ~0x0000003f;
3670 tmp |= 0x00000011;
3671 cs461x_poke(card, BA1_CIE, tmp); /* capture interrupt disable */
3672
3673 /*
3674 * Stop playback DMA.
3675 */
3676 tmp = cs461x_peek(card, BA1_PCTL);
3677 cs461x_poke(card, BA1_PCTL, tmp & 0x0000ffff);
3678
3679 /*
3680 * Stop capture DMA.
3681 */
3682 tmp = cs461x_peek(card, BA1_CCTL);
3683 cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000);
3684
3685 if(card->states[1])
3686 {
3687 card->pm.dmabuf_swptr_play = card->states[1]->dmabuf.swptr;
3688 card->pm.dmabuf_count_play = card->states[1]->dmabuf.count;
3689 }
3690 if(card->states[0])
3691 {
3692 card->pm.dmabuf_swptr_capture = card->states[0]->dmabuf.swptr;
3693 card->pm.dmabuf_count_capture = card->states[0]->dmabuf.count;
3694 }
3695
3696 cs46xx_ac97_suspend(card);
3697
3698 /*
3699 * Reset the processor.
3700 */
3701 cs461x_reset(card);
3702
3703 cs461x_proc_stop(card);
3704
3705 /*
3706 * Power down the DAC and ADC. For now leave the other areas on.
3707 */
3708 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, 0x0300);
3709
3710 /*
3711 * Power down the PLL.
3712 */
3713 cs461x_pokeBA0(card, BA0_CLKCR1, 0);
3714
3715 /*
3716 * Turn off the Processor by turning off the software clock enable flag in
3717 * the clock control register.
3718 */
3719 tmp = cs461x_peekBA0(card, BA0_CLKCR1) & ~CLKCR1_SWCE;
3720 cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
3721
3722 card->active_ctrl(card,-1);
3723
3724 card->pm.flags &= ~CS46XX_PM_SUSPENDING;
3725 card->pm.flags |= CS46XX_PM_SUSPENDED;
3726
3727 printpm(card);
3728
3729 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
3730 printk("cs46xx: cs46xx_suspend()- flags=0x%x\n",
3731 (unsigned)card->pm.flags));
3732 return 0;
3733}
3734
3735static int cs46xx_resume(struct cs_card *card)
3736{
3737 int i;
3738
3739 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
3740 printk( "cs46xx: cs46xx_resume()+ flags=0x%x\n",
3741 (unsigned)card->pm.flags));
3742 if(!(card->pm.flags & CS46XX_PM_SUSPENDED))
3743 {
3744 CS_DBGOUT(CS_PM | CS_ERROR, 2,
3745 printk("cs46xx: cs46xx_resume() unable to resume, not SUSPENDED\n"));
3746 return 1;
3747 }
3748 card->pm.flags |= CS46XX_PM_RESUMING;
3749 card->pm.flags &= ~CS46XX_PM_SUSPENDED;
3750 printpm(card);
3751 card->active_ctrl(card, 1);
3752
3753 for(i=0;i<5;i++)
3754 {
3755 if (cs_hardware_init(card) != 0)
3756 {
3757 CS_DBGOUT(CS_PM | CS_ERROR, 4, printk(
3758 "cs46xx: cs46xx_resume()- ERROR in cs_hardware_init()\n"));
3759 mdelay(10 * cs_laptop_wait);
3760 cs461x_reset(card);
3761 continue;
3762 }
3763 break;
3764 }
3765 if(i>=4)
3766 {
3767 CS_DBGOUT(CS_PM | CS_ERROR, 1, printk(
3768 "cs46xx: cs46xx_resume()- cs_hardware_init() failed, retried %d times.\n",i));
3769 return 0;
3770 }
3771
3772 if(cs46xx_restart_part(card))
3773 {
3774 CS_DBGOUT(CS_PM | CS_ERROR, 4, printk(
3775 "cs46xx: cs46xx_resume(): cs46xx_restart_part() returned error\n"));
3776 }
3777
3778 card->active_ctrl(card, -1);
3779
3780 CS_DBGOUT(CS_PM | CS_FUNCTION, 4, printk("cs46xx: cs46xx_resume()- flags=0x%x\n",
3781 (unsigned)card->pm.flags));
3782 return 0;
3783}
3784
3785static /*const*/ struct file_operations cs461x_fops = {
3786 CS_OWNER CS_THIS_MODULE
3787 .llseek = no_llseek,
3788 .read = cs_read,
3789 .write = cs_write,
3790 .poll = cs_poll,
3791 .ioctl = cs_ioctl,
3792 .mmap = cs_mmap,
3793 .open = cs_open,
3794 .release = cs_release,
3795};
3796
3797/* Write AC97 codec registers */
3798
3799
3800static u16 _cs_ac97_get(struct ac97_codec *dev, u8 reg)
3801{
3802 struct cs_card *card = dev->private_data;
3803 int count,loopcnt;
3804 unsigned int tmp;
3805 u16 ret;
3806
3807 /*
3808 * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
3809 * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97
3810 * 3. Write ACCTL = Control Register = 460h for initiating the write
3811 * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 17h
3812 * 5. if DCV not cleared, break and return error
3813 * 6. Read ACSTS = Status Register = 464h, check VSTS bit
3814 */
3815
3816 cs461x_peekBA0(card, BA0_ACSDA);
3817
3818 /*
3819 * Setup the AC97 control registers on the CS461x to send the
3820 * appropriate command to the AC97 to perform the read.
3821 * ACCAD = Command Address Register = 46Ch
3822 * ACCDA = Command Data Register = 470h
3823 * ACCTL = Control Register = 460h
3824 * set DCV - will clear when process completed
3825 * set CRW - Read command
3826 * set VFRM - valid frame enabled
3827 * set ESYN - ASYNC generation enabled
3828 * set RSTN - ARST# inactive, AC97 codec not reset
3829 */
3830
3831 cs461x_pokeBA0(card, BA0_ACCAD, reg);
3832 cs461x_pokeBA0(card, BA0_ACCDA, 0);
3833 cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_DCV | ACCTL_CRW |
3834 ACCTL_VFRM | ACCTL_ESYN |
3835 ACCTL_RSTN);
3836
3837
3838 /*
3839 * Wait for the read to occur.
3840 */
3841 if(!(card->pm.flags & CS46XX_PM_IDLE))
3842 loopcnt = 2000;
3843 else
3844 loopcnt = 500 * cs_laptop_wait;
3845 loopcnt *= cs_laptop_wait;
3846 for (count = 0; count < loopcnt; count++) {
3847 /*
3848 * First, we want to wait for a short time.
3849 */
3850 udelay(10 * cs_laptop_wait);
3851 /*
3852 * Now, check to see if the read has completed.
3853 * ACCTL = 460h, DCV should be reset by now and 460h = 17h
3854 */
3855 if (!(cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV))
3856 break;
3857 }
3858
3859 /*
3860 * Make sure the read completed.
3861 */
3862 if (cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV) {
3863 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
3864 "cs46xx: AC'97 read problem (ACCTL_DCV), reg = 0x%x returning 0xffff\n", reg));
3865 return 0xffff;
3866 }
3867
3868 /*
3869 * Wait for the valid status bit to go active.
3870 */
3871
3872 if(!(card->pm.flags & CS46XX_PM_IDLE))
3873 loopcnt = 2000;
3874 else
3875 loopcnt = 1000;
3876 loopcnt *= cs_laptop_wait;
3877 for (count = 0; count < loopcnt; count++) {
3878 /*
3879 * Read the AC97 status register.
3880 * ACSTS = Status Register = 464h
3881 * VSTS - Valid Status
3882 */
3883 if (cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_VSTS)
3884 break;
3885 udelay(10 * cs_laptop_wait);
3886 }
3887
3888 /*
3889 * Make sure we got valid status.
3890 */
3891 if (!( (tmp=cs461x_peekBA0(card, BA0_ACSTS)) & ACSTS_VSTS)) {
3892 CS_DBGOUT(CS_ERROR, 2, printk(KERN_WARNING
3893 "cs46xx: AC'97 read problem (ACSTS_VSTS), reg = 0x%x val=0x%x 0xffff \n",
3894 reg, tmp));
3895 return 0xffff;
3896 }
3897
3898 /*
3899 * Read the data returned from the AC97 register.
3900 * ACSDA = Status Data Register = 474h
3901 */
3902 CS_DBGOUT(CS_FUNCTION, 9, printk(KERN_INFO
3903 "cs46xx: cs_ac97_get() reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%x\n",
3904 reg, cs461x_peekBA0(card, BA0_ACSDA),
3905 cs461x_peekBA0(card, BA0_ACCAD)));
3906 ret = cs461x_peekBA0(card, BA0_ACSDA);
3907 return ret;
3908}
3909
3910static u16 cs_ac97_get(struct ac97_codec *dev, u8 reg)
3911{
3912 u16 ret;
3913 struct cs_card *card = dev->private_data;
3914
3915 spin_lock(&card->ac97_lock);
3916 ret = _cs_ac97_get(dev, reg);
3917 spin_unlock(&card->ac97_lock);
3918 return ret;
3919}
3920
3921static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 val)
3922{
3923 struct cs_card *card = dev->private_data;
3924 int count;
3925 int val2 = 0;
3926
3927 spin_lock(&card->ac97_lock);
3928
3929 if(reg == AC97_CD_VOL)
3930 {
3931 val2 = _cs_ac97_get(dev, AC97_CD_VOL);
3932 }
3933
3934
3935 /*
3936 * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
3937 * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97
3938 * 3. Write ACCTL = Control Register = 460h for initiating the write
3939 * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 07h
3940 * 5. if DCV not cleared, break and return error
3941 */
3942
3943 /*
3944 * Setup the AC97 control registers on the CS461x to send the
3945 * appropriate command to the AC97 to perform the read.
3946 * ACCAD = Command Address Register = 46Ch
3947 * ACCDA = Command Data Register = 470h
3948 * ACCTL = Control Register = 460h
3949 * set DCV - will clear when process completed
3950 * reset CRW - Write command
3951 * set VFRM - valid frame enabled
3952 * set ESYN - ASYNC generation enabled
3953 * set RSTN - ARST# inactive, AC97 codec not reset
3954 */
3955 cs461x_pokeBA0(card, BA0_ACCAD, reg);
3956 cs461x_pokeBA0(card, BA0_ACCDA, val);
3957 cs461x_peekBA0(card, BA0_ACCTL);
3958 cs461x_pokeBA0(card, BA0_ACCTL, 0 | ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN);
3959 cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_DCV | ACCTL_VFRM |
3960 ACCTL_ESYN | ACCTL_RSTN);
3961 for (count = 0; count < 1000; count++) {
3962 /*
3963 * First, we want to wait for a short time.
3964 */
3965 udelay(10 * cs_laptop_wait);
3966 /*
3967 * Now, check to see if the write has completed.
3968 * ACCTL = 460h, DCV should be reset by now and 460h = 07h
3969 */
3970 if (!(cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV))
3971 break;
3972 }
3973 /*
3974 * Make sure the write completed.
3975 */
3976 if (cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV)
3977 {
3978 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
3979 "cs46xx: AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val));
3980 }
3981
3982 spin_unlock(&card->ac97_lock);
3983
3984 /*
3985 * Adjust power if the mixer is selected/deselected according
3986 * to the CD.
3987 *
3988 * IF the CD is a valid input source (mixer or direct) AND
3989 * the CD is not muted THEN power is needed
3990 *
3991 * We do two things. When record select changes the input to
3992 * add/remove the CD we adjust the power count if the CD is
3993 * unmuted.
3994 *
3995 * When the CD mute changes we adjust the power level if the
3996 * CD was a valid input.
3997 *
3998 * We also check for CD volume != 0, as the CD mute isn't
3999 * normally tweaked from userspace.
4000 */
4001
4002 /* CD mute change ? */
4003
4004 if(reg==AC97_CD_VOL)
4005 {
4006 /* Mute bit change ? */
4007 if((val2^val)&0x8000 || ((val2 == 0x1f1f || val == 0x1f1f) && val2 != val))
4008 {
4009 /* This is a hack but its cleaner than the alternatives.
4010 Right now card->ac97_codec[0] might be NULL as we are
4011 still doing codec setup. This does an early assignment
4012 to avoid the problem if it occurs */
4013
4014 if(card->ac97_codec[0]==NULL)
4015 card->ac97_codec[0]=dev;
4016
4017 /* Mute on */
4018 if(val&0x8000 || val == 0x1f1f)
4019 card->amplifier_ctrl(card, -1);
4020 else /* Mute off power on */
4021 {
4022 if(card->amp_init)
4023 card->amp_init(card);
4024 card->amplifier_ctrl(card, 1);
4025 }
4026 }
4027 }
4028}
4029
4030
4031/* OSS /dev/mixer file operation methods */
4032
4033static int cs_open_mixdev(struct inode *inode, struct file *file)
4034{
4035 int i=0;
4036 unsigned int minor = iminor(inode);
4037 struct cs_card *card=NULL;
4038 struct list_head *entry;
4039 unsigned int tmp;
4040
4041 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
4042 printk(KERN_INFO "cs46xx: cs_open_mixdev()+\n"));
4043
4044 list_for_each(entry, &cs46xx_devs)
4045 {
4046 card = list_entry(entry, struct cs_card, list);
4047 for (i = 0; i < NR_AC97; i++)
4048 if (card->ac97_codec[i] != NULL &&
4049 card->ac97_codec[i]->dev_mixer == minor)
4050 goto match;
4051 }
4052 if (!card)
4053 {
4054 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
4055 printk(KERN_INFO "cs46xx: cs46xx_open_mixdev()- -ENODEV\n"));
4056 return -ENODEV;
4057 }
4058 match:
4059 if(!card->ac97_codec[i])
4060 return -ENODEV;
4061 file->private_data = card->ac97_codec[i];
4062
4063 card->active_ctrl(card,1);
4064 if(!CS_IN_USE(&card->mixer_use_cnt))
4065 {
4066 if( (tmp = cs46xx_powerup(card, CS_POWER_MIXVON )) )
4067 {
4068 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
4069 "cs46xx: cs_open_mixdev() powerup failure (0x%x)\n",tmp) );
4070 return -EIO;
4071 }
4072 }
4073 card->amplifier_ctrl(card, 1);
4074 CS_INC_USE_COUNT(&card->mixer_use_cnt);
4075 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
4076 printk(KERN_INFO "cs46xx: cs_open_mixdev()- 0\n"));
4077 return nonseekable_open(inode, file);
4078}
4079
4080static int cs_release_mixdev(struct inode *inode, struct file *file)
4081{
4082 unsigned int minor = iminor(inode);
4083 struct cs_card *card=NULL;
4084 struct list_head *entry;
4085 int i;
4086 unsigned int tmp;
4087
4088 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 4,
4089 printk(KERN_INFO "cs46xx: cs_release_mixdev()+\n"));
4090 list_for_each(entry, &cs46xx_devs)
4091 {
4092 card = list_entry(entry, struct cs_card, list);
4093 for (i = 0; i < NR_AC97; i++)
4094 if (card->ac97_codec[i] != NULL &&
4095 card->ac97_codec[i]->dev_mixer == minor)
4096 goto match;
4097 }
4098 if (!card)
4099 {
4100 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
4101 printk(KERN_INFO "cs46xx: cs46xx_open_mixdev()- -ENODEV\n"));
4102 return -ENODEV;
4103 }
4104match:
4105 if(!CS_DEC_AND_TEST(&card->mixer_use_cnt))
4106 {
4107 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 4,
4108 printk(KERN_INFO "cs46xx: cs_release_mixdev()- no powerdown, usecnt>0\n"));
4109 card->active_ctrl(card, -1);
4110 card->amplifier_ctrl(card, -1);
4111 return 0;
4112 }
4113/*
4114* ok, no outstanding mixer opens, so powerdown.
4115*/
4116 if( (tmp = cs461x_powerdown(card, CS_POWER_MIXVON, CS_FALSE )) )
4117 {
4118 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
4119 "cs46xx: cs_release_mixdev() powerdown MIXVON failure (0x%x)\n",tmp) );
4120 card->active_ctrl(card, -1);
4121 card->amplifier_ctrl(card, -1);
4122 return -EIO;
4123 }
4124 card->active_ctrl(card, -1);
4125 card->amplifier_ctrl(card, -1);
4126 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 4,
4127 printk(KERN_INFO "cs46xx: cs_release_mixdev()- 0\n"));
4128 return 0;
4129}
4130
4131static int cs_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
4132 unsigned long arg)
4133{
4134 struct ac97_codec *codec = (struct ac97_codec *)file->private_data;
4135 struct cs_card *card=NULL;
4136 struct list_head *entry;
4137 unsigned long __user *p = (long __user *)arg;
4138
4139#if CSDEBUG_INTERFACE
4140 int val;
4141
4142 if( (cmd == SOUND_MIXER_CS_GETDBGMASK) ||
4143 (cmd == SOUND_MIXER_CS_SETDBGMASK) ||
4144 (cmd == SOUND_MIXER_CS_GETDBGLEVEL) ||
4145 (cmd == SOUND_MIXER_CS_SETDBGLEVEL) ||
4146 (cmd == SOUND_MIXER_CS_APM))
4147 {
4148 switch(cmd)
4149 {
4150
4151 case SOUND_MIXER_CS_GETDBGMASK:
4152 return put_user(cs_debugmask, p);
4153
4154 case SOUND_MIXER_CS_GETDBGLEVEL:
4155 return put_user(cs_debuglevel, p);
4156
4157 case SOUND_MIXER_CS_SETDBGMASK:
4158 if (get_user(val, p))
4159 return -EFAULT;
4160 cs_debugmask = val;
4161 return 0;
4162
4163 case SOUND_MIXER_CS_SETDBGLEVEL:
4164 if (get_user(val, p))
4165 return -EFAULT;
4166 cs_debuglevel = val;
4167 return 0;
4168
4169 case SOUND_MIXER_CS_APM:
4170 if (get_user(val, p))
4171 return -EFAULT;
4172 if(val == CS_IOCTL_CMD_SUSPEND)
4173 {
4174 list_for_each(entry, &cs46xx_devs)
4175 {
4176 card = list_entry(entry, struct cs_card, list);
4177 cs46xx_suspend(card, 0);
4178 }
4179
4180 }
4181 else if(val == CS_IOCTL_CMD_RESUME)
4182 {
4183 list_for_each(entry, &cs46xx_devs)
4184 {
4185 card = list_entry(entry, struct cs_card, list);
4186 cs46xx_resume(card);
4187 }
4188 }
4189 else
4190 {
4191 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
4192 "cs46xx: mixer_ioctl(): invalid APM cmd (%d)\n",
4193 val));
4194 }
4195 return 0;
4196
4197 default:
4198 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
4199 "cs46xx: mixer_ioctl(): ERROR unknown debug cmd\n") );
4200 return 0;
4201 }
4202 }
4203#endif
4204 return codec->mixer_ioctl(codec, cmd, arg);
4205}
4206
4207static /*const*/ struct file_operations cs_mixer_fops = {
4208 CS_OWNER CS_THIS_MODULE
4209 .llseek = no_llseek,
4210 .ioctl = cs_ioctl_mixdev,
4211 .open = cs_open_mixdev,
4212 .release = cs_release_mixdev,
4213};
4214
4215/* AC97 codec initialisation. */
4216static int __init cs_ac97_init(struct cs_card *card)
4217{
4218 int num_ac97 = 0;
4219 int ready_2nd = 0;
4220 struct ac97_codec *codec;
4221 u16 eid;
4222
4223 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
4224 "cs46xx: cs_ac97_init()+\n") );
4225
4226 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
4227 if ((codec = ac97_alloc_codec()) == NULL)
4228 return -ENOMEM;
4229
4230 /* initialize some basic codec information, other fields will be filled
4231 in ac97_probe_codec */
4232 codec->private_data = card;
4233 codec->id = num_ac97;
4234
4235 codec->codec_read = cs_ac97_get;
4236 codec->codec_write = cs_ac97_set;
4237
4238 if (ac97_probe_codec(codec) == 0)
4239 {
4240 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
4241 "cs46xx: cs_ac97_init()- codec number %d not found\n",
4242 num_ac97) );
4243 card->ac97_codec[num_ac97] = NULL;
4244 break;
4245 }
4246 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
4247 "cs46xx: cs_ac97_init() found codec %d\n",num_ac97) );
4248
4249 eid = cs_ac97_get(codec, AC97_EXTENDED_ID);
4250
4251 if(eid==0xFFFF)
4252 {
4253 printk(KERN_WARNING "cs46xx: codec %d not present\n",num_ac97);
4254 ac97_release_codec(codec);
4255 break;
4256 }
4257
4258 card->ac97_features = eid;
4259
4260 if ((codec->dev_mixer = register_sound_mixer(&cs_mixer_fops, -1)) < 0) {
4261 printk(KERN_ERR "cs46xx: couldn't register mixer!\n");
4262 ac97_release_codec(codec);
4263 break;
4264 }
4265 card->ac97_codec[num_ac97] = codec;
4266
4267 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
4268 "cs46xx: cs_ac97_init() ac97_codec[%d] set to %p\n",
4269 (unsigned int)num_ac97,
4270 codec));
4271 /* if there is no secondary codec at all, don't probe any more */
4272 if (!ready_2nd)
4273 {
4274 num_ac97 += 1;
4275 break;
4276 }
4277 }
4278 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
4279 "cs46xx: cs_ac97_init()- %d\n", (unsigned int)num_ac97));
4280 return num_ac97;
4281}
4282
4283/*
4284 * load the static image into the DSP
4285 */
4286#include "cs461x_image.h"
4287static void cs461x_download_image(struct cs_card *card)
4288{
4289 unsigned i, j, temp1, temp2, offset, count;
4290 unsigned char __iomem *pBA1 = ioremap(card->ba1_addr, 0x40000);
4291 for( i=0; i < CLEAR__COUNT; i++)
4292 {
4293 offset = ClrStat[i].BA1__DestByteOffset;
4294 count = ClrStat[i].BA1__SourceSize;
4295 for( temp1 = offset; temp1<(offset+count); temp1+=4 )
4296 writel(0, pBA1+temp1);
4297 }
4298
4299 for(i=0; i<FILL__COUNT; i++)
4300 {
4301 temp2 = FillStat[i].Offset;
4302 for(j=0; j<(FillStat[i].Size)/4; j++)
4303 {
4304 temp1 = (FillStat[i]).pFill[j];
4305 writel(temp1, pBA1+temp2+j*4);
4306 }
4307 }
4308 iounmap(pBA1);
4309}
4310
4311
4312/*
4313 * Chip reset
4314 */
4315
4316static void cs461x_reset(struct cs_card *card)
4317{
4318 int idx;
4319
4320 /*
4321 * Write the reset bit of the SP control register.
4322 */
4323 cs461x_poke(card, BA1_SPCR, SPCR_RSTSP);
4324
4325 /*
4326 * Write the control register.
4327 */
4328 cs461x_poke(card, BA1_SPCR, SPCR_DRQEN);
4329
4330 /*
4331 * Clear the trap registers.
4332 */
4333 for (idx = 0; idx < 8; idx++) {
4334 cs461x_poke(card, BA1_DREG, DREG_REGID_TRAP_SELECT + idx);
4335 cs461x_poke(card, BA1_TWPR, 0xFFFF);
4336 }
4337 cs461x_poke(card, BA1_DREG, 0);
4338
4339 /*
4340 * Set the frame timer to reflect the number of cycles per frame.
4341 */
4342 cs461x_poke(card, BA1_FRMT, 0xadf);
4343}
4344
4345static void cs461x_clear_serial_FIFOs(struct cs_card *card, int type)
4346{
4347 int idx, loop, startfifo=0, endfifo=0, powerdown1 = 0;
4348 unsigned int tmp;
4349
4350 /*
4351 * See if the devices are powered down. If so, we must power them up first
4352 * or they will not respond.
4353 */
4354 if (!((tmp = cs461x_peekBA0(card, BA0_CLKCR1)) & CLKCR1_SWCE)) {
4355 cs461x_pokeBA0(card, BA0_CLKCR1, tmp | CLKCR1_SWCE);
4356 powerdown1 = 1;
4357 }
4358
4359 /*
4360 * We want to clear out the serial port FIFOs so we don't end up playing
4361 * whatever random garbage happens to be in them. We fill the sample FIFOS
4362 * with zero (silence).
4363 */
4364 cs461x_pokeBA0(card, BA0_SERBWP, 0);
4365
4366 /*
4367 * Check for which FIFO locations to clear, if we are currently
4368 * playing or capturing then we don't want to put in 128 bytes of
4369 * "noise".
4370 */
4371 if(type & CS_TYPE_DAC)
4372 {
4373 startfifo = 128;
4374 endfifo = 256;
4375 }
4376 if(type & CS_TYPE_ADC)
4377 {
4378 startfifo = 0;
4379 if(!endfifo)
4380 endfifo = 128;
4381 }
4382 /*
4383 * Fill sample FIFO locations (256 locations total).
4384 */
4385 for (idx = startfifo; idx < endfifo; idx++) {
4386 /*
4387 * Make sure the previous FIFO write operation has completed.
4388 */
4389 for (loop = 0; loop < 5; loop++) {
4390 udelay(50);
4391 if (!(cs461x_peekBA0(card, BA0_SERBST) & SERBST_WBSY))
4392 break;
4393 }
4394 if (cs461x_peekBA0(card, BA0_SERBST) & SERBST_WBSY) {
4395 if (powerdown1)
4396 cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
4397 }
4398 /*
4399 * Write the serial port FIFO index.
4400 */
4401 cs461x_pokeBA0(card, BA0_SERBAD, idx);
4402 /*
4403 * Tell the serial port to load the new value into the FIFO location.
4404 */
4405 cs461x_pokeBA0(card, BA0_SERBCM, SERBCM_WRC);
4406 }
4407 /*
4408 * Now, if we powered up the devices, then power them back down again.
4409 * This is kinda ugly, but should never happen.
4410 */
4411 if (powerdown1)
4412 cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
4413}
4414
4415
4416static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspendflag)
4417{
4418 int count;
4419 unsigned int tmp=0,muted=0;
4420
4421 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
4422 "cs46xx: cs461x_powerdown()+ type=0x%x\n",type));
4423 if(!cs_powerdown && !suspendflag)
4424 {
4425 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
4426 "cs46xx: cs461x_powerdown() DISABLED exiting\n"));
4427 return 0;
4428 }
4429 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4430 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
4431 "cs46xx: cs461x_powerdown() powerdown reg=0x%x\n",tmp));
4432/*
4433* if powering down only the VREF, and not powering down the DAC/ADC,
4434* then do not power down the VREF, UNLESS both the DAC and ADC are not
4435* currently powered down. If powering down DAC and ADC, then
4436* it is possible to power down the VREF (ON).
4437*/
4438 if ( ((type & CS_POWER_MIXVON) &&
4439 (!(type & CS_POWER_ADC) || (!(type & CS_POWER_DAC))) )
4440 &&
4441 ((tmp & CS_AC97_POWER_CONTROL_ADC_ON) ||
4442 (tmp & CS_AC97_POWER_CONTROL_DAC_ON) ) )
4443 {
4444 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
4445 "cs46xx: cs461x_powerdown()- 0 unable to powerdown. tmp=0x%x\n",tmp));
4446 return 0;
4447 }
4448/*
4449* for now, always keep power to the mixer block.
4450* not sure why it's a problem but it seems to be if we power off.
4451*/
4452 type &= ~CS_POWER_MIXVON;
4453 type &= ~CS_POWER_MIXVOFF;
4454
4455 /*
4456 * Power down indicated areas.
4457 */
4458 if(type & CS_POWER_MIXVOFF)
4459 {
4460
4461 CS_DBGOUT(CS_FUNCTION, 4,
4462 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ MIXVOFF\n"));
4463 /*
4464 * Power down the MIXER (VREF ON) on the AC97 card.
4465 */
4466 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4467 if (tmp & CS_AC97_POWER_CONTROL_MIXVOFF_ON)
4468 {
4469 if(!muted)
4470 {
4471 cs_mute(card, CS_TRUE);
4472 muted=1;
4473 }
4474 tmp |= CS_AC97_POWER_CONTROL_MIXVOFF;
4475 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
4476 /*
4477 * Now, we wait until we sample a ready state.
4478 */
4479 for (count = 0; count < 32; count++) {
4480 /*
4481 * First, lets wait a short while to let things settle out a
4482 * bit, and to prevent retrying the read too quickly.
4483 */
4484 udelay(500);
4485
4486 /*
4487 * Read the current state of the power control register.
4488 */
4489 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4490 CS_AC97_POWER_CONTROL_MIXVOFF_ON))
4491 break;
4492 }
4493
4494 /*
4495 * Check the status..
4496 */
4497 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4498 CS_AC97_POWER_CONTROL_MIXVOFF_ON)
4499 {
4500 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4501 "cs46xx: powerdown MIXVOFF failed\n"));
4502 return 1;
4503 }
4504 }
4505 }
4506 if(type & CS_POWER_MIXVON)
4507 {
4508
4509 CS_DBGOUT(CS_FUNCTION, 4,
4510 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ MIXVON\n"));
4511 /*
4512 * Power down the MIXER (VREF ON) on the AC97 card.
4513 */
4514 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4515 if (tmp & CS_AC97_POWER_CONTROL_MIXVON_ON)
4516 {
4517 if(!muted)
4518 {
4519 cs_mute(card, CS_TRUE);
4520 muted=1;
4521 }
4522 tmp |= CS_AC97_POWER_CONTROL_MIXVON;
4523 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
4524 /*
4525 * Now, we wait until we sample a ready state.
4526 */
4527 for (count = 0; count < 32; count++) {
4528 /*
4529 * First, lets wait a short while to let things settle out a
4530 * bit, and to prevent retrying the read too quickly.
4531 */
4532 udelay(500);
4533
4534 /*
4535 * Read the current state of the power control register.
4536 */
4537 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4538 CS_AC97_POWER_CONTROL_MIXVON_ON))
4539 break;
4540 }
4541
4542 /*
4543 * Check the status..
4544 */
4545 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4546 CS_AC97_POWER_CONTROL_MIXVON_ON)
4547 {
4548 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4549 "cs46xx: powerdown MIXVON failed\n"));
4550 return 1;
4551 }
4552 }
4553 }
4554 if(type & CS_POWER_ADC)
4555 {
4556 /*
4557 * Power down the ADC on the AC97 card.
4558 */
4559 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO "cs46xx: cs461x_powerdown()+ ADC\n"));
4560 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4561 if (tmp & CS_AC97_POWER_CONTROL_ADC_ON)
4562 {
4563 if(!muted)
4564 {
4565 cs_mute(card, CS_TRUE);
4566 muted=1;
4567 }
4568 tmp |= CS_AC97_POWER_CONTROL_ADC;
4569 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
4570
4571 /*
4572 * Now, we wait until we sample a ready state.
4573 */
4574 for (count = 0; count < 32; count++) {
4575 /*
4576 * First, lets wait a short while to let things settle out a
4577 * bit, and to prevent retrying the read too quickly.
4578 */
4579 udelay(500);
4580
4581 /*
4582 * Read the current state of the power control register.
4583 */
4584 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4585 CS_AC97_POWER_CONTROL_ADC_ON))
4586 break;
4587 }
4588
4589 /*
4590 * Check the status..
4591 */
4592 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4593 CS_AC97_POWER_CONTROL_ADC_ON)
4594 {
4595 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4596 "cs46xx: powerdown ADC failed\n"));
4597 return 1;
4598 }
4599 }
4600 }
4601 if(type & CS_POWER_DAC)
4602 {
4603 /*
4604 * Power down the DAC on the AC97 card.
4605 */
4606
4607 CS_DBGOUT(CS_FUNCTION, 4,
4608 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ DAC\n"));
4609 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4610 if (tmp & CS_AC97_POWER_CONTROL_DAC_ON)
4611 {
4612 if(!muted)
4613 {
4614 cs_mute(card, CS_TRUE);
4615 muted=1;
4616 }
4617 tmp |= CS_AC97_POWER_CONTROL_DAC;
4618 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
4619 /*
4620 * Now, we wait until we sample a ready state.
4621 */
4622 for (count = 0; count < 32; count++) {
4623 /*
4624 * First, lets wait a short while to let things settle out a
4625 * bit, and to prevent retrying the read too quickly.
4626 */
4627 udelay(500);
4628
4629 /*
4630 * Read the current state of the power control register.
4631 */
4632 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4633 CS_AC97_POWER_CONTROL_DAC_ON))
4634 break;
4635 }
4636
4637 /*
4638 * Check the status..
4639 */
4640 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4641 CS_AC97_POWER_CONTROL_DAC_ON)
4642 {
4643 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4644 "cs46xx: powerdown DAC failed\n"));
4645 return 1;
4646 }
4647 }
4648 }
4649 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4650 if(muted)
4651 cs_mute(card, CS_FALSE);
4652 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
4653 "cs46xx: cs461x_powerdown()- 0 tmp=0x%x\n",tmp));
4654 return 0;
4655}
4656
4657static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4658{
4659 int count;
4660 unsigned int tmp=0,muted=0;
4661
4662 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
4663 "cs46xx: cs46xx_powerup()+ type=0x%x\n",type));
4664 /*
4665 * check for VREF and powerup if need to.
4666 */
4667 if(type & CS_POWER_MIXVON)
4668 type |= CS_POWER_MIXVOFF;
4669 if(type & (CS_POWER_DAC | CS_POWER_ADC))
4670 type |= CS_POWER_MIXVON | CS_POWER_MIXVOFF;
4671
4672 /*
4673 * Power up indicated areas.
4674 */
4675 if(type & CS_POWER_MIXVOFF)
4676 {
4677
4678 CS_DBGOUT(CS_FUNCTION, 4,
4679 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ MIXVOFF\n"));
4680 /*
4681 * Power up the MIXER (VREF ON) on the AC97 card.
4682 */
4683 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4684 if (!(tmp & CS_AC97_POWER_CONTROL_MIXVOFF_ON))
4685 {
4686 if(!muted)
4687 {
4688 cs_mute(card, CS_TRUE);
4689 muted=1;
4690 }
4691 tmp &= ~CS_AC97_POWER_CONTROL_MIXVOFF;
4692 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
4693 /*
4694 * Now, we wait until we sample a ready state.
4695 */
4696 for (count = 0; count < 32; count++) {
4697 /*
4698 * First, lets wait a short while to let things settle out a
4699 * bit, and to prevent retrying the read too quickly.
4700 */
4701 udelay(500);
4702
4703 /*
4704 * Read the current state of the power control register.
4705 */
4706 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4707 CS_AC97_POWER_CONTROL_MIXVOFF_ON)
4708 break;
4709 }
4710
4711 /*
4712 * Check the status..
4713 */
4714 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4715 CS_AC97_POWER_CONTROL_MIXVOFF_ON))
4716 {
4717 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4718 "cs46xx: powerup MIXVOFF failed\n"));
4719 return 1;
4720 }
4721 }
4722 }
4723 if(type & CS_POWER_MIXVON)
4724 {
4725
4726 CS_DBGOUT(CS_FUNCTION, 4,
4727 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ MIXVON\n"));
4728 /*
4729 * Power up the MIXER (VREF ON) on the AC97 card.
4730 */
4731 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4732 if (!(tmp & CS_AC97_POWER_CONTROL_MIXVON_ON))
4733 {
4734 if(!muted)
4735 {
4736 cs_mute(card, CS_TRUE);
4737 muted=1;
4738 }
4739 tmp &= ~CS_AC97_POWER_CONTROL_MIXVON;
4740 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
4741 /*
4742 * Now, we wait until we sample a ready state.
4743 */
4744 for (count = 0; count < 32; count++) {
4745 /*
4746 * First, lets wait a short while to let things settle out a
4747 * bit, and to prevent retrying the read too quickly.
4748 */
4749 udelay(500);
4750
4751 /*
4752 * Read the current state of the power control register.
4753 */
4754 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4755 CS_AC97_POWER_CONTROL_MIXVON_ON)
4756 break;
4757 }
4758
4759 /*
4760 * Check the status..
4761 */
4762 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4763 CS_AC97_POWER_CONTROL_MIXVON_ON))
4764 {
4765 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4766 "cs46xx: powerup MIXVON failed\n"));
4767 return 1;
4768 }
4769 }
4770 }
4771 if(type & CS_POWER_ADC)
4772 {
4773 /*
4774 * Power up the ADC on the AC97 card.
4775 */
4776 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO "cs46xx: cs46xx_powerup()+ ADC\n"));
4777 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4778 if (!(tmp & CS_AC97_POWER_CONTROL_ADC_ON))
4779 {
4780 if(!muted)
4781 {
4782 cs_mute(card, CS_TRUE);
4783 muted=1;
4784 }
4785 tmp &= ~CS_AC97_POWER_CONTROL_ADC;
4786 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
4787
4788 /*
4789 * Now, we wait until we sample a ready state.
4790 */
4791 for (count = 0; count < 32; count++) {
4792 /*
4793 * First, lets wait a short while to let things settle out a
4794 * bit, and to prevent retrying the read too quickly.
4795 */
4796 udelay(500);
4797
4798 /*
4799 * Read the current state of the power control register.
4800 */
4801 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4802 CS_AC97_POWER_CONTROL_ADC_ON)
4803 break;
4804 }
4805
4806 /*
4807 * Check the status..
4808 */
4809 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4810 CS_AC97_POWER_CONTROL_ADC_ON))
4811 {
4812 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4813 "cs46xx: powerup ADC failed\n"));
4814 return 1;
4815 }
4816 }
4817 }
4818 if(type & CS_POWER_DAC)
4819 {
4820 /*
4821 * Power up the DAC on the AC97 card.
4822 */
4823
4824 CS_DBGOUT(CS_FUNCTION, 4,
4825 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ DAC\n"));
4826 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4827 if (!(tmp & CS_AC97_POWER_CONTROL_DAC_ON))
4828 {
4829 if(!muted)
4830 {
4831 cs_mute(card, CS_TRUE);
4832 muted=1;
4833 }
4834 tmp &= ~CS_AC97_POWER_CONTROL_DAC;
4835 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
4836 /*
4837 * Now, we wait until we sample a ready state.
4838 */
4839 for (count = 0; count < 32; count++) {
4840 /*
4841 * First, lets wait a short while to let things settle out a
4842 * bit, and to prevent retrying the read too quickly.
4843 */
4844 udelay(500);
4845
4846 /*
4847 * Read the current state of the power control register.
4848 */
4849 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4850 CS_AC97_POWER_CONTROL_DAC_ON)
4851 break;
4852 }
4853
4854 /*
4855 * Check the status..
4856 */
4857 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4858 CS_AC97_POWER_CONTROL_DAC_ON))
4859 {
4860 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4861 "cs46xx: powerup DAC failed\n"));
4862 return 1;
4863 }
4864 }
4865 }
4866 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4867 if(muted)
4868 cs_mute(card, CS_FALSE);
4869 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
4870 "cs46xx: cs46xx_powerup()- 0 tmp=0x%x\n",tmp));
4871 return 0;
4872}
4873
4874
4875static void cs461x_proc_start(struct cs_card *card)
4876{
4877 int cnt;
4878
4879 /*
4880 * Set the frame timer to reflect the number of cycles per frame.
4881 */
4882 cs461x_poke(card, BA1_FRMT, 0xadf);
4883 /*
4884 * Turn on the run, run at frame, and DMA enable bits in the local copy of
4885 * the SP control register.
4886 */
4887 cs461x_poke(card, BA1_SPCR, SPCR_RUN | SPCR_RUNFR | SPCR_DRQEN);
4888 /*
4889 * Wait until the run at frame bit resets itself in the SP control
4890 * register.
4891 */
4892 for (cnt = 0; cnt < 25; cnt++) {
4893 udelay(50);
4894 if (!(cs461x_peek(card, BA1_SPCR) & SPCR_RUNFR))
4895 break;
4896 }
4897
4898 if (cs461x_peek(card, BA1_SPCR) & SPCR_RUNFR)
4899 printk(KERN_WARNING "cs46xx: SPCR_RUNFR never reset\n");
4900}
4901
4902static void cs461x_proc_stop(struct cs_card *card)
4903{
4904 /*
4905 * Turn off the run, run at frame, and DMA enable bits in the local copy of
4906 * the SP control register.
4907 */
4908 cs461x_poke(card, BA1_SPCR, 0);
4909}
4910
4911static int cs_hardware_init(struct cs_card *card)
4912{
4913 unsigned long end_time;
4914 unsigned int tmp,count;
4915
4916 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
4917 "cs46xx: cs_hardware_init()+\n") );
4918 /*
4919 * First, blast the clock control register to zero so that the PLL starts
4920 * out in a known state, and blast the master serial port control register
4921 * to zero so that the serial ports also start out in a known state.
4922 */
4923 cs461x_pokeBA0(card, BA0_CLKCR1, 0);
4924 cs461x_pokeBA0(card, BA0_SERMC1, 0);
4925
4926 /*
4927 * If we are in AC97 mode, then we must set the part to a host controlled
4928 * AC-link. Otherwise, we won't be able to bring up the link.
4929 */
4930 cs461x_pokeBA0(card, BA0_SERACC, SERACC_HSP | SERACC_CODEC_TYPE_1_03); /* 1.03 card */
4931 /* cs461x_pokeBA0(card, BA0_SERACC, SERACC_HSP | SERACC_CODEC_TYPE_2_0); */ /* 2.00 card */
4932
4933 /*
4934 * Drive the ARST# pin low for a minimum of 1uS (as defined in the AC97
4935 * spec) and then drive it high. This is done for non AC97 modes since
4936 * there might be logic external to the CS461x that uses the ARST# line
4937 * for a reset.
4938 */
4939 cs461x_pokeBA0(card, BA0_ACCTL, 1);
4940 udelay(50);
4941 cs461x_pokeBA0(card, BA0_ACCTL, 0);
4942 udelay(50);
4943 cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_RSTN);
4944
4945 /*
4946 * The first thing we do here is to enable sync generation. As soon
4947 * as we start receiving bit clock, we'll start producing the SYNC
4948 * signal.
4949 */
4950 cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_ESYN | ACCTL_RSTN);
4951
4952 /*
4953 * Now wait for a short while to allow the AC97 part to start
4954 * generating bit clock (so we don't try to start the PLL without an
4955 * input clock).
4956 */
4957 mdelay(5 * cs_laptop_wait); /* 1 should be enough ?? (and pigs might fly) */
4958
4959 /*
4960 * Set the serial port timing configuration, so that
4961 * the clock control circuit gets its clock from the correct place.
4962 */
4963 cs461x_pokeBA0(card, BA0_SERMC1, SERMC1_PTC_AC97);
4964
4965 /*
4966 * The part seems to not be ready for a while after a resume.
4967 * so, if we are resuming, then wait for 700 mils. Note that 600 mils
4968 * is not enough for some platforms! tested on an IBM Thinkpads and
4969 * reference cards.
4970 */
4971 if(!(card->pm.flags & CS46XX_PM_IDLE))
4972 mdelay(initdelay);
4973 /*
4974 * Write the selected clock control setup to the hardware. Do not turn on
4975 * SWCE yet (if requested), so that the devices clocked by the output of
4976 * PLL are not clocked until the PLL is stable.
4977 */
4978 cs461x_pokeBA0(card, BA0_PLLCC, PLLCC_LPF_1050_2780_KHZ | PLLCC_CDR_73_104_MHZ);
4979 cs461x_pokeBA0(card, BA0_PLLM, 0x3a);
4980 cs461x_pokeBA0(card, BA0_CLKCR2, CLKCR2_PDIVS_8);
4981
4982 /*
4983 * Power up the PLL.
4984 */
4985 cs461x_pokeBA0(card, BA0_CLKCR1, CLKCR1_PLLP);
4986
4987 /*
4988 * Wait until the PLL has stabilized.
4989 */
4990 mdelay(5 * cs_laptop_wait); /* Again 1 should be enough ?? */
4991
4992 /*
4993 * Turn on clocking of the core so that we can setup the serial ports.
4994 */
4995 tmp = cs461x_peekBA0(card, BA0_CLKCR1) | CLKCR1_SWCE;
4996 cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
4997
4998 /*
4999 * Fill the serial port FIFOs with silence.
5000 */
5001 cs461x_clear_serial_FIFOs(card,CS_TYPE_DAC | CS_TYPE_ADC);
5002
5003 /*
5004 * Set the serial port FIFO pointer to the first sample in the FIFO.
5005 */
5006 /* cs461x_pokeBA0(card, BA0_SERBSP, 0); */
5007
5008 /*
5009 * Write the serial port configuration to the part. The master
5010 * enable bit is not set until all other values have been written.
5011 */
5012 cs461x_pokeBA0(card, BA0_SERC1, SERC1_SO1F_AC97 | SERC1_SO1EN);
5013 cs461x_pokeBA0(card, BA0_SERC2, SERC2_SI1F_AC97 | SERC1_SO1EN);
5014 cs461x_pokeBA0(card, BA0_SERMC1, SERMC1_PTC_AC97 | SERMC1_MSPE);
5015
5016
5017 mdelay(5 * cs_laptop_wait); /* Shouldnt be needed ?? */
5018
5019/*
5020* If we are resuming under 2.2.x then we can not schedule a timeout.
5021* so, just spin the CPU.
5022*/
5023 if(card->pm.flags & CS46XX_PM_IDLE)
5024 {
5025 /*
5026 * Wait for the card ready signal from the AC97 card.
5027 */
5028 end_time = jiffies + 3 * (HZ >> 2);
5029 do {
5030 /*
5031 * Read the AC97 status register to see if we've seen a CODEC READY
5032 * signal from the AC97 card.
5033 */
5034 if (cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_CRDY)
5035 break;
5036 current->state = TASK_UNINTERRUPTIBLE;
5037 schedule_timeout(1);
5038 } while (time_before(jiffies, end_time));
5039 }
5040 else
5041 {
5042 for (count = 0; count < 100; count++) {
5043 // First, we want to wait for a short time.
5044 udelay(25 * cs_laptop_wait);
5045
5046 if (cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_CRDY)
5047 break;
5048 }
5049 }
5050
5051 /*
5052 * Make sure CODEC is READY.
5053 */
5054 if (!(cs461x_peekBA0(card, BA0_ACSTS) & ACSTS_CRDY)) {
5055 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_WARNING
5056 "cs46xx: create - never read card ready from AC'97\n"));
5057 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_WARNING
5058 "cs46xx: probably not a bug, try using the CS4232 driver,\n"));
5059 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_WARNING
5060 "cs46xx: or turn off any automatic Power Management support in the BIOS.\n"));
5061 return -EIO;
5062 }
5063
5064 /*
5065 * Assert the vaid frame signal so that we can start sending commands
5066 * to the AC97 card.
5067 */
5068 cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN);
5069
5070 if(card->pm.flags & CS46XX_PM_IDLE)
5071 {
5072 /*
5073 * Wait until we've sampled input slots 3 and 4 as valid, meaning that
5074 * the card is pumping ADC data across the AC-link.
5075 */
5076 end_time = jiffies + 3 * (HZ >> 2);
5077 do {
5078 /*
5079 * Read the input slot valid register and see if input slots 3 and
5080 * 4 are valid yet.
5081 */
5082 if ((cs461x_peekBA0(card, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4))
5083 break;
5084 current->state = TASK_UNINTERRUPTIBLE;
5085 schedule_timeout(1);
5086 } while (time_before(jiffies, end_time));
5087 }
5088 else
5089 {
5090 for (count = 0; count < 100; count++) {
5091 // First, we want to wait for a short time.
5092 udelay(25 * cs_laptop_wait);
5093
5094 if ((cs461x_peekBA0(card, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4))
5095 break;
5096 }
5097 }
5098 /*
5099 * Make sure input slots 3 and 4 are valid. If not, then return
5100 * an error.
5101 */
5102 if ((cs461x_peekBA0(card, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) != (ACISV_ISV3 | ACISV_ISV4)) {
5103 printk(KERN_WARNING "cs46xx: create - never read ISV3 & ISV4 from AC'97\n");
5104 return -EIO;
5105 }
5106
5107 /*
5108 * Now, assert valid frame and the slot 3 and 4 valid bits. This will
5109 * commense the transfer of digital audio data to the AC97 card.
5110 */
5111 cs461x_pokeBA0(card, BA0_ACOSV, ACOSV_SLV3 | ACOSV_SLV4);
5112
5113 /*
5114 * Turn off the Processor by turning off the software clock enable flag in
5115 * the clock control register.
5116 */
5117 /* tmp = cs461x_peekBA0(card, BA0_CLKCR1) & ~CLKCR1_SWCE; */
5118 /* cs461x_pokeBA0(card, BA0_CLKCR1, tmp); */
5119
5120 /*
5121 * Reset the processor.
5122 */
5123 cs461x_reset(card);
5124
5125 /*
5126 * Download the image to the processor.
5127 */
5128
5129 cs461x_download_image(card);
5130
5131 /*
5132 * Stop playback DMA.
5133 */
5134 tmp = cs461x_peek(card, BA1_PCTL);
5135 card->pctl = tmp & 0xffff0000;
5136 cs461x_poke(card, BA1_PCTL, tmp & 0x0000ffff);
5137
5138 /*
5139 * Stop capture DMA.
5140 */
5141 tmp = cs461x_peek(card, BA1_CCTL);
5142 card->cctl = tmp & 0x0000ffff;
5143 cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000);
5144
5145 /* initialize AC97 codec and register /dev/mixer */
5146 if(card->pm.flags & CS46XX_PM_IDLE)
5147 {
5148 if (cs_ac97_init(card) <= 0)
5149 {
5150 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
5151 "cs46xx: cs_ac97_init() failure\n") );
5152 return -EIO;
5153 }
5154 }
5155 else
5156 {
5157 cs46xx_ac97_resume(card);
5158 }
5159
5160 cs461x_proc_start(card);
5161
5162 /*
5163 * Enable interrupts on the part.
5164 */
5165 cs461x_pokeBA0(card, BA0_HICR, HICR_IEV | HICR_CHGM);
5166
5167 tmp = cs461x_peek(card, BA1_PFIE);
5168 tmp &= ~0x0000f03f;
5169 cs461x_poke(card, BA1_PFIE, tmp); /* playback interrupt enable */
5170
5171 tmp = cs461x_peek(card, BA1_CIE);
5172 tmp &= ~0x0000003f;
5173 tmp |= 0x00000001;
5174 cs461x_poke(card, BA1_CIE, tmp); /* capture interrupt enable */
5175
5176 /*
5177 * If IDLE then Power down the part. We will power components up
5178 * when we need them.
5179 */
5180 if(card->pm.flags & CS46XX_PM_IDLE)
5181 {
5182 if(!cs_powerdown)
5183 {
5184 if( (tmp = cs46xx_powerup(card, CS_POWER_DAC | CS_POWER_ADC |
5185 CS_POWER_MIXVON )) )
5186 {
5187 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
5188 "cs46xx: cs461x_powerup() failure (0x%x)\n",tmp) );
5189 return -EIO;
5190 }
5191 }
5192 else
5193 {
5194 if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
5195 CS_POWER_MIXVON, CS_FALSE )) )
5196 {
5197 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
5198 "cs46xx: cs461x_powerdown() failure (0x%x)\n",tmp) );
5199 return -EIO;
5200 }
5201 }
5202 }
5203 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
5204 "cs46xx: cs_hardware_init()- 0\n"));
5205 return 0;
5206}
5207
5208/* install the driver, we do not allocate hardware channel nor DMA buffer now, they are defered
5209 until "ACCESS" time (in prog_dmabuf called by open/read/write/ioctl/mmap) */
5210
5211/*
5212 * Card subid table
5213 */
5214
5215struct cs_card_type
5216{
5217 u16 vendor;
5218 u16 id;
5219 char *name;
5220 void (*amp)(struct cs_card *, int);
5221 void (*amp_init)(struct cs_card *);
5222 void (*active)(struct cs_card *, int);
5223};
5224
5225static struct cs_card_type cards[] = {
5226 {
5227 .vendor = 0x1489,
5228 .id = 0x7001,
5229 .name = "Genius Soundmaker 128 value",
5230 .amp = amp_none,
5231 },
5232 {
5233 .vendor = 0x5053,
5234 .id = 0x3357,
5235 .name = "Voyetra",
5236 .amp = amp_voyetra,
5237 },
5238 {
5239 .vendor = 0x1071,
5240 .id = 0x6003,
5241 .name = "Mitac MI6020/21",
5242 .amp = amp_voyetra,
5243 },
5244 {
5245 .vendor = 0x14AF,
5246 .id = 0x0050,
5247 .name = "Hercules Game Theatre XP",
5248 .amp = amp_hercules,
5249 },
5250 {
5251 .vendor = 0x1681,
5252 .id = 0x0050,
5253 .name = "Hercules Game Theatre XP",
5254 .amp = amp_hercules,
5255 },
5256 {
5257 .vendor = 0x1681,
5258 .id = 0x0051,
5259 .name = "Hercules Game Theatre XP",
5260 .amp = amp_hercules,
5261 },
5262 {
5263 .vendor = 0x1681,
5264 .id = 0x0052,
5265 .name = "Hercules Game Theatre XP",
5266 .amp = amp_hercules,
5267 },
5268 {
5269 .vendor = 0x1681,
5270 .id = 0x0053,
5271 .name = "Hercules Game Theatre XP",
5272 .amp = amp_hercules,
5273 },
5274 {
5275 .vendor = 0x1681,
5276 .id = 0x0054,
5277 .name = "Hercules Game Theatre XP",
5278 .amp = amp_hercules,
5279 },
5280 {
5281 .vendor = 0x1681,
5282 .id = 0xa010,
5283 .name = "Hercules Fortissimo II",
5284 .amp = amp_none,
5285 },
5286 /* Not sure if the 570 needs the clkrun hack */
5287 {
5288 .vendor = PCI_VENDOR_ID_IBM,
5289 .id = 0x0132,
5290 .name = "Thinkpad 570",
5291 .amp = amp_none,
5292 .active = clkrun_hack,
5293 },
5294 {
5295 .vendor = PCI_VENDOR_ID_IBM,
5296 .id = 0x0153,
5297 .name = "Thinkpad 600X/A20/T20",
5298 .amp = amp_none,
5299 .active = clkrun_hack,
5300 },
5301 {
5302 .vendor = PCI_VENDOR_ID_IBM,
5303 .id = 0x1010,
5304 .name = "Thinkpad 600E (unsupported)",
5305 },
5306 {
5307 .name = "Card without SSID set",
5308 },
5309 { 0, },
5310};
5311
5312MODULE_AUTHOR("Alan Cox <alan@redhat.com>, Jaroslav Kysela, <pcaudio@crystal.cirrus.com>");
5313MODULE_DESCRIPTION("Crystal SoundFusion Audio Support");
5314MODULE_LICENSE("GPL");
5315
5316
5317static const char cs46xx_banner[] = KERN_INFO "Crystal 4280/46xx + AC97 Audio, version " CS46XX_MAJOR_VERSION "." CS46XX_MINOR_VERSION "." CS46XX_ARCH ", " __TIME__ " " __DATE__ "\n";
5318static const char fndmsg[] = KERN_INFO "cs46xx: Found %d audio device(s).\n";
5319
5320static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5321 const struct pci_device_id *pciid)
5322{
5323 struct pm_dev *pmdev;
5324 int i,j;
5325 u16 ss_card, ss_vendor;
5326 struct cs_card *card;
5327 dma_addr_t dma_mask;
5328 struct cs_card_type *cp = &cards[0];
5329
5330 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2,
5331 printk(KERN_INFO "cs46xx: probe()+\n"));
5332
5333 dma_mask = 0xffffffff; /* this enables playback and recording */
5334 if (pci_enable_device(pci_dev)) {
5335 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
5336 "cs46xx: pci_enable_device() failed\n"));
5337 return -1;
5338 }
5339 if (!RSRCISMEMORYREGION(pci_dev, 0) ||
5340 !RSRCISMEMORYREGION(pci_dev, 1)) {
5341 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
5342 "cs46xx: probe()- Memory region not assigned\n"));
5343 return -1;
5344 }
5345 if (pci_dev->irq == 0) {
5346 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
5347 "cs46xx: probe() IRQ not assigned\n"));
5348 return -1;
5349 }
5350 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
5351 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
5352 "cs46xx: probe() architecture does not support 32bit PCI busmaster DMA\n"));
5353 return -1;
5354 }
5355 pci_read_config_word(pci_dev, PCI_SUBSYSTEM_VENDOR_ID, &ss_vendor);
5356 pci_read_config_word(pci_dev, PCI_SUBSYSTEM_ID, &ss_card);
5357
5358 if ((card = kmalloc(sizeof(struct cs_card), GFP_KERNEL)) == NULL) {
5359 printk(KERN_ERR "cs46xx: out of memory\n");
5360 return -ENOMEM;
5361 }
5362 memset(card, 0, sizeof(*card));
5363 card->ba0_addr = RSRCADDRESS(pci_dev, 0);
5364 card->ba1_addr = RSRCADDRESS(pci_dev, 1);
5365 card->pci_dev = pci_dev;
5366 card->irq = pci_dev->irq;
5367 card->magic = CS_CARD_MAGIC;
5368 spin_lock_init(&card->lock);
5369 spin_lock_init(&card->ac97_lock);
5370
5371 pci_set_master(pci_dev);
5372
5373 printk(cs46xx_banner);
5374 printk(KERN_INFO "cs46xx: Card found at 0x%08lx and 0x%08lx, IRQ %d\n",
5375 card->ba0_addr, card->ba1_addr, card->irq);
5376
5377 card->alloc_pcm_channel = cs_alloc_pcm_channel;
5378 card->alloc_rec_pcm_channel = cs_alloc_rec_pcm_channel;
5379 card->free_pcm_channel = cs_free_pcm_channel;
5380 card->amplifier_ctrl = amp_none;
5381 card->active_ctrl = amp_none;
5382
5383 while (cp->name)
5384 {
5385 if(cp->vendor == ss_vendor && cp->id == ss_card)
5386 {
5387 card->amplifier_ctrl = cp->amp;
5388 if(cp->active)
5389 card->active_ctrl = cp->active;
5390 if(cp->amp_init)
5391 card->amp_init = cp->amp_init;
5392 break;
5393 }
5394 cp++;
5395 }
5396 if (cp->name==NULL)
5397 {
5398 printk(KERN_INFO "cs46xx: Unknown card (%04X:%04X) at 0x%08lx/0x%08lx, IRQ %d\n",
5399 ss_vendor, ss_card, card->ba0_addr, card->ba1_addr, card->irq);
5400 }
5401 else
5402 {
5403 printk(KERN_INFO "cs46xx: %s (%04X:%04X) at 0x%08lx/0x%08lx, IRQ %d\n",
5404 cp->name, ss_vendor, ss_card, card->ba0_addr, card->ba1_addr, card->irq);
5405 }
5406
5407 if (card->amplifier_ctrl==NULL)
5408 {
5409 card->amplifier_ctrl = amp_none;
5410 card->active_ctrl = clkrun_hack;
5411 }
5412
5413 if (external_amp == 1)
5414 {
5415 printk(KERN_INFO "cs46xx: Crystal EAPD support forced on.\n");
5416 card->amplifier_ctrl = amp_voyetra;
5417 }
5418
5419 if (thinkpad == 1)
5420 {
5421 printk(KERN_INFO "cs46xx: Activating CLKRUN hack for Thinkpad.\n");
5422 card->active_ctrl = clkrun_hack;
5423 }
5424/*
5425* The thinkpads don't work well without runtime updating on their kernel
5426* delay values (or any laptop with variable CPU speeds really).
5427* so, just to be safe set the init delay to 2100. Eliminates
5428* failures on T21 Thinkpads. remove this code when the udelay
5429* and mdelay kernel code is replaced by a pm timer, or the delays
5430* work well for battery and/or AC power both.
5431*/
5432 if(card->active_ctrl == clkrun_hack)
5433 {
5434 initdelay = 2100;
5435 cs_laptop_wait = 5;
5436 }
5437 if((card->active_ctrl == clkrun_hack) && !(powerdown == 1))
5438 {
5439/*
5440* for some currently unknown reason, powering down the DAC and ADC component
5441* blocks on thinkpads causes some funky behavior... distoorrrtion and ac97
5442* codec access problems. probably the serial clock becomes unsynced.
5443* added code to sync the chips back up, but only helped about 70% the time.
5444*/
5445 cs_powerdown = 0;
5446 }
5447 if(powerdown == 0)
5448 cs_powerdown = 0;
5449 card->active_ctrl(card, 1);
5450
5451 /* claim our iospace and irq */
5452
5453 card->ba0 = ioremap_nocache(card->ba0_addr, CS461X_BA0_SIZE);
5454 card->ba1.name.data0 = ioremap_nocache(card->ba1_addr + BA1_SP_DMEM0, CS461X_BA1_DATA0_SIZE);
5455 card->ba1.name.data1 = ioremap_nocache(card->ba1_addr + BA1_SP_DMEM1, CS461X_BA1_DATA1_SIZE);
5456 card->ba1.name.pmem = ioremap_nocache(card->ba1_addr + BA1_SP_PMEM, CS461X_BA1_PRG_SIZE);
5457 card->ba1.name.reg = ioremap_nocache(card->ba1_addr + BA1_SP_REG, CS461X_BA1_REG_SIZE);
5458
5459 CS_DBGOUT(CS_INIT, 4, printk(KERN_INFO
5460 "cs46xx: card=%p card->ba0=%p\n",card,card->ba0) );
5461 CS_DBGOUT(CS_INIT, 4, printk(KERN_INFO
5462 "cs46xx: card->ba1=%p %p %p %p\n",
5463 card->ba1.name.data0,
5464 card->ba1.name.data1,
5465 card->ba1.name.pmem,
5466 card->ba1.name.reg) );
5467
5468 if(card->ba0 == 0 || card->ba1.name.data0 == 0 ||
5469 card->ba1.name.data1 == 0 || card->ba1.name.pmem == 0 ||
5470 card->ba1.name.reg == 0)
5471 goto fail2;
5472
5473 if (request_irq(card->irq, &cs_interrupt, SA_SHIRQ, "cs46xx", card)) {
5474 printk(KERN_ERR "cs46xx: unable to allocate irq %d\n", card->irq);
5475 goto fail2;
5476 }
5477 /* register /dev/dsp */
5478 if ((card->dev_audio = register_sound_dsp(&cs461x_fops, -1)) < 0) {
5479 printk(KERN_ERR "cs46xx: unable to register dsp\n");
5480 goto fail;
5481 }
5482
5483 /* register /dev/midi */
5484 if((card->dev_midi = register_sound_midi(&cs_midi_fops, -1)) < 0)
5485 printk(KERN_ERR "cs46xx: unable to register midi\n");
5486
5487 card->pm.flags |= CS46XX_PM_IDLE;
5488 for(i=0;i<5;i++)
5489 {
5490 if (cs_hardware_init(card) != 0)
5491 {
5492 CS_DBGOUT(CS_ERROR, 4, printk(
5493 "cs46xx: ERROR in cs_hardware_init()... retrying\n"));
5494 for (j = 0; j < NR_AC97; j++)
5495 if (card->ac97_codec[j] != NULL) {
5496 unregister_sound_mixer(card->ac97_codec[j]->dev_mixer);
5497 ac97_release_codec(card->ac97_codec[j]);
5498 }
5499 mdelay(10 * cs_laptop_wait);
5500 continue;
5501 }
5502 break;
5503 }
5504 if(i>=4)
5505 {
5506 CS_DBGOUT(CS_PM | CS_ERROR, 1, printk(
5507 "cs46xx: cs46xx_probe()- cs_hardware_init() failed, retried %d times.\n",i));
5508 unregister_sound_dsp(card->dev_audio);
5509 if(card->dev_midi)
5510 unregister_sound_midi(card->dev_midi);
5511 goto fail;
5512 }
5513
5514 init_waitqueue_head(&card->midi.open_wait);
5515 init_MUTEX(&card->midi.open_sem);
5516 init_waitqueue_head(&card->midi.iwait);
5517 init_waitqueue_head(&card->midi.owait);
5518 cs461x_pokeBA0(card, BA0_MIDCR, MIDCR_MRST);
5519 cs461x_pokeBA0(card, BA0_MIDCR, 0);
5520
5521 /*
5522 * Check if we have to init the amplifier, but probably already done
5523 * since the CD logic in the ac97 init code will turn on the ext amp.
5524 */
5525 if(cp->amp_init)
5526 cp->amp_init(card);
5527 card->active_ctrl(card, -1);
5528
5529 PCI_SET_DRIVER_DATA(pci_dev, card);
5530 PCI_SET_DMA_MASK(pci_dev, dma_mask);
5531 list_add(&card->list, &cs46xx_devs);
5532
5533 pmdev = cs_pm_register(PM_PCI_DEV, PM_PCI_ID(pci_dev), cs46xx_pm_callback);
5534 if (pmdev)
5535 {
5536 CS_DBGOUT(CS_INIT | CS_PM, 4, printk(KERN_INFO
5537 "cs46xx: probe() pm_register() succeeded (%p).\n",
5538 pmdev));
5539 pmdev->data = card;
5540 }
5541 else
5542 {
5543 CS_DBGOUT(CS_INIT | CS_PM | CS_ERROR, 2, printk(KERN_INFO
5544 "cs46xx: probe() pm_register() failed (%p).\n",
5545 pmdev));
5546 card->pm.flags |= CS46XX_PM_NOT_REGISTERED;
5547 }
5548
5549 CS_DBGOUT(CS_PM, 9, printk(KERN_INFO "cs46xx: pm.flags=0x%x card=%p\n",
5550 (unsigned)card->pm.flags,card));
5551
5552 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
5553 "cs46xx: probe()- device allocated successfully\n"));
5554 return 0;
5555
5556fail:
5557 free_irq(card->irq, card);
5558fail2:
5559 if(card->ba0)
5560 iounmap(card->ba0);
5561 if(card->ba1.name.data0)
5562 iounmap(card->ba1.name.data0);
5563 if(card->ba1.name.data1)
5564 iounmap(card->ba1.name.data1);
5565 if(card->ba1.name.pmem)
5566 iounmap(card->ba1.name.pmem);
5567 if(card->ba1.name.reg)
5568 iounmap(card->ba1.name.reg);
5569 kfree(card);
5570 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_INFO
5571 "cs46xx: probe()- no device allocated\n"));
5572 return -ENODEV;
5573} // probe_cs46xx
5574
5575// ---------------------------------------------------------------------
5576
5577static void __devexit cs46xx_remove(struct pci_dev *pci_dev)
5578{
5579 struct cs_card *card = PCI_GET_DRIVER_DATA(pci_dev);
5580 int i;
5581 unsigned int tmp;
5582
5583 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
5584 "cs46xx: cs46xx_remove()+\n"));
5585
5586 card->active_ctrl(card,1);
5587
5588 tmp = cs461x_peek(card, BA1_PFIE);
5589 tmp &= ~0x0000f03f;
5590 tmp |= 0x00000010;
5591 cs461x_poke(card, BA1_PFIE, tmp); /* playback interrupt disable */
5592
5593 tmp = cs461x_peek(card, BA1_CIE);
5594 tmp &= ~0x0000003f;
5595 tmp |= 0x00000011;
5596 cs461x_poke(card, BA1_CIE, tmp); /* capture interrupt disable */
5597
5598 /*
5599 * Stop playback DMA.
5600 */
5601 tmp = cs461x_peek(card, BA1_PCTL);
5602 cs461x_poke(card, BA1_PCTL, tmp & 0x0000ffff);
5603
5604 /*
5605 * Stop capture DMA.
5606 */
5607 tmp = cs461x_peek(card, BA1_CCTL);
5608 cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000);
5609
5610 /*
5611 * Reset the processor.
5612 */
5613 cs461x_reset(card);
5614
5615 cs461x_proc_stop(card);
5616
5617 /*
5618 * Power down the DAC and ADC. We will power them up (if) when we need
5619 * them.
5620 */
5621 if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
5622 CS_POWER_MIXVON, CS_TRUE )) )
5623 {
5624 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
5625 "cs46xx: cs461x_powerdown() failure (0x%x)\n",tmp) );
5626 }
5627
5628 /*
5629 * Power down the PLL.
5630 */
5631 cs461x_pokeBA0(card, BA0_CLKCR1, 0);
5632
5633 /*
5634 * Turn off the Processor by turning off the software clock enable flag in
5635 * the clock control register.
5636 */
5637 tmp = cs461x_peekBA0(card, BA0_CLKCR1) & ~CLKCR1_SWCE;
5638 cs461x_pokeBA0(card, BA0_CLKCR1, tmp);
5639
5640 card->active_ctrl(card,-1);
5641
5642 /* free hardware resources */
5643 free_irq(card->irq, card);
5644 iounmap(card->ba0);
5645 iounmap(card->ba1.name.data0);
5646 iounmap(card->ba1.name.data1);
5647 iounmap(card->ba1.name.pmem);
5648 iounmap(card->ba1.name.reg);
5649
5650 /* unregister audio devices */
5651 for (i = 0; i < NR_AC97; i++)
5652 if (card->ac97_codec[i] != NULL) {
5653 unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
5654 ac97_release_codec(card->ac97_codec[i]);
5655 }
5656 unregister_sound_dsp(card->dev_audio);
5657 if(card->dev_midi)
5658 unregister_sound_midi(card->dev_midi);
5659 list_del(&card->list);
5660 kfree(card);
5661 PCI_SET_DRIVER_DATA(pci_dev,NULL);
5662
5663 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
5664 "cs46xx: cs46xx_remove()-: remove successful\n"));
5665}
5666
5667enum {
5668 CS46XX_4610 = 0,
5669 CS46XX_4612, /* same as 4630 */
5670 CS46XX_4615, /* same as 4624 */
5671};
5672
5673static struct pci_device_id cs46xx_pci_tbl[] = {
5674 {
5675 .vendor = PCI_VENDOR_ID_CIRRUS,
5676 .device = PCI_DEVICE_ID_CIRRUS_4610,
5677 .subvendor = PCI_ANY_ID,
5678 .subdevice = PCI_ANY_ID,
5679 .driver_data = CS46XX_4610,
5680 },
5681 {
5682 .vendor = PCI_VENDOR_ID_CIRRUS,
5683 .device = PCI_DEVICE_ID_CIRRUS_4612,
5684 .subvendor = PCI_ANY_ID,
5685 .subdevice = PCI_ANY_ID,
5686 .driver_data = CS46XX_4612,
5687 },
5688 {
5689 .vendor = PCI_VENDOR_ID_CIRRUS,
5690 .device = PCI_DEVICE_ID_CIRRUS_4615,
5691 .subvendor = PCI_ANY_ID,
5692 .subdevice = PCI_ANY_ID,
5693 .driver_data = CS46XX_4615,
5694 },
5695 { 0, },
5696};
5697
5698MODULE_DEVICE_TABLE(pci, cs46xx_pci_tbl);
5699
5700static struct pci_driver cs46xx_pci_driver = {
5701 .name = "cs46xx",
5702 .id_table = cs46xx_pci_tbl,
5703 .probe = cs46xx_probe,
5704 .remove = __devexit_p(cs46xx_remove),
5705 .suspend = CS46XX_SUSPEND_TBL,
5706 .resume = CS46XX_RESUME_TBL,
5707};
5708
5709static int __init cs46xx_init_module(void)
5710{
5711 int rtn = 0;
5712 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
5713 "cs46xx: cs46xx_init_module()+ \n"));
5714 rtn = pci_module_init(&cs46xx_pci_driver);
5715
5716 if(rtn == -ENODEV)
5717 {
5718 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(
5719 "cs46xx: Unable to detect valid cs46xx device\n"));
5720 }
5721
5722 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
5723 printk(KERN_INFO "cs46xx: cs46xx_init_module()- (%d)\n",rtn));
5724 return rtn;
5725}
5726
5727static void __exit cs46xx_cleanup_module(void)
5728{
5729 pci_unregister_driver(&cs46xx_pci_driver);
5730 cs_pm_unregister_all(cs46xx_pm_callback);
5731 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
5732 printk(KERN_INFO "cs46xx: cleanup_cs46xx() finished\n"));
5733}
5734
5735module_init(cs46xx_init_module);
5736module_exit(cs46xx_cleanup_module);
5737
5738#ifndef CS46XX_ACPI_SUPPORT
5739static int cs46xx_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
5740{
5741 struct cs_card *card;
5742
5743 CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
5744 "cs46xx: cs46xx_pm_callback dev=%p rqst=0x%x card=%p\n",
5745 dev,(unsigned)rqst,data));
5746 card = (struct cs_card *) dev->data;
5747 if (card) {
5748 switch(rqst) {
5749 case PM_SUSPEND:
5750 CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
5751 "cs46xx: PM suspend request\n"));
5752 if(cs46xx_suspend(card, 0))
5753 {
5754 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
5755 "cs46xx: PM suspend request refused\n"));
5756 return 1;
5757 }
5758 break;
5759 case PM_RESUME:
5760 CS_DBGOUT(CS_PM, 2, printk(KERN_INFO
5761 "cs46xx: PM resume request\n"));
5762 if(cs46xx_resume(card))
5763 {
5764 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
5765 "cs46xx: PM resume request refused\n"));
5766 return 1;
5767 }
5768 break;
5769 }
5770 }
5771
5772 return 0;
5773}
5774#endif
5775
5776#if CS46XX_ACPI_SUPPORT
5777static int cs46xx_suspend_tbl(struct pci_dev *pcidev, pm_message_t state)
5778{
5779 struct cs_card *s = PCI_GET_DRIVER_DATA(pcidev);
5780 CS_DBGOUT(CS_PM | CS_FUNCTION, 2,
5781 printk(KERN_INFO "cs46xx: cs46xx_suspend_tbl request\n"));
5782 cs46xx_suspend(s, 0);
5783 return 0;
5784}
5785
5786static int cs46xx_resume_tbl(struct pci_dev *pcidev)
5787{
5788 struct cs_card *s = PCI_GET_DRIVER_DATA(pcidev);
5789 CS_DBGOUT(CS_PM | CS_FUNCTION, 2,
5790 printk(KERN_INFO "cs46xx: cs46xx_resume_tbl request\n"));
5791 cs46xx_resume(s);
5792 return 0;
5793}
5794#endif
diff --git a/sound/oss/cs46xx_wrapper-24.h b/sound/oss/cs46xx_wrapper-24.h
new file mode 100644
index 000000000000..f68e01181a7c
--- /dev/null
+++ b/sound/oss/cs46xx_wrapper-24.h
@@ -0,0 +1,56 @@
1/*******************************************************************************
2*
3* "cs46xx_wrapper.c" -- Cirrus Logic-Crystal CS46XX linux audio driver.
4*
5* Copyright (C) 2000,2001 Cirrus Logic Corp.
6* -- tom woller (twoller@crystal.cirrus.com) or
7* (pcaudio@crystal.cirrus.com).
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* 01/11/2001 trw - new file from cs4281 wrapper code.
24*
25*******************************************************************************/
26#ifndef __CS46XX_WRAPPER24_H
27#define __CS46XX_WRAPPER24_H
28
29#include <linux/spinlock.h>
30
31#define CS_OWNER .owner =
32#define CS_THIS_MODULE THIS_MODULE,
33static inline void cs46xx_null(struct pci_dev *pcidev) { return; }
34#define cs4x_mem_map_reserve(page) SetPageReserved(page)
35#define cs4x_mem_map_unreserve(page) ClearPageReserved(page)
36
37#define free_dmabuf(card, dmabuf) \
38 pci_free_consistent((card)->pci_dev, \
39 PAGE_SIZE << (dmabuf)->buforder, \
40 (dmabuf)->rawbuf, (dmabuf)->dmaaddr);
41#define free_dmabuf2(card, dmabuf) \
42 pci_free_consistent((card)->pci_dev, \
43 PAGE_SIZE << (dmabuf)->buforder_tmpbuff, \
44 (dmabuf)->tmpbuff, (dmabuf)->dmaaddr_tmpbuff);
45#define cs4x_pgoff(vma) ((vma)->vm_pgoff)
46
47#define RSRCISIOREGION(dev,num) ((dev)->resource[(num)].start != 0 && \
48 ((dev)->resource[(num)].flags & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO)
49#define RSRCISMEMORYREGION(dev,num) ((dev)->resource[(num)].start != 0 && \
50 ((dev)->resource[(num)].flags & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY)
51#define RSRCADDRESS(dev,num) ((dev)->resource[(num)].start)
52#define PCI_GET_DRIVER_DATA pci_get_drvdata
53#define PCI_SET_DRIVER_DATA pci_set_drvdata
54#define PCI_SET_DMA_MASK(pcidev,mask) pcidev->dma_mask = mask
55
56#endif
diff --git a/sound/oss/cs46xxpm-24.h b/sound/oss/cs46xxpm-24.h
new file mode 100644
index 000000000000..e220bd7240f1
--- /dev/null
+++ b/sound/oss/cs46xxpm-24.h
@@ -0,0 +1,52 @@
1/*******************************************************************************
2*
3* "cs46xxpm-24.h" -- Cirrus Logic-Crystal CS46XX linux audio driver.
4*
5* Copyright (C) 2000,2001 Cirrus Logic Corp.
6* -- tom woller (twoller@crystal.cirrus.com) or
7* (pcaudio@crystal.cirrus.com).
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* 12/22/00 trw - new file.
24*
25*******************************************************************************/
26#ifndef __CS46XXPM24_H
27#define __CS46XXPM24_H
28
29#include <linux/pm.h>
30#include "cs46xxpm.h"
31
32
33#define CS46XX_ACPI_SUPPORT 1
34#ifdef CS46XX_ACPI_SUPPORT
35/*
36* for now (12/22/00) only enable the pm_register PM support.
37* allow these table entries to be null.
38*/
39static int cs46xx_suspend_tbl(struct pci_dev *pcidev, pm_message_t state);
40static int cs46xx_resume_tbl(struct pci_dev *pcidev);
41#define cs_pm_register(a, b, c) NULL
42#define cs_pm_unregister_all(a)
43#define CS46XX_SUSPEND_TBL cs46xx_suspend_tbl
44#define CS46XX_RESUME_TBL cs46xx_resume_tbl
45#else
46#define cs_pm_register(a, b, c) pm_register((a), (b), (c));
47#define cs_pm_unregister_all(a) pm_unregister_all((a));
48#define CS46XX_SUSPEND_TBL cs46xx_null
49#define CS46XX_RESUME_TBL cs46xx_null
50#endif
51
52#endif
diff --git a/sound/oss/cs46xxpm.h b/sound/oss/cs46xxpm.h
new file mode 100644
index 000000000000..2932b6e0e0bb
--- /dev/null
+++ b/sound/oss/cs46xxpm.h
@@ -0,0 +1,70 @@
1/*******************************************************************************
2*
3* "cs46xxpm.h" -- Cirrus Logic-Crystal CS46XX linux audio driver.
4*
5* Copyright (C) 2000,2001 Cirrus Logic Corp.
6* -- tom woller (twoller@crystal.cirrus.com) or
7* (pcaudio@crystal.cirrus.com).
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* 12/22/00 trw - new file.
24*
25*******************************************************************************/
26#ifndef __CS46XXPM_H
27#define __CS46XXPM_H
28
29#define CS46XX_AC97_HIGHESTREGTORESTORE 0x26
30#define CS46XX_AC97_NUMBER_RESTORE_REGS (CS46XX_AC97_HIGHESTREGTORESTORE/2-1)
31
32/* PM state defintions */
33#define CS46XX_PM_NOT_REGISTERED 0x1000
34#define CS46XX_PM_IDLE 0x0001
35#define CS46XX_PM_SUSPENDING 0x0002
36#define CS46XX_PM_SUSPENDED 0x0004
37#define CS46XX_PM_RESUMING 0x0008
38#define CS46XX_PM_RESUMED 0x0010
39
40#define CS_POWER_DAC 0x0001
41#define CS_POWER_ADC 0x0002
42#define CS_POWER_MIXVON 0x0004
43#define CS_POWER_MIXVOFF 0x0008
44#define CS_AC97_POWER_CONTROL_ON 0xf000 /* always on bits (inverted) */
45#define CS_AC97_POWER_CONTROL_ADC 0x0100
46#define CS_AC97_POWER_CONTROL_DAC 0x0200
47#define CS_AC97_POWER_CONTROL_MIXVON 0x0400
48#define CS_AC97_POWER_CONTROL_MIXVOFF 0x0800
49#define CS_AC97_POWER_CONTROL_ADC_ON 0x0001
50#define CS_AC97_POWER_CONTROL_DAC_ON 0x0002
51#define CS_AC97_POWER_CONTROL_MIXVON_ON 0x0004
52#define CS_AC97_POWER_CONTROL_MIXVOFF_ON 0x0008
53
54struct cs46xx_pm {
55 unsigned long flags;
56 u32 u32CLKCR1_SAVE,u32SSPMValue,u32PPLVCvalue,u32PPRVCvalue;
57 u32 u32FMLVCvalue,u32FMRVCvalue,u32GPIORvalue,u32JSCTLvalue,u32SSCR;
58 u32 u32SRCSA,u32DacASR,u32AdcASR,u32DacSR,u32AdcSR,u32MIDCR_Save;
59 u32 u32SSPM_BITS;
60 u32 ac97[CS46XX_AC97_NUMBER_RESTORE_REGS];
61 u32 u32AC97_master_volume, u32AC97_headphone_volume, u32AC97_master_volume_mono;
62 u32 u32AC97_pcm_out_volume, u32AC97_powerdown, u32AC97_general_purpose;
63 u32 u32hwptr_playback,u32hwptr_capture;
64 unsigned dmabuf_swptr_play;
65 int dmabuf_count_play;
66 unsigned dmabuf_swptr_capture;
67 int dmabuf_count_capture;
68};
69
70#endif
diff --git a/sound/oss/dev_table.c b/sound/oss/dev_table.c
new file mode 100644
index 000000000000..f65a90469d8a
--- /dev/null
+++ b/sound/oss/dev_table.c
@@ -0,0 +1,214 @@
1/*
2 * sound/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#define _DEV_TABLE_C_
17#include "sound_config.h"
18
19static int sound_alloc_audiodev(void);
20
21int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
22 int driver_size, int flags, unsigned int format_mask,
23 void *devc, int dma1, int dma2)
24{
25 struct audio_driver *d;
26 struct audio_operations *op;
27 int num;
28
29 if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) {
30 printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name);
31 return -(EINVAL);
32 }
33 num = sound_alloc_audiodev();
34
35 if (num == -1) {
36 printk(KERN_ERR "sound: Too many audio drivers\n");
37 return -(EBUSY);
38 }
39 d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver)));
40
41 if (sound_nblocks < 1024)
42 sound_nblocks++;
43
44 op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_operations)));
45
46 if (sound_nblocks < 1024)
47 sound_nblocks++;
48 if (d == NULL || op == NULL) {
49 printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name);
50 sound_unload_audiodev(num);
51 return -(ENOMEM);
52 }
53 memset((char *) op, 0, sizeof(struct audio_operations));
54 init_waitqueue_head(&op->in_sleeper);
55 init_waitqueue_head(&op->out_sleeper);
56 init_waitqueue_head(&op->poll_sleeper);
57 if (driver_size < sizeof(struct audio_driver))
58 memset((char *) d, 0, sizeof(struct audio_driver));
59
60 memcpy((char *) d, (char *) driver, driver_size);
61
62 op->d = d;
63 strlcpy(op->name, name, sizeof(op->name));
64 op->flags = flags;
65 op->format_mask = format_mask;
66 op->devc = devc;
67
68 /*
69 * Hardcoded defaults
70 */
71 audio_devs[num] = op;
72
73 DMAbuf_init(num, dma1, dma2);
74
75 audio_init_devices();
76 return num;
77}
78
79int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
80 int driver_size, void *devc)
81{
82 struct mixer_operations *op;
83
84 int n = sound_alloc_mixerdev();
85
86 if (n == -1) {
87 printk(KERN_ERR "Sound: Too many mixer drivers\n");
88 return -EBUSY;
89 }
90 if (vers != MIXER_DRIVER_VERSION ||
91 driver_size > sizeof(struct mixer_operations)) {
92 printk(KERN_ERR "Sound: Incompatible mixer driver for %s\n", name);
93 return -EINVAL;
94 }
95
96 /* FIXME: This leaks a mixer_operations struct every time its called
97 until you unload sound! */
98
99 op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct mixer_operations)));
100
101 if (sound_nblocks < 1024)
102 sound_nblocks++;
103 if (op == NULL) {
104 printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name);
105 return -ENOMEM;
106 }
107 memset((char *) op, 0, sizeof(struct mixer_operations));
108 memcpy((char *) op, (char *) driver, driver_size);
109
110 strlcpy(op->name, name, sizeof(op->name));
111 op->devc = devc;
112
113 mixer_devs[n] = op;
114 return n;
115}
116
117void sound_unload_audiodev(int dev)
118{
119 if (dev != -1) {
120 DMAbuf_deinit(dev);
121 audio_devs[dev] = NULL;
122 unregister_sound_dsp((dev<<4)+3);
123 }
124}
125
126static int sound_alloc_audiodev(void)
127{
128 int i = register_sound_dsp(&oss_sound_fops, -1);
129 if(i==-1)
130 return i;
131 i>>=4;
132 if(i>=num_audiodevs)
133 num_audiodevs = i + 1;
134 return i;
135}
136
137int sound_alloc_mididev(void)
138{
139 int i = register_sound_midi(&oss_sound_fops, -1);
140 if(i==-1)
141 return i;
142 i>>=4;
143 if(i>=num_midis)
144 num_midis = i + 1;
145 return i;
146}
147
148int sound_alloc_synthdev(void)
149{
150 int i;
151
152 for (i = 0; i < MAX_SYNTH_DEV; i++) {
153 if (synth_devs[i] == NULL) {
154 if (i >= num_synths)
155 num_synths++;
156 return i;
157 }
158 }
159 return -1;
160}
161
162int sound_alloc_mixerdev(void)
163{
164 int i = register_sound_mixer(&oss_sound_fops, -1);
165 if(i==-1)
166 return -1;
167 i>>=4;
168 if(i>=num_mixers)
169 num_mixers = i + 1;
170 return i;
171}
172
173int sound_alloc_timerdev(void)
174{
175 int i;
176
177 for (i = 0; i < MAX_TIMER_DEV; i++) {
178 if (sound_timer_devs[i] == NULL) {
179 if (i >= num_sound_timers)
180 num_sound_timers++;
181 return i;
182 }
183 }
184 return -1;
185}
186
187void sound_unload_mixerdev(int dev)
188{
189 if (dev != -1) {
190 mixer_devs[dev] = NULL;
191 unregister_sound_mixer(dev<<4);
192 num_mixers--;
193 }
194}
195
196void sound_unload_mididev(int dev)
197{
198 if (dev != -1) {
199 midi_devs[dev] = NULL;
200 unregister_sound_midi((dev<<4)+2);
201 }
202}
203
204void sound_unload_synthdev(int dev)
205{
206 if (dev != -1)
207 synth_devs[dev] = NULL;
208}
209
210void sound_unload_timerdev(int dev)
211{
212 if (dev != -1)
213 sound_timer_devs[dev] = NULL;
214}
diff --git a/sound/oss/dev_table.h b/sound/oss/dev_table.h
new file mode 100644
index 000000000000..adf1d625b576
--- /dev/null
+++ b/sound/oss/dev_table.h
@@ -0,0 +1,405 @@
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 offs, 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
355#ifdef _DEV_TABLE_C_
356struct audio_operations *audio_devs[MAX_AUDIO_DEV];
357int num_audiodevs;
358struct mixer_operations *mixer_devs[MAX_MIXER_DEV];
359int num_mixers;
360struct synth_operations *synth_devs[MAX_SYNTH_DEV+MAX_MIDI_DEV];
361int num_synths;
362struct midi_operations *midi_devs[MAX_MIDI_DEV];
363int num_midis;
364
365extern struct sound_timer_operations default_sound_timer;
366struct sound_timer_operations *sound_timer_devs[MAX_TIMER_DEV] = {
367 &default_sound_timer, NULL
368};
369int num_sound_timers = 1;
370#else
371extern struct audio_operations *audio_devs[MAX_AUDIO_DEV];
372extern int num_audiodevs;
373extern struct mixer_operations *mixer_devs[MAX_MIXER_DEV];
374extern int num_mixers;
375extern struct synth_operations *synth_devs[MAX_SYNTH_DEV+MAX_MIDI_DEV];
376extern int num_synths;
377extern struct midi_operations *midi_devs[MAX_MIDI_DEV];
378extern int num_midis;
379extern struct sound_timer_operations * sound_timer_devs[MAX_TIMER_DEV];
380extern int num_sound_timers;
381#endif /* _DEV_TABLE_C_ */
382
383extern int sound_map_buffer (int dev, struct dma_buffparms *dmap, buffmem_desc *info);
384void sound_timer_init (struct sound_lowlev_timer *t, char *name);
385void sound_dma_intr (int dev, struct dma_buffparms *dmap, int chan);
386
387#define AUDIO_DRIVER_VERSION 2
388#define MIXER_DRIVER_VERSION 2
389int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
390 int driver_size, int flags, unsigned int format_mask,
391 void *devc, int dma1, int dma2);
392int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
393 int driver_size, void *devc);
394
395void sound_unload_audiodev(int dev);
396void sound_unload_mixerdev(int dev);
397void sound_unload_mididev(int dev);
398void sound_unload_synthdev(int dev);
399void sound_unload_timerdev(int dev);
400int sound_alloc_mixerdev(void);
401int sound_alloc_timerdev(void);
402int sound_alloc_synthdev(void);
403int sound_alloc_mididev(void);
404#endif /* _DEV_TABLE_H_ */
405
diff --git a/sound/oss/dm.h b/sound/oss/dm.h
new file mode 100644
index 000000000000..14a90593c44f
--- /dev/null
+++ b/sound/oss/dm.h
@@ -0,0 +1,79 @@
1#ifndef _DRIVERS_SOUND_DM_H
2#define _DRIVERS_SOUND_DM_H
3
4/*
5 * Definitions of the 'direct midi sound' interface used
6 * by the newer commercial OSS package. We should export
7 * this to userland somewhere in glibc later.
8 */
9
10/*
11 * Data structure composing an FM "note" or sound event.
12 */
13
14struct dm_fm_voice
15{
16 u8 op;
17 u8 voice;
18 u8 am;
19 u8 vibrato;
20 u8 do_sustain;
21 u8 kbd_scale;
22 u8 harmonic;
23 u8 scale_level;
24 u8 volume;
25 u8 attack;
26 u8 decay;
27 u8 sustain;
28 u8 release;
29 u8 feedback;
30 u8 connection;
31 u8 left;
32 u8 right;
33 u8 waveform;
34};
35
36/*
37 * This describes an FM note by its voice, octave, frequency number (10bit)
38 * and key on/off.
39 */
40
41struct dm_fm_note
42{
43 u8 voice;
44 u8 octave;
45 u32 fnum;
46 u8 key_on;
47};
48
49/*
50 * FM parameters that apply globally to all voices, and thus are not "notes"
51 */
52
53struct dm_fm_params
54{
55 u8 am_depth;
56 u8 vib_depth;
57 u8 kbd_split;
58 u8 rhythm;
59
60 /* This block is the percussion instrument data */
61 u8 bass;
62 u8 snare;
63 u8 tomtom;
64 u8 cymbal;
65 u8 hihat;
66};
67
68/*
69 * FM mode ioctl settings
70 */
71
72#define FM_IOCTL_RESET 0x20
73#define FM_IOCTL_PLAY_NOTE 0x21
74#define FM_IOCTL_SET_VOICE 0x22
75#define FM_IOCTL_SET_PARAMS 0x23
76#define FM_IOCTL_SET_MODE 0x24
77#define FM_IOCTL_SET_OPL 0x25
78
79#endif
diff --git a/sound/oss/dmabuf.c b/sound/oss/dmabuf.c
new file mode 100644
index 000000000000..baf4244a54f2
--- /dev/null
+++ b/sound/oss/dmabuf.c
@@ -0,0 +1,1298 @@
1/*
2 * sound/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 "sound_config.h"
29
30#define DMAP_FREE_ON_CLOSE 0
31#define DMAP_KEEP_ON_CLOSE 1
32extern int sound_dmap_flag;
33
34static void dma_reset_output(int dev);
35static void dma_reset_input(int dev);
36static int local_start_dma(struct audio_operations *adev, unsigned long physaddr, int count, int dma_mode);
37
38
39
40static int debugmem; /* switched off by default */
41static int dma_buffsize = DSP_BUFFSIZE;
42
43static long dmabuf_timeout(struct dma_buffparms *dmap)
44{
45 long tmout;
46
47 tmout = (dmap->fragment_size * HZ) / dmap->data_rate;
48 tmout += HZ / 5; /* Some safety distance */
49 if (tmout < (HZ / 2))
50 tmout = HZ / 2;
51 if (tmout > 20 * HZ)
52 tmout = 20 * HZ;
53 return tmout;
54}
55
56static int sound_alloc_dmap(struct dma_buffparms *dmap)
57{
58 char *start_addr, *end_addr;
59 int dma_pagesize;
60 int sz, size;
61 struct page *page;
62
63 dmap->mapping_flags &= ~DMA_MAP_MAPPED;
64
65 if (dmap->raw_buf != NULL)
66 return 0; /* Already done */
67 if (dma_buffsize < 4096)
68 dma_buffsize = 4096;
69 dma_pagesize = (dmap->dma < 4) ? (64 * 1024) : (128 * 1024);
70
71 /*
72 * Now check for the Cyrix problem.
73 */
74
75 if(isa_dma_bridge_buggy==2)
76 dma_pagesize=32768;
77
78 dmap->raw_buf = NULL;
79 dmap->buffsize = dma_buffsize;
80 if (dmap->buffsize > dma_pagesize)
81 dmap->buffsize = dma_pagesize;
82 start_addr = NULL;
83 /*
84 * Now loop until we get a free buffer. Try to get smaller buffer if
85 * it fails. Don't accept smaller than 8k buffer for performance
86 * reasons.
87 */
88 while (start_addr == NULL && dmap->buffsize > PAGE_SIZE) {
89 for (sz = 0, size = PAGE_SIZE; size < dmap->buffsize; sz++, size <<= 1);
90 dmap->buffsize = PAGE_SIZE * (1 << sz);
91 start_addr = (char *) __get_free_pages(GFP_ATOMIC|GFP_DMA|__GFP_NOWARN, sz);
92 if (start_addr == NULL)
93 dmap->buffsize /= 2;
94 }
95
96 if (start_addr == NULL) {
97 printk(KERN_WARNING "Sound error: Couldn't allocate DMA buffer\n");
98 return -ENOMEM;
99 } else {
100 /* make some checks */
101 end_addr = start_addr + dmap->buffsize - 1;
102
103 if (debugmem)
104 printk(KERN_DEBUG "sound: start 0x%lx, end 0x%lx\n", (long) start_addr, (long) end_addr);
105
106 /* now check if it fits into the same dma-pagesize */
107
108 if (((long) start_addr & ~(dma_pagesize - 1)) != ((long) end_addr & ~(dma_pagesize - 1))
109 || end_addr >= (char *) (MAX_DMA_ADDRESS)) {
110 printk(KERN_ERR "sound: Got invalid address 0x%lx for %db DMA-buffer\n", (long) start_addr, dmap->buffsize);
111 return -EFAULT;
112 }
113 }
114 dmap->raw_buf = start_addr;
115 dmap->raw_buf_phys = virt_to_bus(start_addr);
116
117 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
118 SetPageReserved(page);
119 return 0;
120}
121
122static void sound_free_dmap(struct dma_buffparms *dmap)
123{
124 int sz, size;
125 struct page *page;
126 unsigned long start_addr, end_addr;
127
128 if (dmap->raw_buf == NULL)
129 return;
130 if (dmap->mapping_flags & DMA_MAP_MAPPED)
131 return; /* Don't free mmapped buffer. Will use it next time */
132 for (sz = 0, size = PAGE_SIZE; size < dmap->buffsize; sz++, size <<= 1);
133
134 start_addr = (unsigned long) dmap->raw_buf;
135 end_addr = start_addr + dmap->buffsize;
136
137 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
138 ClearPageReserved(page);
139
140 free_pages((unsigned long) dmap->raw_buf, sz);
141 dmap->raw_buf = NULL;
142}
143
144
145/* Intel version !!!!!!!!! */
146
147static int sound_start_dma(struct dma_buffparms *dmap, unsigned long physaddr, int count, int dma_mode)
148{
149 unsigned long flags;
150 int chan = dmap->dma;
151
152 /* printk( "Start DMA%d %d, %d\n", chan, (int)(physaddr-dmap->raw_buf_phys), count); */
153
154 flags = claim_dma_lock();
155 disable_dma(chan);
156 clear_dma_ff(chan);
157 set_dma_mode(chan, dma_mode);
158 set_dma_addr(chan, physaddr);
159 set_dma_count(chan, count);
160 enable_dma(chan);
161 release_dma_lock(flags);
162
163 return 0;
164}
165
166static void dma_init_buffers(struct dma_buffparms *dmap)
167{
168 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
169 dmap->byte_counter = 0;
170 dmap->max_byte_counter = 8000 * 60 * 60;
171 dmap->bytes_in_use = dmap->buffsize;
172
173 dmap->dma_mode = DMODE_NONE;
174 dmap->mapping_flags = 0;
175 dmap->neutral_byte = 0x80;
176 dmap->data_rate = 8000;
177 dmap->cfrag = -1;
178 dmap->closing = 0;
179 dmap->nbufs = 1;
180 dmap->flags = DMA_BUSY; /* Other flags off */
181}
182
183static int open_dmap(struct audio_operations *adev, int mode, struct dma_buffparms *dmap)
184{
185 int err;
186
187 if (dmap->flags & DMA_BUSY)
188 return -EBUSY;
189 if ((err = sound_alloc_dmap(dmap)) < 0)
190 return err;
191
192 if (dmap->raw_buf == NULL) {
193 printk(KERN_WARNING "Sound: DMA buffers not available\n");
194 return -ENOSPC; /* Memory allocation failed during boot */
195 }
196 if (dmap->dma >= 0 && sound_open_dma(dmap->dma, adev->name)) {
197 printk(KERN_WARNING "Unable to grab(2) DMA%d for the audio driver\n", dmap->dma);
198 return -EBUSY;
199 }
200 dma_init_buffers(dmap);
201 spin_lock_init(&dmap->lock);
202 dmap->open_mode = mode;
203 dmap->subdivision = dmap->underrun_count = 0;
204 dmap->fragment_size = 0;
205 dmap->max_fragments = 65536; /* Just a large value */
206 dmap->byte_counter = 0;
207 dmap->max_byte_counter = 8000 * 60 * 60;
208 dmap->applic_profile = APF_NORMAL;
209 dmap->needs_reorg = 1;
210 dmap->audio_callback = NULL;
211 dmap->callback_parm = 0;
212 return 0;
213}
214
215static void close_dmap(struct audio_operations *adev, struct dma_buffparms *dmap)
216{
217 unsigned long flags;
218
219 if (dmap->dma >= 0) {
220 sound_close_dma(dmap->dma);
221 flags=claim_dma_lock();
222 disable_dma(dmap->dma);
223 release_dma_lock(flags);
224 }
225 if (dmap->flags & DMA_BUSY)
226 dmap->dma_mode = DMODE_NONE;
227 dmap->flags &= ~DMA_BUSY;
228
229 if (sound_dmap_flag == DMAP_FREE_ON_CLOSE)
230 sound_free_dmap(dmap);
231}
232
233
234static unsigned int default_set_bits(int dev, unsigned int bits)
235{
236 mm_segment_t fs = get_fs();
237
238 set_fs(get_ds());
239 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_SETFMT, (void __user *)&bits);
240 set_fs(fs);
241 return bits;
242}
243
244static int default_set_speed(int dev, int speed)
245{
246 mm_segment_t fs = get_fs();
247
248 set_fs(get_ds());
249 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_SPEED, (void __user *)&speed);
250 set_fs(fs);
251 return speed;
252}
253
254static short default_set_channels(int dev, short channels)
255{
256 int c = channels;
257 mm_segment_t fs = get_fs();
258
259 set_fs(get_ds());
260 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_CHANNELS, (void __user *)&c);
261 set_fs(fs);
262 return c;
263}
264
265static void check_driver(struct audio_driver *d)
266{
267 if (d->set_speed == NULL)
268 d->set_speed = default_set_speed;
269 if (d->set_bits == NULL)
270 d->set_bits = default_set_bits;
271 if (d->set_channels == NULL)
272 d->set_channels = default_set_channels;
273}
274
275int DMAbuf_open(int dev, int mode)
276{
277 struct audio_operations *adev = audio_devs[dev];
278 int retval;
279 struct dma_buffparms *dmap_in = NULL;
280 struct dma_buffparms *dmap_out = NULL;
281
282 if (!adev)
283 return -ENXIO;
284 if (!(adev->flags & DMA_DUPLEX))
285 adev->dmap_in = adev->dmap_out;
286 check_driver(adev->d);
287
288 if ((retval = adev->d->open(dev, mode)) < 0)
289 return retval;
290 dmap_out = adev->dmap_out;
291 dmap_in = adev->dmap_in;
292 if (dmap_in == dmap_out)
293 adev->flags &= ~DMA_DUPLEX;
294
295 if (mode & OPEN_WRITE) {
296 if ((retval = open_dmap(adev, mode, dmap_out)) < 0) {
297 adev->d->close(dev);
298 return retval;
299 }
300 }
301 adev->enable_bits = mode;
302
303 if (mode == OPEN_READ || (mode != OPEN_WRITE && (adev->flags & DMA_DUPLEX))) {
304 if ((retval = open_dmap(adev, mode, dmap_in)) < 0) {
305 adev->d->close(dev);
306 if (mode & OPEN_WRITE)
307 close_dmap(adev, dmap_out);
308 return retval;
309 }
310 }
311 adev->open_mode = mode;
312 adev->go = 1;
313
314 adev->d->set_bits(dev, 8);
315 adev->d->set_channels(dev, 1);
316 adev->d->set_speed(dev, DSP_DEFAULT_SPEED);
317 if (adev->dmap_out->dma_mode == DMODE_OUTPUT)
318 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte,
319 adev->dmap_out->bytes_in_use);
320 return 0;
321}
322/* MUST not hold the spinlock */
323void DMAbuf_reset(int dev)
324{
325 if (audio_devs[dev]->open_mode & OPEN_WRITE)
326 dma_reset_output(dev);
327
328 if (audio_devs[dev]->open_mode & OPEN_READ)
329 dma_reset_input(dev);
330}
331
332static void dma_reset_output(int dev)
333{
334 struct audio_operations *adev = audio_devs[dev];
335 unsigned long flags,f ;
336 struct dma_buffparms *dmap = adev->dmap_out;
337
338 if (!(dmap->flags & DMA_STARTED)) /* DMA is not active */
339 return;
340
341 /*
342 * First wait until the current fragment has been played completely
343 */
344 spin_lock_irqsave(&dmap->lock,flags);
345 adev->dmap_out->flags |= DMA_SYNCING;
346
347 adev->dmap_out->underrun_count = 0;
348 if (!signal_pending(current) && adev->dmap_out->qlen &&
349 adev->dmap_out->underrun_count == 0){
350 spin_unlock_irqrestore(&dmap->lock,flags);
351 interruptible_sleep_on_timeout(&adev->out_sleeper,
352 dmabuf_timeout(dmap));
353 spin_lock_irqsave(&dmap->lock,flags);
354 }
355 adev->dmap_out->flags &= ~(DMA_SYNCING | DMA_ACTIVE);
356
357 /*
358 * Finally shut the device off
359 */
360 if (!(adev->flags & DMA_DUPLEX) || !adev->d->halt_output)
361 adev->d->halt_io(dev);
362 else
363 adev->d->halt_output(dev);
364 adev->dmap_out->flags &= ~DMA_STARTED;
365
366 f=claim_dma_lock();
367 clear_dma_ff(dmap->dma);
368 disable_dma(dmap->dma);
369 release_dma_lock(f);
370
371 dmap->byte_counter = 0;
372 reorganize_buffers(dev, adev->dmap_out, 0);
373 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
374 spin_unlock_irqrestore(&dmap->lock,flags);
375}
376
377static void dma_reset_input(int dev)
378{
379 struct audio_operations *adev = audio_devs[dev];
380 unsigned long flags;
381 struct dma_buffparms *dmap = adev->dmap_in;
382
383 spin_lock_irqsave(&dmap->lock,flags);
384 if (!(adev->flags & DMA_DUPLEX) || !adev->d->halt_input)
385 adev->d->halt_io(dev);
386 else
387 adev->d->halt_input(dev);
388 adev->dmap_in->flags &= ~DMA_STARTED;
389
390 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
391 dmap->byte_counter = 0;
392 reorganize_buffers(dev, adev->dmap_in, 1);
393 spin_unlock_irqrestore(&dmap->lock,flags);
394}
395/* MUST be called with holding the dmap->lock */
396void DMAbuf_launch_output(int dev, struct dma_buffparms *dmap)
397{
398 struct audio_operations *adev = audio_devs[dev];
399
400 if (!((adev->enable_bits * adev->go) & PCM_ENABLE_OUTPUT))
401 return; /* Don't start DMA yet */
402 dmap->dma_mode = DMODE_OUTPUT;
403
404 if (!(dmap->flags & DMA_ACTIVE) || !(adev->flags & DMA_AUTOMODE) || (dmap->flags & DMA_NODMA)) {
405 if (!(dmap->flags & DMA_STARTED)) {
406 reorganize_buffers(dev, dmap, 0);
407 if (adev->d->prepare_for_output(dev, dmap->fragment_size, dmap->nbufs))
408 return;
409 if (!(dmap->flags & DMA_NODMA))
410 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use,DMA_MODE_WRITE);
411 dmap->flags |= DMA_STARTED;
412 }
413 if (dmap->counts[dmap->qhead] == 0)
414 dmap->counts[dmap->qhead] = dmap->fragment_size;
415 dmap->dma_mode = DMODE_OUTPUT;
416 adev->d->output_block(dev, dmap->raw_buf_phys + dmap->qhead * dmap->fragment_size,
417 dmap->counts[dmap->qhead], 1);
418 if (adev->d->trigger)
419 adev->d->trigger(dev,adev->enable_bits * adev->go);
420 }
421 dmap->flags |= DMA_ACTIVE;
422}
423
424int DMAbuf_sync(int dev)
425{
426 struct audio_operations *adev = audio_devs[dev];
427 unsigned long flags;
428 int n = 0;
429 struct dma_buffparms *dmap;
430
431 if (!adev->go && !(adev->enable_bits & PCM_ENABLE_OUTPUT))
432 return 0;
433
434 if (adev->dmap_out->dma_mode == DMODE_OUTPUT) {
435 dmap = adev->dmap_out;
436 spin_lock_irqsave(&dmap->lock,flags);
437 if (dmap->qlen > 0 && !(dmap->flags & DMA_ACTIVE))
438 DMAbuf_launch_output(dev, dmap);
439 adev->dmap_out->flags |= DMA_SYNCING;
440 adev->dmap_out->underrun_count = 0;
441 while (!signal_pending(current) && n++ <= adev->dmap_out->nbufs &&
442 adev->dmap_out->qlen && adev->dmap_out->underrun_count == 0) {
443 long t = dmabuf_timeout(dmap);
444 spin_unlock_irqrestore(&dmap->lock,flags);
445 /* FIXME: not safe may miss events */
446 t = interruptible_sleep_on_timeout(&adev->out_sleeper, t);
447 spin_lock_irqsave(&dmap->lock,flags);
448 if (!t) {
449 adev->dmap_out->flags &= ~DMA_SYNCING;
450 spin_unlock_irqrestore(&dmap->lock,flags);
451 return adev->dmap_out->qlen;
452 }
453 }
454 adev->dmap_out->flags &= ~(DMA_SYNCING | DMA_ACTIVE);
455
456 /*
457 * Some devices such as GUS have huge amount of on board RAM for the
458 * audio data. We have to wait until the device has finished playing.
459 */
460
461 /* still holding the lock */
462 if (adev->d->local_qlen) { /* Device has hidden buffers */
463 while (!signal_pending(current) &&
464 adev->d->local_qlen(dev)){
465 spin_unlock_irqrestore(&dmap->lock,flags);
466 interruptible_sleep_on_timeout(&adev->out_sleeper,
467 dmabuf_timeout(dmap));
468 spin_lock_irqsave(&dmap->lock,flags);
469 }
470 }
471 spin_unlock_irqrestore(&dmap->lock,flags);
472 }
473 adev->dmap_out->dma_mode = DMODE_NONE;
474 return adev->dmap_out->qlen;
475}
476
477int DMAbuf_release(int dev, int mode)
478{
479 struct audio_operations *adev = audio_devs[dev];
480 struct dma_buffparms *dmap;
481 unsigned long flags;
482
483 dmap = adev->dmap_out;
484 if (adev->open_mode & OPEN_WRITE)
485 adev->dmap_out->closing = 1;
486
487 if (adev->open_mode & OPEN_READ){
488 adev->dmap_in->closing = 1;
489 dmap = adev->dmap_in;
490 }
491 if (adev->open_mode & OPEN_WRITE)
492 if (!(adev->dmap_out->mapping_flags & DMA_MAP_MAPPED))
493 if (!signal_pending(current) && (adev->dmap_out->dma_mode == DMODE_OUTPUT))
494 DMAbuf_sync(dev);
495 if (adev->dmap_out->dma_mode == DMODE_OUTPUT)
496 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte, adev->dmap_out->bytes_in_use);
497
498 DMAbuf_reset(dev);
499 spin_lock_irqsave(&dmap->lock,flags);
500 adev->d->close(dev);
501
502 if (adev->open_mode & OPEN_WRITE)
503 close_dmap(adev, adev->dmap_out);
504
505 if (adev->open_mode == OPEN_READ ||
506 (adev->open_mode != OPEN_WRITE &&
507 (adev->flags & DMA_DUPLEX)))
508 close_dmap(adev, adev->dmap_in);
509 adev->open_mode = 0;
510 spin_unlock_irqrestore(&dmap->lock,flags);
511 return 0;
512}
513/* called with dmap->lock dold */
514int DMAbuf_activate_recording(int dev, struct dma_buffparms *dmap)
515{
516 struct audio_operations *adev = audio_devs[dev];
517 int err;
518
519 if (!(adev->open_mode & OPEN_READ))
520 return 0;
521 if (!(adev->enable_bits & PCM_ENABLE_INPUT))
522 return 0;
523 if (dmap->dma_mode == DMODE_OUTPUT) { /* Direction change */
524 /* release lock - it's not recursive */
525 spin_unlock_irq(&dmap->lock);
526 DMAbuf_sync(dev);
527 DMAbuf_reset(dev);
528 spin_lock_irq(&dmap->lock);
529 dmap->dma_mode = DMODE_NONE;
530 }
531 if (!dmap->dma_mode) {
532 reorganize_buffers(dev, dmap, 1);
533 if ((err = adev->d->prepare_for_input(dev,
534 dmap->fragment_size, dmap->nbufs)) < 0)
535 return err;
536 dmap->dma_mode = DMODE_INPUT;
537 }
538 if (!(dmap->flags & DMA_ACTIVE)) {
539 if (dmap->needs_reorg)
540 reorganize_buffers(dev, dmap, 0);
541 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use, DMA_MODE_READ);
542 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size,
543 dmap->fragment_size, 0);
544 dmap->flags |= DMA_ACTIVE;
545 if (adev->d->trigger)
546 adev->d->trigger(dev, adev->enable_bits * adev->go);
547 }
548 return 0;
549}
550/* aquires lock */
551int DMAbuf_getrdbuffer(int dev, char **buf, int *len, int dontblock)
552{
553 struct audio_operations *adev = audio_devs[dev];
554 unsigned long flags;
555 int err = 0, n = 0;
556 struct dma_buffparms *dmap = adev->dmap_in;
557 int go;
558
559 if (!(adev->open_mode & OPEN_READ))
560 return -EIO;
561 spin_lock_irqsave(&dmap->lock,flags);
562 if (dmap->needs_reorg)
563 reorganize_buffers(dev, dmap, 0);
564 if (adev->dmap_in->mapping_flags & DMA_MAP_MAPPED) {
565/* printk(KERN_WARNING "Sound: Can't read from mmapped device (1)\n");*/
566 spin_unlock_irqrestore(&dmap->lock,flags);
567 return -EINVAL;
568 } else while (dmap->qlen <= 0 && n++ < 10) {
569 long timeout = MAX_SCHEDULE_TIMEOUT;
570 if (!(adev->enable_bits & PCM_ENABLE_INPUT) || !adev->go) {
571 spin_unlock_irqrestore(&dmap->lock,flags);
572 return -EAGAIN;
573 }
574 if ((err = DMAbuf_activate_recording(dev, dmap)) < 0) {
575 spin_unlock_irqrestore(&dmap->lock,flags);
576 return err;
577 }
578 /* Wait for the next block */
579
580 if (dontblock) {
581 spin_unlock_irqrestore(&dmap->lock,flags);
582 return -EAGAIN;
583 }
584 if ((go = adev->go))
585 timeout = dmabuf_timeout(dmap);
586
587 spin_unlock_irqrestore(&dmap->lock,flags);
588 timeout = interruptible_sleep_on_timeout(&adev->in_sleeper,
589 timeout);
590 if (!timeout) {
591 /* FIXME: include device name */
592 err = -EIO;
593 printk(KERN_WARNING "Sound: DMA (input) timed out - IRQ/DRQ config error?\n");
594 dma_reset_input(dev);
595 } else
596 err = -EINTR;
597 spin_lock_irqsave(&dmap->lock,flags);
598 }
599 spin_unlock_irqrestore(&dmap->lock,flags);
600
601 if (dmap->qlen <= 0)
602 return err ? err : -EINTR;
603 *buf = &dmap->raw_buf[dmap->qhead * dmap->fragment_size + dmap->counts[dmap->qhead]];
604 *len = dmap->fragment_size - dmap->counts[dmap->qhead];
605
606 return dmap->qhead;
607}
608
609int DMAbuf_rmchars(int dev, int buff_no, int c)
610{
611 struct audio_operations *adev = audio_devs[dev];
612 struct dma_buffparms *dmap = adev->dmap_in;
613 int p = dmap->counts[dmap->qhead] + c;
614
615 if (dmap->mapping_flags & DMA_MAP_MAPPED)
616 {
617/* printk("Sound: Can't read from mmapped device (2)\n");*/
618 return -EINVAL;
619 }
620 else if (dmap->qlen <= 0)
621 return -EIO;
622 else if (p >= dmap->fragment_size) { /* This buffer is completely empty */
623 dmap->counts[dmap->qhead] = 0;
624 dmap->qlen--;
625 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
626 }
627 else dmap->counts[dmap->qhead] = p;
628
629 return 0;
630}
631/* MUST be called with dmap->lock hold */
632int DMAbuf_get_buffer_pointer(int dev, struct dma_buffparms *dmap, int direction)
633{
634 /*
635 * Try to approximate the active byte position of the DMA pointer within the
636 * buffer area as well as possible.
637 */
638
639 int pos;
640 unsigned long f;
641
642 if (!(dmap->flags & DMA_ACTIVE))
643 pos = 0;
644 else {
645 int chan = dmap->dma;
646
647 f=claim_dma_lock();
648 clear_dma_ff(chan);
649
650 if(!isa_dma_bridge_buggy)
651 disable_dma(dmap->dma);
652
653 pos = get_dma_residue(chan);
654
655 pos = dmap->bytes_in_use - pos;
656
657 if (!(dmap->mapping_flags & DMA_MAP_MAPPED)) {
658 if (direction == DMODE_OUTPUT) {
659 if (dmap->qhead == 0)
660 if (pos > dmap->fragment_size)
661 pos = 0;
662 } else {
663 if (dmap->qtail == 0)
664 if (pos > dmap->fragment_size)
665 pos = 0;
666 }
667 }
668 if (pos < 0)
669 pos = 0;
670 if (pos >= dmap->bytes_in_use)
671 pos = 0;
672
673 if(!isa_dma_bridge_buggy)
674 enable_dma(dmap->dma);
675
676 release_dma_lock(f);
677 }
678 /* printk( "%04x ", pos); */
679
680 return pos;
681}
682
683/*
684 * DMAbuf_start_devices() is called by the /dev/music driver to start
685 * one or more audio devices at desired moment.
686 */
687
688void DMAbuf_start_devices(unsigned int devmask)
689{
690 struct audio_operations *adev;
691 int dev;
692
693 for (dev = 0; dev < num_audiodevs; dev++) {
694 if (!(devmask & (1 << dev)))
695 continue;
696 if (!(adev = audio_devs[dev]))
697 continue;
698 if (adev->open_mode == 0)
699 continue;
700 if (adev->go)
701 continue;
702 /* OK to start the device */
703 adev->go = 1;
704 if (adev->d->trigger)
705 adev->d->trigger(dev,adev->enable_bits * adev->go);
706 }
707}
708/* via poll called without a lock ?*/
709int DMAbuf_space_in_queue(int dev)
710{
711 struct audio_operations *adev = audio_devs[dev];
712 int len, max, tmp;
713 struct dma_buffparms *dmap = adev->dmap_out;
714 int lim = dmap->nbufs;
715
716 if (lim < 2)
717 lim = 2;
718
719 if (dmap->qlen >= lim) /* No space at all */
720 return 0;
721
722 /*
723 * Verify that there are no more pending buffers than the limit
724 * defined by the process.
725 */
726
727 max = dmap->max_fragments;
728 if (max > lim)
729 max = lim;
730 len = dmap->qlen;
731
732 if (adev->d->local_qlen) {
733 tmp = adev->d->local_qlen(dev);
734 if (tmp && len)
735 tmp--; /* This buffer has been counted twice */
736 len += tmp;
737 }
738 if (dmap->byte_counter % dmap->fragment_size) /* There is a partial fragment */
739 len = len + 1;
740
741 if (len >= max)
742 return 0;
743 return max - len;
744}
745/* MUST not hold the spinlock - this function may sleep */
746static int output_sleep(int dev, int dontblock)
747{
748 struct audio_operations *adev = audio_devs[dev];
749 int err = 0;
750 struct dma_buffparms *dmap = adev->dmap_out;
751 long timeout;
752 long timeout_value;
753
754 if (dontblock)
755 return -EAGAIN;
756 if (!(adev->enable_bits & PCM_ENABLE_OUTPUT))
757 return -EAGAIN;
758
759 /*
760 * Wait for free space
761 */
762 if (signal_pending(current))
763 return -EINTR;
764 timeout = (adev->go && !(dmap->flags & DMA_NOTIMEOUT));
765 if (timeout)
766 timeout_value = dmabuf_timeout(dmap);
767 else
768 timeout_value = MAX_SCHEDULE_TIMEOUT;
769 timeout_value = interruptible_sleep_on_timeout(&adev->out_sleeper,
770 timeout_value);
771 if (timeout != MAX_SCHEDULE_TIMEOUT && !timeout_value) {
772 printk(KERN_WARNING "Sound: DMA (output) timed out - IRQ/DRQ config error?\n");
773 dma_reset_output(dev);
774 } else {
775 if (signal_pending(current))
776 err = -EINTR;
777 }
778 return err;
779}
780/* called with the lock held */
781static int find_output_space(int dev, char **buf, int *size)
782{
783 struct audio_operations *adev = audio_devs[dev];
784 struct dma_buffparms *dmap = adev->dmap_out;
785 unsigned long active_offs;
786 long len, offs;
787 int maxfrags;
788 int occupied_bytes = (dmap->user_counter % dmap->fragment_size);
789
790 *buf = dmap->raw_buf;
791 if (!(maxfrags = DMAbuf_space_in_queue(dev)) && !occupied_bytes)
792 return 0;
793
794#ifdef BE_CONSERVATIVE
795 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size;
796#else
797 active_offs = DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT);
798 /* Check for pointer wrapping situation */
799 if (active_offs < 0 || active_offs >= dmap->bytes_in_use)
800 active_offs = 0;
801 active_offs += dmap->byte_counter;
802#endif
803
804 offs = (dmap->user_counter % dmap->bytes_in_use) & ~SAMPLE_ROUNDUP;
805 if (offs < 0 || offs >= dmap->bytes_in_use) {
806 printk(KERN_ERR "Sound: Got unexpected offs %ld. Giving up.\n", offs);
807 printk("Counter = %ld, bytes=%d\n", dmap->user_counter, dmap->bytes_in_use);
808 return 0;
809 }
810 *buf = dmap->raw_buf + offs;
811
812 len = active_offs + dmap->bytes_in_use - dmap->user_counter; /* Number of unused bytes in buffer */
813
814 if ((offs + len) > dmap->bytes_in_use)
815 len = dmap->bytes_in_use - offs;
816 if (len < 0) {
817 return 0;
818 }
819 if (len > ((maxfrags * dmap->fragment_size) - occupied_bytes))
820 len = (maxfrags * dmap->fragment_size) - occupied_bytes;
821 *size = len & ~SAMPLE_ROUNDUP;
822 return (*size > 0);
823}
824/* aquires lock */
825int DMAbuf_getwrbuffer(int dev, char **buf, int *size, int dontblock)
826{
827 struct audio_operations *adev = audio_devs[dev];
828 unsigned long flags;
829 int err = -EIO;
830 struct dma_buffparms *dmap = adev->dmap_out;
831
832 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
833/* printk(KERN_DEBUG "Sound: Can't write to mmapped device (3)\n");*/
834 return -EINVAL;
835 }
836 spin_lock_irqsave(&dmap->lock,flags);
837 if (dmap->needs_reorg)
838 reorganize_buffers(dev, dmap, 0);
839
840 if (dmap->dma_mode == DMODE_INPUT) { /* Direction change */
841 spin_unlock_irqrestore(&dmap->lock,flags);
842 DMAbuf_reset(dev);
843 spin_lock_irqsave(&dmap->lock,flags);
844 }
845 dmap->dma_mode = DMODE_OUTPUT;
846
847 while (find_output_space(dev, buf, size) <= 0) {
848 spin_unlock_irqrestore(&dmap->lock,flags);
849 if ((err = output_sleep(dev, dontblock)) < 0) {
850 return err;
851 }
852 spin_lock_irqsave(&dmap->lock,flags);
853 }
854
855 spin_unlock_irqrestore(&dmap->lock,flags);
856 return 0;
857}
858/* has to aquire dmap->lock */
859int DMAbuf_move_wrpointer(int dev, int l)
860{
861 struct audio_operations *adev = audio_devs[dev];
862 struct dma_buffparms *dmap = adev->dmap_out;
863 unsigned long ptr;
864 unsigned long end_ptr, p;
865 int post;
866 unsigned long flags;
867
868 spin_lock_irqsave(&dmap->lock,flags);
869 post= (dmap->flags & DMA_POST);
870 ptr = (dmap->user_counter / dmap->fragment_size) * dmap->fragment_size;
871
872 dmap->flags &= ~DMA_POST;
873 dmap->cfrag = -1;
874 dmap->user_counter += l;
875 dmap->flags |= DMA_DIRTY;
876
877 if (dmap->byte_counter >= dmap->max_byte_counter) {
878 /* Wrap the byte counters */
879 long decr = dmap->byte_counter;
880 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
881 decr -= dmap->byte_counter;
882 dmap->user_counter -= decr;
883 }
884 end_ptr = (dmap->user_counter / dmap->fragment_size) * dmap->fragment_size;
885
886 p = (dmap->user_counter - 1) % dmap->bytes_in_use;
887 dmap->neutral_byte = dmap->raw_buf[p];
888
889 /* Update the fragment based bookkeeping too */
890 while (ptr < end_ptr) {
891 dmap->counts[dmap->qtail] = dmap->fragment_size;
892 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
893 dmap->qlen++;
894 ptr += dmap->fragment_size;
895 }
896
897 dmap->counts[dmap->qtail] = dmap->user_counter - ptr;
898
899 /*
900 * Let the low level driver perform some postprocessing to
901 * the written data.
902 */
903 if (adev->d->postprocess_write)
904 adev->d->postprocess_write(dev);
905
906 if (!(dmap->flags & DMA_ACTIVE))
907 if (dmap->qlen > 1 || (dmap->qlen > 0 && (post || dmap->qlen >= dmap->nbufs - 1)))
908 DMAbuf_launch_output(dev, dmap);
909
910 spin_unlock_irqrestore(&dmap->lock,flags);
911 return 0;
912}
913
914int DMAbuf_start_dma(int dev, unsigned long physaddr, int count, int dma_mode)
915{
916 struct audio_operations *adev = audio_devs[dev];
917 struct dma_buffparms *dmap = (dma_mode == DMA_MODE_WRITE) ? adev->dmap_out : adev->dmap_in;
918
919 if (dmap->raw_buf == NULL) {
920 printk(KERN_ERR "sound: DMA buffer(1) == NULL\n");
921 printk("Device %d, chn=%s\n", dev, (dmap == adev->dmap_out) ? "out" : "in");
922 return 0;
923 }
924 if (dmap->dma < 0)
925 return 0;
926 sound_start_dma(dmap, physaddr, count, dma_mode);
927 return count;
928}
929
930static int local_start_dma(struct audio_operations *adev, unsigned long physaddr, int count, int dma_mode)
931{
932 struct dma_buffparms *dmap = (dma_mode == DMA_MODE_WRITE) ? adev->dmap_out : adev->dmap_in;
933
934 if (dmap->raw_buf == NULL) {
935 printk(KERN_ERR "sound: DMA buffer(2) == NULL\n");
936 printk(KERN_ERR "Device %s, chn=%s\n", adev->name, (dmap == adev->dmap_out) ? "out" : "in");
937 return 0;
938 }
939 if (dmap->flags & DMA_NODMA)
940 return 1;
941 if (dmap->dma < 0)
942 return 0;
943 sound_start_dma(dmap, dmap->raw_buf_phys, dmap->bytes_in_use, dma_mode | DMA_AUTOINIT);
944 dmap->flags |= DMA_STARTED;
945 return count;
946}
947
948static void finish_output_interrupt(int dev, struct dma_buffparms *dmap)
949{
950 struct audio_operations *adev = audio_devs[dev];
951
952 if (dmap->audio_callback != NULL)
953 dmap->audio_callback(dev, dmap->callback_parm);
954 wake_up(&adev->out_sleeper);
955 wake_up(&adev->poll_sleeper);
956}
957/* called with dmap->lock held in irq context*/
958static void do_outputintr(int dev, int dummy)
959{
960 struct audio_operations *adev = audio_devs[dev];
961 struct dma_buffparms *dmap = adev->dmap_out;
962 int this_fragment;
963
964 if (dmap->raw_buf == NULL) {
965 printk(KERN_ERR "Sound: Error. Audio interrupt (%d) after freeing buffers.\n", dev);
966 return;
967 }
968 if (dmap->mapping_flags & DMA_MAP_MAPPED) { /* Virtual memory mapped access */
969 /* mmapped access */
970 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
971 if (dmap->qhead == 0) { /* Wrapped */
972 dmap->byte_counter += dmap->bytes_in_use;
973 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
974 long decr = dmap->byte_counter;
975 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
976 decr -= dmap->byte_counter;
977 dmap->user_counter -= decr;
978 }
979 }
980 dmap->qlen++; /* Yes increment it (don't decrement) */
981 if (!(adev->flags & DMA_AUTOMODE))
982 dmap->flags &= ~DMA_ACTIVE;
983 dmap->counts[dmap->qhead] = dmap->fragment_size;
984 DMAbuf_launch_output(dev, dmap);
985 finish_output_interrupt(dev, dmap);
986 return;
987 }
988
989 dmap->qlen--;
990 this_fragment = dmap->qhead;
991 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
992
993 if (dmap->qhead == 0) { /* Wrapped */
994 dmap->byte_counter += dmap->bytes_in_use;
995 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
996 long decr = dmap->byte_counter;
997 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
998 decr -= dmap->byte_counter;
999 dmap->user_counter -= decr;
1000 }
1001 }
1002 if (!(adev->flags & DMA_AUTOMODE))
1003 dmap->flags &= ~DMA_ACTIVE;
1004
1005 /*
1006 * This is dmap->qlen <= 0 except when closing when
1007 * dmap->qlen < 0
1008 */
1009
1010 while (dmap->qlen <= -dmap->closing) {
1011 dmap->underrun_count++;
1012 dmap->qlen++;
1013 if ((dmap->flags & DMA_DIRTY) && dmap->applic_profile != APF_CPUINTENS) {
1014 dmap->flags &= ~DMA_DIRTY;
1015 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte,
1016 adev->dmap_out->buffsize);
1017 }
1018 dmap->user_counter += dmap->fragment_size;
1019 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1020 }
1021 if (dmap->qlen > 0)
1022 DMAbuf_launch_output(dev, dmap);
1023 finish_output_interrupt(dev, dmap);
1024}
1025/* called in irq context */
1026void DMAbuf_outputintr(int dev, int notify_only)
1027{
1028 struct audio_operations *adev = audio_devs[dev];
1029 unsigned long flags;
1030 struct dma_buffparms *dmap = adev->dmap_out;
1031
1032 spin_lock_irqsave(&dmap->lock,flags);
1033 if (!(dmap->flags & DMA_NODMA)) {
1034 int chan = dmap->dma, pos, n;
1035 unsigned long f;
1036
1037 f=claim_dma_lock();
1038
1039 if(!isa_dma_bridge_buggy)
1040 disable_dma(dmap->dma);
1041 clear_dma_ff(chan);
1042 pos = dmap->bytes_in_use - get_dma_residue(chan);
1043 if(!isa_dma_bridge_buggy)
1044 enable_dma(dmap->dma);
1045 release_dma_lock(f);
1046
1047 pos = pos / dmap->fragment_size; /* Actual qhead */
1048 if (pos < 0 || pos >= dmap->nbufs)
1049 pos = 0;
1050 n = 0;
1051 while (dmap->qhead != pos && n++ < dmap->nbufs)
1052 do_outputintr(dev, notify_only);
1053 }
1054 else
1055 do_outputintr(dev, notify_only);
1056 spin_unlock_irqrestore(&dmap->lock,flags);
1057}
1058/* called with dmap->lock held in irq context */
1059static void do_inputintr(int dev)
1060{
1061 struct audio_operations *adev = audio_devs[dev];
1062 struct dma_buffparms *dmap = adev->dmap_in;
1063
1064 if (dmap->raw_buf == NULL) {
1065 printk(KERN_ERR "Sound: Fatal error. Audio interrupt after freeing buffers.\n");
1066 return;
1067 }
1068 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1069 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1070 if (dmap->qtail == 0) { /* Wrapped */
1071 dmap->byte_counter += dmap->bytes_in_use;
1072 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
1073 long decr = dmap->byte_counter;
1074 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use) + dmap->bytes_in_use;
1075 decr -= dmap->byte_counter;
1076 dmap->user_counter -= decr;
1077 }
1078 }
1079 dmap->qlen++;
1080
1081 if (!(adev->flags & DMA_AUTOMODE)) {
1082 if (dmap->needs_reorg)
1083 reorganize_buffers(dev, dmap, 0);
1084 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use,DMA_MODE_READ);
1085 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size,
1086 dmap->fragment_size, 1);
1087 if (adev->d->trigger)
1088 adev->d->trigger(dev, adev->enable_bits * adev->go);
1089 }
1090 dmap->flags |= DMA_ACTIVE;
1091 } else if (dmap->qlen >= (dmap->nbufs - 1)) {
1092 printk(KERN_WARNING "Sound: Recording overrun\n");
1093 dmap->underrun_count++;
1094
1095 /* Just throw away the oldest fragment but keep the engine running */
1096 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
1097 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1098 } else if (dmap->qlen >= 0 && dmap->qlen < dmap->nbufs) {
1099 dmap->qlen++;
1100 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1101 if (dmap->qtail == 0) { /* Wrapped */
1102 dmap->byte_counter += dmap->bytes_in_use;
1103 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
1104 long decr = dmap->byte_counter;
1105 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use) + dmap->bytes_in_use;
1106 decr -= dmap->byte_counter;
1107 dmap->user_counter -= decr;
1108 }
1109 }
1110 }
1111 if (!(adev->flags & DMA_AUTOMODE) || (dmap->flags & DMA_NODMA)) {
1112 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use, DMA_MODE_READ);
1113 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size, dmap->fragment_size, 1);
1114 if (adev->d->trigger)
1115 adev->d->trigger(dev,adev->enable_bits * adev->go);
1116 }
1117 dmap->flags |= DMA_ACTIVE;
1118 if (dmap->qlen > 0)
1119 {
1120 wake_up(&adev->in_sleeper);
1121 wake_up(&adev->poll_sleeper);
1122 }
1123}
1124/* called in irq context */
1125void DMAbuf_inputintr(int dev)
1126{
1127 struct audio_operations *adev = audio_devs[dev];
1128 struct dma_buffparms *dmap = adev->dmap_in;
1129 unsigned long flags;
1130
1131 spin_lock_irqsave(&dmap->lock,flags);
1132
1133 if (!(dmap->flags & DMA_NODMA)) {
1134 int chan = dmap->dma, pos, n;
1135 unsigned long f;
1136
1137 f=claim_dma_lock();
1138 if(!isa_dma_bridge_buggy)
1139 disable_dma(dmap->dma);
1140 clear_dma_ff(chan);
1141 pos = dmap->bytes_in_use - get_dma_residue(chan);
1142 if(!isa_dma_bridge_buggy)
1143 enable_dma(dmap->dma);
1144 release_dma_lock(f);
1145
1146 pos = pos / dmap->fragment_size; /* Actual qhead */
1147 if (pos < 0 || pos >= dmap->nbufs)
1148 pos = 0;
1149
1150 n = 0;
1151 while (dmap->qtail != pos && ++n < dmap->nbufs)
1152 do_inputintr(dev);
1153 } else
1154 do_inputintr(dev);
1155 spin_unlock_irqrestore(&dmap->lock,flags);
1156}
1157
1158int DMAbuf_open_dma(int dev)
1159{
1160 /*
1161 * NOTE! This routine opens only the primary DMA channel (output).
1162 */
1163 struct audio_operations *adev = audio_devs[dev];
1164 int err;
1165
1166 if ((err = open_dmap(adev, OPEN_READWRITE, adev->dmap_out)) < 0)
1167 return -EBUSY;
1168 dma_init_buffers(adev->dmap_out);
1169 adev->dmap_out->flags |= DMA_ALLOC_DONE;
1170 adev->dmap_out->fragment_size = adev->dmap_out->buffsize;
1171
1172 if (adev->dmap_out->dma >= 0) {
1173 unsigned long flags;
1174
1175 flags=claim_dma_lock();
1176 clear_dma_ff(adev->dmap_out->dma);
1177 disable_dma(adev->dmap_out->dma);
1178 release_dma_lock(flags);
1179 }
1180 return 0;
1181}
1182
1183void DMAbuf_close_dma(int dev)
1184{
1185 close_dmap(audio_devs[dev], audio_devs[dev]->dmap_out);
1186}
1187
1188void DMAbuf_init(int dev, int dma1, int dma2)
1189{
1190 struct audio_operations *adev = audio_devs[dev];
1191 /*
1192 * NOTE! This routine could be called several times.
1193 */
1194
1195 /* drag in audio_syms.o */
1196 {
1197 extern char audio_syms_symbol;
1198 audio_syms_symbol = 0;
1199 }
1200
1201 if (adev && adev->dmap_out == NULL) {
1202 if (adev->d == NULL)
1203 panic("OSS: audio_devs[%d]->d == NULL\n", dev);
1204
1205 if (adev->parent_dev) { /* Use DMA map of the parent dev */
1206 int parent = adev->parent_dev - 1;
1207 adev->dmap_out = audio_devs[parent]->dmap_out;
1208 adev->dmap_in = audio_devs[parent]->dmap_in;
1209 } else {
1210 adev->dmap_out = adev->dmap_in = &adev->dmaps[0];
1211 adev->dmap_out->dma = dma1;
1212 if (adev->flags & DMA_DUPLEX) {
1213 adev->dmap_in = &adev->dmaps[1];
1214 adev->dmap_in->dma = dma2;
1215 }
1216 }
1217 /* Persistent DMA buffers allocated here */
1218 if (sound_dmap_flag == DMAP_KEEP_ON_CLOSE) {
1219 if (adev->dmap_in->raw_buf == NULL)
1220 sound_alloc_dmap(adev->dmap_in);
1221 if (adev->dmap_out->raw_buf == NULL)
1222 sound_alloc_dmap(adev->dmap_out);
1223 }
1224 }
1225}
1226
1227/* No kernel lock - DMAbuf_activate_recording protected by global cli/sti */
1228static unsigned int poll_input(struct file * file, int dev, poll_table *wait)
1229{
1230 struct audio_operations *adev = audio_devs[dev];
1231 struct dma_buffparms *dmap = adev->dmap_in;
1232
1233 if (!(adev->open_mode & OPEN_READ))
1234 return 0;
1235 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1236 if (dmap->qlen)
1237 return POLLIN | POLLRDNORM;
1238 return 0;
1239 }
1240 if (dmap->dma_mode != DMODE_INPUT) {
1241 if (dmap->dma_mode == DMODE_NONE &&
1242 adev->enable_bits & PCM_ENABLE_INPUT &&
1243 !dmap->qlen && adev->go) {
1244 unsigned long flags;
1245
1246 spin_lock_irqsave(&dmap->lock,flags);
1247 DMAbuf_activate_recording(dev, dmap);
1248 spin_unlock_irqrestore(&dmap->lock,flags);
1249 }
1250 return 0;
1251 }
1252 if (!dmap->qlen)
1253 return 0;
1254 return POLLIN | POLLRDNORM;
1255}
1256
1257static unsigned int poll_output(struct file * file, int dev, poll_table *wait)
1258{
1259 struct audio_operations *adev = audio_devs[dev];
1260 struct dma_buffparms *dmap = adev->dmap_out;
1261
1262 if (!(adev->open_mode & OPEN_WRITE))
1263 return 0;
1264 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1265 if (dmap->qlen)
1266 return POLLOUT | POLLWRNORM;
1267 return 0;
1268 }
1269 if (dmap->dma_mode == DMODE_INPUT)
1270 return 0;
1271 if (dmap->dma_mode == DMODE_NONE)
1272 return POLLOUT | POLLWRNORM;
1273 if (!DMAbuf_space_in_queue(dev))
1274 return 0;
1275 return POLLOUT | POLLWRNORM;
1276}
1277
1278unsigned int DMAbuf_poll(struct file * file, int dev, poll_table *wait)
1279{
1280 struct audio_operations *adev = audio_devs[dev];
1281 poll_wait(file, &adev->poll_sleeper, wait);
1282 return poll_input(file, dev, wait) | poll_output(file, dev, wait);
1283}
1284
1285void DMAbuf_deinit(int dev)
1286{
1287 struct audio_operations *adev = audio_devs[dev];
1288 /* This routine is called when driver is being unloaded */
1289 if (!adev)
1290 return;
1291
1292 /* Persistent DMA buffers deallocated here */
1293 if (sound_dmap_flag == DMAP_KEEP_ON_CLOSE) {
1294 sound_free_dmap(adev->dmap_out);
1295 if (adev->flags & DMA_DUPLEX)
1296 sound_free_dmap(adev->dmap_in);
1297 }
1298}
diff --git a/sound/oss/dmasound/Kconfig b/sound/oss/dmasound/Kconfig
new file mode 100644
index 000000000000..cb845580fe03
--- /dev/null
+++ b/sound/oss/dmasound/Kconfig
@@ -0,0 +1,58 @@
1config DMASOUND_ATARI
2 tristate "Atari DMA sound support"
3 depends on ATARI && SOUND
4 select DMASOUND
5 help
6 If you want to use the internal audio of your Atari in Linux, answer
7 Y to this question. This will provide a Sun-like /dev/audio,
8 compatible with the Linux/i386 sound system. Otherwise, say N.
9
10 This driver is also available as a module ( = code which can be
11 inserted in and removed from the running kernel whenever you
12 want). If you want to compile it as a module, say M here and read
13 <file:Documentation/kbuild/modules.txt>.
14
15config DMASOUND_PMAC
16 tristate "PowerMac DMA sound support"
17 depends on PPC32 && PPC_PMAC && SOUND && I2C
18 select DMASOUND
19 help
20 If you want to use the internal audio of your PowerMac in Linux,
21 answer Y to this question. This will provide a Sun-like /dev/audio,
22 compatible with the Linux/i386 sound system. Otherwise, say N.
23
24 This driver is also available as a module ( = code which can be
25 inserted in and removed from the running kernel whenever you
26 want). If you want to compile it as a module, say M here and read
27 <file:Documentation/kbuild/modules.txt>.
28
29config DMASOUND_PAULA
30 tristate "Amiga DMA sound support"
31 depends on (AMIGA || APUS) && SOUND
32 select DMASOUND
33 help
34 If you want to use the internal audio of your Amiga in Linux, answer
35 Y to this question. This will provide a Sun-like /dev/audio,
36 compatible with the Linux/i386 sound system. Otherwise, say N.
37
38 This driver is also available as a module ( = code which can be
39 inserted in and removed from the running kernel whenever you
40 want). If you want to compile it as a module, say M here and read
41 <file:Documentation/kbuild/modules.txt>.
42
43config DMASOUND_Q40
44 tristate "Q40 sound support"
45 depends on Q40 && SOUND
46 select DMASOUND
47 help
48 If you want to use the internal audio of your Q40 in Linux, answer
49 Y to this question. This will provide a Sun-like /dev/audio,
50 compatible with the Linux/i386 sound system. Otherwise, say N.
51
52 This driver is also available as a module ( = code which can be
53 inserted in and removed from the running kernel whenever you
54 want). If you want to compile it as a module, say M here and read
55 <file:Documentation/kbuild/modules.txt>.
56
57config DMASOUND
58 tristate
diff --git a/sound/oss/dmasound/Makefile b/sound/oss/dmasound/Makefile
new file mode 100644
index 000000000000..4611636b1a81
--- /dev/null
+++ b/sound/oss/dmasound/Makefile
@@ -0,0 +1,13 @@
1#
2# Makefile for the DMA sound driver
3#
4
5dmasound_pmac-y += dmasound_awacs.o \
6 trans_16.o dac3550a.o tas_common.o \
7 tas3001c.o tas3001c_tables.o \
8 tas3004.o tas3004_tables.o
9
10obj-$(CONFIG_DMASOUND_ATARI) += dmasound_core.o dmasound_atari.o
11obj-$(CONFIG_DMASOUND_PMAC) += dmasound_core.o dmasound_pmac.o
12obj-$(CONFIG_DMASOUND_PAULA) += dmasound_core.o dmasound_paula.o
13obj-$(CONFIG_DMASOUND_Q40) += dmasound_core.o dmasound_q40.o
diff --git a/sound/oss/dmasound/awacs_defs.h b/sound/oss/dmasound/awacs_defs.h
new file mode 100644
index 000000000000..2194f46b046c
--- /dev/null
+++ b/sound/oss/dmasound/awacs_defs.h
@@ -0,0 +1,251 @@
1/*********************************************************/
2/* This file was written by someone, somewhere, sometime */
3/* And is released into the Public Domain */
4/*********************************************************/
5
6#ifndef _AWACS_DEFS_H_
7#define _AWACS_DEFS_H_
8
9/*******************************/
10/* AWACs Audio Register Layout */
11/*******************************/
12
13struct awacs_regs {
14 unsigned control; /* Audio control register */
15 unsigned pad0[3];
16 unsigned codec_ctrl; /* Codec control register */
17 unsigned pad1[3];
18 unsigned codec_stat; /* Codec status register */
19 unsigned pad2[3];
20 unsigned clip_count; /* Clipping count register */
21 unsigned pad3[3];
22 unsigned byteswap; /* Data is little-endian if 1 */
23};
24
25/*******************/
26/* Audio Bit Masks */
27/*******************/
28
29/* Audio Control Reg Bit Masks */
30/* ----- ------- --- --- ----- */
31#define MASK_ISFSEL (0xf) /* Input SubFrame Select */
32#define MASK_OSFSEL (0xf << 4) /* Output SubFrame Select */
33#define MASK_RATE (0x7 << 8) /* Sound Rate */
34#define MASK_CNTLERR (0x1 << 11) /* Error */
35#define MASK_PORTCHG (0x1 << 12) /* Port Change */
36#define MASK_IEE (0x1 << 13) /* Enable Interrupt on Error */
37#define MASK_IEPC (0x1 << 14) /* Enable Interrupt on Port Change */
38#define MASK_SSFSEL (0x3 << 15) /* Status SubFrame Select */
39
40/* Audio Codec Control Reg Bit Masks */
41/* ----- ----- ------- --- --- ----- */
42#define MASK_NEWECMD (0x1 << 24) /* Lock: don't write to reg when 1 */
43#define MASK_EMODESEL (0x3 << 22) /* Send info out on which frame? */
44#define MASK_EXMODEADDR (0x3ff << 12) /* Extended Mode Address -- 10 bits */
45#define MASK_EXMODEDATA (0xfff) /* Extended Mode Data -- 12 bits */
46
47/* Audio Codec Control Address Values / Masks */
48/* ----- ----- ------- ------- ------ - ----- */
49#define MASK_ADDR0 (0x0 << 12) /* Expanded Data Mode Address 0 */
50#define MASK_ADDR_MUX MASK_ADDR0 /* Mux Control */
51#define MASK_ADDR_GAIN MASK_ADDR0
52
53#define MASK_ADDR1 (0x1 << 12) /* Expanded Data Mode Address 1 */
54#define MASK_ADDR_MUTE MASK_ADDR1
55#define MASK_ADDR_RATE MASK_ADDR1
56
57#define MASK_ADDR2 (0x2 << 12) /* Expanded Data Mode Address 2 */
58#define MASK_ADDR_VOLA MASK_ADDR2 /* Volume Control A -- Headphones */
59#define MASK_ADDR_VOLHD MASK_ADDR2
60
61#define MASK_ADDR4 (0x4 << 12) /* Expanded Data Mode Address 4 */
62#define MASK_ADDR_VOLC MASK_ADDR4 /* Volume Control C -- Speaker */
63#define MASK_ADDR_VOLSPK MASK_ADDR4
64
65/* additional registers of screamer */
66#define MASK_ADDR5 (0x5 << 12) /* Expanded Data Mode Address 5 */
67#define MASK_ADDR6 (0x6 << 12) /* Expanded Data Mode Address 6 */
68#define MASK_ADDR7 (0x7 << 12) /* Expanded Data Mode Address 7 */
69
70/* Address 0 Bit Masks & Macros */
71/* ------- - --- ----- - ------ */
72#define MASK_GAINRIGHT (0xf) /* Gain Right Mask */
73#define MASK_GAINLEFT (0xf << 4) /* Gain Left Mask */
74#define MASK_GAINLINE (0x1 << 8) /* Disable Mic preamp */
75#define MASK_GAINMIC (0x0 << 8) /* Enable Mic preamp */
76
77#define MASK_MUX_CD (0x1 << 9) /* Select CD in MUX */
78#define MASK_MUX_MIC (0x1 << 10) /* Select Mic in MUX */
79#define MASK_MUX_AUDIN (0x1 << 11) /* Select Audio In in MUX */
80#define MASK_MUX_LINE MASK_MUX_AUDIN
81
82#define GAINRIGHT(x) ((x) & MASK_GAINRIGHT)
83#define GAINLEFT(x) (((x) << 4) & MASK_GAINLEFT)
84
85#define DEF_CD_GAIN 0x00bb
86#define DEF_MIC_GAIN 0x00cc
87
88/* Address 1 Bit Masks */
89/* ------- - --- ----- */
90#define MASK_ADDR1RES1 (0x3) /* Reserved */
91#define MASK_RECALIBRATE (0x1 << 2) /* Recalibrate */
92#define MASK_SAMPLERATE (0x7 << 3) /* Sample Rate: */
93#define MASK_LOOPTHRU (0x1 << 6) /* Loopthrough Enable */
94#define MASK_CMUTE (0x1 << 7) /* Output C (Speaker) Mute when 1 */
95#define MASK_SPKMUTE MASK_CMUTE
96#define MASK_ADDR1RES2 (0x1 << 8) /* Reserved */
97#define MASK_AMUTE (0x1 << 9) /* Output A (Headphone) Mute when 1 */
98#define MASK_HDMUTE MASK_AMUTE
99#define MASK_PAROUT0 (0x1 << 10) /* Parallel Output 0 */
100#define MASK_PAROUT1 (0x2 << 10) /* Parallel Output 1 */
101
102#define MASK_MIC_BOOST (0x4) /* screamer mic boost */
103
104#define SAMPLERATE_48000 (0x0 << 3) /* 48 or 44.1 kHz */
105#define SAMPLERATE_32000 (0x1 << 3) /* 32 or 29.4 kHz */
106#define SAMPLERATE_24000 (0x2 << 3) /* 24 or 22.05 kHz */
107#define SAMPLERATE_19200 (0x3 << 3) /* 19.2 or 17.64 kHz */
108#define SAMPLERATE_16000 (0x4 << 3) /* 16 or 14.7 kHz */
109#define SAMPLERATE_12000 (0x5 << 3) /* 12 or 11.025 kHz */
110#define SAMPLERATE_9600 (0x6 << 3) /* 9.6 or 8.82 kHz */
111#define SAMPLERATE_8000 (0x7 << 3) /* 8 or 7.35 kHz */
112
113/* Address 2 & 4 Bit Masks & Macros */
114/* ------- - - - --- ----- - ------ */
115#define MASK_OUTVOLRIGHT (0xf) /* Output Right Volume */
116#define MASK_ADDR2RES1 (0x2 << 4) /* Reserved */
117#define MASK_ADDR4RES1 MASK_ADDR2RES1
118#define MASK_OUTVOLLEFT (0xf << 6) /* Output Left Volume */
119#define MASK_ADDR2RES2 (0x2 << 10) /* Reserved */
120#define MASK_ADDR4RES2 MASK_ADDR2RES2
121
122#define VOLRIGHT(x) (((~(x)) & MASK_OUTVOLRIGHT))
123#define VOLLEFT(x) (((~(x)) << 6) & MASK_OUTVOLLEFT)
124
125/* Audio Codec Status Reg Bit Masks */
126/* ----- ----- ------ --- --- ----- */
127#define MASK_EXTEND (0x1 << 23) /* Extend */
128#define MASK_VALID (0x1 << 22) /* Valid Data? */
129#define MASK_OFLEFT (0x1 << 21) /* Overflow Left */
130#define MASK_OFRIGHT (0x1 << 20) /* Overflow Right */
131#define MASK_ERRCODE (0xf << 16) /* Error Code */
132#define MASK_REVISION (0xf << 12) /* Revision Number */
133#define MASK_MFGID (0xf << 8) /* Mfg. ID */
134#define MASK_CODSTATRES (0xf << 4) /* bits 4 - 7 reserved */
135#define MASK_INPPORT (0xf) /* Input Port */
136#define MASK_HDPCONN 8 /* headphone plugged in */
137
138/* Clipping Count Reg Bit Masks */
139/* -------- ----- --- --- ----- */
140#define MASK_CLIPLEFT (0xff << 7) /* Clipping Count, Left Channel */
141#define MASK_CLIPRIGHT (0xff) /* Clipping Count, Right Channel */
142
143/* DBDMA ChannelStatus Bit Masks */
144/* ----- ------------- --- ----- */
145#define MASK_CSERR (0x1 << 7) /* Error */
146#define MASK_EOI (0x1 << 6) /* End of Input -- only for Input Channel */
147#define MASK_CSUNUSED (0x1f << 1) /* bits 1-5 not used */
148#define MASK_WAIT (0x1) /* Wait */
149
150/* Various Rates */
151/* ------- ----- */
152#define RATE_48000 (0x0 << 8) /* 48 kHz */
153#define RATE_44100 (0x0 << 8) /* 44.1 kHz */
154#define RATE_32000 (0x1 << 8) /* 32 kHz */
155#define RATE_29400 (0x1 << 8) /* 29.4 kHz */
156#define RATE_24000 (0x2 << 8) /* 24 kHz */
157#define RATE_22050 (0x2 << 8) /* 22.05 kHz */
158#define RATE_19200 (0x3 << 8) /* 19.2 kHz */
159#define RATE_17640 (0x3 << 8) /* 17.64 kHz */
160#define RATE_16000 (0x4 << 8) /* 16 kHz */
161#define RATE_14700 (0x4 << 8) /* 14.7 kHz */
162#define RATE_12000 (0x5 << 8) /* 12 kHz */
163#define RATE_11025 (0x5 << 8) /* 11.025 kHz */
164#define RATE_9600 (0x6 << 8) /* 9.6 kHz */
165#define RATE_8820 (0x6 << 8) /* 8.82 kHz */
166#define RATE_8000 (0x7 << 8) /* 8 kHz */
167#define RATE_7350 (0x7 << 8) /* 7.35 kHz */
168
169#define RATE_LOW 1 /* HIGH = 48kHz, etc; LOW = 44.1kHz, etc. */
170
171/*******************/
172/* Burgundy values */
173/*******************/
174
175#define MASK_ADDR_BURGUNDY_INPSEL21 (0x11 << 12)
176#define MASK_ADDR_BURGUNDY_INPSEL3 (0x12 << 12)
177
178#define MASK_ADDR_BURGUNDY_GAINCH1 (0x13 << 12)
179#define MASK_ADDR_BURGUNDY_GAINCH2 (0x14 << 12)
180#define MASK_ADDR_BURGUNDY_GAINCH3 (0x15 << 12)
181#define MASK_ADDR_BURGUNDY_GAINCH4 (0x16 << 12)
182
183#define MASK_ADDR_BURGUNDY_VOLCH1 (0x20 << 12)
184#define MASK_ADDR_BURGUNDY_VOLCH2 (0x21 << 12)
185#define MASK_ADDR_BURGUNDY_VOLCH3 (0x22 << 12)
186#define MASK_ADDR_BURGUNDY_VOLCH4 (0x23 << 12)
187
188#define MASK_ADDR_BURGUNDY_OUTPUTSELECTS (0x2B << 12)
189#define MASK_ADDR_BURGUNDY_OUTPUTENABLES (0x2F << 12)
190
191#define MASK_ADDR_BURGUNDY_MASTER_VOLUME (0x30 << 12)
192
193#define MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES (0x60 << 12)
194
195#define MASK_ADDR_BURGUNDY_ATTENSPEAKER (0x62 << 12)
196#define MASK_ADDR_BURGUNDY_ATTENLINEOUT (0x63 << 12)
197#define MASK_ADDR_BURGUNDY_ATTENHP (0x64 << 12)
198
199#define MASK_ADDR_BURGUNDY_VOLCD (MASK_ADDR_BURGUNDY_VOLCH1)
200#define MASK_ADDR_BURGUNDY_VOLLINE (MASK_ADDR_BURGUNDY_VOLCH2)
201#define MASK_ADDR_BURGUNDY_VOLMIC (MASK_ADDR_BURGUNDY_VOLCH3)
202#define MASK_ADDR_BURGUNDY_VOLMODEM (MASK_ADDR_BURGUNDY_VOLCH4)
203
204#define MASK_ADDR_BURGUNDY_GAINCD (MASK_ADDR_BURGUNDY_GAINCH1)
205#define MASK_ADDR_BURGUNDY_GAINLINE (MASK_ADDR_BURGUNDY_GAINCH2)
206#define MASK_ADDR_BURGUNDY_GAINMIC (MASK_ADDR_BURGUNDY_GAINCH3)
207#define MASK_ADDR_BURGUNDY_GAINMODEM (MASK_ADDR_BURGUNDY_VOLCH4)
208
209
210/* These are all default values for the burgundy */
211#define DEF_BURGUNDY_INPSEL21 (0xAA)
212#define DEF_BURGUNDY_INPSEL3 (0x0A)
213
214#define DEF_BURGUNDY_GAINCD (0x33)
215#define DEF_BURGUNDY_GAINLINE (0x44)
216#define DEF_BURGUNDY_GAINMIC (0x44)
217#define DEF_BURGUNDY_GAINMODEM (0x06)
218
219/* Remember: lowest volume here is 0x9b */
220#define DEF_BURGUNDY_VOLCD (0xCCCCCCCC)
221#define DEF_BURGUNDY_VOLLINE (0x00000000)
222#define DEF_BURGUNDY_VOLMIC (0x00000000)
223#define DEF_BURGUNDY_VOLMODEM (0xCCCCCCCC)
224
225#define DEF_BURGUNDY_OUTPUTSELECTS (0x010f010f)
226#define DEF_BURGUNDY_OUTPUTENABLES (0x0A)
227
228#define DEF_BURGUNDY_MASTER_VOLUME (0xFFFFFFFF)
229
230#define DEF_BURGUNDY_MORE_OUTPUTENABLES (0x7E)
231
232#define DEF_BURGUNDY_ATTENSPEAKER (0x44)
233#define DEF_BURGUNDY_ATTENLINEOUT (0xCC)
234#define DEF_BURGUNDY_ATTENHP (0xCC)
235
236/*********************/
237/* i2s layout values */
238/*********************/
239
240#define I2S_REG_INT_CTL 0x00
241#define I2S_REG_SERIAL_FORMAT 0x10
242#define I2S_REG_CODEC_MSG_OUT 0x20
243#define I2S_REG_CODEC_MSG_IN 0x30
244#define I2S_REG_FRAME_COUNT 0x40
245#define I2S_REG_FRAME_MATCH 0x50
246#define I2S_REG_DATAWORD_SIZES 0x60
247#define I2S_REG_PEAKLEVEL_SEL 0x70
248#define I2S_REG_PEAKLEVEL_IN0 0x80
249#define I2S_REG_PEAKLEVEL_IN1 0x90
250
251#endif /* _AWACS_DEFS_H_ */
diff --git a/sound/oss/dmasound/dac3550a.c b/sound/oss/dmasound/dac3550a.c
new file mode 100644
index 000000000000..533895eba0eb
--- /dev/null
+++ b/sound/oss/dmasound/dac3550a.c
@@ -0,0 +1,210 @@
1/*
2 * Driver for the i2c/i2s based DAC3550a sound chip used
3 * on some Apple iBooks. Also known as "DACA".
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive
7 * for more details.
8 */
9
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/delay.h>
13#include <linux/proc_fs.h>
14#include <linux/ioport.h>
15#include <linux/sysctl.h>
16#include <linux/types.h>
17#include <linux/i2c.h>
18#include <linux/init.h>
19#include <asm/uaccess.h>
20#include <asm/errno.h>
21#include <asm/io.h>
22
23#include "dmasound.h"
24
25/* FYI: This code was derived from the tas3001c.c Texas/Tumbler mixer
26 * control code, as well as info derived from the AppleDACAAudio driver
27 * from Darwin CVS (main thing I derived being register numbers and
28 * values, as well as when to make the calls). */
29
30#define I2C_DRIVERID_DACA (0xFDCB)
31
32#define DACA_VERSION "0.1"
33#define DACA_DATE "20010930"
34
35static int cur_left_vol;
36static int cur_right_vol;
37static struct i2c_client *daca_client;
38
39static int daca_attach_adapter(struct i2c_adapter *adapter);
40static int daca_detect_client(struct i2c_adapter *adapter, int address);
41static int daca_detach_client(struct i2c_client *client);
42
43struct i2c_driver daca_driver = {
44 .owner = THIS_MODULE,
45 .name = "DAC3550A driver V " DACA_VERSION,
46 .id = I2C_DRIVERID_DACA,
47 .flags = I2C_DF_NOTIFY,
48 .attach_adapter = daca_attach_adapter,
49 .detach_client = daca_detach_client,
50};
51
52#define VOL_MAX ((1<<20) - 1)
53
54void daca_get_volume(uint * left_vol, uint *right_vol)
55{
56 *left_vol = cur_left_vol >> 5;
57 *right_vol = cur_right_vol >> 5;
58}
59
60int daca_set_volume(uint left_vol, uint right_vol)
61{
62 unsigned short voldata;
63
64 if (!daca_client)
65 return -1;
66
67 /* Derived from experience, not from any specific values */
68 left_vol <<= 5;
69 right_vol <<= 5;
70
71 if (left_vol > VOL_MAX)
72 left_vol = VOL_MAX;
73 if (right_vol > VOL_MAX)
74 right_vol = VOL_MAX;
75
76 voldata = ((left_vol >> 14) & 0x3f) << 8;
77 voldata |= (right_vol >> 14) & 0x3f;
78
79 if (i2c_smbus_write_word_data(daca_client, 2, voldata) < 0) {
80 printk("daca: failed to set volume \n");
81 return -1;
82 }
83
84 cur_left_vol = left_vol;
85 cur_right_vol = right_vol;
86
87 return 0;
88}
89
90int daca_leave_sleep(void)
91{
92 if (!daca_client)
93 return -1;
94
95 /* Do a short sleep, just to make sure I2C bus is awake and paying
96 * attention to us
97 */
98 msleep(20);
99 /* Write the sample rate reg the value it needs */
100 i2c_smbus_write_byte_data(daca_client, 1, 8);
101 daca_set_volume(cur_left_vol >> 5, cur_right_vol >> 5);
102 /* Another short delay, just to make sure the other I2C bus writes
103 * have taken...
104 */
105 msleep(20);
106 /* Write the global config reg - invert right power amp,
107 * DAC on, use 5-volt mode */
108 i2c_smbus_write_byte_data(daca_client, 3, 0x45);
109
110 return 0;
111}
112
113int daca_enter_sleep(void)
114{
115 if (!daca_client)
116 return -1;
117
118 i2c_smbus_write_byte_data(daca_client, 1, 8);
119 daca_set_volume(cur_left_vol >> 5, cur_right_vol >> 5);
120
121 /* Write the global config reg - invert right power amp,
122 * DAC on, enter low-power mode, use 5-volt mode
123 */
124 i2c_smbus_write_byte_data(daca_client, 3, 0x65);
125
126 return 0;
127}
128
129static int daca_attach_adapter(struct i2c_adapter *adapter)
130{
131 if (!strncmp(adapter->name, "mac-io", 6))
132 daca_detect_client(adapter, 0x4d);
133 return 0;
134}
135
136static int daca_init_client(struct i2c_client * new_client)
137{
138 /*
139 * Probe is not working with the current i2c-keywest
140 * driver. We try to use addr 0x4d on each adapters
141 * instead, by setting the format register.
142 *
143 * FIXME: I'm sure that can be obtained from the
144 * device-tree. --BenH.
145 */
146
147 /* Write the global config reg - invert right power amp,
148 * DAC on, use 5-volt mode
149 */
150 if (i2c_smbus_write_byte_data(new_client, 3, 0x45))
151 return -1;
152
153 i2c_smbus_write_byte_data(new_client, 1, 8);
154 daca_client = new_client;
155 daca_set_volume(15000, 15000);
156
157 return 0;
158}
159
160static int daca_detect_client(struct i2c_adapter *adapter, int address)
161{
162 const char *client_name = "DAC 3550A Digital Equalizer";
163 struct i2c_client *new_client;
164 int rc = -ENODEV;
165
166 new_client = kmalloc(sizeof(*new_client), GFP_KERNEL);
167 if (!new_client)
168 return -ENOMEM;
169 memset(new_client, 0, sizeof(*new_client));
170
171 new_client->addr = address;
172 new_client->adapter = adapter;
173 new_client->driver = &daca_driver;
174 new_client->flags = 0;
175 strcpy(new_client->name, client_name);
176
177 if (daca_init_client(new_client))
178 goto bail;
179
180 /* Tell the i2c layer a new client has arrived */
181 if (i2c_attach_client(new_client))
182 goto bail;
183
184 return 0;
185 bail:
186 kfree(new_client);
187 return rc;
188}
189
190
191static int daca_detach_client(struct i2c_client *client)
192{
193 if (client == daca_client)
194 daca_client = NULL;
195
196 i2c_detach_client(client);
197 kfree(client);
198 return 0;
199}
200
201void daca_cleanup(void)
202{
203 i2c_del_driver(&daca_driver);
204}
205
206int daca_init(void)
207{
208 printk("dac3550a driver version %s (%s)\n",DACA_VERSION,DACA_DATE);
209 return i2c_add_driver(&daca_driver);
210}
diff --git a/sound/oss/dmasound/dmasound.h b/sound/oss/dmasound/dmasound.h
new file mode 100644
index 000000000000..9a2f50f0b184
--- /dev/null
+++ b/sound/oss/dmasound/dmasound.h
@@ -0,0 +1,277 @@
1#ifndef _dmasound_h_
2/*
3 * linux/sound/oss/dmasound/dmasound.h
4 *
5 *
6 * Minor numbers for the sound driver.
7 *
8 * Unfortunately Creative called the codec chip of SB as a DSP. For this
9 * reason the /dev/dsp is reserved for digitized audio use. There is a
10 * device for true DSP processors but it will be called something else.
11 * In v3.0 it's /dev/sndproc but this could be a temporary solution.
12 */
13#define _dmasound_h_
14
15#include <linux/types.h>
16#include <linux/config.h>
17
18#define SND_NDEVS 256 /* Number of supported devices */
19#define SND_DEV_CTL 0 /* Control port /dev/mixer */
20#define SND_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM
21 synthesizer and MIDI output) */
22#define SND_DEV_MIDIN 2 /* Raw midi access */
23#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */
24#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */
25#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */
26#define SND_DEV_STATUS 6 /* /dev/sndstat */
27/* #7 not in use now. Was in 2.4. Free for use after v3.0. */
28#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */
29#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */
30#define SND_DEV_PSS SND_DEV_SNDPROC
31
32/* switch on various prinks */
33#define DEBUG_DMASOUND 1
34
35#define MAX_AUDIO_DEV 5
36#define MAX_MIXER_DEV 4
37#define MAX_SYNTH_DEV 3
38#define MAX_MIDI_DEV 6
39#define MAX_TIMER_DEV 3
40
41#define MAX_CATCH_RADIUS 10
42
43#define le2be16(x) (((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
44#define le2be16dbl(x) (((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))
45
46#define IOCTL_IN(arg, ret) \
47 do { int error = get_user(ret, (int __user *)(arg)); \
48 if (error) return error; \
49 } while (0)
50#define IOCTL_OUT(arg, ret) ioctl_return((int __user *)(arg), ret)
51
52static inline int ioctl_return(int __user *addr, int value)
53{
54 return value < 0 ? value : put_user(value, addr);
55}
56
57
58 /*
59 * Configuration
60 */
61
62#undef HAS_8BIT_TABLES
63#undef HAS_RECORD
64
65#if defined(CONFIG_DMASOUND_ATARI) || defined(CONFIG_DMASOUND_ATARI_MODULE) ||\
66 defined(CONFIG_DMASOUND_PAULA) || defined(CONFIG_DMASOUND_PAULA_MODULE) ||\
67 defined(CONFIG_DMASOUND_Q40) || defined(CONFIG_DMASOUND_Q40_MODULE)
68#define HAS_8BIT_TABLES
69#define MIN_BUFFERS 4
70#define MIN_BUFSIZE (1<<12) /* in bytes (- where does this come from ?) */
71#define MIN_FRAG_SIZE 8 /* not 100% sure about this */
72#define MAX_BUFSIZE (1<<17) /* Limit for Amiga is 128 kb */
73#define MAX_FRAG_SIZE 15 /* allow *4 for mono-8 => stereo-16 (for multi) */
74
75#else /* is pmac and multi is off */
76
77#define MIN_BUFFERS 2
78#define MIN_BUFSIZE (1<<8) /* in bytes */
79#define MIN_FRAG_SIZE 8
80#define MAX_BUFSIZE (1<<18) /* this is somewhat arbitrary for pmac */
81#define MAX_FRAG_SIZE 16 /* need to allow *4 for mono-8 => stereo-16 */
82#endif
83
84#define DEFAULT_N_BUFFERS 4
85#define DEFAULT_BUFF_SIZE (1<<15)
86
87#if defined(CONFIG_DMASOUND_PMAC) || defined(CONFIG_DMASOUND_PMAC_MODULE)
88#define HAS_RECORD
89#endif
90
91 /*
92 * Initialization
93 */
94
95extern int dmasound_init(void);
96#ifdef MODULE
97extern void dmasound_deinit(void);
98#else
99#define dmasound_deinit() do { } while (0)
100#endif
101
102/* description of the set-up applies to either hard or soft settings */
103
104typedef struct {
105 int format; /* AFMT_* */
106 int stereo; /* 0 = mono, 1 = stereo */
107 int size; /* 8/16 bit*/
108 int speed; /* speed */
109} SETTINGS;
110
111 /*
112 * Machine definitions
113 */
114
115typedef struct {
116 const char *name;
117 const char *name2;
118 struct module *owner;
119 void *(*dma_alloc)(unsigned int, int);
120 void (*dma_free)(void *, unsigned int);
121 int (*irqinit)(void);
122#ifdef MODULE
123 void (*irqcleanup)(void);
124#endif
125 void (*init)(void);
126 void (*silence)(void);
127 int (*setFormat)(int);
128 int (*setVolume)(int);
129 int (*setBass)(int);
130 int (*setTreble)(int);
131 int (*setGain)(int);
132 void (*play)(void);
133 void (*record)(void); /* optional */
134 void (*mixer_init)(void); /* optional */
135 int (*mixer_ioctl)(u_int, u_long); /* optional */
136 int (*write_sq_setup)(void); /* optional */
137 int (*read_sq_setup)(void); /* optional */
138 int (*sq_open)(mode_t); /* optional */
139 int (*state_info)(char *, size_t); /* optional */
140 void (*abort_read)(void); /* optional */
141 int min_dsp_speed;
142 int max_dsp_speed;
143 int version ;
144 int hardware_afmts ; /* OSS says we only return h'ware info */
145 /* when queried via SNDCTL_DSP_GETFMTS */
146 int capabilities ; /* low-level reply to SNDCTL_DSP_GETCAPS */
147 SETTINGS default_hard ; /* open() or init() should set something valid */
148 SETTINGS default_soft ; /* you can make it look like old OSS, if you want to */
149} MACHINE;
150
151 /*
152 * Low level stuff
153 */
154
155typedef struct {
156 ssize_t (*ct_ulaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
157 ssize_t (*ct_alaw)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
158 ssize_t (*ct_s8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
159 ssize_t (*ct_u8)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
160 ssize_t (*ct_s16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
161 ssize_t (*ct_u16be)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
162 ssize_t (*ct_s16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
163 ssize_t (*ct_u16le)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
164} TRANS;
165
166struct sound_settings {
167 MACHINE mach; /* machine dependent things */
168 SETTINGS hard; /* hardware settings */
169 SETTINGS soft; /* software settings */
170 SETTINGS dsp; /* /dev/dsp default settings */
171 TRANS *trans_write; /* supported translations */
172#ifdef HAS_RECORD
173 TRANS *trans_read; /* supported translations */
174#endif
175 int volume_left; /* volume (range is machine dependent) */
176 int volume_right;
177 int bass; /* tone (range is machine dependent) */
178 int treble;
179 int gain;
180 int minDev; /* minor device number currently open */
181 spinlock_t lock;
182};
183
184extern struct sound_settings dmasound;
185
186#ifdef HAS_8BIT_TABLES
187extern char dmasound_ulaw2dma8[];
188extern char dmasound_alaw2dma8[];
189#endif
190
191 /*
192 * Mid level stuff
193 */
194
195static inline int dmasound_set_volume(int volume)
196{
197 return dmasound.mach.setVolume(volume);
198}
199
200static inline int dmasound_set_bass(int bass)
201{
202 return dmasound.mach.setBass ? dmasound.mach.setBass(bass) : 50;
203}
204
205static inline int dmasound_set_treble(int treble)
206{
207 return dmasound.mach.setTreble ? dmasound.mach.setTreble(treble) : 50;
208}
209
210static inline int dmasound_set_gain(int gain)
211{
212 return dmasound.mach.setGain ? dmasound.mach.setGain(gain) : 100;
213}
214
215
216 /*
217 * Sound queue stuff, the heart of the driver
218 */
219
220struct sound_queue {
221 /* buffers allocated for this queue */
222 int numBufs; /* real limits on what the user can have */
223 int bufSize; /* in bytes */
224 char **buffers;
225
226 /* current parameters */
227 int locked ; /* params cannot be modified when != 0 */
228 int user_frags ; /* user requests this many */
229 int user_frag_size ; /* of this size */
230 int max_count; /* actual # fragments <= numBufs */
231 int block_size; /* internal block size in bytes */
232 int max_active; /* in-use fragments <= max_count */
233
234 /* it shouldn't be necessary to declare any of these volatile */
235 int front, rear, count;
236 int rear_size;
237 /*
238 * The use of the playing field depends on the hardware
239 *
240 * Atari, PMac: The number of frames that are loaded/playing
241 *
242 * Amiga: Bit 0 is set: a frame is loaded
243 * Bit 1 is set: a frame is playing
244 */
245 int active;
246 wait_queue_head_t action_queue, open_queue, sync_queue;
247 int open_mode;
248 int busy, syncing, xruns, died;
249};
250
251#define SLEEP(queue) interruptible_sleep_on_timeout(&queue, HZ)
252#define WAKE_UP(queue) (wake_up_interruptible(&queue))
253
254extern struct sound_queue dmasound_write_sq;
255#define write_sq dmasound_write_sq
256
257#ifdef HAS_RECORD
258extern struct sound_queue dmasound_read_sq;
259#define read_sq dmasound_read_sq
260#endif
261
262extern int dmasound_catchRadius;
263#define catchRadius dmasound_catchRadius
264
265/* define the value to be put in the byte-swap reg in mac-io
266 when we want it to swap for us.
267*/
268#define BS_VAL 1
269
270#define SW_INPUT_VOLUME_SCALE 4
271#define SW_INPUT_VOLUME_DEFAULT (128 / SW_INPUT_VOLUME_SCALE)
272
273extern int expand_bal; /* Balance factor for expanding (not volume!) */
274extern int expand_read_bal; /* Balance factor for reading */
275extern uint software_input_volume; /* software implemented recording volume! */
276
277#endif /* _dmasound_h_ */
diff --git a/sound/oss/dmasound/dmasound_atari.c b/sound/oss/dmasound/dmasound_atari.c
new file mode 100644
index 000000000000..8daaf87664ba
--- /dev/null
+++ b/sound/oss/dmasound/dmasound_atari.c
@@ -0,0 +1,1600 @@
1/*
2 * linux/sound/oss/dmasound/dmasound_atari.c
3 *
4 * Atari TT and Falcon DMA Sound Driver
5 *
6 * See linux/sound/oss/dmasound/dmasound_core.c for copyright and credits
7 * prior to 28/01/2001
8 *
9 * 28/01/2001 [0.1] Iain Sandoe
10 * - added versioning
11 * - put in and populated the hardware_afmts field.
12 * [0.2] - put in SNDCTL_DSP_GETCAPS value.
13 * 01/02/2001 [0.3] - put in default hard/soft settings.
14 */
15
16
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/soundcard.h>
21#include <linux/mm.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h>
24
25#include <asm/uaccess.h>
26#include <asm/atariints.h>
27#include <asm/atari_stram.h>
28
29#include "dmasound.h"
30
31#define DMASOUND_ATARI_REVISION 0
32#define DMASOUND_ATARI_EDITION 3
33
34extern void atari_microwire_cmd(int cmd);
35
36static int is_falcon;
37static int write_sq_ignore_int; /* ++TeSche: used for Falcon */
38
39static int expand_bal; /* Balance factor for expanding (not volume!) */
40static int expand_data; /* Data for expanding */
41
42
43/*** Translations ************************************************************/
44
45
46/* ++TeSche: radically changed for new expanding purposes...
47 *
48 * These two routines now deal with copying/expanding/translating the samples
49 * from user space into our buffer at the right frequency. They take care about
50 * how much data there's actually to read, how much buffer space there is and
51 * to convert samples into the right frequency/encoding. They will only work on
52 * complete samples so it may happen they leave some bytes in the input stream
53 * if the user didn't write a multiple of the current sample size. They both
54 * return the number of bytes they've used from both streams so you may detect
55 * such a situation. Luckily all programs should be able to cope with that.
56 *
57 * I think I've optimized anything as far as one can do in plain C, all
58 * variables should fit in registers and the loops are really short. There's
59 * one loop for every possible situation. Writing a more generalized and thus
60 * parameterized loop would only produce slower code. Feel free to optimize
61 * this in assembler if you like. :)
62 *
63 * I think these routines belong here because they're not yet really hardware
64 * independent, especially the fact that the Falcon can play 16bit samples
65 * only in stereo is hardcoded in both of them!
66 *
67 * ++geert: split in even more functions (one per format)
68 */
69
70static ssize_t ata_ct_law(const u_char *userPtr, size_t userCount,
71 u_char frame[], ssize_t *frameUsed,
72 ssize_t frameLeft);
73static ssize_t ata_ct_s8(const u_char *userPtr, size_t userCount,
74 u_char frame[], ssize_t *frameUsed,
75 ssize_t frameLeft);
76static ssize_t ata_ct_u8(const u_char *userPtr, size_t userCount,
77 u_char frame[], ssize_t *frameUsed,
78 ssize_t frameLeft);
79static ssize_t ata_ct_s16be(const u_char *userPtr, size_t userCount,
80 u_char frame[], ssize_t *frameUsed,
81 ssize_t frameLeft);
82static ssize_t ata_ct_u16be(const u_char *userPtr, size_t userCount,
83 u_char frame[], ssize_t *frameUsed,
84 ssize_t frameLeft);
85static ssize_t ata_ct_s16le(const u_char *userPtr, size_t userCount,
86 u_char frame[], ssize_t *frameUsed,
87 ssize_t frameLeft);
88static ssize_t ata_ct_u16le(const u_char *userPtr, size_t userCount,
89 u_char frame[], ssize_t *frameUsed,
90 ssize_t frameLeft);
91static ssize_t ata_ctx_law(const u_char *userPtr, size_t userCount,
92 u_char frame[], ssize_t *frameUsed,
93 ssize_t frameLeft);
94static ssize_t ata_ctx_s8(const u_char *userPtr, size_t userCount,
95 u_char frame[], ssize_t *frameUsed,
96 ssize_t frameLeft);
97static ssize_t ata_ctx_u8(const u_char *userPtr, size_t userCount,
98 u_char frame[], ssize_t *frameUsed,
99 ssize_t frameLeft);
100static ssize_t ata_ctx_s16be(const u_char *userPtr, size_t userCount,
101 u_char frame[], ssize_t *frameUsed,
102 ssize_t frameLeft);
103static ssize_t ata_ctx_u16be(const u_char *userPtr, size_t userCount,
104 u_char frame[], ssize_t *frameUsed,
105 ssize_t frameLeft);
106static ssize_t ata_ctx_s16le(const u_char *userPtr, size_t userCount,
107 u_char frame[], ssize_t *frameUsed,
108 ssize_t frameLeft);
109static ssize_t ata_ctx_u16le(const u_char *userPtr, size_t userCount,
110 u_char frame[], ssize_t *frameUsed,
111 ssize_t frameLeft);
112
113
114/*** Low level stuff *********************************************************/
115
116
117static void *AtaAlloc(unsigned int size, int flags);
118static void AtaFree(void *, unsigned int size);
119static int AtaIrqInit(void);
120#ifdef MODULE
121static void AtaIrqCleanUp(void);
122#endif /* MODULE */
123static int AtaSetBass(int bass);
124static int AtaSetTreble(int treble);
125static void TTSilence(void);
126static void TTInit(void);
127static int TTSetFormat(int format);
128static int TTSetVolume(int volume);
129static int TTSetGain(int gain);
130static void FalconSilence(void);
131static void FalconInit(void);
132static int FalconSetFormat(int format);
133static int FalconSetVolume(int volume);
134static void AtaPlayNextFrame(int index);
135static void AtaPlay(void);
136static irqreturn_t AtaInterrupt(int irq, void *dummy, struct pt_regs *fp);
137
138/*** Mid level stuff *********************************************************/
139
140static void TTMixerInit(void);
141static void FalconMixerInit(void);
142static int AtaMixerIoctl(u_int cmd, u_long arg);
143static int TTMixerIoctl(u_int cmd, u_long arg);
144static int FalconMixerIoctl(u_int cmd, u_long arg);
145static int AtaWriteSqSetup(void);
146static int AtaSqOpen(mode_t mode);
147static int TTStateInfo(char *buffer, size_t space);
148static int FalconStateInfo(char *buffer, size_t space);
149
150
151/*** Translations ************************************************************/
152
153
154static ssize_t ata_ct_law(const u_char *userPtr, size_t userCount,
155 u_char frame[], ssize_t *frameUsed,
156 ssize_t frameLeft)
157{
158 char *table = dmasound.soft.format == AFMT_MU_LAW ? dmasound_ulaw2dma8
159 : dmasound_alaw2dma8;
160 ssize_t count, used;
161 u_char *p = &frame[*frameUsed];
162
163 count = min_t(unsigned long, userCount, frameLeft);
164 if (dmasound.soft.stereo)
165 count &= ~1;
166 used = count;
167 while (count > 0) {
168 u_char data;
169 if (get_user(data, userPtr++))
170 return -EFAULT;
171 *p++ = table[data];
172 count--;
173 }
174 *frameUsed += used;
175 return used;
176}
177
178
179static ssize_t ata_ct_s8(const u_char *userPtr, size_t userCount,
180 u_char frame[], ssize_t *frameUsed,
181 ssize_t frameLeft)
182{
183 ssize_t count, used;
184 void *p = &frame[*frameUsed];
185
186 count = min_t(unsigned long, userCount, frameLeft);
187 if (dmasound.soft.stereo)
188 count &= ~1;
189 used = count;
190 if (copy_from_user(p, userPtr, count))
191 return -EFAULT;
192 *frameUsed += used;
193 return used;
194}
195
196
197static ssize_t ata_ct_u8(const u_char *userPtr, size_t userCount,
198 u_char frame[], ssize_t *frameUsed,
199 ssize_t frameLeft)
200{
201 ssize_t count, used;
202
203 if (!dmasound.soft.stereo) {
204 u_char *p = &frame[*frameUsed];
205 count = min_t(unsigned long, userCount, frameLeft);
206 used = count;
207 while (count > 0) {
208 u_char data;
209 if (get_user(data, userPtr++))
210 return -EFAULT;
211 *p++ = data ^ 0x80;
212 count--;
213 }
214 } else {
215 u_short *p = (u_short *)&frame[*frameUsed];
216 count = min_t(unsigned long, userCount, frameLeft)>>1;
217 used = count*2;
218 while (count > 0) {
219 u_short data;
220 if (get_user(data, ((u_short *)userPtr)++))
221 return -EFAULT;
222 *p++ = data ^ 0x8080;
223 count--;
224 }
225 }
226 *frameUsed += used;
227 return used;
228}
229
230
231static ssize_t ata_ct_s16be(const u_char *userPtr, size_t userCount,
232 u_char frame[], ssize_t *frameUsed,
233 ssize_t frameLeft)
234{
235 ssize_t count, used;
236
237 if (!dmasound.soft.stereo) {
238 u_short *p = (u_short *)&frame[*frameUsed];
239 count = min_t(unsigned long, userCount, frameLeft)>>1;
240 used = count*2;
241 while (count > 0) {
242 u_short data;
243 if (get_user(data, ((u_short *)userPtr)++))
244 return -EFAULT;
245 *p++ = data;
246 *p++ = data;
247 count--;
248 }
249 *frameUsed += used*2;
250 } else {
251 void *p = (u_short *)&frame[*frameUsed];
252 count = min_t(unsigned long, userCount, frameLeft) & ~3;
253 used = count;
254 if (copy_from_user(p, userPtr, count))
255 return -EFAULT;
256 *frameUsed += used;
257 }
258 return used;
259}
260
261
262static ssize_t ata_ct_u16be(const u_char *userPtr, size_t userCount,
263 u_char frame[], ssize_t *frameUsed,
264 ssize_t frameLeft)
265{
266 ssize_t count, used;
267
268 if (!dmasound.soft.stereo) {
269 u_short *p = (u_short *)&frame[*frameUsed];
270 count = min_t(unsigned long, userCount, frameLeft)>>1;
271 used = count*2;
272 while (count > 0) {
273 u_short data;
274 if (get_user(data, ((u_short *)userPtr)++))
275 return -EFAULT;
276 data ^= 0x8000;
277 *p++ = data;
278 *p++ = data;
279 count--;
280 }
281 *frameUsed += used*2;
282 } else {
283 u_long *p = (u_long *)&frame[*frameUsed];
284 count = min_t(unsigned long, userCount, frameLeft)>>2;
285 used = count*4;
286 while (count > 0) {
287 u_long data;
288 if (get_user(data, ((u_int *)userPtr)++))
289 return -EFAULT;
290 *p++ = data ^ 0x80008000;
291 count--;
292 }
293 *frameUsed += used;
294 }
295 return used;
296}
297
298
299static ssize_t ata_ct_s16le(const u_char *userPtr, size_t userCount,
300 u_char frame[], ssize_t *frameUsed,
301 ssize_t frameLeft)
302{
303 ssize_t count, used;
304
305 count = frameLeft;
306 if (!dmasound.soft.stereo) {
307 u_short *p = (u_short *)&frame[*frameUsed];
308 count = min_t(unsigned long, userCount, frameLeft)>>1;
309 used = count*2;
310 while (count > 0) {
311 u_short data;
312 if (get_user(data, ((u_short *)userPtr)++))
313 return -EFAULT;
314 data = le2be16(data);
315 *p++ = data;
316 *p++ = data;
317 count--;
318 }
319 *frameUsed += used*2;
320 } else {
321 u_long *p = (u_long *)&frame[*frameUsed];
322 count = min_t(unsigned long, userCount, frameLeft)>>2;
323 used = count*4;
324 while (count > 0) {
325 u_long data;
326 if (get_user(data, ((u_int *)userPtr)++))
327 return -EFAULT;
328 data = le2be16dbl(data);
329 *p++ = data;
330 count--;
331 }
332 *frameUsed += used;
333 }
334 return used;
335}
336
337
338static ssize_t ata_ct_u16le(const u_char *userPtr, size_t userCount,
339 u_char frame[], ssize_t *frameUsed,
340 ssize_t frameLeft)
341{
342 ssize_t count, used;
343
344 count = frameLeft;
345 if (!dmasound.soft.stereo) {
346 u_short *p = (u_short *)&frame[*frameUsed];
347 count = min_t(unsigned long, userCount, frameLeft)>>1;
348 used = count*2;
349 while (count > 0) {
350 u_short data;
351 if (get_user(data, ((u_short *)userPtr)++))
352 return -EFAULT;
353 data = le2be16(data) ^ 0x8000;
354 *p++ = data;
355 *p++ = data;
356 }
357 *frameUsed += used*2;
358 } else {
359 u_long *p = (u_long *)&frame[*frameUsed];
360 count = min_t(unsigned long, userCount, frameLeft)>>2;
361 used = count;
362 while (count > 0) {
363 u_long data;
364 if (get_user(data, ((u_int *)userPtr)++))
365 return -EFAULT;
366 data = le2be16dbl(data) ^ 0x80008000;
367 *p++ = data;
368 count--;
369 }
370 *frameUsed += used;
371 }
372 return used;
373}
374
375
376static ssize_t ata_ctx_law(const u_char *userPtr, size_t userCount,
377 u_char frame[], ssize_t *frameUsed,
378 ssize_t frameLeft)
379{
380 char *table = dmasound.soft.format == AFMT_MU_LAW ? dmasound_ulaw2dma8
381 : dmasound_alaw2dma8;
382 /* this should help gcc to stuff everything into registers */
383 long bal = expand_bal;
384 long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
385 ssize_t used, usedf;
386
387 used = userCount;
388 usedf = frameLeft;
389 if (!dmasound.soft.stereo) {
390 u_char *p = &frame[*frameUsed];
391 u_char data = expand_data;
392 while (frameLeft) {
393 u_char c;
394 if (bal < 0) {
395 if (!userCount)
396 break;
397 if (get_user(c, userPtr++))
398 return -EFAULT;
399 data = table[c];
400 userCount--;
401 bal += hSpeed;
402 }
403 *p++ = data;
404 frameLeft--;
405 bal -= sSpeed;
406 }
407 expand_data = data;
408 } else {
409 u_short *p = (u_short *)&frame[*frameUsed];
410 u_short data = expand_data;
411 while (frameLeft >= 2) {
412 u_char c;
413 if (bal < 0) {
414 if (userCount < 2)
415 break;
416 if (get_user(c, userPtr++))
417 return -EFAULT;
418 data = table[c] << 8;
419 if (get_user(c, userPtr++))
420 return -EFAULT;
421 data |= table[c];
422 userCount -= 2;
423 bal += hSpeed;
424 }
425 *p++ = data;
426 frameLeft -= 2;
427 bal -= sSpeed;
428 }
429 expand_data = data;
430 }
431 expand_bal = bal;
432 used -= userCount;
433 *frameUsed += usedf-frameLeft;
434 return used;
435}
436
437
438static ssize_t ata_ctx_s8(const u_char *userPtr, size_t userCount,
439 u_char frame[], ssize_t *frameUsed,
440 ssize_t frameLeft)
441{
442 /* this should help gcc to stuff everything into registers */
443 long bal = expand_bal;
444 long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
445 ssize_t used, usedf;
446
447 used = userCount;
448 usedf = frameLeft;
449 if (!dmasound.soft.stereo) {
450 u_char *p = &frame[*frameUsed];
451 u_char data = expand_data;
452 while (frameLeft) {
453 if (bal < 0) {
454 if (!userCount)
455 break;
456 if (get_user(data, userPtr++))
457 return -EFAULT;
458 userCount--;
459 bal += hSpeed;
460 }
461 *p++ = data;
462 frameLeft--;
463 bal -= sSpeed;
464 }
465 expand_data = data;
466 } else {
467 u_short *p = (u_short *)&frame[*frameUsed];
468 u_short data = expand_data;
469 while (frameLeft >= 2) {
470 if (bal < 0) {
471 if (userCount < 2)
472 break;
473 if (get_user(data, ((u_short *)userPtr)++))
474 return -EFAULT;
475 userCount -= 2;
476 bal += hSpeed;
477 }
478 *p++ = data;
479 frameLeft -= 2;
480 bal -= sSpeed;
481 }
482 expand_data = data;
483 }
484 expand_bal = bal;
485 used -= userCount;
486 *frameUsed += usedf-frameLeft;
487 return used;
488}
489
490
491static ssize_t ata_ctx_u8(const u_char *userPtr, size_t userCount,
492 u_char frame[], ssize_t *frameUsed,
493 ssize_t frameLeft)
494{
495 /* this should help gcc to stuff everything into registers */
496 long bal = expand_bal;
497 long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
498 ssize_t used, usedf;
499
500 used = userCount;
501 usedf = frameLeft;
502 if (!dmasound.soft.stereo) {
503 u_char *p = &frame[*frameUsed];
504 u_char data = expand_data;
505 while (frameLeft) {
506 if (bal < 0) {
507 if (!userCount)
508 break;
509 if (get_user(data, userPtr++))
510 return -EFAULT;
511 data ^= 0x80;
512 userCount--;
513 bal += hSpeed;
514 }
515 *p++ = data;
516 frameLeft--;
517 bal -= sSpeed;
518 }
519 expand_data = data;
520 } else {
521 u_short *p = (u_short *)&frame[*frameUsed];
522 u_short data = expand_data;
523 while (frameLeft >= 2) {
524 if (bal < 0) {
525 if (userCount < 2)
526 break;
527 if (get_user(data, ((u_short *)userPtr)++))
528 return -EFAULT;
529 data ^= 0x8080;
530 userCount -= 2;
531 bal += hSpeed;
532 }
533 *p++ = data;
534 frameLeft -= 2;
535 bal -= sSpeed;
536 }
537 expand_data = data;
538 }
539 expand_bal = bal;
540 used -= userCount;
541 *frameUsed += usedf-frameLeft;
542 return used;
543}
544
545
546static ssize_t ata_ctx_s16be(const u_char *userPtr, size_t userCount,
547 u_char frame[], ssize_t *frameUsed,
548 ssize_t frameLeft)
549{
550 /* this should help gcc to stuff everything into registers */
551 long bal = expand_bal;
552 long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
553 ssize_t used, usedf;
554
555 used = userCount;
556 usedf = frameLeft;
557 if (!dmasound.soft.stereo) {
558 u_short *p = (u_short *)&frame[*frameUsed];
559 u_short data = expand_data;
560 while (frameLeft >= 4) {
561 if (bal < 0) {
562 if (userCount < 2)
563 break;
564 if (get_user(data, ((u_short *)userPtr)++))
565 return -EFAULT;
566 userCount -= 2;
567 bal += hSpeed;
568 }
569 *p++ = data;
570 *p++ = data;
571 frameLeft -= 4;
572 bal -= sSpeed;
573 }
574 expand_data = data;
575 } else {
576 u_long *p = (u_long *)&frame[*frameUsed];
577 u_long data = expand_data;
578 while (frameLeft >= 4) {
579 if (bal < 0) {
580 if (userCount < 4)
581 break;
582 if (get_user(data, ((u_int *)userPtr)++))
583 return -EFAULT;
584 userCount -= 4;
585 bal += hSpeed;
586 }
587 *p++ = data;
588 frameLeft -= 4;
589 bal -= sSpeed;
590 }
591 expand_data = data;
592 }
593 expand_bal = bal;
594 used -= userCount;
595 *frameUsed += usedf-frameLeft;
596 return used;
597}
598
599
600static ssize_t ata_ctx_u16be(const u_char *userPtr, size_t userCount,
601 u_char frame[], ssize_t *frameUsed,
602 ssize_t frameLeft)
603{
604 /* this should help gcc to stuff everything into registers */
605 long bal = expand_bal;
606 long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
607 ssize_t used, usedf;
608
609 used = userCount;
610 usedf = frameLeft;
611 if (!dmasound.soft.stereo) {
612 u_short *p = (u_short *)&frame[*frameUsed];
613 u_short data = expand_data;
614 while (frameLeft >= 4) {
615 if (bal < 0) {
616 if (userCount < 2)
617 break;
618 if (get_user(data, ((u_short *)userPtr)++))
619 return -EFAULT;
620 data ^= 0x8000;
621 userCount -= 2;
622 bal += hSpeed;
623 }
624 *p++ = data;
625 *p++ = data;
626 frameLeft -= 4;
627 bal -= sSpeed;
628 }
629 expand_data = data;
630 } else {
631 u_long *p = (u_long *)&frame[*frameUsed];
632 u_long data = expand_data;
633 while (frameLeft >= 4) {
634 if (bal < 0) {
635 if (userCount < 4)
636 break;
637 if (get_user(data, ((u_int *)userPtr)++))
638 return -EFAULT;
639 data ^= 0x80008000;
640 userCount -= 4;
641 bal += hSpeed;
642 }
643 *p++ = data;
644 frameLeft -= 4;
645 bal -= sSpeed;
646 }
647 expand_data = data;
648 }
649 expand_bal = bal;
650 used -= userCount;
651 *frameUsed += usedf-frameLeft;
652 return used;
653}
654
655
656static ssize_t ata_ctx_s16le(const u_char *userPtr, size_t userCount,
657 u_char frame[], ssize_t *frameUsed,
658 ssize_t frameLeft)
659{
660 /* this should help gcc to stuff everything into registers */
661 long bal = expand_bal;
662 long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
663 ssize_t used, usedf;
664
665 used = userCount;
666 usedf = frameLeft;
667 if (!dmasound.soft.stereo) {
668 u_short *p = (u_short *)&frame[*frameUsed];
669 u_short data = expand_data;
670 while (frameLeft >= 4) {
671 if (bal < 0) {
672 if (userCount < 2)
673 break;
674 if (get_user(data, ((u_short *)userPtr)++))
675 return -EFAULT;
676 data = le2be16(data);
677 userCount -= 2;
678 bal += hSpeed;
679 }
680 *p++ = data;
681 *p++ = data;
682 frameLeft -= 4;
683 bal -= sSpeed;
684 }
685 expand_data = data;
686 } else {
687 u_long *p = (u_long *)&frame[*frameUsed];
688 u_long data = expand_data;
689 while (frameLeft >= 4) {
690 if (bal < 0) {
691 if (userCount < 4)
692 break;
693 if (get_user(data, ((u_int *)userPtr)++))
694 return -EFAULT;
695 data = le2be16dbl(data);
696 userCount -= 4;
697 bal += hSpeed;
698 }
699 *p++ = data;
700 frameLeft -= 4;
701 bal -= sSpeed;
702 }
703 expand_data = data;
704 }
705 expand_bal = bal;
706 used -= userCount;
707 *frameUsed += usedf-frameLeft;
708 return used;
709}
710
711
712static ssize_t ata_ctx_u16le(const u_char *userPtr, size_t userCount,
713 u_char frame[], ssize_t *frameUsed,
714 ssize_t frameLeft)
715{
716 /* this should help gcc to stuff everything into registers */
717 long bal = expand_bal;
718 long hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
719 ssize_t used, usedf;
720
721 used = userCount;
722 usedf = frameLeft;
723 if (!dmasound.soft.stereo) {
724 u_short *p = (u_short *)&frame[*frameUsed];
725 u_short data = expand_data;
726 while (frameLeft >= 4) {
727 if (bal < 0) {
728 if (userCount < 2)
729 break;
730 if (get_user(data, ((u_short *)userPtr)++))
731 return -EFAULT;
732 data = le2be16(data) ^ 0x8000;
733 userCount -= 2;
734 bal += hSpeed;
735 }
736 *p++ = data;
737 *p++ = data;
738 frameLeft -= 4;
739 bal -= sSpeed;
740 }
741 expand_data = data;
742 } else {
743 u_long *p = (u_long *)&frame[*frameUsed];
744 u_long data = expand_data;
745 while (frameLeft >= 4) {
746 if (bal < 0) {
747 if (userCount < 4)
748 break;
749 if (get_user(data, ((u_int *)userPtr)++))
750 return -EFAULT;
751 data = le2be16dbl(data) ^ 0x80008000;
752 userCount -= 4;
753 bal += hSpeed;
754 }
755 *p++ = data;
756 frameLeft -= 4;
757 bal -= sSpeed;
758 }
759 expand_data = data;
760 }
761 expand_bal = bal;
762 used -= userCount;
763 *frameUsed += usedf-frameLeft;
764 return used;
765}
766
767
768static TRANS transTTNormal = {
769 .ct_ulaw = ata_ct_law,
770 .ct_alaw = ata_ct_law,
771 .ct_s8 = ata_ct_s8,
772 .ct_u8 = ata_ct_u8,
773};
774
775static TRANS transTTExpanding = {
776 .ct_ulaw = ata_ctx_law,
777 .ct_alaw = ata_ctx_law,
778 .ct_s8 = ata_ctx_s8,
779 .ct_u8 = ata_ctx_u8,
780};
781
782static TRANS transFalconNormal = {
783 .ct_ulaw = ata_ct_law,
784 .ct_alaw = ata_ct_law,
785 .ct_s8 = ata_ct_s8,
786 .ct_u8 = ata_ct_u8,
787 .ct_s16be = ata_ct_s16be,
788 .ct_u16be = ata_ct_u16be,
789 .ct_s16le = ata_ct_s16le,
790 .ct_u16le = ata_ct_u16le
791};
792
793static TRANS transFalconExpanding = {
794 .ct_ulaw = ata_ctx_law,
795 .ct_alaw = ata_ctx_law,
796 .ct_s8 = ata_ctx_s8,
797 .ct_u8 = ata_ctx_u8,
798 .ct_s16be = ata_ctx_s16be,
799 .ct_u16be = ata_ctx_u16be,
800 .ct_s16le = ata_ctx_s16le,
801 .ct_u16le = ata_ctx_u16le,
802};
803
804
805/*** Low level stuff *********************************************************/
806
807
808
809/*
810 * Atari (TT/Falcon)
811 */
812
813static void *AtaAlloc(unsigned int size, int flags)
814{
815 return atari_stram_alloc(size, "dmasound");
816}
817
818static void AtaFree(void *obj, unsigned int size)
819{
820 atari_stram_free( obj );
821}
822
823static int __init AtaIrqInit(void)
824{
825 /* Set up timer A. Timer A
826 will receive a signal upon end of playing from the sound
827 hardware. Furthermore Timer A is able to count events
828 and will cause an interrupt after a programmed number
829 of events. So all we need to keep the music playing is
830 to provide the sound hardware with new data upon
831 an interrupt from timer A. */
832 mfp.tim_ct_a = 0; /* ++roman: Stop timer before programming! */
833 mfp.tim_dt_a = 1; /* Cause interrupt after first event. */
834 mfp.tim_ct_a = 8; /* Turn on event counting. */
835 /* Register interrupt handler. */
836 request_irq(IRQ_MFP_TIMA, AtaInterrupt, IRQ_TYPE_SLOW, "DMA sound",
837 AtaInterrupt);
838 mfp.int_en_a |= 0x20; /* Turn interrupt on. */
839 mfp.int_mk_a |= 0x20;
840 return 1;
841}
842
843#ifdef MODULE
844static void AtaIrqCleanUp(void)
845{
846 mfp.tim_ct_a = 0; /* stop timer */
847 mfp.int_en_a &= ~0x20; /* turn interrupt off */
848 free_irq(IRQ_MFP_TIMA, AtaInterrupt);
849}
850#endif /* MODULE */
851
852
853#define TONE_VOXWARE_TO_DB(v) \
854 (((v) < 0) ? -12 : ((v) > 100) ? 12 : ((v) - 50) * 6 / 25)
855#define TONE_DB_TO_VOXWARE(v) (((v) * 25 + ((v) > 0 ? 5 : -5)) / 6 + 50)
856
857
858static int AtaSetBass(int bass)
859{
860 dmasound.bass = TONE_VOXWARE_TO_DB(bass);
861 atari_microwire_cmd(MW_LM1992_BASS(dmasound.bass));
862 return TONE_DB_TO_VOXWARE(dmasound.bass);
863}
864
865
866static int AtaSetTreble(int treble)
867{
868 dmasound.treble = TONE_VOXWARE_TO_DB(treble);
869 atari_microwire_cmd(MW_LM1992_TREBLE(dmasound.treble));
870 return TONE_DB_TO_VOXWARE(dmasound.treble);
871}
872
873
874
875/*
876 * TT
877 */
878
879
880static void TTSilence(void)
881{
882 tt_dmasnd.ctrl = DMASND_CTRL_OFF;
883 atari_microwire_cmd(MW_LM1992_PSG_HIGH); /* mix in PSG signal 1:1 */
884}
885
886
887static void TTInit(void)
888{
889 int mode, i, idx;
890 const int freq[4] = {50066, 25033, 12517, 6258};
891
892 /* search a frequency that fits into the allowed error range */
893
894 idx = -1;
895 for (i = 0; i < ARRAY_SIZE(freq); i++)
896 /* this isn't as much useful for a TT than for a Falcon, but
897 * then it doesn't hurt very much to implement it for a TT too.
898 */
899 if ((100 * abs(dmasound.soft.speed - freq[i]) / freq[i]) < catchRadius)
900 idx = i;
901 if (idx > -1) {
902 dmasound.soft.speed = freq[idx];
903 dmasound.trans_write = &transTTNormal;
904 } else
905 dmasound.trans_write = &transTTExpanding;
906
907 TTSilence();
908 dmasound.hard = dmasound.soft;
909
910 if (dmasound.hard.speed > 50066) {
911 /* we would need to squeeze the sound, but we won't do that */
912 dmasound.hard.speed = 50066;
913 mode = DMASND_MODE_50KHZ;
914 dmasound.trans_write = &transTTNormal;
915 } else if (dmasound.hard.speed > 25033) {
916 dmasound.hard.speed = 50066;
917 mode = DMASND_MODE_50KHZ;
918 } else if (dmasound.hard.speed > 12517) {
919 dmasound.hard.speed = 25033;
920 mode = DMASND_MODE_25KHZ;
921 } else if (dmasound.hard.speed > 6258) {
922 dmasound.hard.speed = 12517;
923 mode = DMASND_MODE_12KHZ;
924 } else {
925 dmasound.hard.speed = 6258;
926 mode = DMASND_MODE_6KHZ;
927 }
928
929 tt_dmasnd.mode = (dmasound.hard.stereo ?
930 DMASND_MODE_STEREO : DMASND_MODE_MONO) |
931 DMASND_MODE_8BIT | mode;
932
933 expand_bal = -dmasound.soft.speed;
934}
935
936
937static int TTSetFormat(int format)
938{
939 /* TT sound DMA supports only 8bit modes */
940
941 switch (format) {
942 case AFMT_QUERY:
943 return dmasound.soft.format;
944 case AFMT_MU_LAW:
945 case AFMT_A_LAW:
946 case AFMT_S8:
947 case AFMT_U8:
948 break;
949 default:
950 format = AFMT_S8;
951 }
952
953 dmasound.soft.format = format;
954 dmasound.soft.size = 8;
955 if (dmasound.minDev == SND_DEV_DSP) {
956 dmasound.dsp.format = format;
957 dmasound.dsp.size = 8;
958 }
959 TTInit();
960
961 return format;
962}
963
964
965#define VOLUME_VOXWARE_TO_DB(v) \
966 (((v) < 0) ? -40 : ((v) > 100) ? 0 : ((v) * 2) / 5 - 40)
967#define VOLUME_DB_TO_VOXWARE(v) ((((v) + 40) * 5 + 1) / 2)
968
969
970static int TTSetVolume(int volume)
971{
972 dmasound.volume_left = VOLUME_VOXWARE_TO_DB(volume & 0xff);
973 atari_microwire_cmd(MW_LM1992_BALLEFT(dmasound.volume_left));
974 dmasound.volume_right = VOLUME_VOXWARE_TO_DB((volume & 0xff00) >> 8);
975 atari_microwire_cmd(MW_LM1992_BALRIGHT(dmasound.volume_right));
976 return VOLUME_DB_TO_VOXWARE(dmasound.volume_left) |
977 (VOLUME_DB_TO_VOXWARE(dmasound.volume_right) << 8);
978}
979
980
981#define GAIN_VOXWARE_TO_DB(v) \
982 (((v) < 0) ? -80 : ((v) > 100) ? 0 : ((v) * 4) / 5 - 80)
983#define GAIN_DB_TO_VOXWARE(v) ((((v) + 80) * 5 + 1) / 4)
984
985static int TTSetGain(int gain)
986{
987 dmasound.gain = GAIN_VOXWARE_TO_DB(gain);
988 atari_microwire_cmd(MW_LM1992_VOLUME(dmasound.gain));
989 return GAIN_DB_TO_VOXWARE(dmasound.gain);
990}
991
992
993
994/*
995 * Falcon
996 */
997
998
999static void FalconSilence(void)
1000{
1001 /* stop playback, set sample rate 50kHz for PSG sound */
1002 tt_dmasnd.ctrl = DMASND_CTRL_OFF;
1003 tt_dmasnd.mode = DMASND_MODE_50KHZ | DMASND_MODE_STEREO | DMASND_MODE_8BIT;
1004 tt_dmasnd.int_div = 0; /* STE compatible divider */
1005 tt_dmasnd.int_ctrl = 0x0;
1006 tt_dmasnd.cbar_src = 0x0000; /* no matrix inputs */
1007 tt_dmasnd.cbar_dst = 0x0000; /* no matrix outputs */
1008 tt_dmasnd.dac_src = 1; /* connect ADC to DAC, disconnect matrix */
1009 tt_dmasnd.adc_src = 3; /* ADC Input = PSG */
1010}
1011
1012
1013static void FalconInit(void)
1014{
1015 int divider, i, idx;
1016 const int freq[8] = {49170, 32780, 24585, 19668, 16390, 12292, 9834, 8195};
1017
1018 /* search a frequency that fits into the allowed error range */
1019
1020 idx = -1;
1021 for (i = 0; i < ARRAY_SIZE(freq); i++)
1022 /* if we will tolerate 3% error 8000Hz->8195Hz (2.38%) would
1023 * be playable without expanding, but that now a kernel runtime
1024 * option
1025 */
1026 if ((100 * abs(dmasound.soft.speed - freq[i]) / freq[i]) < catchRadius)
1027 idx = i;
1028 if (idx > -1) {
1029 dmasound.soft.speed = freq[idx];
1030 dmasound.trans_write = &transFalconNormal;
1031 } else
1032 dmasound.trans_write = &transFalconExpanding;
1033
1034 FalconSilence();
1035 dmasound.hard = dmasound.soft;
1036
1037 if (dmasound.hard.size == 16) {
1038 /* the Falcon can play 16bit samples only in stereo */
1039 dmasound.hard.stereo = 1;
1040 }
1041
1042 if (dmasound.hard.speed > 49170) {
1043 /* we would need to squeeze the sound, but we won't do that */
1044 dmasound.hard.speed = 49170;
1045 divider = 1;
1046 dmasound.trans_write = &transFalconNormal;
1047 } else if (dmasound.hard.speed > 32780) {
1048 dmasound.hard.speed = 49170;
1049 divider = 1;
1050 } else if (dmasound.hard.speed > 24585) {
1051 dmasound.hard.speed = 32780;
1052 divider = 2;
1053 } else if (dmasound.hard.speed > 19668) {
1054 dmasound.hard.speed = 24585;
1055 divider = 3;
1056 } else if (dmasound.hard.speed > 16390) {
1057 dmasound.hard.speed = 19668;
1058 divider = 4;
1059 } else if (dmasound.hard.speed > 12292) {
1060 dmasound.hard.speed = 16390;
1061 divider = 5;
1062 } else if (dmasound.hard.speed > 9834) {
1063 dmasound.hard.speed = 12292;
1064 divider = 7;
1065 } else if (dmasound.hard.speed > 8195) {
1066 dmasound.hard.speed = 9834;
1067 divider = 9;
1068 } else {
1069 dmasound.hard.speed = 8195;
1070 divider = 11;
1071 }
1072 tt_dmasnd.int_div = divider;
1073
1074 /* Setup Falcon sound DMA for playback */
1075 tt_dmasnd.int_ctrl = 0x4; /* Timer A int at play end */
1076 tt_dmasnd.track_select = 0x0; /* play 1 track, track 1 */
1077 tt_dmasnd.cbar_src = 0x0001; /* DMA(25MHz) --> DAC */
1078 tt_dmasnd.cbar_dst = 0x0000;
1079 tt_dmasnd.rec_track_select = 0;
1080 tt_dmasnd.dac_src = 2; /* connect matrix to DAC */
1081 tt_dmasnd.adc_src = 0; /* ADC Input = Mic */
1082
1083 tt_dmasnd.mode = (dmasound.hard.stereo ?
1084 DMASND_MODE_STEREO : DMASND_MODE_MONO) |
1085 ((dmasound.hard.size == 8) ?
1086 DMASND_MODE_8BIT : DMASND_MODE_16BIT) |
1087 DMASND_MODE_6KHZ;
1088
1089 expand_bal = -dmasound.soft.speed;
1090}
1091
1092
1093static int FalconSetFormat(int format)
1094{
1095 int size;
1096 /* Falcon sound DMA supports 8bit and 16bit modes */
1097
1098 switch (format) {
1099 case AFMT_QUERY:
1100 return dmasound.soft.format;
1101 case AFMT_MU_LAW:
1102 case AFMT_A_LAW:
1103 case AFMT_U8:
1104 case AFMT_S8:
1105 size = 8;
1106 break;
1107 case AFMT_S16_BE:
1108 case AFMT_U16_BE:
1109 case AFMT_S16_LE:
1110 case AFMT_U16_LE:
1111 size = 16;
1112 break;
1113 default: /* :-) */
1114 size = 8;
1115 format = AFMT_S8;
1116 }
1117
1118 dmasound.soft.format = format;
1119 dmasound.soft.size = size;
1120 if (dmasound.minDev == SND_DEV_DSP) {
1121 dmasound.dsp.format = format;
1122 dmasound.dsp.size = dmasound.soft.size;
1123 }
1124
1125 FalconInit();
1126
1127 return format;
1128}
1129
1130
1131/* This is for the Falcon output *attenuation* in 1.5dB steps,
1132 * i.e. output level from 0 to -22.5dB in -1.5dB steps.
1133 */
1134#define VOLUME_VOXWARE_TO_ATT(v) \
1135 ((v) < 0 ? 15 : (v) > 100 ? 0 : 15 - (v) * 3 / 20)
1136#define VOLUME_ATT_TO_VOXWARE(v) (100 - (v) * 20 / 3)
1137
1138
1139static int FalconSetVolume(int volume)
1140{
1141 dmasound.volume_left = VOLUME_VOXWARE_TO_ATT(volume & 0xff);
1142 dmasound.volume_right = VOLUME_VOXWARE_TO_ATT((volume & 0xff00) >> 8);
1143 tt_dmasnd.output_atten = dmasound.volume_left << 8 | dmasound.volume_right << 4;
1144 return VOLUME_ATT_TO_VOXWARE(dmasound.volume_left) |
1145 VOLUME_ATT_TO_VOXWARE(dmasound.volume_right) << 8;
1146}
1147
1148
1149static void AtaPlayNextFrame(int index)
1150{
1151 char *start, *end;
1152
1153 /* used by AtaPlay() if all doubts whether there really is something
1154 * to be played are already wiped out.
1155 */
1156 start = write_sq.buffers[write_sq.front];
1157 end = start+((write_sq.count == index) ? write_sq.rear_size
1158 : write_sq.block_size);
1159 /* end might not be a legal virtual address. */
1160 DMASNDSetEnd(virt_to_phys(end - 1) + 1);
1161 DMASNDSetBase(virt_to_phys(start));
1162 /* Since only an even number of samples per frame can
1163 be played, we might lose one byte here. (TO DO) */
1164 write_sq.front = (write_sq.front+1) % write_sq.max_count;
1165 write_sq.active++;
1166 tt_dmasnd.ctrl = DMASND_CTRL_ON | DMASND_CTRL_REPEAT;
1167}
1168
1169
1170static void AtaPlay(void)
1171{
1172 /* ++TeSche: Note that write_sq.active is no longer just a flag but
1173 * holds the number of frames the DMA is currently programmed for
1174 * instead, may be 0, 1 (currently being played) or 2 (pre-programmed).
1175 *
1176 * Changes done to write_sq.count and write_sq.active are a bit more
1177 * subtle again so now I must admit I also prefer disabling the irq
1178 * here rather than considering all possible situations. But the point
1179 * is that disabling the irq doesn't have any bad influence on this
1180 * version of the driver as we benefit from having pre-programmed the
1181 * DMA wherever possible: There's no need to reload the DMA at the
1182 * exact time of an interrupt but only at some time while the
1183 * pre-programmed frame is playing!
1184 */
1185 atari_disable_irq(IRQ_MFP_TIMA);
1186
1187 if (write_sq.active == 2 || /* DMA is 'full' */
1188 write_sq.count <= 0) { /* nothing to do */
1189 atari_enable_irq(IRQ_MFP_TIMA);
1190 return;
1191 }
1192
1193 if (write_sq.active == 0) {
1194 /* looks like there's nothing 'in' the DMA yet, so try
1195 * to put two frames into it (at least one is available).
1196 */
1197 if (write_sq.count == 1 &&
1198 write_sq.rear_size < write_sq.block_size &&
1199 !write_sq.syncing) {
1200 /* hmmm, the only existing frame is not
1201 * yet filled and we're not syncing?
1202 */
1203 atari_enable_irq(IRQ_MFP_TIMA);
1204 return;
1205 }
1206 AtaPlayNextFrame(1);
1207 if (write_sq.count == 1) {
1208 /* no more frames */
1209 atari_enable_irq(IRQ_MFP_TIMA);
1210 return;
1211 }
1212 if (write_sq.count == 2 &&
1213 write_sq.rear_size < write_sq.block_size &&
1214 !write_sq.syncing) {
1215 /* hmmm, there were two frames, but the second
1216 * one is not yet filled and we're not syncing?
1217 */
1218 atari_enable_irq(IRQ_MFP_TIMA);
1219 return;
1220 }
1221 AtaPlayNextFrame(2);
1222 } else {
1223 /* there's already a frame being played so we may only stuff
1224 * one new into the DMA, but even if this may be the last
1225 * frame existing the previous one is still on write_sq.count.
1226 */
1227 if (write_sq.count == 2 &&
1228 write_sq.rear_size < write_sq.block_size &&
1229 !write_sq.syncing) {
1230 /* hmmm, the only existing frame is not
1231 * yet filled and we're not syncing?
1232 */
1233 atari_enable_irq(IRQ_MFP_TIMA);
1234 return;
1235 }
1236 AtaPlayNextFrame(2);
1237 }
1238 atari_enable_irq(IRQ_MFP_TIMA);
1239}
1240
1241
1242static irqreturn_t AtaInterrupt(int irq, void *dummy, struct pt_regs *fp)
1243{
1244#if 0
1245 /* ++TeSche: if you should want to test this... */
1246 static int cnt;
1247 if (write_sq.active == 2)
1248 if (++cnt == 10) {
1249 /* simulate losing an interrupt */
1250 cnt = 0;
1251 return IRQ_HANDLED;
1252 }
1253#endif
1254 spin_lock(&dmasound.lock);
1255 if (write_sq_ignore_int && is_falcon) {
1256 /* ++TeSche: Falcon only: ignore first irq because it comes
1257 * immediately after starting a frame. after that, irqs come
1258 * (almost) like on the TT.
1259 */
1260 write_sq_ignore_int = 0;
1261 return IRQ_HANDLED;
1262 }
1263
1264 if (!write_sq.active) {
1265 /* playing was interrupted and sq_reset() has already cleared
1266 * the sq variables, so better don't do anything here.
1267 */
1268 WAKE_UP(write_sq.sync_queue);
1269 return IRQ_HANDLED;
1270 }
1271
1272 /* Probably ;) one frame is finished. Well, in fact it may be that a
1273 * pre-programmed one is also finished because there has been a long
1274 * delay in interrupt delivery and we've completely lost one, but
1275 * there's no way to detect such a situation. In such a case the last
1276 * frame will be played more than once and the situation will recover
1277 * as soon as the irq gets through.
1278 */
1279 write_sq.count--;
1280 write_sq.active--;
1281
1282 if (!write_sq.active) {
1283 tt_dmasnd.ctrl = DMASND_CTRL_OFF;
1284 write_sq_ignore_int = 1;
1285 }
1286
1287 WAKE_UP(write_sq.action_queue);
1288 /* At least one block of the queue is free now
1289 so wake up a writing process blocked because
1290 of a full queue. */
1291
1292 if ((write_sq.active != 1) || (write_sq.count != 1))
1293 /* We must be a bit carefully here: write_sq.count indicates the
1294 * number of buffers used and not the number of frames to be
1295 * played. If write_sq.count==1 and write_sq.active==1 that
1296 * means the only remaining frame was already programmed
1297 * earlier (and is currently running) so we mustn't call
1298 * AtaPlay() here, otherwise we'll play one frame too much.
1299 */
1300 AtaPlay();
1301
1302 if (!write_sq.active) WAKE_UP(write_sq.sync_queue);
1303 /* We are not playing after AtaPlay(), so there
1304 is nothing to play any more. Wake up a process
1305 waiting for audio output to drain. */
1306 spin_unlock(&dmasound.lock);
1307 return IRQ_HANDLED;
1308}
1309
1310
1311/*** Mid level stuff *********************************************************/
1312
1313
1314/*
1315 * /dev/mixer abstraction
1316 */
1317
1318#define RECLEVEL_VOXWARE_TO_GAIN(v) \
1319 ((v) < 0 ? 0 : (v) > 100 ? 15 : (v) * 3 / 20)
1320#define RECLEVEL_GAIN_TO_VOXWARE(v) (((v) * 20 + 2) / 3)
1321
1322
1323static void __init TTMixerInit(void)
1324{
1325 atari_microwire_cmd(MW_LM1992_VOLUME(0));
1326 dmasound.volume_left = 0;
1327 atari_microwire_cmd(MW_LM1992_BALLEFT(0));
1328 dmasound.volume_right = 0;
1329 atari_microwire_cmd(MW_LM1992_BALRIGHT(0));
1330 atari_microwire_cmd(MW_LM1992_TREBLE(0));
1331 atari_microwire_cmd(MW_LM1992_BASS(0));
1332}
1333
1334static void __init FalconMixerInit(void)
1335{
1336 dmasound.volume_left = (tt_dmasnd.output_atten & 0xf00) >> 8;
1337 dmasound.volume_right = (tt_dmasnd.output_atten & 0xf0) >> 4;
1338}
1339
1340static int AtaMixerIoctl(u_int cmd, u_long arg)
1341{
1342 int data;
1343 unsigned long flags;
1344 switch (cmd) {
1345 case SOUND_MIXER_READ_SPEAKER:
1346 if (is_falcon || MACH_IS_TT) {
1347 int porta;
1348 spin_lock_irqsave(&dmasound.lock, flags);
1349 sound_ym.rd_data_reg_sel = 14;
1350 porta = sound_ym.rd_data_reg_sel;
1351 spin_unlock_irqrestore(&dmasound.lock, flags);
1352 return IOCTL_OUT(arg, porta & 0x40 ? 0 : 100);
1353 }
1354 break;
1355 case SOUND_MIXER_WRITE_VOLUME:
1356 IOCTL_IN(arg, data);
1357 return IOCTL_OUT(arg, dmasound_set_volume(data));
1358 case SOUND_MIXER_WRITE_SPEAKER:
1359 if (is_falcon || MACH_IS_TT) {
1360 int porta;
1361 IOCTL_IN(arg, data);
1362 spin_lock_irqsave(&dmasound.lock, flags);
1363 sound_ym.rd_data_reg_sel = 14;
1364 porta = (sound_ym.rd_data_reg_sel & ~0x40) |
1365 (data < 50 ? 0x40 : 0);
1366 sound_ym.wd_data = porta;
1367 spin_unlock_irqrestore(&dmasound.lock, flags);
1368 return IOCTL_OUT(arg, porta & 0x40 ? 0 : 100);
1369 }
1370 }
1371 return -EINVAL;
1372}
1373
1374
1375static int TTMixerIoctl(u_int cmd, u_long arg)
1376{
1377 int data;
1378 switch (cmd) {
1379 case SOUND_MIXER_READ_RECMASK:
1380 return IOCTL_OUT(arg, 0);
1381 case SOUND_MIXER_READ_DEVMASK:
1382 return IOCTL_OUT(arg,
1383 SOUND_MASK_VOLUME | SOUND_MASK_TREBLE | SOUND_MASK_BASS |
1384 (MACH_IS_TT ? SOUND_MASK_SPEAKER : 0));
1385 case SOUND_MIXER_READ_STEREODEVS:
1386 return IOCTL_OUT(arg, SOUND_MASK_VOLUME);
1387 case SOUND_MIXER_READ_VOLUME:
1388 return IOCTL_OUT(arg,
1389 VOLUME_DB_TO_VOXWARE(dmasound.volume_left) |
1390 (VOLUME_DB_TO_VOXWARE(dmasound.volume_right) << 8));
1391 case SOUND_MIXER_READ_BASS:
1392 return IOCTL_OUT(arg, TONE_DB_TO_VOXWARE(dmasound.bass));
1393 case SOUND_MIXER_READ_TREBLE:
1394 return IOCTL_OUT(arg, TONE_DB_TO_VOXWARE(dmasound.treble));
1395 case SOUND_MIXER_READ_OGAIN:
1396 return IOCTL_OUT(arg, GAIN_DB_TO_VOXWARE(dmasound.gain));
1397 case SOUND_MIXER_WRITE_BASS:
1398 IOCTL_IN(arg, data);
1399 return IOCTL_OUT(arg, dmasound_set_bass(data));
1400 case SOUND_MIXER_WRITE_TREBLE:
1401 IOCTL_IN(arg, data);
1402 return IOCTL_OUT(arg, dmasound_set_treble(data));
1403 case SOUND_MIXER_WRITE_OGAIN:
1404 IOCTL_IN(arg, data);
1405 return IOCTL_OUT(arg, dmasound_set_gain(data));
1406 }
1407 return AtaMixerIoctl(cmd, arg);
1408}
1409
1410static int FalconMixerIoctl(u_int cmd, u_long arg)
1411{
1412 int data;
1413 switch (cmd) {
1414 case SOUND_MIXER_READ_RECMASK:
1415 return IOCTL_OUT(arg, SOUND_MASK_MIC);
1416 case SOUND_MIXER_READ_DEVMASK:
1417 return IOCTL_OUT(arg, SOUND_MASK_VOLUME | SOUND_MASK_MIC | SOUND_MASK_SPEAKER);
1418 case SOUND_MIXER_READ_STEREODEVS:
1419 return IOCTL_OUT(arg, SOUND_MASK_VOLUME | SOUND_MASK_MIC);
1420 case SOUND_MIXER_READ_VOLUME:
1421 return IOCTL_OUT(arg,
1422 VOLUME_ATT_TO_VOXWARE(dmasound.volume_left) |
1423 VOLUME_ATT_TO_VOXWARE(dmasound.volume_right) << 8);
1424 case SOUND_MIXER_READ_CAPS:
1425 return IOCTL_OUT(arg, SOUND_CAP_EXCL_INPUT);
1426 case SOUND_MIXER_WRITE_MIC:
1427 IOCTL_IN(arg, data);
1428 tt_dmasnd.input_gain =
1429 RECLEVEL_VOXWARE_TO_GAIN(data & 0xff) << 4 |
1430 RECLEVEL_VOXWARE_TO_GAIN(data >> 8 & 0xff);
1431 /* fall thru, return set value */
1432 case SOUND_MIXER_READ_MIC:
1433 return IOCTL_OUT(arg,
1434 RECLEVEL_GAIN_TO_VOXWARE(tt_dmasnd.input_gain >> 4 & 0xf) |
1435 RECLEVEL_GAIN_TO_VOXWARE(tt_dmasnd.input_gain & 0xf) << 8);
1436 }
1437 return AtaMixerIoctl(cmd, arg);
1438}
1439
1440static int AtaWriteSqSetup(void)
1441{
1442 write_sq_ignore_int = 0;
1443 return 0 ;
1444}
1445
1446static int AtaSqOpen(mode_t mode)
1447{
1448 write_sq_ignore_int = 1;
1449 return 0 ;
1450}
1451
1452static int TTStateInfo(char *buffer, size_t space)
1453{
1454 int len = 0;
1455 len += sprintf(buffer+len, "\tvol left %ddB [-40... 0]\n",
1456 dmasound.volume_left);
1457 len += sprintf(buffer+len, "\tvol right %ddB [-40... 0]\n",
1458 dmasound.volume_right);
1459 len += sprintf(buffer+len, "\tbass %ddB [-12...+12]\n",
1460 dmasound.bass);
1461 len += sprintf(buffer+len, "\ttreble %ddB [-12...+12]\n",
1462 dmasound.treble);
1463 if (len >= space) {
1464 printk(KERN_ERR "dmasound_atari: overflowed state buffer alloc.\n") ;
1465 len = space ;
1466 }
1467 return len;
1468}
1469
1470static int FalconStateInfo(char *buffer, size_t space)
1471{
1472 int len = 0;
1473 len += sprintf(buffer+len, "\tvol left %ddB [-22.5 ... 0]\n",
1474 dmasound.volume_left);
1475 len += sprintf(buffer+len, "\tvol right %ddB [-22.5 ... 0]\n",
1476 dmasound.volume_right);
1477 if (len >= space) {
1478 printk(KERN_ERR "dmasound_atari: overflowed state buffer alloc.\n") ;
1479 len = space ;
1480 }
1481 return len;
1482}
1483
1484
1485/*** Machine definitions *****************************************************/
1486
1487static SETTINGS def_hard_falcon = {
1488 .format = AFMT_S8,
1489 .stereo = 0,
1490 .size = 8,
1491 .speed = 8195
1492} ;
1493
1494static SETTINGS def_hard_tt = {
1495 .format = AFMT_S8,
1496 .stereo = 0,
1497 .size = 8,
1498 .speed = 12517
1499} ;
1500
1501static SETTINGS def_soft = {
1502 .format = AFMT_U8,
1503 .stereo = 0,
1504 .size = 8,
1505 .speed = 8000
1506} ;
1507
1508static MACHINE machTT = {
1509 .name = "Atari",
1510 .name2 = "TT",
1511 .owner = THIS_MODULE,
1512 .dma_alloc = AtaAlloc,
1513 .dma_free = AtaFree,
1514 .irqinit = AtaIrqInit,
1515#ifdef MODULE
1516 .irqcleanup = AtaIrqCleanUp,
1517#endif /* MODULE */
1518 .init = TTInit,
1519 .silence = TTSilence,
1520 .setFormat = TTSetFormat,
1521 .setVolume = TTSetVolume,
1522 .setBass = AtaSetBass,
1523 .setTreble = AtaSetTreble,
1524 .setGain = TTSetGain,
1525 .play = AtaPlay,
1526 .mixer_init = TTMixerInit,
1527 .mixer_ioctl = TTMixerIoctl,
1528 .write_sq_setup = AtaWriteSqSetup,
1529 .sq_open = AtaSqOpen,
1530 .state_info = TTStateInfo,
1531 .min_dsp_speed = 6258,
1532 .version = ((DMASOUND_ATARI_REVISION<<8) | DMASOUND_ATARI_EDITION),
1533 .hardware_afmts = AFMT_S8, /* h'ware-supported formats *only* here */
1534 .capabilities = DSP_CAP_BATCH /* As per SNDCTL_DSP_GETCAPS */
1535};
1536
1537static MACHINE machFalcon = {
1538 .name = "Atari",
1539 .name2 = "FALCON",
1540 .dma_alloc = AtaAlloc,
1541 .dma_free = AtaFree,
1542 .irqinit = AtaIrqInit,
1543#ifdef MODULE
1544 .irqcleanup = AtaIrqCleanUp,
1545#endif /* MODULE */
1546 .init = FalconInit,
1547 .silence = FalconSilence,
1548 .setFormat = FalconSetFormat,
1549 .setVolume = FalconSetVolume,
1550 .setBass = AtaSetBass,
1551 .setTreble = AtaSetTreble,
1552 .play = AtaPlay,
1553 .mixer_init = FalconMixerInit,
1554 .mixer_ioctl = FalconMixerIoctl,
1555 .write_sq_setup = AtaWriteSqSetup,
1556 .sq_open = AtaSqOpen,
1557 .state_info = FalconStateInfo,
1558 .min_dsp_speed = 8195,
1559 .version = ((DMASOUND_ATARI_REVISION<<8) | DMASOUND_ATARI_EDITION),
1560 .hardware_afmts = (AFMT_S8 | AFMT_S16_BE), /* h'ware-supported formats *only* here */
1561 .capabilities = DSP_CAP_BATCH /* As per SNDCTL_DSP_GETCAPS */
1562};
1563
1564
1565/*** Config & Setup **********************************************************/
1566
1567
1568static int __init dmasound_atari_init(void)
1569{
1570 if (MACH_IS_ATARI && ATARIHW_PRESENT(PCM_8BIT)) {
1571 if (ATARIHW_PRESENT(CODEC)) {
1572 dmasound.mach = machFalcon;
1573 dmasound.mach.default_soft = def_soft ;
1574 dmasound.mach.default_hard = def_hard_falcon ;
1575 is_falcon = 1;
1576 } else if (ATARIHW_PRESENT(MICROWIRE)) {
1577 dmasound.mach = machTT;
1578 dmasound.mach.default_soft = def_soft ;
1579 dmasound.mach.default_hard = def_hard_tt ;
1580 is_falcon = 0;
1581 } else
1582 return -ENODEV;
1583 if ((mfp.int_en_a & mfp.int_mk_a & 0x20) == 0)
1584 return dmasound_init();
1585 else {
1586 printk("DMA sound driver: Timer A interrupt already in use\n");
1587 return -EBUSY;
1588 }
1589 }
1590 return -ENODEV;
1591}
1592
1593static void __exit dmasound_atari_cleanup(void)
1594{
1595 dmasound_deinit();
1596}
1597
1598module_init(dmasound_atari_init);
1599module_exit(dmasound_atari_cleanup);
1600MODULE_LICENSE("GPL");
diff --git a/sound/oss/dmasound/dmasound_awacs.c b/sound/oss/dmasound/dmasound_awacs.c
new file mode 100644
index 000000000000..5281b88987f3
--- /dev/null
+++ b/sound/oss/dmasound/dmasound_awacs.c
@@ -0,0 +1,3176 @@
1/*
2 * linux/sound/oss/dmasound/dmasound_awacs.c
3 *
4 * PowerMac `AWACS' and `Burgundy' DMA Sound Driver
5 * with some limited support for DACA & Tumbler
6 *
7 * See linux/sound/oss/dmasound/dmasound_core.c for copyright and
8 * history prior to 2001/01/26.
9 *
10 * 26/01/2001 ed 0.1 Iain Sandoe
11 * - added version info.
12 * - moved dbdma command buffer allocation to PMacXXXSqSetup()
13 * - fixed up beep dbdma cmd buffers
14 *
15 * 08/02/2001 [0.2]
16 * - make SNDCTL_DSP_GETFMTS return the correct info for the h/w
17 * - move soft format translations to a separate file
18 * - [0.3] make SNDCTL_DSP_GETCAPS return correct info.
19 * - [0.4] more informative machine name strings.
20 * - [0.5]
21 * - record changes.
22 * - made the default_hard/soft entries.
23 * 04/04/2001 [0.6]
24 * - minor correction to bit assignments in awacs_defs.h
25 * - incorporate mixer changes from 2.2.x back-port.
26 * - take out passthru as a rec input (it isn't).
27 * - make Input Gain slider work the 'right way up'.
28 * - try to make the mixer sliders more logical - so now the
29 * input selectors are just two-state (>50% == ON) and the
30 * Input Gain slider handles the rest of the gain issues.
31 * - try to pick slider representations that most closely match
32 * the actual use - e.g. IGain for input gain...
33 * - first stab at over/under-run detection.
34 * - minor cosmetic changes to IRQ identification.
35 * - fix bug where rates > max would be reported as supported.
36 * - first stab at over/under-run detection.
37 * - make use of i2c for mixer settings conditional on perch
38 * rather than cuda (some machines without perch have cuda).
39 * - fix bug where TX stops when dbdma status comes up "DEAD"
40 * so far only reported on PowerComputing clones ... but.
41 * - put in AWACS/Screamer register write timeouts.
42 * - part way to partitioning the init() stuff
43 * - first pass at 'tumbler' stuff (not support - just an attempt
44 * to allow the driver to load on new G4s).
45 * 01/02/2002 [0.7] - BenH
46 * - all sort of minor bits went in since the latest update, I
47 * bumped the version number for that reason
48 *
49 * 07/26/2002 [0.8] - BenH
50 * - More minor bits since last changelog (I should be more careful
51 * with those)
52 * - Support for snapper & better tumbler integration by Toby Sargeant
53 * - Headphone detect for scremer by Julien Blache
54 * - More tumbler fixed by Andreas Schwab
55 * 11/29/2003 [0.8.1] - Renzo Davoli (King Enzo)
56 * - Support for Snapper line in
57 * - snapper input resampling (for rates < 44100)
58 * - software line gain control
59 */
60
61/* GENERAL FIXME/TODO: check that the assumptions about what is written to
62 mac-io is valid for DACA & Tumbler.
63
64 This driver is in bad need of a rewrite. The dbdma code has to be split,
65 some proper device-tree parsing code has to be written, etc...
66*/
67
68#include <linux/types.h>
69#include <linux/module.h>
70#include <linux/config.h>
71#include <linux/slab.h>
72#include <linux/init.h>
73#include <linux/delay.h>
74#include <linux/soundcard.h>
75#include <linux/adb.h>
76#include <linux/nvram.h>
77#include <linux/tty.h>
78#include <linux/vt_kern.h>
79#include <linux/spinlock.h>
80#include <linux/kmod.h>
81#include <linux/interrupt.h>
82#include <linux/input.h>
83#include <asm/semaphore.h>
84#ifdef CONFIG_ADB_CUDA
85#include <linux/cuda.h>
86#endif
87#ifdef CONFIG_ADB_PMU
88#include <linux/pmu.h>
89#endif
90
91#include <linux/i2c-dev.h>
92
93#include <asm/uaccess.h>
94#include <asm/prom.h>
95#include <asm/machdep.h>
96#include <asm/io.h>
97#include <asm/dbdma.h>
98#include <asm/pmac_feature.h>
99#include <asm/irq.h>
100#include <asm/nvram.h>
101
102#include "awacs_defs.h"
103#include "dmasound.h"
104#include "tas3001c.h"
105#include "tas3004.h"
106#include "tas_common.h"
107
108#define DMASOUND_AWACS_REVISION 0
109#define DMASOUND_AWACS_EDITION 7
110
111#define AWACS_SNAPPER 110 /* fake revision # for snapper */
112#define AWACS_BURGUNDY 100 /* fake revision # for burgundy */
113#define AWACS_TUMBLER 90 /* fake revision # for tumbler */
114#define AWACS_DACA 80 /* fake revision # for daca (ibook) */
115#define AWACS_AWACS 2 /* holding revision for AWACS */
116#define AWACS_SCREAMER 3 /* holding revision for Screamer */
117/*
118 * Interrupt numbers and addresses, & info obtained from the device tree.
119 */
120static int awacs_irq, awacs_tx_irq, awacs_rx_irq;
121static volatile struct awacs_regs __iomem *awacs;
122static volatile u32 __iomem *i2s;
123static volatile struct dbdma_regs __iomem *awacs_txdma, *awacs_rxdma;
124static int awacs_rate_index;
125static int awacs_subframe;
126static struct device_node* awacs_node;
127static struct device_node* i2s_node;
128
129static char awacs_name[64];
130static int awacs_revision;
131static int awacs_sleeping;
132static DECLARE_MUTEX(dmasound_sem);
133
134static int sound_device_id; /* exists after iMac revA */
135static int hw_can_byteswap = 1 ; /* most pmac sound h/w can */
136
137/* model info */
138/* To be replaced with better interaction with pmac_feature.c */
139static int is_pbook_3X00;
140static int is_pbook_g3;
141
142/* expansion info */
143static int has_perch;
144static int has_ziva;
145
146/* for earlier powerbooks which need fiddling with mac-io to enable
147 * cd etc.
148*/
149static unsigned char __iomem *latch_base;
150static unsigned char __iomem *macio_base;
151
152/*
153 * Space for the DBDMA command blocks.
154 */
155static void *awacs_tx_cmd_space;
156static volatile struct dbdma_cmd *awacs_tx_cmds;
157static int number_of_tx_cmd_buffers;
158
159static void *awacs_rx_cmd_space;
160static volatile struct dbdma_cmd *awacs_rx_cmds;
161static int number_of_rx_cmd_buffers;
162
163/*
164 * Cached values of AWACS registers (we can't read them).
165 * Except on the burgundy (and screamer). XXX
166 */
167
168int awacs_reg[8];
169int awacs_reg1_save;
170
171/* tracking values for the mixer contents
172*/
173
174static int spk_vol;
175static int line_vol;
176static int passthru_vol;
177
178static int ip_gain; /* mic preamp settings */
179static int rec_lev = 0x4545 ; /* default CD gain 69 % */
180static int mic_lev;
181static int cd_lev = 0x6363 ; /* 99 % */
182static int line_lev;
183
184static int hdp_connected;
185
186/*
187 * Stuff for outputting a beep. The values range from -327 to +327
188 * so we can multiply by an amplitude in the range 0..100 to get a
189 * signed short value to put in the output buffer.
190 */
191static short beep_wform[256] = {
192 0, 40, 79, 117, 153, 187, 218, 245,
193 269, 288, 304, 316, 323, 327, 327, 324,
194 318, 310, 299, 288, 275, 262, 249, 236,
195 224, 213, 204, 196, 190, 186, 183, 182,
196 182, 183, 186, 189, 192, 196, 200, 203,
197 206, 208, 209, 209, 209, 207, 204, 201,
198 197, 193, 188, 183, 179, 174, 170, 166,
199 163, 161, 160, 159, 159, 160, 161, 162,
200 164, 166, 168, 169, 171, 171, 171, 170,
201 169, 167, 163, 159, 155, 150, 144, 139,
202 133, 128, 122, 117, 113, 110, 107, 105,
203 103, 103, 103, 103, 104, 104, 105, 105,
204 105, 103, 101, 97, 92, 86, 78, 68,
205 58, 45, 32, 18, 3, -11, -26, -41,
206 -55, -68, -79, -88, -95, -100, -102, -102,
207 -99, -93, -85, -75, -62, -48, -33, -16,
208 0, 16, 33, 48, 62, 75, 85, 93,
209 99, 102, 102, 100, 95, 88, 79, 68,
210 55, 41, 26, 11, -3, -18, -32, -45,
211 -58, -68, -78, -86, -92, -97, -101, -103,
212 -105, -105, -105, -104, -104, -103, -103, -103,
213 -103, -105, -107, -110, -113, -117, -122, -128,
214 -133, -139, -144, -150, -155, -159, -163, -167,
215 -169, -170, -171, -171, -171, -169, -168, -166,
216 -164, -162, -161, -160, -159, -159, -160, -161,
217 -163, -166, -170, -174, -179, -183, -188, -193,
218 -197, -201, -204, -207, -209, -209, -209, -208,
219 -206, -203, -200, -196, -192, -189, -186, -183,
220 -182, -182, -183, -186, -190, -196, -204, -213,
221 -224, -236, -249, -262, -275, -288, -299, -310,
222 -318, -324, -327, -327, -323, -316, -304, -288,
223 -269, -245, -218, -187, -153, -117, -79, -40,
224};
225
226/* beep support */
227#define BEEP_SRATE 22050 /* 22050 Hz sample rate */
228#define BEEP_BUFLEN 512
229#define BEEP_VOLUME 15 /* 0 - 100 */
230
231static int beep_vol = BEEP_VOLUME;
232static int beep_playing;
233static int awacs_beep_state;
234static short *beep_buf;
235static void *beep_dbdma_cmd_space;
236static volatile struct dbdma_cmd *beep_dbdma_cmd;
237
238/* Burgundy functions */
239static void awacs_burgundy_wcw(unsigned addr,unsigned newval);
240static unsigned awacs_burgundy_rcw(unsigned addr);
241static void awacs_burgundy_write_volume(unsigned address, int volume);
242static int awacs_burgundy_read_volume(unsigned address);
243static void awacs_burgundy_write_mvolume(unsigned address, int volume);
244static int awacs_burgundy_read_mvolume(unsigned address);
245
246/* we will allocate a single 'emergency' dbdma cmd block to use if the
247 tx status comes up "DEAD". This happens on some PowerComputing Pmac
248 clones, either owing to a bug in dbdma or some interaction between
249 IDE and sound. However, this measure would deal with DEAD status if
250 if appeared elsewhere.
251
252 for the sake of memory efficiency we'll allocate this cmd as part of
253 the beep cmd stuff.
254*/
255
256static volatile struct dbdma_cmd *emergency_dbdma_cmd;
257
258#ifdef CONFIG_PMAC_PBOOK
259/*
260 * Stuff for restoring after a sleep.
261 */
262static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when);
263struct pmu_sleep_notifier awacs_sleep_notifier = {
264 awacs_sleep_notify, SLEEP_LEVEL_SOUND,
265};
266#endif /* CONFIG_PMAC_PBOOK */
267
268/* for (soft) sample rate translations */
269int expand_bal; /* Balance factor for expanding (not volume!) */
270int expand_read_bal; /* Balance factor for expanding reads (not volume!) */
271
272/*** Low level stuff *********************************************************/
273
274static void *PMacAlloc(unsigned int size, int flags);
275static void PMacFree(void *ptr, unsigned int size);
276static int PMacIrqInit(void);
277#ifdef MODULE
278static void PMacIrqCleanup(void);
279#endif
280static void PMacSilence(void);
281static void PMacInit(void);
282static int PMacSetFormat(int format);
283static int PMacSetVolume(int volume);
284static void PMacPlay(void);
285static void PMacRecord(void);
286static irqreturn_t pmac_awacs_tx_intr(int irq, void *devid, struct pt_regs *regs);
287static irqreturn_t pmac_awacs_rx_intr(int irq, void *devid, struct pt_regs *regs);
288static irqreturn_t pmac_awacs_intr(int irq, void *devid, struct pt_regs *regs);
289static void awacs_write(int val);
290static int awacs_get_volume(int reg, int lshift);
291static int awacs_volume_setter(int volume, int n, int mute, int lshift);
292
293
294/*** Mid level stuff **********************************************************/
295
296static int PMacMixerIoctl(u_int cmd, u_long arg);
297static int PMacWriteSqSetup(void);
298static int PMacReadSqSetup(void);
299static void PMacAbortRead(void);
300
301extern TRANS transAwacsNormal ;
302extern TRANS transAwacsExpand ;
303extern TRANS transAwacsNormalRead ;
304extern TRANS transAwacsExpandRead ;
305
306extern int daca_init(void);
307extern void daca_cleanup(void);
308extern int daca_set_volume(uint left_vol, uint right_vol);
309extern void daca_get_volume(uint * left_vol, uint *right_vol);
310extern int daca_enter_sleep(void);
311extern int daca_leave_sleep(void);
312
313#define TRY_LOCK() \
314 if ((rc = down_interruptible(&dmasound_sem)) != 0) \
315 return rc;
316#define LOCK() down(&dmasound_sem);
317
318#define UNLOCK() up(&dmasound_sem);
319
320/* We use different versions that the ones provided in dmasound.h
321 *
322 * FIXME: Use different names ;)
323 */
324#undef IOCTL_IN
325#undef IOCTL_OUT
326
327#define IOCTL_IN(arg, ret) \
328 rc = get_user(ret, (int __user *)(arg)); \
329 if (rc) break;
330#define IOCTL_OUT(arg, ret) \
331 ioctl_return2((int __user *)(arg), ret)
332
333static inline int ioctl_return2(int __user *addr, int value)
334{
335 return value < 0 ? value : put_user(value, addr);
336}
337
338
339/*** AE - TUMBLER / SNAPPER START ************************************************/
340
341
342int gpio_audio_reset, gpio_audio_reset_pol;
343int gpio_amp_mute, gpio_amp_mute_pol;
344int gpio_headphone_mute, gpio_headphone_mute_pol;
345int gpio_headphone_detect, gpio_headphone_detect_pol;
346int gpio_headphone_irq;
347
348int
349setup_audio_gpio(const char *name, const char* compatible, int *gpio_addr, int* gpio_pol)
350{
351 struct device_node *np;
352 u32* pp;
353
354 np = find_devices("gpio");
355 if (!np)
356 return -ENODEV;
357
358 np = np->child;
359 while(np != 0) {
360 if (name) {
361 char *property = get_property(np,"audio-gpio",NULL);
362 if (property != 0 && strcmp(property,name) == 0)
363 break;
364 } else if (compatible && device_is_compatible(np, compatible))
365 break;
366 np = np->sibling;
367 }
368 if (!np)
369 return -ENODEV;
370 pp = (u32 *)get_property(np, "AAPL,address", NULL);
371 if (!pp)
372 return -ENODEV;
373 *gpio_addr = (*pp) & 0x0000ffff;
374 pp = (u32 *)get_property(np, "audio-gpio-active-state", NULL);
375 if (pp)
376 *gpio_pol = *pp;
377 else
378 *gpio_pol = 1;
379 if (np->n_intrs > 0)
380 return np->intrs[0].line;
381
382 return 0;
383}
384
385static inline void
386write_audio_gpio(int gpio_addr, int data)
387{
388 if (!gpio_addr)
389 return;
390 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, gpio_addr, data ? 0x05 : 0x04);
391}
392
393static inline int
394read_audio_gpio(int gpio_addr)
395{
396 if (!gpio_addr)
397 return 0;
398 return ((pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, gpio_addr, 0) & 0x02) !=0);
399}
400
401/*
402 * Headphone interrupt via GPIO (Tumbler, Snapper, DACA)
403 */
404static irqreturn_t
405headphone_intr(int irq, void *devid, struct pt_regs *regs)
406{
407 unsigned long flags;
408
409 spin_lock_irqsave(&dmasound.lock, flags);
410 if (read_audio_gpio(gpio_headphone_detect) == gpio_headphone_detect_pol) {
411 printk(KERN_INFO "Audio jack plugged, muting speakers.\n");
412 write_audio_gpio(gpio_headphone_mute, !gpio_headphone_mute_pol);
413 write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
414 tas_output_device_change(sound_device_id,TAS_OUTPUT_HEADPHONES,0);
415 } else {
416 printk(KERN_INFO "Audio jack unplugged, enabling speakers.\n");
417 write_audio_gpio(gpio_amp_mute, !gpio_amp_mute_pol);
418 write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
419 tas_output_device_change(sound_device_id,TAS_OUTPUT_INTERNAL_SPKR,0);
420 }
421 spin_unlock_irqrestore(&dmasound.lock, flags);
422 return IRQ_HANDLED;
423}
424
425
426/* Initialize tumbler */
427
428static int
429tas_dmasound_init(void)
430{
431 setup_audio_gpio(
432 "audio-hw-reset",
433 NULL,
434 &gpio_audio_reset,
435 &gpio_audio_reset_pol);
436 setup_audio_gpio(
437 "amp-mute",
438 NULL,
439 &gpio_amp_mute,
440 &gpio_amp_mute_pol);
441 setup_audio_gpio("headphone-mute",
442 NULL,
443 &gpio_headphone_mute,
444 &gpio_headphone_mute_pol);
445 gpio_headphone_irq = setup_audio_gpio(
446 "headphone-detect",
447 NULL,
448 &gpio_headphone_detect,
449 &gpio_headphone_detect_pol);
450 /* Fix some broken OF entries in desktop machines */
451 if (!gpio_headphone_irq)
452 gpio_headphone_irq = setup_audio_gpio(
453 NULL,
454 "keywest-gpio15",
455 &gpio_headphone_detect,
456 &gpio_headphone_detect_pol);
457
458 write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
459 msleep(100);
460 write_audio_gpio(gpio_audio_reset, !gpio_audio_reset_pol);
461 msleep(100);
462 if (gpio_headphone_irq) {
463 if (request_irq(gpio_headphone_irq,headphone_intr,0,"Headphone detect",NULL) < 0) {
464 printk(KERN_ERR "tumbler: Can't request headphone interrupt\n");
465 gpio_headphone_irq = 0;
466 } else {
467 u8 val;
468 /* Activate headphone status interrupts */
469 val = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, gpio_headphone_detect, 0);
470 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, gpio_headphone_detect, val | 0x80);
471 /* Trigger it */
472 headphone_intr(0,NULL,NULL);
473 }
474 }
475 if (!gpio_headphone_irq) {
476 /* Some machine enter this case ? */
477 printk(KERN_WARNING "tumbler: Headphone detect IRQ not found, enabling all outputs !\n");
478 write_audio_gpio(gpio_amp_mute, !gpio_amp_mute_pol);
479 write_audio_gpio(gpio_headphone_mute, !gpio_headphone_mute_pol);
480 }
481 return 0;
482}
483
484
485static int
486tas_dmasound_cleanup(void)
487{
488 if (gpio_headphone_irq)
489 free_irq(gpio_headphone_irq, NULL);
490 return 0;
491}
492
493/* We don't support 48k yet */
494static int tas_freqs[1] = { 44100 } ;
495static int tas_freqs_ok[1] = { 1 } ;
496
497/* don't know what to do really - just have to leave it where
498 * OF left things
499*/
500
501static int
502tas_set_frame_rate(void)
503{
504 if (i2s) {
505 out_le32(i2s + (I2S_REG_SERIAL_FORMAT >> 2), 0x41190000);
506 out_le32(i2s + (I2S_REG_DATAWORD_SIZES >> 2), 0x02000200);
507 }
508 dmasound.hard.speed = 44100 ;
509 awacs_rate_index = 0 ;
510 return 44100 ;
511}
512
513static int
514tas_mixer_ioctl(u_int cmd, u_long arg)
515{
516 int __user *argp = (int __user *)arg;
517 int data;
518 int rc;
519
520 rc=tas_device_ioctl(cmd, arg);
521 if (rc != -EINVAL) {
522 return rc;
523 }
524
525 if ((cmd & ~0xff) == MIXER_WRITE(0) &&
526 tas_supported_mixers() & (1<<(cmd & 0xff))) {
527 rc = get_user(data, argp);
528 if (rc<0) return rc;
529 tas_set_mixer_level(cmd & 0xff, data);
530 tas_get_mixer_level(cmd & 0xff, &data);
531 return ioctl_return2(argp, data);
532 }
533 if ((cmd & ~0xff) == MIXER_READ(0) &&
534 tas_supported_mixers() & (1<<(cmd & 0xff))) {
535 tas_get_mixer_level(cmd & 0xff, &data);
536 return ioctl_return2(argp, data);
537 }
538
539 switch(cmd) {
540 case SOUND_MIXER_READ_DEVMASK:
541 data = tas_supported_mixers() | SOUND_MASK_SPEAKER;
542 rc = IOCTL_OUT(arg, data);
543 break;
544 case SOUND_MIXER_READ_STEREODEVS:
545 data = tas_stereo_mixers();
546 rc = IOCTL_OUT(arg, data);
547 break;
548 case SOUND_MIXER_READ_CAPS:
549 rc = IOCTL_OUT(arg, 0);
550 break;
551 case SOUND_MIXER_READ_RECMASK:
552 // XXX FIXME: find a way to check what is really available */
553 data = SOUND_MASK_LINE | SOUND_MASK_MIC;
554 rc = IOCTL_OUT(arg, data);
555 break;
556 case SOUND_MIXER_READ_RECSRC:
557 if (awacs_reg[0] & MASK_MUX_AUDIN)
558 data |= SOUND_MASK_LINE;
559 if (awacs_reg[0] & MASK_MUX_MIC)
560 data |= SOUND_MASK_MIC;
561 rc = IOCTL_OUT(arg, data);
562 break;
563 case SOUND_MIXER_WRITE_RECSRC:
564 IOCTL_IN(arg, data);
565 data =0;
566 rc = IOCTL_OUT(arg, data);
567 break;
568 case SOUND_MIXER_WRITE_SPEAKER: /* really bell volume */
569 IOCTL_IN(arg, data);
570 beep_vol = data & 0xff;
571 /* fall through */
572 case SOUND_MIXER_READ_SPEAKER:
573 rc = IOCTL_OUT(arg, (beep_vol<<8) | beep_vol);
574 break;
575 case SOUND_MIXER_OUTMASK:
576 case SOUND_MIXER_OUTSRC:
577 default:
578 rc = -EINVAL;
579 }
580
581 return rc;
582}
583
584static void __init
585tas_init_frame_rates(unsigned int *prop, unsigned int l)
586{
587 int i ;
588 if (prop) {
589 for (i=0; i<1; i++)
590 tas_freqs_ok[i] = 0;
591 for (l /= sizeof(int); l > 0; --l) {
592 unsigned int r = *prop++;
593 /* Apple 'Fixed' format */
594 if (r >= 0x10000)
595 r >>= 16;
596 for (i = 0; i < 1; ++i) {
597 if (r == tas_freqs[i]) {
598 tas_freqs_ok[i] = 1;
599 break;
600 }
601 }
602 }
603 }
604 /* else we assume that all the rates are available */
605}
606
607
608/*** AE - TUMBLER / SNAPPER END ************************************************/
609
610
611
612/*** Low level stuff *********************************************************/
613
614/*
615 * PCI PowerMac, with AWACS, Screamer, Burgundy, DACA or Tumbler and DBDMA.
616 */
617static void *PMacAlloc(unsigned int size, int flags)
618{
619 return kmalloc(size, flags);
620}
621
622static void PMacFree(void *ptr, unsigned int size)
623{
624 kfree(ptr);
625}
626
627static int __init PMacIrqInit(void)
628{
629 if (awacs)
630 if (request_irq(awacs_irq, pmac_awacs_intr, 0, "Built-in Sound misc", NULL))
631 return 0;
632 if (request_irq(awacs_tx_irq, pmac_awacs_tx_intr, 0, "Built-in Sound out", NULL)
633 || request_irq(awacs_rx_irq, pmac_awacs_rx_intr, 0, "Built-in Sound in", NULL))
634 return 0;
635 return 1;
636}
637
638#ifdef MODULE
639static void PMacIrqCleanup(void)
640{
641 /* turn off input & output dma */
642 DBDMA_DO_STOP(awacs_txdma);
643 DBDMA_DO_STOP(awacs_rxdma);
644
645 if (awacs)
646 /* disable interrupts from awacs interface */
647 out_le32(&awacs->control, in_le32(&awacs->control) & 0xfff);
648
649 /* Switch off the sound clock */
650 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 0);
651 /* Make sure proper bits are set on pismo & tipb */
652 if ((machine_is_compatible("PowerBook3,1") ||
653 machine_is_compatible("PowerBook3,2")) && awacs) {
654 awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
655 awacs_write(MASK_ADDR1 | awacs_reg[1]);
656 msleep(200);
657 }
658 if (awacs)
659 free_irq(awacs_irq, NULL);
660 free_irq(awacs_tx_irq, NULL);
661 free_irq(awacs_rx_irq, NULL);
662
663 if (awacs)
664 iounmap(awacs);
665 if (i2s)
666 iounmap(i2s);
667 iounmap(awacs_txdma);
668 iounmap(awacs_rxdma);
669
670 release_OF_resource(awacs_node, 0);
671 release_OF_resource(awacs_node, 1);
672 release_OF_resource(awacs_node, 2);
673
674 if (awacs_tx_cmd_space)
675 kfree(awacs_tx_cmd_space);
676 if (awacs_rx_cmd_space)
677 kfree(awacs_rx_cmd_space);
678 if (beep_dbdma_cmd_space)
679 kfree(beep_dbdma_cmd_space);
680 if (beep_buf)
681 kfree(beep_buf);
682#ifdef CONFIG_PMAC_PBOOK
683 pmu_unregister_sleep_notifier(&awacs_sleep_notifier);
684#endif
685}
686#endif /* MODULE */
687
688static void PMacSilence(void)
689{
690 /* turn off output dma */
691 DBDMA_DO_STOP(awacs_txdma);
692}
693
694/* don't know what to do really - just have to leave it where
695 * OF left things
696*/
697
698static int daca_set_frame_rate(void)
699{
700 if (i2s) {
701 out_le32(i2s + (I2S_REG_SERIAL_FORMAT >> 2), 0x41190000);
702 out_le32(i2s + (I2S_REG_DATAWORD_SIZES >> 2), 0x02000200);
703 }
704 dmasound.hard.speed = 44100 ;
705 awacs_rate_index = 0 ;
706 return 44100 ;
707}
708
709static int awacs_freqs[8] = {
710 44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
711};
712static int awacs_freqs_ok[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
713
714static int
715awacs_set_frame_rate(int desired, int catch_r)
716{
717 int tolerance, i = 8 ;
718 /*
719 * If we have a sample rate which is within catchRadius percent
720 * of the requested value, we don't have to expand the samples.
721 * Otherwise choose the next higher rate.
722 * N.B.: burgundy awacs only works at 44100 Hz.
723 */
724 do {
725 tolerance = catch_r * awacs_freqs[--i] / 100;
726 if (awacs_freqs_ok[i]
727 && dmasound.soft.speed <= awacs_freqs[i] + tolerance)
728 break;
729 } while (i > 0);
730 dmasound.hard.speed = awacs_freqs[i];
731 awacs_rate_index = i;
732
733 out_le32(&awacs->control, MASK_IEPC | (i << 8) | 0x11 );
734 awacs_reg[1] = (awacs_reg[1] & ~MASK_SAMPLERATE) | (i << 3);
735 awacs_write(awacs_reg[1] | MASK_ADDR1);
736 return dmasound.hard.speed;
737}
738
739static int
740burgundy_set_frame_rate(void)
741{
742 awacs_rate_index = 0 ;
743 awacs_reg[1] = (awacs_reg[1] & ~MASK_SAMPLERATE) ;
744 /* XXX disable error interrupt on burgundy for now */
745 out_le32(&awacs->control, MASK_IEPC | 0 | 0x11 | MASK_IEE);
746 return 44100 ;
747}
748
749static int
750set_frame_rate(int desired, int catch_r)
751{
752 switch (awacs_revision) {
753 case AWACS_BURGUNDY:
754 dmasound.hard.speed = burgundy_set_frame_rate();
755 break ;
756 case AWACS_TUMBLER:
757 case AWACS_SNAPPER:
758 dmasound.hard.speed = tas_set_frame_rate();
759 break ;
760 case AWACS_DACA:
761 dmasound.hard.speed =
762 daca_set_frame_rate();
763 break ;
764 default:
765 dmasound.hard.speed = awacs_set_frame_rate(desired,
766 catch_r);
767 break ;
768 }
769 return dmasound.hard.speed ;
770}
771
772static void
773awacs_recalibrate(void)
774{
775 /* Sorry for the horrible delays... I hope to get that improved
776 * by making the whole PM process asynchronous in a future version
777 */
778 msleep(750);
779 awacs_reg[1] |= MASK_CMUTE | MASK_AMUTE;
780 awacs_write(awacs_reg[1] | MASK_RECALIBRATE | MASK_ADDR1);
781 msleep(1000);
782 awacs_write(awacs_reg[1] | MASK_ADDR1);
783}
784
785static void PMacInit(void)
786{
787 int tolerance;
788
789 switch (dmasound.soft.format) {
790 case AFMT_S16_LE:
791 case AFMT_U16_LE:
792 if (hw_can_byteswap)
793 dmasound.hard.format = AFMT_S16_LE;
794 else
795 dmasound.hard.format = AFMT_S16_BE;
796 break;
797 default:
798 dmasound.hard.format = AFMT_S16_BE;
799 break;
800 }
801 dmasound.hard.stereo = 1;
802 dmasound.hard.size = 16;
803
804 /* set dmasound.hard.speed - on the basis of what we want (soft)
805 * and the tolerance we'll allow.
806 */
807 set_frame_rate(dmasound.soft.speed, catchRadius) ;
808
809 tolerance = (catchRadius * dmasound.hard.speed) / 100;
810 if (dmasound.soft.speed >= dmasound.hard.speed - tolerance) {
811 dmasound.trans_write = &transAwacsNormal;
812 dmasound.trans_read = &transAwacsNormalRead;
813 } else {
814 dmasound.trans_write = &transAwacsExpand;
815 dmasound.trans_read = &transAwacsExpandRead;
816 }
817
818 if (awacs) {
819 if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE))
820 out_le32(&awacs->byteswap, BS_VAL);
821 else
822 out_le32(&awacs->byteswap, 0);
823 }
824
825 expand_bal = -dmasound.soft.speed;
826 expand_read_bal = -dmasound.soft.speed;
827}
828
829static int PMacSetFormat(int format)
830{
831 int size;
832 int req_format = format;
833
834 switch (format) {
835 case AFMT_QUERY:
836 return dmasound.soft.format;
837 case AFMT_MU_LAW:
838 case AFMT_A_LAW:
839 case AFMT_U8:
840 case AFMT_S8:
841 size = 8;
842 break;
843 case AFMT_S16_LE:
844 if(!hw_can_byteswap)
845 format = AFMT_S16_BE;
846 case AFMT_S16_BE:
847 size = 16;
848 break;
849 case AFMT_U16_LE:
850 if(!hw_can_byteswap)
851 format = AFMT_U16_BE;
852 case AFMT_U16_BE:
853 size = 16;
854 break;
855 default: /* :-) */
856 printk(KERN_ERR "dmasound: unknown format 0x%x, using AFMT_U8\n",
857 format);
858 size = 8;
859 format = AFMT_U8;
860 }
861
862 if (req_format == format) {
863 dmasound.soft.format = format;
864 dmasound.soft.size = size;
865 if (dmasound.minDev == SND_DEV_DSP) {
866 dmasound.dsp.format = format;
867 dmasound.dsp.size = size;
868 }
869 }
870
871 return format;
872}
873
874#define AWACS_VOLUME_TO_MASK(x) (15 - ((((x) - 1) * 15) / 99))
875#define AWACS_MASK_TO_VOLUME(y) (100 - ((y) * 99 / 15))
876
877static int awacs_get_volume(int reg, int lshift)
878{
879 int volume;
880
881 volume = AWACS_MASK_TO_VOLUME((reg >> lshift) & 0xf);
882 volume |= AWACS_MASK_TO_VOLUME(reg & 0xf) << 8;
883 return volume;
884}
885
886static int awacs_volume_setter(int volume, int n, int mute, int lshift)
887{
888 int r1, rn;
889
890 if (mute && volume == 0) {
891 r1 = awacs_reg[1] | mute;
892 } else {
893 r1 = awacs_reg[1] & ~mute;
894 rn = awacs_reg[n] & ~(0xf | (0xf << lshift));
895 rn |= ((AWACS_VOLUME_TO_MASK(volume & 0xff) & 0xf) << lshift);
896 rn |= AWACS_VOLUME_TO_MASK((volume >> 8) & 0xff) & 0xf;
897 awacs_reg[n] = rn;
898 awacs_write((n << 12) | rn);
899 volume = awacs_get_volume(rn, lshift);
900 }
901 if (r1 != awacs_reg[1]) {
902 awacs_reg[1] = r1;
903 awacs_write(r1 | MASK_ADDR1);
904 }
905 return volume;
906}
907
908static int PMacSetVolume(int volume)
909{
910 printk(KERN_WARNING "Bogus call to PMacSetVolume !\n");
911 return 0;
912}
913
914static void awacs_setup_for_beep(int speed)
915{
916 out_le32(&awacs->control,
917 (in_le32(&awacs->control) & ~0x1f00)
918 | ((speed > 0 ? speed : awacs_rate_index) << 8));
919
920 if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE) && speed == -1)
921 out_le32(&awacs->byteswap, BS_VAL);
922 else
923 out_le32(&awacs->byteswap, 0);
924}
925
926/* CHECK: how much of this *really* needs IRQs masked? */
927static void __PMacPlay(void)
928{
929 volatile struct dbdma_cmd *cp;
930 int next_frg, count;
931
932 count = 300 ; /* > two cycles at the lowest sample rate */
933
934 /* what we want to send next */
935 next_frg = (write_sq.front + write_sq.active) % write_sq.max_count;
936
937 if (awacs_beep_state) {
938 /* sound takes precedence over beeps */
939 /* stop the dma channel */
940 out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
941 while ( (in_le32(&awacs_txdma->status) & RUN) && count--)
942 udelay(1);
943 if (awacs)
944 awacs_setup_for_beep(-1);
945 out_le32(&awacs_txdma->cmdptr,
946 virt_to_bus(&(awacs_tx_cmds[next_frg])));
947
948 beep_playing = 0;
949 awacs_beep_state = 0;
950 }
951 /* this won't allow more than two frags to be in the output queue at
952 once. (or one, if the max frags is 2 - because count can't exceed
953 2 in that case)
954 */
955 while (write_sq.active < 2 && write_sq.active < write_sq.count) {
956 count = (write_sq.count == write_sq.active + 1) ?
957 write_sq.rear_size:write_sq.block_size ;
958 if (count < write_sq.block_size) {
959 if (!write_sq.syncing) /* last block not yet filled,*/
960 break; /* and we're not syncing or POST-ed */
961 else {
962 /* pretend the block is full to force a new
963 block to be started on the next write */
964 write_sq.rear_size = write_sq.block_size ;
965 write_sq.syncing &= ~2 ; /* clear POST */
966 }
967 }
968 cp = &awacs_tx_cmds[next_frg];
969 st_le16(&cp->req_count, count);
970 st_le16(&cp->xfer_status, 0);
971 st_le16(&cp->command, OUTPUT_MORE + INTR_ALWAYS);
972 /* put a STOP at the end of the queue - but only if we have
973 space for it. This means that, if we under-run and we only
974 have two fragments, we might re-play sound from an existing
975 queued frag. I guess the solution to that is not to set two
976 frags if you are likely to under-run...
977 */
978 if (write_sq.count < write_sq.max_count) {
979 if (++next_frg >= write_sq.max_count)
980 next_frg = 0 ; /* wrap */
981 /* if we get here then we've underrun so we will stop*/
982 st_le16(&awacs_tx_cmds[next_frg].command, DBDMA_STOP);
983 }
984 /* set the dbdma controller going, if it is not already */
985 if (write_sq.active == 0)
986 out_le32(&awacs_txdma->cmdptr, virt_to_bus(cp));
987 (void)in_le32(&awacs_txdma->status);
988 out_le32(&awacs_txdma->control, ((RUN|WAKE) << 16) + (RUN|WAKE));
989 ++write_sq.active;
990 }
991}
992
993static void PMacPlay(void)
994{
995 LOCK();
996 if (!awacs_sleeping) {
997 unsigned long flags;
998
999 spin_lock_irqsave(&dmasound.lock, flags);
1000 __PMacPlay();
1001 spin_unlock_irqrestore(&dmasound.lock, flags);
1002 }
1003 UNLOCK();
1004}
1005
1006static void PMacRecord(void)
1007{
1008 unsigned long flags;
1009
1010 if (read_sq.active)
1011 return;
1012
1013 spin_lock_irqsave(&dmasound.lock, flags);
1014
1015 /* This is all we have to do......Just start it up.
1016 */
1017 out_le32(&awacs_rxdma->control, ((RUN|WAKE) << 16) + (RUN|WAKE));
1018 read_sq.active = 1;
1019
1020 spin_unlock_irqrestore(&dmasound.lock, flags);
1021}
1022
1023/* if the TX status comes up "DEAD" - reported on some Power Computing machines
1024 we need to re-start the dbdma - but from a different physical start address
1025 and with a different transfer length. It would get very messy to do this
1026 with the normal dbdma_cmd blocks - we would have to re-write the buffer start
1027 addresses each time. So, we will keep a single dbdma_cmd block which can be
1028 fiddled with.
1029 When DEAD status is first reported the content of the faulted dbdma block is
1030 copied into the emergency buffer and we note that the buffer is in use.
1031 we then bump the start physical address by the amount that was successfully
1032 output before it died.
1033 On any subsequent DEAD result we just do the bump-ups (we know that we are
1034 already using the emergency dbdma_cmd).
1035 CHECK: this just tries to "do it". It is possible that we should abandon
1036 xfers when the number of residual bytes gets below a certain value - I can
1037 see that this might cause a loop-forever if too small a transfer causes
1038 DEAD status. However this is a TODO for now - we'll see what gets reported.
1039 When we get a successful transfer result with the emergency buffer we just
1040 pretend that it completed using the original dmdma_cmd and carry on. The
1041 'next_cmd' field will already point back to the original loop of blocks.
1042*/
1043
1044static irqreturn_t
1045pmac_awacs_tx_intr(int irq, void *devid, struct pt_regs *regs)
1046{
1047 int i = write_sq.front;
1048 int stat;
1049 int i_nowrap = write_sq.front;
1050 volatile struct dbdma_cmd *cp;
1051 /* != 0 when we are dealing with a DEAD xfer */
1052 static int emergency_in_use;
1053
1054 spin_lock(&dmasound.lock);
1055 while (write_sq.active > 0) { /* we expect to have done something*/
1056 if (emergency_in_use) /* we are dealing with DEAD xfer */
1057 cp = emergency_dbdma_cmd ;
1058 else
1059 cp = &awacs_tx_cmds[i];
1060 stat = ld_le16(&cp->xfer_status);
1061 if (stat & DEAD) {
1062 unsigned short req, res ;
1063 unsigned int phy ;
1064#ifdef DEBUG_DMASOUND
1065printk("dmasound_pmac: tx-irq: xfer died - patching it up...\n") ;
1066#endif
1067 /* to clear DEAD status we must first clear RUN
1068 set it to quiescent to be on the safe side */
1069 (void)in_le32(&awacs_txdma->status);
1070 out_le32(&awacs_txdma->control,
1071 (RUN|PAUSE|FLUSH|WAKE) << 16);
1072 write_sq.died++ ;
1073 if (!emergency_in_use) { /* new problem */
1074 memcpy((void *)emergency_dbdma_cmd, (void *)cp,
1075 sizeof(struct dbdma_cmd));
1076 emergency_in_use = 1;
1077 cp = emergency_dbdma_cmd;
1078 }
1079 /* now bump the values to reflect the amount
1080 we haven't yet shifted */
1081 req = ld_le16(&cp->req_count);
1082 res = ld_le16(&cp->res_count);
1083 phy = ld_le32(&cp->phy_addr);
1084 phy += (req - res);
1085 st_le16(&cp->req_count, res);
1086 st_le16(&cp->res_count, 0);
1087 st_le16(&cp->xfer_status, 0);
1088 st_le32(&cp->phy_addr, phy);
1089 st_le32(&cp->cmd_dep, virt_to_bus(&awacs_tx_cmds[(i+1)%write_sq.max_count]));
1090 st_le16(&cp->command, OUTPUT_MORE | BR_ALWAYS | INTR_ALWAYS);
1091
1092 /* point at our patched up command block */
1093 out_le32(&awacs_txdma->cmdptr, virt_to_bus(cp));
1094 /* we must re-start the controller */
1095 (void)in_le32(&awacs_txdma->status);
1096 /* should complete clearing the DEAD status */
1097 out_le32(&awacs_txdma->control,
1098 ((RUN|WAKE) << 16) + (RUN|WAKE));
1099 break; /* this block is still going */
1100 }
1101 if ((stat & ACTIVE) == 0)
1102 break; /* this frame is still going */
1103 if (emergency_in_use)
1104 emergency_in_use = 0 ; /* done that */
1105 --write_sq.count;
1106 --write_sq.active;
1107 i_nowrap++;
1108 if (++i >= write_sq.max_count)
1109 i = 0;
1110 }
1111
1112 /* if we stopped and we were not sync-ing - then we under-ran */
1113 if( write_sq.syncing == 0 ){
1114 stat = in_le32(&awacs_txdma->status) ;
1115 /* we hit the dbdma_stop */
1116 if( (stat & ACTIVE) == 0 ) write_sq.xruns++ ;
1117 }
1118
1119 /* if we used some data up then wake the writer to supply some more*/
1120 if (i_nowrap != write_sq.front)
1121 WAKE_UP(write_sq.action_queue);
1122 write_sq.front = i;
1123
1124 /* but make sure we funnel what we've already got */\
1125 if (!awacs_sleeping)
1126 __PMacPlay();
1127
1128 /* make the wake-on-empty conditional on syncing */
1129 if (!write_sq.active && (write_sq.syncing & 1))
1130 WAKE_UP(write_sq.sync_queue); /* any time we're empty */
1131 spin_unlock(&dmasound.lock);
1132 return IRQ_HANDLED;
1133}
1134
1135
1136static irqreturn_t
1137pmac_awacs_rx_intr(int irq, void *devid, struct pt_regs *regs)
1138{
1139 int stat ;
1140 /* For some reason on my PowerBook G3, I get one interrupt
1141 * when the interrupt vector is installed (like something is
1142 * pending). This happens before the dbdma is initialized by
1143 * us, so I just check the command pointer and if it is zero,
1144 * just blow it off.
1145 */
1146 if (in_le32(&awacs_rxdma->cmdptr) == 0)
1147 return IRQ_HANDLED;
1148
1149 /* We also want to blow 'em off when shutting down.
1150 */
1151 if (read_sq.active == 0)
1152 return IRQ_HANDLED;
1153
1154 spin_lock(&dmasound.lock);
1155 /* Check multiple buffers in case we were held off from
1156 * interrupt processing for a long time. Geeze, I really hope
1157 * this doesn't happen.
1158 */
1159 while ((stat=awacs_rx_cmds[read_sq.rear].xfer_status)) {
1160
1161 /* if we got a "DEAD" status then just log it for now.
1162 and try to restart dma.
1163 TODO: figure out how best to fix it up
1164 */
1165 if (stat & DEAD){
1166#ifdef DEBUG_DMASOUND
1167printk("dmasound_pmac: rx-irq: DIED - attempting resurection\n");
1168#endif
1169 /* to clear DEAD status we must first clear RUN
1170 set it to quiescent to be on the safe side */
1171 (void)in_le32(&awacs_txdma->status);
1172 out_le32(&awacs_txdma->control,
1173 (RUN|PAUSE|FLUSH|WAKE) << 16);
1174 awacs_rx_cmds[read_sq.rear].xfer_status = 0;
1175 awacs_rx_cmds[read_sq.rear].res_count = 0;
1176 read_sq.died++ ;
1177 (void)in_le32(&awacs_txdma->status);
1178 /* re-start the same block */
1179 out_le32(&awacs_rxdma->cmdptr,
1180 virt_to_bus(&awacs_rx_cmds[read_sq.rear]));
1181 /* we must re-start the controller */
1182 (void)in_le32(&awacs_rxdma->status);
1183 /* should complete clearing the DEAD status */
1184 out_le32(&awacs_rxdma->control,
1185 ((RUN|WAKE) << 16) + (RUN|WAKE));
1186 spin_unlock(&dmasound.lock);
1187 return IRQ_HANDLED; /* try this block again */
1188 }
1189 /* Clear status and move on to next buffer.
1190 */
1191 awacs_rx_cmds[read_sq.rear].xfer_status = 0;
1192 read_sq.rear++;
1193
1194 /* Wrap the buffer ring.
1195 */
1196 if (read_sq.rear >= read_sq.max_active)
1197 read_sq.rear = 0;
1198
1199 /* If we have caught up to the front buffer, bump it.
1200 * This will cause weird (but not fatal) results if the
1201 * read loop is currently using this buffer. The user is
1202 * behind in this case anyway, so weird things are going
1203 * to happen.
1204 */
1205 if (read_sq.rear == read_sq.front) {
1206 read_sq.front++;
1207 read_sq.xruns++ ; /* we overan */
1208 if (read_sq.front >= read_sq.max_active)
1209 read_sq.front = 0;
1210 }
1211 }
1212
1213 WAKE_UP(read_sq.action_queue);
1214 spin_unlock(&dmasound.lock);
1215 return IRQ_HANDLED;
1216}
1217
1218
1219static irqreturn_t
1220pmac_awacs_intr(int irq, void *devid, struct pt_regs *regs)
1221{
1222 int ctrl;
1223 int status;
1224 int r1;
1225
1226 spin_lock(&dmasound.lock);
1227 ctrl = in_le32(&awacs->control);
1228 status = in_le32(&awacs->codec_stat);
1229
1230 if (ctrl & MASK_PORTCHG) {
1231 /* tested on Screamer, should work on others too */
1232 if (awacs_revision == AWACS_SCREAMER) {
1233 if (((status & MASK_HDPCONN) >> 3) && (hdp_connected == 0)) {
1234 hdp_connected = 1;
1235
1236 r1 = awacs_reg[1] | MASK_SPKMUTE;
1237 awacs_reg[1] = r1;
1238 awacs_write(r1 | MASK_ADDR_MUTE);
1239 } else if (((status & MASK_HDPCONN) >> 3 == 0) && (hdp_connected == 1)) {
1240 hdp_connected = 0;
1241
1242 r1 = awacs_reg[1] & ~MASK_SPKMUTE;
1243 awacs_reg[1] = r1;
1244 awacs_write(r1 | MASK_ADDR_MUTE);
1245 }
1246 }
1247 }
1248 if (ctrl & MASK_CNTLERR) {
1249 int err = (in_le32(&awacs->codec_stat) & MASK_ERRCODE) >> 16;
1250 /* CHECK: we just swallow burgundy errors at the moment..*/
1251 if (err != 0 && awacs_revision != AWACS_BURGUNDY)
1252 printk(KERN_ERR "dmasound_pmac: error %x\n", err);
1253 }
1254 /* Writing 1s to the CNTLERR and PORTCHG bits clears them... */
1255 out_le32(&awacs->control, ctrl);
1256 spin_unlock(&dmasound.lock);
1257 return IRQ_HANDLED;
1258}
1259
1260static void
1261awacs_write(int val)
1262{
1263 int count = 300 ;
1264 if (awacs_revision >= AWACS_DACA || !awacs)
1265 return ;
1266
1267 while ((in_le32(&awacs->codec_ctrl) & MASK_NEWECMD) && count--)
1268 udelay(1) ; /* timeout is > 2 samples at lowest rate */
1269 out_le32(&awacs->codec_ctrl, val | (awacs_subframe << 22));
1270 (void)in_le32(&awacs->byteswap);
1271}
1272
1273/* this is called when the beep timer expires... it will be called even
1274 if the beep has been overidden by other sound output.
1275*/
1276static void awacs_nosound(unsigned long xx)
1277{
1278 unsigned long flags;
1279 int count = 600 ; /* > four samples at lowest rate */
1280
1281 spin_lock_irqsave(&dmasound.lock, flags);
1282 if (beep_playing) {
1283 st_le16(&beep_dbdma_cmd->command, DBDMA_STOP);
1284 out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
1285 while ((in_le32(&awacs_txdma->status) & RUN) && count--)
1286 udelay(1);
1287 if (awacs)
1288 awacs_setup_for_beep(-1);
1289 beep_playing = 0;
1290 }
1291 spin_unlock_irqrestore(&dmasound.lock, flags);
1292}
1293
1294/*
1295 * We generate the beep with a single dbdma command that loops a buffer
1296 * forever - without generating interrupts.
1297 *
1298 * So, to stop it you have to stop dma output as per awacs_nosound.
1299 */
1300static int awacs_beep_event(struct input_dev *dev, unsigned int type,
1301 unsigned int code, int hz)
1302{
1303 unsigned long flags;
1304 int beep_speed = 0;
1305 int srate;
1306 int period, ncycles, nsamples;
1307 int i, j, f;
1308 short *p;
1309 static int beep_hz_cache;
1310 static int beep_nsamples_cache;
1311 static int beep_volume_cache;
1312
1313 if (type != EV_SND)
1314 return -1;
1315 switch (code) {
1316 case SND_BELL:
1317 if (hz)
1318 hz = 1000;
1319 break;
1320 case SND_TONE:
1321 break;
1322 default:
1323 return -1;
1324 }
1325
1326 if (beep_buf == NULL)
1327 return -1;
1328
1329 /* quick-hack fix for DACA, Burgundy & Tumbler */
1330
1331 if (awacs_revision >= AWACS_DACA){
1332 srate = 44100 ;
1333 } else {
1334 for (i = 0; i < 8 && awacs_freqs[i] >= BEEP_SRATE; ++i)
1335 if (awacs_freqs_ok[i])
1336 beep_speed = i;
1337 srate = awacs_freqs[beep_speed];
1338 }
1339
1340 if (hz <= srate / BEEP_BUFLEN || hz > srate / 2) {
1341 /* cancel beep currently playing */
1342 awacs_nosound(0);
1343 return 0;
1344 }
1345
1346 spin_lock_irqsave(&dmasound.lock, flags);
1347 if (beep_playing || write_sq.active || beep_buf == NULL) {
1348 spin_unlock_irqrestore(&dmasound.lock, flags);
1349 return -1; /* too hard, sorry :-( */
1350 }
1351 beep_playing = 1;
1352 st_le16(&beep_dbdma_cmd->command, OUTPUT_MORE + BR_ALWAYS);
1353 spin_unlock_irqrestore(&dmasound.lock, flags);
1354
1355 if (hz == beep_hz_cache && beep_vol == beep_volume_cache) {
1356 nsamples = beep_nsamples_cache;
1357 } else {
1358 period = srate * 256 / hz; /* fixed point */
1359 ncycles = BEEP_BUFLEN * 256 / period;
1360 nsamples = (period * ncycles) >> 8;
1361 f = ncycles * 65536 / nsamples;
1362 j = 0;
1363 p = beep_buf;
1364 for (i = 0; i < nsamples; ++i, p += 2) {
1365 p[0] = p[1] = beep_wform[j >> 8] * beep_vol;
1366 j = (j + f) & 0xffff;
1367 }
1368 beep_hz_cache = hz;
1369 beep_volume_cache = beep_vol;
1370 beep_nsamples_cache = nsamples;
1371 }
1372
1373 st_le16(&beep_dbdma_cmd->req_count, nsamples*4);
1374 st_le16(&beep_dbdma_cmd->xfer_status, 0);
1375 st_le32(&beep_dbdma_cmd->cmd_dep, virt_to_bus(beep_dbdma_cmd));
1376 st_le32(&beep_dbdma_cmd->phy_addr, virt_to_bus(beep_buf));
1377 awacs_beep_state = 1;
1378
1379 spin_lock_irqsave(&dmasound.lock, flags);
1380 if (beep_playing) { /* i.e. haven't been terminated already */
1381 int count = 300 ;
1382 out_le32(&awacs_txdma->control, (RUN|WAKE|FLUSH|PAUSE) << 16);
1383 while ((in_le32(&awacs_txdma->status) & RUN) && count--)
1384 udelay(1); /* timeout > 2 samples at lowest rate*/
1385 if (awacs)
1386 awacs_setup_for_beep(beep_speed);
1387 out_le32(&awacs_txdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
1388 (void)in_le32(&awacs_txdma->status);
1389 out_le32(&awacs_txdma->control, RUN | (RUN << 16));
1390 }
1391 spin_unlock_irqrestore(&dmasound.lock, flags);
1392
1393 return 0;
1394}
1395
1396/* used in init and for wake-up */
1397
1398static void
1399load_awacs(void)
1400{
1401 awacs_write(awacs_reg[0] + MASK_ADDR0);
1402 awacs_write(awacs_reg[1] + MASK_ADDR1);
1403 awacs_write(awacs_reg[2] + MASK_ADDR2);
1404 awacs_write(awacs_reg[4] + MASK_ADDR4);
1405
1406 if (awacs_revision == AWACS_SCREAMER) {
1407 awacs_write(awacs_reg[5] + MASK_ADDR5);
1408 msleep(100);
1409 awacs_write(awacs_reg[6] + MASK_ADDR6);
1410 msleep(2);
1411 awacs_write(awacs_reg[1] + MASK_ADDR1);
1412 awacs_write(awacs_reg[7] + MASK_ADDR7);
1413 }
1414 if (awacs) {
1415 if (hw_can_byteswap && (dmasound.hard.format == AFMT_S16_LE))
1416 out_le32(&awacs->byteswap, BS_VAL);
1417 else
1418 out_le32(&awacs->byteswap, 0);
1419 }
1420}
1421
1422#ifdef CONFIG_PMAC_PBOOK
1423/*
1424 * Save state when going to sleep, restore it afterwards.
1425 */
1426/* FIXME: sort out disabling/re-enabling of read stuff as well */
1427static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
1428{
1429 unsigned long flags;
1430
1431 switch (when) {
1432 case PBOOK_SLEEP_NOW:
1433 LOCK();
1434 awacs_sleeping = 1;
1435 /* Tell the rest of the driver we are now going to sleep */
1436 mb();
1437 if (awacs_revision == AWACS_SCREAMER ||
1438 awacs_revision == AWACS_AWACS) {
1439 awacs_reg1_save = awacs_reg[1];
1440 awacs_reg[1] |= MASK_AMUTE | MASK_CMUTE;
1441 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1442 }
1443
1444 PMacSilence();
1445 /* stop rx - if going - a bit of a daft user... but */
1446 out_le32(&awacs_rxdma->control, (RUN|WAKE|FLUSH << 16));
1447 /* deny interrupts */
1448 if (awacs)
1449 disable_irq(awacs_irq);
1450 disable_irq(awacs_tx_irq);
1451 disable_irq(awacs_rx_irq);
1452 /* Chip specific sleep code */
1453 switch (awacs_revision) {
1454 case AWACS_TUMBLER:
1455 case AWACS_SNAPPER:
1456 write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
1457 write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
1458 tas_enter_sleep();
1459 write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
1460 break ;
1461 case AWACS_DACA:
1462 daca_enter_sleep();
1463 break ;
1464 case AWACS_BURGUNDY:
1465 break ;
1466 case AWACS_SCREAMER:
1467 case AWACS_AWACS:
1468 default:
1469 out_le32(&awacs->control, 0x11) ;
1470 break ;
1471 }
1472 /* Disable sound clock */
1473 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 0);
1474 /* According to Darwin, we do that after turning off the sound
1475 * chip clock. All this will have to be cleaned up once we properly
1476 * parse the OF sound-objects
1477 */
1478 if ((machine_is_compatible("PowerBook3,1") ||
1479 machine_is_compatible("PowerBook3,2")) && awacs) {
1480 awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
1481 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1482 msleep(200);
1483 }
1484 break;
1485 case PBOOK_WAKE:
1486 /* Enable sound clock */
1487 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, awacs_node, 0, 1);
1488 if ((machine_is_compatible("PowerBook3,1") ||
1489 machine_is_compatible("PowerBook3,2")) && awacs) {
1490 msleep(100);
1491 awacs_reg[1] &= ~(MASK_PAROUT0 | MASK_PAROUT1);
1492 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1493 msleep(300);
1494 } else
1495 msleep(1000);
1496 /* restore settings */
1497 switch (awacs_revision) {
1498 case AWACS_TUMBLER:
1499 case AWACS_SNAPPER:
1500 write_audio_gpio(gpio_headphone_mute, gpio_headphone_mute_pol);
1501 write_audio_gpio(gpio_amp_mute, gpio_amp_mute_pol);
1502 write_audio_gpio(gpio_audio_reset, gpio_audio_reset_pol);
1503 msleep(100);
1504 write_audio_gpio(gpio_audio_reset, !gpio_audio_reset_pol);
1505 msleep(150);
1506 tas_leave_sleep(); /* Stub for now */
1507 headphone_intr(0,NULL,NULL);
1508 break;
1509 case AWACS_DACA:
1510 msleep(10); /* Check this !!! */
1511 daca_leave_sleep();
1512 break ; /* dont know how yet */
1513 case AWACS_BURGUNDY:
1514 break ;
1515 case AWACS_SCREAMER:
1516 case AWACS_AWACS:
1517 default:
1518 load_awacs() ;
1519 break ;
1520 }
1521 /* Recalibrate chip */
1522 if (awacs_revision == AWACS_SCREAMER && awacs)
1523 awacs_recalibrate();
1524 /* Make sure dma is stopped */
1525 PMacSilence();
1526 if (awacs)
1527 enable_irq(awacs_irq);
1528 enable_irq(awacs_tx_irq);
1529 enable_irq(awacs_rx_irq);
1530 if (awacs) {
1531 /* OK, allow ints back again */
1532 out_le32(&awacs->control, MASK_IEPC
1533 | (awacs_rate_index << 8) | 0x11
1534 | (awacs_revision < AWACS_DACA ? MASK_IEE: 0));
1535 }
1536 if (macio_base && is_pbook_g3) {
1537 /* FIXME: should restore the setup we had...*/
1538 out_8(macio_base + 0x37, 3);
1539 } else if (is_pbook_3X00) {
1540 in_8(latch_base + 0x190);
1541 }
1542 /* Remove mute */
1543 if (awacs_revision == AWACS_SCREAMER ||
1544 awacs_revision == AWACS_AWACS) {
1545 awacs_reg[1] = awacs_reg1_save;
1546 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1547 }
1548 awacs_sleeping = 0;
1549 /* Resume pending sounds. */
1550 /* we don't try to restart input... */
1551 spin_lock_irqsave(&dmasound.lock, flags);
1552 __PMacPlay();
1553 spin_unlock_irqrestore(&dmasound.lock, flags);
1554 UNLOCK();
1555 }
1556 return PBOOK_SLEEP_OK;
1557}
1558#endif /* CONFIG_PMAC_PBOOK */
1559
1560
1561/* All the burgundy functions: */
1562
1563/* Waits for busy flag to clear */
1564inline static void
1565awacs_burgundy_busy_wait(void)
1566{
1567 int count = 50; /* > 2 samples at 44k1 */
1568 while ((in_le32(&awacs->codec_ctrl) & MASK_NEWECMD) && count--)
1569 udelay(1) ;
1570}
1571
1572inline static void
1573awacs_burgundy_extend_wait(void)
1574{
1575 int count = 50 ; /* > 2 samples at 44k1 */
1576 while ((!(in_le32(&awacs->codec_stat) & MASK_EXTEND)) && count--)
1577 udelay(1) ;
1578 count = 50;
1579 while ((in_le32(&awacs->codec_stat) & MASK_EXTEND) && count--)
1580 udelay(1);
1581}
1582
1583static void
1584awacs_burgundy_wcw(unsigned addr, unsigned val)
1585{
1586 out_le32(&awacs->codec_ctrl, addr + 0x200c00 + (val & 0xff));
1587 awacs_burgundy_busy_wait();
1588 out_le32(&awacs->codec_ctrl, addr + 0x200d00 +((val>>8) & 0xff));
1589 awacs_burgundy_busy_wait();
1590 out_le32(&awacs->codec_ctrl, addr + 0x200e00 +((val>>16) & 0xff));
1591 awacs_burgundy_busy_wait();
1592 out_le32(&awacs->codec_ctrl, addr + 0x200f00 +((val>>24) & 0xff));
1593 awacs_burgundy_busy_wait();
1594}
1595
1596static unsigned
1597awacs_burgundy_rcw(unsigned addr)
1598{
1599 unsigned val = 0;
1600 unsigned long flags;
1601
1602 /* should have timeouts here */
1603 spin_lock_irqsave(&dmasound.lock, flags);
1604
1605 out_le32(&awacs->codec_ctrl, addr + 0x100000);
1606 awacs_burgundy_busy_wait();
1607 awacs_burgundy_extend_wait();
1608 val += (in_le32(&awacs->codec_stat) >> 4) & 0xff;
1609
1610 out_le32(&awacs->codec_ctrl, addr + 0x100100);
1611 awacs_burgundy_busy_wait();
1612 awacs_burgundy_extend_wait();
1613 val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<8;
1614
1615 out_le32(&awacs->codec_ctrl, addr + 0x100200);
1616 awacs_burgundy_busy_wait();
1617 awacs_burgundy_extend_wait();
1618 val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<16;
1619
1620 out_le32(&awacs->codec_ctrl, addr + 0x100300);
1621 awacs_burgundy_busy_wait();
1622 awacs_burgundy_extend_wait();
1623 val += ((in_le32(&awacs->codec_stat)>>4) & 0xff) <<24;
1624
1625 spin_unlock_irqrestore(&dmasound.lock, flags);
1626
1627 return val;
1628}
1629
1630
1631static void
1632awacs_burgundy_wcb(unsigned addr, unsigned val)
1633{
1634 out_le32(&awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
1635 awacs_burgundy_busy_wait();
1636}
1637
1638static unsigned
1639awacs_burgundy_rcb(unsigned addr)
1640{
1641 unsigned val = 0;
1642 unsigned long flags;
1643
1644 /* should have timeouts here */
1645 spin_lock_irqsave(&dmasound.lock, flags);
1646
1647 out_le32(&awacs->codec_ctrl, addr + 0x100000);
1648 awacs_burgundy_busy_wait();
1649 awacs_burgundy_extend_wait();
1650 val += (in_le32(&awacs->codec_stat) >> 4) & 0xff;
1651
1652 spin_unlock_irqrestore(&dmasound.lock, flags);
1653
1654 return val;
1655}
1656
1657static int
1658awacs_burgundy_check(void)
1659{
1660 /* Checks to see the chip is alive and kicking */
1661 int error = in_le32(&awacs->codec_ctrl) & MASK_ERRCODE;
1662
1663 return error == 0xf0000;
1664}
1665
1666static int
1667awacs_burgundy_init(void)
1668{
1669 if (awacs_burgundy_check()) {
1670 printk(KERN_WARNING "dmasound_pmac: burgundy not working :-(\n");
1671 return 1;
1672 }
1673
1674 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_OUTPUTENABLES,
1675 DEF_BURGUNDY_OUTPUTENABLES);
1676 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
1677 DEF_BURGUNDY_MORE_OUTPUTENABLES);
1678 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_OUTPUTSELECTS,
1679 DEF_BURGUNDY_OUTPUTSELECTS);
1680
1681 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_INPSEL21,
1682 DEF_BURGUNDY_INPSEL21);
1683 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_INPSEL3,
1684 DEF_BURGUNDY_INPSEL3);
1685 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINCD,
1686 DEF_BURGUNDY_GAINCD);
1687 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINLINE,
1688 DEF_BURGUNDY_GAINLINE);
1689 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINMIC,
1690 DEF_BURGUNDY_GAINMIC);
1691 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINMODEM,
1692 DEF_BURGUNDY_GAINMODEM);
1693
1694 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER,
1695 DEF_BURGUNDY_ATTENSPEAKER);
1696 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENLINEOUT,
1697 DEF_BURGUNDY_ATTENLINEOUT);
1698 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENHP,
1699 DEF_BURGUNDY_ATTENHP);
1700
1701 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_MASTER_VOLUME,
1702 DEF_BURGUNDY_MASTER_VOLUME);
1703 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLCD,
1704 DEF_BURGUNDY_VOLCD);
1705 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLLINE,
1706 DEF_BURGUNDY_VOLLINE);
1707 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLMIC,
1708 DEF_BURGUNDY_VOLMIC);
1709 return 0;
1710}
1711
1712static void
1713awacs_burgundy_write_volume(unsigned address, int volume)
1714{
1715 int hardvolume,lvolume,rvolume;
1716
1717 lvolume = (volume & 0xff) ? (volume & 0xff) + 155 : 0;
1718 rvolume = ((volume >>8)&0xff) ? ((volume >> 8)&0xff ) + 155 : 0;
1719
1720 hardvolume = lvolume + (rvolume << 16);
1721
1722 awacs_burgundy_wcw(address, hardvolume);
1723}
1724
1725static int
1726awacs_burgundy_read_volume(unsigned address)
1727{
1728 int softvolume,wvolume;
1729
1730 wvolume = awacs_burgundy_rcw(address);
1731
1732 softvolume = (wvolume & 0xff) - 155;
1733 softvolume += (((wvolume >> 16) & 0xff) - 155)<<8;
1734
1735 return softvolume > 0 ? softvolume : 0;
1736}
1737
1738static int
1739awacs_burgundy_read_mvolume(unsigned address)
1740{
1741 int lvolume,rvolume,wvolume;
1742
1743 wvolume = awacs_burgundy_rcw(address);
1744
1745 wvolume &= 0xffff;
1746
1747 rvolume = (wvolume & 0xff) - 155;
1748 lvolume = ((wvolume & 0xff00)>>8) - 155;
1749
1750 return lvolume + (rvolume << 8);
1751}
1752
1753static void
1754awacs_burgundy_write_mvolume(unsigned address, int volume)
1755{
1756 int lvolume,rvolume,hardvolume;
1757
1758 lvolume = (volume &0xff) ? (volume & 0xff) + 155 :0;
1759 rvolume = ((volume >>8) & 0xff) ? (volume >> 8) + 155 :0;
1760
1761 hardvolume = lvolume + (rvolume << 8);
1762 hardvolume += (hardvolume << 16);
1763
1764 awacs_burgundy_wcw(address, hardvolume);
1765}
1766
1767/* End burgundy functions */
1768
1769/* Set up output volumes on machines with the 'perch/whisper' extension card.
1770 * this has an SGS i2c chip (7433) which is accessed using the cuda.
1771 *
1772 * TODO: split this out and make use of the other parts of the SGS chip to
1773 * do Bass, Treble etc.
1774 */
1775
1776static void
1777awacs_enable_amp(int spkr_vol)
1778{
1779#ifdef CONFIG_ADB_CUDA
1780 struct adb_request req;
1781
1782 if (sys_ctrler != SYS_CTRLER_CUDA)
1783 return;
1784
1785 /* turn on headphones */
1786 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
1787 0x8a, 4, 0);
1788 while (!req.complete) cuda_poll();
1789 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
1790 0x8a, 6, 0);
1791 while (!req.complete) cuda_poll();
1792
1793 /* turn on speaker */
1794 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
1795 0x8a, 3, (100 - (spkr_vol & 0xff)) * 32 / 100);
1796 while (!req.complete) cuda_poll();
1797 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
1798 0x8a, 5, (100 - ((spkr_vol >> 8) & 0xff)) * 32 / 100);
1799 while (!req.complete) cuda_poll();
1800
1801 cuda_request(&req, NULL, 5, CUDA_PACKET,
1802 CUDA_GET_SET_IIC, 0x8a, 1, 0x29);
1803 while (!req.complete) cuda_poll();
1804#endif /* CONFIG_ADB_CUDA */
1805}
1806
1807
1808/*** Mid level stuff *********************************************************/
1809
1810
1811/*
1812 * /dev/mixer abstraction
1813 */
1814
1815static void do_line_lev(int data)
1816{
1817 line_lev = data ;
1818 awacs_reg[0] &= ~MASK_MUX_AUDIN;
1819 if ((data & 0xff) >= 50)
1820 awacs_reg[0] |= MASK_MUX_AUDIN;
1821 awacs_write(MASK_ADDR0 | awacs_reg[0]);
1822}
1823
1824static void do_ip_gain(int data)
1825{
1826 ip_gain = data ;
1827 data &= 0xff;
1828 awacs_reg[0] &= ~MASK_GAINLINE;
1829 if (awacs_revision == AWACS_SCREAMER) {
1830 awacs_reg[6] &= ~MASK_MIC_BOOST ;
1831 if (data >= 33) {
1832 awacs_reg[0] |= MASK_GAINLINE;
1833 if( data >= 66)
1834 awacs_reg[6] |= MASK_MIC_BOOST ;
1835 }
1836 awacs_write(MASK_ADDR6 | awacs_reg[6]) ;
1837 } else {
1838 if (data >= 50)
1839 awacs_reg[0] |= MASK_GAINLINE;
1840 }
1841 awacs_write(MASK_ADDR0 | awacs_reg[0]);
1842}
1843
1844static void do_mic_lev(int data)
1845{
1846 mic_lev = data ;
1847 data &= 0xff;
1848 awacs_reg[0] &= ~MASK_MUX_MIC;
1849 if (data >= 50)
1850 awacs_reg[0] |= MASK_MUX_MIC;
1851 awacs_write(MASK_ADDR0 | awacs_reg[0]);
1852}
1853
1854static void do_cd_lev(int data)
1855{
1856 cd_lev = data ;
1857 awacs_reg[0] &= ~MASK_MUX_CD;
1858 if ((data & 0xff) >= 50)
1859 awacs_reg[0] |= MASK_MUX_CD;
1860 awacs_write(MASK_ADDR0 | awacs_reg[0]);
1861}
1862
1863static void do_rec_lev(int data)
1864{
1865 int left, right ;
1866 rec_lev = data ;
1867 /* need to fudge this to use the volume setter routine */
1868 left = 100 - (data & 0xff) ; if( left < 0 ) left = 0 ;
1869 right = 100 - ((data >> 8) & 0xff) ; if( right < 0 ) right = 0 ;
1870 left |= (right << 8 );
1871 left = awacs_volume_setter(left, 0, 0, 4);
1872}
1873
1874static void do_passthru_vol(int data)
1875{
1876 passthru_vol = data ;
1877 awacs_reg[1] &= ~MASK_LOOPTHRU;
1878 if (awacs_revision == AWACS_SCREAMER) {
1879 if( data ) { /* switch it on for non-zero */
1880 awacs_reg[1] |= MASK_LOOPTHRU;
1881 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1882 }
1883 data = awacs_volume_setter(data, 5, 0, 6) ;
1884 } else {
1885 if ((data & 0xff) >= 50)
1886 awacs_reg[1] |= MASK_LOOPTHRU;
1887 awacs_write(MASK_ADDR1 | awacs_reg[1]);
1888 data = (awacs_reg[1] & MASK_LOOPTHRU)? 100: 0;
1889 }
1890}
1891
1892static int awacs_mixer_ioctl(u_int cmd, u_long arg)
1893{
1894 int data;
1895 int rc;
1896
1897 switch (cmd) {
1898 case SOUND_MIXER_READ_CAPS:
1899 /* say we will allow multiple inputs? prob. wrong
1900 so I'm switching it to single */
1901 return IOCTL_OUT(arg, 1);
1902 case SOUND_MIXER_READ_DEVMASK:
1903 data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER
1904 | SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD
1905 | SOUND_MASK_IGAIN | SOUND_MASK_RECLEV
1906 | SOUND_MASK_ALTPCM
1907 | SOUND_MASK_MONITOR;
1908 rc = IOCTL_OUT(arg, data);
1909 break;
1910 case SOUND_MIXER_READ_RECMASK:
1911 data = SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD;
1912 rc = IOCTL_OUT(arg, data);
1913 break;
1914 case SOUND_MIXER_READ_RECSRC:
1915 data = 0;
1916 if (awacs_reg[0] & MASK_MUX_AUDIN)
1917 data |= SOUND_MASK_LINE;
1918 if (awacs_reg[0] & MASK_MUX_MIC)
1919 data |= SOUND_MASK_MIC;
1920 if (awacs_reg[0] & MASK_MUX_CD)
1921 data |= SOUND_MASK_CD;
1922 rc = IOCTL_OUT(arg, data);
1923 break;
1924 case SOUND_MIXER_WRITE_RECSRC:
1925 IOCTL_IN(arg, data);
1926 data &= (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD);
1927 awacs_reg[0] &= ~(MASK_MUX_CD | MASK_MUX_MIC
1928 | MASK_MUX_AUDIN);
1929 if (data & SOUND_MASK_LINE)
1930 awacs_reg[0] |= MASK_MUX_AUDIN;
1931 if (data & SOUND_MASK_MIC)
1932 awacs_reg[0] |= MASK_MUX_MIC;
1933 if (data & SOUND_MASK_CD)
1934 awacs_reg[0] |= MASK_MUX_CD;
1935 awacs_write(awacs_reg[0] | MASK_ADDR0);
1936 rc = IOCTL_OUT(arg, data);
1937 break;
1938 case SOUND_MIXER_READ_STEREODEVS:
1939 data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER| SOUND_MASK_RECLEV ;
1940 if (awacs_revision == AWACS_SCREAMER)
1941 data |= SOUND_MASK_MONITOR ;
1942 rc = IOCTL_OUT(arg, data);
1943 break;
1944 case SOUND_MIXER_WRITE_VOLUME:
1945 IOCTL_IN(arg, data);
1946 line_vol = data ;
1947 awacs_volume_setter(data, 2, 0, 6);
1948 /* fall through */
1949 case SOUND_MIXER_READ_VOLUME:
1950 rc = IOCTL_OUT(arg, line_vol);
1951 break;
1952 case SOUND_MIXER_WRITE_SPEAKER:
1953 IOCTL_IN(arg, data);
1954 spk_vol = data ;
1955 if (has_perch)
1956 awacs_enable_amp(data);
1957 else
1958 (void)awacs_volume_setter(data, 4, MASK_CMUTE, 6);
1959 /* fall though */
1960 case SOUND_MIXER_READ_SPEAKER:
1961 rc = IOCTL_OUT(arg, spk_vol);
1962 break;
1963 case SOUND_MIXER_WRITE_ALTPCM: /* really bell volume */
1964 IOCTL_IN(arg, data);
1965 beep_vol = data & 0xff;
1966 /* fall through */
1967 case SOUND_MIXER_READ_ALTPCM:
1968 rc = IOCTL_OUT(arg, beep_vol);
1969 break;
1970 case SOUND_MIXER_WRITE_LINE:
1971 IOCTL_IN(arg, data);
1972 do_line_lev(data) ;
1973 /* fall through */
1974 case SOUND_MIXER_READ_LINE:
1975 rc = IOCTL_OUT(arg, line_lev);
1976 break;
1977 case SOUND_MIXER_WRITE_IGAIN:
1978 IOCTL_IN(arg, data);
1979 do_ip_gain(data) ;
1980 /* fall through */
1981 case SOUND_MIXER_READ_IGAIN:
1982 rc = IOCTL_OUT(arg, ip_gain);
1983 break;
1984 case SOUND_MIXER_WRITE_MIC:
1985 IOCTL_IN(arg, data);
1986 do_mic_lev(data);
1987 /* fall through */
1988 case SOUND_MIXER_READ_MIC:
1989 rc = IOCTL_OUT(arg, mic_lev);
1990 break;
1991 case SOUND_MIXER_WRITE_CD:
1992 IOCTL_IN(arg, data);
1993 do_cd_lev(data);
1994 /* fall through */
1995 case SOUND_MIXER_READ_CD:
1996 rc = IOCTL_OUT(arg, cd_lev);
1997 break;
1998 case SOUND_MIXER_WRITE_RECLEV:
1999 IOCTL_IN(arg, data);
2000 do_rec_lev(data) ;
2001 /* fall through */
2002 case SOUND_MIXER_READ_RECLEV:
2003 rc = IOCTL_OUT(arg, rec_lev);
2004 break;
2005 case MIXER_WRITE(SOUND_MIXER_MONITOR):
2006 IOCTL_IN(arg, data);
2007 do_passthru_vol(data) ;
2008 /* fall through */
2009 case MIXER_READ(SOUND_MIXER_MONITOR):
2010 rc = IOCTL_OUT(arg, passthru_vol);
2011 break;
2012 default:
2013 rc = -EINVAL;
2014 }
2015
2016 return rc;
2017}
2018
2019static void awacs_mixer_init(void)
2020{
2021 awacs_volume_setter(line_vol, 2, 0, 6);
2022 if (has_perch)
2023 awacs_enable_amp(spk_vol);
2024 else
2025 (void)awacs_volume_setter(spk_vol, 4, MASK_CMUTE, 6);
2026 do_line_lev(line_lev) ;
2027 do_ip_gain(ip_gain) ;
2028 do_mic_lev(mic_lev) ;
2029 do_cd_lev(cd_lev) ;
2030 do_rec_lev(rec_lev) ;
2031 do_passthru_vol(passthru_vol) ;
2032}
2033
2034static int burgundy_mixer_ioctl(u_int cmd, u_long arg)
2035{
2036 int data;
2037 int rc;
2038
2039 /* We are, we are, we are... Burgundy or better */
2040 switch(cmd) {
2041 case SOUND_MIXER_READ_DEVMASK:
2042 data = SOUND_MASK_VOLUME | SOUND_MASK_CD |
2043 SOUND_MASK_LINE | SOUND_MASK_MIC |
2044 SOUND_MASK_SPEAKER | SOUND_MASK_ALTPCM;
2045 rc = IOCTL_OUT(arg, data);
2046 break;
2047 case SOUND_MIXER_READ_RECMASK:
2048 data = SOUND_MASK_LINE | SOUND_MASK_MIC
2049 | SOUND_MASK_CD;
2050 rc = IOCTL_OUT(arg, data);
2051 break;
2052 case SOUND_MIXER_READ_RECSRC:
2053 data = 0;
2054 if (awacs_reg[0] & MASK_MUX_AUDIN)
2055 data |= SOUND_MASK_LINE;
2056 if (awacs_reg[0] & MASK_MUX_MIC)
2057 data |= SOUND_MASK_MIC;
2058 if (awacs_reg[0] & MASK_MUX_CD)
2059 data |= SOUND_MASK_CD;
2060 rc = IOCTL_OUT(arg, data);
2061 break;
2062 case SOUND_MIXER_WRITE_RECSRC:
2063 IOCTL_IN(arg, data);
2064 data &= (SOUND_MASK_LINE
2065 | SOUND_MASK_MIC | SOUND_MASK_CD);
2066 awacs_reg[0] &= ~(MASK_MUX_CD | MASK_MUX_MIC
2067 | MASK_MUX_AUDIN);
2068 if (data & SOUND_MASK_LINE)
2069 awacs_reg[0] |= MASK_MUX_AUDIN;
2070 if (data & SOUND_MASK_MIC)
2071 awacs_reg[0] |= MASK_MUX_MIC;
2072 if (data & SOUND_MASK_CD)
2073 awacs_reg[0] |= MASK_MUX_CD;
2074 awacs_write(awacs_reg[0] | MASK_ADDR0);
2075 rc = IOCTL_OUT(arg, data);
2076 break;
2077 case SOUND_MIXER_READ_STEREODEVS:
2078 data = SOUND_MASK_VOLUME | SOUND_MASK_SPEAKER
2079 | SOUND_MASK_RECLEV | SOUND_MASK_CD
2080 | SOUND_MASK_LINE;
2081 rc = IOCTL_OUT(arg, data);
2082 break;
2083 case SOUND_MIXER_READ_CAPS:
2084 rc = IOCTL_OUT(arg, 0);
2085 break;
2086 case SOUND_MIXER_WRITE_VOLUME:
2087 IOCTL_IN(arg, data);
2088 awacs_burgundy_write_mvolume(MASK_ADDR_BURGUNDY_MASTER_VOLUME, data);
2089 /* Fall through */
2090 case SOUND_MIXER_READ_VOLUME:
2091 rc = IOCTL_OUT(arg, awacs_burgundy_read_mvolume(MASK_ADDR_BURGUNDY_MASTER_VOLUME));
2092 break;
2093 case SOUND_MIXER_WRITE_SPEAKER:
2094 IOCTL_IN(arg, data);
2095 if (!(data & 0xff)) {
2096 /* Mute the left speaker */
2097 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
2098 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) & ~0x2);
2099 } else {
2100 /* Unmute the left speaker */
2101 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
2102 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) | 0x2);
2103 }
2104 if (!(data & 0xff00)) {
2105 /* Mute the right speaker */
2106 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
2107 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) & ~0x4);
2108 } else {
2109 /* Unmute the right speaker */
2110 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
2111 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES) | 0x4);
2112 }
2113
2114 data = (((data&0xff)*16)/100 > 0xf ? 0xf :
2115 (((data&0xff)*16)/100)) +
2116 ((((data>>8)*16)/100 > 0xf ? 0xf :
2117 ((((data>>8)*16)/100)))<<4);
2118
2119 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER, ~data);
2120 /* Fall through */
2121 case SOUND_MIXER_READ_SPEAKER:
2122 data = awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER);
2123 data = (((data & 0xf)*100)/16) + ((((data>>4)*100)/16)<<8);
2124 rc = IOCTL_OUT(arg, (~data) & 0x0000ffff);
2125 break;
2126 case SOUND_MIXER_WRITE_ALTPCM: /* really bell volume */
2127 IOCTL_IN(arg, data);
2128 beep_vol = data & 0xff;
2129 /* fall through */
2130 case SOUND_MIXER_READ_ALTPCM:
2131 rc = IOCTL_OUT(arg, beep_vol);
2132 break;
2133 case SOUND_MIXER_WRITE_LINE:
2134 IOCTL_IN(arg, data);
2135 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLLINE, data);
2136
2137 /* fall through */
2138 case SOUND_MIXER_READ_LINE:
2139 data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLLINE);
2140 rc = IOCTL_OUT(arg, data);
2141 break;
2142 case SOUND_MIXER_WRITE_MIC:
2143 IOCTL_IN(arg, data);
2144 /* Mic is mono device */
2145 data = (data << 8) + (data << 24);
2146 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLMIC, data);
2147 /* fall through */
2148 case SOUND_MIXER_READ_MIC:
2149 data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLMIC);
2150 data <<= 24;
2151 rc = IOCTL_OUT(arg, data);
2152 break;
2153 case SOUND_MIXER_WRITE_CD:
2154 IOCTL_IN(arg, data);
2155 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLCD, data);
2156 /* fall through */
2157 case SOUND_MIXER_READ_CD:
2158 data = awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLCD);
2159 rc = IOCTL_OUT(arg, data);
2160 break;
2161 case SOUND_MIXER_WRITE_RECLEV:
2162 IOCTL_IN(arg, data);
2163 data = awacs_volume_setter(data, 0, 0, 4);
2164 rc = IOCTL_OUT(arg, data);
2165 break;
2166 case SOUND_MIXER_READ_RECLEV:
2167 data = awacs_get_volume(awacs_reg[0], 4);
2168 rc = IOCTL_OUT(arg, data);
2169 break;
2170 case SOUND_MIXER_OUTMASK:
2171 case SOUND_MIXER_OUTSRC:
2172 default:
2173 rc = -EINVAL;
2174 }
2175
2176 return rc;
2177}
2178
2179static int daca_mixer_ioctl(u_int cmd, u_long arg)
2180{
2181 int data;
2182 int rc;
2183
2184 /* And the DACA's no genius either! */
2185
2186 switch(cmd) {
2187 case SOUND_MIXER_READ_DEVMASK:
2188 data = SOUND_MASK_VOLUME;
2189 rc = IOCTL_OUT(arg, data);
2190 break;
2191 case SOUND_MIXER_READ_RECMASK:
2192 data = 0;
2193 rc = IOCTL_OUT(arg, data);
2194 break;
2195 case SOUND_MIXER_READ_RECSRC:
2196 data = 0;
2197 rc = IOCTL_OUT(arg, data);
2198 break;
2199 case SOUND_MIXER_WRITE_RECSRC:
2200 IOCTL_IN(arg, data);
2201 data =0;
2202 rc = IOCTL_OUT(arg, data);
2203 break;
2204 case SOUND_MIXER_READ_STEREODEVS:
2205 data = SOUND_MASK_VOLUME;
2206 rc = IOCTL_OUT(arg, data);
2207 break;
2208 case SOUND_MIXER_READ_CAPS:
2209 rc = IOCTL_OUT(arg, 0);
2210 break;
2211 case SOUND_MIXER_WRITE_VOLUME:
2212 IOCTL_IN(arg, data);
2213 daca_set_volume(data, data);
2214 /* Fall through */
2215 case SOUND_MIXER_READ_VOLUME:
2216 daca_get_volume(& data, &data);
2217 rc = IOCTL_OUT(arg, data);
2218 break;
2219 case SOUND_MIXER_OUTMASK:
2220 case SOUND_MIXER_OUTSRC:
2221 default:
2222 rc = -EINVAL;
2223 }
2224 return rc;
2225}
2226
2227static int PMacMixerIoctl(u_int cmd, u_long arg)
2228{
2229 int rc;
2230
2231 /* Different IOCTLS for burgundy and, eventually, DACA & Tumbler */
2232
2233 TRY_LOCK();
2234
2235 switch (awacs_revision){
2236 case AWACS_BURGUNDY:
2237 rc = burgundy_mixer_ioctl(cmd, arg);
2238 break ;
2239 case AWACS_DACA:
2240 rc = daca_mixer_ioctl(cmd, arg);
2241 break;
2242 case AWACS_TUMBLER:
2243 case AWACS_SNAPPER:
2244 rc = tas_mixer_ioctl(cmd, arg);
2245 break ;
2246 default: /* ;-)) */
2247 rc = awacs_mixer_ioctl(cmd, arg);
2248 }
2249
2250 UNLOCK();
2251
2252 return rc;
2253}
2254
2255static void PMacMixerInit(void)
2256{
2257 switch (awacs_revision) {
2258 case AWACS_TUMBLER:
2259 printk("AE-Init tumbler mixer\n");
2260 break ;
2261 case AWACS_SNAPPER:
2262 printk("AE-Init snapper mixer\n");
2263 break ;
2264 case AWACS_DACA:
2265 case AWACS_BURGUNDY:
2266 break ; /* don't know yet */
2267 case AWACS_AWACS:
2268 case AWACS_SCREAMER:
2269 default:
2270 awacs_mixer_init() ;
2271 break ;
2272 }
2273}
2274
2275/* Write/Read sq setup functions:
2276 Check to see if we have enough (or any) dbdma cmd buffers for the
2277 user's fragment settings. If not, allocate some. If this fails we will
2278 point at the beep buffer - as an emergency provision - to stop dma tromping
2279 on some random bit of memory (if someone lets it go anyway).
2280 The command buffers are then set up to point to the fragment buffers
2281 (allocated elsewhere). We need n+1 commands the last of which holds
2282 a NOP + loop to start.
2283*/
2284
2285static int PMacWriteSqSetup(void)
2286{
2287 int i, count = 600 ;
2288 volatile struct dbdma_cmd *cp;
2289
2290 LOCK();
2291
2292 /* stop the controller from doing any output - if it isn't already.
2293 it _should_ be before this is called anyway */
2294
2295 out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
2296 while ((in_le32(&awacs_txdma->status) & RUN) && count--)
2297 udelay(1);
2298#ifdef DEBUG_DMASOUND
2299if (count <= 0)
2300 printk("dmasound_pmac: write sq setup: timeout waiting for dma to stop\n");
2301#endif
2302
2303 if ((write_sq.max_count + 1) > number_of_tx_cmd_buffers) {
2304 if (awacs_tx_cmd_space)
2305 kfree(awacs_tx_cmd_space);
2306 number_of_tx_cmd_buffers = 0;
2307
2308 /* we need nbufs + 1 (for the loop) and we should request + 1
2309 again because the DBDMA_ALIGN might pull the start up by up
2310 to sizeof(struct dbdma_cmd) - 4.
2311 */
2312
2313 awacs_tx_cmd_space = kmalloc
2314 ((write_sq.max_count + 1 + 1) * sizeof(struct dbdma_cmd),
2315 GFP_KERNEL);
2316 if (awacs_tx_cmd_space == NULL) {
2317 /* don't leave it dangling - nasty but better than a
2318 random address */
2319 out_le32(&awacs_txdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
2320 printk(KERN_ERR
2321 "dmasound_pmac: can't allocate dbdma cmd buffers"
2322 ", driver disabled\n");
2323 UNLOCK();
2324 return -ENOMEM;
2325 }
2326 awacs_tx_cmds = (volatile struct dbdma_cmd *)
2327 DBDMA_ALIGN(awacs_tx_cmd_space);
2328 number_of_tx_cmd_buffers = write_sq.max_count + 1;
2329 }
2330
2331 cp = awacs_tx_cmds;
2332 memset((void *)cp, 0, (write_sq.max_count+1) * sizeof(struct dbdma_cmd));
2333 for (i = 0; i < write_sq.max_count; ++i, ++cp) {
2334 st_le32(&cp->phy_addr, virt_to_bus(write_sq.buffers[i]));
2335 }
2336 st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS);
2337 st_le32(&cp->cmd_dep, virt_to_bus(awacs_tx_cmds));
2338 /* point the controller at the command stack - ready to go */
2339 out_le32(&awacs_txdma->cmdptr, virt_to_bus(awacs_tx_cmds));
2340 UNLOCK();
2341 return 0;
2342}
2343
2344static int PMacReadSqSetup(void)
2345{
2346 int i, count = 600;
2347 volatile struct dbdma_cmd *cp;
2348
2349 LOCK();
2350
2351 /* stop the controller from doing any input - if it isn't already.
2352 it _should_ be before this is called anyway */
2353
2354 out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
2355 while ((in_le32(&awacs_rxdma->status) & RUN) && count--)
2356 udelay(1);
2357#ifdef DEBUG_DMASOUND
2358if (count <= 0)
2359 printk("dmasound_pmac: read sq setup: timeout waiting for dma to stop\n");
2360#endif
2361
2362 if ((read_sq.max_count+1) > number_of_rx_cmd_buffers ) {
2363 if (awacs_rx_cmd_space)
2364 kfree(awacs_rx_cmd_space);
2365 number_of_rx_cmd_buffers = 0;
2366
2367 /* we need nbufs + 1 (for the loop) and we should request + 1 again
2368 because the DBDMA_ALIGN might pull the start up by up to
2369 sizeof(struct dbdma_cmd) - 4 (assuming kmalloc aligns 32 bits).
2370 */
2371
2372 awacs_rx_cmd_space = kmalloc
2373 ((read_sq.max_count + 1 + 1) * sizeof(struct dbdma_cmd),
2374 GFP_KERNEL);
2375 if (awacs_rx_cmd_space == NULL) {
2376 /* don't leave it dangling - nasty but better than a
2377 random address */
2378 out_le32(&awacs_rxdma->cmdptr, virt_to_bus(beep_dbdma_cmd));
2379 printk(KERN_ERR
2380 "dmasound_pmac: can't allocate dbdma cmd buffers"
2381 ", driver disabled\n");
2382 UNLOCK();
2383 return -ENOMEM;
2384 }
2385 awacs_rx_cmds = (volatile struct dbdma_cmd *)
2386 DBDMA_ALIGN(awacs_rx_cmd_space);
2387 number_of_rx_cmd_buffers = read_sq.max_count + 1 ;
2388 }
2389 cp = awacs_rx_cmds;
2390 memset((void *)cp, 0, (read_sq.max_count+1) * sizeof(struct dbdma_cmd));
2391
2392 /* Set dma buffers up in a loop */
2393 for (i = 0; i < read_sq.max_count; i++,cp++) {
2394 st_le32(&cp->phy_addr, virt_to_bus(read_sq.buffers[i]));
2395 st_le16(&cp->command, INPUT_MORE + INTR_ALWAYS);
2396 st_le16(&cp->req_count, read_sq.block_size);
2397 st_le16(&cp->xfer_status, 0);
2398 }
2399
2400 /* The next two lines make the thing loop around.
2401 */
2402 st_le16(&cp->command, DBDMA_NOP + BR_ALWAYS);
2403 st_le32(&cp->cmd_dep, virt_to_bus(awacs_rx_cmds));
2404 /* point the controller at the command stack - ready to go */
2405 out_le32(&awacs_rxdma->cmdptr, virt_to_bus(awacs_rx_cmds));
2406
2407 UNLOCK();
2408 return 0;
2409}
2410
2411/* TODO: this needs work to guarantee that when it returns DMA has stopped
2412 but in a more elegant way than is done here....
2413*/
2414
2415static void PMacAbortRead(void)
2416{
2417 int i;
2418 volatile struct dbdma_cmd *cp;
2419
2420 LOCK();
2421 /* give it a chance to update the output and provide the IRQ
2422 that is expected.
2423 */
2424
2425 out_le32(&awacs_rxdma->control, ((FLUSH) << 16) + FLUSH );
2426
2427 cp = awacs_rx_cmds;
2428 for (i = 0; i < read_sq.max_count; i++,cp++)
2429 st_le16(&cp->command, DBDMA_STOP);
2430 /*
2431 * We should probably wait for the thing to stop before we
2432 * release the memory.
2433 */
2434
2435 msleep(100) ; /* give it a (small) chance to act */
2436
2437 /* apply the sledgehammer approach - just stop it now */
2438
2439 out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE) << 16);
2440 UNLOCK();
2441}
2442
2443extern char *get_afmt_string(int);
2444static int PMacStateInfo(char *b, size_t sp)
2445{
2446 int i, len = 0;
2447 len = sprintf(b,"HW rates: ");
2448 switch (awacs_revision){
2449 case AWACS_DACA:
2450 case AWACS_BURGUNDY:
2451 len += sprintf(b,"44100 ") ;
2452 break ;
2453 case AWACS_TUMBLER:
2454 case AWACS_SNAPPER:
2455 for (i=0; i<1; i++){
2456 if (tas_freqs_ok[i])
2457 len += sprintf(b+len,"%d ", tas_freqs[i]) ;
2458 }
2459 break ;
2460 case AWACS_AWACS:
2461 case AWACS_SCREAMER:
2462 default:
2463 for (i=0; i<8; i++){
2464 if (awacs_freqs_ok[i])
2465 len += sprintf(b+len,"%d ", awacs_freqs[i]) ;
2466 }
2467 break ;
2468 }
2469 len += sprintf(b+len,"s/sec\n") ;
2470 if (len < sp) {
2471 len += sprintf(b+len,"HW AFMTS: ");
2472 i = AFMT_U16_BE ;
2473 while (i) {
2474 if (i & dmasound.mach.hardware_afmts)
2475 len += sprintf(b+len,"%s ",
2476 get_afmt_string(i & dmasound.mach.hardware_afmts));
2477 i >>= 1 ;
2478 }
2479 len += sprintf(b+len,"\n") ;
2480 }
2481 return len ;
2482}
2483
2484/*** Machine definitions *****************************************************/
2485
2486static SETTINGS def_hard = {
2487 .format = AFMT_S16_BE,
2488 .stereo = 1,
2489 .size = 16,
2490 .speed = 44100
2491} ;
2492
2493static SETTINGS def_soft = {
2494 .format = AFMT_S16_BE,
2495 .stereo = 1,
2496 .size = 16,
2497 .speed = 44100
2498} ;
2499
2500static MACHINE machPMac = {
2501 .name = awacs_name,
2502 .name2 = "PowerMac Built-in Sound",
2503 .owner = THIS_MODULE,
2504 .dma_alloc = PMacAlloc,
2505 .dma_free = PMacFree,
2506 .irqinit = PMacIrqInit,
2507#ifdef MODULE
2508 .irqcleanup = PMacIrqCleanup,
2509#endif /* MODULE */
2510 .init = PMacInit,
2511 .silence = PMacSilence,
2512 .setFormat = PMacSetFormat,
2513 .setVolume = PMacSetVolume,
2514 .play = PMacPlay,
2515 .record = NULL, /* default to no record */
2516 .mixer_init = PMacMixerInit,
2517 .mixer_ioctl = PMacMixerIoctl,
2518 .write_sq_setup = PMacWriteSqSetup,
2519 .read_sq_setup = PMacReadSqSetup,
2520 .state_info = PMacStateInfo,
2521 .abort_read = PMacAbortRead,
2522 .min_dsp_speed = 7350,
2523 .max_dsp_speed = 44100,
2524 .version = ((DMASOUND_AWACS_REVISION<<8) + DMASOUND_AWACS_EDITION)
2525};
2526
2527
2528/*** Config & Setup **********************************************************/
2529
2530/* Check for pmac models that we care about in terms of special actions.
2531*/
2532
2533void __init
2534set_model(void)
2535{
2536 /* portables/lap-tops */
2537
2538 if (machine_is_compatible("AAPL,3400/2400") ||
2539 machine_is_compatible("AAPL,3500")) {
2540 is_pbook_3X00 = 1 ;
2541 }
2542 if (machine_is_compatible("PowerBook1,1") || /* lombard */
2543 machine_is_compatible("AAPL,PowerBook1998")){ /* wallstreet */
2544 is_pbook_g3 = 1 ;
2545 return ;
2546 }
2547}
2548
2549/* Get the OF node that tells us about the registers, interrupts etc. to use
2550 for sound IO.
2551
2552 On most machines the sound IO OF node is the 'davbus' node. On newer pmacs
2553 with DACA (& Tumbler) the node to use is i2s-a. On much older machines i.e.
2554 before 9500 there is no davbus node and we have to use the 'awacs' property.
2555
2556 In the latter case we signal this by setting the codec value - so that the
2557 code that looks for chip properties knows how to go about it.
2558*/
2559
2560static struct device_node* __init
2561get_snd_io_node(void)
2562{
2563 struct device_node *np = NULL;
2564
2565 /* set up awacs_node for early OF which doesn't have a full set of
2566 * properties on davbus
2567 */
2568
2569 awacs_node = find_devices("awacs");
2570 if (awacs_node)
2571 awacs_revision = AWACS_AWACS;
2572
2573 /* powermac models after 9500 (other than those which use DACA or
2574 * Tumbler) have a node called "davbus".
2575 */
2576 np = find_devices("davbus");
2577 /*
2578 * if we didn't find a davbus device, try 'i2s-a' since
2579 * this seems to be what iBooks (& Tumbler) have.
2580 */
2581 if (np == NULL)
2582 np = i2s_node = find_devices("i2s-a");
2583
2584 /* if we didn't find this - perhaps we are on an early model
2585 * which _only_ has an 'awacs' node
2586 */
2587 if (np == NULL && awacs_node)
2588 np = awacs_node ;
2589
2590 /* if we failed all these return null - this will cause the
2591 * driver to give up...
2592 */
2593 return np ;
2594}
2595
2596/* Get the OF node that contains the info about the sound chip, inputs s-rates
2597 etc.
2598 This node does not exist (or contains much reduced info) on earlier machines
2599 we have to deduce the info other ways for these.
2600*/
2601
2602static struct device_node* __init
2603get_snd_info_node(struct device_node *io)
2604{
2605 struct device_node *info;
2606
2607 info = find_devices("sound");
2608 while (info && info->parent != io)
2609 info = info->next;
2610 return info;
2611}
2612
2613/* Find out what type of codec we have.
2614*/
2615
2616static int __init
2617get_codec_type(struct device_node *info)
2618{
2619 /* already set if pre-davbus model and info will be NULL */
2620 int codec = awacs_revision ;
2621
2622 if (info) {
2623 /* must do awacs first to allow screamer to overide it */
2624 if (device_is_compatible(info, "awacs"))
2625 codec = AWACS_AWACS ;
2626 if (device_is_compatible(info, "screamer"))
2627 codec = AWACS_SCREAMER;
2628 if (device_is_compatible(info, "burgundy"))
2629 codec = AWACS_BURGUNDY ;
2630 if (device_is_compatible(info, "daca"))
2631 codec = AWACS_DACA;
2632 if (device_is_compatible(info, "tumbler"))
2633 codec = AWACS_TUMBLER;
2634 if (device_is_compatible(info, "snapper"))
2635 codec = AWACS_SNAPPER;
2636 }
2637 return codec ;
2638}
2639
2640/* find out what type, if any, of expansion card we have
2641*/
2642static void __init
2643get_expansion_type(void)
2644{
2645 if (find_devices("perch") != NULL)
2646 has_perch = 1;
2647
2648 if (find_devices("pb-ziva-pc") != NULL)
2649 has_ziva = 1;
2650 /* need to work out how we deal with iMac SRS module */
2651}
2652
2653/* set up frame rates.
2654 * I suspect that these routines don't quite go about it the right way:
2655 * - where there is more than one rate - I think that the first property
2656 * value is the number of rates.
2657 * TODO: check some more device trees and modify accordingly
2658 * Set dmasound.mach.max_dsp_rate on the basis of these routines.
2659*/
2660
2661static void __init
2662awacs_init_frame_rates(unsigned int *prop, unsigned int l)
2663{
2664 int i ;
2665 if (prop) {
2666 for (i=0; i<8; i++)
2667 awacs_freqs_ok[i] = 0 ;
2668 for (l /= sizeof(int); l > 0; --l) {
2669 unsigned int r = *prop++;
2670 /* Apple 'Fixed' format */
2671 if (r >= 0x10000)
2672 r >>= 16;
2673 for (i = 0; i < 8; ++i) {
2674 if (r == awacs_freqs[i]) {
2675 awacs_freqs_ok[i] = 1;
2676 break;
2677 }
2678 }
2679 }
2680 }
2681 /* else we assume that all the rates are available */
2682}
2683
2684static void __init
2685burgundy_init_frame_rates(unsigned int *prop, unsigned int l)
2686{
2687 int temp[9] ;
2688 int i = 0 ;
2689 if (prop) {
2690 for (l /= sizeof(int); l > 0; --l) {
2691 unsigned int r = *prop++;
2692 /* Apple 'Fixed' format */
2693 if (r >= 0x10000)
2694 r >>= 16;
2695 temp[i] = r ;
2696 i++ ; if(i>=9) i=8;
2697 }
2698 }
2699#ifdef DEBUG_DMASOUND
2700if (i > 1){
2701 int j;
2702 printk("dmasound_pmac: burgundy with multiple frame rates\n");
2703 for(j=0; j<i; j++)
2704 printk("%d ", temp[j]) ;
2705 printk("\n") ;
2706}
2707#endif
2708}
2709
2710static void __init
2711daca_init_frame_rates(unsigned int *prop, unsigned int l)
2712{
2713 int temp[9] ;
2714 int i = 0 ;
2715 if (prop) {
2716 for (l /= sizeof(int); l > 0; --l) {
2717 unsigned int r = *prop++;
2718 /* Apple 'Fixed' format */
2719 if (r >= 0x10000)
2720 r >>= 16;
2721 temp[i] = r ;
2722 i++ ; if(i>=9) i=8;
2723
2724 }
2725 }
2726#ifdef DEBUG_DMASOUND
2727if (i > 1){
2728 int j;
2729 printk("dmasound_pmac: DACA with multiple frame rates\n");
2730 for(j=0; j<i; j++)
2731 printk("%d ", temp[j]) ;
2732 printk("\n") ;
2733}
2734#endif
2735}
2736
2737static void __init
2738init_frame_rates(unsigned int *prop, unsigned int l)
2739{
2740 switch (awacs_revision) {
2741 case AWACS_TUMBLER:
2742 case AWACS_SNAPPER:
2743 tas_init_frame_rates(prop, l);
2744 break ;
2745 case AWACS_DACA:
2746 daca_init_frame_rates(prop, l);
2747 break ;
2748 case AWACS_BURGUNDY:
2749 burgundy_init_frame_rates(prop, l);
2750 break ;
2751 default:
2752 awacs_init_frame_rates(prop, l);
2753 break ;
2754 }
2755}
2756
2757/* find things/machines that can't do mac-io byteswap
2758*/
2759
2760static void __init
2761set_hw_byteswap(struct device_node *io)
2762{
2763 struct device_node *mio ;
2764 unsigned int kl = 0 ;
2765
2766 /* if seems that Keylargo can't byte-swap */
2767
2768 for (mio = io->parent; mio ; mio = mio->parent) {
2769 if (strcmp(mio->name, "mac-io") == 0) {
2770 if (device_is_compatible(mio, "Keylargo"))
2771 kl = 1;
2772 break;
2773 }
2774 }
2775 hw_can_byteswap = !kl;
2776}
2777
2778/* Allocate the resources necessary for beep generation. This cannot be (quite)
2779 done statically (yet) because we cannot do virt_to_bus() on static vars when
2780 the code is loaded as a module.
2781
2782 for the sake of saving the possibility that two allocations will incur the
2783 overhead of two pull-ups in DBDMA_ALIGN() we allocate the 'emergency' dmdma
2784 command here as well... even tho' it is not part of the beep process.
2785*/
2786
2787int32_t
2788__init setup_beep(void)
2789{
2790 /* Initialize beep stuff */
2791 /* want one cmd buffer for beeps, and a second one for emergencies
2792 - i.e. dbdma error conditions.
2793 ask for three to allow for pull up in DBDMA_ALIGN().
2794 */
2795 beep_dbdma_cmd_space =
2796 kmalloc((2 + 1) * sizeof(struct dbdma_cmd), GFP_KERNEL);
2797 if(beep_dbdma_cmd_space == NULL) {
2798 printk(KERN_ERR "dmasound_pmac: no beep dbdma cmd space\n") ;
2799 return -ENOMEM ;
2800 }
2801 beep_dbdma_cmd = (volatile struct dbdma_cmd *)
2802 DBDMA_ALIGN(beep_dbdma_cmd_space);
2803 /* set up emergency dbdma cmd */
2804 emergency_dbdma_cmd = beep_dbdma_cmd+1 ;
2805 beep_buf = (short *) kmalloc(BEEP_BUFLEN * 4, GFP_KERNEL);
2806 if (beep_buf == NULL) {
2807 printk(KERN_ERR "dmasound_pmac: no memory for beep buffer\n");
2808 if( beep_dbdma_cmd_space ) kfree(beep_dbdma_cmd_space) ;
2809 return -ENOMEM ;
2810 }
2811 return 0 ;
2812}
2813
2814static struct input_dev awacs_beep_dev = {
2815 .evbit = { BIT(EV_SND) },
2816 .sndbit = { BIT(SND_BELL) | BIT(SND_TONE) },
2817 .event = awacs_beep_event,
2818 .name = "dmasound beeper",
2819 .phys = "macio/input0", /* what the heck is this?? */
2820 .id = {
2821 .bustype = BUS_HOST,
2822 },
2823};
2824
2825int __init dmasound_awacs_init(void)
2826{
2827 struct device_node *io = NULL, *info = NULL;
2828 int vol, res;
2829
2830 if (_machine != _MACH_Pmac)
2831 return -ENODEV;
2832
2833 awacs_subframe = 0;
2834 awacs_revision = 0;
2835 hw_can_byteswap = 1 ; /* most can */
2836
2837 /* look for models we need to handle specially */
2838 set_model() ;
2839
2840 /* find the OF node that tells us about the dbdma stuff
2841 */
2842 io = get_snd_io_node();
2843 if (io == NULL) {
2844#ifdef DEBUG_DMASOUND
2845printk("dmasound_pmac: couldn't find sound io OF node\n");
2846#endif
2847 return -ENODEV ;
2848 }
2849
2850 /* find the OF node that tells us about the sound sub-system
2851 * this doesn't exist on pre-davbus machines (earlier than 9500)
2852 */
2853 if (awacs_revision != AWACS_AWACS) { /* set for pre-davbus */
2854 info = get_snd_info_node(io) ;
2855 if (info == NULL){
2856#ifdef DEBUG_DMASOUND
2857printk("dmasound_pmac: couldn't find 'sound' OF node\n");
2858#endif
2859 return -ENODEV ;
2860 }
2861 }
2862
2863 awacs_revision = get_codec_type(info) ;
2864 if (awacs_revision == 0) {
2865#ifdef DEBUG_DMASOUND
2866printk("dmasound_pmac: couldn't find a Codec we can handle\n");
2867#endif
2868 return -ENODEV ; /* we don't know this type of h/w */
2869 }
2870
2871 /* set up perch, ziva, SRS or whatever else we have as sound
2872 * expansion.
2873 */
2874 get_expansion_type();
2875
2876 /* we've now got enough information to make up the audio topology.
2877 * we will map the sound part of mac-io now so that we can probe for
2878 * other info if necessary (early AWACS we want to read chip ids)
2879 */
2880
2881 if (io->n_addrs < 3 || io->n_intrs < 3) {
2882 /* OK - maybe we need to use the 'awacs' node (on earlier
2883 * machines).
2884 */
2885 if (awacs_node) {
2886 io = awacs_node ;
2887 if (io->n_addrs < 3 || io->n_intrs < 3) {
2888 printk("dmasound_pmac: can't use %s"
2889 " (%d addrs, %d intrs)\n",
2890 io->full_name, io->n_addrs, io->n_intrs);
2891 return -ENODEV;
2892 }
2893 } else {
2894 printk("dmasound_pmac: can't use %s (%d addrs, %d intrs)\n",
2895 io->full_name, io->n_addrs, io->n_intrs);
2896 }
2897 }
2898
2899 if (!request_OF_resource(io, 0, NULL)) {
2900 printk(KERN_ERR "dmasound: can't request IO resource !\n");
2901 return -ENODEV;
2902 }
2903 if (!request_OF_resource(io, 1, " (tx dma)")) {
2904 release_OF_resource(io, 0);
2905 printk(KERN_ERR "dmasound: can't request TX DMA resource !\n");
2906 return -ENODEV;
2907 }
2908
2909 if (!request_OF_resource(io, 2, " (rx dma)")) {
2910 release_OF_resource(io, 0);
2911 release_OF_resource(io, 1);
2912 printk(KERN_ERR "dmasound: can't request RX DMA resource !\n");
2913 return -ENODEV;
2914 }
2915
2916 /* all OF versions I've seen use this value */
2917 if (i2s_node)
2918 i2s = ioremap(io->addrs[0].address, 0x1000);
2919 else
2920 awacs = ioremap(io->addrs[0].address, 0x1000);
2921 awacs_txdma = ioremap(io->addrs[1].address, 0x100);
2922 awacs_rxdma = ioremap(io->addrs[2].address, 0x100);
2923
2924 /* first of all make sure that the chip is powered up....*/
2925 pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, io, 0, 1);
2926 if (awacs_revision == AWACS_SCREAMER && awacs)
2927 awacs_recalibrate();
2928
2929 awacs_irq = io->intrs[0].line;
2930 awacs_tx_irq = io->intrs[1].line;
2931 awacs_rx_irq = io->intrs[2].line;
2932
2933 /* Hack for legacy crap that will be killed someday */
2934 awacs_node = io;
2935
2936 /* if we have an awacs or screamer - probe the chip to make
2937 * sure we have the right revision.
2938 */
2939
2940 if (awacs_revision <= AWACS_SCREAMER){
2941 uint32_t temp, rev, mfg ;
2942 /* find out the awacs revision from the chip */
2943 temp = in_le32(&awacs->codec_stat);
2944 rev = (temp >> 12) & 0xf;
2945 mfg = (temp >> 8) & 0xf;
2946#ifdef DEBUG_DMASOUND
2947printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
2948#endif
2949 if (rev >= AWACS_SCREAMER)
2950 awacs_revision = AWACS_SCREAMER ;
2951 else
2952 awacs_revision = rev ;
2953 }
2954
2955 dmasound.mach = machPMac;
2956
2957 /* find out other bits & pieces from OF, these may be present
2958 only on some models ... so be careful.
2959 */
2960
2961 /* in the absence of a frame rates property we will use the defaults
2962 */
2963
2964 if (info) {
2965 unsigned int *prop, l;
2966
2967 sound_device_id = 0;
2968 /* device ID appears post g3 b&w */
2969 prop = (unsigned int *)get_property(info, "device-id", NULL);
2970 if (prop != 0)
2971 sound_device_id = *prop;
2972
2973 /* look for a property saying what sample rates
2974 are available */
2975
2976 prop = (unsigned int *)get_property(info, "sample-rates", &l);
2977 if (prop == 0)
2978 prop = (unsigned int *) get_property
2979 (info, "output-frame-rates", &l);
2980
2981 /* if it's there use it to set up frame rates */
2982 init_frame_rates(prop, l) ;
2983 }
2984
2985 if (awacs)
2986 out_le32(&awacs->control, 0x11); /* set everything quiesent */
2987
2988 set_hw_byteswap(io) ; /* figure out if the h/w can do it */
2989
2990#ifdef CONFIG_NVRAM
2991 /* get default volume from nvram */
2992 vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
2993#else
2994 vol = 0;
2995#endif
2996
2997 /* set up tracking values */
2998 spk_vol = vol * 100 ;
2999 spk_vol /= 7 ; /* get set value to a percentage */
3000 spk_vol |= (spk_vol << 8) ; /* equal left & right */
3001 line_vol = passthru_vol = spk_vol ;
3002
3003 /* fill regs that are shared between AWACS & Burgundy */
3004
3005 awacs_reg[2] = vol + (vol << 6);
3006 awacs_reg[4] = vol + (vol << 6);
3007 awacs_reg[5] = vol + (vol << 6); /* screamer has loopthru vol control */
3008 awacs_reg[6] = 0; /* maybe should be vol << 3 for PCMCIA speaker */
3009 awacs_reg[7] = 0;
3010
3011 awacs_reg[0] = MASK_MUX_CD;
3012 awacs_reg[1] = MASK_LOOPTHRU;
3013
3014 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
3015 if (has_perch || sound_device_id == 0x5
3016 || /*sound_device_id == 0x8 ||*/ sound_device_id == 0xb)
3017 awacs_reg[1] |= MASK_PAROUT0 | MASK_PAROUT1;
3018
3019 switch (awacs_revision) {
3020 case AWACS_TUMBLER:
3021 tas_register_driver(&tas3001c_hooks);
3022 tas_init(I2C_DRIVERID_TAS3001C, I2C_DRIVERNAME_TAS3001C);
3023 tas_dmasound_init();
3024 tas_post_init();
3025 break ;
3026 case AWACS_SNAPPER:
3027 tas_register_driver(&tas3004_hooks);
3028 tas_init(I2C_DRIVERID_TAS3004,I2C_DRIVERNAME_TAS3004);
3029 tas_dmasound_init();
3030 tas_post_init();
3031 break;
3032 case AWACS_DACA:
3033 daca_init();
3034 break;
3035 case AWACS_BURGUNDY:
3036 awacs_burgundy_init();
3037 break ;
3038 case AWACS_SCREAMER:
3039 case AWACS_AWACS:
3040 default:
3041 load_awacs();
3042 break ;
3043 }
3044
3045 /* enable/set-up external modules - when we know how */
3046
3047 if (has_perch)
3048 awacs_enable_amp(100 * 0x101);
3049
3050 /* Reset dbdma channels */
3051 out_le32(&awacs_txdma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16);
3052 while (in_le32(&awacs_txdma->status) & RUN)
3053 udelay(1);
3054 out_le32(&awacs_rxdma->control, (RUN|PAUSE|FLUSH|WAKE|DEAD) << 16);
3055 while (in_le32(&awacs_rxdma->status) & RUN)
3056 udelay(1);
3057
3058 /* Initialize beep stuff */
3059 if ((res=setup_beep()))
3060 return res ;
3061
3062#ifdef CONFIG_PMAC_PBOOK
3063 pmu_register_sleep_notifier(&awacs_sleep_notifier);
3064#endif /* CONFIG_PMAC_PBOOK */
3065
3066 /* Powerbooks have odd ways of enabling inputs such as
3067 an expansion-bay CD or sound from an internal modem
3068 or a PC-card modem. */
3069 if (is_pbook_3X00) {
3070 /*
3071 * Enable CD and PC-card sound inputs.
3072 * This is done by reading from address
3073 * f301a000, + 0x10 to enable the expansion-bay
3074 * CD sound input, + 0x80 to enable the PC-card
3075 * sound input. The 0x100 enables the SCSI bus
3076 * terminator power.
3077 */
3078 latch_base = ioremap (0xf301a000, 0x1000);
3079 in_8(latch_base + 0x190);
3080
3081 } else if (is_pbook_g3) {
3082 struct device_node* mio;
3083 macio_base = NULL;
3084 for (mio = io->parent; mio; mio = mio->parent) {
3085 if (strcmp(mio->name, "mac-io") == 0
3086 && mio->n_addrs > 0) {
3087 macio_base = ioremap(mio->addrs[0].address, 0x40);
3088 break;
3089 }
3090 }
3091 /*
3092 * Enable CD sound input.
3093 * The relevant bits for writing to this byte are 0x8f.
3094 * I haven't found out what the 0x80 bit does.
3095 * For the 0xf bits, writing 3 or 7 enables the CD
3096 * input, any other value disables it. Values
3097 * 1, 3, 5, 7 enable the microphone. Values 0, 2,
3098 * 4, 6, 8 - f enable the input from the modem.
3099 * -- paulus.
3100 */
3101 if (macio_base)
3102 out_8(macio_base + 0x37, 3);
3103 }
3104
3105 if (hw_can_byteswap)
3106 dmasound.mach.hardware_afmts = (AFMT_S16_BE | AFMT_S16_LE) ;
3107 else
3108 dmasound.mach.hardware_afmts = AFMT_S16_BE ;
3109
3110 /* shut out chips that do output only.
3111 * may need to extend this to machines which have no inputs - even tho'
3112 * they use screamer - IIRC one of the powerbooks is like this.
3113 */
3114
3115 if (awacs_revision != AWACS_DACA) {
3116 dmasound.mach.capabilities = DSP_CAP_DUPLEX ;
3117 dmasound.mach.record = PMacRecord ;
3118 }
3119
3120 dmasound.mach.default_hard = def_hard ;
3121 dmasound.mach.default_soft = def_soft ;
3122
3123 switch (awacs_revision) {
3124 case AWACS_BURGUNDY:
3125 sprintf(awacs_name, "PowerMac Burgundy ") ;
3126 break ;
3127 case AWACS_DACA:
3128 sprintf(awacs_name, "PowerMac DACA ") ;
3129 break ;
3130 case AWACS_TUMBLER:
3131 sprintf(awacs_name, "PowerMac Tumbler ") ;
3132 break ;
3133 case AWACS_SNAPPER:
3134 sprintf(awacs_name, "PowerMac Snapper ") ;
3135 break ;
3136 case AWACS_SCREAMER:
3137 sprintf(awacs_name, "PowerMac Screamer ") ;
3138 break ;
3139 case AWACS_AWACS:
3140 default:
3141 sprintf(awacs_name, "PowerMac AWACS rev %d ", awacs_revision) ;
3142 break ;
3143 }
3144
3145 /*
3146 * XXX: we should handle errors here, but that would mean
3147 * rewriting the whole init code. later..
3148 */
3149 input_register_device(&awacs_beep_dev);
3150
3151 return dmasound_init();
3152}
3153
3154static void __exit dmasound_awacs_cleanup(void)
3155{
3156 input_unregister_device(&awacs_beep_dev);
3157
3158 switch (awacs_revision) {
3159 case AWACS_TUMBLER:
3160 case AWACS_SNAPPER:
3161 tas_dmasound_cleanup();
3162 tas_cleanup();
3163 break ;
3164 case AWACS_DACA:
3165 daca_cleanup();
3166 break;
3167 }
3168 dmasound_deinit();
3169
3170}
3171
3172MODULE_DESCRIPTION("PowerMac built-in audio driver.");
3173MODULE_LICENSE("GPL");
3174
3175module_init(dmasound_awacs_init);
3176module_exit(dmasound_awacs_cleanup);
diff --git a/sound/oss/dmasound/dmasound_core.c b/sound/oss/dmasound/dmasound_core.c
new file mode 100644
index 000000000000..c9302a1e515b
--- /dev/null
+++ b/sound/oss/dmasound/dmasound_core.c
@@ -0,0 +1,1829 @@
1/*
2 * linux/sound/oss/dmasound/dmasound_core.c
3 *
4 *
5 * OSS/Free compatible Atari TT/Falcon and Amiga DMA sound driver for
6 * Linux/m68k
7 * Extended to support Power Macintosh for Linux/ppc by Paul Mackerras
8 *
9 * (c) 1995 by Michael Schlueter & Michael Marte
10 *
11 * Michael Schlueter (michael@duck.syd.de) did the basic structure of the VFS
12 * interface and the u-law to signed byte conversion.
13 *
14 * Michael Marte (marte@informatik.uni-muenchen.de) did the sound queue,
15 * /dev/mixer, /dev/sndstat and complemented the VFS interface. He would like
16 * to thank:
17 * - Michael Schlueter for initial ideas and documentation on the MFP and
18 * the DMA sound hardware.
19 * - Therapy? for their CD 'Troublegum' which really made me rock.
20 *
21 * /dev/sndstat is based on code by Hannu Savolainen, the author of the
22 * VoxWare family of drivers.
23 *
24 * This file is subject to the terms and conditions of the GNU General Public
25 * License. See the file COPYING in the main directory of this archive
26 * for more details.
27 *
28 * History:
29 *
30 * 1995/8/25 First release
31 *
32 * 1995/9/02 Roman Hodek:
33 * - Fixed atari_stram_alloc() call, the timer
34 * programming and several race conditions
35 * 1995/9/14 Roman Hodek:
36 * - After some discussion with Michael Schlueter,
37 * revised the interrupt disabling
38 * - Slightly speeded up U8->S8 translation by using
39 * long operations where possible
40 * - Added 4:3 interpolation for /dev/audio
41 *
42 * 1995/9/20 Torsten Scherer:
43 * - Fixed a bug in sq_write and changed /dev/audio
44 * converting to play at 12517Hz instead of 6258Hz.
45 *
46 * 1995/9/23 Torsten Scherer:
47 * - Changed sq_interrupt() and sq_play() to pre-program
48 * the DMA for another frame while there's still one
49 * running. This allows the IRQ response to be
50 * arbitrarily delayed and playing will still continue.
51 *
52 * 1995/10/14 Guenther Kelleter, Torsten Scherer:
53 * - Better support for Falcon audio (the Falcon doesn't
54 * raise an IRQ at the end of a frame, but at the
55 * beginning instead!). uses 'if (codec_dma)' in lots
56 * of places to simply switch between Falcon and TT
57 * code.
58 *
59 * 1995/11/06 Torsten Scherer:
60 * - Started introducing a hardware abstraction scheme
61 * (may perhaps also serve for Amigas?)
62 * - Can now play samples at almost all frequencies by
63 * means of a more generalized expand routine
64 * - Takes a good deal of care to cut data only at
65 * sample sizes
66 * - Buffer size is now a kernel runtime option
67 * - Implemented fsync() & several minor improvements
68 * Guenther Kelleter:
69 * - Useful hints and bug fixes
70 * - Cross-checked it for Falcons
71 *
72 * 1996/3/9 Geert Uytterhoeven:
73 * - Support added for Amiga, A-law, 16-bit little
74 * endian.
75 * - Unification to drivers/sound/dmasound.c.
76 *
77 * 1996/4/6 Martin Mitchell:
78 * - Updated to 1.3 kernel.
79 *
80 * 1996/6/13 Topi Kanerva:
81 * - Fixed things that were broken (mainly the amiga
82 * 14-bit routines)
83 * - /dev/sndstat shows now the real hardware frequency
84 * - The lowpass filter is disabled by default now
85 *
86 * 1996/9/25 Geert Uytterhoeven:
87 * - Modularization
88 *
89 * 1998/6/10 Andreas Schwab:
90 * - Converted to use sound_core
91 *
92 * 1999/12/28 Richard Zidlicky:
93 * - Added support for Q40
94 *
95 * 2000/2/27 Geert Uytterhoeven:
96 * - Clean up and split the code into 4 parts:
97 * o dmasound_core: machine-independent code
98 * o dmasound_atari: Atari TT and Falcon support
99 * o dmasound_awacs: Apple PowerMac support
100 * o dmasound_paula: Amiga support
101 *
102 * 2000/3/25 Geert Uytterhoeven:
103 * - Integration of dmasound_q40
104 * - Small clean ups
105 *
106 * 2001/01/26 [1.0] Iain Sandoe
107 * - make /dev/sndstat show revision & edition info.
108 * - since dmasound.mach.sq_setup() can fail on pmac
109 * its type has been changed to int and the returns
110 * are checked.
111 * [1.1] - stop missing translations from being called.
112 * 2001/02/08 [1.2] - remove unused translation tables & move machine-
113 * specific tables to low-level.
114 * - return correct info. for SNDCTL_DSP_GETFMTS.
115 * [1.3] - implement SNDCTL_DSP_GETCAPS fully.
116 * [1.4] - make /dev/sndstat text length usage deterministic.
117 * - make /dev/sndstat call to low-level
118 * dmasound.mach.state_info() pass max space to ll driver.
119 * - tidy startup banners and output info.
120 * [1.5] - tidy up a little (removed some unused #defines in
121 * dmasound.h)
122 * - fix up HAS_RECORD conditionalisation.
123 * - add record code in places it is missing...
124 * - change buf-sizes to bytes to allow < 1kb for pmac
125 * if user param entry is < 256 the value is taken to
126 * be in kb > 256 is taken to be in bytes.
127 * - make default buff/frag params conditional on
128 * machine to allow smaller values for pmac.
129 * - made the ioctls, read & write comply with the OSS
130 * rules on setting params.
131 * - added parsing of _setup() params for record.
132 * 2001/04/04 [1.6] - fix bug where sample rates higher than maximum were
133 * being reported as OK.
134 * - fix open() to return -EBUSY as per OSS doc. when
135 * audio is in use - this is independent of O_NOBLOCK.
136 * - fix bug where SNDCTL_DSP_POST was blocking.
137 */
138
139 /* Record capability notes 30/01/2001:
140 * At present these observations apply only to pmac LL driver (the only one
141 * that can do record, at present). However, if other LL drivers for machines
142 * with record are added they may apply.
143 *
144 * The fragment parameters for the record and play channels are separate.
145 * However, if the driver is opened O_RDWR there is no way (in the current OSS
146 * API) to specify their values independently for the record and playback
147 * channels. Since the only common factor between the input & output is the
148 * sample rate (on pmac) it should be possible to open /dev/dspX O_WRONLY and
149 * /dev/dspY O_RDONLY. The input & output channels could then have different
150 * characteristics (other than the first that sets sample rate claiming the
151 * right to set it for ever). As it stands, the format, channels, number of
152 * bits & sample rate are assumed to be common. In the future perhaps these
153 * should be the responsibility of the LL driver - and then if a card really
154 * does not share items between record & playback they can be specified
155 * separately.
156*/
157
158/* Thread-safeness of shared_resources notes: 31/01/2001
159 * If the user opens O_RDWR and then splits record & play between two threads
160 * both of which inherit the fd - and then starts changing things from both
161 * - we will have difficulty telling.
162 *
163 * It's bad application coding - but ...
164 * TODO: think about how to sort this out... without bogging everything down in
165 * semaphores.
166 *
167 * Similarly, the OSS spec says "all changes to parameters must be between
168 * open() and the first read() or write(). - and a bit later on (by
169 * implication) "between SNDCTL_DSP_RESET and the first read() or write() after
170 * it". If the app is multi-threaded and this rule is broken between threads
171 * we will have trouble spotting it - and the fault will be rather obscure :-(
172 *
173 * We will try and put out at least a kmsg if we see it happen... but I think
174 * it will be quite hard to trap it with an -EXXX return... because we can't
175 * see the fault until after the damage is done.
176*/
177
178#include <linux/module.h>
179#include <linux/slab.h>
180#include <linux/sound.h>
181#include <linux/init.h>
182#include <linux/soundcard.h>
183#include <linux/poll.h>
184#include <linux/smp_lock.h>
185
186#include <asm/uaccess.h>
187
188#include "dmasound.h"
189
190#define DMASOUND_CORE_REVISION 1
191#define DMASOUND_CORE_EDITION 6
192
193 /*
194 * Declarations
195 */
196
197int dmasound_catchRadius = 0;
198MODULE_PARM(dmasound_catchRadius, "i");
199
200static unsigned int numWriteBufs = DEFAULT_N_BUFFERS;
201MODULE_PARM(numWriteBufs, "i");
202static unsigned int writeBufSize = DEFAULT_BUFF_SIZE ; /* in bytes */
203MODULE_PARM(writeBufSize, "i");
204
205#ifdef HAS_RECORD
206static unsigned int numReadBufs = DEFAULT_N_BUFFERS;
207MODULE_PARM(numReadBufs, "i");
208static unsigned int readBufSize = DEFAULT_BUFF_SIZE; /* in bytes */
209MODULE_PARM(readBufSize, "i");
210#endif
211
212MODULE_LICENSE("GPL");
213
214#ifdef MODULE
215static int sq_unit = -1;
216static int mixer_unit = -1;
217static int state_unit = -1;
218static int irq_installed;
219#endif /* MODULE */
220
221/* software implemented recording volume! */
222uint software_input_volume = SW_INPUT_VOLUME_SCALE * SW_INPUT_VOLUME_DEFAULT;
223EXPORT_SYMBOL(software_input_volume);
224
225/* control over who can modify resources shared between play/record */
226static mode_t shared_resource_owner;
227static int shared_resources_initialised;
228
229 /*
230 * Mid level stuff
231 */
232
233struct sound_settings dmasound = { .lock = SPIN_LOCK_UNLOCKED };
234
235static inline void sound_silence(void)
236{
237 dmasound.mach.silence(); /* _MUST_ stop DMA */
238}
239
240static inline int sound_set_format(int format)
241{
242 return dmasound.mach.setFormat(format);
243}
244
245
246static int sound_set_speed(int speed)
247{
248 if (speed < 0)
249 return dmasound.soft.speed;
250
251 /* trap out-of-range speed settings.
252 at present we allow (arbitrarily) low rates - using soft
253 up-conversion - but we can't allow > max because there is
254 no soft down-conversion.
255 */
256 if (dmasound.mach.max_dsp_speed &&
257 (speed > dmasound.mach.max_dsp_speed))
258 speed = dmasound.mach.max_dsp_speed ;
259
260 dmasound.soft.speed = speed;
261
262 if (dmasound.minDev == SND_DEV_DSP)
263 dmasound.dsp.speed = dmasound.soft.speed;
264
265 return dmasound.soft.speed;
266}
267
268static int sound_set_stereo(int stereo)
269{
270 if (stereo < 0)
271 return dmasound.soft.stereo;
272
273 stereo = !!stereo; /* should be 0 or 1 now */
274
275 dmasound.soft.stereo = stereo;
276 if (dmasound.minDev == SND_DEV_DSP)
277 dmasound.dsp.stereo = stereo;
278
279 return stereo;
280}
281
282static ssize_t sound_copy_translate(TRANS *trans, const u_char __user *userPtr,
283 size_t userCount, u_char frame[],
284 ssize_t *frameUsed, ssize_t frameLeft)
285{
286 ssize_t (*ct_func)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
287
288 switch (dmasound.soft.format) {
289 case AFMT_MU_LAW:
290 ct_func = trans->ct_ulaw;
291 break;
292 case AFMT_A_LAW:
293 ct_func = trans->ct_alaw;
294 break;
295 case AFMT_S8:
296 ct_func = trans->ct_s8;
297 break;
298 case AFMT_U8:
299 ct_func = trans->ct_u8;
300 break;
301 case AFMT_S16_BE:
302 ct_func = trans->ct_s16be;
303 break;
304 case AFMT_U16_BE:
305 ct_func = trans->ct_u16be;
306 break;
307 case AFMT_S16_LE:
308 ct_func = trans->ct_s16le;
309 break;
310 case AFMT_U16_LE:
311 ct_func = trans->ct_u16le;
312 break;
313 default:
314 return 0;
315 }
316 /* if the user has requested a non-existent translation don't try
317 to call it but just return 0 bytes moved
318 */
319 if (ct_func)
320 return ct_func(userPtr, userCount, frame, frameUsed, frameLeft);
321 return 0;
322}
323
324 /*
325 * /dev/mixer abstraction
326 */
327
328static struct {
329 int busy;
330 int modify_counter;
331} mixer;
332
333static int mixer_open(struct inode *inode, struct file *file)
334{
335 if (!try_module_get(dmasound.mach.owner))
336 return -ENODEV;
337 mixer.busy = 1;
338 return 0;
339}
340
341static int mixer_release(struct inode *inode, struct file *file)
342{
343 lock_kernel();
344 mixer.busy = 0;
345 module_put(dmasound.mach.owner);
346 unlock_kernel();
347 return 0;
348}
349static int mixer_ioctl(struct inode *inode, struct file *file, u_int cmd,
350 u_long arg)
351{
352 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
353 mixer.modify_counter++;
354 switch (cmd) {
355 case OSS_GETVERSION:
356 return IOCTL_OUT(arg, SOUND_VERSION);
357 case SOUND_MIXER_INFO:
358 {
359 mixer_info info;
360 memset(&info, 0, sizeof(info));
361 strlcpy(info.id, dmasound.mach.name2, sizeof(info.id));
362 strlcpy(info.name, dmasound.mach.name2, sizeof(info.name));
363 info.modify_counter = mixer.modify_counter;
364 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
365 return -EFAULT;
366 return 0;
367 }
368 }
369 if (dmasound.mach.mixer_ioctl)
370 return dmasound.mach.mixer_ioctl(cmd, arg);
371 return -EINVAL;
372}
373
374static struct file_operations mixer_fops =
375{
376 .owner = THIS_MODULE,
377 .llseek = no_llseek,
378 .ioctl = mixer_ioctl,
379 .open = mixer_open,
380 .release = mixer_release,
381};
382
383static void mixer_init(void)
384{
385#ifndef MODULE
386 int mixer_unit;
387#endif
388 mixer_unit = register_sound_mixer(&mixer_fops, -1);
389 if (mixer_unit < 0)
390 return;
391
392 mixer.busy = 0;
393 dmasound.treble = 0;
394 dmasound.bass = 0;
395 if (dmasound.mach.mixer_init)
396 dmasound.mach.mixer_init();
397}
398
399
400 /*
401 * Sound queue stuff, the heart of the driver
402 */
403
404struct sound_queue dmasound_write_sq;
405static void sq_reset_output(void) ;
406#ifdef HAS_RECORD
407struct sound_queue dmasound_read_sq;
408static void sq_reset_input(void) ;
409#endif
410
411static int sq_allocate_buffers(struct sound_queue *sq, int num, int size)
412{
413 int i;
414
415 if (sq->buffers)
416 return 0;
417 sq->numBufs = num;
418 sq->bufSize = size;
419 sq->buffers = kmalloc (num * sizeof(char *), GFP_KERNEL);
420 if (!sq->buffers)
421 return -ENOMEM;
422 for (i = 0; i < num; i++) {
423 sq->buffers[i] = dmasound.mach.dma_alloc(size, GFP_KERNEL);
424 if (!sq->buffers[i]) {
425 while (i--)
426 dmasound.mach.dma_free(sq->buffers[i], size);
427 kfree(sq->buffers);
428 sq->buffers = NULL;
429 return -ENOMEM;
430 }
431 }
432 return 0;
433}
434
435static void sq_release_buffers(struct sound_queue *sq)
436{
437 int i;
438
439 if (sq->buffers) {
440 for (i = 0; i < sq->numBufs; i++)
441 dmasound.mach.dma_free(sq->buffers[i], sq->bufSize);
442 kfree(sq->buffers);
443 sq->buffers = NULL;
444 }
445}
446
447
448static int sq_setup(struct sound_queue *sq)
449{
450 int (*setup_func)(void) = NULL;
451 int hard_frame ;
452
453 if (sq->locked) { /* are we already set? - and not changeable */
454#ifdef DEBUG_DMASOUND
455printk("dmasound_core: tried to sq_setup a locked queue\n") ;
456#endif
457 return -EINVAL ;
458 }
459 sq->locked = 1 ; /* don't think we have a race prob. here _check_ */
460
461 /* make sure that the parameters are set up
462 This should have been done already...
463 */
464
465 dmasound.mach.init();
466
467 /* OK. If the user has set fragment parameters explicitly, then we
468 should leave them alone... as long as they are valid.
469 Invalid user fragment params can occur if we allow the whole buffer
470 to be used when the user requests the fragments sizes (with no soft
471 x-lation) and then the user subsequently sets a soft x-lation that
472 requires increased internal buffering.
473
474 Othwerwise (if the user did not set them) OSS says that we should
475 select frag params on the basis of 0.5 s output & 0.1 s input
476 latency. (TODO. For now we will copy in the defaults.)
477 */
478
479 if (sq->user_frags <= 0) {
480 sq->max_count = sq->numBufs ;
481 sq->max_active = sq->numBufs ;
482 sq->block_size = sq->bufSize;
483 /* set up the user info */
484 sq->user_frags = sq->numBufs ;
485 sq->user_frag_size = sq->bufSize ;
486 sq->user_frag_size *=
487 (dmasound.soft.size * (dmasound.soft.stereo+1) ) ;
488 sq->user_frag_size /=
489 (dmasound.hard.size * (dmasound.hard.stereo+1) ) ;
490 } else {
491 /* work out requested block size */
492 sq->block_size = sq->user_frag_size ;
493 sq->block_size *=
494 (dmasound.hard.size * (dmasound.hard.stereo+1) ) ;
495 sq->block_size /=
496 (dmasound.soft.size * (dmasound.soft.stereo+1) ) ;
497 /* the user wants to write frag-size chunks */
498 sq->block_size *= dmasound.hard.speed ;
499 sq->block_size /= dmasound.soft.speed ;
500 /* this only works for size values which are powers of 2 */
501 hard_frame =
502 (dmasound.hard.size * (dmasound.hard.stereo+1))/8 ;
503 sq->block_size += (hard_frame - 1) ;
504 sq->block_size &= ~(hard_frame - 1) ; /* make sure we are aligned */
505 /* let's just check for obvious mistakes */
506 if ( sq->block_size <= 0 || sq->block_size > sq->bufSize) {
507#ifdef DEBUG_DMASOUND
508printk("dmasound_core: invalid frag size (user set %d)\n", sq->user_frag_size) ;
509#endif
510 sq->block_size = sq->bufSize ;
511 }
512 if ( sq->user_frags <= sq->numBufs ) {
513 sq->max_count = sq->user_frags ;
514 /* if user has set max_active - then use it */
515 sq->max_active = (sq->max_active <= sq->max_count) ?
516 sq->max_active : sq->max_count ;
517 } else {
518#ifdef DEBUG_DMASOUND
519printk("dmasound_core: invalid frag count (user set %d)\n", sq->user_frags) ;
520#endif
521 sq->max_count =
522 sq->max_active = sq->numBufs ;
523 }
524 }
525 sq->front = sq->count = sq->rear_size = 0;
526 sq->syncing = 0;
527 sq->active = 0;
528
529 if (sq == &write_sq) {
530 sq->rear = -1;
531 setup_func = dmasound.mach.write_sq_setup;
532 }
533#ifdef HAS_RECORD
534 else {
535 sq->rear = 0;
536 setup_func = dmasound.mach.read_sq_setup;
537 }
538#endif
539 if (setup_func)
540 return setup_func();
541 return 0 ;
542}
543
544static inline void sq_play(void)
545{
546 dmasound.mach.play();
547}
548
549static ssize_t sq_write(struct file *file, const char __user *src, size_t uLeft,
550 loff_t *ppos)
551{
552 ssize_t uWritten = 0;
553 u_char *dest;
554 ssize_t uUsed = 0, bUsed, bLeft;
555 unsigned long flags ;
556
557 /* ++TeSche: Is something like this necessary?
558 * Hey, that's an honest question! Or does any other part of the
559 * filesystem already checks this situation? I really don't know.
560 */
561 if (uLeft == 0)
562 return 0;
563
564 /* implement any changes we have made to the soft/hard params.
565 this is not satisfactory really, all we have done up to now is to
566 say what we would like - there hasn't been any real checking of capability
567 */
568
569 if (shared_resources_initialised == 0) {
570 dmasound.mach.init() ;
571 shared_resources_initialised = 1 ;
572 }
573
574 /* set up the sq if it is not already done. This may seem a dumb place
575 to do it - but it is what OSS requires. It means that write() can
576 return memory allocation errors. To avoid this possibility use the
577 GETBLKSIZE or GETOSPACE ioctls (after you've fiddled with all the
578 params you want to change) - these ioctls also force the setup.
579 */
580
581 if (write_sq.locked == 0) {
582 if ((uWritten = sq_setup(&write_sq)) < 0) return uWritten ;
583 uWritten = 0 ;
584 }
585
586/* FIXME: I think that this may be the wrong behaviour when we get strapped
587 for time and the cpu is close to being (or actually) behind in sending data.
588 - because we've lost the time that the N samples, already in the buffer,
589 would have given us to get here with the next lot from the user.
590*/
591 /* The interrupt doesn't start to play the last, incomplete frame.
592 * Thus we can append to it without disabling the interrupts! (Note
593 * also that write_sq.rear isn't affected by the interrupt.)
594 */
595
596 /* as of 1.6 this behaviour changes if SNDCTL_DSP_POST has been issued:
597 this will mimic the behaviour of syncing and allow the sq_play() to
598 queue a partial fragment. Since sq_play() may/will be called from
599 the IRQ handler - at least on Pmac we have to deal with it.
600 The strategy - possibly not optimum - is to kill _POST status if we
601 get here. This seems, at least, reasonable - in the sense that POST
602 is supposed to indicate that we might not write before the queue
603 is drained - and if we get here in time then it does not apply.
604 */
605
606 spin_lock_irqsave(&dmasound.lock, flags);
607 write_sq.syncing &= ~2 ; /* take out POST status */
608 spin_unlock_irqrestore(&dmasound.lock, flags);
609
610 if (write_sq.count > 0 &&
611 (bLeft = write_sq.block_size-write_sq.rear_size) > 0) {
612 dest = write_sq.buffers[write_sq.rear];
613 bUsed = write_sq.rear_size;
614 uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft,
615 dest, &bUsed, bLeft);
616 if (uUsed <= 0)
617 return uUsed;
618 src += uUsed;
619 uWritten += uUsed;
620 uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */
621 write_sq.rear_size = bUsed;
622 }
623
624 while (uLeft) {
625 while (write_sq.count >= write_sq.max_active) {
626 sq_play();
627 if (write_sq.open_mode & O_NONBLOCK)
628 return uWritten > 0 ? uWritten : -EAGAIN;
629 SLEEP(write_sq.action_queue);
630 if (signal_pending(current))
631 return uWritten > 0 ? uWritten : -EINTR;
632 }
633
634 /* Here, we can avoid disabling the interrupt by first
635 * copying and translating the data, and then updating
636 * the write_sq variables. Until this is done, the interrupt
637 * won't see the new frame and we can work on it
638 * undisturbed.
639 */
640
641 dest = write_sq.buffers[(write_sq.rear+1) % write_sq.max_count];
642 bUsed = 0;
643 bLeft = write_sq.block_size;
644 uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft,
645 dest, &bUsed, bLeft);
646 if (uUsed <= 0)
647 break;
648 src += uUsed;
649 uWritten += uUsed;
650 uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */
651 if (bUsed) {
652 write_sq.rear = (write_sq.rear+1) % write_sq.max_count;
653 write_sq.rear_size = bUsed;
654 write_sq.count++;
655 }
656 } /* uUsed may have been 0 */
657
658 sq_play();
659
660 return uUsed < 0? uUsed: uWritten;
661}
662
663static unsigned int sq_poll(struct file *file, struct poll_table_struct *wait)
664{
665 unsigned int mask = 0;
666 int retVal;
667
668 if (write_sq.locked == 0) {
669 if ((retVal = sq_setup(&write_sq)) < 0)
670 return retVal;
671 return 0;
672 }
673 if (file->f_mode & FMODE_WRITE )
674 poll_wait(file, &write_sq.action_queue, wait);
675#ifdef HAS_RECORD
676 if (file->f_mode & FMODE_READ)
677 poll_wait(file, &read_sq.action_queue, wait);
678 if (file->f_mode & FMODE_READ)
679 if (read_sq.block_size - read_sq.rear_size > 0)
680 mask |= POLLIN | POLLRDNORM;
681#endif
682 if (file->f_mode & FMODE_WRITE)
683 if (write_sq.count < write_sq.max_active || write_sq.block_size - write_sq.rear_size > 0)
684 mask |= POLLOUT | POLLWRNORM;
685 return mask;
686
687}
688
689#ifdef HAS_RECORD
690 /*
691 * Here is how the values are used for reading.
692 * The value 'active' simply indicates the DMA is running. This is done
693 * so the driver semantics are DMA starts when the first read is posted.
694 * The value 'front' indicates the buffer we should next send to the user.
695 * The value 'rear' indicates the buffer the DMA is currently filling.
696 * When 'front' == 'rear' the buffer "ring" is empty (we always have an
697 * empty available). The 'rear_size' is used to track partial offsets
698 * into the buffer we are currently returning to the user.
699
700 * This level (> [1.5]) doesn't care what strategy the LL driver uses with
701 * DMA on over-run. It can leave it running (and keep active == 1) or it
702 * can kill it and set active == 0 in which case this routine will spot
703 * it and restart the DMA.
704 */
705
706static ssize_t sq_read(struct file *file, char __user *dst, size_t uLeft,
707 loff_t *ppos)
708{
709
710 ssize_t uRead, bLeft, bUsed, uUsed;
711
712 if (uLeft == 0)
713 return 0;
714
715 /* cater for the compatibility mode - record compiled in but no LL */
716 if (dmasound.mach.record == NULL)
717 return -EINVAL ;
718
719 /* see comment in sq_write()
720 */
721
722 if( shared_resources_initialised == 0) {
723 dmasound.mach.init() ;
724 shared_resources_initialised = 1 ;
725 }
726
727 /* set up the sq if it is not already done. see comments in sq_write().
728 */
729
730 if (read_sq.locked == 0) {
731 if ((uRead = sq_setup(&read_sq)) < 0)
732 return uRead ;
733 }
734
735 uRead = 0;
736
737 /* Move what the user requests, depending upon other options.
738 */
739 while (uLeft > 0) {
740
741 /* we happened to get behind and the LL driver killed DMA
742 then we should set it going again. This also sets it
743 going the first time through.
744 */
745 if ( !read_sq.active )
746 dmasound.mach.record();
747
748 /* When front == rear, the DMA is not done yet.
749 */
750 while (read_sq.front == read_sq.rear) {
751 if (read_sq.open_mode & O_NONBLOCK) {
752 return uRead > 0 ? uRead : -EAGAIN;
753 }
754 SLEEP(read_sq.action_queue);
755 if (signal_pending(current))
756 return uRead > 0 ? uRead : -EINTR;
757 }
758
759 /* The amount we move is either what is left in the
760 * current buffer or what the user wants.
761 */
762 bLeft = read_sq.block_size - read_sq.rear_size;
763 bUsed = read_sq.rear_size;
764 uUsed = sound_copy_translate(dmasound.trans_read, dst, uLeft,
765 read_sq.buffers[read_sq.front],
766 &bUsed, bLeft);
767 if (uUsed <= 0)
768 return uUsed;
769 dst += uUsed;
770 uRead += uUsed;
771 uLeft -= uUsed;
772 read_sq.rear_size += bUsed;
773 if (read_sq.rear_size >= read_sq.block_size) {
774 read_sq.rear_size = 0;
775 read_sq.front++;
776 if (read_sq.front >= read_sq.max_active)
777 read_sq.front = 0;
778 }
779 }
780 return uRead;
781}
782#endif /* HAS_RECORD */
783
784static inline void sq_init_waitqueue(struct sound_queue *sq)
785{
786 init_waitqueue_head(&sq->action_queue);
787 init_waitqueue_head(&sq->open_queue);
788 init_waitqueue_head(&sq->sync_queue);
789 sq->busy = 0;
790}
791
792#if 0 /* blocking open() */
793static inline void sq_wake_up(struct sound_queue *sq, struct file *file,
794 mode_t mode)
795{
796 if (file->f_mode & mode) {
797 sq->busy = 0; /* CHECK: IS THIS OK??? */
798 WAKE_UP(sq->open_queue);
799 }
800}
801#endif
802
803static int sq_open2(struct sound_queue *sq, struct file *file, mode_t mode,
804 int numbufs, int bufsize)
805{
806 int rc = 0;
807
808 if (file->f_mode & mode) {
809 if (sq->busy) {
810#if 0 /* blocking open() */
811 rc = -EBUSY;
812 if (file->f_flags & O_NONBLOCK)
813 return rc;
814 rc = -EINTR;
815 while (sq->busy) {
816 SLEEP(sq->open_queue);
817 if (signal_pending(current))
818 return rc;
819 }
820 rc = 0;
821#else
822 /* OSS manual says we will return EBUSY regardless
823 of O_NOBLOCK.
824 */
825 return -EBUSY ;
826#endif
827 }
828 sq->busy = 1; /* Let's play spot-the-race-condition */
829
830 /* allocate the default number & size of buffers.
831 (i.e. specified in _setup() or as module params)
832 can't be changed at the moment - but _could_ be perhaps
833 in the setfragments ioctl.
834 */
835 if (( rc = sq_allocate_buffers(sq, numbufs, bufsize))) {
836#if 0 /* blocking open() */
837 sq_wake_up(sq, file, mode);
838#else
839 sq->busy = 0 ;
840#endif
841 return rc;
842 }
843
844 sq->open_mode = file->f_mode;
845 }
846 return rc;
847}
848
849#define write_sq_init_waitqueue() sq_init_waitqueue(&write_sq)
850#if 0 /* blocking open() */
851#define write_sq_wake_up(file) sq_wake_up(&write_sq, file, FMODE_WRITE)
852#endif
853#define write_sq_release_buffers() sq_release_buffers(&write_sq)
854#define write_sq_open(file) \
855 sq_open2(&write_sq, file, FMODE_WRITE, numWriteBufs, writeBufSize )
856
857#ifdef HAS_RECORD
858#define read_sq_init_waitqueue() sq_init_waitqueue(&read_sq)
859#if 0 /* blocking open() */
860#define read_sq_wake_up(file) sq_wake_up(&read_sq, file, FMODE_READ)
861#endif
862#define read_sq_release_buffers() sq_release_buffers(&read_sq)
863#define read_sq_open(file) \
864 sq_open2(&read_sq, file, FMODE_READ, numReadBufs, readBufSize )
865#else
866#define read_sq_init_waitqueue() do {} while (0)
867#if 0 /* blocking open() */
868#define read_sq_wake_up(file) do {} while (0)
869#endif
870#define read_sq_release_buffers() do {} while (0)
871#define sq_reset_input() do {} while (0)
872#endif
873
874static int sq_open(struct inode *inode, struct file *file)
875{
876 int rc;
877
878 if (!try_module_get(dmasound.mach.owner))
879 return -ENODEV;
880
881 rc = write_sq_open(file); /* checks the f_mode */
882 if (rc)
883 goto out;
884#ifdef HAS_RECORD
885 if (dmasound.mach.record) {
886 rc = read_sq_open(file); /* checks the f_mode */
887 if (rc)
888 goto out;
889 } else { /* no record function installed; in compat mode */
890 if (file->f_mode & FMODE_READ) {
891 /* TODO: if O_RDWR, release any resources grabbed by write part */
892 rc = -ENXIO;
893 goto out;
894 }
895 }
896#else /* !HAS_RECORD */
897 if (file->f_mode & FMODE_READ) {
898 /* TODO: if O_RDWR, release any resources grabbed by write part */
899 rc = -ENXIO ; /* I think this is what is required by open(2) */
900 goto out;
901 }
902#endif /* HAS_RECORD */
903
904 if (dmasound.mach.sq_open)
905 dmasound.mach.sq_open(file->f_mode);
906
907 /* CHECK whether this is sensible - in the case that dsp0 could be opened
908 O_RDONLY and dsp1 could be opened O_WRONLY
909 */
910
911 dmasound.minDev = iminor(inode) & 0x0f;
912
913 /* OK. - we should make some attempt at consistency. At least the H'ware
914 options should be set with a valid mode. We will make it that the LL
915 driver must supply defaults for hard & soft params.
916 */
917
918 if (shared_resource_owner == 0) {
919 /* you can make this AFMT_U8/mono/8K if you want to mimic old
920 OSS behaviour - while we still have soft translations ;-) */
921 dmasound.soft = dmasound.mach.default_soft ;
922 dmasound.dsp = dmasound.mach.default_soft ;
923 dmasound.hard = dmasound.mach.default_hard ;
924 }
925
926#ifndef DMASOUND_STRICT_OSS_COMPLIANCE
927 /* none of the current LL drivers can actually do this "native" at the moment
928 OSS does not really require us to supply /dev/audio if we can't do it.
929 */
930 if (dmasound.minDev == SND_DEV_AUDIO) {
931 sound_set_speed(8000);
932 sound_set_stereo(0);
933 sound_set_format(AFMT_MU_LAW);
934 }
935#endif
936
937 return 0;
938 out:
939 module_put(dmasound.mach.owner);
940 return rc;
941}
942
943static void sq_reset_output(void)
944{
945 sound_silence(); /* this _must_ stop DMA, we might be about to lose the buffers */
946 write_sq.active = 0;
947 write_sq.count = 0;
948 write_sq.rear_size = 0;
949 /* write_sq.front = (write_sq.rear+1) % write_sq.max_count;*/
950 write_sq.front = 0 ;
951 write_sq.rear = -1 ; /* same as for set-up */
952
953 /* OK - we can unlock the parameters and fragment settings */
954 write_sq.locked = 0 ;
955 write_sq.user_frags = 0 ;
956 write_sq.user_frag_size = 0 ;
957}
958
959#ifdef HAS_RECORD
960
961static void sq_reset_input(void)
962{
963 if (dmasound.mach.record && read_sq.active) {
964 if (dmasound.mach.abort_read) { /* this routine must really be present */
965 read_sq.syncing = 1 ;
966 /* this can use the read_sq.sync_queue to sleep if
967 necessary - it should not return until DMA
968 is really stopped - because we might deallocate
969 the buffers as the next action...
970 */
971 dmasound.mach.abort_read() ;
972 } else {
973 printk(KERN_ERR
974 "dmasound_core: %s has no abort_read()!! all bets are off\n",
975 dmasound.mach.name) ;
976 }
977 }
978 read_sq.syncing =
979 read_sq.active =
980 read_sq.front =
981 read_sq.count =
982 read_sq.rear = 0 ;
983
984 /* OK - we can unlock the parameters and fragment settings */
985 read_sq.locked = 0 ;
986 read_sq.user_frags = 0 ;
987 read_sq.user_frag_size = 0 ;
988}
989
990#endif
991
992static void sq_reset(void)
993{
994 sq_reset_output() ;
995 sq_reset_input() ;
996 /* we could consider resetting the shared_resources_owner here... but I
997 think it is probably still rather non-obvious to application writer
998 */
999
1000 /* we release everything else though */
1001 shared_resources_initialised = 0 ;
1002}
1003
1004static int sq_fsync(struct file *filp, struct dentry *dentry)
1005{
1006 int rc = 0;
1007 int timeout = 5;
1008
1009 write_sq.syncing |= 1;
1010 sq_play(); /* there may be an incomplete frame waiting */
1011
1012 while (write_sq.active) {
1013 SLEEP(write_sq.sync_queue);
1014 if (signal_pending(current)) {
1015 /* While waiting for audio output to drain, an
1016 * interrupt occurred. Stop audio output immediately
1017 * and clear the queue. */
1018 sq_reset_output();
1019 rc = -EINTR;
1020 break;
1021 }
1022 if (!--timeout) {
1023 printk(KERN_WARNING "dmasound: Timeout draining output\n");
1024 sq_reset_output();
1025 rc = -EIO;
1026 break;
1027 }
1028 }
1029
1030 /* flag no sync regardless of whether we had a DSP_POST or not */
1031 write_sq.syncing = 0 ;
1032 return rc;
1033}
1034
1035static int sq_release(struct inode *inode, struct file *file)
1036{
1037 int rc = 0;
1038
1039 lock_kernel();
1040
1041#ifdef HAS_RECORD
1042 /* probably best to do the read side first - so that time taken to do it
1043 overlaps with playing any remaining output samples.
1044 */
1045 if (file->f_mode & FMODE_READ) {
1046 sq_reset_input() ; /* make sure dma is stopped and all is quiet */
1047 read_sq_release_buffers();
1048 read_sq.busy = 0;
1049 }
1050#endif
1051
1052 if (file->f_mode & FMODE_WRITE) {
1053 if (write_sq.busy)
1054 rc = sq_fsync(file, file->f_dentry);
1055
1056 sq_reset_output() ; /* make sure dma is stopped and all is quiet */
1057 write_sq_release_buffers();
1058 write_sq.busy = 0;
1059 }
1060
1061 if (file->f_mode & shared_resource_owner) { /* it's us that has them */
1062 shared_resource_owner = 0 ;
1063 shared_resources_initialised = 0 ;
1064 dmasound.hard = dmasound.mach.default_hard ;
1065 }
1066
1067 module_put(dmasound.mach.owner);
1068
1069#if 0 /* blocking open() */
1070 /* Wake up a process waiting for the queue being released.
1071 * Note: There may be several processes waiting for a call
1072 * to open() returning. */
1073
1074 /* Iain: hmm I don't understand this next comment ... */
1075 /* There is probably a DOS atack here. They change the mode flag. */
1076 /* XXX add check here,*/
1077 read_sq_wake_up(file); /* checks f_mode */
1078 write_sq_wake_up(file); /* checks f_mode */
1079#endif /* blocking open() */
1080
1081 unlock_kernel();
1082
1083 return rc;
1084}
1085
1086/* here we see if we have a right to modify format, channels, size and so on
1087 if no-one else has claimed it already then we do...
1088
1089 TODO: We might change this to mask O_RDWR such that only one or the other channel
1090 is the owner - if we have problems.
1091*/
1092
1093static int shared_resources_are_mine(mode_t md)
1094{
1095 if (shared_resource_owner)
1096 return (shared_resource_owner & md ) ;
1097 else {
1098 shared_resource_owner = md ;
1099 return 1 ;
1100 }
1101}
1102
1103/* if either queue is locked we must deny the right to change shared params
1104*/
1105
1106static int queues_are_quiescent(void)
1107{
1108#ifdef HAS_RECORD
1109 if (dmasound.mach.record)
1110 if (read_sq.locked)
1111 return 0 ;
1112#endif
1113 if (write_sq.locked)
1114 return 0 ;
1115 return 1 ;
1116}
1117
1118/* check and set a queue's fragments per user's wishes...
1119 we will check against the pre-defined literals and the actual sizes.
1120 This is a bit fraught - because soft translations can mess with our
1121 buffer requirements *after* this call - OSS says "call setfrags first"
1122*/
1123
1124/* It is possible to replace all the -EINVAL returns with an override that
1125 just puts the allowable value in. This may be what many OSS apps require
1126*/
1127
1128static int set_queue_frags(struct sound_queue *sq, int bufs, int size)
1129{
1130 if (sq->locked) {
1131#ifdef DEBUG_DMASOUND
1132printk("dmasound_core: tried to set_queue_frags on a locked queue\n") ;
1133#endif
1134 return -EINVAL ;
1135 }
1136
1137 if ((size < MIN_FRAG_SIZE) || (size > MAX_FRAG_SIZE))
1138 return -EINVAL ;
1139 size = (1<<size) ; /* now in bytes */
1140 if (size > sq->bufSize)
1141 return -EINVAL ; /* this might still not work */
1142
1143 if (bufs <= 0)
1144 return -EINVAL ;
1145 if (bufs > sq->numBufs) /* the user is allowed say "don't care" with 0x7fff */
1146 bufs = sq->numBufs ;
1147
1148 /* there is, currently, no way to specify max_active separately
1149 from max_count. This could be a LL driver issue - I guess
1150 if there is a requirement for these values to be different then
1151 we will have to pass that info. up to this level.
1152 */
1153 sq->user_frags =
1154 sq->max_active = bufs ;
1155 sq->user_frag_size = size ;
1156
1157 return 0 ;
1158}
1159
1160static int sq_ioctl(struct inode *inode, struct file *file, u_int cmd,
1161 u_long arg)
1162{
1163 int val, result;
1164 u_long fmt;
1165 int data;
1166 int size, nbufs;
1167 audio_buf_info info;
1168
1169 switch (cmd) {
1170 case SNDCTL_DSP_RESET:
1171 sq_reset();
1172 return 0;
1173 break ;
1174 case SNDCTL_DSP_GETFMTS:
1175 fmt = dmasound.mach.hardware_afmts ; /* this is what OSS says.. */
1176 return IOCTL_OUT(arg, fmt);
1177 break ;
1178 case SNDCTL_DSP_GETBLKSIZE:
1179 /* this should tell the caller about bytes that the app can
1180 read/write - the app doesn't care about our internal buffers.
1181 We force sq_setup() here as per OSS 1.1 (which should
1182 compute the values necessary).
1183 Since there is no mechanism to specify read/write separately, for
1184 fds opened O_RDWR, the write_sq values will, arbitrarily, overwrite
1185 the read_sq ones.
1186 */
1187 size = 0 ;
1188#ifdef HAS_RECORD
1189 if (dmasound.mach.record && (file->f_mode & FMODE_READ)) {
1190 if ( !read_sq.locked )
1191 sq_setup(&read_sq) ; /* set params */
1192 size = read_sq.user_frag_size ;
1193 }
1194#endif
1195 if (file->f_mode & FMODE_WRITE) {
1196 if ( !write_sq.locked )
1197 sq_setup(&write_sq) ;
1198 size = write_sq.user_frag_size ;
1199 }
1200 return IOCTL_OUT(arg, size);
1201 break ;
1202 case SNDCTL_DSP_POST:
1203 /* all we are going to do is to tell the LL that any
1204 partial frags can be queued for output.
1205 The LL will have to clear this flag when last output
1206 is queued.
1207 */
1208 write_sq.syncing |= 0x2 ;
1209 sq_play() ;
1210 return 0 ;
1211 case SNDCTL_DSP_SYNC:
1212 /* This call, effectively, has the same behaviour as SNDCTL_DSP_RESET
1213 except that it waits for output to finish before resetting
1214 everything - read, however, is killed imediately.
1215 */
1216 result = 0 ;
1217 if ((file->f_mode & FMODE_READ) && dmasound.mach.record)
1218 sq_reset_input() ;
1219 if (file->f_mode & FMODE_WRITE) {
1220 result = sq_fsync(file, file->f_dentry);
1221 sq_reset_output() ;
1222 }
1223 /* if we are the shared resource owner then release them */
1224 if (file->f_mode & shared_resource_owner)
1225 shared_resources_initialised = 0 ;
1226 return result ;
1227 break ;
1228 case SOUND_PCM_READ_RATE:
1229 return IOCTL_OUT(arg, dmasound.soft.speed);
1230 case SNDCTL_DSP_SPEED:
1231 /* changing this on the fly will have weird effects on the sound.
1232 Where there are rate conversions implemented in soft form - it
1233 will cause the _ctx_xxx() functions to be substituted.
1234 However, there doesn't appear to be any reason to dis-allow it from
1235 a driver pov.
1236 */
1237 if (shared_resources_are_mine(file->f_mode)) {
1238 IOCTL_IN(arg, data);
1239 data = sound_set_speed(data) ;
1240 shared_resources_initialised = 0 ;
1241 return IOCTL_OUT(arg, data);
1242 } else
1243 return -EINVAL ;
1244 break ;
1245 /* OSS says these next 4 actions are undefined when the device is
1246 busy/active - we will just return -EINVAL.
1247 To be allowed to change one - (a) you have to own the right
1248 (b) the queue(s) must be quiescent
1249 */
1250 case SNDCTL_DSP_STEREO:
1251 if (shared_resources_are_mine(file->f_mode) &&
1252 queues_are_quiescent()) {
1253 IOCTL_IN(arg, data);
1254 shared_resources_initialised = 0 ;
1255 return IOCTL_OUT(arg, sound_set_stereo(data));
1256 } else
1257 return -EINVAL ;
1258 break ;
1259 case SOUND_PCM_WRITE_CHANNELS:
1260 if (shared_resources_are_mine(file->f_mode) &&
1261 queues_are_quiescent()) {
1262 IOCTL_IN(arg, data);
1263 /* the user might ask for 20 channels, we will return 1 or 2 */
1264 shared_resources_initialised = 0 ;
1265 return IOCTL_OUT(arg, sound_set_stereo(data-1)+1);
1266 } else
1267 return -EINVAL ;
1268 break ;
1269 case SNDCTL_DSP_SETFMT:
1270 if (shared_resources_are_mine(file->f_mode) &&
1271 queues_are_quiescent()) {
1272 int format;
1273 IOCTL_IN(arg, data);
1274 shared_resources_initialised = 0 ;
1275 format = sound_set_format(data);
1276 result = IOCTL_OUT(arg, format);
1277 if (result < 0)
1278 return result;
1279 if (format != data && data != AFMT_QUERY)
1280 return -EINVAL;
1281 return 0;
1282 } else
1283 return -EINVAL ;
1284 case SNDCTL_DSP_SUBDIVIDE:
1285 return -EINVAL ;
1286 case SNDCTL_DSP_SETFRAGMENT:
1287 /* we can do this independently for the two queues - with the
1288 proviso that for fds opened O_RDWR we cannot separate the
1289 actions and both queues will be set per the last call.
1290 NOTE: this does *NOT* actually set the queue up - merely
1291 registers our intentions.
1292 */
1293 IOCTL_IN(arg, data);
1294 result = 0 ;
1295 nbufs = (data >> 16) & 0x7fff ; /* 0x7fff is 'use maximum' */
1296 size = data & 0xffff;
1297#ifdef HAS_RECORD
1298 if ((file->f_mode & FMODE_READ) && dmasound.mach.record) {
1299 result = set_queue_frags(&read_sq, nbufs, size) ;
1300 if (result)
1301 return result ;
1302 }
1303#endif
1304 if (file->f_mode & FMODE_WRITE) {
1305 result = set_queue_frags(&write_sq, nbufs, size) ;
1306 if (result)
1307 return result ;
1308 }
1309 /* NOTE: this return value is irrelevant - OSS specifically says that
1310 the value is 'random' and that the user _must_ check the actual
1311 frags values using SNDCTL_DSP_GETBLKSIZE or similar */
1312 return IOCTL_OUT(arg, data);
1313 break ;
1314 case SNDCTL_DSP_GETOSPACE:
1315 /*
1316 */
1317 if (file->f_mode & FMODE_WRITE) {
1318 if ( !write_sq.locked )
1319 sq_setup(&write_sq) ;
1320 info.fragments = write_sq.max_active - write_sq.count;
1321 info.fragstotal = write_sq.max_active;
1322 info.fragsize = write_sq.user_frag_size;
1323 info.bytes = info.fragments * info.fragsize;
1324 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1325 return -EFAULT;
1326 return 0;
1327 } else
1328 return -EINVAL ;
1329 break ;
1330 case SNDCTL_DSP_GETCAPS:
1331 val = dmasound.mach.capabilities & 0xffffff00;
1332 return IOCTL_OUT(arg,val);
1333
1334 default:
1335 return mixer_ioctl(inode, file, cmd, arg);
1336 }
1337 return -EINVAL;
1338}
1339
1340static struct file_operations sq_fops =
1341{
1342 .owner = THIS_MODULE,
1343 .llseek = no_llseek,
1344 .write = sq_write,
1345 .poll = sq_poll,
1346 .ioctl = sq_ioctl,
1347 .open = sq_open,
1348 .release = sq_release,
1349#ifdef HAS_RECORD
1350 .read = NULL /* default to no read for compat mode */
1351#endif
1352};
1353
1354static int sq_init(void)
1355{
1356#ifndef MODULE
1357 int sq_unit;
1358#endif
1359
1360#ifdef HAS_RECORD
1361 if (dmasound.mach.record)
1362 sq_fops.read = sq_read ;
1363#endif
1364 sq_unit = register_sound_dsp(&sq_fops, -1);
1365 if (sq_unit < 0) {
1366 printk(KERN_ERR "dmasound_core: couldn't register fops\n") ;
1367 return sq_unit ;
1368 }
1369
1370 write_sq_init_waitqueue();
1371 read_sq_init_waitqueue();
1372
1373 /* These parameters will be restored for every clean open()
1374 * in the case of multiple open()s (e.g. dsp0 & dsp1) they
1375 * will be set so long as the shared resources have no owner.
1376 */
1377
1378 if (shared_resource_owner == 0) {
1379 dmasound.soft = dmasound.mach.default_soft ;
1380 dmasound.hard = dmasound.mach.default_hard ;
1381 dmasound.dsp = dmasound.mach.default_soft ;
1382 shared_resources_initialised = 0 ;
1383 }
1384 return 0 ;
1385}
1386
1387
1388 /*
1389 * /dev/sndstat
1390 */
1391
1392/* we allow more space for record-enabled because there are extra output lines.
1393 the number here must include the amount we are prepared to give to the low-level
1394 driver.
1395*/
1396
1397#ifdef HAS_RECORD
1398#define STAT_BUFF_LEN 1024
1399#else
1400#define STAT_BUFF_LEN 768
1401#endif
1402
1403/* this is how much space we will allow the low-level driver to use
1404 in the stat buffer. Currently, 2 * (80 character line + <NL>).
1405 We do not police this (it is up to the ll driver to be honest).
1406*/
1407
1408#define LOW_LEVEL_STAT_ALLOC 162
1409
1410static struct {
1411 int busy;
1412 char buf[STAT_BUFF_LEN]; /* state.buf should not overflow! */
1413 int len, ptr;
1414} state;
1415
1416/* publish this function for use by low-level code, if required */
1417
1418char *get_afmt_string(int afmt)
1419{
1420 switch(afmt) {
1421 case AFMT_MU_LAW:
1422 return "mu-law";
1423 break;
1424 case AFMT_A_LAW:
1425 return "A-law";
1426 break;
1427 case AFMT_U8:
1428 return "unsigned 8 bit";
1429 break;
1430 case AFMT_S8:
1431 return "signed 8 bit";
1432 break;
1433 case AFMT_S16_BE:
1434 return "signed 16 bit BE";
1435 break;
1436 case AFMT_U16_BE:
1437 return "unsigned 16 bit BE";
1438 break;
1439 case AFMT_S16_LE:
1440 return "signed 16 bit LE";
1441 break;
1442 case AFMT_U16_LE:
1443 return "unsigned 16 bit LE";
1444 break;
1445 case 0:
1446 return "format not set" ;
1447 break ;
1448 default:
1449 break ;
1450 }
1451 return "ERROR: Unsupported AFMT_XXXX code" ;
1452}
1453
1454static int state_open(struct inode *inode, struct file *file)
1455{
1456 char *buffer = state.buf;
1457 int len = 0;
1458
1459 if (state.busy)
1460 return -EBUSY;
1461
1462 if (!try_module_get(dmasound.mach.owner))
1463 return -ENODEV;
1464 state.ptr = 0;
1465 state.busy = 1;
1466
1467 len += sprintf(buffer+len, "%sDMA sound driver rev %03d :\n",
1468 dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) +
1469 ((dmasound.mach.version>>8) & 0x0f));
1470 len += sprintf(buffer+len,
1471 "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n",
1472 DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2,
1473 (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ;
1474
1475 /* call the low-level module to fill in any stat info. that it has
1476 if present. Maximum buffer usage is specified.
1477 */
1478
1479 if (dmasound.mach.state_info)
1480 len += dmasound.mach.state_info(buffer+len,
1481 (size_t) LOW_LEVEL_STAT_ALLOC) ;
1482
1483 /* make usage of the state buffer as deterministic as poss.
1484 exceptional conditions could cause overrun - and this is flagged as
1485 a kernel error.
1486 */
1487
1488 /* formats and settings */
1489
1490 len += sprintf(buffer+len,"\t\t === Formats & settings ===\n") ;
1491 len += sprintf(buffer+len,"Parameter %20s%20s\n","soft","hard") ;
1492 len += sprintf(buffer+len,"Format :%20s%20s\n",
1493 get_afmt_string(dmasound.soft.format),
1494 get_afmt_string(dmasound.hard.format));
1495
1496 len += sprintf(buffer+len,"Samp Rate:%14d s/sec%14d s/sec\n",
1497 dmasound.soft.speed, dmasound.hard.speed);
1498
1499 len += sprintf(buffer+len,"Channels :%20s%20s\n",
1500 dmasound.soft.stereo ? "stereo" : "mono",
1501 dmasound.hard.stereo ? "stereo" : "mono" );
1502
1503 /* sound queue status */
1504
1505 len += sprintf(buffer+len,"\t\t === Sound Queue status ===\n");
1506 len += sprintf(buffer+len,"Allocated:%8s%6s\n","Buffers","Size") ;
1507 len += sprintf(buffer+len,"%9s:%8d%6d\n",
1508 "write", write_sq.numBufs, write_sq.bufSize) ;
1509#ifdef HAS_RECORD
1510 if (dmasound.mach.record)
1511 len += sprintf(buffer+len,"%9s:%8d%6d\n",
1512 "read", read_sq.numBufs, read_sq.bufSize) ;
1513#endif
1514 len += sprintf(buffer+len,
1515 "Current : MaxFrg FragSiz MaxAct Frnt Rear "
1516 "Cnt RrSize A B S L xruns\n") ;
1517 len += sprintf(buffer+len,"%9s:%7d%8d%7d%5d%5d%4d%7d%2d%2d%2d%2d%7d\n",
1518 "write", write_sq.max_count, write_sq.block_size,
1519 write_sq.max_active, write_sq.front, write_sq.rear,
1520 write_sq.count, write_sq.rear_size, write_sq.active,
1521 write_sq.busy, write_sq.syncing, write_sq.locked, write_sq.xruns) ;
1522#ifdef HAS_RECORD
1523 if (dmasound.mach.record)
1524 len += sprintf(buffer+len,"%9s:%7d%8d%7d%5d%5d%4d%7d%2d%2d%2d%2d%7d\n",
1525 "read", read_sq.max_count, read_sq.block_size,
1526 read_sq.max_active, read_sq.front, read_sq.rear,
1527 read_sq.count, read_sq.rear_size, read_sq.active,
1528 read_sq.busy, read_sq.syncing, read_sq.locked, read_sq.xruns) ;
1529#endif
1530#ifdef DEBUG_DMASOUND
1531printk("dmasound: stat buffer used %d bytes\n", len) ;
1532#endif
1533
1534 if (len >= STAT_BUFF_LEN)
1535 printk(KERN_ERR "dmasound_core: stat buffer overflowed!\n");
1536
1537 state.len = len;
1538 return 0;
1539}
1540
1541static int state_release(struct inode *inode, struct file *file)
1542{
1543 lock_kernel();
1544 state.busy = 0;
1545 module_put(dmasound.mach.owner);
1546 unlock_kernel();
1547 return 0;
1548}
1549
1550static ssize_t state_read(struct file *file, char __user *buf, size_t count,
1551 loff_t *ppos)
1552{
1553 int n = state.len - state.ptr;
1554 if (n > count)
1555 n = count;
1556 if (n <= 0)
1557 return 0;
1558 if (copy_to_user(buf, &state.buf[state.ptr], n))
1559 return -EFAULT;
1560 state.ptr += n;
1561 return n;
1562}
1563
1564static struct file_operations state_fops = {
1565 .owner = THIS_MODULE,
1566 .llseek = no_llseek,
1567 .read = state_read,
1568 .open = state_open,
1569 .release = state_release,
1570};
1571
1572static int state_init(void)
1573{
1574#ifndef MODULE
1575 int state_unit;
1576#endif
1577 state_unit = register_sound_special(&state_fops, SND_DEV_STATUS);
1578 if (state_unit < 0)
1579 return state_unit ;
1580 state.busy = 0;
1581 return 0 ;
1582}
1583
1584
1585 /*
1586 * Config & Setup
1587 *
1588 * This function is called by _one_ chipset-specific driver
1589 */
1590
1591int dmasound_init(void)
1592{
1593 int res ;
1594#ifdef MODULE
1595 if (irq_installed)
1596 return -EBUSY;
1597#endif
1598
1599 /* Set up sound queue, /dev/audio and /dev/dsp. */
1600
1601 /* Set default settings. */
1602 if ((res = sq_init()) < 0)
1603 return res ;
1604
1605 /* Set up /dev/sndstat. */
1606 if ((res = state_init()) < 0)
1607 return res ;
1608
1609 /* Set up /dev/mixer. */
1610 mixer_init();
1611
1612 if (!dmasound.mach.irqinit()) {
1613 printk(KERN_ERR "DMA sound driver: Interrupt initialization failed\n");
1614 return -ENODEV;
1615 }
1616#ifdef MODULE
1617 irq_installed = 1;
1618#endif
1619
1620 printk(KERN_INFO "%s DMA sound driver rev %03d installed\n",
1621 dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) +
1622 ((dmasound.mach.version>>8) & 0x0f));
1623 printk(KERN_INFO
1624 "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n",
1625 DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2,
1626 (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ;
1627 printk(KERN_INFO "Write will use %4d fragments of %7d bytes as default\n",
1628 numWriteBufs, writeBufSize) ;
1629#ifdef HAS_RECORD
1630 if (dmasound.mach.record)
1631 printk(KERN_INFO
1632 "Read will use %4d fragments of %7d bytes as default\n",
1633 numReadBufs, readBufSize) ;
1634#endif
1635
1636 return 0;
1637}
1638
1639#ifdef MODULE
1640
1641void dmasound_deinit(void)
1642{
1643 if (irq_installed) {
1644 sound_silence();
1645 dmasound.mach.irqcleanup();
1646 irq_installed = 0;
1647 }
1648
1649 write_sq_release_buffers();
1650 read_sq_release_buffers();
1651
1652 if (mixer_unit >= 0)
1653 unregister_sound_mixer(mixer_unit);
1654 if (state_unit >= 0)
1655 unregister_sound_special(state_unit);
1656 if (sq_unit >= 0)
1657 unregister_sound_dsp(sq_unit);
1658}
1659
1660#else /* !MODULE */
1661
1662static int dmasound_setup(char *str)
1663{
1664 int ints[6], size;
1665
1666 str = get_options(str, ARRAY_SIZE(ints), ints);
1667
1668 /* check the bootstrap parameter for "dmasound=" */
1669
1670 /* FIXME: other than in the most naive of cases there is no sense in these
1671 * buffers being other than powers of two. This is not checked yet.
1672 */
1673
1674 switch (ints[0]) {
1675#ifdef HAS_RECORD
1676 case 5:
1677 if ((ints[5] < 0) || (ints[5] > MAX_CATCH_RADIUS))
1678 printk("dmasound_setup: invalid catch radius, using default = %d\n", catchRadius);
1679 else
1680 catchRadius = ints[5];
1681 /* fall through */
1682 case 4:
1683 if (ints[4] < MIN_BUFFERS)
1684 printk("dmasound_setup: invalid number of read buffers, using default = %d\n",
1685 numReadBufs);
1686 else
1687 numReadBufs = ints[4];
1688 /* fall through */
1689 case 3:
1690 if ((size = ints[3]) < 256) /* check for small buffer specs */
1691 size <<= 10 ;
1692 if (size < MIN_BUFSIZE || size > MAX_BUFSIZE)
1693 printk("dmasound_setup: invalid read buffer size, using default = %d\n", readBufSize);
1694 else
1695 readBufSize = size;
1696 /* fall through */
1697#else
1698 case 3:
1699 if ((ints[3] < 0) || (ints[3] > MAX_CATCH_RADIUS))
1700 printk("dmasound_setup: invalid catch radius, using default = %d\n", catchRadius);
1701 else
1702 catchRadius = ints[3];
1703 /* fall through */
1704#endif
1705 case 2:
1706 if (ints[1] < MIN_BUFFERS)
1707 printk("dmasound_setup: invalid number of buffers, using default = %d\n", numWriteBufs);
1708 else
1709 numWriteBufs = ints[1];
1710 /* fall through */
1711 case 1:
1712 if ((size = ints[2]) < 256) /* check for small buffer specs */
1713 size <<= 10 ;
1714 if (size < MIN_BUFSIZE || size > MAX_BUFSIZE)
1715 printk("dmasound_setup: invalid write buffer size, using default = %d\n", writeBufSize);
1716 else
1717 writeBufSize = size;
1718 case 0:
1719 break;
1720 default:
1721 printk("dmasound_setup: invalid number of arguments\n");
1722 return 0;
1723 }
1724 return 1;
1725}
1726
1727__setup("dmasound=", dmasound_setup);
1728
1729#endif /* !MODULE */
1730
1731 /*
1732 * Conversion tables
1733 */
1734
1735#ifdef HAS_8BIT_TABLES
1736/* 8 bit mu-law */
1737
1738char dmasound_ulaw2dma8[] = {
1739 -126, -122, -118, -114, -110, -106, -102, -98,
1740 -94, -90, -86, -82, -78, -74, -70, -66,
1741 -63, -61, -59, -57, -55, -53, -51, -49,
1742 -47, -45, -43, -41, -39, -37, -35, -33,
1743 -31, -30, -29, -28, -27, -26, -25, -24,
1744 -23, -22, -21, -20, -19, -18, -17, -16,
1745 -16, -15, -15, -14, -14, -13, -13, -12,
1746 -12, -11, -11, -10, -10, -9, -9, -8,
1747 -8, -8, -7, -7, -7, -7, -6, -6,
1748 -6, -6, -5, -5, -5, -5, -4, -4,
1749 -4, -4, -4, -4, -3, -3, -3, -3,
1750 -3, -3, -3, -3, -2, -2, -2, -2,
1751 -2, -2, -2, -2, -2, -2, -2, -2,
1752 -1, -1, -1, -1, -1, -1, -1, -1,
1753 -1, -1, -1, -1, -1, -1, -1, -1,
1754 -1, -1, -1, -1, -1, -1, -1, 0,
1755 125, 121, 117, 113, 109, 105, 101, 97,
1756 93, 89, 85, 81, 77, 73, 69, 65,
1757 62, 60, 58, 56, 54, 52, 50, 48,
1758 46, 44, 42, 40, 38, 36, 34, 32,
1759 30, 29, 28, 27, 26, 25, 24, 23,
1760 22, 21, 20, 19, 18, 17, 16, 15,
1761 15, 14, 14, 13, 13, 12, 12, 11,
1762 11, 10, 10, 9, 9, 8, 8, 7,
1763 7, 7, 6, 6, 6, 6, 5, 5,
1764 5, 5, 4, 4, 4, 4, 3, 3,
1765 3, 3, 3, 3, 2, 2, 2, 2,
1766 2, 2, 2, 2, 1, 1, 1, 1,
1767 1, 1, 1, 1, 1, 1, 1, 1,
1768 0, 0, 0, 0, 0, 0, 0, 0,
1769 0, 0, 0, 0, 0, 0, 0, 0,
1770 0, 0, 0, 0, 0, 0, 0, 0
1771};
1772
1773/* 8 bit A-law */
1774
1775char dmasound_alaw2dma8[] = {
1776 -22, -21, -24, -23, -18, -17, -20, -19,
1777 -30, -29, -32, -31, -26, -25, -28, -27,
1778 -11, -11, -12, -12, -9, -9, -10, -10,
1779 -15, -15, -16, -16, -13, -13, -14, -14,
1780 -86, -82, -94, -90, -70, -66, -78, -74,
1781 -118, -114, -126, -122, -102, -98, -110, -106,
1782 -43, -41, -47, -45, -35, -33, -39, -37,
1783 -59, -57, -63, -61, -51, -49, -55, -53,
1784 -2, -2, -2, -2, -2, -2, -2, -2,
1785 -2, -2, -2, -2, -2, -2, -2, -2,
1786 -1, -1, -1, -1, -1, -1, -1, -1,
1787 -1, -1, -1, -1, -1, -1, -1, -1,
1788 -6, -6, -6, -6, -5, -5, -5, -5,
1789 -8, -8, -8, -8, -7, -7, -7, -7,
1790 -3, -3, -3, -3, -3, -3, -3, -3,
1791 -4, -4, -4, -4, -4, -4, -4, -4,
1792 21, 20, 23, 22, 17, 16, 19, 18,
1793 29, 28, 31, 30, 25, 24, 27, 26,
1794 10, 10, 11, 11, 8, 8, 9, 9,
1795 14, 14, 15, 15, 12, 12, 13, 13,
1796 86, 82, 94, 90, 70, 66, 78, 74,
1797 118, 114, 126, 122, 102, 98, 110, 106,
1798 43, 41, 47, 45, 35, 33, 39, 37,
1799 59, 57, 63, 61, 51, 49, 55, 53,
1800 1, 1, 1, 1, 1, 1, 1, 1,
1801 1, 1, 1, 1, 1, 1, 1, 1,
1802 0, 0, 0, 0, 0, 0, 0, 0,
1803 0, 0, 0, 0, 0, 0, 0, 0,
1804 5, 5, 5, 5, 4, 4, 4, 4,
1805 7, 7, 7, 7, 6, 6, 6, 6,
1806 2, 2, 2, 2, 2, 2, 2, 2,
1807 3, 3, 3, 3, 3, 3, 3, 3
1808};
1809#endif /* HAS_8BIT_TABLES */
1810
1811 /*
1812 * Visible symbols for modules
1813 */
1814
1815EXPORT_SYMBOL(dmasound);
1816EXPORT_SYMBOL(dmasound_init);
1817#ifdef MODULE
1818EXPORT_SYMBOL(dmasound_deinit);
1819#endif
1820EXPORT_SYMBOL(dmasound_write_sq);
1821#ifdef HAS_RECORD
1822EXPORT_SYMBOL(dmasound_read_sq);
1823#endif
1824EXPORT_SYMBOL(dmasound_catchRadius);
1825#ifdef HAS_8BIT_TABLES
1826EXPORT_SYMBOL(dmasound_ulaw2dma8);
1827EXPORT_SYMBOL(dmasound_alaw2dma8);
1828#endif
1829EXPORT_SYMBOL(get_afmt_string) ;
diff --git a/sound/oss/dmasound/dmasound_paula.c b/sound/oss/dmasound/dmasound_paula.c
new file mode 100644
index 000000000000..558db5311e06
--- /dev/null
+++ b/sound/oss/dmasound/dmasound_paula.c
@@ -0,0 +1,743 @@
1/*
2 * linux/sound/oss/dmasound/dmasound_paula.c
3 *
4 * Amiga `Paula' DMA Sound Driver
5 *
6 * See linux/sound/oss/dmasound/dmasound_core.c for copyright and credits
7 * prior to 28/01/2001
8 *
9 * 28/01/2001 [0.1] Iain Sandoe
10 * - added versioning
11 * - put in and populated the hardware_afmts field.
12 * [0.2] - put in SNDCTL_DSP_GETCAPS value.
13 * [0.3] - put in constraint on state buffer usage.
14 * [0.4] - put in default hard/soft settings
15*/
16
17
18#include <linux/module.h>
19#include <linux/config.h>
20#include <linux/mm.h>
21#include <linux/init.h>
22#include <linux/ioport.h>
23#include <linux/soundcard.h>
24#include <linux/interrupt.h>
25
26#include <asm/uaccess.h>
27#include <asm/setup.h>
28#include <asm/amigahw.h>
29#include <asm/amigaints.h>
30#include <asm/machdep.h>
31
32#include "dmasound.h"
33
34#define DMASOUND_PAULA_REVISION 0
35#define DMASOUND_PAULA_EDITION 4
36
37 /*
38 * The minimum period for audio depends on htotal (for OCS/ECS/AGA)
39 * (Imported from arch/m68k/amiga/amisound.c)
40 */
41
42extern volatile u_short amiga_audio_min_period;
43
44
45 /*
46 * amiga_mksound() should be able to restore the period after beeping
47 * (Imported from arch/m68k/amiga/amisound.c)
48 */
49
50extern u_short amiga_audio_period;
51
52
53 /*
54 * Audio DMA masks
55 */
56
57#define AMI_AUDIO_OFF (DMAF_AUD0 | DMAF_AUD1 | DMAF_AUD2 | DMAF_AUD3)
58#define AMI_AUDIO_8 (DMAF_SETCLR | DMAF_MASTER | DMAF_AUD0 | DMAF_AUD1)
59#define AMI_AUDIO_14 (AMI_AUDIO_8 | DMAF_AUD2 | DMAF_AUD3)
60
61
62 /*
63 * Helper pointers for 16(14)-bit sound
64 */
65
66static int write_sq_block_size_half, write_sq_block_size_quarter;
67
68
69/*** Low level stuff *********************************************************/
70
71
72static void *AmiAlloc(unsigned int size, int flags);
73static void AmiFree(void *obj, unsigned int size);
74static int AmiIrqInit(void);
75#ifdef MODULE
76static void AmiIrqCleanUp(void);
77#endif
78static void AmiSilence(void);
79static void AmiInit(void);
80static int AmiSetFormat(int format);
81static int AmiSetVolume(int volume);
82static int AmiSetTreble(int treble);
83static void AmiPlayNextFrame(int index);
84static void AmiPlay(void);
85static irqreturn_t AmiInterrupt(int irq, void *dummy, struct pt_regs *fp);
86
87#ifdef CONFIG_HEARTBEAT
88
89 /*
90 * Heartbeat interferes with sound since the 7 kHz low-pass filter and the
91 * power LED are controlled by the same line.
92 */
93
94#ifdef CONFIG_APUS
95#define mach_heartbeat ppc_md.heartbeat
96#endif
97
98static void (*saved_heartbeat)(int) = NULL;
99
100static inline void disable_heartbeat(void)
101{
102 if (mach_heartbeat) {
103 saved_heartbeat = mach_heartbeat;
104 mach_heartbeat = NULL;
105 }
106 AmiSetTreble(dmasound.treble);
107}
108
109static inline void enable_heartbeat(void)
110{
111 if (saved_heartbeat)
112 mach_heartbeat = saved_heartbeat;
113}
114#else /* !CONFIG_HEARTBEAT */
115#define disable_heartbeat() do { } while (0)
116#define enable_heartbeat() do { } while (0)
117#endif /* !CONFIG_HEARTBEAT */
118
119
120/*** Mid level stuff *********************************************************/
121
122static void AmiMixerInit(void);
123static int AmiMixerIoctl(u_int cmd, u_long arg);
124static int AmiWriteSqSetup(void);
125static int AmiStateInfo(char *buffer, size_t space);
126
127
128/*** Translations ************************************************************/
129
130/* ++TeSche: radically changed for new expanding purposes...
131 *
132 * These two routines now deal with copying/expanding/translating the samples
133 * from user space into our buffer at the right frequency. They take care about
134 * how much data there's actually to read, how much buffer space there is and
135 * to convert samples into the right frequency/encoding. They will only work on
136 * complete samples so it may happen they leave some bytes in the input stream
137 * if the user didn't write a multiple of the current sample size. They both
138 * return the number of bytes they've used from both streams so you may detect
139 * such a situation. Luckily all programs should be able to cope with that.
140 *
141 * I think I've optimized anything as far as one can do in plain C, all
142 * variables should fit in registers and the loops are really short. There's
143 * one loop for every possible situation. Writing a more generalized and thus
144 * parameterized loop would only produce slower code. Feel free to optimize
145 * this in assembler if you like. :)
146 *
147 * I think these routines belong here because they're not yet really hardware
148 * independent, especially the fact that the Falcon can play 16bit samples
149 * only in stereo is hardcoded in both of them!
150 *
151 * ++geert: split in even more functions (one per format)
152 */
153
154
155 /*
156 * Native format
157 */
158
159static ssize_t ami_ct_s8(const u_char *userPtr, size_t userCount,
160 u_char frame[], ssize_t *frameUsed, ssize_t frameLeft)
161{
162 ssize_t count, used;
163
164 if (!dmasound.soft.stereo) {
165 void *p = &frame[*frameUsed];
166 count = min_t(unsigned long, userCount, frameLeft) & ~1;
167 used = count;
168 if (copy_from_user(p, userPtr, count))
169 return -EFAULT;
170 } else {
171 u_char *left = &frame[*frameUsed>>1];
172 u_char *right = left+write_sq_block_size_half;
173 count = min_t(unsigned long, userCount, frameLeft)>>1 & ~1;
174 used = count*2;
175 while (count > 0) {
176 if (get_user(*left++, userPtr++)
177 || get_user(*right++, userPtr++))
178 return -EFAULT;
179 count--;
180 }
181 }
182 *frameUsed += used;
183 return used;
184}
185
186
187 /*
188 * Copy and convert 8 bit data
189 */
190
191#define GENERATE_AMI_CT8(funcname, convsample) \
192static ssize_t funcname(const u_char *userPtr, size_t userCount, \
193 u_char frame[], ssize_t *frameUsed, \
194 ssize_t frameLeft) \
195{ \
196 ssize_t count, used; \
197 \
198 if (!dmasound.soft.stereo) { \
199 u_char *p = &frame[*frameUsed]; \
200 count = min_t(size_t, userCount, frameLeft) & ~1; \
201 used = count; \
202 while (count > 0) { \
203 u_char data; \
204 if (get_user(data, userPtr++)) \
205 return -EFAULT; \
206 *p++ = convsample(data); \
207 count--; \
208 } \
209 } else { \
210 u_char *left = &frame[*frameUsed>>1]; \
211 u_char *right = left+write_sq_block_size_half; \
212 count = min_t(size_t, userCount, frameLeft)>>1 & ~1; \
213 used = count*2; \
214 while (count > 0) { \
215 u_char data; \
216 if (get_user(data, userPtr++)) \
217 return -EFAULT; \
218 *left++ = convsample(data); \
219 if (get_user(data, userPtr++)) \
220 return -EFAULT; \
221 *right++ = convsample(data); \
222 count--; \
223 } \
224 } \
225 *frameUsed += used; \
226 return used; \
227}
228
229#define AMI_CT_ULAW(x) (dmasound_ulaw2dma8[(x)])
230#define AMI_CT_ALAW(x) (dmasound_alaw2dma8[(x)])
231#define AMI_CT_U8(x) ((x) ^ 0x80)
232
233GENERATE_AMI_CT8(ami_ct_ulaw, AMI_CT_ULAW)
234GENERATE_AMI_CT8(ami_ct_alaw, AMI_CT_ALAW)
235GENERATE_AMI_CT8(ami_ct_u8, AMI_CT_U8)
236
237
238 /*
239 * Copy and convert 16 bit data
240 */
241
242#define GENERATE_AMI_CT_16(funcname, convsample) \
243static ssize_t funcname(const u_char *userPtr, size_t userCount, \
244 u_char frame[], ssize_t *frameUsed, \
245 ssize_t frameLeft) \
246{ \
247 ssize_t count, used; \
248 u_short data; \
249 \
250 if (!dmasound.soft.stereo) { \
251 u_char *high = &frame[*frameUsed>>1]; \
252 u_char *low = high+write_sq_block_size_half; \
253 count = min_t(size_t, userCount, frameLeft)>>1 & ~1; \
254 used = count*2; \
255 while (count > 0) { \
256 if (get_user(data, ((u_short *)userPtr)++)) \
257 return -EFAULT; \
258 data = convsample(data); \
259 *high++ = data>>8; \
260 *low++ = (data>>2) & 0x3f; \
261 count--; \
262 } \
263 } else { \
264 u_char *lefth = &frame[*frameUsed>>2]; \
265 u_char *leftl = lefth+write_sq_block_size_quarter; \
266 u_char *righth = lefth+write_sq_block_size_half; \
267 u_char *rightl = righth+write_sq_block_size_quarter; \
268 count = min_t(size_t, userCount, frameLeft)>>2 & ~1; \
269 used = count*4; \
270 while (count > 0) { \
271 if (get_user(data, ((u_short *)userPtr)++)) \
272 return -EFAULT; \
273 data = convsample(data); \
274 *lefth++ = data>>8; \
275 *leftl++ = (data>>2) & 0x3f; \
276 if (get_user(data, ((u_short *)userPtr)++)) \
277 return -EFAULT; \
278 data = convsample(data); \
279 *righth++ = data>>8; \
280 *rightl++ = (data>>2) & 0x3f; \
281 count--; \
282 } \
283 } \
284 *frameUsed += used; \
285 return used; \
286}
287
288#define AMI_CT_S16BE(x) (x)
289#define AMI_CT_U16BE(x) ((x) ^ 0x8000)
290#define AMI_CT_S16LE(x) (le2be16((x)))
291#define AMI_CT_U16LE(x) (le2be16((x)) ^ 0x8000)
292
293GENERATE_AMI_CT_16(ami_ct_s16be, AMI_CT_S16BE)
294GENERATE_AMI_CT_16(ami_ct_u16be, AMI_CT_U16BE)
295GENERATE_AMI_CT_16(ami_ct_s16le, AMI_CT_S16LE)
296GENERATE_AMI_CT_16(ami_ct_u16le, AMI_CT_U16LE)
297
298
299static TRANS transAmiga = {
300 .ct_ulaw = ami_ct_ulaw,
301 .ct_alaw = ami_ct_alaw,
302 .ct_s8 = ami_ct_s8,
303 .ct_u8 = ami_ct_u8,
304 .ct_s16be = ami_ct_s16be,
305 .ct_u16be = ami_ct_u16be,
306 .ct_s16le = ami_ct_s16le,
307 .ct_u16le = ami_ct_u16le,
308};
309
310/*** Low level stuff *********************************************************/
311
312static inline void StopDMA(void)
313{
314 custom.aud[0].audvol = custom.aud[1].audvol = 0;
315 custom.aud[2].audvol = custom.aud[3].audvol = 0;
316 custom.dmacon = AMI_AUDIO_OFF;
317 enable_heartbeat();
318}
319
320static void *AmiAlloc(unsigned int size, int flags)
321{
322 return amiga_chip_alloc((long)size, "dmasound [Paula]");
323}
324
325static void AmiFree(void *obj, unsigned int size)
326{
327 amiga_chip_free (obj);
328}
329
330static int __init AmiIrqInit(void)
331{
332 /* turn off DMA for audio channels */
333 StopDMA();
334
335 /* Register interrupt handler. */
336 if (request_irq(IRQ_AMIGA_AUD0, AmiInterrupt, 0, "DMA sound",
337 AmiInterrupt))
338 return 0;
339 return 1;
340}
341
342#ifdef MODULE
343static void AmiIrqCleanUp(void)
344{
345 /* turn off DMA for audio channels */
346 StopDMA();
347 /* release the interrupt */
348 free_irq(IRQ_AMIGA_AUD0, AmiInterrupt);
349}
350#endif /* MODULE */
351
352static void AmiSilence(void)
353{
354 /* turn off DMA for audio channels */
355 StopDMA();
356}
357
358
359static void AmiInit(void)
360{
361 int period, i;
362
363 AmiSilence();
364
365 if (dmasound.soft.speed)
366 period = amiga_colorclock/dmasound.soft.speed-1;
367 else
368 period = amiga_audio_min_period;
369 dmasound.hard = dmasound.soft;
370 dmasound.trans_write = &transAmiga;
371
372 if (period < amiga_audio_min_period) {
373 /* we would need to squeeze the sound, but we won't do that */
374 period = amiga_audio_min_period;
375 } else if (period > 65535) {
376 period = 65535;
377 }
378 dmasound.hard.speed = amiga_colorclock/(period+1);
379
380 for (i = 0; i < 4; i++)
381 custom.aud[i].audper = period;
382 amiga_audio_period = period;
383}
384
385
386static int AmiSetFormat(int format)
387{
388 int size;
389
390 /* Amiga sound DMA supports 8bit and 16bit (pseudo 14 bit) modes */
391
392 switch (format) {
393 case AFMT_QUERY:
394 return dmasound.soft.format;
395 case AFMT_MU_LAW:
396 case AFMT_A_LAW:
397 case AFMT_U8:
398 case AFMT_S8:
399 size = 8;
400 break;
401 case AFMT_S16_BE:
402 case AFMT_U16_BE:
403 case AFMT_S16_LE:
404 case AFMT_U16_LE:
405 size = 16;
406 break;
407 default: /* :-) */
408 size = 8;
409 format = AFMT_S8;
410 }
411
412 dmasound.soft.format = format;
413 dmasound.soft.size = size;
414 if (dmasound.minDev == SND_DEV_DSP) {
415 dmasound.dsp.format = format;
416 dmasound.dsp.size = dmasound.soft.size;
417 }
418 AmiInit();
419
420 return format;
421}
422
423
424#define VOLUME_VOXWARE_TO_AMI(v) \
425 (((v) < 0) ? 0 : ((v) > 100) ? 64 : ((v) * 64)/100)
426#define VOLUME_AMI_TO_VOXWARE(v) ((v)*100/64)
427
428static int AmiSetVolume(int volume)
429{
430 dmasound.volume_left = VOLUME_VOXWARE_TO_AMI(volume & 0xff);
431 custom.aud[0].audvol = dmasound.volume_left;
432 dmasound.volume_right = VOLUME_VOXWARE_TO_AMI((volume & 0xff00) >> 8);
433 custom.aud[1].audvol = dmasound.volume_right;
434 if (dmasound.hard.size == 16) {
435 if (dmasound.volume_left == 64 && dmasound.volume_right == 64) {
436 custom.aud[2].audvol = 1;
437 custom.aud[3].audvol = 1;
438 } else {
439 custom.aud[2].audvol = 0;
440 custom.aud[3].audvol = 0;
441 }
442 }
443 return VOLUME_AMI_TO_VOXWARE(dmasound.volume_left) |
444 (VOLUME_AMI_TO_VOXWARE(dmasound.volume_right) << 8);
445}
446
447static int AmiSetTreble(int treble)
448{
449 dmasound.treble = treble;
450 if (treble < 50)
451 ciaa.pra &= ~0x02;
452 else
453 ciaa.pra |= 0x02;
454 return treble;
455}
456
457
458#define AMI_PLAY_LOADED 1
459#define AMI_PLAY_PLAYING 2
460#define AMI_PLAY_MASK 3
461
462
463static void AmiPlayNextFrame(int index)
464{
465 u_char *start, *ch0, *ch1, *ch2, *ch3;
466 u_long size;
467
468 /* used by AmiPlay() if all doubts whether there really is something
469 * to be played are already wiped out.
470 */
471 start = write_sq.buffers[write_sq.front];
472 size = (write_sq.count == index ? write_sq.rear_size
473 : write_sq.block_size)>>1;
474
475 if (dmasound.hard.stereo) {
476 ch0 = start;
477 ch1 = start+write_sq_block_size_half;
478 size >>= 1;
479 } else {
480 ch0 = start;
481 ch1 = start;
482 }
483
484 disable_heartbeat();
485 custom.aud[0].audvol = dmasound.volume_left;
486 custom.aud[1].audvol = dmasound.volume_right;
487 if (dmasound.hard.size == 8) {
488 custom.aud[0].audlc = (u_short *)ZTWO_PADDR(ch0);
489 custom.aud[0].audlen = size;
490 custom.aud[1].audlc = (u_short *)ZTWO_PADDR(ch1);
491 custom.aud[1].audlen = size;
492 custom.dmacon = AMI_AUDIO_8;
493 } else {
494 size >>= 1;
495 custom.aud[0].audlc = (u_short *)ZTWO_PADDR(ch0);
496 custom.aud[0].audlen = size;
497 custom.aud[1].audlc = (u_short *)ZTWO_PADDR(ch1);
498 custom.aud[1].audlen = size;
499 if (dmasound.volume_left == 64 && dmasound.volume_right == 64) {
500 /* We can play pseudo 14-bit only with the maximum volume */
501 ch3 = ch0+write_sq_block_size_quarter;
502 ch2 = ch1+write_sq_block_size_quarter;
503 custom.aud[2].audvol = 1; /* we are being affected by the beeps */
504 custom.aud[3].audvol = 1; /* restoring volume here helps a bit */
505 custom.aud[2].audlc = (u_short *)ZTWO_PADDR(ch2);
506 custom.aud[2].audlen = size;
507 custom.aud[3].audlc = (u_short *)ZTWO_PADDR(ch3);
508 custom.aud[3].audlen = size;
509 custom.dmacon = AMI_AUDIO_14;
510 } else {
511 custom.aud[2].audvol = 0;
512 custom.aud[3].audvol = 0;
513 custom.dmacon = AMI_AUDIO_8;
514 }
515 }
516 write_sq.front = (write_sq.front+1) % write_sq.max_count;
517 write_sq.active |= AMI_PLAY_LOADED;
518}
519
520
521static void AmiPlay(void)
522{
523 int minframes = 1;
524
525 custom.intena = IF_AUD0;
526
527 if (write_sq.active & AMI_PLAY_LOADED) {
528 /* There's already a frame loaded */
529 custom.intena = IF_SETCLR | IF_AUD0;
530 return;
531 }
532
533 if (write_sq.active & AMI_PLAY_PLAYING)
534 /* Increase threshold: frame 1 is already being played */
535 minframes = 2;
536
537 if (write_sq.count < minframes) {
538 /* Nothing to do */
539 custom.intena = IF_SETCLR | IF_AUD0;
540 return;
541 }
542
543 if (write_sq.count <= minframes &&
544 write_sq.rear_size < write_sq.block_size && !write_sq.syncing) {
545 /* hmmm, the only existing frame is not
546 * yet filled and we're not syncing?
547 */
548 custom.intena = IF_SETCLR | IF_AUD0;
549 return;
550 }
551
552 AmiPlayNextFrame(minframes);
553
554 custom.intena = IF_SETCLR | IF_AUD0;
555}
556
557
558static irqreturn_t AmiInterrupt(int irq, void *dummy, struct pt_regs *fp)
559{
560 int minframes = 1;
561
562 custom.intena = IF_AUD0;
563
564 if (!write_sq.active) {
565 /* Playing was interrupted and sq_reset() has already cleared
566 * the sq variables, so better don't do anything here.
567 */
568 WAKE_UP(write_sq.sync_queue);
569 return IRQ_HANDLED;
570 }
571
572 if (write_sq.active & AMI_PLAY_PLAYING) {
573 /* We've just finished a frame */
574 write_sq.count--;
575 WAKE_UP(write_sq.action_queue);
576 }
577
578 if (write_sq.active & AMI_PLAY_LOADED)
579 /* Increase threshold: frame 1 is already being played */
580 minframes = 2;
581
582 /* Shift the flags */
583 write_sq.active = (write_sq.active<<1) & AMI_PLAY_MASK;
584
585 if (!write_sq.active)
586 /* No frame is playing, disable audio DMA */
587 StopDMA();
588
589 custom.intena = IF_SETCLR | IF_AUD0;
590
591 if (write_sq.count >= minframes)
592 /* Try to play the next frame */
593 AmiPlay();
594
595 if (!write_sq.active)
596 /* Nothing to play anymore.
597 Wake up a process waiting for audio output to drain. */
598 WAKE_UP(write_sq.sync_queue);
599 return IRQ_HANDLED;
600}
601
602/*** Mid level stuff *********************************************************/
603
604
605/*
606 * /dev/mixer abstraction
607 */
608
609static void __init AmiMixerInit(void)
610{
611 dmasound.volume_left = 64;
612 dmasound.volume_right = 64;
613 custom.aud[0].audvol = dmasound.volume_left;
614 custom.aud[3].audvol = 1; /* For pseudo 14bit */
615 custom.aud[1].audvol = dmasound.volume_right;
616 custom.aud[2].audvol = 1; /* For pseudo 14bit */
617 dmasound.treble = 50;
618}
619
620static int AmiMixerIoctl(u_int cmd, u_long arg)
621{
622 int data;
623 switch (cmd) {
624 case SOUND_MIXER_READ_DEVMASK:
625 return IOCTL_OUT(arg, SOUND_MASK_VOLUME | SOUND_MASK_TREBLE);
626 case SOUND_MIXER_READ_RECMASK:
627 return IOCTL_OUT(arg, 0);
628 case SOUND_MIXER_READ_STEREODEVS:
629 return IOCTL_OUT(arg, SOUND_MASK_VOLUME);
630 case SOUND_MIXER_READ_VOLUME:
631 return IOCTL_OUT(arg,
632 VOLUME_AMI_TO_VOXWARE(dmasound.volume_left) |
633 VOLUME_AMI_TO_VOXWARE(dmasound.volume_right) << 8);
634 case SOUND_MIXER_WRITE_VOLUME:
635 IOCTL_IN(arg, data);
636 return IOCTL_OUT(arg, dmasound_set_volume(data));
637 case SOUND_MIXER_READ_TREBLE:
638 return IOCTL_OUT(arg, dmasound.treble);
639 case SOUND_MIXER_WRITE_TREBLE:
640 IOCTL_IN(arg, data);
641 return IOCTL_OUT(arg, dmasound_set_treble(data));
642 }
643 return -EINVAL;
644}
645
646
647static int AmiWriteSqSetup(void)
648{
649 write_sq_block_size_half = write_sq.block_size>>1;
650 write_sq_block_size_quarter = write_sq_block_size_half>>1;
651 return 0;
652}
653
654
655static int AmiStateInfo(char *buffer, size_t space)
656{
657 int len = 0;
658 len += sprintf(buffer+len, "\tsound.volume_left = %d [0...64]\n",
659 dmasound.volume_left);
660 len += sprintf(buffer+len, "\tsound.volume_right = %d [0...64]\n",
661 dmasound.volume_right);
662 if (len >= space) {
663 printk(KERN_ERR "dmasound_paula: overlowed state buffer alloc.\n") ;
664 len = space ;
665 }
666 return len;
667}
668
669
670/*** Machine definitions *****************************************************/
671
672static SETTINGS def_hard = {
673 .format = AFMT_S8,
674 .stereo = 0,
675 .size = 8,
676 .speed = 8000
677} ;
678
679static SETTINGS def_soft = {
680 .format = AFMT_U8,
681 .stereo = 0,
682 .size = 8,
683 .speed = 8000
684} ;
685
686static MACHINE machAmiga = {
687 .name = "Amiga",
688 .name2 = "AMIGA",
689 .owner = THIS_MODULE,
690 .dma_alloc = AmiAlloc,
691 .dma_free = AmiFree,
692 .irqinit = AmiIrqInit,
693#ifdef MODULE
694 .irqcleanup = AmiIrqCleanUp,
695#endif /* MODULE */
696 .init = AmiInit,
697 .silence = AmiSilence,
698 .setFormat = AmiSetFormat,
699 .setVolume = AmiSetVolume,
700 .setTreble = AmiSetTreble,
701 .play = AmiPlay,
702 .mixer_init = AmiMixerInit,
703 .mixer_ioctl = AmiMixerIoctl,
704 .write_sq_setup = AmiWriteSqSetup,
705 .state_info = AmiStateInfo,
706 .min_dsp_speed = 8000,
707 .version = ((DMASOUND_PAULA_REVISION<<8) | DMASOUND_PAULA_EDITION),
708 .hardware_afmts = (AFMT_S8 | AFMT_S16_BE), /* h'ware-supported formats *only* here */
709 .capabilities = DSP_CAP_BATCH /* As per SNDCTL_DSP_GETCAPS */
710};
711
712
713/*** Config & Setup **********************************************************/
714
715
716int __init dmasound_paula_init(void)
717{
718 int err;
719
720 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(AMI_AUDIO)) {
721 if (!request_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40,
722 "dmasound [Paula]"))
723 return -EBUSY;
724 dmasound.mach = machAmiga;
725 dmasound.mach.default_hard = def_hard ;
726 dmasound.mach.default_soft = def_soft ;
727 err = dmasound_init();
728 if (err)
729 release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
730 return err;
731 } else
732 return -ENODEV;
733}
734
735static void __exit dmasound_paula_cleanup(void)
736{
737 dmasound_deinit();
738 release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
739}
740
741module_init(dmasound_paula_init);
742module_exit(dmasound_paula_cleanup);
743MODULE_LICENSE("GPL");
diff --git a/sound/oss/dmasound/dmasound_q40.c b/sound/oss/dmasound/dmasound_q40.c
new file mode 100644
index 000000000000..92c25a0174db
--- /dev/null
+++ b/sound/oss/dmasound/dmasound_q40.c
@@ -0,0 +1,634 @@
1/*
2 * linux/sound/oss/dmasound/dmasound_q40.c
3 *
4 * Q40 DMA Sound Driver
5 *
6 * See linux/sound/oss/dmasound/dmasound_core.c for copyright and credits
7 * prior to 28/01/2001
8 *
9 * 28/01/2001 [0.1] Iain Sandoe
10 * - added versioning
11 * - put in and populated the hardware_afmts field.
12 * [0.2] - put in SNDCTL_DSP_GETCAPS value.
13 * [0.3] - put in default hard/soft settings.
14 */
15
16
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/soundcard.h>
21#include <linux/interrupt.h>
22
23#include <asm/uaccess.h>
24#include <asm/q40ints.h>
25#include <asm/q40_master.h>
26
27#include "dmasound.h"
28
29#define DMASOUND_Q40_REVISION 0
30#define DMASOUND_Q40_EDITION 3
31
32static int expand_bal; /* Balance factor for expanding (not volume!) */
33static int expand_data; /* Data for expanding */
34
35
36/*** Low level stuff *********************************************************/
37
38
39static void *Q40Alloc(unsigned int size, int flags);
40static void Q40Free(void *, unsigned int);
41static int Q40IrqInit(void);
42#ifdef MODULE
43static void Q40IrqCleanUp(void);
44#endif
45static void Q40Silence(void);
46static void Q40Init(void);
47static int Q40SetFormat(int format);
48static int Q40SetVolume(int volume);
49static void Q40PlayNextFrame(int index);
50static void Q40Play(void);
51static irqreturn_t Q40StereoInterrupt(int irq, void *dummy, struct pt_regs *fp);
52static irqreturn_t Q40MonoInterrupt(int irq, void *dummy, struct pt_regs *fp);
53static void Q40Interrupt(void);
54
55
56/*** Mid level stuff *********************************************************/
57
58
59
60/* userCount, frameUsed, frameLeft == byte counts */
61static ssize_t q40_ct_law(const u_char *userPtr, size_t userCount,
62 u_char frame[], ssize_t *frameUsed,
63 ssize_t frameLeft)
64{
65 char *table = dmasound.soft.format == AFMT_MU_LAW ? dmasound_ulaw2dma8: dmasound_alaw2dma8;
66 ssize_t count, used;
67 u_char *p = (u_char *) &frame[*frameUsed];
68
69 used = count = min_t(size_t, userCount, frameLeft);
70 if (copy_from_user(p,userPtr,count))
71 return -EFAULT;
72 while (count > 0) {
73 *p = table[*p]+128;
74 p++;
75 count--;
76 }
77 *frameUsed += used ;
78 return used;
79}
80
81
82static ssize_t q40_ct_s8(const u_char *userPtr, size_t userCount,
83 u_char frame[], ssize_t *frameUsed,
84 ssize_t frameLeft)
85{
86 ssize_t count, used;
87 u_char *p = (u_char *) &frame[*frameUsed];
88
89 used = count = min_t(size_t, userCount, frameLeft);
90 if (copy_from_user(p,userPtr,count))
91 return -EFAULT;
92 while (count > 0) {
93 *p = *p + 128;
94 p++;
95 count--;
96 }
97 *frameUsed += used;
98 return used;
99}
100
101static ssize_t q40_ct_u8(const u_char *userPtr, size_t userCount,
102 u_char frame[], ssize_t *frameUsed,
103 ssize_t frameLeft)
104{
105 ssize_t count, used;
106 u_char *p = (u_char *) &frame[*frameUsed];
107
108 used = count = min_t(size_t, userCount, frameLeft);
109 if (copy_from_user(p,userPtr,count))
110 return -EFAULT;
111 *frameUsed += used;
112 return used;
113}
114
115
116/* a bit too complicated to optimise right now ..*/
117static ssize_t q40_ctx_law(const u_char *userPtr, size_t userCount,
118 u_char frame[], ssize_t *frameUsed,
119 ssize_t frameLeft)
120{
121 unsigned char *table = (unsigned char *)
122 (dmasound.soft.format == AFMT_MU_LAW ? dmasound_ulaw2dma8: dmasound_alaw2dma8);
123 unsigned int data = expand_data;
124 u_char *p = (u_char *) &frame[*frameUsed];
125 int bal = expand_bal;
126 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
127 int utotal, ftotal;
128
129 ftotal = frameLeft;
130 utotal = userCount;
131 while (frameLeft) {
132 u_char c;
133 if (bal < 0) {
134 if (userCount == 0)
135 break;
136 if (get_user(c, userPtr++))
137 return -EFAULT;
138 data = table[c];
139 data += 0x80;
140 userCount--;
141 bal += hSpeed;
142 }
143 *p++ = data;
144 frameLeft--;
145 bal -= sSpeed;
146 }
147 expand_bal = bal;
148 expand_data = data;
149 *frameUsed += (ftotal - frameLeft);
150 utotal -= userCount;
151 return utotal;
152}
153
154
155static ssize_t q40_ctx_s8(const u_char *userPtr, size_t userCount,
156 u_char frame[], ssize_t *frameUsed,
157 ssize_t frameLeft)
158{
159 u_char *p = (u_char *) &frame[*frameUsed];
160 unsigned int data = expand_data;
161 int bal = expand_bal;
162 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
163 int utotal, ftotal;
164
165
166 ftotal = frameLeft;
167 utotal = userCount;
168 while (frameLeft) {
169 u_char c;
170 if (bal < 0) {
171 if (userCount == 0)
172 break;
173 if (get_user(c, userPtr++))
174 return -EFAULT;
175 data = c ;
176 data += 0x80;
177 userCount--;
178 bal += hSpeed;
179 }
180 *p++ = data;
181 frameLeft--;
182 bal -= sSpeed;
183 }
184 expand_bal = bal;
185 expand_data = data;
186 *frameUsed += (ftotal - frameLeft);
187 utotal -= userCount;
188 return utotal;
189}
190
191
192static ssize_t q40_ctx_u8(const u_char *userPtr, size_t userCount,
193 u_char frame[], ssize_t *frameUsed,
194 ssize_t frameLeft)
195{
196 u_char *p = (u_char *) &frame[*frameUsed];
197 unsigned int data = expand_data;
198 int bal = expand_bal;
199 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
200 int utotal, ftotal;
201
202 ftotal = frameLeft;
203 utotal = userCount;
204 while (frameLeft) {
205 u_char c;
206 if (bal < 0) {
207 if (userCount == 0)
208 break;
209 if (get_user(c, userPtr++))
210 return -EFAULT;
211 data = c ;
212 userCount--;
213 bal += hSpeed;
214 }
215 *p++ = data;
216 frameLeft--;
217 bal -= sSpeed;
218 }
219 expand_bal = bal;
220 expand_data = data;
221 *frameUsed += (ftotal - frameLeft) ;
222 utotal -= userCount;
223 return utotal;
224}
225
226/* compressing versions */
227static ssize_t q40_ctc_law(const u_char *userPtr, size_t userCount,
228 u_char frame[], ssize_t *frameUsed,
229 ssize_t frameLeft)
230{
231 unsigned char *table = (unsigned char *)
232 (dmasound.soft.format == AFMT_MU_LAW ? dmasound_ulaw2dma8: dmasound_alaw2dma8);
233 unsigned int data = expand_data;
234 u_char *p = (u_char *) &frame[*frameUsed];
235 int bal = expand_bal;
236 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
237 int utotal, ftotal;
238
239 ftotal = frameLeft;
240 utotal = userCount;
241 while (frameLeft) {
242 u_char c;
243 while(bal<0) {
244 if (userCount == 0)
245 goto lout;
246 if (!(bal<(-hSpeed))) {
247 if (get_user(c, userPtr))
248 return -EFAULT;
249 data = 0x80 + table[c];
250 }
251 userPtr++;
252 userCount--;
253 bal += hSpeed;
254 }
255 *p++ = data;
256 frameLeft--;
257 bal -= sSpeed;
258 }
259 lout:
260 expand_bal = bal;
261 expand_data = data;
262 *frameUsed += (ftotal - frameLeft);
263 utotal -= userCount;
264 return utotal;
265}
266
267
268static ssize_t q40_ctc_s8(const u_char *userPtr, size_t userCount,
269 u_char frame[], ssize_t *frameUsed,
270 ssize_t frameLeft)
271{
272 u_char *p = (u_char *) &frame[*frameUsed];
273 unsigned int data = expand_data;
274 int bal = expand_bal;
275 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
276 int utotal, ftotal;
277
278 ftotal = frameLeft;
279 utotal = userCount;
280 while (frameLeft) {
281 u_char c;
282 while (bal < 0) {
283 if (userCount == 0)
284 goto lout;
285 if (!(bal<(-hSpeed))) {
286 if (get_user(c, userPtr))
287 return -EFAULT;
288 data = c + 0x80;
289 }
290 userPtr++;
291 userCount--;
292 bal += hSpeed;
293 }
294 *p++ = data;
295 frameLeft--;
296 bal -= sSpeed;
297 }
298 lout:
299 expand_bal = bal;
300 expand_data = data;
301 *frameUsed += (ftotal - frameLeft);
302 utotal -= userCount;
303 return utotal;
304}
305
306
307static ssize_t q40_ctc_u8(const u_char *userPtr, size_t userCount,
308 u_char frame[], ssize_t *frameUsed,
309 ssize_t frameLeft)
310{
311 u_char *p = (u_char *) &frame[*frameUsed];
312 unsigned int data = expand_data;
313 int bal = expand_bal;
314 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
315 int utotal, ftotal;
316
317 ftotal = frameLeft;
318 utotal = userCount;
319 while (frameLeft) {
320 u_char c;
321 while (bal < 0) {
322 if (userCount == 0)
323 goto lout;
324 if (!(bal<(-hSpeed))) {
325 if (get_user(c, userPtr))
326 return -EFAULT;
327 data = c ;
328 }
329 userPtr++;
330 userCount--;
331 bal += hSpeed;
332 }
333 *p++ = data;
334 frameLeft--;
335 bal -= sSpeed;
336 }
337 lout:
338 expand_bal = bal;
339 expand_data = data;
340 *frameUsed += (ftotal - frameLeft) ;
341 utotal -= userCount;
342 return utotal;
343}
344
345
346static TRANS transQ40Normal = {
347 q40_ct_law, q40_ct_law, q40_ct_s8, q40_ct_u8, NULL, NULL, NULL, NULL
348};
349
350static TRANS transQ40Expanding = {
351 q40_ctx_law, q40_ctx_law, q40_ctx_s8, q40_ctx_u8, NULL, NULL, NULL, NULL
352};
353
354static TRANS transQ40Compressing = {
355 q40_ctc_law, q40_ctc_law, q40_ctc_s8, q40_ctc_u8, NULL, NULL, NULL, NULL
356};
357
358
359/*** Low level stuff *********************************************************/
360
361static void *Q40Alloc(unsigned int size, int flags)
362{
363 return kmalloc(size, flags); /* change to vmalloc */
364}
365
366static void Q40Free(void *ptr, unsigned int size)
367{
368 kfree(ptr);
369}
370
371static int __init Q40IrqInit(void)
372{
373 /* Register interrupt handler. */
374 request_irq(Q40_IRQ_SAMPLE, Q40StereoInterrupt, 0,
375 "DMA sound", Q40Interrupt);
376
377 return(1);
378}
379
380
381#ifdef MODULE
382static void Q40IrqCleanUp(void)
383{
384 master_outb(0,SAMPLE_ENABLE_REG);
385 free_irq(Q40_IRQ_SAMPLE, Q40Interrupt);
386}
387#endif /* MODULE */
388
389
390static void Q40Silence(void)
391{
392 master_outb(0,SAMPLE_ENABLE_REG);
393 *DAC_LEFT=*DAC_RIGHT=127;
394}
395
396static char *q40_pp;
397static unsigned int q40_sc;
398
399static void Q40PlayNextFrame(int index)
400{
401 u_char *start;
402 u_long size;
403 u_char speed;
404
405 /* used by Q40Play() if all doubts whether there really is something
406 * to be played are already wiped out.
407 */
408 start = write_sq.buffers[write_sq.front];
409 size = (write_sq.count == index ? write_sq.rear_size : write_sq.block_size);
410
411 q40_pp=start;
412 q40_sc=size;
413
414 write_sq.front = (write_sq.front+1) % write_sq.max_count;
415 write_sq.active++;
416
417 speed=(dmasound.hard.speed==10000 ? 0 : 1);
418
419 master_outb( 0,SAMPLE_ENABLE_REG);
420 free_irq(Q40_IRQ_SAMPLE, Q40Interrupt);
421 if (dmasound.soft.stereo)
422 request_irq(Q40_IRQ_SAMPLE, Q40StereoInterrupt, 0,
423 "Q40 sound", Q40Interrupt);
424 else
425 request_irq(Q40_IRQ_SAMPLE, Q40MonoInterrupt, 0,
426 "Q40 sound", Q40Interrupt);
427
428 master_outb( speed, SAMPLE_RATE_REG);
429 master_outb( 1,SAMPLE_CLEAR_REG);
430 master_outb( 1,SAMPLE_ENABLE_REG);
431}
432
433static void Q40Play(void)
434{
435 unsigned long flags;
436
437 if (write_sq.active || write_sq.count<=0 ) {
438 /* There's already a frame loaded */
439 return;
440 }
441
442 /* nothing in the queue */
443 if (write_sq.count <= 1 && write_sq.rear_size < write_sq.block_size && !write_sq.syncing) {
444 /* hmmm, the only existing frame is not
445 * yet filled and we're not syncing?
446 */
447 return;
448 }
449 spin_lock_irqsave(&dmasound.lock, flags);
450 Q40PlayNextFrame(1);
451 spin_unlock_irqrestore(&dmasound.lock, flags);
452}
453
454static irqreturn_t Q40StereoInterrupt(int irq, void *dummy, struct pt_regs *fp)
455{
456 spin_lock(&dmasound.lock);
457 if (q40_sc>1){
458 *DAC_LEFT=*q40_pp++;
459 *DAC_RIGHT=*q40_pp++;
460 q40_sc -=2;
461 master_outb(1,SAMPLE_CLEAR_REG);
462 }else Q40Interrupt();
463 spin_unlock(&dmasound.lock);
464 return IRQ_HANDLED;
465}
466static irqreturn_t Q40MonoInterrupt(int irq, void *dummy, struct pt_regs *fp)
467{
468 spin_lock(&dmasound.lock);
469 if (q40_sc>0){
470 *DAC_LEFT=*q40_pp;
471 *DAC_RIGHT=*q40_pp++;
472 q40_sc --;
473 master_outb(1,SAMPLE_CLEAR_REG);
474 }else Q40Interrupt();
475 spin_unlock(&dmasound.lock);
476 return IRQ_HANDLED;
477}
478static void Q40Interrupt(void)
479{
480 if (!write_sq.active) {
481 /* playing was interrupted and sq_reset() has already cleared
482 * the sq variables, so better don't do anything here.
483 */
484 WAKE_UP(write_sq.sync_queue);
485 master_outb(0,SAMPLE_ENABLE_REG); /* better safe */
486 goto exit;
487 } else write_sq.active=0;
488 write_sq.count--;
489 Q40Play();
490
491 if (q40_sc<2)
492 { /* there was nothing to play, disable irq */
493 master_outb(0,SAMPLE_ENABLE_REG);
494 *DAC_LEFT=*DAC_RIGHT=127;
495 }
496 WAKE_UP(write_sq.action_queue);
497
498 exit:
499 master_outb(1,SAMPLE_CLEAR_REG);
500}
501
502
503static void Q40Init(void)
504{
505 int i, idx;
506 const int freq[] = {10000, 20000};
507
508 /* search a frequency that fits into the allowed error range */
509
510 idx = -1;
511 for (i = 0; i < 2; i++)
512 if ((100 * abs(dmasound.soft.speed - freq[i]) / freq[i]) <= catchRadius)
513 idx = i;
514
515 dmasound.hard = dmasound.soft;
516 /*sound.hard.stereo=1;*/ /* no longer true */
517 dmasound.hard.size=8;
518
519 if (idx > -1) {
520 dmasound.soft.speed = freq[idx];
521 dmasound.trans_write = &transQ40Normal;
522 } else
523 dmasound.trans_write = &transQ40Expanding;
524
525 Q40Silence();
526
527 if (dmasound.hard.speed > 20200) {
528 /* squeeze the sound, we do that */
529 dmasound.hard.speed = 20000;
530 dmasound.trans_write = &transQ40Compressing;
531 } else if (dmasound.hard.speed > 10000) {
532 dmasound.hard.speed = 20000;
533 } else {
534 dmasound.hard.speed = 10000;
535 }
536 expand_bal = -dmasound.soft.speed;
537}
538
539
540static int Q40SetFormat(int format)
541{
542 /* Q40 sound supports only 8bit modes */
543
544 switch (format) {
545 case AFMT_QUERY:
546 return(dmasound.soft.format);
547 case AFMT_MU_LAW:
548 case AFMT_A_LAW:
549 case AFMT_S8:
550 case AFMT_U8:
551 break;
552 default:
553 format = AFMT_S8;
554 }
555
556 dmasound.soft.format = format;
557 dmasound.soft.size = 8;
558 if (dmasound.minDev == SND_DEV_DSP) {
559 dmasound.dsp.format = format;
560 dmasound.dsp.size = 8;
561 }
562 Q40Init();
563
564 return(format);
565}
566
567static int Q40SetVolume(int volume)
568{
569 return 0;
570}
571
572
573/*** Machine definitions *****************************************************/
574
575static SETTINGS def_hard = {
576 .format = AFMT_U8,
577 .stereo = 0,
578 .size = 8,
579 .speed = 10000
580} ;
581
582static SETTINGS def_soft = {
583 .format = AFMT_U8,
584 .stereo = 0,
585 .size = 8,
586 .speed = 8000
587} ;
588
589static MACHINE machQ40 = {
590 .name = "Q40",
591 .name2 = "Q40",
592 .owner = THIS_MODULE,
593 .dma_alloc = Q40Alloc,
594 .dma_free = Q40Free,
595 .irqinit = Q40IrqInit,
596#ifdef MODULE
597 .irqcleanup = Q40IrqCleanUp,
598#endif /* MODULE */
599 .init = Q40Init,
600 .silence = Q40Silence,
601 .setFormat = Q40SetFormat,
602 .setVolume = Q40SetVolume,
603 .play = Q40Play,
604 .min_dsp_speed = 10000,
605 .version = ((DMASOUND_Q40_REVISION<<8) | DMASOUND_Q40_EDITION),
606 .hardware_afmts = AFMT_U8, /* h'ware-supported formats *only* here */
607 .capabilities = DSP_CAP_BATCH /* As per SNDCTL_DSP_GETCAPS */
608};
609
610
611/*** Config & Setup **********************************************************/
612
613
614int __init dmasound_q40_init(void)
615{
616 if (MACH_IS_Q40) {
617 dmasound.mach = machQ40;
618 dmasound.mach.default_hard = def_hard ;
619 dmasound.mach.default_soft = def_soft ;
620 return dmasound_init();
621 } else
622 return -ENODEV;
623}
624
625static void __exit dmasound_q40_cleanup(void)
626{
627 dmasound_deinit();
628}
629
630module_init(dmasound_q40_init);
631module_exit(dmasound_q40_cleanup);
632
633MODULE_DESCRIPTION("Q40/Q60 sound driver");
634MODULE_LICENSE("GPL");
diff --git a/sound/oss/dmasound/tas3001c.c b/sound/oss/dmasound/tas3001c.c
new file mode 100644
index 000000000000..f227c9f688cc
--- /dev/null
+++ b/sound/oss/dmasound/tas3001c.c
@@ -0,0 +1,850 @@
1/*
2 * Driver for the i2c/i2s based TA3004 sound chip used
3 * on some Apple hardware. Also known as "snapper".
4 *
5 * Tobias Sargeant <tobias.sargeant@bigpond.com>
6 * Based upon, tas3001c.c by Christopher C. Chimelis <chris@debian.org>:
7 *
8 * TODO:
9 * -----
10 * * Enable control over input line 2 (is this connected?)
11 * * Implement sleep support (at least mute everything and
12 * * set gains to minimum during sleep)
13 * * Look into some of Darwin's tweaks regarding the mute
14 * * lines (delays & different behaviour on some HW)
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <linux/proc_fs.h>
21#include <linux/ioport.h>
22#include <linux/sysctl.h>
23#include <linux/types.h>
24#include <linux/i2c.h>
25#include <linux/init.h>
26#include <linux/soundcard.h>
27#include <linux/workqueue.h>
28#include <asm/uaccess.h>
29#include <asm/errno.h>
30#include <asm/io.h>
31#include <asm/prom.h>
32
33#include "dmasound.h"
34#include "tas_common.h"
35#include "tas3001c.h"
36
37#include "tas_ioctl.h"
38
39#define TAS3001C_BIQUAD_FILTER_COUNT 6
40#define TAS3001C_BIQUAD_CHANNEL_COUNT 2
41
42#define VOL_DEFAULT (100 * 4 / 5)
43#define INPUT_DEFAULT (100 * 4 / 5)
44#define BASS_DEFAULT (100 / 2)
45#define TREBLE_DEFAULT (100 / 2)
46
47struct tas3001c_data_t {
48 struct tas_data_t super;
49 int device_id;
50 int output_id;
51 int speaker_id;
52 struct tas_drce_t drce_state;
53};
54
55
56static const union tas_biquad_t
57tas3001c_eq_unity={
58 .buf = { 0x100000, 0x000000, 0x000000, 0x000000, 0x000000 }
59};
60
61
62static inline unsigned char db_to_regval(short db) {
63 int r=0;
64
65 r=(db+0x59a0) / 0x60;
66
67 if (r < 0x91) return 0x91;
68 if (r > 0xef) return 0xef;
69 return r;
70}
71
72static inline short quantize_db(short db) {
73 return db_to_regval(db) * 0x60 - 0x59a0;
74}
75
76
77static inline int
78register_width(enum tas3001c_reg_t r)
79{
80 switch(r) {
81 case TAS3001C_REG_MCR:
82 case TAS3001C_REG_TREBLE:
83 case TAS3001C_REG_BASS:
84 return 1;
85
86 case TAS3001C_REG_DRC:
87 return 2;
88
89 case TAS3001C_REG_MIXER1:
90 case TAS3001C_REG_MIXER2:
91 return 3;
92
93 case TAS3001C_REG_VOLUME:
94 return 6;
95
96 case TAS3001C_REG_LEFT_BIQUAD0:
97 case TAS3001C_REG_LEFT_BIQUAD1:
98 case TAS3001C_REG_LEFT_BIQUAD2:
99 case TAS3001C_REG_LEFT_BIQUAD3:
100 case TAS3001C_REG_LEFT_BIQUAD4:
101 case TAS3001C_REG_LEFT_BIQUAD5:
102 case TAS3001C_REG_LEFT_BIQUAD6:
103
104 case TAS3001C_REG_RIGHT_BIQUAD0:
105 case TAS3001C_REG_RIGHT_BIQUAD1:
106 case TAS3001C_REG_RIGHT_BIQUAD2:
107 case TAS3001C_REG_RIGHT_BIQUAD3:
108 case TAS3001C_REG_RIGHT_BIQUAD4:
109 case TAS3001C_REG_RIGHT_BIQUAD5:
110 case TAS3001C_REG_RIGHT_BIQUAD6:
111 return 15;
112
113 default:
114 return 0;
115 }
116}
117
118static int
119tas3001c_write_register( struct tas3001c_data_t *self,
120 enum tas3001c_reg_t reg_num,
121 char *data,
122 uint write_mode)
123{
124 if (reg_num==TAS3001C_REG_MCR ||
125 reg_num==TAS3001C_REG_BASS ||
126 reg_num==TAS3001C_REG_TREBLE) {
127 return tas_write_byte_register(&self->super,
128 (uint)reg_num,
129 *data,
130 write_mode);
131 } else {
132 return tas_write_register(&self->super,
133 (uint)reg_num,
134 register_width(reg_num),
135 data,
136 write_mode);
137 }
138}
139
140static int
141tas3001c_sync_register( struct tas3001c_data_t *self,
142 enum tas3001c_reg_t reg_num)
143{
144 if (reg_num==TAS3001C_REG_MCR ||
145 reg_num==TAS3001C_REG_BASS ||
146 reg_num==TAS3001C_REG_TREBLE) {
147 return tas_sync_byte_register(&self->super,
148 (uint)reg_num,
149 register_width(reg_num));
150 } else {
151 return tas_sync_register(&self->super,
152 (uint)reg_num,
153 register_width(reg_num));
154 }
155}
156
157static int
158tas3001c_read_register( struct tas3001c_data_t *self,
159 enum tas3001c_reg_t reg_num,
160 char *data,
161 uint write_mode)
162{
163 return tas_read_register(&self->super,
164 (uint)reg_num,
165 register_width(reg_num),
166 data);
167}
168
169static inline int
170tas3001c_fast_load(struct tas3001c_data_t *self, int fast)
171{
172 if (fast)
173 self->super.shadow[TAS3001C_REG_MCR][0] |= 0x80;
174 else
175 self->super.shadow[TAS3001C_REG_MCR][0] &= 0x7f;
176 return tas3001c_sync_register(self,TAS3001C_REG_MCR);
177}
178
179static uint
180tas3001c_supported_mixers(struct tas3001c_data_t *self)
181{
182 return SOUND_MASK_VOLUME |
183 SOUND_MASK_PCM |
184 SOUND_MASK_ALTPCM |
185 SOUND_MASK_TREBLE |
186 SOUND_MASK_BASS;
187}
188
189static int
190tas3001c_mixer_is_stereo(struct tas3001c_data_t *self,int mixer)
191{
192 switch(mixer) {
193 case SOUND_MIXER_VOLUME:
194 return 1;
195 default:
196 return 0;
197 }
198}
199
200static uint
201tas3001c_stereo_mixers(struct tas3001c_data_t *self)
202{
203 uint r=tas3001c_supported_mixers(self);
204 uint i;
205
206 for (i=1; i<SOUND_MIXER_NRDEVICES; i++)
207 if (r&(1<<i) && !tas3001c_mixer_is_stereo(self,i))
208 r &= ~(1<<i);
209 return r;
210}
211
212static int
213tas3001c_get_mixer_level(struct tas3001c_data_t *self,int mixer,uint *level)
214{
215 if (!self)
216 return -1;
217
218 *level=self->super.mixer[mixer];
219
220 return 0;
221}
222
223static int
224tas3001c_set_mixer_level(struct tas3001c_data_t *self,int mixer,uint level)
225{
226 int rc;
227 tas_shadow_t *shadow;
228
229 uint temp;
230 uint offset=0;
231
232 if (!self)
233 return -1;
234
235 shadow=self->super.shadow;
236
237 if (!tas3001c_mixer_is_stereo(self,mixer))
238 level = tas_mono_to_stereo(level);
239
240 switch(mixer) {
241 case SOUND_MIXER_VOLUME:
242 temp = tas3001c_gain.master[level&0xff];
243 shadow[TAS3001C_REG_VOLUME][0] = (temp >> 16) & 0xff;
244 shadow[TAS3001C_REG_VOLUME][1] = (temp >> 8) & 0xff;
245 shadow[TAS3001C_REG_VOLUME][2] = (temp >> 0) & 0xff;
246 temp = tas3001c_gain.master[(level>>8)&0xff];
247 shadow[TAS3001C_REG_VOLUME][3] = (temp >> 16) & 0xff;
248 shadow[TAS3001C_REG_VOLUME][4] = (temp >> 8) & 0xff;
249 shadow[TAS3001C_REG_VOLUME][5] = (temp >> 0) & 0xff;
250 rc = tas3001c_sync_register(self,TAS3001C_REG_VOLUME);
251 break;
252 case SOUND_MIXER_ALTPCM:
253 /* tas3001c_fast_load(self, 1); */
254 level = tas_mono_to_stereo(level);
255 temp = tas3001c_gain.mixer[level&0xff];
256 shadow[TAS3001C_REG_MIXER2][offset+0] = (temp >> 16) & 0xff;
257 shadow[TAS3001C_REG_MIXER2][offset+1] = (temp >> 8) & 0xff;
258 shadow[TAS3001C_REG_MIXER2][offset+2] = (temp >> 0) & 0xff;
259 rc = tas3001c_sync_register(self,TAS3001C_REG_MIXER2);
260 /* tas3001c_fast_load(self, 0); */
261 break;
262 case SOUND_MIXER_PCM:
263 /* tas3001c_fast_load(self, 1); */
264 level = tas_mono_to_stereo(level);
265 temp = tas3001c_gain.mixer[level&0xff];
266 shadow[TAS3001C_REG_MIXER1][offset+0] = (temp >> 16) & 0xff;
267 shadow[TAS3001C_REG_MIXER1][offset+1] = (temp >> 8) & 0xff;
268 shadow[TAS3001C_REG_MIXER1][offset+2] = (temp >> 0) & 0xff;
269 rc = tas3001c_sync_register(self,TAS3001C_REG_MIXER1);
270 /* tas3001c_fast_load(self, 0); */
271 break;
272 case SOUND_MIXER_TREBLE:
273 temp = tas3001c_gain.treble[level&0xff];
274 shadow[TAS3001C_REG_TREBLE][0]=temp&0xff;
275 rc = tas3001c_sync_register(self,TAS3001C_REG_TREBLE);
276 break;
277 case SOUND_MIXER_BASS:
278 temp = tas3001c_gain.bass[level&0xff];
279 shadow[TAS3001C_REG_BASS][0]=temp&0xff;
280 rc = tas3001c_sync_register(self,TAS3001C_REG_BASS);
281 break;
282 default:
283 rc = -1;
284 break;
285 }
286 if (rc < 0)
287 return rc;
288 self->super.mixer[mixer]=level;
289 return 0;
290}
291
292static int
293tas3001c_leave_sleep(struct tas3001c_data_t *self)
294{
295 unsigned char mcr = (1<<6)+(2<<4)+(2<<2);
296
297 if (!self)
298 return -1;
299
300 /* Make sure something answers on the i2c bus */
301 if (tas3001c_write_register(self, TAS3001C_REG_MCR, &mcr,
302 WRITE_NORMAL|FORCE_WRITE) < 0)
303 return -1;
304
305 tas3001c_fast_load(self, 1);
306
307 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD0);
308 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD1);
309 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD2);
310 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD3);
311 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD4);
312 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD5);
313
314 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD0);
315 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD1);
316 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD2);
317 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD3);
318 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD4);
319 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD5);
320
321 tas3001c_fast_load(self, 0);
322
323 (void)tas3001c_sync_register(self,TAS3001C_REG_BASS);
324 (void)tas3001c_sync_register(self,TAS3001C_REG_TREBLE);
325 (void)tas3001c_sync_register(self,TAS3001C_REG_MIXER1);
326 (void)tas3001c_sync_register(self,TAS3001C_REG_MIXER2);
327 (void)tas3001c_sync_register(self,TAS3001C_REG_VOLUME);
328
329 return 0;
330}
331
332static int
333tas3001c_enter_sleep(struct tas3001c_data_t *self)
334{
335 /* Stub for now, but I have the details on low-power mode */
336 if (!self)
337 return -1;
338 return 0;
339}
340
341static int
342tas3001c_sync_biquad( struct tas3001c_data_t *self,
343 u_int channel,
344 u_int filter)
345{
346 enum tas3001c_reg_t reg;
347
348 if (channel >= TAS3001C_BIQUAD_CHANNEL_COUNT ||
349 filter >= TAS3001C_BIQUAD_FILTER_COUNT) return -EINVAL;
350
351 reg=( channel ? TAS3001C_REG_RIGHT_BIQUAD0 : TAS3001C_REG_LEFT_BIQUAD0 ) + filter;
352
353 return tas3001c_sync_register(self,reg);
354}
355
356static int
357tas3001c_write_biquad_shadow( struct tas3001c_data_t *self,
358 u_int channel,
359 u_int filter,
360 const union tas_biquad_t *biquad)
361{
362 tas_shadow_t *shadow=self->super.shadow;
363 enum tas3001c_reg_t reg;
364
365 if (channel >= TAS3001C_BIQUAD_CHANNEL_COUNT ||
366 filter >= TAS3001C_BIQUAD_FILTER_COUNT) return -EINVAL;
367
368 reg=( channel ? TAS3001C_REG_RIGHT_BIQUAD0 : TAS3001C_REG_LEFT_BIQUAD0 ) + filter;
369
370 SET_4_20(shadow[reg], 0,biquad->coeff.b0);
371 SET_4_20(shadow[reg], 3,biquad->coeff.b1);
372 SET_4_20(shadow[reg], 6,biquad->coeff.b2);
373 SET_4_20(shadow[reg], 9,biquad->coeff.a1);
374 SET_4_20(shadow[reg],12,biquad->coeff.a2);
375
376 return 0;
377}
378
379static int
380tas3001c_write_biquad( struct tas3001c_data_t *self,
381 u_int channel,
382 u_int filter,
383 const union tas_biquad_t *biquad)
384{
385 int rc;
386
387 rc=tas3001c_write_biquad_shadow(self, channel, filter, biquad);
388 if (rc < 0) return rc;
389
390 return tas3001c_sync_biquad(self, channel, filter);
391}
392
393static int
394tas3001c_write_biquad_list( struct tas3001c_data_t *self,
395 u_int filter_count,
396 u_int flags,
397 struct tas_biquad_ctrl_t *biquads)
398{
399 int i;
400 int rc;
401
402 if (flags & TAS_BIQUAD_FAST_LOAD) tas3001c_fast_load(self,1);
403
404 for (i=0; i<filter_count; i++) {
405 rc=tas3001c_write_biquad(self,
406 biquads[i].channel,
407 biquads[i].filter,
408 &biquads[i].data);
409 if (rc < 0) break;
410 }
411
412 if (flags & TAS_BIQUAD_FAST_LOAD) {
413 tas3001c_fast_load(self,0);
414
415 (void)tas3001c_sync_register(self,TAS3001C_REG_BASS);
416 (void)tas3001c_sync_register(self,TAS3001C_REG_TREBLE);
417 (void)tas3001c_sync_register(self,TAS3001C_REG_MIXER1);
418 (void)tas3001c_sync_register(self,TAS3001C_REG_MIXER2);
419 (void)tas3001c_sync_register(self,TAS3001C_REG_VOLUME);
420 }
421
422 return rc;
423}
424
425static int
426tas3001c_read_biquad( struct tas3001c_data_t *self,
427 u_int channel,
428 u_int filter,
429 union tas_biquad_t *biquad)
430{
431 tas_shadow_t *shadow=self->super.shadow;
432 enum tas3001c_reg_t reg;
433
434 if (channel >= TAS3001C_BIQUAD_CHANNEL_COUNT ||
435 filter >= TAS3001C_BIQUAD_FILTER_COUNT) return -EINVAL;
436
437 reg=( channel ? TAS3001C_REG_RIGHT_BIQUAD0 : TAS3001C_REG_LEFT_BIQUAD0 ) + filter;
438
439 biquad->coeff.b0=GET_4_20(shadow[reg], 0);
440 biquad->coeff.b1=GET_4_20(shadow[reg], 3);
441 biquad->coeff.b2=GET_4_20(shadow[reg], 6);
442 biquad->coeff.a1=GET_4_20(shadow[reg], 9);
443 biquad->coeff.a2=GET_4_20(shadow[reg],12);
444
445 return 0;
446}
447
448static int
449tas3001c_eq_rw( struct tas3001c_data_t *self,
450 u_int cmd,
451 u_long arg)
452{
453 int rc;
454 struct tas_biquad_ctrl_t biquad;
455 void __user *argp = (void __user *)arg;
456
457 if (copy_from_user(&biquad, argp, sizeof(struct tas_biquad_ctrl_t))) {
458 return -EFAULT;
459 }
460
461 if (cmd & SIOC_IN) {
462 rc=tas3001c_write_biquad(self, biquad.channel, biquad.filter, &biquad.data);
463 if (rc != 0) return rc;
464 }
465
466 if (cmd & SIOC_OUT) {
467 rc=tas3001c_read_biquad(self, biquad.channel, biquad.filter, &biquad.data);
468 if (rc != 0) return rc;
469
470 if (copy_to_user(argp, &biquad, sizeof(struct tas_biquad_ctrl_t))) {
471 return -EFAULT;
472 }
473
474 }
475 return 0;
476}
477
478static int
479tas3001c_eq_list_rw( struct tas3001c_data_t *self,
480 u_int cmd,
481 u_long arg)
482{
483 int rc;
484 int filter_count;
485 int flags;
486 int i,j;
487 char sync_required[2][6];
488 struct tas_biquad_ctrl_t biquad;
489 struct tas_biquad_ctrl_list_t __user *argp = (void __user *)arg;
490
491 memset(sync_required,0,sizeof(sync_required));
492
493 if (copy_from_user(&filter_count, &argp->filter_count, sizeof(int)))
494 return -EFAULT;
495
496 if (copy_from_user(&flags, &argp->flags, sizeof(int)))
497 return -EFAULT;
498
499 if (cmd & SIOC_IN) {
500 }
501
502 for (i=0; i < filter_count; i++) {
503 if (copy_from_user(&biquad, &argp->biquads[i],
504 sizeof(struct tas_biquad_ctrl_t))) {
505 return -EFAULT;
506 }
507
508 if (cmd & SIOC_IN) {
509 sync_required[biquad.channel][biquad.filter]=1;
510 rc=tas3001c_write_biquad_shadow(self, biquad.channel, biquad.filter, &biquad.data);
511 if (rc != 0) return rc;
512 }
513
514 if (cmd & SIOC_OUT) {
515 rc=tas3001c_read_biquad(self, biquad.channel, biquad.filter, &biquad.data);
516 if (rc != 0) return rc;
517
518 if (copy_to_user(&argp->biquads[i], &biquad,
519 sizeof(struct tas_biquad_ctrl_t))) {
520 return -EFAULT;
521 }
522 }
523 }
524
525 if (cmd & SIOC_IN) {
526 if (flags & TAS_BIQUAD_FAST_LOAD) tas3001c_fast_load(self,1);
527 for (i=0; i<2; i++) {
528 for (j=0; j<6; j++) {
529 if (sync_required[i][j]) {
530 rc=tas3001c_sync_biquad(self, i, j);
531 if (rc < 0) return rc;
532 }
533 }
534 }
535 if (flags & TAS_BIQUAD_FAST_LOAD) {
536 tas3001c_fast_load(self,0);
537 /* now we need to set up the mixers again,
538 because leaving fast mode resets them. */
539 (void)tas3001c_sync_register(self,TAS3001C_REG_BASS);
540 (void)tas3001c_sync_register(self,TAS3001C_REG_TREBLE);
541 (void)tas3001c_sync_register(self,TAS3001C_REG_MIXER1);
542 (void)tas3001c_sync_register(self,TAS3001C_REG_MIXER2);
543 (void)tas3001c_sync_register(self,TAS3001C_REG_VOLUME);
544 }
545 }
546
547 return 0;
548}
549
550static int
551tas3001c_update_drce( struct tas3001c_data_t *self,
552 int flags,
553 struct tas_drce_t *drce)
554{
555 tas_shadow_t *shadow;
556 shadow=self->super.shadow;
557
558 shadow[TAS3001C_REG_DRC][1] = 0xc1;
559
560 if (flags & TAS_DRCE_THRESHOLD) {
561 self->drce_state.threshold=quantize_db(drce->threshold);
562 shadow[TAS3001C_REG_DRC][2] = db_to_regval(self->drce_state.threshold);
563 }
564
565 if (flags & TAS_DRCE_ENABLE) {
566 self->drce_state.enable = drce->enable;
567 }
568
569 if (!self->drce_state.enable) {
570 shadow[TAS3001C_REG_DRC][0] = 0xf0;
571 }
572
573#ifdef DEBUG_DRCE
574 printk("DRCE IOCTL: set [ ENABLE:%x THRESH:%x\n",
575 self->drce_state.enable,
576 self->drce_state.threshold);
577
578 printk("DRCE IOCTL: reg [ %02x %02x ]\n",
579 (unsigned char)shadow[TAS3001C_REG_DRC][0],
580 (unsigned char)shadow[TAS3001C_REG_DRC][1]);
581#endif
582
583 return tas3001c_sync_register(self, TAS3001C_REG_DRC);
584}
585
586static int
587tas3001c_drce_rw( struct tas3001c_data_t *self,
588 u_int cmd,
589 u_long arg)
590{
591 int rc;
592 struct tas_drce_ctrl_t drce_ctrl;
593 void __user *argp = (void __user *)arg;
594
595 if (copy_from_user(&drce_ctrl, argp, sizeof(struct tas_drce_ctrl_t)))
596 return -EFAULT;
597
598#ifdef DEBUG_DRCE
599 printk("DRCE IOCTL: input [ FLAGS:%x ENABLE:%x THRESH:%x\n",
600 drce_ctrl.flags,
601 drce_ctrl.data.enable,
602 drce_ctrl.data.threshold);
603#endif
604
605 if (cmd & SIOC_IN) {
606 rc = tas3001c_update_drce(self, drce_ctrl.flags, &drce_ctrl.data);
607 if (rc < 0)
608 return rc;
609 }
610
611 if (cmd & SIOC_OUT) {
612 if (drce_ctrl.flags & TAS_DRCE_ENABLE)
613 drce_ctrl.data.enable = self->drce_state.enable;
614
615 if (drce_ctrl.flags & TAS_DRCE_THRESHOLD)
616 drce_ctrl.data.threshold = self->drce_state.threshold;
617
618 if (copy_to_user(argp, &drce_ctrl,
619 sizeof(struct tas_drce_ctrl_t))) {
620 return -EFAULT;
621 }
622 }
623
624 return 0;
625}
626
627static void
628tas3001c_update_device_parameters(struct tas3001c_data_t *self)
629{
630 int i,j;
631
632 if (!self) return;
633
634 if (self->output_id == TAS_OUTPUT_HEADPHONES) {
635 tas3001c_fast_load(self, 1);
636
637 for (i=0; i<TAS3001C_BIQUAD_CHANNEL_COUNT; i++) {
638 for (j=0; j<TAS3001C_BIQUAD_FILTER_COUNT; j++) {
639 tas3001c_write_biquad(self, i, j, &tas3001c_eq_unity);
640 }
641 }
642
643 tas3001c_fast_load(self, 0);
644
645 (void)tas3001c_sync_register(self,TAS3001C_REG_BASS);
646 (void)tas3001c_sync_register(self,TAS3001C_REG_TREBLE);
647 (void)tas3001c_sync_register(self,TAS3001C_REG_MIXER1);
648 (void)tas3001c_sync_register(self,TAS3001C_REG_MIXER2);
649 (void)tas3001c_sync_register(self,TAS3001C_REG_VOLUME);
650
651 return;
652 }
653
654 for (i=0; tas3001c_eq_prefs[i]; i++) {
655 struct tas_eq_pref_t *eq = tas3001c_eq_prefs[i];
656
657 if (eq->device_id == self->device_id &&
658 (eq->output_id == 0 || eq->output_id == self->output_id) &&
659 (eq->speaker_id == 0 || eq->speaker_id == self->speaker_id)) {
660
661 tas3001c_update_drce(self, TAS_DRCE_ALL, eq->drce);
662 tas3001c_write_biquad_list(self, eq->filter_count, TAS_BIQUAD_FAST_LOAD, eq->biquads);
663
664 break;
665 }
666 }
667}
668
669static void
670tas3001c_device_change_handler(void *self)
671{
672 if (self)
673 tas3001c_update_device_parameters(self);
674}
675
676static struct work_struct device_change;
677
678static int
679tas3001c_output_device_change( struct tas3001c_data_t *self,
680 int device_id,
681 int output_id,
682 int speaker_id)
683{
684 self->device_id=device_id;
685 self->output_id=output_id;
686 self->speaker_id=speaker_id;
687
688 schedule_work(&device_change);
689 return 0;
690}
691
692static int
693tas3001c_device_ioctl( struct tas3001c_data_t *self,
694 u_int cmd,
695 u_long arg)
696{
697 uint __user *argp = (void __user *)arg;
698 switch (cmd) {
699 case TAS_READ_EQ:
700 case TAS_WRITE_EQ:
701 return tas3001c_eq_rw(self, cmd, arg);
702
703 case TAS_READ_EQ_LIST:
704 case TAS_WRITE_EQ_LIST:
705 return tas3001c_eq_list_rw(self, cmd, arg);
706
707 case TAS_READ_EQ_FILTER_COUNT:
708 put_user(TAS3001C_BIQUAD_FILTER_COUNT, argp);
709 return 0;
710
711 case TAS_READ_EQ_CHANNEL_COUNT:
712 put_user(TAS3001C_BIQUAD_CHANNEL_COUNT, argp);
713 return 0;
714
715 case TAS_READ_DRCE:
716 case TAS_WRITE_DRCE:
717 return tas3001c_drce_rw(self, cmd, arg);
718
719 case TAS_READ_DRCE_CAPS:
720 put_user(TAS_DRCE_ENABLE | TAS_DRCE_THRESHOLD, argp);
721 return 0;
722
723 case TAS_READ_DRCE_MIN:
724 case TAS_READ_DRCE_MAX: {
725 struct tas_drce_ctrl_t drce_ctrl;
726
727 if (copy_from_user(&drce_ctrl, argp,
728 sizeof(struct tas_drce_ctrl_t))) {
729 return -EFAULT;
730 }
731
732 if (drce_ctrl.flags & TAS_DRCE_THRESHOLD) {
733 if (cmd == TAS_READ_DRCE_MIN) {
734 drce_ctrl.data.threshold=-36<<8;
735 } else {
736 drce_ctrl.data.threshold=-6<<8;
737 }
738 }
739
740 if (copy_to_user(argp, &drce_ctrl,
741 sizeof(struct tas_drce_ctrl_t))) {
742 return -EFAULT;
743 }
744 }
745 }
746
747 return -EINVAL;
748}
749
750static int
751tas3001c_init_mixer(struct tas3001c_data_t *self)
752{
753 unsigned char mcr = (1<<6)+(2<<4)+(2<<2);
754
755 /* Make sure something answers on the i2c bus */
756 if (tas3001c_write_register(self, TAS3001C_REG_MCR, &mcr,
757 WRITE_NORMAL|FORCE_WRITE) < 0)
758 return -1;
759
760 tas3001c_fast_load(self, 1);
761
762 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD0);
763 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD1);
764 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD2);
765 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD3);
766 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD4);
767 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD5);
768 (void)tas3001c_sync_register(self,TAS3001C_REG_RIGHT_BIQUAD6);
769
770 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD0);
771 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD1);
772 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD2);
773 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD3);
774 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD4);
775 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD5);
776 (void)tas3001c_sync_register(self,TAS3001C_REG_LEFT_BIQUAD6);
777
778 tas3001c_fast_load(self, 0);
779
780 tas3001c_set_mixer_level(self, SOUND_MIXER_VOLUME, VOL_DEFAULT<<8 | VOL_DEFAULT);
781 tas3001c_set_mixer_level(self, SOUND_MIXER_PCM, INPUT_DEFAULT<<8 | INPUT_DEFAULT);
782 tas3001c_set_mixer_level(self, SOUND_MIXER_ALTPCM, 0);
783
784 tas3001c_set_mixer_level(self, SOUND_MIXER_BASS, BASS_DEFAULT);
785 tas3001c_set_mixer_level(self, SOUND_MIXER_TREBLE, TREBLE_DEFAULT);
786
787 return 0;
788}
789
790static int
791tas3001c_uninit_mixer(struct tas3001c_data_t *self)
792{
793 tas3001c_set_mixer_level(self, SOUND_MIXER_VOLUME, 0);
794 tas3001c_set_mixer_level(self, SOUND_MIXER_PCM, 0);
795 tas3001c_set_mixer_level(self, SOUND_MIXER_ALTPCM, 0);
796
797 tas3001c_set_mixer_level(self, SOUND_MIXER_BASS, 0);
798 tas3001c_set_mixer_level(self, SOUND_MIXER_TREBLE, 0);
799
800 return 0;
801}
802
803static int
804tas3001c_init(struct i2c_client *client)
805{
806 struct tas3001c_data_t *self;
807 size_t sz = sizeof(*self) + (TAS3001C_REG_MAX*sizeof(tas_shadow_t));
808 int i, j;
809
810 self = kmalloc(sz, GFP_KERNEL);
811 if (!self)
812 return -ENOMEM;
813 memset(self, 0, sz);
814
815 self->super.client = client;
816 self->super.shadow = (tas_shadow_t *)(self+1);
817 self->output_id = TAS_OUTPUT_HEADPHONES;
818
819 dev_set_drvdata(&client->dev, self);
820
821 for (i = 0; i < TAS3001C_BIQUAD_CHANNEL_COUNT; i++)
822 for (j = 0; j < TAS3001C_BIQUAD_FILTER_COUNT; j++)
823 tas3001c_write_biquad_shadow(self, i, j,
824 &tas3001c_eq_unity);
825
826 INIT_WORK(&device_change, tas3001c_device_change_handler, self);
827 return 0;
828}
829
830static void
831tas3001c_uninit(struct tas3001c_data_t *self)
832{
833 tas3001c_uninit_mixer(self);
834 kfree(self);
835}
836
837struct tas_driver_hooks_t tas3001c_hooks = {
838 .init = (tas_hook_init_t)tas3001c_init,
839 .post_init = (tas_hook_post_init_t)tas3001c_init_mixer,
840 .uninit = (tas_hook_uninit_t)tas3001c_uninit,
841 .get_mixer_level = (tas_hook_get_mixer_level_t)tas3001c_get_mixer_level,
842 .set_mixer_level = (tas_hook_set_mixer_level_t)tas3001c_set_mixer_level,
843 .enter_sleep = (tas_hook_enter_sleep_t)tas3001c_enter_sleep,
844 .leave_sleep = (tas_hook_leave_sleep_t)tas3001c_leave_sleep,
845 .supported_mixers = (tas_hook_supported_mixers_t)tas3001c_supported_mixers,
846 .mixer_is_stereo = (tas_hook_mixer_is_stereo_t)tas3001c_mixer_is_stereo,
847 .stereo_mixers = (tas_hook_stereo_mixers_t)tas3001c_stereo_mixers,
848 .output_device_change = (tas_hook_output_device_change_t)tas3001c_output_device_change,
849 .device_ioctl = (tas_hook_device_ioctl_t)tas3001c_device_ioctl
850};
diff --git a/sound/oss/dmasound/tas3001c.h b/sound/oss/dmasound/tas3001c.h
new file mode 100644
index 000000000000..3660da33a2db
--- /dev/null
+++ b/sound/oss/dmasound/tas3001c.h
@@ -0,0 +1,64 @@
1/*
2 * Header file for the i2c/i2s based TA3001c sound chip used
3 * on some Apple hardware. Also known as "tumbler".
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive
7 * for more details.
8 *
9 * Written by Christopher C. Chimelis <chris@debian.org>
10 */
11
12#ifndef _TAS3001C_H_
13#define _TAS3001C_H_
14
15#include <linux/types.h>
16
17#include "tas_common.h"
18#include "tas_eq_prefs.h"
19
20/*
21 * Macros that correspond to the registers that we write to
22 * when setting the various values.
23 */
24
25#define TAS3001C_VERSION "0.3"
26#define TAS3001C_DATE "20011214"
27
28#define I2C_DRIVERNAME_TAS3001C "TAS3001c driver V " TAS3001C_VERSION
29#define I2C_DRIVERID_TAS3001C (I2C_DRIVERID_TAS_BASE+0)
30
31extern struct tas_driver_hooks_t tas3001c_hooks;
32extern struct tas_gain_t tas3001c_gain;
33extern struct tas_eq_pref_t *tas3001c_eq_prefs[];
34
35enum tas3001c_reg_t {
36 TAS3001C_REG_MCR = 0x01,
37 TAS3001C_REG_DRC = 0x02,
38
39 TAS3001C_REG_VOLUME = 0x04,
40 TAS3001C_REG_TREBLE = 0x05,
41 TAS3001C_REG_BASS = 0x06,
42 TAS3001C_REG_MIXER1 = 0x07,
43 TAS3001C_REG_MIXER2 = 0x08,
44
45 TAS3001C_REG_LEFT_BIQUAD0 = 0x0a,
46 TAS3001C_REG_LEFT_BIQUAD1 = 0x0b,
47 TAS3001C_REG_LEFT_BIQUAD2 = 0x0c,
48 TAS3001C_REG_LEFT_BIQUAD3 = 0x0d,
49 TAS3001C_REG_LEFT_BIQUAD4 = 0x0e,
50 TAS3001C_REG_LEFT_BIQUAD5 = 0x0f,
51 TAS3001C_REG_LEFT_BIQUAD6 = 0x10,
52
53 TAS3001C_REG_RIGHT_BIQUAD0 = 0x13,
54 TAS3001C_REG_RIGHT_BIQUAD1 = 0x14,
55 TAS3001C_REG_RIGHT_BIQUAD2 = 0x15,
56 TAS3001C_REG_RIGHT_BIQUAD3 = 0x16,
57 TAS3001C_REG_RIGHT_BIQUAD4 = 0x17,
58 TAS3001C_REG_RIGHT_BIQUAD5 = 0x18,
59 TAS3001C_REG_RIGHT_BIQUAD6 = 0x19,
60
61 TAS3001C_REG_MAX = 0x20
62};
63
64#endif /* _TAS3001C_H_ */
diff --git a/sound/oss/dmasound/tas3001c_tables.c b/sound/oss/dmasound/tas3001c_tables.c
new file mode 100644
index 000000000000..1768fa95f25b
--- /dev/null
+++ b/sound/oss/dmasound/tas3001c_tables.c
@@ -0,0 +1,375 @@
1#include "tas_common.h"
2#include "tas_eq_prefs.h"
3
4static struct tas_drce_t eqp_0e_2_1_drce = {
5 .enable = 1,
6 .above = { .val = 3.0 * (1<<8), .expand = 0 },
7 .below = { .val = 1.0 * (1<<8), .expand = 0 },
8 .threshold = -15.33 * (1<<8),
9 .energy = 2.4 * (1<<12),
10 .attack = 0.013 * (1<<12),
11 .decay = 0.212 * (1<<12),
12};
13
14static struct tas_biquad_ctrl_t eqp_0e_2_1_biquads[]={
15 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0FCAD3, 0xE06A58, 0x0FCAD3, 0xE06B09, 0x0F9657 } } },
16 { .channel = 0, .filter = 1, .data = { .coeff = { 0x041731, 0x082E63, 0x041731, 0xFD8D08, 0x02CFBD } } },
17 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0FFDC7, 0xE0524C, 0x0FBFAA, 0xE0524C, 0x0FBD72 } } },
18 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0F3D35, 0xE228CA, 0x0EC7B2, 0xE228CA, 0x0E04E8 } } },
19 { .channel = 0, .filter = 4, .data = { .coeff = { 0x0FCEBF, 0xE181C2, 0x0F2656, 0xE181C2, 0x0EF516 } } },
20 { .channel = 0, .filter = 5, .data = { .coeff = { 0x0EC417, 0x073E22, 0x0B0633, 0x073E22, 0x09CA4A } } },
21
22 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0FCAD3, 0xE06A58, 0x0FCAD3, 0xE06B09, 0x0F9657 } } },
23 { .channel = 1, .filter = 1, .data = { .coeff = { 0x041731, 0x082E63, 0x041731, 0xFD8D08, 0x02CFBD } } },
24 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0FFDC7, 0xE0524C, 0x0FBFAA, 0xE0524C, 0x0FBD72 } } },
25 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0F3D35, 0xE228CA, 0x0EC7B2, 0xE228CA, 0x0E04E8 } } },
26 { .channel = 1, .filter = 4, .data = { .coeff = { 0x0FCEBF, 0xE181C2, 0x0F2656, 0xE181C2, 0x0EF516 } } },
27 { .channel = 1, .filter = 5, .data = { .coeff = { 0x0EC417, 0x073E22, 0x0B0633, 0x073E22, 0x09CA4A } } },
28};
29
30static struct tas_eq_pref_t eqp_0e_2_1 = {
31 .sample_rate = 44100,
32 .device_id = 0x0e,
33 .output_id = TAS_OUTPUT_EXTERNAL_SPKR,
34 .speaker_id = 0x01,
35
36 .drce = &eqp_0e_2_1_drce,
37
38 .filter_count = 12,
39 .biquads = eqp_0e_2_1_biquads
40};
41
42/* ======================================================================== */
43
44static struct tas_drce_t eqp_10_1_0_drce={
45 .enable = 1,
46 .above = { .val = 3.0 * (1<<8), .expand = 0 },
47 .below = { .val = 1.0 * (1<<8), .expand = 0 },
48 .threshold = -12.46 * (1<<8),
49 .energy = 2.4 * (1<<12),
50 .attack = 0.013 * (1<<12),
51 .decay = 0.212 * (1<<12),
52};
53
54static struct tas_biquad_ctrl_t eqp_10_1_0_biquads[]={
55 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0F4A12, 0xE16BDA, 0x0F4A12, 0xE173F0, 0x0E9C3A } } },
56 { .channel = 0, .filter = 1, .data = { .coeff = { 0x02DD54, 0x05BAA8, 0x02DD54, 0xF8001D, 0x037532 } } },
57 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0E2FC7, 0xE4D5DC, 0x0D7477, 0xE4D5DC, 0x0BA43F } } },
58 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0E7899, 0xE67CCA, 0x0D0E93, 0xE67CCA, 0x0B872D } } },
59 { .channel = 0, .filter = 4, .data = { .coeff = { 0x100000, 0x000000, 0x000000, 0x000000, 0x000000 } } },
60 { .channel = 0, .filter = 5, .data = { .coeff = { 0x100000, 0x000000, 0x000000, 0x000000, 0x000000 } } },
61
62 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0F4A12, 0xE16BDA, 0x0F4A12, 0xE173F0, 0x0E9C3A } } },
63 { .channel = 1, .filter = 1, .data = { .coeff = { 0x02DD54, 0x05BAA8, 0x02DD54, 0xF8001D, 0x037532 } } },
64 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0E2FC7, 0xE4D5DC, 0x0D7477, 0xE4D5DC, 0x0BA43F } } },
65 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0E7899, 0xE67CCA, 0x0D0E93, 0xE67CCA, 0x0B872D } } },
66 { .channel = 1, .filter = 4, .data = { .coeff = { 0x100000, 0x000000, 0x000000, 0x000000, 0x000000 } } },
67 { .channel = 1, .filter = 5, .data = { .coeff = { 0x100000, 0x000000, 0x000000, 0x000000, 0x000000 } } },
68};
69
70static struct tas_eq_pref_t eqp_10_1_0 = {
71 .sample_rate = 44100,
72 .device_id = 0x10,
73 .output_id = TAS_OUTPUT_INTERNAL_SPKR,
74 .speaker_id = 0x00,
75
76 .drce = &eqp_10_1_0_drce,
77
78 .filter_count = 12,
79 .biquads = eqp_10_1_0_biquads
80};
81
82/* ======================================================================== */
83
84static struct tas_drce_t eqp_15_2_1_drce={
85 .enable = 1,
86 .above = { .val = 3.0 * (1<<8), .expand = 0 },
87 .below = { .val = 1.0 * (1<<8), .expand = 0 },
88 .threshold = -15.33 * (1<<8),
89 .energy = 2.4 * (1<<12),
90 .attack = 0.013 * (1<<12),
91 .decay = 0.212 * (1<<12),
92};
93
94static struct tas_biquad_ctrl_t eqp_15_2_1_biquads[]={
95 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0FE143, 0xE05204, 0x0FCCC5, 0xE05266, 0x0FAE6B } } },
96 { .channel = 0, .filter = 1, .data = { .coeff = { 0x102383, 0xE03A03, 0x0FA325, 0xE03A03, 0x0FC6A8 } } },
97 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0FF2AB, 0xE06285, 0x0FB20A, 0xE06285, 0x0FA4B5 } } },
98 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0F544D, 0xE35971, 0x0D8F3A, 0xE35971, 0x0CE388 } } },
99 { .channel = 0, .filter = 4, .data = { .coeff = { 0x13E1D3, 0xF3ECB5, 0x042227, 0xF3ECB5, 0x0803FA } } },
100 { .channel = 0, .filter = 5, .data = { .coeff = { 0x0AC119, 0x034181, 0x078AB1, 0x034181, 0x024BCA } } },
101
102 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0FE143, 0xE05204, 0x0FCCC5, 0xE05266, 0x0FAE6B } } },
103 { .channel = 1, .filter = 1, .data = { .coeff = { 0x102383, 0xE03A03, 0x0FA325, 0xE03A03, 0x0FC6A8 } } },
104 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0FF2AB, 0xE06285, 0x0FB20A, 0xE06285, 0x0FA4B5 } } },
105 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0F544D, 0xE35971, 0x0D8F3A, 0xE35971, 0x0CE388 } } },
106 { .channel = 1, .filter = 4, .data = { .coeff = { 0x13E1D3, 0xF3ECB5, 0x042227, 0xF3ECB5, 0x0803FA } } },
107 { .channel = 1, .filter = 5, .data = { .coeff = { 0x0AC119, 0x034181, 0x078AB1, 0x034181, 0x024BCA } } },
108};
109
110static struct tas_eq_pref_t eqp_15_2_1 = {
111 .sample_rate = 44100,
112 .device_id = 0x15,
113 .output_id = TAS_OUTPUT_EXTERNAL_SPKR,
114 .speaker_id = 0x01,
115
116 .drce = &eqp_15_2_1_drce,
117
118 .filter_count = 12,
119 .biquads = eqp_15_2_1_biquads
120};
121
122/* ======================================================================== */
123
124static struct tas_drce_t eqp_15_1_0_drce={
125 .enable = 1,
126 .above = { .val = 3.0 * (1<<8), .expand = 0 },
127 .below = { .val = 1.0 * (1<<8), .expand = 0 },
128 .threshold = 0.0 * (1<<8),
129 .energy = 2.4 * (1<<12),
130 .attack = 0.013 * (1<<12),
131 .decay = 0.212 * (1<<12),
132};
133
134static struct tas_biquad_ctrl_t eqp_15_1_0_biquads[]={
135 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0FAD08, 0xE0A5EF, 0x0FAD08, 0xE0A79D, 0x0F5BBE } } },
136 { .channel = 0, .filter = 1, .data = { .coeff = { 0x04B38D, 0x09671B, 0x04B38D, 0x000F71, 0x02BEC5 } } },
137 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0FDD32, 0xE0A56F, 0x0F8A69, 0xE0A56F, 0x0F679C } } },
138 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0FD284, 0xE135FB, 0x0F2161, 0xE135FB, 0x0EF3E5 } } },
139 { .channel = 0, .filter = 4, .data = { .coeff = { 0x0E81B1, 0xE6283F, 0x0CE49D, 0xE6283F, 0x0B664F } } },
140 { .channel = 0, .filter = 5, .data = { .coeff = { 0x0F2D62, 0xE98797, 0x0D1E19, 0xE98797, 0x0C4B7B } } },
141
142 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0FAD08, 0xE0A5EF, 0x0FAD08, 0xE0A79D, 0x0F5BBE } } },
143 { .channel = 1, .filter = 1, .data = { .coeff = { 0x04B38D, 0x09671B, 0x04B38D, 0x000F71, 0x02BEC5 } } },
144 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0FDD32, 0xE0A56F, 0x0F8A69, 0xE0A56F, 0x0F679C } } },
145 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0FD284, 0xE135FB, 0x0F2161, 0xE135FB, 0x0EF3E5 } } },
146 { .channel = 1, .filter = 4, .data = { .coeff = { 0x0E81B1, 0xE6283F, 0x0CE49D, 0xE6283F, 0x0B664F } } },
147 { .channel = 1, .filter = 5, .data = { .coeff = { 0x0F2D62, 0xE98797, 0x0D1E19, 0xE98797, 0x0C4B7B } } },
148};
149
150static struct tas_eq_pref_t eqp_15_1_0 = {
151 .sample_rate = 44100,
152 .device_id = 0x15,
153 .output_id = TAS_OUTPUT_INTERNAL_SPKR,
154 .speaker_id = 0x00,
155
156 .drce = &eqp_15_1_0_drce,
157
158 .filter_count = 12,
159 .biquads = eqp_15_1_0_biquads
160};
161
162/* ======================================================================== */
163
164static struct tas_drce_t eqp_0f_2_1_drce={
165 .enable = 1,
166 .above = { .val = 3.0 * (1<<8), .expand = 0 },
167 .below = { .val = 1.0 * (1<<8), .expand = 0 },
168 .threshold = -15.33 * (1<<8),
169 .energy = 2.4 * (1<<12),
170 .attack = 0.013 * (1<<12),
171 .decay = 0.212 * (1<<12),
172};
173
174static struct tas_biquad_ctrl_t eqp_0f_2_1_biquads[]={
175 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0FE143, 0xE05204, 0x0FCCC5, 0xE05266, 0x0FAE6B } } },
176 { .channel = 0, .filter = 1, .data = { .coeff = { 0x102383, 0xE03A03, 0x0FA325, 0xE03A03, 0x0FC6A8 } } },
177 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0FF2AB, 0xE06285, 0x0FB20A, 0xE06285, 0x0FA4B5 } } },
178 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0F544D, 0xE35971, 0x0D8F3A, 0xE35971, 0x0CE388 } } },
179 { .channel = 0, .filter = 4, .data = { .coeff = { 0x13E1D3, 0xF3ECB5, 0x042227, 0xF3ECB5, 0x0803FA } } },
180 { .channel = 0, .filter = 5, .data = { .coeff = { 0x0AC119, 0x034181, 0x078AB1, 0x034181, 0x024BCA } } },
181
182 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0FE143, 0xE05204, 0x0FCCC5, 0xE05266, 0x0FAE6B } } },
183 { .channel = 1, .filter = 1, .data = { .coeff = { 0x102383, 0xE03A03, 0x0FA325, 0xE03A03, 0x0FC6A8 } } },
184 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0FF2AB, 0xE06285, 0x0FB20A, 0xE06285, 0x0FA4B5 } } },
185 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0F544D, 0xE35971, 0x0D8F3A, 0xE35971, 0x0CE388 } } },
186 { .channel = 1, .filter = 4, .data = { .coeff = { 0x13E1D3, 0xF3ECB5, 0x042227, 0xF3ECB5, 0x0803FA } } },
187 { .channel = 1, .filter = 5, .data = { .coeff = { 0x0AC119, 0x034181, 0x078AB1, 0x034181, 0x024BCA } } },
188};
189
190static struct tas_eq_pref_t eqp_0f_2_1 = {
191 .sample_rate = 44100,
192 .device_id = 0x0f,
193 .output_id = TAS_OUTPUT_EXTERNAL_SPKR,
194 .speaker_id = 0x01,
195
196 .drce = &eqp_0f_2_1_drce,
197
198 .filter_count = 12,
199 .biquads = eqp_0f_2_1_biquads
200};
201
202/* ======================================================================== */
203
204static struct tas_drce_t eqp_0f_1_0_drce={
205 .enable = 1,
206 .above = { .val = 3.0 * (1<<8), .expand = 0 },
207 .below = { .val = 1.0 * (1<<8), .expand = 0 },
208 .threshold = -15.33 * (1<<8),
209 .energy = 2.4 * (1<<12),
210 .attack = 0.013 * (1<<12),
211 .decay = 0.212 * (1<<12),
212};
213
214static struct tas_biquad_ctrl_t eqp_0f_1_0_biquads[]={
215 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0FCAD3, 0xE06A58, 0x0FCAD3, 0xE06B09, 0x0F9657 } } },
216 { .channel = 0, .filter = 1, .data = { .coeff = { 0x041731, 0x082E63, 0x041731, 0xFD8D08, 0x02CFBD } } },
217 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0FFDC7, 0xE0524C, 0x0FBFAA, 0xE0524C, 0x0FBD72 } } },
218 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0F3D35, 0xE228CA, 0x0EC7B2, 0xE228CA, 0x0E04E8 } } },
219 { .channel = 0, .filter = 4, .data = { .coeff = { 0x0FCEBF, 0xE181C2, 0x0F2656, 0xE181C2, 0x0EF516 } } },
220 { .channel = 0, .filter = 5, .data = { .coeff = { 0x0EC417, 0x073E22, 0x0B0633, 0x073E22, 0x09CA4A } } },
221
222 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0FCAD3, 0xE06A58, 0x0FCAD3, 0xE06B09, 0x0F9657 } } },
223 { .channel = 1, .filter = 1, .data = { .coeff = { 0x041731, 0x082E63, 0x041731, 0xFD8D08, 0x02CFBD } } },
224 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0FFDC7, 0xE0524C, 0x0FBFAA, 0xE0524C, 0x0FBD72 } } },
225 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0F3D35, 0xE228CA, 0x0EC7B2, 0xE228CA, 0x0E04E8 } } },
226 { .channel = 1, .filter = 4, .data = { .coeff = { 0x0FCEBF, 0xE181C2, 0x0F2656, 0xE181C2, 0x0EF516 } } },
227 { .channel = 1, .filter = 5, .data = { .coeff = { 0x0EC417, 0x073E22, 0x0B0633, 0x073E22, 0x09CA4A } } },
228};
229
230static struct tas_eq_pref_t eqp_0f_1_0 = {
231 .sample_rate = 44100,
232 .device_id = 0x0f,
233 .output_id = TAS_OUTPUT_INTERNAL_SPKR,
234 .speaker_id = 0x00,
235
236 .drce = &eqp_0f_1_0_drce,
237
238 .filter_count = 12,
239 .biquads = eqp_0f_1_0_biquads
240};
241
242/* ======================================================================== */
243
244static uint tas3001c_master_tab[]={
245 0x0, 0x75, 0x9c, 0xbb,
246 0xdb, 0xfb, 0x11e, 0x143,
247 0x16b, 0x196, 0x1c3, 0x1f5,
248 0x229, 0x263, 0x29f, 0x2e1,
249 0x328, 0x373, 0x3c5, 0x41b,
250 0x478, 0x4dc, 0x547, 0x5b8,
251 0x633, 0x6b5, 0x740, 0x7d5,
252 0x873, 0x91c, 0x9d2, 0xa92,
253 0xb5e, 0xc39, 0xd22, 0xe19,
254 0xf20, 0x1037, 0x1161, 0x129e,
255 0x13ed, 0x1551, 0x16ca, 0x185d,
256 0x1a08, 0x1bcc, 0x1dac, 0x1fa7,
257 0x21c1, 0x23fa, 0x2655, 0x28d6,
258 0x2b7c, 0x2e4a, 0x3141, 0x3464,
259 0x37b4, 0x3b35, 0x3ee9, 0x42d3,
260 0x46f6, 0x4b53, 0x4ff0, 0x54ce,
261 0x59f2, 0x5f5f, 0x6519, 0x6b24,
262 0x7183, 0x783c, 0x7f53, 0x86cc,
263 0x8ead, 0x96fa, 0x9fba, 0xa8f2,
264 0xb2a7, 0xbce1, 0xc7a5, 0xd2fa,
265 0xdee8, 0xeb75, 0xf8aa, 0x1068e,
266 0x1152a, 0x12487, 0x134ad, 0x145a5,
267 0x1577b, 0x16a37, 0x17df5, 0x192bd,
268 0x1a890, 0x1bf7b, 0x1d78d, 0x1f0d1,
269 0x20b55, 0x22727, 0x24456, 0x262f2,
270 0x2830b
271};
272
273static uint tas3001c_mixer_tab[]={
274 0x0, 0x748, 0x9be, 0xbaf,
275 0xda4, 0xfb1, 0x11de, 0x1431,
276 0x16ad, 0x1959, 0x1c37, 0x1f4b,
277 0x2298, 0x2628, 0x29fb, 0x2e12,
278 0x327d, 0x3734, 0x3c47, 0x41b4,
279 0x4787, 0x4dbe, 0x546d, 0x5b86,
280 0x632e, 0x6b52, 0x7400, 0x7d54,
281 0x873b, 0x91c6, 0x9d1a, 0xa920,
282 0xb5e5, 0xc38c, 0xd21b, 0xe18f,
283 0xf1f5, 0x1036a, 0x1160f, 0x129d6,
284 0x13ed0, 0x1550c, 0x16ca0, 0x185c9,
285 0x1a07b, 0x1bcc3, 0x1dab9, 0x1fa75,
286 0x21c0f, 0x23fa3, 0x26552, 0x28d64,
287 0x2b7c9, 0x2e4a2, 0x31411, 0x3463b,
288 0x37b44, 0x3b353, 0x3ee94, 0x42d30,
289 0x46f55, 0x4b533, 0x4fefc, 0x54ce5,
290 0x59f25, 0x5f5f6, 0x65193, 0x6b23c,
291 0x71835, 0x783c3, 0x7f52c, 0x86cc0,
292 0x8eacc, 0x96fa5, 0x9fba0, 0xa8f1a,
293 0xb2a71, 0xbce0a, 0xc7a4a, 0xd2fa0,
294 0xdee7b, 0xeb752, 0xf8a9f, 0x1068e4,
295 0x1152a3, 0x12486a, 0x134ac8, 0x145a55,
296 0x1577ac, 0x16a370, 0x17df51, 0x192bc2,
297 0x1a88f8, 0x1bf7b7, 0x1d78c9, 0x1f0d04,
298 0x20b542, 0x227268, 0x244564, 0x262f26,
299 0x2830af
300};
301
302static uint tas3001c_treble_tab[]={
303 0x96, 0x95, 0x95, 0x94,
304 0x93, 0x92, 0x92, 0x91,
305 0x90, 0x90, 0x8f, 0x8e,
306 0x8d, 0x8d, 0x8c, 0x8b,
307 0x8a, 0x8a, 0x89, 0x88,
308 0x88, 0x87, 0x86, 0x85,
309 0x85, 0x84, 0x83, 0x83,
310 0x82, 0x81, 0x80, 0x80,
311 0x7f, 0x7e, 0x7e, 0x7d,
312 0x7c, 0x7b, 0x7b, 0x7a,
313 0x79, 0x78, 0x78, 0x77,
314 0x76, 0x76, 0x75, 0x74,
315 0x73, 0x73, 0x72, 0x71,
316 0x71, 0x70, 0x6e, 0x6d,
317 0x6d, 0x6c, 0x6b, 0x6a,
318 0x69, 0x68, 0x67, 0x66,
319 0x65, 0x63, 0x62, 0x62,
320 0x60, 0x5f, 0x5d, 0x5c,
321 0x5a, 0x58, 0x56, 0x55,
322 0x53, 0x51, 0x4f, 0x4c,
323 0x4a, 0x48, 0x45, 0x43,
324 0x40, 0x3d, 0x3a, 0x37,
325 0x35, 0x32, 0x2e, 0x2a,
326 0x27, 0x22, 0x1e, 0x1a,
327 0x15, 0x11, 0xc, 0x7,
328 0x1
329};
330
331static uint tas3001c_bass_tab[]={
332 0x86, 0x83, 0x81, 0x7f,
333 0x7d, 0x7b, 0x79, 0x78,
334 0x76, 0x75, 0x74, 0x72,
335 0x71, 0x6f, 0x6e, 0x6d,
336 0x6c, 0x6b, 0x69, 0x67,
337 0x65, 0x64, 0x61, 0x60,
338 0x5e, 0x5d, 0x5c, 0x5b,
339 0x5a, 0x59, 0x58, 0x57,
340 0x56, 0x55, 0x55, 0x54,
341 0x53, 0x52, 0x50, 0x4f,
342 0x4d, 0x4c, 0x4b, 0x49,
343 0x47, 0x45, 0x44, 0x42,
344 0x41, 0x3f, 0x3e, 0x3d,
345 0x3c, 0x3b, 0x39, 0x38,
346 0x37, 0x36, 0x35, 0x34,
347 0x33, 0x31, 0x30, 0x2f,
348 0x2e, 0x2c, 0x2b, 0x2b,
349 0x29, 0x28, 0x27, 0x26,
350 0x25, 0x24, 0x22, 0x21,
351 0x20, 0x1e, 0x1c, 0x19,
352 0x18, 0x18, 0x17, 0x16,
353 0x15, 0x14, 0x13, 0x12,
354 0x11, 0x10, 0xf, 0xe,
355 0xd, 0xb, 0xa, 0x9,
356 0x8, 0x6, 0x4, 0x2,
357 0x1
358};
359
360struct tas_gain_t tas3001c_gain = {
361 .master = tas3001c_master_tab,
362 .treble = tas3001c_treble_tab,
363 .bass = tas3001c_bass_tab,
364 .mixer = tas3001c_mixer_tab
365};
366
367struct tas_eq_pref_t *tas3001c_eq_prefs[]={
368 &eqp_0e_2_1,
369 &eqp_10_1_0,
370 &eqp_15_2_1,
371 &eqp_15_1_0,
372 &eqp_0f_2_1,
373 &eqp_0f_1_0,
374 NULL
375};
diff --git a/sound/oss/dmasound/tas3004.c b/sound/oss/dmasound/tas3004.c
new file mode 100644
index 000000000000..82eaaca2db9a
--- /dev/null
+++ b/sound/oss/dmasound/tas3004.c
@@ -0,0 +1,1140 @@
1/*
2 * Driver for the i2c/i2s based TA3004 sound chip used
3 * on some Apple hardware. Also known as "snapper".
4 *
5 * Tobias Sargeant <tobias.sargeant@bigpond.com>
6 * Based upon tas3001c.c by Christopher C. Chimelis <chris@debian.org>:
7 *
8 * Input support by Renzo Davoli <renzo@cs.unibo.it>
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/proc_fs.h>
15#include <linux/ioport.h>
16#include <linux/sysctl.h>
17#include <linux/types.h>
18#include <linux/i2c.h>
19#include <linux/init.h>
20#include <linux/soundcard.h>
21#include <linux/interrupt.h>
22#include <linux/workqueue.h>
23
24#include <asm/uaccess.h>
25#include <asm/errno.h>
26#include <asm/io.h>
27#include <asm/prom.h>
28
29#include "dmasound.h"
30#include "tas_common.h"
31#include "tas3004.h"
32
33#include "tas_ioctl.h"
34
35/* #define DEBUG_DRCE */
36
37#define TAS3004_BIQUAD_FILTER_COUNT 7
38#define TAS3004_BIQUAD_CHANNEL_COUNT 2
39
40#define VOL_DEFAULT (100 * 4 / 5)
41#define INPUT_DEFAULT (100 * 4 / 5)
42#define BASS_DEFAULT (100 / 2)
43#define TREBLE_DEFAULT (100 / 2)
44
45struct tas3004_data_t {
46 struct tas_data_t super;
47 int device_id;
48 int output_id;
49 int speaker_id;
50 struct tas_drce_t drce_state;
51};
52
53#define MAKE_TIME(sec,usec) (((sec)<<12) + (50000+(usec/10)*(1<<12))/100000)
54
55#define MAKE_RATIO(i,f) (((i)<<8) + ((500+(f)*(1<<8))/1000))
56
57
58static const union tas_biquad_t tas3004_eq_unity = {
59 .buf = { 0x100000, 0x000000, 0x000000, 0x000000, 0x000000 },
60};
61
62
63static const struct tas_drce_t tas3004_drce_min = {
64 .enable = 1,
65 .above = { .val = MAKE_RATIO(16,0), .expand = 0 },
66 .below = { .val = MAKE_RATIO(2,0), .expand = 0 },
67 .threshold = -0x59a0,
68 .energy = MAKE_TIME(0, 1700),
69 .attack = MAKE_TIME(0, 1700),
70 .decay = MAKE_TIME(0, 1700),
71};
72
73
74static const struct tas_drce_t tas3004_drce_max = {
75 .enable = 1,
76 .above = { .val = MAKE_RATIO(1,500), .expand = 1 },
77 .below = { .val = MAKE_RATIO(2,0), .expand = 1 },
78 .threshold = -0x0,
79 .energy = MAKE_TIME(2,400000),
80 .attack = MAKE_TIME(2,400000),
81 .decay = MAKE_TIME(2,400000),
82};
83
84
85static const unsigned short time_constants[]={
86 MAKE_TIME(0, 1700),
87 MAKE_TIME(0, 3500),
88 MAKE_TIME(0, 6700),
89 MAKE_TIME(0, 13000),
90 MAKE_TIME(0, 26000),
91 MAKE_TIME(0, 53000),
92 MAKE_TIME(0,106000),
93 MAKE_TIME(0,212000),
94 MAKE_TIME(0,425000),
95 MAKE_TIME(0,850000),
96 MAKE_TIME(1,700000),
97 MAKE_TIME(2,400000),
98};
99
100static const unsigned short above_threshold_compression_ratio[]={
101 MAKE_RATIO( 1, 70),
102 MAKE_RATIO( 1,140),
103 MAKE_RATIO( 1,230),
104 MAKE_RATIO( 1,330),
105 MAKE_RATIO( 1,450),
106 MAKE_RATIO( 1,600),
107 MAKE_RATIO( 1,780),
108 MAKE_RATIO( 2, 0),
109 MAKE_RATIO( 2,290),
110 MAKE_RATIO( 2,670),
111 MAKE_RATIO( 3,200),
112 MAKE_RATIO( 4, 0),
113 MAKE_RATIO( 5,330),
114 MAKE_RATIO( 8, 0),
115 MAKE_RATIO(16, 0),
116};
117
118static const unsigned short above_threshold_expansion_ratio[]={
119 MAKE_RATIO(1, 60),
120 MAKE_RATIO(1,130),
121 MAKE_RATIO(1,190),
122 MAKE_RATIO(1,250),
123 MAKE_RATIO(1,310),
124 MAKE_RATIO(1,380),
125 MAKE_RATIO(1,440),
126 MAKE_RATIO(1,500)
127};
128
129static const unsigned short below_threshold_compression_ratio[]={
130 MAKE_RATIO(1, 70),
131 MAKE_RATIO(1,140),
132 MAKE_RATIO(1,230),
133 MAKE_RATIO(1,330),
134 MAKE_RATIO(1,450),
135 MAKE_RATIO(1,600),
136 MAKE_RATIO(1,780),
137 MAKE_RATIO(2, 0)
138};
139
140static const unsigned short below_threshold_expansion_ratio[]={
141 MAKE_RATIO(1, 60),
142 MAKE_RATIO(1,130),
143 MAKE_RATIO(1,190),
144 MAKE_RATIO(1,250),
145 MAKE_RATIO(1,310),
146 MAKE_RATIO(1,380),
147 MAKE_RATIO(1,440),
148 MAKE_RATIO(1,500),
149 MAKE_RATIO(1,560),
150 MAKE_RATIO(1,630),
151 MAKE_RATIO(1,690),
152 MAKE_RATIO(1,750),
153 MAKE_RATIO(1,810),
154 MAKE_RATIO(1,880),
155 MAKE_RATIO(1,940),
156 MAKE_RATIO(2, 0)
157};
158
159static inline int
160search( unsigned short val,
161 const unsigned short *arr,
162 const int arrsize) {
163 /*
164 * This could be a binary search, but for small tables,
165 * a linear search is likely to be faster
166 */
167
168 int i;
169
170 for (i=0; i < arrsize; i++)
171 if (arr[i] >= val)
172 goto _1;
173 return arrsize-1;
174 _1:
175 if (i == 0)
176 return 0;
177 return (arr[i]-val < val-arr[i-1]) ? i : i-1;
178}
179
180#define SEARCH(a, b) search(a, b, ARRAY_SIZE(b))
181
182static inline int
183time_index(unsigned short time)
184{
185 return SEARCH(time, time_constants);
186}
187
188
189static inline int
190above_threshold_compression_index(unsigned short ratio)
191{
192 return SEARCH(ratio, above_threshold_compression_ratio);
193}
194
195
196static inline int
197above_threshold_expansion_index(unsigned short ratio)
198{
199 return SEARCH(ratio, above_threshold_expansion_ratio);
200}
201
202
203static inline int
204below_threshold_compression_index(unsigned short ratio)
205{
206 return SEARCH(ratio, below_threshold_compression_ratio);
207}
208
209
210static inline int
211below_threshold_expansion_index(unsigned short ratio)
212{
213 return SEARCH(ratio, below_threshold_expansion_ratio);
214}
215
216static inline unsigned char db_to_regval(short db) {
217 int r=0;
218
219 r=(db+0x59a0) / 0x60;
220
221 if (r < 0x91) return 0x91;
222 if (r > 0xef) return 0xef;
223 return r;
224}
225
226static inline short quantize_db(short db)
227{
228 return db_to_regval(db) * 0x60 - 0x59a0;
229}
230
231static inline int
232register_width(enum tas3004_reg_t r)
233{
234 switch(r) {
235 case TAS3004_REG_MCR:
236 case TAS3004_REG_TREBLE:
237 case TAS3004_REG_BASS:
238 case TAS3004_REG_ANALOG_CTRL:
239 case TAS3004_REG_TEST1:
240 case TAS3004_REG_TEST2:
241 case TAS3004_REG_MCR2:
242 return 1;
243
244 case TAS3004_REG_LEFT_LOUD_BIQUAD_GAIN:
245 case TAS3004_REG_RIGHT_LOUD_BIQUAD_GAIN:
246 return 3;
247
248 case TAS3004_REG_DRC:
249 case TAS3004_REG_VOLUME:
250 return 6;
251
252 case TAS3004_REG_LEFT_MIXER:
253 case TAS3004_REG_RIGHT_MIXER:
254 return 9;
255
256 case TAS3004_REG_TEST:
257 return 10;
258
259 case TAS3004_REG_LEFT_BIQUAD0:
260 case TAS3004_REG_LEFT_BIQUAD1:
261 case TAS3004_REG_LEFT_BIQUAD2:
262 case TAS3004_REG_LEFT_BIQUAD3:
263 case TAS3004_REG_LEFT_BIQUAD4:
264 case TAS3004_REG_LEFT_BIQUAD5:
265 case TAS3004_REG_LEFT_BIQUAD6:
266
267 case TAS3004_REG_RIGHT_BIQUAD0:
268 case TAS3004_REG_RIGHT_BIQUAD1:
269 case TAS3004_REG_RIGHT_BIQUAD2:
270 case TAS3004_REG_RIGHT_BIQUAD3:
271 case TAS3004_REG_RIGHT_BIQUAD4:
272 case TAS3004_REG_RIGHT_BIQUAD5:
273 case TAS3004_REG_RIGHT_BIQUAD6:
274
275 case TAS3004_REG_LEFT_LOUD_BIQUAD:
276 case TAS3004_REG_RIGHT_LOUD_BIQUAD:
277 return 15;
278
279 default:
280 return 0;
281 }
282}
283
284static int
285tas3004_write_register( struct tas3004_data_t *self,
286 enum tas3004_reg_t reg_num,
287 char *data,
288 uint write_mode)
289{
290 if (reg_num==TAS3004_REG_MCR ||
291 reg_num==TAS3004_REG_BASS ||
292 reg_num==TAS3004_REG_TREBLE ||
293 reg_num==TAS3004_REG_ANALOG_CTRL) {
294 return tas_write_byte_register(&self->super,
295 (uint)reg_num,
296 *data,
297 write_mode);
298 } else {
299 return tas_write_register(&self->super,
300 (uint)reg_num,
301 register_width(reg_num),
302 data,
303 write_mode);
304 }
305}
306
307static int
308tas3004_sync_register( struct tas3004_data_t *self,
309 enum tas3004_reg_t reg_num)
310{
311 if (reg_num==TAS3004_REG_MCR ||
312 reg_num==TAS3004_REG_BASS ||
313 reg_num==TAS3004_REG_TREBLE ||
314 reg_num==TAS3004_REG_ANALOG_CTRL) {
315 return tas_sync_byte_register(&self->super,
316 (uint)reg_num,
317 register_width(reg_num));
318 } else {
319 return tas_sync_register(&self->super,
320 (uint)reg_num,
321 register_width(reg_num));
322 }
323}
324
325static int
326tas3004_read_register( struct tas3004_data_t *self,
327 enum tas3004_reg_t reg_num,
328 char *data,
329 uint write_mode)
330{
331 return tas_read_register(&self->super,
332 (uint)reg_num,
333 register_width(reg_num),
334 data);
335}
336
337static inline int
338tas3004_fast_load(struct tas3004_data_t *self, int fast)
339{
340 if (fast)
341 self->super.shadow[TAS3004_REG_MCR][0] |= 0x80;
342 else
343 self->super.shadow[TAS3004_REG_MCR][0] &= 0x7f;
344 return tas3004_sync_register(self,TAS3004_REG_MCR);
345}
346
347static uint
348tas3004_supported_mixers(struct tas3004_data_t *self)
349{
350 return SOUND_MASK_VOLUME |
351 SOUND_MASK_PCM |
352 SOUND_MASK_ALTPCM |
353 SOUND_MASK_IMIX |
354 SOUND_MASK_TREBLE |
355 SOUND_MASK_BASS |
356 SOUND_MASK_MIC |
357 SOUND_MASK_LINE;
358}
359
360static int
361tas3004_mixer_is_stereo(struct tas3004_data_t *self, int mixer)
362{
363 switch(mixer) {
364 case SOUND_MIXER_VOLUME:
365 case SOUND_MIXER_PCM:
366 case SOUND_MIXER_ALTPCM:
367 case SOUND_MIXER_IMIX:
368 return 1;
369 default:
370 return 0;
371 }
372}
373
374static uint
375tas3004_stereo_mixers(struct tas3004_data_t *self)
376{
377 uint r = tas3004_supported_mixers(self);
378 uint i;
379
380 for (i=1; i<SOUND_MIXER_NRDEVICES; i++)
381 if (r&(1<<i) && !tas3004_mixer_is_stereo(self,i))
382 r &= ~(1<<i);
383 return r;
384}
385
386static int
387tas3004_get_mixer_level(struct tas3004_data_t *self, int mixer, uint *level)
388{
389 if (!self)
390 return -1;
391
392 *level = self->super.mixer[mixer];
393
394 return 0;
395}
396
397static int
398tas3004_set_mixer_level(struct tas3004_data_t *self, int mixer, uint level)
399{
400 int rc;
401 tas_shadow_t *shadow;
402 uint temp;
403 uint offset=0;
404
405 if (!self)
406 return -1;
407
408 shadow = self->super.shadow;
409
410 if (!tas3004_mixer_is_stereo(self,mixer))
411 level = tas_mono_to_stereo(level);
412 switch(mixer) {
413 case SOUND_MIXER_VOLUME:
414 temp = tas3004_gain.master[level&0xff];
415 SET_4_20(shadow[TAS3004_REG_VOLUME], 0, temp);
416 temp = tas3004_gain.master[(level>>8)&0xff];
417 SET_4_20(shadow[TAS3004_REG_VOLUME], 3, temp);
418 rc = tas3004_sync_register(self,TAS3004_REG_VOLUME);
419 break;
420 case SOUND_MIXER_IMIX:
421 offset += 3;
422 case SOUND_MIXER_ALTPCM:
423 offset += 3;
424 case SOUND_MIXER_PCM:
425 /*
426 * Don't load these in fast mode. The documentation
427 * says it can be done in either mode, but testing it
428 * shows that fast mode produces ugly clicking.
429 */
430 /* tas3004_fast_load(self,1); */
431 temp = tas3004_gain.mixer[level&0xff];
432 SET_4_20(shadow[TAS3004_REG_LEFT_MIXER], offset, temp);
433 temp = tas3004_gain.mixer[(level>>8)&0xff];
434 SET_4_20(shadow[TAS3004_REG_RIGHT_MIXER], offset, temp);
435 rc = tas3004_sync_register(self,TAS3004_REG_LEFT_MIXER);
436 if (rc == 0)
437 rc=tas3004_sync_register(self,TAS3004_REG_RIGHT_MIXER);
438 /* tas3004_fast_load(self,0); */
439 break;
440 case SOUND_MIXER_TREBLE:
441 temp = tas3004_gain.treble[level&0xff];
442 shadow[TAS3004_REG_TREBLE][0]=temp&0xff;
443 rc = tas3004_sync_register(self,TAS3004_REG_TREBLE);
444 break;
445 case SOUND_MIXER_BASS:
446 temp = tas3004_gain.bass[level&0xff];
447 shadow[TAS3004_REG_BASS][0]=temp&0xff;
448 rc = tas3004_sync_register(self,TAS3004_REG_BASS);
449 break;
450 case SOUND_MIXER_MIC:
451 if ((level&0xff)>0) {
452 software_input_volume = SW_INPUT_VOLUME_SCALE * (level&0xff);
453 if (self->super.mixer[mixer] == 0) {
454 self->super.mixer[SOUND_MIXER_LINE] = 0;
455 shadow[TAS3004_REG_ANALOG_CTRL][0]=0xc2;
456 rc = tas3004_sync_register(self,TAS3004_REG_ANALOG_CTRL);
457 } else rc=0;
458 } else {
459 self->super.mixer[SOUND_MIXER_LINE] = SW_INPUT_VOLUME_DEFAULT;
460 software_input_volume = SW_INPUT_VOLUME_SCALE *
461 (self->super.mixer[SOUND_MIXER_LINE]&0xff);
462 shadow[TAS3004_REG_ANALOG_CTRL][0]=0x00;
463 rc = tas3004_sync_register(self,TAS3004_REG_ANALOG_CTRL);
464 }
465 break;
466 case SOUND_MIXER_LINE:
467 if (self->super.mixer[SOUND_MIXER_MIC] == 0) {
468 software_input_volume = SW_INPUT_VOLUME_SCALE * (level&0xff);
469 rc=0;
470 }
471 break;
472 default:
473 rc = -1;
474 break;
475 }
476 if (rc < 0)
477 return rc;
478 self->super.mixer[mixer] = level;
479
480 return 0;
481}
482
483static int
484tas3004_leave_sleep(struct tas3004_data_t *self)
485{
486 unsigned char mcr = (1<<6)+(2<<4)+(2<<2);
487
488 if (!self)
489 return -1;
490
491 /* Make sure something answers on the i2c bus */
492 if (tas3004_write_register(self, TAS3004_REG_MCR, &mcr,
493 WRITE_NORMAL | FORCE_WRITE) < 0)
494 return -1;
495
496 tas3004_fast_load(self, 1);
497
498 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD0);
499 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD1);
500 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD2);
501 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD3);
502 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD4);
503 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD5);
504 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD6);
505
506 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD0);
507 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD1);
508 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD2);
509 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD3);
510 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD4);
511 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD5);
512 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD6);
513
514 tas3004_fast_load(self, 0);
515
516 (void)tas3004_sync_register(self,TAS3004_REG_VOLUME);
517 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_MIXER);
518 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_MIXER);
519 (void)tas3004_sync_register(self,TAS3004_REG_TREBLE);
520 (void)tas3004_sync_register(self,TAS3004_REG_BASS);
521 (void)tas3004_sync_register(self,TAS3004_REG_ANALOG_CTRL);
522
523 return 0;
524}
525
526static int
527tas3004_enter_sleep(struct tas3004_data_t *self)
528{
529 if (!self)
530 return -1;
531 return 0;
532}
533
534static int
535tas3004_sync_biquad( struct tas3004_data_t *self,
536 u_int channel,
537 u_int filter)
538{
539 enum tas3004_reg_t reg;
540
541 if (channel >= TAS3004_BIQUAD_CHANNEL_COUNT ||
542 filter >= TAS3004_BIQUAD_FILTER_COUNT) return -EINVAL;
543
544 reg=( channel ? TAS3004_REG_RIGHT_BIQUAD0 : TAS3004_REG_LEFT_BIQUAD0 ) + filter;
545
546 return tas3004_sync_register(self,reg);
547}
548
549static int
550tas3004_write_biquad_shadow( struct tas3004_data_t *self,
551 u_int channel,
552 u_int filter,
553 const union tas_biquad_t *biquad)
554{
555 tas_shadow_t *shadow=self->super.shadow;
556 enum tas3004_reg_t reg;
557
558 if (channel >= TAS3004_BIQUAD_CHANNEL_COUNT ||
559 filter >= TAS3004_BIQUAD_FILTER_COUNT) return -EINVAL;
560
561 reg=( channel ? TAS3004_REG_RIGHT_BIQUAD0 : TAS3004_REG_LEFT_BIQUAD0 ) + filter;
562
563 SET_4_20(shadow[reg], 0,biquad->coeff.b0);
564 SET_4_20(shadow[reg], 3,biquad->coeff.b1);
565 SET_4_20(shadow[reg], 6,biquad->coeff.b2);
566 SET_4_20(shadow[reg], 9,biquad->coeff.a1);
567 SET_4_20(shadow[reg],12,biquad->coeff.a2);
568
569 return 0;
570}
571
572static int
573tas3004_write_biquad( struct tas3004_data_t *self,
574 u_int channel,
575 u_int filter,
576 const union tas_biquad_t *biquad)
577{
578 int rc;
579
580 rc=tas3004_write_biquad_shadow(self, channel, filter, biquad);
581 if (rc < 0) return rc;
582
583 return tas3004_sync_biquad(self, channel, filter);
584}
585
586static int
587tas3004_write_biquad_list( struct tas3004_data_t *self,
588 u_int filter_count,
589 u_int flags,
590 struct tas_biquad_ctrl_t *biquads)
591{
592 int i;
593 int rc;
594
595 if (flags & TAS_BIQUAD_FAST_LOAD) tas3004_fast_load(self,1);
596
597 for (i=0; i<filter_count; i++) {
598 rc=tas3004_write_biquad(self,
599 biquads[i].channel,
600 biquads[i].filter,
601 &biquads[i].data);
602 if (rc < 0) break;
603 }
604
605 if (flags & TAS_BIQUAD_FAST_LOAD) tas3004_fast_load(self,0);
606
607 return rc;
608}
609
610static int
611tas3004_read_biquad( struct tas3004_data_t *self,
612 u_int channel,
613 u_int filter,
614 union tas_biquad_t *biquad)
615{
616 tas_shadow_t *shadow=self->super.shadow;
617 enum tas3004_reg_t reg;
618
619 if (channel >= TAS3004_BIQUAD_CHANNEL_COUNT ||
620 filter >= TAS3004_BIQUAD_FILTER_COUNT) return -EINVAL;
621
622 reg=( channel ? TAS3004_REG_RIGHT_BIQUAD0 : TAS3004_REG_LEFT_BIQUAD0 ) + filter;
623
624 biquad->coeff.b0=GET_4_20(shadow[reg], 0);
625 biquad->coeff.b1=GET_4_20(shadow[reg], 3);
626 biquad->coeff.b2=GET_4_20(shadow[reg], 6);
627 biquad->coeff.a1=GET_4_20(shadow[reg], 9);
628 biquad->coeff.a2=GET_4_20(shadow[reg],12);
629
630 return 0;
631}
632
633static int
634tas3004_eq_rw( struct tas3004_data_t *self,
635 u_int cmd,
636 u_long arg)
637{
638 void __user *argp = (void __user *)arg;
639 int rc;
640 struct tas_biquad_ctrl_t biquad;
641
642 if (copy_from_user((void *)&biquad, argp, sizeof(struct tas_biquad_ctrl_t))) {
643 return -EFAULT;
644 }
645
646 if (cmd & SIOC_IN) {
647 rc=tas3004_write_biquad(self, biquad.channel, biquad.filter, &biquad.data);
648 if (rc != 0) return rc;
649 }
650
651 if (cmd & SIOC_OUT) {
652 rc=tas3004_read_biquad(self, biquad.channel, biquad.filter, &biquad.data);
653 if (rc != 0) return rc;
654
655 if (copy_to_user(argp, &biquad, sizeof(struct tas_biquad_ctrl_t))) {
656 return -EFAULT;
657 }
658
659 }
660 return 0;
661}
662
663static int
664tas3004_eq_list_rw( struct tas3004_data_t *self,
665 u_int cmd,
666 u_long arg)
667{
668 int rc = 0;
669 int filter_count;
670 int flags;
671 int i,j;
672 char sync_required[TAS3004_BIQUAD_CHANNEL_COUNT][TAS3004_BIQUAD_FILTER_COUNT];
673 struct tas_biquad_ctrl_t biquad;
674 struct tas_biquad_ctrl_list_t __user *argp = (void __user *)arg;
675
676 memset(sync_required,0,sizeof(sync_required));
677
678 if (copy_from_user(&filter_count, &argp->filter_count, sizeof(int)))
679 return -EFAULT;
680
681 if (copy_from_user(&flags, &argp->flags, sizeof(int)))
682 return -EFAULT;
683
684 if (cmd & SIOC_IN) {
685 }
686
687 for (i=0; i < filter_count; i++) {
688 if (copy_from_user(&biquad, &argp->biquads[i],
689 sizeof(struct tas_biquad_ctrl_t))) {
690 return -EFAULT;
691 }
692
693 if (cmd & SIOC_IN) {
694 sync_required[biquad.channel][biquad.filter]=1;
695 rc=tas3004_write_biquad_shadow(self, biquad.channel, biquad.filter, &biquad.data);
696 if (rc != 0) return rc;
697 }
698
699 if (cmd & SIOC_OUT) {
700 rc=tas3004_read_biquad(self, biquad.channel, biquad.filter, &biquad.data);
701 if (rc != 0) return rc;
702
703 if (copy_to_user(&argp->biquads[i], &biquad,
704 sizeof(struct tas_biquad_ctrl_t))) {
705 return -EFAULT;
706 }
707 }
708 }
709
710 if (cmd & SIOC_IN) {
711 /*
712 * This is OK for the tas3004. For the
713 * tas3001c, going into fast load mode causes
714 * the treble and bass to be reset to 0dB, and
715 * volume controls to be muted.
716 */
717 if (flags & TAS_BIQUAD_FAST_LOAD) tas3004_fast_load(self,1);
718 for (i=0; i<TAS3004_BIQUAD_CHANNEL_COUNT; i++) {
719 for (j=0; j<TAS3004_BIQUAD_FILTER_COUNT; j++) {
720 if (sync_required[i][j]) {
721 rc=tas3004_sync_biquad(self, i, j);
722 if (rc < 0) goto out;
723 }
724 }
725 }
726 out:
727 if (flags & TAS_BIQUAD_FAST_LOAD)
728 tas3004_fast_load(self,0);
729 }
730
731 return rc;
732}
733
734static int
735tas3004_update_drce( struct tas3004_data_t *self,
736 int flags,
737 struct tas_drce_t *drce)
738{
739 tas_shadow_t *shadow;
740 int i;
741 shadow=self->super.shadow;
742
743 if (flags & TAS_DRCE_ABOVE_RATIO) {
744 self->drce_state.above.expand = drce->above.expand;
745 if (drce->above.val == (1<<8)) {
746 self->drce_state.above.val = 1<<8;
747 shadow[TAS3004_REG_DRC][0] = 0x02;
748
749 } else if (drce->above.expand) {
750 i=above_threshold_expansion_index(drce->above.val);
751 self->drce_state.above.val=above_threshold_expansion_ratio[i];
752 shadow[TAS3004_REG_DRC][0] = 0x0a + (i<<3);
753 } else {
754 i=above_threshold_compression_index(drce->above.val);
755 self->drce_state.above.val=above_threshold_compression_ratio[i];
756 shadow[TAS3004_REG_DRC][0] = 0x08 + (i<<3);
757 }
758 }
759
760 if (flags & TAS_DRCE_BELOW_RATIO) {
761 self->drce_state.below.expand = drce->below.expand;
762 if (drce->below.val == (1<<8)) {
763 self->drce_state.below.val = 1<<8;
764 shadow[TAS3004_REG_DRC][1] = 0x02;
765
766 } else if (drce->below.expand) {
767 i=below_threshold_expansion_index(drce->below.val);
768 self->drce_state.below.val=below_threshold_expansion_ratio[i];
769 shadow[TAS3004_REG_DRC][1] = 0x08 + (i<<3);
770 } else {
771 i=below_threshold_compression_index(drce->below.val);
772 self->drce_state.below.val=below_threshold_compression_ratio[i];
773 shadow[TAS3004_REG_DRC][1] = 0x0a + (i<<3);
774 }
775 }
776
777 if (flags & TAS_DRCE_THRESHOLD) {
778 self->drce_state.threshold=quantize_db(drce->threshold);
779 shadow[TAS3004_REG_DRC][2] = db_to_regval(self->drce_state.threshold);
780 }
781
782 if (flags & TAS_DRCE_ENERGY) {
783 i=time_index(drce->energy);
784 self->drce_state.energy=time_constants[i];
785 shadow[TAS3004_REG_DRC][3] = 0x40 + (i<<4);
786 }
787
788 if (flags & TAS_DRCE_ATTACK) {
789 i=time_index(drce->attack);
790 self->drce_state.attack=time_constants[i];
791 shadow[TAS3004_REG_DRC][4] = 0x40 + (i<<4);
792 }
793
794 if (flags & TAS_DRCE_DECAY) {
795 i=time_index(drce->decay);
796 self->drce_state.decay=time_constants[i];
797 shadow[TAS3004_REG_DRC][5] = 0x40 + (i<<4);
798 }
799
800 if (flags & TAS_DRCE_ENABLE) {
801 self->drce_state.enable = drce->enable;
802 }
803
804 if (!self->drce_state.enable) {
805 shadow[TAS3004_REG_DRC][0] |= 0x01;
806 }
807
808#ifdef DEBUG_DRCE
809 printk("DRCE: set [ ENABLE:%x ABOVE:%x/%x BELOW:%x/%x THRESH:%x ENERGY:%x ATTACK:%x DECAY:%x\n",
810 self->drce_state.enable,
811 self->drce_state.above.expand,self->drce_state.above.val,
812 self->drce_state.below.expand,self->drce_state.below.val,
813 self->drce_state.threshold,
814 self->drce_state.energy,
815 self->drce_state.attack,
816 self->drce_state.decay);
817
818 printk("DRCE: reg [ %02x %02x %02x %02x %02x %02x ]\n",
819 (unsigned char)shadow[TAS3004_REG_DRC][0],
820 (unsigned char)shadow[TAS3004_REG_DRC][1],
821 (unsigned char)shadow[TAS3004_REG_DRC][2],
822 (unsigned char)shadow[TAS3004_REG_DRC][3],
823 (unsigned char)shadow[TAS3004_REG_DRC][4],
824 (unsigned char)shadow[TAS3004_REG_DRC][5]);
825#endif
826
827 return tas3004_sync_register(self, TAS3004_REG_DRC);
828}
829
830static int
831tas3004_drce_rw( struct tas3004_data_t *self,
832 u_int cmd,
833 u_long arg)
834{
835 int rc;
836 struct tas_drce_ctrl_t drce_ctrl;
837 void __user *argp = (void __user *)arg;
838
839 if (copy_from_user(&drce_ctrl, argp, sizeof(struct tas_drce_ctrl_t)))
840 return -EFAULT;
841
842#ifdef DEBUG_DRCE
843 printk("DRCE: input [ FLAGS:%x ENABLE:%x ABOVE:%x/%x BELOW:%x/%x THRESH:%x ENERGY:%x ATTACK:%x DECAY:%x\n",
844 drce_ctrl.flags,
845 drce_ctrl.data.enable,
846 drce_ctrl.data.above.expand,drce_ctrl.data.above.val,
847 drce_ctrl.data.below.expand,drce_ctrl.data.below.val,
848 drce_ctrl.data.threshold,
849 drce_ctrl.data.energy,
850 drce_ctrl.data.attack,
851 drce_ctrl.data.decay);
852#endif
853
854 if (cmd & SIOC_IN) {
855 rc = tas3004_update_drce(self, drce_ctrl.flags, &drce_ctrl.data);
856 if (rc < 0) return rc;
857 }
858
859 if (cmd & SIOC_OUT) {
860 if (drce_ctrl.flags & TAS_DRCE_ENABLE)
861 drce_ctrl.data.enable = self->drce_state.enable;
862 if (drce_ctrl.flags & TAS_DRCE_ABOVE_RATIO)
863 drce_ctrl.data.above = self->drce_state.above;
864 if (drce_ctrl.flags & TAS_DRCE_BELOW_RATIO)
865 drce_ctrl.data.below = self->drce_state.below;
866 if (drce_ctrl.flags & TAS_DRCE_THRESHOLD)
867 drce_ctrl.data.threshold = self->drce_state.threshold;
868 if (drce_ctrl.flags & TAS_DRCE_ENERGY)
869 drce_ctrl.data.energy = self->drce_state.energy;
870 if (drce_ctrl.flags & TAS_DRCE_ATTACK)
871 drce_ctrl.data.attack = self->drce_state.attack;
872 if (drce_ctrl.flags & TAS_DRCE_DECAY)
873 drce_ctrl.data.decay = self->drce_state.decay;
874
875 if (copy_to_user(argp, &drce_ctrl,
876 sizeof(struct tas_drce_ctrl_t))) {
877 return -EFAULT;
878 }
879 }
880
881 return 0;
882}
883
884static void
885tas3004_update_device_parameters(struct tas3004_data_t *self)
886{
887 char data;
888 int i;
889
890 if (!self) return;
891
892 if (self->output_id == TAS_OUTPUT_HEADPHONES) {
893 /* turn on allPass when headphones are plugged in */
894 data = 0x02;
895 } else {
896 data = 0x00;
897 }
898
899 tas3004_write_register(self, TAS3004_REG_MCR2, &data, WRITE_NORMAL | FORCE_WRITE);
900
901 for (i=0; tas3004_eq_prefs[i]; i++) {
902 struct tas_eq_pref_t *eq = tas3004_eq_prefs[i];
903
904 if (eq->device_id == self->device_id &&
905 (eq->output_id == 0 || eq->output_id == self->output_id) &&
906 (eq->speaker_id == 0 || eq->speaker_id == self->speaker_id)) {
907
908 tas3004_update_drce(self, TAS_DRCE_ALL, eq->drce);
909 tas3004_write_biquad_list(self, eq->filter_count, TAS_BIQUAD_FAST_LOAD, eq->biquads);
910
911 break;
912 }
913 }
914}
915
916static void
917tas3004_device_change_handler(void *self)
918{
919 if (!self) return;
920
921 tas3004_update_device_parameters((struct tas3004_data_t *)self);
922}
923
924static struct work_struct device_change;
925
926static int
927tas3004_output_device_change( struct tas3004_data_t *self,
928 int device_id,
929 int output_id,
930 int speaker_id)
931{
932 self->device_id=device_id;
933 self->output_id=output_id;
934 self->speaker_id=speaker_id;
935
936 schedule_work(&device_change);
937
938 return 0;
939}
940
941static int
942tas3004_device_ioctl( struct tas3004_data_t *self,
943 u_int cmd,
944 u_long arg)
945{
946 uint __user *argp = (void __user *)arg;
947 switch (cmd) {
948 case TAS_READ_EQ:
949 case TAS_WRITE_EQ:
950 return tas3004_eq_rw(self, cmd, arg);
951
952 case TAS_READ_EQ_LIST:
953 case TAS_WRITE_EQ_LIST:
954 return tas3004_eq_list_rw(self, cmd, arg);
955
956 case TAS_READ_EQ_FILTER_COUNT:
957 put_user(TAS3004_BIQUAD_FILTER_COUNT, argp);
958 return 0;
959
960 case TAS_READ_EQ_CHANNEL_COUNT:
961 put_user(TAS3004_BIQUAD_CHANNEL_COUNT, argp);
962 return 0;
963
964 case TAS_READ_DRCE:
965 case TAS_WRITE_DRCE:
966 return tas3004_drce_rw(self, cmd, arg);
967
968 case TAS_READ_DRCE_CAPS:
969 put_user(TAS_DRCE_ENABLE |
970 TAS_DRCE_ABOVE_RATIO |
971 TAS_DRCE_BELOW_RATIO |
972 TAS_DRCE_THRESHOLD |
973 TAS_DRCE_ENERGY |
974 TAS_DRCE_ATTACK |
975 TAS_DRCE_DECAY,
976 argp);
977 return 0;
978
979 case TAS_READ_DRCE_MIN:
980 case TAS_READ_DRCE_MAX: {
981 struct tas_drce_ctrl_t drce_ctrl;
982 const struct tas_drce_t *drce_copy;
983
984 if (copy_from_user(&drce_ctrl, argp,
985 sizeof(struct tas_drce_ctrl_t))) {
986 return -EFAULT;
987 }
988
989 if (cmd == TAS_READ_DRCE_MIN) {
990 drce_copy=&tas3004_drce_min;
991 } else {
992 drce_copy=&tas3004_drce_max;
993 }
994
995 if (drce_ctrl.flags & TAS_DRCE_ABOVE_RATIO) {
996 drce_ctrl.data.above=drce_copy->above;
997 }
998 if (drce_ctrl.flags & TAS_DRCE_BELOW_RATIO) {
999 drce_ctrl.data.below=drce_copy->below;
1000 }
1001 if (drce_ctrl.flags & TAS_DRCE_THRESHOLD) {
1002 drce_ctrl.data.threshold=drce_copy->threshold;
1003 }
1004 if (drce_ctrl.flags & TAS_DRCE_ENERGY) {
1005 drce_ctrl.data.energy=drce_copy->energy;
1006 }
1007 if (drce_ctrl.flags & TAS_DRCE_ATTACK) {
1008 drce_ctrl.data.attack=drce_copy->attack;
1009 }
1010 if (drce_ctrl.flags & TAS_DRCE_DECAY) {
1011 drce_ctrl.data.decay=drce_copy->decay;
1012 }
1013
1014 if (copy_to_user(argp, &drce_ctrl,
1015 sizeof(struct tas_drce_ctrl_t))) {
1016 return -EFAULT;
1017 }
1018 }
1019 }
1020
1021 return -EINVAL;
1022}
1023
1024static int
1025tas3004_init_mixer(struct tas3004_data_t *self)
1026{
1027 unsigned char mcr = (1<<6)+(2<<4)+(2<<2);
1028
1029 /* Make sure something answers on the i2c bus */
1030 if (tas3004_write_register(self, TAS3004_REG_MCR, &mcr,
1031 WRITE_NORMAL | FORCE_WRITE) < 0)
1032 return -1;
1033
1034 tas3004_fast_load(self, 1);
1035
1036 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD0);
1037 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD1);
1038 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD2);
1039 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD3);
1040 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD4);
1041 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD5);
1042 (void)tas3004_sync_register(self,TAS3004_REG_RIGHT_BIQUAD6);
1043
1044 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD0);
1045 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD1);
1046 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD2);
1047 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD3);
1048 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD4);
1049 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD5);
1050 (void)tas3004_sync_register(self,TAS3004_REG_LEFT_BIQUAD6);
1051
1052 tas3004_sync_register(self, TAS3004_REG_DRC);
1053
1054 tas3004_sync_register(self, TAS3004_REG_MCR2);
1055
1056 tas3004_fast_load(self, 0);
1057
1058 tas3004_set_mixer_level(self, SOUND_MIXER_VOLUME, VOL_DEFAULT<<8 | VOL_DEFAULT);
1059 tas3004_set_mixer_level(self, SOUND_MIXER_PCM, INPUT_DEFAULT<<8 | INPUT_DEFAULT);
1060 tas3004_set_mixer_level(self, SOUND_MIXER_ALTPCM, 0);
1061 tas3004_set_mixer_level(self, SOUND_MIXER_IMIX, 0);
1062
1063 tas3004_set_mixer_level(self, SOUND_MIXER_BASS, BASS_DEFAULT);
1064 tas3004_set_mixer_level(self, SOUND_MIXER_TREBLE, TREBLE_DEFAULT);
1065
1066 tas3004_set_mixer_level(self, SOUND_MIXER_LINE,SW_INPUT_VOLUME_DEFAULT);
1067
1068 return 0;
1069}
1070
1071static int
1072tas3004_uninit_mixer(struct tas3004_data_t *self)
1073{
1074 tas3004_set_mixer_level(self, SOUND_MIXER_VOLUME, 0);
1075 tas3004_set_mixer_level(self, SOUND_MIXER_PCM, 0);
1076 tas3004_set_mixer_level(self, SOUND_MIXER_ALTPCM, 0);
1077 tas3004_set_mixer_level(self, SOUND_MIXER_IMIX, 0);
1078
1079 tas3004_set_mixer_level(self, SOUND_MIXER_BASS, 0);
1080 tas3004_set_mixer_level(self, SOUND_MIXER_TREBLE, 0);
1081
1082 tas3004_set_mixer_level(self, SOUND_MIXER_LINE, 0);
1083
1084 return 0;
1085}
1086
1087static int
1088tas3004_init(struct i2c_client *client)
1089{
1090 struct tas3004_data_t *self;
1091 size_t sz = sizeof(*self) + (TAS3004_REG_MAX*sizeof(tas_shadow_t));
1092 char drce_init[] = { 0x69, 0x22, 0x9f, 0xb0, 0x60, 0xa0 };
1093 char mcr2 = 0;
1094 int i, j;
1095
1096 self = kmalloc(sz, GFP_KERNEL);
1097 if (!self)
1098 return -ENOMEM;
1099 memset(self, 0, sz);
1100
1101 self->super.client = client;
1102 self->super.shadow = (tas_shadow_t *)(self+1);
1103 self->output_id = TAS_OUTPUT_HEADPHONES;
1104
1105 dev_set_drvdata(&client->dev, self);
1106
1107 for (i = 0; i < TAS3004_BIQUAD_CHANNEL_COUNT; i++)
1108 for (j = 0; j<TAS3004_BIQUAD_FILTER_COUNT; j++)
1109 tas3004_write_biquad_shadow(self, i, j,
1110 &tas3004_eq_unity);
1111
1112 tas3004_write_register(self, TAS3004_REG_MCR2, &mcr2, WRITE_SHADOW);
1113 tas3004_write_register(self, TAS3004_REG_DRC, drce_init, WRITE_SHADOW);
1114
1115 INIT_WORK(&device_change, tas3004_device_change_handler, self);
1116 return 0;
1117}
1118
1119static void
1120tas3004_uninit(struct tas3004_data_t *self)
1121{
1122 tas3004_uninit_mixer(self);
1123 kfree(self);
1124}
1125
1126
1127struct tas_driver_hooks_t tas3004_hooks = {
1128 .init = (tas_hook_init_t)tas3004_init,
1129 .post_init = (tas_hook_post_init_t)tas3004_init_mixer,
1130 .uninit = (tas_hook_uninit_t)tas3004_uninit,
1131 .get_mixer_level = (tas_hook_get_mixer_level_t)tas3004_get_mixer_level,
1132 .set_mixer_level = (tas_hook_set_mixer_level_t)tas3004_set_mixer_level,
1133 .enter_sleep = (tas_hook_enter_sleep_t)tas3004_enter_sleep,
1134 .leave_sleep = (tas_hook_leave_sleep_t)tas3004_leave_sleep,
1135 .supported_mixers = (tas_hook_supported_mixers_t)tas3004_supported_mixers,
1136 .mixer_is_stereo = (tas_hook_mixer_is_stereo_t)tas3004_mixer_is_stereo,
1137 .stereo_mixers = (tas_hook_stereo_mixers_t)tas3004_stereo_mixers,
1138 .output_device_change = (tas_hook_output_device_change_t)tas3004_output_device_change,
1139 .device_ioctl = (tas_hook_device_ioctl_t)tas3004_device_ioctl
1140};
diff --git a/sound/oss/dmasound/tas3004.h b/sound/oss/dmasound/tas3004.h
new file mode 100644
index 000000000000..c6d584bf2ca4
--- /dev/null
+++ b/sound/oss/dmasound/tas3004.h
@@ -0,0 +1,77 @@
1/*
2 * Header file for the i2c/i2s based TA3004 sound chip used
3 * on some Apple hardware. Also known as "tumbler".
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive
7 * for more details.
8 *
9 * Written by Christopher C. Chimelis <chris@debian.org>
10 */
11
12#ifndef _TAS3004_H_
13#define _TAS3004_H_
14
15#include <linux/types.h>
16
17#include "tas_common.h"
18#include "tas_eq_prefs.h"
19
20/*
21 * Macros that correspond to the registers that we write to
22 * when setting the various values.
23 */
24
25#define TAS3004_VERSION "0.3"
26#define TAS3004_DATE "20011214"
27
28#define I2C_DRIVERNAME_TAS3004 "TAS3004 driver V " TAS3004_VERSION
29#define I2C_DRIVERID_TAS3004 (I2C_DRIVERID_TAS_BASE+1)
30
31extern struct tas_driver_hooks_t tas3004_hooks;
32extern struct tas_gain_t tas3004_gain;
33extern struct tas_eq_pref_t *tas3004_eq_prefs[];
34
35enum tas3004_reg_t {
36 TAS3004_REG_MCR = 0x01,
37 TAS3004_REG_DRC = 0x02,
38
39 TAS3004_REG_VOLUME = 0x04,
40 TAS3004_REG_TREBLE = 0x05,
41 TAS3004_REG_BASS = 0x06,
42 TAS3004_REG_LEFT_MIXER = 0x07,
43 TAS3004_REG_RIGHT_MIXER = 0x08,
44
45 TAS3004_REG_LEFT_BIQUAD0 = 0x0a,
46 TAS3004_REG_LEFT_BIQUAD1 = 0x0b,
47 TAS3004_REG_LEFT_BIQUAD2 = 0x0c,
48 TAS3004_REG_LEFT_BIQUAD3 = 0x0d,
49 TAS3004_REG_LEFT_BIQUAD4 = 0x0e,
50 TAS3004_REG_LEFT_BIQUAD5 = 0x0f,
51 TAS3004_REG_LEFT_BIQUAD6 = 0x10,
52
53 TAS3004_REG_RIGHT_BIQUAD0 = 0x13,
54 TAS3004_REG_RIGHT_BIQUAD1 = 0x14,
55 TAS3004_REG_RIGHT_BIQUAD2 = 0x15,
56 TAS3004_REG_RIGHT_BIQUAD3 = 0x16,
57 TAS3004_REG_RIGHT_BIQUAD4 = 0x17,
58 TAS3004_REG_RIGHT_BIQUAD5 = 0x18,
59 TAS3004_REG_RIGHT_BIQUAD6 = 0x19,
60
61 TAS3004_REG_LEFT_LOUD_BIQUAD = 0x21,
62 TAS3004_REG_RIGHT_LOUD_BIQUAD = 0x22,
63
64 TAS3004_REG_LEFT_LOUD_BIQUAD_GAIN = 0x23,
65 TAS3004_REG_RIGHT_LOUD_BIQUAD_GAIN = 0x24,
66
67 TAS3004_REG_TEST = 0x29,
68
69 TAS3004_REG_ANALOG_CTRL = 0x40,
70 TAS3004_REG_TEST1 = 0x41,
71 TAS3004_REG_TEST2 = 0x42,
72 TAS3004_REG_MCR2 = 0x43,
73
74 TAS3004_REG_MAX = 0x44
75};
76
77#endif /* _TAS3004_H_ */
diff --git a/sound/oss/dmasound/tas3004_tables.c b/sound/oss/dmasound/tas3004_tables.c
new file mode 100644
index 000000000000..b910e0a66775
--- /dev/null
+++ b/sound/oss/dmasound/tas3004_tables.c
@@ -0,0 +1,301 @@
1#include "tas3004.h"
2#include "tas_eq_prefs.h"
3
4static struct tas_drce_t eqp_17_1_0_drce={
5 .enable = 1,
6 .above = { .val = 3.0 * (1<<8), .expand = 0 },
7 .below = { .val = 1.0 * (1<<8), .expand = 0 },
8 .threshold = -19.12 * (1<<8),
9 .energy = 2.4 * (1<<12),
10 .attack = 0.013 * (1<<12),
11 .decay = 0.212 * (1<<12),
12};
13
14static struct tas_biquad_ctrl_t eqp_17_1_0_biquads[]={
15 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0fd0d4, 0xe05e56, 0x0fd0d4, 0xe05ee1, 0x0fa234 } } },
16 { .channel = 0, .filter = 1, .data = { .coeff = { 0x0910d7, 0x088e1a, 0x030651, 0x01dcb1, 0x02c892 } } },
17 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0ff895, 0xe0970b, 0x0f7f00, 0xe0970b, 0x0f7795 } } },
18 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0fd1c4, 0xe1ac22, 0x0ec8cf, 0xe1ac22, 0x0e9a94 } } },
19 { .channel = 0, .filter = 4, .data = { .coeff = { 0x0f7c1c, 0xe3cc03, 0x0df786, 0xe3cc03, 0x0d73a2 } } },
20 { .channel = 0, .filter = 5, .data = { .coeff = { 0x11fb92, 0xf5a1a0, 0x073cd2, 0xf5a1a0, 0x093865 } } },
21 { .channel = 0, .filter = 6, .data = { .coeff = { 0x0e17a9, 0x068b6c, 0x08a0e5, 0x068b6c, 0x06b88e } } },
22
23 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0fd0d4, 0xe05e56, 0x0fd0d4, 0xe05ee1, 0x0fa234 } } },
24 { .channel = 1, .filter = 1, .data = { .coeff = { 0x0910d7, 0x088e1a, 0x030651, 0x01dcb1, 0x02c892 } } },
25 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0ff895, 0xe0970b, 0x0f7f00, 0xe0970b, 0x0f7795 } } },
26 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0fd1c4, 0xe1ac22, 0x0ec8cf, 0xe1ac22, 0x0e9a94 } } },
27 { .channel = 1, .filter = 4, .data = { .coeff = { 0x0f7c1c, 0xe3cc03, 0x0df786, 0xe3cc03, 0x0d73a2 } } },
28 { .channel = 1, .filter = 5, .data = { .coeff = { 0x11fb92, 0xf5a1a0, 0x073cd2, 0xf5a1a0, 0x093865 } } },
29 { .channel = 1, .filter = 6, .data = { .coeff = { 0x0e17a9, 0x068b6c, 0x08a0e5, 0x068b6c, 0x06b88e } } }
30};
31
32static struct tas_eq_pref_t eqp_17_1_0 = {
33 .sample_rate = 44100,
34 .device_id = 0x17,
35 .output_id = TAS_OUTPUT_INTERNAL_SPKR,
36 .speaker_id = 0x00,
37
38 .drce = &eqp_17_1_0_drce,
39
40 .filter_count = 14,
41 .biquads = eqp_17_1_0_biquads
42};
43
44/* ======================================================================== */
45
46static struct tas_drce_t eqp_18_1_0_drce={
47 .enable = 1,
48 .above = { .val = 3.0 * (1<<8), .expand = 0 },
49 .below = { .val = 1.0 * (1<<8), .expand = 0 },
50 .threshold = -13.14 * (1<<8),
51 .energy = 2.4 * (1<<12),
52 .attack = 0.013 * (1<<12),
53 .decay = 0.212 * (1<<12),
54};
55
56static struct tas_biquad_ctrl_t eqp_18_1_0_biquads[]={
57 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0f5514, 0xe155d7, 0x0f5514, 0xe15cfa, 0x0eb14b } } },
58 { .channel = 0, .filter = 1, .data = { .coeff = { 0x06ec33, 0x02abe3, 0x015eef, 0xf764d9, 0x03922d } } },
59 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0ef5f2, 0xe67d1f, 0x0bcf37, 0xe67d1f, 0x0ac529 } } },
60 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0db050, 0xe5be4d, 0x0d0c78, 0xe5be4d, 0x0abcc8 } } },
61 { .channel = 0, .filter = 4, .data = { .coeff = { 0x0f1298, 0xe64ec6, 0x0cc03e, 0xe64ec6, 0x0bd2d7 } } },
62 { .channel = 0, .filter = 5, .data = { .coeff = { 0x0c641a, 0x06537a, 0x08d155, 0x06537a, 0x053570 } } },
63 { .channel = 0, .filter = 6, .data = { .coeff = { 0x100000, 0x000000, 0x000000, 0x000000, 0x000000 } } },
64
65 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0f5514, 0xe155d7, 0x0f5514, 0xe15cfa, 0x0eb14b } } },
66 { .channel = 1, .filter = 1, .data = { .coeff = { 0x06ec33, 0x02abe3, 0x015eef, 0xf764d9, 0x03922d } } },
67 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0ef5f2, 0xe67d1f, 0x0bcf37, 0xe67d1f, 0x0ac529 } } },
68 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0db050, 0xe5be4d, 0x0d0c78, 0xe5be4d, 0x0abcc8 } } },
69 { .channel = 1, .filter = 4, .data = { .coeff = { 0x0f1298, 0xe64ec6, 0x0cc03e, 0xe64ec6, 0x0bd2d7 } } },
70 { .channel = 1, .filter = 5, .data = { .coeff = { 0x0c641a, 0x06537a, 0x08d155, 0x06537a, 0x053570 } } },
71 { .channel = 1, .filter = 6, .data = { .coeff = { 0x100000, 0x000000, 0x000000, 0x000000, 0x000000 } } }
72};
73
74static struct tas_eq_pref_t eqp_18_1_0 = {
75 .sample_rate = 44100,
76 .device_id = 0x18,
77 .output_id = TAS_OUTPUT_INTERNAL_SPKR,
78 .speaker_id = 0x00,
79
80 .drce = &eqp_18_1_0_drce,
81
82 .filter_count = 14,
83 .biquads = eqp_18_1_0_biquads
84};
85
86/* ======================================================================== */
87
88static struct tas_drce_t eqp_1a_1_0_drce={
89 .enable = 1,
90 .above = { .val = 3.0 * (1<<8), .expand = 0 },
91 .below = { .val = 1.0 * (1<<8), .expand = 0 },
92 .threshold = -10.75 * (1<<8),
93 .energy = 2.4 * (1<<12),
94 .attack = 0.013 * (1<<12),
95 .decay = 0.212 * (1<<12),
96};
97
98static struct tas_biquad_ctrl_t eqp_1a_1_0_biquads[]={
99 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0fb8fd, 0xe08e04, 0x0fb8fd, 0xe08f40, 0x0f7336 } } },
100 { .channel = 0, .filter = 1, .data = { .coeff = { 0x06371d, 0x0c6e3a, 0x06371d, 0x05bfd3, 0x031ca2 } } },
101 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0fa1c0, 0xe18692, 0x0f030e, 0xe18692, 0x0ea4ce } } },
102 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0fe495, 0xe17eff, 0x0f0452, 0xe17eff, 0x0ee8e7 } } },
103 { .channel = 0, .filter = 4, .data = { .coeff = { 0x100857, 0xe7e71c, 0x0e9599, 0xe7e71c, 0x0e9df1 } } },
104 { .channel = 0, .filter = 5, .data = { .coeff = { 0x0fb26e, 0x06a82c, 0x0db2b4, 0x06a82c, 0x0d6522 } } },
105 { .channel = 0, .filter = 6, .data = { .coeff = { 0x11419d, 0xf06cbf, 0x0a4f6e, 0xf06cbf, 0x0b910c } } },
106
107 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0fb8fd, 0xe08e04, 0x0fb8fd, 0xe08f40, 0x0f7336 } } },
108 { .channel = 1, .filter = 1, .data = { .coeff = { 0x06371d, 0x0c6e3a, 0x06371d, 0x05bfd3, 0x031ca2 } } },
109 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0fa1c0, 0xe18692, 0x0f030e, 0xe18692, 0x0ea4ce } } },
110 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0fe495, 0xe17eff, 0x0f0452, 0xe17eff, 0x0ee8e7 } } },
111 { .channel = 1, .filter = 4, .data = { .coeff = { 0x100857, 0xe7e71c, 0x0e9599, 0xe7e71c, 0x0e9df1 } } },
112 { .channel = 1, .filter = 5, .data = { .coeff = { 0x0fb26e, 0x06a82c, 0x0db2b4, 0x06a82c, 0x0d6522 } } },
113 { .channel = 1, .filter = 6, .data = { .coeff = { 0x11419d, 0xf06cbf, 0x0a4f6e, 0xf06cbf, 0x0b910c } } }
114};
115
116static struct tas_eq_pref_t eqp_1a_1_0 = {
117 .sample_rate = 44100,
118 .device_id = 0x1a,
119 .output_id = TAS_OUTPUT_INTERNAL_SPKR,
120 .speaker_id = 0x00,
121
122 .drce = &eqp_1a_1_0_drce,
123
124 .filter_count = 14,
125 .biquads = eqp_1a_1_0_biquads
126};
127
128/* ======================================================================== */
129
130static struct tas_drce_t eqp_1c_1_0_drce={
131 .enable = 1,
132 .above = { .val = 3.0 * (1<<8), .expand = 0 },
133 .below = { .val = 1.0 * (1<<8), .expand = 0 },
134 .threshold = -14.34 * (1<<8),
135 .energy = 2.4 * (1<<12),
136 .attack = 0.013 * (1<<12),
137 .decay = 0.212 * (1<<12),
138};
139
140static struct tas_biquad_ctrl_t eqp_1c_1_0_biquads[]={
141 { .channel = 0, .filter = 0, .data = { .coeff = { 0x0f4f95, 0xe160d4, 0x0f4f95, 0xe1686e, 0x0ea6c5 } } },
142 { .channel = 0, .filter = 1, .data = { .coeff = { 0x066b92, 0x0290d4, 0x0148a0, 0xf6853f, 0x03bfc7 } } },
143 { .channel = 0, .filter = 2, .data = { .coeff = { 0x0f57dc, 0xe51c91, 0x0dd1cb, 0xe51c91, 0x0d29a8 } } },
144 { .channel = 0, .filter = 3, .data = { .coeff = { 0x0df1cb, 0xe4fa84, 0x0d7cdc, 0xe4fa84, 0x0b6ea7 } } },
145 { .channel = 0, .filter = 4, .data = { .coeff = { 0x0eba36, 0xe6aa48, 0x0b9f52, 0xe6aa48, 0x0a5989 } } },
146 { .channel = 0, .filter = 5, .data = { .coeff = { 0x0caf02, 0x05ef9d, 0x084beb, 0x05ef9d, 0x04faee } } },
147 { .channel = 0, .filter = 6, .data = { .coeff = { 0x0fc686, 0xe22947, 0x0e4b5d, 0xe22947, 0x0e11e4 } } },
148
149 { .channel = 1, .filter = 0, .data = { .coeff = { 0x0f4f95, 0xe160d4, 0x0f4f95, 0xe1686e, 0x0ea6c5 } } },
150 { .channel = 1, .filter = 1, .data = { .coeff = { 0x066b92, 0x0290d4, 0x0148a0, 0xf6853f, 0x03bfc7 } } },
151 { .channel = 1, .filter = 2, .data = { .coeff = { 0x0f57dc, 0xe51c91, 0x0dd1cb, 0xe51c91, 0x0d29a8 } } },
152 { .channel = 1, .filter = 3, .data = { .coeff = { 0x0df1cb, 0xe4fa84, 0x0d7cdc, 0xe4fa84, 0x0b6ea7 } } },
153 { .channel = 1, .filter = 4, .data = { .coeff = { 0x0eba36, 0xe6aa48, 0x0b9f52, 0xe6aa48, 0x0a5989 } } },
154 { .channel = 1, .filter = 5, .data = { .coeff = { 0x0caf02, 0x05ef9d, 0x084beb, 0x05ef9d, 0x04faee } } },
155 { .channel = 1, .filter = 6, .data = { .coeff = { 0x0fc686, 0xe22947, 0x0e4b5d, 0xe22947, 0x0e11e4 } } }
156};
157
158static struct tas_eq_pref_t eqp_1c_1_0 = {
159 .sample_rate = 44100,
160 .device_id = 0x1c,
161 .output_id = TAS_OUTPUT_INTERNAL_SPKR,
162 .speaker_id = 0x00,
163
164 .drce = &eqp_1c_1_0_drce,
165
166 .filter_count = 14,
167 .biquads = eqp_1c_1_0_biquads
168};
169
170/* ======================================================================== */
171
172static uint tas3004_master_tab[]={
173 0x0, 0x75, 0x9c, 0xbb,
174 0xdb, 0xfb, 0x11e, 0x143,
175 0x16b, 0x196, 0x1c3, 0x1f5,
176 0x229, 0x263, 0x29f, 0x2e1,
177 0x328, 0x373, 0x3c5, 0x41b,
178 0x478, 0x4dc, 0x547, 0x5b8,
179 0x633, 0x6b5, 0x740, 0x7d5,
180 0x873, 0x91c, 0x9d2, 0xa92,
181 0xb5e, 0xc39, 0xd22, 0xe19,
182 0xf20, 0x1037, 0x1161, 0x129e,
183 0x13ed, 0x1551, 0x16ca, 0x185d,
184 0x1a08, 0x1bcc, 0x1dac, 0x1fa7,
185 0x21c1, 0x23fa, 0x2655, 0x28d6,
186 0x2b7c, 0x2e4a, 0x3141, 0x3464,
187 0x37b4, 0x3b35, 0x3ee9, 0x42d3,
188 0x46f6, 0x4b53, 0x4ff0, 0x54ce,
189 0x59f2, 0x5f5f, 0x6519, 0x6b24,
190 0x7183, 0x783c, 0x7f53, 0x86cc,
191 0x8ead, 0x96fa, 0x9fba, 0xa8f2,
192 0xb2a7, 0xbce1, 0xc7a5, 0xd2fa,
193 0xdee8, 0xeb75, 0xf8aa, 0x1068e,
194 0x1152a, 0x12487, 0x134ad, 0x145a5,
195 0x1577b, 0x16a37, 0x17df5, 0x192bd,
196 0x1a890, 0x1bf7b, 0x1d78d, 0x1f0d1,
197 0x20b55, 0x22727, 0x24456, 0x262f2,
198 0x2830b
199};
200
201static uint tas3004_mixer_tab[]={
202 0x0, 0x748, 0x9be, 0xbaf,
203 0xda4, 0xfb1, 0x11de, 0x1431,
204 0x16ad, 0x1959, 0x1c37, 0x1f4b,
205 0x2298, 0x2628, 0x29fb, 0x2e12,
206 0x327d, 0x3734, 0x3c47, 0x41b4,
207 0x4787, 0x4dbe, 0x546d, 0x5b86,
208 0x632e, 0x6b52, 0x7400, 0x7d54,
209 0x873b, 0x91c6, 0x9d1a, 0xa920,
210 0xb5e5, 0xc38c, 0xd21b, 0xe18f,
211 0xf1f5, 0x1036a, 0x1160f, 0x129d6,
212 0x13ed0, 0x1550c, 0x16ca0, 0x185c9,
213 0x1a07b, 0x1bcc3, 0x1dab9, 0x1fa75,
214 0x21c0f, 0x23fa3, 0x26552, 0x28d64,
215 0x2b7c9, 0x2e4a2, 0x31411, 0x3463b,
216 0x37b44, 0x3b353, 0x3ee94, 0x42d30,
217 0x46f55, 0x4b533, 0x4fefc, 0x54ce5,
218 0x59f25, 0x5f5f6, 0x65193, 0x6b23c,
219 0x71835, 0x783c3, 0x7f52c, 0x86cc0,
220 0x8eacc, 0x96fa5, 0x9fba0, 0xa8f1a,
221 0xb2a71, 0xbce0a, 0xc7a4a, 0xd2fa0,
222 0xdee7b, 0xeb752, 0xf8a9f, 0x1068e4,
223 0x1152a3, 0x12486a, 0x134ac8, 0x145a55,
224 0x1577ac, 0x16a370, 0x17df51, 0x192bc2,
225 0x1a88f8, 0x1bf7b7, 0x1d78c9, 0x1f0d04,
226 0x20b542, 0x227268, 0x244564, 0x262f26,
227 0x2830af
228};
229
230static uint tas3004_treble_tab[]={
231 0x96, 0x95, 0x95, 0x94,
232 0x93, 0x92, 0x92, 0x91,
233 0x90, 0x90, 0x8f, 0x8e,
234 0x8d, 0x8d, 0x8c, 0x8b,
235 0x8a, 0x8a, 0x89, 0x88,
236 0x88, 0x87, 0x86, 0x85,
237 0x85, 0x84, 0x83, 0x83,
238 0x82, 0x81, 0x80, 0x80,
239 0x7f, 0x7e, 0x7e, 0x7d,
240 0x7c, 0x7b, 0x7b, 0x7a,
241 0x79, 0x78, 0x78, 0x77,
242 0x76, 0x76, 0x75, 0x74,
243 0x73, 0x73, 0x72, 0x71,
244 0x71, 0x68, 0x45, 0x5b,
245 0x6d, 0x6c, 0x6b, 0x6a,
246 0x69, 0x68, 0x67, 0x66,
247 0x65, 0x63, 0x62, 0x62,
248 0x60, 0x5e, 0x5c, 0x5b,
249 0x59, 0x57, 0x55, 0x53,
250 0x52, 0x4f, 0x4d, 0x4a,
251 0x48, 0x46, 0x43, 0x40,
252 0x3d, 0x3a, 0x36, 0x33,
253 0x2f, 0x2c, 0x27, 0x23,
254 0x1f, 0x1a, 0x15, 0xf,
255 0x8, 0x5, 0x2, 0x1,
256 0x1
257};
258
259static uint tas3004_bass_tab[]={
260 0x96, 0x95, 0x95, 0x94,
261 0x93, 0x92, 0x92, 0x91,
262 0x90, 0x90, 0x8f, 0x8e,
263 0x8d, 0x8d, 0x8c, 0x8b,
264 0x8a, 0x8a, 0x89, 0x88,
265 0x88, 0x87, 0x86, 0x85,
266 0x85, 0x84, 0x83, 0x83,
267 0x82, 0x81, 0x80, 0x80,
268 0x7f, 0x7e, 0x7e, 0x7d,
269 0x7c, 0x7b, 0x7b, 0x7a,
270 0x79, 0x78, 0x78, 0x77,
271 0x76, 0x76, 0x75, 0x74,
272 0x73, 0x73, 0x72, 0x71,
273 0x70, 0x6f, 0x6e, 0x6d,
274 0x6c, 0x6b, 0x6a, 0x6a,
275 0x69, 0x67, 0x66, 0x66,
276 0x65, 0x63, 0x62, 0x62,
277 0x61, 0x60, 0x5e, 0x5d,
278 0x5b, 0x59, 0x57, 0x55,
279 0x53, 0x51, 0x4f, 0x4c,
280 0x4a, 0x48, 0x46, 0x44,
281 0x41, 0x3e, 0x3b, 0x38,
282 0x36, 0x33, 0x2f, 0x2b,
283 0x28, 0x24, 0x20, 0x1c,
284 0x17, 0x12, 0xd, 0x7,
285 0x1
286};
287
288struct tas_gain_t tas3004_gain={
289 .master = tas3004_master_tab,
290 .treble = tas3004_treble_tab,
291 .bass = tas3004_bass_tab,
292 .mixer = tas3004_mixer_tab
293};
294
295struct tas_eq_pref_t *tas3004_eq_prefs[]={
296 &eqp_17_1_0,
297 &eqp_18_1_0,
298 &eqp_1a_1_0,
299 &eqp_1c_1_0,
300 NULL
301};
diff --git a/sound/oss/dmasound/tas_common.c b/sound/oss/dmasound/tas_common.c
new file mode 100644
index 000000000000..d36a1fe2fcf3
--- /dev/null
+++ b/sound/oss/dmasound/tas_common.c
@@ -0,0 +1,214 @@
1#include <linux/module.h>
2#include <linux/slab.h>
3#include <linux/proc_fs.h>
4#include <linux/ioport.h>
5#include <linux/sysctl.h>
6#include <linux/types.h>
7#include <linux/i2c.h>
8#include <linux/init.h>
9#include <linux/soundcard.h>
10#include <asm/uaccess.h>
11#include <asm/errno.h>
12#include <asm/io.h>
13#include <asm/prom.h>
14
15#include "tas_common.h"
16
17#define CALL0(proc) \
18 do { \
19 struct tas_data_t *self; \
20 if (!tas_client || driver_hooks == NULL) \
21 return -1; \
22 self = dev_get_drvdata(&tas_client->dev); \
23 if (driver_hooks->proc) \
24 return driver_hooks->proc(self); \
25 else \
26 return -EINVAL; \
27 } while (0)
28
29#define CALL(proc,arg...) \
30 do { \
31 struct tas_data_t *self; \
32 if (!tas_client || driver_hooks == NULL) \
33 return -1; \
34 self = dev_get_drvdata(&tas_client->dev); \
35 if (driver_hooks->proc) \
36 return driver_hooks->proc(self, ## arg); \
37 else \
38 return -EINVAL; \
39 } while (0)
40
41
42static u8 tas_i2c_address = 0x34;
43static struct i2c_client *tas_client;
44static struct device_node* tas_node;
45
46static int tas_attach_adapter(struct i2c_adapter *);
47static int tas_detach_client(struct i2c_client *);
48
49struct i2c_driver tas_driver = {
50 .owner = THIS_MODULE,
51 .name = "tas",
52 .flags = I2C_DF_NOTIFY,
53 .attach_adapter = tas_attach_adapter,
54 .detach_client = tas_detach_client,
55};
56
57struct tas_driver_hooks_t *driver_hooks;
58
59int
60tas_register_driver(struct tas_driver_hooks_t *hooks)
61{
62 driver_hooks = hooks;
63 return 0;
64}
65
66int
67tas_get_mixer_level(int mixer, uint *level)
68{
69 CALL(get_mixer_level,mixer,level);
70}
71
72int
73tas_set_mixer_level(int mixer,uint level)
74{
75 CALL(set_mixer_level,mixer,level);
76}
77
78int
79tas_enter_sleep(void)
80{
81 CALL0(enter_sleep);
82}
83
84int
85tas_leave_sleep(void)
86{
87 CALL0(leave_sleep);
88}
89
90int
91tas_supported_mixers(void)
92{
93 CALL0(supported_mixers);
94}
95
96int
97tas_mixer_is_stereo(int mixer)
98{
99 CALL(mixer_is_stereo,mixer);
100}
101
102int
103tas_stereo_mixers(void)
104{
105 CALL0(stereo_mixers);
106}
107
108int
109tas_output_device_change(int device_id,int layout_id,int speaker_id)
110{
111 CALL(output_device_change,device_id,layout_id,speaker_id);
112}
113
114int
115tas_device_ioctl(u_int cmd, u_long arg)
116{
117 CALL(device_ioctl,cmd,arg);
118}
119
120int
121tas_post_init(void)
122{
123 CALL0(post_init);
124}
125
126static int
127tas_detect_client(struct i2c_adapter *adapter, int address)
128{
129 static const char *client_name = "tas Digital Equalizer";
130 struct i2c_client *new_client;
131 int rc = -ENODEV;
132
133 if (!driver_hooks) {
134 printk(KERN_ERR "tas_detect_client called with no hooks !\n");
135 return -ENODEV;
136 }
137
138 new_client = kmalloc(sizeof(*new_client), GFP_KERNEL);
139 if (!new_client)
140 return -ENOMEM;
141 memset(new_client, 0, sizeof(*new_client));
142
143 new_client->addr = address;
144 new_client->adapter = adapter;
145 new_client->driver = &tas_driver;
146 strlcpy(new_client->name, client_name, DEVICE_NAME_SIZE);
147
148 if (driver_hooks->init(new_client))
149 goto bail;
150
151 /* Tell the i2c layer a new client has arrived */
152 if (i2c_attach_client(new_client)) {
153 driver_hooks->uninit(dev_get_drvdata(&new_client->dev));
154 goto bail;
155 }
156
157 tas_client = new_client;
158 return 0;
159 bail:
160 tas_client = NULL;
161 kfree(new_client);
162 return rc;
163}
164
165static int
166tas_attach_adapter(struct i2c_adapter *adapter)
167{
168 if (!strncmp(adapter->name, "mac-io", 6))
169 return tas_detect_client(adapter, tas_i2c_address);
170 return 0;
171}
172
173static int
174tas_detach_client(struct i2c_client *client)
175{
176 if (client == tas_client) {
177 driver_hooks->uninit(dev_get_drvdata(&client->dev));
178
179 i2c_detach_client(client);
180 kfree(client);
181 }
182 return 0;
183}
184
185void
186tas_cleanup(void)
187{
188 i2c_del_driver(&tas_driver);
189}
190
191int __init
192tas_init(int driver_id, const char *driver_name)
193{
194 u32* paddr;
195
196 printk(KERN_INFO "tas driver [%s])\n", driver_name);
197
198#ifndef CONFIG_I2C_KEYWEST
199 request_module("i2c-keywest");
200#endif
201 tas_node = find_devices("deq");
202 if (tas_node == NULL)
203 return -ENODEV;
204 paddr = (u32 *)get_property(tas_node, "i2c-address", NULL);
205 if (paddr) {
206 tas_i2c_address = (*paddr) >> 1;
207 printk(KERN_INFO "using i2c address: 0x%x from device-tree\n",
208 tas_i2c_address);
209 } else
210 printk(KERN_INFO "using i2c address: 0x%x (default)\n",
211 tas_i2c_address);
212
213 return i2c_add_driver(&tas_driver);
214}
diff --git a/sound/oss/dmasound/tas_common.h b/sound/oss/dmasound/tas_common.h
new file mode 100644
index 000000000000..3a6d48666db0
--- /dev/null
+++ b/sound/oss/dmasound/tas_common.h
@@ -0,0 +1,284 @@
1#ifndef _TAS_COMMON_H_
2#define _TAS_COMMON_H_
3
4#include <linux/i2c.h>
5#include <linux/soundcard.h>
6#include <asm/string.h>
7
8#define I2C_DRIVERID_TAS_BASE (0xFEBA)
9
10#define SET_4_20(shadow, offset, val) \
11 do { \
12 (shadow)[(offset)+0] = ((val) >> 16) & 0xff; \
13 (shadow)[(offset)+1] = ((val) >> 8) & 0xff; \
14 (shadow)[(offset)+2] = ((val) >> 0) & 0xff; \
15 } while (0)
16
17#define GET_4_20(shadow, offset) \
18 (((u_int)((shadow)[(offset)+0]) << 16) | \
19 ((u_int)((shadow)[(offset)+1]) << 8) | \
20 ((u_int)((shadow)[(offset)+2]) << 0))
21
22
23#define TAS_BIQUAD_FAST_LOAD 0x01
24
25#define TAS_DRCE_ENABLE 0x01
26#define TAS_DRCE_ABOVE_RATIO 0x02
27#define TAS_DRCE_BELOW_RATIO 0x04
28#define TAS_DRCE_THRESHOLD 0x08
29#define TAS_DRCE_ENERGY 0x10
30#define TAS_DRCE_ATTACK 0x20
31#define TAS_DRCE_DECAY 0x40
32
33#define TAS_DRCE_ALL 0x7f
34
35
36#define TAS_OUTPUT_HEADPHONES 0x00
37#define TAS_OUTPUT_INTERNAL_SPKR 0x01
38#define TAS_OUTPUT_EXTERNAL_SPKR 0x02
39
40
41union tas_biquad_t {
42 struct {
43 int b0,b1,b2,a1,a2;
44 } coeff;
45 int buf[5];
46};
47
48struct tas_biquad_ctrl_t {
49 u_int channel:4;
50 u_int filter:4;
51
52 union tas_biquad_t data;
53};
54
55struct tas_biquad_ctrl_list_t {
56 int flags;
57 int filter_count;
58 struct tas_biquad_ctrl_t biquads[0];
59};
60
61struct tas_ratio_t {
62 unsigned short val; /* 8.8 */
63 unsigned short expand; /* 0 = compress, !0 = expand. */
64};
65
66struct tas_drce_t {
67 unsigned short enable;
68 struct tas_ratio_t above;
69 struct tas_ratio_t below;
70 short threshold; /* dB, 8.8 signed */
71 unsigned short energy; /* seconds, 4.12 unsigned */
72 unsigned short attack; /* seconds, 4.12 unsigned */
73 unsigned short decay; /* seconds, 4.12 unsigned */
74};
75
76struct tas_drce_ctrl_t {
77 uint flags;
78
79 struct tas_drce_t data;
80};
81
82struct tas_gain_t
83{
84 unsigned int *master;
85 unsigned int *treble;
86 unsigned int *bass;
87 unsigned int *mixer;
88};
89
90typedef char tas_shadow_t[0x45];
91
92struct tas_data_t
93{
94 struct i2c_client *client;
95 tas_shadow_t *shadow;
96 uint mixer[SOUND_MIXER_NRDEVICES];
97};
98
99typedef int (*tas_hook_init_t)(struct i2c_client *);
100typedef int (*tas_hook_post_init_t)(struct tas_data_t *);
101typedef void (*tas_hook_uninit_t)(struct tas_data_t *);
102
103typedef int (*tas_hook_get_mixer_level_t)(struct tas_data_t *,int,uint *);
104typedef int (*tas_hook_set_mixer_level_t)(struct tas_data_t *,int,uint);
105
106typedef int (*tas_hook_enter_sleep_t)(struct tas_data_t *);
107typedef int (*tas_hook_leave_sleep_t)(struct tas_data_t *);
108
109typedef int (*tas_hook_supported_mixers_t)(struct tas_data_t *);
110typedef int (*tas_hook_mixer_is_stereo_t)(struct tas_data_t *,int);
111typedef int (*tas_hook_stereo_mixers_t)(struct tas_data_t *);
112
113typedef int (*tas_hook_output_device_change_t)(struct tas_data_t *,int,int,int);
114typedef int (*tas_hook_device_ioctl_t)(struct tas_data_t *,u_int,u_long);
115
116struct tas_driver_hooks_t {
117 /*
118 * All hardware initialisation must be performed in
119 * post_init(), as tas_dmasound_init() does a hardware reset.
120 *
121 * init() is called before tas_dmasound_init() so that
122 * ouput_device_change() is always called after i2c driver
123 * initialisation. The implication is that
124 * output_device_change() must cope with the fact that it
125 * may be called before post_init().
126 */
127
128 tas_hook_init_t init;
129 tas_hook_post_init_t post_init;
130 tas_hook_uninit_t uninit;
131
132 tas_hook_get_mixer_level_t get_mixer_level;
133 tas_hook_set_mixer_level_t set_mixer_level;
134
135 tas_hook_enter_sleep_t enter_sleep;
136 tas_hook_leave_sleep_t leave_sleep;
137
138 tas_hook_supported_mixers_t supported_mixers;
139 tas_hook_mixer_is_stereo_t mixer_is_stereo;
140 tas_hook_stereo_mixers_t stereo_mixers;
141
142 tas_hook_output_device_change_t output_device_change;
143 tas_hook_device_ioctl_t device_ioctl;
144};
145
146enum tas_write_mode_t {
147 WRITE_HW = 0x01,
148 WRITE_SHADOW = 0x02,
149 WRITE_NORMAL = 0x03,
150 FORCE_WRITE = 0x04
151};
152
153static inline uint
154tas_mono_to_stereo(uint mono)
155{
156 mono &=0xff;
157 return mono | (mono<<8);
158}
159
160/*
161 * Todo: make these functions a bit more efficient !
162 */
163static inline int
164tas_write_register( struct tas_data_t *self,
165 uint reg_num,
166 uint reg_width,
167 char *data,
168 uint write_mode)
169{
170 int rc;
171
172 if (reg_width==0 || data==NULL || self==NULL)
173 return -EINVAL;
174 if (!(write_mode & FORCE_WRITE) &&
175 !memcmp(data,self->shadow[reg_num],reg_width))
176 return 0;
177
178 if (write_mode & WRITE_SHADOW)
179 memcpy(self->shadow[reg_num],data,reg_width);
180 if (write_mode & WRITE_HW) {
181 rc=i2c_smbus_write_block_data(self->client,
182 reg_num,
183 reg_width,
184 data);
185 if (rc < 0) {
186 printk("tas: I2C block write failed \n");
187 return rc;
188 }
189 }
190 return 0;
191}
192
193static inline int
194tas_sync_register( struct tas_data_t *self,
195 uint reg_num,
196 uint reg_width)
197{
198 int rc;
199
200 if (reg_width==0 || self==NULL)
201 return -EINVAL;
202 rc=i2c_smbus_write_block_data(self->client,
203 reg_num,
204 reg_width,
205 self->shadow[reg_num]);
206 if (rc < 0) {
207 printk("tas: I2C block write failed \n");
208 return rc;
209 }
210 return 0;
211}
212
213static inline int
214tas_write_byte_register( struct tas_data_t *self,
215 uint reg_num,
216 char data,
217 uint write_mode)
218{
219 if (self==NULL)
220 return -1;
221 if (!(write_mode & FORCE_WRITE) && data != self->shadow[reg_num][0])
222 return 0;
223 if (write_mode & WRITE_SHADOW)
224 self->shadow[reg_num][0]=data;
225 if (write_mode & WRITE_HW) {
226 if (i2c_smbus_write_byte_data(self->client, reg_num, data) < 0) {
227 printk("tas: I2C byte write failed \n");
228 return -1;
229 }
230 }
231 return 0;
232}
233
234static inline int
235tas_sync_byte_register( struct tas_data_t *self,
236 uint reg_num,
237 uint reg_width)
238{
239 if (reg_width==0 || self==NULL)
240 return -1;
241 if (i2c_smbus_write_byte_data(
242 self->client, reg_num, self->shadow[reg_num][0]) < 0) {
243 printk("tas: I2C byte write failed \n");
244 return -1;
245 }
246 return 0;
247}
248
249static inline int
250tas_read_register( struct tas_data_t *self,
251 uint reg_num,
252 uint reg_width,
253 char *data)
254{
255 if (reg_width==0 || data==NULL || self==NULL)
256 return -1;
257 memcpy(data,self->shadow[reg_num],reg_width);
258 return 0;
259}
260
261extern int tas_register_driver(struct tas_driver_hooks_t *hooks);
262
263extern int tas_get_mixer_level(int mixer,uint *level);
264extern int tas_set_mixer_level(int mixer,uint level);
265extern int tas_enter_sleep(void);
266extern int tas_leave_sleep(void);
267extern int tas_supported_mixers(void);
268extern int tas_mixer_is_stereo(int mixer);
269extern int tas_stereo_mixers(void);
270extern int tas_output_device_change(int,int,int);
271extern int tas_device_ioctl(u_int, u_long);
272
273extern void tas_cleanup(void);
274extern int tas_init(int driver_id,const char *driver_name);
275extern int tas_post_init(void);
276
277#endif /* _TAS_COMMON_H_ */
278/*
279 * Local Variables:
280 * tab-width: 8
281 * indent-tabs-mode: t
282 * c-basic-offset: 8
283 * End:
284 */
diff --git a/sound/oss/dmasound/tas_eq_prefs.h b/sound/oss/dmasound/tas_eq_prefs.h
new file mode 100644
index 000000000000..3a994eda6abc
--- /dev/null
+++ b/sound/oss/dmasound/tas_eq_prefs.h
@@ -0,0 +1,24 @@
1#ifndef _TAS_EQ_PREFS_H_
2#define _TAS_EQ_PREFS_H_
3
4struct tas_eq_pref_t {
5 u_int sample_rate;
6 u_int device_id;
7 u_int output_id;
8 u_int speaker_id;
9
10 struct tas_drce_t *drce;
11
12 u_int filter_count;
13 struct tas_biquad_ctrl_t *biquads;
14};
15
16#endif /* _TAS_EQ_PREFS_H_ */
17
18/*
19 * Local Variables:
20 * tab-width: 8
21 * indent-tabs-mode: t
22 * c-basic-offset: 8
23 * End:
24 */
diff --git a/sound/oss/dmasound/tas_ioctl.h b/sound/oss/dmasound/tas_ioctl.h
new file mode 100644
index 000000000000..dccae3a40e01
--- /dev/null
+++ b/sound/oss/dmasound/tas_ioctl.h
@@ -0,0 +1,24 @@
1#ifndef _TAS_IOCTL_H_
2#define _TAS_IOCTL_H_
3
4#include <linux/i2c.h>
5#include <linux/soundcard.h>
6
7
8#define TAS_READ_EQ _SIOR('t',0,struct tas_biquad_ctrl_t)
9#define TAS_WRITE_EQ _SIOW('t',0,struct tas_biquad_ctrl_t)
10
11#define TAS_READ_EQ_LIST _SIOR('t',1,struct tas_biquad_ctrl_t)
12#define TAS_WRITE_EQ_LIST _SIOW('t',1,struct tas_biquad_ctrl_t)
13
14#define TAS_READ_EQ_FILTER_COUNT _SIOR('t',2,int)
15#define TAS_READ_EQ_CHANNEL_COUNT _SIOR('t',3,int)
16
17#define TAS_READ_DRCE _SIOR('t',4,struct tas_drce_ctrl_t)
18#define TAS_WRITE_DRCE _SIOW('t',4,struct tas_drce_ctrl_t)
19
20#define TAS_READ_DRCE_CAPS _SIOR('t',5,int)
21#define TAS_READ_DRCE_MIN _SIOR('t',6,int)
22#define TAS_READ_DRCE_MAX _SIOR('t',7,int)
23
24#endif
diff --git a/sound/oss/dmasound/trans_16.c b/sound/oss/dmasound/trans_16.c
new file mode 100644
index 000000000000..23562e947806
--- /dev/null
+++ b/sound/oss/dmasound/trans_16.c
@@ -0,0 +1,897 @@
1/*
2 * linux/sound/oss/dmasound/trans_16.c
3 *
4 * 16 bit translation routines. Only used by Power mac at present.
5 *
6 * See linux/sound/oss/dmasound/dmasound_core.c for copyright and
7 * history prior to 08/02/2001.
8 *
9 * 08/02/2001 Iain Sandoe
10 * split from dmasound_awacs.c
11 * 11/29/2003 Renzo Davoli (King Enzo)
12 * - input resampling (for soft rate < hard rate)
13 * - software line in gain control
14 */
15
16#include <linux/soundcard.h>
17#include <asm/uaccess.h>
18#include "dmasound.h"
19
20static short dmasound_alaw2dma16[] ;
21static short dmasound_ulaw2dma16[] ;
22
23static ssize_t pmac_ct_law(const u_char __user *userPtr, size_t userCount,
24 u_char frame[], ssize_t *frameUsed,
25 ssize_t frameLeft);
26static ssize_t pmac_ct_s8(const u_char __user *userPtr, size_t userCount,
27 u_char frame[], ssize_t *frameUsed,
28 ssize_t frameLeft);
29static ssize_t pmac_ct_u8(const u_char __user *userPtr, size_t userCount,
30 u_char frame[], ssize_t *frameUsed,
31 ssize_t frameLeft);
32static ssize_t pmac_ct_s16(const u_char __user *userPtr, size_t userCount,
33 u_char frame[], ssize_t *frameUsed,
34 ssize_t frameLeft);
35static ssize_t pmac_ct_u16(const u_char __user *userPtr, size_t userCount,
36 u_char frame[], ssize_t *frameUsed,
37 ssize_t frameLeft);
38
39static ssize_t pmac_ctx_law(const u_char __user *userPtr, size_t userCount,
40 u_char frame[], ssize_t *frameUsed,
41 ssize_t frameLeft);
42static ssize_t pmac_ctx_s8(const u_char __user *userPtr, size_t userCount,
43 u_char frame[], ssize_t *frameUsed,
44 ssize_t frameLeft);
45static ssize_t pmac_ctx_u8(const u_char __user *userPtr, size_t userCount,
46 u_char frame[], ssize_t *frameUsed,
47 ssize_t frameLeft);
48static ssize_t pmac_ctx_s16(const u_char __user *userPtr, size_t userCount,
49 u_char frame[], ssize_t *frameUsed,
50 ssize_t frameLeft);
51static ssize_t pmac_ctx_u16(const u_char __user *userPtr, size_t userCount,
52 u_char frame[], ssize_t *frameUsed,
53 ssize_t frameLeft);
54
55static ssize_t pmac_ct_s16_read(const u_char __user *userPtr, size_t userCount,
56 u_char frame[], ssize_t *frameUsed,
57 ssize_t frameLeft);
58static ssize_t pmac_ct_u16_read(const u_char __user *userPtr, size_t userCount,
59 u_char frame[], ssize_t *frameUsed,
60 ssize_t frameLeft);
61
62/*** Translations ************************************************************/
63
64static int expand_data; /* Data for expanding */
65
66static ssize_t pmac_ct_law(const u_char __user *userPtr, size_t userCount,
67 u_char frame[], ssize_t *frameUsed,
68 ssize_t frameLeft)
69{
70 short *table = dmasound.soft.format == AFMT_MU_LAW
71 ? dmasound_ulaw2dma16 : dmasound_alaw2dma16;
72 ssize_t count, used;
73 short *p = (short *) &frame[*frameUsed];
74 int val, stereo = dmasound.soft.stereo;
75
76 frameLeft >>= 2;
77 if (stereo)
78 userCount >>= 1;
79 used = count = min_t(unsigned long, userCount, frameLeft);
80 while (count > 0) {
81 u_char data;
82 if (get_user(data, userPtr++))
83 return -EFAULT;
84 val = table[data];
85 *p++ = val;
86 if (stereo) {
87 if (get_user(data, userPtr++))
88 return -EFAULT;
89 val = table[data];
90 }
91 *p++ = val;
92 count--;
93 }
94 *frameUsed += used * 4;
95 return stereo? used * 2: used;
96}
97
98
99static ssize_t pmac_ct_s8(const u_char __user *userPtr, size_t userCount,
100 u_char frame[], ssize_t *frameUsed,
101 ssize_t frameLeft)
102{
103 ssize_t count, used;
104 short *p = (short *) &frame[*frameUsed];
105 int val, stereo = dmasound.soft.stereo;
106
107 frameLeft >>= 2;
108 if (stereo)
109 userCount >>= 1;
110 used = count = min_t(unsigned long, userCount, frameLeft);
111 while (count > 0) {
112 u_char data;
113 if (get_user(data, userPtr++))
114 return -EFAULT;
115 val = data << 8;
116 *p++ = val;
117 if (stereo) {
118 if (get_user(data, userPtr++))
119 return -EFAULT;
120 val = data << 8;
121 }
122 *p++ = val;
123 count--;
124 }
125 *frameUsed += used * 4;
126 return stereo? used * 2: used;
127}
128
129
130static ssize_t pmac_ct_u8(const u_char __user *userPtr, size_t userCount,
131 u_char frame[], ssize_t *frameUsed,
132 ssize_t frameLeft)
133{
134 ssize_t count, used;
135 short *p = (short *) &frame[*frameUsed];
136 int val, stereo = dmasound.soft.stereo;
137
138 frameLeft >>= 2;
139 if (stereo)
140 userCount >>= 1;
141 used = count = min_t(unsigned long, userCount, frameLeft);
142 while (count > 0) {
143 u_char data;
144 if (get_user(data, userPtr++))
145 return -EFAULT;
146 val = (data ^ 0x80) << 8;
147 *p++ = val;
148 if (stereo) {
149 if (get_user(data, userPtr++))
150 return -EFAULT;
151 val = (data ^ 0x80) << 8;
152 }
153 *p++ = val;
154 count--;
155 }
156 *frameUsed += used * 4;
157 return stereo? used * 2: used;
158}
159
160
161static ssize_t pmac_ct_s16(const u_char __user *userPtr, size_t userCount,
162 u_char frame[], ssize_t *frameUsed,
163 ssize_t frameLeft)
164{
165 ssize_t count, used;
166 int stereo = dmasound.soft.stereo;
167 short *fp = (short *) &frame[*frameUsed];
168
169 frameLeft >>= 2;
170 userCount >>= (stereo? 2: 1);
171 used = count = min_t(unsigned long, userCount, frameLeft);
172 if (!stereo) {
173 short __user *up = (short __user *) userPtr;
174 while (count > 0) {
175 short data;
176 if (get_user(data, up++))
177 return -EFAULT;
178 *fp++ = data;
179 *fp++ = data;
180 count--;
181 }
182 } else {
183 if (copy_from_user(fp, userPtr, count * 4))
184 return -EFAULT;
185 }
186 *frameUsed += used * 4;
187 return stereo? used * 4: used * 2;
188}
189
190static ssize_t pmac_ct_u16(const u_char __user *userPtr, size_t userCount,
191 u_char frame[], ssize_t *frameUsed,
192 ssize_t frameLeft)
193{
194 ssize_t count, used;
195 int mask = (dmasound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
196 int stereo = dmasound.soft.stereo;
197 short *fp = (short *) &frame[*frameUsed];
198 short __user *up = (short __user *) userPtr;
199
200 frameLeft >>= 2;
201 userCount >>= (stereo? 2: 1);
202 used = count = min_t(unsigned long, userCount, frameLeft);
203 while (count > 0) {
204 short data;
205 if (get_user(data, up++))
206 return -EFAULT;
207 data ^= mask;
208 *fp++ = data;
209 if (stereo) {
210 if (get_user(data, up++))
211 return -EFAULT;
212 data ^= mask;
213 }
214 *fp++ = data;
215 count--;
216 }
217 *frameUsed += used * 4;
218 return stereo? used * 4: used * 2;
219}
220
221
222static ssize_t pmac_ctx_law(const u_char __user *userPtr, size_t userCount,
223 u_char frame[], ssize_t *frameUsed,
224 ssize_t frameLeft)
225{
226 unsigned short *table = (unsigned short *)
227 (dmasound.soft.format == AFMT_MU_LAW
228 ? dmasound_ulaw2dma16 : dmasound_alaw2dma16);
229 unsigned int data = expand_data;
230 unsigned int *p = (unsigned int *) &frame[*frameUsed];
231 int bal = expand_bal;
232 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
233 int utotal, ftotal;
234 int stereo = dmasound.soft.stereo;
235
236 frameLeft >>= 2;
237 if (stereo)
238 userCount >>= 1;
239 ftotal = frameLeft;
240 utotal = userCount;
241 while (frameLeft) {
242 u_char c;
243 if (bal < 0) {
244 if (userCount == 0)
245 break;
246 if (get_user(c, userPtr++))
247 return -EFAULT;
248 data = table[c];
249 if (stereo) {
250 if (get_user(c, userPtr++))
251 return -EFAULT;
252 data = (data << 16) + table[c];
253 } else
254 data = (data << 16) + data;
255 userCount--;
256 bal += hSpeed;
257 }
258 *p++ = data;
259 frameLeft--;
260 bal -= sSpeed;
261 }
262 expand_bal = bal;
263 expand_data = data;
264 *frameUsed += (ftotal - frameLeft) * 4;
265 utotal -= userCount;
266 return stereo? utotal * 2: utotal;
267}
268
269static ssize_t pmac_ctx_s8(const u_char __user *userPtr, size_t userCount,
270 u_char frame[], ssize_t *frameUsed,
271 ssize_t frameLeft)
272{
273 unsigned int *p = (unsigned int *) &frame[*frameUsed];
274 unsigned int data = expand_data;
275 int bal = expand_bal;
276 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
277 int stereo = dmasound.soft.stereo;
278 int utotal, ftotal;
279
280 frameLeft >>= 2;
281 if (stereo)
282 userCount >>= 1;
283 ftotal = frameLeft;
284 utotal = userCount;
285 while (frameLeft) {
286 u_char c;
287 if (bal < 0) {
288 if (userCount == 0)
289 break;
290 if (get_user(c, userPtr++))
291 return -EFAULT;
292 data = c << 8;
293 if (stereo) {
294 if (get_user(c, userPtr++))
295 return -EFAULT;
296 data = (data << 16) + (c << 8);
297 } else
298 data = (data << 16) + data;
299 userCount--;
300 bal += hSpeed;
301 }
302 *p++ = data;
303 frameLeft--;
304 bal -= sSpeed;
305 }
306 expand_bal = bal;
307 expand_data = data;
308 *frameUsed += (ftotal - frameLeft) * 4;
309 utotal -= userCount;
310 return stereo? utotal * 2: utotal;
311}
312
313
314static ssize_t pmac_ctx_u8(const u_char __user *userPtr, size_t userCount,
315 u_char frame[], ssize_t *frameUsed,
316 ssize_t frameLeft)
317{
318 unsigned int *p = (unsigned int *) &frame[*frameUsed];
319 unsigned int data = expand_data;
320 int bal = expand_bal;
321 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
322 int stereo = dmasound.soft.stereo;
323 int utotal, ftotal;
324
325 frameLeft >>= 2;
326 if (stereo)
327 userCount >>= 1;
328 ftotal = frameLeft;
329 utotal = userCount;
330 while (frameLeft) {
331 u_char c;
332 if (bal < 0) {
333 if (userCount == 0)
334 break;
335 if (get_user(c, userPtr++))
336 return -EFAULT;
337 data = (c ^ 0x80) << 8;
338 if (stereo) {
339 if (get_user(c, userPtr++))
340 return -EFAULT;
341 data = (data << 16) + ((c ^ 0x80) << 8);
342 } else
343 data = (data << 16) + data;
344 userCount--;
345 bal += hSpeed;
346 }
347 *p++ = data;
348 frameLeft--;
349 bal -= sSpeed;
350 }
351 expand_bal = bal;
352 expand_data = data;
353 *frameUsed += (ftotal - frameLeft) * 4;
354 utotal -= userCount;
355 return stereo? utotal * 2: utotal;
356}
357
358
359static ssize_t pmac_ctx_s16(const u_char __user *userPtr, size_t userCount,
360 u_char frame[], ssize_t *frameUsed,
361 ssize_t frameLeft)
362{
363 unsigned int *p = (unsigned int *) &frame[*frameUsed];
364 unsigned int data = expand_data;
365 unsigned short __user *up = (unsigned short __user *) userPtr;
366 int bal = expand_bal;
367 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
368 int stereo = dmasound.soft.stereo;
369 int utotal, ftotal;
370
371 frameLeft >>= 2;
372 userCount >>= (stereo? 2: 1);
373 ftotal = frameLeft;
374 utotal = userCount;
375 while (frameLeft) {
376 unsigned short c;
377 if (bal < 0) {
378 if (userCount == 0)
379 break;
380 if (get_user(data, up++))
381 return -EFAULT;
382 if (stereo) {
383 if (get_user(c, up++))
384 return -EFAULT;
385 data = (data << 16) + c;
386 } else
387 data = (data << 16) + data;
388 userCount--;
389 bal += hSpeed;
390 }
391 *p++ = data;
392 frameLeft--;
393 bal -= sSpeed;
394 }
395 expand_bal = bal;
396 expand_data = data;
397 *frameUsed += (ftotal - frameLeft) * 4;
398 utotal -= userCount;
399 return stereo? utotal * 4: utotal * 2;
400}
401
402
403static ssize_t pmac_ctx_u16(const u_char __user *userPtr, size_t userCount,
404 u_char frame[], ssize_t *frameUsed,
405 ssize_t frameLeft)
406{
407 int mask = (dmasound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
408 unsigned int *p = (unsigned int *) &frame[*frameUsed];
409 unsigned int data = expand_data;
410 unsigned short __user *up = (unsigned short __user *) userPtr;
411 int bal = expand_bal;
412 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
413 int stereo = dmasound.soft.stereo;
414 int utotal, ftotal;
415
416 frameLeft >>= 2;
417 userCount >>= (stereo? 2: 1);
418 ftotal = frameLeft;
419 utotal = userCount;
420 while (frameLeft) {
421 unsigned short c;
422 if (bal < 0) {
423 if (userCount == 0)
424 break;
425 if (get_user(data, up++))
426 return -EFAULT;
427 data ^= mask;
428 if (stereo) {
429 if (get_user(c, up++))
430 return -EFAULT;
431 data = (data << 16) + (c ^ mask);
432 } else
433 data = (data << 16) + data;
434 userCount--;
435 bal += hSpeed;
436 }
437 *p++ = data;
438 frameLeft--;
439 bal -= sSpeed;
440 }
441 expand_bal = bal;
442 expand_data = data;
443 *frameUsed += (ftotal - frameLeft) * 4;
444 utotal -= userCount;
445 return stereo? utotal * 4: utotal * 2;
446}
447
448/* data in routines... */
449
450static ssize_t pmac_ct_s8_read(const u_char __user *userPtr, size_t userCount,
451 u_char frame[], ssize_t *frameUsed,
452 ssize_t frameLeft)
453{
454 ssize_t count, used;
455 short *p = (short *) &frame[*frameUsed];
456 int val, stereo = dmasound.soft.stereo;
457
458 frameLeft >>= 2;
459 if (stereo)
460 userCount >>= 1;
461 used = count = min_t(unsigned long, userCount, frameLeft);
462 while (count > 0) {
463 u_char data;
464
465 val = *p++;
466 val = (val * software_input_volume) >> 7;
467 data = val >> 8;
468 if (put_user(data, (u_char __user *)userPtr++))
469 return -EFAULT;
470 if (stereo) {
471 val = *p;
472 val = (val * software_input_volume) >> 7;
473 data = val >> 8;
474 if (put_user(data, (u_char __user *)userPtr++))
475 return -EFAULT;
476 }
477 p++;
478 count--;
479 }
480 *frameUsed += used * 4;
481 return stereo? used * 2: used;
482}
483
484
485static ssize_t pmac_ct_u8_read(const u_char __user *userPtr, size_t userCount,
486 u_char frame[], ssize_t *frameUsed,
487 ssize_t frameLeft)
488{
489 ssize_t count, used;
490 short *p = (short *) &frame[*frameUsed];
491 int val, stereo = dmasound.soft.stereo;
492
493 frameLeft >>= 2;
494 if (stereo)
495 userCount >>= 1;
496 used = count = min_t(unsigned long, userCount, frameLeft);
497 while (count > 0) {
498 u_char data;
499
500 val = *p++;
501 val = (val * software_input_volume) >> 7;
502 data = (val >> 8) ^ 0x80;
503 if (put_user(data, (u_char __user *)userPtr++))
504 return -EFAULT;
505 if (stereo) {
506 val = *p;
507 val = (val * software_input_volume) >> 7;
508 data = (val >> 8) ^ 0x80;
509 if (put_user(data, (u_char __user *)userPtr++))
510 return -EFAULT;
511 }
512 p++;
513 count--;
514 }
515 *frameUsed += used * 4;
516 return stereo? used * 2: used;
517}
518
519static ssize_t pmac_ct_s16_read(const u_char __user *userPtr, size_t userCount,
520 u_char frame[], ssize_t *frameUsed,
521 ssize_t frameLeft)
522{
523 ssize_t count, used;
524 int stereo = dmasound.soft.stereo;
525 short *fp = (short *) &frame[*frameUsed];
526 short __user *up = (short __user *) userPtr;
527
528 frameLeft >>= 2;
529 userCount >>= (stereo? 2: 1);
530 used = count = min_t(unsigned long, userCount, frameLeft);
531 while (count > 0) {
532 short data;
533
534 data = *fp++;
535 data = (data * software_input_volume) >> 7;
536 if (put_user(data, up++))
537 return -EFAULT;
538 if (stereo) {
539 data = *fp;
540 data = (data * software_input_volume) >> 7;
541 if (put_user(data, up++))
542 return -EFAULT;
543 }
544 fp++;
545 count--;
546 }
547 *frameUsed += used * 4;
548 return stereo? used * 4: used * 2;
549}
550
551static ssize_t pmac_ct_u16_read(const u_char __user *userPtr, size_t userCount,
552 u_char frame[], ssize_t *frameUsed,
553 ssize_t frameLeft)
554{
555 ssize_t count, used;
556 int mask = (dmasound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
557 int stereo = dmasound.soft.stereo;
558 short *fp = (short *) &frame[*frameUsed];
559 short __user *up = (short __user *) userPtr;
560
561 frameLeft >>= 2;
562 userCount >>= (stereo? 2: 1);
563 used = count = min_t(unsigned long, userCount, frameLeft);
564 while (count > 0) {
565 int data;
566
567 data = *fp++;
568 data = (data * software_input_volume) >> 7;
569 data ^= mask;
570 if (put_user(data, up++))
571 return -EFAULT;
572 if (stereo) {
573 data = *fp;
574 data = (data * software_input_volume) >> 7;
575 data ^= mask;
576 if (put_user(data, up++))
577 return -EFAULT;
578 }
579 fp++;
580 count--;
581 }
582 *frameUsed += used * 4;
583 return stereo? used * 4: used * 2;
584}
585
586/* data in routines (reducing speed)... */
587
588static ssize_t pmac_ctx_s8_read(const u_char __user *userPtr, size_t userCount,
589 u_char frame[], ssize_t *frameUsed,
590 ssize_t frameLeft)
591{
592 short *p = (short *) &frame[*frameUsed];
593 int bal = expand_read_bal;
594 int vall,valr, stereo = dmasound.soft.stereo;
595 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
596 int utotal, ftotal;
597
598 frameLeft >>= 2;
599 if (stereo)
600 userCount >>= 1;
601 ftotal = frameLeft;
602 utotal = userCount;
603 while (frameLeft) {
604 u_char data;
605
606 if (bal<0 && userCount == 0)
607 break;
608 vall = *p++;
609 vall = (vall * software_input_volume) >> 7;
610 if (stereo) {
611 valr = *p;
612 valr = (valr * software_input_volume) >> 7;
613 }
614 p++;
615 if (bal < 0) {
616 data = vall >> 8;
617 if (put_user(data, (u_char __user *)userPtr++))
618 return -EFAULT;
619 if (stereo) {
620 data = valr >> 8;
621 if (put_user(data, (u_char __user *)userPtr++))
622 return -EFAULT;
623 }
624 userCount--;
625 bal += hSpeed;
626 }
627 frameLeft--;
628 bal -= sSpeed;
629 }
630 expand_read_bal=bal;
631 *frameUsed += (ftotal - frameLeft) * 4;
632 utotal -= userCount;
633 return stereo? utotal * 2: utotal;
634}
635
636
637static ssize_t pmac_ctx_u8_read(const u_char __user *userPtr, size_t userCount,
638 u_char frame[], ssize_t *frameUsed,
639 ssize_t frameLeft)
640{
641 short *p = (short *) &frame[*frameUsed];
642 int bal = expand_read_bal;
643 int vall,valr, stereo = dmasound.soft.stereo;
644 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
645 int utotal, ftotal;
646
647 frameLeft >>= 2;
648 if (stereo)
649 userCount >>= 1;
650 ftotal = frameLeft;
651 utotal = userCount;
652 while (frameLeft) {
653 u_char data;
654
655 if (bal<0 && userCount == 0)
656 break;
657
658 vall = *p++;
659 vall = (vall * software_input_volume) >> 7;
660 if (stereo) {
661 valr = *p;
662 valr = (valr * software_input_volume) >> 7;
663 }
664 p++;
665 if (bal < 0) {
666 data = (vall >> 8) ^ 0x80;
667 if (put_user(data, (u_char __user *)userPtr++))
668 return -EFAULT;
669 if (stereo) {
670 data = (valr >> 8) ^ 0x80;
671 if (put_user(data, (u_char __user *)userPtr++))
672 return -EFAULT;
673 }
674 userCount--;
675 bal += hSpeed;
676 }
677 frameLeft--;
678 bal -= sSpeed;
679 }
680 expand_read_bal=bal;
681 *frameUsed += (ftotal - frameLeft) * 4;
682 utotal -= userCount;
683 return stereo? utotal * 2: utotal;
684}
685
686static ssize_t pmac_ctx_s16_read(const u_char __user *userPtr, size_t userCount,
687 u_char frame[], ssize_t *frameUsed,
688 ssize_t frameLeft)
689{
690 int bal = expand_read_bal;
691 short *fp = (short *) &frame[*frameUsed];
692 short __user *up = (short __user *) userPtr;
693 int stereo = dmasound.soft.stereo;
694 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
695 int utotal, ftotal;
696
697 frameLeft >>= 2;
698 userCount >>= (stereo? 2: 1);
699 ftotal = frameLeft;
700 utotal = userCount;
701 while (frameLeft) {
702 int datal,datar;
703
704 if (bal<0 && userCount == 0)
705 break;
706
707 datal = *fp++;
708 datal = (datal * software_input_volume) >> 7;
709 if (stereo) {
710 datar = *fp;
711 datar = (datar * software_input_volume) >> 7;
712 }
713 fp++;
714 if (bal < 0) {
715 if (put_user(datal, up++))
716 return -EFAULT;
717 if (stereo) {
718 if (put_user(datar, up++))
719 return -EFAULT;
720 }
721 userCount--;
722 bal += hSpeed;
723 }
724 frameLeft--;
725 bal -= sSpeed;
726 }
727 expand_read_bal=bal;
728 *frameUsed += (ftotal - frameLeft) * 4;
729 utotal -= userCount;
730 return stereo? utotal * 4: utotal * 2;
731}
732
733static ssize_t pmac_ctx_u16_read(const u_char __user *userPtr, size_t userCount,
734 u_char frame[], ssize_t *frameUsed,
735 ssize_t frameLeft)
736{
737 int bal = expand_read_bal;
738 int mask = (dmasound.soft.format == AFMT_U16_LE? 0x0080: 0x8000);
739 short *fp = (short *) &frame[*frameUsed];
740 short __user *up = (short __user *) userPtr;
741 int stereo = dmasound.soft.stereo;
742 int hSpeed = dmasound.hard.speed, sSpeed = dmasound.soft.speed;
743 int utotal, ftotal;
744
745 frameLeft >>= 2;
746 userCount >>= (stereo? 2: 1);
747 ftotal = frameLeft;
748 utotal = userCount;
749 while (frameLeft) {
750 int datal,datar;
751
752 if (bal<0 && userCount == 0)
753 break;
754
755 datal = *fp++;
756 datal = (datal * software_input_volume) >> 7;
757 datal ^= mask;
758 if (stereo) {
759 datar = *fp;
760 datar = (datar * software_input_volume) >> 7;
761 datar ^= mask;
762 }
763 fp++;
764 if (bal < 0) {
765 if (put_user(datal, up++))
766 return -EFAULT;
767 if (stereo) {
768 if (put_user(datar, up++))
769 return -EFAULT;
770 }
771 userCount--;
772 bal += hSpeed;
773 }
774 frameLeft--;
775 bal -= sSpeed;
776 }
777 expand_read_bal=bal;
778 *frameUsed += (ftotal - frameLeft) * 4;
779 utotal -= userCount;
780 return stereo? utotal * 4: utotal * 2;
781}
782
783
784TRANS transAwacsNormal = {
785 .ct_ulaw= pmac_ct_law,
786 .ct_alaw= pmac_ct_law,
787 .ct_s8= pmac_ct_s8,
788 .ct_u8= pmac_ct_u8,
789 .ct_s16be= pmac_ct_s16,
790 .ct_u16be= pmac_ct_u16,
791 .ct_s16le= pmac_ct_s16,
792 .ct_u16le= pmac_ct_u16,
793};
794
795TRANS transAwacsExpand = {
796 .ct_ulaw= pmac_ctx_law,
797 .ct_alaw= pmac_ctx_law,
798 .ct_s8= pmac_ctx_s8,
799 .ct_u8= pmac_ctx_u8,
800 .ct_s16be= pmac_ctx_s16,
801 .ct_u16be= pmac_ctx_u16,
802 .ct_s16le= pmac_ctx_s16,
803 .ct_u16le= pmac_ctx_u16,
804};
805
806TRANS transAwacsNormalRead = {
807 .ct_s8= pmac_ct_s8_read,
808 .ct_u8= pmac_ct_u8_read,
809 .ct_s16be= pmac_ct_s16_read,
810 .ct_u16be= pmac_ct_u16_read,
811 .ct_s16le= pmac_ct_s16_read,
812 .ct_u16le= pmac_ct_u16_read,
813};
814
815TRANS transAwacsExpandRead = {
816 .ct_s8= pmac_ctx_s8_read,
817 .ct_u8= pmac_ctx_u8_read,
818 .ct_s16be= pmac_ctx_s16_read,
819 .ct_u16be= pmac_ctx_u16_read,
820 .ct_s16le= pmac_ctx_s16_read,
821 .ct_u16le= pmac_ctx_u16_read,
822};
823
824/* translation tables */
825/* 16 bit mu-law */
826
827static short dmasound_ulaw2dma16[] = {
828 -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
829 -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
830 -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
831 -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316,
832 -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
833 -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
834 -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
835 -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
836 -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
837 -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
838 -876, -844, -812, -780, -748, -716, -684, -652,
839 -620, -588, -556, -524, -492, -460, -428, -396,
840 -372, -356, -340, -324, -308, -292, -276, -260,
841 -244, -228, -212, -196, -180, -164, -148, -132,
842 -120, -112, -104, -96, -88, -80, -72, -64,
843 -56, -48, -40, -32, -24, -16, -8, 0,
844 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
845 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
846 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
847 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
848 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
849 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
850 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
851 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
852 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
853 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
854 876, 844, 812, 780, 748, 716, 684, 652,
855 620, 588, 556, 524, 492, 460, 428, 396,
856 372, 356, 340, 324, 308, 292, 276, 260,
857 244, 228, 212, 196, 180, 164, 148, 132,
858 120, 112, 104, 96, 88, 80, 72, 64,
859 56, 48, 40, 32, 24, 16, 8, 0,
860};
861
862/* 16 bit A-law */
863
864static short dmasound_alaw2dma16[] = {
865 -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
866 -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
867 -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
868 -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
869 -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944,
870 -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136,
871 -11008, -10496, -12032, -11520, -8960, -8448, -9984, -9472,
872 -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568,
873 -344, -328, -376, -360, -280, -264, -312, -296,
874 -472, -456, -504, -488, -408, -392, -440, -424,
875 -88, -72, -120, -104, -24, -8, -56, -40,
876 -216, -200, -248, -232, -152, -136, -184, -168,
877 -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
878 -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
879 -688, -656, -752, -720, -560, -528, -624, -592,
880 -944, -912, -1008, -976, -816, -784, -880, -848,
881 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
882 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
883 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
884 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
885 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
886 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
887 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
888 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
889 344, 328, 376, 360, 280, 264, 312, 296,
890 472, 456, 504, 488, 408, 392, 440, 424,
891 88, 72, 120, 104, 24, 8, 56, 40,
892 216, 200, 248, 232, 152, 136, 184, 168,
893 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
894 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
895 688, 656, 752, 720, 560, 528, 624, 592,
896 944, 912, 1008, 976, 816, 784, 880, 848,
897};
diff --git a/sound/oss/emu10k1/8010.h b/sound/oss/emu10k1/8010.h
new file mode 100644
index 000000000000..61c6c42bbc36
--- /dev/null
+++ b/sound/oss/emu10k1/8010.h
@@ -0,0 +1,737 @@
1/*
2 **********************************************************************
3 * 8010.h
4 * Copyright 1999-2001 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox Cleaned of 8bit chars, DOS
12 * line endings
13 * December 8, 1999 Jon Taylor Added lots of new register info
14 * May 16, 2001 Daniel Bertrand Added unofficial DBG register info
15 * Oct-Nov 2001 D.B. Added unofficial Audigy registers
16 *
17 **********************************************************************
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License as
21 * published by the Free Software Foundation; either version 2 of
22 * the License, or (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public
30 * License along with this program; if not, write to the Free
31 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
32 * USA.
33 *
34 *
35 **********************************************************************
36 */
37
38
39#ifndef _8010_H
40#define _8010_H
41
42#include <linux/types.h>
43
44// Driver version:
45#define MAJOR_VER 0
46#define MINOR_VER 20
47#define DRIVER_VERSION "0.20a"
48
49
50// Audigy specify registers are prefixed with 'A_'
51
52/************************************************************************************************/
53/* PCI function 0 registers, address = <val> + PCIBASE0 */
54/************************************************************************************************/
55
56#define PTR 0x00 /* Indexed register set pointer register */
57 /* NOTE: The CHANNELNUM and ADDRESS words can */
58 /* be modified independently of each other. */
59#define PTR_CHANNELNUM_MASK 0x0000003f /* For each per-channel register, indicates the */
60 /* channel number of the register to be */
61 /* accessed. For non per-channel registers the */
62 /* value should be set to zero. */
63#define PTR_ADDRESS_MASK 0x07ff0000 /* Register index */
64
65#define DATA 0x04 /* Indexed register set data register */
66
67#define IPR 0x08 /* Global interrupt pending register */
68 /* Clear pending interrupts by writing a 1 to */
69 /* the relevant bits and zero to the other bits */
70
71/* The next two interrupts are for the midi port on the Audigy Drive (A_MPU1) */
72#define A_IPR_MIDITRANSBUFEMPTY2 0x10000000 /* MIDI UART transmit buffer empty */
73#define A_IPR_MIDIRECVBUFEMPTY2 0x08000000 /* MIDI UART receive buffer empty */
74
75#define IPR_SAMPLERATETRACKER 0x01000000 /* Sample rate tracker lock status change */
76#define IPR_FXDSP 0x00800000 /* Enable FX DSP interrupts */
77#define IPR_FORCEINT 0x00400000 /* Force Sound Blaster interrupt */
78#define IPR_PCIERROR 0x00200000 /* PCI bus error */
79#define IPR_VOLINCR 0x00100000 /* Volume increment button pressed */
80#define IPR_VOLDECR 0x00080000 /* Volume decrement button pressed */
81#define IPR_MUTE 0x00040000 /* Mute button pressed */
82#define IPR_MICBUFFULL 0x00020000 /* Microphone buffer full */
83#define IPR_MICBUFHALFFULL 0x00010000 /* Microphone buffer half full */
84#define IPR_ADCBUFFULL 0x00008000 /* ADC buffer full */
85#define IPR_ADCBUFHALFFULL 0x00004000 /* ADC buffer half full */
86#define IPR_EFXBUFFULL 0x00002000 /* Effects buffer full */
87#define IPR_EFXBUFHALFFULL 0x00001000 /* Effects buffer half full */
88#define IPR_GPSPDIFSTATUSCHANGE 0x00000800 /* GPSPDIF channel status change */
89#define IPR_CDROMSTATUSCHANGE 0x00000400 /* CD-ROM channel status change */
90#define IPR_INTERVALTIMER 0x00000200 /* Interval timer terminal count */
91#define IPR_MIDITRANSBUFEMPTY 0x00000100 /* MIDI UART transmit buffer empty */
92#define IPR_MIDIRECVBUFEMPTY 0x00000080 /* MIDI UART receive buffer empty */
93#define IPR_CHANNELLOOP 0x00000040 /* One or more channel loop interrupts pending */
94#define IPR_CHANNELNUMBERMASK 0x0000003f /* When IPR_CHANNELLOOP is set, indicates the */
95 /* Highest set channel in CLIPL or CLIPH. When */
96 /* IP is written with CL set, the bit in CLIPL */
97 /* or CLIPH corresponding to the CIN value */
98 /* written will be cleared. */
99#define A_IPR_MIDITRANSBUFEMPTY1 IPR_MIDITRANSBUFEMPTY /* MIDI UART transmit buffer empty */
100#define A_IPR_MIDIRECVBUFEMPTY1 IPR_MIDIRECVBUFEMPTY /* MIDI UART receive buffer empty */
101
102
103
104#define INTE 0x0c /* Interrupt enable register */
105#define INTE_VIRTUALSB_MASK 0xc0000000 /* Virtual Soundblaster I/O port capture */
106#define INTE_VIRTUALSB_220 0x00000000 /* Capture at I/O base address 0x220-0x22f */
107#define INTE_VIRTUALSB_240 0x40000000 /* Capture at I/O base address 0x240 */
108#define INTE_VIRTUALSB_260 0x80000000 /* Capture at I/O base address 0x260 */
109#define INTE_VIRTUALSB_280 0xc0000000 /* Capture at I/O base address 0x280 */
110#define INTE_VIRTUALMPU_MASK 0x30000000 /* Virtual MPU I/O port capture */
111#define INTE_VIRTUALMPU_300 0x00000000 /* Capture at I/O base address 0x300-0x301 */
112#define INTE_VIRTUALMPU_310 0x10000000 /* Capture at I/O base address 0x310 */
113#define INTE_VIRTUALMPU_320 0x20000000 /* Capture at I/O base address 0x320 */
114#define INTE_VIRTUALMPU_330 0x30000000 /* Capture at I/O base address 0x330 */
115#define INTE_MASTERDMAENABLE 0x08000000 /* Master DMA emulation at 0x000-0x00f */
116#define INTE_SLAVEDMAENABLE 0x04000000 /* Slave DMA emulation at 0x0c0-0x0df */
117#define INTE_MASTERPICENABLE 0x02000000 /* Master PIC emulation at 0x020-0x021 */
118#define INTE_SLAVEPICENABLE 0x01000000 /* Slave PIC emulation at 0x0a0-0x0a1 */
119#define INTE_VSBENABLE 0x00800000 /* Enable virtual Soundblaster */
120#define INTE_ADLIBENABLE 0x00400000 /* Enable AdLib emulation at 0x388-0x38b */
121#define INTE_MPUENABLE 0x00200000 /* Enable virtual MPU */
122#define INTE_FORCEINT 0x00100000 /* Continuously assert INTAN */
123
124#define INTE_MRHANDENABLE 0x00080000 /* Enable the "Mr. Hand" logic */
125 /* NOTE: There is no reason to use this under */
126 /* Linux, and it will cause odd hardware */
127 /* behavior and possibly random segfaults and */
128 /* lockups if enabled. */
129
130/* The next two interrupts are for the midi port on the Audigy Drive (A_MPU1) */
131#define A_INTE_MIDITXENABLE2 0x00020000 /* Enable MIDI transmit-buffer-empty interrupts */
132#define A_INTE_MIDIRXENABLE2 0x00010000 /* Enable MIDI receive-buffer-empty interrupts */
133
134
135#define INTE_SAMPLERATETRACKER 0x00002000 /* Enable sample rate tracker interrupts */
136 /* NOTE: This bit must always be enabled */
137#define INTE_FXDSPENABLE 0x00001000 /* Enable FX DSP interrupts */
138#define INTE_PCIERRORENABLE 0x00000800 /* Enable PCI bus error interrupts */
139#define INTE_VOLINCRENABLE 0x00000400 /* Enable volume increment button interrupts */
140#define INTE_VOLDECRENABLE 0x00000200 /* Enable volume decrement button interrupts */
141#define INTE_MUTEENABLE 0x00000100 /* Enable mute button interrupts */
142#define INTE_MICBUFENABLE 0x00000080 /* Enable microphone buffer interrupts */
143#define INTE_ADCBUFENABLE 0x00000040 /* Enable ADC buffer interrupts */
144#define INTE_EFXBUFENABLE 0x00000020 /* Enable Effects buffer interrupts */
145#define INTE_GPSPDIFENABLE 0x00000010 /* Enable GPSPDIF status interrupts */
146#define INTE_CDSPDIFENABLE 0x00000008 /* Enable CDSPDIF status interrupts */
147#define INTE_INTERVALTIMERENB 0x00000004 /* Enable interval timer interrupts */
148#define INTE_MIDITXENABLE 0x00000002 /* Enable MIDI transmit-buffer-empty interrupts */
149#define INTE_MIDIRXENABLE 0x00000001 /* Enable MIDI receive-buffer-empty interrupts */
150
151/* The next two interrupts are for the midi port on the Audigy (A_MPU2) */
152#define A_INTE_MIDITXENABLE1 INTE_MIDITXENABLE
153#define A_INTE_MIDIRXENABLE1 INTE_MIDIRXENABLE
154
155#define WC 0x10 /* Wall Clock register */
156#define WC_SAMPLECOUNTER_MASK 0x03FFFFC0 /* Sample periods elapsed since reset */
157#define WC_SAMPLECOUNTER 0x14060010
158#define WC_CURRENTCHANNEL 0x0000003F /* Channel [0..63] currently being serviced */
159 /* NOTE: Each channel takes 1/64th of a sample */
160 /* period to be serviced. */
161
162#define HCFG 0x14 /* Hardware config register */
163 /* NOTE: There is no reason to use the legacy */
164 /* SoundBlaster emulation stuff described below */
165 /* under Linux, and all kinds of weird hardware */
166 /* behavior can result if you try. Don't. */
167#define HCFG_LEGACYFUNC_MASK 0xe0000000 /* Legacy function number */
168#define HCFG_LEGACYFUNC_MPU 0x00000000 /* Legacy MPU */
169#define HCFG_LEGACYFUNC_SB 0x40000000 /* Legacy SB */
170#define HCFG_LEGACYFUNC_AD 0x60000000 /* Legacy AD */
171#define HCFG_LEGACYFUNC_MPIC 0x80000000 /* Legacy MPIC */
172#define HCFG_LEGACYFUNC_MDMA 0xa0000000 /* Legacy MDMA */
173#define HCFG_LEGACYFUNC_SPCI 0xc0000000 /* Legacy SPCI */
174#define HCFG_LEGACYFUNC_SDMA 0xe0000000 /* Legacy SDMA */
175#define HCFG_IOCAPTUREADDR 0x1f000000 /* The 4 LSBs of the captured I/O address. */
176#define HCFG_LEGACYWRITE 0x00800000 /* 1 = write, 0 = read */
177#define HCFG_LEGACYWORD 0x00400000 /* 1 = word, 0 = byte */
178#define HCFG_LEGACYINT 0x00200000 /* 1 = legacy event captured. Write 1 to clear. */
179 /* NOTE: The rest of the bits in this register */
180 /* _are_ relevant under Linux. */
181#define HCFG_CODECFORMAT_MASK 0x00070000 /* CODEC format */
182#define HCFG_CODECFORMAT_AC97 0x00000000 /* AC97 CODEC format -- Primary Output */
183#define HCFG_CODECFORMAT_I2S 0x00010000 /* I2S CODEC format -- Secondary (Rear) Output */
184#define HCFG_GPINPUT0 0x00004000 /* External pin112 */
185#define HCFG_GPINPUT1 0x00002000 /* External pin110 */
186
187#define HCFG_GPOUTPUT_MASK 0x00001c00 /* External pins which may be controlled */
188#define HCFG_GPOUT0 0x00001000 /* set to enable digital out on 5.1 cards */
189
190#define HCFG_JOYENABLE 0x00000200 /* Internal joystick enable */
191#define HCFG_PHASETRACKENABLE 0x00000100 /* Phase tracking enable */
192 /* 1 = Force all 3 async digital inputs to use */
193 /* the same async sample rate tracker (ZVIDEO) */
194#define HCFG_AC3ENABLE_MASK 0x0x0000e0 /* AC3 async input control - Not implemented */
195#define HCFG_AC3ENABLE_ZVIDEO 0x00000080 /* Channels 0 and 1 replace ZVIDEO */
196#define HCFG_AC3ENABLE_CDSPDIF 0x00000040 /* Channels 0 and 1 replace CDSPDIF */
197#define HCFG_AC3ENABLE_GPSPDIF 0x00000020 /* Channels 0 and 1 replace GPSPDIF */
198#define HCFG_AUTOMUTE 0x00000010 /* When set, the async sample rate convertors */
199 /* will automatically mute their output when */
200 /* they are not rate-locked to the external */
201 /* async audio source */
202#define HCFG_LOCKSOUNDCACHE 0x00000008 /* 1 = Cancel bustmaster accesses to soundcache */
203 /* NOTE: This should generally never be used. */
204#define HCFG_LOCKTANKCACHE_MASK 0x00000004 /* 1 = Cancel bustmaster accesses to tankcache */
205 /* NOTE: This should generally never be used. */
206#define HCFG_LOCKTANKCACHE 0x01020014
207#define HCFG_MUTEBUTTONENABLE 0x00000002 /* 1 = Master mute button sets AUDIOENABLE = 0. */
208 /* NOTE: This is a 'cheap' way to implement a */
209 /* master mute function on the mute button, and */
210 /* in general should not be used unless a more */
211 /* sophisticated master mute function has not */
212 /* been written. */
213#define HCFG_AUDIOENABLE 0x00000001 /* 0 = CODECs transmit zero-valued samples */
214 /* Should be set to 1 when the EMU10K1 is */
215 /* completely initialized. */
216
217//For Audigy, MPU port move to 0x70-0x74 ptr register
218
219#define MUDATA 0x18 /* MPU401 data register (8 bits) */
220
221#define MUCMD 0x19 /* MPU401 command register (8 bits) */
222#define MUCMD_RESET 0xff /* RESET command */
223#define MUCMD_ENTERUARTMODE 0x3f /* Enter_UART_mode command */
224 /* NOTE: All other commands are ignored */
225
226#define MUSTAT MUCMD /* MPU401 status register (8 bits) */
227#define MUSTAT_IRDYN 0x80 /* 0 = MIDI data or command ACK */
228#define MUSTAT_ORDYN 0x40 /* 0 = MUDATA can accept a command or data */
229
230#define A_IOCFG 0x18 /* GPIO on Audigy card (16bits) */
231#define A_GPINPUT_MASK 0xff00
232#define A_GPOUTPUT_MASK 0x00ff
233
234#define TIMER 0x1a /* Timer terminal count register (16-bit) */
235 /* NOTE: After the rate is changed, a maximum */
236 /* of 1024 sample periods should be allowed */
237 /* before the new rate is guaranteed accurate. */
238#define TIMER_RATE_MASK 0x03ff /* Timer interrupt rate in sample periods */
239 /* 0 == 1024 periods, [1..4] are not useful */
240
241#define AC97DATA 0x1c /* AC97 register set data register (16 bit) */
242
243#define AC97ADDRESS 0x1e /* AC97 register set address register (8 bit) */
244#define AC97ADDRESS_READY 0x80 /* Read-only bit, reflects CODEC READY signal */
245#define AC97ADDRESS_ADDRESS 0x7f /* Address of indexed AC97 register */
246
247/********************************************************************************************************/
248/* Emu10k1 pointer-offset register set, accessed through the PTR and DATA registers */
249/********************************************************************************************************/
250
251#define CPF 0x00 /* Current pitch and fraction register */
252#define CPF_CURRENTPITCH_MASK 0xffff0000 /* Current pitch (linear, 0x4000 == unity pitch shift) */
253#define CPF_CURRENTPITCH 0x10100000
254#define CPF_STEREO_MASK 0x00008000 /* 1 = Even channel interleave, odd channel locked */
255#define CPF_STOP_MASK 0x00004000 /* 1 = Current pitch forced to 0 */
256#define CPF_FRACADDRESS_MASK 0x00003fff /* Linear fractional address of the current channel */
257
258#define PTRX 0x01 /* Pitch target and send A/B amounts register */
259#define PTRX_PITCHTARGET_MASK 0xffff0000 /* Pitch target of specified channel */
260#define PTRX_PITCHTARGET 0x10100001
261#define PTRX_FXSENDAMOUNT_A_MASK 0x0000ff00 /* Linear level of channel output sent to FX send bus A */
262#define PTRX_FXSENDAMOUNT_A 0x08080001
263#define PTRX_FXSENDAMOUNT_B_MASK 0x000000ff /* Linear level of channel output sent to FX send bus B */
264#define PTRX_FXSENDAMOUNT_B 0x08000001
265
266#define CVCF 0x02 /* Current volume and filter cutoff register */
267#define CVCF_CURRENTVOL_MASK 0xffff0000 /* Current linear volume of specified channel */
268#define CVCF_CURRENTVOL 0x10100002
269#define CVCF_CURRENTFILTER_MASK 0x0000ffff /* Current filter cutoff frequency of specified channel */
270#define CVCF_CURRENTFILTER 0x10000002
271
272#define VTFT 0x03 /* Volume target and filter cutoff target register */
273#define VTFT_VOLUMETARGET_MASK 0xffff0000 /* Volume target of specified channel */
274#define VTFT_FILTERTARGET_MASK 0x0000ffff /* Filter cutoff target of specified channel */
275
276#define Z1 0x05 /* Filter delay memory 1 register */
277
278#define Z2 0x04 /* Filter delay memory 2 register */
279
280#define PSST 0x06 /* Send C amount and loop start address register */
281#define PSST_FXSENDAMOUNT_C_MASK 0xff000000 /* Linear level of channel output sent to FX send bus C */
282
283#define PSST_FXSENDAMOUNT_C 0x08180006
284
285#define PSST_LOOPSTARTADDR_MASK 0x00ffffff /* Loop start address of the specified channel */
286#define PSST_LOOPSTARTADDR 0x18000006
287
288#define DSL 0x07 /* Send D amount and loop start address register */
289#define DSL_FXSENDAMOUNT_D_MASK 0xff000000 /* Linear level of channel output sent to FX send bus D */
290
291#define DSL_FXSENDAMOUNT_D 0x08180007
292
293#define DSL_LOOPENDADDR_MASK 0x00ffffff /* Loop end address of the specified channel */
294#define DSL_LOOPENDADDR 0x18000007
295
296#define CCCA 0x08 /* Filter Q, interp. ROM, byte size, cur. addr register */
297#define CCCA_RESONANCE 0xf0000000 /* Lowpass filter resonance (Q) height */
298#define CCCA_INTERPROMMASK 0x0e000000 /* Selects passband of interpolation ROM */
299 /* 1 == full band, 7 == lowpass */
300 /* ROM 0 is used when pitch shifting downward or less */
301 /* then 3 semitones upward. Increasingly higher ROM */
302 /* numbers are used, typically in steps of 3 semitones, */
303 /* as upward pitch shifting is performed. */
304#define CCCA_INTERPROM_0 0x00000000 /* Select interpolation ROM 0 */
305#define CCCA_INTERPROM_1 0x02000000 /* Select interpolation ROM 1 */
306#define CCCA_INTERPROM_2 0x04000000 /* Select interpolation ROM 2 */
307#define CCCA_INTERPROM_3 0x06000000 /* Select interpolation ROM 3 */
308#define CCCA_INTERPROM_4 0x08000000 /* Select interpolation ROM 4 */
309#define CCCA_INTERPROM_5 0x0a000000 /* Select interpolation ROM 5 */
310#define CCCA_INTERPROM_6 0x0c000000 /* Select interpolation ROM 6 */
311#define CCCA_INTERPROM_7 0x0e000000 /* Select interpolation ROM 7 */
312#define CCCA_8BITSELECT 0x01000000 /* 1 = Sound memory for this channel uses 8-bit samples */
313#define CCCA_CURRADDR_MASK 0x00ffffff /* Current address of the selected channel */
314#define CCCA_CURRADDR 0x18000008
315
316#define CCR 0x09 /* Cache control register */
317#define CCR_CACHEINVALIDSIZE 0x07190009
318#define CCR_CACHEINVALIDSIZE_MASK 0xfe000000 /* Number of invalid samples cache for this channel */
319#define CCR_CACHELOOPFLAG 0x01000000 /* 1 = Cache has a loop service pending */
320#define CCR_INTERLEAVEDSAMPLES 0x00800000 /* 1 = A cache service will fetch interleaved samples */
321#define CCR_WORDSIZEDSAMPLES 0x00400000 /* 1 = A cache service will fetch word sized samples */
322#define CCR_READADDRESS 0x06100009
323#define CCR_READADDRESS_MASK 0x003f0000 /* Location of cache just beyond current cache service */
324#define CCR_LOOPINVALSIZE 0x0000fe00 /* Number of invalid samples in cache prior to loop */
325 /* NOTE: This is valid only if CACHELOOPFLAG is set */
326#define CCR_LOOPFLAG 0x00000100 /* Set for a single sample period when a loop occurs */
327#define CCR_CACHELOOPADDRHI 0x000000ff /* DSL_LOOPSTARTADDR's hi byte if CACHELOOPFLAG is set */
328
329#define CLP 0x0a /* Cache loop register (valid if CCR_CACHELOOPFLAG = 1) */
330 /* NOTE: This register is normally not used */
331#define CLP_CACHELOOPADDR 0x0000ffff /* Cache loop address (DSL_LOOPSTARTADDR [0..15]) */
332
333#define FXRT 0x0b /* Effects send routing register */
334 /* NOTE: It is illegal to assign the same routing to */
335 /* two effects sends. */
336#define FXRT_CHANNELA 0x000f0000 /* Effects send bus number for channel's effects send A */
337#define FXRT_CHANNELB 0x00f00000 /* Effects send bus number for channel's effects send B */
338#define FXRT_CHANNELC 0x0f000000 /* Effects send bus number for channel's effects send C */
339#define FXRT_CHANNELD 0xf0000000 /* Effects send bus number for channel's effects send D */
340
341#define MAPA 0x0c /* Cache map A */
342
343#define MAPB 0x0d /* Cache map B */
344
345#define MAP_PTE_MASK 0xffffe000 /* The 19 MSBs of the PTE indexed by the PTI */
346#define MAP_PTI_MASK 0x00001fff /* The 13 bit index to one of the 8192 PTE dwords */
347
348#define ENVVOL 0x10 /* Volume envelope register */
349#define ENVVOL_MASK 0x0000ffff /* Current value of volume envelope state variable */
350 /* 0x8000-n == 666*n usec delay */
351
352#define ATKHLDV 0x11 /* Volume envelope hold and attack register */
353#define ATKHLDV_PHASE0 0x00008000 /* 0 = Begin attack phase */
354#define ATKHLDV_HOLDTIME_MASK 0x00007f00 /* Envelope hold time (127-n == n*88.2msec) */
355#define ATKHLDV_ATTACKTIME_MASK 0x0000007f /* Envelope attack time, log encoded */
356 /* 0 = infinite, 1 = 10.9msec, ... 0x7f = 5.5msec */
357
358#define DCYSUSV 0x12 /* Volume envelope sustain and decay register */
359#define DCYSUSV_PHASE1_MASK 0x00008000 /* 0 = Begin attack phase, 1 = begin release phase */
360#define DCYSUSV_SUSTAINLEVEL_MASK 0x00007f00 /* 127 = full, 0 = off, 0.75dB increments */
361#define DCYSUSV_CHANNELENABLE_MASK 0x00000080 /* 1 = Inhibit envelope engine from writing values in */
362 /* this channel and from writing to pitch, filter and */
363 /* volume targets. */
364#define DCYSUSV_DECAYTIME_MASK 0x0000007f /* Volume envelope decay time, log encoded */
365 /* 0 = 43.7msec, 1 = 21.8msec, 0x7f = 22msec */
366
367#define LFOVAL1 0x13 /* Modulation LFO value */
368#define LFOVAL_MASK 0x0000ffff /* Current value of modulation LFO state variable */
369 /* 0x8000-n == 666*n usec delay */
370
371#define ENVVAL 0x14 /* Modulation envelope register */
372#define ENVVAL_MASK 0x0000ffff /* Current value of modulation envelope state variable */
373 /* 0x8000-n == 666*n usec delay */
374
375#define ATKHLDM 0x15 /* Modulation envelope hold and attack register */
376#define ATKHLDM_PHASE0 0x00008000 /* 0 = Begin attack phase */
377#define ATKHLDM_HOLDTIME 0x00007f00 /* Envelope hold time (127-n == n*42msec) */
378#define ATKHLDM_ATTACKTIME 0x0000007f /* Envelope attack time, log encoded */
379 /* 0 = infinite, 1 = 11msec, ... 0x7f = 5.5msec */
380
381#define DCYSUSM 0x16 /* Modulation envelope decay and sustain register */
382#define DCYSUSM_PHASE1_MASK 0x00008000 /* 0 = Begin attack phase, 1 = begin release phase */
383#define DCYSUSM_SUSTAINLEVEL_MASK 0x00007f00 /* 127 = full, 0 = off, 0.75dB increments */
384#define DCYSUSM_DECAYTIME_MASK 0x0000007f /* Envelope decay time, log encoded */
385 /* 0 = 43.7msec, 1 = 21.8msec, 0x7f = 22msec */
386
387#define LFOVAL2 0x17 /* Vibrato LFO register */
388#define LFOVAL2_MASK 0x0000ffff /* Current value of vibrato LFO state variable */
389 /* 0x8000-n == 666*n usec delay */
390
391#define IP 0x18 /* Initial pitch register */
392#define IP_MASK 0x0000ffff /* Exponential initial pitch shift */
393 /* 4 bits of octave, 12 bits of fractional octave */
394#define IP_UNITY 0x0000e000 /* Unity pitch shift */
395
396#define IFATN 0x19 /* Initial filter cutoff and attenuation register */
397#define IFATN_FILTERCUTOFF_MASK 0x0000ff00 /* Initial filter cutoff frequency in exponential units */
398 /* 6 most significant bits are semitones */
399 /* 2 least significant bits are fractions */
400#define IFATN_FILTERCUTOFF 0x08080019
401#define IFATN_ATTENUATION_MASK 0x000000ff /* Initial attenuation in 0.375dB steps */
402#define IFATN_ATTENUATION 0x08000019
403
404
405#define PEFE 0x1a /* Pitch envelope and filter envelope amount register */
406#define PEFE_PITCHAMOUNT_MASK 0x0000ff00 /* Pitch envlope amount */
407 /* Signed 2's complement, +/- one octave peak extremes */
408#define PEFE_PITCHAMOUNT 0x0808001a
409#define PEFE_FILTERAMOUNT_MASK 0x000000ff /* Filter envlope amount */
410 /* Signed 2's complement, +/- six octaves peak extremes */
411#define PEFE_FILTERAMOUNT 0x0800001a
412#define FMMOD 0x1b /* Vibrato/filter modulation from LFO register */
413#define FMMOD_MODVIBRATO 0x0000ff00 /* Vibrato LFO modulation depth */
414 /* Signed 2's complement, +/- one octave extremes */
415#define FMMOD_MOFILTER 0x000000ff /* Filter LFO modulation depth */
416 /* Signed 2's complement, +/- three octave extremes */
417
418
419#define TREMFRQ 0x1c /* Tremolo amount and modulation LFO frequency register */
420#define TREMFRQ_DEPTH 0x0000ff00 /* Tremolo depth */
421 /* Signed 2's complement, with +/- 12dB extremes */
422#define TREMFRQ_FREQUENCY 0x000000ff /* Tremolo LFO frequency */
423 /* ??Hz steps, maximum of ?? Hz. */
424
425#define FM2FRQ2 0x1d /* Vibrato amount and vibrato LFO frequency register */
426#define FM2FRQ2_DEPTH 0x0000ff00 /* Vibrato LFO vibrato depth */
427 /* Signed 2's complement, +/- one octave extremes */
428#define FM2FRQ2_FREQUENCY 0x000000ff /* Vibrato LFO frequency */
429 /* 0.039Hz steps, maximum of 9.85 Hz. */
430
431#define TEMPENV 0x1e /* Tempory envelope register */
432#define TEMPENV_MASK 0x0000ffff /* 16-bit value */
433 /* NOTE: All channels contain internal variables; do */
434 /* not write to these locations. */
435
436#define CD0 0x20 /* Cache data 0 register */
437#define CD1 0x21 /* Cache data 1 register */
438#define CD2 0x22 /* Cache data 2 register */
439#define CD3 0x23 /* Cache data 3 register */
440#define CD4 0x24 /* Cache data 4 register */
441#define CD5 0x25 /* Cache data 5 register */
442#define CD6 0x26 /* Cache data 6 register */
443#define CD7 0x27 /* Cache data 7 register */
444#define CD8 0x28 /* Cache data 8 register */
445#define CD9 0x29 /* Cache data 9 register */
446#define CDA 0x2a /* Cache data A register */
447#define CDB 0x2b /* Cache data B register */
448#define CDC 0x2c /* Cache data C register */
449#define CDD 0x2d /* Cache data D register */
450#define CDE 0x2e /* Cache data E register */
451#define CDF 0x2f /* Cache data F register */
452
453#define PTB 0x40 /* Page table base register */
454#define PTB_MASK 0xfffff000 /* Physical address of the page table in host memory */
455
456#define TCB 0x41 /* Tank cache base register */
457#define TCB_MASK 0xfffff000 /* Physical address of the bottom of host based TRAM */
458
459#define ADCCR 0x42 /* ADC sample rate/stereo control register */
460#define ADCCR_RCHANENABLE 0x00000010 /* Enables right channel for writing to the host */
461#define ADCCR_LCHANENABLE 0x00000008 /* Enables left channel for writing to the host */
462 /* NOTE: To guarantee phase coherency, both channels */
463 /* must be disabled prior to enabling both channels. */
464#define A_ADCCR_RCHANENABLE 0x00000020
465#define A_ADCCR_LCHANENABLE 0x00000010
466
467#define A_ADCCR_SAMPLERATE_MASK 0x0000000F /* Audigy sample rate convertor output rate */
468#define ADCCR_SAMPLERATE_MASK 0x00000007 /* Sample rate convertor output rate */
469
470#define ADCCR_SAMPLERATE_48 0x00000000 /* 48kHz sample rate */
471#define ADCCR_SAMPLERATE_44 0x00000001 /* 44.1kHz sample rate */
472#define ADCCR_SAMPLERATE_32 0x00000002 /* 32kHz sample rate */
473#define ADCCR_SAMPLERATE_24 0x00000003 /* 24kHz sample rate */
474#define ADCCR_SAMPLERATE_22 0x00000004 /* 22.05kHz sample rate */
475#define ADCCR_SAMPLERATE_16 0x00000005 /* 16kHz sample rate */
476#define ADCCR_SAMPLERATE_11 0x00000006 /* 11.025kHz sample rate */
477#define ADCCR_SAMPLERATE_8 0x00000007 /* 8kHz sample rate */
478
479#define A_ADCCR_SAMPLERATE_12 0x00000006 /* 12kHz sample rate */
480#define A_ADCCR_SAMPLERATE_11 0x00000007 /* 11.025kHz sample rate */
481#define A_ADCCR_SAMPLERATE_8 0x00000008 /* 8kHz sample rate */
482
483#define FXWC 0x43 /* FX output write channels register */
484 /* When set, each bit enables the writing of the */
485 /* corresponding FX output channel (internal registers */
486 /* 0x20-0x3f) into host memory. This mode of recording */
487 /* is 16bit, 48KHz only. All 32 channels can be enabled */
488 /* simultaneously. */
489#define TCBS 0x44 /* Tank cache buffer size register */
490#define TCBS_MASK 0x00000007 /* Tank cache buffer size field */
491#define TCBS_BUFFSIZE_16K 0x00000000
492#define TCBS_BUFFSIZE_32K 0x00000001
493#define TCBS_BUFFSIZE_64K 0x00000002
494#define TCBS_BUFFSIZE_128K 0x00000003
495#define TCBS_BUFFSIZE_256K 0x00000004
496#define TCBS_BUFFSIZE_512K 0x00000005
497#define TCBS_BUFFSIZE_1024K 0x00000006
498#define TCBS_BUFFSIZE_2048K 0x00000007
499
500#define MICBA 0x45 /* AC97 microphone buffer address register */
501#define MICBA_MASK 0xfffff000 /* 20 bit base address */
502
503#define ADCBA 0x46 /* ADC buffer address register */
504#define ADCBA_MASK 0xfffff000 /* 20 bit base address */
505
506#define FXBA 0x47 /* FX Buffer Address */
507#define FXBA_MASK 0xfffff000 /* 20 bit base address */
508
509#define MICBS 0x49 /* Microphone buffer size register */
510
511#define ADCBS 0x4a /* ADC buffer size register */
512
513#define FXBS 0x4b /* FX buffer size register */
514
515/* The following mask values define the size of the ADC, MIX and FX buffers in bytes */
516#define ADCBS_BUFSIZE_NONE 0x00000000
517#define ADCBS_BUFSIZE_384 0x00000001
518#define ADCBS_BUFSIZE_448 0x00000002
519#define ADCBS_BUFSIZE_512 0x00000003
520#define ADCBS_BUFSIZE_640 0x00000004
521#define ADCBS_BUFSIZE_768 0x00000005
522#define ADCBS_BUFSIZE_896 0x00000006
523#define ADCBS_BUFSIZE_1024 0x00000007
524#define ADCBS_BUFSIZE_1280 0x00000008
525#define ADCBS_BUFSIZE_1536 0x00000009
526#define ADCBS_BUFSIZE_1792 0x0000000a
527#define ADCBS_BUFSIZE_2048 0x0000000b
528#define ADCBS_BUFSIZE_2560 0x0000000c
529#define ADCBS_BUFSIZE_3072 0x0000000d
530#define ADCBS_BUFSIZE_3584 0x0000000e
531#define ADCBS_BUFSIZE_4096 0x0000000f
532#define ADCBS_BUFSIZE_5120 0x00000010
533#define ADCBS_BUFSIZE_6144 0x00000011
534#define ADCBS_BUFSIZE_7168 0x00000012
535#define ADCBS_BUFSIZE_8192 0x00000013
536#define ADCBS_BUFSIZE_10240 0x00000014
537#define ADCBS_BUFSIZE_12288 0x00000015
538#define ADCBS_BUFSIZE_14366 0x00000016
539#define ADCBS_BUFSIZE_16384 0x00000017
540#define ADCBS_BUFSIZE_20480 0x00000018
541#define ADCBS_BUFSIZE_24576 0x00000019
542#define ADCBS_BUFSIZE_28672 0x0000001a
543#define ADCBS_BUFSIZE_32768 0x0000001b
544#define ADCBS_BUFSIZE_40960 0x0000001c
545#define ADCBS_BUFSIZE_49152 0x0000001d
546#define ADCBS_BUFSIZE_57344 0x0000001e
547#define ADCBS_BUFSIZE_65536 0x0000001f
548
549
550#define CDCS 0x50 /* CD-ROM digital channel status register */
551
552#define GPSCS 0x51 /* General Purpose SPDIF channel status register*/
553
554#define DBG 0x52 /* DO NOT PROGRAM THIS REGISTER!!! MAY DESTROY CHIP */
555
556/* definitions for debug register - taken from the alsa drivers */
557#define DBG_ZC 0x80000000 /* zero tram counter */
558#define DBG_SATURATION_OCCURED 0x02000000 /* saturation control */
559#define DBG_SATURATION_ADDR 0x01ff0000 /* saturation address */
560#define DBG_SINGLE_STEP 0x00008000 /* single step mode */
561#define DBG_STEP 0x00004000 /* start single step */
562#define DBG_CONDITION_CODE 0x00003e00 /* condition code */
563#define DBG_SINGLE_STEP_ADDR 0x000001ff /* single step address */
564
565
566#define REG53 0x53 /* DO NOT PROGRAM THIS REGISTER!!! MAY DESTROY CHIP */
567
568#define A_DBG 0x53
569#define A_DBG_SINGLE_STEP 0x00020000 /* Set to zero to start dsp */
570#define A_DBG_ZC 0x40000000 /* zero tram counter */
571#define A_DBG_STEP_ADDR 0x000003ff
572#define A_DBG_SATURATION_OCCURED 0x20000000
573#define A_DBG_SATURATION_ADDR 0x0ffc0000
574
575#define SPCS0 0x54 /* SPDIF output Channel Status 0 register */
576
577#define SPCS1 0x55 /* SPDIF output Channel Status 1 register */
578
579#define SPCS2 0x56 /* SPDIF output Channel Status 2 register */
580
581#define SPCS_CLKACCYMASK 0x30000000 /* Clock accuracy */
582#define SPCS_CLKACCY_1000PPM 0x00000000 /* 1000 parts per million */
583#define SPCS_CLKACCY_50PPM 0x10000000 /* 50 parts per million */
584#define SPCS_CLKACCY_VARIABLE 0x20000000 /* Variable accuracy */
585#define SPCS_SAMPLERATEMASK 0x0f000000 /* Sample rate */
586#define SPCS_SAMPLERATE_44 0x00000000 /* 44.1kHz sample rate */
587#define SPCS_SAMPLERATE_48 0x02000000 /* 48kHz sample rate */
588#define SPCS_SAMPLERATE_32 0x03000000 /* 32kHz sample rate */
589#define SPCS_CHANNELNUMMASK 0x00f00000 /* Channel number */
590#define SPCS_CHANNELNUM_UNSPEC 0x00000000 /* Unspecified channel number */
591#define SPCS_CHANNELNUM_LEFT 0x00100000 /* Left channel */
592#define SPCS_CHANNELNUM_RIGHT 0x00200000 /* Right channel */
593#define SPCS_SOURCENUMMASK 0x000f0000 /* Source number */
594#define SPCS_SOURCENUM_UNSPEC 0x00000000 /* Unspecified source number */
595#define SPCS_GENERATIONSTATUS 0x00008000 /* Originality flag (see IEC-958 spec) */
596#define SPCS_CATEGORYCODEMASK 0x00007f00 /* Category code (see IEC-958 spec) */
597#define SPCS_MODEMASK 0x000000c0 /* Mode (see IEC-958 spec) */
598#define SPCS_EMPHASISMASK 0x00000038 /* Emphasis */
599#define SPCS_EMPHASIS_NONE 0x00000000 /* No emphasis */
600#define SPCS_EMPHASIS_50_15 0x00000008 /* 50/15 usec 2 channel */
601#define SPCS_COPYRIGHT 0x00000004 /* Copyright asserted flag -- do not modify */
602#define SPCS_NOTAUDIODATA 0x00000002 /* 0 = Digital audio, 1 = not audio */
603#define SPCS_PROFESSIONAL 0x00000001 /* 0 = Consumer (IEC-958), 1 = pro (AES3-1992) */
604
605/* The 32-bit CLIx and SOLx registers all have one bit per channel control/status */
606#define CLIEL 0x58 /* Channel loop interrupt enable low register */
607
608#define CLIEH 0x59 /* Channel loop interrupt enable high register */
609
610#define CLIPL 0x5a /* Channel loop interrupt pending low register */
611
612#define CLIPH 0x5b /* Channel loop interrupt pending high register */
613
614#define SOLEL 0x5c /* Stop on loop enable low register */
615
616#define SOLEH 0x5d /* Stop on loop enable high register */
617
618#define SPBYPASS 0x5e /* SPDIF BYPASS mode register */
619#define SPBYPASS_ENABLE 0x00000001 /* Enable SPDIF bypass mode */
620
621#define AC97SLOT 0x5f /* additional AC97 slots enable bits */
622#define AC97SLOT_CNTR 0x10 /* Center enable */
623#define AC97SLOT_LFE 0x20 /* LFE enable */
624
625#define CDSRCS 0x60 /* CD-ROM Sample Rate Converter status register */
626
627#define GPSRCS 0x61 /* General Purpose SPDIF sample rate cvt status */
628
629#define ZVSRCS 0x62 /* ZVideo sample rate converter status */
630 /* NOTE: This one has no SPDIFLOCKED field */
631 /* Assumes sample lock */
632
633/* These three bitfields apply to CDSRCS, GPSRCS, and (except as noted) ZVSRCS. */
634#define SRCS_SPDIFLOCKED 0x02000000 /* SPDIF stream locked */
635#define SRCS_RATELOCKED 0x01000000 /* Sample rate locked */
636#define SRCS_ESTSAMPLERATE 0x0007ffff /* Do not modify this field. */
637
638
639/* Note that these values can vary +/- by a small amount */
640#define SRCS_SPDIFRATE_44 0x0003acd9
641#define SRCS_SPDIFRATE_48 0x00040000
642#define SRCS_SPDIFRATE_96 0x00080000
643
644#define MICIDX 0x63 /* Microphone recording buffer index register */
645#define MICIDX_MASK 0x0000ffff /* 16-bit value */
646#define MICIDX_IDX 0x10000063
647
648#define A_ADCIDX 0x63
649#define A_ADCIDX_IDX 0x10000063
650
651#define ADCIDX 0x64 /* ADC recording buffer index register */
652#define ADCIDX_MASK 0x0000ffff /* 16 bit index field */
653#define ADCIDX_IDX 0x10000064
654
655#define FXIDX 0x65 /* FX recording buffer index register */
656#define FXIDX_MASK 0x0000ffff /* 16-bit value */
657#define FXIDX_IDX 0x10000065
658
659/* This is the MPU port on the card (via the game port) */
660#define A_MUDATA1 0x70
661#define A_MUCMD1 0x71
662#define A_MUSTAT1 A_MUCMD1
663
664/* This is the MPU port on the Audigy Drive */
665#define A_MUDATA2 0x72
666#define A_MUCMD2 0x73
667#define A_MUSTAT2 A_MUCMD2
668
669/* The next two are the Audigy equivalent of FXWC */
670/* the Audigy can record any output (16bit, 48kHz, up to 64 channel simultaneously) */
671/* Each bit selects a channel for recording */
672#define A_FXWC1 0x74 /* Selects 0x7f-0x60 for FX recording */
673#define A_FXWC2 0x75 /* Selects 0x9f-0x80 for FX recording */
674
675#define A_SPDIF_SAMPLERATE 0x76 /* Set the sample rate of SPDIF output */
676#define A_SPDIF_48000 0x00000080
677#define A_SPDIF_44100 0x00000000
678#define A_SPDIF_96000 0x00000040
679
680#define A_FXRT2 0x7c
681#define A_FXRT_CHANNELE 0x0000003f /* Effects send bus number for channel's effects send E */
682#define A_FXRT_CHANNELF 0x00003f00 /* Effects send bus number for channel's effects send F */
683#define A_FXRT_CHANNELG 0x003f0000 /* Effects send bus number for channel's effects send G */
684#define A_FXRT_CHANNELH 0x3f000000 /* Effects send bus number for channel's effects send H */
685
686#define A_SENDAMOUNTS 0x7d
687#define A_FXSENDAMOUNT_E_MASK 0xff000000
688#define A_FXSENDAMOUNT_F_MASK 0x00ff0000
689#define A_FXSENDAMOUNT_G_MASK 0x0000ff00
690#define A_FXSENDAMOUNT_H_MASK 0x000000ff
691
692/* The send amounts for this one are the same as used with the emu10k1 */
693#define A_FXRT1 0x7e
694#define A_FXRT_CHANNELA 0x0000003f
695#define A_FXRT_CHANNELB 0x00003f00
696#define A_FXRT_CHANNELC 0x003f0000
697#define A_FXRT_CHANNELD 0x3f000000
698
699
700/* Each FX general purpose register is 32 bits in length, all bits are used */
701#define FXGPREGBASE 0x100 /* FX general purpose registers base */
702#define A_FXGPREGBASE 0x400 /* Audigy GPRs, 0x400 to 0x5ff */
703/* Tank audio data is logarithmically compressed down to 16 bits before writing to TRAM and is */
704/* decompressed back to 20 bits on a read. There are a total of 160 locations, the last 32 */
705/* locations are for external TRAM. */
706#define TANKMEMDATAREGBASE 0x200 /* Tank memory data registers base */
707#define TANKMEMDATAREG_MASK 0x000fffff /* 20 bit tank audio data field */
708
709/* Combined address field and memory opcode or flag field. 160 locations, last 32 are external */
710#define TANKMEMADDRREGBASE 0x300 /* Tank memory address registers base */
711#define TANKMEMADDRREG_ADDR_MASK 0x000fffff /* 20 bit tank address field */
712#define TANKMEMADDRREG_CLEAR 0x00800000 /* Clear tank memory */
713#define TANKMEMADDRREG_ALIGN 0x00400000 /* Align read or write relative to tank access */
714#define TANKMEMADDRREG_WRITE 0x00200000 /* Write to tank memory */
715#define TANKMEMADDRREG_READ 0x00100000 /* Read from tank memory */
716
717#define MICROCODEBASE 0x400 /* Microcode data base address */
718
719/* Each DSP microcode instruction is mapped into 2 doublewords */
720/* NOTE: When writing, always write the LO doubleword first. Reads can be in either order. */
721#define LOWORD_OPX_MASK 0x000ffc00 /* Instruction operand X */
722#define LOWORD_OPY_MASK 0x000003ff /* Instruction operand Y */
723#define HIWORD_OPCODE_MASK 0x00f00000 /* Instruction opcode */
724#define HIWORD_RESULT_MASK 0x000ffc00 /* Instruction result */
725#define HIWORD_OPA_MASK 0x000003ff /* Instruction operand A */
726
727
728/* Audigy Soundcard have a different instruction format */
729#define AUDIGY_CODEBASE 0x600
730#define A_LOWORD_OPY_MASK 0x000007ff
731#define A_LOWORD_OPX_MASK 0x007ff000
732#define A_HIWORD_OPCODE_MASK 0x0f000000
733#define A_HIWORD_RESULT_MASK 0x007ff000
734#define A_HIWORD_OPA_MASK 0x000007ff
735
736
737#endif /* _8010_H */
diff --git a/sound/oss/emu10k1/Makefile b/sound/oss/emu10k1/Makefile
new file mode 100644
index 000000000000..b3af9ccb0579
--- /dev/null
+++ b/sound/oss/emu10k1/Makefile
@@ -0,0 +1,17 @@
1# Makefile for Creative Labs EMU10K1
2#
3# 12 Apr 2000 Rui Sousa
4
5obj-$(CONFIG_SOUND_EMU10K1) += emu10k1.o
6
7emu10k1-objs := audio.o cardmi.o cardmo.o cardwi.o cardwo.o ecard.o \
8 efxmgr.o emuadxmg.o hwaccess.o irqmgr.o main.o midi.o \
9 mixer.o passthrough.o recmgr.o timer.o voicemgr.o
10
11ifdef DEBUG
12 EXTRA_CFLAGS += -DEMU10K1_DEBUG
13endif
14
15ifdef CONFIG_MIDI_EMU10K1
16 EXTRA_CFLAGS += -DEMU10K1_SEQUENCER
17endif
diff --git a/sound/oss/emu10k1/audio.c b/sound/oss/emu10k1/audio.c
new file mode 100644
index 000000000000..cde4d59d5430
--- /dev/null
+++ b/sound/oss/emu10k1/audio.c
@@ -0,0 +1,1588 @@
1/*
2 **********************************************************************
3 * audio.c -- /dev/dsp interface for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox cleaned up types/leaks
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#include <linux/module.h>
34#include <linux/poll.h>
35#include <linux/slab.h>
36#include <linux/bitops.h>
37#include <asm/io.h>
38#include <linux/sched.h>
39#include <linux/smp_lock.h>
40
41#include "hwaccess.h"
42#include "cardwo.h"
43#include "cardwi.h"
44#include "recmgr.h"
45#include "irqmgr.h"
46#include "audio.h"
47#include "8010.h"
48
49static void calculate_ofrag(struct woinst *);
50static void calculate_ifrag(struct wiinst *);
51
52static void emu10k1_waveout_bh(unsigned long refdata);
53static void emu10k1_wavein_bh(unsigned long refdata);
54
55/* Audio file operations */
56static ssize_t emu10k1_audio_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
57{
58 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
59 struct wiinst *wiinst = wave_dev->wiinst;
60 ssize_t ret = 0;
61 unsigned long flags;
62
63 DPD(3, "emu10k1_audio_read(), buffer=%p, count=%d\n", buffer, (u32) count);
64
65 if (!access_ok(VERIFY_WRITE, buffer, count))
66 return -EFAULT;
67
68 spin_lock_irqsave(&wiinst->lock, flags);
69
70 if (wiinst->mmapped) {
71 spin_unlock_irqrestore(&wiinst->lock, flags);
72 return -ENXIO;
73 }
74
75 if (wiinst->state == WAVE_STATE_CLOSED) {
76 calculate_ifrag(wiinst);
77
78 while (emu10k1_wavein_open(wave_dev) < 0) {
79 spin_unlock_irqrestore(&wiinst->lock, flags);
80
81 if (file->f_flags & O_NONBLOCK)
82 return -EAGAIN;
83
84 interruptible_sleep_on(&wave_dev->card->open_wait);
85
86 if (signal_pending(current))
87 return -ERESTARTSYS;
88
89 spin_lock_irqsave(&wiinst->lock, flags);
90 }
91 }
92
93 spin_unlock_irqrestore(&wiinst->lock, flags);
94
95 while (count > 0) {
96 u32 bytestocopy;
97
98 spin_lock_irqsave(&wiinst->lock, flags);
99
100 if (!(wiinst->state & WAVE_STATE_STARTED)
101 && (wave_dev->enablebits & PCM_ENABLE_INPUT))
102 emu10k1_wavein_start(wave_dev);
103
104 emu10k1_wavein_update(wave_dev->card, wiinst);
105 emu10k1_wavein_getxfersize(wiinst, &bytestocopy);
106
107 spin_unlock_irqrestore(&wiinst->lock, flags);
108
109 DPD(3, "bytestocopy --> %d\n", bytestocopy);
110
111 if ((bytestocopy >= wiinst->buffer.fragment_size)
112 || (bytestocopy >= count)) {
113 bytestocopy = min_t(u32, bytestocopy, count);
114
115 emu10k1_wavein_xferdata(wiinst, (u8 __user *)buffer, &bytestocopy);
116
117 count -= bytestocopy;
118 buffer += bytestocopy;
119 ret += bytestocopy;
120 }
121
122 if (count > 0) {
123 if ((file->f_flags & O_NONBLOCK)
124 || (!(wave_dev->enablebits & PCM_ENABLE_INPUT)))
125 return (ret ? ret : -EAGAIN);
126
127 interruptible_sleep_on(&wiinst->wait_queue);
128
129 if (signal_pending(current))
130 return (ret ? ret : -ERESTARTSYS);
131
132 }
133 }
134
135 DPD(3, "bytes copied -> %d\n", (u32) ret);
136
137 return ret;
138}
139
140static ssize_t emu10k1_audio_write(struct file *file, const char __user *buffer, size_t count, loff_t * ppos)
141{
142 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
143 struct woinst *woinst = wave_dev->woinst;
144 ssize_t ret;
145 unsigned long flags;
146
147 DPD(3, "emu10k1_audio_write(), buffer=%p, count=%d\n", buffer, (u32) count);
148
149 if (!access_ok(VERIFY_READ, buffer, count))
150 return -EFAULT;
151
152 spin_lock_irqsave(&woinst->lock, flags);
153
154 if (woinst->mmapped) {
155 spin_unlock_irqrestore(&woinst->lock, flags);
156 return -ENXIO;
157 }
158 // This is for emu10k1 revs less than 7, we need to go through tram
159 if (woinst->format.passthrough == 1) {
160 int r;
161
162 woinst->buffer.ossfragshift = PT_BLOCKSIZE_LOG2;
163 woinst->buffer.numfrags = PT_BLOCKCOUNT;
164 calculate_ofrag(woinst);
165
166 r = emu10k1_pt_write(file, buffer, count);
167 spin_unlock_irqrestore(&woinst->lock, flags);
168 return r;
169 }
170
171 if (woinst->state == WAVE_STATE_CLOSED) {
172 calculate_ofrag(woinst);
173
174 while (emu10k1_waveout_open(wave_dev) < 0) {
175 spin_unlock_irqrestore(&woinst->lock, flags);
176
177 if (file->f_flags & O_NONBLOCK)
178 return -EAGAIN;
179
180 interruptible_sleep_on(&wave_dev->card->open_wait);
181
182 if (signal_pending(current))
183 return -ERESTARTSYS;
184
185 spin_lock_irqsave(&woinst->lock, flags);
186 }
187 }
188
189 spin_unlock_irqrestore(&woinst->lock, flags);
190
191 ret = 0;
192 if (count % woinst->format.bytespersample)
193 return -EINVAL;
194
195 count /= woinst->num_voices;
196
197 while (count > 0) {
198 u32 bytestocopy;
199
200 spin_lock_irqsave(&woinst->lock, flags);
201 emu10k1_waveout_update(woinst);
202 emu10k1_waveout_getxfersize(woinst, &bytestocopy);
203 spin_unlock_irqrestore(&woinst->lock, flags);
204
205 DPD(3, "bytestocopy --> %d\n", bytestocopy);
206
207 if ((bytestocopy >= woinst->buffer.fragment_size)
208 || (bytestocopy >= count)) {
209
210 bytestocopy = min_t(u32, bytestocopy, count);
211
212 emu10k1_waveout_xferdata(woinst, (u8 __user *) buffer, &bytestocopy);
213
214 count -= bytestocopy;
215 buffer += bytestocopy * woinst->num_voices;
216 ret += bytestocopy * woinst->num_voices;
217
218 spin_lock_irqsave(&woinst->lock, flags);
219 woinst->total_copied += bytestocopy;
220
221 if (!(woinst->state & WAVE_STATE_STARTED)
222 && (wave_dev->enablebits & PCM_ENABLE_OUTPUT)
223 && (woinst->total_copied >= woinst->buffer.fragment_size))
224 emu10k1_waveout_start(wave_dev);
225
226 spin_unlock_irqrestore(&woinst->lock, flags);
227 }
228
229 if (count > 0) {
230 if ((file->f_flags & O_NONBLOCK)
231 || (!(wave_dev->enablebits & PCM_ENABLE_OUTPUT)))
232 return (ret ? ret : -EAGAIN);
233
234 interruptible_sleep_on(&woinst->wait_queue);
235
236 if (signal_pending(current))
237 return (ret ? ret : -ERESTARTSYS);
238 }
239 }
240
241 DPD(3, "bytes copied -> %d\n", (u32) ret);
242
243 return ret;
244}
245
246static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
247{
248 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
249 struct woinst *woinst = NULL;
250 struct wiinst *wiinst = NULL;
251 int val = 0;
252 u32 bytestocopy;
253 unsigned long flags;
254 int __user *p = (int __user *)arg;
255
256 DPF(4, "emu10k1_audio_ioctl()\n");
257
258 if (file->f_mode & FMODE_WRITE)
259 woinst = wave_dev->woinst;
260
261 if (file->f_mode & FMODE_READ)
262 wiinst = wave_dev->wiinst;
263
264 switch (cmd) {
265 case OSS_GETVERSION:
266 DPF(2, "OSS_GETVERSION:\n");
267 return put_user(SOUND_VERSION, p);
268
269 case SNDCTL_DSP_RESET:
270 DPF(2, "SNDCTL_DSP_RESET:\n");
271 wave_dev->enablebits = PCM_ENABLE_OUTPUT | PCM_ENABLE_INPUT;
272
273 if (file->f_mode & FMODE_WRITE) {
274 spin_lock_irqsave(&woinst->lock, flags);
275
276 if (woinst->state & WAVE_STATE_OPEN) {
277 emu10k1_waveout_close(wave_dev);
278 }
279
280 woinst->mmapped = 0;
281 woinst->total_copied = 0;
282 woinst->total_played = 0;
283 woinst->blocks = 0;
284
285 spin_unlock_irqrestore(&woinst->lock, flags);
286 }
287
288 if (file->f_mode & FMODE_READ) {
289 spin_lock_irqsave(&wiinst->lock, flags);
290
291 if (wiinst->state & WAVE_STATE_OPEN) {
292 emu10k1_wavein_close(wave_dev);
293 }
294
295 wiinst->mmapped = 0;
296 wiinst->total_recorded = 0;
297 wiinst->blocks = 0;
298 spin_unlock_irqrestore(&wiinst->lock, flags);
299 }
300
301 break;
302
303 case SNDCTL_DSP_SYNC:
304 DPF(2, "SNDCTL_DSP_SYNC:\n");
305
306 if (file->f_mode & FMODE_WRITE) {
307
308 spin_lock_irqsave(&woinst->lock, flags);
309
310 if (woinst->state & WAVE_STATE_OPEN) {
311
312 if (woinst->state & WAVE_STATE_STARTED)
313 while ((woinst->total_played < woinst->total_copied)
314 && !signal_pending(current)) {
315 spin_unlock_irqrestore(&woinst->lock, flags);
316 interruptible_sleep_on(&woinst->wait_queue);
317 spin_lock_irqsave(&woinst->lock, flags);
318 }
319 emu10k1_waveout_close(wave_dev);
320 }
321
322 woinst->mmapped = 0;
323 woinst->total_copied = 0;
324 woinst->total_played = 0;
325 woinst->blocks = 0;
326
327 spin_unlock_irqrestore(&woinst->lock, flags);
328 }
329
330 if (file->f_mode & FMODE_READ) {
331 spin_lock_irqsave(&wiinst->lock, flags);
332
333 if (wiinst->state & WAVE_STATE_OPEN) {
334 emu10k1_wavein_close(wave_dev);
335 }
336
337 wiinst->mmapped = 0;
338 wiinst->total_recorded = 0;
339 wiinst->blocks = 0;
340 spin_unlock_irqrestore(&wiinst->lock, flags);
341 }
342
343 break;
344
345 case SNDCTL_DSP_SETDUPLEX:
346 DPF(2, "SNDCTL_DSP_SETDUPLEX:\n");
347 break;
348
349 case SNDCTL_DSP_GETCAPS:
350 DPF(2, "SNDCTL_DSP_GETCAPS:\n");
351 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
352 DSP_CAP_TRIGGER | DSP_CAP_MMAP |
353 DSP_CAP_COPROC| DSP_CAP_MULTI, p);
354 case SNDCTL_DSP_SPEED:
355 DPF(2, "SNDCTL_DSP_SPEED:\n");
356
357 if (get_user(val, p))
358 return -EFAULT;
359
360 DPD(2, "val is %d\n", val);
361
362 if (val > 0) {
363 if (file->f_mode & FMODE_READ) {
364 struct wave_format format;
365
366 spin_lock_irqsave(&wiinst->lock, flags);
367
368 format = wiinst->format;
369 format.samplingrate = val;
370
371 if (emu10k1_wavein_setformat(wave_dev, &format) < 0) {
372 spin_unlock_irqrestore(&wiinst->lock, flags);
373 return -EINVAL;
374 }
375
376 val = wiinst->format.samplingrate;
377
378 spin_unlock_irqrestore(&wiinst->lock, flags);
379
380 DPD(2, "set recording sampling rate -> %d\n", val);
381 }
382
383 if (file->f_mode & FMODE_WRITE) {
384 struct wave_format format;
385
386 spin_lock_irqsave(&woinst->lock, flags);
387
388 format = woinst->format;
389 format.samplingrate = val;
390
391 if (emu10k1_waveout_setformat(wave_dev, &format) < 0) {
392 spin_unlock_irqrestore(&woinst->lock, flags);
393 return -EINVAL;
394 }
395
396 val = woinst->format.samplingrate;
397
398 spin_unlock_irqrestore(&woinst->lock, flags);
399
400 DPD(2, "set playback sampling rate -> %d\n", val);
401 }
402
403 return put_user(val, p);
404 } else {
405 if (file->f_mode & FMODE_READ)
406 val = wiinst->format.samplingrate;
407 else if (file->f_mode & FMODE_WRITE)
408 val = woinst->format.samplingrate;
409
410 return put_user(val, p);
411 }
412 break;
413
414 case SNDCTL_DSP_STEREO:
415 DPF(2, "SNDCTL_DSP_STEREO:\n");
416
417 if (get_user(val, p))
418 return -EFAULT;
419
420 DPD(2, " val is %d\n", val);
421
422 if (file->f_mode & FMODE_READ) {
423 struct wave_format format;
424
425 spin_lock_irqsave(&wiinst->lock, flags);
426
427 format = wiinst->format;
428 format.channels = val ? 2 : 1;
429
430 if (emu10k1_wavein_setformat(wave_dev, &format) < 0) {
431 spin_unlock_irqrestore(&wiinst->lock, flags);
432 return -EINVAL;
433 }
434
435 val = wiinst->format.channels - 1;
436
437 spin_unlock_irqrestore(&wiinst->lock, flags);
438 DPD(2, "set recording stereo -> %d\n", val);
439 }
440
441 if (file->f_mode & FMODE_WRITE) {
442 struct wave_format format;
443
444 spin_lock_irqsave(&woinst->lock, flags);
445
446 format = woinst->format;
447 format.channels = val ? 2 : 1;
448
449 if (emu10k1_waveout_setformat(wave_dev, &format) < 0) {
450 spin_unlock_irqrestore(&woinst->lock, flags);
451 return -EINVAL;
452 }
453
454 val = woinst->format.channels - 1;
455
456 spin_unlock_irqrestore(&woinst->lock, flags);
457
458 DPD(2, "set playback stereo -> %d\n", val);
459 }
460
461 return put_user(val, p);
462
463 break;
464
465 case SNDCTL_DSP_CHANNELS:
466 DPF(2, "SNDCTL_DSP_CHANNELS:\n");
467
468 if (get_user(val, p))
469 return -EFAULT;
470
471 DPD(2, " val is %d\n", val);
472
473 if (val > 0) {
474 if (file->f_mode & FMODE_READ) {
475 struct wave_format format;
476
477 spin_lock_irqsave(&wiinst->lock, flags);
478
479 format = wiinst->format;
480 format.channels = val;
481
482 if (emu10k1_wavein_setformat(wave_dev, &format) < 0) {
483 spin_unlock_irqrestore(&wiinst->lock, flags);
484 return -EINVAL;
485 }
486 val = wiinst->format.channels;
487
488 spin_unlock_irqrestore(&wiinst->lock, flags);
489 DPD(2, "set recording number of channels -> %d\n", val);
490 }
491
492 if (file->f_mode & FMODE_WRITE) {
493 struct wave_format format;
494
495 spin_lock_irqsave(&woinst->lock, flags);
496
497 format = woinst->format;
498 format.channels = val;
499
500 if (emu10k1_waveout_setformat(wave_dev, &format) < 0) {
501 spin_unlock_irqrestore(&woinst->lock, flags);
502 return -EINVAL;
503 }
504
505 val = woinst->format.channels;
506
507 spin_unlock_irqrestore(&woinst->lock, flags);
508 DPD(2, "set playback number of channels -> %d\n", val);
509 }
510
511 return put_user(val, p);
512 } else {
513 if (file->f_mode & FMODE_READ)
514 val = wiinst->format.channels;
515 else if (file->f_mode & FMODE_WRITE)
516 val = woinst->format.channels;
517
518 return put_user(val, p);
519 }
520 break;
521
522 case SNDCTL_DSP_GETFMTS:
523 DPF(2, "SNDCTL_DSP_GETFMTS:\n");
524
525 if (file->f_mode & FMODE_READ)
526 val = AFMT_S16_LE;
527 else if (file->f_mode & FMODE_WRITE) {
528 val = AFMT_S16_LE | AFMT_U8;
529 if (emu10k1_find_control_gpr(&wave_dev->card->mgr,
530 wave_dev->card->pt.patch_name,
531 wave_dev->card->pt.enable_gpr_name) >= 0)
532 val |= AFMT_AC3;
533 }
534 return put_user(val, p);
535
536 case SNDCTL_DSP_SETFMT: /* Same as SNDCTL_DSP_SAMPLESIZE */
537 DPF(2, "SNDCTL_DSP_SETFMT:\n");
538
539 if (get_user(val, p))
540 return -EFAULT;
541
542 DPD(2, " val is %d\n", val);
543
544 if (val != AFMT_QUERY) {
545 if (file->f_mode & FMODE_READ) {
546 struct wave_format format;
547
548 spin_lock_irqsave(&wiinst->lock, flags);
549
550 format = wiinst->format;
551 format.id = val;
552
553 if (emu10k1_wavein_setformat(wave_dev, &format) < 0) {
554 spin_unlock_irqrestore(&wiinst->lock, flags);
555 return -EINVAL;
556 }
557
558 val = wiinst->format.id;
559
560 spin_unlock_irqrestore(&wiinst->lock, flags);
561 DPD(2, "set recording format -> %d\n", val);
562 }
563
564 if (file->f_mode & FMODE_WRITE) {
565 struct wave_format format;
566
567 spin_lock_irqsave(&woinst->lock, flags);
568
569 format = woinst->format;
570 format.id = val;
571
572 if (emu10k1_waveout_setformat(wave_dev, &format) < 0) {
573 spin_unlock_irqrestore(&woinst->lock, flags);
574 return -EINVAL;
575 }
576
577 val = woinst->format.id;
578
579 spin_unlock_irqrestore(&woinst->lock, flags);
580 DPD(2, "set playback format -> %d\n", val);
581 }
582
583 return put_user(val, p);
584 } else {
585 if (file->f_mode & FMODE_READ)
586 val = wiinst->format.id;
587 else if (file->f_mode & FMODE_WRITE)
588 val = woinst->format.id;
589
590 return put_user(val, p);
591 }
592 break;
593
594 case SOUND_PCM_READ_BITS:
595
596 if (file->f_mode & FMODE_READ)
597 val = wiinst->format.bitsperchannel;
598 else if (file->f_mode & FMODE_WRITE)
599 val = woinst->format.bitsperchannel;
600
601 return put_user(val, p);
602
603 case SOUND_PCM_READ_RATE:
604
605 if (file->f_mode & FMODE_READ)
606 val = wiinst->format.samplingrate;
607 else if (file->f_mode & FMODE_WRITE)
608 val = woinst->format.samplingrate;
609
610 return put_user(val, p);
611
612 case SOUND_PCM_READ_CHANNELS:
613
614 if (file->f_mode & FMODE_READ)
615 val = wiinst->format.channels;
616 else if (file->f_mode & FMODE_WRITE)
617 val = woinst->format.channels;
618
619 return put_user(val, p);
620
621 case SOUND_PCM_WRITE_FILTER:
622 DPF(2, "SOUND_PCM_WRITE_FILTER: not implemented\n");
623 break;
624
625 case SOUND_PCM_READ_FILTER:
626 DPF(2, "SOUND_PCM_READ_FILTER: not implemented\n");
627 break;
628
629 case SNDCTL_DSP_SETSYNCRO:
630 DPF(2, "SNDCTL_DSP_SETSYNCRO: not implemented\n");
631 break;
632
633 case SNDCTL_DSP_GETTRIGGER:
634 DPF(2, "SNDCTL_DSP_GETTRIGGER:\n");
635
636 if (file->f_mode & FMODE_WRITE && (wave_dev->enablebits & PCM_ENABLE_OUTPUT))
637 val |= PCM_ENABLE_OUTPUT;
638
639 if (file->f_mode & FMODE_READ && (wave_dev->enablebits & PCM_ENABLE_INPUT))
640 val |= PCM_ENABLE_INPUT;
641
642 return put_user(val, p);
643
644 case SNDCTL_DSP_SETTRIGGER:
645 DPF(2, "SNDCTL_DSP_SETTRIGGER:\n");
646
647 if (get_user(val, p))
648 return -EFAULT;
649
650 if (file->f_mode & FMODE_WRITE) {
651 spin_lock_irqsave(&woinst->lock, flags);
652
653 if (val & PCM_ENABLE_OUTPUT) {
654 wave_dev->enablebits |= PCM_ENABLE_OUTPUT;
655 if (woinst->state & WAVE_STATE_OPEN)
656 emu10k1_waveout_start(wave_dev);
657 } else {
658 wave_dev->enablebits &= ~PCM_ENABLE_OUTPUT;
659 if (woinst->state & WAVE_STATE_STARTED)
660 emu10k1_waveout_stop(wave_dev);
661 }
662
663 spin_unlock_irqrestore(&woinst->lock, flags);
664 }
665
666 if (file->f_mode & FMODE_READ) {
667 spin_lock_irqsave(&wiinst->lock, flags);
668
669 if (val & PCM_ENABLE_INPUT) {
670 wave_dev->enablebits |= PCM_ENABLE_INPUT;
671 if (wiinst->state & WAVE_STATE_OPEN)
672 emu10k1_wavein_start(wave_dev);
673 } else {
674 wave_dev->enablebits &= ~PCM_ENABLE_INPUT;
675 if (wiinst->state & WAVE_STATE_STARTED)
676 emu10k1_wavein_stop(wave_dev);
677 }
678
679 spin_unlock_irqrestore(&wiinst->lock, flags);
680 }
681 break;
682
683 case SNDCTL_DSP_GETOSPACE:
684 {
685 audio_buf_info info;
686
687 DPF(4, "SNDCTL_DSP_GETOSPACE:\n");
688
689 if (!(file->f_mode & FMODE_WRITE))
690 return -EINVAL;
691
692 spin_lock_irqsave(&woinst->lock, flags);
693
694 if (woinst->state & WAVE_STATE_OPEN) {
695 emu10k1_waveout_update(woinst);
696 emu10k1_waveout_getxfersize(woinst, &bytestocopy);
697 info.bytes = bytestocopy;
698 } else {
699 calculate_ofrag(woinst);
700 info.bytes = woinst->buffer.size;
701 }
702 spin_unlock_irqrestore(&woinst->lock, flags);
703
704 info.bytes *= woinst->num_voices;
705 info.fragsize = woinst->buffer.fragment_size * woinst->num_voices;
706 info.fragstotal = woinst->buffer.numfrags * woinst->num_voices;
707 info.fragments = info.bytes / info.fragsize;
708
709 if (copy_to_user(p, &info, sizeof(info)))
710 return -EFAULT;
711 }
712 break;
713
714 case SNDCTL_DSP_GETISPACE:
715 {
716 audio_buf_info info;
717
718 DPF(4, "SNDCTL_DSP_GETISPACE:\n");
719
720 if (!(file->f_mode & FMODE_READ))
721 return -EINVAL;
722
723 spin_lock_irqsave(&wiinst->lock, flags);
724 if (wiinst->state & WAVE_STATE_OPEN) {
725 emu10k1_wavein_update(wave_dev->card, wiinst);
726 emu10k1_wavein_getxfersize(wiinst, &bytestocopy);
727 info.bytes = bytestocopy;
728 } else {
729 calculate_ifrag(wiinst);
730 info.bytes = 0;
731 }
732 spin_unlock_irqrestore(&wiinst->lock, flags);
733
734 info.fragstotal = wiinst->buffer.numfrags;
735 info.fragments = info.bytes / wiinst->buffer.fragment_size;
736 info.fragsize = wiinst->buffer.fragment_size;
737
738 if (copy_to_user(p, &info, sizeof(info)))
739 return -EFAULT;
740 }
741 break;
742
743 case SNDCTL_DSP_NONBLOCK:
744 DPF(2, "SNDCTL_DSP_NONBLOCK:\n");
745
746 file->f_flags |= O_NONBLOCK;
747 break;
748
749 case SNDCTL_DSP_GETODELAY:
750 DPF(4, "SNDCTL_DSP_GETODELAY:\n");
751
752 if (!(file->f_mode & FMODE_WRITE))
753 return -EINVAL;
754
755 spin_lock_irqsave(&woinst->lock, flags);
756 if (woinst->state & WAVE_STATE_OPEN) {
757 emu10k1_waveout_update(woinst);
758 emu10k1_waveout_getxfersize(woinst, &bytestocopy);
759 val = woinst->buffer.size - bytestocopy;
760 } else
761 val = 0;
762
763 val *= woinst->num_voices;
764 spin_unlock_irqrestore(&woinst->lock, flags);
765
766 return put_user(val, p);
767
768 case SNDCTL_DSP_GETIPTR:
769 {
770 count_info cinfo;
771
772 DPF(4, "SNDCTL_DSP_GETIPTR: \n");
773
774 if (!(file->f_mode & FMODE_READ))
775 return -EINVAL;
776
777 spin_lock_irqsave(&wiinst->lock, flags);
778
779 if (wiinst->state & WAVE_STATE_OPEN) {
780 emu10k1_wavein_update(wave_dev->card, wiinst);
781 cinfo.ptr = wiinst->buffer.hw_pos;
782 cinfo.bytes = cinfo.ptr + wiinst->total_recorded - wiinst->total_recorded % wiinst->buffer.size;
783 cinfo.blocks = cinfo.bytes / wiinst->buffer.fragment_size - wiinst->blocks;
784 wiinst->blocks = cinfo.bytes / wiinst->buffer.fragment_size;
785 } else {
786 cinfo.ptr = 0;
787 cinfo.bytes = 0;
788 cinfo.blocks = 0;
789 }
790
791 if (wiinst->mmapped)
792 wiinst->buffer.bytestocopy %= wiinst->buffer.fragment_size;
793
794 spin_unlock_irqrestore(&wiinst->lock, flags);
795
796 if (copy_to_user(p, &cinfo, sizeof(cinfo)))
797 return -EFAULT;
798 }
799 break;
800
801 case SNDCTL_DSP_GETOPTR:
802 {
803 count_info cinfo;
804
805 DPF(4, "SNDCTL_DSP_GETOPTR:\n");
806
807 if (!(file->f_mode & FMODE_WRITE))
808 return -EINVAL;
809
810 spin_lock_irqsave(&woinst->lock, flags);
811
812 if (woinst->state & WAVE_STATE_OPEN ||
813 ((woinst->format.passthrough == 1) && wave_dev->card->pt.state)) {
814 int num_fragments;
815
816 if (woinst->format.passthrough == 1) {
817 emu10k1_pt_waveout_update(wave_dev);
818 cinfo.bytes = woinst->total_played;
819 } else {
820 emu10k1_waveout_update(woinst);
821 cinfo.bytes = woinst->total_played;
822 }
823
824 cinfo.ptr = woinst->buffer.hw_pos;
825 num_fragments = cinfo.bytes / woinst->buffer.fragment_size;
826 cinfo.blocks = num_fragments - woinst->blocks;
827 woinst->blocks = num_fragments;
828
829 cinfo.bytes *= woinst->num_voices;
830 cinfo.ptr *= woinst->num_voices;
831 } else {
832 cinfo.ptr = 0;
833 cinfo.bytes = 0;
834 cinfo.blocks = 0;
835 }
836
837 if (woinst->mmapped)
838 woinst->buffer.free_bytes %= woinst->buffer.fragment_size;
839
840 spin_unlock_irqrestore(&woinst->lock, flags);
841
842 if (copy_to_user(p, &cinfo, sizeof(cinfo)))
843 return -EFAULT;
844 }
845 break;
846
847 case SNDCTL_DSP_GETBLKSIZE:
848 DPF(2, "SNDCTL_DSP_GETBLKSIZE:\n");
849
850 if (file->f_mode & FMODE_WRITE) {
851 spin_lock_irqsave(&woinst->lock, flags);
852
853 calculate_ofrag(woinst);
854 val = woinst->buffer.fragment_size * woinst->num_voices;
855
856 spin_unlock_irqrestore(&woinst->lock, flags);
857 }
858
859 if (file->f_mode & FMODE_READ) {
860 spin_lock_irqsave(&wiinst->lock, flags);
861
862 calculate_ifrag(wiinst);
863 val = wiinst->buffer.fragment_size;
864
865 spin_unlock_irqrestore(&wiinst->lock, flags);
866 }
867
868 return put_user(val, p);
869
870 break;
871
872 case SNDCTL_DSP_POST:
873 if (file->f_mode & FMODE_WRITE) {
874 spin_lock_irqsave(&woinst->lock, flags);
875
876 if (!(woinst->state & WAVE_STATE_STARTED)
877 && (wave_dev->enablebits & PCM_ENABLE_OUTPUT)
878 && (woinst->total_copied > 0))
879 emu10k1_waveout_start(wave_dev);
880
881 spin_unlock_irqrestore(&woinst->lock, flags);
882 }
883
884 break;
885
886 case SNDCTL_DSP_SUBDIVIDE:
887 DPF(2, "SNDCTL_DSP_SUBDIVIDE: not implemented\n");
888 break;
889
890 case SNDCTL_DSP_SETFRAGMENT:
891 DPF(2, "SNDCTL_DSP_SETFRAGMENT:\n");
892
893 if (get_user(val, p))
894 return -EFAULT;
895
896 DPD(2, "val is %#x\n", val);
897
898 if (val == 0)
899 return -EIO;
900
901 if (file->f_mode & FMODE_WRITE) {
902 /* digital pass-through fragment count and size are fixed values */
903 if (woinst->state & WAVE_STATE_OPEN || (woinst->format.passthrough == 1))
904 return -EINVAL; /* too late to change */
905
906 woinst->buffer.ossfragshift = val & 0xffff;
907 woinst->buffer.numfrags = (val >> 16) & 0xffff;
908 }
909
910 if (file->f_mode & FMODE_READ) {
911 if (wiinst->state & WAVE_STATE_OPEN)
912 return -EINVAL; /* too late to change */
913
914 wiinst->buffer.ossfragshift = val & 0xffff;
915 wiinst->buffer.numfrags = (val >> 16) & 0xffff;
916 }
917
918 break;
919
920 case SNDCTL_COPR_LOAD:
921 {
922 copr_buffer *buf;
923 u32 i;
924
925 DPF(4, "SNDCTL_COPR_LOAD:\n");
926
927 buf = kmalloc(sizeof(copr_buffer), GFP_KERNEL);
928 if (!buf)
929 return -ENOMEM;
930
931 if (copy_from_user(buf, p, sizeof(copr_buffer))) {
932 kfree (buf);
933 return -EFAULT;
934 }
935
936 if ((buf->command != CMD_READ) && (buf->command != CMD_WRITE)) {
937 kfree (buf);
938 return -EINVAL;
939 }
940
941 if (buf->command == CMD_WRITE) {
942
943#ifdef DBGEMU
944 if ((buf->offs < 0) || (buf->offs + buf->len > 0xe00) || (buf->len > 1000)) {
945#else
946 if (((buf->offs < 0x100) || (buf->offs + buf->len > (wave_dev->card->is_audigy ? 0xe00 : 0x800)) || (buf->len > 1000)
947 ) && !(
948 //any register allowed raw access to users goes here:
949 (buf->offs == DBG ||
950 buf->offs == A_DBG)
951 && (buf->len == 1))) {
952#endif
953 kfree(buf);
954 return -EINVAL;
955 }
956 } else {
957 if ((buf->offs < 0) || (buf->offs + buf->len > 0xe00) || (buf->len > 1000)) {
958 kfree(buf);
959 return -EINVAL;
960 }
961 }
962
963 if (((unsigned)buf->flags) > 0x3f)
964 buf->flags = 0;
965
966 if (buf->command == CMD_READ) {
967 for (i = 0; i < buf->len; i++)
968 ((u32 *) buf->data)[i] = sblive_readptr(wave_dev->card, buf->offs + i, buf->flags);
969
970 if (copy_to_user(p, buf, sizeof(copr_buffer))) {
971 kfree(buf);
972 return -EFAULT;
973 }
974 } else {
975 for (i = 0; i < buf->len; i++)
976 sblive_writeptr(wave_dev->card, buf->offs + i, buf->flags, ((u32 *) buf->data)[i]);
977 }
978
979 kfree (buf);
980 break;
981 }
982
983 default: /* Default is unrecognized command */
984 DPD(2, "default: %#x\n", cmd);
985 return -EINVAL;
986 }
987 return 0;
988}
989
990static struct page *emu10k1_mm_nopage (struct vm_area_struct * vma, unsigned long address, int *type)
991{
992 struct emu10k1_wavedevice *wave_dev = vma->vm_private_data;
993 struct woinst *woinst = wave_dev->woinst;
994 struct wiinst *wiinst = wave_dev->wiinst;
995 struct page *dmapage;
996 unsigned long pgoff;
997 int rd, wr;
998
999 DPF(3, "emu10k1_mm_nopage()\n");
1000 DPD(3, "addr: %#lx\n", address);
1001
1002 if (address > vma->vm_end) {
1003 DPF(1, "EXIT, returning NOPAGE_SIGBUS\n");
1004 return NOPAGE_SIGBUS; /* Disallow mremap */
1005 }
1006
1007 pgoff = vma->vm_pgoff + ((address - vma->vm_start) >> PAGE_SHIFT);
1008 if (woinst != NULL)
1009 wr = woinst->mmapped;
1010 else
1011 wr = 0;
1012
1013 if (wiinst != NULL)
1014 rd = wiinst->mmapped;
1015 else
1016 rd = 0;
1017
1018 /* if full-duplex (read+write) and we have two sets of bufs,
1019 * then the playback buffers come first, sez soundcard.c */
1020 if (wr) {
1021 if (pgoff >= woinst->buffer.pages) {
1022 pgoff -= woinst->buffer.pages;
1023 dmapage = virt_to_page ((u8 *) wiinst->buffer.addr + pgoff * PAGE_SIZE);
1024 } else
1025 dmapage = virt_to_page (woinst->voice[0].mem.addr[pgoff]);
1026 } else {
1027 dmapage = virt_to_page ((u8 *) wiinst->buffer.addr + pgoff * PAGE_SIZE);
1028 }
1029
1030 get_page (dmapage);
1031
1032 DPD(3, "page: %#lx\n", (unsigned long) dmapage);
1033 if (type)
1034 *type = VM_FAULT_MINOR;
1035 return dmapage;
1036}
1037
1038static struct vm_operations_struct emu10k1_mm_ops = {
1039 .nopage = emu10k1_mm_nopage,
1040};
1041
1042static int emu10k1_audio_mmap(struct file *file, struct vm_area_struct *vma)
1043{
1044 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
1045 unsigned long max_pages, n_pages, pgoffset;
1046 struct woinst *woinst = NULL;
1047 struct wiinst *wiinst = NULL;
1048 unsigned long flags;
1049
1050 DPF(2, "emu10k1_audio_mmap()\n");
1051
1052 max_pages = 0;
1053 if (vma->vm_flags & VM_WRITE) {
1054 woinst = wave_dev->woinst;
1055
1056 spin_lock_irqsave(&woinst->lock, flags);
1057
1058 /* No m'mapping possible for multichannel */
1059 if (woinst->num_voices > 1) {
1060 spin_unlock_irqrestore(&woinst->lock, flags);
1061 return -EINVAL;
1062 }
1063
1064 if (woinst->state == WAVE_STATE_CLOSED) {
1065 calculate_ofrag(woinst);
1066
1067 if (emu10k1_waveout_open(wave_dev) < 0) {
1068 spin_unlock_irqrestore(&woinst->lock, flags);
1069 ERROR();
1070 return -EINVAL;
1071 }
1072 }
1073
1074 woinst->mmapped = 1;
1075 max_pages += woinst->buffer.pages;
1076 spin_unlock_irqrestore(&woinst->lock, flags);
1077 }
1078
1079 if (vma->vm_flags & VM_READ) {
1080 wiinst = wave_dev->wiinst;
1081
1082 spin_lock_irqsave(&wiinst->lock, flags);
1083 if (wiinst->state == WAVE_STATE_CLOSED) {
1084 calculate_ifrag(wiinst);
1085
1086 if (emu10k1_wavein_open(wave_dev) < 0) {
1087 spin_unlock_irqrestore(&wiinst->lock, flags);
1088 ERROR();
1089 return -EINVAL;
1090 }
1091 }
1092
1093 wiinst->mmapped = 1;
1094 max_pages += wiinst->buffer.pages;
1095 spin_unlock_irqrestore(&wiinst->lock, flags);
1096 }
1097
1098 n_pages = ((vma->vm_end - vma->vm_start) + PAGE_SIZE - 1) >> PAGE_SHIFT;
1099 pgoffset = vma->vm_pgoff;
1100
1101 DPD(2, "vma_start: %#lx, vma_end: %#lx, vma_offset: %ld\n", vma->vm_start, vma->vm_end, pgoffset);
1102 DPD(2, "n_pages: %ld, max_pages: %ld\n", n_pages, max_pages);
1103
1104 if (pgoffset + n_pages > max_pages)
1105 return -EINVAL;
1106
1107 vma->vm_flags |= VM_RESERVED;
1108 vma->vm_ops = &emu10k1_mm_ops;
1109 vma->vm_private_data = wave_dev;
1110 return 0;
1111}
1112
1113static int emu10k1_audio_open(struct inode *inode, struct file *file)
1114{
1115 int minor = iminor(inode);
1116 struct emu10k1_card *card = NULL;
1117 struct list_head *entry;
1118 struct emu10k1_wavedevice *wave_dev;
1119
1120 DPF(2, "emu10k1_audio_open()\n");
1121
1122 /* Check for correct device to open */
1123
1124 list_for_each(entry, &emu10k1_devs) {
1125 card = list_entry(entry, struct emu10k1_card, list);
1126
1127 if (!((card->audio_dev ^ minor) & ~0xf) || !((card->audio_dev1 ^ minor) & ~0xf))
1128 goto match;
1129 }
1130
1131 return -ENODEV;
1132
1133match:
1134
1135 wave_dev = (struct emu10k1_wavedevice *) kmalloc(sizeof(struct emu10k1_wavedevice), GFP_KERNEL);
1136
1137 if (wave_dev == NULL) {
1138 ERROR();
1139 return -ENOMEM;
1140 }
1141
1142 wave_dev->card = card;
1143 wave_dev->wiinst = NULL;
1144 wave_dev->woinst = NULL;
1145 wave_dev->enablebits = PCM_ENABLE_OUTPUT | PCM_ENABLE_INPUT; /* Default */
1146
1147 if (file->f_mode & FMODE_READ) {
1148 /* Recording */
1149 struct wiinst *wiinst;
1150
1151 if ((wiinst = (struct wiinst *) kmalloc(sizeof(struct wiinst), GFP_KERNEL)) == NULL) {
1152 ERROR();
1153 kfree(wave_dev);
1154 return -ENOMEM;
1155 }
1156
1157 wiinst->recsrc = card->wavein.recsrc;
1158 wiinst->fxwc = card->wavein.fxwc;
1159
1160 switch (wiinst->recsrc) {
1161 case WAVERECORD_AC97:
1162 wiinst->format.id = AFMT_S16_LE;
1163 wiinst->format.samplingrate = 8000;
1164 wiinst->format.bitsperchannel = 16;
1165 wiinst->format.channels = 1;
1166 break;
1167 case WAVERECORD_MIC:
1168 wiinst->format.id = AFMT_S16_LE;
1169 wiinst->format.samplingrate = 8000;
1170 wiinst->format.bitsperchannel = 16;
1171 wiinst->format.channels = 1;
1172 break;
1173 case WAVERECORD_FX:
1174 wiinst->format.id = AFMT_S16_LE;
1175 wiinst->format.samplingrate = 48000;
1176 wiinst->format.bitsperchannel = 16;
1177 wiinst->format.channels = hweight32(wiinst->fxwc);
1178 break;
1179 default:
1180 kfree(wave_dev);
1181 kfree(wiinst);
1182 BUG();
1183 break;
1184 }
1185
1186 wiinst->state = WAVE_STATE_CLOSED;
1187
1188 wiinst->buffer.ossfragshift = 0;
1189 wiinst->buffer.fragment_size = 0;
1190 wiinst->buffer.numfrags = 0;
1191
1192 init_waitqueue_head(&wiinst->wait_queue);
1193
1194 wiinst->mmapped = 0;
1195 wiinst->total_recorded = 0;
1196 wiinst->blocks = 0;
1197 spin_lock_init(&wiinst->lock);
1198 tasklet_init(&wiinst->timer.tasklet, emu10k1_wavein_bh, (unsigned long) wave_dev);
1199 wave_dev->wiinst = wiinst;
1200 emu10k1_wavein_setformat(wave_dev, &wiinst->format);
1201 }
1202
1203 if (file->f_mode & FMODE_WRITE) {
1204 struct woinst *woinst;
1205 int i;
1206
1207 if ((woinst = (struct woinst *) kmalloc(sizeof(struct woinst), GFP_KERNEL)) == NULL) {
1208 ERROR();
1209 kfree(wave_dev);
1210 return -ENOMEM;
1211 }
1212
1213 if (wave_dev->wiinst != NULL) {
1214 woinst->format = wave_dev->wiinst->format;
1215 } else {
1216 woinst->format.id = AFMT_U8;
1217 woinst->format.samplingrate = 8000;
1218 woinst->format.bitsperchannel = 8;
1219 woinst->format.channels = 1;
1220 }
1221
1222 woinst->state = WAVE_STATE_CLOSED;
1223
1224 woinst->buffer.fragment_size = 0;
1225 woinst->buffer.ossfragshift = 0;
1226 woinst->buffer.numfrags = 0;
1227 woinst->device = (card->audio_dev1 == minor);
1228 woinst->timer.state = TIMER_STATE_UNINSTALLED;
1229 woinst->num_voices = 1;
1230 for (i = 0; i < WAVEOUT_MAXVOICES; i++) {
1231 woinst->voice[i].usage = VOICE_USAGE_FREE;
1232 woinst->voice[i].mem.emupageindex = -1;
1233 }
1234
1235 init_waitqueue_head(&woinst->wait_queue);
1236
1237 woinst->mmapped = 0;
1238 woinst->total_copied = 0;
1239 woinst->total_played = 0;
1240 woinst->blocks = 0;
1241 spin_lock_init(&woinst->lock);
1242 tasklet_init(&woinst->timer.tasklet, emu10k1_waveout_bh, (unsigned long) wave_dev);
1243 wave_dev->woinst = woinst;
1244 emu10k1_waveout_setformat(wave_dev, &woinst->format);
1245 }
1246
1247 file->private_data = (void *) wave_dev;
1248
1249 return nonseekable_open(inode, file);
1250}
1251
1252static int emu10k1_audio_release(struct inode *inode, struct file *file)
1253{
1254 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
1255 struct emu10k1_card *card;
1256 unsigned long flags;
1257
1258 card = wave_dev->card;
1259
1260 DPF(2, "emu10k1_audio_release()\n");
1261
1262 if (file->f_mode & FMODE_WRITE) {
1263 struct woinst *woinst = wave_dev->woinst;
1264
1265 spin_lock_irqsave(&woinst->lock, flags);
1266 if(woinst->format.passthrough==2)
1267 card->pt.state=PT_STATE_PLAYING;
1268 if (woinst->format.passthrough && card->pt.state != PT_STATE_INACTIVE){
1269 spin_lock(&card->pt.lock);
1270 emu10k1_pt_stop(card);
1271 spin_unlock(&card->pt.lock);
1272 }
1273 if (woinst->state & WAVE_STATE_OPEN) {
1274 if (woinst->state & WAVE_STATE_STARTED) {
1275 if (!(file->f_flags & O_NONBLOCK)) {
1276 while (!signal_pending(current)
1277 && (woinst->total_played < woinst->total_copied)) {
1278 DPF(4, "Buffer hasn't been totally played, sleep....\n");
1279 spin_unlock_irqrestore(&woinst->lock, flags);
1280 interruptible_sleep_on(&woinst->wait_queue);
1281 spin_lock_irqsave(&woinst->lock, flags);
1282 }
1283 }
1284 }
1285 emu10k1_waveout_close(wave_dev);
1286 }
1287
1288 spin_unlock_irqrestore(&woinst->lock, flags);
1289 /* remove the tasklet */
1290 tasklet_kill(&woinst->timer.tasklet);
1291 kfree(wave_dev->woinst);
1292 }
1293
1294 if (file->f_mode & FMODE_READ) {
1295 struct wiinst *wiinst = wave_dev->wiinst;
1296
1297 spin_lock_irqsave(&wiinst->lock, flags);
1298
1299 if (wiinst->state & WAVE_STATE_OPEN) {
1300 emu10k1_wavein_close(wave_dev);
1301 }
1302
1303 spin_unlock_irqrestore(&wiinst->lock, flags);
1304 tasklet_kill(&wiinst->timer.tasklet);
1305 kfree(wave_dev->wiinst);
1306 }
1307
1308 kfree(wave_dev);
1309
1310 if (waitqueue_active(&card->open_wait))
1311 wake_up_interruptible(&card->open_wait);
1312
1313 return 0;
1314}
1315
1316/* FIXME sort out poll() + mmap() */
1317static unsigned int emu10k1_audio_poll(struct file *file, struct poll_table_struct *wait)
1318{
1319 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
1320 struct woinst *woinst = wave_dev->woinst;
1321 struct wiinst *wiinst = wave_dev->wiinst;
1322 unsigned int mask = 0;
1323 u32 bytestocopy;
1324 unsigned long flags;
1325
1326 DPF(4, "emu10k1_audio_poll()\n");
1327
1328 if (file->f_mode & FMODE_WRITE)
1329 poll_wait(file, &woinst->wait_queue, wait);
1330
1331 if (file->f_mode & FMODE_READ)
1332 poll_wait(file, &wiinst->wait_queue, wait);
1333
1334 if (file->f_mode & FMODE_WRITE) {
1335 spin_lock_irqsave(&woinst->lock, flags);
1336
1337 if (woinst->state & WAVE_STATE_OPEN) {
1338 emu10k1_waveout_update(woinst);
1339 emu10k1_waveout_getxfersize(woinst, &bytestocopy);
1340
1341 if (bytestocopy >= woinst->buffer.fragment_size)
1342 mask |= POLLOUT | POLLWRNORM;
1343 } else
1344 mask |= POLLOUT | POLLWRNORM;
1345
1346 spin_unlock_irqrestore(&woinst->lock, flags);
1347 }
1348
1349 if (file->f_mode & FMODE_READ) {
1350 spin_lock_irqsave(&wiinst->lock, flags);
1351
1352 if (wiinst->state & WAVE_STATE_OPEN) {
1353 emu10k1_wavein_update(wave_dev->card, wiinst);
1354 emu10k1_wavein_getxfersize(wiinst, &bytestocopy);
1355
1356 if (bytestocopy >= wiinst->buffer.fragment_size)
1357 mask |= POLLIN | POLLRDNORM;
1358 }
1359
1360 spin_unlock_irqrestore(&wiinst->lock, flags);
1361 }
1362
1363 return mask;
1364}
1365
1366static void calculate_ofrag(struct woinst *woinst)
1367{
1368 struct waveout_buffer *buffer = &woinst->buffer;
1369 u32 fragsize;
1370
1371 if (buffer->fragment_size)
1372 return;
1373
1374 if (!buffer->ossfragshift) {
1375 fragsize = (woinst->format.bytespervoicesample * woinst->format.samplingrate * WAVEOUT_DEFAULTFRAGLEN) / 1000 - 1;
1376
1377 while (fragsize) {
1378 fragsize >>= 1;
1379 buffer->ossfragshift++;
1380 }
1381 }
1382
1383 if (buffer->ossfragshift < WAVEOUT_MINFRAGSHIFT)
1384 buffer->ossfragshift = WAVEOUT_MINFRAGSHIFT;
1385
1386 buffer->fragment_size = 1 << buffer->ossfragshift;
1387
1388 while (buffer->fragment_size * WAVEOUT_MINFRAGS > WAVEOUT_MAXBUFSIZE)
1389 buffer->fragment_size >>= 1;
1390
1391 /* now we are sure that:
1392 (2^WAVEOUT_MINFRAGSHIFT) <= (fragment_size = 2^n) <= (WAVEOUT_MAXBUFSIZE / WAVEOUT_MINFRAGS)
1393 */
1394
1395 if (!buffer->numfrags) {
1396 u32 numfrags;
1397
1398 numfrags = (woinst->format.bytespervoicesample * woinst->format.samplingrate * WAVEOUT_DEFAULTBUFLEN) /
1399 (buffer->fragment_size * 1000) - 1;
1400
1401 buffer->numfrags = 1;
1402
1403 while (numfrags) {
1404 numfrags >>= 1;
1405 buffer->numfrags <<= 1;
1406 }
1407 }
1408
1409 if (buffer->numfrags < WAVEOUT_MINFRAGS)
1410 buffer->numfrags = WAVEOUT_MINFRAGS;
1411
1412 if (buffer->numfrags * buffer->fragment_size > WAVEOUT_MAXBUFSIZE)
1413 buffer->numfrags = WAVEOUT_MAXBUFSIZE / buffer->fragment_size;
1414
1415 if (buffer->numfrags < WAVEOUT_MINFRAGS)
1416 BUG();
1417
1418 buffer->size = buffer->fragment_size * buffer->numfrags;
1419 buffer->pages = buffer->size / PAGE_SIZE + ((buffer->size % PAGE_SIZE) ? 1 : 0);
1420
1421 DPD(2, " calculated playback fragment_size -> %d\n", buffer->fragment_size);
1422 DPD(2, " calculated playback numfrags -> %d\n", buffer->numfrags);
1423
1424 return;
1425}
1426
1427static void calculate_ifrag(struct wiinst *wiinst)
1428{
1429 struct wavein_buffer *buffer = &wiinst->buffer;
1430 u32 fragsize, bufsize, size[4];
1431 int i, j;
1432
1433 if (buffer->fragment_size)
1434 return;
1435
1436 if (!buffer->ossfragshift) {
1437 fragsize = (wiinst->format.bytespersec * WAVEIN_DEFAULTFRAGLEN) / 1000 - 1;
1438
1439 while (fragsize) {
1440 fragsize >>= 1;
1441 buffer->ossfragshift++;
1442 }
1443 }
1444
1445 if (buffer->ossfragshift < WAVEIN_MINFRAGSHIFT)
1446 buffer->ossfragshift = WAVEIN_MINFRAGSHIFT;
1447
1448 buffer->fragment_size = 1 << buffer->ossfragshift;
1449
1450 while (buffer->fragment_size * WAVEIN_MINFRAGS > WAVEIN_MAXBUFSIZE)
1451 buffer->fragment_size >>= 1;
1452
1453 /* now we are sure that:
1454 (2^WAVEIN_MINFRAGSHIFT) <= (fragment_size = 2^n) <= (WAVEIN_MAXBUFSIZE / WAVEIN_MINFRAGS)
1455 */
1456
1457
1458 if (!buffer->numfrags)
1459 buffer->numfrags = (wiinst->format.bytespersec * WAVEIN_DEFAULTBUFLEN) / (buffer->fragment_size * 1000) - 1;
1460
1461 if (buffer->numfrags < WAVEIN_MINFRAGS)
1462 buffer->numfrags = WAVEIN_MINFRAGS;
1463
1464 if (buffer->numfrags * buffer->fragment_size > WAVEIN_MAXBUFSIZE)
1465 buffer->numfrags = WAVEIN_MAXBUFSIZE / buffer->fragment_size;
1466
1467 if (buffer->numfrags < WAVEIN_MINFRAGS)
1468 BUG();
1469
1470 bufsize = buffer->fragment_size * buffer->numfrags;
1471
1472 /* the buffer size for recording is restricted to certain values, adjust it now */
1473 if (bufsize >= 0x10000) {
1474 buffer->size = 0x10000;
1475 buffer->sizeregval = 0x1f;
1476 } else {
1477 buffer->size = 0;
1478 size[0] = 384;
1479 size[1] = 448;
1480 size[2] = 512;
1481 size[3] = 640;
1482
1483 for (i = 0; i < 8; i++)
1484 for (j = 0; j < 4; j++)
1485 if (bufsize >= size[j]) {
1486 buffer->size = size[j];
1487 size[j] *= 2;
1488 buffer->sizeregval = i * 4 + j + 1;
1489 } else
1490 goto exitloop;
1491 exitloop:
1492 if (buffer->size == 0) {
1493 buffer->size = 384;
1494 buffer->sizeregval = 0x01;
1495 }
1496 }
1497
1498 /* adjust the fragment size so that buffer size is an integer multiple */
1499 while (buffer->size % buffer->fragment_size)
1500 buffer->fragment_size >>= 1;
1501
1502 buffer->numfrags = buffer->size / buffer->fragment_size;
1503 buffer->pages = buffer->size / PAGE_SIZE + ((buffer->size % PAGE_SIZE) ? 1 : 0);
1504
1505 DPD(2, " calculated recording fragment_size -> %d\n", buffer->fragment_size);
1506 DPD(2, " calculated recording numfrags -> %d\n", buffer->numfrags);
1507 DPD(2, " buffer size register -> %#04x\n", buffer->sizeregval);
1508
1509 return;
1510}
1511
1512static void emu10k1_wavein_bh(unsigned long refdata)
1513{
1514 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) refdata;
1515 struct wiinst *wiinst = wave_dev->wiinst;
1516 u32 bytestocopy;
1517 unsigned long flags;
1518
1519 if (!wiinst)
1520 return;
1521
1522 spin_lock_irqsave(&wiinst->lock, flags);
1523
1524 if (!(wiinst->state & WAVE_STATE_STARTED)) {
1525 spin_unlock_irqrestore(&wiinst->lock, flags);
1526 return;
1527 }
1528
1529 emu10k1_wavein_update(wave_dev->card, wiinst);
1530 emu10k1_wavein_getxfersize(wiinst, &bytestocopy);
1531
1532 spin_unlock_irqrestore(&wiinst->lock, flags);
1533
1534 if (bytestocopy >= wiinst->buffer.fragment_size) {
1535 if (waitqueue_active(&wiinst->wait_queue))
1536 wake_up_interruptible(&wiinst->wait_queue);
1537 } else
1538 DPD(3, "Not enough transfer size, %d\n", bytestocopy);
1539
1540 return;
1541}
1542
1543static void emu10k1_waveout_bh(unsigned long refdata)
1544{
1545 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) refdata;
1546 struct woinst *woinst = wave_dev->woinst;
1547 u32 bytestocopy;
1548 unsigned long flags;
1549
1550 if (!woinst)
1551 return;
1552
1553 spin_lock_irqsave(&woinst->lock, flags);
1554
1555 if (!(woinst->state & WAVE_STATE_STARTED)) {
1556 spin_unlock_irqrestore(&woinst->lock, flags);
1557 return;
1558 }
1559
1560 emu10k1_waveout_update(woinst);
1561 emu10k1_waveout_getxfersize(woinst, &bytestocopy);
1562
1563 if (woinst->buffer.fill_silence) {
1564 spin_unlock_irqrestore(&woinst->lock, flags);
1565 emu10k1_waveout_fillsilence(woinst);
1566 } else
1567 spin_unlock_irqrestore(&woinst->lock, flags);
1568
1569 if (bytestocopy >= woinst->buffer.fragment_size) {
1570 if (waitqueue_active(&woinst->wait_queue))
1571 wake_up_interruptible(&woinst->wait_queue);
1572 } else
1573 DPD(3, "Not enough transfer size -> %d\n", bytestocopy);
1574
1575 return;
1576}
1577
1578struct file_operations emu10k1_audio_fops = {
1579 .owner = THIS_MODULE,
1580 .llseek = no_llseek,
1581 .read = emu10k1_audio_read,
1582 .write = emu10k1_audio_write,
1583 .poll = emu10k1_audio_poll,
1584 .ioctl = emu10k1_audio_ioctl,
1585 .mmap = emu10k1_audio_mmap,
1586 .open = emu10k1_audio_open,
1587 .release = emu10k1_audio_release,
1588};
diff --git a/sound/oss/emu10k1/audio.h b/sound/oss/emu10k1/audio.h
new file mode 100644
index 000000000000..26ee81bbd6c6
--- /dev/null
+++ b/sound/oss/emu10k1/audio.h
@@ -0,0 +1,44 @@
1/*
2 **********************************************************************
3 * audio.c -- /dev/dsp interface for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox cleaned up types/leaks
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#ifndef _AUDIO_H
34#define _AUDIO_H
35
36struct emu10k1_wavedevice
37{
38 struct emu10k1_card *card;
39 struct wiinst *wiinst;
40 struct woinst *woinst;
41 u16 enablebits;
42};
43
44#endif /* _AUDIO_H */
diff --git a/sound/oss/emu10k1/cardmi.c b/sound/oss/emu10k1/cardmi.c
new file mode 100644
index 000000000000..0545814cc67d
--- /dev/null
+++ b/sound/oss/emu10k1/cardmi.c
@@ -0,0 +1,832 @@
1/*
2 **********************************************************************
3 * sblive_mi.c - MIDI UART input HAL for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox clean up
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#include <linux/slab.h>
34#include <linux/jiffies.h>
35
36#include "hwaccess.h"
37#include "8010.h"
38#include "cardmi.h"
39#include "irqmgr.h"
40
41
42static int emu10k1_mpuin_callback(struct emu10k1_mpuin *card_mpuin, u32 msg, unsigned long data, u32 bytesvalid);
43
44static int sblive_miStateInit(struct emu10k1_mpuin *);
45static int sblive_miStateEntry(struct emu10k1_mpuin *, u8);
46static int sblive_miStateParse(struct emu10k1_mpuin *, u8);
47static int sblive_miState3Byte(struct emu10k1_mpuin *, u8);
48static int sblive_miState3ByteKey(struct emu10k1_mpuin *, u8);
49static int sblive_miState3ByteVel(struct emu10k1_mpuin *, u8);
50static int sblive_miState2Byte(struct emu10k1_mpuin *, u8);
51static int sblive_miState2ByteKey(struct emu10k1_mpuin *, u8);
52static int sblive_miStateSysCommon2(struct emu10k1_mpuin *, u8);
53static int sblive_miStateSysCommon2Key(struct emu10k1_mpuin *, u8);
54static int sblive_miStateSysCommon3(struct emu10k1_mpuin *, u8);
55static int sblive_miStateSysCommon3Key(struct emu10k1_mpuin *, u8);
56static int sblive_miStateSysCommon3Vel(struct emu10k1_mpuin *, u8);
57static int sblive_miStateSysExNorm(struct emu10k1_mpuin *, u8);
58static int sblive_miStateSysReal(struct emu10k1_mpuin *, u8);
59
60
61static struct {
62 int (*Fn) (struct emu10k1_mpuin *, u8);
63} midistatefn[] = {
64
65 {
66 sblive_miStateParse}, {
67 sblive_miState3Byte}, /* 0x8n, 0x9n, 0xAn, 0xBn, 0xEn */
68 {
69 sblive_miState3ByteKey}, /* Byte 1 */
70 {
71 sblive_miState3ByteVel}, /* Byte 2 */
72 {
73 sblive_miState2Byte}, /* 0xCn, 0xDn */
74 {
75 sblive_miState2ByteKey}, /* Byte 1 */
76 {
77 sblive_miStateSysCommon2}, /* 0xF1 , 0xF3 */
78 {
79 sblive_miStateSysCommon2Key}, /* 0xF1 , 0xF3, Byte 1 */
80 {
81 sblive_miStateSysCommon3}, /* 0xF2 */
82 {
83 sblive_miStateSysCommon3Key}, /* 0xF2 , Byte 1 */
84 {
85 sblive_miStateSysCommon3Vel}, /* 0xF2 , Byte 2 */
86 {
87 sblive_miStateSysExNorm}, /* 0xF0, 0xF7, Normal mode */
88 {
89 sblive_miStateSysReal} /* 0xF4 - 0xF6 ,0xF8 - 0xFF */
90};
91
92
93/* Installs the IRQ handler for the MPU in port */
94
95/* and initialize parameters */
96
97int emu10k1_mpuin_open(struct emu10k1_card *card, struct midi_openinfo *openinfo)
98{
99 struct emu10k1_mpuin *card_mpuin = card->mpuin;
100
101 DPF(2, "emu10k1_mpuin_open\n");
102
103 if (!(card_mpuin->status & FLAGS_AVAILABLE))
104 return -1;
105
106 /* Copy open info and mark channel as in use */
107 card_mpuin->openinfo = *openinfo;
108 card_mpuin->status &= ~FLAGS_AVAILABLE; /* clear */
109 card_mpuin->status |= FLAGS_READY; /* set */
110 card_mpuin->status &= ~FLAGS_MIDM_STARTED; /* clear */
111 card_mpuin->firstmidiq = NULL;
112 card_mpuin->lastmidiq = NULL;
113 card_mpuin->qhead = 0;
114 card_mpuin->qtail = 0;
115
116 sblive_miStateInit(card_mpuin);
117
118 emu10k1_mpu_reset(card);
119 emu10k1_mpu_acquire(card);
120
121 return 0;
122}
123
124int emu10k1_mpuin_close(struct emu10k1_card *card)
125{
126 struct emu10k1_mpuin *card_mpuin = card->mpuin;
127
128 DPF(2, "emu10k1_mpuin_close()\n");
129
130 /* Check if there are pending input SysEx buffers */
131 if (card_mpuin->firstmidiq != NULL) {
132 ERROR();
133 return -1;
134 }
135
136 /* Disable RX interrupt */
137 emu10k1_irq_disable(card, card->is_audigy ? A_INTE_MIDIRXENABLE : INTE_MIDIRXENABLE);
138
139 emu10k1_mpu_release(card);
140
141 card_mpuin->status |= FLAGS_AVAILABLE; /* set */
142 card_mpuin->status &= ~FLAGS_MIDM_STARTED; /* clear */
143
144 return 0;
145}
146
147/* Adds MIDI buffer to local queue list */
148
149int emu10k1_mpuin_add_buffer(struct emu10k1_mpuin *card_mpuin, struct midi_hdr *midihdr)
150{
151 struct midi_queue *midiq;
152 unsigned long flags;
153
154 DPF(2, "emu10k1_mpuin_add_buffer()\n");
155
156 /* Update MIDI buffer flags */
157 midihdr->flags |= MIDIBUF_INQUEUE; /* set */
158 midihdr->flags &= ~MIDIBUF_DONE; /* clear */
159
160 if ((midiq = (struct midi_queue *) kmalloc(sizeof(struct midi_queue), GFP_ATOMIC)) == NULL) {
161 /* Message lost */
162 return -1;
163 }
164
165 midiq->next = NULL;
166 midiq->qtype = 1;
167 midiq->length = midihdr->bufferlength;
168 midiq->sizeLeft = midihdr->bufferlength;
169 midiq->midibyte = midihdr->data;
170 midiq->refdata = (unsigned long) midihdr;
171
172 spin_lock_irqsave(&card_mpuin->lock, flags);
173
174 if (card_mpuin->firstmidiq == NULL) {
175 card_mpuin->firstmidiq = midiq;
176 card_mpuin->lastmidiq = midiq;
177 } else {
178 (card_mpuin->lastmidiq)->next = midiq;
179 card_mpuin->lastmidiq = midiq;
180 }
181
182 spin_unlock_irqrestore(&card_mpuin->lock, flags);
183
184 return 0;
185}
186
187/* First set the Time Stamp if MIDI IN has not started. */
188
189/* Then enable RX Irq. */
190
191int emu10k1_mpuin_start(struct emu10k1_card *card)
192{
193 struct emu10k1_mpuin *card_mpuin = card->mpuin;
194 u8 dummy;
195
196 DPF(2, "emu10k1_mpuin_start()\n");
197
198 /* Set timestamp if not set */
199 if (card_mpuin->status & FLAGS_MIDM_STARTED) {
200 DPF(2, "Time Stamp not changed\n");
201 } else {
202 while (!emu10k1_mpu_read_data(card, &dummy));
203
204 card_mpuin->status |= FLAGS_MIDM_STARTED; /* set */
205
206 /* Set new time stamp */
207 card_mpuin->timestart = (jiffies * 1000) / HZ;
208 DPD(2, "New Time Stamp = %d\n", card_mpuin->timestart);
209
210 card_mpuin->qhead = 0;
211 card_mpuin->qtail = 0;
212
213 emu10k1_irq_enable(card, card->is_audigy ? A_INTE_MIDIRXENABLE : INTE_MIDIRXENABLE);
214 }
215
216 return 0;
217}
218
219/* Disable the RX Irq. If a partial recorded buffer */
220
221/* exist, send it up to IMIDI level. */
222
223int emu10k1_mpuin_stop(struct emu10k1_card *card)
224{
225 struct emu10k1_mpuin *card_mpuin = card->mpuin;
226 struct midi_queue *midiq;
227 unsigned long flags;
228
229 DPF(2, "emu10k1_mpuin_stop()\n");
230
231 emu10k1_irq_disable(card, card->is_audigy ? A_INTE_MIDIRXENABLE : INTE_MIDIRXENABLE);
232
233 card_mpuin->status &= ~FLAGS_MIDM_STARTED; /* clear */
234
235 if (card_mpuin->firstmidiq) {
236 spin_lock_irqsave(&card_mpuin->lock, flags);
237
238 midiq = card_mpuin->firstmidiq;
239 if (midiq != NULL) {
240 if (midiq->sizeLeft == midiq->length)
241 midiq = NULL;
242 else {
243 card_mpuin->firstmidiq = midiq->next;
244 if (card_mpuin->firstmidiq == NULL)
245 card_mpuin->lastmidiq = NULL;
246 }
247 }
248
249 spin_unlock_irqrestore(&card_mpuin->lock, flags);
250
251 if (midiq) {
252 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INLONGERROR, (unsigned long) midiq, 0);
253 kfree(midiq);
254 }
255 }
256
257 return 0;
258}
259
260/* Disable the RX Irq. If any buffer */
261
262/* exist, send it up to IMIDI level. */
263int emu10k1_mpuin_reset(struct emu10k1_card *card)
264{
265 struct emu10k1_mpuin *card_mpuin = card->mpuin;
266 struct midi_queue *midiq;
267
268 DPF(2, "emu10k1_mpuin_reset()\n");
269
270 emu10k1_irq_disable(card, card->is_audigy ? A_INTE_MIDIRXENABLE : INTE_MIDIRXENABLE);
271
272 while (card_mpuin->firstmidiq) {
273 midiq = card_mpuin->firstmidiq;
274 card_mpuin->firstmidiq = midiq->next;
275
276 if (midiq->sizeLeft == midiq->length)
277 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INLONGDATA, (unsigned long) midiq, 0);
278 else
279 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INLONGERROR, (unsigned long) midiq, 0);
280
281 kfree(midiq);
282 }
283
284 card_mpuin->lastmidiq = NULL;
285 card_mpuin->status &= ~FLAGS_MIDM_STARTED;
286
287 return 0;
288}
289
290/* Passes the message with the data back to the client */
291
292/* via IRQ & DPC callbacks to Ring 3 */
293static int emu10k1_mpuin_callback(struct emu10k1_mpuin *card_mpuin, u32 msg, unsigned long data, u32 bytesvalid)
294{
295 unsigned long timein;
296 struct midi_queue *midiq;
297 unsigned long callback_msg[3];
298 struct midi_hdr *midihdr;
299
300 /* Called during ISR. The data & code touched are:
301 * 1. card_mpuin
302 * 2. The function to be called
303 */
304
305 timein = card_mpuin->timein;
306 if (card_mpuin->timestart <= timein)
307 callback_msg[0] = timein - card_mpuin->timestart;
308 else
309 callback_msg[0] = (~0x0L - card_mpuin->timestart) + timein;
310
311 if (msg == ICARDMIDI_INDATA || msg == ICARDMIDI_INDATAERROR) {
312 callback_msg[1] = data;
313 callback_msg[2] = bytesvalid;
314 DPD(2, "emu10k1_mpuin_callback: midimsg = %#lx\n", data);
315 } else {
316 midiq = (struct midi_queue *) data;
317 midihdr = (struct midi_hdr *) midiq->refdata;
318
319 callback_msg[1] = midiq->length - midiq->sizeLeft;
320 callback_msg[2] = midiq->refdata;
321 midihdr->flags &= ~MIDIBUF_INQUEUE;
322 midihdr->flags |= MIDIBUF_DONE;
323
324 midihdr->bytesrecorded = midiq->length - midiq->sizeLeft;
325 }
326
327 /* Notify client that Sysex buffer has been sent */
328 emu10k1_midi_callback(msg, card_mpuin->openinfo.refdata, callback_msg);
329
330 return 0;
331}
332
333void emu10k1_mpuin_bh(unsigned long refdata)
334{
335 u8 data;
336 unsigned idx;
337 struct emu10k1_mpuin *card_mpuin = (struct emu10k1_mpuin *) refdata;
338 unsigned long flags;
339
340 while (card_mpuin->qhead != card_mpuin->qtail) {
341 spin_lock_irqsave(&card_mpuin->lock, flags);
342 idx = card_mpuin->qhead;
343 data = card_mpuin->midiq[idx].data;
344 card_mpuin->timein = card_mpuin->midiq[idx].timein;
345 idx = (idx + 1) % MIDIIN_MAX_BUFFER_SIZE;
346 card_mpuin->qhead = idx;
347 spin_unlock_irqrestore(&card_mpuin->lock, flags);
348
349 sblive_miStateEntry(card_mpuin, data);
350 }
351
352 return;
353}
354
355/* IRQ callback handler routine for the MPU in port */
356
357int emu10k1_mpuin_irqhandler(struct emu10k1_card *card)
358{
359 unsigned idx;
360 unsigned count;
361 u8 MPUIvalue;
362 struct emu10k1_mpuin *card_mpuin = card->mpuin;
363
364 /* IRQ service routine. The data and code touched are:
365 * 1. card_mpuin
366 */
367
368 count = 0;
369 idx = card_mpuin->qtail;
370
371 while (1) {
372 if (emu10k1_mpu_read_data(card, &MPUIvalue) < 0) {
373 break;
374 } else {
375 ++count;
376 card_mpuin->midiq[idx].data = MPUIvalue;
377 card_mpuin->midiq[idx].timein = (jiffies * 1000) / HZ;
378 idx = (idx + 1) % MIDIIN_MAX_BUFFER_SIZE;
379 }
380 }
381
382 if (count) {
383 card_mpuin->qtail = idx;
384
385 tasklet_hi_schedule(&card_mpuin->tasklet);
386 }
387
388 return 0;
389}
390
391/*****************************************************************************/
392
393/* Supporting functions for Midi-In Interpretation State Machine */
394
395/*****************************************************************************/
396
397/* FIXME: This should be a macro */
398static int sblive_miStateInit(struct emu10k1_mpuin *card_mpuin)
399{
400 card_mpuin->status = 0; /* For MIDI running status */
401 card_mpuin->fstatus = 0; /* For 0xFn status only */
402 card_mpuin->curstate = STIN_PARSE;
403 card_mpuin->laststate = STIN_PARSE;
404 card_mpuin->data = 0;
405 card_mpuin->timestart = 0;
406 card_mpuin->timein = 0;
407
408 return 0;
409}
410
411/* FIXME: This should be a macro */
412static int sblive_miStateEntry(struct emu10k1_mpuin *card_mpuin, u8 data)
413{
414 return midistatefn[card_mpuin->curstate].Fn(card_mpuin, data);
415}
416
417static int sblive_miStateParse(struct emu10k1_mpuin *card_mpuin, u8 data)
418{
419 switch (data & 0xf0) {
420 case 0x80:
421 case 0x90:
422 case 0xA0:
423 case 0xB0:
424 case 0xE0:
425 card_mpuin->curstate = STIN_3BYTE;
426 break;
427
428 case 0xC0:
429 case 0xD0:
430 card_mpuin->curstate = STIN_2BYTE;
431 break;
432
433 case 0xF0:
434 /* System messages do not affect the previous running status! */
435 switch (data & 0x0f) {
436 case 0x0:
437 card_mpuin->laststate = card_mpuin->curstate;
438 card_mpuin->curstate = STIN_SYS_EX_NORM;
439
440 if (card_mpuin->firstmidiq) {
441 struct midi_queue *midiq;
442
443 midiq = card_mpuin->firstmidiq;
444 *midiq->midibyte = data;
445 --midiq->sizeLeft;
446 ++midiq->midibyte;
447 }
448
449 return CTSTATUS_NEXT_BYTE;
450
451 case 0x7:
452 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATAERROR, 0xf7, 0);
453 return -1;
454
455 case 0x2:
456 card_mpuin->laststate = card_mpuin->curstate;
457 card_mpuin->curstate = STIN_SYS_COMMON_3;
458 break;
459
460 case 0x1:
461 case 0x3:
462 card_mpuin->laststate = card_mpuin->curstate;
463 card_mpuin->curstate = STIN_SYS_COMMON_2;
464 break;
465
466 default:
467 /* includes 0xF4 - 0xF6, 0xF8 - 0xFF */
468 return midistatefn[STIN_SYS_REAL].Fn(card_mpuin, data);
469 }
470
471 break;
472
473 default:
474 DPF(2, "BUG: default case hit\n");
475 return -1;
476 }
477
478 return midistatefn[card_mpuin->curstate].Fn(card_mpuin, data);
479}
480
481static int sblive_miState3Byte(struct emu10k1_mpuin *card_mpuin, u8 data)
482{
483 u8 temp = data & 0xf0;
484
485 if (temp < 0x80) {
486 return midistatefn[STIN_3BYTE_KEY].Fn(card_mpuin, data);
487 } else if (temp <= 0xe0 && temp != 0xc0 && temp != 0xd0) {
488 card_mpuin->status = data;
489 card_mpuin->curstate = STIN_3BYTE_KEY;
490
491 return CTSTATUS_NEXT_BYTE;
492 }
493
494 return midistatefn[STIN_PARSE].Fn(card_mpuin, data);
495}
496
497static int sblive_miState3ByteKey(struct emu10k1_mpuin *card_mpuin, u8 data)
498/* byte 1 */
499{
500 unsigned long tmp;
501
502 if (data > 0x7f) {
503 /* Real-time messages check */
504 if (data > 0xf7)
505 return midistatefn[STIN_SYS_REAL].Fn(card_mpuin, data);
506
507 /* Invalid data! */
508 DPF(2, "Invalid data!\n");
509
510 card_mpuin->curstate = STIN_PARSE;
511 tmp = ((unsigned long) data) << 8;
512 tmp |= (unsigned long) card_mpuin->status;
513
514 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATAERROR, tmp, 0);
515
516 return -1;
517 }
518
519 card_mpuin->data = data;
520 card_mpuin->curstate = STIN_3BYTE_VEL;
521
522 return CTSTATUS_NEXT_BYTE;
523}
524
525static int sblive_miState3ByteVel(struct emu10k1_mpuin *card_mpuin, u8 data)
526/* byte 2 */
527{
528 unsigned long tmp;
529
530 if (data > 0x7f) {
531 /* Real-time messages check */
532 if (data > 0xf7)
533 return midistatefn[STIN_SYS_REAL].Fn(card_mpuin, data);
534
535 /* Invalid data! */
536 DPF(2, "Invalid data!\n");
537
538 card_mpuin->curstate = STIN_PARSE;
539 tmp = ((unsigned long) data) << 8;
540 tmp |= card_mpuin->data;
541 tmp = tmp << 8;
542 tmp |= (unsigned long) card_mpuin->status;
543
544 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATAERROR, tmp, 0);
545
546 return -1;
547 }
548
549 card_mpuin->curstate = STIN_3BYTE;
550 tmp = (unsigned long) data;
551 tmp = tmp << 8;
552 tmp |= (unsigned long) card_mpuin->data;
553 tmp = tmp << 8;
554 tmp |= (unsigned long) card_mpuin->status;
555
556 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATA, tmp, 3);
557
558 return 0;
559}
560
561static int sblive_miState2Byte(struct emu10k1_mpuin *card_mpuin, u8 data)
562{
563 u8 temp = data & 0xf0;
564
565 if ((temp == 0xc0) || (temp == 0xd0)) {
566 card_mpuin->status = data;
567 card_mpuin->curstate = STIN_2BYTE_KEY;
568
569 return CTSTATUS_NEXT_BYTE;
570 }
571
572 if (temp < 0x80)
573 return midistatefn[STIN_2BYTE_KEY].Fn(card_mpuin, data);
574
575 return midistatefn[STIN_PARSE].Fn(card_mpuin, data);
576}
577
578static int sblive_miState2ByteKey(struct emu10k1_mpuin *card_mpuin, u8 data)
579/* byte 1 */
580{
581 unsigned long tmp;
582
583 if (data > 0x7f) {
584 /* Real-time messages check */
585 if (data > 0xf7)
586 return midistatefn[STIN_SYS_REAL].Fn(card_mpuin, data);
587
588 /* Invalid data! */
589 DPF(2, "Invalid data!\n");
590
591 card_mpuin->curstate = STIN_PARSE;
592 tmp = (unsigned long) data;
593 tmp = tmp << 8;
594 tmp |= (unsigned long) card_mpuin->status;
595
596 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATAERROR, tmp, 0);
597
598 return -1;
599 }
600
601 card_mpuin->curstate = STIN_2BYTE;
602 tmp = (unsigned long) data;
603 tmp = tmp << 8;
604 tmp |= (unsigned long) card_mpuin->status;
605
606 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATA, tmp, 2);
607
608 return 0;
609}
610
611static int sblive_miStateSysCommon2(struct emu10k1_mpuin *card_mpuin, u8 data)
612{
613 card_mpuin->fstatus = data;
614 card_mpuin->curstate = STIN_SYS_COMMON_2_KEY;
615
616 return CTSTATUS_NEXT_BYTE;
617}
618
619static int sblive_miStateSysCommon2Key(struct emu10k1_mpuin *card_mpuin, u8 data)
620/* byte 1 */
621{
622 unsigned long tmp;
623
624 if (data > 0x7f) {
625 /* Real-time messages check */
626 if (data > 0xf7)
627 return midistatefn[STIN_SYS_REAL].Fn(card_mpuin, data);
628
629 /* Invalid data! */
630 DPF(2, "Invalid data!\n");
631
632 card_mpuin->curstate = card_mpuin->laststate;
633 tmp = (unsigned long) data;
634 tmp = tmp << 8;
635 tmp |= (unsigned long) card_mpuin->fstatus;
636
637 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATAERROR, tmp, 0);
638
639 return -1;
640 }
641
642 card_mpuin->curstate = card_mpuin->laststate;
643 tmp = (unsigned long) data;
644 tmp = tmp << 8;
645 tmp |= (unsigned long) card_mpuin->fstatus;
646
647 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATA, tmp, 2);
648
649 return 0;
650}
651
652static int sblive_miStateSysCommon3(struct emu10k1_mpuin *card_mpuin, u8 data)
653{
654 card_mpuin->fstatus = data;
655 card_mpuin->curstate = STIN_SYS_COMMON_3_KEY;
656
657 return CTSTATUS_NEXT_BYTE;
658}
659
660static int sblive_miStateSysCommon3Key(struct emu10k1_mpuin *card_mpuin, u8 data)
661/* byte 1 */
662{
663 unsigned long tmp;
664
665 if (data > 0x7f) {
666 /* Real-time messages check */
667 if (data > 0xf7)
668 return midistatefn[STIN_SYS_REAL].Fn(card_mpuin, data);
669
670 /* Invalid data! */
671 DPF(2, "Invalid data!\n");
672
673 card_mpuin->curstate = card_mpuin->laststate;
674 tmp = (unsigned long) data;
675 tmp = tmp << 8;
676 tmp |= (unsigned long) card_mpuin->fstatus;
677
678 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATAERROR, tmp, 0);
679
680 return -1;
681 }
682
683 card_mpuin->data = data;
684 card_mpuin->curstate = STIN_SYS_COMMON_3_VEL;
685
686 return CTSTATUS_NEXT_BYTE;
687}
688
689static int sblive_miStateSysCommon3Vel(struct emu10k1_mpuin *card_mpuin, u8 data)
690/* byte 2 */
691{
692 unsigned long tmp;
693
694 if (data > 0x7f) {
695 /* Real-time messages check */
696 if (data > 0xf7)
697 return midistatefn[STIN_SYS_REAL].Fn(card_mpuin, data);
698
699 /* Invalid data! */
700 DPF(2, "Invalid data!\n");
701
702 card_mpuin->curstate = card_mpuin->laststate;
703 tmp = (unsigned long) data;
704 tmp = tmp << 8;
705 tmp |= (unsigned long) card_mpuin->data;
706 tmp = tmp << 8;
707 tmp |= (unsigned long) card_mpuin->fstatus;
708
709 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATAERROR, tmp, 0);
710
711 return -1;
712 }
713
714 card_mpuin->curstate = card_mpuin->laststate;
715 tmp = (unsigned long) data;
716 tmp = tmp << 8;
717 tmp |= (unsigned long) card_mpuin->data;
718 tmp = tmp << 8;
719 tmp |= (unsigned long) card_mpuin->fstatus;
720
721 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATA, tmp, 3);
722
723 return 0;
724}
725
726static int sblive_miStateSysExNorm(struct emu10k1_mpuin *card_mpuin, u8 data)
727{
728 unsigned long flags;
729
730 if ((data > 0x7f) && (data != 0xf7)) {
731 /* Real-time messages check */
732 if (data > 0xf7)
733 return midistatefn[STIN_SYS_REAL].Fn(card_mpuin, data);
734
735 /* Invalid Data! */
736 DPF(2, "Invalid data!\n");
737
738 card_mpuin->curstate = card_mpuin->laststate;
739
740 if (card_mpuin->firstmidiq) {
741 struct midi_queue *midiq;
742
743 midiq = card_mpuin->firstmidiq;
744 *midiq->midibyte = data;
745 --midiq->sizeLeft;
746 ++midiq->midibyte;
747
748 spin_lock_irqsave(&card_mpuin->lock, flags);
749
750 card_mpuin->firstmidiq = midiq->next;
751 if (card_mpuin->firstmidiq == NULL)
752 card_mpuin->lastmidiq = NULL;
753
754 spin_unlock_irqrestore(&card_mpuin->lock, flags);
755
756 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INLONGERROR, (unsigned long) midiq, 0);
757
758 kfree(midiq);
759 }
760
761 return -1;
762 }
763
764 if (card_mpuin->firstmidiq) {
765 struct midi_queue *midiq;
766
767 midiq = card_mpuin->firstmidiq;
768 *midiq->midibyte = data;
769 --midiq->sizeLeft;
770 ++midiq->midibyte;
771 }
772
773 if (data == 0xf7) {
774 /* End of Sysex buffer */
775 /* Send down the buffer */
776
777 card_mpuin->curstate = card_mpuin->laststate;
778
779 if (card_mpuin->firstmidiq) {
780 struct midi_queue *midiq;
781
782 midiq = card_mpuin->firstmidiq;
783
784 spin_lock_irqsave(&card_mpuin->lock, flags);
785
786 card_mpuin->firstmidiq = midiq->next;
787 if (card_mpuin->firstmidiq == NULL)
788 card_mpuin->lastmidiq = NULL;
789
790 spin_unlock_irqrestore(&card_mpuin->lock, flags);
791
792 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INLONGDATA, (unsigned long) midiq, 0);
793
794 kfree(midiq);
795 }
796
797 return 0;
798 }
799
800 if (card_mpuin->firstmidiq) {
801 struct midi_queue *midiq;
802
803 midiq = card_mpuin->firstmidiq;
804
805 if (midiq->sizeLeft == 0) {
806 /* Special case */
807
808 spin_lock_irqsave(&card_mpuin->lock, flags);
809
810 card_mpuin->firstmidiq = midiq->next;
811 if (card_mpuin->firstmidiq == NULL)
812 card_mpuin->lastmidiq = NULL;
813
814 spin_unlock_irqrestore(&card_mpuin->lock, flags);
815
816 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INLONGDATA, (unsigned long) midiq, 0);
817
818 kfree(midiq);
819
820 return CTSTATUS_NEXT_BYTE;
821 }
822 }
823
824 return CTSTATUS_NEXT_BYTE;
825}
826
827static int sblive_miStateSysReal(struct emu10k1_mpuin *card_mpuin, u8 data)
828{
829 emu10k1_mpuin_callback(card_mpuin, ICARDMIDI_INDATA, data, 1);
830
831 return CTSTATUS_NEXT_BYTE;
832}
diff --git a/sound/oss/emu10k1/cardmi.h b/sound/oss/emu10k1/cardmi.h
new file mode 100644
index 000000000000..d12c24116307
--- /dev/null
+++ b/sound/oss/emu10k1/cardmi.h
@@ -0,0 +1,97 @@
1/*
2 **********************************************************************
3 * sblive_mi.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox cleaned up
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#ifndef _CARDMI_H
34#define _CARDMI_H
35
36#include "icardmid.h"
37#include <linux/interrupt.h>
38
39typedef enum
40{
41 STIN_PARSE = 0,
42 STIN_3BYTE, /* 0x80, 0x90, 0xA0, 0xB0, 0xE0 */
43 STIN_3BYTE_KEY, /* Byte 1 */
44 STIN_3BYTE_VEL, /* Byte 1 */
45 STIN_2BYTE, /* 0xC0, 0xD0 */
46 STIN_2BYTE_KEY, /* Byte 1 */
47 STIN_SYS_COMMON_2, /* 0xF1, 0xF3 */
48 STIN_SYS_COMMON_2_KEY,
49 STIN_SYS_COMMON_3, /* 0xF2 */
50 STIN_SYS_COMMON_3_KEY,
51 STIN_SYS_COMMON_3_VEL,
52 STIN_SYS_EX_NORM, /* 0xF0, Normal mode */
53 STIN_SYS_REAL
54} midi_in_state;
55
56
57/* flags for card MIDI in object */
58#define FLAGS_MIDM_STARTED 0x00001000 // Data has started to come in after Midm Start
59#define MIDIIN_MAX_BUFFER_SIZE 200 // Definition for struct emu10k1_mpuin
60
61struct midi_data
62{
63 u8 data;
64 u32 timein;
65};
66
67struct emu10k1_mpuin
68{
69 spinlock_t lock;
70 struct midi_queue *firstmidiq;
71 struct midi_queue *lastmidiq;
72 unsigned qhead, qtail;
73 struct midi_data midiq[MIDIIN_MAX_BUFFER_SIZE];
74 struct tasklet_struct tasklet;
75 struct midi_openinfo openinfo;
76
77 /* For MIDI state machine */
78 u8 status; /* For MIDI running status */
79 u8 fstatus; /* For 0xFn status only */
80 midi_in_state curstate;
81 midi_in_state laststate;
82 u32 timestart;
83 u32 timein;
84 u8 data;
85};
86
87int emu10k1_mpuin_open(struct emu10k1_card *, struct midi_openinfo *);
88int emu10k1_mpuin_close(struct emu10k1_card *);
89int emu10k1_mpuin_add_buffer(struct emu10k1_mpuin *, struct midi_hdr *);
90int emu10k1_mpuin_start(struct emu10k1_card *);
91int emu10k1_mpuin_stop(struct emu10k1_card *);
92int emu10k1_mpuin_reset(struct emu10k1_card *);
93
94int emu10k1_mpuin_irqhandler(struct emu10k1_card *);
95void emu10k1_mpuin_bh(unsigned long);
96
97#endif /* _CARDMI_H */
diff --git a/sound/oss/emu10k1/cardmo.c b/sound/oss/emu10k1/cardmo.c
new file mode 100644
index 000000000000..5938d31f9e21
--- /dev/null
+++ b/sound/oss/emu10k1/cardmo.c
@@ -0,0 +1,229 @@
1/*
2 **********************************************************************
3 * cardmo.c - MIDI UART output HAL for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox cleaned up
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#include <linux/slab.h>
34
35#include "hwaccess.h"
36#include "8010.h"
37#include "cardmo.h"
38#include "irqmgr.h"
39
40/* Installs the IRQ handler for the MPU out port *
41 * and initialize parameters */
42
43int emu10k1_mpuout_open(struct emu10k1_card *card, struct midi_openinfo *openinfo)
44{
45 struct emu10k1_mpuout *card_mpuout = card->mpuout;
46
47 DPF(2, "emu10k1_mpuout_open()\n");
48
49 if (!(card_mpuout->status & FLAGS_AVAILABLE))
50 return -1;
51
52 /* Copy open info and mark channel as in use */
53 card_mpuout->intr = 0;
54 card_mpuout->openinfo = *openinfo;
55 card_mpuout->status &= ~FLAGS_AVAILABLE;
56 card_mpuout->laststatus = 0x80;
57 card_mpuout->firstmidiq = NULL;
58 card_mpuout->lastmidiq = NULL;
59
60 emu10k1_mpu_reset(card);
61 emu10k1_mpu_acquire(card);
62
63 return 0;
64}
65
66int emu10k1_mpuout_close(struct emu10k1_card *card)
67{
68 struct emu10k1_mpuout *card_mpuout = card->mpuout;
69 struct midi_queue *midiq;
70 struct midi_hdr *midihdr;
71 unsigned long flags;
72
73 DPF(2, "emu10k1_mpuout_close()\n");
74
75 emu10k1_irq_disable(card, card->is_audigy ? A_INTE_MIDITXENABLE : INTE_MIDITXENABLE);
76
77 spin_lock_irqsave(&card_mpuout->lock, flags);
78
79 while (card_mpuout->firstmidiq != NULL) {
80 midiq = card_mpuout->firstmidiq;
81 midihdr = (struct midi_hdr *) midiq->refdata;
82
83 card_mpuout->firstmidiq = midiq->next;
84
85 kfree(midihdr->data);
86 kfree(midihdr);
87 kfree(midiq);
88 }
89
90 card_mpuout->lastmidiq = NULL;
91
92 emu10k1_mpu_release(card);
93
94 card_mpuout->status |= FLAGS_AVAILABLE;
95
96 spin_unlock_irqrestore(&card_mpuout->lock, flags);
97
98 return 0;
99}
100
101/* If there isn't enough buffer space, reject Midi Buffer. *
102* Otherwise, disable TX, create object to hold Midi *
103* uffer, update buffer flags and other parameters *
104* before enabling TX again. */
105
106int emu10k1_mpuout_add_buffer(struct emu10k1_card *card, struct midi_hdr *midihdr)
107{
108 struct emu10k1_mpuout *card_mpuout = card->mpuout;
109 struct midi_queue *midiq;
110 unsigned long flags;
111
112 DPF(2, "emu10k1_mpuout_add_buffer()\n");
113
114 if (card_mpuout->state == CARDMIDIOUT_STATE_SUSPEND)
115 return 0;
116
117 midihdr->flags |= MIDIBUF_INQUEUE;
118 midihdr->flags &= ~MIDIBUF_DONE;
119
120 if ((midiq = (struct midi_queue *) kmalloc(sizeof(struct midi_queue), GFP_KERNEL)) == NULL) {
121 /* Message lost */
122 return -1;
123 }
124
125 midiq->next = NULL;
126 midiq->qtype = 1;
127 midiq->length = midihdr->bufferlength;
128 midiq->sizeLeft = midihdr->bufferlength;
129 midiq->midibyte = midihdr->data;
130
131 midiq->refdata = (unsigned long) midihdr;
132
133 spin_lock_irqsave(&card_mpuout->lock, flags);
134
135 if (card_mpuout->firstmidiq == NULL) {
136 card_mpuout->firstmidiq = midiq;
137 card_mpuout->lastmidiq = midiq;
138 } else {
139 (card_mpuout->lastmidiq)->next = midiq;
140 card_mpuout->lastmidiq = midiq;
141 }
142
143 card_mpuout->intr = 0;
144
145 emu10k1_irq_enable(card, card->is_audigy ? A_INTE_MIDITXENABLE : INTE_MIDITXENABLE);
146
147 spin_unlock_irqrestore(&card_mpuout->lock, flags);
148
149 return 0;
150}
151
152void emu10k1_mpuout_bh(unsigned long refdata)
153{
154 struct emu10k1_card *card = (struct emu10k1_card *) refdata;
155 struct emu10k1_mpuout *card_mpuout = card->mpuout;
156 int cByteSent = 0;
157 struct midi_queue *midiq;
158 struct midi_queue *doneq = NULL;
159 unsigned long flags;
160
161 spin_lock_irqsave(&card_mpuout->lock, flags);
162
163 while (card_mpuout->firstmidiq != NULL) {
164 midiq = card_mpuout->firstmidiq;
165
166 while (cByteSent < 4 && midiq->sizeLeft) {
167 if (emu10k1_mpu_write_data(card, *midiq->midibyte) < 0) {
168 DPF(2, "emu10k1_mpuoutDpcCallback error!!\n");
169 } else {
170 ++cByteSent;
171 --midiq->sizeLeft;
172 ++midiq->midibyte;
173 }
174 }
175
176 if (midiq->sizeLeft == 0) {
177 if (doneq == NULL)
178 doneq = midiq;
179 card_mpuout->firstmidiq = midiq->next;
180 } else
181 break;
182 }
183
184 if (card_mpuout->firstmidiq == NULL)
185 card_mpuout->lastmidiq = NULL;
186
187 if (doneq != NULL) {
188 while (doneq != card_mpuout->firstmidiq) {
189 unsigned long callback_msg[3];
190
191 midiq = doneq;
192 doneq = midiq->next;
193
194 if (midiq->qtype) {
195 callback_msg[0] = 0;
196 callback_msg[1] = midiq->length;
197 callback_msg[2] = midiq->refdata;
198
199 emu10k1_midi_callback(ICARDMIDI_OUTLONGDATA, card_mpuout->openinfo.refdata, callback_msg);
200 } else if (((u8) midiq->refdata) < 0xF0 && ((u8) midiq->refdata) > 0x7F)
201 card_mpuout->laststatus = (u8) midiq->refdata;
202
203 kfree(midiq);
204 }
205 }
206
207 if ((card_mpuout->firstmidiq != NULL) || cByteSent) {
208 card_mpuout->intr = 0;
209 emu10k1_irq_enable(card, card->is_audigy ? A_INTE_MIDITXENABLE : INTE_MIDITXENABLE);
210 }
211
212 spin_unlock_irqrestore(&card_mpuout->lock, flags);
213
214 return;
215}
216
217int emu10k1_mpuout_irqhandler(struct emu10k1_card *card)
218{
219 struct emu10k1_mpuout *card_mpuout = card->mpuout;
220
221 DPF(4, "emu10k1_mpuout_irqhandler\n");
222
223 card_mpuout->intr = 1;
224 emu10k1_irq_disable(card, card->is_audigy ? A_INTE_MIDITXENABLE : INTE_MIDITXENABLE);
225
226 tasklet_hi_schedule(&card_mpuout->tasklet);
227
228 return 0;
229}
diff --git a/sound/oss/emu10k1/cardmo.h b/sound/oss/emu10k1/cardmo.h
new file mode 100644
index 000000000000..7026eb3a85af
--- /dev/null
+++ b/sound/oss/emu10k1/cardmo.h
@@ -0,0 +1,62 @@
1/*
2 **********************************************************************
3 * cardmo.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox cleaned up
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#ifndef _CARDMO_H
34#define _CARDMO_H
35
36#include "icardmid.h"
37#include <linux/interrupt.h>
38
39#define CARDMIDIOUT_STATE_DEFAULT 0x00000000
40#define CARDMIDIOUT_STATE_SUSPEND 0x00000001
41
42struct emu10k1_mpuout
43{
44 u32 status;
45 u32 state;
46 volatile int intr;
47 struct midi_queue *firstmidiq;
48 struct midi_queue *lastmidiq;
49 u8 laststatus;
50 struct tasklet_struct tasklet;
51 spinlock_t lock;
52 struct midi_openinfo openinfo;
53};
54
55int emu10k1_mpuout_open(struct emu10k1_card *, struct midi_openinfo *);
56int emu10k1_mpuout_close(struct emu10k1_card *);
57int emu10k1_mpuout_add_buffer(struct emu10k1_card *, struct midi_hdr *);
58
59int emu10k1_mpuout_irqhandler(struct emu10k1_card *);
60void emu10k1_mpuout_bh(unsigned long);
61
62#endif /* _CARDMO_H */
diff --git a/sound/oss/emu10k1/cardwi.c b/sound/oss/emu10k1/cardwi.c
new file mode 100644
index 000000000000..8bbf44b881b4
--- /dev/null
+++ b/sound/oss/emu10k1/cardwi.c
@@ -0,0 +1,373 @@
1/*
2 **********************************************************************
3 * cardwi.c - PCM input HAL for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include <linux/poll.h>
33#include "hwaccess.h"
34#include "timer.h"
35#include "recmgr.h"
36#include "audio.h"
37#include "cardwi.h"
38
39/**
40 * query_format - returns a valid sound format
41 *
42 * This function will return a valid sound format as close
43 * to the requested one as possible.
44 */
45static void query_format(int recsrc, struct wave_format *wave_fmt)
46{
47
48 switch (recsrc) {
49 case WAVERECORD_AC97:
50
51 if ((wave_fmt->channels != 1) && (wave_fmt->channels != 2))
52 wave_fmt->channels = 2;
53
54 if (wave_fmt->samplingrate >= (0xBB80 + 0xAC44) / 2)
55 wave_fmt->samplingrate = 0xBB80;
56 else if (wave_fmt->samplingrate >= (0xAC44 + 0x7D00) / 2)
57 wave_fmt->samplingrate = 0xAC44;
58 else if (wave_fmt->samplingrate >= (0x7D00 + 0x5DC0) / 2)
59 wave_fmt->samplingrate = 0x7D00;
60 else if (wave_fmt->samplingrate >= (0x5DC0 + 0x5622) / 2)
61 wave_fmt->samplingrate = 0x5DC0;
62 else if (wave_fmt->samplingrate >= (0x5622 + 0x3E80) / 2)
63 wave_fmt->samplingrate = 0x5622;
64 else if (wave_fmt->samplingrate >= (0x3E80 + 0x2B11) / 2)
65 wave_fmt->samplingrate = 0x3E80;
66 else if (wave_fmt->samplingrate >= (0x2B11 + 0x1F40) / 2)
67 wave_fmt->samplingrate = 0x2B11;
68 else
69 wave_fmt->samplingrate = 0x1F40;
70
71 switch (wave_fmt->id) {
72 case AFMT_S16_LE:
73 wave_fmt->bitsperchannel = 16;
74 break;
75 case AFMT_U8:
76 wave_fmt->bitsperchannel = 8;
77 break;
78 default:
79 wave_fmt->id = AFMT_S16_LE;
80 wave_fmt->bitsperchannel = 16;
81 break;
82 }
83
84 break;
85
86 /* these can't be changed from the original values */
87 case WAVERECORD_MIC:
88 case WAVERECORD_FX:
89 break;
90
91 default:
92 BUG();
93 break;
94 }
95
96 wave_fmt->bytesperchannel = wave_fmt->bitsperchannel >> 3;
97 wave_fmt->bytespersample = wave_fmt->channels * wave_fmt->bytesperchannel;
98 wave_fmt->bytespersec = wave_fmt->bytespersample * wave_fmt->samplingrate;
99 wave_fmt->bytespervoicesample = wave_fmt->bytespersample;
100}
101
102static int alloc_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer)
103{
104 buffer->addr = pci_alloc_consistent(card->pci_dev, buffer->size * buffer->cov,
105 &buffer->dma_handle);
106 if (buffer->addr == NULL)
107 return -1;
108
109 return 0;
110}
111
112static void free_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer)
113{
114 if (buffer->addr != NULL)
115 pci_free_consistent(card->pci_dev, buffer->size * buffer->cov,
116 buffer->addr, buffer->dma_handle);
117}
118
119int emu10k1_wavein_open(struct emu10k1_wavedevice *wave_dev)
120{
121 struct emu10k1_card *card = wave_dev->card;
122 struct wiinst *wiinst = wave_dev->wiinst;
123 struct wiinst **wiinst_tmp = NULL;
124 u16 delay;
125 unsigned long flags;
126
127 DPF(2, "emu10k1_wavein_open()\n");
128
129 switch (wiinst->recsrc) {
130 case WAVERECORD_AC97:
131 wiinst_tmp = &card->wavein.ac97;
132 break;
133 case WAVERECORD_MIC:
134 wiinst_tmp = &card->wavein.mic;
135 break;
136 case WAVERECORD_FX:
137 wiinst_tmp = &card->wavein.fx;
138 break;
139 default:
140 BUG();
141 break;
142 }
143
144 spin_lock_irqsave(&card->lock, flags);
145 if (*wiinst_tmp != NULL) {
146 spin_unlock_irqrestore(&card->lock, flags);
147 return -1;
148 }
149
150 *wiinst_tmp = wiinst;
151 spin_unlock_irqrestore(&card->lock, flags);
152
153 /* handle 8 bit recording */
154 if (wiinst->format.bytesperchannel == 1) {
155 if (wiinst->buffer.size > 0x8000) {
156 wiinst->buffer.size = 0x8000;
157 wiinst->buffer.sizeregval = 0x1f;
158 } else
159 wiinst->buffer.sizeregval += 4;
160
161 wiinst->buffer.cov = 2;
162 } else
163 wiinst->buffer.cov = 1;
164
165 if (alloc_buffer(card, &wiinst->buffer) < 0) {
166 ERROR();
167 return -1;
168 }
169
170 emu10k1_set_record_src(card, wiinst);
171
172 emu10k1_reset_record(card, &wiinst->buffer);
173
174 wiinst->buffer.hw_pos = 0;
175 wiinst->buffer.pos = 0;
176 wiinst->buffer.bytestocopy = 0;
177
178 delay = (48000 * wiinst->buffer.fragment_size) / wiinst->format.bytespersec;
179
180 emu10k1_timer_install(card, &wiinst->timer, delay / 2);
181
182 wiinst->state = WAVE_STATE_OPEN;
183
184 return 0;
185}
186
187void emu10k1_wavein_close(struct emu10k1_wavedevice *wave_dev)
188{
189 struct emu10k1_card *card = wave_dev->card;
190 struct wiinst *wiinst = wave_dev->wiinst;
191 unsigned long flags;
192
193 DPF(2, "emu10k1_wavein_close()\n");
194
195 emu10k1_wavein_stop(wave_dev);
196
197 emu10k1_timer_uninstall(card, &wiinst->timer);
198
199 free_buffer(card, &wiinst->buffer);
200
201 spin_lock_irqsave(&card->lock, flags);
202 switch (wave_dev->wiinst->recsrc) {
203 case WAVERECORD_AC97:
204 card->wavein.ac97 = NULL;
205 break;
206 case WAVERECORD_MIC:
207 card->wavein.mic = NULL;
208 break;
209 case WAVERECORD_FX:
210 card->wavein.fx = NULL;
211 break;
212 default:
213 BUG();
214 break;
215 }
216 spin_unlock_irqrestore(&card->lock, flags);
217
218 wiinst->state = WAVE_STATE_CLOSED;
219}
220
221void emu10k1_wavein_start(struct emu10k1_wavedevice *wave_dev)
222{
223 struct emu10k1_card *card = wave_dev->card;
224 struct wiinst *wiinst = wave_dev->wiinst;
225
226 DPF(2, "emu10k1_wavein_start()\n");
227
228 emu10k1_start_record(card, &wiinst->buffer);
229 emu10k1_timer_enable(wave_dev->card, &wiinst->timer);
230
231 wiinst->state |= WAVE_STATE_STARTED;
232}
233
234void emu10k1_wavein_stop(struct emu10k1_wavedevice *wave_dev)
235{
236 struct emu10k1_card *card = wave_dev->card;
237 struct wiinst *wiinst = wave_dev->wiinst;
238
239 DPF(2, "emu10k1_wavein_stop()\n");
240
241 if (!(wiinst->state & WAVE_STATE_STARTED))
242 return;
243
244 emu10k1_timer_disable(card, &wiinst->timer);
245 emu10k1_stop_record(card, &wiinst->buffer);
246
247 wiinst->state &= ~WAVE_STATE_STARTED;
248}
249
250int emu10k1_wavein_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_format *format)
251{
252 struct emu10k1_card *card = wave_dev->card;
253 struct wiinst *wiinst = wave_dev->wiinst;
254 u16 delay;
255
256 DPF(2, "emu10k1_wavein_setformat()\n");
257
258 if (wiinst->state & WAVE_STATE_STARTED)
259 return -1;
260
261 query_format(wiinst->recsrc, format);
262
263 if ((wiinst->format.samplingrate != format->samplingrate)
264 || (wiinst->format.bitsperchannel != format->bitsperchannel)
265 || (wiinst->format.channels != format->channels)) {
266
267 wiinst->format = *format;
268
269 if (wiinst->state == WAVE_STATE_CLOSED)
270 return 0;
271
272 wiinst->buffer.size *= wiinst->buffer.cov;
273
274 if (wiinst->format.bytesperchannel == 1) {
275 wiinst->buffer.cov = 2;
276 wiinst->buffer.size /= wiinst->buffer.cov;
277 } else
278 wiinst->buffer.cov = 1;
279
280 emu10k1_timer_uninstall(card, &wiinst->timer);
281
282 delay = (48000 * wiinst->buffer.fragment_size) / wiinst->format.bytespersec;
283
284 emu10k1_timer_install(card, &wiinst->timer, delay / 2);
285 }
286
287 return 0;
288}
289
290void emu10k1_wavein_getxfersize(struct wiinst *wiinst, u32 * size)
291{
292 struct wavein_buffer *buffer = &wiinst->buffer;
293
294 *size = buffer->bytestocopy;
295
296 if (wiinst->mmapped)
297 return;
298
299 if (*size > buffer->size) {
300 *size = buffer->size;
301 buffer->pos = buffer->hw_pos;
302 buffer->bytestocopy = buffer->size;
303 DPF(1, "buffer overrun\n");
304 }
305}
306
307static void copy_block(u8 __user *dst, u8 * src, u32 str, u32 len, u8 cov)
308{
309 if (cov == 1)
310 __copy_to_user(dst, src + str, len);
311 else {
312 u8 byte;
313 u32 i;
314
315 src += 1 + 2 * str;
316
317 for (i = 0; i < len; i++) {
318 byte = src[2 * i] ^ 0x80;
319 __copy_to_user(dst + i, &byte, 1);
320 }
321 }
322}
323
324void emu10k1_wavein_xferdata(struct wiinst *wiinst, u8 __user *data, u32 * size)
325{
326 struct wavein_buffer *buffer = &wiinst->buffer;
327 u32 sizetocopy, sizetocopy_now, start;
328 unsigned long flags;
329
330 sizetocopy = min_t(u32, buffer->size, *size);
331 *size = sizetocopy;
332
333 if (!sizetocopy)
334 return;
335
336 spin_lock_irqsave(&wiinst->lock, flags);
337 start = buffer->pos;
338 buffer->pos += sizetocopy;
339 buffer->pos %= buffer->size;
340 buffer->bytestocopy -= sizetocopy;
341 sizetocopy_now = buffer->size - start;
342
343 spin_unlock_irqrestore(&wiinst->lock, flags);
344
345 if (sizetocopy > sizetocopy_now) {
346 sizetocopy -= sizetocopy_now;
347
348 copy_block(data, buffer->addr, start, sizetocopy_now, buffer->cov);
349 copy_block(data + sizetocopy_now, buffer->addr, 0, sizetocopy, buffer->cov);
350 } else {
351 copy_block(data, buffer->addr, start, sizetocopy, buffer->cov);
352 }
353}
354
355void emu10k1_wavein_update(struct emu10k1_card *card, struct wiinst *wiinst)
356{
357 u32 hw_pos;
358 u32 diff;
359
360 /* There is no actual start yet */
361 if (!(wiinst->state & WAVE_STATE_STARTED)) {
362 hw_pos = wiinst->buffer.hw_pos;
363 } else {
364 /* hw_pos in byte units */
365 hw_pos = sblive_readptr(card, wiinst->buffer.idxreg, 0) / wiinst->buffer.cov;
366 }
367
368 diff = (wiinst->buffer.size + hw_pos - wiinst->buffer.hw_pos) % wiinst->buffer.size;
369 wiinst->total_recorded += diff;
370 wiinst->buffer.bytestocopy += diff;
371
372 wiinst->buffer.hw_pos = hw_pos;
373}
diff --git a/sound/oss/emu10k1/cardwi.h b/sound/oss/emu10k1/cardwi.h
new file mode 100644
index 000000000000..15cfb9b35596
--- /dev/null
+++ b/sound/oss/emu10k1/cardwi.h
@@ -0,0 +1,91 @@
1/*
2 **********************************************************************
3 * cardwi.h -- header file for card wave input functions
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31#ifndef _CARDWI_H
32#define _CARDWI_H
33
34#include "icardwav.h"
35#include "audio.h"
36#include "timer.h"
37
38struct wavein_buffer {
39 u16 ossfragshift;
40 u32 fragment_size;
41 u32 numfrags;
42 u32 hw_pos; /* hardware cursor position */
43 u32 pos; /* software cursor position */
44 u32 bytestocopy; /* bytes of recorded data available */
45 u32 size;
46 u32 pages;
47 u32 sizereg;
48 u32 sizeregval;
49 u32 addrreg;
50 u32 idxreg;
51 u32 adcctl;
52 void *addr;
53 u8 cov;
54 dma_addr_t dma_handle;
55};
56
57struct wiinst
58{
59 u8 state;
60 struct emu_timer timer;
61 struct wave_format format;
62 struct wavein_buffer buffer;
63 wait_queue_head_t wait_queue;
64 u8 mmapped;
65 u32 total_recorded; /* total bytes read() from device */
66 u32 blocks;
67 spinlock_t lock;
68 u8 recsrc;
69 u16 fxwc;
70};
71
72#define WAVEIN_MAXBUFSIZE 65536
73#define WAVEIN_MINBUFSIZE 368
74
75#define WAVEIN_DEFAULTFRAGLEN 100
76#define WAVEIN_DEFAULTBUFLEN 1000
77
78#define WAVEIN_MINFRAGSHIFT 8
79#define WAVEIN_MINFRAGS 2
80
81int emu10k1_wavein_open(struct emu10k1_wavedevice *);
82void emu10k1_wavein_close(struct emu10k1_wavedevice *);
83void emu10k1_wavein_start(struct emu10k1_wavedevice *);
84void emu10k1_wavein_stop(struct emu10k1_wavedevice *);
85void emu10k1_wavein_getxfersize(struct wiinst *, u32 *);
86void emu10k1_wavein_xferdata(struct wiinst *, u8 __user *, u32 *);
87int emu10k1_wavein_setformat(struct emu10k1_wavedevice *, struct wave_format *);
88void emu10k1_wavein_update(struct emu10k1_card *, struct wiinst *);
89
90
91#endif /* _CARDWI_H */
diff --git a/sound/oss/emu10k1/cardwo.c b/sound/oss/emu10k1/cardwo.c
new file mode 100644
index 000000000000..54daca4f57b4
--- /dev/null
+++ b/sound/oss/emu10k1/cardwo.c
@@ -0,0 +1,643 @@
1/*
2 **********************************************************************
3 * cardwo.c - PCM output HAL for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include <linux/poll.h>
33#include "hwaccess.h"
34#include "8010.h"
35#include "voicemgr.h"
36#include "cardwo.h"
37#include "audio.h"
38
39static u32 samplerate_to_linearpitch(u32 samplingrate)
40{
41 samplingrate = (samplingrate << 8) / 375;
42 return (samplingrate >> 1) + (samplingrate & 1);
43}
44
45static void query_format(struct emu10k1_wavedevice *wave_dev, struct wave_format *wave_fmt)
46{
47 int i, j, do_passthrough = 0, is_ac3 = 0;
48 struct emu10k1_card *card = wave_dev->card;
49 struct woinst *woinst = wave_dev->woinst;
50
51 if ((wave_fmt->channels > 2) && (wave_fmt->id != AFMT_S16_LE) && (wave_fmt->id != AFMT_U8))
52 wave_fmt->channels = 2;
53
54 if ((wave_fmt->channels < 1) || (wave_fmt->channels > WAVEOUT_MAXVOICES))
55 wave_fmt->channels = 2;
56
57 if (wave_fmt->channels == 2)
58 woinst->num_voices = 1;
59 else
60 woinst->num_voices = wave_fmt->channels;
61
62 if (wave_fmt->samplingrate >= 0x2ee00)
63 wave_fmt->samplingrate = 0x2ee00;
64
65 wave_fmt->passthrough = 0;
66 do_passthrough = is_ac3 = 0;
67
68 if (card->pt.selected)
69 do_passthrough = 1;
70
71 switch (wave_fmt->id) {
72 case AFMT_S16_LE:
73 wave_fmt->bitsperchannel = 16;
74 break;
75 case AFMT_U8:
76 wave_fmt->bitsperchannel = 8;
77 break;
78 case AFMT_AC3:
79 do_passthrough = 1;
80 is_ac3 = 1;
81 break;
82 default:
83 wave_fmt->id = AFMT_S16_LE;
84 wave_fmt->bitsperchannel = 16;
85 break;
86 }
87 if (do_passthrough) {
88 /* currently only one waveout instance may use pass-through */
89 if (woinst->state != WAVE_STATE_CLOSED ||
90 card->pt.state != PT_STATE_INACTIVE ||
91 (wave_fmt->samplingrate != 48000 && !is_ac3)) {
92 DPF(2, "unable to set pass-through mode\n");
93 } else if (USE_PT_METHOD1) {
94 i = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name, card->pt.intr_gpr_name);
95 j = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name, card->pt.enable_gpr_name);
96 if (i < 0 || j < 0)
97 DPF(2, "unable to set pass-through mode\n");
98 else {
99 wave_fmt->samplingrate = 48000;
100 wave_fmt->channels = 2;
101 card->pt.pos_gpr = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name,
102 card->pt.pos_gpr_name);
103 wave_fmt->passthrough = 1;
104 card->pt.intr_gpr = i;
105 card->pt.enable_gpr = j;
106 card->pt.state = PT_STATE_INACTIVE;
107
108 DPD(2, "is_ac3 is %d\n", is_ac3);
109 card->pt.ac3data = is_ac3;
110 wave_fmt->bitsperchannel = 16;
111 }
112 }else{
113 DPF(2, "Using Passthrough Method 2\n");
114 card->pt.enable_gpr = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name,
115 card->pt.enable_gpr_name);
116 wave_fmt->passthrough = 2;
117 wave_fmt->bitsperchannel = 16;
118 }
119 }
120
121 wave_fmt->bytesperchannel = wave_fmt->bitsperchannel >> 3;
122 wave_fmt->bytespersample = wave_fmt->channels * wave_fmt->bytesperchannel;
123 wave_fmt->bytespersec = wave_fmt->bytespersample * wave_fmt->samplingrate;
124
125 if (wave_fmt->channels == 2)
126 wave_fmt->bytespervoicesample = wave_fmt->channels * wave_fmt->bytesperchannel;
127 else
128 wave_fmt->bytespervoicesample = wave_fmt->bytesperchannel;
129}
130
131static int get_voice(struct emu10k1_card *card, struct woinst *woinst, unsigned int voicenum)
132{
133 struct emu_voice *voice = &woinst->voice[voicenum];
134
135 /* Allocate voices here, if no voices available, return error. */
136
137 voice->usage = VOICE_USAGE_PLAYBACK;
138
139 voice->flags = 0;
140
141 if (woinst->format.channels == 2)
142 voice->flags |= VOICE_FLAGS_STEREO;
143
144 if (woinst->format.bitsperchannel == 16)
145 voice->flags |= VOICE_FLAGS_16BIT;
146
147 if (emu10k1_voice_alloc(card, voice) < 0) {
148 voice->usage = VOICE_USAGE_FREE;
149 return -1;
150 }
151
152 /* Calculate pitch */
153 voice->initial_pitch = (u16) (srToPitch(woinst->format.samplingrate) >> 8);
154 voice->pitch_target = samplerate_to_linearpitch(woinst->format.samplingrate);
155
156 DPD(2, "Initial pitch --> %#x\n", voice->initial_pitch);
157
158 voice->startloop = (voice->mem.emupageindex << 12) /
159 woinst->format.bytespervoicesample;
160 voice->endloop = voice->startloop + woinst->buffer.size / woinst->format.bytespervoicesample;
161 voice->start = voice->startloop;
162
163
164 voice->params[0].volume_target = 0xffff;
165 voice->params[0].initial_fc = 0xff;
166 voice->params[0].initial_attn = 0x00;
167 voice->params[0].byampl_env_sustain = 0x7f;
168 voice->params[0].byampl_env_decay = 0x7f;
169
170
171 if (voice->flags & VOICE_FLAGS_STEREO) {
172 if (woinst->format.passthrough == 2) {
173 voice->params[0].send_routing = voice->params[1].send_routing = card->waveout.send_routing[ROUTE_PT];
174 voice->params[0].send_routing2 = voice->params[1].send_routing2 = card->waveout.send_routing2[ROUTE_PT];
175 voice->params[0].send_dcba = 0xff;
176 voice->params[1].send_dcba = 0xff00;
177 voice->params[0].send_hgfe = voice->params[1].send_hgfe=0;
178 } else {
179 voice->params[0].send_dcba = card->waveout.send_dcba[SEND_LEFT];
180 voice->params[0].send_hgfe = card->waveout.send_hgfe[SEND_LEFT];
181 voice->params[1].send_dcba = card->waveout.send_dcba[SEND_RIGHT];
182 voice->params[1].send_hgfe = card->waveout.send_hgfe[SEND_RIGHT];
183
184 if (woinst->device) {
185 // /dev/dps1
186 voice->params[0].send_routing = voice->params[1].send_routing = card->waveout.send_routing[ROUTE_PCM1];
187 voice->params[0].send_routing2 = voice->params[1].send_routing2 = card->waveout.send_routing2[ROUTE_PCM1];
188 } else {
189 voice->params[0].send_routing = voice->params[1].send_routing = card->waveout.send_routing[ROUTE_PCM];
190 voice->params[0].send_routing2 = voice->params[1].send_routing2 = card->waveout.send_routing2[ROUTE_PCM];
191 }
192 }
193
194 voice->params[1].volume_target = 0xffff;
195 voice->params[1].initial_fc = 0xff;
196 voice->params[1].initial_attn = 0x00;
197 voice->params[1].byampl_env_sustain = 0x7f;
198 voice->params[1].byampl_env_decay = 0x7f;
199 } else {
200 if (woinst->num_voices > 1) {
201 // Multichannel pcm
202 voice->params[0].send_dcba=0xff;
203 voice->params[0].send_hgfe=0;
204 if (card->is_audigy) {
205 voice->params[0].send_routing = 0x3f3f3f00 + card->mchannel_fx + voicenum;
206 voice->params[0].send_routing2 = 0x3f3f3f3f;
207 } else {
208 voice->params[0].send_routing = 0xfff0 + card->mchannel_fx + voicenum;
209 }
210
211 } else {
212 voice->params[0].send_dcba = card->waveout.send_dcba[SEND_MONO];
213 voice->params[0].send_hgfe = card->waveout.send_hgfe[SEND_MONO];
214
215 if (woinst->device) {
216 voice->params[0].send_routing = card->waveout.send_routing[ROUTE_PCM1];
217 voice->params[0].send_routing2 = card->waveout.send_routing2[ROUTE_PCM1];
218 } else {
219 voice->params[0].send_routing = card->waveout.send_routing[ROUTE_PCM];
220 voice->params[0].send_routing2 = card->waveout.send_routing2[ROUTE_PCM];
221 }
222 }
223 }
224
225 DPD(2, "voice: startloop=%#x, endloop=%#x\n", voice->startloop, voice->endloop);
226
227 emu10k1_voice_playback_setup(voice);
228
229 return 0;
230}
231
232int emu10k1_waveout_open(struct emu10k1_wavedevice *wave_dev)
233{
234 struct emu10k1_card *card = wave_dev->card;
235 struct woinst *woinst = wave_dev->woinst;
236 struct waveout_buffer *buffer = &woinst->buffer;
237 unsigned int voicenum;
238 u16 delay;
239
240 DPF(2, "emu10k1_waveout_open()\n");
241
242 for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
243 if (emu10k1_voice_alloc_buffer(card, &woinst->voice[voicenum].mem, woinst->buffer.pages) < 0) {
244 ERROR();
245 emu10k1_waveout_close(wave_dev);
246 return -1;
247 }
248
249 if (get_voice(card, woinst, voicenum) < 0) {
250 ERROR();
251 emu10k1_waveout_close(wave_dev);
252 return -1;
253 }
254 }
255
256 buffer->fill_silence = 0;
257 buffer->silence_bytes = 0;
258 buffer->silence_pos = 0;
259 buffer->hw_pos = 0;
260 buffer->free_bytes = woinst->buffer.size;
261
262 delay = (48000 * woinst->buffer.fragment_size) /
263 (woinst->format.samplingrate * woinst->format.bytespervoicesample);
264
265 emu10k1_timer_install(card, &woinst->timer, delay);
266
267 woinst->state = WAVE_STATE_OPEN;
268
269 return 0;
270}
271
272void emu10k1_waveout_close(struct emu10k1_wavedevice *wave_dev)
273{
274 struct emu10k1_card *card = wave_dev->card;
275 struct woinst *woinst = wave_dev->woinst;
276 unsigned int voicenum;
277
278 DPF(2, "emu10k1_waveout_close()\n");
279
280 emu10k1_waveout_stop(wave_dev);
281
282 emu10k1_timer_uninstall(card, &woinst->timer);
283
284 for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
285 emu10k1_voice_free(&woinst->voice[voicenum]);
286 emu10k1_voice_free_buffer(card, &woinst->voice[voicenum].mem);
287 }
288
289 woinst->state = WAVE_STATE_CLOSED;
290}
291
292void emu10k1_waveout_start(struct emu10k1_wavedevice *wave_dev)
293{
294 struct emu10k1_card *card = wave_dev->card;
295 struct woinst *woinst = wave_dev->woinst;
296 struct pt_data *pt = &card->pt;
297
298 DPF(2, "emu10k1_waveout_start()\n");
299
300 if (woinst->format.passthrough == 2) {
301 emu10k1_pt_setup(wave_dev);
302 sblive_writeptr(card, (card->is_audigy ? A_GPR_BASE : GPR_BASE) + pt->enable_gpr, 0, 1);
303 pt->state = PT_STATE_PLAYING;
304 }
305
306 /* Actual start */
307 emu10k1_voices_start(woinst->voice, woinst->num_voices, woinst->total_played);
308
309 emu10k1_timer_enable(card, &woinst->timer);
310
311 woinst->state |= WAVE_STATE_STARTED;
312}
313
314int emu10k1_waveout_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_format *format)
315{
316 struct emu10k1_card *card = wave_dev->card;
317 struct woinst *woinst = wave_dev->woinst;
318 unsigned int voicenum;
319 u16 delay;
320
321 DPF(2, "emu10k1_waveout_setformat()\n");
322
323 if (woinst->state & WAVE_STATE_STARTED)
324 return -1;
325
326 query_format(wave_dev, format);
327
328 if (woinst->format.samplingrate != format->samplingrate ||
329 woinst->format.channels != format->channels ||
330 woinst->format.bitsperchannel != format->bitsperchannel) {
331
332 woinst->format = *format;
333
334 if (woinst->state == WAVE_STATE_CLOSED)
335 return 0;
336
337 emu10k1_timer_uninstall(card, &woinst->timer);
338
339 for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
340 emu10k1_voice_free(&woinst->voice[voicenum]);
341
342 if (get_voice(card, woinst, voicenum) < 0) {
343 ERROR();
344 emu10k1_waveout_close(wave_dev);
345 return -1;
346 }
347 }
348
349 delay = (48000 * woinst->buffer.fragment_size) /
350 (woinst->format.samplingrate * woinst->format.bytespervoicesample);
351
352 emu10k1_timer_install(card, &woinst->timer, delay);
353 }
354
355 return 0;
356}
357
358void emu10k1_waveout_stop(struct emu10k1_wavedevice *wave_dev)
359{
360 struct emu10k1_card *card = wave_dev->card;
361 struct woinst *woinst = wave_dev->woinst;
362
363 DPF(2, "emu10k1_waveout_stop()\n");
364
365 if (!(woinst->state & WAVE_STATE_STARTED))
366 return;
367
368 emu10k1_timer_disable(card, &woinst->timer);
369
370 /* Stop actual voices */
371 emu10k1_voices_stop(woinst->voice, woinst->num_voices);
372
373 emu10k1_waveout_update(woinst);
374
375 woinst->state &= ~WAVE_STATE_STARTED;
376}
377
378/**
379 * emu10k1_waveout_getxfersize -
380 *
381 * gives the total free bytes on the voice buffer, including silence bytes
382 * (basically: total_free_bytes = free_bytes + silence_bytes).
383 *
384 */
385void emu10k1_waveout_getxfersize(struct woinst *woinst, u32 *total_free_bytes)
386{
387 struct waveout_buffer *buffer = &woinst->buffer;
388 int pending_bytes;
389
390 if (woinst->mmapped) {
391 *total_free_bytes = buffer->free_bytes;
392 return;
393 }
394
395 pending_bytes = buffer->size - buffer->free_bytes;
396
397 buffer->fill_silence = (pending_bytes < (signed) buffer->fragment_size * 2) ? 1 : 0;
398
399 if (pending_bytes > (signed) buffer->silence_bytes) {
400 *total_free_bytes = (buffer->free_bytes + buffer->silence_bytes);
401 } else {
402 *total_free_bytes = buffer->size;
403 buffer->silence_bytes = pending_bytes;
404 if (pending_bytes < 0) {
405 buffer->silence_pos = buffer->hw_pos;
406 buffer->silence_bytes = 0;
407 buffer->free_bytes = buffer->size;
408 DPF(1, "buffer underrun\n");
409 }
410 }
411}
412
413/**
414 * copy_block -
415 *
416 * copies a block of pcm data to a voice buffer.
417 * Notice that the voice buffer is actually a set of disjointed memory pages.
418 *
419 */
420static void copy_block(void **dst, u32 str, u8 __user *src, u32 len)
421{
422 unsigned int pg;
423 unsigned int pgoff;
424 unsigned int k;
425
426 pg = str / PAGE_SIZE;
427 pgoff = str % PAGE_SIZE;
428
429 if (len > PAGE_SIZE - pgoff) {
430 k = PAGE_SIZE - pgoff;
431 if (__copy_from_user((u8 *)dst[pg] + pgoff, src, k))
432 return;
433 len -= k;
434 while (len > PAGE_SIZE) {
435 if (__copy_from_user(dst[++pg], src + k, PAGE_SIZE))
436 return;
437 k += PAGE_SIZE;
438 len -= PAGE_SIZE;
439 }
440 if (__copy_from_user(dst[++pg], src + k, len))
441 return;
442
443 } else
444 __copy_from_user((u8 *)dst[pg] + pgoff, src, len);
445}
446
447/**
448 * copy_ilv_block -
449 *
450 * copies a block of pcm data containing n interleaved channels to n mono voice buffers.
451 * Notice that the voice buffer is actually a set of disjointed memory pages.
452 *
453 */
454static void copy_ilv_block(struct woinst *woinst, u32 str, u8 __user *src, u32 len)
455{
456 unsigned int pg;
457 unsigned int pgoff;
458 unsigned int voice_num;
459 struct emu_voice *voice = woinst->voice;
460
461 pg = str / PAGE_SIZE;
462 pgoff = str % PAGE_SIZE;
463
464 while (len) {
465 for (voice_num = 0; voice_num < woinst->num_voices; voice_num++) {
466 if (__copy_from_user((u8 *)(voice[voice_num].mem.addr[pg]) + pgoff, src, woinst->format.bytespervoicesample))
467 return;
468 src += woinst->format.bytespervoicesample;
469 }
470
471 len -= woinst->format.bytespervoicesample;
472
473 pgoff += woinst->format.bytespervoicesample;
474 if (pgoff >= PAGE_SIZE) {
475 pgoff = 0;
476 pg++;
477 }
478 }
479}
480
481/**
482 * fill_block -
483 *
484 * fills a set voice buffers with a block of a given sample.
485 *
486 */
487static void fill_block(struct woinst *woinst, u32 str, u8 data, u32 len)
488{
489 unsigned int pg;
490 unsigned int pgoff;
491 unsigned int voice_num;
492 struct emu_voice *voice = woinst->voice;
493 unsigned int k;
494
495 pg = str / PAGE_SIZE;
496 pgoff = str % PAGE_SIZE;
497
498 if (len > PAGE_SIZE - pgoff) {
499 k = PAGE_SIZE - pgoff;
500 for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
501 memset((u8 *)voice[voice_num].mem.addr[pg] + pgoff, data, k);
502 len -= k;
503 while (len > PAGE_SIZE) {
504 pg++;
505 for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
506 memset(voice[voice_num].mem.addr[pg], data, PAGE_SIZE);
507
508 len -= PAGE_SIZE;
509 }
510 pg++;
511 for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
512 memset(voice[voice_num].mem.addr[pg], data, len);
513
514 } else {
515 for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
516 memset((u8 *)voice[voice_num].mem.addr[pg] + pgoff, data, len);
517 }
518}
519
520/**
521 * emu10k1_waveout_xferdata -
522 *
523 * copies pcm data to the voice buffer. Silence samples
524 * previously added to the buffer are overwritten.
525 *
526 */
527void emu10k1_waveout_xferdata(struct woinst *woinst, u8 __user *data, u32 *size)
528{
529 struct waveout_buffer *buffer = &woinst->buffer;
530 struct voice_mem *mem = &woinst->voice[0].mem;
531 u32 sizetocopy, sizetocopy_now, start;
532 unsigned long flags;
533
534 sizetocopy = min_t(u32, buffer->size, *size);
535 *size = sizetocopy;
536
537 if (!sizetocopy)
538 return;
539
540 spin_lock_irqsave(&woinst->lock, flags);
541 start = (buffer->size + buffer->silence_pos - buffer->silence_bytes) % buffer->size;
542
543 if (sizetocopy > buffer->silence_bytes) {
544 buffer->silence_pos += sizetocopy - buffer->silence_bytes;
545 buffer->free_bytes -= sizetocopy - buffer->silence_bytes;
546 buffer->silence_bytes = 0;
547 } else
548 buffer->silence_bytes -= sizetocopy;
549
550 spin_unlock_irqrestore(&woinst->lock, flags);
551
552 sizetocopy_now = buffer->size - start;
553 if (sizetocopy > sizetocopy_now) {
554 sizetocopy -= sizetocopy_now;
555 if (woinst->num_voices > 1) {
556 copy_ilv_block(woinst, start, data, sizetocopy_now);
557 copy_ilv_block(woinst, 0, data + sizetocopy_now * woinst->num_voices, sizetocopy);
558 } else {
559 copy_block(mem->addr, start, data, sizetocopy_now);
560 copy_block(mem->addr, 0, data + sizetocopy_now, sizetocopy);
561 }
562 } else {
563 if (woinst->num_voices > 1)
564 copy_ilv_block(woinst, start, data, sizetocopy);
565 else
566 copy_block(mem->addr, start, data, sizetocopy);
567 }
568}
569
570/**
571 * emu10k1_waveout_fillsilence -
572 *
573 * adds samples of silence to the voice buffer so that we
574 * don't loop over stale pcm data.
575 *
576 */
577void emu10k1_waveout_fillsilence(struct woinst *woinst)
578{
579 struct waveout_buffer *buffer = &woinst->buffer;
580 u32 sizetocopy, sizetocopy_now, start;
581 u8 filldata;
582 unsigned long flags;
583
584 sizetocopy = buffer->fragment_size;
585
586 if (woinst->format.bitsperchannel == 16)
587 filldata = 0x00;
588 else
589 filldata = 0x80;
590
591 spin_lock_irqsave(&woinst->lock, flags);
592 buffer->silence_bytes += sizetocopy;
593 buffer->free_bytes -= sizetocopy;
594 buffer->silence_pos %= buffer->size;
595 start = buffer->silence_pos;
596 buffer->silence_pos += sizetocopy;
597 spin_unlock_irqrestore(&woinst->lock, flags);
598
599 sizetocopy_now = buffer->size - start;
600
601 if (sizetocopy > sizetocopy_now) {
602 sizetocopy -= sizetocopy_now;
603 fill_block(woinst, start, filldata, sizetocopy_now);
604 fill_block(woinst, 0, filldata, sizetocopy);
605 } else {
606 fill_block(woinst, start, filldata, sizetocopy);
607 }
608}
609
610/**
611 * emu10k1_waveout_update -
612 *
613 * updates the position of the voice buffer hardware pointer (hw_pos)
614 * and the number of free bytes on the buffer (free_bytes).
615 * The free bytes _don't_ include silence bytes that may have been
616 * added to the buffer.
617 *
618 */
619void emu10k1_waveout_update(struct woinst *woinst)
620{
621 u32 hw_pos;
622 u32 diff;
623
624 /* There is no actual start yet */
625 if (!(woinst->state & WAVE_STATE_STARTED)) {
626 hw_pos = woinst->buffer.hw_pos;
627 } else {
628 /* hw_pos in sample units */
629 hw_pos = sblive_readptr(woinst->voice[0].card, CCCA_CURRADDR, woinst->voice[0].num);
630
631 if(hw_pos < woinst->voice[0].start)
632 hw_pos += woinst->buffer.size / woinst->format.bytespervoicesample - woinst->voice[0].start;
633 else
634 hw_pos -= woinst->voice[0].start;
635
636 hw_pos *= woinst->format.bytespervoicesample;
637 }
638
639 diff = (woinst->buffer.size + hw_pos - woinst->buffer.hw_pos) % woinst->buffer.size;
640 woinst->total_played += diff;
641 woinst->buffer.free_bytes += diff;
642 woinst->buffer.hw_pos = hw_pos;
643}
diff --git a/sound/oss/emu10k1/cardwo.h b/sound/oss/emu10k1/cardwo.h
new file mode 100644
index 000000000000..1dece8853e5c
--- /dev/null
+++ b/sound/oss/emu10k1/cardwo.h
@@ -0,0 +1,90 @@
1/*
2 **********************************************************************
3 * cardwo.h -- header file for card wave out functions
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _CARDWO_H
33#define _CARDWO_H
34
35#include "icardwav.h"
36#include "audio.h"
37#include "voicemgr.h"
38#include "timer.h"
39
40/* setting this to other than a power of two may break some applications */
41#define WAVEOUT_MAXBUFSIZE MAXBUFSIZE
42
43#define WAVEOUT_DEFAULTFRAGLEN 20 /* Time to play a fragment in ms (latency) */
44#define WAVEOUT_DEFAULTBUFLEN 500 /* Time to play the entire buffer in ms */
45
46#define WAVEOUT_MINFRAGSHIFT 6 /* Minimum fragment size in bytes is 2^6 */
47#define WAVEOUT_MINFRAGS 3 /* _don't_ go bellow 3, it would break silence filling */
48#define WAVEOUT_MAXVOICES 6
49
50struct waveout_buffer {
51 u16 ossfragshift;
52 u32 numfrags;
53 u32 fragment_size; /* in bytes units */
54 u32 size; /* in bytes units */
55 u32 pages; /* buffer size in page units*/
56 u32 silence_pos; /* software cursor position (including silence bytes) */
57 u32 hw_pos; /* hardware cursor position */
58 u32 free_bytes; /* free bytes available on the buffer (not including silence bytes) */
59 u8 fill_silence;
60 u32 silence_bytes; /* silence bytes on the buffer */
61};
62
63struct woinst
64{
65 u8 state;
66 u8 num_voices;
67 struct emu_voice voice[WAVEOUT_MAXVOICES];
68 struct emu_timer timer;
69 struct wave_format format;
70 struct waveout_buffer buffer;
71 wait_queue_head_t wait_queue;
72 u8 mmapped;
73 u32 total_copied; /* total number of bytes written() to the buffer (excluding silence) */
74 u32 total_played; /* total number of bytes played including silence */
75 u32 blocks;
76 u8 device;
77 spinlock_t lock;
78};
79
80int emu10k1_waveout_open(struct emu10k1_wavedevice *);
81void emu10k1_waveout_close(struct emu10k1_wavedevice *);
82void emu10k1_waveout_start(struct emu10k1_wavedevice *);
83void emu10k1_waveout_stop(struct emu10k1_wavedevice *);
84void emu10k1_waveout_getxfersize(struct woinst*, u32 *);
85void emu10k1_waveout_xferdata(struct woinst*, u8 __user *, u32 *);
86void emu10k1_waveout_fillsilence(struct woinst*);
87int emu10k1_waveout_setformat(struct emu10k1_wavedevice*, struct wave_format*);
88void emu10k1_waveout_update(struct woinst*);
89
90#endif /* _CARDWO_H */
diff --git a/sound/oss/emu10k1/ecard.c b/sound/oss/emu10k1/ecard.c
new file mode 100644
index 000000000000..4ae635fe1402
--- /dev/null
+++ b/sound/oss/emu10k1/ecard.c
@@ -0,0 +1,157 @@
1/*
2 **********************************************************************
3 * ecard.c - E-card initialization code
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include "ecard.h"
33#include "hwaccess.h"
34
35/* Private routines */
36static void ecard_setadcgain(struct emu10k1_card *, struct ecard_state *, u16);
37static void ecard_write(struct emu10k1_card *, u32);
38
39/**************************************************************************
40 * @func Set the gain of the ECARD's CS3310 Trim/gain controller. The
41 * trim value consists of a 16bit value which is composed of two
42 * 8 bit gain/trim values, one for the left channel and one for the
43 * right channel. The following table maps from the Gain/Attenuation
44 * value in decibels into the corresponding bit pattern for a single
45 * channel.
46 */
47
48static void ecard_setadcgain(struct emu10k1_card *card, struct ecard_state *ecard, u16 gain)
49{
50 u32 currbit;
51 ecard->adc_gain = gain;
52
53 /* Enable writing to the TRIM registers */
54 ecard_write(card, ecard->control_bits & ~EC_TRIM_CSN);
55
56 /* Do it again to insure that we meet hold time requirements */
57 ecard_write(card, ecard->control_bits & ~EC_TRIM_CSN);
58
59 for (currbit = (1L << 15); currbit; currbit >>= 1) {
60
61 u32 value = ecard->control_bits & ~(EC_TRIM_CSN|EC_TRIM_SDATA);
62
63 if (gain & currbit)
64 value |= EC_TRIM_SDATA;
65
66 /* Clock the bit */
67 ecard_write(card, value);
68 ecard_write(card, value | EC_TRIM_SCLK);
69 ecard_write(card, value);
70 }
71
72 ecard_write(card, ecard->control_bits);
73}
74
75/**************************************************************************
76 * @func Clock bits into the Ecard's control latch. The Ecard uses a
77 * control latch will is loaded bit-serially by toggling the Modem control
78 * lines from function 2 on the E8010. This function hides these details
79 * and presents the illusion that we are actually writing to a distinct
80 * register.
81 */
82static void ecard_write(struct emu10k1_card *card, u32 value)
83{
84 u16 count;
85 u32 data, hcvalue;
86 unsigned long flags;
87
88 spin_lock_irqsave(&card->lock, flags);
89
90 hcvalue = inl(card->iobase + HCFG) & ~(HOOKN_BIT|HANDN_BIT|PULSEN_BIT);
91
92 outl(card->iobase + HCFG, hcvalue);
93
94 for (count = 0 ; count < EC_NUM_CONTROL_BITS; count++) {
95
96 /* Set up the value */
97 data = ((value & 0x1) ? PULSEN_BIT : 0);
98 value >>= 1;
99
100 outl(card->iobase + HCFG, hcvalue | data);
101
102 /* Clock the shift register */
103 outl(card->iobase + HCFG, hcvalue | data | HANDN_BIT);
104 outl(card->iobase + HCFG, hcvalue | data);
105 }
106
107 /* Latch the bits */
108 outl(card->iobase + HCFG, hcvalue | HOOKN_BIT);
109 outl(card->iobase + HCFG, hcvalue);
110
111 spin_unlock_irqrestore(&card->lock, flags);
112}
113
114void __devinit emu10k1_ecard_init(struct emu10k1_card *card)
115{
116 u32 hcvalue;
117 struct ecard_state ecard;
118
119 /* Set up the initial settings */
120 ecard.mux0_setting = EC_DEFAULT_SPDIF0_SEL;
121 ecard.mux1_setting = EC_DEFAULT_SPDIF1_SEL;
122 ecard.mux2_setting = 0;
123 ecard.adc_gain = EC_DEFAULT_ADC_GAIN;
124 ecard.control_bits = EC_RAW_RUN_MODE |
125 EC_SPDIF0_SELECT(ecard.mux0_setting) |
126 EC_SPDIF1_SELECT(ecard.mux1_setting);
127
128
129 /* Step 0: Set the codec type in the hardware control register
130 * and enable audio output */
131 hcvalue = emu10k1_readfn0(card, HCFG);
132 emu10k1_writefn0(card, HCFG, hcvalue | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S);
133
134 /* Step 1: Turn off the led and deassert TRIM_CS */
135 ecard_write(card, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
136
137 /* Step 2: Calibrate the ADC and DAC */
138 ecard_write(card, EC_DACCAL | EC_LEDN | EC_TRIM_CSN);
139
140 /* Step 3: Wait for awhile; FIXME: Is this correct? */
141
142 current->state = TASK_INTERRUPTIBLE;
143 schedule_timeout(HZ);
144
145 /* Step 4: Switch off the DAC and ADC calibration. Note
146 * That ADC_CAL is actually an inverted signal, so we assert
147 * it here to stop calibration. */
148 ecard_write(card, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
149
150 /* Step 4: Switch into run mode */
151 ecard_write(card, ecard.control_bits);
152
153 /* Step 5: Set the analog input gain */
154 ecard_setadcgain(card, &ecard, ecard.adc_gain);
155}
156
157
diff --git a/sound/oss/emu10k1/ecard.h b/sound/oss/emu10k1/ecard.h
new file mode 100644
index 000000000000..67aead16e8ec
--- /dev/null
+++ b/sound/oss/emu10k1/ecard.h
@@ -0,0 +1,113 @@
1/*
2 **********************************************************************
3 * ecard.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 * USA.
22 *
23 **********************************************************************
24 */
25
26#ifndef _ECARD_H
27#define _ECARD_H
28
29#include "8010.h"
30#include "hwaccess.h"
31#include <linux/init.h>
32
33/* In A1 Silicon, these bits are in the HC register */
34#define HOOKN_BIT (1L << 12)
35#define HANDN_BIT (1L << 11)
36#define PULSEN_BIT (1L << 10)
37
38#define EC_GDI1 (1 << 13)
39#define EC_GDI0 (1 << 14)
40
41#define EC_NUM_CONTROL_BITS 20
42
43#define EC_AC3_DATA_SELN 0x0001L
44#define EC_EE_DATA_SEL 0x0002L
45#define EC_EE_CNTRL_SELN 0x0004L
46#define EC_EECLK 0x0008L
47#define EC_EECS 0x0010L
48#define EC_EESDO 0x0020L
49#define EC_TRIM_CSN 0x0040L
50#define EC_TRIM_SCLK 0x0080L
51#define EC_TRIM_SDATA 0x0100L
52#define EC_TRIM_MUTEN 0x0200L
53#define EC_ADCCAL 0x0400L
54#define EC_ADCRSTN 0x0800L
55#define EC_DACCAL 0x1000L
56#define EC_DACMUTEN 0x2000L
57#define EC_LEDN 0x4000L
58
59#define EC_SPDIF0_SEL_SHIFT 15
60#define EC_SPDIF1_SEL_SHIFT 17
61#define EC_SPDIF0_SEL_MASK (0x3L << EC_SPDIF0_SEL_SHIFT)
62#define EC_SPDIF1_SEL_MASK (0x7L << EC_SPDIF1_SEL_SHIFT)
63#define EC_SPDIF0_SELECT(_x) (((_x) << EC_SPDIF0_SEL_SHIFT) & EC_SPDIF0_SEL_MASK)
64#define EC_SPDIF1_SELECT(_x) (((_x) << EC_SPDIF1_SEL_SHIFT) & EC_SPDIF1_SEL_MASK)
65#define EC_CURRENT_PROM_VERSION 0x01 /* Self-explanatory. This should
66 * be incremented any time the EEPROM's
67 * format is changed. */
68
69#define EC_EEPROM_SIZE 0x40 /* ECARD EEPROM has 64 16-bit words */
70
71/* Addresses for special values stored in to EEPROM */
72#define EC_PROM_VERSION_ADDR 0x20 /* Address of the current prom version */
73#define EC_BOARDREV0_ADDR 0x21 /* LSW of board rev */
74#define EC_BOARDREV1_ADDR 0x22 /* MSW of board rev */
75
76#define EC_LAST_PROMFILE_ADDR 0x2f
77
78#define EC_SERIALNUM_ADD 0x30 /* First word of serial number. The number
79 * can be up to 30 characters in length
80 * and is stored as a NULL-terminated
81 * ASCII string. Any unused bytes must be
82 * filled with zeros */
83#define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */
84
85
86
87/* Most of this stuff is pretty self-evident. According to the hardware
88 * dudes, we need to leave the ADCCAL bit low in order to avoid a DC
89 * offset problem. Weird.
90 */
91#define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | EC_TRIM_CSN)
92
93
94#define EC_DEFAULT_ADC_GAIN 0xC4C4
95#define EC_DEFAULT_SPDIF0_SEL 0x0
96#define EC_DEFAULT_SPDIF1_SEL 0x4
97
98#define HC_EA 0x01L
99
100/* ECARD state structure. This structure maintains the state
101 * for various portions of the ECARD's onboard hardware.
102 */
103struct ecard_state {
104 u32 control_bits;
105 u16 adc_gain;
106 u16 mux0_setting;
107 u16 mux1_setting;
108 u16 mux2_setting;
109};
110
111void emu10k1_ecard_init(struct emu10k1_card *) __devinit;
112
113#endif /* _ECARD_H */
diff --git a/sound/oss/emu10k1/efxmgr.c b/sound/oss/emu10k1/efxmgr.c
new file mode 100644
index 000000000000..7d5865de4c2e
--- /dev/null
+++ b/sound/oss/emu10k1/efxmgr.c
@@ -0,0 +1,220 @@
1/*
2 **********************************************************************
3 * efxmgr.c
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include <linux/bitops.h>
33#include "hwaccess.h"
34#include "efxmgr.h"
35
36int emu10k1_find_control_gpr(struct patch_manager *mgr, const char *patch_name, const char *gpr_name)
37{
38 struct dsp_patch *patch;
39 struct dsp_rpatch *rpatch;
40 char s[PATCH_NAME_SIZE + 4];
41 unsigned long *gpr_used;
42 int i;
43
44 DPD(2, "emu10k1_find_control_gpr(): %s %s\n", patch_name, gpr_name);
45
46 rpatch = &mgr->rpatch;
47 if (!strcmp(rpatch->name, patch_name)) {
48 gpr_used = rpatch->gpr_used;
49 goto match;
50 }
51
52 for (i = 0; i < mgr->current_pages * PATCHES_PER_PAGE; i++) {
53 patch = PATCH(mgr, i);
54 sprintf(s,"%s", patch->name);
55
56 if (!strcmp(s, patch_name)) {
57 gpr_used = patch->gpr_used;
58 goto match;
59 }
60 }
61
62 return -1;
63
64 match:
65 for (i = 0; i < NUM_GPRS; i++)
66 if (mgr->gpr[i].type == GPR_TYPE_CONTROL &&
67 test_bit(i, gpr_used) &&
68 !strcmp(mgr->gpr[i].name, gpr_name))
69 return i;
70
71 return -1;
72}
73
74void emu10k1_set_control_gpr(struct emu10k1_card *card, int addr, s32 val, int flag)
75{
76 struct patch_manager *mgr = &card->mgr;
77
78 DPD(2, "emu10k1_set_control_gpr(): %d %x\n", addr, val);
79
80 if (addr < 0 || addr >= NUM_GPRS)
81 return;
82
83 //fixme: once patch manager is up, remember to fix this for the audigy
84 if (card->is_audigy) {
85 sblive_writeptr(card, A_GPR_BASE + addr, 0, val);
86 } else {
87 if (flag)
88 val += sblive_readptr(card, GPR_BASE + addr, 0);
89 if (val > mgr->gpr[addr].max)
90 val = mgr->gpr[addr].max;
91 else if (val < mgr->gpr[addr].min)
92 val = mgr->gpr[addr].min;
93 sblive_writeptr(card, GPR_BASE + addr, 0, val);
94 }
95
96
97}
98
99//TODO: make this configurable:
100#define VOLCTRL_CHANNEL SOUND_MIXER_VOLUME
101#define VOLCTRL_STEP_SIZE 5
102
103//An internal function for setting OSS mixer controls.
104static void emu10k1_set_oss_vol(struct emu10k1_card *card, int oss_mixer,
105 unsigned int left, unsigned int right)
106{
107 extern char volume_params[SOUND_MIXER_NRDEVICES];
108
109 card->ac97->mixer_state[oss_mixer] = (right << 8) | left;
110
111 if (!card->is_aps)
112 card->ac97->write_mixer(card->ac97, oss_mixer, left, right);
113
114 emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][0], left,
115 volume_params[oss_mixer]);
116
117 emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][1], right,
118 volume_params[oss_mixer]);
119}
120
121//FIXME: mute should unmute when pressed a second time
122void emu10k1_mute_irqhandler(struct emu10k1_card *card)
123{
124 int oss_channel = VOLCTRL_CHANNEL;
125 int left, right;
126 static int val;
127
128 if (val) {
129 left = val & 0xff;
130 right = (val >> 8) & 0xff;
131 val = 0;
132 } else {
133 val = card->ac97->mixer_state[oss_channel];
134 left = 0;
135 right = 0;
136 }
137
138 emu10k1_set_oss_vol(card, oss_channel, left, right);
139}
140
141void emu10k1_volincr_irqhandler(struct emu10k1_card *card)
142{
143 int oss_channel = VOLCTRL_CHANNEL;
144 int left, right;
145
146 left = card->ac97->mixer_state[oss_channel] & 0xff;
147 right = (card->ac97->mixer_state[oss_channel] >> 8) & 0xff;
148
149 if ((left += VOLCTRL_STEP_SIZE) > 100)
150 left = 100;
151
152 if ((right += VOLCTRL_STEP_SIZE) > 100)
153 right = 100;
154
155 emu10k1_set_oss_vol(card, oss_channel, left, right);
156}
157
158void emu10k1_voldecr_irqhandler(struct emu10k1_card *card)
159{
160 int oss_channel = VOLCTRL_CHANNEL;
161 int left, right;
162
163 left = card->ac97->mixer_state[oss_channel] & 0xff;
164 right = (card->ac97->mixer_state[oss_channel] >> 8) & 0xff;
165
166 if ((left -= VOLCTRL_STEP_SIZE) < 0)
167 left = 0;
168
169 if ((right -= VOLCTRL_STEP_SIZE) < 0)
170 right = 0;
171
172 emu10k1_set_oss_vol(card, oss_channel, left, right);
173}
174
175void emu10k1_set_volume_gpr(struct emu10k1_card *card, int addr, s32 vol, int scale)
176{
177 struct patch_manager *mgr = &card->mgr;
178 unsigned long flags;
179
180 static const s32 log2lin[4] ={ // attenuation (dB)
181 0x7fffffff, // 0.0
182 0x7fffffff * 0.840896415253715 , // 1.5
183 0x7fffffff * 0.707106781186548, // 3.0
184 0x7fffffff * 0.594603557501361 , // 4.5
185 };
186
187 if (addr < 0)
188 return;
189
190 vol = (100 - vol ) * scale / 100;
191
192 // Thanks to the comp.dsp newsgroup for this neat trick:
193 vol = (vol >= scale) ? 0 : (log2lin[vol & 3] >> (vol >> 2));
194
195 spin_lock_irqsave(&mgr->lock, flags);
196 emu10k1_set_control_gpr(card, addr, vol, 0);
197 spin_unlock_irqrestore(&mgr->lock, flags);
198}
199
200void emu10k1_dsp_irqhandler(struct emu10k1_card *card)
201{
202 unsigned long flags;
203
204 if (card->pt.state != PT_STATE_INACTIVE) {
205 u32 bc;
206 bc = sblive_readptr(card, GPR_BASE + card->pt.intr_gpr, 0);
207 if (bc != 0) {
208 DPD(3, "pt interrupt, bc = %d\n", bc);
209 spin_lock_irqsave(&card->pt.lock, flags);
210 card->pt.blocks_played = bc;
211 if (card->pt.blocks_played >= card->pt.blocks_copied) {
212 DPF(1, "buffer underrun in passthrough playback\n");
213 emu10k1_pt_stop(card);
214 }
215 wake_up_interruptible(&card->pt.wait);
216 spin_unlock_irqrestore(&card->pt.lock, flags);
217 }
218 }
219}
220
diff --git a/sound/oss/emu10k1/efxmgr.h b/sound/oss/emu10k1/efxmgr.h
new file mode 100644
index 000000000000..ef48e5c70d1f
--- /dev/null
+++ b/sound/oss/emu10k1/efxmgr.h
@@ -0,0 +1,270 @@
1/*
2 **********************************************************************
3 * sblive_fx.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _EFXMGR_H
33#define _EFXMGR_H
34
35struct emu_efx_info_t{
36 int opcode_shift;
37 int high_operand_shift;
38 int instruction_start;
39 int gpr_base;
40 int output_base;
41};
42
43
44#define WRITE_EFX(a, b, c) sblive_writeptr((a), emu_efx_info[card->is_audigy].instruction_start + (b), 0, (c))
45
46#define OP(op, z, w, x, y) \
47 do { WRITE_EFX(card, (pc) * 2, ((x) << emu_efx_info[card->is_audigy].high_operand_shift) | (y)); \
48 WRITE_EFX(card, (pc) * 2 + 1, ((op) << emu_efx_info[card->is_audigy].opcode_shift ) | ((z) << emu_efx_info[card->is_audigy].high_operand_shift) | (w)); \
49 ++pc; } while (0)
50
51#define NUM_INPUTS 0x20
52#define NUM_OUTPUTS 0x20
53#define NUM_GPRS 0x100
54
55#define A_NUM_INPUTS 0x60
56#define A_NUM_OUTPUTS 0x60 //fixme: this may or may not be true
57#define A_NUM_GPRS 0x200
58
59#define GPR_NAME_SIZE 32
60#define PATCH_NAME_SIZE 32
61
62struct dsp_rpatch {
63 char name[PATCH_NAME_SIZE];
64 u16 code_start;
65 u16 code_size;
66
67 unsigned long gpr_used[NUM_GPRS / (sizeof(unsigned long) * 8) + 1];
68 unsigned long gpr_input[NUM_GPRS / (sizeof(unsigned long) * 8) + 1];
69 unsigned long route[NUM_OUTPUTS];
70 unsigned long route_v[NUM_OUTPUTS];
71};
72
73struct dsp_patch {
74 char name[PATCH_NAME_SIZE];
75 u8 id;
76 unsigned long input; /* bitmap of the lines used as inputs */
77 unsigned long output; /* bitmap of the lines used as outputs */
78 u16 code_start;
79 u16 code_size;
80
81 unsigned long gpr_used[NUM_GPRS / (sizeof(unsigned long) * 8) + 1]; /* bitmap of used gprs */
82 unsigned long gpr_input[NUM_GPRS / (sizeof(unsigned long) * 8) + 1];
83 u8 traml_istart; /* starting address of the internal tram lines used */
84 u8 traml_isize; /* number of internal tram lines used */
85
86 u8 traml_estart;
87 u8 traml_esize;
88
89 u16 tramb_istart; /* starting address of the internal tram memory used */
90 u16 tramb_isize; /* amount of internal memory used */
91 u32 tramb_estart;
92 u32 tramb_esize;
93};
94
95struct dsp_gpr {
96 u8 type; /* gpr type, STATIC, DYNAMIC, INPUT, OUTPUT, CONTROL */
97 char name[GPR_NAME_SIZE]; /* gpr value, only valid for control gprs */
98 s32 min, max; /* value range for this gpr, only valid for control gprs */
99 u8 line; /* which input/output line is the gpr attached, only valid for input/output gprs */
100 u8 usage;
101};
102
103enum {
104 GPR_TYPE_NULL = 0,
105 GPR_TYPE_IO,
106 GPR_TYPE_STATIC,
107 GPR_TYPE_DYNAMIC,
108 GPR_TYPE_CONTROL,
109 GPR_TYPE_CONSTANT
110};
111
112#define GPR_BASE 0x100
113#define OUTPUT_BASE 0x20
114
115#define A_GPR_BASE 0x400
116#define A_OUTPUT_BASE 0x60
117
118#define MAX_PATCHES_PAGES 32
119
120struct patch_manager {
121 void *patch[MAX_PATCHES_PAGES];
122 int current_pages;
123 struct dsp_rpatch rpatch;
124 struct dsp_gpr gpr[NUM_GPRS]; /* gpr usage table */
125 spinlock_t lock;
126 s16 ctrl_gpr[SOUND_MIXER_NRDEVICES][2];
127};
128
129#define PATCHES_PER_PAGE (PAGE_SIZE / sizeof(struct dsp_patch))
130
131#define PATCH(mgr, i) ((struct dsp_patch *) (mgr)->patch[(i) / PATCHES_PER_PAGE] + (i) % PATCHES_PER_PAGE)
132
133/* PCM volume control */
134#define TMP_PCM_L 0x100 //temp PCM L (after the vol control)
135#define TMP_PCM_R 0x101
136#define VOL_PCM_L 0x102 //vol PCM
137#define VOL_PCM_R 0x103
138
139/* Routing patch */
140#define TMP_AC_L 0x104 //tmp ac97 out
141#define TMP_AC_R 0x105
142#define TMP_REAR_L 0x106 //output - Temp Rear
143#define TMP_REAR_R 0x107
144#define TMP_DIGI_L 0x108 //output - Temp digital
145#define TMP_DIGI_R 0x109
146#define DSP_VOL_L 0x10a // main dsp volume
147#define DSP_VOL_R 0x10b
148
149/* hw inputs */
150#define PCM_IN_L 0x00
151#define PCM_IN_R 0x01
152
153#define PCM1_IN_L 0x04
154#define PCM1_IN_R 0x05
155//mutilchannel playback stream appear here:
156
157#define MULTI_FRONT_L 0x08
158#define MULTI_FRONT_R 0x09
159#define MULTI_REAR_L 0x0a
160#define MULTI_REAR_R 0x0b
161#define MULTI_CENTER 0x0c
162#define MULTI_LFE 0x0d
163
164#define AC97_IN_L 0x10
165#define AC97_IN_R 0x11
166#define SPDIF_CD_L 0x12
167#define SPDIF_CD_R 0x13
168
169/* hw outputs */
170#define AC97_FRONT_L 0x20
171#define AC97_FRONT_R 0x21
172#define DIGITAL_OUT_L 0x22
173#define DIGITAL_OUT_R 0x23
174#define DIGITAL_CENTER 0x24
175#define DIGITAL_LFE 0x25
176
177#define ANALOG_REAR_L 0x28
178#define ANALOG_REAR_R 0x29
179#define ADC_REC_L 0x2a
180#define ADC_REC_R 0x2b
181
182#define ANALOG_CENTER 0x31
183#define ANALOG_LFE 0x32
184
185
186#define INPUT_PATCH_START(patch, nm, ln, i) \
187do { \
188 patch = PATCH(mgr, patch_n); \
189 strcpy(patch->name, nm); \
190 patch->code_start = pc * 2; \
191 patch->input = (1<<(0x1f&ln)); \
192 patch->output= (1<<(0x1f&ln)); \
193 patch->id = i; \
194} while(0)
195
196#define INPUT_PATCH_END(patch) \
197do { \
198 patch->code_size = pc * 2 - patch->code_start; \
199 patch_n++; \
200} while(0)
201
202
203#define ROUTING_PATCH_START(patch, nm) \
204do { \
205 patch = &mgr->rpatch; \
206 strcpy(patch->name, nm); \
207 patch->code_start = pc * 2; \
208} while(0)
209
210#define ROUTING_PATCH_END(patch) \
211do { \
212 patch->code_size = pc * 2 - patch->code_start; \
213} while(0)
214
215#define CONNECT(input, output) set_bit(input, &rpatch->route[(output) - OUTPUT_BASE]);
216
217#define CONNECT_V(input, output) set_bit(input, &rpatch->route_v[(output) - OUTPUT_BASE]);
218
219#define OUTPUT_PATCH_START(patch, nm, ln, i) \
220do { \
221 patch = PATCH(mgr, patch_n); \
222 strcpy(patch->name, nm); \
223 patch->code_start = pc * 2; \
224 patch->input = (1<<(0x1f&ln)); \
225 patch->output= (1<<(0x1f&ln)); \
226 patch->id = i; \
227} while(0)
228
229#define OUTPUT_PATCH_END(patch) \
230do { \
231 patch->code_size = pc * 2 - patch->code_start; \
232 patch_n++; \
233} while(0)
234
235#define GET_OUTPUT_GPR(patch, g, ln) \
236do { \
237 mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_IO; \
238 mgr->gpr[(g) - GPR_BASE].usage++; \
239 mgr->gpr[(g) - GPR_BASE].line = ln; \
240 set_bit((g) - GPR_BASE, patch->gpr_used); \
241} while(0)
242
243#define GET_INPUT_GPR(patch, g, ln) \
244do { \
245 mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_IO; \
246 mgr->gpr[(g) - GPR_BASE].usage++; \
247 mgr->gpr[(g) - GPR_BASE].line = ln; \
248 set_bit((g) - GPR_BASE, patch->gpr_used); \
249 set_bit((g) - GPR_BASE, patch->gpr_input); \
250} while(0)
251
252#define GET_DYNAMIC_GPR(patch, g) \
253do { \
254 mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_DYNAMIC; \
255 mgr->gpr[(g) - GPR_BASE].usage++; \
256 set_bit((g) - GPR_BASE, patch->gpr_used); \
257} while(0)
258
259#define GET_CONTROL_GPR(patch, g, nm, a, b) \
260do { \
261 strcpy(mgr->gpr[(g) - GPR_BASE].name, nm); \
262 mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_CONTROL; \
263 mgr->gpr[(g) - GPR_BASE].usage++; \
264 mgr->gpr[(g) - GPR_BASE].min = a; \
265 mgr->gpr[(g) - GPR_BASE].max = b; \
266 sblive_writeptr(card, g, 0, b); \
267 set_bit((g) - GPR_BASE, patch->gpr_used); \
268} while(0)
269
270#endif /* _EFXMGR_H */
diff --git a/sound/oss/emu10k1/emuadxmg.c b/sound/oss/emu10k1/emuadxmg.c
new file mode 100644
index 000000000000..d7d2d4caf7ba
--- /dev/null
+++ b/sound/oss/emu10k1/emuadxmg.c
@@ -0,0 +1,104 @@
1
2/*
3 **********************************************************************
4 * emuadxmg.c - Address space manager for emu10k1 driver
5 * Copyright 1999, 2000 Creative Labs, Inc.
6 *
7 **********************************************************************
8 *
9 * Date Author Summary of changes
10 * ---- ------ ------------------
11 * October 20, 1999 Bertrand Lee base code release
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#include "hwaccess.h"
34
35/* Allocates emu address space */
36
37int emu10k1_addxmgr_alloc(u32 size, struct emu10k1_card *card)
38{
39 u16 *pagetable = card->emupagetable;
40 u16 index = 0;
41 u16 numpages;
42 unsigned long flags;
43
44 /* Convert bytes to pages */
45 numpages = (size / EMUPAGESIZE) + ((size % EMUPAGESIZE) ? 1 : 0);
46
47 spin_lock_irqsave(&card->lock, flags);
48
49 while (index < (MAXPAGES - 1)) {
50 if (pagetable[index] & 0x8000) {
51 /* This block of pages is in use, jump to the start of the next block. */
52 index += (pagetable[index] & 0x7fff);
53 } else {
54 /* Found free block */
55 if (pagetable[index] >= numpages) {
56
57 /* Block is large enough */
58
59 /* If free block is larger than the block requested
60 * then adjust the size of the block remaining */
61 if (pagetable[index] > numpages)
62 pagetable[index + numpages] = pagetable[index] - numpages;
63
64 pagetable[index] = (numpages | 0x8000); /* Mark block as used */
65
66 spin_unlock_irqrestore(&card->lock, flags);
67
68 return index;
69 } else {
70 /* Block too small, jump to the start of the next block */
71 index += pagetable[index];
72 }
73 }
74 }
75
76 spin_unlock_irqrestore(&card->lock, flags);
77
78 return -1;
79}
80
81/* Frees a previously allocated emu address space. */
82
83void emu10k1_addxmgr_free(struct emu10k1_card *card, int index)
84{
85 u16 *pagetable = card->emupagetable;
86 u16 origsize = 0;
87 unsigned long flags;
88
89 spin_lock_irqsave(&card->lock, flags);
90
91 if (pagetable[index] & 0x8000) {
92 /* Block is allocated - mark block as free */
93 origsize = pagetable[index] & 0x7fff;
94 pagetable[index] = origsize;
95
96 /* If next block is free, we concat both blocks */
97 if (!(pagetable[index + origsize] & 0x8000))
98 pagetable[index] += pagetable[index + origsize] & 0x7fff;
99 }
100
101 spin_unlock_irqrestore(&card->lock, flags);
102
103 return;
104}
diff --git a/sound/oss/emu10k1/hwaccess.c b/sound/oss/emu10k1/hwaccess.c
new file mode 100644
index 000000000000..2dc16a841fa1
--- /dev/null
+++ b/sound/oss/emu10k1/hwaccess.c
@@ -0,0 +1,507 @@
1/*
2 **********************************************************************
3 * hwaccess.c -- Hardware access layer
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * December 9, 1999 Jon Taylor rewrote the I/O subsystem
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#include <asm/io.h>
34
35#include "hwaccess.h"
36#include "8010.h"
37#include "icardmid.h"
38
39/*************************************************************************
40* Function : srToPitch *
41* Input : sampleRate - sampling rate *
42* Return : pitch value *
43* About : convert sampling rate to pitch *
44* Note : for 8010, sampling rate is at 48kHz, this function should *
45* be changed. *
46*************************************************************************/
47u32 srToPitch(u32 sampleRate)
48{
49 int i;
50
51 /* FIXME: These tables should be defined in a headerfile */
52 static u32 logMagTable[128] = {
53 0x00000, 0x02dfc, 0x05b9e, 0x088e6, 0x0b5d6, 0x0e26f, 0x10eb3, 0x13aa2,
54 0x1663f, 0x1918a, 0x1bc84, 0x1e72e, 0x2118b, 0x23b9a, 0x2655d, 0x28ed5,
55 0x2b803, 0x2e0e8, 0x30985, 0x331db, 0x359eb, 0x381b6, 0x3a93d, 0x3d081,
56 0x3f782, 0x41e42, 0x444c1, 0x46b01, 0x49101, 0x4b6c4, 0x4dc49, 0x50191,
57 0x5269e, 0x54b6f, 0x57006, 0x59463, 0x5b888, 0x5dc74, 0x60029, 0x623a7,
58 0x646ee, 0x66a00, 0x68cdd, 0x6af86, 0x6d1fa, 0x6f43c, 0x7164b, 0x73829,
59 0x759d4, 0x77b4f, 0x79c9a, 0x7bdb5, 0x7dea1, 0x7ff5e, 0x81fed, 0x8404e,
60 0x86082, 0x88089, 0x8a064, 0x8c014, 0x8df98, 0x8fef1, 0x91e20, 0x93d26,
61 0x95c01, 0x97ab4, 0x9993e, 0x9b79f, 0x9d5d9, 0x9f3ec, 0xa11d8, 0xa2f9d,
62 0xa4d3c, 0xa6ab5, 0xa8808, 0xaa537, 0xac241, 0xadf26, 0xafbe7, 0xb1885,
63 0xb3500, 0xb5157, 0xb6d8c, 0xb899f, 0xba58f, 0xbc15e, 0xbdd0c, 0xbf899,
64 0xc1404, 0xc2f50, 0xc4a7b, 0xc6587, 0xc8073, 0xc9b3f, 0xcb5ed, 0xcd07c,
65 0xceaec, 0xd053f, 0xd1f73, 0xd398a, 0xd5384, 0xd6d60, 0xd8720, 0xda0c3,
66 0xdba4a, 0xdd3b4, 0xded03, 0xe0636, 0xe1f4e, 0xe384a, 0xe512c, 0xe69f3,
67 0xe829f, 0xe9b31, 0xeb3a9, 0xecc08, 0xee44c, 0xefc78, 0xf148a, 0xf2c83,
68 0xf4463, 0xf5c2a, 0xf73da, 0xf8b71, 0xfa2f0, 0xfba57, 0xfd1a7, 0xfe8df
69 };
70
71 static char logSlopeTable[128] = {
72 0x5c, 0x5c, 0x5b, 0x5a, 0x5a, 0x59, 0x58, 0x58,
73 0x57, 0x56, 0x56, 0x55, 0x55, 0x54, 0x53, 0x53,
74 0x52, 0x52, 0x51, 0x51, 0x50, 0x50, 0x4f, 0x4f,
75 0x4e, 0x4d, 0x4d, 0x4d, 0x4c, 0x4c, 0x4b, 0x4b,
76 0x4a, 0x4a, 0x49, 0x49, 0x48, 0x48, 0x47, 0x47,
77 0x47, 0x46, 0x46, 0x45, 0x45, 0x45, 0x44, 0x44,
78 0x43, 0x43, 0x43, 0x42, 0x42, 0x42, 0x41, 0x41,
79 0x41, 0x40, 0x40, 0x40, 0x3f, 0x3f, 0x3f, 0x3e,
80 0x3e, 0x3e, 0x3d, 0x3d, 0x3d, 0x3c, 0x3c, 0x3c,
81 0x3b, 0x3b, 0x3b, 0x3b, 0x3a, 0x3a, 0x3a, 0x39,
82 0x39, 0x39, 0x39, 0x38, 0x38, 0x38, 0x38, 0x37,
83 0x37, 0x37, 0x37, 0x36, 0x36, 0x36, 0x36, 0x35,
84 0x35, 0x35, 0x35, 0x34, 0x34, 0x34, 0x34, 0x34,
85 0x33, 0x33, 0x33, 0x33, 0x32, 0x32, 0x32, 0x32,
86 0x32, 0x31, 0x31, 0x31, 0x31, 0x31, 0x30, 0x30,
87 0x30, 0x30, 0x30, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f
88 };
89
90 if (sampleRate == 0)
91 return 0; /* Bail out if no leading "1" */
92
93 sampleRate *= 11185; /* Scale 48000 to 0x20002380 */
94
95 for (i = 31; i > 0; i--) {
96 if (sampleRate & 0x80000000) { /* Detect leading "1" */
97 return (u32) (((s32) (i - 15) << 20) +
98 logMagTable[0x7f & (sampleRate >> 24)] +
99 (0x7f & (sampleRate >> 17)) * logSlopeTable[0x7f & (sampleRate >> 24)]);
100 }
101 sampleRate = sampleRate << 1;
102 }
103
104 DPF(2, "srToPitch: BUG!\n");
105 return 0; /* Should never reach this point */
106}
107
108/*******************************************
109* write/read PCI function 0 registers *
110********************************************/
111void emu10k1_writefn0(struct emu10k1_card *card, u32 reg, u32 data)
112{
113 unsigned long flags;
114
115 if (reg & 0xff000000) {
116 u32 mask;
117 u8 size, offset;
118
119 size = (reg >> 24) & 0x3f;
120 offset = (reg >> 16) & 0x1f;
121 mask = ((1 << size) - 1) << offset;
122 data = (data << offset) & mask;
123 reg &= 0x7f;
124
125 spin_lock_irqsave(&card->lock, flags);
126 data |= inl(card->iobase + reg) & ~mask;
127 outl(data, card->iobase + reg);
128 spin_unlock_irqrestore(&card->lock, flags);
129 } else {
130 spin_lock_irqsave(&card->lock, flags);
131 outl(data, card->iobase + reg);
132 spin_unlock_irqrestore(&card->lock, flags);
133 }
134
135 return;
136}
137
138#ifdef DBGEMU
139void emu10k1_writefn0_2(struct emu10k1_card *card, u32 reg, u32 data, int size)
140{
141 unsigned long flags;
142
143 spin_lock_irqsave(&card->lock, flags);
144
145 if (size == 32)
146 outl(data, card->iobase + (reg & 0x1F));
147 else if (size == 16)
148 outw(data, card->iobase + (reg & 0x1F));
149 else
150 outb(data, card->iobase + (reg & 0x1F));
151
152 spin_unlock_irqrestore(&card->lock, flags);
153
154 return;
155}
156#endif /* DBGEMU */
157
158u32 emu10k1_readfn0(struct emu10k1_card * card, u32 reg)
159{
160 u32 val;
161 unsigned long flags;
162
163 if (reg & 0xff000000) {
164 u32 mask;
165 u8 size, offset;
166
167 size = (reg >> 24) & 0x3f;
168 offset = (reg >> 16) & 0x1f;
169 mask = ((1 << size) - 1) << offset;
170 reg &= 0x7f;
171
172 spin_lock_irqsave(&card->lock, flags);
173 val = inl(card->iobase + reg);
174 spin_unlock_irqrestore(&card->lock, flags);
175
176 return (val & mask) >> offset;
177 } else {
178 spin_lock_irqsave(&card->lock, flags);
179 val = inl(card->iobase + reg);
180 spin_unlock_irqrestore(&card->lock, flags);
181 return val;
182 }
183}
184
185void emu10k1_timer_set(struct emu10k1_card * card, u16 data)
186{
187 unsigned long flags;
188
189 spin_lock_irqsave(&card->lock, flags);
190 outw(data & TIMER_RATE_MASK, card->iobase + TIMER);
191 spin_unlock_irqrestore(&card->lock, flags);
192}
193
194/************************************************************************
195* write/read Emu10k1 pointer-offset register set, accessed through *
196* the PTR and DATA registers *
197*************************************************************************/
198#define A_PTR_ADDRESS_MASK 0x0fff0000
199void sblive_writeptr(struct emu10k1_card *card, u32 reg, u32 channel, u32 data)
200{
201 u32 regptr;
202 unsigned long flags;
203
204 regptr = ((reg << 16) & A_PTR_ADDRESS_MASK) | (channel & PTR_CHANNELNUM_MASK);
205
206 if (reg & 0xff000000) {
207 u32 mask;
208 u8 size, offset;
209
210 size = (reg >> 24) & 0x3f;
211 offset = (reg >> 16) & 0x1f;
212 mask = ((1 << size) - 1) << offset;
213 data = (data << offset) & mask;
214
215 spin_lock_irqsave(&card->lock, flags);
216 outl(regptr, card->iobase + PTR);
217 data |= inl(card->iobase + DATA) & ~mask;
218 outl(data, card->iobase + DATA);
219 spin_unlock_irqrestore(&card->lock, flags);
220 } else {
221 spin_lock_irqsave(&card->lock, flags);
222 outl(regptr, card->iobase + PTR);
223 outl(data, card->iobase + DATA);
224 spin_unlock_irqrestore(&card->lock, flags);
225 }
226}
227
228/* ... : data, reg, ... , TAGLIST_END */
229void sblive_writeptr_tag(struct emu10k1_card *card, u32 channel, ...)
230{
231 va_list args;
232
233 unsigned long flags;
234 u32 reg;
235
236 va_start(args, channel);
237
238 spin_lock_irqsave(&card->lock, flags);
239 while ((reg = va_arg(args, u32)) != TAGLIST_END) {
240 u32 data = va_arg(args, u32);
241 u32 regptr = (((reg << 16) & A_PTR_ADDRESS_MASK)
242 | (channel & PTR_CHANNELNUM_MASK));
243 outl(regptr, card->iobase + PTR);
244 if (reg & 0xff000000) {
245 int size = (reg >> 24) & 0x3f;
246 int offset = (reg >> 16) & 0x1f;
247 u32 mask = ((1 << size) - 1) << offset;
248 data = (data << offset) & mask;
249
250 data |= inl(card->iobase + DATA) & ~mask;
251 }
252 outl(data, card->iobase + DATA);
253 }
254 spin_unlock_irqrestore(&card->lock, flags);
255
256 va_end(args);
257
258 return;
259}
260
261u32 sblive_readptr(struct emu10k1_card * card, u32 reg, u32 channel)
262{
263 u32 regptr, val;
264 unsigned long flags;
265
266 regptr = ((reg << 16) & A_PTR_ADDRESS_MASK) | (channel & PTR_CHANNELNUM_MASK);
267
268 if (reg & 0xff000000) {
269 u32 mask;
270 u8 size, offset;
271
272 size = (reg >> 24) & 0x3f;
273 offset = (reg >> 16) & 0x1f;
274 mask = ((1 << size) - 1) << offset;
275
276 spin_lock_irqsave(&card->lock, flags);
277 outl(regptr, card->iobase + PTR);
278 val = inl(card->iobase + DATA);
279 spin_unlock_irqrestore(&card->lock, flags);
280
281 return (val & mask) >> offset;
282 } else {
283 spin_lock_irqsave(&card->lock, flags);
284 outl(regptr, card->iobase + PTR);
285 val = inl(card->iobase + DATA);
286 spin_unlock_irqrestore(&card->lock, flags);
287
288 return val;
289 }
290}
291
292void emu10k1_irq_enable(struct emu10k1_card *card, u32 irq_mask)
293{
294 u32 val;
295 unsigned long flags;
296
297 DPF(2,"emu10k1_irq_enable()\n");
298
299 spin_lock_irqsave(&card->lock, flags);
300 val = inl(card->iobase + INTE) | irq_mask;
301 outl(val, card->iobase + INTE);
302 spin_unlock_irqrestore(&card->lock, flags);
303 return;
304}
305
306void emu10k1_irq_disable(struct emu10k1_card *card, u32 irq_mask)
307{
308 u32 val;
309 unsigned long flags;
310
311 DPF(2,"emu10k1_irq_disable()\n");
312
313 spin_lock_irqsave(&card->lock, flags);
314 val = inl(card->iobase + INTE) & ~irq_mask;
315 outl(val, card->iobase + INTE);
316 spin_unlock_irqrestore(&card->lock, flags);
317 return;
318}
319
320void emu10k1_clear_stop_on_loop(struct emu10k1_card *card, u32 voicenum)
321{
322 /* Voice interrupt */
323 if (voicenum >= 32)
324 sblive_writeptr(card, SOLEH | ((0x0100 | (voicenum - 32)) << 16), 0, 0);
325 else
326 sblive_writeptr(card, SOLEL | ((0x0100 | voicenum) << 16), 0, 0);
327
328 return;
329}
330
331static void sblive_wcwait(struct emu10k1_card *card, u32 wait)
332{
333 volatile unsigned uCount;
334 u32 newtime = 0, curtime;
335
336 curtime = emu10k1_readfn0(card, WC_SAMPLECOUNTER);
337 while (wait--) {
338 uCount = 0;
339 while (uCount++ < TIMEOUT) {
340 newtime = emu10k1_readfn0(card, WC_SAMPLECOUNTER);
341 if (newtime != curtime)
342 break;
343 }
344
345 if (uCount >= TIMEOUT)
346 break;
347
348 curtime = newtime;
349 }
350}
351
352u16 emu10k1_ac97_read(struct ac97_codec *codec, u8 reg)
353{
354 struct emu10k1_card *card = codec->private_data;
355 u16 data;
356 unsigned long flags;
357
358 spin_lock_irqsave(&card->lock, flags);
359
360 outb(reg, card->iobase + AC97ADDRESS);
361 data = inw(card->iobase + AC97DATA);
362
363 spin_unlock_irqrestore(&card->lock, flags);
364
365 return data;
366}
367
368void emu10k1_ac97_write(struct ac97_codec *codec, u8 reg, u16 value)
369{
370 struct emu10k1_card *card = codec->private_data;
371 unsigned long flags;
372
373 spin_lock_irqsave(&card->lock, flags);
374
375 outb(reg, card->iobase + AC97ADDRESS);
376 outw(value, card->iobase + AC97DATA);
377 outb( AC97_EXTENDED_ID, card->iobase + AC97ADDRESS);
378 spin_unlock_irqrestore(&card->lock, flags);
379}
380
381/*********************************************************
382* MPU access functions *
383**********************************************************/
384
385int emu10k1_mpu_write_data(struct emu10k1_card *card, u8 data)
386{
387 unsigned long flags;
388 int ret;
389
390 if (card->is_audigy) {
391 if ((sblive_readptr(card, A_MUSTAT,0) & MUSTAT_ORDYN) == 0) {
392 sblive_writeptr(card, A_MUDATA, 0, data);
393 ret = 0;
394 } else
395 ret = -1;
396 } else {
397 spin_lock_irqsave(&card->lock, flags);
398
399 if ((inb(card->iobase + MUSTAT) & MUSTAT_ORDYN) == 0) {
400 outb(data, card->iobase + MUDATA);
401 ret = 0;
402 } else
403 ret = -1;
404
405 spin_unlock_irqrestore(&card->lock, flags);
406 }
407
408 return ret;
409}
410
411int emu10k1_mpu_read_data(struct emu10k1_card *card, u8 * data)
412{
413 unsigned long flags;
414 int ret;
415
416 if (card->is_audigy) {
417 if ((sblive_readptr(card, A_MUSTAT,0) & MUSTAT_IRDYN) == 0) {
418 *data = sblive_readptr(card, A_MUDATA,0);
419 ret = 0;
420 } else
421 ret = -1;
422 } else {
423 spin_lock_irqsave(&card->lock, flags);
424
425 if ((inb(card->iobase + MUSTAT) & MUSTAT_IRDYN) == 0) {
426 *data = inb(card->iobase + MUDATA);
427 ret = 0;
428 } else
429 ret = -1;
430
431 spin_unlock_irqrestore(&card->lock, flags);
432 }
433
434 return ret;
435}
436
437int emu10k1_mpu_reset(struct emu10k1_card *card)
438{
439 u8 status;
440 unsigned long flags;
441
442 DPF(2, "emu10k1_mpu_reset()\n");
443 if (card->is_audigy) {
444 if (card->mpuacqcount == 0) {
445 sblive_writeptr(card, A_MUCMD, 0, MUCMD_RESET);
446 sblive_wcwait(card, 8);
447 sblive_writeptr(card, A_MUCMD, 0, MUCMD_RESET);
448 sblive_wcwait(card, 8);
449 sblive_writeptr(card, A_MUCMD, 0, MUCMD_ENTERUARTMODE);
450 sblive_wcwait(card, 8);
451 status = sblive_readptr(card, A_MUDATA, 0);
452 if (status == 0xfe)
453 return 0;
454 else
455 return -1;
456 }
457
458 return 0;
459 } else {
460 if (card->mpuacqcount == 0) {
461 spin_lock_irqsave(&card->lock, flags);
462 outb(MUCMD_RESET, card->iobase + MUCMD);
463 spin_unlock_irqrestore(&card->lock, flags);
464
465 sblive_wcwait(card, 8);
466
467 spin_lock_irqsave(&card->lock, flags);
468 outb(MUCMD_RESET, card->iobase + MUCMD);
469 spin_unlock_irqrestore(&card->lock, flags);
470
471 sblive_wcwait(card, 8);
472
473 spin_lock_irqsave(&card->lock, flags);
474 outb(MUCMD_ENTERUARTMODE, card->iobase + MUCMD);
475 spin_unlock_irqrestore(&card->lock, flags);
476
477 sblive_wcwait(card, 8);
478
479 spin_lock_irqsave(&card->lock, flags);
480 status = inb(card->iobase + MUDATA);
481 spin_unlock_irqrestore(&card->lock, flags);
482
483 if (status == 0xfe)
484 return 0;
485 else
486 return -1;
487 }
488
489 return 0;
490 }
491}
492
493int emu10k1_mpu_acquire(struct emu10k1_card *card)
494{
495 /* FIXME: This should be a macro */
496 ++card->mpuacqcount;
497
498 return 0;
499}
500
501int emu10k1_mpu_release(struct emu10k1_card *card)
502{
503 /* FIXME: this should be a macro */
504 --card->mpuacqcount;
505
506 return 0;
507}
diff --git a/sound/oss/emu10k1/hwaccess.h b/sound/oss/emu10k1/hwaccess.h
new file mode 100644
index 000000000000..104223a192aa
--- /dev/null
+++ b/sound/oss/emu10k1/hwaccess.h
@@ -0,0 +1,247 @@
1/*
2 **********************************************************************
3 * hwaccess.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _HWACCESS_H
33#define _HWACCESS_H
34
35#include <linux/fs.h>
36#include <linux/sound.h>
37#include <linux/soundcard.h>
38#include <linux/ac97_codec.h>
39#include <linux/pci.h>
40#include <linux/slab.h>
41#include <linux/sched.h>
42#include <asm/io.h>
43
44#include "efxmgr.h"
45#include "passthrough.h"
46#include "midi.h"
47
48#define EMUPAGESIZE 4096 /* don't change */
49#define NUM_G 64 /* use all channels */
50#define NUM_FXSENDS 4 /* don't change */
51/* setting this to other than a power of two may break some applications */
52#define MAXBUFSIZE 65536
53#define MAXPAGES 8192
54#define BUFMAXPAGES (MAXBUFSIZE / PAGE_SIZE)
55
56#define FLAGS_AVAILABLE 0x0001
57#define FLAGS_READY 0x0002
58
59struct memhandle
60{
61 dma_addr_t dma_handle;
62 void *addr;
63 u32 size;
64};
65
66#define DEBUG_LEVEL 2
67
68#ifdef EMU10K1_DEBUG
69# define DPD(level,x,y...) do {if(level <= DEBUG_LEVEL) printk( KERN_NOTICE "emu10k1: %s: %d: " x , __FILE__ , __LINE__ , y );} while(0)
70# define DPF(level,x) do {if(level <= DEBUG_LEVEL) printk( KERN_NOTICE "emu10k1: %s: %d: " x , __FILE__ , __LINE__ );} while(0)
71#else
72# define DPD(level,x,y...) do { } while (0) /* not debugging: nothing */
73# define DPF(level,x) do { } while (0)
74#endif /* EMU10K1_DEBUG */
75
76#define ERROR() DPF(1,"error\n")
77
78/* DATA STRUCTURES */
79
80struct emu10k1_waveout
81{
82 u32 send_routing[3];
83 // audigy only:
84 u32 send_routing2[3];
85
86 u32 send_dcba[3];
87 // audigy only:
88 u32 send_hgfe[3];
89};
90#define ROUTE_PCM 0
91#define ROUTE_PT 1
92#define ROUTE_PCM1 2
93
94#define SEND_MONO 0
95#define SEND_LEFT 1
96#define SEND_RIGHT 2
97
98struct emu10k1_wavein
99{
100 struct wiinst *ac97;
101 struct wiinst *mic;
102 struct wiinst *fx;
103
104 u8 recsrc;
105 u32 fxwc;
106};
107
108#define CMD_READ 1
109#define CMD_WRITE 2
110
111struct mixer_private_ioctl {
112 u32 cmd;
113 u32 val[90];
114};
115
116/* bogus ioctls numbers to escape from OSS mixer limitations */
117#define CMD_WRITEFN0 _IOW('D', 0, struct mixer_private_ioctl)
118#define CMD_READFN0 _IOR('D', 1, struct mixer_private_ioctl)
119#define CMD_WRITEPTR _IOW('D', 2, struct mixer_private_ioctl)
120#define CMD_READPTR _IOR('D', 3, struct mixer_private_ioctl)
121#define CMD_SETRECSRC _IOW('D', 4, struct mixer_private_ioctl)
122#define CMD_GETRECSRC _IOR('D', 5, struct mixer_private_ioctl)
123#define CMD_GETVOICEPARAM _IOR('D', 6, struct mixer_private_ioctl)
124#define CMD_SETVOICEPARAM _IOW('D', 7, struct mixer_private_ioctl)
125#define CMD_GETPATCH _IOR('D', 8, struct mixer_private_ioctl)
126#define CMD_GETGPR _IOR('D', 9, struct mixer_private_ioctl)
127#define CMD_GETCTLGPR _IOR('D', 10, struct mixer_private_ioctl)
128#define CMD_SETPATCH _IOW('D', 11, struct mixer_private_ioctl)
129#define CMD_SETGPR _IOW('D', 12, struct mixer_private_ioctl)
130#define CMD_SETCTLGPR _IOW('D', 13, struct mixer_private_ioctl)
131#define CMD_SETGPOUT _IOW('D', 14, struct mixer_private_ioctl)
132#define CMD_GETGPR2OSS _IOR('D', 15, struct mixer_private_ioctl)
133#define CMD_SETGPR2OSS _IOW('D', 16, struct mixer_private_ioctl)
134#define CMD_SETMCH_FX _IOW('D', 17, struct mixer_private_ioctl)
135#define CMD_SETPASSTHROUGH _IOW('D', 18, struct mixer_private_ioctl)
136#define CMD_PRIVATE3_VERSION _IOW('D', 19, struct mixer_private_ioctl)
137#define CMD_AC97_BOOST _IOW('D', 20, struct mixer_private_ioctl)
138
139//up this number when breaking compatibility
140#define PRIVATE3_VERSION 2
141
142struct emu10k1_card
143{
144 struct list_head list;
145
146 struct memhandle virtualpagetable;
147 struct memhandle tankmem;
148 struct memhandle silentpage;
149
150 spinlock_t lock;
151
152 u8 voicetable[NUM_G];
153 u16 emupagetable[MAXPAGES];
154
155 struct list_head timers;
156 u16 timer_delay;
157 spinlock_t timer_lock;
158
159 struct pci_dev *pci_dev;
160 unsigned long iobase;
161 unsigned long length;
162 unsigned short model;
163 unsigned int irq;
164
165 int audio_dev;
166 int audio_dev1;
167 int midi_dev;
168#ifdef EMU10K1_SEQUENCER
169 int seq_dev;
170 struct emu10k1_mididevice *seq_mididev;
171#endif
172
173 struct ac97_codec *ac97;
174 int ac97_supported_mixers;
175 int ac97_stereo_mixers;
176
177 /* Number of first fx voice for multichannel output */
178 u8 mchannel_fx;
179 struct emu10k1_waveout waveout;
180 struct emu10k1_wavein wavein;
181 struct emu10k1_mpuout *mpuout;
182 struct emu10k1_mpuin *mpuin;
183
184 struct semaphore open_sem;
185 mode_t open_mode;
186 wait_queue_head_t open_wait;
187
188 u32 mpuacqcount; // Mpu acquire count
189 u32 has_toslink; // TOSLink detection
190
191 u8 chiprev; /* Chip revision */
192 u8 is_audigy;
193 u8 is_aps;
194
195 struct patch_manager mgr;
196 struct pt_data pt;
197};
198
199int emu10k1_addxmgr_alloc(u32, struct emu10k1_card *);
200void emu10k1_addxmgr_free(struct emu10k1_card *, int);
201
202int emu10k1_find_control_gpr(struct patch_manager *, const char *, const char *);
203void emu10k1_set_control_gpr(struct emu10k1_card *, int , s32, int );
204
205void emu10k1_set_volume_gpr(struct emu10k1_card *, int, s32, int);
206
207
208#define VOL_6BIT 0x40
209#define VOL_5BIT 0x20
210#define VOL_4BIT 0x10
211
212#define TIMEOUT 16384
213
214u32 srToPitch(u32);
215
216extern struct list_head emu10k1_devs;
217
218/* Hardware Abstraction Layer access functions */
219
220void emu10k1_writefn0(struct emu10k1_card *, u32, u32);
221void emu10k1_writefn0_2(struct emu10k1_card *, u32, u32, int);
222u32 emu10k1_readfn0(struct emu10k1_card *, u32);
223
224void emu10k1_timer_set(struct emu10k1_card *, u16);
225
226void sblive_writeptr(struct emu10k1_card *, u32, u32, u32);
227void sblive_writeptr_tag(struct emu10k1_card *, u32, ...);
228#define TAGLIST_END 0
229
230u32 sblive_readptr(struct emu10k1_card *, u32 , u32 );
231
232void emu10k1_irq_enable(struct emu10k1_card *, u32);
233void emu10k1_irq_disable(struct emu10k1_card *, u32);
234void emu10k1_clear_stop_on_loop(struct emu10k1_card *, u32);
235
236/* AC97 Codec register access function */
237u16 emu10k1_ac97_read(struct ac97_codec *, u8);
238void emu10k1_ac97_write(struct ac97_codec *, u8, u16);
239
240/* MPU access function*/
241int emu10k1_mpu_write_data(struct emu10k1_card *, u8);
242int emu10k1_mpu_read_data(struct emu10k1_card *, u8 *);
243int emu10k1_mpu_reset(struct emu10k1_card *);
244int emu10k1_mpu_acquire(struct emu10k1_card *);
245int emu10k1_mpu_release(struct emu10k1_card *);
246
247#endif /* _HWACCESS_H */
diff --git a/sound/oss/emu10k1/icardmid.h b/sound/oss/emu10k1/icardmid.h
new file mode 100644
index 000000000000..6a6ef419401f
--- /dev/null
+++ b/sound/oss/emu10k1/icardmid.h
@@ -0,0 +1,163 @@
1/*
2 **********************************************************************
3 * isblive_mid.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _ICARDMIDI_H
33#define _ICARDMIDI_H
34
35/* MIDI defines */
36#define MIDI_DATA_FIRST 0x00
37#define MIDI_DATA_LAST 0x7F
38#define MIDI_STATUS_FIRST 0x80
39#define MIDI_STATUS_LAST 0xFF
40
41/* Channel status bytes */
42#define MIDI_STATUS_CHANNEL_FIRST 0x80
43#define MIDI_STATUS_CHANNEL_LAST 0xE0
44#define MIDI_STATUS_CHANNEL_MASK 0xF0
45
46/* Channel voice messages */
47#define MIDI_VOICE_NOTE_OFF 0x80
48#define MIDI_VOICE_NOTE_ON 0x90
49#define MIDI_VOICE_POLY_PRESSURE 0xA0
50#define MIDI_VOICE_CONTROL_CHANGE 0xB0
51#define MIDI_VOICE_PROGRAM_CHANGE 0xC0
52#define MIDI_VOICE_CHANNEL_PRESSURE 0xD0
53#define MIDI_VOICE_PITCH_BEND 0xE0
54
55/* Channel mode messages */
56#define MIDI_MODE_CHANNEL MIDI_VOICE_CONTROL_CHANGE
57
58/* System status bytes */
59#define MIDI_STATUS_SYSTEM_FIRST 0xF0
60#define MIDI_STATUS_SYSTEM_LAST 0xFF
61
62/* System exclusive messages */
63#define MIDI_SYSEX_BEGIN 0xF0
64#define MIDI_SYSEX_EOX 0xF7
65
66/* System common messages */
67#define MIDI_COMMON_TCQF 0xF1 /* Time code quarter frame */
68#define MIDI_COMMON_SONG_POSITION 0xF2
69#define MIDI_COMMON_SONG_SELECT 0xF3
70#define MIDI_COMMON_UNDEFINED_F4 0xF4
71#define MIDI_COMMON_UNDEFINED_F5 0xF5
72#define MIDI_COMMON_TUNE_REQUEST 0xF6
73
74/* System real-time messages */
75#define MIDI_RTIME_TIMING_CLOCK 0xF8
76#define MIDI_RTIME_UNDEFINED_F9 0xF9
77#define MIDI_RTIME_START 0xFA
78#define MIDI_RTIME_CONTINUE 0xFB
79#define MIDI_RTIME_STOP 0xFC
80#define MIDI_RTIME_UNDEFINED_FD 0xFD
81#define MIDI_RTIME_ACTIVE_SENSING 0xFE
82#define MIDI_RTIME_SYSTEM_RESET 0xFF
83
84/* Flags for flags parm of midiOutCachePatches(), midiOutCacheDrumPatches() */
85#define MIDI_CACHE_ALL 1
86#define MIDI_CACHE_BESTFIT 2
87#define MIDI_CACHE_QUERY 3
88#define MIDI_UNCACHE 4
89
90/* Event declarations for MPU IRQ Callbacks */
91#define ICARDMIDI_INLONGDATA 0x00000001 /* MIM_LONGDATA */
92#define ICARDMIDI_INLONGERROR 0x00000002 /* MIM_LONGERROR */
93#define ICARDMIDI_OUTLONGDATA 0x00000004 /* MOM_DONE for MPU OUT buffer */
94#define ICARDMIDI_INDATA 0x00000010 /* MIM_DATA */
95#define ICARDMIDI_INDATAERROR 0x00000020 /* MIM_ERROR */
96
97/* Declaration for flags in CARDMIDIBUFFERHDR */
98/* Make it the same as MHDR_DONE, MHDR_INQUEUE in mmsystem.h */
99#define MIDIBUF_DONE 0x00000001
100#define MIDIBUF_INQUEUE 0x00000004
101
102/* Declaration for msg parameter in midiCallbackFn */
103#define ICARDMIDI_OUTBUFFEROK 0x00000001
104#define ICARDMIDI_INMIDIOK 0x00000002
105
106/* Declaration for technology in struct midi_caps */
107#define MT_MIDIPORT 0x00000001 /* In original MIDIOUTCAPS structure */
108#define MT_FMSYNTH 0x00000004 /* In original MIDIOUTCAPS structure */
109#define MT_AWESYNTH 0x00001000
110#define MT_PCISYNTH 0x00002000
111#define MT_PCISYNTH64 0x00004000
112#define CARDMIDI_AWEMASK 0x0000F000
113
114enum LocalErrorCode
115{
116 CTSTATUS_NOTENABLED = 0x7000,
117 CTSTATUS_READY,
118 CTSTATUS_BUSY,
119 CTSTATUS_DATAAVAIL,
120 CTSTATUS_NODATA,
121 CTSTATUS_NEXT_BYTE
122};
123
124/* MIDI data block header */
125struct midi_hdr
126{
127 u8 *reserved; /* Pointer to original locked data block */
128 u32 bufferlength; /* Length of data in data block */
129 u32 bytesrecorded; /* Used for input only */
130 u32 user; /* For client's use */
131 u32 flags; /* Assorted flags (see defines) */
132 struct list_head list; /* Reserved for driver */
133 u8 *data; /* Second copy of first pointer */
134};
135
136/* Enumeration for SetControl */
137enum
138{
139 MIDIOBJVOLUME = 0x1,
140 MIDIQUERYACTIVEINST
141};
142
143struct midi_queue
144{
145 struct midi_queue *next;
146 u32 qtype; /* 0 = short message, 1 = long data */
147 u32 length;
148 u32 sizeLeft;
149 u8 *midibyte;
150 unsigned long refdata;
151};
152
153struct midi_openinfo
154{
155 u32 cbsize;
156 u32 flags;
157 unsigned long refdata;
158 u32 streamid;
159};
160
161int emu10k1_midi_callback(unsigned long , unsigned long, unsigned long *);
162
163#endif /* _ICARDMIDI_H */
diff --git a/sound/oss/emu10k1/icardwav.h b/sound/oss/emu10k1/icardwav.h
new file mode 100644
index 000000000000..25be40928b4d
--- /dev/null
+++ b/sound/oss/emu10k1/icardwav.h
@@ -0,0 +1,53 @@
1/*
2 **********************************************************************
3 * icardwav.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _ICARDWAV_H
33#define _ICARDWAV_H
34
35struct wave_format
36{
37 int id;
38 int samplingrate;
39 u8 bitsperchannel;
40 u8 channels; /* 1 = Mono, 2 = Stereo, 3, ... = Multichannel */
41 u8 bytesperchannel;
42 u8 bytespervoicesample;
43 u8 bytespersample;
44 int bytespersec;
45 u8 passthrough;
46};
47
48/* emu10k1_wave states */
49#define WAVE_STATE_OPEN 0x01
50#define WAVE_STATE_STARTED 0x02
51#define WAVE_STATE_CLOSED 0x04
52
53#endif /* _ICARDWAV_H */
diff --git a/sound/oss/emu10k1/irqmgr.c b/sound/oss/emu10k1/irqmgr.c
new file mode 100644
index 000000000000..d19b464ba01b
--- /dev/null
+++ b/sound/oss/emu10k1/irqmgr.c
@@ -0,0 +1,113 @@
1/*
2 **********************************************************************
3 * irqmgr.c - IRQ manager for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include "hwaccess.h"
33#include "8010.h"
34#include "cardmi.h"
35#include "cardmo.h"
36#include "irqmgr.h"
37
38/* Interrupt handler */
39
40irqreturn_t emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
41{
42 struct emu10k1_card *card = (struct emu10k1_card *) dev_id;
43 u32 irqstatus, irqstatus_tmp;
44 int handled = 0;
45
46 DPD(4, "emu10k1_interrupt called, irq = %u\n", irq);
47
48 /*
49 ** NOTE :
50 ** We do a 'while loop' here cos on certain machines, with both
51 ** playback and recording going on at the same time, IRQs will
52 ** stop coming in after a while. Checking IPND indeed shows that
53 ** there are interrupts pending but the PIC says no IRQs pending.
54 ** I suspect that some boards need edge-triggered IRQs but are not
55 ** getting that condition if we don't completely clear the IPND
56 ** (make sure no more interrupts are pending).
57 ** - Eric
58 */
59
60 while ((irqstatus = inl(card->iobase + IPR))) {
61 DPD(4, "irq status %#x\n", irqstatus);
62
63 irqstatus_tmp = irqstatus;
64
65 if (irqstatus & IRQTYPE_TIMER) {
66 emu10k1_timer_irqhandler(card);
67 irqstatus &= ~IRQTYPE_TIMER;
68 }
69
70 if (irqstatus & IRQTYPE_DSP) {
71 emu10k1_dsp_irqhandler(card);
72 irqstatus &= ~IRQTYPE_DSP;
73 }
74
75 if (irqstatus & IRQTYPE_MPUIN) {
76 emu10k1_mpuin_irqhandler(card);
77 irqstatus &= ~IRQTYPE_MPUIN;
78 }
79
80 if (irqstatus & IRQTYPE_MPUOUT) {
81 emu10k1_mpuout_irqhandler(card);
82 irqstatus &= ~IRQTYPE_MPUOUT;
83 }
84
85 if (irqstatus & IPR_MUTE) {
86 emu10k1_mute_irqhandler(card);
87 irqstatus &=~IPR_MUTE;
88 }
89
90 if (irqstatus & IPR_VOLINCR) {
91 emu10k1_volincr_irqhandler(card);
92 irqstatus &=~IPR_VOLINCR;
93 }
94
95 if (irqstatus & IPR_VOLDECR) {
96 emu10k1_voldecr_irqhandler(card);
97 irqstatus &=~IPR_VOLDECR;
98 }
99
100 if (irqstatus){
101 printk(KERN_ERR "emu10k1: Warning, unhandled interrupt: %#08x\n", irqstatus);
102 //make sure any interrupts we don't handle are disabled:
103 emu10k1_irq_disable(card, ~(INTE_MIDIRXENABLE | INTE_MIDITXENABLE | INTE_INTERVALTIMERENB |
104 INTE_VOLDECRENABLE | INTE_VOLINCRENABLE | INTE_MUTEENABLE |
105 INTE_FXDSPENABLE));
106 }
107
108 /* acknowledge interrupt */
109 outl(irqstatus_tmp, card->iobase + IPR);
110 handled = 1;
111 }
112 return IRQ_RETVAL(handled);
113}
diff --git a/sound/oss/emu10k1/irqmgr.h b/sound/oss/emu10k1/irqmgr.h
new file mode 100644
index 000000000000..7e7c9ca1098c
--- /dev/null
+++ b/sound/oss/emu10k1/irqmgr.h
@@ -0,0 +1,52 @@
1/*
2 **********************************************************************
3 * irq.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _IRQ_H
33#define _IRQ_H
34
35/* EMU Irq Types */
36#define IRQTYPE_PCIBUSERROR IPR_PCIERROR
37#define IRQTYPE_MIXERBUTTON (IPR_VOLINCR | IPR_VOLDECR | IPR_MUTE)
38#define IRQTYPE_VOICE (IPR_CHANNELLOOP | IPR_CHANNELNUMBERMASK)
39#define IRQTYPE_RECORD (IPR_ADCBUFFULL | IPR_ADCBUFHALFFULL | IPR_MICBUFFULL | IPR_MICBUFHALFFULL | IPR_EFXBUFFULL | IPR_EFXBUFHALFFULL)
40#define IRQTYPE_MPUOUT (IPR_MIDITRANSBUFEMPTY | A_IPR_MIDITRANSBUFEMPTY2)
41#define IRQTYPE_MPUIN (IPR_MIDIRECVBUFEMPTY | A_IPR_MIDIRECVBUFEMPTY2)
42#define IRQTYPE_TIMER IPR_INTERVALTIMER
43#define IRQTYPE_SPDIF (IPR_GPSPDIFSTATUSCHANGE | IPR_CDROMSTATUSCHANGE)
44#define IRQTYPE_DSP IPR_FXDSP
45
46void emu10k1_timer_irqhandler(struct emu10k1_card *);
47void emu10k1_dsp_irqhandler(struct emu10k1_card *);
48void emu10k1_mute_irqhandler(struct emu10k1_card *);
49void emu10k1_volincr_irqhandler(struct emu10k1_card *);
50void emu10k1_voldecr_irqhandler(struct emu10k1_card *);
51
52#endif /* _IRQ_H */
diff --git a/sound/oss/emu10k1/main.c b/sound/oss/emu10k1/main.c
new file mode 100644
index 000000000000..9b905bae423e
--- /dev/null
+++ b/sound/oss/emu10k1/main.c
@@ -0,0 +1,1475 @@
1 /*
2 **********************************************************************
3 * main.c - Creative EMU10K1 audio driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox cleaned up stuff
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 *
32 * Supported devices:
33 * /dev/dsp: Standard /dev/dsp device, OSS-compatible
34 * /dev/dsp1: Routes to rear speakers only
35 * /dev/mixer: Standard /dev/mixer device, OSS-compatible
36 * /dev/midi: Raw MIDI UART device, mostly OSS-compatible
37 * /dev/sequencer: Sequencer Interface (requires sound.o)
38 *
39 * Revision history:
40 * 0.1 beta Initial release
41 * 0.2 Lowered initial mixer vol. Improved on stuttering wave playback. Added MIDI UART support.
42 * 0.3 Fixed mixer routing bug, added APS, joystick support.
43 * 0.4 Added rear-channel, SPDIF support.
44 * 0.5 Source cleanup, SMP fixes, multiopen support, 64 bit arch fixes,
45 * moved bh's to tasklets, moved to the new PCI driver initialization style.
46 * 0.6 Make use of pci_alloc_consistent, improve compatibility layer for 2.2 kernels,
47 * code reorganization and cleanup.
48 * 0.7 Support for the Emu-APS. Bug fixes for voice cache setup, mmaped sound + poll().
49 * Support for setting external TRAM size.
50 * 0.8 Make use of the kernel ac97 interface. Support for a dsp patch manager.
51 * 0.9 Re-enables rear speakers volume controls
52 * 0.10 Initializes rear speaker volume.
53 * Dynamic patch storage allocation.
54 * New private ioctls to change control gpr values.
55 * Enable volume control interrupts.
56 * By default enable dsp routes to digital out.
57 * 0.11 Fixed fx / 4 problem.
58 * 0.12 Implemented mmaped for recording.
59 * Fixed bug: not unreserving mmaped buffer pages.
60 * IRQ handler cleanup.
61 * 0.13 Fixed problem with dsp1
62 * Simplified dsp patch writing (inside the driver)
63 * Fixed several bugs found by the Stanford tools
64 * 0.14 New control gpr to oss mixer mapping feature (Chris Purnell)
65 * Added AC3 Passthrough Support (Juha Yrjola)
66 * Added Support for 5.1 cards (digital out and the third analog out)
67 * 0.15 Added Sequencer Support (Daniel Mack)
68 * Support for multichannel pcm playback (Eduard Hasenleithner)
69 * 0.16 Mixer improvements, added old treble/bass support (Daniel Bertrand)
70 * Small code format cleanup.
71 * Deadlock bug fix for emu10k1_volxxx_irqhandler().
72 * 0.17 Fix for mixer SOUND_MIXER_INFO ioctl.
73 * Fix for HIGHMEM machines (emu10k1 can only do 31 bit bus master)
74 * midi poll initial implementation.
75 * Small mixer fixes/cleanups.
76 * Improved support for 5.1 cards.
77 * 0.18 Fix for possible leak in pci_alloc_consistent()
78 * Cleaned up poll() functions (audio and midi). Don't start input.
79 * Restrict DMA pages used to 512Mib range.
80 * New AC97_BOOST mixer ioctl.
81 * 0.19a Added Support for Audigy Cards
82 * Real fix for kernel with highmem support (cast dma_handle to u32).
83 * Fix recording buffering parameters calculation.
84 * Use unsigned long for variables in bit ops.
85 * 0.20a Fixed recording startup
86 * Fixed timer rate setting (it's a 16-bit register)
87 * 0.21 Converted code to use pci_name() instead of accessing slot_name
88 * directly (Eugene Teo)
89 *********************************************************************/
90
91/* These are only included once per module */
92#include <linux/module.h>
93#include <linux/slab.h>
94#include <linux/init.h>
95#include <linux/delay.h>
96#include <linux/proc_fs.h>
97
98#include "hwaccess.h"
99#include "8010.h"
100#include "efxmgr.h"
101#include "cardwo.h"
102#include "cardwi.h"
103#include "cardmo.h"
104#include "cardmi.h"
105#include "recmgr.h"
106#include "ecard.h"
107
108
109#ifdef EMU10K1_SEQUENCER
110#define MIDI_SYNTH_NAME "EMU10K1 MIDI"
111#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
112
113#include "../sound_config.h"
114#include "../midi_synth.h"
115
116/* this should be in dev_table.h */
117#define SNDCARD_EMU10K1 46
118#endif
119
120
121/* the emu10k1 _seems_ to only supports 29 bit (512MiB) bit bus master */
122#define EMU10K1_DMA_MASK 0x1fffffff /* DMA buffer mask for pci_alloc_consist */
123
124#ifndef PCI_VENDOR_ID_CREATIVE
125#define PCI_VENDOR_ID_CREATIVE 0x1102
126#endif
127
128#ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1
129#define PCI_DEVICE_ID_CREATIVE_EMU10K1 0x0002
130#endif
131#ifndef PCI_DEVICE_ID_CREATIVE_AUDIGY
132#define PCI_DEVICE_ID_CREATIVE_AUDIGY 0x0004
133#endif
134
135#define EMU_APS_SUBID 0x40011102
136
137enum {
138 EMU10K1 = 0,
139 AUDIGY,
140};
141
142static char *card_names[] __devinitdata = {
143 "EMU10K1",
144 "Audigy",
145};
146
147static struct pci_device_id emu10k1_pci_tbl[] = {
148 {PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_EMU10K1,
149 PCI_ANY_ID, PCI_ANY_ID, 0, 0, EMU10K1},
150 {PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_AUDIGY,
151 PCI_ANY_ID, PCI_ANY_ID, 0, 0, AUDIGY},
152 {0,}
153};
154
155MODULE_DEVICE_TABLE(pci, emu10k1_pci_tbl);
156
157/* Global var instantiation */
158
159LIST_HEAD(emu10k1_devs);
160
161extern struct file_operations emu10k1_audio_fops;
162extern struct file_operations emu10k1_mixer_fops;
163extern struct file_operations emu10k1_midi_fops;
164
165#ifdef EMU10K1_SEQUENCER
166static struct midi_operations emu10k1_midi_operations;
167#endif
168
169extern irqreturn_t emu10k1_interrupt(int, void *, struct pt_regs *s);
170
171static int __devinit emu10k1_audio_init(struct emu10k1_card *card)
172{
173 /* Assign default playback voice parameters */
174 if (card->is_audigy)
175 card->mchannel_fx = 0;
176 else
177 card->mchannel_fx = 8;
178
179
180 if (card->is_audigy) {
181 /* mono voice */
182 card->waveout.send_dcba[SEND_MONO] = 0xffffffff;
183 card->waveout.send_hgfe[SEND_MONO] = 0x0000ffff;
184
185 /* stereo voice */
186 /* left */
187 card->waveout.send_dcba[SEND_LEFT] = 0x00ff00ff;
188 card->waveout.send_hgfe[SEND_LEFT] = 0x00007f7f;
189 /* right */
190 card->waveout.send_dcba[SEND_RIGHT] = 0xff00ff00;
191 card->waveout.send_hgfe[SEND_RIGHT] = 0x00007f7f;
192
193 card->waveout.send_routing[ROUTE_PCM] = 0x03020100; // Regular pcm
194 card->waveout.send_routing2[ROUTE_PCM] = 0x07060504;
195
196 card->waveout.send_routing[ROUTE_PT] = 0x3f3f3d3c; // Passthrough
197 card->waveout.send_routing2[ROUTE_PT] = 0x3f3f3f3f;
198
199 card->waveout.send_routing[ROUTE_PCM1] = 0x03020100; // Spare
200 card->waveout.send_routing2[ROUTE_PCM1] = 0x07060404;
201
202 } else {
203 /* mono voice */
204 card->waveout.send_dcba[SEND_MONO] = 0x0000ffff;
205
206 /* stereo voice */
207 /* left */
208 card->waveout.send_dcba[SEND_LEFT] = 0x000000ff;
209 /* right */
210 card->waveout.send_dcba[SEND_RIGHT] = 0x0000ff00;
211
212 card->waveout.send_routing[ROUTE_PCM] = 0x3210; // pcm
213 card->waveout.send_routing[ROUTE_PT] = 0x3210; // passthrough
214 card->waveout.send_routing[ROUTE_PCM1] = 0x7654; // /dev/dsp1
215 }
216
217 /* Assign default recording parameters */
218 /* FIXME */
219 if (card->is_aps)
220 card->wavein.recsrc = WAVERECORD_FX;
221 else
222 card->wavein.recsrc = WAVERECORD_AC97;
223
224 card->wavein.fxwc = 0x0003;
225 return 0;
226}
227
228static void emu10k1_audio_cleanup(struct emu10k1_card *card)
229{
230}
231
232static int __devinit emu10k1_register_devices(struct emu10k1_card *card)
233{
234 card->audio_dev = register_sound_dsp(&emu10k1_audio_fops, -1);
235 if (card->audio_dev < 0) {
236 printk(KERN_ERR "emu10k1: cannot register first audio device!\n");
237 goto err_dev;
238 }
239
240 card->audio_dev1 = register_sound_dsp(&emu10k1_audio_fops, -1);
241 if (card->audio_dev1 < 0) {
242 printk(KERN_ERR "emu10k1: cannot register second audio device!\n");
243 goto err_dev1;
244 }
245
246 card->ac97->dev_mixer = register_sound_mixer(&emu10k1_mixer_fops, -1);
247 if (card->ac97->dev_mixer < 0) {
248 printk(KERN_ERR "emu10k1: cannot register mixer device\n");
249 goto err_mixer;
250 }
251
252 card->midi_dev = register_sound_midi(&emu10k1_midi_fops, -1);
253 if (card->midi_dev < 0) {
254 printk(KERN_ERR "emu10k1: cannot register midi device!\n");
255 goto err_midi;
256 }
257
258#ifdef EMU10K1_SEQUENCER
259 card->seq_dev = sound_alloc_mididev();
260 if (card->seq_dev == -1)
261 printk(KERN_WARNING "emu10k1: unable to register sequencer device!");
262 else {
263 std_midi_synth.midi_dev = card->seq_dev;
264 midi_devs[card->seq_dev] =
265 (struct midi_operations *)
266 kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
267
268 if (midi_devs[card->seq_dev] == NULL) {
269 printk(KERN_ERR "emu10k1: unable to allocate memory!");
270 sound_unload_mididev(card->seq_dev);
271 card->seq_dev = -1;
272 /* return without error */
273 } else {
274 memcpy((char *)midi_devs[card->seq_dev],
275 (char *)&emu10k1_midi_operations,
276 sizeof(struct midi_operations));
277 midi_devs[card->seq_dev]->devc = card;
278 sequencer_init();
279 card->seq_mididev = NULL;
280 }
281 }
282#endif
283 return 0;
284
285err_midi:
286 unregister_sound_mixer(card->ac97->dev_mixer);
287err_mixer:
288 unregister_sound_dsp(card->audio_dev);
289err_dev1:
290 unregister_sound_dsp(card->audio_dev);
291err_dev:
292 return -ENODEV;
293}
294
295static void emu10k1_unregister_devices(struct emu10k1_card *card)
296{
297#ifdef EMU10K1_SEQUENCER
298 if (card->seq_dev > -1) {
299 kfree(midi_devs[card->seq_dev]);
300 midi_devs[card->seq_dev] = NULL;
301 sound_unload_mididev(card->seq_dev);
302 card->seq_dev = -1;
303 }
304#endif
305
306 unregister_sound_midi(card->midi_dev);
307 unregister_sound_mixer(card->ac97->dev_mixer);
308 unregister_sound_dsp(card->audio_dev1);
309 unregister_sound_dsp(card->audio_dev);
310}
311
312static int emu10k1_info_proc (char *page, char **start, off_t off,
313 int count, int *eof, void *data)
314{
315 struct emu10k1_card *card = data;
316 int len = 0;
317
318 if (card == NULL)
319 return -ENODEV;
320
321 len += sprintf (page + len, "Driver Version : %s\n", DRIVER_VERSION);
322 len += sprintf (page + len, "Card type : %s\n", card->is_aps ? "Aps" : (card->is_audigy ? "Audigy" : "Emu10k1"));
323 len += sprintf (page + len, "Revision : %d\n", card->chiprev);
324 len += sprintf (page + len, "Model : %#06x\n", card->model);
325 len += sprintf (page + len, "IO : %#06lx-%#06lx\n", card->iobase, card->iobase + card->length - 1);
326 len += sprintf (page + len, "IRQ : %d\n\n", card->irq);
327
328 len += sprintf (page + len, "Registered /dev Entries:\n");
329 len += sprintf (page + len, "/dev/dsp%d\n", card->audio_dev / 16);
330 len += sprintf (page + len, "/dev/dsp%d\n", card->audio_dev1 / 16);
331 len += sprintf (page + len, "/dev/mixer%d\n", card->ac97->dev_mixer / 16);
332 len += sprintf (page + len, "/dev/midi%d\n", card->midi_dev / 16);
333
334#ifdef EMU10K1_SEQUENCER
335 len += sprintf (page + len, "/dev/sequencer\n");
336#endif
337
338 return len;
339}
340
341static int __devinit emu10k1_proc_init(struct emu10k1_card *card)
342{
343 char s[48];
344
345 if (!proc_mkdir ("driver/emu10k1", NULL)) {
346 printk(KERN_ERR "emu10k1: unable to create proc directory driver/emu10k1\n");
347 goto err_out;
348 }
349
350 sprintf(s, "driver/emu10k1/%s", pci_name(card->pci_dev));
351 if (!proc_mkdir (s, NULL)) {
352 printk(KERN_ERR "emu10k1: unable to create proc directory %s\n", s);
353 goto err_emu10k1_proc;
354 }
355
356 sprintf(s, "driver/emu10k1/%s/info", pci_name(card->pci_dev));
357 if (!create_proc_read_entry (s, 0, NULL, emu10k1_info_proc, card)) {
358 printk(KERN_ERR "emu10k1: unable to create proc entry %s\n", s);
359 goto err_dev_proc;
360 }
361
362 if (!card->is_aps) {
363 sprintf(s, "driver/emu10k1/%s/ac97", pci_name(card->pci_dev));
364 if (!create_proc_read_entry (s, 0, NULL, ac97_read_proc, card->ac97)) {
365 printk(KERN_ERR "emu10k1: unable to create proc entry %s\n", s);
366 goto err_proc_ac97;
367 }
368 }
369
370 return 0;
371
372err_proc_ac97:
373 sprintf(s, "driver/emu10k1/%s/info", pci_name(card->pci_dev));
374 remove_proc_entry(s, NULL);
375
376err_dev_proc:
377 sprintf(s, "driver/emu10k1/%s", pci_name(card->pci_dev));
378 remove_proc_entry(s, NULL);
379
380err_emu10k1_proc:
381 remove_proc_entry("driver/emu10k1", NULL);
382
383err_out:
384 return -EIO;
385}
386
387static void emu10k1_proc_cleanup(struct emu10k1_card *card)
388{
389 char s[48];
390
391 if (!card->is_aps) {
392 sprintf(s, "driver/emu10k1/%s/ac97", pci_name(card->pci_dev));
393 remove_proc_entry(s, NULL);
394 }
395
396 sprintf(s, "driver/emu10k1/%s/info", pci_name(card->pci_dev));
397 remove_proc_entry(s, NULL);
398
399 sprintf(s, "driver/emu10k1/%s", pci_name(card->pci_dev));
400 remove_proc_entry(s, NULL);
401
402 remove_proc_entry("driver/emu10k1", NULL);
403}
404
405static int __devinit emu10k1_mixer_init(struct emu10k1_card *card)
406{
407 struct ac97_codec *codec = ac97_alloc_codec();
408
409 if(codec == NULL)
410 {
411 printk(KERN_ERR "emu10k1: cannot allocate mixer\n");
412 return -EIO;
413 }
414 card->ac97 = codec;
415 card->ac97->private_data = card;
416
417 if (!card->is_aps) {
418 card->ac97->id = 0;
419 card->ac97->codec_read = emu10k1_ac97_read;
420 card->ac97->codec_write = emu10k1_ac97_write;
421
422 if (ac97_probe_codec (card->ac97) == 0) {
423 printk(KERN_ERR "emu10k1: unable to probe AC97 codec\n");
424 goto err_out;
425 }
426 /* 5.1: Enable the additional AC97 Slots and unmute extra channels on AC97 codec */
427 if (codec->codec_read(codec, AC97_EXTENDED_ID) & 0x0080){
428 printk(KERN_INFO "emu10k1: SBLive! 5.1 card detected\n");
429 sblive_writeptr(card, AC97SLOT, 0, AC97SLOT_CNTR | AC97SLOT_LFE);
430 codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0);
431 }
432
433 // Force 5bit:
434 //card->ac97->bit_resolution=5;
435
436 /* these will store the original values and never be modified */
437 card->ac97_supported_mixers = card->ac97->supported_mixers;
438 card->ac97_stereo_mixers = card->ac97->stereo_mixers;
439 }
440
441 return 0;
442
443 err_out:
444 ac97_release_codec(card->ac97);
445 return -EIO;
446}
447
448static void emu10k1_mixer_cleanup(struct emu10k1_card *card)
449{
450 ac97_release_codec(card->ac97);
451}
452
453static int __devinit emu10k1_midi_init(struct emu10k1_card *card)
454{
455 int ret;
456
457 card->mpuout = kmalloc(sizeof(struct emu10k1_mpuout), GFP_KERNEL);
458 if (card->mpuout == NULL) {
459 printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuout: out of memory\n");
460 ret = -ENOMEM;
461 goto err_out1;
462 }
463
464 memset(card->mpuout, 0, sizeof(struct emu10k1_mpuout));
465
466 card->mpuout->intr = 1;
467 card->mpuout->status = FLAGS_AVAILABLE;
468 card->mpuout->state = CARDMIDIOUT_STATE_DEFAULT;
469
470 tasklet_init(&card->mpuout->tasklet, emu10k1_mpuout_bh, (unsigned long) card);
471
472 spin_lock_init(&card->mpuout->lock);
473
474 card->mpuin = kmalloc(sizeof(struct emu10k1_mpuin), GFP_KERNEL);
475 if (card->mpuin == NULL) {
476 printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuin: out of memory\n");
477 ret = -ENOMEM;
478 goto err_out2;
479 }
480
481 memset(card->mpuin, 0, sizeof(struct emu10k1_mpuin));
482
483 card->mpuin->status = FLAGS_AVAILABLE;
484
485 tasklet_init(&card->mpuin->tasklet, emu10k1_mpuin_bh, (unsigned long) card->mpuin);
486
487 spin_lock_init(&card->mpuin->lock);
488
489 /* Reset the MPU port */
490 if (emu10k1_mpu_reset(card) < 0) {
491 ERROR();
492 ret = -EIO;
493 goto err_out3;
494 }
495
496 return 0;
497
498err_out3:
499 kfree(card->mpuin);
500err_out2:
501 kfree(card->mpuout);
502err_out1:
503 return ret;
504}
505
506static void emu10k1_midi_cleanup(struct emu10k1_card *card)
507{
508 tasklet_kill(&card->mpuout->tasklet);
509 kfree(card->mpuout);
510
511 tasklet_kill(&card->mpuin->tasklet);
512 kfree(card->mpuin);
513}
514
515static void __devinit voice_init(struct emu10k1_card *card)
516{
517 int i;
518
519 for (i = 0; i < NUM_G; i++)
520 card->voicetable[i] = VOICE_USAGE_FREE;
521}
522
523static void __devinit timer_init(struct emu10k1_card *card)
524{
525 INIT_LIST_HEAD(&card->timers);
526 card->timer_delay = TIMER_STOPPED;
527 spin_lock_init(&card->timer_lock);
528}
529
530static void __devinit addxmgr_init(struct emu10k1_card *card)
531{
532 u32 count;
533
534 for (count = 0; count < MAXPAGES; count++)
535 card->emupagetable[count] = 0;
536
537 /* Mark first page as used */
538 /* This page is reserved by the driver */
539 card->emupagetable[0] = 0x8001;
540 card->emupagetable[1] = MAXPAGES - 1;
541}
542
543static void fx_cleanup(struct patch_manager *mgr)
544{
545 int i;
546 for(i = 0; i < mgr->current_pages; i++)
547 free_page((unsigned long) mgr->patch[i]);
548}
549
550static int __devinit fx_init(struct emu10k1_card *card)
551{
552 struct patch_manager *mgr = &card->mgr;
553 struct dsp_patch *patch;
554 struct dsp_rpatch *rpatch;
555 s32 left, right;
556 int i;
557 u32 pc = 0;
558 u32 patch_n=0;
559 struct emu_efx_info_t emu_efx_info[2]=
560 {{ 20, 10, 0x400, 0x100, 0x20 },
561 { 24, 12, 0x600, 0x400, 0x60 },
562 };
563
564
565 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
566 mgr->ctrl_gpr[i][0] = -1;
567 mgr->ctrl_gpr[i][1] = -1;
568 }
569
570
571 if (card->is_audigy)
572 mgr->current_pages = (2 + PATCHES_PER_PAGE - 1) / PATCHES_PER_PAGE;
573 else
574 /* !! The number below must equal the number of patches, currently 11 !! */
575 mgr->current_pages = (11 + PATCHES_PER_PAGE - 1) / PATCHES_PER_PAGE;
576
577 for (i = 0; i < mgr->current_pages; i++) {
578 mgr->patch[i] = (void *)__get_free_page(GFP_KERNEL);
579 if (mgr->patch[i] == NULL) {
580 mgr->current_pages = i;
581 fx_cleanup(mgr);
582 return -ENOMEM;
583 }
584 memset(mgr->patch[i], 0, PAGE_SIZE);
585 }
586
587 if (card->is_audigy) {
588 for (i = 0; i < 1024; i++)
589 OP(0xf, 0x0c0, 0x0c0, 0x0cf, 0x0c0);
590
591 for (i = 0; i < 512 ; i++)
592 sblive_writeptr(card, A_GPR_BASE+i,0,0);
593
594 pc=0;
595
596 //Pcm input volume
597 OP(0, 0x402, 0x0c0, 0x406, 0x000);
598 OP(0, 0x403, 0x0c0, 0x407, 0x001);
599
600 //CD-Digital input Volume
601 OP(0, 0x404, 0x0c0, 0x40d, 0x42);
602 OP(0, 0x405, 0x0c0, 0x40f, 0x43);
603
604 // CD + PCM
605 OP(6, 0x400, 0x0c0, 0x402, 0x404);
606 OP(6, 0x401, 0x0c0, 0x403, 0x405);
607
608 // Front Output + Master Volume
609 OP(0, 0x68, 0x0c0, 0x408, 0x400);
610 OP(0, 0x69, 0x0c0, 0x409, 0x401);
611
612 // Add-in analog inputs for other speakers
613 OP(6, 0x400, 0x40, 0x400, 0xc0);
614 OP(6, 0x401, 0x41, 0x401, 0xc0);
615
616 // Digital Front + Master Volume
617 OP(0, 0x60, 0x0c0, 0x408, 0x400);
618 OP(0, 0x61, 0x0c0, 0x409, 0x401);
619
620 // Rear Output + Rear Volume
621 OP(0, 0x06e, 0x0c0, 0x419, 0x400);
622 OP(0, 0x06f, 0x0c0, 0x41a, 0x401);
623
624 // Digital Rear Output + Rear Volume
625 OP(0, 0x066, 0x0c0, 0x419, 0x400);
626 OP(0, 0x067, 0x0c0, 0x41a, 0x401);
627
628 // Audigy Drive, Headphone out
629 OP(6, 0x64, 0x0c0, 0x0c0, 0x400);
630 OP(6, 0x65, 0x0c0, 0x0c0, 0x401);
631
632 // ac97 Recording
633 OP(6, 0x76, 0x0c0, 0x0c0, 0x40);
634 OP(6, 0x77, 0x0c0, 0x0c0, 0x41);
635
636 // Center = sub = Left/2 + Right/2
637 OP(0xe, 0x400, 0x401, 0xcd, 0x400);
638
639 // center/sub Volume (master)
640 OP(0, 0x06a, 0x0c0, 0x408, 0x400);
641 OP(0, 0x06b, 0x0c0, 0x409, 0x400);
642
643 // Digital center/sub Volume (master)
644 OP(0, 0x062, 0x0c0, 0x408, 0x400);
645 OP(0, 0x063, 0x0c0, 0x409, 0x400);
646
647 ROUTING_PATCH_START(rpatch, "Routing");
648 ROUTING_PATCH_END(rpatch);
649
650 /* delimiter patch */
651 patch = PATCH(mgr, patch_n);
652 patch->code_size = 0;
653
654
655 sblive_writeptr(card, 0x53, 0, 0);
656 } else {
657 for (i = 0; i < 512 ; i++)
658 OP(6, 0x40, 0x40, 0x40, 0x40);
659
660 for (i = 0; i < 256; i++)
661 sblive_writeptr_tag(card, 0,
662 FXGPREGBASE + i, 0,
663 TANKMEMADDRREGBASE + i, 0,
664 TAGLIST_END);
665
666
667 pc = 0;
668
669 //first free GPR = 0x11b
670
671
672 /* FX volume correction and Volume control*/
673 INPUT_PATCH_START(patch, "Pcm L vol", 0x0, 0);
674 GET_OUTPUT_GPR(patch, 0x100, 0x0);
675 GET_CONTROL_GPR(patch, 0x106, "Vol", 0, 0x7fffffff);
676 GET_DYNAMIC_GPR(patch, 0x112);
677
678 OP(4, 0x112, 0x40, PCM_IN_L, 0x44); //*4
679 OP(0, 0x100, 0x040, 0x112, 0x106); //*vol
680 INPUT_PATCH_END(patch);
681
682
683 INPUT_PATCH_START(patch, "Pcm R vol", 0x1, 0);
684 GET_OUTPUT_GPR(patch, 0x101, 0x1);
685 GET_CONTROL_GPR(patch, 0x107, "Vol", 0, 0x7fffffff);
686 GET_DYNAMIC_GPR(patch, 0x112);
687
688 OP(4, 0x112, 0x40, PCM_IN_R, 0x44);
689 OP(0, 0x101, 0x040, 0x112, 0x107);
690
691 INPUT_PATCH_END(patch);
692
693
694 // CD-Digital In Volume control
695 INPUT_PATCH_START(patch, "CD-Digital Vol L", 0x12, 0);
696 GET_OUTPUT_GPR(patch, 0x10c, 0x12);
697 GET_CONTROL_GPR(patch, 0x10d, "Vol", 0, 0x7fffffff);
698
699 OP(0, 0x10c, 0x040, SPDIF_CD_L, 0x10d);
700 INPUT_PATCH_END(patch);
701
702 INPUT_PATCH_START(patch, "CD-Digital Vol R", 0x13, 0);
703 GET_OUTPUT_GPR(patch, 0x10e, 0x13);
704 GET_CONTROL_GPR(patch, 0x10f, "Vol", 0, 0x7fffffff);
705
706 OP(0, 0x10e, 0x040, SPDIF_CD_R, 0x10f);
707 INPUT_PATCH_END(patch);
708
709 //Volume Correction for Multi-channel Inputs
710 INPUT_PATCH_START(patch, "Multi-Channel Gain", 0x08, 0);
711 patch->input=patch->output=0x3F00;
712
713 GET_OUTPUT_GPR(patch, 0x113, MULTI_FRONT_L);
714 GET_OUTPUT_GPR(patch, 0x114, MULTI_FRONT_R);
715 GET_OUTPUT_GPR(patch, 0x115, MULTI_REAR_L);
716 GET_OUTPUT_GPR(patch, 0x116, MULTI_REAR_R);
717 GET_OUTPUT_GPR(patch, 0x117, MULTI_CENTER);
718 GET_OUTPUT_GPR(patch, 0x118, MULTI_LFE);
719
720 OP(4, 0x113, 0x40, MULTI_FRONT_L, 0x44);
721 OP(4, 0x114, 0x40, MULTI_FRONT_R, 0x44);
722 OP(4, 0x115, 0x40, MULTI_REAR_L, 0x44);
723 OP(4, 0x116, 0x40, MULTI_REAR_R, 0x44);
724 OP(4, 0x117, 0x40, MULTI_CENTER, 0x44);
725 OP(4, 0x118, 0x40, MULTI_LFE, 0x44);
726
727 INPUT_PATCH_END(patch);
728
729
730 //Routing patch start
731 ROUTING_PATCH_START(rpatch, "Routing");
732 GET_INPUT_GPR(rpatch, 0x100, 0x0);
733 GET_INPUT_GPR(rpatch, 0x101, 0x1);
734 GET_INPUT_GPR(rpatch, 0x10c, 0x12);
735 GET_INPUT_GPR(rpatch, 0x10e, 0x13);
736 GET_INPUT_GPR(rpatch, 0x113, MULTI_FRONT_L);
737 GET_INPUT_GPR(rpatch, 0x114, MULTI_FRONT_R);
738 GET_INPUT_GPR(rpatch, 0x115, MULTI_REAR_L);
739 GET_INPUT_GPR(rpatch, 0x116, MULTI_REAR_R);
740 GET_INPUT_GPR(rpatch, 0x117, MULTI_CENTER);
741 GET_INPUT_GPR(rpatch, 0x118, MULTI_LFE);
742
743 GET_DYNAMIC_GPR(rpatch, 0x102);
744 GET_DYNAMIC_GPR(rpatch, 0x103);
745
746 GET_OUTPUT_GPR(rpatch, 0x104, 0x8);
747 GET_OUTPUT_GPR(rpatch, 0x105, 0x9);
748 GET_OUTPUT_GPR(rpatch, 0x10a, 0x2);
749 GET_OUTPUT_GPR(rpatch, 0x10b, 0x3);
750
751
752 /* input buffer */
753 OP(6, 0x102, AC97_IN_L, 0x40, 0x40);
754 OP(6, 0x103, AC97_IN_R, 0x40, 0x40);
755
756
757 /* Digital In + PCM + MULTI_FRONT-> AC97 out (front speakers)*/
758 OP(6, AC97_FRONT_L, 0x100, 0x10c, 0x113);
759
760 CONNECT(MULTI_FRONT_L, AC97_FRONT_L);
761 CONNECT(PCM_IN_L, AC97_FRONT_L);
762 CONNECT(SPDIF_CD_L, AC97_FRONT_L);
763
764 OP(6, AC97_FRONT_R, 0x101, 0x10e, 0x114);
765
766 CONNECT(MULTI_FRONT_R, AC97_FRONT_R);
767 CONNECT(PCM_IN_R, AC97_FRONT_R);
768 CONNECT(SPDIF_CD_R, AC97_FRONT_R);
769
770 /* Digital In + PCM + AC97 In + PCM1 + MULTI_REAR --> Rear Channel */
771 OP(6, 0x104, PCM1_IN_L, 0x100, 0x115);
772 OP(6, 0x104, 0x104, 0x10c, 0x102);
773
774 CONNECT(MULTI_REAR_L, ANALOG_REAR_L);
775 CONNECT(AC97_IN_L, ANALOG_REAR_L);
776 CONNECT(PCM_IN_L, ANALOG_REAR_L);
777 CONNECT(SPDIF_CD_L, ANALOG_REAR_L);
778 CONNECT(PCM1_IN_L, ANALOG_REAR_L);
779
780 OP(6, 0x105, PCM1_IN_R, 0x101, 0x116);
781 OP(6, 0x105, 0x105, 0x10e, 0x103);
782
783 CONNECT(MULTI_REAR_R, ANALOG_REAR_R);
784 CONNECT(AC97_IN_R, ANALOG_REAR_R);
785 CONNECT(PCM_IN_R, ANALOG_REAR_R);
786 CONNECT(SPDIF_CD_R, ANALOG_REAR_R);
787 CONNECT(PCM1_IN_R, ANALOG_REAR_R);
788
789 /* Digital In + PCM + AC97 In + MULTI_FRONT --> Digital out */
790 OP(6, 0x10b, 0x100, 0x102, 0x10c);
791 OP(6, 0x10b, 0x10b, 0x113, 0x40);
792
793 CONNECT(MULTI_FRONT_L, DIGITAL_OUT_L);
794 CONNECT(PCM_IN_L, DIGITAL_OUT_L);
795 CONNECT(AC97_IN_L, DIGITAL_OUT_L);
796 CONNECT(SPDIF_CD_L, DIGITAL_OUT_L);
797
798 OP(6, 0x10a, 0x101, 0x103, 0x10e);
799 OP(6, 0x10b, 0x10b, 0x114, 0x40);
800
801 CONNECT(MULTI_FRONT_R, DIGITAL_OUT_R);
802 CONNECT(PCM_IN_R, DIGITAL_OUT_R);
803 CONNECT(AC97_IN_R, DIGITAL_OUT_R);
804 CONNECT(SPDIF_CD_R, DIGITAL_OUT_R);
805
806 /* AC97 In --> ADC Recording Buffer */
807 OP(6, ADC_REC_L, 0x102, 0x40, 0x40);
808
809 CONNECT(AC97_IN_L, ADC_REC_L);
810
811 OP(6, ADC_REC_R, 0x103, 0x40, 0x40);
812
813 CONNECT(AC97_IN_R, ADC_REC_R);
814
815
816 /* fx12:Analog-Center */
817 OP(6, ANALOG_CENTER, 0x117, 0x40, 0x40);
818 CONNECT(MULTI_CENTER, ANALOG_CENTER);
819
820 /* fx11:Analog-LFE */
821 OP(6, ANALOG_LFE, 0x118, 0x40, 0x40);
822 CONNECT(MULTI_LFE, ANALOG_LFE);
823
824 /* fx12:Digital-Center */
825 OP(6, DIGITAL_CENTER, 0x117, 0x40, 0x40);
826 CONNECT(MULTI_CENTER, DIGITAL_CENTER);
827
828 /* fx11:Analog-LFE */
829 OP(6, DIGITAL_LFE, 0x118, 0x40, 0x40);
830 CONNECT(MULTI_LFE, DIGITAL_LFE);
831
832 ROUTING_PATCH_END(rpatch);
833
834
835 // Rear volume control
836 OUTPUT_PATCH_START(patch, "Vol Rear L", 0x8, 0);
837 GET_INPUT_GPR(patch, 0x104, 0x8);
838 GET_CONTROL_GPR(patch, 0x119, "Vol", 0, 0x7fffffff);
839
840 OP(0, ANALOG_REAR_L, 0x040, 0x104, 0x119);
841 OUTPUT_PATCH_END(patch);
842
843 OUTPUT_PATCH_START(patch, "Vol Rear R", 0x9, 0);
844 GET_INPUT_GPR(patch, 0x105, 0x9);
845 GET_CONTROL_GPR(patch, 0x11a, "Vol", 0, 0x7fffffff);
846
847 OP(0, ANALOG_REAR_R, 0x040, 0x105, 0x11a);
848 OUTPUT_PATCH_END(patch);
849
850
851 //Master volume control on front-digital
852 OUTPUT_PATCH_START(patch, "Vol Master L", 0x2, 1);
853 GET_INPUT_GPR(patch, 0x10a, 0x2);
854 GET_CONTROL_GPR(patch, 0x108, "Vol", 0, 0x7fffffff);
855
856 OP(0, DIGITAL_OUT_L, 0x040, 0x10a, 0x108);
857 OUTPUT_PATCH_END(patch);
858
859
860 OUTPUT_PATCH_START(patch, "Vol Master R", 0x3, 1);
861 GET_INPUT_GPR(patch, 0x10b, 0x3);
862 GET_CONTROL_GPR(patch, 0x109, "Vol", 0, 0x7fffffff);
863
864 OP(0, DIGITAL_OUT_R, 0x040, 0x10b, 0x109);
865 OUTPUT_PATCH_END(patch);
866
867
868 /* delimiter patch */
869 patch = PATCH(mgr, patch_n);
870 patch->code_size = 0;
871
872
873 sblive_writeptr(card, DBG, 0, 0);
874 }
875
876 spin_lock_init(&mgr->lock);
877
878 // Set up Volume controls, try to keep this the same for both Audigy and Live
879
880 //Master volume
881 mgr->ctrl_gpr[SOUND_MIXER_VOLUME][0] = 8;
882 mgr->ctrl_gpr[SOUND_MIXER_VOLUME][1] = 9;
883
884 left = card->ac97->mixer_state[SOUND_MIXER_VOLUME] & 0xff;
885 right = (card->ac97->mixer_state[SOUND_MIXER_VOLUME] >> 8) & 0xff;
886
887 emu10k1_set_volume_gpr(card, 8, left, 1 << card->ac97->bit_resolution);
888 emu10k1_set_volume_gpr(card, 9, right, 1 << card->ac97->bit_resolution);
889
890 //Rear volume
891 mgr->ctrl_gpr[ SOUND_MIXER_OGAIN ][0] = 0x19;
892 mgr->ctrl_gpr[ SOUND_MIXER_OGAIN ][1] = 0x1a;
893
894 left = right = 67;
895 card->ac97->mixer_state[SOUND_MIXER_OGAIN] = (right << 8) | left;
896
897 card->ac97->supported_mixers |= SOUND_MASK_OGAIN;
898 card->ac97->stereo_mixers |= SOUND_MASK_OGAIN;
899
900 emu10k1_set_volume_gpr(card, 0x19, left, VOL_5BIT);
901 emu10k1_set_volume_gpr(card, 0x1a, right, VOL_5BIT);
902
903 //PCM Volume
904 mgr->ctrl_gpr[SOUND_MIXER_PCM][0] = 6;
905 mgr->ctrl_gpr[SOUND_MIXER_PCM][1] = 7;
906
907 left = card->ac97->mixer_state[SOUND_MIXER_PCM] & 0xff;
908 right = (card->ac97->mixer_state[SOUND_MIXER_PCM] >> 8) & 0xff;
909
910 emu10k1_set_volume_gpr(card, 6, left, VOL_5BIT);
911 emu10k1_set_volume_gpr(card, 7, right, VOL_5BIT);
912
913 //CD-Digital Volume
914 mgr->ctrl_gpr[SOUND_MIXER_DIGITAL1][0] = 0xd;
915 mgr->ctrl_gpr[SOUND_MIXER_DIGITAL1][1] = 0xf;
916
917 left = right = 67;
918 card->ac97->mixer_state[SOUND_MIXER_DIGITAL1] = (right << 8) | left;
919
920 card->ac97->supported_mixers |= SOUND_MASK_DIGITAL1;
921 card->ac97->stereo_mixers |= SOUND_MASK_DIGITAL1;
922
923 emu10k1_set_volume_gpr(card, 0xd, left, VOL_5BIT);
924 emu10k1_set_volume_gpr(card, 0xf, right, VOL_5BIT);
925
926
927 //hard wire the ac97's pcm, pcm volume is done above using dsp code.
928 if (card->is_audigy)
929 //for Audigy, we mute it and use the philips 6 channel DAC instead
930 emu10k1_ac97_write(card->ac97, 0x18, 0x8000);
931 else
932 //For the Live we hardwire it to full volume
933 emu10k1_ac97_write(card->ac97, 0x18, 0x0);
934
935 //remove it from the ac97_codec's control
936 card->ac97_supported_mixers &= ~SOUND_MASK_PCM;
937 card->ac97_stereo_mixers &= ~SOUND_MASK_PCM;
938
939 //set Igain to 0dB by default, maybe consider hardwiring it here.
940 emu10k1_ac97_write(card->ac97, AC97_RECORD_GAIN, 0x0000);
941 card->ac97->mixer_state[SOUND_MIXER_IGAIN] = 0x101;
942
943 return 0;
944}
945
946static int __devinit hw_init(struct emu10k1_card *card)
947{
948 int nCh;
949 u32 pagecount; /* tmp */
950 int ret;
951
952 /* Disable audio and lock cache */
953 emu10k1_writefn0(card, HCFG, HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE);
954
955 /* Reset recording buffers */
956 sblive_writeptr_tag(card, 0,
957 MICBS, ADCBS_BUFSIZE_NONE,
958 MICBA, 0,
959 FXBS, ADCBS_BUFSIZE_NONE,
960 FXBA, 0,
961 ADCBS, ADCBS_BUFSIZE_NONE,
962 ADCBA, 0,
963 TAGLIST_END);
964
965 /* Disable channel interrupt */
966 emu10k1_writefn0(card, INTE, 0);
967 sblive_writeptr_tag(card, 0,
968 CLIEL, 0,
969 CLIEH, 0,
970 SOLEL, 0,
971 SOLEH, 0,
972 TAGLIST_END);
973
974 if (card->is_audigy) {
975 sblive_writeptr_tag(card,0,
976 0x5e,0xf00,
977 0x5f,0x3,
978 TAGLIST_END);
979 }
980
981 /* Init envelope engine */
982 for (nCh = 0; nCh < NUM_G; nCh++) {
983 sblive_writeptr_tag(card, nCh,
984 DCYSUSV, 0,
985 IP, 0,
986 VTFT, 0xffff,
987 CVCF, 0xffff,
988 PTRX, 0,
989 //CPF, 0,
990 CCR, 0,
991
992 PSST, 0,
993 DSL, 0x10,
994 CCCA, 0,
995 Z1, 0,
996 Z2, 0,
997 FXRT, 0xd01c0000,
998
999 ATKHLDM, 0,
1000 DCYSUSM, 0,
1001 IFATN, 0xffff,
1002 PEFE, 0,
1003 FMMOD, 0,
1004 TREMFRQ, 24, /* 1 Hz */
1005 FM2FRQ2, 24, /* 1 Hz */
1006 TEMPENV, 0,
1007
1008 /*** These are last so OFF prevents writing ***/
1009 LFOVAL2, 0,
1010 LFOVAL1, 0,
1011 ATKHLDV, 0,
1012 ENVVOL, 0,
1013 ENVVAL, 0,
1014 TAGLIST_END);
1015 sblive_writeptr(card, CPF, nCh, 0);
1016 /*
1017 Audigy FXRT initialization
1018 reversed eng'd, may not be accurate.
1019 */
1020 if (card->is_audigy) {
1021 sblive_writeptr_tag(card,nCh,
1022 0x4c,0x0,
1023 0x4d,0x0,
1024 0x4e,0x0,
1025 0x4f,0x0,
1026 A_FXRT1, 0x3f3f3f3f,
1027 A_FXRT2, 0x3f3f3f3f,
1028 A_SENDAMOUNTS, 0,
1029 TAGLIST_END);
1030 }
1031 }
1032
1033
1034 /*
1035 ** Init to 0x02109204 :
1036 ** Clock accuracy = 0 (1000ppm)
1037 ** Sample Rate = 2 (48kHz)
1038 ** Audio Channel = 1 (Left of 2)
1039 ** Source Number = 0 (Unspecified)
1040 ** Generation Status = 1 (Original for Cat Code 12)
1041 ** Cat Code = 12 (Digital Signal Mixer)
1042 ** Mode = 0 (Mode 0)
1043 ** Emphasis = 0 (None)
1044 ** CP = 1 (Copyright unasserted)
1045 ** AN = 0 (Digital audio)
1046 ** P = 0 (Consumer)
1047 */
1048
1049 sblive_writeptr_tag(card, 0,
1050
1051 /* SPDIF0 */
1052 SPCS0, (SPCS_CLKACCY_1000PPM | 0x002000000 |
1053 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT),
1054
1055 /* SPDIF1 */
1056 SPCS1, (SPCS_CLKACCY_1000PPM | 0x002000000 |
1057 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT),
1058
1059 /* SPDIF2 & SPDIF3 */
1060 SPCS2, (SPCS_CLKACCY_1000PPM | 0x002000000 |
1061 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT),
1062
1063 TAGLIST_END);
1064
1065 if (card->is_audigy && (card->chiprev == 4)) {
1066 /* Hacks for Alice3 to work independent of haP16V driver */
1067 u32 tmp;
1068
1069 //Setup SRCMulti_I2S SamplingRate
1070 tmp = sblive_readptr(card, A_SPDIF_SAMPLERATE, 0);
1071 tmp &= 0xfffff1ff;
1072 tmp |= (0x2<<9);
1073 sblive_writeptr(card, A_SPDIF_SAMPLERATE, 0, tmp);
1074
1075 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
1076 emu10k1_writefn0(card, 0x20, 0x600000);
1077 emu10k1_writefn0(card, 0x24, 0x14);
1078
1079 /* Setup SRCMulti Input Audio Enable */
1080 emu10k1_writefn0(card, 0x20, 0x6E0000);
1081 emu10k1_writefn0(card, 0x24, 0xFF00FF00);
1082 }
1083
1084 ret = fx_init(card); /* initialize effects engine */
1085 if (ret < 0)
1086 return ret;
1087
1088 card->tankmem.size = 0;
1089
1090 card->virtualpagetable.size = MAXPAGES * sizeof(u32);
1091
1092 card->virtualpagetable.addr = pci_alloc_consistent(card->pci_dev, card->virtualpagetable.size, &card->virtualpagetable.dma_handle);
1093 if (card->virtualpagetable.addr == NULL) {
1094 ERROR();
1095 ret = -ENOMEM;
1096 goto err0;
1097 }
1098
1099 card->silentpage.size = EMUPAGESIZE;
1100
1101 card->silentpage.addr = pci_alloc_consistent(card->pci_dev, card->silentpage.size, &card->silentpage.dma_handle);
1102 if (card->silentpage.addr == NULL) {
1103 ERROR();
1104 ret = -ENOMEM;
1105 goto err1;
1106 }
1107
1108 for (pagecount = 0; pagecount < MAXPAGES; pagecount++)
1109 ((u32 *) card->virtualpagetable.addr)[pagecount] = cpu_to_le32(((u32) card->silentpage.dma_handle * 2) | pagecount);
1110
1111 /* Init page table & tank memory base register */
1112 sblive_writeptr_tag(card, 0,
1113 PTB, (u32) card->virtualpagetable.dma_handle,
1114 TCB, 0,
1115 TCBS, 0,
1116 TAGLIST_END);
1117
1118 for (nCh = 0; nCh < NUM_G; nCh++) {
1119 sblive_writeptr_tag(card, nCh,
1120 MAPA, MAP_PTI_MASK | ((u32) card->silentpage.dma_handle * 2),
1121 MAPB, MAP_PTI_MASK | ((u32) card->silentpage.dma_handle * 2),
1122 TAGLIST_END);
1123 }
1124
1125 /* Hokay, now enable the AUD bit */
1126 /* Enable Audio = 1 */
1127 /* Mute Disable Audio = 0 */
1128 /* Lock Tank Memory = 1 */
1129 /* Lock Sound Memory = 0 */
1130 /* Auto Mute = 1 */
1131 if (card->is_audigy) {
1132 if (card->chiprev == 4)
1133 emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_AC3ENABLE_CDSPDIF | HCFG_AC3ENABLE_GPSPDIF | HCFG_AUTOMUTE | HCFG_JOYENABLE);
1134 else
1135 emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_AUTOMUTE | HCFG_JOYENABLE);
1136 } else {
1137 if (card->model == 0x20 || card->model == 0xc400 ||
1138 (card->model == 0x21 && card->chiprev < 6))
1139 emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE);
1140 else
1141 emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE);
1142 }
1143 /* Enable Vol_Ctrl irqs */
1144 emu10k1_irq_enable(card, INTE_VOLINCRENABLE | INTE_VOLDECRENABLE | INTE_MUTEENABLE | INTE_FXDSPENABLE);
1145
1146 if (card->is_audigy && (card->chiprev == 4)) {
1147 /* Unmute Analog now. Set GPO6 to 1 for Apollo.
1148 * This has to be done after init ALice3 I2SOut beyond 48KHz.
1149 * So, sequence is important. */
1150 u32 tmp = emu10k1_readfn0(card, A_IOCFG);
1151 tmp |= 0x0040;
1152 emu10k1_writefn0(card, A_IOCFG, tmp);
1153 }
1154
1155 /* FIXME: TOSLink detection */
1156 card->has_toslink = 0;
1157
1158 /* Initialize digital passthrough variables */
1159 card->pt.pos_gpr = card->pt.intr_gpr = card->pt.enable_gpr = -1;
1160 card->pt.selected = 0;
1161 card->pt.state = PT_STATE_INACTIVE;
1162 card->pt.spcs_to_use = 0x01;
1163 card->pt.patch_name = "AC3pass";
1164 card->pt.intr_gpr_name = "count";
1165 card->pt.enable_gpr_name = "enable";
1166 card->pt.pos_gpr_name = "ptr";
1167 spin_lock_init(&card->pt.lock);
1168 init_waitqueue_head(&card->pt.wait);
1169
1170/* tmp = sblive_readfn0(card, HCFG);
1171 if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
1172 sblive_writefn0(card, HCFG, tmp | 0x800);
1173
1174 udelay(512);
1175
1176 if (tmp != (sblive_readfn0(card, HCFG) & ~0x800)) {
1177 card->has_toslink = 1;
1178 sblive_writefn0(card, HCFG, tmp);
1179 }
1180 }
1181*/
1182 return 0;
1183
1184 err1:
1185 pci_free_consistent(card->pci_dev, card->virtualpagetable.size, card->virtualpagetable.addr, card->virtualpagetable.dma_handle);
1186 err0:
1187 fx_cleanup(&card->mgr);
1188
1189 return ret;
1190}
1191
1192static int __devinit emu10k1_init(struct emu10k1_card *card)
1193{
1194 /* Init Card */
1195 if (hw_init(card) < 0)
1196 return -1;
1197
1198 voice_init(card);
1199 timer_init(card);
1200 addxmgr_init(card);
1201
1202 DPD(2, " hw control register -> %#x\n", emu10k1_readfn0(card, HCFG));
1203
1204 return 0;
1205}
1206
1207static void emu10k1_cleanup(struct emu10k1_card *card)
1208{
1209 int ch;
1210
1211 emu10k1_writefn0(card, INTE, 0);
1212
1213 /** Shutdown the chip **/
1214 for (ch = 0; ch < NUM_G; ch++)
1215 sblive_writeptr(card, DCYSUSV, ch, 0);
1216
1217 for (ch = 0; ch < NUM_G; ch++) {
1218 sblive_writeptr_tag(card, ch,
1219 VTFT, 0,
1220 CVCF, 0,
1221 PTRX, 0,
1222 //CPF, 0,
1223 TAGLIST_END);
1224 sblive_writeptr(card, CPF, ch, 0);
1225 }
1226
1227 /* Disable audio and lock cache */
1228 emu10k1_writefn0(card, HCFG, HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE);
1229
1230 sblive_writeptr_tag(card, 0,
1231 PTB, 0,
1232
1233 /* Reset recording buffers */
1234 MICBS, ADCBS_BUFSIZE_NONE,
1235 MICBA, 0,
1236 FXBS, ADCBS_BUFSIZE_NONE,
1237 FXBA, 0,
1238 FXWC, 0,
1239 ADCBS, ADCBS_BUFSIZE_NONE,
1240 ADCBA, 0,
1241 TCBS, 0,
1242 TCB, 0,
1243 DBG, 0x8000,
1244
1245 /* Disable channel interrupt */
1246 CLIEL, 0,
1247 CLIEH, 0,
1248 SOLEL, 0,
1249 SOLEH, 0,
1250 TAGLIST_END);
1251
1252 if (card->is_audigy)
1253 sblive_writeptr(card, 0, A_DBG, A_DBG_SINGLE_STEP);
1254
1255 pci_free_consistent(card->pci_dev, card->virtualpagetable.size, card->virtualpagetable.addr, card->virtualpagetable.dma_handle);
1256 pci_free_consistent(card->pci_dev, card->silentpage.size, card->silentpage.addr, card->silentpage.dma_handle);
1257
1258 if(card->tankmem.size != 0)
1259 pci_free_consistent(card->pci_dev, card->tankmem.size, card->tankmem.addr, card->tankmem.dma_handle);
1260
1261 /* release patch storage memory */
1262 fx_cleanup(&card->mgr);
1263}
1264
1265/* Driver initialization routine */
1266static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
1267{
1268 struct emu10k1_card *card;
1269 u32 subsysvid;
1270 int ret;
1271
1272 if (pci_set_dma_mask(pci_dev, EMU10K1_DMA_MASK)) {
1273 printk(KERN_ERR "emu10k1: architecture does not support 29bit PCI busmaster DMA\n");
1274 return -ENODEV;
1275 }
1276
1277 if (pci_enable_device(pci_dev))
1278 return -EIO;
1279
1280 pci_set_master(pci_dev);
1281
1282 if ((card = kmalloc(sizeof(struct emu10k1_card), GFP_KERNEL)) == NULL) {
1283 printk(KERN_ERR "emu10k1: out of memory\n");
1284 return -ENOMEM;
1285 }
1286 memset(card, 0, sizeof(struct emu10k1_card));
1287
1288 card->iobase = pci_resource_start(pci_dev, 0);
1289 card->length = pci_resource_len(pci_dev, 0);
1290
1291 if (request_region(card->iobase, card->length, card_names[pci_id->driver_data]) == NULL) {
1292 printk(KERN_ERR "emu10k1: IO space in use\n");
1293 ret = -EBUSY;
1294 goto err_region;
1295 }
1296
1297 pci_set_drvdata(pci_dev, card);
1298
1299 card->irq = pci_dev->irq;
1300 card->pci_dev = pci_dev;
1301
1302 /* Reserve IRQ Line */
1303 if (request_irq(card->irq, emu10k1_interrupt, SA_SHIRQ, card_names[pci_id->driver_data], card)) {
1304 printk(KERN_ERR "emu10k1: IRQ in use\n");
1305 ret = -EBUSY;
1306 goto err_irq;
1307 }
1308
1309 pci_read_config_byte(pci_dev, PCI_REVISION_ID, &card->chiprev);
1310 pci_read_config_word(pci_dev, PCI_SUBSYSTEM_ID, &card->model);
1311
1312 printk(KERN_INFO "emu10k1: %s rev %d model %#04x found, IO at %#04lx-%#04lx, IRQ %d\n",
1313 card_names[pci_id->driver_data], card->chiprev, card->model, card->iobase,
1314 card->iobase + card->length - 1, card->irq);
1315
1316 if (pci_id->device == PCI_DEVICE_ID_CREATIVE_AUDIGY)
1317 card->is_audigy = 1;
1318
1319 pci_read_config_dword(pci_dev, PCI_SUBSYSTEM_VENDOR_ID, &subsysvid);
1320 card->is_aps = (subsysvid == EMU_APS_SUBID);
1321
1322 spin_lock_init(&card->lock);
1323 init_MUTEX(&card->open_sem);
1324 card->open_mode = 0;
1325 init_waitqueue_head(&card->open_wait);
1326
1327 ret = emu10k1_audio_init(card);
1328 if (ret < 0) {
1329 printk(KERN_ERR "emu10k1: cannot initialize audio devices\n");
1330 goto err_audio;
1331 }
1332
1333 ret = emu10k1_mixer_init(card);
1334 if (ret < 0) {
1335 printk(KERN_ERR "emu10k1: cannot initialize AC97 codec\n");
1336 goto err_mixer;
1337 }
1338
1339 ret = emu10k1_midi_init(card);
1340 if (ret < 0) {
1341 printk(KERN_ERR "emu10k1: cannot register midi device\n");
1342 goto err_midi;
1343 }
1344
1345 ret = emu10k1_init(card);
1346 if (ret < 0) {
1347 printk(KERN_ERR "emu10k1: cannot initialize device\n");
1348 goto err_emu10k1_init;
1349 }
1350
1351 if (card->is_aps)
1352 emu10k1_ecard_init(card);
1353
1354 ret = emu10k1_register_devices(card);
1355 if (ret < 0)
1356 goto err_register;
1357
1358 /* proc entries must be created after registering devices, as
1359 * emu10k1_info_proc prints card->audio_dev &co. */
1360 ret = emu10k1_proc_init(card);
1361 if (ret < 0) {
1362 printk(KERN_ERR "emu10k1: cannot initialize proc directory\n");
1363 goto err_proc;
1364 }
1365
1366 list_add(&card->list, &emu10k1_devs);
1367
1368 return 0;
1369
1370err_proc:
1371 emu10k1_unregister_devices(card);
1372
1373err_register:
1374 emu10k1_cleanup(card);
1375
1376err_emu10k1_init:
1377 emu10k1_midi_cleanup(card);
1378
1379err_midi:
1380 emu10k1_mixer_cleanup(card);
1381
1382err_mixer:
1383 emu10k1_audio_cleanup(card);
1384
1385err_audio:
1386 free_irq(card->irq, card);
1387
1388err_irq:
1389 release_region(card->iobase, card->length);
1390 pci_set_drvdata(pci_dev, NULL);
1391
1392err_region:
1393 kfree(card);
1394
1395 return ret;
1396}
1397
1398static void __devexit emu10k1_remove(struct pci_dev *pci_dev)
1399{
1400 struct emu10k1_card *card = pci_get_drvdata(pci_dev);
1401
1402 list_del(&card->list);
1403
1404 emu10k1_unregister_devices(card);
1405 emu10k1_cleanup(card);
1406 emu10k1_midi_cleanup(card);
1407 emu10k1_mixer_cleanup(card);
1408 emu10k1_proc_cleanup(card);
1409 emu10k1_audio_cleanup(card);
1410 free_irq(card->irq, card);
1411 release_region(card->iobase, card->length);
1412 kfree(card);
1413 pci_set_drvdata(pci_dev, NULL);
1414}
1415
1416MODULE_AUTHOR("Bertrand Lee, Cai Ying. (Email to: emu10k1-devel@lists.sourceforge.net)");
1417MODULE_DESCRIPTION("Creative EMU10K1 PCI Audio Driver v" DRIVER_VERSION "\nCopyright (C) 1999 Creative Technology Ltd.");
1418MODULE_LICENSE("GPL");
1419
1420static struct pci_driver emu10k1_pci_driver = {
1421 .name = "emu10k1",
1422 .id_table = emu10k1_pci_tbl,
1423 .probe = emu10k1_probe,
1424 .remove = __devexit_p(emu10k1_remove),
1425};
1426
1427static int __init emu10k1_init_module(void)
1428{
1429 printk(KERN_INFO "Creative EMU10K1 PCI Audio Driver, version " DRIVER_VERSION ", " __TIME__ " " __DATE__ "\n");
1430
1431 return pci_module_init(&emu10k1_pci_driver);
1432}
1433
1434static void __exit emu10k1_cleanup_module(void)
1435{
1436 pci_unregister_driver(&emu10k1_pci_driver);
1437
1438 return;
1439}
1440
1441module_init(emu10k1_init_module);
1442module_exit(emu10k1_cleanup_module);
1443
1444#ifdef EMU10K1_SEQUENCER
1445
1446/* in midi.c */
1447extern int emu10k1_seq_midi_open(int dev, int mode,
1448 void (*input)(int dev, unsigned char midi_byte),
1449 void (*output)(int dev));
1450extern void emu10k1_seq_midi_close(int dev);
1451extern int emu10k1_seq_midi_out(int dev, unsigned char midi_byte);
1452extern int emu10k1_seq_midi_start_read(int dev);
1453extern int emu10k1_seq_midi_end_read(int dev);
1454extern void emu10k1_seq_midi_kick(int dev);
1455extern int emu10k1_seq_midi_buffer_status(int dev);
1456
1457static struct midi_operations emu10k1_midi_operations =
1458{
1459 THIS_MODULE,
1460 {"EMU10K1 MIDI", 0, 0, SNDCARD_EMU10K1},
1461 &std_midi_synth,
1462 {0},
1463 emu10k1_seq_midi_open,
1464 emu10k1_seq_midi_close,
1465 NULL,
1466 emu10k1_seq_midi_out,
1467 emu10k1_seq_midi_start_read,
1468 emu10k1_seq_midi_end_read,
1469 emu10k1_seq_midi_kick,
1470 NULL,
1471 emu10k1_seq_midi_buffer_status,
1472 NULL
1473};
1474
1475#endif
diff --git a/sound/oss/emu10k1/midi.c b/sound/oss/emu10k1/midi.c
new file mode 100644
index 000000000000..33dea3d56c1e
--- /dev/null
+++ b/sound/oss/emu10k1/midi.c
@@ -0,0 +1,613 @@
1/*
2 **********************************************************************
3 * midi.c - /dev/midi interface for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include <linux/module.h>
33#include <linux/poll.h>
34#include <linux/slab.h>
35#include <linux/sched.h>
36#include <linux/smp_lock.h>
37#include <asm/uaccess.h>
38
39#include "hwaccess.h"
40#include "cardmo.h"
41#include "cardmi.h"
42#include "midi.h"
43
44#ifdef EMU10K1_SEQUENCER
45#include "../sound_config.h"
46#endif
47
48static DEFINE_SPINLOCK(midi_spinlock __attribute((unused)));
49
50static void init_midi_hdr(struct midi_hdr *midihdr)
51{
52 midihdr->bufferlength = MIDIIN_BUFLEN;
53 midihdr->bytesrecorded = 0;
54 midihdr->flags = 0;
55}
56
57static int midiin_add_buffer(struct emu10k1_mididevice *midi_dev, struct midi_hdr **midihdrptr)
58{
59 struct midi_hdr *midihdr;
60
61 if ((midihdr = (struct midi_hdr *) kmalloc(sizeof(struct midi_hdr), GFP_KERNEL)) == NULL) {
62 ERROR();
63 return -EINVAL;
64 }
65
66 init_midi_hdr(midihdr);
67
68 if ((midihdr->data = (u8 *) kmalloc(MIDIIN_BUFLEN, GFP_KERNEL)) == NULL) {
69 ERROR();
70 kfree(midihdr);
71 return -1;
72 }
73
74 if (emu10k1_mpuin_add_buffer(midi_dev->card->mpuin, midihdr) < 0) {
75 ERROR();
76 kfree(midihdr->data);
77 kfree(midihdr);
78 return -1;
79 }
80
81 *midihdrptr = midihdr;
82 list_add_tail(&midihdr->list, &midi_dev->mid_hdrs);
83
84 return 0;
85}
86
87static int emu10k1_midi_open(struct inode *inode, struct file *file)
88{
89 int minor = iminor(inode);
90 struct emu10k1_card *card = NULL;
91 struct emu10k1_mididevice *midi_dev;
92 struct list_head *entry;
93
94 DPF(2, "emu10k1_midi_open()\n");
95
96 /* Check for correct device to open */
97 list_for_each(entry, &emu10k1_devs) {
98 card = list_entry(entry, struct emu10k1_card, list);
99
100 if (card->midi_dev == minor)
101 goto match;
102 }
103
104 return -ENODEV;
105
106match:
107#ifdef EMU10K1_SEQUENCER
108 if (card->seq_mididev) /* card is opened by sequencer */
109 return -EBUSY;
110#endif
111
112 /* Wait for device to become free */
113 down(&card->open_sem);
114 while (card->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
115 if (file->f_flags & O_NONBLOCK) {
116 up(&card->open_sem);
117 return -EBUSY;
118 }
119
120 up(&card->open_sem);
121 interruptible_sleep_on(&card->open_wait);
122
123 if (signal_pending(current)) {
124 return -ERESTARTSYS;
125 }
126
127 down(&card->open_sem);
128 }
129
130 if ((midi_dev = (struct emu10k1_mididevice *) kmalloc(sizeof(*midi_dev), GFP_KERNEL)) == NULL)
131 return -EINVAL;
132
133 midi_dev->card = card;
134 midi_dev->mistate = MIDIIN_STATE_STOPPED;
135 init_waitqueue_head(&midi_dev->oWait);
136 init_waitqueue_head(&midi_dev->iWait);
137 midi_dev->ird = 0;
138 midi_dev->iwr = 0;
139 midi_dev->icnt = 0;
140 INIT_LIST_HEAD(&midi_dev->mid_hdrs);
141
142 if (file->f_mode & FMODE_READ) {
143 struct midi_openinfo dsCardMidiOpenInfo;
144 struct midi_hdr *midihdr1;
145 struct midi_hdr *midihdr2;
146
147 dsCardMidiOpenInfo.refdata = (unsigned long) midi_dev;
148
149 if (emu10k1_mpuin_open(card, &dsCardMidiOpenInfo) < 0) {
150 ERROR();
151 kfree(midi_dev);
152 return -ENODEV;
153 }
154
155 /* Add two buffers to receive sysex buffer */
156 if (midiin_add_buffer(midi_dev, &midihdr1) < 0) {
157 kfree(midi_dev);
158 return -ENODEV;
159 }
160
161 if (midiin_add_buffer(midi_dev, &midihdr2) < 0) {
162 list_del(&midihdr1->list);
163 kfree(midihdr1->data);
164 kfree(midihdr1);
165 kfree(midi_dev);
166 return -ENODEV;
167 }
168 }
169
170 if (file->f_mode & FMODE_WRITE) {
171 struct midi_openinfo dsCardMidiOpenInfo;
172
173 dsCardMidiOpenInfo.refdata = (unsigned long) midi_dev;
174
175 if (emu10k1_mpuout_open(card, &dsCardMidiOpenInfo) < 0) {
176 ERROR();
177 kfree(midi_dev);
178 return -ENODEV;
179 }
180 }
181
182 file->private_data = (void *) midi_dev;
183
184 card->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
185
186 up(&card->open_sem);
187
188 return nonseekable_open(inode, file);
189}
190
191static int emu10k1_midi_release(struct inode *inode, struct file *file)
192{
193 struct emu10k1_mididevice *midi_dev = (struct emu10k1_mididevice *) file->private_data;
194 struct emu10k1_card *card;
195
196 lock_kernel();
197
198 card = midi_dev->card;
199 DPF(2, "emu10k1_midi_release()\n");
200
201 if (file->f_mode & FMODE_WRITE) {
202 if (!(file->f_flags & O_NONBLOCK)) {
203
204 while (!signal_pending(current) && (card->mpuout->firstmidiq != NULL)) {
205 DPF(4, "Cannot close - buffers not empty\n");
206
207 interruptible_sleep_on(&midi_dev->oWait);
208
209 }
210 }
211
212 emu10k1_mpuout_close(card);
213 }
214
215 if (file->f_mode & FMODE_READ) {
216 struct midi_hdr *midihdr;
217
218 if (midi_dev->mistate == MIDIIN_STATE_STARTED) {
219 emu10k1_mpuin_stop(card);
220 midi_dev->mistate = MIDIIN_STATE_STOPPED;
221 }
222
223 emu10k1_mpuin_reset(card);
224 emu10k1_mpuin_close(card);
225
226 while (!list_empty(&midi_dev->mid_hdrs)) {
227 midihdr = list_entry(midi_dev->mid_hdrs.next, struct midi_hdr, list);
228
229 list_del(midi_dev->mid_hdrs.next);
230 kfree(midihdr->data);
231 kfree(midihdr);
232 }
233 }
234
235 kfree(midi_dev);
236
237 down(&card->open_sem);
238 card->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE));
239 up(&card->open_sem);
240 wake_up_interruptible(&card->open_wait);
241
242 unlock_kernel();
243
244 return 0;
245}
246
247static ssize_t emu10k1_midi_read(struct file *file, char __user *buffer, size_t count, loff_t * pos)
248{
249 struct emu10k1_mididevice *midi_dev = (struct emu10k1_mididevice *) file->private_data;
250 ssize_t ret = 0;
251 u16 cnt;
252 unsigned long flags;
253
254 DPD(4, "emu10k1_midi_read(), count %#x\n", (u32) count);
255
256 if (!access_ok(VERIFY_WRITE, buffer, count))
257 return -EFAULT;
258
259 if (midi_dev->mistate == MIDIIN_STATE_STOPPED) {
260 if (emu10k1_mpuin_start(midi_dev->card) < 0) {
261 ERROR();
262 return -EINVAL;
263 }
264
265 midi_dev->mistate = MIDIIN_STATE_STARTED;
266 }
267
268 while (count > 0) {
269 cnt = MIDIIN_BUFLEN - midi_dev->ird;
270
271 spin_lock_irqsave(&midi_spinlock, flags);
272
273 if (midi_dev->icnt < cnt)
274 cnt = midi_dev->icnt;
275
276 spin_unlock_irqrestore(&midi_spinlock, flags);
277
278 if (cnt > count)
279 cnt = count;
280
281 if (cnt <= 0) {
282 if (file->f_flags & O_NONBLOCK)
283 return ret ? ret : -EAGAIN;
284 DPF(2, " Go to sleep...\n");
285
286 interruptible_sleep_on(&midi_dev->iWait);
287
288 if (signal_pending(current))
289 return ret ? ret : -ERESTARTSYS;
290
291 continue;
292 }
293
294 if (copy_to_user(buffer, midi_dev->iBuf + midi_dev->ird, cnt)) {
295 ERROR();
296 return ret ? ret : -EFAULT;
297 }
298
299 midi_dev->ird += cnt;
300 midi_dev->ird %= MIDIIN_BUFLEN;
301
302 spin_lock_irqsave(&midi_spinlock, flags);
303
304 midi_dev->icnt -= cnt;
305
306 spin_unlock_irqrestore(&midi_spinlock, flags);
307
308 count -= cnt;
309 buffer += cnt;
310 ret += cnt;
311
312 if (midi_dev->icnt == 0)
313 break;
314 }
315
316 return ret;
317}
318
319static ssize_t emu10k1_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t * pos)
320{
321 struct emu10k1_mididevice *midi_dev = (struct emu10k1_mididevice *) file->private_data;
322 struct midi_hdr *midihdr;
323 unsigned long flags;
324
325 DPD(4, "emu10k1_midi_write(), count=%#x\n", (u32) count);
326
327 if (!access_ok(VERIFY_READ, buffer, count))
328 return -EFAULT;
329
330 if ((midihdr = (struct midi_hdr *) kmalloc(sizeof(struct midi_hdr), GFP_KERNEL)) == NULL)
331 return -EINVAL;
332
333 midihdr->bufferlength = count;
334 midihdr->bytesrecorded = 0;
335 midihdr->flags = 0;
336
337 if ((midihdr->data = (u8 *) kmalloc(count, GFP_KERNEL)) == NULL) {
338 ERROR();
339 kfree(midihdr);
340 return -EINVAL;
341 }
342
343 if (copy_from_user(midihdr->data, buffer, count)) {
344 kfree(midihdr->data);
345 kfree(midihdr);
346 return -EFAULT;
347 }
348
349 spin_lock_irqsave(&midi_spinlock, flags);
350
351 if (emu10k1_mpuout_add_buffer(midi_dev->card, midihdr) < 0) {
352 ERROR();
353 kfree(midihdr->data);
354 kfree(midihdr);
355 spin_unlock_irqrestore(&midi_spinlock, flags);
356 return -EINVAL;
357 }
358
359 spin_unlock_irqrestore(&midi_spinlock, flags);
360
361 return count;
362}
363
364static unsigned int emu10k1_midi_poll(struct file *file, struct poll_table_struct *wait)
365{
366 struct emu10k1_mididevice *midi_dev = (struct emu10k1_mididevice *) file->private_data;
367 unsigned long flags;
368 unsigned int mask = 0;
369
370 DPF(4, "emu10k1_midi_poll() called\n");
371
372 if (file->f_mode & FMODE_WRITE)
373 poll_wait(file, &midi_dev->oWait, wait);
374
375 if (file->f_mode & FMODE_READ)
376 poll_wait(file, &midi_dev->iWait, wait);
377
378 spin_lock_irqsave(&midi_spinlock, flags);
379
380 if (file->f_mode & FMODE_WRITE)
381 mask |= POLLOUT | POLLWRNORM;
382
383 if (file->f_mode & FMODE_READ) {
384 if (midi_dev->mistate == MIDIIN_STATE_STARTED)
385 if (midi_dev->icnt > 0)
386 mask |= POLLIN | POLLRDNORM;
387 }
388
389 spin_unlock_irqrestore(&midi_spinlock, flags);
390
391 return mask;
392}
393
394int emu10k1_midi_callback(unsigned long msg, unsigned long refdata, unsigned long *pmsg)
395{
396 struct emu10k1_mididevice *midi_dev = (struct emu10k1_mididevice *) refdata;
397 struct midi_hdr *midihdr = NULL;
398 unsigned long flags;
399 int i;
400
401 DPF(4, "emu10k1_midi_callback()\n");
402
403 spin_lock_irqsave(&midi_spinlock, flags);
404
405 switch (msg) {
406 case ICARDMIDI_OUTLONGDATA:
407 midihdr = (struct midi_hdr *) pmsg[2];
408
409 kfree(midihdr->data);
410 kfree(midihdr);
411 wake_up_interruptible(&midi_dev->oWait);
412
413 break;
414
415 case ICARDMIDI_INLONGDATA:
416 midihdr = (struct midi_hdr *) pmsg[2];
417
418 for (i = 0; i < midihdr->bytesrecorded; i++) {
419 midi_dev->iBuf[midi_dev->iwr++] = midihdr->data[i];
420 midi_dev->iwr %= MIDIIN_BUFLEN;
421 }
422
423 midi_dev->icnt += midihdr->bytesrecorded;
424
425 if (midi_dev->mistate == MIDIIN_STATE_STARTED) {
426 init_midi_hdr(midihdr);
427 emu10k1_mpuin_add_buffer(midi_dev->card->mpuin, midihdr);
428 wake_up_interruptible(&midi_dev->iWait);
429 }
430 break;
431
432 case ICARDMIDI_INDATA:
433 {
434 u8 *pBuf = (u8 *) & pmsg[1];
435 u16 bytesvalid = pmsg[2];
436
437 for (i = 0; i < bytesvalid; i++) {
438 midi_dev->iBuf[midi_dev->iwr++] = pBuf[i];
439 midi_dev->iwr %= MIDIIN_BUFLEN;
440 }
441
442 midi_dev->icnt += bytesvalid;
443 }
444
445 wake_up_interruptible(&midi_dev->iWait);
446 break;
447
448 default: /* Unknown message */
449 spin_unlock_irqrestore(&midi_spinlock, flags);
450 return -1;
451 }
452
453 spin_unlock_irqrestore(&midi_spinlock, flags);
454
455 return 0;
456}
457
458/* MIDI file operations */
459struct file_operations emu10k1_midi_fops = {
460 .owner = THIS_MODULE,
461 .read = emu10k1_midi_read,
462 .write = emu10k1_midi_write,
463 .poll = emu10k1_midi_poll,
464 .open = emu10k1_midi_open,
465 .release = emu10k1_midi_release,
466};
467
468
469#ifdef EMU10K1_SEQUENCER
470
471/* functions used for sequencer access */
472
473int emu10k1_seq_midi_open(int dev, int mode,
474 void (*input) (int dev, unsigned char data),
475 void (*output) (int dev))
476{
477 struct emu10k1_card *card;
478 struct midi_openinfo dsCardMidiOpenInfo;
479 struct emu10k1_mididevice *midi_dev;
480
481 if (midi_devs[dev] == NULL || midi_devs[dev]->devc == NULL)
482 return -EINVAL;
483
484 card = midi_devs[dev]->devc;
485
486 if (card->open_mode) /* card is opened native */
487 return -EBUSY;
488
489 DPF(2, "emu10k1_seq_midi_open()\n");
490
491 if ((midi_dev = (struct emu10k1_mididevice *) kmalloc(sizeof(*midi_dev), GFP_KERNEL)) == NULL)
492 return -EINVAL;
493
494 midi_dev->card = card;
495 midi_dev->mistate = MIDIIN_STATE_STOPPED;
496 init_waitqueue_head(&midi_dev->oWait);
497 init_waitqueue_head(&midi_dev->iWait);
498 midi_dev->ird = 0;
499 midi_dev->iwr = 0;
500 midi_dev->icnt = 0;
501 INIT_LIST_HEAD(&midi_dev->mid_hdrs);
502
503 dsCardMidiOpenInfo.refdata = (unsigned long) midi_dev;
504
505 if (emu10k1_mpuout_open(card, &dsCardMidiOpenInfo) < 0) {
506 ERROR();
507 return -ENODEV;
508 }
509
510 card->seq_mididev = midi_dev;
511
512 return 0;
513}
514
515void emu10k1_seq_midi_close(int dev)
516{
517 struct emu10k1_card *card;
518
519 DPF(2, "emu10k1_seq_midi_close()\n");
520 if (midi_devs[dev] == NULL || midi_devs[dev]->devc == NULL)
521 return;
522
523 card = midi_devs[dev]->devc;
524 emu10k1_mpuout_close(card);
525
526 if (card->seq_mididev) {
527 kfree(card->seq_mididev);
528 card->seq_mididev = NULL;
529 }
530}
531
532int emu10k1_seq_midi_out(int dev, unsigned char midi_byte)
533{
534 struct emu10k1_card *card;
535 struct midi_hdr *midihdr;
536 unsigned long flags;
537
538 if (midi_devs[dev] == NULL || midi_devs[dev]->devc == NULL)
539 return -EINVAL;
540
541 card = midi_devs[dev]->devc;
542
543 if ((midihdr = (struct midi_hdr *) kmalloc(sizeof(struct midi_hdr), GFP_KERNEL)) == NULL)
544 return -EINVAL;
545
546 midihdr->bufferlength = 1;
547 midihdr->bytesrecorded = 0;
548 midihdr->flags = 0;
549
550 if ((midihdr->data = (u8 *) kmalloc(1, GFP_KERNEL)) == NULL) {
551 ERROR();
552 kfree(midihdr);
553 return -EINVAL;
554 }
555
556 *(midihdr->data) = midi_byte;
557
558 spin_lock_irqsave(&midi_spinlock, flags);
559
560 if (emu10k1_mpuout_add_buffer(card, midihdr) < 0) {
561 ERROR();
562 kfree(midihdr->data);
563 kfree(midihdr);
564 spin_unlock_irqrestore(&midi_spinlock, flags);
565 return -EINVAL;
566 }
567
568 spin_unlock_irqrestore(&midi_spinlock, flags);
569
570 return 1;
571}
572
573int emu10k1_seq_midi_start_read(int dev)
574{
575 return 0;
576}
577
578int emu10k1_seq_midi_end_read(int dev)
579{
580 return 0;
581}
582
583void emu10k1_seq_midi_kick(int dev)
584{
585}
586
587int emu10k1_seq_midi_buffer_status(int dev)
588{
589 int count;
590 struct midi_queue *queue;
591 struct emu10k1_card *card;
592
593 if (midi_devs[dev] == NULL || midi_devs[dev]->devc == NULL)
594 return -EINVAL;
595
596 count = 0;
597
598 card = midi_devs[dev]->devc;
599 queue = card->mpuout->firstmidiq;
600
601 while (queue != NULL) {
602 count++;
603 if (queue == card->mpuout->lastmidiq)
604 break;
605
606 queue = queue->next;
607 }
608
609 return count;
610}
611
612#endif
613
diff --git a/sound/oss/emu10k1/midi.h b/sound/oss/emu10k1/midi.h
new file mode 100644
index 000000000000..2459ec929e8d
--- /dev/null
+++ b/sound/oss/emu10k1/midi.h
@@ -0,0 +1,78 @@
1/*
2 **********************************************************************
3 * midi.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _MIDI_H
33#define _MIDI_H
34
35#define FMODE_MIDI_SHIFT 3
36#define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
37#define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
38
39#define MIDIIN_STATE_STARTED 0x00000001
40#define MIDIIN_STATE_STOPPED 0x00000002
41
42#define MIDIIN_BUFLEN 1024
43
44struct emu10k1_mididevice
45{
46 struct emu10k1_card *card;
47 u32 mistate;
48 wait_queue_head_t oWait;
49 wait_queue_head_t iWait;
50 s8 iBuf[MIDIIN_BUFLEN];
51 u16 ird, iwr, icnt;
52 struct list_head mid_hdrs;
53};
54
55/* uncomment next line to use midi port on Audigy drive */
56//#define USE_AUDIGY_DRIVE_MIDI
57
58#ifdef USE_AUDIGY_DRIVE_MIDI
59#define A_MUDATA A_MUDATA2
60#define A_MUCMD A_MUCMD2
61#define A_MUSTAT A_MUCMD2
62#define A_IPR_MIDITRANSBUFEMPTY A_IPR_MIDITRANSBUFEMPTY2
63#define A_IPR_MIDIRECVBUFEMPTY A_IPR_MIDIRECVBUFEMPTY2
64#define A_INTE_MIDITXENABLE A_INTE_MIDITXENABLE2
65#define A_INTE_MIDIRXENABLE A_INTE_MIDIRXENABLE2
66#else
67#define A_MUDATA A_MUDATA1
68#define A_MUCMD A_MUCMD1
69#define A_MUSTAT A_MUCMD1
70#define A_IPR_MIDITRANSBUFEMPTY A_IPR_MIDITRANSBUFEMPTY1
71#define A_IPR_MIDIRECVBUFEMPTY A_IPR_MIDIRECVBUFEMPTY1
72#define A_INTE_MIDITXENABLE A_INTE_MIDITXENABLE1
73#define A_INTE_MIDIRXENABLE A_INTE_MIDIRXENABLE1
74#endif
75
76
77#endif /* _MIDI_H */
78
diff --git a/sound/oss/emu10k1/mixer.c b/sound/oss/emu10k1/mixer.c
new file mode 100644
index 000000000000..cbcaaa34189a
--- /dev/null
+++ b/sound/oss/emu10k1/mixer.c
@@ -0,0 +1,690 @@
1/*
2 **********************************************************************
3 * mixer.c - /dev/mixer interface for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox cleaned up stuff
12 *
13 **********************************************************************
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
28 * USA.
29 *
30 **********************************************************************
31 */
32
33#include <linux/module.h>
34#include <asm/uaccess.h>
35#include <linux/fs.h>
36
37#include "hwaccess.h"
38#include "8010.h"
39#include "recmgr.h"
40
41
42static const u32 bass_table[41][5] = {
43 { 0x3e4f844f, 0x84ed4cc3, 0x3cc69927, 0x7b03553a, 0xc4da8486 },
44 { 0x3e69a17a, 0x84c280fb, 0x3cd77cd4, 0x7b2f2a6f, 0xc4b08d1d },
45 { 0x3e82ff42, 0x849991d5, 0x3ce7466b, 0x7b5917c6, 0xc48863ee },
46 { 0x3e9bab3c, 0x847267f0, 0x3cf5ffe8, 0x7b813560, 0xc461f22c },
47 { 0x3eb3b275, 0x844ced29, 0x3d03b295, 0x7ba79a1c, 0xc43d223b },
48 { 0x3ecb2174, 0x84290c8b, 0x3d106714, 0x7bcc5ba3, 0xc419dfa5 },
49 { 0x3ee2044b, 0x8406b244, 0x3d1c2561, 0x7bef8e77, 0xc3f8170f },
50 { 0x3ef86698, 0x83e5cb96, 0x3d26f4d8, 0x7c114600, 0xc3d7b625 },
51 { 0x3f0e5390, 0x83c646c9, 0x3d30dc39, 0x7c319498, 0xc3b8ab97 },
52 { 0x3f23d60b, 0x83a81321, 0x3d39e1af, 0x7c508b9c, 0xc39ae704 },
53 { 0x3f38f884, 0x838b20d2, 0x3d420ad2, 0x7c6e3b75, 0xc37e58f1 },
54 { 0x3f4dc52c, 0x836f60ef, 0x3d495cab, 0x7c8ab3a6, 0xc362f2be },
55 { 0x3f6245e8, 0x8354c565, 0x3d4fdbb8, 0x7ca602d6, 0xc348a69b },
56 { 0x3f76845f, 0x833b40ec, 0x3d558bf0, 0x7cc036df, 0xc32f677c },
57 { 0x3f8a8a03, 0x8322c6fb, 0x3d5a70c4, 0x7cd95cd7, 0xc317290b },
58 { 0x3f9e6014, 0x830b4bc3, 0x3d5e8d25, 0x7cf1811a, 0xc2ffdfa5 },
59 { 0x3fb20fae, 0x82f4c420, 0x3d61e37f, 0x7d08af56, 0xc2e9804a },
60 { 0x3fc5a1cc, 0x82df2592, 0x3d6475c3, 0x7d1ef294, 0xc2d40096 },
61 { 0x3fd91f55, 0x82ca6632, 0x3d664564, 0x7d345541, 0xc2bf56b9 },
62 { 0x3fec9120, 0x82b67cac, 0x3d675356, 0x7d48e138, 0xc2ab796e },
63 { 0x40000000, 0x82a36037, 0x3d67a012, 0x7d5c9fc9, 0xc2985fee },
64 { 0x401374c7, 0x8291088a, 0x3d672b93, 0x7d6f99c3, 0xc28601f2 },
65 { 0x4026f857, 0x827f6dd7, 0x3d65f559, 0x7d81d77c, 0xc27457a3 },
66 { 0x403a939f, 0x826e88c5, 0x3d63fc63, 0x7d9360d4, 0xc2635996 },
67 { 0x404e4faf, 0x825e5266, 0x3d613f32, 0x7da43d42, 0xc25300c6 },
68 { 0x406235ba, 0x824ec434, 0x3d5dbbc3, 0x7db473d7, 0xc243468e },
69 { 0x40764f1f, 0x823fd80c, 0x3d596f8f, 0x7dc40b44, 0xc23424a2 },
70 { 0x408aa576, 0x82318824, 0x3d545787, 0x7dd309e2, 0xc2259509 },
71 { 0x409f4296, 0x8223cf0b, 0x3d4e7012, 0x7de175b5, 0xc2179218 },
72 { 0x40b430a0, 0x8216a7a1, 0x3d47b505, 0x7def5475, 0xc20a1670 },
73 { 0x40c97a0a, 0x820a0d12, 0x3d4021a1, 0x7dfcab8d, 0xc1fd1cf5 },
74 { 0x40df29a6, 0x81fdfad6, 0x3d37b08d, 0x7e098028, 0xc1f0a0ca },
75 { 0x40f54ab1, 0x81f26ca9, 0x3d2e5bd1, 0x7e15d72b, 0xc1e49d52 },
76 { 0x410be8da, 0x81e75e89, 0x3d241cce, 0x7e21b544, 0xc1d90e24 },
77 { 0x41231051, 0x81dcccb3, 0x3d18ec37, 0x7e2d1ee6, 0xc1cdef10 },
78 { 0x413acdd0, 0x81d2b39e, 0x3d0cc20a, 0x7e38184e, 0xc1c33c13 },
79 { 0x41532ea7, 0x81c90ffb, 0x3cff9585, 0x7e42a58b, 0xc1b8f15a },
80 { 0x416c40cd, 0x81bfdeb2, 0x3cf15d21, 0x7e4cca7c, 0xc1af0b3f },
81 { 0x418612ea, 0x81b71cdc, 0x3ce20e85, 0x7e568ad3, 0xc1a58640 },
82 { 0x41a0b465, 0x81aec7c5, 0x3cd19e7c, 0x7e5fea1e, 0xc19c5f03 },
83 { 0x41bc3573, 0x81a6dcea, 0x3cc000e9, 0x7e68ebc2, 0xc1939250 }
84};
85
86static const u32 treble_table[41][5] = {
87 { 0x0125cba9, 0xfed5debd, 0x00599b6c, 0x0d2506da, 0xfa85b354 },
88 { 0x0142f67e, 0xfeb03163, 0x0066cd0f, 0x0d14c69d, 0xfa914473 },
89 { 0x016328bd, 0xfe860158, 0x0075b7f2, 0x0d03eb27, 0xfa9d32d2 },
90 { 0x0186b438, 0xfe56c982, 0x00869234, 0x0cf27048, 0xfaa97fca },
91 { 0x01adf358, 0xfe21f5fe, 0x00999842, 0x0ce051c2, 0xfab62ca5 },
92 { 0x01d949fa, 0xfde6e287, 0x00af0d8d, 0x0ccd8b4a, 0xfac33aa7 },
93 { 0x02092669, 0xfda4d8bf, 0x00c73d4c, 0x0cba1884, 0xfad0ab07 },
94 { 0x023e0268, 0xfd5b0e4a, 0x00e27b54, 0x0ca5f509, 0xfade7ef2 },
95 { 0x0278645c, 0xfd08a2b0, 0x01012509, 0x0c911c63, 0xfaecb788 },
96 { 0x02b8e091, 0xfcac9d1a, 0x0123a262, 0x0c7b8a14, 0xfafb55df },
97 { 0x03001a9a, 0xfc45e9ce, 0x014a6709, 0x0c65398f, 0xfb0a5aff },
98 { 0x034ec6d7, 0xfbd3576b, 0x0175f397, 0x0c4e2643, 0xfb19c7e4 },
99 { 0x03a5ac15, 0xfb5393ee, 0x01a6d6ed, 0x0c364b94, 0xfb299d7c },
100 { 0x0405a562, 0xfac52968, 0x01ddafae, 0x0c1da4e2, 0xfb39dca5 },
101 { 0x046fa3fe, 0xfa267a66, 0x021b2ddd, 0x0c042d8d, 0xfb4a8631 },
102 { 0x04e4b17f, 0xf975be0f, 0x0260149f, 0x0be9e0f2, 0xfb5b9ae0 },
103 { 0x0565f220, 0xf8b0fbe5, 0x02ad3c29, 0x0bceba73, 0xfb6d1b60 },
104 { 0x05f4a745, 0xf7d60722, 0x030393d4, 0x0bb2b578, 0xfb7f084d },
105 { 0x06923236, 0xf6e279bd, 0x03642465, 0x0b95cd75, 0xfb916233 },
106 { 0x07401713, 0xf5d3aef9, 0x03d01283, 0x0b77fded, 0xfba42984 },
107 { 0x08000000, 0xf4a6bd88, 0x0448a161, 0x0b594278, 0xfbb75e9f },
108 { 0x08d3c097, 0xf3587131, 0x04cf35a4, 0x0b3996c9, 0xfbcb01cb },
109 { 0x09bd59a2, 0xf1e543f9, 0x05655880, 0x0b18f6b2, 0xfbdf1333 },
110 { 0x0abefd0f, 0xf04956ca, 0x060cbb12, 0x0af75e2c, 0xfbf392e8 },
111 { 0x0bdb123e, 0xee806984, 0x06c739fe, 0x0ad4c962, 0xfc0880dd },
112 { 0x0d143a94, 0xec85d287, 0x0796e150, 0x0ab134b0, 0xfc1ddce5 },
113 { 0x0e6d5664, 0xea547598, 0x087df0a0, 0x0a8c9cb6, 0xfc33a6ad },
114 { 0x0fe98a2a, 0xe7e6ba35, 0x097edf83, 0x0a66fe5b, 0xfc49ddc2 },
115 { 0x118c4421, 0xe536813a, 0x0a9c6248, 0x0a4056d7, 0xfc608185 },
116 { 0x1359422e, 0xe23d19eb, 0x0bd96efb, 0x0a18a3bf, 0xfc77912c },
117 { 0x1554982b, 0xdef33645, 0x0d3942bd, 0x09efe312, 0xfc8f0bc1 },
118 { 0x1782b68a, 0xdb50deb1, 0x0ebf676d, 0x09c6133f, 0xfca6f019 },
119 { 0x19e8715d, 0xd74d64fd, 0x106fb999, 0x099b3337, 0xfcbf3cd6 },
120 { 0x1c8b07b8, 0xd2df56ab, 0x124e6ec8, 0x096f4274, 0xfcd7f060 },
121 { 0x1f702b6d, 0xcdfc6e92, 0x14601c10, 0x0942410b, 0xfcf108e5 },
122 { 0x229e0933, 0xc89985cd, 0x16a9bcfa, 0x09142fb5, 0xfd0a8451 },
123 { 0x261b5118, 0xc2aa8409, 0x1930bab6, 0x08e50fdc, 0xfd24604d },
124 { 0x29ef3f5d, 0xbc224f28, 0x1bfaf396, 0x08b4e3aa, 0xfd3e9a3b },
125 { 0x2e21a59b, 0xb4f2ba46, 0x1f0ec2d6, 0x0883ae15, 0xfd592f33 },
126 { 0x32baf44b, 0xad0c7429, 0x227308a3, 0x085172eb, 0xfd741bfd },
127 { 0x37c4448b, 0xa45ef51d, 0x262f3267, 0x081e36dc, 0xfd8f5d14 }
128};
129
130
131static void set_bass(struct emu10k1_card *card, int l, int r)
132{
133 int i;
134
135 l = (l * 40 + 50) / 100;
136 r = (r * 40 + 50) / 100;
137
138 for (i = 0; i < 5; i++)
139 sblive_writeptr(card, (card->is_audigy ? A_GPR_BASE : GPR_BASE) + card->mgr.ctrl_gpr[SOUND_MIXER_BASS][0] + i, 0, bass_table[l][i]);
140}
141
142static void set_treble(struct emu10k1_card *card, int l, int r)
143{
144 int i;
145
146 l = (l * 40 + 50) / 100;
147 r = (r * 40 + 50) / 100;
148
149 for (i = 0; i < 5; i++)
150 sblive_writeptr(card, (card->is_audigy ? A_GPR_BASE : GPR_BASE) + card->mgr.ctrl_gpr[SOUND_MIXER_TREBLE][0] + i , 0, treble_table[l][i]);
151}
152
153const char volume_params[SOUND_MIXER_NRDEVICES]= {
154/* Used by the ac97 driver */
155 [SOUND_MIXER_VOLUME] = VOL_6BIT,
156 [SOUND_MIXER_BASS] = VOL_4BIT,
157 [SOUND_MIXER_TREBLE] = VOL_4BIT,
158 [SOUND_MIXER_PCM] = VOL_5BIT,
159 [SOUND_MIXER_SPEAKER] = VOL_4BIT,
160 [SOUND_MIXER_LINE] = VOL_5BIT,
161 [SOUND_MIXER_MIC] = VOL_5BIT,
162 [SOUND_MIXER_CD] = VOL_5BIT,
163 [SOUND_MIXER_ALTPCM] = VOL_6BIT,
164 [SOUND_MIXER_IGAIN] = VOL_4BIT,
165 [SOUND_MIXER_LINE1] = VOL_5BIT,
166 [SOUND_MIXER_PHONEIN] = VOL_5BIT,
167 [SOUND_MIXER_PHONEOUT] = VOL_6BIT,
168 [SOUND_MIXER_VIDEO] = VOL_5BIT,
169/* Not used by the ac97 driver */
170 [SOUND_MIXER_SYNTH] = VOL_5BIT,
171 [SOUND_MIXER_IMIX] = VOL_5BIT,
172 [SOUND_MIXER_RECLEV] = VOL_5BIT,
173 [SOUND_MIXER_OGAIN] = VOL_5BIT,
174 [SOUND_MIXER_LINE2] = VOL_5BIT,
175 [SOUND_MIXER_LINE3] = VOL_5BIT,
176 [SOUND_MIXER_DIGITAL1] = VOL_5BIT,
177 [SOUND_MIXER_DIGITAL2] = VOL_5BIT,
178 [SOUND_MIXER_DIGITAL3] = VOL_5BIT,
179 [SOUND_MIXER_RADIO] = VOL_5BIT,
180 [SOUND_MIXER_MONITOR] = VOL_5BIT
181};
182
183/* Mixer file operations */
184static int emu10k1_private_mixer(struct emu10k1_card *card, unsigned int cmd, unsigned long arg)
185{
186 struct mixer_private_ioctl *ctl;
187 struct dsp_patch *patch;
188 u32 size, page;
189 int addr, size_reg, i, ret;
190 unsigned int id, ch;
191 void __user *argp = (void __user *)arg;
192
193 switch (cmd) {
194
195 case SOUND_MIXER_PRIVATE3:
196
197 ctl = (struct mixer_private_ioctl *) kmalloc(sizeof(struct mixer_private_ioctl), GFP_KERNEL);
198 if (ctl == NULL)
199 return -ENOMEM;
200
201 if (copy_from_user(ctl, argp, sizeof(struct mixer_private_ioctl))) {
202 kfree(ctl);
203 return -EFAULT;
204 }
205
206 ret = 0;
207 switch (ctl->cmd) {
208#ifdef DBGEMU
209 case CMD_WRITEFN0:
210 emu10k1_writefn0_2(card, ctl->val[0], ctl->val[1], ctl->val[2]);
211 break;
212#endif
213 case CMD_WRITEPTR:
214#ifdef DBGEMU
215 if (ctl->val[1] >= 0x40 || ctl->val[0] >= 0x1000) {
216#else
217 if (ctl->val[1] >= 0x40 || ctl->val[0] >= 0x1000 || ((ctl->val[0] < 0x100 ) &&
218 //Any register allowed raw access goes here:
219 (ctl->val[0] != A_SPDIF_SAMPLERATE) && (ctl->val[0] != A_DBG)
220 )
221 ) {
222#endif
223 ret = -EINVAL;
224 break;
225 }
226 sblive_writeptr(card, ctl->val[0], ctl->val[1], ctl->val[2]);
227 break;
228
229 case CMD_READFN0:
230 ctl->val[2] = emu10k1_readfn0(card, ctl->val[0]);
231
232 if (copy_to_user(argp, ctl, sizeof(struct mixer_private_ioctl)))
233 ret = -EFAULT;
234
235 break;
236
237 case CMD_READPTR:
238 if (ctl->val[1] >= 0x40 || (ctl->val[0] & 0x7ff) > 0xff) {
239 ret = -EINVAL;
240 break;
241 }
242
243 if ((ctl->val[0] & 0x7ff) > 0x3f)
244 ctl->val[1] = 0x00;
245
246 ctl->val[2] = sblive_readptr(card, ctl->val[0], ctl->val[1]);
247
248 if (copy_to_user(argp, ctl, sizeof(struct mixer_private_ioctl)))
249 ret = -EFAULT;
250
251 break;
252
253 case CMD_SETRECSRC:
254 switch (ctl->val[0]) {
255 case WAVERECORD_AC97:
256 if (card->is_aps) {
257 ret = -EINVAL;
258 break;
259 }
260
261 card->wavein.recsrc = WAVERECORD_AC97;
262 break;
263
264 case WAVERECORD_MIC:
265 card->wavein.recsrc = WAVERECORD_MIC;
266 break;
267
268 case WAVERECORD_FX:
269 card->wavein.recsrc = WAVERECORD_FX;
270 card->wavein.fxwc = ctl->val[1] & 0xffff;
271
272 if (!card->wavein.fxwc)
273 ret = -EINVAL;
274
275 break;
276
277 default:
278 ret = -EINVAL;
279 break;
280 }
281 break;
282
283 case CMD_GETRECSRC:
284 ctl->val[0] = card->wavein.recsrc;
285 ctl->val[1] = card->wavein.fxwc;
286 if (copy_to_user(argp, ctl, sizeof(struct mixer_private_ioctl)))
287 ret = -EFAULT;
288
289 break;
290
291 case CMD_GETVOICEPARAM:
292 ctl->val[0] = card->waveout.send_routing[0];
293 ctl->val[1] = card->waveout.send_dcba[0];
294
295 ctl->val[2] = card->waveout.send_routing[1];
296 ctl->val[3] = card->waveout.send_dcba[1];
297
298 ctl->val[4] = card->waveout.send_routing[2];
299 ctl->val[5] = card->waveout.send_dcba[2];
300
301 if (copy_to_user(argp, ctl, sizeof(struct mixer_private_ioctl)))
302 ret = -EFAULT;
303
304 break;
305
306 case CMD_SETVOICEPARAM:
307 card->waveout.send_routing[0] = ctl->val[0];
308 card->waveout.send_dcba[0] = ctl->val[1];
309
310 card->waveout.send_routing[1] = ctl->val[2];
311 card->waveout.send_dcba[1] = ctl->val[3];
312
313 card->waveout.send_routing[2] = ctl->val[4];
314 card->waveout.send_dcba[2] = ctl->val[5];
315
316 break;
317
318 case CMD_SETMCH_FX:
319 card->mchannel_fx = ctl->val[0] & 0x000f;
320 break;
321
322 case CMD_GETPATCH:
323 if (ctl->val[0] == 0) {
324 if (copy_to_user(argp, &card->mgr.rpatch, sizeof(struct dsp_rpatch)))
325 ret = -EFAULT;
326 } else {
327 if ((ctl->val[0] - 1) / PATCHES_PER_PAGE >= card->mgr.current_pages) {
328 ret = -EINVAL;
329 break;
330 }
331
332 if (copy_to_user(argp, PATCH(&card->mgr, ctl->val[0] - 1), sizeof(struct dsp_patch)))
333 ret = -EFAULT;
334 }
335
336 break;
337
338 case CMD_GETGPR:
339 id = ctl->val[0];
340
341 if (id > NUM_GPRS) {
342 ret = -EINVAL;
343 break;
344 }
345
346 if (copy_to_user(argp, &card->mgr.gpr[id], sizeof(struct dsp_gpr)))
347 ret = -EFAULT;
348
349 break;
350
351 case CMD_GETCTLGPR:
352 addr = emu10k1_find_control_gpr(&card->mgr, (char *) ctl->val, &((char *) ctl->val)[PATCH_NAME_SIZE]);
353 ctl->val[0] = sblive_readptr(card, addr, 0);
354
355 if (copy_to_user(argp, ctl, sizeof(struct mixer_private_ioctl)))
356 ret = -EFAULT;
357
358 break;
359
360 case CMD_SETPATCH:
361 if (ctl->val[0] == 0)
362 memcpy(&card->mgr.rpatch, &ctl->val[1], sizeof(struct dsp_rpatch));
363 else {
364 page = (ctl->val[0] - 1) / PATCHES_PER_PAGE;
365 if (page > MAX_PATCHES_PAGES) {
366 ret = -EINVAL;
367 break;
368 }
369
370 if (page >= card->mgr.current_pages) {
371 for (i = card->mgr.current_pages; i < page + 1; i++) {
372 card->mgr.patch[i] = (void *)__get_free_page(GFP_KERNEL);
373 if(card->mgr.patch[i] == NULL) {
374 card->mgr.current_pages = i;
375 ret = -ENOMEM;
376 break;
377 }
378 memset(card->mgr.patch[i], 0, PAGE_SIZE);
379 }
380 card->mgr.current_pages = page + 1;
381 }
382
383 patch = PATCH(&card->mgr, ctl->val[0] - 1);
384
385 memcpy(patch, &ctl->val[1], sizeof(struct dsp_patch));
386
387 if (patch->code_size == 0) {
388 for(i = page + 1; i < card->mgr.current_pages; i++)
389 free_page((unsigned long) card->mgr.patch[i]);
390
391 card->mgr.current_pages = page + 1;
392 }
393 }
394 break;
395
396 case CMD_SETGPR:
397 if (ctl->val[0] > NUM_GPRS) {
398 ret = -EINVAL;
399 break;
400 }
401
402 memcpy(&card->mgr.gpr[ctl->val[0]], &ctl->val[1], sizeof(struct dsp_gpr));
403 break;
404
405 case CMD_SETCTLGPR:
406 addr = emu10k1_find_control_gpr(&card->mgr, (char *) ctl->val, (char *) ctl->val + PATCH_NAME_SIZE);
407 emu10k1_set_control_gpr(card, addr, *((s32 *)((char *) ctl->val + 2 * PATCH_NAME_SIZE)), 0);
408 break;
409
410 case CMD_SETGPOUT:
411 if ( ((ctl->val[0] > 2) && (!card->is_audigy))
412 || (ctl->val[0] > 15) || ctl->val[1] > 1) {
413 ret= -EINVAL;
414 break;
415 }
416
417 if (card->is_audigy)
418 emu10k1_writefn0(card, (1 << 24) | ((ctl->val[0]) << 16) | A_IOCFG, ctl->val[1]);
419 else
420 emu10k1_writefn0(card, (1 << 24) | (((ctl->val[0]) + 10) << 16) | HCFG, ctl->val[1]);
421 break;
422
423 case CMD_GETGPR2OSS:
424 id = ctl->val[0];
425 ch = ctl->val[1];
426
427 if (id >= SOUND_MIXER_NRDEVICES || ch >= 2) {
428 ret = -EINVAL;
429 break;
430 }
431
432 ctl->val[2] = card->mgr.ctrl_gpr[id][ch];
433
434 if (copy_to_user(argp, ctl, sizeof(struct mixer_private_ioctl)))
435 ret = -EFAULT;
436
437 break;
438
439 case CMD_SETGPR2OSS:
440 id = ctl->val[0];
441 /* 0 == left, 1 == right */
442 ch = ctl->val[1];
443 addr = ctl->val[2];
444
445 if (id >= SOUND_MIXER_NRDEVICES || ch >= 2) {
446 ret = -EINVAL;
447 break;
448 }
449
450 card->mgr.ctrl_gpr[id][ch] = addr;
451
452 if (card->is_aps)
453 break;
454
455 if (addr >= 0) {
456 unsigned int state = card->ac97->mixer_state[id];
457
458 if (ch == 1) {
459 state >>= 8;
460 card->ac97->stereo_mixers |= (1 << id);
461 }
462
463 card->ac97->supported_mixers |= (1 << id);
464
465 if (id == SOUND_MIXER_TREBLE) {
466 set_treble(card, card->ac97->mixer_state[id] & 0xff, (card->ac97->mixer_state[id] >> 8) & 0xff);
467 } else if (id == SOUND_MIXER_BASS) {
468 set_bass(card, card->ac97->mixer_state[id] & 0xff, (card->ac97->mixer_state[id] >> 8) & 0xff);
469 } else
470 emu10k1_set_volume_gpr(card, addr, state & 0xff,
471 volume_params[id]);
472 } else {
473 card->ac97->stereo_mixers &= ~(1 << id);
474 card->ac97->stereo_mixers |= card->ac97_stereo_mixers;
475
476 if (ch == 0) {
477 card->ac97->supported_mixers &= ~(1 << id);
478 card->ac97->supported_mixers |= card->ac97_supported_mixers;
479 }
480 }
481 break;
482
483 case CMD_SETPASSTHROUGH:
484 card->pt.selected = ctl->val[0] ? 1 : 0;
485 if (card->pt.state != PT_STATE_INACTIVE)
486 break;
487
488 card->pt.spcs_to_use = ctl->val[0] & 0x07;
489 break;
490
491 case CMD_PRIVATE3_VERSION:
492 ctl->val[0] = PRIVATE3_VERSION; //private3 version
493 ctl->val[1] = MAJOR_VER; //major driver version
494 ctl->val[2] = MINOR_VER; //minor driver version
495 ctl->val[3] = card->is_audigy; //1=card is audigy
496
497 if (card->is_audigy)
498 ctl->val[4]=emu10k1_readfn0(card, 0x18);
499
500 if (copy_to_user(argp, ctl, sizeof(struct mixer_private_ioctl)))
501 ret = -EFAULT;
502 break;
503
504 case CMD_AC97_BOOST:
505 if (ctl->val[0])
506 emu10k1_ac97_write(card->ac97, 0x18, 0x0);
507 else
508 emu10k1_ac97_write(card->ac97, 0x18, 0x0808);
509 break;
510 default:
511 ret = -EINVAL;
512 break;
513 }
514
515 kfree(ctl);
516 return ret;
517 break;
518
519 case SOUND_MIXER_PRIVATE4:
520
521 if (copy_from_user(&size, argp, sizeof(size)))
522 return -EFAULT;
523
524 DPD(2, "External tram size %#x\n", size);
525
526 if (size > 0x1fffff)
527 return -EINVAL;
528
529 size_reg = 0;
530
531 if (size != 0) {
532 size = (size - 1) >> 14;
533
534 while (size) {
535 size >>= 1;
536 size_reg++;
537 }
538
539 size = 0x4000 << size_reg;
540 }
541
542 DPD(2, "External tram size %#x %#x\n", size, size_reg);
543
544 if (size != card->tankmem.size) {
545 if (card->tankmem.size > 0) {
546 emu10k1_writefn0(card, HCFG_LOCKTANKCACHE, 1);
547
548 sblive_writeptr_tag(card, 0, TCB, 0, TCBS, 0, TAGLIST_END);
549
550 pci_free_consistent(card->pci_dev, card->tankmem.size, card->tankmem.addr, card->tankmem.dma_handle);
551
552 card->tankmem.size = 0;
553 }
554
555 if (size != 0) {
556 card->tankmem.addr = pci_alloc_consistent(card->pci_dev, size, &card->tankmem.dma_handle);
557 if (card->tankmem.addr == NULL)
558 return -ENOMEM;
559
560 card->tankmem.size = size;
561
562 sblive_writeptr_tag(card, 0, TCB, (u32) card->tankmem.dma_handle, TCBS,(u32) size_reg, TAGLIST_END);
563
564 emu10k1_writefn0(card, HCFG_LOCKTANKCACHE, 0);
565 }
566 }
567 return 0;
568 break;
569
570 default:
571 break;
572 }
573
574 return -EINVAL;
575}
576
577static int emu10k1_dsp_mixer(struct emu10k1_card *card, unsigned int oss_mixer, unsigned long arg)
578{
579 unsigned int left, right;
580 int val;
581 int scale;
582
583 card->ac97->modcnt++;
584
585 if (get_user(val, (int __user *)arg))
586 return -EFAULT;
587
588 /* cleanse input a little */
589 right = ((val >> 8) & 0xff);
590 left = (val & 0xff);
591
592 if (right > 100) right = 100;
593 if (left > 100) left = 100;
594
595 card->ac97->mixer_state[oss_mixer] = (right << 8) | left;
596 if (oss_mixer == SOUND_MIXER_TREBLE) {
597 set_treble(card, left, right);
598 return 0;
599 } if (oss_mixer == SOUND_MIXER_BASS) {
600 set_bass(card, left, right);
601 return 0;
602 }
603
604 if (oss_mixer == SOUND_MIXER_VOLUME)
605 scale = 1 << card->ac97->bit_resolution;
606 else
607 scale = volume_params[oss_mixer];
608
609 emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][0], left, scale);
610 emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][1], right, scale);
611
612 if (card->ac97_supported_mixers & (1 << oss_mixer))
613 card->ac97->write_mixer(card->ac97, oss_mixer, left, right);
614
615 return 0;
616}
617
618static int emu10k1_mixer_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
619{
620 int ret;
621 struct emu10k1_card *card = file->private_data;
622 unsigned int oss_mixer = _IOC_NR(cmd);
623
624 ret = -EINVAL;
625 if (!card->is_aps) {
626 if (cmd == SOUND_MIXER_INFO) {
627 mixer_info info;
628
629 strlcpy(info.id, card->ac97->name, sizeof(info.id));
630
631 if (card->is_audigy)
632 strlcpy(info.name, "Audigy - Emu10k1", sizeof(info.name));
633 else
634 strlcpy(info.name, "Creative SBLive - Emu10k1", sizeof(info.name));
635
636 info.modify_counter = card->ac97->modcnt;
637
638 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
639 return -EFAULT;
640
641 return 0;
642 }
643
644 if ((_SIOC_DIR(cmd) == (_SIOC_WRITE|_SIOC_READ)) && oss_mixer <= SOUND_MIXER_NRDEVICES)
645 ret = emu10k1_dsp_mixer(card, oss_mixer, arg);
646 else
647 ret = card->ac97->mixer_ioctl(card->ac97, cmd, arg);
648 }
649
650 if (ret < 0)
651 ret = emu10k1_private_mixer(card, cmd, arg);
652
653 return ret;
654}
655
656static int emu10k1_mixer_open(struct inode *inode, struct file *file)
657{
658 int minor = iminor(inode);
659 struct emu10k1_card *card = NULL;
660 struct list_head *entry;
661
662 DPF(4, "emu10k1_mixer_open()\n");
663
664 list_for_each(entry, &emu10k1_devs) {
665 card = list_entry(entry, struct emu10k1_card, list);
666
667 if (card->ac97->dev_mixer == minor)
668 goto match;
669 }
670
671 return -ENODEV;
672
673 match:
674 file->private_data = card;
675 return 0;
676}
677
678static int emu10k1_mixer_release(struct inode *inode, struct file *file)
679{
680 DPF(4, "emu10k1_mixer_release()\n");
681 return 0;
682}
683
684struct file_operations emu10k1_mixer_fops = {
685 .owner = THIS_MODULE,
686 .llseek = no_llseek,
687 .ioctl = emu10k1_mixer_ioctl,
688 .open = emu10k1_mixer_open,
689 .release = emu10k1_mixer_release,
690};
diff --git a/sound/oss/emu10k1/passthrough.c b/sound/oss/emu10k1/passthrough.c
new file mode 100644
index 000000000000..4094be55f3be
--- /dev/null
+++ b/sound/oss/emu10k1/passthrough.c
@@ -0,0 +1,236 @@
1/*
2 **********************************************************************
3 * passthrough.c -- Emu10k1 digital passthrough
4 * Copyright (C) 2001 Juha Yrjölä <jyrjola@cc.hut.fi>
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * May 15, 2001 Juha Yrjölä base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include <linux/module.h>
33#include <linux/poll.h>
34#include <linux/slab.h>
35#include <linux/bitops.h>
36#include <asm/io.h>
37#include <linux/sched.h>
38#include <linux/smp_lock.h>
39
40#include "hwaccess.h"
41#include "cardwo.h"
42#include "cardwi.h"
43#include "recmgr.h"
44#include "irqmgr.h"
45#include "audio.h"
46#include "8010.h"
47
48static void pt_putsamples(struct pt_data *pt, u16 *ptr, u16 left, u16 right)
49{
50 unsigned int idx;
51
52 ptr[pt->copyptr] = left;
53 idx = pt->copyptr + PT_SAMPLES/2;
54 idx %= PT_SAMPLES;
55 ptr[idx] = right;
56}
57
58static inline int pt_can_write(struct pt_data *pt)
59{
60 return pt->blocks_copied < pt->blocks_played + 8;
61}
62
63static int pt_wait_for_write(struct emu10k1_wavedevice *wavedev, int nonblock)
64{
65 struct emu10k1_card *card = wavedev->card;
66 struct pt_data *pt = &card->pt;
67
68 if (nonblock && !pt_can_write(pt))
69 return -EAGAIN;
70 while (!pt_can_write(pt) && pt->state != PT_STATE_INACTIVE) {
71 interruptible_sleep_on(&pt->wait);
72 if (signal_pending(current))
73 return -ERESTARTSYS;
74 }
75 if (pt->state == PT_STATE_INACTIVE)
76 return -EAGAIN;
77
78 return 0;
79}
80
81static int pt_putblock(struct emu10k1_wavedevice *wave_dev, u16 *block, int nonblock)
82{
83 struct woinst *woinst = wave_dev->woinst;
84 struct emu10k1_card *card = wave_dev->card;
85 struct pt_data *pt = &card->pt;
86 u16 *ptr = (u16 *) card->tankmem.addr;
87 int i = 0, r;
88 unsigned long flags;
89
90 r = pt_wait_for_write(wave_dev, nonblock);
91 if (r < 0)
92 return r;
93 spin_lock_irqsave(&card->pt.lock, flags);
94 while (i < PT_BLOCKSAMPLES) {
95 pt_putsamples(pt, ptr, block[2*i], block[2*i+1]);
96 if (pt->copyptr == 0)
97 pt->copyptr = PT_SAMPLES;
98 pt->copyptr--;
99 i++;
100 }
101 woinst->total_copied += PT_BLOCKSIZE;
102 pt->blocks_copied++;
103 if (pt->blocks_copied >= 4 && pt->state != PT_STATE_PLAYING) {
104 DPF(2, "activating digital pass-through playback\n");
105 sblive_writeptr(card, GPR_BASE + pt->enable_gpr, 0, 1);
106 pt->state = PT_STATE_PLAYING;
107 }
108 spin_unlock_irqrestore(&card->pt.lock, flags);
109 return 0;
110}
111
112int emu10k1_pt_setup(struct emu10k1_wavedevice *wave_dev)
113{
114 u32 bits;
115 struct emu10k1_card *card = wave_dev->card;
116 struct pt_data *pt = &card->pt;
117 int i;
118
119 for (i = 0; i < 3; i++) {
120 pt->old_spcs[i] = sblive_readptr(card, SPCS0 + i, 0);
121 if (pt->spcs_to_use & (1 << i)) {
122 DPD(2, "using S/PDIF port %d\n", i);
123 bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
124 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS |
125 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
126 if (pt->ac3data)
127 bits |= SPCS_NOTAUDIODATA;
128 sblive_writeptr(card, SPCS0 + i, 0, bits);
129 }
130 }
131 return 0;
132}
133
134ssize_t emu10k1_pt_write(struct file *file, const char __user *buffer, size_t count)
135{
136 struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
137 struct emu10k1_card *card = wave_dev->card;
138 struct pt_data *pt = &card->pt;
139 int nonblock, i, r, blocks, blocks_copied, bytes_copied = 0;
140
141 DPD(3, "emu10k1_pt_write(): %d bytes\n", count);
142
143 nonblock = file->f_flags & O_NONBLOCK;
144
145 if (card->tankmem.size < PT_SAMPLES*2)
146 return -EFAULT;
147 if (pt->state == PT_STATE_INACTIVE) {
148 DPF(2, "bufptr init\n");
149 pt->playptr = PT_SAMPLES-1;
150 pt->copyptr = PT_INITPTR;
151 pt->blocks_played = pt->blocks_copied = 0;
152 memset(card->tankmem.addr, 0, card->tankmem.size);
153 pt->state = PT_STATE_ACTIVATED;
154 pt->buf = kmalloc(PT_BLOCKSIZE, GFP_KERNEL);
155 pt->prepend_size = 0;
156 if (pt->buf == NULL)
157 return -ENOMEM;
158 emu10k1_pt_setup(wave_dev);
159 }
160 if (pt->prepend_size) {
161 int needed = PT_BLOCKSIZE - pt->prepend_size;
162
163 DPD(3, "prepend size %d, prepending %d bytes\n", pt->prepend_size, needed);
164 if (count < needed) {
165 copy_from_user(pt->buf + pt->prepend_size, buffer, count);
166 pt->prepend_size += count;
167 DPD(3, "prepend size now %d\n", pt->prepend_size);
168 return count;
169 }
170 copy_from_user(pt->buf + pt->prepend_size, buffer, needed);
171 r = pt_putblock(wave_dev, (u16 *) pt->buf, nonblock);
172 if (r)
173 return r;
174 bytes_copied += needed;
175 pt->prepend_size = 0;
176 }
177 blocks = (count-bytes_copied)/PT_BLOCKSIZE;
178 blocks_copied = 0;
179 while (blocks > 0) {
180 u16 __user *bufptr = (u16 __user *) buffer + (bytes_copied/2);
181 copy_from_user(pt->buf, bufptr, PT_BLOCKSIZE);
182 r = pt_putblock(wave_dev, (u16 *)pt->buf, nonblock);
183 if (r) {
184 if (bytes_copied)
185 return bytes_copied;
186 else
187 return r;
188 }
189 bytes_copied += PT_BLOCKSIZE;
190 blocks--;
191 blocks_copied++;
192 }
193 i = count - bytes_copied;
194 if (i) {
195 pt->prepend_size = i;
196 copy_from_user(pt->buf, buffer + bytes_copied, i);
197 bytes_copied += i;
198 DPD(3, "filling prepend buffer with %d bytes", i);
199 }
200 return bytes_copied;
201}
202
203void emu10k1_pt_stop(struct emu10k1_card *card)
204{
205 struct pt_data *pt = &card->pt;
206 int i;
207
208 if (pt->state != PT_STATE_INACTIVE) {
209 DPF(2, "digital pass-through stopped\n");
210 sblive_writeptr(card, (card->is_audigy ? A_GPR_BASE : GPR_BASE) + pt->enable_gpr, 0, 0);
211 for (i = 0; i < 3; i++) {
212 if (pt->spcs_to_use & (1 << i))
213 sblive_writeptr(card, SPCS0 + i, 0, pt->old_spcs[i]);
214 }
215 pt->state = PT_STATE_INACTIVE;
216 if(pt->buf)
217 kfree(pt->buf);
218 }
219}
220
221void emu10k1_pt_waveout_update(struct emu10k1_wavedevice *wave_dev)
222{
223 struct woinst *woinst = wave_dev->woinst;
224 struct pt_data *pt = &wave_dev->card->pt;
225 u32 pos;
226
227 if (pt->state == PT_STATE_PLAYING && pt->pos_gpr >= 0) {
228 pos = sblive_readptr(wave_dev->card, GPR_BASE + pt->pos_gpr, 0);
229 if (pos > PT_BLOCKSAMPLES)
230 pos = PT_BLOCKSAMPLES;
231 pos = 4 * (PT_BLOCKSAMPLES - pos);
232 } else
233 pos = 0;
234 woinst->total_played = pt->blocks_played * woinst->buffer.fragment_size + pos;
235 woinst->buffer.hw_pos = pos;
236}
diff --git a/sound/oss/emu10k1/passthrough.h b/sound/oss/emu10k1/passthrough.h
new file mode 100644
index 000000000000..420cc9784251
--- /dev/null
+++ b/sound/oss/emu10k1/passthrough.h
@@ -0,0 +1,99 @@
1/*
2 **********************************************************************
3 * passthrough.h -- Emu10k1 digital passthrough header file
4 * Copyright (C) 2001 Juha Yrjölä <jyrjola@cc.hut.fi>
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * May 15, 2001 Juha Yrjölä base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _PASSTHROUGH_H
33#define _PASSTHROUGH_H
34
35#include "audio.h"
36
37/* number of 16-bit stereo samples in XTRAM buffer */
38#define PT_SAMPLES 0x8000
39#define PT_BLOCKSAMPLES 0x400
40#define PT_BLOCKSIZE (PT_BLOCKSAMPLES*4)
41#define PT_BLOCKSIZE_LOG2 12
42#define PT_BLOCKCOUNT (PT_SAMPLES/PT_BLOCKSAMPLES)
43#define PT_INITPTR (PT_SAMPLES/2-1)
44
45#define PT_STATE_INACTIVE 0
46#define PT_STATE_ACTIVATED 1
47#define PT_STATE_PLAYING 2
48
49/* passthrough struct */
50struct pt_data
51{
52 u8 selected, state, spcs_to_use;
53 int intr_gpr, enable_gpr, pos_gpr;
54 u32 blocks_played, blocks_copied, old_spcs[3];
55 u32 playptr, copyptr;
56 u32 prepend_size;
57 u8 *buf;
58 u8 ac3data;
59
60 char *patch_name, *intr_gpr_name, *enable_gpr_name, *pos_gpr_name;
61
62 wait_queue_head_t wait;
63 spinlock_t lock;
64};
65
66/*
67 Passthrough can be done in two methods:
68
69 Method 1 : tram
70 In original emu10k1, we couldn't bypass the sample rate converters. Even at 48kHz
71 (the internal sample rate of the emu10k1) the samples would get messed up.
72 To over come this, samples are copied into the tram and a special dsp patch copies
73 the samples out and generates interrupts when a block has finnished playing.
74
75 Method 2 : Interpolator bypass
76
77 Creative fixed the sample rate convert problem in emu10k1 rev 7 and higher
78 (including the emu10k2 (audigy)). This allows us to use the regular, and much simpler
79 playback method.
80
81
82 In both methods, dsp code is used to mux audio and passthrough. This ensures that the spdif
83 doesn't receive audio and pasthrough data at the same time. The spdif flag SPCS_NOTAUDIODATA
84 is set to tell
85
86 */
87
88// emu10k1 revs greater than or equal to 7 can use method2
89
90#define USE_PT_METHOD2 (card->is_audigy)
91#define USE_PT_METHOD1 !USE_PT_METHOD2
92
93ssize_t emu10k1_pt_write(struct file *file, const char __user *buf, size_t count);
94
95int emu10k1_pt_setup(struct emu10k1_wavedevice *wave_dev);
96void emu10k1_pt_stop(struct emu10k1_card *card);
97void emu10k1_pt_waveout_update(struct emu10k1_wavedevice *wave_dev);
98
99#endif /* _PASSTHROUGH_H */
diff --git a/sound/oss/emu10k1/recmgr.c b/sound/oss/emu10k1/recmgr.c
new file mode 100644
index 000000000000..67c3fd04cfdd
--- /dev/null
+++ b/sound/oss/emu10k1/recmgr.c
@@ -0,0 +1,147 @@
1/*
2 **********************************************************************
3 * recmgr.c -- Recording manager for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include <asm/delay.h>
33#include "8010.h"
34#include "recmgr.h"
35
36void emu10k1_reset_record(struct emu10k1_card *card, struct wavein_buffer *buffer)
37{
38 DPF(2, "emu10k1_reset_record()\n");
39
40 sblive_writeptr(card, buffer->sizereg, 0, ADCBS_BUFSIZE_NONE);
41
42 sblive_writeptr(card, buffer->sizereg, 0, buffer->sizeregval);
43
44 while (sblive_readptr(card, buffer->idxreg, 0))
45 udelay(5);
46}
47
48void emu10k1_start_record(struct emu10k1_card *card, struct wavein_buffer *buffer)
49{
50 DPF(2, "emu10k1_start_record()\n");
51
52 if (buffer->adcctl)
53 sblive_writeptr(card, ADCCR, 0, buffer->adcctl);
54}
55
56void emu10k1_stop_record(struct emu10k1_card *card, struct wavein_buffer *buffer)
57{
58 DPF(2, "emu10k1_stop_record()\n");
59
60 /* Disable record transfer */
61 if (buffer->adcctl)
62 sblive_writeptr(card, ADCCR, 0, 0);
63}
64
65void emu10k1_set_record_src(struct emu10k1_card *card, struct wiinst *wiinst)
66{
67 struct wavein_buffer *buffer = &wiinst->buffer;
68
69 DPF(2, "emu10k1_set_record_src()\n");
70
71 switch (wiinst->recsrc) {
72
73 case WAVERECORD_AC97:
74 DPF(2, "recording source: AC97\n");
75 buffer->sizereg = ADCBS;
76 buffer->addrreg = ADCBA;
77 buffer->idxreg = card->is_audigy ? A_ADCIDX_IDX : ADCIDX_IDX;
78
79 switch (wiinst->format.samplingrate) {
80 case 0xBB80:
81 buffer->adcctl = ADCCR_SAMPLERATE_48;
82 break;
83 case 0xAC44:
84 buffer->adcctl = ADCCR_SAMPLERATE_44;
85 break;
86 case 0x7D00:
87 buffer->adcctl = ADCCR_SAMPLERATE_32;
88 break;
89 case 0x5DC0:
90 buffer->adcctl = ADCCR_SAMPLERATE_24;
91 break;
92 case 0x5622:
93 buffer->adcctl = ADCCR_SAMPLERATE_22;
94 break;
95 case 0x3E80:
96 buffer->adcctl = ADCCR_SAMPLERATE_16;
97 break;
98 // FIXME: audigy supports 12kHz recording
99 /*
100 case ????:
101 buffer->adcctl = A_ADCCR_SAMPLERATE_12;
102 break;
103 */
104 case 0x2B11:
105 buffer->adcctl = card->is_audigy ? A_ADCCR_SAMPLERATE_11 : ADCCR_SAMPLERATE_11;
106 break;
107 case 0x1F40:
108 buffer->adcctl = card->is_audigy ? A_ADCCR_SAMPLERATE_8 : ADCCR_SAMPLERATE_8;
109 break;
110 default:
111 BUG();
112 break;
113 }
114
115 buffer->adcctl |= card->is_audigy ? A_ADCCR_LCHANENABLE : ADCCR_LCHANENABLE;
116
117 if (wiinst->format.channels == 2)
118 buffer->adcctl |= card->is_audigy ? A_ADCCR_RCHANENABLE : ADCCR_RCHANENABLE;
119
120 break;
121
122 case WAVERECORD_MIC:
123 DPF(2, "recording source: MIC\n");
124 buffer->sizereg = MICBS;
125 buffer->addrreg = MICBA;
126 buffer->idxreg = MICIDX_IDX;
127 buffer->adcctl = 0;
128 break;
129
130 case WAVERECORD_FX:
131 DPF(2, "recording source: FX\n");
132 buffer->sizereg = FXBS;
133 buffer->addrreg = FXBA;
134 buffer->idxreg = FXIDX_IDX;
135 buffer->adcctl = 0;
136
137 sblive_writeptr(card, FXWC, 0, wiinst->fxwc);
138 break;
139 default:
140 BUG();
141 break;
142 }
143
144 DPD(2, "bus addx: %#lx\n", (unsigned long) buffer->dma_handle);
145
146 sblive_writeptr(card, buffer->addrreg, 0, (u32)buffer->dma_handle);
147}
diff --git a/sound/oss/emu10k1/recmgr.h b/sound/oss/emu10k1/recmgr.h
new file mode 100644
index 000000000000..a68766ac4fd5
--- /dev/null
+++ b/sound/oss/emu10k1/recmgr.h
@@ -0,0 +1,48 @@
1/*
2 **********************************************************************
3 * recmgr.h
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _RECORDMGR_H
33#define _RECORDMGR_H
34
35#include "hwaccess.h"
36#include "cardwi.h"
37
38/* Recording resources */
39#define WAVERECORD_AC97 0x01
40#define WAVERECORD_MIC 0x02
41#define WAVERECORD_FX 0x03
42
43void emu10k1_reset_record(struct emu10k1_card *card, struct wavein_buffer *buffer);
44void emu10k1_start_record(struct emu10k1_card *, struct wavein_buffer *);
45void emu10k1_stop_record(struct emu10k1_card *, struct wavein_buffer *);
46void emu10k1_set_record_src(struct emu10k1_card *, struct wiinst *wiinst);
47
48#endif /* _RECORDMGR_H */
diff --git a/sound/oss/emu10k1/timer.c b/sound/oss/emu10k1/timer.c
new file mode 100644
index 000000000000..d10d30739f41
--- /dev/null
+++ b/sound/oss/emu10k1/timer.c
@@ -0,0 +1,176 @@
1
2/*
3 **********************************************************************
4 * timer.c
5 * Copyright (C) 1999, 2000 Creative Labs, inc.
6 *
7 **********************************************************************
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (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
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
22 * USA.
23 *
24 **********************************************************************
25 */
26
27/* 3/6/2000 Improved support for different timer delays Rui Sousa */
28
29/* 4/3/2000 Implemented timer list using list.h Rui Sousa */
30
31#include "hwaccess.h"
32#include "8010.h"
33#include "irqmgr.h"
34#include "timer.h"
35
36/* Try to schedule only once per fragment */
37
38void emu10k1_timer_irqhandler(struct emu10k1_card *card)
39{
40 struct emu_timer *t;
41 struct list_head *entry;
42
43 spin_lock(&card->timer_lock);
44
45 list_for_each(entry, &card->timers) {
46 t = list_entry(entry, struct emu_timer, list);
47
48 if (t->state & TIMER_STATE_ACTIVE) {
49 t->count++;
50 if (t->count == t->count_max) {
51 t->count = 0;
52 tasklet_hi_schedule(&t->tasklet);
53 }
54 }
55 }
56
57 spin_unlock(&card->timer_lock);
58
59 return;
60}
61
62void emu10k1_timer_install(struct emu10k1_card *card, struct emu_timer *timer, u16 delay)
63{
64 struct emu_timer *t;
65 struct list_head *entry;
66 unsigned long flags;
67
68 if (delay < 5)
69 delay = 5;
70
71 timer->delay = delay;
72 timer->state = TIMER_STATE_INSTALLED;
73
74 spin_lock_irqsave(&card->timer_lock, flags);
75
76 timer->count_max = timer->delay / (card->timer_delay < 1024 ? card->timer_delay : 1024);
77 timer->count = timer->count_max - 1;
78
79 list_add(&timer->list, &card->timers);
80
81 if (card->timer_delay > delay) {
82 if (card->timer_delay == TIMER_STOPPED)
83 emu10k1_irq_enable(card, INTE_INTERVALTIMERENB);
84
85 card->timer_delay = delay;
86 delay = (delay < 1024 ? delay : 1024);
87
88 emu10k1_timer_set(card, delay);
89
90 list_for_each(entry, &card->timers) {
91 t = list_entry(entry, struct emu_timer, list);
92
93 t->count_max = t->delay / delay;
94 /* don't want to think much, just force scheduling
95 on the next interrupt */
96 t->count = t->count_max - 1;
97 }
98
99 DPD(2, "timer rate --> %u\n", delay);
100 }
101
102 spin_unlock_irqrestore(&card->timer_lock, flags);
103
104 return;
105}
106
107void emu10k1_timer_uninstall(struct emu10k1_card *card, struct emu_timer *timer)
108{
109 struct emu_timer *t;
110 struct list_head *entry;
111 u16 delay = TIMER_STOPPED;
112 unsigned long flags;
113
114 if (timer->state == TIMER_STATE_UNINSTALLED)
115 return;
116
117 spin_lock_irqsave(&card->timer_lock, flags);
118
119 list_del(&timer->list);
120
121 list_for_each(entry, &card->timers) {
122 t = list_entry(entry, struct emu_timer, list);
123
124 if (t->delay < delay)
125 delay = t->delay;
126 }
127
128 if (card->timer_delay != delay) {
129 card->timer_delay = delay;
130
131 if (delay == TIMER_STOPPED)
132 emu10k1_irq_disable(card, INTE_INTERVALTIMERENB);
133 else {
134 delay = (delay < 1024 ? delay : 1024);
135
136 emu10k1_timer_set(card, delay);
137
138 list_for_each(entry, &card->timers) {
139 t = list_entry(entry, struct emu_timer, list);
140
141 t->count_max = t->delay / delay;
142 t->count = t->count_max - 1;
143 }
144 }
145
146 DPD(2, "timer rate --> %u\n", delay);
147 }
148
149 spin_unlock_irqrestore(&card->timer_lock, flags);
150
151 timer->state = TIMER_STATE_UNINSTALLED;
152
153 return;
154}
155
156void emu10k1_timer_enable(struct emu10k1_card *card, struct emu_timer *timer)
157{
158 unsigned long flags;
159
160 spin_lock_irqsave(&card->timer_lock, flags);
161 timer->state |= TIMER_STATE_ACTIVE;
162 spin_unlock_irqrestore(&card->timer_lock, flags);
163
164 return;
165}
166
167void emu10k1_timer_disable(struct emu10k1_card *card, struct emu_timer *timer)
168{
169 unsigned long flags;
170
171 spin_lock_irqsave(&card->timer_lock, flags);
172 timer->state &= ~TIMER_STATE_ACTIVE;
173 spin_unlock_irqrestore(&card->timer_lock, flags);
174
175 return;
176}
diff --git a/sound/oss/emu10k1/timer.h b/sound/oss/emu10k1/timer.h
new file mode 100644
index 000000000000..b2543b4d53a8
--- /dev/null
+++ b/sound/oss/emu10k1/timer.h
@@ -0,0 +1,54 @@
1/*
2 **********************************************************************
3 * timer.h
4 * Copyright (C) 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 * USA.
22 *
23 **********************************************************************
24 */
25
26
27#ifndef _TIMER_H
28#define _TIMER_H
29
30#include <linux/sched.h>
31#include <linux/interrupt.h>
32#include "hwaccess.h"
33
34struct emu_timer
35{
36 struct list_head list;
37 struct tasklet_struct tasklet;
38 u8 state;
39 u16 count; /* current number of interrupts */
40 u16 count_max; /* number of interrupts needed to schedule the bh */
41 u16 delay; /* timer delay */
42};
43
44void emu10k1_timer_install(struct emu10k1_card *, struct emu_timer *, u16);
45void emu10k1_timer_uninstall(struct emu10k1_card *, struct emu_timer *);
46void emu10k1_timer_enable(struct emu10k1_card *, struct emu_timer *);
47void emu10k1_timer_disable(struct emu10k1_card *, struct emu_timer *);
48
49#define TIMER_STOPPED 0xffff
50#define TIMER_STATE_INSTALLED 0x01
51#define TIMER_STATE_ACTIVE 0x02
52#define TIMER_STATE_UNINSTALLED 0x04
53
54#endif /* _TIMER_H */
diff --git a/sound/oss/emu10k1/voicemgr.c b/sound/oss/emu10k1/voicemgr.c
new file mode 100644
index 000000000000..d88b602c07c2
--- /dev/null
+++ b/sound/oss/emu10k1/voicemgr.c
@@ -0,0 +1,398 @@
1/*
2 **********************************************************************
3 * voicemgr.c - Voice manager for emu10k1 driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#include "voicemgr.h"
33#include "8010.h"
34
35#define PITCH_48000 0x00004000
36#define PITCH_96000 0x00008000
37#define PITCH_85000 0x00007155
38#define PITCH_80726 0x00006ba2
39#define PITCH_67882 0x00005a82
40#define PITCH_57081 0x00004c1c
41
42static u32 emu10k1_select_interprom(struct emu10k1_card *card,
43 struct emu_voice *voice)
44{
45 if(voice->pitch_target==PITCH_48000)
46 return CCCA_INTERPROM_0;
47 else if(voice->pitch_target<PITCH_48000)
48 return CCCA_INTERPROM_1;
49 else if(voice->pitch_target>=PITCH_96000)
50 return CCCA_INTERPROM_0;
51 else if(voice->pitch_target>=PITCH_85000)
52 return CCCA_INTERPROM_6;
53 else if(voice->pitch_target>=PITCH_80726)
54 return CCCA_INTERPROM_5;
55 else if(voice->pitch_target>=PITCH_67882)
56 return CCCA_INTERPROM_4;
57 else if(voice->pitch_target>=PITCH_57081)
58 return CCCA_INTERPROM_3;
59 else
60 return CCCA_INTERPROM_2;
61}
62
63
64/**
65 * emu10k1_voice_alloc_buffer -
66 *
67 * allocates the memory buffer for a voice. Two page tables are kept for each buffer.
68 * One (dma_handle) keeps track of the host memory pages used and the other (virtualpagetable)
69 * is passed to the device so that it can do DMA to host memory.
70 *
71 */
72int emu10k1_voice_alloc_buffer(struct emu10k1_card *card, struct voice_mem *mem, u32 pages)
73{
74 u32 pageindex, pagecount;
75 u32 busaddx;
76 int i;
77
78 DPD(2, "requested pages is: %d\n", pages);
79
80 if ((mem->emupageindex = emu10k1_addxmgr_alloc(pages * PAGE_SIZE, card)) < 0)
81 {
82 DPF(1, "couldn't allocate emu10k1 address space\n");
83 return -1;
84 }
85
86 /* Fill in virtual memory table */
87 for (pagecount = 0; pagecount < pages; pagecount++) {
88 if ((mem->addr[pagecount] = pci_alloc_consistent(card->pci_dev, PAGE_SIZE, &mem->dma_handle[pagecount]))
89 == NULL) {
90 mem->pages = pagecount;
91 DPF(1, "couldn't allocate dma memory\n");
92 return -1;
93 }
94
95 DPD(2, "Virtual Addx: %p\n", mem->addr[pagecount]);
96
97 for (i = 0; i < PAGE_SIZE / EMUPAGESIZE; i++) {
98 busaddx = (u32) mem->dma_handle[pagecount] + i * EMUPAGESIZE;
99
100 DPD(3, "Bus Addx: %#x\n", busaddx);
101
102 pageindex = mem->emupageindex + pagecount * PAGE_SIZE / EMUPAGESIZE + i;
103
104 ((u32 *) card->virtualpagetable.addr)[pageindex] = cpu_to_le32((busaddx * 2) | pageindex);
105 }
106 }
107
108 mem->pages = pagecount;
109
110 return 0;
111}
112
113/**
114 * emu10k1_voice_free_buffer -
115 *
116 * frees the memory buffer for a voice.
117 */
118void emu10k1_voice_free_buffer(struct emu10k1_card *card, struct voice_mem *mem)
119{
120 u32 pagecount, pageindex;
121 int i;
122
123 if (mem->emupageindex < 0)
124 return;
125
126 for (pagecount = 0; pagecount < mem->pages; pagecount++) {
127 pci_free_consistent(card->pci_dev, PAGE_SIZE,
128 mem->addr[pagecount],
129 mem->dma_handle[pagecount]);
130
131 for (i = 0; i < PAGE_SIZE / EMUPAGESIZE; i++) {
132 pageindex = mem->emupageindex + pagecount * PAGE_SIZE / EMUPAGESIZE + i;
133 ((u32 *) card->virtualpagetable.addr)[pageindex] =
134 cpu_to_le32(((u32) card->silentpage.dma_handle * 2) | pageindex);
135 }
136 }
137
138 emu10k1_addxmgr_free(card, mem->emupageindex);
139 mem->emupageindex = -1;
140}
141
142int emu10k1_voice_alloc(struct emu10k1_card *card, struct emu_voice *voice)
143{
144 u8 *voicetable = card->voicetable;
145 int i;
146 unsigned long flags;
147
148 DPF(2, "emu10k1_voice_alloc()\n");
149
150 spin_lock_irqsave(&card->lock, flags);
151
152 if (voice->flags & VOICE_FLAGS_STEREO) {
153 for (i = 0; i < NUM_G; i += 2)
154 if ((voicetable[i] == VOICE_USAGE_FREE) && (voicetable[i + 1] == VOICE_USAGE_FREE)) {
155 voicetable[i] = voice->usage;
156 voicetable[i + 1] = voice->usage;
157 break;
158 }
159 } else {
160 for (i = 0; i < NUM_G; i++)
161 if (voicetable[i] == VOICE_USAGE_FREE) {
162 voicetable[i] = voice->usage;
163 break;
164 }
165 }
166
167 spin_unlock_irqrestore(&card->lock, flags);
168
169 if (i >= NUM_G)
170 return -1;
171
172 voice->card = card;
173 voice->num = i;
174
175 for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
176 DPD(2, " voice allocated -> %d\n", voice->num + i);
177
178 sblive_writeptr_tag(card, voice->num + i, IFATN, 0xffff,
179 DCYSUSV, 0,
180 VTFT, 0x0000ffff,
181 PTRX, 0,
182 TAGLIST_END);
183 }
184
185 return 0;
186}
187
188void emu10k1_voice_free(struct emu_voice *voice)
189{
190 struct emu10k1_card *card = voice->card;
191 int i;
192 unsigned long flags;
193
194 DPF(2, "emu10k1_voice_free()\n");
195
196 if (voice->usage == VOICE_USAGE_FREE)
197 return;
198
199 for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
200 DPD(2, " voice released -> %d\n", voice->num + i);
201
202 sblive_writeptr_tag(card, voice->num + i, DCYSUSV, 0,
203 VTFT, 0x0000ffff,
204 PTRX_PITCHTARGET, 0,
205 CVCF, 0x0000ffff,
206 //CPF, 0,
207 TAGLIST_END);
208
209 sblive_writeptr(card, CPF, voice->num + i, 0);
210 }
211
212 voice->usage = VOICE_USAGE_FREE;
213
214 spin_lock_irqsave(&card->lock, flags);
215
216 card->voicetable[voice->num] = VOICE_USAGE_FREE;
217
218 if (voice->flags & VOICE_FLAGS_STEREO)
219 card->voicetable[voice->num + 1] = VOICE_USAGE_FREE;
220
221 spin_unlock_irqrestore(&card->lock, flags);
222}
223
224void emu10k1_voice_playback_setup(struct emu_voice *voice)
225{
226 struct emu10k1_card *card = voice->card;
227 u32 start;
228 int i;
229
230 DPF(2, "emu10k1_voice_playback_setup()\n");
231
232 if (voice->flags & VOICE_FLAGS_STEREO) {
233 /* Set stereo bit */
234 start = 28;
235 sblive_writeptr(card, CPF, voice->num, CPF_STEREO_MASK);
236 sblive_writeptr(card, CPF, voice->num + 1, CPF_STEREO_MASK);
237 } else {
238 start = 30;
239 sblive_writeptr(card, CPF, voice->num, 0);
240 }
241
242 if(!(voice->flags & VOICE_FLAGS_16BIT))
243 start *= 2;
244
245 voice->start += start;
246
247 for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
248 if (card->is_audigy) {
249 sblive_writeptr(card, A_FXRT1, voice->num + i, voice->params[i].send_routing);
250 sblive_writeptr(card, A_FXRT2, voice->num + i, voice->params[i].send_routing2);
251 sblive_writeptr(card, A_SENDAMOUNTS, voice->num + i, voice->params[i].send_hgfe);
252 } else {
253 sblive_writeptr(card, FXRT, voice->num + i, voice->params[i].send_routing << 16);
254 }
255
256 /* Stop CA */
257 /* Assumption that PT is already 0 so no harm overwriting */
258 sblive_writeptr(card, PTRX, voice->num + i, ((voice->params[i].send_dcba & 0xff) << 8)
259 | ((voice->params[i].send_dcba & 0xff00) >> 8));
260
261 sblive_writeptr_tag(card, voice->num + i,
262 /* CSL, ST, CA */
263 DSL, voice->endloop | (voice->params[i].send_dcba & 0xff000000),
264 PSST, voice->startloop | ((voice->params[i].send_dcba & 0x00ff0000) << 8),
265 CCCA, (voice->start) | emu10k1_select_interprom(card,voice) |
266 ((voice->flags & VOICE_FLAGS_16BIT) ? 0 : CCCA_8BITSELECT),
267 /* Clear filter delay memory */
268 Z1, 0,
269 Z2, 0,
270 /* Invalidate maps */
271 MAPA, MAP_PTI_MASK | ((u32) card->silentpage.dma_handle * 2),
272 MAPB, MAP_PTI_MASK | ((u32) card->silentpage.dma_handle * 2),
273 /* modulation envelope */
274 CVCF, 0x0000ffff,
275 VTFT, 0x0000ffff,
276 ATKHLDM, 0,
277 DCYSUSM, 0x007f,
278 LFOVAL1, 0x8000,
279 LFOVAL2, 0x8000,
280 FMMOD, 0,
281 TREMFRQ, 0,
282 FM2FRQ2, 0,
283 ENVVAL, 0x8000,
284 /* volume envelope */
285 ATKHLDV, 0x7f7f,
286 ENVVOL, 0x8000,
287 /* filter envelope */
288 PEFE_FILTERAMOUNT, 0x7f,
289 /* pitch envelope */
290 PEFE_PITCHAMOUNT, 0, TAGLIST_END);
291
292 voice->params[i].fc_target = 0xffff;
293 }
294}
295
296void emu10k1_voices_start(struct emu_voice *first_voice, unsigned int num_voices, int set)
297{
298 struct emu10k1_card *card = first_voice->card;
299 struct emu_voice *voice;
300 unsigned int voicenum;
301 int j;
302
303 DPF(2, "emu10k1_voices_start()\n");
304
305 for (voicenum = 0; voicenum < num_voices; voicenum++)
306 {
307 voice = first_voice + voicenum;
308
309 if (!set) {
310 u32 cra, ccis, cs, sample;
311 if (voice->flags & VOICE_FLAGS_STEREO) {
312 cra = 64;
313 ccis = 28;
314 cs = 4;
315 } else {
316 cra = 64;
317 ccis = 30;
318 cs = 2;
319 }
320
321 if(voice->flags & VOICE_FLAGS_16BIT) {
322 sample = 0x00000000;
323 } else {
324 sample = 0x80808080;
325 ccis *= 2;
326 }
327
328 for(j = 0; j < cs; j++)
329 sblive_writeptr(card, CD0 + j, voice->num, sample);
330
331 /* Reset cache */
332 sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num, 0);
333 if (voice->flags & VOICE_FLAGS_STEREO)
334 sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num + 1, 0);
335
336 sblive_writeptr(card, CCR_READADDRESS, voice->num, cra);
337
338 if (voice->flags & VOICE_FLAGS_STEREO)
339 sblive_writeptr(card, CCR_READADDRESS, voice->num + 1, cra);
340
341 /* Fill cache */
342 sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num, ccis);
343 }
344
345 for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
346 sblive_writeptr_tag(card, voice->num + j,
347 IFATN, (voice->params[j].initial_fc << 8) | voice->params[j].initial_attn,
348 VTFT, (voice->params[j].volume_target << 16) | voice->params[j].fc_target,
349 CVCF, (voice->params[j].volume_target << 16) | voice->params[j].fc_target,
350 DCYSUSV, (voice->params[j].byampl_env_sustain << 8) | voice->params[j].byampl_env_decay,
351 TAGLIST_END);
352
353 emu10k1_clear_stop_on_loop(card, voice->num + j);
354 }
355 }
356
357
358 for (voicenum = 0; voicenum < num_voices; voicenum++)
359 {
360 voice = first_voice + voicenum;
361
362 for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
363 sblive_writeptr(card, PTRX_PITCHTARGET, voice->num + j, voice->pitch_target);
364
365 if (j == 0)
366 sblive_writeptr(card, CPF_CURRENTPITCH, voice->num, voice->pitch_target);
367
368 sblive_writeptr(card, IP, voice->num + j, voice->initial_pitch);
369 }
370 }
371}
372
373void emu10k1_voices_stop(struct emu_voice *first_voice, int num_voices)
374{
375 struct emu10k1_card *card = first_voice->card;
376 struct emu_voice *voice;
377 unsigned int voice_num;
378 int j;
379
380 DPF(2, "emu10k1_voice_stop()\n");
381
382 for (voice_num = 0; voice_num < num_voices; voice_num++)
383 {
384 voice = first_voice + voice_num;
385
386 for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
387 sblive_writeptr_tag(card, voice->num + j,
388 PTRX_PITCHTARGET, 0,
389 CPF_CURRENTPITCH, 0,
390 IFATN, 0xffff,
391 VTFT, 0x0000ffff,
392 CVCF, 0x0000ffff,
393 IP, 0,
394 TAGLIST_END);
395 }
396 }
397}
398
diff --git a/sound/oss/emu10k1/voicemgr.h b/sound/oss/emu10k1/voicemgr.h
new file mode 100644
index 000000000000..099a8cb7f2c5
--- /dev/null
+++ b/sound/oss/emu10k1/voicemgr.h
@@ -0,0 +1,103 @@
1/*
2 **********************************************************************
3 * sblive_voice.h -- EMU Voice Resource Manager header file
4 * Copyright 1999, 2000 Creative Labs, Inc.
5 *
6 **********************************************************************
7 *
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 *
12 **********************************************************************
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public
25 * License along with this program; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
27 * USA.
28 *
29 **********************************************************************
30 */
31
32#ifndef _VOICEMGR_H
33#define _VOICEMGR_H
34
35#include "hwaccess.h"
36
37/* struct emu_voice.usage flags */
38#define VOICE_USAGE_FREE 0x01
39#define VOICE_USAGE_MIDI 0x02
40#define VOICE_USAGE_PLAYBACK 0x04
41
42/* struct emu_voice.flags flags */
43#define VOICE_FLAGS_STEREO 0x02
44#define VOICE_FLAGS_16BIT 0x04
45
46struct voice_param
47{
48 /* FX bus amount send */
49
50 u32 send_routing;
51 // audigy only:
52 u32 send_routing2;
53
54 u32 send_dcba;
55 // audigy only:
56 u32 send_hgfe;
57
58
59 u32 initial_fc;
60 u32 fc_target;
61
62 u32 initial_attn;
63 u32 volume_target;
64
65 u32 byampl_env_sustain;
66 u32 byampl_env_decay;
67};
68
69struct voice_mem {
70 int emupageindex;
71 void *addr[BUFMAXPAGES];
72 dma_addr_t dma_handle[BUFMAXPAGES];
73 u32 pages;
74};
75
76struct emu_voice
77{
78 struct emu10k1_card *card;
79 u8 usage; /* Free, MIDI, playback */
80 u8 num; /* Voice ID */
81 u8 flags; /* Stereo/mono, 8/16 bit */
82
83 u32 startloop;
84 u32 endloop;
85 u32 start;
86
87 u32 initial_pitch;
88 u32 pitch_target;
89
90 struct voice_param params[2];
91
92 struct voice_mem mem;
93};
94
95int emu10k1_voice_alloc_buffer(struct emu10k1_card *, struct voice_mem *, u32);
96void emu10k1_voice_free_buffer(struct emu10k1_card *, struct voice_mem *);
97int emu10k1_voice_alloc(struct emu10k1_card *, struct emu_voice *);
98void emu10k1_voice_free(struct emu_voice *);
99void emu10k1_voice_playback_setup(struct emu_voice *);
100void emu10k1_voices_start(struct emu_voice *, unsigned int, int);
101void emu10k1_voices_stop(struct emu_voice *, int);
102
103#endif /* _VOICEMGR_H */
diff --git a/sound/oss/es1370.c b/sound/oss/es1370.c
new file mode 100644
index 000000000000..056091cff266
--- /dev/null
+++ b/sound/oss/es1370.c
@@ -0,0 +1,2789 @@
1/*****************************************************************************/
2
3/*
4 * es1370.c -- Ensoniq ES1370/Asahi Kasei AK4531 audio driver.
5 *
6 * Copyright (C) 1998-2001, 2003 Thomas Sailer (t.sailer@alumni.ethz.ch)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * Special thanks to David C. Niemi
23 *
24 *
25 * Module command line parameters:
26 * lineout if 1 the LINE jack is used as an output instead of an input.
27 * LINE then contains the unmixed dsp output. This can be used
28 * to make the card a four channel one: use dsp to output two
29 * channels to LINE and dac to output the other two channels to
30 * SPKR. Set the mixer to only output synth to SPKR.
31 * micbias sets the +5V bias to the mic if using an electretmic.
32 *
33 *
34 * Note: sync mode is not yet supported (i.e. running dsp and dac from the same
35 * clock source)
36 *
37 * Supported devices:
38 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
39 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
40 * /dev/dsp1 additional DAC, like /dev/dsp, but output only,
41 * only 5512, 11025, 22050 and 44100 samples/s,
42 * outputs to mixer "SYNTH" setting
43 * /dev/midi simple MIDI UART interface, no ioctl
44 *
45 * NOTE: the card does not have any FM/Wavetable synthesizer, it is supposed
46 * to be done in software. That is what /dev/dac is for. By now (Q2 1998)
47 * there are several MIDI to PCM (WAV) packages, one of them is timidity.
48 *
49 * Revision history
50 * 26.03.1998 0.1 Initial release
51 * 31.03.1998 0.2 Fix bug in GETOSPACE
52 * 04.04.1998 0.3 Make it work (again) under 2.0.33
53 * Fix mixer write operation not returning the actual
54 * settings
55 * 05.04.1998 0.4 First attempt at using the new PCI stuff
56 * 29.04.1998 0.5 Fix hang when ^C is pressed on amp
57 * 07.05.1998 0.6 Don't double lock around stop_*() in *_release()
58 * 10.05.1998 0.7 First stab at a simple midi interface (no bells&whistles)
59 * 14.05.1998 0.8 Don't allow excessive interrupt rates
60 * 08.06.1998 0.9 First release using Alan Cox' soundcore instead of
61 * miscdevice
62 * 05.07.1998 0.10 Fixed the driver to correctly maintin OSS style volume
63 * settings (not sure if this should be standard)
64 * Fixed many references: f_flags should be f_mode
65 * -- Gerald Britton <gbritton@mit.edu>
66 * 03.08.1998 0.11 Now mixer behaviour can basically be selected between
67 * "OSS documented" and "OSS actual" behaviour
68 * Fixed mixer table thanks to Hakan.Lennestal@lu.erisoft.se
69 * On module startup, set DAC2 to 11kSPS instead of 5.5kSPS,
70 * as it produces an annoying ssssh in the lower sampling rate
71 * Do not include modversions.h
72 * 22.08.1998 0.12 Mixer registers actually have 5 instead of 4 bits
73 * pointed out by Itai Nahshon
74 * 31.08.1998 0.13 Fix realplayer problems - dac.count issues
75 * 08.10.1998 0.14 Joystick support fixed
76 * -- Oliver Neukum <c188@org.chemie.uni-muenchen.de>
77 * 10.12.1998 0.15 Fix drain_dac trying to wait on not yet initialized DMA
78 * 16.12.1998 0.16 Don't wake up app until there are fragsize bytes to read/write
79 * 06.01.1999 0.17 remove the silly SA_INTERRUPT flag.
80 * hopefully killed the egcs section type conflict
81 * 12.03.1999 0.18 cinfo.blocks should be reset after GETxPTR ioctl.
82 * reported by Johan Maes <joma@telindus.be>
83 * 22.03.1999 0.19 return EAGAIN instead of EBUSY when O_NONBLOCK
84 * read/write cannot be executed
85 * 07.04.1999 0.20 implemented the following ioctl's: SOUND_PCM_READ_RATE,
86 * SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
87 * Alpha fixes reported by Peter Jones <pjones@redhat.com>
88 * Note: joystick address handling might still be wrong on archs
89 * other than i386
90 * 10.05.1999 0.21 Added support for an electret mic for SB PCI64
91 * to the Linux kernel sound driver. This mod also straighten
92 * out the question marks around the mic impedance setting
93 * (micz). From Kim.Berts@fisub.mail.abb.com
94 * 11.05.1999 0.22 Implemented the IMIX call to mute recording monitor.
95 * Guenter Geiger <geiger@epy.co.at>
96 * 15.06.1999 0.23 Fix bad allocation bug.
97 * Thanks to Deti Fliegl <fliegl@in.tum.de>
98 * 28.06.1999 0.24 Add pci_set_master
99 * 02.08.1999 0.25 Added workaround for the "phantom write" bug first
100 * documented by Dave Sharpless from Anchor Games
101 * 03.08.1999 0.26 adapt to Linus' new __setup/__initcall
102 * added kernel command line option "es1370=joystick[,lineout[,micbias]]"
103 * removed CONFIG_SOUND_ES1370_JOYPORT_BOOT kludge
104 * 12.08.1999 0.27 module_init/__setup fixes
105 * 19.08.1999 0.28 SOUND_MIXER_IMIX fixes, reported by Gianluca <gialluca@mail.tiscalinet.it>
106 * 31.08.1999 0.29 add spin_lock_init
107 * replaced current->state = x with set_current_state(x)
108 * 03.09.1999 0.30 change read semantics for MIDI to match
109 * OSS more closely; remove possible wakeup race
110 * 28.10.1999 0.31 More waitqueue races fixed
111 * 08.01.2000 0.32 Prevent some ioctl's from returning bad count values on underrun/overrun;
112 * Tim Janik's BSE (Bedevilled Sound Engine) found this
113 * 07.02.2000 0.33 Use pci_alloc_consistent and pci_register_driver
114 * 21.11.2000 0.34 Initialize dma buffers in poll, otherwise poll may return a bogus mask
115 * 12.12.2000 0.35 More dma buffer initializations, patch from
116 * Tjeerd Mulder <tjeerd.mulder@fujitsu-siemens.com>
117 * 07.01.2001 0.36 Timeout change in wrcodec as requested by Frank Klemm <pfk@fuchs.offl.uni-jena.de>
118 * 31.01.2001 0.37 Register/Unregister gameport
119 * Fix SETTRIGGER non OSS API conformity
120 * 03.01.2003 0.38 open_mode fixes from Georg Acher <acher@in.tum.de>
121 *
122 * some important things missing in Ensoniq documentation:
123 *
124 * Experimental PCLKDIV results: play the same waveforms on both DAC1 and DAC2
125 * and vary PCLKDIV to obtain zero beat.
126 * 5512sps: 254
127 * 44100sps: 30
128 * seems to be fs = 1411200/(PCLKDIV+2)
129 *
130 * should find out when curr_sample_ct is cleared and
131 * where exactly the CCB fetches data
132 *
133 * The card uses a 22.5792 MHz crystal.
134 * The LINEIN jack may be converted to an AOUT jack by
135 * setting pin 47 (XCTL0) of the ES1370 to high.
136 * Pin 48 (XCTL1) of the ES1370 sets the +5V bias for an electretmic
137 *
138 *
139 */
140
141/*****************************************************************************/
142
143#include <linux/interrupt.h>
144#include <linux/module.h>
145#include <linux/string.h>
146#include <linux/ioport.h>
147#include <linux/sched.h>
148#include <linux/delay.h>
149#include <linux/sound.h>
150#include <linux/slab.h>
151#include <linux/soundcard.h>
152#include <linux/pci.h>
153#include <linux/smp_lock.h>
154#include <linux/init.h>
155#include <linux/poll.h>
156#include <linux/spinlock.h>
157#include <linux/gameport.h>
158#include <linux/wait.h>
159
160#include <asm/io.h>
161#include <asm/page.h>
162#include <asm/uaccess.h>
163
164/* --------------------------------------------------------------------- */
165
166#undef OSS_DOCUMENTED_MIXER_SEMANTICS
167#define DBG(x) {}
168/*#define DBG(x) {x}*/
169
170/* --------------------------------------------------------------------- */
171
172#ifndef PCI_VENDOR_ID_ENSONIQ
173#define PCI_VENDOR_ID_ENSONIQ 0x1274
174#endif
175
176#ifndef PCI_DEVICE_ID_ENSONIQ_ES1370
177#define PCI_DEVICE_ID_ENSONIQ_ES1370 0x5000
178#endif
179
180#define ES1370_MAGIC ((PCI_VENDOR_ID_ENSONIQ<<16)|PCI_DEVICE_ID_ENSONIQ_ES1370)
181
182#define ES1370_EXTENT 0x40
183#define JOY_EXTENT 8
184
185#define ES1370_REG_CONTROL 0x00
186#define ES1370_REG_STATUS 0x04
187#define ES1370_REG_UART_DATA 0x08
188#define ES1370_REG_UART_STATUS 0x09
189#define ES1370_REG_UART_CONTROL 0x09
190#define ES1370_REG_UART_TEST 0x0a
191#define ES1370_REG_MEMPAGE 0x0c
192#define ES1370_REG_CODEC 0x10
193#define ES1370_REG_SERIAL_CONTROL 0x20
194#define ES1370_REG_DAC1_SCOUNT 0x24
195#define ES1370_REG_DAC2_SCOUNT 0x28
196#define ES1370_REG_ADC_SCOUNT 0x2c
197
198#define ES1370_REG_DAC1_FRAMEADR 0xc30
199#define ES1370_REG_DAC1_FRAMECNT 0xc34
200#define ES1370_REG_DAC2_FRAMEADR 0xc38
201#define ES1370_REG_DAC2_FRAMECNT 0xc3c
202#define ES1370_REG_ADC_FRAMEADR 0xd30
203#define ES1370_REG_ADC_FRAMECNT 0xd34
204#define ES1370_REG_PHANTOM_FRAMEADR 0xd38
205#define ES1370_REG_PHANTOM_FRAMECNT 0xd3c
206
207#define ES1370_FMT_U8_MONO 0
208#define ES1370_FMT_U8_STEREO 1
209#define ES1370_FMT_S16_MONO 2
210#define ES1370_FMT_S16_STEREO 3
211#define ES1370_FMT_STEREO 1
212#define ES1370_FMT_S16 2
213#define ES1370_FMT_MASK 3
214
215static const unsigned sample_size[] = { 1, 2, 2, 4 };
216static const unsigned sample_shift[] = { 0, 1, 1, 2 };
217
218static const unsigned dac1_samplerate[] = { 5512, 11025, 22050, 44100 };
219
220#define DAC2_SRTODIV(x) (((1411200+(x)/2)/(x))-2)
221#define DAC2_DIVTOSR(x) (1411200/((x)+2))
222
223#define CTRL_ADC_STOP 0x80000000 /* 1 = ADC stopped */
224#define CTRL_XCTL1 0x40000000 /* electret mic bias */
225#define CTRL_OPEN 0x20000000 /* no function, can be read and written */
226#define CTRL_PCLKDIV 0x1fff0000 /* ADC/DAC2 clock divider */
227#define CTRL_SH_PCLKDIV 16
228#define CTRL_MSFMTSEL 0x00008000 /* MPEG serial data fmt: 0 = Sony, 1 = I2S */
229#define CTRL_M_SBB 0x00004000 /* DAC2 clock: 0 = PCLKDIV, 1 = MPEG */
230#define CTRL_WTSRSEL 0x00003000 /* DAC1 clock freq: 0=5512, 1=11025, 2=22050, 3=44100 */
231#define CTRL_SH_WTSRSEL 12
232#define CTRL_DAC_SYNC 0x00000800 /* 1 = DAC2 runs off DAC1 clock */
233#define CTRL_CCB_INTRM 0x00000400 /* 1 = CCB "voice" ints enabled */
234#define CTRL_M_CB 0x00000200 /* recording source: 0 = ADC, 1 = MPEG */
235#define CTRL_XCTL0 0x00000100 /* 0 = Line in, 1 = Line out */
236#define CTRL_BREQ 0x00000080 /* 1 = test mode (internal mem test) */
237#define CTRL_DAC1_EN 0x00000040 /* enable DAC1 */
238#define CTRL_DAC2_EN 0x00000020 /* enable DAC2 */
239#define CTRL_ADC_EN 0x00000010 /* enable ADC */
240#define CTRL_UART_EN 0x00000008 /* enable MIDI uart */
241#define CTRL_JYSTK_EN 0x00000004 /* enable Joystick port (presumably at address 0x200) */
242#define CTRL_CDC_EN 0x00000002 /* enable serial (CODEC) interface */
243#define CTRL_SERR_DIS 0x00000001 /* 1 = disable PCI SERR signal */
244
245#define STAT_INTR 0x80000000 /* wired or of all interrupt bits */
246#define STAT_CSTAT 0x00000400 /* 1 = codec busy or codec write in progress */
247#define STAT_CBUSY 0x00000200 /* 1 = codec busy */
248#define STAT_CWRIP 0x00000100 /* 1 = codec write in progress */
249#define STAT_VC 0x00000060 /* CCB int source, 0=DAC1, 1=DAC2, 2=ADC, 3=undef */
250#define STAT_SH_VC 5
251#define STAT_MCCB 0x00000010 /* CCB int pending */
252#define STAT_UART 0x00000008 /* UART int pending */
253#define STAT_DAC1 0x00000004 /* DAC1 int pending */
254#define STAT_DAC2 0x00000002 /* DAC2 int pending */
255#define STAT_ADC 0x00000001 /* ADC int pending */
256
257#define USTAT_RXINT 0x80 /* UART rx int pending */
258#define USTAT_TXINT 0x04 /* UART tx int pending */
259#define USTAT_TXRDY 0x02 /* UART tx ready */
260#define USTAT_RXRDY 0x01 /* UART rx ready */
261
262#define UCTRL_RXINTEN 0x80 /* 1 = enable RX ints */
263#define UCTRL_TXINTEN 0x60 /* TX int enable field mask */
264#define UCTRL_ENA_TXINT 0x20 /* enable TX int */
265#define UCTRL_CNTRL 0x03 /* control field */
266#define UCTRL_CNTRL_SWR 0x03 /* software reset command */
267
268#define SCTRL_P2ENDINC 0x00380000 /* */
269#define SCTRL_SH_P2ENDINC 19
270#define SCTRL_P2STINC 0x00070000 /* */
271#define SCTRL_SH_P2STINC 16
272#define SCTRL_R1LOOPSEL 0x00008000 /* 0 = loop mode */
273#define SCTRL_P2LOOPSEL 0x00004000 /* 0 = loop mode */
274#define SCTRL_P1LOOPSEL 0x00002000 /* 0 = loop mode */
275#define SCTRL_P2PAUSE 0x00001000 /* 1 = pause mode */
276#define SCTRL_P1PAUSE 0x00000800 /* 1 = pause mode */
277#define SCTRL_R1INTEN 0x00000400 /* enable interrupt */
278#define SCTRL_P2INTEN 0x00000200 /* enable interrupt */
279#define SCTRL_P1INTEN 0x00000100 /* enable interrupt */
280#define SCTRL_P1SCTRLD 0x00000080 /* reload sample count register for DAC1 */
281#define SCTRL_P2DACSEN 0x00000040 /* 1 = DAC2 play back last sample when disabled */
282#define SCTRL_R1SEB 0x00000020 /* 1 = 16bit */
283#define SCTRL_R1SMB 0x00000010 /* 1 = stereo */
284#define SCTRL_R1FMT 0x00000030 /* format mask */
285#define SCTRL_SH_R1FMT 4
286#define SCTRL_P2SEB 0x00000008 /* 1 = 16bit */
287#define SCTRL_P2SMB 0x00000004 /* 1 = stereo */
288#define SCTRL_P2FMT 0x0000000c /* format mask */
289#define SCTRL_SH_P2FMT 2
290#define SCTRL_P1SEB 0x00000002 /* 1 = 16bit */
291#define SCTRL_P1SMB 0x00000001 /* 1 = stereo */
292#define SCTRL_P1FMT 0x00000003 /* format mask */
293#define SCTRL_SH_P1FMT 0
294
295/* misc stuff */
296
297#define FMODE_DAC 4 /* slight misuse of mode_t */
298
299/* MIDI buffer sizes */
300
301#define MIDIINBUF 256
302#define MIDIOUTBUF 256
303
304#define FMODE_MIDI_SHIFT 3
305#define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
306#define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
307
308/* --------------------------------------------------------------------- */
309
310struct es1370_state {
311 /* magic */
312 unsigned int magic;
313
314 /* list of es1370 devices */
315 struct list_head devs;
316
317 /* the corresponding pci_dev structure */
318 struct pci_dev *dev;
319
320 /* soundcore stuff */
321 int dev_audio;
322 int dev_mixer;
323 int dev_dac;
324 int dev_midi;
325
326 /* hardware resources */
327 unsigned long io; /* long for SPARC */
328 unsigned int irq;
329
330 /* mixer registers; there is no HW readback */
331 struct {
332 unsigned short vol[10];
333 unsigned int recsrc;
334 unsigned int modcnt;
335 unsigned short micpreamp;
336 unsigned int imix;
337 } mix;
338
339 /* wave stuff */
340 unsigned ctrl;
341 unsigned sctrl;
342
343 spinlock_t lock;
344 struct semaphore open_sem;
345 mode_t open_mode;
346 wait_queue_head_t open_wait;
347
348 struct dmabuf {
349 void *rawbuf;
350 dma_addr_t dmaaddr;
351 unsigned buforder;
352 unsigned numfrag;
353 unsigned fragshift;
354 unsigned hwptr, swptr;
355 unsigned total_bytes;
356 int count;
357 unsigned error; /* over/underrun */
358 wait_queue_head_t wait;
359 /* redundant, but makes calculations easier */
360 unsigned fragsize;
361 unsigned dmasize;
362 unsigned fragsamples;
363 /* OSS stuff */
364 unsigned mapped:1;
365 unsigned ready:1;
366 unsigned endcleared:1;
367 unsigned enabled:1;
368 unsigned ossfragshift;
369 int ossmaxfrags;
370 unsigned subdivision;
371 } dma_dac1, dma_dac2, dma_adc;
372
373 /* The following buffer is used to point the phantom write channel to. */
374 unsigned char *bugbuf_cpu;
375 dma_addr_t bugbuf_dma;
376
377 /* midi stuff */
378 struct {
379 unsigned ird, iwr, icnt;
380 unsigned ord, owr, ocnt;
381 wait_queue_head_t iwait;
382 wait_queue_head_t owait;
383 unsigned char ibuf[MIDIINBUF];
384 unsigned char obuf[MIDIOUTBUF];
385 } midi;
386
387 struct gameport *gameport;
388 struct semaphore sem;
389};
390
391/* --------------------------------------------------------------------- */
392
393static LIST_HEAD(devs);
394
395/* --------------------------------------------------------------------- */
396
397static inline unsigned ld2(unsigned int x)
398{
399 unsigned r = 0;
400
401 if (x >= 0x10000) {
402 x >>= 16;
403 r += 16;
404 }
405 if (x >= 0x100) {
406 x >>= 8;
407 r += 8;
408 }
409 if (x >= 0x10) {
410 x >>= 4;
411 r += 4;
412 }
413 if (x >= 4) {
414 x >>= 2;
415 r += 2;
416 }
417 if (x >= 2)
418 r++;
419 return r;
420}
421
422/* --------------------------------------------------------------------- */
423
424static void wrcodec(struct es1370_state *s, unsigned char idx, unsigned char data)
425{
426 unsigned long tmo = jiffies + HZ/10, j;
427
428 do {
429 j = jiffies;
430 if (!(inl(s->io+ES1370_REG_STATUS) & STAT_CSTAT)) {
431 outw((((unsigned short)idx)<<8)|data, s->io+ES1370_REG_CODEC);
432 return;
433 }
434 schedule();
435 } while ((signed)(tmo-j) > 0);
436 printk(KERN_ERR "es1370: write to codec register timeout\n");
437}
438
439/* --------------------------------------------------------------------- */
440
441static inline void stop_adc(struct es1370_state *s)
442{
443 unsigned long flags;
444
445 spin_lock_irqsave(&s->lock, flags);
446 s->ctrl &= ~CTRL_ADC_EN;
447 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
448 spin_unlock_irqrestore(&s->lock, flags);
449}
450
451static inline void stop_dac1(struct es1370_state *s)
452{
453 unsigned long flags;
454
455 spin_lock_irqsave(&s->lock, flags);
456 s->ctrl &= ~CTRL_DAC1_EN;
457 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
458 spin_unlock_irqrestore(&s->lock, flags);
459}
460
461static inline void stop_dac2(struct es1370_state *s)
462{
463 unsigned long flags;
464
465 spin_lock_irqsave(&s->lock, flags);
466 s->ctrl &= ~CTRL_DAC2_EN;
467 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
468 spin_unlock_irqrestore(&s->lock, flags);
469}
470
471static void start_dac1(struct es1370_state *s)
472{
473 unsigned long flags;
474 unsigned fragremain, fshift;
475
476 spin_lock_irqsave(&s->lock, flags);
477 if (!(s->ctrl & CTRL_DAC1_EN) && (s->dma_dac1.mapped || s->dma_dac1.count > 0)
478 && s->dma_dac1.ready) {
479 s->ctrl |= CTRL_DAC1_EN;
480 s->sctrl = (s->sctrl & ~(SCTRL_P1LOOPSEL | SCTRL_P1PAUSE | SCTRL_P1SCTRLD)) | SCTRL_P1INTEN;
481 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
482 fragremain = ((- s->dma_dac1.hwptr) & (s->dma_dac1.fragsize-1));
483 fshift = sample_shift[(s->sctrl & SCTRL_P1FMT) >> SCTRL_SH_P1FMT];
484 if (fragremain < 2*fshift)
485 fragremain = s->dma_dac1.fragsize;
486 outl((fragremain >> fshift) - 1, s->io+ES1370_REG_DAC1_SCOUNT);
487 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
488 outl((s->dma_dac1.fragsize >> fshift) - 1, s->io+ES1370_REG_DAC1_SCOUNT);
489 }
490 spin_unlock_irqrestore(&s->lock, flags);
491}
492
493static void start_dac2(struct es1370_state *s)
494{
495 unsigned long flags;
496 unsigned fragremain, fshift;
497
498 spin_lock_irqsave(&s->lock, flags);
499 if (!(s->ctrl & CTRL_DAC2_EN) && (s->dma_dac2.mapped || s->dma_dac2.count > 0)
500 && s->dma_dac2.ready) {
501 s->ctrl |= CTRL_DAC2_EN;
502 s->sctrl = (s->sctrl & ~(SCTRL_P2LOOPSEL | SCTRL_P2PAUSE | SCTRL_P2DACSEN |
503 SCTRL_P2ENDINC | SCTRL_P2STINC)) | SCTRL_P2INTEN |
504 (((s->sctrl & SCTRL_P2FMT) ? 2 : 1) << SCTRL_SH_P2ENDINC) |
505 (0 << SCTRL_SH_P2STINC);
506 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
507 fragremain = ((- s->dma_dac2.hwptr) & (s->dma_dac2.fragsize-1));
508 fshift = sample_shift[(s->sctrl & SCTRL_P2FMT) >> SCTRL_SH_P2FMT];
509 if (fragremain < 2*fshift)
510 fragremain = s->dma_dac2.fragsize;
511 outl((fragremain >> fshift) - 1, s->io+ES1370_REG_DAC2_SCOUNT);
512 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
513 outl((s->dma_dac2.fragsize >> fshift) - 1, s->io+ES1370_REG_DAC2_SCOUNT);
514 }
515 spin_unlock_irqrestore(&s->lock, flags);
516}
517
518static void start_adc(struct es1370_state *s)
519{
520 unsigned long flags;
521 unsigned fragremain, fshift;
522
523 spin_lock_irqsave(&s->lock, flags);
524 if (!(s->ctrl & CTRL_ADC_EN) && (s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
525 && s->dma_adc.ready) {
526 s->ctrl |= CTRL_ADC_EN;
527 s->sctrl = (s->sctrl & ~SCTRL_R1LOOPSEL) | SCTRL_R1INTEN;
528 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
529 fragremain = ((- s->dma_adc.hwptr) & (s->dma_adc.fragsize-1));
530 fshift = sample_shift[(s->sctrl & SCTRL_R1FMT) >> SCTRL_SH_R1FMT];
531 if (fragremain < 2*fshift)
532 fragremain = s->dma_adc.fragsize;
533 outl((fragremain >> fshift) - 1, s->io+ES1370_REG_ADC_SCOUNT);
534 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
535 outl((s->dma_adc.fragsize >> fshift) - 1, s->io+ES1370_REG_ADC_SCOUNT);
536 }
537 spin_unlock_irqrestore(&s->lock, flags);
538}
539
540/* --------------------------------------------------------------------- */
541
542#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
543#define DMABUF_MINORDER 1
544
545static inline void dealloc_dmabuf(struct es1370_state *s, struct dmabuf *db)
546{
547 struct page *page, *pend;
548
549 if (db->rawbuf) {
550 /* undo marking the pages as reserved */
551 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
552 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
553 ClearPageReserved(page);
554 pci_free_consistent(s->dev, PAGE_SIZE << db->buforder, db->rawbuf, db->dmaaddr);
555 }
556 db->rawbuf = NULL;
557 db->mapped = db->ready = 0;
558}
559
560static int prog_dmabuf(struct es1370_state *s, struct dmabuf *db, unsigned rate, unsigned fmt, unsigned reg)
561{
562 int order;
563 unsigned bytepersec;
564 unsigned bufs;
565 struct page *page, *pend;
566
567 db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
568 if (!db->rawbuf) {
569 db->ready = db->mapped = 0;
570 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--)
571 if ((db->rawbuf = pci_alloc_consistent(s->dev, PAGE_SIZE << order, &db->dmaaddr)))
572 break;
573 if (!db->rawbuf)
574 return -ENOMEM;
575 db->buforder = order;
576 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
577 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
578 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
579 SetPageReserved(page);
580 }
581 fmt &= ES1370_FMT_MASK;
582 bytepersec = rate << sample_shift[fmt];
583 bufs = PAGE_SIZE << db->buforder;
584 if (db->ossfragshift) {
585 if ((1000 << db->ossfragshift) < bytepersec)
586 db->fragshift = ld2(bytepersec/1000);
587 else
588 db->fragshift = db->ossfragshift;
589 } else {
590 db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
591 if (db->fragshift < 3)
592 db->fragshift = 3;
593 }
594 db->numfrag = bufs >> db->fragshift;
595 while (db->numfrag < 4 && db->fragshift > 3) {
596 db->fragshift--;
597 db->numfrag = bufs >> db->fragshift;
598 }
599 db->fragsize = 1 << db->fragshift;
600 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
601 db->numfrag = db->ossmaxfrags;
602 db->fragsamples = db->fragsize >> sample_shift[fmt];
603 db->dmasize = db->numfrag << db->fragshift;
604 memset(db->rawbuf, (fmt & ES1370_FMT_S16) ? 0 : 0x80, db->dmasize);
605 outl((reg >> 8) & 15, s->io+ES1370_REG_MEMPAGE);
606 outl(db->dmaaddr, s->io+(reg & 0xff));
607 outl((db->dmasize >> 2)-1, s->io+((reg + 4) & 0xff));
608 db->enabled = 1;
609 db->ready = 1;
610 return 0;
611}
612
613static inline int prog_dmabuf_adc(struct es1370_state *s)
614{
615 stop_adc(s);
616 return prog_dmabuf(s, &s->dma_adc, DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV),
617 (s->sctrl >> SCTRL_SH_R1FMT) & ES1370_FMT_MASK, ES1370_REG_ADC_FRAMEADR);
618}
619
620static inline int prog_dmabuf_dac2(struct es1370_state *s)
621{
622 stop_dac2(s);
623 return prog_dmabuf(s, &s->dma_dac2, DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV),
624 (s->sctrl >> SCTRL_SH_P2FMT) & ES1370_FMT_MASK, ES1370_REG_DAC2_FRAMEADR);
625}
626
627static inline int prog_dmabuf_dac1(struct es1370_state *s)
628{
629 stop_dac1(s);
630 return prog_dmabuf(s, &s->dma_dac1, dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL],
631 (s->sctrl >> SCTRL_SH_P1FMT) & ES1370_FMT_MASK, ES1370_REG_DAC1_FRAMEADR);
632}
633
634static inline unsigned get_hwptr(struct es1370_state *s, struct dmabuf *db, unsigned reg)
635{
636 unsigned hwptr, diff;
637
638 outl((reg >> 8) & 15, s->io+ES1370_REG_MEMPAGE);
639 hwptr = (inl(s->io+(reg & 0xff)) >> 14) & 0x3fffc;
640 diff = (db->dmasize + hwptr - db->hwptr) % db->dmasize;
641 db->hwptr = hwptr;
642 return diff;
643}
644
645static inline void clear_advance(void *buf, unsigned bsize, unsigned bptr, unsigned len, unsigned char c)
646{
647 if (bptr + len > bsize) {
648 unsigned x = bsize - bptr;
649 memset(((char *)buf) + bptr, c, x);
650 bptr = 0;
651 len -= x;
652 }
653 memset(((char *)buf) + bptr, c, len);
654}
655
656/* call with spinlock held! */
657static void es1370_update_ptr(struct es1370_state *s)
658{
659 int diff;
660
661 /* update ADC pointer */
662 if (s->ctrl & CTRL_ADC_EN) {
663 diff = get_hwptr(s, &s->dma_adc, ES1370_REG_ADC_FRAMECNT);
664 s->dma_adc.total_bytes += diff;
665 s->dma_adc.count += diff;
666 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
667 wake_up(&s->dma_adc.wait);
668 if (!s->dma_adc.mapped) {
669 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
670 s->ctrl &= ~CTRL_ADC_EN;
671 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
672 s->dma_adc.error++;
673 }
674 }
675 }
676 /* update DAC1 pointer */
677 if (s->ctrl & CTRL_DAC1_EN) {
678 diff = get_hwptr(s, &s->dma_dac1, ES1370_REG_DAC1_FRAMECNT);
679 s->dma_dac1.total_bytes += diff;
680 if (s->dma_dac1.mapped) {
681 s->dma_dac1.count += diff;
682 if (s->dma_dac1.count >= (signed)s->dma_dac1.fragsize)
683 wake_up(&s->dma_dac1.wait);
684 } else {
685 s->dma_dac1.count -= diff;
686 if (s->dma_dac1.count <= 0) {
687 s->ctrl &= ~CTRL_DAC1_EN;
688 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
689 s->dma_dac1.error++;
690 } else if (s->dma_dac1.count <= (signed)s->dma_dac1.fragsize && !s->dma_dac1.endcleared) {
691 clear_advance(s->dma_dac1.rawbuf, s->dma_dac1.dmasize, s->dma_dac1.swptr,
692 s->dma_dac1.fragsize, (s->sctrl & SCTRL_P1SEB) ? 0 : 0x80);
693 s->dma_dac1.endcleared = 1;
694 }
695 if (s->dma_dac1.count + (signed)s->dma_dac1.fragsize <= (signed)s->dma_dac1.dmasize)
696 wake_up(&s->dma_dac1.wait);
697 }
698 }
699 /* update DAC2 pointer */
700 if (s->ctrl & CTRL_DAC2_EN) {
701 diff = get_hwptr(s, &s->dma_dac2, ES1370_REG_DAC2_FRAMECNT);
702 s->dma_dac2.total_bytes += diff;
703 if (s->dma_dac2.mapped) {
704 s->dma_dac2.count += diff;
705 if (s->dma_dac2.count >= (signed)s->dma_dac2.fragsize)
706 wake_up(&s->dma_dac2.wait);
707 } else {
708 s->dma_dac2.count -= diff;
709 if (s->dma_dac2.count <= 0) {
710 s->ctrl &= ~CTRL_DAC2_EN;
711 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
712 s->dma_dac2.error++;
713 } else if (s->dma_dac2.count <= (signed)s->dma_dac2.fragsize && !s->dma_dac2.endcleared) {
714 clear_advance(s->dma_dac2.rawbuf, s->dma_dac2.dmasize, s->dma_dac2.swptr,
715 s->dma_dac2.fragsize, (s->sctrl & SCTRL_P2SEB) ? 0 : 0x80);
716 s->dma_dac2.endcleared = 1;
717 }
718 if (s->dma_dac2.count + (signed)s->dma_dac2.fragsize <= (signed)s->dma_dac2.dmasize)
719 wake_up(&s->dma_dac2.wait);
720 }
721 }
722}
723
724/* hold spinlock for the following! */
725static void es1370_handle_midi(struct es1370_state *s)
726{
727 unsigned char ch;
728 int wake;
729
730 if (!(s->ctrl & CTRL_UART_EN))
731 return;
732 wake = 0;
733 while (inb(s->io+ES1370_REG_UART_STATUS) & USTAT_RXRDY) {
734 ch = inb(s->io+ES1370_REG_UART_DATA);
735 if (s->midi.icnt < MIDIINBUF) {
736 s->midi.ibuf[s->midi.iwr] = ch;
737 s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF;
738 s->midi.icnt++;
739 }
740 wake = 1;
741 }
742 if (wake)
743 wake_up(&s->midi.iwait);
744 wake = 0;
745 while ((inb(s->io+ES1370_REG_UART_STATUS) & USTAT_TXRDY) && s->midi.ocnt > 0) {
746 outb(s->midi.obuf[s->midi.ord], s->io+ES1370_REG_UART_DATA);
747 s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF;
748 s->midi.ocnt--;
749 if (s->midi.ocnt < MIDIOUTBUF-16)
750 wake = 1;
751 }
752 if (wake)
753 wake_up(&s->midi.owait);
754 outb((s->midi.ocnt > 0) ? UCTRL_RXINTEN | UCTRL_ENA_TXINT : UCTRL_RXINTEN, s->io+ES1370_REG_UART_CONTROL);
755}
756
757static irqreturn_t es1370_interrupt(int irq, void *dev_id, struct pt_regs *regs)
758{
759 struct es1370_state *s = (struct es1370_state *)dev_id;
760 unsigned int intsrc, sctl;
761
762 /* fastpath out, to ease interrupt sharing */
763 intsrc = inl(s->io+ES1370_REG_STATUS);
764 if (!(intsrc & 0x80000000))
765 return IRQ_NONE;
766 spin_lock(&s->lock);
767 /* clear audio interrupts first */
768 sctl = s->sctrl;
769 if (intsrc & STAT_ADC)
770 sctl &= ~SCTRL_R1INTEN;
771 if (intsrc & STAT_DAC1)
772 sctl &= ~SCTRL_P1INTEN;
773 if (intsrc & STAT_DAC2)
774 sctl &= ~SCTRL_P2INTEN;
775 outl(sctl, s->io+ES1370_REG_SERIAL_CONTROL);
776 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
777 es1370_update_ptr(s);
778 es1370_handle_midi(s);
779 spin_unlock(&s->lock);
780 return IRQ_HANDLED;
781}
782
783/* --------------------------------------------------------------------- */
784
785static const char invalid_magic[] = KERN_CRIT "es1370: invalid magic value\n";
786
787#define VALIDATE_STATE(s) \
788({ \
789 if (!(s) || (s)->magic != ES1370_MAGIC) { \
790 printk(invalid_magic); \
791 return -ENXIO; \
792 } \
793})
794
795/* --------------------------------------------------------------------- */
796
797static const struct {
798 unsigned volidx:4;
799 unsigned left:4;
800 unsigned right:4;
801 unsigned stereo:1;
802 unsigned recmask:13;
803 unsigned avail:1;
804} mixtable[SOUND_MIXER_NRDEVICES] = {
805 [SOUND_MIXER_VOLUME] = { 0, 0x0, 0x1, 1, 0x0000, 1 }, /* master */
806 [SOUND_MIXER_PCM] = { 1, 0x2, 0x3, 1, 0x0400, 1 }, /* voice */
807 [SOUND_MIXER_SYNTH] = { 2, 0x4, 0x5, 1, 0x0060, 1 }, /* FM */
808 [SOUND_MIXER_CD] = { 3, 0x6, 0x7, 1, 0x0006, 1 }, /* CD */
809 [SOUND_MIXER_LINE] = { 4, 0x8, 0x9, 1, 0x0018, 1 }, /* Line */
810 [SOUND_MIXER_LINE1] = { 5, 0xa, 0xb, 1, 0x1800, 1 }, /* AUX */
811 [SOUND_MIXER_LINE2] = { 6, 0xc, 0x0, 0, 0x0100, 1 }, /* Mono1 */
812 [SOUND_MIXER_LINE3] = { 7, 0xd, 0x0, 0, 0x0200, 1 }, /* Mono2 */
813 [SOUND_MIXER_MIC] = { 8, 0xe, 0x0, 0, 0x0001, 1 }, /* Mic */
814 [SOUND_MIXER_OGAIN] = { 9, 0xf, 0x0, 0, 0x0000, 1 } /* mono out */
815};
816
817static void set_recsrc(struct es1370_state *s, unsigned int val)
818{
819 unsigned int i, j;
820
821 for (j = i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
822 if (!(val & (1 << i)))
823 continue;
824 if (!mixtable[i].recmask) {
825 val &= ~(1 << i);
826 continue;
827 }
828 j |= mixtable[i].recmask;
829 }
830 s->mix.recsrc = val;
831 wrcodec(s, 0x12, j & 0xd5);
832 wrcodec(s, 0x13, j & 0xaa);
833 wrcodec(s, 0x14, (j >> 8) & 0x17);
834 wrcodec(s, 0x15, (j >> 8) & 0x0f);
835 i = (j & 0x37f) | ((j << 1) & 0x3000) | 0xc60;
836 if (!s->mix.imix) {
837 i &= 0xff60; /* mute record and line monitor */
838 }
839 wrcodec(s, 0x10, i);
840 wrcodec(s, 0x11, i >> 8);
841}
842
843static int mixer_ioctl(struct es1370_state *s, unsigned int cmd, unsigned long arg)
844{
845 unsigned long flags;
846 int i, val;
847 unsigned char l, r, rl, rr;
848 int __user *p = (int __user *)arg;
849
850 VALIDATE_STATE(s);
851 if (cmd == SOUND_MIXER_PRIVATE1) {
852 /* enable/disable/query mixer preamp */
853 if (get_user(val, p))
854 return -EFAULT;
855 if (val != -1) {
856 s->mix.micpreamp = !!val;
857 wrcodec(s, 0x19, s->mix.micpreamp);
858 }
859 return put_user(s->mix.micpreamp, p);
860 }
861 if (cmd == SOUND_MIXER_PRIVATE2) {
862 /* enable/disable/query use of linein as second lineout */
863 if (get_user(val, p))
864 return -EFAULT;
865 if (val != -1) {
866 spin_lock_irqsave(&s->lock, flags);
867 if (val)
868 s->ctrl |= CTRL_XCTL0;
869 else
870 s->ctrl &= ~CTRL_XCTL0;
871 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
872 spin_unlock_irqrestore(&s->lock, flags);
873 }
874 return put_user((s->ctrl & CTRL_XCTL0) ? 1 : 0, p);
875 }
876 if (cmd == SOUND_MIXER_PRIVATE3) {
877 /* enable/disable/query microphone impedance setting */
878 if (get_user(val, p))
879 return -EFAULT;
880 if (val != -1) {
881 spin_lock_irqsave(&s->lock, flags);
882 if (val)
883 s->ctrl |= CTRL_XCTL1;
884 else
885 s->ctrl &= ~CTRL_XCTL1;
886 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
887 spin_unlock_irqrestore(&s->lock, flags);
888 }
889 return put_user((s->ctrl & CTRL_XCTL1) ? 1 : 0, p);
890 }
891 if (cmd == SOUND_MIXER_INFO) {
892 mixer_info info;
893 strncpy(info.id, "ES1370", sizeof(info.id));
894 strncpy(info.name, "Ensoniq ES1370", sizeof(info.name));
895 info.modify_counter = s->mix.modcnt;
896 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
897 return -EFAULT;
898 return 0;
899 }
900 if (cmd == SOUND_OLD_MIXER_INFO) {
901 _old_mixer_info info;
902 strncpy(info.id, "ES1370", sizeof(info.id));
903 strncpy(info.name, "Ensoniq ES1370", sizeof(info.name));
904 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
905 return -EFAULT;
906 return 0;
907 }
908 if (cmd == OSS_GETVERSION)
909 return put_user(SOUND_VERSION, p);
910 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
911 return -EINVAL;
912 if (_SIOC_DIR(cmd) == _SIOC_READ) {
913 switch (_IOC_NR(cmd)) {
914 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
915 return put_user(s->mix.recsrc, p);
916
917 case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
918 val = SOUND_MASK_IMIX;
919 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
920 if (mixtable[i].avail)
921 val |= 1 << i;
922 return put_user(val, p);
923
924 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
925 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
926 if (mixtable[i].recmask)
927 val |= 1 << i;
928 return put_user(val, p);
929
930 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
931 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
932 if (mixtable[i].stereo)
933 val |= 1 << i;
934 return put_user(val, p);
935
936 case SOUND_MIXER_CAPS:
937 return put_user(0, p);
938
939 case SOUND_MIXER_IMIX:
940 return put_user(s->mix.imix, p);
941
942 default:
943 i = _IOC_NR(cmd);
944 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].avail)
945 return -EINVAL;
946 return put_user(s->mix.vol[mixtable[i].volidx], p);
947 }
948 }
949 if (_SIOC_DIR(cmd) != (_SIOC_READ|_SIOC_WRITE))
950 return -EINVAL;
951 s->mix.modcnt++;
952 switch (_IOC_NR(cmd)) {
953
954 case SOUND_MIXER_IMIX:
955 if (get_user(s->mix.imix, p))
956 return -EFAULT;
957 set_recsrc(s, s->mix.recsrc);
958 return 0;
959
960 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
961 if (get_user(val, p))
962 return -EFAULT;
963 set_recsrc(s, val);
964 return 0;
965
966 default:
967 i = _IOC_NR(cmd);
968 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].avail)
969 return -EINVAL;
970 if (get_user(val, p))
971 return -EFAULT;
972 l = val & 0xff;
973 if (l > 100)
974 l = 100;
975 if (mixtable[i].stereo) {
976 r = (val >> 8) & 0xff;
977 if (r > 100)
978 r = 100;
979 if (l < 7) {
980 rl = 0x80;
981 l = 0;
982 } else {
983 rl = 31 - ((l - 7) / 3);
984 l = (31 - rl) * 3 + 7;
985 }
986 if (r < 7) {
987 rr = 0x80;
988 r = 0;
989 } else {
990 rr = 31 - ((r - 7) / 3);
991 r = (31 - rr) * 3 + 7;
992 }
993 wrcodec(s, mixtable[i].right, rr);
994 } else {
995 if (mixtable[i].left == 15) {
996 if (l < 2) {
997 rr = rl = 0x80;
998 r = l = 0;
999 } else {
1000 rl = 7 - ((l - 2) / 14);
1001 r = l = (7 - rl) * 14 + 2;
1002 }
1003 } else {
1004 if (l < 7) {
1005 rl = 0x80;
1006 r = l = 0;
1007 } else {
1008 rl = 31 - ((l - 7) / 3);
1009 r = l = (31 - rl) * 3 + 7;
1010 }
1011 }
1012 }
1013 wrcodec(s, mixtable[i].left, rl);
1014#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1015 s->mix.vol[mixtable[i].volidx] = ((unsigned int)r << 8) | l;
1016#else
1017 s->mix.vol[mixtable[i].volidx] = val;
1018#endif
1019 return put_user(s->mix.vol[mixtable[i].volidx], p);
1020 }
1021}
1022
1023/* --------------------------------------------------------------------- */
1024
1025static int es1370_open_mixdev(struct inode *inode, struct file *file)
1026{
1027 unsigned int minor = iminor(inode);
1028 struct list_head *list;
1029 struct es1370_state *s;
1030
1031 for (list = devs.next; ; list = list->next) {
1032 if (list == &devs)
1033 return -ENODEV;
1034 s = list_entry(list, struct es1370_state, devs);
1035 if (s->dev_mixer == minor)
1036 break;
1037 }
1038 VALIDATE_STATE(s);
1039 file->private_data = s;
1040 return nonseekable_open(inode, file);
1041}
1042
1043static int es1370_release_mixdev(struct inode *inode, struct file *file)
1044{
1045 struct es1370_state *s = (struct es1370_state *)file->private_data;
1046
1047 VALIDATE_STATE(s);
1048 return 0;
1049}
1050
1051static int es1370_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1052{
1053 return mixer_ioctl((struct es1370_state *)file->private_data, cmd, arg);
1054}
1055
1056static /*const*/ struct file_operations es1370_mixer_fops = {
1057 .owner = THIS_MODULE,
1058 .llseek = no_llseek,
1059 .ioctl = es1370_ioctl_mixdev,
1060 .open = es1370_open_mixdev,
1061 .release = es1370_release_mixdev,
1062};
1063
1064/* --------------------------------------------------------------------- */
1065
1066static int drain_dac1(struct es1370_state *s, int nonblock)
1067{
1068 DECLARE_WAITQUEUE(wait, current);
1069 unsigned long flags;
1070 int count, tmo;
1071
1072 if (s->dma_dac1.mapped || !s->dma_dac1.ready)
1073 return 0;
1074 add_wait_queue(&s->dma_dac1.wait, &wait);
1075 for (;;) {
1076 __set_current_state(TASK_INTERRUPTIBLE);
1077 spin_lock_irqsave(&s->lock, flags);
1078 count = s->dma_dac1.count;
1079 spin_unlock_irqrestore(&s->lock, flags);
1080 if (count <= 0)
1081 break;
1082 if (signal_pending(current))
1083 break;
1084 if (nonblock) {
1085 remove_wait_queue(&s->dma_dac1.wait, &wait);
1086 set_current_state(TASK_RUNNING);
1087 return -EBUSY;
1088 }
1089 tmo = 3 * HZ * (count + s->dma_dac1.fragsize) / 2
1090 / dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL];
1091 tmo >>= sample_shift[(s->sctrl & SCTRL_P1FMT) >> SCTRL_SH_P1FMT];
1092 if (!schedule_timeout(tmo + 1))
1093 DBG(printk(KERN_DEBUG "es1370: dma timed out??\n");)
1094 }
1095 remove_wait_queue(&s->dma_dac1.wait, &wait);
1096 set_current_state(TASK_RUNNING);
1097 if (signal_pending(current))
1098 return -ERESTARTSYS;
1099 return 0;
1100}
1101
1102static int drain_dac2(struct es1370_state *s, int nonblock)
1103{
1104 DECLARE_WAITQUEUE(wait, current);
1105 unsigned long flags;
1106 int count, tmo;
1107
1108 if (s->dma_dac2.mapped || !s->dma_dac2.ready)
1109 return 0;
1110 add_wait_queue(&s->dma_dac2.wait, &wait);
1111 for (;;) {
1112 __set_current_state(TASK_INTERRUPTIBLE);
1113 spin_lock_irqsave(&s->lock, flags);
1114 count = s->dma_dac2.count;
1115 spin_unlock_irqrestore(&s->lock, flags);
1116 if (count <= 0)
1117 break;
1118 if (signal_pending(current))
1119 break;
1120 if (nonblock) {
1121 remove_wait_queue(&s->dma_dac2.wait, &wait);
1122 set_current_state(TASK_RUNNING);
1123 return -EBUSY;
1124 }
1125 tmo = 3 * HZ * (count + s->dma_dac2.fragsize) / 2
1126 / DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV);
1127 tmo >>= sample_shift[(s->sctrl & SCTRL_P2FMT) >> SCTRL_SH_P2FMT];
1128 if (!schedule_timeout(tmo + 1))
1129 DBG(printk(KERN_DEBUG "es1370: dma timed out??\n");)
1130 }
1131 remove_wait_queue(&s->dma_dac2.wait, &wait);
1132 set_current_state(TASK_RUNNING);
1133 if (signal_pending(current))
1134 return -ERESTARTSYS;
1135 return 0;
1136}
1137
1138/* --------------------------------------------------------------------- */
1139
1140static ssize_t es1370_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1141{
1142 struct es1370_state *s = (struct es1370_state *)file->private_data;
1143 DECLARE_WAITQUEUE(wait, current);
1144 ssize_t ret = 0;
1145 unsigned long flags;
1146 unsigned swptr;
1147 int cnt;
1148
1149 VALIDATE_STATE(s);
1150 if (s->dma_adc.mapped)
1151 return -ENXIO;
1152 if (!access_ok(VERIFY_WRITE, buffer, count))
1153 return -EFAULT;
1154 down(&s->sem);
1155 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1156 goto out;
1157
1158 add_wait_queue(&s->dma_adc.wait, &wait);
1159 while (count > 0) {
1160 spin_lock_irqsave(&s->lock, flags);
1161 swptr = s->dma_adc.swptr;
1162 cnt = s->dma_adc.dmasize-swptr;
1163 if (s->dma_adc.count < cnt)
1164 cnt = s->dma_adc.count;
1165 if (cnt <= 0)
1166 __set_current_state(TASK_INTERRUPTIBLE);
1167 spin_unlock_irqrestore(&s->lock, flags);
1168 if (cnt > count)
1169 cnt = count;
1170 if (cnt <= 0) {
1171 if (s->dma_adc.enabled)
1172 start_adc(s);
1173 if (file->f_flags & O_NONBLOCK) {
1174 if (!ret)
1175 ret = -EAGAIN;
1176 goto out;
1177 }
1178 up(&s->sem);
1179 schedule();
1180 if (signal_pending(current)) {
1181 if (!ret)
1182 ret = -ERESTARTSYS;
1183 goto out;
1184 }
1185 down(&s->sem);
1186 if (s->dma_adc.mapped)
1187 {
1188 ret = -ENXIO;
1189 goto out;
1190 }
1191 continue;
1192 }
1193 if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
1194 if (!ret)
1195 ret = -EFAULT;
1196 goto out;
1197 }
1198 swptr = (swptr + cnt) % s->dma_adc.dmasize;
1199 spin_lock_irqsave(&s->lock, flags);
1200 s->dma_adc.swptr = swptr;
1201 s->dma_adc.count -= cnt;
1202 spin_unlock_irqrestore(&s->lock, flags);
1203 count -= cnt;
1204 buffer += cnt;
1205 ret += cnt;
1206 if (s->dma_adc.enabled)
1207 start_adc(s);
1208 }
1209out:
1210 up(&s->sem);
1211 remove_wait_queue(&s->dma_adc.wait, &wait);
1212 set_current_state(TASK_RUNNING);
1213 return ret;
1214}
1215
1216static ssize_t es1370_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1217{
1218 struct es1370_state *s = (struct es1370_state *)file->private_data;
1219 DECLARE_WAITQUEUE(wait, current);
1220 ssize_t ret = 0;
1221 unsigned long flags;
1222 unsigned swptr;
1223 int cnt;
1224
1225 VALIDATE_STATE(s);
1226 if (s->dma_dac2.mapped)
1227 return -ENXIO;
1228 if (!access_ok(VERIFY_READ, buffer, count))
1229 return -EFAULT;
1230 down(&s->sem);
1231 if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
1232 goto out;
1233 ret = 0;
1234 add_wait_queue(&s->dma_dac2.wait, &wait);
1235 while (count > 0) {
1236 spin_lock_irqsave(&s->lock, flags);
1237 if (s->dma_dac2.count < 0) {
1238 s->dma_dac2.count = 0;
1239 s->dma_dac2.swptr = s->dma_dac2.hwptr;
1240 }
1241 swptr = s->dma_dac2.swptr;
1242 cnt = s->dma_dac2.dmasize-swptr;
1243 if (s->dma_dac2.count + cnt > s->dma_dac2.dmasize)
1244 cnt = s->dma_dac2.dmasize - s->dma_dac2.count;
1245 if (cnt <= 0)
1246 __set_current_state(TASK_INTERRUPTIBLE);
1247 spin_unlock_irqrestore(&s->lock, flags);
1248 if (cnt > count)
1249 cnt = count;
1250 if (cnt <= 0) {
1251 if (s->dma_dac2.enabled)
1252 start_dac2(s);
1253 if (file->f_flags & O_NONBLOCK) {
1254 if (!ret)
1255 ret = -EAGAIN;
1256 goto out;
1257 }
1258 up(&s->sem);
1259 schedule();
1260 if (signal_pending(current)) {
1261 if (!ret)
1262 ret = -ERESTARTSYS;
1263 goto out;
1264 }
1265 down(&s->sem);
1266 if (s->dma_dac2.mapped)
1267 {
1268 ret = -ENXIO;
1269 goto out;
1270 }
1271 continue;
1272 }
1273 if (copy_from_user(s->dma_dac2.rawbuf + swptr, buffer, cnt)) {
1274 if (!ret)
1275 ret = -EFAULT;
1276 goto out;
1277 }
1278 swptr = (swptr + cnt) % s->dma_dac2.dmasize;
1279 spin_lock_irqsave(&s->lock, flags);
1280 s->dma_dac2.swptr = swptr;
1281 s->dma_dac2.count += cnt;
1282 s->dma_dac2.endcleared = 0;
1283 spin_unlock_irqrestore(&s->lock, flags);
1284 count -= cnt;
1285 buffer += cnt;
1286 ret += cnt;
1287 if (s->dma_dac2.enabled)
1288 start_dac2(s);
1289 }
1290out:
1291 up(&s->sem);
1292 remove_wait_queue(&s->dma_dac2.wait, &wait);
1293 set_current_state(TASK_RUNNING);
1294 return ret;
1295}
1296
1297/* No kernel lock - we have our own spinlock */
1298static unsigned int es1370_poll(struct file *file, struct poll_table_struct *wait)
1299{
1300 struct es1370_state *s = (struct es1370_state *)file->private_data;
1301 unsigned long flags;
1302 unsigned int mask = 0;
1303
1304 VALIDATE_STATE(s);
1305 if (file->f_mode & FMODE_WRITE) {
1306 if (!s->dma_dac2.ready && prog_dmabuf_dac2(s))
1307 return 0;
1308 poll_wait(file, &s->dma_dac2.wait, wait);
1309 }
1310 if (file->f_mode & FMODE_READ) {
1311 if (!s->dma_adc.ready && prog_dmabuf_adc(s))
1312 return 0;
1313 poll_wait(file, &s->dma_adc.wait, wait);
1314 }
1315 spin_lock_irqsave(&s->lock, flags);
1316 es1370_update_ptr(s);
1317 if (file->f_mode & FMODE_READ) {
1318 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1319 mask |= POLLIN | POLLRDNORM;
1320 }
1321 if (file->f_mode & FMODE_WRITE) {
1322 if (s->dma_dac2.mapped) {
1323 if (s->dma_dac2.count >= (signed)s->dma_dac2.fragsize)
1324 mask |= POLLOUT | POLLWRNORM;
1325 } else {
1326 if ((signed)s->dma_dac2.dmasize >= s->dma_dac2.count + (signed)s->dma_dac2.fragsize)
1327 mask |= POLLOUT | POLLWRNORM;
1328 }
1329 }
1330 spin_unlock_irqrestore(&s->lock, flags);
1331 return mask;
1332}
1333
1334static int es1370_mmap(struct file *file, struct vm_area_struct *vma)
1335{
1336 struct es1370_state *s = (struct es1370_state *)file->private_data;
1337 struct dmabuf *db;
1338 int ret = 0;
1339 unsigned long size;
1340
1341 VALIDATE_STATE(s);
1342 lock_kernel();
1343 down(&s->sem);
1344 if (vma->vm_flags & VM_WRITE) {
1345 if ((ret = prog_dmabuf_dac2(s)) != 0) {
1346 goto out;
1347 }
1348 db = &s->dma_dac2;
1349 } else if (vma->vm_flags & VM_READ) {
1350 if ((ret = prog_dmabuf_adc(s)) != 0) {
1351 goto out;
1352 }
1353 db = &s->dma_adc;
1354 } else {
1355 ret = -EINVAL;
1356 goto out;
1357 }
1358 if (vma->vm_pgoff != 0) {
1359 ret = -EINVAL;
1360 goto out;
1361 }
1362 size = vma->vm_end - vma->vm_start;
1363 if (size > (PAGE_SIZE << db->buforder)) {
1364 ret = -EINVAL;
1365 goto out;
1366 }
1367 if (remap_pfn_range(vma, vma->vm_start,
1368 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
1369 size, vma->vm_page_prot)) {
1370 ret = -EAGAIN;
1371 goto out;
1372 }
1373 db->mapped = 1;
1374out:
1375 up(&s->sem);
1376 unlock_kernel();
1377 return ret;
1378}
1379
1380static int es1370_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1381{
1382 struct es1370_state *s = (struct es1370_state *)file->private_data;
1383 unsigned long flags;
1384 audio_buf_info abinfo;
1385 count_info cinfo;
1386 int count;
1387 int val, mapped, ret;
1388 void __user *argp = (void __user *)arg;
1389 int __user *p = argp;
1390
1391 VALIDATE_STATE(s);
1392 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac2.mapped) ||
1393 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1394 switch (cmd) {
1395 case OSS_GETVERSION:
1396 return put_user(SOUND_VERSION, p);
1397
1398 case SNDCTL_DSP_SYNC:
1399 if (file->f_mode & FMODE_WRITE)
1400 return drain_dac2(s, 0/*file->f_flags & O_NONBLOCK*/);
1401 return 0;
1402
1403 case SNDCTL_DSP_SETDUPLEX:
1404 return 0;
1405
1406 case SNDCTL_DSP_GETCAPS:
1407 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
1408
1409 case SNDCTL_DSP_RESET:
1410 if (file->f_mode & FMODE_WRITE) {
1411 stop_dac2(s);
1412 synchronize_irq(s->irq);
1413 s->dma_dac2.swptr = s->dma_dac2.hwptr = s->dma_dac2.count = s->dma_dac2.total_bytes = 0;
1414 }
1415 if (file->f_mode & FMODE_READ) {
1416 stop_adc(s);
1417 synchronize_irq(s->irq);
1418 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
1419 }
1420 return 0;
1421
1422 case SNDCTL_DSP_SPEED:
1423 if (get_user(val, p))
1424 return -EFAULT;
1425 if (val >= 0) {
1426 if (s->open_mode & (~file->f_mode) & (FMODE_READ|FMODE_WRITE))
1427 return -EINVAL;
1428 if (val < 4000)
1429 val = 4000;
1430 if (val > 50000)
1431 val = 50000;
1432 stop_adc(s);
1433 stop_dac2(s);
1434 s->dma_adc.ready = s->dma_dac2.ready = 0;
1435 spin_lock_irqsave(&s->lock, flags);
1436 s->ctrl = (s->ctrl & ~CTRL_PCLKDIV) | (DAC2_SRTODIV(val) << CTRL_SH_PCLKDIV);
1437 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
1438 spin_unlock_irqrestore(&s->lock, flags);
1439 }
1440 return put_user(DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), p);
1441
1442 case SNDCTL_DSP_STEREO:
1443 if (get_user(val, p))
1444 return -EFAULT;
1445 if (file->f_mode & FMODE_READ) {
1446 stop_adc(s);
1447 s->dma_adc.ready = 0;
1448 spin_lock_irqsave(&s->lock, flags);
1449 if (val)
1450 s->sctrl |= SCTRL_R1SMB;
1451 else
1452 s->sctrl &= ~SCTRL_R1SMB;
1453 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
1454 spin_unlock_irqrestore(&s->lock, flags);
1455 }
1456 if (file->f_mode & FMODE_WRITE) {
1457 stop_dac2(s);
1458 s->dma_dac2.ready = 0;
1459 spin_lock_irqsave(&s->lock, flags);
1460 if (val)
1461 s->sctrl |= SCTRL_P2SMB;
1462 else
1463 s->sctrl &= ~SCTRL_P2SMB;
1464 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
1465 spin_unlock_irqrestore(&s->lock, flags);
1466 }
1467 return 0;
1468
1469 case SNDCTL_DSP_CHANNELS:
1470 if (get_user(val, p))
1471 return -EFAULT;
1472 if (val != 0) {
1473 if (file->f_mode & FMODE_READ) {
1474 stop_adc(s);
1475 s->dma_adc.ready = 0;
1476 spin_lock_irqsave(&s->lock, flags);
1477 if (val >= 2)
1478 s->sctrl |= SCTRL_R1SMB;
1479 else
1480 s->sctrl &= ~SCTRL_R1SMB;
1481 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
1482 spin_unlock_irqrestore(&s->lock, flags);
1483 }
1484 if (file->f_mode & FMODE_WRITE) {
1485 stop_dac2(s);
1486 s->dma_dac2.ready = 0;
1487 spin_lock_irqsave(&s->lock, flags);
1488 if (val >= 2)
1489 s->sctrl |= SCTRL_P2SMB;
1490 else
1491 s->sctrl &= ~SCTRL_P2SMB;
1492 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
1493 spin_unlock_irqrestore(&s->lock, flags);
1494 }
1495 }
1496 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SMB : SCTRL_P2SMB)) ? 2 : 1, p);
1497
1498 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1499 return put_user(AFMT_S16_LE|AFMT_U8, p);
1500
1501 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1502 if (get_user(val, p))
1503 return -EFAULT;
1504 if (val != AFMT_QUERY) {
1505 if (file->f_mode & FMODE_READ) {
1506 stop_adc(s);
1507 s->dma_adc.ready = 0;
1508 spin_lock_irqsave(&s->lock, flags);
1509 if (val == AFMT_S16_LE)
1510 s->sctrl |= SCTRL_R1SEB;
1511 else
1512 s->sctrl &= ~SCTRL_R1SEB;
1513 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
1514 spin_unlock_irqrestore(&s->lock, flags);
1515 }
1516 if (file->f_mode & FMODE_WRITE) {
1517 stop_dac2(s);
1518 s->dma_dac2.ready = 0;
1519 spin_lock_irqsave(&s->lock, flags);
1520 if (val == AFMT_S16_LE)
1521 s->sctrl |= SCTRL_P2SEB;
1522 else
1523 s->sctrl &= ~SCTRL_P2SEB;
1524 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
1525 spin_unlock_irqrestore(&s->lock, flags);
1526 }
1527 }
1528 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SEB : SCTRL_P2SEB)) ?
1529 AFMT_S16_LE : AFMT_U8, p);
1530
1531 case SNDCTL_DSP_POST:
1532 return 0;
1533
1534 case SNDCTL_DSP_GETTRIGGER:
1535 val = 0;
1536 if (file->f_mode & FMODE_READ && s->ctrl & CTRL_ADC_EN)
1537 val |= PCM_ENABLE_INPUT;
1538 if (file->f_mode & FMODE_WRITE && s->ctrl & CTRL_DAC2_EN)
1539 val |= PCM_ENABLE_OUTPUT;
1540 return put_user(val, p);
1541
1542 case SNDCTL_DSP_SETTRIGGER:
1543 if (get_user(val, p))
1544 return -EFAULT;
1545 if (file->f_mode & FMODE_READ) {
1546 if (val & PCM_ENABLE_INPUT) {
1547 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1548 return ret;
1549 s->dma_adc.enabled = 1;
1550 start_adc(s);
1551 } else {
1552 s->dma_adc.enabled = 0;
1553 stop_adc(s);
1554 }
1555 }
1556 if (file->f_mode & FMODE_WRITE) {
1557 if (val & PCM_ENABLE_OUTPUT) {
1558 if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
1559 return ret;
1560 s->dma_dac2.enabled = 1;
1561 start_dac2(s);
1562 } else {
1563 s->dma_dac2.enabled = 0;
1564 stop_dac2(s);
1565 }
1566 }
1567 return 0;
1568
1569 case SNDCTL_DSP_GETOSPACE:
1570 if (!(file->f_mode & FMODE_WRITE))
1571 return -EINVAL;
1572 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
1573 return val;
1574 spin_lock_irqsave(&s->lock, flags);
1575 es1370_update_ptr(s);
1576 abinfo.fragsize = s->dma_dac2.fragsize;
1577 count = s->dma_dac2.count;
1578 if (count < 0)
1579 count = 0;
1580 abinfo.bytes = s->dma_dac2.dmasize - count;
1581 abinfo.fragstotal = s->dma_dac2.numfrag;
1582 abinfo.fragments = abinfo.bytes >> s->dma_dac2.fragshift;
1583 spin_unlock_irqrestore(&s->lock, flags);
1584 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1585
1586 case SNDCTL_DSP_GETISPACE:
1587 if (!(file->f_mode & FMODE_READ))
1588 return -EINVAL;
1589 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0)
1590 return val;
1591 spin_lock_irqsave(&s->lock, flags);
1592 es1370_update_ptr(s);
1593 abinfo.fragsize = s->dma_adc.fragsize;
1594 count = s->dma_adc.count;
1595 if (count < 0)
1596 count = 0;
1597 abinfo.bytes = count;
1598 abinfo.fragstotal = s->dma_adc.numfrag;
1599 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1600 spin_unlock_irqrestore(&s->lock, flags);
1601 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1602
1603 case SNDCTL_DSP_NONBLOCK:
1604 file->f_flags |= O_NONBLOCK;
1605 return 0;
1606
1607 case SNDCTL_DSP_GETODELAY:
1608 if (!(file->f_mode & FMODE_WRITE))
1609 return -EINVAL;
1610 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
1611 return val;
1612 spin_lock_irqsave(&s->lock, flags);
1613 es1370_update_ptr(s);
1614 count = s->dma_dac2.count;
1615 spin_unlock_irqrestore(&s->lock, flags);
1616 if (count < 0)
1617 count = 0;
1618 return put_user(count, p);
1619
1620 case SNDCTL_DSP_GETIPTR:
1621 if (!(file->f_mode & FMODE_READ))
1622 return -EINVAL;
1623 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0)
1624 return val;
1625 spin_lock_irqsave(&s->lock, flags);
1626 es1370_update_ptr(s);
1627 cinfo.bytes = s->dma_adc.total_bytes;
1628 count = s->dma_adc.count;
1629 if (count < 0)
1630 count = 0;
1631 cinfo.blocks = count >> s->dma_adc.fragshift;
1632 cinfo.ptr = s->dma_adc.hwptr;
1633 if (s->dma_adc.mapped)
1634 s->dma_adc.count &= s->dma_adc.fragsize-1;
1635 spin_unlock_irqrestore(&s->lock, flags);
1636 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1637 return -EFAULT;
1638 return 0;
1639
1640 case SNDCTL_DSP_GETOPTR:
1641 if (!(file->f_mode & FMODE_WRITE))
1642 return -EINVAL;
1643 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
1644 return val;
1645 spin_lock_irqsave(&s->lock, flags);
1646 es1370_update_ptr(s);
1647 cinfo.bytes = s->dma_dac2.total_bytes;
1648 count = s->dma_dac2.count;
1649 if (count < 0)
1650 count = 0;
1651 cinfo.blocks = count >> s->dma_dac2.fragshift;
1652 cinfo.ptr = s->dma_dac2.hwptr;
1653 if (s->dma_dac2.mapped)
1654 s->dma_dac2.count &= s->dma_dac2.fragsize-1;
1655 spin_unlock_irqrestore(&s->lock, flags);
1656 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1657 return -EFAULT;
1658 return 0;
1659
1660 case SNDCTL_DSP_GETBLKSIZE:
1661 if (file->f_mode & FMODE_WRITE) {
1662 if ((val = prog_dmabuf_dac2(s)))
1663 return val;
1664 return put_user(s->dma_dac2.fragsize, p);
1665 }
1666 if ((val = prog_dmabuf_adc(s)))
1667 return val;
1668 return put_user(s->dma_adc.fragsize, p);
1669
1670 case SNDCTL_DSP_SETFRAGMENT:
1671 if (get_user(val, p))
1672 return -EFAULT;
1673 if (file->f_mode & FMODE_READ) {
1674 s->dma_adc.ossfragshift = val & 0xffff;
1675 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1676 if (s->dma_adc.ossfragshift < 4)
1677 s->dma_adc.ossfragshift = 4;
1678 if (s->dma_adc.ossfragshift > 15)
1679 s->dma_adc.ossfragshift = 15;
1680 if (s->dma_adc.ossmaxfrags < 4)
1681 s->dma_adc.ossmaxfrags = 4;
1682 }
1683 if (file->f_mode & FMODE_WRITE) {
1684 s->dma_dac2.ossfragshift = val & 0xffff;
1685 s->dma_dac2.ossmaxfrags = (val >> 16) & 0xffff;
1686 if (s->dma_dac2.ossfragshift < 4)
1687 s->dma_dac2.ossfragshift = 4;
1688 if (s->dma_dac2.ossfragshift > 15)
1689 s->dma_dac2.ossfragshift = 15;
1690 if (s->dma_dac2.ossmaxfrags < 4)
1691 s->dma_dac2.ossmaxfrags = 4;
1692 }
1693 return 0;
1694
1695 case SNDCTL_DSP_SUBDIVIDE:
1696 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1697 (file->f_mode & FMODE_WRITE && s->dma_dac2.subdivision))
1698 return -EINVAL;
1699 if (get_user(val, p))
1700 return -EFAULT;
1701 if (val != 1 && val != 2 && val != 4)
1702 return -EINVAL;
1703 if (file->f_mode & FMODE_READ)
1704 s->dma_adc.subdivision = val;
1705 if (file->f_mode & FMODE_WRITE)
1706 s->dma_dac2.subdivision = val;
1707 return 0;
1708
1709 case SOUND_PCM_READ_RATE:
1710 return put_user(DAC2_DIVTOSR((s->ctrl & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV), p);
1711
1712 case SOUND_PCM_READ_CHANNELS:
1713 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SMB : SCTRL_P2SMB)) ?
1714 2 : 1, p);
1715
1716 case SOUND_PCM_READ_BITS:
1717 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SEB : SCTRL_P2SEB)) ?
1718 16 : 8, p);
1719
1720 case SOUND_PCM_WRITE_FILTER:
1721 case SNDCTL_DSP_SETSYNCRO:
1722 case SOUND_PCM_READ_FILTER:
1723 return -EINVAL;
1724
1725 }
1726 return mixer_ioctl(s, cmd, arg);
1727}
1728
1729static int es1370_open(struct inode *inode, struct file *file)
1730{
1731 unsigned int minor = iminor(inode);
1732 DECLARE_WAITQUEUE(wait, current);
1733 unsigned long flags;
1734 struct list_head *list;
1735 struct es1370_state *s;
1736
1737 for (list = devs.next; ; list = list->next) {
1738 if (list == &devs)
1739 return -ENODEV;
1740 s = list_entry(list, struct es1370_state, devs);
1741 if (!((s->dev_audio ^ minor) & ~0xf))
1742 break;
1743 }
1744 VALIDATE_STATE(s);
1745 file->private_data = s;
1746 /* wait for device to become free */
1747 down(&s->open_sem);
1748 while (s->open_mode & file->f_mode) {
1749 if (file->f_flags & O_NONBLOCK) {
1750 up(&s->open_sem);
1751 return -EBUSY;
1752 }
1753 add_wait_queue(&s->open_wait, &wait);
1754 __set_current_state(TASK_INTERRUPTIBLE);
1755 up(&s->open_sem);
1756 schedule();
1757 remove_wait_queue(&s->open_wait, &wait);
1758 set_current_state(TASK_RUNNING);
1759 if (signal_pending(current))
1760 return -ERESTARTSYS;
1761 down(&s->open_sem);
1762 }
1763 spin_lock_irqsave(&s->lock, flags);
1764 if (!(s->open_mode & (FMODE_READ|FMODE_WRITE)))
1765 s->ctrl = (s->ctrl & ~CTRL_PCLKDIV) | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV);
1766 if (file->f_mode & FMODE_READ) {
1767 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
1768 s->dma_adc.enabled = 1;
1769 s->sctrl &= ~SCTRL_R1FMT;
1770 if ((minor & 0xf) == SND_DEV_DSP16)
1771 s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_R1FMT;
1772 else
1773 s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_R1FMT;
1774 }
1775 if (file->f_mode & FMODE_WRITE) {
1776 s->dma_dac2.ossfragshift = s->dma_dac2.ossmaxfrags = s->dma_dac2.subdivision = 0;
1777 s->dma_dac2.enabled = 1;
1778 s->sctrl &= ~SCTRL_P2FMT;
1779 if ((minor & 0xf) == SND_DEV_DSP16)
1780 s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_P2FMT;
1781 else
1782 s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_P2FMT;
1783 }
1784 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
1785 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
1786 spin_unlock_irqrestore(&s->lock, flags);
1787 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1788 up(&s->open_sem);
1789 init_MUTEX(&s->sem);
1790 return nonseekable_open(inode, file);
1791}
1792
1793static int es1370_release(struct inode *inode, struct file *file)
1794{
1795 struct es1370_state *s = (struct es1370_state *)file->private_data;
1796
1797 VALIDATE_STATE(s);
1798 lock_kernel();
1799 if (file->f_mode & FMODE_WRITE)
1800 drain_dac2(s, file->f_flags & O_NONBLOCK);
1801 down(&s->open_sem);
1802 if (file->f_mode & FMODE_WRITE) {
1803 stop_dac2(s);
1804 synchronize_irq(s->irq);
1805 dealloc_dmabuf(s, &s->dma_dac2);
1806 }
1807 if (file->f_mode & FMODE_READ) {
1808 stop_adc(s);
1809 dealloc_dmabuf(s, &s->dma_adc);
1810 }
1811 s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
1812 wake_up(&s->open_wait);
1813 up(&s->open_sem);
1814 unlock_kernel();
1815 return 0;
1816}
1817
1818static /*const*/ struct file_operations es1370_audio_fops = {
1819 .owner = THIS_MODULE,
1820 .llseek = no_llseek,
1821 .read = es1370_read,
1822 .write = es1370_write,
1823 .poll = es1370_poll,
1824 .ioctl = es1370_ioctl,
1825 .mmap = es1370_mmap,
1826 .open = es1370_open,
1827 .release = es1370_release,
1828};
1829
1830/* --------------------------------------------------------------------- */
1831
1832static ssize_t es1370_write_dac(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1833{
1834 struct es1370_state *s = (struct es1370_state *)file->private_data;
1835 DECLARE_WAITQUEUE(wait, current);
1836 ssize_t ret = 0;
1837 unsigned long flags;
1838 unsigned swptr;
1839 int cnt;
1840
1841 VALIDATE_STATE(s);
1842 if (s->dma_dac1.mapped)
1843 return -ENXIO;
1844 if (!s->dma_dac1.ready && (ret = prog_dmabuf_dac1(s)))
1845 return ret;
1846 if (!access_ok(VERIFY_READ, buffer, count))
1847 return -EFAULT;
1848 add_wait_queue(&s->dma_dac1.wait, &wait);
1849 while (count > 0) {
1850 spin_lock_irqsave(&s->lock, flags);
1851 if (s->dma_dac1.count < 0) {
1852 s->dma_dac1.count = 0;
1853 s->dma_dac1.swptr = s->dma_dac1.hwptr;
1854 }
1855 swptr = s->dma_dac1.swptr;
1856 cnt = s->dma_dac1.dmasize-swptr;
1857 if (s->dma_dac1.count + cnt > s->dma_dac1.dmasize)
1858 cnt = s->dma_dac1.dmasize - s->dma_dac1.count;
1859 if (cnt <= 0)
1860 __set_current_state(TASK_INTERRUPTIBLE);
1861 spin_unlock_irqrestore(&s->lock, flags);
1862 if (cnt > count)
1863 cnt = count;
1864 if (cnt <= 0) {
1865 if (s->dma_dac1.enabled)
1866 start_dac1(s);
1867 if (file->f_flags & O_NONBLOCK) {
1868 if (!ret)
1869 ret = -EAGAIN;
1870 break;
1871 }
1872 schedule();
1873 if (signal_pending(current)) {
1874 if (!ret)
1875 ret = -ERESTARTSYS;
1876 break;
1877 }
1878 continue;
1879 }
1880 if (copy_from_user(s->dma_dac1.rawbuf + swptr, buffer, cnt)) {
1881 if (!ret)
1882 ret = -EFAULT;
1883 break;
1884 }
1885 swptr = (swptr + cnt) % s->dma_dac1.dmasize;
1886 spin_lock_irqsave(&s->lock, flags);
1887 s->dma_dac1.swptr = swptr;
1888 s->dma_dac1.count += cnt;
1889 s->dma_dac1.endcleared = 0;
1890 spin_unlock_irqrestore(&s->lock, flags);
1891 count -= cnt;
1892 buffer += cnt;
1893 ret += cnt;
1894 if (s->dma_dac1.enabled)
1895 start_dac1(s);
1896 }
1897 remove_wait_queue(&s->dma_dac1.wait, &wait);
1898 set_current_state(TASK_RUNNING);
1899 return ret;
1900}
1901
1902/* No kernel lock - we have our own spinlock */
1903static unsigned int es1370_poll_dac(struct file *file, struct poll_table_struct *wait)
1904{
1905 struct es1370_state *s = (struct es1370_state *)file->private_data;
1906 unsigned long flags;
1907 unsigned int mask = 0;
1908
1909 VALIDATE_STATE(s);
1910 if (!s->dma_dac1.ready && prog_dmabuf_dac1(s))
1911 return 0;
1912 poll_wait(file, &s->dma_dac1.wait, wait);
1913 spin_lock_irqsave(&s->lock, flags);
1914 es1370_update_ptr(s);
1915 if (s->dma_dac1.mapped) {
1916 if (s->dma_dac1.count >= (signed)s->dma_dac1.fragsize)
1917 mask |= POLLOUT | POLLWRNORM;
1918 } else {
1919 if ((signed)s->dma_dac1.dmasize >= s->dma_dac1.count + (signed)s->dma_dac1.fragsize)
1920 mask |= POLLOUT | POLLWRNORM;
1921 }
1922 spin_unlock_irqrestore(&s->lock, flags);
1923 return mask;
1924}
1925
1926static int es1370_mmap_dac(struct file *file, struct vm_area_struct *vma)
1927{
1928 struct es1370_state *s = (struct es1370_state *)file->private_data;
1929 int ret;
1930 unsigned long size;
1931
1932 VALIDATE_STATE(s);
1933 if (!(vma->vm_flags & VM_WRITE))
1934 return -EINVAL;
1935 lock_kernel();
1936 if ((ret = prog_dmabuf_dac1(s)) != 0)
1937 goto out;
1938 ret = -EINVAL;
1939 if (vma->vm_pgoff != 0)
1940 goto out;
1941 size = vma->vm_end - vma->vm_start;
1942 if (size > (PAGE_SIZE << s->dma_dac1.buforder))
1943 goto out;
1944 ret = -EAGAIN;
1945 if (remap_pfn_range(vma, vma->vm_start,
1946 virt_to_phys(s->dma_dac1.rawbuf) >> PAGE_SHIFT,
1947 size, vma->vm_page_prot))
1948 goto out;
1949 s->dma_dac1.mapped = 1;
1950 ret = 0;
1951out:
1952 unlock_kernel();
1953 return ret;
1954}
1955
1956static int es1370_ioctl_dac(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1957{
1958 struct es1370_state *s = (struct es1370_state *)file->private_data;
1959 unsigned long flags;
1960 audio_buf_info abinfo;
1961 count_info cinfo;
1962 int count;
1963 unsigned ctrl;
1964 int val, ret;
1965 int __user *p = (int __user *)arg;
1966
1967 VALIDATE_STATE(s);
1968 switch (cmd) {
1969 case OSS_GETVERSION:
1970 return put_user(SOUND_VERSION, p);
1971
1972 case SNDCTL_DSP_SYNC:
1973 return drain_dac1(s, 0/*file->f_flags & O_NONBLOCK*/);
1974
1975 case SNDCTL_DSP_SETDUPLEX:
1976 return -EINVAL;
1977
1978 case SNDCTL_DSP_GETCAPS:
1979 return put_user(DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
1980
1981 case SNDCTL_DSP_RESET:
1982 stop_dac1(s);
1983 synchronize_irq(s->irq);
1984 s->dma_dac1.swptr = s->dma_dac1.hwptr = s->dma_dac1.count = s->dma_dac1.total_bytes = 0;
1985 return 0;
1986
1987 case SNDCTL_DSP_SPEED:
1988 if (get_user(val, p))
1989 return -EFAULT;
1990 if (val >= 0) {
1991 stop_dac1(s);
1992 s->dma_dac1.ready = 0;
1993 for (ctrl = 0; ctrl <= 2; ctrl++)
1994 if (val < (dac1_samplerate[ctrl] + dac1_samplerate[ctrl+1]) / 2)
1995 break;
1996 spin_lock_irqsave(&s->lock, flags);
1997 s->ctrl = (s->ctrl & ~CTRL_WTSRSEL) | (ctrl << CTRL_SH_WTSRSEL);
1998 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
1999 spin_unlock_irqrestore(&s->lock, flags);
2000 }
2001 return put_user(dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL], p);
2002
2003 case SNDCTL_DSP_STEREO:
2004 if (get_user(val, p))
2005 return -EFAULT;
2006 stop_dac1(s);
2007 s->dma_dac1.ready = 0;
2008 spin_lock_irqsave(&s->lock, flags);
2009 if (val)
2010 s->sctrl |= SCTRL_P1SMB;
2011 else
2012 s->sctrl &= ~SCTRL_P1SMB;
2013 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
2014 spin_unlock_irqrestore(&s->lock, flags);
2015 return 0;
2016
2017 case SNDCTL_DSP_CHANNELS:
2018 if (get_user(val, p))
2019 return -EFAULT;
2020 if (val != 0) {
2021 if (s->dma_dac1.mapped)
2022 return -EINVAL;
2023 stop_dac1(s);
2024 s->dma_dac1.ready = 0;
2025 spin_lock_irqsave(&s->lock, flags);
2026 if (val >= 2)
2027 s->sctrl |= SCTRL_P1SMB;
2028 else
2029 s->sctrl &= ~SCTRL_P1SMB;
2030 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
2031 spin_unlock_irqrestore(&s->lock, flags);
2032 }
2033 return put_user((s->sctrl & SCTRL_P1SMB) ? 2 : 1, p);
2034
2035 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
2036 return put_user(AFMT_S16_LE|AFMT_U8, p);
2037
2038 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
2039 if (get_user(val, p))
2040 return -EFAULT;
2041 if (val != AFMT_QUERY) {
2042 stop_dac1(s);
2043 s->dma_dac1.ready = 0;
2044 spin_lock_irqsave(&s->lock, flags);
2045 if (val == AFMT_S16_LE)
2046 s->sctrl |= SCTRL_P1SEB;
2047 else
2048 s->sctrl &= ~SCTRL_P1SEB;
2049 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
2050 spin_unlock_irqrestore(&s->lock, flags);
2051 }
2052 return put_user((s->sctrl & SCTRL_P1SEB) ? AFMT_S16_LE : AFMT_U8, p);
2053
2054 case SNDCTL_DSP_POST:
2055 return 0;
2056
2057 case SNDCTL_DSP_GETTRIGGER:
2058 return put_user((s->ctrl & CTRL_DAC1_EN) ? PCM_ENABLE_OUTPUT : 0, p);
2059
2060 case SNDCTL_DSP_SETTRIGGER:
2061 if (get_user(val, p))
2062 return -EFAULT;
2063 if (val & PCM_ENABLE_OUTPUT) {
2064 if (!s->dma_dac1.ready && (ret = prog_dmabuf_dac1(s)))
2065 return ret;
2066 s->dma_dac1.enabled = 1;
2067 start_dac1(s);
2068 } else {
2069 s->dma_dac1.enabled = 0;
2070 stop_dac1(s);
2071 }
2072 return 0;
2073
2074 case SNDCTL_DSP_GETOSPACE:
2075 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
2076 return val;
2077 spin_lock_irqsave(&s->lock, flags);
2078 es1370_update_ptr(s);
2079 abinfo.fragsize = s->dma_dac1.fragsize;
2080 count = s->dma_dac1.count;
2081 if (count < 0)
2082 count = 0;
2083 abinfo.bytes = s->dma_dac1.dmasize - count;
2084 abinfo.fragstotal = s->dma_dac1.numfrag;
2085 abinfo.fragments = abinfo.bytes >> s->dma_dac1.fragshift;
2086 spin_unlock_irqrestore(&s->lock, flags);
2087 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2088
2089 case SNDCTL_DSP_NONBLOCK:
2090 file->f_flags |= O_NONBLOCK;
2091 return 0;
2092
2093 case SNDCTL_DSP_GETODELAY:
2094 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
2095 return val;
2096 spin_lock_irqsave(&s->lock, flags);
2097 es1370_update_ptr(s);
2098 count = s->dma_dac1.count;
2099 spin_unlock_irqrestore(&s->lock, flags);
2100 if (count < 0)
2101 count = 0;
2102 return put_user(count, p);
2103
2104 case SNDCTL_DSP_GETOPTR:
2105 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
2106 return val;
2107 spin_lock_irqsave(&s->lock, flags);
2108 es1370_update_ptr(s);
2109 cinfo.bytes = s->dma_dac1.total_bytes;
2110 count = s->dma_dac1.count;
2111 if (count < 0)
2112 count = 0;
2113 cinfo.blocks = count >> s->dma_dac1.fragshift;
2114 cinfo.ptr = s->dma_dac1.hwptr;
2115 if (s->dma_dac1.mapped)
2116 s->dma_dac1.count &= s->dma_dac1.fragsize-1;
2117 spin_unlock_irqrestore(&s->lock, flags);
2118 if (copy_to_user((void __user *)arg, &cinfo, sizeof(cinfo)))
2119 return -EFAULT;
2120 return 0;
2121
2122 case SNDCTL_DSP_GETBLKSIZE:
2123 if ((val = prog_dmabuf_dac1(s)))
2124 return val;
2125 return put_user(s->dma_dac1.fragsize, p);
2126
2127 case SNDCTL_DSP_SETFRAGMENT:
2128 if (get_user(val, p))
2129 return -EFAULT;
2130 s->dma_dac1.ossfragshift = val & 0xffff;
2131 s->dma_dac1.ossmaxfrags = (val >> 16) & 0xffff;
2132 if (s->dma_dac1.ossfragshift < 4)
2133 s->dma_dac1.ossfragshift = 4;
2134 if (s->dma_dac1.ossfragshift > 15)
2135 s->dma_dac1.ossfragshift = 15;
2136 if (s->dma_dac1.ossmaxfrags < 4)
2137 s->dma_dac1.ossmaxfrags = 4;
2138 return 0;
2139
2140 case SNDCTL_DSP_SUBDIVIDE:
2141 if (s->dma_dac1.subdivision)
2142 return -EINVAL;
2143 if (get_user(val, p))
2144 return -EFAULT;
2145 if (val != 1 && val != 2 && val != 4)
2146 return -EINVAL;
2147 s->dma_dac1.subdivision = val;
2148 return 0;
2149
2150 case SOUND_PCM_READ_RATE:
2151 return put_user(dac1_samplerate[(s->ctrl & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL], p);
2152
2153 case SOUND_PCM_READ_CHANNELS:
2154 return put_user((s->sctrl & SCTRL_P1SMB) ? 2 : 1, p);
2155
2156 case SOUND_PCM_READ_BITS:
2157 return put_user((s->sctrl & SCTRL_P1SEB) ? 16 : 8, p);
2158
2159 case SOUND_PCM_WRITE_FILTER:
2160 case SNDCTL_DSP_SETSYNCRO:
2161 case SOUND_PCM_READ_FILTER:
2162 return -EINVAL;
2163
2164 }
2165 return mixer_ioctl(s, cmd, arg);
2166}
2167
2168static int es1370_open_dac(struct inode *inode, struct file *file)
2169{
2170 unsigned int minor = iminor(inode);
2171 DECLARE_WAITQUEUE(wait, current);
2172 unsigned long flags;
2173 struct list_head *list;
2174 struct es1370_state *s;
2175
2176 for (list = devs.next; ; list = list->next) {
2177 if (list == &devs)
2178 return -ENODEV;
2179 s = list_entry(list, struct es1370_state, devs);
2180 if (!((s->dev_dac ^ minor) & ~0xf))
2181 break;
2182 }
2183 VALIDATE_STATE(s);
2184 /* we allow opening with O_RDWR, most programs do it although they will only write */
2185#if 0
2186 if (file->f_mode & FMODE_READ)
2187 return -EPERM;
2188#endif
2189 if (!(file->f_mode & FMODE_WRITE))
2190 return -EINVAL;
2191 file->private_data = s;
2192 /* wait for device to become free */
2193 down(&s->open_sem);
2194 while (s->open_mode & FMODE_DAC) {
2195 if (file->f_flags & O_NONBLOCK) {
2196 up(&s->open_sem);
2197 return -EBUSY;
2198 }
2199 add_wait_queue(&s->open_wait, &wait);
2200 __set_current_state(TASK_INTERRUPTIBLE);
2201 up(&s->open_sem);
2202 schedule();
2203 remove_wait_queue(&s->open_wait, &wait);
2204 set_current_state(TASK_RUNNING);
2205 if (signal_pending(current))
2206 return -ERESTARTSYS;
2207 down(&s->open_sem);
2208 }
2209 s->dma_dac1.ossfragshift = s->dma_dac1.ossmaxfrags = s->dma_dac1.subdivision = 0;
2210 s->dma_dac1.enabled = 1;
2211 spin_lock_irqsave(&s->lock, flags);
2212 s->ctrl = (s->ctrl & ~CTRL_WTSRSEL) | (1 << CTRL_SH_WTSRSEL);
2213 s->sctrl &= ~SCTRL_P1FMT;
2214 if ((minor & 0xf) == SND_DEV_DSP16)
2215 s->sctrl |= ES1370_FMT_S16_MONO << SCTRL_SH_P1FMT;
2216 else
2217 s->sctrl |= ES1370_FMT_U8_MONO << SCTRL_SH_P1FMT;
2218 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
2219 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
2220 spin_unlock_irqrestore(&s->lock, flags);
2221 s->open_mode |= FMODE_DAC;
2222 up(&s->open_sem);
2223 return nonseekable_open(inode, file);
2224}
2225
2226static int es1370_release_dac(struct inode *inode, struct file *file)
2227{
2228 struct es1370_state *s = (struct es1370_state *)file->private_data;
2229
2230 VALIDATE_STATE(s);
2231 lock_kernel();
2232 drain_dac1(s, file->f_flags & O_NONBLOCK);
2233 down(&s->open_sem);
2234 stop_dac1(s);
2235 dealloc_dmabuf(s, &s->dma_dac1);
2236 s->open_mode &= ~FMODE_DAC;
2237 wake_up(&s->open_wait);
2238 up(&s->open_sem);
2239 unlock_kernel();
2240 return 0;
2241}
2242
2243static /*const*/ struct file_operations es1370_dac_fops = {
2244 .owner = THIS_MODULE,
2245 .llseek = no_llseek,
2246 .write = es1370_write_dac,
2247 .poll = es1370_poll_dac,
2248 .ioctl = es1370_ioctl_dac,
2249 .mmap = es1370_mmap_dac,
2250 .open = es1370_open_dac,
2251 .release = es1370_release_dac,
2252};
2253
2254/* --------------------------------------------------------------------- */
2255
2256static ssize_t es1370_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2257{
2258 struct es1370_state *s = (struct es1370_state *)file->private_data;
2259 DECLARE_WAITQUEUE(wait, current);
2260 ssize_t ret;
2261 unsigned long flags;
2262 unsigned ptr;
2263 int cnt;
2264
2265 VALIDATE_STATE(s);
2266 if (!access_ok(VERIFY_WRITE, buffer, count))
2267 return -EFAULT;
2268 if (count == 0)
2269 return 0;
2270 ret = 0;
2271 add_wait_queue(&s->midi.iwait, &wait);
2272 while (count > 0) {
2273 spin_lock_irqsave(&s->lock, flags);
2274 ptr = s->midi.ird;
2275 cnt = MIDIINBUF - ptr;
2276 if (s->midi.icnt < cnt)
2277 cnt = s->midi.icnt;
2278 if (cnt <= 0)
2279 __set_current_state(TASK_INTERRUPTIBLE);
2280 spin_unlock_irqrestore(&s->lock, flags);
2281 if (cnt > count)
2282 cnt = count;
2283 if (cnt <= 0) {
2284 if (file->f_flags & O_NONBLOCK) {
2285 if (!ret)
2286 ret = -EAGAIN;
2287 break;
2288 }
2289 schedule();
2290 if (signal_pending(current)) {
2291 if (!ret)
2292 ret = -ERESTARTSYS;
2293 break;
2294 }
2295 continue;
2296 }
2297 if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt)) {
2298 if (!ret)
2299 ret = -EFAULT;
2300 break;
2301 }
2302 ptr = (ptr + cnt) % MIDIINBUF;
2303 spin_lock_irqsave(&s->lock, flags);
2304 s->midi.ird = ptr;
2305 s->midi.icnt -= cnt;
2306 spin_unlock_irqrestore(&s->lock, flags);
2307 count -= cnt;
2308 buffer += cnt;
2309 ret += cnt;
2310 break;
2311 }
2312 __set_current_state(TASK_RUNNING);
2313 remove_wait_queue(&s->midi.iwait, &wait);
2314 return ret;
2315}
2316
2317static ssize_t es1370_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2318{
2319 struct es1370_state *s = (struct es1370_state *)file->private_data;
2320 DECLARE_WAITQUEUE(wait, current);
2321 ssize_t ret;
2322 unsigned long flags;
2323 unsigned ptr;
2324 int cnt;
2325
2326 VALIDATE_STATE(s);
2327 if (!access_ok(VERIFY_READ, buffer, count))
2328 return -EFAULT;
2329 if (count == 0)
2330 return 0;
2331 ret = 0;
2332 add_wait_queue(&s->midi.owait, &wait);
2333 while (count > 0) {
2334 spin_lock_irqsave(&s->lock, flags);
2335 ptr = s->midi.owr;
2336 cnt = MIDIOUTBUF - ptr;
2337 if (s->midi.ocnt + cnt > MIDIOUTBUF)
2338 cnt = MIDIOUTBUF - s->midi.ocnt;
2339 if (cnt <= 0) {
2340 __set_current_state(TASK_INTERRUPTIBLE);
2341 es1370_handle_midi(s);
2342 }
2343 spin_unlock_irqrestore(&s->lock, flags);
2344 if (cnt > count)
2345 cnt = count;
2346 if (cnt <= 0) {
2347 if (file->f_flags & O_NONBLOCK) {
2348 if (!ret)
2349 ret = -EAGAIN;
2350 break;
2351 }
2352 schedule();
2353 if (signal_pending(current)) {
2354 if (!ret)
2355 ret = -ERESTARTSYS;
2356 break;
2357 }
2358 continue;
2359 }
2360 if (copy_from_user(s->midi.obuf + ptr, buffer, cnt)) {
2361 if (!ret)
2362 ret = -EFAULT;
2363 break;
2364 }
2365 ptr = (ptr + cnt) % MIDIOUTBUF;
2366 spin_lock_irqsave(&s->lock, flags);
2367 s->midi.owr = ptr;
2368 s->midi.ocnt += cnt;
2369 spin_unlock_irqrestore(&s->lock, flags);
2370 count -= cnt;
2371 buffer += cnt;
2372 ret += cnt;
2373 spin_lock_irqsave(&s->lock, flags);
2374 es1370_handle_midi(s);
2375 spin_unlock_irqrestore(&s->lock, flags);
2376 }
2377 __set_current_state(TASK_RUNNING);
2378 remove_wait_queue(&s->midi.owait, &wait);
2379 return ret;
2380}
2381
2382/* No kernel lock - we have our own spinlock */
2383static unsigned int es1370_midi_poll(struct file *file, struct poll_table_struct *wait)
2384{
2385 struct es1370_state *s = (struct es1370_state *)file->private_data;
2386 unsigned long flags;
2387 unsigned int mask = 0;
2388
2389 VALIDATE_STATE(s);
2390 if (file->f_mode & FMODE_WRITE)
2391 poll_wait(file, &s->midi.owait, wait);
2392 if (file->f_mode & FMODE_READ)
2393 poll_wait(file, &s->midi.iwait, wait);
2394 spin_lock_irqsave(&s->lock, flags);
2395 if (file->f_mode & FMODE_READ) {
2396 if (s->midi.icnt > 0)
2397 mask |= POLLIN | POLLRDNORM;
2398 }
2399 if (file->f_mode & FMODE_WRITE) {
2400 if (s->midi.ocnt < MIDIOUTBUF)
2401 mask |= POLLOUT | POLLWRNORM;
2402 }
2403 spin_unlock_irqrestore(&s->lock, flags);
2404 return mask;
2405}
2406
2407static int es1370_midi_open(struct inode *inode, struct file *file)
2408{
2409 unsigned int minor = iminor(inode);
2410 DECLARE_WAITQUEUE(wait, current);
2411 unsigned long flags;
2412 struct list_head *list;
2413 struct es1370_state *s;
2414
2415 for (list = devs.next; ; list = list->next) {
2416 if (list == &devs)
2417 return -ENODEV;
2418 s = list_entry(list, struct es1370_state, devs);
2419 if (s->dev_midi == minor)
2420 break;
2421 }
2422 VALIDATE_STATE(s);
2423 file->private_data = s;
2424 /* wait for device to become free */
2425 down(&s->open_sem);
2426 while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
2427 if (file->f_flags & O_NONBLOCK) {
2428 up(&s->open_sem);
2429 return -EBUSY;
2430 }
2431 add_wait_queue(&s->open_wait, &wait);
2432 __set_current_state(TASK_INTERRUPTIBLE);
2433 up(&s->open_sem);
2434 schedule();
2435 remove_wait_queue(&s->open_wait, &wait);
2436 set_current_state(TASK_RUNNING);
2437 if (signal_pending(current))
2438 return -ERESTARTSYS;
2439 down(&s->open_sem);
2440 }
2441 spin_lock_irqsave(&s->lock, flags);
2442 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
2443 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2444 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
2445 outb(UCTRL_CNTRL_SWR, s->io+ES1370_REG_UART_CONTROL);
2446 outb(0, s->io+ES1370_REG_UART_CONTROL);
2447 outb(0, s->io+ES1370_REG_UART_TEST);
2448 }
2449 if (file->f_mode & FMODE_READ) {
2450 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2451 }
2452 if (file->f_mode & FMODE_WRITE) {
2453 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
2454 }
2455 s->ctrl |= CTRL_UART_EN;
2456 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
2457 es1370_handle_midi(s);
2458 spin_unlock_irqrestore(&s->lock, flags);
2459 s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
2460 up(&s->open_sem);
2461 return nonseekable_open(inode, file);
2462}
2463
2464static int es1370_midi_release(struct inode *inode, struct file *file)
2465{
2466 struct es1370_state *s = (struct es1370_state *)file->private_data;
2467 DECLARE_WAITQUEUE(wait, current);
2468 unsigned long flags;
2469 unsigned count, tmo;
2470
2471 VALIDATE_STATE(s);
2472
2473 lock_kernel();
2474 if (file->f_mode & FMODE_WRITE) {
2475 add_wait_queue(&s->midi.owait, &wait);
2476 for (;;) {
2477 __set_current_state(TASK_INTERRUPTIBLE);
2478 spin_lock_irqsave(&s->lock, flags);
2479 count = s->midi.ocnt;
2480 spin_unlock_irqrestore(&s->lock, flags);
2481 if (count <= 0)
2482 break;
2483 if (signal_pending(current))
2484 break;
2485 if (file->f_flags & O_NONBLOCK)
2486 break;
2487 tmo = (count * HZ) / 3100;
2488 if (!schedule_timeout(tmo ? : 1) && tmo)
2489 DBG(printk(KERN_DEBUG "es1370: midi timed out??\n");)
2490 }
2491 remove_wait_queue(&s->midi.owait, &wait);
2492 set_current_state(TASK_RUNNING);
2493 }
2494 down(&s->open_sem);
2495 s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
2496 spin_lock_irqsave(&s->lock, flags);
2497 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
2498 s->ctrl &= ~CTRL_UART_EN;
2499 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
2500 }
2501 spin_unlock_irqrestore(&s->lock, flags);
2502 wake_up(&s->open_wait);
2503 up(&s->open_sem);
2504 unlock_kernel();
2505 return 0;
2506}
2507
2508static /*const*/ struct file_operations es1370_midi_fops = {
2509 .owner = THIS_MODULE,
2510 .llseek = no_llseek,
2511 .read = es1370_midi_read,
2512 .write = es1370_midi_write,
2513 .poll = es1370_midi_poll,
2514 .open = es1370_midi_open,
2515 .release = es1370_midi_release,
2516};
2517
2518/* --------------------------------------------------------------------- */
2519
2520/* maximum number of devices; only used for command line params */
2521#define NR_DEVICE 5
2522
2523static int lineout[NR_DEVICE];
2524static int micbias[NR_DEVICE];
2525
2526static unsigned int devindex;
2527
2528module_param_array(lineout, bool, NULL, 0);
2529MODULE_PARM_DESC(lineout, "if 1 the LINE input is converted to LINE out");
2530module_param_array(micbias, bool, NULL, 0);
2531MODULE_PARM_DESC(micbias, "sets the +5V bias for an electret microphone");
2532
2533MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
2534MODULE_DESCRIPTION("ES1370 AudioPCI Driver");
2535MODULE_LICENSE("GPL");
2536
2537
2538/* --------------------------------------------------------------------- */
2539
2540static struct initvol {
2541 int mixch;
2542 int vol;
2543} initvol[] __devinitdata = {
2544 { SOUND_MIXER_WRITE_VOLUME, 0x4040 },
2545 { SOUND_MIXER_WRITE_PCM, 0x4040 },
2546 { SOUND_MIXER_WRITE_SYNTH, 0x4040 },
2547 { SOUND_MIXER_WRITE_CD, 0x4040 },
2548 { SOUND_MIXER_WRITE_LINE, 0x4040 },
2549 { SOUND_MIXER_WRITE_LINE1, 0x4040 },
2550 { SOUND_MIXER_WRITE_LINE2, 0x4040 },
2551 { SOUND_MIXER_WRITE_LINE3, 0x4040 },
2552 { SOUND_MIXER_WRITE_MIC, 0x4040 },
2553 { SOUND_MIXER_WRITE_OGAIN, 0x4040 }
2554};
2555
2556static int __devinit es1370_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2557{
2558 struct es1370_state *s;
2559 struct gameport *gp = NULL;
2560 mm_segment_t fs;
2561 int i, val, ret;
2562
2563 if ((ret=pci_enable_device(pcidev)))
2564 return ret;
2565
2566 if ( !(pci_resource_flags(pcidev, 0) & IORESOURCE_IO) ||
2567 !pci_resource_start(pcidev, 0)
2568 )
2569 return -ENODEV;
2570 if (pcidev->irq == 0)
2571 return -ENODEV;
2572 i = pci_set_dma_mask(pcidev, 0xffffffff);
2573 if (i) {
2574 printk(KERN_WARNING "es1370: architecture does not support 32bit PCI busmaster DMA\n");
2575 return i;
2576 }
2577 if (!(s = kmalloc(sizeof(struct es1370_state), GFP_KERNEL))) {
2578 printk(KERN_WARNING "es1370: out of memory\n");
2579 return -ENOMEM;
2580 }
2581 memset(s, 0, sizeof(struct es1370_state));
2582 init_waitqueue_head(&s->dma_adc.wait);
2583 init_waitqueue_head(&s->dma_dac1.wait);
2584 init_waitqueue_head(&s->dma_dac2.wait);
2585 init_waitqueue_head(&s->open_wait);
2586 init_waitqueue_head(&s->midi.iwait);
2587 init_waitqueue_head(&s->midi.owait);
2588 init_MUTEX(&s->open_sem);
2589 spin_lock_init(&s->lock);
2590 s->magic = ES1370_MAGIC;
2591 s->dev = pcidev;
2592 s->io = pci_resource_start(pcidev, 0);
2593 s->irq = pcidev->irq;
2594 if (!request_region(s->io, ES1370_EXTENT, "es1370")) {
2595 printk(KERN_ERR "es1370: io ports %#lx-%#lx in use\n", s->io, s->io+ES1370_EXTENT-1);
2596 ret = -EBUSY;
2597 goto err_region;
2598 }
2599 if ((ret=request_irq(s->irq, es1370_interrupt, SA_SHIRQ, "es1370",s))) {
2600 printk(KERN_ERR "es1370: irq %u in use\n", s->irq);
2601 goto err_irq;
2602 }
2603
2604 /* initialize codec registers */
2605 /* note: setting CTRL_SERR_DIS is reported to break
2606 * mic bias setting (by Kim.Berts@fisub.mail.abb.com) */
2607 s->ctrl = CTRL_CDC_EN | (DAC2_SRTODIV(8000) << CTRL_SH_PCLKDIV) | (1 << CTRL_SH_WTSRSEL);
2608 if (!request_region(0x200, JOY_EXTENT, "es1370")) {
2609 printk(KERN_ERR "es1370: joystick io port 0x200 in use\n");
2610 } else if (!(s->gameport = gp = gameport_allocate_port())) {
2611 printk(KERN_ERR "es1370: can not allocate memory for gameport\n");
2612 release_region(0x200, JOY_EXTENT);
2613 } else {
2614 gameport_set_name(gp, "ESS1370");
2615 gameport_set_phys(gp, "pci%s/gameport0", pci_name(s->dev));
2616 gp->dev.parent = &s->dev->dev;
2617 gp->io = 0x200;
2618 s->ctrl |= CTRL_JYSTK_EN;
2619 }
2620 if (lineout[devindex])
2621 s->ctrl |= CTRL_XCTL0;
2622 if (micbias[devindex])
2623 s->ctrl |= CTRL_XCTL1;
2624 s->sctrl = 0;
2625 printk(KERN_INFO "es1370: found adapter at io %#lx irq %u\n"
2626 KERN_INFO "es1370: features: joystick %s, line %s, mic impedance %s\n",
2627 s->io, s->irq, (s->ctrl & CTRL_JYSTK_EN) ? "on" : "off",
2628 (s->ctrl & CTRL_XCTL0) ? "out" : "in",
2629 (s->ctrl & CTRL_XCTL1) ? "1" : "0");
2630 /* register devices */
2631 if ((s->dev_audio = register_sound_dsp(&es1370_audio_fops, -1)) < 0) {
2632 ret = s->dev_audio;
2633 goto err_dev1;
2634 }
2635 if ((s->dev_mixer = register_sound_mixer(&es1370_mixer_fops, -1)) < 0) {
2636 ret = s->dev_mixer;
2637 goto err_dev2;
2638 }
2639 if ((s->dev_dac = register_sound_dsp(&es1370_dac_fops, -1)) < 0) {
2640 ret = s->dev_dac;
2641 goto err_dev3;
2642 }
2643 if ((s->dev_midi = register_sound_midi(&es1370_midi_fops, -1)) < 0) {
2644 ret = s->dev_midi;
2645 goto err_dev4;
2646 }
2647 /* initialize the chips */
2648 outl(s->ctrl, s->io+ES1370_REG_CONTROL);
2649 outl(s->sctrl, s->io+ES1370_REG_SERIAL_CONTROL);
2650 /* point phantom write channel to "bugbuf" */
2651 s->bugbuf_cpu = pci_alloc_consistent(pcidev,16,&s->bugbuf_dma);
2652 if (!s->bugbuf_cpu) {
2653 ret = -ENOMEM;
2654 goto err_dev5;
2655 }
2656 outl((ES1370_REG_PHANTOM_FRAMEADR >> 8) & 15, s->io+ES1370_REG_MEMPAGE);
2657 outl(s->bugbuf_dma, s->io+(ES1370_REG_PHANTOM_FRAMEADR & 0xff));
2658 outl(0, s->io+(ES1370_REG_PHANTOM_FRAMECNT & 0xff));
2659 pci_set_master(pcidev); /* enable bus mastering */
2660 wrcodec(s, 0x16, 3); /* no RST, PD */
2661 wrcodec(s, 0x17, 0); /* CODEC ADC and CODEC DAC use {LR,B}CLK2 and run off the LRCLK2 PLL; program DAC_SYNC=0!! */
2662 wrcodec(s, 0x18, 0); /* recording source is mixer */
2663 wrcodec(s, 0x19, s->mix.micpreamp = 1); /* turn on MIC preamp */
2664 s->mix.imix = 1;
2665 fs = get_fs();
2666 set_fs(KERNEL_DS);
2667 val = SOUND_MASK_LINE|SOUND_MASK_SYNTH|SOUND_MASK_CD;
2668 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
2669 for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
2670 val = initvol[i].vol;
2671 mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val);
2672 }
2673 set_fs(fs);
2674
2675 /* register gameport */
2676 if (gp)
2677 gameport_register_port(gp);
2678
2679 /* store it in the driver field */
2680 pci_set_drvdata(pcidev, s);
2681 /* put it into driver list */
2682 list_add_tail(&s->devs, &devs);
2683 /* increment devindex */
2684 if (devindex < NR_DEVICE-1)
2685 devindex++;
2686 return 0;
2687
2688 err_dev5:
2689 unregister_sound_midi(s->dev_midi);
2690 err_dev4:
2691 unregister_sound_dsp(s->dev_dac);
2692 err_dev3:
2693 unregister_sound_mixer(s->dev_mixer);
2694 err_dev2:
2695 unregister_sound_dsp(s->dev_audio);
2696 err_dev1:
2697 printk(KERN_ERR "es1370: cannot register misc device\n");
2698 free_irq(s->irq, s);
2699 if (s->gameport) {
2700 release_region(s->gameport->io, JOY_EXTENT);
2701 gameport_free_port(s->gameport);
2702 }
2703 err_irq:
2704 release_region(s->io, ES1370_EXTENT);
2705 err_region:
2706 kfree(s);
2707 return ret;
2708}
2709
2710static void __devexit es1370_remove(struct pci_dev *dev)
2711{
2712 struct es1370_state *s = pci_get_drvdata(dev);
2713
2714 if (!s)
2715 return;
2716 list_del(&s->devs);
2717 outl(CTRL_SERR_DIS | (1 << CTRL_SH_WTSRSEL), s->io+ES1370_REG_CONTROL); /* switch everything off */
2718 outl(0, s->io+ES1370_REG_SERIAL_CONTROL); /* clear serial interrupts */
2719 synchronize_irq(s->irq);
2720 free_irq(s->irq, s);
2721 if (s->gameport) {
2722 int gpio = s->gameport->io;
2723 gameport_unregister_port(s->gameport);
2724 release_region(gpio, JOY_EXTENT);
2725 }
2726 release_region(s->io, ES1370_EXTENT);
2727 unregister_sound_dsp(s->dev_audio);
2728 unregister_sound_mixer(s->dev_mixer);
2729 unregister_sound_dsp(s->dev_dac);
2730 unregister_sound_midi(s->dev_midi);
2731 pci_free_consistent(dev, 16, s->bugbuf_cpu, s->bugbuf_dma);
2732 kfree(s);
2733 pci_set_drvdata(dev, NULL);
2734}
2735
2736static struct pci_device_id id_table[] = {
2737 { PCI_VENDOR_ID_ENSONIQ, PCI_DEVICE_ID_ENSONIQ_ES1370, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
2738 { 0, }
2739};
2740
2741MODULE_DEVICE_TABLE(pci, id_table);
2742
2743static struct pci_driver es1370_driver = {
2744 .name = "es1370",
2745 .id_table = id_table,
2746 .probe = es1370_probe,
2747 .remove = __devexit_p(es1370_remove),
2748};
2749
2750static int __init init_es1370(void)
2751{
2752 printk(KERN_INFO "es1370: version v0.38 time " __TIME__ " " __DATE__ "\n");
2753 return pci_module_init(&es1370_driver);
2754}
2755
2756static void __exit cleanup_es1370(void)
2757{
2758 printk(KERN_INFO "es1370: unloading\n");
2759 pci_unregister_driver(&es1370_driver);
2760}
2761
2762module_init(init_es1370);
2763module_exit(cleanup_es1370);
2764
2765/* --------------------------------------------------------------------- */
2766
2767#ifndef MODULE
2768
2769/* format is: es1370=lineout[,micbias]] */
2770
2771static int __init es1370_setup(char *str)
2772{
2773 static unsigned __initdata nr_dev = 0;
2774
2775 if (nr_dev >= NR_DEVICE)
2776 return 0;
2777
2778 (void)
2779 ((get_option(&str,&lineout [nr_dev]) == 2)
2780 && get_option(&str,&micbias [nr_dev])
2781 );
2782
2783 nr_dev++;
2784 return 1;
2785}
2786
2787__setup("es1370=", es1370_setup);
2788
2789#endif /* MODULE */
diff --git a/sound/oss/es1371.c b/sound/oss/es1371.c
new file mode 100644
index 000000000000..a50fddaeea21
--- /dev/null
+++ b/sound/oss/es1371.c
@@ -0,0 +1,3097 @@
1/*****************************************************************************/
2
3/*
4 * es1371.c -- Creative Ensoniq ES1371.
5 *
6 * Copyright (C) 1998-2001, 2003 Thomas Sailer (t.sailer@alumni.ethz.ch)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * Special thanks to Ensoniq
23 *
24 * Supported devices:
25 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
26 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
27 * /dev/dsp1 additional DAC, like /dev/dsp, but outputs to mixer "SYNTH" setting
28 * /dev/midi simple MIDI UART interface, no ioctl
29 *
30 * NOTE: the card does not have any FM/Wavetable synthesizer, it is supposed
31 * to be done in software. That is what /dev/dac is for. By now (Q2 1998)
32 * there are several MIDI to PCM (WAV) packages, one of them is timidity.
33 *
34 * Revision history
35 * 04.06.1998 0.1 Initial release
36 * Mixer stuff should be overhauled; especially optional AC97 mixer bits
37 * should be detected. This results in strange behaviour of some mixer
38 * settings, like master volume and mic.
39 * 08.06.1998 0.2 First release using Alan Cox' soundcore instead of miscdevice
40 * 03.08.1998 0.3 Do not include modversions.h
41 * Now mixer behaviour can basically be selected between
42 * "OSS documented" and "OSS actual" behaviour
43 * 31.08.1998 0.4 Fix realplayer problems - dac.count issues
44 * 27.10.1998 0.5 Fix joystick support
45 * -- Oliver Neukum (c188@org.chemie.uni-muenchen.de)
46 * 10.12.1998 0.6 Fix drain_dac trying to wait on not yet initialized DMA
47 * 23.12.1998 0.7 Fix a few f_file & FMODE_ bugs
48 * Don't wake up app until there are fragsize bytes to read/write
49 * 06.01.1999 0.8 remove the silly SA_INTERRUPT flag.
50 * hopefully killed the egcs section type conflict
51 * 12.03.1999 0.9 cinfo.blocks should be reset after GETxPTR ioctl.
52 * reported by Johan Maes <joma@telindus.be>
53 * 22.03.1999 0.10 return EAGAIN instead of EBUSY when O_NONBLOCK
54 * read/write cannot be executed
55 * 07.04.1999 0.11 implemented the following ioctl's: SOUND_PCM_READ_RATE,
56 * SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
57 * Alpha fixes reported by Peter Jones <pjones@redhat.com>
58 * Another Alpha fix (wait_src_ready in init routine)
59 * reported by "Ivan N. Kokshaysky" <ink@jurassic.park.msu.ru>
60 * Note: joystick address handling might still be wrong on archs
61 * other than i386
62 * 15.06.1999 0.12 Fix bad allocation bug.
63 * Thanks to Deti Fliegl <fliegl@in.tum.de>
64 * 28.06.1999 0.13 Add pci_set_master
65 * 03.08.1999 0.14 adapt to Linus' new __setup/__initcall
66 * added kernel command line option "es1371=joystickaddr"
67 * removed CONFIG_SOUND_ES1371_JOYPORT_BOOT kludge
68 * 10.08.1999 0.15 (Re)added S/PDIF module option for cards revision >= 4.
69 * Initial version by Dave Platt <dplatt@snulbug.mtview.ca.us>.
70 * module_init/__setup fixes
71 * 08.16.1999 0.16 Joe Cotellese <joec@ensoniq.com>
72 * Added detection for ES1371 revision ID so that we can
73 * detect the ES1373 and later parts.
74 * added AC97 #defines for readability
75 * added a /proc file system for dumping hardware state
76 * updated SRC and CODEC w/r functions to accommodate bugs
77 * in some versions of the ES137x chips.
78 * 31.08.1999 0.17 add spin_lock_init
79 * replaced current->state = x with set_current_state(x)
80 * 03.09.1999 0.18 change read semantics for MIDI to match
81 * OSS more closely; remove possible wakeup race
82 * 21.10.1999 0.19 Round sampling rates, requested by
83 * Kasamatsu Kenichi <t29w0267@ip.media.kyoto-u.ac.jp>
84 * 27.10.1999 0.20 Added SigmaTel 3D enhancement string
85 * Codec ID printing changes
86 * 28.10.1999 0.21 More waitqueue races fixed
87 * Joe Cotellese <joec@ensoniq.com>
88 * Changed PCI detection routine so we can more easily
89 * detect ES137x chip and derivatives.
90 * 05.01.2000 0.22 Should now work with rev7 boards; patch by
91 * Eric Lemar, elemar@cs.washington.edu
92 * 08.01.2000 0.23 Prevent some ioctl's from returning bad count values on underrun/overrun;
93 * Tim Janik's BSE (Bedevilled Sound Engine) found this
94 * 07.02.2000 0.24 Use pci_alloc_consistent and pci_register_driver
95 * 07.02.2000 0.25 Use ac97_codec
96 * 01.03.2000 0.26 SPDIF patch by Mikael Bouillot <mikael.bouillot@bigfoot.com>
97 * Use pci_module_init
98 * 21.11.2000 0.27 Initialize dma buffers in poll, otherwise poll may return a bogus mask
99 * 12.12.2000 0.28 More dma buffer initializations, patch from
100 * Tjeerd Mulder <tjeerd.mulder@fujitsu-siemens.com>
101 * 05.01.2001 0.29 Hopefully updates will not be required anymore when Creative bumps
102 * the CT5880 revision.
103 * suggested by Stephan Müller <smueller@chronox.de>
104 * 31.01.2001 0.30 Register/Unregister gameport
105 * Fix SETTRIGGER non OSS API conformity
106 * 14.07.2001 0.31 Add list of laptops needing amplifier control
107 * 03.01.2003 0.32 open_mode fixes from Georg Acher <acher@in.tum.de>
108 */
109
110/*****************************************************************************/
111
112#include <linux/interrupt.h>
113#include <linux/module.h>
114#include <linux/string.h>
115#include <linux/ioport.h>
116#include <linux/sched.h>
117#include <linux/delay.h>
118#include <linux/sound.h>
119#include <linux/slab.h>
120#include <linux/soundcard.h>
121#include <linux/pci.h>
122#include <linux/init.h>
123#include <linux/poll.h>
124#include <linux/bitops.h>
125#include <linux/proc_fs.h>
126#include <linux/spinlock.h>
127#include <linux/smp_lock.h>
128#include <linux/ac97_codec.h>
129#include <linux/gameport.h>
130#include <linux/wait.h>
131
132#include <asm/io.h>
133#include <asm/page.h>
134#include <asm/uaccess.h>
135
136/* --------------------------------------------------------------------- */
137
138#undef OSS_DOCUMENTED_MIXER_SEMANTICS
139#define ES1371_DEBUG
140#define DBG(x) {}
141/*#define DBG(x) {x}*/
142
143/* --------------------------------------------------------------------- */
144
145#ifndef PCI_VENDOR_ID_ENSONIQ
146#define PCI_VENDOR_ID_ENSONIQ 0x1274
147#endif
148
149#ifndef PCI_VENDOR_ID_ECTIVA
150#define PCI_VENDOR_ID_ECTIVA 0x1102
151#endif
152
153#ifndef PCI_DEVICE_ID_ENSONIQ_ES1371
154#define PCI_DEVICE_ID_ENSONIQ_ES1371 0x1371
155#endif
156
157#ifndef PCI_DEVICE_ID_ENSONIQ_CT5880
158#define PCI_DEVICE_ID_ENSONIQ_CT5880 0x5880
159#endif
160
161#ifndef PCI_DEVICE_ID_ECTIVA_EV1938
162#define PCI_DEVICE_ID_ECTIVA_EV1938 0x8938
163#endif
164
165/* ES1371 chip ID */
166/* This is a little confusing because all ES1371 compatible chips have the
167 same DEVICE_ID, the only thing differentiating them is the REV_ID field.
168 This is only significant if you want to enable features on the later parts.
169 Yes, I know it's stupid and why didn't we use the sub IDs?
170*/
171#define ES1371REV_ES1373_A 0x04
172#define ES1371REV_ES1373_B 0x06
173#define ES1371REV_CT5880_A 0x07
174#define CT5880REV_CT5880_C 0x02
175#define CT5880REV_CT5880_D 0x03
176#define ES1371REV_ES1371_B 0x09
177#define EV1938REV_EV1938_A 0x00
178#define ES1371REV_ES1373_8 0x08
179
180#define ES1371_MAGIC ((PCI_VENDOR_ID_ENSONIQ<<16)|PCI_DEVICE_ID_ENSONIQ_ES1371)
181
182#define ES1371_EXTENT 0x40
183#define JOY_EXTENT 8
184
185#define ES1371_REG_CONTROL 0x00
186#define ES1371_REG_STATUS 0x04 /* on the 5880 it is control/status */
187#define ES1371_REG_UART_DATA 0x08
188#define ES1371_REG_UART_STATUS 0x09
189#define ES1371_REG_UART_CONTROL 0x09
190#define ES1371_REG_UART_TEST 0x0a
191#define ES1371_REG_MEMPAGE 0x0c
192#define ES1371_REG_SRCONV 0x10
193#define ES1371_REG_CODEC 0x14
194#define ES1371_REG_LEGACY 0x18
195#define ES1371_REG_SERIAL_CONTROL 0x20
196#define ES1371_REG_DAC1_SCOUNT 0x24
197#define ES1371_REG_DAC2_SCOUNT 0x28
198#define ES1371_REG_ADC_SCOUNT 0x2c
199
200#define ES1371_REG_DAC1_FRAMEADR 0xc30
201#define ES1371_REG_DAC1_FRAMECNT 0xc34
202#define ES1371_REG_DAC2_FRAMEADR 0xc38
203#define ES1371_REG_DAC2_FRAMECNT 0xc3c
204#define ES1371_REG_ADC_FRAMEADR 0xd30
205#define ES1371_REG_ADC_FRAMECNT 0xd34
206
207#define ES1371_FMT_U8_MONO 0
208#define ES1371_FMT_U8_STEREO 1
209#define ES1371_FMT_S16_MONO 2
210#define ES1371_FMT_S16_STEREO 3
211#define ES1371_FMT_STEREO 1
212#define ES1371_FMT_S16 2
213#define ES1371_FMT_MASK 3
214
215static const unsigned sample_size[] = { 1, 2, 2, 4 };
216static const unsigned sample_shift[] = { 0, 1, 1, 2 };
217
218#define CTRL_RECEN_B 0x08000000 /* 1 = don't mix analog in to digital out */
219#define CTRL_SPDIFEN_B 0x04000000
220#define CTRL_JOY_SHIFT 24
221#define CTRL_JOY_MASK 3
222#define CTRL_JOY_200 0x00000000 /* joystick base address */
223#define CTRL_JOY_208 0x01000000
224#define CTRL_JOY_210 0x02000000
225#define CTRL_JOY_218 0x03000000
226#define CTRL_GPIO_IN0 0x00100000 /* general purpose inputs/outputs */
227#define CTRL_GPIO_IN1 0x00200000
228#define CTRL_GPIO_IN2 0x00400000
229#define CTRL_GPIO_IN3 0x00800000
230#define CTRL_GPIO_OUT0 0x00010000
231#define CTRL_GPIO_OUT1 0x00020000
232#define CTRL_GPIO_OUT2 0x00040000
233#define CTRL_GPIO_OUT3 0x00080000
234#define CTRL_MSFMTSEL 0x00008000 /* MPEG serial data fmt: 0 = Sony, 1 = I2S */
235#define CTRL_SYNCRES 0x00004000 /* AC97 warm reset */
236#define CTRL_ADCSTOP 0x00002000 /* stop ADC transfers */
237#define CTRL_PWR_INTRM 0x00001000 /* 1 = power level ints enabled */
238#define CTRL_M_CB 0x00000800 /* recording source: 0 = ADC, 1 = MPEG */
239#define CTRL_CCB_INTRM 0x00000400 /* 1 = CCB "voice" ints enabled */
240#define CTRL_PDLEV0 0x00000000 /* power down level */
241#define CTRL_PDLEV1 0x00000100
242#define CTRL_PDLEV2 0x00000200
243#define CTRL_PDLEV3 0x00000300
244#define CTRL_BREQ 0x00000080 /* 1 = test mode (internal mem test) */
245#define CTRL_DAC1_EN 0x00000040 /* enable DAC1 */
246#define CTRL_DAC2_EN 0x00000020 /* enable DAC2 */
247#define CTRL_ADC_EN 0x00000010 /* enable ADC */
248#define CTRL_UART_EN 0x00000008 /* enable MIDI uart */
249#define CTRL_JYSTK_EN 0x00000004 /* enable Joystick port */
250#define CTRL_XTALCLKDIS 0x00000002 /* 1 = disable crystal clock input */
251#define CTRL_PCICLKDIS 0x00000001 /* 1 = disable PCI clock distribution */
252
253
254#define STAT_INTR 0x80000000 /* wired or of all interrupt bits */
255#define CSTAT_5880_AC97_RST 0x20000000 /* CT5880 Reset bit */
256#define STAT_EN_SPDIF 0x00040000 /* enable S/PDIF circuitry */
257#define STAT_TS_SPDIF 0x00020000 /* test S/PDIF circuitry */
258#define STAT_TESTMODE 0x00010000 /* test ASIC */
259#define STAT_SYNC_ERR 0x00000100 /* 1 = codec sync error */
260#define STAT_VC 0x000000c0 /* CCB int source, 0=DAC1, 1=DAC2, 2=ADC, 3=undef */
261#define STAT_SH_VC 6
262#define STAT_MPWR 0x00000020 /* power level interrupt */
263#define STAT_MCCB 0x00000010 /* CCB int pending */
264#define STAT_UART 0x00000008 /* UART int pending */
265#define STAT_DAC1 0x00000004 /* DAC1 int pending */
266#define STAT_DAC2 0x00000002 /* DAC2 int pending */
267#define STAT_ADC 0x00000001 /* ADC int pending */
268
269#define USTAT_RXINT 0x80 /* UART rx int pending */
270#define USTAT_TXINT 0x04 /* UART tx int pending */
271#define USTAT_TXRDY 0x02 /* UART tx ready */
272#define USTAT_RXRDY 0x01 /* UART rx ready */
273
274#define UCTRL_RXINTEN 0x80 /* 1 = enable RX ints */
275#define UCTRL_TXINTEN 0x60 /* TX int enable field mask */
276#define UCTRL_ENA_TXINT 0x20 /* enable TX int */
277#define UCTRL_CNTRL 0x03 /* control field */
278#define UCTRL_CNTRL_SWR 0x03 /* software reset command */
279
280/* sample rate converter */
281#define SRC_OKSTATE 1
282
283#define SRC_RAMADDR_MASK 0xfe000000
284#define SRC_RAMADDR_SHIFT 25
285#define SRC_DAC1FREEZE (1UL << 21)
286#define SRC_DAC2FREEZE (1UL << 20)
287#define SRC_ADCFREEZE (1UL << 19)
288
289
290#define SRC_WE 0x01000000 /* read/write control for SRC RAM */
291#define SRC_BUSY 0x00800000 /* SRC busy */
292#define SRC_DIS 0x00400000 /* 1 = disable SRC */
293#define SRC_DDAC1 0x00200000 /* 1 = disable accum update for DAC1 */
294#define SRC_DDAC2 0x00100000 /* 1 = disable accum update for DAC2 */
295#define SRC_DADC 0x00080000 /* 1 = disable accum update for ADC2 */
296#define SRC_CTLMASK 0x00780000
297#define SRC_RAMDATA_MASK 0x0000ffff
298#define SRC_RAMDATA_SHIFT 0
299
300#define SRCREG_ADC 0x78
301#define SRCREG_DAC1 0x70
302#define SRCREG_DAC2 0x74
303#define SRCREG_VOL_ADC 0x6c
304#define SRCREG_VOL_DAC1 0x7c
305#define SRCREG_VOL_DAC2 0x7e
306
307#define SRCREG_TRUNC_N 0x00
308#define SRCREG_INT_REGS 0x01
309#define SRCREG_ACCUM_FRAC 0x02
310#define SRCREG_VFREQ_FRAC 0x03
311
312#define CODEC_PIRD 0x00800000 /* 0 = write AC97 register */
313#define CODEC_PIADD_MASK 0x007f0000
314#define CODEC_PIADD_SHIFT 16
315#define CODEC_PIDAT_MASK 0x0000ffff
316#define CODEC_PIDAT_SHIFT 0
317
318#define CODEC_RDY 0x80000000 /* AC97 read data valid */
319#define CODEC_WIP 0x40000000 /* AC97 write in progress */
320#define CODEC_PORD 0x00800000 /* 0 = write AC97 register */
321#define CODEC_POADD_MASK 0x007f0000
322#define CODEC_POADD_SHIFT 16
323#define CODEC_PODAT_MASK 0x0000ffff
324#define CODEC_PODAT_SHIFT 0
325
326
327#define LEGACY_JFAST 0x80000000 /* fast joystick timing */
328#define LEGACY_FIRQ 0x01000000 /* force IRQ */
329
330#define SCTRL_DACTEST 0x00400000 /* 1 = DAC test, test vector generation purposes */
331#define SCTRL_P2ENDINC 0x00380000 /* */
332#define SCTRL_SH_P2ENDINC 19
333#define SCTRL_P2STINC 0x00070000 /* */
334#define SCTRL_SH_P2STINC 16
335#define SCTRL_R1LOOPSEL 0x00008000 /* 0 = loop mode */
336#define SCTRL_P2LOOPSEL 0x00004000 /* 0 = loop mode */
337#define SCTRL_P1LOOPSEL 0x00002000 /* 0 = loop mode */
338#define SCTRL_P2PAUSE 0x00001000 /* 1 = pause mode */
339#define SCTRL_P1PAUSE 0x00000800 /* 1 = pause mode */
340#define SCTRL_R1INTEN 0x00000400 /* enable interrupt */
341#define SCTRL_P2INTEN 0x00000200 /* enable interrupt */
342#define SCTRL_P1INTEN 0x00000100 /* enable interrupt */
343#define SCTRL_P1SCTRLD 0x00000080 /* reload sample count register for DAC1 */
344#define SCTRL_P2DACSEN 0x00000040 /* 1 = DAC2 play back last sample when disabled */
345#define SCTRL_R1SEB 0x00000020 /* 1 = 16bit */
346#define SCTRL_R1SMB 0x00000010 /* 1 = stereo */
347#define SCTRL_R1FMT 0x00000030 /* format mask */
348#define SCTRL_SH_R1FMT 4
349#define SCTRL_P2SEB 0x00000008 /* 1 = 16bit */
350#define SCTRL_P2SMB 0x00000004 /* 1 = stereo */
351#define SCTRL_P2FMT 0x0000000c /* format mask */
352#define SCTRL_SH_P2FMT 2
353#define SCTRL_P1SEB 0x00000002 /* 1 = 16bit */
354#define SCTRL_P1SMB 0x00000001 /* 1 = stereo */
355#define SCTRL_P1FMT 0x00000003 /* format mask */
356#define SCTRL_SH_P1FMT 0
357
358
359/* misc stuff */
360#define POLL_COUNT 0x1000
361#define FMODE_DAC 4 /* slight misuse of mode_t */
362
363/* MIDI buffer sizes */
364
365#define MIDIINBUF 256
366#define MIDIOUTBUF 256
367
368#define FMODE_MIDI_SHIFT 3
369#define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
370#define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
371
372#define ES1371_MODULE_NAME "es1371"
373#define PFX ES1371_MODULE_NAME ": "
374
375/* --------------------------------------------------------------------- */
376
377struct es1371_state {
378 /* magic */
379 unsigned int magic;
380
381 /* list of es1371 devices */
382 struct list_head devs;
383
384 /* the corresponding pci_dev structure */
385 struct pci_dev *dev;
386
387 /* soundcore stuff */
388 int dev_audio;
389 int dev_dac;
390 int dev_midi;
391
392 /* hardware resources */
393 unsigned long io; /* long for SPARC */
394 unsigned int irq;
395
396 /* PCI ID's */
397 u16 vendor;
398 u16 device;
399 u8 rev; /* the chip revision */
400
401 /* options */
402 int spdif_volume; /* S/PDIF output is enabled if != -1 */
403
404#ifdef ES1371_DEBUG
405 /* debug /proc entry */
406 struct proc_dir_entry *ps;
407#endif /* ES1371_DEBUG */
408
409 struct ac97_codec *codec;
410
411 /* wave stuff */
412 unsigned ctrl;
413 unsigned sctrl;
414 unsigned dac1rate, dac2rate, adcrate;
415
416 spinlock_t lock;
417 struct semaphore open_sem;
418 mode_t open_mode;
419 wait_queue_head_t open_wait;
420
421 struct dmabuf {
422 void *rawbuf;
423 dma_addr_t dmaaddr;
424 unsigned buforder;
425 unsigned numfrag;
426 unsigned fragshift;
427 unsigned hwptr, swptr;
428 unsigned total_bytes;
429 int count;
430 unsigned error; /* over/underrun */
431 wait_queue_head_t wait;
432 /* redundant, but makes calculations easier */
433 unsigned fragsize;
434 unsigned dmasize;
435 unsigned fragsamples;
436 /* OSS stuff */
437 unsigned mapped:1;
438 unsigned ready:1;
439 unsigned endcleared:1;
440 unsigned enabled:1;
441 unsigned ossfragshift;
442 int ossmaxfrags;
443 unsigned subdivision;
444 } dma_dac1, dma_dac2, dma_adc;
445
446 /* midi stuff */
447 struct {
448 unsigned ird, iwr, icnt;
449 unsigned ord, owr, ocnt;
450 wait_queue_head_t iwait;
451 wait_queue_head_t owait;
452 unsigned char ibuf[MIDIINBUF];
453 unsigned char obuf[MIDIOUTBUF];
454 } midi;
455
456 struct gameport *gameport;
457 struct semaphore sem;
458};
459
460/* --------------------------------------------------------------------- */
461
462static LIST_HEAD(devs);
463
464/* --------------------------------------------------------------------- */
465
466static inline unsigned ld2(unsigned int x)
467{
468 unsigned r = 0;
469
470 if (x >= 0x10000) {
471 x >>= 16;
472 r += 16;
473 }
474 if (x >= 0x100) {
475 x >>= 8;
476 r += 8;
477 }
478 if (x >= 0x10) {
479 x >>= 4;
480 r += 4;
481 }
482 if (x >= 4) {
483 x >>= 2;
484 r += 2;
485 }
486 if (x >= 2)
487 r++;
488 return r;
489}
490
491/* --------------------------------------------------------------------- */
492
493static unsigned wait_src_ready(struct es1371_state *s)
494{
495 unsigned int t, r;
496
497 for (t = 0; t < POLL_COUNT; t++) {
498 if (!((r = inl(s->io + ES1371_REG_SRCONV)) & SRC_BUSY))
499 return r;
500 udelay(1);
501 }
502 printk(KERN_DEBUG PFX "sample rate converter timeout r = 0x%08x\n", r);
503 return r;
504}
505
506static unsigned src_read(struct es1371_state *s, unsigned reg)
507{
508 unsigned int temp,i,orig;
509
510 /* wait for ready */
511 temp = wait_src_ready (s);
512
513 /* we can only access the SRC at certain times, make sure
514 we're allowed to before we read */
515
516 orig = temp;
517 /* expose the SRC state bits */
518 outl ( (temp & SRC_CTLMASK) | (reg << SRC_RAMADDR_SHIFT) | 0x10000UL,
519 s->io + ES1371_REG_SRCONV);
520
521 /* now, wait for busy and the correct time to read */
522 temp = wait_src_ready (s);
523
524 if ( (temp & 0x00870000UL ) != ( SRC_OKSTATE << 16 )){
525 /* wait for the right state */
526 for (i=0; i<POLL_COUNT; i++){
527 temp = inl (s->io + ES1371_REG_SRCONV);
528 if ( (temp & 0x00870000UL ) == ( SRC_OKSTATE << 16 ))
529 break;
530 }
531 }
532
533 /* hide the state bits */
534 outl ((orig & SRC_CTLMASK) | (reg << SRC_RAMADDR_SHIFT), s->io + ES1371_REG_SRCONV);
535 return temp;
536
537
538}
539
540static void src_write(struct es1371_state *s, unsigned reg, unsigned data)
541{
542
543 unsigned int r;
544
545 r = wait_src_ready(s) & (SRC_DIS | SRC_DDAC1 | SRC_DDAC2 | SRC_DADC);
546 r |= (reg << SRC_RAMADDR_SHIFT) & SRC_RAMADDR_MASK;
547 r |= (data << SRC_RAMDATA_SHIFT) & SRC_RAMDATA_MASK;
548 outl(r | SRC_WE, s->io + ES1371_REG_SRCONV);
549
550}
551
552/* --------------------------------------------------------------------- */
553
554/* most of the following here is black magic */
555static void set_adc_rate(struct es1371_state *s, unsigned rate)
556{
557 unsigned long flags;
558 unsigned int n, truncm, freq;
559
560 if (rate > 48000)
561 rate = 48000;
562 if (rate < 4000)
563 rate = 4000;
564 n = rate / 3000;
565 if ((1 << n) & ((1 << 15) | (1 << 13) | (1 << 11) | (1 << 9)))
566 n--;
567 truncm = (21 * n - 1) | 1;
568 freq = ((48000UL << 15) / rate) * n;
569 s->adcrate = (48000UL << 15) / (freq / n);
570 spin_lock_irqsave(&s->lock, flags);
571 if (rate >= 24000) {
572 if (truncm > 239)
573 truncm = 239;
574 src_write(s, SRCREG_ADC+SRCREG_TRUNC_N,
575 (((239 - truncm) >> 1) << 9) | (n << 4));
576 } else {
577 if (truncm > 119)
578 truncm = 119;
579 src_write(s, SRCREG_ADC+SRCREG_TRUNC_N,
580 0x8000 | (((119 - truncm) >> 1) << 9) | (n << 4));
581 }
582 src_write(s, SRCREG_ADC+SRCREG_INT_REGS,
583 (src_read(s, SRCREG_ADC+SRCREG_INT_REGS) & 0x00ff) |
584 ((freq >> 5) & 0xfc00));
585 src_write(s, SRCREG_ADC+SRCREG_VFREQ_FRAC, freq & 0x7fff);
586 src_write(s, SRCREG_VOL_ADC, n << 8);
587 src_write(s, SRCREG_VOL_ADC+1, n << 8);
588 spin_unlock_irqrestore(&s->lock, flags);
589}
590
591
592static void set_dac1_rate(struct es1371_state *s, unsigned rate)
593{
594 unsigned long flags;
595 unsigned int freq, r;
596
597 if (rate > 48000)
598 rate = 48000;
599 if (rate < 4000)
600 rate = 4000;
601 freq = ((rate << 15) + 1500) / 3000;
602 s->dac1rate = (freq * 3000 + 16384) >> 15;
603 spin_lock_irqsave(&s->lock, flags);
604 r = (wait_src_ready(s) & (SRC_DIS | SRC_DDAC2 | SRC_DADC)) | SRC_DDAC1;
605 outl(r, s->io + ES1371_REG_SRCONV);
606 src_write(s, SRCREG_DAC1+SRCREG_INT_REGS,
607 (src_read(s, SRCREG_DAC1+SRCREG_INT_REGS) & 0x00ff) |
608 ((freq >> 5) & 0xfc00));
609 src_write(s, SRCREG_DAC1+SRCREG_VFREQ_FRAC, freq & 0x7fff);
610 r = (wait_src_ready(s) & (SRC_DIS | SRC_DDAC2 | SRC_DADC));
611 outl(r, s->io + ES1371_REG_SRCONV);
612 spin_unlock_irqrestore(&s->lock, flags);
613}
614
615static void set_dac2_rate(struct es1371_state *s, unsigned rate)
616{
617 unsigned long flags;
618 unsigned int freq, r;
619
620 if (rate > 48000)
621 rate = 48000;
622 if (rate < 4000)
623 rate = 4000;
624 freq = ((rate << 15) + 1500) / 3000;
625 s->dac2rate = (freq * 3000 + 16384) >> 15;
626 spin_lock_irqsave(&s->lock, flags);
627 r = (wait_src_ready(s) & (SRC_DIS | SRC_DDAC1 | SRC_DADC)) | SRC_DDAC2;
628 outl(r, s->io + ES1371_REG_SRCONV);
629 src_write(s, SRCREG_DAC2+SRCREG_INT_REGS,
630 (src_read(s, SRCREG_DAC2+SRCREG_INT_REGS) & 0x00ff) |
631 ((freq >> 5) & 0xfc00));
632 src_write(s, SRCREG_DAC2+SRCREG_VFREQ_FRAC, freq & 0x7fff);
633 r = (wait_src_ready(s) & (SRC_DIS | SRC_DDAC1 | SRC_DADC));
634 outl(r, s->io + ES1371_REG_SRCONV);
635 spin_unlock_irqrestore(&s->lock, flags);
636}
637
638/* --------------------------------------------------------------------- */
639
640static void __devinit src_init(struct es1371_state *s)
641{
642 unsigned int i;
643
644 /* before we enable or disable the SRC we need
645 to wait for it to become ready */
646 wait_src_ready(s);
647
648 outl(SRC_DIS, s->io + ES1371_REG_SRCONV);
649
650 for (i = 0; i < 0x80; i++)
651 src_write(s, i, 0);
652
653 src_write(s, SRCREG_DAC1+SRCREG_TRUNC_N, 16 << 4);
654 src_write(s, SRCREG_DAC1+SRCREG_INT_REGS, 16 << 10);
655 src_write(s, SRCREG_DAC2+SRCREG_TRUNC_N, 16 << 4);
656 src_write(s, SRCREG_DAC2+SRCREG_INT_REGS, 16 << 10);
657 src_write(s, SRCREG_VOL_ADC, 1 << 12);
658 src_write(s, SRCREG_VOL_ADC+1, 1 << 12);
659 src_write(s, SRCREG_VOL_DAC1, 1 << 12);
660 src_write(s, SRCREG_VOL_DAC1+1, 1 << 12);
661 src_write(s, SRCREG_VOL_DAC2, 1 << 12);
662 src_write(s, SRCREG_VOL_DAC2+1, 1 << 12);
663 set_adc_rate(s, 22050);
664 set_dac1_rate(s, 22050);
665 set_dac2_rate(s, 22050);
666
667 /* WARNING:
668 * enabling the sample rate converter without properly programming
669 * its parameters causes the chip to lock up (the SRC busy bit will
670 * be stuck high, and I've found no way to rectify this other than
671 * power cycle)
672 */
673 wait_src_ready(s);
674 outl(0, s->io+ES1371_REG_SRCONV);
675}
676
677/* --------------------------------------------------------------------- */
678
679static void wrcodec(struct ac97_codec *codec, u8 addr, u16 data)
680{
681 struct es1371_state *s = (struct es1371_state *)codec->private_data;
682 unsigned long flags;
683 unsigned t, x;
684
685 spin_lock_irqsave(&s->lock, flags);
686 for (t = 0; t < POLL_COUNT; t++)
687 if (!(inl(s->io+ES1371_REG_CODEC) & CODEC_WIP))
688 break;
689
690 /* save the current state for later */
691 x = wait_src_ready(s);
692
693 /* enable SRC state data in SRC mux */
694 outl((x & (SRC_DIS | SRC_DDAC1 | SRC_DDAC2 | SRC_DADC)) | 0x00010000,
695 s->io+ES1371_REG_SRCONV);
696
697 /* wait for not busy (state 0) first to avoid
698 transition states */
699 for (t=0; t<POLL_COUNT; t++){
700 if((inl(s->io+ES1371_REG_SRCONV) & 0x00870000) ==0 )
701 break;
702 udelay(1);
703 }
704
705 /* wait for a SAFE time to write addr/data and then do it, dammit */
706 for (t=0; t<POLL_COUNT; t++){
707 if((inl(s->io+ES1371_REG_SRCONV) & 0x00870000) ==0x00010000)
708 break;
709 udelay(1);
710 }
711
712 outl(((addr << CODEC_POADD_SHIFT) & CODEC_POADD_MASK) |
713 ((data << CODEC_PODAT_SHIFT) & CODEC_PODAT_MASK), s->io+ES1371_REG_CODEC);
714
715 /* restore SRC reg */
716 wait_src_ready(s);
717 outl(x, s->io+ES1371_REG_SRCONV);
718 spin_unlock_irqrestore(&s->lock, flags);
719}
720
721static u16 rdcodec(struct ac97_codec *codec, u8 addr)
722{
723 struct es1371_state *s = (struct es1371_state *)codec->private_data;
724 unsigned long flags;
725 unsigned t, x;
726
727 spin_lock_irqsave(&s->lock, flags);
728
729 /* wait for WIP to go away */
730 for (t = 0; t < 0x1000; t++)
731 if (!(inl(s->io+ES1371_REG_CODEC) & CODEC_WIP))
732 break;
733
734 /* save the current state for later */
735 x = (wait_src_ready(s) & (SRC_DIS | SRC_DDAC1 | SRC_DDAC2 | SRC_DADC));
736
737 /* enable SRC state data in SRC mux */
738 outl( x | 0x00010000,
739 s->io+ES1371_REG_SRCONV);
740
741 /* wait for not busy (state 0) first to avoid
742 transition states */
743 for (t=0; t<POLL_COUNT; t++){
744 if((inl(s->io+ES1371_REG_SRCONV) & 0x00870000) ==0 )
745 break;
746 udelay(1);
747 }
748
749 /* wait for a SAFE time to write addr/data and then do it, dammit */
750 for (t=0; t<POLL_COUNT; t++){
751 if((inl(s->io+ES1371_REG_SRCONV) & 0x00870000) ==0x00010000)
752 break;
753 udelay(1);
754 }
755
756 outl(((addr << CODEC_POADD_SHIFT) & CODEC_POADD_MASK) | CODEC_PORD, s->io+ES1371_REG_CODEC);
757 /* restore SRC reg */
758 wait_src_ready(s);
759 outl(x, s->io+ES1371_REG_SRCONV);
760
761 /* wait for WIP again */
762 for (t = 0; t < 0x1000; t++)
763 if (!(inl(s->io+ES1371_REG_CODEC) & CODEC_WIP))
764 break;
765
766 /* now wait for the stinkin' data (RDY) */
767 for (t = 0; t < POLL_COUNT; t++)
768 if ((x = inl(s->io+ES1371_REG_CODEC)) & CODEC_RDY)
769 break;
770
771 spin_unlock_irqrestore(&s->lock, flags);
772 return ((x & CODEC_PIDAT_MASK) >> CODEC_PIDAT_SHIFT);
773}
774
775/* --------------------------------------------------------------------- */
776
777static inline void stop_adc(struct es1371_state *s)
778{
779 unsigned long flags;
780
781 spin_lock_irqsave(&s->lock, flags);
782 s->ctrl &= ~CTRL_ADC_EN;
783 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
784 spin_unlock_irqrestore(&s->lock, flags);
785}
786
787static inline void stop_dac1(struct es1371_state *s)
788{
789 unsigned long flags;
790
791 spin_lock_irqsave(&s->lock, flags);
792 s->ctrl &= ~CTRL_DAC1_EN;
793 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
794 spin_unlock_irqrestore(&s->lock, flags);
795}
796
797static inline void stop_dac2(struct es1371_state *s)
798{
799 unsigned long flags;
800
801 spin_lock_irqsave(&s->lock, flags);
802 s->ctrl &= ~CTRL_DAC2_EN;
803 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
804 spin_unlock_irqrestore(&s->lock, flags);
805}
806
807static void start_dac1(struct es1371_state *s)
808{
809 unsigned long flags;
810 unsigned fragremain, fshift;
811
812 spin_lock_irqsave(&s->lock, flags);
813 if (!(s->ctrl & CTRL_DAC1_EN) && (s->dma_dac1.mapped || s->dma_dac1.count > 0)
814 && s->dma_dac1.ready) {
815 s->ctrl |= CTRL_DAC1_EN;
816 s->sctrl = (s->sctrl & ~(SCTRL_P1LOOPSEL | SCTRL_P1PAUSE | SCTRL_P1SCTRLD)) | SCTRL_P1INTEN;
817 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
818 fragremain = ((- s->dma_dac1.hwptr) & (s->dma_dac1.fragsize-1));
819 fshift = sample_shift[(s->sctrl & SCTRL_P1FMT) >> SCTRL_SH_P1FMT];
820 if (fragremain < 2*fshift)
821 fragremain = s->dma_dac1.fragsize;
822 outl((fragremain >> fshift) - 1, s->io+ES1371_REG_DAC1_SCOUNT);
823 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
824 outl((s->dma_dac1.fragsize >> fshift) - 1, s->io+ES1371_REG_DAC1_SCOUNT);
825 }
826 spin_unlock_irqrestore(&s->lock, flags);
827}
828
829static void start_dac2(struct es1371_state *s)
830{
831 unsigned long flags;
832 unsigned fragremain, fshift;
833
834 spin_lock_irqsave(&s->lock, flags);
835 if (!(s->ctrl & CTRL_DAC2_EN) && (s->dma_dac2.mapped || s->dma_dac2.count > 0)
836 && s->dma_dac2.ready) {
837 s->ctrl |= CTRL_DAC2_EN;
838 s->sctrl = (s->sctrl & ~(SCTRL_P2LOOPSEL | SCTRL_P2PAUSE | SCTRL_P2DACSEN |
839 SCTRL_P2ENDINC | SCTRL_P2STINC)) | SCTRL_P2INTEN |
840 (((s->sctrl & SCTRL_P2FMT) ? 2 : 1) << SCTRL_SH_P2ENDINC) |
841 (0 << SCTRL_SH_P2STINC);
842 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
843 fragremain = ((- s->dma_dac2.hwptr) & (s->dma_dac2.fragsize-1));
844 fshift = sample_shift[(s->sctrl & SCTRL_P2FMT) >> SCTRL_SH_P2FMT];
845 if (fragremain < 2*fshift)
846 fragremain = s->dma_dac2.fragsize;
847 outl((fragremain >> fshift) - 1, s->io+ES1371_REG_DAC2_SCOUNT);
848 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
849 outl((s->dma_dac2.fragsize >> fshift) - 1, s->io+ES1371_REG_DAC2_SCOUNT);
850 }
851 spin_unlock_irqrestore(&s->lock, flags);
852}
853
854static void start_adc(struct es1371_state *s)
855{
856 unsigned long flags;
857 unsigned fragremain, fshift;
858
859 spin_lock_irqsave(&s->lock, flags);
860 if (!(s->ctrl & CTRL_ADC_EN) && (s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
861 && s->dma_adc.ready) {
862 s->ctrl |= CTRL_ADC_EN;
863 s->sctrl = (s->sctrl & ~SCTRL_R1LOOPSEL) | SCTRL_R1INTEN;
864 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
865 fragremain = ((- s->dma_adc.hwptr) & (s->dma_adc.fragsize-1));
866 fshift = sample_shift[(s->sctrl & SCTRL_R1FMT) >> SCTRL_SH_R1FMT];
867 if (fragremain < 2*fshift)
868 fragremain = s->dma_adc.fragsize;
869 outl((fragremain >> fshift) - 1, s->io+ES1371_REG_ADC_SCOUNT);
870 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
871 outl((s->dma_adc.fragsize >> fshift) - 1, s->io+ES1371_REG_ADC_SCOUNT);
872 }
873 spin_unlock_irqrestore(&s->lock, flags);
874}
875
876/* --------------------------------------------------------------------- */
877
878#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
879#define DMABUF_MINORDER 1
880
881
882static inline void dealloc_dmabuf(struct es1371_state *s, struct dmabuf *db)
883{
884 struct page *page, *pend;
885
886 if (db->rawbuf) {
887 /* undo marking the pages as reserved */
888 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
889 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
890 ClearPageReserved(page);
891 pci_free_consistent(s->dev, PAGE_SIZE << db->buforder, db->rawbuf, db->dmaaddr);
892 }
893 db->rawbuf = NULL;
894 db->mapped = db->ready = 0;
895}
896
897static int prog_dmabuf(struct es1371_state *s, struct dmabuf *db, unsigned rate, unsigned fmt, unsigned reg)
898{
899 int order;
900 unsigned bytepersec;
901 unsigned bufs;
902 struct page *page, *pend;
903
904 db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
905 if (!db->rawbuf) {
906 db->ready = db->mapped = 0;
907 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--)
908 if ((db->rawbuf = pci_alloc_consistent(s->dev, PAGE_SIZE << order, &db->dmaaddr)))
909 break;
910 if (!db->rawbuf)
911 return -ENOMEM;
912 db->buforder = order;
913 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
914 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
915 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
916 SetPageReserved(page);
917 }
918 fmt &= ES1371_FMT_MASK;
919 bytepersec = rate << sample_shift[fmt];
920 bufs = PAGE_SIZE << db->buforder;
921 if (db->ossfragshift) {
922 if ((1000 << db->ossfragshift) < bytepersec)
923 db->fragshift = ld2(bytepersec/1000);
924 else
925 db->fragshift = db->ossfragshift;
926 } else {
927 db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
928 if (db->fragshift < 3)
929 db->fragshift = 3;
930 }
931 db->numfrag = bufs >> db->fragshift;
932 while (db->numfrag < 4 && db->fragshift > 3) {
933 db->fragshift--;
934 db->numfrag = bufs >> db->fragshift;
935 }
936 db->fragsize = 1 << db->fragshift;
937 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
938 db->numfrag = db->ossmaxfrags;
939 db->fragsamples = db->fragsize >> sample_shift[fmt];
940 db->dmasize = db->numfrag << db->fragshift;
941 memset(db->rawbuf, (fmt & ES1371_FMT_S16) ? 0 : 0x80, db->dmasize);
942 outl((reg >> 8) & 15, s->io+ES1371_REG_MEMPAGE);
943 outl(db->dmaaddr, s->io+(reg & 0xff));
944 outl((db->dmasize >> 2)-1, s->io+((reg + 4) & 0xff));
945 db->enabled = 1;
946 db->ready = 1;
947 return 0;
948}
949
950static inline int prog_dmabuf_adc(struct es1371_state *s)
951{
952 stop_adc(s);
953 return prog_dmabuf(s, &s->dma_adc, s->adcrate, (s->sctrl >> SCTRL_SH_R1FMT) & ES1371_FMT_MASK,
954 ES1371_REG_ADC_FRAMEADR);
955}
956
957static inline int prog_dmabuf_dac2(struct es1371_state *s)
958{
959 stop_dac2(s);
960 return prog_dmabuf(s, &s->dma_dac2, s->dac2rate, (s->sctrl >> SCTRL_SH_P2FMT) & ES1371_FMT_MASK,
961 ES1371_REG_DAC2_FRAMEADR);
962}
963
964static inline int prog_dmabuf_dac1(struct es1371_state *s)
965{
966 stop_dac1(s);
967 return prog_dmabuf(s, &s->dma_dac1, s->dac1rate, (s->sctrl >> SCTRL_SH_P1FMT) & ES1371_FMT_MASK,
968 ES1371_REG_DAC1_FRAMEADR);
969}
970
971static inline unsigned get_hwptr(struct es1371_state *s, struct dmabuf *db, unsigned reg)
972{
973 unsigned hwptr, diff;
974
975 outl((reg >> 8) & 15, s->io+ES1371_REG_MEMPAGE);
976 hwptr = (inl(s->io+(reg & 0xff)) >> 14) & 0x3fffc;
977 diff = (db->dmasize + hwptr - db->hwptr) % db->dmasize;
978 db->hwptr = hwptr;
979 return diff;
980}
981
982static inline void clear_advance(void *buf, unsigned bsize, unsigned bptr, unsigned len, unsigned char c)
983{
984 if (bptr + len > bsize) {
985 unsigned x = bsize - bptr;
986 memset(((char *)buf) + bptr, c, x);
987 bptr = 0;
988 len -= x;
989 }
990 memset(((char *)buf) + bptr, c, len);
991}
992
993/* call with spinlock held! */
994static void es1371_update_ptr(struct es1371_state *s)
995{
996 int diff;
997
998 /* update ADC pointer */
999 if (s->ctrl & CTRL_ADC_EN) {
1000 diff = get_hwptr(s, &s->dma_adc, ES1371_REG_ADC_FRAMECNT);
1001 s->dma_adc.total_bytes += diff;
1002 s->dma_adc.count += diff;
1003 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1004 wake_up(&s->dma_adc.wait);
1005 if (!s->dma_adc.mapped) {
1006 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
1007 s->ctrl &= ~CTRL_ADC_EN;
1008 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
1009 s->dma_adc.error++;
1010 }
1011 }
1012 }
1013 /* update DAC1 pointer */
1014 if (s->ctrl & CTRL_DAC1_EN) {
1015 diff = get_hwptr(s, &s->dma_dac1, ES1371_REG_DAC1_FRAMECNT);
1016 s->dma_dac1.total_bytes += diff;
1017 if (s->dma_dac1.mapped) {
1018 s->dma_dac1.count += diff;
1019 if (s->dma_dac1.count >= (signed)s->dma_dac1.fragsize)
1020 wake_up(&s->dma_dac1.wait);
1021 } else {
1022 s->dma_dac1.count -= diff;
1023 if (s->dma_dac1.count <= 0) {
1024 s->ctrl &= ~CTRL_DAC1_EN;
1025 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
1026 s->dma_dac1.error++;
1027 } else if (s->dma_dac1.count <= (signed)s->dma_dac1.fragsize && !s->dma_dac1.endcleared) {
1028 clear_advance(s->dma_dac1.rawbuf, s->dma_dac1.dmasize, s->dma_dac1.swptr,
1029 s->dma_dac1.fragsize, (s->sctrl & SCTRL_P1SEB) ? 0 : 0x80);
1030 s->dma_dac1.endcleared = 1;
1031 }
1032 if (s->dma_dac1.count + (signed)s->dma_dac1.fragsize <= (signed)s->dma_dac1.dmasize)
1033 wake_up(&s->dma_dac1.wait);
1034 }
1035 }
1036 /* update DAC2 pointer */
1037 if (s->ctrl & CTRL_DAC2_EN) {
1038 diff = get_hwptr(s, &s->dma_dac2, ES1371_REG_DAC2_FRAMECNT);
1039 s->dma_dac2.total_bytes += diff;
1040 if (s->dma_dac2.mapped) {
1041 s->dma_dac2.count += diff;
1042 if (s->dma_dac2.count >= (signed)s->dma_dac2.fragsize)
1043 wake_up(&s->dma_dac2.wait);
1044 } else {
1045 s->dma_dac2.count -= diff;
1046 if (s->dma_dac2.count <= 0) {
1047 s->ctrl &= ~CTRL_DAC2_EN;
1048 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
1049 s->dma_dac2.error++;
1050 } else if (s->dma_dac2.count <= (signed)s->dma_dac2.fragsize && !s->dma_dac2.endcleared) {
1051 clear_advance(s->dma_dac2.rawbuf, s->dma_dac2.dmasize, s->dma_dac2.swptr,
1052 s->dma_dac2.fragsize, (s->sctrl & SCTRL_P2SEB) ? 0 : 0x80);
1053 s->dma_dac2.endcleared = 1;
1054 }
1055 if (s->dma_dac2.count + (signed)s->dma_dac2.fragsize <= (signed)s->dma_dac2.dmasize)
1056 wake_up(&s->dma_dac2.wait);
1057 }
1058 }
1059}
1060
1061/* hold spinlock for the following! */
1062static void es1371_handle_midi(struct es1371_state *s)
1063{
1064 unsigned char ch;
1065 int wake;
1066
1067 if (!(s->ctrl & CTRL_UART_EN))
1068 return;
1069 wake = 0;
1070 while (inb(s->io+ES1371_REG_UART_STATUS) & USTAT_RXRDY) {
1071 ch = inb(s->io+ES1371_REG_UART_DATA);
1072 if (s->midi.icnt < MIDIINBUF) {
1073 s->midi.ibuf[s->midi.iwr] = ch;
1074 s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF;
1075 s->midi.icnt++;
1076 }
1077 wake = 1;
1078 }
1079 if (wake)
1080 wake_up(&s->midi.iwait);
1081 wake = 0;
1082 while ((inb(s->io+ES1371_REG_UART_STATUS) & USTAT_TXRDY) && s->midi.ocnt > 0) {
1083 outb(s->midi.obuf[s->midi.ord], s->io+ES1371_REG_UART_DATA);
1084 s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF;
1085 s->midi.ocnt--;
1086 if (s->midi.ocnt < MIDIOUTBUF-16)
1087 wake = 1;
1088 }
1089 if (wake)
1090 wake_up(&s->midi.owait);
1091 outb((s->midi.ocnt > 0) ? UCTRL_RXINTEN | UCTRL_ENA_TXINT : UCTRL_RXINTEN, s->io+ES1371_REG_UART_CONTROL);
1092}
1093
1094static irqreturn_t es1371_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1095{
1096 struct es1371_state *s = (struct es1371_state *)dev_id;
1097 unsigned int intsrc, sctl;
1098
1099 /* fastpath out, to ease interrupt sharing */
1100 intsrc = inl(s->io+ES1371_REG_STATUS);
1101 if (!(intsrc & 0x80000000))
1102 return IRQ_NONE;
1103 spin_lock(&s->lock);
1104 /* clear audio interrupts first */
1105 sctl = s->sctrl;
1106 if (intsrc & STAT_ADC)
1107 sctl &= ~SCTRL_R1INTEN;
1108 if (intsrc & STAT_DAC1)
1109 sctl &= ~SCTRL_P1INTEN;
1110 if (intsrc & STAT_DAC2)
1111 sctl &= ~SCTRL_P2INTEN;
1112 outl(sctl, s->io+ES1371_REG_SERIAL_CONTROL);
1113 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
1114 es1371_update_ptr(s);
1115 es1371_handle_midi(s);
1116 spin_unlock(&s->lock);
1117 return IRQ_HANDLED;
1118}
1119
1120/* --------------------------------------------------------------------- */
1121
1122static const char invalid_magic[] = KERN_CRIT PFX "invalid magic value\n";
1123
1124#define VALIDATE_STATE(s) \
1125({ \
1126 if (!(s) || (s)->magic != ES1371_MAGIC) { \
1127 printk(invalid_magic); \
1128 return -ENXIO; \
1129 } \
1130})
1131
1132/* --------------------------------------------------------------------- */
1133
1134/* Conversion table for S/PDIF PCM volume emulation through the SRC */
1135/* dB-linear table of DAC vol values; -0dB to -46.5dB with mute */
1136static const unsigned short DACVolTable[101] =
1137{
1138 0x1000, 0x0f2a, 0x0e60, 0x0da0, 0x0cea, 0x0c3e, 0x0b9a, 0x0aff,
1139 0x0a6d, 0x09e1, 0x095e, 0x08e1, 0x086a, 0x07fa, 0x078f, 0x072a,
1140 0x06cb, 0x0670, 0x061a, 0x05c9, 0x057b, 0x0532, 0x04ed, 0x04ab,
1141 0x046d, 0x0432, 0x03fa, 0x03c5, 0x0392, 0x0363, 0x0335, 0x030b,
1142 0x02e2, 0x02bc, 0x0297, 0x0275, 0x0254, 0x0235, 0x0217, 0x01fb,
1143 0x01e1, 0x01c8, 0x01b0, 0x0199, 0x0184, 0x0170, 0x015d, 0x014b,
1144 0x0139, 0x0129, 0x0119, 0x010b, 0x00fd, 0x00f0, 0x00e3, 0x00d7,
1145 0x00cc, 0x00c1, 0x00b7, 0x00ae, 0x00a5, 0x009c, 0x0094, 0x008c,
1146 0x0085, 0x007e, 0x0077, 0x0071, 0x006b, 0x0066, 0x0060, 0x005b,
1147 0x0057, 0x0052, 0x004e, 0x004a, 0x0046, 0x0042, 0x003f, 0x003c,
1148 0x0038, 0x0036, 0x0033, 0x0030, 0x002e, 0x002b, 0x0029, 0x0027,
1149 0x0025, 0x0023, 0x0021, 0x001f, 0x001e, 0x001c, 0x001b, 0x0019,
1150 0x0018, 0x0017, 0x0016, 0x0014, 0x0000
1151};
1152
1153/*
1154 * when we are in S/PDIF mode, we want to disable any analog output so
1155 * we filter the mixer ioctls
1156 */
1157static int mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg)
1158{
1159 struct es1371_state *s = (struct es1371_state *)codec->private_data;
1160 int val;
1161 unsigned long flags;
1162 unsigned int left, right;
1163
1164 VALIDATE_STATE(s);
1165 /* filter mixer ioctls to catch PCM and MASTER volume when in S/PDIF mode */
1166 if (s->spdif_volume == -1)
1167 return codec->mixer_ioctl(codec, cmd, arg);
1168 switch (cmd) {
1169 case SOUND_MIXER_WRITE_VOLUME:
1170 return 0;
1171
1172 case SOUND_MIXER_WRITE_PCM: /* use SRC for PCM volume */
1173 if (get_user(val, (int __user *)arg))
1174 return -EFAULT;
1175 right = ((val >> 8) & 0xff);
1176 left = (val & 0xff);
1177 if (right > 100)
1178 right = 100;
1179 if (left > 100)
1180 left = 100;
1181 s->spdif_volume = (right << 8) | left;
1182 spin_lock_irqsave(&s->lock, flags);
1183 src_write(s, SRCREG_VOL_DAC2, DACVolTable[100 - left]);
1184 src_write(s, SRCREG_VOL_DAC2+1, DACVolTable[100 - right]);
1185 spin_unlock_irqrestore(&s->lock, flags);
1186 return 0;
1187
1188 case SOUND_MIXER_READ_PCM:
1189 return put_user(s->spdif_volume, (int __user *)arg);
1190 }
1191 return codec->mixer_ioctl(codec, cmd, arg);
1192}
1193
1194/* --------------------------------------------------------------------- */
1195
1196/*
1197 * AC97 Mixer Register to Connections mapping of the Concert 97 board
1198 *
1199 * AC97_MASTER_VOL_STEREO Line Out
1200 * AC97_MASTER_VOL_MONO TAD Output
1201 * AC97_PCBEEP_VOL none
1202 * AC97_PHONE_VOL TAD Input (mono)
1203 * AC97_MIC_VOL MIC Input (mono)
1204 * AC97_LINEIN_VOL Line Input (stereo)
1205 * AC97_CD_VOL CD Input (stereo)
1206 * AC97_VIDEO_VOL none
1207 * AC97_AUX_VOL Aux Input (stereo)
1208 * AC97_PCMOUT_VOL Wave Output (stereo)
1209 */
1210
1211static int es1371_open_mixdev(struct inode *inode, struct file *file)
1212{
1213 int minor = iminor(inode);
1214 struct list_head *list;
1215 struct es1371_state *s;
1216
1217 for (list = devs.next; ; list = list->next) {
1218 if (list == &devs)
1219 return -ENODEV;
1220 s = list_entry(list, struct es1371_state, devs);
1221 if (s->codec->dev_mixer == minor)
1222 break;
1223 }
1224 VALIDATE_STATE(s);
1225 file->private_data = s;
1226 return nonseekable_open(inode, file);
1227}
1228
1229static int es1371_release_mixdev(struct inode *inode, struct file *file)
1230{
1231 struct es1371_state *s = (struct es1371_state *)file->private_data;
1232
1233 VALIDATE_STATE(s);
1234 return 0;
1235}
1236
1237static int es1371_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1238{
1239 struct es1371_state *s = (struct es1371_state *)file->private_data;
1240 struct ac97_codec *codec = s->codec;
1241
1242 return mixdev_ioctl(codec, cmd, arg);
1243}
1244
1245static /*const*/ struct file_operations es1371_mixer_fops = {
1246 .owner = THIS_MODULE,
1247 .llseek = no_llseek,
1248 .ioctl = es1371_ioctl_mixdev,
1249 .open = es1371_open_mixdev,
1250 .release = es1371_release_mixdev,
1251};
1252
1253/* --------------------------------------------------------------------- */
1254
1255static int drain_dac1(struct es1371_state *s, int nonblock)
1256{
1257 DECLARE_WAITQUEUE(wait, current);
1258 unsigned long flags;
1259 int count, tmo;
1260
1261 if (s->dma_dac1.mapped || !s->dma_dac1.ready)
1262 return 0;
1263 add_wait_queue(&s->dma_dac1.wait, &wait);
1264 for (;;) {
1265 __set_current_state(TASK_INTERRUPTIBLE);
1266 spin_lock_irqsave(&s->lock, flags);
1267 count = s->dma_dac1.count;
1268 spin_unlock_irqrestore(&s->lock, flags);
1269 if (count <= 0)
1270 break;
1271 if (signal_pending(current))
1272 break;
1273 if (nonblock) {
1274 remove_wait_queue(&s->dma_dac1.wait, &wait);
1275 set_current_state(TASK_RUNNING);
1276 return -EBUSY;
1277 }
1278 tmo = 3 * HZ * (count + s->dma_dac1.fragsize) / 2 / s->dac1rate;
1279 tmo >>= sample_shift[(s->sctrl & SCTRL_P1FMT) >> SCTRL_SH_P1FMT];
1280 if (!schedule_timeout(tmo + 1))
1281 DBG(printk(KERN_DEBUG PFX "dac1 dma timed out??\n");)
1282 }
1283 remove_wait_queue(&s->dma_dac1.wait, &wait);
1284 set_current_state(TASK_RUNNING);
1285 if (signal_pending(current))
1286 return -ERESTARTSYS;
1287 return 0;
1288}
1289
1290static int drain_dac2(struct es1371_state *s, int nonblock)
1291{
1292 DECLARE_WAITQUEUE(wait, current);
1293 unsigned long flags;
1294 int count, tmo;
1295
1296 if (s->dma_dac2.mapped || !s->dma_dac2.ready)
1297 return 0;
1298 add_wait_queue(&s->dma_dac2.wait, &wait);
1299 for (;;) {
1300 __set_current_state(TASK_UNINTERRUPTIBLE);
1301 spin_lock_irqsave(&s->lock, flags);
1302 count = s->dma_dac2.count;
1303 spin_unlock_irqrestore(&s->lock, flags);
1304 if (count <= 0)
1305 break;
1306 if (signal_pending(current))
1307 break;
1308 if (nonblock) {
1309 remove_wait_queue(&s->dma_dac2.wait, &wait);
1310 set_current_state(TASK_RUNNING);
1311 return -EBUSY;
1312 }
1313 tmo = 3 * HZ * (count + s->dma_dac2.fragsize) / 2 / s->dac2rate;
1314 tmo >>= sample_shift[(s->sctrl & SCTRL_P2FMT) >> SCTRL_SH_P2FMT];
1315 if (!schedule_timeout(tmo + 1))
1316 DBG(printk(KERN_DEBUG PFX "dac2 dma timed out??\n");)
1317 }
1318 remove_wait_queue(&s->dma_dac2.wait, &wait);
1319 set_current_state(TASK_RUNNING);
1320 if (signal_pending(current))
1321 return -ERESTARTSYS;
1322 return 0;
1323}
1324
1325/* --------------------------------------------------------------------- */
1326
1327static ssize_t es1371_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1328{
1329 struct es1371_state *s = (struct es1371_state *)file->private_data;
1330 DECLARE_WAITQUEUE(wait, current);
1331 ssize_t ret = 0;
1332 unsigned long flags;
1333 unsigned swptr;
1334 int cnt;
1335
1336 VALIDATE_STATE(s);
1337 if (s->dma_adc.mapped)
1338 return -ENXIO;
1339 if (!access_ok(VERIFY_WRITE, buffer, count))
1340 return -EFAULT;
1341 down(&s->sem);
1342 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1343 goto out2;
1344
1345 add_wait_queue(&s->dma_adc.wait, &wait);
1346 while (count > 0) {
1347 spin_lock_irqsave(&s->lock, flags);
1348 swptr = s->dma_adc.swptr;
1349 cnt = s->dma_adc.dmasize-swptr;
1350 if (s->dma_adc.count < cnt)
1351 cnt = s->dma_adc.count;
1352 if (cnt <= 0)
1353 __set_current_state(TASK_INTERRUPTIBLE);
1354 spin_unlock_irqrestore(&s->lock, flags);
1355 if (cnt > count)
1356 cnt = count;
1357 if (cnt <= 0) {
1358 if (s->dma_adc.enabled)
1359 start_adc(s);
1360 if (file->f_flags & O_NONBLOCK) {
1361 if (!ret)
1362 ret = -EAGAIN;
1363 goto out;
1364 }
1365 up(&s->sem);
1366 schedule();
1367 if (signal_pending(current)) {
1368 if (!ret)
1369 ret = -ERESTARTSYS;
1370 goto out2;
1371 }
1372 down(&s->sem);
1373 if (s->dma_adc.mapped)
1374 {
1375 ret = -ENXIO;
1376 goto out;
1377 }
1378 continue;
1379 }
1380 if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
1381 if (!ret)
1382 ret = -EFAULT;
1383 goto out;
1384 }
1385 swptr = (swptr + cnt) % s->dma_adc.dmasize;
1386 spin_lock_irqsave(&s->lock, flags);
1387 s->dma_adc.swptr = swptr;
1388 s->dma_adc.count -= cnt;
1389 spin_unlock_irqrestore(&s->lock, flags);
1390 count -= cnt;
1391 buffer += cnt;
1392 ret += cnt;
1393 if (s->dma_adc.enabled)
1394 start_adc(s);
1395 }
1396out:
1397 up(&s->sem);
1398out2:
1399 remove_wait_queue(&s->dma_adc.wait, &wait);
1400 set_current_state(TASK_RUNNING);
1401 return ret;
1402}
1403
1404static ssize_t es1371_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1405{
1406 struct es1371_state *s = (struct es1371_state *)file->private_data;
1407 DECLARE_WAITQUEUE(wait, current);
1408 ssize_t ret;
1409 unsigned long flags;
1410 unsigned swptr;
1411 int cnt;
1412
1413 VALIDATE_STATE(s);
1414 if (s->dma_dac2.mapped)
1415 return -ENXIO;
1416 if (!access_ok(VERIFY_READ, buffer, count))
1417 return -EFAULT;
1418 down(&s->sem);
1419 if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
1420 goto out3;
1421 ret = 0;
1422 add_wait_queue(&s->dma_dac2.wait, &wait);
1423 while (count > 0) {
1424 spin_lock_irqsave(&s->lock, flags);
1425 if (s->dma_dac2.count < 0) {
1426 s->dma_dac2.count = 0;
1427 s->dma_dac2.swptr = s->dma_dac2.hwptr;
1428 }
1429 swptr = s->dma_dac2.swptr;
1430 cnt = s->dma_dac2.dmasize-swptr;
1431 if (s->dma_dac2.count + cnt > s->dma_dac2.dmasize)
1432 cnt = s->dma_dac2.dmasize - s->dma_dac2.count;
1433 if (cnt <= 0)
1434 __set_current_state(TASK_INTERRUPTIBLE);
1435 spin_unlock_irqrestore(&s->lock, flags);
1436 if (cnt > count)
1437 cnt = count;
1438 if (cnt <= 0) {
1439 if (s->dma_dac2.enabled)
1440 start_dac2(s);
1441 if (file->f_flags & O_NONBLOCK) {
1442 if (!ret)
1443 ret = -EAGAIN;
1444 goto out;
1445 }
1446 up(&s->sem);
1447 schedule();
1448 if (signal_pending(current)) {
1449 if (!ret)
1450 ret = -ERESTARTSYS;
1451 goto out2;
1452 }
1453 down(&s->sem);
1454 if (s->dma_dac2.mapped)
1455 {
1456 ret = -ENXIO;
1457 goto out;
1458 }
1459 continue;
1460 }
1461 if (copy_from_user(s->dma_dac2.rawbuf + swptr, buffer, cnt)) {
1462 if (!ret)
1463 ret = -EFAULT;
1464 goto out;
1465 }
1466 swptr = (swptr + cnt) % s->dma_dac2.dmasize;
1467 spin_lock_irqsave(&s->lock, flags);
1468 s->dma_dac2.swptr = swptr;
1469 s->dma_dac2.count += cnt;
1470 s->dma_dac2.endcleared = 0;
1471 spin_unlock_irqrestore(&s->lock, flags);
1472 count -= cnt;
1473 buffer += cnt;
1474 ret += cnt;
1475 if (s->dma_dac2.enabled)
1476 start_dac2(s);
1477 }
1478out:
1479 up(&s->sem);
1480out2:
1481 remove_wait_queue(&s->dma_dac2.wait, &wait);
1482out3:
1483 set_current_state(TASK_RUNNING);
1484 return ret;
1485}
1486
1487/* No kernel lock - we have our own spinlock */
1488static unsigned int es1371_poll(struct file *file, struct poll_table_struct *wait)
1489{
1490 struct es1371_state *s = (struct es1371_state *)file->private_data;
1491 unsigned long flags;
1492 unsigned int mask = 0;
1493
1494 VALIDATE_STATE(s);
1495 if (file->f_mode & FMODE_WRITE) {
1496 if (!s->dma_dac2.ready && prog_dmabuf_dac2(s))
1497 return 0;
1498 poll_wait(file, &s->dma_dac2.wait, wait);
1499 }
1500 if (file->f_mode & FMODE_READ) {
1501 if (!s->dma_adc.ready && prog_dmabuf_adc(s))
1502 return 0;
1503 poll_wait(file, &s->dma_adc.wait, wait);
1504 }
1505 spin_lock_irqsave(&s->lock, flags);
1506 es1371_update_ptr(s);
1507 if (file->f_mode & FMODE_READ) {
1508 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1509 mask |= POLLIN | POLLRDNORM;
1510 }
1511 if (file->f_mode & FMODE_WRITE) {
1512 if (s->dma_dac2.mapped) {
1513 if (s->dma_dac2.count >= (signed)s->dma_dac2.fragsize)
1514 mask |= POLLOUT | POLLWRNORM;
1515 } else {
1516 if ((signed)s->dma_dac2.dmasize >= s->dma_dac2.count + (signed)s->dma_dac2.fragsize)
1517 mask |= POLLOUT | POLLWRNORM;
1518 }
1519 }
1520 spin_unlock_irqrestore(&s->lock, flags);
1521 return mask;
1522}
1523
1524static int es1371_mmap(struct file *file, struct vm_area_struct *vma)
1525{
1526 struct es1371_state *s = (struct es1371_state *)file->private_data;
1527 struct dmabuf *db;
1528 int ret = 0;
1529 unsigned long size;
1530
1531 VALIDATE_STATE(s);
1532 lock_kernel();
1533 down(&s->sem);
1534
1535 if (vma->vm_flags & VM_WRITE) {
1536 if ((ret = prog_dmabuf_dac2(s)) != 0) {
1537 goto out;
1538 }
1539 db = &s->dma_dac2;
1540 } else if (vma->vm_flags & VM_READ) {
1541 if ((ret = prog_dmabuf_adc(s)) != 0) {
1542 goto out;
1543 }
1544 db = &s->dma_adc;
1545 } else {
1546 ret = -EINVAL;
1547 goto out;
1548 }
1549 if (vma->vm_pgoff != 0) {
1550 ret = -EINVAL;
1551 goto out;
1552 }
1553 size = vma->vm_end - vma->vm_start;
1554 if (size > (PAGE_SIZE << db->buforder)) {
1555 ret = -EINVAL;
1556 goto out;
1557 }
1558 if (remap_pfn_range(vma, vma->vm_start,
1559 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
1560 size, vma->vm_page_prot)) {
1561 ret = -EAGAIN;
1562 goto out;
1563 }
1564 db->mapped = 1;
1565out:
1566 up(&s->sem);
1567 unlock_kernel();
1568 return ret;
1569}
1570
1571static int es1371_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1572{
1573 struct es1371_state *s = (struct es1371_state *)file->private_data;
1574 unsigned long flags;
1575 audio_buf_info abinfo;
1576 count_info cinfo;
1577 int count;
1578 int val, mapped, ret;
1579 void __user *argp = (void __user *)arg;
1580 int __user *p = argp;
1581
1582 VALIDATE_STATE(s);
1583 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac2.mapped) ||
1584 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1585 switch (cmd) {
1586 case OSS_GETVERSION:
1587 return put_user(SOUND_VERSION, p);
1588
1589 case SNDCTL_DSP_SYNC:
1590 if (file->f_mode & FMODE_WRITE)
1591 return drain_dac2(s, 0/*file->f_flags & O_NONBLOCK*/);
1592 return 0;
1593
1594 case SNDCTL_DSP_SETDUPLEX:
1595 return 0;
1596
1597 case SNDCTL_DSP_GETCAPS:
1598 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
1599
1600 case SNDCTL_DSP_RESET:
1601 if (file->f_mode & FMODE_WRITE) {
1602 stop_dac2(s);
1603 synchronize_irq(s->irq);
1604 s->dma_dac2.swptr = s->dma_dac2.hwptr = s->dma_dac2.count = s->dma_dac2.total_bytes = 0;
1605 }
1606 if (file->f_mode & FMODE_READ) {
1607 stop_adc(s);
1608 synchronize_irq(s->irq);
1609 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
1610 }
1611 return 0;
1612
1613 case SNDCTL_DSP_SPEED:
1614 if (get_user(val, p))
1615 return -EFAULT;
1616 if (val >= 0) {
1617 if (file->f_mode & FMODE_READ) {
1618 stop_adc(s);
1619 s->dma_adc.ready = 0;
1620 set_adc_rate(s, val);
1621 }
1622 if (file->f_mode & FMODE_WRITE) {
1623 stop_dac2(s);
1624 s->dma_dac2.ready = 0;
1625 set_dac2_rate(s, val);
1626 }
1627 }
1628 return put_user((file->f_mode & FMODE_READ) ? s->adcrate : s->dac2rate, p);
1629
1630 case SNDCTL_DSP_STEREO:
1631 if (get_user(val, p))
1632 return -EFAULT;
1633 if (file->f_mode & FMODE_READ) {
1634 stop_adc(s);
1635 s->dma_adc.ready = 0;
1636 spin_lock_irqsave(&s->lock, flags);
1637 if (val)
1638 s->sctrl |= SCTRL_R1SMB;
1639 else
1640 s->sctrl &= ~SCTRL_R1SMB;
1641 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
1642 spin_unlock_irqrestore(&s->lock, flags);
1643 }
1644 if (file->f_mode & FMODE_WRITE) {
1645 stop_dac2(s);
1646 s->dma_dac2.ready = 0;
1647 spin_lock_irqsave(&s->lock, flags);
1648 if (val)
1649 s->sctrl |= SCTRL_P2SMB;
1650 else
1651 s->sctrl &= ~SCTRL_P2SMB;
1652 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
1653 spin_unlock_irqrestore(&s->lock, flags);
1654 }
1655 return 0;
1656
1657 case SNDCTL_DSP_CHANNELS:
1658 if (get_user(val, p))
1659 return -EFAULT;
1660 if (val != 0) {
1661 if (file->f_mode & FMODE_READ) {
1662 stop_adc(s);
1663 s->dma_adc.ready = 0;
1664 spin_lock_irqsave(&s->lock, flags);
1665 if (val >= 2)
1666 s->sctrl |= SCTRL_R1SMB;
1667 else
1668 s->sctrl &= ~SCTRL_R1SMB;
1669 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
1670 spin_unlock_irqrestore(&s->lock, flags);
1671 }
1672 if (file->f_mode & FMODE_WRITE) {
1673 stop_dac2(s);
1674 s->dma_dac2.ready = 0;
1675 spin_lock_irqsave(&s->lock, flags);
1676 if (val >= 2)
1677 s->sctrl |= SCTRL_P2SMB;
1678 else
1679 s->sctrl &= ~SCTRL_P2SMB;
1680 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
1681 spin_unlock_irqrestore(&s->lock, flags);
1682 }
1683 }
1684 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SMB : SCTRL_P2SMB)) ? 2 : 1, p);
1685
1686 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1687 return put_user(AFMT_S16_LE|AFMT_U8, p);
1688
1689 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1690 if (get_user(val, p))
1691 return -EFAULT;
1692 if (val != AFMT_QUERY) {
1693 if (file->f_mode & FMODE_READ) {
1694 stop_adc(s);
1695 s->dma_adc.ready = 0;
1696 spin_lock_irqsave(&s->lock, flags);
1697 if (val == AFMT_S16_LE)
1698 s->sctrl |= SCTRL_R1SEB;
1699 else
1700 s->sctrl &= ~SCTRL_R1SEB;
1701 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
1702 spin_unlock_irqrestore(&s->lock, flags);
1703 }
1704 if (file->f_mode & FMODE_WRITE) {
1705 stop_dac2(s);
1706 s->dma_dac2.ready = 0;
1707 spin_lock_irqsave(&s->lock, flags);
1708 if (val == AFMT_S16_LE)
1709 s->sctrl |= SCTRL_P2SEB;
1710 else
1711 s->sctrl &= ~SCTRL_P2SEB;
1712 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
1713 spin_unlock_irqrestore(&s->lock, flags);
1714 }
1715 }
1716 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SEB : SCTRL_P2SEB)) ?
1717 AFMT_S16_LE : AFMT_U8, p);
1718
1719 case SNDCTL_DSP_POST:
1720 return 0;
1721
1722 case SNDCTL_DSP_GETTRIGGER:
1723 val = 0;
1724 if (file->f_mode & FMODE_READ && s->ctrl & CTRL_ADC_EN)
1725 val |= PCM_ENABLE_INPUT;
1726 if (file->f_mode & FMODE_WRITE && s->ctrl & CTRL_DAC2_EN)
1727 val |= PCM_ENABLE_OUTPUT;
1728 return put_user(val, p);
1729
1730 case SNDCTL_DSP_SETTRIGGER:
1731 if (get_user(val, p))
1732 return -EFAULT;
1733 if (file->f_mode & FMODE_READ) {
1734 if (val & PCM_ENABLE_INPUT) {
1735 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1736 return ret;
1737 s->dma_adc.enabled = 1;
1738 start_adc(s);
1739 } else {
1740 s->dma_adc.enabled = 0;
1741 stop_adc(s);
1742 }
1743 }
1744 if (file->f_mode & FMODE_WRITE) {
1745 if (val & PCM_ENABLE_OUTPUT) {
1746 if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
1747 return ret;
1748 s->dma_dac2.enabled = 1;
1749 start_dac2(s);
1750 } else {
1751 s->dma_dac2.enabled = 0;
1752 stop_dac2(s);
1753 }
1754 }
1755 return 0;
1756
1757 case SNDCTL_DSP_GETOSPACE:
1758 if (!(file->f_mode & FMODE_WRITE))
1759 return -EINVAL;
1760 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
1761 return val;
1762 spin_lock_irqsave(&s->lock, flags);
1763 es1371_update_ptr(s);
1764 abinfo.fragsize = s->dma_dac2.fragsize;
1765 count = s->dma_dac2.count;
1766 if (count < 0)
1767 count = 0;
1768 abinfo.bytes = s->dma_dac2.dmasize - count;
1769 abinfo.fragstotal = s->dma_dac2.numfrag;
1770 abinfo.fragments = abinfo.bytes >> s->dma_dac2.fragshift;
1771 spin_unlock_irqrestore(&s->lock, flags);
1772 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1773
1774 case SNDCTL_DSP_GETISPACE:
1775 if (!(file->f_mode & FMODE_READ))
1776 return -EINVAL;
1777 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0)
1778 return val;
1779 spin_lock_irqsave(&s->lock, flags);
1780 es1371_update_ptr(s);
1781 abinfo.fragsize = s->dma_adc.fragsize;
1782 count = s->dma_adc.count;
1783 if (count < 0)
1784 count = 0;
1785 abinfo.bytes = count;
1786 abinfo.fragstotal = s->dma_adc.numfrag;
1787 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1788 spin_unlock_irqrestore(&s->lock, flags);
1789 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1790
1791 case SNDCTL_DSP_NONBLOCK:
1792 file->f_flags |= O_NONBLOCK;
1793 return 0;
1794
1795 case SNDCTL_DSP_GETODELAY:
1796 if (!(file->f_mode & FMODE_WRITE))
1797 return -EINVAL;
1798 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
1799 return val;
1800 spin_lock_irqsave(&s->lock, flags);
1801 es1371_update_ptr(s);
1802 count = s->dma_dac2.count;
1803 spin_unlock_irqrestore(&s->lock, flags);
1804 if (count < 0)
1805 count = 0;
1806 return put_user(count, p);
1807
1808 case SNDCTL_DSP_GETIPTR:
1809 if (!(file->f_mode & FMODE_READ))
1810 return -EINVAL;
1811 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0)
1812 return val;
1813 spin_lock_irqsave(&s->lock, flags);
1814 es1371_update_ptr(s);
1815 cinfo.bytes = s->dma_adc.total_bytes;
1816 count = s->dma_adc.count;
1817 if (count < 0)
1818 count = 0;
1819 cinfo.blocks = count >> s->dma_adc.fragshift;
1820 cinfo.ptr = s->dma_adc.hwptr;
1821 if (s->dma_adc.mapped)
1822 s->dma_adc.count &= s->dma_adc.fragsize-1;
1823 spin_unlock_irqrestore(&s->lock, flags);
1824 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1825 return -EFAULT;
1826 return 0;
1827
1828 case SNDCTL_DSP_GETOPTR:
1829 if (!(file->f_mode & FMODE_WRITE))
1830 return -EINVAL;
1831 if (!s->dma_dac2.ready && (val = prog_dmabuf_dac2(s)) != 0)
1832 return val;
1833 spin_lock_irqsave(&s->lock, flags);
1834 es1371_update_ptr(s);
1835 cinfo.bytes = s->dma_dac2.total_bytes;
1836 count = s->dma_dac2.count;
1837 if (count < 0)
1838 count = 0;
1839 cinfo.blocks = count >> s->dma_dac2.fragshift;
1840 cinfo.ptr = s->dma_dac2.hwptr;
1841 if (s->dma_dac2.mapped)
1842 s->dma_dac2.count &= s->dma_dac2.fragsize-1;
1843 spin_unlock_irqrestore(&s->lock, flags);
1844 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1845 return -EFAULT;
1846 return 0;
1847
1848 case SNDCTL_DSP_GETBLKSIZE:
1849 if (file->f_mode & FMODE_WRITE) {
1850 if ((val = prog_dmabuf_dac2(s)))
1851 return val;
1852 return put_user(s->dma_dac2.fragsize, p);
1853 }
1854 if ((val = prog_dmabuf_adc(s)))
1855 return val;
1856 return put_user(s->dma_adc.fragsize, p);
1857
1858 case SNDCTL_DSP_SETFRAGMENT:
1859 if (get_user(val, p))
1860 return -EFAULT;
1861 if (file->f_mode & FMODE_READ) {
1862 s->dma_adc.ossfragshift = val & 0xffff;
1863 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1864 if (s->dma_adc.ossfragshift < 4)
1865 s->dma_adc.ossfragshift = 4;
1866 if (s->dma_adc.ossfragshift > 15)
1867 s->dma_adc.ossfragshift = 15;
1868 if (s->dma_adc.ossmaxfrags < 4)
1869 s->dma_adc.ossmaxfrags = 4;
1870 }
1871 if (file->f_mode & FMODE_WRITE) {
1872 s->dma_dac2.ossfragshift = val & 0xffff;
1873 s->dma_dac2.ossmaxfrags = (val >> 16) & 0xffff;
1874 if (s->dma_dac2.ossfragshift < 4)
1875 s->dma_dac2.ossfragshift = 4;
1876 if (s->dma_dac2.ossfragshift > 15)
1877 s->dma_dac2.ossfragshift = 15;
1878 if (s->dma_dac2.ossmaxfrags < 4)
1879 s->dma_dac2.ossmaxfrags = 4;
1880 }
1881 return 0;
1882
1883 case SNDCTL_DSP_SUBDIVIDE:
1884 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1885 (file->f_mode & FMODE_WRITE && s->dma_dac2.subdivision))
1886 return -EINVAL;
1887 if (get_user(val, p))
1888 return -EFAULT;
1889 if (val != 1 && val != 2 && val != 4)
1890 return -EINVAL;
1891 if (file->f_mode & FMODE_READ)
1892 s->dma_adc.subdivision = val;
1893 if (file->f_mode & FMODE_WRITE)
1894 s->dma_dac2.subdivision = val;
1895 return 0;
1896
1897 case SOUND_PCM_READ_RATE:
1898 return put_user((file->f_mode & FMODE_READ) ? s->adcrate : s->dac2rate, p);
1899
1900 case SOUND_PCM_READ_CHANNELS:
1901 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SMB : SCTRL_P2SMB)) ? 2 : 1, p);
1902
1903 case SOUND_PCM_READ_BITS:
1904 return put_user((s->sctrl & ((file->f_mode & FMODE_READ) ? SCTRL_R1SEB : SCTRL_P2SEB)) ? 16 : 8, p);
1905
1906 case SOUND_PCM_WRITE_FILTER:
1907 case SNDCTL_DSP_SETSYNCRO:
1908 case SOUND_PCM_READ_FILTER:
1909 return -EINVAL;
1910
1911 }
1912 return mixdev_ioctl(s->codec, cmd, arg);
1913}
1914
1915static int es1371_open(struct inode *inode, struct file *file)
1916{
1917 int minor = iminor(inode);
1918 DECLARE_WAITQUEUE(wait, current);
1919 unsigned long flags;
1920 struct list_head *list;
1921 struct es1371_state *s;
1922
1923 for (list = devs.next; ; list = list->next) {
1924 if (list == &devs)
1925 return -ENODEV;
1926 s = list_entry(list, struct es1371_state, devs);
1927 if (!((s->dev_audio ^ minor) & ~0xf))
1928 break;
1929 }
1930 VALIDATE_STATE(s);
1931 file->private_data = s;
1932 /* wait for device to become free */
1933 down(&s->open_sem);
1934 while (s->open_mode & file->f_mode) {
1935 if (file->f_flags & O_NONBLOCK) {
1936 up(&s->open_sem);
1937 return -EBUSY;
1938 }
1939 add_wait_queue(&s->open_wait, &wait);
1940 __set_current_state(TASK_INTERRUPTIBLE);
1941 up(&s->open_sem);
1942 schedule();
1943 remove_wait_queue(&s->open_wait, &wait);
1944 set_current_state(TASK_RUNNING);
1945 if (signal_pending(current))
1946 return -ERESTARTSYS;
1947 down(&s->open_sem);
1948 }
1949 if (file->f_mode & FMODE_READ) {
1950 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
1951 s->dma_adc.enabled = 1;
1952 set_adc_rate(s, 8000);
1953 }
1954 if (file->f_mode & FMODE_WRITE) {
1955 s->dma_dac2.ossfragshift = s->dma_dac2.ossmaxfrags = s->dma_dac2.subdivision = 0;
1956 s->dma_dac2.enabled = 1;
1957 set_dac2_rate(s, 8000);
1958 }
1959 spin_lock_irqsave(&s->lock, flags);
1960 if (file->f_mode & FMODE_READ) {
1961 s->sctrl &= ~SCTRL_R1FMT;
1962 if ((minor & 0xf) == SND_DEV_DSP16)
1963 s->sctrl |= ES1371_FMT_S16_MONO << SCTRL_SH_R1FMT;
1964 else
1965 s->sctrl |= ES1371_FMT_U8_MONO << SCTRL_SH_R1FMT;
1966 }
1967 if (file->f_mode & FMODE_WRITE) {
1968 s->sctrl &= ~SCTRL_P2FMT;
1969 if ((minor & 0xf) == SND_DEV_DSP16)
1970 s->sctrl |= ES1371_FMT_S16_MONO << SCTRL_SH_P2FMT;
1971 else
1972 s->sctrl |= ES1371_FMT_U8_MONO << SCTRL_SH_P2FMT;
1973 }
1974 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
1975 spin_unlock_irqrestore(&s->lock, flags);
1976 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1977 up(&s->open_sem);
1978 init_MUTEX(&s->sem);
1979 return nonseekable_open(inode, file);
1980}
1981
1982static int es1371_release(struct inode *inode, struct file *file)
1983{
1984 struct es1371_state *s = (struct es1371_state *)file->private_data;
1985
1986 VALIDATE_STATE(s);
1987 lock_kernel();
1988 if (file->f_mode & FMODE_WRITE)
1989 drain_dac2(s, file->f_flags & O_NONBLOCK);
1990 down(&s->open_sem);
1991 if (file->f_mode & FMODE_WRITE) {
1992 stop_dac2(s);
1993 dealloc_dmabuf(s, &s->dma_dac2);
1994 }
1995 if (file->f_mode & FMODE_READ) {
1996 stop_adc(s);
1997 dealloc_dmabuf(s, &s->dma_adc);
1998 }
1999 s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
2000 up(&s->open_sem);
2001 wake_up(&s->open_wait);
2002 unlock_kernel();
2003 return 0;
2004}
2005
2006static /*const*/ struct file_operations es1371_audio_fops = {
2007 .owner = THIS_MODULE,
2008 .llseek = no_llseek,
2009 .read = es1371_read,
2010 .write = es1371_write,
2011 .poll = es1371_poll,
2012 .ioctl = es1371_ioctl,
2013 .mmap = es1371_mmap,
2014 .open = es1371_open,
2015 .release = es1371_release,
2016};
2017
2018/* --------------------------------------------------------------------- */
2019
2020static ssize_t es1371_write_dac(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2021{
2022 struct es1371_state *s = (struct es1371_state *)file->private_data;
2023 DECLARE_WAITQUEUE(wait, current);
2024 ssize_t ret = 0;
2025 unsigned long flags;
2026 unsigned swptr;
2027 int cnt;
2028
2029 VALIDATE_STATE(s);
2030 if (s->dma_dac1.mapped)
2031 return -ENXIO;
2032 if (!s->dma_dac1.ready && (ret = prog_dmabuf_dac1(s)))
2033 return ret;
2034 if (!access_ok(VERIFY_READ, buffer, count))
2035 return -EFAULT;
2036 add_wait_queue(&s->dma_dac1.wait, &wait);
2037 while (count > 0) {
2038 spin_lock_irqsave(&s->lock, flags);
2039 if (s->dma_dac1.count < 0) {
2040 s->dma_dac1.count = 0;
2041 s->dma_dac1.swptr = s->dma_dac1.hwptr;
2042 }
2043 swptr = s->dma_dac1.swptr;
2044 cnt = s->dma_dac1.dmasize-swptr;
2045 if (s->dma_dac1.count + cnt > s->dma_dac1.dmasize)
2046 cnt = s->dma_dac1.dmasize - s->dma_dac1.count;
2047 if (cnt <= 0)
2048 __set_current_state(TASK_INTERRUPTIBLE);
2049 spin_unlock_irqrestore(&s->lock, flags);
2050 if (cnt > count)
2051 cnt = count;
2052 if (cnt <= 0) {
2053 if (s->dma_dac1.enabled)
2054 start_dac1(s);
2055 if (file->f_flags & O_NONBLOCK) {
2056 if (!ret)
2057 ret = -EAGAIN;
2058 break;
2059 }
2060 schedule();
2061 if (signal_pending(current)) {
2062 if (!ret)
2063 ret = -ERESTARTSYS;
2064 break;
2065 }
2066 continue;
2067 }
2068 if (copy_from_user(s->dma_dac1.rawbuf + swptr, buffer, cnt)) {
2069 if (!ret)
2070 ret = -EFAULT;
2071 break;
2072 }
2073 swptr = (swptr + cnt) % s->dma_dac1.dmasize;
2074 spin_lock_irqsave(&s->lock, flags);
2075 s->dma_dac1.swptr = swptr;
2076 s->dma_dac1.count += cnt;
2077 s->dma_dac1.endcleared = 0;
2078 spin_unlock_irqrestore(&s->lock, flags);
2079 count -= cnt;
2080 buffer += cnt;
2081 ret += cnt;
2082 if (s->dma_dac1.enabled)
2083 start_dac1(s);
2084 }
2085 remove_wait_queue(&s->dma_dac1.wait, &wait);
2086 set_current_state(TASK_RUNNING);
2087 return ret;
2088}
2089
2090/* No kernel lock - we have our own spinlock */
2091static unsigned int es1371_poll_dac(struct file *file, struct poll_table_struct *wait)
2092{
2093 struct es1371_state *s = (struct es1371_state *)file->private_data;
2094 unsigned long flags;
2095 unsigned int mask = 0;
2096
2097 VALIDATE_STATE(s);
2098 if (!s->dma_dac1.ready && prog_dmabuf_dac1(s))
2099 return 0;
2100 poll_wait(file, &s->dma_dac1.wait, wait);
2101 spin_lock_irqsave(&s->lock, flags);
2102 es1371_update_ptr(s);
2103 if (s->dma_dac1.mapped) {
2104 if (s->dma_dac1.count >= (signed)s->dma_dac1.fragsize)
2105 mask |= POLLOUT | POLLWRNORM;
2106 } else {
2107 if ((signed)s->dma_dac1.dmasize >= s->dma_dac1.count + (signed)s->dma_dac1.fragsize)
2108 mask |= POLLOUT | POLLWRNORM;
2109 }
2110 spin_unlock_irqrestore(&s->lock, flags);
2111 return mask;
2112}
2113
2114static int es1371_mmap_dac(struct file *file, struct vm_area_struct *vma)
2115{
2116 struct es1371_state *s = (struct es1371_state *)file->private_data;
2117 int ret;
2118 unsigned long size;
2119
2120 VALIDATE_STATE(s);
2121 if (!(vma->vm_flags & VM_WRITE))
2122 return -EINVAL;
2123 lock_kernel();
2124 if ((ret = prog_dmabuf_dac1(s)) != 0)
2125 goto out;
2126 ret = -EINVAL;
2127 if (vma->vm_pgoff != 0)
2128 goto out;
2129 size = vma->vm_end - vma->vm_start;
2130 if (size > (PAGE_SIZE << s->dma_dac1.buforder))
2131 goto out;
2132 ret = -EAGAIN;
2133 if (remap_pfn_range(vma, vma->vm_start,
2134 virt_to_phys(s->dma_dac1.rawbuf) >> PAGE_SHIFT,
2135 size, vma->vm_page_prot))
2136 goto out;
2137 s->dma_dac1.mapped = 1;
2138 ret = 0;
2139out:
2140 unlock_kernel();
2141 return ret;
2142}
2143
2144static int es1371_ioctl_dac(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2145{
2146 struct es1371_state *s = (struct es1371_state *)file->private_data;
2147 unsigned long flags;
2148 audio_buf_info abinfo;
2149 count_info cinfo;
2150 int count;
2151 int val, ret;
2152 int __user *p = (int __user *)arg;
2153
2154 VALIDATE_STATE(s);
2155 switch (cmd) {
2156 case OSS_GETVERSION:
2157 return put_user(SOUND_VERSION, p);
2158
2159 case SNDCTL_DSP_SYNC:
2160 return drain_dac1(s, 0/*file->f_flags & O_NONBLOCK*/);
2161
2162 case SNDCTL_DSP_SETDUPLEX:
2163 return -EINVAL;
2164
2165 case SNDCTL_DSP_GETCAPS:
2166 return put_user(DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
2167
2168 case SNDCTL_DSP_RESET:
2169 stop_dac1(s);
2170 synchronize_irq(s->irq);
2171 s->dma_dac1.swptr = s->dma_dac1.hwptr = s->dma_dac1.count = s->dma_dac1.total_bytes = 0;
2172 return 0;
2173
2174 case SNDCTL_DSP_SPEED:
2175 if (get_user(val, p))
2176 return -EFAULT;
2177 if (val >= 0) {
2178 stop_dac1(s);
2179 s->dma_dac1.ready = 0;
2180 set_dac1_rate(s, val);
2181 }
2182 return put_user(s->dac1rate, p);
2183
2184 case SNDCTL_DSP_STEREO:
2185 if (get_user(val, p))
2186 return -EFAULT;
2187 stop_dac1(s);
2188 s->dma_dac1.ready = 0;
2189 spin_lock_irqsave(&s->lock, flags);
2190 if (val)
2191 s->sctrl |= SCTRL_P1SMB;
2192 else
2193 s->sctrl &= ~SCTRL_P1SMB;
2194 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
2195 spin_unlock_irqrestore(&s->lock, flags);
2196 return 0;
2197
2198 case SNDCTL_DSP_CHANNELS:
2199 if (get_user(val, p))
2200 return -EFAULT;
2201 if (val != 0) {
2202 stop_dac1(s);
2203 s->dma_dac1.ready = 0;
2204 spin_lock_irqsave(&s->lock, flags);
2205 if (val >= 2)
2206 s->sctrl |= SCTRL_P1SMB;
2207 else
2208 s->sctrl &= ~SCTRL_P1SMB;
2209 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
2210 spin_unlock_irqrestore(&s->lock, flags);
2211 }
2212 return put_user((s->sctrl & SCTRL_P1SMB) ? 2 : 1, p);
2213
2214 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
2215 return put_user(AFMT_S16_LE|AFMT_U8, p);
2216
2217 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
2218 if (get_user(val, p))
2219 return -EFAULT;
2220 if (val != AFMT_QUERY) {
2221 stop_dac1(s);
2222 s->dma_dac1.ready = 0;
2223 spin_lock_irqsave(&s->lock, flags);
2224 if (val == AFMT_S16_LE)
2225 s->sctrl |= SCTRL_P1SEB;
2226 else
2227 s->sctrl &= ~SCTRL_P1SEB;
2228 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
2229 spin_unlock_irqrestore(&s->lock, flags);
2230 }
2231 return put_user((s->sctrl & SCTRL_P1SEB) ? AFMT_S16_LE : AFMT_U8, p);
2232
2233 case SNDCTL_DSP_POST:
2234 return 0;
2235
2236 case SNDCTL_DSP_GETTRIGGER:
2237 return put_user((s->ctrl & CTRL_DAC1_EN) ? PCM_ENABLE_OUTPUT : 0, p);
2238
2239 case SNDCTL_DSP_SETTRIGGER:
2240 if (get_user(val, p))
2241 return -EFAULT;
2242 if (val & PCM_ENABLE_OUTPUT) {
2243 if (!s->dma_dac1.ready && (ret = prog_dmabuf_dac1(s)))
2244 return ret;
2245 s->dma_dac1.enabled = 1;
2246 start_dac1(s);
2247 } else {
2248 s->dma_dac1.enabled = 0;
2249 stop_dac1(s);
2250 }
2251 return 0;
2252
2253 case SNDCTL_DSP_GETOSPACE:
2254 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
2255 return val;
2256 spin_lock_irqsave(&s->lock, flags);
2257 es1371_update_ptr(s);
2258 abinfo.fragsize = s->dma_dac1.fragsize;
2259 count = s->dma_dac1.count;
2260 if (count < 0)
2261 count = 0;
2262 abinfo.bytes = s->dma_dac1.dmasize - count;
2263 abinfo.fragstotal = s->dma_dac1.numfrag;
2264 abinfo.fragments = abinfo.bytes >> s->dma_dac1.fragshift;
2265 spin_unlock_irqrestore(&s->lock, flags);
2266 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2267
2268 case SNDCTL_DSP_NONBLOCK:
2269 file->f_flags |= O_NONBLOCK;
2270 return 0;
2271
2272 case SNDCTL_DSP_GETODELAY:
2273 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
2274 return val;
2275 spin_lock_irqsave(&s->lock, flags);
2276 es1371_update_ptr(s);
2277 count = s->dma_dac1.count;
2278 spin_unlock_irqrestore(&s->lock, flags);
2279 if (count < 0)
2280 count = 0;
2281 return put_user(count, p);
2282
2283 case SNDCTL_DSP_GETOPTR:
2284 if (!s->dma_dac1.ready && (val = prog_dmabuf_dac1(s)) != 0)
2285 return val;
2286 spin_lock_irqsave(&s->lock, flags);
2287 es1371_update_ptr(s);
2288 cinfo.bytes = s->dma_dac1.total_bytes;
2289 count = s->dma_dac1.count;
2290 if (count < 0)
2291 count = 0;
2292 cinfo.blocks = count >> s->dma_dac1.fragshift;
2293 cinfo.ptr = s->dma_dac1.hwptr;
2294 if (s->dma_dac1.mapped)
2295 s->dma_dac1.count &= s->dma_dac1.fragsize-1;
2296 spin_unlock_irqrestore(&s->lock, flags);
2297 if (copy_to_user((void __user *)arg, &cinfo, sizeof(cinfo)))
2298 return -EFAULT;
2299 return 0;
2300
2301 case SNDCTL_DSP_GETBLKSIZE:
2302 if ((val = prog_dmabuf_dac1(s)))
2303 return val;
2304 return put_user(s->dma_dac1.fragsize, p);
2305
2306 case SNDCTL_DSP_SETFRAGMENT:
2307 if (get_user(val, p))
2308 return -EFAULT;
2309 s->dma_dac1.ossfragshift = val & 0xffff;
2310 s->dma_dac1.ossmaxfrags = (val >> 16) & 0xffff;
2311 if (s->dma_dac1.ossfragshift < 4)
2312 s->dma_dac1.ossfragshift = 4;
2313 if (s->dma_dac1.ossfragshift > 15)
2314 s->dma_dac1.ossfragshift = 15;
2315 if (s->dma_dac1.ossmaxfrags < 4)
2316 s->dma_dac1.ossmaxfrags = 4;
2317 return 0;
2318
2319 case SNDCTL_DSP_SUBDIVIDE:
2320 if (s->dma_dac1.subdivision)
2321 return -EINVAL;
2322 if (get_user(val, p))
2323 return -EFAULT;
2324 if (val != 1 && val != 2 && val != 4)
2325 return -EINVAL;
2326 s->dma_dac1.subdivision = val;
2327 return 0;
2328
2329 case SOUND_PCM_READ_RATE:
2330 return put_user(s->dac1rate, p);
2331
2332 case SOUND_PCM_READ_CHANNELS:
2333 return put_user((s->sctrl & SCTRL_P1SMB) ? 2 : 1, p);
2334
2335 case SOUND_PCM_READ_BITS:
2336 return put_user((s->sctrl & SCTRL_P1SEB) ? 16 : 8, p);
2337
2338 case SOUND_PCM_WRITE_FILTER:
2339 case SNDCTL_DSP_SETSYNCRO:
2340 case SOUND_PCM_READ_FILTER:
2341 return -EINVAL;
2342
2343 }
2344 return mixdev_ioctl(s->codec, cmd, arg);
2345}
2346
2347static int es1371_open_dac(struct inode *inode, struct file *file)
2348{
2349 int minor = iminor(inode);
2350 DECLARE_WAITQUEUE(wait, current);
2351 unsigned long flags;
2352 struct list_head *list;
2353 struct es1371_state *s;
2354
2355 for (list = devs.next; ; list = list->next) {
2356 if (list == &devs)
2357 return -ENODEV;
2358 s = list_entry(list, struct es1371_state, devs);
2359 if (!((s->dev_dac ^ minor) & ~0xf))
2360 break;
2361 }
2362 VALIDATE_STATE(s);
2363 /* we allow opening with O_RDWR, most programs do it although they will only write */
2364#if 0
2365 if (file->f_mode & FMODE_READ)
2366 return -EPERM;
2367#endif
2368 if (!(file->f_mode & FMODE_WRITE))
2369 return -EINVAL;
2370 file->private_data = s;
2371 /* wait for device to become free */
2372 down(&s->open_sem);
2373 while (s->open_mode & FMODE_DAC) {
2374 if (file->f_flags & O_NONBLOCK) {
2375 up(&s->open_sem);
2376 return -EBUSY;
2377 }
2378 add_wait_queue(&s->open_wait, &wait);
2379 __set_current_state(TASK_INTERRUPTIBLE);
2380 up(&s->open_sem);
2381 schedule();
2382 remove_wait_queue(&s->open_wait, &wait);
2383 set_current_state(TASK_RUNNING);
2384 if (signal_pending(current))
2385 return -ERESTARTSYS;
2386 down(&s->open_sem);
2387 }
2388 s->dma_dac1.ossfragshift = s->dma_dac1.ossmaxfrags = s->dma_dac1.subdivision = 0;
2389 s->dma_dac1.enabled = 1;
2390 set_dac1_rate(s, 8000);
2391 spin_lock_irqsave(&s->lock, flags);
2392 s->sctrl &= ~SCTRL_P1FMT;
2393 if ((minor & 0xf) == SND_DEV_DSP16)
2394 s->sctrl |= ES1371_FMT_S16_MONO << SCTRL_SH_P1FMT;
2395 else
2396 s->sctrl |= ES1371_FMT_U8_MONO << SCTRL_SH_P1FMT;
2397 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
2398 spin_unlock_irqrestore(&s->lock, flags);
2399 s->open_mode |= FMODE_DAC;
2400 up(&s->open_sem);
2401 return nonseekable_open(inode, file);
2402}
2403
2404static int es1371_release_dac(struct inode *inode, struct file *file)
2405{
2406 struct es1371_state *s = (struct es1371_state *)file->private_data;
2407
2408 VALIDATE_STATE(s);
2409 lock_kernel();
2410 drain_dac1(s, file->f_flags & O_NONBLOCK);
2411 down(&s->open_sem);
2412 stop_dac1(s);
2413 dealloc_dmabuf(s, &s->dma_dac1);
2414 s->open_mode &= ~FMODE_DAC;
2415 up(&s->open_sem);
2416 wake_up(&s->open_wait);
2417 unlock_kernel();
2418 return 0;
2419}
2420
2421static /*const*/ struct file_operations es1371_dac_fops = {
2422 .owner = THIS_MODULE,
2423 .llseek = no_llseek,
2424 .write = es1371_write_dac,
2425 .poll = es1371_poll_dac,
2426 .ioctl = es1371_ioctl_dac,
2427 .mmap = es1371_mmap_dac,
2428 .open = es1371_open_dac,
2429 .release = es1371_release_dac,
2430};
2431
2432/* --------------------------------------------------------------------- */
2433
2434static ssize_t es1371_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2435{
2436 struct es1371_state *s = (struct es1371_state *)file->private_data;
2437 DECLARE_WAITQUEUE(wait, current);
2438 ssize_t ret;
2439 unsigned long flags;
2440 unsigned ptr;
2441 int cnt;
2442
2443 VALIDATE_STATE(s);
2444 if (!access_ok(VERIFY_WRITE, buffer, count))
2445 return -EFAULT;
2446 if (count == 0)
2447 return 0;
2448 ret = 0;
2449 add_wait_queue(&s->midi.iwait, &wait);
2450 while (count > 0) {
2451 spin_lock_irqsave(&s->lock, flags);
2452 ptr = s->midi.ird;
2453 cnt = MIDIINBUF - ptr;
2454 if (s->midi.icnt < cnt)
2455 cnt = s->midi.icnt;
2456 if (cnt <= 0)
2457 __set_current_state(TASK_INTERRUPTIBLE);
2458 spin_unlock_irqrestore(&s->lock, flags);
2459 if (cnt > count)
2460 cnt = count;
2461 if (cnt <= 0) {
2462 if (file->f_flags & O_NONBLOCK) {
2463 if (!ret)
2464 ret = -EAGAIN;
2465 break;
2466 }
2467 schedule();
2468 if (signal_pending(current)) {
2469 if (!ret)
2470 ret = -ERESTARTSYS;
2471 break;
2472 }
2473 continue;
2474 }
2475 if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt)) {
2476 if (!ret)
2477 ret = -EFAULT;
2478 break;
2479 }
2480 ptr = (ptr + cnt) % MIDIINBUF;
2481 spin_lock_irqsave(&s->lock, flags);
2482 s->midi.ird = ptr;
2483 s->midi.icnt -= cnt;
2484 spin_unlock_irqrestore(&s->lock, flags);
2485 count -= cnt;
2486 buffer += cnt;
2487 ret += cnt;
2488 break;
2489 }
2490 __set_current_state(TASK_RUNNING);
2491 remove_wait_queue(&s->midi.iwait, &wait);
2492 return ret;
2493}
2494
2495static ssize_t es1371_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2496{
2497 struct es1371_state *s = (struct es1371_state *)file->private_data;
2498 DECLARE_WAITQUEUE(wait, current);
2499 ssize_t ret;
2500 unsigned long flags;
2501 unsigned ptr;
2502 int cnt;
2503
2504 VALIDATE_STATE(s);
2505 if (!access_ok(VERIFY_READ, buffer, count))
2506 return -EFAULT;
2507 if (count == 0)
2508 return 0;
2509 ret = 0;
2510 add_wait_queue(&s->midi.owait, &wait);
2511 while (count > 0) {
2512 spin_lock_irqsave(&s->lock, flags);
2513 ptr = s->midi.owr;
2514 cnt = MIDIOUTBUF - ptr;
2515 if (s->midi.ocnt + cnt > MIDIOUTBUF)
2516 cnt = MIDIOUTBUF - s->midi.ocnt;
2517 if (cnt <= 0) {
2518 __set_current_state(TASK_INTERRUPTIBLE);
2519 es1371_handle_midi(s);
2520 }
2521 spin_unlock_irqrestore(&s->lock, flags);
2522 if (cnt > count)
2523 cnt = count;
2524 if (cnt <= 0) {
2525 if (file->f_flags & O_NONBLOCK) {
2526 if (!ret)
2527 ret = -EAGAIN;
2528 break;
2529 }
2530 schedule();
2531 if (signal_pending(current)) {
2532 if (!ret)
2533 ret = -ERESTARTSYS;
2534 break;
2535 }
2536 continue;
2537 }
2538 if (copy_from_user(s->midi.obuf + ptr, buffer, cnt)) {
2539 if (!ret)
2540 ret = -EFAULT;
2541 break;
2542 }
2543 ptr = (ptr + cnt) % MIDIOUTBUF;
2544 spin_lock_irqsave(&s->lock, flags);
2545 s->midi.owr = ptr;
2546 s->midi.ocnt += cnt;
2547 spin_unlock_irqrestore(&s->lock, flags);
2548 count -= cnt;
2549 buffer += cnt;
2550 ret += cnt;
2551 spin_lock_irqsave(&s->lock, flags);
2552 es1371_handle_midi(s);
2553 spin_unlock_irqrestore(&s->lock, flags);
2554 }
2555 __set_current_state(TASK_RUNNING);
2556 remove_wait_queue(&s->midi.owait, &wait);
2557 return ret;
2558}
2559
2560/* No kernel lock - we have our own spinlock */
2561static unsigned int es1371_midi_poll(struct file *file, struct poll_table_struct *wait)
2562{
2563 struct es1371_state *s = (struct es1371_state *)file->private_data;
2564 unsigned long flags;
2565 unsigned int mask = 0;
2566
2567 VALIDATE_STATE(s);
2568 if (file->f_mode & FMODE_WRITE)
2569 poll_wait(file, &s->midi.owait, wait);
2570 if (file->f_mode & FMODE_READ)
2571 poll_wait(file, &s->midi.iwait, wait);
2572 spin_lock_irqsave(&s->lock, flags);
2573 if (file->f_mode & FMODE_READ) {
2574 if (s->midi.icnt > 0)
2575 mask |= POLLIN | POLLRDNORM;
2576 }
2577 if (file->f_mode & FMODE_WRITE) {
2578 if (s->midi.ocnt < MIDIOUTBUF)
2579 mask |= POLLOUT | POLLWRNORM;
2580 }
2581 spin_unlock_irqrestore(&s->lock, flags);
2582 return mask;
2583}
2584
2585static int es1371_midi_open(struct inode *inode, struct file *file)
2586{
2587 int minor = iminor(inode);
2588 DECLARE_WAITQUEUE(wait, current);
2589 unsigned long flags;
2590 struct list_head *list;
2591 struct es1371_state *s;
2592
2593 for (list = devs.next; ; list = list->next) {
2594 if (list == &devs)
2595 return -ENODEV;
2596 s = list_entry(list, struct es1371_state, devs);
2597 if (s->dev_midi == minor)
2598 break;
2599 }
2600 VALIDATE_STATE(s);
2601 file->private_data = s;
2602 /* wait for device to become free */
2603 down(&s->open_sem);
2604 while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
2605 if (file->f_flags & O_NONBLOCK) {
2606 up(&s->open_sem);
2607 return -EBUSY;
2608 }
2609 add_wait_queue(&s->open_wait, &wait);
2610 __set_current_state(TASK_INTERRUPTIBLE);
2611 up(&s->open_sem);
2612 schedule();
2613 remove_wait_queue(&s->open_wait, &wait);
2614 set_current_state(TASK_RUNNING);
2615 if (signal_pending(current))
2616 return -ERESTARTSYS;
2617 down(&s->open_sem);
2618 }
2619 spin_lock_irqsave(&s->lock, flags);
2620 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
2621 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2622 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
2623 outb(UCTRL_CNTRL_SWR, s->io+ES1371_REG_UART_CONTROL);
2624 outb(0, s->io+ES1371_REG_UART_CONTROL);
2625 outb(0, s->io+ES1371_REG_UART_TEST);
2626 }
2627 if (file->f_mode & FMODE_READ) {
2628 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2629 }
2630 if (file->f_mode & FMODE_WRITE) {
2631 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
2632 }
2633 s->ctrl |= CTRL_UART_EN;
2634 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
2635 es1371_handle_midi(s);
2636 spin_unlock_irqrestore(&s->lock, flags);
2637 s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
2638 up(&s->open_sem);
2639 return nonseekable_open(inode, file);
2640}
2641
2642static int es1371_midi_release(struct inode *inode, struct file *file)
2643{
2644 struct es1371_state *s = (struct es1371_state *)file->private_data;
2645 DECLARE_WAITQUEUE(wait, current);
2646 unsigned long flags;
2647 unsigned count, tmo;
2648
2649 VALIDATE_STATE(s);
2650 lock_kernel();
2651 if (file->f_mode & FMODE_WRITE) {
2652 add_wait_queue(&s->midi.owait, &wait);
2653 for (;;) {
2654 __set_current_state(TASK_INTERRUPTIBLE);
2655 spin_lock_irqsave(&s->lock, flags);
2656 count = s->midi.ocnt;
2657 spin_unlock_irqrestore(&s->lock, flags);
2658 if (count <= 0)
2659 break;
2660 if (signal_pending(current))
2661 break;
2662 if (file->f_flags & O_NONBLOCK)
2663 break;
2664 tmo = (count * HZ) / 3100;
2665 if (!schedule_timeout(tmo ? : 1) && tmo)
2666 printk(KERN_DEBUG PFX "midi timed out??\n");
2667 }
2668 remove_wait_queue(&s->midi.owait, &wait);
2669 set_current_state(TASK_RUNNING);
2670 }
2671 down(&s->open_sem);
2672 s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
2673 spin_lock_irqsave(&s->lock, flags);
2674 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
2675 s->ctrl &= ~CTRL_UART_EN;
2676 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
2677 }
2678 spin_unlock_irqrestore(&s->lock, flags);
2679 up(&s->open_sem);
2680 wake_up(&s->open_wait);
2681 unlock_kernel();
2682 return 0;
2683}
2684
2685static /*const*/ struct file_operations es1371_midi_fops = {
2686 .owner = THIS_MODULE,
2687 .llseek = no_llseek,
2688 .read = es1371_midi_read,
2689 .write = es1371_midi_write,
2690 .poll = es1371_midi_poll,
2691 .open = es1371_midi_open,
2692 .release = es1371_midi_release,
2693};
2694
2695/* --------------------------------------------------------------------- */
2696
2697/*
2698 * for debugging purposes, we'll create a proc device that dumps the
2699 * CODEC chipstate
2700 */
2701
2702#ifdef ES1371_DEBUG
2703static int proc_es1371_dump (char *buf, char **start, off_t fpos, int length, int *eof, void *data)
2704{
2705 struct es1371_state *s;
2706 int cnt, len = 0;
2707
2708 if (list_empty(&devs))
2709 return 0;
2710 s = list_entry(devs.next, struct es1371_state, devs);
2711 /* print out header */
2712 len += sprintf(buf + len, "\t\tCreative ES137x Debug Dump-o-matic\n");
2713
2714 /* print out CODEC state */
2715 len += sprintf (buf + len, "AC97 CODEC state\n");
2716 for (cnt=0; cnt <= 0x7e; cnt = cnt +2)
2717 len+= sprintf (buf + len, "reg:0x%02x val:0x%04x\n", cnt, rdcodec(s->codec, cnt));
2718
2719 if (fpos >=len){
2720 *start = buf;
2721 *eof =1;
2722 return 0;
2723 }
2724 *start = buf + fpos;
2725 if ((len -= fpos) > length)
2726 return length;
2727 *eof =1;
2728 return len;
2729
2730}
2731#endif /* ES1371_DEBUG */
2732
2733/* --------------------------------------------------------------------- */
2734
2735/* maximum number of devices; only used for command line params */
2736#define NR_DEVICE 5
2737
2738static int spdif[NR_DEVICE];
2739static int nomix[NR_DEVICE];
2740static int amplifier[NR_DEVICE];
2741
2742static unsigned int devindex;
2743
2744module_param_array(spdif, bool, NULL, 0);
2745MODULE_PARM_DESC(spdif, "if 1 the output is in S/PDIF digital mode");
2746module_param_array(nomix, bool, NULL, 0);
2747MODULE_PARM_DESC(nomix, "if 1 no analog audio is mixed to the digital output");
2748module_param_array(amplifier, bool, NULL, 0);
2749MODULE_PARM_DESC(amplifier, "Set to 1 if the machine needs the amp control enabling (many laptops)");
2750
2751MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
2752MODULE_DESCRIPTION("ES1371 AudioPCI97 Driver");
2753MODULE_LICENSE("GPL");
2754
2755
2756/* --------------------------------------------------------------------- */
2757
2758static struct initvol {
2759 int mixch;
2760 int vol;
2761} initvol[] __devinitdata = {
2762 { SOUND_MIXER_WRITE_LINE, 0x4040 },
2763 { SOUND_MIXER_WRITE_CD, 0x4040 },
2764 { MIXER_WRITE(SOUND_MIXER_VIDEO), 0x4040 },
2765 { SOUND_MIXER_WRITE_LINE1, 0x4040 },
2766 { SOUND_MIXER_WRITE_PCM, 0x4040 },
2767 { SOUND_MIXER_WRITE_VOLUME, 0x4040 },
2768 { MIXER_WRITE(SOUND_MIXER_PHONEOUT), 0x4040 },
2769 { SOUND_MIXER_WRITE_OGAIN, 0x4040 },
2770 { MIXER_WRITE(SOUND_MIXER_PHONEIN), 0x4040 },
2771 { SOUND_MIXER_WRITE_SPEAKER, 0x4040 },
2772 { SOUND_MIXER_WRITE_MIC, 0x4040 },
2773 { SOUND_MIXER_WRITE_RECLEV, 0x4040 },
2774 { SOUND_MIXER_WRITE_IGAIN, 0x4040 }
2775};
2776
2777static struct
2778{
2779 short svid, sdid;
2780} amplifier_needed[] =
2781{
2782 { 0x107B, 0x2150 }, /* Gateway Solo 2150 */
2783 { 0x13BD, 0x100C }, /* Mebius PC-MJ100V */
2784 { 0x1102, 0x5938 }, /* Targa Xtender 300 */
2785 { 0x1102, 0x8938 }, /* IPC notebook */
2786 { PCI_ANY_ID, PCI_ANY_ID }
2787};
2788
2789static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2790{
2791 struct es1371_state *s;
2792 struct gameport *gp;
2793 mm_segment_t fs;
2794 int i, gpio, val, res = -1;
2795 int idx;
2796 unsigned long tmo;
2797 signed long tmo2;
2798 unsigned int cssr;
2799
2800 if ((res=pci_enable_device(pcidev)))
2801 return res;
2802
2803 if (!(pci_resource_flags(pcidev, 0) & IORESOURCE_IO))
2804 return -ENODEV;
2805 if (pcidev->irq == 0)
2806 return -ENODEV;
2807 i = pci_set_dma_mask(pcidev, 0xffffffff);
2808 if (i) {
2809 printk(KERN_WARNING "es1371: architecture does not support 32bit PCI busmaster DMA\n");
2810 return i;
2811 }
2812 if (!(s = kmalloc(sizeof(struct es1371_state), GFP_KERNEL))) {
2813 printk(KERN_WARNING PFX "out of memory\n");
2814 return -ENOMEM;
2815 }
2816 memset(s, 0, sizeof(struct es1371_state));
2817
2818 s->codec = ac97_alloc_codec();
2819 if(s->codec == NULL)
2820 goto err_codec;
2821
2822 init_waitqueue_head(&s->dma_adc.wait);
2823 init_waitqueue_head(&s->dma_dac1.wait);
2824 init_waitqueue_head(&s->dma_dac2.wait);
2825 init_waitqueue_head(&s->open_wait);
2826 init_waitqueue_head(&s->midi.iwait);
2827 init_waitqueue_head(&s->midi.owait);
2828 init_MUTEX(&s->open_sem);
2829 spin_lock_init(&s->lock);
2830 s->magic = ES1371_MAGIC;
2831 s->dev = pcidev;
2832 s->io = pci_resource_start(pcidev, 0);
2833 s->irq = pcidev->irq;
2834 s->vendor = pcidev->vendor;
2835 s->device = pcidev->device;
2836 pci_read_config_byte(pcidev, PCI_REVISION_ID, &s->rev);
2837 s->codec->private_data = s;
2838 s->codec->id = 0;
2839 s->codec->codec_read = rdcodec;
2840 s->codec->codec_write = wrcodec;
2841 printk(KERN_INFO PFX "found chip, vendor id 0x%04x device id 0x%04x revision 0x%02x\n",
2842 s->vendor, s->device, s->rev);
2843 if (!request_region(s->io, ES1371_EXTENT, "es1371")) {
2844 printk(KERN_ERR PFX "io ports %#lx-%#lx in use\n", s->io, s->io+ES1371_EXTENT-1);
2845 res = -EBUSY;
2846 goto err_region;
2847 }
2848 if ((res=request_irq(s->irq, es1371_interrupt, SA_SHIRQ, "es1371",s))) {
2849 printk(KERN_ERR PFX "irq %u in use\n", s->irq);
2850 goto err_irq;
2851 }
2852 printk(KERN_INFO PFX "found es1371 rev %d at io %#lx irq %u\n",
2853 s->rev, s->io, s->irq);
2854 /* register devices */
2855 if ((res=(s->dev_audio = register_sound_dsp(&es1371_audio_fops,-1)))<0)
2856 goto err_dev1;
2857 if ((res=(s->codec->dev_mixer = register_sound_mixer(&es1371_mixer_fops, -1))) < 0)
2858 goto err_dev2;
2859 if ((res=(s->dev_dac = register_sound_dsp(&es1371_dac_fops, -1))) < 0)
2860 goto err_dev3;
2861 if ((res=(s->dev_midi = register_sound_midi(&es1371_midi_fops, -1)))<0 )
2862 goto err_dev4;
2863#ifdef ES1371_DEBUG
2864 /* initialize the debug proc device */
2865 s->ps = create_proc_read_entry("es1371",0,NULL,proc_es1371_dump,NULL);
2866#endif /* ES1371_DEBUG */
2867
2868 /* initialize codec registers */
2869 s->ctrl = 0;
2870
2871 /* Check amplifier requirements */
2872
2873 if (amplifier[devindex])
2874 s->ctrl |= CTRL_GPIO_OUT0;
2875 else for(idx = 0; amplifier_needed[idx].svid != PCI_ANY_ID; idx++)
2876 {
2877 if(pcidev->subsystem_vendor == amplifier_needed[idx].svid &&
2878 pcidev->subsystem_device == amplifier_needed[idx].sdid)
2879 {
2880 s->ctrl |= CTRL_GPIO_OUT0; /* turn internal amplifier on */
2881 printk(KERN_INFO PFX "Enabling internal amplifier.\n");
2882 }
2883 }
2884
2885 for (gpio = 0x218; gpio >= 0x200; gpio -= 0x08)
2886 if (request_region(gpio, JOY_EXTENT, "es1371"))
2887 break;
2888
2889 if (gpio < 0x200) {
2890 printk(KERN_ERR PFX "no free joystick address found\n");
2891 } else if (!(s->gameport = gp = gameport_allocate_port())) {
2892 printk(KERN_ERR PFX "can not allocate memory for gameport\n");
2893 release_region(gpio, JOY_EXTENT);
2894 } else {
2895 gameport_set_name(gp, "ESS1371 Gameport");
2896 gameport_set_phys(gp, "isa%04x/gameport0", gpio);
2897 gp->dev.parent = &s->dev->dev;
2898 gp->io = gpio;
2899 s->ctrl |= CTRL_JYSTK_EN | (((gpio >> 3) & CTRL_JOY_MASK) << CTRL_JOY_SHIFT);
2900 }
2901
2902 s->sctrl = 0;
2903 cssr = 0;
2904 s->spdif_volume = -1;
2905 /* check to see if s/pdif mode is being requested */
2906 if (spdif[devindex]) {
2907 if (s->rev >= 4) {
2908 printk(KERN_INFO PFX "enabling S/PDIF output\n");
2909 s->spdif_volume = 0;
2910 cssr |= STAT_EN_SPDIF;
2911 s->ctrl |= CTRL_SPDIFEN_B;
2912 if (nomix[devindex]) /* don't mix analog inputs to s/pdif output */
2913 s->ctrl |= CTRL_RECEN_B;
2914 } else {
2915 printk(KERN_ERR PFX "revision %d does not support S/PDIF\n", s->rev);
2916 }
2917 }
2918 /* initialize the chips */
2919 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
2920 outl(s->sctrl, s->io+ES1371_REG_SERIAL_CONTROL);
2921 outl(LEGACY_JFAST, s->io+ES1371_REG_LEGACY);
2922 pci_set_master(pcidev); /* enable bus mastering */
2923 /* if we are a 5880 turn on the AC97 */
2924 if (s->vendor == PCI_VENDOR_ID_ENSONIQ &&
2925 ((s->device == PCI_DEVICE_ID_ENSONIQ_CT5880 && s->rev >= CT5880REV_CT5880_C) ||
2926 (s->device == PCI_DEVICE_ID_ENSONIQ_ES1371 && s->rev == ES1371REV_CT5880_A) ||
2927 (s->device == PCI_DEVICE_ID_ENSONIQ_ES1371 && s->rev == ES1371REV_ES1373_8))) {
2928 cssr |= CSTAT_5880_AC97_RST;
2929 outl(cssr, s->io+ES1371_REG_STATUS);
2930 /* need to delay around 20ms(bleech) to give
2931 some CODECs enough time to wakeup */
2932 tmo = jiffies + (HZ / 50) + 1;
2933 for (;;) {
2934 tmo2 = tmo - jiffies;
2935 if (tmo2 <= 0)
2936 break;
2937 schedule_timeout(tmo2);
2938 }
2939 }
2940 /* AC97 warm reset to start the bitclk */
2941 outl(s->ctrl | CTRL_SYNCRES, s->io+ES1371_REG_CONTROL);
2942 udelay(2);
2943 outl(s->ctrl, s->io+ES1371_REG_CONTROL);
2944 /* init the sample rate converter */
2945 src_init(s);
2946 /* codec init */
2947 if (!ac97_probe_codec(s->codec)) {
2948 res = -ENODEV;
2949 goto err_gp;
2950 }
2951 /* set default values */
2952
2953 fs = get_fs();
2954 set_fs(KERNEL_DS);
2955 val = SOUND_MASK_LINE;
2956 mixdev_ioctl(s->codec, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
2957 for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
2958 val = initvol[i].vol;
2959 mixdev_ioctl(s->codec, initvol[i].mixch, (unsigned long)&val);
2960 }
2961 /* mute master and PCM when in S/PDIF mode */
2962 if (s->spdif_volume != -1) {
2963 val = 0x0000;
2964 s->codec->mixer_ioctl(s->codec, SOUND_MIXER_WRITE_VOLUME, (unsigned long)&val);
2965 s->codec->mixer_ioctl(s->codec, SOUND_MIXER_WRITE_PCM, (unsigned long)&val);
2966 }
2967 set_fs(fs);
2968 /* turn on S/PDIF output driver if requested */
2969 outl(cssr, s->io+ES1371_REG_STATUS);
2970
2971 /* register gameport */
2972 if (s->gameport)
2973 gameport_register_port(s->gameport);
2974
2975 /* store it in the driver field */
2976 pci_set_drvdata(pcidev, s);
2977 /* put it into driver list */
2978 list_add_tail(&s->devs, &devs);
2979 /* increment devindex */
2980 if (devindex < NR_DEVICE-1)
2981 devindex++;
2982 return 0;
2983
2984 err_gp:
2985 if (s->gameport) {
2986 release_region(s->gameport->io, JOY_EXTENT);
2987 gameport_free_port(s->gameport);
2988 }
2989#ifdef ES1371_DEBUG
2990 if (s->ps)
2991 remove_proc_entry("es1371", NULL);
2992#endif
2993 unregister_sound_midi(s->dev_midi);
2994 err_dev4:
2995 unregister_sound_dsp(s->dev_dac);
2996 err_dev3:
2997 unregister_sound_mixer(s->codec->dev_mixer);
2998 err_dev2:
2999 unregister_sound_dsp(s->dev_audio);
3000 err_dev1:
3001 printk(KERN_ERR PFX "cannot register misc device\n");
3002 free_irq(s->irq, s);
3003 err_irq:
3004 release_region(s->io, ES1371_EXTENT);
3005 err_region:
3006 err_codec:
3007 ac97_release_codec(s->codec);
3008 kfree(s);
3009 return res;
3010}
3011
3012static void __devexit es1371_remove(struct pci_dev *dev)
3013{
3014 struct es1371_state *s = pci_get_drvdata(dev);
3015
3016 if (!s)
3017 return;
3018 list_del(&s->devs);
3019#ifdef ES1371_DEBUG
3020 if (s->ps)
3021 remove_proc_entry("es1371", NULL);
3022#endif /* ES1371_DEBUG */
3023 outl(0, s->io+ES1371_REG_CONTROL); /* switch everything off */
3024 outl(0, s->io+ES1371_REG_SERIAL_CONTROL); /* clear serial interrupts */
3025 synchronize_irq(s->irq);
3026 free_irq(s->irq, s);
3027 if (s->gameport) {
3028 int gpio = s->gameport->io;
3029 gameport_unregister_port(s->gameport);
3030 release_region(gpio, JOY_EXTENT);
3031 }
3032 release_region(s->io, ES1371_EXTENT);
3033 unregister_sound_dsp(s->dev_audio);
3034 unregister_sound_mixer(s->codec->dev_mixer);
3035 unregister_sound_dsp(s->dev_dac);
3036 unregister_sound_midi(s->dev_midi);
3037 ac97_release_codec(s->codec);
3038 kfree(s);
3039 pci_set_drvdata(dev, NULL);
3040}
3041
3042static struct pci_device_id id_table[] = {
3043 { PCI_VENDOR_ID_ENSONIQ, PCI_DEVICE_ID_ENSONIQ_ES1371, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
3044 { PCI_VENDOR_ID_ENSONIQ, PCI_DEVICE_ID_ENSONIQ_CT5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
3045 { PCI_VENDOR_ID_ECTIVA, PCI_DEVICE_ID_ECTIVA_EV1938, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
3046 { 0, }
3047};
3048
3049MODULE_DEVICE_TABLE(pci, id_table);
3050
3051static struct pci_driver es1371_driver = {
3052 .name = "es1371",
3053 .id_table = id_table,
3054 .probe = es1371_probe,
3055 .remove = __devexit_p(es1371_remove),
3056};
3057
3058static int __init init_es1371(void)
3059{
3060 printk(KERN_INFO PFX "version v0.32 time " __TIME__ " " __DATE__ "\n");
3061 return pci_module_init(&es1371_driver);
3062}
3063
3064static void __exit cleanup_es1371(void)
3065{
3066 printk(KERN_INFO PFX "unloading\n");
3067 pci_unregister_driver(&es1371_driver);
3068}
3069
3070module_init(init_es1371);
3071module_exit(cleanup_es1371);
3072
3073/* --------------------------------------------------------------------- */
3074
3075#ifndef MODULE
3076
3077/* format is: es1371=[spdif,[nomix,[amplifier]]] */
3078
3079static int __init es1371_setup(char *str)
3080{
3081 static unsigned __initdata nr_dev = 0;
3082
3083 if (nr_dev >= NR_DEVICE)
3084 return 0;
3085
3086 (void)
3087 ((get_option(&str, &spdif[nr_dev]) == 2)
3088 && (get_option(&str, &nomix[nr_dev]) == 2)
3089 && (get_option(&str, &amplifier[nr_dev])));
3090
3091 nr_dev++;
3092 return 1;
3093}
3094
3095__setup("es1371=", es1371_setup);
3096
3097#endif /* MODULE */
diff --git a/sound/oss/esssolo1.c b/sound/oss/esssolo1.c
new file mode 100644
index 000000000000..6b3b9a99579d
--- /dev/null
+++ b/sound/oss/esssolo1.c
@@ -0,0 +1,2497 @@
1/****************************************************************************/
2
3/*
4 * esssolo1.c -- ESS Technology Solo1 (ES1946) audio driver.
5 *
6 * Copyright (C) 1998-2001, 2003 Thomas Sailer (t.sailer@alumni.ethz.ch)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * Module command line parameters:
23 * none so far
24 *
25 * Supported devices:
26 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
27 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
28 * /dev/midi simple MIDI UART interface, no ioctl
29 *
30 * Revision history
31 * 10.11.1998 0.1 Initial release (without any hardware)
32 * 22.03.1999 0.2 cinfo.blocks should be reset after GETxPTR ioctl.
33 * reported by Johan Maes <joma@telindus.be>
34 * return EAGAIN instead of EBUSY when O_NONBLOCK
35 * read/write cannot be executed
36 * 07.04.1999 0.3 implemented the following ioctl's: SOUND_PCM_READ_RATE,
37 * SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
38 * Alpha fixes reported by Peter Jones <pjones@redhat.com>
39 * 15.06.1999 0.4 Fix bad allocation bug.
40 * Thanks to Deti Fliegl <fliegl@in.tum.de>
41 * 28.06.1999 0.5 Add pci_set_master
42 * 12.08.1999 0.6 Fix MIDI UART crashing the driver
43 * Changed mixer semantics from OSS documented
44 * behaviour to OSS "code behaviour".
45 * Recording might actually work now.
46 * The real DDMA controller address register is at PCI config
47 * 0x60, while the register at 0x18 is used as a placeholder
48 * register for BIOS address allocation. This register
49 * is supposed to be copied into 0x60, according
50 * to the Solo1 datasheet. When I do that, I can access
51 * the DDMA registers except the mask bit, which
52 * is stuck at 1. When I copy the contents of 0x18 +0x10
53 * to the DDMA base register, everything seems to work.
54 * The fun part is that the Windows Solo1 driver doesn't
55 * seem to do these tricks.
56 * Bugs remaining: plops and clicks when starting/stopping playback
57 * 31.08.1999 0.7 add spin_lock_init
58 * replaced current->state = x with set_current_state(x)
59 * 03.09.1999 0.8 change read semantics for MIDI to match
60 * OSS more closely; remove possible wakeup race
61 * 07.10.1999 0.9 Fix initialization; complain if sequencer writes time out
62 * Revised resource grabbing for the FM synthesizer
63 * 28.10.1999 0.10 More waitqueue races fixed
64 * 09.12.1999 0.11 Work around stupid Alpha port issue (virt_to_bus(kmalloc(GFP_DMA)) > 16M)
65 * Disabling recording on Alpha
66 * 12.01.2000 0.12 Prevent some ioctl's from returning bad count values on underrun/overrun;
67 * Tim Janik's BSE (Bedevilled Sound Engine) found this
68 * Integrated (aka redid 8-)) APM support patch by Zach Brown
69 * 07.02.2000 0.13 Use pci_alloc_consistent and pci_register_driver
70 * 19.02.2000 0.14 Use pci_dma_supported to determine if recording should be disabled
71 * 13.03.2000 0.15 Reintroduce initialization of a couple of PCI config space registers
72 * 21.11.2000 0.16 Initialize dma buffers in poll, otherwise poll may return a bogus mask
73 * 12.12.2000 0.17 More dma buffer initializations, patch from
74 * Tjeerd Mulder <tjeerd.mulder@fujitsu-siemens.com>
75 * 31.01.2001 0.18 Register/Unregister gameport, original patch from
76 * Nathaniel Daw <daw@cs.cmu.edu>
77 * Fix SETTRIGGER non OSS API conformity
78 * 10.03.2001 provide abs function, prevent picking up a bogus kernel macro
79 * for abs. Bug report by Andrew Morton <andrewm@uow.edu.au>
80 * 15.05.2001 pci_enable_device moved, return values in probe cleaned
81 * up. Marcus Meissner <mm@caldera.de>
82 * 22.05.2001 0.19 more cleanups, changed PM to PCI 2.4 style, got rid
83 * of global list of devices, using pci device data.
84 * Marcus Meissner <mm@caldera.de>
85 * 03.01.2003 0.20 open_mode fixes from Georg Acher <acher@in.tum.de>
86 */
87
88/*****************************************************************************/
89
90#include <linux/interrupt.h>
91#include <linux/module.h>
92#include <linux/string.h>
93#include <linux/ioport.h>
94#include <linux/sched.h>
95#include <linux/delay.h>
96#include <linux/sound.h>
97#include <linux/slab.h>
98#include <linux/soundcard.h>
99#include <linux/pci.h>
100#include <linux/bitops.h>
101#include <linux/init.h>
102#include <linux/poll.h>
103#include <linux/spinlock.h>
104#include <linux/smp_lock.h>
105#include <linux/gameport.h>
106#include <linux/wait.h>
107
108#include <asm/io.h>
109#include <asm/page.h>
110#include <asm/uaccess.h>
111
112#include "dm.h"
113
114/* --------------------------------------------------------------------- */
115
116#undef OSS_DOCUMENTED_MIXER_SEMANTICS
117
118/* --------------------------------------------------------------------- */
119
120#ifndef PCI_VENDOR_ID_ESS
121#define PCI_VENDOR_ID_ESS 0x125d
122#endif
123#ifndef PCI_DEVICE_ID_ESS_SOLO1
124#define PCI_DEVICE_ID_ESS_SOLO1 0x1969
125#endif
126
127#define SOLO1_MAGIC ((PCI_VENDOR_ID_ESS<<16)|PCI_DEVICE_ID_ESS_SOLO1)
128
129#define DDMABASE_OFFSET 0 /* chip bug workaround kludge */
130#define DDMABASE_EXTENT 16
131
132#define IOBASE_EXTENT 16
133#define SBBASE_EXTENT 16
134#define VCBASE_EXTENT (DDMABASE_EXTENT+DDMABASE_OFFSET)
135#define MPUBASE_EXTENT 4
136#define GPBASE_EXTENT 4
137#define GAMEPORT_EXTENT 4
138
139#define FMSYNTH_EXTENT 4
140
141/* MIDI buffer sizes */
142
143#define MIDIINBUF 256
144#define MIDIOUTBUF 256
145
146#define FMODE_MIDI_SHIFT 3
147#define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
148#define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
149
150#define FMODE_DMFM 0x10
151
152static struct pci_driver solo1_driver;
153
154/* --------------------------------------------------------------------- */
155
156struct solo1_state {
157 /* magic */
158 unsigned int magic;
159
160 /* the corresponding pci_dev structure */
161 struct pci_dev *dev;
162
163 /* soundcore stuff */
164 int dev_audio;
165 int dev_mixer;
166 int dev_midi;
167 int dev_dmfm;
168
169 /* hardware resources */
170 unsigned long iobase, sbbase, vcbase, ddmabase, mpubase; /* long for SPARC */
171 unsigned int irq;
172
173 /* mixer registers */
174 struct {
175 unsigned short vol[10];
176 unsigned int recsrc;
177 unsigned int modcnt;
178 unsigned short micpreamp;
179 } mix;
180
181 /* wave stuff */
182 unsigned fmt;
183 unsigned channels;
184 unsigned rate;
185 unsigned char clkdiv;
186 unsigned ena;
187
188 spinlock_t lock;
189 struct semaphore open_sem;
190 mode_t open_mode;
191 wait_queue_head_t open_wait;
192
193 struct dmabuf {
194 void *rawbuf;
195 dma_addr_t dmaaddr;
196 unsigned buforder;
197 unsigned numfrag;
198 unsigned fragshift;
199 unsigned hwptr, swptr;
200 unsigned total_bytes;
201 int count;
202 unsigned error; /* over/underrun */
203 wait_queue_head_t wait;
204 /* redundant, but makes calculations easier */
205 unsigned fragsize;
206 unsigned dmasize;
207 unsigned fragsamples;
208 /* OSS stuff */
209 unsigned mapped:1;
210 unsigned ready:1;
211 unsigned endcleared:1;
212 unsigned enabled:1;
213 unsigned ossfragshift;
214 int ossmaxfrags;
215 unsigned subdivision;
216 } dma_dac, dma_adc;
217
218 /* midi stuff */
219 struct {
220 unsigned ird, iwr, icnt;
221 unsigned ord, owr, ocnt;
222 wait_queue_head_t iwait;
223 wait_queue_head_t owait;
224 struct timer_list timer;
225 unsigned char ibuf[MIDIINBUF];
226 unsigned char obuf[MIDIOUTBUF];
227 } midi;
228
229 struct gameport *gameport;
230};
231
232/* --------------------------------------------------------------------- */
233
234static inline void write_seq(struct solo1_state *s, unsigned char data)
235{
236 int i;
237 unsigned long flags;
238
239 /* the local_irq_save stunt is to send the data within the command window */
240 for (i = 0; i < 0xffff; i++) {
241 local_irq_save(flags);
242 if (!(inb(s->sbbase+0xc) & 0x80)) {
243 outb(data, s->sbbase+0xc);
244 local_irq_restore(flags);
245 return;
246 }
247 local_irq_restore(flags);
248 }
249 printk(KERN_ERR "esssolo1: write_seq timeout\n");
250 outb(data, s->sbbase+0xc);
251}
252
253static inline int read_seq(struct solo1_state *s, unsigned char *data)
254{
255 int i;
256
257 if (!data)
258 return 0;
259 for (i = 0; i < 0xffff; i++)
260 if (inb(s->sbbase+0xe) & 0x80) {
261 *data = inb(s->sbbase+0xa);
262 return 1;
263 }
264 printk(KERN_ERR "esssolo1: read_seq timeout\n");
265 return 0;
266}
267
268static inline int reset_ctrl(struct solo1_state *s)
269{
270 int i;
271
272 outb(3, s->sbbase+6); /* clear sequencer and FIFO */
273 udelay(10);
274 outb(0, s->sbbase+6);
275 for (i = 0; i < 0xffff; i++)
276 if (inb(s->sbbase+0xe) & 0x80)
277 if (inb(s->sbbase+0xa) == 0xaa) {
278 write_seq(s, 0xc6); /* enter enhanced mode */
279 return 1;
280 }
281 return 0;
282}
283
284static void write_ctrl(struct solo1_state *s, unsigned char reg, unsigned char data)
285{
286 write_seq(s, reg);
287 write_seq(s, data);
288}
289
290#if 0 /* unused */
291static unsigned char read_ctrl(struct solo1_state *s, unsigned char reg)
292{
293 unsigned char r;
294
295 write_seq(s, 0xc0);
296 write_seq(s, reg);
297 read_seq(s, &r);
298 return r;
299}
300#endif /* unused */
301
302static void write_mixer(struct solo1_state *s, unsigned char reg, unsigned char data)
303{
304 outb(reg, s->sbbase+4);
305 outb(data, s->sbbase+5);
306}
307
308static unsigned char read_mixer(struct solo1_state *s, unsigned char reg)
309{
310 outb(reg, s->sbbase+4);
311 return inb(s->sbbase+5);
312}
313
314/* --------------------------------------------------------------------- */
315
316static inline unsigned ld2(unsigned int x)
317{
318 unsigned r = 0;
319
320 if (x >= 0x10000) {
321 x >>= 16;
322 r += 16;
323 }
324 if (x >= 0x100) {
325 x >>= 8;
326 r += 8;
327 }
328 if (x >= 0x10) {
329 x >>= 4;
330 r += 4;
331 }
332 if (x >= 4) {
333 x >>= 2;
334 r += 2;
335 }
336 if (x >= 2)
337 r++;
338 return r;
339}
340
341/* --------------------------------------------------------------------- */
342
343static inline void stop_dac(struct solo1_state *s)
344{
345 unsigned long flags;
346
347 spin_lock_irqsave(&s->lock, flags);
348 s->ena &= ~FMODE_WRITE;
349 write_mixer(s, 0x78, 0x10);
350 spin_unlock_irqrestore(&s->lock, flags);
351}
352
353static void start_dac(struct solo1_state *s)
354{
355 unsigned long flags;
356
357 spin_lock_irqsave(&s->lock, flags);
358 if (!(s->ena & FMODE_WRITE) && (s->dma_dac.mapped || s->dma_dac.count > 0) && s->dma_dac.ready) {
359 s->ena |= FMODE_WRITE;
360 write_mixer(s, 0x78, 0x12);
361 udelay(10);
362 write_mixer(s, 0x78, 0x13);
363 }
364 spin_unlock_irqrestore(&s->lock, flags);
365}
366
367static inline void stop_adc(struct solo1_state *s)
368{
369 unsigned long flags;
370
371 spin_lock_irqsave(&s->lock, flags);
372 s->ena &= ~FMODE_READ;
373 write_ctrl(s, 0xb8, 0xe);
374 spin_unlock_irqrestore(&s->lock, flags);
375}
376
377static void start_adc(struct solo1_state *s)
378{
379 unsigned long flags;
380
381 spin_lock_irqsave(&s->lock, flags);
382 if (!(s->ena & FMODE_READ) && (s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
383 && s->dma_adc.ready) {
384 s->ena |= FMODE_READ;
385 write_ctrl(s, 0xb8, 0xf);
386#if 0
387 printk(KERN_DEBUG "solo1: DMAbuffer: 0x%08lx\n", (long)s->dma_adc.rawbuf);
388 printk(KERN_DEBUG "solo1: DMA: mask: 0x%02x cnt: 0x%04x addr: 0x%08x stat: 0x%02x\n",
389 inb(s->ddmabase+0xf), inw(s->ddmabase+4), inl(s->ddmabase), inb(s->ddmabase+8));
390#endif
391 outb(0, s->ddmabase+0xd); /* master reset */
392 outb(1, s->ddmabase+0xf); /* mask */
393 outb(0x54/*0x14*/, s->ddmabase+0xb); /* DMA_MODE_READ | DMA_MODE_AUTOINIT */
394 outl(virt_to_bus(s->dma_adc.rawbuf), s->ddmabase);
395 outw(s->dma_adc.dmasize-1, s->ddmabase+4);
396 outb(0, s->ddmabase+0xf);
397 }
398 spin_unlock_irqrestore(&s->lock, flags);
399#if 0
400 printk(KERN_DEBUG "solo1: start DMA: reg B8: 0x%02x SBstat: 0x%02x\n"
401 KERN_DEBUG "solo1: DMA: stat: 0x%02x cnt: 0x%04x mask: 0x%02x\n",
402 read_ctrl(s, 0xb8), inb(s->sbbase+0xc),
403 inb(s->ddmabase+8), inw(s->ddmabase+4), inb(s->ddmabase+0xf));
404 printk(KERN_DEBUG "solo1: A1: 0x%02x A2: 0x%02x A4: 0x%02x A5: 0x%02x A8: 0x%02x\n"
405 KERN_DEBUG "solo1: B1: 0x%02x B2: 0x%02x B4: 0x%02x B7: 0x%02x B8: 0x%02x B9: 0x%02x\n",
406 read_ctrl(s, 0xa1), read_ctrl(s, 0xa2), read_ctrl(s, 0xa4), read_ctrl(s, 0xa5), read_ctrl(s, 0xa8),
407 read_ctrl(s, 0xb1), read_ctrl(s, 0xb2), read_ctrl(s, 0xb4), read_ctrl(s, 0xb7), read_ctrl(s, 0xb8),
408 read_ctrl(s, 0xb9));
409#endif
410}
411
412/* --------------------------------------------------------------------- */
413
414#define DMABUF_DEFAULTORDER (15-PAGE_SHIFT)
415#define DMABUF_MINORDER 1
416
417static inline void dealloc_dmabuf(struct solo1_state *s, struct dmabuf *db)
418{
419 struct page *page, *pend;
420
421 if (db->rawbuf) {
422 /* undo marking the pages as reserved */
423 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
424 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
425 ClearPageReserved(page);
426 pci_free_consistent(s->dev, PAGE_SIZE << db->buforder, db->rawbuf, db->dmaaddr);
427 }
428 db->rawbuf = NULL;
429 db->mapped = db->ready = 0;
430}
431
432static int prog_dmabuf(struct solo1_state *s, struct dmabuf *db)
433{
434 int order;
435 unsigned bytespersec;
436 unsigned bufs, sample_shift = 0;
437 struct page *page, *pend;
438
439 db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
440 if (!db->rawbuf) {
441 db->ready = db->mapped = 0;
442 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--)
443 if ((db->rawbuf = pci_alloc_consistent(s->dev, PAGE_SIZE << order, &db->dmaaddr)))
444 break;
445 if (!db->rawbuf)
446 return -ENOMEM;
447 db->buforder = order;
448 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
449 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
450 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
451 SetPageReserved(page);
452 }
453 if (s->fmt & (AFMT_S16_LE | AFMT_U16_LE))
454 sample_shift++;
455 if (s->channels > 1)
456 sample_shift++;
457 bytespersec = s->rate << sample_shift;
458 bufs = PAGE_SIZE << db->buforder;
459 if (db->ossfragshift) {
460 if ((1000 << db->ossfragshift) < bytespersec)
461 db->fragshift = ld2(bytespersec/1000);
462 else
463 db->fragshift = db->ossfragshift;
464 } else {
465 db->fragshift = ld2(bytespersec/100/(db->subdivision ? db->subdivision : 1));
466 if (db->fragshift < 3)
467 db->fragshift = 3;
468 }
469 db->numfrag = bufs >> db->fragshift;
470 while (db->numfrag < 4 && db->fragshift > 3) {
471 db->fragshift--;
472 db->numfrag = bufs >> db->fragshift;
473 }
474 db->fragsize = 1 << db->fragshift;
475 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
476 db->numfrag = db->ossmaxfrags;
477 db->fragsamples = db->fragsize >> sample_shift;
478 db->dmasize = db->numfrag << db->fragshift;
479 db->enabled = 1;
480 return 0;
481}
482
483static inline int prog_dmabuf_adc(struct solo1_state *s)
484{
485 unsigned long va;
486 int c;
487
488 stop_adc(s);
489 /* check if PCI implementation supports 24bit busmaster DMA */
490 if (s->dev->dma_mask > 0xffffff)
491 return -EIO;
492 if ((c = prog_dmabuf(s, &s->dma_adc)))
493 return c;
494 va = s->dma_adc.dmaaddr;
495 if ((va & ~((1<<24)-1)))
496 panic("solo1: buffer above 16M boundary");
497 outb(0, s->ddmabase+0xd); /* clear */
498 outb(1, s->ddmabase+0xf); /* mask */
499 /*outb(0, s->ddmabase+8);*/ /* enable (enable is active low!) */
500 outb(0x54, s->ddmabase+0xb); /* DMA_MODE_READ | DMA_MODE_AUTOINIT */
501 outl(va, s->ddmabase);
502 outw(s->dma_adc.dmasize-1, s->ddmabase+4);
503 c = - s->dma_adc.fragsamples;
504 write_ctrl(s, 0xa4, c);
505 write_ctrl(s, 0xa5, c >> 8);
506 outb(0, s->ddmabase+0xf);
507 s->dma_adc.ready = 1;
508 return 0;
509}
510
511static inline int prog_dmabuf_dac(struct solo1_state *s)
512{
513 unsigned long va;
514 int c;
515
516 stop_dac(s);
517 if ((c = prog_dmabuf(s, &s->dma_dac)))
518 return c;
519 memset(s->dma_dac.rawbuf, (s->fmt & (AFMT_U8 | AFMT_U16_LE)) ? 0 : 0x80, s->dma_dac.dmasize); /* almost correct for U16 */
520 va = s->dma_dac.dmaaddr;
521 if ((va ^ (va + s->dma_dac.dmasize - 1)) & ~((1<<20)-1))
522 panic("solo1: buffer crosses 1M boundary");
523 outl(va, s->iobase);
524 /* warning: s->dma_dac.dmasize & 0xffff must not be zero! i.e. this limits us to a 32k buffer */
525 outw(s->dma_dac.dmasize, s->iobase+4);
526 c = - s->dma_dac.fragsamples;
527 write_mixer(s, 0x74, c);
528 write_mixer(s, 0x76, c >> 8);
529 outb(0xa, s->iobase+6);
530 s->dma_dac.ready = 1;
531 return 0;
532}
533
534static inline void clear_advance(void *buf, unsigned bsize, unsigned bptr, unsigned len, unsigned char c)
535{
536 if (bptr + len > bsize) {
537 unsigned x = bsize - bptr;
538 memset(((char *)buf) + bptr, c, x);
539 bptr = 0;
540 len -= x;
541 }
542 memset(((char *)buf) + bptr, c, len);
543}
544
545/* call with spinlock held! */
546
547static void solo1_update_ptr(struct solo1_state *s)
548{
549 int diff;
550 unsigned hwptr;
551
552 /* update ADC pointer */
553 if (s->ena & FMODE_READ) {
554 hwptr = (s->dma_adc.dmasize - 1 - inw(s->ddmabase+4)) % s->dma_adc.dmasize;
555 diff = (s->dma_adc.dmasize + hwptr - s->dma_adc.hwptr) % s->dma_adc.dmasize;
556 s->dma_adc.hwptr = hwptr;
557 s->dma_adc.total_bytes += diff;
558 s->dma_adc.count += diff;
559#if 0
560 printk(KERN_DEBUG "solo1: rd: hwptr %u swptr %u dmasize %u count %u\n",
561 s->dma_adc.hwptr, s->dma_adc.swptr, s->dma_adc.dmasize, s->dma_adc.count);
562#endif
563 if (s->dma_adc.mapped) {
564 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
565 wake_up(&s->dma_adc.wait);
566 } else {
567 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
568 s->ena &= ~FMODE_READ;
569 write_ctrl(s, 0xb8, 0xe);
570 s->dma_adc.error++;
571 }
572 if (s->dma_adc.count > 0)
573 wake_up(&s->dma_adc.wait);
574 }
575 }
576 /* update DAC pointer */
577 if (s->ena & FMODE_WRITE) {
578 hwptr = (s->dma_dac.dmasize - inw(s->iobase+4)) % s->dma_dac.dmasize;
579 diff = (s->dma_dac.dmasize + hwptr - s->dma_dac.hwptr) % s->dma_dac.dmasize;
580 s->dma_dac.hwptr = hwptr;
581 s->dma_dac.total_bytes += diff;
582#if 0
583 printk(KERN_DEBUG "solo1: wr: hwptr %u swptr %u dmasize %u count %u\n",
584 s->dma_dac.hwptr, s->dma_dac.swptr, s->dma_dac.dmasize, s->dma_dac.count);
585#endif
586 if (s->dma_dac.mapped) {
587 s->dma_dac.count += diff;
588 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
589 wake_up(&s->dma_dac.wait);
590 } else {
591 s->dma_dac.count -= diff;
592 if (s->dma_dac.count <= 0) {
593 s->ena &= ~FMODE_WRITE;
594 write_mixer(s, 0x78, 0x12);
595 s->dma_dac.error++;
596 } else if (s->dma_dac.count <= (signed)s->dma_dac.fragsize && !s->dma_dac.endcleared) {
597 clear_advance(s->dma_dac.rawbuf, s->dma_dac.dmasize, s->dma_dac.swptr,
598 s->dma_dac.fragsize, (s->fmt & (AFMT_U8 | AFMT_U16_LE)) ? 0 : 0x80);
599 s->dma_dac.endcleared = 1;
600 }
601 if (s->dma_dac.count < (signed)s->dma_dac.dmasize)
602 wake_up(&s->dma_dac.wait);
603 }
604 }
605}
606
607/* --------------------------------------------------------------------- */
608
609static void prog_codec(struct solo1_state *s)
610{
611 unsigned long flags;
612 int fdiv, filter;
613 unsigned char c;
614
615 reset_ctrl(s);
616 write_seq(s, 0xd3);
617 /* program sampling rates */
618 filter = s->rate * 9 / 20; /* Set filter roll-off to 90% of rate/2 */
619 fdiv = 256 - 7160000 / (filter * 82);
620 spin_lock_irqsave(&s->lock, flags);
621 write_ctrl(s, 0xa1, s->clkdiv);
622 write_ctrl(s, 0xa2, fdiv);
623 write_mixer(s, 0x70, s->clkdiv);
624 write_mixer(s, 0x72, fdiv);
625 /* program ADC parameters */
626 write_ctrl(s, 0xb8, 0xe);
627 write_ctrl(s, 0xb9, /*0x1*/0);
628 write_ctrl(s, 0xa8, (s->channels > 1) ? 0x11 : 0x12);
629 c = 0xd0;
630 if (s->fmt & (AFMT_S16_LE | AFMT_U16_LE))
631 c |= 0x04;
632 if (s->fmt & (AFMT_S16_LE | AFMT_S8))
633 c |= 0x20;
634 if (s->channels > 1)
635 c ^= 0x48;
636 write_ctrl(s, 0xb7, (c & 0x70) | 1);
637 write_ctrl(s, 0xb7, c);
638 write_ctrl(s, 0xb1, 0x50);
639 write_ctrl(s, 0xb2, 0x50);
640 /* program DAC parameters */
641 c = 0x40;
642 if (s->fmt & (AFMT_S16_LE | AFMT_U16_LE))
643 c |= 1;
644 if (s->fmt & (AFMT_S16_LE | AFMT_S8))
645 c |= 4;
646 if (s->channels > 1)
647 c |= 2;
648 write_mixer(s, 0x7a, c);
649 write_mixer(s, 0x78, 0x10);
650 s->ena = 0;
651 spin_unlock_irqrestore(&s->lock, flags);
652}
653
654/* --------------------------------------------------------------------- */
655
656static const char invalid_magic[] = KERN_CRIT "solo1: invalid magic value\n";
657
658#define VALIDATE_STATE(s) \
659({ \
660 if (!(s) || (s)->magic != SOLO1_MAGIC) { \
661 printk(invalid_magic); \
662 return -ENXIO; \
663 } \
664})
665
666/* --------------------------------------------------------------------- */
667
668static int mixer_ioctl(struct solo1_state *s, unsigned int cmd, unsigned long arg)
669{
670 static const unsigned int mixer_src[8] = {
671 SOUND_MASK_MIC, SOUND_MASK_MIC, SOUND_MASK_CD, SOUND_MASK_VOLUME,
672 SOUND_MASK_MIC, 0, SOUND_MASK_LINE, 0
673 };
674 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
675 [SOUND_MIXER_PCM] = 1, /* voice */
676 [SOUND_MIXER_SYNTH] = 2, /* FM */
677 [SOUND_MIXER_CD] = 3, /* CD */
678 [SOUND_MIXER_LINE] = 4, /* Line */
679 [SOUND_MIXER_LINE1] = 5, /* AUX */
680 [SOUND_MIXER_MIC] = 6, /* Mic */
681 [SOUND_MIXER_LINE2] = 7, /* Mono in */
682 [SOUND_MIXER_SPEAKER] = 8, /* Speaker */
683 [SOUND_MIXER_RECLEV] = 9, /* Recording level */
684 [SOUND_MIXER_VOLUME] = 10 /* Master Volume */
685 };
686 static const unsigned char mixreg[] = {
687 0x7c, /* voice */
688 0x36, /* FM */
689 0x38, /* CD */
690 0x3e, /* Line */
691 0x3a, /* AUX */
692 0x1a, /* Mic */
693 0x6d /* Mono in */
694 };
695 unsigned char l, r, rl, rr, vidx;
696 int i, val;
697 int __user *p = (int __user *)arg;
698
699 VALIDATE_STATE(s);
700
701 if (cmd == SOUND_MIXER_PRIVATE1) {
702 /* enable/disable/query mixer preamp */
703 if (get_user(val, p))
704 return -EFAULT;
705 if (val != -1) {
706 val = val ? 0xff : 0xf7;
707 write_mixer(s, 0x7d, (read_mixer(s, 0x7d) | 0x08) & val);
708 }
709 val = (read_mixer(s, 0x7d) & 0x08) ? 1 : 0;
710 return put_user(val, p);
711 }
712 if (cmd == SOUND_MIXER_PRIVATE2) {
713 /* enable/disable/query spatializer */
714 if (get_user(val, p))
715 return -EFAULT;
716 if (val != -1) {
717 val &= 0x3f;
718 write_mixer(s, 0x52, val);
719 write_mixer(s, 0x50, val ? 0x08 : 0);
720 }
721 return put_user(read_mixer(s, 0x52), p);
722 }
723 if (cmd == SOUND_MIXER_INFO) {
724 mixer_info info;
725 strncpy(info.id, "Solo1", sizeof(info.id));
726 strncpy(info.name, "ESS Solo1", sizeof(info.name));
727 info.modify_counter = s->mix.modcnt;
728 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
729 return -EFAULT;
730 return 0;
731 }
732 if (cmd == SOUND_OLD_MIXER_INFO) {
733 _old_mixer_info info;
734 strncpy(info.id, "Solo1", sizeof(info.id));
735 strncpy(info.name, "ESS Solo1", sizeof(info.name));
736 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
737 return -EFAULT;
738 return 0;
739 }
740 if (cmd == OSS_GETVERSION)
741 return put_user(SOUND_VERSION, p);
742 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
743 return -EINVAL;
744 if (_SIOC_DIR(cmd) == _SIOC_READ) {
745 switch (_IOC_NR(cmd)) {
746 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
747 return put_user(mixer_src[read_mixer(s, 0x1c) & 7], p);
748
749 case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
750 return put_user(SOUND_MASK_PCM | SOUND_MASK_SYNTH | SOUND_MASK_CD |
751 SOUND_MASK_LINE | SOUND_MASK_LINE1 | SOUND_MASK_MIC |
752 SOUND_MASK_VOLUME | SOUND_MASK_LINE2 | SOUND_MASK_RECLEV |
753 SOUND_MASK_SPEAKER, p);
754
755 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
756 return put_user(SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME, p);
757
758 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
759 return put_user(SOUND_MASK_PCM | SOUND_MASK_SYNTH | SOUND_MASK_CD |
760 SOUND_MASK_LINE | SOUND_MASK_LINE1 | SOUND_MASK_MIC |
761 SOUND_MASK_VOLUME | SOUND_MASK_LINE2 | SOUND_MASK_RECLEV, p);
762
763 case SOUND_MIXER_CAPS:
764 return put_user(SOUND_CAP_EXCL_INPUT, p);
765
766 default:
767 i = _IOC_NR(cmd);
768 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i]))
769 return -EINVAL;
770 return put_user(s->mix.vol[vidx-1], p);
771 }
772 }
773 if (_SIOC_DIR(cmd) != (_SIOC_READ|_SIOC_WRITE))
774 return -EINVAL;
775 s->mix.modcnt++;
776 switch (_IOC_NR(cmd)) {
777 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
778#if 0
779 {
780 static const unsigned char regs[] = {
781 0x1c, 0x1a, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x60, 0x62, 0x6d, 0x7c
782 };
783 int i;
784
785 for (i = 0; i < sizeof(regs); i++)
786 printk(KERN_DEBUG "solo1: mixer reg 0x%02x: 0x%02x\n",
787 regs[i], read_mixer(s, regs[i]));
788 printk(KERN_DEBUG "solo1: ctrl reg 0x%02x: 0x%02x\n",
789 0xb4, read_ctrl(s, 0xb4));
790 }
791#endif
792 if (get_user(val, p))
793 return -EFAULT;
794 i = hweight32(val);
795 if (i == 0)
796 return 0;
797 else if (i > 1)
798 val &= ~mixer_src[read_mixer(s, 0x1c) & 7];
799 for (i = 0; i < 8; i++) {
800 if (mixer_src[i] & val)
801 break;
802 }
803 if (i > 7)
804 return 0;
805 write_mixer(s, 0x1c, i);
806 return 0;
807
808 case SOUND_MIXER_VOLUME:
809 if (get_user(val, p))
810 return -EFAULT;
811 l = val & 0xff;
812 if (l > 100)
813 l = 100;
814 r = (val >> 8) & 0xff;
815 if (r > 100)
816 r = 100;
817 if (l < 6) {
818 rl = 0x40;
819 l = 0;
820 } else {
821 rl = (l * 2 - 11) / 3;
822 l = (rl * 3 + 11) / 2;
823 }
824 if (r < 6) {
825 rr = 0x40;
826 r = 0;
827 } else {
828 rr = (r * 2 - 11) / 3;
829 r = (rr * 3 + 11) / 2;
830 }
831 write_mixer(s, 0x60, rl);
832 write_mixer(s, 0x62, rr);
833#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
834 s->mix.vol[9] = ((unsigned int)r << 8) | l;
835#else
836 s->mix.vol[9] = val;
837#endif
838 return put_user(s->mix.vol[9], p);
839
840 case SOUND_MIXER_SPEAKER:
841 if (get_user(val, p))
842 return -EFAULT;
843 l = val & 0xff;
844 if (l > 100)
845 l = 100;
846 else if (l < 2)
847 l = 2;
848 rl = (l - 2) / 14;
849 l = rl * 14 + 2;
850 write_mixer(s, 0x3c, rl);
851#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
852 s->mix.vol[7] = l * 0x101;
853#else
854 s->mix.vol[7] = val;
855#endif
856 return put_user(s->mix.vol[7], p);
857
858 case SOUND_MIXER_RECLEV:
859 if (get_user(val, p))
860 return -EFAULT;
861 l = (val << 1) & 0x1fe;
862 if (l > 200)
863 l = 200;
864 else if (l < 5)
865 l = 5;
866 r = (val >> 7) & 0x1fe;
867 if (r > 200)
868 r = 200;
869 else if (r < 5)
870 r = 5;
871 rl = (l - 5) / 13;
872 rr = (r - 5) / 13;
873 r = (rl * 13 + 5) / 2;
874 l = (rr * 13 + 5) / 2;
875 write_ctrl(s, 0xb4, (rl << 4) | rr);
876#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
877 s->mix.vol[8] = ((unsigned int)r << 8) | l;
878#else
879 s->mix.vol[8] = val;
880#endif
881 return put_user(s->mix.vol[8], p);
882
883 default:
884 i = _IOC_NR(cmd);
885 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i]))
886 return -EINVAL;
887 if (get_user(val, p))
888 return -EFAULT;
889 l = (val << 1) & 0x1fe;
890 if (l > 200)
891 l = 200;
892 else if (l < 5)
893 l = 5;
894 r = (val >> 7) & 0x1fe;
895 if (r > 200)
896 r = 200;
897 else if (r < 5)
898 r = 5;
899 rl = (l - 5) / 13;
900 rr = (r - 5) / 13;
901 r = (rl * 13 + 5) / 2;
902 l = (rr * 13 + 5) / 2;
903 write_mixer(s, mixreg[vidx-1], (rl << 4) | rr);
904#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
905 s->mix.vol[vidx-1] = ((unsigned int)r << 8) | l;
906#else
907 s->mix.vol[vidx-1] = val;
908#endif
909 return put_user(s->mix.vol[vidx-1], p);
910 }
911}
912
913/* --------------------------------------------------------------------- */
914
915static int solo1_open_mixdev(struct inode *inode, struct file *file)
916{
917 unsigned int minor = iminor(inode);
918 struct solo1_state *s = NULL;
919 struct pci_dev *pci_dev = NULL;
920
921 while ((pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
922 struct pci_driver *drvr;
923 drvr = pci_dev_driver (pci_dev);
924 if (drvr != &solo1_driver)
925 continue;
926 s = (struct solo1_state*)pci_get_drvdata(pci_dev);
927 if (!s)
928 continue;
929 if (s->dev_mixer == minor)
930 break;
931 }
932 if (!s)
933 return -ENODEV;
934 VALIDATE_STATE(s);
935 file->private_data = s;
936 return nonseekable_open(inode, file);
937}
938
939static int solo1_release_mixdev(struct inode *inode, struct file *file)
940{
941 struct solo1_state *s = (struct solo1_state *)file->private_data;
942
943 VALIDATE_STATE(s);
944 return 0;
945}
946
947static int solo1_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
948{
949 return mixer_ioctl((struct solo1_state *)file->private_data, cmd, arg);
950}
951
952static /*const*/ struct file_operations solo1_mixer_fops = {
953 .owner = THIS_MODULE,
954 .llseek = no_llseek,
955 .ioctl = solo1_ioctl_mixdev,
956 .open = solo1_open_mixdev,
957 .release = solo1_release_mixdev,
958};
959
960/* --------------------------------------------------------------------- */
961
962static int drain_dac(struct solo1_state *s, int nonblock)
963{
964 DECLARE_WAITQUEUE(wait, current);
965 unsigned long flags;
966 int count;
967 unsigned tmo;
968
969 if (s->dma_dac.mapped)
970 return 0;
971 add_wait_queue(&s->dma_dac.wait, &wait);
972 for (;;) {
973 set_current_state(TASK_INTERRUPTIBLE);
974 spin_lock_irqsave(&s->lock, flags);
975 count = s->dma_dac.count;
976 spin_unlock_irqrestore(&s->lock, flags);
977 if (count <= 0)
978 break;
979 if (signal_pending(current))
980 break;
981 if (nonblock) {
982 remove_wait_queue(&s->dma_dac.wait, &wait);
983 set_current_state(TASK_RUNNING);
984 return -EBUSY;
985 }
986 tmo = 3 * HZ * (count + s->dma_dac.fragsize) / 2 / s->rate;
987 if (s->fmt & (AFMT_S16_LE | AFMT_U16_LE))
988 tmo >>= 1;
989 if (s->channels > 1)
990 tmo >>= 1;
991 if (!schedule_timeout(tmo + 1))
992 printk(KERN_DEBUG "solo1: dma timed out??\n");
993 }
994 remove_wait_queue(&s->dma_dac.wait, &wait);
995 set_current_state(TASK_RUNNING);
996 if (signal_pending(current))
997 return -ERESTARTSYS;
998 return 0;
999}
1000
1001/* --------------------------------------------------------------------- */
1002
1003static ssize_t solo1_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1004{
1005 struct solo1_state *s = (struct solo1_state *)file->private_data;
1006 DECLARE_WAITQUEUE(wait, current);
1007 ssize_t ret;
1008 unsigned long flags;
1009 unsigned swptr;
1010 int cnt;
1011
1012 VALIDATE_STATE(s);
1013 if (s->dma_adc.mapped)
1014 return -ENXIO;
1015 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1016 return ret;
1017 if (!access_ok(VERIFY_WRITE, buffer, count))
1018 return -EFAULT;
1019 ret = 0;
1020 add_wait_queue(&s->dma_adc.wait, &wait);
1021 while (count > 0) {
1022 spin_lock_irqsave(&s->lock, flags);
1023 swptr = s->dma_adc.swptr;
1024 cnt = s->dma_adc.dmasize-swptr;
1025 if (s->dma_adc.count < cnt)
1026 cnt = s->dma_adc.count;
1027 if (cnt <= 0)
1028 __set_current_state(TASK_INTERRUPTIBLE);
1029 spin_unlock_irqrestore(&s->lock, flags);
1030 if (cnt > count)
1031 cnt = count;
1032#ifdef DEBUGREC
1033 printk(KERN_DEBUG "solo1_read: reg B8: 0x%02x DMAstat: 0x%02x DMAcnt: 0x%04x SBstat: 0x%02x cnt: %u\n",
1034 read_ctrl(s, 0xb8), inb(s->ddmabase+8), inw(s->ddmabase+4), inb(s->sbbase+0xc), cnt);
1035#endif
1036 if (cnt <= 0) {
1037 if (s->dma_adc.enabled)
1038 start_adc(s);
1039#ifdef DEBUGREC
1040 printk(KERN_DEBUG "solo1_read: regs: A1: 0x%02x A2: 0x%02x A4: 0x%02x A5: 0x%02x A8: 0x%02x\n"
1041 KERN_DEBUG "solo1_read: regs: B1: 0x%02x B2: 0x%02x B7: 0x%02x B8: 0x%02x B9: 0x%02x\n"
1042 KERN_DEBUG "solo1_read: DMA: addr: 0x%08x cnt: 0x%04x stat: 0x%02x mask: 0x%02x\n"
1043 KERN_DEBUG "solo1_read: SBstat: 0x%02x cnt: %u\n",
1044 read_ctrl(s, 0xa1), read_ctrl(s, 0xa2), read_ctrl(s, 0xa4), read_ctrl(s, 0xa5), read_ctrl(s, 0xa8),
1045 read_ctrl(s, 0xb1), read_ctrl(s, 0xb2), read_ctrl(s, 0xb7), read_ctrl(s, 0xb8), read_ctrl(s, 0xb9),
1046 inl(s->ddmabase), inw(s->ddmabase+4), inb(s->ddmabase+8), inb(s->ddmabase+15), inb(s->sbbase+0xc), cnt);
1047#endif
1048 if (inb(s->ddmabase+15) & 1)
1049 printk(KERN_ERR "solo1: cannot start recording, DDMA mask bit stuck at 1\n");
1050 if (file->f_flags & O_NONBLOCK) {
1051 if (!ret)
1052 ret = -EAGAIN;
1053 break;
1054 }
1055 schedule();
1056#ifdef DEBUGREC
1057 printk(KERN_DEBUG "solo1_read: regs: A1: 0x%02x A2: 0x%02x A4: 0x%02x A5: 0x%02x A8: 0x%02x\n"
1058 KERN_DEBUG "solo1_read: regs: B1: 0x%02x B2: 0x%02x B7: 0x%02x B8: 0x%02x B9: 0x%02x\n"
1059 KERN_DEBUG "solo1_read: DMA: addr: 0x%08x cnt: 0x%04x stat: 0x%02x mask: 0x%02x\n"
1060 KERN_DEBUG "solo1_read: SBstat: 0x%02x cnt: %u\n",
1061 read_ctrl(s, 0xa1), read_ctrl(s, 0xa2), read_ctrl(s, 0xa4), read_ctrl(s, 0xa5), read_ctrl(s, 0xa8),
1062 read_ctrl(s, 0xb1), read_ctrl(s, 0xb2), read_ctrl(s, 0xb7), read_ctrl(s, 0xb8), read_ctrl(s, 0xb9),
1063 inl(s->ddmabase), inw(s->ddmabase+4), inb(s->ddmabase+8), inb(s->ddmabase+15), inb(s->sbbase+0xc), cnt);
1064#endif
1065 if (signal_pending(current)) {
1066 if (!ret)
1067 ret = -ERESTARTSYS;
1068 break;
1069 }
1070 continue;
1071 }
1072 if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
1073 if (!ret)
1074 ret = -EFAULT;
1075 break;
1076 }
1077 swptr = (swptr + cnt) % s->dma_adc.dmasize;
1078 spin_lock_irqsave(&s->lock, flags);
1079 s->dma_adc.swptr = swptr;
1080 s->dma_adc.count -= cnt;
1081 spin_unlock_irqrestore(&s->lock, flags);
1082 count -= cnt;
1083 buffer += cnt;
1084 ret += cnt;
1085 if (s->dma_adc.enabled)
1086 start_adc(s);
1087#ifdef DEBUGREC
1088 printk(KERN_DEBUG "solo1_read: reg B8: 0x%02x DMAstat: 0x%02x DMAcnt: 0x%04x SBstat: 0x%02x\n",
1089 read_ctrl(s, 0xb8), inb(s->ddmabase+8), inw(s->ddmabase+4), inb(s->sbbase+0xc));
1090#endif
1091 }
1092 remove_wait_queue(&s->dma_adc.wait, &wait);
1093 set_current_state(TASK_RUNNING);
1094 return ret;
1095}
1096
1097static ssize_t solo1_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1098{
1099 struct solo1_state *s = (struct solo1_state *)file->private_data;
1100 DECLARE_WAITQUEUE(wait, current);
1101 ssize_t ret;
1102 unsigned long flags;
1103 unsigned swptr;
1104 int cnt;
1105
1106 VALIDATE_STATE(s);
1107 if (s->dma_dac.mapped)
1108 return -ENXIO;
1109 if (!s->dma_dac.ready && (ret = prog_dmabuf_dac(s)))
1110 return ret;
1111 if (!access_ok(VERIFY_READ, buffer, count))
1112 return -EFAULT;
1113#if 0
1114 printk(KERN_DEBUG "solo1_write: reg 70: 0x%02x 71: 0x%02x 72: 0x%02x 74: 0x%02x 76: 0x%02x 78: 0x%02x 7A: 0x%02x\n"
1115 KERN_DEBUG "solo1_write: DMA: addr: 0x%08x cnt: 0x%04x stat: 0x%02x SBstat: 0x%02x\n",
1116 read_mixer(s, 0x70), read_mixer(s, 0x71), read_mixer(s, 0x72), read_mixer(s, 0x74), read_mixer(s, 0x76),
1117 read_mixer(s, 0x78), read_mixer(s, 0x7a), inl(s->iobase), inw(s->iobase+4), inb(s->iobase+6), inb(s->sbbase+0xc));
1118 printk(KERN_DEBUG "solo1_write: reg 78: 0x%02x reg 7A: 0x%02x DMAcnt: 0x%04x DMAstat: 0x%02x SBstat: 0x%02x\n",
1119 read_mixer(s, 0x78), read_mixer(s, 0x7a), inw(s->iobase+4), inb(s->iobase+6), inb(s->sbbase+0xc));
1120#endif
1121 ret = 0;
1122 add_wait_queue(&s->dma_dac.wait, &wait);
1123 while (count > 0) {
1124 spin_lock_irqsave(&s->lock, flags);
1125 if (s->dma_dac.count < 0) {
1126 s->dma_dac.count = 0;
1127 s->dma_dac.swptr = s->dma_dac.hwptr;
1128 }
1129 swptr = s->dma_dac.swptr;
1130 cnt = s->dma_dac.dmasize-swptr;
1131 if (s->dma_dac.count + cnt > s->dma_dac.dmasize)
1132 cnt = s->dma_dac.dmasize - s->dma_dac.count;
1133 if (cnt <= 0)
1134 __set_current_state(TASK_INTERRUPTIBLE);
1135 spin_unlock_irqrestore(&s->lock, flags);
1136 if (cnt > count)
1137 cnt = count;
1138 if (cnt <= 0) {
1139 if (s->dma_dac.enabled)
1140 start_dac(s);
1141 if (file->f_flags & O_NONBLOCK) {
1142 if (!ret)
1143 ret = -EAGAIN;
1144 break;
1145 }
1146 schedule();
1147 if (signal_pending(current)) {
1148 if (!ret)
1149 ret = -ERESTARTSYS;
1150 break;
1151 }
1152 continue;
1153 }
1154 if (copy_from_user(s->dma_dac.rawbuf + swptr, buffer, cnt)) {
1155 if (!ret)
1156 ret = -EFAULT;
1157 break;
1158 }
1159 swptr = (swptr + cnt) % s->dma_dac.dmasize;
1160 spin_lock_irqsave(&s->lock, flags);
1161 s->dma_dac.swptr = swptr;
1162 s->dma_dac.count += cnt;
1163 s->dma_dac.endcleared = 0;
1164 spin_unlock_irqrestore(&s->lock, flags);
1165 count -= cnt;
1166 buffer += cnt;
1167 ret += cnt;
1168 if (s->dma_dac.enabled)
1169 start_dac(s);
1170 }
1171 remove_wait_queue(&s->dma_dac.wait, &wait);
1172 set_current_state(TASK_RUNNING);
1173 return ret;
1174}
1175
1176/* No kernel lock - we have our own spinlock */
1177static unsigned int solo1_poll(struct file *file, struct poll_table_struct *wait)
1178{
1179 struct solo1_state *s = (struct solo1_state *)file->private_data;
1180 unsigned long flags;
1181 unsigned int mask = 0;
1182
1183 VALIDATE_STATE(s);
1184 if (file->f_mode & FMODE_WRITE) {
1185 if (!s->dma_dac.ready && prog_dmabuf_dac(s))
1186 return 0;
1187 poll_wait(file, &s->dma_dac.wait, wait);
1188 }
1189 if (file->f_mode & FMODE_READ) {
1190 if (!s->dma_adc.ready && prog_dmabuf_adc(s))
1191 return 0;
1192 poll_wait(file, &s->dma_adc.wait, wait);
1193 }
1194 spin_lock_irqsave(&s->lock, flags);
1195 solo1_update_ptr(s);
1196 if (file->f_mode & FMODE_READ) {
1197 if (s->dma_adc.mapped) {
1198 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1199 mask |= POLLIN | POLLRDNORM;
1200 } else {
1201 if (s->dma_adc.count > 0)
1202 mask |= POLLIN | POLLRDNORM;
1203 }
1204 }
1205 if (file->f_mode & FMODE_WRITE) {
1206 if (s->dma_dac.mapped) {
1207 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
1208 mask |= POLLOUT | POLLWRNORM;
1209 } else {
1210 if ((signed)s->dma_dac.dmasize > s->dma_dac.count)
1211 mask |= POLLOUT | POLLWRNORM;
1212 }
1213 }
1214 spin_unlock_irqrestore(&s->lock, flags);
1215 return mask;
1216}
1217
1218
1219static int solo1_mmap(struct file *file, struct vm_area_struct *vma)
1220{
1221 struct solo1_state *s = (struct solo1_state *)file->private_data;
1222 struct dmabuf *db;
1223 int ret = -EINVAL;
1224 unsigned long size;
1225
1226 VALIDATE_STATE(s);
1227 lock_kernel();
1228 if (vma->vm_flags & VM_WRITE) {
1229 if ((ret = prog_dmabuf_dac(s)) != 0)
1230 goto out;
1231 db = &s->dma_dac;
1232 } else if (vma->vm_flags & VM_READ) {
1233 if ((ret = prog_dmabuf_adc(s)) != 0)
1234 goto out;
1235 db = &s->dma_adc;
1236 } else
1237 goto out;
1238 ret = -EINVAL;
1239 if (vma->vm_pgoff != 0)
1240 goto out;
1241 size = vma->vm_end - vma->vm_start;
1242 if (size > (PAGE_SIZE << db->buforder))
1243 goto out;
1244 ret = -EAGAIN;
1245 if (remap_pfn_range(vma, vma->vm_start,
1246 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
1247 size, vma->vm_page_prot))
1248 goto out;
1249 db->mapped = 1;
1250 ret = 0;
1251out:
1252 unlock_kernel();
1253 return ret;
1254}
1255
1256static int solo1_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1257{
1258 struct solo1_state *s = (struct solo1_state *)file->private_data;
1259 unsigned long flags;
1260 audio_buf_info abinfo;
1261 count_info cinfo;
1262 int val, mapped, ret, count;
1263 int div1, div2;
1264 unsigned rate1, rate2;
1265 void __user *argp = (void __user *)arg;
1266 int __user *p = argp;
1267
1268 VALIDATE_STATE(s);
1269 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1270 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1271 switch (cmd) {
1272 case OSS_GETVERSION:
1273 return put_user(SOUND_VERSION, p);
1274
1275 case SNDCTL_DSP_SYNC:
1276 if (file->f_mode & FMODE_WRITE)
1277 return drain_dac(s, 0/*file->f_flags & O_NONBLOCK*/);
1278 return 0;
1279
1280 case SNDCTL_DSP_SETDUPLEX:
1281 return 0;
1282
1283 case SNDCTL_DSP_GETCAPS:
1284 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
1285
1286 case SNDCTL_DSP_RESET:
1287 if (file->f_mode & FMODE_WRITE) {
1288 stop_dac(s);
1289 synchronize_irq(s->irq);
1290 s->dma_dac.swptr = s->dma_dac.hwptr = s->dma_dac.count = s->dma_dac.total_bytes = 0;
1291 }
1292 if (file->f_mode & FMODE_READ) {
1293 stop_adc(s);
1294 synchronize_irq(s->irq);
1295 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
1296 }
1297 prog_codec(s);
1298 return 0;
1299
1300 case SNDCTL_DSP_SPEED:
1301 if (get_user(val, p))
1302 return -EFAULT;
1303 if (val >= 0) {
1304 stop_adc(s);
1305 stop_dac(s);
1306 s->dma_adc.ready = s->dma_dac.ready = 0;
1307 /* program sampling rates */
1308 if (val > 48000)
1309 val = 48000;
1310 if (val < 6300)
1311 val = 6300;
1312 div1 = (768000 + val / 2) / val;
1313 rate1 = (768000 + div1 / 2) / div1;
1314 div1 = -div1;
1315 div2 = (793800 + val / 2) / val;
1316 rate2 = (793800 + div2 / 2) / div2;
1317 div2 = (-div2) & 0x7f;
1318 if (abs(val - rate2) < abs(val - rate1)) {
1319 rate1 = rate2;
1320 div1 = div2;
1321 }
1322 s->rate = rate1;
1323 s->clkdiv = div1;
1324 prog_codec(s);
1325 }
1326 return put_user(s->rate, p);
1327
1328 case SNDCTL_DSP_STEREO:
1329 if (get_user(val, p))
1330 return -EFAULT;
1331 stop_adc(s);
1332 stop_dac(s);
1333 s->dma_adc.ready = s->dma_dac.ready = 0;
1334 /* program channels */
1335 s->channels = val ? 2 : 1;
1336 prog_codec(s);
1337 return 0;
1338
1339 case SNDCTL_DSP_CHANNELS:
1340 if (get_user(val, p))
1341 return -EFAULT;
1342 if (val != 0) {
1343 stop_adc(s);
1344 stop_dac(s);
1345 s->dma_adc.ready = s->dma_dac.ready = 0;
1346 /* program channels */
1347 s->channels = (val >= 2) ? 2 : 1;
1348 prog_codec(s);
1349 }
1350 return put_user(s->channels, p);
1351
1352 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1353 return put_user(AFMT_S16_LE|AFMT_U16_LE|AFMT_S8|AFMT_U8, p);
1354
1355 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1356 if (get_user(val, p))
1357 return -EFAULT;
1358 if (val != AFMT_QUERY) {
1359 stop_adc(s);
1360 stop_dac(s);
1361 s->dma_adc.ready = s->dma_dac.ready = 0;
1362 /* program format */
1363 if (val != AFMT_S16_LE && val != AFMT_U16_LE &&
1364 val != AFMT_S8 && val != AFMT_U8)
1365 val = AFMT_U8;
1366 s->fmt = val;
1367 prog_codec(s);
1368 }
1369 return put_user(s->fmt, p);
1370
1371 case SNDCTL_DSP_POST:
1372 return 0;
1373
1374 case SNDCTL_DSP_GETTRIGGER:
1375 val = 0;
1376 if (file->f_mode & s->ena & FMODE_READ)
1377 val |= PCM_ENABLE_INPUT;
1378 if (file->f_mode & s->ena & FMODE_WRITE)
1379 val |= PCM_ENABLE_OUTPUT;
1380 return put_user(val, p);
1381
1382 case SNDCTL_DSP_SETTRIGGER:
1383 if (get_user(val, p))
1384 return -EFAULT;
1385 if (file->f_mode & FMODE_READ) {
1386 if (val & PCM_ENABLE_INPUT) {
1387 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1388 return ret;
1389 s->dma_dac.enabled = 1;
1390 start_adc(s);
1391 if (inb(s->ddmabase+15) & 1)
1392 printk(KERN_ERR "solo1: cannot start recording, DDMA mask bit stuck at 1\n");
1393 } else {
1394 s->dma_dac.enabled = 0;
1395 stop_adc(s);
1396 }
1397 }
1398 if (file->f_mode & FMODE_WRITE) {
1399 if (val & PCM_ENABLE_OUTPUT) {
1400 if (!s->dma_dac.ready && (ret = prog_dmabuf_dac(s)))
1401 return ret;
1402 s->dma_dac.enabled = 1;
1403 start_dac(s);
1404 } else {
1405 s->dma_dac.enabled = 0;
1406 stop_dac(s);
1407 }
1408 }
1409 return 0;
1410
1411 case SNDCTL_DSP_GETOSPACE:
1412 if (!(file->f_mode & FMODE_WRITE))
1413 return -EINVAL;
1414 if (!s->dma_dac.ready && (val = prog_dmabuf_dac(s)) != 0)
1415 return val;
1416 spin_lock_irqsave(&s->lock, flags);
1417 solo1_update_ptr(s);
1418 abinfo.fragsize = s->dma_dac.fragsize;
1419 count = s->dma_dac.count;
1420 if (count < 0)
1421 count = 0;
1422 abinfo.bytes = s->dma_dac.dmasize - count;
1423 abinfo.fragstotal = s->dma_dac.numfrag;
1424 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
1425 spin_unlock_irqrestore(&s->lock, flags);
1426 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1427
1428 case SNDCTL_DSP_GETISPACE:
1429 if (!(file->f_mode & FMODE_READ))
1430 return -EINVAL;
1431 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0)
1432 return val;
1433 spin_lock_irqsave(&s->lock, flags);
1434 solo1_update_ptr(s);
1435 abinfo.fragsize = s->dma_adc.fragsize;
1436 abinfo.bytes = s->dma_adc.count;
1437 abinfo.fragstotal = s->dma_adc.numfrag;
1438 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1439 spin_unlock_irqrestore(&s->lock, flags);
1440 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1441
1442 case SNDCTL_DSP_NONBLOCK:
1443 file->f_flags |= O_NONBLOCK;
1444 return 0;
1445
1446 case SNDCTL_DSP_GETODELAY:
1447 if (!(file->f_mode & FMODE_WRITE))
1448 return -EINVAL;
1449 if (!s->dma_dac.ready && (val = prog_dmabuf_dac(s)) != 0)
1450 return val;
1451 spin_lock_irqsave(&s->lock, flags);
1452 solo1_update_ptr(s);
1453 count = s->dma_dac.count;
1454 spin_unlock_irqrestore(&s->lock, flags);
1455 if (count < 0)
1456 count = 0;
1457 return put_user(count, p);
1458
1459 case SNDCTL_DSP_GETIPTR:
1460 if (!(file->f_mode & FMODE_READ))
1461 return -EINVAL;
1462 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)) != 0)
1463 return val;
1464 spin_lock_irqsave(&s->lock, flags);
1465 solo1_update_ptr(s);
1466 cinfo.bytes = s->dma_adc.total_bytes;
1467 cinfo.blocks = s->dma_adc.count >> s->dma_adc.fragshift;
1468 cinfo.ptr = s->dma_adc.hwptr;
1469 if (s->dma_adc.mapped)
1470 s->dma_adc.count &= s->dma_adc.fragsize-1;
1471 spin_unlock_irqrestore(&s->lock, flags);
1472 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1473 return -EFAULT;
1474 return 0;
1475
1476 case SNDCTL_DSP_GETOPTR:
1477 if (!(file->f_mode & FMODE_WRITE))
1478 return -EINVAL;
1479 if (!s->dma_dac.ready && (val = prog_dmabuf_dac(s)) != 0)
1480 return val;
1481 spin_lock_irqsave(&s->lock, flags);
1482 solo1_update_ptr(s);
1483 cinfo.bytes = s->dma_dac.total_bytes;
1484 count = s->dma_dac.count;
1485 if (count < 0)
1486 count = 0;
1487 cinfo.blocks = count >> s->dma_dac.fragshift;
1488 cinfo.ptr = s->dma_dac.hwptr;
1489 if (s->dma_dac.mapped)
1490 s->dma_dac.count &= s->dma_dac.fragsize-1;
1491 spin_unlock_irqrestore(&s->lock, flags);
1492#if 0
1493 printk(KERN_DEBUG "esssolo1: GETOPTR: bytes %u blocks %u ptr %u, buforder %u numfrag %u fragshift %u\n"
1494 KERN_DEBUG "esssolo1: swptr %u count %u fragsize %u dmasize %u fragsamples %u\n",
1495 cinfo.bytes, cinfo.blocks, cinfo.ptr, s->dma_dac.buforder, s->dma_dac.numfrag, s->dma_dac.fragshift,
1496 s->dma_dac.swptr, s->dma_dac.count, s->dma_dac.fragsize, s->dma_dac.dmasize, s->dma_dac.fragsamples);
1497#endif
1498 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1499 return -EFAULT;
1500 return 0;
1501
1502 case SNDCTL_DSP_GETBLKSIZE:
1503 if (file->f_mode & FMODE_WRITE) {
1504 if ((val = prog_dmabuf_dac(s)))
1505 return val;
1506 return put_user(s->dma_dac.fragsize, p);
1507 }
1508 if ((val = prog_dmabuf_adc(s)))
1509 return val;
1510 return put_user(s->dma_adc.fragsize, p);
1511
1512 case SNDCTL_DSP_SETFRAGMENT:
1513 if (get_user(val, p))
1514 return -EFAULT;
1515 if (file->f_mode & FMODE_READ) {
1516 s->dma_adc.ossfragshift = val & 0xffff;
1517 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1518 if (s->dma_adc.ossfragshift < 4)
1519 s->dma_adc.ossfragshift = 4;
1520 if (s->dma_adc.ossfragshift > 15)
1521 s->dma_adc.ossfragshift = 15;
1522 if (s->dma_adc.ossmaxfrags < 4)
1523 s->dma_adc.ossmaxfrags = 4;
1524 }
1525 if (file->f_mode & FMODE_WRITE) {
1526 s->dma_dac.ossfragshift = val & 0xffff;
1527 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
1528 if (s->dma_dac.ossfragshift < 4)
1529 s->dma_dac.ossfragshift = 4;
1530 if (s->dma_dac.ossfragshift > 15)
1531 s->dma_dac.ossfragshift = 15;
1532 if (s->dma_dac.ossmaxfrags < 4)
1533 s->dma_dac.ossmaxfrags = 4;
1534 }
1535 return 0;
1536
1537 case SNDCTL_DSP_SUBDIVIDE:
1538 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1539 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
1540 return -EINVAL;
1541 if (get_user(val, p))
1542 return -EFAULT;
1543 if (val != 1 && val != 2 && val != 4)
1544 return -EINVAL;
1545 if (file->f_mode & FMODE_READ)
1546 s->dma_adc.subdivision = val;
1547 if (file->f_mode & FMODE_WRITE)
1548 s->dma_dac.subdivision = val;
1549 return 0;
1550
1551 case SOUND_PCM_READ_RATE:
1552 return put_user(s->rate, p);
1553
1554 case SOUND_PCM_READ_CHANNELS:
1555 return put_user(s->channels, p);
1556
1557 case SOUND_PCM_READ_BITS:
1558 return put_user((s->fmt & (AFMT_S8|AFMT_U8)) ? 8 : 16, p);
1559
1560 case SOUND_PCM_WRITE_FILTER:
1561 case SNDCTL_DSP_SETSYNCRO:
1562 case SOUND_PCM_READ_FILTER:
1563 return -EINVAL;
1564
1565 }
1566 return mixer_ioctl(s, cmd, arg);
1567}
1568
1569static int solo1_release(struct inode *inode, struct file *file)
1570{
1571 struct solo1_state *s = (struct solo1_state *)file->private_data;
1572
1573 VALIDATE_STATE(s);
1574 lock_kernel();
1575 if (file->f_mode & FMODE_WRITE)
1576 drain_dac(s, file->f_flags & O_NONBLOCK);
1577 down(&s->open_sem);
1578 if (file->f_mode & FMODE_WRITE) {
1579 stop_dac(s);
1580 outb(0, s->iobase+6); /* disable DMA */
1581 dealloc_dmabuf(s, &s->dma_dac);
1582 }
1583 if (file->f_mode & FMODE_READ) {
1584 stop_adc(s);
1585 outb(1, s->ddmabase+0xf); /* mask DMA channel */
1586 outb(0, s->ddmabase+0xd); /* DMA master clear */
1587 dealloc_dmabuf(s, &s->dma_adc);
1588 }
1589 s->open_mode &= ~(FMODE_READ | FMODE_WRITE);
1590 wake_up(&s->open_wait);
1591 up(&s->open_sem);
1592 unlock_kernel();
1593 return 0;
1594}
1595
1596static int solo1_open(struct inode *inode, struct file *file)
1597{
1598 unsigned int minor = iminor(inode);
1599 DECLARE_WAITQUEUE(wait, current);
1600 struct solo1_state *s = NULL;
1601 struct pci_dev *pci_dev = NULL;
1602
1603 while ((pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
1604 struct pci_driver *drvr;
1605
1606 drvr = pci_dev_driver(pci_dev);
1607 if (drvr != &solo1_driver)
1608 continue;
1609 s = (struct solo1_state*)pci_get_drvdata(pci_dev);
1610 if (!s)
1611 continue;
1612 if (!((s->dev_audio ^ minor) & ~0xf))
1613 break;
1614 }
1615 if (!s)
1616 return -ENODEV;
1617 VALIDATE_STATE(s);
1618 file->private_data = s;
1619 /* wait for device to become free */
1620 down(&s->open_sem);
1621 while (s->open_mode & (FMODE_READ | FMODE_WRITE)) {
1622 if (file->f_flags & O_NONBLOCK) {
1623 up(&s->open_sem);
1624 return -EBUSY;
1625 }
1626 add_wait_queue(&s->open_wait, &wait);
1627 __set_current_state(TASK_INTERRUPTIBLE);
1628 up(&s->open_sem);
1629 schedule();
1630 remove_wait_queue(&s->open_wait, &wait);
1631 set_current_state(TASK_RUNNING);
1632 if (signal_pending(current))
1633 return -ERESTARTSYS;
1634 down(&s->open_sem);
1635 }
1636 s->fmt = AFMT_U8;
1637 s->channels = 1;
1638 s->rate = 8000;
1639 s->clkdiv = 96 | 0x80;
1640 s->ena = 0;
1641 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
1642 s->dma_adc.enabled = 1;
1643 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = s->dma_dac.subdivision = 0;
1644 s->dma_dac.enabled = 1;
1645 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1646 up(&s->open_sem);
1647 prog_codec(s);
1648 return nonseekable_open(inode, file);
1649}
1650
1651static /*const*/ struct file_operations solo1_audio_fops = {
1652 .owner = THIS_MODULE,
1653 .llseek = no_llseek,
1654 .read = solo1_read,
1655 .write = solo1_write,
1656 .poll = solo1_poll,
1657 .ioctl = solo1_ioctl,
1658 .mmap = solo1_mmap,
1659 .open = solo1_open,
1660 .release = solo1_release,
1661};
1662
1663/* --------------------------------------------------------------------- */
1664
1665/* hold spinlock for the following! */
1666static void solo1_handle_midi(struct solo1_state *s)
1667{
1668 unsigned char ch;
1669 int wake;
1670
1671 if (!(s->mpubase))
1672 return;
1673 wake = 0;
1674 while (!(inb(s->mpubase+1) & 0x80)) {
1675 ch = inb(s->mpubase);
1676 if (s->midi.icnt < MIDIINBUF) {
1677 s->midi.ibuf[s->midi.iwr] = ch;
1678 s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF;
1679 s->midi.icnt++;
1680 }
1681 wake = 1;
1682 }
1683 if (wake)
1684 wake_up(&s->midi.iwait);
1685 wake = 0;
1686 while (!(inb(s->mpubase+1) & 0x40) && s->midi.ocnt > 0) {
1687 outb(s->midi.obuf[s->midi.ord], s->mpubase);
1688 s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF;
1689 s->midi.ocnt--;
1690 if (s->midi.ocnt < MIDIOUTBUF-16)
1691 wake = 1;
1692 }
1693 if (wake)
1694 wake_up(&s->midi.owait);
1695}
1696
1697static irqreturn_t solo1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1698{
1699 struct solo1_state *s = (struct solo1_state *)dev_id;
1700 unsigned int intsrc;
1701
1702 /* fastpath out, to ease interrupt sharing */
1703 intsrc = inb(s->iobase+7); /* get interrupt source(s) */
1704 if (!intsrc)
1705 return IRQ_NONE;
1706 (void)inb(s->sbbase+0xe); /* clear interrupt */
1707 spin_lock(&s->lock);
1708 /* clear audio interrupts first */
1709 if (intsrc & 0x20)
1710 write_mixer(s, 0x7a, read_mixer(s, 0x7a) & 0x7f);
1711 solo1_update_ptr(s);
1712 solo1_handle_midi(s);
1713 spin_unlock(&s->lock);
1714 return IRQ_HANDLED;
1715}
1716
1717static void solo1_midi_timer(unsigned long data)
1718{
1719 struct solo1_state *s = (struct solo1_state *)data;
1720 unsigned long flags;
1721
1722 spin_lock_irqsave(&s->lock, flags);
1723 solo1_handle_midi(s);
1724 spin_unlock_irqrestore(&s->lock, flags);
1725 s->midi.timer.expires = jiffies+1;
1726 add_timer(&s->midi.timer);
1727}
1728
1729/* --------------------------------------------------------------------- */
1730
1731static ssize_t solo1_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1732{
1733 struct solo1_state *s = (struct solo1_state *)file->private_data;
1734 DECLARE_WAITQUEUE(wait, current);
1735 ssize_t ret;
1736 unsigned long flags;
1737 unsigned ptr;
1738 int cnt;
1739
1740 VALIDATE_STATE(s);
1741 if (!access_ok(VERIFY_WRITE, buffer, count))
1742 return -EFAULT;
1743 if (count == 0)
1744 return 0;
1745 ret = 0;
1746 add_wait_queue(&s->midi.iwait, &wait);
1747 while (count > 0) {
1748 spin_lock_irqsave(&s->lock, flags);
1749 ptr = s->midi.ird;
1750 cnt = MIDIINBUF - ptr;
1751 if (s->midi.icnt < cnt)
1752 cnt = s->midi.icnt;
1753 if (cnt <= 0)
1754 __set_current_state(TASK_INTERRUPTIBLE);
1755 spin_unlock_irqrestore(&s->lock, flags);
1756 if (cnt > count)
1757 cnt = count;
1758 if (cnt <= 0) {
1759 if (file->f_flags & O_NONBLOCK) {
1760 if (!ret)
1761 ret = -EAGAIN;
1762 break;
1763 }
1764 schedule();
1765 if (signal_pending(current)) {
1766 if (!ret)
1767 ret = -ERESTARTSYS;
1768 break;
1769 }
1770 continue;
1771 }
1772 if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt)) {
1773 if (!ret)
1774 ret = -EFAULT;
1775 break;
1776 }
1777 ptr = (ptr + cnt) % MIDIINBUF;
1778 spin_lock_irqsave(&s->lock, flags);
1779 s->midi.ird = ptr;
1780 s->midi.icnt -= cnt;
1781 spin_unlock_irqrestore(&s->lock, flags);
1782 count -= cnt;
1783 buffer += cnt;
1784 ret += cnt;
1785 break;
1786 }
1787 __set_current_state(TASK_RUNNING);
1788 remove_wait_queue(&s->midi.iwait, &wait);
1789 return ret;
1790}
1791
1792static ssize_t solo1_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1793{
1794 struct solo1_state *s = (struct solo1_state *)file->private_data;
1795 DECLARE_WAITQUEUE(wait, current);
1796 ssize_t ret;
1797 unsigned long flags;
1798 unsigned ptr;
1799 int cnt;
1800
1801 VALIDATE_STATE(s);
1802 if (!access_ok(VERIFY_READ, buffer, count))
1803 return -EFAULT;
1804 if (count == 0)
1805 return 0;
1806 ret = 0;
1807 add_wait_queue(&s->midi.owait, &wait);
1808 while (count > 0) {
1809 spin_lock_irqsave(&s->lock, flags);
1810 ptr = s->midi.owr;
1811 cnt = MIDIOUTBUF - ptr;
1812 if (s->midi.ocnt + cnt > MIDIOUTBUF)
1813 cnt = MIDIOUTBUF - s->midi.ocnt;
1814 if (cnt <= 0) {
1815 __set_current_state(TASK_INTERRUPTIBLE);
1816 solo1_handle_midi(s);
1817 }
1818 spin_unlock_irqrestore(&s->lock, flags);
1819 if (cnt > count)
1820 cnt = count;
1821 if (cnt <= 0) {
1822 if (file->f_flags & O_NONBLOCK) {
1823 if (!ret)
1824 ret = -EAGAIN;
1825 break;
1826 }
1827 schedule();
1828 if (signal_pending(current)) {
1829 if (!ret)
1830 ret = -ERESTARTSYS;
1831 break;
1832 }
1833 continue;
1834 }
1835 if (copy_from_user(s->midi.obuf + ptr, buffer, cnt)) {
1836 if (!ret)
1837 ret = -EFAULT;
1838 break;
1839 }
1840 ptr = (ptr + cnt) % MIDIOUTBUF;
1841 spin_lock_irqsave(&s->lock, flags);
1842 s->midi.owr = ptr;
1843 s->midi.ocnt += cnt;
1844 spin_unlock_irqrestore(&s->lock, flags);
1845 count -= cnt;
1846 buffer += cnt;
1847 ret += cnt;
1848 spin_lock_irqsave(&s->lock, flags);
1849 solo1_handle_midi(s);
1850 spin_unlock_irqrestore(&s->lock, flags);
1851 }
1852 __set_current_state(TASK_RUNNING);
1853 remove_wait_queue(&s->midi.owait, &wait);
1854 return ret;
1855}
1856
1857/* No kernel lock - we have our own spinlock */
1858static unsigned int solo1_midi_poll(struct file *file, struct poll_table_struct *wait)
1859{
1860 struct solo1_state *s = (struct solo1_state *)file->private_data;
1861 unsigned long flags;
1862 unsigned int mask = 0;
1863
1864 VALIDATE_STATE(s);
1865 if (file->f_flags & FMODE_WRITE)
1866 poll_wait(file, &s->midi.owait, wait);
1867 if (file->f_flags & FMODE_READ)
1868 poll_wait(file, &s->midi.iwait, wait);
1869 spin_lock_irqsave(&s->lock, flags);
1870 if (file->f_flags & FMODE_READ) {
1871 if (s->midi.icnt > 0)
1872 mask |= POLLIN | POLLRDNORM;
1873 }
1874 if (file->f_flags & FMODE_WRITE) {
1875 if (s->midi.ocnt < MIDIOUTBUF)
1876 mask |= POLLOUT | POLLWRNORM;
1877 }
1878 spin_unlock_irqrestore(&s->lock, flags);
1879 return mask;
1880}
1881
1882static int solo1_midi_open(struct inode *inode, struct file *file)
1883{
1884 unsigned int minor = iminor(inode);
1885 DECLARE_WAITQUEUE(wait, current);
1886 unsigned long flags;
1887 struct solo1_state *s = NULL;
1888 struct pci_dev *pci_dev = NULL;
1889
1890 while ((pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
1891 struct pci_driver *drvr;
1892
1893 drvr = pci_dev_driver(pci_dev);
1894 if (drvr != &solo1_driver)
1895 continue;
1896 s = (struct solo1_state*)pci_get_drvdata(pci_dev);
1897 if (!s)
1898 continue;
1899 if (s->dev_midi == minor)
1900 break;
1901 }
1902 if (!s)
1903 return -ENODEV;
1904 VALIDATE_STATE(s);
1905 file->private_data = s;
1906 /* wait for device to become free */
1907 down(&s->open_sem);
1908 while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
1909 if (file->f_flags & O_NONBLOCK) {
1910 up(&s->open_sem);
1911 return -EBUSY;
1912 }
1913 add_wait_queue(&s->open_wait, &wait);
1914 __set_current_state(TASK_INTERRUPTIBLE);
1915 up(&s->open_sem);
1916 schedule();
1917 remove_wait_queue(&s->open_wait, &wait);
1918 set_current_state(TASK_RUNNING);
1919 if (signal_pending(current))
1920 return -ERESTARTSYS;
1921 down(&s->open_sem);
1922 }
1923 spin_lock_irqsave(&s->lock, flags);
1924 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
1925 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
1926 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
1927 outb(0xff, s->mpubase+1); /* reset command */
1928 outb(0x3f, s->mpubase+1); /* uart command */
1929 if (!(inb(s->mpubase+1) & 0x80))
1930 inb(s->mpubase);
1931 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
1932 outb(0xb0, s->iobase + 7); /* enable A1, A2, MPU irq's */
1933 init_timer(&s->midi.timer);
1934 s->midi.timer.expires = jiffies+1;
1935 s->midi.timer.data = (unsigned long)s;
1936 s->midi.timer.function = solo1_midi_timer;
1937 add_timer(&s->midi.timer);
1938 }
1939 if (file->f_mode & FMODE_READ) {
1940 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
1941 }
1942 if (file->f_mode & FMODE_WRITE) {
1943 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
1944 }
1945 spin_unlock_irqrestore(&s->lock, flags);
1946 s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
1947 up(&s->open_sem);
1948 return nonseekable_open(inode, file);
1949}
1950
1951static int solo1_midi_release(struct inode *inode, struct file *file)
1952{
1953 struct solo1_state *s = (struct solo1_state *)file->private_data;
1954 DECLARE_WAITQUEUE(wait, current);
1955 unsigned long flags;
1956 unsigned count, tmo;
1957
1958 VALIDATE_STATE(s);
1959
1960 lock_kernel();
1961 if (file->f_mode & FMODE_WRITE) {
1962 add_wait_queue(&s->midi.owait, &wait);
1963 for (;;) {
1964 __set_current_state(TASK_INTERRUPTIBLE);
1965 spin_lock_irqsave(&s->lock, flags);
1966 count = s->midi.ocnt;
1967 spin_unlock_irqrestore(&s->lock, flags);
1968 if (count <= 0)
1969 break;
1970 if (signal_pending(current))
1971 break;
1972 if (file->f_flags & O_NONBLOCK)
1973 break;
1974 tmo = (count * HZ) / 3100;
1975 if (!schedule_timeout(tmo ? : 1) && tmo)
1976 printk(KERN_DEBUG "solo1: midi timed out??\n");
1977 }
1978 remove_wait_queue(&s->midi.owait, &wait);
1979 set_current_state(TASK_RUNNING);
1980 }
1981 down(&s->open_sem);
1982 s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
1983 spin_lock_irqsave(&s->lock, flags);
1984 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
1985 outb(0x30, s->iobase + 7); /* enable A1, A2 irq's */
1986 del_timer(&s->midi.timer);
1987 }
1988 spin_unlock_irqrestore(&s->lock, flags);
1989 wake_up(&s->open_wait);
1990 up(&s->open_sem);
1991 unlock_kernel();
1992 return 0;
1993}
1994
1995static /*const*/ struct file_operations solo1_midi_fops = {
1996 .owner = THIS_MODULE,
1997 .llseek = no_llseek,
1998 .read = solo1_midi_read,
1999 .write = solo1_midi_write,
2000 .poll = solo1_midi_poll,
2001 .open = solo1_midi_open,
2002 .release = solo1_midi_release,
2003};
2004
2005/* --------------------------------------------------------------------- */
2006
2007static int solo1_dmfm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2008{
2009 static const unsigned char op_offset[18] = {
2010 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
2011 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
2012 0x10, 0x11, 0x12, 0x13, 0x14, 0x15
2013 };
2014 struct solo1_state *s = (struct solo1_state *)file->private_data;
2015 struct dm_fm_voice v;
2016 struct dm_fm_note n;
2017 struct dm_fm_params p;
2018 unsigned int io;
2019 unsigned int regb;
2020
2021 switch (cmd) {
2022 case FM_IOCTL_RESET:
2023 for (regb = 0xb0; regb < 0xb9; regb++) {
2024 outb(regb, s->sbbase);
2025 outb(0, s->sbbase+1);
2026 outb(regb, s->sbbase+2);
2027 outb(0, s->sbbase+3);
2028 }
2029 return 0;
2030
2031 case FM_IOCTL_PLAY_NOTE:
2032 if (copy_from_user(&n, (void __user *)arg, sizeof(n)))
2033 return -EFAULT;
2034 if (n.voice >= 18)
2035 return -EINVAL;
2036 if (n.voice >= 9) {
2037 regb = n.voice - 9;
2038 io = s->sbbase+2;
2039 } else {
2040 regb = n.voice;
2041 io = s->sbbase;
2042 }
2043 outb(0xa0 + regb, io);
2044 outb(n.fnum & 0xff, io+1);
2045 outb(0xb0 + regb, io);
2046 outb(((n.fnum >> 8) & 3) | ((n.octave & 7) << 2) | ((n.key_on & 1) << 5), io+1);
2047 return 0;
2048
2049 case FM_IOCTL_SET_VOICE:
2050 if (copy_from_user(&v, (void __user *)arg, sizeof(v)))
2051 return -EFAULT;
2052 if (v.voice >= 18)
2053 return -EINVAL;
2054 regb = op_offset[v.voice];
2055 io = s->sbbase + ((v.op & 1) << 1);
2056 outb(0x20 + regb, io);
2057 outb(((v.am & 1) << 7) | ((v.vibrato & 1) << 6) | ((v.do_sustain & 1) << 5) |
2058 ((v.kbd_scale & 1) << 4) | (v.harmonic & 0xf), io+1);
2059 outb(0x40 + regb, io);
2060 outb(((v.scale_level & 0x3) << 6) | (v.volume & 0x3f), io+1);
2061 outb(0x60 + regb, io);
2062 outb(((v.attack & 0xf) << 4) | (v.decay & 0xf), io+1);
2063 outb(0x80 + regb, io);
2064 outb(((v.sustain & 0xf) << 4) | (v.release & 0xf), io+1);
2065 outb(0xe0 + regb, io);
2066 outb(v.waveform & 0x7, io+1);
2067 if (n.voice >= 9) {
2068 regb = n.voice - 9;
2069 io = s->sbbase+2;
2070 } else {
2071 regb = n.voice;
2072 io = s->sbbase;
2073 }
2074 outb(0xc0 + regb, io);
2075 outb(((v.right & 1) << 5) | ((v.left & 1) << 4) | ((v.feedback & 7) << 1) |
2076 (v.connection & 1), io+1);
2077 return 0;
2078
2079 case FM_IOCTL_SET_PARAMS:
2080 if (copy_from_user(&p, (void __user *)arg, sizeof(p)))
2081 return -EFAULT;
2082 outb(0x08, s->sbbase);
2083 outb((p.kbd_split & 1) << 6, s->sbbase+1);
2084 outb(0xbd, s->sbbase);
2085 outb(((p.am_depth & 1) << 7) | ((p.vib_depth & 1) << 6) | ((p.rhythm & 1) << 5) | ((p.bass & 1) << 4) |
2086 ((p.snare & 1) << 3) | ((p.tomtom & 1) << 2) | ((p.cymbal & 1) << 1) | (p.hihat & 1), s->sbbase+1);
2087 return 0;
2088
2089 case FM_IOCTL_SET_OPL:
2090 outb(4, s->sbbase+2);
2091 outb(arg, s->sbbase+3);
2092 return 0;
2093
2094 case FM_IOCTL_SET_MODE:
2095 outb(5, s->sbbase+2);
2096 outb(arg & 1, s->sbbase+3);
2097 return 0;
2098
2099 default:
2100 return -EINVAL;
2101 }
2102}
2103
2104static int solo1_dmfm_open(struct inode *inode, struct file *file)
2105{
2106 unsigned int minor = iminor(inode);
2107 DECLARE_WAITQUEUE(wait, current);
2108 struct solo1_state *s = NULL;
2109 struct pci_dev *pci_dev = NULL;
2110
2111 while ((pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
2112 struct pci_driver *drvr;
2113
2114 drvr = pci_dev_driver(pci_dev);
2115 if (drvr != &solo1_driver)
2116 continue;
2117 s = (struct solo1_state*)pci_get_drvdata(pci_dev);
2118 if (!s)
2119 continue;
2120 if (s->dev_dmfm == minor)
2121 break;
2122 }
2123 if (!s)
2124 return -ENODEV;
2125 VALIDATE_STATE(s);
2126 file->private_data = s;
2127 /* wait for device to become free */
2128 down(&s->open_sem);
2129 while (s->open_mode & FMODE_DMFM) {
2130 if (file->f_flags & O_NONBLOCK) {
2131 up(&s->open_sem);
2132 return -EBUSY;
2133 }
2134 add_wait_queue(&s->open_wait, &wait);
2135 __set_current_state(TASK_INTERRUPTIBLE);
2136 up(&s->open_sem);
2137 schedule();
2138 remove_wait_queue(&s->open_wait, &wait);
2139 set_current_state(TASK_RUNNING);
2140 if (signal_pending(current))
2141 return -ERESTARTSYS;
2142 down(&s->open_sem);
2143 }
2144 if (!request_region(s->sbbase, FMSYNTH_EXTENT, "ESS Solo1")) {
2145 up(&s->open_sem);
2146 printk(KERN_ERR "solo1: FM synth io ports in use, opl3 loaded?\n");
2147 return -EBUSY;
2148 }
2149 /* init the stuff */
2150 outb(1, s->sbbase);
2151 outb(0x20, s->sbbase+1); /* enable waveforms */
2152 outb(4, s->sbbase+2);
2153 outb(0, s->sbbase+3); /* no 4op enabled */
2154 outb(5, s->sbbase+2);
2155 outb(1, s->sbbase+3); /* enable OPL3 */
2156 s->open_mode |= FMODE_DMFM;
2157 up(&s->open_sem);
2158 return nonseekable_open(inode, file);
2159}
2160
2161static int solo1_dmfm_release(struct inode *inode, struct file *file)
2162{
2163 struct solo1_state *s = (struct solo1_state *)file->private_data;
2164 unsigned int regb;
2165
2166 VALIDATE_STATE(s);
2167 lock_kernel();
2168 down(&s->open_sem);
2169 s->open_mode &= ~FMODE_DMFM;
2170 for (regb = 0xb0; regb < 0xb9; regb++) {
2171 outb(regb, s->sbbase);
2172 outb(0, s->sbbase+1);
2173 outb(regb, s->sbbase+2);
2174 outb(0, s->sbbase+3);
2175 }
2176 release_region(s->sbbase, FMSYNTH_EXTENT);
2177 wake_up(&s->open_wait);
2178 up(&s->open_sem);
2179 unlock_kernel();
2180 return 0;
2181}
2182
2183static /*const*/ struct file_operations solo1_dmfm_fops = {
2184 .owner = THIS_MODULE,
2185 .llseek = no_llseek,
2186 .ioctl = solo1_dmfm_ioctl,
2187 .open = solo1_dmfm_open,
2188 .release = solo1_dmfm_release,
2189};
2190
2191/* --------------------------------------------------------------------- */
2192
2193static struct initvol {
2194 int mixch;
2195 int vol;
2196} initvol[] __devinitdata = {
2197 { SOUND_MIXER_WRITE_VOLUME, 0x4040 },
2198 { SOUND_MIXER_WRITE_PCM, 0x4040 },
2199 { SOUND_MIXER_WRITE_SYNTH, 0x4040 },
2200 { SOUND_MIXER_WRITE_CD, 0x4040 },
2201 { SOUND_MIXER_WRITE_LINE, 0x4040 },
2202 { SOUND_MIXER_WRITE_LINE1, 0x4040 },
2203 { SOUND_MIXER_WRITE_LINE2, 0x4040 },
2204 { SOUND_MIXER_WRITE_RECLEV, 0x4040 },
2205 { SOUND_MIXER_WRITE_SPEAKER, 0x4040 },
2206 { SOUND_MIXER_WRITE_MIC, 0x4040 }
2207};
2208
2209static int setup_solo1(struct solo1_state *s)
2210{
2211 struct pci_dev *pcidev = s->dev;
2212 mm_segment_t fs;
2213 int i, val;
2214
2215 /* initialize DDMA base address */
2216 printk(KERN_DEBUG "solo1: ddma base address: 0x%lx\n", s->ddmabase);
2217 pci_write_config_word(pcidev, 0x60, (s->ddmabase & (~0xf)) | 1);
2218 /* set DMA policy to DDMA, IRQ emulation off (CLKRUN disabled for now) */
2219 pci_write_config_dword(pcidev, 0x50, 0);
2220 /* disable legacy audio address decode */
2221 pci_write_config_word(pcidev, 0x40, 0x907f);
2222
2223 /* initialize the chips */
2224 if (!reset_ctrl(s)) {
2225 printk(KERN_ERR "esssolo1: cannot reset controller\n");
2226 return -1;
2227 }
2228 outb(0xb0, s->iobase+7); /* enable A1, A2, MPU irq's */
2229
2230 /* initialize mixer regs */
2231 write_mixer(s, 0x7f, 0); /* disable music digital recording */
2232 write_mixer(s, 0x7d, 0x0c); /* enable mic preamp, MONO_OUT is 2nd DAC right channel */
2233 write_mixer(s, 0x64, 0x45); /* volume control */
2234 write_mixer(s, 0x48, 0x10); /* enable music DAC/ES6xx interface */
2235 write_mixer(s, 0x50, 0); /* disable spatializer */
2236 write_mixer(s, 0x52, 0);
2237 write_mixer(s, 0x14, 0); /* DAC1 minimum volume */
2238 write_mixer(s, 0x71, 0x20); /* enable new 0xA1 reg format */
2239 outb(0, s->ddmabase+0xd); /* DMA master clear */
2240 outb(1, s->ddmabase+0xf); /* mask channel */
2241 /*outb(0, s->ddmabase+0x8);*/ /* enable controller (enable is low active!!) */
2242
2243 pci_set_master(pcidev); /* enable bus mastering */
2244
2245 fs = get_fs();
2246 set_fs(KERNEL_DS);
2247 val = SOUND_MASK_LINE;
2248 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
2249 for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
2250 val = initvol[i].vol;
2251 mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val);
2252 }
2253 val = 1; /* enable mic preamp */
2254 mixer_ioctl(s, SOUND_MIXER_PRIVATE1, (unsigned long)&val);
2255 set_fs(fs);
2256 return 0;
2257}
2258
2259static int
2260solo1_suspend(struct pci_dev *pci_dev, pm_message_t state) {
2261 struct solo1_state *s = (struct solo1_state*)pci_get_drvdata(pci_dev);
2262 if (!s)
2263 return 1;
2264 outb(0, s->iobase+6);
2265 /* DMA master clear */
2266 outb(0, s->ddmabase+0xd);
2267 /* reset sequencer and FIFO */
2268 outb(3, s->sbbase+6);
2269 /* turn off DDMA controller address space */
2270 pci_write_config_word(s->dev, 0x60, 0);
2271 return 0;
2272}
2273
2274static int
2275solo1_resume(struct pci_dev *pci_dev) {
2276 struct solo1_state *s = (struct solo1_state*)pci_get_drvdata(pci_dev);
2277 if (!s)
2278 return 1;
2279 setup_solo1(s);
2280 return 0;
2281}
2282
2283static int __devinit solo1_register_gameport(struct solo1_state *s, int io_port)
2284{
2285 struct gameport *gp;
2286
2287 if (!request_region(io_port, GAMEPORT_EXTENT, "ESS Solo1")) {
2288 printk(KERN_ERR "solo1: gameport io ports are in use\n");
2289 return -EBUSY;
2290 }
2291
2292 s->gameport = gp = gameport_allocate_port();
2293 if (!gp) {
2294 printk(KERN_ERR "solo1: can not allocate memory for gameport\n");
2295 release_region(io_port, GAMEPORT_EXTENT);
2296 return -ENOMEM;
2297 }
2298
2299 gameport_set_name(gp, "ESS Solo1 Gameport");
2300 gameport_set_phys(gp, "isa%04x/gameport0", io_port);
2301 gp->dev.parent = &s->dev->dev;
2302 gp->io = io_port;
2303
2304 gameport_register_port(gp);
2305
2306 return 0;
2307}
2308
2309static int __devinit solo1_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2310{
2311 struct solo1_state *s;
2312 int gpio;
2313 int ret;
2314
2315 if ((ret=pci_enable_device(pcidev)))
2316 return ret;
2317 if (!(pci_resource_flags(pcidev, 0) & IORESOURCE_IO) ||
2318 !(pci_resource_flags(pcidev, 1) & IORESOURCE_IO) ||
2319 !(pci_resource_flags(pcidev, 2) & IORESOURCE_IO) ||
2320 !(pci_resource_flags(pcidev, 3) & IORESOURCE_IO))
2321 return -ENODEV;
2322 if (pcidev->irq == 0)
2323 return -ENODEV;
2324
2325 /* Recording requires 24-bit DMA, so attempt to set dma mask
2326 * to 24 bits first, then 32 bits (playback only) if that fails.
2327 */
2328 if (pci_set_dma_mask(pcidev, 0x00ffffff) &&
2329 pci_set_dma_mask(pcidev, 0xffffffff)) {
2330 printk(KERN_WARNING "solo1: architecture does not support 24bit or 32bit PCI busmaster DMA\n");
2331 return -ENODEV;
2332 }
2333
2334 if (!(s = kmalloc(sizeof(struct solo1_state), GFP_KERNEL))) {
2335 printk(KERN_WARNING "solo1: out of memory\n");
2336 return -ENOMEM;
2337 }
2338 memset(s, 0, sizeof(struct solo1_state));
2339 init_waitqueue_head(&s->dma_adc.wait);
2340 init_waitqueue_head(&s->dma_dac.wait);
2341 init_waitqueue_head(&s->open_wait);
2342 init_waitqueue_head(&s->midi.iwait);
2343 init_waitqueue_head(&s->midi.owait);
2344 init_MUTEX(&s->open_sem);
2345 spin_lock_init(&s->lock);
2346 s->magic = SOLO1_MAGIC;
2347 s->dev = pcidev;
2348 s->iobase = pci_resource_start(pcidev, 0);
2349 s->sbbase = pci_resource_start(pcidev, 1);
2350 s->vcbase = pci_resource_start(pcidev, 2);
2351 s->ddmabase = s->vcbase + DDMABASE_OFFSET;
2352 s->mpubase = pci_resource_start(pcidev, 3);
2353 gpio = pci_resource_start(pcidev, 4);
2354 s->irq = pcidev->irq;
2355 ret = -EBUSY;
2356 if (!request_region(s->iobase, IOBASE_EXTENT, "ESS Solo1")) {
2357 printk(KERN_ERR "solo1: io ports in use\n");
2358 goto err_region1;
2359 }
2360 if (!request_region(s->sbbase+FMSYNTH_EXTENT, SBBASE_EXTENT-FMSYNTH_EXTENT, "ESS Solo1")) {
2361 printk(KERN_ERR "solo1: io ports in use\n");
2362 goto err_region2;
2363 }
2364 if (!request_region(s->ddmabase, DDMABASE_EXTENT, "ESS Solo1")) {
2365 printk(KERN_ERR "solo1: io ports in use\n");
2366 goto err_region3;
2367 }
2368 if (!request_region(s->mpubase, MPUBASE_EXTENT, "ESS Solo1")) {
2369 printk(KERN_ERR "solo1: io ports in use\n");
2370 goto err_region4;
2371 }
2372 if ((ret=request_irq(s->irq,solo1_interrupt,SA_SHIRQ,"ESS Solo1",s))) {
2373 printk(KERN_ERR "solo1: irq %u in use\n", s->irq);
2374 goto err_irq;
2375 }
2376 /* register devices */
2377 if ((s->dev_audio = register_sound_dsp(&solo1_audio_fops, -1)) < 0) {
2378 ret = s->dev_audio;
2379 goto err_dev1;
2380 }
2381 if ((s->dev_mixer = register_sound_mixer(&solo1_mixer_fops, -1)) < 0) {
2382 ret = s->dev_mixer;
2383 goto err_dev2;
2384 }
2385 if ((s->dev_midi = register_sound_midi(&solo1_midi_fops, -1)) < 0) {
2386 ret = s->dev_midi;
2387 goto err_dev3;
2388 }
2389 if ((s->dev_dmfm = register_sound_special(&solo1_dmfm_fops, 15 /* ?? */)) < 0) {
2390 ret = s->dev_dmfm;
2391 goto err_dev4;
2392 }
2393 if (setup_solo1(s)) {
2394 ret = -EIO;
2395 goto err;
2396 }
2397 /* register gameport */
2398 solo1_register_gameport(s, gpio);
2399 /* store it in the driver field */
2400 pci_set_drvdata(pcidev, s);
2401 return 0;
2402
2403 err:
2404 unregister_sound_special(s->dev_dmfm);
2405 err_dev4:
2406 unregister_sound_midi(s->dev_midi);
2407 err_dev3:
2408 unregister_sound_mixer(s->dev_mixer);
2409 err_dev2:
2410 unregister_sound_dsp(s->dev_audio);
2411 err_dev1:
2412 printk(KERN_ERR "solo1: initialisation error\n");
2413 free_irq(s->irq, s);
2414 err_irq:
2415 release_region(s->mpubase, MPUBASE_EXTENT);
2416 err_region4:
2417 release_region(s->ddmabase, DDMABASE_EXTENT);
2418 err_region3:
2419 release_region(s->sbbase+FMSYNTH_EXTENT, SBBASE_EXTENT-FMSYNTH_EXTENT);
2420 err_region2:
2421 release_region(s->iobase, IOBASE_EXTENT);
2422 err_region1:
2423 kfree(s);
2424 return ret;
2425}
2426
2427static void __devexit solo1_remove(struct pci_dev *dev)
2428{
2429 struct solo1_state *s = pci_get_drvdata(dev);
2430
2431 if (!s)
2432 return;
2433 /* stop DMA controller */
2434 outb(0, s->iobase+6);
2435 outb(0, s->ddmabase+0xd); /* DMA master clear */
2436 outb(3, s->sbbase+6); /* reset sequencer and FIFO */
2437 synchronize_irq(s->irq);
2438 pci_write_config_word(s->dev, 0x60, 0); /* turn off DDMA controller address space */
2439 free_irq(s->irq, s);
2440 if (s->gameport) {
2441 int gpio = s->gameport->io;
2442 gameport_unregister_port(s->gameport);
2443 release_region(gpio, GAMEPORT_EXTENT);
2444 }
2445 release_region(s->iobase, IOBASE_EXTENT);
2446 release_region(s->sbbase+FMSYNTH_EXTENT, SBBASE_EXTENT-FMSYNTH_EXTENT);
2447 release_region(s->ddmabase, DDMABASE_EXTENT);
2448 release_region(s->mpubase, MPUBASE_EXTENT);
2449 unregister_sound_dsp(s->dev_audio);
2450 unregister_sound_mixer(s->dev_mixer);
2451 unregister_sound_midi(s->dev_midi);
2452 unregister_sound_special(s->dev_dmfm);
2453 kfree(s);
2454 pci_set_drvdata(dev, NULL);
2455}
2456
2457static struct pci_device_id id_table[] = {
2458 { PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_SOLO1, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
2459 { 0, }
2460};
2461
2462MODULE_DEVICE_TABLE(pci, id_table);
2463
2464static struct pci_driver solo1_driver = {
2465 .name = "ESS Solo1",
2466 .id_table = id_table,
2467 .probe = solo1_probe,
2468 .remove = __devexit_p(solo1_remove),
2469 .suspend = solo1_suspend,
2470 .resume = solo1_resume,
2471};
2472
2473
2474static int __init init_solo1(void)
2475{
2476 printk(KERN_INFO "solo1: version v0.20 time " __TIME__ " " __DATE__ "\n");
2477 return pci_register_driver(&solo1_driver);
2478}
2479
2480/* --------------------------------------------------------------------- */
2481
2482MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
2483MODULE_DESCRIPTION("ESS Solo1 Driver");
2484MODULE_LICENSE("GPL");
2485
2486
2487static void __exit cleanup_solo1(void)
2488{
2489 printk(KERN_INFO "solo1: unloading\n");
2490 pci_unregister_driver(&solo1_driver);
2491}
2492
2493/* --------------------------------------------------------------------- */
2494
2495module_init(init_solo1);
2496module_exit(cleanup_solo1);
2497
diff --git a/sound/oss/forte.c b/sound/oss/forte.c
new file mode 100644
index 000000000000..8406bc90c4ff
--- /dev/null
+++ b/sound/oss/forte.c
@@ -0,0 +1,2137 @@
1/*
2 * forte.c - ForteMedia FM801 OSS Driver
3 *
4 * Written by Martin K. Petersen <mkp@mkp.net>
5 * Copyright (C) 2002 Hewlett-Packard Company
6 * Portions Copyright (C) 2003 Martin K. Petersen
7 *
8 * Latest version: http://mkp.net/forte/
9 *
10 * Based upon the ALSA FM801 driver by Jaroslav Kysela and OSS drivers
11 * by Thomas Sailer, Alan Cox, Zach Brown, and Jeff Garzik. Thanks
12 * guys!
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License version
16 * 2 as published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 * USA
27 *
28 */
29
30#include <linux/config.h>
31#include <linux/module.h>
32#include <linux/kernel.h>
33
34#include <linux/init.h>
35#include <linux/spinlock.h>
36#include <linux/pci.h>
37
38#include <linux/delay.h>
39#include <linux/poll.h>
40
41#include <linux/sound.h>
42#include <linux/ac97_codec.h>
43#include <linux/interrupt.h>
44
45#include <linux/proc_fs.h>
46
47#include <asm/uaccess.h>
48#include <asm/io.h>
49
50#define DRIVER_NAME "forte"
51#define DRIVER_VERSION "$Id: forte.c,v 1.63 2003/03/01 05:32:42 mkp Exp $"
52#define PFX DRIVER_NAME ": "
53
54#undef M_DEBUG
55
56#ifdef M_DEBUG
57#define DPRINTK(args...) printk(KERN_WARNING args)
58#else
59#define DPRINTK(args...)
60#endif
61
62/* Card capabilities */
63#define FORTE_CAPS (DSP_CAP_MMAP | DSP_CAP_TRIGGER)
64
65/* Supported audio formats */
66#define FORTE_FMTS (AFMT_U8 | AFMT_S16_LE)
67
68/* Buffers */
69#define FORTE_MIN_FRAG_SIZE 256
70#define FORTE_MAX_FRAG_SIZE PAGE_SIZE
71#define FORTE_DEF_FRAG_SIZE 256
72#define FORTE_MIN_FRAGMENTS 2
73#define FORTE_MAX_FRAGMENTS 256
74#define FORTE_DEF_FRAGMENTS 2
75#define FORTE_MIN_BUF_MSECS 500
76#define FORTE_MAX_BUF_MSECS 1000
77
78/* PCI BARs */
79#define FORTE_PCM_VOL 0x00 /* PCM Output Volume */
80#define FORTE_FM_VOL 0x02 /* FM Output Volume */
81#define FORTE_I2S_VOL 0x04 /* I2S Volume */
82#define FORTE_REC_SRC 0x06 /* Record Source */
83#define FORTE_PLY_CTRL 0x08 /* Playback Control */
84#define FORTE_PLY_COUNT 0x0a /* Playback Count */
85#define FORTE_PLY_BUF1 0x0c /* Playback Buffer I */
86#define FORTE_PLY_BUF2 0x10 /* Playback Buffer II */
87#define FORTE_CAP_CTRL 0x14 /* Capture Control */
88#define FORTE_CAP_COUNT 0x16 /* Capture Count */
89#define FORTE_CAP_BUF1 0x18 /* Capture Buffer I */
90#define FORTE_CAP_BUF2 0x1c /* Capture Buffer II */
91#define FORTE_CODEC_CTRL 0x22 /* Codec Control */
92#define FORTE_I2S_MODE 0x24 /* I2S Mode Control */
93#define FORTE_VOLUME 0x26 /* Volume Up/Down/Mute Status */
94#define FORTE_I2C_CTRL 0x29 /* I2C Control */
95#define FORTE_AC97_CMD 0x2a /* AC'97 Command */
96#define FORTE_AC97_DATA 0x2c /* AC'97 Data */
97#define FORTE_MPU401_DATA 0x30 /* MPU401 Data */
98#define FORTE_MPU401_CMD 0x31 /* MPU401 Command */
99#define FORTE_GPIO_CTRL 0x52 /* General Purpose I/O Control */
100#define FORTE_GEN_CTRL 0x54 /* General Control */
101#define FORTE_IRQ_MASK 0x56 /* Interrupt Mask */
102#define FORTE_IRQ_STATUS 0x5a /* Interrupt Status */
103#define FORTE_OPL3_BANK0 0x68 /* OPL3 Status Read / Bank 0 Write */
104#define FORTE_OPL3_DATA0 0x69 /* OPL3 Data 0 Write */
105#define FORTE_OPL3_BANK1 0x6a /* OPL3 Bank 1 Write */
106#define FORTE_OPL3_DATA1 0x6b /* OPL3 Bank 1 Write */
107#define FORTE_POWERDOWN 0x70 /* Blocks Power Down Control */
108
109#define FORTE_CAP_OFFSET FORTE_CAP_CTRL - FORTE_PLY_CTRL
110
111#define FORTE_AC97_ADDR_SHIFT 10
112
113/* Playback and record control register bits */
114#define FORTE_BUF1_LAST (1<<1)
115#define FORTE_BUF2_LAST (1<<2)
116#define FORTE_START (1<<5)
117#define FORTE_PAUSE (1<<6)
118#define FORTE_IMMED_STOP (1<<7)
119#define FORTE_RATE_SHIFT 8
120#define FORTE_RATE_MASK (15 << FORTE_RATE_SHIFT)
121#define FORTE_CHANNELS_4 (1<<12) /* Playback only */
122#define FORTE_CHANNELS_6 (2<<12) /* Playback only */
123#define FORTE_CHANNELS_6MS (3<<12) /* Playback only */
124#define FORTE_CHANNELS_MASK (3<<12)
125#define FORTE_16BIT (1<<14)
126#define FORTE_STEREO (1<<15)
127
128/* IRQ status bits */
129#define FORTE_IRQ_PLAYBACK (1<<8)
130#define FORTE_IRQ_CAPTURE (1<<9)
131#define FORTE_IRQ_VOLUME (1<<14)
132#define FORTE_IRQ_MPU (1<<15)
133
134/* CODEC control */
135#define FORTE_CC_CODEC_RESET (1<<5)
136#define FORTE_CC_AC97_RESET (1<<6)
137
138/* AC97 cmd */
139#define FORTE_AC97_WRITE (0<<7)
140#define FORTE_AC97_READ (1<<7)
141#define FORTE_AC97_DP_INVALID (0<<8)
142#define FORTE_AC97_DP_VALID (1<<8)
143#define FORTE_AC97_PORT_RDY (0<<9)
144#define FORTE_AC97_PORT_BSY (1<<9)
145
146
147struct forte_channel {
148 const char *name;
149
150 unsigned short ctrl; /* Ctrl BAR contents */
151 unsigned long iobase; /* Ctrl BAR address */
152
153 wait_queue_head_t wait;
154
155 void *buf; /* Buffer */
156 dma_addr_t buf_handle; /* Buffer handle */
157
158 unsigned int record;
159 unsigned int format;
160 unsigned int rate;
161 unsigned int stereo;
162
163 unsigned int frag_sz; /* Current fragment size */
164 unsigned int frag_num; /* Current # of fragments */
165 unsigned int frag_msecs; /* Milliseconds per frag */
166 unsigned int buf_sz; /* Current buffer size */
167
168 unsigned int hwptr; /* Tail */
169 unsigned int swptr; /* Head */
170 unsigned int filled_frags; /* Fragments currently full */
171 unsigned int next_buf; /* Index of next buffer */
172
173 unsigned int active; /* Channel currently in use */
174 unsigned int mapped; /* mmap */
175
176 unsigned int buf_pages; /* Real size of buffer */
177 unsigned int nr_irqs; /* Number of interrupts */
178 unsigned int bytes; /* Total bytes */
179 unsigned int residue; /* Partial fragment */
180};
181
182
183struct forte_chip {
184 struct pci_dev *pci_dev;
185 unsigned long iobase;
186 int irq;
187
188 struct semaphore open_sem; /* Device access */
189 spinlock_t lock; /* State */
190
191 spinlock_t ac97_lock;
192 struct ac97_codec *ac97;
193
194 int multichannel;
195 int dsp; /* OSS handle */
196 int trigger; /* mmap I/O trigger */
197
198 struct forte_channel play;
199 struct forte_channel rec;
200};
201
202
203static int channels[] = { 2, 4, 6, };
204static int rates[] = { 5500, 8000, 9600, 11025, 16000, 19200,
205 22050, 32000, 38400, 44100, 48000, };
206
207static struct forte_chip *forte;
208static int found;
209
210
211/* AC97 Codec -------------------------------------------------------------- */
212
213
214/**
215 * forte_ac97_wait:
216 * @chip: fm801 instance whose AC97 codec to wait on
217 *
218 * FIXME:
219 * Stop busy-waiting
220 */
221
222static inline int
223forte_ac97_wait (struct forte_chip *chip)
224{
225 int i = 10000;
226
227 while ( (inw (chip->iobase + FORTE_AC97_CMD) & FORTE_AC97_PORT_BSY)
228 && i-- )
229 cpu_relax();
230
231 return i == 0;
232}
233
234
235/**
236 * forte_ac97_read:
237 * @codec: AC97 codec to read from
238 * @reg: register to read
239 */
240
241static u16
242forte_ac97_read (struct ac97_codec *codec, u8 reg)
243{
244 u16 ret = 0;
245 struct forte_chip *chip = codec->private_data;
246
247 spin_lock (&chip->ac97_lock);
248
249 /* Knock, knock */
250 if (forte_ac97_wait (chip)) {
251 printk (KERN_ERR PFX "ac97_read: Serial bus busy\n");
252 goto out;
253 }
254
255 /* Send read command */
256 outw (reg | (1<<7), chip->iobase + FORTE_AC97_CMD);
257
258 if (forte_ac97_wait (chip)) {
259 printk (KERN_ERR PFX "ac97_read: Bus busy reading reg 0x%x\n",
260 reg);
261 goto out;
262 }
263
264 /* Sanity checking */
265 if (inw (chip->iobase + FORTE_AC97_CMD) & FORTE_AC97_DP_INVALID) {
266 printk (KERN_ERR PFX "ac97_read: Invalid data port");
267 goto out;
268 }
269
270 /* Fetch result */
271 ret = inw (chip->iobase + FORTE_AC97_DATA);
272
273 out:
274 spin_unlock (&chip->ac97_lock);
275 return ret;
276}
277
278
279/**
280 * forte_ac97_write:
281 * @codec: AC97 codec to send command to
282 * @reg: register to write
283 * @val: value to write
284 */
285
286static void
287forte_ac97_write (struct ac97_codec *codec, u8 reg, u16 val)
288{
289 struct forte_chip *chip = codec->private_data;
290
291 spin_lock (&chip->ac97_lock);
292
293 /* Knock, knock */
294 if (forte_ac97_wait (chip)) {
295 printk (KERN_ERR PFX "ac97_write: Serial bus busy\n");
296 goto out;
297 }
298
299 outw (val, chip->iobase + FORTE_AC97_DATA);
300 outb (reg | FORTE_AC97_WRITE, chip->iobase + FORTE_AC97_CMD);
301
302 /* Wait for completion */
303 if (forte_ac97_wait (chip)) {
304 printk (KERN_ERR PFX "ac97_write: Bus busy after write\n");
305 goto out;
306 }
307
308 out:
309 spin_unlock (&chip->ac97_lock);
310}
311
312
313/* Mixer ------------------------------------------------------------------- */
314
315
316/**
317 * forte_mixer_open:
318 * @inode:
319 * @file:
320 */
321
322static int
323forte_mixer_open (struct inode *inode, struct file *file)
324{
325 struct forte_chip *chip = forte;
326 file->private_data = chip->ac97;
327 return 0;
328}
329
330
331/**
332 * forte_mixer_release:
333 * @inode:
334 * @file:
335 */
336
337static int
338forte_mixer_release (struct inode *inode, struct file *file)
339{
340 /* We will welease Wodewick */
341 return 0;
342}
343
344
345/**
346 * forte_mixer_ioctl:
347 * @inode:
348 * @file:
349 */
350
351static int
352forte_mixer_ioctl (struct inode *inode, struct file *file,
353 unsigned int cmd, unsigned long arg)
354{
355 struct ac97_codec *codec = (struct ac97_codec *) file->private_data;
356
357 return codec->mixer_ioctl (codec, cmd, arg);
358}
359
360
361static struct file_operations forte_mixer_fops = {
362 .owner = THIS_MODULE,
363 .llseek = no_llseek,
364 .ioctl = forte_mixer_ioctl,
365 .open = forte_mixer_open,
366 .release = forte_mixer_release,
367};
368
369
370/* Channel ----------------------------------------------------------------- */
371
372/**
373 * forte_channel_reset:
374 * @channel: Channel to reset
375 *
376 * Locking: Must be called with lock held.
377 */
378
379static void
380forte_channel_reset (struct forte_channel *channel)
381{
382 if (!channel || !channel->iobase)
383 return;
384
385 DPRINTK ("%s: channel = %s\n", __FUNCTION__, channel->name);
386
387 channel->ctrl &= ~FORTE_START;
388 outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
389
390 /* We always play at least two fragments, hence these defaults */
391 channel->hwptr = channel->frag_sz;
392 channel->next_buf = 1;
393 channel->swptr = 0;
394 channel->filled_frags = 0;
395 channel->active = 0;
396 channel->bytes = 0;
397 channel->nr_irqs = 0;
398 channel->mapped = 0;
399 channel->residue = 0;
400}
401
402
403/**
404 * forte_channel_start:
405 * @channel: Channel to start (record/playback)
406 *
407 * Locking: Must be called with lock held.
408 */
409
410static void inline
411forte_channel_start (struct forte_channel *channel)
412{
413 if (!channel || !channel->iobase || channel->active)
414 return;
415
416 channel->ctrl &= ~(FORTE_PAUSE | FORTE_BUF1_LAST | FORTE_BUF2_LAST
417 | FORTE_IMMED_STOP);
418 channel->ctrl |= FORTE_START;
419 channel->active = 1;
420 outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
421}
422
423
424/**
425 * forte_channel_stop:
426 * @channel: Channel to stop
427 *
428 * Locking: Must be called with lock held.
429 */
430
431static void inline
432forte_channel_stop (struct forte_channel *channel)
433{
434 if (!channel || !channel->iobase)
435 return;
436
437 channel->ctrl &= ~(FORTE_START | FORTE_PAUSE);
438 channel->ctrl |= FORTE_IMMED_STOP;
439
440 channel->active = 0;
441 outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
442}
443
444
445/**
446 * forte_channel_pause:
447 * @channel: Channel to pause
448 *
449 * Locking: Must be called with lock held.
450 */
451
452static void inline
453forte_channel_pause (struct forte_channel *channel)
454{
455 if (!channel || !channel->iobase)
456 return;
457
458 channel->ctrl |= FORTE_PAUSE;
459
460 channel->active = 0;
461 outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
462}
463
464
465/**
466 * forte_channel_rate:
467 * @channel: Channel whose rate to set. Playback and record are
468 * independent.
469 * @rate: Channel rate in Hz
470 *
471 * Locking: Must be called with lock held.
472 */
473
474static int
475forte_channel_rate (struct forte_channel *channel, unsigned int rate)
476{
477 int new_rate;
478
479 if (!channel || !channel->iobase)
480 return -EINVAL;
481
482 /* The FM801 only supports a handful of fixed frequencies.
483 * We find the value closest to what userland requested.
484 */
485 if (rate <= 6250) { rate = 5500; new_rate = 0; }
486 else if (rate <= 8800) { rate = 8000; new_rate = 1; }
487 else if (rate <= 10312) { rate = 9600; new_rate = 2; }
488 else if (rate <= 13512) { rate = 11025; new_rate = 3; }
489 else if (rate <= 17600) { rate = 16000; new_rate = 4; }
490 else if (rate <= 20625) { rate = 19200; new_rate = 5; }
491 else if (rate <= 27025) { rate = 22050; new_rate = 6; }
492 else if (rate <= 35200) { rate = 32000; new_rate = 7; }
493 else if (rate <= 41250) { rate = 38400; new_rate = 8; }
494 else if (rate <= 46050) { rate = 44100; new_rate = 9; }
495 else { rate = 48000; new_rate = 10; }
496
497 channel->ctrl &= ~FORTE_RATE_MASK;
498 channel->ctrl |= new_rate << FORTE_RATE_SHIFT;
499 channel->rate = rate;
500
501 DPRINTK ("%s: %s rate = %d\n", __FUNCTION__, channel->name, rate);
502
503 return rate;
504}
505
506
507/**
508 * forte_channel_format:
509 * @channel: Channel whose audio format to set
510 * @format: OSS format ID
511 *
512 * Locking: Must be called with lock held.
513 */
514
515static int
516forte_channel_format (struct forte_channel *channel, int format)
517{
518 if (!channel || !channel->iobase)
519 return -EINVAL;
520
521 switch (format) {
522
523 case AFMT_QUERY:
524 break;
525
526 case AFMT_U8:
527 channel->ctrl &= ~FORTE_16BIT;
528 channel->format = AFMT_U8;
529 break;
530
531 case AFMT_S16_LE:
532 default:
533 channel->ctrl |= FORTE_16BIT;
534 channel->format = AFMT_S16_LE;
535 break;
536 }
537
538 DPRINTK ("%s: %s want %d format, got %d\n", __FUNCTION__, channel->name,
539 format, channel->format);
540
541 return channel->format;
542}
543
544
545/**
546 * forte_channel_stereo:
547 * @channel: Channel to toggle
548 * @stereo: 0 for Mono, 1 for Stereo
549 *
550 * Locking: Must be called with lock held.
551 */
552
553static int
554forte_channel_stereo (struct forte_channel *channel, unsigned int stereo)
555{
556 int ret;
557
558 if (!channel || !channel->iobase)
559 return -EINVAL;
560
561 DPRINTK ("%s: %s stereo = %d\n", __FUNCTION__, channel->name, stereo);
562
563 switch (stereo) {
564
565 case 0:
566 channel->ctrl &= ~(FORTE_STEREO | FORTE_CHANNELS_MASK);
567 channel-> stereo = stereo;
568 ret = stereo;
569 break;
570
571 case 1:
572 channel->ctrl &= ~FORTE_CHANNELS_MASK;
573 channel->ctrl |= FORTE_STEREO;
574 channel-> stereo = stereo;
575 ret = stereo;
576 break;
577
578 default:
579 DPRINTK ("Unsupported channel format");
580 ret = -EINVAL;
581 break;
582 }
583
584 return ret;
585}
586
587
588/**
589 * forte_channel_buffer:
590 * @channel: Channel whose buffer to set up
591 *
592 * Locking: Must be called with lock held.
593 */
594
595static void
596forte_channel_buffer (struct forte_channel *channel, int sz, int num)
597{
598 unsigned int msecs, shift;
599
600 /* Go away, I'm busy */
601 if (channel->filled_frags || channel->bytes)
602 return;
603
604 /* Fragment size must be a power of 2 */
605 shift = 0; sz++;
606 while (sz >>= 1)
607 shift++;
608 channel->frag_sz = 1 << shift;
609
610 /* Round fragment size to something reasonable */
611 if (channel->frag_sz < FORTE_MIN_FRAG_SIZE)
612 channel->frag_sz = FORTE_MIN_FRAG_SIZE;
613
614 if (channel->frag_sz > FORTE_MAX_FRAG_SIZE)
615 channel->frag_sz = FORTE_MAX_FRAG_SIZE;
616
617 /* Find fragment length in milliseconds */
618 msecs = channel->frag_sz /
619 (channel->format == AFMT_S16_LE ? 2 : 1) /
620 (channel->stereo ? 2 : 1) /
621 (channel->rate / 1000);
622
623 channel->frag_msecs = msecs;
624
625 /* Pick a suitable number of fragments */
626 if (msecs * num < FORTE_MIN_BUF_MSECS)
627 num = FORTE_MIN_BUF_MSECS / msecs;
628
629 if (msecs * num > FORTE_MAX_BUF_MSECS)
630 num = FORTE_MAX_BUF_MSECS / msecs;
631
632 /* Fragment number must be a power of 2 */
633 shift = 0;
634 while (num >>= 1)
635 shift++;
636 channel->frag_num = 1 << (shift + 1);
637
638 /* Round fragment number to something reasonable */
639 if (channel->frag_num < FORTE_MIN_FRAGMENTS)
640 channel->frag_num = FORTE_MIN_FRAGMENTS;
641
642 if (channel->frag_num > FORTE_MAX_FRAGMENTS)
643 channel->frag_num = FORTE_MAX_FRAGMENTS;
644
645 channel->buf_sz = channel->frag_sz * channel->frag_num;
646
647 DPRINTK ("%s: %s frag_sz = %d, frag_num = %d, buf_sz = %d\n",
648 __FUNCTION__, channel->name, channel->frag_sz,
649 channel->frag_num, channel->buf_sz);
650}
651
652
653/**
654 * forte_channel_prep:
655 * @channel: Channel whose buffer to prepare
656 *
657 * Locking: Lock held.
658 */
659
660static void
661forte_channel_prep (struct forte_channel *channel)
662{
663 struct page *page;
664 int i;
665
666 if (channel->buf)
667 return;
668
669 forte_channel_buffer (channel, channel->frag_sz, channel->frag_num);
670 channel->buf_pages = channel->buf_sz >> PAGE_SHIFT;
671
672 if (channel->buf_sz % PAGE_SIZE)
673 channel->buf_pages++;
674
675 DPRINTK ("%s: %s frag_sz = %d, frag_num = %d, buf_sz = %d, pg = %d\n",
676 __FUNCTION__, channel->name, channel->frag_sz,
677 channel->frag_num, channel->buf_sz, channel->buf_pages);
678
679 /* DMA buffer */
680 channel->buf = pci_alloc_consistent (forte->pci_dev,
681 channel->buf_pages * PAGE_SIZE,
682 &channel->buf_handle);
683
684 if (!channel->buf || !channel->buf_handle)
685 BUG();
686
687 page = virt_to_page (channel->buf);
688
689 /* FIXME: can this go away ? */
690 for (i = 0 ; i < channel->buf_pages ; i++)
691 SetPageReserved(page++);
692
693 /* Prep buffer registers */
694 outw (channel->frag_sz - 1, channel->iobase + FORTE_PLY_COUNT);
695 outl (channel->buf_handle, channel->iobase + FORTE_PLY_BUF1);
696 outl (channel->buf_handle + channel->frag_sz,
697 channel->iobase + FORTE_PLY_BUF2);
698
699 /* Reset hwptr */
700 channel->hwptr = channel->frag_sz;
701 channel->next_buf = 1;
702
703 DPRINTK ("%s: %s buffer @ %p (%p)\n", __FUNCTION__, channel->name,
704 channel->buf, channel->buf_handle);
705}
706
707
708/**
709 * forte_channel_drain:
710 * @chip:
711 * @channel:
712 *
713 * Locking: Don't hold the lock.
714 */
715
716static inline int
717forte_channel_drain (struct forte_channel *channel)
718{
719 DECLARE_WAITQUEUE (wait, current);
720 unsigned long flags;
721
722 DPRINTK ("%s\n", __FUNCTION__);
723
724 if (channel->mapped) {
725 spin_lock_irqsave (&forte->lock, flags);
726 forte_channel_stop (channel);
727 spin_unlock_irqrestore (&forte->lock, flags);
728 return 0;
729 }
730
731 spin_lock_irqsave (&forte->lock, flags);
732 add_wait_queue (&channel->wait, &wait);
733
734 for (;;) {
735 if (channel->active == 0 || channel->filled_frags == 1)
736 break;
737
738 spin_unlock_irqrestore (&forte->lock, flags);
739
740 __set_current_state (TASK_INTERRUPTIBLE);
741 schedule();
742
743 spin_lock_irqsave (&forte->lock, flags);
744 }
745
746 forte_channel_stop (channel);
747 forte_channel_reset (channel);
748 set_current_state (TASK_RUNNING);
749 remove_wait_queue (&channel->wait, &wait);
750 spin_unlock_irqrestore (&forte->lock, flags);
751
752 return 0;
753}
754
755
756/**
757 * forte_channel_init:
758 * @chip: Forte chip instance the channel hangs off
759 * @channel: Channel to initialize
760 *
761 * Description:
762 * Initializes a channel, sets defaults, and allocates
763 * buffers.
764 *
765 * Locking: No lock held.
766 */
767
768static int
769forte_channel_init (struct forte_chip *chip, struct forte_channel *channel)
770{
771 DPRINTK ("%s: chip iobase @ %p\n", __FUNCTION__, (void *)chip->iobase);
772
773 spin_lock_irq (&chip->lock);
774 memset (channel, 0x0, sizeof (*channel));
775
776 if (channel == &chip->play) {
777 channel->name = "PCM_OUT";
778 channel->iobase = chip->iobase;
779 DPRINTK ("%s: PCM-OUT iobase @ %p\n", __FUNCTION__,
780 (void *) channel->iobase);
781 }
782 else if (channel == &chip->rec) {
783 channel->name = "PCM_IN";
784 channel->iobase = chip->iobase + FORTE_CAP_OFFSET;
785 channel->record = 1;
786 DPRINTK ("%s: PCM-IN iobase @ %p\n", __FUNCTION__,
787 (void *) channel->iobase);
788 }
789 else
790 BUG();
791
792 init_waitqueue_head (&channel->wait);
793
794 /* Defaults: 48kHz, 16-bit, stereo */
795 channel->ctrl = inw (channel->iobase + FORTE_PLY_CTRL);
796 forte_channel_reset (channel);
797 forte_channel_stereo (channel, 1);
798 forte_channel_format (channel, AFMT_S16_LE);
799 forte_channel_rate (channel, 48000);
800 channel->frag_sz = FORTE_DEF_FRAG_SIZE;
801 channel->frag_num = FORTE_DEF_FRAGMENTS;
802
803 chip->trigger = 0;
804 spin_unlock_irq (&chip->lock);
805
806 return 0;
807}
808
809
810/**
811 * forte_channel_free:
812 * @chip: Chip this channel hangs off
813 * @channel: Channel to nuke
814 *
815 * Description:
816 * Resets channel and frees buffers.
817 *
818 * Locking: Hold your horses.
819 */
820
821static void
822forte_channel_free (struct forte_chip *chip, struct forte_channel *channel)
823{
824 DPRINTK ("%s: %s\n", __FUNCTION__, channel->name);
825
826 if (!channel->buf_handle)
827 return;
828
829 pci_free_consistent (chip->pci_dev, channel->buf_pages * PAGE_SIZE,
830 channel->buf, channel->buf_handle);
831
832 memset (channel, 0x0, sizeof (*channel));
833}
834
835
836/* DSP --------------------------------------------------------------------- */
837
838
839/**
840 * forte_dsp_ioctl:
841 */
842
843static int
844forte_dsp_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
845 unsigned long arg)
846{
847 int ival=0, ret, rval=0, rd, wr, count;
848 struct forte_chip *chip;
849 struct audio_buf_info abi;
850 struct count_info cinfo;
851 void __user *argp = (void __user *)arg;
852 int __user *p = argp;
853
854 chip = file->private_data;
855
856 if (file->f_mode & FMODE_WRITE)
857 wr = 1;
858 else
859 wr = 0;
860
861 if (file->f_mode & FMODE_READ)
862 rd = 1;
863 else
864 rd = 0;
865
866 switch (cmd) {
867
868 case OSS_GETVERSION:
869 return put_user (SOUND_VERSION, p);
870
871 case SNDCTL_DSP_GETCAPS:
872 DPRINTK ("%s: GETCAPS\n", __FUNCTION__);
873
874 ival = FORTE_CAPS; /* DUPLEX */
875 return put_user (ival, p);
876
877 case SNDCTL_DSP_GETFMTS:
878 DPRINTK ("%s: GETFMTS\n", __FUNCTION__);
879
880 ival = FORTE_FMTS; /* U8, 16LE */
881 return put_user (ival, p);
882
883 case SNDCTL_DSP_SETFMT: /* U8, 16LE */
884 DPRINTK ("%s: SETFMT\n", __FUNCTION__);
885
886 if (get_user (ival, p))
887 return -EFAULT;
888
889 spin_lock_irq (&chip->lock);
890
891 if (rd) {
892 forte_channel_stop (&chip->rec);
893 rval = forte_channel_format (&chip->rec, ival);
894 }
895
896 if (wr) {
897 forte_channel_stop (&chip->rec);
898 rval = forte_channel_format (&chip->play, ival);
899 }
900
901 spin_unlock_irq (&chip->lock);
902
903 return put_user (rval, p);
904
905 case SNDCTL_DSP_STEREO: /* 0 - mono, 1 - stereo */
906 DPRINTK ("%s: STEREO\n", __FUNCTION__);
907
908 if (get_user (ival, p))
909 return -EFAULT;
910
911 spin_lock_irq (&chip->lock);
912
913 if (rd) {
914 forte_channel_stop (&chip->rec);
915 rval = forte_channel_stereo (&chip->rec, ival);
916 }
917
918 if (wr) {
919 forte_channel_stop (&chip->rec);
920 rval = forte_channel_stereo (&chip->play, ival);
921 }
922
923 spin_unlock_irq (&chip->lock);
924
925 return put_user (rval, p);
926
927 case SNDCTL_DSP_CHANNELS: /* 1 - mono, 2 - stereo */
928 DPRINTK ("%s: CHANNELS\n", __FUNCTION__);
929
930 if (get_user (ival, p))
931 return -EFAULT;
932
933 spin_lock_irq (&chip->lock);
934
935 if (rd) {
936 forte_channel_stop (&chip->rec);
937 rval = forte_channel_stereo (&chip->rec, ival-1) + 1;
938 }
939
940 if (wr) {
941 forte_channel_stop (&chip->play);
942 rval = forte_channel_stereo (&chip->play, ival-1) + 1;
943 }
944
945 spin_unlock_irq (&chip->lock);
946
947 return put_user (rval, p);
948
949 case SNDCTL_DSP_SPEED:
950 DPRINTK ("%s: SPEED\n", __FUNCTION__);
951
952 if (get_user (ival, p))
953 return -EFAULT;
954
955 spin_lock_irq (&chip->lock);
956
957 if (rd) {
958 forte_channel_stop (&chip->rec);
959 rval = forte_channel_rate (&chip->rec, ival);
960 }
961
962 if (wr) {
963 forte_channel_stop (&chip->play);
964 rval = forte_channel_rate (&chip->play, ival);
965 }
966
967 spin_unlock_irq (&chip->lock);
968
969 return put_user(rval, p);
970
971 case SNDCTL_DSP_GETBLKSIZE:
972 DPRINTK ("%s: GETBLKSIZE\n", __FUNCTION__);
973
974 spin_lock_irq (&chip->lock);
975
976 if (rd)
977 ival = chip->rec.frag_sz;
978
979 if (wr)
980 ival = chip->play.frag_sz;
981
982 spin_unlock_irq (&chip->lock);
983
984 return put_user (ival, p);
985
986 case SNDCTL_DSP_RESET:
987 DPRINTK ("%s: RESET\n", __FUNCTION__);
988
989 spin_lock_irq (&chip->lock);
990
991 if (rd)
992 forte_channel_reset (&chip->rec);
993
994 if (wr)
995 forte_channel_reset (&chip->play);
996
997 spin_unlock_irq (&chip->lock);
998
999 return 0;
1000
1001 case SNDCTL_DSP_SYNC:
1002 DPRINTK ("%s: SYNC\n", __FUNCTION__);
1003
1004 if (wr)
1005 ret = forte_channel_drain (&chip->play);
1006
1007 return 0;
1008
1009 case SNDCTL_DSP_POST:
1010 DPRINTK ("%s: POST\n", __FUNCTION__);
1011
1012 if (wr) {
1013 spin_lock_irq (&chip->lock);
1014
1015 if (chip->play.filled_frags)
1016 forte_channel_start (&chip->play);
1017
1018 spin_unlock_irq (&chip->lock);
1019 }
1020
1021 return 0;
1022
1023 case SNDCTL_DSP_SETFRAGMENT:
1024 DPRINTK ("%s: SETFRAGMENT\n", __FUNCTION__);
1025
1026 if (get_user (ival, p))
1027 return -EFAULT;
1028
1029 spin_lock_irq (&chip->lock);
1030
1031 if (rd) {
1032 forte_channel_buffer (&chip->rec, ival & 0xffff,
1033 (ival >> 16) & 0xffff);
1034 ival = (chip->rec.frag_num << 16) + chip->rec.frag_sz;
1035 }
1036
1037 if (wr) {
1038 forte_channel_buffer (&chip->play, ival & 0xffff,
1039 (ival >> 16) & 0xffff);
1040 ival = (chip->play.frag_num << 16) +chip->play.frag_sz;
1041 }
1042
1043 spin_unlock_irq (&chip->lock);
1044
1045 return put_user (ival, p);
1046
1047 case SNDCTL_DSP_GETISPACE:
1048 DPRINTK ("%s: GETISPACE\n", __FUNCTION__);
1049
1050 if (!rd)
1051 return -EINVAL;
1052
1053 spin_lock_irq (&chip->lock);
1054
1055 abi.fragstotal = chip->rec.frag_num;
1056 abi.fragsize = chip->rec.frag_sz;
1057
1058 if (chip->rec.mapped) {
1059 abi.fragments = chip->rec.frag_num - 2;
1060 abi.bytes = abi.fragments * abi.fragsize;
1061 }
1062 else {
1063 abi.fragments = chip->rec.filled_frags;
1064 abi.bytes = abi.fragments * abi.fragsize;
1065 }
1066
1067 spin_unlock_irq (&chip->lock);
1068
1069 return copy_to_user (argp, &abi, sizeof (abi)) ? -EFAULT : 0;
1070
1071 case SNDCTL_DSP_GETIPTR:
1072 DPRINTK ("%s: GETIPTR\n", __FUNCTION__);
1073
1074 if (!rd)
1075 return -EINVAL;
1076
1077 spin_lock_irq (&chip->lock);
1078
1079 if (chip->rec.active)
1080 cinfo.ptr = chip->rec.hwptr;
1081 else
1082 cinfo.ptr = 0;
1083
1084 cinfo.bytes = chip->rec.bytes;
1085 cinfo.blocks = chip->rec.nr_irqs;
1086 chip->rec.nr_irqs = 0;
1087
1088 spin_unlock_irq (&chip->lock);
1089
1090 return copy_to_user (argp, &cinfo, sizeof (cinfo)) ? -EFAULT : 0;
1091
1092 case SNDCTL_DSP_GETOSPACE:
1093 if (!wr)
1094 return -EINVAL;
1095
1096 spin_lock_irq (&chip->lock);
1097
1098 abi.fragstotal = chip->play.frag_num;
1099 abi.fragsize = chip->play.frag_sz;
1100
1101 if (chip->play.mapped) {
1102 abi.fragments = chip->play.frag_num - 2;
1103 abi.bytes = chip->play.buf_sz;
1104 }
1105 else {
1106 abi.fragments = chip->play.frag_num -
1107 chip->play.filled_frags;
1108
1109 if (chip->play.residue)
1110 abi.fragments--;
1111
1112 abi.bytes = abi.fragments * abi.fragsize +
1113 chip->play.residue;
1114 }
1115
1116 spin_unlock_irq (&chip->lock);
1117
1118 return copy_to_user (argp, &abi, sizeof (abi)) ? -EFAULT : 0;
1119
1120 case SNDCTL_DSP_GETOPTR:
1121 if (!wr)
1122 return -EINVAL;
1123
1124 spin_lock_irq (&chip->lock);
1125
1126 if (chip->play.active)
1127 cinfo.ptr = chip->play.hwptr;
1128 else
1129 cinfo.ptr = 0;
1130
1131 cinfo.bytes = chip->play.bytes;
1132 cinfo.blocks = chip->play.nr_irqs;
1133 chip->play.nr_irqs = 0;
1134
1135 spin_unlock_irq (&chip->lock);
1136
1137 return copy_to_user (argp, &cinfo, sizeof (cinfo)) ? -EFAULT : 0;
1138
1139 case SNDCTL_DSP_GETODELAY:
1140 if (!wr)
1141 return -EINVAL;
1142
1143 spin_lock_irq (&chip->lock);
1144
1145 if (!chip->play.active) {
1146 ival = 0;
1147 }
1148 else if (chip->play.mapped) {
1149 count = inw (chip->play.iobase + FORTE_PLY_COUNT) + 1;
1150 ival = chip->play.frag_sz - count;
1151 }
1152 else {
1153 ival = chip->play.filled_frags * chip->play.frag_sz;
1154
1155 if (chip->play.residue)
1156 ival += chip->play.frag_sz - chip->play.residue;
1157 }
1158
1159 spin_unlock_irq (&chip->lock);
1160
1161 return put_user (ival, p);
1162
1163 case SNDCTL_DSP_SETDUPLEX:
1164 DPRINTK ("%s: SETDUPLEX\n", __FUNCTION__);
1165
1166 return -EINVAL;
1167
1168 case SNDCTL_DSP_GETTRIGGER:
1169 DPRINTK ("%s: GETTRIGGER\n", __FUNCTION__);
1170
1171 return put_user (chip->trigger, p);
1172
1173 case SNDCTL_DSP_SETTRIGGER:
1174
1175 if (get_user (ival, p))
1176 return -EFAULT;
1177
1178 DPRINTK ("%s: SETTRIGGER %d\n", __FUNCTION__, ival);
1179
1180 if (wr) {
1181 spin_lock_irq (&chip->lock);
1182
1183 if (ival & PCM_ENABLE_OUTPUT)
1184 forte_channel_start (&chip->play);
1185 else {
1186 chip->trigger = 1;
1187 forte_channel_prep (&chip->play);
1188 forte_channel_stop (&chip->play);
1189 }
1190
1191 spin_unlock_irq (&chip->lock);
1192 }
1193 else if (rd) {
1194 spin_lock_irq (&chip->lock);
1195
1196 if (ival & PCM_ENABLE_INPUT)
1197 forte_channel_start (&chip->rec);
1198 else {
1199 chip->trigger = 1;
1200 forte_channel_prep (&chip->rec);
1201 forte_channel_stop (&chip->rec);
1202 }
1203
1204 spin_unlock_irq (&chip->lock);
1205 }
1206
1207 return 0;
1208
1209 case SOUND_PCM_READ_RATE:
1210 DPRINTK ("%s: PCM_READ_RATE\n", __FUNCTION__);
1211 return put_user (chip->play.rate, p);
1212
1213 case SOUND_PCM_READ_CHANNELS:
1214 DPRINTK ("%s: PCM_READ_CHANNELS\n", __FUNCTION__);
1215 return put_user (chip->play.stereo, p);
1216
1217 case SOUND_PCM_READ_BITS:
1218 DPRINTK ("%s: PCM_READ_BITS\n", __FUNCTION__);
1219 return put_user (chip->play.format, p);
1220
1221 case SNDCTL_DSP_NONBLOCK:
1222 DPRINTK ("%s: DSP_NONBLOCK\n", __FUNCTION__);
1223 file->f_flags |= O_NONBLOCK;
1224 return 0;
1225
1226 default:
1227 DPRINTK ("Unsupported ioctl: %x (%p)\n", cmd, argp);
1228 break;
1229 }
1230
1231 return -EINVAL;
1232}
1233
1234
1235/**
1236 * forte_dsp_open:
1237 */
1238
1239static int
1240forte_dsp_open (struct inode *inode, struct file *file)
1241{
1242 struct forte_chip *chip = forte; /* FIXME: HACK FROM HELL! */
1243
1244 if (file->f_flags & O_NONBLOCK) {
1245 if (down_trylock (&chip->open_sem)) {
1246 DPRINTK ("%s: returning -EAGAIN\n", __FUNCTION__);
1247 return -EAGAIN;
1248 }
1249 }
1250 else {
1251 if (down_interruptible (&chip->open_sem)) {
1252 DPRINTK ("%s: returning -ERESTARTSYS\n", __FUNCTION__);
1253 return -ERESTARTSYS;
1254 }
1255 }
1256
1257 file->private_data = forte;
1258
1259 DPRINTK ("%s: dsp opened by %d\n", __FUNCTION__, current->pid);
1260
1261 if (file->f_mode & FMODE_WRITE)
1262 forte_channel_init (forte, &forte->play);
1263
1264 if (file->f_mode & FMODE_READ)
1265 forte_channel_init (forte, &forte->rec);
1266
1267 return nonseekable_open(inode, file);
1268}
1269
1270
1271/**
1272 * forte_dsp_release:
1273 */
1274
1275static int
1276forte_dsp_release (struct inode *inode, struct file *file)
1277{
1278 struct forte_chip *chip = file->private_data;
1279 int ret = 0;
1280
1281 DPRINTK ("%s: chip @ %p\n", __FUNCTION__, chip);
1282
1283 if (file->f_mode & FMODE_WRITE) {
1284 forte_channel_drain (&chip->play);
1285
1286 spin_lock_irq (&chip->lock);
1287
1288 forte_channel_free (chip, &chip->play);
1289
1290 spin_unlock_irq (&chip->lock);
1291 }
1292
1293 if (file->f_mode & FMODE_READ) {
1294 while (chip->rec.filled_frags > 0)
1295 interruptible_sleep_on (&chip->rec.wait);
1296
1297 spin_lock_irq (&chip->lock);
1298
1299 forte_channel_stop (&chip->rec);
1300 forte_channel_free (chip, &chip->rec);
1301
1302 spin_unlock_irq (&chip->lock);
1303 }
1304
1305 up (&chip->open_sem);
1306
1307 return ret;
1308}
1309
1310
1311/**
1312 * forte_dsp_poll:
1313 *
1314 */
1315
1316static unsigned int
1317forte_dsp_poll (struct file *file, struct poll_table_struct *wait)
1318{
1319 struct forte_chip *chip;
1320 struct forte_channel *channel;
1321 unsigned int mask = 0;
1322
1323 chip = file->private_data;
1324
1325 if (file->f_mode & FMODE_WRITE) {
1326 channel = &chip->play;
1327
1328 if (channel->active)
1329 poll_wait (file, &channel->wait, wait);
1330
1331 spin_lock_irq (&chip->lock);
1332
1333 if (channel->frag_num - channel->filled_frags > 0)
1334 mask |= POLLOUT | POLLWRNORM;
1335
1336 spin_unlock_irq (&chip->lock);
1337 }
1338
1339 if (file->f_mode & FMODE_READ) {
1340 channel = &chip->rec;
1341
1342 if (channel->active)
1343 poll_wait (file, &channel->wait, wait);
1344
1345 spin_lock_irq (&chip->lock);
1346
1347 if (channel->filled_frags > 0)
1348 mask |= POLLIN | POLLRDNORM;
1349
1350 spin_unlock_irq (&chip->lock);
1351 }
1352
1353 return mask;
1354}
1355
1356
1357/**
1358 * forte_dsp_mmap:
1359 */
1360
1361static int
1362forte_dsp_mmap (struct file *file, struct vm_area_struct *vma)
1363{
1364 struct forte_chip *chip;
1365 struct forte_channel *channel;
1366 unsigned long size;
1367 int ret;
1368
1369 chip = file->private_data;
1370
1371 DPRINTK ("%s: start %lXh, size %ld, pgoff %ld\n", __FUNCTION__,
1372 vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_pgoff);
1373
1374 spin_lock_irq (&chip->lock);
1375
1376 if (vma->vm_flags & VM_WRITE && chip->play.active) {
1377 ret = -EBUSY;
1378 goto out;
1379 }
1380
1381 if (vma->vm_flags & VM_READ && chip->rec.active) {
1382 ret = -EBUSY;
1383 goto out;
1384 }
1385
1386 if (file->f_mode & FMODE_WRITE)
1387 channel = &chip->play;
1388 else if (file->f_mode & FMODE_READ)
1389 channel = &chip->rec;
1390 else {
1391 ret = -EINVAL;
1392 goto out;
1393 }
1394
1395 forte_channel_prep (channel);
1396 channel->mapped = 1;
1397
1398 if (vma->vm_pgoff != 0) {
1399 ret = -EINVAL;
1400 goto out;
1401 }
1402
1403 size = vma->vm_end - vma->vm_start;
1404
1405 if (size > channel->buf_pages * PAGE_SIZE) {
1406 DPRINTK ("%s: size (%ld) > buf_sz (%d) \n", __FUNCTION__,
1407 size, channel->buf_sz);
1408 ret = -EINVAL;
1409 goto out;
1410 }
1411
1412 if (remap_pfn_range(vma, vma->vm_start,
1413 virt_to_phys(channel->buf) >> PAGE_SHIFT,
1414 size, vma->vm_page_prot)) {
1415 DPRINTK ("%s: remap el a no worko\n", __FUNCTION__);
1416 ret = -EAGAIN;
1417 goto out;
1418 }
1419
1420 ret = 0;
1421
1422 out:
1423 spin_unlock_irq (&chip->lock);
1424 return ret;
1425}
1426
1427
1428/**
1429 * forte_dsp_write:
1430 */
1431
1432static ssize_t
1433forte_dsp_write (struct file *file, const char __user *buffer, size_t bytes,
1434 loff_t *ppos)
1435{
1436 struct forte_chip *chip;
1437 struct forte_channel *channel;
1438 unsigned int i = bytes, sz = 0;
1439 unsigned long flags;
1440
1441 if (!access_ok (VERIFY_READ, buffer, bytes))
1442 return -EFAULT;
1443
1444 chip = (struct forte_chip *) file->private_data;
1445
1446 if (!chip)
1447 BUG();
1448
1449 channel = &chip->play;
1450
1451 if (!channel)
1452 BUG();
1453
1454 spin_lock_irqsave (&chip->lock, flags);
1455
1456 /* Set up buffers with the right fragment size */
1457 forte_channel_prep (channel);
1458
1459 while (i) {
1460 /* All fragment buffers in use -> wait */
1461 if (channel->frag_num - channel->filled_frags == 0) {
1462 DECLARE_WAITQUEUE (wait, current);
1463
1464 /* For trigger or non-blocking operation, get out */
1465 if (chip->trigger || file->f_flags & O_NONBLOCK) {
1466 spin_unlock_irqrestore (&chip->lock, flags);
1467 return -EAGAIN;
1468 }
1469
1470 /* Otherwise wait for buffers */
1471 add_wait_queue (&channel->wait, &wait);
1472
1473 for (;;) {
1474 spin_unlock_irqrestore (&chip->lock, flags);
1475
1476 set_current_state (TASK_INTERRUPTIBLE);
1477 schedule();
1478
1479 spin_lock_irqsave (&chip->lock, flags);
1480
1481 if (channel->frag_num - channel->filled_frags)
1482 break;
1483 }
1484
1485 remove_wait_queue (&channel->wait, &wait);
1486 set_current_state (TASK_RUNNING);
1487
1488 if (signal_pending (current)) {
1489 spin_unlock_irqrestore (&chip->lock, flags);
1490 return -ERESTARTSYS;
1491 }
1492 }
1493
1494 if (channel->residue)
1495 sz = channel->residue;
1496 else if (i > channel->frag_sz)
1497 sz = channel->frag_sz;
1498 else
1499 sz = i;
1500
1501 spin_unlock_irqrestore (&chip->lock, flags);
1502
1503 if (copy_from_user ((void *) channel->buf + channel->swptr, buffer, sz))
1504 return -EFAULT;
1505
1506 spin_lock_irqsave (&chip->lock, flags);
1507
1508 /* Advance software pointer */
1509 buffer += sz;
1510 channel->swptr += sz;
1511 channel->swptr %= channel->buf_sz;
1512 i -= sz;
1513
1514 /* Only bump filled_frags if a full fragment has been written */
1515 if (channel->swptr % channel->frag_sz == 0) {
1516 channel->filled_frags++;
1517 channel->residue = 0;
1518 }
1519 else
1520 channel->residue = channel->frag_sz - sz;
1521
1522 /* If playback isn't active, start it */
1523 if (channel->active == 0 && chip->trigger == 0)
1524 forte_channel_start (channel);
1525 }
1526
1527 spin_unlock_irqrestore (&chip->lock, flags);
1528
1529 return bytes - i;
1530}
1531
1532
1533/**
1534 * forte_dsp_read:
1535 */
1536
1537static ssize_t
1538forte_dsp_read (struct file *file, char __user *buffer, size_t bytes,
1539 loff_t *ppos)
1540{
1541 struct forte_chip *chip;
1542 struct forte_channel *channel;
1543 unsigned int i = bytes, sz;
1544 unsigned long flags;
1545
1546 if (!access_ok (VERIFY_WRITE, buffer, bytes))
1547 return -EFAULT;
1548
1549 chip = (struct forte_chip *) file->private_data;
1550
1551 if (!chip)
1552 BUG();
1553
1554 channel = &chip->rec;
1555
1556 if (!channel)
1557 BUG();
1558
1559 spin_lock_irqsave (&chip->lock, flags);
1560
1561 /* Set up buffers with the right fragment size */
1562 forte_channel_prep (channel);
1563
1564 /* Start recording */
1565 if (!chip->trigger)
1566 forte_channel_start (channel);
1567
1568 while (i) {
1569 /* No fragment buffers in use -> wait */
1570 if (channel->filled_frags == 0) {
1571 DECLARE_WAITQUEUE (wait, current);
1572
1573 /* For trigger mode operation, get out */
1574 if (chip->trigger) {
1575 spin_unlock_irqrestore (&chip->lock, flags);
1576 return -EAGAIN;
1577 }
1578
1579 add_wait_queue (&channel->wait, &wait);
1580
1581 for (;;) {
1582 if (channel->active == 0)
1583 break;
1584
1585 if (channel->filled_frags)
1586 break;
1587
1588 spin_unlock_irqrestore (&chip->lock, flags);
1589
1590 set_current_state (TASK_INTERRUPTIBLE);
1591 schedule();
1592
1593 spin_lock_irqsave (&chip->lock, flags);
1594 }
1595
1596 set_current_state (TASK_RUNNING);
1597 remove_wait_queue (&channel->wait, &wait);
1598 }
1599
1600 if (i > channel->frag_sz)
1601 sz = channel->frag_sz;
1602 else
1603 sz = i;
1604
1605 spin_unlock_irqrestore (&chip->lock, flags);
1606
1607 if (copy_to_user (buffer, (void *)channel->buf+channel->swptr, sz)) {
1608 DPRINTK ("%s: copy_to_user failed\n", __FUNCTION__);
1609 return -EFAULT;
1610 }
1611
1612 spin_lock_irqsave (&chip->lock, flags);
1613
1614 /* Advance software pointer */
1615 buffer += sz;
1616 if (channel->filled_frags > 0)
1617 channel->filled_frags--;
1618 channel->swptr += channel->frag_sz;
1619 channel->swptr %= channel->buf_sz;
1620 i -= sz;
1621 }
1622
1623 spin_unlock_irqrestore (&chip->lock, flags);
1624
1625 return bytes - i;
1626}
1627
1628
1629static struct file_operations forte_dsp_fops = {
1630 .owner = THIS_MODULE,
1631 .llseek = &no_llseek,
1632 .read = &forte_dsp_read,
1633 .write = &forte_dsp_write,
1634 .poll = &forte_dsp_poll,
1635 .ioctl = &forte_dsp_ioctl,
1636 .open = &forte_dsp_open,
1637 .release = &forte_dsp_release,
1638 .mmap = &forte_dsp_mmap,
1639};
1640
1641
1642/* Common ------------------------------------------------------------------ */
1643
1644
1645/**
1646 * forte_interrupt:
1647 */
1648
1649static irqreturn_t
1650forte_interrupt (int irq, void *dev_id, struct pt_regs *regs)
1651{
1652 struct forte_chip *chip = dev_id;
1653 struct forte_channel *channel = NULL;
1654 u16 status, count;
1655
1656 status = inw (chip->iobase + FORTE_IRQ_STATUS);
1657
1658 /* If this is not for us, get outta here ASAP */
1659 if ((status & (FORTE_IRQ_PLAYBACK | FORTE_IRQ_CAPTURE)) == 0)
1660 return IRQ_NONE;
1661
1662 if (status & FORTE_IRQ_PLAYBACK) {
1663 channel = &chip->play;
1664
1665 spin_lock (&chip->lock);
1666
1667 if (channel->frag_sz == 0)
1668 goto pack;
1669
1670 /* Declare a fragment done */
1671 if (channel->filled_frags > 0)
1672 channel->filled_frags--;
1673 channel->bytes += channel->frag_sz;
1674 channel->nr_irqs++;
1675
1676 /* Flip-flop between buffer I and II */
1677 channel->next_buf ^= 1;
1678
1679 /* Advance hardware pointer by fragment size and wrap around */
1680 channel->hwptr += channel->frag_sz;
1681 channel->hwptr %= channel->buf_sz;
1682
1683 /* Buffer I or buffer II BAR */
1684 outl (channel->buf_handle + channel->hwptr,
1685 channel->next_buf == 0 ?
1686 channel->iobase + FORTE_PLY_BUF1 :
1687 channel->iobase + FORTE_PLY_BUF2);
1688
1689 /* If the currently playing fragment is last, schedule pause */
1690 if (channel->filled_frags == 1)
1691 forte_channel_pause (channel);
1692
1693 pack:
1694 /* Acknowledge interrupt */
1695 outw (FORTE_IRQ_PLAYBACK, chip->iobase + FORTE_IRQ_STATUS);
1696
1697 if (waitqueue_active (&channel->wait))
1698 wake_up_all (&channel->wait);
1699
1700 spin_unlock (&chip->lock);
1701 }
1702
1703 if (status & FORTE_IRQ_CAPTURE) {
1704 channel = &chip->rec;
1705 spin_lock (&chip->lock);
1706
1707 /* One fragment filled */
1708 channel->filled_frags++;
1709
1710 /* Get # of completed bytes */
1711 count = inw (channel->iobase + FORTE_PLY_COUNT) + 1;
1712
1713 if (count == 0) {
1714 DPRINTK ("%s: last, filled_frags = %d\n", __FUNCTION__,
1715 channel->filled_frags);
1716 channel->filled_frags = 0;
1717 goto rack;
1718 }
1719
1720 /* Buffer I or buffer II BAR */
1721 outl (channel->buf_handle + channel->hwptr,
1722 channel->next_buf == 0 ?
1723 channel->iobase + FORTE_PLY_BUF1 :
1724 channel->iobase + FORTE_PLY_BUF2);
1725
1726 /* Flip-flop between buffer I and II */
1727 channel->next_buf ^= 1;
1728
1729 /* Advance hardware pointer by fragment size and wrap around */
1730 channel->hwptr += channel->frag_sz;
1731 channel->hwptr %= channel->buf_sz;
1732
1733 /* Out of buffers */
1734 if (channel->filled_frags == channel->frag_num - 1)
1735 forte_channel_stop (channel);
1736 rack:
1737 /* Acknowledge interrupt */
1738 outw (FORTE_IRQ_CAPTURE, chip->iobase + FORTE_IRQ_STATUS);
1739
1740 spin_unlock (&chip->lock);
1741
1742 if (waitqueue_active (&channel->wait))
1743 wake_up_all (&channel->wait);
1744 }
1745
1746 return IRQ_HANDLED;
1747}
1748
1749
1750/**
1751 * forte_proc_read:
1752 */
1753
1754static int
1755forte_proc_read (char *page, char **start, off_t off, int count,
1756 int *eof, void *data)
1757{
1758 int i = 0, p_rate, p_chan, r_rate;
1759 unsigned short p_reg, r_reg;
1760
1761 i += sprintf (page, "ForteMedia FM801 OSS Lite driver\n%s\n \n",
1762 DRIVER_VERSION);
1763
1764 if (!forte->iobase)
1765 return i;
1766
1767 p_rate = p_chan = -1;
1768 p_reg = inw (forte->iobase + FORTE_PLY_CTRL);
1769 p_rate = (p_reg >> 8) & 15;
1770 p_chan = (p_reg >> 12) & 3;
1771
1772 if (p_rate >= 0 || p_rate <= 10)
1773 p_rate = rates[p_rate];
1774
1775 if (p_chan >= 0 || p_chan <= 2)
1776 p_chan = channels[p_chan];
1777
1778 r_rate = -1;
1779 r_reg = inw (forte->iobase + FORTE_CAP_CTRL);
1780 r_rate = (r_reg >> 8) & 15;
1781
1782 if (r_rate >= 0 || r_rate <= 10)
1783 r_rate = rates[r_rate];
1784
1785 i += sprintf (page + i,
1786 " Playback Capture\n"
1787 "FIFO empty : %-3s %-3s\n"
1788 "Buf1 Last : %-3s %-3s\n"
1789 "Buf2 Last : %-3s %-3s\n"
1790 "Started : %-3s %-3s\n"
1791 "Paused : %-3s %-3s\n"
1792 "Immed Stop : %-3s %-3s\n"
1793 "Rate : %-5d %-5d\n"
1794 "Channels : %-5d -\n"
1795 "16-bit : %-3s %-3s\n"
1796 "Stereo : %-3s %-3s\n"
1797 " \n"
1798 "Buffer Sz : %-6d %-6d\n"
1799 "Frag Sz : %-6d %-6d\n"
1800 "Frag Num : %-6d %-6d\n"
1801 "Frag msecs : %-6d %-6d\n"
1802 "Used Frags : %-6d %-6d\n"
1803 "Mapped : %-3s %-3s\n",
1804 p_reg & 1<<0 ? "yes" : "no",
1805 r_reg & 1<<0 ? "yes" : "no",
1806 p_reg & 1<<1 ? "yes" : "no",
1807 r_reg & 1<<1 ? "yes" : "no",
1808 p_reg & 1<<2 ? "yes" : "no",
1809 r_reg & 1<<2 ? "yes" : "no",
1810 p_reg & 1<<5 ? "yes" : "no",
1811 r_reg & 1<<5 ? "yes" : "no",
1812 p_reg & 1<<6 ? "yes" : "no",
1813 r_reg & 1<<6 ? "yes" : "no",
1814 p_reg & 1<<7 ? "yes" : "no",
1815 r_reg & 1<<7 ? "yes" : "no",
1816 p_rate, r_rate,
1817 p_chan,
1818 p_reg & 1<<14 ? "yes" : "no",
1819 r_reg & 1<<14 ? "yes" : "no",
1820 p_reg & 1<<15 ? "yes" : "no",
1821 r_reg & 1<<15 ? "yes" : "no",
1822 forte->play.buf_sz, forte->rec.buf_sz,
1823 forte->play.frag_sz, forte->rec.frag_sz,
1824 forte->play.frag_num, forte->rec.frag_num,
1825 forte->play.frag_msecs, forte->rec.frag_msecs,
1826 forte->play.filled_frags, forte->rec.filled_frags,
1827 forte->play.mapped ? "yes" : "no",
1828 forte->rec.mapped ? "yes" : "no"
1829 );
1830
1831 return i;
1832}
1833
1834
1835/**
1836 * forte_proc_init:
1837 *
1838 * Creates driver info entries in /proc
1839 */
1840
1841static int __init
1842forte_proc_init (void)
1843{
1844 if (!proc_mkdir ("driver/forte", NULL))
1845 return -EIO;
1846
1847 if (!create_proc_read_entry ("driver/forte/chip", 0, NULL, forte_proc_read, forte)) {
1848 remove_proc_entry ("driver/forte", NULL);
1849 return -EIO;
1850 }
1851
1852 if (!create_proc_read_entry("driver/forte/ac97", 0, NULL, ac97_read_proc, forte->ac97)) {
1853 remove_proc_entry ("driver/forte/chip", NULL);
1854 remove_proc_entry ("driver/forte", NULL);
1855 return -EIO;
1856 }
1857
1858 return 0;
1859}
1860
1861
1862/**
1863 * forte_proc_remove:
1864 *
1865 * Removes driver info entries in /proc
1866 */
1867
1868static void
1869forte_proc_remove (void)
1870{
1871 remove_proc_entry ("driver/forte/ac97", NULL);
1872 remove_proc_entry ("driver/forte/chip", NULL);
1873 remove_proc_entry ("driver/forte", NULL);
1874}
1875
1876
1877/**
1878 * forte_chip_init:
1879 * @chip: Chip instance to initialize
1880 *
1881 * Description:
1882 * Resets chip, configures codec and registers the driver with
1883 * the sound subsystem.
1884 *
1885 * Press and hold Start for 8 secs, then switch on Run
1886 * and hold for 4 seconds. Let go of Start. Numbers
1887 * assume a properly oiled TWG.
1888 */
1889
1890static int __devinit
1891forte_chip_init (struct forte_chip *chip)
1892{
1893 u8 revision;
1894 u16 cmdw;
1895 struct ac97_codec *codec;
1896
1897 pci_read_config_byte (chip->pci_dev, PCI_REVISION_ID, &revision);
1898
1899 if (revision >= 0xB1) {
1900 chip->multichannel = 1;
1901 printk (KERN_INFO PFX "Multi-channel device detected.\n");
1902 }
1903
1904 /* Reset chip */
1905 outw (FORTE_CC_CODEC_RESET | FORTE_CC_AC97_RESET,
1906 chip->iobase + FORTE_CODEC_CTRL);
1907 udelay(100);
1908 outw (0, chip->iobase + FORTE_CODEC_CTRL);
1909
1910 /* Request read from AC97 */
1911 outw (FORTE_AC97_READ | (0 << FORTE_AC97_ADDR_SHIFT),
1912 chip->iobase + FORTE_AC97_CMD);
1913 mdelay(750);
1914
1915 if ((inw (chip->iobase + FORTE_AC97_CMD) & (3<<8)) != (1<<8)) {
1916 printk (KERN_INFO PFX "AC97 codec not responding");
1917 return -EIO;
1918 }
1919
1920 /* Init volume */
1921 outw (0x0808, chip->iobase + FORTE_PCM_VOL);
1922 outw (0x9f1f, chip->iobase + FORTE_FM_VOL);
1923 outw (0x8808, chip->iobase + FORTE_I2S_VOL);
1924
1925 /* I2S control - I2S mode */
1926 outw (0x0003, chip->iobase + FORTE_I2S_MODE);
1927
1928 /* Interrupt setup - unmask PLAYBACK & CAPTURE */
1929 cmdw = inw (chip->iobase + FORTE_IRQ_MASK);
1930 cmdw &= ~0x0003;
1931 outw (cmdw, chip->iobase + FORTE_IRQ_MASK);
1932
1933 /* Interrupt clear */
1934 outw (FORTE_IRQ_PLAYBACK|FORTE_IRQ_CAPTURE,
1935 chip->iobase + FORTE_IRQ_STATUS);
1936
1937 /* Set up the AC97 codec */
1938 if ((codec = ac97_alloc_codec()) == NULL)
1939 return -ENOMEM;
1940 codec->private_data = chip;
1941 codec->codec_read = forte_ac97_read;
1942 codec->codec_write = forte_ac97_write;
1943 codec->id = 0;
1944
1945 if (ac97_probe_codec (codec) == 0) {
1946 printk (KERN_ERR PFX "codec probe failed\n");
1947 ac97_release_codec(codec);
1948 return -1;
1949 }
1950
1951 /* Register mixer */
1952 if ((codec->dev_mixer =
1953 register_sound_mixer (&forte_mixer_fops, -1)) < 0) {
1954 printk (KERN_ERR PFX "couldn't register mixer!\n");
1955 ac97_release_codec(codec);
1956 return -1;
1957 }
1958
1959 chip->ac97 = codec;
1960
1961 /* Register DSP */
1962 if ((chip->dsp = register_sound_dsp (&forte_dsp_fops, -1) ) < 0) {
1963 printk (KERN_ERR PFX "couldn't register dsp!\n");
1964 return -1;
1965 }
1966
1967 /* Register with /proc */
1968 if (forte_proc_init()) {
1969 printk (KERN_ERR PFX "couldn't add entries to /proc!\n");
1970 return -1;
1971 }
1972
1973 return 0;
1974}
1975
1976
1977/**
1978 * forte_probe:
1979 * @pci_dev: PCI struct for probed device
1980 * @pci_id:
1981 *
1982 * Description:
1983 * Allocates chip instance, I/O region, and IRQ
1984 */
1985static int __init
1986forte_probe (struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
1987{
1988 struct forte_chip *chip;
1989 int ret = 0;
1990
1991 /* FIXME: Support more than one chip */
1992 if (found++)
1993 return -EIO;
1994
1995 /* Ignition */
1996 if (pci_enable_device (pci_dev))
1997 return -EIO;
1998
1999 pci_set_master (pci_dev);
2000
2001 /* Allocate chip instance and configure */
2002 forte = (struct forte_chip *)
2003 kmalloc (sizeof (struct forte_chip), GFP_KERNEL);
2004 chip = forte;
2005
2006 if (chip == NULL) {
2007 printk (KERN_WARNING PFX "Out of memory");
2008 return -ENOMEM;
2009 }
2010
2011 memset (chip, 0, sizeof (struct forte_chip));
2012 chip->pci_dev = pci_dev;
2013
2014 init_MUTEX(&chip->open_sem);
2015 spin_lock_init (&chip->lock);
2016 spin_lock_init (&chip->ac97_lock);
2017
2018 if (! request_region (pci_resource_start (pci_dev, 0),
2019 pci_resource_len (pci_dev, 0), DRIVER_NAME)) {
2020 printk (KERN_WARNING PFX "Unable to reserve I/O space");
2021 ret = -ENOMEM;
2022 goto error;
2023 }
2024
2025 chip->iobase = pci_resource_start (pci_dev, 0);
2026 chip->irq = pci_dev->irq;
2027
2028 if (request_irq (chip->irq, forte_interrupt, SA_SHIRQ, DRIVER_NAME,
2029 chip)) {
2030 printk (KERN_WARNING PFX "Unable to reserve IRQ");
2031 ret = -EIO;
2032 goto error;
2033 }
2034
2035 pci_set_drvdata (pci_dev, chip);
2036
2037 printk (KERN_INFO PFX "FM801 chip found at 0x%04lX-0x%04lX IRQ %u\n",
2038 chip->iobase, pci_resource_end (pci_dev, 0), chip->irq);
2039
2040 /* Power it up */
2041 if ((ret = forte_chip_init (chip)) == 0)
2042 return 0;
2043
2044 error:
2045 if (chip->irq)
2046 free_irq (chip->irq, chip);
2047
2048 if (chip->iobase)
2049 release_region (pci_resource_start (pci_dev, 0),
2050 pci_resource_len (pci_dev, 0));
2051
2052 kfree (chip);
2053
2054 return ret;
2055}
2056
2057
2058/**
2059 * forte_remove:
2060 * @pci_dev: PCI device to unclaim
2061 *
2062 */
2063
2064static void
2065forte_remove (struct pci_dev *pci_dev)
2066{
2067 struct forte_chip *chip = pci_get_drvdata (pci_dev);
2068
2069 if (chip == NULL)
2070 return;
2071
2072 /* Turn volume down to avoid popping */
2073 outw (0x1f1f, chip->iobase + FORTE_PCM_VOL);
2074 outw (0x1f1f, chip->iobase + FORTE_FM_VOL);
2075 outw (0x1f1f, chip->iobase + FORTE_I2S_VOL);
2076
2077 forte_proc_remove();
2078 free_irq (chip->irq, chip);
2079 release_region (chip->iobase, pci_resource_len (pci_dev, 0));
2080
2081 unregister_sound_dsp (chip->dsp);
2082 unregister_sound_mixer (chip->ac97->dev_mixer);
2083 ac97_release_codec(chip->ac97);
2084 kfree (chip);
2085
2086 printk (KERN_INFO PFX "driver released\n");
2087}
2088
2089
2090static struct pci_device_id forte_pci_ids[] = {
2091 { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
2092 { 0, }
2093};
2094
2095
2096static struct pci_driver forte_pci_driver = {
2097 .name = DRIVER_NAME,
2098 .id_table = forte_pci_ids,
2099 .probe = forte_probe,
2100 .remove = forte_remove,
2101
2102};
2103
2104
2105/**
2106 * forte_init_module:
2107 *
2108 */
2109
2110static int __init
2111forte_init_module (void)
2112{
2113 printk (KERN_INFO PFX DRIVER_VERSION "\n");
2114
2115 return pci_register_driver (&forte_pci_driver);
2116}
2117
2118
2119/**
2120 * forte_cleanup_module:
2121 *
2122 */
2123
2124static void __exit
2125forte_cleanup_module (void)
2126{
2127 pci_unregister_driver (&forte_pci_driver);
2128}
2129
2130
2131module_init(forte_init_module);
2132module_exit(forte_cleanup_module);
2133
2134MODULE_AUTHOR("Martin K. Petersen <mkp@mkp.net>");
2135MODULE_DESCRIPTION("ForteMedia FM801 OSS Driver");
2136MODULE_LICENSE("GPL");
2137MODULE_DEVICE_TABLE (pci, forte_pci_ids);
diff --git a/sound/oss/gus.h b/sound/oss/gus.h
new file mode 100644
index 000000000000..3d5271baf042
--- /dev/null
+++ b/sound/oss/gus.h
@@ -0,0 +1,24 @@
1
2#include "ad1848.h"
3
4/* From gus_card.c */
5int gus_set_midi_irq(int num);
6irqreturn_t gusintr(int irq, void *dev_id, struct pt_regs * dummy);
7
8/* From gus_wave.c */
9int gus_wave_detect(int baseaddr);
10void gus_wave_init(struct address_info *hw_config);
11void gus_wave_unload (struct address_info *hw_config);
12void gus_voice_irq(void);
13void gus_write8(int reg, unsigned int data);
14void guswave_dma_irq(void);
15void gus_delay(void);
16int gus_default_mixer_ioctl (int dev, unsigned int cmd, void __user *arg);
17void gus_timer_command (unsigned int addr, unsigned int val);
18
19/* From gus_midi.c */
20void gus_midi_init(struct address_info *hw_config);
21void gus_midi_interrupt(int dummy);
22
23/* From ics2101.c */
24int ics2101_mixer_init(void);
diff --git a/sound/oss/gus_card.c b/sound/oss/gus_card.c
new file mode 100644
index 000000000000..dbb29771e2bb
--- /dev/null
+++ b/sound/oss/gus_card.c
@@ -0,0 +1,293 @@
1/*
2 * sound/gus_card.c
3 *
4 * Detection routine for the Gravis Ultrasound.
5 *
6 * Copyright (C) by Hannu Savolainen 1993-1997
7 *
8 *
9 * Frank van de Pol : Fixed GUS MAX interrupt handling, enabled simultanious
10 * usage of CS4231A codec, GUS wave and MIDI for GUS MAX.
11 * Christoph Hellwig: Adapted to module_init/module_exit, simple cleanups.
12 *
13 * Status:
14 * Tested...
15 */
16
17
18#include <linux/config.h>
19#include <linux/init.h>
20#include <linux/interrupt.h>
21#include <linux/module.h>
22
23#include "sound_config.h"
24
25#include "gus.h"
26#include "gus_hw.h"
27
28irqreturn_t gusintr(int irq, void *dev_id, struct pt_regs *dummy);
29
30int gus_base = 0, gus_irq = 0, gus_dma = 0;
31int gus_no_wave_dma = 0;
32extern int gus_wave_volume;
33extern int gus_pcm_volume;
34extern int have_gus_max;
35int gus_pnp_flag = 0;
36#ifdef CONFIG_SOUND_GUS16
37static int db16; /* Has a Gus16 AD1848 on it */
38#endif
39
40static void __init attach_gus(struct address_info *hw_config)
41{
42 gus_wave_init(hw_config);
43
44 if (sound_alloc_dma(hw_config->dma, "GUS"))
45 printk(KERN_ERR "gus_card.c: Can't allocate DMA channel %d\n", hw_config->dma);
46 if (hw_config->dma2 != -1 && hw_config->dma2 != hw_config->dma)
47 if (sound_alloc_dma(hw_config->dma2, "GUS(2)"))
48 printk(KERN_ERR "gus_card.c: Can't allocate DMA channel %d\n", hw_config->dma2);
49 gus_midi_init(hw_config);
50 if(request_irq(hw_config->irq, gusintr, 0, "Gravis Ultrasound", hw_config)<0)
51 printk(KERN_ERR "gus_card.c: Unable to allocate IRQ %d\n", hw_config->irq);
52
53 return;
54}
55
56static int __init probe_gus(struct address_info *hw_config)
57{
58 int irq;
59 int io_addr;
60
61 if (hw_config->card_subtype == 1)
62 gus_pnp_flag = 1;
63
64 irq = hw_config->irq;
65
66 if (hw_config->card_subtype == 0) /* GUS/MAX/ACE */
67 if (irq != 3 && irq != 5 && irq != 7 && irq != 9 &&
68 irq != 11 && irq != 12 && irq != 15)
69 {
70 printk(KERN_ERR "GUS: Unsupported IRQ %d\n", irq);
71 return 0;
72 }
73 if (gus_wave_detect(hw_config->io_base))
74 return 1;
75
76#ifndef EXCLUDE_GUS_IODETECT
77
78 /*
79 * Look at the possible base addresses (0x2X0, X=1, 2, 3, 4, 5, 6)
80 */
81
82 for (io_addr = 0x210; io_addr <= 0x260; io_addr += 0x10) {
83 if (io_addr == hw_config->io_base) /* Already tested */
84 continue;
85 if (gus_wave_detect(io_addr)) {
86 hw_config->io_base = io_addr;
87 return 1;
88 }
89 }
90#endif
91
92 printk("NO GUS card found !\n");
93 return 0;
94}
95
96static void __exit unload_gus(struct address_info *hw_config)
97{
98 DDB(printk("unload_gus(%x)\n", hw_config->io_base));
99
100 gus_wave_unload(hw_config);
101
102 release_region(hw_config->io_base, 16);
103 release_region(hw_config->io_base + 0x100, 12); /* 0x10c-> is MAX */
104 free_irq(hw_config->irq, hw_config);
105
106 sound_free_dma(hw_config->dma);
107
108 if (hw_config->dma2 != -1 && hw_config->dma2 != hw_config->dma)
109 sound_free_dma(hw_config->dma2);
110}
111
112irqreturn_t gusintr(int irq, void *dev_id, struct pt_regs *dummy)
113{
114 unsigned char src;
115 extern int gus_timer_enabled;
116 int handled = 0;
117
118#ifdef CONFIG_SOUND_GUSMAX
119 if (have_gus_max) {
120 struct address_info *hw_config = dev_id;
121 adintr(irq, (void *)hw_config->slots[1], NULL);
122 }
123#endif
124#ifdef CONFIG_SOUND_GUS16
125 if (db16) {
126 struct address_info *hw_config = dev_id;
127 adintr(irq, (void *)hw_config->slots[3], NULL);
128 }
129#endif
130
131 while (1)
132 {
133 if (!(src = inb(u_IrqStatus)))
134 break;
135 handled = 1;
136 if (src & DMA_TC_IRQ)
137 {
138 guswave_dma_irq();
139 }
140 if (src & (MIDI_TX_IRQ | MIDI_RX_IRQ))
141 {
142 gus_midi_interrupt(0);
143 }
144 if (src & (GF1_TIMER1_IRQ | GF1_TIMER2_IRQ))
145 {
146 if (gus_timer_enabled)
147 sound_timer_interrupt();
148 gus_write8(0x45, 0); /* Ack IRQ */
149 gus_timer_command(4, 0x80); /* Reset IRQ flags */
150 }
151 if (src & (WAVETABLE_IRQ | ENVELOPE_IRQ))
152 gus_voice_irq();
153 }
154 return IRQ_RETVAL(handled);
155}
156
157/*
158 * Some extra code for the 16 bit sampling option
159 */
160
161#ifdef CONFIG_SOUND_GUS16
162
163static int __init init_gus_db16(struct address_info *hw_config)
164{
165 struct resource *ports;
166
167 ports = request_region(hw_config->io_base, 4, "ad1848");
168 if (!ports)
169 return 0;
170
171 if (!ad1848_detect(ports, NULL, hw_config->osp)) {
172 release_region(hw_config->io_base, 4);
173 return 0;
174 }
175
176 gus_pcm_volume = 100;
177 gus_wave_volume = 90;
178
179 hw_config->slots[3] = ad1848_init("GUS 16 bit sampling", ports,
180 hw_config->irq,
181 hw_config->dma,
182 hw_config->dma, 0,
183 hw_config->osp,
184 THIS_MODULE);
185 return 1;
186}
187
188static void __exit unload_gus_db16(struct address_info *hw_config)
189{
190
191 ad1848_unload(hw_config->io_base,
192 hw_config->irq,
193 hw_config->dma,
194 hw_config->dma, 0);
195 sound_unload_audiodev(hw_config->slots[3]);
196}
197#endif
198
199#ifdef CONFIG_SOUND_GUS16
200static int gus16;
201#endif
202#ifdef CONFIG_SOUND_GUSMAX
203static int no_wave_dma; /* Set if no dma is to be used for the
204 wave table (GF1 chip) */
205#endif
206
207
208/*
209 * Note DMA2 of -1 has the right meaning in the GUS driver as well
210 * as here.
211 */
212
213static struct address_info cfg;
214
215static int __initdata io = -1;
216static int __initdata irq = -1;
217static int __initdata dma = -1;
218static int __initdata dma16 = -1; /* Set this for modules that need it */
219static int __initdata type = 0; /* 1 for PnP */
220
221module_param(io, int, 0);
222module_param(irq, int, 0);
223module_param(dma, int, 0);
224module_param(dma16, int, 0);
225module_param(type, int, 0);
226#ifdef CONFIG_SOUND_GUSMAX
227module_param(no_wave_dma, int, 0);
228#endif
229#ifdef CONFIG_SOUND_GUS16
230module_param(db16, int, 0);
231module_param(gus16, int, 0);
232#endif
233MODULE_LICENSE("GPL");
234
235static int __init init_gus(void)
236{
237 printk(KERN_INFO "Gravis Ultrasound audio driver Copyright (C) by Hannu Savolainen 1993-1996\n");
238
239 cfg.io_base = io;
240 cfg.irq = irq;
241 cfg.dma = dma;
242 cfg.dma2 = dma16;
243 cfg.card_subtype = type;
244#ifdef CONFIG_SOUND_GUSMAX
245 gus_no_wave_dma = no_wave_dma;
246#endif
247
248 if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
249 printk(KERN_ERR "I/O, IRQ, and DMA are mandatory\n");
250 return -EINVAL;
251 }
252
253#ifdef CONFIG_SOUND_GUS16
254 if (gus16 && init_gus_db16(&cfg))
255 db16 = 1;
256#endif
257 if (!probe_gus(&cfg))
258 return -ENODEV;
259 attach_gus(&cfg);
260
261 return 0;
262}
263
264static void __exit cleanup_gus(void)
265{
266#ifdef CONFIG_SOUND_GUS16
267 if (db16)
268 unload_gus_db16(&cfg);
269#endif
270 unload_gus(&cfg);
271}
272
273module_init(init_gus);
274module_exit(cleanup_gus);
275
276#ifndef MODULE
277static int __init setup_gus(char *str)
278{
279 /* io, irq, dma, dma2 */
280 int ints[5];
281
282 str = get_options(str, ARRAY_SIZE(ints), ints);
283
284 io = ints[1];
285 irq = ints[2];
286 dma = ints[3];
287 dma16 = ints[4];
288
289 return 1;
290}
291
292__setup("gus=", setup_gus);
293#endif
diff --git a/sound/oss/gus_hw.h b/sound/oss/gus_hw.h
new file mode 100644
index 000000000000..f97a0b8670e3
--- /dev/null
+++ b/sound/oss/gus_hw.h
@@ -0,0 +1,50 @@
1
2/*
3 * I/O addresses
4 */
5
6#define u_Base (gus_base + 0x000)
7#define u_Mixer u_Base
8#define u_Status (gus_base + 0x006)
9#define u_TimerControl (gus_base + 0x008)
10#define u_TimerData (gus_base + 0x009)
11#define u_IRQDMAControl (gus_base + 0x00b)
12#define u_MidiControl (gus_base + 0x100)
13#define MIDI_RESET 0x03
14#define MIDI_ENABLE_XMIT 0x20
15#define MIDI_ENABLE_RCV 0x80
16#define u_MidiStatus u_MidiControl
17#define MIDI_RCV_FULL 0x01
18#define MIDI_XMIT_EMPTY 0x02
19#define MIDI_FRAME_ERR 0x10
20#define MIDI_OVERRUN 0x20
21#define MIDI_IRQ_PEND 0x80
22#define u_MidiData (gus_base + 0x101)
23#define u_Voice (gus_base + 0x102)
24#define u_Command (gus_base + 0x103)
25#define u_DataLo (gus_base + 0x104)
26#define u_DataHi (gus_base + 0x105)
27#define u_MixData (gus_base + 0x106) /* Rev. 3.7+ mixing */
28#define u_MixSelect (gus_base + 0x506) /* registers. */
29#define u_IrqStatus u_Status
30# define MIDI_TX_IRQ 0x01 /* pending MIDI xmit IRQ */
31# define MIDI_RX_IRQ 0x02 /* pending MIDI recv IRQ */
32# define GF1_TIMER1_IRQ 0x04 /* general purpose timer */
33# define GF1_TIMER2_IRQ 0x08 /* general purpose timer */
34# define WAVETABLE_IRQ 0x20 /* pending wavetable IRQ */
35# define ENVELOPE_IRQ 0x40 /* pending volume envelope IRQ */
36# define DMA_TC_IRQ 0x80 /* pending dma tc IRQ */
37
38#define ICS2101 1
39# define ICS_MIXDEVS 6
40# define DEV_MIC 0
41# define DEV_LINE 1
42# define DEV_CD 2
43# define DEV_GF1 3
44# define DEV_UNUSED 4
45# define DEV_VOL 5
46
47# define CHN_LEFT 0
48# define CHN_RIGHT 1
49#define CS4231 2
50#define u_DRAMIO (gus_base + 0x107)
diff --git a/sound/oss/gus_linearvol.h b/sound/oss/gus_linearvol.h
new file mode 100644
index 000000000000..7ad0c30d4fd9
--- /dev/null
+++ b/sound/oss/gus_linearvol.h
@@ -0,0 +1,18 @@
1static unsigned short gus_linearvol[128] = {
2 0x0000, 0x08ff, 0x09ff, 0x0a80, 0x0aff, 0x0b40, 0x0b80, 0x0bc0,
3 0x0bff, 0x0c20, 0x0c40, 0x0c60, 0x0c80, 0x0ca0, 0x0cc0, 0x0ce0,
4 0x0cff, 0x0d10, 0x0d20, 0x0d30, 0x0d40, 0x0d50, 0x0d60, 0x0d70,
5 0x0d80, 0x0d90, 0x0da0, 0x0db0, 0x0dc0, 0x0dd0, 0x0de0, 0x0df0,
6 0x0dff, 0x0e08, 0x0e10, 0x0e18, 0x0e20, 0x0e28, 0x0e30, 0x0e38,
7 0x0e40, 0x0e48, 0x0e50, 0x0e58, 0x0e60, 0x0e68, 0x0e70, 0x0e78,
8 0x0e80, 0x0e88, 0x0e90, 0x0e98, 0x0ea0, 0x0ea8, 0x0eb0, 0x0eb8,
9 0x0ec0, 0x0ec8, 0x0ed0, 0x0ed8, 0x0ee0, 0x0ee8, 0x0ef0, 0x0ef8,
10 0x0eff, 0x0f04, 0x0f08, 0x0f0c, 0x0f10, 0x0f14, 0x0f18, 0x0f1c,
11 0x0f20, 0x0f24, 0x0f28, 0x0f2c, 0x0f30, 0x0f34, 0x0f38, 0x0f3c,
12 0x0f40, 0x0f44, 0x0f48, 0x0f4c, 0x0f50, 0x0f54, 0x0f58, 0x0f5c,
13 0x0f60, 0x0f64, 0x0f68, 0x0f6c, 0x0f70, 0x0f74, 0x0f78, 0x0f7c,
14 0x0f80, 0x0f84, 0x0f88, 0x0f8c, 0x0f90, 0x0f94, 0x0f98, 0x0f9c,
15 0x0fa0, 0x0fa4, 0x0fa8, 0x0fac, 0x0fb0, 0x0fb4, 0x0fb8, 0x0fbc,
16 0x0fc0, 0x0fc4, 0x0fc8, 0x0fcc, 0x0fd0, 0x0fd4, 0x0fd8, 0x0fdc,
17 0x0fe0, 0x0fe4, 0x0fe8, 0x0fec, 0x0ff0, 0x0ff4, 0x0ff8, 0x0ffc
18};
diff --git a/sound/oss/gus_midi.c b/sound/oss/gus_midi.c
new file mode 100644
index 000000000000..b48f57c24e48
--- /dev/null
+++ b/sound/oss/gus_midi.c
@@ -0,0 +1,256 @@
1/*
2 * sound/gus2_midi.c
3 *
4 * The low level driver for the GUS 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 * Changes:
14 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
15 * Added __init to gus_midi_init()
16 */
17
18#include <linux/init.h>
19#include <linux/spinlock.h>
20#include "sound_config.h"
21
22#include "gus.h"
23#include "gus_hw.h"
24
25static int midi_busy, input_opened;
26static int my_dev;
27static int output_used;
28static volatile unsigned char gus_midi_control;
29static void (*midi_input_intr) (int dev, unsigned char data);
30
31static unsigned char tmp_queue[256];
32extern int gus_pnp_flag;
33static volatile int qlen;
34static volatile unsigned char qhead, qtail;
35extern int gus_base, gus_irq, gus_dma;
36extern int *gus_osp;
37extern spinlock_t gus_lock;
38
39static int GUS_MIDI_STATUS(void)
40{
41 return inb(u_MidiStatus);
42}
43
44static int gus_midi_open(int dev, int mode, void (*input) (int dev, unsigned char data), void (*output) (int dev))
45{
46 if (midi_busy)
47 {
48/* printk("GUS: Midi busy\n");*/
49 return -EBUSY;
50 }
51 outb((MIDI_RESET), u_MidiControl);
52 gus_delay();
53
54 gus_midi_control = 0;
55 input_opened = 0;
56
57 if (mode == OPEN_READ || mode == OPEN_READWRITE)
58 if (!gus_pnp_flag)
59 {
60 gus_midi_control |= MIDI_ENABLE_RCV;
61 input_opened = 1;
62 }
63 outb((gus_midi_control), u_MidiControl); /* Enable */
64
65 midi_busy = 1;
66 qlen = qhead = qtail = output_used = 0;
67 midi_input_intr = input;
68
69 return 0;
70}
71
72static int dump_to_midi(unsigned char midi_byte)
73{
74 unsigned long flags;
75 int ok = 0;
76
77 output_used = 1;
78
79 spin_lock_irqsave(&gus_lock, flags);
80
81 if (GUS_MIDI_STATUS() & MIDI_XMIT_EMPTY)
82 {
83 ok = 1;
84 outb((midi_byte), u_MidiData);
85 }
86 else
87 {
88 /*
89 * Enable Midi xmit interrupts (again)
90 */
91 gus_midi_control |= MIDI_ENABLE_XMIT;
92 outb((gus_midi_control), u_MidiControl);
93 }
94
95 spin_unlock_irqrestore(&gus_lock,flags);
96 return ok;
97}
98
99static void gus_midi_close(int dev)
100{
101 /*
102 * Reset FIFO pointers, disable intrs
103 */
104
105 outb((MIDI_RESET), u_MidiControl);
106 midi_busy = 0;
107}
108
109static int gus_midi_out(int dev, unsigned char midi_byte)
110{
111 unsigned long flags;
112
113 /*
114 * Drain the local queue first
115 */
116 spin_lock_irqsave(&gus_lock, flags);
117
118 while (qlen && dump_to_midi(tmp_queue[qhead]))
119 {
120 qlen--;
121 qhead++;
122 }
123 spin_unlock_irqrestore(&gus_lock,flags);
124
125 /*
126 * Output the byte if the local queue is empty.
127 */
128
129 if (!qlen)
130 if (dump_to_midi(midi_byte))
131 return 1; /*
132 * OK
133 */
134
135 /*
136 * Put to the local queue
137 */
138
139 if (qlen >= 256)
140 return 0; /*
141 * Local queue full
142 */
143 spin_lock_irqsave(&gus_lock, flags);
144
145 tmp_queue[qtail] = midi_byte;
146 qlen++;
147 qtail++;
148
149 spin_unlock_irqrestore(&gus_lock,flags);
150 return 1;
151}
152
153static int gus_midi_start_read(int dev)
154{
155 return 0;
156}
157
158static int gus_midi_end_read(int dev)
159{
160 return 0;
161}
162
163static void gus_midi_kick(int dev)
164{
165}
166
167static int gus_midi_buffer_status(int dev)
168{
169 unsigned long flags;
170
171 if (!output_used)
172 return 0;
173
174 spin_lock_irqsave(&gus_lock, flags);
175
176 if (qlen && dump_to_midi(tmp_queue[qhead]))
177 {
178 qlen--;
179 qhead++;
180 }
181 spin_unlock_irqrestore(&gus_lock,flags);
182 return (qlen > 0) || !(GUS_MIDI_STATUS() & MIDI_XMIT_EMPTY);
183}
184
185#define MIDI_SYNTH_NAME "Gravis Ultrasound Midi"
186#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
187#include "midi_synth.h"
188
189static struct midi_operations gus_midi_operations =
190{
191 .owner = THIS_MODULE,
192 .info = {"Gravis UltraSound Midi", 0, 0, SNDCARD_GUS},
193 .converter = &std_midi_synth,
194 .in_info = {0},
195 .open = gus_midi_open,
196 .close = gus_midi_close,
197 .outputc = gus_midi_out,
198 .start_read = gus_midi_start_read,
199 .end_read = gus_midi_end_read,
200 .kick = gus_midi_kick,
201 .buffer_status = gus_midi_buffer_status,
202};
203
204void __init gus_midi_init(struct address_info *hw_config)
205{
206 int dev = sound_alloc_mididev();
207
208 if (dev == -1)
209 {
210 printk(KERN_INFO "gus_midi: Too many midi devices detected\n");
211 return;
212 }
213 outb((MIDI_RESET), u_MidiControl);
214
215 std_midi_synth.midi_dev = my_dev = dev;
216 hw_config->slots[2] = dev;
217 midi_devs[dev] = &gus_midi_operations;
218 sequencer_init();
219 return;
220}
221
222void gus_midi_interrupt(int dummy)
223{
224 volatile unsigned char stat, data;
225 int timeout = 10;
226
227 spin_lock(&gus_lock);
228
229 while (timeout-- > 0 && (stat = GUS_MIDI_STATUS()) & (MIDI_RCV_FULL | MIDI_XMIT_EMPTY))
230 {
231 if (stat & MIDI_RCV_FULL)
232 {
233 data = inb(u_MidiData);
234 if (input_opened)
235 midi_input_intr(my_dev, data);
236 }
237 if (stat & MIDI_XMIT_EMPTY)
238 {
239 while (qlen && dump_to_midi(tmp_queue[qhead]))
240 {
241 qlen--;
242 qhead++;
243 }
244 if (!qlen)
245 {
246 /*
247 * Disable Midi output interrupts, since no data in the buffer
248 */
249 gus_midi_control &= ~MIDI_ENABLE_XMIT;
250 outb((gus_midi_control), u_MidiControl);
251 outb((gus_midi_control), u_MidiControl);
252 }
253 }
254 }
255 spin_unlock(&gus_lock);
256}
diff --git a/sound/oss/gus_vol.c b/sound/oss/gus_vol.c
new file mode 100644
index 000000000000..6ae6924e1647
--- /dev/null
+++ b/sound/oss/gus_vol.c
@@ -0,0 +1,153 @@
1
2/*
3 * gus_vol.c - Compute volume for GUS.
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#include "sound_config.h"
13
14#include "gus.h"
15#include "gus_linearvol.h"
16
17#define GUS_VOLUME gus_wave_volume
18
19
20extern int gus_wave_volume;
21
22/*
23 * Calculate gus volume from note velocity, main volume, expression, and
24 * intrinsic patch volume given in patch library. Expression is multiplied
25 * in, so it emphasizes differences in note velocity, while main volume is
26 * added in -- I don't know whether this is right, but it seems reasonable to
27 * me. (In the previous stage, main volume controller messages were changed
28 * to expression controller messages, if they were found to be used for
29 * dynamic volume adjustments, so here, main volume can be assumed to be
30 * constant throughout a song.)
31 *
32 * Intrinsic patch volume is added in, but if over 64 is also multiplied in, so
33 * we can give a big boost to very weak voices like nylon guitar and the
34 * basses. The normal value is 64. Strings are assigned lower values.
35 */
36
37unsigned short gus_adagio_vol(int vel, int mainv, int xpn, int voicev)
38{
39 int i, m, n, x;
40
41
42 /*
43 * A voice volume of 64 is considered neutral, so adjust the main volume if
44 * something other than this neutral value was assigned in the patch
45 * library.
46 */
47 x = 256 + 6 * (voicev - 64);
48
49 /*
50 * Boost expression by voice volume above neutral.
51 */
52
53 if (voicev > 65)
54 xpn += voicev - 64;
55 xpn += (voicev - 64) / 2;
56
57 /*
58 * Combine multiplicative and level components.
59 */
60 x = vel * xpn * 6 + (voicev / 4) * x;
61
62#ifdef GUS_VOLUME
63 /*
64 * Further adjustment by installation-specific master volume control
65 * (default 60).
66 */
67 x = (x * GUS_VOLUME * GUS_VOLUME) / 10000;
68#endif
69
70#ifdef GUS_USE_CHN_MAIN_VOLUME
71 /*
72 * Experimental support for the channel main volume
73 */
74
75 mainv = (mainv / 2) + 64; /* Scale to 64 to 127 */
76 x = (x * mainv * mainv) / 16384;
77#endif
78
79 if (x < 2)
80 return (0);
81 else if (x >= 65535)
82 return ((15 << 8) | 255);
83
84 /*
85 * Convert to GUS's logarithmic form with 4 bit exponent i and 8 bit
86 * mantissa m.
87 */
88
89 n = x;
90 i = 7;
91 if (n < 128)
92 {
93 while (i > 0 && n < (1 << i))
94 i--;
95 }
96 else
97 {
98 while (n > 255)
99 {
100 n >>= 1;
101 i++;
102 }
103 }
104 /*
105 * Mantissa is part of linear volume not expressed in exponent. (This is
106 * not quite like real logs -- I wonder if it's right.)
107 */
108 m = x - (1 << i);
109
110 /*
111 * Adjust mantissa to 8 bits.
112 */
113 if (m > 0)
114 {
115 if (i > 8)
116 m >>= i - 8;
117 else if (i < 8)
118 m <<= 8 - i;
119 }
120 return ((i << 8) + m);
121}
122
123/*
124 * Volume-values are interpreted as linear values. Volume is based on the
125 * value supplied with SEQ_START_NOTE(), channel main volume (if compiled in)
126 * and the volume set by the mixer-device (default 60%).
127 */
128
129unsigned short gus_linear_vol(int vol, int mainvol)
130{
131 int mixer_mainvol;
132
133 if (vol <= 0)
134 vol = 0;
135 else if (vol >= 127)
136 vol = 127;
137
138#ifdef GUS_VOLUME
139 mixer_mainvol = GUS_VOLUME;
140#else
141 mixer_mainvol = 100;
142#endif
143
144#ifdef GUS_USE_CHN_MAIN_VOLUME
145 if (mainvol <= 0)
146 mainvol = 0;
147 else if (mainvol >= 127)
148 mainvol = 127;
149#else
150 mainvol = 127;
151#endif
152 return gus_linearvol[(((vol * mainvol) / 127) * mixer_mainvol) / 100];
153}
diff --git a/sound/oss/gus_wave.c b/sound/oss/gus_wave.c
new file mode 100644
index 000000000000..942d5186580d
--- /dev/null
+++ b/sound/oss/gus_wave.c
@@ -0,0 +1,3464 @@
1/*
2 * sound/gus_wave.c
3 *
4 * Driver for the Gravis UltraSound wave table synth.
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 * Frank van de Pol : Fixed GUS MAX interrupt handling. Enabled simultanious
16 * usage of CS4231A codec, GUS wave and MIDI for GUS MAX.
17 * Bartlomiej Zolnierkiewicz : added some __init/__exit
18 */
19
20#include <linux/init.h>
21#include <linux/config.h>
22#include <linux/spinlock.h>
23
24#define GUSPNP_AUTODETECT
25
26#include "sound_config.h"
27#include <linux/ultrasound.h>
28
29#include "gus.h"
30#include "gus_hw.h"
31
32#define GUS_BANK_SIZE (((iw_mode) ? 256*1024*1024 : 256*1024))
33
34#define MAX_SAMPLE 150
35#define MAX_PATCH 256
36
37#define NOT_SAMPLE 0xffff
38
39struct voice_info
40{
41 unsigned long orig_freq;
42 unsigned long current_freq;
43 unsigned long mode;
44 int fixed_pitch;
45 int bender;
46 int bender_range;
47 int panning;
48 int midi_volume;
49 unsigned int initial_volume;
50 unsigned int current_volume;
51 int loop_irq_mode, loop_irq_parm;
52#define LMODE_FINISH 1
53#define LMODE_PCM 2
54#define LMODE_PCM_STOP 3
55 int volume_irq_mode, volume_irq_parm;
56#define VMODE_HALT 1
57#define VMODE_ENVELOPE 2
58#define VMODE_START_NOTE 3
59
60 int env_phase;
61 unsigned char env_rate[6];
62 unsigned char env_offset[6];
63
64 /*
65 * Volume computation parameters for gus_adagio_vol()
66 */
67 int main_vol, expression_vol, patch_vol;
68
69 /* Variables for "Ultraclick" removal */
70 int dev_pending, note_pending, volume_pending,
71 sample_pending;
72 char kill_pending;
73 long offset_pending;
74
75};
76
77static struct voice_alloc_info *voice_alloc;
78static struct address_info *gus_hw_config;
79extern int gus_base;
80extern int gus_irq, gus_dma;
81extern int gus_pnp_flag;
82extern int gus_no_wave_dma;
83static int gus_dma2 = -1;
84static int dual_dma_mode;
85static long gus_mem_size;
86static long free_mem_ptr;
87static int gus_busy;
88static int gus_no_dma;
89static int nr_voices;
90static int gus_devnum;
91static int volume_base, volume_scale, volume_method;
92static int gus_recmask = SOUND_MASK_MIC;
93static int recording_active;
94static int only_read_access;
95static int only_8_bits;
96
97static int iw_mode = 0;
98int gus_wave_volume = 60;
99int gus_pcm_volume = 80;
100int have_gus_max = 0;
101static int gus_line_vol = 100, gus_mic_vol;
102static unsigned char mix_image = 0x00;
103
104int gus_timer_enabled = 0;
105
106/*
107 * Current version of this driver doesn't allow synth and PCM functions
108 * at the same time. The active_device specifies the active driver
109 */
110
111static int active_device;
112
113#define GUS_DEV_WAVE 1 /* Wave table synth */
114#define GUS_DEV_PCM_DONE 2 /* PCM device, transfer done */
115#define GUS_DEV_PCM_CONTINUE 3 /* PCM device, transfer done ch. 1/2 */
116
117static int gus_audio_speed;
118static int gus_audio_channels;
119static int gus_audio_bits;
120static int gus_audio_bsize;
121static char bounce_buf[8 * 1024]; /* Must match value set to max_fragment */
122
123static DECLARE_WAIT_QUEUE_HEAD(dram_sleeper);
124
125/*
126 * Variables and buffers for PCM output
127 */
128
129#define MAX_PCM_BUFFERS (128*MAX_REALTIME_FACTOR) /* Don't change */
130
131static int pcm_bsize, pcm_nblk, pcm_banksize;
132static int pcm_datasize[MAX_PCM_BUFFERS];
133static volatile int pcm_head, pcm_tail, pcm_qlen;
134static volatile int pcm_active;
135static volatile int dma_active;
136static int pcm_opened;
137static int pcm_current_dev;
138static int pcm_current_block;
139static unsigned long pcm_current_buf;
140static int pcm_current_count;
141static int pcm_current_intrflag;
142DEFINE_SPINLOCK(gus_lock);
143
144extern int *gus_osp;
145
146static struct voice_info voices[32];
147
148static int freq_div_table[] =
149{
150 44100, /* 14 */
151 41160, /* 15 */
152 38587, /* 16 */
153 36317, /* 17 */
154 34300, /* 18 */
155 32494, /* 19 */
156 30870, /* 20 */
157 29400, /* 21 */
158 28063, /* 22 */
159 26843, /* 23 */
160 25725, /* 24 */
161 24696, /* 25 */
162 23746, /* 26 */
163 22866, /* 27 */
164 22050, /* 28 */
165 21289, /* 29 */
166 20580, /* 30 */
167 19916, /* 31 */
168 19293 /* 32 */
169};
170
171static struct patch_info *samples;
172static long sample_ptrs[MAX_SAMPLE + 1];
173static int sample_map[32];
174static int free_sample;
175static int mixer_type;
176
177
178static int patch_table[MAX_PATCH];
179static int patch_map[32];
180
181static struct synth_info gus_info = {
182 "Gravis UltraSound", 0, SYNTH_TYPE_SAMPLE, SAMPLE_TYPE_GUS,
183 0, 16, 0, MAX_PATCH
184};
185
186static void gus_poke(long addr, unsigned char data);
187static void compute_and_set_volume(int voice, int volume, int ramp_time);
188extern unsigned short gus_adagio_vol(int vel, int mainv, int xpn, int voicev);
189extern unsigned short gus_linear_vol(int vol, int mainvol);
190static void compute_volume(int voice, int volume);
191static void do_volume_irq(int voice);
192static void set_input_volumes(void);
193static void gus_tmr_install(int io_base);
194
195#define INSTANT_RAMP -1 /* Instant change. No ramping */
196#define FAST_RAMP 0 /* Fastest possible ramp */
197
198static void reset_sample_memory(void)
199{
200 int i;
201
202 for (i = 0; i <= MAX_SAMPLE; i++)
203 sample_ptrs[i] = -1;
204 for (i = 0; i < 32; i++)
205 sample_map[i] = -1;
206 for (i = 0; i < 32; i++)
207 patch_map[i] = -1;
208
209 gus_poke(0, 0); /* Put a silent sample to the beginning */
210 gus_poke(1, 0);
211 free_mem_ptr = 2;
212
213 free_sample = 0;
214
215 for (i = 0; i < MAX_PATCH; i++)
216 patch_table[i] = NOT_SAMPLE;
217}
218
219void gus_delay(void)
220{
221 int i;
222
223 for (i = 0; i < 7; i++)
224 inb(u_DRAMIO);
225}
226
227static void gus_poke(long addr, unsigned char data)
228{ /* Writes a byte to the DRAM */
229 outb((0x43), u_Command);
230 outb((addr & 0xff), u_DataLo);
231 outb(((addr >> 8) & 0xff), u_DataHi);
232
233 outb((0x44), u_Command);
234 outb(((addr >> 16) & 0xff), u_DataHi);
235 outb((data), u_DRAMIO);
236}
237
238static unsigned char gus_peek(long addr)
239{ /* Reads a byte from the DRAM */
240 unsigned char tmp;
241
242 outb((0x43), u_Command);
243 outb((addr & 0xff), u_DataLo);
244 outb(((addr >> 8) & 0xff), u_DataHi);
245
246 outb((0x44), u_Command);
247 outb(((addr >> 16) & 0xff), u_DataHi);
248 tmp = inb(u_DRAMIO);
249
250 return tmp;
251}
252
253void gus_write8(int reg, unsigned int data)
254{ /* Writes to an indirect register (8 bit) */
255 outb((reg), u_Command);
256 outb(((unsigned char) (data & 0xff)), u_DataHi);
257}
258
259static unsigned char gus_read8(int reg)
260{
261 /* Reads from an indirect register (8 bit). Offset 0x80. */
262 unsigned char val;
263
264 outb((reg | 0x80), u_Command);
265 val = inb(u_DataHi);
266
267 return val;
268}
269
270static unsigned char gus_look8(int reg)
271{
272 /* Reads from an indirect register (8 bit). No additional offset. */
273 unsigned char val;
274
275 outb((reg), u_Command);
276 val = inb(u_DataHi);
277
278 return val;
279}
280
281static void gus_write16(int reg, unsigned int data)
282{
283 /* Writes to an indirect register (16 bit) */
284 outb((reg), u_Command);
285
286 outb(((unsigned char) (data & 0xff)), u_DataLo);
287 outb(((unsigned char) ((data >> 8) & 0xff)), u_DataHi);
288}
289
290static unsigned short gus_read16(int reg)
291{
292 /* Reads from an indirect register (16 bit). Offset 0x80. */
293 unsigned char hi, lo;
294
295 outb((reg | 0x80), u_Command);
296
297 lo = inb(u_DataLo);
298 hi = inb(u_DataHi);
299
300 return ((hi << 8) & 0xff00) | lo;
301}
302
303static unsigned short gus_look16(int reg)
304{
305 /* Reads from an indirect register (16 bit). No additional offset. */
306 unsigned char hi, lo;
307
308 outb((reg), u_Command);
309
310 lo = inb(u_DataLo);
311 hi = inb(u_DataHi);
312
313 return ((hi << 8) & 0xff00) | lo;
314}
315
316static void gus_write_addr(int reg, unsigned long address, int frac, int is16bit)
317{
318 /* Writes an 24 bit memory address */
319 unsigned long hold_address;
320
321 if (is16bit)
322 {
323 if (iw_mode)
324 {
325 /* Interwave spesific address translations */
326 address >>= 1;
327 }
328 else
329 {
330 /*
331 * Special processing required for 16 bit patches
332 */
333
334 hold_address = address;
335 address = address >> 1;
336 address &= 0x0001ffffL;
337 address |= (hold_address & 0x000c0000L);
338 }
339 }
340 gus_write16(reg, (unsigned short) ((address >> 7) & 0xffff));
341 gus_write16(reg + 1, (unsigned short) ((address << 9) & 0xffff)
342 + (frac << 5));
343 /* Could writing twice fix problems with GUS_VOICE_POS()? Let's try. */
344 gus_delay();
345 gus_write16(reg, (unsigned short) ((address >> 7) & 0xffff));
346 gus_write16(reg + 1, (unsigned short) ((address << 9) & 0xffff)
347 + (frac << 5));
348}
349
350static void gus_select_voice(int voice)
351{
352 if (voice < 0 || voice > 31)
353 return;
354 outb((voice), u_Voice);
355}
356
357static void gus_select_max_voices(int nvoices)
358{
359 if (iw_mode)
360 nvoices = 32;
361 if (nvoices < 14)
362 nvoices = 14;
363 if (nvoices > 32)
364 nvoices = 32;
365
366 voice_alloc->max_voice = nr_voices = nvoices;
367 gus_write8(0x0e, (nvoices - 1) | 0xc0);
368}
369
370static void gus_voice_on(unsigned int mode)
371{
372 gus_write8(0x00, (unsigned char) (mode & 0xfc));
373 gus_delay();
374 gus_write8(0x00, (unsigned char) (mode & 0xfc));
375}
376
377static void gus_voice_off(void)
378{
379 gus_write8(0x00, gus_read8(0x00) | 0x03);
380}
381
382static void gus_voice_mode(unsigned int m)
383{
384 unsigned char mode = (unsigned char) (m & 0xff);
385
386 gus_write8(0x00, (gus_read8(0x00) & 0x03) |
387 (mode & 0xfc)); /* Don't touch last two bits */
388 gus_delay();
389 gus_write8(0x00, (gus_read8(0x00) & 0x03) | (mode & 0xfc));
390}
391
392static void gus_voice_freq(unsigned long freq)
393{
394 unsigned long divisor = freq_div_table[nr_voices - 14];
395 unsigned short fc;
396
397 /* Interwave plays at 44100 Hz with any number of voices */
398 if (iw_mode)
399 fc = (unsigned short) (((freq << 9) + (44100 >> 1)) / 44100);
400 else
401 fc = (unsigned short) (((freq << 9) + (divisor >> 1)) / divisor);
402 fc = fc << 1;
403
404 gus_write16(0x01, fc);
405}
406
407static void gus_voice_volume(unsigned int vol)
408{
409 gus_write8(0x0d, 0x03); /* Stop ramp before setting volume */
410 gus_write16(0x09, (unsigned short) (vol << 4));
411}
412
413static void gus_voice_balance(unsigned int balance)
414{
415 gus_write8(0x0c, (unsigned char) (balance & 0xff));
416}
417
418static void gus_ramp_range(unsigned int low, unsigned int high)
419{
420 gus_write8(0x07, (unsigned char) ((low >> 4) & 0xff));
421 gus_write8(0x08, (unsigned char) ((high >> 4) & 0xff));
422}
423
424static void gus_ramp_rate(unsigned int scale, unsigned int rate)
425{
426 gus_write8(0x06, (unsigned char) (((scale & 0x03) << 6) | (rate & 0x3f)));
427}
428
429static void gus_rampon(unsigned int m)
430{
431 unsigned char mode = (unsigned char) (m & 0xff);
432
433 gus_write8(0x0d, mode & 0xfc);
434 gus_delay();
435 gus_write8(0x0d, mode & 0xfc);
436}
437
438static void gus_ramp_mode(unsigned int m)
439{
440 unsigned char mode = (unsigned char) (m & 0xff);
441
442 gus_write8(0x0d, (gus_read8(0x0d) & 0x03) |
443 (mode & 0xfc)); /* Leave the last 2 bits alone */
444 gus_delay();
445 gus_write8(0x0d, (gus_read8(0x0d) & 0x03) | (mode & 0xfc));
446}
447
448static void gus_rampoff(void)
449{
450 gus_write8(0x0d, 0x03);
451}
452
453static void gus_set_voice_pos(int voice, long position)
454{
455 int sample_no;
456
457 if ((sample_no = sample_map[voice]) != -1) {
458 if (position < samples[sample_no].len) {
459 if (voices[voice].volume_irq_mode == VMODE_START_NOTE)
460 voices[voice].offset_pending = position;
461 else
462 gus_write_addr(0x0a, sample_ptrs[sample_no] + position, 0,
463 samples[sample_no].mode & WAVE_16_BITS);
464 }
465 }
466}
467
468static void gus_voice_init(int voice)
469{
470 unsigned long flags;
471
472 spin_lock_irqsave(&gus_lock,flags);
473 gus_select_voice(voice);
474 gus_voice_volume(0);
475 gus_voice_off();
476 gus_write_addr(0x0a, 0, 0, 0); /* Set current position to 0 */
477 gus_write8(0x00, 0x03); /* Voice off */
478 gus_write8(0x0d, 0x03); /* Ramping off */
479 voice_alloc->map[voice] = 0;
480 voice_alloc->alloc_times[voice] = 0;
481 spin_unlock_irqrestore(&gus_lock,flags);
482
483}
484
485static void gus_voice_init2(int voice)
486{
487 voices[voice].panning = 0;
488 voices[voice].mode = 0;
489 voices[voice].orig_freq = 20000;
490 voices[voice].current_freq = 20000;
491 voices[voice].bender = 0;
492 voices[voice].bender_range = 200;
493 voices[voice].initial_volume = 0;
494 voices[voice].current_volume = 0;
495 voices[voice].loop_irq_mode = 0;
496 voices[voice].loop_irq_parm = 0;
497 voices[voice].volume_irq_mode = 0;
498 voices[voice].volume_irq_parm = 0;
499 voices[voice].env_phase = 0;
500 voices[voice].main_vol = 127;
501 voices[voice].patch_vol = 127;
502 voices[voice].expression_vol = 127;
503 voices[voice].sample_pending = -1;
504 voices[voice].fixed_pitch = 0;
505}
506
507static void step_envelope(int voice)
508{
509 unsigned vol, prev_vol, phase;
510 unsigned char rate;
511 unsigned long flags;
512
513 if (voices[voice].mode & WAVE_SUSTAIN_ON && voices[voice].env_phase == 2)
514 {
515 spin_lock_irqsave(&gus_lock,flags);
516 gus_select_voice(voice);
517 gus_rampoff();
518 spin_unlock_irqrestore(&gus_lock,flags);
519 return;
520 /*
521 * Sustain phase begins. Continue envelope after receiving note off.
522 */
523 }
524 if (voices[voice].env_phase >= 5)
525 {
526 /* Envelope finished. Shoot the voice down */
527 gus_voice_init(voice);
528 return;
529 }
530 prev_vol = voices[voice].current_volume;
531 phase = ++voices[voice].env_phase;
532 compute_volume(voice, voices[voice].midi_volume);
533 vol = voices[voice].initial_volume * voices[voice].env_offset[phase] / 255;
534 rate = voices[voice].env_rate[phase];
535
536 spin_lock_irqsave(&gus_lock,flags);
537 gus_select_voice(voice);
538
539 gus_voice_volume(prev_vol);
540
541
542 gus_write8(0x06, rate); /* Ramping rate */
543
544 voices[voice].volume_irq_mode = VMODE_ENVELOPE;
545
546 if (((vol - prev_vol) / 64) == 0) /* No significant volume change */
547 {
548 spin_unlock_irqrestore(&gus_lock,flags);
549 step_envelope(voice); /* Continue the envelope on the next step */
550 return;
551 }
552 if (vol > prev_vol)
553 {
554 if (vol >= (4096 - 64))
555 vol = 4096 - 65;
556 gus_ramp_range(0, vol);
557 gus_rampon(0x20); /* Increasing volume, with IRQ */
558 }
559 else
560 {
561 if (vol <= 64)
562 vol = 65;
563 gus_ramp_range(vol, 4030);
564 gus_rampon(0x60); /* Decreasing volume, with IRQ */
565 }
566 voices[voice].current_volume = vol;
567 spin_unlock_irqrestore(&gus_lock,flags);
568}
569
570static void init_envelope(int voice)
571{
572 voices[voice].env_phase = -1;
573 voices[voice].current_volume = 64;
574
575 step_envelope(voice);
576}
577
578static void start_release(int voice)
579{
580 if (gus_read8(0x00) & 0x03)
581 return; /* Voice already stopped */
582
583 voices[voice].env_phase = 2; /* Will be incremented by step_envelope */
584
585 voices[voice].current_volume = voices[voice].initial_volume =
586 gus_read16(0x09) >> 4; /* Get current volume */
587
588 voices[voice].mode &= ~WAVE_SUSTAIN_ON;
589 gus_rampoff();
590 step_envelope(voice);
591}
592
593static void gus_voice_fade(int voice)
594{
595 int instr_no = sample_map[voice], is16bits;
596 unsigned long flags;
597
598 spin_lock_irqsave(&gus_lock,flags);
599 gus_select_voice(voice);
600
601 if (instr_no < 0 || instr_no > MAX_SAMPLE)
602 {
603 gus_write8(0x00, 0x03); /* Hard stop */
604 voice_alloc->map[voice] = 0;
605 spin_unlock_irqrestore(&gus_lock,flags);
606 return;
607 }
608 is16bits = (samples[instr_no].mode & WAVE_16_BITS) ? 1 : 0; /* 8 or 16 bits */
609
610 if (voices[voice].mode & WAVE_ENVELOPES)
611 {
612 start_release(voice);
613 spin_unlock_irqrestore(&gus_lock,flags);
614 return;
615 }
616 /*
617 * Ramp the volume down but not too quickly.
618 */
619 if ((int) (gus_read16(0x09) >> 4) < 100) /* Get current volume */
620 {
621 gus_voice_off();
622 gus_rampoff();
623 gus_voice_init(voice);
624 spin_unlock_irqrestore(&gus_lock,flags);
625 return;
626 }
627 gus_ramp_range(65, 4030);
628 gus_ramp_rate(2, 4);
629 gus_rampon(0x40 | 0x20); /* Down, once, with IRQ */
630 voices[voice].volume_irq_mode = VMODE_HALT;
631 spin_unlock_irqrestore(&gus_lock,flags);
632}
633
634static void gus_reset(void)
635{
636 int i;
637
638 gus_select_max_voices(24);
639 volume_base = 3071;
640 volume_scale = 4;
641 volume_method = VOL_METHOD_ADAGIO;
642
643 for (i = 0; i < 32; i++)
644 {
645 gus_voice_init(i); /* Turn voice off */
646 gus_voice_init2(i);
647 }
648}
649
650static void gus_initialize(void)
651{
652 unsigned long flags;
653 unsigned char dma_image, irq_image, tmp;
654
655 static unsigned char gus_irq_map[16] = {
656 0, 0, 0, 3, 0, 2, 0, 4, 0, 1, 0, 5, 6, 0, 0, 7
657 };
658
659 static unsigned char gus_dma_map[8] = {
660 0, 1, 0, 2, 0, 3, 4, 5
661 };
662
663 spin_lock_irqsave(&gus_lock,flags);
664 gus_write8(0x4c, 0); /* Reset GF1 */
665 gus_delay();
666 gus_delay();
667
668 gus_write8(0x4c, 1); /* Release Reset */
669 gus_delay();
670 gus_delay();
671
672 /*
673 * Clear all interrupts
674 */
675
676 gus_write8(0x41, 0); /* DMA control */
677 gus_write8(0x45, 0); /* Timer control */
678 gus_write8(0x49, 0); /* Sample control */
679
680 gus_select_max_voices(24);
681
682 inb(u_Status); /* Touch the status register */
683
684 gus_look8(0x41); /* Clear any pending DMA IRQs */
685 gus_look8(0x49); /* Clear any pending sample IRQs */
686 gus_read8(0x0f); /* Clear pending IRQs */
687
688 gus_reset(); /* Resets all voices */
689
690 gus_look8(0x41); /* Clear any pending DMA IRQs */
691 gus_look8(0x49); /* Clear any pending sample IRQs */
692 gus_read8(0x0f); /* Clear pending IRQs */
693
694 gus_write8(0x4c, 7); /* Master reset | DAC enable | IRQ enable */
695
696 /*
697 * Set up for Digital ASIC
698 */
699
700 outb((0x05), gus_base + 0x0f);
701
702 mix_image |= 0x02; /* Disable line out (for a moment) */
703 outb((mix_image), u_Mixer);
704
705 outb((0x00), u_IRQDMAControl);
706
707 outb((0x00), gus_base + 0x0f);
708
709 /*
710 * Now set up the DMA and IRQ interface
711 *
712 * The GUS supports two IRQs and two DMAs.
713 *
714 * Just one DMA channel is used. This prevents simultaneous ADC and DAC.
715 * Adding this support requires significant changes to the dmabuf.c, dsp.c
716 * and audio.c also.
717 */
718
719 irq_image = 0;
720 tmp = gus_irq_map[gus_irq];
721 if (!gus_pnp_flag && !tmp)
722 printk(KERN_WARNING "Warning! GUS IRQ not selected\n");
723 irq_image |= tmp;
724 irq_image |= 0x40; /* Combine IRQ1 (GF1) and IRQ2 (Midi) */
725
726 dual_dma_mode = 1;
727 if (gus_dma2 == gus_dma || gus_dma2 == -1)
728 {
729 dual_dma_mode = 0;
730 dma_image = 0x40; /* Combine DMA1 (DRAM) and IRQ2 (ADC) */
731
732 tmp = gus_dma_map[gus_dma];
733 if (!tmp)
734 printk(KERN_WARNING "Warning! GUS DMA not selected\n");
735
736 dma_image |= tmp;
737 }
738 else
739 {
740 /* Setup dual DMA channel mode for GUS MAX */
741
742 dma_image = gus_dma_map[gus_dma];
743 if (!dma_image)
744 printk(KERN_WARNING "Warning! GUS DMA not selected\n");
745
746 tmp = gus_dma_map[gus_dma2] << 3;
747 if (!tmp)
748 {
749 printk(KERN_WARNING "Warning! Invalid GUS MAX DMA\n");
750 tmp = 0x40; /* Combine DMA channels */
751 dual_dma_mode = 0;
752 }
753 dma_image |= tmp;
754 }
755
756 /*
757 * For some reason the IRQ and DMA addresses must be written twice
758 */
759
760 /*
761 * Doing it first time
762 */
763
764 outb((mix_image), u_Mixer); /* Select DMA control */
765 outb((dma_image | 0x80), u_IRQDMAControl); /* Set DMA address */
766
767 outb((mix_image | 0x40), u_Mixer); /* Select IRQ control */
768 outb((irq_image), u_IRQDMAControl); /* Set IRQ address */
769
770 /*
771 * Doing it second time
772 */
773
774 outb((mix_image), u_Mixer); /* Select DMA control */
775 outb((dma_image), u_IRQDMAControl); /* Set DMA address */
776
777 outb((mix_image | 0x40), u_Mixer); /* Select IRQ control */
778 outb((irq_image), u_IRQDMAControl); /* Set IRQ address */
779
780 gus_select_voice(0); /* This disables writes to IRQ/DMA reg */
781
782 mix_image &= ~0x02; /* Enable line out */
783 mix_image |= 0x08; /* Enable IRQ */
784 outb((mix_image), u_Mixer); /*
785 * Turn mixer channels on
786 * Note! Mic in is left off.
787 */
788
789 gus_select_voice(0); /* This disables writes to IRQ/DMA reg */
790
791 gusintr(gus_irq, (void *)gus_hw_config, NULL); /* Serve pending interrupts */
792
793 inb(u_Status); /* Touch the status register */
794
795 gus_look8(0x41); /* Clear any pending DMA IRQs */
796 gus_look8(0x49); /* Clear any pending sample IRQs */
797
798 gus_read8(0x0f); /* Clear pending IRQs */
799
800 if (iw_mode)
801 gus_write8(0x19, gus_read8(0x19) | 0x01);
802 spin_unlock_irqrestore(&gus_lock,flags);
803}
804
805
806static void __init pnp_mem_init(void)
807{
808#include "iwmem.h"
809#define CHUNK_SIZE (256*1024)
810#define BANK_SIZE (4*1024*1024)
811#define CHUNKS_PER_BANK (BANK_SIZE/CHUNK_SIZE)
812
813 int bank, chunk, addr, total = 0;
814 int bank_sizes[4];
815 int i, j, bits = -1, testbits = -1, nbanks = 0;
816
817 /*
818 * This routine determines what kind of RAM is installed in each of the four
819 * SIMM banks and configures the DRAM address decode logic accordingly.
820 */
821
822 /*
823 * Place the chip into enhanced mode
824 */
825 gus_write8(0x19, gus_read8(0x19) | 0x01);
826 gus_write8(0x53, gus_look8(0x53) & ~0x02); /* Select DRAM I/O access */
827
828 /*
829 * Set memory configuration to 4 DRAM banks of 4M in each (16M total).
830 */
831
832 gus_write16(0x52, (gus_look16(0x52) & 0xfff0) | 0x000c);
833
834 /*
835 * Perform the DRAM size detection for each bank individually.
836 */
837 for (bank = 0; bank < 4; bank++)
838 {
839 int size = 0;
840
841 addr = bank * BANK_SIZE;
842
843 /* Clean check points of each chunk */
844 for (chunk = 0; chunk < CHUNKS_PER_BANK; chunk++)
845 {
846 gus_poke(addr + chunk * CHUNK_SIZE + 0L, 0x00);
847 gus_poke(addr + chunk * CHUNK_SIZE + 1L, 0x00);
848 }
849
850 /* Write a value to each chunk point and verify the result */
851 for (chunk = 0; chunk < CHUNKS_PER_BANK; chunk++)
852 {
853 gus_poke(addr + chunk * CHUNK_SIZE + 0L, 0x55);
854 gus_poke(addr + chunk * CHUNK_SIZE + 1L, 0xAA);
855
856 if (gus_peek(addr + chunk * CHUNK_SIZE + 0L) == 0x55 &&
857 gus_peek(addr + chunk * CHUNK_SIZE + 1L) == 0xAA)
858 {
859 /* OK. There is RAM. Now check for possible shadows */
860 int ok = 1, chunk2;
861
862 for (chunk2 = 0; ok && chunk2 < chunk; chunk2++)
863 if (gus_peek(addr + chunk2 * CHUNK_SIZE + 0L) ||
864 gus_peek(addr + chunk2 * CHUNK_SIZE + 1L))
865 ok = 0; /* Addressing wraps */
866
867 if (ok)
868 size = (chunk + 1) * CHUNK_SIZE;
869 }
870 gus_poke(addr + chunk * CHUNK_SIZE + 0L, 0x00);
871 gus_poke(addr + chunk * CHUNK_SIZE + 1L, 0x00);
872 }
873 bank_sizes[bank] = size;
874 if (size)
875 nbanks = bank + 1;
876 DDB(printk("Interwave: Bank %d, size=%dk\n", bank, size / 1024));
877 }
878
879 if (nbanks == 0) /* No RAM - Give up */
880 {
881 printk(KERN_ERR "Sound: An Interwave audio chip detected but no DRAM\n");
882 printk(KERN_ERR "Sound: Unable to work with this card.\n");
883 gus_write8(0x19, gus_read8(0x19) & ~0x01);
884 gus_mem_size = 0;
885 return;
886 }
887
888 /*
889 * Now we know how much DRAM there is in each bank. The next step is
890 * to find a DRAM size encoding (0 to 12) which is best for the combination
891 * we have.
892 *
893 * First try if any of the possible alternatives matches exactly the amount
894 * of memory we have.
895 */
896
897 for (i = 0; bits == -1 && i < 13; i++)
898 {
899 bits = i;
900
901 for (j = 0; bits != -1 && j < 4; j++)
902 if (mem_decode[i][j] != bank_sizes[j])
903 bits = -1; /* No hit */
904 }
905
906 /*
907 * If necessary, try to find a combination where other than the last
908 * bank matches our configuration and the last bank is left oversized.
909 * In this way we don't leave holes in the middle of memory.
910 */
911
912 if (bits == -1) /* No luck yet */
913 {
914 for (i = 0; bits == -1 && i < 13; i++)
915 {
916 bits = i;
917
918 for (j = 0; bits != -1 && j < nbanks - 1; j++)
919 if (mem_decode[i][j] != bank_sizes[j])
920 bits = -1; /* No hit */
921 if (mem_decode[i][nbanks - 1] < bank_sizes[nbanks - 1])
922 bits = -1; /* The last bank is too small */
923 }
924 }
925 /*
926 * The last resort is to search for a combination where the banks are
927 * smaller than the actual SIMMs. This leaves some memory in the banks
928 * unused but doesn't leave holes in the DRAM address space.
929 */
930 if (bits == -1) /* No luck yet */
931 {
932 for (i = 0; i < 13; i++)
933 {
934 testbits = i;
935 for (j = 0; testbits != -1 && j < nbanks - 1; j++)
936 if (mem_decode[i][j] > bank_sizes[j]) {
937 testbits = -1;
938 }
939 if(testbits > bits) bits = testbits;
940 }
941 if (bits != -1)
942 {
943 printk(KERN_INFO "Interwave: Can't use all installed RAM.\n");
944 printk(KERN_INFO "Interwave: Try reordering SIMMS.\n");
945 }
946 printk(KERN_INFO "Interwave: Can't find working DRAM encoding.\n");
947 printk(KERN_INFO "Interwave: Defaulting to 256k. Try reordering SIMMS.\n");
948 bits = 0;
949 }
950 DDB(printk("Interwave: Selecting DRAM addressing mode %d\n", bits));
951
952 for (bank = 0; bank < 4; bank++)
953 {
954 DDB(printk(" Bank %d, mem=%dk (limit %dk)\n", bank, bank_sizes[bank] / 1024, mem_decode[bits][bank] / 1024));
955
956 if (bank_sizes[bank] > mem_decode[bits][bank])
957 total += mem_decode[bits][bank];
958 else
959 total += bank_sizes[bank];
960 }
961
962 DDB(printk("Total %dk of DRAM (enhanced mode)\n", total / 1024));
963
964 /*
965 * Set the memory addressing mode.
966 */
967 gus_write16(0x52, (gus_look16(0x52) & 0xfff0) | bits);
968
969/* Leave the chip into enhanced mode. Disable LFO */
970 gus_mem_size = total;
971 iw_mode = 1;
972 gus_write8(0x19, (gus_read8(0x19) | 0x01) & ~0x02);
973}
974
975int __init gus_wave_detect(int baseaddr)
976{
977 unsigned long i, max_mem = 1024L;
978 unsigned long loc;
979 unsigned char val;
980
981 if (!request_region(baseaddr, 16, "GUS"))
982 return 0;
983 if (!request_region(baseaddr + 0x100, 12, "GUS")) { /* 0x10c-> is MAX */
984 release_region(baseaddr, 16);
985 return 0;
986 }
987
988 gus_base = baseaddr;
989
990 gus_write8(0x4c, 0); /* Reset GF1 */
991 gus_delay();
992 gus_delay();
993
994 gus_write8(0x4c, 1); /* Release Reset */
995 gus_delay();
996 gus_delay();
997
998#ifdef GUSPNP_AUTODETECT
999 val = gus_look8(0x5b); /* Version number register */
1000 gus_write8(0x5b, ~val); /* Invert all bits */
1001
1002 if ((gus_look8(0x5b) & 0xf0) == (val & 0xf0)) /* No change */
1003 {
1004 if ((gus_look8(0x5b) & 0x0f) == ((~val) & 0x0f)) /* Change */
1005 {
1006 DDB(printk("Interwave chip version %d detected\n", (val & 0xf0) >> 4));
1007 gus_pnp_flag = 1;
1008 }
1009 else
1010 {
1011 DDB(printk("Not an Interwave chip (%x)\n", gus_look8(0x5b)));
1012 gus_pnp_flag = 0;
1013 }
1014 }
1015 gus_write8(0x5b, val); /* Restore all bits */
1016#endif
1017
1018 if (gus_pnp_flag)
1019 pnp_mem_init();
1020 if (iw_mode)
1021 return 1;
1022
1023 /* See if there is first block there.... */
1024 gus_poke(0L, 0xaa);
1025 if (gus_peek(0L) != 0xaa) {
1026 release_region(baseaddr + 0x100, 12);
1027 release_region(baseaddr, 16);
1028 return 0;
1029 }
1030
1031 /* Now zero it out so that I can check for mirroring .. */
1032 gus_poke(0L, 0x00);
1033 for (i = 1L; i < max_mem; i++)
1034 {
1035 int n, failed;
1036
1037 /* check for mirroring ... */
1038 if (gus_peek(0L) != 0)
1039 break;
1040 loc = i << 10;
1041
1042 for (n = loc - 1, failed = 0; n <= loc; n++)
1043 {
1044 gus_poke(loc, 0xaa);
1045 if (gus_peek(loc) != 0xaa)
1046 failed = 1;
1047 gus_poke(loc, 0x55);
1048 if (gus_peek(loc) != 0x55)
1049 failed = 1;
1050 }
1051 if (failed)
1052 break;
1053 }
1054 gus_mem_size = i << 10;
1055 return 1;
1056}
1057
1058static int guswave_ioctl(int dev, unsigned int cmd, void __user *arg)
1059{
1060
1061 switch (cmd)
1062 {
1063 case SNDCTL_SYNTH_INFO:
1064 gus_info.nr_voices = nr_voices;
1065 if (copy_to_user(arg, &gus_info, sizeof(gus_info)))
1066 return -EFAULT;
1067 return 0;
1068
1069 case SNDCTL_SEQ_RESETSAMPLES:
1070 reset_sample_memory();
1071 return 0;
1072
1073 case SNDCTL_SEQ_PERCMODE:
1074 return 0;
1075
1076 case SNDCTL_SYNTH_MEMAVL:
1077 return (gus_mem_size == 0) ? 0 : gus_mem_size - free_mem_ptr - 32;
1078
1079 default:
1080 return -EINVAL;
1081 }
1082}
1083
1084static int guswave_set_instr(int dev, int voice, int instr_no)
1085{
1086 int sample_no;
1087
1088 if (instr_no < 0 || instr_no > MAX_PATCH)
1089 instr_no = 0; /* Default to acoustic piano */
1090
1091 if (voice < 0 || voice > 31)
1092 return -EINVAL;
1093
1094 if (voices[voice].volume_irq_mode == VMODE_START_NOTE)
1095 {
1096 voices[voice].sample_pending = instr_no;
1097 return 0;
1098 }
1099 sample_no = patch_table[instr_no];
1100 patch_map[voice] = -1;
1101
1102 if (sample_no == NOT_SAMPLE)
1103 {
1104/* printk("GUS: Undefined patch %d for voice %d\n", instr_no, voice);*/
1105 return -EINVAL; /* Patch not defined */
1106 }
1107 if (sample_ptrs[sample_no] == -1) /* Sample not loaded */
1108 {
1109/* printk("GUS: Sample #%d not loaded for patch %d (voice %d)\n", sample_no, instr_no, voice);*/
1110 return -EINVAL;
1111 }
1112 sample_map[voice] = sample_no;
1113 patch_map[voice] = instr_no;
1114 return 0;
1115}
1116
1117static int guswave_kill_note(int dev, int voice, int note, int velocity)
1118{
1119 unsigned long flags;
1120
1121 spin_lock_irqsave(&gus_lock,flags);
1122 /* voice_alloc->map[voice] = 0xffff; */
1123 if (voices[voice].volume_irq_mode == VMODE_START_NOTE)
1124 {
1125 voices[voice].kill_pending = 1;
1126 spin_unlock_irqrestore(&gus_lock,flags);
1127 }
1128 else
1129 {
1130 spin_unlock_irqrestore(&gus_lock,flags);
1131 gus_voice_fade(voice);
1132 }
1133
1134 return 0;
1135}
1136
1137static void guswave_aftertouch(int dev, int voice, int pressure)
1138{
1139}
1140
1141static void guswave_panning(int dev, int voice, int value)
1142{
1143 if (voice >= 0 || voice < 32)
1144 voices[voice].panning = value;
1145}
1146
1147static void guswave_volume_method(int dev, int mode)
1148{
1149 if (mode == VOL_METHOD_LINEAR || mode == VOL_METHOD_ADAGIO)
1150 volume_method = mode;
1151}
1152
1153static void compute_volume(int voice, int volume)
1154{
1155 if (volume < 128)
1156 voices[voice].midi_volume = volume;
1157
1158 switch (volume_method)
1159 {
1160 case VOL_METHOD_ADAGIO:
1161 voices[voice].initial_volume =
1162 gus_adagio_vol(voices[voice].midi_volume, voices[voice].main_vol,
1163 voices[voice].expression_vol,
1164 voices[voice].patch_vol);
1165 break;
1166
1167 case VOL_METHOD_LINEAR: /* Totally ignores patch-volume and expression */
1168 voices[voice].initial_volume = gus_linear_vol(volume, voices[voice].main_vol);
1169 break;
1170
1171 default:
1172 voices[voice].initial_volume = volume_base +
1173 (voices[voice].midi_volume * volume_scale);
1174 }
1175
1176 if (voices[voice].initial_volume > 4030)
1177 voices[voice].initial_volume = 4030;
1178}
1179
1180static void compute_and_set_volume(int voice, int volume, int ramp_time)
1181{
1182 int curr, target, rate;
1183 unsigned long flags;
1184
1185 compute_volume(voice, volume);
1186 voices[voice].current_volume = voices[voice].initial_volume;
1187
1188 spin_lock_irqsave(&gus_lock,flags);
1189 /*
1190 * CAUTION! Interrupts disabled. Enable them before returning
1191 */
1192
1193 gus_select_voice(voice);
1194
1195 curr = gus_read16(0x09) >> 4;
1196 target = voices[voice].initial_volume;
1197
1198 if (ramp_time == INSTANT_RAMP)
1199 {
1200 gus_rampoff();
1201 gus_voice_volume(target);
1202 spin_unlock_irqrestore(&gus_lock,flags);
1203 return;
1204 }
1205 if (ramp_time == FAST_RAMP)
1206 rate = 63;
1207 else
1208 rate = 16;
1209 gus_ramp_rate(0, rate);
1210
1211 if ((target - curr) / 64 == 0) /* Close enough to target. */
1212 {
1213 gus_rampoff();
1214 gus_voice_volume(target);
1215 spin_unlock_irqrestore(&gus_lock,flags);
1216 return;
1217 }
1218 if (target > curr)
1219 {
1220 if (target > (4095 - 65))
1221 target = 4095 - 65;
1222 gus_ramp_range(curr, target);
1223 gus_rampon(0x00); /* Ramp up, once, no IRQ */
1224 }
1225 else
1226 {
1227 if (target < 65)
1228 target = 65;
1229
1230 gus_ramp_range(target, curr);
1231 gus_rampon(0x40); /* Ramp down, once, no irq */
1232 }
1233 spin_unlock_irqrestore(&gus_lock,flags);
1234}
1235
1236static void dynamic_volume_change(int voice)
1237{
1238 unsigned char status;
1239 unsigned long flags;
1240
1241 spin_lock_irqsave(&gus_lock,flags);
1242 gus_select_voice(voice);
1243 status = gus_read8(0x00); /* Get voice status */
1244 spin_unlock_irqrestore(&gus_lock,flags);
1245
1246 if (status & 0x03)
1247 return; /* Voice was not running */
1248
1249 if (!(voices[voice].mode & WAVE_ENVELOPES))
1250 {
1251 compute_and_set_volume(voice, voices[voice].midi_volume, 1);
1252 return;
1253 }
1254
1255 /*
1256 * Voice is running and has envelopes.
1257 */
1258
1259 spin_lock_irqsave(&gus_lock,flags);
1260 gus_select_voice(voice);
1261 status = gus_read8(0x0d); /* Ramping status */
1262 spin_unlock_irqrestore(&gus_lock,flags);
1263
1264 if (status & 0x03) /* Sustain phase? */
1265 {
1266 compute_and_set_volume(voice, voices[voice].midi_volume, 1);
1267 return;
1268 }
1269 if (voices[voice].env_phase < 0)
1270 return;
1271
1272 compute_volume(voice, voices[voice].midi_volume);
1273
1274}
1275
1276static void guswave_controller(int dev, int voice, int ctrl_num, int value)
1277{
1278 unsigned long flags;
1279 unsigned long freq;
1280
1281 if (voice < 0 || voice > 31)
1282 return;
1283
1284 switch (ctrl_num)
1285 {
1286 case CTRL_PITCH_BENDER:
1287 voices[voice].bender = value;
1288
1289 if (voices[voice].volume_irq_mode != VMODE_START_NOTE)
1290 {
1291 freq = compute_finetune(voices[voice].orig_freq, value, voices[voice].bender_range, 0);
1292 voices[voice].current_freq = freq;
1293
1294 spin_lock_irqsave(&gus_lock,flags);
1295 gus_select_voice(voice);
1296 gus_voice_freq(freq);
1297 spin_unlock_irqrestore(&gus_lock,flags);
1298 }
1299 break;
1300
1301 case CTRL_PITCH_BENDER_RANGE:
1302 voices[voice].bender_range = value;
1303 break;
1304 case CTL_EXPRESSION:
1305 value /= 128;
1306 case CTRL_EXPRESSION:
1307 if (volume_method == VOL_METHOD_ADAGIO)
1308 {
1309 voices[voice].expression_vol = value;
1310 if (voices[voice].volume_irq_mode != VMODE_START_NOTE)
1311 dynamic_volume_change(voice);
1312 }
1313 break;
1314
1315 case CTL_PAN:
1316 voices[voice].panning = (value * 2) - 128;
1317 break;
1318
1319 case CTL_MAIN_VOLUME:
1320 value = (value * 100) / 16383;
1321
1322 case CTRL_MAIN_VOLUME:
1323 voices[voice].main_vol = value;
1324 if (voices[voice].volume_irq_mode != VMODE_START_NOTE)
1325 dynamic_volume_change(voice);
1326 break;
1327
1328 default:
1329 break;
1330 }
1331}
1332
1333static int guswave_start_note2(int dev, int voice, int note_num, int volume)
1334{
1335 int sample, best_sample, best_delta, delta_freq;
1336 int is16bits, samplep, patch, pan;
1337 unsigned long note_freq, base_note, freq, flags;
1338 unsigned char mode = 0;
1339
1340 if (voice < 0 || voice > 31)
1341 {
1342/* printk("GUS: Invalid voice\n");*/
1343 return -EINVAL;
1344 }
1345 if (note_num == 255)
1346 {
1347 if (voices[voice].mode & WAVE_ENVELOPES)
1348 {
1349 voices[voice].midi_volume = volume;
1350 dynamic_volume_change(voice);
1351 return 0;
1352 }
1353 compute_and_set_volume(voice, volume, 1);
1354 return 0;
1355 }
1356 if ((patch = patch_map[voice]) == -1)
1357 return -EINVAL;
1358 if ((samplep = patch_table[patch]) == NOT_SAMPLE)
1359 {
1360 return -EINVAL;
1361 }
1362 note_freq = note_to_freq(note_num);
1363
1364 /*
1365 * Find a sample within a patch so that the note_freq is between low_note
1366 * and high_note.
1367 */
1368 sample = -1;
1369
1370 best_sample = samplep;
1371 best_delta = 1000000;
1372 while (samplep != 0 && samplep != NOT_SAMPLE && sample == -1)
1373 {
1374 delta_freq = note_freq - samples[samplep].base_note;
1375 if (delta_freq < 0)
1376 delta_freq = -delta_freq;
1377 if (delta_freq < best_delta)
1378 {
1379 best_sample = samplep;
1380 best_delta = delta_freq;
1381 }
1382 if (samples[samplep].low_note <= note_freq &&
1383 note_freq <= samples[samplep].high_note)
1384 {
1385 sample = samplep;
1386 }
1387 else
1388 samplep = samples[samplep].key; /* Link to next sample */
1389 }
1390 if (sample == -1)
1391 sample = best_sample;
1392
1393 if (sample == -1)
1394 {
1395/* printk("GUS: Patch %d not defined for note %d\n", patch, note_num);*/
1396 return 0; /* Should play default patch ??? */
1397 }
1398 is16bits = (samples[sample].mode & WAVE_16_BITS) ? 1 : 0;
1399 voices[voice].mode = samples[sample].mode;
1400 voices[voice].patch_vol = samples[sample].volume;
1401
1402 if (iw_mode)
1403 gus_write8(0x15, 0x00); /* RAM, Reset voice deactivate bit of SMSI */
1404
1405 if (voices[voice].mode & WAVE_ENVELOPES)
1406 {
1407 int i;
1408
1409 for (i = 0; i < 6; i++)
1410 {
1411 voices[voice].env_rate[i] = samples[sample].env_rate[i];
1412 voices[voice].env_offset[i] = samples[sample].env_offset[i];
1413 }
1414 }
1415 sample_map[voice] = sample;
1416
1417 if (voices[voice].fixed_pitch) /* Fixed pitch */
1418 {
1419 freq = samples[sample].base_freq;
1420 }
1421 else
1422 {
1423 base_note = samples[sample].base_note / 100;
1424 note_freq /= 100;
1425
1426 freq = samples[sample].base_freq * note_freq / base_note;
1427 }
1428
1429 voices[voice].orig_freq = freq;
1430
1431 /*
1432 * Since the pitch bender may have been set before playing the note, we
1433 * have to calculate the bending now.
1434 */
1435
1436 freq = compute_finetune(voices[voice].orig_freq, voices[voice].bender,
1437 voices[voice].bender_range, 0);
1438 voices[voice].current_freq = freq;
1439
1440 pan = (samples[sample].panning + voices[voice].panning) / 32;
1441 pan += 7;
1442 if (pan < 0)
1443 pan = 0;
1444 if (pan > 15)
1445 pan = 15;
1446
1447 if (samples[sample].mode & WAVE_16_BITS)
1448 {
1449 mode |= 0x04; /* 16 bits */
1450 if ((sample_ptrs[sample] / GUS_BANK_SIZE) !=
1451 ((sample_ptrs[sample] + samples[sample].len) / GUS_BANK_SIZE))
1452 printk(KERN_ERR "GUS: Sample address error\n");
1453 }
1454 spin_lock_irqsave(&gus_lock,flags);
1455 gus_select_voice(voice);
1456 gus_voice_off();
1457 gus_rampoff();
1458
1459 spin_unlock_irqrestore(&gus_lock,flags);
1460
1461 if (voices[voice].mode & WAVE_ENVELOPES)
1462 {
1463 compute_volume(voice, volume);
1464 init_envelope(voice);
1465 }
1466 else
1467 {
1468 compute_and_set_volume(voice, volume, 0);
1469 }
1470
1471 spin_lock_irqsave(&gus_lock,flags);
1472 gus_select_voice(voice);
1473
1474 if (samples[sample].mode & WAVE_LOOP_BACK)
1475 gus_write_addr(0x0a, sample_ptrs[sample] + samples[sample].len -
1476 voices[voice].offset_pending, 0, is16bits); /* start=end */
1477 else
1478 gus_write_addr(0x0a, sample_ptrs[sample] + voices[voice].offset_pending, 0, is16bits); /* Sample start=begin */
1479
1480 if (samples[sample].mode & WAVE_LOOPING)
1481 {
1482 mode |= 0x08;
1483
1484 if (samples[sample].mode & WAVE_BIDIR_LOOP)
1485 mode |= 0x10;
1486
1487 if (samples[sample].mode & WAVE_LOOP_BACK)
1488 {
1489 gus_write_addr(0x0a, sample_ptrs[sample] + samples[sample].loop_end -
1490 voices[voice].offset_pending,
1491 (samples[sample].fractions >> 4) & 0x0f, is16bits);
1492 mode |= 0x40;
1493 }
1494 gus_write_addr(0x02, sample_ptrs[sample] + samples[sample].loop_start,
1495 samples[sample].fractions & 0x0f, is16bits); /* Loop start location */
1496 gus_write_addr(0x04, sample_ptrs[sample] + samples[sample].loop_end,
1497 (samples[sample].fractions >> 4) & 0x0f, is16bits); /* Loop end location */
1498 }
1499 else
1500 {
1501 mode |= 0x20; /* Loop IRQ at the end */
1502 voices[voice].loop_irq_mode = LMODE_FINISH; /* Ramp down at the end */
1503 voices[voice].loop_irq_parm = 1;
1504 gus_write_addr(0x02, sample_ptrs[sample], 0, is16bits); /* Loop start location */
1505 gus_write_addr(0x04, sample_ptrs[sample] + samples[sample].len - 1,
1506 (samples[sample].fractions >> 4) & 0x0f, is16bits); /* Loop end location */
1507 }
1508 gus_voice_freq(freq);
1509 gus_voice_balance(pan);
1510 gus_voice_on(mode);
1511 spin_unlock_irqrestore(&gus_lock,flags);
1512
1513 return 0;
1514}
1515
1516/*
1517 * New guswave_start_note by Andrew J. Robinson attempts to minimize clicking
1518 * when the note playing on the voice is changed. It uses volume
1519 * ramping.
1520 */
1521
1522static int guswave_start_note(int dev, int voice, int note_num, int volume)
1523{
1524 unsigned long flags;
1525 int mode;
1526 int ret_val = 0;
1527
1528 spin_lock_irqsave(&gus_lock,flags);
1529 if (note_num == 255)
1530 {
1531 if (voices[voice].volume_irq_mode == VMODE_START_NOTE)
1532 {
1533 voices[voice].volume_pending = volume;
1534 }
1535 else
1536 {
1537 ret_val = guswave_start_note2(dev, voice, note_num, volume);
1538 }
1539 }
1540 else
1541 {
1542 gus_select_voice(voice);
1543 mode = gus_read8(0x00);
1544 if (mode & 0x20)
1545 gus_write8(0x00, mode & 0xdf); /* No interrupt! */
1546
1547 voices[voice].offset_pending = 0;
1548 voices[voice].kill_pending = 0;
1549 voices[voice].volume_irq_mode = 0;
1550 voices[voice].loop_irq_mode = 0;
1551
1552 if (voices[voice].sample_pending >= 0)
1553 {
1554 spin_unlock_irqrestore(&gus_lock,flags); /* Run temporarily with interrupts enabled */
1555 guswave_set_instr(voices[voice].dev_pending, voice, voices[voice].sample_pending);
1556 voices[voice].sample_pending = -1;
1557 spin_lock_irqsave(&gus_lock,flags);
1558 gus_select_voice(voice); /* Reselect the voice (just to be sure) */
1559 }
1560 if ((mode & 0x01) || (int) ((gus_read16(0x09) >> 4) < (unsigned) 2065))
1561 {
1562 ret_val = guswave_start_note2(dev, voice, note_num, volume);
1563 }
1564 else
1565 {
1566 voices[voice].dev_pending = dev;
1567 voices[voice].note_pending = note_num;
1568 voices[voice].volume_pending = volume;
1569 voices[voice].volume_irq_mode = VMODE_START_NOTE;
1570
1571 gus_rampoff();
1572 gus_ramp_range(2000, 4065);
1573 gus_ramp_rate(0, 63); /* Fastest possible rate */
1574 gus_rampon(0x20 | 0x40); /* Ramp down, once, irq */
1575 }
1576 }
1577 spin_unlock_irqrestore(&gus_lock,flags);
1578 return ret_val;
1579}
1580
1581static void guswave_reset(int dev)
1582{
1583 int i;
1584
1585 for (i = 0; i < 32; i++)
1586 {
1587 gus_voice_init(i);
1588 gus_voice_init2(i);
1589 }
1590}
1591
1592static int guswave_open(int dev, int mode)
1593{
1594 int err;
1595
1596 if (gus_busy)
1597 return -EBUSY;
1598
1599 voice_alloc->timestamp = 0;
1600
1601 if (gus_no_wave_dma) {
1602 gus_no_dma = 1;
1603 } else {
1604 if ((err = DMAbuf_open_dma(gus_devnum)) < 0)
1605 {
1606 /* printk( "GUS: Loading samples without DMA\n"); */
1607 gus_no_dma = 1; /* Upload samples using PIO */
1608 }
1609 else
1610 gus_no_dma = 0;
1611 }
1612
1613 init_waitqueue_head(&dram_sleeper);
1614 gus_busy = 1;
1615 active_device = GUS_DEV_WAVE;
1616
1617 gusintr(gus_irq, (void *)gus_hw_config, NULL); /* Serve pending interrupts */
1618 gus_initialize();
1619 gus_reset();
1620 gusintr(gus_irq, (void *)gus_hw_config, NULL); /* Serve pending interrupts */
1621
1622 return 0;
1623}
1624
1625static void guswave_close(int dev)
1626{
1627 gus_busy = 0;
1628 active_device = 0;
1629 gus_reset();
1630
1631 if (!gus_no_dma)
1632 DMAbuf_close_dma(gus_devnum);
1633}
1634
1635static int guswave_load_patch(int dev, int format, const char __user *addr,
1636 int offs, int count, int pmgr_flag)
1637{
1638 struct patch_info patch;
1639 int instr;
1640 long sizeof_patch;
1641
1642 unsigned long blk_sz, blk_end, left, src_offs, target;
1643
1644 sizeof_patch = (long) &patch.data[0] - (long) &patch; /* Header size */
1645
1646 if (format != GUS_PATCH)
1647 {
1648/* printk("GUS Error: Invalid patch format (key) 0x%x\n", format);*/
1649 return -EINVAL;
1650 }
1651 if (count < sizeof_patch)
1652 {
1653/* printk("GUS Error: Patch header too short\n");*/
1654 return -EINVAL;
1655 }
1656 count -= sizeof_patch;
1657
1658 if (free_sample >= MAX_SAMPLE)
1659 {
1660/* printk("GUS: Sample table full\n");*/
1661 return -ENOSPC;
1662 }
1663 /*
1664 * Copy the header from user space but ignore the first bytes which have
1665 * been transferred already.
1666 */
1667
1668 if (copy_from_user(&((char *) &patch)[offs], &(addr)[offs],
1669 sizeof_patch - offs))
1670 return -EFAULT;
1671
1672 if (patch.mode & WAVE_ROM)
1673 return -EINVAL;
1674 if (gus_mem_size == 0)
1675 return -ENOSPC;
1676
1677 instr = patch.instr_no;
1678
1679 if (instr < 0 || instr > MAX_PATCH)
1680 {
1681/* printk(KERN_ERR "GUS: Invalid patch number %d\n", instr);*/
1682 return -EINVAL;
1683 }
1684 if (count < patch.len)
1685 {
1686/* printk(KERN_ERR "GUS Warning: Patch record too short (%d<%d)\n", count, (int) patch.len);*/
1687 patch.len = count;
1688 }
1689 if (patch.len <= 0 || patch.len > gus_mem_size)
1690 {
1691/* printk(KERN_ERR "GUS: Invalid sample length %d\n", (int) patch.len);*/
1692 return -EINVAL;
1693 }
1694 if (patch.mode & WAVE_LOOPING)
1695 {
1696 if (patch.loop_start < 0 || patch.loop_start >= patch.len)
1697 {
1698/* printk(KERN_ERR "GUS: Invalid loop start\n");*/
1699 return -EINVAL;
1700 }
1701 if (patch.loop_end < patch.loop_start || patch.loop_end > patch.len)
1702 {
1703/* printk(KERN_ERR "GUS: Invalid loop end\n");*/
1704 return -EINVAL;
1705 }
1706 }
1707 free_mem_ptr = (free_mem_ptr + 31) & ~31; /* 32 byte alignment */
1708
1709 if (patch.mode & WAVE_16_BITS)
1710 {
1711 /*
1712 * 16 bit samples must fit one 256k bank.
1713 */
1714 if (patch.len >= GUS_BANK_SIZE)
1715 {
1716/* printk("GUS: Sample (16 bit) too long %d\n", (int) patch.len);*/
1717 return -ENOSPC;
1718 }
1719 if ((free_mem_ptr / GUS_BANK_SIZE) !=
1720 ((free_mem_ptr + patch.len) / GUS_BANK_SIZE))
1721 {
1722 unsigned long tmp_mem =
1723 /* Align to 256K */
1724 ((free_mem_ptr / GUS_BANK_SIZE) + 1) * GUS_BANK_SIZE;
1725
1726 if ((tmp_mem + patch.len) > gus_mem_size)
1727 return -ENOSPC;
1728
1729 free_mem_ptr = tmp_mem; /* This leaves unusable memory */
1730 }
1731 }
1732 if ((free_mem_ptr + patch.len) > gus_mem_size)
1733 return -ENOSPC;
1734
1735 sample_ptrs[free_sample] = free_mem_ptr;
1736
1737 /*
1738 * Tremolo is not possible with envelopes
1739 */
1740
1741 if (patch.mode & WAVE_ENVELOPES)
1742 patch.mode &= ~WAVE_TREMOLO;
1743
1744 if (!(patch.mode & WAVE_FRACTIONS))
1745 {
1746 patch.fractions = 0;
1747 }
1748 memcpy((char *) &samples[free_sample], &patch, sizeof_patch);
1749
1750 /*
1751 * Link this_one sample to the list of samples for patch 'instr'.
1752 */
1753
1754 samples[free_sample].key = patch_table[instr];
1755 patch_table[instr] = free_sample;
1756
1757 /*
1758 * Use DMA to transfer the wave data to the DRAM
1759 */
1760
1761 left = patch.len;
1762 src_offs = 0;
1763 target = free_mem_ptr;
1764
1765 while (left) /* Not completely transferred yet */
1766 {
1767 blk_sz = audio_devs[gus_devnum]->dmap_out->bytes_in_use;
1768 if (blk_sz > left)
1769 blk_sz = left;
1770
1771 /*
1772 * DMA cannot cross bank (256k) boundaries. Check for that.
1773 */
1774
1775 blk_end = target + blk_sz;
1776
1777 if ((target / GUS_BANK_SIZE) != (blk_end / GUS_BANK_SIZE))
1778 {
1779 /* Split the block */
1780 blk_end &= ~(GUS_BANK_SIZE - 1);
1781 blk_sz = blk_end - target;
1782 }
1783 if (gus_no_dma)
1784 {
1785 /*
1786 * For some reason the DMA is not possible. We have to use PIO.
1787 */
1788 long i;
1789 unsigned char data;
1790
1791 for (i = 0; i < blk_sz; i++)
1792 {
1793 get_user(*(unsigned char *) &data, (unsigned char __user *) &((addr)[sizeof_patch + i]));
1794 if (patch.mode & WAVE_UNSIGNED)
1795 if (!(patch.mode & WAVE_16_BITS) || (i & 0x01))
1796 data ^= 0x80; /* Convert to signed */
1797 gus_poke(target + i, data);
1798 }
1799 }
1800 else
1801 {
1802 unsigned long address, hold_address;
1803 unsigned char dma_command;
1804 unsigned long flags;
1805
1806 if (audio_devs[gus_devnum]->dmap_out->raw_buf == NULL)
1807 {
1808 printk(KERN_ERR "GUS: DMA buffer == NULL\n");
1809 return -ENOSPC;
1810 }
1811 /*
1812 * OK, move now. First in and then out.
1813 */
1814
1815 if (copy_from_user(audio_devs[gus_devnum]->dmap_out->raw_buf,
1816 &(addr)[sizeof_patch + src_offs],
1817 blk_sz))
1818 return -EFAULT;
1819
1820 spin_lock_irqsave(&gus_lock,flags);
1821 gus_write8(0x41, 0); /* Disable GF1 DMA */
1822 DMAbuf_start_dma(gus_devnum, audio_devs[gus_devnum]->dmap_out->raw_buf_phys,
1823 blk_sz, DMA_MODE_WRITE);
1824
1825 /*
1826 * Set the DRAM address for the wave data
1827 */
1828
1829 if (iw_mode)
1830 {
1831 /* Different address translation in enhanced mode */
1832
1833 unsigned char hi;
1834
1835 if (gus_dma > 4)
1836 address = target >> 1; /* Convert to 16 bit word address */
1837 else
1838 address = target;
1839
1840 hi = (unsigned char) ((address >> 16) & 0xf0);
1841 hi += (unsigned char) (address & 0x0f);
1842
1843 gus_write16(0x42, (address >> 4) & 0xffff); /* DMA address (low) */
1844 gus_write8(0x50, hi);
1845 }
1846 else
1847 {
1848 address = target;
1849 if (audio_devs[gus_devnum]->dmap_out->dma > 3)
1850 {
1851 hold_address = address;
1852 address = address >> 1;
1853 address &= 0x0001ffffL;
1854 address |= (hold_address & 0x000c0000L);
1855 }
1856 gus_write16(0x42, (address >> 4) & 0xffff); /* DRAM DMA address */
1857 }
1858
1859 /*
1860 * Start the DMA transfer
1861 */
1862
1863 dma_command = 0x21; /* IRQ enable, DMA start */
1864 if (patch.mode & WAVE_UNSIGNED)
1865 dma_command |= 0x80; /* Invert MSB */
1866 if (patch.mode & WAVE_16_BITS)
1867 dma_command |= 0x40; /* 16 bit _DATA_ */
1868 if (audio_devs[gus_devnum]->dmap_out->dma > 3)
1869 dma_command |= 0x04; /* 16 bit DMA _channel_ */
1870
1871 /*
1872 * Sleep here until the DRAM DMA done interrupt is served
1873 */
1874 active_device = GUS_DEV_WAVE;
1875 gus_write8(0x41, dma_command); /* Lets go luteet (=bugs) */
1876
1877 spin_unlock_irqrestore(&gus_lock,flags); /* opens a race */
1878 if (!interruptible_sleep_on_timeout(&dram_sleeper, HZ))
1879 printk("GUS: DMA Transfer timed out\n");
1880 }
1881
1882 /*
1883 * Now the next part
1884 */
1885
1886 left -= blk_sz;
1887 src_offs += blk_sz;
1888 target += blk_sz;
1889
1890 gus_write8(0x41, 0); /* Stop DMA */
1891 }
1892
1893 free_mem_ptr += patch.len;
1894 free_sample++;
1895 return 0;
1896}
1897
1898static void guswave_hw_control(int dev, unsigned char *event_rec)
1899{
1900 int voice, cmd;
1901 unsigned short p1, p2;
1902 unsigned int plong;
1903 unsigned long flags;
1904
1905 cmd = event_rec[2];
1906 voice = event_rec[3];
1907 p1 = *(unsigned short *) &event_rec[4];
1908 p2 = *(unsigned short *) &event_rec[6];
1909 plong = *(unsigned int *) &event_rec[4];
1910
1911 if ((voices[voice].volume_irq_mode == VMODE_START_NOTE) &&
1912 (cmd != _GUS_VOICESAMPLE) && (cmd != _GUS_VOICE_POS))
1913 do_volume_irq(voice);
1914
1915 switch (cmd)
1916 {
1917 case _GUS_NUMVOICES:
1918 spin_lock_irqsave(&gus_lock,flags);
1919 gus_select_voice(voice);
1920 gus_select_max_voices(p1);
1921 spin_unlock_irqrestore(&gus_lock,flags);
1922 break;
1923
1924 case _GUS_VOICESAMPLE:
1925 guswave_set_instr(dev, voice, p1);
1926 break;
1927
1928 case _GUS_VOICEON:
1929 spin_lock_irqsave(&gus_lock,flags);
1930 gus_select_voice(voice);
1931 p1 &= ~0x20; /* Don't allow interrupts */
1932 gus_voice_on(p1);
1933 spin_unlock_irqrestore(&gus_lock,flags);
1934 break;
1935
1936 case _GUS_VOICEOFF:
1937 spin_lock_irqsave(&gus_lock,flags);
1938 gus_select_voice(voice);
1939 gus_voice_off();
1940 spin_unlock_irqrestore(&gus_lock,flags);
1941 break;
1942
1943 case _GUS_VOICEFADE:
1944 gus_voice_fade(voice);
1945 break;
1946
1947 case _GUS_VOICEMODE:
1948 spin_lock_irqsave(&gus_lock,flags);
1949 gus_select_voice(voice);
1950 p1 &= ~0x20; /* Don't allow interrupts */
1951 gus_voice_mode(p1);
1952 spin_unlock_irqrestore(&gus_lock,flags);
1953 break;
1954
1955 case _GUS_VOICEBALA:
1956 spin_lock_irqsave(&gus_lock,flags);
1957 gus_select_voice(voice);
1958 gus_voice_balance(p1);
1959 spin_unlock_irqrestore(&gus_lock,flags);
1960 break;
1961
1962 case _GUS_VOICEFREQ:
1963 spin_lock_irqsave(&gus_lock,flags);
1964 gus_select_voice(voice);
1965 gus_voice_freq(plong);
1966 spin_unlock_irqrestore(&gus_lock,flags);
1967 break;
1968
1969 case _GUS_VOICEVOL:
1970 spin_lock_irqsave(&gus_lock,flags);
1971 gus_select_voice(voice);
1972 gus_voice_volume(p1);
1973 spin_unlock_irqrestore(&gus_lock,flags);
1974 break;
1975
1976 case _GUS_VOICEVOL2: /* Just update the software voice level */
1977 voices[voice].initial_volume = voices[voice].current_volume = p1;
1978 break;
1979
1980 case _GUS_RAMPRANGE:
1981 if (voices[voice].mode & WAVE_ENVELOPES)
1982 break; /* NO-NO */
1983 spin_lock_irqsave(&gus_lock,flags);
1984 gus_select_voice(voice);
1985 gus_ramp_range(p1, p2);
1986 spin_unlock_irqrestore(&gus_lock,flags);
1987 break;
1988
1989 case _GUS_RAMPRATE:
1990 if (voices[voice].mode & WAVE_ENVELOPES)
1991 break; /* NJET-NJET */
1992 spin_lock_irqsave(&gus_lock,flags);
1993 gus_select_voice(voice);
1994 gus_ramp_rate(p1, p2);
1995 spin_unlock_irqrestore(&gus_lock,flags);
1996 break;
1997
1998 case _GUS_RAMPMODE:
1999 if (voices[voice].mode & WAVE_ENVELOPES)
2000 break; /* NO-NO */
2001 spin_lock_irqsave(&gus_lock,flags);
2002 gus_select_voice(voice);
2003 p1 &= ~0x20; /* Don't allow interrupts */
2004 gus_ramp_mode(p1);
2005 spin_unlock_irqrestore(&gus_lock,flags);
2006 break;
2007
2008 case _GUS_RAMPON:
2009 if (voices[voice].mode & WAVE_ENVELOPES)
2010 break; /* EI-EI */
2011 spin_lock_irqsave(&gus_lock,flags);
2012 gus_select_voice(voice);
2013 p1 &= ~0x20; /* Don't allow interrupts */
2014 gus_rampon(p1);
2015 spin_unlock_irqrestore(&gus_lock,flags);
2016 break;
2017
2018 case _GUS_RAMPOFF:
2019 if (voices[voice].mode & WAVE_ENVELOPES)
2020 break; /* NEJ-NEJ */
2021 spin_lock_irqsave(&gus_lock,flags);
2022 gus_select_voice(voice);
2023 gus_rampoff();
2024 spin_unlock_irqrestore(&gus_lock,flags);
2025 break;
2026
2027 case _GUS_VOLUME_SCALE:
2028 volume_base = p1;
2029 volume_scale = p2;
2030 break;
2031
2032 case _GUS_VOICE_POS:
2033 spin_lock_irqsave(&gus_lock,flags);
2034 gus_select_voice(voice);
2035 gus_set_voice_pos(voice, plong);
2036 spin_unlock_irqrestore(&gus_lock,flags);
2037 break;
2038
2039 default:
2040 break;
2041 }
2042}
2043
2044static int gus_audio_set_speed(int speed)
2045{
2046 if (speed <= 0)
2047 speed = gus_audio_speed;
2048
2049 if (speed < 4000)
2050 speed = 4000;
2051
2052 if (speed > 44100)
2053 speed = 44100;
2054
2055 gus_audio_speed = speed;
2056
2057 if (only_read_access)
2058 {
2059 /* Compute nearest valid recording speed and return it */
2060
2061 /* speed = (9878400 / (gus_audio_speed + 2)) / 16; */
2062 speed = (((9878400 + gus_audio_speed / 2) / (gus_audio_speed + 2)) + 8) / 16;
2063 speed = (9878400 / (speed * 16)) - 2;
2064 }
2065 return speed;
2066}
2067
2068static int gus_audio_set_channels(int channels)
2069{
2070 if (!channels)
2071 return gus_audio_channels;
2072 if (channels > 2)
2073 channels = 2;
2074 if (channels < 1)
2075 channels = 1;
2076 gus_audio_channels = channels;
2077 return channels;
2078}
2079
2080static int gus_audio_set_bits(int bits)
2081{
2082 if (!bits)
2083 return gus_audio_bits;
2084
2085 if (bits != 8 && bits != 16)
2086 bits = 8;
2087
2088 if (only_8_bits)
2089 bits = 8;
2090
2091 gus_audio_bits = bits;
2092 return bits;
2093}
2094
2095static int gus_audio_ioctl(int dev, unsigned int cmd, void __user *arg)
2096{
2097 int val;
2098
2099 switch (cmd)
2100 {
2101 case SOUND_PCM_WRITE_RATE:
2102 if (get_user(val, (int __user*)arg))
2103 return -EFAULT;
2104 val = gus_audio_set_speed(val);
2105 break;
2106
2107 case SOUND_PCM_READ_RATE:
2108 val = gus_audio_speed;
2109 break;
2110
2111 case SNDCTL_DSP_STEREO:
2112 if (get_user(val, (int __user *)arg))
2113 return -EFAULT;
2114 val = gus_audio_set_channels(val + 1) - 1;
2115 break;
2116
2117 case SOUND_PCM_WRITE_CHANNELS:
2118 if (get_user(val, (int __user *)arg))
2119 return -EFAULT;
2120 val = gus_audio_set_channels(val);
2121 break;
2122
2123 case SOUND_PCM_READ_CHANNELS:
2124 val = gus_audio_channels;
2125 break;
2126
2127 case SNDCTL_DSP_SETFMT:
2128 if (get_user(val, (int __user *)arg))
2129 return -EFAULT;
2130 val = gus_audio_set_bits(val);
2131 break;
2132
2133 case SOUND_PCM_READ_BITS:
2134 val = gus_audio_bits;
2135 break;
2136
2137 case SOUND_PCM_WRITE_FILTER: /* NOT POSSIBLE */
2138 case SOUND_PCM_READ_FILTER:
2139 val = -EINVAL;
2140 break;
2141 default:
2142 return -EINVAL;
2143 }
2144 return put_user(val, (int __user *)arg);
2145}
2146
2147static void gus_audio_reset(int dev)
2148{
2149 if (recording_active)
2150 {
2151 gus_write8(0x49, 0x00); /* Halt recording */
2152 set_input_volumes();
2153 }
2154}
2155
2156static int saved_iw_mode; /* A hack hack hack */
2157
2158static int gus_audio_open(int dev, int mode)
2159{
2160 if (gus_busy)
2161 return -EBUSY;
2162
2163 if (gus_pnp_flag && mode & OPEN_READ)
2164 {
2165/* printk(KERN_ERR "GUS: Audio device #%d is playback only.\n", dev);*/
2166 return -EIO;
2167 }
2168 gus_initialize();
2169
2170 gus_busy = 1;
2171 active_device = 0;
2172
2173 saved_iw_mode = iw_mode;
2174 if (iw_mode)
2175 {
2176 /* There are some problems with audio in enhanced mode so disable it */
2177 gus_write8(0x19, gus_read8(0x19) & ~0x01); /* Disable enhanced mode */
2178 iw_mode = 0;
2179 }
2180
2181 gus_reset();
2182 reset_sample_memory();
2183 gus_select_max_voices(14);
2184
2185 pcm_active = 0;
2186 dma_active = 0;
2187 pcm_opened = 1;
2188 if (mode & OPEN_READ)
2189 {
2190 recording_active = 1;
2191 set_input_volumes();
2192 }
2193 only_read_access = !(mode & OPEN_WRITE);
2194 only_8_bits = mode & OPEN_READ;
2195 if (only_8_bits)
2196 audio_devs[dev]->format_mask = AFMT_U8;
2197 else
2198 audio_devs[dev]->format_mask = AFMT_U8 | AFMT_S16_LE;
2199
2200 return 0;
2201}
2202
2203static void gus_audio_close(int dev)
2204{
2205 iw_mode = saved_iw_mode;
2206 gus_reset();
2207 gus_busy = 0;
2208 pcm_opened = 0;
2209 active_device = 0;
2210
2211 if (recording_active)
2212 {
2213 gus_write8(0x49, 0x00); /* Halt recording */
2214 set_input_volumes();
2215 }
2216 recording_active = 0;
2217}
2218
2219static void gus_audio_update_volume(void)
2220{
2221 unsigned long flags;
2222 int voice;
2223
2224 if (pcm_active && pcm_opened)
2225 for (voice = 0; voice < gus_audio_channels; voice++)
2226 {
2227 spin_lock_irqsave(&gus_lock,flags);
2228 gus_select_voice(voice);
2229 gus_rampoff();
2230 gus_voice_volume(1530 + (25 * gus_pcm_volume));
2231 gus_ramp_range(65, 1530 + (25 * gus_pcm_volume));
2232 spin_unlock_irqrestore(&gus_lock,flags);
2233 }
2234}
2235
2236static void play_next_pcm_block(void)
2237{
2238 unsigned long flags;
2239 int speed = gus_audio_speed;
2240 int this_one, is16bits, chn;
2241 unsigned long dram_loc;
2242 unsigned char mode[2], ramp_mode[2];
2243
2244 if (!pcm_qlen)
2245 return;
2246
2247 this_one = pcm_head;
2248
2249 for (chn = 0; chn < gus_audio_channels; chn++)
2250 {
2251 mode[chn] = 0x00;
2252 ramp_mode[chn] = 0x03; /* Ramping and rollover off */
2253
2254 if (chn == 0)
2255 {
2256 mode[chn] |= 0x20; /* Loop IRQ */
2257 voices[chn].loop_irq_mode = LMODE_PCM;
2258 }
2259 if (gus_audio_bits != 8)
2260 {
2261 is16bits = 1;
2262 mode[chn] |= 0x04; /* 16 bit data */
2263 }
2264 else
2265 is16bits = 0;
2266
2267 dram_loc = this_one * pcm_bsize;
2268 dram_loc += chn * pcm_banksize;
2269
2270 if (this_one == (pcm_nblk - 1)) /* Last fragment of the DRAM buffer */
2271 {
2272 mode[chn] |= 0x08; /* Enable loop */
2273 ramp_mode[chn] = 0x03; /* Disable rollover bit */
2274 }
2275 else
2276 {
2277 if (chn == 0)
2278 ramp_mode[chn] = 0x04; /* Enable rollover bit */
2279 }
2280 spin_lock_irqsave(&gus_lock,flags);
2281 gus_select_voice(chn);
2282 gus_voice_freq(speed);
2283
2284 if (gus_audio_channels == 1)
2285 gus_voice_balance(7); /* mono */
2286 else if (chn == 0)
2287 gus_voice_balance(0); /* left */
2288 else
2289 gus_voice_balance(15); /* right */
2290
2291 if (!pcm_active) /* Playback not already active */
2292 {
2293 /*
2294 * The playback was not started yet (or there has been a pause).
2295 * Start the voice (again) and ask for a rollover irq at the end of
2296 * this_one block. If this_one one is last of the buffers, use just
2297 * the normal loop with irq.
2298 */
2299
2300 gus_voice_off();
2301 gus_rampoff();
2302 gus_voice_volume(1530 + (25 * gus_pcm_volume));
2303 gus_ramp_range(65, 1530 + (25 * gus_pcm_volume));
2304
2305 gus_write_addr(0x0a, chn * pcm_banksize, 0, is16bits); /* Starting position */
2306 gus_write_addr(0x02, chn * pcm_banksize, 0, is16bits); /* Loop start */
2307
2308 if (chn != 0)
2309 gus_write_addr(0x04, pcm_banksize + (pcm_bsize * pcm_nblk) - 1,
2310 0, is16bits); /* Loop end location */
2311 }
2312 if (chn == 0)
2313 gus_write_addr(0x04, dram_loc + pcm_bsize - 1,
2314 0, is16bits); /* Loop end location */
2315 else
2316 mode[chn] |= 0x08; /* Enable looping */
2317 spin_unlock_irqrestore(&gus_lock,flags);
2318 }
2319 for (chn = 0; chn < gus_audio_channels; chn++)
2320 {
2321 spin_lock_irqsave(&gus_lock,flags);
2322 gus_select_voice(chn);
2323 gus_write8(0x0d, ramp_mode[chn]);
2324 if (iw_mode)
2325 gus_write8(0x15, 0x00); /* Reset voice deactivate bit of SMSI */
2326 gus_voice_on(mode[chn]);
2327 spin_unlock_irqrestore(&gus_lock,flags);
2328 }
2329 pcm_active = 1;
2330}
2331
2332static void gus_transfer_output_block(int dev, unsigned long buf,
2333 int total_count, int intrflag, int chn)
2334{
2335 /*
2336 * This routine transfers one block of audio data to the DRAM. In mono mode
2337 * it's called just once. When in stereo mode, this_one routine is called
2338 * once for both channels.
2339 *
2340 * The left/mono channel data is transferred to the beginning of dram and the
2341 * right data to the area pointed by gus_page_size.
2342 */
2343
2344 int this_one, count;
2345 unsigned long flags;
2346 unsigned char dma_command;
2347 unsigned long address, hold_address;
2348
2349 spin_lock_irqsave(&gus_lock,flags);
2350
2351 count = total_count / gus_audio_channels;
2352
2353 if (chn == 0)
2354 {
2355 if (pcm_qlen >= pcm_nblk)
2356 printk(KERN_WARNING "GUS Warning: PCM buffers out of sync\n");
2357
2358 this_one = pcm_current_block = pcm_tail;
2359 pcm_qlen++;
2360 pcm_tail = (pcm_tail + 1) % pcm_nblk;
2361 pcm_datasize[this_one] = count;
2362 }
2363 else
2364 this_one = pcm_current_block;
2365
2366 gus_write8(0x41, 0); /* Disable GF1 DMA */
2367 DMAbuf_start_dma(dev, buf + (chn * count), count, DMA_MODE_WRITE);
2368
2369 address = this_one * pcm_bsize;
2370 address += chn * pcm_banksize;
2371
2372 if (audio_devs[dev]->dmap_out->dma > 3)
2373 {
2374 hold_address = address;
2375 address = address >> 1;
2376 address &= 0x0001ffffL;
2377 address |= (hold_address & 0x000c0000L);
2378 }
2379 gus_write16(0x42, (address >> 4) & 0xffff); /* DRAM DMA address */
2380
2381 dma_command = 0x21; /* IRQ enable, DMA start */
2382
2383 if (gus_audio_bits != 8)
2384 dma_command |= 0x40; /* 16 bit _DATA_ */
2385 else
2386 dma_command |= 0x80; /* Invert MSB */
2387
2388 if (audio_devs[dev]->dmap_out->dma > 3)
2389 dma_command |= 0x04; /* 16 bit DMA channel */
2390
2391 gus_write8(0x41, dma_command); /* Kick start */
2392
2393 if (chn == (gus_audio_channels - 1)) /* Last channel */
2394 {
2395 /*
2396 * Last (right or mono) channel data
2397 */
2398 dma_active = 1; /* DMA started. There is a unacknowledged buffer */
2399 active_device = GUS_DEV_PCM_DONE;
2400 if (!pcm_active && (pcm_qlen > 1 || count < pcm_bsize))
2401 {
2402 play_next_pcm_block();
2403 }
2404 }
2405 else
2406 {
2407 /*
2408 * Left channel data. The right channel
2409 * is transferred after DMA interrupt
2410 */
2411 active_device = GUS_DEV_PCM_CONTINUE;
2412 }
2413
2414 spin_unlock_irqrestore(&gus_lock,flags);
2415}
2416
2417static void gus_uninterleave8(char *buf, int l)
2418{
2419/* This routine uninterleaves 8 bit stereo output (LRLRLR->LLLRRR) */
2420 int i, p = 0, halfsize = l / 2;
2421 char *buf2 = buf + halfsize, *src = bounce_buf;
2422
2423 memcpy(bounce_buf, buf, l);
2424
2425 for (i = 0; i < halfsize; i++)
2426 {
2427 buf[i] = src[p++]; /* Left channel */
2428 buf2[i] = src[p++]; /* Right channel */
2429 }
2430}
2431
2432static void gus_uninterleave16(short *buf, int l)
2433{
2434/* This routine uninterleaves 16 bit stereo output (LRLRLR->LLLRRR) */
2435 int i, p = 0, halfsize = l / 2;
2436 short *buf2 = buf + halfsize, *src = (short *) bounce_buf;
2437
2438 memcpy(bounce_buf, (char *) buf, l * 2);
2439
2440 for (i = 0; i < halfsize; i++)
2441 {
2442 buf[i] = src[p++]; /* Left channel */
2443 buf2[i] = src[p++]; /* Right channel */
2444 }
2445}
2446
2447static void gus_audio_output_block(int dev, unsigned long buf, int total_count,
2448 int intrflag)
2449{
2450 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
2451
2452 dmap->flags |= DMA_NODMA | DMA_NOTIMEOUT;
2453
2454 pcm_current_buf = buf;
2455 pcm_current_count = total_count;
2456 pcm_current_intrflag = intrflag;
2457 pcm_current_dev = dev;
2458 if (gus_audio_channels == 2)
2459 {
2460 char *b = dmap->raw_buf + (buf - dmap->raw_buf_phys);
2461
2462 if (gus_audio_bits == 8)
2463 gus_uninterleave8(b, total_count);
2464 else
2465 gus_uninterleave16((short *) b, total_count / 2);
2466 }
2467 gus_transfer_output_block(dev, buf, total_count, intrflag, 0);
2468}
2469
2470static void gus_audio_start_input(int dev, unsigned long buf, int count,
2471 int intrflag)
2472{
2473 unsigned long flags;
2474 unsigned char mode;
2475
2476 spin_lock_irqsave(&gus_lock,flags);
2477
2478 DMAbuf_start_dma(dev, buf, count, DMA_MODE_READ);
2479 mode = 0xa0; /* DMA IRQ enabled, invert MSB */
2480
2481 if (audio_devs[dev]->dmap_in->dma > 3)
2482 mode |= 0x04; /* 16 bit DMA channel */
2483 if (gus_audio_channels > 1)
2484 mode |= 0x02; /* Stereo */
2485 mode |= 0x01; /* DMA enable */
2486
2487 gus_write8(0x49, mode);
2488 spin_unlock_irqrestore(&gus_lock,flags);
2489}
2490
2491static int gus_audio_prepare_for_input(int dev, int bsize, int bcount)
2492{
2493 unsigned int rate;
2494
2495 gus_audio_bsize = bsize;
2496 audio_devs[dev]->dmap_in->flags |= DMA_NODMA;
2497 rate = (((9878400 + gus_audio_speed / 2) / (gus_audio_speed + 2)) + 8) / 16;
2498
2499 gus_write8(0x48, rate & 0xff); /* Set sampling rate */
2500
2501 if (gus_audio_bits != 8)
2502 {
2503/* printk("GUS Error: 16 bit recording not supported\n");*/
2504 return -EINVAL;
2505 }
2506 return 0;
2507}
2508
2509static int gus_audio_prepare_for_output(int dev, int bsize, int bcount)
2510{
2511 int i;
2512
2513 long mem_ptr, mem_size;
2514
2515 audio_devs[dev]->dmap_out->flags |= DMA_NODMA | DMA_NOTIMEOUT;
2516 mem_ptr = 0;
2517 mem_size = gus_mem_size / gus_audio_channels;
2518
2519 if (mem_size > (256 * 1024))
2520 mem_size = 256 * 1024;
2521
2522 pcm_bsize = bsize / gus_audio_channels;
2523 pcm_head = pcm_tail = pcm_qlen = 0;
2524
2525 pcm_nblk = 2; /* MAX_PCM_BUFFERS; */
2526 if ((pcm_bsize * pcm_nblk) > mem_size)
2527 pcm_nblk = mem_size / pcm_bsize;
2528
2529 for (i = 0; i < pcm_nblk; i++)
2530 pcm_datasize[i] = 0;
2531
2532 pcm_banksize = pcm_nblk * pcm_bsize;
2533
2534 if (gus_audio_bits != 8 && pcm_banksize == (256 * 1024))
2535 pcm_nblk--;
2536 gus_write8(0x41, 0); /* Disable GF1 DMA */
2537 return 0;
2538}
2539
2540static int gus_local_qlen(int dev)
2541{
2542 return pcm_qlen;
2543}
2544
2545
2546static struct audio_driver gus_audio_driver =
2547{
2548 .owner = THIS_MODULE,
2549 .open = gus_audio_open,
2550 .close = gus_audio_close,
2551 .output_block = gus_audio_output_block,
2552 .start_input = gus_audio_start_input,
2553 .ioctl = gus_audio_ioctl,
2554 .prepare_for_input = gus_audio_prepare_for_input,
2555 .prepare_for_output = gus_audio_prepare_for_output,
2556 .halt_io = gus_audio_reset,
2557 .local_qlen = gus_local_qlen,
2558};
2559
2560static void guswave_setup_voice(int dev, int voice, int chn)
2561{
2562 struct channel_info *info = &synth_devs[dev]->chn_info[chn];
2563
2564 guswave_set_instr(dev, voice, info->pgm_num);
2565 voices[voice].expression_vol = info->controllers[CTL_EXPRESSION]; /* Just MSB */
2566 voices[voice].main_vol = (info->controllers[CTL_MAIN_VOLUME] * 100) / (unsigned) 128;
2567 voices[voice].panning = (info->controllers[CTL_PAN] * 2) - 128;
2568 voices[voice].bender = 0;
2569 voices[voice].bender_range = info->bender_range;
2570
2571 if (chn == 9)
2572 voices[voice].fixed_pitch = 1;
2573}
2574
2575static void guswave_bender(int dev, int voice, int value)
2576{
2577 int freq;
2578 unsigned long flags;
2579
2580 voices[voice].bender = value - 8192;
2581 freq = compute_finetune(voices[voice].orig_freq, value - 8192, voices[voice].bender_range, 0);
2582 voices[voice].current_freq = freq;
2583
2584 spin_lock_irqsave(&gus_lock,flags);
2585 gus_select_voice(voice);
2586 gus_voice_freq(freq);
2587 spin_unlock_irqrestore(&gus_lock,flags);
2588}
2589
2590static int guswave_alloc(int dev, int chn, int note, struct voice_alloc_info *alloc)
2591{
2592 int i, p, best = -1, best_time = 0x7fffffff;
2593
2594 p = alloc->ptr;
2595 /*
2596 * First look for a completely stopped voice
2597 */
2598
2599 for (i = 0; i < alloc->max_voice; i++)
2600 {
2601 if (alloc->map[p] == 0)
2602 {
2603 alloc->ptr = p;
2604 return p;
2605 }
2606 if (alloc->alloc_times[p] < best_time)
2607 {
2608 best = p;
2609 best_time = alloc->alloc_times[p];
2610 }
2611 p = (p + 1) % alloc->max_voice;
2612 }
2613
2614 /*
2615 * Then look for a releasing voice
2616 */
2617
2618 for (i = 0; i < alloc->max_voice; i++)
2619 {
2620 if (alloc->map[p] == 0xffff)
2621 {
2622 alloc->ptr = p;
2623 return p;
2624 }
2625 p = (p + 1) % alloc->max_voice;
2626 }
2627 if (best >= 0)
2628 p = best;
2629
2630 alloc->ptr = p;
2631 return p;
2632}
2633
2634static struct synth_operations guswave_operations =
2635{
2636 .owner = THIS_MODULE,
2637 .id = "GUS",
2638 .info = &gus_info,
2639 .midi_dev = 0,
2640 .synth_type = SYNTH_TYPE_SAMPLE,
2641 .synth_subtype = SAMPLE_TYPE_GUS,
2642 .open = guswave_open,
2643 .close = guswave_close,
2644 .ioctl = guswave_ioctl,
2645 .kill_note = guswave_kill_note,
2646 .start_note = guswave_start_note,
2647 .set_instr = guswave_set_instr,
2648 .reset = guswave_reset,
2649 .hw_control = guswave_hw_control,
2650 .load_patch = guswave_load_patch,
2651 .aftertouch = guswave_aftertouch,
2652 .controller = guswave_controller,
2653 .panning = guswave_panning,
2654 .volume_method = guswave_volume_method,
2655 .bender = guswave_bender,
2656 .alloc_voice = guswave_alloc,
2657 .setup_voice = guswave_setup_voice
2658};
2659
2660static void set_input_volumes(void)
2661{
2662 unsigned long flags;
2663 unsigned char mask = 0xff & ~0x06; /* Just line out enabled */
2664
2665 if (have_gus_max) /* Don't disturb GUS MAX */
2666 return;
2667
2668 spin_lock_irqsave(&gus_lock,flags);
2669
2670 /*
2671 * Enable channels having vol > 10%
2672 * Note! bit 0x01 means the line in DISABLED while 0x04 means
2673 * the mic in ENABLED.
2674 */
2675 if (gus_line_vol > 10)
2676 mask &= ~0x01;
2677 if (gus_mic_vol > 10)
2678 mask |= 0x04;
2679
2680 if (recording_active)
2681 {
2682 /*
2683 * Disable channel, if not selected for recording
2684 */
2685 if (!(gus_recmask & SOUND_MASK_LINE))
2686 mask |= 0x01;
2687 if (!(gus_recmask & SOUND_MASK_MIC))
2688 mask &= ~0x04;
2689 }
2690 mix_image &= ~0x07;
2691 mix_image |= mask & 0x07;
2692 outb((mix_image), u_Mixer);
2693
2694 spin_unlock_irqrestore(&gus_lock,flags);
2695}
2696
2697#define MIX_DEVS (SOUND_MASK_MIC|SOUND_MASK_LINE| \
2698 SOUND_MASK_SYNTH|SOUND_MASK_PCM)
2699
2700int gus_default_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
2701{
2702 int vol, val;
2703
2704 if (((cmd >> 8) & 0xff) != 'M')
2705 return -EINVAL;
2706
2707 if (!access_ok(VERIFY_WRITE, arg, sizeof(int)))
2708 return -EFAULT;
2709
2710 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
2711 {
2712 if (__get_user(val, (int __user *) arg))
2713 return -EFAULT;
2714
2715 switch (cmd & 0xff)
2716 {
2717 case SOUND_MIXER_RECSRC:
2718 gus_recmask = val & MIX_DEVS;
2719 if (!(gus_recmask & (SOUND_MASK_MIC | SOUND_MASK_LINE)))
2720 gus_recmask = SOUND_MASK_MIC;
2721 /* Note! Input volumes are updated during next open for recording */
2722 val = gus_recmask;
2723 break;
2724
2725 case SOUND_MIXER_MIC:
2726 vol = val & 0xff;
2727 if (vol < 0)
2728 vol = 0;
2729 if (vol > 100)
2730 vol = 100;
2731 gus_mic_vol = vol;
2732 set_input_volumes();
2733 val = vol | (vol << 8);
2734 break;
2735
2736 case SOUND_MIXER_LINE:
2737 vol = val & 0xff;
2738 if (vol < 0)
2739 vol = 0;
2740 if (vol > 100)
2741 vol = 100;
2742 gus_line_vol = vol;
2743 set_input_volumes();
2744 val = vol | (vol << 8);
2745 break;
2746
2747 case SOUND_MIXER_PCM:
2748 gus_pcm_volume = val & 0xff;
2749 if (gus_pcm_volume < 0)
2750 gus_pcm_volume = 0;
2751 if (gus_pcm_volume > 100)
2752 gus_pcm_volume = 100;
2753 gus_audio_update_volume();
2754 val = gus_pcm_volume | (gus_pcm_volume << 8);
2755 break;
2756
2757 case SOUND_MIXER_SYNTH:
2758 gus_wave_volume = val & 0xff;
2759 if (gus_wave_volume < 0)
2760 gus_wave_volume = 0;
2761 if (gus_wave_volume > 100)
2762 gus_wave_volume = 100;
2763 if (active_device == GUS_DEV_WAVE)
2764 {
2765 int voice;
2766 for (voice = 0; voice < nr_voices; voice++)
2767 dynamic_volume_change(voice); /* Apply the new vol */
2768 }
2769 val = gus_wave_volume | (gus_wave_volume << 8);
2770 break;
2771
2772 default:
2773 return -EINVAL;
2774 }
2775 }
2776 else
2777 {
2778 switch (cmd & 0xff)
2779 {
2780 /*
2781 * Return parameters
2782 */
2783 case SOUND_MIXER_RECSRC:
2784 val = gus_recmask;
2785 break;
2786
2787 case SOUND_MIXER_DEVMASK:
2788 val = MIX_DEVS;
2789 break;
2790
2791 case SOUND_MIXER_STEREODEVS:
2792 val = 0;
2793 break;
2794
2795 case SOUND_MIXER_RECMASK:
2796 val = SOUND_MASK_MIC | SOUND_MASK_LINE;
2797 break;
2798
2799 case SOUND_MIXER_CAPS:
2800 val = 0;
2801 break;
2802
2803 case SOUND_MIXER_MIC:
2804 val = gus_mic_vol | (gus_mic_vol << 8);
2805 break;
2806
2807 case SOUND_MIXER_LINE:
2808 val = gus_line_vol | (gus_line_vol << 8);
2809 break;
2810
2811 case SOUND_MIXER_PCM:
2812 val = gus_pcm_volume | (gus_pcm_volume << 8);
2813 break;
2814
2815 case SOUND_MIXER_SYNTH:
2816 val = gus_wave_volume | (gus_wave_volume << 8);
2817 break;
2818
2819 default:
2820 return -EINVAL;
2821 }
2822 }
2823 return __put_user(val, (int __user *)arg);
2824}
2825
2826static struct mixer_operations gus_mixer_operations =
2827{
2828 .owner = THIS_MODULE,
2829 .id = "GUS",
2830 .name = "Gravis Ultrasound",
2831 .ioctl = gus_default_mixer_ioctl
2832};
2833
2834static int __init gus_default_mixer_init(void)
2835{
2836 int n;
2837
2838 if ((n = sound_alloc_mixerdev()) != -1)
2839 {
2840 /*
2841 * Don't install if there is another
2842 * mixer
2843 */
2844 mixer_devs[n] = &gus_mixer_operations;
2845 }
2846 if (have_gus_max)
2847 {
2848 /*
2849 * Enable all mixer channels on the GF1 side. Otherwise recording will
2850 * not be possible using GUS MAX.
2851 */
2852 mix_image &= ~0x07;
2853 mix_image |= 0x04; /* All channels enabled */
2854 outb((mix_image), u_Mixer);
2855 }
2856 return n;
2857}
2858
2859void __init gus_wave_init(struct address_info *hw_config)
2860{
2861 unsigned long flags;
2862 unsigned char val;
2863 char *model_num = "2.4";
2864 char tmp[64];
2865 int gus_type = 0x24; /* 2.4 */
2866
2867 int irq = hw_config->irq, dma = hw_config->dma, dma2 = hw_config->dma2;
2868 int sdev;
2869
2870 hw_config->slots[0] = -1; /* No wave */
2871 hw_config->slots[1] = -1; /* No ad1848 */
2872 hw_config->slots[4] = -1; /* No audio */
2873 hw_config->slots[5] = -1; /* No mixer */
2874
2875 if (!gus_pnp_flag)
2876 {
2877 if (irq < 0 || irq > 15)
2878 {
2879 printk(KERN_ERR "ERROR! Invalid IRQ#%d. GUS Disabled", irq);
2880 return;
2881 }
2882 }
2883
2884 if (dma < 0 || dma > 7 || dma == 4)
2885 {
2886 printk(KERN_ERR "ERROR! Invalid DMA#%d. GUS Disabled", dma);
2887 return;
2888 }
2889 gus_irq = irq;
2890 gus_dma = dma;
2891 gus_dma2 = dma2;
2892 gus_hw_config = hw_config;
2893
2894 if (gus_dma2 == -1)
2895 gus_dma2 = dma;
2896
2897 /*
2898 * Try to identify the GUS model.
2899 *
2900 * Versions < 3.6 don't have the digital ASIC. Try to probe it first.
2901 */
2902
2903 spin_lock_irqsave(&gus_lock,flags);
2904 outb((0x20), gus_base + 0x0f);
2905 val = inb(gus_base + 0x0f);
2906 spin_unlock_irqrestore(&gus_lock,flags);
2907
2908 if (gus_pnp_flag || (val != 0xff && (val & 0x06))) /* Should be 0x02?? */
2909 {
2910 int ad_flags = 0;
2911
2912 if (gus_pnp_flag)
2913 ad_flags = 0x12345678; /* Interwave "magic" */
2914 /*
2915 * It has the digital ASIC so the card is at least v3.4.
2916 * Next try to detect the true model.
2917 */
2918
2919 if (gus_pnp_flag) /* Hack hack hack */
2920 val = 10;
2921 else
2922 val = inb(u_MixSelect);
2923
2924 /*
2925 * Value 255 means pre-3.7 which don't have mixer.
2926 * Values 5 thru 9 mean v3.7 which has a ICS2101 mixer.
2927 * 10 and above is GUS MAX which has the CS4231 codec/mixer.
2928 *
2929 */
2930
2931 if (val == 255 || val < 5)
2932 {
2933 model_num = "3.4";
2934 gus_type = 0x34;
2935 }
2936 else if (val < 10)
2937 {
2938 model_num = "3.7";
2939 gus_type = 0x37;
2940 mixer_type = ICS2101;
2941 request_region(u_MixSelect, 1, "GUS mixer");
2942 }
2943 else
2944 {
2945 struct resource *ports;
2946 ports = request_region(gus_base + 0x10c, 4, "ad1848");
2947 model_num = "MAX";
2948 gus_type = 0x40;
2949 mixer_type = CS4231;
2950#ifdef CONFIG_SOUND_GUSMAX
2951 {
2952 unsigned char max_config = 0x40; /* Codec enable */
2953
2954 if (gus_dma2 == -1)
2955 gus_dma2 = gus_dma;
2956
2957 if (gus_dma > 3)
2958 max_config |= 0x10; /* 16 bit capture DMA */
2959
2960 if (gus_dma2 > 3)
2961 max_config |= 0x20; /* 16 bit playback DMA */
2962
2963 max_config |= (gus_base >> 4) & 0x0f; /* Extract the X from 2X0 */
2964
2965 outb((max_config), gus_base + 0x106); /* UltraMax control */
2966 }
2967
2968 if (!ports)
2969 goto no_cs4231;
2970
2971 if (ad1848_detect(ports, &ad_flags, hw_config->osp))
2972 {
2973 char *name = "GUS MAX";
2974 int old_num_mixers = num_mixers;
2975
2976 if (gus_pnp_flag)
2977 name = "GUS PnP";
2978
2979 gus_mic_vol = gus_line_vol = gus_pcm_volume = 100;
2980 gus_wave_volume = 90;
2981 have_gus_max = 1;
2982 if (hw_config->name)
2983 name = hw_config->name;
2984
2985 hw_config->slots[1] = ad1848_init(name, ports,
2986 -irq, gus_dma2, /* Playback DMA */
2987 gus_dma, /* Capture DMA */
2988 1, /* Share DMA channels with GF1 */
2989 hw_config->osp,
2990 THIS_MODULE);
2991
2992 if (num_mixers > old_num_mixers)
2993 {
2994 /* GUS has it's own mixer map */
2995 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_SYNTH);
2996 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD);
2997 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
2998 }
2999 }
3000 else {
3001 release_region(gus_base + 0x10c, 4);
3002 no_cs4231:
3003 printk(KERN_WARNING "GUS: No CS4231 ??");
3004 }
3005#else
3006 printk(KERN_ERR "GUS MAX found, but not compiled in\n");
3007#endif
3008 }
3009 }
3010 else
3011 {
3012 /*
3013 * ASIC not detected so the card must be 2.2 or 2.4.
3014 * There could still be the 16-bit/mixer daughter card.
3015 */
3016 }
3017
3018 if (hw_config->name)
3019 snprintf(tmp, sizeof(tmp), "%s (%dk)", hw_config->name,
3020 (int) gus_mem_size / 1024);
3021 else if (gus_pnp_flag)
3022 snprintf(tmp, sizeof(tmp), "Gravis UltraSound PnP (%dk)",
3023 (int) gus_mem_size / 1024);
3024 else
3025 snprintf(tmp, sizeof(tmp), "Gravis UltraSound %s (%dk)", model_num,
3026 (int) gus_mem_size / 1024);
3027
3028
3029 samples = (struct patch_info *)vmalloc((MAX_SAMPLE + 1) * sizeof(*samples));
3030 if (samples == NULL)
3031 {
3032 printk(KERN_WARNING "gus_init: Cant allocate memory for instrument tables\n");
3033 return;
3034 }
3035 conf_printf(tmp, hw_config);
3036 strlcpy(gus_info.name, tmp, sizeof(gus_info.name));
3037
3038 if ((sdev = sound_alloc_synthdev()) == -1)
3039 printk(KERN_WARNING "gus_init: Too many synthesizers\n");
3040 else
3041 {
3042 voice_alloc = &guswave_operations.alloc;
3043 if (iw_mode)
3044 guswave_operations.id = "IWAVE";
3045 hw_config->slots[0] = sdev;
3046 synth_devs[sdev] = &guswave_operations;
3047 sequencer_init();
3048 gus_tmr_install(gus_base + 8);
3049 }
3050
3051 reset_sample_memory();
3052
3053 gus_initialize();
3054
3055 if ((gus_mem_size > 0) && !gus_no_wave_dma)
3056 {
3057 hw_config->slots[4] = -1;
3058 if ((gus_devnum = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
3059 "Ultrasound",
3060 &gus_audio_driver,
3061 sizeof(struct audio_driver),
3062 NEEDS_RESTART |
3063 ((!iw_mode && dma2 != dma && dma2 != -1) ?
3064 DMA_DUPLEX : 0),
3065 AFMT_U8 | AFMT_S16_LE,
3066 NULL, dma, dma2)) < 0)
3067 {
3068 return;
3069 }
3070
3071 hw_config->slots[4] = gus_devnum;
3072 audio_devs[gus_devnum]->min_fragment = 9; /* 512k */
3073 audio_devs[gus_devnum]->max_fragment = 11; /* 8k (must match size of bounce_buf */
3074 audio_devs[gus_devnum]->mixer_dev = -1; /* Next mixer# */
3075 audio_devs[gus_devnum]->flags |= DMA_HARDSTOP;
3076 }
3077
3078 /*
3079 * Mixer dependent initialization.
3080 */
3081
3082 switch (mixer_type)
3083 {
3084 case ICS2101:
3085 gus_mic_vol = gus_line_vol = gus_pcm_volume = 100;
3086 gus_wave_volume = 90;
3087 request_region(u_MixSelect, 1, "GUS mixer");
3088 hw_config->slots[5] = ics2101_mixer_init();
3089 audio_devs[gus_devnum]->mixer_dev = hw_config->slots[5]; /* Next mixer# */
3090 return;
3091
3092 case CS4231:
3093 /* Initialized elsewhere (ad1848.c) */
3094 default:
3095 hw_config->slots[5] = gus_default_mixer_init();
3096 audio_devs[gus_devnum]->mixer_dev = hw_config->slots[5]; /* Next mixer# */
3097 return;
3098 }
3099}
3100
3101void __exit gus_wave_unload(struct address_info *hw_config)
3102{
3103#ifdef CONFIG_SOUND_GUSMAX
3104 if (have_gus_max)
3105 {
3106 ad1848_unload(gus_base + 0x10c,
3107 -gus_irq,
3108 gus_dma2, /* Playback DMA */
3109 gus_dma, /* Capture DMA */
3110 1); /* Share DMA channels with GF1 */
3111 }
3112#endif
3113
3114 if (mixer_type == ICS2101)
3115 {
3116 release_region(u_MixSelect, 1);
3117 }
3118 if (hw_config->slots[0] != -1)
3119 sound_unload_synthdev(hw_config->slots[0]);
3120 if (hw_config->slots[1] != -1)
3121 sound_unload_audiodev(hw_config->slots[1]);
3122 if (hw_config->slots[2] != -1)
3123 sound_unload_mididev(hw_config->slots[2]);
3124 if (hw_config->slots[4] != -1)
3125 sound_unload_audiodev(hw_config->slots[4]);
3126 if (hw_config->slots[5] != -1)
3127 sound_unload_mixerdev(hw_config->slots[5]);
3128
3129 vfree(samples);
3130 samples=NULL;
3131}
3132/* called in interrupt context */
3133static void do_loop_irq(int voice)
3134{
3135 unsigned char tmp;
3136 int mode, parm;
3137
3138 spin_lock(&gus_lock);
3139 gus_select_voice(voice);
3140
3141 tmp = gus_read8(0x00);
3142 tmp &= ~0x20; /*
3143 * Disable wave IRQ for this_one voice
3144 */
3145 gus_write8(0x00, tmp);
3146
3147 if (tmp & 0x03) /* Voice stopped */
3148 voice_alloc->map[voice] = 0;
3149
3150 mode = voices[voice].loop_irq_mode;
3151 voices[voice].loop_irq_mode = 0;
3152 parm = voices[voice].loop_irq_parm;
3153
3154 switch (mode)
3155 {
3156 case LMODE_FINISH: /*
3157 * Final loop finished, shoot volume down
3158 */
3159
3160 if ((int) (gus_read16(0x09) >> 4) < 100) /*
3161 * Get current volume
3162 */
3163 {
3164 gus_voice_off();
3165 gus_rampoff();
3166 gus_voice_init(voice);
3167 break;
3168 }
3169 gus_ramp_range(65, 4065);
3170 gus_ramp_rate(0, 63); /*
3171 * Fastest possible rate
3172 */
3173 gus_rampon(0x20 | 0x40); /*
3174 * Ramp down, once, irq
3175 */
3176 voices[voice].volume_irq_mode = VMODE_HALT;
3177 break;
3178
3179 case LMODE_PCM_STOP:
3180 pcm_active = 0; /* Signal to the play_next_pcm_block routine */
3181 case LMODE_PCM:
3182 {
3183 pcm_qlen--;
3184 pcm_head = (pcm_head + 1) % pcm_nblk;
3185 if (pcm_qlen && pcm_active)
3186 {
3187 play_next_pcm_block();
3188 }
3189 else
3190 {
3191 /* Underrun. Just stop the voice */
3192 gus_select_voice(0); /* Left channel */
3193 gus_voice_off();
3194 gus_rampoff();
3195 gus_select_voice(1); /* Right channel */
3196 gus_voice_off();
3197 gus_rampoff();
3198 pcm_active = 0;
3199 }
3200
3201 /*
3202 * If the queue was full before this interrupt, the DMA transfer was
3203 * suspended. Let it continue now.
3204 */
3205
3206 if (audio_devs[gus_devnum]->dmap_out->qlen > 0)
3207 DMAbuf_outputintr(gus_devnum, 0);
3208 }
3209 break;
3210
3211 default:
3212 break;
3213 }
3214 spin_unlock(&gus_lock);
3215}
3216
3217static void do_volume_irq(int voice)
3218{
3219 unsigned char tmp;
3220 int mode, parm;
3221 unsigned long flags;
3222
3223 spin_lock_irqsave(&gus_lock,flags);
3224
3225 gus_select_voice(voice);
3226 tmp = gus_read8(0x0d);
3227 tmp &= ~0x20; /*
3228 * Disable volume ramp IRQ
3229 */
3230 gus_write8(0x0d, tmp);
3231
3232 mode = voices[voice].volume_irq_mode;
3233 voices[voice].volume_irq_mode = 0;
3234 parm = voices[voice].volume_irq_parm;
3235
3236 switch (mode)
3237 {
3238 case VMODE_HALT: /* Decay phase finished */
3239 if (iw_mode)
3240 gus_write8(0x15, 0x02); /* Set voice deactivate bit of SMSI */
3241 spin_unlock_irqrestore(&gus_lock,flags);
3242 gus_voice_init(voice);
3243 break;
3244
3245 case VMODE_ENVELOPE:
3246 gus_rampoff();
3247 spin_unlock_irqrestore(&gus_lock,flags);
3248 step_envelope(voice);
3249 break;
3250
3251 case VMODE_START_NOTE:
3252 spin_unlock_irqrestore(&gus_lock,flags);
3253 guswave_start_note2(voices[voice].dev_pending, voice,
3254 voices[voice].note_pending, voices[voice].volume_pending);
3255 if (voices[voice].kill_pending)
3256 guswave_kill_note(voices[voice].dev_pending, voice,
3257 voices[voice].note_pending, 0);
3258
3259 if (voices[voice].sample_pending >= 0)
3260 {
3261 guswave_set_instr(voices[voice].dev_pending, voice,
3262 voices[voice].sample_pending);
3263 voices[voice].sample_pending = -1;
3264 }
3265 break;
3266
3267 default:
3268 spin_unlock_irqrestore(&gus_lock,flags);
3269 }
3270}
3271/* called in irq context */
3272void gus_voice_irq(void)
3273{
3274 unsigned long wave_ignore = 0, volume_ignore = 0;
3275 unsigned long voice_bit;
3276
3277 unsigned char src, voice;
3278
3279 while (1)
3280 {
3281 src = gus_read8(0x0f); /*
3282 * Get source info
3283 */
3284 voice = src & 0x1f;
3285 src &= 0xc0;
3286
3287 if (src == (0x80 | 0x40))
3288 return; /*
3289 * No interrupt
3290 */
3291
3292 voice_bit = 1 << voice;
3293
3294 if (!(src & 0x80)) /*
3295 * Wave IRQ pending
3296 */
3297 if (!(wave_ignore & voice_bit) && (int) voice < nr_voices) /*
3298 * Not done
3299 * yet
3300 */
3301 {
3302 wave_ignore |= voice_bit;
3303 do_loop_irq(voice);
3304 }
3305 if (!(src & 0x40)) /*
3306 * Volume IRQ pending
3307 */
3308 if (!(volume_ignore & voice_bit) && (int) voice < nr_voices) /*
3309 * Not done
3310 * yet
3311 */
3312 {
3313 volume_ignore |= voice_bit;
3314 do_volume_irq(voice);
3315 }
3316 }
3317}
3318
3319void guswave_dma_irq(void)
3320{
3321 unsigned char status;
3322
3323 status = gus_look8(0x41); /* Get DMA IRQ Status */
3324 if (status & 0x40) /* DMA interrupt pending */
3325 switch (active_device)
3326 {
3327 case GUS_DEV_WAVE:
3328 wake_up(&dram_sleeper);
3329 break;
3330
3331 case GUS_DEV_PCM_CONTINUE: /* Left channel data transferred */
3332 gus_write8(0x41, 0); /* Disable GF1 DMA */
3333 gus_transfer_output_block(pcm_current_dev, pcm_current_buf,
3334 pcm_current_count,
3335 pcm_current_intrflag, 1);
3336 break;
3337
3338 case GUS_DEV_PCM_DONE: /* Right or mono channel data transferred */
3339 gus_write8(0x41, 0); /* Disable GF1 DMA */
3340 if (pcm_qlen < pcm_nblk)
3341 {
3342 dma_active = 0;
3343 if (gus_busy)
3344 {
3345 if (audio_devs[gus_devnum]->dmap_out->qlen > 0)
3346 DMAbuf_outputintr(gus_devnum, 0);
3347 }
3348 }
3349 break;
3350
3351 default:
3352 break;
3353 }
3354 status = gus_look8(0x49); /*
3355 * Get Sampling IRQ Status
3356 */
3357 if (status & 0x40) /*
3358 * Sampling Irq pending
3359 */
3360 {
3361 DMAbuf_inputintr(gus_devnum);
3362 }
3363}
3364
3365/*
3366 * Timer stuff
3367 */
3368
3369static volatile int select_addr, data_addr;
3370static volatile int curr_timer;
3371
3372void gus_timer_command(unsigned int addr, unsigned int val)
3373{
3374 int i;
3375
3376 outb(((unsigned char) (addr & 0xff)), select_addr);
3377
3378 for (i = 0; i < 2; i++)
3379 inb(select_addr);
3380
3381 outb(((unsigned char) (val & 0xff)), data_addr);
3382
3383 for (i = 0; i < 2; i++)
3384 inb(select_addr);
3385}
3386
3387static void arm_timer(int timer, unsigned int interval)
3388{
3389 curr_timer = timer;
3390
3391 if (timer == 1)
3392 {
3393 gus_write8(0x46, 256 - interval); /* Set counter for timer 1 */
3394 gus_write8(0x45, 0x04); /* Enable timer 1 IRQ */
3395 gus_timer_command(0x04, 0x01); /* Start timer 1 */
3396 }
3397 else
3398 {
3399 gus_write8(0x47, 256 - interval); /* Set counter for timer 2 */
3400 gus_write8(0x45, 0x08); /* Enable timer 2 IRQ */
3401 gus_timer_command(0x04, 0x02); /* Start timer 2 */
3402 }
3403
3404 gus_timer_enabled = 1;
3405}
3406
3407static unsigned int gus_tmr_start(int dev, unsigned int usecs_per_tick)
3408{
3409 int timer_no, resolution;
3410 int divisor;
3411
3412 if (usecs_per_tick > (256 * 80))
3413 {
3414 timer_no = 2;
3415 resolution = 320; /* usec */
3416 }
3417 else
3418 {
3419 timer_no = 1;
3420 resolution = 80; /* usec */
3421 }
3422 divisor = (usecs_per_tick + (resolution / 2)) / resolution;
3423 arm_timer(timer_no, divisor);
3424
3425 return divisor * resolution;
3426}
3427
3428static void gus_tmr_disable(int dev)
3429{
3430 gus_write8(0x45, 0); /* Disable both timers */
3431 gus_timer_enabled = 0;
3432}
3433
3434static void gus_tmr_restart(int dev)
3435{
3436 if (curr_timer == 1)
3437 gus_write8(0x45, 0x04); /* Start timer 1 again */
3438 else
3439 gus_write8(0x45, 0x08); /* Start timer 2 again */
3440 gus_timer_enabled = 1;
3441}
3442
3443static struct sound_lowlev_timer gus_tmr =
3444{
3445 0,
3446 1,
3447 gus_tmr_start,
3448 gus_tmr_disable,
3449 gus_tmr_restart
3450};
3451
3452static void gus_tmr_install(int io_base)
3453{
3454 struct sound_lowlev_timer *tmr;
3455
3456 select_addr = io_base;
3457 data_addr = io_base + 1;
3458
3459 tmr = &gus_tmr;
3460
3461#ifdef THIS_GETS_FIXED
3462 sound_timer_init(&gus_tmr, "GUS");
3463#endif
3464}
diff --git a/sound/oss/hal2.c b/sound/oss/hal2.c
new file mode 100644
index 000000000000..afe97c4ce069
--- /dev/null
+++ b/sound/oss/hal2.c
@@ -0,0 +1,1557 @@
1/*
2 * Driver for A2 audio system used in SGI machines
3 * Copyright (c) 2001, 2002, 2003 Ladislav Michl <ladis@linux-mips.org>
4 *
5 * Based on Ulf Carlsson's code.
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 version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Supported devices:
21 * /dev/dsp standard dsp device, (mostly) OSS compatible
22 * /dev/mixer standard mixer device, (mostly) OSS compatible
23 *
24 */
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/sched.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <linux/poll.h>
31#include <linux/interrupt.h>
32#include <linux/dma-mapping.h>
33#include <linux/sound.h>
34#include <linux/soundcard.h>
35
36#include <asm/io.h>
37#include <asm/sgi/hpc3.h>
38#include <asm/sgi/ip22.h>
39
40#include "hal2.h"
41
42#if 0
43#define DEBUG(args...) printk(args)
44#else
45#define DEBUG(args...)
46#endif
47
48#if 0
49#define DEBUG_MIX(args...) printk(args)
50#else
51#define DEBUG_MIX(args...)
52#endif
53
54/*
55 * Before touching these look how it works. It is a bit unusual I know,
56 * but it helps to keep things simple. This driver is considered complete
57 * and I won't add any new features although hardware has many cool
58 * capabilities.
59 * (Historical note: HAL2 driver was first written by Ulf Carlsson - ALSA
60 * 0.3 running with 2.2.x kernel. Then ALSA changed completely and it
61 * seemed easier to me to write OSS driver from scratch - this one. Now
62 * when ALSA is official part of 2.6 kernel it's time to write ALSA driver
63 * using (hopefully) final version of ALSA interface)
64 */
65#define H2_BLOCK_SIZE 1024
66#define H2_ADC_BUFSIZE 8192
67#define H2_DAC_BUFSIZE 16834
68
69struct hal2_pbus {
70 struct hpc3_pbus_dmacregs *pbus;
71 int pbusnr;
72 unsigned int ctrl; /* Current state of pbus->pbdma_ctrl */
73};
74
75struct hal2_desc {
76 struct hpc_dma_desc desc;
77 u32 cnt; /* don't touch, it is also padding */
78};
79
80struct hal2_codec {
81 unsigned char *buffer;
82 struct hal2_desc *desc;
83 int desc_count;
84 int tail, head; /* tail index, head index */
85 struct hal2_pbus pbus;
86 unsigned int format; /* Audio data format */
87 int voices; /* mono/stereo */
88 unsigned int sample_rate;
89 unsigned int master; /* Master frequency */
90 unsigned short mod; /* MOD value */
91 unsigned short inc; /* INC value */
92
93 wait_queue_head_t dma_wait;
94 spinlock_t lock;
95 struct semaphore sem;
96
97 int usecount; /* recording and playback are
98 * independent */
99};
100
101#define H2_MIX_OUTPUT_ATT 0
102#define H2_MIX_INPUT_GAIN 1
103#define H2_MIXERS 2
104struct hal2_mixer {
105 int modcnt;
106 unsigned int master;
107 unsigned int volume[H2_MIXERS];
108};
109
110struct hal2_card {
111 int dev_dsp; /* audio device */
112 int dev_mixer; /* mixer device */
113 int dev_midi; /* midi device */
114
115 struct hal2_ctl_regs *ctl_regs; /* HAL2 ctl registers */
116 struct hal2_aes_regs *aes_regs; /* HAL2 aes registers */
117 struct hal2_vol_regs *vol_regs; /* HAL2 vol registers */
118 struct hal2_syn_regs *syn_regs; /* HAL2 syn registers */
119
120 struct hal2_codec dac;
121 struct hal2_codec adc;
122 struct hal2_mixer mixer;
123};
124
125#define H2_INDIRECT_WAIT(regs) while (regs->isr & H2_ISR_TSTATUS);
126
127#define H2_READ_ADDR(addr) (addr | (1<<7))
128#define H2_WRITE_ADDR(addr) (addr)
129
130static char *hal2str = "HAL2";
131
132/*
133 * I doubt anyone has a machine with two HAL2 cards. It's possible to
134 * have two HPC's, so it is probably possible to have two HAL2 cards.
135 * Try to deal with it, but note that it is not tested.
136 */
137#define MAXCARDS 2
138static struct hal2_card* hal2_card[MAXCARDS];
139
140static const struct {
141 unsigned char idx:4, avail:1;
142} mixtable[SOUND_MIXER_NRDEVICES] = {
143 [SOUND_MIXER_PCM] = { H2_MIX_OUTPUT_ATT, 1 }, /* voice */
144 [SOUND_MIXER_MIC] = { H2_MIX_INPUT_GAIN, 1 }, /* mic */
145};
146
147#define H2_SUPPORTED_FORMATS (AFMT_S16_LE | AFMT_S16_BE)
148
149static inline void hal2_isr_write(struct hal2_card *hal2, u16 val)
150{
151 hal2->ctl_regs->isr = val;
152}
153
154static inline u16 hal2_isr_look(struct hal2_card *hal2)
155{
156 return hal2->ctl_regs->isr;
157}
158
159static inline u16 hal2_rev_look(struct hal2_card *hal2)
160{
161 return hal2->ctl_regs->rev;
162}
163
164#ifdef HAL2_DUMP_REGS
165static u16 hal2_i_look16(struct hal2_card *hal2, u16 addr)
166{
167 struct hal2_ctl_regs *regs = hal2->ctl_regs;
168
169 regs->iar = H2_READ_ADDR(addr);
170 H2_INDIRECT_WAIT(regs);
171 return regs->idr0;
172}
173#endif
174
175static u32 hal2_i_look32(struct hal2_card *hal2, u16 addr)
176{
177 u32 ret;
178 struct hal2_ctl_regs *regs = hal2->ctl_regs;
179
180 regs->iar = H2_READ_ADDR(addr);
181 H2_INDIRECT_WAIT(regs);
182 ret = regs->idr0 & 0xffff;
183 regs->iar = H2_READ_ADDR(addr | 0x1);
184 H2_INDIRECT_WAIT(regs);
185 ret |= (regs->idr0 & 0xffff) << 16;
186 return ret;
187}
188
189static void hal2_i_write16(struct hal2_card *hal2, u16 addr, u16 val)
190{
191 struct hal2_ctl_regs *regs = hal2->ctl_regs;
192
193 regs->idr0 = val;
194 regs->idr1 = 0;
195 regs->idr2 = 0;
196 regs->idr3 = 0;
197 regs->iar = H2_WRITE_ADDR(addr);
198 H2_INDIRECT_WAIT(regs);
199}
200
201static void hal2_i_write32(struct hal2_card *hal2, u16 addr, u32 val)
202{
203 struct hal2_ctl_regs *regs = hal2->ctl_regs;
204
205 regs->idr0 = val & 0xffff;
206 regs->idr1 = val >> 16;
207 regs->idr2 = 0;
208 regs->idr3 = 0;
209 regs->iar = H2_WRITE_ADDR(addr);
210 H2_INDIRECT_WAIT(regs);
211}
212
213static void hal2_i_setbit16(struct hal2_card *hal2, u16 addr, u16 bit)
214{
215 struct hal2_ctl_regs *regs = hal2->ctl_regs;
216
217 regs->iar = H2_READ_ADDR(addr);
218 H2_INDIRECT_WAIT(regs);
219 regs->idr0 = (regs->idr0 & 0xffff) | bit;
220 regs->idr1 = 0;
221 regs->idr2 = 0;
222 regs->idr3 = 0;
223 regs->iar = H2_WRITE_ADDR(addr);
224 H2_INDIRECT_WAIT(regs);
225}
226
227static void hal2_i_setbit32(struct hal2_card *hal2, u16 addr, u32 bit)
228{
229 u32 tmp;
230 struct hal2_ctl_regs *regs = hal2->ctl_regs;
231
232 regs->iar = H2_READ_ADDR(addr);
233 H2_INDIRECT_WAIT(regs);
234 tmp = (regs->idr0 & 0xffff) | (regs->idr1 << 16) | bit;
235 regs->idr0 = tmp & 0xffff;
236 regs->idr1 = tmp >> 16;
237 regs->idr2 = 0;
238 regs->idr3 = 0;
239 regs->iar = H2_WRITE_ADDR(addr);
240 H2_INDIRECT_WAIT(regs);
241}
242
243static void hal2_i_clearbit16(struct hal2_card *hal2, u16 addr, u16 bit)
244{
245 struct hal2_ctl_regs *regs = hal2->ctl_regs;
246
247 regs->iar = H2_READ_ADDR(addr);
248 H2_INDIRECT_WAIT(regs);
249 regs->idr0 = (regs->idr0 & 0xffff) & ~bit;
250 regs->idr1 = 0;
251 regs->idr2 = 0;
252 regs->idr3 = 0;
253 regs->iar = H2_WRITE_ADDR(addr);
254 H2_INDIRECT_WAIT(regs);
255}
256
257#if 0
258static void hal2_i_clearbit32(struct hal2_card *hal2, u16 addr, u32 bit)
259{
260 u32 tmp;
261 hal2_ctl_regs_t *regs = hal2->ctl_regs;
262
263 regs->iar = H2_READ_ADDR(addr);
264 H2_INDIRECT_WAIT(regs);
265 tmp = ((regs->idr0 & 0xffff) | (regs->idr1 << 16)) & ~bit;
266 regs->idr0 = tmp & 0xffff;
267 regs->idr1 = tmp >> 16;
268 regs->idr2 = 0;
269 regs->idr3 = 0;
270 regs->iar = H2_WRITE_ADDR(addr);
271 H2_INDIRECT_WAIT(regs);
272}
273#endif
274
275#ifdef HAL2_DUMP_REGS
276static void hal2_dump_regs(struct hal2_card *hal2)
277{
278 DEBUG("isr: %08hx ", hal2_isr_look(hal2));
279 DEBUG("rev: %08hx\n", hal2_rev_look(hal2));
280 DEBUG("relay: %04hx\n", hal2_i_look16(hal2, H2I_RELAY_C));
281 DEBUG("port en: %04hx ", hal2_i_look16(hal2, H2I_DMA_PORT_EN));
282 DEBUG("dma end: %04hx ", hal2_i_look16(hal2, H2I_DMA_END));
283 DEBUG("dma drv: %04hx\n", hal2_i_look16(hal2, H2I_DMA_DRV));
284 DEBUG("syn ctl: %04hx ", hal2_i_look16(hal2, H2I_SYNTH_C));
285 DEBUG("aesrx ctl: %04hx ", hal2_i_look16(hal2, H2I_AESRX_C));
286 DEBUG("aestx ctl: %04hx ", hal2_i_look16(hal2, H2I_AESTX_C));
287 DEBUG("dac ctl1: %04hx ", hal2_i_look16(hal2, H2I_ADC_C1));
288 DEBUG("dac ctl2: %08x ", hal2_i_look32(hal2, H2I_ADC_C2));
289 DEBUG("adc ctl1: %04hx ", hal2_i_look16(hal2, H2I_DAC_C1));
290 DEBUG("adc ctl2: %08x ", hal2_i_look32(hal2, H2I_DAC_C2));
291 DEBUG("syn map: %04hx\n", hal2_i_look16(hal2, H2I_SYNTH_MAP_C));
292 DEBUG("bres1 ctl1: %04hx ", hal2_i_look16(hal2, H2I_BRES1_C1));
293 DEBUG("bres1 ctl2: %04x ", hal2_i_look32(hal2, H2I_BRES1_C2));
294 DEBUG("bres2 ctl1: %04hx ", hal2_i_look16(hal2, H2I_BRES2_C1));
295 DEBUG("bres2 ctl2: %04x ", hal2_i_look32(hal2, H2I_BRES2_C2));
296 DEBUG("bres3 ctl1: %04hx ", hal2_i_look16(hal2, H2I_BRES3_C1));
297 DEBUG("bres3 ctl2: %04x\n", hal2_i_look32(hal2, H2I_BRES3_C2));
298}
299#endif
300
301static struct hal2_card* hal2_dsp_find_card(int minor)
302{
303 int i;
304
305 for (i = 0; i < MAXCARDS; i++)
306 if (hal2_card[i] != NULL && hal2_card[i]->dev_dsp == minor)
307 return hal2_card[i];
308 return NULL;
309}
310
311static struct hal2_card* hal2_mixer_find_card(int minor)
312{
313 int i;
314
315 for (i = 0; i < MAXCARDS; i++)
316 if (hal2_card[i] != NULL && hal2_card[i]->dev_mixer == minor)
317 return hal2_card[i];
318 return NULL;
319}
320
321static void hal2_inc_head(struct hal2_codec *codec)
322{
323 codec->head++;
324 if (codec->head == codec->desc_count)
325 codec->head = 0;
326}
327
328static void hal2_inc_tail(struct hal2_codec *codec)
329{
330 codec->tail++;
331 if (codec->tail == codec->desc_count)
332 codec->tail = 0;
333}
334
335static void hal2_dac_interrupt(struct hal2_codec *dac)
336{
337 int running;
338
339 spin_lock(&dac->lock);
340 /* if tail buffer contains zero samples DMA stream was already
341 * stopped */
342 running = dac->desc[dac->tail].cnt;
343 dac->desc[dac->tail].cnt = 0;
344 dac->desc[dac->tail].desc.cntinfo = HPCDMA_XIE | HPCDMA_EOX;
345 /* we just proccessed empty buffer, don't update tail pointer */
346 if (running)
347 hal2_inc_tail(dac);
348 spin_unlock(&dac->lock);
349
350 wake_up(&dac->dma_wait);
351}
352
353static void hal2_adc_interrupt(struct hal2_codec *adc)
354{
355 int running;
356
357 spin_lock(&adc->lock);
358 /* if head buffer contains nonzero samples DMA stream was already
359 * stopped */
360 running = !adc->desc[adc->head].cnt;
361 adc->desc[adc->head].cnt = H2_BLOCK_SIZE;
362 adc->desc[adc->head].desc.cntinfo = HPCDMA_XIE | HPCDMA_EOR;
363 /* we just proccessed empty buffer, don't update head pointer */
364 if (running)
365 hal2_inc_head(adc);
366 spin_unlock(&adc->lock);
367
368 wake_up(&adc->dma_wait);
369}
370
371static irqreturn_t hal2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
372{
373 struct hal2_card *hal2 = (struct hal2_card*)dev_id;
374 irqreturn_t ret = IRQ_NONE;
375
376 /* decide what caused this interrupt */
377 if (hal2->dac.pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_INT) {
378 hal2_dac_interrupt(&hal2->dac);
379 ret = IRQ_HANDLED;
380 }
381 if (hal2->adc.pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_INT) {
382 hal2_adc_interrupt(&hal2->adc);
383 ret = IRQ_HANDLED;
384 }
385 return ret;
386}
387
388static int hal2_compute_rate(struct hal2_codec *codec, unsigned int rate)
389{
390 unsigned short mod;
391
392 DEBUG("rate: %d\n", rate);
393
394 if (rate < 4000) rate = 4000;
395 else if (rate > 48000) rate = 48000;
396
397 if (44100 % rate < 48000 % rate) {
398 mod = 4 * 44100 / rate;
399 codec->master = 44100;
400 } else {
401 mod = 4 * 48000 / rate;
402 codec->master = 48000;
403 }
404
405 codec->inc = 4;
406 codec->mod = mod;
407 rate = 4 * codec->master / mod;
408
409 DEBUG("real_rate: %d\n", rate);
410
411 return rate;
412}
413
414static void hal2_set_dac_rate(struct hal2_card *hal2)
415{
416 unsigned int master = hal2->dac.master;
417 int inc = hal2->dac.inc;
418 int mod = hal2->dac.mod;
419
420 DEBUG("master: %d inc: %d mod: %d\n", master, inc, mod);
421
422 hal2_i_write16(hal2, H2I_BRES1_C1, (master == 44100) ? 1 : 0);
423 hal2_i_write32(hal2, H2I_BRES1_C2, ((0xffff & (inc - mod - 1)) << 16) | inc);
424}
425
426static void hal2_set_adc_rate(struct hal2_card *hal2)
427{
428 unsigned int master = hal2->adc.master;
429 int inc = hal2->adc.inc;
430 int mod = hal2->adc.mod;
431
432 DEBUG("master: %d inc: %d mod: %d\n", master, inc, mod);
433
434 hal2_i_write16(hal2, H2I_BRES2_C1, (master == 44100) ? 1 : 0);
435 hal2_i_write32(hal2, H2I_BRES2_C2, ((0xffff & (inc - mod - 1)) << 16) | inc);
436}
437
438static void hal2_setup_dac(struct hal2_card *hal2)
439{
440 unsigned int fifobeg, fifoend, highwater, sample_size;
441 struct hal2_pbus *pbus = &hal2->dac.pbus;
442
443 DEBUG("hal2_setup_dac\n");
444
445 /* Now we set up some PBUS information. The PBUS needs information about
446 * what portion of the fifo it will use. If it's receiving or
447 * transmitting, and finally whether the stream is little endian or big
448 * endian. The information is written later, on the start call.
449 */
450 sample_size = 2 * hal2->dac.voices;
451 /* Fifo should be set to hold exactly four samples. Highwater mark
452 * should be set to two samples. */
453 highwater = (sample_size * 2) >> 1; /* halfwords */
454 fifobeg = 0; /* playback is first */
455 fifoend = (sample_size * 4) >> 3; /* doublewords */
456 pbus->ctrl = HPC3_PDMACTRL_RT | HPC3_PDMACTRL_LD |
457 (highwater << 8) | (fifobeg << 16) | (fifoend << 24) |
458 (hal2->dac.format & AFMT_S16_LE ? HPC3_PDMACTRL_SEL : 0);
459 /* We disable everything before we do anything at all */
460 pbus->pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
461 hal2_i_clearbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECTX);
462 /* Setup the HAL2 for playback */
463 hal2_set_dac_rate(hal2);
464 /* Set endianess */
465 if (hal2->dac.format & AFMT_S16_LE)
466 hal2_i_setbit16(hal2, H2I_DMA_END, H2I_DMA_END_CODECTX);
467 else
468 hal2_i_clearbit16(hal2, H2I_DMA_END, H2I_DMA_END_CODECTX);
469 /* Set DMA bus */
470 hal2_i_setbit16(hal2, H2I_DMA_DRV, (1 << pbus->pbusnr));
471 /* We are using 1st Bresenham clock generator for playback */
472 hal2_i_write16(hal2, H2I_DAC_C1, (pbus->pbusnr << H2I_C1_DMA_SHIFT)
473 | (1 << H2I_C1_CLKID_SHIFT)
474 | (hal2->dac.voices << H2I_C1_DATAT_SHIFT));
475}
476
477static void hal2_setup_adc(struct hal2_card *hal2)
478{
479 unsigned int fifobeg, fifoend, highwater, sample_size;
480 struct hal2_pbus *pbus = &hal2->adc.pbus;
481
482 DEBUG("hal2_setup_adc\n");
483
484 sample_size = 2 * hal2->adc.voices;
485 highwater = (sample_size * 2) >> 1; /* halfwords */
486 fifobeg = (4 * 4) >> 3; /* record is second */
487 fifoend = (4 * 4 + sample_size * 4) >> 3; /* doublewords */
488 pbus->ctrl = HPC3_PDMACTRL_RT | HPC3_PDMACTRL_RCV | HPC3_PDMACTRL_LD |
489 (highwater << 8) | (fifobeg << 16) | (fifoend << 24) |
490 (hal2->adc.format & AFMT_S16_LE ? HPC3_PDMACTRL_SEL : 0);
491 pbus->pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
492 hal2_i_clearbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECR);
493 /* Setup the HAL2 for record */
494 hal2_set_adc_rate(hal2);
495 /* Set endianess */
496 if (hal2->adc.format & AFMT_S16_LE)
497 hal2_i_setbit16(hal2, H2I_DMA_END, H2I_DMA_END_CODECR);
498 else
499 hal2_i_clearbit16(hal2, H2I_DMA_END, H2I_DMA_END_CODECR);
500 /* Set DMA bus */
501 hal2_i_setbit16(hal2, H2I_DMA_DRV, (1 << pbus->pbusnr));
502 /* We are using 2nd Bresenham clock generator for record */
503 hal2_i_write16(hal2, H2I_ADC_C1, (pbus->pbusnr << H2I_C1_DMA_SHIFT)
504 | (2 << H2I_C1_CLKID_SHIFT)
505 | (hal2->adc.voices << H2I_C1_DATAT_SHIFT));
506}
507
508static dma_addr_t hal2_desc_addr(struct hal2_codec *codec, int i)
509{
510 if (--i < 0)
511 i = codec->desc_count - 1;
512 return codec->desc[i].desc.pnext;
513}
514
515static void hal2_start_dac(struct hal2_card *hal2)
516{
517 struct hal2_codec *dac = &hal2->dac;
518 struct hal2_pbus *pbus = &dac->pbus;
519
520 pbus->pbus->pbdma_dptr = hal2_desc_addr(dac, dac->tail);
521 pbus->pbus->pbdma_ctrl = pbus->ctrl | HPC3_PDMACTRL_ACT;
522 /* enable DAC */
523 hal2_i_setbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECTX);
524}
525
526static void hal2_start_adc(struct hal2_card *hal2)
527{
528 struct hal2_codec *adc = &hal2->adc;
529 struct hal2_pbus *pbus = &adc->pbus;
530
531 pbus->pbus->pbdma_dptr = hal2_desc_addr(adc, adc->head);
532 pbus->pbus->pbdma_ctrl = pbus->ctrl | HPC3_PDMACTRL_ACT;
533 /* enable ADC */
534 hal2_i_setbit16(hal2, H2I_DMA_PORT_EN, H2I_DMA_PORT_EN_CODECR);
535}
536
537static inline void hal2_stop_dac(struct hal2_card *hal2)
538{
539 hal2->dac.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
540 /* The HAL2 itself may remain enabled safely */
541}
542
543static inline void hal2_stop_adc(struct hal2_card *hal2)
544{
545 hal2->adc.pbus.pbus->pbdma_ctrl = HPC3_PDMACTRL_LD;
546}
547
548static int hal2_alloc_dmabuf(struct hal2_codec *codec, int size,
549 int count, int cntinfo, int dir)
550{
551 struct hal2_desc *desc, *dma_addr;
552 int i;
553
554 DEBUG("allocating %dk DMA buffer.\n", size / 1024);
555
556 codec->buffer = (unsigned char *)__get_free_pages(GFP_KERNEL | GFP_DMA,
557 get_order(size));
558 if (!codec->buffer)
559 return -ENOMEM;
560 desc = dma_alloc_coherent(NULL, count * sizeof(struct hal2_desc),
561 (dma_addr_t *)&dma_addr, GFP_KERNEL);
562 if (!desc) {
563 free_pages((unsigned long)codec->buffer, get_order(size));
564 return -ENOMEM;
565 }
566 codec->desc = desc;
567 for (i = 0; i < count; i++) {
568 desc->desc.pbuf = dma_map_single(NULL,
569 (void *)(codec->buffer + i * H2_BLOCK_SIZE),
570 H2_BLOCK_SIZE, dir);
571 desc->desc.cntinfo = cntinfo;
572 desc->desc.pnext = (i == count - 1) ?
573 (u32)dma_addr : (u32)(dma_addr + i + 1);
574 desc->cnt = 0;
575 desc++;
576 }
577 codec->desc_count = count;
578 codec->head = codec->tail = 0;
579 return 0;
580}
581
582static int hal2_alloc_dac_dmabuf(struct hal2_codec *codec)
583{
584 return hal2_alloc_dmabuf(codec, H2_DAC_BUFSIZE,
585 H2_DAC_BUFSIZE / H2_BLOCK_SIZE,
586 HPCDMA_XIE | HPCDMA_EOX,
587 DMA_TO_DEVICE);
588}
589
590static int hal2_alloc_adc_dmabuf(struct hal2_codec *codec)
591{
592 return hal2_alloc_dmabuf(codec, H2_ADC_BUFSIZE,
593 H2_ADC_BUFSIZE / H2_BLOCK_SIZE,
594 HPCDMA_XIE | H2_BLOCK_SIZE,
595 DMA_TO_DEVICE);
596}
597
598static void hal2_free_dmabuf(struct hal2_codec *codec, int size, int dir)
599{
600 dma_addr_t dma_addr;
601 int i;
602
603 dma_addr = codec->desc[codec->desc_count - 1].desc.pnext;
604 for (i = 0; i < codec->desc_count; i++)
605 dma_unmap_single(NULL, codec->desc[i].desc.pbuf,
606 H2_BLOCK_SIZE, dir);
607 dma_free_coherent(NULL, codec->desc_count * sizeof(struct hal2_desc),
608 (void *)codec->desc, dma_addr);
609 free_pages((unsigned long)codec->buffer, get_order(size));
610}
611
612static void hal2_free_dac_dmabuf(struct hal2_codec *codec)
613{
614 return hal2_free_dmabuf(codec, H2_DAC_BUFSIZE, DMA_TO_DEVICE);
615}
616
617static void hal2_free_adc_dmabuf(struct hal2_codec *codec)
618{
619 return hal2_free_dmabuf(codec, H2_ADC_BUFSIZE, DMA_FROM_DEVICE);
620}
621
622/*
623 * Add 'count' bytes to 'buffer' from DMA ring buffers. Return number of
624 * bytes added or -EFAULT if copy_from_user failed.
625 */
626static int hal2_get_buffer(struct hal2_card *hal2, char *buffer, int count)
627{
628 unsigned long flags;
629 int size, ret = 0;
630 unsigned char *buf;
631 struct hal2_desc *tail;
632 struct hal2_codec *adc = &hal2->adc;
633
634 DEBUG("getting %d bytes ", count);
635
636 spin_lock_irqsave(&adc->lock, flags);
637 tail = &adc->desc[adc->tail];
638 /* enable DMA stream if there are no data */
639 if (!tail->cnt && !(adc->pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_ISACT))
640 hal2_start_adc(hal2);
641 while (tail->cnt > 0 && count > 0) {
642 size = min((int)tail->cnt, count);
643 buf = &adc->buffer[(adc->tail + 1) * H2_BLOCK_SIZE - tail->cnt];
644 spin_unlock_irqrestore(&adc->lock, flags);
645 dma_sync_single(NULL, tail->desc.pbuf, size, DMA_FROM_DEVICE);
646 if (copy_to_user(buffer, buf, size)) {
647 ret = -EFAULT;
648 goto out;
649 }
650 spin_lock_irqsave(&adc->lock, flags);
651 tail->cnt -= size;
652 /* buffer is empty, update tail pointer */
653 if (tail->cnt == 0) {
654 tail->desc.cntinfo = HPCDMA_XIE | H2_BLOCK_SIZE;
655 hal2_inc_tail(adc);
656 tail = &adc->desc[adc->tail];
657 /* enable DMA stream again if needed */
658 if (!(adc->pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_ISACT))
659 hal2_start_adc(hal2);
660 }
661 buffer += size;
662 ret += size;
663 count -= size;
664
665 DEBUG("(%d) ", size);
666 }
667 spin_unlock_irqrestore(&adc->lock, flags);
668out:
669 DEBUG("\n");
670
671 return ret;
672}
673
674/*
675 * Add 'count' bytes from 'buffer' to DMA ring buffers. Return number of
676 * bytes added or -EFAULT if copy_from_user failed.
677 */
678static int hal2_add_buffer(struct hal2_card *hal2, char *buffer, int count)
679{
680 unsigned long flags;
681 unsigned char *buf;
682 int size, ret = 0;
683 struct hal2_desc *head;
684 struct hal2_codec *dac = &hal2->dac;
685
686 DEBUG("adding %d bytes ", count);
687
688 spin_lock_irqsave(&dac->lock, flags);
689 head = &dac->desc[dac->head];
690 while (head->cnt == 0 && count > 0) {
691 size = min((int)H2_BLOCK_SIZE, count);
692 buf = &dac->buffer[dac->head * H2_BLOCK_SIZE];
693 spin_unlock_irqrestore(&dac->lock, flags);
694 if (copy_from_user(buf, buffer, size)) {
695 ret = -EFAULT;
696 goto out;
697 }
698 dma_sync_single(NULL, head->desc.pbuf, size, DMA_TO_DEVICE);
699 spin_lock_irqsave(&dac->lock, flags);
700 head->desc.cntinfo = size | HPCDMA_XIE;
701 head->cnt = size;
702 buffer += size;
703 ret += size;
704 count -= size;
705 hal2_inc_head(dac);
706 head = &dac->desc[dac->head];
707
708 DEBUG("(%d) ", size);
709 }
710 if (!(dac->pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_ISACT) && ret > 0)
711 hal2_start_dac(hal2);
712 spin_unlock_irqrestore(&dac->lock, flags);
713out:
714 DEBUG("\n");
715
716 return ret;
717}
718
719#define hal2_reset_dac_pointer(hal2) hal2_reset_pointer(hal2, 1)
720#define hal2_reset_adc_pointer(hal2) hal2_reset_pointer(hal2, 0)
721static void hal2_reset_pointer(struct hal2_card *hal2, int is_dac)
722{
723 int i;
724 struct hal2_codec *codec = (is_dac) ? &hal2->dac : &hal2->adc;
725
726 DEBUG("hal2_reset_pointer\n");
727
728 for (i = 0; i < codec->desc_count; i++) {
729 codec->desc[i].cnt = 0;
730 codec->desc[i].desc.cntinfo = HPCDMA_XIE | (is_dac) ?
731 HPCDMA_EOX : H2_BLOCK_SIZE;
732 }
733 codec->head = codec->tail = 0;
734}
735
736static int hal2_sync_dac(struct hal2_card *hal2)
737{
738 DECLARE_WAITQUEUE(wait, current);
739 struct hal2_codec *dac = &hal2->dac;
740 int ret = 0;
741 unsigned long flags;
742 signed long timeout = 1000 * H2_BLOCK_SIZE * 2 * dac->voices *
743 HZ / dac->sample_rate / 900;
744
745 while (dac->pbus.pbus->pbdma_ctrl & HPC3_PDMACTRL_ISACT) {
746 add_wait_queue(&dac->dma_wait, &wait);
747 set_current_state(TASK_INTERRUPTIBLE);
748 schedule_timeout(timeout);
749 spin_lock_irqsave(&dac->lock, flags);
750 if (dac->desc[dac->tail].cnt)
751 ret = -ETIME;
752 spin_unlock_irqrestore(&dac->lock, flags);
753 if (signal_pending(current))
754 ret = -ERESTARTSYS;
755 if (ret) {
756 hal2_stop_dac(hal2);
757 hal2_reset_dac_pointer(hal2);
758 }
759 remove_wait_queue(&dac->dma_wait, &wait);
760 }
761
762 return ret;
763}
764
765static int hal2_write_mixer(struct hal2_card *hal2, int index, int vol)
766{
767 unsigned int l, r, tmp;
768
769 DEBUG_MIX("mixer %d write\n", index);
770
771 if (index >= SOUND_MIXER_NRDEVICES || !mixtable[index].avail)
772 return -EINVAL;
773
774 r = (vol >> 8) & 0xff;
775 if (r > 100)
776 r = 100;
777 l = vol & 0xff;
778 if (l > 100)
779 l = 100;
780
781 hal2->mixer.volume[mixtable[index].idx] = l | (r << 8);
782
783 switch (mixtable[index].idx) {
784 case H2_MIX_OUTPUT_ATT:
785
786 DEBUG_MIX("output attenuator %d,%d\n", l, r);
787
788 if (r | l) {
789 tmp = hal2_i_look32(hal2, H2I_DAC_C2);
790 tmp &= ~(H2I_C2_L_ATT_M | H2I_C2_R_ATT_M | H2I_C2_MUTE);
791
792 /* Attenuator has five bits */
793 l = 31 * (100 - l) / 99;
794 r = 31 * (100 - r) / 99;
795
796 DEBUG_MIX("left: %d, right %d\n", l, r);
797
798 tmp |= (l << H2I_C2_L_ATT_SHIFT) & H2I_C2_L_ATT_M;
799 tmp |= (r << H2I_C2_R_ATT_SHIFT) & H2I_C2_R_ATT_M;
800 hal2_i_write32(hal2, H2I_DAC_C2, tmp);
801 } else
802 hal2_i_setbit32(hal2, H2I_DAC_C2, H2I_C2_MUTE);
803 break;
804 case H2_MIX_INPUT_GAIN:
805
806 DEBUG_MIX("input gain %d,%d\n", l, r);
807
808 tmp = hal2_i_look32(hal2, H2I_ADC_C2);
809 tmp &= ~(H2I_C2_L_GAIN_M | H2I_C2_R_GAIN_M);
810
811 /* Gain control has four bits */
812 l = 16 * l / 100;
813 r = 16 * r / 100;
814
815 DEBUG_MIX("left: %d, right %d\n", l, r);
816
817 tmp |= (l << H2I_C2_L_GAIN_SHIFT) & H2I_C2_L_GAIN_M;
818 tmp |= (r << H2I_C2_R_GAIN_SHIFT) & H2I_C2_R_GAIN_M;
819 hal2_i_write32(hal2, H2I_ADC_C2, tmp);
820
821 break;
822 }
823
824 return 0;
825}
826
827static void hal2_init_mixer(struct hal2_card *hal2)
828{
829 int i;
830
831 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
832 if (mixtable[i].avail)
833 hal2->mixer.volume[mixtable[i].idx] = 100 | (100 << 8);
834
835 /* disable attenuator */
836 hal2_i_write32(hal2, H2I_DAC_C2, 0);
837 /* set max input gain */
838 hal2_i_write32(hal2, H2I_ADC_C2, H2I_C2_MUTE |
839 (H2I_C2_L_GAIN_M << H2I_C2_L_GAIN_SHIFT) |
840 (H2I_C2_R_GAIN_M << H2I_C2_R_GAIN_SHIFT));
841 /* set max volume */
842 hal2->mixer.master = 0xff;
843 hal2->vol_regs->left = 0xff;
844 hal2->vol_regs->right = 0xff;
845}
846
847/*
848 * XXX: later i'll implement mixer for main volume which will be disabled
849 * by default. enabling it users will be allowed to have master volume level
850 * control on panel in their favourite X desktop
851 */
852static void hal2_volume_control(int direction)
853{
854 unsigned int master = hal2_card[0]->mixer.master;
855 struct hal2_vol_regs *vol = hal2_card[0]->vol_regs;
856
857 /* volume up */
858 if (direction > 0 && master < 0xff)
859 master++;
860 /* volume down */
861 else if (direction < 0 && master > 0)
862 master--;
863 /* TODO: mute/unmute */
864 vol->left = master;
865 vol->right = master;
866 hal2_card[0]->mixer.master = master;
867}
868
869static int hal2_mixer_ioctl(struct hal2_card *hal2, unsigned int cmd,
870 unsigned long arg)
871{
872 int val;
873
874 if (cmd == SOUND_MIXER_INFO) {
875 mixer_info info;
876
877 memset(&info, 0, sizeof(info));
878 strlcpy(info.id, hal2str, sizeof(info.id));
879 strlcpy(info.name, hal2str, sizeof(info.name));
880 info.modify_counter = hal2->mixer.modcnt;
881 if (copy_to_user((void *)arg, &info, sizeof(info)))
882 return -EFAULT;
883 return 0;
884 }
885 if (cmd == SOUND_OLD_MIXER_INFO) {
886 _old_mixer_info info;
887
888 memset(&info, 0, sizeof(info));
889 strlcpy(info.id, hal2str, sizeof(info.id));
890 strlcpy(info.name, hal2str, sizeof(info.name));
891 if (copy_to_user((void *)arg, &info, sizeof(info)))
892 return -EFAULT;
893 return 0;
894 }
895 if (cmd == OSS_GETVERSION)
896 return put_user(SOUND_VERSION, (int *)arg);
897
898 if (_IOC_TYPE(cmd) != 'M' || _IOC_SIZE(cmd) != sizeof(int))
899 return -EINVAL;
900
901 if (_IOC_DIR(cmd) == _IOC_READ) {
902 switch (_IOC_NR(cmd)) {
903 /* Give the current record source */
904 case SOUND_MIXER_RECSRC:
905 val = 0; /* FIXME */
906 break;
907 /* Give the supported mixers, all of them support stereo */
908 case SOUND_MIXER_DEVMASK:
909 case SOUND_MIXER_STEREODEVS: {
910 int i;
911
912 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
913 if (mixtable[i].avail)
914 val |= 1 << i;
915 break;
916 }
917 /* Arg contains a bit for each supported recording source */
918 case SOUND_MIXER_RECMASK:
919 val = 0;
920 break;
921 case SOUND_MIXER_CAPS:
922 val = 0;
923 break;
924 /* Read a specific mixer */
925 default: {
926 int i = _IOC_NR(cmd);
927
928 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].avail)
929 return -EINVAL;
930 val = hal2->mixer.volume[mixtable[i].idx];
931 break;
932 }
933 }
934 return put_user(val, (int *)arg);
935 }
936
937 if (_IOC_DIR(cmd) != (_IOC_WRITE|_IOC_READ))
938 return -EINVAL;
939
940 hal2->mixer.modcnt++;
941
942 if (get_user(val, (int *)arg))
943 return -EFAULT;
944
945 switch (_IOC_NR(cmd)) {
946 /* Arg contains a bit for each recording source */
947 case SOUND_MIXER_RECSRC:
948 return 0; /* FIXME */
949 default:
950 return hal2_write_mixer(hal2, _IOC_NR(cmd), val);
951 }
952
953 return 0;
954}
955
956static int hal2_open_mixdev(struct inode *inode, struct file *file)
957{
958 struct hal2_card *hal2 = hal2_mixer_find_card(iminor(inode));
959
960 if (hal2) {
961 file->private_data = hal2;
962 return nonseekable_open(inode, file);
963 }
964 return -ENODEV;
965}
966
967static int hal2_release_mixdev(struct inode *inode, struct file *file)
968{
969 return 0;
970}
971
972static int hal2_ioctl_mixdev(struct inode *inode, struct file *file,
973 unsigned int cmd, unsigned long arg)
974{
975 return hal2_mixer_ioctl((struct hal2_card *)file->private_data, cmd, arg);
976}
977
978static int hal2_ioctl(struct inode *inode, struct file *file,
979 unsigned int cmd, unsigned long arg)
980{
981 int val;
982 struct hal2_card *hal2 = (struct hal2_card *) file->private_data;
983
984 switch (cmd) {
985 case OSS_GETVERSION:
986 return put_user(SOUND_VERSION, (int *)arg);
987
988 case SNDCTL_DSP_SYNC:
989 if (file->f_mode & FMODE_WRITE)
990 return hal2_sync_dac(hal2);
991 return 0;
992
993 case SNDCTL_DSP_SETDUPLEX:
994 return 0;
995
996 case SNDCTL_DSP_GETCAPS:
997 return put_user(DSP_CAP_DUPLEX | DSP_CAP_MULTI, (int *)arg);
998
999 case SNDCTL_DSP_RESET:
1000 if (file->f_mode & FMODE_READ) {
1001 hal2_stop_adc(hal2);
1002 hal2_reset_adc_pointer(hal2);
1003 }
1004 if (file->f_mode & FMODE_WRITE) {
1005 hal2_stop_dac(hal2);
1006 hal2_reset_dac_pointer(hal2);
1007 }
1008 return 0;
1009
1010 case SNDCTL_DSP_SPEED:
1011 if (get_user(val, (int *)arg))
1012 return -EFAULT;
1013 if (file->f_mode & FMODE_READ) {
1014 hal2_stop_adc(hal2);
1015 val = hal2_compute_rate(&hal2->adc, val);
1016 hal2->adc.sample_rate = val;
1017 hal2_set_adc_rate(hal2);
1018 }
1019 if (file->f_mode & FMODE_WRITE) {
1020 hal2_stop_dac(hal2);
1021 val = hal2_compute_rate(&hal2->dac, val);
1022 hal2->dac.sample_rate = val;
1023 hal2_set_dac_rate(hal2);
1024 }
1025 return put_user(val, (int *)arg);
1026
1027 case SNDCTL_DSP_STEREO:
1028 if (get_user(val, (int *)arg))
1029 return -EFAULT;
1030 if (file->f_mode & FMODE_READ) {
1031 hal2_stop_adc(hal2);
1032 hal2->adc.voices = (val) ? 2 : 1;
1033 hal2_setup_adc(hal2);
1034 }
1035 if (file->f_mode & FMODE_WRITE) {
1036 hal2_stop_dac(hal2);
1037 hal2->dac.voices = (val) ? 2 : 1;
1038 hal2_setup_dac(hal2);
1039 }
1040 return 0;
1041
1042 case SNDCTL_DSP_CHANNELS:
1043 if (get_user(val, (int *)arg))
1044 return -EFAULT;
1045 if (val != 0) {
1046 if (file->f_mode & FMODE_READ) {
1047 hal2_stop_adc(hal2);
1048 hal2->adc.voices = (val == 1) ? 1 : 2;
1049 hal2_setup_adc(hal2);
1050 }
1051 if (file->f_mode & FMODE_WRITE) {
1052 hal2_stop_dac(hal2);
1053 hal2->dac.voices = (val == 1) ? 1 : 2;
1054 hal2_setup_dac(hal2);
1055 }
1056 }
1057 val = -EINVAL;
1058 if (file->f_mode & FMODE_READ)
1059 val = hal2->adc.voices;
1060 if (file->f_mode & FMODE_WRITE)
1061 val = hal2->dac.voices;
1062 return put_user(val, (int *)arg);
1063
1064 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1065 return put_user(H2_SUPPORTED_FORMATS, (int *)arg);
1066
1067 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1068 if (get_user(val, (int *)arg))
1069 return -EFAULT;
1070 if (val != AFMT_QUERY) {
1071 if (!(val & H2_SUPPORTED_FORMATS))
1072 return -EINVAL;
1073 if (file->f_mode & FMODE_READ) {
1074 hal2_stop_adc(hal2);
1075 hal2->adc.format = val;
1076 hal2_setup_adc(hal2);
1077 }
1078 if (file->f_mode & FMODE_WRITE) {
1079 hal2_stop_dac(hal2);
1080 hal2->dac.format = val;
1081 hal2_setup_dac(hal2);
1082 }
1083 } else {
1084 val = -EINVAL;
1085 if (file->f_mode & FMODE_READ)
1086 val = hal2->adc.format;
1087 if (file->f_mode & FMODE_WRITE)
1088 val = hal2->dac.format;
1089 }
1090 return put_user(val, (int *)arg);
1091
1092 case SNDCTL_DSP_POST:
1093 return 0;
1094
1095 case SNDCTL_DSP_GETOSPACE: {
1096 audio_buf_info info;
1097 int i;
1098 unsigned long flags;
1099 struct hal2_codec *dac = &hal2->dac;
1100
1101 if (!(file->f_mode & FMODE_WRITE))
1102 return -EINVAL;
1103 info.fragments = 0;
1104 spin_lock_irqsave(&dac->lock, flags);
1105 for (i = 0; i < dac->desc_count; i++)
1106 if (dac->desc[i].cnt == 0)
1107 info.fragments++;
1108 spin_unlock_irqrestore(&dac->lock, flags);
1109 info.fragstotal = dac->desc_count;
1110 info.fragsize = H2_BLOCK_SIZE;
1111 info.bytes = info.fragsize * info.fragments;
1112
1113 return copy_to_user((void *)arg, &info, sizeof(info)) ? -EFAULT : 0;
1114 }
1115
1116 case SNDCTL_DSP_GETISPACE: {
1117 audio_buf_info info;
1118 int i;
1119 unsigned long flags;
1120 struct hal2_codec *adc = &hal2->adc;
1121
1122 if (!(file->f_mode & FMODE_READ))
1123 return -EINVAL;
1124 info.fragments = 0;
1125 info.bytes = 0;
1126 spin_lock_irqsave(&adc->lock, flags);
1127 for (i = 0; i < adc->desc_count; i++)
1128 if (adc->desc[i].cnt > 0) {
1129 info.fragments++;
1130 info.bytes += adc->desc[i].cnt;
1131 }
1132 spin_unlock_irqrestore(&adc->lock, flags);
1133 info.fragstotal = adc->desc_count;
1134 info.fragsize = H2_BLOCK_SIZE;
1135
1136 return copy_to_user((void *)arg, &info, sizeof(info)) ? -EFAULT : 0;
1137 }
1138
1139 case SNDCTL_DSP_NONBLOCK:
1140 file->f_flags |= O_NONBLOCK;
1141 return 0;
1142
1143 case SNDCTL_DSP_GETBLKSIZE:
1144 return put_user(H2_BLOCK_SIZE, (int *)arg);
1145
1146 case SNDCTL_DSP_SETFRAGMENT:
1147 return 0;
1148
1149 case SOUND_PCM_READ_RATE:
1150 val = -EINVAL;
1151 if (file->f_mode & FMODE_READ)
1152 val = hal2->adc.sample_rate;
1153 if (file->f_mode & FMODE_WRITE)
1154 val = hal2->dac.sample_rate;
1155 return put_user(val, (int *)arg);
1156
1157 case SOUND_PCM_READ_CHANNELS:
1158 val = -EINVAL;
1159 if (file->f_mode & FMODE_READ)
1160 val = hal2->adc.voices;
1161 if (file->f_mode & FMODE_WRITE)
1162 val = hal2->dac.voices;
1163 return put_user(val, (int *)arg);
1164
1165 case SOUND_PCM_READ_BITS:
1166 return put_user(16, (int *)arg);
1167 }
1168
1169 return hal2_mixer_ioctl(hal2, cmd, arg);
1170}
1171
1172static ssize_t hal2_read(struct file *file, char *buffer,
1173 size_t count, loff_t *ppos)
1174{
1175 ssize_t err;
1176 struct hal2_card *hal2 = (struct hal2_card *) file->private_data;
1177 struct hal2_codec *adc = &hal2->adc;
1178
1179 if (!count)
1180 return 0;
1181 if (down_interruptible(&adc->sem))
1182 return -EINTR;
1183 if (file->f_flags & O_NONBLOCK) {
1184 err = hal2_get_buffer(hal2, buffer, count);
1185 err = err == 0 ? -EAGAIN : err;
1186 } else {
1187 do {
1188 /* ~10% longer */
1189 signed long timeout = 1000 * H2_BLOCK_SIZE *
1190 2 * adc->voices * HZ / adc->sample_rate / 900;
1191 unsigned long flags;
1192 DECLARE_WAITQUEUE(wait, current);
1193 ssize_t cnt = 0;
1194
1195 err = hal2_get_buffer(hal2, buffer, count);
1196 if (err > 0) {
1197 count -= err;
1198 cnt += err;
1199 buffer += err;
1200 err = cnt;
1201 }
1202 if (count > 0 && err >= 0) {
1203 add_wait_queue(&adc->dma_wait, &wait);
1204 set_current_state(TASK_INTERRUPTIBLE);
1205 schedule_timeout(timeout);
1206 spin_lock_irqsave(&adc->lock, flags);
1207 if (!adc->desc[adc->tail].cnt)
1208 err = -EAGAIN;
1209 spin_unlock_irqrestore(&adc->lock, flags);
1210 if (signal_pending(current))
1211 err = -ERESTARTSYS;
1212 remove_wait_queue(&adc->dma_wait, &wait);
1213 if (err < 0) {
1214 hal2_stop_adc(hal2);
1215 hal2_reset_adc_pointer(hal2);
1216 }
1217 }
1218 } while (count > 0 && err >= 0);
1219 }
1220 up(&adc->sem);
1221
1222 return err;
1223}
1224
1225static ssize_t hal2_write(struct file *file, const char *buffer,
1226 size_t count, loff_t *ppos)
1227{
1228 ssize_t err;
1229 char *buf = (char*) buffer;
1230 struct hal2_card *hal2 = (struct hal2_card *) file->private_data;
1231 struct hal2_codec *dac = &hal2->dac;
1232
1233 if (!count)
1234 return 0;
1235 if (down_interruptible(&dac->sem))
1236 return -EINTR;
1237 if (file->f_flags & O_NONBLOCK) {
1238 err = hal2_add_buffer(hal2, buf, count);
1239 err = err == 0 ? -EAGAIN : err;
1240 } else {
1241 do {
1242 /* ~10% longer */
1243 signed long timeout = 1000 * H2_BLOCK_SIZE *
1244 2 * dac->voices * HZ / dac->sample_rate / 900;
1245 unsigned long flags;
1246 DECLARE_WAITQUEUE(wait, current);
1247 ssize_t cnt = 0;
1248
1249 err = hal2_add_buffer(hal2, buf, count);
1250 if (err > 0) {
1251 count -= err;
1252 cnt += err;
1253 buf += err;
1254 err = cnt;
1255 }
1256 if (count > 0 && err >= 0) {
1257 add_wait_queue(&dac->dma_wait, &wait);
1258 set_current_state(TASK_INTERRUPTIBLE);
1259 schedule_timeout(timeout);
1260 spin_lock_irqsave(&dac->lock, flags);
1261 if (dac->desc[dac->head].cnt)
1262 err = -EAGAIN;
1263 spin_unlock_irqrestore(&dac->lock, flags);
1264 if (signal_pending(current))
1265 err = -ERESTARTSYS;
1266 remove_wait_queue(&dac->dma_wait, &wait);
1267 if (err < 0) {
1268 hal2_stop_dac(hal2);
1269 hal2_reset_dac_pointer(hal2);
1270 }
1271 }
1272 } while (count > 0 && err >= 0);
1273 }
1274 up(&dac->sem);
1275
1276 return err;
1277}
1278
1279static unsigned int hal2_poll(struct file *file, struct poll_table_struct *wait)
1280{
1281 unsigned long flags;
1282 unsigned int mask = 0;
1283 struct hal2_card *hal2 = (struct hal2_card *) file->private_data;
1284
1285 if (file->f_mode & FMODE_READ) {
1286 struct hal2_codec *adc = &hal2->adc;
1287
1288 poll_wait(file, &adc->dma_wait, wait);
1289 spin_lock_irqsave(&adc->lock, flags);
1290 if (adc->desc[adc->tail].cnt > 0)
1291 mask |= POLLIN;
1292 spin_unlock_irqrestore(&adc->lock, flags);
1293 }
1294
1295 if (file->f_mode & FMODE_WRITE) {
1296 struct hal2_codec *dac = &hal2->dac;
1297
1298 poll_wait(file, &dac->dma_wait, wait);
1299 spin_lock_irqsave(&dac->lock, flags);
1300 if (dac->desc[dac->head].cnt == 0)
1301 mask |= POLLOUT;
1302 spin_unlock_irqrestore(&dac->lock, flags);
1303 }
1304
1305 return mask;
1306}
1307
1308static int hal2_open(struct inode *inode, struct file *file)
1309{
1310 int err;
1311 struct hal2_card *hal2 = hal2_dsp_find_card(iminor(inode));
1312
1313 if (!hal2)
1314 return -ENODEV;
1315 file->private_data = hal2;
1316 if (file->f_mode & FMODE_READ) {
1317 struct hal2_codec *adc = &hal2->adc;
1318
1319 if (adc->usecount)
1320 return -EBUSY;
1321 /* OSS spec wanted us to use 8 bit, 8 kHz mono by default,
1322 * but HAL2 can't do 8bit audio */
1323 adc->format = AFMT_S16_BE;
1324 adc->voices = 1;
1325 adc->sample_rate = hal2_compute_rate(adc, 8000);
1326 hal2_set_adc_rate(hal2);
1327 err = hal2_alloc_adc_dmabuf(adc);
1328 if (err)
1329 return err;
1330 hal2_setup_adc(hal2);
1331 adc->usecount++;
1332 }
1333 if (file->f_mode & FMODE_WRITE) {
1334 struct hal2_codec *dac = &hal2->dac;
1335
1336 if (dac->usecount)
1337 return -EBUSY;
1338 dac->format = AFMT_S16_BE;
1339 dac->voices = 1;
1340 dac->sample_rate = hal2_compute_rate(dac, 8000);
1341 hal2_set_dac_rate(hal2);
1342 err = hal2_alloc_dac_dmabuf(dac);
1343 if (err)
1344 return err;
1345 hal2_setup_dac(hal2);
1346 dac->usecount++;
1347 }
1348
1349 return nonseekable_open(inode, file);
1350}
1351
1352static int hal2_release(struct inode *inode, struct file *file)
1353{
1354 struct hal2_card *hal2 = (struct hal2_card *) file->private_data;
1355
1356 if (file->f_mode & FMODE_READ) {
1357 struct hal2_codec *adc = &hal2->adc;
1358
1359 down(&adc->sem);
1360 hal2_stop_adc(hal2);
1361 hal2_free_adc_dmabuf(adc);
1362 adc->usecount--;
1363 up(&adc->sem);
1364 }
1365 if (file->f_mode & FMODE_WRITE) {
1366 struct hal2_codec *dac = &hal2->dac;
1367
1368 down(&dac->sem);
1369 hal2_sync_dac(hal2);
1370 hal2_free_dac_dmabuf(dac);
1371 dac->usecount--;
1372 up(&dac->sem);
1373 }
1374
1375 return 0;
1376}
1377
1378static struct file_operations hal2_audio_fops = {
1379 .owner = THIS_MODULE,
1380 .llseek = no_llseek,
1381 .read = hal2_read,
1382 .write = hal2_write,
1383 .poll = hal2_poll,
1384 .ioctl = hal2_ioctl,
1385 .open = hal2_open,
1386 .release = hal2_release,
1387};
1388
1389static struct file_operations hal2_mixer_fops = {
1390 .owner = THIS_MODULE,
1391 .llseek = no_llseek,
1392 .ioctl = hal2_ioctl_mixdev,
1393 .open = hal2_open_mixdev,
1394 .release = hal2_release_mixdev,
1395};
1396
1397static void hal2_init_codec(struct hal2_codec *codec, struct hpc3_regs *hpc3,
1398 int index)
1399{
1400 codec->pbus.pbusnr = index;
1401 codec->pbus.pbus = &hpc3->pbdma[index];
1402 init_waitqueue_head(&codec->dma_wait);
1403 init_MUTEX(&codec->sem);
1404 spin_lock_init(&codec->lock);
1405}
1406
1407static int hal2_detect(struct hal2_card *hal2)
1408{
1409 unsigned short board, major, minor;
1410 unsigned short rev;
1411
1412 /* reset HAL2 */
1413 hal2_isr_write(hal2, 0);
1414 /* release reset */
1415 hal2_isr_write(hal2, H2_ISR_GLOBAL_RESET_N | H2_ISR_CODEC_RESET_N);
1416
1417 hal2_i_write16(hal2, H2I_RELAY_C, H2I_RELAY_C_STATE);
1418 if ((rev = hal2_rev_look(hal2)) & H2_REV_AUDIO_PRESENT)
1419 return -ENODEV;
1420
1421 board = (rev & H2_REV_BOARD_M) >> 12;
1422 major = (rev & H2_REV_MAJOR_CHIP_M) >> 4;
1423 minor = (rev & H2_REV_MINOR_CHIP_M);
1424
1425 printk(KERN_INFO "SGI HAL2 revision %i.%i.%i\n",
1426 board, major, minor);
1427
1428 return 0;
1429}
1430
1431static int hal2_init_card(struct hal2_card **phal2, struct hpc3_regs *hpc3)
1432{
1433 int ret = 0;
1434 struct hal2_card *hal2;
1435
1436 hal2 = (struct hal2_card *) kmalloc(sizeof(struct hal2_card), GFP_KERNEL);
1437 if (!hal2)
1438 return -ENOMEM;
1439 memset(hal2, 0, sizeof(struct hal2_card));
1440
1441 hal2->ctl_regs = (struct hal2_ctl_regs *)hpc3->pbus_extregs[0];
1442 hal2->aes_regs = (struct hal2_aes_regs *)hpc3->pbus_extregs[1];
1443 hal2->vol_regs = (struct hal2_vol_regs *)hpc3->pbus_extregs[2];
1444 hal2->syn_regs = (struct hal2_syn_regs *)hpc3->pbus_extregs[3];
1445
1446 if (hal2_detect(hal2) < 0) {
1447 ret = -ENODEV;
1448 goto free_card;
1449 }
1450
1451 hal2_init_codec(&hal2->dac, hpc3, 0);
1452 hal2_init_codec(&hal2->adc, hpc3, 1);
1453
1454 /*
1455 * All DMA channel interfaces in HAL2 are designed to operate with
1456 * PBUS programmed for 2 cycles in D3, 2 cycles in D4 and 2 cycles
1457 * in D5. HAL2 is a 16-bit device which can accept both big and little
1458 * endian format. It assumes that even address bytes are on high
1459 * portion of PBUS (15:8) and assumes that HPC3 is programmed to
1460 * accept a live (unsynchronized) version of P_DREQ_N from HAL2.
1461 */
1462#define HAL2_PBUS_DMACFG ((0 << HPC3_DMACFG_D3R_SHIFT) | \
1463 (2 << HPC3_DMACFG_D4R_SHIFT) | \
1464 (2 << HPC3_DMACFG_D5R_SHIFT) | \
1465 (0 << HPC3_DMACFG_D3W_SHIFT) | \
1466 (2 << HPC3_DMACFG_D4W_SHIFT) | \
1467 (2 << HPC3_DMACFG_D5W_SHIFT) | \
1468 HPC3_DMACFG_DS16 | \
1469 HPC3_DMACFG_EVENHI | \
1470 HPC3_DMACFG_RTIME | \
1471 (8 << HPC3_DMACFG_BURST_SHIFT) | \
1472 HPC3_DMACFG_DRQLIVE)
1473 /*
1474 * Ignore what's mentioned in the specification and write value which
1475 * works in The Real World (TM)
1476 */
1477 hpc3->pbus_dmacfg[hal2->dac.pbus.pbusnr][0] = 0x8208844;
1478 hpc3->pbus_dmacfg[hal2->adc.pbus.pbusnr][0] = 0x8208844;
1479
1480 if (request_irq(SGI_HPCDMA_IRQ, hal2_interrupt, SA_SHIRQ,
1481 hal2str, hal2)) {
1482 printk(KERN_ERR "HAL2: Can't get irq %d\n", SGI_HPCDMA_IRQ);
1483 ret = -EAGAIN;
1484 goto free_card;
1485 }
1486
1487 hal2->dev_dsp = register_sound_dsp(&hal2_audio_fops, -1);
1488 if (hal2->dev_dsp < 0) {
1489 ret = hal2->dev_dsp;
1490 goto free_irq;
1491 }
1492
1493 hal2->dev_mixer = register_sound_mixer(&hal2_mixer_fops, -1);
1494 if (hal2->dev_mixer < 0) {
1495 ret = hal2->dev_mixer;
1496 goto unregister_dsp;
1497 }
1498
1499 hal2_init_mixer(hal2);
1500
1501 *phal2 = hal2;
1502 return 0;
1503unregister_dsp:
1504 unregister_sound_dsp(hal2->dev_dsp);
1505free_irq:
1506 free_irq(SGI_HPCDMA_IRQ, hal2);
1507free_card:
1508 kfree(hal2);
1509
1510 return ret;
1511}
1512
1513extern void (*indy_volume_button)(int);
1514
1515/*
1516 * Assuming only one HAL2 card. Mail me if you ever meet machine with
1517 * more than one.
1518 */
1519static int __init init_hal2(void)
1520{
1521 int i, error;
1522
1523 for (i = 0; i < MAXCARDS; i++)
1524 hal2_card[i] = NULL;
1525
1526 error = hal2_init_card(&hal2_card[0], hpc3c0);
1527
1528 /* let Indy's volume buttons work */
1529 if (!error && !ip22_is_fullhouse())
1530 indy_volume_button = hal2_volume_control;
1531
1532 return error;
1533
1534}
1535
1536static void __exit exit_hal2(void)
1537{
1538 int i;
1539
1540 /* unregister volume butons callback function */
1541 indy_volume_button = NULL;
1542
1543 for (i = 0; i < MAXCARDS; i++)
1544 if (hal2_card[i]) {
1545 free_irq(SGI_HPCDMA_IRQ, hal2_card[i]);
1546 unregister_sound_dsp(hal2_card[i]->dev_dsp);
1547 unregister_sound_mixer(hal2_card[i]->dev_mixer);
1548 kfree(hal2_card[i]);
1549 }
1550}
1551
1552module_init(init_hal2);
1553module_exit(exit_hal2);
1554
1555MODULE_DESCRIPTION("OSS compatible driver for SGI HAL2 audio");
1556MODULE_AUTHOR("Ladislav Michl");
1557MODULE_LICENSE("GPL");
diff --git a/sound/oss/hal2.h b/sound/oss/hal2.h
new file mode 100644
index 000000000000..2bd3b52d8a37
--- /dev/null
+++ b/sound/oss/hal2.h
@@ -0,0 +1,248 @@
1#ifndef __HAL2_H
2#define __HAL2_H
3
4/*
5 * Driver for HAL2 sound processors
6 * Copyright (c) 1999 Ulf Carlsson <ulfc@bun.falkenberg.se>
7 * Copyright (c) 2001, 2002, 2003 Ladislav Michl <ladis@linux-mips.org>
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 version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24#include <asm/addrspace.h>
25#include <asm/sgi/hpc3.h>
26#include <linux/spinlock.h>
27#include <linux/types.h>
28
29/* Indirect status register */
30
31#define H2_ISR_TSTATUS 0x01 /* RO: transaction status 1=busy */
32#define H2_ISR_USTATUS 0x02 /* RO: utime status bit 1=armed */
33#define H2_ISR_QUAD_MODE 0x04 /* codec mode 0=indigo 1=quad */
34#define H2_ISR_GLOBAL_RESET_N 0x08 /* chip global reset 0=reset */
35#define H2_ISR_CODEC_RESET_N 0x10 /* codec/synth reset 0=reset */
36
37/* Revision register */
38
39#define H2_REV_AUDIO_PRESENT 0x8000 /* RO: audio present 0=present */
40#define H2_REV_BOARD_M 0x7000 /* RO: bits 14:12, board revision */
41#define H2_REV_MAJOR_CHIP_M 0x00F0 /* RO: bits 7:4, major chip revision */
42#define H2_REV_MINOR_CHIP_M 0x000F /* RO: bits 3:0, minor chip revision */
43
44/* Indirect address register */
45
46/*
47 * Address of indirect internal register to be accessed. A write to this
48 * register initiates read or write access to the indirect registers in the
49 * HAL2. Note that there af four indirect data registers for write access to
50 * registers larger than 16 byte.
51 */
52
53#define H2_IAR_TYPE_M 0xF000 /* bits 15:12, type of functional */
54 /* block the register resides in */
55 /* 1=DMA Port */
56 /* 9=Global DMA Control */
57 /* 2=Bresenham */
58 /* 3=Unix Timer */
59#define H2_IAR_NUM_M 0x0F00 /* bits 11:8 instance of the */
60 /* blockin which the indirect */
61 /* register resides */
62 /* If IAR_TYPE_M=DMA Port: */
63 /* 1=Synth In */
64 /* 2=AES In */
65 /* 3=AES Out */
66 /* 4=DAC Out */
67 /* 5=ADC Out */
68 /* 6=Synth Control */
69 /* If IAR_TYPE_M=Global DMA Control: */
70 /* 1=Control */
71 /* If IAR_TYPE_M=Bresenham: */
72 /* 1=Bresenham Clock Gen 1 */
73 /* 2=Bresenham Clock Gen 2 */
74 /* 3=Bresenham Clock Gen 3 */
75 /* If IAR_TYPE_M=Unix Timer: */
76 /* 1=Unix Timer */
77#define H2_IAR_ACCESS_SELECT 0x0080 /* 1=read 0=write */
78#define H2_IAR_PARAM 0x000C /* Parameter Select */
79#define H2_IAR_RB_INDEX_M 0x0003 /* Read Back Index */
80 /* 00:word0 */
81 /* 01:word1 */
82 /* 10:word2 */
83 /* 11:word3 */
84/*
85 * HAL2 internal addressing
86 *
87 * The HAL2 has "indirect registers" (idr) which are accessed by writing to the
88 * Indirect Data registers. Write the address to the Indirect Address register
89 * to transfer the data.
90 *
91 * We define the H2IR_* to the read address and H2IW_* to the write address and
92 * H2I_* to be fields in whatever register is referred to.
93 *
94 * When we write to indirect registers which are larger than one word (16 bit)
95 * we have to fill more than one indirect register before writing. When we read
96 * back however we have to read several times, each time with different Read
97 * Back Indexes (there are defs for doing this easily).
98 */
99
100/*
101 * Relay Control
102 */
103#define H2I_RELAY_C 0x9100
104#define H2I_RELAY_C_STATE 0x01 /* state of RELAY pin signal */
105
106/* DMA port enable */
107
108#define H2I_DMA_PORT_EN 0x9104
109#define H2I_DMA_PORT_EN_SY_IN 0x01 /* Synth_in DMA port */
110#define H2I_DMA_PORT_EN_AESRX 0x02 /* AES receiver DMA port */
111#define H2I_DMA_PORT_EN_AESTX 0x04 /* AES transmitter DMA port */
112#define H2I_DMA_PORT_EN_CODECTX 0x08 /* CODEC transmit DMA port */
113#define H2I_DMA_PORT_EN_CODECR 0x10 /* CODEC receive DMA port */
114
115#define H2I_DMA_END 0x9108 /* global dma endian select */
116#define H2I_DMA_END_SY_IN 0x01 /* Synth_in DMA port */
117#define H2I_DMA_END_AESRX 0x02 /* AES receiver DMA port */
118#define H2I_DMA_END_AESTX 0x04 /* AES transmitter DMA port */
119#define H2I_DMA_END_CODECTX 0x08 /* CODEC transmit DMA port */
120#define H2I_DMA_END_CODECR 0x10 /* CODEC receive DMA port */
121 /* 0=b_end 1=l_end */
122
123#define H2I_DMA_DRV 0x910C /* global PBUS DMA enable */
124
125#define H2I_SYNTH_C 0x1104 /* Synth DMA control */
126
127#define H2I_AESRX_C 0x1204 /* AES RX dma control */
128
129#define H2I_C_TS_EN 0x20 /* Timestamp enable */
130#define H2I_C_TS_FRMT 0x40 /* Timestamp format */
131#define H2I_C_NAUDIO 0x80 /* Sign extend */
132
133/* AESRX CTL, 16 bit */
134
135#define H2I_AESTX_C 0x1304 /* AES TX DMA control */
136#define H2I_AESTX_C_CLKID_SHIFT 3 /* Bresenham Clock Gen 1-3 */
137#define H2I_AESTX_C_CLKID_M 0x18
138#define H2I_AESTX_C_DATAT_SHIFT 8 /* 1=mono 2=stereo (3=quad) */
139#define H2I_AESTX_C_DATAT_M 0x300
140
141/* CODEC registers */
142
143#define H2I_DAC_C1 0x1404 /* DAC DMA control, 16 bit */
144#define H2I_DAC_C2 0x1408 /* DAC DMA control, 32 bit */
145#define H2I_ADC_C1 0x1504 /* ADC DMA control, 16 bit */
146#define H2I_ADC_C2 0x1508 /* ADC DMA control, 32 bit */
147
148/* Bits in CTL1 register */
149
150#define H2I_C1_DMA_SHIFT 0 /* DMA channel */
151#define H2I_C1_DMA_M 0x7
152#define H2I_C1_CLKID_SHIFT 3 /* Bresenham Clock Gen 1-3 */
153#define H2I_C1_CLKID_M 0x18
154#define H2I_C1_DATAT_SHIFT 8 /* 1=mono 2=stereo (3=quad) */
155#define H2I_C1_DATAT_M 0x300
156
157/* Bits in CTL2 register */
158
159#define H2I_C2_R_GAIN_SHIFT 0 /* right a/d input gain */
160#define H2I_C2_R_GAIN_M 0xf
161#define H2I_C2_L_GAIN_SHIFT 4 /* left a/d input gain */
162#define H2I_C2_L_GAIN_M 0xf0
163#define H2I_C2_R_SEL 0x100 /* right input select */
164#define H2I_C2_L_SEL 0x200 /* left input select */
165#define H2I_C2_MUTE 0x400 /* mute */
166#define H2I_C2_DO1 0x00010000 /* digital output port bit 0 */
167#define H2I_C2_DO2 0x00020000 /* digital output port bit 1 */
168#define H2I_C2_R_ATT_SHIFT 18 /* right d/a output - */
169#define H2I_C2_R_ATT_M 0x007c0000 /* attenuation */
170#define H2I_C2_L_ATT_SHIFT 23 /* left d/a output - */
171#define H2I_C2_L_ATT_M 0x0f800000 /* attenuation */
172
173#define H2I_SYNTH_MAP_C 0x1104 /* synth dma handshake ctrl */
174
175/* Clock generator CTL 1, 16 bit */
176
177#define H2I_BRES1_C1 0x2104
178#define H2I_BRES2_C1 0x2204
179#define H2I_BRES3_C1 0x2304
180
181#define H2I_BRES_C1_SHIFT 0 /* 0=48.0 1=44.1 2=aes_rx */
182#define H2I_BRES_C1_M 0x03
183
184/* Clock generator CTL 2, 32 bit */
185
186#define H2I_BRES1_C2 0x2108
187#define H2I_BRES2_C2 0x2208
188#define H2I_BRES3_C2 0x2308
189
190#define H2I_BRES_C2_INC_SHIFT 0 /* increment value */
191#define H2I_BRES_C2_INC_M 0xffff
192#define H2I_BRES_C2_MOD_SHIFT 16 /* modcontrol value */
193#define H2I_BRES_C2_MOD_M 0xffff0000 /* modctrl=0xffff&(modinc-1) */
194
195/* Unix timer, 64 bit */
196
197#define H2I_UTIME 0x3104
198#define H2I_UTIME_0_LD 0xffff /* microseconds, LSB's */
199#define H2I_UTIME_1_LD0 0x0f /* microseconds, MSB's */
200#define H2I_UTIME_1_LD1 0xf0 /* tenths of microseconds */
201#define H2I_UTIME_2_LD 0xffff /* seconds, LSB's */
202#define H2I_UTIME_3_LD 0xffff /* seconds, MSB's */
203
204struct hal2_ctl_regs {
205 u32 _unused0[4];
206 volatile u32 isr; /* 0x10 Status Register */
207 u32 _unused1[3];
208 volatile u32 rev; /* 0x20 Revision Register */
209 u32 _unused2[3];
210 volatile u32 iar; /* 0x30 Indirect Address Register */
211 u32 _unused3[3];
212 volatile u32 idr0; /* 0x40 Indirect Data Register 0 */
213 u32 _unused4[3];
214 volatile u32 idr1; /* 0x50 Indirect Data Register 1 */
215 u32 _unused5[3];
216 volatile u32 idr2; /* 0x60 Indirect Data Register 2 */
217 u32 _unused6[3];
218 volatile u32 idr3; /* 0x70 Indirect Data Register 3 */
219};
220
221struct hal2_aes_regs {
222 volatile u32 rx_stat[2]; /* Status registers */
223 volatile u32 rx_cr[2]; /* Control registers */
224 volatile u32 rx_ud[4]; /* User data window */
225 volatile u32 rx_st[24]; /* Channel status data */
226
227 volatile u32 tx_stat[1]; /* Status register */
228 volatile u32 tx_cr[3]; /* Control registers */
229 volatile u32 tx_ud[4]; /* User data window */
230 volatile u32 tx_st[24]; /* Channel status data */
231};
232
233struct hal2_vol_regs {
234 volatile u32 right; /* Right volume */
235 volatile u32 left; /* Left volume */
236};
237
238struct hal2_syn_regs {
239 u32 _unused0[2];
240 volatile u32 page; /* DOC Page register */
241 volatile u32 regsel; /* DOC Register selection */
242 volatile u32 dlow; /* DOC Data low */
243 volatile u32 dhigh; /* DOC Data high */
244 volatile u32 irq; /* IRQ Status */
245 volatile u32 dram; /* DRAM Access */
246};
247
248#endif /* __HAL2_H */
diff --git a/sound/oss/harmony.c b/sound/oss/harmony.c
new file mode 100644
index 000000000000..bee9d344cd26
--- /dev/null
+++ b/sound/oss/harmony.c
@@ -0,0 +1,1330 @@
1/*
2 drivers/sound/harmony.c
3
4 This is a sound driver for ASP's and Lasi's Harmony sound chip
5 and is unlikely to be used for anything other than on a HP PA-RISC.
6
7 Harmony is found in HP 712s, 715/new and many other GSC based machines.
8 On older 715 machines you'll find the technically identical chip
9 called 'Vivace'. Both Harmony and Vicace are supported by this driver.
10
11 Copyright 2000 (c) Linuxcare Canada, Alex deVries <alex@onefishtwo.ca>
12 Copyright 2000-2003 (c) Helge Deller <deller@gmx.de>
13 Copyright 2001 (c) Matthieu Delahaye <delahaym@esiee.fr>
14 Copyright 2001 (c) Jean-Christophe Vaugeois <vaugeoij@esiee.fr>
15 Copyright 2004 (c) Stuart Brady <sdbrady@ntlworld.com>
16
17
18TODO:
19 - fix SNDCTL_DSP_GETOSPACE and SNDCTL_DSP_GETISPACE ioctls to
20 return the real values
21 - add private ioctl for selecting line- or microphone input
22 (only one of them is available at the same time)
23 - add module parameters
24 - implement mmap functionality
25 - implement gain meter ?
26 - ...
27*/
28
29#include <linux/delay.h>
30#include <linux/errno.h>
31#include <linux/init.h>
32#include <linux/interrupt.h>
33#include <linux/ioport.h>
34#include <linux/types.h>
35#include <linux/mm.h>
36#include <linux/pci.h>
37
38#include <asm/parisc-device.h>
39#include <asm/io.h>
40
41#include "sound_config.h"
42
43
44#define PFX "harmony: "
45#define HARMONY_VERSION "V0.9a"
46
47#undef DEBUG
48#ifdef DEBUG
49# define DPRINTK printk
50#else
51# define DPRINTK(x,...)
52#endif
53
54
55#define MAX_BUFS 10 /* maximum number of rotating buffers */
56#define HARMONY_BUF_SIZE 4096 /* needs to be a multiple of PAGE_SIZE (4096)! */
57
58#define CNTL_C 0x80000000
59#define CNTL_ST 0x00000020
60#define CNTL_44100 0x00000015 /* HARMONY_SR_44KHZ */
61#define CNTL_8000 0x00000008 /* HARMONY_SR_8KHZ */
62
63#define GAINCTL_HE 0x08000000
64#define GAINCTL_LE 0x04000000
65#define GAINCTL_SE 0x02000000
66
67#define DSTATUS_PN 0x00000200
68#define DSTATUS_RN 0x00000002
69
70#define DSTATUS_IE 0x80000000
71
72#define HARMONY_DF_16BIT_LINEAR 0
73#define HARMONY_DF_8BIT_ULAW 1
74#define HARMONY_DF_8BIT_ALAW 2
75
76#define HARMONY_SS_MONO 0
77#define HARMONY_SS_STEREO 1
78
79#define HARMONY_SR_8KHZ 0x08
80#define HARMONY_SR_16KHZ 0x09
81#define HARMONY_SR_27KHZ 0x0A
82#define HARMONY_SR_32KHZ 0x0B
83#define HARMONY_SR_48KHZ 0x0E
84#define HARMONY_SR_9KHZ 0x0F
85#define HARMONY_SR_5KHZ 0x10
86#define HARMONY_SR_11KHZ 0x11
87#define HARMONY_SR_18KHZ 0x12
88#define HARMONY_SR_22KHZ 0x13
89#define HARMONY_SR_37KHZ 0x14
90#define HARMONY_SR_44KHZ 0x15
91#define HARMONY_SR_33KHZ 0x16
92#define HARMONY_SR_6KHZ 0x17
93
94/*
95 * Some magics numbers used to auto-detect file formats
96 */
97
98#define HARMONY_MAGIC_8B_ULAW 1
99#define HARMONY_MAGIC_8B_ALAW 27
100#define HARMONY_MAGIC_16B_LINEAR 3
101#define HARMONY_MAGIC_MONO 1
102#define HARMONY_MAGIC_STEREO 2
103
104/*
105 * Channels Positions in mixer register
106 */
107
108#define GAIN_HE_SHIFT 27
109#define GAIN_HE_MASK ( 1 << GAIN_HE_SHIFT)
110#define GAIN_LE_SHIFT 26
111#define GAIN_LE_MASK ( 1 << GAIN_LE_SHIFT)
112#define GAIN_SE_SHIFT 25
113#define GAIN_SE_MASK ( 1 << GAIN_SE_SHIFT)
114#define GAIN_IS_SHIFT 24
115#define GAIN_IS_MASK ( 1 << GAIN_IS_SHIFT)
116#define GAIN_MA_SHIFT 20
117#define GAIN_MA_MASK ( 0x0f << GAIN_MA_SHIFT)
118#define GAIN_LI_SHIFT 16
119#define GAIN_LI_MASK ( 0x0f << GAIN_LI_SHIFT)
120#define GAIN_RI_SHIFT 12
121#define GAIN_RI_MASK ( 0x0f << GAIN_RI_SHIFT)
122#define GAIN_LO_SHIFT 6
123#define GAIN_LO_MASK ( 0x3f << GAIN_LO_SHIFT)
124#define GAIN_RO_SHIFT 0
125#define GAIN_RO_MASK ( 0x3f << GAIN_RO_SHIFT)
126
127
128#define MAX_OUTPUT_LEVEL (GAIN_RO_MASK >> GAIN_RO_SHIFT)
129#define MAX_INPUT_LEVEL (GAIN_RI_MASK >> GAIN_RI_SHIFT)
130#define MAX_MONITOR_LEVEL (GAIN_MA_MASK >> GAIN_MA_SHIFT)
131
132#define MIXER_INTERNAL SOUND_MIXER_LINE1
133#define MIXER_LINEOUT SOUND_MIXER_LINE2
134#define MIXER_HEADPHONES SOUND_MIXER_LINE3
135
136#define MASK_INTERNAL SOUND_MASK_LINE1
137#define MASK_LINEOUT SOUND_MASK_LINE2
138#define MASK_HEADPHONES SOUND_MASK_LINE3
139
140/*
141 * Channels Mask in mixer register
142 */
143
144#define GAIN_TOTAL_SILENCE 0x00F00FFF
145#define GAIN_DEFAULT 0x0FF00000
146
147
148struct harmony_hpa {
149 u8 unused000;
150 u8 id;
151 u8 teleshare_id;
152 u8 unused003;
153 u32 reset;
154 u32 cntl;
155 u32 gainctl;
156 u32 pnxtadd;
157 u32 pcuradd;
158 u32 rnxtadd;
159 u32 rcuradd;
160 u32 dstatus;
161 u32 ov;
162 u32 pio;
163 u32 unused02c;
164 u32 unused030[3];
165 u32 diag;
166};
167
168struct harmony_dev {
169 struct harmony_hpa *hpa;
170 struct parisc_device *dev;
171 u32 current_gain;
172 u32 dac_rate; /* 8000 ... 48000 (Hz) */
173 u8 data_format; /* HARMONY_DF_xx_BIT_xxx */
174 u8 sample_rate; /* HARMONY_SR_xx_KHZ */
175 u8 stereo_select; /* HARMONY_SS_MONO or HARMONY_SS_STEREO */
176 int format_initialized :1;
177 int suspended_playing :1;
178 int suspended_recording :1;
179
180 int blocked_playing :1;
181 int blocked_recording :1;
182 int audio_open :1;
183 int mixer_open :1;
184
185 wait_queue_head_t wq_play, wq_record;
186 int first_filled_play; /* first buffer containing data (next to play) */
187 int nb_filled_play;
188 int play_offset;
189 int first_filled_record;
190 int nb_filled_record;
191
192 int dsp_unit, mixer_unit;
193};
194
195
196static struct harmony_dev harmony;
197
198
199/*
200 * Dynamic sound buffer allocation and DMA memory
201 */
202
203struct harmony_buffer {
204 unsigned char *addr;
205 dma_addr_t dma_handle;
206 int dma_coherent; /* Zero if dma_alloc_coherent() fails */
207 unsigned int len;
208};
209
210/*
211 * Harmony memory buffers
212 */
213
214static struct harmony_buffer played_buf, recorded_buf, silent, graveyard;
215
216
217#define CHECK_WBACK_INV_OFFSET(b,offset,len) \
218 do { if (!b.dma_coherent) \
219 dma_cache_wback_inv((unsigned long)b.addr+offset,len); \
220 } while (0)
221
222
223static int __init harmony_alloc_buffer(struct harmony_buffer *b,
224 unsigned int buffer_count)
225{
226 b->len = buffer_count * HARMONY_BUF_SIZE;
227 b->addr = dma_alloc_coherent(&harmony.dev->dev,
228 b->len, &b->dma_handle, GFP_KERNEL|GFP_DMA);
229 if (b->addr && b->dma_handle) {
230 b->dma_coherent = 1;
231 DPRINTK(KERN_INFO PFX "coherent memory: 0x%lx, played_buf: 0x%lx\n",
232 (unsigned long)b->dma_handle, (unsigned long)b->addr);
233 } else {
234 b->dma_coherent = 0;
235 /* kmalloc()ed memory will HPMC on ccio machines ! */
236 b->addr = kmalloc(b->len, GFP_KERNEL);
237 if (!b->addr) {
238 printk(KERN_ERR PFX "couldn't allocate memory\n");
239 return -EBUSY;
240 }
241 b->dma_handle = __pa(b->addr);
242 }
243 return 0;
244}
245
246static void __exit harmony_free_buffer(struct harmony_buffer *b)
247{
248 if (!b->addr)
249 return;
250
251 if (b->dma_coherent)
252 dma_free_coherent(&harmony.dev->dev,
253 b->len, b->addr, b->dma_handle);
254 else
255 kfree(b->addr);
256
257 memset(b, 0, sizeof(*b));
258}
259
260
261
262/*
263 * Low-Level sound-chip programming
264 */
265
266static void __inline__ harmony_wait_CNTL(void)
267{
268 /* Wait until we're out of control mode */
269 while (gsc_readl(&harmony.hpa->cntl) & CNTL_C)
270 /* wait */ ;
271}
272
273
274static void harmony_update_control(void)
275{
276 u32 default_cntl;
277
278 /* Set CNTL */
279 default_cntl = (CNTL_C | /* The C bit */
280 (harmony.data_format << 6) | /* Set the data format */
281 (harmony.stereo_select << 5) | /* Stereo select */
282 (harmony.sample_rate)); /* Set sample rate */
283 harmony.format_initialized = 1;
284
285 /* initialize CNTL */
286 gsc_writel(default_cntl, &harmony.hpa->cntl);
287}
288
289static void harmony_set_control(u8 data_format, u8 sample_rate, u8 stereo_select)
290{
291 harmony.sample_rate = sample_rate;
292 harmony.data_format = data_format;
293 harmony.stereo_select = stereo_select;
294 harmony_update_control();
295}
296
297static void harmony_set_rate(u8 data_rate)
298{
299 harmony.sample_rate = data_rate;
300 harmony_update_control();
301}
302
303static int harmony_detect_rate(int *freq)
304{
305 int newrate;
306 switch (*freq) {
307 case 8000: newrate = HARMONY_SR_8KHZ; break;
308 case 16000: newrate = HARMONY_SR_16KHZ; break;
309 case 27428: newrate = HARMONY_SR_27KHZ; break;
310 case 32000: newrate = HARMONY_SR_32KHZ; break;
311 case 48000: newrate = HARMONY_SR_48KHZ; break;
312 case 9600: newrate = HARMONY_SR_9KHZ; break;
313 case 5512: newrate = HARMONY_SR_5KHZ; break;
314 case 11025: newrate = HARMONY_SR_11KHZ; break;
315 case 18900: newrate = HARMONY_SR_18KHZ; break;
316 case 22050: newrate = HARMONY_SR_22KHZ; break;
317 case 37800: newrate = HARMONY_SR_37KHZ; break;
318 case 44100: newrate = HARMONY_SR_44KHZ; break;
319 case 33075: newrate = HARMONY_SR_33KHZ; break;
320 case 6615: newrate = HARMONY_SR_6KHZ; break;
321 default: newrate = HARMONY_SR_8KHZ;
322 *freq = 8000; break;
323 }
324 return newrate;
325}
326
327static void harmony_set_format(u8 data_format)
328{
329 harmony.data_format = data_format;
330 harmony_update_control();
331}
332
333static void harmony_set_stereo(u8 stereo_select)
334{
335 harmony.stereo_select = stereo_select;
336 harmony_update_control();
337}
338
339static void harmony_disable_interrupts(void)
340{
341 harmony_wait_CNTL();
342 gsc_writel(0, &harmony.hpa->dstatus);
343}
344
345static void harmony_enable_interrupts(void)
346{
347 harmony_wait_CNTL();
348 gsc_writel(DSTATUS_IE, &harmony.hpa->dstatus);
349}
350
351/*
352 * harmony_silence()
353 *
354 * This subroutine fills in a buffer starting at location start and
355 * silences for length bytes. This references the current
356 * configuration of the audio format.
357 *
358 */
359
360static void harmony_silence(struct harmony_buffer *buffer, int start, int length)
361{
362 u8 silence_char;
363
364 /* Despite what you hear, silence is different in
365 different audio formats. */
366 switch (harmony.data_format) {
367 case HARMONY_DF_8BIT_ULAW: silence_char = 0x55; break;
368 case HARMONY_DF_8BIT_ALAW: silence_char = 0xff; break;
369 case HARMONY_DF_16BIT_LINEAR: /* fall through */
370 default: silence_char = 0;
371 }
372
373 memset(buffer->addr+start, silence_char, length);
374}
375
376
377static int harmony_audio_open(struct inode *inode, struct file *file)
378{
379 if (harmony.audio_open)
380 return -EBUSY;
381
382 harmony.audio_open = 1;
383 harmony.suspended_playing = harmony.suspended_recording = 1;
384 harmony.blocked_playing = harmony.blocked_recording = 0;
385 harmony.first_filled_play = harmony.first_filled_record = 0;
386 harmony.nb_filled_play = harmony.nb_filled_record = 0;
387 harmony.play_offset = 0;
388 init_waitqueue_head(&harmony.wq_play);
389 init_waitqueue_head(&harmony.wq_record);
390
391 /* Start off in a balanced mode. */
392 harmony_set_control(HARMONY_DF_8BIT_ULAW, HARMONY_SR_8KHZ, HARMONY_SS_MONO);
393 harmony_update_control();
394 harmony.format_initialized = 0;
395
396 /* Clear out all the buffers and flush to cache */
397 harmony_silence(&played_buf, 0, HARMONY_BUF_SIZE*MAX_BUFS);
398 CHECK_WBACK_INV_OFFSET(played_buf, 0, HARMONY_BUF_SIZE*MAX_BUFS);
399
400 return 0;
401}
402
403/*
404 * Release (close) the audio device.
405 */
406
407static int harmony_audio_release(struct inode *inode, struct file *file)
408{
409 if (!harmony.audio_open)
410 return -EBUSY;
411
412 harmony.audio_open = 0;
413
414 return 0;
415}
416
417/*
418 * Read recorded data off the audio device.
419 */
420
421static ssize_t harmony_audio_read(struct file *file,
422 char *buffer,
423 size_t size_count,
424 loff_t *ppos)
425{
426 int total_count = (int) size_count;
427 int count = 0;
428 int buf_to_read;
429
430 while (count<total_count) {
431 /* Wait until we're out of control mode */
432 harmony_wait_CNTL();
433
434 /* Figure out which buffer to fill in */
435 if (harmony.nb_filled_record <= 2) {
436 harmony.blocked_recording = 1;
437 if (harmony.suspended_recording) {
438 harmony.suspended_recording = 0;
439 harmony_enable_interrupts();
440 }
441
442 interruptible_sleep_on(&harmony.wq_record);
443 harmony.blocked_recording = 0;
444 }
445
446 if (harmony.nb_filled_record < 2)
447 return -EBUSY;
448
449 buf_to_read = harmony.first_filled_record;
450
451 /* Copy the page to an aligned buffer */
452 if (copy_to_user(buffer+count, recorded_buf.addr +
453 (HARMONY_BUF_SIZE*buf_to_read),
454 HARMONY_BUF_SIZE)) {
455 count = -EFAULT;
456 break;
457 }
458
459 harmony.nb_filled_record--;
460 harmony.first_filled_record++;
461 harmony.first_filled_record %= MAX_BUFS;
462
463 count += HARMONY_BUF_SIZE;
464 }
465 return count;
466}
467
468
469
470
471/*
472 * Here is the place where we try to recognize file format.
473 * Sun/NeXT .au files begin with the string .snd
474 * At offset 12 is specified the encoding.
475 * At offset 16 is specified speed rate
476 * At Offset 20 is specified the numbers of voices
477 */
478
479#define four_bytes_to_u32(start) (file_header[start] << 24)|\
480 (file_header[start+1] << 16)|\
481 (file_header[start+2] << 8)|\
482 (file_header[start+3]);
483
484#define test_rate(tested,real_value,harmony_value) if ((tested)<=(real_value))\
485
486
487static int harmony_format_auto_detect(const char *buffer, int block_size)
488{
489 u8 file_header[24];
490 u32 start_string;
491 int ret = 0;
492
493 if (block_size>24) {
494 if (copy_from_user(file_header, buffer, sizeof(file_header)))
495 ret = -EFAULT;
496
497 start_string = four_bytes_to_u32(0);
498
499 if ((file_header[4]==0) && (start_string==0x2E736E64)) {
500 u32 format;
501 u32 nb_voices;
502 u32 speed;
503
504 format = four_bytes_to_u32(12);
505 nb_voices = four_bytes_to_u32(20);
506 speed = four_bytes_to_u32(16);
507
508 switch (format) {
509 case HARMONY_MAGIC_8B_ULAW:
510 harmony.data_format = HARMONY_DF_8BIT_ULAW;
511 break;
512 case HARMONY_MAGIC_8B_ALAW:
513 harmony.data_format = HARMONY_DF_8BIT_ALAW;
514 break;
515 case HARMONY_MAGIC_16B_LINEAR:
516 harmony.data_format = HARMONY_DF_16BIT_LINEAR;
517 break;
518 default:
519 harmony_set_control(HARMONY_DF_16BIT_LINEAR,
520 HARMONY_SR_44KHZ, HARMONY_SS_STEREO);
521 goto out;
522 }
523 switch (nb_voices) {
524 case HARMONY_MAGIC_MONO:
525 harmony.stereo_select = HARMONY_SS_MONO;
526 break;
527 case HARMONY_MAGIC_STEREO:
528 harmony.stereo_select = HARMONY_SS_STEREO;
529 break;
530 default:
531 harmony.stereo_select = HARMONY_SS_MONO;
532 break;
533 }
534 harmony_set_rate(harmony_detect_rate(&speed));
535 harmony.dac_rate = speed;
536 goto out;
537 }
538 }
539 harmony_set_control(HARMONY_DF_8BIT_ULAW, HARMONY_SR_8KHZ, HARMONY_SS_MONO);
540out:
541 return ret;
542}
543#undef four_bytes_to_u32
544
545
546static ssize_t harmony_audio_write(struct file *file,
547 const char *buffer,
548 size_t size_count,
549 loff_t *ppos)
550{
551 int total_count = (int) size_count;
552 int count = 0;
553 int frame_size;
554 int buf_to_fill;
555 int fresh_buffer;
556
557 if (!harmony.format_initialized) {
558 if (harmony_format_auto_detect(buffer, total_count))
559 return -EFAULT;
560 }
561
562 while (count<total_count) {
563 /* Wait until we're out of control mode */
564 harmony_wait_CNTL();
565
566 /* Figure out which buffer to fill in */
567 if (harmony.nb_filled_play+2 >= MAX_BUFS && !harmony.play_offset) {
568 harmony.blocked_playing = 1;
569 interruptible_sleep_on(&harmony.wq_play);
570 harmony.blocked_playing = 0;
571 }
572 if (harmony.nb_filled_play+2 >= MAX_BUFS && !harmony.play_offset)
573 return -EBUSY;
574
575
576 buf_to_fill = (harmony.first_filled_play+harmony.nb_filled_play);
577 if (harmony.play_offset) {
578 buf_to_fill--;
579 buf_to_fill += MAX_BUFS;
580 }
581 buf_to_fill %= MAX_BUFS;
582
583 fresh_buffer = (harmony.play_offset == 0);
584
585 /* Figure out the size of the frame */
586 if ((total_count-count) >= HARMONY_BUF_SIZE - harmony.play_offset) {
587 frame_size = HARMONY_BUF_SIZE - harmony.play_offset;
588 } else {
589 frame_size = total_count - count;
590 /* Clear out the buffer, since there we'll only be
591 overlaying part of the old buffer with the new one */
592 harmony_silence(&played_buf,
593 HARMONY_BUF_SIZE*buf_to_fill+frame_size+harmony.play_offset,
594 HARMONY_BUF_SIZE-frame_size-harmony.play_offset);
595 }
596
597 /* Copy the page to an aligned buffer */
598 if (copy_from_user(played_buf.addr +(HARMONY_BUF_SIZE*buf_to_fill) + harmony.play_offset,
599 buffer+count, frame_size))
600 return -EFAULT;
601 CHECK_WBACK_INV_OFFSET(played_buf, (HARMONY_BUF_SIZE*buf_to_fill + harmony.play_offset),
602 frame_size);
603
604 if (fresh_buffer)
605 harmony.nb_filled_play++;
606
607 count += frame_size;
608 harmony.play_offset += frame_size;
609 harmony.play_offset %= HARMONY_BUF_SIZE;
610 if (harmony.suspended_playing && (harmony.nb_filled_play>=4))
611 harmony_enable_interrupts();
612 }
613
614 return count;
615}
616
617static unsigned int harmony_audio_poll(struct file *file,
618 struct poll_table_struct *wait)
619{
620 unsigned int mask = 0;
621
622 if (file->f_mode & FMODE_READ) {
623 if (!harmony.suspended_recording)
624 poll_wait(file, &harmony.wq_record, wait);
625 if (harmony.nb_filled_record)
626 mask |= POLLIN | POLLRDNORM;
627 }
628
629 if (file->f_mode & FMODE_WRITE) {
630 if (!harmony.suspended_playing)
631 poll_wait(file, &harmony.wq_play, wait);
632 if (harmony.nb_filled_play)
633 mask |= POLLOUT | POLLWRNORM;
634 }
635
636 return mask;
637}
638
639static int harmony_audio_ioctl(struct inode *inode,
640 struct file *file,
641 unsigned int cmd,
642 unsigned long arg)
643{
644 int ival, new_format;
645 int frag_size, frag_buf;
646 struct audio_buf_info info;
647
648 switch (cmd) {
649 case OSS_GETVERSION:
650 return put_user(SOUND_VERSION, (int *) arg);
651
652 case SNDCTL_DSP_GETCAPS:
653 ival = DSP_CAP_DUPLEX;
654 return put_user(ival, (int *) arg);
655
656 case SNDCTL_DSP_GETFMTS:
657 ival = (AFMT_S16_BE | AFMT_MU_LAW | AFMT_A_LAW );
658 return put_user(ival, (int *) arg);
659
660 case SNDCTL_DSP_SETFMT:
661 if (get_user(ival, (int *) arg))
662 return -EFAULT;
663 if (ival != AFMT_QUERY) {
664 switch (ival) {
665 case AFMT_MU_LAW: new_format = HARMONY_DF_8BIT_ULAW; break;
666 case AFMT_A_LAW: new_format = HARMONY_DF_8BIT_ALAW; break;
667 case AFMT_S16_BE: new_format = HARMONY_DF_16BIT_LINEAR; break;
668 default: {
669 DPRINTK(KERN_WARNING PFX
670 "unsupported sound format 0x%04x requested.\n",
671 ival);
672 ival = AFMT_S16_BE;
673 return put_user(ival, (int *) arg);
674 }
675 }
676 harmony_set_format(new_format);
677 return 0;
678 } else {
679 switch (harmony.data_format) {
680 case HARMONY_DF_8BIT_ULAW: ival = AFMT_MU_LAW; break;
681 case HARMONY_DF_8BIT_ALAW: ival = AFMT_A_LAW; break;
682 case HARMONY_DF_16BIT_LINEAR: ival = AFMT_U16_BE; break;
683 default: ival = 0;
684 }
685 return put_user(ival, (int *) arg);
686 }
687
688 case SOUND_PCM_READ_RATE:
689 ival = harmony.dac_rate;
690 return put_user(ival, (int *) arg);
691
692 case SNDCTL_DSP_SPEED:
693 if (get_user(ival, (int *) arg))
694 return -EFAULT;
695 harmony_set_rate(harmony_detect_rate(&ival));
696 harmony.dac_rate = ival;
697 return put_user(ival, (int*) arg);
698
699 case SNDCTL_DSP_STEREO:
700 if (get_user(ival, (int *) arg))
701 return -EFAULT;
702 if (ival != 0 && ival != 1)
703 return -EINVAL;
704 harmony_set_stereo(ival);
705 return 0;
706
707 case SNDCTL_DSP_CHANNELS:
708 if (get_user(ival, (int *) arg))
709 return -EFAULT;
710 if (ival != 1 && ival != 2) {
711 ival = harmony.stereo_select == HARMONY_SS_MONO ? 1 : 2;
712 return put_user(ival, (int *) arg);
713 }
714 harmony_set_stereo(ival-1);
715 return 0;
716
717 case SNDCTL_DSP_GETBLKSIZE:
718 ival = HARMONY_BUF_SIZE;
719 return put_user(ival, (int *) arg);
720
721 case SNDCTL_DSP_NONBLOCK:
722 file->f_flags |= O_NONBLOCK;
723 return 0;
724
725 case SNDCTL_DSP_RESET:
726 if (!harmony.suspended_recording) {
727 /* TODO: stop_recording() */
728 }
729 return 0;
730
731 case SNDCTL_DSP_SETFRAGMENT:
732 if (get_user(ival, (int *)arg))
733 return -EFAULT;
734 frag_size = ival & 0xffff;
735 frag_buf = (ival>>16) & 0xffff;
736 /* TODO: We use hardcoded fragment sizes and numbers for now */
737 frag_size = 12; /* 4096 == 2^12 */
738 frag_buf = MAX_BUFS;
739 ival = (frag_buf << 16) + frag_size;
740 return put_user(ival, (int *) arg);
741
742 case SNDCTL_DSP_GETOSPACE:
743 if (!(file->f_mode & FMODE_WRITE))
744 return -EINVAL;
745 info.fragstotal = MAX_BUFS;
746 info.fragments = MAX_BUFS - harmony.nb_filled_play;
747 info.fragsize = HARMONY_BUF_SIZE;
748 info.bytes = info.fragments * info.fragsize;
749 return copy_to_user((void *)arg, &info, sizeof(info)) ? -EFAULT : 0;
750
751 case SNDCTL_DSP_GETISPACE:
752 if (!(file->f_mode & FMODE_READ))
753 return -EINVAL;
754 info.fragstotal = MAX_BUFS;
755 info.fragments = /*MAX_BUFS-*/ harmony.nb_filled_record;
756 info.fragsize = HARMONY_BUF_SIZE;
757 info.bytes = info.fragments * info.fragsize;
758 return copy_to_user((void *)arg, &info, sizeof(info)) ? -EFAULT : 0;
759
760 case SNDCTL_DSP_SYNC:
761 return 0;
762 }
763
764 return -EINVAL;
765}
766
767
768/*
769 * harmony_interrupt()
770 *
771 * harmony interruption service routine
772 *
773 */
774
775static irqreturn_t harmony_interrupt(int irq, void *dev, struct pt_regs *regs)
776{
777 u32 dstatus;
778 struct harmony_hpa *hpa;
779
780 /* Setup the hpa */
781 hpa = ((struct harmony_dev *)dev)->hpa;
782 harmony_wait_CNTL();
783
784 /* Read dstatus and pcuradd (the current address) */
785 dstatus = gsc_readl(&hpa->dstatus);
786
787 /* Turn off interrupts */
788 harmony_disable_interrupts();
789
790 /* Check if this is a request to get the next play buffer */
791 if (dstatus & DSTATUS_PN) {
792 if (!harmony.nb_filled_play) {
793 harmony.suspended_playing = 1;
794 gsc_writel((unsigned long)silent.dma_handle, &hpa->pnxtadd);
795
796 if (!harmony.suspended_recording)
797 harmony_enable_interrupts();
798 } else {
799 harmony.suspended_playing = 0;
800 gsc_writel((unsigned long)played_buf.dma_handle +
801 (HARMONY_BUF_SIZE*harmony.first_filled_play),
802 &hpa->pnxtadd);
803 harmony.first_filled_play++;
804 harmony.first_filled_play %= MAX_BUFS;
805 harmony.nb_filled_play--;
806
807 harmony_enable_interrupts();
808 }
809
810 if (harmony.blocked_playing)
811 wake_up_interruptible(&harmony.wq_play);
812 }
813
814 /* Check if we're being asked to fill in a recording buffer */
815 if (dstatus & DSTATUS_RN) {
816 if((harmony.nb_filled_record+2>=MAX_BUFS) || harmony.suspended_recording)
817 {
818 harmony.nb_filled_record = 0;
819 harmony.first_filled_record = 0;
820 harmony.suspended_recording = 1;
821 gsc_writel((unsigned long)graveyard.dma_handle, &hpa->rnxtadd);
822 if (!harmony.suspended_playing)
823 harmony_enable_interrupts();
824 } else {
825 int buf_to_fill;
826 buf_to_fill = (harmony.first_filled_record+harmony.nb_filled_record) % MAX_BUFS;
827 CHECK_WBACK_INV_OFFSET(recorded_buf, HARMONY_BUF_SIZE*buf_to_fill, HARMONY_BUF_SIZE);
828 gsc_writel((unsigned long)recorded_buf.dma_handle +
829 HARMONY_BUF_SIZE*buf_to_fill,
830 &hpa->rnxtadd);
831 harmony.nb_filled_record++;
832 harmony_enable_interrupts();
833 }
834
835 if (harmony.blocked_recording && harmony.nb_filled_record>3)
836 wake_up_interruptible(&harmony.wq_record);
837 }
838 return IRQ_HANDLED;
839}
840
841/*
842 * Sound playing functions
843 */
844
845static struct file_operations harmony_audio_fops = {
846 .owner = THIS_MODULE,
847 .llseek = no_llseek,
848 .read = harmony_audio_read,
849 .write = harmony_audio_write,
850 .poll = harmony_audio_poll,
851 .ioctl = harmony_audio_ioctl,
852 .open = harmony_audio_open,
853 .release = harmony_audio_release,
854};
855
856static int harmony_audio_init(void)
857{
858 /* Request that IRQ */
859 if (request_irq(harmony.dev->irq, harmony_interrupt, 0 ,"harmony", &harmony)) {
860 printk(KERN_ERR PFX "Error requesting irq %d.\n", harmony.dev->irq);
861 return -EFAULT;
862 }
863
864 harmony.dsp_unit = register_sound_dsp(&harmony_audio_fops, -1);
865 if (harmony.dsp_unit < 0) {
866 printk(KERN_ERR PFX "Error registering dsp\n");
867 free_irq(harmony.dev->irq, &harmony);
868 return -EFAULT;
869 }
870
871 /* Clear the buffers so you don't end up with crap in the buffers. */
872 harmony_silence(&played_buf, 0, HARMONY_BUF_SIZE*MAX_BUFS);
873
874 /* Make sure this makes it to cache */
875 CHECK_WBACK_INV_OFFSET(played_buf, 0, HARMONY_BUF_SIZE*MAX_BUFS);
876
877 /* Clear out the silent buffer and flush to cache */
878 harmony_silence(&silent, 0, HARMONY_BUF_SIZE);
879 CHECK_WBACK_INV_OFFSET(silent, 0, HARMONY_BUF_SIZE);
880
881 harmony.audio_open = 0;
882
883 return 0;
884}
885
886
887/*
888 * mixer functions
889 */
890
891static void harmony_mixer_set_gain(void)
892{
893 harmony_wait_CNTL();
894 gsc_writel(harmony.current_gain, &harmony.hpa->gainctl);
895}
896
897/*
898 * Read gain of selected channel.
899 * The OSS rate is from 0 (silent) to 100 -> need some conversions
900 *
901 * The harmony gain are attenuation for output and monitor gain.
902 * is amplifaction for input gain
903 */
904#define to_harmony_level(level,max) ((level)*max/100)
905#define to_oss_level(level,max) ((level)*100/max)
906
907static int harmony_mixer_get_level(int channel)
908{
909 int left_level;
910 int right_level;
911
912 switch (channel) {
913 case SOUND_MIXER_VOLUME:
914 left_level = (harmony.current_gain & GAIN_LO_MASK) >> GAIN_LO_SHIFT;
915 right_level = (harmony.current_gain & GAIN_RO_MASK) >> GAIN_RO_SHIFT;
916 left_level = to_oss_level(MAX_OUTPUT_LEVEL - left_level, MAX_OUTPUT_LEVEL);
917 right_level = to_oss_level(MAX_OUTPUT_LEVEL - right_level, MAX_OUTPUT_LEVEL);
918 return (right_level << 8)+left_level;
919
920 case SOUND_MIXER_IGAIN:
921 left_level = (harmony.current_gain & GAIN_LI_MASK) >> GAIN_LI_SHIFT;
922 right_level= (harmony.current_gain & GAIN_RI_MASK) >> GAIN_RI_SHIFT;
923 left_level = to_oss_level(left_level, MAX_INPUT_LEVEL);
924 right_level= to_oss_level(right_level, MAX_INPUT_LEVEL);
925 return (right_level << 8)+left_level;
926
927 case SOUND_MIXER_MONITOR:
928 left_level = (harmony.current_gain & GAIN_MA_MASK) >> GAIN_MA_SHIFT;
929 left_level = to_oss_level(MAX_MONITOR_LEVEL-left_level, MAX_MONITOR_LEVEL);
930 return (left_level << 8)+left_level;
931 }
932 return -EINVAL;
933}
934
935
936
937/*
938 * Some conversions for the same reasons.
939 * We give back the new real value(s) due to
940 * the rescale.
941 */
942
943static int harmony_mixer_set_level(int channel, int value)
944{
945 int left_level;
946 int right_level;
947 int new_left_level;
948 int new_right_level;
949
950 right_level = (value & 0x0000ff00) >> 8;
951 left_level = value & 0x000000ff;
952 if (right_level > 100) right_level = 100;
953 if (left_level > 100) left_level = 100;
954
955 switch (channel) {
956 case SOUND_MIXER_VOLUME:
957 right_level = to_harmony_level(100-right_level, MAX_OUTPUT_LEVEL);
958 left_level = to_harmony_level(100-left_level, MAX_OUTPUT_LEVEL);
959 new_right_level = to_oss_level(MAX_OUTPUT_LEVEL - right_level, MAX_OUTPUT_LEVEL);
960 new_left_level = to_oss_level(MAX_OUTPUT_LEVEL - left_level, MAX_OUTPUT_LEVEL);
961 harmony.current_gain = (harmony.current_gain & ~(GAIN_LO_MASK | GAIN_RO_MASK))
962 | (left_level << GAIN_LO_SHIFT) | (right_level << GAIN_RO_SHIFT);
963 harmony_mixer_set_gain();
964 return (new_right_level << 8) + new_left_level;
965
966 case SOUND_MIXER_IGAIN:
967 right_level = to_harmony_level(right_level, MAX_INPUT_LEVEL);
968 left_level = to_harmony_level(left_level, MAX_INPUT_LEVEL);
969 new_right_level = to_oss_level(right_level, MAX_INPUT_LEVEL);
970 new_left_level = to_oss_level(left_level, MAX_INPUT_LEVEL);
971 harmony.current_gain = (harmony.current_gain & ~(GAIN_LI_MASK | GAIN_RI_MASK))
972 | (left_level << GAIN_LI_SHIFT) | (right_level << GAIN_RI_SHIFT);
973 harmony_mixer_set_gain();
974 return (new_right_level << 8) + new_left_level;
975
976 case SOUND_MIXER_MONITOR:
977 left_level = to_harmony_level(100-left_level, MAX_MONITOR_LEVEL);
978 new_left_level = to_oss_level(MAX_MONITOR_LEVEL-left_level, MAX_MONITOR_LEVEL);
979 harmony.current_gain = (harmony.current_gain & ~GAIN_MA_MASK) | (left_level << GAIN_MA_SHIFT);
980 harmony_mixer_set_gain();
981 return (new_left_level << 8) + new_left_level;
982 }
983
984 return -EINVAL;
985}
986
987#undef to_harmony_level
988#undef to_oss_level
989
990/*
991 * Return the selected input device (mic or line)
992 */
993
994static int harmony_mixer_get_recmask(void)
995{
996 int current_input_line;
997
998 current_input_line = (harmony.current_gain & GAIN_IS_MASK)
999 >> GAIN_IS_SHIFT;
1000 if (current_input_line)
1001 return SOUND_MASK_MIC;
1002
1003 return SOUND_MASK_LINE;
1004}
1005
1006/*
1007 * Set the input (only one at time, arbitrary priority to line in)
1008 */
1009
1010static int harmony_mixer_set_recmask(int recmask)
1011{
1012 int new_input_line;
1013 int new_input_mask;
1014 int current_input_line;
1015
1016 current_input_line = (harmony.current_gain & GAIN_IS_MASK)
1017 >> GAIN_IS_SHIFT;
1018 if ((current_input_line && ((recmask & SOUND_MASK_LINE) || !(recmask & SOUND_MASK_MIC))) ||
1019 (!current_input_line && ((recmask & SOUND_MASK_LINE) && !(recmask & SOUND_MASK_MIC)))) {
1020 new_input_line = 0;
1021 new_input_mask = SOUND_MASK_LINE;
1022 } else {
1023 new_input_line = 1;
1024 new_input_mask = SOUND_MASK_MIC;
1025 }
1026 harmony.current_gain = ((harmony.current_gain & ~GAIN_IS_MASK) |
1027 (new_input_line << GAIN_IS_SHIFT ));
1028 harmony_mixer_set_gain();
1029 return new_input_mask;
1030}
1031
1032
1033/*
1034 * give the active outlines
1035 */
1036
1037static int harmony_mixer_get_outmask(void)
1038{
1039 int outmask = 0;
1040
1041 if (harmony.current_gain & GAIN_SE_MASK) outmask |= MASK_INTERNAL;
1042 if (harmony.current_gain & GAIN_LE_MASK) outmask |= MASK_LINEOUT;
1043 if (harmony.current_gain & GAIN_HE_MASK) outmask |= MASK_HEADPHONES;
1044
1045 return outmask;
1046}
1047
1048
1049static int harmony_mixer_set_outmask(int outmask)
1050{
1051 if (outmask & MASK_INTERNAL)
1052 harmony.current_gain |= GAIN_SE_MASK;
1053 else
1054 harmony.current_gain &= ~GAIN_SE_MASK;
1055
1056 if (outmask & MASK_LINEOUT)
1057 harmony.current_gain |= GAIN_LE_MASK;
1058 else
1059 harmony.current_gain &= ~GAIN_LE_MASK;
1060
1061 if (outmask & MASK_HEADPHONES)
1062 harmony.current_gain |= GAIN_HE_MASK;
1063 else
1064 harmony.current_gain &= ~GAIN_HE_MASK;
1065
1066 harmony_mixer_set_gain();
1067
1068 return (outmask & (MASK_INTERNAL | MASK_LINEOUT | MASK_HEADPHONES));
1069}
1070
1071/*
1072 * This code is inspired from sb_mixer.c
1073 */
1074
1075static int harmony_mixer_ioctl(struct inode * inode, struct file * file,
1076 unsigned int cmd, unsigned long arg)
1077{
1078 int val;
1079 int ret;
1080
1081 if (cmd == SOUND_MIXER_INFO) {
1082 mixer_info info;
1083 memset(&info, 0, sizeof(info));
1084 strncpy(info.id, "harmony", sizeof(info.id)-1);
1085 strncpy(info.name, "Harmony audio", sizeof(info.name)-1);
1086 info.modify_counter = 1; /* ? */
1087 if (copy_to_user((void *)arg, &info, sizeof(info)))
1088 return -EFAULT;
1089 return 0;
1090 }
1091
1092 if (cmd == OSS_GETVERSION)
1093 return put_user(SOUND_VERSION, (int *)arg);
1094
1095 /* read */
1096 val = 0;
1097 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
1098 if (get_user(val, (int *)arg))
1099 return -EFAULT;
1100
1101 switch (cmd) {
1102 case MIXER_READ(SOUND_MIXER_CAPS):
1103 ret = SOUND_CAP_EXCL_INPUT;
1104 break;
1105 case MIXER_READ(SOUND_MIXER_STEREODEVS):
1106 ret = SOUND_MASK_VOLUME | SOUND_MASK_IGAIN;
1107 break;
1108
1109 case MIXER_READ(SOUND_MIXER_RECMASK):
1110 ret = SOUND_MASK_MIC | SOUND_MASK_LINE;
1111 break;
1112 case MIXER_READ(SOUND_MIXER_DEVMASK):
1113 ret = SOUND_MASK_VOLUME | SOUND_MASK_IGAIN |
1114 SOUND_MASK_MONITOR;
1115 break;
1116 case MIXER_READ(SOUND_MIXER_OUTMASK):
1117 ret = MASK_INTERNAL | MASK_LINEOUT |
1118 MASK_HEADPHONES;
1119 break;
1120
1121 case MIXER_WRITE(SOUND_MIXER_RECSRC):
1122 ret = harmony_mixer_set_recmask(val);
1123 break;
1124 case MIXER_READ(SOUND_MIXER_RECSRC):
1125 ret = harmony_mixer_get_recmask();
1126 break;
1127
1128 case MIXER_WRITE(SOUND_MIXER_OUTSRC):
1129 ret = harmony_mixer_set_outmask(val);
1130 break;
1131 case MIXER_READ(SOUND_MIXER_OUTSRC):
1132 ret = harmony_mixer_get_outmask();
1133 break;
1134
1135 case MIXER_WRITE(SOUND_MIXER_VOLUME):
1136 case MIXER_WRITE(SOUND_MIXER_IGAIN):
1137 case MIXER_WRITE(SOUND_MIXER_MONITOR):
1138 ret = harmony_mixer_set_level(cmd & 0xff, val);
1139 break;
1140
1141 case MIXER_READ(SOUND_MIXER_VOLUME):
1142 case MIXER_READ(SOUND_MIXER_IGAIN):
1143 case MIXER_READ(SOUND_MIXER_MONITOR):
1144 ret = harmony_mixer_get_level(cmd & 0xff);
1145 break;
1146
1147 default:
1148 return -EINVAL;
1149 }
1150
1151 if (put_user(ret, (int *)arg))
1152 return -EFAULT;
1153 return 0;
1154}
1155
1156
1157static int harmony_mixer_open(struct inode *inode, struct file *file)
1158{
1159 if (harmony.mixer_open)
1160 return -EBUSY;
1161 harmony.mixer_open = 1;
1162 return 0;
1163}
1164
1165static int harmony_mixer_release(struct inode *inode, struct file *file)
1166{
1167 if (!harmony.mixer_open)
1168 return -EBUSY;
1169 harmony.mixer_open = 0;
1170 return 0;
1171}
1172
1173static struct file_operations harmony_mixer_fops = {
1174 .owner = THIS_MODULE,
1175 .llseek = no_llseek,
1176 .open = harmony_mixer_open,
1177 .release = harmony_mixer_release,
1178 .ioctl = harmony_mixer_ioctl,
1179};
1180
1181
1182/*
1183 * Mute all the output and reset Harmony.
1184 */
1185
1186static void __init harmony_mixer_reset(void)
1187{
1188 harmony.current_gain = GAIN_TOTAL_SILENCE;
1189 harmony_mixer_set_gain();
1190 harmony_wait_CNTL();
1191 gsc_writel(1, &harmony.hpa->reset);
1192 mdelay(50); /* wait 50 ms */
1193 gsc_writel(0, &harmony.hpa->reset);
1194 harmony.current_gain = GAIN_DEFAULT;
1195 harmony_mixer_set_gain();
1196}
1197
1198static int __init harmony_mixer_init(void)
1199{
1200 /* Register the device file operations */
1201 harmony.mixer_unit = register_sound_mixer(&harmony_mixer_fops, -1);
1202 if (harmony.mixer_unit < 0) {
1203 printk(KERN_WARNING PFX "Error Registering Mixer Driver\n");
1204 return -EFAULT;
1205 }
1206
1207 harmony_mixer_reset();
1208 harmony.mixer_open = 0;
1209
1210 return 0;
1211}
1212
1213
1214
1215/*
1216 * This is the callback that's called by the inventory hardware code
1217 * if it finds a match to the registered driver.
1218 */
1219static int __devinit
1220harmony_driver_probe(struct parisc_device *dev)
1221{
1222 u8 id;
1223 u8 rev;
1224 u32 cntl;
1225 int ret;
1226
1227 if (harmony.hpa) {
1228 /* We only support one Harmony at this time */
1229 printk(KERN_ERR PFX "driver already registered\n");
1230 return -EBUSY;
1231 }
1232
1233 if (!dev->irq) {
1234 printk(KERN_ERR PFX "no irq found\n");
1235 return -ENODEV;
1236 }
1237
1238 /* Set the HPA of harmony */
1239 harmony.hpa = (struct harmony_hpa *)dev->hpa;
1240 harmony.dev = dev;
1241
1242 /* Grab the ID and revision from the device */
1243 id = gsc_readb(&harmony.hpa->id);
1244 if ((id | 1) != 0x15) {
1245 printk(KERN_WARNING PFX "wrong harmony id 0x%02x\n", id);
1246 return -EBUSY;
1247 }
1248 cntl = gsc_readl(&harmony.hpa->cntl);
1249 rev = (cntl>>20) & 0xff;
1250
1251 printk(KERN_INFO "Lasi Harmony Audio driver " HARMONY_VERSION ", "
1252 "h/w id %i, rev. %i at 0x%lx, IRQ %i\n",
1253 id, rev, dev->hpa, harmony.dev->irq);
1254
1255 /* Make sure the control bit isn't set, although I don't think it
1256 ever is. */
1257 if (cntl & CNTL_C) {
1258 printk(KERN_WARNING PFX "CNTL busy\n");
1259 harmony.hpa = 0;
1260 return -EBUSY;
1261 }
1262
1263 /* Initialize the memory buffers */
1264 if (harmony_alloc_buffer(&played_buf, MAX_BUFS) ||
1265 harmony_alloc_buffer(&recorded_buf, MAX_BUFS) ||
1266 harmony_alloc_buffer(&graveyard, 1) ||
1267 harmony_alloc_buffer(&silent, 1)) {
1268 ret = -EBUSY;
1269 goto out_err;
1270 }
1271
1272 /* Initialize /dev/mixer and /dev/audio */
1273 if ((ret=harmony_mixer_init()))
1274 goto out_err;
1275 if ((ret=harmony_audio_init()))
1276 goto out_err;
1277
1278 return 0;
1279
1280out_err:
1281 harmony.hpa = 0;
1282 harmony_free_buffer(&played_buf);
1283 harmony_free_buffer(&recorded_buf);
1284 harmony_free_buffer(&graveyard);
1285 harmony_free_buffer(&silent);
1286 return ret;
1287}
1288
1289
1290static struct parisc_device_id harmony_tbl[] = {
1291 /* { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007A }, Bushmaster/Flounder */
1292 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007B }, /* 712/715 Audio */
1293 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007E }, /* Pace Audio */
1294 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0007F }, /* Outfield / Coral II */
1295 { 0, }
1296};
1297
1298MODULE_DEVICE_TABLE(parisc, harmony_tbl);
1299
1300static struct parisc_driver harmony_driver = {
1301 .name = "Lasi Harmony",
1302 .id_table = harmony_tbl,
1303 .probe = harmony_driver_probe,
1304};
1305
1306static int __init init_harmony(void)
1307{
1308 return register_parisc_driver(&harmony_driver);
1309}
1310
1311static void __exit cleanup_harmony(void)
1312{
1313 free_irq(harmony.dev->irq, &harmony);
1314 unregister_sound_mixer(harmony.mixer_unit);
1315 unregister_sound_dsp(harmony.dsp_unit);
1316 harmony_free_buffer(&played_buf);
1317 harmony_free_buffer(&recorded_buf);
1318 harmony_free_buffer(&graveyard);
1319 harmony_free_buffer(&silent);
1320 unregister_parisc_driver(&harmony_driver);
1321}
1322
1323
1324MODULE_AUTHOR("Alex DeVries <alex@onefishtwo.ca>");
1325MODULE_DESCRIPTION("Harmony sound driver");
1326MODULE_LICENSE("GPL");
1327
1328module_init(init_harmony);
1329module_exit(cleanup_harmony);
1330
diff --git a/sound/oss/hex2hex.c b/sound/oss/hex2hex.c
new file mode 100644
index 000000000000..5460faae98c9
--- /dev/null
+++ b/sound/oss/hex2hex.c
@@ -0,0 +1,101 @@
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
15int 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/i810_audio.c b/sound/oss/i810_audio.c
new file mode 100644
index 000000000000..7e9f667cf7a7
--- /dev/null
+++ b/sound/oss/i810_audio.c
@@ -0,0 +1,3658 @@
1/*
2 * Intel i810 and friends ICH driver for Linux
3 * Alan Cox <alan@redhat.com>
4 *
5 * Built from:
6 * Low level code: Zach Brown (original nonworking i810 OSS driver)
7 * Jaroslav Kysela <perex@suse.cz> (working ALSA driver)
8 *
9 * Framework: Thomas Sailer <sailer@ife.ee.ethz.ch>
10 * Extended by: Zach Brown <zab@redhat.com>
11 * and others..
12 *
13 * Hardware Provided By:
14 * Analog Devices (A major AC97 codec maker)
15 * Intel Corp (you've probably heard of them already)
16 *
17 * AC97 clues and assistance provided by
18 * Analog Devices
19 * Zach 'Fufu' Brown
20 * Jeff Garzik
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *
36 *
37 * Intel 810 theory of operation
38 *
39 * The chipset provides three DMA channels that talk to an AC97
40 * CODEC (AC97 is a digital/analog mixer standard). At its simplest
41 * you get 48Khz audio with basic volume and mixer controls. At the
42 * best you get rate adaption in the codec. We set the card up so
43 * that we never take completion interrupts but instead keep the card
44 * chasing its tail around a ring buffer. This is needed for mmap
45 * mode audio and happens to work rather well for non-mmap modes too.
46 *
47 * The board has one output channel for PCM audio (supported) and
48 * a stereo line in and mono microphone input. Again these are normally
49 * locked to 48Khz only. Right now recording is not finished.
50 *
51 * There is no midi support, no synth support. Use timidity. To get
52 * esd working you need to use esd -r 48000 as it won't probe 48KHz
53 * by default. mpg123 can't handle 48Khz only audio so use xmms.
54 *
55 * Fix The Sound On Dell
56 *
57 * Not everyone uses 48KHz. We know of no way to detect this reliably
58 * and certainly not to get the right data. If your i810 audio sounds
59 * stupid you may need to investigate other speeds. According to Analog
60 * they tend to use a 14.318MHz clock which gives you a base rate of
61 * 41194Hz.
62 *
63 * This is available via the 'ftsodell=1' option.
64 *
65 * If you need to force a specific rate set the clocking= option
66 *
67 * This driver is cursed. (Ben LaHaise)
68 *
69 * ICH 3 caveats
70 * Intel errata #7 for ICH3 IO. We need to disable SMI stuff
71 * when codec probing. [Not Yet Done]
72 *
73 * ICH 4 caveats
74 *
75 * The ICH4 has the feature, that the codec ID doesn't have to be
76 * congruent with the IO connection.
77 *
78 * Therefore, from driver version 0.23 on, there is a "codec ID" <->
79 * "IO register base offset" mapping (card->ac97_id_map) field.
80 *
81 * Juergen "George" Sawinski (jsaw)
82 */
83
84#include <linux/module.h>
85#include <linux/string.h>
86#include <linux/ctype.h>
87#include <linux/ioport.h>
88#include <linux/sched.h>
89#include <linux/delay.h>
90#include <linux/sound.h>
91#include <linux/slab.h>
92#include <linux/soundcard.h>
93#include <linux/pci.h>
94#include <linux/interrupt.h>
95#include <asm/io.h>
96#include <asm/dma.h>
97#include <linux/init.h>
98#include <linux/poll.h>
99#include <linux/spinlock.h>
100#include <linux/smp_lock.h>
101#include <linux/ac97_codec.h>
102#include <linux/bitops.h>
103#include <asm/uaccess.h>
104
105#define DRIVER_VERSION "1.01"
106
107#define MODULOP2(a, b) ((a) & ((b) - 1))
108#define MASKP2(a, b) ((a) & ~((b) - 1))
109
110static int ftsodell;
111static int strict_clocking;
112static unsigned int clocking;
113static int spdif_locked;
114static int ac97_quirk = AC97_TUNE_DEFAULT;
115
116//#define DEBUG
117//#define DEBUG2
118//#define DEBUG_INTERRUPTS
119//#define DEBUG_MMAP
120//#define DEBUG_MMIO
121
122#define ADC_RUNNING 1
123#define DAC_RUNNING 2
124
125#define I810_FMT_16BIT 1
126#define I810_FMT_STEREO 2
127#define I810_FMT_MASK 3
128
129#define SPDIF_ON 0x0004
130#define SURR_ON 0x0010
131#define CENTER_LFE_ON 0x0020
132#define VOL_MUTED 0x8000
133
134/* the 810's array of pointers to data buffers */
135
136struct sg_item {
137#define BUSADDR_MASK 0xFFFFFFFE
138 u32 busaddr;
139#define CON_IOC 0x80000000 /* interrupt on completion */
140#define CON_BUFPAD 0x40000000 /* pad underrun with last sample, else 0 */
141#define CON_BUFLEN_MASK 0x0000ffff /* buffer length in samples */
142 u32 control;
143};
144
145/* an instance of the i810 channel */
146#define SG_LEN 32
147struct i810_channel
148{
149 /* these sg guys should probably be allocated
150 separately as nocache. Must be 8 byte aligned */
151 struct sg_item sg[SG_LEN]; /* 32*8 */
152 u32 offset; /* 4 */
153 u32 port; /* 4 */
154 u32 used;
155 u32 num;
156};
157
158/*
159 * we have 3 separate dma engines. pcm in, pcm out, and mic.
160 * each dma engine has controlling registers. These goofy
161 * names are from the datasheet, but make it easy to write
162 * code while leafing through it.
163 *
164 * ICH4 has 6 dma engines, pcm in, pcm out, mic, pcm in 2,
165 * mic in 2, s/pdif. Of special interest is the fact that
166 * the upper 3 DMA engines on the ICH4 *must* be accessed
167 * via mmio access instead of pio access.
168 */
169
170#define ENUM_ENGINE(PRE,DIG) \
171enum { \
172 PRE##_BASE = 0x##DIG##0, /* Base Address */ \
173 PRE##_BDBAR = 0x##DIG##0, /* Buffer Descriptor list Base Address */ \
174 PRE##_CIV = 0x##DIG##4, /* Current Index Value */ \
175 PRE##_LVI = 0x##DIG##5, /* Last Valid Index */ \
176 PRE##_SR = 0x##DIG##6, /* Status Register */ \
177 PRE##_PICB = 0x##DIG##8, /* Position In Current Buffer */ \
178 PRE##_PIV = 0x##DIG##a, /* Prefetched Index Value */ \
179 PRE##_CR = 0x##DIG##b /* Control Register */ \
180}
181
182ENUM_ENGINE(OFF,0); /* Offsets */
183ENUM_ENGINE(PI,0); /* PCM In */
184ENUM_ENGINE(PO,1); /* PCM Out */
185ENUM_ENGINE(MC,2); /* Mic In */
186
187enum {
188 GLOB_CNT = 0x2c, /* Global Control */
189 GLOB_STA = 0x30, /* Global Status */
190 CAS = 0x34 /* Codec Write Semaphore Register */
191};
192
193ENUM_ENGINE(MC2,4); /* Mic In 2 */
194ENUM_ENGINE(PI2,5); /* PCM In 2 */
195ENUM_ENGINE(SP,6); /* S/PDIF */
196
197enum {
198 SDM = 0x80 /* SDATA_IN Map Register */
199};
200
201/* interrupts for a dma engine */
202#define DMA_INT_FIFO (1<<4) /* fifo under/over flow */
203#define DMA_INT_COMPLETE (1<<3) /* buffer read/write complete and ioc set */
204#define DMA_INT_LVI (1<<2) /* last valid done */
205#define DMA_INT_CELV (1<<1) /* last valid is current */
206#define DMA_INT_DCH (1) /* DMA Controller Halted (happens on LVI interrupts) */
207#define DMA_INT_MASK (DMA_INT_FIFO|DMA_INT_COMPLETE|DMA_INT_LVI)
208
209/* interrupts for the whole chip */
210#define INT_SEC (1<<11)
211#define INT_PRI (1<<10)
212#define INT_MC (1<<7)
213#define INT_PO (1<<6)
214#define INT_PI (1<<5)
215#define INT_MO (1<<2)
216#define INT_NI (1<<1)
217#define INT_GPI (1<<0)
218#define INT_MASK (INT_SEC|INT_PRI|INT_MC|INT_PO|INT_PI|INT_MO|INT_NI|INT_GPI)
219
220/* magic numbers to protect our data structures */
221#define I810_CARD_MAGIC 0x5072696E /* "Prin" */
222#define I810_STATE_MAGIC 0x63657373 /* "cess" */
223#define I810_DMA_MASK 0xffffffff /* DMA buffer mask for pci_alloc_consist */
224#define NR_HW_CH 3
225
226/* maxinum number of AC97 codecs connected, AC97 2.0 defined 4 */
227#define NR_AC97 4
228
229/* Please note that an 8bit mono stream is not valid on this card, you must have a 16bit */
230/* stream at a minimum for this card to be happy */
231static const unsigned sample_size[] = { 1, 2, 2, 4 };
232/* Samples are 16bit values, so we are shifting to a word, not to a byte, hence shift */
233/* values are one less than might be expected */
234static const unsigned sample_shift[] = { -1, 0, 0, 1 };
235
236enum {
237 ICH82801AA = 0,
238 ICH82901AB,
239 INTEL440MX,
240 INTELICH2,
241 INTELICH3,
242 INTELICH4,
243 INTELICH5,
244 SI7012,
245 NVIDIA_NFORCE,
246 AMD768,
247 AMD8111
248};
249
250static char * card_names[] = {
251 "Intel ICH 82801AA",
252 "Intel ICH 82901AB",
253 "Intel 440MX",
254 "Intel ICH2",
255 "Intel ICH3",
256 "Intel ICH4",
257 "Intel ICH5",
258 "SiS 7012",
259 "NVIDIA nForce Audio",
260 "AMD 768",
261 "AMD-8111 IOHub"
262};
263
264/* These are capabilities (and bugs) the chipsets _can_ have */
265static struct {
266 int16_t nr_ac97;
267#define CAP_MMIO 0x0001
268#define CAP_20BIT_AUDIO_SUPPORT 0x0002
269 u_int16_t flags;
270} card_cap[] = {
271 { 1, 0x0000 }, /* ICH82801AA */
272 { 1, 0x0000 }, /* ICH82901AB */
273 { 1, 0x0000 }, /* INTEL440MX */
274 { 1, 0x0000 }, /* INTELICH2 */
275 { 2, 0x0000 }, /* INTELICH3 */
276 { 3, 0x0003 }, /* INTELICH4 */
277 { 3, 0x0003 }, /* INTELICH5 */
278 /*@FIXME to be verified*/ { 2, 0x0000 }, /* SI7012 */
279 /*@FIXME to be verified*/ { 2, 0x0000 }, /* NVIDIA_NFORCE */
280 /*@FIXME to be verified*/ { 2, 0x0000 }, /* AMD768 */
281 /*@FIXME to be verified*/ { 3, 0x0001 }, /* AMD8111 */
282};
283
284static struct pci_device_id i810_pci_tbl [] = {
285 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_5,
286 PCI_ANY_ID, PCI_ANY_ID, 0, 0, ICH82801AA},
287 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_5,
288 PCI_ANY_ID, PCI_ANY_ID, 0, 0, ICH82901AB},
289 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_440MX,
290 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTEL440MX},
291 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_4,
292 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH2},
293 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_5,
294 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH3},
295 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_5,
296 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
297 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_5,
298 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH5},
299 {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7012,
300 PCI_ANY_ID, PCI_ANY_ID, 0, 0, SI7012},
301 {PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_MCP1_AUDIO,
302 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NVIDIA_NFORCE},
303 {PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_MCP2_AUDIO,
304 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NVIDIA_NFORCE},
305 {PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_MCP3_AUDIO,
306 PCI_ANY_ID, PCI_ANY_ID, 0, 0, NVIDIA_NFORCE},
307 {PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_OPUS_7445,
308 PCI_ANY_ID, PCI_ANY_ID, 0, 0, AMD768},
309 {PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_AUDIO,
310 PCI_ANY_ID, PCI_ANY_ID, 0, 0, AMD8111},
311 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_5,
312 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
313 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_18,
314 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
315
316 {0,}
317};
318
319MODULE_DEVICE_TABLE (pci, i810_pci_tbl);
320
321#ifdef CONFIG_PM
322#define PM_SUSPENDED(card) (card->pm_suspended)
323#else
324#define PM_SUSPENDED(card) (0)
325#endif
326
327/* "software" or virtual channel, an instance of opened /dev/dsp */
328struct i810_state {
329 unsigned int magic;
330 struct i810_card *card; /* Card info */
331
332 /* single open lock mechanism, only used for recording */
333 struct semaphore open_sem;
334 wait_queue_head_t open_wait;
335
336 /* file mode */
337 mode_t open_mode;
338
339 /* virtual channel number */
340 int virt;
341
342#ifdef CONFIG_PM
343 unsigned int pm_saved_dac_rate,pm_saved_adc_rate;
344#endif
345 struct dmabuf {
346 /* wave sample stuff */
347 unsigned int rate;
348 unsigned char fmt, enable, trigger;
349
350 /* hardware channel */
351 struct i810_channel *read_channel;
352 struct i810_channel *write_channel;
353
354 /* OSS buffer management stuff */
355 void *rawbuf;
356 dma_addr_t dma_handle;
357 unsigned buforder;
358 unsigned numfrag;
359 unsigned fragshift;
360
361 /* our buffer acts like a circular ring */
362 unsigned hwptr; /* where dma last started, updated by update_ptr */
363 unsigned swptr; /* where driver last clear/filled, updated by read/write */
364 int count; /* bytes to be consumed or been generated by dma machine */
365 unsigned total_bytes; /* total bytes dmaed by hardware */
366
367 unsigned error; /* number of over/underruns */
368 wait_queue_head_t wait; /* put process on wait queue when no more space in buffer */
369
370 /* redundant, but makes calculations easier */
371 /* what the hardware uses */
372 unsigned dmasize;
373 unsigned fragsize;
374 unsigned fragsamples;
375
376 /* what we tell the user to expect */
377 unsigned userfrags;
378 unsigned userfragsize;
379
380 /* OSS stuff */
381 unsigned mapped:1;
382 unsigned ready:1;
383 unsigned update_flag;
384 unsigned ossfragsize;
385 unsigned ossmaxfrags;
386 unsigned subdivision;
387 } dmabuf;
388};
389
390
391struct i810_card {
392 unsigned int magic;
393
394 /* We keep i810 cards in a linked list */
395 struct i810_card *next;
396
397 /* The i810 has a certain amount of cross channel interaction
398 so we use a single per card lock */
399 spinlock_t lock;
400
401 /* Control AC97 access serialization */
402 spinlock_t ac97_lock;
403
404 /* PCI device stuff */
405 struct pci_dev * pci_dev;
406 u16 pci_id;
407 u16 pci_id_internal; /* used to access card_cap[] */
408#ifdef CONFIG_PM
409 u16 pm_suspended;
410 int pm_saved_mixer_settings[SOUND_MIXER_NRDEVICES][NR_AC97];
411#endif
412 /* soundcore stuff */
413 int dev_audio;
414
415 /* structures for abstraction of hardware facilities, codecs, banks and channels*/
416 u16 ac97_id_map[NR_AC97];
417 struct ac97_codec *ac97_codec[NR_AC97];
418 struct i810_state *states[NR_HW_CH];
419 struct i810_channel *channel; /* 1:1 to states[] but diff. lifetime */
420 dma_addr_t chandma;
421
422 u16 ac97_features;
423 u16 ac97_status;
424 u16 channels;
425
426 /* hardware resources */
427 unsigned long ac97base;
428 unsigned long iobase;
429 u32 irq;
430
431 unsigned long ac97base_mmio_phys;
432 unsigned long iobase_mmio_phys;
433 u_int8_t __iomem *ac97base_mmio;
434 u_int8_t __iomem *iobase_mmio;
435
436 int use_mmio;
437
438 /* Function support */
439 struct i810_channel *(*alloc_pcm_channel)(struct i810_card *);
440 struct i810_channel *(*alloc_rec_pcm_channel)(struct i810_card *);
441 struct i810_channel *(*alloc_rec_mic_channel)(struct i810_card *);
442 void (*free_pcm_channel)(struct i810_card *, int chan);
443
444 /* We have a *very* long init time possibly, so use this to block */
445 /* attempts to open our devices before we are ready (stops oops'es) */
446 int initializing;
447};
448
449/* extract register offset from codec struct */
450#define IO_REG_OFF(codec) (((struct i810_card *) codec->private_data)->ac97_id_map[codec->id])
451
452#define I810_IOREAD(size, type, card, off) \
453({ \
454 type val; \
455 if (card->use_mmio) \
456 val=read##size(card->iobase_mmio+off); \
457 else \
458 val=in##size(card->iobase+off); \
459 val; \
460})
461
462#define I810_IOREADL(card, off) I810_IOREAD(l, u32, card, off)
463#define I810_IOREADW(card, off) I810_IOREAD(w, u16, card, off)
464#define I810_IOREADB(card, off) I810_IOREAD(b, u8, card, off)
465
466#define I810_IOWRITE(size, val, card, off) \
467({ \
468 if (card->use_mmio) \
469 write##size(val, card->iobase_mmio+off); \
470 else \
471 out##size(val, card->iobase+off); \
472})
473
474#define I810_IOWRITEL(val, card, off) I810_IOWRITE(l, val, card, off)
475#define I810_IOWRITEW(val, card, off) I810_IOWRITE(w, val, card, off)
476#define I810_IOWRITEB(val, card, off) I810_IOWRITE(b, val, card, off)
477
478#define GET_CIV(card, port) MODULOP2(I810_IOREADB((card), (port) + OFF_CIV), SG_LEN)
479#define GET_LVI(card, port) MODULOP2(I810_IOREADB((card), (port) + OFF_LVI), SG_LEN)
480
481/* set LVI from CIV */
482#define CIV_TO_LVI(card, port, off) \
483 I810_IOWRITEB(MODULOP2(GET_CIV((card), (port)) + (off), SG_LEN), (card), (port) + OFF_LVI)
484
485static struct ac97_quirk ac97_quirks[] __devinitdata = {
486 {
487 .vendor = 0x0e11,
488 .device = 0x00b8,
489 .name = "Compaq Evo D510C",
490 .type = AC97_TUNE_HP_ONLY
491 },
492 {
493 .vendor = 0x1028,
494 .device = 0x00d8,
495 .name = "Dell Precision 530", /* AD1885 */
496 .type = AC97_TUNE_HP_ONLY
497 },
498 {
499 .vendor = 0x1028,
500 .device = 0x0126,
501 .name = "Dell Optiplex GX260", /* AD1981A */
502 .type = AC97_TUNE_HP_ONLY
503 },
504 {
505 .vendor = 0x1028,
506 .device = 0x012d,
507 .name = "Dell Precision 450", /* AD1981B*/
508 .type = AC97_TUNE_HP_ONLY
509 },
510 { /* FIXME: which codec? */
511 .vendor = 0x103c,
512 .device = 0x00c3,
513 .name = "Hewlett-Packard onboard",
514 .type = AC97_TUNE_HP_ONLY
515 },
516 {
517 .vendor = 0x103c,
518 .device = 0x12f1,
519 .name = "HP xw8200", /* AD1981B*/
520 .type = AC97_TUNE_HP_ONLY
521 },
522 {
523 .vendor = 0x103c,
524 .device = 0x3008,
525 .name = "HP xw4200", /* AD1981B*/
526 .type = AC97_TUNE_HP_ONLY
527 },
528 {
529 .vendor = 0x10f1,
530 .device = 0x2665,
531 .name = "Fujitsu-Siemens Celsius", /* AD1981? */
532 .type = AC97_TUNE_HP_ONLY
533 },
534 {
535 .vendor = 0x10f1,
536 .device = 0x2885,
537 .name = "AMD64 Mobo", /* ALC650 */
538 .type = AC97_TUNE_HP_ONLY
539 },
540 {
541 .vendor = 0x110a,
542 .device = 0x0056,
543 .name = "Fujitsu-Siemens Scenic", /* AD1981? */
544 .type = AC97_TUNE_HP_ONLY
545 },
546 {
547 .vendor = 0x11d4,
548 .device = 0x5375,
549 .name = "ADI AD1985 (discrete)",
550 .type = AC97_TUNE_HP_ONLY
551 },
552 {
553 .vendor = 0x1462,
554 .device = 0x5470,
555 .name = "MSI P4 ATX 645 Ultra",
556 .type = AC97_TUNE_HP_ONLY
557 },
558 {
559 .vendor = 0x1734,
560 .device = 0x0088,
561 .name = "Fujitsu-Siemens D1522", /* AD1981 */
562 .type = AC97_TUNE_HP_ONLY
563 },
564 {
565 .vendor = 0x8086,
566 .device = 0x4856,
567 .name = "Intel D845WN (82801BA)",
568 .type = AC97_TUNE_SWAP_HP
569 },
570 {
571 .vendor = 0x8086,
572 .device = 0x4d44,
573 .name = "Intel D850EMV2", /* AD1885 */
574 .type = AC97_TUNE_HP_ONLY
575 },
576 {
577 .vendor = 0x8086,
578 .device = 0x4d56,
579 .name = "Intel ICH/AD1885",
580 .type = AC97_TUNE_HP_ONLY
581 },
582 {
583 .vendor = 0x1028,
584 .device = 0x012d,
585 .name = "Dell Precision 450", /* AD1981B*/
586 .type = AC97_TUNE_HP_ONLY
587 },
588 {
589 .vendor = 0x103c,
590 .device = 0x3008,
591 .name = "HP xw4200", /* AD1981B*/
592 .type = AC97_TUNE_HP_ONLY
593 },
594 {
595 .vendor = 0x103c,
596 .device = 0x12f1,
597 .name = "HP xw8200", /* AD1981B*/
598 .type = AC97_TUNE_HP_ONLY
599 },
600 { } /* terminator */
601};
602
603static struct i810_card *devs = NULL;
604
605static int i810_open_mixdev(struct inode *inode, struct file *file);
606static int i810_ioctl_mixdev(struct inode *inode, struct file *file,
607 unsigned int cmd, unsigned long arg);
608static u16 i810_ac97_get(struct ac97_codec *dev, u8 reg);
609static void i810_ac97_set(struct ac97_codec *dev, u8 reg, u16 data);
610static u16 i810_ac97_get_mmio(struct ac97_codec *dev, u8 reg);
611static void i810_ac97_set_mmio(struct ac97_codec *dev, u8 reg, u16 data);
612static u16 i810_ac97_get_io(struct ac97_codec *dev, u8 reg);
613static void i810_ac97_set_io(struct ac97_codec *dev, u8 reg, u16 data);
614
615static struct i810_channel *i810_alloc_pcm_channel(struct i810_card *card)
616{
617 if(card->channel[1].used==1)
618 return NULL;
619 card->channel[1].used=1;
620 return &card->channel[1];
621}
622
623static struct i810_channel *i810_alloc_rec_pcm_channel(struct i810_card *card)
624{
625 if(card->channel[0].used==1)
626 return NULL;
627 card->channel[0].used=1;
628 return &card->channel[0];
629}
630
631static struct i810_channel *i810_alloc_rec_mic_channel(struct i810_card *card)
632{
633 if(card->channel[2].used==1)
634 return NULL;
635 card->channel[2].used=1;
636 return &card->channel[2];
637}
638
639static void i810_free_pcm_channel(struct i810_card *card, int channel)
640{
641 card->channel[channel].used=0;
642}
643
644static int i810_valid_spdif_rate ( struct ac97_codec *codec, int rate )
645{
646 unsigned long id = 0L;
647
648 id = (i810_ac97_get(codec, AC97_VENDOR_ID1) << 16);
649 id |= i810_ac97_get(codec, AC97_VENDOR_ID2) & 0xffff;
650#ifdef DEBUG
651 printk ( "i810_audio: codec = %s, codec_id = 0x%08lx\n", codec->name, id);
652#endif
653 switch ( id ) {
654 case 0x41445361: /* AD1886 */
655 if (rate == 48000) {
656 return 1;
657 }
658 break;
659 default: /* all other codecs, until we know otherwiae */
660 if (rate == 48000 || rate == 44100 || rate == 32000) {
661 return 1;
662 }
663 break;
664 }
665 return (0);
666}
667
668/* i810_set_spdif_output
669 *
670 * Configure the S/PDIF output transmitter. When we turn on
671 * S/PDIF, we turn off the analog output. This may not be
672 * the right thing to do.
673 *
674 * Assumptions:
675 * The DSP sample rate must already be set to a supported
676 * S/PDIF rate (32kHz, 44.1kHz, or 48kHz) or we abort.
677 */
678static int i810_set_spdif_output(struct i810_state *state, int slots, int rate)
679{
680 int vol;
681 int aud_reg;
682 int r = 0;
683 struct ac97_codec *codec = state->card->ac97_codec[0];
684
685 if(!codec->codec_ops->digital) {
686 state->card->ac97_status &= ~SPDIF_ON;
687 } else {
688 if ( slots == -1 ) { /* Turn off S/PDIF */
689 codec->codec_ops->digital(codec, 0, 0, 0);
690 /* If the volume wasn't muted before we turned on S/PDIF, unmute it */
691 if ( !(state->card->ac97_status & VOL_MUTED) ) {
692 aud_reg = i810_ac97_get(codec, AC97_MASTER_VOL_STEREO);
693 i810_ac97_set(codec, AC97_MASTER_VOL_STEREO, (aud_reg & ~VOL_MUTED));
694 }
695 state->card->ac97_status &= ~(VOL_MUTED | SPDIF_ON);
696 return 0;
697 }
698
699 vol = i810_ac97_get(codec, AC97_MASTER_VOL_STEREO);
700 state->card->ac97_status = vol & VOL_MUTED;
701
702 r = codec->codec_ops->digital(codec, slots, rate, 0);
703
704 if(r)
705 state->card->ac97_status |= SPDIF_ON;
706 else
707 state->card->ac97_status &= ~SPDIF_ON;
708
709 /* Mute the analog output */
710 /* Should this only mute the PCM volume??? */
711 i810_ac97_set(codec, AC97_MASTER_VOL_STEREO, (vol | VOL_MUTED));
712 }
713 return r;
714}
715
716/* i810_set_dac_channels
717 *
718 * Configure the codec's multi-channel DACs
719 *
720 * The logic is backwards. Setting the bit to 1 turns off the DAC.
721 *
722 * What about the ICH? We currently configure it using the
723 * SNDCTL_DSP_CHANNELS ioctl. If we're turnning on the DAC,
724 * does that imply that we want the ICH set to support
725 * these channels?
726 *
727 * TODO:
728 * vailidate that the codec really supports these DACs
729 * before turning them on.
730 */
731static void i810_set_dac_channels(struct i810_state *state, int channel)
732{
733 int aud_reg;
734 struct ac97_codec *codec = state->card->ac97_codec[0];
735
736 /* No codec, no setup */
737
738 if(codec == NULL)
739 return;
740
741 aud_reg = i810_ac97_get(codec, AC97_EXTENDED_STATUS);
742 aud_reg |= AC97_EA_PRI | AC97_EA_PRJ | AC97_EA_PRK;
743 state->card->ac97_status &= ~(SURR_ON | CENTER_LFE_ON);
744
745 switch ( channel ) {
746 case 2: /* always enabled */
747 break;
748 case 4:
749 aud_reg &= ~AC97_EA_PRJ;
750 state->card->ac97_status |= SURR_ON;
751 break;
752 case 6:
753 aud_reg &= ~(AC97_EA_PRJ | AC97_EA_PRI | AC97_EA_PRK);
754 state->card->ac97_status |= SURR_ON | CENTER_LFE_ON;
755 break;
756 default:
757 break;
758 }
759 i810_ac97_set(codec, AC97_EXTENDED_STATUS, aud_reg);
760
761}
762
763
764/* set playback sample rate */
765static unsigned int i810_set_dac_rate(struct i810_state * state, unsigned int rate)
766{
767 struct dmabuf *dmabuf = &state->dmabuf;
768 u32 new_rate;
769 struct ac97_codec *codec=state->card->ac97_codec[0];
770
771 if(!(state->card->ac97_features&0x0001))
772 {
773 dmabuf->rate = clocking;
774#ifdef DEBUG
775 printk("Asked for %d Hz, but ac97_features says we only do %dHz. Sorry!\n",
776 rate,clocking);
777#endif
778 return clocking;
779 }
780
781 if (rate > 48000)
782 rate = 48000;
783 if (rate < 8000)
784 rate = 8000;
785 dmabuf->rate = rate;
786
787 /*
788 * Adjust for misclocked crap
789 */
790 rate = ( rate * clocking)/48000;
791 if(strict_clocking && rate < 8000) {
792 rate = 8000;
793 dmabuf->rate = (rate * 48000)/clocking;
794 }
795
796 new_rate=ac97_set_dac_rate(codec, rate);
797 if(new_rate != rate) {
798 dmabuf->rate = (new_rate * 48000)/clocking;
799 }
800#ifdef DEBUG
801 printk("i810_audio: called i810_set_dac_rate : asked for %d, got %d\n", rate, dmabuf->rate);
802#endif
803 rate = new_rate;
804 return dmabuf->rate;
805}
806
807/* set recording sample rate */
808static unsigned int i810_set_adc_rate(struct i810_state * state, unsigned int rate)
809{
810 struct dmabuf *dmabuf = &state->dmabuf;
811 u32 new_rate;
812 struct ac97_codec *codec=state->card->ac97_codec[0];
813
814 if(!(state->card->ac97_features&0x0001))
815 {
816 dmabuf->rate = clocking;
817 return clocking;
818 }
819
820 if (rate > 48000)
821 rate = 48000;
822 if (rate < 8000)
823 rate = 8000;
824 dmabuf->rate = rate;
825
826 /*
827 * Adjust for misclocked crap
828 */
829
830 rate = ( rate * clocking)/48000;
831 if(strict_clocking && rate < 8000) {
832 rate = 8000;
833 dmabuf->rate = (rate * 48000)/clocking;
834 }
835
836 new_rate = ac97_set_adc_rate(codec, rate);
837
838 if(new_rate != rate) {
839 dmabuf->rate = (new_rate * 48000)/clocking;
840 rate = new_rate;
841 }
842#ifdef DEBUG
843 printk("i810_audio: called i810_set_adc_rate : rate = %d/%d\n", dmabuf->rate, rate);
844#endif
845 return dmabuf->rate;
846}
847
848/* get current playback/recording dma buffer pointer (byte offset from LBA),
849 called with spinlock held! */
850
851static inline unsigned i810_get_dma_addr(struct i810_state *state, int rec)
852{
853 struct dmabuf *dmabuf = &state->dmabuf;
854 unsigned int civ, offset, port, port_picb, bytes = 2;
855
856 if (!dmabuf->enable)
857 return 0;
858
859 if (rec)
860 port = dmabuf->read_channel->port;
861 else
862 port = dmabuf->write_channel->port;
863
864 if(state->card->pci_id == PCI_DEVICE_ID_SI_7012) {
865 port_picb = port + OFF_SR;
866 bytes = 1;
867 } else
868 port_picb = port + OFF_PICB;
869
870 do {
871 civ = GET_CIV(state->card, port);
872 offset = I810_IOREADW(state->card, port_picb);
873 /* Must have a delay here! */
874 if(offset == 0)
875 udelay(1);
876 /* Reread both registers and make sure that that total
877 * offset from the first reading to the second is 0.
878 * There is an issue with SiS hardware where it will count
879 * picb down to 0, then update civ to the next value,
880 * then set the new picb to fragsize bytes. We can catch
881 * it between the civ update and the picb update, making
882 * it look as though we are 1 fragsize ahead of where we
883 * are. The next to we get the address though, it will
884 * be back in the right place, and we will suddenly think
885 * we just went forward dmasize - fragsize bytes, causing
886 * totally stupid *huge* dma overrun messages. We are
887 * assuming that the 1us delay is more than long enough
888 * that we won't have to worry about the chip still being
889 * out of sync with reality ;-)
890 */
891 } while (civ != GET_CIV(state->card, port) || offset != I810_IOREADW(state->card, port_picb));
892
893 return (((civ + 1) * dmabuf->fragsize - (bytes * offset))
894 % dmabuf->dmasize);
895}
896
897/* Stop recording (lock held) */
898static inline void __stop_adc(struct i810_state *state)
899{
900 struct dmabuf *dmabuf = &state->dmabuf;
901 struct i810_card *card = state->card;
902
903 dmabuf->enable &= ~ADC_RUNNING;
904 I810_IOWRITEB(0, card, PI_CR);
905 // wait for the card to acknowledge shutdown
906 while( I810_IOREADB(card, PI_CR) != 0 ) ;
907 // now clear any latent interrupt bits (like the halt bit)
908 if(card->pci_id == PCI_DEVICE_ID_SI_7012)
909 I810_IOWRITEB( I810_IOREADB(card, PI_PICB), card, PI_PICB );
910 else
911 I810_IOWRITEB( I810_IOREADB(card, PI_SR), card, PI_SR );
912 I810_IOWRITEL( I810_IOREADL(card, GLOB_STA) & INT_PI, card, GLOB_STA);
913}
914
915static void stop_adc(struct i810_state *state)
916{
917 struct i810_card *card = state->card;
918 unsigned long flags;
919
920 spin_lock_irqsave(&card->lock, flags);
921 __stop_adc(state);
922 spin_unlock_irqrestore(&card->lock, flags);
923}
924
925static inline void __start_adc(struct i810_state *state)
926{
927 struct dmabuf *dmabuf = &state->dmabuf;
928
929 if (dmabuf->count < dmabuf->dmasize && dmabuf->ready && !dmabuf->enable &&
930 (dmabuf->trigger & PCM_ENABLE_INPUT)) {
931 dmabuf->enable |= ADC_RUNNING;
932 // Interrupt enable, LVI enable, DMA enable
933 I810_IOWRITEB(0x10 | 0x04 | 0x01, state->card, PI_CR);
934 }
935}
936
937static void start_adc(struct i810_state *state)
938{
939 struct i810_card *card = state->card;
940 unsigned long flags;
941
942 spin_lock_irqsave(&card->lock, flags);
943 __start_adc(state);
944 spin_unlock_irqrestore(&card->lock, flags);
945}
946
947/* stop playback (lock held) */
948static inline void __stop_dac(struct i810_state *state)
949{
950 struct dmabuf *dmabuf = &state->dmabuf;
951 struct i810_card *card = state->card;
952
953 dmabuf->enable &= ~DAC_RUNNING;
954 I810_IOWRITEB(0, card, PO_CR);
955 // wait for the card to acknowledge shutdown
956 while( I810_IOREADB(card, PO_CR) != 0 ) ;
957 // now clear any latent interrupt bits (like the halt bit)
958 if(card->pci_id == PCI_DEVICE_ID_SI_7012)
959 I810_IOWRITEB( I810_IOREADB(card, PO_PICB), card, PO_PICB );
960 else
961 I810_IOWRITEB( I810_IOREADB(card, PO_SR), card, PO_SR );
962 I810_IOWRITEL( I810_IOREADL(card, GLOB_STA) & INT_PO, card, GLOB_STA);
963}
964
965static void stop_dac(struct i810_state *state)
966{
967 struct i810_card *card = state->card;
968 unsigned long flags;
969
970 spin_lock_irqsave(&card->lock, flags);
971 __stop_dac(state);
972 spin_unlock_irqrestore(&card->lock, flags);
973}
974
975static inline void __start_dac(struct i810_state *state)
976{
977 struct dmabuf *dmabuf = &state->dmabuf;
978
979 if (dmabuf->count > 0 && dmabuf->ready && !dmabuf->enable &&
980 (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
981 dmabuf->enable |= DAC_RUNNING;
982 // Interrupt enable, LVI enable, DMA enable
983 I810_IOWRITEB(0x10 | 0x04 | 0x01, state->card, PO_CR);
984 }
985}
986static void start_dac(struct i810_state *state)
987{
988 struct i810_card *card = state->card;
989 unsigned long flags;
990
991 spin_lock_irqsave(&card->lock, flags);
992 __start_dac(state);
993 spin_unlock_irqrestore(&card->lock, flags);
994}
995
996#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT)
997#define DMABUF_MINORDER 1
998
999/* allocate DMA buffer, playback and recording buffer should be allocated separately */
1000static int alloc_dmabuf(struct i810_state *state)
1001{
1002 struct dmabuf *dmabuf = &state->dmabuf;
1003 void *rawbuf= NULL;
1004 int order, size;
1005 struct page *page, *pend;
1006
1007 /* If we don't have any oss frag params, then use our default ones */
1008 if(dmabuf->ossmaxfrags == 0)
1009 dmabuf->ossmaxfrags = 4;
1010 if(dmabuf->ossfragsize == 0)
1011 dmabuf->ossfragsize = (PAGE_SIZE<<DMABUF_DEFAULTORDER)/dmabuf->ossmaxfrags;
1012 size = dmabuf->ossfragsize * dmabuf->ossmaxfrags;
1013
1014 if(dmabuf->rawbuf && (PAGE_SIZE << dmabuf->buforder) == size)
1015 return 0;
1016 /* alloc enough to satisfy the oss params */
1017 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--) {
1018 if ( (PAGE_SIZE<<order) > size )
1019 continue;
1020 if ((rawbuf = pci_alloc_consistent(state->card->pci_dev,
1021 PAGE_SIZE << order,
1022 &dmabuf->dma_handle)))
1023 break;
1024 }
1025 if (!rawbuf)
1026 return -ENOMEM;
1027
1028
1029#ifdef DEBUG
1030 printk("i810_audio: allocated %ld (order = %d) bytes at %p\n",
1031 PAGE_SIZE << order, order, rawbuf);
1032#endif
1033
1034 dmabuf->ready = dmabuf->mapped = 0;
1035 dmabuf->rawbuf = rawbuf;
1036 dmabuf->buforder = order;
1037
1038 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
1039 pend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1);
1040 for (page = virt_to_page(rawbuf); page <= pend; page++)
1041 SetPageReserved(page);
1042
1043 return 0;
1044}
1045
1046/* free DMA buffer */
1047static void dealloc_dmabuf(struct i810_state *state)
1048{
1049 struct dmabuf *dmabuf = &state->dmabuf;
1050 struct page *page, *pend;
1051
1052 if (dmabuf->rawbuf) {
1053 /* undo marking the pages as reserved */
1054 pend = virt_to_page(dmabuf->rawbuf + (PAGE_SIZE << dmabuf->buforder) - 1);
1055 for (page = virt_to_page(dmabuf->rawbuf); page <= pend; page++)
1056 ClearPageReserved(page);
1057 pci_free_consistent(state->card->pci_dev, PAGE_SIZE << dmabuf->buforder,
1058 dmabuf->rawbuf, dmabuf->dma_handle);
1059 }
1060 dmabuf->rawbuf = NULL;
1061 dmabuf->mapped = dmabuf->ready = 0;
1062}
1063
1064static int prog_dmabuf(struct i810_state *state, unsigned rec)
1065{
1066 struct dmabuf *dmabuf = &state->dmabuf;
1067 struct i810_channel *c;
1068 struct sg_item *sg;
1069 unsigned long flags;
1070 int ret;
1071 unsigned fragint;
1072 int i;
1073
1074 spin_lock_irqsave(&state->card->lock, flags);
1075 if(dmabuf->enable & DAC_RUNNING)
1076 __stop_dac(state);
1077 if(dmabuf->enable & ADC_RUNNING)
1078 __stop_adc(state);
1079 dmabuf->total_bytes = 0;
1080 dmabuf->count = dmabuf->error = 0;
1081 dmabuf->swptr = dmabuf->hwptr = 0;
1082 spin_unlock_irqrestore(&state->card->lock, flags);
1083
1084 /* allocate DMA buffer, let alloc_dmabuf determine if we are already
1085 * allocated well enough or if we should replace the current buffer
1086 * (assuming one is already allocated, if it isn't, then allocate it).
1087 */
1088 if ((ret = alloc_dmabuf(state)))
1089 return ret;
1090
1091 /* FIXME: figure out all this OSS fragment stuff */
1092 /* I did, it now does what it should according to the OSS API. DL */
1093 /* We may not have realloced our dmabuf, but the fragment size to
1094 * fragment number ratio may have changed, so go ahead and reprogram
1095 * things
1096 */
1097 dmabuf->dmasize = PAGE_SIZE << dmabuf->buforder;
1098 dmabuf->numfrag = SG_LEN;
1099 dmabuf->fragsize = dmabuf->dmasize/dmabuf->numfrag;
1100 dmabuf->fragsamples = dmabuf->fragsize >> 1;
1101 dmabuf->fragshift = ffs(dmabuf->fragsize) - 1;
1102 dmabuf->userfragsize = dmabuf->ossfragsize;
1103 dmabuf->userfrags = dmabuf->dmasize/dmabuf->ossfragsize;
1104
1105 memset(dmabuf->rawbuf, 0, dmabuf->dmasize);
1106
1107 if(dmabuf->ossmaxfrags == 4) {
1108 fragint = 8;
1109 } else if (dmabuf->ossmaxfrags == 8) {
1110 fragint = 4;
1111 } else if (dmabuf->ossmaxfrags == 16) {
1112 fragint = 2;
1113 } else {
1114 fragint = 1;
1115 }
1116 /*
1117 * Now set up the ring
1118 */
1119 if(dmabuf->read_channel)
1120 c = dmabuf->read_channel;
1121 else
1122 c = dmabuf->write_channel;
1123 while(c != NULL) {
1124 sg=&c->sg[0];
1125 /*
1126 * Load up 32 sg entries and take an interrupt at half
1127 * way (we might want more interrupts later..)
1128 */
1129
1130 for(i=0;i<dmabuf->numfrag;i++)
1131 {
1132 sg->busaddr=(u32)dmabuf->dma_handle+dmabuf->fragsize*i;
1133 // the card will always be doing 16bit stereo
1134 sg->control=dmabuf->fragsamples;
1135 if(state->card->pci_id == PCI_DEVICE_ID_SI_7012)
1136 sg->control <<= 1;
1137 sg->control|=CON_BUFPAD;
1138 // set us up to get IOC interrupts as often as needed to
1139 // satisfy numfrag requirements, no more
1140 if( ((i+1) % fragint) == 0) {
1141 sg->control|=CON_IOC;
1142 }
1143 sg++;
1144 }
1145 spin_lock_irqsave(&state->card->lock, flags);
1146 I810_IOWRITEB(2, state->card, c->port+OFF_CR); /* reset DMA machine */
1147 while( I810_IOREADB(state->card, c->port+OFF_CR) & 0x02 ) ;
1148 I810_IOWRITEL((u32)state->card->chandma +
1149 c->num*sizeof(struct i810_channel),
1150 state->card, c->port+OFF_BDBAR);
1151 CIV_TO_LVI(state->card, c->port, 0);
1152
1153 spin_unlock_irqrestore(&state->card->lock, flags);
1154
1155 if(c != dmabuf->write_channel)
1156 c = dmabuf->write_channel;
1157 else
1158 c = NULL;
1159 }
1160
1161 /* set the ready flag for the dma buffer */
1162 dmabuf->ready = 1;
1163
1164#ifdef DEBUG
1165 printk("i810_audio: prog_dmabuf, sample rate = %d, format = %d,\n\tnumfrag = %d, "
1166 "fragsize = %d dmasize = %d\n",
1167 dmabuf->rate, dmabuf->fmt, dmabuf->numfrag,
1168 dmabuf->fragsize, dmabuf->dmasize);
1169#endif
1170
1171 return 0;
1172}
1173
1174static void __i810_update_lvi(struct i810_state *state, int rec)
1175{
1176 struct dmabuf *dmabuf = &state->dmabuf;
1177 int x, port;
1178 int trigger;
1179 int count, fragsize;
1180 void (*start)(struct i810_state *);
1181
1182 count = dmabuf->count;
1183 if (rec) {
1184 port = dmabuf->read_channel->port;
1185 trigger = PCM_ENABLE_INPUT;
1186 start = __start_adc;
1187 count = dmabuf->dmasize - count;
1188 } else {
1189 port = dmabuf->write_channel->port;
1190 trigger = PCM_ENABLE_OUTPUT;
1191 start = __start_dac;
1192 }
1193
1194 /* Do not process partial fragments. */
1195 fragsize = dmabuf->fragsize;
1196 if (count < fragsize)
1197 return;
1198
1199 /* if we are currently stopped, then our CIV is actually set to our
1200 * *last* sg segment and we are ready to wrap to the next. However,
1201 * if we set our LVI to the last sg segment, then it won't wrap to
1202 * the next sg segment, it won't even get a start. So, instead, when
1203 * we are stopped, we set both the LVI value and also we increment
1204 * the CIV value to the next sg segment to be played so that when
1205 * we call start, things will operate properly. Since the CIV can't
1206 * be written to directly for this purpose, we set the LVI to CIV + 1
1207 * temporarily. Once the engine has started we set the LVI to its
1208 * final value.
1209 */
1210 if (!dmabuf->enable && dmabuf->ready) {
1211 if (!(dmabuf->trigger & trigger))
1212 return;
1213
1214 CIV_TO_LVI(state->card, port, 1);
1215
1216 start(state);
1217 while (!(I810_IOREADB(state->card, port + OFF_CR) & ((1<<4) | (1<<2))))
1218 ;
1219 }
1220
1221 /* MASKP2(swptr, fragsize) - 1 is the tail of our transfer */
1222 x = MODULOP2(MASKP2(dmabuf->swptr, fragsize) - 1, dmabuf->dmasize);
1223 x >>= dmabuf->fragshift;
1224 I810_IOWRITEB(x, state->card, port + OFF_LVI);
1225}
1226
1227static void i810_update_lvi(struct i810_state *state, int rec)
1228{
1229 struct dmabuf *dmabuf = &state->dmabuf;
1230 unsigned long flags;
1231
1232 if(!dmabuf->ready)
1233 return;
1234 spin_lock_irqsave(&state->card->lock, flags);
1235 __i810_update_lvi(state, rec);
1236 spin_unlock_irqrestore(&state->card->lock, flags);
1237}
1238
1239/* update buffer manangement pointers, especially, dmabuf->count and dmabuf->hwptr */
1240static void i810_update_ptr(struct i810_state *state)
1241{
1242 struct dmabuf *dmabuf = &state->dmabuf;
1243 unsigned hwptr;
1244 unsigned fragmask, dmamask;
1245 int diff;
1246
1247 fragmask = MASKP2(~0, dmabuf->fragsize);
1248 dmamask = MODULOP2(~0, dmabuf->dmasize);
1249
1250 /* error handling and process wake up for ADC */
1251 if (dmabuf->enable == ADC_RUNNING) {
1252 /* update hardware pointer */
1253 hwptr = i810_get_dma_addr(state, 1) & fragmask;
1254 diff = (hwptr - dmabuf->hwptr) & dmamask;
1255#if defined(DEBUG_INTERRUPTS) || defined(DEBUG_MMAP)
1256 printk("ADC HWP %d,%d,%d\n", hwptr, dmabuf->hwptr, diff);
1257#endif
1258 dmabuf->hwptr = hwptr;
1259 dmabuf->total_bytes += diff;
1260 dmabuf->count += diff;
1261 if (dmabuf->count > dmabuf->dmasize) {
1262 /* buffer underrun or buffer overrun */
1263 /* this is normal for the end of a read */
1264 /* only give an error if we went past the */
1265 /* last valid sg entry */
1266 if (GET_CIV(state->card, PI_BASE) !=
1267 GET_LVI(state->card, PI_BASE)) {
1268 printk(KERN_WARNING "i810_audio: DMA overrun on read\n");
1269 dmabuf->error++;
1270 }
1271 }
1272 if (diff)
1273 wake_up(&dmabuf->wait);
1274 }
1275 /* error handling and process wake up for DAC */
1276 if (dmabuf->enable == DAC_RUNNING) {
1277 /* update hardware pointer */
1278 hwptr = i810_get_dma_addr(state, 0) & fragmask;
1279 diff = (hwptr - dmabuf->hwptr) & dmamask;
1280#if defined(DEBUG_INTERRUPTS) || defined(DEBUG_MMAP)
1281 printk("DAC HWP %d,%d,%d\n", hwptr, dmabuf->hwptr, diff);
1282#endif
1283 dmabuf->hwptr = hwptr;
1284 dmabuf->total_bytes += diff;
1285 dmabuf->count -= diff;
1286 if (dmabuf->count < 0) {
1287 /* buffer underrun or buffer overrun */
1288 /* this is normal for the end of a write */
1289 /* only give an error if we went past the */
1290 /* last valid sg entry */
1291 if (GET_CIV(state->card, PO_BASE) !=
1292 GET_LVI(state->card, PO_BASE)) {
1293 printk(KERN_WARNING "i810_audio: DMA overrun on write\n");
1294 printk("i810_audio: CIV %d, LVI %d, hwptr %x, "
1295 "count %d\n",
1296 GET_CIV(state->card, PO_BASE),
1297 GET_LVI(state->card, PO_BASE),
1298 dmabuf->hwptr, dmabuf->count);
1299 dmabuf->error++;
1300 }
1301 }
1302 if (diff)
1303 wake_up(&dmabuf->wait);
1304 }
1305}
1306
1307static inline int i810_get_free_write_space(struct i810_state *state)
1308{
1309 struct dmabuf *dmabuf = &state->dmabuf;
1310 int free;
1311
1312 i810_update_ptr(state);
1313 // catch underruns during playback
1314 if (dmabuf->count < 0) {
1315 dmabuf->count = 0;
1316 dmabuf->swptr = dmabuf->hwptr;
1317 }
1318 free = dmabuf->dmasize - dmabuf->count;
1319 if(free < 0)
1320 return(0);
1321 return(free);
1322}
1323
1324static inline int i810_get_available_read_data(struct i810_state *state)
1325{
1326 struct dmabuf *dmabuf = &state->dmabuf;
1327 int avail;
1328
1329 i810_update_ptr(state);
1330 // catch overruns during record
1331 if (dmabuf->count > dmabuf->dmasize) {
1332 dmabuf->count = dmabuf->dmasize;
1333 dmabuf->swptr = dmabuf->hwptr;
1334 }
1335 avail = dmabuf->count;
1336 if(avail < 0)
1337 return(0);
1338 return(avail);
1339}
1340
1341static inline void fill_partial_frag(struct dmabuf *dmabuf)
1342{
1343 unsigned fragsize;
1344 unsigned swptr, len;
1345
1346 fragsize = dmabuf->fragsize;
1347 swptr = dmabuf->swptr;
1348 len = fragsize - MODULOP2(dmabuf->swptr, fragsize);
1349 if (len == fragsize)
1350 return;
1351
1352 memset(dmabuf->rawbuf + swptr, '\0', len);
1353 dmabuf->swptr = MODULOP2(swptr + len, dmabuf->dmasize);
1354 dmabuf->count += len;
1355}
1356
1357static int drain_dac(struct i810_state *state, int signals_allowed)
1358{
1359 DECLARE_WAITQUEUE(wait, current);
1360 struct dmabuf *dmabuf = &state->dmabuf;
1361 unsigned long flags;
1362 unsigned long tmo;
1363 int count;
1364
1365 if (!dmabuf->ready)
1366 return 0;
1367 if(dmabuf->mapped) {
1368 stop_dac(state);
1369 return 0;
1370 }
1371
1372 spin_lock_irqsave(&state->card->lock, flags);
1373
1374 fill_partial_frag(dmabuf);
1375
1376 /*
1377 * This will make sure that our LVI is correct, that our
1378 * pointer is updated, and that the DAC is running. We
1379 * have to force the setting of dmabuf->trigger to avoid
1380 * any possible deadlocks.
1381 */
1382 dmabuf->trigger = PCM_ENABLE_OUTPUT;
1383 __i810_update_lvi(state, 0);
1384
1385 spin_unlock_irqrestore(&state->card->lock, flags);
1386
1387 add_wait_queue(&dmabuf->wait, &wait);
1388 for (;;) {
1389
1390 spin_lock_irqsave(&state->card->lock, flags);
1391 i810_update_ptr(state);
1392 count = dmabuf->count;
1393
1394 /* It seems that we have to set the current state to
1395 * TASK_INTERRUPTIBLE every time to make the process
1396 * really go to sleep. This also has to be *after* the
1397 * update_ptr() call because update_ptr is likely to
1398 * do a wake_up() which will unset this before we ever
1399 * try to sleep, resuling in a tight loop in this code
1400 * instead of actually sleeping and waiting for an
1401 * interrupt to wake us up!
1402 */
1403 __set_current_state(signals_allowed ?
1404 TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
1405 spin_unlock_irqrestore(&state->card->lock, flags);
1406
1407 if (count <= 0)
1408 break;
1409
1410 if (signal_pending(current) && signals_allowed) {
1411 break;
1412 }
1413
1414 /*
1415 * set the timeout to significantly longer than it *should*
1416 * take for the DAC to drain the DMA buffer
1417 */
1418 tmo = (count * HZ) / (dmabuf->rate);
1419 if (!schedule_timeout(tmo >= 2 ? tmo : 2)){
1420 printk(KERN_ERR "i810_audio: drain_dac, dma timeout?\n");
1421 count = 0;
1422 break;
1423 }
1424 }
1425 set_current_state(TASK_RUNNING);
1426 remove_wait_queue(&dmabuf->wait, &wait);
1427 if(count > 0 && signal_pending(current) && signals_allowed)
1428 return -ERESTARTSYS;
1429 stop_dac(state);
1430 return 0;
1431}
1432
1433static void i810_channel_interrupt(struct i810_card *card)
1434{
1435 int i, count;
1436
1437#ifdef DEBUG_INTERRUPTS
1438 printk("CHANNEL ");
1439#endif
1440 for(i=0;i<NR_HW_CH;i++)
1441 {
1442 struct i810_state *state = card->states[i];
1443 struct i810_channel *c;
1444 struct dmabuf *dmabuf;
1445 unsigned long port;
1446 u16 status;
1447
1448 if(!state)
1449 continue;
1450 if(!state->dmabuf.ready)
1451 continue;
1452 dmabuf = &state->dmabuf;
1453 if(dmabuf->enable & DAC_RUNNING) {
1454 c=dmabuf->write_channel;
1455 } else if(dmabuf->enable & ADC_RUNNING) {
1456 c=dmabuf->read_channel;
1457 } else /* This can occur going from R/W to close */
1458 continue;
1459
1460 port = c->port;
1461
1462 if(card->pci_id == PCI_DEVICE_ID_SI_7012)
1463 status = I810_IOREADW(card, port + OFF_PICB);
1464 else
1465 status = I810_IOREADW(card, port + OFF_SR);
1466
1467#ifdef DEBUG_INTERRUPTS
1468 printk("NUM %d PORT %X IRQ ( ST%d ", c->num, c->port, status);
1469#endif
1470 if(status & DMA_INT_COMPLETE)
1471 {
1472 /* only wake_up() waiters if this interrupt signals
1473 * us being beyond a userfragsize of data open or
1474 * available, and i810_update_ptr() does that for
1475 * us
1476 */
1477 i810_update_ptr(state);
1478#ifdef DEBUG_INTERRUPTS
1479 printk("COMP %d ", dmabuf->hwptr /
1480 dmabuf->fragsize);
1481#endif
1482 }
1483 if(status & (DMA_INT_LVI | DMA_INT_DCH))
1484 {
1485 /* wake_up() unconditionally on LVI and DCH */
1486 i810_update_ptr(state);
1487 wake_up(&dmabuf->wait);
1488#ifdef DEBUG_INTERRUPTS
1489 if(status & DMA_INT_LVI)
1490 printk("LVI ");
1491 if(status & DMA_INT_DCH)
1492 printk("DCH -");
1493#endif
1494 count = dmabuf->count;
1495 if(dmabuf->enable & ADC_RUNNING)
1496 count = dmabuf->dmasize - count;
1497 if (count >= (int)dmabuf->fragsize) {
1498 I810_IOWRITEB(I810_IOREADB(card, port+OFF_CR) | 1, card, port+OFF_CR);
1499#ifdef DEBUG_INTERRUPTS
1500 printk(" CONTINUE ");
1501#endif
1502 } else {
1503 if (dmabuf->enable & DAC_RUNNING)
1504 __stop_dac(state);
1505 if (dmabuf->enable & ADC_RUNNING)
1506 __stop_adc(state);
1507 dmabuf->enable = 0;
1508#ifdef DEBUG_INTERRUPTS
1509 printk(" STOP ");
1510#endif
1511 }
1512 }
1513 if(card->pci_id == PCI_DEVICE_ID_SI_7012)
1514 I810_IOWRITEW(status & DMA_INT_MASK, card, port + OFF_PICB);
1515 else
1516 I810_IOWRITEW(status & DMA_INT_MASK, card, port + OFF_SR);
1517 }
1518#ifdef DEBUG_INTERRUPTS
1519 printk(")\n");
1520#endif
1521}
1522
1523static irqreturn_t i810_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1524{
1525 struct i810_card *card = (struct i810_card *)dev_id;
1526 u32 status;
1527
1528 spin_lock(&card->lock);
1529
1530 status = I810_IOREADL(card, GLOB_STA);
1531
1532 if(!(status & INT_MASK))
1533 {
1534 spin_unlock(&card->lock);
1535 return IRQ_NONE; /* not for us */
1536 }
1537
1538 if(status & (INT_PO|INT_PI|INT_MC))
1539 i810_channel_interrupt(card);
1540
1541 /* clear 'em */
1542 I810_IOWRITEL(status & INT_MASK, card, GLOB_STA);
1543 spin_unlock(&card->lock);
1544 return IRQ_HANDLED;
1545}
1546
1547/* in this loop, dmabuf.count signifies the amount of data that is
1548 waiting to be copied to the user's buffer. It is filled by the dma
1549 machine and drained by this loop. */
1550
1551static ssize_t i810_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1552{
1553 struct i810_state *state = (struct i810_state *)file->private_data;
1554 struct i810_card *card=state ? state->card : NULL;
1555 struct dmabuf *dmabuf = &state->dmabuf;
1556 ssize_t ret;
1557 unsigned long flags;
1558 unsigned int swptr;
1559 int cnt;
1560 int pending;
1561 DECLARE_WAITQUEUE(waita, current);
1562
1563#ifdef DEBUG2
1564 printk("i810_audio: i810_read called, count = %d\n", count);
1565#endif
1566
1567 if (dmabuf->mapped)
1568 return -ENXIO;
1569 if (dmabuf->enable & DAC_RUNNING)
1570 return -ENODEV;
1571 if (!dmabuf->read_channel) {
1572 dmabuf->ready = 0;
1573 dmabuf->read_channel = card->alloc_rec_pcm_channel(card);
1574 if (!dmabuf->read_channel) {
1575 return -EBUSY;
1576 }
1577 }
1578 if (!dmabuf->ready && (ret = prog_dmabuf(state, 1)))
1579 return ret;
1580 if (!access_ok(VERIFY_WRITE, buffer, count))
1581 return -EFAULT;
1582 ret = 0;
1583
1584 pending = 0;
1585
1586 add_wait_queue(&dmabuf->wait, &waita);
1587 while (count > 0) {
1588 set_current_state(TASK_INTERRUPTIBLE);
1589 spin_lock_irqsave(&card->lock, flags);
1590 if (PM_SUSPENDED(card)) {
1591 spin_unlock_irqrestore(&card->lock, flags);
1592 schedule();
1593 if (signal_pending(current)) {
1594 if (!ret) ret = -EAGAIN;
1595 break;
1596 }
1597 continue;
1598 }
1599 cnt = i810_get_available_read_data(state);
1600 swptr = dmabuf->swptr;
1601 // this is to make the copy_to_user simpler below
1602 if(cnt > (dmabuf->dmasize - swptr))
1603 cnt = dmabuf->dmasize - swptr;
1604 spin_unlock_irqrestore(&card->lock, flags);
1605
1606 if (cnt > count)
1607 cnt = count;
1608 if (cnt <= 0) {
1609 unsigned long tmo;
1610 /*
1611 * Don't let us deadlock. The ADC won't start if
1612 * dmabuf->trigger isn't set. A call to SETTRIGGER
1613 * could have turned it off after we set it to on
1614 * previously.
1615 */
1616 dmabuf->trigger = PCM_ENABLE_INPUT;
1617 /*
1618 * This does three things. Updates LVI to be correct,
1619 * makes sure the ADC is running, and updates the
1620 * hwptr.
1621 */
1622 i810_update_lvi(state,1);
1623 if (file->f_flags & O_NONBLOCK) {
1624 if (!ret) ret = -EAGAIN;
1625 goto done;
1626 }
1627 /* Set the timeout to how long it would take to fill
1628 * two of our buffers. If we haven't been woke up
1629 * by then, then we know something is wrong.
1630 */
1631 tmo = (dmabuf->dmasize * HZ * 2) / (dmabuf->rate * 4);
1632 /* There are two situations when sleep_on_timeout returns, one is when
1633 the interrupt is serviced correctly and the process is waked up by
1634 ISR ON TIME. Another is when timeout is expired, which means that
1635 either interrupt is NOT serviced correctly (pending interrupt) or it
1636 is TOO LATE for the process to be scheduled to run (scheduler latency)
1637 which results in a (potential) buffer overrun. And worse, there is
1638 NOTHING we can do to prevent it. */
1639 if (!schedule_timeout(tmo >= 2 ? tmo : 2)) {
1640#ifdef DEBUG
1641 printk(KERN_ERR "i810_audio: recording schedule timeout, "
1642 "dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1643 dmabuf->dmasize, dmabuf->fragsize, dmabuf->count,
1644 dmabuf->hwptr, dmabuf->swptr);
1645#endif
1646 /* a buffer overrun, we delay the recovery until next time the
1647 while loop begin and we REALLY have space to record */
1648 }
1649 if (signal_pending(current)) {
1650 ret = ret ? ret : -ERESTARTSYS;
1651 goto done;
1652 }
1653 continue;
1654 }
1655
1656 if (copy_to_user(buffer, dmabuf->rawbuf + swptr, cnt)) {
1657 if (!ret) ret = -EFAULT;
1658 goto done;
1659 }
1660
1661 swptr = MODULOP2(swptr + cnt, dmabuf->dmasize);
1662
1663 spin_lock_irqsave(&card->lock, flags);
1664
1665 if (PM_SUSPENDED(card)) {
1666 spin_unlock_irqrestore(&card->lock, flags);
1667 continue;
1668 }
1669 dmabuf->swptr = swptr;
1670 pending = dmabuf->count -= cnt;
1671 spin_unlock_irqrestore(&card->lock, flags);
1672
1673 count -= cnt;
1674 buffer += cnt;
1675 ret += cnt;
1676 }
1677 done:
1678 pending = dmabuf->dmasize - pending;
1679 if (dmabuf->enable || pending >= dmabuf->userfragsize)
1680 i810_update_lvi(state, 1);
1681 set_current_state(TASK_RUNNING);
1682 remove_wait_queue(&dmabuf->wait, &waita);
1683
1684 return ret;
1685}
1686
1687/* in this loop, dmabuf.count signifies the amount of data that is waiting to be dma to
1688 the soundcard. it is drained by the dma machine and filled by this loop. */
1689static ssize_t i810_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1690{
1691 struct i810_state *state = (struct i810_state *)file->private_data;
1692 struct i810_card *card=state ? state->card : NULL;
1693 struct dmabuf *dmabuf = &state->dmabuf;
1694 ssize_t ret;
1695 unsigned long flags;
1696 unsigned int swptr = 0;
1697 int pending;
1698 int cnt;
1699 DECLARE_WAITQUEUE(waita, current);
1700
1701#ifdef DEBUG2
1702 printk("i810_audio: i810_write called, count = %d\n", count);
1703#endif
1704
1705 if (dmabuf->mapped)
1706 return -ENXIO;
1707 if (dmabuf->enable & ADC_RUNNING)
1708 return -ENODEV;
1709 if (!dmabuf->write_channel) {
1710 dmabuf->ready = 0;
1711 dmabuf->write_channel = card->alloc_pcm_channel(card);
1712 if(!dmabuf->write_channel)
1713 return -EBUSY;
1714 }
1715 if (!dmabuf->ready && (ret = prog_dmabuf(state, 0)))
1716 return ret;
1717 if (!access_ok(VERIFY_READ, buffer, count))
1718 return -EFAULT;
1719 ret = 0;
1720
1721 pending = 0;
1722
1723 add_wait_queue(&dmabuf->wait, &waita);
1724 while (count > 0) {
1725 set_current_state(TASK_INTERRUPTIBLE);
1726 spin_lock_irqsave(&state->card->lock, flags);
1727 if (PM_SUSPENDED(card)) {
1728 spin_unlock_irqrestore(&card->lock, flags);
1729 schedule();
1730 if (signal_pending(current)) {
1731 if (!ret) ret = -EAGAIN;
1732 break;
1733 }
1734 continue;
1735 }
1736
1737 cnt = i810_get_free_write_space(state);
1738 swptr = dmabuf->swptr;
1739 /* Bound the maximum size to how much we can copy to the
1740 * dma buffer before we hit the end. If we have more to
1741 * copy then it will get done in a second pass of this
1742 * loop starting from the beginning of the buffer.
1743 */
1744 if(cnt > (dmabuf->dmasize - swptr))
1745 cnt = dmabuf->dmasize - swptr;
1746 spin_unlock_irqrestore(&state->card->lock, flags);
1747
1748#ifdef DEBUG2
1749 printk(KERN_INFO "i810_audio: i810_write: %d bytes available space\n", cnt);
1750#endif
1751 if (cnt > count)
1752 cnt = count;
1753 if (cnt <= 0) {
1754 unsigned long tmo;
1755 // There is data waiting to be played
1756 /*
1757 * Force the trigger setting since we would
1758 * deadlock with it set any other way
1759 */
1760 dmabuf->trigger = PCM_ENABLE_OUTPUT;
1761 i810_update_lvi(state,0);
1762 if (file->f_flags & O_NONBLOCK) {
1763 if (!ret) ret = -EAGAIN;
1764 goto ret;
1765 }
1766 /* Not strictly correct but works */
1767 tmo = (dmabuf->dmasize * HZ * 2) / (dmabuf->rate * 4);
1768 /* There are two situations when sleep_on_timeout returns, one is when
1769 the interrupt is serviced correctly and the process is waked up by
1770 ISR ON TIME. Another is when timeout is expired, which means that
1771 either interrupt is NOT serviced correctly (pending interrupt) or it
1772 is TOO LATE for the process to be scheduled to run (scheduler latency)
1773 which results in a (potential) buffer underrun. And worse, there is
1774 NOTHING we can do to prevent it. */
1775 if (!schedule_timeout(tmo >= 2 ? tmo : 2)) {
1776#ifdef DEBUG
1777 printk(KERN_ERR "i810_audio: playback schedule timeout, "
1778 "dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1779 dmabuf->dmasize, dmabuf->fragsize, dmabuf->count,
1780 dmabuf->hwptr, dmabuf->swptr);
1781#endif
1782 /* a buffer underrun, we delay the recovery until next time the
1783 while loop begin and we REALLY have data to play */
1784 //return ret;
1785 }
1786 if (signal_pending(current)) {
1787 if (!ret) ret = -ERESTARTSYS;
1788 goto ret;
1789 }
1790 continue;
1791 }
1792 if (copy_from_user(dmabuf->rawbuf+swptr,buffer,cnt)) {
1793 if (!ret) ret = -EFAULT;
1794 goto ret;
1795 }
1796
1797 swptr = MODULOP2(swptr + cnt, dmabuf->dmasize);
1798
1799 spin_lock_irqsave(&state->card->lock, flags);
1800 if (PM_SUSPENDED(card)) {
1801 spin_unlock_irqrestore(&card->lock, flags);
1802 continue;
1803 }
1804
1805 dmabuf->swptr = swptr;
1806 pending = dmabuf->count += cnt;
1807
1808 count -= cnt;
1809 buffer += cnt;
1810 ret += cnt;
1811 spin_unlock_irqrestore(&state->card->lock, flags);
1812 }
1813ret:
1814 if (dmabuf->enable || pending >= dmabuf->userfragsize)
1815 i810_update_lvi(state, 0);
1816 set_current_state(TASK_RUNNING);
1817 remove_wait_queue(&dmabuf->wait, &waita);
1818
1819 return ret;
1820}
1821
1822/* No kernel lock - we have our own spinlock */
1823static unsigned int i810_poll(struct file *file, struct poll_table_struct *wait)
1824{
1825 struct i810_state *state = (struct i810_state *)file->private_data;
1826 struct dmabuf *dmabuf = &state->dmabuf;
1827 unsigned long flags;
1828 unsigned int mask = 0;
1829
1830 if(!dmabuf->ready)
1831 return 0;
1832 poll_wait(file, &dmabuf->wait, wait);
1833 spin_lock_irqsave(&state->card->lock, flags);
1834 if (dmabuf->enable & ADC_RUNNING ||
1835 dmabuf->trigger & PCM_ENABLE_INPUT) {
1836 if (i810_get_available_read_data(state) >=
1837 (signed)dmabuf->userfragsize)
1838 mask |= POLLIN | POLLRDNORM;
1839 }
1840 if (dmabuf->enable & DAC_RUNNING ||
1841 dmabuf->trigger & PCM_ENABLE_OUTPUT) {
1842 if (i810_get_free_write_space(state) >=
1843 (signed)dmabuf->userfragsize)
1844 mask |= POLLOUT | POLLWRNORM;
1845 }
1846 spin_unlock_irqrestore(&state->card->lock, flags);
1847 return mask;
1848}
1849
1850static int i810_mmap(struct file *file, struct vm_area_struct *vma)
1851{
1852 struct i810_state *state = (struct i810_state *)file->private_data;
1853 struct dmabuf *dmabuf = &state->dmabuf;
1854 int ret = -EINVAL;
1855 unsigned long size;
1856
1857 lock_kernel();
1858 if (vma->vm_flags & VM_WRITE) {
1859 if (!dmabuf->write_channel &&
1860 (dmabuf->write_channel =
1861 state->card->alloc_pcm_channel(state->card)) == NULL) {
1862 ret = -EBUSY;
1863 goto out;
1864 }
1865 }
1866 if (vma->vm_flags & VM_READ) {
1867 if (!dmabuf->read_channel &&
1868 (dmabuf->read_channel =
1869 state->card->alloc_rec_pcm_channel(state->card)) == NULL) {
1870 ret = -EBUSY;
1871 goto out;
1872 }
1873 }
1874 if ((ret = prog_dmabuf(state, 0)) != 0)
1875 goto out;
1876
1877 ret = -EINVAL;
1878 if (vma->vm_pgoff != 0)
1879 goto out;
1880 size = vma->vm_end - vma->vm_start;
1881 if (size > (PAGE_SIZE << dmabuf->buforder))
1882 goto out;
1883 ret = -EAGAIN;
1884 if (remap_pfn_range(vma, vma->vm_start,
1885 virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT,
1886 size, vma->vm_page_prot))
1887 goto out;
1888 dmabuf->mapped = 1;
1889 dmabuf->trigger = 0;
1890 ret = 0;
1891#ifdef DEBUG_MMAP
1892 printk("i810_audio: mmap'ed %ld bytes of data space\n", size);
1893#endif
1894out:
1895 unlock_kernel();
1896 return ret;
1897}
1898
1899static int i810_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1900{
1901 struct i810_state *state = (struct i810_state *)file->private_data;
1902 struct i810_channel *c = NULL;
1903 struct dmabuf *dmabuf = &state->dmabuf;
1904 unsigned long flags;
1905 audio_buf_info abinfo;
1906 count_info cinfo;
1907 unsigned int i_glob_cnt;
1908 int val = 0, ret;
1909 struct ac97_codec *codec = state->card->ac97_codec[0];
1910 void __user *argp = (void __user *)arg;
1911 int __user *p = argp;
1912
1913#ifdef DEBUG
1914 printk("i810_audio: i810_ioctl, arg=0x%x, cmd=", arg ? *p : 0);
1915#endif
1916
1917 switch (cmd)
1918 {
1919 case OSS_GETVERSION:
1920#ifdef DEBUG
1921 printk("OSS_GETVERSION\n");
1922#endif
1923 return put_user(SOUND_VERSION, p);
1924
1925 case SNDCTL_DSP_RESET:
1926#ifdef DEBUG
1927 printk("SNDCTL_DSP_RESET\n");
1928#endif
1929 spin_lock_irqsave(&state->card->lock, flags);
1930 if (dmabuf->enable == DAC_RUNNING) {
1931 c = dmabuf->write_channel;
1932 __stop_dac(state);
1933 }
1934 if (dmabuf->enable == ADC_RUNNING) {
1935 c = dmabuf->read_channel;
1936 __stop_adc(state);
1937 }
1938 if (c != NULL) {
1939 I810_IOWRITEB(2, state->card, c->port+OFF_CR); /* reset DMA machine */
1940 while ( I810_IOREADB(state->card, c->port+OFF_CR) & 2 )
1941 cpu_relax();
1942 I810_IOWRITEL((u32)state->card->chandma +
1943 c->num*sizeof(struct i810_channel),
1944 state->card, c->port+OFF_BDBAR);
1945 CIV_TO_LVI(state->card, c->port, 0);
1946 }
1947
1948 spin_unlock_irqrestore(&state->card->lock, flags);
1949 synchronize_irq(state->card->pci_dev->irq);
1950 dmabuf->ready = 0;
1951 dmabuf->swptr = dmabuf->hwptr = 0;
1952 dmabuf->count = dmabuf->total_bytes = 0;
1953 return 0;
1954
1955 case SNDCTL_DSP_SYNC:
1956#ifdef DEBUG
1957 printk("SNDCTL_DSP_SYNC\n");
1958#endif
1959 if (dmabuf->enable != DAC_RUNNING || file->f_flags & O_NONBLOCK)
1960 return 0;
1961 if((val = drain_dac(state, 1)))
1962 return val;
1963 dmabuf->total_bytes = 0;
1964 return 0;
1965
1966 case SNDCTL_DSP_SPEED: /* set smaple rate */
1967#ifdef DEBUG
1968 printk("SNDCTL_DSP_SPEED\n");
1969#endif
1970 if (get_user(val, p))
1971 return -EFAULT;
1972 if (val >= 0) {
1973 if (file->f_mode & FMODE_WRITE) {
1974 if ( (state->card->ac97_status & SPDIF_ON) ) { /* S/PDIF Enabled */
1975 /* AD1886 only supports 48000, need to check that */
1976 if ( i810_valid_spdif_rate ( codec, val ) ) {
1977 /* Set DAC rate */
1978 i810_set_spdif_output ( state, -1, 0 );
1979 stop_dac(state);
1980 dmabuf->ready = 0;
1981 spin_lock_irqsave(&state->card->lock, flags);
1982 i810_set_dac_rate(state, val);
1983 spin_unlock_irqrestore(&state->card->lock, flags);
1984 /* Set S/PDIF transmitter rate. */
1985 i810_set_spdif_output ( state, AC97_EA_SPSA_3_4, val );
1986 if ( ! (state->card->ac97_status & SPDIF_ON) ) {
1987 val = dmabuf->rate;
1988 }
1989 } else { /* Not a valid rate for S/PDIF, ignore it */
1990 val = dmabuf->rate;
1991 }
1992 } else {
1993 stop_dac(state);
1994 dmabuf->ready = 0;
1995 spin_lock_irqsave(&state->card->lock, flags);
1996 i810_set_dac_rate(state, val);
1997 spin_unlock_irqrestore(&state->card->lock, flags);
1998 }
1999 }
2000 if (file->f_mode & FMODE_READ) {
2001 stop_adc(state);
2002 dmabuf->ready = 0;
2003 spin_lock_irqsave(&state->card->lock, flags);
2004 i810_set_adc_rate(state, val);
2005 spin_unlock_irqrestore(&state->card->lock, flags);
2006 }
2007 }
2008 return put_user(dmabuf->rate, p);
2009
2010 case SNDCTL_DSP_STEREO: /* set stereo or mono channel */
2011#ifdef DEBUG
2012 printk("SNDCTL_DSP_STEREO\n");
2013#endif
2014 if (dmabuf->enable & DAC_RUNNING) {
2015 stop_dac(state);
2016 }
2017 if (dmabuf->enable & ADC_RUNNING) {
2018 stop_adc(state);
2019 }
2020 return put_user(1, p);
2021
2022 case SNDCTL_DSP_GETBLKSIZE:
2023 if (file->f_mode & FMODE_WRITE) {
2024 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)))
2025 return val;
2026 }
2027 if (file->f_mode & FMODE_READ) {
2028 if (!dmabuf->ready && (val = prog_dmabuf(state, 1)))
2029 return val;
2030 }
2031#ifdef DEBUG
2032 printk("SNDCTL_DSP_GETBLKSIZE %d\n", dmabuf->userfragsize);
2033#endif
2034 return put_user(dmabuf->userfragsize, p);
2035
2036 case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format*/
2037#ifdef DEBUG
2038 printk("SNDCTL_DSP_GETFMTS\n");
2039#endif
2040 return put_user(AFMT_S16_LE, p);
2041
2042 case SNDCTL_DSP_SETFMT: /* Select sample format */
2043#ifdef DEBUG
2044 printk("SNDCTL_DSP_SETFMT\n");
2045#endif
2046 return put_user(AFMT_S16_LE, p);
2047
2048 case SNDCTL_DSP_CHANNELS:
2049#ifdef DEBUG
2050 printk("SNDCTL_DSP_CHANNELS\n");
2051#endif
2052 if (get_user(val, p))
2053 return -EFAULT;
2054
2055 if (val > 0) {
2056 if (dmabuf->enable & DAC_RUNNING) {
2057 stop_dac(state);
2058 }
2059 if (dmabuf->enable & ADC_RUNNING) {
2060 stop_adc(state);
2061 }
2062 } else {
2063 return put_user(state->card->channels, p);
2064 }
2065
2066 /* ICH and ICH0 only support 2 channels */
2067 if ( state->card->pci_id == PCI_DEVICE_ID_INTEL_82801AA_5
2068 || state->card->pci_id == PCI_DEVICE_ID_INTEL_82801AB_5)
2069 return put_user(2, p);
2070
2071 /* Multi-channel support was added with ICH2. Bits in */
2072 /* Global Status and Global Control register are now */
2073 /* used to indicate this. */
2074
2075 i_glob_cnt = I810_IOREADL(state->card, GLOB_CNT);
2076
2077 /* Current # of channels enabled */
2078 if ( i_glob_cnt & 0x0100000 )
2079 ret = 4;
2080 else if ( i_glob_cnt & 0x0200000 )
2081 ret = 6;
2082 else
2083 ret = 2;
2084
2085 switch ( val ) {
2086 case 2: /* 2 channels is always supported */
2087 I810_IOWRITEL(i_glob_cnt & 0xffcfffff,
2088 state->card, GLOB_CNT);
2089 /* Do we need to change mixer settings???? */
2090 break;
2091 case 4: /* Supported on some chipsets, better check first */
2092 if ( state->card->channels >= 4 ) {
2093 I810_IOWRITEL((i_glob_cnt & 0xffcfffff) | 0x100000,
2094 state->card, GLOB_CNT);
2095 /* Do we need to change mixer settings??? */
2096 } else {
2097 val = ret;
2098 }
2099 break;
2100 case 6: /* Supported on some chipsets, better check first */
2101 if ( state->card->channels >= 6 ) {
2102 I810_IOWRITEL((i_glob_cnt & 0xffcfffff) | 0x200000,
2103 state->card, GLOB_CNT);
2104 /* Do we need to change mixer settings??? */
2105 } else {
2106 val = ret;
2107 }
2108 break;
2109 default: /* nothing else is ever supported by the chipset */
2110 val = ret;
2111 break;
2112 }
2113
2114 return put_user(val, p);
2115
2116 case SNDCTL_DSP_POST: /* the user has sent all data and is notifying us */
2117 /* we update the swptr to the end of the last sg segment then return */
2118#ifdef DEBUG
2119 printk("SNDCTL_DSP_POST\n");
2120#endif
2121 if(!dmabuf->ready || (dmabuf->enable != DAC_RUNNING))
2122 return 0;
2123 if((dmabuf->swptr % dmabuf->fragsize) != 0) {
2124 val = dmabuf->fragsize - (dmabuf->swptr % dmabuf->fragsize);
2125 dmabuf->swptr += val;
2126 dmabuf->count += val;
2127 }
2128 return 0;
2129
2130 case SNDCTL_DSP_SUBDIVIDE:
2131 if (dmabuf->subdivision)
2132 return -EINVAL;
2133 if (get_user(val, p))
2134 return -EFAULT;
2135 if (val != 1 && val != 2 && val != 4)
2136 return -EINVAL;
2137#ifdef DEBUG
2138 printk("SNDCTL_DSP_SUBDIVIDE %d\n", val);
2139#endif
2140 dmabuf->subdivision = val;
2141 dmabuf->ready = 0;
2142 return 0;
2143
2144 case SNDCTL_DSP_SETFRAGMENT:
2145 if (get_user(val, p))
2146 return -EFAULT;
2147
2148 dmabuf->ossfragsize = 1<<(val & 0xffff);
2149 dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
2150 if (!dmabuf->ossfragsize || !dmabuf->ossmaxfrags)
2151 return -EINVAL;
2152 /*
2153 * Bound the frag size into our allowed range of 256 - 4096
2154 */
2155 if (dmabuf->ossfragsize < 256)
2156 dmabuf->ossfragsize = 256;
2157 else if (dmabuf->ossfragsize > 4096)
2158 dmabuf->ossfragsize = 4096;
2159 /*
2160 * The numfrags could be something reasonable, or it could
2161 * be 0xffff meaning "Give me as much as possible". So,
2162 * we check the numfrags * fragsize doesn't exceed our
2163 * 64k buffer limit, nor is it less than our 8k minimum.
2164 * If it fails either one of these checks, then adjust the
2165 * number of fragments, not the size of them. It's OK if
2166 * our number of fragments doesn't equal 32 or anything
2167 * like our hardware based number now since we are using
2168 * a different frag count for the hardware. Before we get
2169 * into this though, bound the maxfrags to avoid overflow
2170 * issues. A reasonable bound would be 64k / 256 since our
2171 * maximum buffer size is 64k and our minimum frag size is
2172 * 256. On the other end, our minimum buffer size is 8k and
2173 * our maximum frag size is 4k, so the lower bound should
2174 * be 2.
2175 */
2176
2177 if(dmabuf->ossmaxfrags > 256)
2178 dmabuf->ossmaxfrags = 256;
2179 else if (dmabuf->ossmaxfrags < 2)
2180 dmabuf->ossmaxfrags = 2;
2181
2182 val = dmabuf->ossfragsize * dmabuf->ossmaxfrags;
2183 while (val < 8192) {
2184 val <<= 1;
2185 dmabuf->ossmaxfrags <<= 1;
2186 }
2187 while (val > 65536) {
2188 val >>= 1;
2189 dmabuf->ossmaxfrags >>= 1;
2190 }
2191 dmabuf->ready = 0;
2192#ifdef DEBUG
2193 printk("SNDCTL_DSP_SETFRAGMENT 0x%x, %d, %d\n", val,
2194 dmabuf->ossfragsize, dmabuf->ossmaxfrags);
2195#endif
2196
2197 return 0;
2198
2199 case SNDCTL_DSP_GETOSPACE:
2200 if (!(file->f_mode & FMODE_WRITE))
2201 return -EINVAL;
2202 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
2203 return val;
2204 spin_lock_irqsave(&state->card->lock, flags);
2205 i810_update_ptr(state);
2206 abinfo.fragsize = dmabuf->userfragsize;
2207 abinfo.fragstotal = dmabuf->userfrags;
2208 if (dmabuf->mapped)
2209 abinfo.bytes = dmabuf->dmasize;
2210 else
2211 abinfo.bytes = i810_get_free_write_space(state);
2212 abinfo.fragments = abinfo.bytes / dmabuf->userfragsize;
2213 spin_unlock_irqrestore(&state->card->lock, flags);
2214#if defined(DEBUG) || defined(DEBUG_MMAP)
2215 printk("SNDCTL_DSP_GETOSPACE %d, %d, %d, %d\n", abinfo.bytes,
2216 abinfo.fragsize, abinfo.fragments, abinfo.fragstotal);
2217#endif
2218 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2219
2220 case SNDCTL_DSP_GETOPTR:
2221 if (!(file->f_mode & FMODE_WRITE))
2222 return -EINVAL;
2223 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
2224 return val;
2225 spin_lock_irqsave(&state->card->lock, flags);
2226 val = i810_get_free_write_space(state);
2227 cinfo.bytes = dmabuf->total_bytes;
2228 cinfo.ptr = dmabuf->hwptr;
2229 cinfo.blocks = val/dmabuf->userfragsize;
2230 if (dmabuf->mapped && (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
2231 dmabuf->count += val;
2232 dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
2233 __i810_update_lvi(state, 0);
2234 }
2235 spin_unlock_irqrestore(&state->card->lock, flags);
2236#if defined(DEBUG) || defined(DEBUG_MMAP)
2237 printk("SNDCTL_DSP_GETOPTR %d, %d, %d, %d\n", cinfo.bytes,
2238 cinfo.blocks, cinfo.ptr, dmabuf->count);
2239#endif
2240 return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2241
2242 case SNDCTL_DSP_GETISPACE:
2243 if (!(file->f_mode & FMODE_READ))
2244 return -EINVAL;
2245 if (!dmabuf->ready && (val = prog_dmabuf(state, 1)) != 0)
2246 return val;
2247 spin_lock_irqsave(&state->card->lock, flags);
2248 abinfo.bytes = i810_get_available_read_data(state);
2249 abinfo.fragsize = dmabuf->userfragsize;
2250 abinfo.fragstotal = dmabuf->userfrags;
2251 abinfo.fragments = abinfo.bytes / dmabuf->userfragsize;
2252 spin_unlock_irqrestore(&state->card->lock, flags);
2253#if defined(DEBUG) || defined(DEBUG_MMAP)
2254 printk("SNDCTL_DSP_GETISPACE %d, %d, %d, %d\n", abinfo.bytes,
2255 abinfo.fragsize, abinfo.fragments, abinfo.fragstotal);
2256#endif
2257 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2258
2259 case SNDCTL_DSP_GETIPTR:
2260 if (!(file->f_mode & FMODE_READ))
2261 return -EINVAL;
2262 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
2263 return val;
2264 spin_lock_irqsave(&state->card->lock, flags);
2265 val = i810_get_available_read_data(state);
2266 cinfo.bytes = dmabuf->total_bytes;
2267 cinfo.blocks = val/dmabuf->userfragsize;
2268 cinfo.ptr = dmabuf->hwptr;
2269 if (dmabuf->mapped && (dmabuf->trigger & PCM_ENABLE_INPUT)) {
2270 dmabuf->count -= val;
2271 dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
2272 __i810_update_lvi(state, 1);
2273 }
2274 spin_unlock_irqrestore(&state->card->lock, flags);
2275#if defined(DEBUG) || defined(DEBUG_MMAP)
2276 printk("SNDCTL_DSP_GETIPTR %d, %d, %d, %d\n", cinfo.bytes,
2277 cinfo.blocks, cinfo.ptr, dmabuf->count);
2278#endif
2279 return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2280
2281 case SNDCTL_DSP_NONBLOCK:
2282#ifdef DEBUG
2283 printk("SNDCTL_DSP_NONBLOCK\n");
2284#endif
2285 file->f_flags |= O_NONBLOCK;
2286 return 0;
2287
2288 case SNDCTL_DSP_GETCAPS:
2289#ifdef DEBUG
2290 printk("SNDCTL_DSP_GETCAPS\n");
2291#endif
2292 return put_user(DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP|DSP_CAP_BIND,
2293 p);
2294
2295 case SNDCTL_DSP_GETTRIGGER:
2296 val = 0;
2297#ifdef DEBUG
2298 printk("SNDCTL_DSP_GETTRIGGER 0x%x\n", dmabuf->trigger);
2299#endif
2300 return put_user(dmabuf->trigger, p);
2301
2302 case SNDCTL_DSP_SETTRIGGER:
2303 if (get_user(val, p))
2304 return -EFAULT;
2305#if defined(DEBUG) || defined(DEBUG_MMAP)
2306 printk("SNDCTL_DSP_SETTRIGGER 0x%x\n", val);
2307#endif
2308 /* silently ignore invalid PCM_ENABLE_xxx bits,
2309 * like the other drivers do
2310 */
2311 if (!(file->f_mode & FMODE_READ ))
2312 val &= ~PCM_ENABLE_INPUT;
2313 if (!(file->f_mode & FMODE_WRITE ))
2314 val &= ~PCM_ENABLE_OUTPUT;
2315 if((file->f_mode & FMODE_READ) && !(val & PCM_ENABLE_INPUT) && dmabuf->enable == ADC_RUNNING) {
2316 stop_adc(state);
2317 }
2318 if((file->f_mode & FMODE_WRITE) && !(val & PCM_ENABLE_OUTPUT) && dmabuf->enable == DAC_RUNNING) {
2319 stop_dac(state);
2320 }
2321 dmabuf->trigger = val;
2322 if((val & PCM_ENABLE_OUTPUT) && !(dmabuf->enable & DAC_RUNNING)) {
2323 if (!dmabuf->write_channel) {
2324 dmabuf->ready = 0;
2325 dmabuf->write_channel = state->card->alloc_pcm_channel(state->card);
2326 if (!dmabuf->write_channel)
2327 return -EBUSY;
2328 }
2329 if (!dmabuf->ready && (ret = prog_dmabuf(state, 0)))
2330 return ret;
2331 if (dmabuf->mapped) {
2332 spin_lock_irqsave(&state->card->lock, flags);
2333 i810_update_ptr(state);
2334 dmabuf->count = 0;
2335 dmabuf->swptr = dmabuf->hwptr;
2336 dmabuf->count = i810_get_free_write_space(state);
2337 dmabuf->swptr = (dmabuf->swptr + dmabuf->count) % dmabuf->dmasize;
2338 spin_unlock_irqrestore(&state->card->lock, flags);
2339 }
2340 i810_update_lvi(state, 0);
2341 start_dac(state);
2342 }
2343 if((val & PCM_ENABLE_INPUT) && !(dmabuf->enable & ADC_RUNNING)) {
2344 if (!dmabuf->read_channel) {
2345 dmabuf->ready = 0;
2346 dmabuf->read_channel = state->card->alloc_rec_pcm_channel(state->card);
2347 if (!dmabuf->read_channel)
2348 return -EBUSY;
2349 }
2350 if (!dmabuf->ready && (ret = prog_dmabuf(state, 1)))
2351 return ret;
2352 if (dmabuf->mapped) {
2353 spin_lock_irqsave(&state->card->lock, flags);
2354 i810_update_ptr(state);
2355 dmabuf->swptr = dmabuf->hwptr;
2356 dmabuf->count = 0;
2357 spin_unlock_irqrestore(&state->card->lock, flags);
2358 }
2359 i810_update_lvi(state, 1);
2360 start_adc(state);
2361 }
2362 return 0;
2363
2364 case SNDCTL_DSP_SETDUPLEX:
2365#ifdef DEBUG
2366 printk("SNDCTL_DSP_SETDUPLEX\n");
2367#endif
2368 return -EINVAL;
2369
2370 case SNDCTL_DSP_GETODELAY:
2371 if (!(file->f_mode & FMODE_WRITE))
2372 return -EINVAL;
2373 spin_lock_irqsave(&state->card->lock, flags);
2374 i810_update_ptr(state);
2375 val = dmabuf->count;
2376 spin_unlock_irqrestore(&state->card->lock, flags);
2377#ifdef DEBUG
2378 printk("SNDCTL_DSP_GETODELAY %d\n", dmabuf->count);
2379#endif
2380 return put_user(val, p);
2381
2382 case SOUND_PCM_READ_RATE:
2383#ifdef DEBUG
2384 printk("SOUND_PCM_READ_RATE %d\n", dmabuf->rate);
2385#endif
2386 return put_user(dmabuf->rate, p);
2387
2388 case SOUND_PCM_READ_CHANNELS:
2389#ifdef DEBUG
2390 printk("SOUND_PCM_READ_CHANNELS\n");
2391#endif
2392 return put_user(2, p);
2393
2394 case SOUND_PCM_READ_BITS:
2395#ifdef DEBUG
2396 printk("SOUND_PCM_READ_BITS\n");
2397#endif
2398 return put_user(AFMT_S16_LE, p);
2399
2400 case SNDCTL_DSP_SETSPDIF: /* Set S/PDIF Control register */
2401#ifdef DEBUG
2402 printk("SNDCTL_DSP_SETSPDIF\n");
2403#endif
2404 if (get_user(val, p))
2405 return -EFAULT;
2406
2407 /* Check to make sure the codec supports S/PDIF transmitter */
2408
2409 if((state->card->ac97_features & 4)) {
2410 /* mask out the transmitter speed bits so the user can't set them */
2411 val &= ~0x3000;
2412
2413 /* Add the current transmitter speed bits to the passed value */
2414 ret = i810_ac97_get(codec, AC97_SPDIF_CONTROL);
2415 val |= (ret & 0x3000);
2416
2417 i810_ac97_set(codec, AC97_SPDIF_CONTROL, val);
2418 if(i810_ac97_get(codec, AC97_SPDIF_CONTROL) != val ) {
2419 printk(KERN_ERR "i810_audio: Unable to set S/PDIF configuration to 0x%04x.\n", val);
2420 return -EFAULT;
2421 }
2422 }
2423#ifdef DEBUG
2424 else
2425 printk(KERN_WARNING "i810_audio: S/PDIF transmitter not avalible.\n");
2426#endif
2427 return put_user(val, p);
2428
2429 case SNDCTL_DSP_GETSPDIF: /* Get S/PDIF Control register */
2430#ifdef DEBUG
2431 printk("SNDCTL_DSP_GETSPDIF\n");
2432#endif
2433 if (get_user(val, p))
2434 return -EFAULT;
2435
2436 /* Check to make sure the codec supports S/PDIF transmitter */
2437
2438 if(!(state->card->ac97_features & 4)) {
2439#ifdef DEBUG
2440 printk(KERN_WARNING "i810_audio: S/PDIF transmitter not avalible.\n");
2441#endif
2442 val = 0;
2443 } else {
2444 val = i810_ac97_get(codec, AC97_SPDIF_CONTROL);
2445 }
2446 //return put_user((val & 0xcfff), p);
2447 return put_user(val, p);
2448
2449 case SNDCTL_DSP_GETCHANNELMASK:
2450#ifdef DEBUG
2451 printk("SNDCTL_DSP_GETCHANNELMASK\n");
2452#endif
2453 if (get_user(val, p))
2454 return -EFAULT;
2455
2456 /* Based on AC'97 DAC support, not ICH hardware */
2457 val = DSP_BIND_FRONT;
2458 if ( state->card->ac97_features & 0x0004 )
2459 val |= DSP_BIND_SPDIF;
2460
2461 if ( state->card->ac97_features & 0x0080 )
2462 val |= DSP_BIND_SURR;
2463 if ( state->card->ac97_features & 0x0140 )
2464 val |= DSP_BIND_CENTER_LFE;
2465
2466 return put_user(val, p);
2467
2468 case SNDCTL_DSP_BIND_CHANNEL:
2469#ifdef DEBUG
2470 printk("SNDCTL_DSP_BIND_CHANNEL\n");
2471#endif
2472 if (get_user(val, p))
2473 return -EFAULT;
2474 if ( val == DSP_BIND_QUERY ) {
2475 val = DSP_BIND_FRONT; /* Always report this as being enabled */
2476 if ( state->card->ac97_status & SPDIF_ON )
2477 val |= DSP_BIND_SPDIF;
2478 else {
2479 if ( state->card->ac97_status & SURR_ON )
2480 val |= DSP_BIND_SURR;
2481 if ( state->card->ac97_status & CENTER_LFE_ON )
2482 val |= DSP_BIND_CENTER_LFE;
2483 }
2484 } else { /* Not a query, set it */
2485 if (!(file->f_mode & FMODE_WRITE))
2486 return -EINVAL;
2487 if ( dmabuf->enable == DAC_RUNNING ) {
2488 stop_dac(state);
2489 }
2490 if ( val & DSP_BIND_SPDIF ) { /* Turn on SPDIF */
2491 /* Ok, this should probably define what slots
2492 * to use. For now, we'll only set it to the
2493 * defaults:
2494 *
2495 * non multichannel codec maps to slots 3&4
2496 * 2 channel codec maps to slots 7&8
2497 * 4 channel codec maps to slots 6&9
2498 * 6 channel codec maps to slots 10&11
2499 *
2500 * there should be some way for the app to
2501 * select the slot assignment.
2502 */
2503
2504 i810_set_spdif_output ( state, AC97_EA_SPSA_3_4, dmabuf->rate );
2505 if ( !(state->card->ac97_status & SPDIF_ON) )
2506 val &= ~DSP_BIND_SPDIF;
2507 } else {
2508 int mask;
2509 int channels;
2510
2511 /* Turn off S/PDIF if it was on */
2512 if ( state->card->ac97_status & SPDIF_ON )
2513 i810_set_spdif_output ( state, -1, 0 );
2514
2515 mask = val & (DSP_BIND_FRONT | DSP_BIND_SURR | DSP_BIND_CENTER_LFE);
2516 switch (mask) {
2517 case DSP_BIND_FRONT:
2518 channels = 2;
2519 break;
2520 case DSP_BIND_FRONT|DSP_BIND_SURR:
2521 channels = 4;
2522 break;
2523 case DSP_BIND_FRONT|DSP_BIND_SURR|DSP_BIND_CENTER_LFE:
2524 channels = 6;
2525 break;
2526 default:
2527 val = DSP_BIND_FRONT;
2528 channels = 2;
2529 break;
2530 }
2531 i810_set_dac_channels ( state, channels );
2532
2533 /* check that they really got turned on */
2534 if (!(state->card->ac97_status & SURR_ON))
2535 val &= ~DSP_BIND_SURR;
2536 if (!(state->card->ac97_status & CENTER_LFE_ON))
2537 val &= ~DSP_BIND_CENTER_LFE;
2538 }
2539 }
2540 return put_user(val, p);
2541
2542 case SNDCTL_DSP_MAPINBUF:
2543 case SNDCTL_DSP_MAPOUTBUF:
2544 case SNDCTL_DSP_SETSYNCRO:
2545 case SOUND_PCM_WRITE_FILTER:
2546 case SOUND_PCM_READ_FILTER:
2547#ifdef DEBUG
2548 printk("SNDCTL_* -EINVAL\n");
2549#endif
2550 return -EINVAL;
2551 }
2552 return -EINVAL;
2553}
2554
2555static int i810_open(struct inode *inode, struct file *file)
2556{
2557 int i = 0;
2558 struct i810_card *card = devs;
2559 struct i810_state *state = NULL;
2560 struct dmabuf *dmabuf = NULL;
2561
2562 /* find an avaiable virtual channel (instance of /dev/dsp) */
2563 while (card != NULL) {
2564 /*
2565 * If we are initializing and then fail, card could go
2566 * away unuexpectedly while we are in the for() loop.
2567 * So, check for card on each iteration before we check
2568 * for card->initializing to avoid a possible oops.
2569 * This usually only matters for times when the driver is
2570 * autoloaded by kmod.
2571 */
2572 for (i = 0; i < 50 && card && card->initializing; i++) {
2573 set_current_state(TASK_UNINTERRUPTIBLE);
2574 schedule_timeout(HZ/20);
2575 }
2576 for (i = 0; i < NR_HW_CH && card && !card->initializing; i++) {
2577 if (card->states[i] == NULL) {
2578 state = card->states[i] = (struct i810_state *)
2579 kmalloc(sizeof(struct i810_state), GFP_KERNEL);
2580 if (state == NULL)
2581 return -ENOMEM;
2582 memset(state, 0, sizeof(struct i810_state));
2583 dmabuf = &state->dmabuf;
2584 goto found_virt;
2585 }
2586 }
2587 card = card->next;
2588 }
2589 /* no more virtual channel avaiable */
2590 if (!state)
2591 return -ENODEV;
2592
2593found_virt:
2594 /* initialize the virtual channel */
2595 state->virt = i;
2596 state->card = card;
2597 state->magic = I810_STATE_MAGIC;
2598 init_waitqueue_head(&dmabuf->wait);
2599 init_MUTEX(&state->open_sem);
2600 file->private_data = state;
2601 dmabuf->trigger = 0;
2602
2603 /* allocate hardware channels */
2604 if(file->f_mode & FMODE_READ) {
2605 if((dmabuf->read_channel = card->alloc_rec_pcm_channel(card)) == NULL) {
2606 kfree (card->states[i]);
2607 card->states[i] = NULL;
2608 return -EBUSY;
2609 }
2610 dmabuf->trigger |= PCM_ENABLE_INPUT;
2611 i810_set_adc_rate(state, 8000);
2612 }
2613 if(file->f_mode & FMODE_WRITE) {
2614 if((dmabuf->write_channel = card->alloc_pcm_channel(card)) == NULL) {
2615 /* make sure we free the record channel allocated above */
2616 if(file->f_mode & FMODE_READ)
2617 card->free_pcm_channel(card,dmabuf->read_channel->num);
2618 kfree (card->states[i]);
2619 card->states[i] = NULL;
2620 return -EBUSY;
2621 }
2622 /* Initialize to 8kHz? What if we don't support 8kHz? */
2623 /* Let's change this to check for S/PDIF stuff */
2624
2625 dmabuf->trigger |= PCM_ENABLE_OUTPUT;
2626 if ( spdif_locked ) {
2627 i810_set_dac_rate(state, spdif_locked);
2628 i810_set_spdif_output(state, AC97_EA_SPSA_3_4, spdif_locked);
2629 } else {
2630 i810_set_dac_rate(state, 8000);
2631 /* Put the ACLink in 2 channel mode by default */
2632 i = I810_IOREADL(card, GLOB_CNT);
2633 I810_IOWRITEL(i & 0xffcfffff, card, GLOB_CNT);
2634 }
2635 }
2636
2637 /* set default sample format. According to OSS Programmer's Guide /dev/dsp
2638 should be default to unsigned 8-bits, mono, with sample rate 8kHz and
2639 /dev/dspW will accept 16-bits sample, but we don't support those so we
2640 set it immediately to stereo and 16bit, which is all we do support */
2641 dmabuf->fmt |= I810_FMT_16BIT | I810_FMT_STEREO;
2642 dmabuf->ossfragsize = 0;
2643 dmabuf->ossmaxfrags = 0;
2644 dmabuf->subdivision = 0;
2645
2646 state->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2647
2648 return nonseekable_open(inode, file);
2649}
2650
2651static int i810_release(struct inode *inode, struct file *file)
2652{
2653 struct i810_state *state = (struct i810_state *)file->private_data;
2654 struct i810_card *card = state->card;
2655 struct dmabuf *dmabuf = &state->dmabuf;
2656 unsigned long flags;
2657
2658 lock_kernel();
2659
2660 /* stop DMA state machine and free DMA buffers/channels */
2661 if(dmabuf->trigger & PCM_ENABLE_OUTPUT) {
2662 drain_dac(state, 0);
2663 }
2664 if(dmabuf->trigger & PCM_ENABLE_INPUT) {
2665 stop_adc(state);
2666 }
2667 spin_lock_irqsave(&card->lock, flags);
2668 dealloc_dmabuf(state);
2669 if (file->f_mode & FMODE_WRITE) {
2670 state->card->free_pcm_channel(state->card, dmabuf->write_channel->num);
2671 }
2672 if (file->f_mode & FMODE_READ) {
2673 state->card->free_pcm_channel(state->card, dmabuf->read_channel->num);
2674 }
2675
2676 state->card->states[state->virt] = NULL;
2677 kfree(state);
2678 spin_unlock_irqrestore(&card->lock, flags);
2679 unlock_kernel();
2680
2681 return 0;
2682}
2683
2684static /*const*/ struct file_operations i810_audio_fops = {
2685 .owner = THIS_MODULE,
2686 .llseek = no_llseek,
2687 .read = i810_read,
2688 .write = i810_write,
2689 .poll = i810_poll,
2690 .ioctl = i810_ioctl,
2691 .mmap = i810_mmap,
2692 .open = i810_open,
2693 .release = i810_release,
2694};
2695
2696/* Write AC97 codec registers */
2697
2698static u16 i810_ac97_get_mmio(struct ac97_codec *dev, u8 reg)
2699{
2700 struct i810_card *card = dev->private_data;
2701 int count = 100;
2702 u16 reg_set = IO_REG_OFF(dev) | (reg&0x7f);
2703
2704 while(count-- && (readb(card->iobase_mmio + CAS) & 1))
2705 udelay(1);
2706
2707#ifdef DEBUG_MMIO
2708 {
2709 u16 ans = readw(card->ac97base_mmio + reg_set);
2710 printk(KERN_DEBUG "i810_audio: ac97_get_mmio(%d) -> 0x%04X\n", ((int) reg_set) & 0xffff, (u32) ans);
2711 return ans;
2712 }
2713#else
2714 return readw(card->ac97base_mmio + reg_set);
2715#endif
2716}
2717
2718static u16 i810_ac97_get_io(struct ac97_codec *dev, u8 reg)
2719{
2720 struct i810_card *card = dev->private_data;
2721 int count = 100;
2722 u16 reg_set = IO_REG_OFF(dev) | (reg&0x7f);
2723
2724 while(count-- && (I810_IOREADB(card, CAS) & 1))
2725 udelay(1);
2726
2727 return inw(card->ac97base + reg_set);
2728}
2729
2730static void i810_ac97_set_mmio(struct ac97_codec *dev, u8 reg, u16 data)
2731{
2732 struct i810_card *card = dev->private_data;
2733 int count = 100;
2734 u16 reg_set = IO_REG_OFF(dev) | (reg&0x7f);
2735
2736 while(count-- && (readb(card->iobase_mmio + CAS) & 1))
2737 udelay(1);
2738
2739 writew(data, card->ac97base_mmio + reg_set);
2740
2741#ifdef DEBUG_MMIO
2742 printk(KERN_DEBUG "i810_audio: ac97_set_mmio(0x%04X, %d)\n", (u32) data, ((int) reg_set) & 0xffff);
2743#endif
2744}
2745
2746static void i810_ac97_set_io(struct ac97_codec *dev, u8 reg, u16 data)
2747{
2748 struct i810_card *card = dev->private_data;
2749 int count = 100;
2750 u16 reg_set = IO_REG_OFF(dev) | (reg&0x7f);
2751
2752 while(count-- && (I810_IOREADB(card, CAS) & 1))
2753 udelay(1);
2754
2755 outw(data, card->ac97base + reg_set);
2756}
2757
2758static u16 i810_ac97_get(struct ac97_codec *dev, u8 reg)
2759{
2760 struct i810_card *card = dev->private_data;
2761 u16 ret;
2762
2763 spin_lock(&card->ac97_lock);
2764 if (card->use_mmio) {
2765 ret = i810_ac97_get_mmio(dev, reg);
2766 }
2767 else {
2768 ret = i810_ac97_get_io(dev, reg);
2769 }
2770 spin_unlock(&card->ac97_lock);
2771
2772 return ret;
2773}
2774
2775static void i810_ac97_set(struct ac97_codec *dev, u8 reg, u16 data)
2776{
2777 struct i810_card *card = dev->private_data;
2778
2779 spin_lock(&card->ac97_lock);
2780 if (card->use_mmio) {
2781 i810_ac97_set_mmio(dev, reg, data);
2782 }
2783 else {
2784 i810_ac97_set_io(dev, reg, data);
2785 }
2786 spin_unlock(&card->ac97_lock);
2787}
2788
2789
2790/* OSS /dev/mixer file operation methods */
2791
2792static int i810_open_mixdev(struct inode *inode, struct file *file)
2793{
2794 int i;
2795 int minor = iminor(inode);
2796 struct i810_card *card = devs;
2797
2798 for (card = devs; card != NULL; card = card->next) {
2799 /*
2800 * If we are initializing and then fail, card could go
2801 * away unuexpectedly while we are in the for() loop.
2802 * So, check for card on each iteration before we check
2803 * for card->initializing to avoid a possible oops.
2804 * This usually only matters for times when the driver is
2805 * autoloaded by kmod.
2806 */
2807 for (i = 0; i < 50 && card && card->initializing; i++) {
2808 set_current_state(TASK_UNINTERRUPTIBLE);
2809 schedule_timeout(HZ/20);
2810 }
2811 for (i = 0; i < NR_AC97 && card && !card->initializing; i++)
2812 if (card->ac97_codec[i] != NULL &&
2813 card->ac97_codec[i]->dev_mixer == minor) {
2814 file->private_data = card->ac97_codec[i];
2815 return nonseekable_open(inode, file);
2816 }
2817 }
2818 return -ENODEV;
2819}
2820
2821static int i810_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
2822 unsigned long arg)
2823{
2824 struct ac97_codec *codec = (struct ac97_codec *)file->private_data;
2825
2826 return codec->mixer_ioctl(codec, cmd, arg);
2827}
2828
2829static /*const*/ struct file_operations i810_mixer_fops = {
2830 .owner = THIS_MODULE,
2831 .llseek = no_llseek,
2832 .ioctl = i810_ioctl_mixdev,
2833 .open = i810_open_mixdev,
2834};
2835
2836/* AC97 codec initialisation. These small functions exist so we don't
2837 duplicate code between module init and apm resume */
2838
2839static inline int i810_ac97_exists(struct i810_card *card, int ac97_number)
2840{
2841 u32 reg = I810_IOREADL(card, GLOB_STA);
2842 switch (ac97_number) {
2843 case 0:
2844 return reg & (1<<8);
2845 case 1:
2846 return reg & (1<<9);
2847 case 2:
2848 return reg & (1<<28);
2849 }
2850 return 0;
2851}
2852
2853static inline int i810_ac97_enable_variable_rate(struct ac97_codec *codec)
2854{
2855 i810_ac97_set(codec, AC97_EXTENDED_STATUS, 9);
2856 i810_ac97_set(codec,AC97_EXTENDED_STATUS,
2857 i810_ac97_get(codec, AC97_EXTENDED_STATUS)|0xE800);
2858
2859 return (i810_ac97_get(codec, AC97_EXTENDED_STATUS)&1);
2860}
2861
2862
2863static int i810_ac97_probe_and_powerup(struct i810_card *card,struct ac97_codec *codec)
2864{
2865 /* Returns 0 on failure */
2866 int i;
2867
2868 if (ac97_probe_codec(codec) == 0) return 0;
2869
2870 /* power it all up */
2871 i810_ac97_set(codec, AC97_POWER_CONTROL,
2872 i810_ac97_get(codec, AC97_POWER_CONTROL) & ~0x7f00);
2873
2874 /* wait for analog ready */
2875 for (i=100; i && ((i810_ac97_get(codec, AC97_POWER_CONTROL) & 0xf) != 0xf); i--)
2876 {
2877 set_current_state(TASK_UNINTERRUPTIBLE);
2878 schedule_timeout(HZ/20);
2879 }
2880 return i;
2881}
2882
2883static int is_new_ich(u16 pci_id)
2884{
2885 switch (pci_id) {
2886 case PCI_DEVICE_ID_INTEL_82801DB_5:
2887 case PCI_DEVICE_ID_INTEL_82801EB_5:
2888 case PCI_DEVICE_ID_INTEL_ESB_5:
2889 case PCI_DEVICE_ID_INTEL_ICH6_18:
2890 return 1;
2891 default:
2892 break;
2893 }
2894
2895 return 0;
2896}
2897
2898static inline int ich_use_mmio(struct i810_card *card)
2899{
2900 return is_new_ich(card->pci_id) && card->use_mmio;
2901}
2902
2903/**
2904 * i810_ac97_power_up_bus - bring up AC97 link
2905 * @card : ICH audio device to power up
2906 *
2907 * Bring up the ACLink AC97 codec bus
2908 */
2909
2910static int i810_ac97_power_up_bus(struct i810_card *card)
2911{
2912 u32 reg = I810_IOREADL(card, GLOB_CNT);
2913 int i;
2914 int primary_codec_id = 0;
2915
2916 if((reg&2)==0) /* Cold required */
2917 reg|=2;
2918 else
2919 reg|=4; /* Warm */
2920
2921 reg&=~8; /* ACLink on */
2922
2923 /* At this point we deassert AC_RESET # */
2924 I810_IOWRITEL(reg , card, GLOB_CNT);
2925
2926 /* We must now allow time for the Codec initialisation.
2927 600mS is the specified time */
2928
2929 for(i=0;i<10;i++)
2930 {
2931 if((I810_IOREADL(card, GLOB_CNT)&4)==0)
2932 break;
2933
2934 set_current_state(TASK_UNINTERRUPTIBLE);
2935 schedule_timeout(HZ/20);
2936 }
2937 if(i==10)
2938 {
2939 printk(KERN_ERR "i810_audio: AC'97 reset failed.\n");
2940 return 0;
2941 }
2942
2943 set_current_state(TASK_UNINTERRUPTIBLE);
2944 schedule_timeout(HZ/2);
2945
2946 /*
2947 * See if the primary codec comes ready. This must happen
2948 * before we start doing DMA stuff
2949 */
2950 /* see i810_ac97_init for the next 10 lines (jsaw) */
2951 if (card->use_mmio)
2952 readw(card->ac97base_mmio);
2953 else
2954 inw(card->ac97base);
2955 if (ich_use_mmio(card)) {
2956 primary_codec_id = (int) readl(card->iobase_mmio + SDM) & 0x3;
2957 printk(KERN_INFO "i810_audio: Primary codec has ID %d\n",
2958 primary_codec_id);
2959 }
2960
2961 if(! i810_ac97_exists(card, primary_codec_id))
2962 {
2963 printk(KERN_INFO "i810_audio: Codec not ready.. wait.. ");
2964 set_current_state(TASK_UNINTERRUPTIBLE);
2965 schedule_timeout(HZ); /* actually 600mS by the spec */
2966
2967 if(i810_ac97_exists(card, primary_codec_id))
2968 printk("OK\n");
2969 else
2970 printk("no response.\n");
2971 }
2972 if (card->use_mmio)
2973 readw(card->ac97base_mmio);
2974 else
2975 inw(card->ac97base);
2976 return 1;
2977}
2978
2979static int __devinit i810_ac97_init(struct i810_card *card)
2980{
2981 int num_ac97 = 0;
2982 int ac97_id;
2983 int total_channels = 0;
2984 int nr_ac97_max = card_cap[card->pci_id_internal].nr_ac97;
2985 struct ac97_codec *codec;
2986 u16 eid;
2987 u32 reg;
2988
2989 if(!i810_ac97_power_up_bus(card)) return 0;
2990
2991 /* Number of channels supported */
2992 /* What about the codec? Just because the ICH supports */
2993 /* multiple channels doesn't mean the codec does. */
2994 /* we'll have to modify this in the codec section below */
2995 /* to reflect what the codec has. */
2996 /* ICH and ICH0 only support 2 channels so don't bother */
2997 /* to check.... */
2998
2999 card->channels = 2;
3000 reg = I810_IOREADL(card, GLOB_STA);
3001 if ( reg & 0x0200000 )
3002 card->channels = 6;
3003 else if ( reg & 0x0100000 )
3004 card->channels = 4;
3005 printk(KERN_INFO "i810_audio: Audio Controller supports %d channels.\n", card->channels);
3006 printk(KERN_INFO "i810_audio: Defaulting to base 2 channel mode.\n");
3007 reg = I810_IOREADL(card, GLOB_CNT);
3008 I810_IOWRITEL(reg & 0xffcfffff, card, GLOB_CNT);
3009
3010 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++)
3011 card->ac97_codec[num_ac97] = NULL;
3012
3013 /*@FIXME I don't know, if I'm playing to safe here... (jsaw) */
3014 if ((nr_ac97_max > 2) && !card->use_mmio) nr_ac97_max = 2;
3015
3016 for (num_ac97 = 0; num_ac97 < nr_ac97_max; num_ac97++) {
3017 /* codec reset */
3018 printk(KERN_INFO "i810_audio: Resetting connection %d\n", num_ac97);
3019 if (card->use_mmio)
3020 readw(card->ac97base_mmio + 0x80*num_ac97);
3021 else
3022 inw(card->ac97base + 0x80*num_ac97);
3023
3024 /* If we have the SDATA_IN Map Register, as on ICH4, we
3025 do not loop thru all possible codec IDs but thru all
3026 possible IO channels. Bit 0:1 of SDM then holds the
3027 last codec ID spoken to.
3028 */
3029 if (ich_use_mmio(card)) {
3030 ac97_id = (int) readl(card->iobase_mmio + SDM) & 0x3;
3031 printk(KERN_INFO "i810_audio: Connection %d with codec id %d\n",
3032 num_ac97, ac97_id);
3033 }
3034 else {
3035 ac97_id = num_ac97;
3036 }
3037
3038 /* The ICH programmer's reference says you should */
3039 /* check the ready status before probing. So we chk */
3040 /* What do we do if it's not ready? Wait and try */
3041 /* again, or abort? */
3042 if (!i810_ac97_exists(card, ac97_id)) {
3043 if(num_ac97 == 0)
3044 printk(KERN_ERR "i810_audio: Primary codec not ready.\n");
3045 }
3046
3047 if ((codec = ac97_alloc_codec()) == NULL)
3048 return -ENOMEM;
3049
3050 /* initialize some basic codec information, other fields will be filled
3051 in ac97_probe_codec */
3052 codec->private_data = card;
3053 codec->id = ac97_id;
3054 card->ac97_id_map[ac97_id] = num_ac97 * 0x80;
3055
3056 if (card->use_mmio) {
3057 codec->codec_read = i810_ac97_get_mmio;
3058 codec->codec_write = i810_ac97_set_mmio;
3059 }
3060 else {
3061 codec->codec_read = i810_ac97_get_io;
3062 codec->codec_write = i810_ac97_set_io;
3063 }
3064
3065 if(!i810_ac97_probe_and_powerup(card,codec)) {
3066 printk(KERN_ERR "i810_audio: timed out waiting for codec %d analog ready.\n", ac97_id);
3067 ac97_release_codec(codec);
3068 break; /* it didn't work */
3069 }
3070 /* Store state information about S/PDIF transmitter */
3071 card->ac97_status = 0;
3072
3073 /* Don't attempt to get eid until powerup is complete */
3074 eid = i810_ac97_get(codec, AC97_EXTENDED_ID);
3075
3076 if(eid==0xFFFF)
3077 {
3078 printk(KERN_WARNING "i810_audio: no codec attached ?\n");
3079 ac97_release_codec(codec);
3080 break;
3081 }
3082
3083 /* Check for an AC97 1.0 soft modem (ID1) */
3084
3085 if(codec->modem)
3086 {
3087 printk(KERN_WARNING "i810_audio: codec %d is a softmodem - skipping.\n", ac97_id);
3088 ac97_release_codec(codec);
3089 continue;
3090 }
3091
3092 card->ac97_features = eid;
3093
3094 /* Now check the codec for useful features to make up for
3095 the dumbness of the 810 hardware engine */
3096
3097 if(!(eid&0x0001))
3098 printk(KERN_WARNING "i810_audio: only 48Khz playback available.\n");
3099 else
3100 {
3101 if(!i810_ac97_enable_variable_rate(codec)) {
3102 printk(KERN_WARNING "i810_audio: Codec refused to allow VRA, using 48Khz only.\n");
3103 card->ac97_features&=~1;
3104 }
3105 }
3106
3107 /* Turn on the amplifier */
3108
3109 codec->codec_write(codec, AC97_POWER_CONTROL,
3110 codec->codec_read(codec, AC97_POWER_CONTROL) & ~0x8000);
3111
3112 /* Determine how many channels the codec(s) support */
3113 /* - The primary codec always supports 2 */
3114 /* - If the codec supports AMAP, surround DACs will */
3115 /* automaticlly get assigned to slots. */
3116 /* * Check for surround DACs and increment if */
3117 /* found. */
3118 /* - Else check if the codec is revision 2.2 */
3119 /* * If surround DACs exist, assign them to slots */
3120 /* and increment channel count. */
3121
3122 /* All of this only applies to ICH2 and above. ICH */
3123 /* and ICH0 only support 2 channels. ICH2 will only */
3124 /* support multiple codecs in a "split audio" config. */
3125 /* as described above. */
3126
3127 /* TODO: Remove all the debugging messages! */
3128
3129 if((eid & 0xc000) == 0) /* primary codec */
3130 total_channels += 2;
3131
3132 if(eid & 0x200) { /* GOOD, AMAP support */
3133 if (eid & 0x0080) /* L/R Surround channels */
3134 total_channels += 2;
3135 if (eid & 0x0140) /* LFE and Center channels */
3136 total_channels += 2;
3137 printk("i810_audio: AC'97 codec %d supports AMAP, total channels = %d\n", ac97_id, total_channels);
3138 } else if (eid & 0x0400) { /* this only works on 2.2 compliant codecs */
3139 eid &= 0xffcf;
3140 if((eid & 0xc000) != 0) {
3141 switch ( total_channels ) {
3142 case 2:
3143 /* Set dsa1, dsa0 to 01 */
3144 eid |= 0x0010;
3145 break;
3146 case 4:
3147 /* Set dsa1, dsa0 to 10 */
3148 eid |= 0x0020;
3149 break;
3150 case 6:
3151 /* Set dsa1, dsa0 to 11 */
3152 eid |= 0x0030;
3153 break;
3154 }
3155 total_channels += 2;
3156 }
3157 i810_ac97_set(codec, AC97_EXTENDED_ID, eid);
3158 eid = i810_ac97_get(codec, AC97_EXTENDED_ID);
3159 printk("i810_audio: AC'97 codec %d, new EID value = 0x%04x\n", ac97_id, eid);
3160 if (eid & 0x0080) /* L/R Surround channels */
3161 total_channels += 2;
3162 if (eid & 0x0140) /* LFE and Center channels */
3163 total_channels += 2;
3164 printk("i810_audio: AC'97 codec %d, DAC map configured, total channels = %d\n", ac97_id, total_channels);
3165 } else {
3166 printk("i810_audio: AC'97 codec %d Unable to map surround DAC's (or DAC's not present), total channels = %d\n", ac97_id, total_channels);
3167 }
3168
3169 if ((codec->dev_mixer = register_sound_mixer(&i810_mixer_fops, -1)) < 0) {
3170 printk(KERN_ERR "i810_audio: couldn't register mixer!\n");
3171 ac97_release_codec(codec);
3172 break;
3173 }
3174
3175 card->ac97_codec[num_ac97] = codec;
3176 }
3177
3178 /* tune up the primary codec */
3179 ac97_tune_hardware(card->pci_dev, ac97_quirks, ac97_quirk);
3180
3181 /* pick the minimum of channels supported by ICHx or codec(s) */
3182 card->channels = (card->channels > total_channels)?total_channels:card->channels;
3183
3184 return num_ac97;
3185}
3186
3187static void __devinit i810_configure_clocking (void)
3188{
3189 struct i810_card *card;
3190 struct i810_state *state;
3191 struct dmabuf *dmabuf;
3192 unsigned int i, offset, new_offset;
3193 unsigned long flags;
3194
3195 card = devs;
3196 /* We could try to set the clocking for multiple cards, but can you even have
3197 * more than one i810 in a machine? Besides, clocking is global, so unless
3198 * someone actually thinks more than one i810 in a machine is possible and
3199 * decides to rewrite that little bit, setting the rate for more than one card
3200 * is a waste of time.
3201 */
3202 if(card != NULL) {
3203 state = card->states[0] = (struct i810_state *)
3204 kmalloc(sizeof(struct i810_state), GFP_KERNEL);
3205 if (state == NULL)
3206 return;
3207 memset(state, 0, sizeof(struct i810_state));
3208 dmabuf = &state->dmabuf;
3209
3210 dmabuf->write_channel = card->alloc_pcm_channel(card);
3211 state->virt = 0;
3212 state->card = card;
3213 state->magic = I810_STATE_MAGIC;
3214 init_waitqueue_head(&dmabuf->wait);
3215 init_MUTEX(&state->open_sem);
3216 dmabuf->fmt = I810_FMT_STEREO | I810_FMT_16BIT;
3217 dmabuf->trigger = PCM_ENABLE_OUTPUT;
3218 i810_set_spdif_output(state, -1, 0);
3219 i810_set_dac_channels(state, 2);
3220 i810_set_dac_rate(state, 48000);
3221 if(prog_dmabuf(state, 0) != 0) {
3222 goto config_out_nodmabuf;
3223 }
3224 if(dmabuf->dmasize < 16384) {
3225 goto config_out;
3226 }
3227 dmabuf->count = dmabuf->dmasize;
3228 CIV_TO_LVI(card, dmabuf->write_channel->port, -1);
3229 local_irq_save(flags);
3230 start_dac(state);
3231 offset = i810_get_dma_addr(state, 0);
3232 mdelay(50);
3233 new_offset = i810_get_dma_addr(state, 0);
3234 stop_dac(state);
3235 local_irq_restore(flags);
3236 i = new_offset - offset;
3237#ifdef DEBUG_INTERRUPTS
3238 printk("i810_audio: %d bytes in 50 milliseconds\n", i);
3239#endif
3240 if(i == 0)
3241 goto config_out;
3242 i = i / 4 * 20;
3243 if (i > 48500 || i < 47500) {
3244 clocking = clocking * clocking / i;
3245 printk("i810_audio: setting clocking to %d\n", clocking);
3246 }
3247config_out:
3248 dealloc_dmabuf(state);
3249config_out_nodmabuf:
3250 state->card->free_pcm_channel(state->card,state->dmabuf.write_channel->num);
3251 kfree(state);
3252 card->states[0] = NULL;
3253 }
3254}
3255
3256/* install the driver, we do not allocate hardware channel nor DMA buffer now, they are defered
3257 until "ACCESS" time (in prog_dmabuf called by open/read/write/ioctl/mmap) */
3258
3259static int __devinit i810_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
3260{
3261 struct i810_card *card;
3262
3263 if (pci_enable_device(pci_dev))
3264 return -EIO;
3265
3266 if (pci_set_dma_mask(pci_dev, I810_DMA_MASK)) {
3267 printk(KERN_ERR "i810_audio: architecture does not support"
3268 " 32bit PCI busmaster DMA\n");
3269 return -ENODEV;
3270 }
3271
3272 if ((card = kmalloc(sizeof(struct i810_card), GFP_KERNEL)) == NULL) {
3273 printk(KERN_ERR "i810_audio: out of memory\n");
3274 return -ENOMEM;
3275 }
3276 memset(card, 0, sizeof(*card));
3277
3278 card->initializing = 1;
3279 card->pci_dev = pci_dev;
3280 card->pci_id = pci_id->device;
3281 card->ac97base = pci_resource_start (pci_dev, 0);
3282 card->iobase = pci_resource_start (pci_dev, 1);
3283
3284 if (!(card->ac97base) || !(card->iobase)) {
3285 card->ac97base = 0;
3286 card->iobase = 0;
3287 }
3288
3289 /* if chipset could have mmio capability, check it */
3290 if (card_cap[pci_id->driver_data].flags & CAP_MMIO) {
3291 card->ac97base_mmio_phys = pci_resource_start (pci_dev, 2);
3292 card->iobase_mmio_phys = pci_resource_start (pci_dev, 3);
3293
3294 if ((card->ac97base_mmio_phys) && (card->iobase_mmio_phys)) {
3295 card->use_mmio = 1;
3296 }
3297 else {
3298 card->ac97base_mmio_phys = 0;
3299 card->iobase_mmio_phys = 0;
3300 }
3301 }
3302
3303 if (!(card->use_mmio) && (!(card->iobase) || !(card->ac97base))) {
3304 printk(KERN_ERR "i810_audio: No I/O resources available.\n");
3305 goto out_mem;
3306 }
3307
3308 card->irq = pci_dev->irq;
3309 card->next = devs;
3310 card->magic = I810_CARD_MAGIC;
3311#ifdef CONFIG_PM
3312 card->pm_suspended=0;
3313#endif
3314 spin_lock_init(&card->lock);
3315 spin_lock_init(&card->ac97_lock);
3316 devs = card;
3317
3318 pci_set_master(pci_dev);
3319
3320 printk(KERN_INFO "i810: %s found at IO 0x%04lx and 0x%04lx, "
3321 "MEM 0x%04lx and 0x%04lx, IRQ %d\n",
3322 card_names[pci_id->driver_data],
3323 card->iobase, card->ac97base,
3324 card->ac97base_mmio_phys, card->iobase_mmio_phys,
3325 card->irq);
3326
3327 card->alloc_pcm_channel = i810_alloc_pcm_channel;
3328 card->alloc_rec_pcm_channel = i810_alloc_rec_pcm_channel;
3329 card->alloc_rec_mic_channel = i810_alloc_rec_mic_channel;
3330 card->free_pcm_channel = i810_free_pcm_channel;
3331
3332 if ((card->channel = pci_alloc_consistent(pci_dev,
3333 sizeof(struct i810_channel)*NR_HW_CH, &card->chandma)) == NULL) {
3334 printk(KERN_ERR "i810: cannot allocate channel DMA memory\n");
3335 goto out_mem;
3336 }
3337
3338 { /* We may dispose of this altogether some time soon, so... */
3339 struct i810_channel *cp = card->channel;
3340
3341 cp[0].offset = 0;
3342 cp[0].port = 0x00;
3343 cp[0].num = 0;
3344 cp[1].offset = 0;
3345 cp[1].port = 0x10;
3346 cp[1].num = 1;
3347 cp[2].offset = 0;
3348 cp[2].port = 0x20;
3349 cp[2].num = 2;
3350 }
3351
3352 /* claim our iospace and irq */
3353 if (!request_region(card->iobase, 64, card_names[pci_id->driver_data])) {
3354 printk(KERN_ERR "i810_audio: unable to allocate region %lx\n", card->iobase);
3355 goto out_region1;
3356 }
3357 if (!request_region(card->ac97base, 256, card_names[pci_id->driver_data])) {
3358 printk(KERN_ERR "i810_audio: unable to allocate region %lx\n", card->ac97base);
3359 goto out_region2;
3360 }
3361
3362 if (request_irq(card->irq, &i810_interrupt, SA_SHIRQ,
3363 card_names[pci_id->driver_data], card)) {
3364 printk(KERN_ERR "i810_audio: unable to allocate irq %d\n", card->irq);
3365 goto out_pio;
3366 }
3367
3368 if (card->use_mmio) {
3369 if (request_mem_region(card->ac97base_mmio_phys, 512, "ich_audio MMBAR")) {
3370 if ((card->ac97base_mmio = ioremap(card->ac97base_mmio_phys, 512))) { /*@FIXME can ioremap fail? don't know (jsaw) */
3371 if (request_mem_region(card->iobase_mmio_phys, 256, "ich_audio MBBAR")) {
3372 if ((card->iobase_mmio = ioremap(card->iobase_mmio_phys, 256))) {
3373 printk(KERN_INFO "i810: %s mmio at 0x%04lx and 0x%04lx\n",
3374 card_names[pci_id->driver_data],
3375 (unsigned long) card->ac97base_mmio,
3376 (unsigned long) card->iobase_mmio);
3377 }
3378 else {
3379 iounmap(card->ac97base_mmio);
3380 release_mem_region(card->ac97base_mmio_phys, 512);
3381 release_mem_region(card->iobase_mmio_phys, 512);
3382 card->use_mmio = 0;
3383 }
3384 }
3385 else {
3386 iounmap(card->ac97base_mmio);
3387 release_mem_region(card->ac97base_mmio_phys, 512);
3388 card->use_mmio = 0;
3389 }
3390 }
3391 }
3392 else {
3393 card->use_mmio = 0;
3394 }
3395 }
3396
3397 /* initialize AC97 codec and register /dev/mixer */
3398 if (i810_ac97_init(card) <= 0) {
3399 free_irq(card->irq, card);
3400 goto out_iospace;
3401 }
3402 pci_set_drvdata(pci_dev, card);
3403
3404 if(clocking == 0) {
3405 clocking = 48000;
3406 i810_configure_clocking();
3407 }
3408
3409 /* register /dev/dsp */
3410 if ((card->dev_audio = register_sound_dsp(&i810_audio_fops, -1)) < 0) {
3411 int i;
3412 printk(KERN_ERR "i810_audio: couldn't register DSP device!\n");
3413 free_irq(card->irq, card);
3414 for (i = 0; i < NR_AC97; i++)
3415 if (card->ac97_codec[i] != NULL) {
3416 unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
3417 ac97_release_codec(card->ac97_codec[i]);
3418 }
3419 goto out_iospace;
3420 }
3421
3422 card->initializing = 0;
3423 return 0;
3424
3425out_iospace:
3426 if (card->use_mmio) {
3427 iounmap(card->ac97base_mmio);
3428 iounmap(card->iobase_mmio);
3429 release_mem_region(card->ac97base_mmio_phys, 512);
3430 release_mem_region(card->iobase_mmio_phys, 256);
3431 }
3432out_pio:
3433 release_region(card->iobase, 64);
3434out_region2:
3435 release_region(card->ac97base, 256);
3436out_region1:
3437 pci_free_consistent(pci_dev, sizeof(struct i810_channel)*NR_HW_CH,
3438 card->channel, card->chandma);
3439out_mem:
3440 kfree(card);
3441 return -ENODEV;
3442}
3443
3444static void __devexit i810_remove(struct pci_dev *pci_dev)
3445{
3446 int i;
3447 struct i810_card *card = pci_get_drvdata(pci_dev);
3448 /* free hardware resources */
3449 free_irq(card->irq, devs);
3450 release_region(card->iobase, 64);
3451 release_region(card->ac97base, 256);
3452 pci_free_consistent(pci_dev, sizeof(struct i810_channel)*NR_HW_CH,
3453 card->channel, card->chandma);
3454 if (card->use_mmio) {
3455 iounmap(card->ac97base_mmio);
3456 iounmap(card->iobase_mmio);
3457 release_mem_region(card->ac97base_mmio_phys, 512);
3458 release_mem_region(card->iobase_mmio_phys, 256);
3459 }
3460
3461 /* unregister audio devices */
3462 for (i = 0; i < NR_AC97; i++)
3463 if (card->ac97_codec[i] != NULL) {
3464 unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
3465 ac97_release_codec(card->ac97_codec[i]);
3466 card->ac97_codec[i] = NULL;
3467 }
3468 unregister_sound_dsp(card->dev_audio);
3469 kfree(card);
3470}
3471
3472#ifdef CONFIG_PM
3473static int i810_pm_suspend(struct pci_dev *dev, pm_message_t pm_state)
3474{
3475 struct i810_card *card = pci_get_drvdata(dev);
3476 struct i810_state *state;
3477 unsigned long flags;
3478 struct dmabuf *dmabuf;
3479 int i,num_ac97;
3480#ifdef DEBUG
3481 printk("i810_audio: i810_pm_suspend called\n");
3482#endif
3483 if(!card) return 0;
3484 spin_lock_irqsave(&card->lock, flags);
3485 card->pm_suspended=1;
3486 for(i=0;i<NR_HW_CH;i++) {
3487 state = card->states[i];
3488 if(!state) continue;
3489 /* this happens only if there are open files */
3490 dmabuf = &state->dmabuf;
3491 if(dmabuf->enable & DAC_RUNNING ||
3492 (dmabuf->count && (dmabuf->trigger & PCM_ENABLE_OUTPUT))) {
3493 state->pm_saved_dac_rate=dmabuf->rate;
3494 stop_dac(state);
3495 } else {
3496 state->pm_saved_dac_rate=0;
3497 }
3498 if(dmabuf->enable & ADC_RUNNING) {
3499 state->pm_saved_adc_rate=dmabuf->rate;
3500 stop_adc(state);
3501 } else {
3502 state->pm_saved_adc_rate=0;
3503 }
3504 dmabuf->ready = 0;
3505 dmabuf->swptr = dmabuf->hwptr = 0;
3506 dmabuf->count = dmabuf->total_bytes = 0;
3507 }
3508
3509 spin_unlock_irqrestore(&card->lock, flags);
3510
3511 /* save mixer settings */
3512 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
3513 struct ac97_codec *codec = card->ac97_codec[num_ac97];
3514 if(!codec) continue;
3515 for(i=0;i< SOUND_MIXER_NRDEVICES ;i++) {
3516 if((supported_mixer(codec,i)) &&
3517 (codec->read_mixer)) {
3518 card->pm_saved_mixer_settings[i][num_ac97]=
3519 codec->read_mixer(codec,i);
3520 }
3521 }
3522 }
3523 pci_save_state(dev); /* XXX do we need this? */
3524 pci_disable_device(dev); /* disable busmastering */
3525 pci_set_power_state(dev,3); /* Zzz. */
3526
3527 return 0;
3528}
3529
3530
3531static int i810_pm_resume(struct pci_dev *dev)
3532{
3533 int num_ac97,i=0;
3534 struct i810_card *card=pci_get_drvdata(dev);
3535 pci_enable_device(dev);
3536 pci_restore_state (dev);
3537
3538 /* observation of a toshiba portege 3440ct suggests that the
3539 hardware has to be more or less completely reinitialized from
3540 scratch after an apm suspend. Works For Me. -dan */
3541
3542 i810_ac97_power_up_bus(card);
3543
3544 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
3545 struct ac97_codec *codec = card->ac97_codec[num_ac97];
3546 /* check they haven't stolen the hardware while we were
3547 away */
3548 if(!codec || !i810_ac97_exists(card,num_ac97)) {
3549 if(num_ac97) continue;
3550 else BUG();
3551 }
3552 if(!i810_ac97_probe_and_powerup(card,codec)) BUG();
3553
3554 if((card->ac97_features&0x0001)) {
3555 /* at probe time we found we could do variable
3556 rates, but APM suspend has made it forget
3557 its magical powers */
3558 if(!i810_ac97_enable_variable_rate(codec)) BUG();
3559 }
3560 /* we lost our mixer settings, so restore them */
3561 for(i=0;i< SOUND_MIXER_NRDEVICES ;i++) {
3562 if(supported_mixer(codec,i)){
3563 int val=card->
3564 pm_saved_mixer_settings[i][num_ac97];
3565 codec->mixer_state[i]=val;
3566 codec->write_mixer(codec,i,
3567 (val & 0xff) ,
3568 ((val >> 8) & 0xff) );
3569 }
3570 }
3571 }
3572
3573 /* we need to restore the sample rate from whatever it was */
3574 for(i=0;i<NR_HW_CH;i++) {
3575 struct i810_state * state=card->states[i];
3576 if(state) {
3577 if(state->pm_saved_adc_rate)
3578 i810_set_adc_rate(state,state->pm_saved_adc_rate);
3579 if(state->pm_saved_dac_rate)
3580 i810_set_dac_rate(state,state->pm_saved_dac_rate);
3581 }
3582 }
3583
3584
3585 card->pm_suspended = 0;
3586
3587 /* any processes that were reading/writing during the suspend
3588 probably ended up here */
3589 for(i=0;i<NR_HW_CH;i++) {
3590 struct i810_state *state = card->states[i];
3591 if(state) wake_up(&state->dmabuf.wait);
3592 }
3593
3594 return 0;
3595}
3596#endif /* CONFIG_PM */
3597
3598MODULE_AUTHOR("The Linux kernel team");
3599MODULE_DESCRIPTION("Intel 810 audio support");
3600MODULE_LICENSE("GPL");
3601module_param(ftsodell, int, 0444);
3602module_param(clocking, uint, 0444);
3603module_param(strict_clocking, int, 0444);
3604module_param(spdif_locked, int, 0444);
3605
3606#define I810_MODULE_NAME "i810_audio"
3607
3608static struct pci_driver i810_pci_driver = {
3609 .name = I810_MODULE_NAME,
3610 .id_table = i810_pci_tbl,
3611 .probe = i810_probe,
3612 .remove = __devexit_p(i810_remove),
3613#ifdef CONFIG_PM
3614 .suspend = i810_pm_suspend,
3615 .resume = i810_pm_resume,
3616#endif /* CONFIG_PM */
3617};
3618
3619
3620static int __init i810_init_module (void)
3621{
3622 int retval;
3623
3624 printk(KERN_INFO "Intel 810 + AC97 Audio, version "
3625 DRIVER_VERSION ", " __TIME__ " " __DATE__ "\n");
3626
3627 retval = pci_register_driver(&i810_pci_driver);
3628 if (retval)
3629 return retval;
3630
3631 if(ftsodell != 0) {
3632 printk("i810_audio: ftsodell is now a deprecated option.\n");
3633 }
3634 if(spdif_locked > 0 ) {
3635 if(spdif_locked == 32000 || spdif_locked == 44100 || spdif_locked == 48000) {
3636 printk("i810_audio: Enabling S/PDIF at sample rate %dHz.\n", spdif_locked);
3637 } else {
3638 printk("i810_audio: S/PDIF can only be locked to 32000, 44100, or 48000Hz.\n");
3639 spdif_locked = 0;
3640 }
3641 }
3642
3643 return 0;
3644}
3645
3646static void __exit i810_cleanup_module (void)
3647{
3648 pci_unregister_driver(&i810_pci_driver);
3649}
3650
3651module_init(i810_init_module);
3652module_exit(i810_cleanup_module);
3653
3654/*
3655Local Variables:
3656c-basic-offset: 8
3657End:
3658*/
diff --git a/sound/oss/ics2101.c b/sound/oss/ics2101.c
new file mode 100644
index 000000000000..d5f3be8550f3
--- /dev/null
+++ b/sound/oss/ics2101.c
@@ -0,0 +1,247 @@
1/*
2 * sound/ics2101.c
3 *
4 * Driver for the ICS2101 mixer of GUS v3.7.
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 * Bartlomiej Zolnierkiewicz : added __init to ics2101_mixer_init()
16 */
17#include <linux/init.h>
18#include <linux/spinlock.h>
19#include "sound_config.h"
20
21#include <linux/ultrasound.h>
22
23#include "gus.h"
24#include "gus_hw.h"
25
26#define MIX_DEVS (SOUND_MASK_MIC|SOUND_MASK_LINE| \
27 SOUND_MASK_SYNTH| \
28 SOUND_MASK_CD | SOUND_MASK_VOLUME)
29
30extern int *gus_osp;
31extern int gus_base;
32extern spinlock_t gus_lock;
33static int volumes[ICS_MIXDEVS];
34static int left_fix[ICS_MIXDEVS] =
35{1, 1, 1, 2, 1, 2};
36static int right_fix[ICS_MIXDEVS] =
37{2, 2, 2, 1, 2, 1};
38
39static int scale_vol(int vol)
40{
41 /*
42 * Experimental volume scaling by Risto Kankkunen.
43 * This should give smoother volume response than just
44 * a plain multiplication.
45 */
46
47 int e;
48
49 if (vol < 0)
50 vol = 0;
51 if (vol > 100)
52 vol = 100;
53 vol = (31 * vol + 50) / 100;
54 e = 0;
55 if (vol)
56 {
57 while (vol < 16)
58 {
59 vol <<= 1;
60 e--;
61 }
62 vol -= 16;
63 e += 7;
64 }
65 return ((e << 4) + vol);
66}
67
68static void write_mix(int dev, int chn, int vol)
69{
70 int *selector;
71 unsigned long flags;
72 int ctrl_addr = dev << 3;
73 int attn_addr = dev << 3;
74
75 vol = scale_vol(vol);
76
77 if (chn == CHN_LEFT)
78 {
79 selector = left_fix;
80 ctrl_addr |= 0x00;
81 attn_addr |= 0x02;
82 }
83 else
84 {
85 selector = right_fix;
86 ctrl_addr |= 0x01;
87 attn_addr |= 0x03;
88 }
89
90 spin_lock_irqsave(&gus_lock, flags);
91 outb((ctrl_addr), u_MixSelect);
92 outb((selector[dev]), u_MixData);
93 outb((attn_addr), u_MixSelect);
94 outb(((unsigned char) vol), u_MixData);
95 spin_unlock_irqrestore(&gus_lock,flags);
96}
97
98static int set_volumes(int dev, int vol)
99{
100 int left = vol & 0x00ff;
101 int right = (vol >> 8) & 0x00ff;
102
103 if (left < 0)
104 left = 0;
105 if (left > 100)
106 left = 100;
107 if (right < 0)
108 right = 0;
109 if (right > 100)
110 right = 100;
111
112 write_mix(dev, CHN_LEFT, left);
113 write_mix(dev, CHN_RIGHT, right);
114
115 vol = left + (right << 8);
116 volumes[dev] = vol;
117 return vol;
118}
119
120static int ics2101_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
121{
122 int val;
123
124 if (((cmd >> 8) & 0xff) == 'M') {
125 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
126
127 if (get_user(val, (int __user *)arg))
128 return -EFAULT;
129 switch (cmd & 0xff) {
130 case SOUND_MIXER_RECSRC:
131 return gus_default_mixer_ioctl(dev, cmd, arg);
132
133 case SOUND_MIXER_MIC:
134 val = set_volumes(DEV_MIC, val);
135 break;
136
137 case SOUND_MIXER_CD:
138 val = set_volumes(DEV_CD, val);
139 break;
140
141 case SOUND_MIXER_LINE:
142 val = set_volumes(DEV_LINE, val);
143 break;
144
145 case SOUND_MIXER_SYNTH:
146 val = set_volumes(DEV_GF1, val);
147 break;
148
149 case SOUND_MIXER_VOLUME:
150 val = set_volumes(DEV_VOL, val);
151 break;
152
153 default:
154 return -EINVAL;
155 }
156 return put_user(val, (int __user *)arg);
157 } else {
158 switch (cmd & 0xff) {
159 /*
160 * Return parameters
161 */
162 case SOUND_MIXER_RECSRC:
163 return gus_default_mixer_ioctl(dev, cmd, arg);
164
165 case SOUND_MIXER_DEVMASK:
166 val = MIX_DEVS;
167 break;
168
169 case SOUND_MIXER_STEREODEVS:
170 val = SOUND_MASK_LINE | SOUND_MASK_CD | SOUND_MASK_SYNTH | SOUND_MASK_VOLUME | SOUND_MASK_MIC;
171 break;
172
173 case SOUND_MIXER_RECMASK:
174 val = SOUND_MASK_MIC | SOUND_MASK_LINE;
175 break;
176
177 case SOUND_MIXER_CAPS:
178 val = 0;
179 break;
180
181 case SOUND_MIXER_MIC:
182 val = volumes[DEV_MIC];
183 break;
184
185 case SOUND_MIXER_LINE:
186 val = volumes[DEV_LINE];
187 break;
188
189 case SOUND_MIXER_CD:
190 val = volumes[DEV_CD];
191 break;
192
193 case SOUND_MIXER_VOLUME:
194 val = volumes[DEV_VOL];
195 break;
196
197 case SOUND_MIXER_SYNTH:
198 val = volumes[DEV_GF1];
199 break;
200
201 default:
202 return -EINVAL;
203 }
204 return put_user(val, (int __user *)arg);
205 }
206 }
207 return -EINVAL;
208}
209
210static struct mixer_operations ics2101_mixer_operations =
211{
212 .owner = THIS_MODULE,
213 .id = "ICS2101",
214 .name = "ICS2101 Multimedia Mixer",
215 .ioctl = ics2101_mixer_ioctl
216};
217
218int __init ics2101_mixer_init(void)
219{
220 int i;
221 int n;
222
223 if ((n = sound_alloc_mixerdev()) != -1)
224 {
225 mixer_devs[n] = &ics2101_mixer_operations;
226
227 /*
228 * Some GUS v3.7 cards had some channels flipped. Disable
229 * the flipping feature if the model id is other than 5.
230 */
231
232 if (inb(u_MixSelect) != 5)
233 {
234 for (i = 0; i < ICS_MIXDEVS; i++)
235 left_fix[i] = 1;
236 for (i = 0; i < ICS_MIXDEVS; i++)
237 right_fix[i] = 2;
238 }
239 set_volumes(DEV_GF1, 0x5a5a);
240 set_volumes(DEV_CD, 0x5a5a);
241 set_volumes(DEV_MIC, 0x0000);
242 set_volumes(DEV_LINE, 0x5a5a);
243 set_volumes(DEV_VOL, 0x5a5a);
244 set_volumes(DEV_UNUSED, 0x0000);
245 }
246 return n;
247}
diff --git a/sound/oss/ite8172.c b/sound/oss/ite8172.c
new file mode 100644
index 000000000000..58f879fda975
--- /dev/null
+++ b/sound/oss/ite8172.c
@@ -0,0 +1,2259 @@
1/*
2 * ite8172.c -- ITE IT8172G Sound Driver.
3 *
4 * Copyright 2001 MontaVista Software Inc.
5 * Author: MontaVista Software, Inc.
6 * stevel@mvista.com or source@mvista.com
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 *
29 * Module command line parameters:
30 *
31 * Supported devices:
32 * /dev/dsp standard OSS /dev/dsp device
33 * /dev/mixer standard OSS /dev/mixer device
34 *
35 * Notes:
36 *
37 * 1. Much of the OSS buffer allocation, ioctl's, and mmap'ing are
38 * taken, slightly modified or not at all, from the ES1371 driver,
39 * so refer to the credits in es1371.c for those. The rest of the
40 * code (probe, open, read, write, the ISR, etc.) is new.
41 * 2. The following support is untested:
42 * * Memory mapping the audio buffers, and the ioctl controls that go
43 * with it.
44 * * S/PDIF output.
45 * * I2S support.
46 * 3. The following is not supported:
47 * * legacy audio mode.
48 * 4. Support for volume button interrupts is implemented but doesn't
49 * work yet.
50 *
51 * Revision history
52 * 02.08.2001 Initial release
53 * 06.22.2001 Added I2S support
54 * 07.30.2003 Removed initialisation to zero for static variables
55 * (spdif[NR_DEVICE], i2s_fmt[NR_DEVICE], and devindex)
56 */
57#include <linux/module.h>
58#include <linux/string.h>
59#include <linux/ioport.h>
60#include <linux/sched.h>
61#include <linux/delay.h>
62#include <linux/sound.h>
63#include <linux/slab.h>
64#include <linux/soundcard.h>
65#include <linux/pci.h>
66#include <linux/init.h>
67#include <linux/poll.h>
68#include <linux/bitops.h>
69#include <linux/proc_fs.h>
70#include <linux/spinlock.h>
71#include <linux/smp_lock.h>
72#include <linux/ac97_codec.h>
73#include <linux/interrupt.h>
74#include <asm/io.h>
75#include <asm/dma.h>
76#include <asm/uaccess.h>
77#include <asm/it8172/it8172.h>
78
79/* --------------------------------------------------------------------- */
80
81#undef OSS_DOCUMENTED_MIXER_SEMANTICS
82#define IT8172_DEBUG
83#undef IT8172_VERBOSE_DEBUG
84#define DBG(x) {}
85
86#define IT8172_MODULE_NAME "IT8172 audio"
87#define PFX IT8172_MODULE_NAME
88
89#ifdef IT8172_DEBUG
90#define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
91#else
92#define dbg(format, arg...) do {} while (0)
93#endif
94#define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
95#define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
96#define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
97
98
99#define IT8172_MODULE_NAME "IT8172 audio"
100#define PFX IT8172_MODULE_NAME
101
102#ifdef IT8172_DEBUG
103#define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
104#else
105#define dbg(format, arg...) do {} while (0)
106#endif
107#define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
108#define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
109#define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
110
111
112static const unsigned sample_shift[] = { 0, 1, 1, 2 };
113
114
115/*
116 * Audio Controller register bit definitions follow. See
117 * include/asm/it8172/it8172.h for register offsets.
118 */
119
120/* PCM Out Volume Reg */
121#define PCMOV_PCMOM (1<<15) /* PCM Out Mute default 1: mute */
122#define PCMOV_PCMRCG_BIT 8 /* PCM Right channel Gain */
123#define PCMOV_PCMRCG_MASK (0x1f<<PCMOV_PCMRCG_BIT)
124#define PCMOV_PCMLCG_BIT 0 /* PCM Left channel gain */
125#define PCMOV_PCMLCG_MASK 0x1f
126
127/* FM Out Volume Reg */
128#define FMOV_FMOM (1<<15) /* FM Out Mute default 1: mute */
129#define FMOV_FMRCG_BIT 8 /* FM Right channel Gain */
130#define FMOV_FMRCG_MASK (0x1f<<FMOV_FMRCG_BIT)
131#define FMOV_FMLCG_BIT 0 /* FM Left channel gain */
132#define FMOV_FMLCG_MASK 0x1f
133
134/* I2S Out Volume Reg */
135#define I2SV_I2SOM (1<<15) /* I2S Out Mute default 1: mute */
136#define I2SV_I2SRCG_BIT 8 /* I2S Right channel Gain */
137#define I2SV_I2SRCG_MASK (0x1f<<I2SV_I2SRCG_BIT)
138#define I2SV_I2SLCG_BIT 0 /* I2S Left channel gain */
139#define I2SV_I2SLCG_MASK 0x1f
140
141/* Digital Recording Source Select Reg */
142#define DRSS_BIT 0
143#define DRSS_MASK 0x07
144#define DRSS_AC97_PRIM 0
145#define DRSS_FM 1
146#define DRSS_I2S 2
147#define DRSS_PCM 3
148#define DRSS_AC97_SEC 4
149
150/* Playback/Capture Channel Control Registers */
151#define CC_SM (1<<15) /* Stereo, Mone 0: mono 1: stereo */
152#define CC_DF (1<<14) /* Data Format 0: 8 bit 1: 16 bit */
153#define CC_FMT_BIT 14
154#define CC_FMT_MASK (0x03<<CC_FMT_BIT)
155#define CC_CF_BIT 12 /* Channel format (Playback only) */
156#define CC_CF_MASK (0x03<<CC_CF_BIT)
157#define CC_CF_2 0
158#define CC_CF_4 (1<<CC_CF_BIT)
159#define CC_CF_6 (2<<CC_CF_BIT)
160#define CC_SR_BIT 8 /* sample Rate */
161#define CC_SR_MASK (0x0f<<CC_SR_BIT)
162#define CC_SR_5500 0
163#define CC_SR_8000 (1<<CC_SR_BIT)
164#define CC_SR_9600 (2<<CC_SR_BIT)
165#define CC_SR_11025 (3<<CC_SR_BIT)
166#define CC_SR_16000 (4<<CC_SR_BIT)
167#define CC_SR_19200 (5<<CC_SR_BIT)
168#define CC_SR_22050 (6<<CC_SR_BIT)
169#define CC_SR_32000 (7<<CC_SR_BIT)
170#define CC_SR_38400 (8<<CC_SR_BIT)
171#define CC_SR_44100 (9<<CC_SR_BIT)
172#define CC_SR_48000 (10<<CC_SR_BIT)
173#define CC_CSP (1<<7) /* Channel stop
174 * 0: End of Current buffer
175 * 1: Immediately stop when rec stop */
176#define CC_CP (1<<6) /* Channel pause 0: normal, 1: pause */
177#define CC_CA (1<<5) /* Channel Action 0: Stop , 1: start */
178#define CC_CB2L (1<<2) /* Cur. buf. 2 xfr is last 0: No, 1: Yes */
179#define CC_CB1L (1<<1) /* Cur. buf. 1 xfr is last 0: No, 1: Yes */
180#define CC_DE 1 /* DFC/DFIFO Data Empty 1: empty, 0: not empty
181 * (Playback only)
182 */
183
184/* Codec Control Reg */
185#define CODECC_GME (1<<9) /* AC97 GPIO Mode enable */
186#define CODECC_ATM (1<<8) /* AC97 ATE test mode 0: test 1: normal */
187#define CODECC_WR (1<<6) /* AC97 Warn reset 1: warm reset , 0: Normal */
188#define CODECC_CR (1<<5) /* AC97 Cold reset 1: Cold reset , 0: Normal */
189
190
191/* I2S Control Reg */
192#define I2SMC_SR_BIT 6 /* I2S Sampling rate
193 * 00: 48KHz, 01: 44.1 KHz, 10: 32 32 KHz */
194#define I2SMC_SR_MASK (0x03<<I2SMC_SR_BIT)
195#define I2SMC_SR_48000 0
196#define I2SMC_SR_44100 (1<<I2SMC_SR_BIT)
197#define I2SMC_SR_32000 (2<<I2SMC_SR_BIT)
198#define I2SMC_SRSS (1<<5) /* Sample Rate Source Select 1:S/W, 0: H/W */
199#define I2SMC_I2SF_BIT 0 /* I2S Format */
200#define I2SMC_I2SF_MASK 0x03
201#define I2SMC_I2SF_DAC 0
202#define I2SMC_I2SF_ADC 2
203#define I2SMC_I2SF_I2S 3
204
205
206/* Volume up, Down, Mute */
207#define VS_VMP (1<<2) /* Volume mute 1: pushed, 0: not */
208#define VS_VDP (1<<1) /* Volume Down 1: pushed, 0: not */
209#define VS_VUP 1 /* Volime Up 1: pushed, 0: not */
210
211/* SRC, Mixer test control/DFC status reg */
212#define SRCS_DPUSC (1<<5) /* DFC Playback underrun Status/clear */
213#define SRCS_DCOSC (1<<4) /* DFC Capture Overrun Status/clear */
214#define SRCS_SIS (1<<3) /* SRC input select 1: Mixer, 0: Codec I/F */
215#define SRCS_CDIS_BIT 0 /* Codec Data Input Select */
216#define SRCS_CDIS_MASK 0x07
217#define SRCS_CDIS_MIXER 0
218#define SRCS_CDIS_PCM 1
219#define SRCS_CDIS_I2S 2
220#define SRCS_CDIS_FM 3
221#define SRCS_CDIS_DFC 4
222
223
224/* Codec Index Reg command Port */
225#define CIRCP_CID_BIT 10
226#define CIRCP_CID_MASK (0x03<<CIRCP_CID_BIT)
227#define CIRCP_CPS (1<<9) /* Command Port Status 0: ready, 1: busy */
228#define CIRCP_DPVF (1<<8) /* Data Port Valid Flag 0: invalis, 1: valid */
229#define CIRCP_RWC (1<<7) /* Read/write command */
230#define CIRCP_CIA_BIT 0
231#define CIRCP_CIA_MASK 0x007F /* Codec Index Address */
232
233/* Test Mode Control/Test group Select Control */
234
235/* General Control Reg */
236#define GC_VDC_BIT 6 /* Volume Division Control */
237#define GC_VDC_MASK (0x03<<GC_VDC_BIT)
238#define GC_VDC_NONE 0
239#define GC_VDC_DIV2 (1<<GC_VDC_BIT)
240#define GC_VDC_DIV4 (2<<GC_VDC_BIT)
241#define GC_SOE (1<<2) /* S/PDIF Output enable */
242#define GC_SWR 1 /* Software warn reset */
243
244/* Interrupt mask Control Reg */
245#define IMC_VCIM (1<<6) /* Volume CNTL interrupt mask */
246#define IMC_CCIM (1<<1) /* Capture Chan. iterrupt mask */
247#define IMC_PCIM 1 /* Playback Chan. interrupt mask */
248
249/* Interrupt status/clear reg */
250#define ISC_VCI (1<<6) /* Volume CNTL interrupt 1: clears */
251#define ISC_CCI (1<<1) /* Capture Chan. interrupt 1: clears */
252#define ISC_PCI 1 /* Playback Chan. interrupt 1: clears */
253
254/* misc stuff */
255#define POLL_COUNT 0x5000
256
257
258/* --------------------------------------------------------------------- */
259
260/*
261 * Define DIGITAL1 as the I2S channel, since it is not listed in
262 * soundcard.h.
263 */
264#define SOUND_MIXER_I2S SOUND_MIXER_DIGITAL1
265#define SOUND_MASK_I2S SOUND_MASK_DIGITAL1
266#define SOUND_MIXER_READ_I2S MIXER_READ(SOUND_MIXER_I2S)
267#define SOUND_MIXER_WRITE_I2S MIXER_WRITE(SOUND_MIXER_I2S)
268
269/* --------------------------------------------------------------------- */
270
271struct it8172_state {
272 /* list of it8172 devices */
273 struct list_head devs;
274
275 /* the corresponding pci_dev structure */
276 struct pci_dev *dev;
277
278 /* soundcore stuff */
279 int dev_audio;
280
281 /* hardware resources */
282 unsigned long io;
283 unsigned int irq;
284
285 /* PCI ID's */
286 u16 vendor;
287 u16 device;
288 u8 rev; /* the chip revision */
289
290 /* options */
291 int spdif_volume; /* S/PDIF output is enabled if != -1 */
292 int i2s_volume; /* current I2S out volume, in OSS format */
293 int i2s_recording;/* 1 = recording from I2S, 0 = not */
294
295#ifdef IT8172_DEBUG
296 /* debug /proc entry */
297 struct proc_dir_entry *ps;
298 struct proc_dir_entry *ac97_ps;
299#endif /* IT8172_DEBUG */
300
301 struct ac97_codec codec;
302
303 unsigned short pcc, capcc;
304 unsigned dacrate, adcrate;
305
306 spinlock_t lock;
307 struct semaphore open_sem;
308 mode_t open_mode;
309 wait_queue_head_t open_wait;
310
311 struct dmabuf {
312 void *rawbuf;
313 dma_addr_t dmaaddr;
314 unsigned buforder;
315 unsigned numfrag;
316 unsigned fragshift;
317 void* nextIn;
318 void* nextOut;
319 int count;
320 int curBufPtr;
321 unsigned total_bytes;
322 unsigned error; /* over/underrun */
323 wait_queue_head_t wait;
324 /* redundant, but makes calculations easier */
325 unsigned fragsize;
326 unsigned dmasize;
327 unsigned fragsamples;
328 /* OSS stuff */
329 unsigned mapped:1;
330 unsigned ready:1;
331 unsigned stopped:1;
332 unsigned ossfragshift;
333 int ossmaxfrags;
334 unsigned subdivision;
335 } dma_dac, dma_adc;
336};
337
338/* --------------------------------------------------------------------- */
339
340static LIST_HEAD(devs);
341
342/* --------------------------------------------------------------------- */
343
344static inline unsigned ld2(unsigned int x)
345{
346 unsigned r = 0;
347
348 if (x >= 0x10000) {
349 x >>= 16;
350 r += 16;
351 }
352 if (x >= 0x100) {
353 x >>= 8;
354 r += 8;
355 }
356 if (x >= 0x10) {
357 x >>= 4;
358 r += 4;
359 }
360 if (x >= 4) {
361 x >>= 2;
362 r += 2;
363 }
364 if (x >= 2)
365 r++;
366 return r;
367}
368
369/* --------------------------------------------------------------------- */
370
371static void it8172_delay(int msec)
372{
373 unsigned long tmo;
374 signed long tmo2;
375
376 if (in_interrupt())
377 return;
378
379 tmo = jiffies + (msec*HZ)/1000;
380 for (;;) {
381 tmo2 = tmo - jiffies;
382 if (tmo2 <= 0)
383 break;
384 schedule_timeout(tmo2);
385 }
386}
387
388
389static unsigned short
390get_compat_rate(unsigned* rate)
391{
392 unsigned rate_out = *rate;
393 unsigned short sr;
394
395 if (rate_out >= 46050) {
396 sr = CC_SR_48000; rate_out = 48000;
397 } else if (rate_out >= 41250) {
398 sr = CC_SR_44100; rate_out = 44100;
399 } else if (rate_out >= 35200) {
400 sr = CC_SR_38400; rate_out = 38400;
401 } else if (rate_out >= 27025) {
402 sr = CC_SR_32000; rate_out = 32000;
403 } else if (rate_out >= 20625) {
404 sr = CC_SR_22050; rate_out = 22050;
405 } else if (rate_out >= 17600) {
406 sr = CC_SR_19200; rate_out = 19200;
407 } else if (rate_out >= 13513) {
408 sr = CC_SR_16000; rate_out = 16000;
409 } else if (rate_out >= 10313) {
410 sr = CC_SR_11025; rate_out = 11025;
411 } else if (rate_out >= 8800) {
412 sr = CC_SR_9600; rate_out = 9600;
413 } else if (rate_out >= 6750) {
414 sr = CC_SR_8000; rate_out = 8000;
415 } else {
416 sr = CC_SR_5500; rate_out = 5500;
417 }
418
419 *rate = rate_out;
420 return sr;
421}
422
423static void set_adc_rate(struct it8172_state *s, unsigned rate)
424{
425 unsigned long flags;
426 unsigned short sr;
427
428 sr = get_compat_rate(&rate);
429
430 spin_lock_irqsave(&s->lock, flags);
431 s->capcc &= ~CC_SR_MASK;
432 s->capcc |= sr;
433 outw(s->capcc, s->io+IT_AC_CAPCC);
434 spin_unlock_irqrestore(&s->lock, flags);
435
436 s->adcrate = rate;
437}
438
439
440static void set_dac_rate(struct it8172_state *s, unsigned rate)
441{
442 unsigned long flags;
443 unsigned short sr;
444
445 sr = get_compat_rate(&rate);
446
447 spin_lock_irqsave(&s->lock, flags);
448 s->pcc &= ~CC_SR_MASK;
449 s->pcc |= sr;
450 outw(s->pcc, s->io+IT_AC_PCC);
451 spin_unlock_irqrestore(&s->lock, flags);
452
453 s->dacrate = rate;
454}
455
456
457/* --------------------------------------------------------------------- */
458
459static u16 rdcodec(struct ac97_codec *codec, u8 addr)
460{
461 struct it8172_state *s = (struct it8172_state *)codec->private_data;
462 unsigned long flags;
463 unsigned short circp, data;
464 int i;
465
466 spin_lock_irqsave(&s->lock, flags);
467
468 for (i = 0; i < POLL_COUNT; i++)
469 if (!(inw(s->io+IT_AC_CIRCP) & CIRCP_CPS))
470 break;
471 if (i == POLL_COUNT)
472 err("rdcodec: codec ready poll expired!");
473
474 circp = addr & CIRCP_CIA_MASK;
475 circp |= (codec->id << CIRCP_CID_BIT);
476 circp |= CIRCP_RWC; // read command
477 outw(circp, s->io+IT_AC_CIRCP);
478
479 /* now wait for the data */
480 for (i = 0; i < POLL_COUNT; i++)
481 if (inw(s->io+IT_AC_CIRCP) & CIRCP_DPVF)
482 break;
483 if (i == POLL_COUNT)
484 err("rdcodec: read poll expired!");
485
486 data = inw(s->io+IT_AC_CIRDP);
487 spin_unlock_irqrestore(&s->lock, flags);
488
489 return data;
490}
491
492
493static void wrcodec(struct ac97_codec *codec, u8 addr, u16 data)
494{
495 struct it8172_state *s = (struct it8172_state *)codec->private_data;
496 unsigned long flags;
497 unsigned short circp;
498 int i;
499
500 spin_lock_irqsave(&s->lock, flags);
501
502 for (i = 0; i < POLL_COUNT; i++)
503 if (!(inw(s->io+IT_AC_CIRCP) & CIRCP_CPS))
504 break;
505 if (i == POLL_COUNT)
506 err("wrcodec: codec ready poll expired!");
507
508 circp = addr & CIRCP_CIA_MASK;
509 circp |= (codec->id << CIRCP_CID_BIT);
510 circp &= ~CIRCP_RWC; // write command
511
512 outw(data, s->io+IT_AC_CIRDP); // send data first
513 outw(circp, s->io+IT_AC_CIRCP);
514
515 spin_unlock_irqrestore(&s->lock, flags);
516}
517
518
519static void waitcodec(struct ac97_codec *codec)
520{
521 unsigned short temp;
522
523 /* codec_wait is used to wait for a ready state after
524 an AC97_RESET. */
525 it8172_delay(10);
526
527 temp = rdcodec(codec, 0x26);
528
529 // If power down, power up
530 if (temp & 0x3f00) {
531 // Power on
532 wrcodec(codec, 0x26, 0);
533 it8172_delay(100);
534 // Reread
535 temp = rdcodec(codec, 0x26);
536 }
537
538 // Check if Codec REF,ANL,DAC,ADC ready***/
539 if ((temp & 0x3f0f) != 0x000f) {
540 err("codec reg 26 status (0x%x) not ready!!", temp);
541 return;
542 }
543}
544
545
546/* --------------------------------------------------------------------- */
547
548static inline void stop_adc(struct it8172_state *s)
549{
550 struct dmabuf* db = &s->dma_adc;
551 unsigned long flags;
552 unsigned char imc;
553
554 if (db->stopped)
555 return;
556
557 spin_lock_irqsave(&s->lock, flags);
558
559 s->capcc &= ~(CC_CA | CC_CP | CC_CB2L | CC_CB1L);
560 s->capcc |= CC_CSP;
561 outw(s->capcc, s->io+IT_AC_CAPCC);
562
563 // disable capture interrupt
564 imc = inb(s->io+IT_AC_IMC);
565 outb(imc | IMC_CCIM, s->io+IT_AC_IMC);
566
567 db->stopped = 1;
568
569 spin_unlock_irqrestore(&s->lock, flags);
570}
571
572static inline void stop_dac(struct it8172_state *s)
573{
574 struct dmabuf* db = &s->dma_dac;
575 unsigned long flags;
576 unsigned char imc;
577
578 if (db->stopped)
579 return;
580
581 spin_lock_irqsave(&s->lock, flags);
582
583 s->pcc &= ~(CC_CA | CC_CP | CC_CB2L | CC_CB1L);
584 s->pcc |= CC_CSP;
585 outw(s->pcc, s->io+IT_AC_PCC);
586
587 // disable playback interrupt
588 imc = inb(s->io+IT_AC_IMC);
589 outb(imc | IMC_PCIM, s->io+IT_AC_IMC);
590
591 db->stopped = 1;
592
593 spin_unlock_irqrestore(&s->lock, flags);
594}
595
596static void start_dac(struct it8172_state *s)
597{
598 struct dmabuf* db = &s->dma_dac;
599 unsigned long flags;
600 unsigned char imc;
601 unsigned long buf1, buf2;
602
603 if (!db->stopped)
604 return;
605
606 spin_lock_irqsave(&s->lock, flags);
607
608 // reset Buffer 1 and 2 pointers to nextOut and nextOut+fragsize
609 buf1 = virt_to_bus(db->nextOut);
610 buf2 = buf1 + db->fragsize;
611 if (buf2 >= db->dmaaddr + db->dmasize)
612 buf2 -= db->dmasize;
613
614 outl(buf1, s->io+IT_AC_PCB1STA);
615 outl(buf2, s->io+IT_AC_PCB2STA);
616 db->curBufPtr = IT_AC_PCB1STA;
617
618 // enable playback interrupt
619 imc = inb(s->io+IT_AC_IMC);
620 outb(imc & ~IMC_PCIM, s->io+IT_AC_IMC);
621
622 s->pcc &= ~(CC_CSP | CC_CP | CC_CB2L | CC_CB1L);
623 s->pcc |= CC_CA;
624 outw(s->pcc, s->io+IT_AC_PCC);
625
626 db->stopped = 0;
627
628 spin_unlock_irqrestore(&s->lock, flags);
629}
630
631static void start_adc(struct it8172_state *s)
632{
633 struct dmabuf* db = &s->dma_adc;
634 unsigned long flags;
635 unsigned char imc;
636 unsigned long buf1, buf2;
637
638 if (!db->stopped)
639 return;
640
641 spin_lock_irqsave(&s->lock, flags);
642
643 // reset Buffer 1 and 2 pointers to nextIn and nextIn+fragsize
644 buf1 = virt_to_bus(db->nextIn);
645 buf2 = buf1 + db->fragsize;
646 if (buf2 >= db->dmaaddr + db->dmasize)
647 buf2 -= db->dmasize;
648
649 outl(buf1, s->io+IT_AC_CAPB1STA);
650 outl(buf2, s->io+IT_AC_CAPB2STA);
651 db->curBufPtr = IT_AC_CAPB1STA;
652
653 // enable capture interrupt
654 imc = inb(s->io+IT_AC_IMC);
655 outb(imc & ~IMC_CCIM, s->io+IT_AC_IMC);
656
657 s->capcc &= ~(CC_CSP | CC_CP | CC_CB2L | CC_CB1L);
658 s->capcc |= CC_CA;
659 outw(s->capcc, s->io+IT_AC_CAPCC);
660
661 db->stopped = 0;
662
663 spin_unlock_irqrestore(&s->lock, flags);
664}
665
666/* --------------------------------------------------------------------- */
667
668#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
669#define DMABUF_MINORDER 1
670
671static inline void dealloc_dmabuf(struct it8172_state *s, struct dmabuf *db)
672{
673 struct page *page, *pend;
674
675 if (db->rawbuf) {
676 /* undo marking the pages as reserved */
677 pend = virt_to_page(db->rawbuf +
678 (PAGE_SIZE << db->buforder) - 1);
679 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
680 ClearPageReserved(page);
681 pci_free_consistent(s->dev, PAGE_SIZE << db->buforder,
682 db->rawbuf, db->dmaaddr);
683 }
684 db->rawbuf = db->nextIn = db->nextOut = NULL;
685 db->mapped = db->ready = 0;
686}
687
688static int prog_dmabuf(struct it8172_state *s, struct dmabuf *db,
689 unsigned rate, unsigned fmt, unsigned reg)
690{
691 int order;
692 unsigned bytepersec;
693 unsigned bufs;
694 struct page *page, *pend;
695
696 if (!db->rawbuf) {
697 db->ready = db->mapped = 0;
698 for (order = DMABUF_DEFAULTORDER;
699 order >= DMABUF_MINORDER; order--)
700 if ((db->rawbuf =
701 pci_alloc_consistent(s->dev,
702 PAGE_SIZE << order,
703 &db->dmaaddr)))
704 break;
705 if (!db->rawbuf)
706 return -ENOMEM;
707 db->buforder = order;
708 /* now mark the pages as reserved;
709 otherwise remap_pfn_range doesn't do what we want */
710 pend = virt_to_page(db->rawbuf +
711 (PAGE_SIZE << db->buforder) - 1);
712 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
713 SetPageReserved(page);
714 }
715
716 db->count = 0;
717 db->nextIn = db->nextOut = db->rawbuf;
718
719 bytepersec = rate << sample_shift[fmt];
720 bufs = PAGE_SIZE << db->buforder;
721 if (db->ossfragshift) {
722 if ((1000 << db->ossfragshift) < bytepersec)
723 db->fragshift = ld2(bytepersec/1000);
724 else
725 db->fragshift = db->ossfragshift;
726 } else {
727 db->fragshift = ld2(bytepersec/100/(db->subdivision ?
728 db->subdivision : 1));
729 if (db->fragshift < 3)
730 db->fragshift = 3;
731 }
732 db->numfrag = bufs >> db->fragshift;
733 while (db->numfrag < 4 && db->fragshift > 3) {
734 db->fragshift--;
735 db->numfrag = bufs >> db->fragshift;
736 }
737 db->fragsize = 1 << db->fragshift;
738 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
739 db->numfrag = db->ossmaxfrags;
740 db->fragsamples = db->fragsize >> sample_shift[fmt];
741 db->dmasize = db->numfrag << db->fragshift;
742 memset(db->rawbuf, (fmt & (CC_DF>>CC_FMT_BIT)) ? 0 : 0x80, bufs);
743
744#ifdef IT8172_VERBOSE_DEBUG
745 dbg("rate=%d, fragsize=%d, numfrag=%d, dmasize=%d",
746 rate, db->fragsize, db->numfrag, db->dmasize);
747#endif
748
749 // set data length register
750 outw(db->fragsize, s->io+reg+2);
751 db->ready = 1;
752
753 return 0;
754}
755
756static inline int prog_dmabuf_adc(struct it8172_state *s)
757{
758 stop_adc(s);
759 return prog_dmabuf(s, &s->dma_adc, s->adcrate,
760 (s->capcc & CC_FMT_MASK) >> CC_FMT_BIT,
761 IT_AC_CAPCC);
762}
763
764static inline int prog_dmabuf_dac(struct it8172_state *s)
765{
766 stop_dac(s);
767 return prog_dmabuf(s, &s->dma_dac, s->dacrate,
768 (s->pcc & CC_FMT_MASK) >> CC_FMT_BIT,
769 IT_AC_PCC);
770}
771
772
773/* hold spinlock for the following! */
774
775static irqreturn_t it8172_interrupt(int irq, void *dev_id, struct pt_regs *regs)
776{
777 struct it8172_state *s = (struct it8172_state *)dev_id;
778 struct dmabuf* dac = &s->dma_dac;
779 struct dmabuf* adc = &s->dma_adc;
780 unsigned char isc, vs;
781 unsigned short vol, mute;
782 unsigned long newptr;
783
784 spin_lock(&s->lock);
785
786 isc = inb(s->io+IT_AC_ISC);
787
788 /* fastpath out, to ease interrupt sharing */
789 if (!(isc & (ISC_VCI | ISC_CCI | ISC_PCI))) {
790 spin_unlock(&s->lock);
791 return IRQ_NONE;
792 }
793
794 /* clear audio interrupts first */
795 outb(isc | ISC_VCI | ISC_CCI | ISC_PCI, s->io+IT_AC_ISC);
796
797 /* handle volume button events (ignore if S/PDIF enabled) */
798 if ((isc & ISC_VCI) && s->spdif_volume == -1) {
799 vs = inb(s->io+IT_AC_VS);
800 outb(0, s->io+IT_AC_VS);
801 vol = inw(s->io+IT_AC_PCMOV);
802 mute = vol & PCMOV_PCMOM;
803 vol &= PCMOV_PCMLCG_MASK;
804 if ((vs & VS_VUP) && vol > 0)
805 vol--;
806 if ((vs & VS_VDP) && vol < 0x1f)
807 vol++;
808 vol |= (vol << PCMOV_PCMRCG_BIT);
809 if (vs & VS_VMP)
810 vol |= (mute ^ PCMOV_PCMOM);
811 outw(vol, s->io+IT_AC_PCMOV);
812 }
813
814 /* update capture pointers */
815 if (isc & ISC_CCI) {
816 if (adc->count > adc->dmasize - adc->fragsize) {
817 // Overrun. Stop ADC and log the error
818 stop_adc(s);
819 adc->error++;
820 dbg("adc overrun");
821 } else {
822 newptr = virt_to_bus(adc->nextIn) + 2*adc->fragsize;
823 if (newptr >= adc->dmaaddr + adc->dmasize)
824 newptr -= adc->dmasize;
825
826 outl(newptr, s->io+adc->curBufPtr);
827 adc->curBufPtr = (adc->curBufPtr == IT_AC_CAPB1STA) ?
828 IT_AC_CAPB2STA : IT_AC_CAPB1STA;
829
830 adc->nextIn += adc->fragsize;
831 if (adc->nextIn >= adc->rawbuf + adc->dmasize)
832 adc->nextIn -= adc->dmasize;
833
834 adc->count += adc->fragsize;
835 adc->total_bytes += adc->fragsize;
836
837 /* wake up anybody listening */
838 if (waitqueue_active(&adc->wait))
839 wake_up_interruptible(&adc->wait);
840 }
841 }
842
843 /* update playback pointers */
844 if (isc & ISC_PCI) {
845 newptr = virt_to_bus(dac->nextOut) + 2*dac->fragsize;
846 if (newptr >= dac->dmaaddr + dac->dmasize)
847 newptr -= dac->dmasize;
848
849 outl(newptr, s->io+dac->curBufPtr);
850 dac->curBufPtr = (dac->curBufPtr == IT_AC_PCB1STA) ?
851 IT_AC_PCB2STA : IT_AC_PCB1STA;
852
853 dac->nextOut += dac->fragsize;
854 if (dac->nextOut >= dac->rawbuf + dac->dmasize)
855 dac->nextOut -= dac->dmasize;
856
857 dac->count -= dac->fragsize;
858 dac->total_bytes += dac->fragsize;
859
860 /* wake up anybody listening */
861 if (waitqueue_active(&dac->wait))
862 wake_up_interruptible(&dac->wait);
863
864 if (dac->count <= 0)
865 stop_dac(s);
866 }
867
868 spin_unlock(&s->lock);
869 return IRQ_HANDLED;
870}
871
872/* --------------------------------------------------------------------- */
873
874static int it8172_open_mixdev(struct inode *inode, struct file *file)
875{
876 int minor = iminor(inode);
877 struct list_head *list;
878 struct it8172_state *s;
879
880 for (list = devs.next; ; list = list->next) {
881 if (list == &devs)
882 return -ENODEV;
883 s = list_entry(list, struct it8172_state, devs);
884 if (s->codec.dev_mixer == minor)
885 break;
886 }
887 file->private_data = s;
888 return nonseekable_open(inode, file);
889}
890
891static int it8172_release_mixdev(struct inode *inode, struct file *file)
892{
893 return 0;
894}
895
896
897static u16
898cvt_ossvol(unsigned int gain)
899{
900 u16 ret;
901
902 if (gain == 0)
903 return 0;
904
905 if (gain > 100)
906 gain = 100;
907
908 ret = (100 - gain + 32) / 4;
909 ret = ret > 31 ? 31 : ret;
910 return ret;
911}
912
913
914static int mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd,
915 unsigned long arg)
916{
917 struct it8172_state *s = (struct it8172_state *)codec->private_data;
918 unsigned int left, right;
919 unsigned long flags;
920 int val;
921 u16 vol;
922
923 /*
924 * When we are in S/PDIF mode, we want to disable any analog output so
925 * we filter the master/PCM channel volume ioctls.
926 *
927 * Also filter I2S channel, which AC'97 knows nothing about.
928 */
929
930 switch (cmd) {
931 case SOUND_MIXER_WRITE_VOLUME:
932 // if not in S/PDIF mode, pass to AC'97
933 if (s->spdif_volume == -1)
934 break;
935 return 0;
936 case SOUND_MIXER_WRITE_PCM:
937 // if not in S/PDIF mode, pass to AC'97
938 if (s->spdif_volume == -1)
939 break;
940 if (get_user(val, (int *)arg))
941 return -EFAULT;
942 right = ((val >> 8) & 0xff);
943 left = (val & 0xff);
944 if (right > 100)
945 right = 100;
946 if (left > 100)
947 left = 100;
948 s->spdif_volume = (right << 8) | left;
949 vol = cvt_ossvol(left);
950 vol |= (cvt_ossvol(right) << PCMOV_PCMRCG_BIT);
951 if (vol == 0)
952 vol = PCMOV_PCMOM; // mute
953 spin_lock_irqsave(&s->lock, flags);
954 outw(vol, s->io+IT_AC_PCMOV);
955 spin_unlock_irqrestore(&s->lock, flags);
956 return put_user(s->spdif_volume, (int *)arg);
957 case SOUND_MIXER_READ_PCM:
958 // if not in S/PDIF mode, pass to AC'97
959 if (s->spdif_volume == -1)
960 break;
961 return put_user(s->spdif_volume, (int *)arg);
962 case SOUND_MIXER_WRITE_I2S:
963 if (get_user(val, (int *)arg))
964 return -EFAULT;
965 right = ((val >> 8) & 0xff);
966 left = (val & 0xff);
967 if (right > 100)
968 right = 100;
969 if (left > 100)
970 left = 100;
971 s->i2s_volume = (right << 8) | left;
972 vol = cvt_ossvol(left);
973 vol |= (cvt_ossvol(right) << I2SV_I2SRCG_BIT);
974 if (vol == 0)
975 vol = I2SV_I2SOM; // mute
976 outw(vol, s->io+IT_AC_I2SV);
977 return put_user(s->i2s_volume, (int *)arg);
978 case SOUND_MIXER_READ_I2S:
979 return put_user(s->i2s_volume, (int *)arg);
980 case SOUND_MIXER_WRITE_RECSRC:
981 if (get_user(val, (int *)arg))
982 return -EFAULT;
983 if (val & SOUND_MASK_I2S) {
984 s->i2s_recording = 1;
985 outb(DRSS_I2S, s->io+IT_AC_DRSS);
986 return 0;
987 } else {
988 s->i2s_recording = 0;
989 outb(DRSS_AC97_PRIM, s->io+IT_AC_DRSS);
990 // now let AC'97 select record source
991 break;
992 }
993 case SOUND_MIXER_READ_RECSRC:
994 if (s->i2s_recording)
995 return put_user(SOUND_MASK_I2S, (int *)arg);
996 else
997 // let AC'97 report recording source
998 break;
999 }
1000
1001 return codec->mixer_ioctl(codec, cmd, arg);
1002}
1003
1004static int it8172_ioctl_mixdev(struct inode *inode, struct file *file,
1005 unsigned int cmd, unsigned long arg)
1006{
1007 struct it8172_state *s = (struct it8172_state *)file->private_data;
1008 struct ac97_codec *codec = &s->codec;
1009
1010 return mixdev_ioctl(codec, cmd, arg);
1011}
1012
1013static /*const*/ struct file_operations it8172_mixer_fops = {
1014 .owner = THIS_MODULE,
1015 .llseek = no_llseek,
1016 .ioctl = it8172_ioctl_mixdev,
1017 .open = it8172_open_mixdev,
1018 .release = it8172_release_mixdev,
1019};
1020
1021/* --------------------------------------------------------------------- */
1022
1023static int drain_dac(struct it8172_state *s, int nonblock)
1024{
1025 unsigned long flags;
1026 int count, tmo;
1027
1028 if (s->dma_dac.mapped || !s->dma_dac.ready || s->dma_dac.stopped)
1029 return 0;
1030
1031 for (;;) {
1032 spin_lock_irqsave(&s->lock, flags);
1033 count = s->dma_dac.count;
1034 spin_unlock_irqrestore(&s->lock, flags);
1035 if (count <= 0)
1036 break;
1037 if (signal_pending(current))
1038 break;
1039 //if (nonblock)
1040 //return -EBUSY;
1041 tmo = 1000 * count / s->dacrate;
1042 tmo >>= sample_shift[(s->pcc & CC_FMT_MASK) >> CC_FMT_BIT];
1043 it8172_delay(tmo);
1044 }
1045 if (signal_pending(current))
1046 return -ERESTARTSYS;
1047 return 0;
1048}
1049
1050/* --------------------------------------------------------------------- */
1051
1052
1053/*
1054 * Copy audio data to/from user buffer from/to dma buffer, taking care
1055 * that we wrap when reading/writing the dma buffer. Returns actual byte
1056 * count written to or read from the dma buffer.
1057 */
1058static int copy_dmabuf_user(struct dmabuf *db, char* userbuf,
1059 int count, int to_user)
1060{
1061 char* bufptr = to_user ? db->nextOut : db->nextIn;
1062 char* bufend = db->rawbuf + db->dmasize;
1063
1064 if (bufptr + count > bufend) {
1065 int partial = (int)(bufend - bufptr);
1066 if (to_user) {
1067 if (copy_to_user(userbuf, bufptr, partial))
1068 return -EFAULT;
1069 if (copy_to_user(userbuf + partial, db->rawbuf,
1070 count - partial))
1071 return -EFAULT;
1072 } else {
1073 if (copy_from_user(bufptr, userbuf, partial))
1074 return -EFAULT;
1075 if (copy_from_user(db->rawbuf,
1076 userbuf + partial,
1077 count - partial))
1078 return -EFAULT;
1079 }
1080 } else {
1081 if (to_user) {
1082 if (copy_to_user(userbuf, bufptr, count))
1083 return -EFAULT;
1084 } else {
1085 if (copy_from_user(bufptr, userbuf, count))
1086 return -EFAULT;
1087 }
1088 }
1089
1090 return count;
1091}
1092
1093
1094static ssize_t it8172_read(struct file *file, char *buffer,
1095 size_t count, loff_t *ppos)
1096{
1097 struct it8172_state *s = (struct it8172_state *)file->private_data;
1098 struct dmabuf *db = &s->dma_adc;
1099 ssize_t ret;
1100 unsigned long flags;
1101 int cnt, remainder, avail;
1102
1103 if (db->mapped)
1104 return -ENXIO;
1105 if (!access_ok(VERIFY_WRITE, buffer, count))
1106 return -EFAULT;
1107 ret = 0;
1108
1109 while (count > 0) {
1110 // wait for samples in capture buffer
1111 do {
1112 spin_lock_irqsave(&s->lock, flags);
1113 if (db->stopped)
1114 start_adc(s);
1115 avail = db->count;
1116 spin_unlock_irqrestore(&s->lock, flags);
1117 if (avail <= 0) {
1118 if (file->f_flags & O_NONBLOCK) {
1119 if (!ret)
1120 ret = -EAGAIN;
1121 return ret;
1122 }
1123 interruptible_sleep_on(&db->wait);
1124 if (signal_pending(current)) {
1125 if (!ret)
1126 ret = -ERESTARTSYS;
1127 return ret;
1128 }
1129 }
1130 } while (avail <= 0);
1131
1132 // copy from nextOut to user
1133 if ((cnt = copy_dmabuf_user(db, buffer, count > avail ?
1134 avail : count, 1)) < 0) {
1135 if (!ret)
1136 ret = -EFAULT;
1137 return ret;
1138 }
1139
1140 spin_lock_irqsave(&s->lock, flags);
1141 db->count -= cnt;
1142 spin_unlock_irqrestore(&s->lock, flags);
1143
1144 db->nextOut += cnt;
1145 if (db->nextOut >= db->rawbuf + db->dmasize)
1146 db->nextOut -= db->dmasize;
1147
1148 count -= cnt;
1149 buffer += cnt;
1150 ret += cnt;
1151 } // while (count > 0)
1152
1153 /*
1154 * See if the dma buffer count after this read call is
1155 * aligned on a fragsize boundary. If not, read from
1156 * buffer until we reach a boundary, and let's hope this
1157 * is just the last remainder of an audio record. If not
1158 * it means the user is not reading in fragsize chunks, in
1159 * which case it's his/her fault that there are audio gaps
1160 * in their record.
1161 */
1162 spin_lock_irqsave(&s->lock, flags);
1163 remainder = db->count % db->fragsize;
1164 if (remainder) {
1165 db->nextOut += remainder;
1166 if (db->nextOut >= db->rawbuf + db->dmasize)
1167 db->nextOut -= db->dmasize;
1168 db->count -= remainder;
1169 }
1170 spin_unlock_irqrestore(&s->lock, flags);
1171
1172 return ret;
1173}
1174
1175static ssize_t it8172_write(struct file *file, const char *buffer,
1176 size_t count, loff_t *ppos)
1177{
1178 struct it8172_state *s = (struct it8172_state *)file->private_data;
1179 struct dmabuf *db = &s->dma_dac;
1180 ssize_t ret;
1181 unsigned long flags;
1182 int cnt, remainder, avail;
1183
1184 if (db->mapped)
1185 return -ENXIO;
1186 if (!access_ok(VERIFY_READ, buffer, count))
1187 return -EFAULT;
1188 ret = 0;
1189
1190 while (count > 0) {
1191 // wait for space in playback buffer
1192 do {
1193 spin_lock_irqsave(&s->lock, flags);
1194 avail = db->dmasize - db->count;
1195 spin_unlock_irqrestore(&s->lock, flags);
1196 if (avail <= 0) {
1197 if (file->f_flags & O_NONBLOCK) {
1198 if (!ret)
1199 ret = -EAGAIN;
1200 return ret;
1201 }
1202 interruptible_sleep_on(&db->wait);
1203 if (signal_pending(current)) {
1204 if (!ret)
1205 ret = -ERESTARTSYS;
1206 return ret;
1207 }
1208 }
1209 } while (avail <= 0);
1210
1211 // copy to nextIn
1212 if ((cnt = copy_dmabuf_user(db, (char*)buffer,
1213 count > avail ?
1214 avail : count, 0)) < 0) {
1215 if (!ret)
1216 ret = -EFAULT;
1217 return ret;
1218 }
1219
1220 spin_lock_irqsave(&s->lock, flags);
1221 db->count += cnt;
1222 if (db->stopped)
1223 start_dac(s);
1224 spin_unlock_irqrestore(&s->lock, flags);
1225
1226 db->nextIn += cnt;
1227 if (db->nextIn >= db->rawbuf + db->dmasize)
1228 db->nextIn -= db->dmasize;
1229
1230 count -= cnt;
1231 buffer += cnt;
1232 ret += cnt;
1233 } // while (count > 0)
1234
1235 /*
1236 * See if the dma buffer count after this write call is
1237 * aligned on a fragsize boundary. If not, fill buffer
1238 * with silence to the next boundary, and let's hope this
1239 * is just the last remainder of an audio playback. If not
1240 * it means the user is not sending us fragsize chunks, in
1241 * which case it's his/her fault that there are audio gaps
1242 * in their playback.
1243 */
1244 spin_lock_irqsave(&s->lock, flags);
1245 remainder = db->count % db->fragsize;
1246 if (remainder) {
1247 int fill_cnt = db->fragsize - remainder;
1248 memset(db->nextIn, 0, fill_cnt);
1249 db->nextIn += fill_cnt;
1250 if (db->nextIn >= db->rawbuf + db->dmasize)
1251 db->nextIn -= db->dmasize;
1252 db->count += fill_cnt;
1253 }
1254 spin_unlock_irqrestore(&s->lock, flags);
1255
1256 return ret;
1257}
1258
1259/* No kernel lock - we have our own spinlock */
1260static unsigned int it8172_poll(struct file *file,
1261 struct poll_table_struct *wait)
1262{
1263 struct it8172_state *s = (struct it8172_state *)file->private_data;
1264 unsigned long flags;
1265 unsigned int mask = 0;
1266
1267 if (file->f_mode & FMODE_WRITE) {
1268 if (!s->dma_dac.ready)
1269 return 0;
1270 poll_wait(file, &s->dma_dac.wait, wait);
1271 }
1272 if (file->f_mode & FMODE_READ) {
1273 if (!s->dma_adc.ready)
1274 return 0;
1275 poll_wait(file, &s->dma_adc.wait, wait);
1276 }
1277
1278 spin_lock_irqsave(&s->lock, flags);
1279 if (file->f_mode & FMODE_READ) {
1280 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1281 mask |= POLLIN | POLLRDNORM;
1282 }
1283 if (file->f_mode & FMODE_WRITE) {
1284 if (s->dma_dac.mapped) {
1285 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
1286 mask |= POLLOUT | POLLWRNORM;
1287 } else {
1288 if ((signed)s->dma_dac.dmasize >=
1289 s->dma_dac.count + (signed)s->dma_dac.fragsize)
1290 mask |= POLLOUT | POLLWRNORM;
1291 }
1292 }
1293 spin_unlock_irqrestore(&s->lock, flags);
1294 return mask;
1295}
1296
1297static int it8172_mmap(struct file *file, struct vm_area_struct *vma)
1298{
1299 struct it8172_state *s = (struct it8172_state *)file->private_data;
1300 struct dmabuf *db;
1301 unsigned long size;
1302
1303 lock_kernel();
1304 if (vma->vm_flags & VM_WRITE)
1305 db = &s->dma_dac;
1306 else if (vma->vm_flags & VM_READ)
1307 db = &s->dma_adc;
1308 else {
1309 unlock_kernel();
1310 return -EINVAL;
1311 }
1312 if (vma->vm_pgoff != 0) {
1313 unlock_kernel();
1314 return -EINVAL;
1315 }
1316 size = vma->vm_end - vma->vm_start;
1317 if (size > (PAGE_SIZE << db->buforder)) {
1318 unlock_kernel();
1319 return -EINVAL;
1320 }
1321 if (remap_pfn_range(vma, vma->vm_start,
1322 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
1323 size, vma->vm_page_prot)) {
1324 unlock_kernel();
1325 return -EAGAIN;
1326 }
1327 db->mapped = 1;
1328 unlock_kernel();
1329 return 0;
1330}
1331
1332
1333#ifdef IT8172_VERBOSE_DEBUG
1334static struct ioctl_str_t {
1335 unsigned int cmd;
1336 const char* str;
1337} ioctl_str[] = {
1338 {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"},
1339 {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"},
1340 {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"},
1341 {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"},
1342 {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"},
1343 {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"},
1344 {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"},
1345 {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"},
1346 {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"},
1347 {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"},
1348 {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"},
1349 {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"},
1350 {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"},
1351 {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"},
1352 {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"},
1353 {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"},
1354 {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"},
1355 {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"},
1356 {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"},
1357 {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"},
1358 {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"},
1359 {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"},
1360 {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"},
1361 {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"},
1362 {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"},
1363 {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"},
1364 {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"},
1365 {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"},
1366 {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"},
1367 {OSS_GETVERSION, "OSS_GETVERSION"},
1368 {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"},
1369 {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"},
1370 {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"},
1371 {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"}
1372};
1373#endif
1374
1375static int it8172_ioctl(struct inode *inode, struct file *file,
1376 unsigned int cmd, unsigned long arg)
1377{
1378 struct it8172_state *s = (struct it8172_state *)file->private_data;
1379 unsigned long flags;
1380 audio_buf_info abinfo;
1381 count_info cinfo;
1382 int count;
1383 int val, mapped, ret, diff;
1384
1385 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1386 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1387
1388#ifdef IT8172_VERBOSE_DEBUG
1389 for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
1390 if (ioctl_str[count].cmd == cmd)
1391 break;
1392 }
1393 if (count < sizeof(ioctl_str)/sizeof(ioctl_str[0]))
1394 dbg("ioctl %s, arg=0x%08x",
1395 ioctl_str[count].str, (unsigned int)arg);
1396 else
1397 dbg("ioctl unknown, 0x%x", cmd);
1398#endif
1399
1400 switch (cmd) {
1401 case OSS_GETVERSION:
1402 return put_user(SOUND_VERSION, (int *)arg);
1403
1404 case SNDCTL_DSP_SYNC:
1405 if (file->f_mode & FMODE_WRITE)
1406 return drain_dac(s, file->f_flags & O_NONBLOCK);
1407 return 0;
1408
1409 case SNDCTL_DSP_SETDUPLEX:
1410 return 0;
1411
1412 case SNDCTL_DSP_GETCAPS:
1413 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
1414 DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg);
1415
1416 case SNDCTL_DSP_RESET:
1417 if (file->f_mode & FMODE_WRITE) {
1418 stop_dac(s);
1419 synchronize_irq(s->irq);
1420 s->dma_dac.count = s->dma_dac.total_bytes = 0;
1421 s->dma_dac.nextIn = s->dma_dac.nextOut =
1422 s->dma_dac.rawbuf;
1423 }
1424 if (file->f_mode & FMODE_READ) {
1425 stop_adc(s);
1426 synchronize_irq(s->irq);
1427 s->dma_adc.count = s->dma_adc.total_bytes = 0;
1428 s->dma_adc.nextIn = s->dma_adc.nextOut =
1429 s->dma_adc.rawbuf;
1430 }
1431 return 0;
1432
1433 case SNDCTL_DSP_SPEED:
1434 if (get_user(val, (int *)arg))
1435 return -EFAULT;
1436 if (val >= 0) {
1437 if (file->f_mode & FMODE_READ) {
1438 stop_adc(s);
1439 set_adc_rate(s, val);
1440 if ((ret = prog_dmabuf_adc(s)))
1441 return ret;
1442 }
1443 if (file->f_mode & FMODE_WRITE) {
1444 stop_dac(s);
1445 set_dac_rate(s, val);
1446 if ((ret = prog_dmabuf_dac(s)))
1447 return ret;
1448 }
1449 }
1450 return put_user((file->f_mode & FMODE_READ) ?
1451 s->adcrate : s->dacrate, (int *)arg);
1452
1453 case SNDCTL_DSP_STEREO:
1454 if (get_user(val, (int *)arg))
1455 return -EFAULT;
1456 if (file->f_mode & FMODE_READ) {
1457 stop_adc(s);
1458 if (val)
1459 s->capcc |= CC_SM;
1460 else
1461 s->capcc &= ~CC_SM;
1462 outw(s->capcc, s->io+IT_AC_CAPCC);
1463 if ((ret = prog_dmabuf_adc(s)))
1464 return ret;
1465 }
1466 if (file->f_mode & FMODE_WRITE) {
1467 stop_dac(s);
1468 if (val)
1469 s->pcc |= CC_SM;
1470 else
1471 s->pcc &= ~CC_SM;
1472 outw(s->pcc, s->io+IT_AC_PCC);
1473 if ((ret = prog_dmabuf_dac(s)))
1474 return ret;
1475 }
1476 return 0;
1477
1478 case SNDCTL_DSP_CHANNELS:
1479 if (get_user(val, (int *)arg))
1480 return -EFAULT;
1481 if (val != 0) {
1482 if (file->f_mode & FMODE_READ) {
1483 stop_adc(s);
1484 if (val >= 2) {
1485 val = 2;
1486 s->capcc |= CC_SM;
1487 }
1488 else
1489 s->capcc &= ~CC_SM;
1490 outw(s->capcc, s->io+IT_AC_CAPCC);
1491 if ((ret = prog_dmabuf_adc(s)))
1492 return ret;
1493 }
1494 if (file->f_mode & FMODE_WRITE) {
1495 stop_dac(s);
1496 switch (val) {
1497 case 1:
1498 s->pcc &= ~CC_SM;
1499 break;
1500 case 2:
1501 s->pcc |= CC_SM;
1502 break;
1503 default:
1504 // FIX! support multichannel???
1505 val = 2;
1506 s->pcc |= CC_SM;
1507 break;
1508 }
1509 outw(s->pcc, s->io+IT_AC_PCC);
1510 if ((ret = prog_dmabuf_dac(s)))
1511 return ret;
1512 }
1513 }
1514 return put_user(val, (int *)arg);
1515
1516 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1517 return put_user(AFMT_S16_LE|AFMT_U8, (int *)arg);
1518
1519 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1520 if (get_user(val, (int *)arg))
1521 return -EFAULT;
1522 if (val != AFMT_QUERY) {
1523 if (file->f_mode & FMODE_READ) {
1524 stop_adc(s);
1525 if (val == AFMT_S16_LE)
1526 s->capcc |= CC_DF;
1527 else {
1528 val = AFMT_U8;
1529 s->capcc &= ~CC_DF;
1530 }
1531 outw(s->capcc, s->io+IT_AC_CAPCC);
1532 if ((ret = prog_dmabuf_adc(s)))
1533 return ret;
1534 }
1535 if (file->f_mode & FMODE_WRITE) {
1536 stop_dac(s);
1537 if (val == AFMT_S16_LE)
1538 s->pcc |= CC_DF;
1539 else {
1540 val = AFMT_U8;
1541 s->pcc &= ~CC_DF;
1542 }
1543 outw(s->pcc, s->io+IT_AC_PCC);
1544 if ((ret = prog_dmabuf_dac(s)))
1545 return ret;
1546 }
1547 } else {
1548 if (file->f_mode & FMODE_READ)
1549 val = (s->capcc & CC_DF) ?
1550 AFMT_S16_LE : AFMT_U8;
1551 else
1552 val = (s->pcc & CC_DF) ?
1553 AFMT_S16_LE : AFMT_U8;
1554 }
1555 return put_user(val, (int *)arg);
1556
1557 case SNDCTL_DSP_POST:
1558 return 0;
1559
1560 case SNDCTL_DSP_GETTRIGGER:
1561 val = 0;
1562 spin_lock_irqsave(&s->lock, flags);
1563 if (file->f_mode & FMODE_READ && !s->dma_adc.stopped)
1564 val |= PCM_ENABLE_INPUT;
1565 if (file->f_mode & FMODE_WRITE && !s->dma_dac.stopped)
1566 val |= PCM_ENABLE_OUTPUT;
1567 spin_unlock_irqrestore(&s->lock, flags);
1568 return put_user(val, (int *)arg);
1569
1570 case SNDCTL_DSP_SETTRIGGER:
1571 if (get_user(val, (int *)arg))
1572 return -EFAULT;
1573 if (file->f_mode & FMODE_READ) {
1574 if (val & PCM_ENABLE_INPUT)
1575 start_adc(s);
1576 else
1577 stop_adc(s);
1578 }
1579 if (file->f_mode & FMODE_WRITE) {
1580 if (val & PCM_ENABLE_OUTPUT)
1581 start_dac(s);
1582 else
1583 stop_dac(s);
1584 }
1585 return 0;
1586
1587 case SNDCTL_DSP_GETOSPACE:
1588 if (!(file->f_mode & FMODE_WRITE))
1589 return -EINVAL;
1590 abinfo.fragsize = s->dma_dac.fragsize;
1591 spin_lock_irqsave(&s->lock, flags);
1592 count = s->dma_dac.count;
1593 if (!s->dma_dac.stopped)
1594 count -= (s->dma_dac.fragsize -
1595 inw(s->io+IT_AC_PCDL));
1596 spin_unlock_irqrestore(&s->lock, flags);
1597 if (count < 0)
1598 count = 0;
1599 abinfo.bytes = s->dma_dac.dmasize - count;
1600 abinfo.fragstotal = s->dma_dac.numfrag;
1601 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
1602 return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ?
1603 -EFAULT : 0;
1604
1605 case SNDCTL_DSP_GETISPACE:
1606 if (!(file->f_mode & FMODE_READ))
1607 return -EINVAL;
1608 abinfo.fragsize = s->dma_adc.fragsize;
1609 spin_lock_irqsave(&s->lock, flags);
1610 count = s->dma_adc.count;
1611 if (!s->dma_adc.stopped)
1612 count += (s->dma_adc.fragsize -
1613 inw(s->io+IT_AC_CAPCDL));
1614 spin_unlock_irqrestore(&s->lock, flags);
1615 if (count < 0)
1616 count = 0;
1617 abinfo.bytes = count;
1618 abinfo.fragstotal = s->dma_adc.numfrag;
1619 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1620 return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ?
1621 -EFAULT : 0;
1622
1623 case SNDCTL_DSP_NONBLOCK:
1624 file->f_flags |= O_NONBLOCK;
1625 return 0;
1626
1627 case SNDCTL_DSP_GETODELAY:
1628 if (!(file->f_mode & FMODE_WRITE))
1629 return -EINVAL;
1630 spin_lock_irqsave(&s->lock, flags);
1631 count = s->dma_dac.count;
1632 if (!s->dma_dac.stopped)
1633 count -= (s->dma_dac.fragsize -
1634 inw(s->io+IT_AC_PCDL));
1635 spin_unlock_irqrestore(&s->lock, flags);
1636 if (count < 0)
1637 count = 0;
1638 return put_user(count, (int *)arg);
1639
1640 case SNDCTL_DSP_GETIPTR:
1641 if (!(file->f_mode & FMODE_READ))
1642 return -EINVAL;
1643 spin_lock_irqsave(&s->lock, flags);
1644 cinfo.bytes = s->dma_adc.total_bytes;
1645 count = s->dma_adc.count;
1646 if (!s->dma_adc.stopped) {
1647 diff = s->dma_adc.fragsize - inw(s->io+IT_AC_CAPCDL);
1648 count += diff;
1649 cinfo.bytes += diff;
1650 cinfo.ptr = inl(s->io+s->dma_adc.curBufPtr) -
1651 s->dma_adc.dmaaddr;
1652 } else
1653 cinfo.ptr = virt_to_bus(s->dma_adc.nextIn) -
1654 s->dma_adc.dmaaddr;
1655 if (s->dma_adc.mapped)
1656 s->dma_adc.count &= s->dma_adc.fragsize-1;
1657 spin_unlock_irqrestore(&s->lock, flags);
1658 if (count < 0)
1659 count = 0;
1660 cinfo.blocks = count >> s->dma_adc.fragshift;
1661 if (copy_to_user((void *)arg, &cinfo, sizeof(cinfo)))
1662 return -EFAULT;
1663 return 0;
1664
1665 case SNDCTL_DSP_GETOPTR:
1666 if (!(file->f_mode & FMODE_READ))
1667 return -EINVAL;
1668 spin_lock_irqsave(&s->lock, flags);
1669 cinfo.bytes = s->dma_dac.total_bytes;
1670 count = s->dma_dac.count;
1671 if (!s->dma_dac.stopped) {
1672 diff = s->dma_dac.fragsize - inw(s->io+IT_AC_CAPCDL);
1673 count -= diff;
1674 cinfo.bytes += diff;
1675 cinfo.ptr = inl(s->io+s->dma_dac.curBufPtr) -
1676 s->dma_dac.dmaaddr;
1677 } else
1678 cinfo.ptr = virt_to_bus(s->dma_dac.nextOut) -
1679 s->dma_dac.dmaaddr;
1680 if (s->dma_dac.mapped)
1681 s->dma_dac.count &= s->dma_dac.fragsize-1;
1682 spin_unlock_irqrestore(&s->lock, flags);
1683 if (count < 0)
1684 count = 0;
1685 cinfo.blocks = count >> s->dma_dac.fragshift;
1686 if (copy_to_user((void *)arg, &cinfo, sizeof(cinfo)))
1687 return -EFAULT;
1688 return 0;
1689
1690 case SNDCTL_DSP_GETBLKSIZE:
1691 if (file->f_mode & FMODE_WRITE)
1692 return put_user(s->dma_dac.fragsize, (int *)arg);
1693 else
1694 return put_user(s->dma_adc.fragsize, (int *)arg);
1695
1696 case SNDCTL_DSP_SETFRAGMENT:
1697 if (get_user(val, (int *)arg))
1698 return -EFAULT;
1699 if (file->f_mode & FMODE_READ) {
1700 stop_adc(s);
1701 s->dma_adc.ossfragshift = val & 0xffff;
1702 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1703 if (s->dma_adc.ossfragshift < 4)
1704 s->dma_adc.ossfragshift = 4;
1705 if (s->dma_adc.ossfragshift > 15)
1706 s->dma_adc.ossfragshift = 15;
1707 if (s->dma_adc.ossmaxfrags < 4)
1708 s->dma_adc.ossmaxfrags = 4;
1709 if ((ret = prog_dmabuf_adc(s)))
1710 return ret;
1711 }
1712 if (file->f_mode & FMODE_WRITE) {
1713 stop_dac(s);
1714 s->dma_dac.ossfragshift = val & 0xffff;
1715 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
1716 if (s->dma_dac.ossfragshift < 4)
1717 s->dma_dac.ossfragshift = 4;
1718 if (s->dma_dac.ossfragshift > 15)
1719 s->dma_dac.ossfragshift = 15;
1720 if (s->dma_dac.ossmaxfrags < 4)
1721 s->dma_dac.ossmaxfrags = 4;
1722 if ((ret = prog_dmabuf_dac(s)))
1723 return ret;
1724 }
1725 return 0;
1726
1727 case SNDCTL_DSP_SUBDIVIDE:
1728 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1729 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
1730 return -EINVAL;
1731 if (get_user(val, (int *)arg))
1732 return -EFAULT;
1733 if (val != 1 && val != 2 && val != 4)
1734 return -EINVAL;
1735 if (file->f_mode & FMODE_READ) {
1736 stop_adc(s);
1737 s->dma_adc.subdivision = val;
1738 if ((ret = prog_dmabuf_adc(s)))
1739 return ret;
1740 }
1741 if (file->f_mode & FMODE_WRITE) {
1742 stop_dac(s);
1743 s->dma_dac.subdivision = val;
1744 if ((ret = prog_dmabuf_dac(s)))
1745 return ret;
1746 }
1747 return 0;
1748
1749 case SOUND_PCM_READ_RATE:
1750 return put_user((file->f_mode & FMODE_READ) ?
1751 s->adcrate : s->dacrate, (int *)arg);
1752
1753 case SOUND_PCM_READ_CHANNELS:
1754 if (file->f_mode & FMODE_READ)
1755 return put_user((s->capcc & CC_SM) ? 2 : 1,
1756 (int *)arg);
1757 else
1758 return put_user((s->pcc & CC_SM) ? 2 : 1,
1759 (int *)arg);
1760
1761 case SOUND_PCM_READ_BITS:
1762 if (file->f_mode & FMODE_READ)
1763 return put_user((s->capcc & CC_DF) ? 16 : 8,
1764 (int *)arg);
1765 else
1766 return put_user((s->pcc & CC_DF) ? 16 : 8,
1767 (int *)arg);
1768
1769 case SOUND_PCM_WRITE_FILTER:
1770 case SNDCTL_DSP_SETSYNCRO:
1771 case SOUND_PCM_READ_FILTER:
1772 return -EINVAL;
1773 }
1774
1775 return mixdev_ioctl(&s->codec, cmd, arg);
1776}
1777
1778
1779static int it8172_open(struct inode *inode, struct file *file)
1780{
1781 int minor = iminor(inode);
1782 DECLARE_WAITQUEUE(wait, current);
1783 unsigned long flags;
1784 struct list_head *list;
1785 struct it8172_state *s;
1786 int ret;
1787
1788#ifdef IT8172_VERBOSE_DEBUG
1789 if (file->f_flags & O_NONBLOCK)
1790 dbg("%s: non-blocking", __FUNCTION__);
1791 else
1792 dbg("%s: blocking", __FUNCTION__);
1793#endif
1794
1795 for (list = devs.next; ; list = list->next) {
1796 if (list == &devs)
1797 return -ENODEV;
1798 s = list_entry(list, struct it8172_state, devs);
1799 if (!((s->dev_audio ^ minor) & ~0xf))
1800 break;
1801 }
1802 file->private_data = s;
1803 /* wait for device to become free */
1804 down(&s->open_sem);
1805 while (s->open_mode & file->f_mode) {
1806 if (file->f_flags & O_NONBLOCK) {
1807 up(&s->open_sem);
1808 return -EBUSY;
1809 }
1810 add_wait_queue(&s->open_wait, &wait);
1811 __set_current_state(TASK_INTERRUPTIBLE);
1812 up(&s->open_sem);
1813 schedule();
1814 remove_wait_queue(&s->open_wait, &wait);
1815 set_current_state(TASK_RUNNING);
1816 if (signal_pending(current))
1817 return -ERESTARTSYS;
1818 down(&s->open_sem);
1819 }
1820
1821 spin_lock_irqsave(&s->lock, flags);
1822
1823 if (file->f_mode & FMODE_READ) {
1824 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
1825 s->dma_adc.subdivision = s->dma_adc.total_bytes = 0;
1826 s->capcc &= ~(CC_SM | CC_DF);
1827 set_adc_rate(s, 8000);
1828 if ((minor & 0xf) == SND_DEV_DSP16)
1829 s->capcc |= CC_DF;
1830 outw(s->capcc, s->io+IT_AC_CAPCC);
1831 if ((ret = prog_dmabuf_adc(s))) {
1832 spin_unlock_irqrestore(&s->lock, flags);
1833 return ret;
1834 }
1835 }
1836 if (file->f_mode & FMODE_WRITE) {
1837 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
1838 s->dma_dac.subdivision = s->dma_dac.total_bytes = 0;
1839 s->pcc &= ~(CC_SM | CC_DF);
1840 set_dac_rate(s, 8000);
1841 if ((minor & 0xf) == SND_DEV_DSP16)
1842 s->pcc |= CC_DF;
1843 outw(s->pcc, s->io+IT_AC_PCC);
1844 if ((ret = prog_dmabuf_dac(s))) {
1845 spin_unlock_irqrestore(&s->lock, flags);
1846 return ret;
1847 }
1848 }
1849
1850 spin_unlock_irqrestore(&s->lock, flags);
1851
1852 s->open_mode |= (file->f_mode & (FMODE_READ | FMODE_WRITE));
1853 up(&s->open_sem);
1854 return nonseekable_open(inode, file);
1855}
1856
1857static int it8172_release(struct inode *inode, struct file *file)
1858{
1859 struct it8172_state *s = (struct it8172_state *)file->private_data;
1860
1861#ifdef IT8172_VERBOSE_DEBUG
1862 dbg(__FUNCTION__);
1863#endif
1864 lock_kernel();
1865 if (file->f_mode & FMODE_WRITE)
1866 drain_dac(s, file->f_flags & O_NONBLOCK);
1867 down(&s->open_sem);
1868 if (file->f_mode & FMODE_WRITE) {
1869 stop_dac(s);
1870 dealloc_dmabuf(s, &s->dma_dac);
1871 }
1872 if (file->f_mode & FMODE_READ) {
1873 stop_adc(s);
1874 dealloc_dmabuf(s, &s->dma_adc);
1875 }
1876 s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
1877 up(&s->open_sem);
1878 wake_up(&s->open_wait);
1879 unlock_kernel();
1880 return 0;
1881}
1882
1883static /*const*/ struct file_operations it8172_audio_fops = {
1884 .owner = THIS_MODULE,
1885 .llseek = no_llseek,
1886 .read = it8172_read,
1887 .write = it8172_write,
1888 .poll = it8172_poll,
1889 .ioctl = it8172_ioctl,
1890 .mmap = it8172_mmap,
1891 .open = it8172_open,
1892 .release = it8172_release,
1893};
1894
1895
1896/* --------------------------------------------------------------------- */
1897
1898
1899/* --------------------------------------------------------------------- */
1900
1901/*
1902 * for debugging purposes, we'll create a proc device that dumps the
1903 * CODEC chipstate
1904 */
1905
1906#ifdef IT8172_DEBUG
1907static int proc_it8172_dump (char *buf, char **start, off_t fpos,
1908 int length, int *eof, void *data)
1909{
1910 struct it8172_state *s;
1911 int cnt, len = 0;
1912
1913 if (list_empty(&devs))
1914 return 0;
1915 s = list_entry(devs.next, struct it8172_state, devs);
1916
1917 /* print out header */
1918 len += sprintf(buf + len, "\n\t\tIT8172 Audio Debug\n\n");
1919
1920 // print out digital controller state
1921 len += sprintf (buf + len, "IT8172 Audio Controller registers\n");
1922 len += sprintf (buf + len, "---------------------------------\n");
1923 cnt=0;
1924 while (cnt < 0x72) {
1925 if (cnt == IT_AC_PCB1STA || cnt == IT_AC_PCB2STA ||
1926 cnt == IT_AC_CAPB1STA || cnt == IT_AC_CAPB2STA ||
1927 cnt == IT_AC_PFDP) {
1928 len+= sprintf (buf + len, "reg %02x = %08x\n",
1929 cnt, inl(s->io+cnt));
1930 cnt += 4;
1931 } else {
1932 len+= sprintf (buf + len, "reg %02x = %04x\n",
1933 cnt, inw(s->io+cnt));
1934 cnt += 2;
1935 }
1936 }
1937
1938 /* print out CODEC state */
1939 len += sprintf (buf + len, "\nAC97 CODEC registers\n");
1940 len += sprintf (buf + len, "----------------------\n");
1941 for (cnt=0; cnt <= 0x7e; cnt = cnt +2)
1942 len+= sprintf (buf + len, "reg %02x = %04x\n",
1943 cnt, rdcodec(&s->codec, cnt));
1944
1945 if (fpos >=len){
1946 *start = buf;
1947 *eof =1;
1948 return 0;
1949 }
1950 *start = buf + fpos;
1951 if ((len -= fpos) > length)
1952 return length;
1953 *eof =1;
1954 return len;
1955
1956}
1957#endif /* IT8172_DEBUG */
1958
1959/* --------------------------------------------------------------------- */
1960
1961/* maximum number of devices; only used for command line params */
1962#define NR_DEVICE 5
1963
1964static int spdif[NR_DEVICE];
1965static int i2s_fmt[NR_DEVICE];
1966
1967static unsigned int devindex;
1968
1969MODULE_PARM(spdif, "1-" __MODULE_STRING(NR_DEVICE) "i");
1970MODULE_PARM_DESC(spdif, "if 1 the S/PDIF digital output is enabled");
1971MODULE_PARM(i2s_fmt, "1-" __MODULE_STRING(NR_DEVICE) "i");
1972MODULE_PARM_DESC(i2s_fmt, "the format of I2S");
1973
1974MODULE_AUTHOR("Monta Vista Software, stevel@mvista.com");
1975MODULE_DESCRIPTION("IT8172 Audio Driver");
1976
1977/* --------------------------------------------------------------------- */
1978
1979static int __devinit it8172_probe(struct pci_dev *pcidev,
1980 const struct pci_device_id *pciid)
1981{
1982 struct it8172_state *s;
1983 int i, val;
1984 unsigned short pcisr, vol;
1985 unsigned char legacy, imc;
1986 char proc_str[80];
1987
1988 if (pcidev->irq == 0)
1989 return -1;
1990
1991 if (!(s = kmalloc(sizeof(struct it8172_state), GFP_KERNEL))) {
1992 err("alloc of device struct failed");
1993 return -1;
1994 }
1995
1996 memset(s, 0, sizeof(struct it8172_state));
1997 init_waitqueue_head(&s->dma_adc.wait);
1998 init_waitqueue_head(&s->dma_dac.wait);
1999 init_waitqueue_head(&s->open_wait);
2000 init_MUTEX(&s->open_sem);
2001 spin_lock_init(&s->lock);
2002 s->dev = pcidev;
2003 s->io = pci_resource_start(pcidev, 0);
2004 s->irq = pcidev->irq;
2005 s->vendor = pcidev->vendor;
2006 s->device = pcidev->device;
2007 pci_read_config_byte(pcidev, PCI_REVISION_ID, &s->rev);
2008 s->codec.private_data = s;
2009 s->codec.id = 0;
2010 s->codec.codec_read = rdcodec;
2011 s->codec.codec_write = wrcodec;
2012 s->codec.codec_wait = waitcodec;
2013
2014 if (!request_region(s->io, pci_resource_len(pcidev,0),
2015 IT8172_MODULE_NAME)) {
2016 err("io ports %#lx->%#lx in use",
2017 s->io, s->io + pci_resource_len(pcidev,0)-1);
2018 goto err_region;
2019 }
2020 if (request_irq(s->irq, it8172_interrupt, SA_INTERRUPT,
2021 IT8172_MODULE_NAME, s)) {
2022 err("irq %u in use", s->irq);
2023 goto err_irq;
2024 }
2025
2026 info("IO at %#lx, IRQ %d", s->io, s->irq);
2027
2028 /* register devices */
2029 if ((s->dev_audio = register_sound_dsp(&it8172_audio_fops, -1)) < 0)
2030 goto err_dev1;
2031 if ((s->codec.dev_mixer =
2032 register_sound_mixer(&it8172_mixer_fops, -1)) < 0)
2033 goto err_dev2;
2034
2035#ifdef IT8172_DEBUG
2036 /* initialize the debug proc device */
2037 s->ps = create_proc_read_entry(IT8172_MODULE_NAME, 0, NULL,
2038 proc_it8172_dump, NULL);
2039#endif /* IT8172_DEBUG */
2040
2041 /*
2042 * Reset the Audio device using the IT8172 PCI Reset register. This
2043 * creates an audible double click on a speaker connected to Line-out.
2044 */
2045 IT_IO_READ16(IT_PM_PCISR, pcisr);
2046 pcisr |= IT_PM_PCISR_ACSR;
2047 IT_IO_WRITE16(IT_PM_PCISR, pcisr);
2048 /* wait up to 100msec for reset to complete */
2049 for (i=0; pcisr & IT_PM_PCISR_ACSR; i++) {
2050 it8172_delay(10);
2051 if (i == 10)
2052 break;
2053 IT_IO_READ16(IT_PM_PCISR, pcisr);
2054 }
2055 if (i == 10) {
2056 err("chip reset timeout!");
2057 goto err_dev3;
2058 }
2059
2060 /* enable pci io and bus mastering */
2061 if (pci_enable_device(pcidev))
2062 goto err_dev3;
2063 pci_set_master(pcidev);
2064
2065 /* get out of legacy mode */
2066 pci_read_config_byte (pcidev, 0x40, &legacy);
2067 pci_write_config_byte (pcidev, 0x40, legacy & ~1);
2068
2069 s->spdif_volume = -1;
2070 /* check to see if s/pdif mode is being requested */
2071 if (spdif[devindex]) {
2072 info("enabling S/PDIF output");
2073 s->spdif_volume = 0;
2074 outb(GC_SOE, s->io+IT_AC_GC);
2075 } else {
2076 info("disabling S/PDIF output");
2077 outb(0, s->io+IT_AC_GC);
2078 }
2079
2080 /* check to see if I2S format requested */
2081 if (i2s_fmt[devindex]) {
2082 info("setting I2S format to 0x%02x", i2s_fmt[devindex]);
2083 outb(i2s_fmt[devindex], s->io+IT_AC_I2SMC);
2084 } else {
2085 outb(I2SMC_I2SF_I2S, s->io+IT_AC_I2SMC);
2086 }
2087
2088 /* cold reset the AC97 */
2089 outw(CODECC_CR, s->io+IT_AC_CODECC);
2090 udelay(1000);
2091 outw(0, s->io+IT_AC_CODECC);
2092 /* need to delay around 500msec(bleech) to give
2093 some CODECs enough time to wakeup */
2094 it8172_delay(500);
2095
2096 /* AC97 warm reset to start the bitclk */
2097 outw(CODECC_WR, s->io+IT_AC_CODECC);
2098 udelay(1000);
2099 outw(0, s->io+IT_AC_CODECC);
2100
2101 /* codec init */
2102 if (!ac97_probe_codec(&s->codec))
2103 goto err_dev3;
2104
2105 /* add I2S as allowable recording source */
2106 s->codec.record_sources |= SOUND_MASK_I2S;
2107
2108 /* Enable Volume button interrupts */
2109 imc = inb(s->io+IT_AC_IMC);
2110 outb(imc & ~IMC_VCIM, s->io+IT_AC_IMC);
2111
2112 /* Un-mute PCM and FM out on the controller */
2113 vol = inw(s->io+IT_AC_PCMOV);
2114 outw(vol & ~PCMOV_PCMOM, s->io+IT_AC_PCMOV);
2115 vol = inw(s->io+IT_AC_FMOV);
2116 outw(vol & ~FMOV_FMOM, s->io+IT_AC_FMOV);
2117
2118 /* set channel defaults to 8-bit, mono, 8 Khz */
2119 s->pcc = 0;
2120 s->capcc = 0;
2121 set_dac_rate(s, 8000);
2122 set_adc_rate(s, 8000);
2123
2124 /* set mic to be the recording source */
2125 val = SOUND_MASK_MIC;
2126 mixdev_ioctl(&s->codec, SOUND_MIXER_WRITE_RECSRC,
2127 (unsigned long)&val);
2128
2129 /* mute AC'97 master and PCM when in S/PDIF mode */
2130 if (s->spdif_volume != -1) {
2131 val = 0x0000;
2132 s->codec.mixer_ioctl(&s->codec, SOUND_MIXER_WRITE_VOLUME,
2133 (unsigned long)&val);
2134 s->codec.mixer_ioctl(&s->codec, SOUND_MIXER_WRITE_PCM,
2135 (unsigned long)&val);
2136 }
2137
2138#ifdef IT8172_DEBUG
2139 sprintf(proc_str, "driver/%s/%d/ac97", IT8172_MODULE_NAME,
2140 s->codec.id);
2141 s->ac97_ps = create_proc_read_entry (proc_str, 0, NULL,
2142 ac97_read_proc, &s->codec);
2143#endif
2144
2145 /* store it in the driver field */
2146 pci_set_drvdata(pcidev, s);
2147 pcidev->dma_mask = 0xffffffff;
2148 /* put it into driver list */
2149 list_add_tail(&s->devs, &devs);
2150 /* increment devindex */
2151 if (devindex < NR_DEVICE-1)
2152 devindex++;
2153 return 0;
2154
2155 err_dev3:
2156 unregister_sound_mixer(s->codec.dev_mixer);
2157 err_dev2:
2158 unregister_sound_dsp(s->dev_audio);
2159 err_dev1:
2160 err("cannot register misc device");
2161 free_irq(s->irq, s);
2162 err_irq:
2163 release_region(s->io, pci_resource_len(pcidev,0));
2164 err_region:
2165 kfree(s);
2166 return -1;
2167}
2168
2169static void __devexit it8172_remove(struct pci_dev *dev)
2170{
2171 struct it8172_state *s = pci_get_drvdata(dev);
2172
2173 if (!s)
2174 return;
2175 list_del(&s->devs);
2176#ifdef IT8172_DEBUG
2177 if (s->ps)
2178 remove_proc_entry(IT8172_MODULE_NAME, NULL);
2179#endif /* IT8172_DEBUG */
2180 synchronize_irq(s->irq);
2181 free_irq(s->irq, s);
2182 release_region(s->io, pci_resource_len(dev,0));
2183 unregister_sound_dsp(s->dev_audio);
2184 unregister_sound_mixer(s->codec.dev_mixer);
2185 kfree(s);
2186 pci_set_drvdata(dev, NULL);
2187}
2188
2189
2190
2191static struct pci_device_id id_table[] = {
2192 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_IT8172G_AUDIO, PCI_ANY_ID,
2193 PCI_ANY_ID, 0, 0 },
2194 { 0, }
2195};
2196
2197MODULE_DEVICE_TABLE(pci, id_table);
2198
2199static struct pci_driver it8172_driver = {
2200 .name = IT8172_MODULE_NAME,
2201 .id_table = id_table,
2202 .probe = it8172_probe,
2203 .remove = __devexit_p(it8172_remove)
2204};
2205
2206static int __init init_it8172(void)
2207{
2208 info("version v0.5 time " __TIME__ " " __DATE__);
2209 return pci_module_init(&it8172_driver);
2210}
2211
2212static void __exit cleanup_it8172(void)
2213{
2214 info("unloading");
2215 pci_unregister_driver(&it8172_driver);
2216}
2217
2218module_init(init_it8172);
2219module_exit(cleanup_it8172);
2220
2221/* --------------------------------------------------------------------- */
2222
2223#ifndef MODULE
2224
2225/* format is: it8172=[spdif],[i2s:<I2S format>] */
2226
2227static int __init it8172_setup(char *options)
2228{
2229 char* this_opt;
2230 static unsigned __initdata nr_dev = 0;
2231
2232 if (nr_dev >= NR_DEVICE)
2233 return 0;
2234
2235 if (!options || !*options)
2236 return 0;
2237
2238 while (this_opt = strsep(&options, ",")) {
2239 if (!*this_opt)
2240 continue;
2241 if (!strncmp(this_opt, "spdif", 5)) {
2242 spdif[nr_dev] = 1;
2243 } else if (!strncmp(this_opt, "i2s:", 4)) {
2244 if (!strncmp(this_opt+4, "dac", 3))
2245 i2s_fmt[nr_dev] = I2SMC_I2SF_DAC;
2246 else if (!strncmp(this_opt+4, "adc", 3))
2247 i2s_fmt[nr_dev] = I2SMC_I2SF_ADC;
2248 else if (!strncmp(this_opt+4, "i2s", 3))
2249 i2s_fmt[nr_dev] = I2SMC_I2SF_I2S;
2250 }
2251 }
2252
2253 nr_dev++;
2254 return 1;
2255}
2256
2257__setup("it8172=", it8172_setup);
2258
2259#endif /* MODULE */
diff --git a/sound/oss/iwmem.h b/sound/oss/iwmem.h
new file mode 100644
index 000000000000..84745fbcabcb
--- /dev/null
+++ b/sound/oss/iwmem.h
@@ -0,0 +1,36 @@
1/*
2 * sound/iwmem.h
3 *
4 * DRAM size encoding table for AMD Interwave chip.
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 * Bartlomiej Zolnierkiewicz : added __initdata to mem_decode
15 */
16
17
18#define K 1024
19#define M (1024*K)
20static int mem_decode[][4] __initdata =
21{
22/* Bank0 Bank1 Bank2 Bank3 Encoding bits */
23 {256*K, 0, 0, 0}, /* 0 */
24 {256*K, 256*K, 0, 0}, /* 1 */
25 {256*K, 256*K, 256*K, 256*K}, /* 2 */
26 {256*K, 1*M, 0, 0}, /* 3 */
27 {256*K, 1*M, 1*M, 1*M}, /* 4 */
28 {256*K, 256*K, 1*M, 0}, /* 5 */
29 {256*K, 256*K, 1*M, 1*M}, /* 6 */
30 {1*M, 0, 0, 0}, /* 7 */
31 {1*M, 1*M, 0, 0}, /* 8 */
32 {1*M, 1*M, 1*M, 1*M}, /* 9 */
33 {4*M, 0, 0, 0}, /* 10 */
34 {4*M, 4*M, 0, 0}, /* 11 */
35 {4*M, 4*M, 4*M, 4*M} /* 12 */
36};
diff --git a/sound/oss/kahlua.c b/sound/oss/kahlua.c
new file mode 100644
index 000000000000..808c5ef969be
--- /dev/null
+++ b/sound/oss/kahlua.c
@@ -0,0 +1,232 @@
1/*
2 * Initialisation code for Cyrix/NatSemi VSA1 softaudio
3 *
4 * (C) Copyright 2003 Red Hat Inc <alan@redhat.com>
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/config.h>
31#include <linux/delay.h>
32#include <linux/init.h>
33#include <linux/module.h>
34#include <linux/pci.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 __devinit 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 __devinit 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 == 0UL)
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 = kmalloc(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 memset(hw_config, 0, sizeof(*hw_config));
150
151 pci_set_drvdata(pdev, hw_config);
152
153 hw_config->io_base = io;
154 hw_config->irq = irq;
155 hw_config->dma = dma8;
156 hw_config->dma2 = dma16;
157 hw_config->name = "Cyrix XpressAudio";
158 hw_config->driver_use_1 = SB_NO_MIDI | SB_PCI_IRQ;
159
160 if (!request_region(io, 16, "soundblaster"))
161 goto err_out_free;
162
163 if(sb_dsp_detect(hw_config, 0, 0, NULL)==0)
164 {
165 printk(KERN_ERR "kahlua: audio not responding.\n");
166 release_region(io, 16);
167 goto err_out_free;
168 }
169
170 oldquiet = sb_be_quiet;
171 sb_be_quiet = 1;
172 if(sb_dsp_init(hw_config, THIS_MODULE))
173 {
174 sb_be_quiet = oldquiet;
175 goto err_out_free;
176 }
177 sb_be_quiet = oldquiet;
178
179 return 0;
180
181err_out_free:
182 pci_set_drvdata(pdev, NULL);
183 kfree(hw_config);
184 return 1;
185}
186
187static void __devexit remove_one(struct pci_dev *pdev)
188{
189 struct address_info *hw_config = pci_get_drvdata(pdev);
190 sb_dsp_unload(hw_config, 0);
191 pci_set_drvdata(pdev, NULL);
192 kfree(hw_config);
193}
194
195MODULE_AUTHOR("Alan Cox");
196MODULE_DESCRIPTION("Kahlua VSA1 PCI Audio");
197MODULE_LICENSE("GPL");
198
199/*
200 * 5530 only. The 5510/5520 decode is different.
201 */
202
203static struct pci_device_id id_tbl[] = {
204 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
205 { }
206};
207
208MODULE_DEVICE_TABLE(pci, id_tbl);
209
210static struct pci_driver kahlua_driver = {
211 .name = "kahlua",
212 .id_table = id_tbl,
213 .probe = probe_one,
214 .remove = __devexit_p(remove_one),
215};
216
217
218static int __init kahlua_init_module(void)
219{
220 printk(KERN_INFO "Cyrix Kahlua VSA1 XpressAudio support (c) Copyright 2003 Red Hat Inc\n");
221 return pci_module_init(&kahlua_driver);
222}
223
224static void __devexit kahlua_cleanup_module(void)
225{
226 pci_unregister_driver(&kahlua_driver);
227}
228
229
230module_init(kahlua_init_module);
231module_exit(kahlua_cleanup_module);
232
diff --git a/sound/oss/mad16.c b/sound/oss/mad16.c
new file mode 100644
index 000000000000..a7067f169919
--- /dev/null
+++ b/sound/oss/mad16.c
@@ -0,0 +1,1097 @@
1/*
2 * Copyright (C) by Hannu Savolainen 1993-1997
3 *
4 * mad16.c
5 *
6 * Initialization code for OPTi MAD16 compatible audio chips. Including
7 *
8 * OPTi 82C928 MAD16 (replaced by C929)
9 * OAK OTI-601D Mozart
10 * OAK OTI-605 Mozart (later version with MPU401 Midi)
11 * OPTi 82C929 MAD16 Pro
12 * OPTi 82C930
13 * OPTi 82C924
14 *
15 * These audio interface chips don't produce sound themselves. They just
16 * connect some other components (OPL-[234] and a WSS compatible codec)
17 * to the PC bus and perform I/O, DMA and IRQ address decoding. There is
18 * also a UART for the MPU-401 mode (not 82C928/Mozart).
19 * The Mozart chip appears to be compatible with the 82C928, although later
20 * issues of the card, using the OTI-605 chip, have an MPU-401 compatible Midi
21 * port. This port is configured differently to that of the OPTi audio chips.
22 *
23 * Changes
24 *
25 * Alan Cox Clean up, added module selections.
26 *
27 * A. Wik Added support for Opti924 PnP.
28 * Improved debugging support. 16-May-1998
29 * Fixed bug. 16-Jun-1998
30 *
31 * Torsten Duwe Made Opti924 PnP support non-destructive
32 * 23-Dec-1998
33 *
34 * Paul Grayson Added support for Midi on later Mozart cards.
35 * 25-Nov-1999
36 * Christoph Hellwig Adapted to module_init/module_exit.
37 * Arnaldo C. de Melo got rid of attach_uart401 21-Sep-2000
38 *
39 * Pavel Rabel Clean up Nov-2000
40 */
41
42#include <linux/config.h>
43#include <linux/init.h>
44#include <linux/module.h>
45#include <linux/gameport.h>
46#include <linux/spinlock.h>
47#include "sound_config.h"
48
49#include "ad1848.h"
50#include "sb.h"
51#include "mpu401.h"
52
53static int mad16_conf;
54static int mad16_cdsel;
55static struct gameport *gameport;
56static DEFINE_SPINLOCK(lock);
57
58#define C928 1
59#define MOZART 2
60#define C929 3
61#define C930 4
62#define C924 5
63
64/*
65 * Registers
66 *
67 * The MAD16 occupies I/O ports 0xf8d to 0xf93 (fixed locations).
68 * All ports are inactive by default. They can be activated by
69 * writing 0xE2 or 0xE3 to the password register. The password is valid
70 * only until the next I/O read or write.
71 *
72 * 82C930 uses 0xE4 as the password and indirect addressing to access
73 * the config registers.
74 */
75
76#define MC0_PORT 0xf8c /* Dummy port */
77#define MC1_PORT 0xf8d /* SB address, CD-ROM interface type, joystick */
78#define MC2_PORT 0xf8e /* CD-ROM address, IRQ, DMA, plus OPL4 bit */
79#define MC3_PORT 0xf8f
80#define PASSWD_REG 0xf8f
81#define MC4_PORT 0xf90
82#define MC5_PORT 0xf91
83#define MC6_PORT 0xf92
84#define MC7_PORT 0xf93
85#define MC8_PORT 0xf94
86#define MC9_PORT 0xf95
87#define MC10_PORT 0xf96
88#define MC11_PORT 0xf97
89#define MC12_PORT 0xf98
90
91static int board_type = C928;
92
93static int *mad16_osp;
94static int c931_detected; /* minor differences from C930 */
95static char c924pnp; /* " " " C924 */
96static int debug; /* debugging output */
97
98#ifdef DDB
99#undef DDB
100#endif
101#define DDB(x) do {if (debug) x;} while (0)
102
103static unsigned char mad_read(int port)
104{
105 unsigned long flags;
106 unsigned char tmp;
107
108 spin_lock_irqsave(&lock,flags);
109
110 switch (board_type) /* Output password */
111 {
112 case C928:
113 case MOZART:
114 outb((0xE2), PASSWD_REG);
115 break;
116
117 case C929:
118 outb((0xE3), PASSWD_REG);
119 break;
120
121 case C930:
122 /* outb(( 0xE4), PASSWD_REG); */
123 break;
124
125 case C924:
126 /* the c924 has its ports relocated by -128 if
127 PnP is enabled -aw */
128 if (!c924pnp)
129 outb((0xE5), PASSWD_REG); else
130 outb((0xE5), PASSWD_REG - 0x80);
131 break;
132 }
133
134 if (board_type == C930)
135 {
136 outb((port - MC0_PORT), 0xe0e); /* Write to index reg */
137 tmp = inb(0xe0f); /* Read from data reg */
138 }
139 else
140 if (!c924pnp)
141 tmp = inb(port); else
142 tmp = inb(port-0x80);
143 spin_unlock_irqrestore(&lock,flags);
144
145 return tmp;
146}
147
148static void mad_write(int port, int value)
149{
150 unsigned long flags;
151
152 spin_lock_irqsave(&lock,flags);
153
154 switch (board_type) /* Output password */
155 {
156 case C928:
157 case MOZART:
158 outb((0xE2), PASSWD_REG);
159 break;
160
161 case C929:
162 outb((0xE3), PASSWD_REG);
163 break;
164
165 case C930:
166 /* outb(( 0xE4), PASSWD_REG); */
167 break;
168
169 case C924:
170 if (!c924pnp)
171 outb((0xE5), PASSWD_REG); else
172 outb((0xE5), PASSWD_REG - 0x80);
173 break;
174 }
175
176 if (board_type == C930)
177 {
178 outb((port - MC0_PORT), 0xe0e); /* Write to index reg */
179 outb(((unsigned char) (value & 0xff)), 0xe0f);
180 }
181 else
182 if (!c924pnp)
183 outb(((unsigned char) (value & 0xff)), port); else
184 outb(((unsigned char) (value & 0xff)), port-0x80);
185 spin_unlock_irqrestore(&lock,flags);
186}
187
188static int __init detect_c930(void)
189{
190 unsigned char tmp = mad_read(MC1_PORT);
191
192 if ((tmp & 0x06) != 0x06)
193 {
194 DDB(printk("Wrong C930 signature (%x)\n", tmp));
195 /* return 0; */
196 }
197 mad_write(MC1_PORT, 0);
198
199 if (mad_read(MC1_PORT) != 0x06)
200 {
201 DDB(printk("Wrong C930 signature2 (%x)\n", tmp));
202 /* return 0; */
203 }
204 mad_write(MC1_PORT, tmp); /* Restore bits */
205
206 mad_write(MC7_PORT, 0);
207 if ((tmp = mad_read(MC7_PORT)) != 0)
208 {
209 DDB(printk("MC7 not writable (%x)\n", tmp));
210 return 0;
211 }
212 mad_write(MC7_PORT, 0xcb);
213 if ((tmp = mad_read(MC7_PORT)) != 0xcb)
214 {
215 DDB(printk("MC7 not writable2 (%x)\n", tmp));
216 return 0;
217 }
218
219 tmp = mad_read(MC0_PORT+18);
220 if (tmp == 0xff || tmp == 0x00)
221 return 1;
222 /* We probably have a C931 */
223 DDB(printk("Detected C931 config=0x%02x\n", tmp));
224 c931_detected = 1;
225
226 /*
227 * We cannot configure the chip if it is in PnP mode.
228 * If we have a CSN assigned (bit 8 in MC13) we first try
229 * a software reset, then a software power off, finally
230 * Clearing PnP mode. The last option is not
231 * Bit 8 in MC13
232 */
233 if ((mad_read(MC0_PORT+13) & 0x80) == 0)
234 return 1;
235
236 /* Software reset */
237 mad_write(MC9_PORT, 0x02);
238 mad_write(MC9_PORT, 0x00);
239
240 if ((mad_read(MC0_PORT+13) & 0x80) == 0)
241 return 1;
242
243 /* Power off, and on again */
244 mad_write(MC9_PORT, 0xc2);
245 mad_write(MC9_PORT, 0xc0);
246
247 if ((mad_read(MC0_PORT+13) & 0x80) == 0)
248 return 1;
249
250#if 0
251 /* Force off PnP mode. This is not recommended because
252 * the PnP bios will not recognize the chip on the next
253 * warm boot and may assignd different resources to other
254 * PnP/PCI cards.
255 */
256 mad_write(MC0_PORT+17, 0x04);
257#endif
258 return 1;
259}
260
261static int __init detect_mad16(void)
262{
263 unsigned char tmp, tmp2, bit;
264 int i, port;
265
266 /*
267 * Check that reading a register doesn't return bus float (0xff)
268 * when the card is accessed using password. This may fail in case
269 * the card is in low power mode. Normally at least the power saving
270 * mode bit should be 0.
271 */
272
273 if ((tmp = mad_read(MC1_PORT)) == 0xff)
274 {
275 DDB(printk("MC1_PORT returned 0xff\n"));
276 return 0;
277 }
278 for (i = 0xf8d; i <= 0xf98; i++)
279 if (!c924pnp)
280 DDB(printk("Port %0x (init value) = %0x\n", i, mad_read(i)));
281 else
282 DDB(printk("Port %0x (init value) = %0x\n", i-0x80, mad_read(i)));
283
284 if (board_type == C930)
285 return detect_c930();
286
287 /*
288 * Now check that the gate is closed on first I/O after writing
289 * the password. (This is how a MAD16 compatible card works).
290 */
291
292 if ((tmp2 = inb(MC1_PORT)) == tmp) /* It didn't close */
293 {
294 DDB(printk("MC1_PORT didn't close after read (0x%02x)\n", tmp2));
295 return 0;
296 }
297
298 bit = (c924pnp) ? 0x20 : 0x80;
299 port = (c924pnp) ? MC2_PORT : MC1_PORT;
300
301 tmp = mad_read(port);
302 mad_write(port, tmp ^ bit); /* Toggle a bit */
303 if ((tmp2 = mad_read(port)) != (tmp ^ bit)) /* Compare the bit */
304 {
305 mad_write(port, tmp); /* Restore */
306 DDB(printk("Bit revert test failed (0x%02x, 0x%02x)\n", tmp, tmp2));
307 return 0;
308 }
309 mad_write(port, tmp); /* Restore */
310 return 1; /* Bingo */
311}
312
313static int __init wss_init(struct address_info *hw_config)
314{
315 /*
316 * Check if the IO port returns valid signature. The original MS Sound
317 * system returns 0x04 while some cards (AudioTrix Pro for example)
318 * return 0x00.
319 */
320
321 if ((inb(hw_config->io_base + 3) & 0x3f) != 0x04 &&
322 (inb(hw_config->io_base + 3) & 0x3f) != 0x00)
323 {
324 DDB(printk("No MSS signature detected on port 0x%x (0x%x)\n", hw_config->io_base, inb(hw_config->io_base + 3)));
325 return 0;
326 }
327 /*
328 * Check that DMA0 is not in use with a 8 bit board.
329 */
330 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80)
331 {
332 printk("MSS: Can't use DMA0 with a 8 bit card/slot\n");
333 return 0;
334 }
335 if (hw_config->irq > 9 && inb(hw_config->io_base + 3) & 0x80)
336 printk(KERN_ERR "MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->irq);
337 return 1;
338}
339
340static void __init init_c930(struct address_info *hw_config, int base)
341{
342 unsigned char cfg = 0;
343
344 cfg |= (0x0f & mad16_conf);
345
346 if(c931_detected)
347 {
348 /* Bit 0 has reversd meaning. Bits 1 and 2 sese
349 reversed on write.
350 Support only IDE cdrom. IDE port programmed
351 somewhere else. */
352 cfg = (cfg & 0x09) ^ 0x07;
353 }
354 cfg |= base << 4;
355 mad_write(MC1_PORT, cfg);
356
357 /* MC2 is CD configuration. Don't touch it. */
358
359 mad_write(MC3_PORT, 0); /* Disable SB mode IRQ and DMA */
360
361 /* bit 2 of MC4 reverses it's meaning between the C930
362 and the C931. */
363 cfg = c931_detected ? 0x04 : 0x00;
364
365 if(mad16_cdsel & 0x20)
366 mad_write(MC4_PORT, 0x62|cfg); /* opl4 */
367 else
368 mad_write(MC4_PORT, 0x52|cfg); /* opl3 */
369
370 mad_write(MC5_PORT, 0x3C); /* Init it into mode2 */
371 mad_write(MC6_PORT, 0x02); /* Enable WSS, Disable MPU and SB */
372 mad_write(MC7_PORT, 0xCB);
373 mad_write(MC10_PORT, 0x11);
374}
375
376static int __init chip_detect(void)
377{
378 int i;
379
380 /*
381 * Then try to detect with the old password
382 */
383 board_type = C924;
384
385 DDB(printk("Detect using password = 0xE5\n"));
386
387 if (detect_mad16()) {
388 return 1;
389 }
390
391 board_type = C928;
392
393 DDB(printk("Detect using password = 0xE2\n"));
394
395 if (detect_mad16())
396 {
397 unsigned char model;
398
399 if (((model = mad_read(MC3_PORT)) & 0x03) == 0x03) {
400 DDB(printk("mad16.c: Mozart detected\n"));
401 board_type = MOZART;
402 } else {
403 DDB(printk("mad16.c: 82C928 detected???\n"));
404 board_type = C928;
405 }
406 return 1;
407 }
408
409 board_type = C929;
410
411 DDB(printk("Detect using password = 0xE3\n"));
412
413 if (detect_mad16())
414 {
415 DDB(printk("mad16.c: 82C929 detected\n"));
416 return 1;
417 }
418
419 if (inb(PASSWD_REG) != 0xff)
420 return 0;
421
422 /*
423 * First relocate MC# registers to 0xe0e/0xe0f, disable password
424 */
425
426 outb((0xE4), PASSWD_REG);
427 outb((0x80), PASSWD_REG);
428
429 board_type = C930;
430
431 DDB(printk("Detect using password = 0xE4\n"));
432
433 for (i = 0xf8d; i <= 0xf93; i++)
434 DDB(printk("port %03x = %02x\n", i, mad_read(i)));
435
436 if(detect_mad16()) {
437 DDB(printk("mad16.c: 82C930 detected\n"));
438 return 1;
439 }
440
441 /* The C931 has the password reg at F8D */
442 outb((0xE4), 0xF8D);
443 outb((0x80), 0xF8D);
444 DDB(printk("Detect using password = 0xE4 for C931\n"));
445
446 if (detect_mad16()) {
447 return 1;
448 }
449
450 board_type = C924;
451 c924pnp++;
452 DDB(printk("Detect using password = 0xE5 (again), port offset -0x80\n"));
453 if (detect_mad16()) {
454 DDB(printk("mad16.c: 82C924 PnP detected\n"));
455 return 1;
456 }
457
458 c924pnp=0;
459
460 return 0;
461}
462
463static int __init probe_mad16(struct address_info *hw_config)
464{
465 int i;
466 unsigned char tmp;
467 unsigned char cs4231_mode = 0;
468
469 int ad_flags = 0;
470
471 signed char bits;
472
473 static char dma_bits[4] = {
474 1, 2, 0, 3
475 };
476
477 int config_port = hw_config->io_base + 0, version_port = hw_config->io_base + 3;
478 int dma = hw_config->dma, dma2 = hw_config->dma2;
479 unsigned char dma2_bit = 0;
480 int base;
481 struct resource *ports;
482
483 mad16_osp = hw_config->osp;
484
485 switch (hw_config->io_base) {
486 case 0x530:
487 base = 0;
488 break;
489 case 0xe80:
490 base = 1;
491 break;
492 case 0xf40:
493 base = 2;
494 break;
495 case 0x604:
496 base = 3;
497 break;
498 default:
499 printk(KERN_ERR "MAD16/Mozart: Bad WSS base address 0x%x\n", hw_config->io_base);
500 return 0;
501 }
502
503 if (dma != 0 && dma != 1 && dma != 3) {
504 printk(KERN_ERR "MSS: Bad DMA %d\n", dma);
505 return 0;
506 }
507
508 /*
509 * Check that all ports return 0xff (bus float) when no password
510 * is written to the password register.
511 */
512
513 DDB(printk("--- Detecting MAD16 / Mozart ---\n"));
514 if (!chip_detect())
515 return 0;
516
517 switch (hw_config->irq) {
518 case 7:
519 bits = 8;
520 break;
521 case 9:
522 bits = 0x10;
523 break;
524 case 10:
525 bits = 0x18;
526 break;
527 case 12:
528 bits = 0x20;
529 break;
530 case 5: /* Also IRQ5 is possible on C930 */
531 if (board_type == C930 || c924pnp) {
532 bits = 0x28;
533 break;
534 }
535 default:
536 printk(KERN_ERR "MAD16/Mozart: Bad IRQ %d\n", hw_config->irq);
537 return 0;
538 }
539
540 ports = request_region(hw_config->io_base + 4, 4, "ad1848");
541 if (!ports) {
542 printk(KERN_ERR "MSS: I/O port conflict\n");
543 return 0;
544 }
545 if (!request_region(hw_config->io_base, 4, "mad16 WSS config")) {
546 release_region(hw_config->io_base + 4, 4);
547 printk(KERN_ERR "MSS: I/O port conflict\n");
548 return 0;
549 }
550
551 if (board_type == C930) {
552 init_c930(hw_config, base);
553 goto got_it;
554 }
555
556 for (i = 0xf8d; i <= 0xf93; i++) {
557 if (!c924pnp)
558 DDB(printk("port %03x = %02x\n", i, mad_read(i)));
559 else
560 DDB(printk("port %03x = %02x\n", i-0x80, mad_read(i)));
561 }
562
563/*
564 * Set the WSS address
565 */
566
567 tmp = (mad_read(MC1_PORT) & 0x0f) | 0x80; /* Enable WSS, Disable SB */
568 tmp |= base << 4; /* WSS port select bits */
569
570 /*
571 * Set optional CD-ROM and joystick settings.
572 */
573
574 tmp &= ~0x0f;
575 tmp |= (mad16_conf & 0x0f); /* CD-ROM and joystick bits */
576 mad_write(MC1_PORT, tmp);
577
578 tmp = mad16_cdsel;
579 mad_write(MC2_PORT, tmp);
580 mad_write(MC3_PORT, 0xf0); /* Disable SB */
581
582 if (board_type == C924) /* Specific C924 init values */
583 {
584 mad_write(MC4_PORT, 0xA0);
585 mad_write(MC5_PORT, 0x05);
586 mad_write(MC6_PORT, 0x03);
587 }
588 if (!ad1848_detect(ports, &ad_flags, mad16_osp))
589 goto fail;
590
591 if (ad_flags & (AD_F_CS4231 | AD_F_CS4248))
592 cs4231_mode = 0x02; /* CS4248/CS4231 sync delay switch */
593
594 if (board_type == C929)
595 {
596 mad_write(MC4_PORT, 0xa2);
597 mad_write(MC5_PORT, 0xA5 | cs4231_mode);
598 mad_write(MC6_PORT, 0x03); /* Disable MPU401 */
599 }
600 else
601 {
602 mad_write(MC4_PORT, 0x02);
603 mad_write(MC5_PORT, 0x30 | cs4231_mode);
604 }
605
606 for (i = 0xf8d; i <= 0xf93; i++) {
607 if (!c924pnp)
608 DDB(printk("port %03x after init = %02x\n", i, mad_read(i)));
609 else
610 DDB(printk("port %03x after init = %02x\n", i-0x80, mad_read(i)));
611 }
612
613got_it:
614 ad_flags = 0;
615 if (!ad1848_detect(ports, &ad_flags, mad16_osp))
616 goto fail;
617
618 if (!wss_init(hw_config))
619 goto fail;
620
621 /*
622 * Set the IRQ and DMA addresses.
623 */
624
625 outb((bits | 0x40), config_port);
626 if ((inb(version_port) & 0x40) == 0)
627 printk(KERN_ERR "[IRQ Conflict?]\n");
628
629 /*
630 * Handle the capture DMA channel
631 */
632
633 if (ad_flags & AD_F_CS4231 && dma2 != -1 && dma2 != dma)
634 {
635 if (!((dma == 0 && dma2 == 1) ||
636 (dma == 1 && dma2 == 0) ||
637 (dma == 3 && dma2 == 0)))
638 { /* Unsupported combination. Try to swap channels */
639 int tmp = dma;
640
641 dma = dma2;
642 dma2 = tmp;
643 }
644 if ((dma == 0 && dma2 == 1) || (dma == 1 && dma2 == 0) ||
645 (dma == 3 && dma2 == 0))
646 {
647 dma2_bit = 0x04; /* Enable capture DMA */
648 }
649 else
650 {
651 printk("MAD16: Invalid capture DMA\n");
652 dma2 = dma;
653 }
654 }
655 else dma2 = dma;
656
657 outb((bits | dma_bits[dma] | dma2_bit), config_port); /* Write IRQ+DMA setup */
658
659 hw_config->slots[0] = ad1848_init("mad16 WSS", ports,
660 hw_config->irq,
661 dma,
662 dma2, 0,
663 hw_config->osp,
664 THIS_MODULE);
665 return 1;
666
667fail:
668 release_region(hw_config->io_base + 4, 4);
669 release_region(hw_config->io_base, 4);
670 return 0;
671}
672
673static int __init probe_mad16_mpu(struct address_info *hw_config)
674{
675 unsigned char tmp;
676
677 if (board_type < C929) /* Early chip. No MPU support. Just SB MIDI */
678 {
679
680#ifdef CONFIG_MAD16_OLDCARD
681
682 tmp = mad_read(MC3_PORT);
683
684 /*
685 * MAD16 SB base is defined by the WSS base. It cannot be changed
686 * alone.
687 * Ignore configured I/O base. Use the active setting.
688 */
689
690 if (mad_read(MC1_PORT) & 0x20)
691 hw_config->io_base = 0x240;
692 else
693 hw_config->io_base = 0x220;
694
695 switch (hw_config->irq)
696 {
697 case 5:
698 tmp = (tmp & 0x3f) | 0x80;
699 break;
700 case 7:
701 tmp = (tmp & 0x3f);
702 break;
703 case 11:
704 tmp = (tmp & 0x3f) | 0x40;
705 break;
706 default:
707 printk(KERN_ERR "mad16/Mozart: Invalid MIDI IRQ\n");
708 return 0;
709 }
710
711 mad_write(MC3_PORT, tmp | 0x04);
712 hw_config->driver_use_1 = SB_MIDI_ONLY;
713 if (!request_region(hw_config->io_base, 16, "soundblaster"))
714 return 0;
715 if (!sb_dsp_detect(hw_config, 0, 0, NULL)) {
716 release_region(hw_config->io_base, 16);
717 return 0;
718 }
719
720 if (mad_read(MC1_PORT) & 0x20)
721 hw_config->io_base = 0x240;
722 else
723 hw_config->io_base = 0x220;
724
725 hw_config->name = "Mad16/Mozart";
726 sb_dsp_init(hw_config, THIS_MODULE);
727 return 1;
728#else
729 /* assuming all later Mozart cards are identified as
730 * either 82C928 or Mozart. If so, following code attempts
731 * to set MPU register. TODO - add probing
732 */
733
734 tmp = mad_read(MC8_PORT);
735
736 switch (hw_config->irq)
737 {
738 case 5:
739 tmp |= 0x08;
740 break;
741 case 7:
742 tmp |= 0x10;
743 break;
744 case 9:
745 tmp |= 0x18;
746 break;
747 case 10:
748 tmp |= 0x20;
749 break;
750 case 11:
751 tmp |= 0x28;
752 break;
753 default:
754 printk(KERN_ERR "mad16/MOZART: invalid mpu_irq\n");
755 return 0;
756 }
757
758 switch (hw_config->io_base)
759 {
760 case 0x300:
761 tmp |= 0x01;
762 break;
763 case 0x310:
764 tmp |= 0x03;
765 break;
766 case 0x320:
767 tmp |= 0x05;
768 break;
769 case 0x330:
770 tmp |= 0x07;
771 break;
772 default:
773 printk(KERN_ERR "mad16/MOZART: invalid mpu_io\n");
774 return 0;
775 }
776
777 mad_write(MC8_PORT, tmp); /* write MPU port parameters */
778 goto probe_401;
779#endif
780 }
781 tmp = mad_read(MC6_PORT) & 0x83;
782 tmp |= 0x80; /* MPU-401 enable */
783
784 /* Set the MPU base bits */
785
786 switch (hw_config->io_base)
787 {
788 case 0x300:
789 tmp |= 0x60;
790 break;
791 case 0x310:
792 tmp |= 0x40;
793 break;
794 case 0x320:
795 tmp |= 0x20;
796 break;
797 case 0x330:
798 tmp |= 0x00;
799 break;
800 default:
801 printk(KERN_ERR "MAD16: Invalid MIDI port 0x%x\n", hw_config->io_base);
802 return 0;
803 }
804
805 /* Set the MPU IRQ bits */
806
807 switch (hw_config->irq)
808 {
809 case 5:
810 tmp |= 0x10;
811 break;
812 case 7:
813 tmp |= 0x18;
814 break;
815 case 9:
816 tmp |= 0x00;
817 break;
818 case 10:
819 tmp |= 0x08;
820 break;
821 default:
822 printk(KERN_ERR "MAD16: Invalid MIDI IRQ %d\n", hw_config->irq);
823 break;
824 }
825
826 mad_write(MC6_PORT, tmp); /* Write MPU401 config */
827
828#ifndef CONFIG_MAD16_OLDCARD
829probe_401:
830#endif
831 hw_config->driver_use_1 = SB_MIDI_ONLY;
832 hw_config->name = "Mad16/Mozart";
833 return probe_uart401(hw_config, THIS_MODULE);
834}
835
836static void __exit unload_mad16(struct address_info *hw_config)
837{
838 ad1848_unload(hw_config->io_base + 4,
839 hw_config->irq,
840 hw_config->dma,
841 hw_config->dma2, 0);
842 release_region(hw_config->io_base, 4);
843 sound_unload_audiodev(hw_config->slots[0]);
844}
845
846static void __exit unload_mad16_mpu(struct address_info *hw_config)
847{
848#ifdef CONFIG_MAD16_OLDCARD
849 if (board_type < C929) /* Early chip. No MPU support. Just SB MIDI */
850 {
851 sb_dsp_unload(hw_config, 0);
852 return;
853 }
854#endif
855
856 unload_uart401(hw_config);
857}
858
859static struct address_info cfg;
860static struct address_info cfg_mpu;
861
862static int found_mpu;
863
864static int __initdata mpu_io = 0;
865static int __initdata mpu_irq = 0;
866static int __initdata io = -1;
867static int __initdata dma = -1;
868static int __initdata dma16 = -1; /* Set this for modules that need it */
869static int __initdata irq = -1;
870static int __initdata cdtype = 0;
871static int __initdata cdirq = 0;
872static int __initdata cdport = 0x340;
873static int __initdata cddma = -1;
874static int __initdata opl4 = 0;
875static int __initdata joystick = 0;
876
877module_param(mpu_io, int, 0);
878module_param(mpu_irq, int, 0);
879module_param(io, int, 0);
880module_param(dma, int, 0);
881module_param(dma16, int, 0);
882module_param(irq, int, 0);
883module_param(cdtype, int, 0);
884module_param(cdirq, int, 0);
885module_param(cdport, int, 0);
886module_param(cddma, int, 0);
887module_param(opl4, int, 0);
888module_param(joystick, bool, 0);
889module_param(debug, bool, 0644);
890
891static int __initdata dma_map[2][8] =
892{
893 {0x03, -1, -1, -1, -1, 0x00, 0x01, 0x02},
894 {0x03, -1, 0x01, 0x00, -1, -1, -1, -1}
895};
896
897static int __initdata irq_map[16] =
898{
899 0x00, -1, -1, 0x0A,
900 -1, 0x04, -1, 0x08,
901 -1, 0x10, 0x14, 0x18,
902 -1, -1, -1, -1
903};
904
905static int __devinit mad16_register_gameport(int io_port)
906{
907 if (!request_region(io_port, 1, "mad16 gameport")) {
908 printk(KERN_ERR "mad16: gameport address 0x%#x already in use\n", io_port);
909 return -EBUSY;
910 }
911
912 gameport = gameport_allocate_port();
913 if (!gameport) {
914 printk(KERN_ERR "mad16: can not allocate memory for gameport\n");
915 release_region(io_port, 1);
916 return -ENOMEM;
917 }
918
919 gameport_set_name(gameport, "MAD16 Gameport");
920 gameport_set_phys(gameport, "isa%04x/gameport0", io_port);
921 gameport->io = io_port;
922
923 gameport_register_port(gameport);
924
925 return 0;
926}
927
928static int __devinit init_mad16(void)
929{
930 int dmatype = 0;
931
932 printk(KERN_INFO "MAD16 audio driver Copyright (C) by Hannu Savolainen 1993-1996\n");
933
934 printk(KERN_INFO "CDROM ");
935 switch (cdtype)
936 {
937 case 0x00:
938 printk("Disabled");
939 cdirq = 0;
940 break;
941 case 0x02:
942 printk("Sony CDU31A");
943 dmatype = 1;
944 if(cddma == -1) cddma = 3;
945 break;
946 case 0x04:
947 printk("Mitsumi");
948 dmatype = 0;
949 if(cddma == -1) cddma = 5;
950 break;
951 case 0x06:
952 printk("Panasonic Lasermate");
953 dmatype = 1;
954 if(cddma == -1) cddma = 3;
955 break;
956 case 0x08:
957 printk("Secondary IDE");
958 dmatype = 0;
959 if(cddma == -1) cddma = 5;
960 break;
961 case 0x0A:
962 printk("Primary IDE");
963 dmatype = 0;
964 if(cddma == -1) cddma = 5;
965 break;
966 default:
967 printk("\n");
968 printk(KERN_ERR "Invalid CDROM type\n");
969 return -EINVAL;
970 }
971
972 /*
973 * Build the config words
974 */
975
976 mad16_conf = (joystick ^ 1) | cdtype;
977 mad16_cdsel = 0;
978 if (opl4)
979 mad16_cdsel |= 0x20;
980
981 if(cdtype){
982 if (cddma > 7 || cddma < 0 || dma_map[dmatype][cddma] == -1)
983 {
984 printk("\n");
985 printk(KERN_ERR "Invalid CDROM DMA\n");
986 return -EINVAL;
987 }
988 if (cddma)
989 printk(", DMA %d", cddma);
990 else
991 printk(", no DMA");
992
993 if (!cdirq)
994 printk(", no IRQ");
995 else if (cdirq < 0 || cdirq > 15 || irq_map[cdirq] == -1)
996 {
997 printk(", invalid IRQ (disabling)");
998 cdirq = 0;
999 }
1000 else printk(", IRQ %d", cdirq);
1001
1002 mad16_cdsel |= dma_map[dmatype][cddma];
1003
1004 if (cdtype < 0x08)
1005 {
1006 switch (cdport)
1007 {
1008 case 0x340:
1009 mad16_cdsel |= 0x00;
1010 break;
1011 case 0x330:
1012 mad16_cdsel |= 0x40;
1013 break;
1014 case 0x360:
1015 mad16_cdsel |= 0x80;
1016 break;
1017 case 0x320:
1018 mad16_cdsel |= 0xC0;
1019 break;
1020 default:
1021 printk(KERN_ERR "Unknown CDROM I/O base %d\n", cdport);
1022 return -EINVAL;
1023 }
1024 }
1025 mad16_cdsel |= irq_map[cdirq];
1026 }
1027
1028 printk(".\n");
1029
1030 cfg.io_base = io;
1031 cfg.irq = irq;
1032 cfg.dma = dma;
1033 cfg.dma2 = dma16;
1034
1035 if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
1036 printk(KERN_ERR "I/O, DMA and irq are mandatory\n");
1037 return -EINVAL;
1038 }
1039
1040 if (!request_region(MC0_PORT, 12, "mad16"))
1041 return -EBUSY;
1042
1043 if (!probe_mad16(&cfg)) {
1044 release_region(MC0_PORT, 12);
1045 return -ENODEV;
1046 }
1047
1048 cfg_mpu.io_base = mpu_io;
1049 cfg_mpu.irq = mpu_irq;
1050
1051 found_mpu = probe_mad16_mpu(&cfg_mpu);
1052
1053 if (joystick)
1054 mad16_register_gameport(0x201);
1055
1056 return 0;
1057}
1058
1059static void __exit cleanup_mad16(void)
1060{
1061 if (found_mpu)
1062 unload_mad16_mpu(&cfg_mpu);
1063 if (gameport) {
1064 /* the gameport was initialized so we must free it up */
1065 gameport_unregister_port(gameport);
1066 gameport = NULL;
1067 release_region(0x201, 1);
1068 }
1069 unload_mad16(&cfg);
1070 release_region(MC0_PORT, 12);
1071}
1072
1073module_init(init_mad16);
1074module_exit(cleanup_mad16);
1075
1076#ifndef MODULE
1077static int __init setup_mad16(char *str)
1078{
1079 /* io, irq */
1080 int ints[8];
1081
1082 str = get_options(str, ARRAY_SIZE(ints), ints);
1083
1084 io = ints[1];
1085 irq = ints[2];
1086 dma = ints[3];
1087 dma16 = ints[4];
1088 mpu_io = ints[5];
1089 mpu_irq = ints[6];
1090 joystick = ints[7];
1091
1092 return 1;
1093}
1094
1095__setup("mad16=", setup_mad16);
1096#endif
1097MODULE_LICENSE("GPL");
diff --git a/sound/oss/maestro.c b/sound/oss/maestro.c
new file mode 100644
index 000000000000..52d2db4bc312
--- /dev/null
+++ b/sound/oss/maestro.c
@@ -0,0 +1,3832 @@
1/*****************************************************************************
2 *
3 * ESS Maestro/Maestro-2/Maestro-2E driver for Linux 2.[23].x
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * (c) Copyright 1999 Alan Cox <alan.cox@linux.org>
20 *
21 * Based heavily on SonicVibes.c:
22 * Copyright (C) 1998-1999 Thomas Sailer (sailer@ife.ee.ethz.ch)
23 *
24 * Heavily modified by Zach Brown <zab@zabbo.net> based on lunch
25 * with ESS engineers. Many thanks to Howard Kim for providing
26 * contacts and hardware. Honorable mention goes to Eric
27 * Brombaugh for all sorts of things. Best regards to the
28 * proprietors of Hack Central for fine lodging.
29 *
30 * Supported devices:
31 * /dev/dsp0-3 standard /dev/dsp device, (mostly) OSS compatible
32 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
33 *
34 * Hardware Description
35 *
36 * A working Maestro setup contains the Maestro chip wired to a
37 * codec or 2. In the Maestro we have the APUs, the ASSP, and the
38 * Wavecache. The APUs can be though of as virtual audio routing
39 * channels. They can take data from a number of sources and perform
40 * basic encodings of the data. The wavecache is a storehouse for
41 * PCM data. Typically it deals with PCI and interracts with the
42 * APUs. The ASSP is a wacky DSP like device that ESS is loth
43 * to release docs on. Thankfully it isn't required on the Maestro
44 * until you start doing insane things like FM emulation and surround
45 * encoding. The codecs are almost always AC-97 compliant codecs,
46 * but it appears that early Maestros may have had PT101 (an ESS
47 * part?) wired to them. The only real difference in the Maestro
48 * families is external goop like docking capability, memory for
49 * the ASSP, and initialization differences.
50 *
51 * Driver Operation
52 *
53 * We only drive the APU/Wavecache as typical DACs and drive the
54 * mixers in the codecs. There are 64 APUs. We assign 6 to each
55 * /dev/dsp? device. 2 channels for output, and 4 channels for
56 * input.
57 *
58 * Each APU can do a number of things, but we only really use
59 * 3 basic functions. For playback we use them to convert PCM
60 * data fetched over PCI by the wavecahche into analog data that
61 * is handed to the codec. One APU for mono, and a pair for stereo.
62 * When in stereo, the combination of smarts in the APU and Wavecache
63 * decide which wavecache gets the left or right channel.
64 *
65 * For record we still use the old overly mono system. For each in
66 * coming channel the data comes in from the codec, through a 'input'
67 * APU, through another rate converter APU, and then into memory via
68 * the wavecache and PCI. If its stereo, we mash it back into LRLR in
69 * software. The pass between the 2 APUs is supposedly what requires us
70 * to have a 512 byte buffer sitting around in wavecache/memory.
71 *
72 * The wavecache makes our life even more fun. First off, it can
73 * only address the first 28 bits of PCI address space, making it
74 * useless on quite a few architectures. Secondly, its insane.
75 * It claims to fetch from 4 regions of PCI space, each 4 meg in length.
76 * But that doesn't really work. You can only use 1 region. So all our
77 * allocations have to be in 4meg of each other. Booo. Hiss.
78 * So we have a module parameter, dsps_order, that is the order of
79 * the number of dsps to provide. All their buffer space is allocated
80 * on open time. The sonicvibes OSS routines we inherited really want
81 * power of 2 buffers, so we have all those next to each other, then
82 * 512 byte regions for the recording wavecaches. This ends up
83 * wasting quite a bit of memory. The only fixes I can see would be
84 * getting a kernel allocator that could work in zones, or figuring out
85 * just how to coerce the WP into doing what we want.
86 *
87 * The indirection of the various registers means we have to spinlock
88 * nearly all register accesses. We have the main register indirection
89 * like the wave cache, maestro registers, etc. Then we have beasts
90 * like the APU interface that is indirect registers gotten at through
91 * the main maestro indirection. Ouch. We spinlock around the actual
92 * ports on a per card basis. This means spinlock activity at each IO
93 * operation, but the only IO operation clusters are in non critical
94 * paths and it makes the code far easier to follow. Interrupts are
95 * blocked while holding the locks because the int handler has to
96 * get at some of them :(. The mixer interface doesn't, however.
97 * We also have an OSS state lock that is thrown around in a few
98 * places.
99 *
100 * This driver has brute force APM suspend support. We catch suspend
101 * notifications and stop all work being done on the chip. Any people
102 * that try between this shutdown and the real suspend operation will
103 * be put to sleep. When we resume we restore our software state on
104 * the chip and wake up the people that were using it. The code thats
105 * being used now is quite dirty and assumes we're on a uni-processor
106 * machine. Much of it will need to be cleaned up for SMP ACPI or
107 * similar.
108 *
109 * We also pay attention to PCI power management now. The driver
110 * will power down units of the chip that it knows aren't needed.
111 * The WaveProcessor and company are only powered on when people
112 * have /dev/dsp*s open. On removal the driver will
113 * power down the maestro entirely. There could still be
114 * trouble with BIOSen that magically change power states
115 * themselves, but we'll see.
116 *
117 * History
118 * v0.15 - May 21 2001 - Marcus Meissner <mm@caldera.de>
119 * Ported to Linux 2.4 PCI API. Some clean ups, global devs list
120 * removed (now using pci device driver data).
121 * PM needs to be polished still. Bumped version.
122 * (still kind of v0.14) May 13 2001 - Ben Pfaff <pfaffben@msu.edu>
123 * Add support for 978 docking and basic hardware volume control
124 * (still kind of v0.14) Nov 23 - Alan Cox <alan@redhat.com>
125 * Add clocking= for people with seriously warped hardware
126 * (still v0.14) Nov 10 2000 - Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
127 * add __init to maestro_ac97_init() and maestro_install()
128 * (still based on v0.14) Mar 29 2000 - Zach Brown <zab@redhat.com>
129 * move to 2.3 power management interface, which
130 * required hacking some suspend/resume/check paths
131 * make static compilation work
132 * v0.14 - Jan 28 2000 - Zach Brown <zab@redhat.com>
133 * add PCI power management through ACPI regs.
134 * we now shut down on machine reboot/halt
135 * leave scary PCI config items alone (isa stuff, mostly)
136 * enable 1921s, it seems only mine was broke.
137 * fix swapped left/right pcm dac. har har.
138 * up bob freq, increase buffers, fix pointers at underflow
139 * silly compilation problems
140 * v0.13 - Nov 18 1999 - Zach Brown <zab@redhat.com>
141 * fix nec Versas? man would that be cool.
142 * v0.12 - Nov 12 1999 - Zach Brown <zab@redhat.com>
143 * brown bag volume max fix..
144 * v0.11 - Nov 11 1999 - Zach Brown <zab@redhat.com>
145 * use proper stereo apu decoding, mmap/write should work.
146 * make volume sliders more useful, tweak rate calculation.
147 * fix lame 8bit format reporting bug. duh. apm apu saving buglet also
148 * fix maestro 1 clock freq "bug", remove pt101 support
149 * v0.10 - Oct 28 1999 - Zach Brown <zab@redhat.com>
150 * aha, so, sometimes the WP writes a status word to offset 0
151 * from one of the PCMBARs. rearrange allocation accordingly..
152 * cheers again to Eric for being a good hacker in investigating this.
153 * Jeroen Hoogervorst submits 7500 fix out of nowhere. yay. :)
154 * v0.09 - Oct 23 1999 - Zach Brown <zab@redhat.com>
155 * added APM support.
156 * re-order something such that some 2Es now work. Magic!
157 * new codec reset routine. made some codecs come to life.
158 * fix clear_advance, sync some control with ESS.
159 * now write to all base regs to be paranoid.
160 * v0.08 - Oct 20 1999 - Zach Brown <zab@redhat.com>
161 * Fix initial buflen bug. I am so smart. also smp compiling..
162 * I owe Eric yet another beer: fixed recmask, igain,
163 * muting, and adc sync consistency. Go Team.
164 * v0.07 - Oct 4 1999 - Zach Brown <zab@redhat.com>
165 * tweak adc/dac, formating, and stuff to allow full duplex
166 * allocate dsps memory at open() so we can fit in the wavecache window
167 * fix wavecache braindamage. again. no more scribbling?
168 * fix ess 1921 codec bug on some laptops.
169 * fix dumb pci scanning bug
170 * started 2.3 cleanup, redid spinlocks, little cleanups
171 * v0.06 - Sep 20 1999 - Zach Brown <zab@redhat.com>
172 * fix wavecache thinkos. limit to 1 /dev/dsp.
173 * eric is wearing his thinking toque this week.
174 * spotted apu mode bugs and gain ramping problem
175 * don't touch weird mixer regs, make recmask optional
176 * fixed igain inversion, defaults for mixers, clean up rec_start
177 * make mono recording work.
178 * report subsystem stuff, please send reports.
179 * littles: parallel out, amp now
180 * v0.05 - Sep 17 1999 - Zach Brown <zab@redhat.com>
181 * merged and fixed up Eric's initial recording code
182 * munged format handling to catch misuse, needs rewrite.
183 * revert ring bus init, fixup shared int, add pci busmaster setting
184 * fix mixer oss interface, fix mic mute and recmask
185 * mask off unsupported mixers, reset with all 1s, modularize defaults
186 * make sure bob is running while we need it
187 * got rid of device limit, initial minimal apm hooks
188 * pull out dead code/includes, only allow multimedia/audio maestros
189 * v0.04 - Sep 01 1999 - Zach Brown <zab@redhat.com>
190 * copied memory leak fix from sonicvibes driver
191 * different ac97 reset, play with 2.0 ac97, simplify ring bus setup
192 * bob freq code, region sanity, jitter sync fix; all from Eric
193 *
194 * TODO
195 * fix bob frequency
196 * endianness
197 * do smart things with ac97 2.0 bits.
198 * dual codecs
199 * leave 54->61 open
200 *
201 * it also would be fun to have a mode that would not use pci dma at all
202 * but would copy into the wavecache on board memory and use that
203 * on architectures that don't like the maestro's pci dma ickiness.
204 */
205
206/*****************************************************************************/
207
208#include <linux/module.h>
209#include <linux/sched.h>
210#include <linux/smp_lock.h>
211#include <linux/string.h>
212#include <linux/ctype.h>
213#include <linux/ioport.h>
214#include <linux/delay.h>
215#include <linux/sound.h>
216#include <linux/slab.h>
217#include <linux/soundcard.h>
218#include <linux/pci.h>
219#include <linux/spinlock.h>
220#include <linux/init.h>
221#include <linux/interrupt.h>
222#include <linux/poll.h>
223#include <linux/reboot.h>
224#include <linux/bitops.h>
225#include <linux/wait.h>
226
227#include <asm/current.h>
228#include <asm/dma.h>
229#include <asm/io.h>
230#include <asm/page.h>
231#include <asm/uaccess.h>
232
233#include <linux/pm.h>
234static int maestro_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *d);
235
236#include "maestro.h"
237
238static struct pci_driver maestro_pci_driver;
239
240/* --------------------------------------------------------------------- */
241
242#define M_DEBUG 1
243
244#ifdef M_DEBUG
245static int debug;
246#define M_printk(args...) {if (debug) printk(args);}
247#else
248#define M_printk(x)
249#endif
250
251/* we try to setup 2^(dsps_order) /dev/dsp devices */
252static int dsps_order;
253/* whether or not we mess around with power management */
254static int use_pm=2; /* set to 1 for force */
255/* clocking for broken hardware - a few laptops seem to use a 50Khz clock
256 ie insmod with clocking=50000 or so */
257
258static int clocking=48000;
259
260MODULE_AUTHOR("Zach Brown <zab@zabbo.net>, Alan Cox <alan@redhat.com>");
261MODULE_DESCRIPTION("ESS Maestro Driver");
262MODULE_LICENSE("GPL");
263
264#ifdef M_DEBUG
265module_param(debug, bool, 0644);
266#endif
267module_param(dsps_order, int, 0);
268module_param(use_pm, int, 0);
269module_param(clocking, int, 0);
270
271/* --------------------------------------------------------------------- */
272#define DRIVER_VERSION "0.15"
273
274#ifndef PCI_VENDOR_ESS
275#define PCI_VENDOR_ESS 0x125D
276#define PCI_DEVICE_ID_ESS_ESS1968 0x1968 /* Maestro 2 */
277#define PCI_DEVICE_ID_ESS_ESS1978 0x1978 /* Maestro 2E */
278
279#define PCI_VENDOR_ESS_OLD 0x1285 /* Platform Tech,
280 the people the maestro
281 was bought from */
282#define PCI_DEVICE_ID_ESS_ESS0100 0x0100 /* maestro 1 */
283#endif /* PCI_VENDOR_ESS */
284
285#define ESS_CHAN_HARD 0x100
286
287/* NEC Versas ? */
288#define NEC_VERSA_SUBID1 0x80581033
289#define NEC_VERSA_SUBID2 0x803c1033
290
291
292/* changed so that I could actually find all the
293 references and fix them up. it's a little more readable now. */
294#define ESS_FMT_STEREO 0x01
295#define ESS_FMT_16BIT 0x02
296#define ESS_FMT_MASK 0x03
297#define ESS_DAC_SHIFT 0
298#define ESS_ADC_SHIFT 4
299
300#define ESS_STATE_MAGIC 0x125D1968
301#define ESS_CARD_MAGIC 0x19283746
302
303#define DAC_RUNNING 1
304#define ADC_RUNNING 2
305
306#define MAX_DSP_ORDER 2
307#define MAX_DSPS (1<<MAX_DSP_ORDER)
308#define NR_DSPS (1<<dsps_order)
309#define NR_IDRS 32
310
311#define NR_APUS 64
312#define NR_APU_REGS 16
313
314/* acpi states */
315enum {
316 ACPI_D0=0,
317 ACPI_D1,
318 ACPI_D2,
319 ACPI_D3
320};
321
322/* bits in the acpi masks */
323#define ACPI_12MHZ ( 1 << 15)
324#define ACPI_24MHZ ( 1 << 14)
325#define ACPI_978 ( 1 << 13)
326#define ACPI_SPDIF ( 1 << 12)
327#define ACPI_GLUE ( 1 << 11)
328#define ACPI__10 ( 1 << 10) /* reserved */
329#define ACPI_PCIINT ( 1 << 9)
330#define ACPI_HV ( 1 << 8) /* hardware volume */
331#define ACPI_GPIO ( 1 << 7)
332#define ACPI_ASSP ( 1 << 6)
333#define ACPI_SB ( 1 << 5) /* sb emul */
334#define ACPI_FM ( 1 << 4) /* fm emul */
335#define ACPI_RB ( 1 << 3) /* ringbus / aclink */
336#define ACPI_MIDI ( 1 << 2)
337#define ACPI_GP ( 1 << 1) /* game port */
338#define ACPI_WP ( 1 << 0) /* wave processor */
339
340#define ACPI_ALL (0xffff)
341#define ACPI_SLEEP (~(ACPI_SPDIF|ACPI_ASSP|ACPI_SB|ACPI_FM| \
342 ACPI_MIDI|ACPI_GP|ACPI_WP))
343#define ACPI_NONE (ACPI__10)
344
345/* these masks indicate which units we care about at
346 which states */
347static u16 acpi_state_mask[] = {
348 [ACPI_D0] = ACPI_ALL,
349 [ACPI_D1] = ACPI_SLEEP,
350 [ACPI_D2] = ACPI_SLEEP,
351 [ACPI_D3] = ACPI_NONE
352};
353
354static char version[] __devinitdata =
355KERN_INFO "maestro: version " DRIVER_VERSION " time " __TIME__ " " __DATE__ "\n";
356
357
358
359static const unsigned sample_size[] = { 1, 2, 2, 4 };
360static const unsigned sample_shift[] = { 0, 1, 1, 2 };
361
362enum card_types_t {
363 TYPE_MAESTRO,
364 TYPE_MAESTRO2,
365 TYPE_MAESTRO2E
366};
367
368static const char *card_names[]={
369 [TYPE_MAESTRO] = "ESS Maestro",
370 [TYPE_MAESTRO2] = "ESS Maestro 2",
371 [TYPE_MAESTRO2E] = "ESS Maestro 2E"
372};
373
374static int clock_freq[]={
375 [TYPE_MAESTRO] = (49152000L / 1024L),
376 [TYPE_MAESTRO2] = (50000000L / 1024L),
377 [TYPE_MAESTRO2E] = (50000000L / 1024L)
378};
379
380static int maestro_notifier(struct notifier_block *nb, unsigned long event, void *buf);
381
382static struct notifier_block maestro_nb = {maestro_notifier, NULL, 0};
383
384/* --------------------------------------------------------------------- */
385
386struct ess_state {
387 unsigned int magic;
388 /* FIXME: we probably want submixers in here, but only one record pair */
389 u8 apu[6]; /* l/r output, l/r intput converters, l/r input apus */
390 u8 apu_mode[6]; /* Running mode for this APU */
391 u8 apu_pan[6]; /* Panning setup for this APU */
392 u32 apu_base[6]; /* base address for this apu */
393 struct ess_card *card; /* Card info */
394 /* wave stuff */
395 unsigned int rateadc, ratedac;
396 unsigned char fmt, enable;
397
398 int index;
399
400 /* this locks around the oss state in the driver */
401 spinlock_t lock;
402 /* only let 1 be opening at a time */
403 struct semaphore open_sem;
404 wait_queue_head_t open_wait;
405 mode_t open_mode;
406
407 /* soundcore stuff */
408 int dev_audio;
409
410 struct dmabuf {
411 void *rawbuf;
412 unsigned buforder;
413 unsigned numfrag;
414 unsigned fragshift;
415 /* XXX zab - swptr only in here so that it can be referenced by
416 clear_advance, as far as I can tell :( */
417 unsigned hwptr, swptr;
418 unsigned total_bytes;
419 int count;
420 unsigned error; /* over/underrun */
421 wait_queue_head_t wait;
422 /* redundant, but makes calculations easier */
423 unsigned fragsize;
424 unsigned dmasize;
425 unsigned fragsamples;
426 /* OSS stuff */
427 unsigned mapped:1;
428 unsigned ready:1; /* our oss buffers are ready to go */
429 unsigned endcleared:1;
430 unsigned ossfragshift;
431 int ossmaxfrags;
432 unsigned subdivision;
433 u16 base; /* Offset for ptr */
434 } dma_dac, dma_adc;
435
436 /* pointer to each dsp?s piece of the apu->src buffer page */
437 void *mixbuf;
438
439};
440
441struct ess_card {
442 unsigned int magic;
443
444 /* We keep maestro cards in a linked list */
445 struct ess_card *next;
446
447 int dev_mixer;
448
449 int card_type;
450
451 /* as most of this is static,
452 perhaps it should be a pointer to a global struct */
453 struct mixer_goo {
454 int modcnt;
455 int supported_mixers;
456 int stereo_mixers;
457 int record_sources;
458 /* the caller must guarantee arg sanity before calling these */
459/* int (*read_mixer)(struct ess_card *card, int index);*/
460 void (*write_mixer)(struct ess_card *card,int mixer, unsigned int left,unsigned int right);
461 int (*recmask_io)(struct ess_card *card,int rw,int mask);
462 unsigned int mixer_state[SOUND_MIXER_NRDEVICES];
463 } mix;
464
465 int power_regs;
466
467 int in_suspend;
468 wait_queue_head_t suspend_queue;
469
470 struct ess_state channels[MAX_DSPS];
471 u16 maestro_map[NR_IDRS]; /* Register map */
472 /* we have to store this junk so that we can come back from a
473 suspend */
474 u16 apu_map[NR_APUS][NR_APU_REGS]; /* contents of apu regs */
475
476 /* this locks around the physical registers on the card */
477 spinlock_t lock;
478
479 /* memory for this card.. wavecache limited :(*/
480 void *dmapages;
481 int dmaorder;
482
483 /* hardware resources */
484 struct pci_dev *pcidev;
485 u32 iobase;
486 u32 irq;
487
488 int bob_freq;
489 char dsps_open;
490
491 int dock_mute_vol;
492};
493
494static void set_mixer(struct ess_card *card,unsigned int mixer, unsigned int val );
495
496static unsigned
497ld2(unsigned int x)
498{
499 unsigned r = 0;
500
501 if (x >= 0x10000) {
502 x >>= 16;
503 r += 16;
504 }
505 if (x >= 0x100) {
506 x >>= 8;
507 r += 8;
508 }
509 if (x >= 0x10) {
510 x >>= 4;
511 r += 4;
512 }
513 if (x >= 4) {
514 x >>= 2;
515 r += 2;
516 }
517 if (x >= 2)
518 r++;
519 return r;
520}
521
522
523/* --------------------------------------------------------------------- */
524
525static void check_suspend(struct ess_card *card);
526
527/* --------------------------------------------------------------------- */
528
529
530/*
531 * ESS Maestro AC97 codec programming interface.
532 */
533
534static void maestro_ac97_set(struct ess_card *card, u8 cmd, u16 val)
535{
536 int io = card->iobase;
537 int i;
538 /*
539 * Wait for the codec bus to be free
540 */
541
542 check_suspend(card);
543
544 for(i=0;i<10000;i++)
545 {
546 if(!(inb(io+ESS_AC97_INDEX)&1))
547 break;
548 }
549 /*
550 * Write the bus
551 */
552 outw(val, io+ESS_AC97_DATA);
553 mdelay(1);
554 outb(cmd, io+ESS_AC97_INDEX);
555 mdelay(1);
556}
557
558static u16 maestro_ac97_get(struct ess_card *card, u8 cmd)
559{
560 int io = card->iobase;
561 int sanity=10000;
562 u16 data;
563 int i;
564
565 check_suspend(card);
566 /*
567 * Wait for the codec bus to be free
568 */
569
570 for(i=0;i<10000;i++)
571 {
572 if(!(inb(io+ESS_AC97_INDEX)&1))
573 break;
574 }
575
576 outb(cmd|0x80, io+ESS_AC97_INDEX);
577 mdelay(1);
578
579 while(inb(io+ESS_AC97_INDEX)&1)
580 {
581 sanity--;
582 if(!sanity)
583 {
584 printk(KERN_ERR "maestro: ac97 codec timeout reading 0x%x.\n",cmd);
585 return 0;
586 }
587 }
588 data=inw(io+ESS_AC97_DATA);
589 mdelay(1);
590 return data;
591}
592
593/* OSS interface to the ac97s.. */
594
595#define AC97_STEREO_MASK (SOUND_MASK_VOLUME|\
596 SOUND_MASK_PCM|SOUND_MASK_LINE|SOUND_MASK_CD|\
597 SOUND_MASK_VIDEO|SOUND_MASK_LINE1|SOUND_MASK_IGAIN)
598
599#define AC97_SUPPORTED_MASK (AC97_STEREO_MASK | \
600 SOUND_MASK_BASS|SOUND_MASK_TREBLE|SOUND_MASK_MIC|\
601 SOUND_MASK_SPEAKER)
602
603#define AC97_RECORD_MASK (SOUND_MASK_MIC|\
604 SOUND_MASK_CD| SOUND_MASK_VIDEO| SOUND_MASK_LINE1| SOUND_MASK_LINE|\
605 SOUND_MASK_PHONEIN)
606
607#define supported_mixer(CARD,FOO) ( CARD->mix.supported_mixers & (1<<FOO) )
608
609/* this table has default mixer values for all OSS mixers.
610 be sure to fill it in if you add oss mixers
611 to anyone's supported mixer defines */
612
613static unsigned int mixer_defaults[SOUND_MIXER_NRDEVICES] = {
614 [SOUND_MIXER_VOLUME] = 0x3232,
615 [SOUND_MIXER_BASS] = 0x3232,
616 [SOUND_MIXER_TREBLE] = 0x3232,
617 [SOUND_MIXER_SPEAKER] = 0x3232,
618 [SOUND_MIXER_MIC] = 0x8000, /* annoying */
619 [SOUND_MIXER_LINE] = 0x3232,
620 [SOUND_MIXER_CD] = 0x3232,
621 [SOUND_MIXER_VIDEO] = 0x3232,
622 [SOUND_MIXER_LINE1] = 0x3232,
623 [SOUND_MIXER_PCM] = 0x3232,
624 [SOUND_MIXER_IGAIN] = 0x3232
625};
626
627static struct ac97_mixer_hw {
628 unsigned char offset;
629 int scale;
630} ac97_hw[SOUND_MIXER_NRDEVICES]= {
631 [SOUND_MIXER_VOLUME] = {0x02,63},
632 [SOUND_MIXER_BASS] = {0x08,15},
633 [SOUND_MIXER_TREBLE] = {0x08,15},
634 [SOUND_MIXER_SPEAKER] = {0x0a,15},
635 [SOUND_MIXER_MIC] = {0x0e,31},
636 [SOUND_MIXER_LINE] = {0x10,31},
637 [SOUND_MIXER_CD] = {0x12,31},
638 [SOUND_MIXER_VIDEO] = {0x14,31},
639 [SOUND_MIXER_LINE1] = {0x16,31},
640 [SOUND_MIXER_PCM] = {0x18,31},
641 [SOUND_MIXER_IGAIN] = {0x1c,15}
642};
643
644#if 0 /* *shrug* removed simply because we never used it.
645 feel free to implement again if needed */
646
647/* reads the given OSS mixer from the ac97
648 the caller must have insured that the ac97 knows
649 about that given mixer, and should be holding a
650 spinlock for the card */
651static int ac97_read_mixer(struct ess_card *card, int mixer)
652{
653 u16 val;
654 int ret=0;
655 struct ac97_mixer_hw *mh = &ac97_hw[mixer];
656
657 val = maestro_ac97_get(card, mh->offset);
658
659 if(AC97_STEREO_MASK & (1<<mixer)) {
660 /* nice stereo mixers .. */
661 int left,right;
662
663 left = (val >> 8) & 0x7f;
664 right = val & 0x7f;
665
666 if (mixer == SOUND_MIXER_IGAIN) {
667 right = (right * 100) / mh->scale;
668 left = (left * 100) / mh->scale;
669 } else {
670 right = 100 - ((right * 100) / mh->scale);
671 left = 100 - ((left * 100) / mh->scale);
672 }
673
674 ret = left | (right << 8);
675 } else if (mixer == SOUND_MIXER_SPEAKER) {
676 ret = 100 - ((((val & 0x1e)>>1) * 100) / mh->scale);
677 } else if (mixer == SOUND_MIXER_MIC) {
678 ret = 100 - (((val & 0x1f) * 100) / mh->scale);
679 /* the low bit is optional in the tone sliders and masking
680 it lets is avoid the 0xf 'bypass'.. */
681 } else if (mixer == SOUND_MIXER_BASS) {
682 ret = 100 - ((((val >> 8) & 0xe) * 100) / mh->scale);
683 } else if (mixer == SOUND_MIXER_TREBLE) {
684 ret = 100 - (((val & 0xe) * 100) / mh->scale);
685 }
686
687 M_printk("read mixer %d (0x%x) %x -> %x\n",mixer,mh->offset,val,ret);
688
689 return ret;
690}
691#endif
692
693/* write the OSS encoded volume to the given OSS encoded mixer,
694 again caller's job to make sure all is well in arg land,
695 call with spinlock held */
696
697/* linear scale -> log */
698static unsigned char lin2log[101] =
699{
7000, 0 , 15 , 23 , 30 , 34 , 38 , 42 , 45 , 47 ,
70150 , 52 , 53 , 55 , 57 , 58 , 60 , 61 , 62 ,
70263 , 65 , 66 , 67 , 68 , 69 , 69 , 70 , 71 ,
70372 , 73 , 73 , 74 , 75 , 75 , 76 , 77 , 77 ,
70478 , 78 , 79 , 80 , 80 , 81 , 81 , 82 , 82 ,
70583 , 83 , 84 , 84 , 84 , 85 , 85 , 86 , 86 ,
70687 , 87 , 87 , 88 , 88 , 88 , 89 , 89 , 89 ,
70790 , 90 , 90 , 91 , 91 , 91 , 92 , 92 , 92 ,
70893 , 93 , 93 , 94 , 94 , 94 , 94 , 95 , 95 ,
70995 , 95 , 96 , 96 , 96 , 96 , 97 , 97 , 97 ,
71097 , 98 , 98 , 98 , 98 , 99 , 99 , 99 , 99 , 99
711};
712
713static void ac97_write_mixer(struct ess_card *card,int mixer, unsigned int left, unsigned int right)
714{
715 u16 val=0;
716 struct ac97_mixer_hw *mh = &ac97_hw[mixer];
717
718 M_printk("wrote mixer %d (0x%x) %d,%d",mixer,mh->offset,left,right);
719
720 if(AC97_STEREO_MASK & (1<<mixer)) {
721 /* stereo mixers, mute them if we can */
722
723 if (mixer == SOUND_MIXER_IGAIN) {
724 /* igain's slider is reversed.. */
725 right = (right * mh->scale) / 100;
726 left = (left * mh->scale) / 100;
727 if ((left == 0) && (right == 0))
728 val |= 0x8000;
729 } else if (mixer == SOUND_MIXER_PCM || mixer == SOUND_MIXER_CD) {
730 /* log conversion seems bad for them */
731 if ((left == 0) && (right == 0))
732 val = 0x8000;
733 right = ((100 - right) * mh->scale) / 100;
734 left = ((100 - left) * mh->scale) / 100;
735 } else {
736 /* log conversion for the stereo controls */
737 if((left == 0) && (right == 0))
738 val = 0x8000;
739 right = ((100 - lin2log[right]) * mh->scale) / 100;
740 left = ((100 - lin2log[left]) * mh->scale) / 100;
741 }
742
743 val |= (left << 8) | right;
744
745 } else if (mixer == SOUND_MIXER_SPEAKER) {
746 val = (((100 - left) * mh->scale) / 100) << 1;
747 } else if (mixer == SOUND_MIXER_MIC) {
748 val = maestro_ac97_get(card, mh->offset) & ~0x801f;
749 val |= (((100 - left) * mh->scale) / 100);
750 /* the low bit is optional in the tone sliders and masking
751 it lets is avoid the 0xf 'bypass'.. */
752 } else if (mixer == SOUND_MIXER_BASS) {
753 val = maestro_ac97_get(card , mh->offset) & ~0x0f00;
754 val |= ((((100 - left) * mh->scale) / 100) << 8) & 0x0e00;
755 } else if (mixer == SOUND_MIXER_TREBLE) {
756 val = maestro_ac97_get(card , mh->offset) & ~0x000f;
757 val |= (((100 - left) * mh->scale) / 100) & 0x000e;
758 }
759
760 maestro_ac97_set(card , mh->offset, val);
761
762 M_printk(" -> %x\n",val);
763}
764
765/* the following tables allow us to go from
766 OSS <-> ac97 quickly. */
767
768enum ac97_recsettings {
769 AC97_REC_MIC=0,
770 AC97_REC_CD,
771 AC97_REC_VIDEO,
772 AC97_REC_AUX,
773 AC97_REC_LINE,
774 AC97_REC_STEREO, /* combination of all enabled outputs.. */
775 AC97_REC_MONO, /*.. or the mono equivalent */
776 AC97_REC_PHONE
777};
778
779static unsigned int ac97_oss_mask[] = {
780 [AC97_REC_MIC] = SOUND_MASK_MIC,
781 [AC97_REC_CD] = SOUND_MASK_CD,
782 [AC97_REC_VIDEO] = SOUND_MASK_VIDEO,
783 [AC97_REC_AUX] = SOUND_MASK_LINE1,
784 [AC97_REC_LINE] = SOUND_MASK_LINE,
785 [AC97_REC_PHONE] = SOUND_MASK_PHONEIN
786};
787
788/* indexed by bit position */
789static unsigned int ac97_oss_rm[] = {
790 [SOUND_MIXER_MIC] = AC97_REC_MIC,
791 [SOUND_MIXER_CD] = AC97_REC_CD,
792 [SOUND_MIXER_VIDEO] = AC97_REC_VIDEO,
793 [SOUND_MIXER_LINE1] = AC97_REC_AUX,
794 [SOUND_MIXER_LINE] = AC97_REC_LINE,
795 [SOUND_MIXER_PHONEIN] = AC97_REC_PHONE
796};
797
798/* read or write the recmask
799 the ac97 can really have left and right recording
800 inputs independently set, but OSS doesn't seem to
801 want us to express that to the user.
802 the caller guarantees that we have a supported bit set,
803 and they must be holding the card's spinlock */
804static int
805ac97_recmask_io(struct ess_card *card, int read, int mask)
806{
807 unsigned int val = ac97_oss_mask[ maestro_ac97_get(card, 0x1a) & 0x7 ];
808
809 if (read) return val;
810
811 /* oss can have many inputs, maestro can't. try
812 to pick the 'new' one */
813
814 if (mask != val) mask &= ~val;
815
816 val = ffs(mask) - 1;
817 val = ac97_oss_rm[val];
818 val |= val << 8; /* set both channels */
819
820 M_printk("maestro: setting ac97 recmask to 0x%x\n",val);
821
822 maestro_ac97_set(card,0x1a,val);
823
824 return 0;
825};
826
827/*
828 * The Maestro can be wired to a standard AC97 compliant codec
829 * (see www.intel.com for the pdf's on this), or to a PT101 codec
830 * which appears to be the ES1918 (data sheet on the esstech.com.tw site)
831 *
832 * The PT101 setup is untested.
833 */
834
835static u16 __init maestro_ac97_init(struct ess_card *card)
836{
837 u16 vend1, vend2, caps;
838
839 card->mix.supported_mixers = AC97_SUPPORTED_MASK;
840 card->mix.stereo_mixers = AC97_STEREO_MASK;
841 card->mix.record_sources = AC97_RECORD_MASK;
842/* card->mix.read_mixer = ac97_read_mixer;*/
843 card->mix.write_mixer = ac97_write_mixer;
844 card->mix.recmask_io = ac97_recmask_io;
845
846 vend1 = maestro_ac97_get(card, 0x7c);
847 vend2 = maestro_ac97_get(card, 0x7e);
848
849 caps = maestro_ac97_get(card, 0x00);
850
851 printk(KERN_INFO "maestro: AC97 Codec detected: v: 0x%2x%2x caps: 0x%x pwr: 0x%x\n",
852 vend1,vend2,caps,maestro_ac97_get(card,0x26) & 0xf);
853
854 if (! (caps & 0x4) ) {
855 /* no bass/treble nobs */
856 card->mix.supported_mixers &= ~(SOUND_MASK_BASS|SOUND_MASK_TREBLE);
857 }
858
859 /* XXX endianness, dork head. */
860 /* vendor specifc bits.. */
861 switch ((long)(vend1 << 16) | vend2) {
862 case 0x545200ff: /* TriTech */
863 /* no idea what this does */
864 maestro_ac97_set(card,0x2a,0x0001);
865 maestro_ac97_set(card,0x2c,0x0000);
866 maestro_ac97_set(card,0x2c,0xffff);
867 break;
868#if 0 /* i thought the problems I was seeing were with
869 the 1921, but apparently they were with the pci board
870 it was on, so this code is commented out.
871 lets see if this holds true. */
872 case 0x83847609: /* ESS 1921 */
873 /* writing to 0xe (mic) or 0x1a (recmask) seems
874 to hang this codec */
875 card->mix.supported_mixers &= ~(SOUND_MASK_MIC);
876 card->mix.record_sources = 0;
877 card->mix.recmask_io = NULL;
878#if 0 /* don't ask. I have yet to see what these actually do. */
879 maestro_ac97_set(card,0x76,0xABBA); /* o/~ Take a chance on me o/~ */
880 udelay(20);
881 maestro_ac97_set(card,0x78,0x3002);
882 udelay(20);
883 maestro_ac97_set(card,0x78,0x3802);
884 udelay(20);
885#endif
886 break;
887#endif
888 default: break;
889 }
890
891 maestro_ac97_set(card, 0x1E, 0x0404);
892 /* null misc stuff */
893 maestro_ac97_set(card, 0x20, 0x0000);
894
895 return 0;
896}
897
898#if 0 /* there has been 1 person on the planet with a pt101 that we
899 know of. If they care, they can put this back in :) */
900static u16 maestro_pt101_init(struct ess_card *card,int iobase)
901{
902 printk(KERN_INFO "maestro: PT101 Codec detected, initializing but _not_ installing mixer device.\n");
903 /* who knows.. */
904 maestro_ac97_set(iobase, 0x2A, 0x0001);
905 maestro_ac97_set(iobase, 0x2C, 0x0000);
906 maestro_ac97_set(iobase, 0x2C, 0xFFFF);
907 maestro_ac97_set(iobase, 0x10, 0x9F1F);
908 maestro_ac97_set(iobase, 0x12, 0x0808);
909 maestro_ac97_set(iobase, 0x14, 0x9F1F);
910 maestro_ac97_set(iobase, 0x16, 0x9F1F);
911 maestro_ac97_set(iobase, 0x18, 0x0404);
912 maestro_ac97_set(iobase, 0x1A, 0x0000);
913 maestro_ac97_set(iobase, 0x1C, 0x0000);
914 maestro_ac97_set(iobase, 0x02, 0x0404);
915 maestro_ac97_set(iobase, 0x04, 0x0808);
916 maestro_ac97_set(iobase, 0x0C, 0x801F);
917 maestro_ac97_set(iobase, 0x0E, 0x801F);
918 return 0;
919}
920#endif
921
922/* this is very magic, and very slow.. */
923static void
924maestro_ac97_reset(int ioaddr, struct pci_dev *pcidev)
925{
926 u16 save_68;
927 u16 w;
928 u32 vend;
929
930 outw( inw(ioaddr + 0x38) & 0xfffc, ioaddr + 0x38);
931 outw( inw(ioaddr + 0x3a) & 0xfffc, ioaddr + 0x3a);
932 outw( inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c);
933
934 /* reset the first codec */
935 outw(0x0000, ioaddr+0x36);
936 save_68 = inw(ioaddr+0x68);
937 pci_read_config_word(pcidev, 0x58, &w); /* something magical with gpio and bus arb. */
938 pci_read_config_dword(pcidev, PCI_SUBSYSTEM_VENDOR_ID, &vend);
939 if( w & 0x1)
940 save_68 |= 0x10;
941 outw(0xfffe, ioaddr + 0x64); /* tickly gpio 0.. */
942 outw(0x0001, ioaddr + 0x68);
943 outw(0x0000, ioaddr + 0x60);
944 udelay(20);
945 outw(0x0001, ioaddr + 0x60);
946 mdelay(20);
947
948 outw(save_68 | 0x1, ioaddr + 0x68); /* now restore .. */
949 outw( (inw(ioaddr + 0x38) & 0xfffc)|0x1, ioaddr + 0x38);
950 outw( (inw(ioaddr + 0x3a) & 0xfffc)|0x1, ioaddr + 0x3a);
951 outw( (inw(ioaddr + 0x3c) & 0xfffc)|0x1, ioaddr + 0x3c);
952
953 /* now the second codec */
954 outw(0x0000, ioaddr+0x36);
955 outw(0xfff7, ioaddr + 0x64);
956 save_68 = inw(ioaddr+0x68);
957 outw(0x0009, ioaddr + 0x68);
958 outw(0x0001, ioaddr + 0x60);
959 udelay(20);
960 outw(0x0009, ioaddr + 0x60);
961 mdelay(500); /* .. ouch.. */
962 outw( inw(ioaddr + 0x38) & 0xfffc, ioaddr + 0x38);
963 outw( inw(ioaddr + 0x3a) & 0xfffc, ioaddr + 0x3a);
964 outw( inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c);
965
966#if 0 /* the loop here needs to be much better if we want it.. */
967 M_printk("trying software reset\n");
968 /* try and do a software reset */
969 outb(0x80|0x7c, ioaddr + 0x30);
970 for (w=0; ; w++) {
971 if ((inw(ioaddr+ 0x30) & 1) == 0) {
972 if(inb(ioaddr + 0x32) !=0) break;
973
974 outb(0x80|0x7d, ioaddr + 0x30);
975 if (((inw(ioaddr+ 0x30) & 1) == 0) && (inb(ioaddr + 0x32) !=0)) break;
976 outb(0x80|0x7f, ioaddr + 0x30);
977 if (((inw(ioaddr+ 0x30) & 1) == 0) && (inb(ioaddr + 0x32) !=0)) break;
978 }
979
980 if( w > 10000) {
981 outb( inb(ioaddr + 0x37) | 0x08, ioaddr + 0x37); /* do a software reset */
982 mdelay(500); /* oh my.. */
983 outb( inb(ioaddr + 0x37) & ~0x08, ioaddr + 0x37);
984 udelay(1);
985 outw( 0x80, ioaddr+0x30);
986 for(w = 0 ; w < 10000; w++) {
987 if((inw(ioaddr + 0x30) & 1) ==0) break;
988 }
989 }
990 }
991#endif
992 if ( vend == NEC_VERSA_SUBID1 || vend == NEC_VERSA_SUBID2) {
993 /* turn on external amp? */
994 outw(0xf9ff, ioaddr + 0x64);
995 outw(inw(ioaddr+0x68) | 0x600, ioaddr + 0x68);
996 outw(0x0209, ioaddr + 0x60);
997 }
998
999 /* Turn on the 978 docking chip.
1000 First frob the "master output enable" bit,
1001 then set most of the playback volume control registers to max. */
1002 outb(inb(ioaddr+0xc0)|(1<<5), ioaddr+0xc0);
1003 outb(0xff, ioaddr+0xc3);
1004 outb(0xff, ioaddr+0xc4);
1005 outb(0xff, ioaddr+0xc6);
1006 outb(0xff, ioaddr+0xc8);
1007 outb(0x3f, ioaddr+0xcf);
1008 outb(0x3f, ioaddr+0xd0);
1009}
1010/*
1011 * Indirect register access. Not all registers are readable so we
1012 * need to keep register state ourselves
1013 */
1014
1015#define WRITEABLE_MAP 0xEFFFFF
1016#define READABLE_MAP 0x64003F
1017
1018/*
1019 * The Maestro engineers were a little indirection happy. These indirected
1020 * registers themselves include indirect registers at another layer
1021 */
1022
1023static void __maestro_write(struct ess_card *card, u16 reg, u16 data)
1024{
1025 long ioaddr = card->iobase;
1026
1027 outw(reg, ioaddr+0x02);
1028 outw(data, ioaddr+0x00);
1029 if( reg >= NR_IDRS) printk("maestro: IDR %d out of bounds!\n",reg);
1030 else card->maestro_map[reg]=data;
1031
1032}
1033
1034static void maestro_write(struct ess_state *s, u16 reg, u16 data)
1035{
1036 unsigned long flags;
1037
1038 check_suspend(s->card);
1039 spin_lock_irqsave(&s->card->lock,flags);
1040
1041 __maestro_write(s->card,reg,data);
1042
1043 spin_unlock_irqrestore(&s->card->lock,flags);
1044}
1045
1046static u16 __maestro_read(struct ess_card *card, u16 reg)
1047{
1048 long ioaddr = card->iobase;
1049
1050 outw(reg, ioaddr+0x02);
1051 return card->maestro_map[reg]=inw(ioaddr+0x00);
1052}
1053
1054static u16 maestro_read(struct ess_state *s, u16 reg)
1055{
1056 if(READABLE_MAP & (1<<reg))
1057 {
1058 unsigned long flags;
1059 check_suspend(s->card);
1060 spin_lock_irqsave(&s->card->lock,flags);
1061
1062 __maestro_read(s->card,reg);
1063
1064 spin_unlock_irqrestore(&s->card->lock,flags);
1065 }
1066 return s->card->maestro_map[reg];
1067}
1068
1069/*
1070 * These routines handle accessing the second level indirections to the
1071 * wave ram.
1072 */
1073
1074/*
1075 * The register names are the ones ESS uses (see 104T31.ZIP)
1076 */
1077
1078#define IDR0_DATA_PORT 0x00
1079#define IDR1_CRAM_POINTER 0x01
1080#define IDR2_CRAM_DATA 0x02
1081#define IDR3_WAVE_DATA 0x03
1082#define IDR4_WAVE_PTR_LOW 0x04
1083#define IDR5_WAVE_PTR_HI 0x05
1084#define IDR6_TIMER_CTRL 0x06
1085#define IDR7_WAVE_ROMRAM 0x07
1086
1087static void apu_index_set(struct ess_card *card, u16 index)
1088{
1089 int i;
1090 __maestro_write(card, IDR1_CRAM_POINTER, index);
1091 for(i=0;i<1000;i++)
1092 if(__maestro_read(card, IDR1_CRAM_POINTER)==index)
1093 return;
1094 printk(KERN_WARNING "maestro: APU register select failed.\n");
1095}
1096
1097static void apu_data_set(struct ess_card *card, u16 data)
1098{
1099 int i;
1100 for(i=0;i<1000;i++)
1101 {
1102 if(__maestro_read(card, IDR0_DATA_PORT)==data)
1103 return;
1104 __maestro_write(card, IDR0_DATA_PORT, data);
1105 }
1106}
1107
1108/*
1109 * This is the public interface for APU manipulation. It handles the
1110 * interlock to avoid two APU writes in parallel etc. Don't diddle
1111 * directly with the stuff above.
1112 */
1113
1114static void apu_set_register(struct ess_state *s, u16 channel, u8 reg, u16 data)
1115{
1116 unsigned long flags;
1117
1118 check_suspend(s->card);
1119
1120 if(channel&ESS_CHAN_HARD)
1121 channel&=~ESS_CHAN_HARD;
1122 else
1123 {
1124 if(channel>5)
1125 printk("BAD CHANNEL %d.\n",channel);
1126 else
1127 channel = s->apu[channel];
1128 /* store based on real hardware apu/reg */
1129 s->card->apu_map[channel][reg]=data;
1130 }
1131 reg|=(channel<<4);
1132
1133 /* hooray for double indirection!! */
1134 spin_lock_irqsave(&s->card->lock,flags);
1135
1136 apu_index_set(s->card, reg);
1137 apu_data_set(s->card, data);
1138
1139 spin_unlock_irqrestore(&s->card->lock,flags);
1140}
1141
1142static u16 apu_get_register(struct ess_state *s, u16 channel, u8 reg)
1143{
1144 unsigned long flags;
1145 u16 v;
1146
1147 check_suspend(s->card);
1148
1149 if(channel&ESS_CHAN_HARD)
1150 channel&=~ESS_CHAN_HARD;
1151 else
1152 channel = s->apu[channel];
1153
1154 reg|=(channel<<4);
1155
1156 spin_lock_irqsave(&s->card->lock,flags);
1157
1158 apu_index_set(s->card, reg);
1159 v=__maestro_read(s->card, IDR0_DATA_PORT);
1160
1161 spin_unlock_irqrestore(&s->card->lock,flags);
1162 return v;
1163}
1164
1165
1166/*
1167 * The wavecache buffers between the APUs and
1168 * pci bus mastering
1169 */
1170
1171static void wave_set_register(struct ess_state *s, u16 reg, u16 value)
1172{
1173 long ioaddr = s->card->iobase;
1174 unsigned long flags;
1175 check_suspend(s->card);
1176
1177 spin_lock_irqsave(&s->card->lock,flags);
1178
1179 outw(reg, ioaddr+0x10);
1180 outw(value, ioaddr+0x12);
1181
1182 spin_unlock_irqrestore(&s->card->lock,flags);
1183}
1184
1185static u16 wave_get_register(struct ess_state *s, u16 reg)
1186{
1187 long ioaddr = s->card->iobase;
1188 unsigned long flags;
1189 u16 value;
1190 check_suspend(s->card);
1191
1192 spin_lock_irqsave(&s->card->lock,flags);
1193 outw(reg, ioaddr+0x10);
1194 value=inw(ioaddr+0x12);
1195 spin_unlock_irqrestore(&s->card->lock,flags);
1196
1197 return value;
1198}
1199
1200static void sound_reset(int ioaddr)
1201{
1202 outw(0x2000, 0x18+ioaddr);
1203 udelay(1);
1204 outw(0x0000, 0x18+ioaddr);
1205 udelay(1);
1206}
1207
1208/* sets the play formats of these apus, should be passed the already shifted format */
1209static void set_apu_fmt(struct ess_state *s, int apu, int mode)
1210{
1211 int apu_fmt = 0x10;
1212
1213 if(!(mode&ESS_FMT_16BIT)) apu_fmt+=0x20;
1214 if((mode&ESS_FMT_STEREO)) apu_fmt+=0x10;
1215 s->apu_mode[apu] = apu_fmt;
1216 s->apu_mode[apu+1] = apu_fmt;
1217}
1218
1219/* this only fixes the output apu mode to be later set by start_dac and
1220 company. output apu modes are set in ess_rec_setup */
1221static void set_fmt(struct ess_state *s, unsigned char mask, unsigned char data)
1222{
1223 s->fmt = (s->fmt & mask) | data;
1224 set_apu_fmt(s, 0, (s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_MASK);
1225}
1226
1227/* this is off by a little bit.. */
1228static u32 compute_rate(struct ess_state *s, u32 freq)
1229{
1230 u32 clock = clock_freq[s->card->card_type];
1231
1232 freq = (freq * clocking)/48000;
1233
1234 if (freq == 48000)
1235 return 0x10000;
1236
1237 return ((freq / clock) <<16 )+
1238 (((freq % clock) << 16) / clock);
1239}
1240
1241static void set_dac_rate(struct ess_state *s, unsigned int rate)
1242{
1243 u32 freq;
1244 int fmt = (s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_MASK;
1245
1246 if (rate > 48000)
1247 rate = 48000;
1248 if (rate < 4000)
1249 rate = 4000;
1250
1251 s->ratedac = rate;
1252
1253 if(! (fmt & ESS_FMT_16BIT) && !(fmt & ESS_FMT_STEREO))
1254 rate >>= 1;
1255
1256/* M_printk("computing dac rate %d with mode %d\n",rate,s->fmt);*/
1257
1258 freq = compute_rate(s, rate);
1259
1260 /* Load the frequency, turn on 6dB */
1261 apu_set_register(s, 0, 2,(apu_get_register(s, 0, 2)&0x00FF)|
1262 ( ((freq&0xFF)<<8)|0x10 ));
1263 apu_set_register(s, 0, 3, freq>>8);
1264 apu_set_register(s, 1, 2,(apu_get_register(s, 1, 2)&0x00FF)|
1265 ( ((freq&0xFF)<<8)|0x10 ));
1266 apu_set_register(s, 1, 3, freq>>8);
1267}
1268
1269static void set_adc_rate(struct ess_state *s, unsigned rate)
1270{
1271 u32 freq;
1272
1273 /* Sample Rate conversion APUs don't like 0x10000 for their rate */
1274 if (rate > 47999)
1275 rate = 47999;
1276 if (rate < 4000)
1277 rate = 4000;
1278
1279 s->rateadc = rate;
1280
1281 freq = compute_rate(s, rate);
1282
1283 /* Load the frequency, turn on 6dB */
1284 apu_set_register(s, 2, 2,(apu_get_register(s, 2, 2)&0x00FF)|
1285 ( ((freq&0xFF)<<8)|0x10 ));
1286 apu_set_register(s, 2, 3, freq>>8);
1287 apu_set_register(s, 3, 2,(apu_get_register(s, 3, 2)&0x00FF)|
1288 ( ((freq&0xFF)<<8)|0x10 ));
1289 apu_set_register(s, 3, 3, freq>>8);
1290
1291 /* fix mixer rate at 48khz. and its _must_ be 0x10000. */
1292 freq = 0x10000;
1293
1294 apu_set_register(s, 4, 2,(apu_get_register(s, 4, 2)&0x00FF)|
1295 ( ((freq&0xFF)<<8)|0x10 ));
1296 apu_set_register(s, 4, 3, freq>>8);
1297 apu_set_register(s, 5, 2,(apu_get_register(s, 5, 2)&0x00FF)|
1298 ( ((freq&0xFF)<<8)|0x10 ));
1299 apu_set_register(s, 5, 3, freq>>8);
1300}
1301
1302/* Stop our host of recording apus */
1303static inline void stop_adc(struct ess_state *s)
1304{
1305 /* XXX lets hope we don't have to lock around this */
1306 if (! (s->enable & ADC_RUNNING)) return;
1307
1308 s->enable &= ~ADC_RUNNING;
1309 apu_set_register(s, 2, 0, apu_get_register(s, 2, 0)&0xFF0F);
1310 apu_set_register(s, 3, 0, apu_get_register(s, 3, 0)&0xFF0F);
1311 apu_set_register(s, 4, 0, apu_get_register(s, 2, 0)&0xFF0F);
1312 apu_set_register(s, 5, 0, apu_get_register(s, 3, 0)&0xFF0F);
1313}
1314
1315/* stop output apus */
1316static void stop_dac(struct ess_state *s)
1317{
1318 /* XXX have to lock around this? */
1319 if (! (s->enable & DAC_RUNNING)) return;
1320
1321 s->enable &= ~DAC_RUNNING;
1322 apu_set_register(s, 0, 0, apu_get_register(s, 0, 0)&0xFF0F);
1323 apu_set_register(s, 1, 0, apu_get_register(s, 1, 0)&0xFF0F);
1324}
1325
1326static void start_dac(struct ess_state *s)
1327{
1328 /* XXX locks? */
1329 if ( (s->dma_dac.mapped || s->dma_dac.count > 0) &&
1330 s->dma_dac.ready &&
1331 (! (s->enable & DAC_RUNNING)) ) {
1332
1333 s->enable |= DAC_RUNNING;
1334
1335 apu_set_register(s, 0, 0,
1336 (apu_get_register(s, 0, 0)&0xFF0F)|s->apu_mode[0]);
1337
1338 if((s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_STEREO)
1339 apu_set_register(s, 1, 0,
1340 (apu_get_register(s, 1, 0)&0xFF0F)|s->apu_mode[1]);
1341 }
1342}
1343
1344static void start_adc(struct ess_state *s)
1345{
1346 /* XXX locks? */
1347 if ((s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
1348 && s->dma_adc.ready && (! (s->enable & ADC_RUNNING)) ) {
1349
1350 s->enable |= ADC_RUNNING;
1351 apu_set_register(s, 2, 0,
1352 (apu_get_register(s, 2, 0)&0xFF0F)|s->apu_mode[2]);
1353 apu_set_register(s, 4, 0,
1354 (apu_get_register(s, 4, 0)&0xFF0F)|s->apu_mode[4]);
1355
1356 if( s->fmt & (ESS_FMT_STEREO << ESS_ADC_SHIFT)) {
1357 apu_set_register(s, 3, 0,
1358 (apu_get_register(s, 3, 0)&0xFF0F)|s->apu_mode[3]);
1359 apu_set_register(s, 5, 0,
1360 (apu_get_register(s, 5, 0)&0xFF0F)|s->apu_mode[5]);
1361 }
1362
1363 }
1364}
1365
1366
1367/*
1368 * Native play back driver
1369 */
1370
1371/* the mode passed should be already shifted and masked */
1372static void
1373ess_play_setup(struct ess_state *ess, int mode, u32 rate, void *buffer, int size)
1374{
1375 u32 pa;
1376 u32 tmpval;
1377 int high_apu = 0;
1378 int channel;
1379
1380 M_printk("mode=%d rate=%d buf=%p len=%d.\n",
1381 mode, rate, buffer, size);
1382
1383 /* all maestro sizes are in 16bit words */
1384 size >>=1;
1385
1386 if(mode&ESS_FMT_STEREO) {
1387 high_apu++;
1388 /* only 16/stereo gets size divided */
1389 if(mode&ESS_FMT_16BIT)
1390 size>>=1;
1391 }
1392
1393 for(channel=0; channel <= high_apu; channel++)
1394 {
1395 pa = virt_to_bus(buffer);
1396
1397 /* set the wavecache control reg */
1398 tmpval = (pa - 0x10) & 0xFFF8;
1399 if(!(mode & ESS_FMT_16BIT)) tmpval |= 4;
1400 if(mode & ESS_FMT_STEREO) tmpval |= 2;
1401 ess->apu_base[channel]=tmpval;
1402 wave_set_register(ess, ess->apu[channel]<<3, tmpval);
1403
1404 pa -= virt_to_bus(ess->card->dmapages);
1405 pa>>=1; /* words */
1406
1407 /* base offset of dma calcs when reading the pointer
1408 on the left one */
1409 if(!channel) ess->dma_dac.base = pa&0xFFFF;
1410
1411 pa|=0x00400000; /* System RAM */
1412
1413 /* XXX the 16bit here might not be needed.. */
1414 if((mode & ESS_FMT_STEREO) && (mode & ESS_FMT_16BIT)) {
1415 if(channel)
1416 pa|=0x00800000; /* Stereo */
1417 pa>>=1;
1418 }
1419
1420/* XXX think about endianess when writing these registers */
1421 M_printk("maestro: ess_play_setup: APU[%d] pa = 0x%x\n", ess->apu[channel], pa);
1422 /* start of sample */
1423 apu_set_register(ess, channel, 4, ((pa>>16)&0xFF)<<8);
1424 apu_set_register(ess, channel, 5, pa&0xFFFF);
1425 /* sample end */
1426 apu_set_register(ess, channel, 6, (pa+size)&0xFFFF);
1427 /* setting loop len == sample len */
1428 apu_set_register(ess, channel, 7, size);
1429
1430 /* clear effects/env.. */
1431 apu_set_register(ess, channel, 8, 0x0000);
1432 /* set amp now to 0xd0 (?), low byte is 'amplitude dest'? */
1433 apu_set_register(ess, channel, 9, 0xD000);
1434
1435 /* clear routing stuff */
1436 apu_set_register(ess, channel, 11, 0x0000);
1437 /* dma on, no envelopes, filter to all 1s) */
1438 apu_set_register(ess, channel, 0, 0x400F);
1439
1440 if(mode&ESS_FMT_16BIT)
1441 ess->apu_mode[channel]=0x10;
1442 else
1443 ess->apu_mode[channel]=0x30;
1444
1445 if(mode&ESS_FMT_STEREO) {
1446 /* set panning: left or right */
1447 apu_set_register(ess, channel, 10, 0x8F00 | (channel ? 0 : 0x10));
1448 ess->apu_mode[channel] += 0x10;
1449 } else
1450 apu_set_register(ess, channel, 10, 0x8F08);
1451 }
1452
1453 /* clear WP interrupts */
1454 outw(1, ess->card->iobase+0x04);
1455 /* enable WP ints */
1456 outw(inw(ess->card->iobase+0x18)|4, ess->card->iobase+0x18);
1457
1458 /* go team! */
1459 set_dac_rate(ess,rate);
1460 start_dac(ess);
1461}
1462
1463/*
1464 * Native record driver
1465 */
1466
1467/* again, passed mode is alrady shifted/masked */
1468static void
1469ess_rec_setup(struct ess_state *ess, int mode, u32 rate, void *buffer, int size)
1470{
1471 int apu_step = 2;
1472 int channel;
1473
1474 M_printk("maestro: ess_rec_setup: mode=%d rate=%d buf=0x%p len=%d.\n",
1475 mode, rate, buffer, size);
1476
1477 /* all maestro sizes are in 16bit words */
1478 size >>=1;
1479
1480 /* we're given the full size of the buffer, but
1481 in stereo each channel will only use its half */
1482 if(mode&ESS_FMT_STEREO) {
1483 size >>=1;
1484 apu_step = 1;
1485 }
1486
1487 /* APU assignments: 2 = mono/left SRC
1488 3 = right SRC
1489 4 = mono/left Input Mixer
1490 5 = right Input Mixer */
1491 for(channel=2;channel<6;channel+=apu_step)
1492 {
1493 int i;
1494 int bsize, route;
1495 u32 pa;
1496 u32 tmpval;
1497
1498 /* data seems to flow from the codec, through an apu into
1499 the 'mixbuf' bit of page, then through the SRC apu
1500 and out to the real 'buffer'. ok. sure. */
1501
1502 if(channel & 0x04) {
1503 /* ok, we're an input mixer going from adc
1504 through the mixbuf to the other apus */
1505
1506 if(!(channel & 0x01)) {
1507 pa = virt_to_bus(ess->mixbuf);
1508 } else {
1509 pa = virt_to_bus(ess->mixbuf + (PAGE_SIZE >> 4));
1510 }
1511
1512 /* we source from a 'magic' apu */
1513 bsize = PAGE_SIZE >> 5; /* half of this channels alloc, in words */
1514 route = 0x14 + (channel - 4); /* parallel in crap, see maestro reg 0xC [8-11] */
1515 ess->apu_mode[channel] = 0x90; /* Input Mixer */
1516
1517 } else {
1518 /* we're a rate converter taking
1519 input from the input apus and outputing it to
1520 system memory */
1521 if(!(channel & 0x01)) {
1522 pa = virt_to_bus(buffer);
1523 } else {
1524 /* right channel records its split half.
1525 *2 accommodates for rampant shifting earlier */
1526 pa = virt_to_bus(buffer + size*2);
1527 }
1528
1529 ess->apu_mode[channel] = 0xB0; /* Sample Rate Converter */
1530
1531 bsize = size;
1532 /* get input from inputing apu */
1533 route = channel + 2;
1534 }
1535
1536 M_printk("maestro: ess_rec_setup: getting pa 0x%x from %d\n",pa,channel);
1537
1538 /* set the wavecache control reg */
1539 tmpval = (pa - 0x10) & 0xFFF8;
1540 ess->apu_base[channel]=tmpval;
1541 wave_set_register(ess, ess->apu[channel]<<3, tmpval);
1542
1543 pa -= virt_to_bus(ess->card->dmapages);
1544 pa>>=1; /* words */
1545
1546 /* base offset of dma calcs when reading the pointer
1547 on this left one */
1548 if(channel==2) ess->dma_adc.base = pa&0xFFFF;
1549
1550 pa|=0x00400000; /* bit 22 -> System RAM */
1551
1552 M_printk("maestro: ess_rec_setup: APU[%d] pa = 0x%x size = 0x%x route = 0x%x\n",
1553 ess->apu[channel], pa, bsize, route);
1554
1555 /* Begin loading the APU */
1556 for(i=0;i<15;i++) /* clear all PBRs */
1557 apu_set_register(ess, channel, i, 0x0000);
1558
1559 apu_set_register(ess, channel, 0, 0x400F);
1560
1561 /* need to enable subgroups.. and we should probably
1562 have different groups for different /dev/dsps.. */
1563 apu_set_register(ess, channel, 2, 0x8);
1564
1565 /* Load the buffer into the wave engine */
1566 apu_set_register(ess, channel, 4, ((pa>>16)&0xFF)<<8);
1567 /* XXX reg is little endian.. */
1568 apu_set_register(ess, channel, 5, pa&0xFFFF);
1569 apu_set_register(ess, channel, 6, (pa+bsize)&0xFFFF);
1570 apu_set_register(ess, channel, 7, bsize);
1571
1572 /* clear effects/env.. */
1573 apu_set_register(ess, channel, 8, 0x00F0);
1574
1575 /* amplitude now? sure. why not. */
1576 apu_set_register(ess, channel, 9, 0x0000);
1577
1578 /* set filter tune, radius, polar pan */
1579 apu_set_register(ess, channel, 10, 0x8F08);
1580
1581 /* route input */
1582 apu_set_register(ess, channel, 11, route);
1583 }
1584
1585 /* clear WP interrupts */
1586 outw(1, ess->card->iobase+0x04);
1587 /* enable WP ints */
1588 outw(inw(ess->card->iobase+0x18)|4, ess->card->iobase+0x18);
1589
1590 /* let 'er rip */
1591 set_adc_rate(ess,rate);
1592 start_adc(ess);
1593}
1594/* --------------------------------------------------------------------- */
1595
1596static void set_dmaa(struct ess_state *s, unsigned int addr, unsigned int count)
1597{
1598 M_printk("set_dmaa??\n");
1599}
1600
1601static void set_dmac(struct ess_state *s, unsigned int addr, unsigned int count)
1602{
1603 M_printk("set_dmac??\n");
1604}
1605
1606/* Playback pointer */
1607static inline unsigned get_dmaa(struct ess_state *s)
1608{
1609 int offset;
1610
1611 offset = apu_get_register(s,0,5);
1612
1613/* M_printk("dmaa: offset: %d, base: %d\n",offset,s->dma_dac.base); */
1614
1615 offset-=s->dma_dac.base;
1616
1617 return (offset&0xFFFE)<<1; /* hardware is in words */
1618}
1619
1620/* Record pointer */
1621static inline unsigned get_dmac(struct ess_state *s)
1622{
1623 int offset;
1624
1625 offset = apu_get_register(s,2,5);
1626
1627/* M_printk("dmac: offset: %d, base: %d\n",offset,s->dma_adc.base); */
1628
1629 /* The offset is an address not a position relative to base */
1630 offset-=s->dma_adc.base;
1631
1632 return (offset&0xFFFE)<<1; /* hardware is in words */
1633}
1634
1635/*
1636 * Meet Bob, the timer...
1637 */
1638
1639static irqreturn_t ess_interrupt(int irq, void *dev_id, struct pt_regs *regs);
1640
1641static void stop_bob(struct ess_state *s)
1642{
1643 /* Mask IDR 11,17 */
1644 maestro_write(s, 0x11, maestro_read(s, 0x11)&~1);
1645 maestro_write(s, 0x17, maestro_read(s, 0x17)&~1);
1646}
1647
1648/* eventually we could be clever and limit bob ints
1649 to the frequency at which our smallest duration
1650 chunks may expire */
1651#define ESS_SYSCLK 50000000
1652static void start_bob(struct ess_state *s)
1653{
1654 int prescale;
1655 int divide;
1656
1657 /* XXX make freq selector much smarter, see calc_bob_rate */
1658 int freq = 200;
1659
1660 /* compute ideal interrupt frequency for buffer size & play rate */
1661 /* first, find best prescaler value to match freq */
1662 for(prescale=5;prescale<12;prescale++)
1663 if(freq > (ESS_SYSCLK>>(prescale+9)))
1664 break;
1665
1666 /* next, back off prescaler whilst getting divider into optimum range */
1667 divide=1;
1668 while((prescale > 5) && (divide<32))
1669 {
1670 prescale--;
1671 divide <<=1;
1672 }
1673 divide>>=1;
1674
1675 /* now fine-tune the divider for best match */
1676 for(;divide<31;divide++)
1677 if(freq >= ((ESS_SYSCLK>>(prescale+9))/(divide+1)))
1678 break;
1679
1680 /* divide = 0 is illegal, but don't let prescale = 4! */
1681 if(divide == 0)
1682 {
1683 divide++;
1684 if(prescale>5)
1685 prescale--;
1686 }
1687
1688 maestro_write(s, 6, 0x9000 | (prescale<<5) | divide); /* set reg */
1689
1690 /* Now set IDR 11/17 */
1691 maestro_write(s, 0x11, maestro_read(s, 0x11)|1);
1692 maestro_write(s, 0x17, maestro_read(s, 0x17)|1);
1693}
1694/* --------------------------------------------------------------------- */
1695
1696/* this quickly calculates the frequency needed for bob
1697 and sets it if its different than what bob is
1698 currently running at. its called often so
1699 needs to be fairly quick. */
1700#define BOB_MIN 50
1701#define BOB_MAX 400
1702static void calc_bob_rate(struct ess_state *s) {
1703#if 0 /* this thing tries to set the frequency of bob such that
1704 there are 2 interrupts / buffer walked by the dac/adc. That
1705 is probably very wrong for people who actually care about
1706 mid buffer positioning. it should be calculated as bytes/interrupt
1707 and that needs to be decided :) so for now just use the static 150
1708 in start_bob.*/
1709
1710 unsigned int dac_rate=2,adc_rate=1,newrate;
1711 static int israte=-1;
1712
1713 if (s->dma_dac.fragsize == 0) dac_rate = BOB_MIN;
1714 else {
1715 dac_rate = (2 * s->ratedac * sample_size[(s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_MASK]) /
1716 (s->dma_dac.fragsize) ;
1717 }
1718
1719 if (s->dma_adc.fragsize == 0) adc_rate = BOB_MIN;
1720 else {
1721 adc_rate = (2 * s->rateadc * sample_size[(s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_MASK]) /
1722 (s->dma_adc.fragsize) ;
1723 }
1724
1725 if(dac_rate > adc_rate) newrate = adc_rate;
1726 else newrate=dac_rate;
1727
1728 if(newrate > BOB_MAX) newrate = BOB_MAX;
1729 else {
1730 if(newrate < BOB_MIN)
1731 newrate = BOB_MIN;
1732 }
1733
1734 if( israte != newrate) {
1735 printk("dac: %d adc: %d rate: %d\n",dac_rate,adc_rate,israte);
1736 israte=newrate;
1737 }
1738#endif
1739
1740}
1741
1742static int
1743prog_dmabuf(struct ess_state *s, unsigned rec)
1744{
1745 struct dmabuf *db = rec ? &s->dma_adc : &s->dma_dac;
1746 unsigned rate = rec ? s->rateadc : s->ratedac;
1747 unsigned bytepersec;
1748 unsigned bufs;
1749 unsigned char fmt;
1750 unsigned long flags;
1751
1752 spin_lock_irqsave(&s->lock, flags);
1753 fmt = s->fmt;
1754 if (rec) {
1755 stop_adc(s);
1756 fmt >>= ESS_ADC_SHIFT;
1757 } else {
1758 stop_dac(s);
1759 fmt >>= ESS_DAC_SHIFT;
1760 }
1761 spin_unlock_irqrestore(&s->lock, flags);
1762 fmt &= ESS_FMT_MASK;
1763
1764 db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
1765
1766 /* this algorithm is a little nuts.. where did /1000 come from? */
1767 bytepersec = rate << sample_shift[fmt];
1768 bufs = PAGE_SIZE << db->buforder;
1769 if (db->ossfragshift) {
1770 if ((1000 << db->ossfragshift) < bytepersec)
1771 db->fragshift = ld2(bytepersec/1000);
1772 else
1773 db->fragshift = db->ossfragshift;
1774 } else {
1775 db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
1776 if (db->fragshift < 3)
1777 db->fragshift = 3;
1778 }
1779 db->numfrag = bufs >> db->fragshift;
1780 while (db->numfrag < 4 && db->fragshift > 3) {
1781 db->fragshift--;
1782 db->numfrag = bufs >> db->fragshift;
1783 }
1784 db->fragsize = 1 << db->fragshift;
1785 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
1786 db->numfrag = db->ossmaxfrags;
1787 db->fragsamples = db->fragsize >> sample_shift[fmt];
1788 db->dmasize = db->numfrag << db->fragshift;
1789
1790 M_printk("maestro: setup oss: numfrag: %d fragsize: %d dmasize: %d\n",db->numfrag,db->fragsize,db->dmasize);
1791
1792 memset(db->rawbuf, (fmt & ESS_FMT_16BIT) ? 0 : 0x80, db->dmasize);
1793
1794 spin_lock_irqsave(&s->lock, flags);
1795 if (rec)
1796 ess_rec_setup(s, fmt, s->rateadc, db->rawbuf, db->dmasize);
1797 else
1798 ess_play_setup(s, fmt, s->ratedac, db->rawbuf, db->dmasize);
1799
1800 spin_unlock_irqrestore(&s->lock, flags);
1801 db->ready = 1;
1802
1803 return 0;
1804}
1805
1806static __inline__ void
1807clear_advance(struct ess_state *s)
1808{
1809 unsigned char c = ((s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_16BIT) ? 0 : 0x80;
1810
1811 unsigned char *buf = s->dma_dac.rawbuf;
1812 unsigned bsize = s->dma_dac.dmasize;
1813 unsigned bptr = s->dma_dac.swptr;
1814 unsigned len = s->dma_dac.fragsize;
1815
1816 if (bptr + len > bsize) {
1817 unsigned x = bsize - bptr;
1818 memset(buf + bptr, c, x);
1819 /* account for wrapping? */
1820 bptr = 0;
1821 len -= x;
1822 }
1823 memset(buf + bptr, c, len);
1824}
1825
1826/* call with spinlock held! */
1827static void
1828ess_update_ptr(struct ess_state *s)
1829{
1830 unsigned hwptr;
1831 int diff;
1832
1833 /* update ADC pointer */
1834 if (s->dma_adc.ready) {
1835 /* oh boy should this all be re-written. everything in the current code paths think
1836 that the various counters/pointers are expressed in bytes to the user but we have
1837 two apus doing stereo stuff so we fix it up here.. it propagates to all the various
1838 counters from here. */
1839 if ( s->fmt & (ESS_FMT_STEREO << ESS_ADC_SHIFT)) {
1840 hwptr = (get_dmac(s)*2) % s->dma_adc.dmasize;
1841 } else {
1842 hwptr = get_dmac(s) % s->dma_adc.dmasize;
1843 }
1844 diff = (s->dma_adc.dmasize + hwptr - s->dma_adc.hwptr) % s->dma_adc.dmasize;
1845 s->dma_adc.hwptr = hwptr;
1846 s->dma_adc.total_bytes += diff;
1847 s->dma_adc.count += diff;
1848 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1849 wake_up(&s->dma_adc.wait);
1850 if (!s->dma_adc.mapped) {
1851 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
1852 /* FILL ME
1853 wrindir(s, SV_CIENABLE, s->enable); */
1854 stop_adc(s);
1855 /* brute force everyone back in sync, sigh */
1856 s->dma_adc.count = 0;
1857 s->dma_adc.swptr = 0;
1858 s->dma_adc.hwptr = 0;
1859 s->dma_adc.error++;
1860 }
1861 }
1862 }
1863 /* update DAC pointer */
1864 if (s->dma_dac.ready) {
1865 hwptr = get_dmaa(s) % s->dma_dac.dmasize;
1866 /* the apu only reports the length it has seen, not the
1867 length of the memory that has been used (the WP
1868 knows that) */
1869 if ( ((s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_MASK) == (ESS_FMT_STEREO|ESS_FMT_16BIT))
1870 hwptr<<=1;
1871
1872 diff = (s->dma_dac.dmasize + hwptr - s->dma_dac.hwptr) % s->dma_dac.dmasize;
1873/* M_printk("updating dac: hwptr: %d diff: %d\n",hwptr,diff);*/
1874 s->dma_dac.hwptr = hwptr;
1875 s->dma_dac.total_bytes += diff;
1876 if (s->dma_dac.mapped) {
1877 s->dma_dac.count += diff;
1878 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize) {
1879 wake_up(&s->dma_dac.wait);
1880 }
1881 } else {
1882 s->dma_dac.count -= diff;
1883/* M_printk("maestro: ess_update_ptr: diff: %d, count: %d\n", diff, s->dma_dac.count); */
1884 if (s->dma_dac.count <= 0) {
1885 M_printk("underflow! diff: %d count: %d hw: %d sw: %d\n", diff, s->dma_dac.count,
1886 hwptr, s->dma_dac.swptr);
1887 /* FILL ME
1888 wrindir(s, SV_CIENABLE, s->enable); */
1889 /* XXX how on earth can calling this with the lock held work.. */
1890 stop_dac(s);
1891 /* brute force everyone back in sync, sigh */
1892 s->dma_dac.count = 0;
1893 s->dma_dac.swptr = hwptr;
1894 s->dma_dac.error++;
1895 } else if (s->dma_dac.count <= (signed)s->dma_dac.fragsize && !s->dma_dac.endcleared) {
1896 clear_advance(s);
1897 s->dma_dac.endcleared = 1;
1898 }
1899 if (s->dma_dac.count + (signed)s->dma_dac.fragsize <= (signed)s->dma_dac.dmasize) {
1900 wake_up(&s->dma_dac.wait);
1901/* printk("waking up DAC count: %d sw: %d hw: %d\n",s->dma_dac.count, s->dma_dac.swptr,
1902 hwptr);*/
1903 }
1904 }
1905 }
1906}
1907
1908static irqreturn_t
1909ess_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1910{
1911 struct ess_state *s;
1912 struct ess_card *c = (struct ess_card *)dev_id;
1913 int i;
1914 u32 event;
1915
1916 if ( ! (event = inb(c->iobase+0x1A)) )
1917 return IRQ_NONE;
1918
1919 outw(inw(c->iobase+4)&1, c->iobase+4);
1920
1921/* M_printk("maestro int: %x\n",event);*/
1922 if(event&(1<<6))
1923 {
1924 int x;
1925 enum {UP_EVT, DOWN_EVT, MUTE_EVT} vol_evt;
1926 int volume;
1927
1928 /* Figure out which volume control button was pushed,
1929 based on differences from the default register
1930 values. */
1931 x = inb(c->iobase+0x1c);
1932 if (x&1) vol_evt = MUTE_EVT;
1933 else if (((x>>1)&7) > 4) vol_evt = UP_EVT;
1934 else vol_evt = DOWN_EVT;
1935
1936 /* Reset the volume control registers. */
1937 outb(0x88, c->iobase+0x1c);
1938 outb(0x88, c->iobase+0x1d);
1939 outb(0x88, c->iobase+0x1e);
1940 outb(0x88, c->iobase+0x1f);
1941
1942 /* Deal with the button press in a hammer-handed
1943 manner by adjusting the master mixer volume. */
1944 volume = c->mix.mixer_state[0] & 0xff;
1945 if (vol_evt == UP_EVT) {
1946 volume += 5;
1947 if (volume > 100)
1948 volume = 100;
1949 }
1950 else if (vol_evt == DOWN_EVT) {
1951 volume -= 5;
1952 if (volume < 0)
1953 volume = 0;
1954 } else {
1955 /* vol_evt == MUTE_EVT */
1956 if (volume == 0)
1957 volume = c->dock_mute_vol;
1958 else {
1959 c->dock_mute_vol = volume;
1960 volume = 0;
1961 }
1962 }
1963 set_mixer (c, 0, (volume << 8) | volume);
1964 }
1965
1966 /* Ack all the interrupts. */
1967 outb(0xFF, c->iobase+0x1A);
1968
1969 /*
1970 * Update the pointers for all APU's we are running.
1971 */
1972 for(i=0;i<NR_DSPS;i++)
1973 {
1974 s=&c->channels[i];
1975 if(s->dev_audio == -1)
1976 break;
1977 spin_lock(&s->lock);
1978 ess_update_ptr(s);
1979 spin_unlock(&s->lock);
1980 }
1981 return IRQ_HANDLED;
1982}
1983
1984
1985/* --------------------------------------------------------------------- */
1986
1987static const char invalid_magic[] = KERN_CRIT "maestro: invalid magic value in %s\n";
1988
1989#define VALIDATE_MAGIC(FOO,MAG) \
1990({ \
1991 if (!(FOO) || (FOO)->magic != MAG) { \
1992 printk(invalid_magic,__FUNCTION__); \
1993 return -ENXIO; \
1994 } \
1995})
1996
1997#define VALIDATE_STATE(a) VALIDATE_MAGIC(a,ESS_STATE_MAGIC)
1998#define VALIDATE_CARD(a) VALIDATE_MAGIC(a,ESS_CARD_MAGIC)
1999
2000static void set_mixer(struct ess_card *card,unsigned int mixer, unsigned int val )
2001{
2002 unsigned int left,right;
2003 /* cleanse input a little */
2004 right = ((val >> 8) & 0xff) ;
2005 left = (val & 0xff) ;
2006
2007 if(right > 100) right = 100;
2008 if(left > 100) left = 100;
2009
2010 card->mix.mixer_state[mixer]=(right << 8) | left;
2011 card->mix.write_mixer(card,mixer,left,right);
2012}
2013
2014static void
2015mixer_push_state(struct ess_card *card)
2016{
2017 int i;
2018 for(i = 0 ; i < SOUND_MIXER_NRDEVICES ; i++) {
2019 if( ! supported_mixer(card,i)) continue;
2020
2021 set_mixer(card,i,card->mix.mixer_state[i]);
2022 }
2023}
2024
2025static int mixer_ioctl(struct ess_card *card, unsigned int cmd, unsigned long arg)
2026{
2027 int i, val=0;
2028 unsigned long flags;
2029 void __user *argp = (void __user *)arg;
2030 int __user *p = argp;
2031
2032 VALIDATE_CARD(card);
2033 if (cmd == SOUND_MIXER_INFO) {
2034 mixer_info info;
2035 memset(&info, 0, sizeof(info));
2036 strlcpy(info.id, card_names[card->card_type], sizeof(info.id));
2037 strlcpy(info.name, card_names[card->card_type], sizeof(info.name));
2038 info.modify_counter = card->mix.modcnt;
2039 if (copy_to_user(argp, &info, sizeof(info)))
2040 return -EFAULT;
2041 return 0;
2042 }
2043 if (cmd == SOUND_OLD_MIXER_INFO) {
2044 _old_mixer_info info;
2045 memset(&info, 0, sizeof(info));
2046 strlcpy(info.id, card_names[card->card_type], sizeof(info.id));
2047 strlcpy(info.name, card_names[card->card_type], sizeof(info.name));
2048 if (copy_to_user(argp, &info, sizeof(info)))
2049 return -EFAULT;
2050 return 0;
2051 }
2052 if (cmd == OSS_GETVERSION)
2053 return put_user(SOUND_VERSION, p);
2054
2055 if (_IOC_TYPE(cmd) != 'M' || _IOC_SIZE(cmd) != sizeof(int))
2056 return -EINVAL;
2057
2058 if (_IOC_DIR(cmd) == _IOC_READ) {
2059 switch (_IOC_NR(cmd)) {
2060 case SOUND_MIXER_RECSRC: /* give them the current record source */
2061
2062 if(!card->mix.recmask_io) {
2063 val = 0;
2064 } else {
2065 spin_lock_irqsave(&card->lock, flags);
2066 val = card->mix.recmask_io(card,1,0);
2067 spin_unlock_irqrestore(&card->lock, flags);
2068 }
2069 break;
2070
2071 case SOUND_MIXER_DEVMASK: /* give them the supported mixers */
2072 val = card->mix.supported_mixers;
2073 break;
2074
2075 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
2076 val = card->mix.record_sources;
2077 break;
2078
2079 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
2080 val = card->mix.stereo_mixers;
2081 break;
2082
2083 case SOUND_MIXER_CAPS:
2084 val = SOUND_CAP_EXCL_INPUT;
2085 break;
2086
2087 default: /* read a specific mixer */
2088 i = _IOC_NR(cmd);
2089
2090 if ( ! supported_mixer(card,i))
2091 return -EINVAL;
2092
2093 /* do we ever want to touch the hardware? */
2094/* spin_lock_irqsave(&card->lock, flags);
2095 val = card->mix.read_mixer(card,i);
2096 spin_unlock_irqrestore(&card->lock, flags);*/
2097
2098 val = card->mix.mixer_state[i];
2099/* M_printk("returned 0x%x for mixer %d\n",val,i);*/
2100
2101 break;
2102 }
2103 return put_user(val, p);
2104 }
2105
2106 if (_IOC_DIR(cmd) != (_IOC_WRITE|_IOC_READ))
2107 return -EINVAL;
2108
2109 card->mix.modcnt++;
2110
2111 if (get_user(val, p))
2112 return -EFAULT;
2113
2114 switch (_IOC_NR(cmd)) {
2115 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
2116
2117 if (!card->mix.recmask_io) return -EINVAL;
2118 if(!val) return 0;
2119 if(! (val &= card->mix.record_sources)) return -EINVAL;
2120
2121 spin_lock_irqsave(&card->lock, flags);
2122 card->mix.recmask_io(card,0,val);
2123 spin_unlock_irqrestore(&card->lock, flags);
2124 return 0;
2125
2126 default:
2127 i = _IOC_NR(cmd);
2128
2129 if ( ! supported_mixer(card,i))
2130 return -EINVAL;
2131
2132 spin_lock_irqsave(&card->lock, flags);
2133 set_mixer(card,i,val);
2134 spin_unlock_irqrestore(&card->lock, flags);
2135
2136 return 0;
2137 }
2138}
2139
2140/* --------------------------------------------------------------------- */
2141static int ess_open_mixdev(struct inode *inode, struct file *file)
2142{
2143 unsigned int minor = iminor(inode);
2144 struct ess_card *card = NULL;
2145 struct pci_dev *pdev = NULL;
2146 struct pci_driver *drvr;
2147
2148 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
2149 drvr = pci_dev_driver (pdev);
2150 if (drvr == &maestro_pci_driver) {
2151 card = (struct ess_card*)pci_get_drvdata (pdev);
2152 if (!card)
2153 continue;
2154 if (card->dev_mixer == minor)
2155 break;
2156 }
2157 }
2158 if (!card)
2159 return -ENODEV;
2160 file->private_data = card;
2161 return nonseekable_open(inode, file);
2162}
2163
2164static int ess_release_mixdev(struct inode *inode, struct file *file)
2165{
2166 struct ess_card *card = (struct ess_card *)file->private_data;
2167
2168 VALIDATE_CARD(card);
2169
2170 return 0;
2171}
2172
2173static int ess_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2174{
2175 struct ess_card *card = (struct ess_card *)file->private_data;
2176
2177 VALIDATE_CARD(card);
2178
2179 return mixer_ioctl(card, cmd, arg);
2180}
2181
2182static /*const*/ struct file_operations ess_mixer_fops = {
2183 .owner = THIS_MODULE,
2184 .llseek = no_llseek,
2185 .ioctl = ess_ioctl_mixdev,
2186 .open = ess_open_mixdev,
2187 .release = ess_release_mixdev,
2188};
2189
2190/* --------------------------------------------------------------------- */
2191
2192static int drain_dac(struct ess_state *s, int nonblock)
2193{
2194 DECLARE_WAITQUEUE(wait,current);
2195 unsigned long flags;
2196 int count;
2197 signed long tmo;
2198
2199 if (s->dma_dac.mapped || !s->dma_dac.ready)
2200 return 0;
2201 current->state = TASK_INTERRUPTIBLE;
2202 add_wait_queue(&s->dma_dac.wait, &wait);
2203 for (;;) {
2204 /* XXX uhm.. questionable locking*/
2205 spin_lock_irqsave(&s->lock, flags);
2206 count = s->dma_dac.count;
2207 spin_unlock_irqrestore(&s->lock, flags);
2208 if (count <= 0)
2209 break;
2210 if (signal_pending(current))
2211 break;
2212 if (nonblock) {
2213 remove_wait_queue(&s->dma_dac.wait, &wait);
2214 current->state = TASK_RUNNING;
2215 return -EBUSY;
2216 }
2217 tmo = (count * HZ) / s->ratedac;
2218 tmo >>= sample_shift[(s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_MASK];
2219 /* XXX this is just broken. someone is waking us up alot, or schedule_timeout is broken.
2220 or something. who cares. - zach */
2221 if (!schedule_timeout(tmo ? tmo : 1) && tmo)
2222 M_printk(KERN_DEBUG "maestro: dma timed out?? %ld\n",jiffies);
2223 }
2224 remove_wait_queue(&s->dma_dac.wait, &wait);
2225 current->state = TASK_RUNNING;
2226 if (signal_pending(current))
2227 return -ERESTARTSYS;
2228 return 0;
2229}
2230
2231/* --------------------------------------------------------------------- */
2232/* Zach sez: "god this is gross.." */
2233static int
2234comb_stereo(unsigned char *real_buffer,unsigned char *tmp_buffer, int offset,
2235 int count, int bufsize)
2236{
2237 /* No such thing as stereo recording, so we
2238 use dual input mixers. which means we have to
2239 combine mono to stereo buffer. yuck.
2240
2241 but we don't have to be able to work a byte at a time..*/
2242
2243 unsigned char *so,*left,*right;
2244 int i;
2245
2246 so = tmp_buffer;
2247 left = real_buffer + offset;
2248 right = real_buffer + bufsize/2 + offset;
2249
2250/* M_printk("comb_stereo writing %d to %p from %p and %p, offset: %d size: %d\n",count/2, tmp_buffer,left,right,offset,bufsize);*/
2251
2252 for(i=count/4; i ; i--) {
2253 (*(so+2)) = *(right++);
2254 (*(so+3)) = *(right++);
2255 (*so) = *(left++);
2256 (*(so+1)) = *(left++);
2257 so+=4;
2258 }
2259
2260 return 0;
2261}
2262
2263/* in this loop, dma_adc.count signifies the amount of data thats waiting
2264 to be copied to the user's buffer. it is filled by the interrupt
2265 handler and drained by this loop. */
2266static ssize_t
2267ess_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2268{
2269 struct ess_state *s = (struct ess_state *)file->private_data;
2270 ssize_t ret;
2271 unsigned long flags;
2272 unsigned swptr;
2273 int cnt;
2274 unsigned char *combbuf = NULL;
2275
2276 VALIDATE_STATE(s);
2277 if (s->dma_adc.mapped)
2278 return -ENXIO;
2279 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
2280 return ret;
2281 if (!access_ok(VERIFY_WRITE, buffer, count))
2282 return -EFAULT;
2283 if(!(combbuf = kmalloc(count,GFP_KERNEL)))
2284 return -ENOMEM;
2285 ret = 0;
2286
2287 calc_bob_rate(s);
2288
2289 while (count > 0) {
2290 spin_lock_irqsave(&s->lock, flags);
2291 /* remember, all these things are expressed in bytes to be
2292 sent to the user.. hence the evil / 2 down below */
2293 swptr = s->dma_adc.swptr;
2294 cnt = s->dma_adc.dmasize-swptr;
2295 if (s->dma_adc.count < cnt)
2296 cnt = s->dma_adc.count;
2297 spin_unlock_irqrestore(&s->lock, flags);
2298
2299 if (cnt > count)
2300 cnt = count;
2301
2302 if ( cnt > 0 ) cnt &= ~3;
2303
2304 if (cnt <= 0) {
2305 start_adc(s);
2306 if (file->f_flags & O_NONBLOCK)
2307 {
2308 ret = ret ? ret : -EAGAIN;
2309 goto rec_return_free;
2310 }
2311 if (!interruptible_sleep_on_timeout(&s->dma_adc.wait, HZ)) {
2312 if(! s->card->in_suspend) printk(KERN_DEBUG "maestro: read: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
2313 s->dma_adc.dmasize, s->dma_adc.fragsize, s->dma_adc.count,
2314 s->dma_adc.hwptr, s->dma_adc.swptr);
2315 stop_adc(s);
2316 spin_lock_irqsave(&s->lock, flags);
2317 set_dmac(s, virt_to_bus(s->dma_adc.rawbuf), s->dma_adc.numfrag << s->dma_adc.fragshift);
2318 /* program enhanced mode registers */
2319 /* FILL ME */
2320/* wrindir(s, SV_CIDMACBASECOUNT1, (s->dma_adc.fragsamples-1) >> 8);
2321 wrindir(s, SV_CIDMACBASECOUNT0, s->dma_adc.fragsamples-1); */
2322 s->dma_adc.count = s->dma_adc.hwptr = s->dma_adc.swptr = 0;
2323 spin_unlock_irqrestore(&s->lock, flags);
2324 }
2325 if (signal_pending(current))
2326 {
2327 ret = ret ? ret : -ERESTARTSYS;
2328 goto rec_return_free;
2329 }
2330 continue;
2331 }
2332
2333 if(s->fmt & (ESS_FMT_STEREO << ESS_ADC_SHIFT)) {
2334 /* swptr/2 so that we know the real offset in each apu's buffer */
2335 comb_stereo(s->dma_adc.rawbuf,combbuf,swptr/2,cnt,s->dma_adc.dmasize);
2336 if (copy_to_user(buffer, combbuf, cnt)) {
2337 ret = ret ? ret : -EFAULT;
2338 goto rec_return_free;
2339 }
2340 } else {
2341 if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
2342 ret = ret ? ret : -EFAULT;
2343 goto rec_return_free;
2344 }
2345 }
2346
2347 swptr = (swptr + cnt) % s->dma_adc.dmasize;
2348 spin_lock_irqsave(&s->lock, flags);
2349 s->dma_adc.swptr = swptr;
2350 s->dma_adc.count -= cnt;
2351 spin_unlock_irqrestore(&s->lock, flags);
2352 count -= cnt;
2353 buffer += cnt;
2354 ret += cnt;
2355 start_adc(s);
2356 }
2357
2358rec_return_free:
2359 if(combbuf) kfree(combbuf);
2360 return ret;
2361}
2362
2363static ssize_t
2364ess_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2365{
2366 struct ess_state *s = (struct ess_state *)file->private_data;
2367 ssize_t ret;
2368 unsigned long flags;
2369 unsigned swptr;
2370 int cnt;
2371
2372 VALIDATE_STATE(s);
2373 if (s->dma_dac.mapped)
2374 return -ENXIO;
2375 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
2376 return ret;
2377 if (!access_ok(VERIFY_READ, buffer, count))
2378 return -EFAULT;
2379 ret = 0;
2380
2381 calc_bob_rate(s);
2382
2383 while (count > 0) {
2384 spin_lock_irqsave(&s->lock, flags);
2385
2386 if (s->dma_dac.count < 0) {
2387 s->dma_dac.count = 0;
2388 s->dma_dac.swptr = s->dma_dac.hwptr;
2389 }
2390 swptr = s->dma_dac.swptr;
2391
2392 cnt = s->dma_dac.dmasize-swptr;
2393
2394 if (s->dma_dac.count + cnt > s->dma_dac.dmasize)
2395 cnt = s->dma_dac.dmasize - s->dma_dac.count;
2396
2397 spin_unlock_irqrestore(&s->lock, flags);
2398
2399 if (cnt > count)
2400 cnt = count;
2401
2402 if (cnt <= 0) {
2403 start_dac(s);
2404 if (file->f_flags & O_NONBLOCK) {
2405 if(!ret) ret = -EAGAIN;
2406 goto return_free;
2407 }
2408 if (!interruptible_sleep_on_timeout(&s->dma_dac.wait, HZ)) {
2409 if(! s->card->in_suspend) printk(KERN_DEBUG "maestro: write: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
2410 s->dma_dac.dmasize, s->dma_dac.fragsize, s->dma_dac.count,
2411 s->dma_dac.hwptr, s->dma_dac.swptr);
2412 stop_dac(s);
2413 spin_lock_irqsave(&s->lock, flags);
2414 set_dmaa(s, virt_to_bus(s->dma_dac.rawbuf), s->dma_dac.numfrag << s->dma_dac.fragshift);
2415 /* program enhanced mode registers */
2416/* wrindir(s, SV_CIDMAABASECOUNT1, (s->dma_dac.fragsamples-1) >> 8);
2417 wrindir(s, SV_CIDMAABASECOUNT0, s->dma_dac.fragsamples-1); */
2418 /* FILL ME */
2419 s->dma_dac.count = s->dma_dac.hwptr = s->dma_dac.swptr = 0;
2420 spin_unlock_irqrestore(&s->lock, flags);
2421 }
2422 if (signal_pending(current)) {
2423 if (!ret) ret = -ERESTARTSYS;
2424 goto return_free;
2425 }
2426 continue;
2427 }
2428 if (copy_from_user(s->dma_dac.rawbuf + swptr, buffer, cnt)) {
2429 if (!ret) ret = -EFAULT;
2430 goto return_free;
2431 }
2432/* printk("wrote %d bytes at sw: %d cnt: %d while hw: %d\n",cnt, swptr, s->dma_dac.count, s->dma_dac.hwptr);*/
2433
2434 swptr = (swptr + cnt) % s->dma_dac.dmasize;
2435
2436 spin_lock_irqsave(&s->lock, flags);
2437 s->dma_dac.swptr = swptr;
2438 s->dma_dac.count += cnt;
2439 s->dma_dac.endcleared = 0;
2440 spin_unlock_irqrestore(&s->lock, flags);
2441 count -= cnt;
2442 buffer += cnt;
2443 ret += cnt;
2444 start_dac(s);
2445 }
2446return_free:
2447 return ret;
2448}
2449
2450/* No kernel lock - we have our own spinlock */
2451static unsigned int ess_poll(struct file *file, struct poll_table_struct *wait)
2452{
2453 struct ess_state *s = (struct ess_state *)file->private_data;
2454 unsigned long flags;
2455 unsigned int mask = 0;
2456
2457 VALIDATE_STATE(s);
2458
2459/* In 0.14 prog_dmabuf always returns success anyway ... */
2460 if (file->f_mode & FMODE_WRITE) {
2461 if (!s->dma_dac.ready && prog_dmabuf(s, 0))
2462 return 0;
2463 }
2464 if (file->f_mode & FMODE_READ) {
2465 if (!s->dma_adc.ready && prog_dmabuf(s, 1))
2466 return 0;
2467 }
2468
2469 if (file->f_mode & FMODE_WRITE)
2470 poll_wait(file, &s->dma_dac.wait, wait);
2471 if (file->f_mode & FMODE_READ)
2472 poll_wait(file, &s->dma_adc.wait, wait);
2473 spin_lock_irqsave(&s->lock, flags);
2474 ess_update_ptr(s);
2475 if (file->f_mode & FMODE_READ) {
2476 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
2477 mask |= POLLIN | POLLRDNORM;
2478 }
2479 if (file->f_mode & FMODE_WRITE) {
2480 if (s->dma_dac.mapped) {
2481 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
2482 mask |= POLLOUT | POLLWRNORM;
2483 } else {
2484 if ((signed)s->dma_dac.dmasize >= s->dma_dac.count + (signed)s->dma_dac.fragsize)
2485 mask |= POLLOUT | POLLWRNORM;
2486 }
2487 }
2488 spin_unlock_irqrestore(&s->lock, flags);
2489 return mask;
2490}
2491
2492static int ess_mmap(struct file *file, struct vm_area_struct *vma)
2493{
2494 struct ess_state *s = (struct ess_state *)file->private_data;
2495 struct dmabuf *db;
2496 int ret = -EINVAL;
2497 unsigned long size;
2498
2499 VALIDATE_STATE(s);
2500 lock_kernel();
2501 if (vma->vm_flags & VM_WRITE) {
2502 if ((ret = prog_dmabuf(s, 1)) != 0)
2503 goto out;
2504 db = &s->dma_dac;
2505 } else
2506#if 0
2507 /* if we can have the wp/wc do the combining
2508 we can turn this back on. */
2509 if (vma->vm_flags & VM_READ) {
2510 if ((ret = prog_dmabuf(s, 0)) != 0)
2511 goto out;
2512 db = &s->dma_adc;
2513 } else
2514#endif
2515 goto out;
2516 ret = -EINVAL;
2517 if (vma->vm_pgoff != 0)
2518 goto out;
2519 size = vma->vm_end - vma->vm_start;
2520 if (size > (PAGE_SIZE << db->buforder))
2521 goto out;
2522 ret = -EAGAIN;
2523 if (remap_pfn_range(vma, vma->vm_start,
2524 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
2525 size, vma->vm_page_prot))
2526 goto out;
2527 db->mapped = 1;
2528 ret = 0;
2529out:
2530 unlock_kernel();
2531 return ret;
2532}
2533
2534static int ess_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2535{
2536 struct ess_state *s = (struct ess_state *)file->private_data;
2537 unsigned long flags;
2538 audio_buf_info abinfo;
2539 count_info cinfo;
2540 int val, mapped, ret;
2541 unsigned char fmtm, fmtd;
2542 void __user *argp = (void __user *)arg;
2543 int __user *p = argp;
2544
2545/* printk("maestro: ess_ioctl: cmd %d\n", cmd);*/
2546
2547 VALIDATE_STATE(s);
2548 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
2549 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
2550 switch (cmd) {
2551 case OSS_GETVERSION:
2552 return put_user(SOUND_VERSION, p);
2553
2554 case SNDCTL_DSP_SYNC:
2555 if (file->f_mode & FMODE_WRITE)
2556 return drain_dac(s, file->f_flags & O_NONBLOCK);
2557 return 0;
2558
2559 case SNDCTL_DSP_SETDUPLEX:
2560 /* XXX fix */
2561 return 0;
2562
2563 case SNDCTL_DSP_GETCAPS:
2564 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
2565
2566 case SNDCTL_DSP_RESET:
2567 if (file->f_mode & FMODE_WRITE) {
2568 stop_dac(s);
2569 synchronize_irq(s->card->pcidev->irq);
2570 s->dma_dac.swptr = s->dma_dac.hwptr = s->dma_dac.count = s->dma_dac.total_bytes = 0;
2571 }
2572 if (file->f_mode & FMODE_READ) {
2573 stop_adc(s);
2574 synchronize_irq(s->card->pcidev->irq);
2575 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
2576 }
2577 return 0;
2578
2579 case SNDCTL_DSP_SPEED:
2580 if (get_user(val, p))
2581 return -EFAULT;
2582 if (val >= 0) {
2583 if (file->f_mode & FMODE_READ) {
2584 stop_adc(s);
2585 s->dma_adc.ready = 0;
2586 set_adc_rate(s, val);
2587 }
2588 if (file->f_mode & FMODE_WRITE) {
2589 stop_dac(s);
2590 s->dma_dac.ready = 0;
2591 set_dac_rate(s, val);
2592 }
2593 }
2594 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
2595
2596 case SNDCTL_DSP_STEREO:
2597 if (get_user(val, p))
2598 return -EFAULT;
2599 fmtd = 0;
2600 fmtm = ~0;
2601 if (file->f_mode & FMODE_READ) {
2602 stop_adc(s);
2603 s->dma_adc.ready = 0;
2604 if (val)
2605 fmtd |= ESS_FMT_STEREO << ESS_ADC_SHIFT;
2606 else
2607 fmtm &= ~(ESS_FMT_STEREO << ESS_ADC_SHIFT);
2608 }
2609 if (file->f_mode & FMODE_WRITE) {
2610 stop_dac(s);
2611 s->dma_dac.ready = 0;
2612 if (val)
2613 fmtd |= ESS_FMT_STEREO << ESS_DAC_SHIFT;
2614 else
2615 fmtm &= ~(ESS_FMT_STEREO << ESS_DAC_SHIFT);
2616 }
2617 set_fmt(s, fmtm, fmtd);
2618 return 0;
2619
2620 case SNDCTL_DSP_CHANNELS:
2621 if (get_user(val, p))
2622 return -EFAULT;
2623 if (val != 0) {
2624 fmtd = 0;
2625 fmtm = ~0;
2626 if (file->f_mode & FMODE_READ) {
2627 stop_adc(s);
2628 s->dma_adc.ready = 0;
2629 if (val >= 2)
2630 fmtd |= ESS_FMT_STEREO << ESS_ADC_SHIFT;
2631 else
2632 fmtm &= ~(ESS_FMT_STEREO << ESS_ADC_SHIFT);
2633 }
2634 if (file->f_mode & FMODE_WRITE) {
2635 stop_dac(s);
2636 s->dma_dac.ready = 0;
2637 if (val >= 2)
2638 fmtd |= ESS_FMT_STEREO << ESS_DAC_SHIFT;
2639 else
2640 fmtm &= ~(ESS_FMT_STEREO << ESS_DAC_SHIFT);
2641 }
2642 set_fmt(s, fmtm, fmtd);
2643 }
2644 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (ESS_FMT_STEREO << ESS_ADC_SHIFT)
2645 : (ESS_FMT_STEREO << ESS_DAC_SHIFT))) ? 2 : 1, p);
2646
2647 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
2648 return put_user(AFMT_U8|AFMT_S16_LE, p);
2649
2650 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
2651 if (get_user(val, p))
2652 return -EFAULT;
2653 if (val != AFMT_QUERY) {
2654 fmtd = 0;
2655 fmtm = ~0;
2656 if (file->f_mode & FMODE_READ) {
2657 stop_adc(s);
2658 s->dma_adc.ready = 0;
2659 /* fixed at 16bit for now */
2660 fmtd |= ESS_FMT_16BIT << ESS_ADC_SHIFT;
2661#if 0
2662 if (val == AFMT_S16_LE)
2663 fmtd |= ESS_FMT_16BIT << ESS_ADC_SHIFT;
2664 else
2665 fmtm &= ~(ESS_FMT_16BIT << ESS_ADC_SHIFT);
2666#endif
2667 }
2668 if (file->f_mode & FMODE_WRITE) {
2669 stop_dac(s);
2670 s->dma_dac.ready = 0;
2671 if (val == AFMT_S16_LE)
2672 fmtd |= ESS_FMT_16BIT << ESS_DAC_SHIFT;
2673 else
2674 fmtm &= ~(ESS_FMT_16BIT << ESS_DAC_SHIFT);
2675 }
2676 set_fmt(s, fmtm, fmtd);
2677 }
2678 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ?
2679 (ESS_FMT_16BIT << ESS_ADC_SHIFT)
2680 : (ESS_FMT_16BIT << ESS_DAC_SHIFT))) ?
2681 AFMT_S16_LE :
2682 AFMT_U8,
2683 p);
2684
2685 case SNDCTL_DSP_POST:
2686 return 0;
2687
2688 case SNDCTL_DSP_GETTRIGGER:
2689 val = 0;
2690 if ((file->f_mode & FMODE_READ) && (s->enable & ADC_RUNNING))
2691 val |= PCM_ENABLE_INPUT;
2692 if ((file->f_mode & FMODE_WRITE) && (s->enable & DAC_RUNNING))
2693 val |= PCM_ENABLE_OUTPUT;
2694 return put_user(val, p);
2695
2696 case SNDCTL_DSP_SETTRIGGER:
2697 if (get_user(val, p))
2698 return -EFAULT;
2699 if (file->f_mode & FMODE_READ) {
2700 if (val & PCM_ENABLE_INPUT) {
2701 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
2702 return ret;
2703 start_adc(s);
2704 } else
2705 stop_adc(s);
2706 }
2707 if (file->f_mode & FMODE_WRITE) {
2708 if (val & PCM_ENABLE_OUTPUT) {
2709 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
2710 return ret;
2711 start_dac(s);
2712 } else
2713 stop_dac(s);
2714 }
2715 return 0;
2716
2717 case SNDCTL_DSP_GETOSPACE:
2718 if (!(file->f_mode & FMODE_WRITE))
2719 return -EINVAL;
2720 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
2721 return ret;
2722 spin_lock_irqsave(&s->lock, flags);
2723 ess_update_ptr(s);
2724 abinfo.fragsize = s->dma_dac.fragsize;
2725 abinfo.bytes = s->dma_dac.dmasize - s->dma_dac.count;
2726 abinfo.fragstotal = s->dma_dac.numfrag;
2727 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
2728 spin_unlock_irqrestore(&s->lock, flags);
2729 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2730
2731 case SNDCTL_DSP_GETISPACE:
2732 if (!(file->f_mode & FMODE_READ))
2733 return -EINVAL;
2734 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
2735 return ret;
2736 spin_lock_irqsave(&s->lock, flags);
2737 ess_update_ptr(s);
2738 abinfo.fragsize = s->dma_adc.fragsize;
2739 abinfo.bytes = s->dma_adc.count;
2740 abinfo.fragstotal = s->dma_adc.numfrag;
2741 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
2742 spin_unlock_irqrestore(&s->lock, flags);
2743 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2744
2745 case SNDCTL_DSP_NONBLOCK:
2746 file->f_flags |= O_NONBLOCK;
2747 return 0;
2748
2749 case SNDCTL_DSP_GETODELAY:
2750 if (!(file->f_mode & FMODE_WRITE))
2751 return -EINVAL;
2752 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
2753 return ret;
2754 spin_lock_irqsave(&s->lock, flags);
2755 ess_update_ptr(s);
2756 val = s->dma_dac.count;
2757 spin_unlock_irqrestore(&s->lock, flags);
2758 return put_user(val, p);
2759
2760 case SNDCTL_DSP_GETIPTR:
2761 if (!(file->f_mode & FMODE_READ))
2762 return -EINVAL;
2763 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
2764 return ret;
2765 spin_lock_irqsave(&s->lock, flags);
2766 ess_update_ptr(s);
2767 cinfo.bytes = s->dma_adc.total_bytes;
2768 cinfo.blocks = s->dma_adc.count >> s->dma_adc.fragshift;
2769 cinfo.ptr = s->dma_adc.hwptr;
2770 if (s->dma_adc.mapped)
2771 s->dma_adc.count &= s->dma_adc.fragsize-1;
2772 spin_unlock_irqrestore(&s->lock, flags);
2773 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
2774 return -EFAULT;
2775 return 0;
2776
2777 case SNDCTL_DSP_GETOPTR:
2778 if (!(file->f_mode & FMODE_WRITE))
2779 return -EINVAL;
2780 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
2781 return ret;
2782 spin_lock_irqsave(&s->lock, flags);
2783 ess_update_ptr(s);
2784 cinfo.bytes = s->dma_dac.total_bytes;
2785 cinfo.blocks = s->dma_dac.count >> s->dma_dac.fragshift;
2786 cinfo.ptr = s->dma_dac.hwptr;
2787 if (s->dma_dac.mapped)
2788 s->dma_dac.count &= s->dma_dac.fragsize-1;
2789 spin_unlock_irqrestore(&s->lock, flags);
2790 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
2791 return -EFAULT;
2792 return 0;
2793
2794 case SNDCTL_DSP_GETBLKSIZE:
2795 if (file->f_mode & FMODE_WRITE) {
2796 if ((val = prog_dmabuf(s, 0)))
2797 return val;
2798 return put_user(s->dma_dac.fragsize, p);
2799 }
2800 if ((val = prog_dmabuf(s, 1)))
2801 return val;
2802 return put_user(s->dma_adc.fragsize, p);
2803
2804 case SNDCTL_DSP_SETFRAGMENT:
2805 if (get_user(val, p))
2806 return -EFAULT;
2807 M_printk("maestro: SETFRAGMENT: %0x\n",val);
2808 if (file->f_mode & FMODE_READ) {
2809 s->dma_adc.ossfragshift = val & 0xffff;
2810 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
2811 if (s->dma_adc.ossfragshift < 4)
2812 s->dma_adc.ossfragshift = 4;
2813 if (s->dma_adc.ossfragshift > 15)
2814 s->dma_adc.ossfragshift = 15;
2815 if (s->dma_adc.ossmaxfrags < 4)
2816 s->dma_adc.ossmaxfrags = 4;
2817 }
2818 if (file->f_mode & FMODE_WRITE) {
2819 s->dma_dac.ossfragshift = val & 0xffff;
2820 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
2821 if (s->dma_dac.ossfragshift < 4)
2822 s->dma_dac.ossfragshift = 4;
2823 if (s->dma_dac.ossfragshift > 15)
2824 s->dma_dac.ossfragshift = 15;
2825 if (s->dma_dac.ossmaxfrags < 4)
2826 s->dma_dac.ossmaxfrags = 4;
2827 }
2828 return 0;
2829
2830 case SNDCTL_DSP_SUBDIVIDE:
2831 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
2832 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
2833 return -EINVAL;
2834 if (get_user(val, p))
2835 return -EFAULT;
2836 if (val != 1 && val != 2 && val != 4)
2837 return -EINVAL;
2838 if (file->f_mode & FMODE_READ)
2839 s->dma_adc.subdivision = val;
2840 if (file->f_mode & FMODE_WRITE)
2841 s->dma_dac.subdivision = val;
2842 return 0;
2843
2844 case SOUND_PCM_READ_RATE:
2845 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
2846
2847 case SOUND_PCM_READ_CHANNELS:
2848 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (ESS_FMT_STEREO << ESS_ADC_SHIFT)
2849 : (ESS_FMT_STEREO << ESS_DAC_SHIFT))) ? 2 : 1, p);
2850
2851 case SOUND_PCM_READ_BITS:
2852 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (ESS_FMT_16BIT << ESS_ADC_SHIFT)
2853 : (ESS_FMT_16BIT << ESS_DAC_SHIFT))) ? 16 : 8, p);
2854
2855 case SOUND_PCM_WRITE_FILTER:
2856 case SNDCTL_DSP_SETSYNCRO:
2857 case SOUND_PCM_READ_FILTER:
2858 return -EINVAL;
2859
2860 }
2861 return -EINVAL;
2862}
2863
2864static void
2865set_base_registers(struct ess_state *s,void *vaddr)
2866{
2867 unsigned long packed_phys = virt_to_bus(vaddr)>>12;
2868 wave_set_register(s, 0x01FC , packed_phys);
2869 wave_set_register(s, 0x01FD , packed_phys);
2870 wave_set_register(s, 0x01FE , packed_phys);
2871 wave_set_register(s, 0x01FF , packed_phys);
2872}
2873
2874/*
2875 * this guy makes sure we're in the right power
2876 * state for what we want to be doing
2877 */
2878static void maestro_power(struct ess_card *card, int tostate)
2879{
2880 u16 active_mask = acpi_state_mask[tostate];
2881 u8 state;
2882
2883 if(!use_pm) return;
2884
2885 pci_read_config_byte(card->pcidev, card->power_regs+0x4, &state);
2886 state&=3;
2887
2888 /* make sure we're in the right state */
2889 if(state != tostate) {
2890 M_printk(KERN_WARNING "maestro: dev %02x:%02x.%x switching from D%d to D%d\n",
2891 card->pcidev->bus->number,
2892 PCI_SLOT(card->pcidev->devfn),
2893 PCI_FUNC(card->pcidev->devfn),
2894 state,tostate);
2895 pci_write_config_byte(card->pcidev, card->power_regs+0x4, tostate);
2896 }
2897
2898 /* and make sure the units we care about are on
2899 XXX we might want to do this before state flipping? */
2900 pci_write_config_word(card->pcidev, 0x54, ~ active_mask);
2901 pci_write_config_word(card->pcidev, 0x56, ~ active_mask);
2902}
2903
2904/* we allocate a large power of two for all our memory.
2905 this is cut up into (not to scale :):
2906 |silly fifo word | 512byte mixbuf per adc | dac/adc * channels |
2907*/
2908static int
2909allocate_buffers(struct ess_state *s)
2910{
2911 void *rawbuf=NULL;
2912 int order,i;
2913 struct page *page, *pend;
2914
2915 /* alloc as big a chunk as we can */
2916 for (order = (dsps_order + (16-PAGE_SHIFT) + 1); order >= (dsps_order + 2 + 1); order--)
2917 if((rawbuf = (void *)__get_free_pages(GFP_KERNEL|GFP_DMA, order)))
2918 break;
2919
2920 if (!rawbuf)
2921 return 1;
2922
2923 M_printk("maestro: allocated %ld (%d) bytes at %p\n",PAGE_SIZE<<order,order, rawbuf);
2924
2925 if ((virt_to_bus(rawbuf) + (PAGE_SIZE << order) - 1) & ~((1<<28)-1)) {
2926 printk(KERN_ERR "maestro: DMA buffer beyond 256MB! busaddr 0x%lx size %ld\n",
2927 virt_to_bus(rawbuf), PAGE_SIZE << order);
2928 kfree(rawbuf);
2929 return 1;
2930 }
2931
2932 s->card->dmapages = rawbuf;
2933 s->card->dmaorder = order;
2934
2935 for(i=0;i<NR_DSPS;i++) {
2936 struct ess_state *ess = &s->card->channels[i];
2937
2938 if(ess->dev_audio == -1)
2939 continue;
2940
2941 ess->dma_dac.ready = s->dma_dac.mapped = 0;
2942 ess->dma_adc.ready = s->dma_adc.mapped = 0;
2943 ess->dma_adc.buforder = ess->dma_dac.buforder = order - 1 - dsps_order - 1;
2944
2945 /* offset dac and adc buffers starting half way through and then at each [da][ad]c's
2946 order's intervals.. */
2947 ess->dma_dac.rawbuf = rawbuf + (PAGE_SIZE<<(order-1)) + (i * ( PAGE_SIZE << (ess->dma_dac.buforder + 1 )));
2948 ess->dma_adc.rawbuf = ess->dma_dac.rawbuf + ( PAGE_SIZE << ess->dma_dac.buforder);
2949 /* offset mixbuf by a mixbuf so that the lame status fifo can
2950 happily scribble away.. */
2951 ess->mixbuf = rawbuf + (512 * (i+1));
2952
2953 M_printk("maestro: setup apu %d: dac: %p adc: %p mix: %p\n",i,ess->dma_dac.rawbuf,
2954 ess->dma_adc.rawbuf, ess->mixbuf);
2955
2956 }
2957
2958 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
2959 pend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1);
2960 for (page = virt_to_page(rawbuf); page <= pend; page++)
2961 SetPageReserved(page);
2962
2963 return 0;
2964}
2965static void
2966free_buffers(struct ess_state *s)
2967{
2968 struct page *page, *pend;
2969
2970 s->dma_dac.rawbuf = s->dma_adc.rawbuf = NULL;
2971 s->dma_dac.mapped = s->dma_adc.mapped = 0;
2972 s->dma_dac.ready = s->dma_adc.ready = 0;
2973
2974 M_printk("maestro: freeing %p\n",s->card->dmapages);
2975 /* undo marking the pages as reserved */
2976
2977 pend = virt_to_page(s->card->dmapages + (PAGE_SIZE << s->card->dmaorder) - 1);
2978 for (page = virt_to_page(s->card->dmapages); page <= pend; page++)
2979 ClearPageReserved(page);
2980
2981 free_pages((unsigned long)s->card->dmapages,s->card->dmaorder);
2982 s->card->dmapages = NULL;
2983}
2984
2985static int
2986ess_open(struct inode *inode, struct file *file)
2987{
2988 unsigned int minor = iminor(inode);
2989 struct ess_state *s = NULL;
2990 unsigned char fmtm = ~0, fmts = 0;
2991 struct pci_dev *pdev = NULL;
2992 /*
2993 * Scan the cards and find the channel. We only
2994 * do this at open time so it is ok
2995 */
2996
2997 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
2998 struct ess_card *c;
2999 struct pci_driver *drvr;
3000
3001 drvr = pci_dev_driver (pdev);
3002 if (drvr == &maestro_pci_driver) {
3003 int i;
3004 struct ess_state *sp;
3005
3006 c = (struct ess_card*)pci_get_drvdata (pdev);
3007 if (!c)
3008 continue;
3009 for(i=0;i<NR_DSPS;i++)
3010 {
3011 sp=&c->channels[i];
3012 if(sp->dev_audio < 0)
3013 continue;
3014 if((sp->dev_audio ^ minor) & ~0xf)
3015 continue;
3016 s=sp;
3017 }
3018 }
3019 }
3020 if (!s)
3021 return -ENODEV;
3022
3023 VALIDATE_STATE(s);
3024 file->private_data = s;
3025 /* wait for device to become free */
3026 down(&s->open_sem);
3027 while (s->open_mode & file->f_mode) {
3028 if (file->f_flags & O_NONBLOCK) {
3029 up(&s->open_sem);
3030 return -EWOULDBLOCK;
3031 }
3032 up(&s->open_sem);
3033 interruptible_sleep_on(&s->open_wait);
3034 if (signal_pending(current))
3035 return -ERESTARTSYS;
3036 down(&s->open_sem);
3037 }
3038
3039 /* under semaphore.. */
3040 if ((s->card->dmapages==NULL) && allocate_buffers(s)) {
3041 up(&s->open_sem);
3042 return -ENOMEM;
3043 }
3044
3045 /* we're covered by the open_sem */
3046 if( ! s->card->dsps_open ) {
3047 maestro_power(s->card,ACPI_D0);
3048 start_bob(s);
3049 }
3050 s->card->dsps_open++;
3051 M_printk("maestro: open, %d bobs now\n",s->card->dsps_open);
3052
3053 /* ok, lets write WC base regs now that we've
3054 powered up the chip */
3055 M_printk("maestro: writing 0x%lx (bus 0x%lx) to the wp\n",virt_to_bus(s->card->dmapages),
3056 ((virt_to_bus(s->card->dmapages))&0xFFE00000)>>12);
3057 set_base_registers(s,s->card->dmapages);
3058
3059 if (file->f_mode & FMODE_READ) {
3060/*
3061 fmtm &= ~((ESS_FMT_STEREO | ESS_FMT_16BIT) << ESS_ADC_SHIFT);
3062 if ((minor & 0xf) == SND_DEV_DSP16)
3063 fmts |= ESS_FMT_16BIT << ESS_ADC_SHIFT; */
3064
3065 fmtm &= ~((ESS_FMT_STEREO|ESS_FMT_16BIT) << ESS_ADC_SHIFT);
3066 fmts = (ESS_FMT_STEREO|ESS_FMT_16BIT) << ESS_ADC_SHIFT;
3067
3068 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
3069 set_adc_rate(s, 8000);
3070 }
3071 if (file->f_mode & FMODE_WRITE) {
3072 fmtm &= ~((ESS_FMT_STEREO | ESS_FMT_16BIT) << ESS_DAC_SHIFT);
3073 if ((minor & 0xf) == SND_DEV_DSP16)
3074 fmts |= ESS_FMT_16BIT << ESS_DAC_SHIFT;
3075
3076 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = s->dma_dac.subdivision = 0;
3077 set_dac_rate(s, 8000);
3078 }
3079 set_fmt(s, fmtm, fmts);
3080 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
3081
3082 up(&s->open_sem);
3083 return nonseekable_open(inode, file);
3084}
3085
3086static int
3087ess_release(struct inode *inode, struct file *file)
3088{
3089 struct ess_state *s = (struct ess_state *)file->private_data;
3090
3091 VALIDATE_STATE(s);
3092 lock_kernel();
3093 if (file->f_mode & FMODE_WRITE)
3094 drain_dac(s, file->f_flags & O_NONBLOCK);
3095 down(&s->open_sem);
3096 if (file->f_mode & FMODE_WRITE) {
3097 stop_dac(s);
3098 }
3099 if (file->f_mode & FMODE_READ) {
3100 stop_adc(s);
3101 }
3102
3103 s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
3104 /* we're covered by the open_sem */
3105 M_printk("maestro: %d dsps now alive\n",s->card->dsps_open-1);
3106 if( --s->card->dsps_open <= 0) {
3107 s->card->dsps_open = 0;
3108 stop_bob(s);
3109 free_buffers(s);
3110 maestro_power(s->card,ACPI_D2);
3111 }
3112 up(&s->open_sem);
3113 wake_up(&s->open_wait);
3114 unlock_kernel();
3115 return 0;
3116}
3117
3118static struct file_operations ess_audio_fops = {
3119 .owner = THIS_MODULE,
3120 .llseek = no_llseek,
3121 .read = ess_read,
3122 .write = ess_write,
3123 .poll = ess_poll,
3124 .ioctl = ess_ioctl,
3125 .mmap = ess_mmap,
3126 .open = ess_open,
3127 .release = ess_release,
3128};
3129
3130static int
3131maestro_config(struct ess_card *card)
3132{
3133 struct pci_dev *pcidev = card->pcidev;
3134 struct ess_state *ess = &card->channels[0];
3135 int apu,iobase = card->iobase;
3136 u16 w;
3137 u32 n;
3138
3139 /* We used to muck around with pci config space that
3140 * we had no business messing with. We don't know enough
3141 * about the machine to know which DMA mode is appropriate,
3142 * etc. We were guessing wrong on some machines and making
3143 * them unhappy. We now trust in the BIOS to do things right,
3144 * which almost certainly means a new host of problems will
3145 * arise with broken BIOS implementations. screw 'em.
3146 * We're already intolerant of machines that don't assign
3147 * IRQs.
3148 */
3149
3150 /* do config work at full power */
3151 maestro_power(card,ACPI_D0);
3152
3153 pci_read_config_word(pcidev, 0x50, &w);
3154
3155 w&=~(1<<5); /* Don't swap left/right (undoc)*/
3156
3157 pci_write_config_word(pcidev, 0x50, w);
3158
3159 pci_read_config_word(pcidev, 0x52, &w);
3160 w&=~(1<<15); /* Turn off internal clock multiplier */
3161 /* XXX how do we know which to use? */
3162 w&=~(1<<14); /* External clock */
3163
3164 w|= (1<<7); /* Hardware volume control on */
3165 w|= (1<<6); /* Debounce off: easier to push the HWV buttons. */
3166 w&=~(1<<5); /* GPIO 4:5 */
3167 w|= (1<<4); /* Disconnect from the CHI. Enabling this made a dell 7500 work. */
3168 w&=~(1<<2); /* MIDI fix off (undoc) */
3169 w&=~(1<<1); /* reserved, always write 0 */
3170 pci_write_config_word(pcidev, 0x52, w);
3171
3172 /*
3173 * Legacy mode
3174 */
3175
3176 pci_read_config_word(pcidev, 0x40, &w);
3177 w|=(1<<15); /* legacy decode off */
3178 w&=~(1<<14); /* Disable SIRQ */
3179 w&=~(0x1f); /* disable mpu irq/io, game port, fm, SB */
3180
3181 pci_write_config_word(pcidev, 0x40, w);
3182
3183 /* Set up 978 docking control chip. */
3184 pci_read_config_word(pcidev, 0x58, &w);
3185 w|=1<<2; /* Enable 978. */
3186 w|=1<<3; /* Turn on 978 hardware volume control. */
3187 w&=~(1<<11); /* Turn on 978 mixer volume control. */
3188 pci_write_config_word(pcidev, 0x58, w);
3189
3190 sound_reset(iobase);
3191
3192 /*
3193 * Ring Bus Setup
3194 */
3195
3196 /* setup usual 0x34 stuff.. 0x36 may be chip specific */
3197 outw(0xC090, iobase+0x34); /* direct sound, stereo */
3198 udelay(20);
3199 outw(0x3000, iobase+0x36); /* direct sound, stereo */
3200 udelay(20);
3201
3202
3203 /*
3204 * Reset the CODEC
3205 */
3206
3207 maestro_ac97_reset(iobase,pcidev);
3208
3209 /*
3210 * Ring Bus Setup
3211 */
3212
3213 n=inl(iobase+0x34);
3214 n&=~0xF000;
3215 n|=12<<12; /* Direct Sound, Stereo */
3216 outl(n, iobase+0x34);
3217
3218 n=inl(iobase+0x34);
3219 n&=~0x0F00; /* Modem off */
3220 outl(n, iobase+0x34);
3221
3222 n=inl(iobase+0x34);
3223 n&=~0x00F0;
3224 n|=9<<4; /* DAC, Stereo */
3225 outl(n, iobase+0x34);
3226
3227 n=inl(iobase+0x34);
3228 n&=~0x000F; /* ASSP off */
3229 outl(n, iobase+0x34);
3230
3231 n=inl(iobase+0x34);
3232 n|=(1<<29); /* Enable ring bus */
3233 outl(n, iobase+0x34);
3234
3235 n=inl(iobase+0x34);
3236 n|=(1<<28); /* Enable serial bus */
3237 outl(n, iobase+0x34);
3238
3239 n=inl(iobase+0x34);
3240 n&=~0x00F00000; /* MIC off */
3241 outl(n, iobase+0x34);
3242
3243 n=inl(iobase+0x34);
3244 n&=~0x000F0000; /* I2S off */
3245 outl(n, iobase+0x34);
3246
3247
3248 w=inw(iobase+0x18);
3249 w&=~(1<<7); /* ClkRun off */
3250 outw(w, iobase+0x18);
3251
3252 w=inw(iobase+0x18);
3253 w&=~(1<<6); /* Hardware volume control interrupt off... for now. */
3254 outw(w, iobase+0x18);
3255
3256 w=inw(iobase+0x18);
3257 w&=~(1<<4); /* ASSP irq off */
3258 outw(w, iobase+0x18);
3259
3260 w=inw(iobase+0x18);
3261 w&=~(1<<3); /* ISDN irq off */
3262 outw(w, iobase+0x18);
3263
3264 w=inw(iobase+0x18);
3265 w|=(1<<2); /* Direct Sound IRQ on */
3266 outw(w, iobase+0x18);
3267
3268 w=inw(iobase+0x18);
3269 w&=~(1<<1); /* MPU401 IRQ off */
3270 outw(w, iobase+0x18);
3271
3272 w=inw(iobase+0x18);
3273 w|=(1<<0); /* SB IRQ on */
3274 outw(w, iobase+0x18);
3275
3276 /* Set hardware volume control registers to midpoints.
3277 We can tell which button was pushed based on how they change. */
3278 outb(0x88, iobase+0x1c);
3279 outb(0x88, iobase+0x1d);
3280 outb(0x88, iobase+0x1e);
3281 outb(0x88, iobase+0x1f);
3282
3283 /* it appears some maestros (dell 7500) only work if these are set,
3284 regardless of whether we use the assp or not. */
3285
3286 outb(0, iobase+0xA4);
3287 outb(3, iobase+0xA2);
3288 outb(0, iobase+0xA6);
3289
3290 for(apu=0;apu<16;apu++)
3291 {
3292 /* Write 0 into the buffer area 0x1E0->1EF */
3293 outw(0x01E0+apu, 0x10+iobase);
3294 outw(0x0000, 0x12+iobase);
3295
3296 /*
3297 * The 1.10 test program seem to write 0 into the buffer area
3298 * 0x1D0-0x1DF too.
3299 */
3300 outw(0x01D0+apu, 0x10+iobase);
3301 outw(0x0000, 0x12+iobase);
3302 }
3303
3304#if 1
3305 wave_set_register(ess, IDR7_WAVE_ROMRAM,
3306 (wave_get_register(ess, IDR7_WAVE_ROMRAM)&0xFF00));
3307 wave_set_register(ess, IDR7_WAVE_ROMRAM,
3308 wave_get_register(ess, IDR7_WAVE_ROMRAM)|0x100);
3309 wave_set_register(ess, IDR7_WAVE_ROMRAM,
3310 wave_get_register(ess, IDR7_WAVE_ROMRAM)&~0x200);
3311 wave_set_register(ess, IDR7_WAVE_ROMRAM,
3312 wave_get_register(ess, IDR7_WAVE_ROMRAM)|~0x400);
3313#else
3314 maestro_write(ess, IDR7_WAVE_ROMRAM,
3315 (maestro_read(ess, IDR7_WAVE_ROMRAM)&0xFF00));
3316 maestro_write(ess, IDR7_WAVE_ROMRAM,
3317 maestro_read(ess, IDR7_WAVE_ROMRAM)|0x100);
3318 maestro_write(ess, IDR7_WAVE_ROMRAM,
3319 maestro_read(ess, IDR7_WAVE_ROMRAM)&~0x200);
3320 maestro_write(ess, IDR7_WAVE_ROMRAM,
3321 maestro_read(ess, IDR7_WAVE_ROMRAM)|0x400);
3322#endif
3323
3324 maestro_write(ess, IDR2_CRAM_DATA, 0x0000);
3325 maestro_write(ess, 0x08, 0xB004);
3326 /* Now back to the DirectSound stuff */
3327 maestro_write(ess, 0x09, 0x001B);
3328 maestro_write(ess, 0x0A, 0x8000);
3329 maestro_write(ess, 0x0B, 0x3F37);
3330 maestro_write(ess, 0x0C, 0x0098);
3331
3332 /* parallel out ?? */
3333 maestro_write(ess, 0x0C,
3334 (maestro_read(ess, 0x0C)&~0xF000)|0x8000);
3335 /* parallel in, has something to do with recording :) */
3336 maestro_write(ess, 0x0C,
3337 (maestro_read(ess, 0x0C)&~0x0F00)|0x0500);
3338
3339 maestro_write(ess, 0x0D, 0x7632);
3340
3341 /* Wave cache control on - test off, sg off,
3342 enable, enable extra chans 1Mb */
3343
3344 outw(inw(0x14+iobase)|(1<<8),0x14+iobase);
3345 outw(inw(0x14+iobase)&0xFE03,0x14+iobase);
3346 outw((inw(0x14+iobase)&0xFFFC), 0x14+iobase);
3347 outw(inw(0x14+iobase)|(1<<7),0x14+iobase);
3348
3349 outw(0xA1A0, 0x14+iobase); /* 0300 ? */
3350
3351 /* Now clear the APU control ram */
3352 for(apu=0;apu<NR_APUS;apu++)
3353 {
3354 for(w=0;w<NR_APU_REGS;w++)
3355 apu_set_register(ess, apu|ESS_CHAN_HARD, w, 0);
3356
3357 }
3358
3359 return 0;
3360
3361}
3362
3363/* this guy tries to find the pci power management
3364 * register bank. this should really be in core
3365 * code somewhere. 1 on success. */
3366static int
3367parse_power(struct ess_card *card, struct pci_dev *pcidev)
3368{
3369 u32 n;
3370 u16 w;
3371 u8 next;
3372 int max = 64; /* an a 8bit guy pointing to 32bit guys
3373 can only express so much. */
3374
3375 card->power_regs = 0;
3376
3377 /* check to see if we have a capabilities list in
3378 the config register */
3379 pci_read_config_word(pcidev, PCI_STATUS, &w);
3380 if(!(w & PCI_STATUS_CAP_LIST)) return 0;
3381
3382 /* walk the list, starting at the head. */
3383 pci_read_config_byte(pcidev,PCI_CAPABILITY_LIST,&next);
3384
3385 while(next && max--) {
3386 pci_read_config_dword(pcidev, next & ~3, &n);
3387 if((n & 0xff) == PCI_CAP_ID_PM) {
3388 card->power_regs = next;
3389 break;
3390 }
3391 next = ((n>>8) & 0xff);
3392 }
3393
3394 return card->power_regs ? 1 : 0;
3395}
3396
3397static int __init
3398maestro_probe(struct pci_dev *pcidev,const struct pci_device_id *pdid)
3399{
3400 int card_type = pdid->driver_data;
3401 u32 n;
3402 int iobase;
3403 int i, ret;
3404 struct ess_card *card;
3405 struct ess_state *ess;
3406 struct pm_dev *pmdev;
3407 int num = 0;
3408
3409/* when built into the kernel, we only print version if device is found */
3410#ifndef MODULE
3411 static int printed_version;
3412 if (!printed_version++)
3413 printk(version);
3414#endif
3415
3416 /* don't pick up weird modem maestros */
3417 if(((pcidev->class >> 8) & 0xffff) != PCI_CLASS_MULTIMEDIA_AUDIO)
3418 return -ENODEV;
3419
3420
3421 if ((ret=pci_enable_device(pcidev)))
3422 return ret;
3423
3424 iobase = pci_resource_start(pcidev,0);
3425 if (!iobase || !(pci_resource_flags(pcidev, 0 ) & IORESOURCE_IO))
3426 return -ENODEV;
3427
3428 if(pcidev->irq == 0)
3429 return -ENODEV;
3430
3431 /* stake our claim on the iospace */
3432 if( request_region(iobase, 256, card_names[card_type]) == NULL )
3433 {
3434 printk(KERN_WARNING "maestro: can't allocate 256 bytes I/O at 0x%4.4x\n", iobase);
3435 return -EBUSY;
3436 }
3437
3438 /* just to be sure */
3439 pci_set_master(pcidev);
3440
3441 card = kmalloc(sizeof(struct ess_card), GFP_KERNEL);
3442 if(card == NULL)
3443 {
3444 printk(KERN_WARNING "maestro: out of memory\n");
3445 release_region(iobase, 256);
3446 return -ENOMEM;
3447 }
3448
3449 memset(card, 0, sizeof(*card));
3450 card->pcidev = pcidev;
3451
3452 pmdev = pm_register(PM_PCI_DEV, PM_PCI_ID(pcidev),
3453 maestro_pm_callback);
3454 if (pmdev)
3455 pmdev->data = card;
3456
3457 card->iobase = iobase;
3458 card->card_type = card_type;
3459 card->irq = pcidev->irq;
3460 card->magic = ESS_CARD_MAGIC;
3461 spin_lock_init(&card->lock);
3462 init_waitqueue_head(&card->suspend_queue);
3463
3464 card->dock_mute_vol = 50;
3465
3466 /* init our groups of 6 apus */
3467 for(i=0;i<NR_DSPS;i++)
3468 {
3469 struct ess_state *s=&card->channels[i];
3470
3471 s->index = i;
3472
3473 s->card = card;
3474 init_waitqueue_head(&s->dma_adc.wait);
3475 init_waitqueue_head(&s->dma_dac.wait);
3476 init_waitqueue_head(&s->open_wait);
3477 spin_lock_init(&s->lock);
3478 init_MUTEX(&s->open_sem);
3479 s->magic = ESS_STATE_MAGIC;
3480
3481 s->apu[0] = 6*i;
3482 s->apu[1] = (6*i)+1;
3483 s->apu[2] = (6*i)+2;
3484 s->apu[3] = (6*i)+3;
3485 s->apu[4] = (6*i)+4;
3486 s->apu[5] = (6*i)+5;
3487
3488 if(s->dma_adc.ready || s->dma_dac.ready || s->dma_adc.rawbuf)
3489 printk("maestro: BOTCH!\n");
3490 /* register devices */
3491 if ((s->dev_audio = register_sound_dsp(&ess_audio_fops, -1)) < 0)
3492 break;
3493 }
3494
3495 num = i;
3496
3497 /* clear the rest if we ran out of slots to register */
3498 for(;i<NR_DSPS;i++)
3499 {
3500 struct ess_state *s=&card->channels[i];
3501 s->dev_audio = -1;
3502 }
3503
3504 ess = &card->channels[0];
3505
3506 /*
3507 * Ok card ready. Begin setup proper
3508 */
3509
3510 printk(KERN_INFO "maestro: Configuring %s found at IO 0x%04X IRQ %d\n",
3511 card_names[card_type],iobase,card->irq);
3512 pci_read_config_dword(pcidev, PCI_SUBSYSTEM_VENDOR_ID, &n);
3513 printk(KERN_INFO "maestro: subvendor id: 0x%08x\n",n);
3514
3515 /* turn off power management unless:
3516 * - the user explicitly asks for it
3517 * or
3518 * - we're not a 2e, lesser chipps seem to have problems.
3519 * - we're not on our _very_ small whitelist. some implemenetations
3520 * really don't like the pm code, others require it.
3521 * feel free to expand this as required.
3522 */
3523#define SUBSYSTEM_VENDOR(x) (x&0xffff)
3524 if( (use_pm != 1) &&
3525 ((card_type != TYPE_MAESTRO2E) || (SUBSYSTEM_VENDOR(n) != 0x1028)))
3526 use_pm = 0;
3527
3528 if(!use_pm)
3529 printk(KERN_INFO "maestro: not attempting power management.\n");
3530 else {
3531 if(!parse_power(card,pcidev))
3532 printk(KERN_INFO "maestro: no PCI power management interface found.\n");
3533 else {
3534 pci_read_config_dword(pcidev, card->power_regs, &n);
3535 printk(KERN_INFO "maestro: PCI power management capability: 0x%x\n",n>>16);
3536 }
3537 }
3538
3539 maestro_config(card);
3540
3541 if(maestro_ac97_get(card, 0x00)==0x0080) {
3542 printk(KERN_ERR "maestro: my goodness! you seem to have a pt101 codec, which is quite rare.\n"
3543 "\tyou should tell someone about this.\n");
3544 } else {
3545 maestro_ac97_init(card);
3546 }
3547
3548 if ((card->dev_mixer = register_sound_mixer(&ess_mixer_fops, -1)) < 0) {
3549 printk("maestro: couldn't register mixer!\n");
3550 } else {
3551 memcpy(card->mix.mixer_state,mixer_defaults,sizeof(card->mix.mixer_state));
3552 mixer_push_state(card);
3553 }
3554
3555 if((ret=request_irq(card->irq, ess_interrupt, SA_SHIRQ, card_names[card_type], card)))
3556 {
3557 printk(KERN_ERR "maestro: unable to allocate irq %d,\n", card->irq);
3558 unregister_sound_mixer(card->dev_mixer);
3559 for(i=0;i<NR_DSPS;i++)
3560 {
3561 struct ess_state *s = &card->channels[i];
3562 if(s->dev_audio != -1)
3563 unregister_sound_dsp(s->dev_audio);
3564 }
3565 release_region(card->iobase, 256);
3566 unregister_reboot_notifier(&maestro_nb);
3567 kfree(card);
3568 return ret;
3569 }
3570
3571 /* Turn on hardware volume control interrupt.
3572 This has to come after we grab the IRQ above,
3573 or a crash will result on installation if a button has been pressed,
3574 because in that case we'll get an immediate interrupt. */
3575 n = inw(iobase+0x18);
3576 n|=(1<<6);
3577 outw(n, iobase+0x18);
3578
3579 pci_set_drvdata(pcidev,card);
3580 /* now go to sleep 'till something interesting happens */
3581 maestro_power(card,ACPI_D2);
3582
3583 printk(KERN_INFO "maestro: %d channels configured.\n", num);
3584 return 0;
3585}
3586
3587static void maestro_remove(struct pci_dev *pcidev) {
3588 struct ess_card *card = pci_get_drvdata(pcidev);
3589 int i;
3590 u32 n;
3591
3592 /* XXX maybe should force stop bob, but should be all
3593 stopped by _release by now */
3594
3595 /* Turn off hardware volume control interrupt.
3596 This has to come before we leave the IRQ below,
3597 or a crash results if a button is pressed ! */
3598 n = inw(card->iobase+0x18);
3599 n&=~(1<<6);
3600 outw(n, card->iobase+0x18);
3601
3602 free_irq(card->irq, card);
3603 unregister_sound_mixer(card->dev_mixer);
3604 for(i=0;i<NR_DSPS;i++)
3605 {
3606 struct ess_state *ess = &card->channels[i];
3607 if(ess->dev_audio != -1)
3608 unregister_sound_dsp(ess->dev_audio);
3609 }
3610 /* Goodbye, Mr. Bond. */
3611 maestro_power(card,ACPI_D3);
3612 release_region(card->iobase, 256);
3613 kfree(card);
3614 pci_set_drvdata(pcidev,NULL);
3615}
3616
3617static struct pci_device_id maestro_pci_tbl[] = {
3618 {PCI_VENDOR_ESS, PCI_DEVICE_ID_ESS_ESS1968, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_MAESTRO2},
3619 {PCI_VENDOR_ESS, PCI_DEVICE_ID_ESS_ESS1978, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_MAESTRO2E},
3620 {PCI_VENDOR_ESS_OLD, PCI_DEVICE_ID_ESS_ESS0100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_MAESTRO},
3621 {0,}
3622};
3623MODULE_DEVICE_TABLE(pci, maestro_pci_tbl);
3624
3625static struct pci_driver maestro_pci_driver = {
3626 .name = "maestro",
3627 .id_table = maestro_pci_tbl,
3628 .probe = maestro_probe,
3629 .remove = maestro_remove,
3630};
3631
3632static int __init init_maestro(void)
3633{
3634 int rc;
3635
3636 rc = pci_module_init(&maestro_pci_driver);
3637 if (rc < 0)
3638 return rc;
3639
3640 if (register_reboot_notifier(&maestro_nb))
3641 printk(KERN_WARNING "maestro: reboot notifier registration failed; may not reboot properly.\n");
3642#ifdef MODULE
3643 printk(version);
3644#endif
3645 if (dsps_order < 0) {
3646 dsps_order = 1;
3647 printk(KERN_WARNING "maestro: clipping dsps_order to %d\n",dsps_order);
3648 }
3649 else if (dsps_order > MAX_DSP_ORDER) {
3650 dsps_order = MAX_DSP_ORDER;
3651 printk(KERN_WARNING "maestro: clipping dsps_order to %d\n",dsps_order);
3652 }
3653 return 0;
3654}
3655
3656static int maestro_notifier(struct notifier_block *nb, unsigned long event, void *buf)
3657{
3658 /* this notifier is called when the kernel is really shut down. */
3659 M_printk("maestro: shutting down\n");
3660 /* this will remove all card instances too */
3661 pci_unregister_driver(&maestro_pci_driver);
3662 /* XXX dunno about power management */
3663 return NOTIFY_OK;
3664}
3665
3666/* --------------------------------------------------------------------- */
3667
3668
3669static void cleanup_maestro(void) {
3670 M_printk("maestro: unloading\n");
3671 pci_unregister_driver(&maestro_pci_driver);
3672 pm_unregister_all(maestro_pm_callback);
3673 unregister_reboot_notifier(&maestro_nb);
3674}
3675
3676/* --------------------------------------------------------------------- */
3677
3678void
3679check_suspend(struct ess_card *card)
3680{
3681 DECLARE_WAITQUEUE(wait, current);
3682
3683 if(!card->in_suspend) return;
3684
3685 card->in_suspend++;
3686 add_wait_queue(&(card->suspend_queue), &wait);
3687 current->state = TASK_UNINTERRUPTIBLE;
3688 schedule();
3689 remove_wait_queue(&(card->suspend_queue), &wait);
3690 current->state = TASK_RUNNING;
3691}
3692
3693static int
3694maestro_suspend(struct ess_card *card)
3695{
3696 unsigned long flags;
3697 int i,j;
3698
3699 spin_lock_irqsave(&card->lock,flags); /* over-kill */
3700
3701 M_printk("maestro: apm in dev %p\n",card);
3702
3703 /* we have to read from the apu regs, need
3704 to power it up */
3705 maestro_power(card,ACPI_D0);
3706
3707 for(i=0;i<NR_DSPS;i++) {
3708 struct ess_state *s = &card->channels[i];
3709
3710 if(s->dev_audio == -1)
3711 continue;
3712
3713 M_printk("maestro: stopping apus for device %d\n",i);
3714 stop_dac(s);
3715 stop_adc(s);
3716 for(j=0;j<6;j++)
3717 card->apu_map[s->apu[j]][5]=apu_get_register(s,j,5);
3718
3719 }
3720
3721 /* get rid of interrupts? */
3722 if( card->dsps_open > 0)
3723 stop_bob(&card->channels[0]);
3724
3725 card->in_suspend++;
3726
3727 spin_unlock_irqrestore(&card->lock,flags);
3728
3729 /* we trust in the bios to power down the chip on suspend.
3730 * XXX I'm also not sure that in_suspend will protect
3731 * against all reg accesses from here on out.
3732 */
3733 return 0;
3734}
3735static int
3736maestro_resume(struct ess_card *card)
3737{
3738 unsigned long flags;
3739 int i;
3740
3741 spin_lock_irqsave(&card->lock,flags); /* over-kill */
3742
3743 card->in_suspend = 0;
3744
3745 M_printk("maestro: resuming card at %p\n",card);
3746
3747 /* restore all our config */
3748 maestro_config(card);
3749 /* need to restore the base pointers.. */
3750 if(card->dmapages)
3751 set_base_registers(&card->channels[0],card->dmapages);
3752
3753 mixer_push_state(card);
3754
3755 /* set each channels' apu control registers before
3756 * restoring audio
3757 */
3758 for(i=0;i<NR_DSPS;i++) {
3759 struct ess_state *s = &card->channels[i];
3760 int chan,reg;
3761
3762 if(s->dev_audio == -1)
3763 continue;
3764
3765 for(chan = 0 ; chan < 6 ; chan++) {
3766 wave_set_register(s,s->apu[chan]<<3,s->apu_base[chan]);
3767 for(reg = 1 ; reg < NR_APU_REGS ; reg++)
3768 apu_set_register(s,chan,reg,s->card->apu_map[s->apu[chan]][reg]);
3769 }
3770 for(chan = 0 ; chan < 6 ; chan++)
3771 apu_set_register(s,chan,0,s->card->apu_map[s->apu[chan]][0] & 0xFF0F);
3772 }
3773
3774 /* now we flip on the music */
3775
3776 if( card->dsps_open <= 0) {
3777 /* this card's idle */
3778 maestro_power(card,ACPI_D2);
3779 } else {
3780 /* ok, we're actually playing things on
3781 this card */
3782 maestro_power(card,ACPI_D0);
3783 start_bob(&card->channels[0]);
3784 for(i=0;i<NR_DSPS;i++) {
3785 struct ess_state *s = &card->channels[i];
3786
3787 /* these use the apu_mode, and can handle
3788 spurious calls */
3789 start_dac(s);
3790 start_adc(s);
3791 }
3792 }
3793
3794 spin_unlock_irqrestore(&card->lock,flags);
3795
3796 /* all right, we think things are ready,
3797 wake up people who were using the device
3798 when we suspended */
3799 wake_up(&(card->suspend_queue));
3800
3801 return 0;
3802}
3803
3804int
3805maestro_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
3806{
3807 struct ess_card *card = (struct ess_card*) dev->data;
3808
3809 if ( ! card ) goto out;
3810
3811 M_printk("maestro: pm event 0x%x received for card %p\n", rqst, card);
3812
3813 switch (rqst) {
3814 case PM_SUSPEND:
3815 maestro_suspend(card);
3816 break;
3817 case PM_RESUME:
3818 maestro_resume(card);
3819 break;
3820 /*
3821 * we'd also like to find out about
3822 * power level changes because some biosen
3823 * do mean things to the maestro when they
3824 * change their power state.
3825 */
3826 }
3827out:
3828 return 0;
3829}
3830
3831module_init(init_maestro);
3832module_exit(cleanup_maestro);
diff --git a/sound/oss/maestro.h b/sound/oss/maestro.h
new file mode 100644
index 000000000000..023ec7f968f9
--- /dev/null
+++ b/sound/oss/maestro.h
@@ -0,0 +1,60 @@
1/*
2 * Registers for the ESS PCI cards
3 */
4
5/*
6 * Memory access
7 */
8
9#define ESS_MEM_DATA 0x00
10#define ESS_MEM_INDEX 0x02
11
12/*
13 * AC-97 Codec port. Delay 1uS after each write. This is used to
14 * talk AC-97 (see intel.com). Write data then register.
15 */
16
17#define ESS_AC97_INDEX 0x30 /* byte wide */
18#define ESS_AC97_DATA 0x32
19
20/*
21 * Reading is a bit different. You write register|0x80 to ubdex
22 * delay 1uS poll the low bit of index, when it clears read the
23 * data value.
24 */
25
26/*
27 * Control port. Not yet fully understood
28 * The value 0xC090 gets loaded to it then 0x0000 and 0x2800
29 * to the data port. Then after 4uS the value 0x300 is written
30 */
31
32#define RING_BUS_CTRL_L 0x34
33#define RING_BUS_CTRL_H 0x36
34
35/*
36 * This is also used during setup. The value 0x17 is written to it
37 */
38
39#define ESS_SETUP_18 0x18
40
41/*
42 * And this one gets 0x000b
43 */
44
45#define ESS_SETUP_A2 0xA2
46
47/*
48 * And this 0x0000
49 */
50
51#define ESS_SETUP_A4 0xA4
52#define ESS_SETUP_A6 0xA6
53
54/*
55 * Stuff to do with Harpo - the wave stuff
56 */
57
58#define ESS_WAVETABLE_SIZE 0x14
59#define ESS_WAVETABLE_2M 0xA180
60
diff --git a/sound/oss/maestro3.c b/sound/oss/maestro3.c
new file mode 100644
index 000000000000..f3dec70fcb9b
--- /dev/null
+++ b/sound/oss/maestro3.c
@@ -0,0 +1,2973 @@
1/*****************************************************************************
2 *
3 * ESS Maestro3/Allegro driver for Linux 2.4.x
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * (c) Copyright 2000 Zach Brown <zab@zabbo.net>
20 *
21 * I need to thank many people for helping make this driver happen.
22 * As always, Eric Brombaugh was a hacking machine and killed many bugs
23 * that I was too dumb to notice. Howard Kim at ESS provided reference boards
24 * and as much docs as he could. Todd and Mick at Dell tested snapshots on
25 * an army of laptops. msw and deviant at Red Hat also humoured me by hanging
26 * their laptops every few hours in the name of science.
27 *
28 * Shouts go out to Mike "DJ XPCom" Ang.
29 *
30 * History
31 * v1.23 - Jun 5 2002 - Michael Olson <olson@cs.odu.edu>
32 * added a module option to allow selection of GPIO pin number
33 * for external amp
34 * v1.22 - Feb 28 2001 - Zach Brown <zab@zabbo.net>
35 * allocate mem at insmod/setup, rather than open
36 * limit pci dma addresses to 28bit, thanks guys.
37 * v1.21 - Feb 04 2001 - Zach Brown <zab@zabbo.net>
38 * fix up really dumb notifier -> suspend oops
39 * v1.20 - Jan 30 2001 - Zach Brown <zab@zabbo.net>
40 * get rid of pm callback and use pci_dev suspend/resume instead
41 * m3_probe cleanups, including pm oops think-o
42 * v1.10 - Jan 6 2001 - Zach Brown <zab@zabbo.net>
43 * revert to lame remap_page_range mmap() just to make it work
44 * record mmap fixed.
45 * fix up incredibly broken open/release resource management
46 * duh. fix record format setting.
47 * add SMP locking and cleanup formatting here and there
48 * v1.00 - Dec 16 2000 - Zach Brown <zab@zabbo.net>
49 * port to sexy 2.4 interfaces
50 * properly align instance allocations so recording works
51 * clean up function namespace a little :/
52 * update PCI IDs based on mail from ESS
53 * arbitrarily bump version number to show its 2.4 now,
54 * 2.2 will stay 0., oss_audio port gets 2.
55 * v0.03 - Nov 05 2000 - Zach Brown <zab@zabbo.net>
56 * disable recording but allow dsp to be opened read
57 * pull out most silly compat defines
58 * v0.02 - Nov 04 2000 - Zach Brown <zab@zabbo.net>
59 * changed clocking setup for m3, slowdown fixed.
60 * codec reset is hopefully reliable now
61 * rudimentary apm/power management makes suspend/resume work
62 * v0.01 - Oct 31 2000 - Zach Brown <zab@zabbo.net>
63 * first release
64 * v0.00 - Sep 09 2000 - Zach Brown <zab@zabbo.net>
65 * first pass derivation from maestro.c
66 *
67 * TODO
68 * in/out allocated contiguously so fullduplex mmap will work?
69 * no beep on init (mute)
70 * resetup msrc data memory if freq changes?
71 *
72 * --
73 *
74 * Allow me to ramble a bit about the m3 architecture. The core of the
75 * chip is the 'assp', the custom ESS dsp that runs the show. It has
76 * a small amount of code and data ram. ESS drops binary dsp code images
77 * on our heads, but we don't get to see specs on the dsp.
78 *
79 * The constant piece of code on the dsp is the 'kernel'. It also has a
80 * chunk of the dsp memory that is statically set aside for its control
81 * info. This is the KDATA defines in maestro3.h. Part of its core
82 * data is a list of code addresses that point to the pieces of DSP code
83 * that it should walk through in its loop. These other pieces of code
84 * do the real work. The kernel presumably jumps into each of them in turn.
85 * These code images tend to have their own data area, and one can have
86 * multiple data areas representing different states for each of the 'client
87 * instance' code portions. There is generally a list in the kernel data
88 * that points to the data instances for a given piece of code.
89 *
90 * We've only been given the binary image for the 'minisrc', mini sample
91 * rate converter. This is rather annoying because it limits the work
92 * we can do on the dsp, but it also greatly simplifies the job of managing
93 * dsp data memory for the code and data for our playing streams :). We
94 * statically allocate the minisrc code into a region we 'know' to be free
95 * based on the map of the binary kernel image we're loading. We also
96 * statically allocate the data areas for the maximum number of pcm streams
97 * we can be dealing with. This max is set by the length of the static list
98 * in the kernel data that records the number of minisrc data regions we
99 * can have. Thats right, all software dsp mixing with static code list
100 * limits. Rock.
101 *
102 * How sound goes in and out is still a relative mystery. It appears
103 * that the dsp has the ability to get input and output through various
104 * 'connections'. To do IO from or to a connection, you put the address
105 * of the minisrc client area in the static kernel data lists for that
106 * input or output. so for pcm -> dsp -> mixer, we put the minisrc data
107 * instance in the DMA list and also in the list for the mixer. I guess
108 * it Just Knows which is in/out, and we give some dma control info that
109 * helps. There are all sorts of cool inputs/outputs that it seems we can't
110 * use without dsp code images that know how to use them.
111 *
112 * So at init time we preload all the memory allocation stuff and set some
113 * system wide parameters. When we really get a sound to play we build
114 * up its minisrc header (stream parameters, buffer addresses, input/output
115 * settings). Then we throw its header on the various lists. We also
116 * tickle some KDATA settings that ask the assp to raise clock interrupts
117 * and do some amount of software mixing before handing data to the ac97.
118 *
119 * Sorry for the vague details. Feel free to ask Eric or myself if you
120 * happen to be trying to use this driver elsewhere. Please accept my
121 * apologies for the quality of the OSS support code, its passed through
122 * too many hands now and desperately wants to be rethought.
123 */
124
125/*****************************************************************************/
126
127#include <linux/config.h>
128#include <linux/module.h>
129#include <linux/kernel.h>
130#include <linux/string.h>
131#include <linux/ctype.h>
132#include <linux/ioport.h>
133#include <linux/sched.h>
134#include <linux/delay.h>
135#include <linux/sound.h>
136#include <linux/slab.h>
137#include <linux/soundcard.h>
138#include <linux/pci.h>
139#include <linux/vmalloc.h>
140#include <linux/init.h>
141#include <linux/interrupt.h>
142#include <linux/poll.h>
143#include <linux/reboot.h>
144#include <linux/spinlock.h>
145#include <linux/ac97_codec.h>
146#include <linux/wait.h>
147
148#include <asm/io.h>
149#include <asm/dma.h>
150#include <asm/uaccess.h>
151
152#include "maestro3.h"
153
154#define M_DEBUG 1
155
156#define DRIVER_VERSION "1.23"
157#define M3_MODULE_NAME "maestro3"
158#define PFX M3_MODULE_NAME ": "
159
160#define M3_STATE_MAGIC 0x734d724d
161#define M3_CARD_MAGIC 0x646e6f50
162
163#define ESS_FMT_STEREO 0x01
164#define ESS_FMT_16BIT 0x02
165#define ESS_FMT_MASK 0x03
166#define ESS_DAC_SHIFT 0
167#define ESS_ADC_SHIFT 4
168
169#define DAC_RUNNING 1
170#define ADC_RUNNING 2
171
172#define SND_DEV_DSP16 5
173
174#ifdef M_DEBUG
175static int debug;
176#define DPMOD 1 /* per module load */
177#define DPSTR 2 /* per 'stream' */
178#define DPSYS 3 /* per syscall */
179#define DPCRAP 4 /* stuff the user shouldn't see unless they're really debuggin */
180#define DPINT 5 /* per interrupt, LOTS */
181#define DPRINTK(DP, args...) {if (debug >= (DP)) printk(KERN_DEBUG PFX args);}
182#else
183#define DPRINTK(x)
184#endif
185
186struct m3_list {
187 int curlen;
188 u16 mem_addr;
189 int max;
190};
191
192static int external_amp = 1;
193static int gpio_pin = -1;
194
195struct m3_state {
196 unsigned int magic;
197 struct m3_card *card;
198 unsigned char fmt, enable;
199
200 int index;
201
202 /* this locks around the oss state in the driver */
203 /* no, this lock is removed - only use card->lock */
204 /* otherwise: against what are you protecting on SMP
205 when irqhandler uses s->lock
206 and m3_assp_read uses card->lock ?
207 */
208 struct semaphore open_sem;
209 wait_queue_head_t open_wait;
210 mode_t open_mode;
211
212 int dev_audio;
213
214 struct assp_instance {
215 u16 code, data;
216 } dac_inst, adc_inst;
217
218 /* should be in dmabuf */
219 unsigned int rateadc, ratedac;
220
221 struct dmabuf {
222 void *rawbuf;
223 unsigned buforder;
224 unsigned numfrag;
225 unsigned fragshift;
226 unsigned hwptr, swptr;
227 unsigned total_bytes;
228 int count;
229 unsigned error; /* over/underrun */
230 wait_queue_head_t wait;
231 /* redundant, but makes calculations easier */
232 unsigned fragsize;
233 unsigned dmasize;
234 unsigned fragsamples;
235 /* OSS stuff */
236 unsigned mapped:1;
237 unsigned ready:1;
238 unsigned endcleared:1;
239 unsigned ossfragshift;
240 int ossmaxfrags;
241 unsigned subdivision;
242 /* new in m3 */
243 int mixer_index, dma_index, msrc_index, adc1_index;
244 int in_lists;
245 /* 2.4.. */
246 dma_addr_t handle;
247
248 } dma_dac, dma_adc;
249};
250
251struct m3_card {
252 unsigned int magic;
253
254 struct m3_card *next;
255
256 struct ac97_codec *ac97;
257 spinlock_t ac97_lock;
258
259 int card_type;
260
261#define NR_DSPS 1
262#define MAX_DSPS NR_DSPS
263 struct m3_state channels[MAX_DSPS];
264
265 /* this locks around the physical registers on the card */
266 spinlock_t lock;
267
268 /* hardware resources */
269 struct pci_dev *pcidev;
270 u32 iobase;
271 u32 irq;
272
273 int dacs_active;
274
275 int timer_users;
276
277 struct m3_list msrc_list,
278 mixer_list,
279 adc1_list,
280 dma_list;
281
282 /* for storing reset state..*/
283 u8 reset_state;
284
285 u16 *suspend_mem;
286 int in_suspend;
287 wait_queue_head_t suspend_queue;
288};
289
290/*
291 * an arbitrary volume we set the internal
292 * volume settings to so that the ac97 volume
293 * range is a little less insane. 0x7fff is
294 * max.
295 */
296#define ARB_VOLUME ( 0x6800 )
297
298static const unsigned sample_shift[] = { 0, 1, 1, 2 };
299
300enum {
301 ESS_ALLEGRO,
302 ESS_MAESTRO3,
303 /*
304 * a maestro3 with 'hardware strapping', only
305 * found inside ESS?
306 */
307 ESS_MAESTRO3HW,
308};
309
310static char *card_names[] = {
311 [ESS_ALLEGRO] = "Allegro",
312 [ESS_MAESTRO3] = "Maestro3(i)",
313 [ESS_MAESTRO3HW] = "Maestro3(i)hw"
314};
315
316#ifndef PCI_VENDOR_ESS
317#define PCI_VENDOR_ESS 0x125D
318#endif
319
320#define M3_DEVICE(DEV, TYPE) \
321{ \
322.vendor = PCI_VENDOR_ESS, \
323.device = DEV, \
324.subvendor = PCI_ANY_ID, \
325.subdevice = PCI_ANY_ID, \
326.class = PCI_CLASS_MULTIMEDIA_AUDIO << 8, \
327.class_mask = 0xffff << 8, \
328.driver_data = TYPE, \
329}
330
331static struct pci_device_id m3_id_table[] = {
332 M3_DEVICE(0x1988, ESS_ALLEGRO),
333 M3_DEVICE(0x1998, ESS_MAESTRO3),
334 M3_DEVICE(0x199a, ESS_MAESTRO3HW),
335 {0,}
336};
337
338MODULE_DEVICE_TABLE (pci, m3_id_table);
339
340/*
341 * reports seem to indicate that the m3 is limited
342 * to 28bit bus addresses. aaaargggh...
343 */
344#define M3_PCI_DMA_MASK 0x0fffffff
345
346static unsigned
347ld2(unsigned int x)
348{
349 unsigned r = 0;
350
351 if (x >= 0x10000) {
352 x >>= 16;
353 r += 16;
354 }
355 if (x >= 0x100) {
356 x >>= 8;
357 r += 8;
358 }
359 if (x >= 0x10) {
360 x >>= 4;
361 r += 4;
362 }
363 if (x >= 4) {
364 x >>= 2;
365 r += 2;
366 }
367 if (x >= 2)
368 r++;
369 return r;
370}
371
372static struct m3_card *devs;
373
374/*
375 * I'm not very good at laying out functions in a file :)
376 */
377static int m3_notifier(struct notifier_block *nb, unsigned long event, void *buf);
378static int m3_suspend(struct pci_dev *pci_dev, pm_message_t state);
379static void check_suspend(struct m3_card *card);
380
381static struct notifier_block m3_reboot_nb = {
382 .notifier_call = m3_notifier,
383};
384
385static void m3_outw(struct m3_card *card,
386 u16 value, unsigned long reg)
387{
388 check_suspend(card);
389 outw(value, card->iobase + reg);
390}
391
392static u16 m3_inw(struct m3_card *card, unsigned long reg)
393{
394 check_suspend(card);
395 return inw(card->iobase + reg);
396}
397static void m3_outb(struct m3_card *card,
398 u8 value, unsigned long reg)
399{
400 check_suspend(card);
401 outb(value, card->iobase + reg);
402}
403static u8 m3_inb(struct m3_card *card, unsigned long reg)
404{
405 check_suspend(card);
406 return inb(card->iobase + reg);
407}
408
409/*
410 * access 16bit words to the code or data regions of the dsp's memory.
411 * index addresses 16bit words.
412 */
413static u16 __m3_assp_read(struct m3_card *card, u16 region, u16 index)
414{
415 m3_outw(card, region & MEMTYPE_MASK, DSP_PORT_MEMORY_TYPE);
416 m3_outw(card, index, DSP_PORT_MEMORY_INDEX);
417 return m3_inw(card, DSP_PORT_MEMORY_DATA);
418}
419static u16 m3_assp_read(struct m3_card *card, u16 region, u16 index)
420{
421 unsigned long flags;
422 u16 ret;
423
424 spin_lock_irqsave(&(card->lock), flags);
425 ret = __m3_assp_read(card, region, index);
426 spin_unlock_irqrestore(&(card->lock), flags);
427
428 return ret;
429}
430
431static void __m3_assp_write(struct m3_card *card,
432 u16 region, u16 index, u16 data)
433{
434 m3_outw(card, region & MEMTYPE_MASK, DSP_PORT_MEMORY_TYPE);
435 m3_outw(card, index, DSP_PORT_MEMORY_INDEX);
436 m3_outw(card, data, DSP_PORT_MEMORY_DATA);
437}
438static void m3_assp_write(struct m3_card *card,
439 u16 region, u16 index, u16 data)
440{
441 unsigned long flags;
442
443 spin_lock_irqsave(&(card->lock), flags);
444 __m3_assp_write(card, region, index, data);
445 spin_unlock_irqrestore(&(card->lock), flags);
446}
447
448static void m3_assp_halt(struct m3_card *card)
449{
450 card->reset_state = m3_inb(card, DSP_PORT_CONTROL_REG_B) & ~REGB_STOP_CLOCK;
451 mdelay(10);
452 m3_outb(card, card->reset_state & ~REGB_ENABLE_RESET, DSP_PORT_CONTROL_REG_B);
453}
454
455static void m3_assp_continue(struct m3_card *card)
456{
457 m3_outb(card, card->reset_state | REGB_ENABLE_RESET, DSP_PORT_CONTROL_REG_B);
458}
459
460/*
461 * This makes me sad. the maestro3 has lists
462 * internally that must be packed.. 0 terminates,
463 * apparently, or maybe all unused entries have
464 * to be 0, the lists have static lengths set
465 * by the binary code images.
466 */
467
468static int m3_add_list(struct m3_card *card,
469 struct m3_list *list, u16 val)
470{
471 DPRINTK(DPSTR, "adding val 0x%x to list 0x%p at pos %d\n",
472 val, list, list->curlen);
473
474 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
475 list->mem_addr + list->curlen,
476 val);
477
478 return list->curlen++;
479
480}
481
482static void m3_remove_list(struct m3_card *card,
483 struct m3_list *list, int index)
484{
485 u16 val;
486 int lastindex = list->curlen - 1;
487
488 DPRINTK(DPSTR, "removing ind %d from list 0x%p\n",
489 index, list);
490
491 if(index != lastindex) {
492 val = m3_assp_read(card, MEMTYPE_INTERNAL_DATA,
493 list->mem_addr + lastindex);
494 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
495 list->mem_addr + index,
496 val);
497 }
498
499 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
500 list->mem_addr + lastindex,
501 0);
502
503 list->curlen--;
504}
505
506static void set_fmt(struct m3_state *s, unsigned char mask, unsigned char data)
507{
508 int tmp;
509
510 s->fmt = (s->fmt & mask) | data;
511
512 tmp = (s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_MASK;
513
514 /* write to 'mono' word */
515 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
516 s->dac_inst.data + SRC3_DIRECTION_OFFSET + 1,
517 (tmp & ESS_FMT_STEREO) ? 0 : 1);
518 /* write to '8bit' word */
519 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
520 s->dac_inst.data + SRC3_DIRECTION_OFFSET + 2,
521 (tmp & ESS_FMT_16BIT) ? 0 : 1);
522
523 tmp = (s->fmt >> ESS_ADC_SHIFT) & ESS_FMT_MASK;
524
525 /* write to 'mono' word */
526 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
527 s->adc_inst.data + SRC3_DIRECTION_OFFSET + 1,
528 (tmp & ESS_FMT_STEREO) ? 0 : 1);
529 /* write to '8bit' word */
530 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
531 s->adc_inst.data + SRC3_DIRECTION_OFFSET + 2,
532 (tmp & ESS_FMT_16BIT) ? 0 : 1);
533}
534
535static void set_dac_rate(struct m3_state *s, unsigned int rate)
536{
537 u32 freq;
538
539 if (rate > 48000)
540 rate = 48000;
541 if (rate < 8000)
542 rate = 8000;
543
544 s->ratedac = rate;
545
546 freq = ((rate << 15) + 24000 ) / 48000;
547 if(freq)
548 freq--;
549
550 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
551 s->dac_inst.data + CDATA_FREQUENCY,
552 freq);
553}
554
555static void set_adc_rate(struct m3_state *s, unsigned int rate)
556{
557 u32 freq;
558
559 if (rate > 48000)
560 rate = 48000;
561 if (rate < 8000)
562 rate = 8000;
563
564 s->rateadc = rate;
565
566 freq = ((rate << 15) + 24000 ) / 48000;
567 if(freq)
568 freq--;
569
570 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
571 s->adc_inst.data + CDATA_FREQUENCY,
572 freq);
573}
574
575static void inc_timer_users(struct m3_card *card)
576{
577 unsigned long flags;
578
579 spin_lock_irqsave(&card->lock, flags);
580
581 card->timer_users++;
582 DPRINTK(DPSYS, "inc timer users now %d\n",
583 card->timer_users);
584 if(card->timer_users != 1)
585 goto out;
586
587 __m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
588 KDATA_TIMER_COUNT_RELOAD,
589 240 ) ;
590
591 __m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
592 KDATA_TIMER_COUNT_CURRENT,
593 240 ) ;
594
595 m3_outw(card,
596 m3_inw(card, HOST_INT_CTRL) | CLKRUN_GEN_ENABLE,
597 HOST_INT_CTRL);
598out:
599 spin_unlock_irqrestore(&card->lock, flags);
600}
601
602static void dec_timer_users(struct m3_card *card)
603{
604 unsigned long flags;
605
606 spin_lock_irqsave(&card->lock, flags);
607
608 card->timer_users--;
609 DPRINTK(DPSYS, "dec timer users now %d\n",
610 card->timer_users);
611 if(card->timer_users > 0 )
612 goto out;
613
614 __m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
615 KDATA_TIMER_COUNT_RELOAD,
616 0 ) ;
617
618 __m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
619 KDATA_TIMER_COUNT_CURRENT,
620 0 ) ;
621
622 m3_outw(card, m3_inw(card, HOST_INT_CTRL) & ~CLKRUN_GEN_ENABLE,
623 HOST_INT_CTRL);
624out:
625 spin_unlock_irqrestore(&card->lock, flags);
626}
627
628/*
629 * {start,stop}_{adc,dac} should be called
630 * while holding the 'state' lock and they
631 * will try to grab the 'card' lock..
632 */
633static void stop_adc(struct m3_state *s)
634{
635 if (! (s->enable & ADC_RUNNING))
636 return;
637
638 s->enable &= ~ADC_RUNNING;
639 dec_timer_users(s->card);
640
641 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
642 s->adc_inst.data + CDATA_INSTANCE_READY, 0);
643
644 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
645 KDATA_ADC1_REQUEST, 0);
646}
647
648static void stop_dac(struct m3_state *s)
649{
650 if (! (s->enable & DAC_RUNNING))
651 return;
652
653 DPRINTK(DPSYS, "stop_dac()\n");
654
655 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
656 s->dac_inst.data + CDATA_INSTANCE_READY, 0);
657
658 s->enable &= ~DAC_RUNNING;
659 s->card->dacs_active--;
660 dec_timer_users(s->card);
661
662 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
663 KDATA_MIXER_TASK_NUMBER,
664 s->card->dacs_active ) ;
665}
666
667static void start_dac(struct m3_state *s)
668{
669 if( (!s->dma_dac.mapped && s->dma_dac.count < 1) ||
670 !s->dma_dac.ready ||
671 (s->enable & DAC_RUNNING))
672 return;
673
674 DPRINTK(DPSYS, "start_dac()\n");
675
676 s->enable |= DAC_RUNNING;
677 s->card->dacs_active++;
678 inc_timer_users(s->card);
679
680 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
681 s->dac_inst.data + CDATA_INSTANCE_READY, 1);
682
683 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
684 KDATA_MIXER_TASK_NUMBER,
685 s->card->dacs_active ) ;
686}
687
688static void start_adc(struct m3_state *s)
689{
690 if ((! s->dma_adc.mapped &&
691 s->dma_adc.count >= (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
692 || !s->dma_adc.ready
693 || (s->enable & ADC_RUNNING) )
694 return;
695
696 DPRINTK(DPSYS, "start_adc()\n");
697
698 s->enable |= ADC_RUNNING;
699 inc_timer_users(s->card);
700
701 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
702 KDATA_ADC1_REQUEST, 1);
703
704 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
705 s->adc_inst.data + CDATA_INSTANCE_READY, 1);
706}
707
708static struct play_vals {
709 u16 addr, val;
710} pv[] = {
711 {CDATA_LEFT_VOLUME, ARB_VOLUME},
712 {CDATA_RIGHT_VOLUME, ARB_VOLUME},
713 {SRC3_DIRECTION_OFFSET, 0} ,
714 /* +1, +2 are stereo/16 bit */
715 {SRC3_DIRECTION_OFFSET + 3, 0x0000}, /* fraction? */
716 {SRC3_DIRECTION_OFFSET + 4, 0}, /* first l */
717 {SRC3_DIRECTION_OFFSET + 5, 0}, /* first r */
718 {SRC3_DIRECTION_OFFSET + 6, 0}, /* second l */
719 {SRC3_DIRECTION_OFFSET + 7, 0}, /* second r */
720 {SRC3_DIRECTION_OFFSET + 8, 0}, /* delta l */
721 {SRC3_DIRECTION_OFFSET + 9, 0}, /* delta r */
722 {SRC3_DIRECTION_OFFSET + 10, 0x8000}, /* round */
723 {SRC3_DIRECTION_OFFSET + 11, 0xFF00}, /* higher bute mark */
724 {SRC3_DIRECTION_OFFSET + 13, 0}, /* temp0 */
725 {SRC3_DIRECTION_OFFSET + 14, 0}, /* c fraction */
726 {SRC3_DIRECTION_OFFSET + 15, 0}, /* counter */
727 {SRC3_DIRECTION_OFFSET + 16, 8}, /* numin */
728 {SRC3_DIRECTION_OFFSET + 17, 50*2}, /* numout */
729 {SRC3_DIRECTION_OFFSET + 18, MINISRC_BIQUAD_STAGE - 1}, /* numstage */
730 {SRC3_DIRECTION_OFFSET + 20, 0}, /* filtertap */
731 {SRC3_DIRECTION_OFFSET + 21, 0} /* booster */
732};
733
734
735/* the mode passed should be already shifted and masked */
736static void m3_play_setup(struct m3_state *s, int mode, u32 rate, void *buffer, int size)
737{
738 int dsp_in_size = MINISRC_IN_BUFFER_SIZE - (0x20 * 2);
739 int dsp_out_size = MINISRC_OUT_BUFFER_SIZE - (0x20 * 2);
740 int dsp_in_buffer = s->dac_inst.data + (MINISRC_TMP_BUFFER_SIZE / 2);
741 int dsp_out_buffer = dsp_in_buffer + (dsp_in_size / 2) + 1;
742 struct dmabuf *db = &s->dma_dac;
743 int i;
744
745 DPRINTK(DPSTR, "mode=%d rate=%d buf=%p len=%d.\n",
746 mode, rate, buffer, size);
747
748#define LO(x) ((x) & 0xffff)
749#define HI(x) LO((x) >> 16)
750
751 /* host dma buffer pointers */
752
753 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
754 s->dac_inst.data + CDATA_HOST_SRC_ADDRL,
755 LO(virt_to_bus(buffer)));
756
757 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
758 s->dac_inst.data + CDATA_HOST_SRC_ADDRH,
759 HI(virt_to_bus(buffer)));
760
761 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
762 s->dac_inst.data + CDATA_HOST_SRC_END_PLUS_1L,
763 LO(virt_to_bus(buffer) + size));
764
765 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
766 s->dac_inst.data + CDATA_HOST_SRC_END_PLUS_1H,
767 HI(virt_to_bus(buffer) + size));
768
769 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
770 s->dac_inst.data + CDATA_HOST_SRC_CURRENTL,
771 LO(virt_to_bus(buffer)));
772
773 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
774 s->dac_inst.data + CDATA_HOST_SRC_CURRENTH,
775 HI(virt_to_bus(buffer)));
776#undef LO
777#undef HI
778
779 /* dsp buffers */
780
781 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
782 s->dac_inst.data + CDATA_IN_BUF_BEGIN,
783 dsp_in_buffer);
784
785 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
786 s->dac_inst.data + CDATA_IN_BUF_END_PLUS_1,
787 dsp_in_buffer + (dsp_in_size / 2));
788
789 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
790 s->dac_inst.data + CDATA_IN_BUF_HEAD,
791 dsp_in_buffer);
792
793 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
794 s->dac_inst.data + CDATA_IN_BUF_TAIL,
795 dsp_in_buffer);
796
797 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
798 s->dac_inst.data + CDATA_OUT_BUF_BEGIN,
799 dsp_out_buffer);
800
801 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
802 s->dac_inst.data + CDATA_OUT_BUF_END_PLUS_1,
803 dsp_out_buffer + (dsp_out_size / 2));
804
805 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
806 s->dac_inst.data + CDATA_OUT_BUF_HEAD,
807 dsp_out_buffer);
808
809 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
810 s->dac_inst.data + CDATA_OUT_BUF_TAIL,
811 dsp_out_buffer);
812
813 /*
814 * some per client initializers
815 */
816
817 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
818 s->dac_inst.data + SRC3_DIRECTION_OFFSET + 12,
819 s->dac_inst.data + 40 + 8);
820
821 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
822 s->dac_inst.data + SRC3_DIRECTION_OFFSET + 19,
823 s->dac_inst.code + MINISRC_COEF_LOC);
824
825 /* enable or disable low pass filter? */
826 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
827 s->dac_inst.data + SRC3_DIRECTION_OFFSET + 22,
828 s->ratedac > 45000 ? 0xff : 0 );
829
830 /* tell it which way dma is going? */
831 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
832 s->dac_inst.data + CDATA_DMA_CONTROL,
833 DMACONTROL_AUTOREPEAT + DMAC_PAGE3_SELECTOR + DMAC_BLOCKF_SELECTOR);
834
835 /*
836 * set an armload of static initializers
837 */
838 for(i = 0 ; i < (sizeof(pv) / sizeof(pv[0])) ; i++)
839 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
840 s->dac_inst.data + pv[i].addr, pv[i].val);
841
842 /*
843 * put us in the lists if we're not already there
844 */
845
846 if(db->in_lists == 0) {
847
848 db->msrc_index = m3_add_list(s->card, &s->card->msrc_list,
849 s->dac_inst.data >> DP_SHIFT_COUNT);
850
851 db->dma_index = m3_add_list(s->card, &s->card->dma_list,
852 s->dac_inst.data >> DP_SHIFT_COUNT);
853
854 db->mixer_index = m3_add_list(s->card, &s->card->mixer_list,
855 s->dac_inst.data >> DP_SHIFT_COUNT);
856
857 db->in_lists = 1;
858 }
859
860 set_dac_rate(s,rate);
861 start_dac(s);
862}
863
864/*
865 * Native record driver
866 */
867static struct rec_vals {
868 u16 addr, val;
869} rv[] = {
870 {CDATA_LEFT_VOLUME, ARB_VOLUME},
871 {CDATA_RIGHT_VOLUME, ARB_VOLUME},
872 {SRC3_DIRECTION_OFFSET, 1} ,
873 /* +1, +2 are stereo/16 bit */
874 {SRC3_DIRECTION_OFFSET + 3, 0x0000}, /* fraction? */
875 {SRC3_DIRECTION_OFFSET + 4, 0}, /* first l */
876 {SRC3_DIRECTION_OFFSET + 5, 0}, /* first r */
877 {SRC3_DIRECTION_OFFSET + 6, 0}, /* second l */
878 {SRC3_DIRECTION_OFFSET + 7, 0}, /* second r */
879 {SRC3_DIRECTION_OFFSET + 8, 0}, /* delta l */
880 {SRC3_DIRECTION_OFFSET + 9, 0}, /* delta r */
881 {SRC3_DIRECTION_OFFSET + 10, 0x8000}, /* round */
882 {SRC3_DIRECTION_OFFSET + 11, 0xFF00}, /* higher bute mark */
883 {SRC3_DIRECTION_OFFSET + 13, 0}, /* temp0 */
884 {SRC3_DIRECTION_OFFSET + 14, 0}, /* c fraction */
885 {SRC3_DIRECTION_OFFSET + 15, 0}, /* counter */
886 {SRC3_DIRECTION_OFFSET + 16, 50},/* numin */
887 {SRC3_DIRECTION_OFFSET + 17, 8}, /* numout */
888 {SRC3_DIRECTION_OFFSET + 18, 0}, /* numstage */
889 {SRC3_DIRECTION_OFFSET + 19, 0}, /* coef */
890 {SRC3_DIRECTION_OFFSET + 20, 0}, /* filtertap */
891 {SRC3_DIRECTION_OFFSET + 21, 0}, /* booster */
892 {SRC3_DIRECTION_OFFSET + 22, 0xff} /* skip lpf */
893};
894
895/* again, passed mode is alrady shifted/masked */
896static void m3_rec_setup(struct m3_state *s, int mode, u32 rate, void *buffer, int size)
897{
898 int dsp_in_size = MINISRC_IN_BUFFER_SIZE + (0x10 * 2);
899 int dsp_out_size = MINISRC_OUT_BUFFER_SIZE - (0x10 * 2);
900 int dsp_in_buffer = s->adc_inst.data + (MINISRC_TMP_BUFFER_SIZE / 2);
901 int dsp_out_buffer = dsp_in_buffer + (dsp_in_size / 2) + 1;
902 struct dmabuf *db = &s->dma_adc;
903 int i;
904
905 DPRINTK(DPSTR, "rec_setup mode=%d rate=%d buf=%p len=%d.\n",
906 mode, rate, buffer, size);
907
908#define LO(x) ((x) & 0xffff)
909#define HI(x) LO((x) >> 16)
910
911 /* host dma buffer pointers */
912
913 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
914 s->adc_inst.data + CDATA_HOST_SRC_ADDRL,
915 LO(virt_to_bus(buffer)));
916
917 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
918 s->adc_inst.data + CDATA_HOST_SRC_ADDRH,
919 HI(virt_to_bus(buffer)));
920
921 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
922 s->adc_inst.data + CDATA_HOST_SRC_END_PLUS_1L,
923 LO(virt_to_bus(buffer) + size));
924
925 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
926 s->adc_inst.data + CDATA_HOST_SRC_END_PLUS_1H,
927 HI(virt_to_bus(buffer) + size));
928
929 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
930 s->adc_inst.data + CDATA_HOST_SRC_CURRENTL,
931 LO(virt_to_bus(buffer)));
932
933 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
934 s->adc_inst.data + CDATA_HOST_SRC_CURRENTH,
935 HI(virt_to_bus(buffer)));
936#undef LO
937#undef HI
938
939 /* dsp buffers */
940
941 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
942 s->adc_inst.data + CDATA_IN_BUF_BEGIN,
943 dsp_in_buffer);
944
945 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
946 s->adc_inst.data + CDATA_IN_BUF_END_PLUS_1,
947 dsp_in_buffer + (dsp_in_size / 2));
948
949 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
950 s->adc_inst.data + CDATA_IN_BUF_HEAD,
951 dsp_in_buffer);
952
953 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
954 s->adc_inst.data + CDATA_IN_BUF_TAIL,
955 dsp_in_buffer);
956
957 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
958 s->adc_inst.data + CDATA_OUT_BUF_BEGIN,
959 dsp_out_buffer);
960
961 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
962 s->adc_inst.data + CDATA_OUT_BUF_END_PLUS_1,
963 dsp_out_buffer + (dsp_out_size / 2));
964
965 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
966 s->adc_inst.data + CDATA_OUT_BUF_HEAD,
967 dsp_out_buffer);
968
969 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
970 s->adc_inst.data + CDATA_OUT_BUF_TAIL,
971 dsp_out_buffer);
972
973 /*
974 * some per client initializers
975 */
976
977 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
978 s->adc_inst.data + SRC3_DIRECTION_OFFSET + 12,
979 s->adc_inst.data + 40 + 8);
980
981 /* tell it which way dma is going? */
982 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
983 s->adc_inst.data + CDATA_DMA_CONTROL,
984 DMACONTROL_DIRECTION + DMACONTROL_AUTOREPEAT +
985 DMAC_PAGE3_SELECTOR + DMAC_BLOCKF_SELECTOR);
986
987 /*
988 * set an armload of static initializers
989 */
990 for(i = 0 ; i < (sizeof(rv) / sizeof(rv[0])) ; i++)
991 m3_assp_write(s->card, MEMTYPE_INTERNAL_DATA,
992 s->adc_inst.data + rv[i].addr, rv[i].val);
993
994 /*
995 * put us in the lists if we're not already there
996 */
997
998 if(db->in_lists == 0) {
999
1000 db->adc1_index = m3_add_list(s->card, &s->card->adc1_list,
1001 s->adc_inst.data >> DP_SHIFT_COUNT);
1002
1003 db->dma_index = m3_add_list(s->card, &s->card->dma_list,
1004 s->adc_inst.data >> DP_SHIFT_COUNT);
1005
1006 db->msrc_index = m3_add_list(s->card, &s->card->msrc_list,
1007 s->adc_inst.data >> DP_SHIFT_COUNT);
1008
1009 db->in_lists = 1;
1010 }
1011
1012 set_adc_rate(s,rate);
1013 start_adc(s);
1014}
1015/* --------------------------------------------------------------------- */
1016
1017static void set_dmaa(struct m3_state *s, unsigned int addr, unsigned int count)
1018{
1019 DPRINTK(DPINT,"set_dmaa??\n");
1020}
1021
1022static void set_dmac(struct m3_state *s, unsigned int addr, unsigned int count)
1023{
1024 DPRINTK(DPINT,"set_dmac??\n");
1025}
1026
1027static u32 get_dma_pos(struct m3_card *card,
1028 int instance_addr)
1029{
1030 u16 hi = 0, lo = 0;
1031 int retry = 10;
1032
1033 /*
1034 * try and get a valid answer
1035 */
1036 while(retry--) {
1037 hi = m3_assp_read(card, MEMTYPE_INTERNAL_DATA,
1038 instance_addr + CDATA_HOST_SRC_CURRENTH);
1039
1040 lo = m3_assp_read(card, MEMTYPE_INTERNAL_DATA,
1041 instance_addr + CDATA_HOST_SRC_CURRENTL);
1042
1043 if(hi == m3_assp_read(card, MEMTYPE_INTERNAL_DATA,
1044 instance_addr + CDATA_HOST_SRC_CURRENTH))
1045 break;
1046 }
1047 return lo | (hi<<16);
1048}
1049
1050static u32 get_dmaa(struct m3_state *s)
1051{
1052 u32 offset;
1053
1054 offset = get_dma_pos(s->card, s->dac_inst.data) -
1055 virt_to_bus(s->dma_dac.rawbuf);
1056
1057 DPRINTK(DPINT,"get_dmaa: 0x%08x\n",offset);
1058
1059 return offset;
1060}
1061
1062static u32 get_dmac(struct m3_state *s)
1063{
1064 u32 offset;
1065
1066 offset = get_dma_pos(s->card, s->adc_inst.data) -
1067 virt_to_bus(s->dma_adc.rawbuf);
1068
1069 DPRINTK(DPINT,"get_dmac: 0x%08x\n",offset);
1070
1071 return offset;
1072
1073}
1074
1075static int
1076prog_dmabuf(struct m3_state *s, unsigned rec)
1077{
1078 struct dmabuf *db = rec ? &s->dma_adc : &s->dma_dac;
1079 unsigned rate = rec ? s->rateadc : s->ratedac;
1080 unsigned bytepersec;
1081 unsigned bufs;
1082 unsigned char fmt;
1083 unsigned long flags;
1084
1085 spin_lock_irqsave(&s->card->lock, flags);
1086
1087 fmt = s->fmt;
1088 if (rec) {
1089 stop_adc(s);
1090 fmt >>= ESS_ADC_SHIFT;
1091 } else {
1092 stop_dac(s);
1093 fmt >>= ESS_DAC_SHIFT;
1094 }
1095 fmt &= ESS_FMT_MASK;
1096
1097 db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
1098
1099 bytepersec = rate << sample_shift[fmt];
1100 bufs = PAGE_SIZE << db->buforder;
1101 if (db->ossfragshift) {
1102 if ((1000 << db->ossfragshift) < bytepersec)
1103 db->fragshift = ld2(bytepersec/1000);
1104 else
1105 db->fragshift = db->ossfragshift;
1106 } else {
1107 db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
1108 if (db->fragshift < 3)
1109 db->fragshift = 3;
1110 }
1111 db->numfrag = bufs >> db->fragshift;
1112 while (db->numfrag < 4 && db->fragshift > 3) {
1113 db->fragshift--;
1114 db->numfrag = bufs >> db->fragshift;
1115 }
1116 db->fragsize = 1 << db->fragshift;
1117 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
1118 db->numfrag = db->ossmaxfrags;
1119 db->fragsamples = db->fragsize >> sample_shift[fmt];
1120 db->dmasize = db->numfrag << db->fragshift;
1121
1122 DPRINTK(DPSTR,"prog_dmabuf: numfrag: %d fragsize: %d dmasize: %d\n",db->numfrag,db->fragsize,db->dmasize);
1123
1124 memset(db->rawbuf, (fmt & ESS_FMT_16BIT) ? 0 : 0x80, db->dmasize);
1125
1126 if (rec)
1127 m3_rec_setup(s, fmt, s->rateadc, db->rawbuf, db->dmasize);
1128 else
1129 m3_play_setup(s, fmt, s->ratedac, db->rawbuf, db->dmasize);
1130
1131 db->ready = 1;
1132
1133 spin_unlock_irqrestore(&s->card->lock, flags);
1134
1135 return 0;
1136}
1137
1138static void clear_advance(struct m3_state *s)
1139{
1140 unsigned char c = ((s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_16BIT) ? 0 : 0x80;
1141
1142 unsigned char *buf = s->dma_dac.rawbuf;
1143 unsigned bsize = s->dma_dac.dmasize;
1144 unsigned bptr = s->dma_dac.swptr;
1145 unsigned len = s->dma_dac.fragsize;
1146
1147 if (bptr + len > bsize) {
1148 unsigned x = bsize - bptr;
1149 memset(buf + bptr, c, x);
1150 /* account for wrapping? */
1151 bptr = 0;
1152 len -= x;
1153 }
1154 memset(buf + bptr, c, len);
1155}
1156
1157/* call with spinlock held! */
1158static void m3_update_ptr(struct m3_state *s)
1159{
1160 unsigned hwptr;
1161 int diff;
1162
1163 /* update ADC pointer */
1164 if (s->dma_adc.ready) {
1165 hwptr = get_dmac(s) % s->dma_adc.dmasize;
1166 diff = (s->dma_adc.dmasize + hwptr - s->dma_adc.hwptr) % s->dma_adc.dmasize;
1167 s->dma_adc.hwptr = hwptr;
1168 s->dma_adc.total_bytes += diff;
1169 s->dma_adc.count += diff;
1170 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1171 wake_up(&s->dma_adc.wait);
1172 if (!s->dma_adc.mapped) {
1173 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
1174 stop_adc(s);
1175 /* brute force everyone back in sync, sigh */
1176 s->dma_adc.count = 0;
1177 s->dma_adc.swptr = 0;
1178 s->dma_adc.hwptr = 0;
1179 s->dma_adc.error++;
1180 }
1181 }
1182 }
1183 /* update DAC pointer */
1184 if (s->dma_dac.ready) {
1185 hwptr = get_dmaa(s) % s->dma_dac.dmasize;
1186 diff = (s->dma_dac.dmasize + hwptr - s->dma_dac.hwptr) % s->dma_dac.dmasize;
1187
1188 DPRINTK(DPINT,"updating dac: hwptr: %6d diff: %6d count: %6d\n",
1189 hwptr,diff,s->dma_dac.count);
1190
1191 s->dma_dac.hwptr = hwptr;
1192 s->dma_dac.total_bytes += diff;
1193
1194 if (s->dma_dac.mapped) {
1195
1196 s->dma_dac.count += diff;
1197 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize) {
1198 wake_up(&s->dma_dac.wait);
1199 }
1200 } else {
1201
1202 s->dma_dac.count -= diff;
1203
1204 if (s->dma_dac.count <= 0) {
1205 DPRINTK(DPCRAP,"underflow! diff: %d (0x%x) count: %d (0x%x) hw: %d (0x%x) sw: %d (0x%x)\n",
1206 diff, diff,
1207 s->dma_dac.count,
1208 s->dma_dac.count,
1209 hwptr, hwptr,
1210 s->dma_dac.swptr,
1211 s->dma_dac.swptr);
1212 stop_dac(s);
1213 /* brute force everyone back in sync, sigh */
1214 s->dma_dac.count = 0;
1215 s->dma_dac.swptr = hwptr;
1216 s->dma_dac.error++;
1217 } else if (s->dma_dac.count <= (signed)s->dma_dac.fragsize && !s->dma_dac.endcleared) {
1218 clear_advance(s);
1219 s->dma_dac.endcleared = 1;
1220 }
1221 if (s->dma_dac.count + (signed)s->dma_dac.fragsize <= (signed)s->dma_dac.dmasize) {
1222 wake_up(&s->dma_dac.wait);
1223 DPRINTK(DPINT,"waking up DAC count: %d sw: %d hw: %d\n",
1224 s->dma_dac.count, s->dma_dac.swptr, hwptr);
1225 }
1226 }
1227 }
1228}
1229
1230static irqreturn_t m3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1231{
1232 struct m3_card *c = (struct m3_card *)dev_id;
1233 struct m3_state *s = &c->channels[0];
1234 u8 status;
1235
1236 status = inb(c->iobase+0x1A);
1237
1238 if(status == 0xff)
1239 return IRQ_NONE;
1240
1241 /* presumably acking the ints? */
1242 outw(status, c->iobase+0x1A);
1243
1244 if(c->in_suspend)
1245 return IRQ_HANDLED;
1246
1247 /*
1248 * ack an assp int if its running
1249 * and has an int pending
1250 */
1251 if( status & ASSP_INT_PENDING) {
1252 u8 ctl = inb(c->iobase + ASSP_CONTROL_B);
1253 if( !(ctl & STOP_ASSP_CLOCK)) {
1254 ctl = inb(c->iobase + ASSP_HOST_INT_STATUS );
1255 if(ctl & DSP2HOST_REQ_TIMER) {
1256 outb( DSP2HOST_REQ_TIMER, c->iobase + ASSP_HOST_INT_STATUS);
1257 /* update adc/dac info if it was a timer int */
1258 spin_lock(&c->lock);
1259 m3_update_ptr(s);
1260 spin_unlock(&c->lock);
1261 }
1262 }
1263 }
1264
1265 /* XXX is this needed? */
1266 if(status & 0x40)
1267 outb(0x40, c->iobase+0x1A);
1268 return IRQ_HANDLED;
1269}
1270
1271
1272/* --------------------------------------------------------------------- */
1273
1274static const char invalid_magic[] = KERN_CRIT PFX "invalid magic value in %s\n";
1275
1276#define VALIDATE_MAGIC(FOO,MAG) \
1277({ \
1278 if (!(FOO) || (FOO)->magic != MAG) { \
1279 printk(invalid_magic,__FUNCTION__); \
1280 return -ENXIO; \
1281 } \
1282})
1283
1284#define VALIDATE_STATE(a) VALIDATE_MAGIC(a,M3_STATE_MAGIC)
1285#define VALIDATE_CARD(a) VALIDATE_MAGIC(a,M3_CARD_MAGIC)
1286
1287/* --------------------------------------------------------------------- */
1288
1289static int drain_dac(struct m3_state *s, int nonblock)
1290{
1291 DECLARE_WAITQUEUE(wait,current);
1292 unsigned long flags;
1293 int count;
1294 signed long tmo;
1295
1296 if (s->dma_dac.mapped || !s->dma_dac.ready)
1297 return 0;
1298 set_current_state(TASK_INTERRUPTIBLE);
1299 add_wait_queue(&s->dma_dac.wait, &wait);
1300 for (;;) {
1301 spin_lock_irqsave(&s->card->lock, flags);
1302 count = s->dma_dac.count;
1303 spin_unlock_irqrestore(&s->card->lock, flags);
1304 if (count <= 0)
1305 break;
1306 if (signal_pending(current))
1307 break;
1308 if (nonblock) {
1309 remove_wait_queue(&s->dma_dac.wait, &wait);
1310 set_current_state(TASK_RUNNING);
1311 return -EBUSY;
1312 }
1313 tmo = (count * HZ) / s->ratedac;
1314 tmo >>= sample_shift[(s->fmt >> ESS_DAC_SHIFT) & ESS_FMT_MASK];
1315 /* XXX this is just broken. someone is waking us up alot, or schedule_timeout is broken.
1316 or something. who cares. - zach */
1317 if (!schedule_timeout(tmo ? tmo : 1) && tmo)
1318 DPRINTK(DPCRAP,"dma timed out?? %ld\n",jiffies);
1319 }
1320 remove_wait_queue(&s->dma_dac.wait, &wait);
1321 set_current_state(TASK_RUNNING);
1322 if (signal_pending(current))
1323 return -ERESTARTSYS;
1324 return 0;
1325}
1326
1327static ssize_t m3_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1328{
1329 struct m3_state *s = (struct m3_state *)file->private_data;
1330 ssize_t ret;
1331 unsigned long flags;
1332 unsigned swptr;
1333 int cnt;
1334
1335 VALIDATE_STATE(s);
1336 if (s->dma_adc.mapped)
1337 return -ENXIO;
1338 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
1339 return ret;
1340 if (!access_ok(VERIFY_WRITE, buffer, count))
1341 return -EFAULT;
1342 ret = 0;
1343
1344 spin_lock_irqsave(&s->card->lock, flags);
1345
1346 while (count > 0) {
1347 int timed_out;
1348
1349 swptr = s->dma_adc.swptr;
1350 cnt = s->dma_adc.dmasize-swptr;
1351 if (s->dma_adc.count < cnt)
1352 cnt = s->dma_adc.count;
1353
1354 if (cnt > count)
1355 cnt = count;
1356
1357 if (cnt <= 0) {
1358 start_adc(s);
1359 if (file->f_flags & O_NONBLOCK)
1360 {
1361 ret = ret ? ret : -EAGAIN;
1362 goto out;
1363 }
1364
1365 spin_unlock_irqrestore(&s->card->lock, flags);
1366 timed_out = interruptible_sleep_on_timeout(&s->dma_adc.wait, HZ) == 0;
1367 spin_lock_irqsave(&s->card->lock, flags);
1368
1369 if(timed_out) {
1370 printk("read: chip lockup? dmasz %u fragsz %u count %u hwptr %u swptr %u\n",
1371 s->dma_adc.dmasize, s->dma_adc.fragsize, s->dma_adc.count,
1372 s->dma_adc.hwptr, s->dma_adc.swptr);
1373 stop_adc(s);
1374 set_dmac(s, virt_to_bus(s->dma_adc.rawbuf), s->dma_adc.numfrag << s->dma_adc.fragshift);
1375 s->dma_adc.count = s->dma_adc.hwptr = s->dma_adc.swptr = 0;
1376 }
1377 if (signal_pending(current))
1378 {
1379 ret = ret ? ret : -ERESTARTSYS;
1380 goto out;
1381 }
1382 continue;
1383 }
1384
1385 spin_unlock_irqrestore(&s->card->lock, flags);
1386 if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
1387 ret = ret ? ret : -EFAULT;
1388 return ret;
1389 }
1390 spin_lock_irqsave(&s->card->lock, flags);
1391
1392 swptr = (swptr + cnt) % s->dma_adc.dmasize;
1393 s->dma_adc.swptr = swptr;
1394 s->dma_adc.count -= cnt;
1395 count -= cnt;
1396 buffer += cnt;
1397 ret += cnt;
1398 start_adc(s);
1399 }
1400
1401out:
1402 spin_unlock_irqrestore(&s->card->lock, flags);
1403 return ret;
1404}
1405
1406static ssize_t m3_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1407{
1408 struct m3_state *s = (struct m3_state *)file->private_data;
1409 ssize_t ret;
1410 unsigned long flags;
1411 unsigned swptr;
1412 int cnt;
1413
1414 VALIDATE_STATE(s);
1415 if (s->dma_dac.mapped)
1416 return -ENXIO;
1417 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
1418 return ret;
1419 if (!access_ok(VERIFY_READ, buffer, count))
1420 return -EFAULT;
1421 ret = 0;
1422
1423 spin_lock_irqsave(&s->card->lock, flags);
1424
1425 while (count > 0) {
1426 int timed_out;
1427
1428 if (s->dma_dac.count < 0) {
1429 s->dma_dac.count = 0;
1430 s->dma_dac.swptr = s->dma_dac.hwptr;
1431 }
1432 swptr = s->dma_dac.swptr;
1433
1434 cnt = s->dma_dac.dmasize-swptr;
1435
1436 if (s->dma_dac.count + cnt > s->dma_dac.dmasize)
1437 cnt = s->dma_dac.dmasize - s->dma_dac.count;
1438
1439
1440 if (cnt > count)
1441 cnt = count;
1442
1443 if (cnt <= 0) {
1444 start_dac(s);
1445 if (file->f_flags & O_NONBLOCK) {
1446 if(!ret) ret = -EAGAIN;
1447 goto out;
1448 }
1449 spin_unlock_irqrestore(&s->card->lock, flags);
1450 timed_out = interruptible_sleep_on_timeout(&s->dma_dac.wait, HZ) == 0;
1451 spin_lock_irqsave(&s->card->lock, flags);
1452 if(timed_out) {
1453 DPRINTK(DPCRAP,"write: chip lockup? dmasz %u fragsz %u count %u hwptr %u swptr %u\n",
1454 s->dma_dac.dmasize, s->dma_dac.fragsize, s->dma_dac.count,
1455 s->dma_dac.hwptr, s->dma_dac.swptr);
1456 stop_dac(s);
1457 set_dmaa(s, virt_to_bus(s->dma_dac.rawbuf), s->dma_dac.numfrag << s->dma_dac.fragshift);
1458 s->dma_dac.count = s->dma_dac.hwptr = s->dma_dac.swptr = 0;
1459 }
1460 if (signal_pending(current)) {
1461 if (!ret) ret = -ERESTARTSYS;
1462 goto out;
1463 }
1464 continue;
1465 }
1466 spin_unlock_irqrestore(&s->card->lock, flags);
1467 if (copy_from_user(s->dma_dac.rawbuf + swptr, buffer, cnt)) {
1468 if (!ret) ret = -EFAULT;
1469 return ret;
1470 }
1471 spin_lock_irqsave(&s->card->lock, flags);
1472
1473 DPRINTK(DPSYS,"wrote %6d bytes at sw: %6d cnt: %6d while hw: %6d\n",
1474 cnt, swptr, s->dma_dac.count, s->dma_dac.hwptr);
1475
1476 swptr = (swptr + cnt) % s->dma_dac.dmasize;
1477
1478 s->dma_dac.swptr = swptr;
1479 s->dma_dac.count += cnt;
1480 s->dma_dac.endcleared = 0;
1481 count -= cnt;
1482 buffer += cnt;
1483 ret += cnt;
1484 start_dac(s);
1485 }
1486out:
1487 spin_unlock_irqrestore(&s->card->lock, flags);
1488 return ret;
1489}
1490
1491static unsigned int m3_poll(struct file *file, struct poll_table_struct *wait)
1492{
1493 struct m3_state *s = (struct m3_state *)file->private_data;
1494 unsigned long flags;
1495 unsigned int mask = 0;
1496
1497 VALIDATE_STATE(s);
1498 if (file->f_mode & FMODE_WRITE)
1499 poll_wait(file, &s->dma_dac.wait, wait);
1500 if (file->f_mode & FMODE_READ)
1501 poll_wait(file, &s->dma_adc.wait, wait);
1502
1503 spin_lock_irqsave(&s->card->lock, flags);
1504 m3_update_ptr(s);
1505
1506 if (file->f_mode & FMODE_READ) {
1507 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1508 mask |= POLLIN | POLLRDNORM;
1509 }
1510 if (file->f_mode & FMODE_WRITE) {
1511 if (s->dma_dac.mapped) {
1512 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
1513 mask |= POLLOUT | POLLWRNORM;
1514 } else {
1515 if ((signed)s->dma_dac.dmasize >= s->dma_dac.count + (signed)s->dma_dac.fragsize)
1516 mask |= POLLOUT | POLLWRNORM;
1517 }
1518 }
1519
1520 spin_unlock_irqrestore(&s->card->lock, flags);
1521 return mask;
1522}
1523
1524static int m3_mmap(struct file *file, struct vm_area_struct *vma)
1525{
1526 struct m3_state *s = (struct m3_state *)file->private_data;
1527 unsigned long max_size, size, start, offset;
1528 struct dmabuf *db;
1529 int ret = -EINVAL;
1530
1531 VALIDATE_STATE(s);
1532 if (vma->vm_flags & VM_WRITE) {
1533 if ((ret = prog_dmabuf(s, 0)) != 0)
1534 return ret;
1535 db = &s->dma_dac;
1536 } else
1537 if (vma->vm_flags & VM_READ) {
1538 if ((ret = prog_dmabuf(s, 1)) != 0)
1539 return ret;
1540 db = &s->dma_adc;
1541 } else
1542 return -EINVAL;
1543
1544 max_size = db->dmasize;
1545
1546 start = vma->vm_start;
1547 offset = (vma->vm_pgoff << PAGE_SHIFT);
1548 size = vma->vm_end - vma->vm_start;
1549
1550 if(size > max_size)
1551 goto out;
1552 if(offset > max_size - size)
1553 goto out;
1554
1555 /*
1556 * this will be ->nopage() once I can
1557 * ask Jeff what the hell I'm doing wrong.
1558 */
1559 ret = -EAGAIN;
1560 if (remap_pfn_range(vma, vma->vm_start,
1561 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
1562 size, vma->vm_page_prot))
1563 goto out;
1564
1565 db->mapped = 1;
1566 ret = 0;
1567
1568out:
1569 return ret;
1570}
1571
1572/*
1573 * this function is a disaster..
1574 */
1575#define get_user_ret(x, ptr, ret) ({ if(get_user(x, ptr)) return ret; })
1576static int m3_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1577{
1578 struct m3_state *s = (struct m3_state *)file->private_data;
1579 struct m3_card *card=s->card;
1580 unsigned long flags;
1581 audio_buf_info abinfo;
1582 count_info cinfo;
1583 int val, mapped, ret;
1584 unsigned char fmtm, fmtd;
1585 void __user *argp = (void __user *)arg;
1586 int __user *p = argp;
1587
1588 VALIDATE_STATE(s);
1589
1590 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1591 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1592
1593 DPRINTK(DPSYS,"m3_ioctl: cmd %d\n", cmd);
1594
1595 switch (cmd) {
1596 case OSS_GETVERSION:
1597 return put_user(SOUND_VERSION, p);
1598
1599 case SNDCTL_DSP_SYNC:
1600 if (file->f_mode & FMODE_WRITE)
1601 return drain_dac(s, file->f_flags & O_NONBLOCK);
1602 return 0;
1603
1604 case SNDCTL_DSP_SETDUPLEX:
1605 /* XXX fix */
1606 return 0;
1607
1608 case SNDCTL_DSP_GETCAPS:
1609 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
1610
1611 case SNDCTL_DSP_RESET:
1612 spin_lock_irqsave(&card->lock, flags);
1613 if (file->f_mode & FMODE_WRITE) {
1614 stop_dac(s);
1615 synchronize_irq(s->card->pcidev->irq);
1616 s->dma_dac.swptr = s->dma_dac.hwptr = s->dma_dac.count = s->dma_dac.total_bytes = 0;
1617 }
1618 if (file->f_mode & FMODE_READ) {
1619 stop_adc(s);
1620 synchronize_irq(s->card->pcidev->irq);
1621 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
1622 }
1623 spin_unlock_irqrestore(&card->lock, flags);
1624 return 0;
1625
1626 case SNDCTL_DSP_SPEED:
1627 get_user_ret(val, p, -EFAULT);
1628 spin_lock_irqsave(&card->lock, flags);
1629 if (val >= 0) {
1630 if (file->f_mode & FMODE_READ) {
1631 stop_adc(s);
1632 s->dma_adc.ready = 0;
1633 set_adc_rate(s, val);
1634 }
1635 if (file->f_mode & FMODE_WRITE) {
1636 stop_dac(s);
1637 s->dma_dac.ready = 0;
1638 set_dac_rate(s, val);
1639 }
1640 }
1641 spin_unlock_irqrestore(&card->lock, flags);
1642 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
1643
1644 case SNDCTL_DSP_STEREO:
1645 get_user_ret(val, p, -EFAULT);
1646 spin_lock_irqsave(&card->lock, flags);
1647 fmtd = 0;
1648 fmtm = ~0;
1649 if (file->f_mode & FMODE_READ) {
1650 stop_adc(s);
1651 s->dma_adc.ready = 0;
1652 if (val)
1653 fmtd |= ESS_FMT_STEREO << ESS_ADC_SHIFT;
1654 else
1655 fmtm &= ~(ESS_FMT_STEREO << ESS_ADC_SHIFT);
1656 }
1657 if (file->f_mode & FMODE_WRITE) {
1658 stop_dac(s);
1659 s->dma_dac.ready = 0;
1660 if (val)
1661 fmtd |= ESS_FMT_STEREO << ESS_DAC_SHIFT;
1662 else
1663 fmtm &= ~(ESS_FMT_STEREO << ESS_DAC_SHIFT);
1664 }
1665 set_fmt(s, fmtm, fmtd);
1666 spin_unlock_irqrestore(&card->lock, flags);
1667 return 0;
1668
1669 case SNDCTL_DSP_CHANNELS:
1670 get_user_ret(val, p, -EFAULT);
1671 spin_lock_irqsave(&card->lock, flags);
1672 if (val != 0) {
1673 fmtd = 0;
1674 fmtm = ~0;
1675 if (file->f_mode & FMODE_READ) {
1676 stop_adc(s);
1677 s->dma_adc.ready = 0;
1678 if (val >= 2)
1679 fmtd |= ESS_FMT_STEREO << ESS_ADC_SHIFT;
1680 else
1681 fmtm &= ~(ESS_FMT_STEREO << ESS_ADC_SHIFT);
1682 }
1683 if (file->f_mode & FMODE_WRITE) {
1684 stop_dac(s);
1685 s->dma_dac.ready = 0;
1686 if (val >= 2)
1687 fmtd |= ESS_FMT_STEREO << ESS_DAC_SHIFT;
1688 else
1689 fmtm &= ~(ESS_FMT_STEREO << ESS_DAC_SHIFT);
1690 }
1691 set_fmt(s, fmtm, fmtd);
1692 }
1693 spin_unlock_irqrestore(&card->lock, flags);
1694 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (ESS_FMT_STEREO << ESS_ADC_SHIFT)
1695 : (ESS_FMT_STEREO << ESS_DAC_SHIFT))) ? 2 : 1, p);
1696
1697 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1698 return put_user(AFMT_U8|AFMT_S16_LE, p);
1699
1700 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1701 get_user_ret(val, p, -EFAULT);
1702 spin_lock_irqsave(&card->lock, flags);
1703 if (val != AFMT_QUERY) {
1704 fmtd = 0;
1705 fmtm = ~0;
1706 if (file->f_mode & FMODE_READ) {
1707 stop_adc(s);
1708 s->dma_adc.ready = 0;
1709 if (val == AFMT_S16_LE)
1710 fmtd |= ESS_FMT_16BIT << ESS_ADC_SHIFT;
1711 else
1712 fmtm &= ~(ESS_FMT_16BIT << ESS_ADC_SHIFT);
1713 }
1714 if (file->f_mode & FMODE_WRITE) {
1715 stop_dac(s);
1716 s->dma_dac.ready = 0;
1717 if (val == AFMT_S16_LE)
1718 fmtd |= ESS_FMT_16BIT << ESS_DAC_SHIFT;
1719 else
1720 fmtm &= ~(ESS_FMT_16BIT << ESS_DAC_SHIFT);
1721 }
1722 set_fmt(s, fmtm, fmtd);
1723 }
1724 spin_unlock_irqrestore(&card->lock, flags);
1725 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ?
1726 (ESS_FMT_16BIT << ESS_ADC_SHIFT)
1727 : (ESS_FMT_16BIT << ESS_DAC_SHIFT))) ?
1728 AFMT_S16_LE :
1729 AFMT_U8,
1730 p);
1731
1732 case SNDCTL_DSP_POST:
1733 return 0;
1734
1735 case SNDCTL_DSP_GETTRIGGER:
1736 val = 0;
1737 if ((file->f_mode & FMODE_READ) && (s->enable & ADC_RUNNING))
1738 val |= PCM_ENABLE_INPUT;
1739 if ((file->f_mode & FMODE_WRITE) && (s->enable & DAC_RUNNING))
1740 val |= PCM_ENABLE_OUTPUT;
1741 return put_user(val, p);
1742
1743 case SNDCTL_DSP_SETTRIGGER:
1744 get_user_ret(val, p, -EFAULT);
1745 if (file->f_mode & FMODE_READ) {
1746 if (val & PCM_ENABLE_INPUT) {
1747 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
1748 return ret;
1749 start_adc(s);
1750 } else
1751 stop_adc(s);
1752 }
1753 if (file->f_mode & FMODE_WRITE) {
1754 if (val & PCM_ENABLE_OUTPUT) {
1755 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
1756 return ret;
1757 start_dac(s);
1758 } else
1759 stop_dac(s);
1760 }
1761 return 0;
1762
1763 case SNDCTL_DSP_GETOSPACE:
1764 if (!(file->f_mode & FMODE_WRITE))
1765 return -EINVAL;
1766 if (!(s->enable & DAC_RUNNING) && (val = prog_dmabuf(s, 0)) != 0)
1767 return val;
1768 spin_lock_irqsave(&card->lock, flags);
1769 m3_update_ptr(s);
1770 abinfo.fragsize = s->dma_dac.fragsize;
1771 abinfo.bytes = s->dma_dac.dmasize - s->dma_dac.count;
1772 abinfo.fragstotal = s->dma_dac.numfrag;
1773 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
1774 spin_unlock_irqrestore(&card->lock, flags);
1775 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1776
1777 case SNDCTL_DSP_GETISPACE:
1778 if (!(file->f_mode & FMODE_READ))
1779 return -EINVAL;
1780 if (!(s->enable & ADC_RUNNING) && (val = prog_dmabuf(s, 1)) != 0)
1781 return val;
1782 spin_lock_irqsave(&card->lock, flags);
1783 m3_update_ptr(s);
1784 abinfo.fragsize = s->dma_adc.fragsize;
1785 abinfo.bytes = s->dma_adc.count;
1786 abinfo.fragstotal = s->dma_adc.numfrag;
1787 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1788 spin_unlock_irqrestore(&card->lock, flags);
1789 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1790
1791 case SNDCTL_DSP_NONBLOCK:
1792 file->f_flags |= O_NONBLOCK;
1793 return 0;
1794
1795 case SNDCTL_DSP_GETODELAY:
1796 if (!(file->f_mode & FMODE_WRITE))
1797 return -EINVAL;
1798 spin_lock_irqsave(&card->lock, flags);
1799 m3_update_ptr(s);
1800 val = s->dma_dac.count;
1801 spin_unlock_irqrestore(&card->lock, flags);
1802 return put_user(val, p);
1803
1804 case SNDCTL_DSP_GETIPTR:
1805 if (!(file->f_mode & FMODE_READ))
1806 return -EINVAL;
1807 spin_lock_irqsave(&card->lock, flags);
1808 m3_update_ptr(s);
1809 cinfo.bytes = s->dma_adc.total_bytes;
1810 cinfo.blocks = s->dma_adc.count >> s->dma_adc.fragshift;
1811 cinfo.ptr = s->dma_adc.hwptr;
1812 if (s->dma_adc.mapped)
1813 s->dma_adc.count &= s->dma_adc.fragsize-1;
1814 spin_unlock_irqrestore(&card->lock, flags);
1815 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1816 return -EFAULT;
1817 return 0;
1818
1819 case SNDCTL_DSP_GETOPTR:
1820 if (!(file->f_mode & FMODE_WRITE))
1821 return -EINVAL;
1822 spin_lock_irqsave(&card->lock, flags);
1823 m3_update_ptr(s);
1824 cinfo.bytes = s->dma_dac.total_bytes;
1825 cinfo.blocks = s->dma_dac.count >> s->dma_dac.fragshift;
1826 cinfo.ptr = s->dma_dac.hwptr;
1827 if (s->dma_dac.mapped)
1828 s->dma_dac.count &= s->dma_dac.fragsize-1;
1829 spin_unlock_irqrestore(&card->lock, flags);
1830 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1831 return -EFAULT;
1832 return 0;
1833
1834 case SNDCTL_DSP_GETBLKSIZE:
1835 if (file->f_mode & FMODE_WRITE) {
1836 if ((val = prog_dmabuf(s, 0)))
1837 return val;
1838 return put_user(s->dma_dac.fragsize, p);
1839 }
1840 if ((val = prog_dmabuf(s, 1)))
1841 return val;
1842 return put_user(s->dma_adc.fragsize, p);
1843
1844 case SNDCTL_DSP_SETFRAGMENT:
1845 get_user_ret(val, p, -EFAULT);
1846 spin_lock_irqsave(&card->lock, flags);
1847 if (file->f_mode & FMODE_READ) {
1848 s->dma_adc.ossfragshift = val & 0xffff;
1849 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1850 if (s->dma_adc.ossfragshift < 4)
1851 s->dma_adc.ossfragshift = 4;
1852 if (s->dma_adc.ossfragshift > 15)
1853 s->dma_adc.ossfragshift = 15;
1854 if (s->dma_adc.ossmaxfrags < 4)
1855 s->dma_adc.ossmaxfrags = 4;
1856 }
1857 if (file->f_mode & FMODE_WRITE) {
1858 s->dma_dac.ossfragshift = val & 0xffff;
1859 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
1860 if (s->dma_dac.ossfragshift < 4)
1861 s->dma_dac.ossfragshift = 4;
1862 if (s->dma_dac.ossfragshift > 15)
1863 s->dma_dac.ossfragshift = 15;
1864 if (s->dma_dac.ossmaxfrags < 4)
1865 s->dma_dac.ossmaxfrags = 4;
1866 }
1867 spin_unlock_irqrestore(&card->lock, flags);
1868 return 0;
1869
1870 case SNDCTL_DSP_SUBDIVIDE:
1871 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1872 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
1873 return -EINVAL;
1874 get_user_ret(val, p, -EFAULT);
1875 if (val != 1 && val != 2 && val != 4)
1876 return -EINVAL;
1877 if (file->f_mode & FMODE_READ)
1878 s->dma_adc.subdivision = val;
1879 if (file->f_mode & FMODE_WRITE)
1880 s->dma_dac.subdivision = val;
1881 return 0;
1882
1883 case SOUND_PCM_READ_RATE:
1884 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
1885
1886 case SOUND_PCM_READ_CHANNELS:
1887 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (ESS_FMT_STEREO << ESS_ADC_SHIFT)
1888 : (ESS_FMT_STEREO << ESS_DAC_SHIFT))) ? 2 : 1, p);
1889
1890 case SOUND_PCM_READ_BITS:
1891 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (ESS_FMT_16BIT << ESS_ADC_SHIFT)
1892 : (ESS_FMT_16BIT << ESS_DAC_SHIFT))) ? 16 : 8, p);
1893
1894 case SOUND_PCM_WRITE_FILTER:
1895 case SNDCTL_DSP_SETSYNCRO:
1896 case SOUND_PCM_READ_FILTER:
1897 return -EINVAL;
1898
1899 }
1900 return -EINVAL;
1901}
1902
1903static int
1904allocate_dmabuf(struct pci_dev *pci_dev, struct dmabuf *db)
1905{
1906 int order;
1907
1908 DPRINTK(DPSTR,"allocating for dmabuf %p\n", db);
1909
1910 /*
1911 * alloc as big a chunk as we can, start with
1912 * 64k 'cause we're insane. based on order cause
1913 * the amazingly complicated prog_dmabuf wants it.
1914 *
1915 * pci_alloc_sonsistent guarantees that it won't cross a natural
1916 * boundary; the m3 hardware can't have dma cross a 64k bus
1917 * address boundary.
1918 */
1919 for (order = 16-PAGE_SHIFT; order >= 1; order--) {
1920 db->rawbuf = pci_alloc_consistent(pci_dev, PAGE_SIZE << order,
1921 &(db->handle));
1922 if(db->rawbuf)
1923 break;
1924 }
1925
1926 if (!db->rawbuf)
1927 return 1;
1928
1929 DPRINTK(DPSTR,"allocated %ld (%d) bytes at %p\n",
1930 PAGE_SIZE<<order, order, db->rawbuf);
1931
1932 {
1933 struct page *page, *pend;
1934
1935 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << order) - 1);
1936 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
1937 SetPageReserved(page);
1938 }
1939
1940
1941 db->buforder = order;
1942 db->ready = 0;
1943 db->mapped = 0;
1944
1945 return 0;
1946}
1947
1948static void
1949nuke_lists(struct m3_card *card, struct dmabuf *db)
1950{
1951 m3_remove_list(card, &(card->dma_list), db->dma_index);
1952 m3_remove_list(card, &(card->msrc_list), db->msrc_index);
1953 db->in_lists = 0;
1954}
1955
1956static void
1957free_dmabuf(struct pci_dev *pci_dev, struct dmabuf *db)
1958{
1959 if(db->rawbuf == NULL)
1960 return;
1961
1962 DPRINTK(DPSTR,"freeing %p from dmabuf %p\n",db->rawbuf, db);
1963
1964 {
1965 struct page *page, *pend;
1966 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
1967 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
1968 ClearPageReserved(page);
1969 }
1970
1971
1972 pci_free_consistent(pci_dev, PAGE_SIZE << db->buforder,
1973 db->rawbuf, db->handle);
1974
1975 db->rawbuf = NULL;
1976 db->buforder = 0;
1977 db->mapped = 0;
1978 db->ready = 0;
1979}
1980
1981static int m3_open(struct inode *inode, struct file *file)
1982{
1983 unsigned int minor = iminor(inode);
1984 struct m3_card *c;
1985 struct m3_state *s = NULL;
1986 int i;
1987 unsigned char fmtm = ~0, fmts = 0;
1988 unsigned long flags;
1989
1990 /*
1991 * Scan the cards and find the channel. We only
1992 * do this at open time so it is ok
1993 */
1994 for(c = devs ; c != NULL ; c = c->next) {
1995
1996 for(i=0;i<NR_DSPS;i++) {
1997
1998 if(c->channels[i].dev_audio < 0)
1999 continue;
2000 if((c->channels[i].dev_audio ^ minor) & ~0xf)
2001 continue;
2002
2003 s = &c->channels[i];
2004 break;
2005 }
2006 }
2007
2008 if (!s)
2009 return -ENODEV;
2010
2011 VALIDATE_STATE(s);
2012
2013 file->private_data = s;
2014
2015 /* wait for device to become free */
2016 down(&s->open_sem);
2017 while (s->open_mode & file->f_mode) {
2018 if (file->f_flags & O_NONBLOCK) {
2019 up(&s->open_sem);
2020 return -EWOULDBLOCK;
2021 }
2022 up(&s->open_sem);
2023 interruptible_sleep_on(&s->open_wait);
2024 if (signal_pending(current))
2025 return -ERESTARTSYS;
2026 down(&s->open_sem);
2027 }
2028
2029 spin_lock_irqsave(&c->lock, flags);
2030
2031 if (file->f_mode & FMODE_READ) {
2032 fmtm &= ~((ESS_FMT_STEREO | ESS_FMT_16BIT) << ESS_ADC_SHIFT);
2033 if ((minor & 0xf) == SND_DEV_DSP16)
2034 fmts |= ESS_FMT_16BIT << ESS_ADC_SHIFT;
2035
2036 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
2037 set_adc_rate(s, 8000);
2038 }
2039 if (file->f_mode & FMODE_WRITE) {
2040 fmtm &= ~((ESS_FMT_STEREO | ESS_FMT_16BIT) << ESS_DAC_SHIFT);
2041 if ((minor & 0xf) == SND_DEV_DSP16)
2042 fmts |= ESS_FMT_16BIT << ESS_DAC_SHIFT;
2043
2044 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = s->dma_dac.subdivision = 0;
2045 set_dac_rate(s, 8000);
2046 }
2047 set_fmt(s, fmtm, fmts);
2048 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2049
2050 up(&s->open_sem);
2051 spin_unlock_irqrestore(&c->lock, flags);
2052 return nonseekable_open(inode, file);
2053}
2054
2055static int m3_release(struct inode *inode, struct file *file)
2056{
2057 struct m3_state *s = (struct m3_state *)file->private_data;
2058 struct m3_card *card=s->card;
2059 unsigned long flags;
2060
2061 VALIDATE_STATE(s);
2062 if (file->f_mode & FMODE_WRITE)
2063 drain_dac(s, file->f_flags & O_NONBLOCK);
2064
2065 down(&s->open_sem);
2066 spin_lock_irqsave(&card->lock, flags);
2067
2068 if (file->f_mode & FMODE_WRITE) {
2069 stop_dac(s);
2070 if(s->dma_dac.in_lists) {
2071 m3_remove_list(s->card, &(s->card->mixer_list), s->dma_dac.mixer_index);
2072 nuke_lists(s->card, &(s->dma_dac));
2073 }
2074 }
2075 if (file->f_mode & FMODE_READ) {
2076 stop_adc(s);
2077 if(s->dma_adc.in_lists) {
2078 m3_remove_list(s->card, &(s->card->adc1_list), s->dma_adc.adc1_index);
2079 nuke_lists(s->card, &(s->dma_adc));
2080 }
2081 }
2082
2083 s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
2084
2085 spin_unlock_irqrestore(&card->lock, flags);
2086 up(&s->open_sem);
2087 wake_up(&s->open_wait);
2088
2089 return 0;
2090}
2091
2092/*
2093 * Wait for the ac97 serial bus to be free.
2094 * return nonzero if the bus is still busy.
2095 */
2096static int m3_ac97_wait(struct m3_card *card)
2097{
2098 int i = 10000;
2099
2100 while( (m3_inb(card, 0x30) & 1) && i--) ;
2101
2102 return i == 0;
2103}
2104
2105static u16 m3_ac97_read(struct ac97_codec *codec, u8 reg)
2106{
2107 u16 ret = 0;
2108 struct m3_card *card = codec->private_data;
2109
2110 spin_lock(&card->ac97_lock);
2111
2112 if(m3_ac97_wait(card)) {
2113 printk(KERN_ERR PFX "serial bus busy reading reg 0x%x\n",reg);
2114 goto out;
2115 }
2116
2117 m3_outb(card, 0x80 | (reg & 0x7f), 0x30);
2118
2119 if(m3_ac97_wait(card)) {
2120 printk(KERN_ERR PFX "serial bus busy finishing read reg 0x%x\n",reg);
2121 goto out;
2122 }
2123
2124 ret = m3_inw(card, 0x32);
2125 DPRINTK(DPCRAP,"reading 0x%04x from 0x%02x\n",ret, reg);
2126
2127out:
2128 spin_unlock(&card->ac97_lock);
2129 return ret;
2130}
2131
2132static void m3_ac97_write(struct ac97_codec *codec, u8 reg, u16 val)
2133{
2134 struct m3_card *card = codec->private_data;
2135
2136 spin_lock(&card->ac97_lock);
2137
2138 if(m3_ac97_wait(card)) {
2139 printk(KERN_ERR PFX "serial bus busy writing 0x%x to 0x%x\n",val, reg);
2140 goto out;
2141 }
2142 DPRINTK(DPCRAP,"writing 0x%04x to 0x%02x\n", val, reg);
2143
2144 m3_outw(card, val, 0x32);
2145 m3_outb(card, reg & 0x7f, 0x30);
2146out:
2147 spin_unlock(&card->ac97_lock);
2148}
2149/* OSS /dev/mixer file operation methods */
2150static int m3_open_mixdev(struct inode *inode, struct file *file)
2151{
2152 unsigned int minor = iminor(inode);
2153 struct m3_card *card = devs;
2154
2155 for (card = devs; card != NULL; card = card->next) {
2156 if((card->ac97 != NULL) && (card->ac97->dev_mixer == minor))
2157 break;
2158 }
2159
2160 if (!card) {
2161 return -ENODEV;
2162 }
2163
2164 file->private_data = card->ac97;
2165
2166 return nonseekable_open(inode, file);
2167}
2168
2169static int m3_release_mixdev(struct inode *inode, struct file *file)
2170{
2171 return 0;
2172}
2173
2174static int m3_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
2175 unsigned long arg)
2176{
2177 struct ac97_codec *codec = (struct ac97_codec *)file->private_data;
2178
2179 return codec->mixer_ioctl(codec, cmd, arg);
2180}
2181
2182static struct file_operations m3_mixer_fops = {
2183 .owner = THIS_MODULE,
2184 .llseek = no_llseek,
2185 .ioctl = m3_ioctl_mixdev,
2186 .open = m3_open_mixdev,
2187 .release = m3_release_mixdev,
2188};
2189
2190static void remote_codec_config(int io, int isremote)
2191{
2192 isremote = isremote ? 1 : 0;
2193
2194 outw( (inw(io + RING_BUS_CTRL_B) & ~SECOND_CODEC_ID_MASK) | isremote,
2195 io + RING_BUS_CTRL_B);
2196 outw( (inw(io + SDO_OUT_DEST_CTRL) & ~COMMAND_ADDR_OUT) | isremote,
2197 io + SDO_OUT_DEST_CTRL);
2198 outw( (inw(io + SDO_IN_DEST_CTRL) & ~STATUS_ADDR_IN) | isremote,
2199 io + SDO_IN_DEST_CTRL);
2200}
2201
2202/*
2203 * hack, returns non zero on err
2204 */
2205static int try_read_vendor(struct m3_card *card)
2206{
2207 u16 ret;
2208
2209 if(m3_ac97_wait(card))
2210 return 1;
2211
2212 m3_outb(card, 0x80 | (AC97_VENDOR_ID1 & 0x7f), 0x30);
2213
2214 if(m3_ac97_wait(card))
2215 return 1;
2216
2217 ret = m3_inw(card, 0x32);
2218
2219 return (ret == 0) || (ret == 0xffff);
2220}
2221
2222static void m3_codec_reset(struct m3_card *card, int busywait)
2223{
2224 u16 dir;
2225 int delay1 = 0, delay2 = 0, i;
2226 int io = card->iobase;
2227
2228 switch (card->card_type) {
2229 /*
2230 * the onboard codec on the allegro seems
2231 * to want to wait a very long time before
2232 * coming back to life
2233 */
2234 case ESS_ALLEGRO:
2235 delay1 = 50;
2236 delay2 = 800;
2237 break;
2238 case ESS_MAESTRO3:
2239 case ESS_MAESTRO3HW:
2240 delay1 = 20;
2241 delay2 = 500;
2242 break;
2243 }
2244
2245 for(i = 0; i < 5; i ++) {
2246 dir = inw(io + GPIO_DIRECTION);
2247 dir |= 0x10; /* assuming pci bus master? */
2248
2249 remote_codec_config(io, 0);
2250
2251 outw(IO_SRAM_ENABLE, io + RING_BUS_CTRL_A);
2252 udelay(20);
2253
2254 outw(dir & ~GPO_PRIMARY_AC97 , io + GPIO_DIRECTION);
2255 outw(~GPO_PRIMARY_AC97 , io + GPIO_MASK);
2256 outw(0, io + GPIO_DATA);
2257 outw(dir | GPO_PRIMARY_AC97, io + GPIO_DIRECTION);
2258
2259 if(busywait) {
2260 mdelay(delay1);
2261 } else {
2262 set_current_state(TASK_UNINTERRUPTIBLE);
2263 schedule_timeout((delay1 * HZ) / 1000);
2264 }
2265
2266 outw(GPO_PRIMARY_AC97, io + GPIO_DATA);
2267 udelay(5);
2268 /* ok, bring back the ac-link */
2269 outw(IO_SRAM_ENABLE | SERIAL_AC_LINK_ENABLE, io + RING_BUS_CTRL_A);
2270 outw(~0, io + GPIO_MASK);
2271
2272 if(busywait) {
2273 mdelay(delay2);
2274 } else {
2275 set_current_state(TASK_UNINTERRUPTIBLE);
2276 schedule_timeout((delay2 * HZ) / 1000);
2277 }
2278 if(! try_read_vendor(card))
2279 break;
2280
2281 delay1 += 10;
2282 delay2 += 100;
2283
2284 DPRINTK(DPMOD, "retrying codec reset with delays of %d and %d ms\n",
2285 delay1, delay2);
2286 }
2287
2288#if 0
2289 /* more gung-ho reset that doesn't
2290 * seem to work anywhere :)
2291 */
2292 tmp = inw(io + RING_BUS_CTRL_A);
2293 outw(RAC_SDFS_ENABLE|LAC_SDFS_ENABLE, io + RING_BUS_CTRL_A);
2294 mdelay(20);
2295 outw(tmp, io + RING_BUS_CTRL_A);
2296 mdelay(50);
2297#endif
2298}
2299
2300static int __devinit m3_codec_install(struct m3_card *card)
2301{
2302 struct ac97_codec *codec;
2303
2304 if ((codec = ac97_alloc_codec()) == NULL)
2305 return -ENOMEM;
2306
2307 codec->private_data = card;
2308 codec->codec_read = m3_ac97_read;
2309 codec->codec_write = m3_ac97_write;
2310 /* someday we should support secondary codecs.. */
2311 codec->id = 0;
2312
2313 if (ac97_probe_codec(codec) == 0) {
2314 printk(KERN_ERR PFX "codec probe failed\n");
2315 ac97_release_codec(codec);
2316 return -1;
2317 }
2318
2319 if ((codec->dev_mixer = register_sound_mixer(&m3_mixer_fops, -1)) < 0) {
2320 printk(KERN_ERR PFX "couldn't register mixer!\n");
2321 ac97_release_codec(codec);
2322 return -1;
2323 }
2324
2325 card->ac97 = codec;
2326
2327 return 0;
2328}
2329
2330
2331#define MINISRC_LPF_LEN 10
2332static u16 minisrc_lpf[MINISRC_LPF_LEN] = {
2333 0X0743, 0X1104, 0X0A4C, 0XF88D, 0X242C,
2334 0X1023, 0X1AA9, 0X0B60, 0XEFDD, 0X186F
2335};
2336static void m3_assp_init(struct m3_card *card)
2337{
2338 int i;
2339
2340 /* zero kernel data */
2341 for(i = 0 ; i < (REV_B_DATA_MEMORY_UNIT_LENGTH * NUM_UNITS_KERNEL_DATA) / 2; i++)
2342 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2343 KDATA_BASE_ADDR + i, 0);
2344
2345 /* zero mixer data? */
2346 for(i = 0 ; i < (REV_B_DATA_MEMORY_UNIT_LENGTH * NUM_UNITS_KERNEL_DATA) / 2; i++)
2347 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2348 KDATA_BASE_ADDR2 + i, 0);
2349
2350 /* init dma pointer */
2351 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2352 KDATA_CURRENT_DMA,
2353 KDATA_DMA_XFER0);
2354
2355 /* write kernel into code memory.. */
2356 for(i = 0 ; i < sizeof(assp_kernel_image) / 2; i++) {
2357 m3_assp_write(card, MEMTYPE_INTERNAL_CODE,
2358 REV_B_CODE_MEMORY_BEGIN + i,
2359 assp_kernel_image[i]);
2360 }
2361
2362 /*
2363 * We only have this one client and we know that 0x400
2364 * is free in our kernel's mem map, so lets just
2365 * drop it there. It seems that the minisrc doesn't
2366 * need vectors, so we won't bother with them..
2367 */
2368 for(i = 0 ; i < sizeof(assp_minisrc_image) / 2; i++) {
2369 m3_assp_write(card, MEMTYPE_INTERNAL_CODE,
2370 0x400 + i,
2371 assp_minisrc_image[i]);
2372 }
2373
2374 /*
2375 * write the coefficients for the low pass filter?
2376 */
2377 for(i = 0; i < MINISRC_LPF_LEN ; i++) {
2378 m3_assp_write(card, MEMTYPE_INTERNAL_CODE,
2379 0x400 + MINISRC_COEF_LOC + i,
2380 minisrc_lpf[i]);
2381 }
2382
2383 m3_assp_write(card, MEMTYPE_INTERNAL_CODE,
2384 0x400 + MINISRC_COEF_LOC + MINISRC_LPF_LEN,
2385 0x8000);
2386
2387 /*
2388 * the minisrc is the only thing on
2389 * our task list..
2390 */
2391 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2392 KDATA_TASK0,
2393 0x400);
2394
2395 /*
2396 * init the mixer number..
2397 */
2398
2399 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2400 KDATA_MIXER_TASK_NUMBER,0);
2401
2402 /*
2403 * EXTREME KERNEL MASTER VOLUME
2404 */
2405 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2406 KDATA_DAC_LEFT_VOLUME, ARB_VOLUME);
2407 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2408 KDATA_DAC_RIGHT_VOLUME, ARB_VOLUME);
2409
2410 card->mixer_list.mem_addr = KDATA_MIXER_XFER0;
2411 card->mixer_list.max = MAX_VIRTUAL_MIXER_CHANNELS;
2412 card->adc1_list.mem_addr = KDATA_ADC1_XFER0;
2413 card->adc1_list.max = MAX_VIRTUAL_ADC1_CHANNELS;
2414 card->dma_list.mem_addr = KDATA_DMA_XFER0;
2415 card->dma_list.max = MAX_VIRTUAL_DMA_CHANNELS;
2416 card->msrc_list.mem_addr = KDATA_INSTANCE0_MINISRC;
2417 card->msrc_list.max = MAX_INSTANCE_MINISRC;
2418}
2419
2420static int setup_msrc(struct m3_card *card,
2421 struct assp_instance *inst, int index)
2422{
2423 int data_bytes = 2 * ( MINISRC_TMP_BUFFER_SIZE / 2 +
2424 MINISRC_IN_BUFFER_SIZE / 2 +
2425 1 + MINISRC_OUT_BUFFER_SIZE / 2 + 1 );
2426 int address, i;
2427
2428 /*
2429 * the revb memory map has 0x1100 through 0x1c00
2430 * free.
2431 */
2432
2433 /*
2434 * align instance address to 256 bytes so that it's
2435 * shifted list address is aligned.
2436 * list address = (mem address >> 1) >> 7;
2437 */
2438 data_bytes = (data_bytes + 255) & ~255;
2439 address = 0x1100 + ((data_bytes/2) * index);
2440
2441 if((address + (data_bytes/2)) >= 0x1c00) {
2442 printk(KERN_ERR PFX "no memory for %d bytes at ind %d (addr 0x%x)\n",
2443 data_bytes, index, address);
2444 return -1;
2445 }
2446
2447 for(i = 0; i < data_bytes/2 ; i++)
2448 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2449 address + i, 0);
2450
2451 inst->code = 0x400;
2452 inst->data = address;
2453
2454 return 0;
2455}
2456
2457static int m3_assp_client_init(struct m3_state *s)
2458{
2459 setup_msrc(s->card, &(s->dac_inst), s->index * 2);
2460 setup_msrc(s->card, &(s->adc_inst), (s->index * 2) + 1);
2461
2462 return 0;
2463}
2464
2465static void m3_amp_enable(struct m3_card *card, int enable)
2466{
2467 /*
2468 * this works for the reference board, have to find
2469 * out about others
2470 *
2471 * this needs more magic for 4 speaker, but..
2472 */
2473 int io = card->iobase;
2474 u16 gpo, polarity_port, polarity;
2475
2476 if(!external_amp)
2477 return;
2478
2479 if (gpio_pin >= 0 && gpio_pin <= 15) {
2480 polarity_port = 0x1000 + (0x100 * gpio_pin);
2481 } else {
2482 switch (card->card_type) {
2483 case ESS_ALLEGRO:
2484 polarity_port = 0x1800;
2485 break;
2486 default:
2487 polarity_port = 0x1100;
2488 /* Panasonic toughbook CF72 has to be different... */
2489 if(card->pcidev->subsystem_vendor == 0x10F7 && card->pcidev->subsystem_device == 0x833D)
2490 polarity_port = 0x1D00;
2491 break;
2492 }
2493 }
2494
2495 gpo = (polarity_port >> 8) & 0x0F;
2496 polarity = polarity_port >> 12;
2497 if ( enable )
2498 polarity = !polarity;
2499 polarity = polarity << gpo;
2500 gpo = 1 << gpo;
2501
2502 outw(~gpo , io + GPIO_MASK);
2503
2504 outw( inw(io + GPIO_DIRECTION) | gpo ,
2505 io + GPIO_DIRECTION);
2506
2507 outw( (GPO_SECONDARY_AC97 | GPO_PRIMARY_AC97 | polarity) ,
2508 io + GPIO_DATA);
2509
2510 outw(0xffff , io + GPIO_MASK);
2511}
2512
2513static int
2514maestro_config(struct m3_card *card)
2515{
2516 struct pci_dev *pcidev = card->pcidev;
2517 u32 n;
2518 u8 t; /* makes as much sense as 'n', no? */
2519
2520 pci_read_config_dword(pcidev, PCI_ALLEGRO_CONFIG, &n);
2521 n &= REDUCED_DEBOUNCE;
2522 n |= PM_CTRL_ENABLE | CLK_DIV_BY_49 | USE_PCI_TIMING;
2523 pci_write_config_dword(pcidev, PCI_ALLEGRO_CONFIG, n);
2524
2525 outb(RESET_ASSP, card->iobase + ASSP_CONTROL_B);
2526 pci_read_config_dword(pcidev, PCI_ALLEGRO_CONFIG, &n);
2527 n &= ~INT_CLK_SELECT;
2528 if(card->card_type >= ESS_MAESTRO3) {
2529 n &= ~INT_CLK_MULT_ENABLE;
2530 n |= INT_CLK_SRC_NOT_PCI;
2531 }
2532 n &= ~( CLK_MULT_MODE_SELECT | CLK_MULT_MODE_SELECT_2 );
2533 pci_write_config_dword(pcidev, PCI_ALLEGRO_CONFIG, n);
2534
2535 if(card->card_type <= ESS_ALLEGRO) {
2536 pci_read_config_dword(pcidev, PCI_USER_CONFIG, &n);
2537 n |= IN_CLK_12MHZ_SELECT;
2538 pci_write_config_dword(pcidev, PCI_USER_CONFIG, n);
2539 }
2540
2541 t = inb(card->iobase + ASSP_CONTROL_A);
2542 t &= ~( DSP_CLK_36MHZ_SELECT | ASSP_CLK_49MHZ_SELECT);
2543 t |= ASSP_CLK_49MHZ_SELECT;
2544 t |= ASSP_0_WS_ENABLE;
2545 outb(t, card->iobase + ASSP_CONTROL_A);
2546
2547 outb(RUN_ASSP, card->iobase + ASSP_CONTROL_B);
2548
2549 return 0;
2550}
2551
2552static void m3_enable_ints(struct m3_card *card)
2553{
2554 unsigned long io = card->iobase;
2555
2556 outw(ASSP_INT_ENABLE, io + HOST_INT_CTRL);
2557 outb(inb(io + ASSP_CONTROL_C) | ASSP_HOST_INT_ENABLE,
2558 io + ASSP_CONTROL_C);
2559}
2560
2561static struct file_operations m3_audio_fops = {
2562 .owner = THIS_MODULE,
2563 .llseek = no_llseek,
2564 .read = m3_read,
2565 .write = m3_write,
2566 .poll = m3_poll,
2567 .ioctl = m3_ioctl,
2568 .mmap = m3_mmap,
2569 .open = m3_open,
2570 .release = m3_release,
2571};
2572
2573#ifdef CONFIG_PM
2574static int alloc_dsp_suspendmem(struct m3_card *card)
2575{
2576 int len = sizeof(u16) * (REV_B_CODE_MEMORY_LENGTH + REV_B_DATA_MEMORY_LENGTH);
2577
2578 if( (card->suspend_mem = vmalloc(len)) == NULL)
2579 return 1;
2580
2581 return 0;
2582}
2583static void free_dsp_suspendmem(struct m3_card *card)
2584{
2585 if(card->suspend_mem)
2586 vfree(card->suspend_mem);
2587}
2588
2589#else
2590#define alloc_dsp_suspendmem(args...) 0
2591#define free_dsp_suspendmem(args...)
2592#endif
2593
2594/*
2595 * great day! this function is ugly as hell.
2596 */
2597static int __devinit m3_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
2598{
2599 u32 n;
2600 int i;
2601 struct m3_card *card = NULL;
2602 int ret = 0;
2603 int card_type = pci_id->driver_data;
2604
2605 DPRINTK(DPMOD, "in maestro_install\n");
2606
2607 if (pci_enable_device(pci_dev))
2608 return -EIO;
2609
2610 if (pci_set_dma_mask(pci_dev, M3_PCI_DMA_MASK)) {
2611 printk(KERN_ERR PFX "architecture does not support limiting to 28bit PCI bus addresses\n");
2612 return -ENODEV;
2613 }
2614
2615 pci_set_master(pci_dev);
2616
2617 if( (card = kmalloc(sizeof(struct m3_card), GFP_KERNEL)) == NULL) {
2618 printk(KERN_WARNING PFX "out of memory\n");
2619 return -ENOMEM;
2620 }
2621 memset(card, 0, sizeof(struct m3_card));
2622 card->pcidev = pci_dev;
2623 init_waitqueue_head(&card->suspend_queue);
2624
2625 if ( ! request_region(pci_resource_start(pci_dev, 0),
2626 pci_resource_len (pci_dev, 0), M3_MODULE_NAME)) {
2627
2628 printk(KERN_WARNING PFX "unable to reserve I/O space.\n");
2629 ret = -EBUSY;
2630 goto out;
2631 }
2632
2633 card->iobase = pci_resource_start(pci_dev, 0);
2634
2635 if(alloc_dsp_suspendmem(card)) {
2636 printk(KERN_WARNING PFX "couldn't alloc %d bytes for saving dsp state on suspend\n",
2637 REV_B_CODE_MEMORY_LENGTH + REV_B_DATA_MEMORY_LENGTH);
2638 ret = -ENOMEM;
2639 goto out;
2640 }
2641
2642 card->card_type = card_type;
2643 card->irq = pci_dev->irq;
2644 card->next = devs;
2645 card->magic = M3_CARD_MAGIC;
2646 spin_lock_init(&card->lock);
2647 spin_lock_init(&card->ac97_lock);
2648 devs = card;
2649 for(i = 0; i<NR_DSPS; i++) {
2650 struct m3_state *s = &(card->channels[i]);
2651 s->dev_audio = -1;
2652 }
2653
2654 printk(KERN_INFO PFX "Configuring ESS %s found at IO 0x%04X IRQ %d\n",
2655 card_names[card->card_type], card->iobase, card->irq);
2656
2657 pci_read_config_dword(pci_dev, PCI_SUBSYSTEM_VENDOR_ID, &n);
2658 printk(KERN_INFO PFX " subvendor id: 0x%08x\n",n);
2659
2660 maestro_config(card);
2661 m3_assp_halt(card);
2662
2663 m3_codec_reset(card, 0);
2664
2665 if(m3_codec_install(card)) {
2666 ret = -EIO;
2667 goto out;
2668 }
2669
2670 m3_assp_init(card);
2671 m3_amp_enable(card, 1);
2672
2673 for(i=0;i<NR_DSPS;i++) {
2674 struct m3_state *s=&card->channels[i];
2675
2676 s->index = i;
2677
2678 s->card = card;
2679 init_waitqueue_head(&s->dma_adc.wait);
2680 init_waitqueue_head(&s->dma_dac.wait);
2681 init_waitqueue_head(&s->open_wait);
2682 init_MUTEX(&(s->open_sem));
2683 s->magic = M3_STATE_MAGIC;
2684
2685 m3_assp_client_init(s);
2686
2687 if(s->dma_adc.ready || s->dma_dac.ready || s->dma_adc.rawbuf)
2688 printk(KERN_WARNING PFX "initing a dsp device that is already in use?\n");
2689 /* register devices */
2690 if ((s->dev_audio = register_sound_dsp(&m3_audio_fops, -1)) < 0) {
2691 break;
2692 }
2693
2694 if( allocate_dmabuf(card->pcidev, &(s->dma_adc)) ||
2695 allocate_dmabuf(card->pcidev, &(s->dma_dac))) {
2696 ret = -ENOMEM;
2697 goto out;
2698 }
2699 }
2700
2701 if(request_irq(card->irq, m3_interrupt, SA_SHIRQ, card_names[card->card_type], card)) {
2702
2703 printk(KERN_ERR PFX "unable to allocate irq %d,\n", card->irq);
2704
2705 ret = -EIO;
2706 goto out;
2707 }
2708
2709 pci_set_drvdata(pci_dev, card);
2710
2711 m3_enable_ints(card);
2712 m3_assp_continue(card);
2713
2714out:
2715 if(ret) {
2716 if(card->iobase)
2717 release_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
2718 free_dsp_suspendmem(card);
2719 if(card->ac97) {
2720 unregister_sound_mixer(card->ac97->dev_mixer);
2721 kfree(card->ac97);
2722 }
2723 for(i=0;i<NR_DSPS;i++)
2724 {
2725 struct m3_state *s = &card->channels[i];
2726 if(s->dev_audio != -1)
2727 unregister_sound_dsp(s->dev_audio);
2728 }
2729 kfree(card);
2730 }
2731
2732 return ret;
2733}
2734
2735static void m3_remove(struct pci_dev *pci_dev)
2736{
2737 struct m3_card *card;
2738
2739 unregister_reboot_notifier(&m3_reboot_nb);
2740
2741 while ((card = devs)) {
2742 int i;
2743 devs = devs->next;
2744
2745 free_irq(card->irq, card);
2746 unregister_sound_mixer(card->ac97->dev_mixer);
2747 kfree(card->ac97);
2748
2749 for(i=0;i<NR_DSPS;i++)
2750 {
2751 struct m3_state *s = &card->channels[i];
2752 if(s->dev_audio < 0)
2753 continue;
2754
2755 unregister_sound_dsp(s->dev_audio);
2756 free_dmabuf(card->pcidev, &s->dma_adc);
2757 free_dmabuf(card->pcidev, &s->dma_dac);
2758 }
2759
2760 release_region(card->iobase, 256);
2761 free_dsp_suspendmem(card);
2762 kfree(card);
2763 }
2764 devs = NULL;
2765}
2766
2767/*
2768 * some bioses like the sound chip to be powered down
2769 * at shutdown. We're just calling _suspend to
2770 * achieve that..
2771 */
2772static int m3_notifier(struct notifier_block *nb, unsigned long event, void *buf)
2773{
2774 struct m3_card *card;
2775
2776 DPRINTK(DPMOD, "notifier suspending all cards\n");
2777
2778 for(card = devs; card != NULL; card = card->next) {
2779 if(!card->in_suspend)
2780 m3_suspend(card->pcidev, PMSG_SUSPEND); /* XXX legal? */
2781 }
2782 return 0;
2783}
2784
2785static int m3_suspend(struct pci_dev *pci_dev, pm_message_t state)
2786{
2787 unsigned long flags;
2788 int i;
2789 struct m3_card *card = pci_get_drvdata(pci_dev);
2790
2791 /* must be a better way.. */
2792 spin_lock_irqsave(&card->lock, flags);
2793
2794 DPRINTK(DPMOD, "pm in dev %p\n",card);
2795
2796 for(i=0;i<NR_DSPS;i++) {
2797 struct m3_state *s = &card->channels[i];
2798
2799 if(s->dev_audio == -1)
2800 continue;
2801
2802 DPRINTK(DPMOD, "stop_adc/dac() device %d\n",i);
2803 stop_dac(s);
2804 stop_adc(s);
2805 }
2806
2807 mdelay(10); /* give the assp a chance to idle.. */
2808
2809 m3_assp_halt(card);
2810
2811 if(card->suspend_mem) {
2812 int index = 0;
2813
2814 DPRINTK(DPMOD, "saving code\n");
2815 for(i = REV_B_CODE_MEMORY_BEGIN ; i <= REV_B_CODE_MEMORY_END; i++)
2816 card->suspend_mem[index++] =
2817 m3_assp_read(card, MEMTYPE_INTERNAL_CODE, i);
2818 DPRINTK(DPMOD, "saving data\n");
2819 for(i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2820 card->suspend_mem[index++] =
2821 m3_assp_read(card, MEMTYPE_INTERNAL_DATA, i);
2822 }
2823
2824 DPRINTK(DPMOD, "powering down apci regs\n");
2825 m3_outw(card, 0xffff, 0x54);
2826 m3_outw(card, 0xffff, 0x56);
2827
2828 card->in_suspend = 1;
2829
2830 spin_unlock_irqrestore(&card->lock, flags);
2831
2832 return 0;
2833}
2834
2835static int m3_resume(struct pci_dev *pci_dev)
2836{
2837 unsigned long flags;
2838 int index;
2839 int i;
2840 struct m3_card *card = pci_get_drvdata(pci_dev);
2841
2842 spin_lock_irqsave(&card->lock, flags);
2843 card->in_suspend = 0;
2844
2845 DPRINTK(DPMOD, "resuming\n");
2846
2847 /* first lets just bring everything back. .*/
2848
2849 DPRINTK(DPMOD, "bringing power back on card 0x%p\n",card);
2850 m3_outw(card, 0, 0x54);
2851 m3_outw(card, 0, 0x56);
2852
2853 DPRINTK(DPMOD, "restoring pci configs and reseting codec\n");
2854 maestro_config(card);
2855 m3_assp_halt(card);
2856 m3_codec_reset(card, 1);
2857
2858 DPRINTK(DPMOD, "restoring dsp code card\n");
2859 index = 0;
2860 for(i = REV_B_CODE_MEMORY_BEGIN ; i <= REV_B_CODE_MEMORY_END; i++)
2861 m3_assp_write(card, MEMTYPE_INTERNAL_CODE, i,
2862 card->suspend_mem[index++]);
2863 for(i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2864 m3_assp_write(card, MEMTYPE_INTERNAL_DATA, i,
2865 card->suspend_mem[index++]);
2866
2867 /* tell the dma engine to restart itself */
2868 m3_assp_write(card, MEMTYPE_INTERNAL_DATA,
2869 KDATA_DMA_ACTIVE, 0);
2870
2871 DPRINTK(DPMOD, "resuming dsp\n");
2872 m3_assp_continue(card);
2873
2874 DPRINTK(DPMOD, "enabling ints\n");
2875 m3_enable_ints(card);
2876
2877 /* bring back the old school flavor */
2878 for(i = 0; i < SOUND_MIXER_NRDEVICES ; i++) {
2879 int state = card->ac97->mixer_state[i];
2880 if (!supported_mixer(card->ac97, i))
2881 continue;
2882
2883 card->ac97->write_mixer(card->ac97, i,
2884 state & 0xff, (state >> 8) & 0xff);
2885 }
2886
2887 m3_amp_enable(card, 1);
2888
2889 /*
2890 * now we flip on the music
2891 */
2892 for(i=0;i<NR_DSPS;i++) {
2893 struct m3_state *s = &card->channels[i];
2894 if(s->dev_audio == -1)
2895 continue;
2896 /*
2897 * db->ready makes it so these guys can be
2898 * called unconditionally..
2899 */
2900 DPRINTK(DPMOD, "turning on dacs ind %d\n",i);
2901 start_dac(s);
2902 start_adc(s);
2903 }
2904
2905 spin_unlock_irqrestore(&card->lock, flags);
2906
2907 /*
2908 * all right, we think things are ready,
2909 * wake up people who were using the device
2910 * when we suspended
2911 */
2912 wake_up(&card->suspend_queue);
2913
2914 return 0;
2915}
2916
2917MODULE_AUTHOR("Zach Brown <zab@zabbo.net>");
2918MODULE_DESCRIPTION("ESS Maestro3/Allegro Driver");
2919MODULE_LICENSE("GPL");
2920
2921#ifdef M_DEBUG
2922module_param(debug, int, 0);
2923#endif
2924module_param(external_amp, int, 0);
2925module_param(gpio_pin, int, 0);
2926
2927static struct pci_driver m3_pci_driver = {
2928 .name = "ess_m3_audio",
2929 .id_table = m3_id_table,
2930 .probe = m3_probe,
2931 .remove = m3_remove,
2932 .suspend = m3_suspend,
2933 .resume = m3_resume,
2934};
2935
2936static int __init m3_init_module(void)
2937{
2938 printk(KERN_INFO PFX "version " DRIVER_VERSION " built at " __TIME__ " " __DATE__ "\n");
2939
2940 if (register_reboot_notifier(&m3_reboot_nb)) {
2941 printk(KERN_WARNING PFX "reboot notifier registration failed\n");
2942 return -ENODEV; /* ? */
2943 }
2944
2945 if (pci_register_driver(&m3_pci_driver)) {
2946 unregister_reboot_notifier(&m3_reboot_nb);
2947 return -ENODEV;
2948 }
2949 return 0;
2950}
2951
2952static void __exit m3_cleanup_module(void)
2953{
2954 pci_unregister_driver(&m3_pci_driver);
2955}
2956
2957module_init(m3_init_module);
2958module_exit(m3_cleanup_module);
2959
2960void check_suspend(struct m3_card *card)
2961{
2962 DECLARE_WAITQUEUE(wait, current);
2963
2964 if(!card->in_suspend)
2965 return;
2966
2967 card->in_suspend++;
2968 add_wait_queue(&card->suspend_queue, &wait);
2969 set_current_state(TASK_UNINTERRUPTIBLE);
2970 schedule();
2971 remove_wait_queue(&card->suspend_queue, &wait);
2972 set_current_state(TASK_RUNNING);
2973}
diff --git a/sound/oss/maestro3.h b/sound/oss/maestro3.h
new file mode 100644
index 000000000000..dde29862c572
--- /dev/null
+++ b/sound/oss/maestro3.h
@@ -0,0 +1,821 @@
1/*
2 * ESS Technology allegro audio driver.
3 *
4 * Copyright (C) 1992-2000 Don Kim (don.kim@esstech.com)
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Hacked for the maestro3 driver by zab
21 */
22
23// Allegro PCI configuration registers
24#define PCI_LEGACY_AUDIO_CTRL 0x40
25#define SOUND_BLASTER_ENABLE 0x00000001
26#define FM_SYNTHESIS_ENABLE 0x00000002
27#define GAME_PORT_ENABLE 0x00000004
28#define MPU401_IO_ENABLE 0x00000008
29#define MPU401_IRQ_ENABLE 0x00000010
30#define ALIAS_10BIT_IO 0x00000020
31#define SB_DMA_MASK 0x000000C0
32#define SB_DMA_0 0x00000040
33#define SB_DMA_1 0x00000040
34#define SB_DMA_R 0x00000080
35#define SB_DMA_3 0x000000C0
36#define SB_IRQ_MASK 0x00000700
37#define SB_IRQ_5 0x00000000
38#define SB_IRQ_7 0x00000100
39#define SB_IRQ_9 0x00000200
40#define SB_IRQ_10 0x00000300
41#define MIDI_IRQ_MASK 0x00003800
42#define SERIAL_IRQ_ENABLE 0x00004000
43#define DISABLE_LEGACY 0x00008000
44
45#define PCI_ALLEGRO_CONFIG 0x50
46#define SB_ADDR_240 0x00000004
47#define MPU_ADDR_MASK 0x00000018
48#define MPU_ADDR_330 0x00000000
49#define MPU_ADDR_300 0x00000008
50#define MPU_ADDR_320 0x00000010
51#define MPU_ADDR_340 0x00000018
52#define USE_PCI_TIMING 0x00000040
53#define POSTED_WRITE_ENABLE 0x00000080
54#define DMA_POLICY_MASK 0x00000700
55#define DMA_DDMA 0x00000000
56#define DMA_TDMA 0x00000100
57#define DMA_PCPCI 0x00000200
58#define DMA_WBDMA16 0x00000400
59#define DMA_WBDMA4 0x00000500
60#define DMA_WBDMA2 0x00000600
61#define DMA_WBDMA1 0x00000700
62#define DMA_SAFE_GUARD 0x00000800
63#define HI_PERF_GP_ENABLE 0x00001000
64#define PIC_SNOOP_MODE_0 0x00002000
65#define PIC_SNOOP_MODE_1 0x00004000
66#define SOUNDBLASTER_IRQ_MASK 0x00008000
67#define RING_IN_ENABLE 0x00010000
68#define SPDIF_TEST_MODE 0x00020000
69#define CLK_MULT_MODE_SELECT_2 0x00040000
70#define EEPROM_WRITE_ENABLE 0x00080000
71#define CODEC_DIR_IN 0x00100000
72#define HV_BUTTON_FROM_GD 0x00200000
73#define REDUCED_DEBOUNCE 0x00400000
74#define HV_CTRL_ENABLE 0x00800000
75#define SPDIF_ENABLE 0x01000000
76#define CLK_DIV_SELECT 0x06000000
77#define CLK_DIV_BY_48 0x00000000
78#define CLK_DIV_BY_49 0x02000000
79#define CLK_DIV_BY_50 0x04000000
80#define CLK_DIV_RESERVED 0x06000000
81#define PM_CTRL_ENABLE 0x08000000
82#define CLK_MULT_MODE_SELECT 0x30000000
83#define CLK_MULT_MODE_SHIFT 28
84#define CLK_MULT_MODE_0 0x00000000
85#define CLK_MULT_MODE_1 0x10000000
86#define CLK_MULT_MODE_2 0x20000000
87#define CLK_MULT_MODE_3 0x30000000
88#define INT_CLK_SELECT 0x40000000
89#define INT_CLK_MULT_RESET 0x80000000
90
91// M3
92#define INT_CLK_SRC_NOT_PCI 0x00100000
93#define INT_CLK_MULT_ENABLE 0x80000000
94
95#define PCI_ACPI_CONTROL 0x54
96#define PCI_ACPI_D0 0x00000000
97#define PCI_ACPI_D1 0xB4F70000
98#define PCI_ACPI_D2 0xB4F7B4F7
99
100#define PCI_USER_CONFIG 0x58
101#define EXT_PCI_MASTER_ENABLE 0x00000001
102#define SPDIF_OUT_SELECT 0x00000002
103#define TEST_PIN_DIR_CTRL 0x00000004
104#define AC97_CODEC_TEST 0x00000020
105#define TRI_STATE_BUFFER 0x00000080
106#define IN_CLK_12MHZ_SELECT 0x00000100
107#define MULTI_FUNC_DISABLE 0x00000200
108#define EXT_MASTER_PAIR_SEL 0x00000400
109#define PCI_MASTER_SUPPORT 0x00000800
110#define STOP_CLOCK_ENABLE 0x00001000
111#define EAPD_DRIVE_ENABLE 0x00002000
112#define REQ_TRI_STATE_ENABLE 0x00004000
113#define REQ_LOW_ENABLE 0x00008000
114#define MIDI_1_ENABLE 0x00010000
115#define MIDI_2_ENABLE 0x00020000
116#define SB_AUDIO_SYNC 0x00040000
117#define HV_CTRL_TEST 0x00100000
118#define SOUNDBLASTER_TEST 0x00400000
119
120#define PCI_USER_CONFIG_C 0x5C
121
122#define PCI_DDMA_CTRL 0x60
123#define DDMA_ENABLE 0x00000001
124
125
126// Allegro registers
127#define HOST_INT_CTRL 0x18
128#define SB_INT_ENABLE 0x0001
129#define MPU401_INT_ENABLE 0x0002
130#define ASSP_INT_ENABLE 0x0010
131#define RING_INT_ENABLE 0x0020
132#define HV_INT_ENABLE 0x0040
133#define CLKRUN_GEN_ENABLE 0x0100
134#define HV_CTRL_TO_PME 0x0400
135#define SOFTWARE_RESET_ENABLE 0x8000
136
137/*
138 * should be using the above defines, probably.
139 */
140#define REGB_ENABLE_RESET 0x01
141#define REGB_STOP_CLOCK 0x10
142
143#define HOST_INT_STATUS 0x1A
144#define SB_INT_PENDING 0x01
145#define MPU401_INT_PENDING 0x02
146#define ASSP_INT_PENDING 0x10
147#define RING_INT_PENDING 0x20
148#define HV_INT_PENDING 0x40
149
150#define HARDWARE_VOL_CTRL 0x1B
151#define SHADOW_MIX_REG_VOICE 0x1C
152#define HW_VOL_COUNTER_VOICE 0x1D
153#define SHADOW_MIX_REG_MASTER 0x1E
154#define HW_VOL_COUNTER_MASTER 0x1F
155
156#define CODEC_COMMAND 0x30
157#define CODEC_READ_B 0x80
158
159#define CODEC_STATUS 0x30
160#define CODEC_BUSY_B 0x01
161
162#define CODEC_DATA 0x32
163
164#define RING_BUS_CTRL_A 0x36
165#define RAC_PME_ENABLE 0x0100
166#define RAC_SDFS_ENABLE 0x0200
167#define LAC_PME_ENABLE 0x0400
168#define LAC_SDFS_ENABLE 0x0800
169#define SERIAL_AC_LINK_ENABLE 0x1000
170#define IO_SRAM_ENABLE 0x2000
171#define IIS_INPUT_ENABLE 0x8000
172
173#define RING_BUS_CTRL_B 0x38
174#define SECOND_CODEC_ID_MASK 0x0003
175#define SPDIF_FUNC_ENABLE 0x0010
176#define SECOND_AC_ENABLE 0x0020
177#define SB_MODULE_INTF_ENABLE 0x0040
178#define SSPE_ENABLE 0x0040
179#define M3I_DOCK_ENABLE 0x0080
180
181#define SDO_OUT_DEST_CTRL 0x3A
182#define COMMAND_ADDR_OUT 0x0003
183#define PCM_LR_OUT_LOCAL 0x0000
184#define PCM_LR_OUT_REMOTE 0x0004
185#define PCM_LR_OUT_MUTE 0x0008
186#define PCM_LR_OUT_BOTH 0x000C
187#define LINE1_DAC_OUT_LOCAL 0x0000
188#define LINE1_DAC_OUT_REMOTE 0x0010
189#define LINE1_DAC_OUT_MUTE 0x0020
190#define LINE1_DAC_OUT_BOTH 0x0030
191#define PCM_CLS_OUT_LOCAL 0x0000
192#define PCM_CLS_OUT_REMOTE 0x0040
193#define PCM_CLS_OUT_MUTE 0x0080
194#define PCM_CLS_OUT_BOTH 0x00C0
195#define PCM_RLF_OUT_LOCAL 0x0000
196#define PCM_RLF_OUT_REMOTE 0x0100
197#define PCM_RLF_OUT_MUTE 0x0200
198#define PCM_RLF_OUT_BOTH 0x0300
199#define LINE2_DAC_OUT_LOCAL 0x0000
200#define LINE2_DAC_OUT_REMOTE 0x0400
201#define LINE2_DAC_OUT_MUTE 0x0800
202#define LINE2_DAC_OUT_BOTH 0x0C00
203#define HANDSET_OUT_LOCAL 0x0000
204#define HANDSET_OUT_REMOTE 0x1000
205#define HANDSET_OUT_MUTE 0x2000
206#define HANDSET_OUT_BOTH 0x3000
207#define IO_CTRL_OUT_LOCAL 0x0000
208#define IO_CTRL_OUT_REMOTE 0x4000
209#define IO_CTRL_OUT_MUTE 0x8000
210#define IO_CTRL_OUT_BOTH 0xC000
211
212#define SDO_IN_DEST_CTRL 0x3C
213#define STATUS_ADDR_IN 0x0003
214#define PCM_LR_IN_LOCAL 0x0000
215#define PCM_LR_IN_REMOTE 0x0004
216#define PCM_LR_RESERVED 0x0008
217#define PCM_LR_IN_BOTH 0x000C
218#define LINE1_ADC_IN_LOCAL 0x0000
219#define LINE1_ADC_IN_REMOTE 0x0010
220#define LINE1_ADC_IN_MUTE 0x0020
221#define MIC_ADC_IN_LOCAL 0x0000
222#define MIC_ADC_IN_REMOTE 0x0040
223#define MIC_ADC_IN_MUTE 0x0080
224#define LINE2_DAC_IN_LOCAL 0x0000
225#define LINE2_DAC_IN_REMOTE 0x0400
226#define LINE2_DAC_IN_MUTE 0x0800
227#define HANDSET_IN_LOCAL 0x0000
228#define HANDSET_IN_REMOTE 0x1000
229#define HANDSET_IN_MUTE 0x2000
230#define IO_STATUS_IN_LOCAL 0x0000
231#define IO_STATUS_IN_REMOTE 0x4000
232
233#define SPDIF_IN_CTRL 0x3E
234#define SPDIF_IN_ENABLE 0x0001
235
236#define GPIO_DATA 0x60
237#define GPIO_DATA_MASK 0x0FFF
238#define GPIO_HV_STATUS 0x3000
239#define GPIO_PME_STATUS 0x4000
240
241#define GPIO_MASK 0x64
242#define GPIO_DIRECTION 0x68
243#define GPO_PRIMARY_AC97 0x0001
244#define GPI_LINEOUT_SENSE 0x0004
245#define GPO_SECONDARY_AC97 0x0008
246#define GPI_VOL_DOWN 0x0010
247#define GPI_VOL_UP 0x0020
248#define GPI_IIS_CLK 0x0040
249#define GPI_IIS_LRCLK 0x0080
250#define GPI_IIS_DATA 0x0100
251#define GPI_DOCKING_STATUS 0x0100
252#define GPI_HEADPHONE_SENSE 0x0200
253#define GPO_EXT_AMP_SHUTDOWN 0x1000
254
255// M3
256#define GPO_M3_EXT_AMP_SHUTDN 0x0002
257
258#define ASSP_INDEX_PORT 0x80
259#define ASSP_MEMORY_PORT 0x82
260#define ASSP_DATA_PORT 0x84
261
262#define MPU401_DATA_PORT 0x98
263#define MPU401_STATUS_PORT 0x99
264
265#define CLK_MULT_DATA_PORT 0x9C
266
267#define ASSP_CONTROL_A 0xA2
268#define ASSP_0_WS_ENABLE 0x01
269#define ASSP_CTRL_A_RESERVED1 0x02
270#define ASSP_CTRL_A_RESERVED2 0x04
271#define ASSP_CLK_49MHZ_SELECT 0x08
272#define FAST_PLU_ENABLE 0x10
273#define ASSP_CTRL_A_RESERVED3 0x20
274#define DSP_CLK_36MHZ_SELECT 0x40
275
276#define ASSP_CONTROL_B 0xA4
277#define RESET_ASSP 0x00
278#define RUN_ASSP 0x01
279#define ENABLE_ASSP_CLOCK 0x00
280#define STOP_ASSP_CLOCK 0x10
281#define RESET_TOGGLE 0x40
282
283#define ASSP_CONTROL_C 0xA6
284#define ASSP_HOST_INT_ENABLE 0x01
285#define FM_ADDR_REMAP_DISABLE 0x02
286#define HOST_WRITE_PORT_ENABLE 0x08
287
288#define ASSP_HOST_INT_STATUS 0xAC
289#define DSP2HOST_REQ_PIORECORD 0x01
290#define DSP2HOST_REQ_I2SRATE 0x02
291#define DSP2HOST_REQ_TIMER 0x04
292
293// AC97 registers
294// XXX fix this crap up
295/*#define AC97_RESET 0x00*/
296
297#define AC97_VOL_MUTE_B 0x8000
298#define AC97_VOL_M 0x1F
299#define AC97_LEFT_VOL_S 8
300
301#define AC97_MASTER_VOL 0x02
302#define AC97_LINE_LEVEL_VOL 0x04
303#define AC97_MASTER_MONO_VOL 0x06
304#define AC97_PC_BEEP_VOL 0x0A
305#define AC97_PC_BEEP_VOL_M 0x0F
306#define AC97_SROUND_MASTER_VOL 0x38
307#define AC97_PC_BEEP_VOL_S 1
308
309/*#define AC97_PHONE_VOL 0x0C
310#define AC97_MIC_VOL 0x0E*/
311#define AC97_MIC_20DB_ENABLE 0x40
312
313/*#define AC97_LINEIN_VOL 0x10
314#define AC97_CD_VOL 0x12
315#define AC97_VIDEO_VOL 0x14
316#define AC97_AUX_VOL 0x16*/
317#define AC97_PCM_OUT_VOL 0x18
318/*#define AC97_RECORD_SELECT 0x1A*/
319#define AC97_RECORD_MIC 0x00
320#define AC97_RECORD_CD 0x01
321#define AC97_RECORD_VIDEO 0x02
322#define AC97_RECORD_AUX 0x03
323#define AC97_RECORD_MONO_MUX 0x02
324#define AC97_RECORD_DIGITAL 0x03
325#define AC97_RECORD_LINE 0x04
326#define AC97_RECORD_STEREO 0x05
327#define AC97_RECORD_MONO 0x06
328#define AC97_RECORD_PHONE 0x07
329
330/*#define AC97_RECORD_GAIN 0x1C*/
331#define AC97_RECORD_VOL_M 0x0F
332
333/*#define AC97_GENERAL_PURPOSE 0x20*/
334#define AC97_POWER_DOWN_CTRL 0x26
335#define AC97_ADC_READY 0x0001
336#define AC97_DAC_READY 0x0002
337#define AC97_ANALOG_READY 0x0004
338#define AC97_VREF_ON 0x0008
339#define AC97_PR0 0x0100
340#define AC97_PR1 0x0200
341#define AC97_PR2 0x0400
342#define AC97_PR3 0x0800
343#define AC97_PR4 0x1000
344
345#define AC97_RESERVED1 0x28
346
347#define AC97_VENDOR_TEST 0x5A
348
349#define AC97_CLOCK_DELAY 0x5C
350#define AC97_LINEOUT_MUX_SEL 0x0001
351#define AC97_MONO_MUX_SEL 0x0002
352#define AC97_CLOCK_DELAY_SEL 0x1F
353#define AC97_DAC_CDS_SHIFT 6
354#define AC97_ADC_CDS_SHIFT 11
355
356#define AC97_MULTI_CHANNEL_SEL 0x74
357
358/*#define AC97_VENDOR_ID1 0x7C
359#define AC97_VENDOR_ID2 0x7E*/
360
361/*
362 * ASSP control regs
363 */
364#define DSP_PORT_TIMER_COUNT 0x06
365
366#define DSP_PORT_MEMORY_INDEX 0x80
367
368#define DSP_PORT_MEMORY_TYPE 0x82
369#define MEMTYPE_INTERNAL_CODE 0x0002
370#define MEMTYPE_INTERNAL_DATA 0x0003
371#define MEMTYPE_MASK 0x0003
372
373#define DSP_PORT_MEMORY_DATA 0x84
374
375#define DSP_PORT_CONTROL_REG_A 0xA2
376#define DSP_PORT_CONTROL_REG_B 0xA4
377#define DSP_PORT_CONTROL_REG_C 0xA6
378
379#define REV_A_CODE_MEMORY_BEGIN 0x0000
380#define REV_A_CODE_MEMORY_END 0x0FFF
381#define REV_A_CODE_MEMORY_UNIT_LENGTH 0x0040
382#define REV_A_CODE_MEMORY_LENGTH (REV_A_CODE_MEMORY_END - REV_A_CODE_MEMORY_BEGIN + 1)
383
384#define REV_B_CODE_MEMORY_BEGIN 0x0000
385#define REV_B_CODE_MEMORY_END 0x0BFF
386#define REV_B_CODE_MEMORY_UNIT_LENGTH 0x0040
387#define REV_B_CODE_MEMORY_LENGTH (REV_B_CODE_MEMORY_END - REV_B_CODE_MEMORY_BEGIN + 1)
388
389#define REV_A_DATA_MEMORY_BEGIN 0x1000
390#define REV_A_DATA_MEMORY_END 0x2FFF
391#define REV_A_DATA_MEMORY_UNIT_LENGTH 0x0080
392#define REV_A_DATA_MEMORY_LENGTH (REV_A_DATA_MEMORY_END - REV_A_DATA_MEMORY_BEGIN + 1)
393
394#define REV_B_DATA_MEMORY_BEGIN 0x1000
395#define REV_B_DATA_MEMORY_END 0x2BFF
396#define REV_B_DATA_MEMORY_UNIT_LENGTH 0x0080
397#define REV_B_DATA_MEMORY_LENGTH (REV_B_DATA_MEMORY_END - REV_B_DATA_MEMORY_BEGIN + 1)
398
399
400#define NUM_UNITS_KERNEL_CODE 16
401#define NUM_UNITS_KERNEL_DATA 2
402
403#define NUM_UNITS_KERNEL_CODE_WITH_HSP 16
404#define NUM_UNITS_KERNEL_DATA_WITH_HSP 5
405
406/*
407 * Kernel data layout
408 */
409
410#define DP_SHIFT_COUNT 7
411
412#define KDATA_BASE_ADDR 0x1000
413#define KDATA_BASE_ADDR2 0x1080
414
415#define KDATA_TASK0 (KDATA_BASE_ADDR + 0x0000)
416#define KDATA_TASK1 (KDATA_BASE_ADDR + 0x0001)
417#define KDATA_TASK2 (KDATA_BASE_ADDR + 0x0002)
418#define KDATA_TASK3 (KDATA_BASE_ADDR + 0x0003)
419#define KDATA_TASK4 (KDATA_BASE_ADDR + 0x0004)
420#define KDATA_TASK5 (KDATA_BASE_ADDR + 0x0005)
421#define KDATA_TASK6 (KDATA_BASE_ADDR + 0x0006)
422#define KDATA_TASK7 (KDATA_BASE_ADDR + 0x0007)
423#define KDATA_TASK_ENDMARK (KDATA_BASE_ADDR + 0x0008)
424
425#define KDATA_CURRENT_TASK (KDATA_BASE_ADDR + 0x0009)
426#define KDATA_TASK_SWITCH (KDATA_BASE_ADDR + 0x000A)
427
428#define KDATA_INSTANCE0_POS3D (KDATA_BASE_ADDR + 0x000B)
429#define KDATA_INSTANCE1_POS3D (KDATA_BASE_ADDR + 0x000C)
430#define KDATA_INSTANCE2_POS3D (KDATA_BASE_ADDR + 0x000D)
431#define KDATA_INSTANCE3_POS3D (KDATA_BASE_ADDR + 0x000E)
432#define KDATA_INSTANCE4_POS3D (KDATA_BASE_ADDR + 0x000F)
433#define KDATA_INSTANCE5_POS3D (KDATA_BASE_ADDR + 0x0010)
434#define KDATA_INSTANCE6_POS3D (KDATA_BASE_ADDR + 0x0011)
435#define KDATA_INSTANCE7_POS3D (KDATA_BASE_ADDR + 0x0012)
436#define KDATA_INSTANCE8_POS3D (KDATA_BASE_ADDR + 0x0013)
437#define KDATA_INSTANCE_POS3D_ENDMARK (KDATA_BASE_ADDR + 0x0014)
438
439#define KDATA_INSTANCE0_SPKVIRT (KDATA_BASE_ADDR + 0x0015)
440#define KDATA_INSTANCE_SPKVIRT_ENDMARK (KDATA_BASE_ADDR + 0x0016)
441
442#define KDATA_INSTANCE0_SPDIF (KDATA_BASE_ADDR + 0x0017)
443#define KDATA_INSTANCE_SPDIF_ENDMARK (KDATA_BASE_ADDR + 0x0018)
444
445#define KDATA_INSTANCE0_MODEM (KDATA_BASE_ADDR + 0x0019)
446#define KDATA_INSTANCE_MODEM_ENDMARK (KDATA_BASE_ADDR + 0x001A)
447
448#define KDATA_INSTANCE0_SRC (KDATA_BASE_ADDR + 0x001B)
449#define KDATA_INSTANCE1_SRC (KDATA_BASE_ADDR + 0x001C)
450#define KDATA_INSTANCE_SRC_ENDMARK (KDATA_BASE_ADDR + 0x001D)
451
452#define KDATA_INSTANCE0_MINISRC (KDATA_BASE_ADDR + 0x001E)
453#define KDATA_INSTANCE1_MINISRC (KDATA_BASE_ADDR + 0x001F)
454#define KDATA_INSTANCE2_MINISRC (KDATA_BASE_ADDR + 0x0020)
455#define KDATA_INSTANCE3_MINISRC (KDATA_BASE_ADDR + 0x0021)
456#define KDATA_INSTANCE_MINISRC_ENDMARK (KDATA_BASE_ADDR + 0x0022)
457
458#define KDATA_INSTANCE0_CPYTHRU (KDATA_BASE_ADDR + 0x0023)
459#define KDATA_INSTANCE1_CPYTHRU (KDATA_BASE_ADDR + 0x0024)
460#define KDATA_INSTANCE_CPYTHRU_ENDMARK (KDATA_BASE_ADDR + 0x0025)
461
462#define KDATA_CURRENT_DMA (KDATA_BASE_ADDR + 0x0026)
463#define KDATA_DMA_SWITCH (KDATA_BASE_ADDR + 0x0027)
464#define KDATA_DMA_ACTIVE (KDATA_BASE_ADDR + 0x0028)
465
466#define KDATA_DMA_XFER0 (KDATA_BASE_ADDR + 0x0029)
467#define KDATA_DMA_XFER1 (KDATA_BASE_ADDR + 0x002A)
468#define KDATA_DMA_XFER2 (KDATA_BASE_ADDR + 0x002B)
469#define KDATA_DMA_XFER3 (KDATA_BASE_ADDR + 0x002C)
470#define KDATA_DMA_XFER4 (KDATA_BASE_ADDR + 0x002D)
471#define KDATA_DMA_XFER5 (KDATA_BASE_ADDR + 0x002E)
472#define KDATA_DMA_XFER6 (KDATA_BASE_ADDR + 0x002F)
473#define KDATA_DMA_XFER7 (KDATA_BASE_ADDR + 0x0030)
474#define KDATA_DMA_XFER8 (KDATA_BASE_ADDR + 0x0031)
475#define KDATA_DMA_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0032)
476
477#define KDATA_I2S_SAMPLE_COUNT (KDATA_BASE_ADDR + 0x0033)
478#define KDATA_I2S_INT_METER (KDATA_BASE_ADDR + 0x0034)
479#define KDATA_I2S_ACTIVE (KDATA_BASE_ADDR + 0x0035)
480
481#define KDATA_TIMER_COUNT_RELOAD (KDATA_BASE_ADDR + 0x0036)
482#define KDATA_TIMER_COUNT_CURRENT (KDATA_BASE_ADDR + 0x0037)
483
484#define KDATA_HALT_SYNCH_CLIENT (KDATA_BASE_ADDR + 0x0038)
485#define KDATA_HALT_SYNCH_DMA (KDATA_BASE_ADDR + 0x0039)
486#define KDATA_HALT_ACKNOWLEDGE (KDATA_BASE_ADDR + 0x003A)
487
488#define KDATA_ADC1_XFER0 (KDATA_BASE_ADDR + 0x003B)
489#define KDATA_ADC1_XFER_ENDMARK (KDATA_BASE_ADDR + 0x003C)
490#define KDATA_ADC1_LEFT_VOLUME (KDATA_BASE_ADDR + 0x003D)
491#define KDATA_ADC1_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x003E)
492#define KDATA_ADC1_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x003F)
493#define KDATA_ADC1_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x0040)
494
495#define KDATA_ADC2_XFER0 (KDATA_BASE_ADDR + 0x0041)
496#define KDATA_ADC2_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0042)
497#define KDATA_ADC2_LEFT_VOLUME (KDATA_BASE_ADDR + 0x0043)
498#define KDATA_ADC2_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x0044)
499#define KDATA_ADC2_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x0045)
500#define KDATA_ADC2_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x0046)
501
502#define KDATA_CD_XFER0 (KDATA_BASE_ADDR + 0x0047)
503#define KDATA_CD_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0048)
504#define KDATA_CD_LEFT_VOLUME (KDATA_BASE_ADDR + 0x0049)
505#define KDATA_CD_RIGHT_VOLUME (KDATA_BASE_ADDR + 0x004A)
506#define KDATA_CD_LEFT_SUR_VOL (KDATA_BASE_ADDR + 0x004B)
507#define KDATA_CD_RIGHT_SUR_VOL (KDATA_BASE_ADDR + 0x004C)
508
509#define KDATA_MIC_XFER0 (KDATA_BASE_ADDR + 0x004D)
510#define KDATA_MIC_XFER_ENDMARK (KDATA_BASE_ADDR + 0x004E)
511#define KDATA_MIC_VOLUME (KDATA_BASE_ADDR + 0x004F)
512#define KDATA_MIC_SUR_VOL (KDATA_BASE_ADDR + 0x0050)
513
514#define KDATA_I2S_XFER0 (KDATA_BASE_ADDR + 0x0051)
515#define KDATA_I2S_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0052)
516
517#define KDATA_CHI_XFER0 (KDATA_BASE_ADDR + 0x0053)
518#define KDATA_CHI_XFER_ENDMARK (KDATA_BASE_ADDR + 0x0054)
519
520#define KDATA_SPDIF_XFER (KDATA_BASE_ADDR + 0x0055)
521#define KDATA_SPDIF_CURRENT_FRAME (KDATA_BASE_ADDR + 0x0056)
522#define KDATA_SPDIF_FRAME0 (KDATA_BASE_ADDR + 0x0057)
523#define KDATA_SPDIF_FRAME1 (KDATA_BASE_ADDR + 0x0058)
524#define KDATA_SPDIF_FRAME2 (KDATA_BASE_ADDR + 0x0059)
525
526#define KDATA_SPDIF_REQUEST (KDATA_BASE_ADDR + 0x005A)
527#define KDATA_SPDIF_TEMP (KDATA_BASE_ADDR + 0x005B)
528
529#define KDATA_SPDIFIN_XFER0 (KDATA_BASE_ADDR + 0x005C)
530#define KDATA_SPDIFIN_XFER_ENDMARK (KDATA_BASE_ADDR + 0x005D)
531#define KDATA_SPDIFIN_INT_METER (KDATA_BASE_ADDR + 0x005E)
532
533#define KDATA_DSP_RESET_COUNT (KDATA_BASE_ADDR + 0x005F)
534#define KDATA_DEBUG_OUTPUT (KDATA_BASE_ADDR + 0x0060)
535
536#define KDATA_KERNEL_ISR_LIST (KDATA_BASE_ADDR + 0x0061)
537
538#define KDATA_KERNEL_ISR_CBSR1 (KDATA_BASE_ADDR + 0x0062)
539#define KDATA_KERNEL_ISR_CBER1 (KDATA_BASE_ADDR + 0x0063)
540#define KDATA_KERNEL_ISR_CBCR (KDATA_BASE_ADDR + 0x0064)
541#define KDATA_KERNEL_ISR_AR0 (KDATA_BASE_ADDR + 0x0065)
542#define KDATA_KERNEL_ISR_AR1 (KDATA_BASE_ADDR + 0x0066)
543#define KDATA_KERNEL_ISR_AR2 (KDATA_BASE_ADDR + 0x0067)
544#define KDATA_KERNEL_ISR_AR3 (KDATA_BASE_ADDR + 0x0068)
545#define KDATA_KERNEL_ISR_AR4 (KDATA_BASE_ADDR + 0x0069)
546#define KDATA_KERNEL_ISR_AR5 (KDATA_BASE_ADDR + 0x006A)
547#define KDATA_KERNEL_ISR_BRCR (KDATA_BASE_ADDR + 0x006B)
548#define KDATA_KERNEL_ISR_PASR (KDATA_BASE_ADDR + 0x006C)
549#define KDATA_KERNEL_ISR_PAER (KDATA_BASE_ADDR + 0x006D)
550
551#define KDATA_CLIENT_SCRATCH0 (KDATA_BASE_ADDR + 0x006E)
552#define KDATA_CLIENT_SCRATCH1 (KDATA_BASE_ADDR + 0x006F)
553#define KDATA_KERNEL_SCRATCH (KDATA_BASE_ADDR + 0x0070)
554#define KDATA_KERNEL_ISR_SCRATCH (KDATA_BASE_ADDR + 0x0071)
555
556#define KDATA_OUEUE_LEFT (KDATA_BASE_ADDR + 0x0072)
557#define KDATA_QUEUE_RIGHT (KDATA_BASE_ADDR + 0x0073)
558
559#define KDATA_ADC1_REQUEST (KDATA_BASE_ADDR + 0x0074)
560#define KDATA_ADC2_REQUEST (KDATA_BASE_ADDR + 0x0075)
561#define KDATA_CD_REQUEST (KDATA_BASE_ADDR + 0x0076)
562#define KDATA_MIC_REQUEST (KDATA_BASE_ADDR + 0x0077)
563
564#define KDATA_ADC1_MIXER_REQUEST (KDATA_BASE_ADDR + 0x0078)
565#define KDATA_ADC2_MIXER_REQUEST (KDATA_BASE_ADDR + 0x0079)
566#define KDATA_CD_MIXER_REQUEST (KDATA_BASE_ADDR + 0x007A)
567#define KDATA_MIC_MIXER_REQUEST (KDATA_BASE_ADDR + 0x007B)
568#define KDATA_MIC_SYNC_COUNTER (KDATA_BASE_ADDR + 0x007C)
569
570/*
571 * second 'segment' (?) reserved for mixer
572 * buffers..
573 */
574
575#define KDATA_MIXER_WORD0 (KDATA_BASE_ADDR2 + 0x0000)
576#define KDATA_MIXER_WORD1 (KDATA_BASE_ADDR2 + 0x0001)
577#define KDATA_MIXER_WORD2 (KDATA_BASE_ADDR2 + 0x0002)
578#define KDATA_MIXER_WORD3 (KDATA_BASE_ADDR2 + 0x0003)
579#define KDATA_MIXER_WORD4 (KDATA_BASE_ADDR2 + 0x0004)
580#define KDATA_MIXER_WORD5 (KDATA_BASE_ADDR2 + 0x0005)
581#define KDATA_MIXER_WORD6 (KDATA_BASE_ADDR2 + 0x0006)
582#define KDATA_MIXER_WORD7 (KDATA_BASE_ADDR2 + 0x0007)
583#define KDATA_MIXER_WORD8 (KDATA_BASE_ADDR2 + 0x0008)
584#define KDATA_MIXER_WORD9 (KDATA_BASE_ADDR2 + 0x0009)
585#define KDATA_MIXER_WORDA (KDATA_BASE_ADDR2 + 0x000A)
586#define KDATA_MIXER_WORDB (KDATA_BASE_ADDR2 + 0x000B)
587#define KDATA_MIXER_WORDC (KDATA_BASE_ADDR2 + 0x000C)
588#define KDATA_MIXER_WORDD (KDATA_BASE_ADDR2 + 0x000D)
589#define KDATA_MIXER_WORDE (KDATA_BASE_ADDR2 + 0x000E)
590#define KDATA_MIXER_WORDF (KDATA_BASE_ADDR2 + 0x000F)
591
592#define KDATA_MIXER_XFER0 (KDATA_BASE_ADDR2 + 0x0010)
593#define KDATA_MIXER_XFER1 (KDATA_BASE_ADDR2 + 0x0011)
594#define KDATA_MIXER_XFER2 (KDATA_BASE_ADDR2 + 0x0012)
595#define KDATA_MIXER_XFER3 (KDATA_BASE_ADDR2 + 0x0013)
596#define KDATA_MIXER_XFER4 (KDATA_BASE_ADDR2 + 0x0014)
597#define KDATA_MIXER_XFER5 (KDATA_BASE_ADDR2 + 0x0015)
598#define KDATA_MIXER_XFER6 (KDATA_BASE_ADDR2 + 0x0016)
599#define KDATA_MIXER_XFER7 (KDATA_BASE_ADDR2 + 0x0017)
600#define KDATA_MIXER_XFER8 (KDATA_BASE_ADDR2 + 0x0018)
601#define KDATA_MIXER_XFER9 (KDATA_BASE_ADDR2 + 0x0019)
602#define KDATA_MIXER_XFER_ENDMARK (KDATA_BASE_ADDR2 + 0x001A)
603
604#define KDATA_MIXER_TASK_NUMBER (KDATA_BASE_ADDR2 + 0x001B)
605#define KDATA_CURRENT_MIXER (KDATA_BASE_ADDR2 + 0x001C)
606#define KDATA_MIXER_ACTIVE (KDATA_BASE_ADDR2 + 0x001D)
607#define KDATA_MIXER_BANK_STATUS (KDATA_BASE_ADDR2 + 0x001E)
608#define KDATA_DAC_LEFT_VOLUME (KDATA_BASE_ADDR2 + 0x001F)
609#define KDATA_DAC_RIGHT_VOLUME (KDATA_BASE_ADDR2 + 0x0020)
610
611#define MAX_INSTANCE_MINISRC (KDATA_INSTANCE_MINISRC_ENDMARK - KDATA_INSTANCE0_MINISRC)
612#define MAX_VIRTUAL_DMA_CHANNELS (KDATA_DMA_XFER_ENDMARK - KDATA_DMA_XFER0)
613#define MAX_VIRTUAL_MIXER_CHANNELS (KDATA_MIXER_XFER_ENDMARK - KDATA_MIXER_XFER0)
614#define MAX_VIRTUAL_ADC1_CHANNELS (KDATA_ADC1_XFER_ENDMARK - KDATA_ADC1_XFER0)
615
616/*
617 * client data area offsets
618 */
619#define CDATA_INSTANCE_READY 0x00
620
621#define CDATA_HOST_SRC_ADDRL 0x01
622#define CDATA_HOST_SRC_ADDRH 0x02
623#define CDATA_HOST_SRC_END_PLUS_1L 0x03
624#define CDATA_HOST_SRC_END_PLUS_1H 0x04
625#define CDATA_HOST_SRC_CURRENTL 0x05
626#define CDATA_HOST_SRC_CURRENTH 0x06
627
628#define CDATA_IN_BUF_CONNECT 0x07
629#define CDATA_OUT_BUF_CONNECT 0x08
630
631#define CDATA_IN_BUF_BEGIN 0x09
632#define CDATA_IN_BUF_END_PLUS_1 0x0A
633#define CDATA_IN_BUF_HEAD 0x0B
634#define CDATA_IN_BUF_TAIL 0x0C
635#define CDATA_OUT_BUF_BEGIN 0x0D
636#define CDATA_OUT_BUF_END_PLUS_1 0x0E
637#define CDATA_OUT_BUF_HEAD 0x0F
638#define CDATA_OUT_BUF_TAIL 0x10
639
640#define CDATA_DMA_CONTROL 0x11
641#define CDATA_RESERVED 0x12
642
643#define CDATA_FREQUENCY 0x13
644#define CDATA_LEFT_VOLUME 0x14
645#define CDATA_RIGHT_VOLUME 0x15
646#define CDATA_LEFT_SUR_VOL 0x16
647#define CDATA_RIGHT_SUR_VOL 0x17
648
649#define CDATA_HEADER_LEN 0x18
650
651#define SRC3_DIRECTION_OFFSET CDATA_HEADER_LEN
652#define SRC3_MODE_OFFSET (CDATA_HEADER_LEN + 1)
653#define SRC3_WORD_LENGTH_OFFSET (CDATA_HEADER_LEN + 2)
654#define SRC3_PARAMETER_OFFSET (CDATA_HEADER_LEN + 3)
655#define SRC3_COEFF_ADDR_OFFSET (CDATA_HEADER_LEN + 8)
656#define SRC3_FILTAP_ADDR_OFFSET (CDATA_HEADER_LEN + 10)
657#define SRC3_TEMP_INBUF_ADDR_OFFSET (CDATA_HEADER_LEN + 16)
658#define SRC3_TEMP_OUTBUF_ADDR_OFFSET (CDATA_HEADER_LEN + 17)
659
660#define MINISRC_IN_BUFFER_SIZE ( 0x50 * 2 )
661#define MINISRC_OUT_BUFFER_SIZE ( 0x50 * 2 * 2)
662#define MINISRC_OUT_BUFFER_SIZE ( 0x50 * 2 * 2)
663#define MINISRC_TMP_BUFFER_SIZE ( 112 + ( MINISRC_BIQUAD_STAGE * 3 + 4 ) * 2 * 2 )
664#define MINISRC_BIQUAD_STAGE 2
665#define MINISRC_COEF_LOC 0X175
666
667#define DMACONTROL_BLOCK_MASK 0x000F
668#define DMAC_BLOCK0_SELECTOR 0x0000
669#define DMAC_BLOCK1_SELECTOR 0x0001
670#define DMAC_BLOCK2_SELECTOR 0x0002
671#define DMAC_BLOCK3_SELECTOR 0x0003
672#define DMAC_BLOCK4_SELECTOR 0x0004
673#define DMAC_BLOCK5_SELECTOR 0x0005
674#define DMAC_BLOCK6_SELECTOR 0x0006
675#define DMAC_BLOCK7_SELECTOR 0x0007
676#define DMAC_BLOCK8_SELECTOR 0x0008
677#define DMAC_BLOCK9_SELECTOR 0x0009
678#define DMAC_BLOCKA_SELECTOR 0x000A
679#define DMAC_BLOCKB_SELECTOR 0x000B
680#define DMAC_BLOCKC_SELECTOR 0x000C
681#define DMAC_BLOCKD_SELECTOR 0x000D
682#define DMAC_BLOCKE_SELECTOR 0x000E
683#define DMAC_BLOCKF_SELECTOR 0x000F
684#define DMACONTROL_PAGE_MASK 0x00F0
685#define DMAC_PAGE0_SELECTOR 0x0030
686#define DMAC_PAGE1_SELECTOR 0x0020
687#define DMAC_PAGE2_SELECTOR 0x0010
688#define DMAC_PAGE3_SELECTOR 0x0000
689#define DMACONTROL_AUTOREPEAT 0x1000
690#define DMACONTROL_STOPPED 0x2000
691#define DMACONTROL_DIRECTION 0x0100
692
693
694/*
695 * DSP Code images
696 */
697
698static u16 assp_kernel_image[] = {
699 0x7980, 0x0030, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x00FB, 0x7980, 0x00DD, 0x7980, 0x03B4,
700 0x7980, 0x0332, 0x7980, 0x0287, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4,
701 0x7980, 0x031A, 0x7980, 0x03B4, 0x7980, 0x022F, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4,
702 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x0063, 0x7980, 0x006B, 0x7980, 0x03B4, 0x7980, 0x03B4,
703 0xBF80, 0x2C7C, 0x8806, 0x8804, 0xBE40, 0xBC20, 0xAE09, 0x1000, 0xAE0A, 0x0001, 0x6938, 0xEB08,
704 0x0053, 0x695A, 0xEB08, 0x00D6, 0x0009, 0x8B88, 0x6980, 0xE388, 0x0036, 0xBE30, 0xBC20, 0x6909,
705 0xB801, 0x9009, 0xBE41, 0xBE41, 0x6928, 0xEB88, 0x0078, 0xBE41, 0xBE40, 0x7980, 0x0038, 0xBE41,
706 0xBE41, 0x903A, 0x6938, 0xE308, 0x0056, 0x903A, 0xBE41, 0xBE40, 0xEF00, 0x903A, 0x6939, 0xE308,
707 0x005E, 0x903A, 0xEF00, 0x690B, 0x660C, 0xEF8C, 0x690A, 0x660C, 0x620B, 0x6609, 0xEF00, 0x6910,
708 0x660F, 0xEF04, 0xE388, 0x0075, 0x690E, 0x660F, 0x6210, 0x660D, 0xEF00, 0x690E, 0x660D, 0xEF00,
709 0xAE70, 0x0001, 0xBC20, 0xAE27, 0x0001, 0x6939, 0xEB08, 0x005D, 0x6926, 0xB801, 0x9026, 0x0026,
710 0x8B88, 0x6980, 0xE388, 0x00CB, 0x9028, 0x0D28, 0x4211, 0xE100, 0x007A, 0x4711, 0xE100, 0x00A0,
711 0x7A80, 0x0063, 0xB811, 0x660A, 0x6209, 0xE304, 0x007A, 0x0C0B, 0x4005, 0x100A, 0xBA01, 0x9012,
712 0x0C12, 0x4002, 0x7980, 0x00AF, 0x7A80, 0x006B, 0xBE02, 0x620E, 0x660D, 0xBA10, 0xE344, 0x007A,
713 0x0C10, 0x4005, 0x100E, 0xBA01, 0x9012, 0x0C12, 0x4002, 0x1003, 0xBA02, 0x9012, 0x0C12, 0x4000,
714 0x1003, 0xE388, 0x00BA, 0x1004, 0x7980, 0x00BC, 0x1004, 0xBA01, 0x9012, 0x0C12, 0x4001, 0x0C05,
715 0x4003, 0x0C06, 0x4004, 0x1011, 0xBFB0, 0x01FF, 0x9012, 0x0C12, 0x4006, 0xBC20, 0xEF00, 0xAE26,
716 0x1028, 0x6970, 0xBFD0, 0x0001, 0x9070, 0xE388, 0x007A, 0xAE28, 0x0000, 0xEF00, 0xAE70, 0x0300,
717 0x0C70, 0xB00C, 0xAE5A, 0x0000, 0xEF00, 0x7A80, 0x038A, 0x697F, 0xB801, 0x907F, 0x0056, 0x8B88,
718 0x0CA0, 0xB008, 0xAF71, 0xB000, 0x4E71, 0xE200, 0x00F3, 0xAE56, 0x1057, 0x0056, 0x0CA0, 0xB008,
719 0x8056, 0x7980, 0x03A1, 0x0810, 0xBFA0, 0x1059, 0xE304, 0x03A1, 0x8056, 0x7980, 0x03A1, 0x7A80,
720 0x038A, 0xBF01, 0xBE43, 0xBE59, 0x907C, 0x6937, 0xE388, 0x010D, 0xBA01, 0xE308, 0x010C, 0xAE71,
721 0x0004, 0x0C71, 0x5000, 0x6936, 0x9037, 0xBF0A, 0x109E, 0x8B8A, 0xAF80, 0x8014, 0x4C80, 0xBF0A,
722 0x0560, 0xF500, 0xBF0A, 0x0520, 0xB900, 0xBB17, 0x90A0, 0x6917, 0xE388, 0x0148, 0x0D17, 0xE100,
723 0x0127, 0xBF0C, 0x0578, 0xBF0D, 0x057C, 0x7980, 0x012B, 0xBF0C, 0x0538, 0xBF0D, 0x053C, 0x6900,
724 0xE308, 0x0135, 0x8B8C, 0xBE59, 0xBB07, 0x90A0, 0xBC20, 0x7980, 0x0157, 0x030C, 0x8B8B, 0xB903,
725 0x8809, 0xBEC6, 0x013E, 0x69AC, 0x90AB, 0x69AD, 0x90AB, 0x0813, 0x660A, 0xE344, 0x0144, 0x0309,
726 0x830C, 0xBC20, 0x7980, 0x0157, 0x6955, 0xE388, 0x0157, 0x7C38, 0xBF0B, 0x0578, 0xF500, 0xBF0B,
727 0x0538, 0xB907, 0x8809, 0xBEC6, 0x0156, 0x10AB, 0x90AA, 0x6974, 0xE388, 0x0163, 0xAE72, 0x0540,
728 0xF500, 0xAE72, 0x0500, 0xAE61, 0x103B, 0x7A80, 0x02F6, 0x6978, 0xE388, 0x0182, 0x8B8C, 0xBF0C,
729 0x0560, 0xE500, 0x7C40, 0x0814, 0xBA20, 0x8812, 0x733D, 0x7A80, 0x0380, 0x733E, 0x7A80, 0x0380,
730 0x8B8C, 0xBF0C, 0x056C, 0xE500, 0x7C40, 0x0814, 0xBA2C, 0x8812, 0x733F, 0x7A80, 0x0380, 0x7340,
731 0x7A80, 0x0380, 0x6975, 0xE388, 0x018E, 0xAE72, 0x0548, 0xF500, 0xAE72, 0x0508, 0xAE61, 0x1041,
732 0x7A80, 0x02F6, 0x6979, 0xE388, 0x01AD, 0x8B8C, 0xBF0C, 0x0560, 0xE500, 0x7C40, 0x0814, 0xBA18,
733 0x8812, 0x7343, 0x7A80, 0x0380, 0x7344, 0x7A80, 0x0380, 0x8B8C, 0xBF0C, 0x056C, 0xE500, 0x7C40,
734 0x0814, 0xBA24, 0x8812, 0x7345, 0x7A80, 0x0380, 0x7346, 0x7A80, 0x0380, 0x6976, 0xE388, 0x01B9,
735 0xAE72, 0x0558, 0xF500, 0xAE72, 0x0518, 0xAE61, 0x1047, 0x7A80, 0x02F6, 0x697A, 0xE388, 0x01D8,
736 0x8B8C, 0xBF0C, 0x0560, 0xE500, 0x7C40, 0x0814, 0xBA08, 0x8812, 0x7349, 0x7A80, 0x0380, 0x734A,
737 0x7A80, 0x0380, 0x8B8C, 0xBF0C, 0x056C, 0xE500, 0x7C40, 0x0814, 0xBA14, 0x8812, 0x734B, 0x7A80,
738 0x0380, 0x734C, 0x7A80, 0x0380, 0xBC21, 0xAE1C, 0x1090, 0x8B8A, 0xBF0A, 0x0560, 0xE500, 0x7C40,
739 0x0812, 0xB804, 0x8813, 0x8B8D, 0xBF0D, 0x056C, 0xE500, 0x7C40, 0x0815, 0xB804, 0x8811, 0x7A80,
740 0x034A, 0x8B8A, 0xBF0A, 0x0560, 0xE500, 0x7C40, 0x731F, 0xB903, 0x8809, 0xBEC6, 0x01F9, 0x548A,
741 0xBE03, 0x98A0, 0x7320, 0xB903, 0x8809, 0xBEC6, 0x0201, 0x548A, 0xBE03, 0x98A0, 0x1F20, 0x2F1F,
742 0x9826, 0xBC20, 0x6935, 0xE388, 0x03A1, 0x6933, 0xB801, 0x9033, 0xBFA0, 0x02EE, 0xE308, 0x03A1,
743 0x9033, 0xBF00, 0x6951, 0xE388, 0x021F, 0x7334, 0xBE80, 0x5760, 0xBE03, 0x9F7E, 0xBE59, 0x9034,
744 0x697E, 0x0D51, 0x9013, 0xBC20, 0x695C, 0xE388, 0x03A1, 0x735E, 0xBE80, 0x5760, 0xBE03, 0x9F7E,
745 0xBE59, 0x905E, 0x697E, 0x0D5C, 0x9013, 0x7980, 0x03A1, 0x7A80, 0x038A, 0xBF01, 0xBE43, 0x6977,
746 0xE388, 0x024E, 0xAE61, 0x104D, 0x0061, 0x8B88, 0x6980, 0xE388, 0x024E, 0x9071, 0x0D71, 0x000B,
747 0xAFA0, 0x8010, 0xAFA0, 0x8010, 0x0810, 0x660A, 0xE308, 0x0249, 0x0009, 0x0810, 0x660C, 0xE388,
748 0x024E, 0x800B, 0xBC20, 0x697B, 0xE388, 0x03A1, 0xBF0A, 0x109E, 0x8B8A, 0xAF80, 0x8014, 0x4C80,
749 0xE100, 0x0266, 0x697C, 0xBF90, 0x0560, 0x9072, 0x0372, 0x697C, 0xBF90, 0x0564, 0x9073, 0x0473,
750 0x7980, 0x0270, 0x697C, 0xBF90, 0x0520, 0x9072, 0x0372, 0x697C, 0xBF90, 0x0524, 0x9073, 0x0473,
751 0x697C, 0xB801, 0x907C, 0xBF0A, 0x10FD, 0x8B8A, 0xAF80, 0x8010, 0x734F, 0x548A, 0xBE03, 0x9880,
752 0xBC21, 0x7326, 0x548B, 0xBE03, 0x618B, 0x988C, 0xBE03, 0x6180, 0x9880, 0x7980, 0x03A1, 0x7A80,
753 0x038A, 0x0D28, 0x4711, 0xE100, 0x02BE, 0xAF12, 0x4006, 0x6912, 0xBFB0, 0x0C00, 0xE388, 0x02B6,
754 0xBFA0, 0x0800, 0xE388, 0x02B2, 0x6912, 0xBFB0, 0x0C00, 0xBFA0, 0x0400, 0xE388, 0x02A3, 0x6909,
755 0x900B, 0x7980, 0x02A5, 0xAF0B, 0x4005, 0x6901, 0x9005, 0x6902, 0x9006, 0x4311, 0xE100, 0x02ED,
756 0x6911, 0xBFC0, 0x2000, 0x9011, 0x7980, 0x02ED, 0x6909, 0x900B, 0x7980, 0x02B8, 0xAF0B, 0x4005,
757 0xAF05, 0x4003, 0xAF06, 0x4004, 0x7980, 0x02ED, 0xAF12, 0x4006, 0x6912, 0xBFB0, 0x0C00, 0xE388,
758 0x02E7, 0xBFA0, 0x0800, 0xE388, 0x02E3, 0x6912, 0xBFB0, 0x0C00, 0xBFA0, 0x0400, 0xE388, 0x02D4,
759 0x690D, 0x9010, 0x7980, 0x02D6, 0xAF10, 0x4005, 0x6901, 0x9005, 0x6902, 0x9006, 0x4311, 0xE100,
760 0x02ED, 0x6911, 0xBFC0, 0x2000, 0x9011, 0x7980, 0x02ED, 0x690D, 0x9010, 0x7980, 0x02E9, 0xAF10,
761 0x4005, 0xAF05, 0x4003, 0xAF06, 0x4004, 0xBC20, 0x6970, 0x9071, 0x7A80, 0x0078, 0x6971, 0x9070,
762 0x7980, 0x03A1, 0xBC20, 0x0361, 0x8B8B, 0x6980, 0xEF88, 0x0272, 0x0372, 0x7804, 0x9071, 0x0D71,
763 0x8B8A, 0x000B, 0xB903, 0x8809, 0xBEC6, 0x0309, 0x69A8, 0x90AB, 0x69A8, 0x90AA, 0x0810, 0x660A,
764 0xE344, 0x030F, 0x0009, 0x0810, 0x660C, 0xE388, 0x0314, 0x800B, 0xBC20, 0x6961, 0xB801, 0x9061,
765 0x7980, 0x02F7, 0x7A80, 0x038A, 0x5D35, 0x0001, 0x6934, 0xB801, 0x9034, 0xBF0A, 0x109E, 0x8B8A,
766 0xAF80, 0x8014, 0x4880, 0xAE72, 0x0550, 0xF500, 0xAE72, 0x0510, 0xAE61, 0x1051, 0x7A80, 0x02F6,
767 0x7980, 0x03A1, 0x7A80, 0x038A, 0x5D35, 0x0002, 0x695E, 0xB801, 0x905E, 0xBF0A, 0x109E, 0x8B8A,
768 0xAF80, 0x8014, 0x4780, 0xAE72, 0x0558, 0xF500, 0xAE72, 0x0518, 0xAE61, 0x105C, 0x7A80, 0x02F6,
769 0x7980, 0x03A1, 0x001C, 0x8B88, 0x6980, 0xEF88, 0x901D, 0x0D1D, 0x100F, 0x6610, 0xE38C, 0x0358,
770 0x690E, 0x6610, 0x620F, 0x660D, 0xBA0F, 0xE301, 0x037A, 0x0410, 0x8B8A, 0xB903, 0x8809, 0xBEC6,
771 0x036C, 0x6A8C, 0x61AA, 0x98AB, 0x6A8C, 0x61AB, 0x98AD, 0x6A8C, 0x61AD, 0x98A9, 0x6A8C, 0x61A9,
772 0x98AA, 0x7C04, 0x8B8B, 0x7C04, 0x8B8D, 0x7C04, 0x8B89, 0x7C04, 0x0814, 0x660E, 0xE308, 0x0379,
773 0x040D, 0x8410, 0xBC21, 0x691C, 0xB801, 0x901C, 0x7980, 0x034A, 0xB903, 0x8809, 0x8B8A, 0xBEC6,
774 0x0388, 0x54AC, 0xBE03, 0x618C, 0x98AA, 0xEF00, 0xBC20, 0xBE46, 0x0809, 0x906B, 0x080A, 0x906C,
775 0x080B, 0x906D, 0x081A, 0x9062, 0x081B, 0x9063, 0x081E, 0x9064, 0xBE59, 0x881E, 0x8065, 0x8166,
776 0x8267, 0x8368, 0x8469, 0x856A, 0xEF00, 0xBC20, 0x696B, 0x8809, 0x696C, 0x880A, 0x696D, 0x880B,
777 0x6962, 0x881A, 0x6963, 0x881B, 0x6964, 0x881E, 0x0065, 0x0166, 0x0267, 0x0368, 0x0469, 0x056A,
778 0xBE3A,
779};
780
781/*
782 * Mini sample rate converter code image
783 * that is to be loaded at 0x400 on the DSP.
784 */
785static u16 assp_minisrc_image[] = {
786
787 0xBF80, 0x101E, 0x906E, 0x006E, 0x8B88, 0x6980, 0xEF88, 0x906F, 0x0D6F, 0x6900, 0xEB08, 0x0412,
788 0xBC20, 0x696E, 0xB801, 0x906E, 0x7980, 0x0403, 0xB90E, 0x8807, 0xBE43, 0xBF01, 0xBE47, 0xBE41,
789 0x7A80, 0x002A, 0xBE40, 0x3029, 0xEFCC, 0xBE41, 0x7A80, 0x0028, 0xBE40, 0x3028, 0xEFCC, 0x6907,
790 0xE308, 0x042A, 0x6909, 0x902C, 0x7980, 0x042C, 0x690D, 0x902C, 0x1009, 0x881A, 0x100A, 0xBA01,
791 0x881B, 0x100D, 0x881C, 0x100E, 0xBA01, 0x881D, 0xBF80, 0x00ED, 0x881E, 0x050C, 0x0124, 0xB904,
792 0x9027, 0x6918, 0xE308, 0x04B3, 0x902D, 0x6913, 0xBFA0, 0x7598, 0xF704, 0xAE2D, 0x00FF, 0x8B8D,
793 0x6919, 0xE308, 0x0463, 0x691A, 0xE308, 0x0456, 0xB907, 0x8809, 0xBEC6, 0x0453, 0x10A9, 0x90AD,
794 0x7980, 0x047C, 0xB903, 0x8809, 0xBEC6, 0x0460, 0x1889, 0x6C22, 0x90AD, 0x10A9, 0x6E23, 0x6C22,
795 0x90AD, 0x7980, 0x047C, 0x101A, 0xE308, 0x046F, 0xB903, 0x8809, 0xBEC6, 0x046C, 0x10A9, 0x90A0,
796 0x90AD, 0x7980, 0x047C, 0xB901, 0x8809, 0xBEC6, 0x047B, 0x1889, 0x6C22, 0x90A0, 0x90AD, 0x10A9,
797 0x6E23, 0x6C22, 0x90A0, 0x90AD, 0x692D, 0xE308, 0x049C, 0x0124, 0xB703, 0xB902, 0x8818, 0x8B89,
798 0x022C, 0x108A, 0x7C04, 0x90A0, 0x692B, 0x881F, 0x7E80, 0x055B, 0x692A, 0x8809, 0x8B89, 0x99A0,
799 0x108A, 0x90A0, 0x692B, 0x881F, 0x7E80, 0x055B, 0x692A, 0x8809, 0x8B89, 0x99AF, 0x7B99, 0x0484,
800 0x0124, 0x060F, 0x101B, 0x2013, 0x901B, 0xBFA0, 0x7FFF, 0xE344, 0x04AC, 0x901B, 0x8B89, 0x7A80,
801 0x051A, 0x6927, 0xBA01, 0x9027, 0x7A80, 0x0523, 0x6927, 0xE308, 0x049E, 0x7980, 0x050F, 0x0624,
802 0x1026, 0x2013, 0x9026, 0xBFA0, 0x7FFF, 0xE304, 0x04C0, 0x8B8D, 0x7A80, 0x051A, 0x7980, 0x04B4,
803 0x9026, 0x1013, 0x3026, 0x901B, 0x8B8D, 0x7A80, 0x051A, 0x7A80, 0x0523, 0x1027, 0xBA01, 0x9027,
804 0xE308, 0x04B4, 0x0124, 0x060F, 0x8B89, 0x691A, 0xE308, 0x04EA, 0x6919, 0xE388, 0x04E0, 0xB903,
805 0x8809, 0xBEC6, 0x04DD, 0x1FA0, 0x2FAE, 0x98A9, 0x7980, 0x050F, 0xB901, 0x8818, 0xB907, 0x8809,
806 0xBEC6, 0x04E7, 0x10EE, 0x90A9, 0x7980, 0x050F, 0x6919, 0xE308, 0x04FE, 0xB903, 0x8809, 0xBE46,
807 0xBEC6, 0x04FA, 0x17A0, 0xBE1E, 0x1FAE, 0xBFBF, 0xFF00, 0xBE13, 0xBFDF, 0x8080, 0x99A9, 0xBE47,
808 0x7980, 0x050F, 0xB901, 0x8809, 0xBEC6, 0x050E, 0x16A0, 0x26A0, 0xBFB7, 0xFF00, 0xBE1E, 0x1EA0,
809 0x2EAE, 0xBFBF, 0xFF00, 0xBE13, 0xBFDF, 0x8080, 0x99A9, 0x850C, 0x860F, 0x6907, 0xE388, 0x0516,
810 0x0D07, 0x8510, 0xBE59, 0x881E, 0xBE4A, 0xEF00, 0x101E, 0x901C, 0x101F, 0x901D, 0x10A0, 0x901E,
811 0x10A0, 0x901F, 0xEF00, 0x101E, 0x301C, 0x9020, 0x731B, 0x5420, 0xBE03, 0x9825, 0x1025, 0x201C,
812 0x9025, 0x7325, 0x5414, 0xBE03, 0x8B8E, 0x9880, 0x692F, 0xE388, 0x0539, 0xBE59, 0xBB07, 0x6180,
813 0x9880, 0x8BA0, 0x101F, 0x301D, 0x9021, 0x731B, 0x5421, 0xBE03, 0x982E, 0x102E, 0x201D, 0x902E,
814 0x732E, 0x5415, 0xBE03, 0x9880, 0x692F, 0xE388, 0x054F, 0xBE59, 0xBB07, 0x6180, 0x9880, 0x8BA0,
815 0x6918, 0xEF08, 0x7325, 0x5416, 0xBE03, 0x98A0, 0x732E, 0x5417, 0xBE03, 0x98A0, 0xEF00, 0x8BA0,
816 0xBEC6, 0x056B, 0xBE59, 0xBB04, 0xAA90, 0xBE04, 0xBE1E, 0x99E0, 0x8BE0, 0x69A0, 0x90D0, 0x69A0,
817 0x90D0, 0x081F, 0xB805, 0x881F, 0x8B90, 0x69A0, 0x90D0, 0x69A0, 0x9090, 0x8BD0, 0x8BD8, 0xBE1F,
818 0xEF00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
819 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
820};
821
diff --git a/sound/oss/maui.c b/sound/oss/maui.c
new file mode 100644
index 000000000000..05cf194eda6b
--- /dev/null
+++ b/sound/oss/maui.c
@@ -0,0 +1,478 @@
1/*
2 * sound/maui.c
3 *
4 * The low level driver for Turtle Beach Maui and Tropez.
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 General clean up, use kernel IRQ
15 * system
16 * Christoph Hellwig Adapted to module_init/module_exit
17 * Bartlomiej Zolnierkiewicz
18 * Added __init to download_code()
19 *
20 * Status:
21 * Andrew J. Kroll Tested 06/01/1999 with:
22 * * OSWF.MOT File Version: 1.15
23 * * OSWF.MOT File Dated: 09/12/94
24 * * Older versions will cause problems.
25 */
26
27#include <linux/interrupt.h>
28#include <linux/config.h>
29#include <linux/module.h>
30#include <linux/init.h>
31
32#define USE_SEQ_MACROS
33#define USE_SIMPLE_MACROS
34
35#include "sound_config.h"
36#include "sound_firmware.h"
37
38#include "mpu401.h"
39
40static int maui_base = 0x330;
41
42static volatile int irq_ok;
43static int *maui_osp;
44
45#define HOST_DATA_PORT (maui_base + 2)
46#define HOST_STAT_PORT (maui_base + 3)
47#define HOST_CTRL_PORT (maui_base + 3)
48
49#define STAT_TX_INTR 0x40
50#define STAT_TX_AVAIL 0x20
51#define STAT_TX_IENA 0x10
52#define STAT_RX_INTR 0x04
53#define STAT_RX_AVAIL 0x02
54#define STAT_RX_IENA 0x01
55
56static int (*orig_load_patch)(int dev, int format, const char __user *addr,
57 int offs, int count, int pmgr_flag) = NULL;
58
59#include "maui_boot.h"
60
61static int maui_wait(int mask)
62{
63 int i;
64
65 /*
66 * Perform a short initial wait without sleeping
67 */
68
69 for (i = 0; i < 100; i++)
70 if (inb(HOST_STAT_PORT) & mask)
71 return 1;
72
73 /*
74 * Wait up to 15 seconds with sleeping
75 */
76
77 for (i = 0; i < 150; i++) {
78 if (inb(HOST_STAT_PORT) & mask)
79 return 1;
80 current->state = TASK_INTERRUPTIBLE;
81 schedule_timeout(HZ / 10);
82 if (signal_pending(current))
83 return 0;
84 }
85 return 0;
86}
87
88static int maui_read(void)
89{
90 if (maui_wait(STAT_RX_AVAIL))
91 return inb(HOST_DATA_PORT);
92 return -1;
93}
94
95static int maui_write(unsigned char data)
96{
97 if (maui_wait(STAT_TX_AVAIL)) {
98 outb((data), HOST_DATA_PORT);
99 return 1;
100 }
101 printk(KERN_WARNING "Maui: Write timeout\n");
102 return 0;
103}
104
105static irqreturn_t mauiintr(int irq, void *dev_id, struct pt_regs *dummy)
106{
107 irq_ok = 1;
108 return IRQ_HANDLED;
109}
110
111static int __init download_code(void)
112{
113 int i, lines = 0;
114 int eol_seen = 0, done = 0;
115 int skip = 1;
116
117 printk(KERN_INFO "Code download (%d bytes): ", maui_osLen);
118
119 for (i = 0; i < maui_osLen; i++) {
120 if (maui_os[i] != '\r') {
121 if (!skip || (maui_os[i] == 'S' && (i == 0 || maui_os[i - 1] == '\n'))) {
122 skip = 0;
123
124 if (maui_os[i] == '\n')
125 eol_seen = skip = 1;
126 else if (maui_os[i] == 'S') {
127 if (maui_os[i + 1] == '8')
128 done = 1;
129 if (!maui_write(0xF1))
130 goto failure;
131 if (!maui_write('S'))
132 goto failure;
133 } else {
134 if (!maui_write(maui_os[i]))
135 goto failure;
136 }
137
138 if (eol_seen) {
139 int c = 0;
140 int n;
141
142 eol_seen = 0;
143
144 for (n = 0; n < 2; n++) {
145 if (maui_wait(STAT_RX_AVAIL)) {
146 c = inb(HOST_DATA_PORT);
147 break;
148 }
149 }
150 if (c != 0x80) {
151 printk("Download not acknowledged\n");
152 return 0;
153 }
154 else if (!(lines++ % 10))
155 printk(".");
156
157 if (done) {
158 printk("\n");
159 printk(KERN_INFO "Download complete\n");
160 return 1;
161 }
162 }
163 }
164 }
165 }
166
167failure:
168 printk("\n");
169 printk(KERN_ERR "Download failed!!!\n");
170 return 0;
171}
172
173static int __init maui_init(int irq)
174{
175 unsigned char bits;
176
177 switch (irq) {
178 case 9:
179 bits = 0x00;
180 break;
181 case 5:
182 bits = 0x08;
183 break;
184 case 12:
185 bits = 0x10;
186 break;
187 case 15:
188 bits = 0x18;
189 break;
190
191 default:
192 printk(KERN_ERR "Maui: Invalid IRQ %d\n", irq);
193 return 0;
194 }
195 outb((0x00), HOST_CTRL_PORT); /* Reset */
196 outb((bits), HOST_DATA_PORT); /* Set the IRQ bits */
197 outb((bits | 0x80), HOST_DATA_PORT); /* Set the IRQ bits again? */
198 outb((0x80), HOST_CTRL_PORT); /* Leave reset */
199 outb((0x80), HOST_CTRL_PORT); /* Leave reset */
200 outb((0xD0), HOST_CTRL_PORT); /* Cause interrupt */
201
202#ifdef CONFIG_SMP
203 {
204 int i;
205 for (i = 0; i < 1000000 && !irq_ok; i++)
206 ;
207 if (!irq_ok)
208 return 0;
209 }
210#endif
211 outb((0x80), HOST_CTRL_PORT); /* Leave reset */
212
213 printk(KERN_INFO "Turtle Beach Maui initialization\n");
214
215 if (!download_code())
216 return 0;
217
218 outb((0xE0), HOST_CTRL_PORT); /* Normal operation */
219
220 /* Select mpu401 mode */
221
222 maui_write(0xf0);
223 maui_write(1);
224 if (maui_read() != 0x80) {
225 maui_write(0xf0);
226 maui_write(1);
227 if (maui_read() != 0x80)
228 printk(KERN_ERR "Maui didn't acknowledge set HW mode command\n");
229 }
230 printk(KERN_INFO "Maui initialized OK\n");
231 return 1;
232}
233
234static int maui_short_wait(int mask) {
235 int i;
236
237 for (i = 0; i < 1000; i++) {
238 if (inb(HOST_STAT_PORT) & mask) {
239 return 1;
240 }
241 }
242 return 0;
243}
244
245static int maui_load_patch(int dev, int format, const char __user *addr,
246 int offs, int count, int pmgr_flag)
247{
248
249 struct sysex_info header;
250 unsigned long left, src_offs;
251 int hdr_size = (unsigned long) &header.data[0] - (unsigned long) &header;
252 int i;
253
254 if (format == SYSEX_PATCH) /* Handled by midi_synth.c */
255 return orig_load_patch(dev, format, addr, offs, count, pmgr_flag);
256
257 if (format != MAUI_PATCH)
258 {
259 printk(KERN_WARNING "Maui: Unknown patch format\n");
260 }
261 if (count < hdr_size) {
262/* printk("Maui error: Patch header too short\n");*/
263 return -EINVAL;
264 }
265 count -= hdr_size;
266
267 /*
268 * Copy the header from user space but ignore the first bytes which have
269 * been transferred already.
270 */
271
272 if(copy_from_user(&((char *) &header)[offs], &(addr)[offs], hdr_size - offs))
273 return -EFAULT;
274
275 if (count < header.len) {
276 printk(KERN_ERR "Maui warning: Host command record too short (%d<%d)\n", count, (int) header.len);
277 header.len = count;
278 }
279 left = header.len;
280 src_offs = 0;
281
282 for (i = 0; i < left; i++) {
283 unsigned char data;
284
285 if(get_user(*(unsigned char *) &data, (unsigned char __user *) &((addr)[hdr_size + i])))
286 return -EFAULT;
287 if (i == 0 && !(data & 0x80))
288 return -EINVAL;
289
290 if (maui_write(data) == -1)
291 return -EIO;
292 }
293
294 if ((i = maui_read()) != 0x80) {
295 if (i != -1)
296 printk("Maui: Error status %02x\n", i);
297 return -EIO;
298 }
299 return 0;
300}
301
302static int __init probe_maui(struct address_info *hw_config)
303{
304 struct resource *ports;
305 int this_dev;
306 int i;
307 int tmp1, tmp2, ret;
308
309 ports = request_region(hw_config->io_base, 2, "mpu401");
310 if (!ports)
311 return 0;
312
313 if (!request_region(hw_config->io_base + 2, 6, "Maui"))
314 goto out;
315
316 maui_base = hw_config->io_base;
317 maui_osp = hw_config->osp;
318
319 if (request_irq(hw_config->irq, mauiintr, 0, "Maui", NULL) < 0)
320 goto out2;
321
322 /*
323 * Initialize the processor if necessary
324 */
325
326 if (maui_osLen > 0) {
327 if (!(inb(HOST_STAT_PORT) & STAT_TX_AVAIL) ||
328 !maui_write(0x9F) || /* Report firmware version */
329 !maui_short_wait(STAT_RX_AVAIL) ||
330 maui_read() == -1 || maui_read() == -1)
331 if (!maui_init(hw_config->irq))
332 goto out3;
333 }
334 if (!maui_write(0xCF)) /* Report hardware version */ {
335 printk(KERN_ERR "No WaveFront firmware detected (card uninitialized?)\n");
336 goto out3;
337 }
338 if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1) {
339 printk(KERN_ERR "No WaveFront firmware detected (card uninitialized?)\n");
340 goto out3;
341 }
342 if (tmp1 == 0xff || tmp2 == 0xff)
343 goto out3;
344 printk(KERN_DEBUG "WaveFront hardware version %d.%d\n", tmp1, tmp2);
345
346 if (!maui_write(0x9F)) /* Report firmware version */
347 goto out3;
348 if ((tmp1 = maui_read()) == -1 || (tmp2 = maui_read()) == -1)
349 goto out3;
350
351 printk(KERN_DEBUG "WaveFront firmware version %d.%d\n", tmp1, tmp2);
352
353 if (!maui_write(0x85)) /* Report free DRAM */
354 goto out3;
355 tmp1 = 0;
356 for (i = 0; i < 4; i++) {
357 tmp1 |= maui_read() << (7 * i);
358 }
359 printk(KERN_DEBUG "Available DRAM %dk\n", tmp1 / 1024);
360
361 for (i = 0; i < 1000; i++)
362 if (probe_mpu401(hw_config, ports))
363 break;
364
365 ret = probe_mpu401(hw_config, ports);
366 if (!ret)
367 goto out3;
368
369 conf_printf("Maui", hw_config);
370
371 hw_config->irq *= -1;
372 hw_config->name = "Maui";
373 attach_mpu401(hw_config, THIS_MODULE);
374
375 if (hw_config->slots[1] != -1) /* The MPU401 driver installed itself */ {
376 struct synth_operations *synth;
377
378 this_dev = hw_config->slots[1];
379
380 /*
381 * Intercept patch loading calls so that they can be handled
382 * by the Maui driver.
383 */
384
385 synth = midi_devs[this_dev]->converter;
386 if (synth != NULL) {
387 synth->id = "MAUI";
388 orig_load_patch = synth->load_patch;
389 synth->load_patch = &maui_load_patch;
390 } else
391 printk(KERN_ERR "Maui: Can't install patch loader\n");
392 }
393 return 1;
394
395out3:
396 free_irq(hw_config->irq, NULL);
397out2:
398 release_region(hw_config->io_base + 2, 6);
399out:
400 release_region(hw_config->io_base, 2);
401 return 0;
402}
403
404static void __exit unload_maui(struct address_info *hw_config)
405{
406 int irq = hw_config->irq;
407 release_region(hw_config->io_base + 2, 6);
408 unload_mpu401(hw_config);
409
410 if (irq < 0)
411 irq = -irq;
412 if (irq > 0)
413 free_irq(irq, NULL);
414}
415
416static int fw_load;
417
418static struct address_info cfg;
419
420static int __initdata io = -1;
421static int __initdata irq = -1;
422
423module_param(io, int, 0);
424module_param(irq, int, 0);
425
426/*
427 * Install a Maui card. Needs mpu401 loaded already.
428 */
429
430static int __init init_maui(void)
431{
432 printk(KERN_INFO "Turtle beach Maui and Tropez driver, Copyright (C) by Hannu Savolainen 1993-1996\n");
433
434 cfg.io_base = io;
435 cfg.irq = irq;
436
437 if (cfg.io_base == -1 || cfg.irq == -1) {
438 printk(KERN_INFO "maui: irq and io must be set.\n");
439 return -EINVAL;
440 }
441
442 if (maui_os == NULL) {
443 fw_load = 1;
444 maui_osLen = mod_firmware_load("/etc/sound/oswf.mot", (char **) &maui_os);
445 }
446 if (probe_maui(&cfg) == 0)
447 return -ENODEV;
448
449 return 0;
450}
451
452static void __exit cleanup_maui(void)
453{
454 if (fw_load && maui_os)
455 vfree(maui_os);
456 unload_maui(&cfg);
457}
458
459module_init(init_maui);
460module_exit(cleanup_maui);
461
462#ifndef MODULE
463static int __init setup_maui(char *str)
464{
465 /* io, irq */
466 int ints[3];
467
468 str = get_options(str, ARRAY_SIZE(ints), ints);
469
470 io = ints[1];
471 irq = ints[2];
472
473 return 1;
474}
475
476__setup("maui=", setup_maui);
477#endif
478MODULE_LICENSE("GPL");
diff --git a/sound/oss/midi_ctrl.h b/sound/oss/midi_ctrl.h
new file mode 100644
index 000000000000..3353e5a67c24
--- /dev/null
+++ b/sound/oss/midi_ctrl.h
@@ -0,0 +1,22 @@
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_syms.c b/sound/oss/midi_syms.c
new file mode 100644
index 000000000000..5b146ddf5725
--- /dev/null
+++ b/sound/oss/midi_syms.c
@@ -0,0 +1,29 @@
1/*
2 * Exported symbols for midi driver.
3 */
4
5#include <linux/module.h>
6
7char midi_syms_symbol;
8
9#include "sound_config.h"
10#define _MIDI_SYNTH_C_
11#include "midi_synth.h"
12
13EXPORT_SYMBOL(do_midi_msg);
14EXPORT_SYMBOL(midi_synth_open);
15EXPORT_SYMBOL(midi_synth_close);
16EXPORT_SYMBOL(midi_synth_ioctl);
17EXPORT_SYMBOL(midi_synth_kill_note);
18EXPORT_SYMBOL(midi_synth_start_note);
19EXPORT_SYMBOL(midi_synth_set_instr);
20EXPORT_SYMBOL(midi_synth_reset);
21EXPORT_SYMBOL(midi_synth_hw_control);
22EXPORT_SYMBOL(midi_synth_aftertouch);
23EXPORT_SYMBOL(midi_synth_controller);
24EXPORT_SYMBOL(midi_synth_panning);
25EXPORT_SYMBOL(midi_synth_setup_voice);
26EXPORT_SYMBOL(midi_synth_send_sysex);
27EXPORT_SYMBOL(midi_synth_bender);
28EXPORT_SYMBOL(midi_synth_load_patch);
29EXPORT_SYMBOL(MIDIbuf_avail);
diff --git a/sound/oss/midi_synth.c b/sound/oss/midi_synth.c
new file mode 100644
index 000000000000..972edc62afd1
--- /dev/null
+++ b/sound/oss/midi_synth.c
@@ -0,0 +1,697 @@
1/*
2 * sound/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}
87
88static void
89midi_outc(int midi_dev, int data)
90{
91 int timeout;
92
93 for (timeout = 0; timeout < 3200; timeout++)
94 if (midi_devs[midi_dev]->outputc(midi_dev, (unsigned char) (data & 0xff)))
95 {
96 if (data & 0x80) /*
97 * Status byte
98 */
99 prev_out_status[midi_dev] =
100 (unsigned char) (data & 0xff); /*
101 * Store for running status
102 */
103 return; /*
104 * Mission complete
105 */
106 }
107 /*
108 * Sorry! No space on buffers.
109 */
110 printk("Midi send timed out\n");
111}
112
113static int
114prefix_cmd(int midi_dev, unsigned char status)
115{
116 if ((char *) midi_devs[midi_dev]->prefix_cmd == NULL)
117 return 1;
118
119 return midi_devs[midi_dev]->prefix_cmd(midi_dev, status);
120}
121
122static void
123midi_synth_input(int orig_dev, unsigned char data)
124{
125 int dev;
126 struct midi_input_info *inc;
127
128 static unsigned char len_tab[] = /* # of data bytes following a status
129 */
130 {
131 2, /* 8x */
132 2, /* 9x */
133 2, /* Ax */
134 2, /* Bx */
135 1, /* Cx */
136 1, /* Dx */
137 2, /* Ex */
138 0 /* Fx */
139 };
140
141 if (orig_dev < 0 || orig_dev > num_midis || midi_devs[orig_dev] == NULL)
142 return;
143
144 if (data == 0xfe) /* Ignore active sensing */
145 return;
146
147 dev = midi2synth[orig_dev];
148 inc = &midi_devs[orig_dev]->in_info;
149
150 switch (inc->m_state)
151 {
152 case MST_INIT:
153 if (data & 0x80) /* MIDI status byte */
154 {
155 if ((data & 0xf0) == 0xf0) /* Common message */
156 {
157 switch (data)
158 {
159 case 0xf0: /* Sysex */
160 inc->m_state = MST_SYSEX;
161 break; /* Sysex */
162
163 case 0xf1: /* MTC quarter frame */
164 case 0xf3: /* Song select */
165 inc->m_state = MST_DATA;
166 inc->m_ptr = 1;
167 inc->m_left = 1;
168 inc->m_buf[0] = data;
169 break;
170
171 case 0xf2: /* Song position pointer */
172 inc->m_state = MST_DATA;
173 inc->m_ptr = 1;
174 inc->m_left = 2;
175 inc->m_buf[0] = data;
176 break;
177
178 default:
179 inc->m_buf[0] = data;
180 inc->m_ptr = 1;
181 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
182 inc->m_ptr = 0;
183 inc->m_left = 0;
184 }
185 } else
186 {
187 inc->m_state = MST_DATA;
188 inc->m_ptr = 1;
189 inc->m_left = len_tab[(data >> 4) - 8];
190 inc->m_buf[0] = inc->m_prev_status = data;
191 }
192 } else if (inc->m_prev_status & 0x80) {
193 /* Data byte (use running status) */
194 inc->m_ptr = 2;
195 inc->m_buf[1] = data;
196 inc->m_buf[0] = inc->m_prev_status;
197 inc->m_left = len_tab[(inc->m_buf[0] >> 4) - 8] - 1;
198 if (inc->m_left > 0)
199 inc->m_state = MST_DATA; /* Not done yet */
200 else {
201 inc->m_state = MST_INIT;
202 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
203 inc->m_ptr = 0;
204 }
205 }
206 break; /* MST_INIT */
207
208 case MST_DATA:
209 inc->m_buf[inc->m_ptr++] = data;
210 if (--inc->m_left <= 0)
211 {
212 inc->m_state = MST_INIT;
213 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
214 inc->m_ptr = 0;
215 }
216 break; /* MST_DATA */
217
218 case MST_SYSEX:
219 if (data == 0xf7) /* Sysex end */
220 {
221 inc->m_state = MST_INIT;
222 inc->m_left = 0;
223 inc->m_ptr = 0;
224 }
225 break; /* MST_SYSEX */
226
227 default:
228 printk("MIDI%d: Unexpected state %d (%02x)\n", orig_dev, inc->m_state, (int) data);
229 inc->m_state = MST_INIT;
230 }
231}
232
233static void
234leave_sysex(int dev)
235{
236 int orig_dev = synth_devs[dev]->midi_dev;
237 int timeout = 0;
238
239 if (!sysex_state[dev])
240 return;
241
242 sysex_state[dev] = 0;
243
244 while (!midi_devs[orig_dev]->outputc(orig_dev, 0xf7) &&
245 timeout < 1000)
246 timeout++;
247
248 sysex_state[dev] = 0;
249}
250
251static void
252midi_synth_output(int dev)
253{
254 /*
255 * Currently NOP
256 */
257}
258
259int midi_synth_ioctl(int dev, unsigned int cmd, void __user *arg)
260{
261 /*
262 * int orig_dev = synth_devs[dev]->midi_dev;
263 */
264
265 switch (cmd) {
266
267 case SNDCTL_SYNTH_INFO:
268 if (__copy_to_user(arg, synth_devs[dev]->info, sizeof(struct synth_info)))
269 return -EFAULT;
270 return 0;
271
272 case SNDCTL_SYNTH_MEMAVL:
273 return 0x7fffffff;
274
275 default:
276 return -EINVAL;
277 }
278}
279
280int
281midi_synth_kill_note(int dev, int channel, int note, int velocity)
282{
283 int orig_dev = synth_devs[dev]->midi_dev;
284 int msg, chn;
285
286 if (note < 0 || note > 127)
287 return 0;
288 if (channel < 0 || channel > 15)
289 return 0;
290 if (velocity < 0)
291 velocity = 0;
292 if (velocity > 127)
293 velocity = 127;
294
295 leave_sysex(dev);
296
297 msg = prev_out_status[orig_dev] & 0xf0;
298 chn = prev_out_status[orig_dev] & 0x0f;
299
300 if (chn == channel && ((msg == 0x90 && velocity == 64) || msg == 0x80))
301 { /*
302 * Use running status
303 */
304 if (!prefix_cmd(orig_dev, note))
305 return 0;
306
307 midi_outc(orig_dev, note);
308
309 if (msg == 0x90) /*
310 * Running status = Note on
311 */
312 midi_outc(orig_dev, 0); /*
313 * Note on with velocity 0 == note
314 * off
315 */
316 else
317 midi_outc(orig_dev, velocity);
318 } else
319 {
320 if (velocity == 64)
321 {
322 if (!prefix_cmd(orig_dev, 0x90 | (channel & 0x0f)))
323 return 0;
324 midi_outc(orig_dev, 0x90 | (channel & 0x0f)); /*
325 * Note on
326 */
327 midi_outc(orig_dev, note);
328 midi_outc(orig_dev, 0); /*
329 * Zero G
330 */
331 } else
332 {
333 if (!prefix_cmd(orig_dev, 0x80 | (channel & 0x0f)))
334 return 0;
335 midi_outc(orig_dev, 0x80 | (channel & 0x0f)); /*
336 * Note off
337 */
338 midi_outc(orig_dev, note);
339 midi_outc(orig_dev, velocity);
340 }
341 }
342
343 return 0;
344}
345
346int
347midi_synth_set_instr(int dev, int channel, int instr_no)
348{
349 int orig_dev = synth_devs[dev]->midi_dev;
350
351 if (instr_no < 0 || instr_no > 127)
352 instr_no = 0;
353 if (channel < 0 || channel > 15)
354 return 0;
355
356 leave_sysex(dev);
357
358 if (!prefix_cmd(orig_dev, 0xc0 | (channel & 0x0f)))
359 return 0;
360 midi_outc(orig_dev, 0xc0 | (channel & 0x0f)); /*
361 * Program change
362 */
363 midi_outc(orig_dev, instr_no);
364
365 return 0;
366}
367
368int
369midi_synth_start_note(int dev, int channel, int note, int velocity)
370{
371 int orig_dev = synth_devs[dev]->midi_dev;
372 int msg, chn;
373
374 if (note < 0 || note > 127)
375 return 0;
376 if (channel < 0 || channel > 15)
377 return 0;
378 if (velocity < 0)
379 velocity = 0;
380 if (velocity > 127)
381 velocity = 127;
382
383 leave_sysex(dev);
384
385 msg = prev_out_status[orig_dev] & 0xf0;
386 chn = prev_out_status[orig_dev] & 0x0f;
387
388 if (chn == channel && msg == 0x90)
389 { /*
390 * Use running status
391 */
392 if (!prefix_cmd(orig_dev, note))
393 return 0;
394 midi_outc(orig_dev, note);
395 midi_outc(orig_dev, velocity);
396 } else
397 {
398 if (!prefix_cmd(orig_dev, 0x90 | (channel & 0x0f)))
399 return 0;
400 midi_outc(orig_dev, 0x90 | (channel & 0x0f)); /*
401 * Note on
402 */
403 midi_outc(orig_dev, note);
404 midi_outc(orig_dev, velocity);
405 }
406 return 0;
407}
408
409void
410midi_synth_reset(int dev)
411{
412
413 leave_sysex(dev);
414}
415
416int
417midi_synth_open(int dev, int mode)
418{
419 int orig_dev = synth_devs[dev]->midi_dev;
420 int err;
421 struct midi_input_info *inc;
422
423 if (orig_dev < 0 || orig_dev > num_midis || midi_devs[orig_dev] == NULL)
424 return -ENXIO;
425
426 midi2synth[orig_dev] = dev;
427 sysex_state[dev] = 0;
428 prev_out_status[orig_dev] = 0;
429
430 if ((err = midi_devs[orig_dev]->open(orig_dev, mode,
431 midi_synth_input, midi_synth_output)) < 0)
432 return err;
433 inc = &midi_devs[orig_dev]->in_info;
434
435 /* save_flags(flags);
436 cli();
437 don't know against what irqhandler to protect*/
438 inc->m_busy = 0;
439 inc->m_state = MST_INIT;
440 inc->m_ptr = 0;
441 inc->m_left = 0;
442 inc->m_prev_status = 0x00;
443 /* restore_flags(flags); */
444
445 return 1;
446}
447
448void
449midi_synth_close(int dev)
450{
451 int orig_dev = synth_devs[dev]->midi_dev;
452
453 leave_sysex(dev);
454
455 /*
456 * Shut up the synths by sending just single active sensing message.
457 */
458 midi_devs[orig_dev]->outputc(orig_dev, 0xfe);
459
460 midi_devs[orig_dev]->close(orig_dev);
461}
462
463void
464midi_synth_hw_control(int dev, unsigned char *event)
465{
466}
467
468int
469midi_synth_load_patch(int dev, int format, const char __user *addr,
470 int offs, int count, int pmgr_flag)
471{
472 int orig_dev = synth_devs[dev]->midi_dev;
473
474 struct sysex_info sysex;
475 int i;
476 unsigned long left, src_offs, eox_seen = 0;
477 int first_byte = 1;
478 int hdr_size = (unsigned long) &sysex.data[0] - (unsigned long) &sysex;
479
480 leave_sysex(dev);
481
482 if (!prefix_cmd(orig_dev, 0xf0))
483 return 0;
484
485 if (format != SYSEX_PATCH)
486 {
487/* printk("MIDI Error: Invalid patch format (key) 0x%x\n", format);*/
488 return -EINVAL;
489 }
490 if (count < hdr_size)
491 {
492/* printk("MIDI Error: Patch header too short\n");*/
493 return -EINVAL;
494 }
495 count -= hdr_size;
496
497 /*
498 * Copy the header from user space but ignore the first bytes which have
499 * been transferred already.
500 */
501
502 if(copy_from_user(&((char *) &sysex)[offs], &(addr)[offs], hdr_size - offs))
503 return -EFAULT;
504
505 if (count < sysex.len)
506 {
507/* printk(KERN_WARNING "MIDI Warning: Sysex record too short (%d<%d)\n", count, (int) sysex.len);*/
508 sysex.len = count;
509 }
510 left = sysex.len;
511 src_offs = 0;
512
513 for (i = 0; i < left && !signal_pending(current); i++)
514 {
515 unsigned char data;
516
517 get_user(*(unsigned char *) &data, (unsigned char __user *) &((addr)[hdr_size + i]));
518
519 eox_seen = (i > 0 && data & 0x80); /* End of sysex */
520
521 if (eox_seen && data != 0xf7)
522 data = 0xf7;
523
524 if (i == 0)
525 {
526 if (data != 0xf0)
527 {
528 printk(KERN_WARNING "midi_synth: Sysex start missing\n");
529 return -EINVAL;
530 }
531 }
532 while (!midi_devs[orig_dev]->outputc(orig_dev, (unsigned char) (data & 0xff)) &&
533 !signal_pending(current))
534 schedule();
535
536 if (!first_byte && data & 0x80)
537 return 0;
538 first_byte = 0;
539 }
540
541 if (!eox_seen)
542 midi_outc(orig_dev, 0xf7);
543 return 0;
544}
545
546void midi_synth_panning(int dev, int channel, int pressure)
547{
548}
549
550void midi_synth_aftertouch(int dev, int channel, int pressure)
551{
552 int orig_dev = synth_devs[dev]->midi_dev;
553 int msg, chn;
554
555 if (pressure < 0 || pressure > 127)
556 return;
557 if (channel < 0 || channel > 15)
558 return;
559
560 leave_sysex(dev);
561
562 msg = prev_out_status[orig_dev] & 0xf0;
563 chn = prev_out_status[orig_dev] & 0x0f;
564
565 if (msg != 0xd0 || chn != channel) /*
566 * Test for running status
567 */
568 {
569 if (!prefix_cmd(orig_dev, 0xd0 | (channel & 0x0f)))
570 return;
571 midi_outc(orig_dev, 0xd0 | (channel & 0x0f)); /*
572 * Channel pressure
573 */
574 } else if (!prefix_cmd(orig_dev, pressure))
575 return;
576
577 midi_outc(orig_dev, pressure);
578}
579
580void
581midi_synth_controller(int dev, int channel, int ctrl_num, int value)
582{
583 int orig_dev = synth_devs[dev]->midi_dev;
584 int chn, msg;
585
586 if (ctrl_num < 0 || ctrl_num > 127)
587 return;
588 if (channel < 0 || channel > 15)
589 return;
590
591 leave_sysex(dev);
592
593 msg = prev_out_status[orig_dev] & 0xf0;
594 chn = prev_out_status[orig_dev] & 0x0f;
595
596 if (msg != 0xb0 || chn != channel)
597 {
598 if (!prefix_cmd(orig_dev, 0xb0 | (channel & 0x0f)))
599 return;
600 midi_outc(orig_dev, 0xb0 | (channel & 0x0f));
601 } else if (!prefix_cmd(orig_dev, ctrl_num))
602 return;
603
604 midi_outc(orig_dev, ctrl_num);
605 midi_outc(orig_dev, value & 0x7f);
606}
607
608void
609midi_synth_bender(int dev, int channel, int value)
610{
611 int orig_dev = synth_devs[dev]->midi_dev;
612 int msg, prev_chn;
613
614 if (channel < 0 || channel > 15)
615 return;
616
617 if (value < 0 || value > 16383)
618 return;
619
620 leave_sysex(dev);
621
622 msg = prev_out_status[orig_dev] & 0xf0;
623 prev_chn = prev_out_status[orig_dev] & 0x0f;
624
625 if (msg != 0xd0 || prev_chn != channel) /*
626 * Test for running status
627 */
628 {
629 if (!prefix_cmd(orig_dev, 0xe0 | (channel & 0x0f)))
630 return;
631 midi_outc(orig_dev, 0xe0 | (channel & 0x0f));
632 } else if (!prefix_cmd(orig_dev, value & 0x7f))
633 return;
634
635 midi_outc(orig_dev, value & 0x7f);
636 midi_outc(orig_dev, (value >> 7) & 0x7f);
637}
638
639void
640midi_synth_setup_voice(int dev, int voice, int channel)
641{
642}
643
644int
645midi_synth_send_sysex(int dev, unsigned char *bytes, int len)
646{
647 int orig_dev = synth_devs[dev]->midi_dev;
648 int i;
649
650 for (i = 0; i < len; i++)
651 {
652 switch (bytes[i])
653 {
654 case 0xf0: /* Start sysex */
655 if (!prefix_cmd(orig_dev, 0xf0))
656 return 0;
657 sysex_state[dev] = 1;
658 break;
659
660 case 0xf7: /* End sysex */
661 if (!sysex_state[dev]) /* Orphan sysex end */
662 return 0;
663 sysex_state[dev] = 0;
664 break;
665
666 default:
667 if (!sysex_state[dev])
668 return 0;
669
670 if (bytes[i] & 0x80) /* Error. Another message before sysex end */
671 {
672 bytes[i] = 0xf7; /* Sysex end */
673 sysex_state[dev] = 0;
674 }
675 }
676
677 if (!midi_devs[orig_dev]->outputc(orig_dev, bytes[i]))
678 {
679/*
680 * Hardware level buffer is full. Abort the sysex message.
681 */
682
683 int timeout = 0;
684
685 bytes[i] = 0xf7;
686 sysex_state[dev] = 0;
687
688 while (!midi_devs[orig_dev]->outputc(orig_dev, bytes[i]) &&
689 timeout < 1000)
690 timeout++;
691 }
692 if (!sysex_state[dev])
693 return 0;
694 }
695
696 return 0;
697}
diff --git a/sound/oss/midi_synth.h b/sound/oss/midi_synth.h
new file mode 100644
index 000000000000..6bc9d00bc77c
--- /dev/null
+++ b/sound/oss/midi_synth.h
@@ -0,0 +1,47 @@
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 offs, 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
new file mode 100644
index 000000000000..b2676fa34630
--- /dev/null
+++ b/sound/oss/midibuf.c
@@ -0,0 +1,431 @@
1/*
2 * sound/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#define MIDIBUF_C
20
21#include "sound_config.h"
22
23
24/*
25 * Don't make MAX_QUEUE_SIZE larger than 4000
26 */
27
28#define MAX_QUEUE_SIZE 4000
29
30static wait_queue_head_t midi_sleeper[MAX_MIDI_DEV];
31static wait_queue_head_t input_sleeper[MAX_MIDI_DEV];
32
33struct midi_buf
34{
35 int len, head, tail;
36 unsigned char queue[MAX_QUEUE_SIZE];
37};
38
39struct midi_parms
40{
41 long prech_timeout; /*
42 * Timeout before the first ch
43 */
44};
45
46static struct midi_buf *midi_out_buf[MAX_MIDI_DEV] = {NULL};
47static struct midi_buf *midi_in_buf[MAX_MIDI_DEV] = {NULL};
48static struct midi_parms parms[MAX_MIDI_DEV];
49
50static void midi_poll(unsigned long dummy);
51
52
53static struct timer_list poll_timer = TIMER_INITIALIZER(midi_poll, 0, 0);
54
55static volatile int open_devs;
56static DEFINE_SPINLOCK(lock);
57
58#define DATA_AVAIL(q) (q->len)
59#define SPACE_AVAIL(q) (MAX_QUEUE_SIZE - q->len)
60
61#define QUEUE_BYTE(q, data) \
62 if (SPACE_AVAIL(q)) \
63 { \
64 unsigned long flags; \
65 spin_lock_irqsave(&lock, flags); \
66 q->queue[q->tail] = (data); \
67 q->len++; q->tail = (q->tail+1) % MAX_QUEUE_SIZE; \
68 spin_unlock_irqrestore(&lock, flags); \
69 }
70
71#define REMOVE_BYTE(q, data) \
72 if (DATA_AVAIL(q)) \
73 { \
74 unsigned long flags; \
75 spin_lock_irqsave(&lock, flags); \
76 data = q->queue[q->head]; \
77 q->len--; q->head = (q->head+1) % MAX_QUEUE_SIZE; \
78 spin_unlock_irqrestore(&lock, flags); \
79 }
80
81static void drain_midi_queue(int dev)
82{
83
84 /*
85 * Give the Midi driver time to drain its output queues
86 */
87
88 if (midi_devs[dev]->buffer_status != NULL)
89 while (!signal_pending(current) && midi_devs[dev]->buffer_status(dev))
90 interruptible_sleep_on_timeout(&midi_sleeper[dev],
91 HZ/10);
92}
93
94static void midi_input_intr(int dev, unsigned char data)
95{
96 if (midi_in_buf[dev] == NULL)
97 return;
98
99 if (data == 0xfe) /*
100 * Active sensing
101 */
102 return; /*
103 * Ignore
104 */
105
106 if (SPACE_AVAIL(midi_in_buf[dev])) {
107 QUEUE_BYTE(midi_in_buf[dev], data);
108 wake_up(&input_sleeper[dev]);
109 }
110}
111
112static void midi_output_intr(int dev)
113{
114 /*
115 * Currently NOP
116 */
117}
118
119static void midi_poll(unsigned long dummy)
120{
121 unsigned long flags;
122 int dev;
123
124 spin_lock_irqsave(&lock, flags);
125 if (open_devs)
126 {
127 for (dev = 0; dev < num_midis; dev++)
128 if (midi_devs[dev] != NULL && midi_out_buf[dev] != NULL)
129 {
130 int ok = 1;
131
132 while (DATA_AVAIL(midi_out_buf[dev]) && ok)
133 {
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 midi_out_buf[dev]->head = (midi_out_buf[dev]->head + 1) % MAX_QUEUE_SIZE;
140 midi_out_buf[dev]->len--;
141 }
142
143 if (DATA_AVAIL(midi_out_buf[dev]) < 100)
144 wake_up(&midi_sleeper[dev]);
145 }
146 poll_timer.expires = (1) + jiffies;
147 add_timer(&poll_timer);
148 /*
149 * Come back later
150 */
151 }
152 spin_unlock_irqrestore(&lock, flags);
153}
154
155int MIDIbuf_open(int dev, struct file *file)
156{
157 int mode, err;
158
159 dev = dev >> 4;
160 mode = translate_mode(file);
161
162 if (num_midis > MAX_MIDI_DEV)
163 {
164 printk(KERN_ERR "midi: Too many midi interfaces\n");
165 num_midis = MAX_MIDI_DEV;
166 }
167 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
168 return -ENXIO;
169 /*
170 * Interrupts disabled. Be careful
171 */
172
173 module_put(midi_devs[dev]->owner);
174
175 if ((err = midi_devs[dev]->open(dev, mode,
176 midi_input_intr, midi_output_intr)) < 0)
177 return err;
178
179 parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT;
180 midi_in_buf[dev] = (struct midi_buf *) vmalloc(sizeof(struct midi_buf));
181
182 if (midi_in_buf[dev] == NULL)
183 {
184 printk(KERN_WARNING "midi: Can't allocate buffer\n");
185 midi_devs[dev]->close(dev);
186 return -EIO;
187 }
188 midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0;
189
190 midi_out_buf[dev] = (struct midi_buf *) vmalloc(sizeof(struct midi_buf));
191
192 if (midi_out_buf[dev] == NULL)
193 {
194 printk(KERN_WARNING "midi: Can't allocate buffer\n");
195 midi_devs[dev]->close(dev);
196 vfree(midi_in_buf[dev]);
197 midi_in_buf[dev] = NULL;
198 return -EIO;
199 }
200 midi_out_buf[dev]->len = midi_out_buf[dev]->head = midi_out_buf[dev]->tail = 0;
201 open_devs++;
202
203 init_waitqueue_head(&midi_sleeper[dev]);
204 init_waitqueue_head(&input_sleeper[dev]);
205
206 if (open_devs < 2) /* This was first open */
207 {
208 poll_timer.expires = 1 + jiffies;
209 add_timer(&poll_timer); /* Start polling */
210 }
211 return err;
212}
213
214void MIDIbuf_release(int dev, struct file *file)
215{
216 int mode;
217
218 dev = dev >> 4;
219 mode = translate_mode(file);
220
221 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
222 return;
223
224 /*
225 * Wait until the queue is empty
226 */
227
228 if (mode != OPEN_READ)
229 {
230 midi_devs[dev]->outputc(dev, 0xfe); /*
231 * Active sensing to shut the
232 * devices
233 */
234
235 while (!signal_pending(current) && DATA_AVAIL(midi_out_buf[dev]))
236 interruptible_sleep_on(&midi_sleeper[dev]);
237 /*
238 * Sync
239 */
240
241 drain_midi_queue(dev); /*
242 * Ensure the output queues are empty
243 */
244 }
245
246 midi_devs[dev]->close(dev);
247
248 open_devs--;
249 if (open_devs == 0)
250 del_timer_sync(&poll_timer);
251 vfree(midi_in_buf[dev]);
252 vfree(midi_out_buf[dev]);
253 midi_in_buf[dev] = NULL;
254 midi_out_buf[dev] = NULL;
255
256 module_put(midi_devs[dev]->owner);
257}
258
259int MIDIbuf_write(int dev, struct file *file, const char __user *buf, int count)
260{
261 int c, n, i;
262 unsigned char tmp_data;
263
264 dev = dev >> 4;
265
266 if (!count)
267 return 0;
268
269 c = 0;
270
271 while (c < count)
272 {
273 n = SPACE_AVAIL(midi_out_buf[dev]);
274
275 if (n == 0) { /*
276 * No space just now.
277 */
278
279 if (file->f_flags & O_NONBLOCK) {
280 c = -EAGAIN;
281 goto out;
282 }
283
284 interruptible_sleep_on(&midi_sleeper[dev]);
285 if (signal_pending(current))
286 {
287 c = -EINTR;
288 goto out;
289 }
290 n = SPACE_AVAIL(midi_out_buf[dev]);
291 }
292 if (n > (count - c))
293 n = count - c;
294
295 for (i = 0; i < n; i++)
296 {
297 /* BROKE BROKE BROKE - CANT DO THIS WITH CLI !! */
298 /* yes, think the same, so I removed the cli() brackets
299 QUEUE_BYTE is protected against interrupts */
300 if (copy_from_user((char *) &tmp_data, &(buf)[c], 1)) {
301 c = -EFAULT;
302 goto out;
303 }
304 QUEUE_BYTE(midi_out_buf[dev], tmp_data);
305 c++;
306 }
307 }
308out:
309 return c;
310}
311
312
313int MIDIbuf_read(int dev, struct file *file, char __user *buf, int count)
314{
315 int n, c = 0;
316 unsigned char tmp_data;
317
318 dev = dev >> 4;
319
320 if (!DATA_AVAIL(midi_in_buf[dev])) { /*
321 * No data yet, wait
322 */
323 if (file->f_flags & O_NONBLOCK) {
324 c = -EAGAIN;
325 goto out;
326 }
327 interruptible_sleep_on_timeout(&input_sleeper[dev],
328 parms[dev].prech_timeout);
329
330 if (signal_pending(current))
331 c = -EINTR; /* The user is getting restless */
332 }
333 if (c == 0 && DATA_AVAIL(midi_in_buf[dev])) /*
334 * Got some bytes
335 */
336 {
337 n = DATA_AVAIL(midi_in_buf[dev]);
338 if (n > count)
339 n = count;
340 c = 0;
341
342 while (c < n)
343 {
344 char *fixit;
345 REMOVE_BYTE(midi_in_buf[dev], tmp_data);
346 fixit = (char *) &tmp_data;
347 /* BROKE BROKE BROKE */
348 /* yes removed the cli() brackets again
349 should q->len,tail&head be atomic_t? */
350 if (copy_to_user(&(buf)[c], fixit, 1)) {
351 c = -EFAULT;
352 goto out;
353 }
354 c++;
355 }
356 }
357out:
358 return c;
359}
360
361int MIDIbuf_ioctl(int dev, struct file *file,
362 unsigned int cmd, void __user *arg)
363{
364 int val;
365
366 dev = dev >> 4;
367
368 if (((cmd >> 8) & 0xff) == 'C')
369 {
370 if (midi_devs[dev]->coproc) /* Coprocessor ioctl */
371 return midi_devs[dev]->coproc->ioctl(midi_devs[dev]->coproc->devc, cmd, arg, 0);
372/* printk("/dev/midi%d: No coprocessor for this device\n", dev);*/
373 return -ENXIO;
374 }
375 else
376 {
377 switch (cmd)
378 {
379 case SNDCTL_MIDI_PRETIME:
380 if (get_user(val, (int __user *)arg))
381 return -EFAULT;
382 if (val < 0)
383 val = 0;
384 val = (HZ * val) / 10;
385 parms[dev].prech_timeout = val;
386 return put_user(val, (int __user *)arg);
387
388 default:
389 if (!midi_devs[dev]->ioctl)
390 return -EINVAL;
391 return midi_devs[dev]->ioctl(dev, cmd, arg);
392 }
393 }
394}
395
396/* No kernel lock - fine */
397unsigned int MIDIbuf_poll(int dev, struct file *file, poll_table * wait)
398{
399 unsigned int mask = 0;
400
401 dev = dev >> 4;
402
403 /* input */
404 poll_wait(file, &input_sleeper[dev], wait);
405 if (DATA_AVAIL(midi_in_buf[dev]))
406 mask |= POLLIN | POLLRDNORM;
407
408 /* output */
409 poll_wait(file, &midi_sleeper[dev], wait);
410 if (!SPACE_AVAIL(midi_out_buf[dev]))
411 mask |= POLLOUT | POLLWRNORM;
412
413 return mask;
414}
415
416
417void MIDIbuf_init(void)
418{
419 /* drag in midi_syms.o */
420 {
421 extern char midi_syms_symbol;
422 midi_syms_symbol = 0;
423 }
424}
425
426int MIDIbuf_avail(int dev)
427{
428 if (midi_in_buf[dev])
429 return DATA_AVAIL (midi_in_buf[dev]);
430 return 0;
431}
diff --git a/sound/oss/mpu401.c b/sound/oss/mpu401.c
new file mode 100644
index 000000000000..b66f53fa8db0
--- /dev/null
+++ b/sound/oss/mpu401.c
@@ -0,0 +1,1826 @@
1/*
2 * sound/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/init.h>
23#include <linux/interrupt.h>
24#include <linux/spinlock.h>
25#define USE_SEQ_MACROS
26#define USE_SIMPLE_MACROS
27
28#include "sound_config.h"
29
30#include "coproc.h"
31#include "mpu401.h"
32
33static int timer_mode = TMR_INTERNAL, timer_caps = TMR_INTERNAL;
34
35struct mpu_config
36{
37 int base; /*
38 * I/O base
39 */
40 int irq;
41 int opened; /*
42 * Open mode
43 */
44 int devno;
45 int synthno;
46 int uart_mode;
47 int initialized;
48 int mode;
49#define MODE_MIDI 1
50#define MODE_SYNTH 2
51 unsigned char version, revision;
52 unsigned int capabilities;
53#define MPU_CAP_INTLG 0x10000000
54#define MPU_CAP_SYNC 0x00000010
55#define MPU_CAP_FSK 0x00000020
56#define MPU_CAP_CLS 0x00000040
57#define MPU_CAP_SMPTE 0x00000080
58#define MPU_CAP_2PORT 0x00000001
59 int timer_flag;
60
61#define MBUF_MAX 10
62#define BUFTEST(dc) if (dc->m_ptr >= MBUF_MAX || dc->m_ptr < 0) \
63 {printk( "MPU: Invalid buffer pointer %d/%d, s=%d\n", dc->m_ptr, dc->m_left, dc->m_state);dc->m_ptr--;}
64 int m_busy;
65 unsigned char m_buf[MBUF_MAX];
66 int m_ptr;
67 int m_state;
68 int m_left;
69 unsigned char last_status;
70 void (*inputintr) (int dev, unsigned char data);
71 int shared_irq;
72 int *osp;
73 spinlock_t lock;
74 };
75
76#define DATAPORT(base) (base)
77#define COMDPORT(base) (base+1)
78#define STATPORT(base) (base+1)
79
80
81static void mpu401_close(int dev);
82
83static inline int mpu401_status(struct mpu_config *devc)
84{
85 return inb(STATPORT(devc->base));
86}
87
88#define input_avail(devc) (!(mpu401_status(devc)&INPUT_AVAIL))
89#define output_ready(devc) (!(mpu401_status(devc)&OUTPUT_READY))
90
91static inline void write_command(struct mpu_config *devc, unsigned char cmd)
92{
93 outb(cmd, COMDPORT(devc->base));
94}
95
96static inline int read_data(struct mpu_config *devc)
97{
98 return inb(DATAPORT(devc->base));
99}
100
101static inline void write_data(struct mpu_config *devc, unsigned char byte)
102{
103 outb(byte, DATAPORT(devc->base));
104}
105
106#define OUTPUT_READY 0x40
107#define INPUT_AVAIL 0x80
108#define MPU_ACK 0xFE
109#define MPU_RESET 0xFF
110#define UART_MODE_ON 0x3F
111
112static struct mpu_config dev_conf[MAX_MIDI_DEV];
113
114static int n_mpu_devs;
115
116static int reset_mpu401(struct mpu_config *devc);
117static void set_uart_mode(int dev, struct mpu_config *devc, int arg);
118
119static int mpu_timer_init(int midi_dev);
120static void mpu_timer_interrupt(void);
121static void timer_ext_event(struct mpu_config *devc, int event, int parm);
122
123static struct synth_info mpu_synth_info_proto = {
124 "MPU-401 MIDI interface",
125 0,
126 SYNTH_TYPE_MIDI,
127 MIDI_TYPE_MPU401,
128 0, 128,
129 0, 128,
130 SYNTH_CAP_INPUT
131};
132
133static struct synth_info mpu_synth_info[MAX_MIDI_DEV];
134
135/*
136 * States for the input scanner
137 */
138
139#define ST_INIT 0 /* Ready for timing byte or msg */
140#define ST_TIMED 1 /* Leading timing byte rcvd */
141#define ST_DATABYTE 2 /* Waiting for (nr_left) data bytes */
142
143#define ST_SYSMSG 100 /* System message (sysx etc). */
144#define ST_SYSEX 101 /* System exclusive msg */
145#define ST_MTC 102 /* Midi Time Code (MTC) qframe msg */
146#define ST_SONGSEL 103 /* Song select */
147#define ST_SONGPOS 104 /* Song position pointer */
148
149static unsigned char len_tab[] = /* # of data bytes following a status
150 */
151{
152 2, /* 8x */
153 2, /* 9x */
154 2, /* Ax */
155 2, /* Bx */
156 1, /* Cx */
157 1, /* Dx */
158 2, /* Ex */
159 0 /* Fx */
160};
161
162#define STORE(cmd) \
163{ \
164 int len; \
165 unsigned char obuf[8]; \
166 cmd; \
167 seq_input_event(obuf, len); \
168}
169
170#define _seqbuf obuf
171#define _seqbufptr 0
172#define _SEQ_ADVBUF(x) len=x
173
174static int mpu_input_scanner(struct mpu_config *devc, unsigned char midic)
175{
176
177 switch (devc->m_state)
178 {
179 case ST_INIT:
180 switch (midic)
181 {
182 case 0xf8:
183 /* Timer overflow */
184 break;
185
186 case 0xfc:
187 printk("<all end>");
188 break;
189
190 case 0xfd:
191 if (devc->timer_flag)
192 mpu_timer_interrupt();
193 break;
194
195 case 0xfe:
196 return MPU_ACK;
197
198 case 0xf0:
199 case 0xf1:
200 case 0xf2:
201 case 0xf3:
202 case 0xf4:
203 case 0xf5:
204 case 0xf6:
205 case 0xf7:
206 printk("<Trk data rq #%d>", midic & 0x0f);
207 break;
208
209 case 0xf9:
210 printk("<conductor rq>");
211 break;
212
213 case 0xff:
214 devc->m_state = ST_SYSMSG;
215 break;
216
217 default:
218 if (midic <= 0xef)
219 {
220 /* printk( "mpu time: %d ", midic); */
221 devc->m_state = ST_TIMED;
222 }
223 else
224 printk("<MPU: Unknown event %02x> ", midic);
225 }
226 break;
227
228 case ST_TIMED:
229 {
230 int msg = ((int) (midic & 0xf0) >> 4);
231
232 devc->m_state = ST_DATABYTE;
233
234 if (msg < 8) /* Data byte */
235 {
236 /* printk( "midi msg (running status) "); */
237 msg = ((int) (devc->last_status & 0xf0) >> 4);
238 msg -= 8;
239 devc->m_left = len_tab[msg] - 1;
240
241 devc->m_ptr = 2;
242 devc->m_buf[0] = devc->last_status;
243 devc->m_buf[1] = midic;
244
245 if (devc->m_left <= 0)
246 {
247 devc->m_state = ST_INIT;
248 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
249 devc->m_ptr = 0;
250 }
251 }
252 else if (msg == 0xf) /* MPU MARK */
253 {
254 devc->m_state = ST_INIT;
255
256 switch (midic)
257 {
258 case 0xf8:
259 /* printk( "NOP "); */
260 break;
261
262 case 0xf9:
263 /* printk( "meas end "); */
264 break;
265
266 case 0xfc:
267 /* printk( "data end "); */
268 break;
269
270 default:
271 printk("Unknown MPU mark %02x\n", midic);
272 }
273 }
274 else
275 {
276 devc->last_status = midic;
277 /* printk( "midi msg "); */
278 msg -= 8;
279 devc->m_left = len_tab[msg];
280
281 devc->m_ptr = 1;
282 devc->m_buf[0] = midic;
283
284 if (devc->m_left <= 0)
285 {
286 devc->m_state = ST_INIT;
287 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
288 devc->m_ptr = 0;
289 }
290 }
291 }
292 break;
293
294 case ST_SYSMSG:
295 switch (midic)
296 {
297 case 0xf0:
298 printk("<SYX>");
299 devc->m_state = ST_SYSEX;
300 break;
301
302 case 0xf1:
303 devc->m_state = ST_MTC;
304 break;
305
306 case 0xf2:
307 devc->m_state = ST_SONGPOS;
308 devc->m_ptr = 0;
309 break;
310
311 case 0xf3:
312 devc->m_state = ST_SONGSEL;
313 break;
314
315 case 0xf6:
316 /* printk( "tune_request\n"); */
317 devc->m_state = ST_INIT;
318
319 /*
320 * Real time messages
321 */
322 case 0xf8:
323 /* midi clock */
324 devc->m_state = ST_INIT;
325 timer_ext_event(devc, TMR_CLOCK, 0);
326 break;
327
328 case 0xfA:
329 devc->m_state = ST_INIT;
330 timer_ext_event(devc, TMR_START, 0);
331 break;
332
333 case 0xFB:
334 devc->m_state = ST_INIT;
335 timer_ext_event(devc, TMR_CONTINUE, 0);
336 break;
337
338 case 0xFC:
339 devc->m_state = ST_INIT;
340 timer_ext_event(devc, TMR_STOP, 0);
341 break;
342
343 case 0xFE:
344 /* active sensing */
345 devc->m_state = ST_INIT;
346 break;
347
348 case 0xff:
349 /* printk( "midi hard reset"); */
350 devc->m_state = ST_INIT;
351 break;
352
353 default:
354 printk("unknown MIDI sysmsg %0x\n", midic);
355 devc->m_state = ST_INIT;
356 }
357 break;
358
359 case ST_MTC:
360 devc->m_state = ST_INIT;
361 printk("MTC frame %x02\n", midic);
362 break;
363
364 case ST_SYSEX:
365 if (midic == 0xf7)
366 {
367 printk("<EOX>");
368 devc->m_state = ST_INIT;
369 }
370 else
371 printk("%02x ", midic);
372 break;
373
374 case ST_SONGPOS:
375 BUFTEST(devc);
376 devc->m_buf[devc->m_ptr++] = midic;
377 if (devc->m_ptr == 2)
378 {
379 devc->m_state = ST_INIT;
380 devc->m_ptr = 0;
381 timer_ext_event(devc, TMR_SPP,
382 ((devc->m_buf[1] & 0x7f) << 7) |
383 (devc->m_buf[0] & 0x7f));
384 }
385 break;
386
387 case ST_DATABYTE:
388 BUFTEST(devc);
389 devc->m_buf[devc->m_ptr++] = midic;
390 if ((--devc->m_left) <= 0)
391 {
392 devc->m_state = ST_INIT;
393 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
394 devc->m_ptr = 0;
395 }
396 break;
397
398 default:
399 printk("Bad state %d ", devc->m_state);
400 devc->m_state = ST_INIT;
401 }
402 return 1;
403}
404
405static void mpu401_input_loop(struct mpu_config *devc)
406{
407 unsigned long flags;
408 int busy;
409 int n;
410
411 spin_lock_irqsave(&devc->lock,flags);
412 busy = devc->m_busy;
413 devc->m_busy = 1;
414 spin_unlock_irqrestore(&devc->lock,flags);
415
416 if (busy) /* Already inside the scanner */
417 return;
418
419 n = 50;
420
421 while (input_avail(devc) && n-- > 0)
422 {
423 unsigned char c = read_data(devc);
424
425 if (devc->mode == MODE_SYNTH)
426 {
427 mpu_input_scanner(devc, c);
428 }
429 else if (devc->opened & OPEN_READ && devc->inputintr != NULL)
430 devc->inputintr(devc->devno, c);
431 }
432 devc->m_busy = 0;
433}
434
435int intchk_mpu401(void *dev_id)
436{
437 struct mpu_config *devc;
438 int dev = (int) dev_id;
439
440 devc = &dev_conf[dev];
441 return input_avail(devc);
442}
443
444irqreturn_t mpuintr(int irq, void *dev_id, struct pt_regs *dummy)
445{
446 struct mpu_config *devc;
447 int dev = (int) dev_id;
448 int handled = 0;
449
450 devc = &dev_conf[dev];
451
452 if (input_avail(devc))
453 {
454 handled = 1;
455 if (devc->base != 0 && (devc->opened & OPEN_READ || devc->mode == MODE_SYNTH))
456 mpu401_input_loop(devc);
457 else
458 {
459 /* Dummy read (just to acknowledge the interrupt) */
460 read_data(devc);
461 }
462 }
463 return IRQ_RETVAL(handled);
464}
465
466static int mpu401_open(int dev, int mode,
467 void (*input) (int dev, unsigned char data),
468 void (*output) (int dev)
469)
470{
471 int err;
472 struct mpu_config *devc;
473 struct coproc_operations *coprocessor;
474
475 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
476 return -ENXIO;
477
478 devc = &dev_conf[dev];
479
480 if (devc->opened)
481 return -EBUSY;
482 /*
483 * Verify that the device is really running.
484 * Some devices (such as Ensoniq SoundScape don't
485 * work before the on board processor (OBP) is initialized
486 * by downloading its microcode.
487 */
488
489 if (!devc->initialized)
490 {
491 if (mpu401_status(devc) == 0xff) /* Bus float */
492 {
493 printk(KERN_ERR "mpu401: Device not initialized properly\n");
494 return -EIO;
495 }
496 reset_mpu401(devc);
497 }
498
499 if ( (coprocessor = midi_devs[dev]->coproc) != NULL )
500 {
501 if (!try_module_get(coprocessor->owner)) {
502 mpu401_close(dev);
503 return -ENODEV;
504 }
505
506 if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0)
507 {
508 printk(KERN_WARNING "MPU-401: Can't access coprocessor device\n");
509 mpu401_close(dev);
510 return err;
511 }
512 }
513
514 set_uart_mode(dev, devc, 1);
515 devc->mode = MODE_MIDI;
516 devc->synthno = 0;
517
518 mpu401_input_loop(devc);
519
520 devc->inputintr = input;
521 devc->opened = mode;
522
523 return 0;
524}
525
526static void mpu401_close(int dev)
527{
528 struct mpu_config *devc;
529 struct coproc_operations *coprocessor;
530
531 devc = &dev_conf[dev];
532 if (devc->uart_mode)
533 reset_mpu401(devc); /*
534 * This disables the UART mode
535 */
536 devc->mode = 0;
537 devc->inputintr = NULL;
538
539 coprocessor = midi_devs[dev]->coproc;
540 if (coprocessor) {
541 coprocessor->close(coprocessor->devc, COPR_MIDI);
542 module_put(coprocessor->owner);
543 }
544 devc->opened = 0;
545}
546
547static int mpu401_out(int dev, unsigned char midi_byte)
548{
549 int timeout;
550 unsigned long flags;
551
552 struct mpu_config *devc;
553
554 devc = &dev_conf[dev];
555
556 /*
557 * Sometimes it takes about 30000 loops before the output becomes ready
558 * (After reset). Normally it takes just about 10 loops.
559 */
560
561 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
562
563 spin_lock_irqsave(&devc->lock,flags);
564 if (!output_ready(devc))
565 {
566 printk(KERN_WARNING "mpu401: Send data timeout\n");
567 spin_unlock_irqrestore(&devc->lock,flags);
568 return 0;
569 }
570 write_data(devc, midi_byte);
571 spin_unlock_irqrestore(&devc->lock,flags);
572 return 1;
573}
574
575static int mpu401_command(int dev, mpu_command_rec * cmd)
576{
577 int i, timeout, ok;
578 int ret = 0;
579 unsigned long flags;
580 struct mpu_config *devc;
581
582 devc = &dev_conf[dev];
583
584 if (devc->uart_mode) /*
585 * Not possible in UART mode
586 */
587 {
588 printk(KERN_WARNING "mpu401: commands not possible in the UART mode\n");
589 return -EINVAL;
590 }
591 /*
592 * Test for input since pending input seems to block the output.
593 */
594 if (input_avail(devc))
595 mpu401_input_loop(devc);
596
597 /*
598 * Sometimes it takes about 50000 loops before the output becomes ready
599 * (After reset). Normally it takes just about 10 loops.
600 */
601
602 timeout = 50000;
603retry:
604 if (timeout-- <= 0)
605 {
606 printk(KERN_WARNING "mpu401: Command (0x%x) timeout\n", (int) cmd->cmd);
607 return -EIO;
608 }
609 spin_lock_irqsave(&devc->lock,flags);
610
611 if (!output_ready(devc))
612 {
613 spin_unlock_irqrestore(&devc->lock,flags);
614 goto retry;
615 }
616 write_command(devc, cmd->cmd);
617
618 ok = 0;
619 for (timeout = 50000; timeout > 0 && !ok; timeout--)
620 {
621 if (input_avail(devc))
622 {
623 if (devc->opened && devc->mode == MODE_SYNTH)
624 {
625 if (mpu_input_scanner(devc, read_data(devc)) == MPU_ACK)
626 ok = 1;
627 }
628 else
629 {
630 /* Device is not currently open. Use simpler method */
631 if (read_data(devc) == MPU_ACK)
632 ok = 1;
633 }
634 }
635 }
636 if (!ok)
637 {
638 spin_unlock_irqrestore(&devc->lock,flags);
639 return -EIO;
640 }
641 if (cmd->nr_args)
642 {
643 for (i = 0; i < cmd->nr_args; i++)
644 {
645 for (timeout = 3000; timeout > 0 && !output_ready(devc); timeout--);
646
647 if (!mpu401_out(dev, cmd->data[i]))
648 {
649 spin_unlock_irqrestore(&devc->lock,flags);
650 printk(KERN_WARNING "mpu401: Command (0x%x), parm send failed.\n", (int) cmd->cmd);
651 return -EIO;
652 }
653 }
654 }
655 ret = 0;
656 cmd->data[0] = 0;
657
658 if (cmd->nr_returns)
659 {
660 for (i = 0; i < cmd->nr_returns; i++)
661 {
662 ok = 0;
663 for (timeout = 5000; timeout > 0 && !ok; timeout--)
664 if (input_avail(devc))
665 {
666 cmd->data[i] = read_data(devc);
667 ok = 1;
668 }
669 if (!ok)
670 {
671 spin_unlock_irqrestore(&devc->lock,flags);
672 return -EIO;
673 }
674 }
675 }
676 spin_unlock_irqrestore(&devc->lock,flags);
677 return ret;
678}
679
680static int mpu_cmd(int dev, int cmd, int data)
681{
682 int ret;
683
684 static mpu_command_rec rec;
685
686 rec.cmd = cmd & 0xff;
687 rec.nr_args = ((cmd & 0xf0) == 0xE0);
688 rec.nr_returns = ((cmd & 0xf0) == 0xA0);
689 rec.data[0] = data & 0xff;
690
691 if ((ret = mpu401_command(dev, &rec)) < 0)
692 return ret;
693 return (unsigned char) rec.data[0];
694}
695
696static int mpu401_prefix_cmd(int dev, unsigned char status)
697{
698 struct mpu_config *devc = &dev_conf[dev];
699
700 if (devc->uart_mode)
701 return 1;
702
703 if (status < 0xf0)
704 {
705 if (mpu_cmd(dev, 0xD0, 0) < 0)
706 return 0;
707 return 1;
708 }
709 switch (status)
710 {
711 case 0xF0:
712 if (mpu_cmd(dev, 0xDF, 0) < 0)
713 return 0;
714 return 1;
715
716 default:
717 return 0;
718 }
719}
720
721static int mpu401_start_read(int dev)
722{
723 return 0;
724}
725
726static int mpu401_end_read(int dev)
727{
728 return 0;
729}
730
731static int mpu401_ioctl(int dev, unsigned cmd, void __user *arg)
732{
733 struct mpu_config *devc;
734 mpu_command_rec rec;
735 int val, ret;
736
737 devc = &dev_conf[dev];
738 switch (cmd)
739 {
740 case SNDCTL_MIDI_MPUMODE:
741 if (!(devc->capabilities & MPU_CAP_INTLG)) { /* No intelligent mode */
742 printk(KERN_WARNING "mpu401: Intelligent mode not supported by the HW\n");
743 return -EINVAL;
744 }
745 if (get_user(val, (int __user *)arg))
746 return -EFAULT;
747 set_uart_mode(dev, devc, !val);
748 return 0;
749
750 case SNDCTL_MIDI_MPUCMD:
751 if (copy_from_user(&rec, arg, sizeof(rec)))
752 return -EFAULT;
753 if ((ret = mpu401_command(dev, &rec)) < 0)
754 return ret;
755 if (copy_to_user(arg, &rec, sizeof(rec)))
756 return -EFAULT;
757 return 0;
758
759 default:
760 return -EINVAL;
761 }
762}
763
764static void mpu401_kick(int dev)
765{
766}
767
768static int mpu401_buffer_status(int dev)
769{
770 return 0; /*
771 * No data in buffers
772 */
773}
774
775static int mpu_synth_ioctl(int dev, unsigned int cmd, void __user *arg)
776{
777 int midi_dev;
778 struct mpu_config *devc;
779
780 midi_dev = synth_devs[dev]->midi_dev;
781
782 if (midi_dev < 0 || midi_dev > num_midis || midi_devs[midi_dev] == NULL)
783 return -ENXIO;
784
785 devc = &dev_conf[midi_dev];
786
787 switch (cmd)
788 {
789
790 case SNDCTL_SYNTH_INFO:
791 if (copy_to_user(arg, &mpu_synth_info[midi_dev],
792 sizeof(struct synth_info)))
793 return -EFAULT;
794 return 0;
795
796 case SNDCTL_SYNTH_MEMAVL:
797 return 0x7fffffff;
798
799 default:
800 return -EINVAL;
801 }
802}
803
804static int mpu_synth_open(int dev, int mode)
805{
806 int midi_dev, err;
807 struct mpu_config *devc;
808 struct coproc_operations *coprocessor;
809
810 midi_dev = synth_devs[dev]->midi_dev;
811
812 if (midi_dev < 0 || midi_dev > num_midis || midi_devs[midi_dev] == NULL)
813 return -ENXIO;
814
815 devc = &dev_conf[midi_dev];
816
817 /*
818 * Verify that the device is really running.
819 * Some devices (such as Ensoniq SoundScape don't
820 * work before the on board processor (OBP) is initialized
821 * by downloading its microcode.
822 */
823
824 if (!devc->initialized)
825 {
826 if (mpu401_status(devc) == 0xff) /* Bus float */
827 {
828 printk(KERN_ERR "mpu401: Device not initialized properly\n");
829 return -EIO;
830 }
831 reset_mpu401(devc);
832 }
833 if (devc->opened)
834 return -EBUSY;
835 devc->mode = MODE_SYNTH;
836 devc->synthno = dev;
837
838 devc->inputintr = NULL;
839
840 coprocessor = midi_devs[midi_dev]->coproc;
841 if (coprocessor) {
842 if (!try_module_get(coprocessor->owner))
843 return -ENODEV;
844
845 if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0)
846 {
847 printk(KERN_WARNING "mpu401: Can't access coprocessor device\n");
848 return err;
849 }
850 }
851 devc->opened = mode;
852 reset_mpu401(devc);
853
854 if (mode & OPEN_READ)
855 {
856 mpu_cmd(midi_dev, 0x8B, 0); /* Enable data in stop mode */
857 mpu_cmd(midi_dev, 0x34, 0); /* Return timing bytes in stop mode */
858 mpu_cmd(midi_dev, 0x87, 0); /* Enable pitch & controller */
859 }
860 return 0;
861}
862
863static void mpu_synth_close(int dev)
864{
865 int midi_dev;
866 struct mpu_config *devc;
867 struct coproc_operations *coprocessor;
868
869 midi_dev = synth_devs[dev]->midi_dev;
870
871 devc = &dev_conf[midi_dev];
872 mpu_cmd(midi_dev, 0x15, 0); /* Stop recording, playback and MIDI */
873 mpu_cmd(midi_dev, 0x8a, 0); /* Disable data in stopped mode */
874
875 devc->inputintr = NULL;
876
877 coprocessor = midi_devs[midi_dev]->coproc;
878 if (coprocessor) {
879 coprocessor->close(coprocessor->devc, COPR_MIDI);
880 module_put(coprocessor->owner);
881 }
882 devc->opened = 0;
883 devc->mode = 0;
884}
885
886#define MIDI_SYNTH_NAME "MPU-401 UART Midi"
887#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
888#include "midi_synth.h"
889
890static struct synth_operations mpu401_synth_proto =
891{
892 .owner = THIS_MODULE,
893 .id = "MPU401",
894 .info = NULL,
895 .midi_dev = 0,
896 .synth_type = SYNTH_TYPE_MIDI,
897 .synth_subtype = 0,
898 .open = mpu_synth_open,
899 .close = mpu_synth_close,
900 .ioctl = mpu_synth_ioctl,
901 .kill_note = midi_synth_kill_note,
902 .start_note = midi_synth_start_note,
903 .set_instr = midi_synth_set_instr,
904 .reset = midi_synth_reset,
905 .hw_control = midi_synth_hw_control,
906 .load_patch = midi_synth_load_patch,
907 .aftertouch = midi_synth_aftertouch,
908 .controller = midi_synth_controller,
909 .panning = midi_synth_panning,
910 .bender = midi_synth_bender,
911 .setup_voice = midi_synth_setup_voice,
912 .send_sysex = midi_synth_send_sysex
913};
914
915static struct synth_operations *mpu401_synth_operations[MAX_MIDI_DEV];
916
917static struct midi_operations mpu401_midi_proto =
918{
919 .owner = THIS_MODULE,
920 .info = {"MPU-401 Midi", 0, MIDI_CAP_MPU401, SNDCARD_MPU401},
921 .in_info = {0},
922 .open = mpu401_open,
923 .close = mpu401_close,
924 .ioctl = mpu401_ioctl,
925 .outputc = mpu401_out,
926 .start_read = mpu401_start_read,
927 .end_read = mpu401_end_read,
928 .kick = mpu401_kick,
929 .buffer_status = mpu401_buffer_status,
930 .prefix_cmd = mpu401_prefix_cmd
931};
932
933static struct midi_operations mpu401_midi_operations[MAX_MIDI_DEV];
934
935static void mpu401_chk_version(int n, struct mpu_config *devc)
936{
937 int tmp;
938 unsigned long flags;
939
940 devc->version = devc->revision = 0;
941
942 spin_lock_irqsave(&devc->lock,flags);
943 if ((tmp = mpu_cmd(n, 0xAC, 0)) < 0)
944 {
945 spin_unlock_irqrestore(&devc->lock,flags);
946 return;
947 }
948 if ((tmp & 0xf0) > 0x20) /* Why it's larger than 2.x ??? */
949 {
950 spin_unlock_irqrestore(&devc->lock,flags);
951 return;
952 }
953 devc->version = tmp;
954
955 if ((tmp = mpu_cmd(n, 0xAD, 0)) < 0)
956 {
957 devc->version = 0;
958 spin_unlock_irqrestore(&devc->lock,flags);
959 return;
960 }
961 devc->revision = tmp;
962 spin_unlock_irqrestore(&devc->lock,flags);
963}
964
965int attach_mpu401(struct address_info *hw_config, struct module *owner)
966{
967 unsigned long flags;
968 char revision_char;
969
970 int m, ret;
971 struct mpu_config *devc;
972
973 hw_config->slots[1] = -1;
974 m = sound_alloc_mididev();
975 if (m == -1)
976 {
977 printk(KERN_WARNING "MPU-401: Too many midi devices detected\n");
978 ret = -ENOMEM;
979 goto out_err;
980 }
981 devc = &dev_conf[m];
982 devc->base = hw_config->io_base;
983 devc->osp = hw_config->osp;
984 devc->irq = hw_config->irq;
985 devc->opened = 0;
986 devc->uart_mode = 0;
987 devc->initialized = 0;
988 devc->version = 0;
989 devc->revision = 0;
990 devc->capabilities = 0;
991 devc->timer_flag = 0;
992 devc->m_busy = 0;
993 devc->m_state = ST_INIT;
994 devc->shared_irq = hw_config->always_detect;
995 devc->irq = hw_config->irq;
996 spin_lock_init(&devc->lock);
997
998 if (devc->irq < 0)
999 {
1000 devc->irq *= -1;
1001 devc->shared_irq = 1;
1002 }
1003
1004 if (!hw_config->always_detect)
1005 {
1006 /* Verify the hardware again */
1007 if (!reset_mpu401(devc))
1008 {
1009 printk(KERN_WARNING "mpu401: Device didn't respond\n");
1010 ret = -ENODEV;
1011 goto out_mididev;
1012 }
1013 if (!devc->shared_irq)
1014 {
1015 if (request_irq(devc->irq, mpuintr, 0, "mpu401", (void *)m) < 0)
1016 {
1017 printk(KERN_WARNING "mpu401: Failed to allocate IRQ%d\n", devc->irq);
1018 ret = -ENOMEM;
1019 goto out_mididev;
1020 }
1021 }
1022 spin_lock_irqsave(&devc->lock,flags);
1023 mpu401_chk_version(m, devc);
1024 if (devc->version == 0)
1025 mpu401_chk_version(m, devc);
1026 spin_unlock_irqrestore(&devc->lock,flags);
1027 }
1028
1029 if (devc->version != 0)
1030 if (mpu_cmd(m, 0xC5, 0) >= 0) /* Set timebase OK */
1031 if (mpu_cmd(m, 0xE0, 120) >= 0) /* Set tempo OK */
1032 devc->capabilities |= MPU_CAP_INTLG; /* Supports intelligent mode */
1033
1034
1035 mpu401_synth_operations[m] = (struct synth_operations *)kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
1036
1037 if (mpu401_synth_operations[m] == NULL)
1038 {
1039 printk(KERN_ERR "mpu401: Can't allocate memory\n");
1040 ret = -ENOMEM;
1041 goto out_irq;
1042 }
1043 if (!(devc->capabilities & MPU_CAP_INTLG)) /* No intelligent mode */
1044 {
1045 memcpy((char *) mpu401_synth_operations[m],
1046 (char *) &std_midi_synth,
1047 sizeof(struct synth_operations));
1048 }
1049 else
1050 {
1051 memcpy((char *) mpu401_synth_operations[m],
1052 (char *) &mpu401_synth_proto,
1053 sizeof(struct synth_operations));
1054 }
1055 if (owner)
1056 mpu401_synth_operations[m]->owner = owner;
1057
1058 memcpy((char *) &mpu401_midi_operations[m],
1059 (char *) &mpu401_midi_proto,
1060 sizeof(struct midi_operations));
1061
1062 mpu401_midi_operations[m].converter = mpu401_synth_operations[m];
1063
1064 memcpy((char *) &mpu_synth_info[m],
1065 (char *) &mpu_synth_info_proto,
1066 sizeof(struct synth_info));
1067
1068 n_mpu_devs++;
1069
1070 if (devc->version == 0x20 && devc->revision >= 0x07) /* MusicQuest interface */
1071 {
1072 int ports = (devc->revision & 0x08) ? 32 : 16;
1073
1074 devc->capabilities |= MPU_CAP_SYNC | MPU_CAP_SMPTE |
1075 MPU_CAP_CLS | MPU_CAP_2PORT;
1076
1077 revision_char = (devc->revision == 0x7f) ? 'M' : ' ';
1078 sprintf(mpu_synth_info[m].name, "MQX-%d%c MIDI Interface #%d",
1079 ports,
1080 revision_char,
1081 n_mpu_devs);
1082 }
1083 else
1084 {
1085 revision_char = devc->revision ? devc->revision + '@' : ' ';
1086 if ((int) devc->revision > ('Z' - '@'))
1087 revision_char = '+';
1088
1089 devc->capabilities |= MPU_CAP_SYNC | MPU_CAP_FSK;
1090
1091 if (hw_config->name)
1092 sprintf(mpu_synth_info[m].name, "%s (MPU401)", hw_config->name);
1093 else
1094 sprintf(mpu_synth_info[m].name,
1095 "MPU-401 %d.%d%c Midi interface #%d",
1096 (int) (devc->version & 0xf0) >> 4,
1097 devc->version & 0x0f,
1098 revision_char,
1099 n_mpu_devs);
1100 }
1101
1102 strcpy(mpu401_midi_operations[m].info.name,
1103 mpu_synth_info[m].name);
1104
1105 conf_printf(mpu_synth_info[m].name, hw_config);
1106
1107 mpu401_synth_operations[m]->midi_dev = devc->devno = m;
1108 mpu401_synth_operations[devc->devno]->info = &mpu_synth_info[devc->devno];
1109
1110 if (devc->capabilities & MPU_CAP_INTLG) /* Intelligent mode */
1111 hw_config->slots[2] = mpu_timer_init(m);
1112
1113 midi_devs[m] = &mpu401_midi_operations[devc->devno];
1114
1115 if (owner)
1116 midi_devs[m]->owner = owner;
1117
1118 hw_config->slots[1] = m;
1119 sequencer_init();
1120
1121 return 0;
1122
1123out_irq:
1124 free_irq(devc->irq, (void *)m);
1125out_mididev:
1126 sound_unload_mididev(m);
1127out_err:
1128 release_region(hw_config->io_base, 2);
1129 return ret;
1130}
1131
1132static int reset_mpu401(struct mpu_config *devc)
1133{
1134 unsigned long flags;
1135 int ok, timeout, n;
1136 int timeout_limit;
1137
1138 /*
1139 * Send the RESET command. Try again if no success at the first time.
1140 * (If the device is in the UART mode, it will not ack the reset cmd).
1141 */
1142
1143 ok = 0;
1144
1145 timeout_limit = devc->initialized ? 30000 : 100000;
1146 devc->initialized = 1;
1147
1148 for (n = 0; n < 2 && !ok; n++)
1149 {
1150 for (timeout = timeout_limit; timeout > 0 && !ok; timeout--)
1151 ok = output_ready(devc);
1152
1153 write_command(devc, MPU_RESET); /*
1154 * Send MPU-401 RESET Command
1155 */
1156
1157 /*
1158 * Wait at least 25 msec. This method is not accurate so let's make the
1159 * loop bit longer. Cannot sleep since this is called during boot.
1160 */
1161
1162 for (timeout = timeout_limit * 2; timeout > 0 && !ok; timeout--)
1163 {
1164 spin_lock_irqsave(&devc->lock,flags);
1165 if (input_avail(devc))
1166 if (read_data(devc) == MPU_ACK)
1167 ok = 1;
1168 spin_unlock_irqrestore(&devc->lock,flags);
1169 }
1170
1171 }
1172
1173 devc->m_state = ST_INIT;
1174 devc->m_ptr = 0;
1175 devc->m_left = 0;
1176 devc->last_status = 0;
1177 devc->uart_mode = 0;
1178
1179 return ok;
1180}
1181
1182static void set_uart_mode(int dev, struct mpu_config *devc, int arg)
1183{
1184 if (!arg && (devc->capabilities & MPU_CAP_INTLG))
1185 return;
1186 if ((devc->uart_mode == 0) == (arg == 0))
1187 return; /* Already set */
1188 reset_mpu401(devc); /* This exits the uart mode */
1189
1190 if (arg)
1191 {
1192 if (mpu_cmd(dev, UART_MODE_ON, 0) < 0)
1193 {
1194 printk(KERN_ERR "mpu401: Can't enter UART mode\n");
1195 devc->uart_mode = 0;
1196 return;
1197 }
1198 }
1199 devc->uart_mode = arg;
1200
1201}
1202
1203int probe_mpu401(struct address_info *hw_config, struct resource *ports)
1204{
1205 int ok = 0;
1206 struct mpu_config tmp_devc;
1207
1208 tmp_devc.base = hw_config->io_base;
1209 tmp_devc.irq = hw_config->irq;
1210 tmp_devc.initialized = 0;
1211 tmp_devc.opened = 0;
1212 tmp_devc.osp = hw_config->osp;
1213
1214 if (hw_config->always_detect)
1215 return 1;
1216
1217 if (inb(hw_config->io_base + 1) == 0xff)
1218 {
1219 DDB(printk("MPU401: Port %x looks dead.\n", hw_config->io_base));
1220 return 0; /* Just bus float? */
1221 }
1222 ok = reset_mpu401(&tmp_devc);
1223
1224 if (!ok)
1225 {
1226 DDB(printk("MPU401: Reset failed on port %x\n", hw_config->io_base));
1227 }
1228 return ok;
1229}
1230
1231void unload_mpu401(struct address_info *hw_config)
1232{
1233 void *p;
1234 int n=hw_config->slots[1];
1235
1236 if (n != -1) {
1237 release_region(hw_config->io_base, 2);
1238 if (hw_config->always_detect == 0 && hw_config->irq > 0)
1239 free_irq(hw_config->irq, (void *)n);
1240 p=mpu401_synth_operations[n];
1241 sound_unload_mididev(n);
1242 sound_unload_timerdev(hw_config->slots[2]);
1243 if(p)
1244 kfree(p);
1245 }
1246}
1247
1248/*****************************************************
1249 * Timer stuff
1250 ****************************************************/
1251
1252static volatile int timer_initialized = 0, timer_open = 0, tmr_running = 0;
1253static volatile int curr_tempo, curr_timebase, hw_timebase;
1254static int max_timebase = 8; /* 8*24=192 ppqn */
1255static volatile unsigned long next_event_time;
1256static volatile unsigned long curr_ticks, curr_clocks;
1257static unsigned long prev_event_time;
1258static int metronome_mode;
1259
1260static unsigned long clocks2ticks(unsigned long clocks)
1261{
1262 /*
1263 * The MPU-401 supports just a limited set of possible timebase values.
1264 * Since the applications require more choices, the driver has to
1265 * program the HW to do its best and to convert between the HW and
1266 * actual timebases.
1267 */
1268 return ((clocks * curr_timebase) + (hw_timebase / 2)) / hw_timebase;
1269}
1270
1271static void set_timebase(int midi_dev, int val)
1272{
1273 int hw_val;
1274
1275 if (val < 48)
1276 val = 48;
1277 if (val > 1000)
1278 val = 1000;
1279
1280 hw_val = val;
1281 hw_val = (hw_val + 12) / 24;
1282 if (hw_val > max_timebase)
1283 hw_val = max_timebase;
1284
1285 if (mpu_cmd(midi_dev, 0xC0 | (hw_val & 0x0f), 0) < 0)
1286 {
1287 printk(KERN_WARNING "mpu401: Can't set HW timebase to %d\n", hw_val * 24);
1288 return;
1289 }
1290 hw_timebase = hw_val * 24;
1291 curr_timebase = val;
1292
1293}
1294
1295static void tmr_reset(struct mpu_config *devc)
1296{
1297 unsigned long flags;
1298
1299 spin_lock_irqsave(&devc->lock,flags);
1300 next_event_time = (unsigned long) -1;
1301 prev_event_time = 0;
1302 curr_ticks = curr_clocks = 0;
1303 spin_unlock_irqrestore(&devc->lock,flags);
1304}
1305
1306static void set_timer_mode(int midi_dev)
1307{
1308 if (timer_mode & TMR_MODE_CLS)
1309 mpu_cmd(midi_dev, 0x3c, 0); /* Use CLS sync */
1310 else if (timer_mode & TMR_MODE_SMPTE)
1311 mpu_cmd(midi_dev, 0x3d, 0); /* Use SMPTE sync */
1312
1313 if (timer_mode & TMR_INTERNAL)
1314 {
1315 mpu_cmd(midi_dev, 0x80, 0); /* Use MIDI sync */
1316 }
1317 else
1318 {
1319 if (timer_mode & (TMR_MODE_MIDI | TMR_MODE_CLS))
1320 {
1321 mpu_cmd(midi_dev, 0x82, 0); /* Use MIDI sync */
1322 mpu_cmd(midi_dev, 0x91, 0); /* Enable ext MIDI ctrl */
1323 }
1324 else if (timer_mode & TMR_MODE_FSK)
1325 mpu_cmd(midi_dev, 0x81, 0); /* Use FSK sync */
1326 }
1327}
1328
1329static void stop_metronome(int midi_dev)
1330{
1331 mpu_cmd(midi_dev, 0x84, 0); /* Disable metronome */
1332}
1333
1334static void setup_metronome(int midi_dev)
1335{
1336 int numerator, denominator;
1337 int clks_per_click, num_32nds_per_beat;
1338 int beats_per_measure;
1339
1340 numerator = ((unsigned) metronome_mode >> 24) & 0xff;
1341 denominator = ((unsigned) metronome_mode >> 16) & 0xff;
1342 clks_per_click = ((unsigned) metronome_mode >> 8) & 0xff;
1343 num_32nds_per_beat = (unsigned) metronome_mode & 0xff;
1344 beats_per_measure = (numerator * 4) >> denominator;
1345
1346 if (!metronome_mode)
1347 mpu_cmd(midi_dev, 0x84, 0); /* Disable metronome */
1348 else
1349 {
1350 mpu_cmd(midi_dev, 0xE4, clks_per_click);
1351 mpu_cmd(midi_dev, 0xE6, beats_per_measure);
1352 mpu_cmd(midi_dev, 0x83, 0); /* Enable metronome without accents */
1353 }
1354}
1355
1356static int mpu_start_timer(int midi_dev)
1357{
1358 struct mpu_config *devc= &dev_conf[midi_dev];
1359
1360 tmr_reset(devc);
1361 set_timer_mode(midi_dev);
1362
1363 if (tmr_running)
1364 return TIMER_NOT_ARMED; /* Already running */
1365
1366 if (timer_mode & TMR_INTERNAL)
1367 {
1368 mpu_cmd(midi_dev, 0x02, 0); /* Send MIDI start */
1369 tmr_running = 1;
1370 return TIMER_NOT_ARMED;
1371 }
1372 else
1373 {
1374 mpu_cmd(midi_dev, 0x35, 0); /* Enable mode messages to PC */
1375 mpu_cmd(midi_dev, 0x38, 0); /* Enable sys common messages to PC */
1376 mpu_cmd(midi_dev, 0x39, 0); /* Enable real time messages to PC */
1377 mpu_cmd(midi_dev, 0x97, 0); /* Enable system exclusive messages to PC */
1378 }
1379 return TIMER_ARMED;
1380}
1381
1382static int mpu_timer_open(int dev, int mode)
1383{
1384 int midi_dev = sound_timer_devs[dev]->devlink;
1385 struct mpu_config *devc= &dev_conf[midi_dev];
1386
1387 if (timer_open)
1388 return -EBUSY;
1389
1390 tmr_reset(devc);
1391 curr_tempo = 50;
1392 mpu_cmd(midi_dev, 0xE0, 50);
1393 curr_timebase = hw_timebase = 120;
1394 set_timebase(midi_dev, 120);
1395 timer_open = 1;
1396 metronome_mode = 0;
1397 set_timer_mode(midi_dev);
1398
1399 mpu_cmd(midi_dev, 0xe7, 0x04); /* Send all clocks to host */
1400 mpu_cmd(midi_dev, 0x95, 0); /* Enable clock to host */
1401
1402 return 0;
1403}
1404
1405static void mpu_timer_close(int dev)
1406{
1407 int midi_dev = sound_timer_devs[dev]->devlink;
1408
1409 timer_open = tmr_running = 0;
1410 mpu_cmd(midi_dev, 0x15, 0); /* Stop all */
1411 mpu_cmd(midi_dev, 0x94, 0); /* Disable clock to host */
1412 mpu_cmd(midi_dev, 0x8c, 0); /* Disable measure end messages to host */
1413 stop_metronome(midi_dev);
1414}
1415
1416static int mpu_timer_event(int dev, unsigned char *event)
1417{
1418 unsigned char command = event[1];
1419 unsigned long parm = *(unsigned int *) &event[4];
1420 int midi_dev = sound_timer_devs[dev]->devlink;
1421
1422 switch (command)
1423 {
1424 case TMR_WAIT_REL:
1425 parm += prev_event_time;
1426 case TMR_WAIT_ABS:
1427 if (parm > 0)
1428 {
1429 long time;
1430
1431 if (parm <= curr_ticks) /* It's the time */
1432 return TIMER_NOT_ARMED;
1433 time = parm;
1434 next_event_time = prev_event_time = time;
1435
1436 return TIMER_ARMED;
1437 }
1438 break;
1439
1440 case TMR_START:
1441 if (tmr_running)
1442 break;
1443 return mpu_start_timer(midi_dev);
1444
1445 case TMR_STOP:
1446 mpu_cmd(midi_dev, 0x01, 0); /* Send MIDI stop */
1447 stop_metronome(midi_dev);
1448 tmr_running = 0;
1449 break;
1450
1451 case TMR_CONTINUE:
1452 if (tmr_running)
1453 break;
1454 mpu_cmd(midi_dev, 0x03, 0); /* Send MIDI continue */
1455 setup_metronome(midi_dev);
1456 tmr_running = 1;
1457 break;
1458
1459 case TMR_TEMPO:
1460 if (parm)
1461 {
1462 if (parm < 8)
1463 parm = 8;
1464 if (parm > 250)
1465 parm = 250;
1466 if (mpu_cmd(midi_dev, 0xE0, parm) < 0)
1467 printk(KERN_WARNING "mpu401: Can't set tempo to %d\n", (int) parm);
1468 curr_tempo = parm;
1469 }
1470 break;
1471
1472 case TMR_ECHO:
1473 seq_copy_to_input(event, 8);
1474 break;
1475
1476 case TMR_TIMESIG:
1477 if (metronome_mode) /* Metronome enabled */
1478 {
1479 metronome_mode = parm;
1480 setup_metronome(midi_dev);
1481 }
1482 break;
1483
1484 default:;
1485 }
1486 return TIMER_NOT_ARMED;
1487}
1488
1489static unsigned long mpu_timer_get_time(int dev)
1490{
1491 if (!timer_open)
1492 return 0;
1493
1494 return curr_ticks;
1495}
1496
1497static int mpu_timer_ioctl(int dev, unsigned int command, void __user *arg)
1498{
1499 int midi_dev = sound_timer_devs[dev]->devlink;
1500 int __user *p = (int __user *)arg;
1501
1502 switch (command)
1503 {
1504 case SNDCTL_TMR_SOURCE:
1505 {
1506 int parm;
1507
1508 if (get_user(parm, p))
1509 return -EFAULT;
1510 parm &= timer_caps;
1511
1512 if (parm != 0)
1513 {
1514 timer_mode = parm;
1515
1516 if (timer_mode & TMR_MODE_CLS)
1517 mpu_cmd(midi_dev, 0x3c, 0); /* Use CLS sync */
1518 else if (timer_mode & TMR_MODE_SMPTE)
1519 mpu_cmd(midi_dev, 0x3d, 0); /* Use SMPTE sync */
1520 }
1521 if (put_user(timer_mode, p))
1522 return -EFAULT;
1523 return timer_mode;
1524 }
1525 break;
1526
1527 case SNDCTL_TMR_START:
1528 mpu_start_timer(midi_dev);
1529 return 0;
1530
1531 case SNDCTL_TMR_STOP:
1532 tmr_running = 0;
1533 mpu_cmd(midi_dev, 0x01, 0); /* Send MIDI stop */
1534 stop_metronome(midi_dev);
1535 return 0;
1536
1537 case SNDCTL_TMR_CONTINUE:
1538 if (tmr_running)
1539 return 0;
1540 tmr_running = 1;
1541 mpu_cmd(midi_dev, 0x03, 0); /* Send MIDI continue */
1542 return 0;
1543
1544 case SNDCTL_TMR_TIMEBASE:
1545 {
1546 int val;
1547 if (get_user(val, p))
1548 return -EFAULT;
1549 if (val)
1550 set_timebase(midi_dev, val);
1551 if (put_user(curr_timebase, p))
1552 return -EFAULT;
1553 return curr_timebase;
1554 }
1555 break;
1556
1557 case SNDCTL_TMR_TEMPO:
1558 {
1559 int val;
1560 int ret;
1561
1562 if (get_user(val, p))
1563 return -EFAULT;
1564
1565 if (val)
1566 {
1567 if (val < 8)
1568 val = 8;
1569 if (val > 250)
1570 val = 250;
1571 if ((ret = mpu_cmd(midi_dev, 0xE0, val)) < 0)
1572 {
1573 printk(KERN_WARNING "mpu401: Can't set tempo to %d\n", (int) val);
1574 return ret;
1575 }
1576 curr_tempo = val;
1577 }
1578 if (put_user(curr_tempo, p))
1579 return -EFAULT;
1580 return curr_tempo;
1581 }
1582 break;
1583
1584 case SNDCTL_SEQ_CTRLRATE:
1585 {
1586 int val;
1587 if (get_user(val, p))
1588 return -EFAULT;
1589
1590 if (val != 0) /* Can't change */
1591 return -EINVAL;
1592 val = ((curr_tempo * curr_timebase) + 30)/60;
1593 if (put_user(val, p))
1594 return -EFAULT;
1595 return val;
1596 }
1597 break;
1598
1599 case SNDCTL_SEQ_GETTIME:
1600 if (put_user(curr_ticks, p))
1601 return -EFAULT;
1602 return curr_ticks;
1603
1604 case SNDCTL_TMR_METRONOME:
1605 if (get_user(metronome_mode, p))
1606 return -EFAULT;
1607 setup_metronome(midi_dev);
1608 return 0;
1609
1610 default:;
1611 }
1612 return -EINVAL;
1613}
1614
1615static void mpu_timer_arm(int dev, long time)
1616{
1617 if (time < 0)
1618 time = curr_ticks + 1;
1619 else if (time <= curr_ticks) /* It's the time */
1620 return;
1621 next_event_time = prev_event_time = time;
1622 return;
1623}
1624
1625static struct sound_timer_operations mpu_timer =
1626{
1627 .owner = THIS_MODULE,
1628 .info = {"MPU-401 Timer", 0},
1629 .priority = 10, /* Priority */
1630 .devlink = 0, /* Local device link */
1631 .open = mpu_timer_open,
1632 .close = mpu_timer_close,
1633 .event = mpu_timer_event,
1634 .get_time = mpu_timer_get_time,
1635 .ioctl = mpu_timer_ioctl,
1636 .arm_timer = mpu_timer_arm
1637};
1638
1639static void mpu_timer_interrupt(void)
1640{
1641 if (!timer_open)
1642 return;
1643
1644 if (!tmr_running)
1645 return;
1646
1647 curr_clocks++;
1648 curr_ticks = clocks2ticks(curr_clocks);
1649
1650 if (curr_ticks >= next_event_time)
1651 {
1652 next_event_time = (unsigned long) -1;
1653 sequencer_timer(0);
1654 }
1655}
1656
1657static void timer_ext_event(struct mpu_config *devc, int event, int parm)
1658{
1659 int midi_dev = devc->devno;
1660
1661 if (!devc->timer_flag)
1662 return;
1663
1664 switch (event)
1665 {
1666 case TMR_CLOCK:
1667 printk("<MIDI clk>");
1668 break;
1669
1670 case TMR_START:
1671 printk("Ext MIDI start\n");
1672 if (!tmr_running)
1673 {
1674 if (timer_mode & TMR_EXTERNAL)
1675 {
1676 tmr_running = 1;
1677 setup_metronome(midi_dev);
1678 next_event_time = 0;
1679 STORE(SEQ_START_TIMER());
1680 }
1681 }
1682 break;
1683
1684 case TMR_STOP:
1685 printk("Ext MIDI stop\n");
1686 if (timer_mode & TMR_EXTERNAL)
1687 {
1688 tmr_running = 0;
1689 stop_metronome(midi_dev);
1690 STORE(SEQ_STOP_TIMER());
1691 }
1692 break;
1693
1694 case TMR_CONTINUE:
1695 printk("Ext MIDI continue\n");
1696 if (timer_mode & TMR_EXTERNAL)
1697 {
1698 tmr_running = 1;
1699 setup_metronome(midi_dev);
1700 STORE(SEQ_CONTINUE_TIMER());
1701 }
1702 break;
1703
1704 case TMR_SPP:
1705 printk("Songpos: %d\n", parm);
1706 if (timer_mode & TMR_EXTERNAL)
1707 {
1708 STORE(SEQ_SONGPOS(parm));
1709 }
1710 break;
1711 }
1712}
1713
1714static int mpu_timer_init(int midi_dev)
1715{
1716 struct mpu_config *devc;
1717 int n;
1718
1719 devc = &dev_conf[midi_dev];
1720
1721 if (timer_initialized)
1722 return -1; /* There is already a similar timer */
1723
1724 timer_initialized = 1;
1725
1726 mpu_timer.devlink = midi_dev;
1727 dev_conf[midi_dev].timer_flag = 1;
1728
1729 n = sound_alloc_timerdev();
1730 if (n == -1)
1731 n = 0;
1732 sound_timer_devs[n] = &mpu_timer;
1733
1734 if (devc->version < 0x20) /* Original MPU-401 */
1735 timer_caps = TMR_INTERNAL | TMR_EXTERNAL | TMR_MODE_FSK | TMR_MODE_MIDI;
1736 else
1737 {
1738 /*
1739 * The version number 2.0 is used (at least) by the
1740 * MusicQuest cards and the Roland Super-MPU.
1741 *
1742 * MusicQuest has given a special meaning to the bits of the
1743 * revision number. The Super-MPU returns 0.
1744 */
1745
1746 if (devc->revision)
1747 timer_caps |= TMR_EXTERNAL | TMR_MODE_MIDI;
1748
1749 if (devc->revision & 0x02)
1750 timer_caps |= TMR_MODE_CLS;
1751
1752
1753 if (devc->revision & 0x40)
1754 max_timebase = 10; /* Has the 216 and 240 ppqn modes */
1755 }
1756
1757 timer_mode = (TMR_INTERNAL | TMR_MODE_MIDI) & timer_caps;
1758 return n;
1759
1760}
1761
1762EXPORT_SYMBOL(probe_mpu401);
1763EXPORT_SYMBOL(attach_mpu401);
1764EXPORT_SYMBOL(unload_mpu401);
1765EXPORT_SYMBOL(intchk_mpu401);
1766EXPORT_SYMBOL(mpuintr);
1767
1768static struct address_info cfg;
1769
1770static int io = -1;
1771static int irq = -1;
1772
1773module_param(irq, int, 0);
1774module_param(io, int, 0);
1775
1776static int __init init_mpu401(void)
1777{
1778 int ret;
1779 /* Can be loaded either for module use or to provide functions
1780 to others */
1781 if (io != -1 && irq != -1) {
1782 struct resource *ports;
1783 cfg.irq = irq;
1784 cfg.io_base = io;
1785 ports = request_region(io, 2, "mpu401");
1786 if (!ports)
1787 return -EBUSY;
1788 if (probe_mpu401(&cfg, ports) == 0) {
1789 release_region(io, 2);
1790 return -ENODEV;
1791 }
1792 if ((ret = attach_mpu401(&cfg, THIS_MODULE)))
1793 return ret;
1794 }
1795
1796 return 0;
1797}
1798
1799static void __exit cleanup_mpu401(void)
1800{
1801 if (io != -1 && irq != -1) {
1802 /* Check for use by, for example, sscape driver */
1803 unload_mpu401(&cfg);
1804 }
1805}
1806
1807module_init(init_mpu401);
1808module_exit(cleanup_mpu401);
1809
1810#ifndef MODULE
1811static int __init setup_mpu401(char *str)
1812{
1813 /* io, irq */
1814 int ints[3];
1815
1816 str = get_options(str, ARRAY_SIZE(ints), ints);
1817
1818 io = ints[1];
1819 irq = ints[2];
1820
1821 return 1;
1822}
1823
1824__setup("mpu401=", setup_mpu401);
1825#endif
1826MODULE_LICENSE("GPL");
diff --git a/sound/oss/mpu401.h b/sound/oss/mpu401.h
new file mode 100644
index 000000000000..bdc5bde641e6
--- /dev/null
+++ b/sound/oss/mpu401.h
@@ -0,0 +1,14 @@
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, struct pt_regs * dummy);
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);
12
13int intchk_mpu401(void *dev_id);
14irqreturn_t mpuintr(int irq, void *dev_id, struct pt_regs * dummy);
diff --git a/sound/oss/msnd.c b/sound/oss/msnd.c
new file mode 100644
index 000000000000..4f1ff1bccdce
--- /dev/null
+++ b/sound/oss/msnd.c
@@ -0,0 +1,419 @@
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 * $Id: msnd.c,v 1.17 1999/03/21 16:50:09 andrewtv Exp $
24 *
25 ********************************************************************/
26
27#include <linux/version.h>
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/slab.h>
31#include <linux/vmalloc.h>
32#include <linux/types.h>
33#include <linux/delay.h>
34#include <linux/mm.h>
35#include <linux/init.h>
36#include <linux/interrupt.h>
37
38#include <asm/io.h>
39#include <asm/uaccess.h>
40#include <linux/spinlock.h>
41#include <asm/irq.h>
42#include "msnd.h"
43
44#define LOGNAME "msnd"
45
46#define MSND_MAX_DEVS 4
47
48static multisound_dev_t *devs[MSND_MAX_DEVS];
49static int num_devs;
50
51int __init msnd_register(multisound_dev_t *dev)
52{
53 int i;
54
55 for (i = 0; i < MSND_MAX_DEVS; ++i)
56 if (devs[i] == NULL)
57 break;
58
59 if (i == MSND_MAX_DEVS)
60 return -ENOMEM;
61
62 devs[i] = dev;
63 ++num_devs;
64 return 0;
65}
66
67void msnd_unregister(multisound_dev_t *dev)
68{
69 int i;
70
71 for (i = 0; i < MSND_MAX_DEVS; ++i)
72 if (devs[i] == dev)
73 break;
74
75 if (i == MSND_MAX_DEVS) {
76 printk(KERN_WARNING LOGNAME ": Unregistering unknown device\n");
77 return;
78 }
79
80 devs[i] = NULL;
81 --num_devs;
82}
83
84void msnd_init_queue(void __iomem *base, int start, int size)
85{
86 writew(PCTODSP_BASED(start), base + JQS_wStart);
87 writew(PCTODSP_OFFSET(size) - 1, base + JQS_wSize);
88 writew(0, base + JQS_wHead);
89 writew(0, base + JQS_wTail);
90}
91
92void msnd_fifo_init(msnd_fifo *f)
93{
94 f->data = NULL;
95}
96
97void msnd_fifo_free(msnd_fifo *f)
98{
99 if (f->data) {
100 vfree(f->data);
101 f->data = NULL;
102 }
103}
104
105int msnd_fifo_alloc(msnd_fifo *f, size_t n)
106{
107 msnd_fifo_free(f);
108 f->data = (char *)vmalloc(n);
109 f->n = n;
110 f->tail = 0;
111 f->head = 0;
112 f->len = 0;
113
114 if (!f->data)
115 return -ENOMEM;
116
117 return 0;
118}
119
120void msnd_fifo_make_empty(msnd_fifo *f)
121{
122 f->len = f->tail = f->head = 0;
123}
124
125int msnd_fifo_write_io(msnd_fifo *f, char __iomem *buf, size_t len)
126{
127 int count = 0;
128
129 while ((count < len) && (f->len != f->n)) {
130
131 int nwritten;
132
133 if (f->head <= f->tail) {
134 nwritten = len - count;
135 if (nwritten > f->n - f->tail)
136 nwritten = f->n - f->tail;
137 }
138 else {
139 nwritten = f->head - f->tail;
140 if (nwritten > len - count)
141 nwritten = len - count;
142 }
143
144 memcpy_fromio(f->data + f->tail, buf, nwritten);
145
146 count += nwritten;
147 buf += nwritten;
148 f->len += nwritten;
149 f->tail += nwritten;
150 f->tail %= f->n;
151 }
152
153 return count;
154}
155
156int msnd_fifo_write(msnd_fifo *f, const char *buf, size_t len)
157{
158 int count = 0;
159
160 while ((count < len) && (f->len != f->n)) {
161
162 int nwritten;
163
164 if (f->head <= f->tail) {
165 nwritten = len - count;
166 if (nwritten > f->n - f->tail)
167 nwritten = f->n - f->tail;
168 }
169 else {
170 nwritten = f->head - f->tail;
171 if (nwritten > len - count)
172 nwritten = len - count;
173 }
174
175 memcpy(f->data + f->tail, buf, nwritten);
176
177 count += nwritten;
178 buf += nwritten;
179 f->len += nwritten;
180 f->tail += nwritten;
181 f->tail %= f->n;
182 }
183
184 return count;
185}
186
187int msnd_fifo_read_io(msnd_fifo *f, char __iomem *buf, size_t len)
188{
189 int count = 0;
190
191 while ((count < len) && (f->len > 0)) {
192
193 int nread;
194
195 if (f->tail <= f->head) {
196 nread = len - count;
197 if (nread > f->n - f->head)
198 nread = f->n - f->head;
199 }
200 else {
201 nread = f->tail - f->head;
202 if (nread > len - count)
203 nread = len - count;
204 }
205
206 memcpy_toio(buf, f->data + f->head, nread);
207
208 count += nread;
209 buf += nread;
210 f->len -= nread;
211 f->head += nread;
212 f->head %= f->n;
213 }
214
215 return count;
216}
217
218int msnd_fifo_read(msnd_fifo *f, char *buf, size_t len)
219{
220 int count = 0;
221
222 while ((count < len) && (f->len > 0)) {
223
224 int nread;
225
226 if (f->tail <= f->head) {
227 nread = len - count;
228 if (nread > f->n - f->head)
229 nread = f->n - f->head;
230 }
231 else {
232 nread = f->tail - f->head;
233 if (nread > len - count)
234 nread = len - count;
235 }
236
237 memcpy(buf, f->data + f->head, nread);
238
239 count += nread;
240 buf += nread;
241 f->len -= nread;
242 f->head += nread;
243 f->head %= f->n;
244 }
245
246 return count;
247}
248
249static int msnd_wait_TXDE(multisound_dev_t *dev)
250{
251 register unsigned int io = dev->io;
252 register int timeout = 1000;
253
254 while(timeout-- > 0)
255 if (msnd_inb(io + HP_ISR) & HPISR_TXDE)
256 return 0;
257
258 return -EIO;
259}
260
261static int msnd_wait_HC0(multisound_dev_t *dev)
262{
263 register unsigned int io = dev->io;
264 register int timeout = 1000;
265
266 while(timeout-- > 0)
267 if (!(msnd_inb(io + HP_CVR) & HPCVR_HC))
268 return 0;
269
270 return -EIO;
271}
272
273int msnd_send_dsp_cmd(multisound_dev_t *dev, BYTE cmd)
274{
275 unsigned long flags;
276
277 spin_lock_irqsave(&dev->lock, flags);
278 if (msnd_wait_HC0(dev) == 0) {
279 msnd_outb(cmd, dev->io + HP_CVR);
280 spin_unlock_irqrestore(&dev->lock, flags);
281 return 0;
282 }
283 spin_unlock_irqrestore(&dev->lock, flags);
284
285 printk(KERN_DEBUG LOGNAME ": Send DSP command timeout\n");
286
287 return -EIO;
288}
289
290int msnd_send_word(multisound_dev_t *dev, unsigned char high,
291 unsigned char mid, unsigned char low)
292{
293 register unsigned int io = dev->io;
294
295 if (msnd_wait_TXDE(dev) == 0) {
296 msnd_outb(high, io + HP_TXH);
297 msnd_outb(mid, io + HP_TXM);
298 msnd_outb(low, io + HP_TXL);
299 return 0;
300 }
301
302 printk(KERN_DEBUG LOGNAME ": Send host word timeout\n");
303
304 return -EIO;
305}
306
307int msnd_upload_host(multisound_dev_t *dev, char *bin, int len)
308{
309 int i;
310
311 if (len % 3 != 0) {
312 printk(KERN_WARNING LOGNAME ": Upload host data not multiple of 3!\n");
313 return -EINVAL;
314 }
315
316 for (i = 0; i < len; i += 3)
317 if (msnd_send_word(dev, bin[i], bin[i + 1], bin[i + 2]) != 0)
318 return -EIO;
319
320 msnd_inb(dev->io + HP_RXL);
321 msnd_inb(dev->io + HP_CVR);
322
323 return 0;
324}
325
326int msnd_enable_irq(multisound_dev_t *dev)
327{
328 unsigned long flags;
329
330 if (dev->irq_ref++)
331 return 0;
332
333 printk(KERN_DEBUG LOGNAME ": Enabling IRQ\n");
334
335 spin_lock_irqsave(&dev->lock, flags);
336 if (msnd_wait_TXDE(dev) == 0) {
337 msnd_outb(msnd_inb(dev->io + HP_ICR) | HPICR_TREQ, dev->io + HP_ICR);
338 if (dev->type == msndClassic)
339 msnd_outb(dev->irqid, dev->io + HP_IRQM);
340 msnd_outb(msnd_inb(dev->io + HP_ICR) & ~HPICR_TREQ, dev->io + HP_ICR);
341 msnd_outb(msnd_inb(dev->io + HP_ICR) | HPICR_RREQ, dev->io + HP_ICR);
342 enable_irq(dev->irq);
343 msnd_init_queue(dev->DSPQ, dev->dspq_data_buff, dev->dspq_buff_size);
344 spin_unlock_irqrestore(&dev->lock, flags);
345 return 0;
346 }
347 spin_unlock_irqrestore(&dev->lock, flags);
348
349 printk(KERN_DEBUG LOGNAME ": Enable IRQ failed\n");
350
351 return -EIO;
352}
353
354int msnd_disable_irq(multisound_dev_t *dev)
355{
356 unsigned long flags;
357
358 if (--dev->irq_ref > 0)
359 return 0;
360
361 if (dev->irq_ref < 0)
362 printk(KERN_DEBUG LOGNAME ": IRQ ref count is %d\n", dev->irq_ref);
363
364 printk(KERN_DEBUG LOGNAME ": Disabling IRQ\n");
365
366 spin_lock_irqsave(&dev->lock, flags);
367 if (msnd_wait_TXDE(dev) == 0) {
368 msnd_outb(msnd_inb(dev->io + HP_ICR) & ~HPICR_RREQ, dev->io + HP_ICR);
369 if (dev->type == msndClassic)
370 msnd_outb(HPIRQ_NONE, dev->io + HP_IRQM);
371 disable_irq(dev->irq);
372 spin_unlock_irqrestore(&dev->lock, flags);
373 return 0;
374 }
375 spin_unlock_irqrestore(&dev->lock, flags);
376
377 printk(KERN_DEBUG LOGNAME ": Disable IRQ failed\n");
378
379 return -EIO;
380}
381
382#ifndef LINUX20
383EXPORT_SYMBOL(msnd_register);
384EXPORT_SYMBOL(msnd_unregister);
385
386EXPORT_SYMBOL(msnd_init_queue);
387
388EXPORT_SYMBOL(msnd_fifo_init);
389EXPORT_SYMBOL(msnd_fifo_free);
390EXPORT_SYMBOL(msnd_fifo_alloc);
391EXPORT_SYMBOL(msnd_fifo_make_empty);
392EXPORT_SYMBOL(msnd_fifo_write_io);
393EXPORT_SYMBOL(msnd_fifo_read_io);
394EXPORT_SYMBOL(msnd_fifo_write);
395EXPORT_SYMBOL(msnd_fifo_read);
396
397EXPORT_SYMBOL(msnd_send_dsp_cmd);
398EXPORT_SYMBOL(msnd_send_word);
399EXPORT_SYMBOL(msnd_upload_host);
400
401EXPORT_SYMBOL(msnd_enable_irq);
402EXPORT_SYMBOL(msnd_disable_irq);
403#endif
404
405#ifdef MODULE
406MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
407MODULE_DESCRIPTION ("Turtle Beach MultiSound Driver Base");
408MODULE_LICENSE("GPL");
409
410
411int init_module(void)
412{
413 return 0;
414}
415
416void cleanup_module(void)
417{
418}
419#endif
diff --git a/sound/oss/msnd.h b/sound/oss/msnd.h
new file mode 100644
index 000000000000..05cf7865be5e
--- /dev/null
+++ b/sound/oss/msnd.h
@@ -0,0 +1,280 @@
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 * $Id: msnd.h,v 1.36 1999/03/21 17:05:42 andrewtv Exp $
28 *
29 ********************************************************************/
30#ifndef __MSND_H
31#define __MSND_H
32
33#define VERSION "0.8.3.1"
34
35#define DEFSAMPLERATE DSP_DEFAULT_SPEED
36#define DEFSAMPLESIZE AFMT_U8
37#define DEFCHANNELS 1
38
39#define DEFFIFOSIZE 128
40
41#define SNDCARD_MSND 38
42
43#define SRAM_BANK_SIZE 0x8000
44#define SRAM_CNTL_START 0x7F00
45
46#define DSP_BASE_ADDR 0x4000
47#define DSP_BANK_BASE 0x4000
48
49#define HP_ICR 0x00
50#define HP_CVR 0x01
51#define HP_ISR 0x02
52#define HP_IVR 0x03
53#define HP_NU 0x04
54#define HP_INFO 0x04
55#define HP_TXH 0x05
56#define HP_RXH 0x05
57#define HP_TXM 0x06
58#define HP_RXM 0x06
59#define HP_TXL 0x07
60#define HP_RXL 0x07
61
62#define HP_ICR_DEF 0x00
63#define HP_CVR_DEF 0x12
64#define HP_ISR_DEF 0x06
65#define HP_IVR_DEF 0x0f
66#define HP_NU_DEF 0x00
67
68#define HP_IRQM 0x09
69
70#define HPR_BLRC 0x08
71#define HPR_SPR1 0x09
72#define HPR_SPR2 0x0A
73#define HPR_TCL0 0x0B
74#define HPR_TCL1 0x0C
75#define HPR_TCL2 0x0D
76#define HPR_TCL3 0x0E
77#define HPR_TCL4 0x0F
78
79#define HPICR_INIT 0x80
80#define HPICR_HM1 0x40
81#define HPICR_HM0 0x20
82#define HPICR_HF1 0x10
83#define HPICR_HF0 0x08
84#define HPICR_TREQ 0x02
85#define HPICR_RREQ 0x01
86
87#define HPCVR_HC 0x80
88
89#define HPISR_HREQ 0x80
90#define HPISR_DMA 0x40
91#define HPISR_HF3 0x10
92#define HPISR_HF2 0x08
93#define HPISR_TRDY 0x04
94#define HPISR_TXDE 0x02
95#define HPISR_RXDF 0x01
96
97#define HPIO_290 0
98#define HPIO_260 1
99#define HPIO_250 2
100#define HPIO_240 3
101#define HPIO_230 4
102#define HPIO_220 5
103#define HPIO_210 6
104#define HPIO_3E0 7
105
106#define HPMEM_NONE 0
107#define HPMEM_B000 1
108#define HPMEM_C800 2
109#define HPMEM_D000 3
110#define HPMEM_D400 4
111#define HPMEM_D800 5
112#define HPMEM_E000 6
113#define HPMEM_E800 7
114
115#define HPIRQ_NONE 0
116#define HPIRQ_5 1
117#define HPIRQ_7 2
118#define HPIRQ_9 3
119#define HPIRQ_10 4
120#define HPIRQ_11 5
121#define HPIRQ_12 6
122#define HPIRQ_15 7
123
124#define HIMT_PLAY_DONE 0x00
125#define HIMT_RECORD_DONE 0x01
126#define HIMT_MIDI_EOS 0x02
127#define HIMT_MIDI_OUT 0x03
128
129#define HIMT_MIDI_IN_UCHAR 0x0E
130#define HIMT_DSP 0x0F
131
132#define HDEX_BASE 0x92
133#define HDEX_PLAY_START (0 + HDEX_BASE)
134#define HDEX_PLAY_STOP (1 + HDEX_BASE)
135#define HDEX_PLAY_PAUSE (2 + HDEX_BASE)
136#define HDEX_PLAY_RESUME (3 + HDEX_BASE)
137#define HDEX_RECORD_START (4 + HDEX_BASE)
138#define HDEX_RECORD_STOP (5 + HDEX_BASE)
139#define HDEX_MIDI_IN_START (6 + HDEX_BASE)
140#define HDEX_MIDI_IN_STOP (7 + HDEX_BASE)
141#define HDEX_MIDI_OUT_START (8 + HDEX_BASE)
142#define HDEX_MIDI_OUT_STOP (9 + HDEX_BASE)
143#define HDEX_AUX_REQ (10 + HDEX_BASE)
144
145#define HIWORD(l) ((WORD)((((DWORD)(l)) >> 16) & 0xFFFF))
146#define LOWORD(l) ((WORD)(DWORD)(l))
147#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
148#define LOBYTE(w) ((BYTE)(w))
149#define MAKELONG(low,hi) ((long)(((WORD)(low))|(((DWORD)((WORD)(hi)))<<16)))
150#define MAKEWORD(low,hi) ((WORD)(((BYTE)(low))|(((WORD)((BYTE)(hi)))<<8)))
151
152#define PCTODSP_OFFSET(w) (USHORT)((w)/2)
153#define PCTODSP_BASED(w) (USHORT)(((w)/2) + DSP_BASE_ADDR)
154#define DSPTOPC_BASED(w) (((w) - DSP_BASE_ADDR) * 2)
155
156#ifdef SLOWIO
157#define msnd_outb outb_p
158#define msnd_inb inb_p
159#else
160#define msnd_outb outb
161#define msnd_inb inb
162#endif
163
164/* JobQueueStruct */
165#define JQS_wStart 0x00
166#define JQS_wSize 0x02
167#define JQS_wHead 0x04
168#define JQS_wTail 0x06
169#define JQS__size 0x08
170
171/* DAQueueDataStruct */
172#define DAQDS_wStart 0x00
173#define DAQDS_wSize 0x02
174#define DAQDS_wFormat 0x04
175#define DAQDS_wSampleSize 0x06
176#define DAQDS_wChannels 0x08
177#define DAQDS_wSampleRate 0x0A
178#define DAQDS_wIntMsg 0x0C
179#define DAQDS_wFlags 0x0E
180#define DAQDS__size 0x10
181
182typedef u8 BYTE;
183typedef u16 USHORT;
184typedef u16 WORD;
185typedef u32 DWORD;
186typedef void __iomem * LPDAQD;
187
188/* Generic FIFO */
189typedef struct {
190 size_t n, len;
191 char *data;
192 int head, tail;
193} msnd_fifo;
194
195typedef struct multisound_dev {
196 /* Linux device info */
197 char *name;
198 int dsp_minor, mixer_minor;
199 int ext_midi_dev, hdr_midi_dev;
200
201 /* Hardware resources */
202 int io, numio;
203 int memid, irqid;
204 int irq, irq_ref;
205 unsigned char info;
206 void __iomem *base;
207
208 /* Motorola 56k DSP SMA */
209 void __iomem *SMA;
210 void __iomem *DAPQ, *DARQ, *MODQ, *MIDQ, *DSPQ;
211 void __iomem *pwDSPQData, *pwMIDQData, *pwMODQData;
212 int dspq_data_buff, dspq_buff_size;
213
214 /* State variables */
215 enum { msndClassic, msndPinnacle } type;
216 mode_t mode;
217 unsigned long flags;
218#define F_RESETTING 0
219#define F_HAVEDIGITAL 1
220#define F_AUDIO_WRITE_INUSE 2
221#define F_WRITING 3
222#define F_WRITEBLOCK 4
223#define F_WRITEFLUSH 5
224#define F_AUDIO_READ_INUSE 6
225#define F_READING 7
226#define F_READBLOCK 8
227#define F_EXT_MIDI_INUSE 9
228#define F_HDR_MIDI_INUSE 10
229#define F_DISABLE_WRITE_NDELAY 11
230 wait_queue_head_t writeblock;
231 wait_queue_head_t readblock;
232 wait_queue_head_t writeflush;
233 spinlock_t lock;
234 int nresets;
235 unsigned long recsrc;
236 int left_levels[16];
237 int right_levels[16];
238 int mixer_mod_count;
239 int calibrate_signal;
240 int play_sample_size, play_sample_rate, play_channels;
241 int play_ndelay;
242 int rec_sample_size, rec_sample_rate, rec_channels;
243 int rec_ndelay;
244 BYTE bCurrentMidiPatch;
245
246 /* Digital audio FIFOs */
247 msnd_fifo DAPF, DARF;
248 int fifosize;
249 int last_playbank, last_recbank;
250
251 /* MIDI in callback */
252 void (*midi_in_interrupt)(struct multisound_dev *);
253} multisound_dev_t;
254
255#ifndef mdelay
256# define mdelay(a) udelay((a) * 1000)
257#endif
258
259int msnd_register(multisound_dev_t *dev);
260void msnd_unregister(multisound_dev_t *dev);
261
262void msnd_init_queue(void __iomem *, int start, int size);
263
264void msnd_fifo_init(msnd_fifo *f);
265void msnd_fifo_free(msnd_fifo *f);
266int msnd_fifo_alloc(msnd_fifo *f, size_t n);
267void msnd_fifo_make_empty(msnd_fifo *f);
268int msnd_fifo_write_io(msnd_fifo *f, char __iomem *buf, size_t len);
269int msnd_fifo_read_io(msnd_fifo *f, char __iomem *buf, size_t len);
270int msnd_fifo_write(msnd_fifo *f, const char *buf, size_t len);
271int msnd_fifo_read(msnd_fifo *f, char *buf, size_t len);
272
273int msnd_send_dsp_cmd(multisound_dev_t *dev, BYTE cmd);
274int msnd_send_word(multisound_dev_t *dev, unsigned char high,
275 unsigned char mid, unsigned char low);
276int msnd_upload_host(multisound_dev_t *dev, char *bin, int len);
277int msnd_enable_irq(multisound_dev_t *dev);
278int msnd_disable_irq(multisound_dev_t *dev);
279
280#endif /* __MSND_H */
diff --git a/sound/oss/msnd_classic.c b/sound/oss/msnd_classic.c
new file mode 100644
index 000000000000..3b23a096fa4e
--- /dev/null
+++ b/sound/oss/msnd_classic.c
@@ -0,0 +1,3 @@
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
new file mode 100644
index 000000000000..83c3c46ffffe
--- /dev/null
+++ b/sound/oss/msnd_classic.h
@@ -0,0 +1,188 @@
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 * $Id: msnd_classic.h,v 1.10 1999/03/21 17:36:09 andrewtv Exp $
28 *
29 ********************************************************************/
30#ifndef __MSND_CLASSIC_H
31#define __MSND_CLASSIC_H
32
33#include <linux/config.h>
34
35#define DSP_NUMIO 0x10
36
37#define HP_MEMM 0x08
38
39#define HP_BITM 0x0E
40#define HP_WAIT 0x0D
41#define HP_DSPR 0x0A
42#define HP_PROR 0x0B
43#define HP_BLKS 0x0C
44
45#define HPPRORESET_OFF 0
46#define HPPRORESET_ON 1
47
48#define HPDSPRESET_OFF 0
49#define HPDSPRESET_ON 1
50
51#define HPBLKSEL_0 0
52#define HPBLKSEL_1 1
53
54#define HPWAITSTATE_0 0
55#define HPWAITSTATE_1 1
56
57#define HPBITMODE_16 0
58#define HPBITMODE_8 1
59
60#define HIDSP_INT_PLAY_UNDER 0x00
61#define HIDSP_INT_RECORD_OVER 0x01
62#define HIDSP_INPUT_CLIPPING 0x02
63#define HIDSP_MIDI_IN_OVER 0x10
64#define HIDSP_MIDI_OVERRUN_ERR 0x13
65
66#define HDEXAR_CLEAR_PEAKS 1
67#define HDEXAR_IN_SET_POTS 2
68#define HDEXAR_AUX_SET_POTS 3
69#define HDEXAR_CAL_A_TO_D 4
70#define HDEXAR_RD_EXT_DSP_BITS 5
71
72#define TIME_PRO_RESET_DONE 0x028A
73#define TIME_PRO_SYSEX 0x0040
74#define TIME_PRO_RESET 0x0032
75
76#define AGND 0x01
77#define SIGNAL 0x02
78
79#define EXT_DSP_BIT_DCAL 0x0001
80#define EXT_DSP_BIT_MIDI_CON 0x0002
81
82#define BUFFSIZE 0x8000
83#define HOSTQ_SIZE 0x40
84
85#define SRAM_CNTL_START 0x7F00
86#define SMA_STRUCT_START 0x7F40
87
88#define DAP_BUFF_SIZE 0x2400
89#define DAR_BUFF_SIZE 0x2000
90
91#define DAPQ_STRUCT_SIZE 0x10
92#define DARQ_STRUCT_SIZE 0x10
93#define DAPQ_BUFF_SIZE (3 * 0x10)
94#define DARQ_BUFF_SIZE (3 * 0x10)
95#define MODQ_BUFF_SIZE 0x400
96#define MIDQ_BUFF_SIZE 0x200
97#define DSPQ_BUFF_SIZE 0x40
98
99#define DAPQ_DATA_BUFF 0x6C00
100#define DARQ_DATA_BUFF 0x6C30
101#define MODQ_DATA_BUFF 0x6C60
102#define MIDQ_DATA_BUFF 0x7060
103#define DSPQ_DATA_BUFF 0x7260
104
105#define DAPQ_OFFSET SRAM_CNTL_START
106#define DARQ_OFFSET (SRAM_CNTL_START + 0x08)
107#define MODQ_OFFSET (SRAM_CNTL_START + 0x10)
108#define MIDQ_OFFSET (SRAM_CNTL_START + 0x18)
109#define DSPQ_OFFSET (SRAM_CNTL_START + 0x20)
110
111#define MOP_SYNTH 0x10
112#define MOP_EXTOUT 0x32
113#define MOP_EXTTHRU 0x02
114#define MOP_OUTMASK 0x01
115
116#define MIP_EXTIN 0x01
117#define MIP_SYNTH 0x00
118#define MIP_INMASK 0x32
119
120/* Classic SMA Common Data */
121#define SMA_wCurrPlayBytes 0x0000
122#define SMA_wCurrRecordBytes 0x0002
123#define SMA_wCurrPlayVolLeft 0x0004
124#define SMA_wCurrPlayVolRight 0x0006
125#define SMA_wCurrInVolLeft 0x0008
126#define SMA_wCurrInVolRight 0x000a
127#define SMA_wUser_3 0x000c
128#define SMA_wUser_4 0x000e
129#define SMA_dwUser_5 0x0010
130#define SMA_dwUser_6 0x0014
131#define SMA_wUser_7 0x0018
132#define SMA_wReserved_A 0x001a
133#define SMA_wReserved_B 0x001c
134#define SMA_wReserved_C 0x001e
135#define SMA_wReserved_D 0x0020
136#define SMA_wReserved_E 0x0022
137#define SMA_wReserved_F 0x0024
138#define SMA_wReserved_G 0x0026
139#define SMA_wReserved_H 0x0028
140#define SMA_wCurrDSPStatusFlags 0x002a
141#define SMA_wCurrHostStatusFlags 0x002c
142#define SMA_wCurrInputTagBits 0x002e
143#define SMA_wCurrLeftPeak 0x0030
144#define SMA_wCurrRightPeak 0x0032
145#define SMA_wExtDSPbits 0x0034
146#define SMA_bExtHostbits 0x0036
147#define SMA_bBoardLevel 0x0037
148#define SMA_bInPotPosRight 0x0038
149#define SMA_bInPotPosLeft 0x0039
150#define SMA_bAuxPotPosRight 0x003a
151#define SMA_bAuxPotPosLeft 0x003b
152#define SMA_wCurrMastVolLeft 0x003c
153#define SMA_wCurrMastVolRight 0x003e
154#define SMA_bUser_12 0x0040
155#define SMA_bUser_13 0x0041
156#define SMA_wUser_14 0x0042
157#define SMA_wUser_15 0x0044
158#define SMA_wCalFreqAtoD 0x0046
159#define SMA_wUser_16 0x0048
160#define SMA_wUser_17 0x004a
161#define SMA__size 0x004c
162
163#ifdef HAVE_DSPCODEH
164# include "msndperm.c"
165# include "msndinit.c"
166# define PERMCODE msndperm
167# define INITCODE msndinit
168# define PERMCODESIZE sizeof(msndperm)
169# define INITCODESIZE sizeof(msndinit)
170#else
171# ifndef CONFIG_MSNDCLAS_INIT_FILE
172# define CONFIG_MSNDCLAS_INIT_FILE \
173 "/etc/sound/msndinit.bin"
174# endif
175# ifndef CONFIG_MSNDCLAS_PERM_FILE
176# define CONFIG_MSNDCLAS_PERM_FILE \
177 "/etc/sound/msndperm.bin"
178# endif
179# define PERMCODEFILE CONFIG_MSNDCLAS_PERM_FILE
180# define INITCODEFILE CONFIG_MSNDCLAS_INIT_FILE
181# define PERMCODE dspini
182# define INITCODE permini
183# define PERMCODESIZE sizeof_dspini
184# define INITCODESIZE sizeof_permini
185#endif
186#define LONGNAME "MultiSound (Classic/Monterey/Tahiti)"
187
188#endif /* __MSND_CLASSIC_H */
diff --git a/sound/oss/msnd_pinnacle.c b/sound/oss/msnd_pinnacle.c
new file mode 100644
index 000000000000..6ba03f89fc43
--- /dev/null
+++ b/sound/oss/msnd_pinnacle.c
@@ -0,0 +1,1922 @@
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 * $Id: msnd_pinnacle.c,v 1.8 2000/12/30 00:33:21 sycamore Exp $
33 *
34 * 12-3-2000 Modified IO port validation Steve Sycamore
35 *
36 *
37 * $$$: msnd_pinnacle.c,v 1.75 1999/03/21 16:50:09 andrewtv $$$ $
38 *
39 ********************************************************************/
40
41#include <linux/kernel.h>
42#include <linux/config.h>
43#include <linux/module.h>
44#include <linux/slab.h>
45#include <linux/types.h>
46#include <linux/delay.h>
47#include <linux/init.h>
48#include <linux/interrupt.h>
49#include <linux/smp_lock.h>
50#include <asm/irq.h>
51#include <asm/io.h>
52#include "sound_config.h"
53#include "sound_firmware.h"
54#ifdef MSND_CLASSIC
55# ifndef __alpha__
56# define SLOWIO
57# endif
58#endif
59#include "msnd.h"
60#ifdef MSND_CLASSIC
61# ifdef CONFIG_MSNDCLAS_HAVE_BOOT
62# define HAVE_DSPCODEH
63# endif
64# include "msnd_classic.h"
65# define LOGNAME "msnd_classic"
66#else
67# ifdef CONFIG_MSNDPIN_HAVE_BOOT
68# define HAVE_DSPCODEH
69# endif
70# include "msnd_pinnacle.h"
71# define LOGNAME "msnd_pinnacle"
72#endif
73
74#ifndef CONFIG_MSND_WRITE_NDELAY
75# define CONFIG_MSND_WRITE_NDELAY 1
76#endif
77
78#define get_play_delay_jiffies(size) ((size) * HZ * \
79 dev.play_sample_size / 8 / \
80 dev.play_sample_rate / \
81 dev.play_channels)
82
83#define get_rec_delay_jiffies(size) ((size) * HZ * \
84 dev.rec_sample_size / 8 / \
85 dev.rec_sample_rate / \
86 dev.rec_channels)
87
88static multisound_dev_t dev;
89
90#ifndef HAVE_DSPCODEH
91static char *dspini, *permini;
92static int sizeof_dspini, sizeof_permini;
93#endif
94
95static int dsp_full_reset(void);
96static void dsp_write_flush(void);
97
98static __inline__ int chk_send_dsp_cmd(multisound_dev_t *dev, register BYTE cmd)
99{
100 if (msnd_send_dsp_cmd(dev, cmd) == 0)
101 return 0;
102 dsp_full_reset();
103 return msnd_send_dsp_cmd(dev, cmd);
104}
105
106static void reset_play_queue(void)
107{
108 int n;
109 LPDAQD lpDAQ;
110
111 dev.last_playbank = -1;
112 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DAPQ + JQS_wHead);
113 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DAPQ + JQS_wTail);
114
115 for (n = 0, lpDAQ = dev.base + DAPQ_DATA_BUFF; n < 3; ++n, lpDAQ += DAQDS__size) {
116 writew(PCTODSP_BASED((DWORD)(DAP_BUFF_SIZE * n)), lpDAQ + DAQDS_wStart);
117 writew(0, lpDAQ + DAQDS_wSize);
118 writew(1, lpDAQ + DAQDS_wFormat);
119 writew(dev.play_sample_size, lpDAQ + DAQDS_wSampleSize);
120 writew(dev.play_channels, lpDAQ + DAQDS_wChannels);
121 writew(dev.play_sample_rate, lpDAQ + DAQDS_wSampleRate);
122 writew(HIMT_PLAY_DONE * 0x100 + n, lpDAQ + DAQDS_wIntMsg);
123 writew(n, lpDAQ + DAQDS_wFlags);
124 }
125}
126
127static void reset_record_queue(void)
128{
129 int n;
130 LPDAQD lpDAQ;
131 unsigned long flags;
132
133 dev.last_recbank = 2;
134 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DARQ + JQS_wHead);
135 writew(PCTODSP_OFFSET(dev.last_recbank * DAQDS__size), dev.DARQ + JQS_wTail);
136
137 /* Critical section: bank 1 access */
138 spin_lock_irqsave(&dev.lock, flags);
139 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
140 memset_io(dev.base, 0, DAR_BUFF_SIZE * 3);
141 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
142 spin_unlock_irqrestore(&dev.lock, flags);
143
144 for (n = 0, lpDAQ = dev.base + DARQ_DATA_BUFF; n < 3; ++n, lpDAQ += DAQDS__size) {
145 writew(PCTODSP_BASED((DWORD)(DAR_BUFF_SIZE * n)) + 0x4000, lpDAQ + DAQDS_wStart);
146 writew(DAR_BUFF_SIZE, lpDAQ + DAQDS_wSize);
147 writew(1, lpDAQ + DAQDS_wFormat);
148 writew(dev.rec_sample_size, lpDAQ + DAQDS_wSampleSize);
149 writew(dev.rec_channels, lpDAQ + DAQDS_wChannels);
150 writew(dev.rec_sample_rate, lpDAQ + DAQDS_wSampleRate);
151 writew(HIMT_RECORD_DONE * 0x100 + n, lpDAQ + DAQDS_wIntMsg);
152 writew(n, lpDAQ + DAQDS_wFlags);
153 }
154}
155
156static void reset_queues(void)
157{
158 if (dev.mode & FMODE_WRITE) {
159 msnd_fifo_make_empty(&dev.DAPF);
160 reset_play_queue();
161 }
162 if (dev.mode & FMODE_READ) {
163 msnd_fifo_make_empty(&dev.DARF);
164 reset_record_queue();
165 }
166}
167
168static int dsp_set_format(struct file *file, int val)
169{
170 int data, i;
171 LPDAQD lpDAQ, lpDARQ;
172
173 lpDAQ = dev.base + DAPQ_DATA_BUFF;
174 lpDARQ = dev.base + DARQ_DATA_BUFF;
175
176 switch (val) {
177 case AFMT_U8:
178 case AFMT_S16_LE:
179 data = val;
180 break;
181 default:
182 data = DEFSAMPLESIZE;
183 break;
184 }
185
186 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
187 if (file->f_mode & FMODE_WRITE)
188 writew(data, lpDAQ + DAQDS_wSampleSize);
189 if (file->f_mode & FMODE_READ)
190 writew(data, lpDARQ + DAQDS_wSampleSize);
191 }
192 if (file->f_mode & FMODE_WRITE)
193 dev.play_sample_size = data;
194 if (file->f_mode & FMODE_READ)
195 dev.rec_sample_size = data;
196
197 return data;
198}
199
200static int dsp_get_frag_size(void)
201{
202 int size;
203 size = dev.fifosize / 4;
204 if (size > 32 * 1024)
205 size = 32 * 1024;
206 return size;
207}
208
209static int dsp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
210{
211 int val, i, data, tmp;
212 LPDAQD lpDAQ, lpDARQ;
213 audio_buf_info abinfo;
214 unsigned long flags;
215 int __user *p = (int __user *)arg;
216
217 lpDAQ = dev.base + DAPQ_DATA_BUFF;
218 lpDARQ = dev.base + DARQ_DATA_BUFF;
219
220 switch (cmd) {
221 case SNDCTL_DSP_SUBDIVIDE:
222 case SNDCTL_DSP_SETFRAGMENT:
223 case SNDCTL_DSP_SETDUPLEX:
224 case SNDCTL_DSP_POST:
225 return 0;
226
227 case SNDCTL_DSP_GETIPTR:
228 case SNDCTL_DSP_GETOPTR:
229 case SNDCTL_DSP_MAPINBUF:
230 case SNDCTL_DSP_MAPOUTBUF:
231 return -EINVAL;
232
233 case SNDCTL_DSP_GETOSPACE:
234 if (!(file->f_mode & FMODE_WRITE))
235 return -EINVAL;
236 spin_lock_irqsave(&dev.lock, flags);
237 abinfo.fragsize = dsp_get_frag_size();
238 abinfo.bytes = dev.DAPF.n - dev.DAPF.len;
239 abinfo.fragstotal = dev.DAPF.n / abinfo.fragsize;
240 abinfo.fragments = abinfo.bytes / abinfo.fragsize;
241 spin_unlock_irqrestore(&dev.lock, flags);
242 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
243
244 case SNDCTL_DSP_GETISPACE:
245 if (!(file->f_mode & FMODE_READ))
246 return -EINVAL;
247 spin_lock_irqsave(&dev.lock, flags);
248 abinfo.fragsize = dsp_get_frag_size();
249 abinfo.bytes = dev.DARF.n - dev.DARF.len;
250 abinfo.fragstotal = dev.DARF.n / abinfo.fragsize;
251 abinfo.fragments = abinfo.bytes / abinfo.fragsize;
252 spin_unlock_irqrestore(&dev.lock, flags);
253 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
254
255 case SNDCTL_DSP_RESET:
256 dev.nresets = 0;
257 reset_queues();
258 return 0;
259
260 case SNDCTL_DSP_SYNC:
261 dsp_write_flush();
262 return 0;
263
264 case SNDCTL_DSP_GETBLKSIZE:
265 tmp = dsp_get_frag_size();
266 if (put_user(tmp, p))
267 return -EFAULT;
268 return 0;
269
270 case SNDCTL_DSP_GETFMTS:
271 val = AFMT_S16_LE | AFMT_U8;
272 if (put_user(val, p))
273 return -EFAULT;
274 return 0;
275
276 case SNDCTL_DSP_SETFMT:
277 if (get_user(val, p))
278 return -EFAULT;
279
280 if (file->f_mode & FMODE_WRITE)
281 data = val == AFMT_QUERY
282 ? dev.play_sample_size
283 : dsp_set_format(file, val);
284 else
285 data = val == AFMT_QUERY
286 ? dev.rec_sample_size
287 : dsp_set_format(file, val);
288
289 if (put_user(data, p))
290 return -EFAULT;
291 return 0;
292
293 case SNDCTL_DSP_NONBLOCK:
294 if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags) &&
295 file->f_mode & FMODE_WRITE)
296 dev.play_ndelay = 1;
297 if (file->f_mode & FMODE_READ)
298 dev.rec_ndelay = 1;
299 return 0;
300
301 case SNDCTL_DSP_GETCAPS:
302 val = DSP_CAP_DUPLEX | DSP_CAP_BATCH;
303 if (put_user(val, p))
304 return -EFAULT;
305 return 0;
306
307 case SNDCTL_DSP_SPEED:
308 if (get_user(val, p))
309 return -EFAULT;
310
311 if (val < 8000)
312 val = 8000;
313
314 if (val > 48000)
315 val = 48000;
316
317 data = val;
318
319 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
320 if (file->f_mode & FMODE_WRITE)
321 writew(data, lpDAQ + DAQDS_wSampleRate);
322 if (file->f_mode & FMODE_READ)
323 writew(data, lpDARQ + DAQDS_wSampleRate);
324 }
325 if (file->f_mode & FMODE_WRITE)
326 dev.play_sample_rate = data;
327 if (file->f_mode & FMODE_READ)
328 dev.rec_sample_rate = data;
329
330 if (put_user(data, p))
331 return -EFAULT;
332 return 0;
333
334 case SNDCTL_DSP_CHANNELS:
335 case SNDCTL_DSP_STEREO:
336 if (get_user(val, p))
337 return -EFAULT;
338
339 if (cmd == SNDCTL_DSP_CHANNELS) {
340 switch (val) {
341 case 1:
342 case 2:
343 data = val;
344 break;
345 default:
346 val = data = 2;
347 break;
348 }
349 } else {
350 switch (val) {
351 case 0:
352 data = 1;
353 break;
354 default:
355 val = 1;
356 case 1:
357 data = 2;
358 break;
359 }
360 }
361
362 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
363 if (file->f_mode & FMODE_WRITE)
364 writew(data, lpDAQ + DAQDS_wChannels);
365 if (file->f_mode & FMODE_READ)
366 writew(data, lpDARQ + DAQDS_wChannels);
367 }
368 if (file->f_mode & FMODE_WRITE)
369 dev.play_channels = data;
370 if (file->f_mode & FMODE_READ)
371 dev.rec_channels = data;
372
373 if (put_user(val, p))
374 return -EFAULT;
375 return 0;
376 }
377
378 return -EINVAL;
379}
380
381static int mixer_get(int d)
382{
383 if (d > 31)
384 return -EINVAL;
385
386 switch (d) {
387 case SOUND_MIXER_VOLUME:
388 case SOUND_MIXER_PCM:
389 case SOUND_MIXER_LINE:
390 case SOUND_MIXER_IMIX:
391 case SOUND_MIXER_LINE1:
392#ifndef MSND_CLASSIC
393 case SOUND_MIXER_MIC:
394 case SOUND_MIXER_SYNTH:
395#endif
396 return (dev.left_levels[d] >> 8) * 100 / 0xff |
397 (((dev.right_levels[d] >> 8) * 100 / 0xff) << 8);
398 default:
399 return 0;
400 }
401}
402
403#define update_volm(a,b) \
404 writew((dev.left_levels[a] >> 1) * \
405 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
406 dev.SMA + SMA_##b##Left); \
407 writew((dev.right_levels[a] >> 1) * \
408 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
409 dev.SMA + SMA_##b##Right);
410
411#define update_potm(d,s,ar) \
412 writeb((dev.left_levels[d] >> 8) * \
413 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
414 dev.SMA + SMA_##s##Left); \
415 writeb((dev.right_levels[d] >> 8) * \
416 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
417 dev.SMA + SMA_##s##Right); \
418 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
419 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
420
421#define update_pot(d,s,ar) \
422 writeb(dev.left_levels[d] >> 8, \
423 dev.SMA + SMA_##s##Left); \
424 writeb(dev.right_levels[d] >> 8, \
425 dev.SMA + SMA_##s##Right); \
426 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
427 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
428
429static int mixer_set(int d, int value)
430{
431 int left = value & 0x000000ff;
432 int right = (value & 0x0000ff00) >> 8;
433 int bLeft, bRight;
434 int wLeft, wRight;
435 int updatemaster = 0;
436
437 if (d > 31)
438 return -EINVAL;
439
440 bLeft = left * 0xff / 100;
441 wLeft = left * 0xffff / 100;
442
443 bRight = right * 0xff / 100;
444 wRight = right * 0xffff / 100;
445
446 dev.left_levels[d] = wLeft;
447 dev.right_levels[d] = wRight;
448
449 switch (d) {
450 /* master volume unscaled controls */
451 case SOUND_MIXER_LINE: /* line pot control */
452 /* scaled by IMIX in digital mix */
453 writeb(bLeft, dev.SMA + SMA_bInPotPosLeft);
454 writeb(bRight, dev.SMA + SMA_bInPotPosRight);
455 if (msnd_send_word(&dev, 0, 0, HDEXAR_IN_SET_POTS) == 0)
456 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
457 break;
458#ifndef MSND_CLASSIC
459 case SOUND_MIXER_MIC: /* mic pot control */
460 /* scaled by IMIX in digital mix */
461 writeb(bLeft, dev.SMA + SMA_bMicPotPosLeft);
462 writeb(bRight, dev.SMA + SMA_bMicPotPosRight);
463 if (msnd_send_word(&dev, 0, 0, HDEXAR_MIC_SET_POTS) == 0)
464 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
465 break;
466#endif
467 case SOUND_MIXER_VOLUME: /* master volume */
468 writew(wLeft, dev.SMA + SMA_wCurrMastVolLeft);
469 writew(wRight, dev.SMA + SMA_wCurrMastVolRight);
470 /* fall through */
471
472 case SOUND_MIXER_LINE1: /* aux pot control */
473 /* scaled by master volume */
474 /* fall through */
475
476 /* digital controls */
477 case SOUND_MIXER_SYNTH: /* synth vol (dsp mix) */
478 case SOUND_MIXER_PCM: /* pcm vol (dsp mix) */
479 case SOUND_MIXER_IMIX: /* input monitor (dsp mix) */
480 /* scaled by master volume */
481 updatemaster = 1;
482 break;
483
484 default:
485 return 0;
486 }
487
488 if (updatemaster) {
489 /* update master volume scaled controls */
490 update_volm(SOUND_MIXER_PCM, wCurrPlayVol);
491 update_volm(SOUND_MIXER_IMIX, wCurrInVol);
492#ifndef MSND_CLASSIC
493 update_volm(SOUND_MIXER_SYNTH, wCurrMHdrVol);
494#endif
495 update_potm(SOUND_MIXER_LINE1, bAuxPotPos, HDEXAR_AUX_SET_POTS);
496 }
497
498 return mixer_get(d);
499}
500
501static void mixer_setup(void)
502{
503 update_pot(SOUND_MIXER_LINE, bInPotPos, HDEXAR_IN_SET_POTS);
504 update_potm(SOUND_MIXER_LINE1, bAuxPotPos, HDEXAR_AUX_SET_POTS);
505 update_volm(SOUND_MIXER_PCM, wCurrPlayVol);
506 update_volm(SOUND_MIXER_IMIX, wCurrInVol);
507#ifndef MSND_CLASSIC
508 update_pot(SOUND_MIXER_MIC, bMicPotPos, HDEXAR_MIC_SET_POTS);
509 update_volm(SOUND_MIXER_SYNTH, wCurrMHdrVol);
510#endif
511}
512
513static unsigned long set_recsrc(unsigned long recsrc)
514{
515 if (dev.recsrc == recsrc)
516 return dev.recsrc;
517#ifdef HAVE_NORECSRC
518 else if (recsrc == 0)
519 dev.recsrc = 0;
520#endif
521 else
522 dev.recsrc ^= recsrc;
523
524#ifndef MSND_CLASSIC
525 if (dev.recsrc & SOUND_MASK_IMIX) {
526 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_ANA_IN) == 0)
527 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
528 }
529 else if (dev.recsrc & SOUND_MASK_SYNTH) {
530 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_SYNTH_IN) == 0)
531 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
532 }
533 else if ((dev.recsrc & SOUND_MASK_DIGITAL1) && test_bit(F_HAVEDIGITAL, &dev.flags)) {
534 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_DAT_IN) == 0)
535 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
536 }
537 else {
538#ifdef HAVE_NORECSRC
539 /* Select no input (?) */
540 dev.recsrc = 0;
541#else
542 dev.recsrc = SOUND_MASK_IMIX;
543 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_ANA_IN) == 0)
544 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
545#endif
546 }
547#endif /* MSND_CLASSIC */
548
549 return dev.recsrc;
550}
551
552static unsigned long force_recsrc(unsigned long recsrc)
553{
554 dev.recsrc = 0;
555 return set_recsrc(recsrc);
556}
557
558#define set_mixer_info() \
559 memset(&info, 0, sizeof(info)); \
560 strlcpy(info.id, "MSNDMIXER", sizeof(info.id)); \
561 strlcpy(info.name, "MultiSound Mixer", sizeof(info.name));
562
563static int mixer_ioctl(unsigned int cmd, unsigned long arg)
564{
565 if (cmd == SOUND_MIXER_INFO) {
566 mixer_info info;
567 set_mixer_info();
568 info.modify_counter = dev.mixer_mod_count;
569 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
570 return -EFAULT;
571 return 0;
572 } else if (cmd == SOUND_OLD_MIXER_INFO) {
573 _old_mixer_info info;
574 set_mixer_info();
575 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
576 return -EFAULT;
577 return 0;
578 } else if (cmd == SOUND_MIXER_PRIVATE1) {
579 dev.nresets = 0;
580 dsp_full_reset();
581 return 0;
582 } else if (((cmd >> 8) & 0xff) == 'M') {
583 int val = 0;
584
585 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
586 switch (cmd & 0xff) {
587 case SOUND_MIXER_RECSRC:
588 if (get_user(val, (int __user *)arg))
589 return -EFAULT;
590 val = set_recsrc(val);
591 break;
592
593 default:
594 if (get_user(val, (int __user *)arg))
595 return -EFAULT;
596 val = mixer_set(cmd & 0xff, val);
597 break;
598 }
599 ++dev.mixer_mod_count;
600 return put_user(val, (int __user *)arg);
601 } else {
602 switch (cmd & 0xff) {
603 case SOUND_MIXER_RECSRC:
604 val = dev.recsrc;
605 break;
606
607 case SOUND_MIXER_DEVMASK:
608 case SOUND_MIXER_STEREODEVS:
609 val = SOUND_MASK_PCM |
610 SOUND_MASK_LINE |
611 SOUND_MASK_IMIX |
612 SOUND_MASK_LINE1 |
613#ifndef MSND_CLASSIC
614 SOUND_MASK_MIC |
615 SOUND_MASK_SYNTH |
616#endif
617 SOUND_MASK_VOLUME;
618 break;
619
620 case SOUND_MIXER_RECMASK:
621#ifdef MSND_CLASSIC
622 val = 0;
623#else
624 val = SOUND_MASK_IMIX |
625 SOUND_MASK_SYNTH;
626 if (test_bit(F_HAVEDIGITAL, &dev.flags))
627 val |= SOUND_MASK_DIGITAL1;
628#endif
629 break;
630
631 case SOUND_MIXER_CAPS:
632 val = SOUND_CAP_EXCL_INPUT;
633 break;
634
635 default:
636 if ((val = mixer_get(cmd & 0xff)) < 0)
637 return -EINVAL;
638 break;
639 }
640 }
641
642 return put_user(val, (int __user *)arg);
643 }
644
645 return -EINVAL;
646}
647
648static int dev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
649{
650 int minor = iminor(inode);
651
652 if (cmd == OSS_GETVERSION) {
653 int sound_version = SOUND_VERSION;
654 return put_user(sound_version, (int __user *)arg);
655 }
656
657 if (minor == dev.dsp_minor)
658 return dsp_ioctl(file, cmd, arg);
659 else if (minor == dev.mixer_minor)
660 return mixer_ioctl(cmd, arg);
661
662 return -EINVAL;
663}
664
665static void dsp_write_flush(void)
666{
667 if (!(dev.mode & FMODE_WRITE) || !test_bit(F_WRITING, &dev.flags))
668 return;
669 set_bit(F_WRITEFLUSH, &dev.flags);
670 interruptible_sleep_on_timeout(
671 &dev.writeflush,
672 get_play_delay_jiffies(dev.DAPF.len));
673 clear_bit(F_WRITEFLUSH, &dev.flags);
674 if (!signal_pending(current)) {
675 current->state = TASK_INTERRUPTIBLE;
676 schedule_timeout(get_play_delay_jiffies(DAP_BUFF_SIZE));
677 }
678 clear_bit(F_WRITING, &dev.flags);
679}
680
681static void dsp_halt(struct file *file)
682{
683 if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
684 clear_bit(F_READING, &dev.flags);
685 chk_send_dsp_cmd(&dev, HDEX_RECORD_STOP);
686 msnd_disable_irq(&dev);
687 if (file) {
688 printk(KERN_DEBUG LOGNAME ": Stopping read for %p\n", file);
689 dev.mode &= ~FMODE_READ;
690 }
691 clear_bit(F_AUDIO_READ_INUSE, &dev.flags);
692 }
693 if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
694 if (test_bit(F_WRITING, &dev.flags)) {
695 dsp_write_flush();
696 chk_send_dsp_cmd(&dev, HDEX_PLAY_STOP);
697 }
698 msnd_disable_irq(&dev);
699 if (file) {
700 printk(KERN_DEBUG LOGNAME ": Stopping write for %p\n", file);
701 dev.mode &= ~FMODE_WRITE;
702 }
703 clear_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
704 }
705}
706
707static int dsp_release(struct file *file)
708{
709 dsp_halt(file);
710 return 0;
711}
712
713static int dsp_open(struct file *file)
714{
715 if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
716 set_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
717 clear_bit(F_WRITING, &dev.flags);
718 msnd_fifo_make_empty(&dev.DAPF);
719 reset_play_queue();
720 if (file) {
721 printk(KERN_DEBUG LOGNAME ": Starting write for %p\n", file);
722 dev.mode |= FMODE_WRITE;
723 }
724 msnd_enable_irq(&dev);
725 }
726 if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
727 set_bit(F_AUDIO_READ_INUSE, &dev.flags);
728 clear_bit(F_READING, &dev.flags);
729 msnd_fifo_make_empty(&dev.DARF);
730 reset_record_queue();
731 if (file) {
732 printk(KERN_DEBUG LOGNAME ": Starting read for %p\n", file);
733 dev.mode |= FMODE_READ;
734 }
735 msnd_enable_irq(&dev);
736 }
737 return 0;
738}
739
740static void set_default_play_audio_parameters(void)
741{
742 dev.play_sample_size = DEFSAMPLESIZE;
743 dev.play_sample_rate = DEFSAMPLERATE;
744 dev.play_channels = DEFCHANNELS;
745}
746
747static void set_default_rec_audio_parameters(void)
748{
749 dev.rec_sample_size = DEFSAMPLESIZE;
750 dev.rec_sample_rate = DEFSAMPLERATE;
751 dev.rec_channels = DEFCHANNELS;
752}
753
754static void set_default_audio_parameters(void)
755{
756 set_default_play_audio_parameters();
757 set_default_rec_audio_parameters();
758}
759
760static int dev_open(struct inode *inode, struct file *file)
761{
762 int minor = iminor(inode);
763 int err = 0;
764
765 if (minor == dev.dsp_minor) {
766 if ((file->f_mode & FMODE_WRITE &&
767 test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) ||
768 (file->f_mode & FMODE_READ &&
769 test_bit(F_AUDIO_READ_INUSE, &dev.flags)))
770 return -EBUSY;
771
772 if ((err = dsp_open(file)) >= 0) {
773 dev.nresets = 0;
774 if (file->f_mode & FMODE_WRITE) {
775 set_default_play_audio_parameters();
776 if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags))
777 dev.play_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
778 else
779 dev.play_ndelay = 0;
780 }
781 if (file->f_mode & FMODE_READ) {
782 set_default_rec_audio_parameters();
783 dev.rec_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
784 }
785 }
786 }
787 else if (minor == dev.mixer_minor) {
788 /* nothing */
789 } else
790 err = -EINVAL;
791
792 return err;
793}
794
795static int dev_release(struct inode *inode, struct file *file)
796{
797 int minor = iminor(inode);
798 int err = 0;
799
800 lock_kernel();
801 if (minor == dev.dsp_minor)
802 err = dsp_release(file);
803 else if (minor == dev.mixer_minor) {
804 /* nothing */
805 } else
806 err = -EINVAL;
807 unlock_kernel();
808 return err;
809}
810
811static __inline__ int pack_DARQ_to_DARF(register int bank)
812{
813 register int size, timeout = 3;
814 register WORD wTmp;
815 LPDAQD DAQD;
816
817 /* Increment the tail and check for queue wrap */
818 wTmp = readw(dev.DARQ + JQS_wTail) + PCTODSP_OFFSET(DAQDS__size);
819 if (wTmp > readw(dev.DARQ + JQS_wSize))
820 wTmp = 0;
821 while (wTmp == readw(dev.DARQ + JQS_wHead) && timeout--)
822 udelay(1);
823 writew(wTmp, dev.DARQ + JQS_wTail);
824
825 /* Get our digital audio queue struct */
826 DAQD = bank * DAQDS__size + dev.base + DARQ_DATA_BUFF;
827
828 /* Get length of data */
829 size = readw(DAQD + DAQDS_wSize);
830
831 /* Read data from the head (unprotected bank 1 access okay
832 since this is only called inside an interrupt) */
833 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
834 msnd_fifo_write_io(
835 &dev.DARF,
836 dev.base + bank * DAR_BUFF_SIZE,
837 size);
838 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
839
840 return 1;
841}
842
843static __inline__ int pack_DAPF_to_DAPQ(register int start)
844{
845 register WORD DAPQ_tail;
846 register int protect = start, nbanks = 0;
847 LPDAQD DAQD;
848
849 DAPQ_tail = readw(dev.DAPQ + JQS_wTail);
850 while (DAPQ_tail != readw(dev.DAPQ + JQS_wHead) || start) {
851 register int bank_num = DAPQ_tail / PCTODSP_OFFSET(DAQDS__size);
852 register int n;
853 unsigned long flags;
854
855 /* Write the data to the new tail */
856 if (protect) {
857 /* Critical section: protect fifo in non-interrupt */
858 spin_lock_irqsave(&dev.lock, flags);
859 n = msnd_fifo_read_io(
860 &dev.DAPF,
861 dev.base + bank_num * DAP_BUFF_SIZE,
862 DAP_BUFF_SIZE);
863 spin_unlock_irqrestore(&dev.lock, flags);
864 } else {
865 n = msnd_fifo_read_io(
866 &dev.DAPF,
867 dev.base + bank_num * DAP_BUFF_SIZE,
868 DAP_BUFF_SIZE);
869 }
870 if (!n)
871 break;
872
873 if (start)
874 start = 0;
875
876 /* Get our digital audio queue struct */
877 DAQD = bank_num * DAQDS__size + dev.base + DAPQ_DATA_BUFF;
878
879 /* Write size of this bank */
880 writew(n, DAQD + DAQDS_wSize);
881 ++nbanks;
882
883 /* Then advance the tail */
884 DAPQ_tail = (++bank_num % 3) * PCTODSP_OFFSET(DAQDS__size);
885 writew(DAPQ_tail, dev.DAPQ + JQS_wTail);
886 /* Tell the DSP to play the bank */
887 msnd_send_dsp_cmd(&dev, HDEX_PLAY_START);
888 }
889 return nbanks;
890}
891
892static int dsp_read(char __user *buf, size_t len)
893{
894 int count = len;
895 char *page = (char *)__get_free_page(PAGE_SIZE);
896
897 if (!page)
898 return -ENOMEM;
899
900 while (count > 0) {
901 int n, k;
902 unsigned long flags;
903
904 k = PAGE_SIZE;
905 if (k > count)
906 k = count;
907
908 /* Critical section: protect fifo in non-interrupt */
909 spin_lock_irqsave(&dev.lock, flags);
910 n = msnd_fifo_read(&dev.DARF, page, k);
911 spin_unlock_irqrestore(&dev.lock, flags);
912 if (copy_to_user(buf, page, n)) {
913 free_page((unsigned long)page);
914 return -EFAULT;
915 }
916 buf += n;
917 count -= n;
918
919 if (n == k && count)
920 continue;
921
922 if (!test_bit(F_READING, &dev.flags) && dev.mode & FMODE_READ) {
923 dev.last_recbank = -1;
924 if (chk_send_dsp_cmd(&dev, HDEX_RECORD_START) == 0)
925 set_bit(F_READING, &dev.flags);
926 }
927
928 if (dev.rec_ndelay) {
929 free_page((unsigned long)page);
930 return count == len ? -EAGAIN : len - count;
931 }
932
933 if (count > 0) {
934 set_bit(F_READBLOCK, &dev.flags);
935 if (!interruptible_sleep_on_timeout(
936 &dev.readblock,
937 get_rec_delay_jiffies(DAR_BUFF_SIZE)))
938 clear_bit(F_READING, &dev.flags);
939 clear_bit(F_READBLOCK, &dev.flags);
940 if (signal_pending(current)) {
941 free_page((unsigned long)page);
942 return -EINTR;
943 }
944 }
945 }
946 free_page((unsigned long)page);
947 return len - count;
948}
949
950static int dsp_write(const char __user *buf, size_t len)
951{
952 int count = len;
953 char *page = (char *)__get_free_page(GFP_KERNEL);
954
955 if (!page)
956 return -ENOMEM;
957
958 while (count > 0) {
959 int n, k;
960 unsigned long flags;
961
962 k = PAGE_SIZE;
963 if (k > count)
964 k = count;
965
966 if (copy_from_user(page, buf, k)) {
967 free_page((unsigned long)page);
968 return -EFAULT;
969 }
970
971 /* Critical section: protect fifo in non-interrupt */
972 spin_lock_irqsave(&dev.lock, flags);
973 n = msnd_fifo_write(&dev.DAPF, page, k);
974 spin_unlock_irqrestore(&dev.lock, flags);
975 buf += n;
976 count -= n;
977
978 if (count && n == k)
979 continue;
980
981 if (!test_bit(F_WRITING, &dev.flags) && (dev.mode & FMODE_WRITE)) {
982 dev.last_playbank = -1;
983 if (pack_DAPF_to_DAPQ(1) > 0)
984 set_bit(F_WRITING, &dev.flags);
985 }
986
987 if (dev.play_ndelay) {
988 free_page((unsigned long)page);
989 return count == len ? -EAGAIN : len - count;
990 }
991
992 if (count > 0) {
993 set_bit(F_WRITEBLOCK, &dev.flags);
994 interruptible_sleep_on_timeout(
995 &dev.writeblock,
996 get_play_delay_jiffies(DAP_BUFF_SIZE));
997 clear_bit(F_WRITEBLOCK, &dev.flags);
998 if (signal_pending(current)) {
999 free_page((unsigned long)page);
1000 return -EINTR;
1001 }
1002 }
1003 }
1004
1005 free_page((unsigned long)page);
1006 return len - count;
1007}
1008
1009static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_t *off)
1010{
1011 int minor = iminor(file->f_dentry->d_inode);
1012 if (minor == dev.dsp_minor)
1013 return dsp_read(buf, count);
1014 else
1015 return -EINVAL;
1016}
1017
1018static ssize_t dev_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
1019{
1020 int minor = iminor(file->f_dentry->d_inode);
1021 if (minor == dev.dsp_minor)
1022 return dsp_write(buf, count);
1023 else
1024 return -EINVAL;
1025}
1026
1027static __inline__ void eval_dsp_msg(register WORD wMessage)
1028{
1029 switch (HIBYTE(wMessage)) {
1030 case HIMT_PLAY_DONE:
1031 if (dev.last_playbank == LOBYTE(wMessage) || !test_bit(F_WRITING, &dev.flags))
1032 break;
1033 dev.last_playbank = LOBYTE(wMessage);
1034
1035 if (pack_DAPF_to_DAPQ(0) <= 0) {
1036 if (!test_bit(F_WRITEBLOCK, &dev.flags)) {
1037 if (test_and_clear_bit(F_WRITEFLUSH, &dev.flags))
1038 wake_up_interruptible(&dev.writeflush);
1039 }
1040 clear_bit(F_WRITING, &dev.flags);
1041 }
1042
1043 if (test_bit(F_WRITEBLOCK, &dev.flags))
1044 wake_up_interruptible(&dev.writeblock);
1045 break;
1046
1047 case HIMT_RECORD_DONE:
1048 if (dev.last_recbank == LOBYTE(wMessage))
1049 break;
1050 dev.last_recbank = LOBYTE(wMessage);
1051
1052 pack_DARQ_to_DARF(dev.last_recbank);
1053
1054 if (test_bit(F_READBLOCK, &dev.flags))
1055 wake_up_interruptible(&dev.readblock);
1056 break;
1057
1058 case HIMT_DSP:
1059 switch (LOBYTE(wMessage)) {
1060#ifndef MSND_CLASSIC
1061 case HIDSP_PLAY_UNDER:
1062#endif
1063 case HIDSP_INT_PLAY_UNDER:
1064/* printk(KERN_DEBUG LOGNAME ": Play underflow\n"); */
1065 clear_bit(F_WRITING, &dev.flags);
1066 break;
1067
1068 case HIDSP_INT_RECORD_OVER:
1069/* printk(KERN_DEBUG LOGNAME ": Record overflow\n"); */
1070 clear_bit(F_READING, &dev.flags);
1071 break;
1072
1073 default:
1074/* printk(KERN_DEBUG LOGNAME ": DSP message %d 0x%02x\n",
1075 LOBYTE(wMessage), LOBYTE(wMessage)); */
1076 break;
1077 }
1078 break;
1079
1080 case HIMT_MIDI_IN_UCHAR:
1081 if (dev.midi_in_interrupt)
1082 (*dev.midi_in_interrupt)(&dev);
1083 break;
1084
1085 default:
1086/* printk(KERN_DEBUG LOGNAME ": HIMT message %d 0x%02x\n", HIBYTE(wMessage), HIBYTE(wMessage)); */
1087 break;
1088 }
1089}
1090
1091static irqreturn_t intr(int irq, void *dev_id, struct pt_regs *regs)
1092{
1093 /* Send ack to DSP */
1094 msnd_inb(dev.io + HP_RXL);
1095
1096 /* Evaluate queued DSP messages */
1097 while (readw(dev.DSPQ + JQS_wTail) != readw(dev.DSPQ + JQS_wHead)) {
1098 register WORD wTmp;
1099
1100 eval_dsp_msg(readw(dev.pwDSPQData + 2*readw(dev.DSPQ + JQS_wHead)));
1101
1102 if ((wTmp = readw(dev.DSPQ + JQS_wHead) + 1) > readw(dev.DSPQ + JQS_wSize))
1103 writew(0, dev.DSPQ + JQS_wHead);
1104 else
1105 writew(wTmp, dev.DSPQ + JQS_wHead);
1106 }
1107 return IRQ_HANDLED;
1108}
1109
1110static struct file_operations dev_fileops = {
1111 .owner = THIS_MODULE,
1112 .read = dev_read,
1113 .write = dev_write,
1114 .ioctl = dev_ioctl,
1115 .open = dev_open,
1116 .release = dev_release,
1117};
1118
1119static int reset_dsp(void)
1120{
1121 int timeout = 100;
1122
1123 msnd_outb(HPDSPRESET_ON, dev.io + HP_DSPR);
1124 mdelay(1);
1125#ifndef MSND_CLASSIC
1126 dev.info = msnd_inb(dev.io + HP_INFO);
1127#endif
1128 msnd_outb(HPDSPRESET_OFF, dev.io + HP_DSPR);
1129 mdelay(1);
1130 while (timeout-- > 0) {
1131 if (msnd_inb(dev.io + HP_CVR) == HP_CVR_DEF)
1132 return 0;
1133 mdelay(1);
1134 }
1135 printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
1136
1137 return -EIO;
1138}
1139
1140static int __init probe_multisound(void)
1141{
1142#ifndef MSND_CLASSIC
1143 char *xv, *rev = NULL;
1144 char *pin = "Pinnacle", *fiji = "Fiji";
1145 char *pinfiji = "Pinnacle/Fiji";
1146#endif
1147
1148 if (!request_region(dev.io, dev.numio, "probing")) {
1149 printk(KERN_ERR LOGNAME ": I/O port conflict\n");
1150 return -ENODEV;
1151 }
1152
1153 if (reset_dsp() < 0) {
1154 release_region(dev.io, dev.numio);
1155 return -ENODEV;
1156 }
1157
1158#ifdef MSND_CLASSIC
1159 dev.name = "Classic/Tahiti/Monterey";
1160 printk(KERN_INFO LOGNAME ": %s, "
1161#else
1162 switch (dev.info >> 4) {
1163 case 0xf: xv = "<= 1.15"; break;
1164 case 0x1: xv = "1.18/1.2"; break;
1165 case 0x2: xv = "1.3"; break;
1166 case 0x3: xv = "1.4"; break;
1167 default: xv = "unknown"; break;
1168 }
1169
1170 switch (dev.info & 0x7) {
1171 case 0x0: rev = "I"; dev.name = pin; break;
1172 case 0x1: rev = "F"; dev.name = pin; break;
1173 case 0x2: rev = "G"; dev.name = pin; break;
1174 case 0x3: rev = "H"; dev.name = pin; break;
1175 case 0x4: rev = "E"; dev.name = fiji; break;
1176 case 0x5: rev = "C"; dev.name = fiji; break;
1177 case 0x6: rev = "D"; dev.name = fiji; break;
1178 case 0x7:
1179 rev = "A-B (Fiji) or A-E (Pinnacle)";
1180 dev.name = pinfiji;
1181 break;
1182 }
1183 printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
1184#endif /* MSND_CLASSIC */
1185 "I/O 0x%x-0x%x, IRQ %d, memory mapped to %p-%p\n",
1186 dev.name,
1187#ifndef MSND_CLASSIC
1188 rev, xv,
1189#endif
1190 dev.io, dev.io + dev.numio - 1,
1191 dev.irq,
1192 dev.base, dev.base + 0x7fff);
1193
1194 release_region(dev.io, dev.numio);
1195 return 0;
1196}
1197
1198static int init_sma(void)
1199{
1200 static int initted;
1201 WORD mastVolLeft, mastVolRight;
1202 unsigned long flags;
1203
1204#ifdef MSND_CLASSIC
1205 msnd_outb(dev.memid, dev.io + HP_MEMM);
1206#endif
1207 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1208 if (initted) {
1209 mastVolLeft = readw(dev.SMA + SMA_wCurrMastVolLeft);
1210 mastVolRight = readw(dev.SMA + SMA_wCurrMastVolRight);
1211 } else
1212 mastVolLeft = mastVolRight = 0;
1213 memset_io(dev.base, 0, 0x8000);
1214
1215 /* Critical section: bank 1 access */
1216 spin_lock_irqsave(&dev.lock, flags);
1217 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
1218 memset_io(dev.base, 0, 0x8000);
1219 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1220 spin_unlock_irqrestore(&dev.lock, flags);
1221
1222 dev.pwDSPQData = (dev.base + DSPQ_DATA_BUFF);
1223 dev.pwMODQData = (dev.base + MODQ_DATA_BUFF);
1224 dev.pwMIDQData = (dev.base + MIDQ_DATA_BUFF);
1225
1226 /* Motorola 56k shared memory base */
1227 dev.SMA = dev.base + SMA_STRUCT_START;
1228
1229 /* Digital audio play queue */
1230 dev.DAPQ = dev.base + DAPQ_OFFSET;
1231 msnd_init_queue(dev.DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
1232
1233 /* Digital audio record queue */
1234 dev.DARQ = dev.base + DARQ_OFFSET;
1235 msnd_init_queue(dev.DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
1236
1237 /* MIDI out queue */
1238 dev.MODQ = dev.base + MODQ_OFFSET;
1239 msnd_init_queue(dev.MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
1240
1241 /* MIDI in queue */
1242 dev.MIDQ = dev.base + MIDQ_OFFSET;
1243 msnd_init_queue(dev.MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
1244
1245 /* DSP -> host message queue */
1246 dev.DSPQ = dev.base + DSPQ_OFFSET;
1247 msnd_init_queue(dev.DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
1248
1249 /* Setup some DSP values */
1250#ifndef MSND_CLASSIC
1251 writew(1, dev.SMA + SMA_wCurrPlayFormat);
1252 writew(dev.play_sample_size, dev.SMA + SMA_wCurrPlaySampleSize);
1253 writew(dev.play_channels, dev.SMA + SMA_wCurrPlayChannels);
1254 writew(dev.play_sample_rate, dev.SMA + SMA_wCurrPlaySampleRate);
1255#endif
1256 writew(dev.play_sample_rate, dev.SMA + SMA_wCalFreqAtoD);
1257 writew(mastVolLeft, dev.SMA + SMA_wCurrMastVolLeft);
1258 writew(mastVolRight, dev.SMA + SMA_wCurrMastVolRight);
1259#ifndef MSND_CLASSIC
1260 writel(0x00010000, dev.SMA + SMA_dwCurrPlayPitch);
1261 writel(0x00000001, dev.SMA + SMA_dwCurrPlayRate);
1262#endif
1263 writew(0x303, dev.SMA + SMA_wCurrInputTagBits);
1264
1265 initted = 1;
1266
1267 return 0;
1268}
1269
1270static int __init calibrate_adc(WORD srate)
1271{
1272 writew(srate, dev.SMA + SMA_wCalFreqAtoD);
1273 if (dev.calibrate_signal == 0)
1274 writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
1275 | 0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
1276 else
1277 writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
1278 & ~0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
1279 if (msnd_send_word(&dev, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
1280 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ) == 0) {
1281 current->state = TASK_INTERRUPTIBLE;
1282 schedule_timeout(HZ / 3);
1283 return 0;
1284 }
1285 printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
1286
1287 return -EIO;
1288}
1289
1290static int upload_dsp_code(void)
1291{
1292 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1293#ifndef HAVE_DSPCODEH
1294 INITCODESIZE = mod_firmware_load(INITCODEFILE, &INITCODE);
1295 if (!INITCODE) {
1296 printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
1297 return -EBUSY;
1298 }
1299
1300 PERMCODESIZE = mod_firmware_load(PERMCODEFILE, &PERMCODE);
1301 if (!PERMCODE) {
1302 printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
1303 vfree(INITCODE);
1304 return -EBUSY;
1305 }
1306#endif
1307 memcpy_toio(dev.base, PERMCODE, PERMCODESIZE);
1308 if (msnd_upload_host(&dev, INITCODE, INITCODESIZE) < 0) {
1309 printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
1310 return -ENODEV;
1311 }
1312#ifdef HAVE_DSPCODEH
1313 printk(KERN_INFO LOGNAME ": DSP firmware uploaded (resident)\n");
1314#else
1315 printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
1316#endif
1317
1318#ifndef HAVE_DSPCODEH
1319 vfree(INITCODE);
1320 vfree(PERMCODE);
1321#endif
1322
1323 return 0;
1324}
1325
1326#ifdef MSND_CLASSIC
1327static void reset_proteus(void)
1328{
1329 msnd_outb(HPPRORESET_ON, dev.io + HP_PROR);
1330 mdelay(TIME_PRO_RESET);
1331 msnd_outb(HPPRORESET_OFF, dev.io + HP_PROR);
1332 mdelay(TIME_PRO_RESET_DONE);
1333}
1334#endif
1335
1336static int initialize(void)
1337{
1338 int err, timeout;
1339
1340#ifdef MSND_CLASSIC
1341 msnd_outb(HPWAITSTATE_0, dev.io + HP_WAIT);
1342 msnd_outb(HPBITMODE_16, dev.io + HP_BITM);
1343
1344 reset_proteus();
1345#endif
1346 if ((err = init_sma()) < 0) {
1347 printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
1348 return err;
1349 }
1350
1351 if ((err = reset_dsp()) < 0)
1352 return err;
1353
1354 if ((err = upload_dsp_code()) < 0) {
1355 printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
1356 return err;
1357 }
1358
1359 timeout = 200;
1360 while (readw(dev.base)) {
1361 mdelay(1);
1362 if (!timeout--) {
1363 printk(KERN_DEBUG LOGNAME ": DSP reset timeout\n");
1364 return -EIO;
1365 }
1366 }
1367
1368 mixer_setup();
1369
1370 return 0;
1371}
1372
1373static int dsp_full_reset(void)
1374{
1375 int rv;
1376
1377 if (test_bit(F_RESETTING, &dev.flags) || ++dev.nresets > 10)
1378 return 0;
1379
1380 set_bit(F_RESETTING, &dev.flags);
1381 printk(KERN_INFO LOGNAME ": DSP reset\n");
1382 dsp_halt(NULL); /* Unconditionally halt */
1383 if ((rv = initialize()))
1384 printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
1385 force_recsrc(dev.recsrc);
1386 dsp_open(NULL);
1387 clear_bit(F_RESETTING, &dev.flags);
1388
1389 return rv;
1390}
1391
1392static int __init attach_multisound(void)
1393{
1394 int err;
1395
1396 if ((err = request_irq(dev.irq, intr, 0, dev.name, &dev)) < 0) {
1397 printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", dev.irq);
1398 return err;
1399 }
1400 request_region(dev.io, dev.numio, dev.name);
1401
1402 if ((err = dsp_full_reset()) < 0) {
1403 release_region(dev.io, dev.numio);
1404 free_irq(dev.irq, &dev);
1405 return err;
1406 }
1407
1408 if ((err = msnd_register(&dev)) < 0) {
1409 printk(KERN_ERR LOGNAME ": Unable to register MultiSound\n");
1410 release_region(dev.io, dev.numio);
1411 free_irq(dev.irq, &dev);
1412 return err;
1413 }
1414
1415 if ((dev.dsp_minor = register_sound_dsp(&dev_fileops, -1)) < 0) {
1416 printk(KERN_ERR LOGNAME ": Unable to register DSP operations\n");
1417 msnd_unregister(&dev);
1418 release_region(dev.io, dev.numio);
1419 free_irq(dev.irq, &dev);
1420 return dev.dsp_minor;
1421 }
1422
1423 if ((dev.mixer_minor = register_sound_mixer(&dev_fileops, -1)) < 0) {
1424 printk(KERN_ERR LOGNAME ": Unable to register mixer operations\n");
1425 unregister_sound_mixer(dev.mixer_minor);
1426 msnd_unregister(&dev);
1427 release_region(dev.io, dev.numio);
1428 free_irq(dev.irq, &dev);
1429 return dev.mixer_minor;
1430 }
1431
1432 dev.ext_midi_dev = dev.hdr_midi_dev = -1;
1433
1434 disable_irq(dev.irq);
1435 calibrate_adc(dev.play_sample_rate);
1436#ifndef MSND_CLASSIC
1437 force_recsrc(SOUND_MASK_IMIX);
1438#endif
1439
1440 return 0;
1441}
1442
1443static void __exit unload_multisound(void)
1444{
1445 release_region(dev.io, dev.numio);
1446 free_irq(dev.irq, &dev);
1447 unregister_sound_mixer(dev.mixer_minor);
1448 unregister_sound_dsp(dev.dsp_minor);
1449 msnd_unregister(&dev);
1450}
1451
1452#ifndef MSND_CLASSIC
1453
1454/* Pinnacle/Fiji Logical Device Configuration */
1455
1456static int __init msnd_write_cfg(int cfg, int reg, int value)
1457{
1458 msnd_outb(reg, cfg);
1459 msnd_outb(value, cfg + 1);
1460 if (value != msnd_inb(cfg + 1)) {
1461 printk(KERN_ERR LOGNAME ": msnd_write_cfg: I/O error\n");
1462 return -EIO;
1463 }
1464 return 0;
1465}
1466
1467static int __init msnd_write_cfg_io0(int cfg, int num, WORD io)
1468{
1469 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1470 return -EIO;
1471 if (msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
1472 return -EIO;
1473 if (msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
1474 return -EIO;
1475 return 0;
1476}
1477
1478static int __init msnd_write_cfg_io1(int cfg, int num, WORD io)
1479{
1480 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1481 return -EIO;
1482 if (msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
1483 return -EIO;
1484 if (msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
1485 return -EIO;
1486 return 0;
1487}
1488
1489static int __init msnd_write_cfg_irq(int cfg, int num, WORD irq)
1490{
1491 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1492 return -EIO;
1493 if (msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
1494 return -EIO;
1495 if (msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
1496 return -EIO;
1497 return 0;
1498}
1499
1500static int __init msnd_write_cfg_mem(int cfg, int num, int mem)
1501{
1502 WORD wmem;
1503
1504 mem >>= 8;
1505 mem &= 0xfff;
1506 wmem = (WORD)mem;
1507 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1508 return -EIO;
1509 if (msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
1510 return -EIO;
1511 if (msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
1512 return -EIO;
1513 if (wmem && msnd_write_cfg(cfg, IREG_MEMCONTROL, (MEMTYPE_HIADDR | MEMTYPE_16BIT)))
1514 return -EIO;
1515 return 0;
1516}
1517
1518static int __init msnd_activate_logical(int cfg, int num)
1519{
1520 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1521 return -EIO;
1522 if (msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
1523 return -EIO;
1524 return 0;
1525}
1526
1527static int __init msnd_write_cfg_logical(int cfg, int num, WORD io0, WORD io1, WORD irq, int mem)
1528{
1529 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1530 return -EIO;
1531 if (msnd_write_cfg_io0(cfg, num, io0))
1532 return -EIO;
1533 if (msnd_write_cfg_io1(cfg, num, io1))
1534 return -EIO;
1535 if (msnd_write_cfg_irq(cfg, num, irq))
1536 return -EIO;
1537 if (msnd_write_cfg_mem(cfg, num, mem))
1538 return -EIO;
1539 if (msnd_activate_logical(cfg, num))
1540 return -EIO;
1541 return 0;
1542}
1543
1544typedef struct msnd_pinnacle_cfg_device {
1545 WORD io0, io1, irq;
1546 int mem;
1547} msnd_pinnacle_cfg_t[4];
1548
1549static int __init msnd_pinnacle_cfg_devices(int cfg, int reset, msnd_pinnacle_cfg_t device)
1550{
1551 int i;
1552
1553 /* Reset devices if told to */
1554 if (reset) {
1555 printk(KERN_INFO LOGNAME ": Resetting all devices\n");
1556 for (i = 0; i < 4; ++i)
1557 if (msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
1558 return -EIO;
1559 }
1560
1561 /* Configure specified devices */
1562 for (i = 0; i < 4; ++i) {
1563
1564 switch (i) {
1565 case 0: /* DSP */
1566 if (!(device[i].io0 && device[i].irq && device[i].mem))
1567 continue;
1568 break;
1569 case 1: /* MPU */
1570 if (!(device[i].io0 && device[i].irq))
1571 continue;
1572 printk(KERN_INFO LOGNAME
1573 ": Configuring MPU to I/O 0x%x IRQ %d\n",
1574 device[i].io0, device[i].irq);
1575 break;
1576 case 2: /* IDE */
1577 if (!(device[i].io0 && device[i].io1 && device[i].irq))
1578 continue;
1579 printk(KERN_INFO LOGNAME
1580 ": Configuring IDE to I/O 0x%x, 0x%x IRQ %d\n",
1581 device[i].io0, device[i].io1, device[i].irq);
1582 break;
1583 case 3: /* Joystick */
1584 if (!(device[i].io0))
1585 continue;
1586 printk(KERN_INFO LOGNAME
1587 ": Configuring joystick to I/O 0x%x\n",
1588 device[i].io0);
1589 break;
1590 }
1591
1592 /* Configure the device */
1593 if (msnd_write_cfg_logical(cfg, i, device[i].io0, device[i].io1, device[i].irq, device[i].mem))
1594 return -EIO;
1595 }
1596
1597 return 0;
1598}
1599#endif
1600
1601#ifdef MODULE
1602MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
1603MODULE_DESCRIPTION ("Turtle Beach " LONGNAME " Linux Driver");
1604MODULE_LICENSE("GPL");
1605
1606static int io __initdata = -1;
1607static int irq __initdata = -1;
1608static int mem __initdata = -1;
1609static int write_ndelay __initdata = -1;
1610
1611#ifndef MSND_CLASSIC
1612/* Pinnacle/Fiji non-PnP Config Port */
1613static int cfg __initdata = -1;
1614
1615/* Extra Peripheral Configuration */
1616static int reset __initdata = 0;
1617static int mpu_io __initdata = 0;
1618static int mpu_irq __initdata = 0;
1619static int ide_io0 __initdata = 0;
1620static int ide_io1 __initdata = 0;
1621static int ide_irq __initdata = 0;
1622static int joystick_io __initdata = 0;
1623
1624/* If we have the digital daugherboard... */
1625static int digital __initdata = 0;
1626#endif
1627
1628static int fifosize __initdata = DEFFIFOSIZE;
1629static int calibrate_signal __initdata = 0;
1630
1631#else /* not a module */
1632
1633static int write_ndelay __initdata = -1;
1634
1635#ifdef MSND_CLASSIC
1636static int io __initdata = CONFIG_MSNDCLAS_IO;
1637static int irq __initdata = CONFIG_MSNDCLAS_IRQ;
1638static int mem __initdata = CONFIG_MSNDCLAS_MEM;
1639#else /* Pinnacle/Fiji */
1640
1641static int io __initdata = CONFIG_MSNDPIN_IO;
1642static int irq __initdata = CONFIG_MSNDPIN_IRQ;
1643static int mem __initdata = CONFIG_MSNDPIN_MEM;
1644
1645/* Pinnacle/Fiji non-PnP Config Port */
1646#ifdef CONFIG_MSNDPIN_NONPNP
1647# ifndef CONFIG_MSNDPIN_CFG
1648# define CONFIG_MSNDPIN_CFG 0x250
1649# endif
1650#else
1651# ifdef CONFIG_MSNDPIN_CFG
1652# undef CONFIG_MSNDPIN_CFG
1653# endif
1654# define CONFIG_MSNDPIN_CFG -1
1655#endif
1656static int cfg __initdata = CONFIG_MSNDPIN_CFG;
1657/* If not a module, we don't need to bother with reset=1 */
1658static int reset;
1659
1660/* Extra Peripheral Configuration (Default: Disable) */
1661#ifndef CONFIG_MSNDPIN_MPU_IO
1662# define CONFIG_MSNDPIN_MPU_IO 0
1663#endif
1664static int mpu_io __initdata = CONFIG_MSNDPIN_MPU_IO;
1665
1666#ifndef CONFIG_MSNDPIN_MPU_IRQ
1667# define CONFIG_MSNDPIN_MPU_IRQ 0
1668#endif
1669static int mpu_irq __initdata = CONFIG_MSNDPIN_MPU_IRQ;
1670
1671#ifndef CONFIG_MSNDPIN_IDE_IO0
1672# define CONFIG_MSNDPIN_IDE_IO0 0
1673#endif
1674static int ide_io0 __initdata = CONFIG_MSNDPIN_IDE_IO0;
1675
1676#ifndef CONFIG_MSNDPIN_IDE_IO1
1677# define CONFIG_MSNDPIN_IDE_IO1 0
1678#endif
1679static int ide_io1 __initdata = CONFIG_MSNDPIN_IDE_IO1;
1680
1681#ifndef CONFIG_MSNDPIN_IDE_IRQ
1682# define CONFIG_MSNDPIN_IDE_IRQ 0
1683#endif
1684static int ide_irq __initdata = CONFIG_MSNDPIN_IDE_IRQ;
1685
1686#ifndef CONFIG_MSNDPIN_JOYSTICK_IO
1687# define CONFIG_MSNDPIN_JOYSTICK_IO 0
1688#endif
1689static int joystick_io __initdata = CONFIG_MSNDPIN_JOYSTICK_IO;
1690
1691/* Have SPDIF (Digital) Daughterboard */
1692#ifndef CONFIG_MSNDPIN_DIGITAL
1693# define CONFIG_MSNDPIN_DIGITAL 0
1694#endif
1695static int digital __initdata = CONFIG_MSNDPIN_DIGITAL;
1696
1697#endif /* MSND_CLASSIC */
1698
1699#ifndef CONFIG_MSND_FIFOSIZE
1700# define CONFIG_MSND_FIFOSIZE DEFFIFOSIZE
1701#endif
1702static int fifosize __initdata = CONFIG_MSND_FIFOSIZE;
1703
1704#ifndef CONFIG_MSND_CALSIGNAL
1705# define CONFIG_MSND_CALSIGNAL 0
1706#endif
1707static int
1708calibrate_signal __initdata = CONFIG_MSND_CALSIGNAL;
1709#endif /* MODULE */
1710
1711module_param (io, int, 0);
1712module_param (irq, int, 0);
1713module_param (mem, int, 0);
1714module_param (write_ndelay, int, 0);
1715module_param (fifosize, int, 0);
1716module_param (calibrate_signal, int, 0);
1717#ifndef MSND_CLASSIC
1718module_param (digital, bool, 0);
1719module_param (cfg, int, 0);
1720module_param (reset, int, 0);
1721module_param (mpu_io, int, 0);
1722module_param (mpu_irq, int, 0);
1723module_param (ide_io0, int, 0);
1724module_param (ide_io1, int, 0);
1725module_param (ide_irq, int, 0);
1726module_param (joystick_io, int, 0);
1727#endif
1728
1729static int __init msnd_init(void)
1730{
1731 int err;
1732#ifndef MSND_CLASSIC
1733 static msnd_pinnacle_cfg_t pinnacle_devs;
1734#endif /* MSND_CLASSIC */
1735
1736 printk(KERN_INFO LOGNAME ": Turtle Beach " LONGNAME " Linux Driver Version "
1737 VERSION ", Copyright (C) 1998 Andrew Veliath\n");
1738
1739 if (io == -1 || irq == -1 || mem == -1)
1740 printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
1741
1742#ifdef MSND_CLASSIC
1743 if (io == -1 ||
1744 !(io == 0x290 ||
1745 io == 0x260 ||
1746 io == 0x250 ||
1747 io == 0x240 ||
1748 io == 0x230 ||
1749 io == 0x220 ||
1750 io == 0x210 ||
1751 io == 0x3e0)) {
1752 printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, or 0x3E0\n");
1753 return -EINVAL;
1754 }
1755#else
1756 if (io == -1 ||
1757 io < 0x100 ||
1758 io > 0x3e0 ||
1759 (io % 0x10) != 0) {
1760 printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must within the range 0x100 to 0x3E0 and must be evenly divisible by 0x10\n");
1761 return -EINVAL;
1762 }
1763#endif /* MSND_CLASSIC */
1764
1765 if (irq == -1 ||
1766 !(irq == 5 ||
1767 irq == 7 ||
1768 irq == 9 ||
1769 irq == 10 ||
1770 irq == 11 ||
1771 irq == 12)) {
1772 printk(KERN_ERR LOGNAME ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
1773 return -EINVAL;
1774 }
1775
1776 if (mem == -1 ||
1777 !(mem == 0xb0000 ||
1778 mem == 0xc8000 ||
1779 mem == 0xd0000 ||
1780 mem == 0xd8000 ||
1781 mem == 0xe0000 ||
1782 mem == 0xe8000)) {
1783 printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
1784 "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
1785 return -EINVAL;
1786 }
1787
1788#ifdef MSND_CLASSIC
1789 switch (irq) {
1790 case 5: dev.irqid = HPIRQ_5; break;
1791 case 7: dev.irqid = HPIRQ_7; break;
1792 case 9: dev.irqid = HPIRQ_9; break;
1793 case 10: dev.irqid = HPIRQ_10; break;
1794 case 11: dev.irqid = HPIRQ_11; break;
1795 case 12: dev.irqid = HPIRQ_12; break;
1796 }
1797
1798 switch (mem) {
1799 case 0xb0000: dev.memid = HPMEM_B000; break;
1800 case 0xc8000: dev.memid = HPMEM_C800; break;
1801 case 0xd0000: dev.memid = HPMEM_D000; break;
1802 case 0xd8000: dev.memid = HPMEM_D800; break;
1803 case 0xe0000: dev.memid = HPMEM_E000; break;
1804 case 0xe8000: dev.memid = HPMEM_E800; break;
1805 }
1806#else
1807 if (cfg == -1) {
1808 printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
1809 } else if (cfg != 0x250 && cfg != 0x260 && cfg != 0x270) {
1810 printk(KERN_INFO LOGNAME ": Config port must be 0x250, 0x260 or 0x270 (or unspecified for PnP mode)\n");
1811 return -EINVAL;
1812 } else {
1813 printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%x\n", cfg);
1814
1815 /* DSP */
1816 pinnacle_devs[0].io0 = io;
1817 pinnacle_devs[0].irq = irq;
1818 pinnacle_devs[0].mem = mem;
1819
1820 /* The following are Pinnacle specific */
1821
1822 /* MPU */
1823 pinnacle_devs[1].io0 = mpu_io;
1824 pinnacle_devs[1].irq = mpu_irq;
1825
1826 /* IDE */
1827 pinnacle_devs[2].io0 = ide_io0;
1828 pinnacle_devs[2].io1 = ide_io1;
1829 pinnacle_devs[2].irq = ide_irq;
1830
1831 /* Joystick */
1832 pinnacle_devs[3].io0 = joystick_io;
1833
1834 if (!request_region(cfg, 2, "Pinnacle/Fiji Config")) {
1835 printk(KERN_ERR LOGNAME ": Config port 0x%x conflict\n", cfg);
1836 return -EIO;
1837 }
1838
1839 if (msnd_pinnacle_cfg_devices(cfg, reset, pinnacle_devs)) {
1840 printk(KERN_ERR LOGNAME ": Device configuration error\n");
1841 release_region(cfg, 2);
1842 return -EIO;
1843 }
1844 release_region(cfg, 2);
1845 }
1846#endif /* MSND_CLASSIC */
1847
1848 if (fifosize < 16)
1849 fifosize = 16;
1850
1851 if (fifosize > 1024)
1852 fifosize = 1024;
1853
1854 set_default_audio_parameters();
1855#ifdef MSND_CLASSIC
1856 dev.type = msndClassic;
1857#else
1858 dev.type = msndPinnacle;
1859#endif
1860 dev.io = io;
1861 dev.numio = DSP_NUMIO;
1862 dev.irq = irq;
1863 dev.base = ioremap(mem, 0x8000);
1864 dev.fifosize = fifosize * 1024;
1865 dev.calibrate_signal = calibrate_signal ? 1 : 0;
1866 dev.recsrc = 0;
1867 dev.dspq_data_buff = DSPQ_DATA_BUFF;
1868 dev.dspq_buff_size = DSPQ_BUFF_SIZE;
1869 if (write_ndelay == -1)
1870 write_ndelay = CONFIG_MSND_WRITE_NDELAY;
1871 if (write_ndelay)
1872 clear_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
1873 else
1874 set_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
1875#ifndef MSND_CLASSIC
1876 if (digital)
1877 set_bit(F_HAVEDIGITAL, &dev.flags);
1878#endif
1879 init_waitqueue_head(&dev.writeblock);
1880 init_waitqueue_head(&dev.readblock);
1881 init_waitqueue_head(&dev.writeflush);
1882 msnd_fifo_init(&dev.DAPF);
1883 msnd_fifo_init(&dev.DARF);
1884 spin_lock_init(&dev.lock);
1885 printk(KERN_INFO LOGNAME ": %u byte audio FIFOs (x2)\n", dev.fifosize);
1886 if ((err = msnd_fifo_alloc(&dev.DAPF, dev.fifosize)) < 0) {
1887 printk(KERN_ERR LOGNAME ": Couldn't allocate write FIFO\n");
1888 return err;
1889 }
1890
1891 if ((err = msnd_fifo_alloc(&dev.DARF, dev.fifosize)) < 0) {
1892 printk(KERN_ERR LOGNAME ": Couldn't allocate read FIFO\n");
1893 msnd_fifo_free(&dev.DAPF);
1894 return err;
1895 }
1896
1897 if ((err = probe_multisound()) < 0) {
1898 printk(KERN_ERR LOGNAME ": Probe failed\n");
1899 msnd_fifo_free(&dev.DAPF);
1900 msnd_fifo_free(&dev.DARF);
1901 return err;
1902 }
1903
1904 if ((err = attach_multisound()) < 0) {
1905 printk(KERN_ERR LOGNAME ": Attach failed\n");
1906 msnd_fifo_free(&dev.DAPF);
1907 msnd_fifo_free(&dev.DARF);
1908 return err;
1909 }
1910
1911 return 0;
1912}
1913
1914static void __exit msdn_cleanup(void)
1915{
1916 unload_multisound();
1917 msnd_fifo_free(&dev.DAPF);
1918 msnd_fifo_free(&dev.DARF);
1919}
1920
1921module_init(msnd_init);
1922module_exit(msdn_cleanup);
diff --git a/sound/oss/msnd_pinnacle.h b/sound/oss/msnd_pinnacle.h
new file mode 100644
index 000000000000..e85aef4a55e0
--- /dev/null
+++ b/sound/oss/msnd_pinnacle.h
@@ -0,0 +1,249 @@
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 * $Id: msnd_pinnacle.h,v 1.11 1999/03/21 17:36:09 andrewtv Exp $
28 *
29 ********************************************************************/
30#ifndef __MSND_PINNACLE_H
31#define __MSND_PINNACLE_H
32
33#include <linux/config.h>
34
35#define DSP_NUMIO 0x08
36
37#define IREG_LOGDEVICE 0x07
38#define IREG_ACTIVATE 0x30
39#define LD_ACTIVATE 0x01
40#define LD_DISACTIVATE 0x00
41#define IREG_EECONTROL 0x3F
42#define IREG_MEMBASEHI 0x40
43#define IREG_MEMBASELO 0x41
44#define IREG_MEMCONTROL 0x42
45#define IREG_MEMRANGEHI 0x43
46#define IREG_MEMRANGELO 0x44
47#define MEMTYPE_8BIT 0x00
48#define MEMTYPE_16BIT 0x02
49#define MEMTYPE_RANGE 0x00
50#define MEMTYPE_HIADDR 0x01
51#define IREG_IO0_BASEHI 0x60
52#define IREG_IO0_BASELO 0x61
53#define IREG_IO1_BASEHI 0x62
54#define IREG_IO1_BASELO 0x63
55#define IREG_IRQ_NUMBER 0x70
56#define IREG_IRQ_TYPE 0x71
57#define IRQTYPE_HIGH 0x02
58#define IRQTYPE_LOW 0x00
59#define IRQTYPE_LEVEL 0x01
60#define IRQTYPE_EDGE 0x00
61
62#define HP_DSPR 0x04
63#define HP_BLKS 0x04
64
65#define HPDSPRESET_OFF 2
66#define HPDSPRESET_ON 0
67
68#define HPBLKSEL_0 2
69#define HPBLKSEL_1 3
70
71#define HIMT_DAT_OFF 0x03
72
73#define HIDSP_PLAY_UNDER 0x00
74#define HIDSP_INT_PLAY_UNDER 0x01
75#define HIDSP_SSI_TX_UNDER 0x02
76#define HIDSP_RECQ_OVERFLOW 0x08
77#define HIDSP_INT_RECORD_OVER 0x09
78#define HIDSP_SSI_RX_OVERFLOW 0x0a
79
80#define HIDSP_MIDI_IN_OVER 0x10
81
82#define HIDSP_MIDI_FRAME_ERR 0x11
83#define HIDSP_MIDI_PARITY_ERR 0x12
84#define HIDSP_MIDI_OVERRUN_ERR 0x13
85
86#define HIDSP_INPUT_CLIPPING 0x20
87#define HIDSP_MIX_CLIPPING 0x30
88#define HIDSP_DAT_IN_OFF 0x21
89
90#define HDEXAR_SET_ANA_IN 0
91#define HDEXAR_CLEAR_PEAKS 1
92#define HDEXAR_IN_SET_POTS 2
93#define HDEXAR_AUX_SET_POTS 3
94#define HDEXAR_CAL_A_TO_D 4
95#define HDEXAR_RD_EXT_DSP_BITS 5
96
97#define HDEXAR_SET_SYNTH_IN 4
98#define HDEXAR_READ_DAT_IN 5
99#define HDEXAR_MIC_SET_POTS 6
100#define HDEXAR_SET_DAT_IN 7
101
102#define HDEXAR_SET_SYNTH_48 8
103#define HDEXAR_SET_SYNTH_44 9
104
105#define TIME_PRO_RESET_DONE 0x028A
106#define TIME_PRO_SYSEX 0x001E
107#define TIME_PRO_RESET 0x0032
108
109#define AGND 0x01
110#define SIGNAL 0x02
111
112#define EXT_DSP_BIT_DCAL 0x0001
113#define EXT_DSP_BIT_MIDI_CON 0x0002
114
115#define BUFFSIZE 0x8000
116#define HOSTQ_SIZE 0x40
117
118#define SRAM_CNTL_START 0x7F00
119#define SMA_STRUCT_START 0x7F40
120
121#define DAP_BUFF_SIZE 0x2400
122#define DAR_BUFF_SIZE 0x2000
123
124#define DAPQ_STRUCT_SIZE 0x10
125#define DARQ_STRUCT_SIZE 0x10
126#define DAPQ_BUFF_SIZE (3 * 0x10)
127#define DARQ_BUFF_SIZE (3 * 0x10)
128#define MODQ_BUFF_SIZE 0x400
129#define MIDQ_BUFF_SIZE 0x800
130#define DSPQ_BUFF_SIZE 0x5A0
131
132#define DAPQ_DATA_BUFF 0x6C00
133#define DARQ_DATA_BUFF 0x6C30
134#define MODQ_DATA_BUFF 0x6C60
135#define MIDQ_DATA_BUFF 0x7060
136#define DSPQ_DATA_BUFF 0x7860
137
138#define DAPQ_OFFSET SRAM_CNTL_START
139#define DARQ_OFFSET (SRAM_CNTL_START + 0x08)
140#define MODQ_OFFSET (SRAM_CNTL_START + 0x10)
141#define MIDQ_OFFSET (SRAM_CNTL_START + 0x18)
142#define DSPQ_OFFSET (SRAM_CNTL_START + 0x20)
143
144#define MOP_WAVEHDR 0
145#define MOP_EXTOUT 1
146#define MOP_HWINIT 0xfe
147#define MOP_NONE 0xff
148#define MOP_MAX 1
149
150#define MIP_EXTIN 0
151#define MIP_WAVEHDR 1
152#define MIP_HWINIT 0xfe
153#define MIP_MAX 1
154
155/* Pinnacle/Fiji SMA Common Data */
156#define SMA_wCurrPlayBytes 0x0000
157#define SMA_wCurrRecordBytes 0x0002
158#define SMA_wCurrPlayVolLeft 0x0004
159#define SMA_wCurrPlayVolRight 0x0006
160#define SMA_wCurrInVolLeft 0x0008
161#define SMA_wCurrInVolRight 0x000a
162#define SMA_wCurrMHdrVolLeft 0x000c
163#define SMA_wCurrMHdrVolRight 0x000e
164#define SMA_dwCurrPlayPitch 0x0010
165#define SMA_dwCurrPlayRate 0x0014
166#define SMA_wCurrMIDIIOPatch 0x0018
167#define SMA_wCurrPlayFormat 0x001a
168#define SMA_wCurrPlaySampleSize 0x001c
169#define SMA_wCurrPlayChannels 0x001e
170#define SMA_wCurrPlaySampleRate 0x0020
171#define SMA_wCurrRecordFormat 0x0022
172#define SMA_wCurrRecordSampleSize 0x0024
173#define SMA_wCurrRecordChannels 0x0026
174#define SMA_wCurrRecordSampleRate 0x0028
175#define SMA_wCurrDSPStatusFlags 0x002a
176#define SMA_wCurrHostStatusFlags 0x002c
177#define SMA_wCurrInputTagBits 0x002e
178#define SMA_wCurrLeftPeak 0x0030
179#define SMA_wCurrRightPeak 0x0032
180#define SMA_bMicPotPosLeft 0x0034
181#define SMA_bMicPotPosRight 0x0035
182#define SMA_bMicPotMaxLeft 0x0036
183#define SMA_bMicPotMaxRight 0x0037
184#define SMA_bInPotPosLeft 0x0038
185#define SMA_bInPotPosRight 0x0039
186#define SMA_bAuxPotPosLeft 0x003a
187#define SMA_bAuxPotPosRight 0x003b
188#define SMA_bInPotMaxLeft 0x003c
189#define SMA_bInPotMaxRight 0x003d
190#define SMA_bAuxPotMaxLeft 0x003e
191#define SMA_bAuxPotMaxRight 0x003f
192#define SMA_bInPotMaxMethod 0x0040
193#define SMA_bAuxPotMaxMethod 0x0041
194#define SMA_wCurrMastVolLeft 0x0042
195#define SMA_wCurrMastVolRight 0x0044
196#define SMA_wCalFreqAtoD 0x0046
197#define SMA_wCurrAuxVolLeft 0x0048
198#define SMA_wCurrAuxVolRight 0x004a
199#define SMA_wCurrPlay1VolLeft 0x004c
200#define SMA_wCurrPlay1VolRight 0x004e
201#define SMA_wCurrPlay2VolLeft 0x0050
202#define SMA_wCurrPlay2VolRight 0x0052
203#define SMA_wCurrPlay3VolLeft 0x0054
204#define SMA_wCurrPlay3VolRight 0x0056
205#define SMA_wCurrPlay4VolLeft 0x0058
206#define SMA_wCurrPlay4VolRight 0x005a
207#define SMA_wCurrPlay1PeakLeft 0x005c
208#define SMA_wCurrPlay1PeakRight 0x005e
209#define SMA_wCurrPlay2PeakLeft 0x0060
210#define SMA_wCurrPlay2PeakRight 0x0062
211#define SMA_wCurrPlay3PeakLeft 0x0064
212#define SMA_wCurrPlay3PeakRight 0x0066
213#define SMA_wCurrPlay4PeakLeft 0x0068
214#define SMA_wCurrPlay4PeakRight 0x006a
215#define SMA_wCurrPlayPeakLeft 0x006c
216#define SMA_wCurrPlayPeakRight 0x006e
217#define SMA_wCurrDATSR 0x0070
218#define SMA_wCurrDATRXCHNL 0x0072
219#define SMA_wCurrDATTXCHNL 0x0074
220#define SMA_wCurrDATRXRate 0x0076
221#define SMA_dwDSPPlayCount 0x0078
222#define SMA__size 0x007c
223
224#ifdef HAVE_DSPCODEH
225# include "pndsperm.c"
226# include "pndspini.c"
227# define PERMCODE pndsperm
228# define INITCODE pndspini
229# define PERMCODESIZE sizeof(pndsperm)
230# define INITCODESIZE sizeof(pndspini)
231#else
232# ifndef CONFIG_MSNDPIN_INIT_FILE
233# define CONFIG_MSNDPIN_INIT_FILE \
234 "/etc/sound/pndspini.bin"
235# endif
236# ifndef CONFIG_MSNDPIN_PERM_FILE
237# define CONFIG_MSNDPIN_PERM_FILE \
238 "/etc/sound/pndsperm.bin"
239# endif
240# define PERMCODEFILE CONFIG_MSNDPIN_PERM_FILE
241# define INITCODEFILE CONFIG_MSNDPIN_INIT_FILE
242# define PERMCODE dspini
243# define INITCODE permini
244# define PERMCODESIZE sizeof_dspini
245# define INITCODESIZE sizeof_permini
246#endif
247#define LONGNAME "MultiSound (Pinnacle/Fiji)"
248
249#endif /* __MSND_PINNACLE_H */
diff --git a/sound/oss/nec_vrc5477.c b/sound/oss/nec_vrc5477.c
new file mode 100644
index 000000000000..0481e5e54ddf
--- /dev/null
+++ b/sound/oss/nec_vrc5477.c
@@ -0,0 +1,2059 @@
1/***********************************************************************
2 * Copyright 2001 MontaVista Software Inc.
3 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
4 *
5 * drivers/sound/nec_vrc5477.c
6 * AC97 sound dirver for NEC Vrc5477 chip (an integrated,
7 * multi-function controller chip for MIPS CPUs)
8 *
9 * VRA support Copyright 2001 Bradley D. LaRonde <brad@ltc.com>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 ***********************************************************************
16 */
17
18/*
19 * This code is derived from ite8172.c, which is written by Steve Longerbeam.
20 *
21 * Features:
22 * Currently we only support the following capabilities:
23 * . mono output to PCM L/R (line out).
24 * . stereo output to PCM L/R (line out).
25 * . mono input from PCM L (line in).
26 * . stereo output from PCM (line in).
27 * . sampling rate at 48k or variable sampling rate
28 * . support /dev/dsp, /dev/mixer devices, standard OSS devices.
29 * . only support 16-bit PCM format (hardware limit, no software
30 * translation)
31 * . support duplex, but no trigger or realtime.
32 *
33 * Specifically the following are not supported:
34 * . app-set frag size.
35 * . mmap'ed buffer access
36 */
37
38/*
39 * Original comments from ite8172.c file.
40 */
41
42/*
43 *
44 * Notes:
45 *
46 * 1. Much of the OSS buffer allocation, ioctl's, and mmap'ing are
47 * taken, slightly modified or not at all, from the ES1371 driver,
48 * so refer to the credits in es1371.c for those. The rest of the
49 * code (probe, open, read, write, the ISR, etc.) is new.
50 * 2. The following support is untested:
51 * * Memory mapping the audio buffers, and the ioctl controls that go
52 * with it.
53 * * S/PDIF output.
54 * 3. The following is not supported:
55 * * I2S input.
56 * * legacy audio mode.
57 * 4. Support for volume button interrupts is implemented but doesn't
58 * work yet.
59 *
60 * Revision history
61 * 02.08.2001 0.1 Initial release
62 */
63
64#include <linux/module.h>
65#include <linux/string.h>
66#include <linux/kernel.h>
67#include <linux/ioport.h>
68#include <linux/sched.h>
69#include <linux/delay.h>
70#include <linux/sound.h>
71#include <linux/slab.h>
72#include <linux/soundcard.h>
73#include <linux/pci.h>
74#include <linux/init.h>
75#include <linux/poll.h>
76#include <linux/bitops.h>
77#include <linux/proc_fs.h>
78#include <linux/spinlock.h>
79#include <linux/smp_lock.h>
80#include <linux/ac97_codec.h>
81#include <asm/io.h>
82#include <asm/dma.h>
83#include <asm/uaccess.h>
84
85/* -------------------debug macros -------------------------------------- */
86/* #undef VRC5477_AC97_DEBUG */
87#define VRC5477_AC97_DEBUG
88
89#undef VRC5477_AC97_VERBOSE_DEBUG
90/* #define VRC5477_AC97_VERBOSE_DEBUG */
91
92#if defined(VRC5477_AC97_VERBOSE_DEBUG)
93#define VRC5477_AC97_DEBUG
94#endif
95
96#if defined(VRC5477_AC97_DEBUG)
97#define ASSERT(x) if (!(x)) { \
98 panic("assertion failed at %s:%d: %s\n", __FILE__, __LINE__, #x); }
99#else
100#define ASSERT(x)
101#endif /* VRC5477_AC97_DEBUG */
102
103#if defined(VRC5477_AC97_VERBOSE_DEBUG)
104static u16 inTicket; /* check sync between intr & write */
105static u16 outTicket;
106#endif
107
108/* --------------------------------------------------------------------- */
109
110#undef OSS_DOCUMENTED_MIXER_SEMANTICS
111
112static const unsigned sample_shift[] = { 0, 1, 1, 2 };
113
114#define VRC5477_INT_CLR 0x0
115#define VRC5477_INT_STATUS 0x0
116#define VRC5477_CODEC_WR 0x4
117#define VRC5477_CODEC_RD 0x8
118#define VRC5477_CTRL 0x18
119#define VRC5477_ACLINK_CTRL 0x1c
120#define VRC5477_INT_MASK 0x24
121
122#define VRC5477_DAC1_CTRL 0x30
123#define VRC5477_DAC1L 0x34
124#define VRC5477_DAC1_BADDR 0x38
125#define VRC5477_DAC2_CTRL 0x3c
126#define VRC5477_DAC2L 0x40
127#define VRC5477_DAC2_BADDR 0x44
128#define VRC5477_DAC3_CTRL 0x48
129#define VRC5477_DAC3L 0x4c
130#define VRC5477_DAC3_BADDR 0x50
131
132#define VRC5477_ADC1_CTRL 0x54
133#define VRC5477_ADC1L 0x58
134#define VRC5477_ADC1_BADDR 0x5c
135#define VRC5477_ADC2_CTRL 0x60
136#define VRC5477_ADC2L 0x64
137#define VRC5477_ADC2_BADDR 0x68
138#define VRC5477_ADC3_CTRL 0x6c
139#define VRC5477_ADC3L 0x70
140#define VRC5477_ADC3_BADDR 0x74
141
142#define VRC5477_CODEC_WR_RWC (1 << 23)
143
144#define VRC5477_CODEC_RD_RRDYA (1 << 31)
145#define VRC5477_CODEC_RD_RRDYD (1 << 30)
146
147#define VRC5477_ACLINK_CTRL_RST_ON (1 << 15)
148#define VRC5477_ACLINK_CTRL_RST_TIME 0x7f
149#define VRC5477_ACLINK_CTRL_SYNC_ON (1 << 30)
150#define VRC5477_ACLINK_CTRL_CK_STOP_ON (1 << 31)
151
152#define VRC5477_CTRL_DAC2ENB (1 << 15)
153#define VRC5477_CTRL_ADC2ENB (1 << 14)
154#define VRC5477_CTRL_DAC1ENB (1 << 13)
155#define VRC5477_CTRL_ADC1ENB (1 << 12)
156
157#define VRC5477_INT_MASK_NMASK (1 << 31)
158#define VRC5477_INT_MASK_DAC1END (1 << 5)
159#define VRC5477_INT_MASK_DAC2END (1 << 4)
160#define VRC5477_INT_MASK_DAC3END (1 << 3)
161#define VRC5477_INT_MASK_ADC1END (1 << 2)
162#define VRC5477_INT_MASK_ADC2END (1 << 1)
163#define VRC5477_INT_MASK_ADC3END (1 << 0)
164
165#define VRC5477_DMA_ACTIVATION (1 << 31)
166#define VRC5477_DMA_WIP (1 << 30)
167
168
169#define VRC5477_AC97_MODULE_NAME "NEC_Vrc5477_audio"
170#define PFX VRC5477_AC97_MODULE_NAME ": "
171
172/* --------------------------------------------------------------------- */
173
174struct vrc5477_ac97_state {
175 /* list of vrc5477_ac97 devices */
176 struct list_head devs;
177
178 /* the corresponding pci_dev structure */
179 struct pci_dev *dev;
180
181 /* soundcore stuff */
182 int dev_audio;
183
184 /* hardware resources */
185 unsigned long io;
186 unsigned int irq;
187
188#ifdef VRC5477_AC97_DEBUG
189 /* debug /proc entry */
190 struct proc_dir_entry *ps;
191 struct proc_dir_entry *ac97_ps;
192#endif /* VRC5477_AC97_DEBUG */
193
194 struct ac97_codec *codec;
195
196 unsigned dacChannels, adcChannels;
197 unsigned short dacRate, adcRate;
198 unsigned short extended_status;
199
200 spinlock_t lock;
201 struct semaphore open_sem;
202 mode_t open_mode;
203 wait_queue_head_t open_wait;
204
205 struct dmabuf {
206 void *lbuf, *rbuf;
207 dma_addr_t lbufDma, rbufDma;
208 unsigned bufOrder;
209 unsigned numFrag;
210 unsigned fragShift;
211 unsigned fragSize; /* redundant */
212 unsigned fragTotalSize; /* = numFrag * fragSize(real) */
213 unsigned nextIn;
214 unsigned nextOut;
215 int count;
216 unsigned error; /* over/underrun */
217 wait_queue_head_t wait;
218 /* OSS stuff */
219 unsigned stopped:1;
220 unsigned ready:1;
221 } dma_dac, dma_adc;
222
223 #define WORK_BUF_SIZE 2048
224 struct {
225 u16 lchannel;
226 u16 rchannel;
227 } workBuf[WORK_BUF_SIZE/4];
228};
229
230/* --------------------------------------------------------------------- */
231
232static LIST_HEAD(devs);
233
234/* --------------------------------------------------------------------- */
235
236static inline unsigned ld2(unsigned int x)
237{
238 unsigned r = 0;
239
240 if (x >= 0x10000) {
241 x >>= 16;
242 r += 16;
243 }
244 if (x >= 0x100) {
245 x >>= 8;
246 r += 8;
247 }
248 if (x >= 0x10) {
249 x >>= 4;
250 r += 4;
251 }
252 if (x >= 4) {
253 x >>= 2;
254 r += 2;
255 }
256 if (x >= 2)
257 r++;
258 return r;
259}
260
261/* --------------------------------------------------------------------- */
262
263static u16 rdcodec(struct ac97_codec *codec, u8 addr)
264{
265 struct vrc5477_ac97_state *s =
266 (struct vrc5477_ac97_state *)codec->private_data;
267 unsigned long flags;
268 u32 result;
269
270 spin_lock_irqsave(&s->lock, flags);
271
272 /* wait until we can access codec registers */
273 while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
274
275 /* write the address and "read" command to codec */
276 addr = addr & 0x7f;
277 outl((addr << 16) | VRC5477_CODEC_WR_RWC, s->io + VRC5477_CODEC_WR);
278
279 /* get the return result */
280 udelay(100); /* workaround hardware bug */
281 while ( (result = inl(s->io + VRC5477_CODEC_RD)) &
282 (VRC5477_CODEC_RD_RRDYA | VRC5477_CODEC_RD_RRDYD) ) {
283 /* we get either addr or data, or both */
284 if (result & VRC5477_CODEC_RD_RRDYA) {
285 ASSERT(addr == ((result >> 16) & 0x7f) );
286 }
287 if (result & VRC5477_CODEC_RD_RRDYD) {
288 break;
289 }
290 }
291
292 spin_unlock_irqrestore(&s->lock, flags);
293
294 return result & 0xffff;
295}
296
297
298static void wrcodec(struct ac97_codec *codec, u8 addr, u16 data)
299{
300 struct vrc5477_ac97_state *s =
301 (struct vrc5477_ac97_state *)codec->private_data;
302 unsigned long flags;
303
304 spin_lock_irqsave(&s->lock, flags);
305
306 /* wait until we can access codec registers */
307 while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
308
309 /* write the address and value to codec */
310 outl((addr << 16) | data, s->io + VRC5477_CODEC_WR);
311
312 spin_unlock_irqrestore(&s->lock, flags);
313}
314
315
316static void waitcodec(struct ac97_codec *codec)
317{
318 struct vrc5477_ac97_state *s =
319 (struct vrc5477_ac97_state *)codec->private_data;
320
321 /* wait until we can access codec registers */
322 while (inl(s->io + VRC5477_CODEC_WR) & 0x80000000);
323}
324
325static int ac97_codec_not_present(struct ac97_codec *codec)
326{
327 struct vrc5477_ac97_state *s =
328 (struct vrc5477_ac97_state *)codec->private_data;
329 unsigned long flags;
330 unsigned short count = 0xffff;
331
332 spin_lock_irqsave(&s->lock, flags);
333
334 /* wait until we can access codec registers */
335 do {
336 if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
337 break;
338 } while (--count);
339
340 if (count == 0) {
341 spin_unlock_irqrestore(&s->lock, flags);
342 return -1;
343 }
344
345 /* write 0 to reset */
346 outl((AC97_RESET << 16) | 0, s->io + VRC5477_CODEC_WR);
347
348 /* test whether we get a response from ac97 chip */
349 count = 0xffff;
350 do {
351 if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
352 break;
353 } while (--count);
354
355 if (count == 0) {
356 spin_unlock_irqrestore(&s->lock, flags);
357 return -1;
358 }
359 spin_unlock_irqrestore(&s->lock, flags);
360 return 0;
361}
362
363/* --------------------------------------------------------------------- */
364
365static void vrc5477_ac97_delay(int msec)
366{
367 unsigned long tmo;
368 signed long tmo2;
369
370 if (in_interrupt())
371 return;
372
373 tmo = jiffies + (msec*HZ)/1000;
374 for (;;) {
375 tmo2 = tmo - jiffies;
376 if (tmo2 <= 0)
377 break;
378 schedule_timeout(tmo2);
379 }
380}
381
382
383static void set_adc_rate(struct vrc5477_ac97_state *s, unsigned rate)
384{
385 wrcodec(s->codec, AC97_PCM_LR_ADC_RATE, rate);
386 s->adcRate = rate;
387}
388
389
390static void set_dac_rate(struct vrc5477_ac97_state *s, unsigned rate)
391{
392 if(s->extended_status & AC97_EXTSTAT_VRA) {
393 wrcodec(s->codec, AC97_PCM_FRONT_DAC_RATE, rate);
394 s->dacRate = rdcodec(s->codec, AC97_PCM_FRONT_DAC_RATE);
395 }
396}
397
398static int ac97_codec_not_present(struct ac97_codec *codec)
399{
400 struct vrc5477_ac97_state *s =
401 (struct vrc5477_ac97_state *)codec->private_data;
402 unsigned long flags;
403 unsigned short count = 0xffff;
404
405 spin_lock_irqsave(&s->lock, flags);
406
407 /* wait until we can access codec registers */
408 do {
409 if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
410 break;
411 } while (--count);
412
413 if (count == 0) {
414 spin_unlock_irqrestore(&s->lock, flags);
415 return -1;
416 }
417
418 /* write 0 to reset */
419 outl((AC97_RESET << 16) | 0, s->io + VRC5477_CODEC_WR);
420
421 /* test whether we get a response from ac97 chip */
422 count = 0xffff;
423 do {
424 if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
425 break;
426 } while (--count);
427
428 if (count == 0) {
429 spin_unlock_irqrestore(&s->lock, flags);
430 return -1;
431 }
432 spin_unlock_irqrestore(&s->lock, flags);
433 return 0;
434}
435
436/* --------------------------------------------------------------------- */
437
438extern inline void
439stop_dac(struct vrc5477_ac97_state *s)
440{
441 struct dmabuf* db = &s->dma_dac;
442 unsigned long flags;
443 u32 temp;
444
445 spin_lock_irqsave(&s->lock, flags);
446
447 if (db->stopped) {
448 spin_unlock_irqrestore(&s->lock, flags);
449 return;
450 }
451
452 /* deactivate the dma */
453 outl(0, s->io + VRC5477_DAC1_CTRL);
454 outl(0, s->io + VRC5477_DAC2_CTRL);
455
456 /* wait for DAM completely stop */
457 while (inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
458 while (inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
459
460 /* disable dac slots in aclink */
461 temp = inl(s->io + VRC5477_CTRL);
462 temp &= ~ (VRC5477_CTRL_DAC1ENB | VRC5477_CTRL_DAC2ENB);
463 outl (temp, s->io + VRC5477_CTRL);
464
465 /* disable interrupts */
466 temp = inl(s->io + VRC5477_INT_MASK);
467 temp &= ~ (VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END);
468 outl (temp, s->io + VRC5477_INT_MASK);
469
470 /* clear pending ones */
471 outl(VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END,
472 s->io + VRC5477_INT_CLR);
473
474 db->stopped = 1;
475
476 spin_unlock_irqrestore(&s->lock, flags);
477}
478
479static void start_dac(struct vrc5477_ac97_state *s)
480{
481 struct dmabuf* db = &s->dma_dac;
482 unsigned long flags;
483 u32 dmaLength;
484 u32 temp;
485
486 spin_lock_irqsave(&s->lock, flags);
487
488 if (!db->stopped) {
489 spin_unlock_irqrestore(&s->lock, flags);
490 return;
491 }
492
493 /* we should have some data to do the DMA trasnfer */
494 ASSERT(db->count >= db->fragSize);
495
496 /* clear pending fales interrupts */
497 outl(VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END,
498 s->io + VRC5477_INT_CLR);
499
500 /* enable interrupts */
501 temp = inl(s->io + VRC5477_INT_MASK);
502 temp |= VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END;
503 outl(temp, s->io + VRC5477_INT_MASK);
504
505 /* setup dma base addr */
506 outl(db->lbufDma + db->nextOut, s->io + VRC5477_DAC1_BADDR);
507 if (s->dacChannels == 1) {
508 outl(db->lbufDma + db->nextOut, s->io + VRC5477_DAC2_BADDR);
509 } else {
510 outl(db->rbufDma + db->nextOut, s->io + VRC5477_DAC2_BADDR);
511 }
512
513 /* set dma length, in the unit of 0x10 bytes */
514 dmaLength = db->fragSize >> 4;
515 outl(dmaLength, s->io + VRC5477_DAC1L);
516 outl(dmaLength, s->io + VRC5477_DAC2L);
517
518 /* activate dma */
519 outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_DAC1_CTRL);
520 outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_DAC2_CTRL);
521
522 /* enable dac slots - we should hear the music now! */
523 temp = inl(s->io + VRC5477_CTRL);
524 temp |= (VRC5477_CTRL_DAC1ENB | VRC5477_CTRL_DAC2ENB);
525 outl (temp, s->io + VRC5477_CTRL);
526
527 /* it is time to setup next dma transfer */
528 ASSERT(inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
529 ASSERT(inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
530
531 temp = db->nextOut + db->fragSize;
532 if (temp >= db->fragTotalSize) {
533 ASSERT(temp == db->fragTotalSize);
534 temp = 0;
535 }
536
537 outl(db->lbufDma + temp, s->io + VRC5477_DAC1_BADDR);
538 if (s->dacChannels == 1) {
539 outl(db->lbufDma + temp, s->io + VRC5477_DAC2_BADDR);
540 } else {
541 outl(db->rbufDma + temp, s->io + VRC5477_DAC2_BADDR);
542 }
543
544 db->stopped = 0;
545
546#if defined(VRC5477_AC97_VERBOSE_DEBUG)
547 outTicket = *(u16*)(db->lbuf+db->nextOut);
548 if (db->count > db->fragSize) {
549 ASSERT((u16)(outTicket+1) == *(u16*)(db->lbuf+temp));
550 }
551#endif
552
553 spin_unlock_irqrestore(&s->lock, flags);
554}
555
556extern inline void stop_adc(struct vrc5477_ac97_state *s)
557{
558 struct dmabuf* db = &s->dma_adc;
559 unsigned long flags;
560 u32 temp;
561
562 spin_lock_irqsave(&s->lock, flags);
563
564 if (db->stopped) {
565 spin_unlock_irqrestore(&s->lock, flags);
566 return;
567 }
568
569 /* deactivate the dma */
570 outl(0, s->io + VRC5477_ADC1_CTRL);
571 outl(0, s->io + VRC5477_ADC2_CTRL);
572
573 /* disable adc slots in aclink */
574 temp = inl(s->io + VRC5477_CTRL);
575 temp &= ~ (VRC5477_CTRL_ADC1ENB | VRC5477_CTRL_ADC2ENB);
576 outl (temp, s->io + VRC5477_CTRL);
577
578 /* disable interrupts */
579 temp = inl(s->io + VRC5477_INT_MASK);
580 temp &= ~ (VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END);
581 outl (temp, s->io + VRC5477_INT_MASK);
582
583 /* clear pending ones */
584 outl(VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END,
585 s->io + VRC5477_INT_CLR);
586
587 db->stopped = 1;
588
589 spin_unlock_irqrestore(&s->lock, flags);
590}
591
592static void start_adc(struct vrc5477_ac97_state *s)
593{
594 struct dmabuf* db = &s->dma_adc;
595 unsigned long flags;
596 u32 dmaLength;
597 u32 temp;
598
599 spin_lock_irqsave(&s->lock, flags);
600
601 if (!db->stopped) {
602 spin_unlock_irqrestore(&s->lock, flags);
603 return;
604 }
605
606 /* we should at least have some free space in the buffer */
607 ASSERT(db->count < db->fragTotalSize - db->fragSize * 2);
608
609 /* clear pending ones */
610 outl(VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END,
611 s->io + VRC5477_INT_CLR);
612
613 /* enable interrupts */
614 temp = inl(s->io + VRC5477_INT_MASK);
615 temp |= VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END;
616 outl(temp, s->io + VRC5477_INT_MASK);
617
618 /* setup dma base addr */
619 outl(db->lbufDma + db->nextIn, s->io + VRC5477_ADC1_BADDR);
620 outl(db->rbufDma + db->nextIn, s->io + VRC5477_ADC2_BADDR);
621
622 /* setup dma length */
623 dmaLength = db->fragSize >> 4;
624 outl(dmaLength, s->io + VRC5477_ADC1L);
625 outl(dmaLength, s->io + VRC5477_ADC2L);
626
627 /* activate dma */
628 outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_ADC1_CTRL);
629 outl(VRC5477_DMA_ACTIVATION, s->io + VRC5477_ADC2_CTRL);
630
631 /* enable adc slots */
632 temp = inl(s->io + VRC5477_CTRL);
633 temp |= (VRC5477_CTRL_ADC1ENB | VRC5477_CTRL_ADC2ENB);
634 outl (temp, s->io + VRC5477_CTRL);
635
636 /* it is time to setup next dma transfer */
637 temp = db->nextIn + db->fragSize;
638 if (temp >= db->fragTotalSize) {
639 ASSERT(temp == db->fragTotalSize);
640 temp = 0;
641 }
642 outl(db->lbufDma + temp, s->io + VRC5477_ADC1_BADDR);
643 outl(db->rbufDma + temp, s->io + VRC5477_ADC2_BADDR);
644
645 db->stopped = 0;
646
647 spin_unlock_irqrestore(&s->lock, flags);
648}
649
650/* --------------------------------------------------------------------- */
651
652#define DMABUF_DEFAULTORDER (16-PAGE_SHIFT)
653#define DMABUF_MINORDER 1
654
655extern inline void dealloc_dmabuf(struct vrc5477_ac97_state *s,
656 struct dmabuf *db)
657{
658 if (db->lbuf) {
659 ASSERT(db->rbuf);
660 pci_free_consistent(s->dev, PAGE_SIZE << db->bufOrder,
661 db->lbuf, db->lbufDma);
662 pci_free_consistent(s->dev, PAGE_SIZE << db->bufOrder,
663 db->rbuf, db->rbufDma);
664 db->lbuf = db->rbuf = NULL;
665 }
666 db->nextIn = db->nextOut = 0;
667 db->ready = 0;
668}
669
670static int prog_dmabuf(struct vrc5477_ac97_state *s,
671 struct dmabuf *db,
672 unsigned rate)
673{
674 int order;
675 unsigned bufsize;
676
677 if (!db->lbuf) {
678 ASSERT(!db->rbuf);
679
680 db->ready = 0;
681 for (order = DMABUF_DEFAULTORDER;
682 order >= DMABUF_MINORDER;
683 order--) {
684 db->lbuf = pci_alloc_consistent(s->dev,
685 PAGE_SIZE << order,
686 &db->lbufDma);
687 db->rbuf = pci_alloc_consistent(s->dev,
688 PAGE_SIZE << order,
689 &db->rbufDma);
690 if (db->lbuf && db->rbuf) break;
691 if (db->lbuf) {
692 ASSERT(!db->rbuf);
693 pci_free_consistent(s->dev,
694 PAGE_SIZE << order,
695 db->lbuf,
696 db->lbufDma);
697 }
698 }
699 if (!db->lbuf) {
700 ASSERT(!db->rbuf);
701 return -ENOMEM;
702 }
703
704 db->bufOrder = order;
705 }
706
707 db->count = 0;
708 db->nextIn = db->nextOut = 0;
709
710 bufsize = PAGE_SIZE << db->bufOrder;
711 db->fragShift = ld2(rate * 2 / 100);
712 if (db->fragShift < 4) db->fragShift = 4;
713
714 db->numFrag = bufsize >> db->fragShift;
715 while (db->numFrag < 4 && db->fragShift > 4) {
716 db->fragShift--;
717 db->numFrag = bufsize >> db->fragShift;
718 }
719 db->fragSize = 1 << db->fragShift;
720 db->fragTotalSize = db->numFrag << db->fragShift;
721 memset(db->lbuf, 0, db->fragTotalSize);
722 memset(db->rbuf, 0, db->fragTotalSize);
723
724 db->ready = 1;
725
726 return 0;
727}
728
729static inline int prog_dmabuf_adc(struct vrc5477_ac97_state *s)
730{
731 stop_adc(s);
732 return prog_dmabuf(s, &s->dma_adc, s->adcRate);
733}
734
735static inline int prog_dmabuf_dac(struct vrc5477_ac97_state *s)
736{
737 stop_dac(s);
738 return prog_dmabuf(s, &s->dma_dac, s->dacRate);
739}
740
741
742/* --------------------------------------------------------------------- */
743/* hold spinlock for the following! */
744
745static inline void vrc5477_ac97_adc_interrupt(struct vrc5477_ac97_state *s)
746{
747 struct dmabuf* adc = &s->dma_adc;
748 unsigned temp;
749
750 /* we need two frags avaiable because one is already being used
751 * and the other will be used when next interrupt happens.
752 */
753 if (adc->count >= adc->fragTotalSize - adc->fragSize) {
754 stop_adc(s);
755 adc->error++;
756 printk(KERN_INFO PFX "adc overrun\n");
757 return;
758 }
759
760 /* set the base addr for next DMA transfer */
761 temp = adc->nextIn + 2*adc->fragSize;
762 if (temp >= adc->fragTotalSize) {
763 ASSERT( (temp == adc->fragTotalSize) ||
764 (temp == adc->fragTotalSize + adc->fragSize) );
765 temp -= adc->fragTotalSize;
766 }
767 outl(adc->lbufDma + temp, s->io + VRC5477_ADC1_BADDR);
768 outl(adc->rbufDma + temp, s->io + VRC5477_ADC2_BADDR);
769
770 /* adjust nextIn */
771 adc->nextIn += adc->fragSize;
772 if (adc->nextIn >= adc->fragTotalSize) {
773 ASSERT(adc->nextIn == adc->fragTotalSize);
774 adc->nextIn = 0;
775 }
776
777 /* adjust count */
778 adc->count += adc->fragSize;
779
780 /* wake up anybody listening */
781 if (waitqueue_active(&adc->wait)) {
782 wake_up_interruptible(&adc->wait);
783 }
784}
785
786static inline void vrc5477_ac97_dac_interrupt(struct vrc5477_ac97_state *s)
787{
788 struct dmabuf* dac = &s->dma_dac;
789 unsigned temp;
790
791 /* next DMA transfer should already started */
792 // ASSERT(inl(s->io + VRC5477_DAC1_CTRL) & VRC5477_DMA_WIP);
793 // ASSERT(inl(s->io + VRC5477_DAC2_CTRL) & VRC5477_DMA_WIP);
794
795 /* let us set for next next DMA transfer */
796 temp = dac->nextOut + dac->fragSize*2;
797 if (temp >= dac->fragTotalSize) {
798 ASSERT( (temp == dac->fragTotalSize) ||
799 (temp == dac->fragTotalSize + dac->fragSize) );
800 temp -= dac->fragTotalSize;
801 }
802 outl(dac->lbufDma + temp, s->io + VRC5477_DAC1_BADDR);
803 if (s->dacChannels == 1) {
804 outl(dac->lbufDma + temp, s->io + VRC5477_DAC2_BADDR);
805 } else {
806 outl(dac->rbufDma + temp, s->io + VRC5477_DAC2_BADDR);
807 }
808
809#if defined(VRC5477_AC97_VERBOSE_DEBUG)
810 if (*(u16*)(dac->lbuf + dac->nextOut) != outTicket) {
811 printk("assert fail: - %d vs %d\n",
812 *(u16*)(dac->lbuf + dac->nextOut),
813 outTicket);
814 ASSERT(1 == 0);
815 }
816#endif
817
818 /* adjust nextOut pointer */
819 dac->nextOut += dac->fragSize;
820 if (dac->nextOut >= dac->fragTotalSize) {
821 ASSERT(dac->nextOut == dac->fragTotalSize);
822 dac->nextOut = 0;
823 }
824
825 /* adjust count */
826 dac->count -= dac->fragSize;
827 if (dac->count <=0 ) {
828 /* buffer under run */
829 dac->count = 0;
830 dac->nextIn = dac->nextOut;
831 stop_dac(s);
832 }
833
834#if defined(VRC5477_AC97_VERBOSE_DEBUG)
835 if (dac->count) {
836 outTicket ++;
837 ASSERT(*(u16*)(dac->lbuf + dac->nextOut) == outTicket);
838 }
839#endif
840
841 /* we cannot have both under run and someone is waiting on us */
842 ASSERT(! (waitqueue_active(&dac->wait) && (dac->count <= 0)) );
843
844 /* wake up anybody listening */
845 if (waitqueue_active(&dac->wait))
846 wake_up_interruptible(&dac->wait);
847}
848
849static irqreturn_t vrc5477_ac97_interrupt(int irq, void *dev_id, struct pt_regs *regs)
850{
851 struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)dev_id;
852 u32 irqStatus;
853 u32 adcInterrupts, dacInterrupts;
854
855 spin_lock(&s->lock);
856
857 /* get irqStatus and clear the detected ones */
858 irqStatus = inl(s->io + VRC5477_INT_STATUS);
859 outl(irqStatus, s->io + VRC5477_INT_CLR);
860
861 /* let us see what we get */
862 dacInterrupts = VRC5477_INT_MASK_DAC1END | VRC5477_INT_MASK_DAC2END;
863 adcInterrupts = VRC5477_INT_MASK_ADC1END | VRC5477_INT_MASK_ADC2END;
864 if (irqStatus & dacInterrupts) {
865 /* we should get both interrupts, but just in case ... */
866 if (irqStatus & VRC5477_INT_MASK_DAC1END) {
867 vrc5477_ac97_dac_interrupt(s);
868 }
869 if ( (irqStatus & dacInterrupts) != dacInterrupts ) {
870 printk(KERN_WARNING "vrc5477_ac97 : dac interrupts not in sync!!!\n");
871 stop_dac(s);
872 start_dac(s);
873 }
874 } else if (irqStatus & adcInterrupts) {
875 /* we should get both interrupts, but just in case ... */
876 if(irqStatus & VRC5477_INT_MASK_ADC1END) {
877 vrc5477_ac97_adc_interrupt(s);
878 }
879 if ( (irqStatus & adcInterrupts) != adcInterrupts ) {
880 printk(KERN_WARNING "vrc5477_ac97 : adc interrupts not in sync!!!\n");
881 stop_adc(s);
882 start_adc(s);
883 }
884 }
885
886 spin_unlock(&s->lock);
887 return IRQ_HANDLED;
888}
889
890/* --------------------------------------------------------------------- */
891
892static int vrc5477_ac97_open_mixdev(struct inode *inode, struct file *file)
893{
894 int minor = iminor(inode);
895 struct list_head *list;
896 struct vrc5477_ac97_state *s;
897
898 for (list = devs.next; ; list = list->next) {
899 if (list == &devs)
900 return -ENODEV;
901 s = list_entry(list, struct vrc5477_ac97_state, devs);
902 if (s->codec->dev_mixer == minor)
903 break;
904 }
905 file->private_data = s;
906 return nonseekable_open(inode, file);
907}
908
909static int vrc5477_ac97_release_mixdev(struct inode *inode, struct file *file)
910{
911 return 0;
912}
913
914
915static int mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd,
916 unsigned long arg)
917{
918 return codec->mixer_ioctl(codec, cmd, arg);
919}
920
921static int vrc5477_ac97_ioctl_mixdev(struct inode *inode, struct file *file,
922 unsigned int cmd, unsigned long arg)
923{
924 struct vrc5477_ac97_state *s =
925 (struct vrc5477_ac97_state *)file->private_data;
926 struct ac97_codec *codec = s->codec;
927
928 return mixdev_ioctl(codec, cmd, arg);
929}
930
931static /*const*/ struct file_operations vrc5477_ac97_mixer_fops = {
932 .owner = THIS_MODULE,
933 .llseek = no_llseek,
934 .ioctl = vrc5477_ac97_ioctl_mixdev,
935 .open = vrc5477_ac97_open_mixdev,
936 .release = vrc5477_ac97_release_mixdev,
937};
938
939/* --------------------------------------------------------------------- */
940
941static int drain_dac(struct vrc5477_ac97_state *s, int nonblock)
942{
943 unsigned long flags;
944 int count, tmo;
945
946 if (!s->dma_dac.ready)
947 return 0;
948
949 for (;;) {
950 spin_lock_irqsave(&s->lock, flags);
951 count = s->dma_dac.count;
952 spin_unlock_irqrestore(&s->lock, flags);
953 if (count <= 0)
954 break;
955 if (signal_pending(current))
956 break;
957 if (nonblock)
958 return -EBUSY;
959 tmo = 1000 * count / s->dacRate / 2;
960 vrc5477_ac97_delay(tmo);
961 }
962 if (signal_pending(current))
963 return -ERESTARTSYS;
964 return 0;
965}
966
967/* --------------------------------------------------------------------- */
968
969static inline int
970copy_two_channel_adc_to_user(struct vrc5477_ac97_state *s,
971 char *buffer,
972 int copyCount)
973{
974 struct dmabuf *db = &s->dma_adc;
975 int bufStart = db->nextOut;
976 for (; copyCount > 0; ) {
977 int i;
978 int count = copyCount;
979 if (count > WORK_BUF_SIZE/2) count = WORK_BUF_SIZE/2;
980 for (i=0; i< count/2; i++) {
981 s->workBuf[i].lchannel =
982 *(u16*)(db->lbuf + bufStart + i*2);
983 s->workBuf[i].rchannel =
984 *(u16*)(db->rbuf + bufStart + i*2);
985 }
986 if (copy_to_user(buffer, s->workBuf, count*2)) {
987 return -1;
988 }
989
990 copyCount -= count;
991 bufStart += count;
992 ASSERT(bufStart <= db->fragTotalSize);
993 buffer += count *2;
994 }
995 return 0;
996}
997
998/* return the total bytes that is copied */
999static inline int
1000copy_adc_to_user(struct vrc5477_ac97_state *s,
1001 char * buffer,
1002 size_t count,
1003 int avail)
1004{
1005 struct dmabuf *db = &s->dma_adc;
1006 int copyCount=0;
1007 int copyFragCount=0;
1008 int totalCopyCount = 0;
1009 int totalCopyFragCount = 0;
1010 unsigned long flags;
1011
1012 /* adjust count to signel channel byte count */
1013 count >>= s->adcChannels - 1;
1014
1015 /* we may have to "copy" twice as ring buffer wraps around */
1016 for (; (avail > 0) && (count > 0); ) {
1017 /* determine max possible copy count for single channel */
1018 copyCount = count;
1019 if (copyCount > avail) {
1020 copyCount = avail;
1021 }
1022 if (copyCount + db->nextOut > db->fragTotalSize) {
1023 copyCount = db->fragTotalSize - db->nextOut;
1024 ASSERT((copyCount % db->fragSize) == 0);
1025 }
1026
1027 copyFragCount = (copyCount-1) >> db->fragShift;
1028 copyFragCount = (copyFragCount+1) << db->fragShift;
1029 ASSERT(copyFragCount >= copyCount);
1030
1031 /* we copy differently based on adc channels */
1032 if (s->adcChannels == 1) {
1033 if (copy_to_user(buffer,
1034 db->lbuf + db->nextOut,
1035 copyCount))
1036 return -1;
1037 } else {
1038 /* *sigh* we have to mix two streams into one */
1039 if (copy_two_channel_adc_to_user(s, buffer, copyCount))
1040 return -1;
1041 }
1042
1043 count -= copyCount;
1044 totalCopyCount += copyCount;
1045 avail -= copyFragCount;
1046 totalCopyFragCount += copyFragCount;
1047
1048 buffer += copyCount << (s->adcChannels-1);
1049
1050 db->nextOut += copyFragCount;
1051 if (db->nextOut >= db->fragTotalSize) {
1052 ASSERT(db->nextOut == db->fragTotalSize);
1053 db->nextOut = 0;
1054 }
1055
1056 ASSERT((copyFragCount % db->fragSize) == 0);
1057 ASSERT( (count == 0) || (copyCount == copyFragCount));
1058 }
1059
1060 spin_lock_irqsave(&s->lock, flags);
1061 db->count -= totalCopyFragCount;
1062 spin_unlock_irqrestore(&s->lock, flags);
1063
1064 return totalCopyCount << (s->adcChannels-1);
1065}
1066
1067static ssize_t
1068vrc5477_ac97_read(struct file *file,
1069 char *buffer,
1070 size_t count,
1071 loff_t *ppos)
1072{
1073 struct vrc5477_ac97_state *s =
1074 (struct vrc5477_ac97_state *)file->private_data;
1075 struct dmabuf *db = &s->dma_adc;
1076 ssize_t ret = 0;
1077 unsigned long flags;
1078 int copyCount;
1079 size_t avail;
1080
1081 if (!access_ok(VERIFY_WRITE, buffer, count))
1082 return -EFAULT;
1083
1084 ASSERT(db->ready);
1085
1086 while (count > 0) {
1087 // wait for samples in capture buffer
1088 do {
1089 spin_lock_irqsave(&s->lock, flags);
1090 if (db->stopped)
1091 start_adc(s);
1092 avail = db->count;
1093 spin_unlock_irqrestore(&s->lock, flags);
1094 if (avail <= 0) {
1095 if (file->f_flags & O_NONBLOCK) {
1096 if (!ret)
1097 ret = -EAGAIN;
1098 return ret;
1099 }
1100 interruptible_sleep_on(&db->wait);
1101 if (signal_pending(current)) {
1102 if (!ret)
1103 ret = -ERESTARTSYS;
1104 return ret;
1105 }
1106 }
1107 } while (avail <= 0);
1108
1109 ASSERT( (avail % db->fragSize) == 0);
1110 copyCount = copy_adc_to_user(s, buffer, count, avail);
1111 if (copyCount <=0 ) {
1112 if (!ret) ret = -EFAULT;
1113 return ret;
1114 }
1115
1116 count -= copyCount;
1117 buffer += copyCount;
1118 ret += copyCount;
1119 } // while (count > 0)
1120
1121 return ret;
1122}
1123
1124static inline int
1125copy_two_channel_dac_from_user(struct vrc5477_ac97_state *s,
1126 const char *buffer,
1127 int copyCount)
1128{
1129 struct dmabuf *db = &s->dma_dac;
1130 int bufStart = db->nextIn;
1131
1132 ASSERT(db->ready);
1133
1134 for (; copyCount > 0; ) {
1135 int i;
1136 int count = copyCount;
1137 if (count > WORK_BUF_SIZE/2) count = WORK_BUF_SIZE/2;
1138 if (copy_from_user(s->workBuf, buffer, count*2)) {
1139 return -1;
1140 }
1141 for (i=0; i< count/2; i++) {
1142 *(u16*)(db->lbuf + bufStart + i*2) =
1143 s->workBuf[i].lchannel;
1144 *(u16*)(db->rbuf + bufStart + i*2) =
1145 s->workBuf[i].rchannel;
1146 }
1147
1148 copyCount -= count;
1149 bufStart += count;
1150 ASSERT(bufStart <= db->fragTotalSize);
1151 buffer += count *2;
1152 }
1153 return 0;
1154
1155}
1156
1157/* return the total bytes that is copied */
1158static inline int
1159copy_dac_from_user(struct vrc5477_ac97_state *s,
1160 const char *buffer,
1161 size_t count,
1162 int avail)
1163{
1164 struct dmabuf *db = &s->dma_dac;
1165 int copyCount=0;
1166 int copyFragCount=0;
1167 int totalCopyCount = 0;
1168 int totalCopyFragCount = 0;
1169 unsigned long flags;
1170#if defined(VRC5477_AC97_VERBOSE_DEBUG)
1171 int i;
1172#endif
1173
1174 /* adjust count to signel channel byte count */
1175 count >>= s->dacChannels - 1;
1176
1177 /* we may have to "copy" twice as ring buffer wraps around */
1178 for (; (avail > 0) && (count > 0); ) {
1179 /* determine max possible copy count for single channel */
1180 copyCount = count;
1181 if (copyCount > avail) {
1182 copyCount = avail;
1183 }
1184 if (copyCount + db->nextIn > db->fragTotalSize) {
1185 copyCount = db->fragTotalSize - db->nextIn;
1186 ASSERT(copyCount > 0);
1187 }
1188
1189 copyFragCount = copyCount;
1190 ASSERT(copyFragCount >= copyCount);
1191
1192 /* we copy differently based on the number channels */
1193 if (s->dacChannels == 1) {
1194 if (copy_from_user(db->lbuf + db->nextIn,
1195 buffer,
1196 copyCount))
1197 return -1;
1198 /* fill gaps with 0 */
1199 memset(db->lbuf + db->nextIn + copyCount,
1200 0,
1201 copyFragCount - copyCount);
1202 } else {
1203 /* we have demux the stream into two separate ones */
1204 if (copy_two_channel_dac_from_user(s, buffer, copyCount))
1205 return -1;
1206 /* fill gaps with 0 */
1207 memset(db->lbuf + db->nextIn + copyCount,
1208 0,
1209 copyFragCount - copyCount);
1210 memset(db->rbuf + db->nextIn + copyCount,
1211 0,
1212 copyFragCount - copyCount);
1213 }
1214
1215#if defined(VRC5477_AC97_VERBOSE_DEBUG)
1216 for (i=0; i< copyFragCount; i+= db->fragSize) {
1217 *(u16*)(db->lbuf + db->nextIn + i) = inTicket ++;
1218 }
1219#endif
1220
1221 count -= copyCount;
1222 totalCopyCount += copyCount;
1223 avail -= copyFragCount;
1224 totalCopyFragCount += copyFragCount;
1225
1226 buffer += copyCount << (s->dacChannels - 1);
1227
1228 db->nextIn += copyFragCount;
1229 if (db->nextIn >= db->fragTotalSize) {
1230 ASSERT(db->nextIn == db->fragTotalSize);
1231 db->nextIn = 0;
1232 }
1233
1234 ASSERT( (count == 0) || (copyCount == copyFragCount));
1235 }
1236
1237 spin_lock_irqsave(&s->lock, flags);
1238 db->count += totalCopyFragCount;
1239 if (db->stopped) {
1240 start_dac(s);
1241 }
1242
1243 /* nextIn should not be equal to nextOut unless we are full */
1244 ASSERT( ( (db->count == db->fragTotalSize) &&
1245 (db->nextIn == db->nextOut) ) ||
1246 ( (db->count < db->fragTotalSize) &&
1247 (db->nextIn != db->nextOut) ) );
1248
1249 spin_unlock_irqrestore(&s->lock, flags);
1250
1251 return totalCopyCount << (s->dacChannels-1);
1252
1253}
1254
1255static ssize_t vrc5477_ac97_write(struct file *file, const char *buffer,
1256 size_t count, loff_t *ppos)
1257{
1258 struct vrc5477_ac97_state *s =
1259 (struct vrc5477_ac97_state *)file->private_data;
1260 struct dmabuf *db = &s->dma_dac;
1261 ssize_t ret;
1262 unsigned long flags;
1263 int copyCount, avail;
1264
1265 if (!access_ok(VERIFY_READ, buffer, count))
1266 return -EFAULT;
1267 ret = 0;
1268
1269 while (count > 0) {
1270 // wait for space in playback buffer
1271 do {
1272 spin_lock_irqsave(&s->lock, flags);
1273 avail = db->fragTotalSize - db->count;
1274 spin_unlock_irqrestore(&s->lock, flags);
1275 if (avail <= 0) {
1276 if (file->f_flags & O_NONBLOCK) {
1277 if (!ret)
1278 ret = -EAGAIN;
1279 return ret;
1280 }
1281 interruptible_sleep_on(&db->wait);
1282 if (signal_pending(current)) {
1283 if (!ret)
1284 ret = -ERESTARTSYS;
1285 return ret;
1286 }
1287 }
1288 } while (avail <= 0);
1289
1290 copyCount = copy_dac_from_user(s, buffer, count, avail);
1291 if (copyCount < 0) {
1292 if (!ret) ret = -EFAULT;
1293 return ret;
1294 }
1295
1296 count -= copyCount;
1297 buffer += copyCount;
1298 ret += copyCount;
1299 } // while (count > 0)
1300
1301 return ret;
1302}
1303
1304/* No kernel lock - we have our own spinlock */
1305static unsigned int vrc5477_ac97_poll(struct file *file,
1306 struct poll_table_struct *wait)
1307{
1308 struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)file->private_data;
1309 unsigned long flags;
1310 unsigned int mask = 0;
1311
1312 if (file->f_mode & FMODE_WRITE)
1313 poll_wait(file, &s->dma_dac.wait, wait);
1314 if (file->f_mode & FMODE_READ)
1315 poll_wait(file, &s->dma_adc.wait, wait);
1316 spin_lock_irqsave(&s->lock, flags);
1317 if (file->f_mode & FMODE_READ) {
1318 if (s->dma_adc.count >= (signed)s->dma_adc.fragSize)
1319 mask |= POLLIN | POLLRDNORM;
1320 }
1321 if (file->f_mode & FMODE_WRITE) {
1322 if ((signed)s->dma_dac.fragTotalSize >=
1323 s->dma_dac.count + (signed)s->dma_dac.fragSize)
1324 mask |= POLLOUT | POLLWRNORM;
1325 }
1326 spin_unlock_irqrestore(&s->lock, flags);
1327 return mask;
1328}
1329
1330#ifdef VRC5477_AC97_DEBUG
1331static struct ioctl_str_t {
1332 unsigned int cmd;
1333 const char* str;
1334} ioctl_str[] = {
1335 {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"},
1336 {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"},
1337 {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"},
1338 {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"},
1339 {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"},
1340 {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"},
1341 {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"},
1342 {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"},
1343 {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"},
1344 {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"},
1345 {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"},
1346 {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"},
1347 {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"},
1348 {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"},
1349 {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"},
1350 {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"},
1351 {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"},
1352 {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"},
1353 {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"},
1354 {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"},
1355 {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"},
1356 {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"},
1357 {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"},
1358 {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"},
1359 {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"},
1360 {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"},
1361 {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"},
1362 {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"},
1363 {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"},
1364 {OSS_GETVERSION, "OSS_GETVERSION"},
1365 {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"},
1366 {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"},
1367 {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"},
1368 {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"}
1369};
1370#endif
1371
1372static int vrc5477_ac97_ioctl(struct inode *inode, struct file *file,
1373 unsigned int cmd, unsigned long arg)
1374{
1375 struct vrc5477_ac97_state *s = (struct vrc5477_ac97_state *)file->private_data;
1376 unsigned long flags;
1377 audio_buf_info abinfo;
1378 int count;
1379 int val, ret;
1380
1381#ifdef VRC5477_AC97_DEBUG
1382 for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
1383 if (ioctl_str[count].cmd == cmd)
1384 break;
1385 }
1386 if (count < sizeof(ioctl_str)/sizeof(ioctl_str[0]))
1387 printk(KERN_INFO PFX "ioctl %s\n", ioctl_str[count].str);
1388 else
1389 printk(KERN_INFO PFX "ioctl unknown, 0x%x\n", cmd);
1390#endif
1391
1392 switch (cmd) {
1393 case OSS_GETVERSION:
1394 return put_user(SOUND_VERSION, (int *)arg);
1395
1396 case SNDCTL_DSP_SYNC:
1397 if (file->f_mode & FMODE_WRITE)
1398 return drain_dac(s, file->f_flags & O_NONBLOCK);
1399 return 0;
1400
1401 case SNDCTL_DSP_SETDUPLEX:
1402 return 0;
1403
1404 case SNDCTL_DSP_GETCAPS:
1405 return put_user(DSP_CAP_DUPLEX, (int *)arg);
1406
1407 case SNDCTL_DSP_RESET:
1408 if (file->f_mode & FMODE_WRITE) {
1409 stop_dac(s);
1410 synchronize_irq(s->irq);
1411 s->dma_dac.count = 0;
1412 s->dma_dac.nextIn = s->dma_dac.nextOut = 0;
1413 }
1414 if (file->f_mode & FMODE_READ) {
1415 stop_adc(s);
1416 synchronize_irq(s->irq);
1417 s->dma_adc.count = 0;
1418 s->dma_adc.nextIn = s->dma_adc.nextOut = 0;
1419 }
1420 return 0;
1421
1422 case SNDCTL_DSP_SPEED:
1423 if (get_user(val, (int *)arg))
1424 return -EFAULT;
1425 if (val >= 0) {
1426 if (file->f_mode & FMODE_READ) {
1427 stop_adc(s);
1428 set_adc_rate(s, val);
1429 if ((ret = prog_dmabuf_adc(s)))
1430 return ret;
1431 }
1432 if (file->f_mode & FMODE_WRITE) {
1433 stop_dac(s);
1434 set_dac_rate(s, val);
1435 if ((ret = prog_dmabuf_dac(s)))
1436 return ret;
1437 }
1438 }
1439 return put_user((file->f_mode & FMODE_READ) ?
1440 s->adcRate : s->dacRate, (int *)arg);
1441
1442 case SNDCTL_DSP_STEREO:
1443 if (get_user(val, (int *)arg))
1444 return -EFAULT;
1445 if (file->f_mode & FMODE_READ) {
1446 stop_adc(s);
1447 if (val)
1448 s->adcChannels = 2;
1449 else
1450 s->adcChannels = 1;
1451 if ((ret = prog_dmabuf_adc(s)))
1452 return ret;
1453 }
1454 if (file->f_mode & FMODE_WRITE) {
1455 stop_dac(s);
1456 if (val)
1457 s->dacChannels = 2;
1458 else
1459 s->dacChannels = 1;
1460 if ((ret = prog_dmabuf_dac(s)))
1461 return ret;
1462 }
1463 return 0;
1464
1465 case SNDCTL_DSP_CHANNELS:
1466 if (get_user(val, (int *)arg))
1467 return -EFAULT;
1468 if (val != 0) {
1469 if ( (val != 1) && (val != 2)) val = 2;
1470
1471 if (file->f_mode & FMODE_READ) {
1472 stop_adc(s);
1473 s->dacChannels = val;
1474 if ((ret = prog_dmabuf_adc(s)))
1475 return ret;
1476 }
1477 if (file->f_mode & FMODE_WRITE) {
1478 stop_dac(s);
1479 s->dacChannels = val;
1480 if ((ret = prog_dmabuf_dac(s)))
1481 return ret;
1482 }
1483 }
1484 return put_user(val, (int *)arg);
1485
1486 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1487 return put_user(AFMT_S16_LE, (int *)arg);
1488
1489 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1490 if (get_user(val, (int *)arg))
1491 return -EFAULT;
1492 if (val != AFMT_QUERY) {
1493 if (val != AFMT_S16_LE) return -EINVAL;
1494 if (file->f_mode & FMODE_READ) {
1495 stop_adc(s);
1496 if ((ret = prog_dmabuf_adc(s)))
1497 return ret;
1498 }
1499 if (file->f_mode & FMODE_WRITE) {
1500 stop_dac(s);
1501 if ((ret = prog_dmabuf_dac(s)))
1502 return ret;
1503 }
1504 } else {
1505 val = AFMT_S16_LE;
1506 }
1507 return put_user(val, (int *)arg);
1508
1509 case SNDCTL_DSP_POST:
1510 return 0;
1511
1512 case SNDCTL_DSP_GETTRIGGER:
1513 case SNDCTL_DSP_SETTRIGGER:
1514 /* NO trigger */
1515 return -EINVAL;
1516
1517 case SNDCTL_DSP_GETOSPACE:
1518 if (!(file->f_mode & FMODE_WRITE))
1519 return -EINVAL;
1520 abinfo.fragsize = s->dma_dac.fragSize << (s->dacChannels-1);
1521 spin_lock_irqsave(&s->lock, flags);
1522 count = s->dma_dac.count;
1523 spin_unlock_irqrestore(&s->lock, flags);
1524 abinfo.bytes = (s->dma_dac.fragTotalSize - count) <<
1525 (s->dacChannels-1);
1526 abinfo.fragstotal = s->dma_dac.numFrag;
1527 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragShift >>
1528 (s->dacChannels-1);
1529 return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1530
1531 case SNDCTL_DSP_GETISPACE:
1532 if (!(file->f_mode & FMODE_READ))
1533 return -EINVAL;
1534 abinfo.fragsize = s->dma_adc.fragSize << (s->adcChannels-1);
1535 spin_lock_irqsave(&s->lock, flags);
1536 count = s->dma_adc.count;
1537 spin_unlock_irqrestore(&s->lock, flags);
1538 if (count < 0)
1539 count = 0;
1540 abinfo.bytes = count << (s->adcChannels-1);
1541 abinfo.fragstotal = s->dma_adc.numFrag;
1542 abinfo.fragments = (abinfo.bytes >> s->dma_adc.fragShift) >>
1543 (s->adcChannels-1);
1544 return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1545
1546 case SNDCTL_DSP_NONBLOCK:
1547 file->f_flags |= O_NONBLOCK;
1548 return 0;
1549
1550 case SNDCTL_DSP_GETODELAY:
1551 if (!(file->f_mode & FMODE_WRITE))
1552 return -EINVAL;
1553 spin_lock_irqsave(&s->lock, flags);
1554 count = s->dma_dac.count;
1555 spin_unlock_irqrestore(&s->lock, flags);
1556 return put_user(count, (int *)arg);
1557
1558 case SNDCTL_DSP_GETIPTR:
1559 case SNDCTL_DSP_GETOPTR:
1560 /* we cannot get DMA ptr */
1561 return -EINVAL;
1562
1563 case SNDCTL_DSP_GETBLKSIZE:
1564 if (file->f_mode & FMODE_WRITE)
1565 return put_user(s->dma_dac.fragSize << (s->dacChannels-1), (int *)arg);
1566 else
1567 return put_user(s->dma_adc.fragSize << (s->adcChannels-1), (int *)arg);
1568
1569 case SNDCTL_DSP_SETFRAGMENT:
1570 /* we ignore fragment size request */
1571 return 0;
1572
1573 case SNDCTL_DSP_SUBDIVIDE:
1574 /* what is this for? [jsun] */
1575 return 0;
1576
1577 case SOUND_PCM_READ_RATE:
1578 return put_user((file->f_mode & FMODE_READ) ?
1579 s->adcRate : s->dacRate, (int *)arg);
1580
1581 case SOUND_PCM_READ_CHANNELS:
1582 if (file->f_mode & FMODE_READ)
1583 return put_user(s->adcChannels, (int *)arg);
1584 else
1585 return put_user(s->dacChannels ? 2 : 1, (int *)arg);
1586
1587 case SOUND_PCM_READ_BITS:
1588 return put_user(16, (int *)arg);
1589
1590 case SOUND_PCM_WRITE_FILTER:
1591 case SNDCTL_DSP_SETSYNCRO:
1592 case SOUND_PCM_READ_FILTER:
1593 return -EINVAL;
1594 }
1595
1596 return mixdev_ioctl(s->codec, cmd, arg);
1597}
1598
1599
1600static int vrc5477_ac97_open(struct inode *inode, struct file *file)
1601{
1602 int minor = iminor(inode);
1603 DECLARE_WAITQUEUE(wait, current);
1604 unsigned long flags;
1605 struct list_head *list;
1606 struct vrc5477_ac97_state *s;
1607 int ret=0;
1608
1609 nonseekable_open(inode, file);
1610 for (list = devs.next; ; list = list->next) {
1611 if (list == &devs)
1612 return -ENODEV;
1613 s = list_entry(list, struct vrc5477_ac97_state, devs);
1614 if (!((s->dev_audio ^ minor) & ~0xf))
1615 break;
1616 }
1617 file->private_data = s;
1618
1619 /* wait for device to become free */
1620 down(&s->open_sem);
1621 while (s->open_mode & file->f_mode) {
1622
1623 if (file->f_flags & O_NONBLOCK) {
1624 up(&s->open_sem);
1625 return -EBUSY;
1626 }
1627 add_wait_queue(&s->open_wait, &wait);
1628 __set_current_state(TASK_INTERRUPTIBLE);
1629 up(&s->open_sem);
1630 schedule();
1631 remove_wait_queue(&s->open_wait, &wait);
1632 set_current_state(TASK_RUNNING);
1633 if (signal_pending(current))
1634 return -ERESTARTSYS;
1635 down(&s->open_sem);
1636 }
1637
1638 spin_lock_irqsave(&s->lock, flags);
1639
1640 if (file->f_mode & FMODE_READ) {
1641 /* set default settings */
1642 set_adc_rate(s, 48000);
1643 s->adcChannels = 2;
1644
1645 ret = prog_dmabuf_adc(s);
1646 if (ret) goto bailout;
1647 }
1648 if (file->f_mode & FMODE_WRITE) {
1649 /* set default settings */
1650 set_dac_rate(s, 48000);
1651 s->dacChannels = 2;
1652
1653 ret = prog_dmabuf_dac(s);
1654 if (ret) goto bailout;
1655 }
1656
1657 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1658
1659 bailout:
1660 spin_unlock_irqrestore(&s->lock, flags);
1661
1662 up(&s->open_sem);
1663 return ret;
1664}
1665
1666static int vrc5477_ac97_release(struct inode *inode, struct file *file)
1667{
1668 struct vrc5477_ac97_state *s =
1669 (struct vrc5477_ac97_state *)file->private_data;
1670
1671 lock_kernel();
1672 if (file->f_mode & FMODE_WRITE)
1673 drain_dac(s, file->f_flags & O_NONBLOCK);
1674 down(&s->open_sem);
1675 if (file->f_mode & FMODE_WRITE) {
1676 stop_dac(s);
1677 dealloc_dmabuf(s, &s->dma_dac);
1678 }
1679 if (file->f_mode & FMODE_READ) {
1680 stop_adc(s);
1681 dealloc_dmabuf(s, &s->dma_adc);
1682 }
1683 s->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
1684 up(&s->open_sem);
1685 wake_up(&s->open_wait);
1686 unlock_kernel();
1687 return 0;
1688}
1689
1690static /*const*/ struct file_operations vrc5477_ac97_audio_fops = {
1691 .owner = THIS_MODULE,
1692 .llseek = no_llseek,
1693 .read = vrc5477_ac97_read,
1694 .write = vrc5477_ac97_write,
1695 .poll = vrc5477_ac97_poll,
1696 .ioctl = vrc5477_ac97_ioctl,
1697 // .mmap = vrc5477_ac97_mmap,
1698 .open = vrc5477_ac97_open,
1699 .release = vrc5477_ac97_release,
1700};
1701
1702
1703/* --------------------------------------------------------------------- */
1704
1705
1706/* --------------------------------------------------------------------- */
1707
1708/*
1709 * for debugging purposes, we'll create a proc device that dumps the
1710 * CODEC chipstate
1711 */
1712
1713#ifdef VRC5477_AC97_DEBUG
1714
1715struct {
1716 const char *regname;
1717 unsigned regaddr;
1718} vrc5477_ac97_regs[] = {
1719 {"VRC5477_INT_STATUS", VRC5477_INT_STATUS},
1720 {"VRC5477_CODEC_WR", VRC5477_CODEC_WR},
1721 {"VRC5477_CODEC_RD", VRC5477_CODEC_RD},
1722 {"VRC5477_CTRL", VRC5477_CTRL},
1723 {"VRC5477_ACLINK_CTRL", VRC5477_ACLINK_CTRL},
1724 {"VRC5477_INT_MASK", VRC5477_INT_MASK},
1725 {"VRC5477_DAC1_CTRL", VRC5477_DAC1_CTRL},
1726 {"VRC5477_DAC1L", VRC5477_DAC1L},
1727 {"VRC5477_DAC1_BADDR", VRC5477_DAC1_BADDR},
1728 {"VRC5477_DAC2_CTRL", VRC5477_DAC2_CTRL},
1729 {"VRC5477_DAC2L", VRC5477_DAC2L},
1730 {"VRC5477_DAC2_BADDR", VRC5477_DAC2_BADDR},
1731 {"VRC5477_DAC3_CTRL", VRC5477_DAC3_CTRL},
1732 {"VRC5477_DAC3L", VRC5477_DAC3L},
1733 {"VRC5477_DAC3_BADDR", VRC5477_DAC3_BADDR},
1734 {"VRC5477_ADC1_CTRL", VRC5477_ADC1_CTRL},
1735 {"VRC5477_ADC1L", VRC5477_ADC1L},
1736 {"VRC5477_ADC1_BADDR", VRC5477_ADC1_BADDR},
1737 {"VRC5477_ADC2_CTRL", VRC5477_ADC2_CTRL},
1738 {"VRC5477_ADC2L", VRC5477_ADC2L},
1739 {"VRC5477_ADC2_BADDR", VRC5477_ADC2_BADDR},
1740 {"VRC5477_ADC3_CTRL", VRC5477_ADC3_CTRL},
1741 {"VRC5477_ADC3L", VRC5477_ADC3L},
1742 {"VRC5477_ADC3_BADDR", VRC5477_ADC3_BADDR},
1743 {NULL, 0x0}
1744};
1745
1746static int proc_vrc5477_ac97_dump (char *buf, char **start, off_t fpos,
1747 int length, int *eof, void *data)
1748{
1749 struct vrc5477_ac97_state *s;
1750 int cnt, len = 0;
1751
1752 if (list_empty(&devs))
1753 return 0;
1754 s = list_entry(devs.next, struct vrc5477_ac97_state, devs);
1755
1756 /* print out header */
1757 len += sprintf(buf + len, "\n\t\tVrc5477 Audio Debug\n\n");
1758
1759 // print out digital controller state
1760 len += sprintf (buf + len, "NEC Vrc5477 Audio Controller registers\n");
1761 len += sprintf (buf + len, "---------------------------------\n");
1762 for (cnt=0; vrc5477_ac97_regs[cnt].regname != NULL; cnt++) {
1763 len+= sprintf (buf + len, "%-20s = %08x\n",
1764 vrc5477_ac97_regs[cnt].regname,
1765 inl(s->io + vrc5477_ac97_regs[cnt].regaddr));
1766 }
1767
1768 /* print out driver state */
1769 len += sprintf (buf + len, "NEC Vrc5477 Audio driver states\n");
1770 len += sprintf (buf + len, "---------------------------------\n");
1771 len += sprintf (buf + len, "dacChannels = %d\n", s->dacChannels);
1772 len += sprintf (buf + len, "adcChannels = %d\n", s->adcChannels);
1773 len += sprintf (buf + len, "dacRate = %d\n", s->dacRate);
1774 len += sprintf (buf + len, "adcRate = %d\n", s->adcRate);
1775
1776 len += sprintf (buf + len, "dma_dac is %s ready\n",
1777 s->dma_dac.ready? "" : "not");
1778 if (s->dma_dac.ready) {
1779 len += sprintf (buf + len, "dma_dac is %s stopped.\n",
1780 s->dma_dac.stopped? "" : "not");
1781 len += sprintf (buf + len, "dma_dac.fragSize = %x\n",
1782 s->dma_dac.fragSize);
1783 len += sprintf (buf + len, "dma_dac.fragShift = %x\n",
1784 s->dma_dac.fragShift);
1785 len += sprintf (buf + len, "dma_dac.numFrag = %x\n",
1786 s->dma_dac.numFrag);
1787 len += sprintf (buf + len, "dma_dac.fragTotalSize = %x\n",
1788 s->dma_dac.fragTotalSize);
1789 len += sprintf (buf + len, "dma_dac.nextIn = %x\n",
1790 s->dma_dac.nextIn);
1791 len += sprintf (buf + len, "dma_dac.nextOut = %x\n",
1792 s->dma_dac.nextOut);
1793 len += sprintf (buf + len, "dma_dac.count = %x\n",
1794 s->dma_dac.count);
1795 }
1796
1797 len += sprintf (buf + len, "dma_adc is %s ready\n",
1798 s->dma_adc.ready? "" : "not");
1799 if (s->dma_adc.ready) {
1800 len += sprintf (buf + len, "dma_adc is %s stopped.\n",
1801 s->dma_adc.stopped? "" : "not");
1802 len += sprintf (buf + len, "dma_adc.fragSize = %x\n",
1803 s->dma_adc.fragSize);
1804 len += sprintf (buf + len, "dma_adc.fragShift = %x\n",
1805 s->dma_adc.fragShift);
1806 len += sprintf (buf + len, "dma_adc.numFrag = %x\n",
1807 s->dma_adc.numFrag);
1808 len += sprintf (buf + len, "dma_adc.fragTotalSize = %x\n",
1809 s->dma_adc.fragTotalSize);
1810 len += sprintf (buf + len, "dma_adc.nextIn = %x\n",
1811 s->dma_adc.nextIn);
1812 len += sprintf (buf + len, "dma_adc.nextOut = %x\n",
1813 s->dma_adc.nextOut);
1814 len += sprintf (buf + len, "dma_adc.count = %x\n",
1815 s->dma_adc.count);
1816 }
1817
1818 /* print out CODEC state */
1819 len += sprintf (buf + len, "\nAC97 CODEC registers\n");
1820 len += sprintf (buf + len, "----------------------\n");
1821 for (cnt=0; cnt <= 0x7e; cnt = cnt +2)
1822 len+= sprintf (buf + len, "reg %02x = %04x\n",
1823 cnt, rdcodec(s->codec, cnt));
1824
1825 if (fpos >=len){
1826 *start = buf;
1827 *eof =1;
1828 return 0;
1829 }
1830 *start = buf + fpos;
1831 if ((len -= fpos) > length)
1832 return length;
1833 *eof =1;
1834 return len;
1835
1836}
1837#endif /* VRC5477_AC97_DEBUG */
1838
1839/* --------------------------------------------------------------------- */
1840
1841/* maximum number of devices; only used for command line params */
1842#define NR_DEVICE 5
1843
1844static unsigned int devindex;
1845
1846MODULE_AUTHOR("Monta Vista Software, jsun@mvista.com or jsun@junsun.net");
1847MODULE_DESCRIPTION("NEC Vrc5477 audio (AC97) Driver");
1848MODULE_LICENSE("GPL");
1849
1850static int __devinit vrc5477_ac97_probe(struct pci_dev *pcidev,
1851 const struct pci_device_id *pciid)
1852{
1853 struct vrc5477_ac97_state *s;
1854#ifdef VRC5477_AC97_DEBUG
1855 char proc_str[80];
1856#endif
1857
1858 if (pcidev->irq == 0)
1859 return -1;
1860
1861 if (!(s = kmalloc(sizeof(struct vrc5477_ac97_state), GFP_KERNEL))) {
1862 printk(KERN_ERR PFX "alloc of device struct failed\n");
1863 return -1;
1864 }
1865 memset(s, 0, sizeof(struct vrc5477_ac97_state));
1866
1867 init_waitqueue_head(&s->dma_adc.wait);
1868 init_waitqueue_head(&s->dma_dac.wait);
1869 init_waitqueue_head(&s->open_wait);
1870 init_MUTEX(&s->open_sem);
1871 spin_lock_init(&s->lock);
1872
1873 s->dev = pcidev;
1874 s->io = pci_resource_start(pcidev, 0);
1875 s->irq = pcidev->irq;
1876
1877 s->codec = ac97_alloc_codec();
1878
1879 s->codec->private_data = s;
1880 s->codec->id = 0;
1881 s->codec->codec_read = rdcodec;
1882 s->codec->codec_write = wrcodec;
1883 s->codec->codec_wait = waitcodec;
1884
1885 /* setting some other default values such as
1886 * adcChannels, adcRate is done in open() so that
1887 * no persistent state across file opens.
1888 */
1889
1890 /* test if get response from ac97, if not return */
1891 if (ac97_codec_not_present(s->codec)) {
1892 printk(KERN_ERR PFX "no ac97 codec\n");
1893 goto err_region;
1894
1895 }
1896
1897 /* test if get response from ac97, if not return */
1898 if (ac97_codec_not_present(&(s->codec))) {
1899 printk(KERN_ERR PFX "no ac97 codec\n");
1900 goto err_region;
1901
1902 }
1903
1904 if (!request_region(s->io, pci_resource_len(pcidev,0),
1905 VRC5477_AC97_MODULE_NAME)) {
1906 printk(KERN_ERR PFX "io ports %#lx->%#lx in use\n",
1907 s->io, s->io + pci_resource_len(pcidev,0)-1);
1908 goto err_region;
1909 }
1910 if (request_irq(s->irq, vrc5477_ac97_interrupt, SA_INTERRUPT,
1911 VRC5477_AC97_MODULE_NAME, s)) {
1912 printk(KERN_ERR PFX "irq %u in use\n", s->irq);
1913 goto err_irq;
1914 }
1915
1916 printk(KERN_INFO PFX "IO at %#lx, IRQ %d\n", s->io, s->irq);
1917
1918 /* register devices */
1919 if ((s->dev_audio = register_sound_dsp(&vrc5477_ac97_audio_fops, -1)) < 0)
1920 goto err_dev1;
1921 if ((s->codec->dev_mixer =
1922 register_sound_mixer(&vrc5477_ac97_mixer_fops, -1)) < 0)
1923 goto err_dev2;
1924
1925#ifdef VRC5477_AC97_DEBUG
1926 /* initialize the debug proc device */
1927 s->ps = create_proc_read_entry(VRC5477_AC97_MODULE_NAME, 0, NULL,
1928 proc_vrc5477_ac97_dump, NULL);
1929#endif /* VRC5477_AC97_DEBUG */
1930
1931 /* enable pci io and bus mastering */
1932 if (pci_enable_device(pcidev))
1933 goto err_dev3;
1934 pci_set_master(pcidev);
1935
1936 /* cold reset the AC97 */
1937 outl(VRC5477_ACLINK_CTRL_RST_ON | VRC5477_ACLINK_CTRL_RST_TIME,
1938 s->io + VRC5477_ACLINK_CTRL);
1939 while (inl(s->io + VRC5477_ACLINK_CTRL) & VRC5477_ACLINK_CTRL_RST_ON);
1940
1941 /* codec init */
1942 if (!ac97_probe_codec(s->codec))
1943 goto err_dev3;
1944
1945#ifdef VRC5477_AC97_DEBUG
1946 sprintf(proc_str, "driver/%s/%d/ac97",
1947 VRC5477_AC97_MODULE_NAME, s->codec->id);
1948 s->ac97_ps = create_proc_read_entry (proc_str, 0, NULL,
1949 ac97_read_proc, s->codec);
1950 /* TODO : why this proc file does not show up? */
1951#endif
1952
1953 /* Try to enable variable rate audio mode. */
1954 wrcodec(s->codec, AC97_EXTENDED_STATUS,
1955 rdcodec(s->codec, AC97_EXTENDED_STATUS) | AC97_EXTSTAT_VRA);
1956 /* Did we enable it? */
1957 if(rdcodec(s->codec, AC97_EXTENDED_STATUS) & AC97_EXTSTAT_VRA)
1958 s->extended_status |= AC97_EXTSTAT_VRA;
1959 else {
1960 s->dacRate = 48000;
1961 printk(KERN_INFO PFX "VRA mode not enabled; rate fixed at %d.",
1962 s->dacRate);
1963 }
1964
1965 /* let us get the default volumne louder */
1966 wrcodec(s->codec, 0x2, 0x1010); /* master volume, middle */
1967 wrcodec(s->codec, 0xc, 0x10); /* phone volume, middle */
1968 // wrcodec(s->codec, 0xe, 0x10); /* misc volume, middle */
1969 wrcodec(s->codec, 0x10, 0x8000); /* line-in 2 line-out disable */
1970 wrcodec(s->codec, 0x18, 0x0707); /* PCM out (line out) middle */
1971
1972
1973 /* by default we select line in the input */
1974 wrcodec(s->codec, 0x1a, 0x0404);
1975 wrcodec(s->codec, 0x1c, 0x0f0f);
1976 wrcodec(s->codec, 0x1e, 0x07);
1977
1978 /* enable the master interrupt but disable all others */
1979 outl(VRC5477_INT_MASK_NMASK, s->io + VRC5477_INT_MASK);
1980
1981 /* store it in the driver field */
1982 pci_set_drvdata(pcidev, s);
1983 pcidev->dma_mask = 0xffffffff;
1984 /* put it into driver list */
1985 list_add_tail(&s->devs, &devs);
1986 /* increment devindex */
1987 if (devindex < NR_DEVICE-1)
1988 devindex++;
1989 return 0;
1990
1991 err_dev3:
1992 unregister_sound_mixer(s->codec->dev_mixer);
1993 err_dev2:
1994 unregister_sound_dsp(s->dev_audio);
1995 err_dev1:
1996 printk(KERN_ERR PFX "cannot register misc device\n");
1997 free_irq(s->irq, s);
1998 err_irq:
1999 release_region(s->io, pci_resource_len(pcidev,0));
2000 err_region:
2001 ac97_release_codec(codec);
2002 kfree(s);
2003 return -1;
2004}
2005
2006static void __devexit vrc5477_ac97_remove(struct pci_dev *dev)
2007{
2008 struct vrc5477_ac97_state *s = pci_get_drvdata(dev);
2009
2010 if (!s)
2011 return;
2012 list_del(&s->devs);
2013
2014#ifdef VRC5477_AC97_DEBUG
2015 if (s->ps)
2016 remove_proc_entry(VRC5477_AC97_MODULE_NAME, NULL);
2017#endif /* VRC5477_AC97_DEBUG */
2018
2019 synchronize_irq();
2020 free_irq(s->irq, s);
2021 release_region(s->io, pci_resource_len(dev,0));
2022 unregister_sound_dsp(s->dev_audio);
2023 unregister_sound_mixer(s->codec->dev_mixer);
2024 ac97_release_codec(s->codec);
2025 kfree(s);
2026 pci_set_drvdata(dev, NULL);
2027}
2028
2029
2030static struct pci_device_id id_table[] = {
2031 { PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_VRC5477_AC97,
2032 PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
2033 { 0, }
2034};
2035
2036MODULE_DEVICE_TABLE(pci, id_table);
2037
2038static struct pci_driver vrc5477_ac97_driver = {
2039 .name = VRC5477_AC97_MODULE_NAME,
2040 .id_table = id_table,
2041 .probe = vrc5477_ac97_probe,
2042 .remove = __devexit_p(vrc5477_ac97_remove)
2043};
2044
2045static int __init init_vrc5477_ac97(void)
2046{
2047 printk("Vrc5477 AC97 driver: version v0.2 time " __TIME__ " " __DATE__ " by Jun Sun\n");
2048 return pci_module_init(&vrc5477_ac97_driver);
2049}
2050
2051static void __exit cleanup_vrc5477_ac97(void)
2052{
2053 printk(KERN_INFO PFX "unloading\n");
2054 pci_unregister_driver(&vrc5477_ac97_driver);
2055}
2056
2057module_init(init_vrc5477_ac97);
2058module_exit(cleanup_vrc5477_ac97);
2059
diff --git a/sound/oss/nm256.h b/sound/oss/nm256.h
new file mode 100644
index 000000000000..eae7d99d6826
--- /dev/null
+++ b/sound/oss/nm256.h
@@ -0,0 +1,295 @@
1#ifndef _NM256_H_
2#define _NM256_H_
3
4#include <linux/spinlock.h>
5#include <linux/interrupt.h>
6
7#include "ac97.h"
8
9/* The revisions that we currently handle. */
10enum nm256rev {
11 REV_NM256AV, REV_NM256ZX
12};
13
14/* Per-card structure. */
15struct nm256_info
16{
17 /* Magic number used to verify that this struct is valid. */
18#define NM_MAGIC_SIG 0x55aa00ff
19 int magsig;
20
21 /* Revision number */
22 enum nm256rev rev;
23
24 struct ac97_hwint mdev;
25
26 /* Our audio device numbers. */
27 int dev[2];
28
29 /* The # of times each device has been opened. (Should only be
30 0 or 1). */
31 int opencnt[2];
32
33 /* We use two devices, because we can do simultaneous play and record.
34 This keeps track of which device is being used for what purpose;
35 these are the actual device numbers. */
36 int dev_for_play;
37 int dev_for_record;
38
39 spinlock_t lock;
40
41 /* The mixer device. */
42 int mixer_oss_dev;
43
44 /*
45 * Can only be opened once for each operation. These aren't set
46 * until an actual I/O operation is performed; this allows one
47 * device to be open for read/write without inhibiting I/O to
48 * the other device.
49 */
50 int is_open_play;
51 int is_open_record;
52
53 /* Non-zero if we're currently playing a sample. */
54 int playing;
55 /* Ditto for recording a sample. */
56 int recording;
57
58 /* The two memory ports. */
59 struct nm256_ports {
60 /* Physical address of the port. */
61 u32 physaddr;
62 /* Our mapped-in pointer. */
63 char __iomem *ptr;
64 /* PTR's offset within the physical port. */
65 u32 start_offset;
66 /* And the offset of the end of the buffer. */
67 u32 end_offset;
68 } port[2];
69
70 /* The following are offsets within memory port 1. */
71 u32 coeffBuf;
72 u32 allCoeffBuf;
73
74 /* Record and playback buffers. */
75 u32 abuf1, abuf2;
76
77 /* Offset of the AC97 mixer in memory port 2. */
78 u32 mixer;
79
80 /* Offset of the mixer status register in memory port 2. */
81 u32 mixer_status_offset;
82
83 /* Non-zero if we have written initial values to the mixer. */
84 u8 mixer_values_init;
85
86 /*
87 * Status mask bit; (*mixer_status_loc & mixer_status_mask) == 0 means
88 * it's ready.
89 */
90 u16 mixer_status_mask;
91
92 /* The sizes of the playback and record ring buffers. */
93 u32 playbackBufferSize;
94 u32 recordBufferSize;
95
96 /* Are the coefficient values in the memory cache current? */
97 u8 coeffsCurrent;
98
99 /* For writes, the amount we last wrote. */
100 u32 requested_amt;
101 /* The start of the block currently playing. */
102 u32 curPlayPos;
103
104 /* The amount of data we were requested to record. */
105 u32 requestedRecAmt;
106 /* The offset of the currently-recording block. */
107 u32 curRecPos;
108 /* The destination buffer. */
109 char *recBuf;
110
111 /* Our IRQ number. */
112 int irq;
113
114 /* A flag indicating how many times we've grabbed the IRQ. */
115 int has_irq;
116
117 /* The card interrupt service routine. */
118 irqreturn_t (*introutine) (int, void *, struct pt_regs *);
119
120 /* Current audio config, cached. */
121 struct sinfo {
122 u32 samplerate;
123 u8 bits;
124 u8 stereo;
125 } sinfo[2]; /* goes with each device */
126
127 /* The cards are stored in a chain; this is the next card. */
128 struct nm256_info *next_card;
129};
130
131/* Debug flag--bigger numbers mean more output. */
132extern int nm256_debug;
133
134/* The BIOS signature. */
135#define NM_SIGNATURE 0x4e4d0000
136/* Signature mask. */
137#define NM_SIG_MASK 0xffff0000
138
139/* Size of the second memory area. */
140#define NM_PORT2_SIZE 4096
141
142/* The base offset of the mixer in the second memory area. */
143#define NM_MIXER_OFFSET 0x600
144
145/* The maximum size of a coefficient entry. */
146#define NM_MAX_COEFFICIENT 0x5000
147
148/* The interrupt register. */
149#define NM_INT_REG 0xa04
150/* And its bits. */
151#define NM_PLAYBACK_INT 0x40
152#define NM_RECORD_INT 0x100
153#define NM_MISC_INT_1 0x4000
154#define NM_MISC_INT_2 0x1
155#define NM_ACK_INT(CARD, X) nm256_writePort16((CARD), 2, NM_INT_REG, (X) << 1)
156
157/* The AV's "mixer ready" status bit and location. */
158#define NM_MIXER_STATUS_OFFSET 0xa04
159#define NM_MIXER_READY_MASK 0x0800
160#define NM_MIXER_PRESENCE 0xa06
161#define NM_PRESENCE_MASK 0x0050
162#define NM_PRESENCE_VALUE 0x0040
163
164/*
165 * For the ZX. It uses the same interrupt register, but it holds 32
166 * bits instead of 16.
167 */
168#define NM2_PLAYBACK_INT 0x10000
169#define NM2_RECORD_INT 0x80000
170#define NM2_MISC_INT_1 0x8
171#define NM2_MISC_INT_2 0x2
172#define NM2_ACK_INT(CARD, X) nm256_writePort32((CARD), 2, NM_INT_REG, (X))
173
174/* The ZX's "mixer ready" status bit and location. */
175#define NM2_MIXER_STATUS_OFFSET 0xa06
176#define NM2_MIXER_READY_MASK 0x0800
177
178/* The playback registers start from here. */
179#define NM_PLAYBACK_REG_OFFSET 0x0
180/* The record registers start from here. */
181#define NM_RECORD_REG_OFFSET 0x200
182
183/* The rate register is located 2 bytes from the start of the register area. */
184#define NM_RATE_REG_OFFSET 2
185
186/* Mono/stereo flag, number of bits on playback, and rate mask. */
187#define NM_RATE_STEREO 1
188#define NM_RATE_BITS_16 2
189#define NM_RATE_MASK 0xf0
190
191/* Playback enable register. */
192#define NM_PLAYBACK_ENABLE_REG (NM_PLAYBACK_REG_OFFSET + 0x1)
193#define NM_PLAYBACK_ENABLE_FLAG 1
194#define NM_PLAYBACK_ONESHOT 2
195#define NM_PLAYBACK_FREERUN 4
196
197/* Mutes the audio output. */
198#define NM_AUDIO_MUTE_REG (NM_PLAYBACK_REG_OFFSET + 0x18)
199#define NM_AUDIO_MUTE_LEFT 0x8000
200#define NM_AUDIO_MUTE_RIGHT 0x0080
201
202/* Recording enable register. */
203#define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0)
204#define NM_RECORD_ENABLE_FLAG 1
205#define NM_RECORD_FREERUN 2
206
207#define NM_RBUFFER_START (NM_RECORD_REG_OFFSET + 0x4)
208#define NM_RBUFFER_END (NM_RECORD_REG_OFFSET + 0x10)
209#define NM_RBUFFER_WMARK (NM_RECORD_REG_OFFSET + 0xc)
210#define NM_RBUFFER_CURRP (NM_RECORD_REG_OFFSET + 0x8)
211
212#define NM_PBUFFER_START (NM_PLAYBACK_REG_OFFSET + 0x4)
213#define NM_PBUFFER_END (NM_PLAYBACK_REG_OFFSET + 0x14)
214#define NM_PBUFFER_WMARK (NM_PLAYBACK_REG_OFFSET + 0xc)
215#define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8)
216
217/* A few trivial routines to make it easier to work with the registers
218 on the chip. */
219
220/* This is a common code portion used to fix up the port offsets. */
221#define NM_FIX_PORT \
222 if (port < 1 || port > 2 || card == NULL) \
223 return -1; \
224\
225 if (offset < card->port[port - 1].start_offset \
226 || offset >= card->port[port - 1].end_offset) { \
227 printk (KERN_ERR "Bad access: port %d, offset 0x%x\n", port, offset); \
228 return -1; \
229 } \
230 offset -= card->port[port - 1].start_offset;
231
232#define DEFwritePortX(X, func) \
233static inline int nm256_writePort##X (struct nm256_info *card,\
234 int port, int offset, int value)\
235{\
236 u##X __iomem *addr;\
237\
238 if (nm256_debug > 1)\
239 printk (KERN_DEBUG "Writing 0x%x to %d:0x%x\n", value, port, offset);\
240\
241 NM_FIX_PORT;\
242\
243 addr = (u##X __iomem *)(card->port[port - 1].ptr + offset);\
244 func (value, addr);\
245 return 0;\
246}
247
248DEFwritePortX (8, writeb)
249DEFwritePortX (16, writew)
250DEFwritePortX (32, writel)
251
252#define DEFreadPortX(X, func) \
253static inline u##X nm256_readPort##X (struct nm256_info *card,\
254 int port, int offset)\
255{\
256 u##X __iomem *addr;\
257\
258 NM_FIX_PORT\
259\
260 addr = (u##X __iomem *)(card->port[port - 1].ptr + offset);\
261 return func(addr);\
262}
263
264DEFreadPortX (8, readb)
265DEFreadPortX (16, readw)
266DEFreadPortX (32, readl)
267
268static inline int
269nm256_writeBuffer8 (struct nm256_info *card, u8 *src, int port, int offset,
270 int amt)
271{
272 NM_FIX_PORT;
273 memcpy_toio (card->port[port - 1].ptr + offset, src, amt);
274 return 0;
275}
276
277static inline int
278nm256_readBuffer8 (struct nm256_info *card, u8 *dst, int port, int offset,
279 int amt)
280{
281 NM_FIX_PORT;
282 memcpy_fromio (dst, card->port[port - 1].ptr + offset, amt);
283 return 0;
284}
285
286/* Returns a non-zero value if we should use the coefficient cache. */
287extern int nm256_cachedCoefficients (struct nm256_info *card);
288
289#endif
290
291/*
292 * Local variables:
293 * c-basic-offset: 4
294 * End:
295 */
diff --git a/sound/oss/nm256_audio.c b/sound/oss/nm256_audio.c
new file mode 100644
index 000000000000..f9166e135192
--- /dev/null
+++ b/sound/oss/nm256_audio.c
@@ -0,0 +1,1707 @@
1/*
2 * Audio driver for the NeoMagic 256AV and 256ZX chipsets in native
3 * mode, with AC97 mixer support.
4 *
5 * Overall design and parts of this code stolen from vidc_*.c and
6 * skeleton.c.
7 *
8 * Yeah, there are a lot of magic constants in here. You tell ME what
9 * they are. I just get this stuff psychically, remember?
10 *
11 * This driver was written by someone who wishes to remain anonymous.
12 * It is in the public domain, so share and enjoy. Try to make a profit
13 * off of it; go on, I dare you.
14 *
15 * Changes:
16 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
17 * Added some __init
18 * 19-04-2001 Marcus Meissner <mm@caldera.de>
19 * Ported to 2.4 PCI API.
20 */
21
22#include <linux/pci.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/pm.h>
28#include <linux/delay.h>
29#include <linux/spinlock.h>
30#include "sound_config.h"
31#include "nm256.h"
32#include "nm256_coeff.h"
33
34int nm256_debug;
35static int force_load;
36
37/*
38 * The size of the playback reserve. When the playback buffer has less
39 * than NM256_PLAY_WMARK_SIZE bytes to output, we request a new
40 * buffer.
41 */
42#define NM256_PLAY_WMARK_SIZE 512
43
44static struct audio_driver nm256_audio_driver;
45
46static int nm256_grabInterrupt (struct nm256_info *card);
47static int nm256_releaseInterrupt (struct nm256_info *card);
48static irqreturn_t nm256_interrupt (int irq, void *dev_id, struct pt_regs *dummy);
49static irqreturn_t nm256_interrupt_zx (int irq, void *dev_id, struct pt_regs *dummy);
50static int handle_pm_event (struct pm_dev *dev, pm_request_t rqst, void *data);
51
52/* These belong in linux/pci.h. */
53#define PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO 0x8005
54#define PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO 0x8006
55#define PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO 0x8016
56
57/* List of cards. */
58static struct nm256_info *nmcard_list;
59
60/* Release the mapped-in memory for CARD. */
61static void
62nm256_release_ports (struct nm256_info *card)
63{
64 int x;
65
66 for (x = 0; x < 2; x++) {
67 if (card->port[x].ptr != NULL) {
68 iounmap (card->port[x].ptr);
69 card->port[x].ptr = NULL;
70 }
71 }
72}
73
74/*
75 * Map in the memory ports for CARD, if they aren't already mapped in
76 * and have been configured. If successful, a zero value is returned;
77 * otherwise any previously mapped-in areas are released and a non-zero
78 * value is returned.
79 *
80 * This is invoked twice, once for each port. Ideally it would only be
81 * called once, but we now need to map in the second port in order to
82 * check how much memory the card has on the 256ZX.
83 */
84static int
85nm256_remap_ports (struct nm256_info *card)
86{
87 int x;
88
89 for (x = 0; x < 2; x++) {
90 if (card->port[x].ptr == NULL && card->port[x].end_offset > 0) {
91 u32 physaddr
92 = card->port[x].physaddr + card->port[x].start_offset;
93 u32 size
94 = card->port[x].end_offset - card->port[x].start_offset;
95
96 card->port[x].ptr = ioremap_nocache (physaddr, size);
97
98 if (card->port[x].ptr == NULL) {
99 printk (KERN_ERR "NM256: Unable to remap port %d\n", x + 1);
100 nm256_release_ports (card);
101 return -1;
102 }
103 }
104 }
105 return 0;
106}
107
108/* Locate the card in our list. */
109static struct nm256_info *
110nm256_find_card (int dev)
111{
112 struct nm256_info *card;
113
114 for (card = nmcard_list; card != NULL; card = card->next_card)
115 if (card->dev[0] == dev || card->dev[1] == dev)
116 return card;
117
118 return NULL;
119}
120
121/*
122 * Ditto, but find the card struct corresponding to the mixer device DEV
123 * instead.
124 */
125static struct nm256_info *
126nm256_find_card_for_mixer (int dev)
127{
128 struct nm256_info *card;
129
130 for (card = nmcard_list; card != NULL; card = card->next_card)
131 if (card->mixer_oss_dev == dev)
132 return card;
133
134 return NULL;
135}
136
137static int usecache;
138static int buffertop;
139
140/* Check to see if we're using the bank of cached coefficients. */
141int
142nm256_cachedCoefficients (struct nm256_info *card)
143{
144 return usecache;
145}
146
147/* The actual rates supported by the card. */
148static int samplerates[9] = {
149 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, 99999999
150};
151
152/*
153 * Set the card samplerate, word size and stereo mode to correspond to
154 * the settings in the CARD struct for the specified device in DEV.
155 * We keep two separate sets of information, one for each device; the
156 * hardware is not actually configured until a read or write is
157 * attempted.
158 */
159
160static int
161nm256_setInfo (int dev, struct nm256_info *card)
162{
163 int x;
164 int w;
165 int targetrate;
166
167 if (card->dev[0] == dev)
168 w = 0;
169 else if (card->dev[1] == dev)
170 w = 1;
171 else
172 return -ENODEV;
173
174 targetrate = card->sinfo[w].samplerate;
175
176 if ((card->sinfo[w].bits != 8 && card->sinfo[w].bits != 16)
177 || targetrate < samplerates[0]
178 || targetrate > samplerates[7])
179 return -EINVAL;
180
181 for (x = 0; x < 8; x++)
182 if (targetrate < ((samplerates[x] + samplerates[x + 1]) / 2))
183 break;
184
185 if (x < 8) {
186 u8 ratebits = ((x << 4) & NM_RATE_MASK);
187 if (card->sinfo[w].bits == 16)
188 ratebits |= NM_RATE_BITS_16;
189 if (card->sinfo[w].stereo)
190 ratebits |= NM_RATE_STEREO;
191
192 card->sinfo[w].samplerate = samplerates[x];
193
194
195 if (card->dev_for_play == dev && card->playing) {
196 if (nm256_debug)
197 printk (KERN_DEBUG "Setting play ratebits to 0x%x\n",
198 ratebits);
199 nm256_loadCoefficient (card, 0, x);
200 nm256_writePort8 (card, 2,
201 NM_PLAYBACK_REG_OFFSET + NM_RATE_REG_OFFSET,
202 ratebits);
203 }
204
205 if (card->dev_for_record == dev && card->recording) {
206 if (nm256_debug)
207 printk (KERN_DEBUG "Setting record ratebits to 0x%x\n",
208 ratebits);
209 nm256_loadCoefficient (card, 1, x);
210 nm256_writePort8 (card, 2,
211 NM_RECORD_REG_OFFSET + NM_RATE_REG_OFFSET,
212 ratebits);
213 }
214 return 0;
215 }
216 else
217 return -EINVAL;
218}
219
220/* Start the play process going. */
221static void
222startPlay (struct nm256_info *card)
223{
224 if (! card->playing) {
225 card->playing = 1;
226 if (nm256_grabInterrupt (card) == 0) {
227 nm256_setInfo (card->dev_for_play, card);
228
229 /* Enable playback engine and interrupts. */
230 nm256_writePort8 (card, 2, NM_PLAYBACK_ENABLE_REG,
231 NM_PLAYBACK_ENABLE_FLAG | NM_PLAYBACK_FREERUN);
232
233 /* Enable both channels. */
234 nm256_writePort16 (card, 2, NM_AUDIO_MUTE_REG, 0x0);
235 }
236 }
237}
238
239/*
240 * Request one chunk of AMT bytes from the recording device. When the
241 * operation is complete, the data will be copied into BUFFER and the
242 * function DMAbuf_inputintr will be invoked.
243 */
244
245static void
246nm256_startRecording (struct nm256_info *card, char *buffer, u32 amt)
247{
248 u32 endpos;
249 int enableEngine = 0;
250 u32 ringsize = card->recordBufferSize;
251 unsigned long flags;
252
253 if (amt > (ringsize / 2)) {
254 /*
255 * Of course this won't actually work right, because the
256 * caller is going to assume we will give what we got asked
257 * for.
258 */
259 printk (KERN_ERR "NM256: Read request too large: %d\n", amt);
260 amt = ringsize / 2;
261 }
262
263 if (amt < 8) {
264 printk (KERN_ERR "NM256: Read request too small; %d\n", amt);
265 return;
266 }
267
268 spin_lock_irqsave(&card->lock,flags);
269 /*
270 * If we're not currently recording, set up the start and end registers
271 * for the recording engine.
272 */
273 if (! card->recording) {
274 card->recording = 1;
275 if (nm256_grabInterrupt (card) == 0) {
276 card->curRecPos = 0;
277 nm256_setInfo (card->dev_for_record, card);
278 nm256_writePort32 (card, 2, NM_RBUFFER_START, card->abuf2);
279 nm256_writePort32 (card, 2, NM_RBUFFER_END,
280 card->abuf2 + ringsize);
281
282 nm256_writePort32 (card, 2, NM_RBUFFER_CURRP,
283 card->abuf2 + card->curRecPos);
284 enableEngine = 1;
285 }
286 else {
287 /* Not sure what else to do here. */
288 spin_unlock_irqrestore(&card->lock,flags);
289 return;
290 }
291 }
292
293 /*
294 * If we happen to go past the end of the buffer a bit (due to a
295 * delayed interrupt) it's OK. So might as well set the watermark
296 * right at the end of the data we want.
297 */
298 endpos = card->abuf2 + ((card->curRecPos + amt) % ringsize);
299
300 card->recBuf = buffer;
301 card->requestedRecAmt = amt;
302 nm256_writePort32 (card, 2, NM_RBUFFER_WMARK, endpos);
303 /* Enable recording engine and interrupts. */
304 if (enableEngine)
305 nm256_writePort8 (card, 2, NM_RECORD_ENABLE_REG,
306 NM_RECORD_ENABLE_FLAG | NM_RECORD_FREERUN);
307
308 spin_unlock_irqrestore(&card->lock,flags);
309}
310
311/* Stop the play engine. */
312static void
313stopPlay (struct nm256_info *card)
314{
315 /* Shut off sound from both channels. */
316 nm256_writePort16 (card, 2, NM_AUDIO_MUTE_REG,
317 NM_AUDIO_MUTE_LEFT | NM_AUDIO_MUTE_RIGHT);
318 /* Disable play engine. */
319 nm256_writePort8 (card, 2, NM_PLAYBACK_ENABLE_REG, 0);
320 if (card->playing) {
321 nm256_releaseInterrupt (card);
322
323 /* Reset the relevant state bits. */
324 card->playing = 0;
325 card->curPlayPos = 0;
326 }
327}
328
329/* Stop recording. */
330static void
331stopRecord (struct nm256_info *card)
332{
333 /* Disable recording engine. */
334 nm256_writePort8 (card, 2, NM_RECORD_ENABLE_REG, 0);
335
336 if (card->recording) {
337 nm256_releaseInterrupt (card);
338
339 card->recording = 0;
340 card->curRecPos = 0;
341 }
342}
343
344/*
345 * Ring buffers, man. That's where the hip-hop, wild-n-wooly action's at.
346 * 1972? (Well, I suppose it was cheep-n-easy to implement.)
347 *
348 * Write AMT bytes of BUFFER to the playback ring buffer, and start the
349 * playback engine running. It will only accept up to 1/2 of the total
350 * size of the ring buffer. No check is made that we're about to overwrite
351 * the currently-playing sample.
352 */
353
354static void
355nm256_write_block (struct nm256_info *card, char *buffer, u32 amt)
356{
357 u32 ringsize = card->playbackBufferSize;
358 u32 endstop;
359 unsigned long flags;
360
361 if (amt > (ringsize / 2)) {
362 printk (KERN_ERR "NM256: Write request too large: %d\n", amt);
363 amt = (ringsize / 2);
364 }
365
366 if (amt < NM256_PLAY_WMARK_SIZE) {
367 printk (KERN_ERR "NM256: Write request too small: %d\n", amt);
368 return;
369 }
370
371 card->curPlayPos %= ringsize;
372
373 card->requested_amt = amt;
374
375 spin_lock_irqsave(&card->lock,flags);
376
377 if ((card->curPlayPos + amt) >= ringsize) {
378 u32 rem = ringsize - card->curPlayPos;
379
380 nm256_writeBuffer8 (card, buffer, 1,
381 card->abuf1 + card->curPlayPos,
382 rem);
383 if (amt > rem)
384 nm256_writeBuffer8 (card, buffer + rem, 1, card->abuf1,
385 amt - rem);
386 }
387 else
388 nm256_writeBuffer8 (card, buffer, 1,
389 card->abuf1 + card->curPlayPos,
390 amt);
391
392 /*
393 * Setup the start-n-stop-n-limit registers, and start that engine
394 * goin'.
395 *
396 * Normally we just let it wrap around to avoid the click-click
397 * action scene.
398 */
399 if (! card->playing) {
400 /* The PBUFFER_END register in this case points to one sample
401 before the end of the buffer. */
402 int w = (card->dev_for_play == card->dev[0] ? 0 : 1);
403 int sampsize = (card->sinfo[w].bits == 16 ? 2 : 1);
404
405 if (card->sinfo[w].stereo)
406 sampsize *= 2;
407
408 /* Need to set the not-normally-changing-registers up. */
409 nm256_writePort32 (card, 2, NM_PBUFFER_START,
410 card->abuf1 + card->curPlayPos);
411 nm256_writePort32 (card, 2, NM_PBUFFER_END,
412 card->abuf1 + ringsize - sampsize);
413 nm256_writePort32 (card, 2, NM_PBUFFER_CURRP,
414 card->abuf1 + card->curPlayPos);
415 }
416 endstop = (card->curPlayPos + amt - NM256_PLAY_WMARK_SIZE) % ringsize;
417 nm256_writePort32 (card, 2, NM_PBUFFER_WMARK, card->abuf1 + endstop);
418
419 if (! card->playing)
420 startPlay (card);
421
422 spin_unlock_irqrestore(&card->lock,flags);
423}
424
425/* We just got a card playback interrupt; process it. */
426static void
427nm256_get_new_block (struct nm256_info *card)
428{
429 /* Check to see how much got played so far. */
430 u32 amt = nm256_readPort32 (card, 2, NM_PBUFFER_CURRP) - card->abuf1;
431
432 if (amt >= card->playbackBufferSize) {
433 printk (KERN_ERR "NM256: Sound playback pointer invalid!\n");
434 amt = 0;
435 }
436
437 if (amt < card->curPlayPos)
438 amt = (card->playbackBufferSize - card->curPlayPos) + amt;
439 else
440 amt -= card->curPlayPos;
441
442 if (card->requested_amt > (amt + NM256_PLAY_WMARK_SIZE)) {
443 u32 endstop =
444 card->curPlayPos + card->requested_amt - NM256_PLAY_WMARK_SIZE;
445 nm256_writePort32 (card, 2, NM_PBUFFER_WMARK, card->abuf1 + endstop);
446 }
447 else {
448 card->curPlayPos += card->requested_amt;
449 /* Get a new block to write. This will eventually invoke
450 nm256_write_block () or stopPlay (). */
451 DMAbuf_outputintr (card->dev_for_play, 1);
452 }
453}
454
455/*
456 * Read the last-recorded block from the ring buffer, copy it into the
457 * saved buffer pointer, and invoke DMAuf_inputintr() with the recording
458 * device.
459 */
460
461static void
462nm256_read_block (struct nm256_info *card)
463{
464 /* Grab the current position of the recording pointer. */
465 u32 currptr = nm256_readPort32 (card, 2, NM_RBUFFER_CURRP) - card->abuf2;
466 u32 amtToRead = card->requestedRecAmt;
467 u32 ringsize = card->recordBufferSize;
468
469 if (currptr >= card->recordBufferSize) {
470 printk (KERN_ERR "NM256: Sound buffer record pointer invalid!\n");
471 currptr = 0;
472 }
473
474 /*
475 * This test is probably redundant; we shouldn't be here unless
476 * it's true.
477 */
478 if (card->recording) {
479 /* If we wrapped around, copy everything from the start of our
480 recording buffer to the end of the buffer. */
481 if (currptr < card->curRecPos) {
482 u32 amt = min (ringsize - card->curRecPos, amtToRead);
483
484 nm256_readBuffer8 (card, card->recBuf, 1,
485 card->abuf2 + card->curRecPos,
486 amt);
487 amtToRead -= amt;
488 card->curRecPos += amt;
489 card->recBuf += amt;
490 if (card->curRecPos == ringsize)
491 card->curRecPos = 0;
492 }
493
494 if ((card->curRecPos < currptr) && (amtToRead > 0)) {
495 u32 amt = min (currptr - card->curRecPos, amtToRead);
496 nm256_readBuffer8 (card, card->recBuf, 1,
497 card->abuf2 + card->curRecPos, amt);
498 card->curRecPos = ((card->curRecPos + amt) % ringsize);
499 }
500 card->recBuf = NULL;
501 card->requestedRecAmt = 0;
502 DMAbuf_inputintr (card->dev_for_record);
503 }
504}
505
506/*
507 * Initialize the hardware.
508 */
509static void
510nm256_initHw (struct nm256_info *card)
511{
512 /* Reset everything. */
513 nm256_writePort8 (card, 2, 0x0, 0x11);
514 nm256_writePort16 (card, 2, 0x214, 0);
515
516 stopRecord (card);
517 stopPlay (card);
518}
519
520/*
521 * Handle a potential interrupt for the device referred to by DEV_ID.
522 *
523 * I don't like the cut-n-paste job here either between the two routines,
524 * but there are sufficient differences between the two interrupt handlers
525 * that parameterizing it isn't all that great either. (Could use a macro,
526 * I suppose...yucky bleah.)
527 */
528
529static irqreturn_t
530nm256_interrupt (int irq, void *dev_id, struct pt_regs *dummy)
531{
532 struct nm256_info *card = (struct nm256_info *)dev_id;
533 u16 status;
534 static int badintrcount;
535 int handled = 0;
536
537 if ((card == NULL) || (card->magsig != NM_MAGIC_SIG)) {
538 printk (KERN_ERR "NM256: Bad card pointer\n");
539 return IRQ_NONE;
540 }
541
542 status = nm256_readPort16 (card, 2, NM_INT_REG);
543
544 /* Not ours. */
545 if (status == 0) {
546 if (badintrcount++ > 1000) {
547 /*
548 * I'm not sure if the best thing is to stop the card from
549 * playing or just release the interrupt (after all, we're in
550 * a bad situation, so doing fancy stuff may not be such a good
551 * idea).
552 *
553 * I worry about the card engine continuing to play noise
554 * over and over, however--that could become a very
555 * obnoxious problem. And we know that when this usually
556 * happens things are fairly safe, it just means the user's
557 * inserted a PCMCIA card and someone's spamming us with IRQ 9s.
558 */
559
560 handled = 1;
561 if (card->playing)
562 stopPlay (card);
563 if (card->recording)
564 stopRecord (card);
565 badintrcount = 0;
566 }
567 return IRQ_RETVAL(handled);
568 }
569
570 badintrcount = 0;
571
572 /* Rather boring; check for individual interrupts and process them. */
573
574 if (status & NM_PLAYBACK_INT) {
575 handled = 1;
576 status &= ~NM_PLAYBACK_INT;
577 NM_ACK_INT (card, NM_PLAYBACK_INT);
578
579 if (card->playing)
580 nm256_get_new_block (card);
581 }
582
583 if (status & NM_RECORD_INT) {
584 handled = 1;
585 status &= ~NM_RECORD_INT;
586 NM_ACK_INT (card, NM_RECORD_INT);
587
588 if (card->recording)
589 nm256_read_block (card);
590 }
591
592 if (status & NM_MISC_INT_1) {
593 u8 cbyte;
594
595 handled = 1;
596 status &= ~NM_MISC_INT_1;
597 printk (KERN_ERR "NM256: Got misc interrupt #1\n");
598 NM_ACK_INT (card, NM_MISC_INT_1);
599 nm256_writePort16 (card, 2, NM_INT_REG, 0x8000);
600 cbyte = nm256_readPort8 (card, 2, 0x400);
601 nm256_writePort8 (card, 2, 0x400, cbyte | 2);
602 }
603
604 if (status & NM_MISC_INT_2) {
605 u8 cbyte;
606
607 handled = 1;
608 status &= ~NM_MISC_INT_2;
609 printk (KERN_ERR "NM256: Got misc interrupt #2\n");
610 NM_ACK_INT (card, NM_MISC_INT_2);
611 cbyte = nm256_readPort8 (card, 2, 0x400);
612 nm256_writePort8 (card, 2, 0x400, cbyte & ~2);
613 }
614
615 /* Unknown interrupt. */
616 if (status) {
617 handled = 1;
618 printk (KERN_ERR "NM256: Fire in the hole! Unknown status 0x%x\n",
619 status);
620 /* Pray. */
621 NM_ACK_INT (card, status);
622 }
623 return IRQ_RETVAL(handled);
624}
625
626/*
627 * Handle a potential interrupt for the device referred to by DEV_ID.
628 * This handler is for the 256ZX, and is very similar to the non-ZX
629 * routine.
630 */
631
632static irqreturn_t
633nm256_interrupt_zx (int irq, void *dev_id, struct pt_regs *dummy)
634{
635 struct nm256_info *card = (struct nm256_info *)dev_id;
636 u32 status;
637 static int badintrcount;
638 int handled = 0;
639
640 if ((card == NULL) || (card->magsig != NM_MAGIC_SIG)) {
641 printk (KERN_ERR "NM256: Bad card pointer\n");
642 return IRQ_NONE;
643 }
644
645 status = nm256_readPort32 (card, 2, NM_INT_REG);
646
647 /* Not ours. */
648 if (status == 0) {
649 if (badintrcount++ > 1000) {
650 printk (KERN_ERR "NM256: Releasing interrupt, over 1000 invalid interrupts\n");
651 /*
652 * I'm not sure if the best thing is to stop the card from
653 * playing or just release the interrupt (after all, we're in
654 * a bad situation, so doing fancy stuff may not be such a good
655 * idea).
656 *
657 * I worry about the card engine continuing to play noise
658 * over and over, however--that could become a very
659 * obnoxious problem. And we know that when this usually
660 * happens things are fairly safe, it just means the user's
661 * inserted a PCMCIA card and someone's spamming us with
662 * IRQ 9s.
663 */
664
665 handled = 1;
666 if (card->playing)
667 stopPlay (card);
668 if (card->recording)
669 stopRecord (card);
670 badintrcount = 0;
671 }
672 return IRQ_RETVAL(handled);
673 }
674
675 badintrcount = 0;
676
677 /* Rather boring; check for individual interrupts and process them. */
678
679 if (status & NM2_PLAYBACK_INT) {
680 handled = 1;
681 status &= ~NM2_PLAYBACK_INT;
682 NM2_ACK_INT (card, NM2_PLAYBACK_INT);
683
684 if (card->playing)
685 nm256_get_new_block (card);
686 }
687
688 if (status & NM2_RECORD_INT) {
689 handled = 1;
690 status &= ~NM2_RECORD_INT;
691 NM2_ACK_INT (card, NM2_RECORD_INT);
692
693 if (card->recording)
694 nm256_read_block (card);
695 }
696
697 if (status & NM2_MISC_INT_1) {
698 u8 cbyte;
699
700 handled = 1;
701 status &= ~NM2_MISC_INT_1;
702 printk (KERN_ERR "NM256: Got misc interrupt #1\n");
703 NM2_ACK_INT (card, NM2_MISC_INT_1);
704 cbyte = nm256_readPort8 (card, 2, 0x400);
705 nm256_writePort8 (card, 2, 0x400, cbyte | 2);
706 }
707
708 if (status & NM2_MISC_INT_2) {
709 u8 cbyte;
710
711 handled = 1;
712 status &= ~NM2_MISC_INT_2;
713 printk (KERN_ERR "NM256: Got misc interrupt #2\n");
714 NM2_ACK_INT (card, NM2_MISC_INT_2);
715 cbyte = nm256_readPort8 (card, 2, 0x400);
716 nm256_writePort8 (card, 2, 0x400, cbyte & ~2);
717 }
718
719 /* Unknown interrupt. */
720 if (status) {
721 handled = 1;
722 printk (KERN_ERR "NM256: Fire in the hole! Unknown status 0x%x\n",
723 status);
724 /* Pray. */
725 NM2_ACK_INT (card, status);
726 }
727 return IRQ_RETVAL(handled);
728}
729
730/*
731 * Request our interrupt.
732 */
733static int
734nm256_grabInterrupt (struct nm256_info *card)
735{
736 if (card->has_irq++ == 0) {
737 if (request_irq (card->irq, card->introutine, SA_SHIRQ,
738 "NM256_audio", card) < 0) {
739 printk (KERN_ERR "NM256: can't obtain IRQ %d\n", card->irq);
740 return -1;
741 }
742 }
743 return 0;
744}
745
746/*
747 * Release our interrupt.
748 */
749static int
750nm256_releaseInterrupt (struct nm256_info *card)
751{
752 if (card->has_irq <= 0) {
753 printk (KERN_ERR "nm256: too many calls to releaseInterrupt\n");
754 return -1;
755 }
756 card->has_irq--;
757 if (card->has_irq == 0) {
758 free_irq (card->irq, card);
759 }
760 return 0;
761}
762
763/*
764 * Waits for the mixer to become ready to be written; returns a zero value
765 * if it timed out.
766 */
767
768static int
769nm256_isReady (struct ac97_hwint *dev)
770{
771 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
772 int t2 = 10;
773 u32 testaddr;
774 u16 testb;
775 int done = 0;
776
777 if (card->magsig != NM_MAGIC_SIG) {
778 printk (KERN_ERR "NM256: Bad magic signature in isReady!\n");
779 return 0;
780 }
781
782 testaddr = card->mixer_status_offset;
783 testb = card->mixer_status_mask;
784
785 /*
786 * Loop around waiting for the mixer to become ready.
787 */
788 while (! done && t2-- > 0) {
789 if ((nm256_readPort16 (card, 2, testaddr) & testb) == 0)
790 done = 1;
791 else
792 udelay (100);
793 }
794 return done;
795}
796
797/*
798 * Return the contents of the AC97 mixer register REG. Returns a positive
799 * value if successful, or a negative error code.
800 */
801static int
802nm256_readAC97Reg (struct ac97_hwint *dev, u8 reg)
803{
804 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
805
806 if (card->magsig != NM_MAGIC_SIG) {
807 printk (KERN_ERR "NM256: Bad magic signature in readAC97Reg!\n");
808 return -EINVAL;
809 }
810
811 if (reg < 128) {
812 int res;
813
814 nm256_isReady (dev);
815 res = nm256_readPort16 (card, 2, card->mixer + reg);
816 /* Magic delay. Bleah yucky. */
817 udelay (1000);
818 return res;
819 }
820 else
821 return -EINVAL;
822}
823
824/*
825 * Writes VALUE to AC97 mixer register REG. Returns 0 if successful, or
826 * a negative error code.
827 */
828static int
829nm256_writeAC97Reg (struct ac97_hwint *dev, u8 reg, u16 value)
830{
831 unsigned long flags;
832 int tries = 2;
833 int done = 0;
834 u32 base;
835
836 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
837
838 if (card->magsig != NM_MAGIC_SIG) {
839 printk (KERN_ERR "NM256: Bad magic signature in writeAC97Reg!\n");
840 return -EINVAL;
841 }
842
843 base = card->mixer;
844
845 spin_lock_irqsave(&card->lock,flags);
846
847 nm256_isReady (dev);
848
849 /* Wait for the write to take, too. */
850 while ((tries-- > 0) && !done) {
851 nm256_writePort16 (card, 2, base + reg, value);
852 if (nm256_isReady (dev)) {
853 done = 1;
854 break;
855 }
856
857 }
858
859 spin_unlock_irqrestore(&card->lock,flags);
860 udelay (1000);
861
862 return ! done;
863}
864
865/*
866 * Initial register values to be written to the AC97 mixer.
867 * While most of these are identical to the reset values, we do this
868 * so that we have most of the register contents cached--this avoids
869 * reading from the mixer directly (which seems to be problematic,
870 * probably due to ignorance).
871 */
872struct initialValues
873{
874 unsigned short port;
875 unsigned short value;
876};
877
878static struct initialValues nm256_ac97_initial_values[] =
879{
880 { AC97_MASTER_VOL_STEREO, 0x8000 },
881 { AC97_HEADPHONE_VOL, 0x8000 },
882 { AC97_MASTER_VOL_MONO, 0x0000 },
883 { AC97_PCBEEP_VOL, 0x0000 },
884 { AC97_PHONE_VOL, 0x0008 },
885 { AC97_MIC_VOL, 0x8000 },
886 { AC97_LINEIN_VOL, 0x8808 },
887 { AC97_CD_VOL, 0x8808 },
888 { AC97_VIDEO_VOL, 0x8808 },
889 { AC97_AUX_VOL, 0x8808 },
890 { AC97_PCMOUT_VOL, 0x0808 },
891 { AC97_RECORD_SELECT, 0x0000 },
892 { AC97_RECORD_GAIN, 0x0B0B },
893 { AC97_GENERAL_PURPOSE, 0x0000 },
894 { 0xffff, 0xffff }
895};
896
897/* Initialize the AC97 into a known state. */
898static int
899nm256_resetAC97 (struct ac97_hwint *dev)
900{
901 struct nm256_info *card = (struct nm256_info *)dev->driver_private;
902 int x;
903
904 if (card->magsig != NM_MAGIC_SIG) {
905 printk (KERN_ERR "NM256: Bad magic signature in resetAC97!\n");
906 return -EINVAL;
907 }
908
909 /* Reset the mixer. 'Tis magic! */
910 nm256_writePort8 (card, 2, 0x6c0, 1);
911// nm256_writePort8 (card, 2, 0x6cc, 0x87); /* This crashes Dell latitudes */
912 nm256_writePort8 (card, 2, 0x6cc, 0x80);
913 nm256_writePort8 (card, 2, 0x6cc, 0x0);
914
915 if (! card->mixer_values_init) {
916 for (x = 0; nm256_ac97_initial_values[x].port != 0xffff; x++) {
917 ac97_put_register (dev,
918 nm256_ac97_initial_values[x].port,
919 nm256_ac97_initial_values[x].value);
920 card->mixer_values_init = 1;
921 }
922 }
923
924 return 0;
925}
926
927/*
928 * We don't do anything particularly special here; it just passes the
929 * mixer ioctl to the AC97 driver.
930 */
931static int
932nm256_default_mixer_ioctl (int dev, unsigned int cmd, void __user *arg)
933{
934 struct nm256_info *card = nm256_find_card_for_mixer (dev);
935 if (card != NULL)
936 return ac97_mixer_ioctl (&(card->mdev), cmd, arg);
937 else
938 return -ENODEV;
939}
940
941static struct mixer_operations nm256_mixer_operations = {
942 .owner = THIS_MODULE,
943 .id = "NeoMagic",
944 .name = "NM256AC97Mixer",
945 .ioctl = nm256_default_mixer_ioctl
946};
947
948/*
949 * Default settings for the OSS mixer. These are set last, after the
950 * mixer is initialized.
951 *
952 * I "love" C sometimes. Got braces?
953 */
954static struct ac97_mixer_value_list mixer_defaults[] = {
955 { SOUND_MIXER_VOLUME, { { 85, 85 } } },
956 { SOUND_MIXER_SPEAKER, { { 100 } } },
957 { SOUND_MIXER_PCM, { { 65, 65 } } },
958 { SOUND_MIXER_CD, { { 65, 65 } } },
959 { -1, { { 0, 0 } } }
960};
961
962
963/* Installs the AC97 mixer into CARD. */
964static int __init
965nm256_install_mixer (struct nm256_info *card)
966{
967 int mixer;
968
969 card->mdev.reset_device = nm256_resetAC97;
970 card->mdev.read_reg = nm256_readAC97Reg;
971 card->mdev.write_reg = nm256_writeAC97Reg;
972 card->mdev.driver_private = (void *)card;
973
974 if (ac97_init (&(card->mdev)))
975 return -1;
976
977 mixer = sound_alloc_mixerdev();
978 if (num_mixers >= MAX_MIXER_DEV) {
979 printk ("NM256 mixer: Unable to alloc mixerdev\n");
980 return -1;
981 }
982
983 mixer_devs[mixer] = &nm256_mixer_operations;
984 card->mixer_oss_dev = mixer;
985
986 /* Some reasonable default values. */
987 ac97_set_values (&(card->mdev), mixer_defaults);
988
989 printk(KERN_INFO "Initialized AC97 mixer\n");
990 return 0;
991}
992
993/* Perform a full reset on the hardware; this is invoked when an APM
994 resume event occurs. */
995static void
996nm256_full_reset (struct nm256_info *card)
997{
998 nm256_initHw (card);
999 ac97_reset (&(card->mdev));
1000}
1001
1002/*
1003 * See if the signature left by the NM256 BIOS is intact; if so, we use
1004 * the associated address as the end of our audio buffer in the video
1005 * RAM.
1006 */
1007
1008static void __init
1009nm256_peek_for_sig (struct nm256_info *card)
1010{
1011 u32 port1offset
1012 = card->port[0].physaddr + card->port[0].end_offset - 0x0400;
1013 /* The signature is located 1K below the end of video RAM. */
1014 char __iomem *temp = ioremap_nocache (port1offset, 16);
1015 /* Default buffer end is 5120 bytes below the top of RAM. */
1016 u32 default_value = card->port[0].end_offset - 0x1400;
1017 u32 sig;
1018
1019 /* Install the default value first, so we don't have to repeatedly
1020 do it if there is a problem. */
1021 card->port[0].end_offset = default_value;
1022
1023 if (temp == NULL) {
1024 printk (KERN_ERR "NM256: Unable to scan for card signature in video RAM\n");
1025 return;
1026 }
1027 sig = readl (temp);
1028 if ((sig & NM_SIG_MASK) == NM_SIGNATURE) {
1029 u32 pointer = readl (temp + 4);
1030
1031 /*
1032 * If it's obviously invalid, don't use it (the port already has a
1033 * suitable default value set).
1034 */
1035 if (pointer != 0xffffffff)
1036 card->port[0].end_offset = pointer;
1037
1038 printk (KERN_INFO "NM256: Found card signature in video RAM: 0x%x\n",
1039 pointer);
1040 }
1041
1042 iounmap (temp);
1043}
1044
1045/*
1046 * Install a driver for the PCI device referenced by PCIDEV.
1047 * VERSTR is a human-readable version string.
1048 */
1049
1050static int __devinit
1051nm256_install(struct pci_dev *pcidev, enum nm256rev rev, char *verstr)
1052{
1053 struct nm256_info *card;
1054 struct pm_dev *pmdev;
1055 int x;
1056
1057 if (pci_enable_device(pcidev))
1058 return 0;
1059
1060 card = kmalloc (sizeof (struct nm256_info), GFP_KERNEL);
1061 if (card == NULL) {
1062 printk (KERN_ERR "NM256: out of memory!\n");
1063 return 0;
1064 }
1065
1066 card->magsig = NM_MAGIC_SIG;
1067 card->playing = 0;
1068 card->recording = 0;
1069 card->rev = rev;
1070 spin_lock_init(&card->lock);
1071
1072 /* Init the memory port info. */
1073 for (x = 0; x < 2; x++) {
1074 card->port[x].physaddr = pci_resource_start (pcidev, x);
1075 card->port[x].ptr = NULL;
1076 card->port[x].start_offset = 0;
1077 card->port[x].end_offset = 0;
1078 }
1079
1080 /* Port 2 is easy. */
1081 card->port[1].start_offset = 0;
1082 card->port[1].end_offset = NM_PORT2_SIZE;
1083
1084 /* Yuck. But we have to map in port 2 so we can check how much RAM the
1085 card has. */
1086 if (nm256_remap_ports (card)) {
1087 kfree (card);
1088 return 0;
1089 }
1090
1091 /*
1092 * The NM256 has two memory ports. The first port is nothing
1093 * more than a chunk of video RAM, which is used as the I/O ring
1094 * buffer. The second port has the actual juicy stuff (like the
1095 * mixer and the playback engine control registers).
1096 */
1097
1098 if (card->rev == REV_NM256AV) {
1099 /* Ok, try to see if this is a non-AC97 version of the hardware. */
1100 int pval = nm256_readPort16 (card, 2, NM_MIXER_PRESENCE);
1101 if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) {
1102 if (! force_load) {
1103 printk (KERN_ERR "NM256: This doesn't look to me like the AC97-compatible version.\n");
1104 printk (KERN_ERR " You can force the driver to load by passing in the module\n");
1105 printk (KERN_ERR " parameter:\n");
1106 printk (KERN_ERR " force_load = 1\n");
1107 printk (KERN_ERR "\n");
1108 printk (KERN_ERR " More likely, you should be using the appropriate SB-16 or\n");
1109 printk (KERN_ERR " CS4232 driver instead. (If your BIOS has settings for\n");
1110 printk (KERN_ERR " IRQ and/or DMA for the sound card, this is *not* the correct\n");
1111 printk (KERN_ERR " driver to use.)\n");
1112 nm256_release_ports (card);
1113 kfree (card);
1114 return 0;
1115 }
1116 else {
1117 printk (KERN_INFO "NM256: Forcing driver load as per user request.\n");
1118 }
1119 }
1120 else {
1121 /* printk (KERN_INFO "NM256: Congratulations. You're not running Eunice.\n")*/;
1122 }
1123 card->port[0].end_offset = 2560 * 1024;
1124 card->introutine = nm256_interrupt;
1125 card->mixer_status_offset = NM_MIXER_STATUS_OFFSET;
1126 card->mixer_status_mask = NM_MIXER_READY_MASK;
1127 }
1128 else {
1129 /* Not sure if there is any relevant detect for the ZX or not. */
1130 if (nm256_readPort8 (card, 2, 0xa0b) != 0)
1131 card->port[0].end_offset = 6144 * 1024;
1132 else
1133 card->port[0].end_offset = 4096 * 1024;
1134
1135 card->introutine = nm256_interrupt_zx;
1136 card->mixer_status_offset = NM2_MIXER_STATUS_OFFSET;
1137 card->mixer_status_mask = NM2_MIXER_READY_MASK;
1138 }
1139
1140 if (buffertop >= 98304 && buffertop < card->port[0].end_offset)
1141 card->port[0].end_offset = buffertop;
1142 else
1143 nm256_peek_for_sig (card);
1144
1145 card->port[0].start_offset = card->port[0].end_offset - 98304;
1146
1147 printk (KERN_INFO "NM256: Mapping port 1 from 0x%x - 0x%x\n",
1148 card->port[0].start_offset, card->port[0].end_offset);
1149
1150 if (nm256_remap_ports (card)) {
1151 kfree (card);
1152 return 0;
1153 }
1154
1155 /* See if we can get the interrupt. */
1156
1157 card->irq = pcidev->irq;
1158 card->has_irq = 0;
1159
1160 if (nm256_grabInterrupt (card) != 0) {
1161 nm256_release_ports (card);
1162 kfree (card);
1163 return 0;
1164 }
1165
1166 nm256_releaseInterrupt (card);
1167
1168 /*
1169 * Init the board.
1170 */
1171
1172 card->playbackBufferSize = 16384;
1173 card->recordBufferSize = 16384;
1174
1175 card->coeffBuf = card->port[0].end_offset - NM_MAX_COEFFICIENT;
1176 card->abuf2 = card->coeffBuf - card->recordBufferSize;
1177 card->abuf1 = card->abuf2 - card->playbackBufferSize;
1178 card->allCoeffBuf = card->abuf2 - (NM_TOTAL_COEFF_COUNT * 4);
1179
1180 /* Fixed setting. */
1181 card->mixer = NM_MIXER_OFFSET;
1182 card->mixer_values_init = 0;
1183
1184 card->is_open_play = 0;
1185 card->is_open_record = 0;
1186
1187 card->coeffsCurrent = 0;
1188
1189 card->opencnt[0] = 0; card->opencnt[1] = 0;
1190
1191 /* Reasonable default settings, but largely unnecessary. */
1192 for (x = 0; x < 2; x++) {
1193 card->sinfo[x].bits = 8;
1194 card->sinfo[x].stereo = 0;
1195 card->sinfo[x].samplerate = 8000;
1196 }
1197
1198 nm256_initHw (card);
1199
1200 for (x = 0; x < 2; x++) {
1201 if ((card->dev[x] =
1202 sound_install_audiodrv(AUDIO_DRIVER_VERSION,
1203 "NM256", &nm256_audio_driver,
1204 sizeof(struct audio_driver),
1205 DMA_NODMA, AFMT_U8 | AFMT_S16_LE,
1206 NULL, -1, -1)) >= 0) {
1207 /* 1K minimum buffer size. */
1208 audio_devs[card->dev[x]]->min_fragment = 10;
1209 /* Maximum of 8K buffer size. */
1210 audio_devs[card->dev[x]]->max_fragment = 13;
1211 }
1212 else {
1213 printk(KERN_ERR "NM256: Too many PCM devices available\n");
1214 nm256_release_ports (card);
1215 kfree (card);
1216 return 0;
1217 }
1218 }
1219
1220 pci_set_drvdata(pcidev,card);
1221
1222 /* Insert the card in the list. */
1223 card->next_card = nmcard_list;
1224 nmcard_list = card;
1225
1226 printk(KERN_INFO "Initialized NeoMagic %s audio in PCI native mode\n",
1227 verstr);
1228
1229 /*
1230 * And our mixer. (We should allow support for other mixers, maybe.)
1231 */
1232
1233 nm256_install_mixer (card);
1234
1235 pmdev = pm_register(PM_PCI_DEV, PM_PCI_ID(pcidev), handle_pm_event);
1236 if (pmdev)
1237 pmdev->data = card;
1238
1239 return 1;
1240}
1241
1242
1243/*
1244 * PM event handler, so the card is properly reinitialized after a power
1245 * event.
1246 */
1247static int
1248handle_pm_event (struct pm_dev *dev, pm_request_t rqst, void *data)
1249{
1250 struct nm256_info *crd = (struct nm256_info*) dev->data;
1251 if (crd) {
1252 switch (rqst) {
1253 case PM_SUSPEND:
1254 break;
1255 case PM_RESUME:
1256 {
1257 int playing = crd->playing;
1258 nm256_full_reset (crd);
1259 /*
1260 * A little ugly, but that's ok; pretend the
1261 * block we were playing is done.
1262 */
1263 if (playing)
1264 DMAbuf_outputintr (crd->dev_for_play, 1);
1265 }
1266 break;
1267 }
1268 }
1269 return 0;
1270}
1271
1272static int __devinit
1273nm256_probe(struct pci_dev *pcidev,const struct pci_device_id *pciid)
1274{
1275 if (pcidev->device == PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO)
1276 return nm256_install(pcidev, REV_NM256AV, "256AV");
1277 if (pcidev->device == PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO)
1278 return nm256_install(pcidev, REV_NM256ZX, "256ZX");
1279 if (pcidev->device == PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO)
1280 return nm256_install(pcidev, REV_NM256ZX, "256XL+");
1281 return -1; /* should not come here ... */
1282}
1283
1284static void __devinit
1285nm256_remove(struct pci_dev *pcidev) {
1286 struct nm256_info *xcard = pci_get_drvdata(pcidev);
1287 struct nm256_info *card,*next_card = NULL;
1288
1289 for (card = nmcard_list; card != NULL; card = next_card) {
1290 next_card = card->next_card;
1291 if (card == xcard) {
1292 stopPlay (card);
1293 stopRecord (card);
1294 if (card->has_irq)
1295 free_irq (card->irq, card);
1296 nm256_release_ports (card);
1297 sound_unload_mixerdev (card->mixer_oss_dev);
1298 sound_unload_audiodev (card->dev[0]);
1299 sound_unload_audiodev (card->dev[1]);
1300 kfree (card);
1301 break;
1302 }
1303 }
1304 if (nmcard_list == card)
1305 nmcard_list = next_card;
1306}
1307
1308/*
1309 * Open the device
1310 *
1311 * DEV - device
1312 * MODE - mode to open device (logical OR of OPEN_READ and OPEN_WRITE)
1313 *
1314 * Called when opening the DMAbuf (dmabuf.c:259)
1315 */
1316static int
1317nm256_audio_open(int dev, int mode)
1318{
1319 struct nm256_info *card = nm256_find_card (dev);
1320 int w;
1321
1322 if (card == NULL)
1323 return -ENODEV;
1324
1325 if (card->dev[0] == dev)
1326 w = 0;
1327 else if (card->dev[1] == dev)
1328 w = 1;
1329 else
1330 return -ENODEV;
1331
1332 if (card->opencnt[w] > 0)
1333 return -EBUSY;
1334
1335 /* No bits set? Huh? */
1336 if (! ((mode & OPEN_READ) || (mode & OPEN_WRITE)))
1337 return -EIO;
1338
1339 /*
1340 * If it's open for both read and write, and the card's currently
1341 * being read or written to, then do the opposite of what has
1342 * already been done. Otherwise, don't specify any mode until the
1343 * user actually tries to do I/O. (Some programs open the device
1344 * for both read and write, but only actually do reading or writing.)
1345 */
1346
1347 if ((mode & OPEN_WRITE) && (mode & OPEN_READ)) {
1348 if (card->is_open_play)
1349 mode = OPEN_WRITE;
1350 else if (card->is_open_record)
1351 mode = OPEN_READ;
1352 else mode = 0;
1353 }
1354
1355 if (mode & OPEN_WRITE) {
1356 if (card->is_open_play == 0) {
1357 card->dev_for_play = dev;
1358 card->is_open_play = 1;
1359 }
1360 else
1361 return -EBUSY;
1362 }
1363
1364 if (mode & OPEN_READ) {
1365 if (card->is_open_record == 0) {
1366 card->dev_for_record = dev;
1367 card->is_open_record = 1;
1368 }
1369 else
1370 return -EBUSY;
1371 }
1372
1373 card->opencnt[w]++;
1374 return 0;
1375}
1376
1377/*
1378 * Close the device
1379 *
1380 * DEV - device
1381 *
1382 * Called when closing the DMAbuf (dmabuf.c:477)
1383 * after halt_xfer
1384 */
1385static void
1386nm256_audio_close(int dev)
1387{
1388 struct nm256_info *card = nm256_find_card (dev);
1389
1390 if (card != NULL) {
1391 int w;
1392
1393 if (card->dev[0] == dev)
1394 w = 0;
1395 else if (card->dev[1] == dev)
1396 w = 1;
1397 else
1398 return;
1399
1400 card->opencnt[w]--;
1401 if (card->opencnt[w] <= 0) {
1402 card->opencnt[w] = 0;
1403
1404 if (card->dev_for_play == dev) {
1405 stopPlay (card);
1406 card->is_open_play = 0;
1407 card->dev_for_play = -1;
1408 }
1409
1410 if (card->dev_for_record == dev) {
1411 stopRecord (card);
1412 card->is_open_record = 0;
1413 card->dev_for_record = -1;
1414 }
1415 }
1416 }
1417}
1418
1419/* Standard ioctl handler. */
1420static int
1421nm256_audio_ioctl(int dev, unsigned int cmd, void __user *arg)
1422{
1423 int ret;
1424 u32 oldinfo;
1425 int w;
1426
1427 struct nm256_info *card = nm256_find_card (dev);
1428
1429 if (card == NULL)
1430 return -ENODEV;
1431
1432 if (dev == card->dev[0])
1433 w = 0;
1434 else
1435 w = 1;
1436
1437 /*
1438 * The code here is messy. There are probably better ways to do
1439 * it. (It should be possible to handle it the same way the AC97 mixer
1440 * is done.)
1441 */
1442 switch (cmd)
1443 {
1444 case SOUND_PCM_WRITE_RATE:
1445 if (get_user(ret, (int __user *) arg))
1446 return -EFAULT;
1447
1448 if (ret != 0) {
1449 oldinfo = card->sinfo[w].samplerate;
1450 card->sinfo[w].samplerate = ret;
1451 ret = nm256_setInfo(dev, card);
1452 if (ret != 0)
1453 card->sinfo[w].samplerate = oldinfo;
1454 }
1455 if (ret == 0)
1456 ret = card->sinfo[w].samplerate;
1457 break;
1458
1459 case SOUND_PCM_READ_RATE:
1460 ret = card->sinfo[w].samplerate;
1461 break;
1462
1463 case SNDCTL_DSP_STEREO:
1464 if (get_user(ret, (int __user *) arg))
1465 return -EFAULT;
1466
1467 card->sinfo[w].stereo = ret ? 1 : 0;
1468 ret = nm256_setInfo (dev, card);
1469 if (ret == 0)
1470 ret = card->sinfo[w].stereo;
1471
1472 break;
1473
1474 case SOUND_PCM_WRITE_CHANNELS:
1475 if (get_user(ret, (int __user *) arg))
1476 return -EFAULT;
1477
1478 if (ret < 1 || ret > 3)
1479 ret = card->sinfo[w].stereo + 1;
1480 else {
1481 card->sinfo[w].stereo = ret - 1;
1482 ret = nm256_setInfo (dev, card);
1483 if (ret == 0)
1484 ret = card->sinfo[w].stereo + 1;
1485 }
1486 break;
1487
1488 case SOUND_PCM_READ_CHANNELS:
1489 ret = card->sinfo[w].stereo + 1;
1490 break;
1491
1492 case SNDCTL_DSP_SETFMT:
1493 if (get_user(ret, (int __user *) arg))
1494 return -EFAULT;
1495
1496 if (ret != 0) {
1497 oldinfo = card->sinfo[w].bits;
1498 card->sinfo[w].bits = ret;
1499 ret = nm256_setInfo (dev, card);
1500 if (ret != 0)
1501 card->sinfo[w].bits = oldinfo;
1502 }
1503 if (ret == 0)
1504 ret = card->sinfo[w].bits;
1505 break;
1506
1507 case SOUND_PCM_READ_BITS:
1508 ret = card->sinfo[w].bits;
1509 break;
1510
1511 default:
1512 return -EINVAL;
1513 }
1514 return put_user(ret, (int __user *) arg);
1515}
1516
1517/*
1518 * Given the sound device DEV and an associated physical buffer PHYSBUF,
1519 * return a pointer to the actual buffer in kernel space.
1520 *
1521 * This routine should exist as part of the soundcore routines.
1522 */
1523
1524static char *
1525nm256_getDMAbuffer (int dev, unsigned long physbuf)
1526{
1527 struct audio_operations *adev = audio_devs[dev];
1528 struct dma_buffparms *dmap = adev->dmap_out;
1529 char *dma_start =
1530 (char *)(physbuf - (unsigned long)dmap->raw_buf_phys
1531 + (unsigned long)dmap->raw_buf);
1532
1533 return dma_start;
1534}
1535
1536
1537/*
1538 * Output a block to sound device
1539 *
1540 * dev - device number
1541 * buf - physical address of buffer
1542 * total_count - total byte count in buffer
1543 * intrflag - set if this has been called from an interrupt
1544 * (via DMAbuf_outputintr)
1545 * restart_dma - set if engine needs to be re-initialised
1546 *
1547 * Called when:
1548 * 1. Starting output (dmabuf.c:1327)
1549 * 2. (dmabuf.c:1504)
1550 * 3. A new buffer needs to be sent to the device (dmabuf.c:1579)
1551 */
1552static void
1553nm256_audio_output_block(int dev, unsigned long physbuf,
1554 int total_count, int intrflag)
1555{
1556 struct nm256_info *card = nm256_find_card (dev);
1557
1558 if (card != NULL) {
1559 char *dma_buf = nm256_getDMAbuffer (dev, physbuf);
1560 card->is_open_play = 1;
1561 card->dev_for_play = dev;
1562 nm256_write_block (card, dma_buf, total_count);
1563 }
1564}
1565
1566/* Ditto, but do recording instead. */
1567static void
1568nm256_audio_start_input(int dev, unsigned long physbuf, int count,
1569 int intrflag)
1570{
1571 struct nm256_info *card = nm256_find_card (dev);
1572
1573 if (card != NULL) {
1574 char *dma_buf = nm256_getDMAbuffer (dev, physbuf);
1575 card->is_open_record = 1;
1576 card->dev_for_record = dev;
1577 nm256_startRecording (card, dma_buf, count);
1578 }
1579}
1580
1581/*
1582 * Prepare for inputting samples to DEV.
1583 * Each requested buffer will be BSIZE byes long, with a total of
1584 * BCOUNT buffers.
1585 */
1586
1587static int
1588nm256_audio_prepare_for_input(int dev, int bsize, int bcount)
1589{
1590 struct nm256_info *card = nm256_find_card (dev);
1591
1592 if (card == NULL)
1593 return -ENODEV;
1594
1595 if (card->is_open_record && card->dev_for_record != dev)
1596 return -EBUSY;
1597
1598 audio_devs[dev]->dmap_in->flags |= DMA_NODMA;
1599 return 0;
1600}
1601
1602/*
1603 * Prepare for outputting samples to `dev'
1604 *
1605 * Each buffer that will be passed will be `bsize' bytes long,
1606 * with a total of `bcount' buffers.
1607 *
1608 * Called when:
1609 * 1. A trigger enables audio output (dmabuf.c:978)
1610 * 2. We get a write buffer without dma_mode setup (dmabuf.c:1152)
1611 * 3. We restart a transfer (dmabuf.c:1324)
1612 */
1613
1614static int
1615nm256_audio_prepare_for_output(int dev, int bsize, int bcount)
1616{
1617 struct nm256_info *card = nm256_find_card (dev);
1618
1619 if (card == NULL)
1620 return -ENODEV;
1621
1622 if (card->is_open_play && card->dev_for_play != dev)
1623 return -EBUSY;
1624
1625 audio_devs[dev]->dmap_out->flags |= DMA_NODMA;
1626 return 0;
1627}
1628
1629/* Stop the current operations associated with DEV. */
1630static void
1631nm256_audio_reset(int dev)
1632{
1633 struct nm256_info *card = nm256_find_card (dev);
1634
1635 if (card != NULL) {
1636 if (card->dev_for_play == dev)
1637 stopPlay (card);
1638 if (card->dev_for_record == dev)
1639 stopRecord (card);
1640 }
1641}
1642
1643static int
1644nm256_audio_local_qlen(int dev)
1645{
1646 return 0;
1647}
1648
1649static struct audio_driver nm256_audio_driver =
1650{
1651 .owner = THIS_MODULE,
1652 .open = nm256_audio_open,
1653 .close = nm256_audio_close,
1654 .output_block = nm256_audio_output_block,
1655 .start_input = nm256_audio_start_input,
1656 .ioctl = nm256_audio_ioctl,
1657 .prepare_for_input = nm256_audio_prepare_for_input,
1658 .prepare_for_output = nm256_audio_prepare_for_output,
1659 .halt_io = nm256_audio_reset,
1660 .local_qlen = nm256_audio_local_qlen,
1661};
1662
1663static struct pci_device_id nm256_pci_tbl[] = {
1664 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO,
1665 PCI_ANY_ID, PCI_ANY_ID, 0, 0},
1666 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO,
1667 PCI_ANY_ID, PCI_ANY_ID, 0, 0},
1668 {PCI_VENDOR_ID_NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO,
1669 PCI_ANY_ID, PCI_ANY_ID, 0, 0},
1670 {0,}
1671};
1672MODULE_DEVICE_TABLE(pci, nm256_pci_tbl);
1673MODULE_LICENSE("GPL");
1674
1675
1676static struct pci_driver nm256_pci_driver = {
1677 .name = "nm256_audio",
1678 .id_table = nm256_pci_tbl,
1679 .probe = nm256_probe,
1680 .remove = nm256_remove,
1681};
1682
1683module_param(usecache, bool, 0);
1684module_param(buffertop, int, 0);
1685module_param(nm256_debug, bool, 0644);
1686module_param(force_load, bool, 0);
1687
1688static int __init do_init_nm256(void)
1689{
1690 printk (KERN_INFO "NeoMagic 256AV/256ZX audio driver, version 1.1p\n");
1691 return pci_module_init(&nm256_pci_driver);
1692}
1693
1694static void __exit cleanup_nm256 (void)
1695{
1696 pci_unregister_driver(&nm256_pci_driver);
1697 pm_unregister_all (&handle_pm_event);
1698}
1699
1700module_init(do_init_nm256);
1701module_exit(cleanup_nm256);
1702
1703/*
1704 * Local variables:
1705 * c-basic-offset: 4
1706 * End:
1707 */
diff --git a/sound/oss/nm256_coeff.h b/sound/oss/nm256_coeff.h
new file mode 100644
index 000000000000..0ceecc20077b
--- /dev/null
+++ b/sound/oss/nm256_coeff.h
@@ -0,0 +1,4697 @@
1#ifndef NM256_COEFF_H
2#define NM256_COEFF_H
3
4#define NM_TOTAL_COEFF_COUNT 0x3158
5
6static char coefficients[NM_TOTAL_COEFF_COUNT * 4] = {
7 0xFF, 0xFF, 0x2F, 0x00, 0x4B, 0xFF, 0xA5, 0x01, 0xEF, 0xFC, 0x21,
8 0x05, 0x87, 0xF7, 0x62, 0x11, 0xE9, 0x45, 0x5E, 0xF9, 0xB5, 0x01,
9 0xDE, 0xFF, 0xA4, 0xFF, 0x60, 0x00, 0xCA, 0xFF, 0x0D, 0x00, 0xFD,
10 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3D, 0xFC, 0xD6, 0x06,
11 0x4C, 0xF3, 0xED, 0x20, 0x3D, 0x3D, 0x4A, 0xF3, 0x4E, 0x05, 0xB1,
12 0xFD, 0xE1, 0x00, 0xC3, 0xFF, 0x05, 0x00, 0x02, 0x00, 0xFD, 0xFF,
13 0x2A, 0x00, 0x5C, 0xFF, 0xAA, 0x01, 0x71, 0xFC, 0x07, 0x07, 0x7E,
14 0xF1, 0x44, 0x30, 0x44, 0x30, 0x7E, 0xF1, 0x07, 0x07, 0x71, 0xFC,
15 0xAA, 0x01, 0x5C, 0xFF, 0x2A, 0x00, 0xFD, 0xFF, 0x02, 0x00, 0x05,
16 0x00, 0xC3, 0xFF, 0xE1, 0x00, 0xB1, 0xFD, 0x4E, 0x05, 0x4A, 0xF3,
17 0x3D, 0x3D, 0xED, 0x20, 0x4C, 0xF3, 0xD6, 0x06, 0x3D, 0xFC, 0xE6,
18 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x0D, 0x00, 0xCA, 0xFF,
19 0x60, 0x00, 0xA4, 0xFF, 0xDE, 0xFF, 0xB5, 0x01, 0x5E, 0xF9, 0xE9,
20 0x45, 0x62, 0x11, 0x87, 0xF7, 0x21, 0x05, 0xEF, 0xFC, 0xA5, 0x01,
21 0x4B, 0xFF, 0x2F, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x1E, 0x00, 0x84,
22 0xFF, 0x11, 0x01, 0x34, 0xFE, 0x8F, 0x02, 0xC7, 0xFC, 0xAE, 0x03,
23 0xF7, 0x48, 0xAE, 0x03, 0xC7, 0xFC, 0x8F, 0x02, 0x34, 0xFE, 0x11,
24 0x01, 0x84, 0xFF, 0x1E, 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3D, 0xFF,
25 0xCA, 0x01, 0x95, 0xFC, 0xEA, 0x05, 0xBB, 0xF5, 0x25, 0x17, 0x3C,
26 0x43, 0x8D, 0xF6, 0x43, 0x03, 0xF5, 0xFE, 0x26, 0x00, 0x20, 0x00,
27 0xE2, 0xFF, 0x08, 0x00, 0xFD, 0xFF, 0x30, 0x00, 0x4D, 0xFF, 0xC5,
28 0x01, 0x4C, 0xFC, 0x26, 0x07, 0xA3, 0xF1, 0xAB, 0x2C, 0xBB, 0x33,
29 0x8F, 0xF1, 0xCA, 0x06, 0xA6, 0xFC, 0x85, 0x01, 0x6F, 0xFF, 0x24,
30 0x00, 0xFD, 0xFF, 0x03, 0x00, 0xFE, 0xFF, 0xD5, 0xFF, 0xBC, 0x00,
31 0xF0, 0xFD, 0xEC, 0x04, 0xD9, 0xF3, 0xB1, 0x3E, 0xCD, 0x1E, 0xC1,
32 0xF3, 0xAF, 0x06, 0x49, 0xFC, 0xE4, 0x01, 0x36, 0xFF, 0x36, 0x00,
33 0xFE, 0xFF, 0x16, 0x00, 0xA6, 0xFF, 0xBB, 0x00, 0xE9, 0xFE, 0x38,
34 0x01, 0x4B, 0xFF, 0x28, 0xFE, 0x3A, 0x48, 0x04, 0x0A, 0x2E, 0xFA,
35 0xDF, 0x03, 0x8A, 0xFD, 0x60, 0x01, 0x65, 0xFF, 0x27, 0x00, 0x00,
36 0x00, 0xFF, 0xFF, 0x2E, 0x00, 0x50, 0xFF, 0x98, 0x01, 0x0D, 0xFD,
37 0xE0, 0x04, 0x14, 0xF8, 0xC3, 0x0F, 0x89, 0x46, 0x4C, 0xFA, 0x38,
38 0x01, 0x25, 0x00, 0x7D, 0xFF, 0x73, 0x00, 0xC2, 0xFF, 0x0F, 0x00,
39 0xFD, 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xE3, 0x01, 0x31, 0xFC, 0x0F,
40 0x07, 0x84, 0xF2, 0x29, 0x25, 0x1A, 0x3A, 0x67, 0xF2, 0xF6, 0x05,
41 0x41, 0xFD, 0x24, 0x01, 0xA1, 0xFF, 0x12, 0x00, 0x00, 0x00, 0xFF,
42 0xFF, 0x15, 0x00, 0x97, 0xFF, 0x37, 0x01, 0x22, 0xFD, 0x23, 0x06,
43 0x2F, 0xF2, 0x11, 0x39, 0x7B, 0x26, 0x50, 0xF2, 0x1B, 0x07, 0x32,
44 0xFC, 0xE1, 0x01, 0x3C, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x0E, 0x00,
45 0xC8, 0xFF, 0x64, 0x00, 0x9B, 0xFF, 0xEE, 0xFF, 0x98, 0x01, 0x93,
46 0xF9, 0x10, 0x46, 0x03, 0x11, 0xA7, 0xF7, 0x12, 0x05, 0xF6, 0xFC,
47 0xA2, 0x01, 0x4C, 0xFF, 0x2F, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x26,
48 0x00, 0x6A, 0xFF, 0x53, 0x01, 0xA6, 0xFD, 0xA6, 0x03, 0xA1, 0xFA,
49 0xDE, 0x08, 0x76, 0x48, 0x0C, 0xFF, 0xDE, 0xFE, 0x73, 0x01, 0xC9,
50 0xFE, 0xCA, 0x00, 0xA0, 0xFF, 0x17, 0x00, 0xFE, 0xFF, 0x36, 0x00,
51 0x36, 0xFF, 0xE1, 0x01, 0x52, 0xFC, 0x93, 0x06, 0x10, 0xF4, 0x78,
52 0x1D, 0x90, 0x3F, 0x3E, 0xF4, 0xAA, 0x04, 0x19, 0xFE, 0xA4, 0x00,
53 0xE2, 0xFF, 0xFA, 0xFF, 0x03, 0x00, 0xFD, 0xFF, 0x26, 0x00, 0x68,
54 0xFF, 0x93, 0x01, 0x92, 0xFC, 0xE2, 0x06, 0x83, 0xF1, 0x8C, 0x32,
55 0xED, 0x2D, 0x90, 0xF1, 0x1E, 0x07, 0x57, 0xFC, 0xBD, 0x01, 0x51,
56 0xFF, 0x2E, 0x00, 0xFD, 0xFF, 0x07, 0x00, 0xE8, 0xFF, 0x12, 0x00,
57 0x42, 0x00, 0xC4, 0xFE, 0x94, 0x03, 0x02, 0xF6, 0x89, 0x42, 0x76,
58 0x18, 0x5C, 0xF5, 0x12, 0x06, 0x84, 0xFC, 0xD1, 0x01, 0x3B, 0xFF,
59 0x34, 0x00, 0xFE, 0xFF, 0x1D, 0x00, 0x8A, 0xFF, 0x03, 0x01, 0x53,
60 0xFE, 0x53, 0x02, 0x39, 0xFD, 0xA9, 0x02, 0xF2, 0x48, 0xB9, 0x04,
61 0x54, 0xFC, 0xCA, 0x02, 0x16, 0xFE, 0x20, 0x01, 0x7F, 0xFF, 0x20,
62 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0x40, 0xFF, 0xC3, 0x01,
63 0xA7, 0xFC, 0xC0, 0x05, 0x1E, 0xF6, 0xD8, 0x15, 0xE7, 0x43, 0x20,
64 0xF7, 0xEF, 0x02, 0x27, 0xFF, 0x0A, 0x00, 0x2E, 0x00, 0xDD, 0xFF,
65 0x09, 0x00, 0xFD, 0xFF, 0x31, 0x00, 0x48, 0xFF, 0xCD, 0x01, 0x43,
66 0xFC, 0x2A, 0x07, 0xBC, 0xF1, 0x64, 0x2B, 0xE3, 0x34, 0xA3, 0xF1,
67 0xAE, 0x06, 0xBD, 0xFC, 0x77, 0x01, 0x77, 0xFF, 0x21, 0x00, 0xFE,
68 0xFF, 0x02, 0x00, 0x03, 0x00, 0xCA, 0xFF, 0xD4, 0x00, 0xC8, 0xFD,
69 0x2A, 0x05, 0x7D, 0xF3, 0xCA, 0x3D, 0x22, 0x20, 0x76, 0xF3, 0xC8,
70 0x06, 0x41, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF,
71 0x14, 0x00, 0xAC, 0xFF, 0xAC, 0x00, 0x08, 0xFF, 0xFD, 0x00, 0xB5,
72 0xFF, 0x4B, 0xFD, 0xF4, 0x47, 0x30, 0x0B, 0xBC, 0xF9, 0x17, 0x04,
73 0x6E, 0xFD, 0x6D, 0x01, 0x60, 0xFF, 0x29, 0x00, 0x00, 0x00, 0xFF,
74 0xFF, 0x2C, 0x00, 0x54, 0xFF, 0x8D, 0x01, 0x26, 0xFD, 0xAD, 0x04,
75 0x82, 0xF8, 0x87, 0x0E, 0xF9, 0x46, 0x0C, 0xFB, 0xD4, 0x00, 0x5D,
76 0x00, 0x5E, 0xFF, 0x82, 0x00, 0xBD, 0xFF, 0x10, 0x00, 0xFD, 0xFF,
77 0x36, 0x00, 0x38, 0xFF, 0xE5, 0x01, 0x33, 0xFC, 0x01, 0x07, 0xBE,
78 0xF2, 0xD6, 0x23, 0x1F, 0x3B, 0xA5, 0xF2, 0xC5, 0x05, 0x62, 0xFD,
79 0x10, 0x01, 0xAB, 0xFF, 0x0E, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x19,
80 0x00, 0x8E, 0xFF, 0x49, 0x01, 0x04, 0xFD, 0x4D, 0x06, 0x00, 0xF2,
81 0xFE, 0x37, 0xCB, 0x27, 0x21, 0xF2, 0x23, 0x07, 0x34, 0xFC, 0xDD,
82 0x01, 0x3F, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x0C, 0x00, 0xCE, 0xFF,
83 0x56, 0x00, 0xB9, 0xFF, 0xB8, 0xFF, 0xF7, 0x01, 0xE2, 0xF8, 0x8D,
84 0x45, 0x46, 0x12, 0x3C, 0xF7, 0x43, 0x05, 0xDF, 0xFC, 0xAC, 0x01,
85 0x48, 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x24, 0x00, 0x70,
86 0xFF, 0x46, 0x01, 0xC3, 0xFD, 0x6D, 0x03, 0x14, 0xFB, 0xBE, 0x07,
87 0xA6, 0x48, 0xF8, 0xFF, 0x70, 0xFE, 0xAE, 0x01, 0xAA, 0xFE, 0xD9,
88 0x00, 0x9A, 0xFF, 0x19, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF,
89 0xDE, 0x01, 0x5D, 0xFC, 0x74, 0x06, 0x63, 0xF4, 0x23, 0x1C, 0x66,
90 0x40, 0xAA, 0xF4, 0x65, 0x04, 0x44, 0xFE, 0x8B, 0x00, 0xEE, 0xFF,
91 0xF5, 0xFF, 0x04, 0x00, 0xFD, 0xFF, 0x29, 0x00, 0x61, 0xFF, 0x9F,
92 0x01, 0x80, 0xFC, 0xF7, 0x06, 0x7D, 0xF1, 0x5A, 0x31, 0x2C, 0x2F,
93 0x83, 0xF1, 0x13, 0x07, 0x64, 0xFC, 0xB3, 0x01, 0x57, 0xFF, 0x2C,
94 0x00, 0xFD, 0xFF, 0x06, 0x00, 0xED, 0xFF, 0x05, 0x00, 0x5D, 0x00,
95 0x95, 0xFE, 0xE2, 0x03, 0x7F, 0xF5, 0xCC, 0x41, 0xC7, 0x19, 0xFF,
96 0xF4, 0x37, 0x06, 0x75, 0xFC, 0xD6, 0x01, 0x39, 0xFF, 0x35, 0x00,
97 0xFE, 0xFF, 0x1B, 0x00, 0x90, 0xFF, 0xF4, 0x00, 0x72, 0xFE, 0x18,
98 0x02, 0xAA, 0xFD, 0xAB, 0x01, 0xDF, 0x48, 0xCA, 0x05, 0xE1, 0xFB,
99 0x05, 0x03, 0xF7, 0xFD, 0x2E, 0x01, 0x79, 0xFF, 0x21, 0x00, 0x00,
100 0x00, 0xFF, 0xFF, 0x32, 0x00, 0x43, 0xFF, 0xBB, 0x01, 0xBA, 0xFC,
101 0x95, 0x05, 0x83, 0xF6, 0x8C, 0x14, 0x87, 0x44, 0xBB, 0xF7, 0x98,
102 0x02, 0x5A, 0xFF, 0xEE, 0xFF, 0x3C, 0x00, 0xD8, 0xFF, 0x0A, 0x00,
103 0xFD, 0xFF, 0x32, 0x00, 0x44, 0xFF, 0xD3, 0x01, 0x3C, 0xFC, 0x2A,
104 0x07, 0xDC, 0xF1, 0x1A, 0x2A, 0x06, 0x36, 0xBE, 0xF1, 0x8E, 0x06,
105 0xD5, 0xFC, 0x67, 0x01, 0x7F, 0xFF, 0x1E, 0x00, 0xFE, 0xFF, 0x01,
106 0x00, 0x07, 0x00, 0xBE, 0xFF, 0xEA, 0x00, 0xA2, 0xFD, 0x65, 0x05,
107 0x28, 0xF3, 0xDB, 0x3C, 0x78, 0x21, 0x30, 0xF3, 0xDF, 0x06, 0x3A,
108 0xFC, 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x13, 0x00,
109 0xB2, 0xFF, 0x9D, 0x00, 0x27, 0xFF, 0xC3, 0x00, 0x1F, 0x00, 0x76,
110 0xFC, 0xA3, 0x47, 0x60, 0x0C, 0x4A, 0xF9, 0x4E, 0x04, 0x53, 0xFD,
111 0x79, 0x01, 0x5C, 0xFF, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B,
112 0x00, 0x58, 0xFF, 0x82, 0x01, 0x3F, 0xFD, 0x78, 0x04, 0xF2, 0xF8,
113 0x50, 0x0D, 0x5E, 0x47, 0xD5, 0xFB, 0x6F, 0x00, 0x96, 0x00, 0x40,
114 0xFF, 0x91, 0x00, 0xB7, 0xFF, 0x12, 0x00, 0xFD, 0xFF, 0x36, 0x00,
115 0x37, 0xFF, 0xE6, 0x01, 0x36, 0xFC, 0xEF, 0x06, 0xFC, 0xF2, 0x81,
116 0x22, 0x1C, 0x3C, 0xEC, 0xF2, 0x90, 0x05, 0x85, 0xFD, 0xFB, 0x00,
117 0xB6, 0xFF, 0x0A, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x1C, 0x00, 0x85,
118 0xFF, 0x5B, 0x01, 0xE9, 0xFC, 0x73, 0x06, 0xD8, 0xF1, 0xE5, 0x36,
119 0x19, 0x29, 0xF8, 0xF1, 0x29, 0x07, 0x37, 0xFC, 0xD8, 0x01, 0x42,
120 0xFF, 0x33, 0x00, 0xFD, 0xFF, 0x0B, 0x00, 0xD3, 0xFF, 0x47, 0x00,
121 0xD7, 0xFF, 0x82, 0xFF, 0x53, 0x02, 0x39, 0xF8, 0xFD, 0x44, 0x8D,
122 0x13, 0xD3, 0xF6, 0x72, 0x05, 0xCA, 0xFC, 0xB5, 0x01, 0x45, 0xFF,
123 0x31, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x23, 0x00, 0x75, 0xFF, 0x39,
124 0x01, 0xE0, 0xFD, 0x33, 0x03, 0x87, 0xFB, 0xA2, 0x06, 0xCB, 0x48,
125 0xEA, 0x00, 0x01, 0xFE, 0xE9, 0x01, 0x8A, 0xFE, 0xE8, 0x00, 0x95,
126 0xFF, 0x1A, 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x38, 0xFF, 0xDA, 0x01,
127 0x6A, 0xFC, 0x53, 0x06, 0xBA, 0xF4, 0xCE, 0x1A, 0x32, 0x41, 0x1F,
128 0xF5, 0x1D, 0x04, 0x71, 0xFE, 0x71, 0x00, 0xFB, 0xFF, 0xF0, 0xFF,
129 0x05, 0x00, 0xFD, 0xFF, 0x2B, 0x00, 0x5B, 0xFF, 0xAB, 0x01, 0x6F,
130 0xFC, 0x08, 0x07, 0x7E, 0xF1, 0x21, 0x30, 0x67, 0x30, 0x7D, 0xF1,
131 0x05, 0x07, 0x73, 0xFC, 0xA8, 0x01, 0x5C, 0xFF, 0x2A, 0x00, 0xFD,
132 0xFF, 0x05, 0x00, 0xF2, 0xFF, 0xF8, 0xFF, 0x77, 0x00, 0x67, 0xFE,
133 0x2D, 0x04, 0x04, 0xF5, 0x07, 0x41, 0x1B, 0x1B, 0xA6, 0xF4, 0x5A,
134 0x06, 0x67, 0xFC, 0xDB, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFE, 0xFF,
135 0x1A, 0x00, 0x96, 0xFF, 0xE5, 0x00, 0x91, 0xFE, 0xDC, 0x01, 0x1A,
136 0xFE, 0xB3, 0x00, 0xC3, 0x48, 0xE1, 0x06, 0x6E, 0xFB, 0x40, 0x03,
137 0xDA, 0xFD, 0x3C, 0x01, 0x74, 0xFF, 0x23, 0x00, 0x00, 0x00, 0xFF,
138 0xFF, 0x31, 0x00, 0x46, 0xFF, 0xB3, 0x01, 0xCF, 0xFC, 0x67, 0x05,
139 0xEA, 0xF6, 0x44, 0x13, 0x1E, 0x45, 0x5E, 0xF8, 0x3F, 0x02, 0x8E,
140 0xFF, 0xD0, 0xFF, 0x4A, 0x00, 0xD2, 0xFF, 0x0B, 0x00, 0xFD, 0xFF,
141 0x33, 0x00, 0x41, 0xFF, 0xD9, 0x01, 0x36, 0xFC, 0x28, 0x07, 0x01,
142 0xF2, 0xCE, 0x28, 0x23, 0x37, 0xE0, 0xF1, 0x6B, 0x06, 0xEF, 0xFC,
143 0x57, 0x01, 0x87, 0xFF, 0x1B, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x0B,
144 0x00, 0xB4, 0xFF, 0x00, 0x01, 0x7E, 0xFD, 0x9C, 0x05, 0xDC, 0xF2,
145 0xE4, 0x3B, 0xCD, 0x22, 0xEE, 0xF2, 0xF3, 0x06, 0x35, 0xFC, 0xE6,
146 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x11, 0x00, 0xB8, 0xFF,
147 0x8E, 0x00, 0x46, 0xFF, 0x8A, 0x00, 0x86, 0x00, 0xA7, 0xFB, 0x48,
148 0x47, 0x95, 0x0D, 0xD9, 0xF8, 0x84, 0x04, 0x39, 0xFD, 0x85, 0x01,
149 0x57, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x5D,
150 0xFF, 0x76, 0x01, 0x59, 0xFD, 0x42, 0x04, 0x63, 0xF9, 0x1C, 0x0C,
151 0xB6, 0x47, 0xA4, 0xFC, 0x07, 0x00, 0xD0, 0x00, 0x20, 0xFF, 0xA0,
152 0x00, 0xB1, 0xFF, 0x13, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF,
153 0xE6, 0x01, 0x3B, 0xFC, 0xDA, 0x06, 0x3F, 0xF3, 0x2C, 0x21, 0x11,
154 0x3D, 0x3A, 0xF3, 0x58, 0x05, 0xAA, 0xFD, 0xE5, 0x00, 0xC1, 0xFF,
155 0x06, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x1F, 0x00, 0x7D, 0xFF, 0x6B,
156 0x01, 0xCF, 0xFC, 0x96, 0x06, 0xB7, 0xF1, 0xC6, 0x35, 0x64, 0x2A,
157 0xD4, 0xF1, 0x2B, 0x07, 0x3D, 0xFC, 0xD2, 0x01, 0x45, 0xFF, 0x32,
158 0x00, 0xFD, 0xFF, 0x0A, 0x00, 0xD9, 0xFF, 0x39, 0x00, 0xF4, 0xFF,
159 0x4E, 0xFF, 0xAC, 0x02, 0x98, 0xF7, 0x65, 0x44, 0xD6, 0x14, 0x6C,
160 0xF6, 0x9F, 0x05, 0xB6, 0xFC, 0xBD, 0x01, 0x42, 0xFF, 0x32, 0x00,
161 0xFF, 0xFF, 0x00, 0x00, 0x21, 0x00, 0x7A, 0xFF, 0x2B, 0x01, 0xFE,
162 0xFD, 0xF8, 0x02, 0xFB, 0xFB, 0x8D, 0x05, 0xE5, 0x48, 0xE3, 0x01,
163 0x91, 0xFD, 0x25, 0x02, 0x6B, 0xFE, 0xF7, 0x00, 0x8F, 0xFF, 0x1C,
164 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xD5, 0x01, 0x78, 0xFC,
165 0x2F, 0x06, 0x13, 0xF5, 0x7C, 0x19, 0xF7, 0x41, 0x9B, 0xF5, 0xD1,
166 0x03, 0x9F, 0xFE, 0x57, 0x00, 0x08, 0x00, 0xEC, 0xFF, 0x06, 0x00,
167 0xFD, 0xFF, 0x2D, 0x00, 0x55, 0xFF, 0xB5, 0x01, 0x61, 0xFC, 0x16,
168 0x07, 0x85, 0xF1, 0xE6, 0x2E, 0x9E, 0x31, 0x7D, 0xF1, 0xF3, 0x06,
169 0x84, 0xFC, 0x9D, 0x01, 0x63, 0xFF, 0x28, 0x00, 0xFD, 0xFF, 0x04,
170 0x00, 0xF6, 0xFF, 0xEB, 0xFF, 0x91, 0x00, 0x3B, 0xFE, 0x75, 0x04,
171 0x92, 0xF4, 0x36, 0x40, 0x6E, 0x1C, 0x50, 0xF4, 0x7B, 0x06, 0x5B,
172 0xFC, 0xDF, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x18, 0x00,
173 0x9C, 0xFF, 0xD6, 0x00, 0xB1, 0xFE, 0xA1, 0x01, 0x89, 0xFE, 0xC3,
174 0xFF, 0x9C, 0x48, 0xFD, 0x07, 0xFA, 0xFA, 0x7A, 0x03, 0xBC, 0xFD,
175 0x49, 0x01, 0x6E, 0xFF, 0x24, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x30,
176 0x00, 0x49, 0xFF, 0xAA, 0x01, 0xE4, 0xFC, 0x38, 0x05, 0x54, 0xF7,
177 0xFE, 0x11, 0xAA, 0x45, 0x09, 0xF9, 0xE2, 0x01, 0xC4, 0xFF, 0xB3,
178 0xFF, 0x59, 0x00, 0xCD, 0xFF, 0x0D, 0x00, 0xFD, 0xFF, 0x34, 0x00,
179 0x3E, 0xFF, 0xDE, 0x01, 0x33, 0xFC, 0x22, 0x07, 0x2B, 0xF2, 0x80,
180 0x27, 0x3B, 0x38, 0x0A, 0xF2, 0x44, 0x06, 0x0B, 0xFD, 0x45, 0x01,
181 0x90, 0xFF, 0x18, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x0F, 0x00, 0xA9,
182 0xFF, 0x15, 0x01, 0x5B, 0xFD, 0xD0, 0x05, 0x97, 0xF2, 0xE6, 0x3A,
183 0x21, 0x24, 0xB1, 0xF2, 0x04, 0x07, 0x33, 0xFC, 0xE5, 0x01, 0x39,
184 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x10, 0x00, 0xBE, 0xFF, 0x7F, 0x00,
185 0x65, 0xFF, 0x51, 0x00, 0xEB, 0x00, 0xE1, 0xFA, 0xE1, 0x46, 0xCD,
186 0x0E, 0x6A, 0xF8, 0xB8, 0x04, 0x20, 0xFD, 0x90, 0x01, 0x53, 0xFF,
187 0x2D, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x28, 0x00, 0x62, 0xFF, 0x6A,
188 0x01, 0x74, 0xFD, 0x0A, 0x04, 0xD5, 0xF9, 0xED, 0x0A, 0x03, 0x48,
189 0x7C, 0xFD, 0x9E, 0xFF, 0x0A, 0x01, 0x01, 0xFF, 0xAF, 0x00, 0xAB,
190 0xFF, 0x14, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE5, 0x01,
191 0x42, 0xFC, 0xC3, 0x06, 0x87, 0xF3, 0xD7, 0x1F, 0xFE, 0x3D, 0x91,
192 0xF3, 0x1D, 0x05, 0xD1, 0xFD, 0xCE, 0x00, 0xCC, 0xFF, 0x02, 0x00,
193 0x02, 0x00, 0xFE, 0xFF, 0x22, 0x00, 0x75, 0xFF, 0x7A, 0x01, 0xB8,
194 0xFC, 0xB4, 0x06, 0x9E, 0xF1, 0xA2, 0x34, 0xAD, 0x2B, 0xB6, 0xF1,
195 0x29, 0x07, 0x45, 0xFC, 0xCB, 0x01, 0x49, 0xFF, 0x31, 0x00, 0xFD,
196 0xFF, 0x09, 0x00, 0xDE, 0xFF, 0x2B, 0x00, 0x11, 0x00, 0x1B, 0xFF,
197 0x02, 0x03, 0xFE, 0xF6, 0xC3, 0x43, 0x22, 0x16, 0x07, 0xF6, 0xCA,
198 0x05, 0xA3, 0xFC, 0xC5, 0x01, 0x3F, 0xFF, 0x33, 0x00, 0xFF, 0xFF,
199 0x00, 0x00, 0x20, 0x00, 0x80, 0xFF, 0x1C, 0x01, 0x1C, 0xFE, 0xBD,
200 0x02, 0x6E, 0xFC, 0x7D, 0x04, 0xF3, 0x48, 0xE2, 0x02, 0x1F, 0xFD,
201 0x60, 0x02, 0x4C, 0xFE, 0x06, 0x01, 0x89, 0xFF, 0x1D, 0x00, 0xFE,
202 0xFF, 0x34, 0x00, 0x3C, 0xFF, 0xCF, 0x01, 0x88, 0xFC, 0x09, 0x06,
203 0x71, 0xF5, 0x2B, 0x18, 0xB2, 0x42, 0x20, 0xF6, 0x83, 0x03, 0xCF,
204 0xFE, 0x3C, 0x00, 0x15, 0x00, 0xE6, 0xFF, 0x07, 0x00, 0xFD, 0xFF,
205 0x2E, 0x00, 0x50, 0xFF, 0xBF, 0x01, 0x54, 0xFC, 0x20, 0x07, 0x94,
206 0xF1, 0xA6, 0x2D, 0xD0, 0x32, 0x85, 0xF1, 0xDD, 0x06, 0x96, 0xFC,
207 0x90, 0x01, 0x69, 0xFF, 0x26, 0x00, 0xFD, 0xFF, 0x03, 0x00, 0xFB,
208 0xFF, 0xDF, 0xFF, 0xA9, 0x00, 0x10, 0xFE, 0xB9, 0x04, 0x27, 0xF4,
209 0x5E, 0x3F, 0xC3, 0x1D, 0xFE, 0xF3, 0x99, 0x06, 0x50, 0xFC, 0xE2,
210 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x17, 0x00, 0xA2, 0xFF,
211 0xC7, 0x00, 0xD0, 0xFE, 0x65, 0x01, 0xF6, 0xFE, 0xD9, 0xFE, 0x6A,
212 0x48, 0x1F, 0x09, 0x87, 0xFA, 0xB3, 0x03, 0xA0, 0xFD, 0x56, 0x01,
213 0x69, 0xFF, 0x26, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2F, 0x00, 0x4D,
214 0xFF, 0xA0, 0x01, 0xFB, 0xFC, 0x07, 0x05, 0xBF, 0xF7, 0xBB, 0x10,
215 0x2B, 0x46, 0xBB, 0xF9, 0x83, 0x01, 0xFA, 0xFF, 0x95, 0xFF, 0x68,
216 0x00, 0xC7, 0xFF, 0x0E, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3C, 0xFF,
217 0xE1, 0x01, 0x31, 0xFC, 0x19, 0x07, 0x5B, 0xF2, 0x30, 0x26, 0x4B,
218 0x39, 0x3B, 0xF2, 0x1A, 0x06, 0x29, 0xFD, 0x33, 0x01, 0x99, 0xFF,
219 0x15, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x13, 0x00, 0x9F, 0xFF, 0x28,
220 0x01, 0x3A, 0xFD, 0x00, 0x06, 0x5A, 0xF2, 0xDF, 0x39, 0x73, 0x25,
221 0x79, 0xF2, 0x12, 0x07, 0x31, 0xFC, 0xE3, 0x01, 0x3B, 0xFF, 0x35,
222 0x00, 0xFD, 0xFF, 0x0F, 0x00, 0xC4, 0xFF, 0x70, 0x00, 0x84, 0xFF,
223 0x19, 0x00, 0x4D, 0x01, 0x22, 0xFA, 0x70, 0x46, 0x0A, 0x10, 0xFC,
224 0xF7, 0xEB, 0x04, 0x08, 0xFD, 0x9A, 0x01, 0x4F, 0xFF, 0x2E, 0x00,
225 0xFF, 0xFF, 0x00, 0x00, 0x27, 0x00, 0x66, 0xFF, 0x5E, 0x01, 0x90,
226 0xFD, 0xD2, 0x03, 0x47, 0xFA, 0xC3, 0x09, 0x48, 0x48, 0x5A, 0xFE,
227 0x33, 0xFF, 0x45, 0x01, 0xE2, 0xFE, 0xBE, 0x00, 0xA5, 0xFF, 0x16,
228 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE3, 0x01, 0x4B, 0xFC,
229 0xA9, 0x06, 0xD2, 0xF3, 0x81, 0x1E, 0xE4, 0x3E, 0xEF, 0xF3, 0xDE,
230 0x04, 0xF9, 0xFD, 0xB7, 0x00, 0xD8, 0xFF, 0xFD, 0xFF, 0x03, 0x00,
231 0xFD, 0xFF, 0x24, 0x00, 0x6D, 0xFF, 0x88, 0x01, 0xA2, 0xFC, 0xD0,
232 0x06, 0x8C, 0xF1, 0x78, 0x33, 0xF2, 0x2C, 0x9E, 0xF1, 0x24, 0x07,
233 0x4E, 0xFC, 0xC3, 0x01, 0x4E, 0xFF, 0x2F, 0x00, 0xFD, 0xFF, 0x08,
234 0x00, 0xE4, 0xFF, 0x1D, 0x00, 0x2D, 0x00, 0xEA, 0xFE, 0x56, 0x03,
235 0x6D, 0xF6, 0x17, 0x43, 0x70, 0x17, 0xA6, 0xF5, 0xF3, 0x05, 0x91,
236 0xFC, 0xCC, 0x01, 0x3D, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0x1E, 0x00,
237 0x86, 0xFF, 0x0E, 0x01, 0x3B, 0xFE, 0x82, 0x02, 0xE0, 0xFC, 0x73,
238 0x03, 0xF6, 0x48, 0xE9, 0x03, 0xAD, 0xFC, 0x9C, 0x02, 0x2D, 0xFE,
239 0x14, 0x01, 0x83, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x33,
240 0x00, 0x3E, 0xFF, 0xC9, 0x01, 0x99, 0xFC, 0xE1, 0x05, 0xD1, 0xF5,
241 0xDC, 0x16, 0x65, 0x43, 0xAD, 0xF6, 0x31, 0x03, 0x00, 0xFF, 0x20,
242 0x00, 0x23, 0x00, 0xE1, 0xFF, 0x08, 0x00, 0xFD, 0xFF, 0x30, 0x00,
243 0x4C, 0xFF, 0xC7, 0x01, 0x4A, 0xFC, 0x27, 0x07, 0xA8, 0xF1, 0x62,
244 0x2C, 0xFD, 0x33, 0x93, 0xF1, 0xC4, 0x06, 0xAB, 0xFC, 0x82, 0x01,
245 0x71, 0xFF, 0x23, 0x00, 0xFE, 0xFF, 0x02, 0x00, 0xFF, 0xFF, 0xD3,
246 0xFF, 0xC1, 0x00, 0xE7, 0xFD, 0xFA, 0x04, 0xC4, 0xF3, 0x7E, 0x3E,
247 0x19, 0x1F, 0xB0, 0xF3, 0xB5, 0x06, 0x47, 0xFC, 0xE4, 0x01, 0x36,
248 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x15, 0x00, 0xA8, 0xFF, 0xB8, 0x00,
249 0xF0, 0xFE, 0x2B, 0x01, 0x63, 0xFF, 0xF6, 0xFD, 0x2C, 0x48, 0x47,
250 0x0A, 0x14, 0xFA, 0xEB, 0x03, 0x84, 0xFD, 0x63, 0x01, 0x64, 0xFF,
251 0x27, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2D, 0x00, 0x51, 0xFF, 0x96,
252 0x01, 0x13, 0xFD, 0xD5, 0x04, 0x2C, 0xF8, 0x7D, 0x0F, 0xA3, 0x46,
253 0x76, 0xFA, 0x22, 0x01, 0x32, 0x00, 0x76, 0xFF, 0x76, 0x00, 0xC1,
254 0xFF, 0x0F, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x3A, 0xFF, 0xE4, 0x01,
255 0x32, 0xFC, 0x0C, 0x07, 0x91, 0xF2, 0xDD, 0x24, 0x54, 0x3A, 0x74,
256 0xF2, 0xEB, 0x05, 0x49, 0xFD, 0x20, 0x01, 0xA3, 0xFF, 0x11, 0x00,
257 0x00, 0x00, 0xFF, 0xFF, 0x16, 0x00, 0x95, 0xFF, 0x3B, 0x01, 0x1B,
258 0xFD, 0x2D, 0x06, 0x24, 0xF2, 0xD3, 0x38, 0xC6, 0x26, 0x45, 0xF2,
259 0x1D, 0x07, 0x32, 0xFC, 0xE0, 0x01, 0x3D, 0xFF, 0x35, 0x00, 0xFD,
260 0xFF, 0x0D, 0x00, 0xC9, 0xFF, 0x61, 0x00, 0xA2, 0xFF, 0xE2, 0xFF,
261 0xAE, 0x01, 0x6B, 0xF9, 0xF2, 0x45, 0x4A, 0x11, 0x8F, 0xF7, 0x1D,
262 0x05, 0xF1, 0xFC, 0xA4, 0x01, 0x4B, 0xFF, 0x2F, 0x00, 0xFF, 0xFF,
263 0x00, 0x00, 0x25, 0x00, 0x6C, 0xFF, 0x51, 0x01, 0xAC, 0xFD, 0x9A,
264 0x03, 0xBA, 0xFA, 0x9E, 0x08, 0x81, 0x48, 0x40, 0xFF, 0xC6, 0xFE,
265 0x80, 0x01, 0xC2, 0xFE, 0xCE, 0x00, 0x9F, 0xFF, 0x17, 0x00, 0xFE,
266 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE1, 0x01, 0x55, 0xFC, 0x8C, 0x06,
267 0x22, 0xF4, 0x2C, 0x1D, 0xC0, 0x3F, 0x55, 0xF4, 0x9B, 0x04, 0x23,
268 0xFE, 0x9F, 0x00, 0xE4, 0xFF, 0xF9, 0xFF, 0x04, 0x00, 0xFD, 0xFF,
269 0x27, 0x00, 0x66, 0xFF, 0x96, 0x01, 0x8E, 0xFC, 0xE7, 0x06, 0x81,
270 0xF1, 0x48, 0x32, 0x34, 0x2E, 0x8D, 0xF1, 0x1C, 0x07, 0x5A, 0xFC,
271 0xBB, 0x01, 0x53, 0xFF, 0x2E, 0x00, 0xFD, 0xFF, 0x07, 0x00, 0xE9,
272 0xFF, 0x0F, 0x00, 0x48, 0x00, 0xB9, 0xFE, 0xA6, 0x03, 0xE4, 0xF5,
273 0x60, 0x42, 0xC1, 0x18, 0x47, 0xF5, 0x1A, 0x06, 0x81, 0xFC, 0xD2,
274 0x01, 0x3B, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1C, 0x00, 0x8B, 0xFF,
275 0xFF, 0x00, 0x5A, 0xFE, 0x46, 0x02, 0x52, 0xFD, 0x70, 0x02, 0xED,
276 0x48, 0xF5, 0x04, 0x3B, 0xFC, 0xD7, 0x02, 0x0F, 0xFE, 0x23, 0x01,
277 0x7E, 0xFF, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0x40,
278 0xFF, 0xC1, 0x01, 0xAB, 0xFC, 0xB7, 0x05, 0x34, 0xF6, 0x8E, 0x15,
279 0x0B, 0x44, 0x42, 0xF7, 0xDC, 0x02, 0x32, 0xFF, 0x04, 0x00, 0x31,
280 0x00, 0xDC, 0xFF, 0x09, 0x00, 0xFD, 0xFF, 0x31, 0x00, 0x47, 0xFF,
281 0xCE, 0x01, 0x41, 0xFC, 0x2A, 0x07, 0xC2, 0xF1, 0x1B, 0x2B, 0x25,
282 0x35, 0xA8, 0xF1, 0xA7, 0x06, 0xC2, 0xFC, 0x74, 0x01, 0x78, 0xFF,
283 0x20, 0x00, 0xFE, 0xFF, 0x02, 0x00, 0x04, 0x00, 0xC7, 0xFF, 0xD9,
284 0x00, 0xBF, 0xFD, 0x38, 0x05, 0x69, 0xF3, 0x96, 0x3D, 0x6F, 0x20,
285 0x66, 0xF3, 0xCE, 0x06, 0x3F, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36,
286 0x00, 0xFD, 0xFF, 0x14, 0x00, 0xAE, 0xFF, 0xA9, 0x00, 0x0F, 0xFF,
287 0xF0, 0x00, 0xCD, 0xFF, 0x1B, 0xFD, 0xE4, 0x47, 0x73, 0x0B, 0xA2,
288 0xF9, 0x23, 0x04, 0x68, 0xFD, 0x70, 0x01, 0x5F, 0xFF, 0x29, 0x00,
289 0x00, 0x00, 0xFF, 0xFF, 0x2C, 0x00, 0x55, 0xFF, 0x8B, 0x01, 0x2B,
290 0xFD, 0xA1, 0x04, 0x9B, 0xF8, 0x42, 0x0E, 0x0F, 0x47, 0x38, 0xFB,
291 0xBE, 0x00, 0x6A, 0x00, 0x58, 0xFF, 0x85, 0x00, 0xBB, 0xFF, 0x10,
292 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xE6, 0x01, 0x34, 0xFC,
293 0xFD, 0x06, 0xCB, 0xF2, 0x8A, 0x23, 0x58, 0x3B, 0xB4, 0xF2, 0xBA,
294 0x05, 0x6A, 0xFD, 0x0B, 0x01, 0xAE, 0xFF, 0x0D, 0x00, 0x00, 0x00,
295 0xFF, 0xFF, 0x19, 0x00, 0x8C, 0xFF, 0x4D, 0x01, 0xFE, 0xFC, 0x56,
296 0x06, 0xF7, 0xF1, 0xBF, 0x37, 0x15, 0x28, 0x18, 0xF2, 0x25, 0x07,
297 0x34, 0xFC, 0xDC, 0x01, 0x3F, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x0C,
298 0x00, 0xCF, 0xFF, 0x52, 0x00, 0xC0, 0xFF, 0xAC, 0xFF, 0x0C, 0x02,
299 0xBC, 0xF8, 0x6D, 0x45, 0x8E, 0x12, 0x24, 0xF7, 0x4D, 0x05, 0xDB,
300 0xFC, 0xAE, 0x01, 0x48, 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0x00, 0x00,
301 0x24, 0x00, 0x71, 0xFF, 0x43, 0x01, 0xC9, 0xFD, 0x60, 0x03, 0x2E,
302 0xFB, 0x7E, 0x07, 0xAF, 0x48, 0x2D, 0x00, 0x58, 0xFE, 0xBB, 0x01,
303 0xA3, 0xFE, 0xDD, 0x00, 0x99, 0xFF, 0x19, 0x00, 0xFE, 0xFF, 0x36,
304 0x00, 0x37, 0xFF, 0xDD, 0x01, 0x60, 0xFC, 0x6D, 0x06, 0x76, 0xF4,
305 0xD8, 0x1B, 0x95, 0x40, 0xC3, 0xF4, 0x56, 0x04, 0x4E, 0xFE, 0x85,
306 0x00, 0xF1, 0xFF, 0xF4, 0xFF, 0x04, 0x00, 0xFD, 0xFF, 0x29, 0x00,
307 0x60, 0xFF, 0xA2, 0x01, 0x7C, 0xFC, 0xFB, 0x06, 0x7C, 0xF1, 0x15,
308 0x31, 0x73, 0x2F, 0x81, 0xF1, 0x10, 0x07, 0x67, 0xFC, 0xB1, 0x01,
309 0x58, 0xFF, 0x2C, 0x00, 0xFD, 0xFF, 0x06, 0x00, 0xEE, 0xFF, 0x02,
310 0x00, 0x63, 0x00, 0x8A, 0xFE, 0xF3, 0x03, 0x63, 0xF5, 0xA1, 0x41,
311 0x12, 0x1A, 0xEB, 0xF4, 0x3F, 0x06, 0x72, 0xFC, 0xD7, 0x01, 0x39,
312 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1B, 0x00, 0x91, 0xFF, 0xF1, 0x00,
313 0x79, 0xFE, 0x0A, 0x02, 0xC3, 0xFD, 0x73, 0x01, 0xDB, 0x48, 0x07,
314 0x06, 0xC7, 0xFB, 0x12, 0x03, 0xF1, 0xFD, 0x31, 0x01, 0x78, 0xFF,
315 0x22, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x32, 0x00, 0x43, 0xFF, 0xBA,
316 0x01, 0xBF, 0xFC, 0x8B, 0x05, 0x99, 0xF6, 0x43, 0x14, 0xA9, 0x44,
317 0xDE, 0xF7, 0x85, 0x02, 0x65, 0xFF, 0xE7, 0xFF, 0x3F, 0x00, 0xD6,
318 0xFF, 0x0A, 0x00, 0xFD, 0xFF, 0x32, 0x00, 0x44, 0xFF, 0xD5, 0x01,
319 0x3A, 0xFC, 0x2A, 0x07, 0xE3, 0xF1, 0xD1, 0x29, 0x46, 0x36, 0xC5,
320 0xF1, 0x87, 0x06, 0xDA, 0xFC, 0x64, 0x01, 0x80, 0xFF, 0x1E, 0x00,
321 0xFE, 0xFF, 0x01, 0x00, 0x08, 0x00, 0xBC, 0xFF, 0xEF, 0x00, 0x9A,
322 0xFD, 0x72, 0x05, 0x16, 0xF3, 0xA5, 0x3C, 0xC4, 0x21, 0x21, 0xF3,
323 0xE4, 0x06, 0x39, 0xFC, 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD,
324 0xFF, 0x12, 0x00, 0xB3, 0xFF, 0x99, 0x00, 0x2E, 0xFF, 0xB6, 0x00,
325 0x36, 0x00, 0x47, 0xFC, 0x90, 0x47, 0xA4, 0x0C, 0x31, 0xF9, 0x5A,
326 0x04, 0x4E, 0xFD, 0x7C, 0x01, 0x5B, 0xFF, 0x2A, 0x00, 0x00, 0x00,
327 0x00, 0x00, 0x2B, 0x00, 0x59, 0xFF, 0x80, 0x01, 0x45, 0xFD, 0x6C,
328 0x04, 0x0B, 0xF9, 0x0B, 0x0D, 0x73, 0x47, 0x02, 0xFC, 0x58, 0x00,
329 0xA3, 0x00, 0x39, 0xFF, 0x94, 0x00, 0xB5, 0xFF, 0x12, 0x00, 0xFD,
330 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x37, 0xFC, 0xEB, 0x06,
331 0x0B, 0xF3, 0x35, 0x22, 0x52, 0x3C, 0xFD, 0xF2, 0x84, 0x05, 0x8D,
332 0xFD, 0xF6, 0x00, 0xB8, 0xFF, 0x09, 0x00, 0x01, 0x00, 0xFE, 0xFF,
333 0x1D, 0x00, 0x83, 0xFF, 0x5E, 0x01, 0xE3, 0xFC, 0x7B, 0x06, 0xD0,
334 0xF1, 0xA5, 0x36, 0x62, 0x29, 0xEF, 0xF1, 0x29, 0x07, 0x39, 0xFC,
335 0xD7, 0x01, 0x42, 0xFF, 0x33, 0x00, 0xFD, 0xFF, 0x0B, 0x00, 0xD5,
336 0xFF, 0x44, 0x00, 0xDD, 0xFF, 0x77, 0xFF, 0x67, 0x02, 0x14, 0xF8,
337 0xDC, 0x44, 0xD5, 0x13, 0xBC, 0xF6, 0x7C, 0x05, 0xC5, 0xFC, 0xB7,
338 0x01, 0x44, 0xFF, 0x31, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x22, 0x00,
339 0x76, 0xFF, 0x35, 0x01, 0xE7, 0xFD, 0x26, 0x03, 0xA1, 0xFB, 0x64,
340 0x06, 0xD2, 0x48, 0x21, 0x01, 0xE8, 0xFD, 0xF7, 0x01, 0x83, 0xFE,
341 0xEC, 0x00, 0x93, 0xFF, 0x1A, 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x39,
342 0xFF, 0xD9, 0x01, 0x6D, 0xFC, 0x4B, 0x06, 0xCD, 0xF4, 0x83, 0x1A,
343 0x5F, 0x41, 0x3A, 0xF5, 0x0C, 0x04, 0x7B, 0xFE, 0x6C, 0x00, 0xFE,
344 0xFF, 0xEF, 0xFF, 0x05, 0x00, 0xFD, 0xFF, 0x2B, 0x00, 0x5A, 0xFF,
345 0xAD, 0x01, 0x6C, 0xFC, 0x0C, 0x07, 0x7F, 0xF1, 0xDC, 0x2F, 0xAD,
346 0x30, 0x7D, 0xF1, 0x01, 0x07, 0x76, 0xFC, 0xA6, 0x01, 0x5E, 0xFF,
347 0x2A, 0x00, 0xFD, 0xFF, 0x05, 0x00, 0xF3, 0xFF, 0xF5, 0xFF, 0x7D,
348 0x00, 0x5D, 0xFE, 0x3E, 0x04, 0xEA, 0xF4, 0xD9, 0x40, 0x66, 0x1B,
349 0x93, 0xF4, 0x62, 0x06, 0x64, 0xFC, 0xDC, 0x01, 0x38, 0xFF, 0x36,
350 0x00, 0xFE, 0xFF, 0x19, 0x00, 0x97, 0xFF, 0xE2, 0x00, 0x98, 0xFE,
351 0xCF, 0x01, 0x33, 0xFE, 0x7D, 0x00, 0xBB, 0x48, 0x1F, 0x07, 0x54,
352 0xFB, 0x4C, 0x03, 0xD3, 0xFD, 0x3F, 0x01, 0x73, 0xFF, 0x23, 0x00,
353 0x00, 0x00, 0xFF, 0xFF, 0x31, 0x00, 0x46, 0xFF, 0xB1, 0x01, 0xD3,
354 0xFC, 0x5D, 0x05, 0x01, 0xF7, 0xFB, 0x12, 0x3F, 0x45, 0x83, 0xF8,
355 0x2A, 0x02, 0x9A, 0xFF, 0xCA, 0xFF, 0x4E, 0x00, 0xD1, 0xFF, 0x0C,
356 0x00, 0xFD, 0xFF, 0x34, 0x00, 0x40, 0xFF, 0xDA, 0x01, 0x35, 0xFC,
357 0x27, 0x07, 0x09, 0xF2, 0x85, 0x28, 0x63, 0x37, 0xE9, 0xF1, 0x63,
358 0x06, 0xF5, 0xFC, 0x53, 0x01, 0x89, 0xFF, 0x1A, 0x00, 0xFE, 0xFF,
359 0x00, 0x00, 0x0C, 0x00, 0xB1, 0xFF, 0x04, 0x01, 0x76, 0xFD, 0xA8,
360 0x05, 0xCC, 0xF2, 0xAB, 0x3B, 0x18, 0x23, 0xE0, 0xF2, 0xF7, 0x06,
361 0x35, 0xFC, 0xE6, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x11,
362 0x00, 0xB9, 0xFF, 0x8A, 0x00, 0x4D, 0xFF, 0x7D, 0x00, 0x9C, 0x00,
363 0x7B, 0xFB, 0x31, 0x47, 0xD9, 0x0D, 0xC0, 0xF8, 0x8F, 0x04, 0x34,
364 0xFD, 0x87, 0x01, 0x56, 0xFF, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00,
365 0x29, 0x00, 0x5E, 0xFF, 0x74, 0x01, 0x5F, 0xFD, 0x35, 0x04, 0x7C,
366 0xF9, 0xD8, 0x0B, 0xC9, 0x47, 0xD4, 0xFC, 0xF0, 0xFF, 0xDD, 0x00,
367 0x19, 0xFF, 0xA4, 0x00, 0xAF, 0xFF, 0x13, 0x00, 0xFD, 0xFF, 0x36,
368 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3D, 0xFC, 0xD5, 0x06, 0x4F, 0xF3,
369 0xE0, 0x20, 0x45, 0x3D, 0x4D, 0xF3, 0x4B, 0x05, 0xB3, 0xFD, 0xE0,
370 0x00, 0xC3, 0xFF, 0x05, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x20, 0x00,
371 0x7B, 0xFF, 0x6E, 0x01, 0xCA, 0xFC, 0x9D, 0x06, 0xB1, 0xF1, 0x86,
372 0x35, 0xAE, 0x2A, 0xCD, 0xF1, 0x2B, 0x07, 0x3F, 0xFC, 0xD1, 0x01,
373 0x46, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0x0A, 0x00, 0xDA, 0xFF, 0x36,
374 0x00, 0xFA, 0xFF, 0x43, 0xFF, 0xBF, 0x02, 0x75, 0xF7, 0x42, 0x44,
375 0x20, 0x15, 0x55, 0xF6, 0xA9, 0x05, 0xB2, 0xFC, 0xBF, 0x01, 0x41,
376 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x21, 0x00, 0x7C, 0xFF,
377 0x27, 0x01, 0x05, 0xFE, 0xEB, 0x02, 0x14, 0xFC, 0x50, 0x05, 0xEA,
378 0x48, 0x1B, 0x02, 0x78, 0xFD, 0x32, 0x02, 0x64, 0xFE, 0xFA, 0x00,
379 0x8D, 0xFF, 0x1C, 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xD4,
380 0x01, 0x7C, 0xFC, 0x27, 0x06, 0x28, 0xF5, 0x31, 0x19, 0x21, 0x42,
381 0xB8, 0xF5, 0xC0, 0x03, 0xAA, 0xFE, 0x51, 0x00, 0x0B, 0x00, 0xEA,
382 0xFF, 0x06, 0x00, 0xFD, 0xFF, 0x2D, 0x00, 0x54, 0xFF, 0xB7, 0x01,
383 0x5E, 0xFC, 0x19, 0x07, 0x88, 0xF1, 0x9F, 0x2E, 0xE3, 0x31, 0x7E,
384 0xF1, 0xEE, 0x06, 0x88, 0xFC, 0x9A, 0x01, 0x64, 0xFF, 0x28, 0x00,
385 0xFD, 0xFF, 0x04, 0x00, 0xF7, 0xFF, 0xE8, 0xFF, 0x96, 0x00, 0x31,
386 0xFE, 0x84, 0x04, 0x79, 0xF4, 0x07, 0x40, 0xBA, 0x1C, 0x3E, 0xF4,
387 0x82, 0x06, 0x58, 0xFC, 0xE0, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE,
388 0xFF, 0x18, 0x00, 0x9D, 0xFF, 0xD3, 0x00, 0xB8, 0xFE, 0x93, 0x01,
389 0xA1, 0xFE, 0x8E, 0xFF, 0x92, 0x48, 0x3D, 0x08, 0xE1, 0xFA, 0x86,
390 0x03, 0xB6, 0xFD, 0x4C, 0x01, 0x6D, 0xFF, 0x25, 0x00, 0x00, 0x00,
391 0xFF, 0xFF, 0x30, 0x00, 0x4A, 0xFF, 0xA8, 0x01, 0xE9, 0xFC, 0x2D,
392 0x05, 0x6B, 0xF7, 0xB6, 0x11, 0xC8, 0x45, 0x30, 0xF9, 0xCD, 0x01,
393 0xD0, 0xFF, 0xAC, 0xFF, 0x5C, 0x00, 0xCB, 0xFF, 0x0D, 0x00, 0xFD,
394 0xFF, 0x34, 0x00, 0x3E, 0xFF, 0xDF, 0x01, 0x33, 0xFC, 0x20, 0x07,
395 0x35, 0xF2, 0x36, 0x27, 0x78, 0x38, 0x14, 0xF2, 0x3B, 0x06, 0x11,
396 0xFD, 0x41, 0x01, 0x92, 0xFF, 0x17, 0x00, 0xFF, 0xFF, 0x00, 0x00,
397 0x10, 0x00, 0xA7, 0xFF, 0x19, 0x01, 0x53, 0xFD, 0xDB, 0x05, 0x88,
398 0xF2, 0xAD, 0x3A, 0x6D, 0x24, 0xA4, 0xF2, 0x08, 0x07, 0x32, 0xFC,
399 0xE5, 0x01, 0x39, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x10, 0x00, 0xBF,
400 0xFF, 0x7B, 0x00, 0x6C, 0xFF, 0x44, 0x00, 0x01, 0x01, 0xB6, 0xFA,
401 0xC8, 0x46, 0x13, 0x0F, 0x51, 0xF8, 0xC4, 0x04, 0x1B, 0xFD, 0x92,
402 0x01, 0x52, 0xFF, 0x2D, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x28, 0x00,
403 0x63, 0xFF, 0x67, 0x01, 0x7A, 0xFD, 0xFE, 0x03, 0xEE, 0xF9, 0xAA,
404 0x0A, 0x16, 0x48, 0xAC, 0xFD, 0x86, 0xFF, 0x17, 0x01, 0xFA, 0xFE,
405 0xB3, 0x00, 0xAA, 0xFF, 0x15, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36,
406 0xFF, 0xE5, 0x01, 0x44, 0xFC, 0xBD, 0x06, 0x97, 0xF3, 0x8A, 0x1F,
407 0x31, 0x3E, 0xA5, 0xF3, 0x0F, 0x05, 0xDA, 0xFD, 0xC9, 0x00, 0xCF,
408 0xFF, 0x01, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x22, 0x00, 0x73, 0xFF,
409 0x7D, 0x01, 0xB3, 0xFC, 0xBB, 0x06, 0x9A, 0xF1, 0x60, 0x34, 0xF5,
410 0x2B, 0xB0, 0xF1, 0x28, 0x07, 0x47, 0xFC, 0xCA, 0x01, 0x4A, 0xFF,
411 0x30, 0x00, 0xFD, 0xFF, 0x09, 0x00, 0xDF, 0xFF, 0x28, 0x00, 0x17,
412 0x00, 0x10, 0xFF, 0x15, 0x03, 0xDD, 0xF6, 0x9E, 0x43, 0x6C, 0x16,
413 0xF1, 0xF5, 0xD3, 0x05, 0x9F, 0xFC, 0xC6, 0x01, 0x3F, 0xFF, 0x33,
414 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x1F, 0x00, 0x81, 0xFF, 0x19, 0x01,
415 0x23, 0xFE, 0xB0, 0x02, 0x87, 0xFC, 0x41, 0x04, 0xF4, 0x48, 0x1C,
416 0x03, 0x06, 0xFD, 0x6E, 0x02, 0x45, 0xFE, 0x09, 0x01, 0x88, 0xFF,
417 0x1D, 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3C, 0xFF, 0xCE, 0x01, 0x8C,
418 0xFC, 0x00, 0x06, 0x86, 0xF5, 0xE0, 0x17, 0xDB, 0x42, 0x3F, 0xF6,
419 0x71, 0x03, 0xD9, 0xFE, 0x36, 0x00, 0x18, 0x00, 0xE5, 0xFF, 0x07,
420 0x00, 0xFD, 0xFF, 0x2F, 0x00, 0x4F, 0xFF, 0xC1, 0x01, 0x52, 0xFC,
421 0x22, 0x07, 0x98, 0xF1, 0x5E, 0x2D, 0x13, 0x33, 0x87, 0xF1, 0xD8,
422 0x06, 0x9B, 0xFC, 0x8D, 0x01, 0x6B, 0xFF, 0x25, 0x00, 0xFD, 0xFF,
423 0x03, 0x00, 0xFC, 0xFF, 0xDC, 0xFF, 0xAF, 0x00, 0x07, 0xFE, 0xC8,
424 0x04, 0x10, 0xF4, 0x2D, 0x3F, 0x0F, 0x1E, 0xED, 0xF3, 0xA0, 0x06,
425 0x4E, 0xFC, 0xE3, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x16,
426 0x00, 0xA3, 0xFF, 0xC3, 0x00, 0xD7, 0xFE, 0x58, 0x01, 0x0F, 0xFF,
427 0xA6, 0xFE, 0x5D, 0x48, 0x61, 0x09, 0x6E, 0xFA, 0xC0, 0x03, 0x99,
428 0xFD, 0x59, 0x01, 0x68, 0xFF, 0x26, 0x00, 0x00, 0x00, 0xFF, 0xFF,
429 0x2E, 0x00, 0x4E, 0xFF, 0x9E, 0x01, 0x00, 0xFD, 0xFC, 0x04, 0xD7,
430 0xF7, 0x75, 0x10, 0x48, 0x46, 0xE4, 0xF9, 0x6E, 0x01, 0x06, 0x00,
431 0x8E, 0xFF, 0x6B, 0x00, 0xC6, 0xFF, 0x0E, 0x00, 0xFD, 0xFF, 0x35,
432 0x00, 0x3B, 0xFF, 0xE2, 0x01, 0x31, 0xFC, 0x16, 0x07, 0x67, 0xF2,
433 0xE5, 0x25, 0x87, 0x39, 0x47, 0xF2, 0x10, 0x06, 0x30, 0xFD, 0x2F,
434 0x01, 0x9C, 0xFF, 0x14, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x13, 0x00,
435 0x9D, 0xFF, 0x2D, 0x01, 0x33, 0xFD, 0x0B, 0x06, 0x4D, 0xF2, 0xA5,
436 0x39, 0xBF, 0x25, 0x6D, 0xF2, 0x15, 0x07, 0x31, 0xFC, 0xE2, 0x01,
437 0x3B, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x0E, 0x00, 0xC5, 0xFF, 0x6D,
438 0x00, 0x8B, 0xFF, 0x0D, 0x00, 0x63, 0x01, 0xF9, 0xF9, 0x55, 0x46,
439 0x51, 0x10, 0xE3, 0xF7, 0xF7, 0x04, 0x03, 0xFD, 0x9D, 0x01, 0x4E,
440 0xFF, 0x2E, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x26, 0x00, 0x68, 0xFF,
441 0x5B, 0x01, 0x96, 0xFD, 0xC6, 0x03, 0x61, 0xFA, 0x81, 0x09, 0x57,
442 0x48, 0x8D, 0xFE, 0x1B, 0xFF, 0x52, 0x01, 0xDB, 0xFE, 0xC2, 0x00,
443 0xA4, 0xFF, 0x16, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE3,
444 0x01, 0x4D, 0xFC, 0xA3, 0x06, 0xE4, 0xF3, 0x36, 0x1E, 0x16, 0x3F,
445 0x05, 0xF4, 0xCF, 0x04, 0x02, 0xFE, 0xB2, 0x00, 0xDB, 0xFF, 0xFC,
446 0xFF, 0x03, 0x00, 0xFD, 0xFF, 0x25, 0x00, 0x6C, 0xFF, 0x8B, 0x01,
447 0x9D, 0xFC, 0xD5, 0x06, 0x89, 0xF1, 0x35, 0x33, 0x3A, 0x2D, 0x9A,
448 0xF1, 0x23, 0x07, 0x51, 0xFC, 0xC2, 0x01, 0x4F, 0xFF, 0x2F, 0x00,
449 0xFD, 0xFF, 0x07, 0x00, 0xE5, 0xFF, 0x1A, 0x00, 0x33, 0x00, 0xDF,
450 0xFE, 0x68, 0x03, 0x4E, 0xF6, 0xEE, 0x42, 0xBB, 0x17, 0x90, 0xF5,
451 0xFC, 0x05, 0x8E, 0xFC, 0xCD, 0x01, 0x3C, 0xFF, 0x34, 0x00, 0xFE,
452 0xFF, 0x1E, 0x00, 0x87, 0xFF, 0x0B, 0x01, 0x42, 0xFE, 0x74, 0x02,
453 0xF9, 0xFC, 0x39, 0x03, 0xF5, 0x48, 0x24, 0x04, 0x94, 0xFC, 0xA9,
454 0x02, 0x27, 0xFE, 0x18, 0x01, 0x82, 0xFF, 0x1F, 0x00, 0x00, 0x00,
455 0xFF, 0xFF, 0x33, 0x00, 0x3E, 0xFF, 0xC7, 0x01, 0x9D, 0xFC, 0xD8,
456 0x05, 0xE7, 0xF5, 0x91, 0x16, 0x89, 0x43, 0xCD, 0xF6, 0x1E, 0x03,
457 0x0B, 0xFF, 0x1A, 0x00, 0x26, 0x00, 0xE0, 0xFF, 0x08, 0x00, 0xFD,
458 0xFF, 0x30, 0x00, 0x4B, 0xFF, 0xC9, 0x01, 0x48, 0xFC, 0x28, 0x07,
459 0xAD, 0xF1, 0x19, 0x2C, 0x3F, 0x34, 0x97, 0xF1, 0xBE, 0x06, 0xB0,
460 0xFC, 0x7F, 0x01, 0x72, 0xFF, 0x23, 0x00, 0xFE, 0xFF, 0x02, 0x00,
461 0x00, 0x00, 0xD0, 0xFF, 0xC7, 0x00, 0xDE, 0xFD, 0x08, 0x05, 0xB0,
462 0xF3, 0x4A, 0x3E, 0x64, 0x1F, 0xA0, 0xF3, 0xBB, 0x06, 0x45, 0xFC,
463 0xE5, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x15, 0x00, 0xA9,
464 0xFF, 0xB4, 0x00, 0xF7, 0xFE, 0x1D, 0x01, 0x7A, 0xFF, 0xC5, 0xFD,
465 0x1D, 0x48, 0x89, 0x0A, 0xFB, 0xF9, 0xF8, 0x03, 0x7D, 0xFD, 0x66,
466 0x01, 0x63, 0xFF, 0x28, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2D, 0x00,
467 0x52, 0xFF, 0x93, 0x01, 0x18, 0xFD, 0xC9, 0x04, 0x45, 0xF8, 0x36,
468 0x0F, 0xBB, 0x46, 0xA1, 0xFA, 0x0C, 0x01, 0x3E, 0x00, 0x70, 0xFF,
469 0x7A, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x39,
470 0xFF, 0xE4, 0x01, 0x32, 0xFC, 0x09, 0x07, 0x9D, 0xF2, 0x92, 0x24,
471 0x8F, 0x3A, 0x82, 0xF2, 0xE1, 0x05, 0x50, 0xFD, 0x1B, 0x01, 0xA6,
472 0xFF, 0x10, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x17, 0x00, 0x93, 0xFF,
473 0x3F, 0x01, 0x15, 0xFD, 0x36, 0x06, 0x19, 0xF2, 0x97, 0x38, 0x11,
474 0x27, 0x3B, 0xF2, 0x1F, 0x07, 0x32, 0xFC, 0xDF, 0x01, 0x3D, 0xFF,
475 0x34, 0x00, 0xFD, 0xFF, 0x0D, 0x00, 0xCB, 0xFF, 0x5E, 0x00, 0xA9,
476 0xFF, 0xD6, 0xFF, 0xC3, 0x01, 0x43, 0xF9, 0xD7, 0x45, 0x92, 0x11,
477 0x77, 0xF7, 0x28, 0x05, 0xEC, 0xFC, 0xA7, 0x01, 0x4A, 0xFF, 0x2F,
478 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x25, 0x00, 0x6D, 0xFF, 0x4E, 0x01,
479 0xB3, 0xFD, 0x8D, 0x03, 0xD4, 0xFA, 0x5D, 0x08, 0x8D, 0x48, 0x74,
480 0xFF, 0xAE, 0xFE, 0x8D, 0x01, 0xBB, 0xFE, 0xD1, 0x00, 0x9E, 0xFF,
481 0x18, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE0, 0x01, 0x57,
482 0xFC, 0x85, 0x06, 0x34, 0xF4, 0xE0, 0x1C, 0xF0, 0x3F, 0x6D, 0xF4,
483 0x8C, 0x04, 0x2C, 0xFE, 0x99, 0x00, 0xE7, 0xFF, 0xF8, 0xFF, 0x04,
484 0x00, 0xFD, 0xFF, 0x27, 0x00, 0x65, 0xFF, 0x98, 0x01, 0x8A, 0xFC,
485 0xEC, 0x06, 0x7F, 0xF1, 0x04, 0x32, 0x7B, 0x2E, 0x8A, 0xF1, 0x1A,
486 0x07, 0x5D, 0xFC, 0xB8, 0x01, 0x54, 0xFF, 0x2D, 0x00, 0xFD, 0xFF,
487 0x06, 0x00, 0xEA, 0xFF, 0x0C, 0x00, 0x4E, 0x00, 0xAF, 0xFE, 0xB8,
488 0x03, 0xC7, 0xF5, 0x38, 0x42, 0x0C, 0x19, 0x32, 0xF5, 0x23, 0x06,
489 0x7D, 0xFC, 0xD3, 0x01, 0x3A, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1C,
490 0x00, 0x8D, 0xFF, 0xFC, 0x00, 0x61, 0xFE, 0x39, 0x02, 0x6B, 0xFD,
491 0x37, 0x02, 0xEB, 0x48, 0x31, 0x05, 0x21, 0xFC, 0xE4, 0x02, 0x08,
492 0xFE, 0x26, 0x01, 0x7C, 0xFF, 0x21, 0x00, 0x00, 0x00, 0xFF, 0xFF,
493 0x32, 0x00, 0x41, 0xFF, 0xC0, 0x01, 0xAF, 0xFC, 0xAD, 0x05, 0x4A,
494 0xF6, 0x44, 0x15, 0x2F, 0x44, 0x64, 0xF7, 0xC9, 0x02, 0x3D, 0xFF,
495 0xFE, 0xFF, 0x34, 0x00, 0xDB, 0xFF, 0x09, 0x00, 0xFD, 0xFF, 0x32,
496 0x00, 0x47, 0xFF, 0xD0, 0x01, 0x40, 0xFC, 0x2A, 0x07, 0xCA, 0xF1,
497 0xD1, 0x2A, 0x65, 0x35, 0xAE, 0xF1, 0xA0, 0x06, 0xC7, 0xFC, 0x70,
498 0x01, 0x7A, 0xFF, 0x20, 0x00, 0xFE, 0xFF, 0x02, 0x00, 0x05, 0x00,
499 0xC5, 0xFF, 0xDE, 0x00, 0xB7, 0xFD, 0x45, 0x05, 0x56, 0xF3, 0x61,
500 0x3D, 0xBA, 0x20, 0x56, 0xF3, 0xD3, 0x06, 0x3E, 0xFC, 0xE6, 0x01,
501 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x13, 0x00, 0xAF, 0xFF, 0xA5,
502 0x00, 0x16, 0xFF, 0xE3, 0x00, 0xE4, 0xFF, 0xEB, 0xFC, 0xD2, 0x47,
503 0xB6, 0x0B, 0x89, 0xF9, 0x2F, 0x04, 0x62, 0xFD, 0x72, 0x01, 0x5E,
504 0xFF, 0x29, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2C, 0x00, 0x56, 0xFF,
505 0x88, 0x01, 0x31, 0xFD, 0x95, 0x04, 0xB4, 0xF8, 0xFC, 0x0D, 0x26,
506 0x47, 0x64, 0xFB, 0xA7, 0x00, 0x77, 0x00, 0x51, 0xFF, 0x89, 0x00,
507 0xBA, 0xFF, 0x11, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xE6,
508 0x01, 0x34, 0xFC, 0xF9, 0x06, 0xD9, 0xF2, 0x3F, 0x23, 0x90, 0x3B,
509 0xC4, 0xF2, 0xAE, 0x05, 0x72, 0xFD, 0x07, 0x01, 0xB0, 0xFF, 0x0C,
510 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x1A, 0x00, 0x8A, 0xFF, 0x51, 0x01,
511 0xF8, 0xFC, 0x5E, 0x06, 0xED, 0xF1, 0x82, 0x37, 0x60, 0x28, 0x0E,
512 0xF2, 0x26, 0x07, 0x35, 0xFC, 0xDB, 0x01, 0x40, 0xFF, 0x34, 0x00,
513 0xFD, 0xFF, 0x0C, 0x00, 0xD0, 0xFF, 0x4F, 0x00, 0xC7, 0xFF, 0xA0,
514 0xFF, 0x20, 0x02, 0x96, 0xF8, 0x4E, 0x45, 0xD7, 0x12, 0x0D, 0xF7,
515 0x58, 0x05, 0xD6, 0xFC, 0xB0, 0x01, 0x47, 0xFF, 0x30, 0x00, 0xFF,
516 0xFF, 0x00, 0x00, 0x23, 0x00, 0x72, 0xFF, 0x40, 0x01, 0xD0, 0xFD,
517 0x53, 0x03, 0x47, 0xFB, 0x3F, 0x07, 0xB8, 0x48, 0x62, 0x00, 0x3F,
518 0xFE, 0xC8, 0x01, 0x9C, 0xFE, 0xE0, 0x00, 0x98, 0xFF, 0x19, 0x00,
519 0xFE, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xDC, 0x01, 0x63, 0xFC, 0x66,
520 0x06, 0x89, 0xF4, 0x8C, 0x1B, 0xC3, 0x40, 0xDD, 0xF4, 0x46, 0x04,
521 0x58, 0xFE, 0x80, 0x00, 0xF4, 0xFF, 0xF3, 0xFF, 0x05, 0x00, 0xFD,
522 0xFF, 0x29, 0x00, 0x5F, 0xFF, 0xA5, 0x01, 0x78, 0xFC, 0xFF, 0x06,
523 0x7D, 0xF1, 0xCF, 0x30, 0xB8, 0x2F, 0x80, 0xF1, 0x0D, 0x07, 0x6A,
524 0xFC, 0xAE, 0x01, 0x59, 0xFF, 0x2B, 0x00, 0xFD, 0xFF, 0x05, 0x00,
525 0xEF, 0xFF, 0xFF, 0xFF, 0x69, 0x00, 0x80, 0xFE, 0x04, 0x04, 0x48,
526 0xF5, 0x74, 0x41, 0x5D, 0x1A, 0xD7, 0xF4, 0x47, 0x06, 0x6F, 0xFC,
527 0xD8, 0x01, 0x39, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1B, 0x00, 0x93,
528 0xFF, 0xED, 0x00, 0x80, 0xFE, 0xFD, 0x01, 0xDC, 0xFD, 0x3C, 0x01,
529 0xD5, 0x48, 0x45, 0x06, 0xAE, 0xFB, 0x1F, 0x03, 0xEA, 0xFD, 0x34,
530 0x01, 0x77, 0xFF, 0x22, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x31, 0x00,
531 0x44, 0xFF, 0xB8, 0x01, 0xC3, 0xFC, 0x81, 0x05, 0xB0, 0xF6, 0xFA,
532 0x13, 0xCC, 0x44, 0x02, 0xF8, 0x71, 0x02, 0x71, 0xFF, 0xE1, 0xFF,
533 0x42, 0x00, 0xD5, 0xFF, 0x0B, 0x00, 0xFD, 0xFF, 0x33, 0x00, 0x43,
534 0xFF, 0xD6, 0x01, 0x39, 0xFC, 0x2A, 0x07, 0xEB, 0xF1, 0x87, 0x29,
535 0x85, 0x36, 0xCC, 0xF1, 0x7F, 0x06, 0xE0, 0xFC, 0x60, 0x01, 0x82,
536 0xFF, 0x1D, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x09, 0x00, 0xBA, 0xFF,
537 0xF4, 0x00, 0x91, 0xFD, 0x7E, 0x05, 0x05, 0xF3, 0x6E, 0x3C, 0x10,
538 0x22, 0x12, 0xF3, 0xE9, 0x06, 0x38, 0xFC, 0xE6, 0x01, 0x37, 0xFF,
539 0x36, 0x00, 0xFD, 0xFF, 0x12, 0x00, 0xB5, 0xFF, 0x96, 0x00, 0x35,
540 0xFF, 0xA9, 0x00, 0x4D, 0x00, 0x19, 0xFC, 0x7C, 0x47, 0xE8, 0x0C,
541 0x18, 0xF9, 0x66, 0x04, 0x48, 0xFD, 0x7E, 0x01, 0x5A, 0xFF, 0x2B,
542 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x5A, 0xFF, 0x7D, 0x01,
543 0x4B, 0xFD, 0x60, 0x04, 0x24, 0xF9, 0xC6, 0x0C, 0x86, 0x47, 0x30,
544 0xFC, 0x41, 0x00, 0xB0, 0x00, 0x32, 0xFF, 0x98, 0x00, 0xB4, 0xFF,
545 0x12, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x38,
546 0xFC, 0xE6, 0x06, 0x19, 0xF3, 0xEA, 0x21, 0x8A, 0x3C, 0x0E, 0xF3,
547 0x78, 0x05, 0x96, 0xFD, 0xF1, 0x00, 0xBB, 0xFF, 0x08, 0x00, 0x01,
548 0x00, 0xFE, 0xFF, 0x1D, 0x00, 0x81, 0xFF, 0x62, 0x01, 0xDD, 0xFC,
549 0x83, 0x06, 0xC9, 0xF1, 0x66, 0x36, 0xAC, 0x29, 0xE7, 0xF1, 0x2A,
550 0x07, 0x3A, 0xFC, 0xD5, 0x01, 0x43, 0xFF, 0x33, 0x00, 0xFD, 0xFF,
551 0x0B, 0x00, 0xD6, 0xFF, 0x41, 0x00, 0xE4, 0xFF, 0x6B, 0xFF, 0x7B,
552 0x02, 0xF0, 0xF7, 0xBA, 0x44, 0x1E, 0x14, 0xA5, 0xF6, 0x86, 0x05,
553 0xC1, 0xFC, 0xB9, 0x01, 0x44, 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0x00,
554 0x00, 0x22, 0x00, 0x77, 0xFF, 0x32, 0x01, 0xED, 0xFD, 0x19, 0x03,
555 0xBB, 0xFB, 0x26, 0x06, 0xD7, 0x48, 0x58, 0x01, 0xCF, 0xFD, 0x04,
556 0x02, 0x7D, 0xFE, 0xEF, 0x00, 0x92, 0xFF, 0x1B, 0x00, 0xFE, 0xFF,
557 0x35, 0x00, 0x39, 0xFF, 0xD8, 0x01, 0x70, 0xFC, 0x43, 0x06, 0xE1,
558 0xF4, 0x38, 0x1A, 0x8C, 0x41, 0x55, 0xF5, 0xFC, 0x03, 0x85, 0xFE,
559 0x66, 0x00, 0x01, 0x00, 0xEE, 0xFF, 0x06, 0x00, 0xFD, 0xFF, 0x2B,
560 0x00, 0x59, 0xFF, 0xB0, 0x01, 0x69, 0xFC, 0x0F, 0x07, 0x80, 0xF1,
561 0x96, 0x2F, 0xF2, 0x30, 0x7C, 0xF1, 0xFD, 0x06, 0x7A, 0xFC, 0xA3,
562 0x01, 0x5F, 0xFF, 0x29, 0x00, 0xFD, 0xFF, 0x05, 0x00, 0xF4, 0xFF,
563 0xF2, 0xFF, 0x83, 0x00, 0x53, 0xFE, 0x4E, 0x04, 0xD0, 0xF4, 0xAB,
564 0x40, 0xB2, 0x1B, 0x7F, 0xF4, 0x69, 0x06, 0x62, 0xFC, 0xDD, 0x01,
565 0x38, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x19, 0x00, 0x98, 0xFF, 0xDE,
566 0x00, 0x9F, 0xFE, 0xC2, 0x01, 0x4B, 0xFE, 0x48, 0x00, 0xB3, 0x48,
567 0x5E, 0x07, 0x3B, 0xFB, 0x59, 0x03, 0xCD, 0xFD, 0x42, 0x01, 0x71,
568 0xFF, 0x24, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x30, 0x00, 0x47, 0xFF,
569 0xAF, 0x01, 0xD8, 0xFC, 0x52, 0x05, 0x19, 0xF7, 0xB2, 0x12, 0x5C,
570 0x45, 0xA9, 0xF8, 0x16, 0x02, 0xA6, 0xFF, 0xC3, 0xFF, 0x51, 0x00,
571 0xD0, 0xFF, 0x0C, 0x00, 0xFD, 0xFF, 0x34, 0x00, 0x40, 0xFF, 0xDB,
572 0x01, 0x35, 0xFC, 0x25, 0x07, 0x13, 0xF2, 0x3A, 0x28, 0xA0, 0x37,
573 0xF2, 0xF1, 0x5A, 0x06, 0xFB, 0xFC, 0x4F, 0x01, 0x8B, 0xFF, 0x1A,
574 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x0D, 0x00, 0xAF, 0xFF, 0x09, 0x01,
575 0x6E, 0xFD, 0xB4, 0x05, 0xBC, 0xF2, 0x73, 0x3B, 0x64, 0x23, 0xD2,
576 0xF2, 0xFB, 0x06, 0x34, 0xFC, 0xE6, 0x01, 0x38, 0xFF, 0x36, 0x00,
577 0xFD, 0xFF, 0x11, 0x00, 0xBB, 0xFF, 0x87, 0x00, 0x54, 0xFF, 0x70,
578 0x00, 0xB3, 0x00, 0x4E, 0xFB, 0x1A, 0x47, 0x1F, 0x0E, 0xA8, 0xF8,
579 0x9B, 0x04, 0x2E, 0xFD, 0x8A, 0x01, 0x55, 0xFF, 0x2C, 0x00, 0xFF,
580 0xFF, 0x00, 0x00, 0x29, 0x00, 0x5F, 0xFF, 0x71, 0x01, 0x65, 0xFD,
581 0x29, 0x04, 0x96, 0xF9, 0x95, 0x0B, 0xDC, 0x47, 0x03, 0xFD, 0xD9,
582 0xFF, 0xEA, 0x00, 0x12, 0xFF, 0xA7, 0x00, 0xAE, 0xFF, 0x14, 0x00,
583 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3E, 0xFC, 0xD0,
584 0x06, 0x5E, 0xF3, 0x94, 0x20, 0x7B, 0x3D, 0x60, 0xF3, 0x3E, 0x05,
585 0xBB, 0xFD, 0xDB, 0x00, 0xC6, 0xFF, 0x04, 0x00, 0x02, 0x00, 0xFE,
586 0xFF, 0x20, 0x00, 0x79, 0xFF, 0x72, 0x01, 0xC4, 0xFC, 0xA4, 0x06,
587 0xAB, 0xF1, 0x46, 0x35, 0xF7, 0x2A, 0xC6, 0xF1, 0x2A, 0x07, 0x40,
588 0xFC, 0xCF, 0x01, 0x47, 0xFF, 0x31, 0x00, 0xFD, 0xFF, 0x09, 0x00,
589 0xDB, 0xFF, 0x33, 0x00, 0x01, 0x00, 0x38, 0xFF, 0xD3, 0x02, 0x53,
590 0xF7, 0x1F, 0x44, 0x69, 0x15, 0x3F, 0xF6, 0xB2, 0x05, 0xAD, 0xFC,
591 0xC1, 0x01, 0x41, 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x20,
592 0x00, 0x7D, 0xFF, 0x24, 0x01, 0x0C, 0xFE, 0xDE, 0x02, 0x2E, 0xFC,
593 0x13, 0x05, 0xEC, 0x48, 0x54, 0x02, 0x5E, 0xFD, 0x3F, 0x02, 0x5D,
594 0xFE, 0xFE, 0x00, 0x8C, 0xFF, 0x1C, 0x00, 0xFE, 0xFF, 0x35, 0x00,
595 0x3B, 0xFF, 0xD3, 0x01, 0x7F, 0xFC, 0x1F, 0x06, 0x3C, 0xF5, 0xE6,
596 0x18, 0x4D, 0x42, 0xD5, 0xF5, 0xAF, 0x03, 0xB4, 0xFE, 0x4B, 0x00,
597 0x0E, 0x00, 0xE9, 0xFF, 0x07, 0x00, 0xFD, 0xFF, 0x2D, 0x00, 0x53,
598 0xFF, 0xBA, 0x01, 0x5B, 0xFC, 0x1B, 0x07, 0x8B, 0xF1, 0x58, 0x2E,
599 0x26, 0x32, 0x80, 0xF1, 0xEA, 0x06, 0x8C, 0xFC, 0x97, 0x01, 0x66,
600 0xFF, 0x27, 0x00, 0xFD, 0xFF, 0x04, 0x00, 0xF8, 0xFF, 0xE6, 0xFF,
601 0x9C, 0x00, 0x27, 0xFE, 0x94, 0x04, 0x61, 0xF4, 0xD7, 0x3F, 0x06,
602 0x1D, 0x2B, 0xF4, 0x89, 0x06, 0x56, 0xFC, 0xE0, 0x01, 0x37, 0xFF,
603 0x36, 0x00, 0xFE, 0xFF, 0x17, 0x00, 0x9E, 0xFF, 0xCF, 0x00, 0xBF,
604 0xFE, 0x86, 0x01, 0xBA, 0xFE, 0x5A, 0xFF, 0x86, 0x48, 0x7D, 0x08,
605 0xC7, 0xFA, 0x93, 0x03, 0xB0, 0xFD, 0x4F, 0x01, 0x6C, 0xFF, 0x25,
606 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2F, 0x00, 0x4B, 0xFF, 0xA6, 0x01,
607 0xEE, 0xFC, 0x23, 0x05, 0x83, 0xF7, 0x6E, 0x11, 0xE5, 0x45, 0x57,
608 0xF9, 0xB8, 0x01, 0xDC, 0xFF, 0xA5, 0xFF, 0x5F, 0x00, 0xCA, 0xFF,
609 0x0D, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3D, 0xFF, 0xDF, 0x01, 0x32,
610 0xFC, 0x1E, 0x07, 0x40, 0xF2, 0xEB, 0x26, 0xB5, 0x38, 0x1F, 0xF2,
611 0x32, 0x06, 0x18, 0xFD, 0x3D, 0x01, 0x94, 0xFF, 0x16, 0x00, 0xFF,
612 0xFF, 0x00, 0x00, 0x11, 0x00, 0xA4, 0xFF, 0x1D, 0x01, 0x4C, 0xFD,
613 0xE6, 0x05, 0x7B, 0xF2, 0x71, 0x3A, 0xB8, 0x24, 0x97, 0xF2, 0x0B,
614 0x07, 0x32, 0xFC, 0xE4, 0x01, 0x39, 0xFF, 0x36, 0x00, 0xFD, 0xFF,
615 0x0F, 0x00, 0xC0, 0xFF, 0x78, 0x00, 0x73, 0xFF, 0x38, 0x00, 0x17,
616 0x01, 0x8B, 0xFA, 0xAF, 0x46, 0x59, 0x0F, 0x39, 0xF8, 0xCF, 0x04,
617 0x15, 0xFD, 0x95, 0x01, 0x51, 0xFF, 0x2D, 0x00, 0xFF, 0xFF, 0x00,
618 0x00, 0x28, 0x00, 0x64, 0xFF, 0x65, 0x01, 0x81, 0xFD, 0xF2, 0x03,
619 0x08, 0xFA, 0x68, 0x0A, 0x25, 0x48, 0xDE, 0xFD, 0x6E, 0xFF, 0x24,
620 0x01, 0xF3, 0xFE, 0xB6, 0x00, 0xA8, 0xFF, 0x15, 0x00, 0xFD, 0xFF,
621 0x36, 0x00, 0x36, 0xFF, 0xE5, 0x01, 0x46, 0xFC, 0xB8, 0x06, 0xA8,
622 0xF3, 0x3F, 0x1F, 0x64, 0x3E, 0xBA, 0xF3, 0x01, 0x05, 0xE2, 0xFD,
623 0xC4, 0x00, 0xD2, 0xFF, 0x00, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x23,
624 0x00, 0x71, 0xFF, 0x81, 0x01, 0xAE, 0xFC, 0xC1, 0x06, 0x95, 0xF1,
625 0x1E, 0x34, 0x3E, 0x2C, 0xAB, 0xF1, 0x27, 0x07, 0x49, 0xFC, 0xC8,
626 0x01, 0x4B, 0xFF, 0x30, 0x00, 0xFD, 0xFF, 0x08, 0x00, 0xE1, 0xFF,
627 0x25, 0x00, 0x1D, 0x00, 0x05, 0xFF, 0x28, 0x03, 0xBD, 0xF6, 0x77,
628 0x43, 0xB6, 0x16, 0xDC, 0xF5, 0xDD, 0x05, 0x9B, 0xFC, 0xC8, 0x01,
629 0x3E, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x1F, 0x00, 0x83,
630 0xFF, 0x16, 0x01, 0x2A, 0xFE, 0xA3, 0x02, 0xA1, 0xFC, 0x06, 0x04,
631 0xF5, 0x48, 0x56, 0x03, 0xED, 0xFC, 0x7B, 0x02, 0x3E, 0xFE, 0x0C,
632 0x01, 0x86, 0xFF, 0x1E, 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3D, 0xFF,
633 0xCC, 0x01, 0x8F, 0xFC, 0xF8, 0x05, 0x9B, 0xF5, 0x96, 0x17, 0x02,
634 0x43, 0x5E, 0xF6, 0x5F, 0x03, 0xE4, 0xFE, 0x30, 0x00, 0x1B, 0x00,
635 0xE4, 0xFF, 0x08, 0x00, 0xFD, 0xFF, 0x2F, 0x00, 0x4E, 0xFF, 0xC3,
636 0x01, 0x4F, 0xFC, 0x24, 0x07, 0x9C, 0xF1, 0x17, 0x2D, 0x57, 0x33,
637 0x8A, 0xF1, 0xD3, 0x06, 0x9F, 0xFC, 0x8A, 0x01, 0x6D, 0xFF, 0x25,
638 0x00, 0xFD, 0xFF, 0x03, 0x00, 0xFD, 0xFF, 0xD9, 0xFF, 0xB4, 0x00,
639 0xFD, 0xFD, 0xD7, 0x04, 0xFA, 0xF3, 0xFC, 0x3E, 0x5B, 0x1E, 0xDB,
640 0xF3, 0xA6, 0x06, 0x4C, 0xFC, 0xE3, 0x01, 0x36, 0xFF, 0x36, 0x00,
641 0xFE, 0xFF, 0x16, 0x00, 0xA4, 0xFF, 0xC0, 0x00, 0xDE, 0xFE, 0x4B,
642 0x01, 0x27, 0xFF, 0x73, 0xFE, 0x4F, 0x48, 0xA2, 0x09, 0x54, 0xFA,
643 0xCC, 0x03, 0x93, 0xFD, 0x5C, 0x01, 0x67, 0xFF, 0x27, 0x00, 0x00,
644 0x00, 0xFF, 0xFF, 0x2E, 0x00, 0x4E, 0xFF, 0x9C, 0x01, 0x05, 0xFD,
645 0xF1, 0x04, 0xF0, 0xF7, 0x2D, 0x10, 0x61, 0x46, 0x0D, 0xFA, 0x58,
646 0x01, 0x13, 0x00, 0x87, 0xFF, 0x6E, 0x00, 0xC4, 0xFF, 0x0E, 0x00,
647 0xFD, 0xFF, 0x35, 0x00, 0x3B, 0xFF, 0xE3, 0x01, 0x31, 0xFC, 0x14,
648 0x07, 0x73, 0xF2, 0x99, 0x25, 0xC2, 0x39, 0x54, 0xF2, 0x05, 0x06,
649 0x37, 0xFD, 0x2B, 0x01, 0x9E, 0xFF, 0x13, 0x00, 0xFF, 0xFF, 0xFF,
650 0xFF, 0x14, 0x00, 0x9B, 0xFF, 0x31, 0x01, 0x2C, 0xFD, 0x15, 0x06,
651 0x41, 0xF2, 0x6A, 0x39, 0x0A, 0x26, 0x61, 0xF2, 0x17, 0x07, 0x31,
652 0xFC, 0xE2, 0x01, 0x3B, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x0E, 0x00,
653 0xC6, 0xFF, 0x69, 0x00, 0x91, 0xFF, 0x00, 0x00, 0x78, 0x01, 0xD0,
654 0xF9, 0x39, 0x46, 0x98, 0x10, 0xCB, 0xF7, 0x02, 0x05, 0xFE, 0xFC,
655 0x9F, 0x01, 0x4D, 0xFF, 0x2E, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x26,
656 0x00, 0x69, 0xFF, 0x58, 0x01, 0x9D, 0xFD, 0xB9, 0x03, 0x7B, 0xFA,
657 0x40, 0x09, 0x63, 0x48, 0xBF, 0xFE, 0x03, 0xFF, 0x5F, 0x01, 0xD4,
658 0xFE, 0xC5, 0x00, 0xA2, 0xFF, 0x16, 0x00, 0xFE, 0xFF, 0x36, 0x00,
659 0x36, 0xFF, 0xE2, 0x01, 0x4F, 0xFC, 0x9C, 0x06, 0xF5, 0xF3, 0xEA,
660 0x1D, 0x47, 0x3F, 0x1B, 0xF4, 0xC1, 0x04, 0x0B, 0xFE, 0xAC, 0x00,
661 0xDE, 0xFF, 0xFB, 0xFF, 0x03, 0x00, 0xFD, 0xFF, 0x25, 0x00, 0x6A,
662 0xFF, 0x8E, 0x01, 0x99, 0xFC, 0xDB, 0x06, 0x86, 0xF1, 0xF2, 0x32,
663 0x82, 0x2D, 0x96, 0xF1, 0x21, 0x07, 0x53, 0xFC, 0xC0, 0x01, 0x50,
664 0xFF, 0x2E, 0x00, 0xFD, 0xFF, 0x07, 0x00, 0xE6, 0xFF, 0x17, 0x00,
665 0x39, 0x00, 0xD4, 0xFE, 0x7A, 0x03, 0x2F, 0xF6, 0xC7, 0x42, 0x06,
666 0x18, 0x7B, 0xF5, 0x05, 0x06, 0x8A, 0xFC, 0xCF, 0x01, 0x3C, 0xFF,
667 0x34, 0x00, 0xFE, 0xFF, 0x1D, 0x00, 0x88, 0xFF, 0x07, 0x01, 0x49,
668 0xFE, 0x67, 0x02, 0x13, 0xFD, 0xFF, 0x02, 0xF4, 0x48, 0x5F, 0x04,
669 0x7A, 0xFC, 0xB6, 0x02, 0x20, 0xFE, 0x1B, 0x01, 0x81, 0xFF, 0x1F,
670 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0x3F, 0xFF, 0xC6, 0x01,
671 0xA1, 0xFC, 0xCF, 0x05, 0xFC, 0xF5, 0x47, 0x16, 0xB0, 0x43, 0xEE,
672 0xF6, 0x0C, 0x03, 0x16, 0xFF, 0x14, 0x00, 0x29, 0x00, 0xDF, 0xFF,
673 0x09, 0x00, 0xFD, 0xFF, 0x30, 0x00, 0x4A, 0xFF, 0xCA, 0x01, 0x46,
674 0xFC, 0x29, 0x07, 0xB3, 0xF1, 0xD1, 0x2B, 0x81, 0x34, 0x9C, 0xF1,
675 0xB8, 0x06, 0xB5, 0xFC, 0x7C, 0x01, 0x74, 0xFF, 0x22, 0x00, 0xFE,
676 0xFF, 0x02, 0x00, 0x01, 0x00, 0xCE, 0xFF, 0xCC, 0x00, 0xD5, 0xFD,
677 0x16, 0x05, 0x9B, 0xF3, 0x18, 0x3E, 0xB1, 0x1F, 0x8F, 0xF3, 0xC0,
678 0x06, 0x43, 0xFC, 0xE5, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF,
679 0x15, 0x00, 0xAA, 0xFF, 0xB1, 0x00, 0xFE, 0xFE, 0x10, 0x01, 0x92,
680 0xFF, 0x94, 0xFD, 0x0D, 0x48, 0xCB, 0x0A, 0xE2, 0xF9, 0x04, 0x04,
681 0x77, 0xFD, 0x69, 0x01, 0x62, 0xFF, 0x28, 0x00, 0x00, 0x00, 0xFF,
682 0xFF, 0x2D, 0x00, 0x52, 0xFF, 0x91, 0x01, 0x1E, 0xFD, 0xBE, 0x04,
683 0x5E, 0xF8, 0xF0, 0x0E, 0xD3, 0x46, 0xCB, 0xFA, 0xF6, 0x00, 0x4B,
684 0x00, 0x69, 0xFF, 0x7D, 0x00, 0xBE, 0xFF, 0x10, 0x00, 0xFD, 0xFF,
685 0x36, 0x00, 0x39, 0xFF, 0xE5, 0x01, 0x32, 0xFC, 0x06, 0x07, 0xAA,
686 0xF2, 0x46, 0x24, 0xC8, 0x3A, 0x90, 0xF2, 0xD6, 0x05, 0x57, 0xFD,
687 0x17, 0x01, 0xA8, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x18,
688 0x00, 0x91, 0xFF, 0x43, 0x01, 0x0E, 0xFD, 0x40, 0x06, 0x0F, 0xF2,
689 0x5B, 0x38, 0x5C, 0x27, 0x30, 0xF2, 0x21, 0x07, 0x33, 0xFC, 0xDE,
690 0x01, 0x3E, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x0D, 0x00, 0xCC, 0xFF,
691 0x5A, 0x00, 0xAF, 0xFF, 0xCA, 0xFF, 0xD8, 0x01, 0x1C, 0xF9, 0xB8,
692 0x45, 0xDA, 0x11, 0x60, 0xF7, 0x33, 0x05, 0xE7, 0xFC, 0xA9, 0x01,
693 0x4A, 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x25, 0x00, 0x6E,
694 0xFF, 0x4B, 0x01, 0xB9, 0xFD, 0x80, 0x03, 0xEE, 0xFA, 0x1D, 0x08,
695 0x98, 0x48, 0xA8, 0xFF, 0x95, 0xFE, 0x9A, 0x01, 0xB4, 0xFE, 0xD4,
696 0x00, 0x9C, 0xFF, 0x18, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF,
697 0xDF, 0x01, 0x5A, 0xFC, 0x7E, 0x06, 0x47, 0xF4, 0x94, 0x1C, 0x1F,
698 0x40, 0x85, 0xF4, 0x7D, 0x04, 0x36, 0xFE, 0x93, 0x00, 0xEA, 0xFF,
699 0xF7, 0xFF, 0x04, 0x00, 0xFD, 0xFF, 0x28, 0x00, 0x63, 0xFF, 0x9B,
700 0x01, 0x86, 0xFC, 0xF1, 0x06, 0x7E, 0xF1, 0xC0, 0x31, 0xC2, 0x2E,
701 0x87, 0xF1, 0x17, 0x07, 0x5F, 0xFC, 0xB6, 0x01, 0x55, 0xFF, 0x2D,
702 0x00, 0xFD, 0xFF, 0x06, 0x00, 0xEB, 0xFF, 0x09, 0x00, 0x54, 0x00,
703 0xA4, 0xFE, 0xC9, 0x03, 0xAA, 0xF5, 0x0C, 0x42, 0x56, 0x19, 0x1E,
704 0xF5, 0x2B, 0x06, 0x7A, 0xFC, 0xD4, 0x01, 0x3A, 0xFF, 0x35, 0x00,
705 0xFE, 0xFF, 0x1C, 0x00, 0x8E, 0xFF, 0xF9, 0x00, 0x68, 0xFE, 0x2C,
706 0x02, 0x84, 0xFD, 0xFF, 0x01, 0xE6, 0x48, 0x6E, 0x05, 0x07, 0xFC,
707 0xF1, 0x02, 0x01, 0xFE, 0x29, 0x01, 0x7B, 0xFF, 0x21, 0x00, 0x00,
708 0x00, 0xFF, 0xFF, 0x32, 0x00, 0x42, 0xFF, 0xBE, 0x01, 0xB4, 0xFC,
709 0xA4, 0x05, 0x61, 0xF6, 0xFB, 0x14, 0x53, 0x44, 0x86, 0xF7, 0xB6,
710 0x02, 0x49, 0xFF, 0xF7, 0xFF, 0x37, 0x00, 0xD9, 0xFF, 0x0A, 0x00,
711 0xFD, 0xFF, 0x32, 0x00, 0x46, 0xFF, 0xD1, 0x01, 0x3E, 0xFC, 0x2B,
712 0x07, 0xD0, 0xF1, 0x89, 0x2A, 0xA6, 0x35, 0xB4, 0xF1, 0x99, 0x06,
713 0xCD, 0xFC, 0x6D, 0x01, 0x7C, 0xFF, 0x1F, 0x00, 0xFE, 0xFF, 0x01,
714 0x00, 0x06, 0x00, 0xC2, 0xFF, 0xE3, 0x00, 0xAE, 0xFD, 0x52, 0x05,
715 0x44, 0xF3, 0x2A, 0x3D, 0x06, 0x21, 0x47, 0xF3, 0xD8, 0x06, 0x3C,
716 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x13, 0x00,
717 0xB0, 0xFF, 0xA2, 0x00, 0x1D, 0xFF, 0xD6, 0x00, 0xFC, 0xFF, 0xBC,
718 0xFC, 0xC0, 0x47, 0xFA, 0x0B, 0x70, 0xF9, 0x3C, 0x04, 0x5C, 0xFD,
719 0x75, 0x01, 0x5D, 0xFF, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B,
720 0x00, 0x57, 0xFF, 0x86, 0x01, 0x36, 0xFD, 0x89, 0x04, 0xCD, 0xF8,
721 0xB7, 0x0D, 0x3D, 0x47, 0x91, 0xFB, 0x91, 0x00, 0x83, 0x00, 0x4A,
722 0xFF, 0x8C, 0x00, 0xB9, 0xFF, 0x11, 0x00, 0xFD, 0xFF, 0x36, 0x00,
723 0x38, 0xFF, 0xE6, 0x01, 0x35, 0xFC, 0xF5, 0x06, 0xE7, 0xF2, 0xF2,
724 0x22, 0xC7, 0x3B, 0xD4, 0xF2, 0xA2, 0x05, 0x7A, 0xFD, 0x02, 0x01,
725 0xB2, 0xFF, 0x0B, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x1B, 0x00, 0x88,
726 0xFF, 0x55, 0x01, 0xF2, 0xFC, 0x67, 0x06, 0xE4, 0xF1, 0x44, 0x37,
727 0xAA, 0x28, 0x05, 0xF2, 0x27, 0x07, 0x36, 0xFC, 0xDA, 0x01, 0x41,
728 0xFF, 0x33, 0x00, 0xFD, 0xFF, 0x0B, 0x00, 0xD2, 0xFF, 0x4C, 0x00,
729 0xCD, 0xFF, 0x94, 0xFF, 0x34, 0x02, 0x70, 0xF8, 0x2E, 0x45, 0x20,
730 0x13, 0xF6, 0xF6, 0x62, 0x05, 0xD1, 0xFC, 0xB2, 0x01, 0x46, 0xFF,
731 0x31, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x23, 0x00, 0x73, 0xFF, 0x3D,
732 0x01, 0xD6, 0xFD, 0x46, 0x03, 0x61, 0xFB, 0x00, 0x07, 0xBF, 0x48,
733 0x98, 0x00, 0x26, 0xFE, 0xD5, 0x01, 0x95, 0xFE, 0xE3, 0x00, 0x96,
734 0xFF, 0x1A, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xDB, 0x01,
735 0x66, 0xFC, 0x5E, 0x06, 0x9C, 0xF4, 0x40, 0x1B, 0xEF, 0x40, 0xF7,
736 0xF4, 0x35, 0x04, 0x62, 0xFE, 0x7A, 0x00, 0xF7, 0xFF, 0xF2, 0xFF,
737 0x05, 0x00, 0xFD, 0xFF, 0x2A, 0x00, 0x5D, 0xFF, 0xA7, 0x01, 0x75,
738 0xFC, 0x03, 0x07, 0x7D, 0xF1, 0x8A, 0x30, 0xFF, 0x2F, 0x7E, 0xF1,
739 0x0A, 0x07, 0x6E, 0xFC, 0xAC, 0x01, 0x5A, 0xFF, 0x2B, 0x00, 0xFD,
740 0xFF, 0x05, 0x00, 0xF0, 0xFF, 0xFC, 0xFF, 0x6E, 0x00, 0x76, 0xFE,
741 0x15, 0x04, 0x2C, 0xF5, 0x49, 0x41, 0xA9, 0x1A, 0xC3, 0xF4, 0x4F,
742 0x06, 0x6C, 0xFC, 0xD9, 0x01, 0x38, 0xFF, 0x35, 0x00, 0xFE, 0xFF,
743 0x1A, 0x00, 0x94, 0xFF, 0xEA, 0x00, 0x87, 0xFE, 0xF0, 0x01, 0xF5,
744 0xFD, 0x05, 0x01, 0xCE, 0x48, 0x83, 0x06, 0x94, 0xFB, 0x2C, 0x03,
745 0xE4, 0xFD, 0x37, 0x01, 0x76, 0xFF, 0x22, 0x00, 0x00, 0x00, 0xFF,
746 0xFF, 0x31, 0x00, 0x45, 0xFF, 0xB6, 0x01, 0xC8, 0xFC, 0x77, 0x05,
747 0xC7, 0xF6, 0xB1, 0x13, 0xED, 0x44, 0x26, 0xF8, 0x5D, 0x02, 0x7D,
748 0xFF, 0xDA, 0xFF, 0x46, 0x00, 0xD4, 0xFF, 0x0B, 0x00, 0xFD, 0xFF,
749 0x33, 0x00, 0x42, 0xFF, 0xD7, 0x01, 0x38, 0xFC, 0x29, 0x07, 0xF3,
750 0xF1, 0x3E, 0x29, 0xC6, 0x36, 0xD4, 0xF1, 0x77, 0x06, 0xE6, 0xFC,
751 0x5C, 0x01, 0x84, 0xFF, 0x1C, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x0A,
752 0x00, 0xB7, 0xFF, 0xF9, 0x00, 0x89, 0xFD, 0x8A, 0x05, 0xF4, 0xF2,
753 0x37, 0x3C, 0x5B, 0x22, 0x03, 0xF3, 0xED, 0x06, 0x37, 0xFC, 0xE6,
754 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x12, 0x00, 0xB6, 0xFF,
755 0x93, 0x00, 0x3C, 0xFF, 0x9D, 0x00, 0x63, 0x00, 0xEB, 0xFB, 0x69,
756 0x47, 0x2D, 0x0D, 0xFF, 0xF8, 0x72, 0x04, 0x42, 0xFD, 0x81, 0x01,
757 0x59, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x5B,
758 0xFF, 0x7A, 0x01, 0x50, 0xFD, 0x54, 0x04, 0x3D, 0xF9, 0x82, 0x0C,
759 0x9A, 0x47, 0x5E, 0xFC, 0x2A, 0x00, 0xBD, 0x00, 0x2B, 0xFF, 0x9B,
760 0x00, 0xB3, 0xFF, 0x12, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x37, 0xFF,
761 0xE6, 0x01, 0x3A, 0xFC, 0xE2, 0x06, 0x28, 0xF3, 0x9E, 0x21, 0xC0,
762 0x3C, 0x1F, 0xF3, 0x6C, 0x05, 0x9E, 0xFD, 0xED, 0x00, 0xBD, 0xFF,
763 0x07, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x1E, 0x00, 0x80, 0xFF, 0x66,
764 0x01, 0xD8, 0xFC, 0x8B, 0x06, 0xC1, 0xF1, 0x27, 0x36, 0xF6, 0x29,
765 0xDF, 0xF1, 0x2A, 0x07, 0x3B, 0xFC, 0xD4, 0x01, 0x44, 0xFF, 0x32,
766 0x00, 0xFD, 0xFF, 0x0A, 0x00, 0xD7, 0xFF, 0x3E, 0x00, 0xEA, 0xFF,
767 0x60, 0xFF, 0x8F, 0x02, 0xCD, 0xF7, 0x99, 0x44, 0x68, 0x14, 0x8E,
768 0xF6, 0x90, 0x05, 0xBC, 0xFC, 0xBA, 0x01, 0x43, 0xFF, 0x32, 0x00,
769 0xFF, 0xFF, 0x00, 0x00, 0x22, 0x00, 0x79, 0xFF, 0x2F, 0x01, 0xF4,
770 0xFD, 0x0C, 0x03, 0xD4, 0xFB, 0xE9, 0x05, 0xDE, 0x48, 0x8F, 0x01,
771 0xB6, 0xFD, 0x11, 0x02, 0x76, 0xFE, 0xF2, 0x00, 0x91, 0xFF, 0x1B,
772 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x39, 0xFF, 0xD7, 0x01, 0x73, 0xFC,
773 0x3B, 0x06, 0xF5, 0xF4, 0xED, 0x19, 0xB7, 0x41, 0x71, 0xF5, 0xEB,
774 0x03, 0x90, 0xFE, 0x60, 0x00, 0x04, 0x00, 0xED, 0xFF, 0x06, 0x00,
775 0xFD, 0xFF, 0x2C, 0x00, 0x57, 0xFF, 0xB2, 0x01, 0x65, 0xFC, 0x12,
776 0x07, 0x82, 0xF1, 0x50, 0x2F, 0x38, 0x31, 0x7C, 0xF1, 0xF9, 0x06,
777 0x7E, 0xFC, 0xA1, 0x01, 0x61, 0xFF, 0x29, 0x00, 0xFD, 0xFF, 0x04,
778 0x00, 0xF5, 0xFF, 0xEF, 0xFF, 0x88, 0x00, 0x49, 0xFE, 0x5D, 0x04,
779 0xB7, 0xF4, 0x7D, 0x40, 0xFD, 0x1B, 0x6C, 0xF4, 0x70, 0x06, 0x5F,
780 0xFC, 0xDE, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x19, 0x00,
781 0x9A, 0xFF, 0xDB, 0x00, 0xA6, 0xFE, 0xB4, 0x01, 0x64, 0xFE, 0x12,
782 0x00, 0xAA, 0x48, 0x9E, 0x07, 0x21, 0xFB, 0x66, 0x03, 0xC6, 0xFD,
783 0x45, 0x01, 0x70, 0xFF, 0x24, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x30,
784 0x00, 0x48, 0xFF, 0xAD, 0x01, 0xDD, 0xFC, 0x48, 0x05, 0x30, 0xF7,
785 0x6B, 0x12, 0x7D, 0x45, 0xCF, 0xF8, 0x01, 0x02, 0xB2, 0xFF, 0xBD,
786 0xFF, 0x54, 0x00, 0xCE, 0xFF, 0x0C, 0x00, 0xFD, 0xFF, 0x34, 0x00,
787 0x3F, 0xFF, 0xDC, 0x01, 0x34, 0xFC, 0x24, 0x07, 0x1C, 0xF2, 0xF0,
788 0x27, 0xDF, 0x37, 0xFB, 0xF1, 0x51, 0x06, 0x01, 0xFD, 0x4B, 0x01,
789 0x8D, 0xFF, 0x19, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x0E, 0x00, 0xAC,
790 0xFF, 0x0E, 0x01, 0x66, 0xFD, 0xBF, 0x05, 0xAD, 0xF2, 0x3B, 0x3B,
791 0xB0, 0x23, 0xC4, 0xF2, 0xFF, 0x06, 0x33, 0xFC, 0xE5, 0x01, 0x38,
792 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x10, 0x00, 0xBC, 0xFF, 0x84, 0x00,
793 0x5B, 0xFF, 0x64, 0x00, 0xC9, 0x00, 0x22, 0xFB, 0x02, 0x47, 0x64,
794 0x0E, 0x8F, 0xF8, 0xA7, 0x04, 0x29, 0xFD, 0x8C, 0x01, 0x54, 0xFF,
795 0x2C, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x29, 0x00, 0x60, 0xFF, 0x6E,
796 0x01, 0x6B, 0xFD, 0x1D, 0x04, 0xAF, 0xF9, 0x51, 0x0B, 0xEC, 0x47,
797 0x33, 0xFD, 0xC1, 0xFF, 0xF7, 0x00, 0x0C, 0xFF, 0xAA, 0x00, 0xAD,
798 0xFF, 0x14, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01,
799 0x40, 0xFC, 0xCB, 0x06, 0x6E, 0xF3, 0x49, 0x20, 0xB0, 0x3D, 0x73,
800 0xF3, 0x31, 0x05, 0xC4, 0xFD, 0xD6, 0x00, 0xC8, 0xFF, 0x03, 0x00,
801 0x02, 0x00, 0xFE, 0xFF, 0x21, 0x00, 0x77, 0xFF, 0x75, 0x01, 0xBF,
802 0xFC, 0xAB, 0x06, 0xA6, 0xF1, 0x05, 0x35, 0x40, 0x2B, 0xBF, 0xF1,
803 0x2A, 0x07, 0x42, 0xFC, 0xCE, 0x01, 0x48, 0xFF, 0x31, 0x00, 0xFD,
804 0xFF, 0x09, 0x00, 0xDC, 0xFF, 0x2F, 0x00, 0x07, 0x00, 0x2C, 0xFF,
805 0xE6, 0x02, 0x31, 0xF7, 0xFA, 0x43, 0xB3, 0x15, 0x29, 0xF6, 0xBC,
806 0x05, 0xA9, 0xFC, 0xC2, 0x01, 0x40, 0xFF, 0x33, 0x00, 0xFF, 0xFF,
807 0x00, 0x00, 0x20, 0x00, 0x7E, 0xFF, 0x21, 0x01, 0x12, 0xFE, 0xD1,
808 0x02, 0x47, 0xFC, 0xD7, 0x04, 0xF0, 0x48, 0x8D, 0x02, 0x45, 0xFD,
809 0x4D, 0x02, 0x56, 0xFE, 0x01, 0x01, 0x8B, 0xFF, 0x1D, 0x00, 0xFE,
810 0xFF, 0x34, 0x00, 0x3B, 0xFF, 0xD1, 0x01, 0x83, 0xFC, 0x16, 0x06,
811 0x51, 0xF5, 0x9B, 0x18, 0x75, 0x42, 0xF3, 0xF5, 0x9D, 0x03, 0xBF,
812 0xFE, 0x45, 0x00, 0x11, 0x00, 0xE8, 0xFF, 0x07, 0x00, 0xFD, 0xFF,
813 0x2E, 0x00, 0x52, 0xFF, 0xBC, 0x01, 0x58, 0xFC, 0x1D, 0x07, 0x8E,
814 0xF1, 0x11, 0x2E, 0x6B, 0x32, 0x81, 0xF1, 0xE5, 0x06, 0x90, 0xFC,
815 0x94, 0x01, 0x67, 0xFF, 0x26, 0x00, 0xFD, 0xFF, 0x04, 0x00, 0xF9,
816 0xFF, 0xE3, 0xFF, 0xA1, 0x00, 0x1E, 0xFE, 0xA3, 0x04, 0x49, 0xF4,
817 0xA8, 0x3F, 0x52, 0x1D, 0x19, 0xF4, 0x90, 0x06, 0x53, 0xFC, 0xE1,
818 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x17, 0x00, 0xA0, 0xFF,
819 0xCC, 0x00, 0xC6, 0xFE, 0x79, 0x01, 0xD2, 0xFE, 0x26, 0xFF, 0x7C,
820 0x48, 0xBE, 0x08, 0xAE, 0xFA, 0xA0, 0x03, 0xA9, 0xFD, 0x52, 0x01,
821 0x6B, 0xFF, 0x25, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2F, 0x00, 0x4C,
822 0xFF, 0xA3, 0x01, 0xF3, 0xFC, 0x18, 0x05, 0x9B, 0xF7, 0x27, 0x11,
823 0x02, 0x46, 0x7F, 0xF9, 0xA3, 0x01, 0xE8, 0xFF, 0x9F, 0xFF, 0x63,
824 0x00, 0xC9, 0xFF, 0x0D, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3C, 0xFF,
825 0xE0, 0x01, 0x32, 0xFC, 0x1C, 0x07, 0x4B, 0xF2, 0xA0, 0x26, 0xF2,
826 0x38, 0x2A, 0xF2, 0x28, 0x06, 0x1F, 0xFD, 0x39, 0x01, 0x96, 0xFF,
827 0x16, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x11, 0x00, 0xA2, 0xFF, 0x22,
828 0x01, 0x45, 0xFD, 0xF1, 0x05, 0x6D, 0xF2, 0x38, 0x3A, 0x03, 0x25,
829 0x8B, 0xF2, 0x0E, 0x07, 0x32, 0xFC, 0xE4, 0x01, 0x3A, 0xFF, 0x36,
830 0x00, 0xFD, 0xFF, 0x0F, 0x00, 0xC2, 0xFF, 0x75, 0x00, 0x7A, 0xFF,
831 0x2B, 0x00, 0x2D, 0x01, 0x61, 0xFA, 0x97, 0x46, 0xA0, 0x0F, 0x20,
832 0xF8, 0xDA, 0x04, 0x10, 0xFD, 0x97, 0x01, 0x50, 0xFF, 0x2E, 0x00,
833 0xFF, 0xFF, 0x00, 0x00, 0x27, 0x00, 0x65, 0xFF, 0x62, 0x01, 0x87,
834 0xFD, 0xE5, 0x03, 0x21, 0xFA, 0x25, 0x0A, 0x33, 0x48, 0x0F, 0xFE,
835 0x57, 0xFF, 0x31, 0x01, 0xEC, 0xFE, 0xB9, 0x00, 0xA7, 0xFF, 0x15,
836 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE4, 0x01, 0x48, 0xFC,
837 0xB2, 0x06, 0xB9, 0xF3, 0xF3, 0x1E, 0x98, 0x3E, 0xCF, 0xF3, 0xF3,
838 0x04, 0xEB, 0xFD, 0xBF, 0x00, 0xD4, 0xFF, 0xFF, 0xFF, 0x03, 0x00,
839 0xFE, 0xFF, 0x23, 0x00, 0x70, 0xFF, 0x84, 0x01, 0xA9, 0xFC, 0xC7,
840 0x06, 0x91, 0xF1, 0xDC, 0x33, 0x87, 0x2C, 0xA5, 0xF1, 0x26, 0x07,
841 0x4B, 0xFC, 0xC6, 0x01, 0x4C, 0xFF, 0x30, 0x00, 0xFD, 0xFF, 0x08,
842 0x00, 0xE2, 0xFF, 0x21, 0x00, 0x23, 0x00, 0xFA, 0xFE, 0x3A, 0x03,
843 0x9D, 0xF6, 0x50, 0x43, 0x00, 0x17, 0xC6, 0xF5, 0xE6, 0x05, 0x97,
844 0xFC, 0xC9, 0x01, 0x3E, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0x00, 0x00,
845 0x1E, 0x00, 0x84, 0xFF, 0x13, 0x01, 0x31, 0xFE, 0x95, 0x02, 0xBA,
846 0xFC, 0xCB, 0x03, 0xF7, 0x48, 0x91, 0x03, 0xD3, 0xFC, 0x88, 0x02,
847 0x38, 0xFE, 0x10, 0x01, 0x85, 0xFF, 0x1E, 0x00, 0xFE, 0xFF, 0x34,
848 0x00, 0x3D, 0xFF, 0xCB, 0x01, 0x93, 0xFC, 0xEF, 0x05, 0xB0, 0xF5,
849 0x4B, 0x17, 0x2A, 0x43, 0x7D, 0xF6, 0x4D, 0x03, 0xEF, 0xFE, 0x2A,
850 0x00, 0x1E, 0x00, 0xE3, 0xFF, 0x08, 0x00, 0xFD, 0xFF, 0x2F, 0x00,
851 0x4D, 0xFF, 0xC4, 0x01, 0x4D, 0xFC, 0x25, 0x07, 0xA1, 0xF1, 0xCE,
852 0x2C, 0x99, 0x33, 0x8E, 0xF1, 0xCD, 0x06, 0xA4, 0xFC, 0x87, 0x01,
853 0x6E, 0xFF, 0x24, 0x00, 0xFD, 0xFF, 0x03, 0x00, 0xFE, 0xFF, 0xD7,
854 0xFF, 0xBA, 0x00, 0xF4, 0xFD, 0xE5, 0x04, 0xE4, 0xF3, 0xCA, 0x3E,
855 0xA7, 0x1E, 0xCA, 0xF3, 0xAC, 0x06, 0x4A, 0xFC, 0xE4, 0x01, 0x36,
856 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x16, 0x00, 0xA6, 0xFF, 0xBD, 0x00,
857 0xE5, 0xFE, 0x3E, 0x01, 0x3F, 0xFF, 0x41, 0xFE, 0x41, 0x48, 0xE4,
858 0x09, 0x3B, 0xFA, 0xD9, 0x03, 0x8D, 0xFD, 0x5F, 0x01, 0x66, 0xFF,
859 0x27, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2E, 0x00, 0x4F, 0xFF, 0x99,
860 0x01, 0x0B, 0xFD, 0xE6, 0x04, 0x08, 0xF8, 0xE7, 0x0F, 0x7C, 0x46,
861 0x37, 0xFA, 0x42, 0x01, 0x1F, 0x00, 0x81, 0xFF, 0x71, 0x00, 0xC3,
862 0xFF, 0x0F, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xE3, 0x01,
863 0x31, 0xFC, 0x11, 0x07, 0x7F, 0xF2, 0x4E, 0x25, 0xFD, 0x39, 0x60,
864 0xF2, 0xFB, 0x05, 0x3E, 0xFD, 0x26, 0x01, 0xA0, 0xFF, 0x12, 0x00,
865 0x00, 0x00, 0xFF, 0xFF, 0x15, 0x00, 0x98, 0xFF, 0x35, 0x01, 0x25,
866 0xFD, 0x1E, 0x06, 0x35, 0xF2, 0x2E, 0x39, 0x55, 0x26, 0x56, 0xF2,
867 0x1A, 0x07, 0x31, 0xFC, 0xE1, 0x01, 0x3C, 0xFF, 0x35, 0x00, 0xFD,
868 0xFF, 0x0E, 0x00, 0xC7, 0xFF, 0x66, 0x00, 0x98, 0xFF, 0xF4, 0xFF,
869 0x8E, 0x01, 0xA7, 0xF9, 0x1D, 0x46, 0xDF, 0x10, 0xB3, 0xF7, 0x0D,
870 0x05, 0xF8, 0xFC, 0xA1, 0x01, 0x4C, 0xFF, 0x2F, 0x00, 0xFF, 0xFF,
871 0x00, 0x00, 0x26, 0x00, 0x6A, 0xFF, 0x55, 0x01, 0xA3, 0xFD, 0xAD,
872 0x03, 0x94, 0xFA, 0xFF, 0x08, 0x70, 0x48, 0xF3, 0xFE, 0xEA, 0xFE,
873 0x6C, 0x01, 0xCD, 0xFE, 0xC9, 0x00, 0xA1, 0xFF, 0x17, 0x00, 0xFE,
874 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE2, 0x01, 0x51, 0xFC, 0x96, 0x06,
875 0x07, 0xF4, 0x9E, 0x1D, 0x77, 0x3F, 0x32, 0xF4, 0xB2, 0x04, 0x15,
876 0xFE, 0xA7, 0x00, 0xE0, 0xFF, 0xFA, 0xFF, 0x03, 0x00, 0xFD, 0xFF,
877 0x26, 0x00, 0x69, 0xFF, 0x91, 0x01, 0x94, 0xFC, 0xE0, 0x06, 0x84,
878 0xF1, 0xAF, 0x32, 0xCA, 0x2D, 0x92, 0xF1, 0x1F, 0x07, 0x56, 0xFC,
879 0xBE, 0x01, 0x51, 0xFF, 0x2E, 0x00, 0xFD, 0xFF, 0x07, 0x00, 0xE7,
880 0xFF, 0x14, 0x00, 0x3F, 0x00, 0xC9, 0xFE, 0x8C, 0x03, 0x11, 0xF6,
881 0x9E, 0x42, 0x50, 0x18, 0x66, 0xF5, 0x0D, 0x06, 0x86, 0xFC, 0xD0,
882 0x01, 0x3B, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0x1D, 0x00, 0x8A, 0xFF,
883 0x04, 0x01, 0x50, 0xFE, 0x5A, 0x02, 0x2C, 0xFD, 0xC6, 0x02, 0xF2,
884 0x48, 0x9B, 0x04, 0x61, 0xFC, 0xC3, 0x02, 0x19, 0xFE, 0x1E, 0x01,
885 0x7F, 0xFF, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0x40,
886 0xFF, 0xC4, 0x01, 0xA5, 0xFC, 0xC5, 0x05, 0x13, 0xF6, 0xFD, 0x15,
887 0xD4, 0x43, 0x0F, 0xF7, 0xF9, 0x02, 0x21, 0xFF, 0x0D, 0x00, 0x2C,
888 0x00, 0xDE, 0xFF, 0x09, 0x00, 0xFD, 0xFF, 0x31, 0x00, 0x49, 0xFF,
889 0xCC, 0x01, 0x44, 0xFC, 0x29, 0x07, 0xB9, 0xF1, 0x89, 0x2B, 0xC3,
890 0x34, 0xA0, 0xF1, 0xB1, 0x06, 0xBA, 0xFC, 0x79, 0x01, 0x76, 0xFF,
891 0x21, 0x00, 0xFE, 0xFF, 0x02, 0x00, 0x02, 0x00, 0xCB, 0xFF, 0xD1,
892 0x00, 0xCC, 0xFD, 0x24, 0x05, 0x87, 0xF3, 0xE4, 0x3D, 0xFD, 0x1F,
893 0x7F, 0xF3, 0xC6, 0x06, 0x41, 0xFC, 0xE5, 0x01, 0x36, 0xFF, 0x36,
894 0x00, 0xFD, 0xFF, 0x14, 0x00, 0xAC, 0xFF, 0xAE, 0x00, 0x05, 0xFF,
895 0x03, 0x01, 0xAA, 0xFF, 0x63, 0xFD, 0xFD, 0x47, 0x0E, 0x0B, 0xC8,
896 0xF9, 0x11, 0x04, 0x71, 0xFD, 0x6C, 0x01, 0x61, 0xFF, 0x28, 0x00,
897 0x00, 0x00, 0xFF, 0xFF, 0x2D, 0x00, 0x53, 0xFF, 0x8F, 0x01, 0x23,
898 0xFD, 0xB2, 0x04, 0x76, 0xF8, 0xAA, 0x0E, 0xED, 0x46, 0xF7, 0xFA,
899 0xDF, 0x00, 0x57, 0x00, 0x62, 0xFF, 0x80, 0x00, 0xBD, 0xFF, 0x10,
900 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x39, 0xFF, 0xE5, 0x01, 0x33, 0xFC,
901 0x03, 0x07, 0xB7, 0xF2, 0xFC, 0x23, 0x03, 0x3B, 0x9E, 0xF2, 0xCB,
902 0x05, 0x5F, 0xFD, 0x12, 0x01, 0xAA, 0xFF, 0x0E, 0x00, 0x00, 0x00,
903 0xFF, 0xFF, 0x18, 0x00, 0x8F, 0xFF, 0x47, 0x01, 0x08, 0xFD, 0x49,
904 0x06, 0x05, 0xF2, 0x1D, 0x38, 0xA6, 0x27, 0x26, 0xF2, 0x23, 0x07,
905 0x33, 0xFC, 0xDD, 0x01, 0x3E, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x0C,
906 0x00, 0xCD, 0xFF, 0x57, 0x00, 0xB6, 0xFF, 0xBE, 0xFF, 0xED, 0x01,
907 0xF5, 0xF8, 0x9B, 0x45, 0x22, 0x12, 0x48, 0xF7, 0x3D, 0x05, 0xE2,
908 0xFC, 0xAB, 0x01, 0x49, 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0x00, 0x00,
909 0x24, 0x00, 0x6F, 0xFF, 0x48, 0x01, 0xC0, 0xFD, 0x73, 0x03, 0x07,
910 0xFB, 0xDD, 0x07, 0xA1, 0x48, 0xDD, 0xFF, 0x7D, 0xFE, 0xA7, 0x01,
911 0xAD, 0xFE, 0xD8, 0x00, 0x9B, 0xFF, 0x18, 0x00, 0xFE, 0xFF, 0x36,
912 0x00, 0x37, 0xFF, 0xDF, 0x01, 0x5C, 0xFC, 0x78, 0x06, 0x5A, 0xF4,
913 0x49, 0x1C, 0x4E, 0x40, 0x9E, 0xF4, 0x6D, 0x04, 0x3F, 0xFE, 0x8E,
914 0x00, 0xED, 0xFF, 0xF6, 0xFF, 0x04, 0x00, 0xFD, 0xFF, 0x28, 0x00,
915 0x62, 0xFF, 0x9E, 0x01, 0x82, 0xFC, 0xF5, 0x06, 0x7D, 0xF1, 0x7B,
916 0x31, 0x09, 0x2F, 0x84, 0xF1, 0x15, 0x07, 0x62, 0xFC, 0xB4, 0x01,
917 0x56, 0xFF, 0x2C, 0x00, 0xFD, 0xFF, 0x06, 0x00, 0xEC, 0xFF, 0x06,
918 0x00, 0x5A, 0x00, 0x9A, 0xFE, 0xDA, 0x03, 0x8D, 0xF5, 0xE1, 0x41,
919 0xA1, 0x19, 0x09, 0xF5, 0x33, 0x06, 0x77, 0xFC, 0xD6, 0x01, 0x3A,
920 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1B, 0x00, 0x8F, 0xFF, 0xF5, 0x00,
921 0x6F, 0xFE, 0x1E, 0x02, 0x9D, 0xFD, 0xC7, 0x01, 0xE1, 0x48, 0xAB,
922 0x05, 0xEE, 0xFB, 0xFE, 0x02, 0xFB, 0xFD, 0x2C, 0x01, 0x7A, 0xFF,
923 0x21, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x32, 0x00, 0x42, 0xFF, 0xBC,
924 0x01, 0xB8, 0xFC, 0x9A, 0x05, 0x77, 0xF6, 0xB1, 0x14, 0x77, 0x44,
925 0xA9, 0xF7, 0xA2, 0x02, 0x54, 0xFF, 0xF1, 0xFF, 0x3A, 0x00, 0xD8,
926 0xFF, 0x0A, 0x00, 0xFD, 0xFF, 0x32, 0x00, 0x45, 0xFF, 0xD3, 0x01,
927 0x3C, 0xFC, 0x2A, 0x07, 0xD8, 0xF1, 0x3F, 0x2A, 0xE6, 0x35, 0xBB,
928 0xF1, 0x92, 0x06, 0xD2, 0xFC, 0x69, 0x01, 0x7E, 0xFF, 0x1F, 0x00,
929 0xFE, 0xFF, 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xE8, 0x00, 0xA6,
930 0xFD, 0x5F, 0x05, 0x31, 0xF3, 0xF6, 0x3C, 0x52, 0x21, 0x37, 0xF3,
931 0xDD, 0x06, 0x3B, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD,
932 0xFF, 0x13, 0x00, 0xB1, 0xFF, 0x9F, 0x00, 0x24, 0xFF, 0xC9, 0x00,
933 0x13, 0x00, 0x8D, 0xFC, 0xAE, 0x47, 0x3E, 0x0C, 0x56, 0xF9, 0x48,
934 0x04, 0x56, 0xFD, 0x78, 0x01, 0x5C, 0xFF, 0x2A, 0x00, 0x00, 0x00,
935 0x00, 0x00, 0x2B, 0x00, 0x58, 0xFF, 0x83, 0x01, 0x3C, 0xFD, 0x7E,
936 0x04, 0xE6, 0xF8, 0x72, 0x0D, 0x52, 0x47, 0xBE, 0xFB, 0x7A, 0x00,
937 0x90, 0x00, 0x43, 0xFF, 0x8F, 0x00, 0xB7, 0xFF, 0x11, 0x00, 0xFD,
938 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x36, 0xFC, 0xF1, 0x06,
939 0xF5, 0xF2, 0xA7, 0x22, 0xFF, 0x3B, 0xE4, 0xF2, 0x96, 0x05, 0x81,
940 0xFD, 0xFD, 0x00, 0xB5, 0xFF, 0x0B, 0x00, 0x01, 0x00, 0xFE, 0xFF,
941 0x1C, 0x00, 0x86, 0xFF, 0x59, 0x01, 0xEC, 0xFC, 0x6F, 0x06, 0xDC,
942 0xF1, 0x04, 0x37, 0xF3, 0x28, 0xFC, 0xF1, 0x28, 0x07, 0x37, 0xFC,
943 0xD8, 0x01, 0x41, 0xFF, 0x33, 0x00, 0xFD, 0xFF, 0x0B, 0x00, 0xD3,
944 0xFF, 0x49, 0x00, 0xD4, 0xFF, 0x88, 0xFF, 0x49, 0x02, 0x4B, 0xF8,
945 0x0D, 0x45, 0x68, 0x13, 0xDF, 0xF6, 0x6C, 0x05, 0xCC, 0xFC, 0xB4,
946 0x01, 0x45, 0xFF, 0x31, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x23, 0x00,
947 0x74, 0xFF, 0x3A, 0x01, 0xDD, 0xFD, 0x39, 0x03, 0x7B, 0xFB, 0xC1,
948 0x06, 0xC7, 0x48, 0xCF, 0x00, 0x0D, 0xFE, 0xE3, 0x01, 0x8E, 0xFE,
949 0xE7, 0x00, 0x95, 0xFF, 0x1A, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x38,
950 0xFF, 0xDA, 0x01, 0x69, 0xFC, 0x57, 0x06, 0xAF, 0xF4, 0xF5, 0x1A,
951 0x1D, 0x41, 0x11, 0xF5, 0x25, 0x04, 0x6C, 0xFE, 0x74, 0x00, 0xF9,
952 0xFF, 0xF1, 0xFF, 0x05, 0x00, 0xFD, 0xFF, 0x2A, 0x00, 0x5C, 0xFF,
953 0xAA, 0x01, 0x71, 0xFC, 0x07, 0x07, 0x7E, 0xF1, 0x44, 0x30, 0x44,
954 0x30, 0x7E, 0xF1, 0x07, 0x07, 0x71, 0xFC, 0xAA, 0x01, 0x5C, 0xFF,
955 0x2A, 0x00, 0xFD, 0xFF, 0x05, 0x00, 0xF1, 0xFF, 0xF9, 0xFF, 0x74,
956 0x00, 0x6C, 0xFE, 0x25, 0x04, 0x11, 0xF5, 0x1D, 0x41, 0xF5, 0x1A,
957 0xAF, 0xF4, 0x57, 0x06, 0x69, 0xFC, 0xDA, 0x01, 0x38, 0xFF, 0x36,
958 0x00, 0xFE, 0xFF, 0x1A, 0x00, 0x95, 0xFF, 0xE7, 0x00, 0x8E, 0xFE,
959 0xE3, 0x01, 0x0D, 0xFE, 0xCF, 0x00, 0xC7, 0x48, 0xC1, 0x06, 0x7B,
960 0xFB, 0x39, 0x03, 0xDD, 0xFD, 0x3A, 0x01, 0x74, 0xFF, 0x23, 0x00,
961 0x00, 0x00, 0xFF, 0xFF, 0x31, 0x00, 0x45, 0xFF, 0xB4, 0x01, 0xCC,
962 0xFC, 0x6C, 0x05, 0xDF, 0xF6, 0x68, 0x13, 0x0D, 0x45, 0x4B, 0xF8,
963 0x49, 0x02, 0x88, 0xFF, 0xD4, 0xFF, 0x49, 0x00, 0xD3, 0xFF, 0x0B,
964 0x00, 0xFD, 0xFF, 0x33, 0x00, 0x41, 0xFF, 0xD8, 0x01, 0x37, 0xFC,
965 0x28, 0x07, 0xFC, 0xF1, 0xF3, 0x28, 0x04, 0x37, 0xDC, 0xF1, 0x6F,
966 0x06, 0xEC, 0xFC, 0x59, 0x01, 0x86, 0xFF, 0x1C, 0x00, 0xFE, 0xFF,
967 0x01, 0x00, 0x0B, 0x00, 0xB5, 0xFF, 0xFD, 0x00, 0x81, 0xFD, 0x96,
968 0x05, 0xE4, 0xF2, 0xFF, 0x3B, 0xA7, 0x22, 0xF5, 0xF2, 0xF1, 0x06,
969 0x36, 0xFC, 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x11,
970 0x00, 0xB7, 0xFF, 0x8F, 0x00, 0x43, 0xFF, 0x90, 0x00, 0x7A, 0x00,
971 0xBE, 0xFB, 0x52, 0x47, 0x72, 0x0D, 0xE6, 0xF8, 0x7E, 0x04, 0x3C,
972 0xFD, 0x83, 0x01, 0x58, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00,
973 0x2A, 0x00, 0x5C, 0xFF, 0x78, 0x01, 0x56, 0xFD, 0x48, 0x04, 0x56,
974 0xF9, 0x3E, 0x0C, 0xAE, 0x47, 0x8D, 0xFC, 0x13, 0x00, 0xC9, 0x00,
975 0x24, 0xFF, 0x9F, 0x00, 0xB1, 0xFF, 0x13, 0x00, 0xFD, 0xFF, 0x36,
976 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3B, 0xFC, 0xDD, 0x06, 0x37, 0xF3,
977 0x52, 0x21, 0xF6, 0x3C, 0x31, 0xF3, 0x5F, 0x05, 0xA6, 0xFD, 0xE8,
978 0x00, 0xC0, 0xFF, 0x07, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x1F, 0x00,
979 0x7E, 0xFF, 0x69, 0x01, 0xD2, 0xFC, 0x92, 0x06, 0xBB, 0xF1, 0xE6,
980 0x35, 0x3F, 0x2A, 0xD8, 0xF1, 0x2A, 0x07, 0x3C, 0xFC, 0xD3, 0x01,
981 0x45, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0x0A, 0x00, 0xD8, 0xFF, 0x3A,
982 0x00, 0xF1, 0xFF, 0x54, 0xFF, 0xA2, 0x02, 0xA9, 0xF7, 0x77, 0x44,
983 0xB1, 0x14, 0x77, 0xF6, 0x9A, 0x05, 0xB8, 0xFC, 0xBC, 0x01, 0x42,
984 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x21, 0x00, 0x7A, 0xFF,
985 0x2C, 0x01, 0xFB, 0xFD, 0xFE, 0x02, 0xEE, 0xFB, 0xAB, 0x05, 0xE1,
986 0x48, 0xC7, 0x01, 0x9D, 0xFD, 0x1E, 0x02, 0x6F, 0xFE, 0xF5, 0x00,
987 0x8F, 0xFF, 0x1B, 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xD6,
988 0x01, 0x77, 0xFC, 0x33, 0x06, 0x09, 0xF5, 0xA1, 0x19, 0xE1, 0x41,
989 0x8D, 0xF5, 0xDA, 0x03, 0x9A, 0xFE, 0x5A, 0x00, 0x06, 0x00, 0xEC,
990 0xFF, 0x06, 0x00, 0xFD, 0xFF, 0x2C, 0x00, 0x56, 0xFF, 0xB4, 0x01,
991 0x62, 0xFC, 0x15, 0x07, 0x84, 0xF1, 0x09, 0x2F, 0x7B, 0x31, 0x7D,
992 0xF1, 0xF5, 0x06, 0x82, 0xFC, 0x9E, 0x01, 0x62, 0xFF, 0x28, 0x00,
993 0xFD, 0xFF, 0x04, 0x00, 0xF6, 0xFF, 0xED, 0xFF, 0x8E, 0x00, 0x3F,
994 0xFE, 0x6D, 0x04, 0x9E, 0xF4, 0x4E, 0x40, 0x49, 0x1C, 0x5A, 0xF4,
995 0x78, 0x06, 0x5C, 0xFC, 0xDF, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE,
996 0xFF, 0x18, 0x00, 0x9B, 0xFF, 0xD8, 0x00, 0xAD, 0xFE, 0xA7, 0x01,
997 0x7D, 0xFE, 0xDD, 0xFF, 0xA1, 0x48, 0xDD, 0x07, 0x07, 0xFB, 0x73,
998 0x03, 0xC0, 0xFD, 0x48, 0x01, 0x6F, 0xFF, 0x24, 0x00, 0x00, 0x00,
999 0xFF, 0xFF, 0x30, 0x00, 0x49, 0xFF, 0xAB, 0x01, 0xE2, 0xFC, 0x3D,
1000 0x05, 0x48, 0xF7, 0x22, 0x12, 0x9B, 0x45, 0xF5, 0xF8, 0xED, 0x01,
1001 0xBE, 0xFF, 0xB6, 0xFF, 0x57, 0x00, 0xCD, 0xFF, 0x0C, 0x00, 0xFD,
1002 0xFF, 0x34, 0x00, 0x3E, 0xFF, 0xDD, 0x01, 0x33, 0xFC, 0x23, 0x07,
1003 0x26, 0xF2, 0xA6, 0x27, 0x1D, 0x38, 0x05, 0xF2, 0x49, 0x06, 0x08,
1004 0xFD, 0x47, 0x01, 0x8F, 0xFF, 0x18, 0x00, 0xFF, 0xFF, 0x00, 0x00,
1005 0x0E, 0x00, 0xAA, 0xFF, 0x12, 0x01, 0x5F, 0xFD, 0xCB, 0x05, 0x9E,
1006 0xF2, 0x03, 0x3B, 0xFC, 0x23, 0xB7, 0xF2, 0x03, 0x07, 0x33, 0xFC,
1007 0xE5, 0x01, 0x39, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x10, 0x00, 0xBD,
1008 0xFF, 0x80, 0x00, 0x62, 0xFF, 0x57, 0x00, 0xDF, 0x00, 0xF7, 0xFA,
1009 0xED, 0x46, 0xAA, 0x0E, 0x76, 0xF8, 0xB2, 0x04, 0x23, 0xFD, 0x8F,
1010 0x01, 0x53, 0xFF, 0x2D, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x28, 0x00,
1011 0x61, 0xFF, 0x6C, 0x01, 0x71, 0xFD, 0x11, 0x04, 0xC8, 0xF9, 0x0E,
1012 0x0B, 0xFD, 0x47, 0x63, 0xFD, 0xAA, 0xFF, 0x03, 0x01, 0x05, 0xFF,
1013 0xAE, 0x00, 0xAC, 0xFF, 0x14, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36,
1014 0xFF, 0xE5, 0x01, 0x41, 0xFC, 0xC6, 0x06, 0x7F, 0xF3, 0xFD, 0x1F,
1015 0xE4, 0x3D, 0x87, 0xF3, 0x24, 0x05, 0xCC, 0xFD, 0xD1, 0x00, 0xCB,
1016 0xFF, 0x02, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x21, 0x00, 0x76, 0xFF,
1017 0x79, 0x01, 0xBA, 0xFC, 0xB1, 0x06, 0xA0, 0xF1, 0xC3, 0x34, 0x89,
1018 0x2B, 0xB9, 0xF1, 0x29, 0x07, 0x44, 0xFC, 0xCC, 0x01, 0x49, 0xFF,
1019 0x31, 0x00, 0xFD, 0xFF, 0x09, 0x00, 0xDE, 0xFF, 0x2C, 0x00, 0x0D,
1020 0x00, 0x21, 0xFF, 0xF9, 0x02, 0x0F, 0xF7, 0xD4, 0x43, 0xFD, 0x15,
1021 0x13, 0xF6, 0xC5, 0x05, 0xA5, 0xFC, 0xC4, 0x01, 0x40, 0xFF, 0x33,
1022 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x20, 0x00, 0x7F, 0xFF, 0x1E, 0x01,
1023 0x19, 0xFE, 0xC3, 0x02, 0x61, 0xFC, 0x9B, 0x04, 0xF2, 0x48, 0xC6,
1024 0x02, 0x2C, 0xFD, 0x5A, 0x02, 0x50, 0xFE, 0x04, 0x01, 0x8A, 0xFF,
1025 0x1D, 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3B, 0xFF, 0xD0, 0x01, 0x86,
1026 0xFC, 0x0D, 0x06, 0x66, 0xF5, 0x50, 0x18, 0x9E, 0x42, 0x11, 0xF6,
1027 0x8C, 0x03, 0xC9, 0xFE, 0x3F, 0x00, 0x14, 0x00, 0xE7, 0xFF, 0x07,
1028 0x00, 0xFD, 0xFF, 0x2E, 0x00, 0x51, 0xFF, 0xBE, 0x01, 0x56, 0xFC,
1029 0x1F, 0x07, 0x92, 0xF1, 0xCA, 0x2D, 0xAF, 0x32, 0x84, 0xF1, 0xE0,
1030 0x06, 0x94, 0xFC, 0x91, 0x01, 0x69, 0xFF, 0x26, 0x00, 0xFD, 0xFF,
1031 0x03, 0x00, 0xFA, 0xFF, 0xE0, 0xFF, 0xA7, 0x00, 0x15, 0xFE, 0xB2,
1032 0x04, 0x32, 0xF4, 0x77, 0x3F, 0x9E, 0x1D, 0x07, 0xF4, 0x96, 0x06,
1033 0x51, 0xFC, 0xE2, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x17,
1034 0x00, 0xA1, 0xFF, 0xC9, 0x00, 0xCD, 0xFE, 0x6C, 0x01, 0xEA, 0xFE,
1035 0xF3, 0xFE, 0x70, 0x48, 0xFF, 0x08, 0x94, 0xFA, 0xAD, 0x03, 0xA3,
1036 0xFD, 0x55, 0x01, 0x6A, 0xFF, 0x26, 0x00, 0x00, 0x00, 0xFF, 0xFF,
1037 0x2F, 0x00, 0x4C, 0xFF, 0xA1, 0x01, 0xF8, 0xFC, 0x0D, 0x05, 0xB3,
1038 0xF7, 0xDF, 0x10, 0x1D, 0x46, 0xA7, 0xF9, 0x8E, 0x01, 0xF4, 0xFF,
1039 0x98, 0xFF, 0x66, 0x00, 0xC7, 0xFF, 0x0E, 0x00, 0xFD, 0xFF, 0x35,
1040 0x00, 0x3C, 0xFF, 0xE1, 0x01, 0x31, 0xFC, 0x1A, 0x07, 0x56, 0xF2,
1041 0x55, 0x26, 0x2E, 0x39, 0x35, 0xF2, 0x1E, 0x06, 0x25, 0xFD, 0x35,
1042 0x01, 0x98, 0xFF, 0x15, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x12, 0x00,
1043 0xA0, 0xFF, 0x26, 0x01, 0x3E, 0xFD, 0xFB, 0x05, 0x60, 0xF2, 0xFD,
1044 0x39, 0x4E, 0x25, 0x7F, 0xF2, 0x11, 0x07, 0x31, 0xFC, 0xE3, 0x01,
1045 0x3A, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x0F, 0x00, 0xC3, 0xFF, 0x71,
1046 0x00, 0x81, 0xFF, 0x1F, 0x00, 0x42, 0x01, 0x37, 0xFA, 0x7C, 0x46,
1047 0xE7, 0x0F, 0x08, 0xF8, 0xE6, 0x04, 0x0B, 0xFD, 0x99, 0x01, 0x4F,
1048 0xFF, 0x2E, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x27, 0x00, 0x66, 0xFF,
1049 0x5F, 0x01, 0x8D, 0xFD, 0xD9, 0x03, 0x3B, 0xFA, 0xE4, 0x09, 0x41,
1050 0x48, 0x41, 0xFE, 0x3F, 0xFF, 0x3E, 0x01, 0xE5, 0xFE, 0xBD, 0x00,
1051 0xA6, 0xFF, 0x16, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE4,
1052 0x01, 0x4A, 0xFC, 0xAC, 0x06, 0xCA, 0xF3, 0xA7, 0x1E, 0xCA, 0x3E,
1053 0xE4, 0xF3, 0xE5, 0x04, 0xF4, 0xFD, 0xBA, 0x00, 0xD7, 0xFF, 0xFE,
1054 0xFF, 0x03, 0x00, 0xFD, 0xFF, 0x24, 0x00, 0x6E, 0xFF, 0x87, 0x01,
1055 0xA4, 0xFC, 0xCD, 0x06, 0x8E, 0xF1, 0x99, 0x33, 0xCE, 0x2C, 0xA1,
1056 0xF1, 0x25, 0x07, 0x4D, 0xFC, 0xC4, 0x01, 0x4D, 0xFF, 0x2F, 0x00,
1057 0xFD, 0xFF, 0x08, 0x00, 0xE3, 0xFF, 0x1E, 0x00, 0x2A, 0x00, 0xEF,
1058 0xFE, 0x4D, 0x03, 0x7D, 0xF6, 0x2A, 0x43, 0x4B, 0x17, 0xB0, 0xF5,
1059 0xEF, 0x05, 0x93, 0xFC, 0xCB, 0x01, 0x3D, 0xFF, 0x34, 0x00, 0xFE,
1060 0xFF, 0x1E, 0x00, 0x85, 0xFF, 0x10, 0x01, 0x38, 0xFE, 0x88, 0x02,
1061 0xD3, 0xFC, 0x91, 0x03, 0xF7, 0x48, 0xCB, 0x03, 0xBA, 0xFC, 0x95,
1062 0x02, 0x31, 0xFE, 0x13, 0x01, 0x84, 0xFF, 0x1E, 0x00, 0x00, 0x00,
1063 0xFE, 0xFF, 0x34, 0x00, 0x3E, 0xFF, 0xC9, 0x01, 0x97, 0xFC, 0xE6,
1064 0x05, 0xC6, 0xF5, 0x00, 0x17, 0x50, 0x43, 0x9D, 0xF6, 0x3A, 0x03,
1065 0xFA, 0xFE, 0x23, 0x00, 0x21, 0x00, 0xE2, 0xFF, 0x08, 0x00, 0xFD,
1066 0xFF, 0x30, 0x00, 0x4C, 0xFF, 0xC6, 0x01, 0x4B, 0xFC, 0x26, 0x07,
1067 0xA5, 0xF1, 0x87, 0x2C, 0xDC, 0x33, 0x91, 0xF1, 0xC7, 0x06, 0xA9,
1068 0xFC, 0x84, 0x01, 0x70, 0xFF, 0x23, 0x00, 0xFE, 0xFF, 0x03, 0x00,
1069 0xFF, 0xFF, 0xD4, 0xFF, 0xBF, 0x00, 0xEB, 0xFD, 0xF3, 0x04, 0xCF,
1070 0xF3, 0x98, 0x3E, 0xF3, 0x1E, 0xB9, 0xF3, 0xB2, 0x06, 0x48, 0xFC,
1071 0xE4, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x15, 0x00, 0xA7,
1072 0xFF, 0xB9, 0x00, 0xEC, 0xFE, 0x31, 0x01, 0x57, 0xFF, 0x0F, 0xFE,
1073 0x33, 0x48, 0x25, 0x0A, 0x21, 0xFA, 0xE5, 0x03, 0x87, 0xFD, 0x62,
1074 0x01, 0x65, 0xFF, 0x27, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2E, 0x00,
1075 0x50, 0xFF, 0x97, 0x01, 0x10, 0xFD, 0xDA, 0x04, 0x20, 0xF8, 0xA0,
1076 0x0F, 0x97, 0x46, 0x61, 0xFA, 0x2D, 0x01, 0x2B, 0x00, 0x7A, 0xFF,
1077 0x75, 0x00, 0xC2, 0xFF, 0x0F, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x3A,
1078 0xFF, 0xE4, 0x01, 0x32, 0xFC, 0x0E, 0x07, 0x8B, 0xF2, 0x03, 0x25,
1079 0x38, 0x3A, 0x6D, 0xF2, 0xF1, 0x05, 0x45, 0xFD, 0x22, 0x01, 0xA2,
1080 0xFF, 0x11, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x16, 0x00, 0x96, 0xFF,
1081 0x39, 0x01, 0x1F, 0xFD, 0x28, 0x06, 0x2A, 0xF2, 0xF2, 0x38, 0xA0,
1082 0x26, 0x4B, 0xF2, 0x1C, 0x07, 0x32, 0xFC, 0xE0, 0x01, 0x3C, 0xFF,
1083 0x35, 0x00, 0xFD, 0xFF, 0x0D, 0x00, 0xC9, 0xFF, 0x63, 0x00, 0x9F,
1084 0xFF, 0xE8, 0xFF, 0xA3, 0x01, 0x7F, 0xF9, 0x02, 0x46, 0x27, 0x11,
1085 0x9B, 0xF7, 0x18, 0x05, 0xF3, 0xFC, 0xA3, 0x01, 0x4C, 0xFF, 0x2F,
1086 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x25, 0x00, 0x6B, 0xFF, 0x52, 0x01,
1087 0xA9, 0xFD, 0xA0, 0x03, 0xAE, 0xFA, 0xBE, 0x08, 0x7C, 0x48, 0x26,
1088 0xFF, 0xD2, 0xFE, 0x79, 0x01, 0xC6, 0xFE, 0xCC, 0x00, 0xA0, 0xFF,
1089 0x17, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE1, 0x01, 0x53,
1090 0xFC, 0x90, 0x06, 0x19, 0xF4, 0x52, 0x1D, 0xA8, 0x3F, 0x49, 0xF4,
1091 0xA3, 0x04, 0x1E, 0xFE, 0xA1, 0x00, 0xE3, 0xFF, 0xF9, 0xFF, 0x04,
1092 0x00, 0xFD, 0xFF, 0x26, 0x00, 0x67, 0xFF, 0x94, 0x01, 0x90, 0xFC,
1093 0xE5, 0x06, 0x81, 0xF1, 0x6B, 0x32, 0x11, 0x2E, 0x8E, 0xF1, 0x1D,
1094 0x07, 0x58, 0xFC, 0xBC, 0x01, 0x52, 0xFF, 0x2E, 0x00, 0xFD, 0xFF,
1095 0x07, 0x00, 0xE8, 0xFF, 0x11, 0x00, 0x45, 0x00, 0xBF, 0xFE, 0x9D,
1096 0x03, 0xF3, 0xF5, 0x75, 0x42, 0x9B, 0x18, 0x51, 0xF5, 0x16, 0x06,
1097 0x83, 0xFC, 0xD1, 0x01, 0x3B, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0x1D,
1098 0x00, 0x8B, 0xFF, 0x01, 0x01, 0x56, 0xFE, 0x4D, 0x02, 0x45, 0xFD,
1099 0x8D, 0x02, 0xF0, 0x48, 0xD7, 0x04, 0x47, 0xFC, 0xD1, 0x02, 0x12,
1100 0xFE, 0x21, 0x01, 0x7E, 0xFF, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF,
1101 0x33, 0x00, 0x40, 0xFF, 0xC2, 0x01, 0xA9, 0xFC, 0xBC, 0x05, 0x29,
1102 0xF6, 0xB3, 0x15, 0xFA, 0x43, 0x31, 0xF7, 0xE6, 0x02, 0x2C, 0xFF,
1103 0x07, 0x00, 0x2F, 0x00, 0xDC, 0xFF, 0x09, 0x00, 0xFD, 0xFF, 0x31,
1104 0x00, 0x48, 0xFF, 0xCE, 0x01, 0x42, 0xFC, 0x2A, 0x07, 0xBF, 0xF1,
1105 0x40, 0x2B, 0x05, 0x35, 0xA6, 0xF1, 0xAB, 0x06, 0xBF, 0xFC, 0x75,
1106 0x01, 0x77, 0xFF, 0x21, 0x00, 0xFE, 0xFF, 0x02, 0x00, 0x03, 0x00,
1107 0xC8, 0xFF, 0xD6, 0x00, 0xC4, 0xFD, 0x31, 0x05, 0x73, 0xF3, 0xB0,
1108 0x3D, 0x49, 0x20, 0x6E, 0xF3, 0xCB, 0x06, 0x40, 0xFC, 0xE6, 0x01,
1109 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x14, 0x00, 0xAD, 0xFF, 0xAA,
1110 0x00, 0x0C, 0xFF, 0xF7, 0x00, 0xC1, 0xFF, 0x33, 0xFD, 0xEC, 0x47,
1111 0x51, 0x0B, 0xAF, 0xF9, 0x1D, 0x04, 0x6B, 0xFD, 0x6E, 0x01, 0x60,
1112 0xFF, 0x29, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2C, 0x00, 0x54, 0xFF,
1113 0x8C, 0x01, 0x29, 0xFD, 0xA7, 0x04, 0x8F, 0xF8, 0x64, 0x0E, 0x02,
1114 0x47, 0x22, 0xFB, 0xC9, 0x00, 0x64, 0x00, 0x5B, 0xFF, 0x84, 0x00,
1115 0xBC, 0xFF, 0x10, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xE5,
1116 0x01, 0x33, 0xFC, 0xFF, 0x06, 0xC4, 0xF2, 0xB0, 0x23, 0x3B, 0x3B,
1117 0xAD, 0xF2, 0xBF, 0x05, 0x66, 0xFD, 0x0E, 0x01, 0xAC, 0xFF, 0x0E,
1118 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x19, 0x00, 0x8D, 0xFF, 0x4B, 0x01,
1119 0x01, 0xFD, 0x51, 0x06, 0xFB, 0xF1, 0xDF, 0x37, 0xF0, 0x27, 0x1C,
1120 0xF2, 0x24, 0x07, 0x34, 0xFC, 0xDC, 0x01, 0x3F, 0xFF, 0x34, 0x00,
1121 0xFD, 0xFF, 0x0C, 0x00, 0xCE, 0xFF, 0x54, 0x00, 0xBD, 0xFF, 0xB2,
1122 0xFF, 0x01, 0x02, 0xCF, 0xF8, 0x7D, 0x45, 0x6B, 0x12, 0x30, 0xF7,
1123 0x48, 0x05, 0xDD, 0xFC, 0xAD, 0x01, 0x48, 0xFF, 0x30, 0x00, 0xFF,
1124 0xFF, 0x00, 0x00, 0x24, 0x00, 0x70, 0xFF, 0x45, 0x01, 0xC6, 0xFD,
1125 0x66, 0x03, 0x21, 0xFB, 0x9E, 0x07, 0xAA, 0x48, 0x12, 0x00, 0x64,
1126 0xFE, 0xB4, 0x01, 0xA6, 0xFE, 0xDB, 0x00, 0x9A, 0xFF, 0x19, 0x00,
1127 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xDE, 0x01, 0x5F, 0xFC, 0x70,
1128 0x06, 0x6C, 0xF4, 0xFD, 0x1B, 0x7D, 0x40, 0xB7, 0xF4, 0x5D, 0x04,
1129 0x49, 0xFE, 0x88, 0x00, 0xEF, 0xFF, 0xF5, 0xFF, 0x04, 0x00, 0xFD,
1130 0xFF, 0x29, 0x00, 0x61, 0xFF, 0xA1, 0x01, 0x7E, 0xFC, 0xF9, 0x06,
1131 0x7C, 0xF1, 0x38, 0x31, 0x50, 0x2F, 0x82, 0xF1, 0x12, 0x07, 0x65,
1132 0xFC, 0xB2, 0x01, 0x57, 0xFF, 0x2C, 0x00, 0xFD, 0xFF, 0x06, 0x00,
1133 0xED, 0xFF, 0x04, 0x00, 0x60, 0x00, 0x90, 0xFE, 0xEB, 0x03, 0x71,
1134 0xF5, 0xB7, 0x41, 0xED, 0x19, 0xF5, 0xF4, 0x3B, 0x06, 0x73, 0xFC,
1135 0xD7, 0x01, 0x39, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1B, 0x00, 0x91,
1136 0xFF, 0xF2, 0x00, 0x76, 0xFE, 0x11, 0x02, 0xB6, 0xFD, 0x8F, 0x01,
1137 0xDE, 0x48, 0xE9, 0x05, 0xD4, 0xFB, 0x0C, 0x03, 0xF4, 0xFD, 0x2F,
1138 0x01, 0x79, 0xFF, 0x22, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x32, 0x00,
1139 0x43, 0xFF, 0xBA, 0x01, 0xBC, 0xFC, 0x90, 0x05, 0x8E, 0xF6, 0x68,
1140 0x14, 0x99, 0x44, 0xCD, 0xF7, 0x8F, 0x02, 0x60, 0xFF, 0xEA, 0xFF,
1141 0x3E, 0x00, 0xD7, 0xFF, 0x0A, 0x00, 0xFD, 0xFF, 0x32, 0x00, 0x44,
1142 0xFF, 0xD4, 0x01, 0x3B, 0xFC, 0x2A, 0x07, 0xDF, 0xF1, 0xF6, 0x29,
1143 0x27, 0x36, 0xC1, 0xF1, 0x8B, 0x06, 0xD8, 0xFC, 0x66, 0x01, 0x80,
1144 0xFF, 0x1E, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x07, 0x00, 0xBD, 0xFF,
1145 0xED, 0x00, 0x9E, 0xFD, 0x6C, 0x05, 0x1F, 0xF3, 0xC0, 0x3C, 0x9E,
1146 0x21, 0x28, 0xF3, 0xE2, 0x06, 0x3A, 0xFC, 0xE6, 0x01, 0x37, 0xFF,
1147 0x36, 0x00, 0xFD, 0xFF, 0x12, 0x00, 0xB3, 0xFF, 0x9B, 0x00, 0x2B,
1148 0xFF, 0xBD, 0x00, 0x2A, 0x00, 0x5E, 0xFC, 0x9A, 0x47, 0x82, 0x0C,
1149 0x3D, 0xF9, 0x54, 0x04, 0x50, 0xFD, 0x7A, 0x01, 0x5B, 0xFF, 0x2A,
1150 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x59, 0xFF, 0x81, 0x01,
1151 0x42, 0xFD, 0x72, 0x04, 0xFF, 0xF8, 0x2D, 0x0D, 0x69, 0x47, 0xEB,
1152 0xFB, 0x63, 0x00, 0x9D, 0x00, 0x3C, 0xFF, 0x93, 0x00, 0xB6, 0xFF,
1153 0x12, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x37,
1154 0xFC, 0xED, 0x06, 0x03, 0xF3, 0x5B, 0x22, 0x37, 0x3C, 0xF4, 0xF2,
1155 0x8A, 0x05, 0x89, 0xFD, 0xF9, 0x00, 0xB7, 0xFF, 0x0A, 0x00, 0x01,
1156 0x00, 0xFE, 0xFF, 0x1C, 0x00, 0x84, 0xFF, 0x5C, 0x01, 0xE6, 0xFC,
1157 0x77, 0x06, 0xD4, 0xF1, 0xC6, 0x36, 0x3E, 0x29, 0xF3, 0xF1, 0x29,
1158 0x07, 0x38, 0xFC, 0xD7, 0x01, 0x42, 0xFF, 0x33, 0x00, 0xFD, 0xFF,
1159 0x0B, 0x00, 0xD4, 0xFF, 0x46, 0x00, 0xDA, 0xFF, 0x7D, 0xFF, 0x5D,
1160 0x02, 0x26, 0xF8, 0xED, 0x44, 0xB1, 0x13, 0xC7, 0xF6, 0x77, 0x05,
1161 0xC8, 0xFC, 0xB6, 0x01, 0x45, 0xFF, 0x31, 0x00, 0xFF, 0xFF, 0x00,
1162 0x00, 0x22, 0x00, 0x76, 0xFF, 0x37, 0x01, 0xE4, 0xFD, 0x2C, 0x03,
1163 0x94, 0xFB, 0x83, 0x06, 0xCE, 0x48, 0x05, 0x01, 0xF5, 0xFD, 0xF0,
1164 0x01, 0x87, 0xFE, 0xEA, 0x00, 0x94, 0xFF, 0x1A, 0x00, 0xFE, 0xFF,
1165 0x35, 0x00, 0x38, 0xFF, 0xD9, 0x01, 0x6C, 0xFC, 0x4F, 0x06, 0xC3,
1166 0xF4, 0xA9, 0x1A, 0x49, 0x41, 0x2C, 0xF5, 0x15, 0x04, 0x76, 0xFE,
1167 0x6E, 0x00, 0xFC, 0xFF, 0xF0, 0xFF, 0x05, 0x00, 0xFD, 0xFF, 0x2B,
1168 0x00, 0x5A, 0xFF, 0xAC, 0x01, 0x6E, 0xFC, 0x0A, 0x07, 0x7E, 0xF1,
1169 0xFF, 0x2F, 0x8A, 0x30, 0x7D, 0xF1, 0x03, 0x07, 0x75, 0xFC, 0xA7,
1170 0x01, 0x5D, 0xFF, 0x2A, 0x00, 0xFD, 0xFF, 0x05, 0x00, 0xF2, 0xFF,
1171 0xF7, 0xFF, 0x7A, 0x00, 0x62, 0xFE, 0x35, 0x04, 0xF7, 0xF4, 0xEF,
1172 0x40, 0x40, 0x1B, 0x9C, 0xF4, 0x5E, 0x06, 0x66, 0xFC, 0xDB, 0x01,
1173 0x38, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x1A, 0x00, 0x96, 0xFF, 0xE3,
1174 0x00, 0x95, 0xFE, 0xD5, 0x01, 0x26, 0xFE, 0x98, 0x00, 0xBF, 0x48,
1175 0x00, 0x07, 0x61, 0xFB, 0x46, 0x03, 0xD6, 0xFD, 0x3D, 0x01, 0x73,
1176 0xFF, 0x23, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x31, 0x00, 0x46, 0xFF,
1177 0xB2, 0x01, 0xD1, 0xFC, 0x62, 0x05, 0xF6, 0xF6, 0x20, 0x13, 0x2E,
1178 0x45, 0x70, 0xF8, 0x34, 0x02, 0x94, 0xFF, 0xCD, 0xFF, 0x4C, 0x00,
1179 0xD2, 0xFF, 0x0B, 0x00, 0xFD, 0xFF, 0x33, 0x00, 0x41, 0xFF, 0xDA,
1180 0x01, 0x36, 0xFC, 0x27, 0x07, 0x05, 0xF2, 0xAA, 0x28, 0x44, 0x37,
1181 0xE4, 0xF1, 0x67, 0x06, 0xF2, 0xFC, 0x55, 0x01, 0x88, 0xFF, 0x1B,
1182 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x0B, 0x00, 0xB2, 0xFF, 0x02, 0x01,
1183 0x7A, 0xFD, 0xA2, 0x05, 0xD4, 0xF2, 0xC7, 0x3B, 0xF2, 0x22, 0xE7,
1184 0xF2, 0xF5, 0x06, 0x35, 0xFC, 0xE6, 0x01, 0x38, 0xFF, 0x36, 0x00,
1185 0xFD, 0xFF, 0x11, 0x00, 0xB9, 0xFF, 0x8C, 0x00, 0x4A, 0xFF, 0x83,
1186 0x00, 0x91, 0x00, 0x91, 0xFB, 0x3D, 0x47, 0xB7, 0x0D, 0xCD, 0xF8,
1187 0x89, 0x04, 0x36, 0xFD, 0x86, 0x01, 0x57, 0xFF, 0x2B, 0x00, 0x00,
1188 0x00, 0x00, 0x00, 0x2A, 0x00, 0x5D, 0xFF, 0x75, 0x01, 0x5C, 0xFD,
1189 0x3C, 0x04, 0x70, 0xF9, 0xFA, 0x0B, 0xC0, 0x47, 0xBC, 0xFC, 0xFC,
1190 0xFF, 0xD6, 0x00, 0x1D, 0xFF, 0xA2, 0x00, 0xB0, 0xFF, 0x13, 0x00,
1191 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3C, 0xFC, 0xD8,
1192 0x06, 0x47, 0xF3, 0x06, 0x21, 0x2A, 0x3D, 0x44, 0xF3, 0x52, 0x05,
1193 0xAE, 0xFD, 0xE3, 0x00, 0xC2, 0xFF, 0x06, 0x00, 0x01, 0x00, 0xFE,
1194 0xFF, 0x1F, 0x00, 0x7C, 0xFF, 0x6D, 0x01, 0xCD, 0xFC, 0x99, 0x06,
1195 0xB4, 0xF1, 0xA6, 0x35, 0x89, 0x2A, 0xD0, 0xF1, 0x2B, 0x07, 0x3E,
1196 0xFC, 0xD1, 0x01, 0x46, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0x0A, 0x00,
1197 0xD9, 0xFF, 0x37, 0x00, 0xF7, 0xFF, 0x49, 0xFF, 0xB6, 0x02, 0x86,
1198 0xF7, 0x53, 0x44, 0xFB, 0x14, 0x61, 0xF6, 0xA4, 0x05, 0xB4, 0xFC,
1199 0xBE, 0x01, 0x42, 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x21,
1200 0x00, 0x7B, 0xFF, 0x29, 0x01, 0x01, 0xFE, 0xF1, 0x02, 0x07, 0xFC,
1201 0x6E, 0x05, 0xE6, 0x48, 0xFF, 0x01, 0x84, 0xFD, 0x2C, 0x02, 0x68,
1202 0xFE, 0xF9, 0x00, 0x8E, 0xFF, 0x1C, 0x00, 0xFE, 0xFF, 0x35, 0x00,
1203 0x3A, 0xFF, 0xD4, 0x01, 0x7A, 0xFC, 0x2B, 0x06, 0x1E, 0xF5, 0x56,
1204 0x19, 0x0C, 0x42, 0xAA, 0xF5, 0xC9, 0x03, 0xA4, 0xFE, 0x54, 0x00,
1205 0x09, 0x00, 0xEB, 0xFF, 0x06, 0x00, 0xFD, 0xFF, 0x2D, 0x00, 0x55,
1206 0xFF, 0xB6, 0x01, 0x5F, 0xFC, 0x17, 0x07, 0x87, 0xF1, 0xC2, 0x2E,
1207 0xC0, 0x31, 0x7E, 0xF1, 0xF1, 0x06, 0x86, 0xFC, 0x9B, 0x01, 0x63,
1208 0xFF, 0x28, 0x00, 0xFD, 0xFF, 0x04, 0x00, 0xF7, 0xFF, 0xEA, 0xFF,
1209 0x93, 0x00, 0x36, 0xFE, 0x7D, 0x04, 0x85, 0xF4, 0x1F, 0x40, 0x94,
1210 0x1C, 0x47, 0xF4, 0x7E, 0x06, 0x5A, 0xFC, 0xDF, 0x01, 0x37, 0xFF,
1211 0x36, 0x00, 0xFE, 0xFF, 0x18, 0x00, 0x9C, 0xFF, 0xD4, 0x00, 0xB4,
1212 0xFE, 0x9A, 0x01, 0x95, 0xFE, 0xA8, 0xFF, 0x98, 0x48, 0x1D, 0x08,
1213 0xEE, 0xFA, 0x80, 0x03, 0xB9, 0xFD, 0x4B, 0x01, 0x6E, 0xFF, 0x25,
1214 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x30, 0x00, 0x4A, 0xFF, 0xA9, 0x01,
1215 0xE7, 0xFC, 0x33, 0x05, 0x60, 0xF7, 0xDA, 0x11, 0xB8, 0x45, 0x1C,
1216 0xF9, 0xD8, 0x01, 0xCA, 0xFF, 0xAF, 0xFF, 0x5A, 0x00, 0xCC, 0xFF,
1217 0x0D, 0x00, 0xFD, 0xFF, 0x34, 0x00, 0x3E, 0xFF, 0xDE, 0x01, 0x33,
1218 0xFC, 0x21, 0x07, 0x30, 0xF2, 0x5C, 0x27, 0x5B, 0x38, 0x0F, 0xF2,
1219 0x40, 0x06, 0x0E, 0xFD, 0x43, 0x01, 0x91, 0xFF, 0x18, 0x00, 0xFF,
1220 0xFF, 0x00, 0x00, 0x0F, 0x00, 0xA8, 0xFF, 0x17, 0x01, 0x57, 0xFD,
1221 0xD6, 0x05, 0x90, 0xF2, 0xC8, 0x3A, 0x46, 0x24, 0xAA, 0xF2, 0x06,
1222 0x07, 0x32, 0xFC, 0xE5, 0x01, 0x39, 0xFF, 0x36, 0x00, 0xFD, 0xFF,
1223 0x10, 0x00, 0xBE, 0xFF, 0x7D, 0x00, 0x69, 0xFF, 0x4B, 0x00, 0xF6,
1224 0x00, 0xCB, 0xFA, 0xD3, 0x46, 0xF0, 0x0E, 0x5E, 0xF8, 0xBE, 0x04,
1225 0x1E, 0xFD, 0x91, 0x01, 0x52, 0xFF, 0x2D, 0x00, 0xFF, 0xFF, 0x00,
1226 0x00, 0x28, 0x00, 0x62, 0xFF, 0x69, 0x01, 0x77, 0xFD, 0x04, 0x04,
1227 0xE2, 0xF9, 0xCB, 0x0A, 0x0D, 0x48, 0x94, 0xFD, 0x92, 0xFF, 0x10,
1228 0x01, 0xFE, 0xFE, 0xB1, 0x00, 0xAA, 0xFF, 0x15, 0x00, 0xFD, 0xFF,
1229 0x36, 0x00, 0x36, 0xFF, 0xE5, 0x01, 0x43, 0xFC, 0xC0, 0x06, 0x8F,
1230 0xF3, 0xB1, 0x1F, 0x18, 0x3E, 0x9B, 0xF3, 0x16, 0x05, 0xD5, 0xFD,
1231 0xCC, 0x00, 0xCE, 0xFF, 0x01, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x22,
1232 0x00, 0x74, 0xFF, 0x7C, 0x01, 0xB5, 0xFC, 0xB8, 0x06, 0x9C, 0xF1,
1233 0x81, 0x34, 0xD1, 0x2B, 0xB3, 0xF1, 0x29, 0x07, 0x46, 0xFC, 0xCA,
1234 0x01, 0x4A, 0xFF, 0x30, 0x00, 0xFD, 0xFF, 0x09, 0x00, 0xDF, 0xFF,
1235 0x29, 0x00, 0x14, 0x00, 0x16, 0xFF, 0x0C, 0x03, 0xEE, 0xF6, 0xB0,
1236 0x43, 0x47, 0x16, 0xFC, 0xF5, 0xCF, 0x05, 0xA1, 0xFC, 0xC6, 0x01,
1237 0x3F, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x1F, 0x00, 0x81,
1238 0xFF, 0x1B, 0x01, 0x20, 0xFE, 0xB6, 0x02, 0x7A, 0xFC, 0x5F, 0x04,
1239 0xF4, 0x48, 0xFF, 0x02, 0x13, 0xFD, 0x67, 0x02, 0x49, 0xFE, 0x07,
1240 0x01, 0x88, 0xFF, 0x1D, 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3C, 0xFF,
1241 0xCF, 0x01, 0x8A, 0xFC, 0x05, 0x06, 0x7B, 0xF5, 0x06, 0x18, 0xC7,
1242 0x42, 0x2F, 0xF6, 0x7A, 0x03, 0xD4, 0xFE, 0x39, 0x00, 0x17, 0x00,
1243 0xE6, 0xFF, 0x07, 0x00, 0xFD, 0xFF, 0x2E, 0x00, 0x50, 0xFF, 0xC0,
1244 0x01, 0x53, 0xFC, 0x21, 0x07, 0x96, 0xF1, 0x82, 0x2D, 0xF2, 0x32,
1245 0x86, 0xF1, 0xDB, 0x06, 0x99, 0xFC, 0x8E, 0x01, 0x6A, 0xFF, 0x25,
1246 0x00, 0xFD, 0xFF, 0x03, 0x00, 0xFB, 0xFF, 0xDE, 0xFF, 0xAC, 0x00,
1247 0x0B, 0xFE, 0xC1, 0x04, 0x1B, 0xF4, 0x47, 0x3F, 0xEA, 0x1D, 0xF5,
1248 0xF3, 0x9C, 0x06, 0x4F, 0xFC, 0xE2, 0x01, 0x36, 0xFF, 0x36, 0x00,
1249 0xFE, 0xFF, 0x16, 0x00, 0xA2, 0xFF, 0xC5, 0x00, 0xD4, 0xFE, 0x5F,
1250 0x01, 0x03, 0xFF, 0xBF, 0xFE, 0x63, 0x48, 0x40, 0x09, 0x7B, 0xFA,
1251 0xB9, 0x03, 0x9D, 0xFD, 0x58, 0x01, 0x69, 0xFF, 0x26, 0x00, 0x00,
1252 0x00, 0xFF, 0xFF, 0x2E, 0x00, 0x4D, 0xFF, 0x9F, 0x01, 0xFE, 0xFC,
1253 0x02, 0x05, 0xCB, 0xF7, 0x98, 0x10, 0x39, 0x46, 0xD0, 0xF9, 0x78,
1254 0x01, 0x00, 0x00, 0x91, 0xFF, 0x69, 0x00, 0xC6, 0xFF, 0x0E, 0x00,
1255 0xFD, 0xFF, 0x35, 0x00, 0x3B, 0xFF, 0xE2, 0x01, 0x31, 0xFC, 0x17,
1256 0x07, 0x61, 0xF2, 0x0A, 0x26, 0x6A, 0x39, 0x41, 0xF2, 0x15, 0x06,
1257 0x2C, 0xFD, 0x31, 0x01, 0x9B, 0xFF, 0x14, 0x00, 0xFF, 0xFF, 0xFF,
1258 0xFF, 0x13, 0x00, 0x9E, 0xFF, 0x2B, 0x01, 0x37, 0xFD, 0x05, 0x06,
1259 0x54, 0xF2, 0xC2, 0x39, 0x99, 0x25, 0x73, 0xF2, 0x14, 0x07, 0x31,
1260 0xFC, 0xE3, 0x01, 0x3B, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x0E, 0x00,
1261 0xC4, 0xFF, 0x6E, 0x00, 0x87, 0xFF, 0x13, 0x00, 0x58, 0x01, 0x0D,
1262 0xFA, 0x61, 0x46, 0x2D, 0x10, 0xF0, 0xF7, 0xF1, 0x04, 0x05, 0xFD,
1263 0x9C, 0x01, 0x4E, 0xFF, 0x2E, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x27,
1264 0x00, 0x67, 0xFF, 0x5C, 0x01, 0x93, 0xFD, 0xCC, 0x03, 0x54, 0xFA,
1265 0xA2, 0x09, 0x4F, 0x48, 0x73, 0xFE, 0x27, 0xFF, 0x4B, 0x01, 0xDE,
1266 0xFE, 0xC0, 0x00, 0xA4, 0xFF, 0x16, 0x00, 0xFE, 0xFF, 0x36, 0x00,
1267 0x36, 0xFF, 0xE3, 0x01, 0x4C, 0xFC, 0xA6, 0x06, 0xDB, 0xF3, 0x5B,
1268 0x1E, 0xFC, 0x3E, 0xFA, 0xF3, 0xD7, 0x04, 0xFD, 0xFD, 0xB4, 0x00,
1269 0xD9, 0xFF, 0xFD, 0xFF, 0x03, 0x00, 0xFD, 0xFF, 0x25, 0x00, 0x6D,
1270 0xFF, 0x8A, 0x01, 0x9F, 0xFC, 0xD3, 0x06, 0x8A, 0xF1, 0x57, 0x33,
1271 0x17, 0x2D, 0x9C, 0xF1, 0x24, 0x07, 0x4F, 0xFC, 0xC3, 0x01, 0x4E,
1272 0xFF, 0x2F, 0x00, 0xFD, 0xFF, 0x08, 0x00, 0xE4, 0xFF, 0x1B, 0x00,
1273 0x30, 0x00, 0xE4, 0xFE, 0x5F, 0x03, 0x5E, 0xF6, 0x02, 0x43, 0x96,
1274 0x17, 0x9B, 0xF5, 0xF8, 0x05, 0x8F, 0xFC, 0xCC, 0x01, 0x3D, 0xFF,
1275 0x34, 0x00, 0xFE, 0xFF, 0x1E, 0x00, 0x86, 0xFF, 0x0C, 0x01, 0x3E,
1276 0xFE, 0x7B, 0x02, 0xED, 0xFC, 0x56, 0x03, 0xF5, 0x48, 0x06, 0x04,
1277 0xA1, 0xFC, 0xA3, 0x02, 0x2A, 0xFE, 0x16, 0x01, 0x83, 0xFF, 0x1F,
1278 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0x3E, 0xFF, 0xC8, 0x01,
1279 0x9B, 0xFC, 0xDD, 0x05, 0xDC, 0xF5, 0xB6, 0x16, 0x77, 0x43, 0xBD,
1280 0xF6, 0x28, 0x03, 0x05, 0xFF, 0x1D, 0x00, 0x25, 0x00, 0xE1, 0xFF,
1281 0x08, 0x00, 0xFD, 0xFF, 0x30, 0x00, 0x4B, 0xFF, 0xC8, 0x01, 0x49,
1282 0xFC, 0x27, 0x07, 0xAB, 0xF1, 0x3E, 0x2C, 0x1E, 0x34, 0x95, 0xF1,
1283 0xC1, 0x06, 0xAE, 0xFC, 0x81, 0x01, 0x71, 0xFF, 0x23, 0x00, 0xFE,
1284 0xFF, 0x02, 0x00, 0x00, 0x00, 0xD2, 0xFF, 0xC4, 0x00, 0xE2, 0xFD,
1285 0x01, 0x05, 0xBA, 0xF3, 0x64, 0x3E, 0x3F, 0x1F, 0xA8, 0xF3, 0xB8,
1286 0x06, 0x46, 0xFC, 0xE5, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF,
1287 0x15, 0x00, 0xA8, 0xFF, 0xB6, 0x00, 0xF3, 0xFE, 0x24, 0x01, 0x6E,
1288 0xFF, 0xDE, 0xFD, 0x25, 0x48, 0x68, 0x0A, 0x08, 0xFA, 0xF2, 0x03,
1289 0x81, 0xFD, 0x65, 0x01, 0x64, 0xFF, 0x28, 0x00, 0x00, 0x00, 0xFF,
1290 0xFF, 0x2D, 0x00, 0x51, 0xFF, 0x95, 0x01, 0x15, 0xFD, 0xCF, 0x04,
1291 0x39, 0xF8, 0x59, 0x0F, 0xAF, 0x46, 0x8B, 0xFA, 0x17, 0x01, 0x38,
1292 0x00, 0x73, 0xFF, 0x78, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0xFD, 0xFF,
1293 0x36, 0x00, 0x39, 0xFF, 0xE4, 0x01, 0x32, 0xFC, 0x0B, 0x07, 0x97,
1294 0xF2, 0xB8, 0x24, 0x71, 0x3A, 0x7B, 0xF2, 0xE6, 0x05, 0x4C, 0xFD,
1295 0x1D, 0x01, 0xA4, 0xFF, 0x11, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x16,
1296 0x00, 0x94, 0xFF, 0x3D, 0x01, 0x18, 0xFD, 0x32, 0x06, 0x1F, 0xF2,
1297 0xB5, 0x38, 0xEB, 0x26, 0x40, 0xF2, 0x1E, 0x07, 0x32, 0xFC, 0xDF,
1298 0x01, 0x3D, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x0D, 0x00, 0xCA, 0xFF,
1299 0x5F, 0x00, 0xA5, 0xFF, 0xDC, 0xFF, 0xB8, 0x01, 0x57, 0xF9, 0xE5,
1300 0x45, 0x6E, 0x11, 0x83, 0xF7, 0x23, 0x05, 0xEE, 0xFC, 0xA6, 0x01,
1301 0x4B, 0xFF, 0x2F, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x25, 0x00, 0x6C,
1302 0xFF, 0x4F, 0x01, 0xB0, 0xFD, 0x93, 0x03, 0xC7, 0xFA, 0x7D, 0x08,
1303 0x86, 0x48, 0x5A, 0xFF, 0xBA, 0xFE, 0x86, 0x01, 0xBF, 0xFE, 0xCF,
1304 0x00, 0x9E, 0xFF, 0x17, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF,
1305 0xE0, 0x01, 0x56, 0xFC, 0x89, 0x06, 0x2B, 0xF4, 0x06, 0x1D, 0xD7,
1306 0x3F, 0x61, 0xF4, 0x94, 0x04, 0x27, 0xFE, 0x9C, 0x00, 0xE6, 0xFF,
1307 0xF8, 0xFF, 0x04, 0x00, 0xFD, 0xFF, 0x27, 0x00, 0x66, 0xFF, 0x97,
1308 0x01, 0x8C, 0xFC, 0xEA, 0x06, 0x80, 0xF1, 0x26, 0x32, 0x58, 0x2E,
1309 0x8B, 0xF1, 0x1B, 0x07, 0x5B, 0xFC, 0xBA, 0x01, 0x53, 0xFF, 0x2D,
1310 0x00, 0xFD, 0xFF, 0x07, 0x00, 0xE9, 0xFF, 0x0E, 0x00, 0x4B, 0x00,
1311 0xB4, 0xFE, 0xAF, 0x03, 0xD5, 0xF5, 0x4D, 0x42, 0xE6, 0x18, 0x3C,
1312 0xF5, 0x1F, 0x06, 0x7F, 0xFC, 0xD3, 0x01, 0x3B, 0xFF, 0x35, 0x00,
1313 0xFE, 0xFF, 0x1C, 0x00, 0x8C, 0xFF, 0xFE, 0x00, 0x5D, 0xFE, 0x3F,
1314 0x02, 0x5E, 0xFD, 0x54, 0x02, 0xEC, 0x48, 0x13, 0x05, 0x2E, 0xFC,
1315 0xDE, 0x02, 0x0C, 0xFE, 0x24, 0x01, 0x7D, 0xFF, 0x20, 0x00, 0x00,
1316 0x00, 0xFF, 0xFF, 0x32, 0x00, 0x41, 0xFF, 0xC1, 0x01, 0xAD, 0xFC,
1317 0xB2, 0x05, 0x3F, 0xF6, 0x69, 0x15, 0x1F, 0x44, 0x53, 0xF7, 0xD3,
1318 0x02, 0x38, 0xFF, 0x01, 0x00, 0x33, 0x00, 0xDB, 0xFF, 0x09, 0x00,
1319 0xFD, 0xFF, 0x31, 0x00, 0x47, 0xFF, 0xCF, 0x01, 0x40, 0xFC, 0x2A,
1320 0x07, 0xC6, 0xF1, 0xF7, 0x2A, 0x46, 0x35, 0xAB, 0xF1, 0xA4, 0x06,
1321 0xC4, 0xFC, 0x72, 0x01, 0x79, 0xFF, 0x20, 0x00, 0xFE, 0xFF, 0x02,
1322 0x00, 0x04, 0x00, 0xC6, 0xFF, 0xDB, 0x00, 0xBB, 0xFD, 0x3E, 0x05,
1323 0x60, 0xF3, 0x7B, 0x3D, 0x94, 0x20, 0x5E, 0xF3, 0xD0, 0x06, 0x3E,
1324 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x14, 0x00,
1325 0xAE, 0xFF, 0xA7, 0x00, 0x12, 0xFF, 0xEA, 0x00, 0xD9, 0xFF, 0x03,
1326 0xFD, 0xDC, 0x47, 0x95, 0x0B, 0x96, 0xF9, 0x29, 0x04, 0x65, 0xFD,
1327 0x71, 0x01, 0x5F, 0xFF, 0x29, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2C,
1328 0x00, 0x55, 0xFF, 0x8A, 0x01, 0x2E, 0xFD, 0x9B, 0x04, 0xA8, 0xF8,
1329 0x1F, 0x0E, 0x1A, 0x47, 0x4E, 0xFB, 0xB3, 0x00, 0x70, 0x00, 0x54,
1330 0xFF, 0x87, 0x00, 0xBB, 0xFF, 0x11, 0x00, 0xFD, 0xFF, 0x36, 0x00,
1331 0x38, 0xFF, 0xE6, 0x01, 0x34, 0xFC, 0xFB, 0x06, 0xD2, 0xF2, 0x64,
1332 0x23, 0x73, 0x3B, 0xBC, 0xF2, 0xB4, 0x05, 0x6E, 0xFD, 0x09, 0x01,
1333 0xAF, 0xFF, 0x0D, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x1A, 0x00, 0x8B,
1334 0xFF, 0x4F, 0x01, 0xFB, 0xFC, 0x5A, 0x06, 0xF2, 0xF1, 0xA0, 0x37,
1335 0x3A, 0x28, 0x13, 0xF2, 0x25, 0x07, 0x35, 0xFC, 0xDB, 0x01, 0x40,
1336 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x0C, 0x00, 0xD0, 0xFF, 0x51, 0x00,
1337 0xC3, 0xFF, 0xA6, 0xFF, 0x16, 0x02, 0xA9, 0xF8, 0x5C, 0x45, 0xB2,
1338 0x12, 0x19, 0xF7, 0x52, 0x05, 0xD8, 0xFC, 0xAF, 0x01, 0x47, 0xFF,
1339 0x30, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x24, 0x00, 0x71, 0xFF, 0x42,
1340 0x01, 0xCD, 0xFD, 0x59, 0x03, 0x3B, 0xFB, 0x5E, 0x07, 0xB3, 0x48,
1341 0x48, 0x00, 0x4B, 0xFE, 0xC2, 0x01, 0x9F, 0xFE, 0xDE, 0x00, 0x98,
1342 0xFF, 0x19, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xDD, 0x01,
1343 0x62, 0xFC, 0x69, 0x06, 0x7F, 0xF4, 0xB2, 0x1B, 0xAB, 0x40, 0xD0,
1344 0xF4, 0x4E, 0x04, 0x53, 0xFE, 0x83, 0x00, 0xF2, 0xFF, 0xF4, 0xFF,
1345 0x05, 0x00, 0xFD, 0xFF, 0x29, 0x00, 0x5F, 0xFF, 0xA3, 0x01, 0x7A,
1346 0xFC, 0xFD, 0x06, 0x7C, 0xF1, 0xF2, 0x30, 0x96, 0x2F, 0x80, 0xF1,
1347 0x0F, 0x07, 0x69, 0xFC, 0xB0, 0x01, 0x59, 0xFF, 0x2B, 0x00, 0xFD,
1348 0xFF, 0x06, 0x00, 0xEE, 0xFF, 0x01, 0x00, 0x66, 0x00, 0x85, 0xFE,
1349 0xFC, 0x03, 0x55, 0xF5, 0x8C, 0x41, 0x38, 0x1A, 0xE1, 0xF4, 0x43,
1350 0x06, 0x70, 0xFC, 0xD8, 0x01, 0x39, 0xFF, 0x35, 0x00, 0xFE, 0xFF,
1351 0x1B, 0x00, 0x92, 0xFF, 0xEF, 0x00, 0x7D, 0xFE, 0x04, 0x02, 0xCF,
1352 0xFD, 0x58, 0x01, 0xD7, 0x48, 0x26, 0x06, 0xBB, 0xFB, 0x19, 0x03,
1353 0xED, 0xFD, 0x32, 0x01, 0x77, 0xFF, 0x22, 0x00, 0x00, 0x00, 0xFF,
1354 0xFF, 0x32, 0x00, 0x44, 0xFF, 0xB9, 0x01, 0xC1, 0xFC, 0x86, 0x05,
1355 0xA5, 0xF6, 0x1E, 0x14, 0xBA, 0x44, 0xF0, 0xF7, 0x7B, 0x02, 0x6B,
1356 0xFF, 0xE4, 0xFF, 0x41, 0x00, 0xD6, 0xFF, 0x0B, 0x00, 0xFD, 0xFF,
1357 0x33, 0x00, 0x43, 0xFF, 0xD5, 0x01, 0x3A, 0xFC, 0x2A, 0x07, 0xE7,
1358 0xF1, 0xAC, 0x29, 0x66, 0x36, 0xC9, 0xF1, 0x83, 0x06, 0xDD, 0xFC,
1359 0x62, 0x01, 0x81, 0xFF, 0x1D, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x08,
1360 0x00, 0xBB, 0xFF, 0xF1, 0x00, 0x96, 0xFD, 0x78, 0x05, 0x0E, 0xF3,
1361 0x8A, 0x3C, 0xEA, 0x21, 0x19, 0xF3, 0xE6, 0x06, 0x38, 0xFC, 0xE6,
1362 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x12, 0x00, 0xB4, 0xFF,
1363 0x98, 0x00, 0x32, 0xFF, 0xB0, 0x00, 0x41, 0x00, 0x30, 0xFC, 0x86,
1364 0x47, 0xC6, 0x0C, 0x24, 0xF9, 0x60, 0x04, 0x4B, 0xFD, 0x7D, 0x01,
1365 0x5A, 0xFF, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x5A,
1366 0xFF, 0x7E, 0x01, 0x48, 0xFD, 0x66, 0x04, 0x18, 0xF9, 0xE8, 0x0C,
1367 0x7C, 0x47, 0x19, 0xFC, 0x4D, 0x00, 0xA9, 0x00, 0x35, 0xFF, 0x96,
1368 0x00, 0xB5, 0xFF, 0x12, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x37, 0xFF,
1369 0xE6, 0x01, 0x38, 0xFC, 0xE9, 0x06, 0x12, 0xF3, 0x10, 0x22, 0x6E,
1370 0x3C, 0x05, 0xF3, 0x7E, 0x05, 0x91, 0xFD, 0xF4, 0x00, 0xBA, 0xFF,
1371 0x09, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x1D, 0x00, 0x82, 0xFF, 0x60,
1372 0x01, 0xE0, 0xFC, 0x7F, 0x06, 0xCC, 0xF1, 0x85, 0x36, 0x87, 0x29,
1373 0xEB, 0xF1, 0x2A, 0x07, 0x39, 0xFC, 0xD6, 0x01, 0x43, 0xFF, 0x33,
1374 0x00, 0xFD, 0xFF, 0x0B, 0x00, 0xD5, 0xFF, 0x42, 0x00, 0xE1, 0xFF,
1375 0x71, 0xFF, 0x71, 0x02, 0x02, 0xF8, 0xCC, 0x44, 0xFA, 0x13, 0xB0,
1376 0xF6, 0x81, 0x05, 0xC3, 0xFC, 0xB8, 0x01, 0x44, 0xFF, 0x31, 0x00,
1377 0xFF, 0xFF, 0x00, 0x00, 0x22, 0x00, 0x77, 0xFF, 0x34, 0x01, 0xEA,
1378 0xFD, 0x1F, 0x03, 0xAE, 0xFB, 0x45, 0x06, 0xD5, 0x48, 0x3C, 0x01,
1379 0xDC, 0xFD, 0xFD, 0x01, 0x80, 0xFE, 0xED, 0x00, 0x93, 0xFF, 0x1B,
1380 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x39, 0xFF, 0xD8, 0x01, 0x6F, 0xFC,
1381 0x47, 0x06, 0xD7, 0xF4, 0x5D, 0x1A, 0x74, 0x41, 0x48, 0xF5, 0x04,
1382 0x04, 0x80, 0xFE, 0x69, 0x00, 0xFF, 0xFF, 0xEF, 0xFF, 0x05, 0x00,
1383 0xFD, 0xFF, 0x2B, 0x00, 0x59, 0xFF, 0xAE, 0x01, 0x6A, 0xFC, 0x0D,
1384 0x07, 0x80, 0xF1, 0xB8, 0x2F, 0xCF, 0x30, 0x7D, 0xF1, 0xFF, 0x06,
1385 0x78, 0xFC, 0xA5, 0x01, 0x5F, 0xFF, 0x29, 0x00, 0xFD, 0xFF, 0x05,
1386 0x00, 0xF3, 0xFF, 0xF4, 0xFF, 0x80, 0x00, 0x58, 0xFE, 0x46, 0x04,
1387 0xDD, 0xF4, 0xC3, 0x40, 0x8C, 0x1B, 0x89, 0xF4, 0x66, 0x06, 0x63,
1388 0xFC, 0xDC, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x19, 0x00,
1389 0x98, 0xFF, 0xE0, 0x00, 0x9C, 0xFE, 0xC8, 0x01, 0x3F, 0xFE, 0x62,
1390 0x00, 0xB8, 0x48, 0x3F, 0x07, 0x47, 0xFB, 0x53, 0x03, 0xD0, 0xFD,
1391 0x40, 0x01, 0x72, 0xFF, 0x23, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x30,
1392 0x00, 0x47, 0xFF, 0xB0, 0x01, 0xD6, 0xFC, 0x58, 0x05, 0x0D, 0xF7,
1393 0xD7, 0x12, 0x4E, 0x45, 0x96, 0xF8, 0x20, 0x02, 0xA0, 0xFF, 0xC7,
1394 0xFF, 0x4F, 0x00, 0xD0, 0xFF, 0x0C, 0x00, 0xFD, 0xFF, 0x34, 0x00,
1395 0x40, 0xFF, 0xDB, 0x01, 0x35, 0xFC, 0x26, 0x07, 0x0E, 0xF2, 0x60,
1396 0x28, 0x82, 0x37, 0xED, 0xF1, 0x5E, 0x06, 0xF8, 0xFC, 0x51, 0x01,
1397 0x8A, 0xFF, 0x1A, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00, 0xB0,
1398 0xFF, 0x07, 0x01, 0x72, 0xFD, 0xAE, 0x05, 0xC4, 0xF2, 0x90, 0x3B,
1399 0x3F, 0x23, 0xD9, 0xF2, 0xF9, 0x06, 0x34, 0xFC, 0xE6, 0x01, 0x38,
1400 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x11, 0x00, 0xBA, 0xFF, 0x89, 0x00,
1401 0x51, 0xFF, 0x77, 0x00, 0xA7, 0x00, 0x64, 0xFB, 0x26, 0x47, 0xFC,
1402 0x0D, 0xB4, 0xF8, 0x95, 0x04, 0x31, 0xFD, 0x88, 0x01, 0x56, 0xFF,
1403 0x2C, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x29, 0x00, 0x5E, 0xFF, 0x72,
1404 0x01, 0x62, 0xFD, 0x2F, 0x04, 0x89, 0xF9, 0xB6, 0x0B, 0xD2, 0x47,
1405 0xEB, 0xFC, 0xE4, 0xFF, 0xE3, 0x00, 0x16, 0xFF, 0xA5, 0x00, 0xAF,
1406 0xFF, 0x13, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01,
1407 0x3E, 0xFC, 0xD3, 0x06, 0x56, 0xF3, 0xBA, 0x20, 0x61, 0x3D, 0x56,
1408 0xF3, 0x45, 0x05, 0xB7, 0xFD, 0xDE, 0x00, 0xC5, 0xFF, 0x05, 0x00,
1409 0x02, 0x00, 0xFE, 0xFF, 0x20, 0x00, 0x7A, 0xFF, 0x70, 0x01, 0xC7,
1410 0xFC, 0xA0, 0x06, 0xAE, 0xF1, 0x65, 0x35, 0xD1, 0x2A, 0xCA, 0xF1,
1411 0x2A, 0x07, 0x40, 0xFC, 0xD0, 0x01, 0x47, 0xFF, 0x32, 0x00, 0xFD,
1412 0xFF, 0x09, 0x00, 0xDB, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0x3D, 0xFF,
1413 0xC9, 0x02, 0x64, 0xF7, 0x2F, 0x44, 0x44, 0x15, 0x4A, 0xF6, 0xAD,
1414 0x05, 0xAF, 0xFC, 0xC0, 0x01, 0x41, 0xFF, 0x32, 0x00, 0xFF, 0xFF,
1415 0x00, 0x00, 0x21, 0x00, 0x7C, 0xFF, 0x26, 0x01, 0x08, 0xFE, 0xE4,
1416 0x02, 0x21, 0xFC, 0x31, 0x05, 0xEB, 0x48, 0x37, 0x02, 0x6B, 0xFD,
1417 0x39, 0x02, 0x61, 0xFE, 0xFC, 0x00, 0x8D, 0xFF, 0x1C, 0x00, 0xFE,
1418 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xD3, 0x01, 0x7D, 0xFC, 0x23, 0x06,
1419 0x32, 0xF5, 0x0C, 0x19, 0x38, 0x42, 0xC7, 0xF5, 0xB8, 0x03, 0xAF,
1420 0xFE, 0x4E, 0x00, 0x0C, 0x00, 0xEA, 0xFF, 0x06, 0x00, 0xFD, 0xFF,
1421 0x2D, 0x00, 0x54, 0xFF, 0xB8, 0x01, 0x5D, 0xFC, 0x1A, 0x07, 0x8A,
1422 0xF1, 0x7B, 0x2E, 0x04, 0x32, 0x7F, 0xF1, 0xEC, 0x06, 0x8A, 0xFC,
1423 0x98, 0x01, 0x65, 0xFF, 0x27, 0x00, 0xFD, 0xFF, 0x04, 0x00, 0xF8,
1424 0xFF, 0xE7, 0xFF, 0x99, 0x00, 0x2C, 0xFE, 0x8C, 0x04, 0x6D, 0xF4,
1425 0xF0, 0x3F, 0xE0, 0x1C, 0x34, 0xF4, 0x85, 0x06, 0x57, 0xFC, 0xE0,
1426 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x18, 0x00, 0x9E, 0xFF,
1427 0xD1, 0x00, 0xBB, 0xFE, 0x8D, 0x01, 0xAE, 0xFE, 0x74, 0xFF, 0x8D,
1428 0x48, 0x5D, 0x08, 0xD4, 0xFA, 0x8D, 0x03, 0xB3, 0xFD, 0x4E, 0x01,
1429 0x6D, 0xFF, 0x25, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2F, 0x00, 0x4A,
1430 0xFF, 0xA7, 0x01, 0xEC, 0xFC, 0x28, 0x05, 0x77, 0xF7, 0x92, 0x11,
1431 0xD7, 0x45, 0x43, 0xF9, 0xC3, 0x01, 0xD6, 0xFF, 0xA9, 0xFF, 0x5E,
1432 0x00, 0xCB, 0xFF, 0x0D, 0x00, 0xFD, 0xFF, 0x34, 0x00, 0x3D, 0xFF,
1433 0xDF, 0x01, 0x32, 0xFC, 0x1F, 0x07, 0x3B, 0xF2, 0x11, 0x27, 0x97,
1434 0x38, 0x19, 0xF2, 0x36, 0x06, 0x15, 0xFD, 0x3F, 0x01, 0x93, 0xFF,
1435 0x17, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x10, 0x00, 0xA6, 0xFF, 0x1B,
1436 0x01, 0x50, 0xFD, 0xE1, 0x05, 0x82, 0xF2, 0x8F, 0x3A, 0x92, 0x24,
1437 0x9D, 0xF2, 0x09, 0x07, 0x32, 0xFC, 0xE4, 0x01, 0x39, 0xFF, 0x36,
1438 0x00, 0xFD, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0x7A, 0x00, 0x70, 0xFF,
1439 0x3E, 0x00, 0x0C, 0x01, 0xA1, 0xFA, 0xBB, 0x46, 0x36, 0x0F, 0x45,
1440 0xF8, 0xC9, 0x04, 0x18, 0xFD, 0x93, 0x01, 0x52, 0xFF, 0x2D, 0x00,
1441 0xFF, 0xFF, 0x00, 0x00, 0x28, 0x00, 0x63, 0xFF, 0x66, 0x01, 0x7D,
1442 0xFD, 0xF8, 0x03, 0xFB, 0xF9, 0x89, 0x0A, 0x1D, 0x48, 0xC5, 0xFD,
1443 0x7A, 0xFF, 0x1D, 0x01, 0xF7, 0xFE, 0xB4, 0x00, 0xA9, 0xFF, 0x15,
1444 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE5, 0x01, 0x45, 0xFC,
1445 0xBB, 0x06, 0xA0, 0xF3, 0x64, 0x1F, 0x4A, 0x3E, 0xB0, 0xF3, 0x08,
1446 0x05, 0xDE, 0xFD, 0xC7, 0x00, 0xD0, 0xFF, 0x00, 0x00, 0x02, 0x00,
1447 0xFE, 0xFF, 0x23, 0x00, 0x72, 0xFF, 0x7F, 0x01, 0xB0, 0xFC, 0xBE,
1448 0x06, 0x97, 0xF1, 0x3F, 0x34, 0x19, 0x2C, 0xAD, 0xF1, 0x28, 0x07,
1449 0x48, 0xFC, 0xC9, 0x01, 0x4B, 0xFF, 0x30, 0x00, 0xFD, 0xFF, 0x08,
1450 0x00, 0xE0, 0xFF, 0x26, 0x00, 0x1A, 0x00, 0x0B, 0xFF, 0x1E, 0x03,
1451 0xCD, 0xF6, 0x89, 0x43, 0x91, 0x16, 0xE7, 0xF5, 0xD8, 0x05, 0x9D,
1452 0xFC, 0xC7, 0x01, 0x3E, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0x00, 0x00,
1453 0x1F, 0x00, 0x82, 0xFF, 0x18, 0x01, 0x27, 0xFE, 0xA9, 0x02, 0x94,
1454 0xFC, 0x24, 0x04, 0xF5, 0x48, 0x39, 0x03, 0xF9, 0xFC, 0x74, 0x02,
1455 0x42, 0xFE, 0x0B, 0x01, 0x87, 0xFF, 0x1E, 0x00, 0xFE, 0xFF, 0x34,
1456 0x00, 0x3C, 0xFF, 0xCD, 0x01, 0x8E, 0xFC, 0xFC, 0x05, 0x90, 0xF5,
1457 0xBB, 0x17, 0xEE, 0x42, 0x4E, 0xF6, 0x68, 0x03, 0xDF, 0xFE, 0x33,
1458 0x00, 0x1A, 0x00, 0xE5, 0xFF, 0x07, 0x00, 0xFD, 0xFF, 0x2F, 0x00,
1459 0x4F, 0xFF, 0xC2, 0x01, 0x51, 0xFC, 0x23, 0x07, 0x9A, 0xF1, 0x3A,
1460 0x2D, 0x35, 0x33, 0x89, 0xF1, 0xD5, 0x06, 0x9D, 0xFC, 0x8B, 0x01,
1461 0x6C, 0xFF, 0x25, 0x00, 0xFD, 0xFF, 0x03, 0x00, 0xFC, 0xFF, 0xDB,
1462 0xFF, 0xB2, 0x00, 0x02, 0xFE, 0xCF, 0x04, 0x05, 0xF4, 0x16, 0x3F,
1463 0x36, 0x1E, 0xE4, 0xF3, 0xA3, 0x06, 0x4D, 0xFC, 0xE3, 0x01, 0x36,
1464 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x16, 0x00, 0xA4, 0xFF, 0xC2, 0x00,
1465 0xDB, 0xFE, 0x52, 0x01, 0x1B, 0xFF, 0x8D, 0xFE, 0x57, 0x48, 0x81,
1466 0x09, 0x61, 0xFA, 0xC6, 0x03, 0x96, 0xFD, 0x5B, 0x01, 0x68, 0xFF,
1467 0x26, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2E, 0x00, 0x4E, 0xFF, 0x9D,
1468 0x01, 0x03, 0xFD, 0xF7, 0x04, 0xE3, 0xF7, 0x51, 0x10, 0x55, 0x46,
1469 0xF9, 0xF9, 0x63, 0x01, 0x0D, 0x00, 0x8B, 0xFF, 0x6D, 0x00, 0xC5,
1470 0xFF, 0x0E, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3B, 0xFF, 0xE2, 0x01,
1471 0x31, 0xFC, 0x15, 0x07, 0x6D, 0xF2, 0xBF, 0x25, 0xA5, 0x39, 0x4D,
1472 0xF2, 0x0B, 0x06, 0x33, 0xFD, 0x2D, 0x01, 0x9D, 0xFF, 0x13, 0x00,
1473 0xFF, 0xFF, 0xFF, 0xFF, 0x14, 0x00, 0x9C, 0xFF, 0x2F, 0x01, 0x30,
1474 0xFD, 0x10, 0x06, 0x47, 0xF2, 0x87, 0x39, 0xE5, 0x25, 0x67, 0xF2,
1475 0x16, 0x07, 0x31, 0xFC, 0xE2, 0x01, 0x3B, 0xFF, 0x35, 0x00, 0xFD,
1476 0xFF, 0x0E, 0x00, 0xC6, 0xFF, 0x6B, 0x00, 0x8E, 0xFF, 0x06, 0x00,
1477 0x6E, 0x01, 0xE4, 0xF9, 0x48, 0x46, 0x75, 0x10, 0xD7, 0xF7, 0xFC,
1478 0x04, 0x00, 0xFD, 0x9E, 0x01, 0x4E, 0xFF, 0x2E, 0x00, 0xFF, 0xFF,
1479 0x00, 0x00, 0x26, 0x00, 0x68, 0xFF, 0x59, 0x01, 0x99, 0xFD, 0xC0,
1480 0x03, 0x6E, 0xFA, 0x61, 0x09, 0x5D, 0x48, 0xA6, 0xFE, 0x0F, 0xFF,
1481 0x58, 0x01, 0xD7, 0xFE, 0xC3, 0x00, 0xA3, 0xFF, 0x16, 0x00, 0xFE,
1482 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE3, 0x01, 0x4E, 0xFC, 0xA0, 0x06,
1483 0xED, 0xF3, 0x0F, 0x1E, 0x2D, 0x3F, 0x10, 0xF4, 0xC8, 0x04, 0x07,
1484 0xFE, 0xAF, 0x00, 0xDC, 0xFF, 0xFC, 0xFF, 0x03, 0x00, 0xFD, 0xFF,
1485 0x25, 0x00, 0x6B, 0xFF, 0x8D, 0x01, 0x9B, 0xFC, 0xD8, 0x06, 0x87,
1486 0xF1, 0x13, 0x33, 0x5E, 0x2D, 0x98, 0xF1, 0x22, 0x07, 0x52, 0xFC,
1487 0xC1, 0x01, 0x4F, 0xFF, 0x2F, 0x00, 0xFD, 0xFF, 0x07, 0x00, 0xE5,
1488 0xFF, 0x18, 0x00, 0x36, 0x00, 0xD9, 0xFE, 0x71, 0x03, 0x3F, 0xF6,
1489 0xDB, 0x42, 0xE0, 0x17, 0x86, 0xF5, 0x00, 0x06, 0x8C, 0xFC, 0xCE,
1490 0x01, 0x3C, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0x1D, 0x00, 0x88, 0xFF,
1491 0x09, 0x01, 0x45, 0xFE, 0x6E, 0x02, 0x06, 0xFD, 0x1C, 0x03, 0xF4,
1492 0x48, 0x41, 0x04, 0x87, 0xFC, 0xB0, 0x02, 0x23, 0xFE, 0x19, 0x01,
1493 0x81, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0x3F,
1494 0xFF, 0xC6, 0x01, 0x9F, 0xFC, 0xD3, 0x05, 0xF1, 0xF5, 0x6C, 0x16,
1495 0x9E, 0x43, 0xDD, 0xF6, 0x15, 0x03, 0x10, 0xFF, 0x17, 0x00, 0x28,
1496 0x00, 0xDF, 0xFF, 0x09, 0x00, 0xFD, 0xFF, 0x30, 0x00, 0x4A, 0xFF,
1497 0xCA, 0x01, 0x47, 0xFC, 0x28, 0x07, 0xB0, 0xF1, 0xF5, 0x2B, 0x60,
1498 0x34, 0x9A, 0xF1, 0xBB, 0x06, 0xB3, 0xFC, 0x7D, 0x01, 0x73, 0xFF,
1499 0x22, 0x00, 0xFE, 0xFF, 0x02, 0x00, 0x01, 0x00, 0xCF, 0xFF, 0xC9,
1500 0x00, 0xDA, 0xFD, 0x0F, 0x05, 0xA5, 0xF3, 0x31, 0x3E, 0x8A, 0x1F,
1501 0x97, 0xF3, 0xBD, 0x06, 0x44, 0xFC, 0xE5, 0x01, 0x36, 0xFF, 0x36,
1502 0x00, 0xFD, 0xFF, 0x15, 0x00, 0xAA, 0xFF, 0xB3, 0x00, 0xFA, 0xFE,
1503 0x17, 0x01, 0x86, 0xFF, 0xAC, 0xFD, 0x16, 0x48, 0xAA, 0x0A, 0xEE,
1504 0xF9, 0xFE, 0x03, 0x7A, 0xFD, 0x67, 0x01, 0x63, 0xFF, 0x28, 0x00,
1505 0x00, 0x00, 0xFF, 0xFF, 0x2D, 0x00, 0x52, 0xFF, 0x92, 0x01, 0x1B,
1506 0xFD, 0xC4, 0x04, 0x51, 0xF8, 0x13, 0x0F, 0xC8, 0x46, 0xB6, 0xFA,
1507 0x01, 0x01, 0x44, 0x00, 0x6C, 0xFF, 0x7B, 0x00, 0xBF, 0xFF, 0x10,
1508 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x39, 0xFF, 0xE5, 0x01, 0x32, 0xFC,
1509 0x08, 0x07, 0xA4, 0xF2, 0x6D, 0x24, 0xAD, 0x3A, 0x88, 0xF2, 0xDB,
1510 0x05, 0x53, 0xFD, 0x19, 0x01, 0xA7, 0xFF, 0x10, 0x00, 0x00, 0x00,
1511 0xFF, 0xFF, 0x17, 0x00, 0x92, 0xFF, 0x41, 0x01, 0x11, 0xFD, 0x3B,
1512 0x06, 0x14, 0xF2, 0x78, 0x38, 0x36, 0x27, 0x35, 0xF2, 0x20, 0x07,
1513 0x33, 0xFC, 0xDF, 0x01, 0x3E, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x0D,
1514 0x00, 0xCB, 0xFF, 0x5C, 0x00, 0xAC, 0xFF, 0xD0, 0xFF, 0xCD, 0x01,
1515 0x30, 0xF9, 0xC8, 0x45, 0xB6, 0x11, 0x6B, 0xF7, 0x2D, 0x05, 0xE9,
1516 0xFC, 0xA8, 0x01, 0x4A, 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0x00, 0x00,
1517 0x25, 0x00, 0x6D, 0xFF, 0x4C, 0x01, 0xB6, 0xFD, 0x86, 0x03, 0xE1,
1518 0xFA, 0x3D, 0x08, 0x92, 0x48, 0x8E, 0xFF, 0xA1, 0xFE, 0x93, 0x01,
1519 0xB8, 0xFE, 0xD3, 0x00, 0x9D, 0xFF, 0x18, 0x00, 0xFE, 0xFF, 0x36,
1520 0x00, 0x37, 0xFF, 0xE0, 0x01, 0x58, 0xFC, 0x82, 0x06, 0x3E, 0xF4,
1521 0xBA, 0x1C, 0x07, 0x40, 0x79, 0xF4, 0x84, 0x04, 0x31, 0xFE, 0x96,
1522 0x00, 0xE8, 0xFF, 0xF7, 0xFF, 0x04, 0x00, 0xFD, 0xFF, 0x28, 0x00,
1523 0x64, 0xFF, 0x9A, 0x01, 0x88, 0xFC, 0xEE, 0x06, 0x7E, 0xF1, 0xE3,
1524 0x31, 0x9F, 0x2E, 0x88, 0xF1, 0x19, 0x07, 0x5E, 0xFC, 0xB7, 0x01,
1525 0x54, 0xFF, 0x2D, 0x00, 0xFD, 0xFF, 0x06, 0x00, 0xEA, 0xFF, 0x0B,
1526 0x00, 0x51, 0x00, 0xAA, 0xFE, 0xC0, 0x03, 0xB8, 0xF5, 0x21, 0x42,
1527 0x31, 0x19, 0x28, 0xF5, 0x27, 0x06, 0x7C, 0xFC, 0xD4, 0x01, 0x3A,
1528 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1C, 0x00, 0x8D, 0xFF, 0xFA, 0x00,
1529 0x64, 0xFE, 0x32, 0x02, 0x78, 0xFD, 0x1B, 0x02, 0xEA, 0x48, 0x50,
1530 0x05, 0x14, 0xFC, 0xEB, 0x02, 0x05, 0xFE, 0x27, 0x01, 0x7C, 0xFF,
1531 0x21, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x32, 0x00, 0x41, 0xFF, 0xBF,
1532 0x01, 0xB2, 0xFC, 0xA9, 0x05, 0x55, 0xF6, 0x20, 0x15, 0x42, 0x44,
1533 0x75, 0xF7, 0xBF, 0x02, 0x43, 0xFF, 0xFA, 0xFF, 0x36, 0x00, 0xDA,
1534 0xFF, 0x0A, 0x00, 0xFD, 0xFF, 0x32, 0x00, 0x46, 0xFF, 0xD1, 0x01,
1535 0x3F, 0xFC, 0x2B, 0x07, 0xCD, 0xF1, 0xAE, 0x2A, 0x86, 0x35, 0xB1,
1536 0xF1, 0x9D, 0x06, 0xCA, 0xFC, 0x6E, 0x01, 0x7B, 0xFF, 0x20, 0x00,
1537 0xFE, 0xFF, 0x02, 0x00, 0x05, 0x00, 0xC3, 0xFF, 0xE0, 0x00, 0xB3,
1538 0xFD, 0x4B, 0x05, 0x4D, 0xF3, 0x45, 0x3D, 0xE0, 0x20, 0x4F, 0xF3,
1539 0xD5, 0x06, 0x3D, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD,
1540 0xFF, 0x13, 0x00, 0xAF, 0xFF, 0xA4, 0x00, 0x19, 0xFF, 0xDD, 0x00,
1541 0xF0, 0xFF, 0xD4, 0xFC, 0xC9, 0x47, 0xD8, 0x0B, 0x7C, 0xF9, 0x35,
1542 0x04, 0x5F, 0xFD, 0x74, 0x01, 0x5E, 0xFF, 0x29, 0x00, 0x00, 0x00,
1543 0x00, 0x00, 0x2C, 0x00, 0x56, 0xFF, 0x87, 0x01, 0x34, 0xFD, 0x8F,
1544 0x04, 0xC0, 0xF8, 0xD9, 0x0D, 0x31, 0x47, 0x7B, 0xFB, 0x9C, 0x00,
1545 0x7D, 0x00, 0x4D, 0xFF, 0x8A, 0x00, 0xB9, 0xFF, 0x11, 0x00, 0xFD,
1546 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xE6, 0x01, 0x35, 0xFC, 0xF7, 0x06,
1547 0xE0, 0xF2, 0x18, 0x23, 0xAB, 0x3B, 0xCC, 0xF2, 0xA8, 0x05, 0x76,
1548 0xFD, 0x04, 0x01, 0xB1, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0xFE, 0xFF,
1549 0x1A, 0x00, 0x89, 0xFF, 0x53, 0x01, 0xF5, 0xFC, 0x63, 0x06, 0xE9,
1550 0xF1, 0x63, 0x37, 0x85, 0x28, 0x09, 0xF2, 0x27, 0x07, 0x35, 0xFC,
1551 0xDA, 0x01, 0x40, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x0C, 0x00, 0xD1,
1552 0xFF, 0x4E, 0x00, 0xCA, 0xFF, 0x9A, 0xFF, 0x2A, 0x02, 0x83, 0xF8,
1553 0x3F, 0x45, 0xFB, 0x12, 0x01, 0xF7, 0x5D, 0x05, 0xD3, 0xFC, 0xB1,
1554 0x01, 0x46, 0xFF, 0x31, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x23, 0x00,
1555 0x73, 0xFF, 0x3F, 0x01, 0xD3, 0xFD, 0x4C, 0x03, 0x54, 0xFB, 0x1F,
1556 0x07, 0xBB, 0x48, 0x7D, 0x00, 0x33, 0xFE, 0xCF, 0x01, 0x98, 0xFE,
1557 0xE2, 0x00, 0x97, 0xFF, 0x19, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x38,
1558 0xFF, 0xDC, 0x01, 0x64, 0xFC, 0x62, 0x06, 0x93, 0xF4, 0x66, 0x1B,
1559 0xD9, 0x40, 0xEA, 0xF4, 0x3E, 0x04, 0x5D, 0xFE, 0x7D, 0x00, 0xF5,
1560 0xFF, 0xF3, 0xFF, 0x05, 0x00, 0xFD, 0xFF, 0x2A, 0x00, 0x5E, 0xFF,
1561 0xA6, 0x01, 0x76, 0xFC, 0x01, 0x07, 0x7D, 0xF1, 0xAD, 0x30, 0xDC,
1562 0x2F, 0x7F, 0xF1, 0x0C, 0x07, 0x6C, 0xFC, 0xAD, 0x01, 0x5A, 0xFF,
1563 0x2B, 0x00, 0xFD, 0xFF, 0x05, 0x00, 0xEF, 0xFF, 0xFE, 0xFF, 0x6C,
1564 0x00, 0x7B, 0xFE, 0x0C, 0x04, 0x3A, 0xF5, 0x5F, 0x41, 0x83, 0x1A,
1565 0xCD, 0xF4, 0x4B, 0x06, 0x6D, 0xFC, 0xD9, 0x01, 0x39, 0xFF, 0x35,
1566 0x00, 0xFE, 0xFF, 0x1A, 0x00, 0x93, 0xFF, 0xEC, 0x00, 0x83, 0xFE,
1567 0xF7, 0x01, 0xE8, 0xFD, 0x21, 0x01, 0xD2, 0x48, 0x64, 0x06, 0xA1,
1568 0xFB, 0x26, 0x03, 0xE7, 0xFD, 0x35, 0x01, 0x76, 0xFF, 0x22, 0x00,
1569 0x00, 0x00, 0xFF, 0xFF, 0x31, 0x00, 0x44, 0xFF, 0xB7, 0x01, 0xC5,
1570 0xFC, 0x7C, 0x05, 0xBC, 0xF6, 0xD5, 0x13, 0xDC, 0x44, 0x14, 0xF8,
1571 0x67, 0x02, 0x77, 0xFF, 0xDD, 0xFF, 0x44, 0x00, 0xD5, 0xFF, 0x0B,
1572 0x00, 0xFD, 0xFF, 0x33, 0x00, 0x42, 0xFF, 0xD7, 0x01, 0x39, 0xFC,
1573 0x29, 0x07, 0xEF, 0xF1, 0x62, 0x29, 0xA5, 0x36, 0xD0, 0xF1, 0x7B,
1574 0x06, 0xE3, 0xFC, 0x5E, 0x01, 0x83, 0xFF, 0x1D, 0x00, 0xFE, 0xFF,
1575 0x01, 0x00, 0x09, 0x00, 0xB8, 0xFF, 0xF6, 0x00, 0x8D, 0xFD, 0x84,
1576 0x05, 0xFD, 0xF2, 0x52, 0x3C, 0x35, 0x22, 0x0B, 0xF3, 0xEB, 0x06,
1577 0x37, 0xFC, 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x12,
1578 0x00, 0xB5, 0xFF, 0x94, 0x00, 0x39, 0xFF, 0xA3, 0x00, 0x58, 0x00,
1579 0x02, 0xFC, 0x73, 0x47, 0x0B, 0x0D, 0x0B, 0xF9, 0x6C, 0x04, 0x45,
1580 0xFD, 0x80, 0x01, 0x59, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00,
1581 0x2A, 0x00, 0x5B, 0xFF, 0x7C, 0x01, 0x4E, 0xFD, 0x5A, 0x04, 0x31,
1582 0xF9, 0xA4, 0x0C, 0x90, 0x47, 0x47, 0xFC, 0x36, 0x00, 0xB6, 0x00,
1583 0x2E, 0xFF, 0x99, 0x00, 0xB3, 0xFF, 0x12, 0x00, 0xFD, 0xFF, 0x36,
1584 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x39, 0xFC, 0xE4, 0x06, 0x21, 0xF3,
1585 0xC4, 0x21, 0xA5, 0x3C, 0x16, 0xF3, 0x72, 0x05, 0x9A, 0xFD, 0xEF,
1586 0x00, 0xBC, 0xFF, 0x08, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x1E, 0x00,
1587 0x80, 0xFF, 0x64, 0x01, 0xDA, 0xFC, 0x87, 0x06, 0xC5, 0xF1, 0x46,
1588 0x36, 0xD1, 0x29, 0xE3, 0xF1, 0x2A, 0x07, 0x3A, 0xFC, 0xD5, 0x01,
1589 0x44, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0x0A, 0x00, 0xD6, 0xFF, 0x3F,
1590 0x00, 0xE7, 0xFF, 0x65, 0xFF, 0x85, 0x02, 0xDE, 0xF7, 0xA9, 0x44,
1591 0x43, 0x14, 0x99, 0xF6, 0x8B, 0x05, 0xBF, 0xFC, 0xBA, 0x01, 0x43,
1592 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x22, 0x00, 0x78, 0xFF,
1593 0x31, 0x01, 0xF1, 0xFD, 0x12, 0x03, 0xC7, 0xFB, 0x07, 0x06, 0xDB,
1594 0x48, 0x73, 0x01, 0xC3, 0xFD, 0x0A, 0x02, 0x79, 0xFE, 0xF1, 0x00,
1595 0x91, 0xFF, 0x1B, 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x39, 0xFF, 0xD7,
1596 0x01, 0x72, 0xFC, 0x3F, 0x06, 0xEB, 0xF4, 0x12, 0x1A, 0xA1, 0x41,
1597 0x63, 0xF5, 0xF3, 0x03, 0x8A, 0xFE, 0x63, 0x00, 0x02, 0x00, 0xEE,
1598 0xFF, 0x06, 0x00, 0xFD, 0xFF, 0x2C, 0x00, 0x58, 0xFF, 0xB1, 0x01,
1599 0x67, 0xFC, 0x10, 0x07, 0x81, 0xF1, 0x73, 0x2F, 0x15, 0x31, 0x7C,
1600 0xF1, 0xFB, 0x06, 0x7C, 0xFC, 0xA2, 0x01, 0x60, 0xFF, 0x29, 0x00,
1601 0xFD, 0xFF, 0x04, 0x00, 0xF4, 0xFF, 0xF1, 0xFF, 0x85, 0x00, 0x4E,
1602 0xFE, 0x56, 0x04, 0xC3, 0xF4, 0x95, 0x40, 0xD8, 0x1B, 0x76, 0xF4,
1603 0x6D, 0x06, 0x60, 0xFC, 0xDD, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE,
1604 0xFF, 0x19, 0x00, 0x99, 0xFF, 0xDD, 0x00, 0xA3, 0xFE, 0xBB, 0x01,
1605 0x58, 0xFE, 0x2D, 0x00, 0xAF, 0x48, 0x7E, 0x07, 0x2E, 0xFB, 0x60,
1606 0x03, 0xC9, 0xFD, 0x43, 0x01, 0x71, 0xFF, 0x24, 0x00, 0x00, 0x00,
1607 0xFF, 0xFF, 0x30, 0x00, 0x48, 0xFF, 0xAE, 0x01, 0xDB, 0xFC, 0x4D,
1608 0x05, 0x24, 0xF7, 0x8E, 0x12, 0x6D, 0x45, 0xBC, 0xF8, 0x0C, 0x02,
1609 0xAC, 0xFF, 0xC0, 0xFF, 0x52, 0x00, 0xCF, 0xFF, 0x0C, 0x00, 0xFD,
1610 0xFF, 0x34, 0x00, 0x3F, 0xFF, 0xDC, 0x01, 0x34, 0xFC, 0x25, 0x07,
1611 0x18, 0xF2, 0x15, 0x28, 0xBF, 0x37, 0xF7, 0xF1, 0x56, 0x06, 0xFE,
1612 0xFC, 0x4D, 0x01, 0x8C, 0xFF, 0x19, 0x00, 0xFF, 0xFF, 0x00, 0x00,
1613 0x0D, 0x00, 0xAE, 0xFF, 0x0B, 0x01, 0x6A, 0xFD, 0xBA, 0x05, 0xB4,
1614 0xF2, 0x58, 0x3B, 0x8A, 0x23, 0xCB, 0xF2, 0xFD, 0x06, 0x34, 0xFC,
1615 0xE6, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x10, 0x00, 0xBB,
1616 0xFF, 0x85, 0x00, 0x58, 0xFF, 0x6A, 0x00, 0xBE, 0x00, 0x38, 0xFB,
1617 0x0F, 0x47, 0x42, 0x0E, 0x9B, 0xF8, 0xA1, 0x04, 0x2B, 0xFD, 0x8B,
1618 0x01, 0x55, 0xFF, 0x2C, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x29, 0x00,
1619 0x5F, 0xFF, 0x70, 0x01, 0x68, 0xFD, 0x23, 0x04, 0xA2, 0xF9, 0x73,
1620 0x0B, 0xE4, 0x47, 0x1B, 0xFD, 0xCD, 0xFF, 0xF0, 0x00, 0x0F, 0xFF,
1621 0xA9, 0x00, 0xAE, 0xFF, 0x14, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36,
1622 0xFF, 0xE6, 0x01, 0x3F, 0xFC, 0xCE, 0x06, 0x66, 0xF3, 0x6F, 0x20,
1623 0x96, 0x3D, 0x69, 0xF3, 0x38, 0x05, 0xBF, 0xFD, 0xD9, 0x00, 0xC7,
1624 0xFF, 0x04, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x20, 0x00, 0x78, 0xFF,
1625 0x74, 0x01, 0xC2, 0xFC, 0xA7, 0x06, 0xA8, 0xF1, 0x25, 0x35, 0x1B,
1626 0x2B, 0xC2, 0xF1, 0x2A, 0x07, 0x41, 0xFC, 0xCE, 0x01, 0x47, 0xFF,
1627 0x31, 0x00, 0xFD, 0xFF, 0x09, 0x00, 0xDC, 0xFF, 0x31, 0x00, 0x04,
1628 0x00, 0x32, 0xFF, 0xDC, 0x02, 0x42, 0xF7, 0x0B, 0x44, 0x8E, 0x15,
1629 0x34, 0xF6, 0xB7, 0x05, 0xAB, 0xFC, 0xC1, 0x01, 0x40, 0xFF, 0x33,
1630 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x20, 0x00, 0x7E, 0xFF, 0x23, 0x01,
1631 0x0F, 0xFE, 0xD7, 0x02, 0x3B, 0xFC, 0xF5, 0x04, 0xED, 0x48, 0x70,
1632 0x02, 0x52, 0xFD, 0x46, 0x02, 0x5A, 0xFE, 0xFF, 0x00, 0x8B, 0xFF,
1633 0x1C, 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x3B, 0xFF, 0xD2, 0x01, 0x81,
1634 0xFC, 0x1A, 0x06, 0x47, 0xF5, 0xC1, 0x18, 0x60, 0x42, 0xE4, 0xF5,
1635 0xA6, 0x03, 0xB9, 0xFE, 0x48, 0x00, 0x0F, 0x00, 0xE9, 0xFF, 0x07,
1636 0x00, 0xFD, 0xFF, 0x2E, 0x00, 0x53, 0xFF, 0xBB, 0x01, 0x5A, 0xFC,
1637 0x1C, 0x07, 0x8D, 0xF1, 0x34, 0x2E, 0x48, 0x32, 0x81, 0xF1, 0xE7,
1638 0x06, 0x8E, 0xFC, 0x96, 0x01, 0x66, 0xFF, 0x27, 0x00, 0xFD, 0xFF,
1639 0x04, 0x00, 0xF9, 0xFF, 0xE4, 0xFF, 0x9F, 0x00, 0x23, 0xFE, 0x9B,
1640 0x04, 0x55, 0xF4, 0xC0, 0x3F, 0x2C, 0x1D, 0x22, 0xF4, 0x8C, 0x06,
1641 0x55, 0xFC, 0xE1, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x17,
1642 0x00, 0x9F, 0xFF, 0xCE, 0x00, 0xC2, 0xFE, 0x80, 0x01, 0xC6, 0xFE,
1643 0x40, 0xFF, 0x81, 0x48, 0x9E, 0x08, 0xBA, 0xFA, 0x9A, 0x03, 0xAC,
1644 0xFD, 0x51, 0x01, 0x6C, 0xFF, 0x25, 0x00, 0x00, 0x00, 0xFF, 0xFF,
1645 0x2F, 0x00, 0x4B, 0xFF, 0xA4, 0x01, 0xF1, 0xFC, 0x1D, 0x05, 0x8F,
1646 0xF7, 0x4A, 0x11, 0xF2, 0x45, 0x6B, 0xF9, 0xAE, 0x01, 0xE2, 0xFF,
1647 0xA2, 0xFF, 0x61, 0x00, 0xC9, 0xFF, 0x0D, 0x00, 0xFD, 0xFF, 0x35,
1648 0x00, 0x3D, 0xFF, 0xE0, 0x01, 0x32, 0xFC, 0x1D, 0x07, 0x45, 0xF2,
1649 0xC6, 0x26, 0xD3, 0x38, 0x24, 0xF2, 0x2D, 0x06, 0x1B, 0xFD, 0x3B,
1650 0x01, 0x95, 0xFF, 0x16, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x11, 0x00,
1651 0xA3, 0xFF, 0x20, 0x01, 0x49, 0xFD, 0xEB, 0x05, 0x74, 0xF2, 0x54,
1652 0x3A, 0xDD, 0x24, 0x91, 0xF2, 0x0C, 0x07, 0x32, 0xFC, 0xE4, 0x01,
1653 0x3A, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x0F, 0x00, 0xC1, 0xFF, 0x76,
1654 0x00, 0x76, 0xFF, 0x32, 0x00, 0x22, 0x01, 0x76, 0xFA, 0xA3, 0x46,
1655 0x7D, 0x0F, 0x2C, 0xF8, 0xD5, 0x04, 0x13, 0xFD, 0x96, 0x01, 0x51,
1656 0xFF, 0x2D, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x27, 0x00, 0x64, 0xFF,
1657 0x63, 0x01, 0x84, 0xFD, 0xEB, 0x03, 0x14, 0xFA, 0x47, 0x0A, 0x2C,
1658 0x48, 0xF6, 0xFD, 0x63, 0xFF, 0x2B, 0x01, 0xF0, 0xFE, 0xB8, 0x00,
1659 0xA8, 0xFF, 0x15, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE4,
1660 0x01, 0x47, 0xFC, 0xB5, 0x06, 0xB0, 0xF3, 0x19, 0x1F, 0x7E, 0x3E,
1661 0xC4, 0xF3, 0xFA, 0x04, 0xE7, 0xFD, 0xC1, 0x00, 0xD3, 0xFF, 0xFF,
1662 0xFF, 0x02, 0x00, 0xFE, 0xFF, 0x23, 0x00, 0x71, 0xFF, 0x82, 0x01,
1663 0xAB, 0xFC, 0xC4, 0x06, 0x93, 0xF1, 0xFD, 0x33, 0x62, 0x2C, 0xA8,
1664 0xF1, 0x27, 0x07, 0x4A, 0xFC, 0xC7, 0x01, 0x4C, 0xFF, 0x30, 0x00,
1665 0xFD, 0xFF, 0x08, 0x00, 0xE1, 0xFF, 0x23, 0x00, 0x20, 0x00, 0x00,
1666 0xFF, 0x31, 0x03, 0xAD, 0xF6, 0x65, 0x43, 0xDC, 0x16, 0xD1, 0xF5,
1667 0xE1, 0x05, 0x99, 0xFC, 0xC9, 0x01, 0x3E, 0xFF, 0x33, 0x00, 0xFF,
1668 0xFF, 0x00, 0x00, 0x1F, 0x00, 0x83, 0xFF, 0x14, 0x01, 0x2D, 0xFE,
1669 0x9C, 0x02, 0xAD, 0xFC, 0xE9, 0x03, 0xF6, 0x48, 0x73, 0x03, 0xE0,
1670 0xFC, 0x82, 0x02, 0x3B, 0xFE, 0x0E, 0x01, 0x86, 0xFF, 0x1E, 0x00,
1671 0xFE, 0xFF, 0x34, 0x00, 0x3D, 0xFF, 0xCC, 0x01, 0x91, 0xFC, 0xF3,
1672 0x05, 0xA6, 0xF5, 0x70, 0x17, 0x17, 0x43, 0x6D, 0xF6, 0x56, 0x03,
1673 0xEA, 0xFE, 0x2D, 0x00, 0x1D, 0x00, 0xE4, 0xFF, 0x08, 0x00, 0xFD,
1674 0xFF, 0x2F, 0x00, 0x4E, 0xFF, 0xC3, 0x01, 0x4E, 0xFC, 0x24, 0x07,
1675 0x9E, 0xF1, 0xF2, 0x2C, 0x78, 0x33, 0x8C, 0xF1, 0xD0, 0x06, 0xA2,
1676 0xFC, 0x88, 0x01, 0x6D, 0xFF, 0x24, 0x00, 0xFD, 0xFF, 0x03, 0x00,
1677 0xFD, 0xFF, 0xD8, 0xFF, 0xB7, 0x00, 0xF9, 0xFD, 0xDE, 0x04, 0xEF,
1678 0xF3, 0xE4, 0x3E, 0x81, 0x1E, 0xD2, 0xF3, 0xA9, 0x06, 0x4B, 0xFC,
1679 0xE3, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x16, 0x00, 0xA5,
1680 0xFF, 0xBE, 0x00, 0xE2, 0xFE, 0x45, 0x01, 0x33, 0xFF, 0x5A, 0xFE,
1681 0x48, 0x48, 0xC3, 0x09, 0x47, 0xFA, 0xD2, 0x03, 0x90, 0xFD, 0x5E,
1682 0x01, 0x66, 0xFF, 0x27, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2E, 0x00,
1683 0x4F, 0xFF, 0x9A, 0x01, 0x08, 0xFD, 0xEB, 0x04, 0xFC, 0xF7, 0x0A,
1684 0x10, 0x70, 0x46, 0x22, 0xFA, 0x4D, 0x01, 0x19, 0x00, 0x84, 0xFF,
1685 0x70, 0x00, 0xC4, 0xFF, 0x0F, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3B,
1686 0xFF, 0xE3, 0x01, 0x31, 0xFC, 0x12, 0x07, 0x79, 0xF2, 0x73, 0x25,
1687 0xDF, 0x39, 0x5A, 0xF2, 0x00, 0x06, 0x3A, 0xFD, 0x28, 0x01, 0x9F,
1688 0xFF, 0x13, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x15, 0x00, 0x99, 0xFF,
1689 0x33, 0x01, 0x29, 0xFD, 0x1A, 0x06, 0x3B, 0xF2, 0x4B, 0x39, 0x30,
1690 0x26, 0x5B, 0xF2, 0x19, 0x07, 0x31, 0xFC, 0xE1, 0x01, 0x3C, 0xFF,
1691 0x35, 0x00, 0xFD, 0xFF, 0x0E, 0x00, 0xC7, 0xFF, 0x68, 0x00, 0x95,
1692 0xFF, 0xFA, 0xFF, 0x83, 0x01, 0xBB, 0xF9, 0x2B, 0x46, 0xBB, 0x10,
1693 0xBF, 0xF7, 0x07, 0x05, 0xFB, 0xFC, 0xA0, 0x01, 0x4D, 0xFF, 0x2F,
1694 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x26, 0x00, 0x69, 0xFF, 0x56, 0x01,
1695 0xA0, 0xFD, 0xB3, 0x03, 0x87, 0xFA, 0x1F, 0x09, 0x6A, 0x48, 0xD9,
1696 0xFE, 0xF6, 0xFE, 0x65, 0x01, 0xD0, 0xFE, 0xC7, 0x00, 0xA2, 0xFF,
1697 0x17, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE2, 0x01, 0x50,
1698 0xFC, 0x99, 0x06, 0xFE, 0xF3, 0xC3, 0x1D, 0x5E, 0x3F, 0x27, 0xF4,
1699 0xB9, 0x04, 0x10, 0xFE, 0xA9, 0x00, 0xDF, 0xFF, 0xFB, 0xFF, 0x03,
1700 0x00, 0xFD, 0xFF, 0x26, 0x00, 0x69, 0xFF, 0x90, 0x01, 0x96, 0xFC,
1701 0xDD, 0x06, 0x85, 0xF1, 0xD0, 0x32, 0xA6, 0x2D, 0x94, 0xF1, 0x20,
1702 0x07, 0x54, 0xFC, 0xBF, 0x01, 0x50, 0xFF, 0x2E, 0x00, 0xFD, 0xFF,
1703 0x07, 0x00, 0xE6, 0xFF, 0x15, 0x00, 0x3C, 0x00, 0xCF, 0xFE, 0x83,
1704 0x03, 0x20, 0xF6, 0xB2, 0x42, 0x2B, 0x18, 0x71, 0xF5, 0x09, 0x06,
1705 0x88, 0xFC, 0xCF, 0x01, 0x3C, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0x1D,
1706 0x00, 0x89, 0xFF, 0x06, 0x01, 0x4C, 0xFE, 0x60, 0x02, 0x1F, 0xFD,
1707 0xE2, 0x02, 0xF3, 0x48, 0x7D, 0x04, 0x6E, 0xFC, 0xBD, 0x02, 0x1C,
1708 0xFE, 0x1C, 0x01, 0x80, 0xFF, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF,
1709 0x33, 0x00, 0x3F, 0xFF, 0xC5, 0x01, 0xA3, 0xFC, 0xCA, 0x05, 0x07,
1710 0xF6, 0x22, 0x16, 0xC3, 0x43, 0xFE, 0xF6, 0x02, 0x03, 0x1B, 0xFF,
1711 0x11, 0x00, 0x2B, 0x00, 0xDE, 0xFF, 0x09, 0x00, 0xFD, 0xFF, 0x31,
1712 0x00, 0x49, 0xFF, 0xCB, 0x01, 0x45, 0xFC, 0x29, 0x07, 0xB6, 0xF1,
1713 0xAD, 0x2B, 0xA2, 0x34, 0x9E, 0xF1, 0xB4, 0x06, 0xB8, 0xFC, 0x7A,
1714 0x01, 0x75, 0xFF, 0x22, 0x00, 0xFE, 0xFF, 0x02, 0x00, 0x02, 0x00,
1715 0xCC, 0xFF, 0xCE, 0x00, 0xD1, 0xFD, 0x1D, 0x05, 0x91, 0xF3, 0xFE,
1716 0x3D, 0xD7, 0x1F, 0x87, 0xF3, 0xC3, 0x06, 0x42, 0xFC, 0xE5, 0x01,
1717 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x14, 0x00, 0xAB, 0xFF, 0xAF,
1718 0x00, 0x01, 0xFF, 0x0A, 0x01, 0x9E, 0xFF, 0x7C, 0xFD, 0x03, 0x48,
1719 0xED, 0x0A, 0xD5, 0xF9, 0x0A, 0x04, 0x74, 0xFD, 0x6A, 0x01, 0x62,
1720 0xFF, 0x28, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x2D, 0x00, 0x53, 0xFF,
1721 0x90, 0x01, 0x20, 0xFD, 0xB8, 0x04, 0x6A, 0xF8, 0xCD, 0x0E, 0xE1,
1722 0x46, 0xE1, 0xFA, 0xEB, 0x00, 0x51, 0x00, 0x65, 0xFF, 0x7F, 0x00,
1723 0xBE, 0xFF, 0x10, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x39, 0xFF, 0xE5,
1724 0x01, 0x33, 0xFC, 0x04, 0x07, 0xB1, 0xF2, 0x21, 0x24, 0xE6, 0x3A,
1725 0x97, 0xF2, 0xD0, 0x05, 0x5B, 0xFD, 0x15, 0x01, 0xA9, 0xFF, 0x0F,
1726 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x18, 0x00, 0x90, 0xFF, 0x45, 0x01,
1727 0x0B, 0xFD, 0x44, 0x06, 0x0A, 0xF2, 0x3B, 0x38, 0x80, 0x27, 0x2B,
1728 0xF2, 0x22, 0x07, 0x33, 0xFC, 0xDE, 0x01, 0x3E, 0xFF, 0x34, 0x00,
1729 0xFD, 0xFF, 0x0D, 0x00, 0xCD, 0xFF, 0x59, 0x00, 0xB3, 0xFF, 0xC4,
1730 0xFF, 0xE2, 0x01, 0x09, 0xF9, 0xAA, 0x45, 0xFE, 0x11, 0x54, 0xF7,
1731 0x38, 0x05, 0xE4, 0xFC, 0xAA, 0x01, 0x49, 0xFF, 0x30, 0x00, 0xFF,
1732 0xFF, 0x00, 0x00, 0x24, 0x00, 0x6E, 0xFF, 0x49, 0x01, 0xBC, 0xFD,
1733 0x7A, 0x03, 0xFA, 0xFA, 0xFD, 0x07, 0x9C, 0x48, 0xC3, 0xFF, 0x89,
1734 0xFE, 0xA1, 0x01, 0xB1, 0xFE, 0xD6, 0x00, 0x9C, 0xFF, 0x18, 0x00,
1735 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xDF, 0x01, 0x5B, 0xFC, 0x7B,
1736 0x06, 0x50, 0xF4, 0x6E, 0x1C, 0x36, 0x40, 0x92, 0xF4, 0x75, 0x04,
1737 0x3B, 0xFE, 0x91, 0x00, 0xEB, 0xFF, 0xF6, 0xFF, 0x04, 0x00, 0xFD,
1738 0xFF, 0x28, 0x00, 0x63, 0xFF, 0x9D, 0x01, 0x84, 0xFC, 0xF3, 0x06,
1739 0x7D, 0xF1, 0x9E, 0x31, 0xE6, 0x2E, 0x85, 0xF1, 0x16, 0x07, 0x61,
1740 0xFC, 0xB5, 0x01, 0x55, 0xFF, 0x2D, 0x00, 0xFD, 0xFF, 0x06, 0x00,
1741 0xEC, 0xFF, 0x08, 0x00, 0x57, 0x00, 0x9F, 0xFE, 0xD1, 0x03, 0x9B,
1742 0xF5, 0xF7, 0x41, 0x7C, 0x19, 0x13, 0xF5, 0x2F, 0x06, 0x78, 0xFC,
1743 0xD5, 0x01, 0x3A, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1C, 0x00, 0x8F,
1744 0xFF, 0xF7, 0x00, 0x6B, 0xFE, 0x25, 0x02, 0x91, 0xFD, 0xE3, 0x01,
1745 0xE5, 0x48, 0x8D, 0x05, 0xFB, 0xFB, 0xF8, 0x02, 0xFE, 0xFD, 0x2B,
1746 0x01, 0x7A, 0xFF, 0x21, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x32, 0x00,
1747 0x42, 0xFF, 0xBD, 0x01, 0xB6, 0xFC, 0x9F, 0x05, 0x6C, 0xF6, 0xD6,
1748 0x14, 0x65, 0x44, 0x98, 0xF7, 0xAC, 0x02, 0x4E, 0xFF, 0xF4, 0xFF,
1749 0x39, 0x00, 0xD9, 0xFF, 0x0A, 0x00, 0xFD, 0xFF, 0x32, 0x00, 0x45,
1750 0xFF, 0xD2, 0x01, 0x3D, 0xFC, 0x2B, 0x07, 0xD4, 0xF1, 0x64, 0x2A,
1751 0xC6, 0x35, 0xB7, 0xF1, 0x96, 0x06, 0xCF, 0xFC, 0x6B, 0x01, 0x7D,
1752 0xFF, 0x1F, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x06, 0x00, 0xC1, 0xFF,
1753 0xE5, 0x00, 0xAA, 0xFD, 0x58, 0x05, 0x3A, 0xF3, 0x11, 0x3D, 0x2C,
1754 0x21, 0x3F, 0xF3, 0xDA, 0x06, 0x3B, 0xFC, 0xE6, 0x01, 0x36, 0xFF,
1755 0x36, 0x00, 0xFD, 0xFF, 0x13, 0x00, 0xB1, 0xFF, 0xA0, 0x00, 0x20,
1756 0xFF, 0xD0, 0x00, 0x07, 0x00, 0xA4, 0xFC, 0xB6, 0x47, 0x1C, 0x0C,
1757 0x63, 0xF9, 0x42, 0x04, 0x59, 0xFD, 0x76, 0x01, 0x5D, 0xFF, 0x2A,
1758 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x57, 0xFF, 0x85, 0x01,
1759 0x39, 0xFD, 0x84, 0x04, 0xD9, 0xF8, 0x95, 0x0D, 0x48, 0x47, 0xA7,
1760 0xFB, 0x86, 0x00, 0x8A, 0x00, 0x46, 0xFF, 0x8E, 0x00, 0xB8, 0xFF,
1761 0x11, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x35,
1762 0xFC, 0xF3, 0x06, 0xEE, 0xF2, 0xCD, 0x22, 0xE4, 0x3B, 0xDC, 0xF2,
1763 0x9C, 0x05, 0x7E, 0xFD, 0x00, 0x01, 0xB4, 0xFF, 0x0B, 0x00, 0x01,
1764 0x00, 0xFE, 0xFF, 0x1B, 0x00, 0x87, 0xFF, 0x57, 0x01, 0xEF, 0xFC,
1765 0x6B, 0x06, 0xE0, 0xF1, 0x23, 0x37, 0xCE, 0x28, 0x01, 0xF2, 0x28,
1766 0x07, 0x36, 0xFC, 0xD9, 0x01, 0x41, 0xFF, 0x33, 0x00, 0xFD, 0xFF,
1767 0x0B, 0x00, 0xD2, 0xFF, 0x4A, 0x00, 0xD0, 0xFF, 0x8E, 0xFF, 0x3F,
1768 0x02, 0x5E, 0xF8, 0x1E, 0x45, 0x44, 0x13, 0xEA, 0xF6, 0x67, 0x05,
1769 0xCF, 0xFC, 0xB3, 0x01, 0x46, 0xFF, 0x31, 0x00, 0xFF, 0xFF, 0x00,
1770 0x00, 0x23, 0x00, 0x74, 0xFF, 0x3C, 0x01, 0xDA, 0xFD, 0x40, 0x03,
1771 0x6E, 0xFB, 0xE1, 0x06, 0xC3, 0x48, 0xB3, 0x00, 0x1A, 0xFE, 0xDC,
1772 0x01, 0x91, 0xFE, 0xE5, 0x00, 0x96, 0xFF, 0x1A, 0x00, 0xFE, 0xFF,
1773 0x36, 0x00, 0x38, 0xFF, 0xDB, 0x01, 0x67, 0xFC, 0x5A, 0x06, 0xA6,
1774 0xF4, 0x1B, 0x1B, 0x07, 0x41, 0x04, 0xF5, 0x2D, 0x04, 0x67, 0xFE,
1775 0x77, 0x00, 0xF8, 0xFF, 0xF2, 0xFF, 0x05, 0x00, 0xFD, 0xFF, 0x2A,
1776 0x00, 0x5C, 0xFF, 0xA8, 0x01, 0x73, 0xFC, 0x05, 0x07, 0x7D, 0xF1,
1777 0x67, 0x30, 0x21, 0x30, 0x7E, 0xF1, 0x08, 0x07, 0x6F, 0xFC, 0xAB,
1778 0x01, 0x5B, 0xFF, 0x2B, 0x00, 0xFD, 0xFF, 0x05, 0x00, 0xF0, 0xFF,
1779 0xFB, 0xFF, 0x71, 0x00, 0x71, 0xFE, 0x1D, 0x04, 0x1F, 0xF5, 0x32,
1780 0x41, 0xCE, 0x1A, 0xBA, 0xF4, 0x53, 0x06, 0x6A, 0xFC, 0xDA, 0x01,
1781 0x38, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x1A, 0x00, 0x95, 0xFF, 0xE8,
1782 0x00, 0x8A, 0xFE, 0xE9, 0x01, 0x01, 0xFE, 0xEA, 0x00, 0xCB, 0x48,
1783 0xA2, 0x06, 0x87, 0xFB, 0x33, 0x03, 0xE0, 0xFD, 0x39, 0x01, 0x75,
1784 0xFF, 0x23, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x31, 0x00, 0x45, 0xFF,
1785 0xB5, 0x01, 0xCA, 0xFC, 0x72, 0x05, 0xD3, 0xF6, 0x8D, 0x13, 0xFD,
1786 0x44, 0x39, 0xF8, 0x53, 0x02, 0x82, 0xFF, 0xD7, 0xFF, 0x47, 0x00,
1787 0xD3, 0xFF, 0x0B, 0x00, 0xFD, 0xFF, 0x33, 0x00, 0x42, 0xFF, 0xD8,
1788 0x01, 0x37, 0xFC, 0x29, 0x07, 0xF8, 0xF1, 0x19, 0x29, 0xE5, 0x36,
1789 0xD8, 0xF1, 0x73, 0x06, 0xE9, 0xFC, 0x5B, 0x01, 0x85, 0xFF, 0x1C,
1790 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x0A, 0x00, 0xB6, 0xFF, 0xFB, 0x00,
1791 0x85, 0xFD, 0x90, 0x05, 0xEC, 0xF2, 0x1C, 0x3C, 0x81, 0x22, 0xFC,
1792 0xF2, 0xEF, 0x06, 0x36, 0xFC, 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00,
1793 0xFD, 0xFF, 0x12, 0x00, 0xB7, 0xFF, 0x91, 0x00, 0x40, 0xFF, 0x96,
1794 0x00, 0x6F, 0x00, 0xD5, 0xFB, 0x5E, 0x47, 0x50, 0x0D, 0xF2, 0xF8,
1795 0x78, 0x04, 0x3F, 0xFD, 0x82, 0x01, 0x58, 0xFF, 0x2B, 0x00, 0x00,
1796 0x00, 0x00, 0x00, 0x2A, 0x00, 0x5C, 0xFF, 0x79, 0x01, 0x53, 0xFD,
1797 0x4E, 0x04, 0x4A, 0xF9, 0x60, 0x0C, 0xA3, 0x47, 0x76, 0xFC, 0x1F,
1798 0x00, 0xC3, 0x00, 0x27, 0xFF, 0x9D, 0x00, 0xB2, 0xFF, 0x13, 0x00,
1799 0xFD, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x3A, 0xFC, 0xDF,
1800 0x06, 0x30, 0xF3, 0x78, 0x21, 0xDB, 0x3C, 0x28, 0xF3, 0x65, 0x05,
1801 0xA2, 0xFD, 0xEA, 0x00, 0xBE, 0xFF, 0x07, 0x00, 0x01, 0x00, 0xFE,
1802 0xFF, 0x1E, 0x00, 0x7F, 0xFF, 0x67, 0x01, 0xD5, 0xFC, 0x8E, 0x06,
1803 0xBE, 0xF1, 0x06, 0x36, 0x1A, 0x2A, 0xDC, 0xF1, 0x2A, 0x07, 0x3C,
1804 0xFC, 0xD3, 0x01, 0x44, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0x0A, 0x00,
1805 0xD8, 0xFF, 0x3C, 0x00, 0xEE, 0xFF, 0x5A, 0xFF, 0x98, 0x02, 0xBB,
1806 0xF7, 0x87, 0x44, 0x8C, 0x14, 0x83, 0xF6, 0x95, 0x05, 0xBA, 0xFC,
1807 0xBB, 0x01, 0x43, 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x21,
1808 0x00, 0x79, 0xFF, 0x2E, 0x01, 0xF7, 0xFD, 0x05, 0x03, 0xE1, 0xFB,
1809 0xCA, 0x05, 0xDF, 0x48, 0xAB, 0x01, 0xAA, 0xFD, 0x18, 0x02, 0x72,
1810 0xFE, 0xF4, 0x00, 0x90, 0xFF, 0x1B, 0x00, 0xFE, 0xFF, 0x35, 0x00,
1811 0x39, 0xFF, 0xD6, 0x01, 0x75, 0xFC, 0x37, 0x06, 0xFF, 0xF4, 0xC7,
1812 0x19, 0xCC, 0x41, 0x7F, 0xF5, 0xE2, 0x03, 0x95, 0xFE, 0x5D, 0x00,
1813 0x05, 0x00, 0xED, 0xFF, 0x06, 0x00, 0xFD, 0xFF, 0x2C, 0x00, 0x57,
1814 0xFF, 0xB3, 0x01, 0x64, 0xFC, 0x13, 0x07, 0x83, 0xF1, 0x2C, 0x2F,
1815 0x5A, 0x31, 0x7D, 0xF1, 0xF7, 0x06, 0x80, 0xFC, 0x9F, 0x01, 0x61,
1816 0xFF, 0x29, 0x00, 0xFD, 0xFF, 0x04, 0x00, 0xF5, 0xFF, 0xEE, 0xFF,
1817 0x8B, 0x00, 0x44, 0xFE, 0x65, 0x04, 0xAA, 0xF4, 0x66, 0x40, 0x23,
1818 0x1C, 0x63, 0xF4, 0x74, 0x06, 0x5D, 0xFC, 0xDE, 0x01, 0x37, 0xFF,
1819 0x36, 0x00, 0xFE, 0xFF, 0x19, 0x00, 0x9A, 0xFF, 0xD9, 0x00, 0xAA,
1820 0xFE, 0xAE, 0x01, 0x70, 0xFE, 0xF8, 0xFF, 0xA6, 0x48, 0xBE, 0x07,
1821 0x14, 0xFB, 0x6D, 0x03, 0xC3, 0xFD, 0x46, 0x01, 0x70, 0xFF, 0x24,
1822 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x30, 0x00, 0x48, 0xFF, 0xAC, 0x01,
1823 0xDF, 0xFC, 0x43, 0x05, 0x3C, 0xF7, 0x46, 0x12, 0x8D, 0x45, 0xE2,
1824 0xF8, 0xF7, 0x01, 0xB8, 0xFF, 0xB9, 0xFF, 0x56, 0x00, 0xCE, 0xFF,
1825 0x0C, 0x00, 0xFD, 0xFF, 0x34, 0x00, 0x3F, 0xFF, 0xDD, 0x01, 0x34,
1826 0xFC, 0x23, 0x07, 0x21, 0xF2, 0xCB, 0x27, 0xFE, 0x37, 0x00, 0xF2,
1827 0x4D, 0x06, 0x04, 0xFD, 0x49, 0x01, 0x8E, 0xFF, 0x19, 0x00, 0xFF,
1828 0xFF, 0x00, 0x00, 0x0E, 0x00, 0xAB, 0xFF, 0x10, 0x01, 0x62, 0xFD,
1829 0xC5, 0x05, 0xA5, 0xF2, 0x1F, 0x3B, 0xD6, 0x23, 0xBE, 0xF2, 0x01,
1830 0x07, 0x33, 0xFC, 0xE5, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFD, 0xFF,
1831 0x10, 0x00, 0xBD, 0xFF, 0x82, 0x00, 0x5E, 0xFF, 0x5D, 0x00, 0xD4,
1832 0x00, 0x0C, 0xFB, 0xF9, 0x46, 0x87, 0x0E, 0x82, 0xF8, 0xAD, 0x04,
1833 0x26, 0xFD, 0x8D, 0x01, 0x54, 0xFF, 0x2C, 0x00, 0xFF, 0xFF, 0x00,
1834 0x00, 0x29, 0x00, 0x60, 0xFF, 0x6D, 0x01, 0x6E, 0xFD, 0x17, 0x04,
1835 0xBC, 0xF9, 0x30, 0x0B, 0xF4, 0x47, 0x4B, 0xFD, 0xB5, 0xFF, 0xFD,
1836 0x00, 0x08, 0xFF, 0xAC, 0x00, 0xAC, 0xFF, 0x14, 0x00, 0xFD, 0xFF,
1837 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x41, 0xFC, 0xC8, 0x06, 0x76,
1838 0xF3, 0x22, 0x20, 0xCA, 0x3D, 0x7D, 0xF3, 0x2A, 0x05, 0xC8, 0xFD,
1839 0xD4, 0x00, 0xCA, 0xFF, 0x03, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x21,
1840 0x00, 0x77, 0xFF, 0x77, 0x01, 0xBD, 0xFC, 0xAE, 0x06, 0xA3, 0xF1,
1841 0xE3, 0x34, 0x64, 0x2B, 0xBC, 0xF1, 0x2A, 0x07, 0x43, 0xFC, 0xCD,
1842 0x01, 0x48, 0xFF, 0x31, 0x00, 0xFD, 0xFF, 0x09, 0x00, 0xDD, 0xFF,
1843 0x2E, 0x00, 0x0A, 0x00, 0x27, 0xFF, 0xEF, 0x02, 0x20, 0xF7, 0xE7,
1844 0x43, 0xD8, 0x15, 0x1E, 0xF6, 0xC0, 0x05, 0xA7, 0xFC, 0xC3, 0x01,
1845 0x40, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x20, 0x00, 0x7F,
1846 0xFF, 0x20, 0x01, 0x16, 0xFE, 0xCA, 0x02, 0x54, 0xFC, 0xB9, 0x04,
1847 0xF2, 0x48, 0xA9, 0x02, 0x39, 0xFD, 0x53, 0x02, 0x53, 0xFE, 0x03,
1848 0x01, 0x8A, 0xFF, 0x1D, 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3B, 0xFF,
1849 0xD1, 0x01, 0x84, 0xFC, 0x12, 0x06, 0x5C, 0xF5, 0x76, 0x18, 0x89,
1850 0x42, 0x02, 0xF6, 0x94, 0x03, 0xC4, 0xFE, 0x42, 0x00, 0x12, 0x00,
1851 0xE8, 0xFF, 0x07, 0x00, 0xFD, 0xFF, 0x2E, 0x00, 0x51, 0xFF, 0xBD,
1852 0x01, 0x57, 0xFC, 0x1E, 0x07, 0x90, 0xF1, 0xED, 0x2D, 0x8C, 0x32,
1853 0x83, 0xF1, 0xE2, 0x06, 0x92, 0xFC, 0x93, 0x01, 0x68, 0xFF, 0x26,
1854 0x00, 0xFD, 0xFF, 0x03, 0x00, 0xFA, 0xFF, 0xE2, 0xFF, 0xA4, 0x00,
1855 0x19, 0xFE, 0xAA, 0x04, 0x3E, 0xF4, 0x90, 0x3F, 0x78, 0x1D, 0x10,
1856 0xF4, 0x93, 0x06, 0x52, 0xFC, 0xE1, 0x01, 0x36, 0xFF, 0x36, 0x00,
1857 0xFE, 0xFF, 0x17, 0x00, 0xA0, 0xFF, 0xCA, 0x00, 0xC9, 0xFE, 0x73,
1858 0x01, 0xDE, 0xFE, 0x0C, 0xFF, 0x76, 0x48, 0xDE, 0x08, 0xA1, 0xFA,
1859 0xA6, 0x03, 0xA6, 0xFD, 0x53, 0x01, 0x6A, 0xFF, 0x26, 0x00, 0x00,
1860 0x00, 0xFF, 0xFF, 0x2F, 0x00, 0x4C, 0xFF, 0xA2, 0x01, 0xF6, 0xFC,
1861 0x12, 0x05, 0xA7, 0xF7, 0x03, 0x11, 0x10, 0x46, 0x93, 0xF9, 0x98,
1862 0x01, 0xEE, 0xFF, 0x9B, 0xFF, 0x64, 0x00, 0xC8, 0xFF, 0x0E, 0x00,
1863 0xFD, 0xFF, 0x35, 0x00, 0x3C, 0xFF, 0xE1, 0x01, 0x32, 0xFC, 0x1B,
1864 0x07, 0x50, 0xF2, 0x7B, 0x26, 0x11, 0x39, 0x2F, 0xF2, 0x23, 0x06,
1865 0x22, 0xFD, 0x37, 0x01, 0x97, 0xFF, 0x15, 0x00, 0xFF, 0xFF, 0x00,
1866 0x00, 0x12, 0x00, 0xA1, 0xFF, 0x24, 0x01, 0x41, 0xFD, 0xF6, 0x05,
1867 0x67, 0xF2, 0x1A, 0x3A, 0x29, 0x25, 0x84, 0xF2, 0x0F, 0x07, 0x31,
1868 0xFC, 0xE3, 0x01, 0x3A, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x0F, 0x00,
1869 0xC2, 0xFF, 0x73, 0x00, 0x7D, 0xFF, 0x25, 0x00, 0x38, 0x01, 0x4C,
1870 0xFA, 0x89, 0x46, 0xC3, 0x0F, 0x14, 0xF8, 0xE0, 0x04, 0x0D, 0xFD,
1871 0x98, 0x01, 0x50, 0xFF, 0x2E, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x27,
1872 0x00, 0x65, 0xFF, 0x60, 0x01, 0x8A, 0xFD, 0xDF, 0x03, 0x2E, 0xFA,
1873 0x04, 0x0A, 0x3A, 0x48, 0x28, 0xFE, 0x4B, 0xFF, 0x38, 0x01, 0xE9,
1874 0xFE, 0xBB, 0x00, 0xA6, 0xFF, 0x16, 0x00, 0xFE, 0xFF, 0x36, 0x00,
1875 0x36, 0xFF, 0xE4, 0x01, 0x49, 0xFC, 0xAF, 0x06, 0xC1, 0xF3, 0xCD,
1876 0x1E, 0xB1, 0x3E, 0xD9, 0xF3, 0xEC, 0x04, 0xF0, 0xFD, 0xBC, 0x00,
1877 0xD5, 0xFF, 0xFE, 0xFF, 0x03, 0x00, 0xFD, 0xFF, 0x24, 0x00, 0x6F,
1878 0xFF, 0x85, 0x01, 0xA6, 0xFC, 0xCA, 0x06, 0x8F, 0xF1, 0xBB, 0x33,
1879 0xAB, 0x2C, 0xA3, 0xF1, 0x26, 0x07, 0x4C, 0xFC, 0xC5, 0x01, 0x4D,
1880 0xFF, 0x30, 0x00, 0xFD, 0xFF, 0x08, 0x00, 0xE2, 0xFF, 0x20, 0x00,
1881 0x26, 0x00, 0xF5, 0xFE, 0x43, 0x03, 0x8D, 0xF6, 0x3C, 0x43, 0x25,
1882 0x17, 0xBB, 0xF5, 0xEA, 0x05, 0x95, 0xFC, 0xCA, 0x01, 0x3D, 0xFF,
1883 0x34, 0x00, 0xFE, 0xFF, 0x00, 0x00, 0x1E, 0x00, 0x84, 0xFF, 0x11,
1884 0x01, 0x34, 0xFE, 0x8F, 0x02, 0xC7, 0xFC, 0xAE, 0x03, 0xF7, 0x48,
1885 0xAE, 0x03, 0xC7, 0xFC, 0x8F, 0x02, 0x34, 0xFE, 0x11, 0x01, 0x84,
1886 0xFF, 0x1E, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01,
1887 0x3D, 0xFC, 0xD6, 0x06, 0x4C, 0xF3, 0xED, 0x20, 0x3D, 0x3D, 0x4A,
1888 0xF3, 0x4E, 0x05, 0xB1, 0xFD, 0xE1, 0x00, 0xC3, 0xFF, 0x05, 0x00,
1889 0x02, 0x00, 0x02, 0x00, 0x05, 0x00, 0xC3, 0xFF, 0xE1, 0x00, 0xB1,
1890 0xFD, 0x4E, 0x05, 0x4A, 0xF3, 0x3D, 0x3D, 0xED, 0x20, 0x4C, 0xF3,
1891 0xD6, 0x06, 0x3D, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD,
1892 0xFF, 0x00, 0x00, 0x1E, 0x00, 0x84, 0xFF, 0x11, 0x01, 0x34, 0xFE,
1893 0x8F, 0x02, 0xC7, 0xFC, 0xAE, 0x03, 0xF7, 0x48, 0xAE, 0x03, 0xC7,
1894 0xFC, 0x8F, 0x02, 0x34, 0xFE, 0x11, 0x01, 0x84, 0xFF, 0x1E, 0x00,
1895 0xFD, 0xFF, 0x30, 0x00, 0x4D, 0xFF, 0xC5, 0x01, 0x4C, 0xFC, 0x26,
1896 0x07, 0xA3, 0xF1, 0xAB, 0x2C, 0xBB, 0x33, 0x8F, 0xF1, 0xCA, 0x06,
1897 0xA6, 0xFC, 0x85, 0x01, 0x6F, 0xFF, 0x24, 0x00, 0xFD, 0xFF, 0x16,
1898 0x00, 0xA6, 0xFF, 0xBB, 0x00, 0xE9, 0xFE, 0x38, 0x01, 0x4B, 0xFF,
1899 0x28, 0xFE, 0x3A, 0x48, 0x04, 0x0A, 0x2E, 0xFA, 0xDF, 0x03, 0x8A,
1900 0xFD, 0x60, 0x01, 0x65, 0xFF, 0x27, 0x00, 0x00, 0x00, 0xFD, 0xFF,
1901 0x35, 0x00, 0x3A, 0xFF, 0xE3, 0x01, 0x31, 0xFC, 0x0F, 0x07, 0x84,
1902 0xF2, 0x29, 0x25, 0x1A, 0x3A, 0x67, 0xF2, 0xF6, 0x05, 0x41, 0xFD,
1903 0x24, 0x01, 0xA1, 0xFF, 0x12, 0x00, 0x00, 0x00, 0x0E, 0x00, 0xC8,
1904 0xFF, 0x64, 0x00, 0x9B, 0xFF, 0xEE, 0xFF, 0x98, 0x01, 0x93, 0xF9,
1905 0x10, 0x46, 0x03, 0x11, 0xA7, 0xF7, 0x12, 0x05, 0xF6, 0xFC, 0xA2,
1906 0x01, 0x4C, 0xFF, 0x2F, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00,
1907 0x36, 0xFF, 0xE1, 0x01, 0x52, 0xFC, 0x93, 0x06, 0x10, 0xF4, 0x78,
1908 0x1D, 0x90, 0x3F, 0x3E, 0xF4, 0xAA, 0x04, 0x19, 0xFE, 0xA4, 0x00,
1909 0xE2, 0xFF, 0xFA, 0xFF, 0x03, 0x00, 0x07, 0x00, 0xE8, 0xFF, 0x12,
1910 0x00, 0x42, 0x00, 0xC4, 0xFE, 0x94, 0x03, 0x02, 0xF6, 0x89, 0x42,
1911 0x76, 0x18, 0x5C, 0xF5, 0x12, 0x06, 0x84, 0xFC, 0xD1, 0x01, 0x3B,
1912 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x33, 0x00, 0x40, 0xFF,
1913 0xC3, 0x01, 0xA7, 0xFC, 0xC0, 0x05, 0x1E, 0xF6, 0xD8, 0x15, 0xE7,
1914 0x43, 0x20, 0xF7, 0xEF, 0x02, 0x27, 0xFF, 0x0A, 0x00, 0x2E, 0x00,
1915 0xDD, 0xFF, 0x09, 0x00, 0x02, 0x00, 0x03, 0x00, 0xCA, 0xFF, 0xD4,
1916 0x00, 0xC8, 0xFD, 0x2A, 0x05, 0x7D, 0xF3, 0xCA, 0x3D, 0x22, 0x20,
1917 0x76, 0xF3, 0xC8, 0x06, 0x41, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36,
1918 0x00, 0xFD, 0xFF, 0xFF, 0xFF, 0x2C, 0x00, 0x54, 0xFF, 0x8D, 0x01,
1919 0x26, 0xFD, 0xAD, 0x04, 0x82, 0xF8, 0x87, 0x0E, 0xF9, 0x46, 0x0C,
1920 0xFB, 0xD4, 0x00, 0x5D, 0x00, 0x5E, 0xFF, 0x82, 0x00, 0xBD, 0xFF,
1921 0x10, 0x00, 0xFF, 0xFF, 0x19, 0x00, 0x8E, 0xFF, 0x49, 0x01, 0x04,
1922 0xFD, 0x4D, 0x06, 0x00, 0xF2, 0xFE, 0x37, 0xCB, 0x27, 0x21, 0xF2,
1923 0x23, 0x07, 0x34, 0xFC, 0xDD, 0x01, 0x3F, 0xFF, 0x34, 0x00, 0xFD,
1924 0xFF, 0x00, 0x00, 0x24, 0x00, 0x70, 0xFF, 0x46, 0x01, 0xC3, 0xFD,
1925 0x6D, 0x03, 0x14, 0xFB, 0xBE, 0x07, 0xA6, 0x48, 0xF8, 0xFF, 0x70,
1926 0xFE, 0xAE, 0x01, 0xAA, 0xFE, 0xD9, 0x00, 0x9A, 0xFF, 0x19, 0x00,
1927 0xFD, 0xFF, 0x29, 0x00, 0x61, 0xFF, 0x9F, 0x01, 0x80, 0xFC, 0xF7,
1928 0x06, 0x7D, 0xF1, 0x5A, 0x31, 0x2C, 0x2F, 0x83, 0xF1, 0x13, 0x07,
1929 0x64, 0xFC, 0xB3, 0x01, 0x57, 0xFF, 0x2C, 0x00, 0xFD, 0xFF, 0x1B,
1930 0x00, 0x90, 0xFF, 0xF4, 0x00, 0x72, 0xFE, 0x18, 0x02, 0xAA, 0xFD,
1931 0xAB, 0x01, 0xDF, 0x48, 0xCA, 0x05, 0xE1, 0xFB, 0x05, 0x03, 0xF7,
1932 0xFD, 0x2E, 0x01, 0x79, 0xFF, 0x21, 0x00, 0x00, 0x00, 0xFD, 0xFF,
1933 0x32, 0x00, 0x44, 0xFF, 0xD3, 0x01, 0x3C, 0xFC, 0x2A, 0x07, 0xDC,
1934 0xF1, 0x1A, 0x2A, 0x06, 0x36, 0xBE, 0xF1, 0x8E, 0x06, 0xD5, 0xFC,
1935 0x67, 0x01, 0x7F, 0xFF, 0x1E, 0x00, 0xFE, 0xFF, 0x13, 0x00, 0xB2,
1936 0xFF, 0x9D, 0x00, 0x27, 0xFF, 0xC3, 0x00, 0x1F, 0x00, 0x76, 0xFC,
1937 0xA3, 0x47, 0x60, 0x0C, 0x4A, 0xF9, 0x4E, 0x04, 0x53, 0xFD, 0x79,
1938 0x01, 0x5C, 0xFF, 0x2A, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x36, 0x00,
1939 0x37, 0xFF, 0xE6, 0x01, 0x36, 0xFC, 0xEF, 0x06, 0xFC, 0xF2, 0x81,
1940 0x22, 0x1C, 0x3C, 0xEC, 0xF2, 0x90, 0x05, 0x85, 0xFD, 0xFB, 0x00,
1941 0xB6, 0xFF, 0x0A, 0x00, 0x01, 0x00, 0x0B, 0x00, 0xD3, 0xFF, 0x47,
1942 0x00, 0xD7, 0xFF, 0x82, 0xFF, 0x53, 0x02, 0x39, 0xF8, 0xFD, 0x44,
1943 0x8D, 0x13, 0xD3, 0xF6, 0x72, 0x05, 0xCA, 0xFC, 0xB5, 0x01, 0x45,
1944 0xFF, 0x31, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x35, 0x00, 0x38, 0xFF,
1945 0xDA, 0x01, 0x6A, 0xFC, 0x53, 0x06, 0xBA, 0xF4, 0xCE, 0x1A, 0x32,
1946 0x41, 0x1F, 0xF5, 0x1D, 0x04, 0x71, 0xFE, 0x71, 0x00, 0xFB, 0xFF,
1947 0xF0, 0xFF, 0x05, 0x00, 0x05, 0x00, 0xF2, 0xFF, 0xF8, 0xFF, 0x77,
1948 0x00, 0x67, 0xFE, 0x2D, 0x04, 0x04, 0xF5, 0x07, 0x41, 0x1B, 0x1B,
1949 0xA6, 0xF4, 0x5A, 0x06, 0x67, 0xFC, 0xDB, 0x01, 0x38, 0xFF, 0x36,
1950 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x31, 0x00, 0x46, 0xFF, 0xB3, 0x01,
1951 0xCF, 0xFC, 0x67, 0x05, 0xEA, 0xF6, 0x44, 0x13, 0x1E, 0x45, 0x5E,
1952 0xF8, 0x3F, 0x02, 0x8E, 0xFF, 0xD0, 0xFF, 0x4A, 0x00, 0xD2, 0xFF,
1953 0x0B, 0x00, 0x01, 0x00, 0x0B, 0x00, 0xB4, 0xFF, 0x00, 0x01, 0x7E,
1954 0xFD, 0x9C, 0x05, 0xDC, 0xF2, 0xE4, 0x3B, 0xCD, 0x22, 0xEE, 0xF2,
1955 0xF3, 0x06, 0x35, 0xFC, 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD,
1956 0xFF, 0x00, 0x00, 0x2A, 0x00, 0x5D, 0xFF, 0x76, 0x01, 0x59, 0xFD,
1957 0x42, 0x04, 0x63, 0xF9, 0x1C, 0x0C, 0xB6, 0x47, 0xA4, 0xFC, 0x07,
1958 0x00, 0xD0, 0x00, 0x20, 0xFF, 0xA0, 0x00, 0xB1, 0xFF, 0x13, 0x00,
1959 0xFE, 0xFF, 0x1F, 0x00, 0x7D, 0xFF, 0x6B, 0x01, 0xCF, 0xFC, 0x96,
1960 0x06, 0xB7, 0xF1, 0xC6, 0x35, 0x64, 0x2A, 0xD4, 0xF1, 0x2B, 0x07,
1961 0x3D, 0xFC, 0xD2, 0x01, 0x45, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0x00,
1962 0x00, 0x21, 0x00, 0x7A, 0xFF, 0x2B, 0x01, 0xFE, 0xFD, 0xF8, 0x02,
1963 0xFB, 0xFB, 0x8D, 0x05, 0xE5, 0x48, 0xE3, 0x01, 0x91, 0xFD, 0x25,
1964 0x02, 0x6B, 0xFE, 0xF7, 0x00, 0x8F, 0xFF, 0x1C, 0x00, 0xFD, 0xFF,
1965 0x2D, 0x00, 0x55, 0xFF, 0xB5, 0x01, 0x61, 0xFC, 0x16, 0x07, 0x85,
1966 0xF1, 0xE6, 0x2E, 0x9E, 0x31, 0x7D, 0xF1, 0xF3, 0x06, 0x84, 0xFC,
1967 0x9D, 0x01, 0x63, 0xFF, 0x28, 0x00, 0xFD, 0xFF, 0x18, 0x00, 0x9C,
1968 0xFF, 0xD6, 0x00, 0xB1, 0xFE, 0xA1, 0x01, 0x89, 0xFE, 0xC3, 0xFF,
1969 0x9C, 0x48, 0xFD, 0x07, 0xFA, 0xFA, 0x7A, 0x03, 0xBC, 0xFD, 0x49,
1970 0x01, 0x6E, 0xFF, 0x24, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x34, 0x00,
1971 0x3E, 0xFF, 0xDE, 0x01, 0x33, 0xFC, 0x22, 0x07, 0x2B, 0xF2, 0x80,
1972 0x27, 0x3B, 0x38, 0x0A, 0xF2, 0x44, 0x06, 0x0B, 0xFD, 0x45, 0x01,
1973 0x90, 0xFF, 0x18, 0x00, 0xFF, 0xFF, 0x10, 0x00, 0xBE, 0xFF, 0x7F,
1974 0x00, 0x65, 0xFF, 0x51, 0x00, 0xEB, 0x00, 0xE1, 0xFA, 0xE1, 0x46,
1975 0xCD, 0x0E, 0x6A, 0xF8, 0xB8, 0x04, 0x20, 0xFD, 0x90, 0x01, 0x53,
1976 0xFF, 0x2D, 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF,
1977 0xE5, 0x01, 0x42, 0xFC, 0xC3, 0x06, 0x87, 0xF3, 0xD7, 0x1F, 0xFE,
1978 0x3D, 0x91, 0xF3, 0x1D, 0x05, 0xD1, 0xFD, 0xCE, 0x00, 0xCC, 0xFF,
1979 0x02, 0x00, 0x02, 0x00, 0x09, 0x00, 0xDE, 0xFF, 0x2B, 0x00, 0x11,
1980 0x00, 0x1B, 0xFF, 0x02, 0x03, 0xFE, 0xF6, 0xC3, 0x43, 0x22, 0x16,
1981 0x07, 0xF6, 0xCA, 0x05, 0xA3, 0xFC, 0xC5, 0x01, 0x3F, 0xFF, 0x33,
1982 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x34, 0x00, 0x3C, 0xFF, 0xCF, 0x01,
1983 0x88, 0xFC, 0x09, 0x06, 0x71, 0xF5, 0x2B, 0x18, 0xB2, 0x42, 0x20,
1984 0xF6, 0x83, 0x03, 0xCF, 0xFE, 0x3C, 0x00, 0x15, 0x00, 0xE6, 0xFF,
1985 0x07, 0x00, 0x03, 0x00, 0xFB, 0xFF, 0xDF, 0xFF, 0xA9, 0x00, 0x10,
1986 0xFE, 0xB9, 0x04, 0x27, 0xF4, 0x5E, 0x3F, 0xC3, 0x1D, 0xFE, 0xF3,
1987 0x99, 0x06, 0x50, 0xFC, 0xE2, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE,
1988 0xFF, 0xFF, 0xFF, 0x2F, 0x00, 0x4D, 0xFF, 0xA0, 0x01, 0xFB, 0xFC,
1989 0x07, 0x05, 0xBF, 0xF7, 0xBB, 0x10, 0x2B, 0x46, 0xBB, 0xF9, 0x83,
1990 0x01, 0xFA, 0xFF, 0x95, 0xFF, 0x68, 0x00, 0xC7, 0xFF, 0x0E, 0x00,
1991 0x00, 0x00, 0x13, 0x00, 0x9F, 0xFF, 0x28, 0x01, 0x3A, 0xFD, 0x00,
1992 0x06, 0x5A, 0xF2, 0xDF, 0x39, 0x73, 0x25, 0x79, 0xF2, 0x12, 0x07,
1993 0x31, 0xFC, 0xE3, 0x01, 0x3B, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x00,
1994 0x00, 0x27, 0x00, 0x66, 0xFF, 0x5E, 0x01, 0x90, 0xFD, 0xD2, 0x03,
1995 0x47, 0xFA, 0xC3, 0x09, 0x48, 0x48, 0x5A, 0xFE, 0x33, 0xFF, 0x45,
1996 0x01, 0xE2, 0xFE, 0xBE, 0x00, 0xA5, 0xFF, 0x16, 0x00, 0xFD, 0xFF,
1997 0x24, 0x00, 0x6D, 0xFF, 0x88, 0x01, 0xA2, 0xFC, 0xD0, 0x06, 0x8C,
1998 0xF1, 0x78, 0x33, 0xF2, 0x2C, 0x9E, 0xF1, 0x24, 0x07, 0x4E, 0xFC,
1999 0xC3, 0x01, 0x4E, 0xFF, 0x2F, 0x00, 0xFD, 0xFF, 0x1E, 0x00, 0x86,
2000 0xFF, 0x0E, 0x01, 0x3B, 0xFE, 0x82, 0x02, 0xE0, 0xFC, 0x73, 0x03,
2001 0xF6, 0x48, 0xE9, 0x03, 0xAD, 0xFC, 0x9C, 0x02, 0x2D, 0xFE, 0x14,
2002 0x01, 0x83, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x30, 0x00,
2003 0x4C, 0xFF, 0xC7, 0x01, 0x4A, 0xFC, 0x27, 0x07, 0xA8, 0xF1, 0x62,
2004 0x2C, 0xFD, 0x33, 0x93, 0xF1, 0xC4, 0x06, 0xAB, 0xFC, 0x82, 0x01,
2005 0x71, 0xFF, 0x23, 0x00, 0xFE, 0xFF, 0x15, 0x00, 0xA8, 0xFF, 0xB8,
2006 0x00, 0xF0, 0xFE, 0x2B, 0x01, 0x63, 0xFF, 0xF6, 0xFD, 0x2C, 0x48,
2007 0x47, 0x0A, 0x14, 0xFA, 0xEB, 0x03, 0x84, 0xFD, 0x63, 0x01, 0x64,
2008 0xFF, 0x27, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x3A, 0xFF,
2009 0xE4, 0x01, 0x32, 0xFC, 0x0C, 0x07, 0x91, 0xF2, 0xDD, 0x24, 0x54,
2010 0x3A, 0x74, 0xF2, 0xEB, 0x05, 0x49, 0xFD, 0x20, 0x01, 0xA3, 0xFF,
2011 0x11, 0x00, 0x00, 0x00, 0x0D, 0x00, 0xC9, 0xFF, 0x61, 0x00, 0xA2,
2012 0xFF, 0xE2, 0xFF, 0xAE, 0x01, 0x6B, 0xF9, 0xF2, 0x45, 0x4A, 0x11,
2013 0x8F, 0xF7, 0x1D, 0x05, 0xF1, 0xFC, 0xA4, 0x01, 0x4B, 0xFF, 0x2F,
2014 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE1, 0x01,
2015 0x55, 0xFC, 0x8C, 0x06, 0x22, 0xF4, 0x2C, 0x1D, 0xC0, 0x3F, 0x55,
2016 0xF4, 0x9B, 0x04, 0x23, 0xFE, 0x9F, 0x00, 0xE4, 0xFF, 0xF9, 0xFF,
2017 0x04, 0x00, 0x07, 0x00, 0xE9, 0xFF, 0x0F, 0x00, 0x48, 0x00, 0xB9,
2018 0xFE, 0xA6, 0x03, 0xE4, 0xF5, 0x60, 0x42, 0xC1, 0x18, 0x47, 0xF5,
2019 0x1A, 0x06, 0x81, 0xFC, 0xD2, 0x01, 0x3B, 0xFF, 0x35, 0x00, 0xFE,
2020 0xFF, 0xFF, 0xFF, 0x33, 0x00, 0x40, 0xFF, 0xC1, 0x01, 0xAB, 0xFC,
2021 0xB7, 0x05, 0x34, 0xF6, 0x8E, 0x15, 0x0B, 0x44, 0x42, 0xF7, 0xDC,
2022 0x02, 0x32, 0xFF, 0x04, 0x00, 0x31, 0x00, 0xDC, 0xFF, 0x09, 0x00,
2023 0x02, 0x00, 0x04, 0x00, 0xC7, 0xFF, 0xD9, 0x00, 0xBF, 0xFD, 0x38,
2024 0x05, 0x69, 0xF3, 0x96, 0x3D, 0x6F, 0x20, 0x66, 0xF3, 0xCE, 0x06,
2025 0x3F, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFF,
2026 0xFF, 0x2C, 0x00, 0x55, 0xFF, 0x8B, 0x01, 0x2B, 0xFD, 0xA1, 0x04,
2027 0x9B, 0xF8, 0x42, 0x0E, 0x0F, 0x47, 0x38, 0xFB, 0xBE, 0x00, 0x6A,
2028 0x00, 0x58, 0xFF, 0x85, 0x00, 0xBB, 0xFF, 0x10, 0x00, 0xFF, 0xFF,
2029 0x19, 0x00, 0x8C, 0xFF, 0x4D, 0x01, 0xFE, 0xFC, 0x56, 0x06, 0xF7,
2030 0xF1, 0xBF, 0x37, 0x15, 0x28, 0x18, 0xF2, 0x25, 0x07, 0x34, 0xFC,
2031 0xDC, 0x01, 0x3F, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x24,
2032 0x00, 0x71, 0xFF, 0x43, 0x01, 0xC9, 0xFD, 0x60, 0x03, 0x2E, 0xFB,
2033 0x7E, 0x07, 0xAF, 0x48, 0x2D, 0x00, 0x58, 0xFE, 0xBB, 0x01, 0xA3,
2034 0xFE, 0xDD, 0x00, 0x99, 0xFF, 0x19, 0x00, 0xFD, 0xFF, 0x29, 0x00,
2035 0x60, 0xFF, 0xA2, 0x01, 0x7C, 0xFC, 0xFB, 0x06, 0x7C, 0xF1, 0x15,
2036 0x31, 0x73, 0x2F, 0x81, 0xF1, 0x10, 0x07, 0x67, 0xFC, 0xB1, 0x01,
2037 0x58, 0xFF, 0x2C, 0x00, 0xFD, 0xFF, 0x1B, 0x00, 0x91, 0xFF, 0xF1,
2038 0x00, 0x79, 0xFE, 0x0A, 0x02, 0xC3, 0xFD, 0x73, 0x01, 0xDB, 0x48,
2039 0x07, 0x06, 0xC7, 0xFB, 0x12, 0x03, 0xF1, 0xFD, 0x31, 0x01, 0x78,
2040 0xFF, 0x22, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x32, 0x00, 0x44, 0xFF,
2041 0xD5, 0x01, 0x3A, 0xFC, 0x2A, 0x07, 0xE3, 0xF1, 0xD1, 0x29, 0x46,
2042 0x36, 0xC5, 0xF1, 0x87, 0x06, 0xDA, 0xFC, 0x64, 0x01, 0x80, 0xFF,
2043 0x1E, 0x00, 0xFE, 0xFF, 0x12, 0x00, 0xB3, 0xFF, 0x99, 0x00, 0x2E,
2044 0xFF, 0xB6, 0x00, 0x36, 0x00, 0x47, 0xFC, 0x90, 0x47, 0xA4, 0x0C,
2045 0x31, 0xF9, 0x5A, 0x04, 0x4E, 0xFD, 0x7C, 0x01, 0x5B, 0xFF, 0x2A,
2046 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01,
2047 0x37, 0xFC, 0xEB, 0x06, 0x0B, 0xF3, 0x35, 0x22, 0x52, 0x3C, 0xFD,
2048 0xF2, 0x84, 0x05, 0x8D, 0xFD, 0xF6, 0x00, 0xB8, 0xFF, 0x09, 0x00,
2049 0x01, 0x00, 0x0B, 0x00, 0xD5, 0xFF, 0x44, 0x00, 0xDD, 0xFF, 0x77,
2050 0xFF, 0x67, 0x02, 0x14, 0xF8, 0xDC, 0x44, 0xD5, 0x13, 0xBC, 0xF6,
2051 0x7C, 0x05, 0xC5, 0xFC, 0xB7, 0x01, 0x44, 0xFF, 0x31, 0x00, 0xFF,
2052 0xFF, 0xFE, 0xFF, 0x35, 0x00, 0x39, 0xFF, 0xD9, 0x01, 0x6D, 0xFC,
2053 0x4B, 0x06, 0xCD, 0xF4, 0x83, 0x1A, 0x5F, 0x41, 0x3A, 0xF5, 0x0C,
2054 0x04, 0x7B, 0xFE, 0x6C, 0x00, 0xFE, 0xFF, 0xEF, 0xFF, 0x05, 0x00,
2055 0x05, 0x00, 0xF3, 0xFF, 0xF5, 0xFF, 0x7D, 0x00, 0x5D, 0xFE, 0x3E,
2056 0x04, 0xEA, 0xF4, 0xD9, 0x40, 0x66, 0x1B, 0x93, 0xF4, 0x62, 0x06,
2057 0x64, 0xFC, 0xDC, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0xFF,
2058 0xFF, 0x31, 0x00, 0x46, 0xFF, 0xB1, 0x01, 0xD3, 0xFC, 0x5D, 0x05,
2059 0x01, 0xF7, 0xFB, 0x12, 0x3F, 0x45, 0x83, 0xF8, 0x2A, 0x02, 0x9A,
2060 0xFF, 0xCA, 0xFF, 0x4E, 0x00, 0xD1, 0xFF, 0x0C, 0x00, 0x00, 0x00,
2061 0x0C, 0x00, 0xB1, 0xFF, 0x04, 0x01, 0x76, 0xFD, 0xA8, 0x05, 0xCC,
2062 0xF2, 0xAB, 0x3B, 0x18, 0x23, 0xE0, 0xF2, 0xF7, 0x06, 0x35, 0xFC,
2063 0xE6, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x29,
2064 0x00, 0x5E, 0xFF, 0x74, 0x01, 0x5F, 0xFD, 0x35, 0x04, 0x7C, 0xF9,
2065 0xD8, 0x0B, 0xC9, 0x47, 0xD4, 0xFC, 0xF0, 0xFF, 0xDD, 0x00, 0x19,
2066 0xFF, 0xA4, 0x00, 0xAF, 0xFF, 0x13, 0x00, 0xFE, 0xFF, 0x20, 0x00,
2067 0x7B, 0xFF, 0x6E, 0x01, 0xCA, 0xFC, 0x9D, 0x06, 0xB1, 0xF1, 0x86,
2068 0x35, 0xAE, 0x2A, 0xCD, 0xF1, 0x2B, 0x07, 0x3F, 0xFC, 0xD1, 0x01,
2069 0x46, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x21, 0x00, 0x7C,
2070 0xFF, 0x27, 0x01, 0x05, 0xFE, 0xEB, 0x02, 0x14, 0xFC, 0x50, 0x05,
2071 0xEA, 0x48, 0x1B, 0x02, 0x78, 0xFD, 0x32, 0x02, 0x64, 0xFE, 0xFA,
2072 0x00, 0x8D, 0xFF, 0x1C, 0x00, 0xFD, 0xFF, 0x2D, 0x00, 0x54, 0xFF,
2073 0xB7, 0x01, 0x5E, 0xFC, 0x19, 0x07, 0x88, 0xF1, 0x9F, 0x2E, 0xE3,
2074 0x31, 0x7E, 0xF1, 0xEE, 0x06, 0x88, 0xFC, 0x9A, 0x01, 0x64, 0xFF,
2075 0x28, 0x00, 0xFD, 0xFF, 0x18, 0x00, 0x9D, 0xFF, 0xD3, 0x00, 0xB8,
2076 0xFE, 0x93, 0x01, 0xA1, 0xFE, 0x8E, 0xFF, 0x92, 0x48, 0x3D, 0x08,
2077 0xE1, 0xFA, 0x86, 0x03, 0xB6, 0xFD, 0x4C, 0x01, 0x6D, 0xFF, 0x25,
2078 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x34, 0x00, 0x3E, 0xFF, 0xDF, 0x01,
2079 0x33, 0xFC, 0x20, 0x07, 0x35, 0xF2, 0x36, 0x27, 0x78, 0x38, 0x14,
2080 0xF2, 0x3B, 0x06, 0x11, 0xFD, 0x41, 0x01, 0x92, 0xFF, 0x17, 0x00,
2081 0xFF, 0xFF, 0x10, 0x00, 0xBF, 0xFF, 0x7B, 0x00, 0x6C, 0xFF, 0x44,
2082 0x00, 0x01, 0x01, 0xB6, 0xFA, 0xC8, 0x46, 0x13, 0x0F, 0x51, 0xF8,
2083 0xC4, 0x04, 0x1B, 0xFD, 0x92, 0x01, 0x52, 0xFF, 0x2D, 0x00, 0xFF,
2084 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE5, 0x01, 0x44, 0xFC,
2085 0xBD, 0x06, 0x97, 0xF3, 0x8A, 0x1F, 0x31, 0x3E, 0xA5, 0xF3, 0x0F,
2086 0x05, 0xDA, 0xFD, 0xC9, 0x00, 0xCF, 0xFF, 0x01, 0x00, 0x02, 0x00,
2087 0x09, 0x00, 0xDF, 0xFF, 0x28, 0x00, 0x17, 0x00, 0x10, 0xFF, 0x15,
2088 0x03, 0xDD, 0xF6, 0x9E, 0x43, 0x6C, 0x16, 0xF1, 0xF5, 0xD3, 0x05,
2089 0x9F, 0xFC, 0xC6, 0x01, 0x3F, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0xFE,
2090 0xFF, 0x34, 0x00, 0x3C, 0xFF, 0xCE, 0x01, 0x8C, 0xFC, 0x00, 0x06,
2091 0x86, 0xF5, 0xE0, 0x17, 0xDB, 0x42, 0x3F, 0xF6, 0x71, 0x03, 0xD9,
2092 0xFE, 0x36, 0x00, 0x18, 0x00, 0xE5, 0xFF, 0x07, 0x00, 0x03, 0x00,
2093 0xFC, 0xFF, 0xDC, 0xFF, 0xAF, 0x00, 0x07, 0xFE, 0xC8, 0x04, 0x10,
2094 0xF4, 0x2D, 0x3F, 0x0F, 0x1E, 0xED, 0xF3, 0xA0, 0x06, 0x4E, 0xFC,
2095 0xE3, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x2E,
2096 0x00, 0x4E, 0xFF, 0x9E, 0x01, 0x00, 0xFD, 0xFC, 0x04, 0xD7, 0xF7,
2097 0x75, 0x10, 0x48, 0x46, 0xE4, 0xF9, 0x6E, 0x01, 0x06, 0x00, 0x8E,
2098 0xFF, 0x6B, 0x00, 0xC6, 0xFF, 0x0E, 0x00, 0xFF, 0xFF, 0x13, 0x00,
2099 0x9D, 0xFF, 0x2D, 0x01, 0x33, 0xFD, 0x0B, 0x06, 0x4D, 0xF2, 0xA5,
2100 0x39, 0xBF, 0x25, 0x6D, 0xF2, 0x15, 0x07, 0x31, 0xFC, 0xE2, 0x01,
2101 0x3B, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x26, 0x00, 0x68,
2102 0xFF, 0x5B, 0x01, 0x96, 0xFD, 0xC6, 0x03, 0x61, 0xFA, 0x81, 0x09,
2103 0x57, 0x48, 0x8D, 0xFE, 0x1B, 0xFF, 0x52, 0x01, 0xDB, 0xFE, 0xC2,
2104 0x00, 0xA4, 0xFF, 0x16, 0x00, 0xFD, 0xFF, 0x25, 0x00, 0x6C, 0xFF,
2105 0x8B, 0x01, 0x9D, 0xFC, 0xD5, 0x06, 0x89, 0xF1, 0x35, 0x33, 0x3A,
2106 0x2D, 0x9A, 0xF1, 0x23, 0x07, 0x51, 0xFC, 0xC2, 0x01, 0x4F, 0xFF,
2107 0x2F, 0x00, 0xFD, 0xFF, 0x1E, 0x00, 0x87, 0xFF, 0x0B, 0x01, 0x42,
2108 0xFE, 0x74, 0x02, 0xF9, 0xFC, 0x39, 0x03, 0xF5, 0x48, 0x24, 0x04,
2109 0x94, 0xFC, 0xA9, 0x02, 0x27, 0xFE, 0x18, 0x01, 0x82, 0xFF, 0x1F,
2110 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x30, 0x00, 0x4B, 0xFF, 0xC9, 0x01,
2111 0x48, 0xFC, 0x28, 0x07, 0xAD, 0xF1, 0x19, 0x2C, 0x3F, 0x34, 0x97,
2112 0xF1, 0xBE, 0x06, 0xB0, 0xFC, 0x7F, 0x01, 0x72, 0xFF, 0x23, 0x00,
2113 0xFE, 0xFF, 0x15, 0x00, 0xA9, 0xFF, 0xB4, 0x00, 0xF7, 0xFE, 0x1D,
2114 0x01, 0x7A, 0xFF, 0xC5, 0xFD, 0x1D, 0x48, 0x89, 0x0A, 0xFB, 0xF9,
2115 0xF8, 0x03, 0x7D, 0xFD, 0x66, 0x01, 0x63, 0xFF, 0x28, 0x00, 0x00,
2116 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x39, 0xFF, 0xE4, 0x01, 0x32, 0xFC,
2117 0x09, 0x07, 0x9D, 0xF2, 0x92, 0x24, 0x8F, 0x3A, 0x82, 0xF2, 0xE1,
2118 0x05, 0x50, 0xFD, 0x1B, 0x01, 0xA6, 0xFF, 0x10, 0x00, 0x00, 0x00,
2119 0x0D, 0x00, 0xCB, 0xFF, 0x5E, 0x00, 0xA9, 0xFF, 0xD6, 0xFF, 0xC3,
2120 0x01, 0x43, 0xF9, 0xD7, 0x45, 0x92, 0x11, 0x77, 0xF7, 0x28, 0x05,
2121 0xEC, 0xFC, 0xA7, 0x01, 0x4A, 0xFF, 0x2F, 0x00, 0xFF, 0xFF, 0xFE,
2122 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE0, 0x01, 0x57, 0xFC, 0x85, 0x06,
2123 0x34, 0xF4, 0xE0, 0x1C, 0xF0, 0x3F, 0x6D, 0xF4, 0x8C, 0x04, 0x2C,
2124 0xFE, 0x99, 0x00, 0xE7, 0xFF, 0xF8, 0xFF, 0x04, 0x00, 0x06, 0x00,
2125 0xEA, 0xFF, 0x0C, 0x00, 0x4E, 0x00, 0xAF, 0xFE, 0xB8, 0x03, 0xC7,
2126 0xF5, 0x38, 0x42, 0x0C, 0x19, 0x32, 0xF5, 0x23, 0x06, 0x7D, 0xFC,
2127 0xD3, 0x01, 0x3A, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x32,
2128 0x00, 0x41, 0xFF, 0xC0, 0x01, 0xAF, 0xFC, 0xAD, 0x05, 0x4A, 0xF6,
2129 0x44, 0x15, 0x2F, 0x44, 0x64, 0xF7, 0xC9, 0x02, 0x3D, 0xFF, 0xFE,
2130 0xFF, 0x34, 0x00, 0xDB, 0xFF, 0x09, 0x00, 0x02, 0x00, 0x05, 0x00,
2131 0xC5, 0xFF, 0xDE, 0x00, 0xB7, 0xFD, 0x45, 0x05, 0x56, 0xF3, 0x61,
2132 0x3D, 0xBA, 0x20, 0x56, 0xF3, 0xD3, 0x06, 0x3E, 0xFC, 0xE6, 0x01,
2133 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFF, 0xFF, 0x2C, 0x00, 0x56,
2134 0xFF, 0x88, 0x01, 0x31, 0xFD, 0x95, 0x04, 0xB4, 0xF8, 0xFC, 0x0D,
2135 0x26, 0x47, 0x64, 0xFB, 0xA7, 0x00, 0x77, 0x00, 0x51, 0xFF, 0x89,
2136 0x00, 0xBA, 0xFF, 0x11, 0x00, 0xFF, 0xFF, 0x1A, 0x00, 0x8A, 0xFF,
2137 0x51, 0x01, 0xF8, 0xFC, 0x5E, 0x06, 0xED, 0xF1, 0x82, 0x37, 0x60,
2138 0x28, 0x0E, 0xF2, 0x26, 0x07, 0x35, 0xFC, 0xDB, 0x01, 0x40, 0xFF,
2139 0x34, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x23, 0x00, 0x72, 0xFF, 0x40,
2140 0x01, 0xD0, 0xFD, 0x53, 0x03, 0x47, 0xFB, 0x3F, 0x07, 0xB8, 0x48,
2141 0x62, 0x00, 0x3F, 0xFE, 0xC8, 0x01, 0x9C, 0xFE, 0xE0, 0x00, 0x98,
2142 0xFF, 0x19, 0x00, 0xFD, 0xFF, 0x29, 0x00, 0x5F, 0xFF, 0xA5, 0x01,
2143 0x78, 0xFC, 0xFF, 0x06, 0x7D, 0xF1, 0xCF, 0x30, 0xB8, 0x2F, 0x80,
2144 0xF1, 0x0D, 0x07, 0x6A, 0xFC, 0xAE, 0x01, 0x59, 0xFF, 0x2B, 0x00,
2145 0xFD, 0xFF, 0x1B, 0x00, 0x93, 0xFF, 0xED, 0x00, 0x80, 0xFE, 0xFD,
2146 0x01, 0xDC, 0xFD, 0x3C, 0x01, 0xD5, 0x48, 0x45, 0x06, 0xAE, 0xFB,
2147 0x1F, 0x03, 0xEA, 0xFD, 0x34, 0x01, 0x77, 0xFF, 0x22, 0x00, 0x00,
2148 0x00, 0xFD, 0xFF, 0x33, 0x00, 0x43, 0xFF, 0xD6, 0x01, 0x39, 0xFC,
2149 0x2A, 0x07, 0xEB, 0xF1, 0x87, 0x29, 0x85, 0x36, 0xCC, 0xF1, 0x7F,
2150 0x06, 0xE0, 0xFC, 0x60, 0x01, 0x82, 0xFF, 0x1D, 0x00, 0xFE, 0xFF,
2151 0x12, 0x00, 0xB5, 0xFF, 0x96, 0x00, 0x35, 0xFF, 0xA9, 0x00, 0x4D,
2152 0x00, 0x19, 0xFC, 0x7C, 0x47, 0xE8, 0x0C, 0x18, 0xF9, 0x66, 0x04,
2153 0x48, 0xFD, 0x7E, 0x01, 0x5A, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0xFD,
2154 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x38, 0xFC, 0xE6, 0x06,
2155 0x19, 0xF3, 0xEA, 0x21, 0x8A, 0x3C, 0x0E, 0xF3, 0x78, 0x05, 0x96,
2156 0xFD, 0xF1, 0x00, 0xBB, 0xFF, 0x08, 0x00, 0x01, 0x00, 0x0B, 0x00,
2157 0xD6, 0xFF, 0x41, 0x00, 0xE4, 0xFF, 0x6B, 0xFF, 0x7B, 0x02, 0xF0,
2158 0xF7, 0xBA, 0x44, 0x1E, 0x14, 0xA5, 0xF6, 0x86, 0x05, 0xC1, 0xFC,
2159 0xB9, 0x01, 0x44, 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x35,
2160 0x00, 0x39, 0xFF, 0xD8, 0x01, 0x70, 0xFC, 0x43, 0x06, 0xE1, 0xF4,
2161 0x38, 0x1A, 0x8C, 0x41, 0x55, 0xF5, 0xFC, 0x03, 0x85, 0xFE, 0x66,
2162 0x00, 0x01, 0x00, 0xEE, 0xFF, 0x06, 0x00, 0x05, 0x00, 0xF4, 0xFF,
2163 0xF2, 0xFF, 0x83, 0x00, 0x53, 0xFE, 0x4E, 0x04, 0xD0, 0xF4, 0xAB,
2164 0x40, 0xB2, 0x1B, 0x7F, 0xF4, 0x69, 0x06, 0x62, 0xFC, 0xDD, 0x01,
2165 0x38, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x30, 0x00, 0x47,
2166 0xFF, 0xAF, 0x01, 0xD8, 0xFC, 0x52, 0x05, 0x19, 0xF7, 0xB2, 0x12,
2167 0x5C, 0x45, 0xA9, 0xF8, 0x16, 0x02, 0xA6, 0xFF, 0xC3, 0xFF, 0x51,
2168 0x00, 0xD0, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x0D, 0x00, 0xAF, 0xFF,
2169 0x09, 0x01, 0x6E, 0xFD, 0xB4, 0x05, 0xBC, 0xF2, 0x73, 0x3B, 0x64,
2170 0x23, 0xD2, 0xF2, 0xFB, 0x06, 0x34, 0xFC, 0xE6, 0x01, 0x38, 0xFF,
2171 0x36, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x29, 0x00, 0x5F, 0xFF, 0x71,
2172 0x01, 0x65, 0xFD, 0x29, 0x04, 0x96, 0xF9, 0x95, 0x0B, 0xDC, 0x47,
2173 0x03, 0xFD, 0xD9, 0xFF, 0xEA, 0x00, 0x12, 0xFF, 0xA7, 0x00, 0xAE,
2174 0xFF, 0x14, 0x00, 0xFE, 0xFF, 0x20, 0x00, 0x79, 0xFF, 0x72, 0x01,
2175 0xC4, 0xFC, 0xA4, 0x06, 0xAB, 0xF1, 0x46, 0x35, 0xF7, 0x2A, 0xC6,
2176 0xF1, 0x2A, 0x07, 0x40, 0xFC, 0xCF, 0x01, 0x47, 0xFF, 0x31, 0x00,
2177 0xFD, 0xFF, 0x00, 0x00, 0x20, 0x00, 0x7D, 0xFF, 0x24, 0x01, 0x0C,
2178 0xFE, 0xDE, 0x02, 0x2E, 0xFC, 0x13, 0x05, 0xEC, 0x48, 0x54, 0x02,
2179 0x5E, 0xFD, 0x3F, 0x02, 0x5D, 0xFE, 0xFE, 0x00, 0x8C, 0xFF, 0x1C,
2180 0x00, 0xFD, 0xFF, 0x2D, 0x00, 0x53, 0xFF, 0xBA, 0x01, 0x5B, 0xFC,
2181 0x1B, 0x07, 0x8B, 0xF1, 0x58, 0x2E, 0x26, 0x32, 0x80, 0xF1, 0xEA,
2182 0x06, 0x8C, 0xFC, 0x97, 0x01, 0x66, 0xFF, 0x27, 0x00, 0xFD, 0xFF,
2183 0x17, 0x00, 0x9E, 0xFF, 0xCF, 0x00, 0xBF, 0xFE, 0x86, 0x01, 0xBA,
2184 0xFE, 0x5A, 0xFF, 0x86, 0x48, 0x7D, 0x08, 0xC7, 0xFA, 0x93, 0x03,
2185 0xB0, 0xFD, 0x4F, 0x01, 0x6C, 0xFF, 0x25, 0x00, 0x00, 0x00, 0xFD,
2186 0xFF, 0x35, 0x00, 0x3D, 0xFF, 0xDF, 0x01, 0x32, 0xFC, 0x1E, 0x07,
2187 0x40, 0xF2, 0xEB, 0x26, 0xB5, 0x38, 0x1F, 0xF2, 0x32, 0x06, 0x18,
2188 0xFD, 0x3D, 0x01, 0x94, 0xFF, 0x16, 0x00, 0xFF, 0xFF, 0x0F, 0x00,
2189 0xC0, 0xFF, 0x78, 0x00, 0x73, 0xFF, 0x38, 0x00, 0x17, 0x01, 0x8B,
2190 0xFA, 0xAF, 0x46, 0x59, 0x0F, 0x39, 0xF8, 0xCF, 0x04, 0x15, 0xFD,
2191 0x95, 0x01, 0x51, 0xFF, 0x2D, 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0x36,
2192 0x00, 0x36, 0xFF, 0xE5, 0x01, 0x46, 0xFC, 0xB8, 0x06, 0xA8, 0xF3,
2193 0x3F, 0x1F, 0x64, 0x3E, 0xBA, 0xF3, 0x01, 0x05, 0xE2, 0xFD, 0xC4,
2194 0x00, 0xD2, 0xFF, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, 0xE1, 0xFF,
2195 0x25, 0x00, 0x1D, 0x00, 0x05, 0xFF, 0x28, 0x03, 0xBD, 0xF6, 0x77,
2196 0x43, 0xB6, 0x16, 0xDC, 0xF5, 0xDD, 0x05, 0x9B, 0xFC, 0xC8, 0x01,
2197 0x3E, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x34, 0x00, 0x3D,
2198 0xFF, 0xCC, 0x01, 0x8F, 0xFC, 0xF8, 0x05, 0x9B, 0xF5, 0x96, 0x17,
2199 0x02, 0x43, 0x5E, 0xF6, 0x5F, 0x03, 0xE4, 0xFE, 0x30, 0x00, 0x1B,
2200 0x00, 0xE4, 0xFF, 0x08, 0x00, 0x03, 0x00, 0xFD, 0xFF, 0xD9, 0xFF,
2201 0xB4, 0x00, 0xFD, 0xFD, 0xD7, 0x04, 0xFA, 0xF3, 0xFC, 0x3E, 0x5B,
2202 0x1E, 0xDB, 0xF3, 0xA6, 0x06, 0x4C, 0xFC, 0xE3, 0x01, 0x36, 0xFF,
2203 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x2E, 0x00, 0x4E, 0xFF, 0x9C,
2204 0x01, 0x05, 0xFD, 0xF1, 0x04, 0xF0, 0xF7, 0x2D, 0x10, 0x61, 0x46,
2205 0x0D, 0xFA, 0x58, 0x01, 0x13, 0x00, 0x87, 0xFF, 0x6E, 0x00, 0xC4,
2206 0xFF, 0x0E, 0x00, 0xFF, 0xFF, 0x14, 0x00, 0x9B, 0xFF, 0x31, 0x01,
2207 0x2C, 0xFD, 0x15, 0x06, 0x41, 0xF2, 0x6A, 0x39, 0x0A, 0x26, 0x61,
2208 0xF2, 0x17, 0x07, 0x31, 0xFC, 0xE2, 0x01, 0x3B, 0xFF, 0x35, 0x00,
2209 0xFD, 0xFF, 0x00, 0x00, 0x26, 0x00, 0x69, 0xFF, 0x58, 0x01, 0x9D,
2210 0xFD, 0xB9, 0x03, 0x7B, 0xFA, 0x40, 0x09, 0x63, 0x48, 0xBF, 0xFE,
2211 0x03, 0xFF, 0x5F, 0x01, 0xD4, 0xFE, 0xC5, 0x00, 0xA2, 0xFF, 0x16,
2212 0x00, 0xFD, 0xFF, 0x25, 0x00, 0x6A, 0xFF, 0x8E, 0x01, 0x99, 0xFC,
2213 0xDB, 0x06, 0x86, 0xF1, 0xF2, 0x32, 0x82, 0x2D, 0x96, 0xF1, 0x21,
2214 0x07, 0x53, 0xFC, 0xC0, 0x01, 0x50, 0xFF, 0x2E, 0x00, 0xFD, 0xFF,
2215 0x1D, 0x00, 0x88, 0xFF, 0x07, 0x01, 0x49, 0xFE, 0x67, 0x02, 0x13,
2216 0xFD, 0xFF, 0x02, 0xF4, 0x48, 0x5F, 0x04, 0x7A, 0xFC, 0xB6, 0x02,
2217 0x20, 0xFE, 0x1B, 0x01, 0x81, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0xFD,
2218 0xFF, 0x30, 0x00, 0x4A, 0xFF, 0xCA, 0x01, 0x46, 0xFC, 0x29, 0x07,
2219 0xB3, 0xF1, 0xD1, 0x2B, 0x81, 0x34, 0x9C, 0xF1, 0xB8, 0x06, 0xB5,
2220 0xFC, 0x7C, 0x01, 0x74, 0xFF, 0x22, 0x00, 0xFE, 0xFF, 0x15, 0x00,
2221 0xAA, 0xFF, 0xB1, 0x00, 0xFE, 0xFE, 0x10, 0x01, 0x92, 0xFF, 0x94,
2222 0xFD, 0x0D, 0x48, 0xCB, 0x0A, 0xE2, 0xF9, 0x04, 0x04, 0x77, 0xFD,
2223 0x69, 0x01, 0x62, 0xFF, 0x28, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x36,
2224 0x00, 0x39, 0xFF, 0xE5, 0x01, 0x32, 0xFC, 0x06, 0x07, 0xAA, 0xF2,
2225 0x46, 0x24, 0xC8, 0x3A, 0x90, 0xF2, 0xD6, 0x05, 0x57, 0xFD, 0x17,
2226 0x01, 0xA8, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x0D, 0x00, 0xCC, 0xFF,
2227 0x5A, 0x00, 0xAF, 0xFF, 0xCA, 0xFF, 0xD8, 0x01, 0x1C, 0xF9, 0xB8,
2228 0x45, 0xDA, 0x11, 0x60, 0xF7, 0x33, 0x05, 0xE7, 0xFC, 0xA9, 0x01,
2229 0x4A, 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00, 0x37,
2230 0xFF, 0xDF, 0x01, 0x5A, 0xFC, 0x7E, 0x06, 0x47, 0xF4, 0x94, 0x1C,
2231 0x1F, 0x40, 0x85, 0xF4, 0x7D, 0x04, 0x36, 0xFE, 0x93, 0x00, 0xEA,
2232 0xFF, 0xF7, 0xFF, 0x04, 0x00, 0x06, 0x00, 0xEB, 0xFF, 0x09, 0x00,
2233 0x54, 0x00, 0xA4, 0xFE, 0xC9, 0x03, 0xAA, 0xF5, 0x0C, 0x42, 0x56,
2234 0x19, 0x1E, 0xF5, 0x2B, 0x06, 0x7A, 0xFC, 0xD4, 0x01, 0x3A, 0xFF,
2235 0x35, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x32, 0x00, 0x42, 0xFF, 0xBE,
2236 0x01, 0xB4, 0xFC, 0xA4, 0x05, 0x61, 0xF6, 0xFB, 0x14, 0x53, 0x44,
2237 0x86, 0xF7, 0xB6, 0x02, 0x49, 0xFF, 0xF7, 0xFF, 0x37, 0x00, 0xD9,
2238 0xFF, 0x0A, 0x00, 0x01, 0x00, 0x06, 0x00, 0xC2, 0xFF, 0xE3, 0x00,
2239 0xAE, 0xFD, 0x52, 0x05, 0x44, 0xF3, 0x2A, 0x3D, 0x06, 0x21, 0x47,
2240 0xF3, 0xD8, 0x06, 0x3C, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00,
2241 0xFD, 0xFF, 0x00, 0x00, 0x2B, 0x00, 0x57, 0xFF, 0x86, 0x01, 0x36,
2242 0xFD, 0x89, 0x04, 0xCD, 0xF8, 0xB7, 0x0D, 0x3D, 0x47, 0x91, 0xFB,
2243 0x91, 0x00, 0x83, 0x00, 0x4A, 0xFF, 0x8C, 0x00, 0xB9, 0xFF, 0x11,
2244 0x00, 0xFE, 0xFF, 0x1B, 0x00, 0x88, 0xFF, 0x55, 0x01, 0xF2, 0xFC,
2245 0x67, 0x06, 0xE4, 0xF1, 0x44, 0x37, 0xAA, 0x28, 0x05, 0xF2, 0x27,
2246 0x07, 0x36, 0xFC, 0xDA, 0x01, 0x41, 0xFF, 0x33, 0x00, 0xFD, 0xFF,
2247 0x00, 0x00, 0x23, 0x00, 0x73, 0xFF, 0x3D, 0x01, 0xD6, 0xFD, 0x46,
2248 0x03, 0x61, 0xFB, 0x00, 0x07, 0xBF, 0x48, 0x98, 0x00, 0x26, 0xFE,
2249 0xD5, 0x01, 0x95, 0xFE, 0xE3, 0x00, 0x96, 0xFF, 0x1A, 0x00, 0xFD,
2250 0xFF, 0x2A, 0x00, 0x5D, 0xFF, 0xA7, 0x01, 0x75, 0xFC, 0x03, 0x07,
2251 0x7D, 0xF1, 0x8A, 0x30, 0xFF, 0x2F, 0x7E, 0xF1, 0x0A, 0x07, 0x6E,
2252 0xFC, 0xAC, 0x01, 0x5A, 0xFF, 0x2B, 0x00, 0xFD, 0xFF, 0x1A, 0x00,
2253 0x94, 0xFF, 0xEA, 0x00, 0x87, 0xFE, 0xF0, 0x01, 0xF5, 0xFD, 0x05,
2254 0x01, 0xCE, 0x48, 0x83, 0x06, 0x94, 0xFB, 0x2C, 0x03, 0xE4, 0xFD,
2255 0x37, 0x01, 0x76, 0xFF, 0x22, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x33,
2256 0x00, 0x42, 0xFF, 0xD7, 0x01, 0x38, 0xFC, 0x29, 0x07, 0xF3, 0xF1,
2257 0x3E, 0x29, 0xC6, 0x36, 0xD4, 0xF1, 0x77, 0x06, 0xE6, 0xFC, 0x5C,
2258 0x01, 0x84, 0xFF, 0x1C, 0x00, 0xFE, 0xFF, 0x12, 0x00, 0xB6, 0xFF,
2259 0x93, 0x00, 0x3C, 0xFF, 0x9D, 0x00, 0x63, 0x00, 0xEB, 0xFB, 0x69,
2260 0x47, 0x2D, 0x0D, 0xFF, 0xF8, 0x72, 0x04, 0x42, 0xFD, 0x81, 0x01,
2261 0x59, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x37,
2262 0xFF, 0xE6, 0x01, 0x3A, 0xFC, 0xE2, 0x06, 0x28, 0xF3, 0x9E, 0x21,
2263 0xC0, 0x3C, 0x1F, 0xF3, 0x6C, 0x05, 0x9E, 0xFD, 0xED, 0x00, 0xBD,
2264 0xFF, 0x07, 0x00, 0x01, 0x00, 0x0A, 0x00, 0xD7, 0xFF, 0x3E, 0x00,
2265 0xEA, 0xFF, 0x60, 0xFF, 0x8F, 0x02, 0xCD, 0xF7, 0x99, 0x44, 0x68,
2266 0x14, 0x8E, 0xF6, 0x90, 0x05, 0xBC, 0xFC, 0xBA, 0x01, 0x43, 0xFF,
2267 0x32, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x35, 0x00, 0x39, 0xFF, 0xD7,
2268 0x01, 0x73, 0xFC, 0x3B, 0x06, 0xF5, 0xF4, 0xED, 0x19, 0xB7, 0x41,
2269 0x71, 0xF5, 0xEB, 0x03, 0x90, 0xFE, 0x60, 0x00, 0x04, 0x00, 0xED,
2270 0xFF, 0x06, 0x00, 0x04, 0x00, 0xF5, 0xFF, 0xEF, 0xFF, 0x88, 0x00,
2271 0x49, 0xFE, 0x5D, 0x04, 0xB7, 0xF4, 0x7D, 0x40, 0xFD, 0x1B, 0x6C,
2272 0xF4, 0x70, 0x06, 0x5F, 0xFC, 0xDE, 0x01, 0x37, 0xFF, 0x36, 0x00,
2273 0xFE, 0xFF, 0xFF, 0xFF, 0x30, 0x00, 0x48, 0xFF, 0xAD, 0x01, 0xDD,
2274 0xFC, 0x48, 0x05, 0x30, 0xF7, 0x6B, 0x12, 0x7D, 0x45, 0xCF, 0xF8,
2275 0x01, 0x02, 0xB2, 0xFF, 0xBD, 0xFF, 0x54, 0x00, 0xCE, 0xFF, 0x0C,
2276 0x00, 0x00, 0x00, 0x0E, 0x00, 0xAC, 0xFF, 0x0E, 0x01, 0x66, 0xFD,
2277 0xBF, 0x05, 0xAD, 0xF2, 0x3B, 0x3B, 0xB0, 0x23, 0xC4, 0xF2, 0xFF,
2278 0x06, 0x33, 0xFC, 0xE5, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFD, 0xFF,
2279 0x00, 0x00, 0x29, 0x00, 0x60, 0xFF, 0x6E, 0x01, 0x6B, 0xFD, 0x1D,
2280 0x04, 0xAF, 0xF9, 0x51, 0x0B, 0xEC, 0x47, 0x33, 0xFD, 0xC1, 0xFF,
2281 0xF7, 0x00, 0x0C, 0xFF, 0xAA, 0x00, 0xAD, 0xFF, 0x14, 0x00, 0xFE,
2282 0xFF, 0x21, 0x00, 0x77, 0xFF, 0x75, 0x01, 0xBF, 0xFC, 0xAB, 0x06,
2283 0xA6, 0xF1, 0x05, 0x35, 0x40, 0x2B, 0xBF, 0xF1, 0x2A, 0x07, 0x42,
2284 0xFC, 0xCE, 0x01, 0x48, 0xFF, 0x31, 0x00, 0xFD, 0xFF, 0x00, 0x00,
2285 0x20, 0x00, 0x7E, 0xFF, 0x21, 0x01, 0x12, 0xFE, 0xD1, 0x02, 0x47,
2286 0xFC, 0xD7, 0x04, 0xF0, 0x48, 0x8D, 0x02, 0x45, 0xFD, 0x4D, 0x02,
2287 0x56, 0xFE, 0x01, 0x01, 0x8B, 0xFF, 0x1D, 0x00, 0xFD, 0xFF, 0x2E,
2288 0x00, 0x52, 0xFF, 0xBC, 0x01, 0x58, 0xFC, 0x1D, 0x07, 0x8E, 0xF1,
2289 0x11, 0x2E, 0x6B, 0x32, 0x81, 0xF1, 0xE5, 0x06, 0x90, 0xFC, 0x94,
2290 0x01, 0x67, 0xFF, 0x26, 0x00, 0xFD, 0xFF, 0x17, 0x00, 0xA0, 0xFF,
2291 0xCC, 0x00, 0xC6, 0xFE, 0x79, 0x01, 0xD2, 0xFE, 0x26, 0xFF, 0x7C,
2292 0x48, 0xBE, 0x08, 0xAE, 0xFA, 0xA0, 0x03, 0xA9, 0xFD, 0x52, 0x01,
2293 0x6B, 0xFF, 0x25, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3C,
2294 0xFF, 0xE0, 0x01, 0x32, 0xFC, 0x1C, 0x07, 0x4B, 0xF2, 0xA0, 0x26,
2295 0xF2, 0x38, 0x2A, 0xF2, 0x28, 0x06, 0x1F, 0xFD, 0x39, 0x01, 0x96,
2296 0xFF, 0x16, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0xC2, 0xFF, 0x75, 0x00,
2297 0x7A, 0xFF, 0x2B, 0x00, 0x2D, 0x01, 0x61, 0xFA, 0x97, 0x46, 0xA0,
2298 0x0F, 0x20, 0xF8, 0xDA, 0x04, 0x10, 0xFD, 0x97, 0x01, 0x50, 0xFF,
2299 0x2E, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE4,
2300 0x01, 0x48, 0xFC, 0xB2, 0x06, 0xB9, 0xF3, 0xF3, 0x1E, 0x98, 0x3E,
2301 0xCF, 0xF3, 0xF3, 0x04, 0xEB, 0xFD, 0xBF, 0x00, 0xD4, 0xFF, 0xFF,
2302 0xFF, 0x03, 0x00, 0x08, 0x00, 0xE2, 0xFF, 0x21, 0x00, 0x23, 0x00,
2303 0xFA, 0xFE, 0x3A, 0x03, 0x9D, 0xF6, 0x50, 0x43, 0x00, 0x17, 0xC6,
2304 0xF5, 0xE6, 0x05, 0x97, 0xFC, 0xC9, 0x01, 0x3E, 0xFF, 0x34, 0x00,
2305 0xFE, 0xFF, 0xFE, 0xFF, 0x34, 0x00, 0x3D, 0xFF, 0xCB, 0x01, 0x93,
2306 0xFC, 0xEF, 0x05, 0xB0, 0xF5, 0x4B, 0x17, 0x2A, 0x43, 0x7D, 0xF6,
2307 0x4D, 0x03, 0xEF, 0xFE, 0x2A, 0x00, 0x1E, 0x00, 0xE3, 0xFF, 0x08,
2308 0x00, 0x03, 0x00, 0xFE, 0xFF, 0xD7, 0xFF, 0xBA, 0x00, 0xF4, 0xFD,
2309 0xE5, 0x04, 0xE4, 0xF3, 0xCA, 0x3E, 0xA7, 0x1E, 0xCA, 0xF3, 0xAC,
2310 0x06, 0x4A, 0xFC, 0xE4, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF,
2311 0xFF, 0xFF, 0x2E, 0x00, 0x4F, 0xFF, 0x99, 0x01, 0x0B, 0xFD, 0xE6,
2312 0x04, 0x08, 0xF8, 0xE7, 0x0F, 0x7C, 0x46, 0x37, 0xFA, 0x42, 0x01,
2313 0x1F, 0x00, 0x81, 0xFF, 0x71, 0x00, 0xC3, 0xFF, 0x0F, 0x00, 0xFF,
2314 0xFF, 0x15, 0x00, 0x98, 0xFF, 0x35, 0x01, 0x25, 0xFD, 0x1E, 0x06,
2315 0x35, 0xF2, 0x2E, 0x39, 0x55, 0x26, 0x56, 0xF2, 0x1A, 0x07, 0x31,
2316 0xFC, 0xE1, 0x01, 0x3C, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x00, 0x00,
2317 0x26, 0x00, 0x6A, 0xFF, 0x55, 0x01, 0xA3, 0xFD, 0xAD, 0x03, 0x94,
2318 0xFA, 0xFF, 0x08, 0x70, 0x48, 0xF3, 0xFE, 0xEA, 0xFE, 0x6C, 0x01,
2319 0xCD, 0xFE, 0xC9, 0x00, 0xA1, 0xFF, 0x17, 0x00, 0xFD, 0xFF, 0x26,
2320 0x00, 0x69, 0xFF, 0x91, 0x01, 0x94, 0xFC, 0xE0, 0x06, 0x84, 0xF1,
2321 0xAF, 0x32, 0xCA, 0x2D, 0x92, 0xF1, 0x1F, 0x07, 0x56, 0xFC, 0xBE,
2322 0x01, 0x51, 0xFF, 0x2E, 0x00, 0xFD, 0xFF, 0x1D, 0x00, 0x8A, 0xFF,
2323 0x04, 0x01, 0x50, 0xFE, 0x5A, 0x02, 0x2C, 0xFD, 0xC6, 0x02, 0xF2,
2324 0x48, 0x9B, 0x04, 0x61, 0xFC, 0xC3, 0x02, 0x19, 0xFE, 0x1E, 0x01,
2325 0x7F, 0xFF, 0x20, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x31, 0x00, 0x49,
2326 0xFF, 0xCC, 0x01, 0x44, 0xFC, 0x29, 0x07, 0xB9, 0xF1, 0x89, 0x2B,
2327 0xC3, 0x34, 0xA0, 0xF1, 0xB1, 0x06, 0xBA, 0xFC, 0x79, 0x01, 0x76,
2328 0xFF, 0x21, 0x00, 0xFE, 0xFF, 0x14, 0x00, 0xAC, 0xFF, 0xAE, 0x00,
2329 0x05, 0xFF, 0x03, 0x01, 0xAA, 0xFF, 0x63, 0xFD, 0xFD, 0x47, 0x0E,
2330 0x0B, 0xC8, 0xF9, 0x11, 0x04, 0x71, 0xFD, 0x6C, 0x01, 0x61, 0xFF,
2331 0x28, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x39, 0xFF, 0xE5,
2332 0x01, 0x33, 0xFC, 0x03, 0x07, 0xB7, 0xF2, 0xFC, 0x23, 0x03, 0x3B,
2333 0x9E, 0xF2, 0xCB, 0x05, 0x5F, 0xFD, 0x12, 0x01, 0xAA, 0xFF, 0x0E,
2334 0x00, 0x00, 0x00, 0x0C, 0x00, 0xCD, 0xFF, 0x57, 0x00, 0xB6, 0xFF,
2335 0xBE, 0xFF, 0xED, 0x01, 0xF5, 0xF8, 0x9B, 0x45, 0x22, 0x12, 0x48,
2336 0xF7, 0x3D, 0x05, 0xE2, 0xFC, 0xAB, 0x01, 0x49, 0xFF, 0x30, 0x00,
2337 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xDF, 0x01, 0x5C,
2338 0xFC, 0x78, 0x06, 0x5A, 0xF4, 0x49, 0x1C, 0x4E, 0x40, 0x9E, 0xF4,
2339 0x6D, 0x04, 0x3F, 0xFE, 0x8E, 0x00, 0xED, 0xFF, 0xF6, 0xFF, 0x04,
2340 0x00, 0x06, 0x00, 0xEC, 0xFF, 0x06, 0x00, 0x5A, 0x00, 0x9A, 0xFE,
2341 0xDA, 0x03, 0x8D, 0xF5, 0xE1, 0x41, 0xA1, 0x19, 0x09, 0xF5, 0x33,
2342 0x06, 0x77, 0xFC, 0xD6, 0x01, 0x3A, 0xFF, 0x35, 0x00, 0xFE, 0xFF,
2343 0xFF, 0xFF, 0x32, 0x00, 0x42, 0xFF, 0xBC, 0x01, 0xB8, 0xFC, 0x9A,
2344 0x05, 0x77, 0xF6, 0xB1, 0x14, 0x77, 0x44, 0xA9, 0xF7, 0xA2, 0x02,
2345 0x54, 0xFF, 0xF1, 0xFF, 0x3A, 0x00, 0xD8, 0xFF, 0x0A, 0x00, 0x01,
2346 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xE8, 0x00, 0xA6, 0xFD, 0x5F, 0x05,
2347 0x31, 0xF3, 0xF6, 0x3C, 0x52, 0x21, 0x37, 0xF3, 0xDD, 0x06, 0x3B,
2348 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x00, 0x00,
2349 0x2B, 0x00, 0x58, 0xFF, 0x83, 0x01, 0x3C, 0xFD, 0x7E, 0x04, 0xE6,
2350 0xF8, 0x72, 0x0D, 0x52, 0x47, 0xBE, 0xFB, 0x7A, 0x00, 0x90, 0x00,
2351 0x43, 0xFF, 0x8F, 0x00, 0xB7, 0xFF, 0x11, 0x00, 0xFE, 0xFF, 0x1C,
2352 0x00, 0x86, 0xFF, 0x59, 0x01, 0xEC, 0xFC, 0x6F, 0x06, 0xDC, 0xF1,
2353 0x04, 0x37, 0xF3, 0x28, 0xFC, 0xF1, 0x28, 0x07, 0x37, 0xFC, 0xD8,
2354 0x01, 0x41, 0xFF, 0x33, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x23, 0x00,
2355 0x74, 0xFF, 0x3A, 0x01, 0xDD, 0xFD, 0x39, 0x03, 0x7B, 0xFB, 0xC1,
2356 0x06, 0xC7, 0x48, 0xCF, 0x00, 0x0D, 0xFE, 0xE3, 0x01, 0x8E, 0xFE,
2357 0xE7, 0x00, 0x95, 0xFF, 0x1A, 0x00, 0xFD, 0xFF, 0x2A, 0x00, 0x5C,
2358 0xFF, 0xAA, 0x01, 0x71, 0xFC, 0x07, 0x07, 0x7E, 0xF1, 0x44, 0x30,
2359 0x44, 0x30, 0x7E, 0xF1, 0x07, 0x07, 0x71, 0xFC, 0xAA, 0x01, 0x5C,
2360 0xFF, 0x2A, 0x00, 0xFD, 0xFF, 0x1A, 0x00, 0x95, 0xFF, 0xE7, 0x00,
2361 0x8E, 0xFE, 0xE3, 0x01, 0x0D, 0xFE, 0xCF, 0x00, 0xC7, 0x48, 0xC1,
2362 0x06, 0x7B, 0xFB, 0x39, 0x03, 0xDD, 0xFD, 0x3A, 0x01, 0x74, 0xFF,
2363 0x23, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x33, 0x00, 0x41, 0xFF, 0xD8,
2364 0x01, 0x37, 0xFC, 0x28, 0x07, 0xFC, 0xF1, 0xF3, 0x28, 0x04, 0x37,
2365 0xDC, 0xF1, 0x6F, 0x06, 0xEC, 0xFC, 0x59, 0x01, 0x86, 0xFF, 0x1C,
2366 0x00, 0xFE, 0xFF, 0x11, 0x00, 0xB7, 0xFF, 0x8F, 0x00, 0x43, 0xFF,
2367 0x90, 0x00, 0x7A, 0x00, 0xBE, 0xFB, 0x52, 0x47, 0x72, 0x0D, 0xE6,
2368 0xF8, 0x7E, 0x04, 0x3C, 0xFD, 0x83, 0x01, 0x58, 0xFF, 0x2B, 0x00,
2369 0x00, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3B,
2370 0xFC, 0xDD, 0x06, 0x37, 0xF3, 0x52, 0x21, 0xF6, 0x3C, 0x31, 0xF3,
2371 0x5F, 0x05, 0xA6, 0xFD, 0xE8, 0x00, 0xC0, 0xFF, 0x07, 0x00, 0x01,
2372 0x00, 0x0A, 0x00, 0xD8, 0xFF, 0x3A, 0x00, 0xF1, 0xFF, 0x54, 0xFF,
2373 0xA2, 0x02, 0xA9, 0xF7, 0x77, 0x44, 0xB1, 0x14, 0x77, 0xF6, 0x9A,
2374 0x05, 0xB8, 0xFC, 0xBC, 0x01, 0x42, 0xFF, 0x32, 0x00, 0xFF, 0xFF,
2375 0xFE, 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xD6, 0x01, 0x77, 0xFC, 0x33,
2376 0x06, 0x09, 0xF5, 0xA1, 0x19, 0xE1, 0x41, 0x8D, 0xF5, 0xDA, 0x03,
2377 0x9A, 0xFE, 0x5A, 0x00, 0x06, 0x00, 0xEC, 0xFF, 0x06, 0x00, 0x04,
2378 0x00, 0xF6, 0xFF, 0xED, 0xFF, 0x8E, 0x00, 0x3F, 0xFE, 0x6D, 0x04,
2379 0x9E, 0xF4, 0x4E, 0x40, 0x49, 0x1C, 0x5A, 0xF4, 0x78, 0x06, 0x5C,
2380 0xFC, 0xDF, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF,
2381 0x30, 0x00, 0x49, 0xFF, 0xAB, 0x01, 0xE2, 0xFC, 0x3D, 0x05, 0x48,
2382 0xF7, 0x22, 0x12, 0x9B, 0x45, 0xF5, 0xF8, 0xED, 0x01, 0xBE, 0xFF,
2383 0xB6, 0xFF, 0x57, 0x00, 0xCD, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x0E,
2384 0x00, 0xAA, 0xFF, 0x12, 0x01, 0x5F, 0xFD, 0xCB, 0x05, 0x9E, 0xF2,
2385 0x03, 0x3B, 0xFC, 0x23, 0xB7, 0xF2, 0x03, 0x07, 0x33, 0xFC, 0xE5,
2386 0x01, 0x39, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x28, 0x00,
2387 0x61, 0xFF, 0x6C, 0x01, 0x71, 0xFD, 0x11, 0x04, 0xC8, 0xF9, 0x0E,
2388 0x0B, 0xFD, 0x47, 0x63, 0xFD, 0xAA, 0xFF, 0x03, 0x01, 0x05, 0xFF,
2389 0xAE, 0x00, 0xAC, 0xFF, 0x14, 0x00, 0xFE, 0xFF, 0x21, 0x00, 0x76,
2390 0xFF, 0x79, 0x01, 0xBA, 0xFC, 0xB1, 0x06, 0xA0, 0xF1, 0xC3, 0x34,
2391 0x89, 0x2B, 0xB9, 0xF1, 0x29, 0x07, 0x44, 0xFC, 0xCC, 0x01, 0x49,
2392 0xFF, 0x31, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x20, 0x00, 0x7F, 0xFF,
2393 0x1E, 0x01, 0x19, 0xFE, 0xC3, 0x02, 0x61, 0xFC, 0x9B, 0x04, 0xF2,
2394 0x48, 0xC6, 0x02, 0x2C, 0xFD, 0x5A, 0x02, 0x50, 0xFE, 0x04, 0x01,
2395 0x8A, 0xFF, 0x1D, 0x00, 0xFD, 0xFF, 0x2E, 0x00, 0x51, 0xFF, 0xBE,
2396 0x01, 0x56, 0xFC, 0x1F, 0x07, 0x92, 0xF1, 0xCA, 0x2D, 0xAF, 0x32,
2397 0x84, 0xF1, 0xE0, 0x06, 0x94, 0xFC, 0x91, 0x01, 0x69, 0xFF, 0x26,
2398 0x00, 0xFD, 0xFF, 0x17, 0x00, 0xA1, 0xFF, 0xC9, 0x00, 0xCD, 0xFE,
2399 0x6C, 0x01, 0xEA, 0xFE, 0xF3, 0xFE, 0x70, 0x48, 0xFF, 0x08, 0x94,
2400 0xFA, 0xAD, 0x03, 0xA3, 0xFD, 0x55, 0x01, 0x6A, 0xFF, 0x26, 0x00,
2401 0x00, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3C, 0xFF, 0xE1, 0x01, 0x31,
2402 0xFC, 0x1A, 0x07, 0x56, 0xF2, 0x55, 0x26, 0x2E, 0x39, 0x35, 0xF2,
2403 0x1E, 0x06, 0x25, 0xFD, 0x35, 0x01, 0x98, 0xFF, 0x15, 0x00, 0xFF,
2404 0xFF, 0x0F, 0x00, 0xC3, 0xFF, 0x71, 0x00, 0x81, 0xFF, 0x1F, 0x00,
2405 0x42, 0x01, 0x37, 0xFA, 0x7C, 0x46, 0xE7, 0x0F, 0x08, 0xF8, 0xE6,
2406 0x04, 0x0B, 0xFD, 0x99, 0x01, 0x4F, 0xFF, 0x2E, 0x00, 0xFF, 0xFF,
2407 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE4, 0x01, 0x4A, 0xFC, 0xAC,
2408 0x06, 0xCA, 0xF3, 0xA7, 0x1E, 0xCA, 0x3E, 0xE4, 0xF3, 0xE5, 0x04,
2409 0xF4, 0xFD, 0xBA, 0x00, 0xD7, 0xFF, 0xFE, 0xFF, 0x03, 0x00, 0x08,
2410 0x00, 0xE3, 0xFF, 0x1E, 0x00, 0x2A, 0x00, 0xEF, 0xFE, 0x4D, 0x03,
2411 0x7D, 0xF6, 0x2A, 0x43, 0x4B, 0x17, 0xB0, 0xF5, 0xEF, 0x05, 0x93,
2412 0xFC, 0xCB, 0x01, 0x3D, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0xFE, 0xFF,
2413 0x34, 0x00, 0x3E, 0xFF, 0xC9, 0x01, 0x97, 0xFC, 0xE6, 0x05, 0xC6,
2414 0xF5, 0x00, 0x17, 0x50, 0x43, 0x9D, 0xF6, 0x3A, 0x03, 0xFA, 0xFE,
2415 0x23, 0x00, 0x21, 0x00, 0xE2, 0xFF, 0x08, 0x00, 0x03, 0x00, 0xFF,
2416 0xFF, 0xD4, 0xFF, 0xBF, 0x00, 0xEB, 0xFD, 0xF3, 0x04, 0xCF, 0xF3,
2417 0x98, 0x3E, 0xF3, 0x1E, 0xB9, 0xF3, 0xB2, 0x06, 0x48, 0xFC, 0xE4,
2418 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x2E, 0x00,
2419 0x50, 0xFF, 0x97, 0x01, 0x10, 0xFD, 0xDA, 0x04, 0x20, 0xF8, 0xA0,
2420 0x0F, 0x97, 0x46, 0x61, 0xFA, 0x2D, 0x01, 0x2B, 0x00, 0x7A, 0xFF,
2421 0x75, 0x00, 0xC2, 0xFF, 0x0F, 0x00, 0xFF, 0xFF, 0x16, 0x00, 0x96,
2422 0xFF, 0x39, 0x01, 0x1F, 0xFD, 0x28, 0x06, 0x2A, 0xF2, 0xF2, 0x38,
2423 0xA0, 0x26, 0x4B, 0xF2, 0x1C, 0x07, 0x32, 0xFC, 0xE0, 0x01, 0x3C,
2424 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x25, 0x00, 0x6B, 0xFF,
2425 0x52, 0x01, 0xA9, 0xFD, 0xA0, 0x03, 0xAE, 0xFA, 0xBE, 0x08, 0x7C,
2426 0x48, 0x26, 0xFF, 0xD2, 0xFE, 0x79, 0x01, 0xC6, 0xFE, 0xCC, 0x00,
2427 0xA0, 0xFF, 0x17, 0x00, 0xFD, 0xFF, 0x26, 0x00, 0x67, 0xFF, 0x94,
2428 0x01, 0x90, 0xFC, 0xE5, 0x06, 0x81, 0xF1, 0x6B, 0x32, 0x11, 0x2E,
2429 0x8E, 0xF1, 0x1D, 0x07, 0x58, 0xFC, 0xBC, 0x01, 0x52, 0xFF, 0x2E,
2430 0x00, 0xFD, 0xFF, 0x1D, 0x00, 0x8B, 0xFF, 0x01, 0x01, 0x56, 0xFE,
2431 0x4D, 0x02, 0x45, 0xFD, 0x8D, 0x02, 0xF0, 0x48, 0xD7, 0x04, 0x47,
2432 0xFC, 0xD1, 0x02, 0x12, 0xFE, 0x21, 0x01, 0x7E, 0xFF, 0x20, 0x00,
2433 0x00, 0x00, 0xFD, 0xFF, 0x31, 0x00, 0x48, 0xFF, 0xCE, 0x01, 0x42,
2434 0xFC, 0x2A, 0x07, 0xBF, 0xF1, 0x40, 0x2B, 0x05, 0x35, 0xA6, 0xF1,
2435 0xAB, 0x06, 0xBF, 0xFC, 0x75, 0x01, 0x77, 0xFF, 0x21, 0x00, 0xFE,
2436 0xFF, 0x14, 0x00, 0xAD, 0xFF, 0xAA, 0x00, 0x0C, 0xFF, 0xF7, 0x00,
2437 0xC1, 0xFF, 0x33, 0xFD, 0xEC, 0x47, 0x51, 0x0B, 0xAF, 0xF9, 0x1D,
2438 0x04, 0x6B, 0xFD, 0x6E, 0x01, 0x60, 0xFF, 0x29, 0x00, 0x00, 0x00,
2439 0xFD, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xE5, 0x01, 0x33, 0xFC, 0xFF,
2440 0x06, 0xC4, 0xF2, 0xB0, 0x23, 0x3B, 0x3B, 0xAD, 0xF2, 0xBF, 0x05,
2441 0x66, 0xFD, 0x0E, 0x01, 0xAC, 0xFF, 0x0E, 0x00, 0x00, 0x00, 0x0C,
2442 0x00, 0xCE, 0xFF, 0x54, 0x00, 0xBD, 0xFF, 0xB2, 0xFF, 0x01, 0x02,
2443 0xCF, 0xF8, 0x7D, 0x45, 0x6B, 0x12, 0x30, 0xF7, 0x48, 0x05, 0xDD,
2444 0xFC, 0xAD, 0x01, 0x48, 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0xFE, 0xFF,
2445 0x36, 0x00, 0x37, 0xFF, 0xDE, 0x01, 0x5F, 0xFC, 0x70, 0x06, 0x6C,
2446 0xF4, 0xFD, 0x1B, 0x7D, 0x40, 0xB7, 0xF4, 0x5D, 0x04, 0x49, 0xFE,
2447 0x88, 0x00, 0xEF, 0xFF, 0xF5, 0xFF, 0x04, 0x00, 0x06, 0x00, 0xED,
2448 0xFF, 0x04, 0x00, 0x60, 0x00, 0x90, 0xFE, 0xEB, 0x03, 0x71, 0xF5,
2449 0xB7, 0x41, 0xED, 0x19, 0xF5, 0xF4, 0x3B, 0x06, 0x73, 0xFC, 0xD7,
2450 0x01, 0x39, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x32, 0x00,
2451 0x43, 0xFF, 0xBA, 0x01, 0xBC, 0xFC, 0x90, 0x05, 0x8E, 0xF6, 0x68,
2452 0x14, 0x99, 0x44, 0xCD, 0xF7, 0x8F, 0x02, 0x60, 0xFF, 0xEA, 0xFF,
2453 0x3E, 0x00, 0xD7, 0xFF, 0x0A, 0x00, 0x01, 0x00, 0x07, 0x00, 0xBD,
2454 0xFF, 0xED, 0x00, 0x9E, 0xFD, 0x6C, 0x05, 0x1F, 0xF3, 0xC0, 0x3C,
2455 0x9E, 0x21, 0x28, 0xF3, 0xE2, 0x06, 0x3A, 0xFC, 0xE6, 0x01, 0x37,
2456 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x2B, 0x00, 0x59, 0xFF,
2457 0x81, 0x01, 0x42, 0xFD, 0x72, 0x04, 0xFF, 0xF8, 0x2D, 0x0D, 0x69,
2458 0x47, 0xEB, 0xFB, 0x63, 0x00, 0x9D, 0x00, 0x3C, 0xFF, 0x93, 0x00,
2459 0xB6, 0xFF, 0x12, 0x00, 0xFE, 0xFF, 0x1C, 0x00, 0x84, 0xFF, 0x5C,
2460 0x01, 0xE6, 0xFC, 0x77, 0x06, 0xD4, 0xF1, 0xC6, 0x36, 0x3E, 0x29,
2461 0xF3, 0xF1, 0x29, 0x07, 0x38, 0xFC, 0xD7, 0x01, 0x42, 0xFF, 0x33,
2462 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x22, 0x00, 0x76, 0xFF, 0x37, 0x01,
2463 0xE4, 0xFD, 0x2C, 0x03, 0x94, 0xFB, 0x83, 0x06, 0xCE, 0x48, 0x05,
2464 0x01, 0xF5, 0xFD, 0xF0, 0x01, 0x87, 0xFE, 0xEA, 0x00, 0x94, 0xFF,
2465 0x1A, 0x00, 0xFD, 0xFF, 0x2B, 0x00, 0x5A, 0xFF, 0xAC, 0x01, 0x6E,
2466 0xFC, 0x0A, 0x07, 0x7E, 0xF1, 0xFF, 0x2F, 0x8A, 0x30, 0x7D, 0xF1,
2467 0x03, 0x07, 0x75, 0xFC, 0xA7, 0x01, 0x5D, 0xFF, 0x2A, 0x00, 0xFD,
2468 0xFF, 0x1A, 0x00, 0x96, 0xFF, 0xE3, 0x00, 0x95, 0xFE, 0xD5, 0x01,
2469 0x26, 0xFE, 0x98, 0x00, 0xBF, 0x48, 0x00, 0x07, 0x61, 0xFB, 0x46,
2470 0x03, 0xD6, 0xFD, 0x3D, 0x01, 0x73, 0xFF, 0x23, 0x00, 0x00, 0x00,
2471 0xFD, 0xFF, 0x33, 0x00, 0x41, 0xFF, 0xDA, 0x01, 0x36, 0xFC, 0x27,
2472 0x07, 0x05, 0xF2, 0xAA, 0x28, 0x44, 0x37, 0xE4, 0xF1, 0x67, 0x06,
2473 0xF2, 0xFC, 0x55, 0x01, 0x88, 0xFF, 0x1B, 0x00, 0xFE, 0xFF, 0x11,
2474 0x00, 0xB9, 0xFF, 0x8C, 0x00, 0x4A, 0xFF, 0x83, 0x00, 0x91, 0x00,
2475 0x91, 0xFB, 0x3D, 0x47, 0xB7, 0x0D, 0xCD, 0xF8, 0x89, 0x04, 0x36,
2476 0xFD, 0x86, 0x01, 0x57, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0xFD, 0xFF,
2477 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3C, 0xFC, 0xD8, 0x06, 0x47,
2478 0xF3, 0x06, 0x21, 0x2A, 0x3D, 0x44, 0xF3, 0x52, 0x05, 0xAE, 0xFD,
2479 0xE3, 0x00, 0xC2, 0xFF, 0x06, 0x00, 0x01, 0x00, 0x0A, 0x00, 0xD9,
2480 0xFF, 0x37, 0x00, 0xF7, 0xFF, 0x49, 0xFF, 0xB6, 0x02, 0x86, 0xF7,
2481 0x53, 0x44, 0xFB, 0x14, 0x61, 0xF6, 0xA4, 0x05, 0xB4, 0xFC, 0xBE,
2482 0x01, 0x42, 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x35, 0x00,
2483 0x3A, 0xFF, 0xD4, 0x01, 0x7A, 0xFC, 0x2B, 0x06, 0x1E, 0xF5, 0x56,
2484 0x19, 0x0C, 0x42, 0xAA, 0xF5, 0xC9, 0x03, 0xA4, 0xFE, 0x54, 0x00,
2485 0x09, 0x00, 0xEB, 0xFF, 0x06, 0x00, 0x04, 0x00, 0xF7, 0xFF, 0xEA,
2486 0xFF, 0x93, 0x00, 0x36, 0xFE, 0x7D, 0x04, 0x85, 0xF4, 0x1F, 0x40,
2487 0x94, 0x1C, 0x47, 0xF4, 0x7E, 0x06, 0x5A, 0xFC, 0xDF, 0x01, 0x37,
2488 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x30, 0x00, 0x4A, 0xFF,
2489 0xA9, 0x01, 0xE7, 0xFC, 0x33, 0x05, 0x60, 0xF7, 0xDA, 0x11, 0xB8,
2490 0x45, 0x1C, 0xF9, 0xD8, 0x01, 0xCA, 0xFF, 0xAF, 0xFF, 0x5A, 0x00,
2491 0xCC, 0xFF, 0x0D, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xA8, 0xFF, 0x17,
2492 0x01, 0x57, 0xFD, 0xD6, 0x05, 0x90, 0xF2, 0xC8, 0x3A, 0x46, 0x24,
2493 0xAA, 0xF2, 0x06, 0x07, 0x32, 0xFC, 0xE5, 0x01, 0x39, 0xFF, 0x36,
2494 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x28, 0x00, 0x62, 0xFF, 0x69, 0x01,
2495 0x77, 0xFD, 0x04, 0x04, 0xE2, 0xF9, 0xCB, 0x0A, 0x0D, 0x48, 0x94,
2496 0xFD, 0x92, 0xFF, 0x10, 0x01, 0xFE, 0xFE, 0xB1, 0x00, 0xAA, 0xFF,
2497 0x15, 0x00, 0xFE, 0xFF, 0x22, 0x00, 0x74, 0xFF, 0x7C, 0x01, 0xB5,
2498 0xFC, 0xB8, 0x06, 0x9C, 0xF1, 0x81, 0x34, 0xD1, 0x2B, 0xB3, 0xF1,
2499 0x29, 0x07, 0x46, 0xFC, 0xCA, 0x01, 0x4A, 0xFF, 0x30, 0x00, 0xFD,
2500 0xFF, 0x00, 0x00, 0x1F, 0x00, 0x81, 0xFF, 0x1B, 0x01, 0x20, 0xFE,
2501 0xB6, 0x02, 0x7A, 0xFC, 0x5F, 0x04, 0xF4, 0x48, 0xFF, 0x02, 0x13,
2502 0xFD, 0x67, 0x02, 0x49, 0xFE, 0x07, 0x01, 0x88, 0xFF, 0x1D, 0x00,
2503 0xFD, 0xFF, 0x2E, 0x00, 0x50, 0xFF, 0xC0, 0x01, 0x53, 0xFC, 0x21,
2504 0x07, 0x96, 0xF1, 0x82, 0x2D, 0xF2, 0x32, 0x86, 0xF1, 0xDB, 0x06,
2505 0x99, 0xFC, 0x8E, 0x01, 0x6A, 0xFF, 0x25, 0x00, 0xFD, 0xFF, 0x16,
2506 0x00, 0xA2, 0xFF, 0xC5, 0x00, 0xD4, 0xFE, 0x5F, 0x01, 0x03, 0xFF,
2507 0xBF, 0xFE, 0x63, 0x48, 0x40, 0x09, 0x7B, 0xFA, 0xB9, 0x03, 0x9D,
2508 0xFD, 0x58, 0x01, 0x69, 0xFF, 0x26, 0x00, 0x00, 0x00, 0xFD, 0xFF,
2509 0x35, 0x00, 0x3B, 0xFF, 0xE2, 0x01, 0x31, 0xFC, 0x17, 0x07, 0x61,
2510 0xF2, 0x0A, 0x26, 0x6A, 0x39, 0x41, 0xF2, 0x15, 0x06, 0x2C, 0xFD,
2511 0x31, 0x01, 0x9B, 0xFF, 0x14, 0x00, 0xFF, 0xFF, 0x0E, 0x00, 0xC4,
2512 0xFF, 0x6E, 0x00, 0x87, 0xFF, 0x13, 0x00, 0x58, 0x01, 0x0D, 0xFA,
2513 0x61, 0x46, 0x2D, 0x10, 0xF0, 0xF7, 0xF1, 0x04, 0x05, 0xFD, 0x9C,
2514 0x01, 0x4E, 0xFF, 0x2E, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00,
2515 0x36, 0xFF, 0xE3, 0x01, 0x4C, 0xFC, 0xA6, 0x06, 0xDB, 0xF3, 0x5B,
2516 0x1E, 0xFC, 0x3E, 0xFA, 0xF3, 0xD7, 0x04, 0xFD, 0xFD, 0xB4, 0x00,
2517 0xD9, 0xFF, 0xFD, 0xFF, 0x03, 0x00, 0x08, 0x00, 0xE4, 0xFF, 0x1B,
2518 0x00, 0x30, 0x00, 0xE4, 0xFE, 0x5F, 0x03, 0x5E, 0xF6, 0x02, 0x43,
2519 0x96, 0x17, 0x9B, 0xF5, 0xF8, 0x05, 0x8F, 0xFC, 0xCC, 0x01, 0x3D,
2520 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x33, 0x00, 0x3E, 0xFF,
2521 0xC8, 0x01, 0x9B, 0xFC, 0xDD, 0x05, 0xDC, 0xF5, 0xB6, 0x16, 0x77,
2522 0x43, 0xBD, 0xF6, 0x28, 0x03, 0x05, 0xFF, 0x1D, 0x00, 0x25, 0x00,
2523 0xE1, 0xFF, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0xD2, 0xFF, 0xC4,
2524 0x00, 0xE2, 0xFD, 0x01, 0x05, 0xBA, 0xF3, 0x64, 0x3E, 0x3F, 0x1F,
2525 0xA8, 0xF3, 0xB8, 0x06, 0x46, 0xFC, 0xE5, 0x01, 0x36, 0xFF, 0x36,
2526 0x00, 0xFD, 0xFF, 0xFF, 0xFF, 0x2D, 0x00, 0x51, 0xFF, 0x95, 0x01,
2527 0x15, 0xFD, 0xCF, 0x04, 0x39, 0xF8, 0x59, 0x0F, 0xAF, 0x46, 0x8B,
2528 0xFA, 0x17, 0x01, 0x38, 0x00, 0x73, 0xFF, 0x78, 0x00, 0xC0, 0xFF,
2529 0x0F, 0x00, 0xFF, 0xFF, 0x16, 0x00, 0x94, 0xFF, 0x3D, 0x01, 0x18,
2530 0xFD, 0x32, 0x06, 0x1F, 0xF2, 0xB5, 0x38, 0xEB, 0x26, 0x40, 0xF2,
2531 0x1E, 0x07, 0x32, 0xFC, 0xDF, 0x01, 0x3D, 0xFF, 0x35, 0x00, 0xFD,
2532 0xFF, 0x00, 0x00, 0x25, 0x00, 0x6C, 0xFF, 0x4F, 0x01, 0xB0, 0xFD,
2533 0x93, 0x03, 0xC7, 0xFA, 0x7D, 0x08, 0x86, 0x48, 0x5A, 0xFF, 0xBA,
2534 0xFE, 0x86, 0x01, 0xBF, 0xFE, 0xCF, 0x00, 0x9E, 0xFF, 0x17, 0x00,
2535 0xFD, 0xFF, 0x27, 0x00, 0x66, 0xFF, 0x97, 0x01, 0x8C, 0xFC, 0xEA,
2536 0x06, 0x80, 0xF1, 0x26, 0x32, 0x58, 0x2E, 0x8B, 0xF1, 0x1B, 0x07,
2537 0x5B, 0xFC, 0xBA, 0x01, 0x53, 0xFF, 0x2D, 0x00, 0xFD, 0xFF, 0x1C,
2538 0x00, 0x8C, 0xFF, 0xFE, 0x00, 0x5D, 0xFE, 0x3F, 0x02, 0x5E, 0xFD,
2539 0x54, 0x02, 0xEC, 0x48, 0x13, 0x05, 0x2E, 0xFC, 0xDE, 0x02, 0x0C,
2540 0xFE, 0x24, 0x01, 0x7D, 0xFF, 0x20, 0x00, 0x00, 0x00, 0xFD, 0xFF,
2541 0x31, 0x00, 0x47, 0xFF, 0xCF, 0x01, 0x40, 0xFC, 0x2A, 0x07, 0xC6,
2542 0xF1, 0xF7, 0x2A, 0x46, 0x35, 0xAB, 0xF1, 0xA4, 0x06, 0xC4, 0xFC,
2543 0x72, 0x01, 0x79, 0xFF, 0x20, 0x00, 0xFE, 0xFF, 0x14, 0x00, 0xAE,
2544 0xFF, 0xA7, 0x00, 0x12, 0xFF, 0xEA, 0x00, 0xD9, 0xFF, 0x03, 0xFD,
2545 0xDC, 0x47, 0x95, 0x0B, 0x96, 0xF9, 0x29, 0x04, 0x65, 0xFD, 0x71,
2546 0x01, 0x5F, 0xFF, 0x29, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x36, 0x00,
2547 0x38, 0xFF, 0xE6, 0x01, 0x34, 0xFC, 0xFB, 0x06, 0xD2, 0xF2, 0x64,
2548 0x23, 0x73, 0x3B, 0xBC, 0xF2, 0xB4, 0x05, 0x6E, 0xFD, 0x09, 0x01,
2549 0xAF, 0xFF, 0x0D, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xD0, 0xFF, 0x51,
2550 0x00, 0xC3, 0xFF, 0xA6, 0xFF, 0x16, 0x02, 0xA9, 0xF8, 0x5C, 0x45,
2551 0xB2, 0x12, 0x19, 0xF7, 0x52, 0x05, 0xD8, 0xFC, 0xAF, 0x01, 0x47,
2552 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00, 0x38, 0xFF,
2553 0xDD, 0x01, 0x62, 0xFC, 0x69, 0x06, 0x7F, 0xF4, 0xB2, 0x1B, 0xAB,
2554 0x40, 0xD0, 0xF4, 0x4E, 0x04, 0x53, 0xFE, 0x83, 0x00, 0xF2, 0xFF,
2555 0xF4, 0xFF, 0x05, 0x00, 0x06, 0x00, 0xEE, 0xFF, 0x01, 0x00, 0x66,
2556 0x00, 0x85, 0xFE, 0xFC, 0x03, 0x55, 0xF5, 0x8C, 0x41, 0x38, 0x1A,
2557 0xE1, 0xF4, 0x43, 0x06, 0x70, 0xFC, 0xD8, 0x01, 0x39, 0xFF, 0x35,
2558 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x32, 0x00, 0x44, 0xFF, 0xB9, 0x01,
2559 0xC1, 0xFC, 0x86, 0x05, 0xA5, 0xF6, 0x1E, 0x14, 0xBA, 0x44, 0xF0,
2560 0xF7, 0x7B, 0x02, 0x6B, 0xFF, 0xE4, 0xFF, 0x41, 0x00, 0xD6, 0xFF,
2561 0x0B, 0x00, 0x01, 0x00, 0x08, 0x00, 0xBB, 0xFF, 0xF1, 0x00, 0x96,
2562 0xFD, 0x78, 0x05, 0x0E, 0xF3, 0x8A, 0x3C, 0xEA, 0x21, 0x19, 0xF3,
2563 0xE6, 0x06, 0x38, 0xFC, 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD,
2564 0xFF, 0x00, 0x00, 0x2B, 0x00, 0x5A, 0xFF, 0x7E, 0x01, 0x48, 0xFD,
2565 0x66, 0x04, 0x18, 0xF9, 0xE8, 0x0C, 0x7C, 0x47, 0x19, 0xFC, 0x4D,
2566 0x00, 0xA9, 0x00, 0x35, 0xFF, 0x96, 0x00, 0xB5, 0xFF, 0x12, 0x00,
2567 0xFE, 0xFF, 0x1D, 0x00, 0x82, 0xFF, 0x60, 0x01, 0xE0, 0xFC, 0x7F,
2568 0x06, 0xCC, 0xF1, 0x85, 0x36, 0x87, 0x29, 0xEB, 0xF1, 0x2A, 0x07,
2569 0x39, 0xFC, 0xD6, 0x01, 0x43, 0xFF, 0x33, 0x00, 0xFD, 0xFF, 0x00,
2570 0x00, 0x22, 0x00, 0x77, 0xFF, 0x34, 0x01, 0xEA, 0xFD, 0x1F, 0x03,
2571 0xAE, 0xFB, 0x45, 0x06, 0xD5, 0x48, 0x3C, 0x01, 0xDC, 0xFD, 0xFD,
2572 0x01, 0x80, 0xFE, 0xED, 0x00, 0x93, 0xFF, 0x1B, 0x00, 0xFD, 0xFF,
2573 0x2B, 0x00, 0x59, 0xFF, 0xAE, 0x01, 0x6A, 0xFC, 0x0D, 0x07, 0x80,
2574 0xF1, 0xB8, 0x2F, 0xCF, 0x30, 0x7D, 0xF1, 0xFF, 0x06, 0x78, 0xFC,
2575 0xA5, 0x01, 0x5F, 0xFF, 0x29, 0x00, 0xFD, 0xFF, 0x19, 0x00, 0x98,
2576 0xFF, 0xE0, 0x00, 0x9C, 0xFE, 0xC8, 0x01, 0x3F, 0xFE, 0x62, 0x00,
2577 0xB8, 0x48, 0x3F, 0x07, 0x47, 0xFB, 0x53, 0x03, 0xD0, 0xFD, 0x40,
2578 0x01, 0x72, 0xFF, 0x23, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x34, 0x00,
2579 0x40, 0xFF, 0xDB, 0x01, 0x35, 0xFC, 0x26, 0x07, 0x0E, 0xF2, 0x60,
2580 0x28, 0x82, 0x37, 0xED, 0xF1, 0x5E, 0x06, 0xF8, 0xFC, 0x51, 0x01,
2581 0x8A, 0xFF, 0x1A, 0x00, 0xFF, 0xFF, 0x11, 0x00, 0xBA, 0xFF, 0x89,
2582 0x00, 0x51, 0xFF, 0x77, 0x00, 0xA7, 0x00, 0x64, 0xFB, 0x26, 0x47,
2583 0xFC, 0x0D, 0xB4, 0xF8, 0x95, 0x04, 0x31, 0xFD, 0x88, 0x01, 0x56,
2584 0xFF, 0x2C, 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF,
2585 0xE6, 0x01, 0x3E, 0xFC, 0xD3, 0x06, 0x56, 0xF3, 0xBA, 0x20, 0x61,
2586 0x3D, 0x56, 0xF3, 0x45, 0x05, 0xB7, 0xFD, 0xDE, 0x00, 0xC5, 0xFF,
2587 0x05, 0x00, 0x02, 0x00, 0x09, 0x00, 0xDB, 0xFF, 0x34, 0x00, 0xFE,
2588 0xFF, 0x3D, 0xFF, 0xC9, 0x02, 0x64, 0xF7, 0x2F, 0x44, 0x44, 0x15,
2589 0x4A, 0xF6, 0xAD, 0x05, 0xAF, 0xFC, 0xC0, 0x01, 0x41, 0xFF, 0x32,
2590 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xD3, 0x01,
2591 0x7D, 0xFC, 0x23, 0x06, 0x32, 0xF5, 0x0C, 0x19, 0x38, 0x42, 0xC7,
2592 0xF5, 0xB8, 0x03, 0xAF, 0xFE, 0x4E, 0x00, 0x0C, 0x00, 0xEA, 0xFF,
2593 0x06, 0x00, 0x04, 0x00, 0xF8, 0xFF, 0xE7, 0xFF, 0x99, 0x00, 0x2C,
2594 0xFE, 0x8C, 0x04, 0x6D, 0xF4, 0xF0, 0x3F, 0xE0, 0x1C, 0x34, 0xF4,
2595 0x85, 0x06, 0x57, 0xFC, 0xE0, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE,
2596 0xFF, 0xFF, 0xFF, 0x2F, 0x00, 0x4A, 0xFF, 0xA7, 0x01, 0xEC, 0xFC,
2597 0x28, 0x05, 0x77, 0xF7, 0x92, 0x11, 0xD7, 0x45, 0x43, 0xF9, 0xC3,
2598 0x01, 0xD6, 0xFF, 0xA9, 0xFF, 0x5E, 0x00, 0xCB, 0xFF, 0x0D, 0x00,
2599 0x00, 0x00, 0x10, 0x00, 0xA6, 0xFF, 0x1B, 0x01, 0x50, 0xFD, 0xE1,
2600 0x05, 0x82, 0xF2, 0x8F, 0x3A, 0x92, 0x24, 0x9D, 0xF2, 0x09, 0x07,
2601 0x32, 0xFC, 0xE4, 0x01, 0x39, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x00,
2602 0x00, 0x28, 0x00, 0x63, 0xFF, 0x66, 0x01, 0x7D, 0xFD, 0xF8, 0x03,
2603 0xFB, 0xF9, 0x89, 0x0A, 0x1D, 0x48, 0xC5, 0xFD, 0x7A, 0xFF, 0x1D,
2604 0x01, 0xF7, 0xFE, 0xB4, 0x00, 0xA9, 0xFF, 0x15, 0x00, 0xFE, 0xFF,
2605 0x23, 0x00, 0x72, 0xFF, 0x7F, 0x01, 0xB0, 0xFC, 0xBE, 0x06, 0x97,
2606 0xF1, 0x3F, 0x34, 0x19, 0x2C, 0xAD, 0xF1, 0x28, 0x07, 0x48, 0xFC,
2607 0xC9, 0x01, 0x4B, 0xFF, 0x30, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x1F,
2608 0x00, 0x82, 0xFF, 0x18, 0x01, 0x27, 0xFE, 0xA9, 0x02, 0x94, 0xFC,
2609 0x24, 0x04, 0xF5, 0x48, 0x39, 0x03, 0xF9, 0xFC, 0x74, 0x02, 0x42,
2610 0xFE, 0x0B, 0x01, 0x87, 0xFF, 0x1E, 0x00, 0xFD, 0xFF, 0x2F, 0x00,
2611 0x4F, 0xFF, 0xC2, 0x01, 0x51, 0xFC, 0x23, 0x07, 0x9A, 0xF1, 0x3A,
2612 0x2D, 0x35, 0x33, 0x89, 0xF1, 0xD5, 0x06, 0x9D, 0xFC, 0x8B, 0x01,
2613 0x6C, 0xFF, 0x25, 0x00, 0xFD, 0xFF, 0x16, 0x00, 0xA4, 0xFF, 0xC2,
2614 0x00, 0xDB, 0xFE, 0x52, 0x01, 0x1B, 0xFF, 0x8D, 0xFE, 0x57, 0x48,
2615 0x81, 0x09, 0x61, 0xFA, 0xC6, 0x03, 0x96, 0xFD, 0x5B, 0x01, 0x68,
2616 0xFF, 0x26, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3B, 0xFF,
2617 0xE2, 0x01, 0x31, 0xFC, 0x15, 0x07, 0x6D, 0xF2, 0xBF, 0x25, 0xA5,
2618 0x39, 0x4D, 0xF2, 0x0B, 0x06, 0x33, 0xFD, 0x2D, 0x01, 0x9D, 0xFF,
2619 0x13, 0x00, 0xFF, 0xFF, 0x0E, 0x00, 0xC6, 0xFF, 0x6B, 0x00, 0x8E,
2620 0xFF, 0x06, 0x00, 0x6E, 0x01, 0xE4, 0xF9, 0x48, 0x46, 0x75, 0x10,
2621 0xD7, 0xF7, 0xFC, 0x04, 0x00, 0xFD, 0x9E, 0x01, 0x4E, 0xFF, 0x2E,
2622 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE3, 0x01,
2623 0x4E, 0xFC, 0xA0, 0x06, 0xED, 0xF3, 0x0F, 0x1E, 0x2D, 0x3F, 0x10,
2624 0xF4, 0xC8, 0x04, 0x07, 0xFE, 0xAF, 0x00, 0xDC, 0xFF, 0xFC, 0xFF,
2625 0x03, 0x00, 0x07, 0x00, 0xE5, 0xFF, 0x18, 0x00, 0x36, 0x00, 0xD9,
2626 0xFE, 0x71, 0x03, 0x3F, 0xF6, 0xDB, 0x42, 0xE0, 0x17, 0x86, 0xF5,
2627 0x00, 0x06, 0x8C, 0xFC, 0xCE, 0x01, 0x3C, 0xFF, 0x34, 0x00, 0xFE,
2628 0xFF, 0xFF, 0xFF, 0x33, 0x00, 0x3F, 0xFF, 0xC6, 0x01, 0x9F, 0xFC,
2629 0xD3, 0x05, 0xF1, 0xF5, 0x6C, 0x16, 0x9E, 0x43, 0xDD, 0xF6, 0x15,
2630 0x03, 0x10, 0xFF, 0x17, 0x00, 0x28, 0x00, 0xDF, 0xFF, 0x09, 0x00,
2631 0x02, 0x00, 0x01, 0x00, 0xCF, 0xFF, 0xC9, 0x00, 0xDA, 0xFD, 0x0F,
2632 0x05, 0xA5, 0xF3, 0x31, 0x3E, 0x8A, 0x1F, 0x97, 0xF3, 0xBD, 0x06,
2633 0x44, 0xFC, 0xE5, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFF,
2634 0xFF, 0x2D, 0x00, 0x52, 0xFF, 0x92, 0x01, 0x1B, 0xFD, 0xC4, 0x04,
2635 0x51, 0xF8, 0x13, 0x0F, 0xC8, 0x46, 0xB6, 0xFA, 0x01, 0x01, 0x44,
2636 0x00, 0x6C, 0xFF, 0x7B, 0x00, 0xBF, 0xFF, 0x10, 0x00, 0xFF, 0xFF,
2637 0x17, 0x00, 0x92, 0xFF, 0x41, 0x01, 0x11, 0xFD, 0x3B, 0x06, 0x14,
2638 0xF2, 0x78, 0x38, 0x36, 0x27, 0x35, 0xF2, 0x20, 0x07, 0x33, 0xFC,
2639 0xDF, 0x01, 0x3E, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x25,
2640 0x00, 0x6D, 0xFF, 0x4C, 0x01, 0xB6, 0xFD, 0x86, 0x03, 0xE1, 0xFA,
2641 0x3D, 0x08, 0x92, 0x48, 0x8E, 0xFF, 0xA1, 0xFE, 0x93, 0x01, 0xB8,
2642 0xFE, 0xD3, 0x00, 0x9D, 0xFF, 0x18, 0x00, 0xFD, 0xFF, 0x28, 0x00,
2643 0x64, 0xFF, 0x9A, 0x01, 0x88, 0xFC, 0xEE, 0x06, 0x7E, 0xF1, 0xE3,
2644 0x31, 0x9F, 0x2E, 0x88, 0xF1, 0x19, 0x07, 0x5E, 0xFC, 0xB7, 0x01,
2645 0x54, 0xFF, 0x2D, 0x00, 0xFD, 0xFF, 0x1C, 0x00, 0x8D, 0xFF, 0xFA,
2646 0x00, 0x64, 0xFE, 0x32, 0x02, 0x78, 0xFD, 0x1B, 0x02, 0xEA, 0x48,
2647 0x50, 0x05, 0x14, 0xFC, 0xEB, 0x02, 0x05, 0xFE, 0x27, 0x01, 0x7C,
2648 0xFF, 0x21, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x32, 0x00, 0x46, 0xFF,
2649 0xD1, 0x01, 0x3F, 0xFC, 0x2B, 0x07, 0xCD, 0xF1, 0xAE, 0x2A, 0x86,
2650 0x35, 0xB1, 0xF1, 0x9D, 0x06, 0xCA, 0xFC, 0x6E, 0x01, 0x7B, 0xFF,
2651 0x20, 0x00, 0xFE, 0xFF, 0x13, 0x00, 0xAF, 0xFF, 0xA4, 0x00, 0x19,
2652 0xFF, 0xDD, 0x00, 0xF0, 0xFF, 0xD4, 0xFC, 0xC9, 0x47, 0xD8, 0x0B,
2653 0x7C, 0xF9, 0x35, 0x04, 0x5F, 0xFD, 0x74, 0x01, 0x5E, 0xFF, 0x29,
2654 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xE6, 0x01,
2655 0x35, 0xFC, 0xF7, 0x06, 0xE0, 0xF2, 0x18, 0x23, 0xAB, 0x3B, 0xCC,
2656 0xF2, 0xA8, 0x05, 0x76, 0xFD, 0x04, 0x01, 0xB1, 0xFF, 0x0C, 0x00,
2657 0x00, 0x00, 0x0C, 0x00, 0xD1, 0xFF, 0x4E, 0x00, 0xCA, 0xFF, 0x9A,
2658 0xFF, 0x2A, 0x02, 0x83, 0xF8, 0x3F, 0x45, 0xFB, 0x12, 0x01, 0xF7,
2659 0x5D, 0x05, 0xD3, 0xFC, 0xB1, 0x01, 0x46, 0xFF, 0x31, 0x00, 0xFF,
2660 0xFF, 0xFE, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xDC, 0x01, 0x64, 0xFC,
2661 0x62, 0x06, 0x93, 0xF4, 0x66, 0x1B, 0xD9, 0x40, 0xEA, 0xF4, 0x3E,
2662 0x04, 0x5D, 0xFE, 0x7D, 0x00, 0xF5, 0xFF, 0xF3, 0xFF, 0x05, 0x00,
2663 0x05, 0x00, 0xEF, 0xFF, 0xFE, 0xFF, 0x6C, 0x00, 0x7B, 0xFE, 0x0C,
2664 0x04, 0x3A, 0xF5, 0x5F, 0x41, 0x83, 0x1A, 0xCD, 0xF4, 0x4B, 0x06,
2665 0x6D, 0xFC, 0xD9, 0x01, 0x39, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0xFF,
2666 0xFF, 0x31, 0x00, 0x44, 0xFF, 0xB7, 0x01, 0xC5, 0xFC, 0x7C, 0x05,
2667 0xBC, 0xF6, 0xD5, 0x13, 0xDC, 0x44, 0x14, 0xF8, 0x67, 0x02, 0x77,
2668 0xFF, 0xDD, 0xFF, 0x44, 0x00, 0xD5, 0xFF, 0x0B, 0x00, 0x01, 0x00,
2669 0x09, 0x00, 0xB8, 0xFF, 0xF6, 0x00, 0x8D, 0xFD, 0x84, 0x05, 0xFD,
2670 0xF2, 0x52, 0x3C, 0x35, 0x22, 0x0B, 0xF3, 0xEB, 0x06, 0x37, 0xFC,
2671 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x2A,
2672 0x00, 0x5B, 0xFF, 0x7C, 0x01, 0x4E, 0xFD, 0x5A, 0x04, 0x31, 0xF9,
2673 0xA4, 0x0C, 0x90, 0x47, 0x47, 0xFC, 0x36, 0x00, 0xB6, 0x00, 0x2E,
2674 0xFF, 0x99, 0x00, 0xB3, 0xFF, 0x12, 0x00, 0xFE, 0xFF, 0x1E, 0x00,
2675 0x80, 0xFF, 0x64, 0x01, 0xDA, 0xFC, 0x87, 0x06, 0xC5, 0xF1, 0x46,
2676 0x36, 0xD1, 0x29, 0xE3, 0xF1, 0x2A, 0x07, 0x3A, 0xFC, 0xD5, 0x01,
2677 0x44, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x22, 0x00, 0x78,
2678 0xFF, 0x31, 0x01, 0xF1, 0xFD, 0x12, 0x03, 0xC7, 0xFB, 0x07, 0x06,
2679 0xDB, 0x48, 0x73, 0x01, 0xC3, 0xFD, 0x0A, 0x02, 0x79, 0xFE, 0xF1,
2680 0x00, 0x91, 0xFF, 0x1B, 0x00, 0xFD, 0xFF, 0x2C, 0x00, 0x58, 0xFF,
2681 0xB1, 0x01, 0x67, 0xFC, 0x10, 0x07, 0x81, 0xF1, 0x73, 0x2F, 0x15,
2682 0x31, 0x7C, 0xF1, 0xFB, 0x06, 0x7C, 0xFC, 0xA2, 0x01, 0x60, 0xFF,
2683 0x29, 0x00, 0xFD, 0xFF, 0x19, 0x00, 0x99, 0xFF, 0xDD, 0x00, 0xA3,
2684 0xFE, 0xBB, 0x01, 0x58, 0xFE, 0x2D, 0x00, 0xAF, 0x48, 0x7E, 0x07,
2685 0x2E, 0xFB, 0x60, 0x03, 0xC9, 0xFD, 0x43, 0x01, 0x71, 0xFF, 0x24,
2686 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x34, 0x00, 0x3F, 0xFF, 0xDC, 0x01,
2687 0x34, 0xFC, 0x25, 0x07, 0x18, 0xF2, 0x15, 0x28, 0xBF, 0x37, 0xF7,
2688 0xF1, 0x56, 0x06, 0xFE, 0xFC, 0x4D, 0x01, 0x8C, 0xFF, 0x19, 0x00,
2689 0xFF, 0xFF, 0x10, 0x00, 0xBB, 0xFF, 0x85, 0x00, 0x58, 0xFF, 0x6A,
2690 0x00, 0xBE, 0x00, 0x38, 0xFB, 0x0F, 0x47, 0x42, 0x0E, 0x9B, 0xF8,
2691 0xA1, 0x04, 0x2B, 0xFD, 0x8B, 0x01, 0x55, 0xFF, 0x2C, 0x00, 0xFF,
2692 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3F, 0xFC,
2693 0xCE, 0x06, 0x66, 0xF3, 0x6F, 0x20, 0x96, 0x3D, 0x69, 0xF3, 0x38,
2694 0x05, 0xBF, 0xFD, 0xD9, 0x00, 0xC7, 0xFF, 0x04, 0x00, 0x02, 0x00,
2695 0x09, 0x00, 0xDC, 0xFF, 0x31, 0x00, 0x04, 0x00, 0x32, 0xFF, 0xDC,
2696 0x02, 0x42, 0xF7, 0x0B, 0x44, 0x8E, 0x15, 0x34, 0xF6, 0xB7, 0x05,
2697 0xAB, 0xFC, 0xC1, 0x01, 0x40, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0xFE,
2698 0xFF, 0x35, 0x00, 0x3B, 0xFF, 0xD2, 0x01, 0x81, 0xFC, 0x1A, 0x06,
2699 0x47, 0xF5, 0xC1, 0x18, 0x60, 0x42, 0xE4, 0xF5, 0xA6, 0x03, 0xB9,
2700 0xFE, 0x48, 0x00, 0x0F, 0x00, 0xE9, 0xFF, 0x07, 0x00, 0x04, 0x00,
2701 0xF9, 0xFF, 0xE4, 0xFF, 0x9F, 0x00, 0x23, 0xFE, 0x9B, 0x04, 0x55,
2702 0xF4, 0xC0, 0x3F, 0x2C, 0x1D, 0x22, 0xF4, 0x8C, 0x06, 0x55, 0xFC,
2703 0xE1, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x2F,
2704 0x00, 0x4B, 0xFF, 0xA4, 0x01, 0xF1, 0xFC, 0x1D, 0x05, 0x8F, 0xF7,
2705 0x4A, 0x11, 0xF2, 0x45, 0x6B, 0xF9, 0xAE, 0x01, 0xE2, 0xFF, 0xA2,
2706 0xFF, 0x61, 0x00, 0xC9, 0xFF, 0x0D, 0x00, 0x00, 0x00, 0x11, 0x00,
2707 0xA3, 0xFF, 0x20, 0x01, 0x49, 0xFD, 0xEB, 0x05, 0x74, 0xF2, 0x54,
2708 0x3A, 0xDD, 0x24, 0x91, 0xF2, 0x0C, 0x07, 0x32, 0xFC, 0xE4, 0x01,
2709 0x3A, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x27, 0x00, 0x64,
2710 0xFF, 0x63, 0x01, 0x84, 0xFD, 0xEB, 0x03, 0x14, 0xFA, 0x47, 0x0A,
2711 0x2C, 0x48, 0xF6, 0xFD, 0x63, 0xFF, 0x2B, 0x01, 0xF0, 0xFE, 0xB8,
2712 0x00, 0xA8, 0xFF, 0x15, 0x00, 0xFE, 0xFF, 0x23, 0x00, 0x71, 0xFF,
2713 0x82, 0x01, 0xAB, 0xFC, 0xC4, 0x06, 0x93, 0xF1, 0xFD, 0x33, 0x62,
2714 0x2C, 0xA8, 0xF1, 0x27, 0x07, 0x4A, 0xFC, 0xC7, 0x01, 0x4C, 0xFF,
2715 0x30, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x1F, 0x00, 0x83, 0xFF, 0x14,
2716 0x01, 0x2D, 0xFE, 0x9C, 0x02, 0xAD, 0xFC, 0xE9, 0x03, 0xF6, 0x48,
2717 0x73, 0x03, 0xE0, 0xFC, 0x82, 0x02, 0x3B, 0xFE, 0x0E, 0x01, 0x86,
2718 0xFF, 0x1E, 0x00, 0xFD, 0xFF, 0x2F, 0x00, 0x4E, 0xFF, 0xC3, 0x01,
2719 0x4E, 0xFC, 0x24, 0x07, 0x9E, 0xF1, 0xF2, 0x2C, 0x78, 0x33, 0x8C,
2720 0xF1, 0xD0, 0x06, 0xA2, 0xFC, 0x88, 0x01, 0x6D, 0xFF, 0x24, 0x00,
2721 0xFD, 0xFF, 0x16, 0x00, 0xA5, 0xFF, 0xBE, 0x00, 0xE2, 0xFE, 0x45,
2722 0x01, 0x33, 0xFF, 0x5A, 0xFE, 0x48, 0x48, 0xC3, 0x09, 0x47, 0xFA,
2723 0xD2, 0x03, 0x90, 0xFD, 0x5E, 0x01, 0x66, 0xFF, 0x27, 0x00, 0x00,
2724 0x00, 0xFD, 0xFF, 0x35, 0x00, 0x3B, 0xFF, 0xE3, 0x01, 0x31, 0xFC,
2725 0x12, 0x07, 0x79, 0xF2, 0x73, 0x25, 0xDF, 0x39, 0x5A, 0xF2, 0x00,
2726 0x06, 0x3A, 0xFD, 0x28, 0x01, 0x9F, 0xFF, 0x13, 0x00, 0x00, 0x00,
2727 0x0E, 0x00, 0xC7, 0xFF, 0x68, 0x00, 0x95, 0xFF, 0xFA, 0xFF, 0x83,
2728 0x01, 0xBB, 0xF9, 0x2B, 0x46, 0xBB, 0x10, 0xBF, 0xF7, 0x07, 0x05,
2729 0xFB, 0xFC, 0xA0, 0x01, 0x4D, 0xFF, 0x2F, 0x00, 0xFF, 0xFF, 0xFE,
2730 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE2, 0x01, 0x50, 0xFC, 0x99, 0x06,
2731 0xFE, 0xF3, 0xC3, 0x1D, 0x5E, 0x3F, 0x27, 0xF4, 0xB9, 0x04, 0x10,
2732 0xFE, 0xA9, 0x00, 0xDF, 0xFF, 0xFB, 0xFF, 0x03, 0x00, 0x07, 0x00,
2733 0xE6, 0xFF, 0x15, 0x00, 0x3C, 0x00, 0xCF, 0xFE, 0x83, 0x03, 0x20,
2734 0xF6, 0xB2, 0x42, 0x2B, 0x18, 0x71, 0xF5, 0x09, 0x06, 0x88, 0xFC,
2735 0xCF, 0x01, 0x3C, 0xFF, 0x34, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x33,
2736 0x00, 0x3F, 0xFF, 0xC5, 0x01, 0xA3, 0xFC, 0xCA, 0x05, 0x07, 0xF6,
2737 0x22, 0x16, 0xC3, 0x43, 0xFE, 0xF6, 0x02, 0x03, 0x1B, 0xFF, 0x11,
2738 0x00, 0x2B, 0x00, 0xDE, 0xFF, 0x09, 0x00, 0x02, 0x00, 0x02, 0x00,
2739 0xCC, 0xFF, 0xCE, 0x00, 0xD1, 0xFD, 0x1D, 0x05, 0x91, 0xF3, 0xFE,
2740 0x3D, 0xD7, 0x1F, 0x87, 0xF3, 0xC3, 0x06, 0x42, 0xFC, 0xE5, 0x01,
2741 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFF, 0xFF, 0x2D, 0x00, 0x53,
2742 0xFF, 0x90, 0x01, 0x20, 0xFD, 0xB8, 0x04, 0x6A, 0xF8, 0xCD, 0x0E,
2743 0xE1, 0x46, 0xE1, 0xFA, 0xEB, 0x00, 0x51, 0x00, 0x65, 0xFF, 0x7F,
2744 0x00, 0xBE, 0xFF, 0x10, 0x00, 0xFF, 0xFF, 0x18, 0x00, 0x90, 0xFF,
2745 0x45, 0x01, 0x0B, 0xFD, 0x44, 0x06, 0x0A, 0xF2, 0x3B, 0x38, 0x80,
2746 0x27, 0x2B, 0xF2, 0x22, 0x07, 0x33, 0xFC, 0xDE, 0x01, 0x3E, 0xFF,
2747 0x34, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x24, 0x00, 0x6E, 0xFF, 0x49,
2748 0x01, 0xBC, 0xFD, 0x7A, 0x03, 0xFA, 0xFA, 0xFD, 0x07, 0x9C, 0x48,
2749 0xC3, 0xFF, 0x89, 0xFE, 0xA1, 0x01, 0xB1, 0xFE, 0xD6, 0x00, 0x9C,
2750 0xFF, 0x18, 0x00, 0xFD, 0xFF, 0x28, 0x00, 0x63, 0xFF, 0x9D, 0x01,
2751 0x84, 0xFC, 0xF3, 0x06, 0x7D, 0xF1, 0x9E, 0x31, 0xE6, 0x2E, 0x85,
2752 0xF1, 0x16, 0x07, 0x61, 0xFC, 0xB5, 0x01, 0x55, 0xFF, 0x2D, 0x00,
2753 0xFD, 0xFF, 0x1C, 0x00, 0x8F, 0xFF, 0xF7, 0x00, 0x6B, 0xFE, 0x25,
2754 0x02, 0x91, 0xFD, 0xE3, 0x01, 0xE5, 0x48, 0x8D, 0x05, 0xFB, 0xFB,
2755 0xF8, 0x02, 0xFE, 0xFD, 0x2B, 0x01, 0x7A, 0xFF, 0x21, 0x00, 0x00,
2756 0x00, 0xFD, 0xFF, 0x32, 0x00, 0x45, 0xFF, 0xD2, 0x01, 0x3D, 0xFC,
2757 0x2B, 0x07, 0xD4, 0xF1, 0x64, 0x2A, 0xC6, 0x35, 0xB7, 0xF1, 0x96,
2758 0x06, 0xCF, 0xFC, 0x6B, 0x01, 0x7D, 0xFF, 0x1F, 0x00, 0xFE, 0xFF,
2759 0x13, 0x00, 0xB1, 0xFF, 0xA0, 0x00, 0x20, 0xFF, 0xD0, 0x00, 0x07,
2760 0x00, 0xA4, 0xFC, 0xB6, 0x47, 0x1C, 0x0C, 0x63, 0xF9, 0x42, 0x04,
2761 0x59, 0xFD, 0x76, 0x01, 0x5D, 0xFF, 0x2A, 0x00, 0x00, 0x00, 0xFD,
2762 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x35, 0xFC, 0xF3, 0x06,
2763 0xEE, 0xF2, 0xCD, 0x22, 0xE4, 0x3B, 0xDC, 0xF2, 0x9C, 0x05, 0x7E,
2764 0xFD, 0x00, 0x01, 0xB4, 0xFF, 0x0B, 0x00, 0x01, 0x00, 0x0B, 0x00,
2765 0xD2, 0xFF, 0x4A, 0x00, 0xD0, 0xFF, 0x8E, 0xFF, 0x3F, 0x02, 0x5E,
2766 0xF8, 0x1E, 0x45, 0x44, 0x13, 0xEA, 0xF6, 0x67, 0x05, 0xCF, 0xFC,
2767 0xB3, 0x01, 0x46, 0xFF, 0x31, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x36,
2768 0x00, 0x38, 0xFF, 0xDB, 0x01, 0x67, 0xFC, 0x5A, 0x06, 0xA6, 0xF4,
2769 0x1B, 0x1B, 0x07, 0x41, 0x04, 0xF5, 0x2D, 0x04, 0x67, 0xFE, 0x77,
2770 0x00, 0xF8, 0xFF, 0xF2, 0xFF, 0x05, 0x00, 0x05, 0x00, 0xF0, 0xFF,
2771 0xFB, 0xFF, 0x71, 0x00, 0x71, 0xFE, 0x1D, 0x04, 0x1F, 0xF5, 0x32,
2772 0x41, 0xCE, 0x1A, 0xBA, 0xF4, 0x53, 0x06, 0x6A, 0xFC, 0xDA, 0x01,
2773 0x38, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x31, 0x00, 0x45,
2774 0xFF, 0xB5, 0x01, 0xCA, 0xFC, 0x72, 0x05, 0xD3, 0xF6, 0x8D, 0x13,
2775 0xFD, 0x44, 0x39, 0xF8, 0x53, 0x02, 0x82, 0xFF, 0xD7, 0xFF, 0x47,
2776 0x00, 0xD3, 0xFF, 0x0B, 0x00, 0x01, 0x00, 0x0A, 0x00, 0xB6, 0xFF,
2777 0xFB, 0x00, 0x85, 0xFD, 0x90, 0x05, 0xEC, 0xF2, 0x1C, 0x3C, 0x81,
2778 0x22, 0xFC, 0xF2, 0xEF, 0x06, 0x36, 0xFC, 0xE6, 0x01, 0x37, 0xFF,
2779 0x36, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x2A, 0x00, 0x5C, 0xFF, 0x79,
2780 0x01, 0x53, 0xFD, 0x4E, 0x04, 0x4A, 0xF9, 0x60, 0x0C, 0xA3, 0x47,
2781 0x76, 0xFC, 0x1F, 0x00, 0xC3, 0x00, 0x27, 0xFF, 0x9D, 0x00, 0xB2,
2782 0xFF, 0x13, 0x00, 0xFE, 0xFF, 0x1E, 0x00, 0x7F, 0xFF, 0x67, 0x01,
2783 0xD5, 0xFC, 0x8E, 0x06, 0xBE, 0xF1, 0x06, 0x36, 0x1A, 0x2A, 0xDC,
2784 0xF1, 0x2A, 0x07, 0x3C, 0xFC, 0xD3, 0x01, 0x44, 0xFF, 0x32, 0x00,
2785 0xFD, 0xFF, 0x00, 0x00, 0x21, 0x00, 0x79, 0xFF, 0x2E, 0x01, 0xF7,
2786 0xFD, 0x05, 0x03, 0xE1, 0xFB, 0xCA, 0x05, 0xDF, 0x48, 0xAB, 0x01,
2787 0xAA, 0xFD, 0x18, 0x02, 0x72, 0xFE, 0xF4, 0x00, 0x90, 0xFF, 0x1B,
2788 0x00, 0xFD, 0xFF, 0x2C, 0x00, 0x57, 0xFF, 0xB3, 0x01, 0x64, 0xFC,
2789 0x13, 0x07, 0x83, 0xF1, 0x2C, 0x2F, 0x5A, 0x31, 0x7D, 0xF1, 0xF7,
2790 0x06, 0x80, 0xFC, 0x9F, 0x01, 0x61, 0xFF, 0x29, 0x00, 0xFD, 0xFF,
2791 0x19, 0x00, 0x9A, 0xFF, 0xD9, 0x00, 0xAA, 0xFE, 0xAE, 0x01, 0x70,
2792 0xFE, 0xF8, 0xFF, 0xA6, 0x48, 0xBE, 0x07, 0x14, 0xFB, 0x6D, 0x03,
2793 0xC3, 0xFD, 0x46, 0x01, 0x70, 0xFF, 0x24, 0x00, 0x00, 0x00, 0xFD,
2794 0xFF, 0x34, 0x00, 0x3F, 0xFF, 0xDD, 0x01, 0x34, 0xFC, 0x23, 0x07,
2795 0x21, 0xF2, 0xCB, 0x27, 0xFE, 0x37, 0x00, 0xF2, 0x4D, 0x06, 0x04,
2796 0xFD, 0x49, 0x01, 0x8E, 0xFF, 0x19, 0x00, 0xFF, 0xFF, 0x10, 0x00,
2797 0xBD, 0xFF, 0x82, 0x00, 0x5E, 0xFF, 0x5D, 0x00, 0xD4, 0x00, 0x0C,
2798 0xFB, 0xF9, 0x46, 0x87, 0x0E, 0x82, 0xF8, 0xAD, 0x04, 0x26, 0xFD,
2799 0x8D, 0x01, 0x54, 0xFF, 0x2C, 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0x36,
2800 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x41, 0xFC, 0xC8, 0x06, 0x76, 0xF3,
2801 0x22, 0x20, 0xCA, 0x3D, 0x7D, 0xF3, 0x2A, 0x05, 0xC8, 0xFD, 0xD4,
2802 0x00, 0xCA, 0xFF, 0x03, 0x00, 0x02, 0x00, 0x09, 0x00, 0xDD, 0xFF,
2803 0x2E, 0x00, 0x0A, 0x00, 0x27, 0xFF, 0xEF, 0x02, 0x20, 0xF7, 0xE7,
2804 0x43, 0xD8, 0x15, 0x1E, 0xF6, 0xC0, 0x05, 0xA7, 0xFC, 0xC3, 0x01,
2805 0x40, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0xFE, 0xFF, 0x34, 0x00, 0x3B,
2806 0xFF, 0xD1, 0x01, 0x84, 0xFC, 0x12, 0x06, 0x5C, 0xF5, 0x76, 0x18,
2807 0x89, 0x42, 0x02, 0xF6, 0x94, 0x03, 0xC4, 0xFE, 0x42, 0x00, 0x12,
2808 0x00, 0xE8, 0xFF, 0x07, 0x00, 0x03, 0x00, 0xFA, 0xFF, 0xE2, 0xFF,
2809 0xA4, 0x00, 0x19, 0xFE, 0xAA, 0x04, 0x3E, 0xF4, 0x90, 0x3F, 0x78,
2810 0x1D, 0x10, 0xF4, 0x93, 0x06, 0x52, 0xFC, 0xE1, 0x01, 0x36, 0xFF,
2811 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x2F, 0x00, 0x4C, 0xFF, 0xA2,
2812 0x01, 0xF6, 0xFC, 0x12, 0x05, 0xA7, 0xF7, 0x03, 0x11, 0x10, 0x46,
2813 0x93, 0xF9, 0x98, 0x01, 0xEE, 0xFF, 0x9B, 0xFF, 0x64, 0x00, 0xC8,
2814 0xFF, 0x0E, 0x00, 0x00, 0x00, 0x12, 0x00, 0xA1, 0xFF, 0x24, 0x01,
2815 0x41, 0xFD, 0xF6, 0x05, 0x67, 0xF2, 0x1A, 0x3A, 0x29, 0x25, 0x84,
2816 0xF2, 0x0F, 0x07, 0x31, 0xFC, 0xE3, 0x01, 0x3A, 0xFF, 0x35, 0x00,
2817 0xFD, 0xFF, 0x00, 0x00, 0x27, 0x00, 0x65, 0xFF, 0x60, 0x01, 0x8A,
2818 0xFD, 0xDF, 0x03, 0x2E, 0xFA, 0x04, 0x0A, 0x3A, 0x48, 0x28, 0xFE,
2819 0x4B, 0xFF, 0x38, 0x01, 0xE9, 0xFE, 0xBB, 0x00, 0xA6, 0xFF, 0x16,
2820 0x00, 0xFD, 0xFF, 0x24, 0x00, 0x6F, 0xFF, 0x85, 0x01, 0xA6, 0xFC,
2821 0xCA, 0x06, 0x8F, 0xF1, 0xBB, 0x33, 0xAB, 0x2C, 0xA3, 0xF1, 0x26,
2822 0x07, 0x4C, 0xFC, 0xC5, 0x01, 0x4D, 0xFF, 0x30, 0x00, 0xFD, 0xFF,
2823 0x00, 0x00, 0x1E, 0x00, 0x84, 0xFF, 0x11, 0x01, 0x34, 0xFE, 0x8F,
2824 0x02, 0xC7, 0xFC, 0xAE, 0x03, 0xF7, 0x48, 0xAE, 0x03, 0xC7, 0xFC,
2825 0x8F, 0x02, 0x34, 0xFE, 0x11, 0x01, 0x84, 0xFF, 0x1E, 0x00, 0xFD,
2826 0xFF, 0x2A, 0x00, 0x5C, 0xFF, 0xAA, 0x01, 0x71, 0xFC, 0x07, 0x07,
2827 0x7E, 0xF1, 0x44, 0x30, 0x44, 0x30, 0x7E, 0xF1, 0x07, 0x07, 0x71,
2828 0xFC, 0xAA, 0x01, 0x5C, 0xFF, 0x2A, 0x00, 0xFD, 0xFF, 0x00, 0x00,
2829 0x1E, 0x00, 0x84, 0xFF, 0x11, 0x01, 0x34, 0xFE, 0x8F, 0x02, 0xC7,
2830 0xFC, 0xAE, 0x03, 0xF7, 0x48, 0xAE, 0x03, 0xC7, 0xFC, 0x8F, 0x02,
2831 0x34, 0xFE, 0x11, 0x01, 0x84, 0xFF, 0x1E, 0x00, 0x02, 0x00, 0x05,
2832 0x00, 0xC3, 0xFF, 0xE1, 0x00, 0xB1, 0xFD, 0x4E, 0x05, 0x4A, 0xF3,
2833 0x3D, 0x3D, 0xED, 0x20, 0x4C, 0xF3, 0xD6, 0x06, 0x3D, 0xFC, 0xE6,
2834 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x36, 0x00,
2835 0x36, 0xFF, 0xE6, 0x01, 0x3D, 0xFC, 0xD6, 0x06, 0x4C, 0xF3, 0xED,
2836 0x20, 0x3D, 0x3D, 0x4A, 0xF3, 0x4E, 0x05, 0xB1, 0xFD, 0xE1, 0x00,
2837 0xC3, 0xFF, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x84,
2838 0xFF, 0x11, 0x01, 0x34, 0xFE, 0x8F, 0x02, 0xC7, 0xFC, 0xAE, 0x03,
2839 0xF7, 0x48, 0xAE, 0x03, 0xC7, 0xFC, 0x8F, 0x02, 0x34, 0xFE, 0x11,
2840 0x01, 0x84, 0xFF, 0x1E, 0x00, 0x16, 0x00, 0xA6, 0xFF, 0xBB, 0x00,
2841 0xE9, 0xFE, 0x38, 0x01, 0x4B, 0xFF, 0x28, 0xFE, 0x3A, 0x48, 0x04,
2842 0x0A, 0x2E, 0xFA, 0xDF, 0x03, 0x8A, 0xFD, 0x60, 0x01, 0x65, 0xFF,
2843 0x27, 0x00, 0x00, 0x00, 0x0E, 0x00, 0xC8, 0xFF, 0x64, 0x00, 0x9B,
2844 0xFF, 0xEE, 0xFF, 0x98, 0x01, 0x93, 0xF9, 0x10, 0x46, 0x03, 0x11,
2845 0xA7, 0xF7, 0x12, 0x05, 0xF6, 0xFC, 0xA2, 0x01, 0x4C, 0xFF, 0x2F,
2846 0x00, 0xFF, 0xFF, 0x07, 0x00, 0xE8, 0xFF, 0x12, 0x00, 0x42, 0x00,
2847 0xC4, 0xFE, 0x94, 0x03, 0x02, 0xF6, 0x89, 0x42, 0x76, 0x18, 0x5C,
2848 0xF5, 0x12, 0x06, 0x84, 0xFC, 0xD1, 0x01, 0x3B, 0xFF, 0x34, 0x00,
2849 0xFE, 0xFF, 0x02, 0x00, 0x03, 0x00, 0xCA, 0xFF, 0xD4, 0x00, 0xC8,
2850 0xFD, 0x2A, 0x05, 0x7D, 0xF3, 0xCA, 0x3D, 0x22, 0x20, 0x76, 0xF3,
2851 0xC8, 0x06, 0x41, 0xFC, 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD,
2852 0xFF, 0xFF, 0xFF, 0x19, 0x00, 0x8E, 0xFF, 0x49, 0x01, 0x04, 0xFD,
2853 0x4D, 0x06, 0x00, 0xF2, 0xFE, 0x37, 0xCB, 0x27, 0x21, 0xF2, 0x23,
2854 0x07, 0x34, 0xFC, 0xDD, 0x01, 0x3F, 0xFF, 0x34, 0x00, 0xFD, 0xFF,
2855 0xFD, 0xFF, 0x29, 0x00, 0x61, 0xFF, 0x9F, 0x01, 0x80, 0xFC, 0xF7,
2856 0x06, 0x7D, 0xF1, 0x5A, 0x31, 0x2C, 0x2F, 0x83, 0xF1, 0x13, 0x07,
2857 0x64, 0xFC, 0xB3, 0x01, 0x57, 0xFF, 0x2C, 0x00, 0xFD, 0xFF, 0xFD,
2858 0xFF, 0x32, 0x00, 0x44, 0xFF, 0xD3, 0x01, 0x3C, 0xFC, 0x2A, 0x07,
2859 0xDC, 0xF1, 0x1A, 0x2A, 0x06, 0x36, 0xBE, 0xF1, 0x8E, 0x06, 0xD5,
2860 0xFC, 0x67, 0x01, 0x7F, 0xFF, 0x1E, 0x00, 0xFE, 0xFF, 0xFD, 0xFF,
2861 0x36, 0x00, 0x37, 0xFF, 0xE6, 0x01, 0x36, 0xFC, 0xEF, 0x06, 0xFC,
2862 0xF2, 0x81, 0x22, 0x1C, 0x3C, 0xEC, 0xF2, 0x90, 0x05, 0x85, 0xFD,
2863 0xFB, 0x00, 0xB6, 0xFF, 0x0A, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x35,
2864 0x00, 0x38, 0xFF, 0xDA, 0x01, 0x6A, 0xFC, 0x53, 0x06, 0xBA, 0xF4,
2865 0xCE, 0x1A, 0x32, 0x41, 0x1F, 0xF5, 0x1D, 0x04, 0x71, 0xFE, 0x71,
2866 0x00, 0xFB, 0xFF, 0xF0, 0xFF, 0x05, 0x00, 0xFF, 0xFF, 0x31, 0x00,
2867 0x46, 0xFF, 0xB3, 0x01, 0xCF, 0xFC, 0x67, 0x05, 0xEA, 0xF6, 0x44,
2868 0x13, 0x1E, 0x45, 0x5E, 0xF8, 0x3F, 0x02, 0x8E, 0xFF, 0xD0, 0xFF,
2869 0x4A, 0x00, 0xD2, 0xFF, 0x0B, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x5D,
2870 0xFF, 0x76, 0x01, 0x59, 0xFD, 0x42, 0x04, 0x63, 0xF9, 0x1C, 0x0C,
2871 0xB6, 0x47, 0xA4, 0xFC, 0x07, 0x00, 0xD0, 0x00, 0x20, 0xFF, 0xA0,
2872 0x00, 0xB1, 0xFF, 0x13, 0x00, 0x00, 0x00, 0x21, 0x00, 0x7A, 0xFF,
2873 0x2B, 0x01, 0xFE, 0xFD, 0xF8, 0x02, 0xFB, 0xFB, 0x8D, 0x05, 0xE5,
2874 0x48, 0xE3, 0x01, 0x91, 0xFD, 0x25, 0x02, 0x6B, 0xFE, 0xF7, 0x00,
2875 0x8F, 0xFF, 0x1C, 0x00, 0x18, 0x00, 0x9C, 0xFF, 0xD6, 0x00, 0xB1,
2876 0xFE, 0xA1, 0x01, 0x89, 0xFE, 0xC3, 0xFF, 0x9C, 0x48, 0xFD, 0x07,
2877 0xFA, 0xFA, 0x7A, 0x03, 0xBC, 0xFD, 0x49, 0x01, 0x6E, 0xFF, 0x24,
2878 0x00, 0x00, 0x00, 0x10, 0x00, 0xBE, 0xFF, 0x7F, 0x00, 0x65, 0xFF,
2879 0x51, 0x00, 0xEB, 0x00, 0xE1, 0xFA, 0xE1, 0x46, 0xCD, 0x0E, 0x6A,
2880 0xF8, 0xB8, 0x04, 0x20, 0xFD, 0x90, 0x01, 0x53, 0xFF, 0x2D, 0x00,
2881 0xFF, 0xFF, 0x09, 0x00, 0xDE, 0xFF, 0x2B, 0x00, 0x11, 0x00, 0x1B,
2882 0xFF, 0x02, 0x03, 0xFE, 0xF6, 0xC3, 0x43, 0x22, 0x16, 0x07, 0xF6,
2883 0xCA, 0x05, 0xA3, 0xFC, 0xC5, 0x01, 0x3F, 0xFF, 0x33, 0x00, 0xFF,
2884 0xFF, 0x03, 0x00, 0xFB, 0xFF, 0xDF, 0xFF, 0xA9, 0x00, 0x10, 0xFE,
2885 0xB9, 0x04, 0x27, 0xF4, 0x5E, 0x3F, 0xC3, 0x1D, 0xFE, 0xF3, 0x99,
2886 0x06, 0x50, 0xFC, 0xE2, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF,
2887 0x00, 0x00, 0x13, 0x00, 0x9F, 0xFF, 0x28, 0x01, 0x3A, 0xFD, 0x00,
2888 0x06, 0x5A, 0xF2, 0xDF, 0x39, 0x73, 0x25, 0x79, 0xF2, 0x12, 0x07,
2889 0x31, 0xFC, 0xE3, 0x01, 0x3B, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0xFD,
2890 0xFF, 0x24, 0x00, 0x6D, 0xFF, 0x88, 0x01, 0xA2, 0xFC, 0xD0, 0x06,
2891 0x8C, 0xF1, 0x78, 0x33, 0xF2, 0x2C, 0x9E, 0xF1, 0x24, 0x07, 0x4E,
2892 0xFC, 0xC3, 0x01, 0x4E, 0xFF, 0x2F, 0x00, 0xFD, 0xFF, 0xFD, 0xFF,
2893 0x30, 0x00, 0x4C, 0xFF, 0xC7, 0x01, 0x4A, 0xFC, 0x27, 0x07, 0xA8,
2894 0xF1, 0x62, 0x2C, 0xFD, 0x33, 0x93, 0xF1, 0xC4, 0x06, 0xAB, 0xFC,
2895 0x82, 0x01, 0x71, 0xFF, 0x23, 0x00, 0xFE, 0xFF, 0xFD, 0xFF, 0x36,
2896 0x00, 0x3A, 0xFF, 0xE4, 0x01, 0x32, 0xFC, 0x0C, 0x07, 0x91, 0xF2,
2897 0xDD, 0x24, 0x54, 0x3A, 0x74, 0xF2, 0xEB, 0x05, 0x49, 0xFD, 0x20,
2898 0x01, 0xA3, 0xFF, 0x11, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x36, 0x00,
2899 0x37, 0xFF, 0xE1, 0x01, 0x55, 0xFC, 0x8C, 0x06, 0x22, 0xF4, 0x2C,
2900 0x1D, 0xC0, 0x3F, 0x55, 0xF4, 0x9B, 0x04, 0x23, 0xFE, 0x9F, 0x00,
2901 0xE4, 0xFF, 0xF9, 0xFF, 0x04, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0x40,
2902 0xFF, 0xC1, 0x01, 0xAB, 0xFC, 0xB7, 0x05, 0x34, 0xF6, 0x8E, 0x15,
2903 0x0B, 0x44, 0x42, 0xF7, 0xDC, 0x02, 0x32, 0xFF, 0x04, 0x00, 0x31,
2904 0x00, 0xDC, 0xFF, 0x09, 0x00, 0xFF, 0xFF, 0x2C, 0x00, 0x55, 0xFF,
2905 0x8B, 0x01, 0x2B, 0xFD, 0xA1, 0x04, 0x9B, 0xF8, 0x42, 0x0E, 0x0F,
2906 0x47, 0x38, 0xFB, 0xBE, 0x00, 0x6A, 0x00, 0x58, 0xFF, 0x85, 0x00,
2907 0xBB, 0xFF, 0x10, 0x00, 0x00, 0x00, 0x24, 0x00, 0x71, 0xFF, 0x43,
2908 0x01, 0xC9, 0xFD, 0x60, 0x03, 0x2E, 0xFB, 0x7E, 0x07, 0xAF, 0x48,
2909 0x2D, 0x00, 0x58, 0xFE, 0xBB, 0x01, 0xA3, 0xFE, 0xDD, 0x00, 0x99,
2910 0xFF, 0x19, 0x00, 0x1B, 0x00, 0x91, 0xFF, 0xF1, 0x00, 0x79, 0xFE,
2911 0x0A, 0x02, 0xC3, 0xFD, 0x73, 0x01, 0xDB, 0x48, 0x07, 0x06, 0xC7,
2912 0xFB, 0x12, 0x03, 0xF1, 0xFD, 0x31, 0x01, 0x78, 0xFF, 0x22, 0x00,
2913 0x00, 0x00, 0x12, 0x00, 0xB3, 0xFF, 0x99, 0x00, 0x2E, 0xFF, 0xB6,
2914 0x00, 0x36, 0x00, 0x47, 0xFC, 0x90, 0x47, 0xA4, 0x0C, 0x31, 0xF9,
2915 0x5A, 0x04, 0x4E, 0xFD, 0x7C, 0x01, 0x5B, 0xFF, 0x2A, 0x00, 0x00,
2916 0x00, 0x0B, 0x00, 0xD5, 0xFF, 0x44, 0x00, 0xDD, 0xFF, 0x77, 0xFF,
2917 0x67, 0x02, 0x14, 0xF8, 0xDC, 0x44, 0xD5, 0x13, 0xBC, 0xF6, 0x7C,
2918 0x05, 0xC5, 0xFC, 0xB7, 0x01, 0x44, 0xFF, 0x31, 0x00, 0xFF, 0xFF,
2919 0x05, 0x00, 0xF3, 0xFF, 0xF5, 0xFF, 0x7D, 0x00, 0x5D, 0xFE, 0x3E,
2920 0x04, 0xEA, 0xF4, 0xD9, 0x40, 0x66, 0x1B, 0x93, 0xF4, 0x62, 0x06,
2921 0x64, 0xFC, 0xDC, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x00,
2922 0x00, 0x0C, 0x00, 0xB1, 0xFF, 0x04, 0x01, 0x76, 0xFD, 0xA8, 0x05,
2923 0xCC, 0xF2, 0xAB, 0x3B, 0x18, 0x23, 0xE0, 0xF2, 0xF7, 0x06, 0x35,
2924 0xFC, 0xE6, 0x01, 0x38, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFE, 0xFF,
2925 0x20, 0x00, 0x7B, 0xFF, 0x6E, 0x01, 0xCA, 0xFC, 0x9D, 0x06, 0xB1,
2926 0xF1, 0x86, 0x35, 0xAE, 0x2A, 0xCD, 0xF1, 0x2B, 0x07, 0x3F, 0xFC,
2927 0xD1, 0x01, 0x46, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x2D,
2928 0x00, 0x54, 0xFF, 0xB7, 0x01, 0x5E, 0xFC, 0x19, 0x07, 0x88, 0xF1,
2929 0x9F, 0x2E, 0xE3, 0x31, 0x7E, 0xF1, 0xEE, 0x06, 0x88, 0xFC, 0x9A,
2930 0x01, 0x64, 0xFF, 0x28, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x34, 0x00,
2931 0x3E, 0xFF, 0xDF, 0x01, 0x33, 0xFC, 0x20, 0x07, 0x35, 0xF2, 0x36,
2932 0x27, 0x78, 0x38, 0x14, 0xF2, 0x3B, 0x06, 0x11, 0xFD, 0x41, 0x01,
2933 0x92, 0xFF, 0x17, 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x36,
2934 0xFF, 0xE5, 0x01, 0x44, 0xFC, 0xBD, 0x06, 0x97, 0xF3, 0x8A, 0x1F,
2935 0x31, 0x3E, 0xA5, 0xF3, 0x0F, 0x05, 0xDA, 0xFD, 0xC9, 0x00, 0xCF,
2936 0xFF, 0x01, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3C, 0xFF,
2937 0xCE, 0x01, 0x8C, 0xFC, 0x00, 0x06, 0x86, 0xF5, 0xE0, 0x17, 0xDB,
2938 0x42, 0x3F, 0xF6, 0x71, 0x03, 0xD9, 0xFE, 0x36, 0x00, 0x18, 0x00,
2939 0xE5, 0xFF, 0x07, 0x00, 0xFF, 0xFF, 0x2E, 0x00, 0x4E, 0xFF, 0x9E,
2940 0x01, 0x00, 0xFD, 0xFC, 0x04, 0xD7, 0xF7, 0x75, 0x10, 0x48, 0x46,
2941 0xE4, 0xF9, 0x6E, 0x01, 0x06, 0x00, 0x8E, 0xFF, 0x6B, 0x00, 0xC6,
2942 0xFF, 0x0E, 0x00, 0x00, 0x00, 0x26, 0x00, 0x68, 0xFF, 0x5B, 0x01,
2943 0x96, 0xFD, 0xC6, 0x03, 0x61, 0xFA, 0x81, 0x09, 0x57, 0x48, 0x8D,
2944 0xFE, 0x1B, 0xFF, 0x52, 0x01, 0xDB, 0xFE, 0xC2, 0x00, 0xA4, 0xFF,
2945 0x16, 0x00, 0x1E, 0x00, 0x87, 0xFF, 0x0B, 0x01, 0x42, 0xFE, 0x74,
2946 0x02, 0xF9, 0xFC, 0x39, 0x03, 0xF5, 0x48, 0x24, 0x04, 0x94, 0xFC,
2947 0xA9, 0x02, 0x27, 0xFE, 0x18, 0x01, 0x82, 0xFF, 0x1F, 0x00, 0x00,
2948 0x00, 0x15, 0x00, 0xA9, 0xFF, 0xB4, 0x00, 0xF7, 0xFE, 0x1D, 0x01,
2949 0x7A, 0xFF, 0xC5, 0xFD, 0x1D, 0x48, 0x89, 0x0A, 0xFB, 0xF9, 0xF8,
2950 0x03, 0x7D, 0xFD, 0x66, 0x01, 0x63, 0xFF, 0x28, 0x00, 0x00, 0x00,
2951 0x0D, 0x00, 0xCB, 0xFF, 0x5E, 0x00, 0xA9, 0xFF, 0xD6, 0xFF, 0xC3,
2952 0x01, 0x43, 0xF9, 0xD7, 0x45, 0x92, 0x11, 0x77, 0xF7, 0x28, 0x05,
2953 0xEC, 0xFC, 0xA7, 0x01, 0x4A, 0xFF, 0x2F, 0x00, 0xFF, 0xFF, 0x06,
2954 0x00, 0xEA, 0xFF, 0x0C, 0x00, 0x4E, 0x00, 0xAF, 0xFE, 0xB8, 0x03,
2955 0xC7, 0xF5, 0x38, 0x42, 0x0C, 0x19, 0x32, 0xF5, 0x23, 0x06, 0x7D,
2956 0xFC, 0xD3, 0x01, 0x3A, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x02, 0x00,
2957 0x05, 0x00, 0xC5, 0xFF, 0xDE, 0x00, 0xB7, 0xFD, 0x45, 0x05, 0x56,
2958 0xF3, 0x61, 0x3D, 0xBA, 0x20, 0x56, 0xF3, 0xD3, 0x06, 0x3E, 0xFC,
2959 0xE6, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFF, 0xFF, 0x1A,
2960 0x00, 0x8A, 0xFF, 0x51, 0x01, 0xF8, 0xFC, 0x5E, 0x06, 0xED, 0xF1,
2961 0x82, 0x37, 0x60, 0x28, 0x0E, 0xF2, 0x26, 0x07, 0x35, 0xFC, 0xDB,
2962 0x01, 0x40, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x29, 0x00,
2963 0x5F, 0xFF, 0xA5, 0x01, 0x78, 0xFC, 0xFF, 0x06, 0x7D, 0xF1, 0xCF,
2964 0x30, 0xB8, 0x2F, 0x80, 0xF1, 0x0D, 0x07, 0x6A, 0xFC, 0xAE, 0x01,
2965 0x59, 0xFF, 0x2B, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x33, 0x00, 0x43,
2966 0xFF, 0xD6, 0x01, 0x39, 0xFC, 0x2A, 0x07, 0xEB, 0xF1, 0x87, 0x29,
2967 0x85, 0x36, 0xCC, 0xF1, 0x7F, 0x06, 0xE0, 0xFC, 0x60, 0x01, 0x82,
2968 0xFF, 0x1D, 0x00, 0xFE, 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x37, 0xFF,
2969 0xE6, 0x01, 0x38, 0xFC, 0xE6, 0x06, 0x19, 0xF3, 0xEA, 0x21, 0x8A,
2970 0x3C, 0x0E, 0xF3, 0x78, 0x05, 0x96, 0xFD, 0xF1, 0x00, 0xBB, 0xFF,
2971 0x08, 0x00, 0x01, 0x00, 0xFE, 0xFF, 0x35, 0x00, 0x39, 0xFF, 0xD8,
2972 0x01, 0x70, 0xFC, 0x43, 0x06, 0xE1, 0xF4, 0x38, 0x1A, 0x8C, 0x41,
2973 0x55, 0xF5, 0xFC, 0x03, 0x85, 0xFE, 0x66, 0x00, 0x01, 0x00, 0xEE,
2974 0xFF, 0x06, 0x00, 0xFF, 0xFF, 0x30, 0x00, 0x47, 0xFF, 0xAF, 0x01,
2975 0xD8, 0xFC, 0x52, 0x05, 0x19, 0xF7, 0xB2, 0x12, 0x5C, 0x45, 0xA9,
2976 0xF8, 0x16, 0x02, 0xA6, 0xFF, 0xC3, 0xFF, 0x51, 0x00, 0xD0, 0xFF,
2977 0x0C, 0x00, 0x00, 0x00, 0x29, 0x00, 0x5F, 0xFF, 0x71, 0x01, 0x65,
2978 0xFD, 0x29, 0x04, 0x96, 0xF9, 0x95, 0x0B, 0xDC, 0x47, 0x03, 0xFD,
2979 0xD9, 0xFF, 0xEA, 0x00, 0x12, 0xFF, 0xA7, 0x00, 0xAE, 0xFF, 0x14,
2980 0x00, 0x00, 0x00, 0x20, 0x00, 0x7D, 0xFF, 0x24, 0x01, 0x0C, 0xFE,
2981 0xDE, 0x02, 0x2E, 0xFC, 0x13, 0x05, 0xEC, 0x48, 0x54, 0x02, 0x5E,
2982 0xFD, 0x3F, 0x02, 0x5D, 0xFE, 0xFE, 0x00, 0x8C, 0xFF, 0x1C, 0x00,
2983 0x17, 0x00, 0x9E, 0xFF, 0xCF, 0x00, 0xBF, 0xFE, 0x86, 0x01, 0xBA,
2984 0xFE, 0x5A, 0xFF, 0x86, 0x48, 0x7D, 0x08, 0xC7, 0xFA, 0x93, 0x03,
2985 0xB0, 0xFD, 0x4F, 0x01, 0x6C, 0xFF, 0x25, 0x00, 0x00, 0x00, 0x0F,
2986 0x00, 0xC0, 0xFF, 0x78, 0x00, 0x73, 0xFF, 0x38, 0x00, 0x17, 0x01,
2987 0x8B, 0xFA, 0xAF, 0x46, 0x59, 0x0F, 0x39, 0xF8, 0xCF, 0x04, 0x15,
2988 0xFD, 0x95, 0x01, 0x51, 0xFF, 0x2D, 0x00, 0xFF, 0xFF, 0x08, 0x00,
2989 0xE1, 0xFF, 0x25, 0x00, 0x1D, 0x00, 0x05, 0xFF, 0x28, 0x03, 0xBD,
2990 0xF6, 0x77, 0x43, 0xB6, 0x16, 0xDC, 0xF5, 0xDD, 0x05, 0x9B, 0xFC,
2991 0xC8, 0x01, 0x3E, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0xFD,
2992 0xFF, 0xD9, 0xFF, 0xB4, 0x00, 0xFD, 0xFD, 0xD7, 0x04, 0xFA, 0xF3,
2993 0xFC, 0x3E, 0x5B, 0x1E, 0xDB, 0xF3, 0xA6, 0x06, 0x4C, 0xFC, 0xE3,
2994 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x14, 0x00,
2995 0x9B, 0xFF, 0x31, 0x01, 0x2C, 0xFD, 0x15, 0x06, 0x41, 0xF2, 0x6A,
2996 0x39, 0x0A, 0x26, 0x61, 0xF2, 0x17, 0x07, 0x31, 0xFC, 0xE2, 0x01,
2997 0x3B, 0xFF, 0x35, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x25, 0x00, 0x6A,
2998 0xFF, 0x8E, 0x01, 0x99, 0xFC, 0xDB, 0x06, 0x86, 0xF1, 0xF2, 0x32,
2999 0x82, 0x2D, 0x96, 0xF1, 0x21, 0x07, 0x53, 0xFC, 0xC0, 0x01, 0x50,
3000 0xFF, 0x2E, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x30, 0x00, 0x4A, 0xFF,
3001 0xCA, 0x01, 0x46, 0xFC, 0x29, 0x07, 0xB3, 0xF1, 0xD1, 0x2B, 0x81,
3002 0x34, 0x9C, 0xF1, 0xB8, 0x06, 0xB5, 0xFC, 0x7C, 0x01, 0x74, 0xFF,
3003 0x22, 0x00, 0xFE, 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x39, 0xFF, 0xE5,
3004 0x01, 0x32, 0xFC, 0x06, 0x07, 0xAA, 0xF2, 0x46, 0x24, 0xC8, 0x3A,
3005 0x90, 0xF2, 0xD6, 0x05, 0x57, 0xFD, 0x17, 0x01, 0xA8, 0xFF, 0x0F,
3006 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xDF, 0x01,
3007 0x5A, 0xFC, 0x7E, 0x06, 0x47, 0xF4, 0x94, 0x1C, 0x1F, 0x40, 0x85,
3008 0xF4, 0x7D, 0x04, 0x36, 0xFE, 0x93, 0x00, 0xEA, 0xFF, 0xF7, 0xFF,
3009 0x04, 0x00, 0xFF, 0xFF, 0x32, 0x00, 0x42, 0xFF, 0xBE, 0x01, 0xB4,
3010 0xFC, 0xA4, 0x05, 0x61, 0xF6, 0xFB, 0x14, 0x53, 0x44, 0x86, 0xF7,
3011 0xB6, 0x02, 0x49, 0xFF, 0xF7, 0xFF, 0x37, 0x00, 0xD9, 0xFF, 0x0A,
3012 0x00, 0x00, 0x00, 0x2B, 0x00, 0x57, 0xFF, 0x86, 0x01, 0x36, 0xFD,
3013 0x89, 0x04, 0xCD, 0xF8, 0xB7, 0x0D, 0x3D, 0x47, 0x91, 0xFB, 0x91,
3014 0x00, 0x83, 0x00, 0x4A, 0xFF, 0x8C, 0x00, 0xB9, 0xFF, 0x11, 0x00,
3015 0x00, 0x00, 0x23, 0x00, 0x73, 0xFF, 0x3D, 0x01, 0xD6, 0xFD, 0x46,
3016 0x03, 0x61, 0xFB, 0x00, 0x07, 0xBF, 0x48, 0x98, 0x00, 0x26, 0xFE,
3017 0xD5, 0x01, 0x95, 0xFE, 0xE3, 0x00, 0x96, 0xFF, 0x1A, 0x00, 0x1A,
3018 0x00, 0x94, 0xFF, 0xEA, 0x00, 0x87, 0xFE, 0xF0, 0x01, 0xF5, 0xFD,
3019 0x05, 0x01, 0xCE, 0x48, 0x83, 0x06, 0x94, 0xFB, 0x2C, 0x03, 0xE4,
3020 0xFD, 0x37, 0x01, 0x76, 0xFF, 0x22, 0x00, 0x00, 0x00, 0x12, 0x00,
3021 0xB6, 0xFF, 0x93, 0x00, 0x3C, 0xFF, 0x9D, 0x00, 0x63, 0x00, 0xEB,
3022 0xFB, 0x69, 0x47, 0x2D, 0x0D, 0xFF, 0xF8, 0x72, 0x04, 0x42, 0xFD,
3023 0x81, 0x01, 0x59, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0x0A, 0x00, 0xD7,
3024 0xFF, 0x3E, 0x00, 0xEA, 0xFF, 0x60, 0xFF, 0x8F, 0x02, 0xCD, 0xF7,
3025 0x99, 0x44, 0x68, 0x14, 0x8E, 0xF6, 0x90, 0x05, 0xBC, 0xFC, 0xBA,
3026 0x01, 0x43, 0xFF, 0x32, 0x00, 0xFF, 0xFF, 0x04, 0x00, 0xF5, 0xFF,
3027 0xEF, 0xFF, 0x88, 0x00, 0x49, 0xFE, 0x5D, 0x04, 0xB7, 0xF4, 0x7D,
3028 0x40, 0xFD, 0x1B, 0x6C, 0xF4, 0x70, 0x06, 0x5F, 0xFC, 0xDE, 0x01,
3029 0x37, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x00, 0x00, 0x0E, 0x00, 0xAC,
3030 0xFF, 0x0E, 0x01, 0x66, 0xFD, 0xBF, 0x05, 0xAD, 0xF2, 0x3B, 0x3B,
3031 0xB0, 0x23, 0xC4, 0xF2, 0xFF, 0x06, 0x33, 0xFC, 0xE5, 0x01, 0x38,
3032 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFE, 0xFF, 0x21, 0x00, 0x77, 0xFF,
3033 0x75, 0x01, 0xBF, 0xFC, 0xAB, 0x06, 0xA6, 0xF1, 0x05, 0x35, 0x40,
3034 0x2B, 0xBF, 0xF1, 0x2A, 0x07, 0x42, 0xFC, 0xCE, 0x01, 0x48, 0xFF,
3035 0x31, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x2E, 0x00, 0x52, 0xFF, 0xBC,
3036 0x01, 0x58, 0xFC, 0x1D, 0x07, 0x8E, 0xF1, 0x11, 0x2E, 0x6B, 0x32,
3037 0x81, 0xF1, 0xE5, 0x06, 0x90, 0xFC, 0x94, 0x01, 0x67, 0xFF, 0x26,
3038 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x35, 0x00, 0x3C, 0xFF, 0xE0, 0x01,
3039 0x32, 0xFC, 0x1C, 0x07, 0x4B, 0xF2, 0xA0, 0x26, 0xF2, 0x38, 0x2A,
3040 0xF2, 0x28, 0x06, 0x1F, 0xFD, 0x39, 0x01, 0x96, 0xFF, 0x16, 0x00,
3041 0xFF, 0xFF, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE4, 0x01, 0x48,
3042 0xFC, 0xB2, 0x06, 0xB9, 0xF3, 0xF3, 0x1E, 0x98, 0x3E, 0xCF, 0xF3,
3043 0xF3, 0x04, 0xEB, 0xFD, 0xBF, 0x00, 0xD4, 0xFF, 0xFF, 0xFF, 0x03,
3044 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3D, 0xFF, 0xCB, 0x01, 0x93, 0xFC,
3045 0xEF, 0x05, 0xB0, 0xF5, 0x4B, 0x17, 0x2A, 0x43, 0x7D, 0xF6, 0x4D,
3046 0x03, 0xEF, 0xFE, 0x2A, 0x00, 0x1E, 0x00, 0xE3, 0xFF, 0x08, 0x00,
3047 0xFF, 0xFF, 0x2E, 0x00, 0x4F, 0xFF, 0x99, 0x01, 0x0B, 0xFD, 0xE6,
3048 0x04, 0x08, 0xF8, 0xE7, 0x0F, 0x7C, 0x46, 0x37, 0xFA, 0x42, 0x01,
3049 0x1F, 0x00, 0x81, 0xFF, 0x71, 0x00, 0xC3, 0xFF, 0x0F, 0x00, 0x00,
3050 0x00, 0x26, 0x00, 0x6A, 0xFF, 0x55, 0x01, 0xA3, 0xFD, 0xAD, 0x03,
3051 0x94, 0xFA, 0xFF, 0x08, 0x70, 0x48, 0xF3, 0xFE, 0xEA, 0xFE, 0x6C,
3052 0x01, 0xCD, 0xFE, 0xC9, 0x00, 0xA1, 0xFF, 0x17, 0x00, 0x1D, 0x00,
3053 0x8A, 0xFF, 0x04, 0x01, 0x50, 0xFE, 0x5A, 0x02, 0x2C, 0xFD, 0xC6,
3054 0x02, 0xF2, 0x48, 0x9B, 0x04, 0x61, 0xFC, 0xC3, 0x02, 0x19, 0xFE,
3055 0x1E, 0x01, 0x7F, 0xFF, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0xAC,
3056 0xFF, 0xAE, 0x00, 0x05, 0xFF, 0x03, 0x01, 0xAA, 0xFF, 0x63, 0xFD,
3057 0xFD, 0x47, 0x0E, 0x0B, 0xC8, 0xF9, 0x11, 0x04, 0x71, 0xFD, 0x6C,
3058 0x01, 0x61, 0xFF, 0x28, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xCD, 0xFF,
3059 0x57, 0x00, 0xB6, 0xFF, 0xBE, 0xFF, 0xED, 0x01, 0xF5, 0xF8, 0x9B,
3060 0x45, 0x22, 0x12, 0x48, 0xF7, 0x3D, 0x05, 0xE2, 0xFC, 0xAB, 0x01,
3061 0x49, 0xFF, 0x30, 0x00, 0xFF, 0xFF, 0x06, 0x00, 0xEC, 0xFF, 0x06,
3062 0x00, 0x5A, 0x00, 0x9A, 0xFE, 0xDA, 0x03, 0x8D, 0xF5, 0xE1, 0x41,
3063 0xA1, 0x19, 0x09, 0xF5, 0x33, 0x06, 0x77, 0xFC, 0xD6, 0x01, 0x3A,
3064 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF,
3065 0xE8, 0x00, 0xA6, 0xFD, 0x5F, 0x05, 0x31, 0xF3, 0xF6, 0x3C, 0x52,
3066 0x21, 0x37, 0xF3, 0xDD, 0x06, 0x3B, 0xFC, 0xE6, 0x01, 0x36, 0xFF,
3067 0x36, 0x00, 0xFD, 0xFF, 0xFE, 0xFF, 0x1C, 0x00, 0x86, 0xFF, 0x59,
3068 0x01, 0xEC, 0xFC, 0x6F, 0x06, 0xDC, 0xF1, 0x04, 0x37, 0xF3, 0x28,
3069 0xFC, 0xF1, 0x28, 0x07, 0x37, 0xFC, 0xD8, 0x01, 0x41, 0xFF, 0x33,
3070 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x2A, 0x00, 0x5C, 0xFF, 0xAA, 0x01,
3071 0x71, 0xFC, 0x07, 0x07, 0x7E, 0xF1, 0x44, 0x30, 0x44, 0x30, 0x7E,
3072 0xF1, 0x07, 0x07, 0x71, 0xFC, 0xAA, 0x01, 0x5C, 0xFF, 0x2A, 0x00,
3073 0xFD, 0xFF, 0xFD, 0xFF, 0x33, 0x00, 0x41, 0xFF, 0xD8, 0x01, 0x37,
3074 0xFC, 0x28, 0x07, 0xFC, 0xF1, 0xF3, 0x28, 0x04, 0x37, 0xDC, 0xF1,
3075 0x6F, 0x06, 0xEC, 0xFC, 0x59, 0x01, 0x86, 0xFF, 0x1C, 0x00, 0xFE,
3076 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3B, 0xFC,
3077 0xDD, 0x06, 0x37, 0xF3, 0x52, 0x21, 0xF6, 0x3C, 0x31, 0xF3, 0x5F,
3078 0x05, 0xA6, 0xFD, 0xE8, 0x00, 0xC0, 0xFF, 0x07, 0x00, 0x01, 0x00,
3079 0xFE, 0xFF, 0x35, 0x00, 0x3A, 0xFF, 0xD6, 0x01, 0x77, 0xFC, 0x33,
3080 0x06, 0x09, 0xF5, 0xA1, 0x19, 0xE1, 0x41, 0x8D, 0xF5, 0xDA, 0x03,
3081 0x9A, 0xFE, 0x5A, 0x00, 0x06, 0x00, 0xEC, 0xFF, 0x06, 0x00, 0xFF,
3082 0xFF, 0x30, 0x00, 0x49, 0xFF, 0xAB, 0x01, 0xE2, 0xFC, 0x3D, 0x05,
3083 0x48, 0xF7, 0x22, 0x12, 0x9B, 0x45, 0xF5, 0xF8, 0xED, 0x01, 0xBE,
3084 0xFF, 0xB6, 0xFF, 0x57, 0x00, 0xCD, 0xFF, 0x0C, 0x00, 0x00, 0x00,
3085 0x28, 0x00, 0x61, 0xFF, 0x6C, 0x01, 0x71, 0xFD, 0x11, 0x04, 0xC8,
3086 0xF9, 0x0E, 0x0B, 0xFD, 0x47, 0x63, 0xFD, 0xAA, 0xFF, 0x03, 0x01,
3087 0x05, 0xFF, 0xAE, 0x00, 0xAC, 0xFF, 0x14, 0x00, 0x00, 0x00, 0x20,
3088 0x00, 0x7F, 0xFF, 0x1E, 0x01, 0x19, 0xFE, 0xC3, 0x02, 0x61, 0xFC,
3089 0x9B, 0x04, 0xF2, 0x48, 0xC6, 0x02, 0x2C, 0xFD, 0x5A, 0x02, 0x50,
3090 0xFE, 0x04, 0x01, 0x8A, 0xFF, 0x1D, 0x00, 0x17, 0x00, 0xA1, 0xFF,
3091 0xC9, 0x00, 0xCD, 0xFE, 0x6C, 0x01, 0xEA, 0xFE, 0xF3, 0xFE, 0x70,
3092 0x48, 0xFF, 0x08, 0x94, 0xFA, 0xAD, 0x03, 0xA3, 0xFD, 0x55, 0x01,
3093 0x6A, 0xFF, 0x26, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xC3, 0xFF, 0x71,
3094 0x00, 0x81, 0xFF, 0x1F, 0x00, 0x42, 0x01, 0x37, 0xFA, 0x7C, 0x46,
3095 0xE7, 0x0F, 0x08, 0xF8, 0xE6, 0x04, 0x0B, 0xFD, 0x99, 0x01, 0x4F,
3096 0xFF, 0x2E, 0x00, 0xFF, 0xFF, 0x08, 0x00, 0xE3, 0xFF, 0x1E, 0x00,
3097 0x2A, 0x00, 0xEF, 0xFE, 0x4D, 0x03, 0x7D, 0xF6, 0x2A, 0x43, 0x4B,
3098 0x17, 0xB0, 0xF5, 0xEF, 0x05, 0x93, 0xFC, 0xCB, 0x01, 0x3D, 0xFF,
3099 0x34, 0x00, 0xFE, 0xFF, 0x03, 0x00, 0xFF, 0xFF, 0xD4, 0xFF, 0xBF,
3100 0x00, 0xEB, 0xFD, 0xF3, 0x04, 0xCF, 0xF3, 0x98, 0x3E, 0xF3, 0x1E,
3101 0xB9, 0xF3, 0xB2, 0x06, 0x48, 0xFC, 0xE4, 0x01, 0x36, 0xFF, 0x36,
3102 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0x16, 0x00, 0x96, 0xFF, 0x39, 0x01,
3103 0x1F, 0xFD, 0x28, 0x06, 0x2A, 0xF2, 0xF2, 0x38, 0xA0, 0x26, 0x4B,
3104 0xF2, 0x1C, 0x07, 0x32, 0xFC, 0xE0, 0x01, 0x3C, 0xFF, 0x35, 0x00,
3105 0xFD, 0xFF, 0xFD, 0xFF, 0x26, 0x00, 0x67, 0xFF, 0x94, 0x01, 0x90,
3106 0xFC, 0xE5, 0x06, 0x81, 0xF1, 0x6B, 0x32, 0x11, 0x2E, 0x8E, 0xF1,
3107 0x1D, 0x07, 0x58, 0xFC, 0xBC, 0x01, 0x52, 0xFF, 0x2E, 0x00, 0xFD,
3108 0xFF, 0xFD, 0xFF, 0x31, 0x00, 0x48, 0xFF, 0xCE, 0x01, 0x42, 0xFC,
3109 0x2A, 0x07, 0xBF, 0xF1, 0x40, 0x2B, 0x05, 0x35, 0xA6, 0xF1, 0xAB,
3110 0x06, 0xBF, 0xFC, 0x75, 0x01, 0x77, 0xFF, 0x21, 0x00, 0xFE, 0xFF,
3111 0xFD, 0xFF, 0x36, 0x00, 0x38, 0xFF, 0xE5, 0x01, 0x33, 0xFC, 0xFF,
3112 0x06, 0xC4, 0xF2, 0xB0, 0x23, 0x3B, 0x3B, 0xAD, 0xF2, 0xBF, 0x05,
3113 0x66, 0xFD, 0x0E, 0x01, 0xAC, 0xFF, 0x0E, 0x00, 0x00, 0x00, 0xFE,
3114 0xFF, 0x36, 0x00, 0x37, 0xFF, 0xDE, 0x01, 0x5F, 0xFC, 0x70, 0x06,
3115 0x6C, 0xF4, 0xFD, 0x1B, 0x7D, 0x40, 0xB7, 0xF4, 0x5D, 0x04, 0x49,
3116 0xFE, 0x88, 0x00, 0xEF, 0xFF, 0xF5, 0xFF, 0x04, 0x00, 0xFF, 0xFF,
3117 0x32, 0x00, 0x43, 0xFF, 0xBA, 0x01, 0xBC, 0xFC, 0x90, 0x05, 0x8E,
3118 0xF6, 0x68, 0x14, 0x99, 0x44, 0xCD, 0xF7, 0x8F, 0x02, 0x60, 0xFF,
3119 0xEA, 0xFF, 0x3E, 0x00, 0xD7, 0xFF, 0x0A, 0x00, 0x00, 0x00, 0x2B,
3120 0x00, 0x59, 0xFF, 0x81, 0x01, 0x42, 0xFD, 0x72, 0x04, 0xFF, 0xF8,
3121 0x2D, 0x0D, 0x69, 0x47, 0xEB, 0xFB, 0x63, 0x00, 0x9D, 0x00, 0x3C,
3122 0xFF, 0x93, 0x00, 0xB6, 0xFF, 0x12, 0x00, 0x00, 0x00, 0x22, 0x00,
3123 0x76, 0xFF, 0x37, 0x01, 0xE4, 0xFD, 0x2C, 0x03, 0x94, 0xFB, 0x83,
3124 0x06, 0xCE, 0x48, 0x05, 0x01, 0xF5, 0xFD, 0xF0, 0x01, 0x87, 0xFE,
3125 0xEA, 0x00, 0x94, 0xFF, 0x1A, 0x00, 0x1A, 0x00, 0x96, 0xFF, 0xE3,
3126 0x00, 0x95, 0xFE, 0xD5, 0x01, 0x26, 0xFE, 0x98, 0x00, 0xBF, 0x48,
3127 0x00, 0x07, 0x61, 0xFB, 0x46, 0x03, 0xD6, 0xFD, 0x3D, 0x01, 0x73,
3128 0xFF, 0x23, 0x00, 0x00, 0x00, 0x11, 0x00, 0xB9, 0xFF, 0x8C, 0x00,
3129 0x4A, 0xFF, 0x83, 0x00, 0x91, 0x00, 0x91, 0xFB, 0x3D, 0x47, 0xB7,
3130 0x0D, 0xCD, 0xF8, 0x89, 0x04, 0x36, 0xFD, 0x86, 0x01, 0x57, 0xFF,
3131 0x2B, 0x00, 0x00, 0x00, 0x0A, 0x00, 0xD9, 0xFF, 0x37, 0x00, 0xF7,
3132 0xFF, 0x49, 0xFF, 0xB6, 0x02, 0x86, 0xF7, 0x53, 0x44, 0xFB, 0x14,
3133 0x61, 0xF6, 0xA4, 0x05, 0xB4, 0xFC, 0xBE, 0x01, 0x42, 0xFF, 0x32,
3134 0x00, 0xFF, 0xFF, 0x04, 0x00, 0xF7, 0xFF, 0xEA, 0xFF, 0x93, 0x00,
3135 0x36, 0xFE, 0x7D, 0x04, 0x85, 0xF4, 0x1F, 0x40, 0x94, 0x1C, 0x47,
3136 0xF4, 0x7E, 0x06, 0x5A, 0xFC, 0xDF, 0x01, 0x37, 0xFF, 0x36, 0x00,
3137 0xFE, 0xFF, 0x00, 0x00, 0x0F, 0x00, 0xA8, 0xFF, 0x17, 0x01, 0x57,
3138 0xFD, 0xD6, 0x05, 0x90, 0xF2, 0xC8, 0x3A, 0x46, 0x24, 0xAA, 0xF2,
3139 0x06, 0x07, 0x32, 0xFC, 0xE5, 0x01, 0x39, 0xFF, 0x36, 0x00, 0xFD,
3140 0xFF, 0xFE, 0xFF, 0x22, 0x00, 0x74, 0xFF, 0x7C, 0x01, 0xB5, 0xFC,
3141 0xB8, 0x06, 0x9C, 0xF1, 0x81, 0x34, 0xD1, 0x2B, 0xB3, 0xF1, 0x29,
3142 0x07, 0x46, 0xFC, 0xCA, 0x01, 0x4A, 0xFF, 0x30, 0x00, 0xFD, 0xFF,
3143 0xFD, 0xFF, 0x2E, 0x00, 0x50, 0xFF, 0xC0, 0x01, 0x53, 0xFC, 0x21,
3144 0x07, 0x96, 0xF1, 0x82, 0x2D, 0xF2, 0x32, 0x86, 0xF1, 0xDB, 0x06,
3145 0x99, 0xFC, 0x8E, 0x01, 0x6A, 0xFF, 0x25, 0x00, 0xFD, 0xFF, 0xFD,
3146 0xFF, 0x35, 0x00, 0x3B, 0xFF, 0xE2, 0x01, 0x31, 0xFC, 0x17, 0x07,
3147 0x61, 0xF2, 0x0A, 0x26, 0x6A, 0x39, 0x41, 0xF2, 0x15, 0x06, 0x2C,
3148 0xFD, 0x31, 0x01, 0x9B, 0xFF, 0x14, 0x00, 0xFF, 0xFF, 0xFE, 0xFF,
3149 0x36, 0x00, 0x36, 0xFF, 0xE3, 0x01, 0x4C, 0xFC, 0xA6, 0x06, 0xDB,
3150 0xF3, 0x5B, 0x1E, 0xFC, 0x3E, 0xFA, 0xF3, 0xD7, 0x04, 0xFD, 0xFD,
3151 0xB4, 0x00, 0xD9, 0xFF, 0xFD, 0xFF, 0x03, 0x00, 0xFF, 0xFF, 0x33,
3152 0x00, 0x3E, 0xFF, 0xC8, 0x01, 0x9B, 0xFC, 0xDD, 0x05, 0xDC, 0xF5,
3153 0xB6, 0x16, 0x77, 0x43, 0xBD, 0xF6, 0x28, 0x03, 0x05, 0xFF, 0x1D,
3154 0x00, 0x25, 0x00, 0xE1, 0xFF, 0x08, 0x00, 0xFF, 0xFF, 0x2D, 0x00,
3155 0x51, 0xFF, 0x95, 0x01, 0x15, 0xFD, 0xCF, 0x04, 0x39, 0xF8, 0x59,
3156 0x0F, 0xAF, 0x46, 0x8B, 0xFA, 0x17, 0x01, 0x38, 0x00, 0x73, 0xFF,
3157 0x78, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x25, 0x00, 0x6C,
3158 0xFF, 0x4F, 0x01, 0xB0, 0xFD, 0x93, 0x03, 0xC7, 0xFA, 0x7D, 0x08,
3159 0x86, 0x48, 0x5A, 0xFF, 0xBA, 0xFE, 0x86, 0x01, 0xBF, 0xFE, 0xCF,
3160 0x00, 0x9E, 0xFF, 0x17, 0x00, 0x1C, 0x00, 0x8C, 0xFF, 0xFE, 0x00,
3161 0x5D, 0xFE, 0x3F, 0x02, 0x5E, 0xFD, 0x54, 0x02, 0xEC, 0x48, 0x13,
3162 0x05, 0x2E, 0xFC, 0xDE, 0x02, 0x0C, 0xFE, 0x24, 0x01, 0x7D, 0xFF,
3163 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0xAE, 0xFF, 0xA7, 0x00, 0x12,
3164 0xFF, 0xEA, 0x00, 0xD9, 0xFF, 0x03, 0xFD, 0xDC, 0x47, 0x95, 0x0B,
3165 0x96, 0xF9, 0x29, 0x04, 0x65, 0xFD, 0x71, 0x01, 0x5F, 0xFF, 0x29,
3166 0x00, 0x00, 0x00, 0x0C, 0x00, 0xD0, 0xFF, 0x51, 0x00, 0xC3, 0xFF,
3167 0xA6, 0xFF, 0x16, 0x02, 0xA9, 0xF8, 0x5C, 0x45, 0xB2, 0x12, 0x19,
3168 0xF7, 0x52, 0x05, 0xD8, 0xFC, 0xAF, 0x01, 0x47, 0xFF, 0x30, 0x00,
3169 0xFF, 0xFF, 0x06, 0x00, 0xEE, 0xFF, 0x01, 0x00, 0x66, 0x00, 0x85,
3170 0xFE, 0xFC, 0x03, 0x55, 0xF5, 0x8C, 0x41, 0x38, 0x1A, 0xE1, 0xF4,
3171 0x43, 0x06, 0x70, 0xFC, 0xD8, 0x01, 0x39, 0xFF, 0x35, 0x00, 0xFE,
3172 0xFF, 0x01, 0x00, 0x08, 0x00, 0xBB, 0xFF, 0xF1, 0x00, 0x96, 0xFD,
3173 0x78, 0x05, 0x0E, 0xF3, 0x8A, 0x3C, 0xEA, 0x21, 0x19, 0xF3, 0xE6,
3174 0x06, 0x38, 0xFC, 0xE6, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF,
3175 0xFE, 0xFF, 0x1D, 0x00, 0x82, 0xFF, 0x60, 0x01, 0xE0, 0xFC, 0x7F,
3176 0x06, 0xCC, 0xF1, 0x85, 0x36, 0x87, 0x29, 0xEB, 0xF1, 0x2A, 0x07,
3177 0x39, 0xFC, 0xD6, 0x01, 0x43, 0xFF, 0x33, 0x00, 0xFD, 0xFF, 0xFD,
3178 0xFF, 0x2B, 0x00, 0x59, 0xFF, 0xAE, 0x01, 0x6A, 0xFC, 0x0D, 0x07,
3179 0x80, 0xF1, 0xB8, 0x2F, 0xCF, 0x30, 0x7D, 0xF1, 0xFF, 0x06, 0x78,
3180 0xFC, 0xA5, 0x01, 0x5F, 0xFF, 0x29, 0x00, 0xFD, 0xFF, 0xFD, 0xFF,
3181 0x34, 0x00, 0x40, 0xFF, 0xDB, 0x01, 0x35, 0xFC, 0x26, 0x07, 0x0E,
3182 0xF2, 0x60, 0x28, 0x82, 0x37, 0xED, 0xF1, 0x5E, 0x06, 0xF8, 0xFC,
3183 0x51, 0x01, 0x8A, 0xFF, 0x1A, 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0x36,
3184 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3E, 0xFC, 0xD3, 0x06, 0x56, 0xF3,
3185 0xBA, 0x20, 0x61, 0x3D, 0x56, 0xF3, 0x45, 0x05, 0xB7, 0xFD, 0xDE,
3186 0x00, 0xC5, 0xFF, 0x05, 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x35, 0x00,
3187 0x3A, 0xFF, 0xD3, 0x01, 0x7D, 0xFC, 0x23, 0x06, 0x32, 0xF5, 0x0C,
3188 0x19, 0x38, 0x42, 0xC7, 0xF5, 0xB8, 0x03, 0xAF, 0xFE, 0x4E, 0x00,
3189 0x0C, 0x00, 0xEA, 0xFF, 0x06, 0x00, 0xFF, 0xFF, 0x2F, 0x00, 0x4A,
3190 0xFF, 0xA7, 0x01, 0xEC, 0xFC, 0x28, 0x05, 0x77, 0xF7, 0x92, 0x11,
3191 0xD7, 0x45, 0x43, 0xF9, 0xC3, 0x01, 0xD6, 0xFF, 0xA9, 0xFF, 0x5E,
3192 0x00, 0xCB, 0xFF, 0x0D, 0x00, 0x00, 0x00, 0x28, 0x00, 0x63, 0xFF,
3193 0x66, 0x01, 0x7D, 0xFD, 0xF8, 0x03, 0xFB, 0xF9, 0x89, 0x0A, 0x1D,
3194 0x48, 0xC5, 0xFD, 0x7A, 0xFF, 0x1D, 0x01, 0xF7, 0xFE, 0xB4, 0x00,
3195 0xA9, 0xFF, 0x15, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x82, 0xFF, 0x18,
3196 0x01, 0x27, 0xFE, 0xA9, 0x02, 0x94, 0xFC, 0x24, 0x04, 0xF5, 0x48,
3197 0x39, 0x03, 0xF9, 0xFC, 0x74, 0x02, 0x42, 0xFE, 0x0B, 0x01, 0x87,
3198 0xFF, 0x1E, 0x00, 0x16, 0x00, 0xA4, 0xFF, 0xC2, 0x00, 0xDB, 0xFE,
3199 0x52, 0x01, 0x1B, 0xFF, 0x8D, 0xFE, 0x57, 0x48, 0x81, 0x09, 0x61,
3200 0xFA, 0xC6, 0x03, 0x96, 0xFD, 0x5B, 0x01, 0x68, 0xFF, 0x26, 0x00,
3201 0x00, 0x00, 0x0E, 0x00, 0xC6, 0xFF, 0x6B, 0x00, 0x8E, 0xFF, 0x06,
3202 0x00, 0x6E, 0x01, 0xE4, 0xF9, 0x48, 0x46, 0x75, 0x10, 0xD7, 0xF7,
3203 0xFC, 0x04, 0x00, 0xFD, 0x9E, 0x01, 0x4E, 0xFF, 0x2E, 0x00, 0xFF,
3204 0xFF, 0x07, 0x00, 0xE5, 0xFF, 0x18, 0x00, 0x36, 0x00, 0xD9, 0xFE,
3205 0x71, 0x03, 0x3F, 0xF6, 0xDB, 0x42, 0xE0, 0x17, 0x86, 0xF5, 0x00,
3206 0x06, 0x8C, 0xFC, 0xCE, 0x01, 0x3C, 0xFF, 0x34, 0x00, 0xFE, 0xFF,
3207 0x02, 0x00, 0x01, 0x00, 0xCF, 0xFF, 0xC9, 0x00, 0xDA, 0xFD, 0x0F,
3208 0x05, 0xA5, 0xF3, 0x31, 0x3E, 0x8A, 0x1F, 0x97, 0xF3, 0xBD, 0x06,
3209 0x44, 0xFC, 0xE5, 0x01, 0x36, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFF,
3210 0xFF, 0x17, 0x00, 0x92, 0xFF, 0x41, 0x01, 0x11, 0xFD, 0x3B, 0x06,
3211 0x14, 0xF2, 0x78, 0x38, 0x36, 0x27, 0x35, 0xF2, 0x20, 0x07, 0x33,
3212 0xFC, 0xDF, 0x01, 0x3E, 0xFF, 0x34, 0x00, 0xFD, 0xFF, 0xFD, 0xFF,
3213 0x28, 0x00, 0x64, 0xFF, 0x9A, 0x01, 0x88, 0xFC, 0xEE, 0x06, 0x7E,
3214 0xF1, 0xE3, 0x31, 0x9F, 0x2E, 0x88, 0xF1, 0x19, 0x07, 0x5E, 0xFC,
3215 0xB7, 0x01, 0x54, 0xFF, 0x2D, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x32,
3216 0x00, 0x46, 0xFF, 0xD1, 0x01, 0x3F, 0xFC, 0x2B, 0x07, 0xCD, 0xF1,
3217 0xAE, 0x2A, 0x86, 0x35, 0xB1, 0xF1, 0x9D, 0x06, 0xCA, 0xFC, 0x6E,
3218 0x01, 0x7B, 0xFF, 0x20, 0x00, 0xFE, 0xFF, 0xFD, 0xFF, 0x36, 0x00,
3219 0x38, 0xFF, 0xE6, 0x01, 0x35, 0xFC, 0xF7, 0x06, 0xE0, 0xF2, 0x18,
3220 0x23, 0xAB, 0x3B, 0xCC, 0xF2, 0xA8, 0x05, 0x76, 0xFD, 0x04, 0x01,
3221 0xB1, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x38,
3222 0xFF, 0xDC, 0x01, 0x64, 0xFC, 0x62, 0x06, 0x93, 0xF4, 0x66, 0x1B,
3223 0xD9, 0x40, 0xEA, 0xF4, 0x3E, 0x04, 0x5D, 0xFE, 0x7D, 0x00, 0xF5,
3224 0xFF, 0xF3, 0xFF, 0x05, 0x00, 0xFF, 0xFF, 0x31, 0x00, 0x44, 0xFF,
3225 0xB7, 0x01, 0xC5, 0xFC, 0x7C, 0x05, 0xBC, 0xF6, 0xD5, 0x13, 0xDC,
3226 0x44, 0x14, 0xF8, 0x67, 0x02, 0x77, 0xFF, 0xDD, 0xFF, 0x44, 0x00,
3227 0xD5, 0xFF, 0x0B, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x5B, 0xFF, 0x7C,
3228 0x01, 0x4E, 0xFD, 0x5A, 0x04, 0x31, 0xF9, 0xA4, 0x0C, 0x90, 0x47,
3229 0x47, 0xFC, 0x36, 0x00, 0xB6, 0x00, 0x2E, 0xFF, 0x99, 0x00, 0xB3,
3230 0xFF, 0x12, 0x00, 0x00, 0x00, 0x22, 0x00, 0x78, 0xFF, 0x31, 0x01,
3231 0xF1, 0xFD, 0x12, 0x03, 0xC7, 0xFB, 0x07, 0x06, 0xDB, 0x48, 0x73,
3232 0x01, 0xC3, 0xFD, 0x0A, 0x02, 0x79, 0xFE, 0xF1, 0x00, 0x91, 0xFF,
3233 0x1B, 0x00, 0x19, 0x00, 0x99, 0xFF, 0xDD, 0x00, 0xA3, 0xFE, 0xBB,
3234 0x01, 0x58, 0xFE, 0x2D, 0x00, 0xAF, 0x48, 0x7E, 0x07, 0x2E, 0xFB,
3235 0x60, 0x03, 0xC9, 0xFD, 0x43, 0x01, 0x71, 0xFF, 0x24, 0x00, 0x00,
3236 0x00, 0x10, 0x00, 0xBB, 0xFF, 0x85, 0x00, 0x58, 0xFF, 0x6A, 0x00,
3237 0xBE, 0x00, 0x38, 0xFB, 0x0F, 0x47, 0x42, 0x0E, 0x9B, 0xF8, 0xA1,
3238 0x04, 0x2B, 0xFD, 0x8B, 0x01, 0x55, 0xFF, 0x2C, 0x00, 0xFF, 0xFF,
3239 0x09, 0x00, 0xDC, 0xFF, 0x31, 0x00, 0x04, 0x00, 0x32, 0xFF, 0xDC,
3240 0x02, 0x42, 0xF7, 0x0B, 0x44, 0x8E, 0x15, 0x34, 0xF6, 0xB7, 0x05,
3241 0xAB, 0xFC, 0xC1, 0x01, 0x40, 0xFF, 0x33, 0x00, 0xFF, 0xFF, 0x04,
3242 0x00, 0xF9, 0xFF, 0xE4, 0xFF, 0x9F, 0x00, 0x23, 0xFE, 0x9B, 0x04,
3243 0x55, 0xF4, 0xC0, 0x3F, 0x2C, 0x1D, 0x22, 0xF4, 0x8C, 0x06, 0x55,
3244 0xFC, 0xE1, 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFE, 0xFF, 0x00, 0x00,
3245 0x11, 0x00, 0xA3, 0xFF, 0x20, 0x01, 0x49, 0xFD, 0xEB, 0x05, 0x74,
3246 0xF2, 0x54, 0x3A, 0xDD, 0x24, 0x91, 0xF2, 0x0C, 0x07, 0x32, 0xFC,
3247 0xE4, 0x01, 0x3A, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFE, 0xFF, 0x23,
3248 0x00, 0x71, 0xFF, 0x82, 0x01, 0xAB, 0xFC, 0xC4, 0x06, 0x93, 0xF1,
3249 0xFD, 0x33, 0x62, 0x2C, 0xA8, 0xF1, 0x27, 0x07, 0x4A, 0xFC, 0xC7,
3250 0x01, 0x4C, 0xFF, 0x30, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x2F, 0x00,
3251 0x4E, 0xFF, 0xC3, 0x01, 0x4E, 0xFC, 0x24, 0x07, 0x9E, 0xF1, 0xF2,
3252 0x2C, 0x78, 0x33, 0x8C, 0xF1, 0xD0, 0x06, 0xA2, 0xFC, 0x88, 0x01,
3253 0x6D, 0xFF, 0x24, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x35, 0x00, 0x3B,
3254 0xFF, 0xE3, 0x01, 0x31, 0xFC, 0x12, 0x07, 0x79, 0xF2, 0x73, 0x25,
3255 0xDF, 0x39, 0x5A, 0xF2, 0x00, 0x06, 0x3A, 0xFD, 0x28, 0x01, 0x9F,
3256 0xFF, 0x13, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x36, 0x00, 0x36, 0xFF,
3257 0xE2, 0x01, 0x50, 0xFC, 0x99, 0x06, 0xFE, 0xF3, 0xC3, 0x1D, 0x5E,
3258 0x3F, 0x27, 0xF4, 0xB9, 0x04, 0x10, 0xFE, 0xA9, 0x00, 0xDF, 0xFF,
3259 0xFB, 0xFF, 0x03, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0x3F, 0xFF, 0xC5,
3260 0x01, 0xA3, 0xFC, 0xCA, 0x05, 0x07, 0xF6, 0x22, 0x16, 0xC3, 0x43,
3261 0xFE, 0xF6, 0x02, 0x03, 0x1B, 0xFF, 0x11, 0x00, 0x2B, 0x00, 0xDE,
3262 0xFF, 0x09, 0x00, 0xFF, 0xFF, 0x2D, 0x00, 0x53, 0xFF, 0x90, 0x01,
3263 0x20, 0xFD, 0xB8, 0x04, 0x6A, 0xF8, 0xCD, 0x0E, 0xE1, 0x46, 0xE1,
3264 0xFA, 0xEB, 0x00, 0x51, 0x00, 0x65, 0xFF, 0x7F, 0x00, 0xBE, 0xFF,
3265 0x10, 0x00, 0x00, 0x00, 0x24, 0x00, 0x6E, 0xFF, 0x49, 0x01, 0xBC,
3266 0xFD, 0x7A, 0x03, 0xFA, 0xFA, 0xFD, 0x07, 0x9C, 0x48, 0xC3, 0xFF,
3267 0x89, 0xFE, 0xA1, 0x01, 0xB1, 0xFE, 0xD6, 0x00, 0x9C, 0xFF, 0x18,
3268 0x00, 0x1C, 0x00, 0x8F, 0xFF, 0xF7, 0x00, 0x6B, 0xFE, 0x25, 0x02,
3269 0x91, 0xFD, 0xE3, 0x01, 0xE5, 0x48, 0x8D, 0x05, 0xFB, 0xFB, 0xF8,
3270 0x02, 0xFE, 0xFD, 0x2B, 0x01, 0x7A, 0xFF, 0x21, 0x00, 0x00, 0x00,
3271 0x13, 0x00, 0xB1, 0xFF, 0xA0, 0x00, 0x20, 0xFF, 0xD0, 0x00, 0x07,
3272 0x00, 0xA4, 0xFC, 0xB6, 0x47, 0x1C, 0x0C, 0x63, 0xF9, 0x42, 0x04,
3273 0x59, 0xFD, 0x76, 0x01, 0x5D, 0xFF, 0x2A, 0x00, 0x00, 0x00, 0x0B,
3274 0x00, 0xD2, 0xFF, 0x4A, 0x00, 0xD0, 0xFF, 0x8E, 0xFF, 0x3F, 0x02,
3275 0x5E, 0xF8, 0x1E, 0x45, 0x44, 0x13, 0xEA, 0xF6, 0x67, 0x05, 0xCF,
3276 0xFC, 0xB3, 0x01, 0x46, 0xFF, 0x31, 0x00, 0xFF, 0xFF, 0x05, 0x00,
3277 0xF0, 0xFF, 0xFB, 0xFF, 0x71, 0x00, 0x71, 0xFE, 0x1D, 0x04, 0x1F,
3278 0xF5, 0x32, 0x41, 0xCE, 0x1A, 0xBA, 0xF4, 0x53, 0x06, 0x6A, 0xFC,
3279 0xDA, 0x01, 0x38, 0xFF, 0x35, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x0A,
3280 0x00, 0xB6, 0xFF, 0xFB, 0x00, 0x85, 0xFD, 0x90, 0x05, 0xEC, 0xF2,
3281 0x1C, 0x3C, 0x81, 0x22, 0xFC, 0xF2, 0xEF, 0x06, 0x36, 0xFC, 0xE6,
3282 0x01, 0x37, 0xFF, 0x36, 0x00, 0xFD, 0xFF, 0xFE, 0xFF, 0x1E, 0x00,
3283 0x7F, 0xFF, 0x67, 0x01, 0xD5, 0xFC, 0x8E, 0x06, 0xBE, 0xF1, 0x06,
3284 0x36, 0x1A, 0x2A, 0xDC, 0xF1, 0x2A, 0x07, 0x3C, 0xFC, 0xD3, 0x01,
3285 0x44, 0xFF, 0x32, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x2C, 0x00, 0x57,
3286 0xFF, 0xB3, 0x01, 0x64, 0xFC, 0x13, 0x07, 0x83, 0xF1, 0x2C, 0x2F,
3287 0x5A, 0x31, 0x7D, 0xF1, 0xF7, 0x06, 0x80, 0xFC, 0x9F, 0x01, 0x61,
3288 0xFF, 0x29, 0x00, 0xFD, 0xFF, 0xFD, 0xFF, 0x34, 0x00, 0x3F, 0xFF,
3289 0xDD, 0x01, 0x34, 0xFC, 0x23, 0x07, 0x21, 0xF2, 0xCB, 0x27, 0xFE,
3290 0x37, 0x00, 0xF2, 0x4D, 0x06, 0x04, 0xFD, 0x49, 0x01, 0x8E, 0xFF,
3291 0x19, 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6,
3292 0x01, 0x41, 0xFC, 0xC8, 0x06, 0x76, 0xF3, 0x22, 0x20, 0xCA, 0x3D,
3293 0x7D, 0xF3, 0x2A, 0x05, 0xC8, 0xFD, 0xD4, 0x00, 0xCA, 0xFF, 0x03,
3294 0x00, 0x02, 0x00, 0xFE, 0xFF, 0x34, 0x00, 0x3B, 0xFF, 0xD1, 0x01,
3295 0x84, 0xFC, 0x12, 0x06, 0x5C, 0xF5, 0x76, 0x18, 0x89, 0x42, 0x02,
3296 0xF6, 0x94, 0x03, 0xC4, 0xFE, 0x42, 0x00, 0x12, 0x00, 0xE8, 0xFF,
3297 0x07, 0x00, 0xFF, 0xFF, 0x2F, 0x00, 0x4C, 0xFF, 0xA2, 0x01, 0xF6,
3298 0xFC, 0x12, 0x05, 0xA7, 0xF7, 0x03, 0x11, 0x10, 0x46, 0x93, 0xF9,
3299 0x98, 0x01, 0xEE, 0xFF, 0x9B, 0xFF, 0x64, 0x00, 0xC8, 0xFF, 0x0E,
3300 0x00, 0x00, 0x00, 0x27, 0x00, 0x65, 0xFF, 0x60, 0x01, 0x8A, 0xFD,
3301 0xDF, 0x03, 0x2E, 0xFA, 0x04, 0x0A, 0x3A, 0x48, 0x28, 0xFE, 0x4B,
3302 0xFF, 0x38, 0x01, 0xE9, 0xFE, 0xBB, 0x00, 0xA6, 0xFF, 0x16, 0x00,
3303 0x00, 0x00, 0x1E, 0x00, 0x84, 0xFF, 0x11, 0x01, 0x34, 0xFE, 0x8F,
3304 0x02, 0xC7, 0xFC, 0xAE, 0x03, 0xF7, 0x48, 0xAE, 0x03, 0xC7, 0xFC,
3305 0x8F, 0x02, 0x34, 0xFE, 0x11, 0x01, 0x84, 0xFF, 0x1E, 0x00, 0x00,
3306 0x00, 0xF4, 0xFF, 0x1A, 0x00, 0xFF, 0x00, 0x07, 0x03, 0x16, 0x06,
3307 0x7C, 0x09, 0x2A, 0x0C, 0x2E, 0x0D, 0x2A, 0x0C, 0x7C, 0x09, 0x16,
3308 0x06, 0x07, 0x03, 0xFF, 0x00, 0x1A, 0x00, 0xF4, 0xFF, 0xF2, 0xFF,
3309 0xA0, 0xFF, 0x71, 0xFF, 0x71, 0x00, 0x86, 0x03, 0x73, 0x08, 0x88,
3310 0x0D, 0x78, 0x10, 0xC9, 0x0F, 0xD5, 0x0B, 0x8B, 0x06, 0x28, 0x02,
3311 0xDF, 0xFF, 0x6F, 0xFF, 0xC3, 0xFF, 0xFD, 0xFF, 0x00, 0x00, 0xDC,
3312 0xFF, 0x80, 0xFF, 0x9A, 0xFF, 0x46, 0x01, 0x1E, 0x05, 0x5A, 0x0A,
3313 0xED, 0x0E, 0xAA, 0x10, 0xAF, 0x0E, 0xFD, 0x09, 0xCB, 0x04, 0x18,
3314 0x01, 0x8E, 0xFF, 0x85, 0xFF, 0xE1, 0xFF, 0xFC, 0xFF, 0xBD, 0xFF,
3315 0x6D, 0xFF, 0xF6, 0xFF, 0x65, 0x02, 0xE5, 0x06, 0x2B, 0x0C, 0xF3,
3316 0x0F, 0x60, 0x10, 0x3B, 0x0D, 0x16, 0x08, 0x3F, 0x03, 0x50, 0x00,
3317 0x6E, 0xFF, 0xA7, 0xFF, 0xF5, 0xFF, 0xEF, 0xFF, 0x9A, 0xFF, 0x75,
3318 0xFF, 0x91, 0x00, 0xC9, 0x03, 0xC8, 0x08, 0xCC, 0x0D, 0x89, 0x10,
3319 0x9F, 0x0F, 0x85, 0x0B, 0x3B, 0x06, 0xF4, 0x01, 0xCD, 0xFF, 0x72,
3320 0xFF, 0xC9, 0xFF, 0xFE, 0xFF, 0x00, 0x00, 0xD7, 0xFF, 0x7B, 0xFF,
3321 0xA5, 0xFF, 0x73, 0x01, 0x6A, 0x05, 0xAD, 0x0A, 0x21, 0x0F, 0xA6,
3322 0x10, 0x74, 0x0E, 0xA9, 0x09, 0x83, 0x04, 0xF0, 0x00, 0x85, 0xFF,
3323 0x8B, 0xFF, 0xE5, 0xFF, 0xFA, 0xFF, 0xB7, 0xFF, 0x6C, 0xFF, 0x0C,
3324 0x00, 0x9D, 0x02, 0x37, 0x07, 0x78, 0x0C, 0x15, 0x10, 0x47, 0x10,
3325 0xF3, 0x0C, 0xC2, 0x07, 0x01, 0x03, 0x35, 0x00, 0x6D, 0xFF, 0xAD,
3326 0xFF, 0xF7, 0xFF, 0xEB, 0xFF, 0x94, 0xFF, 0x7A, 0xFF, 0xB3, 0x00,
3327 0x0D, 0x04, 0x1C, 0x09, 0x0D, 0x0E, 0x97, 0x10, 0x73, 0x0F, 0x35,
3328 0x0B, 0xEB, 0x05, 0xC1, 0x01, 0xBD, 0xFF, 0x75, 0xFF, 0xCE, 0xFF,
3329 0xFF, 0xFF, 0xFF, 0xFF, 0xD2, 0xFF, 0x77, 0xFF, 0xB3, 0xFF, 0xA1,
3330 0x01, 0xB7, 0x05, 0xFF, 0x0A, 0x53, 0x0F, 0x9E, 0x10, 0x37, 0x0E,
3331 0x55, 0x09, 0x3B, 0x04, 0xCB, 0x00, 0x7E, 0xFF, 0x90, 0xFF, 0xE9,
3332 0xFF, 0xF8, 0xFF, 0xB1, 0xFF, 0x6C, 0xFF, 0x24, 0x00, 0xD8, 0x02,
3333 0x8A, 0x07, 0xC2, 0x0C, 0x34, 0x10, 0x2A, 0x10, 0xAA, 0x0C, 0x6F,
3334 0x07, 0xC4, 0x02, 0x1C, 0x00, 0x6C, 0xFF, 0xB3, 0xFF, 0xF9, 0xFF,
3335 0xE8, 0xFF, 0x8E, 0xFF, 0x80, 0xFF, 0xD7, 0x00, 0x53, 0x04, 0x71,
3336 0x09, 0x4C, 0x0E, 0xA1, 0x10, 0x43, 0x0F, 0xE3, 0x0A, 0x9D, 0x05,
3337 0x91, 0x01, 0xAE, 0xFF, 0x79, 0xFF, 0xD4, 0xFF, 0x00, 0x00, 0xFF,
3338 0xFF, 0xCD, 0xFF, 0x74, 0xFF, 0xC2, 0xFF, 0xD2, 0x01, 0x06, 0x06,
3339 0x50, 0x0B, 0x82, 0x0F, 0x93, 0x10, 0xF8, 0x0D, 0x00, 0x09, 0xF6,
3340 0x03, 0xA7, 0x00, 0x78, 0xFF, 0x96, 0xFF, 0xEC, 0xFF, 0xF6, 0xFF,
3341 0xAB, 0xFF, 0x6D, 0xFF, 0x3E, 0x00, 0x15, 0x03, 0xDE, 0x07, 0x0B,
3342 0x0D, 0x50, 0x10, 0x0A, 0x10, 0x5E, 0x0C, 0x1C, 0x07, 0x8A, 0x02,
3343 0x04, 0x00, 0x6C, 0xFF, 0xB9, 0xFF, 0xFB, 0xFF, 0xE4, 0xFF, 0x89,
3344 0xFF, 0x88, 0xFF, 0xFD, 0x00, 0x9B, 0x04, 0xC5, 0x09, 0x88, 0x0E,
3345 0xA8, 0x10, 0x10, 0x0F, 0x91, 0x0A, 0x50, 0x05, 0x64, 0x01, 0xA1,
3346 0xFF, 0x7D, 0xFF, 0xD9, 0xFF, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0xFF,
3347 0x71, 0xFF, 0xD3, 0xFF, 0x05, 0x02, 0x55, 0x06, 0xA0, 0x0B, 0xAD,
3348 0x0F, 0x84, 0x10, 0xB6, 0x0D, 0xAC, 0x08, 0xB3, 0x03, 0x86, 0x00,
3349 0x74, 0xFF, 0x9C, 0xFF, 0xF0, 0xFF, 0xF4, 0xFF, 0xA5, 0xFF, 0x6F,
3350 0xFF, 0x5A, 0x00, 0x54, 0x03, 0x32, 0x08, 0x52, 0x0D, 0x68, 0x10,
3351 0xE6, 0x0F, 0x11, 0x0C, 0xCA, 0x06, 0x52, 0x02, 0xEF, 0xFF, 0x6E,
3352 0xFF, 0xBF, 0xFF, 0xFC, 0xFF, 0xDF, 0xFF, 0x84, 0xFF, 0x91, 0xFF,
3353 0x25, 0x01, 0xE4, 0x04, 0x19, 0x0A, 0xC2, 0x0E, 0xAA, 0x10, 0xDA,
3354 0x0E, 0x3E, 0x0A, 0x05, 0x05, 0x38, 0x01, 0x96, 0xFF, 0x81, 0xFF,
3355 0xDD, 0xFF, 0x00, 0x00, 0xFD, 0xFF, 0xC1, 0xFF, 0x6E, 0xFF, 0xE6,
3356 0xFF, 0x3A, 0x02, 0xA6, 0x06, 0xEF, 0x0B, 0xD6, 0x0F, 0x71, 0x10,
3357 0x71, 0x0D, 0x57, 0x08, 0x71, 0x03, 0x67, 0x00, 0x70, 0xFF, 0xA2,
3358 0xFF, 0xF3, 0xFF, 0xF1, 0xFF, 0x9F, 0xFF, 0x72, 0xFF, 0x78, 0x00,
3359 0x95, 0x03, 0x86, 0x08, 0x98, 0x0D, 0x7C, 0x10, 0xC0, 0x0F, 0xC3,
3360 0x0B, 0x79, 0x06, 0x1C, 0x02, 0xDB, 0xFF, 0x70, 0xFF, 0xC5, 0xFF,
3361 0xFE, 0xFF, 0x00, 0x00, 0xDB, 0xFF, 0x7F, 0xFF, 0x9C, 0xFF, 0x50,
3362 0x01, 0x2F, 0x05, 0x6C, 0x0A, 0xF9, 0x0E, 0xA9, 0x10, 0xA2, 0x0E,
3363 0xEA, 0x09, 0xBB, 0x04, 0x0F, 0x01, 0x8C, 0xFF, 0x87, 0xFF, 0xE2,
3364 0xFF, 0xFC, 0xFF, 0xBC, 0xFF, 0x6D, 0xFF, 0xFA, 0xFF, 0x71, 0x02,
3365 0xF7, 0x06, 0x3C, 0x0C, 0xFB, 0x0F, 0x5B, 0x10, 0x2B, 0x0D, 0x03,
3366 0x08, 0x31, 0x03, 0x4A, 0x00, 0x6E, 0xFF, 0xA8, 0xFF, 0xF5, 0xFF,
3367 0xEE, 0xFF, 0x99, 0xFF, 0x76, 0xFF, 0x98, 0x00, 0xD8, 0x03, 0xDB,
3368 0x08, 0xDB, 0x0D, 0x8D, 0x10, 0x96, 0x0F, 0x73, 0x0B, 0x29, 0x06,
3369 0xE8, 0x01, 0xC9, 0xFF, 0x72, 0xFF, 0xCA, 0xFF, 0xFE, 0xFF, 0x00,
3370 0x00, 0xD6, 0xFF, 0x7A, 0xFF, 0xA8, 0xFF, 0x7D, 0x01, 0x7B, 0x05,
3371 0xBF, 0x0A, 0x2D, 0x0F, 0xA5, 0x10, 0x67, 0x0E, 0x96, 0x09, 0x73,
3372 0x04, 0xE7, 0x00, 0x84, 0xFF, 0x8C, 0xFF, 0xE6, 0xFF, 0xFA, 0xFF,
3373 0xB6, 0xFF, 0x6C, 0xFF, 0x11, 0x00, 0xAA, 0x02, 0x4A, 0x07, 0x88,
3374 0x0C, 0x1C, 0x10, 0x41, 0x10, 0xE3, 0x0C, 0xAF, 0x07, 0xF3, 0x02,
3375 0x2F, 0x00, 0x6C, 0xFF, 0xAE, 0xFF, 0xF7, 0xFF, 0xEA, 0xFF, 0x93,
3376 0xFF, 0x7B, 0xFF, 0xBB, 0x00, 0x1C, 0x04, 0x2F, 0x09, 0x1B, 0x0E,
3377 0x9A, 0x10, 0x68, 0x0F, 0x23, 0x0B, 0xDA, 0x05, 0xB7, 0x01, 0xB9,
3378 0xFF, 0x76, 0xFF, 0xD0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xD1, 0xFF,
3379 0x76, 0xFF, 0xB6, 0xFF, 0xAC, 0x01, 0xC8, 0x05, 0x11, 0x0B, 0x5E,
3380 0x0F, 0x9C, 0x10, 0x29, 0x0E, 0x42, 0x09, 0x2C, 0x04, 0xC2, 0x00,
3381 0x7D, 0xFF, 0x92, 0xFF, 0xEA, 0xFF, 0xF8, 0xFF, 0xB0, 0xFF, 0x6C,
3382 0xFF, 0x29, 0x00, 0xE6, 0x02, 0x9D, 0x07, 0xD3, 0x0C, 0x3B, 0x10,
3383 0x23, 0x10, 0x99, 0x0C, 0x5C, 0x07, 0xB7, 0x02, 0x16, 0x00, 0x6C,
3384 0xFF, 0xB4, 0xFF, 0xF9, 0xFF, 0xE7, 0xFF, 0x8D, 0xFF, 0x82, 0xFF,
3385 0xDF, 0x00, 0x63, 0x04, 0x84, 0x09, 0x59, 0x0E, 0xA3, 0x10, 0x38,
3386 0x0F, 0xD1, 0x0A, 0x8C, 0x05, 0x87, 0x01, 0xAB, 0xFF, 0x79, 0xFF,
3387 0xD5, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xCB, 0xFF, 0x73, 0xFF, 0xC6,
3388 0xFF, 0xDD, 0x01, 0x17, 0x06, 0x62, 0x0B, 0x8C, 0x0F, 0x90, 0x10,
3389 0xE9, 0x0D, 0xED, 0x08, 0xE7, 0x03, 0xA0, 0x00, 0x77, 0xFF, 0x97,
3390 0xFF, 0xED, 0xFF, 0xF6, 0xFF, 0xA9, 0xFF, 0x6D, 0xFF, 0x44, 0x00,
3391 0x23, 0x03, 0xF1, 0x07, 0x1B, 0x0D, 0x55, 0x10, 0x02, 0x10, 0x4D,
3392 0x0C, 0x0A, 0x07, 0x7E, 0x02, 0xFF, 0xFF, 0x6D, 0xFF, 0xBA, 0xFF,
3393 0xFB, 0xFF, 0xE3, 0xFF, 0x88, 0xFF, 0x8A, 0xFF, 0x06, 0x01, 0xAB,
3394 0x04, 0xD8, 0x09, 0x95, 0x0E, 0xA9, 0x10, 0x05, 0x0F, 0x7F, 0x0A,
3395 0x40, 0x05, 0x5A, 0x01, 0x9F, 0xFF, 0x7E, 0xFF, 0xDA, 0xFF, 0x00,
3396 0x00, 0xFE, 0xFF, 0xC6, 0xFF, 0x70, 0xFF, 0xD7, 0xFF, 0x10, 0x02,
3397 0x67, 0x06, 0xB1, 0x0B, 0xB7, 0x0F, 0x80, 0x10, 0xA7, 0x0D, 0x99,
3398 0x08, 0xA4, 0x03, 0x7F, 0x00, 0x73, 0xFF, 0x9D, 0xFF, 0xF0, 0xFF,
3399 0xF3, 0xFF, 0xA3, 0xFF, 0x70, 0xFF, 0x60, 0x00, 0x62, 0x03, 0x45,
3400 0x08, 0x62, 0x0D, 0x6C, 0x10, 0xDE, 0x0F, 0x00, 0x0C, 0xB8, 0x06,
3401 0x46, 0x02, 0xEA, 0xFF, 0x6E, 0xFF, 0xC0, 0xFF, 0xFD, 0xFF, 0x00,
3402 0x00, 0xDE, 0xFF, 0x83, 0xFF, 0x94, 0xFF, 0x2F, 0x01, 0xF4, 0x04,
3403 0x2B, 0x0A, 0xCE, 0x0E, 0xAA, 0x10, 0xCE, 0x0E, 0x2B, 0x0A, 0xF4,
3404 0x04, 0x2F, 0x01, 0x94, 0xFF, 0x83, 0xFF, 0xDE, 0xFF, 0xFD, 0xFF,
3405 0xC0, 0xFF, 0x6E, 0xFF, 0xEA, 0xFF, 0x46, 0x02, 0xB8, 0x06, 0x00,
3406 0x0C, 0xDE, 0x0F, 0x6C, 0x10, 0x62, 0x0D, 0x45, 0x08, 0x62, 0x03,
3407 0x60, 0x00, 0x70, 0xFF, 0xA3, 0xFF, 0xF3, 0xFF, 0xF0, 0xFF, 0x9D,
3408 0xFF, 0x73, 0xFF, 0x7F, 0x00, 0xA4, 0x03, 0x99, 0x08, 0xA7, 0x0D,
3409 0x80, 0x10, 0xB7, 0x0F, 0xB1, 0x0B, 0x67, 0x06, 0x10, 0x02, 0xD7,
3410 0xFF, 0x70, 0xFF, 0xC6, 0xFF, 0xFE, 0xFF, 0x00, 0x00, 0xDA, 0xFF,
3411 0x7E, 0xFF, 0x9F, 0xFF, 0x5A, 0x01, 0x40, 0x05, 0x7F, 0x0A, 0x05,
3412 0x0F, 0xA9, 0x10, 0x95, 0x0E, 0xD8, 0x09, 0xAB, 0x04, 0x06, 0x01,
3413 0x8A, 0xFF, 0x88, 0xFF, 0xE3, 0xFF, 0xFB, 0xFF, 0xBA, 0xFF, 0x6D,
3414 0xFF, 0xFF, 0xFF, 0x7E, 0x02, 0x0A, 0x07, 0x4D, 0x0C, 0x02, 0x10,
3415 0x55, 0x10, 0x1B, 0x0D, 0xF1, 0x07, 0x23, 0x03, 0x44, 0x00, 0x6D,
3416 0xFF, 0xA9, 0xFF, 0xF6, 0xFF, 0xED, 0xFF, 0x97, 0xFF, 0x77, 0xFF,
3417 0xA0, 0x00, 0xE7, 0x03, 0xED, 0x08, 0xE9, 0x0D, 0x90, 0x10, 0x8C,
3418 0x0F, 0x62, 0x0B, 0x17, 0x06, 0xDD, 0x01, 0xC6, 0xFF, 0x73, 0xFF,
3419 0xCB, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xD5, 0xFF, 0x79, 0xFF, 0xAB,
3420 0xFF, 0x87, 0x01, 0x8C, 0x05, 0xD1, 0x0A, 0x38, 0x0F, 0xA3, 0x10,
3421 0x59, 0x0E, 0x84, 0x09, 0x63, 0x04, 0xDF, 0x00, 0x82, 0xFF, 0x8D,
3422 0xFF, 0xE7, 0xFF, 0xF9, 0xFF, 0xB4, 0xFF, 0x6C, 0xFF, 0x16, 0x00,
3423 0xB7, 0x02, 0x5C, 0x07, 0x99, 0x0C, 0x23, 0x10, 0x3B, 0x10, 0xD3,
3424 0x0C, 0x9D, 0x07, 0xE6, 0x02, 0x29, 0x00, 0x6C, 0xFF, 0xB0, 0xFF,
3425 0xF8, 0xFF, 0xEA, 0xFF, 0x92, 0xFF, 0x7D, 0xFF, 0xC2, 0x00, 0x2C,
3426 0x04, 0x42, 0x09, 0x29, 0x0E, 0x9C, 0x10, 0x5E, 0x0F, 0x11, 0x0B,
3427 0xC8, 0x05, 0xAC, 0x01, 0xB6, 0xFF, 0x76, 0xFF, 0xD1, 0xFF, 0xFF,
3428 0xFF, 0xFF, 0xFF, 0xD0, 0xFF, 0x76, 0xFF, 0xB9, 0xFF, 0xB7, 0x01,
3429 0xDA, 0x05, 0x23, 0x0B, 0x68, 0x0F, 0x9A, 0x10, 0x1B, 0x0E, 0x2F,
3430 0x09, 0x1C, 0x04, 0xBB, 0x00, 0x7B, 0xFF, 0x93, 0xFF, 0xEA, 0xFF,
3431 0xF7, 0xFF, 0xAE, 0xFF, 0x6C, 0xFF, 0x2F, 0x00, 0xF3, 0x02, 0xAF,
3432 0x07, 0xE3, 0x0C, 0x41, 0x10, 0x1C, 0x10, 0x88, 0x0C, 0x4A, 0x07,
3433 0xAA, 0x02, 0x11, 0x00, 0x6C, 0xFF, 0xB6, 0xFF, 0xFA, 0xFF, 0xE6,
3434 0xFF, 0x8C, 0xFF, 0x84, 0xFF, 0xE7, 0x00, 0x73, 0x04, 0x96, 0x09,
3435 0x67, 0x0E, 0xA5, 0x10, 0x2D, 0x0F, 0xBF, 0x0A, 0x7B, 0x05, 0x7D,
3436 0x01, 0xA8, 0xFF, 0x7A, 0xFF, 0xD6, 0xFF, 0x00, 0x00, 0xFE, 0xFF,
3437 0xCA, 0xFF, 0x72, 0xFF, 0xC9, 0xFF, 0xE8, 0x01, 0x29, 0x06, 0x73,
3438 0x0B, 0x96, 0x0F, 0x8D, 0x10, 0xDB, 0x0D, 0xDB, 0x08, 0xD8, 0x03,
3439 0x98, 0x00, 0x76, 0xFF, 0x99, 0xFF, 0xEE, 0xFF, 0xF5, 0xFF, 0xA8,
3440 0xFF, 0x6E, 0xFF, 0x4A, 0x00, 0x31, 0x03, 0x03, 0x08, 0x2B, 0x0D,
3441 0x5B, 0x10, 0xFB, 0x0F, 0x3C, 0x0C, 0xF7, 0x06, 0x71, 0x02, 0xFA,
3442 0xFF, 0x6D, 0xFF, 0xBC, 0xFF, 0xFC, 0xFF, 0xE2, 0xFF, 0x87, 0xFF,
3443 0x8C, 0xFF, 0x0F, 0x01, 0xBB, 0x04, 0xEA, 0x09, 0xA2, 0x0E, 0xA9,
3444 0x10, 0xF9, 0x0E, 0x6C, 0x0A, 0x2F, 0x05, 0x50, 0x01, 0x9C, 0xFF,
3445 0x7F, 0xFF, 0xDB, 0xFF, 0x00, 0x00, 0xFE, 0xFF, 0xC5, 0xFF, 0x70,
3446 0xFF, 0xDB, 0xFF, 0x1C, 0x02, 0x79, 0x06, 0xC3, 0x0B, 0xC0, 0x0F,
3447 0x7C, 0x10, 0x98, 0x0D, 0x86, 0x08, 0x95, 0x03, 0x78, 0x00, 0x72,
3448 0xFF, 0x9F, 0xFF, 0xF1, 0xFF, 0xF3, 0xFF, 0xA2, 0xFF, 0x70, 0xFF,
3449 0x67, 0x00, 0x71, 0x03, 0x57, 0x08, 0x71, 0x0D, 0x71, 0x10, 0xD6,
3450 0x0F, 0xEF, 0x0B, 0xA6, 0x06, 0x3A, 0x02, 0xE6, 0xFF, 0x6E, 0xFF,
3451 0xC1, 0xFF, 0xFD, 0xFF, 0x00, 0x00, 0xDD, 0xFF, 0x81, 0xFF, 0x96,
3452 0xFF, 0x38, 0x01, 0x05, 0x05, 0x3E, 0x0A, 0xDA, 0x0E, 0xAA, 0x10,
3453 0xC2, 0x0E, 0x19, 0x0A, 0xE4, 0x04, 0x25, 0x01, 0x91, 0xFF, 0x84,
3454 0xFF, 0xDF, 0xFF, 0xFC, 0xFF, 0xBF, 0xFF, 0x6E, 0xFF, 0xEF, 0xFF,
3455 0x52, 0x02, 0xCA, 0x06, 0x11, 0x0C, 0xE6, 0x0F, 0x68, 0x10, 0x52,
3456 0x0D, 0x32, 0x08, 0x54, 0x03, 0x5A, 0x00, 0x6F, 0xFF, 0xA5, 0xFF,
3457 0xF4, 0xFF, 0xF0, 0xFF, 0x9C, 0xFF, 0x74, 0xFF, 0x86, 0x00, 0xB3,
3458 0x03, 0xAC, 0x08, 0xB6, 0x0D, 0x84, 0x10, 0xAD, 0x0F, 0xA0, 0x0B,
3459 0x55, 0x06, 0x05, 0x02, 0xD3, 0xFF, 0x71, 0xFF, 0xC7, 0xFF, 0xFE,
3460 0xFF, 0x00, 0x00, 0xD9, 0xFF, 0x7D, 0xFF, 0xA1, 0xFF, 0x64, 0x01,
3461 0x50, 0x05, 0x91, 0x0A, 0x10, 0x0F, 0xA8, 0x10, 0x88, 0x0E, 0xC5,
3462 0x09, 0x9B, 0x04, 0xFD, 0x00, 0x88, 0xFF, 0x89, 0xFF, 0xE4, 0xFF,
3463 0xFB, 0xFF, 0xB9, 0xFF, 0x6C, 0xFF, 0x04, 0x00, 0x8A, 0x02, 0x1C,
3464 0x07, 0x5E, 0x0C, 0x0A, 0x10, 0x50, 0x10, 0x0B, 0x0D, 0xDE, 0x07,
3465 0x15, 0x03, 0x3E, 0x00, 0x6D, 0xFF, 0xAB, 0xFF, 0xF6, 0xFF, 0xEC,
3466 0xFF, 0x96, 0xFF, 0x78, 0xFF, 0xA7, 0x00, 0xF6, 0x03, 0x00, 0x09,
3467 0xF8, 0x0D, 0x93, 0x10, 0x82, 0x0F, 0x50, 0x0B, 0x06, 0x06, 0xD2,
3468 0x01, 0xC2, 0xFF, 0x74, 0xFF, 0xCD, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
3469 0xD4, 0xFF, 0x79, 0xFF, 0xAE, 0xFF, 0x91, 0x01, 0x9D, 0x05, 0xE3,
3470 0x0A, 0x43, 0x0F, 0xA1, 0x10, 0x4C, 0x0E, 0x71, 0x09, 0x53, 0x04,
3471 0xD7, 0x00, 0x80, 0xFF, 0x8E, 0xFF, 0xE8, 0xFF, 0xF9, 0xFF, 0xB3,
3472 0xFF, 0x6C, 0xFF, 0x1C, 0x00, 0xC4, 0x02, 0x6F, 0x07, 0xAA, 0x0C,
3473 0x2A, 0x10, 0x34, 0x10, 0xC2, 0x0C, 0x8A, 0x07, 0xD8, 0x02, 0x24,
3474 0x00, 0x6C, 0xFF, 0xB1, 0xFF, 0xF8, 0xFF, 0xE9, 0xFF, 0x90, 0xFF,
3475 0x7E, 0xFF, 0xCB, 0x00, 0x3B, 0x04, 0x55, 0x09, 0x37, 0x0E, 0x9E,
3476 0x10, 0x53, 0x0F, 0xFF, 0x0A, 0xB7, 0x05, 0xA1, 0x01, 0xB3, 0xFF,
3477 0x77, 0xFF, 0xD2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xCE, 0xFF, 0x75,
3478 0xFF, 0xBD, 0xFF, 0xC1, 0x01, 0xEB, 0x05, 0x35, 0x0B, 0x73, 0x0F,
3479 0x97, 0x10, 0x0D, 0x0E, 0x1C, 0x09, 0x0D, 0x04, 0xB3, 0x00, 0x7A,
3480 0xFF, 0x94, 0xFF, 0xEB, 0xFF, 0xF7, 0xFF, 0xAD, 0xFF, 0x6D, 0xFF,
3481 0x35, 0x00, 0x01, 0x03, 0xC2, 0x07, 0xF3, 0x0C, 0x47, 0x10, 0x15,
3482 0x10, 0x78, 0x0C, 0x37, 0x07, 0x9D, 0x02, 0x0C, 0x00, 0x6C, 0xFF,
3483 0xB7, 0xFF, 0xFA, 0xFF, 0xE5, 0xFF, 0x8B, 0xFF, 0x85, 0xFF, 0xF0,
3484 0x00, 0x83, 0x04, 0xA9, 0x09, 0x74, 0x0E, 0xA6, 0x10, 0x21, 0x0F,
3485 0xAD, 0x0A, 0x6A, 0x05, 0x73, 0x01, 0xA5, 0xFF, 0x7B, 0xFF, 0xD7,
3486 0xFF, 0x00, 0x00, 0xFE, 0xFF, 0xC9, 0xFF, 0x72, 0xFF, 0xCD, 0xFF,
3487 0xF4, 0x01, 0x3B, 0x06, 0x85, 0x0B, 0x9F, 0x0F, 0x89, 0x10, 0xCC,
3488 0x0D, 0xC8, 0x08, 0xC9, 0x03, 0x91, 0x00, 0x75, 0xFF, 0x9A, 0xFF,
3489 0xEF, 0xFF, 0xF5, 0xFF, 0xA7, 0xFF, 0x6E, 0xFF, 0x50, 0x00, 0x3F,
3490 0x03, 0x16, 0x08, 0x3B, 0x0D, 0x60, 0x10, 0xF3, 0x0F, 0x2B, 0x0C,
3491 0xE5, 0x06, 0x65, 0x02, 0xF6, 0xFF, 0x6D, 0xFF, 0xBD, 0xFF, 0xFC,
3492 0xFF, 0xE1, 0xFF, 0x85, 0xFF, 0x8E, 0xFF, 0x18, 0x01, 0xCB, 0x04,
3493 0xFD, 0x09, 0xAF, 0x0E, 0xAA, 0x10, 0xED, 0x0E, 0x5A, 0x0A, 0x1E,
3494 0x05, 0x46, 0x01, 0x9A, 0xFF, 0x80, 0xFF, 0xDC, 0xFF, 0x00, 0x00,
3495 0xFD, 0xFF, 0xC3, 0xFF, 0x6F, 0xFF, 0xDF, 0xFF, 0x28, 0x02, 0x8B,
3496 0x06, 0xD5, 0x0B, 0xC9, 0x0F, 0x78, 0x10, 0x88, 0x0D, 0x73, 0x08,
3497 0x86, 0x03, 0x71, 0x00, 0x71, 0xFF, 0xA0, 0xFF, 0xF2, 0xFF, 0xF2,
3498 0xFF, 0xA1, 0xFF, 0x71, 0xFF, 0x6E, 0x00, 0x7F, 0x03, 0x6A, 0x08,
3499 0x81, 0x0D, 0x76, 0x10, 0xCD, 0x0F, 0xDD, 0x0B, 0x94, 0x06, 0x2E,
3500 0x02, 0xE1, 0xFF, 0x6F, 0xFF, 0xC3, 0xFF, 0xFD, 0xFF, 0x00, 0x00,
3501 0xDC, 0xFF, 0x80, 0xFF, 0x98, 0xFF, 0x42, 0x01, 0x16, 0x05, 0x50,
3502 0x0A, 0xE7, 0x0E, 0xAA, 0x10, 0xB5, 0x0E, 0x06, 0x0A, 0xD3, 0x04,
3503 0x1C, 0x01, 0x8F, 0xFF, 0x85, 0xFF, 0xE0, 0xFF, 0xFC, 0xFF, 0xBE,
3504 0xFF, 0x6D, 0xFF, 0xF3, 0xFF, 0x5E, 0x02, 0xDC, 0x06, 0x23, 0x0C,
3505 0xEF, 0x0F, 0x63, 0x10, 0x43, 0x0D, 0x1F, 0x08, 0x46, 0x03, 0x53,
3506 0x00, 0x6E, 0xFF, 0xA6, 0xFF, 0xF4, 0xFF, 0xEF, 0xFF, 0x9B, 0xFF,
3507 0x75, 0xFF, 0x8D, 0x00, 0xC1, 0x03, 0xBE, 0x08, 0xC4, 0x0D, 0x88,
3508 0x10, 0xA4, 0x0F, 0x8E, 0x0B, 0x43, 0x06, 0xF9, 0x01, 0xCF, 0xFF,
3509 0x71, 0xFF, 0xC8, 0xFF, 0xFE, 0xFF, 0x00, 0x00, 0xD8, 0xFF, 0x7C,
3510 0xFF, 0xA4, 0xFF, 0x6E, 0x01, 0x61, 0x05, 0xA3, 0x0A, 0x1C, 0x0F,
3511 0xA7, 0x10, 0x7B, 0x0E, 0xB2, 0x09, 0x8B, 0x04, 0xF4, 0x00, 0x86,
3512 0xFF, 0x8A, 0xFF, 0xE4, 0xFF, 0xFA, 0xFF, 0xB8, 0xFF, 0x6C, 0xFF,
3513 0x09, 0x00, 0x97, 0x02, 0x2E, 0x07, 0x6F, 0x0C, 0x11, 0x10, 0x4A,
3514 0x10, 0xFB, 0x0C, 0xCB, 0x07, 0x07, 0x03, 0x38, 0x00, 0x6D, 0xFF,
3515 0xAC, 0xFF, 0xF7, 0xFF, 0xEC, 0xFF, 0x95, 0xFF, 0x79, 0xFF, 0xAF,
3516 0x00, 0x05, 0x04, 0x13, 0x09, 0x06, 0x0E, 0x96, 0x10, 0x78, 0x0F,
3517 0x3E, 0x0B, 0xF4, 0x05, 0xC7, 0x01, 0xBF, 0xFF, 0x74, 0xFF, 0xCE,
3518 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xD2, 0xFF, 0x78, 0xFF, 0xB1, 0xFF,
3519 0x9C, 0x01, 0xAE, 0x05, 0xF6, 0x0A, 0x4E, 0x0F, 0x9F, 0x10, 0x3E,
3520 0x0E, 0x5E, 0x09, 0x43, 0x04, 0xCF, 0x00, 0x7F, 0xFF, 0x90, 0xFF,
3521 0xE8, 0xFF, 0xF9, 0xFF, 0xB2, 0xFF, 0x6C, 0xFF, 0x21, 0x00, 0xD2,
3522 0x02, 0x81, 0x07, 0xBA, 0x0C, 0x31, 0x10, 0x2E, 0x10, 0xB2, 0x0C,
3523 0x78, 0x07, 0xCB, 0x02, 0x1E, 0x00, 0x6C, 0xFF, 0xB2, 0xFF, 0xF9,
3524 0xFF, 0xE8, 0xFF, 0x8F, 0xFF, 0x80, 0xFF, 0xD3, 0x00, 0x4B, 0x04,
3525 0x67, 0x09, 0x45, 0x0E, 0xA0, 0x10, 0x48, 0x0F, 0xEC, 0x0A, 0xA6,
3526 0x05, 0x97, 0x01, 0xB0, 0xFF, 0x78, 0xFF, 0xD3, 0xFF, 0x00, 0x00,
3527 0xFF, 0xFF, 0xCD, 0xFF, 0x74, 0xFF, 0xC0, 0xFF, 0xCC, 0x01, 0xFD,
3528 0x05, 0x47, 0x0B, 0x7D, 0x0F, 0x94, 0x10, 0xFF, 0x0D, 0x0A, 0x09,
3529 0xFE, 0x03, 0xAB, 0x00, 0x79, 0xFF, 0x95, 0xFF, 0xEC, 0xFF, 0xF7,
3530 0xFF, 0xAC, 0xFF, 0x6D, 0xFF, 0x3B, 0x00, 0x0E, 0x03, 0xD5, 0x07,
3531 0x03, 0x0D, 0x4D, 0x10, 0x0E, 0x10, 0x67, 0x0C, 0x25, 0x07, 0x91,
3532 0x02, 0x07, 0x00, 0x6C, 0xFF, 0xB8, 0xFF, 0xFB, 0xFF, 0xE4, 0xFF,
3533 0x89, 0xFF, 0x87, 0xFF, 0xF9, 0x00, 0x93, 0x04, 0xBC, 0x09, 0x82,
3534 0x0E, 0xA7, 0x10, 0x16, 0x0F, 0x9A, 0x0A, 0x59, 0x05, 0x69, 0x01,
3535 0xA3, 0xFF, 0x7C, 0xFF, 0xD8, 0xFF, 0x00, 0x00, 0xFE, 0xFF, 0xC8,
3536 0xFF, 0x71, 0xFF, 0xD1, 0xFF, 0xFF, 0x01, 0x4C, 0x06, 0x97, 0x0B,
3537 0xA9, 0x0F, 0x86, 0x10, 0xBD, 0x0D, 0xB5, 0x08, 0xBA, 0x03, 0x8A,
3538 0x00, 0x74, 0xFF, 0x9B, 0xFF, 0xEF, 0xFF, 0xF4, 0xFF, 0xA5, 0xFF,
3539 0x6F, 0xFF, 0x57, 0x00, 0x4D, 0x03, 0x29, 0x08, 0x4B, 0x0D, 0x65,
3540 0x10, 0xEB, 0x0F, 0x1A, 0x0C, 0xD3, 0x06, 0x58, 0x02, 0xF1, 0xFF,
3541 0x6D, 0xFF, 0xBE, 0xFF, 0xFC, 0xFF, 0xE0, 0xFF, 0x84, 0xFF, 0x90,
3542 0xFF, 0x21, 0x01, 0xDC, 0x04, 0x10, 0x0A, 0xBB, 0x0E, 0xAA, 0x10,
3543 0xE1, 0x0E, 0x47, 0x0A, 0x0D, 0x05, 0x3D, 0x01, 0x97, 0xFF, 0x81,
3544 0xFF, 0xDD, 0xFF, 0x00, 0x00, 0xFD, 0xFF, 0xC2, 0xFF, 0x6F, 0xFF,
3545 0xE4, 0xFF, 0x34, 0x02, 0x9D, 0x06, 0xE6, 0x0B, 0xD1, 0x0F, 0x73,
3546 0x10, 0x79, 0x0D, 0x61, 0x08, 0x78, 0x03, 0x6A, 0x00, 0x70, 0xFF,
3547 0xA1, 0xFF, 0xF2, 0xFF, 0xF1, 0xFF, 0x9F, 0xFF, 0x72, 0xFF, 0x74,
3548 0x00, 0x8E, 0x03, 0x7D, 0x08, 0x90, 0x0D, 0x7A, 0x10, 0xC4, 0x0F,
3549 0xCC, 0x0B, 0x82, 0x06, 0x22, 0x02, 0xDD, 0xFF, 0x6F, 0xFF, 0xC4,
3550 0xFF, 0xFD, 0xFF, 0x00, 0x00, 0xDB, 0xFF, 0x7F, 0xFF, 0x9B, 0xFF,
3551 0x4B, 0x01, 0x26, 0x05, 0x63, 0x0A, 0xF3, 0x0E, 0xAA, 0x10, 0xA8,
3552 0x0E, 0xF4, 0x09, 0xC3, 0x04, 0x13, 0x01, 0x8D, 0xFF, 0x86, 0xFF,
3553 0xE1, 0xFF, 0xFC, 0xFF, 0xBC, 0xFF, 0x6D, 0xFF, 0xF8, 0xFF, 0x6B,
3554 0x02, 0xEE, 0x06, 0x34, 0x0C, 0xF7, 0x0F, 0x5D, 0x10, 0x33, 0x0D,
3555 0x0D, 0x08, 0x38, 0x03, 0x4D, 0x00, 0x6E, 0xFF, 0xA7, 0xFF, 0xF5,
3556 0xFF, 0xEE, 0xFF, 0x99, 0xFF, 0x76, 0xFF, 0x94, 0x00, 0xD0, 0x03,
3557 0xD1, 0x08, 0xD3, 0x0D, 0x8B, 0x10, 0x9A, 0x0F, 0x7C, 0x0B, 0x32,
3558 0x06, 0xEE, 0x01, 0xCB, 0xFF, 0x72, 0xFF, 0xCA, 0xFF, 0xFE, 0xFF,
3559 0x00, 0x00, 0xD6, 0xFF, 0x7B, 0xFF, 0xA7, 0xFF, 0x78, 0x01, 0x72,
3560 0x05, 0xB6, 0x0A, 0x27, 0x0F, 0xA5, 0x10, 0x6E, 0x0E, 0xA0, 0x09,
3561 0x7B, 0x04, 0xEC, 0x00, 0x85, 0xFF, 0x8B, 0xFF, 0xE5, 0xFF, 0xFA,
3562 0xFF, 0xB6, 0xFF, 0x6C, 0xFF, 0x0E, 0x00, 0xA4, 0x02, 0x41, 0x07,
3563 0x80, 0x0C, 0x19, 0x10, 0x44, 0x10, 0xEB, 0x0C, 0xB9, 0x07, 0xFA,
3564 0x02, 0x32, 0x00, 0x6D, 0xFF, 0xAE, 0xFF, 0xF7, 0xFF, 0xEB, 0xFF,
3565 0x93, 0xFF, 0x7B, 0xFF, 0xB7, 0x00, 0x15, 0x04, 0x26, 0x09, 0x14,
3566 0x0E, 0x98, 0x10, 0x6D, 0x0F, 0x2C, 0x0B, 0xE3, 0x05, 0xBC, 0x01,
3567 0xBB, 0xFF, 0x75, 0xFF, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xD1,
3568 0xFF, 0x77, 0xFF, 0xB5, 0xFF, 0xA6, 0x01, 0xC0, 0x05, 0x08, 0x0B,
3569 0x58, 0x0F, 0x9D, 0x10, 0x30, 0x0E, 0x4B, 0x09, 0x34, 0x04, 0xC6,
3570 0x00, 0x7D, 0xFF, 0x91, 0xFF, 0xE9, 0xFF, 0xF8, 0xFF, 0xB0, 0xFF,
3571 0x6C, 0xFF, 0x27, 0x00, 0xDF, 0x02, 0x94, 0x07, 0xCA, 0x0C, 0x37,
3572 0x10, 0x27, 0x10, 0xA1, 0x0C, 0x65, 0x07, 0xBE, 0x02, 0x19, 0x00,
3573 0x6C, 0xFF, 0xB4, 0xFF, 0xF9, 0xFF, 0xE7, 0xFF, 0x8E, 0xFF, 0x81,
3574 0xFF, 0xDB, 0x00, 0x5B, 0x04, 0x7A, 0x09, 0x53, 0x0E, 0xA2, 0x10,
3575 0x3D, 0x0F, 0xDA, 0x0A, 0x95, 0x05, 0x8C, 0x01, 0xAD, 0xFF, 0x79,
3576 0xFF, 0xD4, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xCC, 0xFF, 0x73, 0xFF,
3577 0xC4, 0xFF, 0xD7, 0x01, 0x0E, 0x06, 0x59, 0x0B, 0x87, 0x0F, 0x91,
3578 0x10, 0xF0, 0x0D, 0xF7, 0x08, 0xEF, 0x03, 0xA3, 0x00, 0x78, 0xFF,
3579 0x97, 0xFF, 0xED, 0xFF, 0xF6, 0xFF, 0xAA, 0xFF, 0x6D, 0xFF, 0x41,
3580 0x00, 0x1C, 0x03, 0xE7, 0x07, 0x13, 0x0D, 0x52, 0x10, 0x06, 0x10,
3581 0x56, 0x0C, 0x13, 0x07, 0x84, 0x02, 0x02, 0x00, 0x6D, 0xFF, 0xBA,
3582 0xFF, 0xFB, 0xFF, 0xE3, 0xFF, 0x88, 0xFF, 0x89, 0xFF, 0x01, 0x01,
3583 0xA3, 0x04, 0xCE, 0x09, 0x8F, 0x0E, 0xA8, 0x10, 0x0A, 0x0F, 0x88,
3584 0x0A, 0x48, 0x05, 0x5F, 0x01, 0xA0, 0xFF, 0x7D, 0xFF, 0xD9, 0xFF,
3585 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0xFF, 0x70, 0xFF, 0xD5, 0xFF, 0x0B,
3586 0x02, 0x5E, 0x06, 0xA9, 0x0B, 0xB2, 0x0F, 0x82, 0x10, 0xAE, 0x0D,
3587 0xA2, 0x08, 0xAB, 0x03, 0x82, 0x00, 0x73, 0xFF, 0x9D, 0xFF, 0xF0,
3588 0xFF, 0xF3, 0xFF, 0xA4, 0xFF, 0x6F, 0xFF, 0x5D, 0x00, 0x5B, 0x03,
3589 0x3B, 0x08, 0x5A, 0x0D, 0x6A, 0x10, 0xE2, 0x0F, 0x09, 0x0C, 0xC1,
3590 0x06, 0x4C, 0x02, 0xEC, 0xFF, 0x6E, 0xFF, 0xC0, 0xFF, 0xFC, 0xFF,
3591 0xDF, 0xFF, 0x83, 0xFF, 0x93, 0xFF, 0x2A, 0x01, 0xEC, 0x04, 0x22,
3592 0x0A, 0xC8, 0x0E, 0xAB, 0x10, 0xD4, 0x0E, 0x35, 0x0A, 0xFD, 0x04,
3593 0x33, 0x01, 0x95, 0xFF, 0x82, 0xFF, 0xDE, 0xFF, 0x00, 0x00, 0xFD,
3594 0xFF, 0xC1, 0xFF, 0x6E, 0xFF, 0xE8, 0xFF, 0x40, 0x02, 0xAF, 0x06,
3595 0xF7, 0x0B, 0xDA, 0x0F, 0x6F, 0x10, 0x6A, 0x0D, 0x4E, 0x08, 0x6A,
3596 0x03, 0x64, 0x00, 0x70, 0xFF, 0xA3, 0xFF, 0xF3, 0xFF, 0xF1, 0xFF,
3597 0x9E, 0xFF, 0x72, 0xFF, 0x7B, 0x00, 0x9C, 0x03, 0x90, 0x08, 0x9F,
3598 0x0D, 0x7E, 0x10, 0xBB, 0x0F, 0xBA, 0x0B, 0x70, 0x06, 0x16, 0x02,
3599 0xD9, 0xFF, 0x70, 0xFF, 0xC5, 0xFF, 0xFE, 0xFF, 0x00, 0x00, 0xDA,
3600 0xFF, 0x7E, 0xFF, 0x9D, 0xFF, 0x55, 0x01, 0x37, 0x05, 0x75, 0x0A,
3601 0xFF, 0x0E, 0xA9, 0x10, 0x9C, 0x0E, 0xE1, 0x09, 0xB3, 0x04, 0x0A,
3602 0x01, 0x8B, 0xFF, 0x87, 0xFF, 0xE2, 0xFF, 0xFB, 0xFF, 0xBB, 0xFF,
3603 0x6D, 0xFF, 0xFD, 0xFF, 0x77, 0x02, 0x01, 0x07, 0x45, 0x0C, 0xFF,
3604 0x0F, 0x58, 0x10, 0x23, 0x0D, 0xFA, 0x07, 0x2A, 0x03, 0x47, 0x00,
3605 0x6E, 0xFF, 0xA9, 0xFF, 0xF5, 0xFF, 0xED, 0xFF, 0x98, 0xFF, 0x77,
3606 0xFF, 0x9C, 0x00, 0xDF, 0x03, 0xE4, 0x08, 0xE2, 0x0D, 0x8E, 0x10,
3607 0x91, 0x0F, 0x6B, 0x0B, 0x20, 0x06, 0xE3, 0x01, 0xC8, 0xFF, 0x73,
3608 0xFF, 0xCB, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xD5, 0xFF, 0x7A, 0xFF,
3609 0xAA, 0xFF, 0x82, 0x01, 0x83, 0x05, 0xC8, 0x0A, 0x32, 0x0F, 0xA4,
3610 0x10, 0x60, 0x0E, 0x8D, 0x09, 0x6B, 0x04, 0xE3, 0x00, 0x83, 0xFF,
3611 0x8D, 0xFF, 0xE6, 0xFF, 0xFA, 0xFF, 0xB5, 0xFF, 0x6C, 0xFF, 0x14,
3612 0x00, 0xB1, 0x02, 0x53, 0x07, 0x91, 0x0C, 0x20, 0x10, 0x3E, 0x10,
3613 0xDB, 0x0C, 0xA6, 0x07, 0xEC, 0x02, 0x2C, 0x00, 0x6C, 0xFF, 0xAF,
3614 0xFF, 0xF8, 0xFF, 0xEA, 0xFF, 0x92, 0xFF, 0x7C, 0xFF, 0xBE, 0x00,
3615 0x24, 0x04, 0x38, 0x09, 0x22, 0x0E, 0x9B, 0x10, 0x63, 0x0F, 0x1A,
3616 0x0B, 0xD1, 0x05, 0xB1, 0x01, 0xB8, 0xFF, 0x76, 0xFF, 0xD0, 0xFF,
3617 0xFF, 0xFF, 0xFF, 0xFF, 0xD0, 0xFF, 0x76, 0xFF, 0xB8, 0xFF, 0xB1,
3618 0x01, 0xD1, 0x05, 0x1A, 0x0B, 0x63, 0x0F, 0x9B, 0x10, 0x22, 0x0E,
3619 0x38, 0x09, 0x24, 0x04, 0xBE, 0x00, 0x7C, 0xFF, 0x92, 0xFF, 0xEA,
3620 0xFF, 0xF8, 0xFF, 0xAF, 0xFF, 0x6C, 0xFF, 0x2C, 0x00, 0xEC, 0x02,
3621 0xA6, 0x07, 0xDB, 0x0C, 0x3E, 0x10, 0x20, 0x10, 0x91, 0x0C, 0x53,
3622 0x07, 0xB1, 0x02, 0x14, 0x00, 0x6C, 0xFF, 0xB5, 0xFF, 0xFA, 0xFF,
3623 0xE6, 0xFF, 0x8D, 0xFF, 0x83, 0xFF, 0xE3, 0x00, 0x6B, 0x04, 0x8D,
3624 0x09, 0x60, 0x0E, 0xA4, 0x10, 0x32, 0x0F, 0xC8, 0x0A, 0x83, 0x05,
3625 0x82, 0x01, 0xAA, 0xFF, 0x7A, 0xFF, 0xD5, 0xFF, 0x00, 0x00, 0xFF,
3626 0xFF, 0xCB, 0xFF, 0x73, 0xFF, 0xC8, 0xFF, 0xE3, 0x01, 0x20, 0x06,
3627 0x6B, 0x0B, 0x91, 0x0F, 0x8E, 0x10, 0xE2, 0x0D, 0xE4, 0x08, 0xDF,
3628 0x03, 0x9C, 0x00, 0x77, 0xFF, 0x98, 0xFF, 0xED, 0xFF, 0xF5, 0xFF,
3629 0xA9, 0xFF, 0x6E, 0xFF, 0x47, 0x00, 0x2A, 0x03, 0xFA, 0x07, 0x23,
3630 0x0D, 0x58, 0x10, 0xFF, 0x0F, 0x45, 0x0C, 0x01, 0x07, 0x77, 0x02,
3631 0xFD, 0xFF, 0x6D, 0xFF, 0xBB, 0xFF, 0xFB, 0xFF, 0xE2, 0xFF, 0x87,
3632 0xFF, 0x8B, 0xFF, 0x0A, 0x01, 0xB3, 0x04, 0xE1, 0x09, 0x9C, 0x0E,
3633 0xA9, 0x10, 0xFF, 0x0E, 0x75, 0x0A, 0x37, 0x05, 0x55, 0x01, 0x9D,
3634 0xFF, 0x7E, 0xFF, 0xDA, 0xFF, 0x00, 0x00, 0xFE, 0xFF, 0xC5, 0xFF,
3635 0x70, 0xFF, 0xD9, 0xFF, 0x16, 0x02, 0x70, 0x06, 0xBA, 0x0B, 0xBB,
3636 0x0F, 0x7E, 0x10, 0x9F, 0x0D, 0x90, 0x08, 0x9C, 0x03, 0x7B, 0x00,
3637 0x72, 0xFF, 0x9E, 0xFF, 0xF1, 0xFF, 0xF3, 0xFF, 0xA3, 0xFF, 0x70,
3638 0xFF, 0x64, 0x00, 0x6A, 0x03, 0x4E, 0x08, 0x6A, 0x0D, 0x6F, 0x10,
3639 0xDA, 0x0F, 0xF7, 0x0B, 0xAF, 0x06, 0x40, 0x02, 0xE8, 0xFF, 0x6E,
3640 0xFF, 0xC1, 0xFF, 0xFD, 0xFF, 0x00, 0x00, 0xDE, 0xFF, 0x82, 0xFF,
3641 0x95, 0xFF, 0x33, 0x01, 0xFD, 0x04, 0x35, 0x0A, 0xD4, 0x0E, 0xAB,
3642 0x10, 0xC8, 0x0E, 0x22, 0x0A, 0xEC, 0x04, 0x2A, 0x01, 0x93, 0xFF,
3643 0x83, 0xFF, 0xDF, 0xFF, 0xFC, 0xFF, 0xC0, 0xFF, 0x6E, 0xFF, 0xEC,
3644 0xFF, 0x4C, 0x02, 0xC1, 0x06, 0x09, 0x0C, 0xE2, 0x0F, 0x6A, 0x10,
3645 0x5A, 0x0D, 0x3B, 0x08, 0x5B, 0x03, 0x5D, 0x00, 0x6F, 0xFF, 0xA4,
3646 0xFF, 0xF3, 0xFF, 0xF0, 0xFF, 0x9D, 0xFF, 0x73, 0xFF, 0x82, 0x00,
3647 0xAB, 0x03, 0xA2, 0x08, 0xAE, 0x0D, 0x82, 0x10, 0xB2, 0x0F, 0xA9,
3648 0x0B, 0x5E, 0x06, 0x0B, 0x02, 0xD5, 0xFF, 0x70, 0xFF, 0xC7, 0xFF,
3649 0xFE, 0xFF, 0x00, 0x00, 0xD9, 0xFF, 0x7D, 0xFF, 0xA0, 0xFF, 0x5F,
3650 0x01, 0x48, 0x05, 0x88, 0x0A, 0x0A, 0x0F, 0xA8, 0x10, 0x8F, 0x0E,
3651 0xCE, 0x09, 0xA3, 0x04, 0x01, 0x01, 0x89, 0xFF, 0x88, 0xFF, 0xE3,
3652 0xFF, 0xFB, 0xFF, 0xBA, 0xFF, 0x6D, 0xFF, 0x02, 0x00, 0x84, 0x02,
3653 0x13, 0x07, 0x56, 0x0C, 0x06, 0x10, 0x52, 0x10, 0x13, 0x0D, 0xE7,
3654 0x07, 0x1C, 0x03, 0x41, 0x00, 0x6D, 0xFF, 0xAA, 0xFF, 0xF6, 0xFF,
3655 0xED, 0xFF, 0x97, 0xFF, 0x78, 0xFF, 0xA3, 0x00, 0xEF, 0x03, 0xF7,
3656 0x08, 0xF0, 0x0D, 0x91, 0x10, 0x87, 0x0F, 0x59, 0x0B, 0x0E, 0x06,
3657 0xD7, 0x01, 0xC4, 0xFF, 0x73, 0xFF, 0xCC, 0xFF, 0xFF, 0xFF, 0x00,
3658 0x00, 0xD4, 0xFF, 0x79, 0xFF, 0xAD, 0xFF, 0x8C, 0x01, 0x95, 0x05,
3659 0xDA, 0x0A, 0x3D, 0x0F, 0xA2, 0x10, 0x53, 0x0E, 0x7A, 0x09, 0x5B,
3660 0x04, 0xDB, 0x00, 0x81, 0xFF, 0x8E, 0xFF, 0xE7, 0xFF, 0xF9, 0xFF,
3661 0xB4, 0xFF, 0x6C, 0xFF, 0x19, 0x00, 0xBE, 0x02, 0x65, 0x07, 0xA1,
3662 0x0C, 0x27, 0x10, 0x37, 0x10, 0xCA, 0x0C, 0x94, 0x07, 0xDF, 0x02,
3663 0x27, 0x00, 0x6C, 0xFF, 0xB0, 0xFF, 0xF8, 0xFF, 0xE9, 0xFF, 0x91,
3664 0xFF, 0x7D, 0xFF, 0xC6, 0x00, 0x34, 0x04, 0x4B, 0x09, 0x30, 0x0E,
3665 0x9D, 0x10, 0x58, 0x0F, 0x08, 0x0B, 0xC0, 0x05, 0xA6, 0x01, 0xB5,
3666 0xFF, 0x77, 0xFF, 0xD1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xCF, 0xFF,
3667 0x75, 0xFF, 0xBB, 0xFF, 0xBC, 0x01, 0xE3, 0x05, 0x2C, 0x0B, 0x6D,
3668 0x0F, 0x98, 0x10, 0x14, 0x0E, 0x26, 0x09, 0x15, 0x04, 0xB7, 0x00,
3669 0x7B, 0xFF, 0x93, 0xFF, 0xEB, 0xFF, 0xF7, 0xFF, 0xAE, 0xFF, 0x6D,
3670 0xFF, 0x32, 0x00, 0xFA, 0x02, 0xB9, 0x07, 0xEB, 0x0C, 0x44, 0x10,
3671 0x19, 0x10, 0x80, 0x0C, 0x41, 0x07, 0xA4, 0x02, 0x0E, 0x00, 0x6C,
3672 0xFF, 0xB6, 0xFF, 0xFA, 0xFF, 0xE5, 0xFF, 0x8B, 0xFF, 0x85, 0xFF,
3673 0xEC, 0x00, 0x7B, 0x04, 0xA0, 0x09, 0x6E, 0x0E, 0xA5, 0x10, 0x27,
3674 0x0F, 0xB6, 0x0A, 0x72, 0x05, 0x78, 0x01, 0xA7, 0xFF, 0x7B, 0xFF,
3675 0xD6, 0xFF, 0x00, 0x00, 0xFE, 0xFF, 0xCA, 0xFF, 0x72, 0xFF, 0xCB,
3676 0xFF, 0xEE, 0x01, 0x32, 0x06, 0x7C, 0x0B, 0x9A, 0x0F, 0x8B, 0x10,
3677 0xD3, 0x0D, 0xD1, 0x08, 0xD0, 0x03, 0x94, 0x00, 0x76, 0xFF, 0x99,
3678 0xFF, 0xEE, 0xFF, 0xF5, 0xFF, 0xA7, 0xFF, 0x6E, 0xFF, 0x4D, 0x00,
3679 0x38, 0x03, 0x0D, 0x08, 0x33, 0x0D, 0x5D, 0x10, 0xF7, 0x0F, 0x34,
3680 0x0C, 0xEE, 0x06, 0x6B, 0x02, 0xF8, 0xFF, 0x6D, 0xFF, 0xBC, 0xFF,
3681 0xFC, 0xFF, 0xE1, 0xFF, 0x86, 0xFF, 0x8D, 0xFF, 0x13, 0x01, 0xC3,
3682 0x04, 0xF4, 0x09, 0xA8, 0x0E, 0xAA, 0x10, 0xF3, 0x0E, 0x63, 0x0A,
3683 0x26, 0x05, 0x4B, 0x01, 0x9B, 0xFF, 0x7F, 0xFF, 0xDB, 0xFF, 0x00,
3684 0x00, 0xFD, 0xFF, 0xC4, 0xFF, 0x6F, 0xFF, 0xDD, 0xFF, 0x22, 0x02,
3685 0x82, 0x06, 0xCC, 0x0B, 0xC4, 0x0F, 0x7A, 0x10, 0x90, 0x0D, 0x7D,
3686 0x08, 0x8E, 0x03, 0x74, 0x00, 0x72, 0xFF, 0x9F, 0xFF, 0xF1, 0xFF,
3687 0xF2, 0xFF, 0xA1, 0xFF, 0x70, 0xFF, 0x6A, 0x00, 0x78, 0x03, 0x61,
3688 0x08, 0x79, 0x0D, 0x73, 0x10, 0xD1, 0x0F, 0xE6, 0x0B, 0x9D, 0x06,
3689 0x34, 0x02, 0xE4, 0xFF, 0x6F, 0xFF, 0xC2, 0xFF, 0xFD, 0xFF, 0x00,
3690 0x00, 0xDD, 0xFF, 0x81, 0xFF, 0x97, 0xFF, 0x3D, 0x01, 0x0D, 0x05,
3691 0x47, 0x0A, 0xE1, 0x0E, 0xAA, 0x10, 0xBB, 0x0E, 0x10, 0x0A, 0xDC,
3692 0x04, 0x21, 0x01, 0x90, 0xFF, 0x84, 0xFF, 0xE0, 0xFF, 0xFC, 0xFF,
3693 0xBE, 0xFF, 0x6D, 0xFF, 0xF1, 0xFF, 0x58, 0x02, 0xD3, 0x06, 0x1A,
3694 0x0C, 0xEB, 0x0F, 0x65, 0x10, 0x4B, 0x0D, 0x29, 0x08, 0x4D, 0x03,
3695 0x57, 0x00, 0x6F, 0xFF, 0xA5, 0xFF, 0xF4, 0xFF, 0xEF, 0xFF, 0x9B,
3696 0xFF, 0x74, 0xFF, 0x8A, 0x00, 0xBA, 0x03, 0xB5, 0x08, 0xBD, 0x0D,
3697 0x86, 0x10, 0xA9, 0x0F, 0x97, 0x0B, 0x4C, 0x06, 0xFF, 0x01, 0xD1,
3698 0xFF, 0x71, 0xFF, 0xC8, 0xFF, 0xFE, 0xFF, 0x00, 0x00, 0xD8, 0xFF,
3699 0x7C, 0xFF, 0xA3, 0xFF, 0x69, 0x01, 0x59, 0x05, 0x9A, 0x0A, 0x16,
3700 0x0F, 0xA7, 0x10, 0x82, 0x0E, 0xBC, 0x09, 0x93, 0x04, 0xF9, 0x00,
3701 0x87, 0xFF, 0x89, 0xFF, 0xE4, 0xFF, 0xFB, 0xFF, 0xB8, 0xFF, 0x6C,
3702 0xFF, 0x07, 0x00, 0x91, 0x02, 0x25, 0x07, 0x67, 0x0C, 0x0E, 0x10,
3703 0x4D, 0x10, 0x03, 0x0D, 0xD5, 0x07, 0x0E, 0x03, 0x3B, 0x00, 0x6D,
3704 0xFF, 0xAC, 0xFF, 0xF7, 0xFF, 0xEC, 0xFF, 0x95, 0xFF, 0x79, 0xFF,
3705 0xAB, 0x00, 0xFE, 0x03, 0x0A, 0x09, 0xFF, 0x0D, 0x94, 0x10, 0x7D,
3706 0x0F, 0x47, 0x0B, 0xFD, 0x05, 0xCC, 0x01, 0xC0, 0xFF, 0x74, 0xFF,
3707 0xCD, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xD3, 0xFF, 0x78, 0xFF, 0xB0,
3708 0xFF, 0x97, 0x01, 0xA6, 0x05, 0xEC, 0x0A, 0x48, 0x0F, 0xA0, 0x10,
3709 0x45, 0x0E, 0x67, 0x09, 0x4B, 0x04, 0xD3, 0x00, 0x80, 0xFF, 0x8F,
3710 0xFF, 0xE8, 0xFF, 0xF9, 0xFF, 0xB2, 0xFF, 0x6C, 0xFF, 0x1E, 0x00,
3711 0xCB, 0x02, 0x78, 0x07, 0xB2, 0x0C, 0x2E, 0x10, 0x31, 0x10, 0xBA,
3712 0x0C, 0x81, 0x07, 0xD2, 0x02, 0x21, 0x00, 0x6C, 0xFF, 0xB2, 0xFF,
3713 0xF9, 0xFF, 0xE8, 0xFF, 0x90, 0xFF, 0x7F, 0xFF, 0xCF, 0x00, 0x43,
3714 0x04, 0x5E, 0x09, 0x3E, 0x0E, 0x9F, 0x10, 0x4E, 0x0F, 0xF6, 0x0A,
3715 0xAE, 0x05, 0x9C, 0x01, 0xB1, 0xFF, 0x78, 0xFF, 0xD2, 0xFF, 0xFF,
3716 0xFF, 0xFF, 0xFF, 0xCE, 0xFF, 0x74, 0xFF, 0xBF, 0xFF, 0xC7, 0x01,
3717 0xF4, 0x05, 0x3E, 0x0B, 0x78, 0x0F, 0x96, 0x10, 0x06, 0x0E, 0x13,
3718 0x09, 0x05, 0x04, 0xAF, 0x00, 0x79, 0xFF, 0x95, 0xFF, 0xEC, 0xFF,
3719 0xF7, 0xFF, 0xAC, 0xFF, 0x6D, 0xFF, 0x38, 0x00, 0x07, 0x03, 0xCB,
3720 0x07, 0xFB, 0x0C, 0x4A, 0x10, 0x11, 0x10, 0x6F, 0x0C, 0x2E, 0x07,
3721 0x97, 0x02, 0x09, 0x00, 0x6C, 0xFF, 0xB8, 0xFF, 0xFA, 0xFF, 0xE4,
3722 0xFF, 0x8A, 0xFF, 0x86, 0xFF, 0xF4, 0x00, 0x8B, 0x04, 0xB2, 0x09,
3723 0x7B, 0x0E, 0xA7, 0x10, 0x1C, 0x0F, 0xA3, 0x0A, 0x61, 0x05, 0x6E,
3724 0x01, 0xA4, 0xFF, 0x7C, 0xFF, 0xD8, 0xFF, 0x00, 0x00, 0xFE, 0xFF,
3725 0xC8, 0xFF, 0x71, 0xFF, 0xCF, 0xFF, 0xF9, 0x01, 0x43, 0x06, 0x8E,
3726 0x0B, 0xA4, 0x0F, 0x88, 0x10, 0xC4, 0x0D, 0xBE, 0x08, 0xC1, 0x03,
3727 0x8D, 0x00, 0x75, 0xFF, 0x9B, 0xFF, 0xEF, 0xFF, 0xF4, 0xFF, 0xA6,
3728 0xFF, 0x6E, 0xFF, 0x53, 0x00, 0x46, 0x03, 0x1F, 0x08, 0x43, 0x0D,
3729 0x63, 0x10, 0xEF, 0x0F, 0x23, 0x0C, 0xDC, 0x06, 0x5E, 0x02, 0xF3,
3730 0xFF, 0x6D, 0xFF, 0xBE, 0xFF, 0xFC, 0xFF, 0xE0, 0xFF, 0x85, 0xFF,
3731 0x8F, 0xFF, 0x1C, 0x01, 0xD3, 0x04, 0x06, 0x0A, 0xB5, 0x0E, 0xAA,
3732 0x10, 0xE7, 0x0E, 0x50, 0x0A, 0x16, 0x05, 0x42, 0x01, 0x98, 0xFF,
3733 0x80, 0xFF, 0xDC, 0xFF, 0x00, 0x00, 0xFD, 0xFF, 0xC3, 0xFF, 0x6F,
3734 0xFF, 0xE1, 0xFF, 0x2E, 0x02, 0x94, 0x06, 0xDD, 0x0B, 0xCD, 0x0F,
3735 0x76, 0x10, 0x81, 0x0D, 0x6A, 0x08, 0x7F, 0x03, 0x6E, 0x00, 0x71,
3736 0xFF, 0xA1, 0xFF, 0xF2, 0xFF, 0x00, 0x00, 0x15, 0x00, 0xD1, 0xFF,
3737 0x8B, 0xFE, 0xBC, 0xFD, 0xE1, 0x00, 0x84, 0x09, 0xB0, 0x13, 0x47,
3738 0x18, 0xB0, 0x13, 0x84, 0x09, 0xE1, 0x00, 0xBC, 0xFD, 0x8B, 0xFE,
3739 0xD1, 0xFF, 0x15, 0x00, 0xFD, 0xFF, 0x13, 0x00, 0xDA, 0x00, 0x30,
3740 0x00, 0x5D, 0xFC, 0xB3, 0xFC, 0x35, 0x0A, 0xC2, 0x1C, 0x24, 0x20,
3741 0x48, 0x10, 0x5D, 0xFF, 0x74, 0xFB, 0x3A, 0xFF, 0xFB, 0x00, 0x42,
3742 0x00, 0xF8, 0xFF, 0xFA, 0xFF, 0x2C, 0x00, 0xF3, 0x00, 0xAD, 0xFF,
3743 0xC5, 0xFB, 0x11, 0xFE, 0xAF, 0x0D, 0xEF, 0x1E, 0x68, 0x1E, 0xBC,
3744 0x0C, 0xA7, 0xFD, 0xEA, 0xFB, 0xD3, 0xFF, 0xEE, 0x00, 0x24, 0x00,
3745 0xFA, 0xFF, 0xF7, 0xFF, 0x4C, 0x00, 0xFB, 0x00, 0x0C, 0xFF, 0x5F,
3746 0xFB, 0xE8, 0xFF, 0x3D, 0x11, 0x7E, 0x20, 0x13, 0x1C, 0x4C, 0x09,
3747 0x6A, 0xFC, 0x8C, 0xFC, 0x4E, 0x00, 0xD1, 0x00, 0x0E, 0x00, 0xFD,
3748 0xFF, 0xF7, 0xFF, 0x72, 0x00, 0xEC, 0x00, 0x55, 0xFE, 0x3D, 0xFB,
3749 0x37, 0x02, 0xBE, 0x14, 0x5D, 0x21, 0x40, 0x19, 0x18, 0x06, 0xA2,
3750 0xFB, 0x47, 0xFD, 0xA7, 0x00, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00,
3751 0x00, 0x00, 0xFC, 0xFF, 0x9B, 0x00, 0xC0, 0x00, 0x92, 0xFD, 0x73,
3752 0xFB, 0xF2, 0x04, 0x0E, 0x18, 0x81, 0x21, 0x0C, 0x16, 0x37, 0x03,
3753 0x47, 0xFB, 0x0B, 0xFE, 0xDF, 0x00, 0x82, 0x00, 0xF9, 0xFF, 0xFE,
3754 0xFF, 0x08, 0x00, 0xC3, 0x00, 0x74, 0x00, 0xD2, 0xFC, 0x10, 0xFC,
3755 0x08, 0x08, 0x0A, 0x1B, 0xE9, 0x20, 0x9A, 0x12, 0xBE, 0x00, 0x49,
3756 0xFB, 0xC8, 0xFE, 0xF9, 0x00, 0x5A, 0x00, 0xF7, 0xFF, 0xFC, 0xFF,
3757 0x1B, 0x00, 0xE4, 0x00, 0x06, 0x00, 0x24, 0xFC, 0x1E, 0xFD, 0x65,
3758 0x0B, 0x94, 0x1D, 0x9D, 0x1F, 0x0D, 0x0F, 0xB8, 0xFE, 0x96, 0xFB,
3759 0x72, 0xFF, 0xF9, 0x00, 0x37, 0x00, 0xF8, 0xFF, 0xF9, 0xFF, 0x36,
3760 0x00, 0xF8, 0x00, 0x78, 0xFF, 0x9B, 0xFB, 0xA6, 0xFE, 0xE9, 0x0E,
3761 0x8D, 0x1F, 0xAA, 0x1D, 0x87, 0x0B, 0x2B, 0xFD, 0x1E, 0xFC, 0x02,
3762 0x00, 0xE5, 0x00, 0x1C, 0x00, 0xFB, 0xFF, 0xF7, 0xFF, 0x58, 0x00,
3763 0xF9, 0x00, 0xCF, 0xFE, 0x4A, 0xFB, 0xA7, 0x00, 0x77, 0x12, 0xE0,
3764 0x20, 0x26, 0x1B, 0x28, 0x08, 0x18, 0xFC, 0xCB, 0xFC, 0x71, 0x00,
3765 0xC5, 0x00, 0x08, 0x00, 0xFE, 0xFF, 0xF8, 0xFF, 0x80, 0x00, 0xE1,
3766 0x00, 0x13, 0xFE, 0x45, 0xFB, 0x1D, 0x03, 0xEB, 0x15, 0x7F, 0x21,
3767 0x2D, 0x18, 0x0E, 0x05, 0x77, 0xFB, 0x8B, 0xFD, 0xBE, 0x00, 0x9D,
3768 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xA9, 0x00,
3769 0xAA, 0x00, 0x4F, 0xFD, 0x9D, 0xFB, 0xFA, 0x05, 0x22, 0x19, 0x62,
3770 0x21, 0xE0, 0x14, 0x50, 0x02, 0x3E, 0xFB, 0x4E, 0xFE, 0xEB, 0x00,
3771 0x73, 0x00, 0xF7, 0xFF, 0xFE, 0xFF, 0x0D, 0x00, 0xD0, 0x00, 0x52,
3772 0x00, 0x93, 0xFC, 0x60, 0xFC, 0x2C, 0x09, 0xFA, 0x1B, 0x8A, 0x20,
3773 0x60, 0x11, 0xFD, 0xFF, 0x5C, 0xFB, 0x06, 0xFF, 0xFB, 0x00, 0x4D,
3774 0x00, 0xF7, 0xFF, 0xFA, 0xFF, 0x23, 0x00, 0xED, 0x00, 0xD9, 0xFF,
3775 0xEF, 0xFB, 0x98, 0xFD, 0x99, 0x0C, 0x54, 0x1E, 0x02, 0x1F, 0xD2,
3776 0x0D, 0x20, 0xFE, 0xC0, 0xFB, 0xA7, 0xFF, 0xF4, 0x00, 0x2D, 0x00,
3777 0xF9, 0xFF, 0xF8, 0xFF, 0x41, 0x00, 0xFB, 0x00, 0x41, 0xFF, 0x78,
3778 0xFB, 0x4A, 0xFF, 0x25, 0x10, 0x16, 0x20, 0xDA, 0x1C, 0x56, 0x0A,
3779 0xBE, 0xFC, 0x56, 0xFC, 0x2C, 0x00, 0xDB, 0x00, 0x14, 0x00, 0xFD,
3780 0xFF, 0xF7, 0xFF, 0x66, 0x00, 0xF4, 0x00, 0x8F, 0xFE, 0x3F, 0xFB,
3781 0x75, 0x01, 0xAE, 0x13, 0x2C, 0x21, 0x2A, 0x1A, 0x0D, 0x07, 0xD4,
3782 0xFB, 0x0C, 0xFD, 0x8F, 0x00, 0xB7, 0x00, 0x03, 0x00, 0xFF, 0xFF,
3783 0x00, 0x00, 0xFA, 0xFF, 0x8E, 0x00, 0xD1, 0x00, 0xCF, 0xFD, 0x58,
3784 0xFB, 0x10, 0x04, 0x10, 0x17, 0x8A, 0x21, 0x10, 0x17, 0x10, 0x04,
3785 0x58, 0xFB, 0xCF, 0xFD, 0xD1, 0x00, 0x8E, 0x00, 0xFA, 0xFF, 0xFF,
3786 0xFF, 0x03, 0x00, 0xB7, 0x00, 0x8F, 0x00, 0x0C, 0xFD, 0xD4, 0xFB,
3787 0x0D, 0x07, 0x2A, 0x1A, 0x2C, 0x21, 0xAE, 0x13, 0x75, 0x01, 0x3F,
3788 0xFB, 0x8F, 0xFE, 0xF4, 0x00, 0x66, 0x00, 0xF7, 0xFF, 0xFD, 0xFF,
3789 0x14, 0x00, 0xDB, 0x00, 0x2C, 0x00, 0x56, 0xFC, 0xBE, 0xFC, 0x56,
3790 0x0A, 0xDA, 0x1C, 0x16, 0x20, 0x25, 0x10, 0x4A, 0xFF, 0x78, 0xFB,
3791 0x41, 0xFF, 0xFB, 0x00, 0x41, 0x00, 0xF8, 0xFF, 0xF9, 0xFF, 0x2D,
3792 0x00, 0xF4, 0x00, 0xA7, 0xFF, 0xC0, 0xFB, 0x20, 0xFE, 0xD2, 0x0D,
3793 0x02, 0x1F, 0x54, 0x1E, 0x99, 0x0C, 0x98, 0xFD, 0xEF, 0xFB, 0xD9,
3794 0xFF, 0xED, 0x00, 0x23, 0x00, 0xFA, 0xFF, 0xF7, 0xFF, 0x4D, 0x00,
3795 0xFB, 0x00, 0x06, 0xFF, 0x5C, 0xFB, 0xFD, 0xFF, 0x60, 0x11, 0x8A,
3796 0x20, 0xFA, 0x1B, 0x2C, 0x09, 0x60, 0xFC, 0x93, 0xFC, 0x52, 0x00,
3797 0xD0, 0x00, 0x0D, 0x00, 0xFE, 0xFF, 0xF7, 0xFF, 0x73, 0x00, 0xEB,
3798 0x00, 0x4E, 0xFE, 0x3E, 0xFB, 0x50, 0x02, 0xE0, 0x14, 0x62, 0x21,
3799 0x22, 0x19, 0xFA, 0x05, 0x9D, 0xFB, 0x4F, 0xFD, 0xAA, 0x00, 0xA9,
3800 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0x9D, 0x00,
3801 0xBE, 0x00, 0x8B, 0xFD, 0x77, 0xFB, 0x0E, 0x05, 0x2D, 0x18, 0x7F,
3802 0x21, 0xEB, 0x15, 0x1D, 0x03, 0x45, 0xFB, 0x13, 0xFE, 0xE1, 0x00,
3803 0x80, 0x00, 0xF8, 0xFF, 0xFE, 0xFF, 0x08, 0x00, 0xC5, 0x00, 0x71,
3804 0x00, 0xCB, 0xFC, 0x18, 0xFC, 0x28, 0x08, 0x26, 0x1B, 0xE0, 0x20,
3805 0x77, 0x12, 0xA7, 0x00, 0x4A, 0xFB, 0xCF, 0xFE, 0xF9, 0x00, 0x58,
3806 0x00, 0xF7, 0xFF, 0xFB, 0xFF, 0x1C, 0x00, 0xE5, 0x00, 0x02, 0x00,
3807 0x1E, 0xFC, 0x2B, 0xFD, 0x87, 0x0B, 0xAA, 0x1D, 0x8D, 0x1F, 0xE9,
3808 0x0E, 0xA6, 0xFE, 0x9B, 0xFB, 0x78, 0xFF, 0xF8, 0x00, 0x36, 0x00,
3809 0xF9, 0xFF, 0xF8, 0xFF, 0x37, 0x00, 0xF9, 0x00, 0x72, 0xFF, 0x96,
3810 0xFB, 0xB8, 0xFE, 0x0D, 0x0F, 0x9D, 0x1F, 0x94, 0x1D, 0x65, 0x0B,
3811 0x1E, 0xFD, 0x24, 0xFC, 0x06, 0x00, 0xE4, 0x00, 0x1B, 0x00, 0xFC,
3812 0xFF, 0xF7, 0xFF, 0x5A, 0x00, 0xF9, 0x00, 0xC8, 0xFE, 0x49, 0xFB,
3813 0xBE, 0x00, 0x9A, 0x12, 0xE9, 0x20, 0x0A, 0x1B, 0x08, 0x08, 0x10,
3814 0xFC, 0xD2, 0xFC, 0x74, 0x00, 0xC3, 0x00, 0x08, 0x00, 0xFE, 0xFF,
3815 0xF9, 0xFF, 0x82, 0x00, 0xDF, 0x00, 0x0B, 0xFE, 0x47, 0xFB, 0x37,
3816 0x03, 0x0C, 0x16, 0x81, 0x21, 0x0E, 0x18, 0xF2, 0x04, 0x73, 0xFB,
3817 0x92, 0xFD, 0xC0, 0x00, 0x9B, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00,
3818 0x00, 0x00, 0x00, 0xAB, 0x00, 0xA7, 0x00, 0x47, 0xFD, 0xA2, 0xFB,
3819 0x18, 0x06, 0x40, 0x19, 0x5D, 0x21, 0xBE, 0x14, 0x37, 0x02, 0x3D,
3820 0xFB, 0x55, 0xFE, 0xEC, 0x00, 0x72, 0x00, 0xF7, 0xFF, 0xFD, 0xFF,
3821 0x0E, 0x00, 0xD1, 0x00, 0x4E, 0x00, 0x8C, 0xFC, 0x6A, 0xFC, 0x4C,
3822 0x09, 0x13, 0x1C, 0x7E, 0x20, 0x3D, 0x11, 0xE8, 0xFF, 0x5F, 0xFB,
3823 0x0C, 0xFF, 0xFB, 0x00, 0x4C, 0x00, 0xF7, 0xFF, 0xFA, 0xFF, 0x24,
3824 0x00, 0xEE, 0x00, 0xD3, 0xFF, 0xEA, 0xFB, 0xA7, 0xFD, 0xBC, 0x0C,
3825 0x68, 0x1E, 0xEF, 0x1E, 0xAF, 0x0D, 0x11, 0xFE, 0xC5, 0xFB, 0xAD,
3826 0xFF, 0xF3, 0x00, 0x2C, 0x00, 0xFA, 0xFF, 0xF8, 0xFF, 0x42, 0x00,
3827 0xFB, 0x00, 0x3A, 0xFF, 0x74, 0xFB, 0x5D, 0xFF, 0x48, 0x10, 0x24,
3828 0x20, 0xC2, 0x1C, 0x35, 0x0A, 0xB3, 0xFC, 0x5D, 0xFC, 0x30, 0x00,
3829 0xDA, 0x00, 0x13, 0x00, 0xFD, 0xFF, 0xF7, 0xFF, 0x67, 0x00, 0xF3,
3830 0x00, 0x88, 0xFE, 0x3E, 0xFB, 0x8C, 0x01, 0xD0, 0x13, 0x33, 0x21,
3831 0x0D, 0x1A, 0xEE, 0x06, 0xCD, 0xFB, 0x13, 0xFD, 0x92, 0x00, 0xB6,
3832 0x00, 0x03, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFA, 0xFF, 0x90, 0x00,
3833 0xCF, 0x00, 0xC7, 0xFD, 0x5B, 0xFB, 0x2B, 0x04, 0x31, 0x17, 0x8A,
3834 0x21, 0xF0, 0x16, 0xF4, 0x03, 0x56, 0xFB, 0xD6, 0xFD, 0xD3, 0x00,
3835 0x8D, 0x00, 0xFA, 0xFF, 0xFF, 0xFF, 0x04, 0x00, 0xB9, 0x00, 0x8C,
3836 0x00, 0x05, 0xFD, 0xDB, 0xFB, 0x2C, 0x07, 0x47, 0x1A, 0x25, 0x21,
3837 0x8B, 0x13, 0x5D, 0x01, 0x40, 0xFB, 0x97, 0xFE, 0xF5, 0x00, 0x64,
3838 0x00, 0xF7, 0xFF, 0xFC, 0xFF, 0x15, 0x00, 0xDC, 0x00, 0x27, 0x00,
3839 0x50, 0xFC, 0xCA, 0xFC, 0x78, 0x0A, 0xF2, 0x1C, 0x07, 0x20, 0x02,
3840 0x10, 0x37, 0xFF, 0x7B, 0xFB, 0x47, 0xFF, 0xFB, 0x00, 0x40, 0x00,
3841 0xF8, 0xFF, 0xF9, 0xFF, 0x2E, 0x00, 0xF5, 0x00, 0xA2, 0xFF, 0xBB,
3842 0xFB, 0x31, 0xFE, 0xF5, 0x0D, 0x14, 0x1F, 0x3F, 0x1E, 0x77, 0x0C,
3843 0x8A, 0xFD, 0xF5, 0xFB, 0xDE, 0xFF, 0xEC, 0x00, 0x22, 0x00, 0xFB,
3844 0xFF, 0xF7, 0xFF, 0x4E, 0x00, 0xFB, 0x00, 0xFF, 0xFE, 0x59, 0xFB,
3845 0x11, 0x00, 0x83, 0x11, 0x96, 0x20, 0xE0, 0x1B, 0x0B, 0x09, 0x56,
3846 0xFC, 0x99, 0xFC, 0x56, 0x00, 0xCE, 0x00, 0x0D, 0x00, 0xFE, 0xFF,
3847 0xF8, 0xFF, 0x75, 0x00, 0xEA, 0x00, 0x47, 0xFE, 0x3E, 0xFB, 0x69,
3848 0x02, 0x02, 0x15, 0x66, 0x21, 0x04, 0x19, 0xDC, 0x05, 0x98, 0xFB,
3849 0x56, 0xFD, 0xAD, 0x00, 0xA8, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00,
3850 0x00, 0xFD, 0xFF, 0x9E, 0x00, 0xBC, 0x00, 0x83, 0xFD, 0x7B, 0xFB,
3851 0x2B, 0x05, 0x4C, 0x18, 0x7C, 0x21, 0xCA, 0x15, 0x03, 0x03, 0x44,
3852 0xFB, 0x1A, 0xFE, 0xE2, 0x00, 0x7E, 0x00, 0xF8, 0xFF, 0xFE, 0xFF,
3853 0x09, 0x00, 0xC6, 0x00, 0x6D, 0x00, 0xC3, 0xFC, 0x20, 0xFC, 0x49,
3854 0x08, 0x41, 0x1B, 0xD6, 0x20, 0x54, 0x12, 0x92, 0x00, 0x4C, 0xFB,
3855 0xD6, 0xFE, 0xFA, 0x00, 0x57, 0x00, 0xF7, 0xFF, 0xFB, 0xFF, 0x1D,
3856 0x00, 0xE6, 0x00, 0xFD, 0xFF, 0x18, 0xFC, 0x38, 0xFD, 0xA9, 0x0B,
3857 0xC0, 0x1D, 0x7C, 0x1F, 0xC6, 0x0E, 0x95, 0xFE, 0x9F, 0xFB, 0x7E,
3858 0xFF, 0xF8, 0x00, 0x35, 0x00, 0xF9, 0xFF, 0xF8, 0xFF, 0x38, 0x00,
3859 0xF9, 0x00, 0x6C, 0xFF, 0x92, 0xFB, 0xC9, 0xFE, 0x2F, 0x0F, 0xAD,
3860 0x1F, 0x7D, 0x1D, 0x42, 0x0B, 0x12, 0xFD, 0x2A, 0xFC, 0x0B, 0x00,
3861 0xE3, 0x00, 0x1A, 0x00, 0xFC, 0xFF, 0xF7, 0xFF, 0x5B, 0x00, 0xF8,
3862 0x00, 0xC1, 0xFE, 0x47, 0xFB, 0xD4, 0x00, 0xBC, 0x12, 0xF3, 0x20,
3863 0xEF, 0x1A, 0xE9, 0x07, 0x08, 0xFC, 0xD9, 0xFC, 0x78, 0x00, 0xC2,
3864 0x00, 0x07, 0x00, 0xFF, 0xFF, 0xF9, 0xFF, 0x83, 0x00, 0xDD, 0x00,
3865 0x04, 0xFE, 0x49, 0xFB, 0x52, 0x03, 0x2D, 0x16, 0x83, 0x21, 0xEF,
3866 0x17, 0xD5, 0x04, 0x6F, 0xFB, 0x9A, 0xFD, 0xC3, 0x00, 0x9A, 0x00,
3867 0xFC, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xAD, 0x00, 0xA4,
3868 0x00, 0x40, 0xFD, 0xA8, 0xFB, 0x36, 0x06, 0x5E, 0x19, 0x58, 0x21,
3869 0x9C, 0x14, 0x1E, 0x02, 0x3D, 0xFB, 0x5D, 0xFE, 0xED, 0x00, 0x70,
3870 0x00, 0xF7, 0xFF, 0xFD, 0xFF, 0x0F, 0x00, 0xD2, 0x00, 0x4A, 0x00,
3871 0x85, 0xFC, 0x74, 0xFC, 0x6D, 0x09, 0x2D, 0x1C, 0x72, 0x20, 0x1A,
3872 0x11, 0xD4, 0xFF, 0x61, 0xFB, 0x13, 0xFF, 0xFC, 0x00, 0x4A, 0x00,
3873 0xF7, 0xFF, 0xFA, 0xFF, 0x25, 0x00, 0xEF, 0x00, 0xCE, 0xFF, 0xE4,
3874 0xFB, 0xB5, 0xFD, 0xDE, 0x0C, 0x7C, 0x1E, 0xDD, 0x1E, 0x8C, 0x0D,
3875 0x01, 0xFE, 0xCA, 0xFB, 0xB3, 0xFF, 0xF3, 0x00, 0x2B, 0x00, 0xFA,
3876 0xFF, 0xF8, 0xFF, 0x44, 0x00, 0xFB, 0x00, 0x34, 0xFF, 0x71, 0xFB,
3877 0x71, 0xFF, 0x6B, 0x10, 0x32, 0x20, 0xA9, 0x1C, 0x13, 0x0A, 0xA8,
3878 0xFC, 0x63, 0xFC, 0x35, 0x00, 0xD9, 0x00, 0x12, 0x00, 0xFD, 0xFF,
3879 0xF7, 0xFF, 0x69, 0x00, 0xF2, 0x00, 0x81, 0xFE, 0x3E, 0xFB, 0xA4,
3880 0x01, 0xF2, 0x13, 0x3A, 0x21, 0xF0, 0x19, 0xCF, 0x06, 0xC7, 0xFB,
3881 0x1B, 0xFD, 0x96, 0x00, 0xB4, 0x00, 0x02, 0x00, 0xFF, 0xFF, 0x00,
3882 0x00, 0xFB, 0xFF, 0x92, 0x00, 0xCD, 0x00, 0xC0, 0xFD, 0x5E, 0xFB,
3883 0x47, 0x04, 0x51, 0x17, 0x8A, 0x21, 0xD0, 0x16, 0xD9, 0x03, 0x53,
3884 0xFB, 0xDE, 0xFD, 0xD5, 0x00, 0x8B, 0x00, 0xFA, 0xFF, 0xFF, 0xFF,
3885 0x04, 0x00, 0xBA, 0x00, 0x89, 0x00, 0xFD, 0xFC, 0xE2, 0xFB, 0x4B,
3886 0x07, 0x63, 0x1A, 0x1D, 0x21, 0x69, 0x13, 0x46, 0x01, 0x41, 0xFB,
3887 0x9E, 0xFE, 0xF5, 0x00, 0x63, 0x00, 0xF7, 0xFF, 0xFC, 0xFF, 0x16,
3888 0x00, 0xDD, 0x00, 0x23, 0x00, 0x49, 0xFC, 0xD5, 0xFC, 0x99, 0x0A,
3889 0x09, 0x1D, 0xF9, 0x1F, 0xDF, 0x0F, 0x24, 0xFF, 0x7F, 0xFB, 0x4D,
3890 0xFF, 0xFB, 0x00, 0x3F, 0x00, 0xF8, 0xFF, 0xF9, 0xFF, 0x2F, 0x00,
3891 0xF5, 0x00, 0x9C, 0xFF, 0xB6, 0xFB, 0x41, 0xFE, 0x17, 0x0E, 0x26,
3892 0x1F, 0x2B, 0x1E, 0x54, 0x0C, 0x7C, 0xFD, 0xFA, 0xFB, 0xE3, 0xFF,
3893 0xEB, 0x00, 0x21, 0x00, 0xFB, 0xFF, 0xF7, 0xFF, 0x50, 0x00, 0xFB,
3894 0x00, 0xF8, 0xFE, 0x57, 0xFB, 0x26, 0x00, 0xA6, 0x11, 0xA1, 0x20,
3895 0xC6, 0x1B, 0xEA, 0x08, 0x4D, 0xFC, 0xA0, 0xFC, 0x5A, 0x00, 0xCD,
3896 0x00, 0x0C, 0x00, 0xFE, 0xFF, 0xF8, 0xFF, 0x77, 0x00, 0xE9, 0x00,
3897 0x3F, 0xFE, 0x3F, 0xFB, 0x82, 0x02, 0x23, 0x15, 0x6B, 0x21, 0xE5,
3898 0x18, 0xBE, 0x05, 0x93, 0xFB, 0x5E, 0xFD, 0xAF, 0x00, 0xA6, 0x00,
3899 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFD, 0xFF, 0xA0, 0x00, 0xB9,
3900 0x00, 0x7C, 0xFD, 0x80, 0xFB, 0x48, 0x05, 0x6B, 0x18, 0x79, 0x21,
3901 0xA9, 0x15, 0xE9, 0x02, 0x43, 0xFB, 0x21, 0xFE, 0xE3, 0x00, 0x7D,
3902 0x00, 0xF8, 0xFF, 0xFE, 0xFF, 0x09, 0x00, 0xC7, 0x00, 0x69, 0x00,
3903 0xBC, 0xFC, 0x29, 0xFC, 0x69, 0x08, 0x5C, 0x1B, 0xCC, 0x20, 0x32,
3904 0x12, 0x7C, 0x00, 0x4E, 0xFB, 0xDD, 0xFE, 0xFA, 0x00, 0x56, 0x00,
3905 0xF7, 0xFF, 0xFB, 0xFF, 0x1D, 0x00, 0xE7, 0x00, 0xF8, 0xFF, 0x12,
3906 0xFC, 0x45, 0xFD, 0xCB, 0x0B, 0xD6, 0x1D, 0x6C, 0x1F, 0xA3, 0x0E,
3907 0x84, 0xFE, 0xA4, 0xFB, 0x84, 0xFF, 0xF7, 0x00, 0x34, 0x00, 0xF9,
3908 0xFF, 0xF8, 0xFF, 0x3A, 0x00, 0xFA, 0x00, 0x66, 0xFF, 0x8E, 0xFB,
3909 0xDB, 0xFE, 0x53, 0x0F, 0xBD, 0x1F, 0x66, 0x1D, 0x21, 0x0B, 0x05,
3910 0xFD, 0x30, 0xFC, 0x10, 0x00, 0xE2, 0x00, 0x19, 0x00, 0xFC, 0xFF,
3911 0xF7, 0xFF, 0x5D, 0x00, 0xF8, 0x00, 0xBA, 0xFE, 0x46, 0xFB, 0xEA,
3912 0x00, 0xDF, 0x12, 0xFC, 0x20, 0xD3, 0x1A, 0xC9, 0x07, 0x00, 0xFC,
3913 0xE0, 0xFC, 0x7B, 0x00, 0xC0, 0x00, 0x07, 0x00, 0xFF, 0xFF, 0xF9,
3914 0xFF, 0x85, 0x00, 0xDC, 0x00, 0xFC, 0xFD, 0x4A, 0xFB, 0x6C, 0x03,
3915 0x4E, 0x16, 0x85, 0x21, 0xCF, 0x17, 0xB8, 0x04, 0x6C, 0xFB, 0xA2,
3916 0xFD, 0xC5, 0x00, 0x98, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0xFF, 0xFF,
3917 0x01, 0x00, 0xAE, 0x00, 0xA1, 0x00, 0x38, 0xFD, 0xAE, 0xFB, 0x54,
3918 0x06, 0x7C, 0x19, 0x53, 0x21, 0x7B, 0x14, 0x05, 0x02, 0x3D, 0xFB,
3919 0x64, 0xFE, 0xEE, 0x00, 0x6F, 0x00, 0xF7, 0xFF, 0xFD, 0xFF, 0x0F,
3920 0x00, 0xD4, 0x00, 0x46, 0x00, 0x7E, 0xFC, 0x7E, 0xFC, 0x8E, 0x09,
3921 0x46, 0x1C, 0x66, 0x20, 0xF7, 0x10, 0xC0, 0xFF, 0x64, 0xFB, 0x1A,
3922 0xFF, 0xFC, 0x00, 0x49, 0x00, 0xF7, 0xFF, 0xFA, 0xFF, 0x26, 0x00,
3923 0xF0, 0x00, 0xC9, 0xFF, 0xDF, 0xFB, 0xC4, 0xFD, 0x01, 0x0D, 0x90,
3924 0x1E, 0xCA, 0x1E, 0x69, 0x0D, 0xF1, 0xFD, 0xCF, 0xFB, 0xB8, 0xFF,
3925 0xF2, 0x00, 0x29, 0x00, 0xFA, 0xFF, 0xF7, 0xFF, 0x45, 0x00, 0xFC,
3926 0x00, 0x2D, 0xFF, 0x6D, 0xFB, 0x84, 0xFF, 0x8E, 0x10, 0x3F, 0x20,
3927 0x91, 0x1C, 0xF2, 0x09, 0x9D, 0xFC, 0x6A, 0xFC, 0x39, 0x00, 0xD7,
3928 0x00, 0x12, 0x00, 0xFD, 0xFF, 0xF7, 0xFF, 0x6A, 0x00, 0xF1, 0x00,
3929 0x7A, 0xFE, 0x3D, 0xFB, 0xBC, 0x01, 0x14, 0x14, 0x41, 0x21, 0xD4,
3930 0x19, 0xB0, 0x06, 0xC0, 0xFB, 0x22, 0xFD, 0x99, 0x00, 0xB3, 0x00,
3931 0x02, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFB, 0xFF, 0x93, 0x00, 0xCB,
3932 0x00, 0xB8, 0xFD, 0x61, 0xFB, 0x63, 0x04, 0x71, 0x17, 0x89, 0x21,
3933 0xB0, 0x16, 0xBD, 0x03, 0x51, 0xFB, 0xE6, 0xFD, 0xD7, 0x00, 0x8A,
3934 0x00, 0xFA, 0xFF, 0xFF, 0xFF, 0x05, 0x00, 0xBC, 0x00, 0x86, 0x00,
3935 0xF6, 0xFC, 0xE9, 0xFB, 0x6A, 0x07, 0x80, 0x1A, 0x15, 0x21, 0x47,
3936 0x13, 0x2F, 0x01, 0x42, 0xFB, 0xA5, 0xFE, 0xF6, 0x00, 0x61, 0x00,
3937 0xF7, 0xFF, 0xFC, 0xFF, 0x16, 0x00, 0xDF, 0x00, 0x1E, 0x00, 0x43,
3938 0xFC, 0xE1, 0xFC, 0xBB, 0x0A, 0x21, 0x1D, 0xEA, 0x1F, 0xBC, 0x0F,
3939 0x12, 0xFF, 0x82, 0xFB, 0x54, 0xFF, 0xFA, 0x00, 0x3D, 0x00, 0xF8,
3940 0xFF, 0xF9, 0xFF, 0x30, 0x00, 0xF6, 0x00, 0x96, 0xFF, 0xB1, 0xFB,
3941 0x51, 0xFE, 0x3A, 0x0E, 0x38, 0x1F, 0x16, 0x1E, 0x32, 0x0C, 0x6E,
3942 0xFD, 0x00, 0xFC, 0xE8, 0xFF, 0xEA, 0x00, 0x20, 0x00, 0xFB, 0xFF,
3943 0xF7, 0xFF, 0x51, 0x00, 0xFB, 0x00, 0xF1, 0xFE, 0x54, 0xFB, 0x3B,
3944 0x00, 0xC9, 0x11, 0xAD, 0x20, 0xAC, 0x1B, 0xCA, 0x08, 0x44, 0xFC,
3945 0xA7, 0xFC, 0x5E, 0x00, 0xCC, 0x00, 0x0B, 0x00, 0xFE, 0xFF, 0xF8,
3946 0xFF, 0x78, 0x00, 0xE7, 0x00, 0x38, 0xFE, 0x40, 0xFB, 0x9B, 0x02,
3947 0x45, 0x15, 0x6F, 0x21, 0xC7, 0x18, 0xA1, 0x05, 0x8E, 0xFB, 0x65,
3948 0xFD, 0xB2, 0x00, 0xA5, 0x00, 0xFE, 0xFF, 0x00, 0x00, 0x00, 0x00,
3949 0xFE, 0xFF, 0xA2, 0x00, 0xB7, 0x00, 0x74, 0xFD, 0x84, 0xFB, 0x66,
3950 0x05, 0x8A, 0x18, 0x76, 0x21, 0x87, 0x15, 0xCF, 0x02, 0x41, 0xFB,
3951 0x29, 0xFE, 0xE5, 0x00, 0x7B, 0x00, 0xF8, 0xFF, 0xFE, 0xFF, 0x0A,
3952 0x00, 0xC9, 0x00, 0x66, 0x00, 0xB5, 0xFC, 0x32, 0xFC, 0x89, 0x08,
3953 0x77, 0x1B, 0xC2, 0x20, 0x0F, 0x12, 0x66, 0x00, 0x50, 0xFB, 0xE4,
3954 0xFE, 0xFA, 0x00, 0x54, 0x00, 0xF7, 0xFF, 0xFB, 0xFF, 0x1E, 0x00,
3955 0xE8, 0x00, 0xF3, 0xFF, 0x0C, 0xFC, 0x53, 0xFD, 0xED, 0x0B, 0xEB,
3956 0x1D, 0x5A, 0x1F, 0x80, 0x0E, 0x73, 0xFE, 0xA8, 0xFB, 0x8A, 0xFF,
3957 0xF7, 0x00, 0x32, 0x00, 0xF9, 0xFF, 0xF8, 0xFF, 0x3B, 0x00, 0xFA,
3958 0x00, 0x60, 0xFF, 0x8A, 0xFB, 0xED, 0xFE, 0x76, 0x0F, 0xCC, 0x1F,
3959 0x4F, 0x1D, 0xFF, 0x0A, 0xF9, 0xFC, 0x36, 0xFC, 0x15, 0x00, 0xE1,
3960 0x00, 0x18, 0x00, 0xFC, 0xFF, 0xF7, 0xFF, 0x5E, 0x00, 0xF7, 0x00,
3961 0xB3, 0xFE, 0x44, 0xFB, 0x01, 0x01, 0x02, 0x13, 0x04, 0x21, 0xB8,
3962 0x1A, 0xA9, 0x07, 0xF8, 0xFB, 0xE7, 0xFC, 0x7F, 0x00, 0xBF, 0x00,
3963 0x06, 0x00, 0xFF, 0xFF, 0xF9, 0xFF, 0x86, 0x00, 0xDA, 0x00, 0xF5,
3964 0xFD, 0x4C, 0xFB, 0x87, 0x03, 0x6E, 0x16, 0x86, 0x21, 0xB0, 0x17,
3965 0x9C, 0x04, 0x68, 0xFB, 0xA9, 0xFD, 0xC7, 0x00, 0x96, 0x00, 0xFB,
3966 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x00, 0xB0, 0x00, 0x9F, 0x00,
3967 0x31, 0xFD, 0xB4, 0xFB, 0x73, 0x06, 0x99, 0x19, 0x4D, 0x21, 0x59,
3968 0x14, 0xED, 0x01, 0x3D, 0xFB, 0x6B, 0xFE, 0xEF, 0x00, 0x6D, 0x00,
3969 0xF7, 0xFF, 0xFD, 0xFF, 0x10, 0x00, 0xD5, 0x00, 0x42, 0x00, 0x77,
3970 0xFC, 0x88, 0xFC, 0xAF, 0x09, 0x5F, 0x1C, 0x59, 0x20, 0xD4, 0x10,
3971 0xAC, 0xFF, 0x67, 0xFB, 0x20, 0xFF, 0xFC, 0x00, 0x48, 0x00, 0xF7,
3972 0xFF, 0xFA, 0xFF, 0x27, 0x00, 0xF0, 0x00, 0xC3, 0xFF, 0xD9, 0xFB,
3973 0xD3, 0xFD, 0x24, 0x0D, 0xA3, 0x1E, 0xB7, 0x1E, 0x46, 0x0D, 0xE2,
3974 0xFD, 0xD4, 0xFB, 0xBE, 0xFF, 0xF1, 0x00, 0x28, 0x00, 0xFA, 0xFF,
3975 0xF7, 0xFF, 0x46, 0x00, 0xFC, 0x00, 0x27, 0xFF, 0x6A, 0xFB, 0x98,
3976 0xFF, 0xB1, 0x10, 0x4C, 0x20, 0x78, 0x1C, 0xD1, 0x09, 0x93, 0xFC,
3977 0x71, 0xFC, 0x3D, 0x00, 0xD6, 0x00, 0x11, 0x00, 0xFD, 0xFF, 0xF7,
3978 0xFF, 0x6C, 0x00, 0xF0, 0x00, 0x72, 0xFE, 0x3D, 0xFB, 0xD4, 0x01,
3979 0x36, 0x14, 0x47, 0x21, 0xB6, 0x19, 0x91, 0x06, 0xBA, 0xFB, 0x29,
3980 0xFD, 0x9C, 0x00, 0xB1, 0x00, 0x02, 0x00, 0xFF, 0xFF, 0x00, 0x00,
3981 0xFB, 0xFF, 0x95, 0x00, 0xC9, 0x00, 0xB1, 0xFD, 0x65, 0xFB, 0x80,
3982 0x04, 0x90, 0x17, 0x88, 0x21, 0x8F, 0x16, 0xA2, 0x03, 0x4E, 0xFB,
3983 0xED, 0xFD, 0xD9, 0x00, 0x88, 0x00, 0xF9, 0xFF, 0xFF, 0xFF, 0x05,
3984 0x00, 0xBD, 0x00, 0x82, 0x00, 0xEF, 0xFC, 0xF0, 0xFB, 0x8A, 0x07,
3985 0x9C, 0x1A, 0x0D, 0x21, 0x24, 0x13, 0x18, 0x01, 0x43, 0xFB, 0xAC,
3986 0xFE, 0xF7, 0x00, 0x60, 0x00, 0xF7, 0xFF, 0xFC, 0xFF, 0x17, 0x00,
3987 0xE0, 0x00, 0x1A, 0x00, 0x3D, 0xFC, 0xED, 0xFC, 0xDD, 0x0A, 0x38,
3988 0x1D, 0xDB, 0x1F, 0x99, 0x0F, 0xFF, 0xFE, 0x86, 0xFB, 0x5A, 0xFF,
3989 0xFA, 0x00, 0x3C, 0x00, 0xF8, 0xFF, 0xF9, 0xFF, 0x31, 0x00, 0xF6,
3990 0x00, 0x90, 0xFF, 0xAD, 0xFB, 0x62, 0xFE, 0x5D, 0x0E, 0x49, 0x1F,
3991 0x01, 0x1E, 0x10, 0x0C, 0x60, 0xFD, 0x06, 0xFC, 0xEE, 0xFF, 0xE9,
3992 0x00, 0x1F, 0x00, 0xFB, 0xFF, 0xF7, 0xFF, 0x53, 0x00, 0xFB, 0x00,
3993 0xEB, 0xFE, 0x52, 0xFB, 0x51, 0x00, 0xEC, 0x11, 0xB7, 0x20, 0x91,
3994 0x1B, 0xA9, 0x08, 0x3B, 0xFC, 0xAE, 0xFC, 0x62, 0x00, 0xCA, 0x00,
3995 0x0B, 0x00, 0xFE, 0xFF, 0xF8, 0xFF, 0x7A, 0x00, 0xE6, 0x00, 0x30,
3996 0xFE, 0x40, 0xFB, 0xB5, 0x02, 0x66, 0x15, 0x73, 0x21, 0xA9, 0x18,
3997 0x83, 0x05, 0x89, 0xFB, 0x6D, 0xFD, 0xB4, 0x00, 0xA3, 0x00, 0xFE,
3998 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xA3, 0x00, 0xB4, 0x00,
3999 0x6D, 0xFD, 0x89, 0xFB, 0x83, 0x05, 0xA9, 0x18, 0x73, 0x21, 0x66,
4000 0x15, 0xB5, 0x02, 0x40, 0xFB, 0x30, 0xFE, 0xE6, 0x00, 0x7A, 0x00,
4001 0xF8, 0xFF, 0xFE, 0xFF, 0x0B, 0x00, 0xCA, 0x00, 0x62, 0x00, 0xAE,
4002 0xFC, 0x3B, 0xFC, 0xA9, 0x08, 0x91, 0x1B, 0xB7, 0x20, 0xEC, 0x11,
4003 0x51, 0x00, 0x52, 0xFB, 0xEB, 0xFE, 0xFB, 0x00, 0x53, 0x00, 0xF7,
4004 0xFF, 0xFB, 0xFF, 0x1F, 0x00, 0xE9, 0x00, 0xEE, 0xFF, 0x06, 0xFC,
4005 0x60, 0xFD, 0x10, 0x0C, 0x01, 0x1E, 0x49, 0x1F, 0x5D, 0x0E, 0x62,
4006 0xFE, 0xAD, 0xFB, 0x90, 0xFF, 0xF6, 0x00, 0x31, 0x00, 0xF9, 0xFF,
4007 0xF8, 0xFF, 0x3C, 0x00, 0xFA, 0x00, 0x5A, 0xFF, 0x86, 0xFB, 0xFF,
4008 0xFE, 0x99, 0x0F, 0xDB, 0x1F, 0x38, 0x1D, 0xDD, 0x0A, 0xED, 0xFC,
4009 0x3D, 0xFC, 0x1A, 0x00, 0xE0, 0x00, 0x17, 0x00, 0xFC, 0xFF, 0xF7,
4010 0xFF, 0x60, 0x00, 0xF7, 0x00, 0xAC, 0xFE, 0x43, 0xFB, 0x18, 0x01,
4011 0x24, 0x13, 0x0D, 0x21, 0x9C, 0x1A, 0x8A, 0x07, 0xF0, 0xFB, 0xEF,
4012 0xFC, 0x82, 0x00, 0xBD, 0x00, 0x05, 0x00, 0xFF, 0xFF, 0xF9, 0xFF,
4013 0x88, 0x00, 0xD9, 0x00, 0xED, 0xFD, 0x4E, 0xFB, 0xA2, 0x03, 0x8F,
4014 0x16, 0x88, 0x21, 0x90, 0x17, 0x80, 0x04, 0x65, 0xFB, 0xB1, 0xFD,
4015 0xC9, 0x00, 0x95, 0x00, 0xFB, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x02,
4016 0x00, 0xB1, 0x00, 0x9C, 0x00, 0x29, 0xFD, 0xBA, 0xFB, 0x91, 0x06,
4017 0xB6, 0x19, 0x47, 0x21, 0x36, 0x14, 0xD4, 0x01, 0x3D, 0xFB, 0x72,
4018 0xFE, 0xF0, 0x00, 0x6C, 0x00, 0xF7, 0xFF, 0xFD, 0xFF, 0x11, 0x00,
4019 0xD6, 0x00, 0x3D, 0x00, 0x71, 0xFC, 0x93, 0xFC, 0xD1, 0x09, 0x78,
4020 0x1C, 0x4C, 0x20, 0xB1, 0x10, 0x98, 0xFF, 0x6A, 0xFB, 0x27, 0xFF,
4021 0xFC, 0x00, 0x46, 0x00, 0xF7, 0xFF, 0xFA, 0xFF, 0x28, 0x00, 0xF1,
4022 0x00, 0xBE, 0xFF, 0xD4, 0xFB, 0xE2, 0xFD, 0x46, 0x0D, 0xB7, 0x1E,
4023 0xA3, 0x1E, 0x24, 0x0D, 0xD3, 0xFD, 0xD9, 0xFB, 0xC3, 0xFF, 0xF0,
4024 0x00, 0x27, 0x00, 0xFA, 0xFF, 0xF7, 0xFF, 0x48, 0x00, 0xFC, 0x00,
4025 0x20, 0xFF, 0x67, 0xFB, 0xAC, 0xFF, 0xD4, 0x10, 0x59, 0x20, 0x5F,
4026 0x1C, 0xAF, 0x09, 0x88, 0xFC, 0x77, 0xFC, 0x42, 0x00, 0xD5, 0x00,
4027 0x10, 0x00, 0xFD, 0xFF, 0xF7, 0xFF, 0x6D, 0x00, 0xEF, 0x00, 0x6B,
4028 0xFE, 0x3D, 0xFB, 0xED, 0x01, 0x59, 0x14, 0x4D, 0x21, 0x99, 0x19,
4029 0x73, 0x06, 0xB4, 0xFB, 0x31, 0xFD, 0x9F, 0x00, 0xB0, 0x00, 0x01,
4030 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFB, 0xFF, 0x96, 0x00, 0xC7, 0x00,
4031 0xA9, 0xFD, 0x68, 0xFB, 0x9C, 0x04, 0xB0, 0x17, 0x86, 0x21, 0x6E,
4032 0x16, 0x87, 0x03, 0x4C, 0xFB, 0xF5, 0xFD, 0xDA, 0x00, 0x86, 0x00,
4033 0xF9, 0xFF, 0xFF, 0xFF, 0x06, 0x00, 0xBF, 0x00, 0x7F, 0x00, 0xE7,
4034 0xFC, 0xF8, 0xFB, 0xA9, 0x07, 0xB8, 0x1A, 0x04, 0x21, 0x02, 0x13,
4035 0x01, 0x01, 0x44, 0xFB, 0xB3, 0xFE, 0xF7, 0x00, 0x5E, 0x00, 0xF7,
4036 0xFF, 0xFC, 0xFF, 0x18, 0x00, 0xE1, 0x00, 0x15, 0x00, 0x36, 0xFC,
4037 0xF9, 0xFC, 0xFF, 0x0A, 0x4F, 0x1D, 0xCC, 0x1F, 0x76, 0x0F, 0xED,
4038 0xFE, 0x8A, 0xFB, 0x60, 0xFF, 0xFA, 0x00, 0x3B, 0x00, 0xF8, 0xFF,
4039 0xF9, 0xFF, 0x32, 0x00, 0xF7, 0x00, 0x8A, 0xFF, 0xA8, 0xFB, 0x73,
4040 0xFE, 0x80, 0x0E, 0x5A, 0x1F, 0xEB, 0x1D, 0xED, 0x0B, 0x53, 0xFD,
4041 0x0C, 0xFC, 0xF3, 0xFF, 0xE8, 0x00, 0x1E, 0x00, 0xFB, 0xFF, 0xF7,
4042 0xFF, 0x54, 0x00, 0xFA, 0x00, 0xE4, 0xFE, 0x50, 0xFB, 0x66, 0x00,
4043 0x0F, 0x12, 0xC2, 0x20, 0x77, 0x1B, 0x89, 0x08, 0x32, 0xFC, 0xB5,
4044 0xFC, 0x66, 0x00, 0xC9, 0x00, 0x0A, 0x00, 0xFE, 0xFF, 0xF8, 0xFF,
4045 0x7B, 0x00, 0xE5, 0x00, 0x29, 0xFE, 0x41, 0xFB, 0xCF, 0x02, 0x87,
4046 0x15, 0x76, 0x21, 0x8A, 0x18, 0x66, 0x05, 0x84, 0xFB, 0x74, 0xFD,
4047 0xB7, 0x00, 0xA2, 0x00, 0xFE, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFE,
4048 0xFF, 0xA5, 0x00, 0xB2, 0x00, 0x65, 0xFD, 0x8E, 0xFB, 0xA1, 0x05,
4049 0xC7, 0x18, 0x6F, 0x21, 0x45, 0x15, 0x9B, 0x02, 0x40, 0xFB, 0x38,
4050 0xFE, 0xE7, 0x00, 0x78, 0x00, 0xF8, 0xFF, 0xFE, 0xFF, 0x0B, 0x00,
4051 0xCC, 0x00, 0x5E, 0x00, 0xA7, 0xFC, 0x44, 0xFC, 0xCA, 0x08, 0xAC,
4052 0x1B, 0xAD, 0x20, 0xC9, 0x11, 0x3B, 0x00, 0x54, 0xFB, 0xF1, 0xFE,
4053 0xFB, 0x00, 0x51, 0x00, 0xF7, 0xFF, 0xFB, 0xFF, 0x20, 0x00, 0xEA,
4054 0x00, 0xE8, 0xFF, 0x00, 0xFC, 0x6E, 0xFD, 0x32, 0x0C, 0x16, 0x1E,
4055 0x38, 0x1F, 0x3A, 0x0E, 0x51, 0xFE, 0xB1, 0xFB, 0x96, 0xFF, 0xF6,
4056 0x00, 0x30, 0x00, 0xF9, 0xFF, 0xF8, 0xFF, 0x3D, 0x00, 0xFA, 0x00,
4057 0x54, 0xFF, 0x82, 0xFB, 0x12, 0xFF, 0xBC, 0x0F, 0xEA, 0x1F, 0x21,
4058 0x1D, 0xBB, 0x0A, 0xE1, 0xFC, 0x43, 0xFC, 0x1E, 0x00, 0xDF, 0x00,
4059 0x16, 0x00, 0xFC, 0xFF, 0xF7, 0xFF, 0x61, 0x00, 0xF6, 0x00, 0xA5,
4060 0xFE, 0x42, 0xFB, 0x2F, 0x01, 0x47, 0x13, 0x15, 0x21, 0x80, 0x1A,
4061 0x6A, 0x07, 0xE9, 0xFB, 0xF6, 0xFC, 0x86, 0x00, 0xBC, 0x00, 0x05,
4062 0x00, 0xFF, 0xFF, 0xFA, 0xFF, 0x8A, 0x00, 0xD7, 0x00, 0xE6, 0xFD,
4063 0x51, 0xFB, 0xBD, 0x03, 0xB0, 0x16, 0x89, 0x21, 0x71, 0x17, 0x63,
4064 0x04, 0x61, 0xFB, 0xB8, 0xFD, 0xCB, 0x00, 0x93, 0x00, 0xFB, 0xFF,
4065 0x00, 0x00, 0xFF, 0xFF, 0x02, 0x00, 0xB3, 0x00, 0x99, 0x00, 0x22,
4066 0xFD, 0xC0, 0xFB, 0xB0, 0x06, 0xD4, 0x19, 0x41, 0x21, 0x14, 0x14,
4067 0xBC, 0x01, 0x3D, 0xFB, 0x7A, 0xFE, 0xF1, 0x00, 0x6A, 0x00, 0xF7,
4068 0xFF, 0xFD, 0xFF, 0x12, 0x00, 0xD7, 0x00, 0x39, 0x00, 0x6A, 0xFC,
4069 0x9D, 0xFC, 0xF2, 0x09, 0x91, 0x1C, 0x3F, 0x20, 0x8E, 0x10, 0x84,
4070 0xFF, 0x6D, 0xFB, 0x2D, 0xFF, 0xFC, 0x00, 0x45, 0x00, 0xF7, 0xFF,
4071 0xFA, 0xFF, 0x29, 0x00, 0xF2, 0x00, 0xB8, 0xFF, 0xCF, 0xFB, 0xF1,
4072 0xFD, 0x69, 0x0D, 0xCA, 0x1E, 0x90, 0x1E, 0x01, 0x0D, 0xC4, 0xFD,
4073 0xDF, 0xFB, 0xC9, 0xFF, 0xF0, 0x00, 0x26, 0x00, 0xFA, 0xFF, 0xF7,
4074 0xFF, 0x49, 0x00, 0xFC, 0x00, 0x1A, 0xFF, 0x64, 0xFB, 0xC0, 0xFF,
4075 0xF7, 0x10, 0x66, 0x20, 0x46, 0x1C, 0x8E, 0x09, 0x7E, 0xFC, 0x7E,
4076 0xFC, 0x46, 0x00, 0xD4, 0x00, 0x0F, 0x00, 0xFD, 0xFF, 0xF7, 0xFF,
4077 0x6F, 0x00, 0xEE, 0x00, 0x64, 0xFE, 0x3D, 0xFB, 0x05, 0x02, 0x7B,
4078 0x14, 0x53, 0x21, 0x7C, 0x19, 0x54, 0x06, 0xAE, 0xFB, 0x38, 0xFD,
4079 0xA1, 0x00, 0xAE, 0x00, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFC,
4080 0xFF, 0x98, 0x00, 0xC5, 0x00, 0xA2, 0xFD, 0x6C, 0xFB, 0xB8, 0x04,
4081 0xCF, 0x17, 0x85, 0x21, 0x4E, 0x16, 0x6C, 0x03, 0x4A, 0xFB, 0xFC,
4082 0xFD, 0xDC, 0x00, 0x85, 0x00, 0xF9, 0xFF, 0xFF, 0xFF, 0x07, 0x00,
4083 0xC0, 0x00, 0x7B, 0x00, 0xE0, 0xFC, 0x00, 0xFC, 0xC9, 0x07, 0xD3,
4084 0x1A, 0xFC, 0x20, 0xDF, 0x12, 0xEA, 0x00, 0x46, 0xFB, 0xBA, 0xFE,
4085 0xF8, 0x00, 0x5D, 0x00, 0xF7, 0xFF, 0xFC, 0xFF, 0x19, 0x00, 0xE2,
4086 0x00, 0x10, 0x00, 0x30, 0xFC, 0x05, 0xFD, 0x21, 0x0B, 0x66, 0x1D,
4087 0xBD, 0x1F, 0x53, 0x0F, 0xDB, 0xFE, 0x8E, 0xFB, 0x66, 0xFF, 0xFA,
4088 0x00, 0x3A, 0x00, 0xF8, 0xFF, 0xF9, 0xFF, 0x34, 0x00, 0xF7, 0x00,
4089 0x84, 0xFF, 0xA4, 0xFB, 0x84, 0xFE, 0xA3, 0x0E, 0x6C, 0x1F, 0xD6,
4090 0x1D, 0xCB, 0x0B, 0x45, 0xFD, 0x12, 0xFC, 0xF8, 0xFF, 0xE7, 0x00,
4091 0x1D, 0x00, 0xFB, 0xFF, 0xF7, 0xFF, 0x56, 0x00, 0xFA, 0x00, 0xDD,
4092 0xFE, 0x4E, 0xFB, 0x7C, 0x00, 0x32, 0x12, 0xCC, 0x20, 0x5C, 0x1B,
4093 0x69, 0x08, 0x29, 0xFC, 0xBC, 0xFC, 0x69, 0x00, 0xC7, 0x00, 0x09,
4094 0x00, 0xFE, 0xFF, 0xF8, 0xFF, 0x7D, 0x00, 0xE3, 0x00, 0x21, 0xFE,
4095 0x43, 0xFB, 0xE9, 0x02, 0xA9, 0x15, 0x79, 0x21, 0x6B, 0x18, 0x48,
4096 0x05, 0x80, 0xFB, 0x7C, 0xFD, 0xB9, 0x00, 0xA0, 0x00, 0xFD, 0xFF,
4097 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xA6, 0x00, 0xAF, 0x00, 0x5E,
4098 0xFD, 0x93, 0xFB, 0xBE, 0x05, 0xE5, 0x18, 0x6B, 0x21, 0x23, 0x15,
4099 0x82, 0x02, 0x3F, 0xFB, 0x3F, 0xFE, 0xE9, 0x00, 0x77, 0x00, 0xF8,
4100 0xFF, 0xFE, 0xFF, 0x0C, 0x00, 0xCD, 0x00, 0x5A, 0x00, 0xA0, 0xFC,
4101 0x4D, 0xFC, 0xEA, 0x08, 0xC6, 0x1B, 0xA1, 0x20, 0xA6, 0x11, 0x26,
4102 0x00, 0x57, 0xFB, 0xF8, 0xFE, 0xFB, 0x00, 0x50, 0x00, 0xF7, 0xFF,
4103 0xFB, 0xFF, 0x21, 0x00, 0xEB, 0x00, 0xE3, 0xFF, 0xFA, 0xFB, 0x7C,
4104 0xFD, 0x54, 0x0C, 0x2B, 0x1E, 0x26, 0x1F, 0x17, 0x0E, 0x41, 0xFE,
4105 0xB6, 0xFB, 0x9C, 0xFF, 0xF5, 0x00, 0x2F, 0x00, 0xF9, 0xFF, 0xF8,
4106 0xFF, 0x3F, 0x00, 0xFB, 0x00, 0x4D, 0xFF, 0x7F, 0xFB, 0x24, 0xFF,
4107 0xDF, 0x0F, 0xF9, 0x1F, 0x09, 0x1D, 0x99, 0x0A, 0xD5, 0xFC, 0x49,
4108 0xFC, 0x23, 0x00, 0xDD, 0x00, 0x16, 0x00, 0xFC, 0xFF, 0xF7, 0xFF,
4109 0x63, 0x00, 0xF5, 0x00, 0x9E, 0xFE, 0x41, 0xFB, 0x46, 0x01, 0x69,
4110 0x13, 0x1D, 0x21, 0x63, 0x1A, 0x4B, 0x07, 0xE2, 0xFB, 0xFD, 0xFC,
4111 0x89, 0x00, 0xBA, 0x00, 0x04, 0x00, 0xFF, 0xFF, 0xFA, 0xFF, 0x8B,
4112 0x00, 0xD5, 0x00, 0xDE, 0xFD, 0x53, 0xFB, 0xD9, 0x03, 0xD0, 0x16,
4113 0x8A, 0x21, 0x51, 0x17, 0x47, 0x04, 0x5E, 0xFB, 0xC0, 0xFD, 0xCD,
4114 0x00, 0x92, 0x00, 0xFB, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x02, 0x00,
4115 0xB4, 0x00, 0x96, 0x00, 0x1B, 0xFD, 0xC7, 0xFB, 0xCF, 0x06, 0xF0,
4116 0x19, 0x3A, 0x21, 0xF2, 0x13, 0xA4, 0x01, 0x3E, 0xFB, 0x81, 0xFE,
4117 0xF2, 0x00, 0x69, 0x00, 0xF7, 0xFF, 0xFD, 0xFF, 0x12, 0x00, 0xD9,
4118 0x00, 0x35, 0x00, 0x63, 0xFC, 0xA8, 0xFC, 0x13, 0x0A, 0xA9, 0x1C,
4119 0x32, 0x20, 0x6B, 0x10, 0x71, 0xFF, 0x71, 0xFB, 0x34, 0xFF, 0xFB,
4120 0x00, 0x44, 0x00, 0xF8, 0xFF, 0xFA, 0xFF, 0x2B, 0x00, 0xF3, 0x00,
4121 0xB3, 0xFF, 0xCA, 0xFB, 0x01, 0xFE, 0x8C, 0x0D, 0xDD, 0x1E, 0x7C,
4122 0x1E, 0xDE, 0x0C, 0xB5, 0xFD, 0xE4, 0xFB, 0xCE, 0xFF, 0xEF, 0x00,
4123 0x25, 0x00, 0xFA, 0xFF, 0xF7, 0xFF, 0x4A, 0x00, 0xFC, 0x00, 0x13,
4124 0xFF, 0x61, 0xFB, 0xD4, 0xFF, 0x1A, 0x11, 0x72, 0x20, 0x2D, 0x1C,
4125 0x6D, 0x09, 0x74, 0xFC, 0x85, 0xFC, 0x4A, 0x00, 0xD2, 0x00, 0x0F,
4126 0x00, 0xFD, 0xFF, 0xF7, 0xFF, 0x70, 0x00, 0xED, 0x00, 0x5D, 0xFE,
4127 0x3D, 0xFB, 0x1E, 0x02, 0x9C, 0x14, 0x58, 0x21, 0x5E, 0x19, 0x36,
4128 0x06, 0xA8, 0xFB, 0x40, 0xFD, 0xA4, 0x00, 0xAD, 0x00, 0x00, 0x00,
4129 0xFF, 0xFF, 0x00, 0x00, 0xFC, 0xFF, 0x9A, 0x00, 0xC3, 0x00, 0x9A,
4130 0xFD, 0x6F, 0xFB, 0xD5, 0x04, 0xEF, 0x17, 0x83, 0x21, 0x2D, 0x16,
4131 0x52, 0x03, 0x49, 0xFB, 0x04, 0xFE, 0xDD, 0x00, 0x83, 0x00, 0xF9,
4132 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0xC2, 0x00, 0x78, 0x00, 0xD9, 0xFC,
4133 0x08, 0xFC, 0xE9, 0x07, 0xEF, 0x1A, 0xF3, 0x20, 0xBC, 0x12, 0xD4,
4134 0x00, 0x47, 0xFB, 0xC1, 0xFE, 0xF8, 0x00, 0x5B, 0x00, 0xF7, 0xFF,
4135 0xFC, 0xFF, 0x1A, 0x00, 0xE3, 0x00, 0x0B, 0x00, 0x2A, 0xFC, 0x12,
4136 0xFD, 0x42, 0x0B, 0x7D, 0x1D, 0xAD, 0x1F, 0x2F, 0x0F, 0xC9, 0xFE,
4137 0x92, 0xFB, 0x6C, 0xFF, 0xF9, 0x00, 0x38, 0x00, 0xF8, 0xFF, 0xF9,
4138 0xFF, 0x35, 0x00, 0xF8, 0x00, 0x7E, 0xFF, 0x9F, 0xFB, 0x95, 0xFE,
4139 0xC6, 0x0E, 0x7C, 0x1F, 0xC0, 0x1D, 0xA9, 0x0B, 0x38, 0xFD, 0x18,
4140 0xFC, 0xFD, 0xFF, 0xE6, 0x00, 0x1D, 0x00, 0xFB, 0xFF, 0xF7, 0xFF,
4141 0x57, 0x00, 0xFA, 0x00, 0xD6, 0xFE, 0x4C, 0xFB, 0x92, 0x00, 0x54,
4142 0x12, 0xD6, 0x20, 0x41, 0x1B, 0x49, 0x08, 0x20, 0xFC, 0xC3, 0xFC,
4143 0x6D, 0x00, 0xC6, 0x00, 0x09, 0x00, 0xFE, 0xFF, 0xF8, 0xFF, 0x7E,
4144 0x00, 0xE2, 0x00, 0x1A, 0xFE, 0x44, 0xFB, 0x03, 0x03, 0xCA, 0x15,
4145 0x7C, 0x21, 0x4C, 0x18, 0x2B, 0x05, 0x7B, 0xFB, 0x83, 0xFD, 0xBC,
4146 0x00, 0x9E, 0x00, 0xFD, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
4147 0xA8, 0x00, 0xAD, 0x00, 0x56, 0xFD, 0x98, 0xFB, 0xDC, 0x05, 0x04,
4148 0x19, 0x66, 0x21, 0x02, 0x15, 0x69, 0x02, 0x3E, 0xFB, 0x47, 0xFE,
4149 0xEA, 0x00, 0x75, 0x00, 0xF8, 0xFF, 0xFE, 0xFF, 0x0D, 0x00, 0xCE,
4150 0x00, 0x56, 0x00, 0x99, 0xFC, 0x56, 0xFC, 0x0B, 0x09, 0xE0, 0x1B,
4151 0x96, 0x20, 0x83, 0x11, 0x11, 0x00, 0x59, 0xFB, 0xFF, 0xFE, 0xFB,
4152 0x00, 0x4E, 0x00, 0xF7, 0xFF, 0xFB, 0xFF, 0x22, 0x00, 0xEC, 0x00,
4153 0xDE, 0xFF, 0xF5, 0xFB, 0x8A, 0xFD, 0x77, 0x0C, 0x3F, 0x1E, 0x14,
4154 0x1F, 0xF5, 0x0D, 0x31, 0xFE, 0xBB, 0xFB, 0xA2, 0xFF, 0xF5, 0x00,
4155 0x2E, 0x00, 0xF9, 0xFF, 0xF8, 0xFF, 0x40, 0x00, 0xFB, 0x00, 0x47,
4156 0xFF, 0x7B, 0xFB, 0x37, 0xFF, 0x02, 0x10, 0x07, 0x20, 0xF2, 0x1C,
4157 0x78, 0x0A, 0xCA, 0xFC, 0x50, 0xFC, 0x27, 0x00, 0xDC, 0x00, 0x15,
4158 0x00, 0xFC, 0xFF, 0xF7, 0xFF, 0x64, 0x00, 0xF5, 0x00, 0x97, 0xFE,
4159 0x40, 0xFB, 0x5D, 0x01, 0x8B, 0x13, 0x25, 0x21, 0x47, 0x1A, 0x2C,
4160 0x07, 0xDB, 0xFB, 0x05, 0xFD, 0x8C, 0x00, 0xB9, 0x00, 0x04, 0x00,
4161 0xFF, 0xFF, 0xFA, 0xFF, 0x8D, 0x00, 0xD3, 0x00, 0xD6, 0xFD, 0x56,
4162 0xFB, 0xF4, 0x03, 0xF0, 0x16, 0x8A, 0x21, 0x31, 0x17, 0x2B, 0x04,
4163 0x5B, 0xFB, 0xC7, 0xFD, 0xCF, 0x00, 0x90, 0x00, 0xFA, 0xFF, 0x00,
4164 0x00, 0xFF, 0xFF, 0x03, 0x00, 0xB6, 0x00, 0x92, 0x00, 0x13, 0xFD,
4165 0xCD, 0xFB, 0xEE, 0x06, 0x0D, 0x1A, 0x33, 0x21, 0xD0, 0x13, 0x8C,
4166 0x01, 0x3E, 0xFB, 0x88, 0xFE, 0xF3, 0x00, 0x67, 0x00, 0xF7, 0xFF,
4167 0x06, 0x00, 0x1D, 0x00, 0x03, 0xFF, 0xFE, 0x00, 0xA1, 0x02, 0xA6,
4168 0xF8, 0x56, 0x02, 0xA5, 0x28, 0xA5, 0x28, 0x56, 0x02, 0xA6, 0xF8,
4169 0xA1, 0x02, 0xFE, 0x00, 0x03, 0xFF, 0x1D, 0x00, 0x06, 0x00, 0x00,
4170 0x00, 0x21, 0x00, 0xA6, 0xFF, 0x3F, 0xFF, 0x0B, 0x03, 0x42, 0xFE,
4171 0x3E, 0xF8, 0x7F, 0x15, 0xAC, 0x30, 0x7F, 0x15, 0x3E, 0xF8, 0x42,
4172 0xFE, 0x0B, 0x03, 0x3F, 0xFF, 0xA6, 0xFF, 0x21, 0x00, 0x00, 0x00,
4173 0xFA, 0xFF, 0xCE, 0xFF, 0x14, 0x01, 0x00, 0xFD, 0x35, 0x06, 0xD5,
4174 0xF4, 0xDA, 0x15, 0x92, 0x40, 0xAE, 0xFE, 0xF3, 0xFC, 0x68, 0x03,
4175 0x86, 0xFD, 0x51, 0x01, 0x8B, 0xFF, 0x11, 0x00, 0x01, 0x00, 0xEC,
4176 0xFF, 0xF9, 0xFF, 0xC6, 0x00, 0x55, 0xFD, 0x35, 0x06, 0x90, 0xF3,
4177 0xE5, 0x1C, 0x6B, 0x3D, 0x71, 0xFA, 0x34, 0xFF, 0x46, 0x02, 0xFF,
4178 0xFD, 0x2D, 0x01, 0x90, 0xFF, 0x10, 0x00, 0x03, 0x00, 0xDB, 0xFF,
4179 0x2D, 0x00, 0x60, 0x00, 0xE1, 0xFD, 0xCE, 0x05, 0xED, 0xF2, 0xF3,
4180 0x23, 0x20, 0x39, 0x22, 0xF7, 0x44, 0x01, 0x1F, 0x01, 0x89, 0xFE,
4181 0xFB, 0x00, 0x9C, 0xFF, 0x0D, 0x00, 0x06, 0x00, 0xC9, 0xFF, 0x68,
4182 0x00, 0xE5, 0xFF, 0xA0, 0xFE, 0xFB, 0x04, 0x0C, 0xF3, 0xC5, 0x2A,
4183 0xD8, 0x33, 0xC9, 0xF4, 0x0B, 0x03, 0x05, 0x00, 0x1A, 0xFF, 0xC1,
4184 0x00, 0xAD, 0xFF, 0x0A, 0x00, 0x09, 0x00, 0xB5, 0xFF, 0xA5, 0x00,
4185 0x5C, 0xFF, 0x8C, 0xFF, 0xBF, 0x03, 0x06, 0xF4, 0x22, 0x31, 0xC8,
4186 0x2D, 0x63, 0xF3, 0x76, 0x04, 0x08, 0xFF, 0xA7, 0xFF, 0x84, 0x00,
4187 0xC0, 0xFF, 0x07, 0x00, 0x0C, 0x00, 0xA4, 0xFF, 0xE1, 0x00, 0xCB,
4188 0xFE, 0x9B, 0x00, 0x21, 0x02, 0xEE, 0xF5, 0xCD, 0x36, 0x24, 0x27,
4189 0xE1, 0xF2, 0x7A, 0x05, 0x33, 0xFE, 0x2A, 0x00, 0x47, 0x00, 0xD3,
4190 0xFF, 0x04, 0x00, 0x0F, 0x00, 0x95, 0xFF, 0x17, 0x01, 0x3D, 0xFE,
4191 0xBD, 0x01, 0x30, 0x00, 0xCC, 0xF8, 0x92, 0x3B, 0x2A, 0x20, 0x2E,
4192 0xF3, 0x12, 0x06, 0x8F, 0xFD, 0x9A, 0x00, 0x10, 0x00, 0xE5, 0xFF,
4193 0x02, 0x00, 0x10, 0x00, 0x8C, 0xFF, 0x42, 0x01, 0xBB, 0xFD, 0xE4,
4194 0x02, 0x01, 0xFE, 0x9C, 0xFC, 0x45, 0x3F, 0x16, 0x19, 0x2D, 0xF4,
4195 0x41, 0x06, 0x21, 0xFD, 0xF3, 0x00, 0xE0, 0xFF, 0xF4, 0xFF, 0x01,
4196 0x00, 0x10, 0x00, 0x8B, 0xFF, 0x5D, 0x01, 0x4F, 0xFD, 0xFB, 0x03,
4197 0xB2, 0xFB, 0x53, 0x01, 0xC2, 0x41, 0x24, 0x12, 0xBA, 0xF5, 0x0F,
4198 0x06, 0xE9, 0xFC, 0x33, 0x01, 0xBB, 0xFF, 0x00, 0x00, 0x00, 0x00,
4199 0x0D, 0x00, 0x93, 0xFF, 0x63, 0x01, 0x04, 0xFD, 0xEF, 0x04, 0x62,
4200 0xF9, 0xD7, 0x06, 0xF2, 0x42, 0x8D, 0x0B, 0xB0, 0xF7, 0x87, 0x05,
4201 0xE6, 0xFC, 0x58, 0x01, 0xA0, 0xFF, 0x09, 0x00, 0x00, 0x00, 0x00,
4202 0x00, 0x07, 0x00, 0xA5, 0xFF, 0x52, 0x01, 0xE2, 0xFC, 0xAD, 0x05,
4203 0x35, 0xF7, 0x08, 0x0D, 0xCB, 0x42, 0x81, 0x05, 0xE8, 0xF9, 0xBB,
4204 0x04, 0x12, 0xFD, 0x64, 0x01, 0x90, 0xFF, 0x0E, 0x00, 0x00, 0x00,
4205 0xFE, 0xFF, 0xC2, 0xFF, 0x27, 0x01, 0xF1, 0xFC, 0x22, 0x06, 0x54,
4206 0xF5, 0xB8, 0x13, 0x4A, 0x41, 0x29, 0x00, 0x3C, 0xFC, 0xBD, 0x03,
4207 0x66, 0xFD, 0x58, 0x01, 0x8A, 0xFF, 0x11, 0x00, 0x01, 0x00, 0xF1,
4208 0xFF, 0xEB, 0xFF, 0xE1, 0x00, 0x35, 0xFD, 0x40, 0x06, 0xE4, 0xF3,
4209 0xB7, 0x1A, 0x85, 0x3E, 0xA6, 0xFB, 0x86, 0xFE, 0xA0, 0x02, 0xD7,
4210 0xFD, 0x39, 0x01, 0x8E, 0xFF, 0x10, 0x00, 0x03, 0x00, 0xE1, 0xFF,
4211 0x1C, 0x00, 0x82, 0x00, 0xB0, 0xFD, 0xF9, 0x05, 0x0C, 0xF3, 0xCB,
4212 0x21, 0x8F, 0x3A, 0x0D, 0xF8, 0xA9, 0x00, 0x79, 0x01, 0x5D, 0xFE,
4213 0x0B, 0x01, 0x98, 0xFF, 0x0E, 0x00, 0x05, 0x00, 0xCE, 0xFF, 0x55,
4214 0x00, 0x0D, 0x00, 0x60, 0xFE, 0x48, 0x05, 0xEC, 0xF2, 0xB6, 0x28,
4215 0x91, 0x35, 0x68, 0xF5, 0x88, 0x02, 0x5A, 0x00, 0xED, 0xFE, 0xD4,
4216 0x00, 0xA8, 0xFF, 0x0B, 0x00, 0x08, 0x00, 0xBB, 0xFF, 0x92, 0x00,
4217 0x87, 0xFF, 0x3F, 0xFF, 0x2B, 0x04, 0xA1, 0xF3, 0x3D, 0x2F, 0xB8,
4218 0x2F, 0xB8, 0xF3, 0x11, 0x04, 0x52, 0xFF, 0x7C, 0xFF, 0x97, 0x00,
4219 0xBA, 0xFF, 0x08, 0x00, 0x0B, 0x00, 0xA9, 0xFF, 0xCF, 0x00, 0xF8,
4220 0xFE, 0x44, 0x00, 0xAA, 0x02, 0x3E, 0xF5, 0x24, 0x35, 0x3B, 0x29,
4221 0xF2, 0xF2, 0x35, 0x05, 0x70, 0xFE, 0x03, 0x00, 0x5A, 0x00, 0xCD,
4222 0xFF, 0x05, 0x00, 0x0E, 0x00, 0x99, 0xFF, 0x07, 0x01, 0x68, 0xFE,
4223 0x63, 0x01, 0xD0, 0x00, 0xD0, 0xF7, 0x35, 0x3A, 0x55, 0x22, 0x02,
4224 0xF3, 0xEF, 0x05, 0xBC, 0xFD, 0x7A, 0x00, 0x20, 0x00, 0xDF, 0xFF,
4225 0x03, 0x00, 0x10, 0x00, 0x8E, 0xFF, 0x36, 0x01, 0xE1, 0xFD, 0x8A,
4226 0x02, 0xB2, 0xFE, 0x56, 0xFB, 0x40, 0x3E, 0x42, 0x1B, 0xCE, 0xF3,
4227 0x3E, 0x06, 0x3D, 0xFD, 0xDB, 0x00, 0xEE, 0xFF, 0xF0, 0xFF, 0x01,
4228 0x00, 0x11, 0x00, 0x8A, 0xFF, 0x57, 0x01, 0x6D, 0xFD, 0xA8, 0x03,
4229 0x69, 0xFC, 0xC8, 0xFF, 0x20, 0x41, 0x40, 0x14, 0x33, 0xF5, 0x28,
4230 0x06, 0xF5, 0xFC, 0x22, 0x01, 0xC5, 0xFF, 0xFD, 0xFF, 0x00, 0x00,
4231 0x0F, 0x00, 0x8F, 0xFF, 0x64, 0x01, 0x17, 0xFD, 0xA9, 0x04, 0x16,
4232 0xFA, 0x10, 0x05, 0xB8, 0x42, 0x87, 0x0D, 0x0D, 0xF7, 0xB9, 0x05,
4233 0xE2, 0xFC, 0x50, 0x01, 0xA7, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00,
4234 0x00, 0x0A, 0x00, 0x9E, 0xFF, 0x5A, 0x01, 0xE8, 0xFC, 0x7A, 0x05,
4235 0xDA, 0xF7, 0x10, 0x0B, 0xFB, 0x42, 0x4B, 0x07, 0x35, 0xF9, 0x00,
4236 0x05, 0x00, 0xFD, 0x63, 0x01, 0x94, 0xFF, 0x0D, 0x00, 0x00, 0x00,
4237 0x01, 0x00, 0xB8, 0xFF, 0x37, 0x01, 0xE7, 0xFC, 0x07, 0x06, 0xDE,
4238 0xF5, 0x9F, 0x11, 0xE4, 0x41, 0xB8, 0x01, 0x84, 0xFB, 0x0F, 0x04,
4239 0x48, 0xFD, 0x5E, 0x01, 0x8B, 0xFF, 0x10, 0x00, 0x01, 0x00, 0xF5,
4240 0xFF, 0xDD, 0xFF, 0xF9, 0x00, 0x1B, 0xFD, 0x41, 0x06, 0x47, 0xF4,
4241 0x8B, 0x18, 0x81, 0x3F, 0xF1, 0xFC, 0xD5, 0xFD, 0xFA, 0x02, 0xB2,
4242 0xFD, 0x45, 0x01, 0x8C, 0xFF, 0x11, 0x00, 0x02, 0x00, 0xE6, 0xFF,
4243 0x0C, 0x00, 0xA2, 0x00, 0x85, 0xFD, 0x1A, 0x06, 0x3C, 0xF3, 0x9F,
4244 0x1F, 0xE6, 0x3B, 0x0E, 0xF9, 0x07, 0x00, 0xD4, 0x01, 0x33, 0xFE,
4245 0x1B, 0x01, 0x94, 0xFF, 0x0F, 0x00, 0x04, 0x00, 0xD4, 0xFF, 0x43,
4246 0x00, 0x33, 0x00, 0x25, 0xFE, 0x89, 0x05, 0xE0, 0xF2, 0x9C, 0x26,
4247 0x33, 0x37, 0x1E, 0xF6, 0xFD, 0x01, 0xB0, 0x00, 0xC0, 0xFE, 0xE6,
4248 0x00, 0xA2, 0xFF, 0x0C, 0x00, 0x07, 0x00, 0xC1, 0xFF, 0x7F, 0x00,
4249 0xB2, 0xFF, 0xF6, 0xFE, 0x8E, 0x04, 0x51, 0xF3, 0x49, 0x2D, 0x98,
4250 0x31, 0x23, 0xF4, 0xA2, 0x03, 0xA0, 0xFF, 0x51, 0xFF, 0xAA, 0x00,
4251 0xB4, 0xFF, 0x09, 0x00, 0x0A, 0x00, 0xAE, 0xFF, 0xBD, 0x00, 0x25,
4252 0xFF, 0xF1, 0xFF, 0x2B, 0x03, 0xA5, 0xF4, 0x68, 0x33, 0x48, 0x2B,
4253 0x17, 0xF3, 0xE7, 0x04, 0xB1, 0xFE, 0xDB, 0xFF, 0x6C, 0x00, 0xC7,
4254 0xFF, 0x06, 0x00, 0x0D, 0x00, 0x9E, 0xFF, 0xF7, 0x00, 0x94, 0xFE,
4255 0x09, 0x01, 0x6A, 0x01, 0xEB, 0xF6, 0xC1, 0x38, 0x7D, 0x24, 0xE8,
4256 0xF2, 0xC1, 0x05, 0xEE, 0xFD, 0x57, 0x00, 0x31, 0x00, 0xDA, 0xFF,
4257 0x03, 0x00, 0x10, 0x00, 0x91, 0xFF, 0x29, 0x01, 0x09, 0xFE, 0x2F,
4258 0x02, 0x5F, 0xFF, 0x27, 0xFA, 0x20, 0x3D, 0x70, 0x1D, 0x7D, 0xF3,
4259 0x31, 0x06, 0x5E, 0xFD, 0xBF, 0x00, 0xFD, 0xFF, 0xEB, 0xFF, 0x02,
4260 0x00, 0x11, 0x00, 0x8B, 0xFF, 0x4E, 0x01, 0x8E, 0xFD, 0x52, 0x03,
4261 0x20, 0xFD, 0x52, 0xFE, 0x60, 0x40, 0x63, 0x16, 0xB7, 0xF4, 0x39,
4262 0x06, 0x05, 0xFD, 0x0F, 0x01, 0xD1, 0xFF, 0xF9, 0xFF, 0x00, 0x00,
4263 0x10, 0x00, 0x8D, 0xFF, 0x62, 0x01, 0x2E, 0xFD, 0x5E, 0x04, 0xCC,
4264 0xFA, 0x5B, 0x03, 0x5E, 0x42, 0x8E, 0x0F, 0x71, 0xF6, 0xE4, 0x05,
4265 0xE2, 0xFC, 0x45, 0x01, 0xAF, 0xFF, 0x04, 0x00, 0x00, 0x00, 0x00,
4266 0x00, 0x0B, 0x00, 0x99, 0xFF, 0x60, 0x01, 0xF2, 0xFC, 0x40, 0x05,
4267 0x85, 0xF8, 0x26, 0x09, 0x0C, 0x43, 0x26, 0x09, 0x85, 0xF8, 0x40,
4268 0x05, 0xF2, 0xFC, 0x60, 0x01, 0x99, 0xFF, 0x0B, 0x00, 0x00, 0x00,
4269 0x04, 0x00, 0xAF, 0xFF, 0x45, 0x01, 0xE2, 0xFC, 0xE4, 0x05, 0x71,
4270 0xF6, 0x8E, 0x0F, 0x5E, 0x42, 0x5B, 0x03, 0xCC, 0xFA, 0x5E, 0x04,
4271 0x2E, 0xFD, 0x62, 0x01, 0x8D, 0xFF, 0x10, 0x00, 0x00, 0x00, 0xF9,
4272 0xFF, 0xD1, 0xFF, 0x0F, 0x01, 0x05, 0xFD, 0x39, 0x06, 0xB7, 0xF4,
4273 0x63, 0x16, 0x60, 0x40, 0x52, 0xFE, 0x20, 0xFD, 0x52, 0x03, 0x8E,
4274 0xFD, 0x4E, 0x01, 0x8B, 0xFF, 0x11, 0x00, 0x02, 0x00, 0xEB, 0xFF,
4275 0xFD, 0xFF, 0xBF, 0x00, 0x5E, 0xFD, 0x31, 0x06, 0x7D, 0xF3, 0x70,
4276 0x1D, 0x20, 0x3D, 0x27, 0xFA, 0x5F, 0xFF, 0x2F, 0x02, 0x09, 0xFE,
4277 0x29, 0x01, 0x91, 0xFF, 0x10, 0x00, 0x03, 0x00, 0xDA, 0xFF, 0x31,
4278 0x00, 0x57, 0x00, 0xEE, 0xFD, 0xC1, 0x05, 0xE8, 0xF2, 0x7D, 0x24,
4279 0xC1, 0x38, 0xEB, 0xF6, 0x6A, 0x01, 0x09, 0x01, 0x94, 0xFE, 0xF7,
4280 0x00, 0x9E, 0xFF, 0x0D, 0x00, 0x06, 0x00, 0xC7, 0xFF, 0x6C, 0x00,
4281 0xDB, 0xFF, 0xB1, 0xFE, 0xE7, 0x04, 0x17, 0xF3, 0x48, 0x2B, 0x68,
4282 0x33, 0xA5, 0xF4, 0x2B, 0x03, 0xF1, 0xFF, 0x25, 0xFF, 0xBD, 0x00,
4283 0xAE, 0xFF, 0x0A, 0x00, 0x09, 0x00, 0xB4, 0xFF, 0xAA, 0x00, 0x51,
4284 0xFF, 0xA0, 0xFF, 0xA2, 0x03, 0x23, 0xF4, 0x98, 0x31, 0x49, 0x2D,
4285 0x51, 0xF3, 0x8E, 0x04, 0xF6, 0xFE, 0xB2, 0xFF, 0x7F, 0x00, 0xC1,
4286 0xFF, 0x07, 0x00, 0x0C, 0x00, 0xA2, 0xFF, 0xE6, 0x00, 0xC0, 0xFE,
4287 0xB0, 0x00, 0xFD, 0x01, 0x1E, 0xF6, 0x33, 0x37, 0x9C, 0x26, 0xE0,
4288 0xF2, 0x89, 0x05, 0x25, 0xFE, 0x33, 0x00, 0x43, 0x00, 0xD4, 0xFF,
4289 0x04, 0x00, 0x0F, 0x00, 0x94, 0xFF, 0x1B, 0x01, 0x33, 0xFE, 0xD4,
4290 0x01, 0x07, 0x00, 0x0E, 0xF9, 0xE6, 0x3B, 0x9F, 0x1F, 0x3C, 0xF3,
4291 0x1A, 0x06, 0x85, 0xFD, 0xA2, 0x00, 0x0C, 0x00, 0xE6, 0xFF, 0x02,
4292 0x00, 0x11, 0x00, 0x8C, 0xFF, 0x45, 0x01, 0xB2, 0xFD, 0xFA, 0x02,
4293 0xD5, 0xFD, 0xF1, 0xFC, 0x81, 0x3F, 0x8B, 0x18, 0x47, 0xF4, 0x41,
4294 0x06, 0x1B, 0xFD, 0xF9, 0x00, 0xDD, 0xFF, 0xF5, 0xFF, 0x01, 0x00,
4295 0x10, 0x00, 0x8B, 0xFF, 0x5E, 0x01, 0x48, 0xFD, 0x0F, 0x04, 0x84,
4296 0xFB, 0xB8, 0x01, 0xE4, 0x41, 0x9F, 0x11, 0xDE, 0xF5, 0x07, 0x06,
4297 0xE7, 0xFC, 0x37, 0x01, 0xB8, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x0D,
4298 0x00, 0x94, 0xFF, 0x63, 0x01, 0x00, 0xFD, 0x00, 0x05, 0x35, 0xF9,
4299 0x4B, 0x07, 0xFB, 0x42, 0x10, 0x0B, 0xDA, 0xF7, 0x7A, 0x05, 0xE8,
4300 0xFC, 0x5A, 0x01, 0x9E, 0xFF, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00,
4301 0x07, 0x00, 0xA7, 0xFF, 0x50, 0x01, 0xE2, 0xFC, 0xB9, 0x05, 0x0D,
4302 0xF7, 0x87, 0x0D, 0xB8, 0x42, 0x10, 0x05, 0x16, 0xFA, 0xA9, 0x04,
4303 0x17, 0xFD, 0x64, 0x01, 0x8F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xFD,
4304 0xFF, 0xC5, 0xFF, 0x22, 0x01, 0xF5, 0xFC, 0x28, 0x06, 0x33, 0xF5,
4305 0x40, 0x14, 0x20, 0x41, 0xC8, 0xFF, 0x69, 0xFC, 0xA8, 0x03, 0x6D,
4306 0xFD, 0x57, 0x01, 0x8A, 0xFF, 0x11, 0x00, 0x01, 0x00, 0xF0, 0xFF,
4307 0xEE, 0xFF, 0xDB, 0x00, 0x3D, 0xFD, 0x3E, 0x06, 0xCE, 0xF3, 0x42,
4308 0x1B, 0x40, 0x3E, 0x56, 0xFB, 0xB2, 0xFE, 0x8A, 0x02, 0xE1, 0xFD,
4309 0x36, 0x01, 0x8E, 0xFF, 0x10, 0x00, 0x03, 0x00, 0xDF, 0xFF, 0x20,
4310 0x00, 0x7A, 0x00, 0xBC, 0xFD, 0xEF, 0x05, 0x02, 0xF3, 0x55, 0x22,
4311 0x35, 0x3A, 0xD0, 0xF7, 0xD0, 0x00, 0x63, 0x01, 0x68, 0xFE, 0x07,
4312 0x01, 0x99, 0xFF, 0x0E, 0x00, 0x05, 0x00, 0xCD, 0xFF, 0x5A, 0x00,
4313 0x03, 0x00, 0x70, 0xFE, 0x35, 0x05, 0xF2, 0xF2, 0x3B, 0x29, 0x24,
4314 0x35, 0x3E, 0xF5, 0xAA, 0x02, 0x44, 0x00, 0xF8, 0xFE, 0xCF, 0x00,
4315 0xA9, 0xFF, 0x0B, 0x00, 0x08, 0x00, 0xBA, 0xFF, 0x97, 0x00, 0x7C,
4316 0xFF, 0x52, 0xFF, 0x11, 0x04, 0xB8, 0xF3, 0xB8, 0x2F, 0x3D, 0x2F,
4317 0xA1, 0xF3, 0x2B, 0x04, 0x3F, 0xFF, 0x87, 0xFF, 0x92, 0x00, 0xBB,
4318 0xFF, 0x08, 0x00, 0x0B, 0x00, 0xA8, 0xFF, 0xD4, 0x00, 0xED, 0xFE,
4319 0x5A, 0x00, 0x88, 0x02, 0x68, 0xF5, 0x91, 0x35, 0xB6, 0x28, 0xEC,
4320 0xF2, 0x48, 0x05, 0x60, 0xFE, 0x0D, 0x00, 0x55, 0x00, 0xCE, 0xFF,
4321 0x05, 0x00, 0x0E, 0x00, 0x98, 0xFF, 0x0B, 0x01, 0x5D, 0xFE, 0x79,
4322 0x01, 0xA9, 0x00, 0x0D, 0xF8, 0x8F, 0x3A, 0xCB, 0x21, 0x0C, 0xF3,
4323 0xF9, 0x05, 0xB0, 0xFD, 0x82, 0x00, 0x1C, 0x00, 0xE1, 0xFF, 0x03,
4324 0x00, 0x10, 0x00, 0x8E, 0xFF, 0x39, 0x01, 0xD7, 0xFD, 0xA0, 0x02,
4325 0x86, 0xFE, 0xA6, 0xFB, 0x85, 0x3E, 0xB7, 0x1A, 0xE4, 0xF3, 0x40,
4326 0x06, 0x35, 0xFD, 0xE1, 0x00, 0xEB, 0xFF, 0xF1, 0xFF, 0x01, 0x00,
4327 0x11, 0x00, 0x8A, 0xFF, 0x58, 0x01, 0x66, 0xFD, 0xBD, 0x03, 0x3C,
4328 0xFC, 0x29, 0x00, 0x4A, 0x41, 0xB8, 0x13, 0x54, 0xF5, 0x22, 0x06,
4329 0xF1, 0xFC, 0x27, 0x01, 0xC2, 0xFF, 0xFE, 0xFF, 0x00, 0x00, 0x0E,
4330 0x00, 0x90, 0xFF, 0x64, 0x01, 0x12, 0xFD, 0xBB, 0x04, 0xE8, 0xF9,
4331 0x81, 0x05, 0xCB, 0x42, 0x08, 0x0D, 0x35, 0xF7, 0xAD, 0x05, 0xE2,
4332 0xFC, 0x52, 0x01, 0xA5, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
4333 0x09, 0x00, 0xA0, 0xFF, 0x58, 0x01, 0xE6, 0xFC, 0x87, 0x05, 0xB0,
4334 0xF7, 0x8D, 0x0B, 0xF2, 0x42, 0xD7, 0x06, 0x62, 0xF9, 0xEF, 0x04,
4335 0x04, 0xFD, 0x63, 0x01, 0x93, 0xFF, 0x0D, 0x00, 0x00, 0x00, 0x00,
4336 0x00, 0xBB, 0xFF, 0x33, 0x01, 0xE9, 0xFC, 0x0F, 0x06, 0xBA, 0xF5,
4337 0x24, 0x12, 0xC2, 0x41, 0x53, 0x01, 0xB2, 0xFB, 0xFB, 0x03, 0x4F,
4338 0xFD, 0x5D, 0x01, 0x8B, 0xFF, 0x10, 0x00, 0x01, 0x00, 0xF4, 0xFF,
4339 0xE0, 0xFF, 0xF3, 0x00, 0x21, 0xFD, 0x41, 0x06, 0x2D, 0xF4, 0x16,
4340 0x19, 0x45, 0x3F, 0x9C, 0xFC, 0x01, 0xFE, 0xE4, 0x02, 0xBB, 0xFD,
4341 0x42, 0x01, 0x8C, 0xFF, 0x10, 0x00, 0x02, 0x00, 0xE5, 0xFF, 0x10,
4342 0x00, 0x9A, 0x00, 0x8F, 0xFD, 0x12, 0x06, 0x2E, 0xF3, 0x2A, 0x20,
4343 0x92, 0x3B, 0xCC, 0xF8, 0x30, 0x00, 0xBD, 0x01, 0x3D, 0xFE, 0x17,
4344 0x01, 0x95, 0xFF, 0x0F, 0x00, 0x04, 0x00, 0xD3, 0xFF, 0x47, 0x00,
4345 0x2A, 0x00, 0x33, 0xFE, 0x7A, 0x05, 0xE1, 0xF2, 0x24, 0x27, 0xCD,
4346 0x36, 0xEE, 0xF5, 0x21, 0x02, 0x9B, 0x00, 0xCB, 0xFE, 0xE1, 0x00,
4347 0xA4, 0xFF, 0x0C, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0x84, 0x00, 0xA7,
4348 0xFF, 0x08, 0xFF, 0x76, 0x04, 0x63, 0xF3, 0xC8, 0x2D, 0x22, 0x31,
4349 0x06, 0xF4, 0xBF, 0x03, 0x8C, 0xFF, 0x5C, 0xFF, 0xA5, 0x00, 0xB5,
4350 0xFF, 0x09, 0x00, 0x0A, 0x00, 0xAD, 0xFF, 0xC1, 0x00, 0x1A, 0xFF,
4351 0x05, 0x00, 0x0B, 0x03, 0xC9, 0xF4, 0xD8, 0x33, 0xC5, 0x2A, 0x0C,
4352 0xF3, 0xFB, 0x04, 0xA0, 0xFE, 0xE5, 0xFF, 0x68, 0x00, 0xC9, 0xFF,
4353 0x06, 0x00, 0x0D, 0x00, 0x9C, 0xFF, 0xFB, 0x00, 0x89, 0xFE, 0x1F,
4354 0x01, 0x44, 0x01, 0x22, 0xF7, 0x20, 0x39, 0xF3, 0x23, 0xED, 0xF2,
4355 0xCE, 0x05, 0xE1, 0xFD, 0x60, 0x00, 0x2D, 0x00, 0xDB, 0xFF, 0x03,
4356 0x00, 0x10, 0x00, 0x90, 0xFF, 0x2D, 0x01, 0xFF, 0xFD, 0x46, 0x02,
4357 0x34, 0xFF, 0x71, 0xFA, 0x6B, 0x3D, 0xE5, 0x1C, 0x90, 0xF3, 0x35,
4358 0x06, 0x55, 0xFD, 0xC6, 0x00, 0xF9, 0xFF, 0xEC, 0xFF, 0x01, 0x00,
4359 0x11, 0x00, 0x8B, 0xFF, 0x51, 0x01, 0x86, 0xFD, 0x68, 0x03, 0xF3,
4360 0xFC, 0xAE, 0xFE, 0x92, 0x40, 0xDA, 0x15, 0xD5, 0xF4, 0x35, 0x06,
4361 0x00, 0xFD, 0x14, 0x01, 0xCE, 0xFF, 0xFA, 0xFF, 0x00, 0x00, 0x0F,
4362 0x00, 0x8D, 0xFF, 0x63, 0x01, 0x28, 0xFD, 0x71, 0x04, 0x9E, 0xFA,
4363 0xC7, 0x03, 0x79, 0x42, 0x0B, 0x0F, 0x97, 0xF6, 0xDA, 0x05, 0xE2,
4364 0xFC, 0x48, 0x01, 0xAD, 0xFF, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
4365 0x0B, 0x00, 0x9A, 0xFF, 0x5F, 0x01, 0xEF, 0xFC, 0x4F, 0x05, 0x5A,
4366 0xF8, 0x9F, 0x09, 0x0A, 0x43, 0xAE, 0x08, 0xB1, 0xF8, 0x30, 0x05,
4367 0xF5, 0xFC, 0x61, 0x01, 0x97, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x03,
4368 0x00, 0xB1, 0xFF, 0x41, 0x01, 0xE3, 0xFC, 0xED, 0x05, 0x4C, 0xF6,
4369 0x11, 0x10, 0x42, 0x42, 0xF1, 0x02, 0xFA, 0xFA, 0x4B, 0x04, 0x34,
4370 0xFD, 0x61, 0x01, 0x8C, 0xFF, 0x10, 0x00, 0x01, 0x00, 0xF8, 0xFF,
4371 0xD4, 0xFF, 0x0A, 0x01, 0x0A, 0xFD, 0x3C, 0x06, 0x9A, 0xF4, 0xED,
4372 0x16, 0x2A, 0x40, 0xF8, 0xFD, 0x4D, 0xFD, 0x3C, 0x03, 0x97, 0xFD,
4373 0x4C, 0x01, 0x8B, 0xFF, 0x11, 0x00, 0x02, 0x00, 0xEA, 0xFF, 0x00,
4374 0x00, 0xB8, 0x00, 0x67, 0xFD, 0x2C, 0x06, 0x6B, 0xF3, 0xFC, 0x1D,
4375 0xD3, 0x3C, 0xDF, 0xF9, 0x89, 0xFF, 0x18, 0x02, 0x13, 0xFE, 0x26,
4376 0x01, 0x92, 0xFF, 0x0F, 0x00, 0x04, 0x00, 0xD9, 0xFF, 0x36, 0x00,
4377 0x4E, 0x00, 0xFB, 0xFD, 0xB4, 0x05, 0xE4, 0xF2, 0x04, 0x25, 0x5F,
4378 0x38, 0xB6, 0xF6, 0x90, 0x01, 0xF3, 0x00, 0x9F, 0xFE, 0xF3, 0x00,
4379 0x9F, 0xFF, 0x0D, 0x00, 0x06, 0x00, 0xC6, 0xFF, 0x71, 0x00, 0xD1,
4380 0xFF, 0xC2, 0xFE, 0xD1, 0x04, 0x23, 0xF3, 0xC9, 0x2B, 0xF5, 0x32,
4381 0x83, 0xF4, 0x49, 0x03, 0xDC, 0xFF, 0x30, 0xFF, 0xB8, 0x00, 0xB0,
4382 0xFF, 0x0A, 0x00, 0x09, 0x00, 0xB3, 0xFF, 0xAE, 0x00, 0x46, 0xFF,
4383 0xB4, 0xFF, 0x85, 0x03, 0x42, 0xF4, 0x0E, 0x32, 0xCA, 0x2C, 0x41,
4384 0xF3, 0xA5, 0x04, 0xE4, 0xFE, 0xBC, 0xFF, 0x7A, 0x00, 0xC3, 0xFF,
4385 0x07, 0x00, 0x0D, 0x00, 0xA1, 0xFF, 0xEA, 0x00, 0xB5, 0xFE, 0xC6,
4386 0x00, 0xD9, 0x01, 0x4F, 0xF6, 0x99, 0x37, 0x16, 0x26, 0xE0, 0xF2,
4387 0x98, 0x05, 0x16, 0xFE, 0x3C, 0x00, 0x3F, 0x00, 0xD6, 0xFF, 0x04,
4388 0x00, 0x0F, 0x00, 0x93, 0xFF, 0x1F, 0x01, 0x28, 0xFE, 0xEB, 0x01,
4389 0xDD, 0xFF, 0x52, 0xF9, 0x36, 0x3C, 0x13, 0x1F, 0x4B, 0xF3, 0x20,
4390 0x06, 0x7B, 0xFD, 0xA9, 0x00, 0x08, 0x00, 0xE7, 0xFF, 0x02, 0x00,
4391 0x11, 0x00, 0x8C, 0xFF, 0x47, 0x01, 0xA9, 0xFD, 0x10, 0x03, 0xA8,
4392 0xFD, 0x47, 0xFD, 0xBB, 0x3F, 0x01, 0x18, 0x62, 0xF4, 0x40, 0x06,
4393 0x15, 0xFD, 0xFF, 0x00, 0xDA, 0xFF, 0xF6, 0xFF, 0x01, 0x00, 0x10,
4394 0x00, 0x8B, 0xFF, 0x5F, 0x01, 0x41, 0xFD, 0x23, 0x04, 0x56, 0xFB,
4395 0x1F, 0x02, 0x06, 0x42, 0x19, 0x11, 0x02, 0xF6, 0xFF, 0x05, 0xE5,
4396 0xFC, 0x3B, 0x01, 0xB6, 0xFF, 0x02, 0x00, 0x00, 0x00, 0x0D, 0x00,
4397 0x95, 0xFF, 0x62, 0x01, 0xFC, 0xFC, 0x10, 0x05, 0x09, 0xF9, 0xC1,
4398 0x07, 0x03, 0x43, 0x94, 0x0A, 0x05, 0xF8, 0x6C, 0x05, 0xEA, 0xFC,
4399 0x5C, 0x01, 0x9D, 0xFF, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
4400 0x00, 0xA9, 0xFF, 0x4D, 0x01, 0xE1, 0xFC, 0xC4, 0x05, 0xE6, 0xF6,
4401 0x08, 0x0E, 0xA5, 0x42, 0xA1, 0x04, 0x43, 0xFA, 0x97, 0x04, 0x1D,
4402 0xFD, 0x64, 0x01, 0x8F, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xFC, 0xFF,
4403 0xC8, 0xFF, 0x1E, 0x01, 0xF8, 0xFC, 0x2D, 0x06, 0x13, 0xF5, 0xC8,
4404 0x14, 0xF2, 0x40, 0x69, 0xFF, 0x97, 0xFC, 0x92, 0x03, 0x75, 0xFD,
4405 0x55, 0x01, 0x8A, 0xFF, 0x11, 0x00, 0x01, 0x00, 0xEF, 0xFF, 0xF2,
4406 0xFF, 0xD4, 0x00, 0x45, 0xFD, 0x3B, 0x06, 0xB8, 0xF3, 0xCE, 0x1B,
4407 0xFB, 0x3D, 0x08, 0xFB, 0xDE, 0xFE, 0x73, 0x02, 0xEB, 0xFD, 0x33,
4408 0x01, 0x8F, 0xFF, 0x10, 0x00, 0x03, 0x00, 0xDE, 0xFF, 0x25, 0x00,
4409 0x71, 0x00, 0xC8, 0xFD, 0xE5, 0x05, 0xFA, 0xF2, 0xDF, 0x22, 0xDB,
4410 0x39, 0x94, 0xF7, 0xF7, 0x00, 0x4C, 0x01, 0x73, 0xFE, 0x03, 0x01,
4411 0x9A, 0xFF, 0x0E, 0x00, 0x05, 0x00, 0xCC, 0xFF, 0x5E, 0x00, 0xF9,
4412 0xFF, 0x80, 0xFE, 0x23, 0x05, 0xF9, 0xF2, 0xC0, 0x29, 0xB8, 0x34,
4413 0x16, 0xF5, 0xCB, 0x02, 0x2F, 0x00, 0x03, 0xFF, 0xCA, 0x00, 0xAA,
4414 0xFF, 0x0B, 0x00, 0x08, 0x00, 0xB8, 0xFF, 0x9B, 0x00, 0x72, 0xFF,
4415 0x65, 0xFF, 0xF6, 0x03, 0xD1, 0xF3, 0x31, 0x30, 0xC1, 0x2E, 0x8B,
4416 0xF3, 0x45, 0x04, 0x2D, 0xFF, 0x92, 0xFF, 0x8D, 0x00, 0xBD, 0xFF,
4417 0x08, 0x00, 0x0C, 0x00, 0xA6, 0xFF, 0xD8, 0x00, 0xE2, 0xFE, 0x6F,
4418 0x00, 0x66, 0x02, 0x93, 0xF5, 0xFB, 0x35, 0x31, 0x28, 0xE7, 0xF2,
4419 0x59, 0x05, 0x51, 0xFE, 0x17, 0x00, 0x50, 0x00, 0xD0, 0xFF, 0x05,
4420 0x00, 0x0E, 0x00, 0x97, 0xFF, 0x0F, 0x01, 0x53, 0xFE, 0x90, 0x01,
4421 0x81, 0x00, 0x4B, 0xF8, 0xE6, 0x3A, 0x3F, 0x21, 0x16, 0xF3, 0x02,
4422 0x06, 0xA5, 0xFD, 0x8A, 0x00, 0x18, 0x00, 0xE2, 0xFF, 0x02, 0x00,
4423 0x10, 0x00, 0x8D, 0xFF, 0x3C, 0x01, 0xCE, 0xFD, 0xB7, 0x02, 0x5A,
4424 0xFE, 0xF7, 0xFB, 0xC6, 0x3E, 0x2C, 0x1A, 0xFC, 0xF3, 0x41, 0x06,
4425 0x2E, 0xFD, 0xE7, 0x00, 0xE7, 0xFF, 0xF2, 0xFF, 0x01, 0x00, 0x10,
4426 0x00, 0x8B, 0xFF, 0x5A, 0x01, 0x5E, 0xFD, 0xD2, 0x03, 0x0E, 0xFC,
4427 0x8B, 0x00, 0x75, 0x41, 0x32, 0x13, 0x75, 0xF5, 0x1C, 0x06, 0xEE,
4428 0xFC, 0x2B, 0x01, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0E, 0x00,
4429 0x91, 0xFF, 0x64, 0x01, 0x0D, 0xFD, 0xCD, 0x04, 0xBB, 0xF9, 0xF2,
4430 0x05, 0xD9, 0x42, 0x88, 0x0C, 0x5E, 0xF7, 0xA1, 0x05, 0xE3, 0xFC,
4431 0x54, 0x01, 0xA3, 0xFF, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
4432 0x00, 0xA2, 0xFF, 0x56, 0x01, 0xE5, 0xFC, 0x94, 0x05, 0x87, 0xF7,
4433 0x0A, 0x0C, 0xE6, 0x42, 0x64, 0x06, 0x8E, 0xF9, 0xDE, 0x04, 0x09,
4434 0xFD, 0x64, 0x01, 0x92, 0xFF, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00,
4435 0xBD, 0xFF, 0x2F, 0x01, 0xEC, 0xFC, 0x16, 0x06, 0x98, 0xF5, 0xAB,
4436 0x12, 0x9C, 0x41, 0xEE, 0x00, 0xE0, 0xFB, 0xE6, 0x03, 0x57, 0xFD,
4437 0x5B, 0x01, 0x8B, 0xFF, 0x10, 0x00, 0x01, 0x00, 0xF3, 0xFF, 0xE4,
4438 0xFF, 0xED, 0x00, 0x27, 0xFD, 0x41, 0x06, 0x14, 0xF4, 0xA1, 0x19,
4439 0x06, 0x3F, 0x49, 0xFC, 0x2E, 0xFE, 0xCD, 0x02, 0xC4, 0xFD, 0x3F,
4440 0x01, 0x8D, 0xFF, 0x10, 0x00, 0x02, 0x00, 0xE3, 0xFF, 0x14, 0x00,
4441 0x92, 0x00, 0x9A, 0xFD, 0x0A, 0x06, 0x22, 0xF3, 0xB4, 0x20, 0x3C,
4442 0x3B, 0x8B, 0xF8, 0x58, 0x00, 0xA7, 0x01, 0x48, 0xFE, 0x13, 0x01,
4443 0x96, 0xFF, 0x0F, 0x00, 0x04, 0x00, 0xD1, 0xFF, 0x4C, 0x00, 0x20,
4444 0x00, 0x42, 0xFE, 0x6A, 0x05, 0xE3, 0xF2, 0xAB, 0x27, 0x66, 0x36,
4445 0xC0, 0xF5, 0x44, 0x02, 0x85, 0x00, 0xD7, 0xFE, 0xDD, 0x00, 0xA5,
4446 0xFF, 0x0C, 0x00, 0x07, 0x00, 0xBE, 0xFF, 0x89, 0x00, 0x9D, 0xFF,
4447 0x1A, 0xFF, 0x5E, 0x04, 0x76, 0xF3, 0x45, 0x2E, 0xAA, 0x30, 0xEB,
4448 0xF3, 0xDB, 0x03, 0x79, 0xFF, 0x67, 0xFF, 0xA0, 0x00, 0xB7, 0xFF,
4449 0x09, 0x00, 0x0B, 0x00, 0xAC, 0xFF, 0xC6, 0x00, 0x0E, 0xFF, 0x1A,
4450 0x00, 0xEB, 0x02, 0xEF, 0xF4, 0x49, 0x34, 0x43, 0x2A, 0x02, 0xF3,
4451 0x0F, 0x05, 0x90, 0xFE, 0xEF, 0xFF, 0x63, 0x00, 0xCA, 0xFF, 0x06,
4452 0x00, 0x0E, 0x00, 0x9B, 0xFF, 0xFF, 0x00, 0x7E, 0xFE, 0x36, 0x01,
4453 0x1E, 0x01, 0x5B, 0xF7, 0x7E, 0x39, 0x69, 0x23, 0xF3, 0xF2, 0xD9,
4454 0x05, 0xD4, 0xFD, 0x69, 0x00, 0x29, 0x00, 0xDD, 0xFF, 0x03, 0x00,
4455 0x10, 0x00, 0x90, 0xFF, 0x30, 0x01, 0xF5, 0xFD, 0x5C, 0x02, 0x09,
4456 0xFF, 0xBC, 0xFA, 0xB5, 0x3D, 0x5A, 0x1C, 0xA3, 0xF3, 0x38, 0x06,
4457 0x4D, 0xFD, 0xCD, 0x00, 0xF5, 0xFF, 0xED, 0xFF, 0x01, 0x00, 0x11,
4458 0x00, 0x8B, 0xFF, 0x53, 0x01, 0x7E, 0xFD, 0x7D, 0x03, 0xC5, 0xFC,
4459 0x0B, 0xFF, 0xC3, 0x40, 0x51, 0x15, 0xF4, 0xF4, 0x31, 0x06, 0xFC,
4460 0xFC, 0x19, 0x01, 0xCB, 0xFF, 0xFB, 0xFF, 0x00, 0x00, 0x0F, 0x00,
4461 0x8E, 0xFF, 0x63, 0x01, 0x22, 0xFD, 0x84, 0x04, 0x71, 0xFA, 0x34,
4462 0x04, 0x90, 0x42, 0x89, 0x0E, 0xBE, 0xF6, 0xCF, 0x05, 0xE1, 0xFC,
4463 0x4A, 0x01, 0xAB, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B,
4464 0x00, 0x9B, 0xFF, 0x5D, 0x01, 0xEC, 0xFC, 0x5D, 0x05, 0x2F, 0xF8,
4465 0x19, 0x0A, 0x07, 0x43, 0x37, 0x08, 0xDD, 0xF8, 0x21, 0x05, 0xF8,
4466 0xFC, 0x62, 0x01, 0x96, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x00,
4467 0xB4, 0xFF, 0x3E, 0x01, 0xE4, 0xFC, 0xF6, 0x05, 0x26, 0xF6, 0x95,
4468 0x10, 0x26, 0x42, 0x87, 0x02, 0x28, 0xFB, 0x37, 0x04, 0x3B, 0xFD,
4469 0x60, 0x01, 0x8C, 0xFF, 0x10, 0x00, 0x01, 0x00, 0xF7, 0xFF, 0xD7,
4470 0xFF, 0x04, 0x01, 0x0F, 0xFD, 0x3E, 0x06, 0x7D, 0xF4, 0x76, 0x17,
4471 0xF4, 0x3F, 0x9F, 0xFD, 0x7B, 0xFD, 0x26, 0x03, 0xA0, 0xFD, 0x4A,
4472 0x01, 0x8B, 0xFF, 0x11, 0x00, 0x02, 0x00, 0xE9, 0xFF, 0x04, 0x00,
4473 0xB1, 0x00, 0x71, 0xFD, 0x26, 0x06, 0x5A, 0xF3, 0x88, 0x1E, 0x87,
4474 0x3C, 0x98, 0xF9, 0xB3, 0xFF, 0x02, 0x02, 0x1E, 0xFE, 0x22, 0x01,
4475 0x93, 0xFF, 0x0F, 0x00, 0x04, 0x00, 0xD7, 0xFF, 0x3A, 0x00, 0x45,
4476 0x00, 0x09, 0xFE, 0xA7, 0x05, 0xE1, 0xF2, 0x8D, 0x25, 0xFD, 0x37,
4477 0x82, 0xF6, 0xB5, 0x01, 0xDC, 0x00, 0xAA, 0xFE, 0xEE, 0x00, 0xA0,
4478 0xFF, 0x0D, 0x00, 0x06, 0x00, 0xC4, 0xFF, 0x76, 0x00, 0xC7, 0xFF,
4479 0xD3, 0xFE, 0xBC, 0x04, 0x31, 0xF3, 0x4A, 0x2C, 0x83, 0x32, 0x61,
4480 0xF4, 0x68, 0x03, 0xC8, 0xFF, 0x3B, 0xFF, 0xB3, 0x00, 0xB1, 0xFF,
4481 0x0A, 0x00, 0x0A, 0x00, 0xB1, 0xFF, 0xB3, 0x00, 0x3B, 0xFF, 0xC8,
4482 0xFF, 0x68, 0x03, 0x61, 0xF4, 0x83, 0x32, 0x4A, 0x2C, 0x31, 0xF3,
4483 0xBC, 0x04, 0xD3, 0xFE, 0xC7, 0xFF, 0x76, 0x00, 0xC4, 0xFF, 0x06,
4484 0x00, 0x0D, 0x00, 0xA0, 0xFF, 0xEE, 0x00, 0xAA, 0xFE, 0xDC, 0x00,
4485 0xB5, 0x01, 0x82, 0xF6, 0xFD, 0x37, 0x8D, 0x25, 0xE1, 0xF2, 0xA7,
4486 0x05, 0x09, 0xFE, 0x45, 0x00, 0x3A, 0x00, 0xD7, 0xFF, 0x04, 0x00,
4487 0x0F, 0x00, 0x93, 0xFF, 0x22, 0x01, 0x1E, 0xFE, 0x02, 0x02, 0xB3,
4488 0xFF, 0x98, 0xF9, 0x87, 0x3C, 0x88, 0x1E, 0x5A, 0xF3, 0x26, 0x06,
4489 0x71, 0xFD, 0xB1, 0x00, 0x04, 0x00, 0xE9, 0xFF, 0x02, 0x00, 0x11,
4490 0x00, 0x8B, 0xFF, 0x4A, 0x01, 0xA0, 0xFD, 0x26, 0x03, 0x7B, 0xFD,
4491 0x9F, 0xFD, 0xF4, 0x3F, 0x76, 0x17, 0x7D, 0xF4, 0x3E, 0x06, 0x0F,
4492 0xFD, 0x04, 0x01, 0xD7, 0xFF, 0xF7, 0xFF, 0x01, 0x00, 0x10, 0x00,
4493 0x8C, 0xFF, 0x60, 0x01, 0x3B, 0xFD, 0x37, 0x04, 0x28, 0xFB, 0x87,
4494 0x02, 0x26, 0x42, 0x95, 0x10, 0x26, 0xF6, 0xF6, 0x05, 0xE4, 0xFC,
4495 0x3E, 0x01, 0xB4, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x96,
4496 0xFF, 0x62, 0x01, 0xF8, 0xFC, 0x21, 0x05, 0xDD, 0xF8, 0x37, 0x08,
4497 0x07, 0x43, 0x19, 0x0A, 0x2F, 0xF8, 0x5D, 0x05, 0xEC, 0xFC, 0x5D,
4498 0x01, 0x9B, 0xFF, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
4499 0xAB, 0xFF, 0x4A, 0x01, 0xE1, 0xFC, 0xCF, 0x05, 0xBE, 0xF6, 0x89,
4500 0x0E, 0x90, 0x42, 0x34, 0x04, 0x71, 0xFA, 0x84, 0x04, 0x22, 0xFD,
4501 0x63, 0x01, 0x8E, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xFB, 0xFF, 0xCB,
4502 0xFF, 0x19, 0x01, 0xFC, 0xFC, 0x31, 0x06, 0xF4, 0xF4, 0x51, 0x15,
4503 0xC3, 0x40, 0x0B, 0xFF, 0xC5, 0xFC, 0x7D, 0x03, 0x7E, 0xFD, 0x53,
4504 0x01, 0x8B, 0xFF, 0x11, 0x00, 0x01, 0x00, 0xED, 0xFF, 0xF5, 0xFF,
4505 0xCD, 0x00, 0x4D, 0xFD, 0x38, 0x06, 0xA3, 0xF3, 0x5A, 0x1C, 0xB5,
4506 0x3D, 0xBC, 0xFA, 0x09, 0xFF, 0x5C, 0x02, 0xF5, 0xFD, 0x30, 0x01,
4507 0x90, 0xFF, 0x10, 0x00, 0x03, 0x00, 0xDD, 0xFF, 0x29, 0x00, 0x69,
4508 0x00, 0xD4, 0xFD, 0xD9, 0x05, 0xF3, 0xF2, 0x69, 0x23, 0x7E, 0x39,
4509 0x5B, 0xF7, 0x1E, 0x01, 0x36, 0x01, 0x7E, 0xFE, 0xFF, 0x00, 0x9B,
4510 0xFF, 0x0E, 0x00, 0x06, 0x00, 0xCA, 0xFF, 0x63, 0x00, 0xEF, 0xFF,
4511 0x90, 0xFE, 0x0F, 0x05, 0x02, 0xF3, 0x43, 0x2A, 0x49, 0x34, 0xEF,
4512 0xF4, 0xEB, 0x02, 0x1A, 0x00, 0x0E, 0xFF, 0xC6, 0x00, 0xAC, 0xFF,
4513 0x0B, 0x00, 0x09, 0x00, 0xB7, 0xFF, 0xA0, 0x00, 0x67, 0xFF, 0x79,
4514 0xFF, 0xDB, 0x03, 0xEB, 0xF3, 0xAA, 0x30, 0x45, 0x2E, 0x76, 0xF3,
4515 0x5E, 0x04, 0x1A, 0xFF, 0x9D, 0xFF, 0x89, 0x00, 0xBE, 0xFF, 0x07,
4516 0x00, 0x0C, 0x00, 0xA5, 0xFF, 0xDD, 0x00, 0xD7, 0xFE, 0x85, 0x00,
4517 0x44, 0x02, 0xC0, 0xF5, 0x66, 0x36, 0xAB, 0x27, 0xE3, 0xF2, 0x6A,
4518 0x05, 0x42, 0xFE, 0x20, 0x00, 0x4C, 0x00, 0xD1, 0xFF, 0x04, 0x00,
4519 0x0F, 0x00, 0x96, 0xFF, 0x13, 0x01, 0x48, 0xFE, 0xA7, 0x01, 0x58,
4520 0x00, 0x8B, 0xF8, 0x3C, 0x3B, 0xB4, 0x20, 0x22, 0xF3, 0x0A, 0x06,
4521 0x9A, 0xFD, 0x92, 0x00, 0x14, 0x00, 0xE3, 0xFF, 0x02, 0x00, 0x10,
4522 0x00, 0x8D, 0xFF, 0x3F, 0x01, 0xC4, 0xFD, 0xCD, 0x02, 0x2E, 0xFE,
4523 0x49, 0xFC, 0x06, 0x3F, 0xA1, 0x19, 0x14, 0xF4, 0x41, 0x06, 0x27,
4524 0xFD, 0xED, 0x00, 0xE4, 0xFF, 0xF3, 0xFF, 0x01, 0x00, 0x10, 0x00,
4525 0x8B, 0xFF, 0x5B, 0x01, 0x57, 0xFD, 0xE6, 0x03, 0xE0, 0xFB, 0xEE,
4526 0x00, 0x9C, 0x41, 0xAB, 0x12, 0x98, 0xF5, 0x16, 0x06, 0xEC, 0xFC,
4527 0x2F, 0x01, 0xBD, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x92,
4528 0xFF, 0x64, 0x01, 0x09, 0xFD, 0xDE, 0x04, 0x8E, 0xF9, 0x64, 0x06,
4529 0xE6, 0x42, 0x0A, 0x0C, 0x87, 0xF7, 0x94, 0x05, 0xE5, 0xFC, 0x56,
4530 0x01, 0xA2, 0xFF, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
4531 0xA3, 0xFF, 0x54, 0x01, 0xE3, 0xFC, 0xA1, 0x05, 0x5E, 0xF7, 0x88,
4532 0x0C, 0xD9, 0x42, 0xF2, 0x05, 0xBB, 0xF9, 0xCD, 0x04, 0x0D, 0xFD,
4533 0x64, 0x01, 0x91, 0xFF, 0x0E, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xC0,
4534 0xFF, 0x2B, 0x01, 0xEE, 0xFC, 0x1C, 0x06, 0x75, 0xF5, 0x32, 0x13,
4535 0x75, 0x41, 0x8B, 0x00, 0x0E, 0xFC, 0xD2, 0x03, 0x5E, 0xFD, 0x5A,
4536 0x01, 0x8B, 0xFF, 0x10, 0x00, 0x01, 0x00, 0xF2, 0xFF, 0xE7, 0xFF,
4537 0xE7, 0x00, 0x2E, 0xFD, 0x41, 0x06, 0xFC, 0xF3, 0x2C, 0x1A, 0xC6,
4538 0x3E, 0xF7, 0xFB, 0x5A, 0xFE, 0xB7, 0x02, 0xCE, 0xFD, 0x3C, 0x01,
4539 0x8D, 0xFF, 0x10, 0x00, 0x02, 0x00, 0xE2, 0xFF, 0x18, 0x00, 0x8A,
4540 0x00, 0xA5, 0xFD, 0x02, 0x06, 0x16, 0xF3, 0x3F, 0x21, 0xE6, 0x3A,
4541 0x4B, 0xF8, 0x81, 0x00, 0x90, 0x01, 0x53, 0xFE, 0x0F, 0x01, 0x97,
4542 0xFF, 0x0E, 0x00, 0x05, 0x00, 0xD0, 0xFF, 0x50, 0x00, 0x17, 0x00,
4543 0x51, 0xFE, 0x59, 0x05, 0xE7, 0xF2, 0x31, 0x28, 0xFB, 0x35, 0x93,
4544 0xF5, 0x66, 0x02, 0x6F, 0x00, 0xE2, 0xFE, 0xD8, 0x00, 0xA6, 0xFF,
4545 0x0C, 0x00, 0x08, 0x00, 0xBD, 0xFF, 0x8D, 0x00, 0x92, 0xFF, 0x2D,
4546 0xFF, 0x45, 0x04, 0x8B, 0xF3, 0xC1, 0x2E, 0x31, 0x30, 0xD1, 0xF3,
4547 0xF6, 0x03, 0x65, 0xFF, 0x72, 0xFF, 0x9B, 0x00, 0xB8, 0xFF, 0x08,
4548 0x00, 0x0B, 0x00, 0xAA, 0xFF, 0xCA, 0x00, 0x03, 0xFF, 0x2F, 0x00,
4549 0xCB, 0x02, 0x16, 0xF5, 0xB8, 0x34, 0xC0, 0x29, 0xF9, 0xF2, 0x23,
4550 0x05, 0x80, 0xFE, 0xF9, 0xFF, 0x5E, 0x00, 0xCC, 0xFF, 0x05, 0x00,
4551 0x0E, 0x00, 0x9A, 0xFF, 0x03, 0x01, 0x73, 0xFE, 0x4C, 0x01, 0xF7,
4552 0x00, 0x94, 0xF7, 0xDB, 0x39, 0xDF, 0x22, 0xFA, 0xF2, 0xE5, 0x05,
4553 0xC8, 0xFD, 0x71, 0x00, 0x25, 0x00, 0xDE, 0xFF, 0x03, 0x00, 0x10,
4554 0x00, 0x8F, 0xFF, 0x33, 0x01, 0xEB, 0xFD, 0x73, 0x02, 0xDE, 0xFE,
4555 0x08, 0xFB, 0xFB, 0x3D, 0xCE, 0x1B, 0xB8, 0xF3, 0x3B, 0x06, 0x45,
4556 0xFD, 0xD4, 0x00, 0xF2, 0xFF, 0xEF, 0xFF, 0x01, 0x00, 0x11, 0x00,
4557 0x8A, 0xFF, 0x55, 0x01, 0x75, 0xFD, 0x92, 0x03, 0x97, 0xFC, 0x69,
4558 0xFF, 0xF2, 0x40, 0xC8, 0x14, 0x13, 0xF5, 0x2D, 0x06, 0xF8, 0xFC,
4559 0x1E, 0x01, 0xC8, 0xFF, 0xFC, 0xFF, 0x00, 0x00, 0x0F, 0x00, 0x8F,
4560 0xFF, 0x64, 0x01, 0x1D, 0xFD, 0x97, 0x04, 0x43, 0xFA, 0xA1, 0x04,
4561 0xA5, 0x42, 0x08, 0x0E, 0xE6, 0xF6, 0xC4, 0x05, 0xE1, 0xFC, 0x4D,
4562 0x01, 0xA9, 0xFF, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00,
4563 0x9D, 0xFF, 0x5C, 0x01, 0xEA, 0xFC, 0x6C, 0x05, 0x05, 0xF8, 0x94,
4564 0x0A, 0x03, 0x43, 0xC1, 0x07, 0x09, 0xF9, 0x10, 0x05, 0xFC, 0xFC,
4565 0x62, 0x01, 0x95, 0xFF, 0x0D, 0x00, 0x00, 0x00, 0x02, 0x00, 0xB6,
4566 0xFF, 0x3B, 0x01, 0xE5, 0xFC, 0xFF, 0x05, 0x02, 0xF6, 0x19, 0x11,
4567 0x06, 0x42, 0x1F, 0x02, 0x56, 0xFB, 0x23, 0x04, 0x41, 0xFD, 0x5F,
4568 0x01, 0x8B, 0xFF, 0x10, 0x00, 0x01, 0x00, 0xF6, 0xFF, 0xDA, 0xFF,
4569 0xFF, 0x00, 0x15, 0xFD, 0x40, 0x06, 0x62, 0xF4, 0x01, 0x18, 0xBB,
4570 0x3F, 0x47, 0xFD, 0xA8, 0xFD, 0x10, 0x03, 0xA9, 0xFD, 0x47, 0x01,
4571 0x8C, 0xFF, 0x11, 0x00, 0x02, 0x00, 0xE7, 0xFF, 0x08, 0x00, 0xA9,
4572 0x00, 0x7B, 0xFD, 0x20, 0x06, 0x4B, 0xF3, 0x13, 0x1F, 0x36, 0x3C,
4573 0x52, 0xF9, 0xDD, 0xFF, 0xEB, 0x01, 0x28, 0xFE, 0x1F, 0x01, 0x93,
4574 0xFF, 0x0F, 0x00, 0x04, 0x00, 0xD6, 0xFF, 0x3F, 0x00, 0x3C, 0x00,
4575 0x16, 0xFE, 0x98, 0x05, 0xE0, 0xF2, 0x16, 0x26, 0x99, 0x37, 0x4F,
4576 0xF6, 0xD9, 0x01, 0xC6, 0x00, 0xB5, 0xFE, 0xEA, 0x00, 0xA1, 0xFF,
4577 0x0D, 0x00, 0x07, 0x00, 0xC3, 0xFF, 0x7A, 0x00, 0xBC, 0xFF, 0xE4,
4578 0xFE, 0xA5, 0x04, 0x41, 0xF3, 0xCA, 0x2C, 0x0E, 0x32, 0x42, 0xF4,
4579 0x85, 0x03, 0xB4, 0xFF, 0x46, 0xFF, 0xAE, 0x00, 0xB3, 0xFF, 0x09,
4580 0x00, 0x0A, 0x00, 0xB0, 0xFF, 0xB8, 0x00, 0x30, 0xFF, 0xDC, 0xFF,
4581 0x49, 0x03, 0x83, 0xF4, 0xF5, 0x32, 0xC9, 0x2B, 0x23, 0xF3, 0xD1,
4582 0x04, 0xC2, 0xFE, 0xD1, 0xFF, 0x71, 0x00, 0xC6, 0xFF, 0x06, 0x00,
4583 0x0D, 0x00, 0x9F, 0xFF, 0xF3, 0x00, 0x9F, 0xFE, 0xF3, 0x00, 0x90,
4584 0x01, 0xB6, 0xF6, 0x5F, 0x38, 0x04, 0x25, 0xE4, 0xF2, 0xB4, 0x05,
4585 0xFB, 0xFD, 0x4E, 0x00, 0x36, 0x00, 0xD9, 0xFF, 0x04, 0x00, 0x0F,
4586 0x00, 0x92, 0xFF, 0x26, 0x01, 0x13, 0xFE, 0x18, 0x02, 0x89, 0xFF,
4587 0xDF, 0xF9, 0xD3, 0x3C, 0xFC, 0x1D, 0x6B, 0xF3, 0x2C, 0x06, 0x67,
4588 0xFD, 0xB8, 0x00, 0x00, 0x00, 0xEA, 0xFF, 0x02, 0x00, 0x11, 0x00,
4589 0x8B, 0xFF, 0x4C, 0x01, 0x97, 0xFD, 0x3C, 0x03, 0x4D, 0xFD, 0xF8,
4590 0xFD, 0x2A, 0x40, 0xED, 0x16, 0x9A, 0xF4, 0x3C, 0x06, 0x0A, 0xFD,
4591 0x0A, 0x01, 0xD4, 0xFF, 0xF8, 0xFF, 0x01, 0x00, 0x10, 0x00, 0x8C,
4592 0xFF, 0x61, 0x01, 0x34, 0xFD, 0x4B, 0x04, 0xFA, 0xFA, 0xF1, 0x02,
4593 0x42, 0x42, 0x11, 0x10, 0x4C, 0xF6, 0xED, 0x05, 0xE3, 0xFC, 0x41,
4594 0x01, 0xB1, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x97, 0xFF,
4595 0x61, 0x01, 0xF5, 0xFC, 0x30, 0x05, 0xB1, 0xF8, 0xAE, 0x08, 0x0A,
4596 0x43, 0x9F, 0x09, 0x5A, 0xF8, 0x4F, 0x05, 0xEF, 0xFC, 0x5F, 0x01,
4597 0x9A, 0xFF, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0xAD,
4598 0xFF, 0x48, 0x01, 0xE2, 0xFC, 0xDA, 0x05, 0x97, 0xF6, 0x0B, 0x0F,
4599 0x79, 0x42, 0xC7, 0x03, 0x9E, 0xFA, 0x71, 0x04, 0x28, 0xFD, 0x63,
4600 0x01, 0x8D, 0xFF, 0x0F, 0x00
4601};
4602
4603static u16
4604CoefficientSizes[] = {
4605 /* Playback */
4606 0x00C0, 0x5000, 0x0060, 0x2800, 0x0040, 0x0060, 0x1400, 0x0000,
4607 /* Record */
4608 0x0020, 0x1260, 0x0020, 0x1260, 0x0000, 0x0040, 0x1260, 0x0000,
4609};
4610
4611#ifndef JUST_DATA
4612
4613static u16
4614nm256_getStartOffset (u8 which)
4615{
4616 u16 offset = 0;
4617
4618 while (which-- > 0)
4619 offset += CoefficientSizes[which];
4620
4621 return offset;
4622}
4623
4624static void
4625nm256_loadOneCoefficient (struct nm256_info *card, int devnum, u32 port,
4626 u16 which)
4627{
4628 u32 coeffBuf = (which < 8) ? card->coeffBuf : card->allCoeffBuf;
4629 u16 offset = nm256_getStartOffset (which);
4630 u16 size = CoefficientSizes[which];
4631
4632 card->coeffsCurrent = 0;
4633
4634 if (nm256_debug)
4635 printk (KERN_INFO "NM256: Loading coefficient buffer 0x%x-0x%x with coefficient %d, size %d, port 0x%x\n",
4636 coeffBuf, coeffBuf + size - 1, which, size, port);
4637 nm256_writeBuffer8 (card, coefficients + offset, 1, coeffBuf, size);
4638 nm256_writePort32 (card, 2, port + 0, coeffBuf);
4639 /* ??? Record seems to behave differently than playback. */
4640 if (devnum == 0)
4641 size--;
4642 nm256_writePort32 (card, 2, port + 4, coeffBuf + size);
4643}
4644
4645static void
4646nm256_loadAllCoefficients (struct nm256_info *card)
4647{
4648 nm256_writeBuffer8 (card, coefficients, 1, card->allCoeffBuf,
4649 NM_TOTAL_COEFF_COUNT * 4);
4650 card->coeffsCurrent = 1;
4651}
4652
4653void
4654nm256_loadCoefficient (struct nm256_info *card, int which, int number)
4655{
4656 static u16 addrs[3] = { 0x1c, 0x21c, 0x408 };
4657 /* The enable register for the specified engine. */
4658 u32 poffset = (which == 1 ? 0x200 : 1);
4659
4660 if (nm256_readPort8 (card, 2, poffset) & 1) {
4661 printk (KERN_ERR "NM256: Engine was enabled while loading coefficients!\n");
4662 return;
4663 }
4664
4665 /* The recording engine uses coefficient values 8-15. */
4666 if (which == 1)
4667 number += 8;
4668
4669 if (! nm256_cachedCoefficients (card))
4670 nm256_loadOneCoefficient (card, which, addrs[which], number);
4671 else {
4672 u32 base = card->allCoeffBuf;
4673 u32 offset = nm256_getStartOffset (number);
4674 u32 endOffset = offset + CoefficientSizes[number];
4675
4676 if (nm256_debug)
4677 printk (KERN_DEBUG "loading coefficient %d at port 0x%x, offset %d (0x%x-0x%x)\n",
4678 number, addrs[which], offset, base + offset,
4679 base + endOffset - 1);
4680
4681 if (! card->coeffsCurrent)
4682 nm256_loadAllCoefficients (card);
4683
4684 nm256_writePort32 (card, 2, addrs[which], base + offset);
4685 nm256_writePort32 (card, 2, addrs[which] + 4, base + endOffset - 1);
4686 }
4687}
4688
4689#endif /* JUST_DATA */
4690
4691#endif
4692
4693/*
4694 * Local variables:
4695 * c-basic-offset: 4
4696 * End:
4697 */
diff --git a/sound/oss/opl3.c b/sound/oss/opl3.c
new file mode 100644
index 000000000000..a31734b7842f
--- /dev/null
+++ b/sound/oss/opl3.c
@@ -0,0 +1,1257 @@
1/*
2 * sound/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/module.h>
28#include <linux/delay.h>
29
30/*
31 * Major improvements to the FM handling 30AUG92 by Rob Hooft,
32 * hooft@chem.ruu.nl
33 */
34
35#include "sound_config.h"
36
37#include "opl3.h"
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
55typedef struct 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 int *osp;
77} opl_devinfo;
78
79static struct opl_devinfo *devc = NULL;
80
81static int detected_model;
82
83static int store_instr(int instr_no, struct sbi_instrument *instr);
84static void freq_to_fnum(int freq, int *block, int *fnum);
85static void opl3_command(int io_addr, unsigned int addr, unsigned int val);
86static int opl3_kill_note(int dev, int voice, int note, int velocity);
87
88static void enter_4op_mode(void)
89{
90 int i;
91 static int v4op[MAX_VOICE] = {
92 0, 1, 2, 9, 10, 11, 6, 7, 8, 15, 16, 17
93 };
94
95 devc->cmask = 0x3f; /* Connect all possible 4 OP voice operators */
96 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, 0x3f);
97
98 for (i = 0; i < 3; i++)
99 pv_map[i].voice_mode = 4;
100 for (i = 3; i < 6; i++)
101 pv_map[i].voice_mode = 0;
102
103 for (i = 9; i < 12; i++)
104 pv_map[i].voice_mode = 4;
105 for (i = 12; i < 15; i++)
106 pv_map[i].voice_mode = 0;
107
108 for (i = 0; i < 12; i++)
109 devc->lv_map[i] = v4op[i];
110 devc->v_alloc->max_voice = devc->nr_voice = 12;
111}
112
113static int opl3_ioctl(int dev, unsigned int cmd, void __user * arg)
114{
115 struct sbi_instrument ins;
116
117 switch (cmd) {
118 case SNDCTL_FM_LOAD_INSTR:
119 printk(KERN_WARNING "Warning: Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. Fix the program.\n");
120 if (copy_from_user(&ins, arg, sizeof(ins)))
121 return -EFAULT;
122 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR) {
123 printk(KERN_WARNING "FM Error: Invalid instrument number %d\n", ins.channel);
124 return -EINVAL;
125 }
126 return store_instr(ins.channel, &ins);
127
128 case SNDCTL_SYNTH_INFO:
129 devc->fm_info.nr_voices = (devc->nr_voice == 12) ? 6 : devc->nr_voice;
130 if (copy_to_user(arg, &devc->fm_info, sizeof(devc->fm_info)))
131 return -EFAULT;
132 return 0;
133
134 case SNDCTL_SYNTH_MEMAVL:
135 return 0x7fffffff;
136
137 case SNDCTL_FM_4OP_ENABLE:
138 if (devc->model == 2)
139 enter_4op_mode();
140 return 0;
141
142 default:
143 return -EINVAL;
144 }
145}
146
147int opl3_detect(int ioaddr, int *osp)
148{
149 /*
150 * This function returns 1 if the FM chip is present at the given I/O port
151 * The detection algorithm plays with the timer built in the FM chip and
152 * looks for a change in the status register.
153 *
154 * Note! The timers of the FM chip are not connected to AdLib (and compatible)
155 * boards.
156 *
157 * Note2! The chip is initialized if detected.
158 */
159
160 unsigned char stat1, signature;
161 int i;
162
163 if (devc != NULL)
164 {
165 printk(KERN_ERR "opl3: Only one OPL3 supported.\n");
166 return 0;
167 }
168
169 devc = (struct opl_devinfo *)kmalloc(sizeof(*devc), GFP_KERNEL);
170
171 if (devc == NULL)
172 {
173 printk(KERN_ERR "opl3: Can't allocate memory for the device control "
174 "structure \n ");
175 return 0;
176 }
177
178 memset(devc, 0, sizeof(*devc));
179 strcpy(devc->fm_info.name, "OPL2");
180
181 if (!request_region(ioaddr, 4, devc->fm_info.name)) {
182 printk(KERN_WARNING "opl3: I/O port 0x%x already in use\n", ioaddr);
183 goto cleanup_devc;
184 }
185
186 devc->osp = osp;
187 devc->base = ioaddr;
188
189 /* Reset timers 1 and 2 */
190 opl3_command(ioaddr, TIMER_CONTROL_REGISTER, TIMER1_MASK | TIMER2_MASK);
191
192 /* Reset the IRQ of the FM chip */
193 opl3_command(ioaddr, TIMER_CONTROL_REGISTER, IRQ_RESET);
194
195 signature = stat1 = inb(ioaddr); /* Status register */
196
197 if (signature != 0x00 && signature != 0x06 && signature != 0x02 &&
198 signature != 0x0f)
199 {
200 MDB(printk(KERN_INFO "OPL3 not detected %x\n", signature));
201 goto cleanup_region;
202 }
203
204 if (signature == 0x06) /* OPL2 */
205 {
206 detected_model = 2;
207 }
208 else if (signature == 0x00 || signature == 0x0f) /* OPL3 or OPL4 */
209 {
210 unsigned char tmp;
211
212 detected_model = 3;
213
214 /*
215 * Detect availability of OPL4 (_experimental_). Works probably
216 * only after a cold boot. In addition the OPL4 port
217 * of the chip may not be connected to the PC bus at all.
218 */
219
220 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, 0x00);
221 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, OPL3_ENABLE | OPL4_ENABLE);
222
223 if ((tmp = inb(ioaddr)) == 0x02) /* Have a OPL4 */
224 {
225 detected_model = 4;
226 }
227
228 if (request_region(ioaddr - 8, 2, "OPL4")) /* OPL4 port was free */
229 {
230 int tmp;
231
232 outb((0x02), ioaddr - 8); /* Select OPL4 ID register */
233 udelay(10);
234 tmp = inb(ioaddr - 7); /* Read it */
235 udelay(10);
236
237 if (tmp == 0x20) /* OPL4 should return 0x20 here */
238 {
239 detected_model = 4;
240 outb((0xF8), ioaddr - 8); /* Select OPL4 FM mixer control */
241 udelay(10);
242 outb((0x1B), ioaddr - 7); /* Write value */
243 udelay(10);
244 }
245 else
246 { /* release OPL4 port */
247 release_region(ioaddr - 8, 2);
248 detected_model = 3;
249 }
250 }
251 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, 0);
252 }
253 for (i = 0; i < 9; i++)
254 opl3_command(ioaddr, KEYON_BLOCK + i, 0); /*
255 * Note off
256 */
257
258 opl3_command(ioaddr, TEST_REGISTER, ENABLE_WAVE_SELECT);
259 opl3_command(ioaddr, PERCOSSION_REGISTER, 0x00); /*
260 * Melodic mode.
261 */
262 return 1;
263cleanup_region:
264 release_region(ioaddr, 4);
265cleanup_devc:
266 kfree(devc);
267 devc = NULL;
268 return 0;
269}
270
271static int opl3_kill_note (int devno, int voice, int note, int velocity)
272{
273 struct physical_voice_info *map;
274
275 if (voice < 0 || voice >= devc->nr_voice)
276 return 0;
277
278 devc->v_alloc->map[voice] = 0;
279
280 map = &pv_map[devc->lv_map[voice]];
281 DEB(printk("Kill note %d\n", voice));
282
283 if (map->voice_mode == 0)
284 return 0;
285
286 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, devc->voc[voice].keyon_byte & ~0x20);
287 devc->voc[voice].keyon_byte = 0;
288 devc->voc[voice].bender = 0;
289 devc->voc[voice].volume = 64;
290 devc->voc[voice].panning = 0xffff; /* Not set */
291 devc->voc[voice].bender_range = 200;
292 devc->voc[voice].orig_freq = 0;
293 devc->voc[voice].current_freq = 0;
294 devc->voc[voice].mode = 0;
295 return 0;
296}
297
298#define HIHAT 0
299#define CYMBAL 1
300#define TOMTOM 2
301#define SNARE 3
302#define BDRUM 4
303#define UNDEFINED TOMTOM
304#define DEFAULT TOMTOM
305
306static int store_instr(int instr_no, struct sbi_instrument *instr)
307{
308 if (instr->key != FM_PATCH && (instr->key != OPL3_PATCH || devc->model != 2))
309 printk(KERN_WARNING "FM warning: Invalid patch format field (key) 0x%x\n", instr->key);
310 memcpy((char *) &(devc->i_map[instr_no]), (char *) instr, sizeof(*instr));
311 return 0;
312}
313
314static int opl3_set_instr (int dev, int voice, int instr_no)
315{
316 if (voice < 0 || voice >= devc->nr_voice)
317 return 0;
318 if (instr_no < 0 || instr_no >= SBFM_MAXINSTR)
319 instr_no = 0; /* Acoustic piano (usually) */
320
321 devc->act_i[voice] = &devc->i_map[instr_no];
322 return 0;
323}
324
325/*
326 * The next table looks magical, but it certainly is not. Its values have
327 * been calculated as table[i]=8*log(i/64)/log(2) with an obvious exception
328 * for i=0. This log-table converts a linear volume-scaling (0..127) to a
329 * logarithmic scaling as present in the FM-synthesizer chips. so : Volume
330 * 64 = 0 db = relative volume 0 and: Volume 32 = -6 db = relative
331 * volume -8 it was implemented as a table because it is only 128 bytes and
332 * it saves a lot of log() calculations. (RH)
333 */
334
335static char fm_volume_table[128] =
336{
337 -64, -48, -40, -35, -32, -29, -27, -26,
338 -24, -23, -21, -20, -19, -18, -18, -17,
339 -16, -15, -15, -14, -13, -13, -12, -12,
340 -11, -11, -10, -10, -10, -9, -9, -8,
341 -8, -8, -7, -7, -7, -6, -6, -6,
342 -5, -5, -5, -5, -4, -4, -4, -4,
343 -3, -3, -3, -3, -2, -2, -2, -2,
344 -2, -1, -1, -1, -1, 0, 0, 0,
345 0, 0, 0, 1, 1, 1, 1, 1,
346 1, 2, 2, 2, 2, 2, 2, 2,
347 3, 3, 3, 3, 3, 3, 3, 4,
348 4, 4, 4, 4, 4, 4, 4, 5,
349 5, 5, 5, 5, 5, 5, 5, 5,
350 6, 6, 6, 6, 6, 6, 6, 6,
351 6, 7, 7, 7, 7, 7, 7, 7,
352 7, 7, 7, 8, 8, 8, 8, 8
353};
354
355static void calc_vol(unsigned char *regbyte, int volume, int main_vol)
356{
357 int level = (~*regbyte & 0x3f);
358
359 if (main_vol > 127)
360 main_vol = 127;
361 volume = (volume * main_vol) / 127;
362
363 if (level)
364 level += fm_volume_table[volume];
365
366 if (level > 0x3f)
367 level = 0x3f;
368 if (level < 0)
369 level = 0;
370
371 *regbyte = (*regbyte & 0xc0) | (~level & 0x3f);
372}
373
374static void set_voice_volume(int voice, int volume, int main_vol)
375{
376 unsigned char vol1, vol2, vol3, vol4;
377 struct sbi_instrument *instr;
378 struct physical_voice_info *map;
379
380 if (voice < 0 || voice >= devc->nr_voice)
381 return;
382
383 map = &pv_map[devc->lv_map[voice]];
384 instr = devc->act_i[voice];
385
386 if (!instr)
387 instr = &devc->i_map[0];
388
389 if (instr->channel < 0)
390 return;
391
392 if (devc->voc[voice].mode == 0)
393 return;
394
395 if (devc->voc[voice].mode == 2)
396 {
397 vol1 = instr->operators[2];
398 vol2 = instr->operators[3];
399 if ((instr->operators[10] & 0x01))
400 {
401 calc_vol(&vol1, volume, main_vol);
402 calc_vol(&vol2, volume, main_vol);
403 }
404 else
405 {
406 calc_vol(&vol2, volume, main_vol);
407 }
408 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], vol1);
409 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], vol2);
410 }
411 else
412 { /*
413 * 4 OP voice
414 */
415 int connection;
416
417 vol1 = instr->operators[2];
418 vol2 = instr->operators[3];
419 vol3 = instr->operators[OFFS_4OP + 2];
420 vol4 = instr->operators[OFFS_4OP + 3];
421
422 /*
423 * The connection method for 4 OP devc->voc is defined by the rightmost
424 * bits at the offsets 10 and 10+OFFS_4OP
425 */
426
427 connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);
428
429 switch (connection)
430 {
431 case 0:
432 calc_vol(&vol4, volume, main_vol);
433 break;
434
435 case 1:
436 calc_vol(&vol2, volume, main_vol);
437 calc_vol(&vol4, volume, main_vol);
438 break;
439
440 case 2:
441 calc_vol(&vol1, volume, main_vol);
442 calc_vol(&vol4, volume, main_vol);
443 break;
444
445 case 3:
446 calc_vol(&vol1, volume, main_vol);
447 calc_vol(&vol3, volume, main_vol);
448 calc_vol(&vol4, volume, main_vol);
449 break;
450
451 default:
452 ;
453 }
454 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], vol1);
455 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], vol2);
456 opl3_command(map->ioaddr, KSL_LEVEL + map->op[2], vol3);
457 opl3_command(map->ioaddr, KSL_LEVEL + map->op[3], vol4);
458 }
459}
460
461static int opl3_start_note (int dev, int voice, int note, int volume)
462{
463 unsigned char data, fpc;
464 int block, fnum, freq, voice_mode, pan;
465 struct sbi_instrument *instr;
466 struct physical_voice_info *map;
467
468 if (voice < 0 || voice >= devc->nr_voice)
469 return 0;
470
471 map = &pv_map[devc->lv_map[voice]];
472 pan = devc->voc[voice].panning;
473
474 if (map->voice_mode == 0)
475 return 0;
476
477 if (note == 255) /*
478 * Just change the volume
479 */
480 {
481 set_voice_volume(voice, volume, devc->voc[voice].volume);
482 return 0;
483 }
484
485 /*
486 * Kill previous note before playing
487 */
488
489 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], 0xff); /*
490 * Carrier
491 * volume to
492 * min
493 */
494 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], 0xff); /*
495 * Modulator
496 * volume to
497 */
498
499 if (map->voice_mode == 4)
500 {
501 opl3_command(map->ioaddr, KSL_LEVEL + map->op[2], 0xff);
502 opl3_command(map->ioaddr, KSL_LEVEL + map->op[3], 0xff);
503 }
504
505 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, 0x00); /*
506 * Note
507 * off
508 */
509
510 instr = devc->act_i[voice];
511
512 if (!instr)
513 instr = &devc->i_map[0];
514
515 if (instr->channel < 0)
516 {
517 printk(KERN_WARNING "opl3: Initializing voice %d with undefined instrument\n", voice);
518 return 0;
519 }
520
521 if (map->voice_mode == 2 && instr->key == OPL3_PATCH)
522 return 0; /*
523 * Cannot play
524 */
525
526 voice_mode = map->voice_mode;
527
528 if (voice_mode == 4)
529 {
530 int voice_shift;
531
532 voice_shift = (map->ioaddr == devc->left_io) ? 0 : 3;
533 voice_shift += map->voice_num;
534
535 if (instr->key != OPL3_PATCH) /*
536 * Just 2 OP patch
537 */
538 {
539 voice_mode = 2;
540 devc->cmask &= ~(1 << voice_shift);
541 }
542 else
543 {
544 devc->cmask |= (1 << voice_shift);
545 }
546
547 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, devc->cmask);
548 }
549
550 /*
551 * Set Sound Characteristics
552 */
553
554 opl3_command(map->ioaddr, AM_VIB + map->op[0], instr->operators[0]);
555 opl3_command(map->ioaddr, AM_VIB + map->op[1], instr->operators[1]);
556
557 /*
558 * Set Attack/Decay
559 */
560
561 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[0], instr->operators[4]);
562 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[1], instr->operators[5]);
563
564 /*
565 * Set Sustain/Release
566 */
567
568 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[0], instr->operators[6]);
569 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[1], instr->operators[7]);
570
571 /*
572 * Set Wave Select
573 */
574
575 opl3_command(map->ioaddr, WAVE_SELECT + map->op[0], instr->operators[8]);
576 opl3_command(map->ioaddr, WAVE_SELECT + map->op[1], instr->operators[9]);
577
578 /*
579 * Set Feedback/Connection
580 */
581
582 fpc = instr->operators[10];
583
584 if (pan != 0xffff)
585 {
586 fpc &= ~STEREO_BITS;
587 if (pan < -64)
588 fpc |= VOICE_TO_LEFT;
589 else
590 if (pan > 64)
591 fpc |= VOICE_TO_RIGHT;
592 else
593 fpc |= (VOICE_TO_LEFT | VOICE_TO_RIGHT);
594 }
595
596 if (!(fpc & 0x30))
597 fpc |= 0x30; /*
598 * Ensure that at least one chn is enabled
599 */
600 opl3_command(map->ioaddr, FEEDBACK_CONNECTION + map->voice_num, fpc);
601
602 /*
603 * If the voice is a 4 OP one, initialize the operators 3 and 4 also
604 */
605
606 if (voice_mode == 4)
607 {
608 /*
609 * Set Sound Characteristics
610 */
611
612 opl3_command(map->ioaddr, AM_VIB + map->op[2], instr->operators[OFFS_4OP + 0]);
613 opl3_command(map->ioaddr, AM_VIB + map->op[3], instr->operators[OFFS_4OP + 1]);
614
615 /*
616 * Set Attack/Decay
617 */
618
619 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[2], instr->operators[OFFS_4OP + 4]);
620 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[3], instr->operators[OFFS_4OP + 5]);
621
622 /*
623 * Set Sustain/Release
624 */
625
626 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[2], instr->operators[OFFS_4OP + 6]);
627 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[3], instr->operators[OFFS_4OP + 7]);
628
629 /*
630 * Set Wave Select
631 */
632
633 opl3_command(map->ioaddr, WAVE_SELECT + map->op[2], instr->operators[OFFS_4OP + 8]);
634 opl3_command(map->ioaddr, WAVE_SELECT + map->op[3], instr->operators[OFFS_4OP + 9]);
635
636 /*
637 * Set Feedback/Connection
638 */
639
640 fpc = instr->operators[OFFS_4OP + 10];
641 if (!(fpc & 0x30))
642 fpc |= 0x30; /*
643 * Ensure that at least one chn is enabled
644 */
645 opl3_command(map->ioaddr, FEEDBACK_CONNECTION + map->voice_num + 3, fpc);
646 }
647
648 devc->voc[voice].mode = voice_mode;
649 set_voice_volume(voice, volume, devc->voc[voice].volume);
650
651 freq = devc->voc[voice].orig_freq = note_to_freq(note) / 1000;
652
653 /*
654 * Since the pitch bender may have been set before playing the note, we
655 * have to calculate the bending now.
656 */
657
658 freq = compute_finetune(devc->voc[voice].orig_freq, devc->voc[voice].bender, devc->voc[voice].bender_range, 0);
659 devc->voc[voice].current_freq = freq;
660
661 freq_to_fnum(freq, &block, &fnum);
662
663 /*
664 * Play note
665 */
666
667 data = fnum & 0xff; /*
668 * Least significant bits of fnumber
669 */
670 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data);
671
672 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
673 devc->voc[voice].keyon_byte = data;
674 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data);
675 if (voice_mode == 4)
676 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num + 3, data);
677
678 return 0;
679}
680
681static void freq_to_fnum (int freq, int *block, int *fnum)
682{
683 int f, octave;
684
685 /*
686 * Converts the note frequency to block and fnum values for the FM chip
687 */
688 /*
689 * First try to compute the block -value (octave) where the note belongs
690 */
691
692 f = freq;
693
694 octave = 5;
695
696 if (f == 0)
697 octave = 0;
698 else if (f < 261)
699 {
700 while (f < 261)
701 {
702 octave--;
703 f <<= 1;
704 }
705 }
706 else if (f > 493)
707 {
708 while (f > 493)
709 {
710 octave++;
711 f >>= 1;
712 }
713 }
714
715 if (octave > 7)
716 octave = 7;
717
718 *fnum = freq * (1 << (20 - octave)) / 49716;
719 *block = octave;
720}
721
722static void opl3_command (int io_addr, unsigned int addr, unsigned int val)
723{
724 int i;
725
726 /*
727 * The original 2-OP synth requires a quite long delay after writing to a
728 * register. The OPL-3 survives with just two INBs
729 */
730
731 outb(((unsigned char) (addr & 0xff)), io_addr);
732
733 if (devc->model != 2)
734 udelay(10);
735 else
736 for (i = 0; i < 2; i++)
737 inb(io_addr);
738
739 outb(((unsigned char) (val & 0xff)), io_addr + 1);
740
741 if (devc->model != 2)
742 udelay(30);
743 else
744 for (i = 0; i < 2; i++)
745 inb(io_addr);
746}
747
748static void opl3_reset(int devno)
749{
750 int i;
751
752 for (i = 0; i < 18; i++)
753 devc->lv_map[i] = i;
754
755 for (i = 0; i < devc->nr_voice; i++)
756 {
757 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
758 KSL_LEVEL + pv_map[devc->lv_map[i]].op[0], 0xff);
759
760 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
761 KSL_LEVEL + pv_map[devc->lv_map[i]].op[1], 0xff);
762
763 if (pv_map[devc->lv_map[i]].voice_mode == 4)
764 {
765 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
766 KSL_LEVEL + pv_map[devc->lv_map[i]].op[2], 0xff);
767
768 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
769 KSL_LEVEL + pv_map[devc->lv_map[i]].op[3], 0xff);
770 }
771
772 opl3_kill_note(devno, i, 0, 64);
773 }
774
775 if (devc->model == 2)
776 {
777 devc->v_alloc->max_voice = devc->nr_voice = 18;
778
779 for (i = 0; i < 18; i++)
780 pv_map[i].voice_mode = 2;
781
782 }
783}
784
785static int opl3_open(int dev, int mode)
786{
787 int i;
788
789 if (devc->busy)
790 return -EBUSY;
791 devc->busy = 1;
792
793 devc->v_alloc->max_voice = devc->nr_voice = (devc->model == 2) ? 18 : 9;
794 devc->v_alloc->timestamp = 0;
795
796 for (i = 0; i < 18; i++)
797 {
798 devc->v_alloc->map[i] = 0;
799 devc->v_alloc->alloc_times[i] = 0;
800 }
801
802 devc->cmask = 0x00; /*
803 * Just 2 OP mode
804 */
805 if (devc->model == 2)
806 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, devc->cmask);
807 return 0;
808}
809
810static void opl3_close(int dev)
811{
812 devc->busy = 0;
813 devc->v_alloc->max_voice = devc->nr_voice = (devc->model == 2) ? 18 : 9;
814
815 devc->fm_info.nr_drums = 0;
816 devc->fm_info.perc_mode = 0;
817
818 opl3_reset(dev);
819}
820
821static void opl3_hw_control(int dev, unsigned char *event)
822{
823}
824
825static int opl3_load_patch(int dev, int format, const char __user *addr,
826 int offs, int count, int pmgr_flag)
827{
828 struct sbi_instrument ins;
829
830 if (count <sizeof(ins))
831 {
832 printk(KERN_WARNING "FM Error: Patch record too short\n");
833 return -EINVAL;
834 }
835
836 /*
837 * What the fuck is going on here? We leave junk in the beginning
838 * of ins and then check the field pretty close to that beginning?
839 */
840 if(copy_from_user(&((char *) &ins)[offs], addr + offs, sizeof(ins) - offs))
841 return -EFAULT;
842
843 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR)
844 {
845 printk(KERN_WARNING "FM Error: Invalid instrument number %d\n", ins.channel);
846 return -EINVAL;
847 }
848 ins.key = format;
849
850 return store_instr(ins.channel, &ins);
851}
852
853static void opl3_panning(int dev, int voice, int value)
854{
855 devc->voc[voice].panning = value;
856}
857
858static void opl3_volume_method(int dev, int mode)
859{
860}
861
862#define SET_VIBRATO(cell) { \
863 tmp = instr->operators[(cell-1)+(((cell-1)/2)*OFFS_4OP)]; \
864 if (pressure > 110) \
865 tmp |= 0x40; /* Vibrato on */ \
866 opl3_command (map->ioaddr, AM_VIB + map->op[cell-1], tmp);}
867
868static void opl3_aftertouch(int dev, int voice, int pressure)
869{
870 int tmp;
871 struct sbi_instrument *instr;
872 struct physical_voice_info *map;
873
874 if (voice < 0 || voice >= devc->nr_voice)
875 return;
876
877 map = &pv_map[devc->lv_map[voice]];
878
879 DEB(printk("Aftertouch %d\n", voice));
880
881 if (map->voice_mode == 0)
882 return;
883
884 /*
885 * Adjust the amount of vibrato depending the pressure
886 */
887
888 instr = devc->act_i[voice];
889
890 if (!instr)
891 instr = &devc->i_map[0];
892
893 if (devc->voc[voice].mode == 4)
894 {
895 int connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);
896
897 switch (connection)
898 {
899 case 0:
900 SET_VIBRATO(4);
901 break;
902
903 case 1:
904 SET_VIBRATO(2);
905 SET_VIBRATO(4);
906 break;
907
908 case 2:
909 SET_VIBRATO(1);
910 SET_VIBRATO(4);
911 break;
912
913 case 3:
914 SET_VIBRATO(1);
915 SET_VIBRATO(3);
916 SET_VIBRATO(4);
917 break;
918
919 }
920 /*
921 * Not implemented yet
922 */
923 }
924 else
925 {
926 SET_VIBRATO(1);
927
928 if ((instr->operators[10] & 0x01)) /*
929 * Additive synthesis
930 */
931 SET_VIBRATO(2);
932 }
933}
934
935#undef SET_VIBRATO
936
937static void bend_pitch(int dev, int voice, int value)
938{
939 unsigned char data;
940 int block, fnum, freq;
941 struct physical_voice_info *map;
942
943 map = &pv_map[devc->lv_map[voice]];
944
945 if (map->voice_mode == 0)
946 return;
947
948 devc->voc[voice].bender = value;
949 if (!value)
950 return;
951 if (!(devc->voc[voice].keyon_byte & 0x20))
952 return; /*
953 * Not keyed on
954 */
955
956 freq = compute_finetune(devc->voc[voice].orig_freq, devc->voc[voice].bender, devc->voc[voice].bender_range, 0);
957 devc->voc[voice].current_freq = freq;
958
959 freq_to_fnum(freq, &block, &fnum);
960
961 data = fnum & 0xff; /*
962 * Least significant bits of fnumber
963 */
964 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data);
965
966 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
967 devc->voc[voice].keyon_byte = data;
968 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data);
969}
970
971static void opl3_controller (int dev, int voice, int ctrl_num, int value)
972{
973 if (voice < 0 || voice >= devc->nr_voice)
974 return;
975
976 switch (ctrl_num)
977 {
978 case CTRL_PITCH_BENDER:
979 bend_pitch(dev, voice, value);
980 break;
981
982 case CTRL_PITCH_BENDER_RANGE:
983 devc->voc[voice].bender_range = value;
984 break;
985
986 case CTL_MAIN_VOLUME:
987 devc->voc[voice].volume = value / 128;
988 break;
989
990 case CTL_PAN:
991 devc->voc[voice].panning = (value * 2) - 128;
992 break;
993 }
994}
995
996static void opl3_bender(int dev, int voice, int value)
997{
998 if (voice < 0 || voice >= devc->nr_voice)
999 return;
1000
1001 bend_pitch(dev, voice, value - 8192);
1002}
1003
1004static int opl3_alloc_voice(int dev, int chn, int note, struct voice_alloc_info *alloc)
1005{
1006 int i, p, best, first, avail, best_time = 0x7fffffff;
1007 struct sbi_instrument *instr;
1008 int is4op;
1009 int instr_no;
1010
1011 if (chn < 0 || chn > 15)
1012 instr_no = 0;
1013 else
1014 instr_no = devc->chn_info[chn].pgm_num;
1015
1016 instr = &devc->i_map[instr_no];
1017 if (instr->channel < 0 || /* Instrument not loaded */
1018 devc->nr_voice != 12) /* Not in 4 OP mode */
1019 is4op = 0;
1020 else if (devc->nr_voice == 12) /* 4 OP mode */
1021 is4op = (instr->key == OPL3_PATCH);
1022 else
1023 is4op = 0;
1024
1025 if (is4op)
1026 {
1027 first = p = 0;
1028 avail = 6;
1029 }
1030 else
1031 {
1032 if (devc->nr_voice == 12) /* 4 OP mode. Use the '2 OP only' operators first */
1033 first = p = 6;
1034 else
1035 first = p = 0;
1036 avail = devc->nr_voice;
1037 }
1038
1039 /*
1040 * Now try to find a free voice
1041 */
1042 best = first;
1043
1044 for (i = 0; i < avail; i++)
1045 {
1046 if (alloc->map[p] == 0)
1047 {
1048 return p;
1049 }
1050 if (alloc->alloc_times[p] < best_time) /* Find oldest playing note */
1051 {
1052 best_time = alloc->alloc_times[p];
1053 best = p;
1054 }
1055 p = (p + 1) % avail;
1056 }
1057
1058 /*
1059 * Insert some kind of priority mechanism here.
1060 */
1061
1062 if (best < 0)
1063 best = 0;
1064 if (best > devc->nr_voice)
1065 best -= devc->nr_voice;
1066
1067 return best; /* All devc->voc in use. Select the first one. */
1068}
1069
1070static void opl3_setup_voice(int dev, int voice, int chn)
1071{
1072 struct channel_info *info =
1073 &synth_devs[dev]->chn_info[chn];
1074
1075 opl3_set_instr(dev, voice, info->pgm_num);
1076
1077 devc->voc[voice].bender = 0;
1078 devc->voc[voice].bender_range = info->bender_range;
1079 devc->voc[voice].volume = info->controllers[CTL_MAIN_VOLUME];
1080 devc->voc[voice].panning = (info->controllers[CTL_PAN] * 2) - 128;
1081}
1082
1083static struct synth_operations opl3_operations =
1084{
1085 .owner = THIS_MODULE,
1086 .id = "OPL",
1087 .info = NULL,
1088 .midi_dev = 0,
1089 .synth_type = SYNTH_TYPE_FM,
1090 .synth_subtype = FM_TYPE_ADLIB,
1091 .open = opl3_open,
1092 .close = opl3_close,
1093 .ioctl = opl3_ioctl,
1094 .kill_note = opl3_kill_note,
1095 .start_note = opl3_start_note,
1096 .set_instr = opl3_set_instr,
1097 .reset = opl3_reset,
1098 .hw_control = opl3_hw_control,
1099 .load_patch = opl3_load_patch,
1100 .aftertouch = opl3_aftertouch,
1101 .controller = opl3_controller,
1102 .panning = opl3_panning,
1103 .volume_method = opl3_volume_method,
1104 .bender = opl3_bender,
1105 .alloc_voice = opl3_alloc_voice,
1106 .setup_voice = opl3_setup_voice
1107};
1108
1109int opl3_init(int ioaddr, int *osp, struct module *owner)
1110{
1111 int i;
1112 int me;
1113
1114 if (devc == NULL)
1115 {
1116 printk(KERN_ERR "opl3: Device control structure not initialized.\n");
1117 return -1;
1118 }
1119
1120 if ((me = sound_alloc_synthdev()) == -1)
1121 {
1122 printk(KERN_WARNING "opl3: Too many synthesizers\n");
1123 return -1;
1124 }
1125
1126 devc->nr_voice = 9;
1127
1128 devc->fm_info.device = 0;
1129 devc->fm_info.synth_type = SYNTH_TYPE_FM;
1130 devc->fm_info.synth_subtype = FM_TYPE_ADLIB;
1131 devc->fm_info.perc_mode = 0;
1132 devc->fm_info.nr_voices = 9;
1133 devc->fm_info.nr_drums = 0;
1134 devc->fm_info.instr_bank_size = SBFM_MAXINSTR;
1135 devc->fm_info.capabilities = 0;
1136 devc->left_io = ioaddr;
1137 devc->right_io = ioaddr + 2;
1138
1139 if (detected_model <= 2)
1140 devc->model = 1;
1141 else
1142 {
1143 devc->model = 2;
1144 if (detected_model == 4)
1145 devc->is_opl4 = 1;
1146 }
1147
1148 opl3_operations.info = &devc->fm_info;
1149
1150 synth_devs[me] = &opl3_operations;
1151
1152 if (owner)
1153 synth_devs[me]->owner = owner;
1154
1155 sequencer_init();
1156 devc->v_alloc = &opl3_operations.alloc;
1157 devc->chn_info = &opl3_operations.chn_info[0];
1158
1159 if (devc->model == 2)
1160 {
1161 if (devc->is_opl4)
1162 strcpy(devc->fm_info.name, "Yamaha OPL4/OPL3 FM");
1163 else
1164 strcpy(devc->fm_info.name, "Yamaha OPL3");
1165
1166 devc->v_alloc->max_voice = devc->nr_voice = 18;
1167 devc->fm_info.nr_drums = 0;
1168 devc->fm_info.synth_subtype = FM_TYPE_OPL3;
1169 devc->fm_info.capabilities |= SYNTH_CAP_OPL3;
1170
1171 for (i = 0; i < 18; i++)
1172 {
1173 if (pv_map[i].ioaddr == USE_LEFT)
1174 pv_map[i].ioaddr = devc->left_io;
1175 else
1176 pv_map[i].ioaddr = devc->right_io;
1177 }
1178 opl3_command(devc->right_io, OPL3_MODE_REGISTER, OPL3_ENABLE);
1179 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, 0x00);
1180 }
1181 else
1182 {
1183 strcpy(devc->fm_info.name, "Yamaha OPL2");
1184 devc->v_alloc->max_voice = devc->nr_voice = 9;
1185 devc->fm_info.nr_drums = 0;
1186
1187 for (i = 0; i < 18; i++)
1188 pv_map[i].ioaddr = devc->left_io;
1189 };
1190 conf_printf2(devc->fm_info.name, ioaddr, 0, -1, -1);
1191
1192 for (i = 0; i < SBFM_MAXINSTR; i++)
1193 devc->i_map[i].channel = -1;
1194
1195 return me;
1196}
1197
1198EXPORT_SYMBOL(opl3_init);
1199EXPORT_SYMBOL(opl3_detect);
1200
1201static int me;
1202
1203static int io = -1;
1204
1205module_param(io, int, 0);
1206
1207static int __init init_opl3 (void)
1208{
1209 printk(KERN_INFO "YM3812 and OPL-3 driver Copyright (C) by Hannu Savolainen, Rob Hooft 1993-1996\n");
1210
1211 if (io != -1) /* User loading pure OPL3 module */
1212 {
1213 if (!opl3_detect(io, NULL))
1214 {
1215 return -ENODEV;
1216 }
1217
1218 me = opl3_init(io, NULL, THIS_MODULE);
1219 }
1220
1221 return 0;
1222}
1223
1224static void __exit cleanup_opl3(void)
1225{
1226 if (devc && io != -1)
1227 {
1228 if (devc->base) {
1229 release_region(devc->base,4);
1230 if (devc->is_opl4)
1231 release_region(devc->base - 8, 2);
1232 }
1233 kfree(devc);
1234 devc = NULL;
1235 sound_unload_synthdev(me);
1236 }
1237}
1238
1239module_init(init_opl3);
1240module_exit(cleanup_opl3);
1241
1242#ifndef MODULE
1243static int __init setup_opl3(char *str)
1244{
1245 /* io */
1246 int ints[2];
1247
1248 str = get_options(str, ARRAY_SIZE(ints), ints);
1249
1250 io = ints[1];
1251
1252 return 1;
1253}
1254
1255__setup("opl3=", setup_opl3);
1256#endif
1257MODULE_LICENSE("GPL");
diff --git a/sound/oss/opl3.h b/sound/oss/opl3.h
new file mode 100644
index 000000000000..0bc9a4bcda13
--- /dev/null
+++ b/sound/oss/opl3.h
@@ -0,0 +1,5 @@
1
2int opl3_detect (int ioaddr, int *osp);
3int opl3_init(int ioaddr, int *osp, struct module *owner);
4
5void enable_opl3_mode(int left, int right, int both);
diff --git a/sound/oss/opl3_hw.h b/sound/oss/opl3_hw.h
new file mode 100644
index 000000000000..8b11c893e869
--- /dev/null
+++ b/sound/oss/opl3_hw.h
@@ -0,0 +1,246 @@
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/opl3sa.c b/sound/oss/opl3sa.c
new file mode 100644
index 000000000000..fe4907c6e8fc
--- /dev/null
+++ b/sound/oss/opl3sa.c
@@ -0,0 +1,329 @@
1/*
2 * sound/opl3sa.c
3 *
4 * Low level driver for Yamaha YMF701B aka OPL3-SA chip
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 * Changes:
15 * Alan Cox Modularisation
16 * Christoph Hellwig Adapted to module_init/module_exit
17 * Arnaldo C. de Melo got rid of attach_uart401
18 *
19 * FIXME:
20 * Check for install of mpu etc is wrong, should check result of the mss stuff
21 */
22
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/spinlock.h>
26
27#undef SB_OK
28
29#include "sound_config.h"
30
31#include "ad1848.h"
32#include "mpu401.h"
33
34#ifdef SB_OK
35#include "sb.h"
36static int sb_initialized;
37#endif
38
39static DEFINE_SPINLOCK(lock);
40
41static unsigned char opl3sa_read(int addr)
42{
43 unsigned long flags;
44 unsigned char tmp;
45
46 spin_lock_irqsave(&lock,flags);
47 outb((0x1d), 0xf86); /* password */
48 outb(((unsigned char) addr), 0xf86); /* address */
49 tmp = inb(0xf87); /* data */
50 spin_unlock_irqrestore(&lock,flags);
51
52 return tmp;
53}
54
55static void opl3sa_write(int addr, int data)
56{
57 unsigned long flags;
58
59 spin_lock_irqsave(&lock,flags);
60 outb((0x1d), 0xf86); /* password */
61 outb(((unsigned char) addr), 0xf86); /* address */
62 outb(((unsigned char) data), 0xf87); /* data */
63 spin_unlock_irqrestore(&lock,flags);
64}
65
66static int __init opl3sa_detect(void)
67{
68 int tmp;
69
70 if (((tmp = opl3sa_read(0x01)) & 0xc4) != 0x04)
71 {
72 DDB(printk("OPL3-SA detect error 1 (%x)\n", opl3sa_read(0x01)));
73 /* return 0; */
74 }
75
76 /*
77 * Check that the password feature has any effect
78 */
79
80 if (inb(0xf87) == tmp)
81 {
82 DDB(printk("OPL3-SA detect failed 2 (%x/%x)\n", tmp, inb(0xf87)));
83 return 0;
84 }
85 tmp = (opl3sa_read(0x04) & 0xe0) >> 5;
86
87 if (tmp != 0 && tmp != 1)
88 {
89 DDB(printk("OPL3-SA detect failed 3 (%d)\n", tmp));
90 return 0;
91 }
92 DDB(printk("OPL3-SA mode %x detected\n", tmp));
93
94 opl3sa_write(0x01, 0x00); /* Disable MSS */
95 opl3sa_write(0x02, 0x00); /* Disable SB */
96 opl3sa_write(0x03, 0x00); /* Disable MPU */
97
98 return 1;
99}
100
101/*
102 * Probe and attach routines for the Windows Sound System mode of
103 * OPL3-SA
104 */
105
106static int __init probe_opl3sa_wss(struct address_info *hw_config, struct resource *ports)
107{
108 unsigned char tmp = 0x24; /* WSS enable */
109
110 /*
111 * Check if the IO port returns valid signature. The original MS Sound
112 * system returns 0x04 while some cards (OPL3-SA for example)
113 * return 0x00.
114 */
115
116 if (!opl3sa_detect())
117 {
118 printk(KERN_ERR "OSS: OPL3-SA chip not found\n");
119 return 0;
120 }
121
122 switch (hw_config->io_base)
123 {
124 case 0x530:
125 tmp |= 0x00;
126 break;
127 case 0xe80:
128 tmp |= 0x08;
129 break;
130 case 0xf40:
131 tmp |= 0x10;
132 break;
133 case 0x604:
134 tmp |= 0x18;
135 break;
136 default:
137 printk(KERN_ERR "OSS: Unsupported OPL3-SA/WSS base %x\n", hw_config->io_base);
138 return 0;
139 }
140
141 opl3sa_write(0x01, tmp); /* WSS setup register */
142
143 return probe_ms_sound(hw_config, ports);
144}
145
146static void __init attach_opl3sa_wss(struct address_info *hw_config, struct resource *ports)
147{
148 int nm = num_mixers;
149
150 /* FIXME */
151 attach_ms_sound(hw_config, ports, THIS_MODULE);
152 if (num_mixers > nm) /* A mixer was installed */
153 {
154 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_CD);
155 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH);
156 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
157 }
158}
159
160
161static int __init probe_opl3sa_mpu(struct address_info *hw_config)
162{
163 unsigned char conf;
164 static signed char irq_bits[] = {
165 -1, -1, -1, -1, -1, 1, -1, 2, -1, 3, 4
166 };
167
168 if (hw_config->irq > 10)
169 {
170 printk(KERN_ERR "OPL3-SA: Bad MPU IRQ %d\n", hw_config->irq);
171 return 0;
172 }
173 if (irq_bits[hw_config->irq] == -1)
174 {
175 printk(KERN_ERR "OPL3-SA: Bad MPU IRQ %d\n", hw_config->irq);
176 return 0;
177 }
178 switch (hw_config->io_base)
179 {
180 case 0x330:
181 conf = 0x00;
182 break;
183 case 0x332:
184 conf = 0x20;
185 break;
186 case 0x334:
187 conf = 0x40;
188 break;
189 case 0x300:
190 conf = 0x60;
191 break;
192 default:
193 return 0; /* Invalid port */
194 }
195
196 conf |= 0x83; /* MPU & OPL3 (synth) & game port enable */
197 conf |= irq_bits[hw_config->irq] << 2;
198
199 opl3sa_write(0x03, conf);
200
201 hw_config->name = "OPL3-SA (MPU401)";
202
203 return probe_uart401(hw_config, THIS_MODULE);
204}
205
206static void __exit unload_opl3sa_wss(struct address_info *hw_config)
207{
208 int dma2 = hw_config->dma2;
209
210 if (dma2 == -1)
211 dma2 = hw_config->dma;
212
213 release_region(0xf86, 2);
214 release_region(hw_config->io_base, 4);
215
216 ad1848_unload(hw_config->io_base + 4,
217 hw_config->irq,
218 hw_config->dma,
219 dma2,
220 0);
221 sound_unload_audiodev(hw_config->slots[0]);
222}
223
224static inline void __exit unload_opl3sa_mpu(struct address_info *hw_config)
225{
226 unload_uart401(hw_config);
227}
228
229#ifdef SB_OK
230static inline void __exit unload_opl3sa_sb(struct address_info *hw_config)
231{
232 sb_dsp_unload(hw_config);
233}
234#endif
235
236static int found_mpu;
237
238static struct address_info cfg;
239static struct address_info cfg_mpu;
240
241static int __initdata io = -1;
242static int __initdata irq = -1;
243static int __initdata dma = -1;
244static int __initdata dma2 = -1;
245static int __initdata mpu_io = -1;
246static int __initdata mpu_irq = -1;
247
248module_param(io, int, 0);
249module_param(irq, int, 0);
250module_param(dma, int, 0);
251module_param(dma2, int, 0);
252module_param(mpu_io, int, 0);
253module_param(mpu_irq, int, 0);
254
255static int __init init_opl3sa(void)
256{
257 struct resource *ports;
258 if (io == -1 || irq == -1 || dma == -1) {
259 printk(KERN_ERR "opl3sa: dma, irq and io must be set.\n");
260 return -EINVAL;
261 }
262
263 cfg.io_base = io;
264 cfg.irq = irq;
265 cfg.dma = dma;
266 cfg.dma2 = dma2;
267
268 cfg_mpu.io_base = mpu_io;
269 cfg_mpu.irq = mpu_irq;
270
271 ports = request_region(io + 4, 4, "ad1848");
272 if (!ports)
273 return -EBUSY;
274
275 if (!request_region(0xf86, 2, "OPL3-SA"))/* Control port is busy */ {
276 release_region(io + 4, 4);
277 return 0;
278 }
279
280 if (!request_region(io, 4, "WSS config")) {
281 release_region(0x86, 2);
282 release_region(io + 4, 4);
283 return 0;
284 }
285
286 if (probe_opl3sa_wss(&cfg, ports) == 0) {
287 release_region(0xf86, 2);
288 release_region(io, 4);
289 release_region(io + 4, 4);
290 return -ENODEV;
291 }
292
293 found_mpu=probe_opl3sa_mpu(&cfg_mpu);
294
295 attach_opl3sa_wss(&cfg, ports);
296 return 0;
297}
298
299static void __exit cleanup_opl3sa(void)
300{
301 if(found_mpu)
302 unload_opl3sa_mpu(&cfg_mpu);
303 unload_opl3sa_wss(&cfg);
304}
305
306module_init(init_opl3sa);
307module_exit(cleanup_opl3sa);
308
309#ifndef MODULE
310static int __init setup_opl3sa(char *str)
311{
312 /* io, irq, dma, dma2, mpu_io, mpu_irq */
313 int ints[7];
314
315 str = get_options(str, ARRAY_SIZE(ints), ints);
316
317 io = ints[1];
318 irq = ints[2];
319 dma = ints[3];
320 dma2 = ints[4];
321 mpu_io = ints[5];
322 mpu_irq = ints[6];
323
324 return 1;
325}
326
327__setup("opl3sa=", setup_opl3sa);
328#endif
329MODULE_LICENSE("GPL");
diff --git a/sound/oss/opl3sa2.c b/sound/oss/opl3sa2.c
new file mode 100644
index 000000000000..7b4996e71576
--- /dev/null
+++ b/sound/oss/opl3sa2.c
@@ -0,0 +1,1129 @@
1/*
2 * sound/opl3sa2.c
3 *
4 * A low level driver for Yamaha OPL3-SA2 and SA3 cards.
5 * NOTE: All traces of the name OPL3-SAx have now (December 2000) been
6 * removed from the driver code, as an email exchange with Yamaha
7 * provided the information that the YMF-719 is indeed just a
8 * re-badged 715.
9 *
10 * Copyright 1998-2001 Scott Murray <scott@spiteful.org>
11 *
12 * Originally based on the CS4232 driver (in cs4232.c) by Hannu Savolainen
13 * and others. Now incorporates code/ideas from pss.c, also by Hannu
14 * Savolainen. Both of those files are distributed with the following
15 * license:
16 *
17 * "Copyright (C) by Hannu Savolainen 1993-1997
18 *
19 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
20 * Version 2 (June 1991). See the "COPYING" file distributed with this software
21 * for more info."
22 *
23 * As such, in accordance with the above license, this file, opl3sa2.c, is
24 * distributed under the GNU GENERAL PUBLIC LICENSE (GPL) Version 2 (June 1991).
25 * See the "COPYING" file distributed with this software for more information.
26 *
27 * Change History
28 * --------------
29 * Scott Murray Original driver (Jun 14, 1998)
30 * Paul J.Y. Lahaie Changed probing / attach code order
31 * Scott Murray Added mixer support (Dec 03, 1998)
32 * Scott Murray Changed detection code to be more forgiving,
33 * added force option as last resort,
34 * fixed ioctl return values. (Dec 30, 1998)
35 * Scott Murray Simpler detection code should work all the time now
36 * (with thanks to Ben Hutchings for the heuristic),
37 * removed now unnecessary force option. (Jan 5, 1999)
38 * Christoph Hellwig Adapted to module_init/module_exit (Mar 4, 2000)
39 * Scott Murray Reworked SA2 versus SA3 mixer code, updated chipset
40 * version detection code (again!). (Dec 5, 2000)
41 * Scott Murray Adjusted master volume mixer scaling. (Dec 6, 2000)
42 * Scott Murray Based on a patch by Joel Yliluoma (aka Bisqwit),
43 * integrated wide mixer and adjusted mic, bass, treble
44 * scaling. (Dec 6, 2000)
45 * Scott Murray Based on a patch by Peter Englmaier, integrated
46 * ymode and loopback options. (Dec 6, 2000)
47 * Scott Murray Inspired by a patch by Peter Englmaier, and based on
48 * what ALSA does, added initialization code for the
49 * default DMA and IRQ settings. (Dec 6, 2000)
50 * Scott Murray Added some more checks to the card detection code,
51 * based on what ALSA does. (Dec 12, 2000)
52 * Scott Murray Inspired by similar patches from John Fremlin,
53 * Jim Radford, Mike Rolig, and Ingmar Steen, added 2.4
54 * ISA PnP API support, mainly based on bits from
55 * sb_card.c and awe_wave.c. (Dec 12, 2000)
56 * Scott Murray Some small cleanups to the init code output.
57 * (Jan 7, 2001)
58 * Zwane Mwaikambo Added PM support. (Dec 4 2001)
59 *
60 * Adam Belay Converted driver to new PnP Layer (Oct 12, 2002)
61 * Zwane Mwaikambo Code, data structure cleanups. (Feb 15 2002)
62 * Zwane Mwaikambo Free resources during auxiliary device probe
63 * failures (Apr 29 2002)
64 *
65 */
66
67#include <linux/config.h>
68#include <linux/pnp.h>
69#include <linux/init.h>
70#include <linux/module.h>
71#include <linux/delay.h>
72#include <linux/pm.h>
73#include "sound_config.h"
74
75#include "ad1848.h"
76#include "mpu401.h"
77
78#define OPL3SA2_MODULE_NAME "opl3sa2"
79#define PFX OPL3SA2_MODULE_NAME ": "
80
81/* Useful control port indexes: */
82#define OPL3SA2_PM 0x01
83#define OPL3SA2_SYS_CTRL 0x02
84#define OPL3SA2_IRQ_CONFIG 0x03
85#define OPL3SA2_DMA_CONFIG 0x06
86#define OPL3SA2_MASTER_LEFT 0x07
87#define OPL3SA2_MASTER_RIGHT 0x08
88#define OPL3SA2_MIC 0x09
89#define OPL3SA2_MISC 0x0A
90
91#define OPL3SA3_WIDE 0x14
92#define OPL3SA3_BASS 0x15
93#define OPL3SA3_TREBLE 0x16
94
95/* Useful constants: */
96#define DEFAULT_VOLUME 50
97#define DEFAULT_MIC 50
98#define DEFAULT_TIMBRE 0
99
100/* Power saving modes */
101#define OPL3SA2_PM_MODE0 0x00
102#define OPL3SA2_PM_MODE1 0x04 /* PSV */
103#define OPL3SA2_PM_MODE2 0x05 /* PSV | PDX */
104#define OPL3SA2_PM_MODE3 0x27 /* ADOWN | PSV | PDN | PDX */
105
106
107/* For checking against what the card returns: */
108#define VERSION_UNKNOWN 0
109#define VERSION_YMF711 1
110#define VERSION_YMF715 2
111#define VERSION_YMF715B 3
112#define VERSION_YMF715E 4
113/* also assuming that anything > 4 but <= 7 is a 715E */
114
115/* Chipset type constants for use below */
116#define CHIPSET_UNKNOWN -1
117#define CHIPSET_OPL3SA2 0
118#define CHIPSET_OPL3SA3 1
119static const char *CHIPSET_TABLE[] = {"OPL3-SA2", "OPL3-SA3"};
120
121#ifdef CONFIG_PNP
122#define OPL3SA2_CARDS_MAX 4
123#else
124#define OPL3SA2_CARDS_MAX 1
125#endif
126
127/* This should be pretty obvious */
128static int opl3sa2_cards_num;
129
130typedef struct {
131 /* device resources */
132 unsigned short cfg_port;
133 struct address_info cfg;
134 struct address_info cfg_mss;
135 struct address_info cfg_mpu;
136#ifdef CONFIG_PNP
137 /* PnP Stuff */
138 struct pnp_dev* pdev;
139 int activated; /* Whether said devices have been activated */
140#endif
141#ifdef CONFIG_PM
142 unsigned int in_suspend;
143 struct pm_dev *pmdev;
144#endif
145 unsigned int card;
146 int chipset; /* What's my version(s)? */
147 char *chipset_name;
148
149 /* mixer data */
150 int mixer;
151 unsigned int volume_l;
152 unsigned int volume_r;
153 unsigned int mic;
154 unsigned int bass_l;
155 unsigned int bass_r;
156 unsigned int treble_l;
157 unsigned int treble_r;
158 unsigned int wide_l;
159 unsigned int wide_r;
160} opl3sa2_state_t;
161static opl3sa2_state_t opl3sa2_state[OPL3SA2_CARDS_MAX];
162
163
164
165/* Our parameters */
166static int __initdata io = -1;
167static int __initdata mss_io = -1;
168static int __initdata mpu_io = -1;
169static int __initdata irq = -1;
170static int __initdata dma = -1;
171static int __initdata dma2 = -1;
172static int __initdata ymode = -1;
173static int __initdata loopback = -1;
174
175#ifdef CONFIG_PNP
176/* PnP specific parameters */
177static int __initdata isapnp = 1;
178static int __initdata multiple = 1;
179
180/* Whether said devices have been activated */
181static int opl3sa2_activated[OPL3SA2_CARDS_MAX];
182#else
183static int __initdata isapnp; /* = 0 */
184static int __initdata multiple; /* = 0 */
185#endif
186
187MODULE_DESCRIPTION("Module for OPL3-SA2 and SA3 sound cards (uses AD1848 MSS driver).");
188MODULE_AUTHOR("Scott Murray <scott@spiteful.org>");
189MODULE_LICENSE("GPL");
190
191
192module_param(io, int, 0);
193MODULE_PARM_DESC(io, "Set I/O base of OPL3-SA2 or SA3 card (usually 0x370. Address must be even and must be from 0x100 to 0xFFE)");
194
195module_param(mss_io, int, 0);
196MODULE_PARM_DESC(mss_io, "Set MSS (audio) I/O base (0x530, 0xE80, or other. Address must end in 0 or 4 and must be from 0x530 to 0xF48)");
197
198module_param(mpu_io, int, 0);
199MODULE_PARM_DESC(mpu_io, "Set MIDI I/O base (0x330 or other. Address must be even and must be from 0x300 to 0x334)");
200
201module_param(irq, int, 0);
202MODULE_PARM_DESC(mss_irq, "Set MSS (audio) IRQ (5, 7, 9, 10, 11, 12)");
203
204module_param(dma, int, 0);
205MODULE_PARM_DESC(dma, "Set MSS (audio) first DMA channel (0, 1, 3)");
206
207module_param(dma2, int, 0);
208MODULE_PARM_DESC(dma2, "Set MSS (audio) second DMA channel (0, 1, 3)");
209
210module_param(ymode, int, 0);
211MODULE_PARM_DESC(ymode, "Set Yamaha 3D enhancement mode (0 = Desktop/Normal, 1 = Notebook PC (1), 2 = Notebook PC (2), 3 = Hi-Fi)");
212
213module_param(loopback, int, 0);
214MODULE_PARM_DESC(loopback, "Set A/D input source. Useful for echo cancellation (0 = Mic Rch (default), 1 = Mono output loopback)");
215
216#ifdef CONFIG_PNP
217module_param(isapnp, bool, 0);
218MODULE_PARM_DESC(isapnp, "When set to 0, ISA PnP support will be disabled");
219
220module_param(multiple, bool, 0);
221MODULE_PARM_DESC(multiple, "When set to 0, will not search for multiple cards");
222#endif
223
224
225/*
226 * Standard read and write functions
227*/
228
229static inline void opl3sa2_write(unsigned short port,
230 unsigned char index,
231 unsigned char data)
232{
233 outb_p(index, port);
234 outb(data, port + 1);
235}
236
237
238static inline void opl3sa2_read(unsigned short port,
239 unsigned char index,
240 unsigned char* data)
241{
242 outb_p(index, port);
243 *data = inb(port + 1);
244}
245
246
247/*
248 * All of the mixer functions...
249 */
250
251static void opl3sa2_set_volume(opl3sa2_state_t* devc, int left, int right)
252{
253 static unsigned char scale[101] = {
254 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
255 0x0e, 0x0e, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0c,
256 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b,
257 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x09, 0x09,
258 0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08,
259 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06,
260 0x06, 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
261 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03,
262 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01,
263 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00
265 };
266 unsigned char vol;
267
268 vol = scale[left];
269
270 /* If level is zero, turn on mute */
271 if(!left)
272 vol |= 0x80;
273
274 opl3sa2_write(devc->cfg_port, OPL3SA2_MASTER_LEFT, vol);
275
276 vol = scale[right];
277
278 /* If level is zero, turn on mute */
279 if(!right)
280 vol |= 0x80;
281
282 opl3sa2_write(devc->cfg_port, OPL3SA2_MASTER_RIGHT, vol);
283}
284
285
286static void opl3sa2_set_mic(opl3sa2_state_t* devc, int level)
287{
288 unsigned char vol = 0x1F;
289
290 if((level >= 0) && (level <= 100))
291 vol = 0x1F - (unsigned char) (32 * level / 101);
292
293 /* If level is zero, turn on mute */
294 if(!level)
295 vol |= 0x80;
296
297 opl3sa2_write(devc->cfg_port, OPL3SA2_MIC, vol);
298}
299
300
301static void opl3sa3_set_bass(opl3sa2_state_t* devc, int left, int right)
302{
303 unsigned char bass;
304
305 bass = left ? ((unsigned char) (8 * left / 101)) : 0;
306 bass |= (right ? ((unsigned char) (8 * right / 101)) : 0) << 4;
307
308 opl3sa2_write(devc->cfg_port, OPL3SA3_BASS, bass);
309}
310
311
312static void opl3sa3_set_treble(opl3sa2_state_t* devc, int left, int right)
313{
314 unsigned char treble;
315
316 treble = left ? ((unsigned char) (8 * left / 101)) : 0;
317 treble |= (right ? ((unsigned char) (8 * right / 101)) : 0) << 4;
318
319 opl3sa2_write(devc->cfg_port, OPL3SA3_TREBLE, treble);
320}
321
322
323
324
325static void opl3sa2_mixer_reset(opl3sa2_state_t* devc)
326{
327 if (devc) {
328 opl3sa2_set_volume(devc, DEFAULT_VOLUME, DEFAULT_VOLUME);
329 devc->volume_l = devc->volume_r = DEFAULT_VOLUME;
330
331 opl3sa2_set_mic(devc, DEFAULT_MIC);
332 devc->mic = DEFAULT_MIC;
333
334 if (devc->chipset == CHIPSET_OPL3SA3) {
335 opl3sa3_set_bass(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
336 devc->bass_l = devc->bass_r = DEFAULT_TIMBRE;
337 opl3sa3_set_treble(devc, DEFAULT_TIMBRE, DEFAULT_TIMBRE);
338 devc->treble_l = devc->treble_r = DEFAULT_TIMBRE;
339 }
340 }
341}
342
343/* Currently only used for power management */
344#ifdef CONFIG_PM
345static void opl3sa2_mixer_restore(opl3sa2_state_t* devc)
346{
347 if (devc) {
348 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
349 opl3sa2_set_mic(devc, devc->mic);
350
351 if (devc->chipset == CHIPSET_OPL3SA3) {
352 opl3sa3_set_bass(devc, devc->bass_l, devc->bass_r);
353 opl3sa3_set_treble(devc, devc->treble_l, devc->treble_r);
354 }
355 }
356}
357#endif
358
359static inline void arg_to_vol_mono(unsigned int vol, int* value)
360{
361 int left;
362
363 left = vol & 0x00ff;
364 if (left > 100)
365 left = 100;
366 *value = left;
367}
368
369
370static inline void arg_to_vol_stereo(unsigned int vol, int* aleft, int* aright)
371{
372 arg_to_vol_mono(vol, aleft);
373 arg_to_vol_mono(vol >> 8, aright);
374}
375
376
377static inline int ret_vol_mono(int vol)
378{
379 return ((vol << 8) | vol);
380}
381
382
383static inline int ret_vol_stereo(int left, int right)
384{
385 return ((right << 8) | left);
386}
387
388
389static int opl3sa2_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
390{
391 int retval, value, cmdf = cmd & 0xff;
392 int __user *p = (int __user *)arg;
393
394 opl3sa2_state_t* devc = &opl3sa2_state[dev];
395
396 switch (cmdf) {
397 case SOUND_MIXER_VOLUME:
398 case SOUND_MIXER_MIC:
399 case SOUND_MIXER_DEVMASK:
400 case SOUND_MIXER_STEREODEVS:
401 case SOUND_MIXER_RECMASK:
402 case SOUND_MIXER_RECSRC:
403 case SOUND_MIXER_CAPS:
404 break;
405
406 default:
407 return -EINVAL;
408 }
409
410 if (((cmd >> 8) & 0xff) != 'M')
411 return -EINVAL;
412
413 retval = 0;
414 if (_SIOC_DIR (cmd) & _SIOC_WRITE) {
415 switch (cmdf) {
416 case SOUND_MIXER_VOLUME:
417 retval = get_user(value, (unsigned __user *) arg);
418 if (retval)
419 break;
420 arg_to_vol_stereo(value, &devc->volume_l, &devc->volume_r);
421 opl3sa2_set_volume(devc, devc->volume_l, devc->volume_r);
422 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
423 retval = put_user(value, p);
424 break;
425
426 case SOUND_MIXER_MIC:
427 retval = get_user(value, (unsigned __user *) arg);
428 if (retval)
429 break;
430 arg_to_vol_mono(value, &devc->mic);
431 opl3sa2_set_mic(devc, devc->mic);
432 value = ret_vol_mono(devc->mic);
433 retval = put_user(value, p);
434 break;
435
436 default:
437 retval = -EINVAL;
438 }
439 }
440 else {
441 /*
442 * Return parameters
443 */
444 switch (cmdf) {
445 case SOUND_MIXER_DEVMASK:
446 retval = put_user(SOUND_MASK_VOLUME | SOUND_MASK_MIC, p);
447 break;
448
449 case SOUND_MIXER_STEREODEVS:
450 retval = put_user(SOUND_MASK_VOLUME, p);
451 break;
452
453 case SOUND_MIXER_RECMASK:
454 /* No recording devices */
455 retval = put_user(0, p);
456 break;
457
458 case SOUND_MIXER_CAPS:
459 retval = put_user(SOUND_CAP_EXCL_INPUT, p);
460 break;
461
462 case SOUND_MIXER_RECSRC:
463 /* No recording source */
464 retval = put_user(0, p);
465 break;
466
467 case SOUND_MIXER_VOLUME:
468 value = ret_vol_stereo(devc->volume_l, devc->volume_r);
469 retval = put_user(value, p);
470 break;
471
472 case SOUND_MIXER_MIC:
473 value = ret_vol_mono(devc->mic);
474 put_user(value, p);
475 break;
476
477 default:
478 retval = -EINVAL;
479 }
480 }
481 return retval;
482}
483/* opl3sa2_mixer_ioctl end */
484
485
486static int opl3sa3_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
487{
488 int value, retval, cmdf = cmd & 0xff;
489
490 opl3sa2_state_t* devc = &opl3sa2_state[dev];
491
492 switch (cmdf) {
493 case SOUND_MIXER_BASS:
494 value = ret_vol_stereo(devc->bass_l, devc->bass_r);
495 retval = put_user(value, (int __user *) arg);
496 break;
497
498 case SOUND_MIXER_TREBLE:
499 value = ret_vol_stereo(devc->treble_l, devc->treble_r);
500 retval = put_user(value, (int __user *) arg);
501 break;
502
503 case SOUND_MIXER_DIGITAL1:
504 value = ret_vol_stereo(devc->wide_l, devc->wide_r);
505 retval = put_user(value, (int __user *) arg);
506 break;
507
508 default:
509 retval = -EINVAL;
510 }
511 return retval;
512}
513/* opl3sa3_mixer_ioctl end */
514
515
516static struct mixer_operations opl3sa2_mixer_operations =
517{
518 .owner = THIS_MODULE,
519 .id = "OPL3-SA2",
520 .name = "Yamaha OPL3-SA2",
521 .ioctl = opl3sa2_mixer_ioctl
522};
523
524static struct mixer_operations opl3sa3_mixer_operations =
525{
526 .owner = THIS_MODULE,
527 .id = "OPL3-SA3",
528 .name = "Yamaha OPL3-SA3",
529 .ioctl = opl3sa3_mixer_ioctl
530};
531
532/* End of mixer-related stuff */
533
534
535/*
536 * Component probe, attach, unload functions
537 */
538
539static inline void __exit unload_opl3sa2_mpu(struct address_info *hw_config)
540{
541 unload_mpu401(hw_config);
542}
543
544
545static void __init attach_opl3sa2_mss(struct address_info* hw_config, struct resource *ports)
546{
547 int initial_mixers;
548
549 initial_mixers = num_mixers;
550 attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
551 if (hw_config->slots[0] != -1) {
552 /* Did the MSS driver install? */
553 if(num_mixers == (initial_mixers + 1)) {
554 /* The MSS mixer is installed, reroute mixers appropiately */
555 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_CD);
556 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH);
557 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_LINE);
558 }
559 else {
560 printk(KERN_ERR PFX "MSS mixer not installed?\n");
561 }
562 }
563}
564
565
566static inline void __exit unload_opl3sa2_mss(struct address_info* hw_config)
567{
568 unload_ms_sound(hw_config);
569}
570
571
572static int __init probe_opl3sa2(struct address_info* hw_config, int card)
573{
574 unsigned char misc;
575 unsigned char tmp;
576 unsigned char version;
577
578 /*
579 * Try and allocate our I/O port range.
580 */
581 if (!request_region(hw_config->io_base, 2, OPL3SA2_MODULE_NAME)) {
582 printk(KERN_ERR PFX "Control I/O port %#x not free\n",
583 hw_config->io_base);
584 goto out_nodev;
585 }
586
587 /*
588 * Check if writing to the read-only version bits of the miscellaneous
589 * register succeeds or not (it should not).
590 */
591 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
592 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc ^ 0x07);
593 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &tmp);
594 if(tmp != misc) {
595 printk(KERN_ERR PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
596 hw_config->io_base);
597 goto out_region;
598 }
599
600 /*
601 * Check if the MIC register is accessible.
602 */
603 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
604 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, 0x8a);
605 opl3sa2_read(hw_config->io_base, OPL3SA2_MIC, &tmp);
606 if((tmp & 0x9f) != 0x8a) {
607 printk(KERN_ERR
608 PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
609 hw_config->io_base);
610 goto out_region;
611 }
612 opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, tmp);
613
614 /*
615 * Determine chipset type (SA2 or SA3)
616 *
617 * This is done by looking at the chipset version in the lower 3 bits
618 * of the miscellaneous register.
619 */
620 version = misc & 0x07;
621 printk(KERN_DEBUG PFX "Chipset version = %#x\n", version);
622 switch (version) {
623 case 0:
624 opl3sa2_state[card].chipset = CHIPSET_UNKNOWN;
625 printk(KERN_ERR
626 PFX "Unknown Yamaha audio controller version\n");
627 break;
628
629 case VERSION_YMF711:
630 opl3sa2_state[card].chipset = CHIPSET_OPL3SA2;
631 printk(KERN_INFO PFX "Found OPL3-SA2 (YMF711)\n");
632 break;
633
634 case VERSION_YMF715:
635 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
636 printk(KERN_INFO
637 PFX "Found OPL3-SA3 (YMF715 or YMF719)\n");
638 break;
639
640 case VERSION_YMF715B:
641 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
642 printk(KERN_INFO
643 PFX "Found OPL3-SA3 (YMF715B or YMF719B)\n");
644 break;
645
646 case VERSION_YMF715E:
647 default:
648 opl3sa2_state[card].chipset = CHIPSET_OPL3SA3;
649 printk(KERN_INFO
650 PFX "Found OPL3-SA3 (YMF715E or YMF719E)\n");
651 break;
652 }
653
654 if (opl3sa2_state[card].chipset != CHIPSET_UNKNOWN) {
655 /* Generate a pretty name */
656 opl3sa2_state[card].chipset_name = (char *)CHIPSET_TABLE[opl3sa2_state[card].chipset];
657 return 0;
658 }
659
660out_region:
661 release_region(hw_config->io_base, 2);
662out_nodev:
663 return -ENODEV;
664}
665
666
667static void __init attach_opl3sa2(struct address_info* hw_config, int card)
668{
669 /* Initialize IRQ configuration to IRQ-B: -, IRQ-A: WSS+MPU+OPL3 */
670 opl3sa2_write(hw_config->io_base, OPL3SA2_IRQ_CONFIG, 0x0d);
671
672 /* Initialize DMA configuration */
673 if(hw_config->dma2 == hw_config->dma) {
674 /* Want DMA configuration DMA-B: -, DMA-A: WSS-P+WSS-R */
675 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x03);
676 }
677 else {
678 /* Want DMA configuration DMA-B: WSS-R, DMA-A: WSS-P */
679 opl3sa2_write(hw_config->io_base, OPL3SA2_DMA_CONFIG, 0x21);
680 }
681}
682
683
684static void __init attach_opl3sa2_mixer(struct address_info *hw_config, int card)
685{
686 struct mixer_operations* mixer_operations;
687 opl3sa2_state_t* devc = &opl3sa2_state[card];
688
689 /* Install master mixer */
690 if (devc->chipset == CHIPSET_OPL3SA3) {
691 mixer_operations = &opl3sa3_mixer_operations;
692 }
693 else {
694 mixer_operations = &opl3sa2_mixer_operations;
695 }
696
697 devc->cfg_port = hw_config->io_base;
698 devc->mixer = sound_install_mixer(MIXER_DRIVER_VERSION,
699 mixer_operations->name,
700 mixer_operations,
701 sizeof(struct mixer_operations),
702 devc);
703 if(devc->mixer < 0) {
704 printk(KERN_ERR PFX "Could not install %s master mixer\n",
705 mixer_operations->name);
706 }
707 else {
708 opl3sa2_mixer_reset(devc);
709
710 }
711}
712
713
714static void opl3sa2_clear_slots(struct address_info* hw_config)
715{
716 int i;
717
718 for(i = 0; i < 6; i++) {
719 hw_config->slots[i] = -1;
720 }
721}
722
723
724static void __init opl3sa2_set_ymode(struct address_info* hw_config, int ymode)
725{
726 /*
727 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
728 * it's supported.
729 *
730 * 0: Desktop (aka normal) 5-12 cm speakers
731 * 1: Notebook PC mode 1 3 cm speakers
732 * 2: Notebook PC mode 2 1.5 cm speakers
733 * 3: Hi-fi 16-38 cm speakers
734 */
735 if(ymode >= 0 && ymode <= 3) {
736 unsigned char sys_ctrl;
737
738 opl3sa2_read(hw_config->io_base, OPL3SA2_SYS_CTRL, &sys_ctrl);
739 sys_ctrl = (sys_ctrl & 0xcf) | ((ymode & 3) << 4);
740 opl3sa2_write(hw_config->io_base, OPL3SA2_SYS_CTRL, sys_ctrl);
741 }
742 else {
743 printk(KERN_ERR PFX "not setting ymode, it must be one of 0,1,2,3\n");
744 }
745}
746
747
748static void __init opl3sa2_set_loopback(struct address_info* hw_config, int loopback)
749{
750 if(loopback >= 0 && loopback <= 1) {
751 unsigned char misc;
752
753 opl3sa2_read(hw_config->io_base, OPL3SA2_MISC, &misc);
754 misc = (misc & 0xef) | ((loopback & 1) << 4);
755 opl3sa2_write(hw_config->io_base, OPL3SA2_MISC, misc);
756 }
757 else {
758 printk(KERN_ERR PFX "not setting loopback, it must be either 0 or 1\n");
759 }
760}
761
762
763static void __exit unload_opl3sa2(struct address_info* hw_config, int card)
764{
765 /* Release control ports */
766 release_region(hw_config->io_base, 2);
767
768 /* Unload mixer */
769 if(opl3sa2_state[card].mixer >= 0)
770 sound_unload_mixerdev(opl3sa2_state[card].mixer);
771
772}
773
774#ifdef CONFIG_PNP
775static struct pnp_device_id pnp_opl3sa2_list[] = {
776 {.id = "YMH0021", .driver_data = 0},
777 {.id = ""}
778};
779
780MODULE_DEVICE_TABLE(pnp, pnp_opl3sa2_list);
781
782static int opl3sa2_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
783{
784 int card = opl3sa2_cards_num;
785
786 /* we don't actually want to return an error as the user may have specified
787 * no multiple card search
788 */
789
790 if (opl3sa2_cards_num == OPL3SA2_CARDS_MAX)
791 return 0;
792 opl3sa2_activated[card] = 1;
793
794 /* Our own config: */
795 opl3sa2_state[card].cfg.io_base = pnp_port_start(dev, 4);
796 opl3sa2_state[card].cfg.irq = pnp_irq(dev, 0);
797 opl3sa2_state[card].cfg.dma = pnp_dma(dev, 0);
798 opl3sa2_state[card].cfg.dma2 = pnp_dma(dev, 1);
799
800 /* The MSS config: */
801 opl3sa2_state[card].cfg_mss.io_base = pnp_port_start(dev, 1);
802 opl3sa2_state[card].cfg_mss.irq = pnp_irq(dev, 0);
803 opl3sa2_state[card].cfg_mss.dma = pnp_dma(dev, 0);
804 opl3sa2_state[card].cfg_mss.dma2 = pnp_dma(dev, 1);
805 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
806
807 opl3sa2_state[card].cfg_mpu.io_base = pnp_port_start(dev, 3);
808 opl3sa2_state[card].cfg_mpu.irq = pnp_irq(dev, 0);
809 opl3sa2_state[card].cfg_mpu.dma = -1;
810 opl3sa2_state[card].cfg_mpu.dma2 = -1;
811 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* It's there, so use shared IRQs */
812
813 /* Call me paranoid: */
814 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
815 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
816 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
817
818 opl3sa2_state[card].pdev = dev;
819 opl3sa2_cards_num++;
820
821 return 0;
822}
823
824static struct pnp_driver opl3sa2_driver = {
825 .name = "opl3sa2",
826 .id_table = pnp_opl3sa2_list,
827 .probe = opl3sa2_pnp_probe,
828};
829
830#endif /* CONFIG_PNP */
831
832/* End of component functions */
833
834#ifdef CONFIG_PM
835static DEFINE_SPINLOCK(opl3sa2_lock);
836
837/* Power Management support functions */
838static int opl3sa2_suspend(struct pm_dev *pdev, unsigned int pm_mode)
839{
840 unsigned long flags;
841 opl3sa2_state_t *p;
842
843 if (!pdev)
844 return -EINVAL;
845
846 spin_lock_irqsave(&opl3sa2_lock,flags);
847
848 p = (opl3sa2_state_t *) pdev->data;
849 switch (pm_mode) {
850 case 1:
851 pm_mode = OPL3SA2_PM_MODE1;
852 break;
853 case 2:
854 pm_mode = OPL3SA2_PM_MODE2;
855 break;
856 case 3:
857 pm_mode = OPL3SA2_PM_MODE3;
858 break;
859 default:
860 /* we don't know howto handle this... */
861 spin_unlock_irqrestore(&opl3sa2_lock, flags);
862 return -EBUSY;
863 }
864
865 p->in_suspend = 1;
866
867 /* its supposed to automute before suspending, so we won't bother */
868 opl3sa2_write(p->cfg_port, OPL3SA2_PM, pm_mode);
869 /* wait a while for the clock oscillator to stabilise */
870 mdelay(10);
871
872 spin_unlock_irqrestore(&opl3sa2_lock,flags);
873 return 0;
874}
875
876static int opl3sa2_resume(struct pm_dev *pdev)
877{
878 unsigned long flags;
879 opl3sa2_state_t *p;
880
881 if (!pdev)
882 return -EINVAL;
883
884 p = (opl3sa2_state_t *) pdev->data;
885 spin_lock_irqsave(&opl3sa2_lock,flags);
886
887 /* I don't think this is necessary */
888 opl3sa2_write(p->cfg_port, OPL3SA2_PM, OPL3SA2_PM_MODE0);
889 opl3sa2_mixer_restore(p);
890 p->in_suspend = 0;
891
892 spin_unlock_irqrestore(&opl3sa2_lock,flags);
893 return 0;
894}
895
896static int opl3sa2_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)
897{
898 unsigned long mode = (unsigned long)data;
899
900 switch (rqst) {
901 case PM_SUSPEND:
902 return opl3sa2_suspend(pdev, mode);
903
904 case PM_RESUME:
905 return opl3sa2_resume(pdev);
906 }
907 return 0;
908}
909#endif /* CONFIG_PM */
910
911/*
912 * Install OPL3-SA2 based card(s).
913 *
914 * Need to have ad1848 and mpu401 loaded ready.
915 */
916static int __init init_opl3sa2(void)
917{
918 int card, max;
919
920 /* Sanitize isapnp and multiple settings */
921 isapnp = isapnp != 0 ? 1 : 0;
922 multiple = multiple != 0 ? 1 : 0;
923
924 max = (multiple && isapnp) ? OPL3SA2_CARDS_MAX : 1;
925
926#ifdef CONFIG_PNP
927 if (isapnp){
928 pnp_register_driver(&opl3sa2_driver);
929 if(!opl3sa2_cards_num){
930 printk(KERN_INFO PFX "No PnP cards found\n");
931 isapnp = 0;
932 }
933 max = opl3sa2_cards_num;
934 }
935#endif
936
937 for (card = 0; card < max; card++) {
938 /* If a user wants an I/O then assume they meant it */
939 struct resource *ports;
940 int base;
941
942 if (!isapnp) {
943 if (io == -1 || irq == -1 || dma == -1 ||
944 dma2 == -1 || mss_io == -1) {
945 printk(KERN_ERR
946 PFX "io, mss_io, irq, dma, and dma2 must be set\n");
947 return -EINVAL;
948 }
949 opl3sa2_cards_num++;
950
951 /*
952 * Our own config:
953 * (NOTE: IRQ and DMA aren't used, so they're set to
954 * give pretty output from conf_printf. :)
955 */
956 opl3sa2_state[card].cfg.io_base = io;
957 opl3sa2_state[card].cfg.irq = irq;
958 opl3sa2_state[card].cfg.dma = dma;
959 opl3sa2_state[card].cfg.dma2 = dma2;
960
961 /* The MSS config: */
962 opl3sa2_state[card].cfg_mss.io_base = mss_io;
963 opl3sa2_state[card].cfg_mss.irq = irq;
964 opl3sa2_state[card].cfg_mss.dma = dma;
965 opl3sa2_state[card].cfg_mss.dma2 = dma2;
966 opl3sa2_state[card].cfg_mss.card_subtype = 1; /* No IRQ or DMA setup */
967
968 opl3sa2_state[card].cfg_mpu.io_base = mpu_io;
969 opl3sa2_state[card].cfg_mpu.irq = irq;
970 opl3sa2_state[card].cfg_mpu.dma = -1;
971 opl3sa2_state[card].cfg_mpu.always_detect = 1; /* Use shared IRQs */
972
973 /* Call me paranoid: */
974 opl3sa2_clear_slots(&opl3sa2_state[card].cfg);
975 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mss);
976 opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
977 }
978
979 /* FIXME: leak */
980 if (probe_opl3sa2(&opl3sa2_state[card].cfg, card))
981 return -ENODEV;
982
983 base = opl3sa2_state[card].cfg_mss.io_base;
984
985 if (!request_region(base, 4, "WSS config"))
986 goto failed;
987
988 ports = request_region(base + 4, 4, "ad1848");
989 if (!ports)
990 goto failed2;
991
992 if (!probe_ms_sound(&opl3sa2_state[card].cfg_mss, ports)) {
993 /*
994 * If one or more cards are already registered, don't
995 * return an error but print a warning. Note, this
996 * should never really happen unless the hardware or
997 * ISA PnP screwed up.
998 */
999 release_region(base + 4, 4);
1000 failed2:
1001 release_region(base, 4);
1002 failed:
1003 release_region(opl3sa2_state[card].cfg.io_base, 2);
1004
1005 if (opl3sa2_cards_num) {
1006 printk(KERN_WARNING
1007 PFX "There was a problem probing one "
1008 " of the ISA PNP cards, continuing\n");
1009 opl3sa2_cards_num--;
1010 continue;
1011 } else
1012 return -ENODEV;
1013 }
1014
1015 attach_opl3sa2(&opl3sa2_state[card].cfg, card);
1016 conf_printf(opl3sa2_state[card].chipset_name, &opl3sa2_state[card].cfg);
1017 attach_opl3sa2_mixer(&opl3sa2_state[card].cfg, card);
1018 attach_opl3sa2_mss(&opl3sa2_state[card].cfg_mss, ports);
1019
1020 /* ewww =) */
1021 opl3sa2_state[card].card = card;
1022#ifdef CONFIG_PM
1023 /* register our power management capabilities */
1024 opl3sa2_state[card].pmdev = pm_register(PM_ISA_DEV, card, opl3sa2_pm_callback);
1025 if (opl3sa2_state[card].pmdev)
1026 opl3sa2_state[card].pmdev->data = &opl3sa2_state[card];
1027#endif /* CONFIG_PM */
1028
1029 /*
1030 * Set the Yamaha 3D enhancement mode (aka Ymersion) if asked to and
1031 * it's supported.
1032 */
1033 if (ymode != -1) {
1034 if (opl3sa2_state[card].chipset == CHIPSET_OPL3SA2) {
1035 printk(KERN_ERR
1036 PFX "ymode not supported on OPL3-SA2\n");
1037 }
1038 else {
1039 opl3sa2_set_ymode(&opl3sa2_state[card].cfg, ymode);
1040 }
1041 }
1042
1043
1044 /* Set A/D input to Mono loopback if asked to. */
1045 if (loopback != -1) {
1046 opl3sa2_set_loopback(&opl3sa2_state[card].cfg, loopback);
1047 }
1048
1049 /* Attach MPU if we've been asked to do so, failure isn't fatal */
1050 if (opl3sa2_state[card].cfg_mpu.io_base != -1) {
1051 int base = opl3sa2_state[card].cfg_mpu.io_base;
1052 struct resource *ports;
1053 ports = request_region(base, 2, "mpu401");
1054 if (!ports)
1055 goto out;
1056 if (!probe_mpu401(&opl3sa2_state[card].cfg_mpu, ports)) {
1057 release_region(base, 2);
1058 goto out;
1059 }
1060 if (attach_mpu401(&opl3sa2_state[card].cfg_mpu, THIS_MODULE)) {
1061 printk(KERN_ERR PFX "failed to attach MPU401\n");
1062 opl3sa2_state[card].cfg_mpu.slots[1] = -1;
1063 }
1064 }
1065 }
1066
1067out:
1068 if (isapnp) {
1069 printk(KERN_NOTICE PFX "%d PnP card(s) found.\n", opl3sa2_cards_num);
1070 }
1071
1072 return 0;
1073}
1074
1075
1076/*
1077 * Uninstall OPL3-SA2 based card(s).
1078 */
1079static void __exit cleanup_opl3sa2(void)
1080{
1081 int card;
1082
1083 for(card = 0; card < opl3sa2_cards_num; card++) {
1084#ifdef CONFIG_PM
1085 if (opl3sa2_state[card].pmdev)
1086 pm_unregister(opl3sa2_state[card].pmdev);
1087#endif
1088 if (opl3sa2_state[card].cfg_mpu.slots[1] != -1) {
1089 unload_opl3sa2_mpu(&opl3sa2_state[card].cfg_mpu);
1090 }
1091 unload_opl3sa2_mss(&opl3sa2_state[card].cfg_mss);
1092 unload_opl3sa2(&opl3sa2_state[card].cfg, card);
1093#ifdef CONFIG_PNP
1094 pnp_unregister_driver(&opl3sa2_driver);
1095#endif
1096 }
1097}
1098
1099module_init(init_opl3sa2);
1100module_exit(cleanup_opl3sa2);
1101
1102#ifndef MODULE
1103static int __init setup_opl3sa2(char *str)
1104{
1105 /* io, irq, dma, dma2,... */
1106#ifdef CONFIG_PNP
1107 int ints[11];
1108#else
1109 int ints[9];
1110#endif
1111 str = get_options(str, ARRAY_SIZE(ints), ints);
1112
1113 io = ints[1];
1114 irq = ints[2];
1115 dma = ints[3];
1116 dma2 = ints[4];
1117 mss_io = ints[5];
1118 mpu_io = ints[6];
1119 ymode = ints[7];
1120 loopback = ints[8];
1121#ifdef CONFIG_PNP
1122 isapnp = ints[9];
1123 multiple = ints[10];
1124#endif
1125 return 1;
1126}
1127
1128__setup("opl3sa2=", setup_opl3sa2);
1129#endif
diff --git a/sound/oss/os.h b/sound/oss/os.h
new file mode 100644
index 000000000000..d6b96297835c
--- /dev/null
+++ b/sound/oss/os.h
@@ -0,0 +1,51 @@
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#include <linux/version.h>
9
10#ifdef __KERNEL__
11#include <linux/utsname.h>
12#include <linux/string.h>
13#include <linux/fs.h>
14#include <asm/dma.h>
15#include <asm/io.h>
16#include <asm/param.h>
17#include <linux/sched.h>
18#include <linux/slab.h>
19#include <linux/ioport.h>
20#include <asm/page.h>
21#include <asm/system.h>
22#ifdef __alpha__
23#include <asm/segment.h>
24#endif
25#include <linux/vmalloc.h>
26#include <asm/uaccess.h>
27#include <linux/poll.h>
28#include <linux/pci.h>
29#endif
30
31#include <linux/soundcard.h>
32
33#define FALSE 0
34#define TRUE 1
35
36extern int sound_alloc_dma(int chn, char *deviceID);
37extern int sound_open_dma(int chn, char *deviceID);
38extern void sound_free_dma(int chn);
39extern void sound_close_dma(int chn);
40
41extern void reprogram_timer(void);
42
43#define USE_AUTOINIT_DMA
44
45extern void *sound_mem_blocks[1024];
46extern int sound_nblocks;
47
48#undef PSEUDO_DMA_AUTOINIT
49#define ALLOW_BUFFER_MAPPING
50
51extern struct file_operations oss_sound_fops;
diff --git a/sound/oss/pas2.h b/sound/oss/pas2.h
new file mode 100644
index 000000000000..fa12c55f560e
--- /dev/null
+++ b/sound/oss/pas2.h
@@ -0,0 +1,17 @@
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);
diff --git a/sound/oss/pas2_card.c b/sound/oss/pas2_card.c
new file mode 100644
index 000000000000..c9696dc9fdf9
--- /dev/null
+++ b/sound/oss/pas2_card.c
@@ -0,0 +1,458 @@
1/*
2 * sound/pas2_card.c
3 *
4 * Detection routine for the Pro Audio Spectrum cards.
5 */
6
7#include <linux/config.h>
8#include <linux/init.h>
9#include <linux/interrupt.h>
10#include <linux/module.h>
11#include <linux/spinlock.h>
12#include "sound_config.h"
13
14#include "pas2.h"
15#include "sb.h"
16
17static unsigned char dma_bits[] = {
18 4, 1, 2, 3, 0, 5, 6, 7
19};
20
21static unsigned char irq_bits[] = {
22 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 7, 8, 9, 0, 10, 11
23};
24
25static unsigned char sb_irq_bits[] = {
26 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20,
27 0x00, 0x08, 0x28, 0x30, 0x38, 0, 0
28};
29
30static unsigned char sb_dma_bits[] = {
31 0x00, 0x40, 0x80, 0xC0, 0, 0, 0, 0
32};
33
34/*
35 * The Address Translation code is used to convert I/O register addresses to
36 * be relative to the given base -register
37 */
38
39int pas_translate_code = 0;
40static int pas_intr_mask;
41static int pas_irq;
42static int pas_sb_base;
43DEFINE_SPINLOCK(pas_lock);
44#ifndef CONFIG_PAS_JOYSTICK
45static int joystick;
46#else
47static int joystick = 1;
48#endif
49#ifdef SYMPHONY_PAS
50static int symphony = 1;
51#else
52static int symphony;
53#endif
54#ifdef BROKEN_BUS_CLOCK
55static int broken_bus_clock = 1;
56#else
57static int broken_bus_clock;
58#endif
59
60static struct address_info cfg;
61static struct address_info cfg2;
62
63char pas_model = 0;
64static char *pas_model_names[] = {
65 "",
66 "Pro AudioSpectrum+",
67 "CDPC",
68 "Pro AudioSpectrum 16",
69 "Pro AudioSpectrum 16D"
70};
71
72/*
73 * pas_read() and pas_write() are equivalents of inb and outb
74 * These routines perform the I/O address translation required
75 * to support other than the default base address
76 */
77
78extern void mix_write(unsigned char data, int ioaddr);
79
80unsigned char pas_read(int ioaddr)
81{
82 return inb(ioaddr + pas_translate_code);
83}
84
85void pas_write(unsigned char data, int ioaddr)
86{
87 outb((data), ioaddr + pas_translate_code);
88}
89
90/******************* Begin of the Interrupt Handler ********************/
91
92static irqreturn_t pasintr(int irq, void *dev_id, struct pt_regs *dummy)
93{
94 int status;
95
96 status = pas_read(0x0B89);
97 pas_write(status, 0x0B89); /* Clear interrupt */
98
99 if (status & 0x08)
100 {
101 pas_pcm_interrupt(status, 1);
102 status &= ~0x08;
103 }
104 if (status & 0x10)
105 {
106 pas_midi_interrupt();
107 status &= ~0x10;
108 }
109 return IRQ_HANDLED;
110}
111
112int pas_set_intr(int mask)
113{
114 if (!mask)
115 return 0;
116
117 pas_intr_mask |= mask;
118
119 pas_write(pas_intr_mask, 0x0B8B);
120 return 0;
121}
122
123int pas_remove_intr(int mask)
124{
125 if (!mask)
126 return 0;
127
128 pas_intr_mask &= ~mask;
129 pas_write(pas_intr_mask, 0x0B8B);
130
131 return 0;
132}
133
134/******************* End of the Interrupt handler **********************/
135
136/******************* Begin of the Initialization Code ******************/
137
138static int __init config_pas_hw(struct address_info *hw_config)
139{
140 char ok = 1;
141 unsigned int_ptrs; /* scsi/sound interrupt pointers */
142
143 pas_irq = hw_config->irq;
144
145 pas_write(0x00, 0x0B8B);
146 pas_write(0x36, 0x138B);
147 pas_write(0x36, 0x1388);
148 pas_write(0, 0x1388);
149 pas_write(0x74, 0x138B);
150 pas_write(0x74, 0x1389);
151 pas_write(0, 0x1389);
152
153 pas_write(0x80 | 0x40 | 0x20 | 1, 0x0B8A);
154 pas_write(0x80 | 0x20 | 0x10 | 0x08 | 0x01, 0xF8A);
155 pas_write(0x01 | 0x02 | 0x04 | 0x10 /*
156 * |
157 * 0x80
158 */ , 0xB88);
159
160 pas_write(0x80
161 | joystick?0x40:0
162 ,0xF388);
163
164 if (pas_irq < 0 || pas_irq > 15)
165 {
166 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
167 hw_config->irq=-1;
168 ok = 0;
169 }
170 else
171 {
172 int_ptrs = pas_read(0xF38A);
173 int_ptrs = (int_ptrs & 0xf0) | irq_bits[pas_irq];
174 pas_write(int_ptrs, 0xF38A);
175 if (!irq_bits[pas_irq])
176 {
177 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
178 hw_config->irq=-1;
179 ok = 0;
180 }
181 else
182 {
183 if (request_irq(pas_irq, pasintr, 0, "PAS16",hw_config) < 0) {
184 printk(KERN_ERR "PAS16: Cannot allocate IRQ %d\n",pas_irq);
185 hw_config->irq=-1;
186 ok = 0;
187 }
188 }
189 }
190
191 if (hw_config->dma < 0 || hw_config->dma > 7)
192 {
193 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
194 hw_config->dma=-1;
195 ok = 0;
196 }
197 else
198 {
199 pas_write(dma_bits[hw_config->dma], 0xF389);
200 if (!dma_bits[hw_config->dma])
201 {
202 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
203 hw_config->dma=-1;
204 ok = 0;
205 }
206 else
207 {
208 if (sound_alloc_dma(hw_config->dma, "PAS16"))
209 {
210 printk(KERN_ERR "pas2_card.c: Can't allocate DMA channel\n");
211 hw_config->dma=-1;
212 ok = 0;
213 }
214 }
215 }
216
217 /*
218 * This fixes the timing problems of the PAS due to the Symphony chipset
219 * as per Media Vision. Only define this if your PAS doesn't work correctly.
220 */
221
222 if(symphony)
223 {
224 outb((0x05), 0xa8);
225 outb((0x60), 0xa9);
226 }
227
228 if(broken_bus_clock)
229 pas_write(0x01 | 0x10 | 0x20 | 0x04, 0x8388);
230 else
231 /*
232 * pas_write(0x01, 0x8388);
233 */
234 pas_write(0x01 | 0x10 | 0x20, 0x8388);
235
236 pas_write(0x18, 0x838A); /* ??? */
237 pas_write(0x20 | 0x01, 0x0B8A); /* Mute off, filter = 17.897 kHz */
238 pas_write(8, 0xBF8A);
239
240 mix_write(0x80 | 5, 0x078B);
241 mix_write(5, 0x078B);
242
243 {
244 struct address_info *sb_config;
245
246 sb_config = &cfg2;
247 if (sb_config->io_base)
248 {
249 unsigned char irq_dma;
250
251 /*
252 * Turn on Sound Blaster compatibility
253 * bit 1 = SB emulation
254 * bit 0 = MPU401 emulation (CDPC only :-( )
255 */
256
257 pas_write(0x02, 0xF788);
258
259 /*
260 * "Emulation address"
261 */
262
263 pas_write((sb_config->io_base >> 4) & 0x0f, 0xF789);
264 pas_sb_base = sb_config->io_base;
265
266 if (!sb_dma_bits[sb_config->dma])
267 printk(KERN_ERR "PAS16 Warning: Invalid SB DMA %d\n\n", sb_config->dma);
268
269 if (!sb_irq_bits[sb_config->irq])
270 printk(KERN_ERR "PAS16 Warning: Invalid SB IRQ %d\n\n", sb_config->irq);
271
272 irq_dma = sb_dma_bits[sb_config->dma] |
273 sb_irq_bits[sb_config->irq];
274
275 pas_write(irq_dma, 0xFB8A);
276 }
277 else
278 pas_write(0x00, 0xF788);
279 }
280
281 if (!ok)
282 printk(KERN_WARNING "PAS16: Driver not enabled\n");
283
284 return ok;
285}
286
287static int __init detect_pas_hw(struct address_info *hw_config)
288{
289 unsigned char board_id, foo;
290
291 /*
292 * WARNING: Setting an option like W:1 or so that disables warm boot reset
293 * of the card will screw up this detect code something fierce. Adding code
294 * to handle this means possibly interfering with other cards on the bus if
295 * you have something on base port 0x388. SO be forewarned.
296 */
297
298 outb((0xBC), 0x9A01); /* Activate first board */
299 outb((hw_config->io_base >> 2), 0x9A01); /* Set base address */
300 pas_translate_code = hw_config->io_base - 0x388;
301 pas_write(1, 0xBF88); /* Select one wait states */
302
303 board_id = pas_read(0x0B8B);
304
305 if (board_id == 0xff)
306 return 0;
307
308 /*
309 * We probably have a PAS-series board, now check for a PAS16-series board
310 * by trying to change the board revision bits. PAS16-series hardware won't
311 * let you do this - the bits are read-only.
312 */
313
314 foo = board_id ^ 0xe0;
315
316 pas_write(foo, 0x0B8B);
317 foo = pas_read(0x0B8B);
318 pas_write(board_id, 0x0B8B);
319
320 if (board_id != foo)
321 return 0;
322
323 pas_model = pas_read(0xFF88);
324
325 return pas_model;
326}
327
328static void __init attach_pas_card(struct address_info *hw_config)
329{
330 pas_irq = hw_config->irq;
331
332 if (detect_pas_hw(hw_config))
333 {
334
335 if ((pas_model = pas_read(0xFF88)))
336 {
337 char temp[100];
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(io, int, 0);
387module_param(irq, int, 0);
388module_param(dma, int, 0);
389module_param(dma16, int, 0);
390
391module_param(sb_io, int, 0);
392module_param(sb_irq, int, 0);
393module_param(sb_dma, int, 0);
394module_param(sb_dma16, int, 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
new file mode 100644
index 000000000000..79d6a5827b6d
--- /dev/null
+++ b/sound/oss/pas2_midi.c
@@ -0,0 +1,262 @@
1/*
2 * sound/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
new file mode 100644
index 000000000000..4aade5304587
--- /dev/null
+++ b/sound/oss/pas2_mixer.c
@@ -0,0 +1,336 @@
1
2/*
3 * sound/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
24#ifndef DEB
25#define DEB(what) /* (what) */
26#endif
27
28extern int pas_translate_code;
29extern char pas_model;
30extern int *pas_osp;
31extern int pas_audiodev;
32
33static int rec_devices = (SOUND_MASK_MIC); /* Default recording source */
34static int mode_control;
35
36#define POSSIBLE_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
37 SOUND_MASK_CD | SOUND_MASK_ALTPCM)
38
39#define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
40 SOUND_MASK_CD | SOUND_MASK_ALTPCM | SOUND_MASK_IMIX | \
41 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_RECLEV)
42
43static int *levels;
44
45static int default_levels[32] =
46{
47 0x3232, /* Master Volume */
48 0x3232, /* Bass */
49 0x3232, /* Treble */
50 0x5050, /* FM */
51 0x4b4b, /* PCM */
52 0x3232, /* PC Speaker */
53 0x4b4b, /* Ext Line */
54 0x4b4b, /* Mic */
55 0x4b4b, /* CD */
56 0x6464, /* Recording monitor */
57 0x4b4b, /* SB PCM */
58 0x6464 /* Recording level */
59};
60
61void
62mix_write(unsigned char data, int ioaddr)
63{
64 /*
65 * The Revision D cards have a problem with their MVA508 interface. The
66 * kludge-o-rama fix is to make a 16-bit quantity with identical LSB and
67 * MSBs out of the output byte and to do a 16-bit out to the mixer port -
68 * 1. We need to do this because it isn't timing problem but chip access
69 * sequence problem.
70 */
71
72 if (pas_model == 4)
73 {
74 outw(data | (data << 8), (ioaddr + pas_translate_code) - 1);
75 outb((0x80), 0);
76 } else
77 pas_write(data, ioaddr);
78}
79
80static int
81mixer_output(int right_vol, int left_vol, int div, int bits,
82 int mixer) /* Input or output mixer */
83{
84 int left = left_vol * div / 100;
85 int right = right_vol * div / 100;
86
87
88 if (bits & 0x10)
89 {
90 left |= mixer;
91 right |= mixer;
92 }
93 if (bits == 0x03 || bits == 0x04)
94 {
95 mix_write(0x80 | bits, 0x078B);
96 mix_write(left, 0x078B);
97 right_vol = left_vol;
98 } else
99 {
100 mix_write(0x80 | 0x20 | bits, 0x078B);
101 mix_write(left, 0x078B);
102 mix_write(0x80 | 0x40 | bits, 0x078B);
103 mix_write(right, 0x078B);
104 }
105
106 return (left_vol | (right_vol << 8));
107}
108
109static void
110set_mode(int new_mode)
111{
112 mix_write(0x80 | 0x05, 0x078B);
113 mix_write(new_mode, 0x078B);
114
115 mode_control = new_mode;
116}
117
118static int
119pas_mixer_set(int whichDev, unsigned int level)
120{
121 int left, right, devmask, changed, i, mixer = 0;
122
123 DEB(printk("static int pas_mixer_set(int whichDev = %d, unsigned int level = %X)\n", whichDev, level));
124
125 left = level & 0x7f;
126 right = (level & 0x7f00) >> 8;
127
128 if (whichDev < SOUND_MIXER_NRDEVICES) {
129 if ((1 << whichDev) & rec_devices)
130 mixer = 0x20;
131 else
132 mixer = 0x00;
133 }
134
135 switch (whichDev)
136 {
137 case SOUND_MIXER_VOLUME: /* Master volume (0-63) */
138 levels[whichDev] = mixer_output(right, left, 63, 0x01, 0);
139 break;
140
141 /*
142 * Note! Bass and Treble are mono devices. Will use just the left
143 * channel.
144 */
145 case SOUND_MIXER_BASS: /* Bass (0-12) */
146 levels[whichDev] = mixer_output(right, left, 12, 0x03, 0);
147 break;
148 case SOUND_MIXER_TREBLE: /* Treble (0-12) */
149 levels[whichDev] = mixer_output(right, left, 12, 0x04, 0);
150 break;
151
152 case SOUND_MIXER_SYNTH: /* Internal synthesizer (0-31) */
153 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x00, mixer);
154 break;
155 case SOUND_MIXER_PCM: /* PAS PCM (0-31) */
156 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x05, mixer);
157 break;
158 case SOUND_MIXER_ALTPCM: /* SB PCM (0-31) */
159 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x07, mixer);
160 break;
161 case SOUND_MIXER_SPEAKER: /* PC speaker (0-31) */
162 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x06, mixer);
163 break;
164 case SOUND_MIXER_LINE: /* External line (0-31) */
165 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x02, mixer);
166 break;
167 case SOUND_MIXER_CD: /* CD (0-31) */
168 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x03, mixer);
169 break;
170 case SOUND_MIXER_MIC: /* External microphone (0-31) */
171 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x04, mixer);
172 break;
173 case SOUND_MIXER_IMIX: /* Recording monitor (0-31) (Output mixer only) */
174 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x01,
175 0x00);
176 break;
177 case SOUND_MIXER_RECLEV: /* Recording level (0-15) */
178 levels[whichDev] = mixer_output(right, left, 15, 0x02, 0);
179 break;
180
181
182 case SOUND_MIXER_RECSRC:
183 devmask = level & POSSIBLE_RECORDING_DEVICES;
184
185 changed = devmask ^ rec_devices;
186 rec_devices = devmask;
187
188 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
189 if (changed & (1 << i))
190 {
191 pas_mixer_set(i, levels[i]);
192 }
193 return rec_devices;
194 break;
195
196 default:
197 return -EINVAL;
198 }
199
200 return (levels[whichDev]);
201}
202
203/*****/
204
205static void
206pas_mixer_reset(void)
207{
208 int foo;
209
210 DEB(printk("pas2_mixer.c: void pas_mixer_reset(void)\n"));
211
212 for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++)
213 pas_mixer_set(foo, levels[foo]);
214
215 set_mode(0x04 | 0x01);
216}
217
218static int pas_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
219{
220 int level,v ;
221 int __user *p = (int __user *)arg;
222
223 DEB(printk("pas2_mixer.c: int pas_mixer_ioctl(unsigned int cmd = %X, unsigned int arg = %X)\n", cmd, arg));
224 if (cmd == SOUND_MIXER_PRIVATE1) { /* Set loudness bit */
225 if (get_user(level, p))
226 return -EFAULT;
227 if (level == -1) /* Return current settings */
228 level = (mode_control & 0x04);
229 else {
230 mode_control &= ~0x04;
231 if (level)
232 mode_control |= 0x04;
233 set_mode(mode_control);
234 }
235 level = !!level;
236 return put_user(level, p);
237 }
238 if (cmd == SOUND_MIXER_PRIVATE2) { /* Set enhance bit */
239 if (get_user(level, p))
240 return -EFAULT;
241 if (level == -1) { /* Return current settings */
242 if (!(mode_control & 0x03))
243 level = 0;
244 else
245 level = ((mode_control & 0x03) + 1) * 20;
246 } else {
247 int i = 0;
248
249 level &= 0x7f;
250 if (level)
251 i = (level / 20) - 1;
252 mode_control &= ~0x03;
253 mode_control |= i & 0x03;
254 set_mode(mode_control);
255 if (i)
256 i = (i + 1) * 20;
257 level = i;
258 }
259 return put_user(level, p);
260 }
261 if (cmd == SOUND_MIXER_PRIVATE3) { /* Set mute bit */
262 if (get_user(level, p))
263 return -EFAULT;
264 if (level == -1) /* Return current settings */
265 level = !(pas_read(0x0B8A) & 0x20);
266 else {
267 if (level)
268 pas_write(pas_read(0x0B8A) & (~0x20), 0x0B8A);
269 else
270 pas_write(pas_read(0x0B8A) | 0x20, 0x0B8A);
271
272 level = !(pas_read(0x0B8A) & 0x20);
273 }
274 return put_user(level, p);
275 }
276 if (((cmd >> 8) & 0xff) == 'M') {
277 if (get_user(v, p))
278 return -EFAULT;
279 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
280 v = pas_mixer_set(cmd & 0xff, v);
281 } else {
282 switch (cmd & 0xff) {
283 case SOUND_MIXER_RECSRC:
284 v = rec_devices;
285 break;
286
287 case SOUND_MIXER_STEREODEVS:
288 v = SUPPORTED_MIXER_DEVICES & ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE);
289 break;
290
291 case SOUND_MIXER_DEVMASK:
292 v = SUPPORTED_MIXER_DEVICES;
293 break;
294
295 case SOUND_MIXER_RECMASK:
296 v = POSSIBLE_RECORDING_DEVICES & SUPPORTED_MIXER_DEVICES;
297 break;
298
299 case SOUND_MIXER_CAPS:
300 v = 0; /* No special capabilities */
301 break;
302
303 default:
304 v = levels[cmd & 0xff];
305 break;
306 }
307 }
308 return put_user(v, p);
309 }
310 return -EINVAL;
311}
312
313static struct mixer_operations pas_mixer_operations =
314{
315 .owner = THIS_MODULE,
316 .id = "PAS16",
317 .name = "Pro Audio Spectrum 16",
318 .ioctl = pas_mixer_ioctl
319};
320
321int __init
322pas_init_mixer(void)
323{
324 int d;
325
326 levels = load_mixer_volumes("PAS16_1", default_levels, 1);
327
328 pas_mixer_reset();
329
330 if ((d = sound_alloc_mixerdev()) != -1)
331 {
332 audio_devs[pas_audiodev]->mixer_dev = d;
333 mixer_devs[d] = &pas_mixer_operations;
334 }
335 return 1;
336}
diff --git a/sound/oss/pas2_pcm.c b/sound/oss/pas2_pcm.c
new file mode 100644
index 000000000000..4af6aafa3d86
--- /dev/null
+++ b/sound/oss/pas2_pcm.c
@@ -0,0 +1,437 @@
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 <asm/timex.h>
21#include "sound_config.h"
22
23#include "pas2.h"
24
25#ifndef DEB
26#define DEB(WHAT)
27#endif
28
29#define PAS_PCM_INTRBITS (0x08)
30/*
31 * Sample buffer timer interrupt enable
32 */
33
34#define PCM_NON 0
35#define PCM_DAC 1
36#define PCM_ADC 2
37
38static unsigned long pcm_speed; /* sampling rate */
39static unsigned char pcm_channels = 1; /* channels (1 or 2) */
40static unsigned char pcm_bits = 8; /* bits/sample (8 or 16) */
41static unsigned char pcm_filter; /* filter FLAG */
42static unsigned char pcm_mode = PCM_NON;
43static unsigned long pcm_count;
44static unsigned short pcm_bitsok = 8; /* mask of OK bits */
45static int pcm_busy;
46int pas_audiodev = -1;
47static int open_mode;
48
49extern spinlock_t pas_lock;
50
51static int pcm_set_speed(int arg)
52{
53 int foo, tmp;
54 unsigned long flags;
55
56 if (arg == 0)
57 return pcm_speed;
58
59 if (arg > 44100)
60 arg = 44100;
61 if (arg < 5000)
62 arg = 5000;
63
64 if (pcm_channels & 2)
65 {
66 foo = ((CLOCK_TICK_RATE / 2) + (arg / 2)) / arg;
67 arg = ((CLOCK_TICK_RATE / 2) + (foo / 2)) / foo;
68 }
69 else
70 {
71 foo = (CLOCK_TICK_RATE + (arg / 2)) / arg;
72 arg = (CLOCK_TICK_RATE + (foo / 2)) / foo;
73 }
74
75 pcm_speed = arg;
76
77 tmp = pas_read(0x0B8A);
78
79 /*
80 * Set anti-aliasing filters according to sample rate. You really *NEED*
81 * to enable this feature for all normal recording unless you want to
82 * experiment with aliasing effects.
83 * These filters apply to the selected "recording" source.
84 * I (pfw) don't know the encoding of these 5 bits. The values shown
85 * come from the SDK found on ftp.uwp.edu:/pub/msdos/proaudio/.
86 *
87 * I cleared bit 5 of these values, since that bit controls the master
88 * mute flag. (Olav Wölfelschneider)
89 *
90 */
91#if !defined NO_AUTO_FILTER_SET
92 tmp &= 0xe0;
93 if (pcm_speed >= 2 * 17897)
94 tmp |= 0x01;
95 else if (pcm_speed >= 2 * 15909)
96 tmp |= 0x02;
97 else if (pcm_speed >= 2 * 11931)
98 tmp |= 0x09;
99 else if (pcm_speed >= 2 * 8948)
100 tmp |= 0x11;
101 else if (pcm_speed >= 2 * 5965)
102 tmp |= 0x19;
103 else if (pcm_speed >= 2 * 2982)
104 tmp |= 0x04;
105 pcm_filter = tmp;
106#endif
107
108 spin_lock_irqsave(&pas_lock, flags);
109
110 pas_write(tmp & ~(0x40 | 0x80), 0x0B8A);
111 pas_write(0x00 | 0x30 | 0x04, 0x138B);
112 pas_write(foo & 0xff, 0x1388);
113 pas_write((foo >> 8) & 0xff, 0x1388);
114 pas_write(tmp, 0x0B8A);
115
116 spin_unlock_irqrestore(&pas_lock, flags);
117
118 return pcm_speed;
119}
120
121static int pcm_set_channels(int arg)
122{
123
124 if ((arg != 1) && (arg != 2))
125 return pcm_channels;
126
127 if (arg != pcm_channels)
128 {
129 pas_write(pas_read(0xF8A) ^ 0x20, 0xF8A);
130
131 pcm_channels = arg;
132 pcm_set_speed(pcm_speed); /* The speed must be reinitialized */
133 }
134 return pcm_channels;
135}
136
137static int pcm_set_bits(int arg)
138{
139 if (arg == 0)
140 return pcm_bits;
141
142 if ((arg & pcm_bitsok) != arg)
143 return pcm_bits;
144
145 if (arg != pcm_bits)
146 {
147 pas_write(pas_read(0x8389) ^ 0x04, 0x8389);
148
149 pcm_bits = arg;
150 }
151 return pcm_bits;
152}
153
154static int pas_audio_ioctl(int dev, unsigned int cmd, void __user *arg)
155{
156 int val, ret;
157 int __user *p = arg;
158
159 DEB(printk("pas2_pcm.c: static int pas_audio_ioctl(unsigned int cmd = %X, unsigned int arg = %X)\n", cmd, arg));
160
161 switch (cmd)
162 {
163 case SOUND_PCM_WRITE_RATE:
164 if (get_user(val, p))
165 return -EFAULT;
166 ret = pcm_set_speed(val);
167 break;
168
169 case SOUND_PCM_READ_RATE:
170 ret = pcm_speed;
171 break;
172
173 case SNDCTL_DSP_STEREO:
174 if (get_user(val, p))
175 return -EFAULT;
176 ret = pcm_set_channels(val + 1) - 1;
177 break;
178
179 case SOUND_PCM_WRITE_CHANNELS:
180 if (get_user(val, p))
181 return -EFAULT;
182 ret = pcm_set_channels(val);
183 break;
184
185 case SOUND_PCM_READ_CHANNELS:
186 ret = pcm_channels;
187 break;
188
189 case SNDCTL_DSP_SETFMT:
190 if (get_user(val, p))
191 return -EFAULT;
192 ret = pcm_set_bits(val);
193 break;
194
195 case SOUND_PCM_READ_BITS:
196 ret = pcm_bits;
197 break;
198
199 default:
200 return -EINVAL;
201 }
202 return put_user(ret, p);
203}
204
205static void pas_audio_reset(int dev)
206{
207 DEB(printk("pas2_pcm.c: static void pas_audio_reset(void)\n"));
208
209 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A); /* Disable PCM */
210}
211
212static int pas_audio_open(int dev, int mode)
213{
214 int err;
215 unsigned long flags;
216
217 DEB(printk("pas2_pcm.c: static int pas_audio_open(int mode = %X)\n", mode));
218
219 spin_lock_irqsave(&pas_lock, flags);
220 if (pcm_busy)
221 {
222 spin_unlock_irqrestore(&pas_lock, flags);
223 return -EBUSY;
224 }
225 pcm_busy = 1;
226 spin_unlock_irqrestore(&pas_lock, flags);
227
228 if ((err = pas_set_intr(PAS_PCM_INTRBITS)) < 0)
229 return err;
230
231
232 pcm_count = 0;
233 open_mode = mode;
234
235 return 0;
236}
237
238static void pas_audio_close(int dev)
239{
240 unsigned long flags;
241
242 DEB(printk("pas2_pcm.c: static void pas_audio_close(void)\n"));
243
244 spin_lock_irqsave(&pas_lock, flags);
245
246 pas_audio_reset(dev);
247 pas_remove_intr(PAS_PCM_INTRBITS);
248 pcm_mode = PCM_NON;
249
250 pcm_busy = 0;
251 spin_unlock_irqrestore(&pas_lock, flags);
252}
253
254static void pas_audio_output_block(int dev, unsigned long buf, int count,
255 int intrflag)
256{
257 unsigned long flags, cnt;
258
259 DEB(printk("pas2_pcm.c: static void pas_audio_output_block(char *buf = %P, int count = %X)\n", buf, count));
260
261 cnt = count;
262 if (audio_devs[dev]->dmap_out->dma > 3)
263 cnt >>= 1;
264
265 if (audio_devs[dev]->flags & DMA_AUTOMODE &&
266 intrflag &&
267 cnt == pcm_count)
268 return;
269
270 spin_lock_irqsave(&pas_lock, flags);
271
272 pas_write(pas_read(0xF8A) & ~0x40,
273 0xF8A);
274
275 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
276
277 if (audio_devs[dev]->dmap_out->dma > 3)
278 count >>= 1;
279
280 if (count != pcm_count)
281 {
282 pas_write(pas_read(0x0B8A) & ~0x80, 0x0B8A);
283 pas_write(0x40 | 0x30 | 0x04, 0x138B);
284 pas_write(count & 0xff, 0x1389);
285 pas_write((count >> 8) & 0xff, 0x1389);
286 pas_write(pas_read(0x0B8A) | 0x80, 0x0B8A);
287
288 pcm_count = count;
289 }
290 pas_write(pas_read(0x0B8A) | 0x80 | 0x40, 0x0B8A);
291#ifdef NO_TRIGGER
292 pas_write(pas_read(0xF8A) | 0x40 | 0x10, 0xF8A);
293#endif
294
295 pcm_mode = PCM_DAC;
296
297 spin_unlock_irqrestore(&pas_lock, flags);
298}
299
300static void pas_audio_start_input(int dev, unsigned long buf, int count,
301 int intrflag)
302{
303 unsigned long flags;
304 int cnt;
305
306 DEB(printk("pas2_pcm.c: static void pas_audio_start_input(char *buf = %P, int count = %X)\n", buf, count));
307
308 cnt = count;
309 if (audio_devs[dev]->dmap_out->dma > 3)
310 cnt >>= 1;
311
312 if (audio_devs[pas_audiodev]->flags & DMA_AUTOMODE &&
313 intrflag &&
314 cnt == pcm_count)
315 return;
316
317 spin_lock_irqsave(&pas_lock, flags);
318
319 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
320
321 if (audio_devs[dev]->dmap_out->dma > 3)
322 count >>= 1;
323
324 if (count != pcm_count)
325 {
326 pas_write(pas_read(0x0B8A) & ~0x80, 0x0B8A);
327 pas_write(0x40 | 0x30 | 0x04, 0x138B);
328 pas_write(count & 0xff, 0x1389);
329 pas_write((count >> 8) & 0xff, 0x1389);
330 pas_write(pas_read(0x0B8A) | 0x80, 0x0B8A);
331
332 pcm_count = count;
333 }
334 pas_write(pas_read(0x0B8A) | 0x80 | 0x40, 0x0B8A);
335#ifdef NO_TRIGGER
336 pas_write((pas_read(0xF8A) | 0x40) & ~0x10, 0xF8A);
337#endif
338
339 pcm_mode = PCM_ADC;
340
341 spin_unlock_irqrestore(&pas_lock, flags);
342}
343
344#ifndef NO_TRIGGER
345static void pas_audio_trigger(int dev, int state)
346{
347 unsigned long flags;
348
349 spin_lock_irqsave(&pas_lock, flags);
350 state &= open_mode;
351
352 if (state & PCM_ENABLE_OUTPUT)
353 pas_write(pas_read(0xF8A) | 0x40 | 0x10, 0xF8A);
354 else if (state & PCM_ENABLE_INPUT)
355 pas_write((pas_read(0xF8A) | 0x40) & ~0x10, 0xF8A);
356 else
357 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A);
358
359 spin_unlock_irqrestore(&pas_lock, flags);
360}
361#endif
362
363static int pas_audio_prepare_for_input(int dev, int bsize, int bcount)
364{
365 pas_audio_reset(dev);
366 return 0;
367}
368
369static int pas_audio_prepare_for_output(int dev, int bsize, int bcount)
370{
371 pas_audio_reset(dev);
372 return 0;
373}
374
375static struct audio_driver pas_audio_driver =
376{
377 .owner = THIS_MODULE,
378 .open = pas_audio_open,
379 .close = pas_audio_close,
380 .output_block = pas_audio_output_block,
381 .start_input = pas_audio_start_input,
382 .ioctl = pas_audio_ioctl,
383 .prepare_for_input = pas_audio_prepare_for_input,
384 .prepare_for_output = pas_audio_prepare_for_output,
385 .halt_io = pas_audio_reset,
386 .trigger = pas_audio_trigger
387};
388
389void __init pas_pcm_init(struct address_info *hw_config)
390{
391 DEB(printk("pas2_pcm.c: long pas_pcm_init()\n"));
392
393 pcm_bitsok = 8;
394 if (pas_read(0xEF8B) & 0x08)
395 pcm_bitsok |= 16;
396
397 pcm_set_speed(DSP_DEFAULT_SPEED);
398
399 if ((pas_audiodev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
400 "Pro Audio Spectrum",
401 &pas_audio_driver,
402 sizeof(struct audio_driver),
403 DMA_AUTOMODE,
404 AFMT_U8 | AFMT_S16_LE,
405 NULL,
406 hw_config->dma,
407 hw_config->dma)) < 0)
408 printk(KERN_WARNING "PAS16: Too many PCM devices available\n");
409}
410
411void pas_pcm_interrupt(unsigned char status, int cause)
412{
413 if (cause == 1)
414 {
415 /*
416 * Halt the PCM first. Otherwise we don't have time to start a new
417 * block before the PCM chip proceeds to the next sample
418 */
419
420 if (!(audio_devs[pas_audiodev]->flags & DMA_AUTOMODE))
421 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A);
422
423 switch (pcm_mode)
424 {
425 case PCM_DAC:
426 DMAbuf_outputintr(pas_audiodev, 1);
427 break;
428
429 case PCM_ADC:
430 DMAbuf_inputintr(pas_audiodev);
431 break;
432
433 default:
434 printk(KERN_WARNING "PAS: Unexpected PCM interrupt\n");
435 }
436 }
437}
diff --git a/sound/oss/pss.c b/sound/oss/pss.c
new file mode 100644
index 000000000000..3ed38765dcc4
--- /dev/null
+++ b/sound/oss/pss.c
@@ -0,0 +1,1283 @@
1/*
2 * sound/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 fireware 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/config.h>
61#include <linux/init.h>
62#include <linux/module.h>
63#include <linux/spinlock.h>
64
65#include "sound_config.h"
66#include "sound_firmware.h"
67
68#include "ad1848.h"
69#include "mpu401.h"
70
71/*
72 * PSS registers.
73 */
74#define REG(x) (devc->base+x)
75#define PSS_DATA 0
76#define PSS_STATUS 2
77#define PSS_CONTROL 2
78#define PSS_ID 4
79#define PSS_IRQACK 4
80#define PSS_PIO 0x1a
81
82/*
83 * Config registers
84 */
85#define CONF_PSS 0x10
86#define CONF_WSS 0x12
87#define CONF_SB 0x14
88#define CONF_CDROM 0x16
89#define CONF_MIDI 0x18
90
91/*
92 * Status bits.
93 */
94#define PSS_FLAG3 0x0800
95#define PSS_FLAG2 0x0400
96#define PSS_FLAG1 0x1000
97#define PSS_FLAG0 0x0800
98#define PSS_WRITE_EMPTY 0x8000
99#define PSS_READ_FULL 0x4000
100
101/*
102 * WSS registers
103 */
104#define WSS_INDEX 4
105#define WSS_DATA 5
106
107/*
108 * WSS status bits
109 */
110#define WSS_INITIALIZING 0x80
111#define WSS_AUTOCALIBRATION 0x20
112
113#define NO_WSS_MIXER -1
114
115#include "coproc.h"
116
117#include "pss_boot.h"
118
119/* If compiled into kernel, it enable or disable pss mixer */
120#ifdef CONFIG_PSS_MIXER
121static int pss_mixer = 1;
122#else
123static int pss_mixer;
124#endif
125
126
127typedef struct pss_mixerdata {
128 unsigned int volume_l;
129 unsigned int volume_r;
130 unsigned int bass;
131 unsigned int treble;
132 unsigned int synth;
133} pss_mixerdata;
134
135typedef struct pss_confdata {
136 int base;
137 int irq;
138 int dma;
139 int *osp;
140 pss_mixerdata mixer;
141 int ad_mixer_dev;
142} pss_confdata;
143
144static pss_confdata pss_data;
145static pss_confdata *devc = &pss_data;
146static DEFINE_SPINLOCK(lock);
147
148static int pss_initialized;
149static int nonstandard_microcode;
150static int pss_cdrom_port = -1; /* Parameter for the PSS cdrom port */
151static int pss_enable_joystick; /* Parameter for enabling the joystick */
152static coproc_operations pss_coproc_operations;
153
154static void pss_write(pss_confdata *devc, int data)
155{
156 unsigned long i, limit;
157
158 limit = jiffies + HZ/10; /* The timeout is 0.1 seconds */
159 /*
160 * Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
161 * called while interrupts are disabled. This means that the timer is
162 * disabled also. However the timeout situation is a abnormal condition.
163 * Normally the DSP should be ready to accept commands after just couple of
164 * loops.
165 */
166
167 for (i = 0; i < 5000000 && time_before(jiffies, limit); i++)
168 {
169 if (inw(REG(PSS_STATUS)) & PSS_WRITE_EMPTY)
170 {
171 outw(data, REG(PSS_DATA));
172 return;
173 }
174 }
175 printk(KERN_WARNING "PSS: DSP Command (%04x) Timeout.\n", data);
176}
177
178static int __init probe_pss(struct address_info *hw_config)
179{
180 unsigned short id;
181 int irq, dma;
182
183 devc->base = hw_config->io_base;
184 irq = devc->irq = hw_config->irq;
185 dma = devc->dma = hw_config->dma;
186 devc->osp = hw_config->osp;
187
188 if (devc->base != 0x220 && devc->base != 0x240)
189 if (devc->base != 0x230 && devc->base != 0x250) /* Some cards use these */
190 return 0;
191
192 if (!request_region(devc->base, 0x10, "PSS mixer, SB emulation")) {
193 printk(KERN_ERR "PSS: I/O port conflict\n");
194 return 0;
195 }
196 id = inw(REG(PSS_ID));
197 if ((id >> 8) != 'E') {
198 printk(KERN_ERR "No PSS signature detected at 0x%x (0x%x)\n", devc->base, id);
199 release_region(devc->base, 0x10);
200 return 0;
201 }
202 if (!request_region(devc->base + 0x10, 0x9, "PSS config")) {
203 printk(KERN_ERR "PSS: I/O port conflict\n");
204 release_region(devc->base, 0x10);
205 return 0;
206 }
207 return 1;
208}
209
210static int set_irq(pss_confdata * devc, int dev, int irq)
211{
212 static unsigned short irq_bits[16] =
213 {
214 0x0000, 0x0000, 0x0000, 0x0008,
215 0x0000, 0x0010, 0x0000, 0x0018,
216 0x0000, 0x0020, 0x0028, 0x0030,
217 0x0038, 0x0000, 0x0000, 0x0000
218 };
219
220 unsigned short tmp, bits;
221
222 if (irq < 0 || irq > 15)
223 return 0;
224
225 tmp = inw(REG(dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
226
227 if ((bits = irq_bits[irq]) == 0 && irq != 0)
228 {
229 printk(KERN_ERR "PSS: Invalid IRQ %d\n", irq);
230 return 0;
231 }
232 outw(tmp | bits, REG(dev));
233 return 1;
234}
235
236static int set_io_base(pss_confdata * devc, int dev, int base)
237{
238 unsigned short tmp = inw(REG(dev)) & 0x003f;
239 unsigned short bits = (base & 0x0ffc) << 4;
240
241 outw(bits | tmp, REG(dev));
242
243 return 1;
244}
245
246static int set_dma(pss_confdata * devc, int dev, int dma)
247{
248 static unsigned short dma_bits[8] =
249 {
250 0x0001, 0x0002, 0x0000, 0x0003,
251 0x0000, 0x0005, 0x0006, 0x0007
252 };
253
254 unsigned short tmp, bits;
255
256 if (dma < 0 || dma > 7)
257 return 0;
258
259 tmp = inw(REG(dev)) & ~0x07; /* Load confreg, mask DMA bits out */
260
261 if ((bits = dma_bits[dma]) == 0 && dma != 4)
262 {
263 printk(KERN_ERR "PSS: Invalid DMA %d\n", dma);
264 return 0;
265 }
266 outw(tmp | bits, REG(dev));
267 return 1;
268}
269
270static int pss_reset_dsp(pss_confdata * devc)
271{
272 unsigned long i, limit = jiffies + HZ/10;
273
274 outw(0x2000, REG(PSS_CONTROL));
275 for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
276 inw(REG(PSS_CONTROL));
277 outw(0x0000, REG(PSS_CONTROL));
278 return 1;
279}
280
281static int pss_put_dspword(pss_confdata * devc, unsigned short word)
282{
283 int i, val;
284
285 for (i = 0; i < 327680; i++)
286 {
287 val = inw(REG(PSS_STATUS));
288 if (val & PSS_WRITE_EMPTY)
289 {
290 outw(word, REG(PSS_DATA));
291 return 1;
292 }
293 }
294 return 0;
295}
296
297static int pss_get_dspword(pss_confdata * devc, unsigned short *word)
298{
299 int i, val;
300
301 for (i = 0; i < 327680; i++)
302 {
303 val = inw(REG(PSS_STATUS));
304 if (val & PSS_READ_FULL)
305 {
306 *word = inw(REG(PSS_DATA));
307 return 1;
308 }
309 }
310 return 0;
311}
312
313static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size, int flags)
314{
315 int i, val, count;
316 unsigned long limit;
317
318 if (flags & CPF_FIRST)
319 {
320/*_____ Warn DSP software that a boot is coming */
321 outw(0x00fe, REG(PSS_DATA));
322
323 limit = jiffies + HZ/10;
324 for (i = 0; i < 32768 && time_before(jiffies, limit); i++)
325 if (inw(REG(PSS_DATA)) == 0x5500)
326 break;
327
328 outw(*block++, REG(PSS_DATA));
329 pss_reset_dsp(devc);
330 }
331 count = 1;
332 while ((flags&CPF_LAST) || count<size )
333 {
334 int j;
335
336 for (j = 0; j < 327670; j++)
337 {
338/*_____ Wait for BG to appear */
339 if (inw(REG(PSS_STATUS)) & PSS_FLAG3)
340 break;
341 }
342
343 if (j == 327670)
344 {
345 /* It's ok we timed out when the file was empty */
346 if (count >= size && flags & CPF_LAST)
347 break;
348 else
349 {
350 printk("\n");
351 printk(KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
352 return 0;
353 }
354 }
355/*_____ Send the next byte */
356 if (count >= size)
357 {
358 /* If not data in block send 0xffff */
359 outw (0xffff, REG (PSS_DATA));
360 }
361 else
362 {
363 /*_____ Send the next byte */
364 outw (*block++, REG (PSS_DATA));
365 };
366 count++;
367 }
368
369 if (flags & CPF_LAST)
370 {
371/*_____ Why */
372 outw(0, REG(PSS_DATA));
373
374 limit = jiffies + HZ/10;
375 for (i = 0; i < 32768 && (limit - jiffies >= 0); i++)
376 val = inw(REG(PSS_STATUS));
377
378 limit = jiffies + HZ/10;
379 for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
380 {
381 val = inw(REG(PSS_STATUS));
382 if (val & 0x4000)
383 break;
384 }
385
386 /* now read the version */
387 for (i = 0; i < 32000; i++)
388 {
389 val = inw(REG(PSS_STATUS));
390 if (val & PSS_READ_FULL)
391 break;
392 }
393 if (i == 32000)
394 return 0;
395
396 val = inw(REG(PSS_DATA));
397 /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
398 }
399 return 1;
400}
401
402/* Mixer */
403static void set_master_volume(pss_confdata *devc, int left, int right)
404{
405 static unsigned char log_scale[101] = {
406 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
407 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
408 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
409 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
410 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
411 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
412 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
413 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
414 0xfe, 0xfe, 0xff, 0xff, 0xff
415 };
416 pss_write(devc, 0x0010);
417 pss_write(devc, log_scale[left] | 0x0000);
418 pss_write(devc, 0x0010);
419 pss_write(devc, log_scale[right] | 0x0100);
420}
421
422static void set_synth_volume(pss_confdata *devc, int volume)
423{
424 int vol = ((0x8000*volume)/100L);
425 pss_write(devc, 0x0080);
426 pss_write(devc, vol);
427 pss_write(devc, 0x0081);
428 pss_write(devc, vol);
429}
430
431static void set_bass(pss_confdata *devc, int level)
432{
433 int vol = (int)(((0xfd - 0xf0) * level)/100L) + 0xf0;
434 pss_write(devc, 0x0010);
435 pss_write(devc, vol | 0x0200);
436};
437
438static void set_treble(pss_confdata *devc, int level)
439{
440 int vol = (((0xfd - 0xf0) * level)/100L) + 0xf0;
441 pss_write(devc, 0x0010);
442 pss_write(devc, vol | 0x0300);
443};
444
445static void pss_mixer_reset(pss_confdata *devc)
446{
447 set_master_volume(devc, 33, 33);
448 set_bass(devc, 50);
449 set_treble(devc, 50);
450 set_synth_volume(devc, 30);
451 pss_write (devc, 0x0010);
452 pss_write (devc, 0x0800 | 0xce); /* Stereo */
453
454 if(pss_mixer)
455 {
456 devc->mixer.volume_l = devc->mixer.volume_r = 33;
457 devc->mixer.bass = 50;
458 devc->mixer.treble = 50;
459 devc->mixer.synth = 30;
460 }
461}
462
463static int set_volume_mono(unsigned __user *p, int *aleft)
464{
465 int left;
466 unsigned volume;
467 if (get_user(volume, p))
468 return -EFAULT;
469
470 left = volume & 0xff;
471 if (left > 100)
472 left = 100;
473 *aleft = left;
474 return 0;
475}
476
477static int set_volume_stereo(unsigned __user *p, int *aleft, int *aright)
478{
479 int left, right;
480 unsigned volume;
481 if (get_user(volume, p))
482 return -EFAULT;
483
484 left = volume & 0xff;
485 if (left > 100)
486 left = 100;
487 right = (volume >> 8) & 0xff;
488 if (right > 100)
489 right = 100;
490 *aleft = left;
491 *aright = right;
492 return 0;
493}
494
495static int ret_vol_mono(int left)
496{
497 return ((left << 8) | left);
498}
499
500static int ret_vol_stereo(int left, int right)
501{
502 return ((right << 8) | left);
503}
504
505static int call_ad_mixer(pss_confdata *devc,unsigned int cmd, void __user *arg)
506{
507 if (devc->ad_mixer_dev != NO_WSS_MIXER)
508 return mixer_devs[devc->ad_mixer_dev]->ioctl(devc->ad_mixer_dev, cmd, arg);
509 else
510 return -EINVAL;
511}
512
513static int pss_mixer_ioctl (int dev, unsigned int cmd, void __user *arg)
514{
515 pss_confdata *devc = mixer_devs[dev]->devc;
516 int cmdf = cmd & 0xff;
517
518 if ((cmdf != SOUND_MIXER_VOLUME) && (cmdf != SOUND_MIXER_BASS) &&
519 (cmdf != SOUND_MIXER_TREBLE) && (cmdf != SOUND_MIXER_SYNTH) &&
520 (cmdf != SOUND_MIXER_DEVMASK) && (cmdf != SOUND_MIXER_STEREODEVS) &&
521 (cmdf != SOUND_MIXER_RECMASK) && (cmdf != SOUND_MIXER_CAPS) &&
522 (cmdf != SOUND_MIXER_RECSRC))
523 {
524 return call_ad_mixer(devc, cmd, arg);
525 }
526
527 if (((cmd >> 8) & 0xff) != 'M')
528 return -EINVAL;
529
530 if (_SIOC_DIR (cmd) & _SIOC_WRITE)
531 {
532 switch (cmdf)
533 {
534 case SOUND_MIXER_RECSRC:
535 if (devc->ad_mixer_dev != NO_WSS_MIXER)
536 return call_ad_mixer(devc, cmd, arg);
537 else
538 {
539 int v;
540 if (get_user(v, (int __user *)arg))
541 return -EFAULT;
542 if (v != 0)
543 return -EINVAL;
544 return 0;
545 }
546 case SOUND_MIXER_VOLUME:
547 if (set_volume_stereo(arg,
548 &devc->mixer.volume_l,
549 &devc->mixer.volume_r))
550 return -EFAULT;
551 set_master_volume(devc, devc->mixer.volume_l,
552 devc->mixer.volume_r);
553 return ret_vol_stereo(devc->mixer.volume_l,
554 devc->mixer.volume_r);
555
556 case SOUND_MIXER_BASS:
557 if (set_volume_mono(arg, &devc->mixer.bass))
558 return -EFAULT;
559 set_bass(devc, devc->mixer.bass);
560 return ret_vol_mono(devc->mixer.bass);
561
562 case SOUND_MIXER_TREBLE:
563 if (set_volume_mono(arg, &devc->mixer.treble))
564 return -EFAULT;
565 set_treble(devc, devc->mixer.treble);
566 return ret_vol_mono(devc->mixer.treble);
567
568 case SOUND_MIXER_SYNTH:
569 if (set_volume_mono(arg, &devc->mixer.synth))
570 return -EFAULT;
571 set_synth_volume(devc, devc->mixer.synth);
572 return ret_vol_mono(devc->mixer.synth);
573
574 default:
575 return -EINVAL;
576 }
577 }
578 else
579 {
580 int val, and_mask = 0, or_mask = 0;
581 /*
582 * Return parameters
583 */
584 switch (cmdf)
585 {
586 case SOUND_MIXER_DEVMASK:
587 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
588 break;
589 and_mask = ~0;
590 or_mask = SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_SYNTH;
591 break;
592
593 case SOUND_MIXER_STEREODEVS:
594 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
595 break;
596 and_mask = ~0;
597 or_mask = SOUND_MASK_VOLUME;
598 break;
599
600 case SOUND_MIXER_RECMASK:
601 if (devc->ad_mixer_dev != NO_WSS_MIXER)
602 return call_ad_mixer(devc, cmd, arg);
603 break;
604
605 case SOUND_MIXER_CAPS:
606 if (devc->ad_mixer_dev != NO_WSS_MIXER)
607 return call_ad_mixer(devc, cmd, arg);
608 or_mask = SOUND_CAP_EXCL_INPUT;
609 break;
610
611 case SOUND_MIXER_RECSRC:
612 if (devc->ad_mixer_dev != NO_WSS_MIXER)
613 return call_ad_mixer(devc, cmd, arg);
614 break;
615
616 case SOUND_MIXER_VOLUME:
617 or_mask = ret_vol_stereo(devc->mixer.volume_l, devc->mixer.volume_r);
618 break;
619
620 case SOUND_MIXER_BASS:
621 or_mask = ret_vol_mono(devc->mixer.bass);
622 break;
623
624 case SOUND_MIXER_TREBLE:
625 or_mask = ret_vol_mono(devc->mixer.treble);
626 break;
627
628 case SOUND_MIXER_SYNTH:
629 or_mask = ret_vol_mono(devc->mixer.synth);
630 break;
631 default:
632 return -EINVAL;
633 }
634 if (get_user(val, (int __user *)arg))
635 return -EFAULT;
636 val &= and_mask;
637 val |= or_mask;
638 if (put_user(val, (int __user *)arg))
639 return -EFAULT;
640 return val;
641 }
642}
643
644static struct mixer_operations pss_mixer_operations =
645{
646 .owner = THIS_MODULE,
647 .id = "SOUNDPORT",
648 .name = "PSS-AD1848",
649 .ioctl = pss_mixer_ioctl
650};
651
652static void disable_all_emulations(void)
653{
654 outw(0x0000, REG(CONF_PSS)); /* 0x0400 enables joystick */
655 outw(0x0000, REG(CONF_WSS));
656 outw(0x0000, REG(CONF_SB));
657 outw(0x0000, REG(CONF_MIDI));
658 outw(0x0000, REG(CONF_CDROM));
659}
660
661static void configure_nonsound_components(void)
662{
663 /* Configure Joystick port */
664
665 if(pss_enable_joystick)
666 {
667 outw(0x0400, REG(CONF_PSS)); /* 0x0400 enables joystick */
668 printk(KERN_INFO "PSS: joystick enabled.\n");
669 }
670 else
671 {
672 printk(KERN_INFO "PSS: joystick port not enabled.\n");
673 }
674
675 /* Configure CDROM port */
676
677 if(pss_cdrom_port == -1) /* If cdrom port enablation wasn't requested */
678 {
679 printk(KERN_INFO "PSS: CDROM port not enabled.\n");
680 }
681 else if(check_region(pss_cdrom_port, 2))
682 {
683 printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
684 }
685 else if(!set_io_base(devc, CONF_CDROM, pss_cdrom_port))
686 {
687 printk(KERN_ERR "PSS: CDROM I/O port could not be set.\n");
688 }
689 else /* CDROM port successfully configured */
690 {
691 printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
692 }
693}
694
695static int __init attach_pss(struct address_info *hw_config)
696{
697 unsigned short id;
698 char tmp[100];
699
700 devc->base = hw_config->io_base;
701 devc->irq = hw_config->irq;
702 devc->dma = hw_config->dma;
703 devc->osp = hw_config->osp;
704 devc->ad_mixer_dev = NO_WSS_MIXER;
705
706 if (!probe_pss(hw_config))
707 return 0;
708
709 id = inw(REG(PSS_ID)) & 0x00ff;
710
711 /*
712 * Disable all emulations. Will be enabled later (if required).
713 */
714
715 disable_all_emulations();
716
717#if YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
718 if (sound_alloc_dma(hw_config->dma, "PSS"))
719 {
720 printk("pss.c: Can't allocate DMA channel.\n");
721 release_region(hw_config->io_base, 0x10);
722 release_region(hw_config->io_base+0x10, 0x9);
723 return 0;
724 }
725 if (!set_irq(devc, CONF_PSS, devc->irq))
726 {
727 printk("PSS: IRQ allocation error.\n");
728 release_region(hw_config->io_base, 0x10);
729 release_region(hw_config->io_base+0x10, 0x9);
730 return 0;
731 }
732 if (!set_dma(devc, CONF_PSS, devc->dma))
733 {
734 printk(KERN_ERR "PSS: DMA allocation error\n");
735 release_region(hw_config->io_base, 0x10);
736 release_region(hw_config->io_base+0x10, 0x9);
737 return 0;
738 }
739#endif
740
741 configure_nonsound_components();
742 pss_initialized = 1;
743 sprintf(tmp, "ECHO-PSS Rev. %d", id);
744 conf_printf(tmp, hw_config);
745 return 1;
746}
747
748static int __init probe_pss_mpu(struct address_info *hw_config)
749{
750 struct resource *ports;
751 int timeout;
752
753 if (!pss_initialized)
754 return 0;
755
756 ports = request_region(hw_config->io_base, 2, "mpu401");
757
758 if (!ports) {
759 printk(KERN_ERR "PSS: MPU I/O port conflict\n");
760 return 0;
761 }
762 if (!set_io_base(devc, CONF_MIDI, hw_config->io_base)) {
763 printk(KERN_ERR "PSS: MIDI base could not be set.\n");
764 goto fail;
765 }
766 if (!set_irq(devc, CONF_MIDI, hw_config->irq)) {
767 printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
768 goto fail;
769 }
770 if (!pss_synthLen) {
771 printk(KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
772 goto fail;
773 }
774 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
775 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
776 goto fail;
777 }
778
779 /*
780 * Finally wait until the DSP algorithm has initialized itself and
781 * deactivates receive interrupt.
782 */
783
784 for (timeout = 900000; timeout > 0; timeout--)
785 {
786 if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
787 inb(hw_config->io_base); /* Discard it */
788 else
789 break; /* No more input */
790 }
791
792 if (!probe_mpu401(hw_config, ports))
793 goto fail;
794
795 attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
796 if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
797 midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
798 return 1;
799fail:
800 release_region(hw_config->io_base, 2);
801 return 0;
802}
803
804static int pss_coproc_open(void *dev_info, int sub_device)
805{
806 switch (sub_device)
807 {
808 case COPR_MIDI:
809 if (pss_synthLen == 0)
810 {
811 printk(KERN_ERR "PSS: MIDI synth microcode not available.\n");
812 return -EIO;
813 }
814 if (nonstandard_microcode)
815 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
816 {
817 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
818 return -EIO;
819 }
820 nonstandard_microcode = 0;
821 break;
822
823 default:
824 break;
825 }
826 return 0;
827}
828
829static void pss_coproc_close(void *dev_info, int sub_device)
830{
831 return;
832}
833
834static void pss_coproc_reset(void *dev_info)
835{
836 if (pss_synthLen)
837 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
838 {
839 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
840 }
841 nonstandard_microcode = 0;
842}
843
844static int download_boot_block(void *dev_info, copr_buffer * buf)
845{
846 if (buf->len <= 0 || buf->len > sizeof(buf->data))
847 return -EINVAL;
848
849 if (!pss_download_boot(devc, buf->data, buf->len, buf->flags))
850 {
851 printk(KERN_ERR "PSS: Unable to load microcode block to DSP.\n");
852 return -EIO;
853 }
854 nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
855 return 0;
856}
857
858static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
859{
860 copr_buffer *buf;
861 copr_msg *mbuf;
862 copr_debug_buf dbuf;
863 unsigned short tmp;
864 unsigned long flags;
865 unsigned short *data;
866 int i, err;
867 /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
868
869 switch (cmd)
870 {
871 case SNDCTL_COPR_RESET:
872 pss_coproc_reset(dev_info);
873 return 0;
874
875 case SNDCTL_COPR_LOAD:
876 buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
877 if (buf == NULL)
878 return -ENOSPC;
879 if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
880 vfree(buf);
881 return -EFAULT;
882 }
883 err = download_boot_block(dev_info, buf);
884 vfree(buf);
885 return err;
886
887 case SNDCTL_COPR_SENDMSG:
888 mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
889 if (mbuf == NULL)
890 return -ENOSPC;
891 if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
892 vfree(mbuf);
893 return -EFAULT;
894 }
895 data = (unsigned short *)(mbuf->data);
896 spin_lock_irqsave(&lock, flags);
897 for (i = 0; i < mbuf->len; i++) {
898 if (!pss_put_dspword(devc, *data++)) {
899 spin_unlock_irqrestore(&lock,flags);
900 mbuf->len = i; /* feed back number of WORDs sent */
901 err = copy_to_user(arg, mbuf, sizeof(copr_msg));
902 vfree(mbuf);
903 return err ? -EFAULT : -EIO;
904 }
905 }
906 spin_unlock_irqrestore(&lock,flags);
907 vfree(mbuf);
908 return 0;
909
910 case SNDCTL_COPR_RCVMSG:
911 err = 0;
912 mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
913 if (mbuf == NULL)
914 return -ENOSPC;
915 data = (unsigned short *)mbuf->data;
916 spin_lock_irqsave(&lock, flags);
917 for (i = 0; i < sizeof(mbuf->data)/sizeof(unsigned short); i++) {
918 mbuf->len = i; /* feed back number of WORDs read */
919 if (!pss_get_dspword(devc, data++)) {
920 if (i == 0)
921 err = -EIO;
922 break;
923 }
924 }
925 spin_unlock_irqrestore(&lock,flags);
926 if (copy_to_user(arg, mbuf, sizeof(copr_msg)))
927 err = -EFAULT;
928 vfree(mbuf);
929 return err;
930
931 case SNDCTL_COPR_RDATA:
932 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
933 return -EFAULT;
934 spin_lock_irqsave(&lock, flags);
935 if (!pss_put_dspword(devc, 0x00d0)) {
936 spin_unlock_irqrestore(&lock,flags);
937 return -EIO;
938 }
939 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
940 spin_unlock_irqrestore(&lock,flags);
941 return -EIO;
942 }
943 if (!pss_get_dspword(devc, &tmp)) {
944 spin_unlock_irqrestore(&lock,flags);
945 return -EIO;
946 }
947 dbuf.parm1 = tmp;
948 spin_unlock_irqrestore(&lock,flags);
949 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
950 return -EFAULT;
951 return 0;
952
953 case SNDCTL_COPR_WDATA:
954 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
955 return -EFAULT;
956 spin_lock_irqsave(&lock, flags);
957 if (!pss_put_dspword(devc, 0x00d1)) {
958 spin_unlock_irqrestore(&lock,flags);
959 return -EIO;
960 }
961 if (!pss_put_dspword(devc, (unsigned short) (dbuf.parm1 & 0xffff))) {
962 spin_unlock_irqrestore(&lock,flags);
963 return -EIO;
964 }
965 tmp = (unsigned int)dbuf.parm2 & 0xffff;
966 if (!pss_put_dspword(devc, tmp)) {
967 spin_unlock_irqrestore(&lock,flags);
968 return -EIO;
969 }
970 spin_unlock_irqrestore(&lock,flags);
971 return 0;
972
973 case SNDCTL_COPR_WCODE:
974 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
975 return -EFAULT;
976 spin_lock_irqsave(&lock, flags);
977 if (!pss_put_dspword(devc, 0x00d3)) {
978 spin_unlock_irqrestore(&lock,flags);
979 return -EIO;
980 }
981 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
982 spin_unlock_irqrestore(&lock,flags);
983 return -EIO;
984 }
985 tmp = (unsigned int)dbuf.parm2 & 0x00ff;
986 if (!pss_put_dspword(devc, tmp)) {
987 spin_unlock_irqrestore(&lock,flags);
988 return -EIO;
989 }
990 tmp = ((unsigned int)dbuf.parm2 >> 8) & 0xffff;
991 if (!pss_put_dspword(devc, tmp)) {
992 spin_unlock_irqrestore(&lock,flags);
993 return -EIO;
994 }
995 spin_unlock_irqrestore(&lock,flags);
996 return 0;
997
998 case SNDCTL_COPR_RCODE:
999 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
1000 return -EFAULT;
1001 spin_lock_irqsave(&lock, flags);
1002 if (!pss_put_dspword(devc, 0x00d2)) {
1003 spin_unlock_irqrestore(&lock,flags);
1004 return -EIO;
1005 }
1006 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
1007 spin_unlock_irqrestore(&lock,flags);
1008 return -EIO;
1009 }
1010 if (!pss_get_dspword(devc, &tmp)) { /* Read MSB */
1011 spin_unlock_irqrestore(&lock,flags);
1012 return -EIO;
1013 }
1014 dbuf.parm1 = tmp << 8;
1015 if (!pss_get_dspword(devc, &tmp)) { /* Read LSB */
1016 spin_unlock_irqrestore(&lock,flags);
1017 return -EIO;
1018 }
1019 dbuf.parm1 |= tmp & 0x00ff;
1020 spin_unlock_irqrestore(&lock,flags);
1021 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
1022 return -EFAULT;
1023 return 0;
1024
1025 default:
1026 return -EINVAL;
1027 }
1028 return -EINVAL;
1029}
1030
1031static coproc_operations pss_coproc_operations =
1032{
1033 "ADSP-2115",
1034 THIS_MODULE,
1035 pss_coproc_open,
1036 pss_coproc_close,
1037 pss_coproc_ioctl,
1038 pss_coproc_reset,
1039 &pss_data
1040};
1041
1042static int __init probe_pss_mss(struct address_info *hw_config)
1043{
1044 volatile int timeout;
1045 struct resource *ports;
1046 int my_mix = -999; /* gcc shut up */
1047
1048 if (!pss_initialized)
1049 return 0;
1050
1051 if (!request_region(hw_config->io_base, 4, "WSS config")) {
1052 printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
1053 return 0;
1054 }
1055 ports = request_region(hw_config->io_base + 4, 4, "ad1848");
1056 if (!ports) {
1057 printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
1058 release_region(hw_config->io_base, 4);
1059 return 0;
1060 }
1061 if (!set_io_base(devc, CONF_WSS, hw_config->io_base)) {
1062 printk("PSS: WSS base not settable.\n");
1063 goto fail;
1064 }
1065 if (!set_irq(devc, CONF_WSS, hw_config->irq)) {
1066 printk("PSS: WSS IRQ allocation error.\n");
1067 goto fail;
1068 }
1069 if (!set_dma(devc, CONF_WSS, hw_config->dma)) {
1070 printk(KERN_ERR "PSS: WSS DMA allocation error\n");
1071 goto fail;
1072 }
1073 /*
1074 * For some reason the card returns 0xff in the WSS status register
1075 * immediately after boot. Probably MIDI+SB emulation algorithm
1076 * downloaded to the ADSP2115 spends some time initializing the card.
1077 * Let's try to wait until it finishes this task.
1078 */
1079 for (timeout = 0; timeout < 100000 && (inb(hw_config->io_base + WSS_INDEX) &
1080 WSS_INITIALIZING); timeout++)
1081 ;
1082
1083 outb((0x0b), hw_config->io_base + WSS_INDEX); /* Required by some cards */
1084
1085 for (timeout = 0; (inb(hw_config->io_base + WSS_DATA) & WSS_AUTOCALIBRATION) &&
1086 (timeout < 100000); timeout++)
1087 ;
1088
1089 if (!probe_ms_sound(hw_config, ports))
1090 goto fail;
1091
1092 devc->ad_mixer_dev = NO_WSS_MIXER;
1093 if (pss_mixer)
1094 {
1095 if ((my_mix = sound_install_mixer (MIXER_DRIVER_VERSION,
1096 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
1097 &pss_mixer_operations,
1098 sizeof (struct mixer_operations),
1099 devc)) < 0)
1100 {
1101 printk(KERN_ERR "Could not install PSS mixer\n");
1102 goto fail;
1103 }
1104 }
1105 pss_mixer_reset(devc);
1106 attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
1107
1108 if (hw_config->slots[0] != -1)
1109 {
1110 /* The MSS driver installed itself */
1111 audio_devs[hw_config->slots[0]]->coproc = &pss_coproc_operations;
1112 if (pss_mixer && (num_mixers == (my_mix + 2)))
1113 {
1114 /* The MSS mixer installed */
1115 devc->ad_mixer_dev = audio_devs[hw_config->slots[0]]->mixer_dev;
1116 }
1117 }
1118 return 1;
1119fail:
1120 release_region(hw_config->io_base + 4, 4);
1121 release_region(hw_config->io_base, 4);
1122 return 0;
1123}
1124
1125static inline void __exit unload_pss(struct address_info *hw_config)
1126{
1127 release_region(hw_config->io_base, 0x10);
1128 release_region(hw_config->io_base+0x10, 0x9);
1129}
1130
1131static inline void __exit unload_pss_mpu(struct address_info *hw_config)
1132{
1133 unload_mpu401(hw_config);
1134}
1135
1136static inline void __exit unload_pss_mss(struct address_info *hw_config)
1137{
1138 unload_ms_sound(hw_config);
1139}
1140
1141
1142static struct address_info cfg;
1143static struct address_info cfg2;
1144static struct address_info cfg_mpu;
1145
1146static int pss_io __initdata = -1;
1147static int mss_io __initdata = -1;
1148static int mss_irq __initdata = -1;
1149static int mss_dma __initdata = -1;
1150static int mpu_io __initdata = -1;
1151static int mpu_irq __initdata = -1;
1152static int pss_no_sound = 0; /* Just configure non-sound components */
1153static int pss_keep_settings = 1; /* Keep hardware settings at module exit */
1154static char *pss_firmware = "/etc/sound/pss_synth";
1155
1156module_param(pss_io, int, 0);
1157MODULE_PARM_DESC(pss_io, "Set i/o base of PSS card (probably 0x220 or 0x240)");
1158module_param(mss_io, int, 0);
1159MODULE_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)");
1160module_param(mss_irq, int, 0);
1161MODULE_PARM_DESC(mss_irq, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
1162module_param(mss_dma, int, 0);
1163MODULE_PARM_DESC(mss_dma, "Set WSS (audio) DMA (0, 1, 3)");
1164module_param(mpu_io, int, 0);
1165MODULE_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)");
1166module_param(mpu_irq, int, 0);
1167MODULE_PARM_DESC(mpu_irq, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
1168module_param(pss_cdrom_port, int, 0);
1169MODULE_PARM_DESC(pss_cdrom_port, "Set the PSS CDROM port i/o base (0x340 or other)");
1170module_param(pss_enable_joystick, bool, 0);
1171MODULE_PARM_DESC(pss_enable_joystick, "Enables the PSS joystick port (1 to enable, 0 to disable)");
1172module_param(pss_no_sound, bool, 0);
1173MODULE_PARM_DESC(pss_no_sound, "Configure sound compoents (0 - no, 1 - yes)");
1174module_param(pss_keep_settings, bool, 0);
1175MODULE_PARM_DESC(pss_keep_settings, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
1176module_param(pss_firmware, charp, 0);
1177MODULE_PARM_DESC(pss_firmware, "Location of the firmware file (default - /etc/sound/pss_synth)");
1178module_param(pss_mixer, bool, 0);
1179MODULE_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.");
1180MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
1181MODULE_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).");
1182MODULE_LICENSE("GPL");
1183
1184
1185static int fw_load = 0;
1186static int pssmpu = 0, pssmss = 0;
1187
1188/*
1189 * Load a PSS sound card module
1190 */
1191
1192static int __init init_pss(void)
1193{
1194
1195 if(pss_no_sound) /* If configuring only nonsound components */
1196 {
1197 cfg.io_base = pss_io;
1198 if(!probe_pss(&cfg))
1199 return -ENODEV;
1200 printk(KERN_INFO "ECHO-PSS Rev. %d\n", inw(REG(PSS_ID)) & 0x00ff);
1201 printk(KERN_INFO "PSS: loading in no sound mode.\n");
1202 disable_all_emulations();
1203 configure_nonsound_components();
1204 release_region(pss_io, 0x10);
1205 release_region(pss_io + 0x10, 0x9);
1206 return 0;
1207 }
1208
1209 cfg.io_base = pss_io;
1210
1211 cfg2.io_base = mss_io;
1212 cfg2.irq = mss_irq;
1213 cfg2.dma = mss_dma;
1214
1215 cfg_mpu.io_base = mpu_io;
1216 cfg_mpu.irq = mpu_irq;
1217
1218 if (cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 || cfg.dma == -1) {
1219 printk(KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1220 return -EINVAL;
1221 }
1222
1223 if (!pss_synth) {
1224 fw_load = 1;
1225 pss_synthLen = mod_firmware_load(pss_firmware, (void *) &pss_synth);
1226 }
1227 if (!attach_pss(&cfg))
1228 return -ENODEV;
1229 /*
1230 * Attach stuff
1231 */
1232 if (probe_pss_mpu(&cfg_mpu))
1233 pssmpu = 1;
1234
1235 if (probe_pss_mss(&cfg2))
1236 pssmss = 1;
1237
1238 return 0;
1239}
1240
1241static void __exit cleanup_pss(void)
1242{
1243 if(!pss_no_sound)
1244 {
1245 if(fw_load && pss_synth)
1246 vfree(pss_synth);
1247 if(pssmss)
1248 unload_pss_mss(&cfg2);
1249 if(pssmpu)
1250 unload_pss_mpu(&cfg_mpu);
1251 unload_pss(&cfg);
1252 }
1253
1254 if(!pss_keep_settings) /* Keep hardware settings if asked */
1255 {
1256 disable_all_emulations();
1257 printk(KERN_INFO "Resetting PSS sound card configurations.\n");
1258 }
1259}
1260
1261module_init(init_pss);
1262module_exit(cleanup_pss);
1263
1264#ifndef MODULE
1265static int __init setup_pss(char *str)
1266{
1267 /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
1268 int ints[7];
1269
1270 str = get_options(str, ARRAY_SIZE(ints), ints);
1271
1272 pss_io = ints[1];
1273 mss_io = ints[2];
1274 mss_irq = ints[3];
1275 mss_dma = ints[4];
1276 mpu_io = ints[5];
1277 mpu_irq = ints[6];
1278
1279 return 1;
1280}
1281
1282__setup("pss=", setup_pss);
1283#endif
diff --git a/sound/oss/rme96xx.c b/sound/oss/rme96xx.c
new file mode 100644
index 000000000000..76774bbc1436
--- /dev/null
+++ b/sound/oss/rme96xx.c
@@ -0,0 +1,1861 @@
1/* (C) 2000 Guenter Geiger <geiger@debian.org>
2 with copy/pastes from the driver of Winfried Ritsch <ritsch@iem.kug.ac.at>
3 based on es1370.c
4
5
6
7 * 10 Jan 2001: 0.1 initial version
8 * 19 Jan 2001: 0.2 fixed bug in select()
9 * 27 Apr 2001: 0.3 more than one card usable
10 * 11 May 2001: 0.4 fixed for SMP, included into kernel source tree
11 * 17 May 2001: 0.5 draining code didn't work on new cards
12 * 18 May 2001: 0.6 remove synchronize_irq() call
13 * 17 Jul 2001: 0.7 updated xrmectrl to make it work for newer cards
14 * 2 feb 2002: 0.8 fixed pci device handling, see below for patches from Heiko (Thanks!)
15 Marcus Meissner <Marcus.Meissner@caldera.de>
16
17 Modifications - Heiko Purnhagen <purnhage@tnt.uni-hannover.de>
18 HP20020108 fixed handling of "large" read()
19 HP20020116 towards REV 1.5 support, based on ALSA's card-rme9652.c
20 HP20020118 made mixer ioctl and handling of devices>1 more safe
21 HP20020201 fixed handling of "large" read() properly
22 added REV 1.5 S/P-DIF receiver support
23 SNDCTL_DSP_SPEED now returns the actual speed
24 * 10 Aug 2002: added synchronize_irq() again
25
26TODO:
27 - test more than one card --- done
28 - check for pci IOREGION (see es1370) in rme96xx_probe ??
29 - error detection
30 - mmap interface
31 - mixer mmap interface
32 - mixer ioctl
33 - get rid of noise upon first open (why ??)
34 - allow multiple open (at least for read)
35 - allow multiple open for non overlapping regions
36 - recheck the multiple devices part (offsets of different devices, etc)
37 - do decent draining in _release --- done
38 - SMP support
39 - what about using fragstotal>2 for small fragsize? (HP20020118)
40 - add support for AFMT_S32_LE
41*/
42
43#ifndef RMEVERSION
44#define RMEVERSION "0.8"
45#endif
46
47#include <linux/version.h>
48#include <linux/module.h>
49#include <linux/string.h>
50#include <linux/sched.h>
51#include <linux/sound.h>
52#include <linux/soundcard.h>
53#include <linux/pci.h>
54#include <linux/smp_lock.h>
55#include <linux/delay.h>
56#include <linux/slab.h>
57#include <linux/interrupt.h>
58#include <linux/init.h>
59#include <linux/interrupt.h>
60#include <linux/poll.h>
61#include <linux/wait.h>
62
63#include <asm/dma.h>
64#include <asm/page.h>
65
66#include "rme96xx.h"
67
68#define NR_DEVICE 2
69
70static int devices = 1;
71module_param(devices, int, 0);
72MODULE_PARM_DESC(devices, "number of dsp devices allocated by the driver");
73
74
75MODULE_AUTHOR("Guenter Geiger, geiger@debian.org");
76MODULE_DESCRIPTION("RME9652/36 \"Hammerfall\" Driver");
77MODULE_LICENSE("GPL");
78
79
80#ifdef DEBUG
81#define DBG(x) printk("RME_DEBUG:");x
82#define COMM(x) printk("RME_COMM: " x "\n");
83#else
84#define DBG(x) while (0) {}
85#define COMM(x)
86#endif
87
88/*--------------------------------------------------------------------------
89 Preporcessor Macros and Definitions
90 --------------------------------------------------------------------------*/
91
92#define RME96xx_MAGIC 0x6473
93
94/* Registers-Space in offsets from base address with 16MByte size */
95
96#define RME96xx_IO_EXTENT 16l*1024l*1024l
97#define RME96xx_CHANNELS_PER_CARD 26
98
99/* Write - Register */
100
101/* 0,4,8,12,16,20,24,28 ... hardware init (erasing fifo-pointer intern) */
102#define RME96xx_num_of_init_regs 8
103
104#define RME96xx_init_buffer (0/4)
105#define RME96xx_play_buffer (32/4) /* pointer to 26x64kBit RAM from mainboard */
106#define RME96xx_rec_buffer (36/4) /* pointer to 26x64kBit RAM from mainboard */
107#define RME96xx_control_register (64/4) /* exact meaning see below */
108#define RME96xx_irq_clear (96/4) /* irq acknowledge */
109#define RME96xx_time_code (100/4) /* if used with alesis adat */
110#define RME96xx_thru_base (128/4) /* 132...228 Thru for 26 channels */
111#define RME96xx_thru_channels RME96xx_CHANNELS_PER_CARD
112
113/* Read Register */
114
115#define RME96xx_status_register 0 /* meaning see below */
116
117
118
119/* Status Register: */
120/* ------------------------------------------------------------------------ */
121#define RME96xx_IRQ 0x0000001 /* IRQ is High if not reset by RMExx_irq_clear */
122#define RME96xx_lock_2 0x0000002 /* ADAT 3-PLL: 1=locked, 0=unlocked */
123#define RME96xx_lock_1 0x0000004 /* ADAT 2-PLL: 1=locked, 0=unlocked */
124#define RME96xx_lock_0 0x0000008 /* ADAT 1-PLL: 1=locked, 0=unlocked */
125
126#define RME96xx_fs48 0x0000010 /* sample rate 0 ...44.1/88.2, 1 ... 48/96 Khz */
127#define RME96xx_wsel_rd 0x0000020 /* if Word-Clock is used and valid then 1 */
128#define RME96xx_buf_pos1 0x0000040 /* Bit 6..15 : Position of buffer-pointer in 64Bytes-blocks */
129#define RME96xx_buf_pos2 0x0000080 /* resolution +/- 1 64Byte/block (since 64Bytes bursts) */
130
131#define RME96xx_buf_pos3 0x0000100 /* 10 bits = 1024 values */
132#define RME96xx_buf_pos4 0x0000200 /* if we mask off the first 6 bits, we can take the status */
133#define RME96xx_buf_pos5 0x0000400 /* register as sample counter in the hardware buffer */
134#define RME96xx_buf_pos6 0x0000800
135
136#define RME96xx_buf_pos7 0x0001000
137#define RME96xx_buf_pos8 0x0002000
138#define RME96xx_buf_pos9 0x0004000
139#define RME96xx_buf_pos10 0x0008000
140
141#define RME96xx_sync_2 0x0010000 /* if ADAT-IN3 synced to system clock */
142#define RME96xx_sync_1 0x0020000 /* if ADAT-IN2 synced to system clock */
143#define RME96xx_sync_0 0x0040000 /* if ADAT-IN1 synced to system clock */
144#define RME96xx_DS_rd 0x0080000 /* 1=Double Speed, 0=Normal Speed */
145
146#define RME96xx_tc_busy 0x0100000 /* 1=time-code copy in progress (960ms) */
147#define RME96xx_tc_out 0x0200000 /* time-code out bit */
148#define RME96xx_F_0 0x0400000 /* 000=64kHz, 100=88.2kHz, 011=96kHz */
149#define RME96xx_F_1 0x0800000 /* 111=32kHz, 110=44.1kHz, 101=48kHz, */
150
151#define RME96xx_F_2 0x1000000 /* 001=Rev 1.5+ external Crystal Chip */
152#define RME96xx_ERF 0x2000000 /* Error-Flag of SDPIF Receiver (1=No Lock)*/
153#define RME96xx_buffer_id 0x4000000 /* toggles by each interrupt on rec/play */
154#define RME96xx_tc_valid 0x8000000 /* 1 = a signal is detected on time-code input */
155#define RME96xx_SPDIF_READ 0x10000000 /* byte available from Rev 1.5+ SPDIF interface */
156
157/* Status Register Fields */
158
159#define RME96xx_lock (RME96xx_lock_0|RME96xx_lock_1|RME96xx_lock_2)
160#define RME96xx_sync (RME96xx_sync_0|RME96xx_sync_1|RME96xx_sync_2)
161#define RME96xx_F (RME96xx_F_0|RME96xx_F_1|RME96xx_F_2)
162#define rme96xx_decode_spdif_rate(x) ((x)>>22)
163
164/* Bit 6..15 : h/w buffer pointer */
165#define RME96xx_buf_pos 0x000FFC0
166/* Bits 31,30,29 are bits 5,4,3 of h/w pointer position on later
167 Rev G EEPROMS and Rev 1.5 cards or later.
168*/
169#define RME96xx_REV15_buf_pos(x) ((((x)&0xE0000000)>>26)|((x)&RME96xx_buf_pos))
170
171
172/* Control-Register: */
173/*--------------------------------------------------------------------------------*/
174
175#define RME96xx_start_bit 0x0001 /* start record/play */
176#define RME96xx_latency0 0x0002 /* Buffer size / latency */
177#define RME96xx_latency1 0x0004 /* buffersize = 512Bytes * 2^n */
178#define RME96xx_latency2 0x0008 /* 0=64samples ... 7=8192samples */
179
180#define RME96xx_Master 0x0010 /* Clock Mode 1=Master, 0=Slave/Auto */
181#define RME96xx_IE 0x0020 /* Interupt Enable */
182#define RME96xx_freq 0x0040 /* samplerate 0=44.1/88.2, 1=48/96 kHz*/
183#define RME96xx_freq1 0x0080 /* samplerate 0=32 kHz, 1=other rates ??? (from ALSA, but may be wrong) */
184#define RME96xx_DS 0x0100 /* double speed 0=44.1/48, 1=88.2/96 Khz */
185#define RME96xx_PRO 0x0200 /* SPDIF-OUT 0=consumer, 1=professional */
186#define RME96xx_EMP 0x0400 /* SPDIF-OUT emphasis 0=off, 1=on */
187#define RME96xx_Dolby 0x0800 /* SPDIF-OUT non-audio bit 1=set, 0=unset */
188
189#define RME96xx_opt_out 0x1000 /* use 1st optical OUT as SPDIF: 1=yes, 0=no */
190#define RME96xx_wsel 0x2000 /* use Wordclock as sync (overwrites master) */
191#define RME96xx_inp_0 0x4000 /* SPDIF-IN 00=optical (ADAT1), */
192#define RME96xx_inp_1 0x8000 /* 01=coaxial (Cinch), 10=internal CDROM */
193
194#define RME96xx_SyncRef0 0x10000 /* preferred sync-source in autosync */
195#define RME96xx_SyncRef1 0x20000 /* 00=ADAT1, 01=ADAT2, 10=ADAT3, 11=SPDIF */
196
197#define RME96xx_SPDIF_RESET (1<<18) /* Rev 1.5+: h/w SPDIF receiver */
198#define RME96xx_SPDIF_SELECT (1<<19)
199#define RME96xx_SPDIF_CLOCK (1<<20)
200#define RME96xx_SPDIF_WRITE (1<<21)
201#define RME96xx_ADAT1_INTERNAL (1<<22) /* Rev 1.5+: if set, internal CD connector carries ADAT */
202
203
204#define RME96xx_ctrl_init (RME96xx_latency0 |\
205 RME96xx_Master |\
206 RME96xx_inp_1)
207
208
209
210/* Control register fields and shortcuts */
211
212#define RME96xx_latency (RME96xx_latency0|RME96xx_latency1|RME96xx_latency2)
213#define RME96xx_inp (RME96xx_inp_0|RME96xx_inp_1)
214#define RME96xx_SyncRef (RME96xx_SyncRef0|RME96xx_SyncRef1)
215#define RME96xx_mixer_allowed (RME96xx_Master|RME96xx_PRO|RME96xx_EMP|RME96xx_Dolby|RME96xx_opt_out|RME96xx_wsel|RME96xx_inp|RME96xx_SyncRef|RME96xx_ADAT1_INTERNAL)
216
217/* latency = 512Bytes * 2^n, where n is made from Bit3 ... Bit1 (??? HP20020201) */
218
219#define RME96xx_SET_LATENCY(x) (((x)&0x7)<<1)
220#define RME96xx_GET_LATENCY(x) (((x)>>1)&0x7)
221#define RME96xx_SET_inp(x) (((x)&0x3)<<14)
222#define RME96xx_GET_inp(x) (((x)>>14)&0x3)
223#define RME96xx_SET_SyncRef(x) (((x)&0x3)<<17)
224#define RME96xx_GET_SyncRef(x) (((x)>>17)&0x3)
225
226
227/* buffer sizes */
228#define RME96xx_BYTES_PER_SAMPLE 4 /* sizeof(u32) */
229#define RME_16K 16*1024
230
231#define RME96xx_DMA_MAX_SAMPLES (RME_16K)
232#define RME96xx_DMA_MAX_SIZE (RME_16K * RME96xx_BYTES_PER_SAMPLE)
233#define RME96xx_DMA_MAX_SIZE_ALL (RME96xx_DMA_MAX_SIZE * RME96xx_CHANNELS_PER_CARD)
234
235#define RME96xx_NUM_OF_FRAGMENTS 2
236#define RME96xx_FRAGMENT_MAX_SIZE (RME96xx_DMA_MAX_SIZE/2)
237#define RME96xx_FRAGMENT_MAX_SAMPLES (RME96xx_DMA_MAX_SAMPLES/2)
238#define RME96xx_MAX_LATENCY 7 /* 16k samples */
239
240
241#define RME96xx_MAX_DEVS 4 /* we provide some OSS stereodevs */
242#define RME96xx_MASK_DEVS 0x3 /* RME96xx_MAX_DEVS-1 */
243
244#define RME_MESS "rme96xx:"
245/*------------------------------------------------------------------------
246 Types, struct and function declarations
247 ------------------------------------------------------------------------*/
248
249
250/* --------------------------------------------------------------------- */
251
252static const char invalid_magic[] = KERN_CRIT RME_MESS" invalid magic value\n";
253
254#define VALIDATE_STATE(s) \
255({ \
256 if (!(s) || (s)->magic != RME96xx_MAGIC) { \
257 printk(invalid_magic); \
258 return -ENXIO; \
259 } \
260})
261
262/* --------------------------------------------------------------------- */
263
264
265static struct file_operations rme96xx_audio_fops;
266static struct file_operations rme96xx_mixer_fops;
267static int numcards;
268
269typedef int32_t raw_sample_t;
270
271typedef struct _rme96xx_info {
272
273 /* hardware settings */
274 int magic;
275 struct pci_dev * pcidev; /* pci_dev structure */
276 unsigned long __iomem *iobase;
277 unsigned int irq;
278
279 /* list of rme96xx devices */
280 struct list_head devs;
281
282 spinlock_t lock;
283
284 u32 *recbuf; /* memory for rec buffer */
285 u32 *playbuf; /* memory for play buffer */
286
287 u32 control_register;
288
289 u32 thru_bits; /* thru 1=on, 0=off channel 1=Bit1... channel 26= Bit26 */
290
291 int hw_rev; /* h/w rev * 10 (i.e. 1.5 has hw_rev = 15) */
292 char *card_name; /* hammerfall or hammerfall light names */
293
294 int open_count; /* unused ??? HP20020201 */
295
296 int rate;
297 int latency;
298 unsigned int fragsize;
299 int started;
300
301 int hwptr; /* can be negativ because of pci burst offset */
302 unsigned int hwbufid; /* set by interrupt, buffer which is written/read now */
303
304 struct dmabuf {
305
306 unsigned int format;
307 int formatshift;
308 int inchannels; /* number of channels for device */
309 int outchannels; /* number of channels for device */
310 int mono; /* if true, we play mono on 2 channels */
311 int inoffset; /* which channel is considered the first one */
312 int outoffset;
313
314 /* state */
315 int opened; /* open() made */
316 int started; /* first write/read */
317 int mmapped; /* mmap */
318 int open_mode;
319
320 struct _rme96xx_info *s;
321
322 /* pointer to read/write position in buffer */
323 unsigned readptr;
324 unsigned writeptr;
325
326 unsigned error; /* over/underruns cleared on sync again */
327
328 /* waiting and locking */
329 wait_queue_head_t wait;
330 struct semaphore open_sem;
331 wait_queue_head_t open_wait;
332
333 } dma[RME96xx_MAX_DEVS];
334
335 int dspnum[RME96xx_MAX_DEVS]; /* register with sound subsystem */
336 int mixer; /* register with sound subsystem */
337} rme96xx_info;
338
339
340/* fiddling with the card (first level hardware control) */
341
342static inline void rme96xx_set_ctrl(rme96xx_info* s,int mask)
343{
344
345 s->control_register|=mask;
346 writel(s->control_register,s->iobase + RME96xx_control_register);
347
348}
349
350static inline void rme96xx_unset_ctrl(rme96xx_info* s,int mask)
351{
352
353 s->control_register&=(~mask);
354 writel(s->control_register,s->iobase + RME96xx_control_register);
355
356}
357
358static inline int rme96xx_get_sample_rate_status(rme96xx_info* s)
359{
360 int val;
361 u32 status;
362 status = readl(s->iobase + RME96xx_status_register);
363 val = (status & RME96xx_fs48) ? 48000 : 44100;
364 if (status & RME96xx_DS_rd)
365 val *= 2;
366 return val;
367}
368
369static inline int rme96xx_get_sample_rate_ctrl(rme96xx_info* s)
370{
371 int val;
372 val = (s->control_register & RME96xx_freq) ? 48000 : 44100;
373 if (s->control_register & RME96xx_DS)
374 val *= 2;
375 return val;
376}
377
378
379/* code from ALSA card-rme9652.c for rev 1.5 SPDIF receiver HP 20020201 */
380
381static void rme96xx_spdif_set_bit (rme96xx_info* s, int mask, int onoff)
382{
383 if (onoff)
384 s->control_register |= mask;
385 else
386 s->control_register &= ~mask;
387
388 writel(s->control_register,s->iobase + RME96xx_control_register);
389}
390
391static void rme96xx_spdif_write_byte (rme96xx_info* s, const int val)
392{
393 long mask;
394 long i;
395
396 for (i = 0, mask = 0x80; i < 8; i++, mask >>= 1) {
397 if (val & mask)
398 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_WRITE, 1);
399 else
400 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_WRITE, 0);
401
402 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_CLOCK, 1);
403 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_CLOCK, 0);
404 }
405}
406
407static int rme96xx_spdif_read_byte (rme96xx_info* s)
408{
409 long mask;
410 long val;
411 long i;
412
413 val = 0;
414
415 for (i = 0, mask = 0x80; i < 8; i++, mask >>= 1) {
416 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_CLOCK, 1);
417 if (readl(s->iobase + RME96xx_status_register) & RME96xx_SPDIF_READ)
418 val |= mask;
419 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_CLOCK, 0);
420 }
421
422 return val;
423}
424
425static void rme96xx_write_spdif_codec (rme96xx_info* s, const int address, const int data)
426{
427 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_SELECT, 1);
428 rme96xx_spdif_write_byte (s, 0x20);
429 rme96xx_spdif_write_byte (s, address);
430 rme96xx_spdif_write_byte (s, data);
431 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_SELECT, 0);
432}
433
434
435static int rme96xx_spdif_read_codec (rme96xx_info* s, const int address)
436{
437 int ret;
438
439 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_SELECT, 1);
440 rme96xx_spdif_write_byte (s, 0x20);
441 rme96xx_spdif_write_byte (s, address);
442 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_SELECT, 0);
443 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_SELECT, 1);
444
445 rme96xx_spdif_write_byte (s, 0x21);
446 ret = rme96xx_spdif_read_byte (s);
447 rme96xx_spdif_set_bit (s, RME96xx_SPDIF_SELECT, 0);
448
449 return ret;
450}
451
452static void rme96xx_initialize_spdif_receiver (rme96xx_info* s)
453{
454 /* XXX what unsets this ? */
455 /* no idea ??? HP 20020201 */
456
457 s->control_register |= RME96xx_SPDIF_RESET;
458
459 rme96xx_write_spdif_codec (s, 4, 0x40);
460 rme96xx_write_spdif_codec (s, 17, 0x13);
461 rme96xx_write_spdif_codec (s, 6, 0x02);
462}
463
464static inline int rme96xx_spdif_sample_rate (rme96xx_info *s, int *spdifrate)
465{
466 unsigned int rate_bits;
467
468 *spdifrate = 0x1;
469 if (readl(s->iobase + RME96xx_status_register) & RME96xx_ERF) {
470 return -1; /* error condition */
471 }
472
473 if (s->hw_rev == 15) {
474
475 int x, y, ret;
476
477 x = rme96xx_spdif_read_codec (s, 30);
478
479 if (x != 0)
480 y = 48000 * 64 / x;
481 else
482 y = 0;
483
484 if (y > 30400 && y < 33600) {ret = 32000; *spdifrate = 0x7;}
485 else if (y > 41900 && y < 46000) {ret = 44100; *spdifrate = 0x6;}
486 else if (y > 46000 && y < 50400) {ret = 48000; *spdifrate = 0x5;}
487 else if (y > 60800 && y < 67200) {ret = 64000; *spdifrate = 0x0;}
488 else if (y > 83700 && y < 92000) {ret = 88200; *spdifrate = 0x4;}
489 else if (y > 92000 && y < 100000) {ret = 96000; *spdifrate = 0x3;}
490 else {ret = 0; *spdifrate = 0x1;}
491 return ret;
492 }
493
494 rate_bits = readl(s->iobase + RME96xx_status_register) & RME96xx_F;
495
496 switch (*spdifrate = rme96xx_decode_spdif_rate(rate_bits)) {
497 case 0x7:
498 return 32000;
499 break;
500
501 case 0x6:
502 return 44100;
503 break;
504
505 case 0x5:
506 return 48000;
507 break;
508
509 case 0x4:
510 return 88200;
511 break;
512
513 case 0x3:
514 return 96000;
515 break;
516
517 case 0x0:
518 return 64000;
519 break;
520
521 default:
522 /* was an ALSA warning ...
523 snd_printk("%s: unknown S/PDIF input rate (bits = 0x%x)\n",
524 s->card_name, rate_bits);
525 */
526 return 0;
527 break;
528 }
529}
530
531/* end of code from ALSA card-rme9652.c */
532
533
534
535/* the hwbuf in the status register seems to have some jitter, to get rid of
536 it, we first only let the numbers grow, to be on the secure side we
537 subtract a certain amount RME96xx_BURSTBYTES from the resulting number */
538
539/* the function returns the hardware pointer in bytes */
540#define RME96xx_BURSTBYTES -64 /* bytes by which hwptr could be off */
541
542static inline int rme96xx_gethwptr(rme96xx_info* s,int exact)
543{
544 unsigned long flags;
545 if (exact) {
546 unsigned int hwp;
547/* the hwptr seems to be rather unreliable :(, so we don't use it */
548 spin_lock_irqsave(&s->lock,flags);
549
550 hwp = readl(s->iobase + RME96xx_status_register) & 0xffc0;
551 s->hwptr = (hwp < s->hwptr) ? s->hwptr : hwp;
552// s->hwptr = hwp;
553
554 spin_unlock_irqrestore(&s->lock,flags);
555 return (s->hwptr+RME96xx_BURSTBYTES) & ((s->fragsize<<1)-1);
556 }
557 return (s->hwbufid ? s->fragsize : 0);
558}
559
560static inline void rme96xx_setlatency(rme96xx_info* s,int l)
561{
562 s->latency = l;
563 s->fragsize = 1<<(8+l);
564 rme96xx_unset_ctrl(s,RME96xx_latency);
565 rme96xx_set_ctrl(s,RME96xx_SET_LATENCY(l));
566}
567
568
569static void rme96xx_clearbufs(struct dmabuf* dma)
570{
571 int i,j;
572 unsigned long flags;
573
574 /* clear dmabufs */
575 for(i=0;i<devices;i++) {
576 for (j=0;j<dma->outchannels + dma->mono;j++)
577 memset(&dma->s->playbuf[(dma->outoffset + j)*RME96xx_DMA_MAX_SAMPLES],
578 0, RME96xx_DMA_MAX_SIZE);
579 }
580 spin_lock_irqsave(&dma->s->lock,flags);
581 dma->writeptr = 0;
582 dma->readptr = 0;
583 spin_unlock_irqrestore(&dma->s->lock,flags);
584}
585
586static int rme96xx_startcard(rme96xx_info *s,int stop)
587{
588 int i;
589 unsigned long flags;
590
591 COMM ("startcard");
592 if(s->control_register & RME96xx_IE){
593 /* disable interrupt first */
594
595 rme96xx_unset_ctrl( s,RME96xx_start_bit );
596 udelay(10);
597 rme96xx_unset_ctrl( s,RME96xx_IE);
598 spin_lock_irqsave(&s->lock,flags); /* timing is critical */
599 s->started = 0;
600 spin_unlock_irqrestore(&s->lock,flags);
601 if (stop) {
602 COMM("Sound card stopped");
603 return 1;
604 }
605 }
606 COMM ("interrupt disabled");
607 /* first initialize all pointers on card */
608 for(i=0;i<RME96xx_num_of_init_regs;i++){
609 writel(0,s->iobase + i);
610 udelay(10); /* ?? */
611 }
612 COMM ("regs cleaned");
613
614 spin_lock_irqsave(&s->lock,flags); /* timing is critical */
615 udelay(10);
616 s->started = 1;
617 s->hwptr = 0;
618 spin_unlock_irqrestore(&s->lock,flags);
619
620 rme96xx_set_ctrl( s, RME96xx_IE | RME96xx_start_bit);
621
622
623 COMM("Sound card started");
624
625 return 1;
626}
627
628
629static inline int rme96xx_getospace(struct dmabuf * dma, unsigned int hwp)
630{
631 int cnt;
632 int swptr;
633 unsigned long flags;
634
635 spin_lock_irqsave(&dma->s->lock,flags);
636 swptr = dma->writeptr;
637 cnt = (hwp - swptr);
638
639 if (cnt < 0) {
640 cnt = ((dma->s->fragsize<<1) - swptr);
641 }
642 spin_unlock_irqrestore(&dma->s->lock,flags);
643 return cnt;
644}
645
646static inline int rme96xx_getispace(struct dmabuf * dma, unsigned int hwp)
647{
648 int cnt;
649 int swptr;
650 unsigned long flags;
651
652 spin_lock_irqsave(&dma->s->lock,flags);
653 swptr = dma->readptr;
654 cnt = (hwp - swptr);
655
656 if (cnt < 0) {
657 cnt = ((dma->s->fragsize<<1) - swptr);
658 }
659 spin_unlock_irqrestore(&dma->s->lock,flags);
660 return cnt;
661}
662
663
664static inline int rme96xx_copyfromuser(struct dmabuf* dma,const char __user * buffer,int count,int hop)
665{
666 int swptr = dma->writeptr;
667 switch (dma->format) {
668 case AFMT_S32_BLOCKED:
669 {
670 char __user * buf = (char __user *)buffer;
671 int cnt = count/dma->outchannels;
672 int i;
673 for (i=0;i < dma->outchannels;i++) {
674 char* hwbuf =(char*) &dma->s->playbuf[(dma->outoffset + i)*RME96xx_DMA_MAX_SAMPLES];
675 hwbuf+=swptr;
676
677 if (copy_from_user(hwbuf,buf, cnt))
678 return -1;
679 buf+=hop;
680 }
681 swptr+=cnt;
682 break;
683 }
684 case AFMT_S16_LE:
685 {
686 int i,j;
687 int cnt = count/dma->outchannels;
688 for (i=0;i < dma->outchannels + dma->mono;i++) {
689 short __user * sbuf = (short __user *)buffer + i*(!dma->mono);
690 short* hwbuf =(short*) &dma->s->playbuf[(dma->outoffset + i)*RME96xx_DMA_MAX_SAMPLES];
691 hwbuf+=(swptr>>1);
692 for (j=0;j<(cnt>>1);j++) {
693 hwbuf++; /* skip the low 16 bits */
694 __get_user(*hwbuf++,sbuf++);
695 sbuf+=(dma->outchannels-1);
696 }
697 }
698 swptr += (cnt<<1);
699 break;
700 }
701 default:
702 printk(RME_MESS" unsupported format\n");
703 return -1;
704 } /* switch */
705
706 swptr&=((dma->s->fragsize<<1) -1);
707 dma->writeptr = swptr;
708
709 return 0;
710}
711
712/* The count argument is the number of bytes */
713static inline int rme96xx_copytouser(struct dmabuf* dma,const char __user* buffer,int count,int hop)
714{
715 int swptr = dma->readptr;
716 switch (dma->format) {
717 case AFMT_S32_BLOCKED:
718 {
719 char __user * buf = (char __user *)buffer;
720 int cnt = count/dma->inchannels;
721 int i;
722
723 for (i=0;i < dma->inchannels;i++) {
724 char* hwbuf =(char*) &dma->s->recbuf[(dma->inoffset + i)*RME96xx_DMA_MAX_SAMPLES];
725 hwbuf+=swptr;
726
727 if (copy_to_user(buf,hwbuf,cnt))
728 return -1;
729 buf+=hop;
730 }
731 swptr+=cnt;
732 break;
733 }
734 case AFMT_S16_LE:
735 {
736 int i,j;
737 int cnt = count/dma->inchannels;
738 for (i=0;i < dma->inchannels;i++) {
739 short __user * sbuf = (short __user *)buffer + i;
740 short* hwbuf =(short*) &dma->s->recbuf[(dma->inoffset + i)*RME96xx_DMA_MAX_SAMPLES];
741 hwbuf+=(swptr>>1);
742 for (j=0;j<(cnt>>1);j++) {
743 hwbuf++;
744 __put_user(*hwbuf++,sbuf++);
745 sbuf+=(dma->inchannels-1);
746 }
747 }
748 swptr += (cnt<<1);
749 break;
750 }
751 default:
752 printk(RME_MESS" unsupported format\n");
753 return -1;
754 } /* switch */
755
756 swptr&=((dma->s->fragsize<<1) -1);
757 dma->readptr = swptr;
758 return 0;
759}
760
761
762static irqreturn_t rme96xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
763{
764 int i;
765 rme96xx_info *s = (rme96xx_info *)dev_id;
766 struct dmabuf *db;
767 u32 status;
768 unsigned long flags;
769
770 status = readl(s->iobase + RME96xx_status_register);
771 if (!(status & RME96xx_IRQ)) {
772 return IRQ_NONE;
773 }
774
775 spin_lock_irqsave(&s->lock,flags);
776 writel(0,s->iobase + RME96xx_irq_clear);
777
778 s->hwbufid = (status & RME96xx_buffer_id)>>26;
779 if ((status & 0xffc0) <= 256) s->hwptr = 0;
780 for(i=0;i<devices;i++)
781 {
782 db = &(s->dma[i]);
783 if(db->started > 0)
784 wake_up(&(db->wait));
785 }
786 spin_unlock_irqrestore(&s->lock,flags);
787 return IRQ_HANDLED;
788}
789
790
791
792/*----------------------------------------------------------------------------
793 PCI detection and module initialization stuff
794 ----------------------------------------------------------------------------*/
795
796static void* busmaster_malloc(int size) {
797 int pg; /* 2 s exponent of memory size */
798 char *buf;
799
800 DBG(printk("kernel malloc pages ..\n"));
801
802 for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
803
804 buf = (char *) __get_free_pages(GFP_KERNEL | GFP_DMA, pg);
805
806 if (buf) {
807 struct page* page, *last_page;
808
809 page = virt_to_page(buf);
810 last_page = virt_to_page(buf + (1 << pg));
811 DBG(printk("setting reserved bit\n"));
812 while (page < last_page) {
813 SetPageReserved(page);
814 page++;
815 }
816 return buf;
817 }
818 DBG(printk("allocated %ld",(long)buf));
819 return NULL;
820}
821
822static void busmaster_free(void* ptr,int size) {
823 int pg;
824 struct page* page, *last_page;
825
826 if (ptr == NULL)
827 return;
828
829 for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
830
831 page = virt_to_page(ptr);
832 last_page = page + (1 << pg);
833 while (page < last_page) {
834 ClearPageReserved(page);
835 page++;
836 }
837 DBG(printk("freeing pages\n"));
838 free_pages((unsigned long) ptr, pg);
839 DBG(printk("done\n"));
840}
841
842/* initialize those parts of the info structure which are not pci detectable resources */
843
844static int rme96xx_dmabuf_init(rme96xx_info * s,struct dmabuf* dma,int ioffset,int ooffset) {
845
846 init_MUTEX(&dma->open_sem);
847 init_waitqueue_head(&dma->open_wait);
848 init_waitqueue_head(&dma->wait);
849 dma->s = s;
850 dma->error = 0;
851
852 dma->format = AFMT_S32_BLOCKED;
853 dma->formatshift = 0;
854 dma->inchannels = dma->outchannels = 1;
855 dma->inoffset = ioffset;
856 dma->outoffset = ooffset;
857
858 dma->opened=0;
859 dma->started=0;
860 dma->mmapped=0;
861 dma->open_mode=0;
862 dma->mono=0;
863
864 rme96xx_clearbufs(dma);
865 return 0;
866}
867
868
869static int rme96xx_init(rme96xx_info* s)
870{
871 int i;
872 int status;
873 unsigned short rev;
874
875 DBG(printk("%s\n", __FUNCTION__));
876 numcards++;
877
878 s->magic = RME96xx_MAGIC;
879
880 spin_lock_init(&s->lock);
881
882 COMM ("setup busmaster memory")
883 s->recbuf = busmaster_malloc(RME96xx_DMA_MAX_SIZE_ALL);
884 s->playbuf = busmaster_malloc(RME96xx_DMA_MAX_SIZE_ALL);
885
886 if (!s->recbuf || !s->playbuf) {
887 printk(KERN_ERR RME_MESS" Unable to allocate busmaster memory\n");
888 return -ENODEV;
889 }
890
891 COMM ("setting rec and playbuffers")
892
893 writel((u32) virt_to_bus(s->recbuf),s->iobase + RME96xx_rec_buffer);
894 writel((u32) virt_to_bus(s->playbuf),s->iobase + RME96xx_play_buffer);
895
896 COMM ("initializing control register")
897 rme96xx_unset_ctrl(s,0xffffffff);
898 rme96xx_set_ctrl(s,RME96xx_ctrl_init);
899
900
901 COMM ("setup devices")
902 for (i=0;i < devices;i++) {
903 struct dmabuf * dma = &s->dma[i];
904 rme96xx_dmabuf_init(s,dma,2*i,2*i);
905 }
906
907 /* code from ALSA card-rme9652.c HP 20020201 */
908 /* Determine the h/w rev level of the card. This seems like
909 a particularly kludgy way to encode it, but its what RME
910 chose to do, so we follow them ...
911 */
912
913 status = readl(s->iobase + RME96xx_status_register);
914 if (rme96xx_decode_spdif_rate(status&RME96xx_F) == 1) {
915 s->hw_rev = 15;
916 } else {
917 s->hw_rev = 11;
918 }
919
920 /* Differentiate between the standard Hammerfall, and the
921 "Light", which does not have the expansion board. This
922 method comes from information received from Mathhias
923 Clausen at RME. Display the EEPROM and h/w revID where
924 relevant.
925 */
926
927 pci_read_config_word(s->pcidev, PCI_CLASS_REVISION, &rev);
928 switch (rev & 0xff) {
929 case 8: /* original eprom */
930 if (s->hw_rev == 15) {
931 s->card_name = "RME Digi9636 (Rev 1.5)";
932 } else {
933 s->card_name = "RME Digi9636";
934 }
935 break;
936 case 9: /* W36_G EPROM */
937 s->card_name = "RME Digi9636 (Rev G)";
938 break;
939 case 4: /* W52_G EPROM */
940 s->card_name = "RME Digi9652 (Rev G)";
941 break;
942 default:
943 case 3: /* original eprom */
944 if (s->hw_rev == 15) {
945 s->card_name = "RME Digi9652 (Rev 1.5)";
946 } else {
947 s->card_name = "RME Digi9652";
948 }
949 break;
950 }
951
952 printk(KERN_INFO RME_MESS" detected %s (hw_rev %d)\n",s->card_name,s->hw_rev);
953
954 if (s->hw_rev == 15)
955 rme96xx_initialize_spdif_receiver (s);
956
957 s->started = 0;
958 rme96xx_setlatency(s,7);
959
960 printk(KERN_INFO RME_MESS" card %d initialized\n",numcards);
961 return 0;
962}
963
964
965/* open uses this to figure out which device was opened .. this seems to be
966 unnecessary complex */
967
968static LIST_HEAD(devs);
969
970static int __devinit rme96xx_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
971{
972 int i;
973 rme96xx_info *s;
974
975 DBG(printk("%s\n", __FUNCTION__));
976
977 if (pcidev->irq == 0)
978 return -1;
979 if (!pci_dma_supported(pcidev, 0xffffffff)) {
980 printk(KERN_WARNING RME_MESS" architecture does not support 32bit PCI busmaster DMA\n");
981 return -1;
982 }
983 if (!(s = kmalloc(sizeof(rme96xx_info), GFP_KERNEL))) {
984 printk(KERN_WARNING RME_MESS" out of memory\n");
985 return -1;
986 }
987 memset(s, 0, sizeof(rme96xx_info));
988
989 s->pcidev = pcidev;
990 s->iobase = ioremap(pci_resource_start(pcidev, 0),RME96xx_IO_EXTENT);
991 s->irq = pcidev->irq;
992
993 DBG(printk("remapped iobase: %lx irq %d\n",(long)s->iobase,s->irq));
994
995 if (pci_enable_device(pcidev))
996 goto err_irq;
997 if (request_irq(s->irq, rme96xx_interrupt, SA_SHIRQ, "rme96xx", s)) {
998 printk(KERN_ERR RME_MESS" irq %u in use\n", s->irq);
999 goto err_irq;
1000 }
1001
1002 /* initialize the card */
1003
1004 i = 0;
1005 if (rme96xx_init(s) < 0) {
1006 printk(KERN_ERR RME_MESS" initialization failed\n");
1007 goto err_devices;
1008 }
1009 for (i=0;i<devices;i++) {
1010 if ((s->dspnum[i] = register_sound_dsp(&rme96xx_audio_fops, -1)) < 0)
1011 goto err_devices;
1012 }
1013
1014 if ((s->mixer = register_sound_mixer(&rme96xx_mixer_fops, -1)) < 0)
1015 goto err_devices;
1016
1017 pci_set_drvdata(pcidev, s);
1018 pcidev->dma_mask = 0xffffffff; /* ????? */
1019 /* put it into driver list */
1020 list_add_tail(&s->devs, &devs);
1021
1022 DBG(printk("initialization successful\n"));
1023 return 0;
1024
1025 /* error handler */
1026 err_devices:
1027 while (i--)
1028 unregister_sound_dsp(s->dspnum[i]);
1029 free_irq(s->irq,s);
1030 err_irq:
1031 kfree(s);
1032 return -1;
1033}
1034
1035
1036static void __devexit rme96xx_remove(struct pci_dev *dev)
1037{
1038 int i;
1039 rme96xx_info *s = pci_get_drvdata(dev);
1040
1041 if (!s) {
1042 printk(KERN_ERR"device structure not valid\n");
1043 return ;
1044 }
1045
1046 if (s->started) rme96xx_startcard(s,0);
1047
1048 i = devices;
1049 while (i) {
1050 i--;
1051 unregister_sound_dsp(s->dspnum[i]);
1052 }
1053
1054 unregister_sound_mixer(s->mixer);
1055 synchronize_irq(s->irq);
1056 free_irq(s->irq,s);
1057 busmaster_free(s->recbuf,RME96xx_DMA_MAX_SIZE_ALL);
1058 busmaster_free(s->playbuf,RME96xx_DMA_MAX_SIZE_ALL);
1059 kfree(s);
1060 pci_set_drvdata(dev, NULL);
1061}
1062
1063
1064#ifndef PCI_VENDOR_ID_RME
1065#define PCI_VENDOR_ID_RME 0x10ee
1066#endif
1067#ifndef PCI_DEVICE_ID_RME9652
1068#define PCI_DEVICE_ID_RME9652 0x3fc4
1069#endif
1070#ifndef PCI_ANY_ID
1071#define PCI_ANY_ID 0
1072#endif
1073
1074static struct pci_device_id id_table[] = {
1075 {
1076 .vendor = PCI_VENDOR_ID_RME,
1077 .device = PCI_DEVICE_ID_RME9652,
1078 .subvendor = PCI_ANY_ID,
1079 .subdevice = PCI_ANY_ID,
1080 },
1081 { 0, },
1082};
1083
1084MODULE_DEVICE_TABLE(pci, id_table);
1085
1086static struct pci_driver rme96xx_driver = {
1087 .name = "rme96xx",
1088 .id_table = id_table,
1089 .probe = rme96xx_probe,
1090 .remove = __devexit_p(rme96xx_remove),
1091};
1092
1093static int __init init_rme96xx(void)
1094{
1095 printk(KERN_INFO RME_MESS" version "RMEVERSION" time " __TIME__ " " __DATE__ "\n");
1096 devices = ((devices-1) & RME96xx_MASK_DEVS) + 1;
1097 printk(KERN_INFO RME_MESS" reserving %d dsp device(s)\n",devices);
1098 numcards = 0;
1099 return pci_module_init(&rme96xx_driver);
1100}
1101
1102static void __exit cleanup_rme96xx(void)
1103{
1104 printk(KERN_INFO RME_MESS" unloading\n");
1105 pci_unregister_driver(&rme96xx_driver);
1106}
1107
1108module_init(init_rme96xx);
1109module_exit(cleanup_rme96xx);
1110
1111
1112
1113
1114
1115/*--------------------------------------------------------------------------
1116 Implementation of file operations
1117---------------------------------------------------------------------------*/
1118
1119#define RME96xx_FMT (AFMT_S16_LE|AFMT_U8|AFMT_S32_BLOCKED)
1120/* AFTM_U8 is not (yet?) supported ... HP20020201 */
1121
1122static int rme96xx_ioctl(struct inode *in, struct file *file, unsigned int cmd, unsigned long arg)
1123{
1124 struct dmabuf * dma = (struct dmabuf *)file->private_data;
1125 rme96xx_info *s = dma->s;
1126 unsigned long flags;
1127 audio_buf_info abinfo;
1128 count_info cinfo;
1129 int count;
1130 int val = 0;
1131 void __user *argp = (void __user *)arg;
1132 int __user *p = argp;
1133
1134 VALIDATE_STATE(s);
1135
1136 DBG(printk("ioctl %ud\n",cmd));
1137
1138 switch (cmd) {
1139 case OSS_GETVERSION:
1140 return put_user(SOUND_VERSION, p);
1141
1142 case SNDCTL_DSP_SYNC:
1143#if 0
1144 if (file->f_mode & FMODE_WRITE)
1145 return drain_dac2(s, 0/*file->f_flags & O_NONBLOCK*/);
1146#endif
1147 return 0;
1148
1149 case SNDCTL_DSP_SETDUPLEX:
1150 return 0;
1151
1152 case SNDCTL_DSP_GETCAPS:
1153 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
1154
1155 case SNDCTL_DSP_RESET:
1156// rme96xx_clearbufs(dma);
1157 return 0;
1158
1159 case SNDCTL_DSP_SPEED:
1160 if (get_user(val, p))
1161 return -EFAULT;
1162 if (val >= 0) {
1163/* generally it's not a problem if we change the speed
1164 if (dma->open_mode & (~file->f_mode) & (FMODE_READ|FMODE_WRITE))
1165 return -EINVAL;
1166*/
1167 spin_lock_irqsave(&s->lock, flags);
1168
1169 switch (val) {
1170 case 44100:
1171 case 88200:
1172 rme96xx_unset_ctrl(s,RME96xx_freq);
1173 break;
1174 case 48000:
1175 case 96000:
1176 rme96xx_set_ctrl(s,RME96xx_freq);
1177 break;
1178 /* just report current rate as default
1179 e.g. use 0 to "select" current digital input rate
1180 default:
1181 rme96xx_unset_ctrl(s,RME96xx_freq);
1182 val = 44100;
1183 */
1184 }
1185 if (val > 50000)
1186 rme96xx_set_ctrl(s,RME96xx_DS);
1187 else
1188 rme96xx_unset_ctrl(s,RME96xx_DS);
1189 /* set val to actual value HP 20020201 */
1190 /* NOTE: if not "Sync Master", reported rate might be not yet "updated" ... but I don't want to insert a long udelay() here */
1191 if ((s->control_register & RME96xx_Master) && !(s->control_register & RME96xx_wsel))
1192 val = rme96xx_get_sample_rate_ctrl(s);
1193 else
1194 val = rme96xx_get_sample_rate_status(s);
1195 s->rate = val;
1196 spin_unlock_irqrestore(&s->lock, flags);
1197 }
1198 DBG(printk("speed set to %d\n",val));
1199 return put_user(val, p);
1200
1201 case SNDCTL_DSP_STEREO: /* this plays a mono file on two channels */
1202 if (get_user(val, p))
1203 return -EFAULT;
1204
1205 if (!val) {
1206 DBG(printk("setting to mono\n"));
1207 dma->mono=1;
1208 dma->inchannels = 1;
1209 dma->outchannels = 1;
1210 }
1211 else {
1212 DBG(printk("setting to stereo\n"));
1213 dma->mono = 0;
1214 dma->inchannels = 2;
1215 dma->outchannels = 2;
1216 }
1217 return 0;
1218 case SNDCTL_DSP_CHANNELS:
1219 /* remember to check for resonable offset/channel pairs here */
1220 if (get_user(val, p))
1221 return -EFAULT;
1222
1223 if (file->f_mode & FMODE_WRITE) {
1224 if (val > 0 && (dma->outoffset + val) <= RME96xx_CHANNELS_PER_CARD)
1225 dma->outchannels = val;
1226 else
1227 dma->outchannels = val = 2;
1228 DBG(printk("setting to outchannels %d\n",val));
1229 }
1230 if (file->f_mode & FMODE_READ) {
1231 if (val > 0 && (dma->inoffset + val) <= RME96xx_CHANNELS_PER_CARD)
1232 dma->inchannels = val;
1233 else
1234 dma->inchannels = val = 2;
1235 DBG(printk("setting to inchannels %d\n",val));
1236 }
1237
1238 dma->mono=0;
1239
1240 return put_user(val, p);
1241
1242 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1243 return put_user(RME96xx_FMT, p);
1244
1245 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1246 DBG(printk("setting to format %x\n",val));
1247 if (get_user(val, p))
1248 return -EFAULT;
1249 if (val != AFMT_QUERY) {
1250 if (val & RME96xx_FMT)
1251 dma->format = val;
1252 switch (dma->format) {
1253 case AFMT_S16_LE:
1254 dma->formatshift=1;
1255 break;
1256 case AFMT_S32_BLOCKED:
1257 dma->formatshift=0;
1258 break;
1259 }
1260 }
1261 return put_user(dma->format, p);
1262
1263 case SNDCTL_DSP_POST:
1264 return 0;
1265
1266 case SNDCTL_DSP_GETTRIGGER:
1267 val = 0;
1268#if 0
1269 if (file->f_mode & FMODE_READ && s->ctrl & CTRL_ADC_EN)
1270 val |= PCM_ENABLE_INPUT;
1271 if (file->f_mode & FMODE_WRITE && s->ctrl & CTRL_DAC2_EN)
1272 val |= PCM_ENABLE_OUTPUT;
1273#endif
1274 return put_user(val, p);
1275
1276 case SNDCTL_DSP_SETTRIGGER:
1277 if (get_user(val, p))
1278 return -EFAULT;
1279#if 0
1280 if (file->f_mode & FMODE_READ) {
1281 if (val & PCM_ENABLE_INPUT) {
1282 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1283 return ret;
1284 start_adc(s);
1285 } else
1286 stop_adc(s);
1287 }
1288 if (file->f_mode & FMODE_WRITE) {
1289 if (val & PCM_ENABLE_OUTPUT) {
1290 if (!s->dma_dac2.ready && (ret = prog_dmabuf_dac2(s)))
1291 return ret;
1292 start_dac2(s);
1293 } else
1294 stop_dac2(s);
1295 }
1296#endif
1297 return 0;
1298
1299 case SNDCTL_DSP_GETOSPACE:
1300 if (!(file->f_mode & FMODE_WRITE))
1301 return -EINVAL;
1302
1303 val = rme96xx_gethwptr(dma->s,0);
1304
1305
1306 count = rme96xx_getospace(dma,val);
1307 if (!s->started) count = s->fragsize*2;
1308 abinfo.fragsize =(s->fragsize*dma->outchannels)>>dma->formatshift;
1309 abinfo.bytes = (count*dma->outchannels)>>dma->formatshift;
1310 abinfo.fragstotal = 2;
1311 abinfo.fragments = (count > s->fragsize);
1312
1313 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1314
1315 case SNDCTL_DSP_GETISPACE:
1316 if (!(file->f_mode & FMODE_READ))
1317 return -EINVAL;
1318
1319 val = rme96xx_gethwptr(dma->s,0);
1320
1321 count = rme96xx_getispace(dma,val);
1322
1323 abinfo.fragsize = (s->fragsize*dma->inchannels)>>dma->formatshift;
1324 abinfo.bytes = (count*dma->inchannels)>>dma->formatshift;
1325 abinfo.fragstotal = 2;
1326 abinfo.fragments = count > s->fragsize;
1327 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1328
1329 case SNDCTL_DSP_NONBLOCK:
1330 file->f_flags |= O_NONBLOCK;
1331 return 0;
1332
1333 case SNDCTL_DSP_GETODELAY: /* What should this exactly do ? ,
1334 ATM it is just abinfo.bytes */
1335 if (!(file->f_mode & FMODE_WRITE))
1336 return -EINVAL;
1337
1338 val = rme96xx_gethwptr(dma->s,0);
1339 count = val - dma->readptr;
1340 if (count < 0)
1341 count += s->fragsize<<1;
1342
1343 return put_user(count, p);
1344
1345
1346/* check out how to use mmaped mode (can only be blocked !!!) */
1347 case SNDCTL_DSP_GETIPTR:
1348 if (!(file->f_mode & FMODE_READ))
1349 return -EINVAL;
1350 val = rme96xx_gethwptr(dma->s,0);
1351 spin_lock_irqsave(&s->lock,flags);
1352 cinfo.bytes = s->fragsize<<1;
1353 count = val - dma->readptr;
1354 if (count < 0)
1355 count += s->fragsize<<1;
1356
1357 cinfo.blocks = (count > s->fragsize);
1358 cinfo.ptr = val;
1359 if (dma->mmapped)
1360 dma->readptr &= s->fragsize<<1;
1361 spin_unlock_irqrestore(&s->lock,flags);
1362
1363 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1364 return -EFAULT;
1365 return 0;
1366
1367 case SNDCTL_DSP_GETOPTR:
1368 if (!(file->f_mode & FMODE_READ))
1369 return -EINVAL;
1370 val = rme96xx_gethwptr(dma->s,0);
1371 spin_lock_irqsave(&s->lock,flags);
1372 cinfo.bytes = s->fragsize<<1;
1373 count = val - dma->writeptr;
1374 if (count < 0)
1375 count += s->fragsize<<1;
1376
1377 cinfo.blocks = (count > s->fragsize);
1378 cinfo.ptr = val;
1379 if (dma->mmapped)
1380 dma->writeptr &= s->fragsize<<1;
1381 spin_unlock_irqrestore(&s->lock,flags);
1382 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1383 return -EFAULT;
1384 return 0;
1385 case SNDCTL_DSP_GETBLKSIZE:
1386 return put_user(s->fragsize, p);
1387
1388 case SNDCTL_DSP_SETFRAGMENT:
1389 if (get_user(val, p))
1390 return -EFAULT;
1391 val&=0xffff;
1392 val -= 7;
1393 if (val < 0) val = 0;
1394 if (val > 7) val = 7;
1395 rme96xx_setlatency(s,val);
1396 return 0;
1397
1398 case SNDCTL_DSP_SUBDIVIDE:
1399#if 0
1400 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1401 (file->f_mode & FMODE_WRITE && s->dma_dac2.subdivision))
1402 return -EINVAL;
1403 if (get_user(val, p))
1404 return -EFAULT;
1405 if (val != 1 && val != 2 && val != 4)
1406 return -EINVAL;
1407 if (file->f_mode & FMODE_READ)
1408 s->dma_adc.subdivision = val;
1409 if (file->f_mode & FMODE_WRITE)
1410 s->dma_dac2.subdivision = val;
1411#endif
1412 return 0;
1413
1414 case SOUND_PCM_READ_RATE:
1415 /* HP20020201 */
1416 s->rate = rme96xx_get_sample_rate_status(s);
1417 return put_user(s->rate, p);
1418
1419 case SOUND_PCM_READ_CHANNELS:
1420 return put_user(dma->outchannels, p);
1421
1422 case SOUND_PCM_READ_BITS:
1423 switch (dma->format) {
1424 case AFMT_S32_BLOCKED:
1425 val = 32;
1426 break;
1427 case AFMT_S16_LE:
1428 val = 16;
1429 break;
1430 }
1431 return put_user(val, p);
1432
1433 case SOUND_PCM_WRITE_FILTER:
1434 case SNDCTL_DSP_SETSYNCRO:
1435 case SOUND_PCM_READ_FILTER:
1436 return -EINVAL;
1437
1438 }
1439
1440
1441 return -ENODEV;
1442}
1443
1444
1445
1446static int rme96xx_open(struct inode *in, struct file *f)
1447{
1448 int minor = iminor(in);
1449 struct list_head *list;
1450 int devnum;
1451 rme96xx_info *s;
1452 struct dmabuf* dma;
1453 DECLARE_WAITQUEUE(wait, current);
1454
1455 DBG(printk("device num %d open\n",devnum));
1456
1457 nonseekable_open(in, f);
1458 for (list = devs.next; ; list = list->next) {
1459 if (list == &devs)
1460 return -ENODEV;
1461 s = list_entry(list, rme96xx_info, devs);
1462 for (devnum=0; devnum<devices; devnum++)
1463 if (!((s->dspnum[devnum] ^ minor) & ~0xf))
1464 break;
1465 if (devnum<devices)
1466 break;
1467 }
1468 VALIDATE_STATE(s);
1469
1470 dma = &s->dma[devnum];
1471 f->private_data = dma;
1472 /* wait for device to become free */
1473 down(&dma->open_sem);
1474 while (dma->open_mode & f->f_mode) {
1475 if (f->f_flags & O_NONBLOCK) {
1476 up(&dma->open_sem);
1477 return -EBUSY;
1478 }
1479 add_wait_queue(&dma->open_wait, &wait);
1480 __set_current_state(TASK_INTERRUPTIBLE);
1481 up(&dma->open_sem);
1482 schedule();
1483 remove_wait_queue(&dma->open_wait, &wait);
1484 set_current_state(TASK_RUNNING);
1485 if (signal_pending(current))
1486 return -ERESTARTSYS;
1487 down(&dma->open_sem);
1488 }
1489
1490 COMM ("hardware open")
1491
1492 if (!dma->opened) rme96xx_dmabuf_init(dma->s,dma,dma->inoffset,dma->outoffset);
1493
1494 dma->open_mode |= (f->f_mode & (FMODE_READ | FMODE_WRITE));
1495 dma->opened = 1;
1496 up(&dma->open_sem);
1497
1498 DBG(printk("device num %d open finished\n",devnum));
1499 return 0;
1500}
1501
1502static int rme96xx_release(struct inode *in, struct file *file)
1503{
1504 struct dmabuf * dma = (struct dmabuf*) file->private_data;
1505 /* int hwp; ... was unused HP20020201 */
1506 DBG(printk("%s\n", __FUNCTION__));
1507
1508 COMM ("draining")
1509 if (dma->open_mode & FMODE_WRITE) {
1510#if 0 /* Why doesn't this work with some cards ?? */
1511 hwp = rme96xx_gethwptr(dma->s,0);
1512 while (rme96xx_getospace(dma,hwp)) {
1513 interruptible_sleep_on(&(dma->wait));
1514 hwp = rme96xx_gethwptr(dma->s,0);
1515 }
1516#endif
1517 rme96xx_clearbufs(dma);
1518 }
1519
1520 dma->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
1521
1522 if (!(dma->open_mode & (FMODE_READ|FMODE_WRITE))) {
1523 dma->opened = 0;
1524 if (dma->s->started) rme96xx_startcard(dma->s,1);
1525 }
1526
1527 wake_up(&dma->open_wait);
1528 up(&dma->open_sem);
1529
1530 return 0;
1531}
1532
1533
1534static ssize_t rme96xx_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1535{
1536 struct dmabuf *dma = (struct dmabuf *)file->private_data;
1537 ssize_t ret = 0;
1538 int cnt; /* number of bytes from "buffer" that will/can be used */
1539 int hop = count/dma->outchannels;
1540 int hwp;
1541 int exact = (file->f_flags & O_NONBLOCK);
1542
1543
1544 if(dma == NULL || (dma->s) == NULL)
1545 return -ENXIO;
1546
1547 if (dma->mmapped || !dma->opened)
1548 return -ENXIO;
1549
1550 if (!access_ok(VERIFY_READ, buffer, count))
1551 return -EFAULT;
1552
1553 if (! (dma->open_mode & FMODE_WRITE))
1554 return -ENXIO;
1555
1556 if (!dma->s->started) rme96xx_startcard(dma->s,exact);
1557 hwp = rme96xx_gethwptr(dma->s,0);
1558
1559 if(!(dma->started)){
1560 COMM ("first write")
1561
1562 dma->readptr = hwp;
1563 dma->writeptr = hwp;
1564 dma->started = 1;
1565 }
1566
1567 while (count > 0) {
1568 cnt = rme96xx_getospace(dma,hwp);
1569 cnt>>=dma->formatshift;
1570 cnt*=dma->outchannels;
1571 if (cnt > count)
1572 cnt = count;
1573
1574 if (cnt != 0) {
1575 if (rme96xx_copyfromuser(dma,buffer,cnt,hop))
1576 return ret ? ret : -EFAULT;
1577 count -= cnt;
1578 buffer += cnt;
1579 ret += cnt;
1580 if (count == 0) return ret;
1581 }
1582 if (file->f_flags & O_NONBLOCK)
1583 return ret ? ret : -EAGAIN;
1584
1585 if ((hwp - dma->writeptr) <= 0) {
1586 interruptible_sleep_on(&(dma->wait));
1587
1588 if (signal_pending(current))
1589 return ret ? ret : -ERESTARTSYS;
1590 }
1591
1592 hwp = rme96xx_gethwptr(dma->s,exact);
1593
1594 }; /* count > 0 */
1595
1596 return ret;
1597}
1598
1599static ssize_t rme96xx_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1600{
1601 struct dmabuf *dma = (struct dmabuf *)file->private_data;
1602 ssize_t ret = 0;
1603 int cnt; /* number of bytes from "buffer" that will/can be used */
1604 int hop = count/dma->inchannels;
1605 int hwp;
1606 int exact = (file->f_flags & O_NONBLOCK);
1607
1608
1609 if(dma == NULL || (dma->s) == NULL)
1610 return -ENXIO;
1611
1612 if (dma->mmapped || !dma->opened)
1613 return -ENXIO;
1614
1615 if (!access_ok(VERIFY_WRITE, buffer, count))
1616 return -EFAULT;
1617
1618 if (! (dma->open_mode & FMODE_READ))
1619 return -ENXIO;
1620
1621 if (!dma->s->started) rme96xx_startcard(dma->s,exact);
1622 hwp = rme96xx_gethwptr(dma->s,0);
1623
1624 if(!(dma->started)){
1625 COMM ("first read")
1626
1627 dma->writeptr = hwp;
1628 dma->readptr = hwp;
1629 dma->started = 1;
1630 }
1631
1632 while (count > 0) {
1633 cnt = rme96xx_getispace(dma,hwp);
1634 cnt>>=dma->formatshift;
1635 cnt*=dma->inchannels;
1636
1637 if (cnt > count)
1638 cnt = count;
1639
1640 if (cnt != 0) {
1641
1642 if (rme96xx_copytouser(dma,buffer,cnt,hop))
1643 return ret ? ret : -EFAULT;
1644
1645 count -= cnt;
1646 buffer += cnt;
1647 ret += cnt;
1648 if (count == 0) return ret;
1649 }
1650 if (file->f_flags & O_NONBLOCK)
1651 return ret ? ret : -EAGAIN;
1652
1653 if ((hwp - dma->readptr) <= 0) {
1654 interruptible_sleep_on(&(dma->wait));
1655
1656 if (signal_pending(current))
1657 return ret ? ret : -ERESTARTSYS;
1658 }
1659 hwp = rme96xx_gethwptr(dma->s,exact);
1660
1661 }; /* count > 0 */
1662
1663 return ret;
1664}
1665
1666static int rm96xx_mmap(struct file *file, struct vm_area_struct *vma) {
1667 struct dmabuf *dma = (struct dmabuf *)file->private_data;
1668 rme96xx_info* s = dma->s;
1669 unsigned long size;
1670
1671 VALIDATE_STATE(s);
1672 lock_kernel();
1673
1674 if (vma->vm_pgoff != 0) {
1675 unlock_kernel();
1676 return -EINVAL;
1677 }
1678 size = vma->vm_end - vma->vm_start;
1679 if (size > RME96xx_DMA_MAX_SIZE) {
1680 unlock_kernel();
1681 return -EINVAL;
1682 }
1683
1684
1685 if (vma->vm_flags & VM_WRITE) {
1686 if (!s->started) rme96xx_startcard(s,1);
1687
1688 if (remap_pfn_range(vma, vma->vm_start, virt_to_phys(s->playbuf + dma->outoffset*RME96xx_DMA_MAX_SIZE) >> PAGE_SHIFT, size, vma->vm_page_prot)) {
1689 unlock_kernel();
1690 return -EAGAIN;
1691 }
1692 }
1693 else if (vma->vm_flags & VM_READ) {
1694 if (!s->started) rme96xx_startcard(s,1);
1695 if (remap_pfn_range(vma, vma->vm_start, virt_to_phys(s->playbuf + dma->inoffset*RME96xx_DMA_MAX_SIZE) >> PAGE_SHIFT, size, vma->vm_page_prot)) {
1696 unlock_kernel();
1697 return -EAGAIN;
1698 }
1699 } else {
1700 unlock_kernel();
1701 return -EINVAL;
1702 }
1703
1704
1705/* this is the mapping */
1706 vma->vm_flags &= ~VM_IO;
1707 dma->mmapped = 1;
1708 unlock_kernel();
1709 return 0;
1710}
1711
1712static unsigned int rme96xx_poll(struct file *file, struct poll_table_struct *wait)
1713{
1714 struct dmabuf *dma = (struct dmabuf *)file->private_data;
1715 rme96xx_info* s = dma->s;
1716 unsigned int mask = 0;
1717 unsigned int hwp,cnt;
1718
1719 DBG(printk("rme96xx poll_wait ...\n"));
1720 VALIDATE_STATE(s);
1721
1722 if (!s->started) {
1723 mask |= POLLOUT | POLLWRNORM;
1724 }
1725 poll_wait(file, &dma->wait, wait);
1726
1727 hwp = rme96xx_gethwptr(dma->s,0);
1728
1729 DBG(printk("rme96xx poll: ..cnt %d > %d\n",cnt,s->fragsize));
1730
1731 cnt = rme96xx_getispace(dma,hwp);
1732
1733 if (file->f_mode & FMODE_READ)
1734 if (cnt > 0)
1735 mask |= POLLIN | POLLRDNORM;
1736
1737
1738
1739 cnt = rme96xx_getospace(dma,hwp);
1740
1741 if (file->f_mode & FMODE_WRITE)
1742 if (cnt > 0)
1743 mask |= POLLOUT | POLLWRNORM;
1744
1745
1746// printk("rme96xx poll_wait ...%d > %d\n",rme96xx_getospace(dma,hwp),rme96xx_getispace(dma,hwp));
1747
1748 return mask;
1749}
1750
1751
1752static struct file_operations rme96xx_audio_fops = {
1753#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1754 .owner = THIS_MODULE,
1755#endif
1756 .read = rme96xx_read,
1757 .write = rme96xx_write,
1758 .poll = rme96xx_poll,
1759 .ioctl = rme96xx_ioctl,
1760 .mmap = rm96xx_mmap,
1761 .open = rme96xx_open,
1762 .release = rme96xx_release
1763};
1764
1765static int rme96xx_mixer_open(struct inode *inode, struct file *file)
1766{
1767 int minor = iminor(inode);
1768 struct list_head *list;
1769 rme96xx_info *s;
1770
1771 COMM ("mixer open");
1772
1773 nonseekable_open(inode, file);
1774 for (list = devs.next; ; list = list->next) {
1775 if (list == &devs)
1776 return -ENODEV;
1777 s = list_entry(list, rme96xx_info, devs);
1778 if (s->mixer== minor)
1779 break;
1780 }
1781 VALIDATE_STATE(s);
1782 file->private_data = s;
1783
1784 COMM ("mixer opened")
1785 return 0;
1786}
1787
1788static int rme96xx_mixer_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1789{
1790 rme96xx_info *s = (rme96xx_info *)file->private_data;
1791 u32 status;
1792 int spdifrate;
1793 void __user *argp = (void __user *)arg;
1794 int __user *p = argp;
1795
1796 status = readl(s->iobase + RME96xx_status_register);
1797 /* hack to convert rev 1.5 SPDIF rate to "crystalrate" format HP 20020201 */
1798 rme96xx_spdif_sample_rate(s,&spdifrate);
1799 status = (status & ~RME96xx_F) | ((spdifrate<<22) & RME96xx_F);
1800
1801 VALIDATE_STATE(s);
1802 if (cmd == SOUND_MIXER_PRIVATE1) {
1803 rme_mixer mixer;
1804 if (copy_from_user(&mixer,argp,sizeof(mixer)))
1805 return -EFAULT;
1806
1807 mixer.devnr &= RME96xx_MASK_DEVS;
1808 if (mixer.devnr >= devices)
1809 mixer.devnr = devices-1;
1810 if (file->f_mode & FMODE_WRITE && !s->dma[mixer.devnr].opened) {
1811 /* modify only if device not open */
1812 if (mixer.o_offset < 0)
1813 mixer.o_offset = 0;
1814 if (mixer.o_offset >= RME96xx_CHANNELS_PER_CARD)
1815 mixer.o_offset = RME96xx_CHANNELS_PER_CARD-1;
1816 if (mixer.i_offset < 0)
1817 mixer.i_offset = 0;
1818 if (mixer.i_offset >= RME96xx_CHANNELS_PER_CARD)
1819 mixer.i_offset = RME96xx_CHANNELS_PER_CARD-1;
1820 s->dma[mixer.devnr].outoffset = mixer.o_offset;
1821 s->dma[mixer.devnr].inoffset = mixer.i_offset;
1822 }
1823
1824 mixer.o_offset = s->dma[mixer.devnr].outoffset;
1825 mixer.i_offset = s->dma[mixer.devnr].inoffset;
1826
1827 return copy_to_user(argp, &mixer, sizeof(mixer)) ? -EFAULT : 0;
1828 }
1829 if (cmd == SOUND_MIXER_PRIVATE2) {
1830 return put_user(status, p);
1831 }
1832 if (cmd == SOUND_MIXER_PRIVATE3) {
1833 u32 control;
1834 if (copy_from_user(&control,argp,sizeof(control)))
1835 return -EFAULT;
1836 if (file->f_mode & FMODE_WRITE) {
1837 s->control_register &= ~RME96xx_mixer_allowed;
1838 s->control_register |= control & RME96xx_mixer_allowed;
1839 writel(control,s->iobase + RME96xx_control_register);
1840 }
1841
1842 return put_user(s->control_register, p);
1843 }
1844 return -1;
1845}
1846
1847
1848
1849static int rme96xx_mixer_release(struct inode *inode, struct file *file)
1850{
1851 return 0;
1852}
1853
1854static /*const*/ struct file_operations rme96xx_mixer_fops = {
1855#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1856 .owner = THIS_MODULE,
1857#endif
1858 .ioctl = rme96xx_mixer_ioctl,
1859 .open = rme96xx_mixer_open,
1860 .release = rme96xx_mixer_release,
1861};
diff --git a/sound/oss/rme96xx.h b/sound/oss/rme96xx.h
new file mode 100644
index 000000000000..7a3c188ea0a8
--- /dev/null
+++ b/sound/oss/rme96xx.h
@@ -0,0 +1,78 @@
1/* (C) 2000 Guenter Geiger <geiger@debian.org>
2 with copy/pastes from the driver of Winfried Ritsch <ritsch@iem.kug.ac.at>
3
4Modifications - Heiko Purnhagen <purnhage@tnt.uni-hannover.de>
5 HP20020116 towards REV 1.5 support, based on ALSA's card-rme9652.c
6 HP20020201 completed?
7
8A text/graphic control panel (rmectrl/xrmectrl) is available from
9 http://gige.xdv.org/pages/soft/pages/rme
10*/
11
12
13#ifndef AFMT_S32_BLOCKED
14#define AFMT_S32_BLOCKED 0x0000400
15#endif
16
17/* AFMT_S16_BLOCKED not yet supported */
18#ifndef AFMT_S16_BLOCKED
19#define AFMT_S16_BLOCKED 0x0000800
20#endif
21
22
23typedef struct rme_status {
24 unsigned int irq:1;
25 unsigned int lockmask:3; /* ADAT input PLLs locked */
26 /* 100=ADAT1, 010=ADAT2, 001=ADAT3 */
27 unsigned int sr48:1; /* sample rate: 0=44.1/88.2 1=48/96 kHz */
28 unsigned int wclock:1; /* 1=wordclock used */
29 unsigned int bufpoint:10;
30 unsigned int syncmask:3; /* ADAT input in sync with system clock */
31 /* 100=ADAT1, 010=ADAT2, 001=ADAT3 */
32 unsigned int doublespeed:1; /* sample rate: 0=44.1/48 1=88.2/96 kHz */
33 unsigned int tc_busy:1;
34 unsigned int tc_out:1;
35 unsigned int crystalrate:3; /* spdif input sample rate: */
36 /* 000=64kHz, 100=88.2kHz, 011=96kHz */
37 /* 111=32kHz, 110=44.1kHz, 101=48kHz */
38 unsigned int spdif_error:1; /* 1=no spdif lock */
39 unsigned int bufid:1;
40 unsigned int tc_valid:1; /* 1=timecode input detected */
41 unsigned int spdif_read:1;
42} rme_status_t;
43
44
45/* only fields marked W: can be modified by writing to SOUND_MIXER_PRIVATE3 */
46typedef struct rme_control {
47 unsigned int start:1;
48 unsigned int latency:3; /* buffer size / latency [samples]: */
49 /* 0=64 ... 7=8192 */
50 unsigned int master:1; /* W: clock mode: 1=master 0=slave/auto */
51 unsigned int ie:1;
52 unsigned int sr48:1; /* samplerate 0=44.1/88.2, 1=48/96 kHz */
53 unsigned int spare:1;
54 unsigned int doublespeed:1; /* double speed 0=44.1/48, 1=88.2/96 Khz */
55 unsigned int pro:1; /* W: SPDIF-OUT 0=consumer, 1=professional */
56 unsigned int emphasis:1; /* W: SPDIF-OUT emphasis 0=off, 1=on */
57 unsigned int dolby:1; /* W: SPDIF-OUT non-audio bit 1=set, 0=unset */
58 unsigned int opt_out:1; /* W: use 1st optical OUT as SPDIF: 1=yes, 0=no */
59 unsigned int wordclock:1; /* W: use Wordclock as sync (overwrites master) */
60 unsigned int spdif_in:2; /* W: SPDIF-IN: */
61 /* 00=optical (ADAT1), 01=coaxial (Cinch), 10=internal CDROM */
62 unsigned int sync_ref:2; /* W: preferred sync-source in autosync */
63 /* 00=ADAT1, 01=ADAT2, 10=ADAT3, 11=SPDIF */
64 unsigned int spdif_reset:1;
65 unsigned int spdif_select:1;
66 unsigned int spdif_clock:1;
67 unsigned int spdif_write:1;
68 unsigned int adat1_cd:1; /* W: Rev 1.5+: if set, internal CD connector carries ADAT */
69} rme_ctrl_t;
70
71
72typedef struct _rme_mixer {
73 int i_offset;
74 int o_offset;
75 int devnr;
76 int spare[8];
77} rme_mixer;
78
diff --git a/sound/oss/sb.h b/sound/oss/sb.h
new file mode 100644
index 000000000000..77e8891ce333
--- /dev/null
+++ b/sound/oss/sb.h
@@ -0,0 +1,185 @@
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
new file mode 100644
index 000000000000..75e54f6f638a
--- /dev/null
+++ b/sound/oss/sb_audio.c
@@ -0,0 +1,1098 @@
1/*
2 * sound/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 {
106 struct dma_buffparms *dmap_temp;
107 dmap_temp = audio_devs[dev]->dmap_out;
108 audio_devs[dev]->dmap_out = audio_devs[dev]->dmap_in;
109 audio_devs[dev]->dmap_in = dmap_temp;
110 }
111 audio_devs[dev]->dmap_out->dma = devc->dma8;
112 audio_devs[dev]->dmap_in->dma = ( devc->duplex ) ?
113 devc->dma16 : devc->dma8;
114
115 if (devc->dma16 != -1 && devc->dma16 != devc->dma8 && !devc->duplex)
116 sound_close_dma(devc->dma16);
117
118 /* For ALS007, turn DSP output back on if closing the device for read */
119
120 if ((devc->submodel == SUBMDL_ALS007) && (devc->opened & OPEN_READ))
121 {
122 sb_setmixer(devc,ALS007_OUTPUT_CTRL2,
123 sb_getmixer(devc,ALS007_OUTPUT_CTRL2) | 0x06);
124 }
125 devc->opened = 0;
126}
127
128static void sb_set_output_parms(int dev, unsigned long buf, int nr_bytes,
129 int intrflag)
130{
131 sb_devc *devc = audio_devs[dev]->devc;
132
133 if (!devc->fullduplex || devc->bits == AFMT_S16_LE)
134 {
135 devc->trg_buf = buf;
136 devc->trg_bytes = nr_bytes;
137 devc->trg_intrflag = intrflag;
138 devc->irq_mode = IMODE_OUTPUT;
139 }
140 else
141 {
142 devc->trg_buf_16 = buf;
143 devc->trg_bytes_16 = nr_bytes;
144 devc->trg_intrflag_16 = intrflag;
145 devc->irq_mode_16 = IMODE_OUTPUT;
146 }
147}
148
149static void sb_set_input_parms(int dev, unsigned long buf, int count, int intrflag)
150{
151 sb_devc *devc = audio_devs[dev]->devc;
152
153 if (!devc->fullduplex || devc->bits != AFMT_S16_LE)
154 {
155 devc->trg_buf = buf;
156 devc->trg_bytes = count;
157 devc->trg_intrflag = intrflag;
158 devc->irq_mode = IMODE_INPUT;
159 }
160 else
161 {
162 devc->trg_buf_16 = buf;
163 devc->trg_bytes_16 = count;
164 devc->trg_intrflag_16 = intrflag;
165 devc->irq_mode_16 = IMODE_INPUT;
166 }
167}
168
169/*
170 * SB1.x compatible routines
171 */
172
173static void sb1_audio_output_block(int dev, unsigned long buf, int nr_bytes, int intrflag)
174{
175 unsigned long flags;
176 int count = nr_bytes;
177 sb_devc *devc = audio_devs[dev]->devc;
178
179 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
180
181 if (audio_devs[dev]->dmap_out->dma > 3)
182 count >>= 1;
183 count--;
184
185 devc->irq_mode = IMODE_OUTPUT;
186
187 spin_lock_irqsave(&devc->lock, flags);
188 if (sb_dsp_command(devc, 0x14)) /* 8 bit DAC using DMA */
189 {
190 sb_dsp_command(devc, (unsigned char) (count & 0xff));
191 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
192 }
193 else
194 printk(KERN_WARNING "Sound Blaster: unable to start DAC.\n");
195 spin_unlock_irqrestore(&devc->lock, flags);
196 devc->intr_active = 1;
197}
198
199static void sb1_audio_start_input(int dev, unsigned long buf, int nr_bytes, int intrflag)
200{
201 unsigned long flags;
202 int count = nr_bytes;
203 sb_devc *devc = audio_devs[dev]->devc;
204
205 /*
206 * Start a DMA input to the buffer pointed by dmaqtail
207 */
208
209 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
210
211 if (audio_devs[dev]->dmap_out->dma > 3)
212 count >>= 1;
213 count--;
214
215 devc->irq_mode = IMODE_INPUT;
216
217 spin_lock_irqsave(&devc->lock, flags);
218 if (sb_dsp_command(devc, 0x24)) /* 8 bit ADC using DMA */
219 {
220 sb_dsp_command(devc, (unsigned char) (count & 0xff));
221 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
222 }
223 else
224 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
225 spin_unlock_irqrestore(&devc->lock, flags);
226
227 devc->intr_active = 1;
228}
229
230static void sb1_audio_trigger(int dev, int bits)
231{
232 sb_devc *devc = audio_devs[dev]->devc;
233
234 bits &= devc->irq_mode;
235
236 if (!bits)
237 sb_dsp_command(devc, 0xd0); /* Halt DMA */
238 else
239 {
240 switch (devc->irq_mode)
241 {
242 case IMODE_INPUT:
243 sb1_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
244 devc->trg_intrflag);
245 break;
246
247 case IMODE_OUTPUT:
248 sb1_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
249 devc->trg_intrflag);
250 break;
251 }
252 }
253 devc->trigger_bits = bits;
254}
255
256static int sb1_audio_prepare_for_input(int dev, int bsize, int bcount)
257{
258 sb_devc *devc = audio_devs[dev]->devc;
259 unsigned long flags;
260
261 spin_lock_irqsave(&devc->lock, flags);
262 if (sb_dsp_command(devc, 0x40))
263 sb_dsp_command(devc, devc->tconst);
264 sb_dsp_command(devc, DSP_CMD_SPKOFF);
265 spin_unlock_irqrestore(&devc->lock, flags);
266
267 devc->trigger_bits = 0;
268 return 0;
269}
270
271static int sb1_audio_prepare_for_output(int dev, int bsize, int bcount)
272{
273 sb_devc *devc = audio_devs[dev]->devc;
274 unsigned long flags;
275
276 spin_lock_irqsave(&devc->lock, flags);
277 if (sb_dsp_command(devc, 0x40))
278 sb_dsp_command(devc, devc->tconst);
279 sb_dsp_command(devc, DSP_CMD_SPKON);
280 spin_unlock_irqrestore(&devc->lock, flags);
281 devc->trigger_bits = 0;
282 return 0;
283}
284
285static int sb1_audio_set_speed(int dev, int speed)
286{
287 int max_speed = 23000;
288 sb_devc *devc = audio_devs[dev]->devc;
289 int tmp;
290
291 if (devc->opened & OPEN_READ)
292 max_speed = 13000;
293
294 if (speed > 0)
295 {
296 if (speed < 4000)
297 speed = 4000;
298
299 if (speed > max_speed)
300 speed = max_speed;
301
302 devc->tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
303 tmp = 256 - devc->tconst;
304 speed = (1000000 + tmp / 2) / tmp;
305
306 devc->speed = speed;
307 }
308 return devc->speed;
309}
310
311static short sb1_audio_set_channels(int dev, short channels)
312{
313 sb_devc *devc = audio_devs[dev]->devc;
314 return devc->channels = 1;
315}
316
317static unsigned int sb1_audio_set_bits(int dev, unsigned int bits)
318{
319 sb_devc *devc = audio_devs[dev]->devc;
320 return devc->bits = 8;
321}
322
323static void sb1_audio_halt_xfer(int dev)
324{
325 unsigned long flags;
326 sb_devc *devc = audio_devs[dev]->devc;
327
328 spin_lock_irqsave(&devc->lock, flags);
329 sb_dsp_reset(devc);
330 spin_unlock_irqrestore(&devc->lock, flags);
331}
332
333/*
334 * SB 2.0 and SB 2.01 compatible routines
335 */
336
337static void sb20_audio_output_block(int dev, unsigned long buf, int nr_bytes,
338 int intrflag)
339{
340 unsigned long flags;
341 int count = nr_bytes;
342 sb_devc *devc = audio_devs[dev]->devc;
343 unsigned char cmd;
344
345 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
346
347 if (audio_devs[dev]->dmap_out->dma > 3)
348 count >>= 1;
349 count--;
350
351 devc->irq_mode = IMODE_OUTPUT;
352
353 spin_lock_irqsave(&devc->lock, flags);
354 if (sb_dsp_command(devc, 0x48)) /* DSP Block size */
355 {
356 sb_dsp_command(devc, (unsigned char) (count & 0xff));
357 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
358
359 if (devc->speed * devc->channels <= 23000)
360 cmd = 0x1c; /* 8 bit PCM output */
361 else
362 cmd = 0x90; /* 8 bit high speed PCM output (SB2.01/Pro) */
363
364 if (!sb_dsp_command(devc, cmd))
365 printk(KERN_ERR "Sound Blaster: unable to start DAC.\n");
366 }
367 else
368 printk(KERN_ERR "Sound Blaster: unable to start DAC.\n");
369 spin_unlock_irqrestore(&devc->lock, flags);
370 devc->intr_active = 1;
371}
372
373static void sb20_audio_start_input(int dev, unsigned long buf, int nr_bytes, int intrflag)
374{
375 unsigned long flags;
376 int count = nr_bytes;
377 sb_devc *devc = audio_devs[dev]->devc;
378 unsigned char cmd;
379
380 /*
381 * Start a DMA input to the buffer pointed by dmaqtail
382 */
383
384 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
385
386 if (audio_devs[dev]->dmap_out->dma > 3)
387 count >>= 1;
388 count--;
389
390 devc->irq_mode = IMODE_INPUT;
391
392 spin_lock_irqsave(&devc->lock, flags);
393 if (sb_dsp_command(devc, 0x48)) /* DSP Block size */
394 {
395 sb_dsp_command(devc, (unsigned char) (count & 0xff));
396 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
397
398 if (devc->speed * devc->channels <= (devc->major == 3 ? 23000 : 13000))
399 cmd = 0x2c; /* 8 bit PCM input */
400 else
401 cmd = 0x98; /* 8 bit high speed PCM input (SB2.01/Pro) */
402
403 if (!sb_dsp_command(devc, cmd))
404 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
405 }
406 else
407 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
408 spin_unlock_irqrestore(&devc->lock, flags);
409 devc->intr_active = 1;
410}
411
412static void sb20_audio_trigger(int dev, int bits)
413{
414 sb_devc *devc = audio_devs[dev]->devc;
415 bits &= devc->irq_mode;
416
417 if (!bits)
418 sb_dsp_command(devc, 0xd0); /* Halt DMA */
419 else
420 {
421 switch (devc->irq_mode)
422 {
423 case IMODE_INPUT:
424 sb20_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
425 devc->trg_intrflag);
426 break;
427
428 case IMODE_OUTPUT:
429 sb20_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
430 devc->trg_intrflag);
431 break;
432 }
433 }
434 devc->trigger_bits = bits;
435}
436
437/*
438 * SB2.01 specific speed setup
439 */
440
441static int sb201_audio_set_speed(int dev, int speed)
442{
443 sb_devc *devc = audio_devs[dev]->devc;
444 int tmp;
445 int s = speed * devc->channels;
446
447 if (speed > 0)
448 {
449 if (speed < 4000)
450 speed = 4000;
451 if (speed > 44100)
452 speed = 44100;
453 if (devc->opened & OPEN_READ && speed > 15000)
454 speed = 15000;
455 devc->tconst = (256 - ((1000000 + s / 2) / s)) & 0xff;
456 tmp = 256 - devc->tconst;
457 speed = ((1000000 + tmp / 2) / tmp) / devc->channels;
458
459 devc->speed = speed;
460 }
461 return devc->speed;
462}
463
464/*
465 * SB Pro specific routines
466 */
467
468static int sbpro_audio_prepare_for_input(int dev, int bsize, int bcount)
469{ /* For SB Pro and Jazz16 */
470 sb_devc *devc = audio_devs[dev]->devc;
471 unsigned long flags;
472 unsigned char bits = 0;
473
474 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
475 audio_devs[dev]->dmap_out->dma = audio_devs[dev]->dmap_in->dma =
476 devc->bits == 16 ? devc->dma16 : devc->dma8;
477
478 if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)
479 if (devc->bits == AFMT_S16_LE)
480 bits = 0x04; /* 16 bit mode */
481
482 spin_lock_irqsave(&devc->lock, flags);
483 if (sb_dsp_command(devc, 0x40))
484 sb_dsp_command(devc, devc->tconst);
485 sb_dsp_command(devc, DSP_CMD_SPKOFF);
486 if (devc->channels == 1)
487 sb_dsp_command(devc, 0xa0 | bits); /* Mono input */
488 else
489 sb_dsp_command(devc, 0xa8 | bits); /* Stereo input */
490 spin_unlock_irqrestore(&devc->lock, flags);
491
492 devc->trigger_bits = 0;
493 return 0;
494}
495
496static int sbpro_audio_prepare_for_output(int dev, int bsize, int bcount)
497{ /* For SB Pro and Jazz16 */
498 sb_devc *devc = audio_devs[dev]->devc;
499 unsigned long flags;
500 unsigned char tmp;
501 unsigned char bits = 0;
502
503 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
504 audio_devs[dev]->dmap_out->dma = audio_devs[dev]->dmap_in->dma = devc->bits == 16 ? devc->dma16 : devc->dma8;
505 if (devc->model == MDL_SBPRO)
506 sb_mixer_set_stereo(devc, devc->channels == 2);
507
508 spin_lock_irqsave(&devc->lock, flags);
509 if (sb_dsp_command(devc, 0x40))
510 sb_dsp_command(devc, devc->tconst);
511 sb_dsp_command(devc, DSP_CMD_SPKON);
512
513 if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)
514 {
515 if (devc->bits == AFMT_S16_LE)
516 bits = 0x04; /* 16 bit mode */
517
518 if (devc->channels == 1)
519 sb_dsp_command(devc, 0xa0 | bits); /* Mono output */
520 else
521 sb_dsp_command(devc, 0xa8 | bits); /* Stereo output */
522 spin_unlock_irqrestore(&devc->lock, flags);
523 }
524 else
525 {
526 spin_unlock_irqrestore(&devc->lock, flags);
527 tmp = sb_getmixer(devc, 0x0e);
528 if (devc->channels == 1)
529 tmp &= ~0x02;
530 else
531 tmp |= 0x02;
532 sb_setmixer(devc, 0x0e, tmp);
533 }
534 devc->trigger_bits = 0;
535 return 0;
536}
537
538static int sbpro_audio_set_speed(int dev, int speed)
539{
540 sb_devc *devc = audio_devs[dev]->devc;
541
542 if (speed > 0)
543 {
544 if (speed < 4000)
545 speed = 4000;
546 if (speed > 44100)
547 speed = 44100;
548 if (devc->channels > 1 && speed > 22050)
549 speed = 22050;
550 sb201_audio_set_speed(dev, speed);
551 }
552 return devc->speed;
553}
554
555static short sbpro_audio_set_channels(int dev, short channels)
556{
557 sb_devc *devc = audio_devs[dev]->devc;
558
559 if (channels == 1 || channels == 2)
560 {
561 if (channels != devc->channels)
562 {
563 devc->channels = channels;
564 if (devc->model == MDL_SBPRO && devc->channels == 2)
565 sbpro_audio_set_speed(dev, devc->speed);
566 }
567 }
568 return devc->channels;
569}
570
571static int jazz16_audio_set_speed(int dev, int speed)
572{
573 sb_devc *devc = audio_devs[dev]->devc;
574
575 if (speed > 0)
576 {
577 int tmp;
578 int s = speed * devc->channels;
579
580 if (speed < 5000)
581 speed = 5000;
582 if (speed > 44100)
583 speed = 44100;
584
585 devc->tconst = (256 - ((1000000 + s / 2) / s)) & 0xff;
586
587 tmp = 256 - devc->tconst;
588 speed = ((1000000 + tmp / 2) / tmp) / devc->channels;
589
590 devc->speed = speed;
591 }
592 return devc->speed;
593}
594
595/*
596 * SB16 specific routines
597 */
598
599static int sb16_audio_set_speed(int dev, int speed)
600{
601 sb_devc *devc = audio_devs[dev]->devc;
602 int max_speed = devc->submodel == SUBMDL_ALS100 ? 48000 : 44100;
603
604 if (speed > 0)
605 {
606 if (speed < 5000)
607 speed = 5000;
608
609 if (speed > max_speed)
610 speed = max_speed;
611
612 devc->speed = speed;
613 }
614 return devc->speed;
615}
616
617static unsigned int sb16_audio_set_bits(int dev, unsigned int bits)
618{
619 sb_devc *devc = audio_devs[dev]->devc;
620
621 if (bits != 0)
622 {
623 if (bits == AFMT_U8 || bits == AFMT_S16_LE)
624 devc->bits = bits;
625 else
626 devc->bits = AFMT_U8;
627 }
628
629 return devc->bits;
630}
631
632static int sb16_audio_prepare_for_input(int dev, int bsize, int bcount)
633{
634 sb_devc *devc = audio_devs[dev]->devc;
635
636 if (!devc->fullduplex)
637 {
638 audio_devs[dev]->dmap_out->dma =
639 audio_devs[dev]->dmap_in->dma =
640 devc->bits == AFMT_S16_LE ?
641 devc->dma16 : devc->dma8;
642 }
643 else if (devc->bits == AFMT_S16_LE)
644 {
645 audio_devs[dev]->dmap_out->dma = devc->dma8;
646 audio_devs[dev]->dmap_in->dma = devc->dma16;
647 }
648 else
649 {
650 audio_devs[dev]->dmap_out->dma = devc->dma16;
651 audio_devs[dev]->dmap_in->dma = devc->dma8;
652 }
653
654 devc->trigger_bits = 0;
655 return 0;
656}
657
658static int sb16_audio_prepare_for_output(int dev, int bsize, int bcount)
659{
660 sb_devc *devc = audio_devs[dev]->devc;
661
662 if (!devc->fullduplex)
663 {
664 audio_devs[dev]->dmap_out->dma =
665 audio_devs[dev]->dmap_in->dma =
666 devc->bits == AFMT_S16_LE ?
667 devc->dma16 : devc->dma8;
668 }
669 else if (devc->bits == AFMT_S16_LE)
670 {
671 audio_devs[dev]->dmap_out->dma = devc->dma8;
672 audio_devs[dev]->dmap_in->dma = devc->dma16;
673 }
674 else
675 {
676 audio_devs[dev]->dmap_out->dma = devc->dma16;
677 audio_devs[dev]->dmap_in->dma = devc->dma8;
678 }
679
680 devc->trigger_bits = 0;
681 return 0;
682}
683
684static void sb16_audio_output_block(int dev, unsigned long buf, int count,
685 int intrflag)
686{
687 unsigned long flags, cnt;
688 sb_devc *devc = audio_devs[dev]->devc;
689 unsigned long bits;
690
691 if (!devc->fullduplex || devc->bits == AFMT_S16_LE)
692 {
693 devc->irq_mode = IMODE_OUTPUT;
694 devc->intr_active = 1;
695 }
696 else
697 {
698 devc->irq_mode_16 = IMODE_OUTPUT;
699 devc->intr_active_16 = 1;
700 }
701
702 /* save value */
703 spin_lock_irqsave(&devc->lock, flags);
704 bits = devc->bits;
705 if (devc->fullduplex)
706 devc->bits = (devc->bits == AFMT_S16_LE) ?
707 AFMT_U8 : AFMT_S16_LE;
708 spin_unlock_irqrestore(&devc->lock, flags);
709
710 cnt = count;
711 if (devc->bits == AFMT_S16_LE)
712 cnt >>= 1;
713 cnt--;
714
715 spin_lock_irqsave(&devc->lock, flags);
716
717 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
718
719 sb_dsp_command(devc, 0x41);
720 sb_dsp_command(devc, (unsigned char) ((devc->speed >> 8) & 0xff));
721 sb_dsp_command(devc, (unsigned char) (devc->speed & 0xff));
722
723 sb_dsp_command(devc, (devc->bits == AFMT_S16_LE ? 0xb6 : 0xc6));
724 sb_dsp_command(devc, ((devc->channels == 2 ? 0x20 : 0) +
725 (devc->bits == AFMT_S16_LE ? 0x10 : 0)));
726 sb_dsp_command(devc, (unsigned char) (cnt & 0xff));
727 sb_dsp_command(devc, (unsigned char) (cnt >> 8));
728
729 /* restore real value after all programming */
730 devc->bits = bits;
731 spin_unlock_irqrestore(&devc->lock, flags);
732}
733
734
735/*
736 * This fails on the Cyrix MediaGX. If you don't have the DMA enabled
737 * before the first sample arrives it locks up. However even if you
738 * do enable the DMA in time you just get DMA timeouts and missing
739 * interrupts and stuff, so for now I've not bothered fixing this either.
740 */
741
742static void sb16_audio_start_input(int dev, unsigned long buf, int count, int intrflag)
743{
744 unsigned long flags, cnt;
745 sb_devc *devc = audio_devs[dev]->devc;
746
747 if (!devc->fullduplex || devc->bits != AFMT_S16_LE)
748 {
749 devc->irq_mode = IMODE_INPUT;
750 devc->intr_active = 1;
751 }
752 else
753 {
754 devc->irq_mode_16 = IMODE_INPUT;
755 devc->intr_active_16 = 1;
756 }
757
758 cnt = count;
759 if (devc->bits == AFMT_S16_LE)
760 cnt >>= 1;
761 cnt--;
762
763 spin_lock_irqsave(&devc->lock, flags);
764
765 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
766
767 sb_dsp_command(devc, 0x42);
768 sb_dsp_command(devc, (unsigned char) ((devc->speed >> 8) & 0xff));
769 sb_dsp_command(devc, (unsigned char) (devc->speed & 0xff));
770
771 sb_dsp_command(devc, (devc->bits == AFMT_S16_LE ? 0xbe : 0xce));
772 sb_dsp_command(devc, ((devc->channels == 2 ? 0x20 : 0) +
773 (devc->bits == AFMT_S16_LE ? 0x10 : 0)));
774 sb_dsp_command(devc, (unsigned char) (cnt & 0xff));
775 sb_dsp_command(devc, (unsigned char) (cnt >> 8));
776
777 spin_unlock_irqrestore(&devc->lock, flags);
778}
779
780static void sb16_audio_trigger(int dev, int bits)
781{
782 sb_devc *devc = audio_devs[dev]->devc;
783
784 int bits_16 = bits & devc->irq_mode_16;
785 bits &= devc->irq_mode;
786
787 if (!bits && !bits_16)
788 sb_dsp_command(devc, 0xd0); /* Halt DMA */
789 else
790 {
791 if (bits)
792 {
793 switch (devc->irq_mode)
794 {
795 case IMODE_INPUT:
796 sb16_audio_start_input(dev,
797 devc->trg_buf,
798 devc->trg_bytes,
799 devc->trg_intrflag);
800 break;
801
802 case IMODE_OUTPUT:
803 sb16_audio_output_block(dev,
804 devc->trg_buf,
805 devc->trg_bytes,
806 devc->trg_intrflag);
807 break;
808 }
809 }
810 if (bits_16)
811 {
812 switch (devc->irq_mode_16)
813 {
814 case IMODE_INPUT:
815 sb16_audio_start_input(dev,
816 devc->trg_buf_16,
817 devc->trg_bytes_16,
818 devc->trg_intrflag_16);
819 break;
820
821 case IMODE_OUTPUT:
822 sb16_audio_output_block(dev,
823 devc->trg_buf_16,
824 devc->trg_bytes_16,
825 devc->trg_intrflag_16);
826 break;
827 }
828 }
829 }
830
831 devc->trigger_bits = bits | bits_16;
832}
833
834static unsigned char lbuf8[2048];
835static signed short *lbuf16 = (signed short *)lbuf8;
836#define LBUFCOPYSIZE 1024
837static void
838sb16_copy_from_user(int dev,
839 char *localbuf, int localoffs,
840 const char __user *userbuf, int useroffs,
841 int max_in, int max_out,
842 int *used, int *returned,
843 int len)
844{
845 sb_devc *devc = audio_devs[dev]->devc;
846 int i, c, p, locallen;
847 unsigned char *buf8;
848 signed short *buf16;
849
850 /* if not duplex no conversion */
851 if (!devc->fullduplex)
852 {
853 if (copy_from_user(localbuf + localoffs,
854 userbuf + useroffs, len))
855 return;
856 *used = len;
857 *returned = len;
858 }
859 else if (devc->bits == AFMT_S16_LE)
860 {
861 /* 16 -> 8 */
862 /* max_in >> 1, max number of samples in ( 16 bits ) */
863 /* max_out, max number of samples out ( 8 bits ) */
864 /* len, number of samples that will be taken ( 16 bits )*/
865 /* c, count of samples remaining in buffer ( 16 bits )*/
866 /* p, count of samples already processed ( 16 bits )*/
867 len = ( (max_in >> 1) > max_out) ? max_out : (max_in >> 1);
868 c = len;
869 p = 0;
870 buf8 = (unsigned char *)(localbuf + localoffs);
871 while (c)
872 {
873 locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
874 /* << 1 in order to get 16 bit samples */
875 if (copy_from_user(lbuf16,
876 userbuf + useroffs + (p << 1),
877 locallen << 1))
878 return;
879 for (i = 0; i < locallen; i++)
880 {
881 buf8[p+i] = ~((lbuf16[i] >> 8) & 0xff) ^ 0x80;
882 }
883 c -= locallen; p += locallen;
884 }
885 /* used = ( samples * 16 bits size ) */
886 *used = max_in > ( max_out << 1) ? (max_out << 1) : max_in;
887 /* returned = ( samples * 8 bits size ) */
888 *returned = len;
889 }
890 else
891 {
892 /* 8 -> 16 */
893 /* max_in, max number of samples in ( 8 bits ) */
894 /* max_out >> 1, max number of samples out ( 16 bits ) */
895 /* len, number of samples that will be taken ( 8 bits )*/
896 /* c, count of samples remaining in buffer ( 8 bits )*/
897 /* p, count of samples already processed ( 8 bits )*/
898 len = max_in > (max_out >> 1) ? (max_out >> 1) : max_in;
899 c = len;
900 p = 0;
901 buf16 = (signed short *)(localbuf + localoffs);
902 while (c)
903 {
904 locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
905 if (copy_from_user(lbuf8,
906 userbuf+useroffs + p,
907 locallen))
908 return;
909 for (i = 0; i < locallen; i++)
910 {
911 buf16[p+i] = (~lbuf8[i] ^ 0x80) << 8;
912 }
913 c -= locallen; p += locallen;
914 }
915 /* used = ( samples * 8 bits size ) */
916 *used = len;
917 /* returned = ( samples * 16 bits size ) */
918 *returned = len << 1;
919 }
920}
921
922static void
923sb16_audio_mmap(int dev)
924{
925 sb_devc *devc = audio_devs[dev]->devc;
926 devc->fullduplex = 0;
927}
928
929static struct audio_driver sb1_audio_driver = /* SB1.x */
930{
931 .owner = THIS_MODULE,
932 .open = sb_audio_open,
933 .close = sb_audio_close,
934 .output_block = sb_set_output_parms,
935 .start_input = sb_set_input_parms,
936 .prepare_for_input = sb1_audio_prepare_for_input,
937 .prepare_for_output = sb1_audio_prepare_for_output,
938 .halt_io = sb1_audio_halt_xfer,
939 .trigger = sb1_audio_trigger,
940 .set_speed = sb1_audio_set_speed,
941 .set_bits = sb1_audio_set_bits,
942 .set_channels = sb1_audio_set_channels
943};
944
945static struct audio_driver sb20_audio_driver = /* SB2.0 */
946{
947 .owner = THIS_MODULE,
948 .open = sb_audio_open,
949 .close = sb_audio_close,
950 .output_block = sb_set_output_parms,
951 .start_input = sb_set_input_parms,
952 .prepare_for_input = sb1_audio_prepare_for_input,
953 .prepare_for_output = sb1_audio_prepare_for_output,
954 .halt_io = sb1_audio_halt_xfer,
955 .trigger = sb20_audio_trigger,
956 .set_speed = sb1_audio_set_speed,
957 .set_bits = sb1_audio_set_bits,
958 .set_channels = sb1_audio_set_channels
959};
960
961static struct audio_driver sb201_audio_driver = /* SB2.01 */
962{
963 .owner = THIS_MODULE,
964 .open = sb_audio_open,
965 .close = sb_audio_close,
966 .output_block = sb_set_output_parms,
967 .start_input = sb_set_input_parms,
968 .prepare_for_input = sb1_audio_prepare_for_input,
969 .prepare_for_output = sb1_audio_prepare_for_output,
970 .halt_io = sb1_audio_halt_xfer,
971 .trigger = sb20_audio_trigger,
972 .set_speed = sb201_audio_set_speed,
973 .set_bits = sb1_audio_set_bits,
974 .set_channels = sb1_audio_set_channels
975};
976
977static struct audio_driver sbpro_audio_driver = /* SB Pro */
978{
979 .owner = THIS_MODULE,
980 .open = sb_audio_open,
981 .close = sb_audio_close,
982 .output_block = sb_set_output_parms,
983 .start_input = sb_set_input_parms,
984 .prepare_for_input = sbpro_audio_prepare_for_input,
985 .prepare_for_output = sbpro_audio_prepare_for_output,
986 .halt_io = sb1_audio_halt_xfer,
987 .trigger = sb20_audio_trigger,
988 .set_speed = sbpro_audio_set_speed,
989 .set_bits = sb1_audio_set_bits,
990 .set_channels = sbpro_audio_set_channels
991};
992
993static struct audio_driver jazz16_audio_driver = /* Jazz16 and SM Wave */
994{
995 .owner = THIS_MODULE,
996 .open = sb_audio_open,
997 .close = sb_audio_close,
998 .output_block = sb_set_output_parms,
999 .start_input = sb_set_input_parms,
1000 .prepare_for_input = sbpro_audio_prepare_for_input,
1001 .prepare_for_output = sbpro_audio_prepare_for_output,
1002 .halt_io = sb1_audio_halt_xfer,
1003 .trigger = sb20_audio_trigger,
1004 .set_speed = jazz16_audio_set_speed,
1005 .set_bits = sb16_audio_set_bits,
1006 .set_channels = sbpro_audio_set_channels
1007};
1008
1009static struct audio_driver sb16_audio_driver = /* SB16 */
1010{
1011 .owner = THIS_MODULE,
1012 .open = sb_audio_open,
1013 .close = sb_audio_close,
1014 .output_block = sb_set_output_parms,
1015 .start_input = sb_set_input_parms,
1016 .prepare_for_input = sb16_audio_prepare_for_input,
1017 .prepare_for_output = sb16_audio_prepare_for_output,
1018 .halt_io = sb1_audio_halt_xfer,
1019 .copy_user = sb16_copy_from_user,
1020 .trigger = sb16_audio_trigger,
1021 .set_speed = sb16_audio_set_speed,
1022 .set_bits = sb16_audio_set_bits,
1023 .set_channels = sbpro_audio_set_channels,
1024 .mmap = sb16_audio_mmap
1025};
1026
1027void sb_audio_init(sb_devc * devc, char *name, struct module *owner)
1028{
1029 int audio_flags = 0;
1030 int format_mask = AFMT_U8;
1031
1032 struct audio_driver *driver = &sb1_audio_driver;
1033
1034 switch (devc->model)
1035 {
1036 case MDL_SB1: /* SB1.0 or SB 1.5 */
1037 DDB(printk("Will use standard SB1.x driver\n"));
1038 audio_flags = DMA_HARDSTOP;
1039 break;
1040
1041 case MDL_SB2:
1042 DDB(printk("Will use SB2.0 driver\n"));
1043 audio_flags = DMA_AUTOMODE;
1044 driver = &sb20_audio_driver;
1045 break;
1046
1047 case MDL_SB201:
1048 DDB(printk("Will use SB2.01 (high speed) driver\n"));
1049 audio_flags = DMA_AUTOMODE;
1050 driver = &sb201_audio_driver;
1051 break;
1052
1053 case MDL_JAZZ:
1054 case MDL_SMW:
1055 DDB(printk("Will use Jazz16 driver\n"));
1056 audio_flags = DMA_AUTOMODE;
1057 format_mask |= AFMT_S16_LE;
1058 driver = &jazz16_audio_driver;
1059 break;
1060
1061 case MDL_ESS:
1062 DDB(printk("Will use ESS ES688/1688 driver\n"));
1063 driver = ess_audio_init (devc, &audio_flags, &format_mask);
1064 break;
1065
1066 case MDL_SB16:
1067 DDB(printk("Will use SB16 driver\n"));
1068 audio_flags = DMA_AUTOMODE;
1069 format_mask |= AFMT_S16_LE;
1070 if (devc->dma8 != devc->dma16 && devc->dma16 != -1)
1071 {
1072 audio_flags |= DMA_DUPLEX;
1073 devc->duplex = 1;
1074 }
1075 driver = &sb16_audio_driver;
1076 break;
1077
1078 default:
1079 DDB(printk("Will use SB Pro driver\n"));
1080 audio_flags = DMA_AUTOMODE;
1081 driver = &sbpro_audio_driver;
1082 }
1083
1084 if (owner)
1085 driver->owner = owner;
1086
1087 if ((devc->dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
1088 name,driver, sizeof(struct audio_driver),
1089 audio_flags, format_mask, devc,
1090 devc->dma8,
1091 devc->duplex ? devc->dma16 : devc->dma8)) < 0)
1092 {
1093 printk(KERN_ERR "Sound Blaster: unable to install audio.\n");
1094 return;
1095 }
1096 audio_devs[devc->dev]->mixer_dev = devc->my_mixerdev;
1097 audio_devs[devc->dev]->min_fragment = 5;
1098}
diff --git a/sound/oss/sb_card.c b/sound/oss/sb_card.c
new file mode 100644
index 000000000000..680b82e15298
--- /dev/null
+++ b/sound/oss/sb_card.c
@@ -0,0 +1,347 @@
1/*
2 * sound/oss/sb_card.c
3 *
4 * Detection routine for the ISA Sound Blaster and compatable 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/config.h>
26#include <linux/module.h>
27#include <linux/moduleparam.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 __initdata pnp = 1;
56/*
57static int __initdata uart401 = 0;
58*/
59#else
60static int __initdata pnp = 0;
61#endif
62
63module_param(io, int, 000);
64MODULE_PARM_DESC(io, "Soundblaster i/o base address (0x220,0x240,0x260,0x280)");
65module_param(irq, int, 000);
66MODULE_PARM_DESC(irq, "IRQ (5,7,9,10)");
67module_param(dma, int, 000);
68MODULE_PARM_DESC(dma, "8-bit DMA channel (0,1,3)");
69module_param(dma16, int, 000);
70MODULE_PARM_DESC(dma16, "16-bit DMA channel (5,6,7)");
71module_param(mpu_io, int, 000);
72MODULE_PARM_DESC(mpu_io, "MPU base address");
73module_param(type, int, 000);
74MODULE_PARM_DESC(type, "You can set this to specific card type (doesn't " \
75 "work with pnp)");
76module_param(sm_games, int, 000);
77MODULE_PARM_DESC(sm_games, "Enable support for Logitech soundman games " \
78 "(doesn't work with pnp)");
79module_param(esstype, int, 000);
80MODULE_PARM_DESC(esstype, "ESS chip type (doesn't work with pnp)");
81module_param(acer, int, 000);
82MODULE_PARM_DESC(acer, "Set this to detect cards in some ACER notebooks "\
83 "(doesn't work with pnp)");
84
85#ifdef CONFIG_PNP
86module_param(pnp, int, 000);
87MODULE_PARM_DESC(pnp, "Went set to 0 will disable detection using PnP. "\
88 "Default is 1.\n");
89/* Not done yet.... */
90/*
91module_param(uart401, int, 000);
92MODULE_PARM_DESC(uart401, "When set to 1, will attempt to detect and enable"\
93 "the mpu on some clones");
94*/
95#endif /* CONFIG_PNP */
96
97/* OSS subsystem card registration shared by PnP and legacy routines */
98static int sb_register_oss(struct sb_card_config *scc, struct sb_module_options *sbmo)
99{
100 if (!request_region(scc->conf.io_base, 16, "soundblaster")) {
101 printk(KERN_ERR "sb: ports busy.\n");
102 kfree(scc);
103 return -EBUSY;
104 }
105
106 if (!sb_dsp_detect(&scc->conf, 0, 0, sbmo)) {
107 release_region(scc->conf.io_base, 16);
108 printk(KERN_ERR "sb: Failed DSP Detect.\n");
109 kfree(scc);
110 return -ENODEV;
111 }
112 if(!sb_dsp_init(&scc->conf, THIS_MODULE)) {
113 printk(KERN_ERR "sb: Failed DSP init.\n");
114 kfree(scc);
115 return -ENODEV;
116 }
117 if(scc->mpucnf.io_base > 0) {
118 scc->mpu = 1;
119 printk(KERN_INFO "sb: Turning on MPU\n");
120 if(!probe_sbmpu(&scc->mpucnf, THIS_MODULE))
121 scc->mpu = 0;
122 }
123
124 return 1;
125}
126
127static void sb_unload(struct sb_card_config *scc)
128{
129 sb_dsp_unload(&scc->conf, 0);
130 if(scc->mpu)
131 unload_sbmpu(&scc->mpucnf);
132 kfree(scc);
133}
134
135/* Register legacy card with OSS subsystem */
136static int sb_init_legacy(void)
137{
138 struct sb_module_options sbmo = {0};
139
140 if((legacy = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
141 printk(KERN_ERR "sb: Error: Could not allocate memory\n");
142 return -ENOMEM;
143 }
144 memset(legacy, 0, sizeof(struct sb_card_config));
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
237/* Probe callback function for the PnP API */
238static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_device_id *card_id)
239{
240 struct sb_card_config *scc;
241 struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
242 struct pnp_dev *dev = pnp_request_card_device(card, card_id->devs[0].id, NULL);
243
244 if(!dev){
245 return -EBUSY;
246 }
247
248 if((scc = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
249 printk(KERN_ERR "sb: Error: Could not allocate memory\n");
250 return -ENOMEM;
251 }
252 memset(scc, 0, sizeof(struct sb_card_config));
253
254 printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
255 "%s, Device PnP id = %s\n", card->card->name, card_id->id,
256 dev->id->id);
257
258 scc->card_id = card_id->id;
259 scc->dev_id = dev->id->id;
260 sb_dev2cfg(dev, scc);
261
262 printk(KERN_INFO "sb: PnP: Detected at: io=0x%x, irq=%d, " \
263 "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
264 scc->conf.dma, scc->conf.dma2);
265
266 pnp_set_card_drvdata(card, scc);
267
268 return sb_register_oss(scc, &sbmo);
269}
270
271static void sb_pnp_remove(struct pnp_card_link *card)
272{
273 struct sb_card_config *scc = pnp_get_card_drvdata(card);
274
275 if(!scc)
276 return;
277
278 printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
279
280 sb_unload(scc);
281}
282
283static struct pnp_card_driver sb_pnp_driver = {
284 .name = "OSS SndBlstr", /* 16 character limit */
285 .id_table = sb_pnp_card_table,
286 .probe = sb_pnp_probe,
287 .remove = sb_pnp_remove,
288};
289MODULE_DEVICE_TABLE(pnp_card, sb_pnp_card_table);
290#endif /* CONFIG_PNP */
291
292static int __init sb_init(void)
293{
294 int lres = 0;
295 int pres = 0;
296
297 printk(KERN_INFO "sb: Init: Starting Probe...\n");
298
299 if(io != -1 && irq != -1 && dma != -1) {
300 printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
301 "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
302 lres = sb_init_legacy();
303 } else if((io != -1 || irq != -1 || dma != -1) ||
304 (!pnp && (io == -1 && irq == -1 && dma == -1)))
305 printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
306 "must be set for legacy cards.\n");
307
308#ifdef CONFIG_PNP
309 if(pnp) {
310 pres = pnp_register_card_driver(&sb_pnp_driver);
311 }
312#endif
313 printk(KERN_INFO "sb: Init: Done\n");
314
315 /* If either PnP or Legacy registered a card then return
316 * success */
317 if (pres <= 0 && lres <= 0) {
318#ifdef CONFIG_PNP
319 pnp_unregister_card_driver(&sb_pnp_driver);
320#endif
321 return -ENODEV;
322 }
323 return 0;
324}
325
326static void __exit sb_exit(void)
327{
328 printk(KERN_INFO "sb: Unloading...\n");
329
330 /* Unload legacy card */
331 if (legacy) {
332 printk (KERN_INFO "sb: Unloading legacy card\n");
333 sb_unload(legacy);
334 }
335
336#ifdef CONFIG_PNP
337 pnp_unregister_card_driver(&sb_pnp_driver);
338#endif
339
340 if (smw_free) {
341 vfree(smw_free);
342 smw_free = NULL;
343 }
344}
345
346module_init(sb_init);
347module_exit(sb_exit);
diff --git a/sound/oss/sb_card.h b/sound/oss/sb_card.h
new file mode 100644
index 000000000000..5535cff800df
--- /dev/null
+++ b/sound/oss/sb_card.h
@@ -0,0 +1,149 @@
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
new file mode 100644
index 000000000000..ce359e6c933a
--- /dev/null
+++ b/sound/oss/sb_common.c
@@ -0,0 +1,1291 @@
1/*
2 * sound/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/config.h>
30#include <linux/init.h>
31#include <linux/interrupt.h>
32#include <linux/module.h>
33#include <linux/delay.h>
34#include <linux/spinlock.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, NULL);
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_WARN "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_WARN "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, struct pt_regs *dummy)
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 DEB(printk("Entered sb_dsp_reset()\n"));
230
231 if (devc->model == MDL_ESS) return ess_dsp_reset (devc);
232
233 /* This is only for non-ESS chips */
234
235 outb(1, DSP_RESET);
236
237 udelay(10);
238 outb(0, DSP_RESET);
239 udelay(30);
240
241 for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
242
243 if (inb(DSP_READ) != 0xAA)
244 {
245 DDB(printk("sb: No response to RESET\n"));
246 return 0; /* Sorry */
247 }
248
249 DEB(printk("sb_dsp_reset() OK\n"));
250
251 return 1;
252}
253
254static void dsp_get_vers(sb_devc * devc)
255{
256 int i;
257
258 unsigned long flags;
259
260 DDB(printk("Entered dsp_get_vers()\n"));
261 spin_lock_irqsave(&devc->lock, flags);
262 devc->major = devc->minor = 0;
263 sb_dsp_command(devc, 0xe1); /* Get version */
264
265 for (i = 100000; i; i--)
266 {
267 if (inb(DSP_DATA_AVAIL) & 0x80)
268 {
269 if (devc->major == 0)
270 devc->major = inb(DSP_READ);
271 else
272 {
273 devc->minor = inb(DSP_READ);
274 break;
275 }
276 }
277 }
278 spin_unlock_irqrestore(&devc->lock, flags);
279 DDB(printk("DSP version %d.%02d\n", devc->major, devc->minor));
280}
281
282static int sb16_set_dma_hw(sb_devc * devc)
283{
284 int bits;
285
286 if (devc->dma8 != 0 && devc->dma8 != 1 && devc->dma8 != 3)
287 {
288 printk(KERN_ERR "SB16: Invalid 8 bit DMA (%d)\n", devc->dma8);
289 return 0;
290 }
291 bits = (1 << devc->dma8);
292
293 if (devc->dma16 >= 5 && devc->dma16 <= 7)
294 bits |= (1 << devc->dma16);
295
296 sb_setmixer(devc, DMA_NR, bits);
297 return 1;
298}
299
300static void sb16_set_mpu_port(sb_devc * devc, struct address_info *hw_config)
301{
302 /*
303 * This routine initializes new MIDI port setup register of SB Vibra (CT2502).
304 */
305 unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
306
307 switch (hw_config->io_base)
308 {
309 case 0x300:
310 sb_setmixer(devc, 0x84, bits | 0x04);
311 break;
312
313 case 0x330:
314 sb_setmixer(devc, 0x84, bits | 0x00);
315 break;
316
317 default:
318 sb_setmixer(devc, 0x84, bits | 0x02); /* Disable MPU */
319 printk(KERN_ERR "SB16: Invalid MIDI I/O port %x\n", hw_config->io_base);
320 }
321}
322
323static int sb16_set_irq_hw(sb_devc * devc, int level)
324{
325 int ival;
326
327 switch (level)
328 {
329 case 5:
330 ival = 2;
331 break;
332 case 7:
333 ival = 4;
334 break;
335 case 9:
336 ival = 1;
337 break;
338 case 10:
339 ival = 8;
340 break;
341 default:
342 printk(KERN_ERR "SB16: Invalid IRQ%d\n", level);
343 return 0;
344 }
345 sb_setmixer(devc, IRQ_NR, ival);
346 return 1;
347}
348
349static void relocate_Jazz16(sb_devc * devc, struct address_info *hw_config)
350{
351 unsigned char bits = 0;
352 unsigned long flags;
353
354 if (jazz16_base != 0 && jazz16_base != hw_config->io_base)
355 return;
356
357 switch (hw_config->io_base)
358 {
359 case 0x220:
360 bits = 1;
361 break;
362 case 0x240:
363 bits = 2;
364 break;
365 case 0x260:
366 bits = 3;
367 break;
368 default:
369 return;
370 }
371 bits = jazz16_bits = bits << 5;
372 jazz16_base = hw_config->io_base;
373
374 /*
375 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
376 */
377 spin_lock_irqsave(&jazz16_lock, flags);
378 outb((0xAF), 0x201);
379 outb((0x50), 0x201);
380 outb((bits), 0x201);
381 spin_unlock_irqrestore(&jazz16_lock, flags);
382}
383
384static int init_Jazz16(sb_devc * devc, struct address_info *hw_config)
385{
386 char name[100];
387 /*
388 * First try to check that the card has Jazz16 chip. It identifies itself
389 * by returning 0x12 as response to DSP command 0xfa.
390 */
391
392 if (!sb_dsp_command(devc, 0xfa))
393 return 0;
394
395 if (sb_dsp_get_byte(devc) != 0x12)
396 return 0;
397
398 /*
399 * OK so far. Now configure the IRQ and DMA channel used by the card.
400 */
401 if (hw_config->irq < 1 || hw_config->irq > 15 || jazz_irq_bits[hw_config->irq] == 0)
402 {
403 printk(KERN_ERR "Jazz16: Invalid interrupt (IRQ%d)\n", hw_config->irq);
404 return 0;
405 }
406 if (hw_config->dma < 0 || hw_config->dma > 3 || jazz_dma_bits[hw_config->dma] == 0)
407 {
408 printk(KERN_ERR "Jazz16: Invalid 8 bit DMA (DMA%d)\n", hw_config->dma);
409 return 0;
410 }
411 if (hw_config->dma2 < 0)
412 {
413 printk(KERN_ERR "Jazz16: No 16 bit DMA channel defined\n");
414 return 0;
415 }
416 if (hw_config->dma2 < 5 || hw_config->dma2 > 7 || jazz_dma_bits[hw_config->dma2] == 0)
417 {
418 printk(KERN_ERR "Jazz16: Invalid 16 bit DMA (DMA%d)\n", hw_config->dma2);
419 return 0;
420 }
421 devc->dma16 = hw_config->dma2;
422
423 if (!sb_dsp_command(devc, 0xfb))
424 return 0;
425
426 if (!sb_dsp_command(devc, jazz_dma_bits[hw_config->dma] |
427 (jazz_dma_bits[hw_config->dma2] << 4)))
428 return 0;
429
430 if (!sb_dsp_command(devc, jazz_irq_bits[hw_config->irq]))
431 return 0;
432
433 /*
434 * Now we have configured a standard Jazz16 device.
435 */
436 devc->model = MDL_JAZZ;
437 strcpy(name, "Jazz16");
438
439 hw_config->name = "Jazz16";
440 devc->caps |= SB_NO_MIDI;
441 return 1;
442}
443
444static void relocate_ess1688(sb_devc * devc)
445{
446 unsigned char bits;
447
448 switch (devc->base)
449 {
450 case 0x220:
451 bits = 0x04;
452 break;
453 case 0x230:
454 bits = 0x05;
455 break;
456 case 0x240:
457 bits = 0x06;
458 break;
459 case 0x250:
460 bits = 0x07;
461 break;
462 default:
463 return; /* Wrong port */
464 }
465
466 DDB(printk("Doing ESS1688 address selection\n"));
467
468 /*
469 * ES1688 supports two alternative ways for software address config.
470 * First try the so called Read-Sequence-Key method.
471 */
472
473 /* Reset the sequence logic */
474 inb(0x229);
475 inb(0x229);
476 inb(0x229);
477
478 /* Perform the read sequence */
479 inb(0x22b);
480 inb(0x229);
481 inb(0x22b);
482 inb(0x229);
483 inb(0x229);
484 inb(0x22b);
485 inb(0x229);
486
487 /* Select the base address by reading from it. Then probe using the port. */
488 inb(devc->base);
489 if (sb_dsp_reset(devc)) /* Bingo */
490 return;
491
492#if 0 /* This causes system lockups (Nokia 386/25 at least) */
493 /*
494 * The last resort is the system control register method.
495 */
496
497 outb((0x00), 0xfb); /* 0xFB is the unlock register */
498 outb((0x00), 0xe0); /* Select index 0 */
499 outb((bits), 0xe1); /* Write the config bits */
500 outb((0x00), 0xf9); /* 0xFB is the lock register */
501#endif
502}
503
504int sb_dsp_detect(struct address_info *hw_config, int pci, int pciio, struct sb_module_options *sbmo)
505{
506 sb_devc sb_info;
507 sb_devc *devc = &sb_info;
508
509 memset((char *) &sb_info, 0, sizeof(sb_info)); /* Zero everything */
510
511 /* Copy module options in place */
512 if(sbmo) memcpy(&devc->sbmo, sbmo, sizeof(struct sb_module_options));
513
514 sb_info.my_mididev = -1;
515 sb_info.my_mixerdev = -1;
516 sb_info.dev = -1;
517
518 /*
519 * Initialize variables
520 */
521
522 DDB(printk("sb_dsp_detect(%x) entered\n", hw_config->io_base));
523
524 spin_lock_init(&devc->lock);
525 devc->type = hw_config->card_subtype;
526
527 devc->base = hw_config->io_base;
528 devc->irq = hw_config->irq;
529 devc->dma8 = hw_config->dma;
530
531 devc->dma16 = -1;
532 devc->pcibase = pciio;
533
534 if(pci == SB_PCI_ESSMAESTRO)
535 {
536 devc->model = MDL_ESSPCI;
537 devc->caps |= SB_PCI_IRQ;
538 hw_config->driver_use_1 |= SB_PCI_IRQ;
539 hw_config->card_subtype = MDL_ESSPCI;
540 }
541
542 if(pci == SB_PCI_YAMAHA)
543 {
544 devc->model = MDL_YMPCI;
545 devc->caps |= SB_PCI_IRQ;
546 hw_config->driver_use_1 |= SB_PCI_IRQ;
547 hw_config->card_subtype = MDL_YMPCI;
548
549 printk("Yamaha PCI mode.\n");
550 }
551
552 if (devc->sbmo.acer)
553 {
554 unsigned long flags;
555
556 spin_lock_irqsave(&devc->lock, flags);
557 inb(devc->base + 0x09);
558 inb(devc->base + 0x09);
559 inb(devc->base + 0x09);
560 inb(devc->base + 0x0b);
561 inb(devc->base + 0x09);
562 inb(devc->base + 0x0b);
563 inb(devc->base + 0x09);
564 inb(devc->base + 0x09);
565 inb(devc->base + 0x0b);
566 inb(devc->base + 0x09);
567 inb(devc->base + 0x00);
568 spin_unlock_irqrestore(&devc->lock, flags);
569 }
570 /*
571 * Detect the device
572 */
573
574 if (sb_dsp_reset(devc))
575 dsp_get_vers(devc);
576 else
577 devc->major = 0;
578
579 if (devc->type == 0 || devc->type == MDL_JAZZ || devc->type == MDL_SMW)
580 if (devc->major == 0 || (devc->major == 3 && devc->minor == 1))
581 relocate_Jazz16(devc, hw_config);
582
583 if (devc->major == 0 && (devc->type == MDL_ESS || devc->type == 0))
584 relocate_ess1688(devc);
585
586 if (!sb_dsp_reset(devc))
587 {
588 DDB(printk("SB reset failed\n"));
589#ifdef MODULE
590 printk(KERN_INFO "sb: dsp reset failed.\n");
591#endif
592 return 0;
593 }
594 if (devc->major == 0)
595 dsp_get_vers(devc);
596
597 if (devc->major == 3 && devc->minor == 1)
598 {
599 if (devc->type == MDL_AZTECH) /* SG Washington? */
600 {
601 if (sb_dsp_command(devc, 0x09))
602 if (sb_dsp_command(devc, 0x00)) /* Enter WSS mode */
603 {
604 int i;
605
606 /* Have some delay */
607 for (i = 0; i < 10000; i++)
608 inb(DSP_DATA_AVAIL);
609 devc->caps = SB_NO_AUDIO | SB_NO_MIDI; /* Mixer only */
610 devc->model = MDL_AZTECH;
611 }
612 }
613 }
614
615 if(devc->type == MDL_ESSPCI)
616 devc->model = MDL_ESSPCI;
617
618 if(devc->type == MDL_YMPCI)
619 {
620 printk("YMPCI selected\n");
621 devc->model = MDL_YMPCI;
622 }
623
624 /*
625 * Save device information for sb_dsp_init()
626 */
627
628
629 detected_devc = (sb_devc *)kmalloc(sizeof(sb_devc), GFP_KERNEL);
630 if (detected_devc == NULL)
631 {
632 printk(KERN_ERR "sb: Can't allocate memory for device information\n");
633 return 0;
634 }
635 memcpy(detected_devc, devc, sizeof(sb_devc));
636 MDB(printk(KERN_INFO "SB %d.%02d detected OK (%x)\n", devc->major, devc->minor, hw_config->io_base));
637 return 1;
638}
639
640int sb_dsp_init(struct address_info *hw_config, struct module *owner)
641{
642 sb_devc *devc;
643 char name[100];
644 extern int sb_be_quiet;
645 int mixer22, mixer30;
646
647/*
648 * Check if we had detected a SB device earlier
649 */
650 DDB(printk("sb_dsp_init(%x) entered\n", hw_config->io_base));
651 name[0] = 0;
652
653 if (detected_devc == NULL)
654 {
655 MDB(printk("No detected device\n"));
656 return 0;
657 }
658 devc = detected_devc;
659 detected_devc = NULL;
660
661 if (devc->base != hw_config->io_base)
662 {
663 DDB(printk("I/O port mismatch\n"));
664 release_region(devc->base, 16);
665 return 0;
666 }
667 /*
668 * Now continue initialization of the device
669 */
670
671 devc->caps = hw_config->driver_use_1;
672
673 if (!((devc->caps & SB_NO_AUDIO) && (devc->caps & SB_NO_MIDI)) && hw_config->irq > 0)
674 { /* IRQ setup */
675
676 /*
677 * ESS PCI cards do shared PCI IRQ stuff. Since they
678 * will get shared PCI irq lines we must cope.
679 */
680
681 int i=(devc->caps&SB_PCI_IRQ)?SA_SHIRQ:0;
682
683 if (request_irq(hw_config->irq, sbintr, i, "soundblaster", devc) < 0)
684 {
685 printk(KERN_ERR "SB: Can't allocate IRQ%d\n", hw_config->irq);
686 release_region(devc->base, 16);
687 return 0;
688 }
689 devc->irq_ok = 0;
690
691 if (devc->major == 4)
692 if (!sb16_set_irq_hw(devc, devc->irq)) /* Unsupported IRQ */
693 {
694 free_irq(devc->irq, devc);
695 release_region(devc->base, 16);
696 return 0;
697 }
698 if ((devc->type == 0 || devc->type == MDL_ESS) &&
699 devc->major == 3 && devc->minor == 1)
700 { /* Handle various chipsets which claim they are SB Pro compatible */
701 if ((devc->type != 0 && devc->type != MDL_ESS) ||
702 !ess_init(devc, hw_config))
703 {
704 if ((devc->type != 0 && devc->type != MDL_JAZZ &&
705 devc->type != MDL_SMW) || !init_Jazz16(devc, hw_config))
706 {
707 DDB(printk("This is a genuine SB Pro\n"));
708 }
709 }
710 }
711 if (devc->major == 4 && devc->minor <= 11 ) /* Won't work */
712 devc->irq_ok = 1;
713 else
714 {
715 int n;
716
717 for (n = 0; n < 3 && devc->irq_ok == 0; n++)
718 {
719 if (sb_dsp_command(devc, 0xf2)) /* Cause interrupt immediately */
720 {
721 int i;
722
723 for (i = 0; !devc->irq_ok && i < 10000; i++);
724 }
725 }
726 if (!devc->irq_ok)
727 printk(KERN_WARNING "sb: Interrupt test on IRQ%d failed - Probable IRQ conflict\n", devc->irq);
728 else
729 {
730 DDB(printk("IRQ test OK (IRQ%d)\n", devc->irq));
731 }
732 }
733 } /* IRQ setup */
734
735 last_sb = devc;
736
737 switch (devc->major)
738 {
739 case 1: /* SB 1.0 or 1.5 */
740 devc->model = hw_config->card_subtype = MDL_SB1;
741 break;
742
743 case 2: /* SB 2.x */
744 if (devc->minor == 0)
745 devc->model = hw_config->card_subtype = MDL_SB2;
746 else
747 devc->model = hw_config->card_subtype = MDL_SB201;
748 break;
749
750 case 3: /* SB Pro and most clones */
751 switch (devc->model) {
752 case 0:
753 devc->model = hw_config->card_subtype = MDL_SBPRO;
754 if (hw_config->name == NULL)
755 hw_config->name = "Sound Blaster Pro (8 BIT ONLY)";
756 break;
757 case MDL_ESS:
758 ess_dsp_init(devc, hw_config);
759 break;
760 }
761 break;
762
763 case 4:
764 devc->model = hw_config->card_subtype = MDL_SB16;
765 /*
766 * ALS007 and ALS100 return DSP version 4.2 and have 2 post-reset !=0
767 * registers at 0x3c and 0x4c (output ctrl registers on ALS007) whereas
768 * a "standard" SB16 doesn't have a register at 0x4c. ALS100 actively
769 * updates register 0x22 whenever 0x30 changes, as per the SB16 spec.
770 * Since ALS007 doesn't, this can be used to differentiate the 2 cards.
771 */
772 if ((devc->minor == 2) && sb_getmixer(devc,0x3c) && sb_getmixer(devc,0x4c))
773 {
774 mixer30 = sb_getmixer(devc,0x30);
775 sb_setmixer(devc,0x22,(mixer22=sb_getmixer(devc,0x22)) & 0x0f);
776 sb_setmixer(devc,0x30,0xff);
777 /* ALS100 will force 0x30 to 0xf8 like SB16; ALS007 will allow 0xff. */
778 /* Register 0x22 & 0xf0 on ALS100 == 0xf0; on ALS007 it == 0x10. */
779 if ((sb_getmixer(devc,0x30) != 0xff) || ((sb_getmixer(devc,0x22) & 0xf0) != 0x10))
780 {
781 devc->submodel = SUBMDL_ALS100;
782 if (hw_config->name == NULL)
783 hw_config->name = "Sound Blaster 16 (ALS-100)";
784 }
785 else
786 {
787 sb_setmixer(devc,0x3c,0x1f); /* Enable all inputs */
788 sb_setmixer(devc,0x4c,0x1f);
789 sb_setmixer(devc,0x22,mixer22); /* Restore 0x22 to original value */
790 devc->submodel = SUBMDL_ALS007;
791 if (hw_config->name == NULL)
792 hw_config->name = "Sound Blaster 16 (ALS-007)";
793 }
794 sb_setmixer(devc,0x30,mixer30);
795 }
796 else if (hw_config->name == NULL)
797 hw_config->name = "Sound Blaster 16";
798
799 if (hw_config->dma2 == -1)
800 devc->dma16 = devc->dma8;
801 else if (hw_config->dma2 < 5 || hw_config->dma2 > 7)
802 {
803 printk(KERN_WARNING "SB16: Bad or missing 16 bit DMA channel\n");
804 devc->dma16 = devc->dma8;
805 }
806 else
807 devc->dma16 = hw_config->dma2;
808
809 if(!sb16_set_dma_hw(devc)) {
810 free_irq(devc->irq, devc);
811 release_region(hw_config->io_base, 16);
812 return 0;
813 }
814
815 devc->caps |= SB_NO_MIDI;
816 }
817
818 if (!(devc->caps & SB_NO_MIXER))
819 if (devc->major == 3 || devc->major == 4)
820 sb_mixer_init(devc, owner);
821
822 if (!(devc->caps & SB_NO_MIDI))
823 sb_dsp_midi_init(devc, owner);
824
825 if (hw_config->name == NULL)
826 hw_config->name = "Sound Blaster (8 BIT/MONO ONLY)";
827
828 sprintf(name, "%s (%d.%02d)", hw_config->name, devc->major, devc->minor);
829 conf_printf(name, hw_config);
830
831 /*
832 * Assuming that a sound card is Sound Blaster (compatible) is the most common
833 * configuration error and the mother of all problems. Usually sound cards
834 * emulate SB Pro but in addition they have a 16 bit native mode which should be
835 * used in Unix. See Readme.cards for more information about configuring OSS/Free
836 * properly.
837 */
838 if (devc->model <= MDL_SBPRO)
839 {
840 if (devc->major == 3 && devc->minor != 1) /* "True" SB Pro should have v3.1 (rare ones may have 3.2). */
841 {
842 printk(KERN_INFO "This sound card may not be fully Sound Blaster Pro compatible.\n");
843 printk(KERN_INFO "In many cases there is another way to configure OSS so that\n");
844 printk(KERN_INFO "it works properly with OSS (for example in 16 bit mode).\n");
845 printk(KERN_INFO "Please ignore this message if you _really_ have a SB Pro.\n");
846 }
847 else if (!sb_be_quiet && devc->model == MDL_SBPRO)
848 {
849 printk(KERN_INFO "SB DSP version is just %d.%02d which means that your card is\n", devc->major, devc->minor);
850 printk(KERN_INFO "several years old (8 bit only device) or alternatively the sound driver\n");
851 printk(KERN_INFO "is incorrectly configured.\n");
852 }
853 }
854 hw_config->card_subtype = devc->model;
855 hw_config->slots[0]=devc->dev;
856 last_devc = devc; /* For SB MPU detection */
857
858 if (!(devc->caps & SB_NO_AUDIO) && devc->dma8 >= 0)
859 {
860 if (sound_alloc_dma(devc->dma8, "SoundBlaster8"))
861 {
862 printk(KERN_WARNING "Sound Blaster: Can't allocate 8 bit DMA channel %d\n", devc->dma8);
863 }
864 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
865 {
866 if (sound_alloc_dma(devc->dma16, "SoundBlaster16"))
867 printk(KERN_WARNING "Sound Blaster: can't allocate 16 bit DMA channel %d.\n", devc->dma16);
868 }
869 sb_audio_init(devc, name, owner);
870 hw_config->slots[0]=devc->dev;
871 }
872 else
873 {
874 MDB(printk("Sound Blaster: no audio devices found.\n"));
875 }
876 return 1;
877}
878
879/* if (sbmpu) below we allow mpu401 to manage the midi devs
880 otherwise we have to unload them. (Andrzej Krzysztofowicz) */
881
882void sb_dsp_unload(struct address_info *hw_config, int sbmpu)
883{
884 sb_devc *devc;
885
886 devc = audio_devs[hw_config->slots[0]]->devc;
887
888 if (devc && devc->base == hw_config->io_base)
889 {
890 if ((devc->model & MDL_ESS) && devc->pcibase)
891 release_region(devc->pcibase, 8);
892
893 release_region(devc->base, 16);
894
895 if (!(devc->caps & SB_NO_AUDIO))
896 {
897 sound_free_dma(devc->dma8);
898 if (devc->dma16 >= 0)
899 sound_free_dma(devc->dma16);
900 }
901 if (!(devc->caps & SB_NO_AUDIO && devc->caps & SB_NO_MIDI))
902 {
903 if (devc->irq > 0)
904 free_irq(devc->irq, devc);
905
906 sb_mixer_unload(devc);
907 /* We don't have to do this bit any more the UART401 is its own
908 master -- Krzysztof Halasa */
909 /* But we have to do it, if UART401 is not detected */
910 if (!sbmpu)
911 sound_unload_mididev(devc->my_mididev);
912 sound_unload_audiodev(devc->dev);
913 }
914 kfree(devc);
915 }
916 else
917 release_region(hw_config->io_base, 16);
918 if(detected_devc)
919 kfree(detected_devc);
920}
921
922/*
923 * Mixer access routines
924 *
925 * ES1887 modifications: some mixer registers reside in the
926 * range above 0xa0. These must be accessed in another way.
927 */
928
929void sb_setmixer(sb_devc * devc, unsigned int port, unsigned int value)
930{
931 unsigned long flags;
932
933 if (devc->model == MDL_ESS) {
934 ess_setmixer (devc, port, value);
935 return;
936 }
937
938 spin_lock_irqsave(&devc->lock, flags);
939
940 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
941 udelay(20);
942 outb(((unsigned char) (value & 0xff)), MIXER_DATA);
943 udelay(20);
944
945 spin_unlock_irqrestore(&devc->lock, flags);
946}
947
948unsigned int sb_getmixer(sb_devc * devc, unsigned int port)
949{
950 unsigned int val;
951 unsigned long flags;
952
953 if (devc->model == MDL_ESS) return ess_getmixer (devc, port);
954
955 spin_lock_irqsave(&devc->lock, flags);
956
957 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
958 udelay(20);
959 val = inb(MIXER_DATA);
960 udelay(20);
961
962 spin_unlock_irqrestore(&devc->lock, flags);
963
964 return val;
965}
966
967void sb_chgmixer
968 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
969{
970 int value;
971
972 value = sb_getmixer(devc, reg);
973 value = (value & ~mask) | (val & mask);
974 sb_setmixer(devc, reg, value);
975}
976
977/*
978 * MPU401 MIDI initialization.
979 */
980
981static void smw_putmem(sb_devc * devc, int base, int addr, unsigned char val)
982{
983 unsigned long flags;
984
985 spin_lock_irqsave(&jazz16_lock, flags); /* NOT the SB card? */
986
987 outb((addr & 0xff), base + 1); /* Low address bits */
988 outb((addr >> 8), base + 2); /* High address bits */
989 outb((val), base); /* Data */
990
991 spin_unlock_irqrestore(&jazz16_lock, flags);
992}
993
994static unsigned char smw_getmem(sb_devc * devc, int base, int addr)
995{
996 unsigned long flags;
997 unsigned char val;
998
999 spin_lock_irqsave(&jazz16_lock, flags); /* NOT the SB card? */
1000
1001 outb((addr & 0xff), base + 1); /* Low address bits */
1002 outb((addr >> 8), base + 2); /* High address bits */
1003 val = inb(base); /* Data */
1004
1005 spin_unlock_irqrestore(&jazz16_lock, flags);
1006 return val;
1007}
1008
1009static int smw_midi_init(sb_devc * devc, struct address_info *hw_config)
1010{
1011 int mpu_base = hw_config->io_base;
1012 int mp_base = mpu_base + 4; /* Microcontroller base */
1013 int i;
1014 unsigned char control;
1015
1016
1017 /*
1018 * Reset the microcontroller so that the RAM can be accessed
1019 */
1020
1021 control = inb(mpu_base + 7);
1022 outb((control | 3), mpu_base + 7); /* Set last two bits to 1 (?) */
1023 outb(((control & 0xfe) | 2), mpu_base + 7); /* xxxxxxx0 resets the mc */
1024
1025 mdelay(3); /* Wait at least 1ms */
1026
1027 outb((control & 0xfc), mpu_base + 7); /* xxxxxx00 enables RAM */
1028
1029 /*
1030 * Detect microcontroller by probing the 8k RAM area
1031 */
1032 smw_putmem(devc, mp_base, 0, 0x00);
1033 smw_putmem(devc, mp_base, 1, 0xff);
1034 udelay(10);
1035
1036 if (smw_getmem(devc, mp_base, 0) != 0x00 || smw_getmem(devc, mp_base, 1) != 0xff)
1037 {
1038 DDB(printk("SM Wave: No microcontroller RAM detected (%02x, %02x)\n", smw_getmem(devc, mp_base, 0), smw_getmem(devc, mp_base, 1)));
1039 return 0; /* No RAM */
1040 }
1041 /*
1042 * There is RAM so assume it's really a SM Wave
1043 */
1044
1045 devc->model = MDL_SMW;
1046 smw_mixer_init(devc);
1047
1048#ifdef MODULE
1049 if (!smw_ucode)
1050 {
1051 smw_ucodeLen = mod_firmware_load("/etc/sound/midi0001.bin", (void *) &smw_ucode);
1052 smw_free = smw_ucode;
1053 }
1054#endif
1055 if (smw_ucodeLen > 0)
1056 {
1057 if (smw_ucodeLen != 8192)
1058 {
1059 printk(KERN_ERR "SM Wave: Invalid microcode (MIDI0001.BIN) length\n");
1060 return 1;
1061 }
1062 /*
1063 * Download microcode
1064 */
1065
1066 for (i = 0; i < 8192; i++)
1067 smw_putmem(devc, mp_base, i, smw_ucode[i]);
1068
1069 /*
1070 * Verify microcode
1071 */
1072
1073 for (i = 0; i < 8192; i++)
1074 if (smw_getmem(devc, mp_base, i) != smw_ucode[i])
1075 {
1076 printk(KERN_ERR "SM Wave: Microcode verification failed\n");
1077 return 0;
1078 }
1079 }
1080 control = 0;
1081#ifdef SMW_SCSI_IRQ
1082 /*
1083 * Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
1084 * is disabled by default.
1085 *
1086 * FIXME - make this a module option
1087 *
1088 * BTW the Zilog 5380 SCSI controller is located at MPU base + 0x10.
1089 */
1090 {
1091 static unsigned char scsi_irq_bits[] = {
1092 0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0
1093 };
1094 control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1095 }
1096#endif
1097
1098#ifdef SMW_OPL4_ENABLE
1099 /*
1100 * Make the OPL4 chip visible on the PC bus at 0x380.
1101 *
1102 * There is no need to enable this feature since this driver
1103 * doesn't support OPL4 yet. Also there is no RAM in SM Wave so
1104 * enabling OPL4 is pretty useless.
1105 */
1106 control |= 0x10; /* Uses IRQ12 if bit 0x20 == 0 */
1107 /* control |= 0x20; Uncomment this if you want to use IRQ7 */
1108#endif
1109 outb((control | 0x03), mpu_base + 7); /* xxxxxx11 restarts */
1110 hw_config->name = "SoundMan Wave";
1111 return 1;
1112}
1113
1114static int init_Jazz16_midi(sb_devc * devc, struct address_info *hw_config)
1115{
1116 int mpu_base = hw_config->io_base;
1117 int sb_base = devc->base;
1118 int irq = hw_config->irq;
1119
1120 unsigned char bits = 0;
1121 unsigned long flags;
1122
1123 if (irq < 0)
1124 irq *= -1;
1125
1126 if (irq < 1 || irq > 15 ||
1127 jazz_irq_bits[irq] == 0)
1128 {
1129 printk(KERN_ERR "Jazz16: Invalid MIDI interrupt (IRQ%d)\n", irq);
1130 return 0;
1131 }
1132 switch (sb_base)
1133 {
1134 case 0x220:
1135 bits = 1;
1136 break;
1137 case 0x240:
1138 bits = 2;
1139 break;
1140 case 0x260:
1141 bits = 3;
1142 break;
1143 default:
1144 return 0;
1145 }
1146 bits = jazz16_bits = bits << 5;
1147 switch (mpu_base)
1148 {
1149 case 0x310:
1150 bits |= 1;
1151 break;
1152 case 0x320:
1153 bits |= 2;
1154 break;
1155 case 0x330:
1156 bits |= 3;
1157 break;
1158 default:
1159 printk(KERN_ERR "Jazz16: Invalid MIDI I/O port %x\n", mpu_base);
1160 return 0;
1161 }
1162 /*
1163 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
1164 */
1165 spin_lock_irqsave(&jazz16_lock, flags);
1166 outb(0xAF, 0x201);
1167 outb(0x50, 0x201);
1168 outb(bits, 0x201);
1169 spin_unlock_irqrestore(&jazz16_lock, flags);
1170
1171 hw_config->name = "Jazz16";
1172 smw_midi_init(devc, hw_config);
1173
1174 if (!sb_dsp_command(devc, 0xfb))
1175 return 0;
1176
1177 if (!sb_dsp_command(devc, jazz_dma_bits[devc->dma8] |
1178 (jazz_dma_bits[devc->dma16] << 4)))
1179 return 0;
1180
1181 if (!sb_dsp_command(devc, jazz_irq_bits[devc->irq] |
1182 (jazz_irq_bits[irq] << 4)))
1183 return 0;
1184
1185 return 1;
1186}
1187
1188int probe_sbmpu(struct address_info *hw_config, struct module *owner)
1189{
1190 sb_devc *devc = last_devc;
1191 int ret;
1192
1193 if (last_devc == NULL)
1194 return 0;
1195
1196 last_devc = NULL;
1197
1198 if (hw_config->io_base <= 0)
1199 {
1200 /* The real vibra16 is fine about this, but we have to go
1201 wipe up after Cyrix again */
1202
1203 if(devc->model == MDL_SB16 && devc->minor >= 12)
1204 {
1205 unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
1206 sb_setmixer(devc, 0x84, bits | 0x02); /* Disable MPU */
1207 }
1208 return 0;
1209 }
1210
1211#if defined(CONFIG_SOUND_MPU401)
1212 if (devc->model == MDL_ESS)
1213 {
1214 struct resource *ports;
1215 ports = request_region(hw_config->io_base, 2, "mpu401");
1216 if (!ports) {
1217 printk(KERN_ERR "sbmpu: I/O port conflict (%x)\n", hw_config->io_base);
1218 return 0;
1219 }
1220 if (!ess_midi_init(devc, hw_config)) {
1221 release_region(hw_config->io_base, 2);
1222 return 0;
1223 }
1224 hw_config->name = "ESS1xxx MPU";
1225 devc->midi_irq_cookie = NULL;
1226 if (!probe_mpu401(hw_config, ports)) {
1227 release_region(hw_config->io_base, 2);
1228 return 0;
1229 }
1230 attach_mpu401(hw_config, owner);
1231 if (last_sb->irq == -hw_config->irq)
1232 last_sb->midi_irq_cookie=(void *)hw_config->slots[1];
1233 return 1;
1234 }
1235#endif
1236
1237 switch (devc->model)
1238 {
1239 case MDL_SB16:
1240 if (hw_config->io_base != 0x300 && hw_config->io_base != 0x330)
1241 {
1242 printk(KERN_ERR "SB16: Invalid MIDI port %x\n", hw_config->io_base);
1243 return 0;
1244 }
1245 hw_config->name = "Sound Blaster 16";
1246 if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1247 hw_config->irq = -devc->irq;
1248 if (devc->minor > 12) /* What is Vibra's version??? */
1249 sb16_set_mpu_port(devc, hw_config);
1250 break;
1251
1252 case MDL_JAZZ:
1253 if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1254 hw_config->irq = -devc->irq;
1255 if (!init_Jazz16_midi(devc, hw_config))
1256 return 0;
1257 break;
1258
1259 case MDL_YMPCI:
1260 hw_config->name = "Yamaha PCI Legacy";
1261 printk("Yamaha PCI legacy UART401 check.\n");
1262 break;
1263 default:
1264 return 0;
1265 }
1266
1267 ret = probe_uart401(hw_config, owner);
1268 if (ret)
1269 last_sb->midi_irq_cookie=midi_devs[hw_config->slots[4]]->devc;
1270 return ret;
1271}
1272
1273void unload_sbmpu(struct address_info *hw_config)
1274{
1275#if defined(CONFIG_SOUND_MPU401)
1276 if (!strcmp (hw_config->name, "ESS1xxx MPU")) {
1277 unload_mpu401(hw_config);
1278 return;
1279 }
1280#endif
1281 unload_uart401(hw_config);
1282}
1283
1284EXPORT_SYMBOL(sb_dsp_init);
1285EXPORT_SYMBOL(sb_dsp_detect);
1286EXPORT_SYMBOL(sb_dsp_unload);
1287EXPORT_SYMBOL(sb_be_quiet);
1288EXPORT_SYMBOL(probe_sbmpu);
1289EXPORT_SYMBOL(unload_sbmpu);
1290EXPORT_SYMBOL(smw_free);
1291MODULE_LICENSE("GPL");
diff --git a/sound/oss/sb_ess.c b/sound/oss/sb_ess.c
new file mode 100644
index 000000000000..fae05fe3de43
--- /dev/null
+++ b/sound/oss/sb_ess.c
@@ -0,0 +1,1832 @@
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. Interresting ones are 0x7f, 0x7d and 0x7a. They are
101 * related to the Audio 2 channel. I also was suprised about the consequenses
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 decribed
109 * as if it's exactly the same as register 0xa1. This is *NOT* true. The
110 * 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 allways 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 operation, and uses the
121 * same dma as audio 1: your ess changes into a funny echo machine.
122 *
123 * Received the new 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. It's 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 * it's 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 * it's 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. Futhermore 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 * recordig 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_WARN "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 DEB(printk("Entered ess_dsp_reset()\n"));
869
870 outb(3, DSP_RESET); /* Reset FIFO too */
871
872 udelay(10);
873 outb(0, DSP_RESET);
874 udelay(30);
875
876 for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
877
878 if (inb(DSP_READ) != 0xAA) {
879 DDB(printk("sb: No response to RESET\n"));
880 return 0; /* Sorry */
881 }
882 ess_extended (devc);
883
884 DEB(printk("sb_dsp_reset() OK\n"));
885
886#ifdef FKS_LOGGING
887printk(KERN_INFO "FKS: dsp_reset 2\n");
888ess_show_mixerregs (devc);
889#endif
890
891 return 1;
892}
893
894static int ess_irq_bits (int irq)
895{
896 switch (irq) {
897 case 2:
898 case 9:
899 return 0;
900
901 case 5:
902 return 1;
903
904 case 7:
905 return 2;
906
907 case 10:
908 return 3;
909
910 default:
911 printk(KERN_ERR "ESS1688: Invalid IRQ %d\n", irq);
912 return -1;
913 }
914}
915
916/*
917 * Set IRQ configuration register for all ESS models
918 */
919static int ess_common_set_irq_hw (sb_devc * devc)
920{
921 int irq_bits;
922
923 if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return 0;
924
925 if (!ess_write (devc, 0xb1, 0x50 | (irq_bits << 2))) {
926 printk(KERN_ERR "ES1688: Failed to write to IRQ config register\n");
927 return 0;
928 }
929 return 1;
930}
931
932/*
933 * I wanna use modern ES1887 mixer irq handling. Funny is the
934 * fact that my BIOS wants the same. But suppose someone's BIOS
935 * doesn't do this!
936 * This is independent of duplex. If there's a 1887 this will
937 * prevent it from going into 1888 mode.
938 */
939static void ess_es1887_set_irq_hw (sb_devc * devc)
940{
941 int irq_bits;
942
943 if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return;
944
945 ess_chgmixer (devc, 0x7f, 0x0f, 0x01 | ((irq_bits + 1) << 1));
946}
947
948static int ess_set_irq_hw (sb_devc * devc)
949{
950 if (devc->submodel == SUBMDL_ES1887) ess_es1887_set_irq_hw (devc);
951
952 return ess_common_set_irq_hw (devc);
953}
954
955#ifdef FKS_TEST
956
957/*
958 * FKS_test:
959 * for ES1887: 00, 18, non wr bits: 0001 1000
960 * for ES1868: 00, b8, non wr bits: 1011 1000
961 * for ES1888: 00, f8, non wr bits: 1111 1000
962 * for ES1688: 00, f8, non wr bits: 1111 1000
963 * + ES968
964 */
965
966static void FKS_test (sb_devc * devc)
967{
968 int val1, val2;
969 val1 = ess_getmixer (devc, 0x64);
970 ess_setmixer (devc, 0x64, ~val1);
971 val2 = ess_getmixer (devc, 0x64) ^ ~val1;
972 ess_setmixer (devc, 0x64, val1);
973 val1 ^= ess_getmixer (devc, 0x64);
974printk (KERN_INFO "FKS: FKS_test %02x, %02x\n", (val1 & 0x0ff), (val2 & 0x0ff));
975};
976#endif
977
978static unsigned int ess_identify (sb_devc * devc)
979{
980 unsigned int val;
981 unsigned long flags;
982
983 spin_lock_irqsave(&devc->lock, flags);
984 outb(((unsigned char) (0x40 & 0xff)), MIXER_ADDR);
985
986 udelay(20);
987 val = inb(MIXER_DATA) << 8;
988 udelay(20);
989 val |= inb(MIXER_DATA);
990 udelay(20);
991 spin_unlock_irqrestore(&devc->lock, flags);
992
993 return val;
994}
995
996/*
997 * ESS technology describes a detection scheme in their docs. It involves
998 * fiddling with the bits in certain mixer registers. ess_probe is supposed
999 * to help.
1000 *
1001 * FKS: tracing shows ess_probe writes wrong value to 0x64. Bit 3 reads 1, but
1002 * should be written 0 only. Check this.
1003 */
1004static int ess_probe (sb_devc * devc, int reg, int xorval)
1005{
1006 int val1, val2, val3;
1007
1008 val1 = ess_getmixer (devc, reg);
1009 val2 = val1 ^ xorval;
1010 ess_setmixer (devc, reg, val2);
1011 val3 = ess_getmixer (devc, reg);
1012 ess_setmixer (devc, reg, val1);
1013
1014 return (val2 == val3);
1015}
1016
1017int ess_init(sb_devc * devc, struct address_info *hw_config)
1018{
1019 unsigned char cfg;
1020 int ess_major = 0, ess_minor = 0;
1021 int i;
1022 static char name[100], modelname[10];
1023
1024 /*
1025 * Try to detect ESS chips.
1026 */
1027
1028 sb_dsp_command(devc, 0xe7); /* Return identification */
1029
1030 for (i = 1000; i; i--) {
1031 if (inb(DSP_DATA_AVAIL) & 0x80) {
1032 if (ess_major == 0) {
1033 ess_major = inb(DSP_READ);
1034 } else {
1035 ess_minor = inb(DSP_READ);
1036 break;
1037 }
1038 }
1039 }
1040
1041 if (ess_major == 0) return 0;
1042
1043 if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80) {
1044 sprintf(name, "ESS ES488 AudioDrive (rev %d)",
1045 ess_minor & 0x0f);
1046 hw_config->name = name;
1047 devc->model = MDL_SBPRO;
1048 return 1;
1049 }
1050
1051 /*
1052 * This the detection heuristic of ESS technology, though somewhat
1053 * changed to actually make it work.
1054 * This results in the following detection steps:
1055 * - distinct between ES688 and ES1688+ (as always done in this driver)
1056 * if ES688 we're ready
1057 * - try to detect ES1868, ES1869 or ES1878 (ess_identify)
1058 * if successful we're ready
1059 * - try to detect ES1888, ES1887 or ES1788 (aim: detect ES1887)
1060 * if successful we're ready
1061 * - Dunno. Must be 1688. Will do in general
1062 *
1063 * This is the most BETA part of the software: Will the detection
1064 * always work?
1065 */
1066 devc->model = MDL_ESS;
1067 devc->submodel = ess_minor & 0x0f;
1068
1069 if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80) {
1070 char *chip = NULL;
1071 int submodel = -1;
1072
1073 switch (devc->sbmo.esstype) {
1074 case ESSTYPE_DETECT:
1075 case ESSTYPE_LIKE20:
1076 break;
1077 case 688:
1078 submodel = 0x00;
1079 break;
1080 case 1688:
1081 submodel = 0x08;
1082 break;
1083 case 1868:
1084 submodel = SUBMDL_ES1868;
1085 break;
1086 case 1869:
1087 submodel = SUBMDL_ES1869;
1088 break;
1089 case 1788:
1090 submodel = SUBMDL_ES1788;
1091 break;
1092 case 1878:
1093 submodel = SUBMDL_ES1878;
1094 break;
1095 case 1879:
1096 submodel = SUBMDL_ES1879;
1097 break;
1098 case 1887:
1099 submodel = SUBMDL_ES1887;
1100 break;
1101 case 1888:
1102 submodel = SUBMDL_ES1888;
1103 break;
1104 default:
1105 printk (KERN_ERR "Invalid esstype=%d specified\n", devc->sbmo.esstype);
1106 return 0;
1107 };
1108 if (submodel != -1) {
1109 devc->submodel = submodel;
1110 sprintf (modelname, "ES%d", devc->sbmo.esstype);
1111 chip = modelname;
1112 };
1113 if (chip == NULL && (ess_minor & 0x0f) < 8) {
1114 chip = "ES688";
1115 };
1116#ifdef FKS_TEST
1117FKS_test (devc);
1118#endif
1119 /*
1120 * If Nothing detected yet, and we want 2.0 behaviour...
1121 * Then let's assume it's ES1688.
1122 */
1123 if (chip == NULL && devc->sbmo.esstype == ESSTYPE_LIKE20) {
1124 chip = "ES1688";
1125 };
1126
1127 if (chip == NULL) {
1128 int type;
1129
1130 type = ess_identify (devc);
1131
1132 switch (type) {
1133 case 0x1868:
1134 chip = "ES1868";
1135 devc->submodel = SUBMDL_ES1868;
1136 break;
1137 case 0x1869:
1138 chip = "ES1869";
1139 devc->submodel = SUBMDL_ES1869;
1140 break;
1141 case 0x1878:
1142 chip = "ES1878";
1143 devc->submodel = SUBMDL_ES1878;
1144 break;
1145 case 0x1879:
1146 chip = "ES1879";
1147 devc->submodel = SUBMDL_ES1879;
1148 break;
1149 default:
1150 if ((type & 0x00ff) != ((type >> 8) & 0x00ff)) {
1151 printk ("ess_init: Unrecognized %04x\n", type);
1152 }
1153 };
1154 };
1155#if 0
1156 /*
1157 * this one failed:
1158 * the probing of bit 4 is another thought: from ES1788 and up, all
1159 * chips seem to have hardware volume control. Bit 4 is readonly to
1160 * check if a hardware volume interrupt has fired.
1161 * Cause ES688/ES1688 don't have this feature, bit 4 might be writeable
1162 * for these chips.
1163 */
1164 if (chip == NULL && !ess_probe(devc, 0x64, (1 << 4))) {
1165#endif
1166 /*
1167 * the probing of bit 2 is my idea. The ES1887 docs want me to probe
1168 * bit 3. This results in ES1688 being detected as ES1788.
1169 * Bit 2 is for "Enable HWV IRQE", but as ES(1)688 chips don't have
1170 * HardWare Volume, I think they don't have this IRQE.
1171 */
1172 if (chip == NULL && ess_probe(devc, 0x64, (1 << 2))) {
1173 if (ess_probe (devc, 0x70, 0x7f)) {
1174 if (ess_probe (devc, 0x64, (1 << 5))) {
1175 chip = "ES1887";
1176 devc->submodel = SUBMDL_ES1887;
1177 } else {
1178 chip = "ES1888";
1179 devc->submodel = SUBMDL_ES1888;
1180 }
1181 } else {
1182 chip = "ES1788";
1183 devc->submodel = SUBMDL_ES1788;
1184 }
1185 };
1186 if (chip == NULL) {
1187 chip = "ES1688";
1188 };
1189
1190 printk ( KERN_INFO "ESS chip %s %s%s\n"
1191 , chip
1192 , ( devc->sbmo.esstype == ESSTYPE_DETECT || devc->sbmo.esstype == ESSTYPE_LIKE20
1193 ? "detected"
1194 : "specified"
1195 )
1196 , ( devc->sbmo.esstype == ESSTYPE_LIKE20
1197 ? " (kernel 2.0 compatible)"
1198 : ""
1199 )
1200 );
1201
1202 sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f);
1203 } else {
1204 strcpy(name, "Jazz16");
1205 }
1206
1207 /* AAS: info stolen from ALSA: these boards have different clocks */
1208 switch(devc->submodel) {
1209/* APPARENTLY NOT 1869 AND 1887
1210 case SUBMDL_ES1869:
1211 case SUBMDL_ES1887:
1212*/
1213 case SUBMDL_ES1888:
1214 devc->caps |= SB_CAP_ES18XX_RATE;
1215 break;
1216 }
1217
1218 hw_config->name = name;
1219 /* FKS: sb_dsp_reset to enable extended mode???? */
1220 sb_dsp_reset(devc); /* Turn on extended mode */
1221
1222 /*
1223 * Enable joystick and OPL3
1224 */
1225 cfg = ess_getmixer (devc, 0x40);
1226 ess_setmixer (devc, 0x40, cfg | 0x03);
1227 if (devc->submodel >= 8) { /* ES1688 */
1228 devc->caps |= SB_NO_MIDI; /* ES1688 uses MPU401 MIDI mode */
1229 }
1230 sb_dsp_reset (devc);
1231
1232 /*
1233 * This is important! If it's not done, the IRQ probe in sb_dsp_init
1234 * may fail.
1235 */
1236 return ess_set_irq_hw (devc);
1237}
1238
1239static int ess_set_dma_hw(sb_devc * devc)
1240{
1241 unsigned char cfg, dma_bits = 0, dma16_bits;
1242 int dma;
1243
1244#ifdef FKS_LOGGING
1245printk(KERN_INFO "ess_set_dma_hw: dma8=%d,dma16=%d,dup=%d\n"
1246, devc->dma8, devc->dma16, devc->duplex);
1247#endif
1248
1249 /*
1250 * FKS: It seems as if this duplex flag isn't set yet. Check it.
1251 */
1252 dma = devc->dma8;
1253
1254 if (dma > 3 || dma < 0 || dma == 2) {
1255 dma_bits = 0;
1256 printk(KERN_ERR "ESS1688: Invalid DMA8 %d\n", dma);
1257 return 0;
1258 } else {
1259 /* Extended mode DMA enable */
1260 cfg = 0x50;
1261
1262 if (dma == 3) {
1263 dma_bits = 3;
1264 } else {
1265 dma_bits = dma + 1;
1266 }
1267 }
1268
1269 if (!ess_write (devc, 0xb2, cfg | (dma_bits << 2))) {
1270 printk(KERN_ERR "ESS1688: Failed to write to DMA config register\n");
1271 return 0;
1272 }
1273
1274 if (devc->duplex) {
1275 dma = devc->dma16;
1276 dma16_bits = 0;
1277
1278 if (dma >= 0) {
1279 switch (dma) {
1280 case 0:
1281 dma_bits = 0x04;
1282 break;
1283 case 1:
1284 dma_bits = 0x05;
1285 break;
1286 case 3:
1287 dma_bits = 0x06;
1288 break;
1289 case 5:
1290 dma_bits = 0x07;
1291 dma16_bits = 0x20;
1292 break;
1293 default:
1294 printk(KERN_ERR "ESS1887: Invalid DMA16 %d\n", dma);
1295 return 0;
1296 };
1297 ess_chgmixer (devc, 0x78, 0x20, dma16_bits);
1298 ess_chgmixer (devc, 0x7d, 0x07, dma_bits);
1299 }
1300 }
1301 return 1;
1302}
1303
1304/*
1305 * This one is called from sb_dsp_init.
1306 *
1307 * Return values:
1308 * 0: Failed
1309 * 1: Succeeded or doesn't apply (not SUBMDL_ES1887)
1310 */
1311int ess_dsp_init (sb_devc *devc, struct address_info *hw_config)
1312{
1313 /*
1314 * Caller also checks this, but anyway
1315 */
1316 if (devc->model != MDL_ESS) {
1317 printk (KERN_INFO "ess_dsp_init for non ESS chip\n");
1318 return 1;
1319 }
1320 /*
1321 * This for ES1887 to run Full Duplex. Actually ES1888
1322 * is allowed to do so too. I have no idea yet if this
1323 * will work for ES1888 however.
1324 *
1325 * For SB16 having both dma8 and dma16 means enable
1326 * Full Duplex. Let's try this for ES1887 too
1327 *
1328 */
1329 if (devc->submodel == SUBMDL_ES1887) {
1330 if (hw_config->dma2 != -1) {
1331 devc->dma16 = hw_config->dma2;
1332 }
1333 /*
1334 * devc->duplex initialization is put here, cause
1335 * ess_set_dma_hw needs it.
1336 */
1337 if (devc->dma8 != devc->dma16 && devc->dma16 != -1) {
1338 devc->duplex = 1;
1339 }
1340 }
1341 if (!ess_set_dma_hw (devc)) {
1342 free_irq(devc->irq, devc);
1343 return 0;
1344 }
1345 return 1;
1346}
1347
1348/****************************************************************************
1349 * *
1350 * ESS mixer *
1351 * *
1352 ****************************************************************************/
1353
1354#define ES688_RECORDING_DEVICES \
1355 ( SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD )
1356#define ES688_MIXER_DEVICES \
1357 ( SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE \
1358 | SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME \
1359 | SOUND_MASK_LINE2 | SOUND_MASK_SPEAKER )
1360
1361#define ES1688_RECORDING_DEVICES \
1362 ( ES688_RECORDING_DEVICES )
1363#define ES1688_MIXER_DEVICES \
1364 ( ES688_MIXER_DEVICES | SOUND_MASK_RECLEV )
1365
1366#define ES1887_RECORDING_DEVICES \
1367 ( ES1688_RECORDING_DEVICES | SOUND_MASK_LINE2 | SOUND_MASK_SYNTH)
1368#define ES1887_MIXER_DEVICES \
1369 ( ES1688_MIXER_DEVICES )
1370
1371/*
1372 * Mixer registers of ES1887
1373 *
1374 * These registers specifically take care of recording levels. To make the
1375 * mapping from playback devices to recording devices every recording
1376 * devices = playback device + ES_REC_MIXER_RECDIFF
1377 */
1378#define ES_REC_MIXER_RECBASE (SOUND_MIXER_LINE3 + 1)
1379#define ES_REC_MIXER_RECDIFF (ES_REC_MIXER_RECBASE - SOUND_MIXER_SYNTH)
1380
1381#define ES_REC_MIXER_RECSYNTH (SOUND_MIXER_SYNTH + ES_REC_MIXER_RECDIFF)
1382#define ES_REC_MIXER_RECPCM (SOUND_MIXER_PCM + ES_REC_MIXER_RECDIFF)
1383#define ES_REC_MIXER_RECSPEAKER (SOUND_MIXER_SPEAKER + ES_REC_MIXER_RECDIFF)
1384#define ES_REC_MIXER_RECLINE (SOUND_MIXER_LINE + ES_REC_MIXER_RECDIFF)
1385#define ES_REC_MIXER_RECMIC (SOUND_MIXER_MIC + ES_REC_MIXER_RECDIFF)
1386#define ES_REC_MIXER_RECCD (SOUND_MIXER_CD + ES_REC_MIXER_RECDIFF)
1387#define ES_REC_MIXER_RECIMIX (SOUND_MIXER_IMIX + ES_REC_MIXER_RECDIFF)
1388#define ES_REC_MIXER_RECALTPCM (SOUND_MIXER_ALTPCM + ES_REC_MIXER_RECDIFF)
1389#define ES_REC_MIXER_RECRECLEV (SOUND_MIXER_RECLEV + ES_REC_MIXER_RECDIFF)
1390#define ES_REC_MIXER_RECIGAIN (SOUND_MIXER_IGAIN + ES_REC_MIXER_RECDIFF)
1391#define ES_REC_MIXER_RECOGAIN (SOUND_MIXER_OGAIN + ES_REC_MIXER_RECDIFF)
1392#define ES_REC_MIXER_RECLINE1 (SOUND_MIXER_LINE1 + ES_REC_MIXER_RECDIFF)
1393#define ES_REC_MIXER_RECLINE2 (SOUND_MIXER_LINE2 + ES_REC_MIXER_RECDIFF)
1394#define ES_REC_MIXER_RECLINE3 (SOUND_MIXER_LINE3 + ES_REC_MIXER_RECDIFF)
1395
1396static mixer_tab es688_mix = {
1397MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
1398MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1399MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1400MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1401MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1402MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1403MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1404MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1405MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1406MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1407MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1408MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0),
1409MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1410MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1411MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1412MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1413MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1414};
1415
1416/*
1417 * The ES1688 specifics... hopefully correct...
1418 * - 6 bit master volume
1419 * I was wrong, ES1888 docs say ES1688 didn't have it.
1420 * - RECLEV control
1421 * These may apply to ES688 too. I have no idea.
1422 */
1423static mixer_tab es1688_mix = {
1424MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
1425MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1426MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1427MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1428MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1429MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1430MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1431MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1432MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1433MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1434MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1435MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1436MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1437MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1438MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1439MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1440MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1441};
1442
1443static mixer_tab es1688later_mix = {
1444MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1445MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1446MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1447MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1448MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1449MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1450MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1451MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1452MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1453MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1454MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1455MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1456MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1457MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1458MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1459MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1460MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1461};
1462
1463/*
1464 * This one is for all ESS chips with a record mixer.
1465 * It's not used (yet) however
1466 */
1467static mixer_tab es_rec_mix = {
1468MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1469MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1470MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1471MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1472MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1473MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1474MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1475MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1476MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1477MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1478MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1479MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1480MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1481MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1482MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1483MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1484MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
1485MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
1486MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
1487MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
1488MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
1489MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
1490MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
1491MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
1492MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1493MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
1494MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
1495MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
1496MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
1497MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
1498MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
1499};
1500
1501/*
1502 * This one is for ES1887. It's little different from es_rec_mix: it
1503 * has 0x7c for PCM playback level. This is because ES1887 uses
1504 * Audio 2 for playback.
1505 */
1506static mixer_tab es1887_mix = {
1507MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1508MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1509MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1510MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1511MIX_ENT(SOUND_MIXER_PCM, 0x7c, 7, 4, 0x7c, 3, 4),
1512MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1513MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1514MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1515MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1516MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1517MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1518MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1519MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1520MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1521MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1522MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1523MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
1524MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
1525MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
1526MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
1527MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
1528MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
1529MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
1530MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
1531MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1532MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
1533MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
1534MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
1535MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
1536MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
1537MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
1538};
1539
1540static int ess_has_rec_mixer (int submodel)
1541{
1542 switch (submodel) {
1543 case SUBMDL_ES1887:
1544 return 1;
1545 default:
1546 return 0;
1547 };
1548};
1549
1550#ifdef FKS_LOGGING
1551static int ess_mixer_mon_regs[]
1552 = { 0x70, 0x71, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7d, 0x7f
1553 , 0xa1, 0xa2, 0xa4, 0xa5, 0xa8, 0xa9
1554 , 0xb1, 0xb2, 0xb4, 0xb5, 0xb6, 0xb7, 0xb9
1555 , 0x00};
1556
1557static void ess_show_mixerregs (sb_devc *devc)
1558{
1559 int *mp = ess_mixer_mon_regs;
1560
1561return;
1562
1563 while (*mp != 0) {
1564 printk (KERN_INFO "res (%x)=%x\n", *mp, (int)(ess_getmixer (devc, *mp)));
1565 mp++;
1566 }
1567}
1568#endif
1569
1570void ess_setmixer (sb_devc * devc, unsigned int port, unsigned int value)
1571{
1572 unsigned long flags;
1573
1574#ifdef FKS_LOGGING
1575printk(KERN_INFO "FKS: write mixer %x: %x\n", port, value);
1576#endif
1577
1578 spin_lock_irqsave(&devc->lock, flags);
1579 if (port >= 0xa0) {
1580 ess_write (devc, port, value);
1581 } else {
1582 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
1583
1584 udelay(20);
1585 outb(((unsigned char) (value & 0xff)), MIXER_DATA);
1586 udelay(20);
1587 };
1588 spin_unlock_irqrestore(&devc->lock, flags);
1589}
1590
1591unsigned int ess_getmixer (sb_devc * devc, unsigned int port)
1592{
1593 unsigned int val;
1594 unsigned long flags;
1595
1596 spin_lock_irqsave(&devc->lock, flags);
1597
1598 if (port >= 0xa0) {
1599 val = ess_read (devc, port);
1600 } else {
1601 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
1602
1603 udelay(20);
1604 val = inb(MIXER_DATA);
1605 udelay(20);
1606 }
1607 spin_unlock_irqrestore(&devc->lock, flags);
1608
1609 return val;
1610}
1611
1612static void ess_chgmixer
1613 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
1614{
1615 int value;
1616
1617 value = ess_getmixer (devc, reg);
1618 value = (value & ~mask) | (val & mask);
1619 ess_setmixer (devc, reg, value);
1620}
1621
1622/*
1623 * ess_mixer_init must be called from sb_mixer_init
1624 */
1625void ess_mixer_init (sb_devc * devc)
1626{
1627 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
1628
1629 /*
1630 * Take care of ES1887 specifics...
1631 */
1632 switch (devc->submodel) {
1633 case SUBMDL_ES1887:
1634 devc->supported_devices = ES1887_MIXER_DEVICES;
1635 devc->supported_rec_devices = ES1887_RECORDING_DEVICES;
1636#ifdef FKS_LOGGING
1637printk (KERN_INFO "FKS: ess_mixer_init dup = %d\n", devc->duplex);
1638#endif
1639 if (devc->duplex) {
1640 devc->iomap = &es1887_mix;
1641 devc->iomap_sz = ARRAY_SIZE(es1887_mix);
1642 } else {
1643 devc->iomap = &es_rec_mix;
1644 devc->iomap_sz = ARRAY_SIZE(es_rec_mix);
1645 }
1646 break;
1647 default:
1648 if (devc->submodel < 8) {
1649 devc->supported_devices = ES688_MIXER_DEVICES;
1650 devc->supported_rec_devices = ES688_RECORDING_DEVICES;
1651 devc->iomap = &es688_mix;
1652 devc->iomap_sz = ARRAY_SIZE(es688_mix);
1653 } else {
1654 /*
1655 * es1688 has 4 bits master vol.
1656 * later chips have 6 bits (?)
1657 */
1658 devc->supported_devices = ES1688_MIXER_DEVICES;
1659 devc->supported_rec_devices = ES1688_RECORDING_DEVICES;
1660 if (devc->submodel < 0x10) {
1661 devc->iomap = &es1688_mix;
1662 devc->iomap_sz = ARRAY_SIZE(es688_mix);
1663 } else {
1664 devc->iomap = &es1688later_mix;
1665 devc->iomap_sz = ARRAY_SIZE(es1688later_mix);
1666 }
1667 }
1668 }
1669}
1670
1671/*
1672 * Changing playback levels at an ESS chip with record mixer means having to
1673 * take care of recording levels of recorded inputs (devc->recmask) too!
1674 */
1675int ess_mixer_set(sb_devc *devc, int dev, int left, int right)
1676{
1677 if (ess_has_rec_mixer (devc->submodel) && (devc->recmask & (1 << dev))) {
1678 sb_common_mixer_set (devc, dev + ES_REC_MIXER_RECDIFF, left, right);
1679 }
1680 return sb_common_mixer_set (devc, dev, left, right);
1681}
1682
1683/*
1684 * After a sb_dsp_reset extended register 0xb4 (RECLEV) is reset too. After
1685 * sb_dsp_reset RECLEV has to be restored. This is where ess_mixer_reload
1686 * helps.
1687 */
1688void ess_mixer_reload (sb_devc *devc, int dev)
1689{
1690 int left, right, value;
1691
1692 value = devc->levels[dev];
1693 left = value & 0x000000ff;
1694 right = (value & 0x0000ff00) >> 8;
1695
1696 sb_common_mixer_set(devc, dev, left, right);
1697}
1698
1699static int es_rec_set_recmask(sb_devc * devc, int mask)
1700{
1701 int i, i_mask, cur_mask, diff_mask;
1702 int value, left, right;
1703
1704#ifdef FKS_LOGGING
1705printk (KERN_INFO "FKS: es_rec_set_recmask mask = %x\n", mask);
1706#endif
1707 /*
1708 * Changing the recmask on an ESS chip with recording mixer means:
1709 * (1) Find the differences
1710 * (2) For "turned-on" inputs: make the recording level the playback level
1711 * (3) For "turned-off" inputs: make the recording level zero
1712 */
1713 cur_mask = devc->recmask;
1714 diff_mask = (cur_mask ^ mask);
1715
1716 for (i = 0; i < 32; i++) {
1717 i_mask = (1 << i);
1718 if (diff_mask & i_mask) { /* Difference? (1) */
1719 if (mask & i_mask) { /* Turn it on (2) */
1720 value = devc->levels[i];
1721 left = value & 0x000000ff;
1722 right = (value & 0x0000ff00) >> 8;
1723 } else { /* Turn it off (3) */
1724 left = 0;
1725 left = 0;
1726 right = 0;
1727 }
1728 sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right);
1729 }
1730 }
1731 return mask;
1732}
1733
1734int ess_set_recmask(sb_devc * devc, int *mask)
1735{
1736 /* This applies to ESS chips with record mixers only! */
1737
1738 if (ess_has_rec_mixer (devc->submodel)) {
1739 *mask = es_rec_set_recmask (devc, *mask);
1740 return 1; /* Applied */
1741 } else {
1742 return 0; /* Not applied */
1743 }
1744}
1745
1746/*
1747 * ess_mixer_reset must be called from sb_mixer_reset
1748 */
1749int ess_mixer_reset (sb_devc * devc)
1750{
1751 /*
1752 * Separate actions for ESS chips with a record mixer:
1753 */
1754 if (ess_has_rec_mixer (devc->submodel)) {
1755 switch (devc->submodel) {
1756 case SUBMDL_ES1887:
1757 /*
1758 * Separate actions for ES1887:
1759 * Change registers 7a and 1c to make the record mixer the
1760 * actual recording source.
1761 */
1762 ess_chgmixer(devc, 0x7a, 0x18, 0x08);
1763 ess_chgmixer(devc, 0x1c, 0x07, 0x07);
1764 break;
1765 };
1766 /*
1767 * Call set_recmask for proper initialization
1768 */
1769 devc->recmask = devc->supported_rec_devices;
1770 es_rec_set_recmask(devc, 0);
1771 devc->recmask = 0;
1772
1773 return 1; /* We took care of recmask. */
1774 } else {
1775 return 0; /* We didn't take care; caller do it */
1776 }
1777}
1778
1779/****************************************************************************
1780 * *
1781 * ESS midi *
1782 * *
1783 ****************************************************************************/
1784
1785/*
1786 * FKS: IRQ may be shared. Hm. And if so? Then What?
1787 */
1788int ess_midi_init(sb_devc * devc, struct address_info *hw_config)
1789{
1790 unsigned char cfg, tmp;
1791
1792 cfg = ess_getmixer (devc, 0x40) & 0x03;
1793
1794 if (devc->submodel < 8) {
1795 ess_setmixer (devc, 0x40, cfg | 0x03); /* Enable OPL3 & joystick */
1796 return 0; /* ES688 doesn't support MPU401 mode */
1797 }
1798 tmp = (hw_config->io_base & 0x0f0) >> 4;
1799
1800 if (tmp > 3) {
1801 ess_setmixer (devc, 0x40, cfg);
1802 return 0;
1803 }
1804 cfg |= tmp << 3;
1805
1806 tmp = 1; /* MPU enabled without interrupts */
1807
1808 /* May be shared: if so the value is -ve */
1809
1810 switch (abs(hw_config->irq)) {
1811 case 9:
1812 tmp = 0x4;
1813 break;
1814 case 5:
1815 tmp = 0x5;
1816 break;
1817 case 7:
1818 tmp = 0x6;
1819 break;
1820 case 10:
1821 tmp = 0x7;
1822 break;
1823 default:
1824 return 0;
1825 }
1826
1827 cfg |= tmp << 5;
1828 ess_setmixer (devc, 0x40, cfg | 0x03);
1829
1830 return 1;
1831}
1832
diff --git a/sound/oss/sb_ess.h b/sound/oss/sb_ess.h
new file mode 100644
index 000000000000..38aa072e01f2
--- /dev/null
+++ b/sound/oss/sb_ess.h
@@ -0,0 +1,34 @@
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
new file mode 100644
index 000000000000..ed3bd0640ffd
--- /dev/null
+++ b/sound/oss/sb_midi.c
@@ -0,0 +1,205 @@
1/*
2 * sound/sb_dsp.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
16#include "sound_config.h"
17
18#include "sb.h"
19#undef SB_TEST_IRQ
20
21/*
22 * The DSP channel can be used either for input or output. Variable
23 * 'sb_irq_mode' will be set when the program calls read or write first time
24 * after open. Current version doesn't support mode changes without closing
25 * and reopening the device. Support for this feature may be implemented in a
26 * future version of this driver.
27 */
28
29
30static int sb_midi_open(int dev, int mode,
31 void (*input) (int dev, unsigned char data),
32 void (*output) (int dev)
33)
34{
35 sb_devc *devc = midi_devs[dev]->devc;
36 unsigned long flags;
37
38 if (devc == NULL)
39 return -ENXIO;
40
41 spin_lock_irqsave(&devc->lock, flags);
42 if (devc->opened)
43 {
44 spin_unlock_irqrestore(&devc->lock, flags);
45 return -EBUSY;
46 }
47 devc->opened = 1;
48 spin_unlock_irqrestore(&devc->lock, flags);
49
50 devc->irq_mode = IMODE_MIDI;
51 devc->midi_broken = 0;
52
53 sb_dsp_reset(devc);
54
55 if (!sb_dsp_command(devc, 0x35)) /* Start MIDI UART mode */
56 {
57 devc->opened = 0;
58 return -EIO;
59 }
60 devc->intr_active = 1;
61
62 if (mode & OPEN_READ)
63 {
64 devc->input_opened = 1;
65 devc->midi_input_intr = input;
66 }
67 return 0;
68}
69
70static void sb_midi_close(int dev)
71{
72 sb_devc *devc = midi_devs[dev]->devc;
73 unsigned long flags;
74
75 if (devc == NULL)
76 return;
77
78 spin_lock_irqsave(&devc->lock, flags);
79 sb_dsp_reset(devc);
80 devc->intr_active = 0;
81 devc->input_opened = 0;
82 devc->opened = 0;
83 spin_unlock_irqrestore(&devc->lock, flags);
84}
85
86static int sb_midi_out(int dev, unsigned char midi_byte)
87{
88 sb_devc *devc = midi_devs[dev]->devc;
89
90 if (devc == NULL)
91 return 1;
92
93 if (devc->midi_broken)
94 return 1;
95
96 if (!sb_dsp_command(devc, midi_byte))
97 {
98 devc->midi_broken = 1;
99 return 1;
100 }
101 return 1;
102}
103
104static int sb_midi_start_read(int dev)
105{
106 return 0;
107}
108
109static int sb_midi_end_read(int dev)
110{
111 sb_devc *devc = midi_devs[dev]->devc;
112
113 if (devc == NULL)
114 return -ENXIO;
115
116 sb_dsp_reset(devc);
117 devc->intr_active = 0;
118 return 0;
119}
120
121static int sb_midi_ioctl(int dev, unsigned cmd, void __user *arg)
122{
123 return -EINVAL;
124}
125
126void sb_midi_interrupt(sb_devc * devc)
127{
128 unsigned long flags;
129 unsigned char data;
130
131 if (devc == NULL)
132 return;
133
134 spin_lock_irqsave(&devc->lock, flags);
135
136 data = inb(DSP_READ);
137 if (devc->input_opened)
138 devc->midi_input_intr(devc->my_mididev, data);
139
140 spin_unlock_irqrestore(&devc->lock, flags);
141}
142
143#define MIDI_SYNTH_NAME "Sound Blaster Midi"
144#define MIDI_SYNTH_CAPS 0
145#include "midi_synth.h"
146
147static struct midi_operations sb_midi_operations =
148{
149 .owner = THIS_MODULE,
150 .info = {"Sound Blaster", 0, 0, SNDCARD_SB},
151 .converter = &std_midi_synth,
152 .in_info = {0},
153 .open = sb_midi_open,
154 .close = sb_midi_close,
155 .ioctl = sb_midi_ioctl,
156 .outputc = sb_midi_out,
157 .start_read = sb_midi_start_read,
158 .end_read = sb_midi_end_read,
159};
160
161void sb_dsp_midi_init(sb_devc * devc, struct module *owner)
162{
163 int dev;
164
165 if (devc->model < 2) /* No MIDI support for SB 1.x */
166 return;
167
168 dev = sound_alloc_mididev();
169
170 if (dev == -1)
171 {
172 printk(KERN_ERR "sb_midi: too many MIDI devices detected\n");
173 return;
174 }
175 std_midi_synth.midi_dev = devc->my_mididev = dev;
176 midi_devs[dev] = (struct midi_operations *)kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
177 if (midi_devs[dev] == NULL)
178 {
179 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
180 sound_unload_mididev(dev);
181 return;
182 }
183 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations,
184 sizeof(struct midi_operations));
185
186 if (owner)
187 midi_devs[dev]->owner = owner;
188
189 midi_devs[dev]->devc = devc;
190
191
192 midi_devs[dev]->converter = (struct synth_operations *)kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
193 if (midi_devs[dev]->converter == NULL)
194 {
195 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
196 kfree(midi_devs[dev]);
197 sound_unload_mididev(dev);
198 return;
199 }
200 memcpy((char *) midi_devs[dev]->converter, (char *) &std_midi_synth,
201 sizeof(struct synth_operations));
202
203 midi_devs[dev]->converter->id = "SBMIDI";
204 sequencer_init();
205}
diff --git a/sound/oss/sb_mixer.c b/sound/oss/sb_mixer.c
new file mode 100644
index 000000000000..f56898c3981e
--- /dev/null
+++ b/sound/oss/sb_mixer.c
@@ -0,0 +1,768 @@
1/*
2 * sound/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 "sound_config.h"
20
21#define __SB_MIXER_C__
22
23#include "sb.h"
24#include "sb_mixer.h"
25
26#include "sb_ess.h"
27
28#define SBPRO_RECORDING_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD)
29
30/* Same as SB Pro, unless I find otherwise */
31#define SGNXPRO_RECORDING_DEVICES SBPRO_RECORDING_DEVICES
32
33#define SBPRO_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE | SOUND_MASK_MIC | \
34 SOUND_MASK_CD | SOUND_MASK_VOLUME)
35
36/* SG NX Pro has treble and bass settings on the mixer. The 'speaker'
37 * channel is the COVOX/DisneySoundSource emulation volume control
38 * on the mixer. It does NOT control speaker volume. Should have own
39 * mask eventually?
40 */
41#define SGNXPRO_MIXER_DEVICES (SBPRO_MIXER_DEVICES|SOUND_MASK_BASS| \
42 SOUND_MASK_TREBLE|SOUND_MASK_SPEAKER )
43
44#define SB16_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_LINE | SOUND_MASK_MIC | \
45 SOUND_MASK_CD)
46
47#define SB16_OUTFILTER_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | \
48 SOUND_MASK_CD)
49
50#define SB16_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
51 SOUND_MASK_CD | \
52 SOUND_MASK_IGAIN | SOUND_MASK_OGAIN | \
53 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | \
54 SOUND_MASK_IMIX)
55
56/* These are the only devices that are working at the moment. Others could
57 * be added once they are identified and a method is found to control them.
58 */
59#define ALS007_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_LINE | \
60 SOUND_MASK_PCM | SOUND_MASK_MIC | \
61 SOUND_MASK_CD | \
62 SOUND_MASK_VOLUME)
63
64static mixer_tab sbpro_mix = {
65MIX_ENT(SOUND_MIXER_VOLUME, 0x22, 7, 4, 0x22, 3, 4),
66MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
67MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
68MIX_ENT(SOUND_MIXER_SYNTH, 0x26, 7, 4, 0x26, 3, 4),
69MIX_ENT(SOUND_MIXER_PCM, 0x04, 7, 4, 0x04, 3, 4),
70MIX_ENT(SOUND_MIXER_SPEAKER, 0x00, 0, 0, 0x00, 0, 0),
71MIX_ENT(SOUND_MIXER_LINE, 0x2e, 7, 4, 0x2e, 3, 4),
72MIX_ENT(SOUND_MIXER_MIC, 0x0a, 2, 3, 0x00, 0, 0),
73MIX_ENT(SOUND_MIXER_CD, 0x28, 7, 4, 0x28, 3, 4),
74MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
75MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
76MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0)
77};
78
79static mixer_tab sb16_mix = {
80MIX_ENT(SOUND_MIXER_VOLUME, 0x30, 7, 5, 0x31, 7, 5),
81MIX_ENT(SOUND_MIXER_BASS, 0x46, 7, 4, 0x47, 7, 4),
82MIX_ENT(SOUND_MIXER_TREBLE, 0x44, 7, 4, 0x45, 7, 4),
83MIX_ENT(SOUND_MIXER_SYNTH, 0x34, 7, 5, 0x35, 7, 5),
84MIX_ENT(SOUND_MIXER_PCM, 0x32, 7, 5, 0x33, 7, 5),
85MIX_ENT(SOUND_MIXER_SPEAKER, 0x3b, 7, 2, 0x00, 0, 0),
86MIX_ENT(SOUND_MIXER_LINE, 0x38, 7, 5, 0x39, 7, 5),
87MIX_ENT(SOUND_MIXER_MIC, 0x3a, 7, 5, 0x00, 0, 0),
88MIX_ENT(SOUND_MIXER_CD, 0x36, 7, 5, 0x37, 7, 5),
89MIX_ENT(SOUND_MIXER_IMIX, 0x3c, 0, 1, 0x00, 0, 0),
90MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
91MIX_ENT(SOUND_MIXER_RECLEV, 0x3f, 7, 2, 0x40, 7, 2), /* Obsolete. Use IGAIN */
92MIX_ENT(SOUND_MIXER_IGAIN, 0x3f, 7, 2, 0x40, 7, 2),
93MIX_ENT(SOUND_MIXER_OGAIN, 0x41, 7, 2, 0x42, 7, 2)
94};
95
96static mixer_tab als007_mix =
97{
98MIX_ENT(SOUND_MIXER_VOLUME, 0x62, 7, 4, 0x62, 3, 4),
99MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
100MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
101MIX_ENT(SOUND_MIXER_SYNTH, 0x66, 7, 4, 0x66, 3, 4),
102MIX_ENT(SOUND_MIXER_PCM, 0x64, 7, 4, 0x64, 3, 4),
103MIX_ENT(SOUND_MIXER_SPEAKER, 0x00, 0, 0, 0x00, 0, 0),
104MIX_ENT(SOUND_MIXER_LINE, 0x6e, 7, 4, 0x6e, 3, 4),
105MIX_ENT(SOUND_MIXER_MIC, 0x6a, 2, 3, 0x00, 0, 0),
106MIX_ENT(SOUND_MIXER_CD, 0x68, 7, 4, 0x68, 3, 4),
107MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
108MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
109MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0), /* Obsolete. Use IGAIN */
110MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
111MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0)
112};
113
114
115/* SM_GAMES Master volume is lower and PCM & FM volumes
116 higher than with SB Pro. This improves the
117 sound quality */
118
119static int smg_default_levels[32] =
120{
121 0x2020, /* Master Volume */
122 0x4b4b, /* Bass */
123 0x4b4b, /* Treble */
124 0x6464, /* FM */
125 0x6464, /* PCM */
126 0x4b4b, /* PC Speaker */
127 0x4b4b, /* Ext Line */
128 0x0000, /* Mic */
129 0x4b4b, /* CD */
130 0x4b4b, /* Recording monitor */
131 0x4b4b, /* SB PCM */
132 0x4b4b, /* Recording level */
133 0x4b4b, /* Input gain */
134 0x4b4b, /* Output gain */
135 0x4040, /* Line1 */
136 0x4040, /* Line2 */
137 0x1515 /* Line3 */
138};
139
140static int sb_default_levels[32] =
141{
142 0x5a5a, /* Master Volume */
143 0x4b4b, /* Bass */
144 0x4b4b, /* Treble */
145 0x4b4b, /* FM */
146 0x4b4b, /* PCM */
147 0x4b4b, /* PC Speaker */
148 0x4b4b, /* Ext Line */
149 0x1010, /* Mic */
150 0x4b4b, /* CD */
151 0x0000, /* Recording monitor */
152 0x4b4b, /* SB PCM */
153 0x4b4b, /* Recording level */
154 0x4b4b, /* Input gain */
155 0x4b4b, /* Output gain */
156 0x4040, /* Line1 */
157 0x4040, /* Line2 */
158 0x1515 /* Line3 */
159};
160
161static unsigned char sb16_recmasks_L[SOUND_MIXER_NRDEVICES] =
162{
163 0x00, /* SOUND_MIXER_VOLUME */
164 0x00, /* SOUND_MIXER_BASS */
165 0x00, /* SOUND_MIXER_TREBLE */
166 0x40, /* SOUND_MIXER_SYNTH */
167 0x00, /* SOUND_MIXER_PCM */
168 0x00, /* SOUND_MIXER_SPEAKER */
169 0x10, /* SOUND_MIXER_LINE */
170 0x01, /* SOUND_MIXER_MIC */
171 0x04, /* SOUND_MIXER_CD */
172 0x00, /* SOUND_MIXER_IMIX */
173 0x00, /* SOUND_MIXER_ALTPCM */
174 0x00, /* SOUND_MIXER_RECLEV */
175 0x00, /* SOUND_MIXER_IGAIN */
176 0x00 /* SOUND_MIXER_OGAIN */
177};
178
179static unsigned char sb16_recmasks_R[SOUND_MIXER_NRDEVICES] =
180{
181 0x00, /* SOUND_MIXER_VOLUME */
182 0x00, /* SOUND_MIXER_BASS */
183 0x00, /* SOUND_MIXER_TREBLE */
184 0x20, /* SOUND_MIXER_SYNTH */
185 0x00, /* SOUND_MIXER_PCM */
186 0x00, /* SOUND_MIXER_SPEAKER */
187 0x08, /* SOUND_MIXER_LINE */
188 0x01, /* SOUND_MIXER_MIC */
189 0x02, /* SOUND_MIXER_CD */
190 0x00, /* SOUND_MIXER_IMIX */
191 0x00, /* SOUND_MIXER_ALTPCM */
192 0x00, /* SOUND_MIXER_RECLEV */
193 0x00, /* SOUND_MIXER_IGAIN */
194 0x00 /* SOUND_MIXER_OGAIN */
195};
196
197static char smw_mix_regs[] = /* Left mixer registers */
198{
199 0x0b, /* SOUND_MIXER_VOLUME */
200 0x0d, /* SOUND_MIXER_BASS */
201 0x0d, /* SOUND_MIXER_TREBLE */
202 0x05, /* SOUND_MIXER_SYNTH */
203 0x09, /* SOUND_MIXER_PCM */
204 0x00, /* SOUND_MIXER_SPEAKER */
205 0x03, /* SOUND_MIXER_LINE */
206 0x01, /* SOUND_MIXER_MIC */
207 0x07, /* SOUND_MIXER_CD */
208 0x00, /* SOUND_MIXER_IMIX */
209 0x00, /* SOUND_MIXER_ALTPCM */
210 0x00, /* SOUND_MIXER_RECLEV */
211 0x00, /* SOUND_MIXER_IGAIN */
212 0x00, /* SOUND_MIXER_OGAIN */
213 0x00, /* SOUND_MIXER_LINE1 */
214 0x00, /* SOUND_MIXER_LINE2 */
215 0x00 /* SOUND_MIXER_LINE3 */
216};
217
218static int sbmixnum = 1;
219
220static void sb_mixer_reset(sb_devc * devc);
221
222void sb_mixer_set_stereo(sb_devc * devc, int mode)
223{
224 sb_chgmixer(devc, OUT_FILTER, STEREO_DAC, (mode ? STEREO_DAC : MONO_DAC));
225}
226
227static int detect_mixer(sb_devc * devc)
228{
229 /* Just trust the mixer is there */
230 return 1;
231}
232
233static void change_bits(sb_devc * devc, unsigned char *regval, int dev, int chn, int newval)
234{
235 unsigned char mask;
236 int shift;
237
238 mask = (1 << (*devc->iomap)[dev][chn].nbits) - 1;
239 newval = (int) ((newval * mask) + 50) / 100; /* Scale */
240
241 shift = (*devc->iomap)[dev][chn].bitoffs - (*devc->iomap)[dev][LEFT_CHN].nbits + 1;
242
243 *regval &= ~(mask << shift); /* Mask out previous value */
244 *regval |= (newval & mask) << shift; /* Set the new value */
245}
246
247static int sb_mixer_get(sb_devc * devc, int dev)
248{
249 if (!((1 << dev) & devc->supported_devices))
250 return -EINVAL;
251 return devc->levels[dev];
252}
253
254void smw_mixer_init(sb_devc * devc)
255{
256 int i;
257
258 sb_setmixer(devc, 0x00, 0x18); /* Mute unused (Telephone) line */
259 sb_setmixer(devc, 0x10, 0x38); /* Config register 2 */
260
261 devc->supported_devices = 0;
262 for (i = 0; i < sizeof(smw_mix_regs); i++)
263 if (smw_mix_regs[i] != 0)
264 devc->supported_devices |= (1 << i);
265
266 devc->supported_rec_devices = devc->supported_devices &
267 ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_PCM | SOUND_MASK_VOLUME);
268 sb_mixer_reset(devc);
269}
270
271int sb_common_mixer_set(sb_devc * devc, int dev, int left, int right)
272{
273 int regoffs;
274 unsigned char val;
275
276 regoffs = (*devc->iomap)[dev][LEFT_CHN].regno;
277
278 if (regoffs == 0)
279 return -EINVAL;
280
281 if ((dev < 0) || (dev >= devc->iomap_sz))
282 return -EINVAL;
283
284 val = sb_getmixer(devc, regoffs);
285 change_bits(devc, &val, dev, LEFT_CHN, left);
286
287 if ((*devc->iomap)[dev][RIGHT_CHN].regno != regoffs) /*
288 * Change register
289 */
290 {
291 sb_setmixer(devc, regoffs, val); /*
292 * Save the old one
293 */
294 regoffs = (*devc->iomap)[dev][RIGHT_CHN].regno;
295
296 if (regoffs == 0)
297 return left | (left << 8); /*
298 * Just left channel present
299 */
300
301 val = sb_getmixer(devc, regoffs); /*
302 * Read the new one
303 */
304 }
305 change_bits(devc, &val, dev, RIGHT_CHN, right);
306
307 sb_setmixer(devc, regoffs, val);
308
309 return left | (right << 8);
310}
311
312static int smw_mixer_set(sb_devc * devc, int dev, int left, int right)
313{
314 int reg, val;
315
316 switch (dev)
317 {
318 case SOUND_MIXER_VOLUME:
319 sb_setmixer(devc, 0x0b, 96 - (96 * left / 100)); /* 96=mute, 0=max */
320 sb_setmixer(devc, 0x0c, 96 - (96 * right / 100));
321 break;
322
323 case SOUND_MIXER_BASS:
324 case SOUND_MIXER_TREBLE:
325 devc->levels[dev] = left | (right << 8);
326 /* Set left bass and treble values */
327 val = ((devc->levels[SOUND_MIXER_TREBLE] & 0xff) * 16 / (unsigned) 100) << 4;
328 val |= ((devc->levels[SOUND_MIXER_BASS] & 0xff) * 16 / (unsigned) 100) & 0x0f;
329 sb_setmixer(devc, 0x0d, val);
330
331 /* Set right bass and treble values */
332 val = (((devc->levels[SOUND_MIXER_TREBLE] >> 8) & 0xff) * 16 / (unsigned) 100) << 4;
333 val |= (((devc->levels[SOUND_MIXER_BASS] >> 8) & 0xff) * 16 / (unsigned) 100) & 0x0f;
334 sb_setmixer(devc, 0x0e, val);
335
336 break;
337
338 default:
339 /* bounds check */
340 if (dev < 0 || dev >= ARRAY_SIZE(smw_mix_regs))
341 return -EINVAL;
342 reg = smw_mix_regs[dev];
343 if (reg == 0)
344 return -EINVAL;
345 sb_setmixer(devc, reg, (24 - (24 * left / 100)) | 0x20); /* 24=mute, 0=max */
346 sb_setmixer(devc, reg + 1, (24 - (24 * right / 100)) | 0x40);
347 }
348
349 devc->levels[dev] = left | (right << 8);
350 return left | (right << 8);
351}
352
353static int sb_mixer_set(sb_devc * devc, int dev, int value)
354{
355 int left = value & 0x000000ff;
356 int right = (value & 0x0000ff00) >> 8;
357 int retval;
358
359 if (left > 100)
360 left = 100;
361 if (right > 100)
362 right = 100;
363
364 if ((dev < 0) || (dev > 31))
365 return -EINVAL;
366
367 if (!(devc->supported_devices & (1 << dev))) /*
368 * Not supported
369 */
370 return -EINVAL;
371
372 /* Differentiate depending on the chipsets */
373 switch (devc->model) {
374 case MDL_SMW:
375 retval = smw_mixer_set(devc, dev, left, right);
376 break;
377 case MDL_ESS:
378 retval = ess_mixer_set(devc, dev, left, right);
379 break;
380 default:
381 retval = sb_common_mixer_set(devc, dev, left, right);
382 }
383 if (retval >= 0) devc->levels[dev] = retval;
384
385 return retval;
386}
387
388/*
389 * set_recsrc doesn't apply to ES188x
390 */
391static void set_recsrc(sb_devc * devc, int src)
392{
393 sb_setmixer(devc, RECORD_SRC, (sb_getmixer(devc, RECORD_SRC) & ~7) | (src & 0x7));
394}
395
396static int set_recmask(sb_devc * devc, int mask)
397{
398 int devmask, i;
399 unsigned char regimageL, regimageR;
400
401 devmask = mask & devc->supported_rec_devices;
402
403 switch (devc->model)
404 {
405 case MDL_SBPRO:
406 case MDL_ESS:
407 case MDL_JAZZ:
408 case MDL_SMW:
409 if (devc->model == MDL_ESS && ess_set_recmask (devc, &devmask)) {
410 break;
411 };
412 if (devmask != SOUND_MASK_MIC &&
413 devmask != SOUND_MASK_LINE &&
414 devmask != SOUND_MASK_CD)
415 {
416 /*
417 * More than one device selected. Drop the
418 * previous selection
419 */
420 devmask &= ~devc->recmask;
421 }
422 if (devmask != SOUND_MASK_MIC &&
423 devmask != SOUND_MASK_LINE &&
424 devmask != SOUND_MASK_CD)
425 {
426 /*
427 * More than one device selected. Default to
428 * mic
429 */
430 devmask = SOUND_MASK_MIC;
431 }
432 if (devmask ^ devc->recmask) /*
433 * Input source changed
434 */
435 {
436 switch (devmask)
437 {
438 case SOUND_MASK_MIC:
439 set_recsrc(devc, SRC__MIC);
440 break;
441
442 case SOUND_MASK_LINE:
443 set_recsrc(devc, SRC__LINE);
444 break;
445
446 case SOUND_MASK_CD:
447 set_recsrc(devc, SRC__CD);
448 break;
449
450 default:
451 set_recsrc(devc, SRC__MIC);
452 }
453 }
454 break;
455
456 case MDL_SB16:
457 if (!devmask)
458 devmask = SOUND_MASK_MIC;
459
460 if (devc->submodel == SUBMDL_ALS007)
461 {
462 switch (devmask)
463 {
464 case SOUND_MASK_LINE:
465 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_LINE);
466 break;
467 case SOUND_MASK_CD:
468 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_CD);
469 break;
470 case SOUND_MASK_SYNTH:
471 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_SYNTH);
472 break;
473 default: /* Also takes care of SOUND_MASK_MIC case */
474 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_MIC);
475 break;
476 }
477 }
478 else
479 {
480 regimageL = regimageR = 0;
481 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
482 {
483 if ((1 << i) & devmask)
484 {
485 regimageL |= sb16_recmasks_L[i];
486 regimageR |= sb16_recmasks_R[i];
487 }
488 sb_setmixer (devc, SB16_IMASK_L, regimageL);
489 sb_setmixer (devc, SB16_IMASK_R, regimageR);
490 }
491 }
492 break;
493 }
494 devc->recmask = devmask;
495 return devc->recmask;
496}
497
498static int set_outmask(sb_devc * devc, int mask)
499{
500 int devmask, i;
501 unsigned char regimage;
502
503 devmask = mask & devc->supported_out_devices;
504
505 switch (devc->model)
506 {
507 case MDL_SB16:
508 if (devc->submodel == SUBMDL_ALS007)
509 break;
510 else
511 {
512 regimage = 0;
513 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
514 {
515 if ((1 << i) & devmask)
516 {
517 regimage |= (sb16_recmasks_L[i] | sb16_recmasks_R[i]);
518 }
519 sb_setmixer (devc, SB16_OMASK, regimage);
520 }
521 }
522 break;
523 default:
524 break;
525 }
526
527 devc->outmask = devmask;
528 return devc->outmask;
529}
530
531static int sb_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
532{
533 sb_devc *devc = mixer_devs[dev]->devc;
534 int val, ret;
535 int __user *p = arg;
536
537 /*
538 * Use ioctl(fd, SOUND_MIXER_AGC, &mode) to turn AGC off (0) or on (1).
539 * Use ioctl(fd, SOUND_MIXER_3DSE, &mode) to turn 3DSE off (0) or on (1)
540 * or mode==2 put 3DSE state to mode.
541 */
542 if (devc->model == MDL_SB16) {
543 if (cmd == SOUND_MIXER_AGC)
544 {
545 if (get_user(val, p))
546 return -EFAULT;
547 sb_setmixer(devc, 0x43, (~val) & 0x01);
548 return 0;
549 }
550 if (cmd == SOUND_MIXER_3DSE)
551 {
552 /* I put here 15, but I don't know the exact version.
553 At least my 4.13 havn't 3DSE, 4.16 has it. */
554 if (devc->minor < 15)
555 return -EINVAL;
556 if (get_user(val, p))
557 return -EFAULT;
558 if (val == 0 || val == 1)
559 sb_chgmixer(devc, AWE_3DSE, 0x01, val);
560 else if (val == 2)
561 {
562 ret = sb_getmixer(devc, AWE_3DSE)&0x01;
563 return put_user(ret, p);
564 }
565 else
566 return -EINVAL;
567 return 0;
568 }
569 }
570 if (((cmd >> 8) & 0xff) == 'M')
571 {
572 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
573 {
574 if (get_user(val, p))
575 return -EFAULT;
576 switch (cmd & 0xff)
577 {
578 case SOUND_MIXER_RECSRC:
579 ret = set_recmask(devc, val);
580 break;
581
582 case SOUND_MIXER_OUTSRC:
583 ret = set_outmask(devc, val);
584 break;
585
586 default:
587 ret = sb_mixer_set(devc, cmd & 0xff, val);
588 }
589 }
590 else switch (cmd & 0xff)
591 {
592 case SOUND_MIXER_RECSRC:
593 ret = devc->recmask;
594 break;
595
596 case SOUND_MIXER_OUTSRC:
597 ret = devc->outmask;
598 break;
599
600 case SOUND_MIXER_DEVMASK:
601 ret = devc->supported_devices;
602 break;
603
604 case SOUND_MIXER_STEREODEVS:
605 ret = devc->supported_devices;
606 /* The ESS seems to have stereo mic controls */
607 if (devc->model == MDL_ESS)
608 ret &= ~(SOUND_MASK_SPEAKER|SOUND_MASK_IMIX);
609 else if (devc->model != MDL_JAZZ && devc->model != MDL_SMW)
610 ret &= ~(SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
611 break;
612
613 case SOUND_MIXER_RECMASK:
614 ret = devc->supported_rec_devices;
615 break;
616
617 case SOUND_MIXER_OUTMASK:
618 ret = devc->supported_out_devices;
619 break;
620
621 case SOUND_MIXER_CAPS:
622 ret = devc->mixer_caps;
623 break;
624
625 default:
626 ret = sb_mixer_get(devc, cmd & 0xff);
627 break;
628 }
629 return put_user(ret, p);
630 } else
631 return -EINVAL;
632}
633
634static struct mixer_operations sb_mixer_operations =
635{
636 .owner = THIS_MODULE,
637 .id = "SB",
638 .name = "Sound Blaster",
639 .ioctl = sb_mixer_ioctl
640};
641
642static struct mixer_operations als007_mixer_operations =
643{
644 .owner = THIS_MODULE,
645 .id = "ALS007",
646 .name = "Avance ALS-007",
647 .ioctl = sb_mixer_ioctl
648};
649
650static void sb_mixer_reset(sb_devc * devc)
651{
652 char name[32];
653 int i;
654
655 sprintf(name, "SB_%d", devc->sbmixnum);
656
657 if (devc->sbmo.sm_games)
658 devc->levels = load_mixer_volumes(name, smg_default_levels, 1);
659 else
660 devc->levels = load_mixer_volumes(name, sb_default_levels, 1);
661
662 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
663 sb_mixer_set(devc, i, devc->levels[i]);
664
665 if (devc->model != MDL_ESS || !ess_mixer_reset (devc)) {
666 set_recmask(devc, SOUND_MASK_MIC);
667 };
668}
669
670int sb_mixer_init(sb_devc * devc, struct module *owner)
671{
672 int mixer_type = 0;
673 int m;
674
675 devc->sbmixnum = sbmixnum++;
676 devc->levels = NULL;
677
678 sb_setmixer(devc, 0x00, 0); /* Reset mixer */
679
680 if (!(mixer_type = detect_mixer(devc)))
681 return 0; /* No mixer. Why? */
682
683 switch (devc->model)
684 {
685 case MDL_ESSPCI:
686 case MDL_YMPCI:
687 case MDL_SBPRO:
688 case MDL_AZTECH:
689 case MDL_JAZZ:
690 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
691 devc->supported_devices = SBPRO_MIXER_DEVICES;
692 devc->supported_rec_devices = SBPRO_RECORDING_DEVICES;
693 devc->iomap = &sbpro_mix;
694 devc->iomap_sz = ARRAY_SIZE(sbpro_mix);
695 break;
696
697 case MDL_ESS:
698 ess_mixer_init (devc);
699 break;
700
701 case MDL_SMW:
702 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
703 devc->supported_devices = 0;
704 devc->supported_rec_devices = 0;
705 devc->iomap = &sbpro_mix;
706 devc->iomap_sz = ARRAY_SIZE(sbpro_mix);
707 smw_mixer_init(devc);
708 break;
709
710 case MDL_SB16:
711 devc->mixer_caps = 0;
712 devc->supported_rec_devices = SB16_RECORDING_DEVICES;
713 devc->supported_out_devices = SB16_OUTFILTER_DEVICES;
714 if (devc->submodel != SUBMDL_ALS007)
715 {
716 devc->supported_devices = SB16_MIXER_DEVICES;
717 devc->iomap = &sb16_mix;
718 devc->iomap_sz = ARRAY_SIZE(sb16_mix);
719 }
720 else
721 {
722 devc->supported_devices = ALS007_MIXER_DEVICES;
723 devc->iomap = &als007_mix;
724 devc->iomap_sz = ARRAY_SIZE(als007_mix);
725 }
726 break;
727
728 default:
729 printk(KERN_WARNING "sb_mixer: Unsupported mixer type %d\n", devc->model);
730 return 0;
731 }
732
733 m = sound_alloc_mixerdev();
734 if (m == -1)
735 return 0;
736
737 mixer_devs[m] = (struct mixer_operations *)kmalloc(sizeof(struct mixer_operations), GFP_KERNEL);
738 if (mixer_devs[m] == NULL)
739 {
740 printk(KERN_ERR "sb_mixer: Can't allocate memory\n");
741 sound_unload_mixerdev(m);
742 return 0;
743 }
744
745 if (devc->submodel != SUBMDL_ALS007)
746 memcpy ((char *) mixer_devs[m], (char *) &sb_mixer_operations, sizeof (struct mixer_operations));
747 else
748 memcpy ((char *) mixer_devs[m], (char *) &als007_mixer_operations, sizeof (struct mixer_operations));
749
750 mixer_devs[m]->devc = devc;
751
752 if (owner)
753 mixer_devs[m]->owner = owner;
754
755 devc->my_mixerdev = m;
756 sb_mixer_reset(devc);
757 return 1;
758}
759
760void sb_mixer_unload(sb_devc *devc)
761{
762 if (devc->my_mixerdev == -1)
763 return;
764
765 kfree(mixer_devs[devc->my_mixerdev]);
766 sound_unload_mixerdev(devc->my_mixerdev);
767 sbmixnum--;
768}
diff --git a/sound/oss/sb_mixer.h b/sound/oss/sb_mixer.h
new file mode 100644
index 000000000000..ab74426157ba
--- /dev/null
+++ b/sound/oss/sb_mixer.h
@@ -0,0 +1,105 @@
1/*
2 * sound/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
new file mode 100644
index 000000000000..698614226c9a
--- /dev/null
+++ b/sound/oss/sequencer.c
@@ -0,0 +1,1684 @@
1/*
2 * sound/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#define SEQUENCER_C
20#include "sound_config.h"
21
22#include "midi_ctrl.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 interruptible_sleep_on_timeout(&midi_sleeper,
105 pre_event_timeout);
106 spin_lock_irqsave(&lock,flags);
107 if (!iqlen)
108 {
109 spin_unlock_irqrestore(&lock,flags);
110 return 0;
111 }
112 }
113 while (iqlen && c >= ev_len)
114 {
115 char *fixit = (char *) &iqueue[iqhead * IEV_SZ];
116 spin_unlock_irqrestore(&lock,flags);
117 if (copy_to_user(&(buf)[p], fixit, ev_len))
118 return count - c;
119 p += ev_len;
120 c -= ev_len;
121
122 spin_lock_irqsave(&lock,flags);
123 iqhead = (iqhead + 1) % SEQ_MAX_QUEUE;
124 iqlen--;
125 }
126 spin_unlock_irqrestore(&lock,flags);
127 return count - c;
128}
129
130static void sequencer_midi_output(int dev)
131{
132 /*
133 * Currently NOP
134 */
135}
136
137void seq_copy_to_input(unsigned char *event_rec, int len)
138{
139 unsigned long flags;
140
141 /*
142 * Verify that the len is valid for the current mode.
143 */
144
145 if (len != 4 && len != 8)
146 return;
147 if ((seq_mode == SEQ_1) != (len == 4))
148 return;
149
150 if (iqlen >= (SEQ_MAX_QUEUE - 1))
151 return; /* Overflow */
152
153 spin_lock_irqsave(&lock,flags);
154 memcpy(&iqueue[iqtail * IEV_SZ], event_rec, len);
155 iqlen++;
156 iqtail = (iqtail + 1) % SEQ_MAX_QUEUE;
157 wake_up(&midi_sleeper);
158 spin_unlock_irqrestore(&lock,flags);
159}
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}
209
210int sequencer_write(int dev, struct file *file, const char __user *buf, int count)
211{
212 unsigned char event_rec[EV_SZ], ev_code;
213 int p = 0, c, ev_size;
214 int err;
215 int mode = translate_mode(file);
216
217 dev = dev >> 4;
218
219 DEB(printk("sequencer_write(dev=%d, count=%d)\n", dev, count));
220
221 if (mode == OPEN_READ)
222 return -EIO;
223
224 c = count;
225
226 while (c >= 4)
227 {
228 if (copy_from_user((char *) event_rec, &(buf)[p], 4))
229 goto out;
230 ev_code = event_rec[0];
231
232 if (ev_code == SEQ_FULLSIZE)
233 {
234 int err, fmt;
235
236 dev = *(unsigned short *) &event_rec[2];
237 if (dev < 0 || dev >= max_synthdev || synth_devs[dev] == NULL)
238 return -ENXIO;
239
240 if (!(synth_open_mask & (1 << dev)))
241 return -ENXIO;
242
243 fmt = (*(short *) &event_rec[0]) & 0xffff;
244 err = synth_devs[dev]->load_patch(dev, fmt, buf, p + 4, c, 0);
245 if (err < 0)
246 return err;
247
248 return err;
249 }
250 if (ev_code >= 128)
251 {
252 if (seq_mode == SEQ_2 && ev_code == SEQ_EXTENDED)
253 {
254 printk(KERN_WARNING "Sequencer: Invalid level 2 event %x\n", ev_code);
255 return -EINVAL;
256 }
257 ev_size = 8;
258
259 if (c < ev_size)
260 {
261 if (!seq_playing)
262 seq_startplay();
263 return count - c;
264 }
265 if (copy_from_user((char *)&event_rec[4],
266 &(buf)[p + 4], 4))
267 goto out;
268
269 }
270 else
271 {
272 if (seq_mode == SEQ_2)
273 {
274 printk(KERN_WARNING "Sequencer: 4 byte event in level 2 mode\n");
275 return -EINVAL;
276 }
277 ev_size = 4;
278
279 if (event_rec[0] != SEQ_MIDIPUTC)
280 obsolete_api_used = 1;
281 }
282
283 if (event_rec[0] == SEQ_MIDIPUTC)
284 {
285 if (!midi_opened[event_rec[2]])
286 {
287 int mode;
288 int dev = event_rec[2];
289
290 if (dev >= max_mididev || midi_devs[dev]==NULL)
291 {
292 /*printk("Sequencer Error: Nonexistent MIDI device %d\n", dev);*/
293 return -ENXIO;
294 }
295 mode = translate_mode(file);
296
297 if ((err = midi_devs[dev]->open(dev, mode,
298 sequencer_midi_input, sequencer_midi_output)) < 0)
299 {
300 seq_reset();
301 printk(KERN_WARNING "Sequencer Error: Unable to open Midi #%d\n", dev);
302 return err;
303 }
304 midi_opened[dev] = 1;
305 }
306 }
307 if (!seq_queue(event_rec, (file->f_flags & (O_NONBLOCK) ? 1 : 0)))
308 {
309 int processed = count - c;
310
311 if (!seq_playing)
312 seq_startplay();
313
314 if (!processed && (file->f_flags & O_NONBLOCK))
315 return -EAGAIN;
316 else
317 return processed;
318 }
319 p += ev_size;
320 c -= ev_size;
321 }
322
323 if (!seq_playing)
324 seq_startplay();
325out:
326 return count;
327}
328
329static int seq_queue(unsigned char *note, char nonblock)
330{
331
332 /*
333 * Test if there is space in the queue
334 */
335
336 if (qlen >= SEQ_MAX_QUEUE)
337 if (!seq_playing)
338 seq_startplay(); /*
339 * Give chance to drain the queue
340 */
341
342 if (!nonblock && qlen >= SEQ_MAX_QUEUE && !waitqueue_active(&seq_sleeper)) {
343 /*
344 * Sleep until there is enough space on the queue
345 */
346 interruptible_sleep_on(&seq_sleeper);
347 }
348 if (qlen >= SEQ_MAX_QUEUE)
349 {
350 return 0; /*
351 * To be sure
352 */
353 }
354 memcpy(&queue[qtail * EV_SZ], note, EV_SZ);
355
356 qtail = (qtail + 1) % SEQ_MAX_QUEUE;
357 qlen++;
358
359 return 1;
360}
361
362static int extended_event(unsigned char *q)
363{
364 int dev = q[2];
365
366 if (dev < 0 || dev >= max_synthdev)
367 return -ENXIO;
368
369 if (!(synth_open_mask & (1 << dev)))
370 return -ENXIO;
371
372 switch (q[1])
373 {
374 case SEQ_NOTEOFF:
375 synth_devs[dev]->kill_note(dev, q[3], q[4], q[5]);
376 break;
377
378 case SEQ_NOTEON:
379 if (q[4] > 127 && q[4] != 255)
380 return 0;
381
382 if (q[5] == 0)
383 {
384 synth_devs[dev]->kill_note(dev, q[3], q[4], q[5]);
385 break;
386 }
387 synth_devs[dev]->start_note(dev, q[3], q[4], q[5]);
388 break;
389
390 case SEQ_PGMCHANGE:
391 synth_devs[dev]->set_instr(dev, q[3], q[4]);
392 break;
393
394 case SEQ_AFTERTOUCH:
395 synth_devs[dev]->aftertouch(dev, q[3], q[4]);
396 break;
397
398 case SEQ_BALANCE:
399 synth_devs[dev]->panning(dev, q[3], (char) q[4]);
400 break;
401
402 case SEQ_CONTROLLER:
403 synth_devs[dev]->controller(dev, q[3], q[4], (short) (q[5] | (q[6] << 8)));
404 break;
405
406 case SEQ_VOLMODE:
407 if (synth_devs[dev]->volume_method != NULL)
408 synth_devs[dev]->volume_method(dev, q[3]);
409 break;
410
411 default:
412 return -EINVAL;
413 }
414 return 0;
415}
416
417static int find_voice(int dev, int chn, int note)
418{
419 unsigned short key;
420 int i;
421
422 key = (chn << 8) | (note + 1);
423 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
424 if (synth_devs[dev]->alloc.map[i] == key)
425 return i;
426 return -1;
427}
428
429static int alloc_voice(int dev, int chn, int note)
430{
431 unsigned short key;
432 int voice;
433
434 key = (chn << 8) | (note + 1);
435
436 voice = synth_devs[dev]->alloc_voice(dev, chn, note,
437 &synth_devs[dev]->alloc);
438 synth_devs[dev]->alloc.map[voice] = key;
439 synth_devs[dev]->alloc.alloc_times[voice] =
440 synth_devs[dev]->alloc.timestamp++;
441 return voice;
442}
443
444static void seq_chn_voice_event(unsigned char *event_rec)
445{
446#define dev event_rec[1]
447#define cmd event_rec[2]
448#define chn event_rec[3]
449#define note event_rec[4]
450#define parm event_rec[5]
451
452 int voice = -1;
453
454 if ((int) dev > max_synthdev || synth_devs[dev] == NULL)
455 return;
456 if (!(synth_open_mask & (1 << dev)))
457 return;
458 if (!synth_devs[dev])
459 return;
460
461 if (seq_mode == SEQ_2)
462 {
463 if (synth_devs[dev]->alloc_voice)
464 voice = find_voice(dev, chn, note);
465
466 if (cmd == MIDI_NOTEON && parm == 0)
467 {
468 cmd = MIDI_NOTEOFF;
469 parm = 64;
470 }
471 }
472
473 switch (cmd)
474 {
475 case MIDI_NOTEON:
476 if (note > 127 && note != 255) /* Not a seq2 feature */
477 return;
478
479 if (voice == -1 && seq_mode == SEQ_2 && synth_devs[dev]->alloc_voice)
480 {
481 /* Internal synthesizer (FM, GUS, etc) */
482 voice = alloc_voice(dev, chn, note);
483 }
484 if (voice == -1)
485 voice = chn;
486
487 if (seq_mode == SEQ_2 && (int) dev < num_synths)
488 {
489 /*
490 * The MIDI channel 10 is a percussive channel. Use the note
491 * number to select the proper patch (128 to 255) to play.
492 */
493
494 if (chn == 9)
495 {
496 synth_devs[dev]->set_instr(dev, voice, 128 + note);
497 synth_devs[dev]->chn_info[chn].pgm_num = 128 + note;
498 }
499 synth_devs[dev]->setup_voice(dev, voice, chn);
500 }
501 synth_devs[dev]->start_note(dev, voice, note, parm);
502 break;
503
504 case MIDI_NOTEOFF:
505 if (voice == -1)
506 voice = chn;
507 synth_devs[dev]->kill_note(dev, voice, note, parm);
508 break;
509
510 case MIDI_KEY_PRESSURE:
511 if (voice == -1)
512 voice = chn;
513 synth_devs[dev]->aftertouch(dev, voice, parm);
514 break;
515
516 default:;
517 }
518#undef dev
519#undef cmd
520#undef chn
521#undef note
522#undef parm
523}
524
525
526static void seq_chn_common_event(unsigned char *event_rec)
527{
528 unsigned char dev = event_rec[1];
529 unsigned char cmd = event_rec[2];
530 unsigned char chn = event_rec[3];
531 unsigned char p1 = event_rec[4];
532
533 /* unsigned char p2 = event_rec[5]; */
534 unsigned short w14 = *(short *) &event_rec[6];
535
536 if ((int) dev > max_synthdev || synth_devs[dev] == NULL)
537 return;
538 if (!(synth_open_mask & (1 << dev)))
539 return;
540 if (!synth_devs[dev])
541 return;
542
543 switch (cmd)
544 {
545 case MIDI_PGM_CHANGE:
546 if (seq_mode == SEQ_2)
547 {
548 synth_devs[dev]->chn_info[chn].pgm_num = p1;
549 if ((int) dev >= num_synths)
550 synth_devs[dev]->set_instr(dev, chn, p1);
551 }
552 else
553 synth_devs[dev]->set_instr(dev, chn, p1);
554
555 break;
556
557 case MIDI_CTL_CHANGE:
558 if (seq_mode == SEQ_2)
559 {
560 if (chn > 15 || p1 > 127)
561 break;
562
563 synth_devs[dev]->chn_info[chn].controllers[p1] = w14 & 0x7f;
564
565 if (p1 < 32) /* Setting MSB should clear LSB to 0 */
566 synth_devs[dev]->chn_info[chn].controllers[p1 + 32] = 0;
567
568 if ((int) dev < num_synths)
569 {
570 int val = w14 & 0x7f;
571 int i, key;
572
573 if (p1 < 64) /* Combine MSB and LSB */
574 {
575 val = ((synth_devs[dev]->
576 chn_info[chn].controllers[p1 & ~32] & 0x7f) << 7)
577 | (synth_devs[dev]->
578 chn_info[chn].controllers[p1 | 32] & 0x7f);
579 p1 &= ~32;
580 }
581 /* Handle all playing notes on this channel */
582
583 key = ((int) chn << 8);
584
585 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
586 if ((synth_devs[dev]->alloc.map[i] & 0xff00) == key)
587 synth_devs[dev]->controller(dev, i, p1, val);
588 }
589 else
590 synth_devs[dev]->controller(dev, chn, p1, w14);
591 }
592 else /* Mode 1 */
593 synth_devs[dev]->controller(dev, chn, p1, w14);
594 break;
595
596 case MIDI_PITCH_BEND:
597 if (seq_mode == SEQ_2)
598 {
599 synth_devs[dev]->chn_info[chn].bender_value = w14;
600
601 if ((int) dev < num_synths)
602 {
603 /* Handle all playing notes on this channel */
604 int i, key;
605
606 key = (chn << 8);
607
608 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
609 if ((synth_devs[dev]->alloc.map[i] & 0xff00) == key)
610 synth_devs[dev]->bender(dev, i, w14);
611 }
612 else
613 synth_devs[dev]->bender(dev, chn, w14);
614 }
615 else /* MODE 1 */
616 synth_devs[dev]->bender(dev, chn, w14);
617 break;
618
619 default:;
620 }
621}
622
623static int seq_timing_event(unsigned char *event_rec)
624{
625 unsigned char cmd = event_rec[1];
626 unsigned int parm = *(int *) &event_rec[4];
627
628 if (seq_mode == SEQ_2)
629 {
630 int ret;
631
632 if ((ret = tmr->event(tmr_no, event_rec)) == TIMER_ARMED)
633 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
634 wake_up(&seq_sleeper);
635 return ret;
636 }
637 switch (cmd)
638 {
639 case TMR_WAIT_REL:
640 parm += prev_event_time;
641
642 /*
643 * NOTE! No break here. Execution of TMR_WAIT_REL continues in the
644 * next case (TMR_WAIT_ABS)
645 */
646
647 case TMR_WAIT_ABS:
648 if (parm > 0)
649 {
650 long time;
651
652 time = parm;
653 prev_event_time = time;
654
655 seq_playing = 1;
656 request_sound_timer(time);
657
658 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
659 wake_up(&seq_sleeper);
660 return TIMER_ARMED;
661 }
662 break;
663
664 case TMR_START:
665 seq_time = jiffies;
666 prev_input_time = 0;
667 prev_event_time = 0;
668 break;
669
670 case TMR_STOP:
671 break;
672
673 case TMR_CONTINUE:
674 break;
675
676 case TMR_TEMPO:
677 break;
678
679 case TMR_ECHO:
680 if (seq_mode == SEQ_2)
681 seq_copy_to_input(event_rec, 8);
682 else
683 {
684 parm = (parm << 8 | SEQ_ECHO);
685 seq_copy_to_input((unsigned char *) &parm, 4);
686 }
687 break;
688
689 default:;
690 }
691
692 return TIMER_NOT_ARMED;
693}
694
695static void seq_local_event(unsigned char *event_rec)
696{
697 unsigned char cmd = event_rec[1];
698 unsigned int parm = *((unsigned int *) &event_rec[4]);
699
700 switch (cmd)
701 {
702 case LOCL_STARTAUDIO:
703 DMAbuf_start_devices(parm);
704 break;
705
706 default:;
707 }
708}
709
710static void seq_sysex_message(unsigned char *event_rec)
711{
712 int dev = event_rec[1];
713 int i, l = 0;
714 unsigned char *buf = &event_rec[2];
715
716 if ((int) dev > max_synthdev)
717 return;
718 if (!(synth_open_mask & (1 << dev)))
719 return;
720 if (!synth_devs[dev])
721 return;
722
723 l = 0;
724 for (i = 0; i < 6 && buf[i] != 0xff; i++)
725 l = i + 1;
726
727 if (!synth_devs[dev]->send_sysex)
728 return;
729 if (l > 0)
730 synth_devs[dev]->send_sysex(dev, buf, l);
731}
732
733static int play_event(unsigned char *q)
734{
735 /*
736 * NOTE! This routine returns
737 * 0 = normal event played.
738 * 1 = Timer armed. Suspend playback until timer callback.
739 * 2 = MIDI output buffer full. Restore queue and suspend until timer
740 */
741 unsigned int *delay;
742
743 switch (q[0])
744 {
745 case SEQ_NOTEOFF:
746 if (synth_open_mask & (1 << 0))
747 if (synth_devs[0])
748 synth_devs[0]->kill_note(0, q[1], 255, q[3]);
749 break;
750
751 case SEQ_NOTEON:
752 if (q[4] < 128 || q[4] == 255)
753 if (synth_open_mask & (1 << 0))
754 if (synth_devs[0])
755 synth_devs[0]->start_note(0, q[1], q[2], q[3]);
756 break;
757
758 case SEQ_WAIT:
759 delay = (unsigned int *) q; /*
760 * Bytes 1 to 3 are containing the *
761 * delay in 'ticks'
762 */
763 *delay = (*delay >> 8) & 0xffffff;
764
765 if (*delay > 0)
766 {
767 long time;
768
769 seq_playing = 1;
770 time = *delay;
771 prev_event_time = time;
772
773 request_sound_timer(time);
774
775 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
776 wake_up(&seq_sleeper);
777 /*
778 * The timer is now active and will reinvoke this function
779 * after the timer expires. Return to the caller now.
780 */
781 return 1;
782 }
783 break;
784
785 case SEQ_PGMCHANGE:
786 if (synth_open_mask & (1 << 0))
787 if (synth_devs[0])
788 synth_devs[0]->set_instr(0, q[1], q[2]);
789 break;
790
791 case SEQ_SYNCTIMER: /*
792 * Reset timer
793 */
794 seq_time = jiffies;
795 prev_input_time = 0;
796 prev_event_time = 0;
797 break;
798
799 case SEQ_MIDIPUTC: /*
800 * Put a midi character
801 */
802 if (midi_opened[q[2]])
803 {
804 int dev;
805
806 dev = q[2];
807
808 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
809 break;
810
811 if (!midi_devs[dev]->outputc(dev, q[1]))
812 {
813 /*
814 * Output FIFO is full. Wait one timer cycle and try again.
815 */
816
817 seq_playing = 1;
818 request_sound_timer(-1);
819 return 2;
820 }
821 else
822 midi_written[dev] = 1;
823 }
824 break;
825
826 case SEQ_ECHO:
827 seq_copy_to_input(q, 4); /*
828 * Echo back to the process
829 */
830 break;
831
832 case SEQ_PRIVATE:
833 if ((int) q[1] < max_synthdev)
834 synth_devs[q[1]]->hw_control(q[1], q);
835 break;
836
837 case SEQ_EXTENDED:
838 extended_event(q);
839 break;
840
841 case EV_CHN_VOICE:
842 seq_chn_voice_event(q);
843 break;
844
845 case EV_CHN_COMMON:
846 seq_chn_common_event(q);
847 break;
848
849 case EV_TIMING:
850 if (seq_timing_event(q) == TIMER_ARMED)
851 {
852 return 1;
853 }
854 break;
855
856 case EV_SEQ_LOCAL:
857 seq_local_event(q);
858 break;
859
860 case EV_SYSEX:
861 seq_sysex_message(q);
862 break;
863
864 default:;
865 }
866 return 0;
867}
868
869/* called also as timer in irq context */
870static void seq_startplay(void)
871{
872 int this_one, action;
873 unsigned long flags;
874
875 while (qlen > 0)
876 {
877
878 spin_lock_irqsave(&lock,flags);
879 qhead = ((this_one = qhead) + 1) % SEQ_MAX_QUEUE;
880 qlen--;
881 spin_unlock_irqrestore(&lock,flags);
882
883 seq_playing = 1;
884
885 if ((action = play_event(&queue[this_one * EV_SZ])))
886 { /* Suspend playback. Next timer routine invokes this routine again */
887 if (action == 2)
888 {
889 qlen++;
890 qhead = this_one;
891 }
892 return;
893 }
894 }
895
896 seq_playing = 0;
897
898 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
899 wake_up(&seq_sleeper);
900}
901
902static void reset_controllers(int dev, unsigned char *controller, int update_dev)
903{
904 int i;
905 for (i = 0; i < 128; i++)
906 controller[i] = ctrl_def_values[i];
907}
908
909static void setup_mode2(void)
910{
911 int dev;
912
913 max_synthdev = num_synths;
914
915 for (dev = 0; dev < num_midis; dev++)
916 {
917 if (midi_devs[dev] && midi_devs[dev]->converter != NULL)
918 {
919 synth_devs[max_synthdev++] = midi_devs[dev]->converter;
920 }
921 }
922
923 for (dev = 0; dev < max_synthdev; dev++)
924 {
925 int chn;
926
927 synth_devs[dev]->sysex_ptr = 0;
928 synth_devs[dev]->emulation = 0;
929
930 for (chn = 0; chn < 16; chn++)
931 {
932 synth_devs[dev]->chn_info[chn].pgm_num = 0;
933 reset_controllers(dev,
934 synth_devs[dev]->chn_info[chn].controllers,0);
935 synth_devs[dev]->chn_info[chn].bender_value = (1 << 7); /* Neutral */
936 synth_devs[dev]->chn_info[chn].bender_range = 200;
937 }
938 }
939 max_mididev = 0;
940 seq_mode = SEQ_2;
941}
942
943int sequencer_open(int dev, struct file *file)
944{
945 int retval, mode, i;
946 int level, tmp;
947
948 if (!sequencer_ok)
949 sequencer_init();
950
951 level = ((dev & 0x0f) == SND_DEV_SEQ2) ? 2 : 1;
952
953 dev = dev >> 4;
954 mode = translate_mode(file);
955
956 DEB(printk("sequencer_open(dev=%d)\n", dev));
957
958 if (!sequencer_ok)
959 {
960/* printk("Sound card: sequencer not initialized\n");*/
961 return -ENXIO;
962 }
963 if (dev) /* Patch manager device (obsolete) */
964 return -ENXIO;
965
966 if(synth_devs[dev] == NULL)
967 request_module("synth0");
968
969 if (mode == OPEN_READ)
970 {
971 if (!num_midis)
972 {
973 /*printk("Sequencer: No MIDI devices. Input not possible\n");*/
974 sequencer_busy = 0;
975 return -ENXIO;
976 }
977 }
978 if (sequencer_busy)
979 {
980 return -EBUSY;
981 }
982 sequencer_busy = 1;
983 obsolete_api_used = 0;
984
985 max_mididev = num_midis;
986 max_synthdev = num_synths;
987 pre_event_timeout = MAX_SCHEDULE_TIMEOUT;
988 seq_mode = SEQ_1;
989
990 if (pending_timer != -1)
991 {
992 tmr_no = pending_timer;
993 pending_timer = -1;
994 }
995 if (tmr_no == -1) /* Not selected yet */
996 {
997 int i, best;
998
999 best = -1;
1000 for (i = 0; i < num_sound_timers; i++)
1001 if (sound_timer_devs[i] && sound_timer_devs[i]->priority > best)
1002 {
1003 tmr_no = i;
1004 best = sound_timer_devs[i]->priority;
1005 }
1006 if (tmr_no == -1) /* Should not be */
1007 tmr_no = 0;
1008 }
1009 tmr = sound_timer_devs[tmr_no];
1010
1011 if (level == 2)
1012 {
1013 if (tmr == NULL)
1014 {
1015 /*printk("sequencer: No timer for level 2\n");*/
1016 sequencer_busy = 0;
1017 return -ENXIO;
1018 }
1019 setup_mode2();
1020 }
1021 if (!max_synthdev && !max_mididev)
1022 {
1023 sequencer_busy=0;
1024 return -ENXIO;
1025 }
1026
1027 synth_open_mask = 0;
1028
1029 for (i = 0; i < max_mididev; i++)
1030 {
1031 midi_opened[i] = 0;
1032 midi_written[i] = 0;
1033 }
1034
1035 for (i = 0; i < max_synthdev; i++)
1036 {
1037 if (synth_devs[i]==NULL)
1038 continue;
1039
1040 if (!try_module_get(synth_devs[i]->owner))
1041 continue;
1042
1043 if ((tmp = synth_devs[i]->open(i, mode)) < 0)
1044 {
1045 printk(KERN_WARNING "Sequencer: Warning! Cannot open synth device #%d (%d)\n", i, tmp);
1046 if (synth_devs[i]->midi_dev)
1047 printk(KERN_WARNING "(Maps to MIDI dev #%d)\n", synth_devs[i]->midi_dev);
1048 }
1049 else
1050 {
1051 synth_open_mask |= (1 << i);
1052 if (synth_devs[i]->midi_dev)
1053 midi_opened[synth_devs[i]->midi_dev] = 1;
1054 }
1055 }
1056
1057 seq_time = jiffies;
1058
1059 prev_input_time = 0;
1060 prev_event_time = 0;
1061
1062 if (seq_mode == SEQ_1 && (mode == OPEN_READ || mode == OPEN_READWRITE))
1063 {
1064 /*
1065 * Initialize midi input devices
1066 */
1067
1068 for (i = 0; i < max_mididev; i++)
1069 if (!midi_opened[i] && midi_devs[i])
1070 {
1071 if (!try_module_get(midi_devs[i]->owner))
1072 continue;
1073
1074 if ((retval = midi_devs[i]->open(i, mode,
1075 sequencer_midi_input, sequencer_midi_output)) >= 0)
1076 {
1077 midi_opened[i] = 1;
1078 }
1079 }
1080 }
1081
1082 if (seq_mode == SEQ_2) {
1083 if (try_module_get(tmr->owner))
1084 tmr->open(tmr_no, seq_mode);
1085 }
1086
1087 init_waitqueue_head(&seq_sleeper);
1088 init_waitqueue_head(&midi_sleeper);
1089 output_threshold = SEQ_MAX_QUEUE / 2;
1090
1091 return 0;
1092}
1093
1094static void seq_drain_midi_queues(void)
1095{
1096 int i, n;
1097
1098 /*
1099 * Give the Midi drivers time to drain their output queues
1100 */
1101
1102 n = 1;
1103
1104 while (!signal_pending(current) && n)
1105 {
1106 n = 0;
1107
1108 for (i = 0; i < max_mididev; i++)
1109 if (midi_opened[i] && midi_written[i])
1110 if (midi_devs[i]->buffer_status != NULL)
1111 if (midi_devs[i]->buffer_status(i))
1112 n++;
1113
1114 /*
1115 * Let's have a delay
1116 */
1117
1118 if (n)
1119 interruptible_sleep_on_timeout(&seq_sleeper,
1120 HZ/10);
1121 }
1122}
1123
1124void sequencer_release(int dev, struct file *file)
1125{
1126 int i;
1127 int mode = translate_mode(file);
1128
1129 dev = dev >> 4;
1130
1131 DEB(printk("sequencer_release(dev=%d)\n", dev));
1132
1133 /*
1134 * Wait until the queue is empty (if we don't have nonblock)
1135 */
1136
1137 if (mode != OPEN_READ && !(file->f_flags & O_NONBLOCK))
1138 {
1139 while (!signal_pending(current) && qlen > 0)
1140 {
1141 seq_sync();
1142 interruptible_sleep_on_timeout(&seq_sleeper,
1143 3*HZ);
1144 /* Extra delay */
1145 }
1146 }
1147
1148 if (mode != OPEN_READ)
1149 seq_drain_midi_queues(); /*
1150 * Ensure the output queues are empty
1151 */
1152 seq_reset();
1153 if (mode != OPEN_READ)
1154 seq_drain_midi_queues(); /*
1155 * Flush the all notes off messages
1156 */
1157
1158 for (i = 0; i < max_synthdev; i++)
1159 {
1160 if (synth_open_mask & (1 << i)) /*
1161 * Actually opened
1162 */
1163 if (synth_devs[i])
1164 {
1165 synth_devs[i]->close(i);
1166
1167 module_put(synth_devs[i]->owner);
1168
1169 if (synth_devs[i]->midi_dev)
1170 midi_opened[synth_devs[i]->midi_dev] = 0;
1171 }
1172 }
1173
1174 for (i = 0; i < max_mididev; i++)
1175 {
1176 if (midi_opened[i]) {
1177 midi_devs[i]->close(i);
1178 module_put(midi_devs[i]->owner);
1179 }
1180 }
1181
1182 if (seq_mode == SEQ_2) {
1183 tmr->close(tmr_no);
1184 module_put(tmr->owner);
1185 }
1186
1187 if (obsolete_api_used)
1188 printk(KERN_WARNING "/dev/music: Obsolete (4 byte) API was used by %s\n", current->comm);
1189 sequencer_busy = 0;
1190}
1191
1192static int seq_sync(void)
1193{
1194 if (qlen && !seq_playing && !signal_pending(current))
1195 seq_startplay();
1196
1197 if (qlen > 0)
1198 interruptible_sleep_on_timeout(&seq_sleeper, HZ);
1199 return qlen;
1200}
1201
1202static void midi_outc(int dev, unsigned char data)
1203{
1204 /*
1205 * NOTE! Calls sleep(). Don't call this from interrupt.
1206 */
1207
1208 int n;
1209 unsigned long flags;
1210
1211 /*
1212 * This routine sends one byte to the Midi channel.
1213 * If the output FIFO is full, it waits until there
1214 * is space in the queue
1215 */
1216
1217 n = 3 * HZ; /* Timeout */
1218
1219 spin_lock_irqsave(&lock,flags);
1220 while (n && !midi_devs[dev]->outputc(dev, data)) {
1221 interruptible_sleep_on_timeout(&seq_sleeper, HZ/25);
1222 n--;
1223 }
1224 spin_unlock_irqrestore(&lock,flags);
1225}
1226
1227static void seq_reset(void)
1228{
1229 /*
1230 * NOTE! Calls sleep(). Don't call this from interrupt.
1231 */
1232
1233 int i;
1234 int chn;
1235 unsigned long flags;
1236
1237 sound_stop_timer();
1238
1239 seq_time = jiffies;
1240 prev_input_time = 0;
1241 prev_event_time = 0;
1242
1243 qlen = qhead = qtail = 0;
1244 iqlen = iqhead = iqtail = 0;
1245
1246 for (i = 0; i < max_synthdev; i++)
1247 if (synth_open_mask & (1 << i))
1248 if (synth_devs[i])
1249 synth_devs[i]->reset(i);
1250
1251 if (seq_mode == SEQ_2)
1252 {
1253 for (chn = 0; chn < 16; chn++)
1254 for (i = 0; i < max_synthdev; i++)
1255 if (synth_open_mask & (1 << i))
1256 if (synth_devs[i])
1257 {
1258 synth_devs[i]->controller(i, chn, 123, 0); /* All notes off */
1259 synth_devs[i]->controller(i, chn, 121, 0); /* Reset all ctl */
1260 synth_devs[i]->bender(i, chn, 1 << 13); /* Bender off */
1261 }
1262 }
1263 else /* seq_mode == SEQ_1 */
1264 {
1265 for (i = 0; i < max_mididev; i++)
1266 if (midi_written[i]) /*
1267 * Midi used. Some notes may still be playing
1268 */
1269 {
1270 /*
1271 * Sending just a ACTIVE SENSING message should be enough to stop all
1272 * playing notes. Since there are devices not recognizing the
1273 * active sensing, we have to send some all notes off messages also.
1274 */
1275 midi_outc(i, 0xfe);
1276
1277 for (chn = 0; chn < 16; chn++)
1278 {
1279 midi_outc(i, (unsigned char) (0xb0 + (chn & 0x0f))); /* control change */
1280 midi_outc(i, 0x7b); /* All notes off */
1281 midi_outc(i, 0); /* Dummy parameter */
1282 }
1283
1284 midi_devs[i]->close(i);
1285
1286 midi_written[i] = 0;
1287 midi_opened[i] = 0;
1288 }
1289 }
1290
1291 seq_playing = 0;
1292
1293 spin_lock_irqsave(&lock,flags);
1294
1295 if (waitqueue_active(&seq_sleeper)) {
1296 /* printk( "Sequencer Warning: Unexpected sleeping process - Waking up\n"); */
1297 wake_up(&seq_sleeper);
1298 }
1299 spin_unlock_irqrestore(&lock,flags);
1300}
1301
1302static void seq_panic(void)
1303{
1304 /*
1305 * This routine is called by the application in case the user
1306 * wants to reset the system to the default state.
1307 */
1308
1309 seq_reset();
1310
1311 /*
1312 * Since some of the devices don't recognize the active sensing and
1313 * all notes off messages, we have to shut all notes manually.
1314 *
1315 * TO BE IMPLEMENTED LATER
1316 */
1317
1318 /*
1319 * Also return the controllers to their default states
1320 */
1321}
1322
1323int sequencer_ioctl(int dev, struct file *file, unsigned int cmd, void __user *arg)
1324{
1325 int midi_dev, orig_dev, val, err;
1326 int mode = translate_mode(file);
1327 struct synth_info inf;
1328 struct seq_event_rec event_rec;
1329 unsigned long flags;
1330 int __user *p = arg;
1331
1332 orig_dev = dev = dev >> 4;
1333
1334 switch (cmd)
1335 {
1336 case SNDCTL_TMR_TIMEBASE:
1337 case SNDCTL_TMR_TEMPO:
1338 case SNDCTL_TMR_START:
1339 case SNDCTL_TMR_STOP:
1340 case SNDCTL_TMR_CONTINUE:
1341 case SNDCTL_TMR_METRONOME:
1342 case SNDCTL_TMR_SOURCE:
1343 if (seq_mode != SEQ_2)
1344 return -EINVAL;
1345 return tmr->ioctl(tmr_no, cmd, arg);
1346
1347 case SNDCTL_TMR_SELECT:
1348 if (seq_mode != SEQ_2)
1349 return -EINVAL;
1350 if (get_user(pending_timer, p))
1351 return -EFAULT;
1352 if (pending_timer < 0 || pending_timer >= num_sound_timers || sound_timer_devs[pending_timer] == NULL)
1353 {
1354 pending_timer = -1;
1355 return -EINVAL;
1356 }
1357 val = pending_timer;
1358 break;
1359
1360 case SNDCTL_SEQ_PANIC:
1361 seq_panic();
1362 return -EINVAL;
1363
1364 case SNDCTL_SEQ_SYNC:
1365 if (mode == OPEN_READ)
1366 return 0;
1367 while (qlen > 0 && !signal_pending(current))
1368 seq_sync();
1369 return qlen ? -EINTR : 0;
1370
1371 case SNDCTL_SEQ_RESET:
1372 seq_reset();
1373 return 0;
1374
1375 case SNDCTL_SEQ_TESTMIDI:
1376 if (__get_user(midi_dev, p))
1377 return -EFAULT;
1378 if (midi_dev < 0 || midi_dev >= max_mididev || !midi_devs[midi_dev])
1379 return -ENXIO;
1380
1381 if (!midi_opened[midi_dev] &&
1382 (err = midi_devs[midi_dev]->open(midi_dev, mode, sequencer_midi_input,
1383 sequencer_midi_output)) < 0)
1384 return err;
1385 midi_opened[midi_dev] = 1;
1386 return 0;
1387
1388 case SNDCTL_SEQ_GETINCOUNT:
1389 if (mode == OPEN_WRITE)
1390 return 0;
1391 val = iqlen;
1392 break;
1393
1394 case SNDCTL_SEQ_GETOUTCOUNT:
1395 if (mode == OPEN_READ)
1396 return 0;
1397 val = SEQ_MAX_QUEUE - qlen;
1398 break;
1399
1400 case SNDCTL_SEQ_GETTIME:
1401 if (seq_mode == SEQ_2)
1402 return tmr->ioctl(tmr_no, cmd, arg);
1403 val = jiffies - seq_time;
1404 break;
1405
1406 case SNDCTL_SEQ_CTRLRATE:
1407 /*
1408 * If *arg == 0, just return the current rate
1409 */
1410 if (seq_mode == SEQ_2)
1411 return tmr->ioctl(tmr_no, cmd, arg);
1412
1413 if (get_user(val, p))
1414 return -EFAULT;
1415 if (val != 0)
1416 return -EINVAL;
1417 val = HZ;
1418 break;
1419
1420 case SNDCTL_SEQ_RESETSAMPLES:
1421 case SNDCTL_SYNTH_REMOVESAMPLE:
1422 case SNDCTL_SYNTH_CONTROL:
1423 if (get_user(dev, p))
1424 return -EFAULT;
1425 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1426 return -ENXIO;
1427 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1428 return -EBUSY;
1429 return synth_devs[dev]->ioctl(dev, cmd, arg);
1430
1431 case SNDCTL_SEQ_NRSYNTHS:
1432 val = max_synthdev;
1433 break;
1434
1435 case SNDCTL_SEQ_NRMIDIS:
1436 val = max_mididev;
1437 break;
1438
1439 case SNDCTL_SYNTH_MEMAVL:
1440 if (get_user(dev, p))
1441 return -EFAULT;
1442 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1443 return -ENXIO;
1444 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1445 return -EBUSY;
1446 val = synth_devs[dev]->ioctl(dev, cmd, arg);
1447 break;
1448
1449 case SNDCTL_FM_4OP_ENABLE:
1450 if (get_user(dev, p))
1451 return -EFAULT;
1452 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1453 return -ENXIO;
1454 if (!(synth_open_mask & (1 << dev)))
1455 return -ENXIO;
1456 synth_devs[dev]->ioctl(dev, cmd, arg);
1457 return 0;
1458
1459 case SNDCTL_SYNTH_INFO:
1460 if (get_user(dev, &((struct synth_info __user *)arg)->device))
1461 return -EFAULT;
1462 if (dev < 0 || dev >= max_synthdev)
1463 return -ENXIO;
1464 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1465 return -EBUSY;
1466 return synth_devs[dev]->ioctl(dev, cmd, arg);
1467
1468 /* Like SYNTH_INFO but returns ID in the name field */
1469 case SNDCTL_SYNTH_ID:
1470 if (get_user(dev, &((struct synth_info __user *)arg)->device))
1471 return -EFAULT;
1472 if (dev < 0 || dev >= max_synthdev)
1473 return -ENXIO;
1474 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1475 return -EBUSY;
1476 memcpy(&inf, synth_devs[dev]->info, sizeof(inf));
1477 strlcpy(inf.name, synth_devs[dev]->id, sizeof(inf.name));
1478 inf.device = dev;
1479 return copy_to_user(arg, &inf, sizeof(inf))?-EFAULT:0;
1480
1481 case SNDCTL_SEQ_OUTOFBAND:
1482 if (copy_from_user(&event_rec, arg, sizeof(event_rec)))
1483 return -EFAULT;
1484 spin_lock_irqsave(&lock,flags);
1485 play_event(event_rec.arr);
1486 spin_unlock_irqrestore(&lock,flags);
1487 return 0;
1488
1489 case SNDCTL_MIDI_INFO:
1490 if (get_user(dev, &((struct midi_info __user *)arg)->device))
1491 return -EFAULT;
1492 if (dev < 0 || dev >= max_mididev || !midi_devs[dev])
1493 return -ENXIO;
1494 midi_devs[dev]->info.device = dev;
1495 return copy_to_user(arg, &midi_devs[dev]->info, sizeof(struct midi_info))?-EFAULT:0;
1496
1497 case SNDCTL_SEQ_THRESHOLD:
1498 if (get_user(val, p))
1499 return -EFAULT;
1500 if (val < 1)
1501 val = 1;
1502 if (val >= SEQ_MAX_QUEUE)
1503 val = SEQ_MAX_QUEUE - 1;
1504 output_threshold = val;
1505 return 0;
1506
1507 case SNDCTL_MIDI_PRETIME:
1508 if (get_user(val, p))
1509 return -EFAULT;
1510 if (val < 0)
1511 val = 0;
1512 val = (HZ * val) / 10;
1513 pre_event_timeout = val;
1514 break;
1515
1516 default:
1517 if (mode == OPEN_READ)
1518 return -EIO;
1519 if (!synth_devs[0])
1520 return -ENXIO;
1521 if (!(synth_open_mask & (1 << 0)))
1522 return -ENXIO;
1523 if (!synth_devs[0]->ioctl)
1524 return -EINVAL;
1525 return synth_devs[0]->ioctl(0, cmd, arg);
1526 }
1527 return put_user(val, p);
1528}
1529
1530/* No kernel lock - we're using the global irq lock here */
1531unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait)
1532{
1533 unsigned long flags;
1534 unsigned int mask = 0;
1535
1536 dev = dev >> 4;
1537
1538 spin_lock_irqsave(&lock,flags);
1539 /* input */
1540 poll_wait(file, &midi_sleeper, wait);
1541 if (iqlen)
1542 mask |= POLLIN | POLLRDNORM;
1543
1544 /* output */
1545 poll_wait(file, &seq_sleeper, wait);
1546 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
1547 mask |= POLLOUT | POLLWRNORM;
1548 spin_unlock_irqrestore(&lock,flags);
1549 return mask;
1550}
1551
1552
1553void sequencer_timer(unsigned long dummy)
1554{
1555 seq_startplay();
1556}
1557
1558int note_to_freq(int note_num)
1559{
1560
1561 /*
1562 * This routine converts a midi note to a frequency (multiplied by 1000)
1563 */
1564
1565 int note, octave, note_freq;
1566 static int notes[] =
1567 {
1568 261632, 277189, 293671, 311132, 329632, 349232,
1569 369998, 391998, 415306, 440000, 466162, 493880
1570 };
1571
1572#define BASE_OCTAVE 5
1573
1574 octave = note_num / 12;
1575 note = note_num % 12;
1576
1577 note_freq = notes[note];
1578
1579 if (octave < BASE_OCTAVE)
1580 note_freq >>= (BASE_OCTAVE - octave);
1581 else if (octave > BASE_OCTAVE)
1582 note_freq <<= (octave - BASE_OCTAVE);
1583
1584 /*
1585 * note_freq >>= 1;
1586 */
1587
1588 return note_freq;
1589}
1590
1591unsigned long compute_finetune(unsigned long base_freq, int bend, int range,
1592 int vibrato_cents)
1593{
1594 unsigned long amount;
1595 int negative, semitones, cents, multiplier = 1;
1596
1597 if (!bend)
1598 return base_freq;
1599 if (!range)
1600 return base_freq;
1601
1602 if (!base_freq)
1603 return base_freq;
1604
1605 if (range >= 8192)
1606 range = 8192;
1607
1608 bend = bend * range / 8192; /* Convert to cents */
1609 bend += vibrato_cents;
1610
1611 if (!bend)
1612 return base_freq;
1613
1614 negative = bend < 0 ? 1 : 0;
1615
1616 if (bend < 0)
1617 bend *= -1;
1618 if (bend > range)
1619 bend = range;
1620
1621 /*
1622 if (bend > 2399)
1623 bend = 2399;
1624 */
1625 while (bend > 2399)
1626 {
1627 multiplier *= 4;
1628 bend -= 2400;
1629 }
1630
1631 semitones = bend / 100;
1632 if (semitones > 99)
1633 semitones = 99;
1634 cents = bend % 100;
1635
1636 amount = (int) (semitone_tuning[semitones] * multiplier * cent_tuning[cents]) / 10000;
1637
1638 if (negative)
1639 return (base_freq * 10000) / amount; /* Bend down */
1640 else
1641 return (base_freq * amount) / 10000; /* Bend up */
1642}
1643
1644
1645void sequencer_init(void)
1646{
1647 /* drag in sequencer_syms.o */
1648 {
1649 extern char sequencer_syms_symbol;
1650 sequencer_syms_symbol = 0;
1651 }
1652
1653 if (sequencer_ok)
1654 return;
1655 MIDIbuf_init();
1656 queue = (unsigned char *)vmalloc(SEQ_MAX_QUEUE * EV_SZ);
1657 if (queue == NULL)
1658 {
1659 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer output queue\n");
1660 return;
1661 }
1662 iqueue = (unsigned char *)vmalloc(SEQ_MAX_QUEUE * IEV_SZ);
1663 if (iqueue == NULL)
1664 {
1665 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer input queue\n");
1666 vfree(queue);
1667 return;
1668 }
1669 sequencer_ok = 1;
1670}
1671
1672void sequencer_unload(void)
1673{
1674 if(queue)
1675 {
1676 vfree(queue);
1677 queue=NULL;
1678 }
1679 if(iqueue)
1680 {
1681 vfree(iqueue);
1682 iqueue=NULL;
1683 }
1684}
diff --git a/sound/oss/sequencer_syms.c b/sound/oss/sequencer_syms.c
new file mode 100644
index 000000000000..45edfd767e4e
--- /dev/null
+++ b/sound/oss/sequencer_syms.c
@@ -0,0 +1,30 @@
1/*
2 * Exported symbols for sequencer driver.
3 */
4
5#include <linux/module.h>
6
7char sequencer_syms_symbol;
8
9#include "sound_config.h"
10#include "sound_calls.h"
11
12EXPORT_SYMBOL(note_to_freq);
13EXPORT_SYMBOL(compute_finetune);
14EXPORT_SYMBOL(seq_copy_to_input);
15EXPORT_SYMBOL(seq_input_event);
16EXPORT_SYMBOL(sequencer_init);
17EXPORT_SYMBOL(sequencer_timer);
18
19EXPORT_SYMBOL(sound_timer_init);
20EXPORT_SYMBOL(sound_timer_interrupt);
21EXPORT_SYMBOL(sound_timer_syncinterval);
22EXPORT_SYMBOL(reprogram_timer);
23
24/* Tuning */
25
26#define _SEQUENCER_C_
27#include "tuning.h"
28
29EXPORT_SYMBOL(cent_tuning);
30EXPORT_SYMBOL(semitone_tuning);
diff --git a/sound/oss/sgalaxy.c b/sound/oss/sgalaxy.c
new file mode 100644
index 000000000000..3f32d4674371
--- /dev/null
+++ b/sound/oss/sgalaxy.c
@@ -0,0 +1,207 @@
1/*
2 * sound/sgalaxy.c
3 *
4 * Low level driver for Aztech Sound Galaxy cards.
5 * Copyright 1998 Artur Skawina <skawina@geocities.com>
6 *
7 * Supported cards:
8 * Aztech Sound Galaxy Waverider Pro 32 - 3D
9 * Aztech Sound Galaxy Washington 16
10 *
11 * Based on cs4232.c by Hannu Savolainen and Alan Cox.
12 *
13 *
14 * Copyright (C) by Hannu Savolainen 1993-1997
15 *
16 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
17 * Version 2 (June 1991). See the "COPYING" file distributed with this software
18 * for more info.
19 *
20 * Changes:
21 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
22 * Added __init to sb_rst() and sb_cmd()
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27
28#include "sound_config.h"
29#include "ad1848.h"
30
31static void sleep( unsigned howlong )
32{
33 current->state = TASK_INTERRUPTIBLE;
34 schedule_timeout(howlong);
35}
36
37#define DPORT 0x80
38
39/* Sound Blaster regs */
40
41#define SBDSP_RESET 0x6
42#define SBDSP_READ 0xA
43#define SBDSP_COMMAND 0xC
44#define SBDSP_STATUS SBDSP_COMMAND
45#define SBDSP_DATA_AVAIL 0xE
46
47static int __init sb_rst(int base)
48{
49 int i;
50
51 outb( 1, base+SBDSP_RESET ); /* reset the DSP */
52 outb( 0, base+SBDSP_RESET );
53
54 for ( i=0; i<500; i++ ) /* delay */
55 inb(DPORT);
56
57 for ( i=0; i<100000; i++ )
58 {
59 if ( inb( base+SBDSP_DATA_AVAIL )&0x80 )
60 break;
61 }
62
63 if ( inb( base+SBDSP_READ )!=0xAA )
64 return 0;
65
66 return 1;
67}
68
69static int __init sb_cmd( int base, unsigned char val )
70{
71 int i;
72
73 for ( i=100000; i; i-- )
74 {
75 if ( (inb( base+SBDSP_STATUS )&0x80)==0 )
76 {
77 outb( val, base+SBDSP_COMMAND );
78 break;
79 }
80 }
81 return i; /* i>0 == success */
82}
83
84
85#define ai_sgbase driver_use_1
86
87static int __init probe_sgalaxy( struct address_info *ai )
88{
89 struct resource *ports;
90 int n;
91
92 if (!request_region(ai->io_base, 4, "WSS config")) {
93 printk(KERN_ERR "sgalaxy: WSS IO port 0x%03x not available\n", ai->io_base);
94 return 0;
95 }
96
97 ports = request_region(ai->io_base + 4, 4, "ad1848");
98 if (!ports) {
99 printk(KERN_ERR "sgalaxy: WSS IO port 0x%03x not available\n", ai->io_base);
100 release_region(ai->io_base, 4);
101 return 0;
102 }
103
104 if (!request_region( ai->ai_sgbase, 0x10, "SoundGalaxy SB")) {
105 printk(KERN_ERR "sgalaxy: SB IO port 0x%03x not available\n", ai->ai_sgbase);
106 release_region(ai->io_base + 4, 4);
107 release_region(ai->io_base, 4);
108 return 0;
109 }
110
111 if (ad1848_detect(ports, NULL, ai->osp))
112 goto out; /* The card is already active, check irq etc... */
113
114 /* switch to MSS/WSS mode */
115
116 sb_rst( ai->ai_sgbase );
117
118 sb_cmd( ai->ai_sgbase, 9 );
119 sb_cmd( ai->ai_sgbase, 0 );
120
121 sleep( HZ/10 );
122
123out:
124 if (!probe_ms_sound(ai, ports)) {
125 release_region(ai->io_base + 4, 4);
126 release_region(ai->io_base, 4);
127 release_region(ai->ai_sgbase, 0x10);
128 return 0;
129 }
130
131 attach_ms_sound(ai, ports, THIS_MODULE);
132 n=ai->slots[0];
133
134 if (n!=-1 && audio_devs[n]->mixer_dev != -1 ) {
135 AD1848_REROUTE( SOUND_MIXER_LINE1, SOUND_MIXER_LINE ); /* Line-in */
136 AD1848_REROUTE( SOUND_MIXER_LINE2, SOUND_MIXER_SYNTH ); /* FM+Wavetable*/
137 AD1848_REROUTE( SOUND_MIXER_LINE3, SOUND_MIXER_CD ); /* CD */
138 }
139 return 1;
140}
141
142static void __exit unload_sgalaxy( struct address_info *ai )
143{
144 unload_ms_sound( ai );
145 release_region( ai->ai_sgbase, 0x10 );
146}
147
148static struct address_info cfg;
149
150static int __initdata io = -1;
151static int __initdata irq = -1;
152static int __initdata dma = -1;
153static int __initdata dma2 = -1;
154static int __initdata sgbase = -1;
155
156module_param(io, int, 0);
157module_param(irq, int, 0);
158module_param(dma, int, 0);
159module_param(dma2, int, 0);
160module_param(sgbase, int, 0);
161
162static int __init init_sgalaxy(void)
163{
164 cfg.io_base = io;
165 cfg.irq = irq;
166 cfg.dma = dma;
167 cfg.dma2 = dma2;
168 cfg.ai_sgbase = sgbase;
169
170 if (cfg.io_base == -1 || cfg.irq == -1 || cfg.dma == -1 || cfg.ai_sgbase == -1 ) {
171 printk(KERN_ERR "sgalaxy: io, irq, dma and sgbase must be set.\n");
172 return -EINVAL;
173 }
174
175 if ( probe_sgalaxy(&cfg) == 0 )
176 return -ENODEV;
177
178 return 0;
179}
180
181static void __exit cleanup_sgalaxy(void)
182{
183 unload_sgalaxy(&cfg);
184}
185
186module_init(init_sgalaxy);
187module_exit(cleanup_sgalaxy);
188
189#ifndef MODULE
190static int __init setup_sgalaxy(char *str)
191{
192 /* io, irq, dma, dma2, sgbase */
193 int ints[6];
194
195 str = get_options(str, ARRAY_SIZE(ints), ints);
196 io = ints[1];
197 irq = ints[2];
198 dma = ints[3];
199 dma2 = ints[4];
200 sgbase = ints[5];
201
202 return 1;
203}
204
205__setup("sgalaxy=", setup_sgalaxy);
206#endif
207MODULE_LICENSE("GPL");
diff --git a/sound/oss/sh_dac_audio.c b/sound/oss/sh_dac_audio.c
new file mode 100644
index 000000000000..c09cdeedc191
--- /dev/null
+++ b/sound/oss/sh_dac_audio.c
@@ -0,0 +1,325 @@
1#include <linux/config.h>
2#include <linux/module.h>
3#include <linux/init.h>
4#include <linux/sched.h>
5#include <linux/version.h>
6#include <linux/linkage.h>
7#include <linux/slab.h>
8#include <linux/fs.h>
9#include <linux/sound.h>
10#include <linux/soundcard.h>
11#include <asm/io.h>
12#include <asm/uaccess.h>
13#include <asm/irq.h>
14#include <asm/delay.h>
15#include <linux/interrupt.h>
16
17#include <asm/cpu/dac.h>
18
19#ifdef MACH_HP600
20#include <asm/hp6xx/hp6xx.h>
21#include <asm/hd64461/hd64461.h>
22#endif
23
24#define MODNAME "sh_dac_audio"
25
26#define TMU_TOCR_INIT 0x00
27
28#define TMU1_TCR_INIT 0x0020 /* Clock/4, rising edge; interrupt on */
29#define TMU1_TSTR_INIT 0x02 /* Bit to turn on TMU1 */
30
31#define TMU_TSTR 0xfffffe92
32#define TMU1_TCOR 0xfffffea0
33#define TMU1_TCNT 0xfffffea4
34#define TMU1_TCR 0xfffffea8
35
36#define BUFFER_SIZE 48000
37
38static int rate;
39static int empty;
40static char *data_buffer, *buffer_begin, *buffer_end;
41static int in_use, device_major;
42
43static void dac_audio_start_timer(void)
44{
45 u8 tstr;
46
47 tstr = ctrl_inb(TMU_TSTR);
48 tstr |= TMU1_TSTR_INIT;
49 ctrl_outb(tstr, TMU_TSTR);
50}
51
52static void dac_audio_stop_timer(void)
53{
54 u8 tstr;
55
56 tstr = ctrl_inb(TMU_TSTR);
57 tstr &= ~TMU1_TSTR_INIT;
58 ctrl_outb(tstr, TMU_TSTR);
59}
60
61static void dac_audio_reset(void)
62{
63 dac_audio_stop_timer();
64 buffer_begin = buffer_end = data_buffer;
65 empty = 1;
66}
67
68static void dac_audio_sync(void)
69{
70 while (!empty)
71 schedule();
72}
73
74static void dac_audio_start(void)
75{
76#ifdef MACH_HP600
77 u16 v;
78 v = inw(HD64461_GPADR);
79 v &= ~HD64461_GPADR_SPEAKER;
80 outw(v, HD64461_GPADR);
81#endif
82 sh_dac_enable(CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL);
83 ctrl_outw(TMU1_TCR_INIT, TMU1_TCR);
84}
85static void dac_audio_stop(void)
86{
87#ifdef MACH_HP600
88 u16 v;
89#endif
90 dac_audio_stop_timer();
91#ifdef MACH_HP600
92 v = inw(HD64461_GPADR);
93 v |= HD64461_GPADR_SPEAKER;
94 outw(v, HD64461_GPADR);
95#endif
96 sh_dac_disable(CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL);
97}
98
99static void dac_audio_set_rate(void)
100{
101 unsigned long interval;
102
103 interval = (current_cpu_data.module_clock / 4) / rate;
104 ctrl_outl(interval, TMU1_TCOR);
105 ctrl_outl(interval, TMU1_TCNT);
106}
107
108static int dac_audio_ioctl(struct inode *inode, struct file *file,
109 unsigned int cmd, unsigned long arg)
110{
111 int val;
112
113 switch (cmd) {
114 case OSS_GETVERSION:
115 return put_user(SOUND_VERSION, (int *)arg);
116
117 case SNDCTL_DSP_SYNC:
118 dac_audio_sync();
119 return 0;
120
121 case SNDCTL_DSP_RESET:
122 dac_audio_reset();
123 return 0;
124
125 case SNDCTL_DSP_GETFMTS:
126 return put_user(AFMT_U8, (int *)arg);
127
128 case SNDCTL_DSP_SETFMT:
129 return put_user(AFMT_U8, (int *)arg);
130
131 case SNDCTL_DSP_NONBLOCK:
132 file->f_flags |= O_NONBLOCK;
133 return 0;
134
135 case SNDCTL_DSP_GETCAPS:
136 return 0;
137
138 case SOUND_PCM_WRITE_RATE:
139 val = *(int *)arg;
140 if (val > 0) {
141 rate = val;
142 dac_audio_set_rate();
143 }
144 return put_user(rate, (int *)arg);
145
146 case SNDCTL_DSP_STEREO:
147 return put_user(0, (int *)arg);
148
149 case SOUND_PCM_WRITE_CHANNELS:
150 return put_user(1, (int *)arg);
151
152 case SNDCTL_DSP_SETDUPLEX:
153 return -EINVAL;
154
155 case SNDCTL_DSP_PROFILE:
156 return -EINVAL;
157
158 case SNDCTL_DSP_GETBLKSIZE:
159 return put_user(BUFFER_SIZE, (int *)arg);
160
161 case SNDCTL_DSP_SETFRAGMENT:
162 return 0;
163
164 default:
165 printk(KERN_ERR "sh_dac_audio: unimplemented ioctl=0x%x\n",
166 cmd);
167 return -EINVAL;
168 }
169 return -EINVAL;
170}
171
172static ssize_t dac_audio_write(struct file *file, const char *buf, size_t count,
173 loff_t * ppos)
174{
175 int free;
176 int nbytes;
177
178 if (count < 0)
179 return -EINVAL;
180
181 if (!count) {
182 dac_audio_sync();
183 return 0;
184 }
185
186 free = buffer_begin - buffer_end;
187
188 if (free < 0)
189 free += BUFFER_SIZE;
190 if ((free == 0) && (empty))
191 free = BUFFER_SIZE;
192 if (count > free)
193 count = free;
194 if (buffer_begin > buffer_end) {
195 if (copy_from_user((void *)buffer_end, buf, count))
196 return -EFAULT;
197
198 buffer_end += count;
199 } else {
200 nbytes = data_buffer + BUFFER_SIZE - buffer_end;
201 if (nbytes > count) {
202 if (copy_from_user((void *)buffer_end, buf, count))
203 return -EFAULT;
204 buffer_end += count;
205 } else {
206 if (copy_from_user((void *)buffer_end, buf, nbytes))
207 return -EFAULT;
208 if (copy_from_user
209 ((void *)data_buffer, buf + nbytes, count - nbytes))
210 return -EFAULT;
211 buffer_end = data_buffer + count - nbytes;
212 }
213 }
214
215 if (empty) {
216 empty = 0;
217 dac_audio_start_timer();
218 }
219
220 return count;
221}
222
223static ssize_t dac_audio_read(struct file *file, char *buf, size_t count,
224 loff_t * ppos)
225{
226 return -EINVAL;
227}
228
229static int dac_audio_open(struct inode *inode, struct file *file)
230{
231 if (file->f_mode & FMODE_READ)
232 return -ENODEV;
233 if (in_use)
234 return -EBUSY;
235
236 in_use = 1;
237
238 dac_audio_start();
239
240 return 0;
241}
242
243static int dac_audio_release(struct inode *inode, struct file *file)
244{
245 dac_audio_sync();
246 dac_audio_stop();
247 in_use = 0;
248
249 return 0;
250}
251
252struct file_operations dac_audio_fops = {
253 .read = dac_audio_read,
254 .write = dac_audio_write,
255 .ioctl = dac_audio_ioctl,
256 .open = dac_audio_open,
257 .release = dac_audio_release,
258};
259
260static irqreturn_t timer1_interrupt(int irq, void *dev, struct pt_regs *regs)
261{
262 unsigned long timer_status;
263
264 timer_status = ctrl_inw(TMU1_TCR);
265 timer_status &= ~0x100;
266 ctrl_outw(timer_status, TMU1_TCR);
267
268 if (!empty) {
269 sh_dac_output(*buffer_begin, CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL);
270 buffer_begin++;
271
272 if (buffer_begin == data_buffer + BUFFER_SIZE)
273 buffer_begin = data_buffer;
274 if (buffer_begin == buffer_end) {
275 empty = 1;
276 dac_audio_stop_timer();
277 }
278 }
279 return IRQ_HANDLED;
280}
281
282static int __init dac_audio_init(void)
283{
284 int retval;
285
286 if ((device_major = register_sound_dsp(&dac_audio_fops, -1)) < 0) {
287 printk(KERN_ERR "Cannot register dsp device");
288 return device_major;
289 }
290
291 in_use = 0;
292
293 data_buffer = (char *)kmalloc(BUFFER_SIZE, GFP_KERNEL);
294 if (data_buffer == NULL)
295 return -ENOMEM;
296
297 dac_audio_reset();
298 rate = 8000;
299 dac_audio_set_rate();
300
301 retval =
302 request_irq(TIMER1_IRQ, timer1_interrupt, SA_INTERRUPT, MODNAME, 0);
303 if (retval < 0) {
304 printk(KERN_ERR "sh_dac_audio: IRQ %d request failed\n",
305 TIMER1_IRQ);
306 return retval;
307 }
308
309 return 0;
310}
311
312static void __exit dac_audio_exit(void)
313{
314 free_irq(TIMER1_IRQ, 0);
315
316 unregister_sound_dsp(device_major);
317 kfree((void *)data_buffer);
318}
319
320module_init(dac_audio_init);
321module_exit(dac_audio_exit);
322
323MODULE_AUTHOR("Andriy Skulysh, askulysh@image.kiev.ua");
324MODULE_DESCRIPTION("SH DAC sound driver");
325MODULE_LICENSE("GPL");
diff --git a/sound/oss/skeleton.c b/sound/oss/skeleton.c
new file mode 100644
index 000000000000..8fea783dd0cb
--- /dev/null
+++ b/sound/oss/skeleton.c
@@ -0,0 +1,219 @@
1/*
2 * PCI sound skeleton example
3 *
4 * (c) 1998 Red Hat Software
5 *
6 * This software may be used and distributed according to the
7 * terms of the GNU General Public License, incorporated herein by
8 * reference.
9 *
10 * This example is designed to be built in the linux/drivers/sound
11 * directory as part of a kernel build. The example is modular only
12 * drop me a note once you have a working modular driver and want
13 * to integrate it with the main code.
14 * -- Alan <alan@redhat.com>
15 *
16 * This is a first draft. Please report any errors, corrections or
17 * improvements to me.
18 */
19
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <linux/errno.h>
23#include <linux/fs.h>
24#include <linux/kernel.h>
25#include <linux/pci.h>
26
27#include <asm/io.h>
28
29#include "sound_config.h"
30
31/*
32 * Define our PCI vendor ID here
33 */
34
35#ifndef PCI_VENDOR_MYIDENT
36#define PCI_VENDOR_MYIDENT 0x125D
37
38/*
39 * PCI identity for the card.
40 */
41
42#define PCI_DEVICE_ID_MYIDENT_MYCARD1 0x1969
43#endif
44
45#define CARD_NAME "ExampleWave 3D Pro Ultra ThingyWotsit"
46
47#define MAX_CARDS 8
48
49/*
50 * Each address_info object holds the information about one of
51 * our card resources. In this case the MSS emulation of our
52 * ficticious card. Its used to manage and attach things.
53 */
54
55static struct address_info mss_data[MAX_CARDS];
56static int cards;
57
58/*
59 * Install the actual card. This is an example
60 */
61
62static int mycard_install(struct pci_dev *pcidev)
63{
64 int iobase;
65 int mssbase;
66 int mpubase;
67 u8 x;
68 u16 w;
69 u32 v;
70 int i;
71 int dma;
72
73 /*
74 * Our imaginary code has its I/O on PCI address 0, a
75 * MSS on PCI address 1 and an MPU on address 2
76 *
77 * For the example we will only initialise the MSS
78 */
79
80 iobase = pci_resource_start(pcidev, 0);
81 mssbase = pci_resource_start(pcidev, 1);
82 mpubase = pci_resource_start(pcidev, 2);
83
84 /*
85 * Reset the board
86 */
87
88 /*
89 * Wait for completion. udelay() waits in microseconds
90 */
91
92 udelay(100);
93
94 /*
95 * Ok card ready. Begin setup proper. You might for example
96 * load the firmware here
97 */
98
99 dma = card_specific_magic(ioaddr);
100
101 /*
102 * Turn on legacy mode (example), There are also byte and
103 * dword (32bit) PCI configuration function calls
104 */
105
106 pci_read_config_word(pcidev, 0x40, &w);
107 w&=~(1<<15); /* legacy decode on */
108 w|=(1<<14); /* Reserved write as 1 in this case */
109 w|=(1<<3)|(1<<1)|(1<<0); /* SB on , FM on, MPU on */
110 pci_write_config_word(pcidev, 0x40, w);
111
112 /*
113 * Let the user know we found his toy.
114 */
115
116 printk(KERN_INFO "Programmed "CARD_NAME" at 0x%X to legacy mode.\n",
117 iobase);
118
119 /*
120 * Now set it up the description of the card
121 */
122
123 mss_data[cards].io_base = mssbase;
124 mss_data[cards].irq = pcidev->irq;
125 mss_data[cards].dma = dma;
126
127 /*
128 * Check there is an MSS present
129 */
130
131 if(ad1848_detect(mssbase, NULL, mss_data[cards].osp)==0)
132 return 0;
133
134 /*
135 * Initialize it
136 */
137
138 mss_data[cards].slots[3] = ad1848_init("MyCard MSS 16bit",
139 mssbase,
140 mss_data[cards].irq,
141 mss_data[cards].dma,
142 mss_data[cards].dma,
143 0,
144 0,
145 THIS_MODULE);
146
147 cards++;
148 return 1;
149}
150
151
152/*
153 * This loop walks the PCI configuration database and finds where
154 * the sound cards are.
155 */
156
157int init_mycard(void)
158{
159 struct pci_dev *pcidev=NULL;
160 int count=0;
161
162 while((pcidev = pci_find_device(PCI_VENDOR_MYIDENT, PCI_DEVICE_ID_MYIDENT_MYCARD1, pcidev))!=NULL)
163 {
164 if (pci_enable_device(pcidev))
165 continue;
166 count+=mycard_install(pcidev);
167 if(count)
168 return 0;
169 if(count==MAX_CARDS)
170 break;
171 }
172
173 if(count==0)
174 return -ENODEV;
175 return 0;
176}
177
178/*
179 * This function is called when the user or kernel loads the
180 * module into memory.
181 */
182
183
184int init_module(void)
185{
186 if(init_mycard()<0)
187 {
188 printk(KERN_ERR "No "CARD_NAME" cards found.\n");
189 return -ENODEV;
190 }
191
192 return 0;
193}
194
195/*
196 * This is called when it is removed. It will only be removed
197 * when its use count is 0.
198 */
199
200void cleanup_module(void)
201{
202 for(i=0;i< cards; i++)
203 {
204 /*
205 * Free attached resources
206 */
207
208 ad1848_unload(mss_data[i].io_base,
209 mss_data[i].irq,
210 mss_data[i].dma,
211 mss_data[i].dma,
212 0);
213 /*
214 * And disconnect the device from the kernel
215 */
216 sound_unload_audiodevice(mss_data[i].slots[3]);
217 }
218}
219
diff --git a/sound/oss/sonicvibes.c b/sound/oss/sonicvibes.c
new file mode 100644
index 000000000000..e1d69611a257
--- /dev/null
+++ b/sound/oss/sonicvibes.c
@@ -0,0 +1,2792 @@
1/*****************************************************************************/
2
3/*
4 * sonicvibes.c -- S3 Sonic Vibes audio driver.
5 *
6 * Copyright (C) 1998-2001, 2003 Thomas Sailer (t.sailer@alumni.ethz.ch)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * Special thanks to David C. Niemi
23 *
24 *
25 * Module command line parameters:
26 * none so far
27 *
28 *
29 * Supported devices:
30 * /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
31 * /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
32 * /dev/midi simple MIDI UART interface, no ioctl
33 *
34 * The card has both an FM and a Wavetable synth, but I have to figure
35 * out first how to drive them...
36 *
37 * Revision history
38 * 06.05.1998 0.1 Initial release
39 * 10.05.1998 0.2 Fixed many bugs, esp. ADC rate calculation
40 * First stab at a simple midi interface (no bells&whistles)
41 * 13.05.1998 0.3 Fix stupid cut&paste error: set_adc_rate was called instead of
42 * set_dac_rate in the FMODE_WRITE case in sv_open
43 * Fix hwptr out of bounds (now mpg123 works)
44 * 14.05.1998 0.4 Don't allow excessive interrupt rates
45 * 08.06.1998 0.5 First release using Alan Cox' soundcore instead of miscdevice
46 * 03.08.1998 0.6 Do not include modversions.h
47 * Now mixer behaviour can basically be selected between
48 * "OSS documented" and "OSS actual" behaviour
49 * 31.08.1998 0.7 Fix realplayer problems - dac.count issues
50 * 10.12.1998 0.8 Fix drain_dac trying to wait on not yet initialized DMA
51 * 16.12.1998 0.9 Fix a few f_file & FMODE_ bugs
52 * 06.01.1999 0.10 remove the silly SA_INTERRUPT flag.
53 * hopefully killed the egcs section type conflict
54 * 12.03.1999 0.11 cinfo.blocks should be reset after GETxPTR ioctl.
55 * reported by Johan Maes <joma@telindus.be>
56 * 22.03.1999 0.12 return EAGAIN instead of EBUSY when O_NONBLOCK
57 * read/write cannot be executed
58 * 05.04.1999 0.13 added code to sv_read and sv_write which should detect
59 * lockups of the sound chip and revive it. This is basically
60 * an ugly hack, but at least applications using this driver
61 * won't hang forever. I don't know why these lockups happen,
62 * it might well be the motherboard chipset (an early 486 PCI
63 * board with ALI chipset), since every busmastering 100MB
64 * ethernet card I've tried (Realtek 8139 and Macronix tulip clone)
65 * exhibit similar behaviour (they work for a couple of packets
66 * and then lock up and can be revived by ifconfig down/up).
67 * 07.04.1999 0.14 implemented the following ioctl's: SOUND_PCM_READ_RATE,
68 * SOUND_PCM_READ_CHANNELS, SOUND_PCM_READ_BITS;
69 * Alpha fixes reported by Peter Jones <pjones@redhat.com>
70 * Note: dmaio hack might still be wrong on archs other than i386
71 * 15.06.1999 0.15 Fix bad allocation bug.
72 * Thanks to Deti Fliegl <fliegl@in.tum.de>
73 * 28.06.1999 0.16 Add pci_set_master
74 * 03.08.1999 0.17 adapt to Linus' new __setup/__initcall
75 * added kernel command line options "sonicvibes=reverb" and "sonicvibesdmaio=dmaioaddr"
76 * 12.08.1999 0.18 module_init/__setup fixes
77 * 24.08.1999 0.19 get rid of the dmaio kludge, replace with allocate_resource
78 * 31.08.1999 0.20 add spin_lock_init
79 * use new resource allocation to allocate DDMA IO space
80 * replaced current->state = x with set_current_state(x)
81 * 03.09.1999 0.21 change read semantics for MIDI to match
82 * OSS more closely; remove possible wakeup race
83 * 28.10.1999 0.22 More waitqueue races fixed
84 * 01.12.1999 0.23 New argument to allocate_resource
85 * 07.12.1999 0.24 More allocate_resource semantics change
86 * 08.01.2000 0.25 Prevent some ioctl's from returning bad count values on underrun/overrun;
87 * Tim Janik's BSE (Bedevilled Sound Engine) found this
88 * use Martin Mares' pci_assign_resource
89 * 07.02.2000 0.26 Use pci_alloc_consistent and pci_register_driver
90 * 21.11.2000 0.27 Initialize dma buffers in poll, otherwise poll may return a bogus mask
91 * 12.12.2000 0.28 More dma buffer initializations, patch from
92 * Tjeerd Mulder <tjeerd.mulder@fujitsu-siemens.com>
93 * 31.01.2001 0.29 Register/Unregister gameport
94 * Fix SETTRIGGER non OSS API conformity
95 * 18.05.2001 0.30 PCI probing and error values cleaned up by Marcus
96 * Meissner <mm@caldera.de>
97 * 03.01.2003 0.31 open_mode fixes from Georg Acher <acher@in.tum.de>
98 *
99 */
100
101/*****************************************************************************/
102
103#include <linux/module.h>
104#include <linux/string.h>
105#include <linux/ioport.h>
106#include <linux/interrupt.h>
107#include <linux/wait.h>
108#include <linux/mm.h>
109#include <linux/delay.h>
110#include <linux/sound.h>
111#include <linux/slab.h>
112#include <linux/soundcard.h>
113#include <linux/pci.h>
114#include <linux/init.h>
115#include <linux/poll.h>
116#include <linux/spinlock.h>
117#include <linux/smp_lock.h>
118#include <linux/gameport.h>
119
120#include <asm/io.h>
121#include <asm/uaccess.h>
122
123#include "dm.h"
124
125
126/* --------------------------------------------------------------------- */
127
128#undef OSS_DOCUMENTED_MIXER_SEMANTICS
129
130/* --------------------------------------------------------------------- */
131
132#ifndef PCI_VENDOR_ID_S3
133#define PCI_VENDOR_ID_S3 0x5333
134#endif
135#ifndef PCI_DEVICE_ID_S3_SONICVIBES
136#define PCI_DEVICE_ID_S3_SONICVIBES 0xca00
137#endif
138
139#define SV_MAGIC ((PCI_VENDOR_ID_S3<<16)|PCI_DEVICE_ID_S3_SONICVIBES)
140
141#define SV_EXTENT_SB 0x10
142#define SV_EXTENT_ENH 0x10
143#define SV_EXTENT_SYNTH 0x4
144#define SV_EXTENT_MIDI 0x4
145#define SV_EXTENT_GAME 0x8
146#define SV_EXTENT_DMA 0x10
147
148/*
149 * we are not a bridge and thus use a resource for DDMA that is used for bridges but
150 * left empty for normal devices
151 */
152#define RESOURCE_SB 0
153#define RESOURCE_ENH 1
154#define RESOURCE_SYNTH 2
155#define RESOURCE_MIDI 3
156#define RESOURCE_GAME 4
157#define RESOURCE_DDMA 7
158
159#define SV_MIDI_DATA 0
160#define SV_MIDI_COMMAND 1
161#define SV_MIDI_STATUS 1
162
163#define SV_DMA_ADDR0 0
164#define SV_DMA_ADDR1 1
165#define SV_DMA_ADDR2 2
166#define SV_DMA_ADDR3 3
167#define SV_DMA_COUNT0 4
168#define SV_DMA_COUNT1 5
169#define SV_DMA_COUNT2 6
170#define SV_DMA_MODE 0xb
171#define SV_DMA_RESET 0xd
172#define SV_DMA_MASK 0xf
173
174/*
175 * DONT reset the DMA controllers unless you understand
176 * the reset semantics. Assuming reset semantics as in
177 * the 8237 does not work.
178 */
179
180#define DMA_MODE_AUTOINIT 0x10
181#define DMA_MODE_READ 0x44 /* I/O to memory, no autoinit, increment, single mode */
182#define DMA_MODE_WRITE 0x48 /* memory to I/O, no autoinit, increment, single mode */
183
184#define SV_CODEC_CONTROL 0
185#define SV_CODEC_INTMASK 1
186#define SV_CODEC_STATUS 2
187#define SV_CODEC_IADDR 4
188#define SV_CODEC_IDATA 5
189
190#define SV_CCTRL_RESET 0x80
191#define SV_CCTRL_INTADRIVE 0x20
192#define SV_CCTRL_WAVETABLE 0x08
193#define SV_CCTRL_REVERB 0x04
194#define SV_CCTRL_ENHANCED 0x01
195
196#define SV_CINTMASK_DMAA 0x01
197#define SV_CINTMASK_DMAC 0x04
198#define SV_CINTMASK_SPECIAL 0x08
199#define SV_CINTMASK_UPDOWN 0x40
200#define SV_CINTMASK_MIDI 0x80
201
202#define SV_CSTAT_DMAA 0x01
203#define SV_CSTAT_DMAC 0x04
204#define SV_CSTAT_SPECIAL 0x08
205#define SV_CSTAT_UPDOWN 0x40
206#define SV_CSTAT_MIDI 0x80
207
208#define SV_CIADDR_TRD 0x80
209#define SV_CIADDR_MCE 0x40
210
211/* codec indirect registers */
212#define SV_CIMIX_ADCINL 0x00
213#define SV_CIMIX_ADCINR 0x01
214#define SV_CIMIX_AUX1INL 0x02
215#define SV_CIMIX_AUX1INR 0x03
216#define SV_CIMIX_CDINL 0x04
217#define SV_CIMIX_CDINR 0x05
218#define SV_CIMIX_LINEINL 0x06
219#define SV_CIMIX_LINEINR 0x07
220#define SV_CIMIX_MICIN 0x08
221#define SV_CIMIX_SYNTHINL 0x0A
222#define SV_CIMIX_SYNTHINR 0x0B
223#define SV_CIMIX_AUX2INL 0x0C
224#define SV_CIMIX_AUX2INR 0x0D
225#define SV_CIMIX_ANALOGINL 0x0E
226#define SV_CIMIX_ANALOGINR 0x0F
227#define SV_CIMIX_PCMINL 0x10
228#define SV_CIMIX_PCMINR 0x11
229
230#define SV_CIGAMECONTROL 0x09
231#define SV_CIDATAFMT 0x12
232#define SV_CIENABLE 0x13
233#define SV_CIUPDOWN 0x14
234#define SV_CIREVISION 0x15
235#define SV_CIADCOUTPUT 0x16
236#define SV_CIDMAABASECOUNT1 0x18
237#define SV_CIDMAABASECOUNT0 0x19
238#define SV_CIDMACBASECOUNT1 0x1c
239#define SV_CIDMACBASECOUNT0 0x1d
240#define SV_CIPCMSR0 0x1e
241#define SV_CIPCMSR1 0x1f
242#define SV_CISYNTHSR0 0x20
243#define SV_CISYNTHSR1 0x21
244#define SV_CIADCCLKSOURCE 0x22
245#define SV_CIADCALTSR 0x23
246#define SV_CIADCPLLM 0x24
247#define SV_CIADCPLLN 0x25
248#define SV_CISYNTHPLLM 0x26
249#define SV_CISYNTHPLLN 0x27
250#define SV_CIUARTCONTROL 0x2a
251#define SV_CIDRIVECONTROL 0x2b
252#define SV_CISRSSPACE 0x2c
253#define SV_CISRSCENTER 0x2d
254#define SV_CIWAVETABLESRC 0x2e
255#define SV_CIANALOGPWRDOWN 0x30
256#define SV_CIDIGITALPWRDOWN 0x31
257
258
259#define SV_CIMIX_ADCSRC_CD 0x20
260#define SV_CIMIX_ADCSRC_DAC 0x40
261#define SV_CIMIX_ADCSRC_AUX2 0x60
262#define SV_CIMIX_ADCSRC_LINE 0x80
263#define SV_CIMIX_ADCSRC_AUX1 0xa0
264#define SV_CIMIX_ADCSRC_MIC 0xc0
265#define SV_CIMIX_ADCSRC_MIXOUT 0xe0
266#define SV_CIMIX_ADCSRC_MASK 0xe0
267
268#define SV_CFMT_STEREO 0x01
269#define SV_CFMT_16BIT 0x02
270#define SV_CFMT_MASK 0x03
271#define SV_CFMT_ASHIFT 0
272#define SV_CFMT_CSHIFT 4
273
274static const unsigned sample_size[] = { 1, 2, 2, 4 };
275static const unsigned sample_shift[] = { 0, 1, 1, 2 };
276
277#define SV_CENABLE_PPE 0x4
278#define SV_CENABLE_RE 0x2
279#define SV_CENABLE_PE 0x1
280
281
282/* MIDI buffer sizes */
283
284#define MIDIINBUF 256
285#define MIDIOUTBUF 256
286
287#define FMODE_MIDI_SHIFT 2
288#define FMODE_MIDI_READ (FMODE_READ << FMODE_MIDI_SHIFT)
289#define FMODE_MIDI_WRITE (FMODE_WRITE << FMODE_MIDI_SHIFT)
290
291#define FMODE_DMFM 0x10
292
293/* --------------------------------------------------------------------- */
294
295struct sv_state {
296 /* magic */
297 unsigned int magic;
298
299 /* list of sonicvibes devices */
300 struct list_head devs;
301
302 /* the corresponding pci_dev structure */
303 struct pci_dev *dev;
304
305 /* soundcore stuff */
306 int dev_audio;
307 int dev_mixer;
308 int dev_midi;
309 int dev_dmfm;
310
311 /* hardware resources */
312 unsigned long iosb, ioenh, iosynth, iomidi; /* long for SPARC */
313 unsigned int iodmaa, iodmac, irq;
314
315 /* mixer stuff */
316 struct {
317 unsigned int modcnt;
318#ifndef OSS_DOCUMENTED_MIXER_SEMANTICS
319 unsigned short vol[13];
320#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
321 } mix;
322
323 /* wave stuff */
324 unsigned int rateadc, ratedac;
325 unsigned char fmt, enable;
326
327 spinlock_t lock;
328 struct semaphore open_sem;
329 mode_t open_mode;
330 wait_queue_head_t open_wait;
331
332 struct dmabuf {
333 void *rawbuf;
334 dma_addr_t dmaaddr;
335 unsigned buforder;
336 unsigned numfrag;
337 unsigned fragshift;
338 unsigned hwptr, swptr;
339 unsigned total_bytes;
340 int count;
341 unsigned error; /* over/underrun */
342 wait_queue_head_t wait;
343 /* redundant, but makes calculations easier */
344 unsigned fragsize;
345 unsigned dmasize;
346 unsigned fragsamples;
347 /* OSS stuff */
348 unsigned mapped:1;
349 unsigned ready:1;
350 unsigned endcleared:1;
351 unsigned enabled:1;
352 unsigned ossfragshift;
353 int ossmaxfrags;
354 unsigned subdivision;
355 } dma_dac, dma_adc;
356
357 /* midi stuff */
358 struct {
359 unsigned ird, iwr, icnt;
360 unsigned ord, owr, ocnt;
361 wait_queue_head_t iwait;
362 wait_queue_head_t owait;
363 struct timer_list timer;
364 unsigned char ibuf[MIDIINBUF];
365 unsigned char obuf[MIDIOUTBUF];
366 } midi;
367
368 struct gameport *gameport;
369};
370
371/* --------------------------------------------------------------------- */
372
373static LIST_HEAD(devs);
374static unsigned long wavetable_mem;
375
376/* --------------------------------------------------------------------- */
377
378static inline unsigned ld2(unsigned int x)
379{
380 unsigned r = 0;
381
382 if (x >= 0x10000) {
383 x >>= 16;
384 r += 16;
385 }
386 if (x >= 0x100) {
387 x >>= 8;
388 r += 8;
389 }
390 if (x >= 0x10) {
391 x >>= 4;
392 r += 4;
393 }
394 if (x >= 4) {
395 x >>= 2;
396 r += 2;
397 }
398 if (x >= 2)
399 r++;
400 return r;
401}
402
403/*
404 * hweightN: returns the hamming weight (i.e. the number
405 * of bits set) of a N-bit word
406 */
407
408#ifdef hweight32
409#undef hweight32
410#endif
411
412static inline unsigned int hweight32(unsigned int w)
413{
414 unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
415 res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
416 res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
417 res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
418 return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
419}
420
421/* --------------------------------------------------------------------- */
422
423/*
424 * Why use byte IO? Nobody knows, but S3 does it also in their Windows driver.
425 */
426
427#undef DMABYTEIO
428
429static void set_dmaa(struct sv_state *s, unsigned int addr, unsigned int count)
430{
431#ifdef DMABYTEIO
432 unsigned io = s->iodmaa, u;
433
434 count--;
435 for (u = 4; u > 0; u--, addr >>= 8, io++)
436 outb(addr & 0xff, io);
437 for (u = 3; u > 0; u--, count >>= 8, io++)
438 outb(count & 0xff, io);
439#else /* DMABYTEIO */
440 count--;
441 outl(addr, s->iodmaa + SV_DMA_ADDR0);
442 outl(count, s->iodmaa + SV_DMA_COUNT0);
443#endif /* DMABYTEIO */
444 outb(0x18, s->iodmaa + SV_DMA_MODE);
445}
446
447static void set_dmac(struct sv_state *s, unsigned int addr, unsigned int count)
448{
449#ifdef DMABYTEIO
450 unsigned io = s->iodmac, u;
451
452 count >>= 1;
453 count--;
454 for (u = 4; u > 0; u--, addr >>= 8, io++)
455 outb(addr & 0xff, io);
456 for (u = 3; u > 0; u--, count >>= 8, io++)
457 outb(count & 0xff, io);
458#else /* DMABYTEIO */
459 count >>= 1;
460 count--;
461 outl(addr, s->iodmac + SV_DMA_ADDR0);
462 outl(count, s->iodmac + SV_DMA_COUNT0);
463#endif /* DMABYTEIO */
464 outb(0x14, s->iodmac + SV_DMA_MODE);
465}
466
467static inline unsigned get_dmaa(struct sv_state *s)
468{
469#ifdef DMABYTEIO
470 unsigned io = s->iodmaa+6, v = 0, u;
471
472 for (u = 3; u > 0; u--, io--) {
473 v <<= 8;
474 v |= inb(io);
475 }
476 return v + 1;
477#else /* DMABYTEIO */
478 return (inl(s->iodmaa + SV_DMA_COUNT0) & 0xffffff) + 1;
479#endif /* DMABYTEIO */
480}
481
482static inline unsigned get_dmac(struct sv_state *s)
483{
484#ifdef DMABYTEIO
485 unsigned io = s->iodmac+6, v = 0, u;
486
487 for (u = 3; u > 0; u--, io--) {
488 v <<= 8;
489 v |= inb(io);
490 }
491 return (v + 1) << 1;
492#else /* DMABYTEIO */
493 return ((inl(s->iodmac + SV_DMA_COUNT0) & 0xffffff) + 1) << 1;
494#endif /* DMABYTEIO */
495}
496
497static void wrindir(struct sv_state *s, unsigned char idx, unsigned char data)
498{
499 outb(idx & 0x3f, s->ioenh + SV_CODEC_IADDR);
500 udelay(10);
501 outb(data, s->ioenh + SV_CODEC_IDATA);
502 udelay(10);
503}
504
505static unsigned char rdindir(struct sv_state *s, unsigned char idx)
506{
507 unsigned char v;
508
509 outb(idx & 0x3f, s->ioenh + SV_CODEC_IADDR);
510 udelay(10);
511 v = inb(s->ioenh + SV_CODEC_IDATA);
512 udelay(10);
513 return v;
514}
515
516static void set_fmt(struct sv_state *s, unsigned char mask, unsigned char data)
517{
518 unsigned long flags;
519
520 spin_lock_irqsave(&s->lock, flags);
521 outb(SV_CIDATAFMT | SV_CIADDR_MCE, s->ioenh + SV_CODEC_IADDR);
522 if (mask) {
523 s->fmt = inb(s->ioenh + SV_CODEC_IDATA);
524 udelay(10);
525 }
526 s->fmt = (s->fmt & mask) | data;
527 outb(s->fmt, s->ioenh + SV_CODEC_IDATA);
528 udelay(10);
529 outb(0, s->ioenh + SV_CODEC_IADDR);
530 spin_unlock_irqrestore(&s->lock, flags);
531 udelay(10);
532}
533
534static void frobindir(struct sv_state *s, unsigned char idx, unsigned char mask, unsigned char data)
535{
536 outb(idx & 0x3f, s->ioenh + SV_CODEC_IADDR);
537 udelay(10);
538 outb((inb(s->ioenh + SV_CODEC_IDATA) & mask) ^ data, s->ioenh + SV_CODEC_IDATA);
539 udelay(10);
540}
541
542#define REFFREQUENCY 24576000
543#define ADCMULT 512
544#define FULLRATE 48000
545
546static unsigned setpll(struct sv_state *s, unsigned char reg, unsigned rate)
547{
548 unsigned long flags;
549 unsigned char r, m=0, n=0;
550 unsigned xm, xn, xr, xd, metric = ~0U;
551 /* the warnings about m and n used uninitialized are bogus and may safely be ignored */
552
553 if (rate < 625000/ADCMULT)
554 rate = 625000/ADCMULT;
555 if (rate > 150000000/ADCMULT)
556 rate = 150000000/ADCMULT;
557 /* slight violation of specs, needed for continuous sampling rates */
558 for (r = 0; rate < 75000000/ADCMULT; r += 0x20, rate <<= 1);
559 for (xn = 3; xn < 35; xn++)
560 for (xm = 3; xm < 130; xm++) {
561 xr = REFFREQUENCY/ADCMULT * xm / xn;
562 xd = abs((signed)(xr - rate));
563 if (xd < metric) {
564 metric = xd;
565 m = xm - 2;
566 n = xn - 2;
567 }
568 }
569 reg &= 0x3f;
570 spin_lock_irqsave(&s->lock, flags);
571 outb(reg, s->ioenh + SV_CODEC_IADDR);
572 udelay(10);
573 outb(m, s->ioenh + SV_CODEC_IDATA);
574 udelay(10);
575 outb(reg+1, s->ioenh + SV_CODEC_IADDR);
576 udelay(10);
577 outb(r | n, s->ioenh + SV_CODEC_IDATA);
578 spin_unlock_irqrestore(&s->lock, flags);
579 udelay(10);
580 return (REFFREQUENCY/ADCMULT * (m + 2) / (n + 2)) >> ((r >> 5) & 7);
581}
582
583#if 0
584
585static unsigned getpll(struct sv_state *s, unsigned char reg)
586{
587 unsigned long flags;
588 unsigned char m, n;
589
590 reg &= 0x3f;
591 spin_lock_irqsave(&s->lock, flags);
592 outb(reg, s->ioenh + SV_CODEC_IADDR);
593 udelay(10);
594 m = inb(s->ioenh + SV_CODEC_IDATA);
595 udelay(10);
596 outb(reg+1, s->ioenh + SV_CODEC_IADDR);
597 udelay(10);
598 n = inb(s->ioenh + SV_CODEC_IDATA);
599 spin_unlock_irqrestore(&s->lock, flags);
600 udelay(10);
601 return (REFFREQUENCY/ADCMULT * (m + 2) / ((n & 0x1f) + 2)) >> ((n >> 5) & 7);
602}
603
604#endif
605
606static void set_dac_rate(struct sv_state *s, unsigned rate)
607{
608 unsigned div;
609 unsigned long flags;
610
611 if (rate > 48000)
612 rate = 48000;
613 if (rate < 4000)
614 rate = 4000;
615 div = (rate * 65536 + FULLRATE/2) / FULLRATE;
616 if (div > 65535)
617 div = 65535;
618 spin_lock_irqsave(&s->lock, flags);
619 wrindir(s, SV_CIPCMSR1, div >> 8);
620 wrindir(s, SV_CIPCMSR0, div);
621 spin_unlock_irqrestore(&s->lock, flags);
622 s->ratedac = (div * FULLRATE + 32768) / 65536;
623}
624
625static void set_adc_rate(struct sv_state *s, unsigned rate)
626{
627 unsigned long flags;
628 unsigned rate1, rate2, div;
629
630 if (rate > 48000)
631 rate = 48000;
632 if (rate < 4000)
633 rate = 4000;
634 rate1 = setpll(s, SV_CIADCPLLM, rate);
635 div = (48000 + rate/2) / rate;
636 if (div > 8)
637 div = 8;
638 rate2 = (48000 + div/2) / div;
639 spin_lock_irqsave(&s->lock, flags);
640 wrindir(s, SV_CIADCALTSR, (div-1) << 4);
641 if (abs((signed)(rate-rate2)) <= abs((signed)(rate-rate1))) {
642 wrindir(s, SV_CIADCCLKSOURCE, 0x10);
643 s->rateadc = rate2;
644 } else {
645 wrindir(s, SV_CIADCCLKSOURCE, 0x00);
646 s->rateadc = rate1;
647 }
648 spin_unlock_irqrestore(&s->lock, flags);
649}
650
651/* --------------------------------------------------------------------- */
652
653static inline void stop_adc(struct sv_state *s)
654{
655 unsigned long flags;
656
657 spin_lock_irqsave(&s->lock, flags);
658 s->enable &= ~SV_CENABLE_RE;
659 wrindir(s, SV_CIENABLE, s->enable);
660 spin_unlock_irqrestore(&s->lock, flags);
661}
662
663static inline void stop_dac(struct sv_state *s)
664{
665 unsigned long flags;
666
667 spin_lock_irqsave(&s->lock, flags);
668 s->enable &= ~(SV_CENABLE_PPE | SV_CENABLE_PE);
669 wrindir(s, SV_CIENABLE, s->enable);
670 spin_unlock_irqrestore(&s->lock, flags);
671}
672
673static void start_dac(struct sv_state *s)
674{
675 unsigned long flags;
676
677 spin_lock_irqsave(&s->lock, flags);
678 if ((s->dma_dac.mapped || s->dma_dac.count > 0) && s->dma_dac.ready) {
679 s->enable = (s->enable & ~SV_CENABLE_PPE) | SV_CENABLE_PE;
680 wrindir(s, SV_CIENABLE, s->enable);
681 }
682 spin_unlock_irqrestore(&s->lock, flags);
683}
684
685static void start_adc(struct sv_state *s)
686{
687 unsigned long flags;
688
689 spin_lock_irqsave(&s->lock, flags);
690 if ((s->dma_adc.mapped || s->dma_adc.count < (signed)(s->dma_adc.dmasize - 2*s->dma_adc.fragsize))
691 && s->dma_adc.ready) {
692 s->enable |= SV_CENABLE_RE;
693 wrindir(s, SV_CIENABLE, s->enable);
694 }
695 spin_unlock_irqrestore(&s->lock, flags);
696}
697
698/* --------------------------------------------------------------------- */
699
700#define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
701#define DMABUF_MINORDER 1
702
703static void dealloc_dmabuf(struct sv_state *s, struct dmabuf *db)
704{
705 struct page *page, *pend;
706
707 if (db->rawbuf) {
708 /* undo marking the pages as reserved */
709 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
710 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
711 ClearPageReserved(page);
712 pci_free_consistent(s->dev, PAGE_SIZE << db->buforder, db->rawbuf, db->dmaaddr);
713 }
714 db->rawbuf = NULL;
715 db->mapped = db->ready = 0;
716}
717
718
719/* DMAA is used for playback, DMAC is used for recording */
720
721static int prog_dmabuf(struct sv_state *s, unsigned rec)
722{
723 struct dmabuf *db = rec ? &s->dma_adc : &s->dma_dac;
724 unsigned rate = rec ? s->rateadc : s->ratedac;
725 int order;
726 unsigned bytepersec;
727 unsigned bufs;
728 struct page *page, *pend;
729 unsigned char fmt;
730 unsigned long flags;
731
732 spin_lock_irqsave(&s->lock, flags);
733 fmt = s->fmt;
734 if (rec) {
735 s->enable &= ~SV_CENABLE_RE;
736 fmt >>= SV_CFMT_CSHIFT;
737 } else {
738 s->enable &= ~SV_CENABLE_PE;
739 fmt >>= SV_CFMT_ASHIFT;
740 }
741 wrindir(s, SV_CIENABLE, s->enable);
742 spin_unlock_irqrestore(&s->lock, flags);
743 fmt &= SV_CFMT_MASK;
744 db->hwptr = db->swptr = db->total_bytes = db->count = db->error = db->endcleared = 0;
745 if (!db->rawbuf) {
746 db->ready = db->mapped = 0;
747 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--)
748 if ((db->rawbuf = pci_alloc_consistent(s->dev, PAGE_SIZE << order, &db->dmaaddr)))
749 break;
750 if (!db->rawbuf)
751 return -ENOMEM;
752 db->buforder = order;
753 if ((virt_to_bus(db->rawbuf) ^ (virt_to_bus(db->rawbuf) + (PAGE_SIZE << db->buforder) - 1)) & ~0xffff)
754 printk(KERN_DEBUG "sv: DMA buffer crosses 64k boundary: busaddr 0x%lx size %ld\n",
755 virt_to_bus(db->rawbuf), PAGE_SIZE << db->buforder);
756 if ((virt_to_bus(db->rawbuf) + (PAGE_SIZE << db->buforder) - 1) & ~0xffffff)
757 printk(KERN_DEBUG "sv: DMA buffer beyond 16MB: busaddr 0x%lx size %ld\n",
758 virt_to_bus(db->rawbuf), PAGE_SIZE << db->buforder);
759 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
760 pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
761 for (page = virt_to_page(db->rawbuf); page <= pend; page++)
762 SetPageReserved(page);
763 }
764 bytepersec = rate << sample_shift[fmt];
765 bufs = PAGE_SIZE << db->buforder;
766 if (db->ossfragshift) {
767 if ((1000 << db->ossfragshift) < bytepersec)
768 db->fragshift = ld2(bytepersec/1000);
769 else
770 db->fragshift = db->ossfragshift;
771 } else {
772 db->fragshift = ld2(bytepersec/100/(db->subdivision ? db->subdivision : 1));
773 if (db->fragshift < 3)
774 db->fragshift = 3;
775 }
776 db->numfrag = bufs >> db->fragshift;
777 while (db->numfrag < 4 && db->fragshift > 3) {
778 db->fragshift--;
779 db->numfrag = bufs >> db->fragshift;
780 }
781 db->fragsize = 1 << db->fragshift;
782 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
783 db->numfrag = db->ossmaxfrags;
784 db->fragsamples = db->fragsize >> sample_shift[fmt];
785 db->dmasize = db->numfrag << db->fragshift;
786 memset(db->rawbuf, (fmt & SV_CFMT_16BIT) ? 0 : 0x80, db->dmasize);
787 spin_lock_irqsave(&s->lock, flags);
788 if (rec) {
789 set_dmac(s, db->dmaaddr, db->numfrag << db->fragshift);
790 /* program enhanced mode registers */
791 wrindir(s, SV_CIDMACBASECOUNT1, (db->fragsamples-1) >> 8);
792 wrindir(s, SV_CIDMACBASECOUNT0, db->fragsamples-1);
793 } else {
794 set_dmaa(s, db->dmaaddr, db->numfrag << db->fragshift);
795 /* program enhanced mode registers */
796 wrindir(s, SV_CIDMAABASECOUNT1, (db->fragsamples-1) >> 8);
797 wrindir(s, SV_CIDMAABASECOUNT0, db->fragsamples-1);
798 }
799 spin_unlock_irqrestore(&s->lock, flags);
800 db->enabled = 1;
801 db->ready = 1;
802 return 0;
803}
804
805static inline void clear_advance(struct sv_state *s)
806{
807 unsigned char c = (s->fmt & (SV_CFMT_16BIT << SV_CFMT_ASHIFT)) ? 0 : 0x80;
808 unsigned char *buf = s->dma_dac.rawbuf;
809 unsigned bsize = s->dma_dac.dmasize;
810 unsigned bptr = s->dma_dac.swptr;
811 unsigned len = s->dma_dac.fragsize;
812
813 if (bptr + len > bsize) {
814 unsigned x = bsize - bptr;
815 memset(buf + bptr, c, x);
816 bptr = 0;
817 len -= x;
818 }
819 memset(buf + bptr, c, len);
820}
821
822/* call with spinlock held! */
823static void sv_update_ptr(struct sv_state *s)
824{
825 unsigned hwptr;
826 int diff;
827
828 /* update ADC pointer */
829 if (s->dma_adc.ready) {
830 hwptr = (s->dma_adc.dmasize - get_dmac(s)) % s->dma_adc.dmasize;
831 diff = (s->dma_adc.dmasize + hwptr - s->dma_adc.hwptr) % s->dma_adc.dmasize;
832 s->dma_adc.hwptr = hwptr;
833 s->dma_adc.total_bytes += diff;
834 s->dma_adc.count += diff;
835 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
836 wake_up(&s->dma_adc.wait);
837 if (!s->dma_adc.mapped) {
838 if (s->dma_adc.count > (signed)(s->dma_adc.dmasize - ((3 * s->dma_adc.fragsize) >> 1))) {
839 s->enable &= ~SV_CENABLE_RE;
840 wrindir(s, SV_CIENABLE, s->enable);
841 s->dma_adc.error++;
842 }
843 }
844 }
845 /* update DAC pointer */
846 if (s->dma_dac.ready) {
847 hwptr = (s->dma_dac.dmasize - get_dmaa(s)) % s->dma_dac.dmasize;
848 diff = (s->dma_dac.dmasize + hwptr - s->dma_dac.hwptr) % s->dma_dac.dmasize;
849 s->dma_dac.hwptr = hwptr;
850 s->dma_dac.total_bytes += diff;
851 if (s->dma_dac.mapped) {
852 s->dma_dac.count += diff;
853 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
854 wake_up(&s->dma_dac.wait);
855 } else {
856 s->dma_dac.count -= diff;
857 if (s->dma_dac.count <= 0) {
858 s->enable &= ~SV_CENABLE_PE;
859 wrindir(s, SV_CIENABLE, s->enable);
860 s->dma_dac.error++;
861 } else if (s->dma_dac.count <= (signed)s->dma_dac.fragsize && !s->dma_dac.endcleared) {
862 clear_advance(s);
863 s->dma_dac.endcleared = 1;
864 }
865 if (s->dma_dac.count + (signed)s->dma_dac.fragsize <= (signed)s->dma_dac.dmasize)
866 wake_up(&s->dma_dac.wait);
867 }
868 }
869}
870
871/* hold spinlock for the following! */
872static void sv_handle_midi(struct sv_state *s)
873{
874 unsigned char ch;
875 int wake;
876
877 wake = 0;
878 while (!(inb(s->iomidi+1) & 0x80)) {
879 ch = inb(s->iomidi);
880 if (s->midi.icnt < MIDIINBUF) {
881 s->midi.ibuf[s->midi.iwr] = ch;
882 s->midi.iwr = (s->midi.iwr + 1) % MIDIINBUF;
883 s->midi.icnt++;
884 }
885 wake = 1;
886 }
887 if (wake)
888 wake_up(&s->midi.iwait);
889 wake = 0;
890 while (!(inb(s->iomidi+1) & 0x40) && s->midi.ocnt > 0) {
891 outb(s->midi.obuf[s->midi.ord], s->iomidi);
892 s->midi.ord = (s->midi.ord + 1) % MIDIOUTBUF;
893 s->midi.ocnt--;
894 if (s->midi.ocnt < MIDIOUTBUF-16)
895 wake = 1;
896 }
897 if (wake)
898 wake_up(&s->midi.owait);
899}
900
901static irqreturn_t sv_interrupt(int irq, void *dev_id, struct pt_regs *regs)
902{
903 struct sv_state *s = (struct sv_state *)dev_id;
904 unsigned int intsrc;
905
906 /* fastpath out, to ease interrupt sharing */
907 intsrc = inb(s->ioenh + SV_CODEC_STATUS);
908 if (!(intsrc & (SV_CSTAT_DMAA | SV_CSTAT_DMAC | SV_CSTAT_MIDI)))
909 return IRQ_NONE;
910 spin_lock(&s->lock);
911 sv_update_ptr(s);
912 sv_handle_midi(s);
913 spin_unlock(&s->lock);
914 return IRQ_HANDLED;
915}
916
917static void sv_midi_timer(unsigned long data)
918{
919 struct sv_state *s = (struct sv_state *)data;
920 unsigned long flags;
921
922 spin_lock_irqsave(&s->lock, flags);
923 sv_handle_midi(s);
924 spin_unlock_irqrestore(&s->lock, flags);
925 s->midi.timer.expires = jiffies+1;
926 add_timer(&s->midi.timer);
927}
928
929/* --------------------------------------------------------------------- */
930
931static const char invalid_magic[] = KERN_CRIT "sv: invalid magic value\n";
932
933#define VALIDATE_STATE(s) \
934({ \
935 if (!(s) || (s)->magic != SV_MAGIC) { \
936 printk(invalid_magic); \
937 return -ENXIO; \
938 } \
939})
940
941/* --------------------------------------------------------------------- */
942
943#define MT_4 1
944#define MT_5MUTE 2
945#define MT_4MUTEMONO 3
946#define MT_6MUTE 4
947
948static const struct {
949 unsigned left:5;
950 unsigned right:5;
951 unsigned type:3;
952 unsigned rec:3;
953} mixtable[SOUND_MIXER_NRDEVICES] = {
954 [SOUND_MIXER_RECLEV] = { SV_CIMIX_ADCINL, SV_CIMIX_ADCINR, MT_4, 0 },
955 [SOUND_MIXER_LINE1] = { SV_CIMIX_AUX1INL, SV_CIMIX_AUX1INR, MT_5MUTE, 5 },
956 [SOUND_MIXER_CD] = { SV_CIMIX_CDINL, SV_CIMIX_CDINR, MT_5MUTE, 1 },
957 [SOUND_MIXER_LINE] = { SV_CIMIX_LINEINL, SV_CIMIX_LINEINR, MT_5MUTE, 4 },
958 [SOUND_MIXER_MIC] = { SV_CIMIX_MICIN, SV_CIMIX_ADCINL, MT_4MUTEMONO, 6 },
959 [SOUND_MIXER_SYNTH] = { SV_CIMIX_SYNTHINL, SV_CIMIX_SYNTHINR, MT_5MUTE, 2 },
960 [SOUND_MIXER_LINE2] = { SV_CIMIX_AUX2INL, SV_CIMIX_AUX2INR, MT_5MUTE, 3 },
961 [SOUND_MIXER_VOLUME] = { SV_CIMIX_ANALOGINL, SV_CIMIX_ANALOGINR, MT_5MUTE, 7 },
962 [SOUND_MIXER_PCM] = { SV_CIMIX_PCMINL, SV_CIMIX_PCMINR, MT_6MUTE, 0 }
963};
964
965#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
966
967static int return_mixval(struct sv_state *s, unsigned i, int *arg)
968{
969 unsigned long flags;
970 unsigned char l, r, rl, rr;
971
972 spin_lock_irqsave(&s->lock, flags);
973 l = rdindir(s, mixtable[i].left);
974 r = rdindir(s, mixtable[i].right);
975 spin_unlock_irqrestore(&s->lock, flags);
976 switch (mixtable[i].type) {
977 case MT_4:
978 r &= 0xf;
979 l &= 0xf;
980 rl = 10 + 6 * (l & 15);
981 rr = 10 + 6 * (r & 15);
982 break;
983
984 case MT_4MUTEMONO:
985 rl = 55 - 3 * (l & 15);
986 if (r & 0x10)
987 rl += 45;
988 rr = rl;
989 r = l;
990 break;
991
992 case MT_5MUTE:
993 default:
994 rl = 100 - 3 * (l & 31);
995 rr = 100 - 3 * (r & 31);
996 break;
997
998 case MT_6MUTE:
999 rl = 100 - 3 * (l & 63) / 2;
1000 rr = 100 - 3 * (r & 63) / 2;
1001 break;
1002 }
1003 if (l & 0x80)
1004 rl = 0;
1005 if (r & 0x80)
1006 rr = 0;
1007 return put_user((rr << 8) | rl, arg);
1008}
1009
1010#else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1011
1012static const unsigned char volidx[SOUND_MIXER_NRDEVICES] =
1013{
1014 [SOUND_MIXER_RECLEV] = 1,
1015 [SOUND_MIXER_LINE1] = 2,
1016 [SOUND_MIXER_CD] = 3,
1017 [SOUND_MIXER_LINE] = 4,
1018 [SOUND_MIXER_MIC] = 5,
1019 [SOUND_MIXER_SYNTH] = 6,
1020 [SOUND_MIXER_LINE2] = 7,
1021 [SOUND_MIXER_VOLUME] = 8,
1022 [SOUND_MIXER_PCM] = 9
1023};
1024
1025#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1026
1027static unsigned mixer_recmask(struct sv_state *s)
1028{
1029 unsigned long flags;
1030 int i, j;
1031
1032 spin_lock_irqsave(&s->lock, flags);
1033 j = rdindir(s, SV_CIMIX_ADCINL) >> 5;
1034 spin_unlock_irqrestore(&s->lock, flags);
1035 j &= 7;
1036 for (i = 0; i < SOUND_MIXER_NRDEVICES && mixtable[i].rec != j; i++);
1037 return 1 << i;
1038}
1039
1040static int mixer_ioctl(struct sv_state *s, unsigned int cmd, unsigned long arg)
1041{
1042 unsigned long flags;
1043 int i, val;
1044 unsigned char l, r, rl, rr;
1045 int __user *p = (int __user *)arg;
1046
1047 VALIDATE_STATE(s);
1048 if (cmd == SOUND_MIXER_INFO) {
1049 mixer_info info;
1050 memset(&info, 0, sizeof(info));
1051 strlcpy(info.id, "SonicVibes", sizeof(info.id));
1052 strlcpy(info.name, "S3 SonicVibes", sizeof(info.name));
1053 info.modify_counter = s->mix.modcnt;
1054 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1055 return -EFAULT;
1056 return 0;
1057 }
1058 if (cmd == SOUND_OLD_MIXER_INFO) {
1059 _old_mixer_info info;
1060 memset(&info, 0, sizeof(info));
1061 strlcpy(info.id, "SonicVibes", sizeof(info.id));
1062 strlcpy(info.name, "S3 SonicVibes", sizeof(info.name));
1063 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
1064 return -EFAULT;
1065 return 0;
1066 }
1067 if (cmd == OSS_GETVERSION)
1068 return put_user(SOUND_VERSION, p);
1069 if (cmd == SOUND_MIXER_PRIVATE1) { /* SRS settings */
1070 if (get_user(val, p))
1071 return -EFAULT;
1072 spin_lock_irqsave(&s->lock, flags);
1073 if (val & 1) {
1074 if (val & 2) {
1075 l = 4 - ((val >> 2) & 7);
1076 if (l & ~3)
1077 l = 4;
1078 r = 4 - ((val >> 5) & 7);
1079 if (r & ~3)
1080 r = 4;
1081 wrindir(s, SV_CISRSSPACE, l);
1082 wrindir(s, SV_CISRSCENTER, r);
1083 } else
1084 wrindir(s, SV_CISRSSPACE, 0x80);
1085 }
1086 l = rdindir(s, SV_CISRSSPACE);
1087 r = rdindir(s, SV_CISRSCENTER);
1088 spin_unlock_irqrestore(&s->lock, flags);
1089 if (l & 0x80)
1090 return put_user(0, p);
1091 return put_user(((4 - (l & 7)) << 2) | ((4 - (r & 7)) << 5) | 2, p);
1092 }
1093 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
1094 return -EINVAL;
1095 if (_SIOC_DIR(cmd) == _SIOC_READ) {
1096 switch (_IOC_NR(cmd)) {
1097 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
1098 return put_user(mixer_recmask(s), p);
1099
1100 case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
1101 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1102 if (mixtable[i].type)
1103 val |= 1 << i;
1104 return put_user(val, p);
1105
1106 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
1107 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1108 if (mixtable[i].rec)
1109 val |= 1 << i;
1110 return put_user(val, p);
1111
1112 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
1113 for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1114 if (mixtable[i].type && mixtable[i].type != MT_4MUTEMONO)
1115 val |= 1 << i;
1116 return put_user(val, p);
1117
1118 case SOUND_MIXER_CAPS:
1119 return put_user(SOUND_CAP_EXCL_INPUT, p);
1120
1121 default:
1122 i = _IOC_NR(cmd);
1123 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
1124 return -EINVAL;
1125#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1126 return return_mixval(s, i, p);
1127#else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1128 if (!volidx[i])
1129 return -EINVAL;
1130 return put_user(s->mix.vol[volidx[i]-1], p);
1131#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1132 }
1133 }
1134 if (_SIOC_DIR(cmd) != (_SIOC_READ|_SIOC_WRITE))
1135 return -EINVAL;
1136 s->mix.modcnt++;
1137 switch (_IOC_NR(cmd)) {
1138 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
1139 if (get_user(val, p))
1140 return -EFAULT;
1141 i = hweight32(val);
1142 if (i == 0)
1143 return 0; /*val = mixer_recmask(s);*/
1144 else if (i > 1)
1145 val &= ~mixer_recmask(s);
1146 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1147 if (!(val & (1 << i)))
1148 continue;
1149 if (mixtable[i].rec)
1150 break;
1151 }
1152 if (!mixtable[i].rec)
1153 return 0;
1154 spin_lock_irqsave(&s->lock, flags);
1155 frobindir(s, SV_CIMIX_ADCINL, 0x1f, mixtable[i].rec << 5);
1156 frobindir(s, SV_CIMIX_ADCINR, 0x1f, mixtable[i].rec << 5);
1157 spin_unlock_irqrestore(&s->lock, flags);
1158 return 0;
1159
1160 default:
1161 i = _IOC_NR(cmd);
1162 if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
1163 return -EINVAL;
1164 if (get_user(val, p))
1165 return -EFAULT;
1166 l = val & 0xff;
1167 r = (val >> 8) & 0xff;
1168 if (mixtable[i].type == MT_4MUTEMONO)
1169 l = (r + l) / 2;
1170 if (l > 100)
1171 l = 100;
1172 if (r > 100)
1173 r = 100;
1174 spin_lock_irqsave(&s->lock, flags);
1175 switch (mixtable[i].type) {
1176 case MT_4:
1177 if (l >= 10)
1178 l -= 10;
1179 if (r >= 10)
1180 r -= 10;
1181 frobindir(s, mixtable[i].left, 0xf0, l / 6);
1182 frobindir(s, mixtable[i].right, 0xf0, l / 6);
1183 break;
1184
1185 case MT_4MUTEMONO:
1186 rr = 0;
1187 if (l < 10)
1188 rl = 0x80;
1189 else {
1190 if (l >= 55) {
1191 rr = 0x10;
1192 l -= 45;
1193 }
1194 rl = (55 - l) / 3;
1195 }
1196 wrindir(s, mixtable[i].left, rl);
1197 frobindir(s, mixtable[i].right, ~0x10, rr);
1198 break;
1199
1200 case MT_5MUTE:
1201 if (l < 7)
1202 rl = 0x80;
1203 else
1204 rl = (100 - l) / 3;
1205 if (r < 7)
1206 rr = 0x80;
1207 else
1208 rr = (100 - r) / 3;
1209 wrindir(s, mixtable[i].left, rl);
1210 wrindir(s, mixtable[i].right, rr);
1211 break;
1212
1213 case MT_6MUTE:
1214 if (l < 6)
1215 rl = 0x80;
1216 else
1217 rl = (100 - l) * 2 / 3;
1218 if (r < 6)
1219 rr = 0x80;
1220 else
1221 rr = (100 - r) * 2 / 3;
1222 wrindir(s, mixtable[i].left, rl);
1223 wrindir(s, mixtable[i].right, rr);
1224 break;
1225 }
1226 spin_unlock_irqrestore(&s->lock, flags);
1227#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1228 return return_mixval(s, i, p);
1229#else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1230 if (!volidx[i])
1231 return -EINVAL;
1232 s->mix.vol[volidx[i]-1] = val;
1233 return put_user(s->mix.vol[volidx[i]-1], p);
1234#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
1235 }
1236}
1237
1238/* --------------------------------------------------------------------- */
1239
1240static int sv_open_mixdev(struct inode *inode, struct file *file)
1241{
1242 int minor = iminor(inode);
1243 struct list_head *list;
1244 struct sv_state *s;
1245
1246 for (list = devs.next; ; list = list->next) {
1247 if (list == &devs)
1248 return -ENODEV;
1249 s = list_entry(list, struct sv_state, devs);
1250 if (s->dev_mixer == minor)
1251 break;
1252 }
1253 VALIDATE_STATE(s);
1254 file->private_data = s;
1255 return nonseekable_open(inode, file);
1256}
1257
1258static int sv_release_mixdev(struct inode *inode, struct file *file)
1259{
1260 struct sv_state *s = (struct sv_state *)file->private_data;
1261
1262 VALIDATE_STATE(s);
1263 return 0;
1264}
1265
1266static int sv_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1267{
1268 return mixer_ioctl((struct sv_state *)file->private_data, cmd, arg);
1269}
1270
1271static /*const*/ struct file_operations sv_mixer_fops = {
1272 .owner = THIS_MODULE,
1273 .llseek = no_llseek,
1274 .ioctl = sv_ioctl_mixdev,
1275 .open = sv_open_mixdev,
1276 .release = sv_release_mixdev,
1277};
1278
1279/* --------------------------------------------------------------------- */
1280
1281static int drain_dac(struct sv_state *s, int nonblock)
1282{
1283 DECLARE_WAITQUEUE(wait, current);
1284 unsigned long flags;
1285 int count, tmo;
1286
1287 if (s->dma_dac.mapped || !s->dma_dac.ready)
1288 return 0;
1289 add_wait_queue(&s->dma_dac.wait, &wait);
1290 for (;;) {
1291 __set_current_state(TASK_INTERRUPTIBLE);
1292 spin_lock_irqsave(&s->lock, flags);
1293 count = s->dma_dac.count;
1294 spin_unlock_irqrestore(&s->lock, flags);
1295 if (count <= 0)
1296 break;
1297 if (signal_pending(current))
1298 break;
1299 if (nonblock) {
1300 remove_wait_queue(&s->dma_dac.wait, &wait);
1301 set_current_state(TASK_RUNNING);
1302 return -EBUSY;
1303 }
1304 tmo = 3 * HZ * (count + s->dma_dac.fragsize) / 2 / s->ratedac;
1305 tmo >>= sample_shift[(s->fmt >> SV_CFMT_ASHIFT) & SV_CFMT_MASK];
1306 if (!schedule_timeout(tmo + 1))
1307 printk(KERN_DEBUG "sv: dma timed out??\n");
1308 }
1309 remove_wait_queue(&s->dma_dac.wait, &wait);
1310 set_current_state(TASK_RUNNING);
1311 if (signal_pending(current))
1312 return -ERESTARTSYS;
1313 return 0;
1314}
1315
1316/* --------------------------------------------------------------------- */
1317
1318static ssize_t sv_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1319{
1320 struct sv_state *s = (struct sv_state *)file->private_data;
1321 DECLARE_WAITQUEUE(wait, current);
1322 ssize_t ret;
1323 unsigned long flags;
1324 unsigned swptr;
1325 int cnt;
1326
1327 VALIDATE_STATE(s);
1328 if (s->dma_adc.mapped)
1329 return -ENXIO;
1330 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
1331 return ret;
1332 if (!access_ok(VERIFY_WRITE, buffer, count))
1333 return -EFAULT;
1334 ret = 0;
1335#if 0
1336 spin_lock_irqsave(&s->lock, flags);
1337 sv_update_ptr(s);
1338 spin_unlock_irqrestore(&s->lock, flags);
1339#endif
1340 add_wait_queue(&s->dma_adc.wait, &wait);
1341 while (count > 0) {
1342 spin_lock_irqsave(&s->lock, flags);
1343 swptr = s->dma_adc.swptr;
1344 cnt = s->dma_adc.dmasize-swptr;
1345 if (s->dma_adc.count < cnt)
1346 cnt = s->dma_adc.count;
1347 if (cnt <= 0)
1348 __set_current_state(TASK_INTERRUPTIBLE);
1349 spin_unlock_irqrestore(&s->lock, flags);
1350 if (cnt > count)
1351 cnt = count;
1352 if (cnt <= 0) {
1353 if (s->dma_adc.enabled)
1354 start_adc(s);
1355 if (file->f_flags & O_NONBLOCK) {
1356 if (!ret)
1357 ret = -EAGAIN;
1358 break;
1359 }
1360 if (!schedule_timeout(HZ)) {
1361 printk(KERN_DEBUG "sv: read: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1362 s->dma_adc.dmasize, s->dma_adc.fragsize, s->dma_adc.count,
1363 s->dma_adc.hwptr, s->dma_adc.swptr);
1364 stop_adc(s);
1365 spin_lock_irqsave(&s->lock, flags);
1366 set_dmac(s, virt_to_bus(s->dma_adc.rawbuf), s->dma_adc.numfrag << s->dma_adc.fragshift);
1367 /* program enhanced mode registers */
1368 wrindir(s, SV_CIDMACBASECOUNT1, (s->dma_adc.fragsamples-1) >> 8);
1369 wrindir(s, SV_CIDMACBASECOUNT0, s->dma_adc.fragsamples-1);
1370 s->dma_adc.count = s->dma_adc.hwptr = s->dma_adc.swptr = 0;
1371 spin_unlock_irqrestore(&s->lock, flags);
1372 }
1373 if (signal_pending(current)) {
1374 if (!ret)
1375 ret = -ERESTARTSYS;
1376 break;
1377 }
1378 continue;
1379 }
1380 if (copy_to_user(buffer, s->dma_adc.rawbuf + swptr, cnt)) {
1381 if (!ret)
1382 ret = -EFAULT;
1383 break;
1384 }
1385 swptr = (swptr + cnt) % s->dma_adc.dmasize;
1386 spin_lock_irqsave(&s->lock, flags);
1387 s->dma_adc.swptr = swptr;
1388 s->dma_adc.count -= cnt;
1389 spin_unlock_irqrestore(&s->lock, flags);
1390 count -= cnt;
1391 buffer += cnt;
1392 ret += cnt;
1393 if (s->dma_adc.enabled)
1394 start_adc(s);
1395 }
1396 remove_wait_queue(&s->dma_adc.wait, &wait);
1397 set_current_state(TASK_RUNNING);
1398 return ret;
1399}
1400
1401static ssize_t sv_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1402{
1403 struct sv_state *s = (struct sv_state *)file->private_data;
1404 DECLARE_WAITQUEUE(wait, current);
1405 ssize_t ret;
1406 unsigned long flags;
1407 unsigned swptr;
1408 int cnt;
1409
1410 VALIDATE_STATE(s);
1411 if (s->dma_dac.mapped)
1412 return -ENXIO;
1413 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
1414 return ret;
1415 if (!access_ok(VERIFY_READ, buffer, count))
1416 return -EFAULT;
1417 ret = 0;
1418#if 0
1419 spin_lock_irqsave(&s->lock, flags);
1420 sv_update_ptr(s);
1421 spin_unlock_irqrestore(&s->lock, flags);
1422#endif
1423 add_wait_queue(&s->dma_dac.wait, &wait);
1424 while (count > 0) {
1425 spin_lock_irqsave(&s->lock, flags);
1426 if (s->dma_dac.count < 0) {
1427 s->dma_dac.count = 0;
1428 s->dma_dac.swptr = s->dma_dac.hwptr;
1429 }
1430 swptr = s->dma_dac.swptr;
1431 cnt = s->dma_dac.dmasize-swptr;
1432 if (s->dma_dac.count + cnt > s->dma_dac.dmasize)
1433 cnt = s->dma_dac.dmasize - s->dma_dac.count;
1434 if (cnt <= 0)
1435 __set_current_state(TASK_INTERRUPTIBLE);
1436 spin_unlock_irqrestore(&s->lock, flags);
1437 if (cnt > count)
1438 cnt = count;
1439 if (cnt <= 0) {
1440 if (s->dma_dac.enabled)
1441 start_dac(s);
1442 if (file->f_flags & O_NONBLOCK) {
1443 if (!ret)
1444 ret = -EAGAIN;
1445 break;
1446 }
1447 if (!schedule_timeout(HZ)) {
1448 printk(KERN_DEBUG "sv: write: chip lockup? dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1449 s->dma_dac.dmasize, s->dma_dac.fragsize, s->dma_dac.count,
1450 s->dma_dac.hwptr, s->dma_dac.swptr);
1451 stop_dac(s);
1452 spin_lock_irqsave(&s->lock, flags);
1453 set_dmaa(s, virt_to_bus(s->dma_dac.rawbuf), s->dma_dac.numfrag << s->dma_dac.fragshift);
1454 /* program enhanced mode registers */
1455 wrindir(s, SV_CIDMAABASECOUNT1, (s->dma_dac.fragsamples-1) >> 8);
1456 wrindir(s, SV_CIDMAABASECOUNT0, s->dma_dac.fragsamples-1);
1457 s->dma_dac.count = s->dma_dac.hwptr = s->dma_dac.swptr = 0;
1458 spin_unlock_irqrestore(&s->lock, flags);
1459 }
1460 if (signal_pending(current)) {
1461 if (!ret)
1462 ret = -ERESTARTSYS;
1463 break;
1464 }
1465 continue;
1466 }
1467 if (copy_from_user(s->dma_dac.rawbuf + swptr, buffer, cnt)) {
1468 if (!ret)
1469 ret = -EFAULT;
1470 break;
1471 }
1472 swptr = (swptr + cnt) % s->dma_dac.dmasize;
1473 spin_lock_irqsave(&s->lock, flags);
1474 s->dma_dac.swptr = swptr;
1475 s->dma_dac.count += cnt;
1476 s->dma_dac.endcleared = 0;
1477 spin_unlock_irqrestore(&s->lock, flags);
1478 count -= cnt;
1479 buffer += cnt;
1480 ret += cnt;
1481 if (s->dma_dac.enabled)
1482 start_dac(s);
1483 }
1484 remove_wait_queue(&s->dma_dac.wait, &wait);
1485 set_current_state(TASK_RUNNING);
1486 return ret;
1487}
1488
1489/* No kernel lock - we have our own spinlock */
1490static unsigned int sv_poll(struct file *file, struct poll_table_struct *wait)
1491{
1492 struct sv_state *s = (struct sv_state *)file->private_data;
1493 unsigned long flags;
1494 unsigned int mask = 0;
1495
1496 VALIDATE_STATE(s);
1497 if (file->f_mode & FMODE_WRITE) {
1498 if (!s->dma_dac.ready && prog_dmabuf(s, 1))
1499 return 0;
1500 poll_wait(file, &s->dma_dac.wait, wait);
1501 }
1502 if (file->f_mode & FMODE_READ) {
1503 if (!s->dma_adc.ready && prog_dmabuf(s, 0))
1504 return 0;
1505 poll_wait(file, &s->dma_adc.wait, wait);
1506 }
1507 spin_lock_irqsave(&s->lock, flags);
1508 sv_update_ptr(s);
1509 if (file->f_mode & FMODE_READ) {
1510 if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
1511 mask |= POLLIN | POLLRDNORM;
1512 }
1513 if (file->f_mode & FMODE_WRITE) {
1514 if (s->dma_dac.mapped) {
1515 if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
1516 mask |= POLLOUT | POLLWRNORM;
1517 } else {
1518 if ((signed)s->dma_dac.dmasize >= s->dma_dac.count + (signed)s->dma_dac.fragsize)
1519 mask |= POLLOUT | POLLWRNORM;
1520 }
1521 }
1522 spin_unlock_irqrestore(&s->lock, flags);
1523 return mask;
1524}
1525
1526static int sv_mmap(struct file *file, struct vm_area_struct *vma)
1527{
1528 struct sv_state *s = (struct sv_state *)file->private_data;
1529 struct dmabuf *db;
1530 int ret = -EINVAL;
1531 unsigned long size;
1532
1533 VALIDATE_STATE(s);
1534 lock_kernel();
1535 if (vma->vm_flags & VM_WRITE) {
1536 if ((ret = prog_dmabuf(s, 1)) != 0)
1537 goto out;
1538 db = &s->dma_dac;
1539 } else if (vma->vm_flags & VM_READ) {
1540 if ((ret = prog_dmabuf(s, 0)) != 0)
1541 goto out;
1542 db = &s->dma_adc;
1543 } else
1544 goto out;
1545 ret = -EINVAL;
1546 if (vma->vm_pgoff != 0)
1547 goto out;
1548 size = vma->vm_end - vma->vm_start;
1549 if (size > (PAGE_SIZE << db->buforder))
1550 goto out;
1551 ret = -EAGAIN;
1552 if (remap_pfn_range(vma, vma->vm_start,
1553 virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
1554 size, vma->vm_page_prot))
1555 goto out;
1556 db->mapped = 1;
1557 ret = 0;
1558out:
1559 unlock_kernel();
1560 return ret;
1561}
1562
1563static int sv_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1564{
1565 struct sv_state *s = (struct sv_state *)file->private_data;
1566 unsigned long flags;
1567 audio_buf_info abinfo;
1568 count_info cinfo;
1569 int count;
1570 int val, mapped, ret;
1571 unsigned char fmtm, fmtd;
1572 void __user *argp = (void __user *)arg;
1573 int __user *p = argp;
1574
1575 VALIDATE_STATE(s);
1576 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1577 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1578 switch (cmd) {
1579 case OSS_GETVERSION:
1580 return put_user(SOUND_VERSION, p);
1581
1582 case SNDCTL_DSP_SYNC:
1583 if (file->f_mode & FMODE_WRITE)
1584 return drain_dac(s, 0/*file->f_flags & O_NONBLOCK*/);
1585 return 0;
1586
1587 case SNDCTL_DSP_SETDUPLEX:
1588 return 0;
1589
1590 case SNDCTL_DSP_GETCAPS:
1591 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP, p);
1592
1593 case SNDCTL_DSP_RESET:
1594 if (file->f_mode & FMODE_WRITE) {
1595 stop_dac(s);
1596 synchronize_irq(s->irq);
1597 s->dma_dac.swptr = s->dma_dac.hwptr = s->dma_dac.count = s->dma_dac.total_bytes = 0;
1598 }
1599 if (file->f_mode & FMODE_READ) {
1600 stop_adc(s);
1601 synchronize_irq(s->irq);
1602 s->dma_adc.swptr = s->dma_adc.hwptr = s->dma_adc.count = s->dma_adc.total_bytes = 0;
1603 }
1604 return 0;
1605
1606 case SNDCTL_DSP_SPEED:
1607 if (get_user(val, p))
1608 return -EFAULT;
1609 if (val >= 0) {
1610 if (file->f_mode & FMODE_READ) {
1611 stop_adc(s);
1612 s->dma_adc.ready = 0;
1613 set_adc_rate(s, val);
1614 }
1615 if (file->f_mode & FMODE_WRITE) {
1616 stop_dac(s);
1617 s->dma_dac.ready = 0;
1618 set_dac_rate(s, val);
1619 }
1620 }
1621 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
1622
1623 case SNDCTL_DSP_STEREO:
1624 if (get_user(val, p))
1625 return -EFAULT;
1626 fmtd = 0;
1627 fmtm = ~0;
1628 if (file->f_mode & FMODE_READ) {
1629 stop_adc(s);
1630 s->dma_adc.ready = 0;
1631 if (val)
1632 fmtd |= SV_CFMT_STEREO << SV_CFMT_CSHIFT;
1633 else
1634 fmtm &= ~(SV_CFMT_STEREO << SV_CFMT_CSHIFT);
1635 }
1636 if (file->f_mode & FMODE_WRITE) {
1637 stop_dac(s);
1638 s->dma_dac.ready = 0;
1639 if (val)
1640 fmtd |= SV_CFMT_STEREO << SV_CFMT_ASHIFT;
1641 else
1642 fmtm &= ~(SV_CFMT_STEREO << SV_CFMT_ASHIFT);
1643 }
1644 set_fmt(s, fmtm, fmtd);
1645 return 0;
1646
1647 case SNDCTL_DSP_CHANNELS:
1648 if (get_user(val, p))
1649 return -EFAULT;
1650 if (val != 0) {
1651 fmtd = 0;
1652 fmtm = ~0;
1653 if (file->f_mode & FMODE_READ) {
1654 stop_adc(s);
1655 s->dma_adc.ready = 0;
1656 if (val >= 2)
1657 fmtd |= SV_CFMT_STEREO << SV_CFMT_CSHIFT;
1658 else
1659 fmtm &= ~(SV_CFMT_STEREO << SV_CFMT_CSHIFT);
1660 }
1661 if (file->f_mode & FMODE_WRITE) {
1662 stop_dac(s);
1663 s->dma_dac.ready = 0;
1664 if (val >= 2)
1665 fmtd |= SV_CFMT_STEREO << SV_CFMT_ASHIFT;
1666 else
1667 fmtm &= ~(SV_CFMT_STEREO << SV_CFMT_ASHIFT);
1668 }
1669 set_fmt(s, fmtm, fmtd);
1670 }
1671 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (SV_CFMT_STEREO << SV_CFMT_CSHIFT)
1672 : (SV_CFMT_STEREO << SV_CFMT_ASHIFT))) ? 2 : 1, p);
1673
1674 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1675 return put_user(AFMT_S16_LE|AFMT_U8, p);
1676
1677 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
1678 if (get_user(val, p))
1679 return -EFAULT;
1680 if (val != AFMT_QUERY) {
1681 fmtd = 0;
1682 fmtm = ~0;
1683 if (file->f_mode & FMODE_READ) {
1684 stop_adc(s);
1685 s->dma_adc.ready = 0;
1686 if (val == AFMT_S16_LE)
1687 fmtd |= SV_CFMT_16BIT << SV_CFMT_CSHIFT;
1688 else
1689 fmtm &= ~(SV_CFMT_16BIT << SV_CFMT_CSHIFT);
1690 }
1691 if (file->f_mode & FMODE_WRITE) {
1692 stop_dac(s);
1693 s->dma_dac.ready = 0;
1694 if (val == AFMT_S16_LE)
1695 fmtd |= SV_CFMT_16BIT << SV_CFMT_ASHIFT;
1696 else
1697 fmtm &= ~(SV_CFMT_16BIT << SV_CFMT_ASHIFT);
1698 }
1699 set_fmt(s, fmtm, fmtd);
1700 }
1701 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (SV_CFMT_16BIT << SV_CFMT_CSHIFT)
1702 : (SV_CFMT_16BIT << SV_CFMT_ASHIFT))) ? AFMT_S16_LE : AFMT_U8, p);
1703
1704 case SNDCTL_DSP_POST:
1705 return 0;
1706
1707 case SNDCTL_DSP_GETTRIGGER:
1708 val = 0;
1709 if (file->f_mode & FMODE_READ && s->enable & SV_CENABLE_RE)
1710 val |= PCM_ENABLE_INPUT;
1711 if (file->f_mode & FMODE_WRITE && s->enable & SV_CENABLE_PE)
1712 val |= PCM_ENABLE_OUTPUT;
1713 return put_user(val, p);
1714
1715 case SNDCTL_DSP_SETTRIGGER:
1716 if (get_user(val, p))
1717 return -EFAULT;
1718 if (file->f_mode & FMODE_READ) {
1719 if (val & PCM_ENABLE_INPUT) {
1720 if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
1721 return ret;
1722 s->dma_adc.enabled = 1;
1723 start_adc(s);
1724 } else {
1725 s->dma_adc.enabled = 0;
1726 stop_adc(s);
1727 }
1728 }
1729 if (file->f_mode & FMODE_WRITE) {
1730 if (val & PCM_ENABLE_OUTPUT) {
1731 if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
1732 return ret;
1733 s->dma_dac.enabled = 1;
1734 start_dac(s);
1735 } else {
1736 s->dma_dac.enabled = 0;
1737 stop_dac(s);
1738 }
1739 }
1740 return 0;
1741
1742 case SNDCTL_DSP_GETOSPACE:
1743 if (!(file->f_mode & FMODE_WRITE))
1744 return -EINVAL;
1745 if (!s->dma_dac.ready && (val = prog_dmabuf(s, 0)) != 0)
1746 return val;
1747 spin_lock_irqsave(&s->lock, flags);
1748 sv_update_ptr(s);
1749 abinfo.fragsize = s->dma_dac.fragsize;
1750 count = s->dma_dac.count;
1751 if (count < 0)
1752 count = 0;
1753 abinfo.bytes = s->dma_dac.dmasize - count;
1754 abinfo.fragstotal = s->dma_dac.numfrag;
1755 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
1756 spin_unlock_irqrestore(&s->lock, flags);
1757 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1758
1759 case SNDCTL_DSP_GETISPACE:
1760 if (!(file->f_mode & FMODE_READ))
1761 return -EINVAL;
1762 if (!s->dma_adc.ready && (val = prog_dmabuf(s, 1)) != 0)
1763 return val;
1764 spin_lock_irqsave(&s->lock, flags);
1765 sv_update_ptr(s);
1766 abinfo.fragsize = s->dma_adc.fragsize;
1767 count = s->dma_adc.count;
1768 if (count < 0)
1769 count = 0;
1770 abinfo.bytes = count;
1771 abinfo.fragstotal = s->dma_adc.numfrag;
1772 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1773 spin_unlock_irqrestore(&s->lock, flags);
1774 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1775
1776 case SNDCTL_DSP_NONBLOCK:
1777 file->f_flags |= O_NONBLOCK;
1778 return 0;
1779
1780 case SNDCTL_DSP_GETODELAY:
1781 if (!(file->f_mode & FMODE_WRITE))
1782 return -EINVAL;
1783 if (!s->dma_dac.ready && (val = prog_dmabuf(s, 0)) != 0)
1784 return val;
1785 spin_lock_irqsave(&s->lock, flags);
1786 sv_update_ptr(s);
1787 count = s->dma_dac.count;
1788 spin_unlock_irqrestore(&s->lock, flags);
1789 if (count < 0)
1790 count = 0;
1791 return put_user(count, p);
1792
1793 case SNDCTL_DSP_GETIPTR:
1794 if (!(file->f_mode & FMODE_READ))
1795 return -EINVAL;
1796 if (!s->dma_adc.ready && (val = prog_dmabuf(s, 1)) != 0)
1797 return val;
1798 spin_lock_irqsave(&s->lock, flags);
1799 sv_update_ptr(s);
1800 cinfo.bytes = s->dma_adc.total_bytes;
1801 count = s->dma_adc.count;
1802 if (count < 0)
1803 count = 0;
1804 cinfo.blocks = count >> s->dma_adc.fragshift;
1805 cinfo.ptr = s->dma_adc.hwptr;
1806 if (s->dma_adc.mapped)
1807 s->dma_adc.count &= s->dma_adc.fragsize-1;
1808 spin_unlock_irqrestore(&s->lock, flags);
1809 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1810 return -EFAULT;
1811 return 0;
1812
1813 case SNDCTL_DSP_GETOPTR:
1814 if (!(file->f_mode & FMODE_WRITE))
1815 return -EINVAL;
1816 if (!s->dma_dac.ready && (val = prog_dmabuf(s, 0)) != 0)
1817 return val;
1818 spin_lock_irqsave(&s->lock, flags);
1819 sv_update_ptr(s);
1820 cinfo.bytes = s->dma_dac.total_bytes;
1821 count = s->dma_dac.count;
1822 if (count < 0)
1823 count = 0;
1824 cinfo.blocks = count >> s->dma_dac.fragshift;
1825 cinfo.ptr = s->dma_dac.hwptr;
1826 if (s->dma_dac.mapped)
1827 s->dma_dac.count &= s->dma_dac.fragsize-1;
1828 spin_unlock_irqrestore(&s->lock, flags);
1829 if (copy_to_user(argp, &cinfo, sizeof(cinfo)))
1830 return -EFAULT;
1831 return 0;
1832
1833 case SNDCTL_DSP_GETBLKSIZE:
1834 if (file->f_mode & FMODE_WRITE) {
1835 if ((val = prog_dmabuf(s, 0)))
1836 return val;
1837 return put_user(s->dma_dac.fragsize, p);
1838 }
1839 if ((val = prog_dmabuf(s, 1)))
1840 return val;
1841 return put_user(s->dma_adc.fragsize, p);
1842
1843 case SNDCTL_DSP_SETFRAGMENT:
1844 if (get_user(val, p))
1845 return -EFAULT;
1846 if (file->f_mode & FMODE_READ) {
1847 s->dma_adc.ossfragshift = val & 0xffff;
1848 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1849 if (s->dma_adc.ossfragshift < 4)
1850 s->dma_adc.ossfragshift = 4;
1851 if (s->dma_adc.ossfragshift > 15)
1852 s->dma_adc.ossfragshift = 15;
1853 if (s->dma_adc.ossmaxfrags < 4)
1854 s->dma_adc.ossmaxfrags = 4;
1855 }
1856 if (file->f_mode & FMODE_WRITE) {
1857 s->dma_dac.ossfragshift = val & 0xffff;
1858 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
1859 if (s->dma_dac.ossfragshift < 4)
1860 s->dma_dac.ossfragshift = 4;
1861 if (s->dma_dac.ossfragshift > 15)
1862 s->dma_dac.ossfragshift = 15;
1863 if (s->dma_dac.ossmaxfrags < 4)
1864 s->dma_dac.ossmaxfrags = 4;
1865 }
1866 return 0;
1867
1868 case SNDCTL_DSP_SUBDIVIDE:
1869 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1870 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
1871 return -EINVAL;
1872 if (get_user(val, p))
1873 return -EFAULT;
1874 if (val != 1 && val != 2 && val != 4)
1875 return -EINVAL;
1876 if (file->f_mode & FMODE_READ)
1877 s->dma_adc.subdivision = val;
1878 if (file->f_mode & FMODE_WRITE)
1879 s->dma_dac.subdivision = val;
1880 return 0;
1881
1882 case SOUND_PCM_READ_RATE:
1883 return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
1884
1885 case SOUND_PCM_READ_CHANNELS:
1886 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (SV_CFMT_STEREO << SV_CFMT_CSHIFT)
1887 : (SV_CFMT_STEREO << SV_CFMT_ASHIFT))) ? 2 : 1, p);
1888
1889 case SOUND_PCM_READ_BITS:
1890 return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (SV_CFMT_16BIT << SV_CFMT_CSHIFT)
1891 : (SV_CFMT_16BIT << SV_CFMT_ASHIFT))) ? 16 : 8, p);
1892
1893 case SOUND_PCM_WRITE_FILTER:
1894 case SNDCTL_DSP_SETSYNCRO:
1895 case SOUND_PCM_READ_FILTER:
1896 return -EINVAL;
1897
1898 }
1899 return mixer_ioctl(s, cmd, arg);
1900}
1901
1902static int sv_open(struct inode *inode, struct file *file)
1903{
1904 int minor = iminor(inode);
1905 DECLARE_WAITQUEUE(wait, current);
1906 unsigned char fmtm = ~0, fmts = 0;
1907 struct list_head *list;
1908 struct sv_state *s;
1909
1910 for (list = devs.next; ; list = list->next) {
1911 if (list == &devs)
1912 return -ENODEV;
1913 s = list_entry(list, struct sv_state, devs);
1914 if (!((s->dev_audio ^ minor) & ~0xf))
1915 break;
1916 }
1917 VALIDATE_STATE(s);
1918 file->private_data = s;
1919 /* wait for device to become free */
1920 down(&s->open_sem);
1921 while (s->open_mode & file->f_mode) {
1922 if (file->f_flags & O_NONBLOCK) {
1923 up(&s->open_sem);
1924 return -EBUSY;
1925 }
1926 add_wait_queue(&s->open_wait, &wait);
1927 __set_current_state(TASK_INTERRUPTIBLE);
1928 up(&s->open_sem);
1929 schedule();
1930 remove_wait_queue(&s->open_wait, &wait);
1931 set_current_state(TASK_RUNNING);
1932 if (signal_pending(current))
1933 return -ERESTARTSYS;
1934 down(&s->open_sem);
1935 }
1936 if (file->f_mode & FMODE_READ) {
1937 fmtm &= ~((SV_CFMT_STEREO | SV_CFMT_16BIT) << SV_CFMT_CSHIFT);
1938 if ((minor & 0xf) == SND_DEV_DSP16)
1939 fmts |= SV_CFMT_16BIT << SV_CFMT_CSHIFT;
1940 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = s->dma_adc.subdivision = 0;
1941 s->dma_adc.enabled = 1;
1942 set_adc_rate(s, 8000);
1943 }
1944 if (file->f_mode & FMODE_WRITE) {
1945 fmtm &= ~((SV_CFMT_STEREO | SV_CFMT_16BIT) << SV_CFMT_ASHIFT);
1946 if ((minor & 0xf) == SND_DEV_DSP16)
1947 fmts |= SV_CFMT_16BIT << SV_CFMT_ASHIFT;
1948 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = s->dma_dac.subdivision = 0;
1949 s->dma_dac.enabled = 1;
1950 set_dac_rate(s, 8000);
1951 }
1952 set_fmt(s, fmtm, fmts);
1953 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1954 up(&s->open_sem);
1955 return nonseekable_open(inode, file);
1956}
1957
1958static int sv_release(struct inode *inode, struct file *file)
1959{
1960 struct sv_state *s = (struct sv_state *)file->private_data;
1961
1962 VALIDATE_STATE(s);
1963 lock_kernel();
1964 if (file->f_mode & FMODE_WRITE)
1965 drain_dac(s, file->f_flags & O_NONBLOCK);
1966 down(&s->open_sem);
1967 if (file->f_mode & FMODE_WRITE) {
1968 stop_dac(s);
1969 dealloc_dmabuf(s, &s->dma_dac);
1970 }
1971 if (file->f_mode & FMODE_READ) {
1972 stop_adc(s);
1973 dealloc_dmabuf(s, &s->dma_adc);
1974 }
1975 s->open_mode &= ~(file->f_mode & (FMODE_READ|FMODE_WRITE));
1976 wake_up(&s->open_wait);
1977 up(&s->open_sem);
1978 unlock_kernel();
1979 return 0;
1980}
1981
1982static /*const*/ struct file_operations sv_audio_fops = {
1983 .owner = THIS_MODULE,
1984 .llseek = no_llseek,
1985 .read = sv_read,
1986 .write = sv_write,
1987 .poll = sv_poll,
1988 .ioctl = sv_ioctl,
1989 .mmap = sv_mmap,
1990 .open = sv_open,
1991 .release = sv_release,
1992};
1993
1994/* --------------------------------------------------------------------- */
1995
1996static ssize_t sv_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1997{
1998 struct sv_state *s = (struct sv_state *)file->private_data;
1999 DECLARE_WAITQUEUE(wait, current);
2000 ssize_t ret;
2001 unsigned long flags;
2002 unsigned ptr;
2003 int cnt;
2004
2005 VALIDATE_STATE(s);
2006 if (!access_ok(VERIFY_WRITE, buffer, count))
2007 return -EFAULT;
2008 if (count == 0)
2009 return 0;
2010 ret = 0;
2011 add_wait_queue(&s->midi.iwait, &wait);
2012 while (count > 0) {
2013 spin_lock_irqsave(&s->lock, flags);
2014 ptr = s->midi.ird;
2015 cnt = MIDIINBUF - ptr;
2016 if (s->midi.icnt < cnt)
2017 cnt = s->midi.icnt;
2018 if (cnt <= 0)
2019 __set_current_state(TASK_INTERRUPTIBLE);
2020 spin_unlock_irqrestore(&s->lock, flags);
2021 if (cnt > count)
2022 cnt = count;
2023 if (cnt <= 0) {
2024 if (file->f_flags & O_NONBLOCK) {
2025 if (!ret)
2026 ret = -EAGAIN;
2027 break;
2028 }
2029 schedule();
2030 if (signal_pending(current)) {
2031 if (!ret)
2032 ret = -ERESTARTSYS;
2033 break;
2034 }
2035 continue;
2036 }
2037 if (copy_to_user(buffer, s->midi.ibuf + ptr, cnt)) {
2038 if (!ret)
2039 ret = -EFAULT;
2040 break;
2041 }
2042 ptr = (ptr + cnt) % MIDIINBUF;
2043 spin_lock_irqsave(&s->lock, flags);
2044 s->midi.ird = ptr;
2045 s->midi.icnt -= cnt;
2046 spin_unlock_irqrestore(&s->lock, flags);
2047 count -= cnt;
2048 buffer += cnt;
2049 ret += cnt;
2050 break;
2051 }
2052 __set_current_state(TASK_RUNNING);
2053 remove_wait_queue(&s->midi.iwait, &wait);
2054 return ret;
2055}
2056
2057static ssize_t sv_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2058{
2059 struct sv_state *s = (struct sv_state *)file->private_data;
2060 DECLARE_WAITQUEUE(wait, current);
2061 ssize_t ret;
2062 unsigned long flags;
2063 unsigned ptr;
2064 int cnt;
2065
2066 VALIDATE_STATE(s);
2067 if (!access_ok(VERIFY_READ, buffer, count))
2068 return -EFAULT;
2069 if (count == 0)
2070 return 0;
2071 ret = 0;
2072 add_wait_queue(&s->midi.owait, &wait);
2073 while (count > 0) {
2074 spin_lock_irqsave(&s->lock, flags);
2075 ptr = s->midi.owr;
2076 cnt = MIDIOUTBUF - ptr;
2077 if (s->midi.ocnt + cnt > MIDIOUTBUF)
2078 cnt = MIDIOUTBUF - s->midi.ocnt;
2079 if (cnt <= 0) {
2080 __set_current_state(TASK_INTERRUPTIBLE);
2081 sv_handle_midi(s);
2082 }
2083 spin_unlock_irqrestore(&s->lock, flags);
2084 if (cnt > count)
2085 cnt = count;
2086 if (cnt <= 0) {
2087 if (file->f_flags & O_NONBLOCK) {
2088 if (!ret)
2089 ret = -EAGAIN;
2090 break;
2091 }
2092 schedule();
2093 if (signal_pending(current)) {
2094 if (!ret)
2095 ret = -ERESTARTSYS;
2096 break;
2097 }
2098 continue;
2099 }
2100 if (copy_from_user(s->midi.obuf + ptr, buffer, cnt)) {
2101 if (!ret)
2102 ret = -EFAULT;
2103 break;
2104 }
2105 ptr = (ptr + cnt) % MIDIOUTBUF;
2106 spin_lock_irqsave(&s->lock, flags);
2107 s->midi.owr = ptr;
2108 s->midi.ocnt += cnt;
2109 spin_unlock_irqrestore(&s->lock, flags);
2110 count -= cnt;
2111 buffer += cnt;
2112 ret += cnt;
2113 spin_lock_irqsave(&s->lock, flags);
2114 sv_handle_midi(s);
2115 spin_unlock_irqrestore(&s->lock, flags);
2116 }
2117 __set_current_state(TASK_RUNNING);
2118 remove_wait_queue(&s->midi.owait, &wait);
2119 return ret;
2120}
2121
2122/* No kernel lock - we have our own spinlock */
2123static unsigned int sv_midi_poll(struct file *file, struct poll_table_struct *wait)
2124{
2125 struct sv_state *s = (struct sv_state *)file->private_data;
2126 unsigned long flags;
2127 unsigned int mask = 0;
2128
2129 VALIDATE_STATE(s);
2130 if (file->f_mode & FMODE_WRITE)
2131 poll_wait(file, &s->midi.owait, wait);
2132 if (file->f_mode & FMODE_READ)
2133 poll_wait(file, &s->midi.iwait, wait);
2134 spin_lock_irqsave(&s->lock, flags);
2135 if (file->f_mode & FMODE_READ) {
2136 if (s->midi.icnt > 0)
2137 mask |= POLLIN | POLLRDNORM;
2138 }
2139 if (file->f_mode & FMODE_WRITE) {
2140 if (s->midi.ocnt < MIDIOUTBUF)
2141 mask |= POLLOUT | POLLWRNORM;
2142 }
2143 spin_unlock_irqrestore(&s->lock, flags);
2144 return mask;
2145}
2146
2147static int sv_midi_open(struct inode *inode, struct file *file)
2148{
2149 int minor = iminor(inode);
2150 DECLARE_WAITQUEUE(wait, current);
2151 unsigned long flags;
2152 struct list_head *list;
2153 struct sv_state *s;
2154
2155 for (list = devs.next; ; list = list->next) {
2156 if (list == &devs)
2157 return -ENODEV;
2158 s = list_entry(list, struct sv_state, devs);
2159 if (s->dev_midi == minor)
2160 break;
2161 }
2162 VALIDATE_STATE(s);
2163 file->private_data = s;
2164 /* wait for device to become free */
2165 down(&s->open_sem);
2166 while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
2167 if (file->f_flags & O_NONBLOCK) {
2168 up(&s->open_sem);
2169 return -EBUSY;
2170 }
2171 add_wait_queue(&s->open_wait, &wait);
2172 __set_current_state(TASK_INTERRUPTIBLE);
2173 up(&s->open_sem);
2174 schedule();
2175 remove_wait_queue(&s->open_wait, &wait);
2176 set_current_state(TASK_RUNNING);
2177 if (signal_pending(current))
2178 return -ERESTARTSYS;
2179 down(&s->open_sem);
2180 }
2181 spin_lock_irqsave(&s->lock, flags);
2182 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
2183 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2184 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
2185 //outb(inb(s->ioenh + SV_CODEC_CONTROL) | SV_CCTRL_WAVETABLE, s->ioenh + SV_CODEC_CONTROL);
2186 outb(inb(s->ioenh + SV_CODEC_INTMASK) | SV_CINTMASK_MIDI, s->ioenh + SV_CODEC_INTMASK);
2187 wrindir(s, SV_CIUARTCONTROL, 5); /* output MIDI data to external and internal synth */
2188 wrindir(s, SV_CIWAVETABLESRC, 1); /* Wavetable in PC RAM */
2189 outb(0xff, s->iomidi+1); /* reset command */
2190 outb(0x3f, s->iomidi+1); /* uart command */
2191 if (!(inb(s->iomidi+1) & 0x80))
2192 inb(s->iomidi);
2193 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2194 init_timer(&s->midi.timer);
2195 s->midi.timer.expires = jiffies+1;
2196 s->midi.timer.data = (unsigned long)s;
2197 s->midi.timer.function = sv_midi_timer;
2198 add_timer(&s->midi.timer);
2199 }
2200 if (file->f_mode & FMODE_READ) {
2201 s->midi.ird = s->midi.iwr = s->midi.icnt = 0;
2202 }
2203 if (file->f_mode & FMODE_WRITE) {
2204 s->midi.ord = s->midi.owr = s->midi.ocnt = 0;
2205 }
2206 spin_unlock_irqrestore(&s->lock, flags);
2207 s->open_mode |= (file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ | FMODE_MIDI_WRITE);
2208 up(&s->open_sem);
2209 return nonseekable_open(inode, file);
2210}
2211
2212static int sv_midi_release(struct inode *inode, struct file *file)
2213{
2214 struct sv_state *s = (struct sv_state *)file->private_data;
2215 DECLARE_WAITQUEUE(wait, current);
2216 unsigned long flags;
2217 unsigned count, tmo;
2218
2219 VALIDATE_STATE(s);
2220
2221 lock_kernel();
2222 if (file->f_mode & FMODE_WRITE) {
2223 add_wait_queue(&s->midi.owait, &wait);
2224 for (;;) {
2225 __set_current_state(TASK_INTERRUPTIBLE);
2226 spin_lock_irqsave(&s->lock, flags);
2227 count = s->midi.ocnt;
2228 spin_unlock_irqrestore(&s->lock, flags);
2229 if (count <= 0)
2230 break;
2231 if (signal_pending(current))
2232 break;
2233 if (file->f_flags & O_NONBLOCK) {
2234 remove_wait_queue(&s->midi.owait, &wait);
2235 set_current_state(TASK_RUNNING);
2236 unlock_kernel();
2237 return -EBUSY;
2238 }
2239 tmo = (count * HZ) / 3100;
2240 if (!schedule_timeout(tmo ? : 1) && tmo)
2241 printk(KERN_DEBUG "sv: midi timed out??\n");
2242 }
2243 remove_wait_queue(&s->midi.owait, &wait);
2244 set_current_state(TASK_RUNNING);
2245 }
2246 down(&s->open_sem);
2247 s->open_mode &= ~((file->f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ|FMODE_MIDI_WRITE));
2248 spin_lock_irqsave(&s->lock, flags);
2249 if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
2250 outb(inb(s->ioenh + SV_CODEC_INTMASK) & ~SV_CINTMASK_MIDI, s->ioenh + SV_CODEC_INTMASK);
2251 del_timer(&s->midi.timer);
2252 }
2253 spin_unlock_irqrestore(&s->lock, flags);
2254 wake_up(&s->open_wait);
2255 up(&s->open_sem);
2256 unlock_kernel();
2257 return 0;
2258}
2259
2260static /*const*/ struct file_operations sv_midi_fops = {
2261 .owner = THIS_MODULE,
2262 .llseek = no_llseek,
2263 .read = sv_midi_read,
2264 .write = sv_midi_write,
2265 .poll = sv_midi_poll,
2266 .open = sv_midi_open,
2267 .release = sv_midi_release,
2268};
2269
2270/* --------------------------------------------------------------------- */
2271
2272static int sv_dmfm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2273{
2274 static const unsigned char op_offset[18] = {
2275 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
2276 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
2277 0x10, 0x11, 0x12, 0x13, 0x14, 0x15
2278 };
2279 struct sv_state *s = (struct sv_state *)file->private_data;
2280 struct dm_fm_voice v;
2281 struct dm_fm_note n;
2282 struct dm_fm_params p;
2283 unsigned int io;
2284 unsigned int regb;
2285
2286 switch (cmd) {
2287 case FM_IOCTL_RESET:
2288 for (regb = 0xb0; regb < 0xb9; regb++) {
2289 outb(regb, s->iosynth);
2290 outb(0, s->iosynth+1);
2291 outb(regb, s->iosynth+2);
2292 outb(0, s->iosynth+3);
2293 }
2294 return 0;
2295
2296 case FM_IOCTL_PLAY_NOTE:
2297 if (copy_from_user(&n, (void __user *)arg, sizeof(n)))
2298 return -EFAULT;
2299 if (n.voice >= 18)
2300 return -EINVAL;
2301 if (n.voice >= 9) {
2302 regb = n.voice - 9;
2303 io = s->iosynth+2;
2304 } else {
2305 regb = n.voice;
2306 io = s->iosynth;
2307 }
2308 outb(0xa0 + regb, io);
2309 outb(n.fnum & 0xff, io+1);
2310 outb(0xb0 + regb, io);
2311 outb(((n.fnum >> 8) & 3) | ((n.octave & 7) << 2) | ((n.key_on & 1) << 5), io+1);
2312 return 0;
2313
2314 case FM_IOCTL_SET_VOICE:
2315 if (copy_from_user(&v, (void __user *)arg, sizeof(v)))
2316 return -EFAULT;
2317 if (v.voice >= 18)
2318 return -EINVAL;
2319 regb = op_offset[v.voice];
2320 io = s->iosynth + ((v.op & 1) << 1);
2321 outb(0x20 + regb, io);
2322 outb(((v.am & 1) << 7) | ((v.vibrato & 1) << 6) | ((v.do_sustain & 1) << 5) |
2323 ((v.kbd_scale & 1) << 4) | (v.harmonic & 0xf), io+1);
2324 outb(0x40 + regb, io);
2325 outb(((v.scale_level & 0x3) << 6) | (v.volume & 0x3f), io+1);
2326 outb(0x60 + regb, io);
2327 outb(((v.attack & 0xf) << 4) | (v.decay & 0xf), io+1);
2328 outb(0x80 + regb, io);
2329 outb(((v.sustain & 0xf) << 4) | (v.release & 0xf), io+1);
2330 outb(0xe0 + regb, io);
2331 outb(v.waveform & 0x7, io+1);
2332 if (n.voice >= 9) {
2333 regb = n.voice - 9;
2334 io = s->iosynth+2;
2335 } else {
2336 regb = n.voice;
2337 io = s->iosynth;
2338 }
2339 outb(0xc0 + regb, io);
2340 outb(((v.right & 1) << 5) | ((v.left & 1) << 4) | ((v.feedback & 7) << 1) |
2341 (v.connection & 1), io+1);
2342 return 0;
2343
2344 case FM_IOCTL_SET_PARAMS:
2345 if (copy_from_user(&p, (void *__user )arg, sizeof(p)))
2346 return -EFAULT;
2347 outb(0x08, s->iosynth);
2348 outb((p.kbd_split & 1) << 6, s->iosynth+1);
2349 outb(0xbd, s->iosynth);
2350 outb(((p.am_depth & 1) << 7) | ((p.vib_depth & 1) << 6) | ((p.rhythm & 1) << 5) | ((p.bass & 1) << 4) |
2351 ((p.snare & 1) << 3) | ((p.tomtom & 1) << 2) | ((p.cymbal & 1) << 1) | (p.hihat & 1), s->iosynth+1);
2352 return 0;
2353
2354 case FM_IOCTL_SET_OPL:
2355 outb(4, s->iosynth+2);
2356 outb(arg, s->iosynth+3);
2357 return 0;
2358
2359 case FM_IOCTL_SET_MODE:
2360 outb(5, s->iosynth+2);
2361 outb(arg & 1, s->iosynth+3);
2362 return 0;
2363
2364 default:
2365 return -EINVAL;
2366 }
2367}
2368
2369static int sv_dmfm_open(struct inode *inode, struct file *file)
2370{
2371 int minor = iminor(inode);
2372 DECLARE_WAITQUEUE(wait, current);
2373 struct list_head *list;
2374 struct sv_state *s;
2375
2376 for (list = devs.next; ; list = list->next) {
2377 if (list == &devs)
2378 return -ENODEV;
2379 s = list_entry(list, struct sv_state, devs);
2380 if (s->dev_dmfm == minor)
2381 break;
2382 }
2383 VALIDATE_STATE(s);
2384 file->private_data = s;
2385 /* wait for device to become free */
2386 down(&s->open_sem);
2387 while (s->open_mode & FMODE_DMFM) {
2388 if (file->f_flags & O_NONBLOCK) {
2389 up(&s->open_sem);
2390 return -EBUSY;
2391 }
2392 add_wait_queue(&s->open_wait, &wait);
2393 __set_current_state(TASK_INTERRUPTIBLE);
2394 up(&s->open_sem);
2395 schedule();
2396 remove_wait_queue(&s->open_wait, &wait);
2397 set_current_state(TASK_RUNNING);
2398 if (signal_pending(current))
2399 return -ERESTARTSYS;
2400 down(&s->open_sem);
2401 }
2402 /* init the stuff */
2403 outb(1, s->iosynth);
2404 outb(0x20, s->iosynth+1); /* enable waveforms */
2405 outb(4, s->iosynth+2);
2406 outb(0, s->iosynth+3); /* no 4op enabled */
2407 outb(5, s->iosynth+2);
2408 outb(1, s->iosynth+3); /* enable OPL3 */
2409 s->open_mode |= FMODE_DMFM;
2410 up(&s->open_sem);
2411 return nonseekable_open(inode, file);
2412}
2413
2414static int sv_dmfm_release(struct inode *inode, struct file *file)
2415{
2416 struct sv_state *s = (struct sv_state *)file->private_data;
2417 unsigned int regb;
2418
2419 VALIDATE_STATE(s);
2420 lock_kernel();
2421 down(&s->open_sem);
2422 s->open_mode &= ~FMODE_DMFM;
2423 for (regb = 0xb0; regb < 0xb9; regb++) {
2424 outb(regb, s->iosynth);
2425 outb(0, s->iosynth+1);
2426 outb(regb, s->iosynth+2);
2427 outb(0, s->iosynth+3);
2428 }
2429 wake_up(&s->open_wait);
2430 up(&s->open_sem);
2431 unlock_kernel();
2432 return 0;
2433}
2434
2435static /*const*/ struct file_operations sv_dmfm_fops = {
2436 .owner = THIS_MODULE,
2437 .llseek = no_llseek,
2438 .ioctl = sv_dmfm_ioctl,
2439 .open = sv_dmfm_open,
2440 .release = sv_dmfm_release,
2441};
2442
2443/* --------------------------------------------------------------------- */
2444
2445/* maximum number of devices; only used for command line params */
2446#define NR_DEVICE 5
2447
2448static int reverb[NR_DEVICE];
2449
2450#if 0
2451static int wavetable[NR_DEVICE];
2452#endif
2453
2454static unsigned int devindex;
2455
2456module_param_array(reverb, bool, NULL, 0);
2457MODULE_PARM_DESC(reverb, "if 1 enables the reverb circuitry. NOTE: your card must have the reverb RAM");
2458#if 0
2459MODULE_PARM(wavetable, "1-" __MODULE_STRING(NR_DEVICE) "i");
2460MODULE_PARM_DESC(wavetable, "if 1 the wavetable synth is enabled");
2461#endif
2462
2463MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
2464MODULE_DESCRIPTION("S3 SonicVibes Driver");
2465MODULE_LICENSE("GPL");
2466
2467
2468/* --------------------------------------------------------------------- */
2469
2470static struct initvol {
2471 int mixch;
2472 int vol;
2473} initvol[] __devinitdata = {
2474 { SOUND_MIXER_WRITE_RECLEV, 0x4040 },
2475 { SOUND_MIXER_WRITE_LINE1, 0x4040 },
2476 { SOUND_MIXER_WRITE_CD, 0x4040 },
2477 { SOUND_MIXER_WRITE_LINE, 0x4040 },
2478 { SOUND_MIXER_WRITE_MIC, 0x4040 },
2479 { SOUND_MIXER_WRITE_SYNTH, 0x4040 },
2480 { SOUND_MIXER_WRITE_LINE2, 0x4040 },
2481 { SOUND_MIXER_WRITE_VOLUME, 0x4040 },
2482 { SOUND_MIXER_WRITE_PCM, 0x4040 }
2483};
2484
2485#define RSRCISIOREGION(dev,num) (pci_resource_start((dev), (num)) != 0 && \
2486 (pci_resource_flags((dev), (num)) & IORESOURCE_IO))
2487
2488static int __devinit sv_register_gameport(struct sv_state *s, int io_port)
2489{
2490 struct gameport *gp;
2491
2492 if (!request_region(io_port, SV_EXTENT_GAME, "S3 SonicVibes Gameport")) {
2493 printk(KERN_ERR "sv: gameport io ports are in use\n");
2494 return -EBUSY;
2495 }
2496
2497 s->gameport = gp = gameport_allocate_port();
2498 if (!gp) {
2499 printk(KERN_ERR "sv: can not allocate memory for gameport\n");
2500 release_region(io_port, SV_EXTENT_GAME);
2501 return -ENOMEM;
2502 }
2503
2504 gameport_set_name(gp, "S3 SonicVibes Gameport");
2505 gameport_set_phys(gp, "isa%04x/gameport0", io_port);
2506 gp->dev.parent = &s->dev->dev;
2507 gp->io = io_port;
2508
2509 gameport_register_port(gp);
2510
2511 return 0;
2512}
2513
2514static int __devinit sv_probe(struct pci_dev *pcidev, const struct pci_device_id *pciid)
2515{
2516 static char __devinitdata sv_ddma_name[] = "S3 Inc. SonicVibes DDMA Controller";
2517 struct sv_state *s;
2518 mm_segment_t fs;
2519 int i, val, ret;
2520 int gpio;
2521 char *ddmaname;
2522 unsigned ddmanamelen;
2523
2524 if ((ret=pci_enable_device(pcidev)))
2525 return ret;
2526
2527 if (!RSRCISIOREGION(pcidev, RESOURCE_SB) ||
2528 !RSRCISIOREGION(pcidev, RESOURCE_ENH) ||
2529 !RSRCISIOREGION(pcidev, RESOURCE_SYNTH) ||
2530 !RSRCISIOREGION(pcidev, RESOURCE_MIDI) ||
2531 !RSRCISIOREGION(pcidev, RESOURCE_GAME))
2532 return -ENODEV;
2533 if (pcidev->irq == 0)
2534 return -ENODEV;
2535 if (pci_set_dma_mask(pcidev, 0x00ffffff)) {
2536 printk(KERN_WARNING "sonicvibes: architecture does not support 24bit PCI busmaster DMA\n");
2537 return -ENODEV;
2538 }
2539 /* try to allocate a DDMA resource if not already available */
2540 if (!RSRCISIOREGION(pcidev, RESOURCE_DDMA)) {
2541 pcidev->resource[RESOURCE_DDMA].start = 0;
2542 pcidev->resource[RESOURCE_DDMA].end = 2*SV_EXTENT_DMA-1;
2543 pcidev->resource[RESOURCE_DDMA].flags = PCI_BASE_ADDRESS_SPACE_IO | IORESOURCE_IO;
2544 ddmanamelen = strlen(sv_ddma_name)+1;
2545 if (!(ddmaname = kmalloc(ddmanamelen, GFP_KERNEL)))
2546 return -1;
2547 memcpy(ddmaname, sv_ddma_name, ddmanamelen);
2548 pcidev->resource[RESOURCE_DDMA].name = ddmaname;
2549 if (pci_assign_resource(pcidev, RESOURCE_DDMA)) {
2550 pcidev->resource[RESOURCE_DDMA].name = NULL;
2551 kfree(ddmaname);
2552 printk(KERN_ERR "sv: cannot allocate DDMA controller io ports\n");
2553 return -EBUSY;
2554 }
2555 }
2556 if (!(s = kmalloc(sizeof(struct sv_state), GFP_KERNEL))) {
2557 printk(KERN_WARNING "sv: out of memory\n");
2558 return -ENOMEM;
2559 }
2560 memset(s, 0, sizeof(struct sv_state));
2561 init_waitqueue_head(&s->dma_adc.wait);
2562 init_waitqueue_head(&s->dma_dac.wait);
2563 init_waitqueue_head(&s->open_wait);
2564 init_waitqueue_head(&s->midi.iwait);
2565 init_waitqueue_head(&s->midi.owait);
2566 init_MUTEX(&s->open_sem);
2567 spin_lock_init(&s->lock);
2568 s->magic = SV_MAGIC;
2569 s->dev = pcidev;
2570 s->iosb = pci_resource_start(pcidev, RESOURCE_SB);
2571 s->ioenh = pci_resource_start(pcidev, RESOURCE_ENH);
2572 s->iosynth = pci_resource_start(pcidev, RESOURCE_SYNTH);
2573 s->iomidi = pci_resource_start(pcidev, RESOURCE_MIDI);
2574 s->iodmaa = pci_resource_start(pcidev, RESOURCE_DDMA);
2575 s->iodmac = pci_resource_start(pcidev, RESOURCE_DDMA) + SV_EXTENT_DMA;
2576 gpio = pci_resource_start(pcidev, RESOURCE_GAME);
2577 pci_write_config_dword(pcidev, 0x40, s->iodmaa | 9); /* enable and use extended mode */
2578 pci_write_config_dword(pcidev, 0x48, s->iodmac | 9); /* enable */
2579 printk(KERN_DEBUG "sv: io ports: %#lx %#lx %#lx %#lx %#x %#x %#x\n",
2580 s->iosb, s->ioenh, s->iosynth, s->iomidi, gpio, s->iodmaa, s->iodmac);
2581 s->irq = pcidev->irq;
2582
2583 /* hack */
2584 pci_write_config_dword(pcidev, 0x60, wavetable_mem >> 12); /* wavetable base address */
2585
2586 ret = -EBUSY;
2587 if (!request_region(s->ioenh, SV_EXTENT_ENH, "S3 SonicVibes PCM")) {
2588 printk(KERN_ERR "sv: io ports %#lx-%#lx in use\n", s->ioenh, s->ioenh+SV_EXTENT_ENH-1);
2589 goto err_region5;
2590 }
2591 if (!request_region(s->iodmaa, SV_EXTENT_DMA, "S3 SonicVibes DMAA")) {
2592 printk(KERN_ERR "sv: io ports %#x-%#x in use\n", s->iodmaa, s->iodmaa+SV_EXTENT_DMA-1);
2593 goto err_region4;
2594 }
2595 if (!request_region(s->iodmac, SV_EXTENT_DMA, "S3 SonicVibes DMAC")) {
2596 printk(KERN_ERR "sv: io ports %#x-%#x in use\n", s->iodmac, s->iodmac+SV_EXTENT_DMA-1);
2597 goto err_region3;
2598 }
2599 if (!request_region(s->iomidi, SV_EXTENT_MIDI, "S3 SonicVibes Midi")) {
2600 printk(KERN_ERR "sv: io ports %#lx-%#lx in use\n", s->iomidi, s->iomidi+SV_EXTENT_MIDI-1);
2601 goto err_region2;
2602 }
2603 if (!request_region(s->iosynth, SV_EXTENT_SYNTH, "S3 SonicVibes Synth")) {
2604 printk(KERN_ERR "sv: io ports %#lx-%#lx in use\n", s->iosynth, s->iosynth+SV_EXTENT_SYNTH-1);
2605 goto err_region1;
2606 }
2607
2608 /* initialize codec registers */
2609 outb(0x80, s->ioenh + SV_CODEC_CONTROL); /* assert reset */
2610 udelay(50);
2611 outb(0x00, s->ioenh + SV_CODEC_CONTROL); /* deassert reset */
2612 udelay(50);
2613 outb(SV_CCTRL_INTADRIVE | SV_CCTRL_ENHANCED /*| SV_CCTRL_WAVETABLE */
2614 | (reverb[devindex] ? SV_CCTRL_REVERB : 0), s->ioenh + SV_CODEC_CONTROL);
2615 inb(s->ioenh + SV_CODEC_STATUS); /* clear ints */
2616 wrindir(s, SV_CIDRIVECONTROL, 0); /* drive current 16mA */
2617 wrindir(s, SV_CIENABLE, s->enable = 0); /* disable DMAA and DMAC */
2618 outb(~(SV_CINTMASK_DMAA | SV_CINTMASK_DMAC), s->ioenh + SV_CODEC_INTMASK);
2619 /* outb(0xff, s->iodmaa + SV_DMA_RESET); */
2620 /* outb(0xff, s->iodmac + SV_DMA_RESET); */
2621 inb(s->ioenh + SV_CODEC_STATUS); /* ack interrupts */
2622 wrindir(s, SV_CIADCCLKSOURCE, 0); /* use pll as ADC clock source */
2623 wrindir(s, SV_CIANALOGPWRDOWN, 0); /* power up the analog parts of the device */
2624 wrindir(s, SV_CIDIGITALPWRDOWN, 0); /* power up the digital parts of the device */
2625 setpll(s, SV_CIADCPLLM, 8000);
2626 wrindir(s, SV_CISRSSPACE, 0x80); /* SRS off */
2627 wrindir(s, SV_CIPCMSR0, (8000 * 65536 / FULLRATE) & 0xff);
2628 wrindir(s, SV_CIPCMSR1, ((8000 * 65536 / FULLRATE) >> 8) & 0xff);
2629 wrindir(s, SV_CIADCOUTPUT, 0);
2630 /* request irq */
2631 if ((ret=request_irq(s->irq,sv_interrupt,SA_SHIRQ,"S3 SonicVibes",s))) {
2632 printk(KERN_ERR "sv: irq %u in use\n", s->irq);
2633 goto err_irq;
2634 }
2635 printk(KERN_INFO "sv: found adapter at io %#lx irq %u dmaa %#06x dmac %#06x revision %u\n",
2636 s->ioenh, s->irq, s->iodmaa, s->iodmac, rdindir(s, SV_CIREVISION));
2637 /* register devices */
2638 if ((s->dev_audio = register_sound_dsp(&sv_audio_fops, -1)) < 0) {
2639 ret = s->dev_audio;
2640 goto err_dev1;
2641 }
2642 if ((s->dev_mixer = register_sound_mixer(&sv_mixer_fops, -1)) < 0) {
2643 ret = s->dev_mixer;
2644 goto err_dev2;
2645 }
2646 if ((s->dev_midi = register_sound_midi(&sv_midi_fops, -1)) < 0) {
2647 ret = s->dev_midi;
2648 goto err_dev3;
2649 }
2650 if ((s->dev_dmfm = register_sound_special(&sv_dmfm_fops, 15 /* ?? */)) < 0) {
2651 ret = s->dev_dmfm;
2652 goto err_dev4;
2653 }
2654 pci_set_master(pcidev); /* enable bus mastering */
2655 /* initialize the chips */
2656 fs = get_fs();
2657 set_fs(KERNEL_DS);
2658 val = SOUND_MASK_LINE|SOUND_MASK_SYNTH;
2659 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
2660 for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
2661 val = initvol[i].vol;
2662 mixer_ioctl(s, initvol[i].mixch, (unsigned long)&val);
2663 }
2664 set_fs(fs);
2665 /* register gameport */
2666 sv_register_gameport(s, gpio);
2667 /* store it in the driver field */
2668 pci_set_drvdata(pcidev, s);
2669 /* put it into driver list */
2670 list_add_tail(&s->devs, &devs);
2671 /* increment devindex */
2672 if (devindex < NR_DEVICE-1)
2673 devindex++;
2674 return 0;
2675
2676 err_dev4:
2677 unregister_sound_midi(s->dev_midi);
2678 err_dev3:
2679 unregister_sound_mixer(s->dev_mixer);
2680 err_dev2:
2681 unregister_sound_dsp(s->dev_audio);
2682 err_dev1:
2683 printk(KERN_ERR "sv: cannot register misc device\n");
2684 free_irq(s->irq, s);
2685 err_irq:
2686 release_region(s->iosynth, SV_EXTENT_SYNTH);
2687 err_region1:
2688 release_region(s->iomidi, SV_EXTENT_MIDI);
2689 err_region2:
2690 release_region(s->iodmac, SV_EXTENT_DMA);
2691 err_region3:
2692 release_region(s->iodmaa, SV_EXTENT_DMA);
2693 err_region4:
2694 release_region(s->ioenh, SV_EXTENT_ENH);
2695 err_region5:
2696 kfree(s);
2697 return ret;
2698}
2699
2700static void __devexit sv_remove(struct pci_dev *dev)
2701{
2702 struct sv_state *s = pci_get_drvdata(dev);
2703
2704 if (!s)
2705 return;
2706 list_del(&s->devs);
2707 outb(~0, s->ioenh + SV_CODEC_INTMASK); /* disable ints */
2708 synchronize_irq(s->irq);
2709 inb(s->ioenh + SV_CODEC_STATUS); /* ack interrupts */
2710 wrindir(s, SV_CIENABLE, 0); /* disable DMAA and DMAC */
2711 /*outb(0, s->iodmaa + SV_DMA_RESET);*/
2712 /*outb(0, s->iodmac + SV_DMA_RESET);*/
2713 free_irq(s->irq, s);
2714 if (s->gameport) {
2715 int gpio = s->gameport->io;
2716 gameport_unregister_port(s->gameport);
2717 release_region(gpio, SV_EXTENT_GAME);
2718 }
2719 release_region(s->iodmac, SV_EXTENT_DMA);
2720 release_region(s->iodmaa, SV_EXTENT_DMA);
2721 release_region(s->ioenh, SV_EXTENT_ENH);
2722 release_region(s->iomidi, SV_EXTENT_MIDI);
2723 release_region(s->iosynth, SV_EXTENT_SYNTH);
2724 unregister_sound_dsp(s->dev_audio);
2725 unregister_sound_mixer(s->dev_mixer);
2726 unregister_sound_midi(s->dev_midi);
2727 unregister_sound_special(s->dev_dmfm);
2728 kfree(s);
2729 pci_set_drvdata(dev, NULL);
2730}
2731
2732static struct pci_device_id id_table[] = {
2733 { PCI_VENDOR_ID_S3, PCI_DEVICE_ID_S3_SONICVIBES, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
2734 { 0, }
2735};
2736
2737MODULE_DEVICE_TABLE(pci, id_table);
2738
2739static struct pci_driver sv_driver = {
2740 .name = "sonicvibes",
2741 .id_table = id_table,
2742 .probe = sv_probe,
2743 .remove = __devexit_p(sv_remove),
2744};
2745
2746static int __init init_sonicvibes(void)
2747{
2748 printk(KERN_INFO "sv: version v0.31 time " __TIME__ " " __DATE__ "\n");
2749#if 0
2750 if (!(wavetable_mem = __get_free_pages(GFP_KERNEL, 20-PAGE_SHIFT)))
2751 printk(KERN_INFO "sv: cannot allocate 1MB of contiguous nonpageable memory for wavetable data\n");
2752#endif
2753 return pci_module_init(&sv_driver);
2754}
2755
2756static void __exit cleanup_sonicvibes(void)
2757{
2758 printk(KERN_INFO "sv: unloading\n");
2759 pci_unregister_driver(&sv_driver);
2760 if (wavetable_mem)
2761 free_pages(wavetable_mem, 20-PAGE_SHIFT);
2762}
2763
2764module_init(init_sonicvibes);
2765module_exit(cleanup_sonicvibes);
2766
2767/* --------------------------------------------------------------------- */
2768
2769#ifndef MODULE
2770
2771/* format is: sonicvibes=[reverb] sonicvibesdmaio=dmaioaddr */
2772
2773static int __init sonicvibes_setup(char *str)
2774{
2775 static unsigned __initdata nr_dev = 0;
2776
2777 if (nr_dev >= NR_DEVICE)
2778 return 0;
2779#if 0
2780 if (get_option(&str, &reverb[nr_dev]) == 2)
2781 (void)get_option(&str, &wavetable[nr_dev]);
2782#else
2783 (void)get_option(&str, &reverb[nr_dev]);
2784#endif
2785
2786 nr_dev++;
2787 return 1;
2788}
2789
2790__setup("sonicvibes=", sonicvibes_setup);
2791
2792#endif /* MODULE */
diff --git a/sound/oss/sound_calls.h b/sound/oss/sound_calls.h
new file mode 100644
index 000000000000..1ae07509664f
--- /dev/null
+++ b/sound/oss/sound_calls.h
@@ -0,0 +1,90 @@
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);
16int DMAbuf_open_dma (int dev);
17void DMAbuf_close_dma (int dev);
18void DMAbuf_inputintr(int dev);
19void DMAbuf_outputintr(int dev, int underflow_flag);
20struct dma_buffparms;
21int DMAbuf_space_in_queue (int dev);
22int DMAbuf_activate_recording (int dev, struct dma_buffparms *dmap);
23int DMAbuf_get_buffer_pointer (int dev, struct dma_buffparms *dmap, int direction);
24void DMAbuf_launch_output(int dev, struct dma_buffparms *dmap);
25unsigned int DMAbuf_poll(struct file *file, int dev, poll_table *wait);
26void DMAbuf_start_devices(unsigned int devmask);
27void DMAbuf_reset (int dev);
28int DMAbuf_sync (int dev);
29
30/*
31 * System calls for /dev/dsp and /dev/audio (audio.c)
32 */
33
34int audio_read (int dev, struct file *file, char __user *buf, int count);
35int audio_write (int dev, struct file *file, const char __user *buf, int count);
36int audio_open (int dev, struct file *file);
37void audio_release (int dev, struct file *file);
38int audio_ioctl (int dev, struct file *file,
39 unsigned int cmd, void __user *arg);
40void audio_init_devices (void);
41void reorganize_buffers (int dev, struct dma_buffparms *dmap, int recording);
42
43/*
44 * System calls for the /dev/sequencer
45 */
46
47int sequencer_read (int dev, struct file *file, char __user *buf, int count);
48int sequencer_write (int dev, struct file *file, const char __user *buf, int count);
49int sequencer_open (int dev, struct file *file);
50void sequencer_release (int dev, struct file *file);
51int sequencer_ioctl (int dev, struct file *file, unsigned int cmd, void __user *arg);
52unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait);
53
54void sequencer_init (void);
55void sequencer_unload (void);
56void sequencer_timer(unsigned long dummy);
57int note_to_freq(int note_num);
58unsigned long compute_finetune(unsigned long base_freq, int bend, int range,
59 int vibrato_bend);
60void seq_input_event(unsigned char *event, int len);
61void seq_copy_to_input (unsigned char *event, int len);
62
63/*
64 * System calls for the /dev/midi
65 */
66
67int MIDIbuf_read (int dev, struct file *file, char __user *buf, int count);
68int MIDIbuf_write (int dev, struct file *file, const char __user *buf, int count);
69int MIDIbuf_open (int dev, struct file *file);
70void MIDIbuf_release (int dev, struct file *file);
71int MIDIbuf_ioctl (int dev, struct file *file, unsigned int cmd, void __user *arg);
72unsigned int MIDIbuf_poll(int dev, struct file *file, poll_table * wait);
73int MIDIbuf_avail(int dev);
74
75void MIDIbuf_bytes_received(int dev, unsigned char *buf, int count);
76void MIDIbuf_init(void);
77
78
79/* From soundcard.c */
80void request_sound_timer (int count);
81void sound_stop_timer(void);
82void conf_printf(char *name, struct address_info *hw_config);
83void conf_printf2(char *name, int base, int irq, int dma, int dma2);
84
85/* From sound_timer.c */
86void sound_timer_interrupt(void);
87void sound_timer_syncinterval(unsigned int new_usecs);
88
89/* From midi_synth.c */
90void do_midi_msg (int synthno, unsigned char *msg, int mlen);
diff --git a/sound/oss/sound_config.h b/sound/oss/sound_config.h
new file mode 100644
index 000000000000..9f912b8a2969
--- /dev/null
+++ b/sound/oss/sound_config.h
@@ -0,0 +1,154 @@
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/config.h>
18#include <linux/fs.h>
19#include <linux/sound.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
114#if OPEN_READ == FMODE_READ && OPEN_WRITE == FMODE_WRITE
115
116static inline int translate_mode(struct file *file)
117{
118 return file->f_mode;
119}
120
121#else
122
123static inline int translate_mode(struct file *file)
124{
125 return ((file->f_mode & FMODE_READ) ? OPEN_READ : 0) |
126 ((file->f_mode & FMODE_WRITE) ? OPEN_WRITE : 0);
127}
128
129#endif
130
131
132#include "sound_calls.h"
133#include "dev_table.h"
134
135#ifndef DEB
136#define DEB(x)
137#endif
138
139#ifndef DDB
140#define DDB(x) do {} while (0)
141#endif
142
143#ifndef MDB
144#ifdef MODULE
145#define MDB(x) x
146#else
147#define MDB(x)
148#endif
149#endif
150
151#define TIMER_ARMED 121234
152#define TIMER_NOT_ARMED 1
153
154#endif
diff --git a/sound/oss/sound_firmware.h b/sound/oss/sound_firmware.h
new file mode 100644
index 000000000000..0a0cbfdfb855
--- /dev/null
+++ b/sound/oss/sound_firmware.h
@@ -0,0 +1,2 @@
1extern int mod_firmware_load(const char *fn, char **fp);
2
diff --git a/sound/oss/sound_syms.c b/sound/oss/sound_syms.c
new file mode 100644
index 000000000000..cb7c33fe5b05
--- /dev/null
+++ b/sound/oss/sound_syms.c
@@ -0,0 +1,50 @@
1/*
2 * The sound core exports the following symbols to the rest of
3 * modulespace.
4 *
5 * (C) Copyright 1997 Alan Cox, Licensed under the GNU GPL
6 *
7 * Thu May 27 1999 Andrew J. Kroll <ag784@freenet..buffalo..edu>
8 * left out exported symbol... fixed
9 */
10
11#include <linux/module.h>
12#include "sound_config.h"
13#include "sound_calls.h"
14
15char sound_syms_symbol;
16
17EXPORT_SYMBOL(mixer_devs);
18EXPORT_SYMBOL(audio_devs);
19EXPORT_SYMBOL(num_mixers);
20EXPORT_SYMBOL(num_audiodevs);
21
22EXPORT_SYMBOL(midi_devs);
23EXPORT_SYMBOL(num_midis);
24EXPORT_SYMBOL(synth_devs);
25
26EXPORT_SYMBOL(sound_timer_devs);
27
28EXPORT_SYMBOL(sound_install_audiodrv);
29EXPORT_SYMBOL(sound_install_mixer);
30EXPORT_SYMBOL(sound_alloc_dma);
31EXPORT_SYMBOL(sound_free_dma);
32EXPORT_SYMBOL(sound_open_dma);
33EXPORT_SYMBOL(sound_close_dma);
34EXPORT_SYMBOL(sound_alloc_mididev);
35EXPORT_SYMBOL(sound_alloc_mixerdev);
36EXPORT_SYMBOL(sound_alloc_timerdev);
37EXPORT_SYMBOL(sound_alloc_synthdev);
38EXPORT_SYMBOL(sound_unload_audiodev);
39EXPORT_SYMBOL(sound_unload_mididev);
40EXPORT_SYMBOL(sound_unload_mixerdev);
41EXPORT_SYMBOL(sound_unload_timerdev);
42EXPORT_SYMBOL(sound_unload_synthdev);
43
44EXPORT_SYMBOL(load_mixer_volumes);
45
46EXPORT_SYMBOL(conf_printf);
47EXPORT_SYMBOL(conf_printf2);
48
49MODULE_DESCRIPTION("OSS Sound subsystem");
50MODULE_AUTHOR("Hannu Savolainen, et al.");
diff --git a/sound/oss/sound_timer.c b/sound/oss/sound_timer.c
new file mode 100644
index 000000000000..bc2777dd2ef9
--- /dev/null
+++ b/sound/oss/sound_timer.c
@@ -0,0 +1,323 @@
1/*
2 * sound/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 time_t 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 spinlock_t 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}
79
80static void tmr_reset(void)
81{
82 unsigned long flags;
83
84 spin_lock_irqsave(&lock,flags);
85 tmr_offs = 0;
86 ticks_offs = 0;
87 tmr_ctr = 0;
88 next_event_time = (unsigned long) -1;
89 prev_event_time = 0;
90 curr_ticks = 0;
91 spin_unlock_irqrestore(&lock,flags);
92}
93
94static int timer_open(int dev, int mode)
95{
96 if (opened)
97 return -EBUSY;
98 tmr_reset();
99 curr_tempo = 60;
100 curr_timebase = 100;
101 opened = 1;
102 reprogram_timer();
103 return 0;
104}
105
106static void timer_close(int dev)
107{
108 opened = tmr_running = 0;
109 tmr->tmr_disable(tmr->dev);
110}
111
112static int timer_event(int dev, unsigned char *event)
113{
114 unsigned char cmd = event[1];
115 unsigned long parm = *(int *) &event[4];
116
117 switch (cmd)
118 {
119 case TMR_WAIT_REL:
120 parm += prev_event_time;
121 case TMR_WAIT_ABS:
122 if (parm > 0)
123 {
124 long time;
125
126 if (parm <= curr_ticks) /* It's the time */
127 return TIMER_NOT_ARMED;
128 time = parm;
129 next_event_time = prev_event_time = time;
130 return TIMER_ARMED;
131 }
132 break;
133
134 case TMR_START:
135 tmr_reset();
136 tmr_running = 1;
137 reprogram_timer();
138 break;
139
140 case TMR_STOP:
141 tmr_running = 0;
142 break;
143
144 case TMR_CONTINUE:
145 tmr_running = 1;
146 reprogram_timer();
147 break;
148
149 case TMR_TEMPO:
150 if (parm)
151 {
152 if (parm < 8)
153 parm = 8;
154 if (parm > 250)
155 parm = 250;
156 tmr_offs = tmr_ctr;
157 ticks_offs += tmr2ticks(tmr_ctr);
158 tmr_ctr = 0;
159 curr_tempo = parm;
160 reprogram_timer();
161 }
162 break;
163
164 case TMR_ECHO:
165 seq_copy_to_input(event, 8);
166 break;
167
168 default:;
169 }
170 return TIMER_NOT_ARMED;
171}
172
173static unsigned long timer_get_time(int dev)
174{
175 if (!opened)
176 return 0;
177 return curr_ticks;
178}
179
180static int timer_ioctl(int dev, unsigned int cmd, void __user *arg)
181{
182 int __user *p = arg;
183 int val;
184
185 switch (cmd)
186 {
187 case SNDCTL_TMR_SOURCE:
188 val = TMR_INTERNAL;
189 break;
190
191 case SNDCTL_TMR_START:
192 tmr_reset();
193 tmr_running = 1;
194 return 0;
195
196 case SNDCTL_TMR_STOP:
197 tmr_running = 0;
198 return 0;
199
200 case SNDCTL_TMR_CONTINUE:
201 tmr_running = 1;
202 return 0;
203
204 case SNDCTL_TMR_TIMEBASE:
205 if (get_user(val, p))
206 return -EFAULT;
207 if (val)
208 {
209 if (val < 1)
210 val = 1;
211 if (val > 1000)
212 val = 1000;
213 curr_timebase = val;
214 }
215 val = curr_timebase;
216 break;
217
218 case SNDCTL_TMR_TEMPO:
219 if (get_user(val, p))
220 return -EFAULT;
221 if (val)
222 {
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 val = curr_tempo;
234 break;
235
236 case SNDCTL_SEQ_CTRLRATE:
237 if (get_user(val, p))
238 return -EFAULT;
239 if (val != 0) /* Can't change */
240 return -EINVAL;
241 val = ((curr_tempo * curr_timebase) + 30) / 60;
242 break;
243
244 case SNDCTL_SEQ_GETTIME:
245 val = curr_ticks;
246 break;
247
248 case SNDCTL_TMR_METRONOME:
249 default:
250 return -EINVAL;
251 }
252 return put_user(val, p);
253}
254
255static void timer_arm(int dev, long time)
256{
257 if (time < 0)
258 time = curr_ticks + 1;
259 else if (time <= curr_ticks) /* It's the time */
260 return;
261
262 next_event_time = prev_event_time = time;
263 return;
264}
265
266static struct sound_timer_operations sound_timer =
267{
268 .owner = THIS_MODULE,
269 .info = {"Sound Timer", 0},
270 .priority = 1, /* Priority */
271 .devlink = 0, /* Local device link */
272 .open = timer_open,
273 .close = timer_close,
274 .event = timer_event,
275 .get_time = timer_get_time,
276 .ioctl = timer_ioctl,
277 .arm_timer = timer_arm
278};
279
280void sound_timer_interrupt(void)
281{
282 unsigned long flags;
283
284 if (!opened)
285 return;
286
287 tmr->tmr_restart(tmr->dev);
288
289 if (!tmr_running)
290 return;
291
292 spin_lock_irqsave(&lock,flags);
293 tmr_ctr++;
294 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
295
296 if (curr_ticks >= next_event_time)
297 {
298 next_event_time = (unsigned long) -1;
299 sequencer_timer(0);
300 }
301 spin_unlock_irqrestore(&lock,flags);
302}
303
304void sound_timer_init(struct sound_lowlev_timer *t, char *name)
305{
306 int n;
307
308 if (initialized)
309 {
310 if (t->priority <= tmr->priority)
311 return; /* There is already a similar or better timer */
312 tmr = t;
313 return;
314 }
315 initialized = 1;
316 tmr = t;
317
318 n = sound_alloc_timerdev();
319 if (n == -1)
320 n = 0; /* Overwrite the system timer */
321 strcpy(sound_timer.info.name, name);
322 sound_timer_devs[n] = &sound_timer;
323}
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
new file mode 100644
index 000000000000..de91c90a0112
--- /dev/null
+++ b/sound/oss/soundcard.c
@@ -0,0 +1,751 @@
1/*
2 * linux/drivers/sound/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#include <linux/config.h>
26
27#include "sound_config.h"
28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/errno.h>
31#include <linux/signal.h>
32#include <linux/fcntl.h>
33#include <linux/ctype.h>
34#include <linux/stddef.h>
35#include <linux/kmod.h>
36#include <asm/dma.h>
37#include <asm/io.h>
38#include <linux/wait.h>
39#include <linux/slab.h>
40#include <linux/ioport.h>
41#include <linux/devfs_fs_kernel.h>
42#include <linux/major.h>
43#include <linux/delay.h>
44#include <linux/proc_fs.h>
45#include <linux/smp_lock.h>
46#include <linux/module.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[1024];
59int sound_nblocks = 0;
60
61/* Persistent DMA buffers */
62#ifdef CONFIG_SOUND_DMAP
63int sound_dmap_flag = 1;
64#else
65int sound_dmap_flag = 0;
66#endif
67
68static char dma_alloc_map[MAX_DMA_CHANNELS];
69
70#define DMA_MAP_UNAVAIL 0
71#define DMA_MAP_FREE 1
72#define DMA_MAP_BUSY 2
73
74
75unsigned long seq_time = 0; /* Time for /dev/sequencer */
76extern struct class_simple *sound_class;
77
78/*
79 * Table for configurable mixer volume handling
80 */
81static mixer_vol_table mixer_vols[MAX_MIXER_DEV];
82static int num_mixer_volumes;
83
84int *load_mixer_volumes(char *name, int *levels, int present)
85{
86 int i, n;
87
88 for (i = 0; i < num_mixer_volumes; i++) {
89 if (strcmp(name, mixer_vols[i].name) == 0) {
90 if (present)
91 mixer_vols[i].num = i;
92 return mixer_vols[i].levels;
93 }
94 }
95 if (num_mixer_volumes >= MAX_MIXER_DEV) {
96 printk(KERN_ERR "Sound: Too many mixers (%s)\n", name);
97 return levels;
98 }
99 n = num_mixer_volumes++;
100
101 strcpy(mixer_vols[n].name, name);
102
103 if (present)
104 mixer_vols[n].num = n;
105 else
106 mixer_vols[n].num = -1;
107
108 for (i = 0; i < 32; i++)
109 mixer_vols[n].levels[i] = levels[i];
110 return mixer_vols[n].levels;
111}
112
113static int set_mixer_levels(void __user * arg)
114{
115 /* mixer_vol_table is 174 bytes, so IMHO no reason to not allocate it on the stack */
116 mixer_vol_table buf;
117
118 if (__copy_from_user(&buf, arg, sizeof(buf)))
119 return -EFAULT;
120 load_mixer_volumes(buf.name, buf.levels, 0);
121 if (__copy_to_user(arg, &buf, sizeof(buf)))
122 return -EFAULT;
123 return 0;
124}
125
126static int get_mixer_levels(void __user * arg)
127{
128 int n;
129
130 if (__get_user(n, (int __user *)(&(((mixer_vol_table __user *)arg)->num))))
131 return -EFAULT;
132 if (n < 0 || n >= num_mixer_volumes)
133 return -EINVAL;
134 if (__copy_to_user(arg, &mixer_vols[n], sizeof(mixer_vol_table)))
135 return -EFAULT;
136 return 0;
137}
138
139/* 4K page size but our output routines use some slack for overruns */
140#define PROC_BLOCK_SIZE (3*1024)
141
142static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
143{
144 int dev = iminor(file->f_dentry->d_inode);
145 int ret = -EINVAL;
146
147 /*
148 * The OSS drivers aren't remotely happy without this locking,
149 * and unless someone fixes them when they are about to bite the
150 * big one anyway, we might as well bandage here..
151 */
152
153 lock_kernel();
154
155 DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count));
156 switch (dev & 0x0f) {
157 case SND_DEV_DSP:
158 case SND_DEV_DSP16:
159 case SND_DEV_AUDIO:
160 ret = audio_read(dev, file, buf, count);
161 break;
162
163 case SND_DEV_SEQ:
164 case SND_DEV_SEQ2:
165 ret = sequencer_read(dev, file, buf, count);
166 break;
167
168 case SND_DEV_MIDIN:
169 ret = MIDIbuf_read(dev, file, buf, count);
170 }
171 unlock_kernel();
172 return ret;
173}
174
175static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
176{
177 int dev = iminor(file->f_dentry->d_inode);
178 int ret = -EINVAL;
179
180 lock_kernel();
181 DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count));
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 unlock_kernel();
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 DEB(printk("sound_open(dev=%d)\n", dev));
208 if ((dev >= SND_NDEVS) || (dev < 0)) {
209 printk(KERN_ERR "Invalid minor device %d\n", dev);
210 return -ENXIO;
211 }
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 if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL))
219 return -ENXIO;
220
221 if (!try_module_get(mixer_devs[dev]->owner))
222 return -ENXIO;
223 break;
224
225 case SND_DEV_SEQ:
226 case SND_DEV_SEQ2:
227 if ((retval = sequencer_open(dev, file)) < 0)
228 return retval;
229 break;
230
231 case SND_DEV_MIDIN:
232 if ((retval = MIDIbuf_open(dev, file)) < 0)
233 return retval;
234 break;
235
236 case SND_DEV_DSP:
237 case SND_DEV_DSP16:
238 case SND_DEV_AUDIO:
239 if ((retval = audio_open(dev, file)) < 0)
240 return retval;
241 break;
242
243 default:
244 printk(KERN_ERR "Invalid minor device %d\n", dev);
245 return -ENXIO;
246 }
247
248 return 0;
249}
250
251static int sound_release(struct inode *inode, struct file *file)
252{
253 int dev = iminor(inode);
254
255 lock_kernel();
256 DEB(printk("sound_release(dev=%d)\n", dev));
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 unlock_kernel();
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 int sound_ioctl(struct inode *inode, struct file *file,
330 unsigned int cmd, unsigned long arg)
331{
332 int len = 0, dtype;
333 int dev = iminor(inode);
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 DEB(printk("sound_ioctl(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg));
351 if (cmd == OSS_GETVERSION)
352 return __put_user(SOUND_VERSION, (int __user *)p);
353
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 return sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
362 cmd, p);
363
364 default:
365 return sound_mixer_ioctl(dev >> 4, cmd, p);
366 }
367 }
368 switch (dev & 0x0f) {
369 case SND_DEV_CTL:
370 if (cmd == SOUND_MIXER_GETLEVELS)
371 return get_mixer_levels(p);
372 if (cmd == SOUND_MIXER_SETLEVELS)
373 return set_mixer_levels(p);
374 return sound_mixer_ioctl(dev >> 4, cmd, p);
375
376 case SND_DEV_SEQ:
377 case SND_DEV_SEQ2:
378 return sequencer_ioctl(dev, file, cmd, p);
379
380 case SND_DEV_DSP:
381 case SND_DEV_DSP16:
382 case SND_DEV_AUDIO:
383 return audio_ioctl(dev, file, cmd, p);
384 break;
385
386 case SND_DEV_MIDIN:
387 return MIDIbuf_ioctl(dev, file, cmd, p);
388 break;
389
390 }
391 return -EINVAL;
392}
393
394static unsigned int sound_poll(struct file *file, poll_table * wait)
395{
396 struct inode *inode = file->f_dentry->d_inode;
397 int dev = iminor(inode);
398
399 DEB(printk("sound_poll(dev=%d)\n", dev));
400 switch (dev & 0x0f) {
401 case SND_DEV_SEQ:
402 case SND_DEV_SEQ2:
403 return sequencer_poll(dev, file, wait);
404
405 case SND_DEV_MIDIN:
406 return MIDIbuf_poll(dev, file, wait);
407
408 case SND_DEV_DSP:
409 case SND_DEV_DSP16:
410 case SND_DEV_AUDIO:
411 return DMAbuf_poll(file, dev >> 4, wait);
412 }
413 return 0;
414}
415
416static int sound_mmap(struct file *file, struct vm_area_struct *vma)
417{
418 int dev_class;
419 unsigned long size;
420 struct dma_buffparms *dmap = NULL;
421 int dev = iminor(file->f_dentry->d_inode);
422
423 dev_class = dev & 0x0f;
424 dev >>= 4;
425
426 if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) {
427 printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n");
428 return -EINVAL;
429 }
430 lock_kernel();
431 if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */
432 dmap = audio_devs[dev]->dmap_out;
433 else if (vma->vm_flags & VM_READ)
434 dmap = audio_devs[dev]->dmap_in;
435 else {
436 printk(KERN_ERR "Sound: Undefined mmap() access\n");
437 unlock_kernel();
438 return -EINVAL;
439 }
440
441 if (dmap == NULL) {
442 printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n");
443 unlock_kernel();
444 return -EIO;
445 }
446 if (dmap->raw_buf == NULL) {
447 printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n");
448 unlock_kernel();
449 return -EIO;
450 }
451 if (dmap->mapping_flags) {
452 printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n");
453 unlock_kernel();
454 return -EIO;
455 }
456 if (vma->vm_pgoff != 0) {
457 printk(KERN_ERR "Sound: mmap() offset must be 0.\n");
458 unlock_kernel();
459 return -EINVAL;
460 }
461 size = vma->vm_end - vma->vm_start;
462
463 if (size != dmap->bytes_in_use) {
464 printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use);
465 }
466 if (remap_pfn_range(vma, vma->vm_start,
467 virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT,
468 vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
469 unlock_kernel();
470 return -EAGAIN;
471 }
472
473 dmap->mapping_flags |= DMA_MAP_MAPPED;
474
475 if( audio_devs[dev]->d->mmap)
476 audio_devs[dev]->d->mmap(dev);
477
478 memset(dmap->raw_buf,
479 dmap->neutral_byte,
480 dmap->bytes_in_use);
481 unlock_kernel();
482 return 0;
483}
484
485struct file_operations oss_sound_fops = {
486 .owner = THIS_MODULE,
487 .llseek = no_llseek,
488 .read = sound_read,
489 .write = sound_write,
490 .poll = sound_poll,
491 .ioctl = sound_ioctl,
492 .mmap = sound_mmap,
493 .open = sound_open,
494 .release = sound_release,
495};
496
497/*
498 * Create the required special subdevices
499 */
500
501static int create_special_devices(void)
502{
503 int seq1,seq2;
504 seq1=register_sound_special(&oss_sound_fops, 1);
505 if(seq1==-1)
506 goto bad;
507 seq2=register_sound_special(&oss_sound_fops, 8);
508 if(seq2!=-1)
509 return 0;
510 unregister_sound_special(1);
511bad:
512 return -1;
513}
514
515
516/* These device names follow the official Linux device list,
517 * Documentation/devices.txt. Let us know if there are other
518 * common names we should support for compatibility.
519 * Only those devices not created by the generic code in sound_core.c are
520 * registered here.
521 */
522static const struct {
523 unsigned short minor;
524 char *name;
525 umode_t mode;
526 int *num;
527} dev_list[] = { /* list of minor devices */
528/* seems to be some confusion here -- this device is not in the device list */
529 {SND_DEV_DSP16, "dspW", S_IWUGO | S_IRUSR | S_IRGRP,
530 &num_audiodevs},
531 {SND_DEV_AUDIO, "audio", S_IWUGO | S_IRUSR | S_IRGRP,
532 &num_audiodevs},
533};
534
535static int dmabuf;
536static int dmabug;
537
538module_param(dmabuf, int, 0444);
539module_param(dmabug, int, 0444);
540
541static int __init oss_init(void)
542{
543 int err;
544 int i, j;
545
546 /* drag in sound_syms.o */
547 {
548 extern char sound_syms_symbol;
549 sound_syms_symbol = 0;
550 }
551
552#ifdef CONFIG_PCI
553 if(dmabug)
554 isa_dma_bridge_buggy = dmabug;
555#endif
556
557 err = create_special_devices();
558 if (err) {
559 printk(KERN_ERR "sound: driver already loaded/included in kernel\n");
560 return err;
561 }
562
563 /* Protecting the innocent */
564 sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
565
566 for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
567 devfs_mk_cdev(MKDEV(SOUND_MAJOR, dev_list[i].minor),
568 S_IFCHR | dev_list[i].mode,
569 "sound/%s", dev_list[i].name);
570 class_simple_device_add(sound_class,
571 MKDEV(SOUND_MAJOR, dev_list[i].minor),
572 NULL, "%s", dev_list[i].name);
573
574 if (!dev_list[i].num)
575 continue;
576
577 for (j = 1; j < *dev_list[i].num; j++) {
578 devfs_mk_cdev(MKDEV(SOUND_MAJOR,
579 dev_list[i].minor + (j*0x10)),
580 S_IFCHR | dev_list[i].mode,
581 "sound/%s%d", dev_list[i].name, j);
582 class_simple_device_add(sound_class,
583 MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)),
584 NULL,
585 "%s%d", dev_list[i].name, j);
586 }
587 }
588
589 if (sound_nblocks >= 1024)
590 printk(KERN_ERR "Sound warning: Deallocation table was too small.\n");
591
592 return 0;
593}
594
595static void __exit oss_cleanup(void)
596{
597 int i, j;
598
599 for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
600 devfs_remove("sound/%s", dev_list[i].name);
601 class_simple_device_remove(MKDEV(SOUND_MAJOR, dev_list[i].minor));
602 if (!dev_list[i].num)
603 continue;
604 for (j = 1; j < *dev_list[i].num; j++) {
605 devfs_remove("sound/%s%d", dev_list[i].name, j);
606 class_simple_device_remove(MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)));
607 }
608 }
609
610 unregister_sound_special(1);
611 unregister_sound_special(8);
612
613 sound_stop_timer();
614
615 sequencer_unload();
616
617 for (i = 0; i < MAX_DMA_CHANNELS; i++)
618 if (dma_alloc_map[i] != DMA_MAP_UNAVAIL) {
619 printk(KERN_ERR "Sound: Hmm, DMA%d was left allocated - fixed\n", i);
620 sound_free_dma(i);
621 }
622
623 for (i = 0; i < sound_nblocks; i++)
624 vfree(sound_mem_blocks[i]);
625
626}
627
628module_init(oss_init);
629module_exit(oss_cleanup);
630MODULE_LICENSE("GPL");
631
632
633int sound_alloc_dma(int chn, char *deviceID)
634{
635 int err;
636
637 if ((err = request_dma(chn, deviceID)) != 0)
638 return err;
639
640 dma_alloc_map[chn] = DMA_MAP_FREE;
641
642 return 0;
643}
644
645int sound_open_dma(int chn, char *deviceID)
646{
647 if (!valid_dma(chn)) {
648 printk(KERN_ERR "sound_open_dma: Invalid DMA channel %d\n", chn);
649 return 1;
650 }
651
652 if (dma_alloc_map[chn] != DMA_MAP_FREE) {
653 printk("sound_open_dma: DMA channel %d busy or not allocated (%d)\n", chn, dma_alloc_map[chn]);
654 return 1;
655 }
656 dma_alloc_map[chn] = DMA_MAP_BUSY;
657 return 0;
658}
659
660void sound_free_dma(int chn)
661{
662 if (dma_alloc_map[chn] == DMA_MAP_UNAVAIL) {
663 /* printk( "sound_free_dma: Bad access to DMA channel %d\n", chn); */
664 return;
665 }
666 free_dma(chn);
667 dma_alloc_map[chn] = DMA_MAP_UNAVAIL;
668}
669
670void sound_close_dma(int chn)
671{
672 if (dma_alloc_map[chn] != DMA_MAP_BUSY) {
673 printk(KERN_ERR "sound_close_dma: Bad access to DMA channel %d\n", chn);
674 return;
675 }
676 dma_alloc_map[chn] = DMA_MAP_FREE;
677}
678
679static void do_sequencer_timer(unsigned long dummy)
680{
681 sequencer_timer(0);
682}
683
684
685static struct timer_list seq_timer =
686 TIMER_INITIALIZER(do_sequencer_timer, 0, 0);
687
688void request_sound_timer(int count)
689{
690 extern unsigned long seq_time;
691
692 if (count < 0) {
693 seq_timer.expires = (-count) + jiffies;
694 add_timer(&seq_timer);
695 return;
696 }
697 count += seq_time;
698
699 count -= jiffies;
700
701 if (count < 1)
702 count = 1;
703
704 seq_timer.expires = (count) + jiffies;
705 add_timer(&seq_timer);
706}
707
708void sound_stop_timer(void)
709{
710 del_timer(&seq_timer);
711}
712
713void conf_printf(char *name, struct address_info *hw_config)
714{
715#ifndef CONFIG_SOUND_TRACEINIT
716 return;
717#else
718 printk("<%s> at 0x%03x", name, hw_config->io_base);
719
720 if (hw_config->irq)
721 printk(" irq %d", (hw_config->irq > 0) ? hw_config->irq : -hw_config->irq);
722
723 if (hw_config->dma != -1 || hw_config->dma2 != -1)
724 {
725 printk(" dma %d", hw_config->dma);
726 if (hw_config->dma2 != -1)
727 printk(",%d", hw_config->dma2);
728 }
729 printk("\n");
730#endif
731}
732
733void conf_printf2(char *name, int base, int irq, int dma, int dma2)
734{
735#ifndef CONFIG_SOUND_TRACEINIT
736 return;
737#else
738 printk("<%s> at 0x%03x", name, base);
739
740 if (irq)
741 printk(" irq %d", (irq > 0) ? irq : -irq);
742
743 if (dma != -1 || dma2 != -1)
744 {
745 printk(" dma %d", dma);
746 if (dma2 != -1)
747 printk(",%d", dma2);
748 }
749 printk("\n");
750#endif
751}
diff --git a/sound/oss/soundvers.h b/sound/oss/soundvers.h
new file mode 100644
index 000000000000..e9084d2f46a9
--- /dev/null
+++ b/sound/oss/soundvers.h
@@ -0,0 +1,2 @@
1#define SOUND_VERSION_STRING "3.8s2++-971130"
2#define SOUND_INTERNAL_VERSION 0x030804
diff --git a/sound/oss/sscape.c b/sound/oss/sscape.c
new file mode 100644
index 000000000000..50ca64629450
--- /dev/null
+++ b/sound/oss/sscape.c
@@ -0,0 +1,1485 @@
1/*
2 * sound/sscape.c
3 *
4 * Low level driver for Ensoniq SoundScape
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 * Sergey Smitienko : ensoniq p'n'p support
16 * Christoph Hellwig : adapted to module_init/module_exit
17 * Bartlomiej Zolnierkiewicz : added __init to attach_sscape()
18 * Chris Rankin : Specify that this module owns the coprocessor
19 * Arnaldo C. de Melo : added missing restore_flags in sscape_pnp_upload_file
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24
25#include "sound_config.h"
26#include "sound_firmware.h"
27
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 <asm/dma.h>
36#include <asm/io.h>
37#include <linux/wait.h>
38#include <linux/slab.h>
39#include <linux/ioport.h>
40#include <linux/delay.h>
41#include <linux/proc_fs.h>
42#include <linux/spinlock.h>
43
44#include "coproc.h"
45
46#include "ad1848.h"
47#include "mpu401.h"
48
49/*
50 * I/O ports
51 */
52#define MIDI_DATA 0
53#define MIDI_CTRL 1
54#define HOST_CTRL 2
55#define TX_READY 0x02
56#define RX_READY 0x01
57#define HOST_DATA 3
58#define ODIE_ADDR 4
59#define ODIE_DATA 5
60
61/*
62 * Indirect registers
63 */
64
65#define GA_INTSTAT_REG 0
66#define GA_INTENA_REG 1
67#define GA_DMAA_REG 2
68#define GA_DMAB_REG 3
69#define GA_INTCFG_REG 4
70#define GA_DMACFG_REG 5
71#define GA_CDCFG_REG 6
72#define GA_SMCFGA_REG 7
73#define GA_SMCFGB_REG 8
74#define GA_HMCTL_REG 9
75
76/*
77 * DMA channel identifiers (A and B)
78 */
79
80#define SSCAPE_DMA_A 0
81#define SSCAPE_DMA_B 1
82
83#define PORT(name) (devc->base+name)
84
85/*
86 * Host commands recognized by the OBP microcode
87 */
88
89#define CMD_GEN_HOST_ACK 0x80
90#define CMD_GEN_MPU_ACK 0x81
91#define CMD_GET_BOARD_TYPE 0x82
92#define CMD_SET_CONTROL 0x88 /* Old firmware only */
93#define CMD_GET_CONTROL 0x89 /* Old firmware only */
94#define CTL_MASTER_VOL 0
95#define CTL_MIC_MODE 2
96#define CTL_SYNTH_VOL 4
97#define CTL_WAVE_VOL 7
98#define CMD_SET_EXTMIDI 0x8a
99#define CMD_GET_EXTMIDI 0x8b
100#define CMD_SET_MT32 0x8c
101#define CMD_GET_MT32 0x8d
102
103#define CMD_ACK 0x80
104
105#define IC_ODIE 1
106#define IC_OPUS 2
107
108typedef struct sscape_info
109{
110 int base, irq, dma;
111
112 int codec, codec_irq; /* required to setup pnp cards*/
113 int codec_type;
114 int ic_type;
115 char* raw_buf;
116 unsigned long raw_buf_phys;
117 int buffsize; /* -------------------------- */
118 spinlock_t lock;
119 int ok; /* Properly detected */
120 int failed;
121 int dma_allocated;
122 int codec_audiodev;
123 int opened;
124 int *osp;
125 int my_audiodev;
126} sscape_info;
127
128static struct sscape_info adev_info = {
129 0
130};
131
132static struct sscape_info *devc = &adev_info;
133static int sscape_mididev = -1;
134
135/* Some older cards have assigned interrupt bits differently than new ones */
136static char valid_interrupts_old[] = {
137 9, 7, 5, 15
138};
139
140static char valid_interrupts_new[] = {
141 9, 5, 7, 10
142};
143
144static char *valid_interrupts = valid_interrupts_new;
145
146/*
147 * See the bottom of the driver. This can be set by spea =0/1.
148 */
149
150#ifdef REVEAL_SPEA
151static char old_hardware = 1;
152#else
153static char old_hardware;
154#endif
155
156static void sleep(unsigned howlong)
157{
158 current->state = TASK_INTERRUPTIBLE;
159 schedule_timeout(howlong);
160}
161
162static unsigned char sscape_read(struct sscape_info *devc, int reg)
163{
164 unsigned long flags;
165 unsigned char val;
166
167 spin_lock_irqsave(&devc->lock,flags);
168 outb(reg, PORT(ODIE_ADDR));
169 val = inb(PORT(ODIE_DATA));
170 spin_unlock_irqrestore(&devc->lock,flags);
171 return val;
172}
173
174static void __sscape_write(int reg, int data)
175{
176 outb(reg, PORT(ODIE_ADDR));
177 outb(data, PORT(ODIE_DATA));
178}
179
180static void sscape_write(struct sscape_info *devc, int reg, int data)
181{
182 unsigned long flags;
183
184 spin_lock_irqsave(&devc->lock,flags);
185 __sscape_write(reg, data);
186 spin_unlock_irqrestore(&devc->lock,flags);
187}
188
189static unsigned char sscape_pnp_read_codec(sscape_info* devc, unsigned char reg)
190{
191 unsigned char res;
192 unsigned long flags;
193
194 spin_lock_irqsave(&devc->lock,flags);
195 outb( reg, devc -> codec);
196 res = inb (devc -> codec + 1);
197 spin_unlock_irqrestore(&devc->lock,flags);
198 return res;
199
200}
201
202static void sscape_pnp_write_codec(sscape_info* devc, unsigned char reg, unsigned char data)
203{
204 unsigned long flags;
205
206 spin_lock_irqsave(&devc->lock,flags);
207 outb( reg, devc -> codec);
208 outb( data, devc -> codec + 1);
209 spin_unlock_irqrestore(&devc->lock,flags);
210}
211
212static void host_open(struct sscape_info *devc)
213{
214 outb((0x00), PORT(HOST_CTRL)); /* Put the board to the host mode */
215}
216
217static void host_close(struct sscape_info *devc)
218{
219 outb((0x03), PORT(HOST_CTRL)); /* Put the board to the MIDI mode */
220}
221
222static int host_write(struct sscape_info *devc, unsigned char *data, int count)
223{
224 unsigned long flags;
225 int i, timeout_val;
226
227 spin_lock_irqsave(&devc->lock,flags);
228 /*
229 * Send the command and data bytes
230 */
231
232 for (i = 0; i < count; i++)
233 {
234 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
235 if (inb(PORT(HOST_CTRL)) & TX_READY)
236 break;
237
238 if (timeout_val <= 0)
239 {
240 spin_unlock_irqrestore(&devc->lock,flags);
241 return 0;
242 }
243 outb(data[i], PORT(HOST_DATA));
244 }
245 spin_unlock_irqrestore(&devc->lock,flags);
246 return 1;
247}
248
249static int host_read(struct sscape_info *devc)
250{
251 unsigned long flags;
252 int timeout_val;
253 unsigned char data;
254
255 spin_lock_irqsave(&devc->lock,flags);
256 /*
257 * Read a byte
258 */
259
260 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
261 if (inb(PORT(HOST_CTRL)) & RX_READY)
262 break;
263
264 if (timeout_val <= 0)
265 {
266 spin_unlock_irqrestore(&devc->lock,flags);
267 return -1;
268 }
269 data = inb(PORT(HOST_DATA));
270 spin_unlock_irqrestore(&devc->lock,flags);
271 return data;
272}
273
274#if 0 /* unused */
275static int host_command1(struct sscape_info *devc, int cmd)
276{
277 unsigned char buf[10];
278 buf[0] = (unsigned char) (cmd & 0xff);
279 return host_write(devc, buf, 1);
280}
281#endif /* unused */
282
283
284static int host_command2(struct sscape_info *devc, int cmd, int parm1)
285{
286 unsigned char buf[10];
287
288 buf[0] = (unsigned char) (cmd & 0xff);
289 buf[1] = (unsigned char) (parm1 & 0xff);
290
291 return host_write(devc, buf, 2);
292}
293
294static int host_command3(struct sscape_info *devc, int cmd, int parm1, int parm2)
295{
296 unsigned char buf[10];
297
298 buf[0] = (unsigned char) (cmd & 0xff);
299 buf[1] = (unsigned char) (parm1 & 0xff);
300 buf[2] = (unsigned char) (parm2 & 0xff);
301 return host_write(devc, buf, 3);
302}
303
304static void set_mt32(struct sscape_info *devc, int value)
305{
306 host_open(devc);
307 host_command2(devc, CMD_SET_MT32, value ? 1 : 0);
308 if (host_read(devc) != CMD_ACK)
309 {
310 /* printk( "SNDSCAPE: Setting MT32 mode failed\n"); */
311 }
312 host_close(devc);
313}
314
315static void set_control(struct sscape_info *devc, int ctrl, int value)
316{
317 host_open(devc);
318 host_command3(devc, CMD_SET_CONTROL, ctrl, value);
319 if (host_read(devc) != CMD_ACK)
320 {
321 /* printk( "SNDSCAPE: Setting control (%d) failed\n", ctrl); */
322 }
323 host_close(devc);
324}
325
326static void do_dma(struct sscape_info *devc, int dma_chan, unsigned long buf, int blk_size, int mode)
327{
328 unsigned char temp;
329
330 if (dma_chan != SSCAPE_DMA_A)
331 {
332 printk(KERN_WARNING "soundscape: Tried to use DMA channel != A. Why?\n");
333 return;
334 }
335 audio_devs[devc->codec_audiodev]->flags &= ~DMA_AUTOMODE;
336 DMAbuf_start_dma(devc->codec_audiodev, buf, blk_size, mode);
337 audio_devs[devc->codec_audiodev]->flags |= DMA_AUTOMODE;
338
339 temp = devc->dma << 4; /* Setup DMA channel select bits */
340 if (devc->dma <= 3)
341 temp |= 0x80; /* 8 bit DMA channel */
342
343 temp |= 1; /* Trigger DMA */
344 sscape_write(devc, GA_DMAA_REG, temp);
345 temp &= 0xfe; /* Clear DMA trigger */
346 sscape_write(devc, GA_DMAA_REG, temp);
347}
348
349static int verify_mpu(struct sscape_info *devc)
350{
351 /*
352 * The SoundScape board could be in three modes (MPU, 8250 and host).
353 * If the card is not in the MPU mode, enabling the MPU driver will
354 * cause infinite loop (the driver believes that there is always some
355 * received data in the buffer.
356 *
357 * Detect this by looking if there are more than 10 received MIDI bytes
358 * (0x00) in the buffer.
359 */
360
361 int i;
362
363 for (i = 0; i < 10; i++)
364 {
365 if (inb(devc->base + HOST_CTRL) & 0x80)
366 return 1;
367
368 if (inb(devc->base) != 0x00)
369 return 1;
370 }
371 printk(KERN_WARNING "SoundScape: The device is not in the MPU-401 mode\n");
372 return 0;
373}
374
375static int sscape_coproc_open(void *dev_info, int sub_device)
376{
377 if (sub_device == COPR_MIDI)
378 {
379 set_mt32(devc, 0);
380 if (!verify_mpu(devc))
381 return -EIO;
382 }
383 return 0;
384}
385
386static void sscape_coproc_close(void *dev_info, int sub_device)
387{
388 struct sscape_info *devc = dev_info;
389 unsigned long flags;
390
391 spin_lock_irqsave(&devc->lock,flags);
392 if (devc->dma_allocated)
393 {
394 __sscape_write(GA_DMAA_REG, 0x20); /* DMA channel disabled */
395 devc->dma_allocated = 0;
396 }
397 spin_unlock_irqrestore(&devc->lock,flags);
398 return;
399}
400
401static void sscape_coproc_reset(void *dev_info)
402{
403}
404
405static int sscape_download_boot(struct sscape_info *devc, unsigned char *block, int size, int flag)
406{
407 unsigned long flags;
408 unsigned char temp;
409 volatile int done, timeout_val;
410 static unsigned char codec_dma_bits;
411
412 if (flag & CPF_FIRST)
413 {
414 /*
415 * First block. Have to allocate DMA and to reset the board
416 * before continuing.
417 */
418
419 spin_lock_irqsave(&devc->lock,flags);
420 codec_dma_bits = sscape_read(devc, GA_CDCFG_REG);
421
422 if (devc->dma_allocated == 0)
423 devc->dma_allocated = 1;
424
425 spin_unlock_irqrestore(&devc->lock,flags);
426
427 sscape_write(devc, GA_HMCTL_REG,
428 (temp = sscape_read(devc, GA_HMCTL_REG)) & 0x3f); /*Reset */
429
430 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
431 sscape_read(devc, GA_HMCTL_REG); /* Delay */
432
433 /* Take board out of reset */
434 sscape_write(devc, GA_HMCTL_REG,
435 (temp = sscape_read(devc, GA_HMCTL_REG)) | 0x80);
436 }
437 /*
438 * Transfer one code block using DMA
439 */
440 if (audio_devs[devc->codec_audiodev]->dmap_out->raw_buf == NULL)
441 {
442 printk(KERN_WARNING "soundscape: DMA buffer not available\n");
443 return 0;
444 }
445 memcpy(audio_devs[devc->codec_audiodev]->dmap_out->raw_buf, block, size);
446
447 spin_lock_irqsave(&devc->lock,flags);
448
449 /******** INTERRUPTS DISABLED NOW ********/
450
451 do_dma(devc, SSCAPE_DMA_A,
452 audio_devs[devc->codec_audiodev]->dmap_out->raw_buf_phys,
453 size, DMA_MODE_WRITE);
454
455 /*
456 * Wait until transfer completes.
457 */
458
459 done = 0;
460 timeout_val = 30;
461 while (!done && timeout_val-- > 0)
462 {
463 int resid;
464
465 if (HZ / 50)
466 sleep(HZ / 50);
467 clear_dma_ff(devc->dma);
468 if ((resid = get_dma_residue(devc->dma)) == 0)
469 done = 1;
470 }
471
472 spin_unlock_irqrestore(&devc->lock,flags);
473 if (!done)
474 return 0;
475
476 if (flag & CPF_LAST)
477 {
478 /*
479 * Take the board out of reset
480 */
481 outb((0x00), PORT(HOST_CTRL));
482 outb((0x00), PORT(MIDI_CTRL));
483
484 temp = sscape_read(devc, GA_HMCTL_REG);
485 temp |= 0x40;
486 sscape_write(devc, GA_HMCTL_REG, temp); /* Kickstart the board */
487
488 /*
489 * Wait until the ODB wakes up
490 */
491 spin_lock_irqsave(&devc->lock,flags);
492 done = 0;
493 timeout_val = 5 * HZ;
494 while (!done && timeout_val-- > 0)
495 {
496 unsigned char x;
497
498 sleep(1);
499 x = inb(PORT(HOST_DATA));
500 if (x == 0xff || x == 0xfe) /* OBP startup acknowledge */
501 {
502 DDB(printk("Soundscape: Acknowledge = %x\n", x));
503 done = 1;
504 }
505 }
506 sscape_write(devc, GA_CDCFG_REG, codec_dma_bits);
507
508 spin_unlock_irqrestore(&devc->lock,flags);
509 if (!done)
510 {
511 printk(KERN_ERR "soundscape: The OBP didn't respond after code download\n");
512 return 0;
513 }
514 spin_lock_irqsave(&devc->lock,flags);
515 done = 0;
516 timeout_val = 5 * HZ;
517 while (!done && timeout_val-- > 0)
518 {
519 sleep(1);
520 if (inb(PORT(HOST_DATA)) == 0xfe) /* Host startup acknowledge */
521 done = 1;
522 }
523 spin_unlock_irqrestore(&devc->lock,flags);
524 if (!done)
525 {
526 printk(KERN_ERR "soundscape: OBP Initialization failed.\n");
527 return 0;
528 }
529 printk(KERN_INFO "SoundScape board initialized OK\n");
530 set_control(devc, CTL_MASTER_VOL, 100);
531 set_control(devc, CTL_SYNTH_VOL, 100);
532
533#ifdef SSCAPE_DEBUG3
534 /*
535 * Temporary debugging aid. Print contents of the registers after
536 * downloading the code.
537 */
538 {
539 int i;
540
541 for (i = 0; i < 13; i++)
542 printk("I%d = %02x (new value)\n", i, sscape_read(devc, i));
543 }
544#endif
545
546 }
547 return 1;
548}
549
550static int download_boot_block(void *dev_info, copr_buffer * buf)
551{
552 if (buf->len <= 0 || buf->len > sizeof(buf->data))
553 return -EINVAL;
554
555 if (!sscape_download_boot(devc, buf->data, buf->len, buf->flags))
556 {
557 printk(KERN_ERR "soundscape: Unable to load microcode block to the OBP.\n");
558 return -EIO;
559 }
560 return 0;
561}
562
563static int sscape_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
564{
565 copr_buffer *buf;
566 int err;
567
568 switch (cmd)
569 {
570 case SNDCTL_COPR_RESET:
571 sscape_coproc_reset(dev_info);
572 return 0;
573
574 case SNDCTL_COPR_LOAD:
575 buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
576 if (buf == NULL)
577 return -ENOSPC;
578 if (copy_from_user(buf, arg, sizeof(copr_buffer)))
579 {
580 vfree(buf);
581 return -EFAULT;
582 }
583 err = download_boot_block(dev_info, buf);
584 vfree(buf);
585 return err;
586
587 default:
588 return -EINVAL;
589 }
590}
591
592static coproc_operations sscape_coproc_operations =
593{
594 "SoundScape M68K",
595 THIS_MODULE,
596 sscape_coproc_open,
597 sscape_coproc_close,
598 sscape_coproc_ioctl,
599 sscape_coproc_reset,
600 &adev_info
601};
602
603static struct resource *sscape_ports;
604static int sscape_is_pnp;
605
606static void __init attach_sscape(struct address_info *hw_config)
607{
608#ifndef SSCAPE_REGS
609 /*
610 * Config register values for Spea/V7 Media FX and Ensoniq S-2000.
611 * These values are card
612 * dependent. If you have another SoundScape based card, you have to
613 * find the correct values. Do the following:
614 * - Compile this driver with SSCAPE_DEBUG1 defined.
615 * - Shut down and power off your machine.
616 * - Boot with DOS so that the SSINIT.EXE program is run.
617 * - Warm boot to {Linux|SYSV|BSD} and write down the lines displayed
618 * when detecting the SoundScape.
619 * - Modify the following list to use the values printed during boot.
620 * Undefine the SSCAPE_DEBUG1
621 */
622#define SSCAPE_REGS { \
623/* I0 */ 0x00, \
624/* I1 */ 0xf0, /* Note! Ignored. Set always to 0xf0 */ \
625/* I2 */ 0x20, /* Note! Ignored. Set always to 0x20 */ \
626/* I3 */ 0x20, /* Note! Ignored. Set always to 0x20 */ \
627/* I4 */ 0xf5, /* Ignored */ \
628/* I5 */ 0x10, \
629/* I6 */ 0x00, \
630/* I7 */ 0x2e, /* I7 MEM config A. Likely to vary between models */ \
631/* I8 */ 0x00, /* I8 MEM config B. Likely to vary between models */ \
632/* I9 */ 0x40 /* Ignored */ \
633 }
634#endif
635
636 unsigned long flags;
637 static unsigned char regs[10] = SSCAPE_REGS;
638
639 int i, irq_bits = 0xff;
640
641 if (old_hardware)
642 {
643 valid_interrupts = valid_interrupts_old;
644 conf_printf("Ensoniq SoundScape (old)", hw_config);
645 }
646 else
647 conf_printf("Ensoniq SoundScape", hw_config);
648
649 for (i = 0; i < 4; i++)
650 {
651 if (hw_config->irq == valid_interrupts[i])
652 {
653 irq_bits = i;
654 break;
655 }
656 }
657 if (hw_config->irq > 15 || (regs[4] = irq_bits == 0xff))
658 {
659 printk(KERN_ERR "Invalid IRQ%d\n", hw_config->irq);
660 release_region(devc->base, 2);
661 release_region(devc->base + 2, 6);
662 if (sscape_is_pnp)
663 release_region(devc->codec, 2);
664 return;
665 }
666
667 if (!sscape_is_pnp) {
668
669 spin_lock_irqsave(&devc->lock,flags);
670 /* Host interrupt enable */
671 sscape_write(devc, 1, 0xf0); /* All interrupts enabled */
672 /* DMA A status/trigger register */
673 sscape_write(devc, 2, 0x20); /* DMA channel disabled */
674 /* DMA B status/trigger register */
675 sscape_write(devc, 3, 0x20); /* DMA channel disabled */
676 /* Host interrupt config reg */
677 sscape_write(devc, 4, 0xf0 | (irq_bits << 2) | irq_bits);
678 /* Don't destroy CD-ROM DMA config bits (0xc0) */
679 sscape_write(devc, 5, (regs[5] & 0x3f) | (sscape_read(devc, 5) & 0xc0));
680 /* CD-ROM config (WSS codec actually) */
681 sscape_write(devc, 6, regs[6]);
682 sscape_write(devc, 7, regs[7]);
683 sscape_write(devc, 8, regs[8]);
684 /* Master control reg. Don't modify CR-ROM bits. Disable SB emul */
685 sscape_write(devc, 9, (sscape_read(devc, 9) & 0xf0) | 0x08);
686 spin_unlock_irqrestore(&devc->lock,flags);
687 }
688#ifdef SSCAPE_DEBUG2
689 /*
690 * Temporary debugging aid. Print contents of the registers after
691 * changing them.
692 */
693 {
694 int i;
695
696 for (i = 0; i < 13; i++)
697 printk("I%d = %02x (new value)\n", i, sscape_read(devc, i));
698 }
699#endif
700
701 if (probe_mpu401(hw_config, sscape_ports))
702 hw_config->always_detect = 1;
703 hw_config->name = "SoundScape";
704
705 hw_config->irq *= -1; /* Negative value signals IRQ sharing */
706 attach_mpu401(hw_config, THIS_MODULE);
707 hw_config->irq *= -1; /* Restore it */
708
709 if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
710 {
711 sscape_mididev = hw_config->slots[1];
712 midi_devs[hw_config->slots[1]]->coproc = &sscape_coproc_operations;
713 }
714 sscape_write(devc, GA_INTENA_REG, 0x80); /* Master IRQ enable */
715 devc->ok = 1;
716 devc->failed = 0;
717}
718
719static int detect_ga(sscape_info * devc)
720{
721 unsigned char save;
722
723 DDB(printk("Entered Soundscape detect_ga(%x)\n", devc->base));
724
725 /*
726 * First check that the address register of "ODIE" is
727 * there and that it has exactly 4 writable bits.
728 * First 4 bits
729 */
730
731 if ((save = inb(PORT(ODIE_ADDR))) & 0xf0)
732 {
733 DDB(printk("soundscape: Detect error A\n"));
734 return 0;
735 }
736 outb((0x00), PORT(ODIE_ADDR));
737 if (inb(PORT(ODIE_ADDR)) != 0x00)
738 {
739 DDB(printk("soundscape: Detect error B\n"));
740 return 0;
741 }
742 outb((0xff), PORT(ODIE_ADDR));
743 if (inb(PORT(ODIE_ADDR)) != 0x0f)
744 {
745 DDB(printk("soundscape: Detect error C\n"));
746 return 0;
747 }
748 outb((save), PORT(ODIE_ADDR));
749
750 /*
751 * Now verify that some indirect registers return zero on some bits.
752 * This may break the driver with some future revisions of "ODIE" but...
753 */
754
755 if (sscape_read(devc, 0) & 0x0c)
756 {
757 DDB(printk("soundscape: Detect error D (%x)\n", sscape_read(devc, 0)));
758 return 0;
759 }
760 if (sscape_read(devc, 1) & 0x0f)
761 {
762 DDB(printk("soundscape: Detect error E\n"));
763 return 0;
764 }
765 if (sscape_read(devc, 5) & 0x0f)
766 {
767 DDB(printk("soundscape: Detect error F\n"));
768 return 0;
769 }
770 return 1;
771}
772
773static int sscape_read_host_ctrl(sscape_info* devc)
774{
775 return host_read(devc);
776}
777
778static void sscape_write_host_ctrl2(sscape_info *devc, int a, int b)
779{
780 host_command2(devc, a, b);
781}
782
783static int sscape_alloc_dma(sscape_info *devc)
784{
785 char *start_addr, *end_addr;
786 int dma_pagesize;
787 int sz, size;
788 struct page *page;
789
790 if (devc->raw_buf != NULL) return 0; /* Already done */
791 dma_pagesize = (devc->dma < 4) ? (64 * 1024) : (128 * 1024);
792 devc->raw_buf = NULL;
793 devc->buffsize = 8192*4;
794 if (devc->buffsize > dma_pagesize) devc->buffsize = dma_pagesize;
795 start_addr = NULL;
796 /*
797 * Now loop until we get a free buffer. Try to get smaller buffer if
798 * it fails. Don't accept smaller than 8k buffer for performance
799 * reasons.
800 */
801 while (start_addr == NULL && devc->buffsize > PAGE_SIZE) {
802 for (sz = 0, size = PAGE_SIZE; size < devc->buffsize; sz++, size <<= 1);
803 devc->buffsize = PAGE_SIZE * (1 << sz);
804 start_addr = (char *) __get_free_pages(GFP_ATOMIC|GFP_DMA, sz);
805 if (start_addr == NULL) devc->buffsize /= 2;
806 }
807
808 if (start_addr == NULL) {
809 printk(KERN_ERR "sscape pnp init error: Couldn't allocate DMA buffer\n");
810 return 0;
811 } else {
812 /* make some checks */
813 end_addr = start_addr + devc->buffsize - 1;
814 /* now check if it fits into the same dma-pagesize */
815
816 if (((long) start_addr & ~(dma_pagesize - 1)) != ((long) end_addr & ~(dma_pagesize - 1))
817 || end_addr >= (char *) (MAX_DMA_ADDRESS)) {
818 printk(KERN_ERR "sscape pnp: Got invalid address 0x%lx for %db DMA-buffer\n", (long) start_addr, devc->buffsize);
819 return 0;
820 }
821 }
822 devc->raw_buf = start_addr;
823 devc->raw_buf_phys = virt_to_bus(start_addr);
824
825 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
826 SetPageReserved(page);
827 return 1;
828}
829
830static void sscape_free_dma(sscape_info *devc)
831{
832 int sz, size;
833 unsigned long start_addr, end_addr;
834 struct page *page;
835
836 if (devc->raw_buf == NULL) return;
837 for (sz = 0, size = PAGE_SIZE; size < devc->buffsize; sz++, size <<= 1);
838 start_addr = (unsigned long) devc->raw_buf;
839 end_addr = start_addr + devc->buffsize;
840
841 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
842 ClearPageReserved(page);
843
844 free_pages((unsigned long) devc->raw_buf, sz);
845 devc->raw_buf = NULL;
846}
847
848/* Intel version !!!!!!!!! */
849
850static int sscape_start_dma(int chan, unsigned long physaddr, int count, int dma_mode)
851{
852 unsigned long flags;
853
854 flags = claim_dma_lock();
855 disable_dma(chan);
856 clear_dma_ff(chan);
857 set_dma_mode(chan, dma_mode);
858 set_dma_addr(chan, physaddr);
859 set_dma_count(chan, count);
860 enable_dma(chan);
861 release_dma_lock(flags);
862 return 0;
863}
864
865static void sscape_pnp_start_dma(sscape_info* devc, int arg )
866{
867 int reg;
868 if (arg == 0) reg = 2;
869 else reg = 3;
870
871 sscape_write(devc, reg, sscape_read( devc, reg) | 0x01);
872 sscape_write(devc, reg, sscape_read( devc, reg) & 0xFE);
873}
874
875static int sscape_pnp_wait_dma (sscape_info* devc, int arg )
876{
877 int reg;
878 unsigned long i;
879 unsigned char d;
880
881 if (arg == 0) reg = 2;
882 else reg = 3;
883
884 sleep ( 1 );
885 i = 0;
886 do {
887 d = sscape_read(devc, reg) & 1;
888 if ( d == 1) break;
889 i++;
890 } while (i < 500000);
891 d = sscape_read(devc, reg) & 1;
892 return d;
893}
894
895static int sscape_pnp_alloc_dma(sscape_info* devc)
896{
897 /* printk(KERN_INFO "sscape: requesting dma\n"); */
898 if (request_dma(devc -> dma, "sscape")) return 0;
899 /* printk(KERN_INFO "sscape: dma channel allocated\n"); */
900 if (!sscape_alloc_dma(devc)) {
901 free_dma(devc -> dma);
902 return 0;
903 };
904 return 1;
905}
906
907static void sscape_pnp_free_dma(sscape_info* devc)
908{
909 sscape_free_dma( devc);
910 free_dma(devc -> dma );
911 /* printk(KERN_INFO "sscape: dma released\n"); */
912}
913
914static int sscape_pnp_upload_file(sscape_info* devc, char* fn)
915{
916 int done = 0;
917 int timeout_val;
918 char* data,*dt;
919 int len,l;
920 unsigned long flags;
921
922 sscape_write( devc, 9, sscape_read(devc, 9 ) & 0x3F );
923 sscape_write( devc, 2, (devc -> dma << 4) | 0x80 );
924 sscape_write( devc, 3, 0x20 );
925 sscape_write( devc, 9, sscape_read( devc, 9 ) | 0x80 );
926
927 len = mod_firmware_load(fn, &data);
928 if (len == 0) {
929 printk(KERN_ERR "sscape: file not found: %s\n", fn);
930 return 0;
931 }
932 dt = data;
933 spin_lock_irqsave(&devc->lock,flags);
934 while ( len > 0 ) {
935 if (len > devc -> buffsize) l = devc->buffsize;
936 else l = len;
937 len -= l;
938 memcpy(devc->raw_buf, dt, l); dt += l;
939 sscape_start_dma(devc->dma, devc->raw_buf_phys, l, 0x48);
940 sscape_pnp_start_dma ( devc, 0 );
941 if (sscape_pnp_wait_dma ( devc, 0 ) == 0) {
942 spin_unlock_irqrestore(&devc->lock,flags);
943 return 0;
944 }
945 }
946
947 spin_unlock_irqrestore(&devc->lock,flags);
948 vfree(data);
949
950 outb(0, devc -> base + 2);
951 outb(0, devc -> base);
952
953 sscape_write ( devc, 9, sscape_read( devc, 9 ) | 0x40);
954
955 timeout_val = 5 * HZ;
956 while (!done && timeout_val-- > 0)
957 {
958 unsigned char x;
959 sleep(1);
960 x = inb( devc -> base + 3);
961 if (x == 0xff || x == 0xfe) /* OBP startup acknowledge */
962 {
963 //printk(KERN_ERR "Soundscape: Acknowledge = %x\n", x);
964 done = 1;
965 }
966 }
967 timeout_val = 5 * HZ;
968 done = 0;
969 while (!done && timeout_val-- > 0)
970 {
971 unsigned char x;
972 sleep(1);
973 x = inb( devc -> base + 3);
974 if (x == 0xfe) /* OBP startup acknowledge */
975 {
976 //printk(KERN_ERR "Soundscape: Acknowledge = %x\n", x);
977 done = 1;
978 }
979 }
980
981 if ( !done ) printk(KERN_ERR "soundscape: OBP Initialization failed.\n");
982
983 sscape_write( devc, 2, devc->ic_type == IC_ODIE ? 0x70 : 0x40);
984 sscape_write( devc, 3, (devc -> dma << 4) + 0x80);
985 return 1;
986}
987
988static void __init sscape_pnp_init_hw(sscape_info* devc)
989{
990 unsigned char midi_irq = 0, sb_irq = 0;
991 unsigned i;
992 static char code_file_name[23] = "/sndscape/sndscape.cox";
993
994 int sscape_sb_enable = 0;
995 int sscape_joystic_enable = 0x7f;
996 int sscape_mic_enable = 0;
997 int sscape_ext_midi = 0;
998
999 if ( !sscape_pnp_alloc_dma(devc) ) {
1000 printk(KERN_ERR "sscape: faild to allocate dma\n");
1001 return;
1002 }
1003
1004 for (i = 0; i < 4; i++) {
1005 if ( devc -> irq == valid_interrupts[i] )
1006 midi_irq = i;
1007 if ( devc -> codec_irq == valid_interrupts[i] )
1008 sb_irq = i;
1009 }
1010
1011 sscape_write( devc, 5, 0x50);
1012 sscape_write( devc, 7, 0x2e);
1013 sscape_write( devc, 8, 0x00);
1014
1015 sscape_write( devc, 2, devc->ic_type == IC_ODIE ? 0x70 : 0x40);
1016 sscape_write( devc, 3, ( devc -> dma << 4) | 0x80);
1017
1018 if ( sscape_sb_enable )
1019 sscape_write (devc, 4, 0xF0 | (sb_irq << 2) | midi_irq);
1020 else
1021 sscape_write (devc, 4, 0xF0 | (midi_irq<<2) | midi_irq);
1022
1023 i = 0x10; //sscape_read(devc, 9) & (devc->ic_type == IC_ODIE ? 0xf0 : 0xc0);
1024 if ( sscape_sb_enable )
1025 i |= devc->ic_type == IC_ODIE ? 0x05 : 0x07;
1026 if (sscape_joystic_enable) i |= 8;
1027
1028 sscape_write (devc, 9, i);
1029 sscape_write (devc, 6, 0x80);
1030 sscape_write (devc, 1, 0x80);
1031
1032 if (devc -> codec_type == 2) {
1033 sscape_pnp_write_codec( devc, 0x0C, 0x50);
1034 sscape_pnp_write_codec( devc, 0x10, sscape_pnp_read_codec( devc, 0x10) & 0x3F);
1035 sscape_pnp_write_codec( devc, 0x11, sscape_pnp_read_codec( devc, 0x11) | 0xC0);
1036 sscape_pnp_write_codec( devc, 29, 0x20);
1037 }
1038
1039 if (sscape_pnp_upload_file(devc, "/sndscape/scope.cod") == 0 ) {
1040 printk(KERN_ERR "sscape: faild to upload file /sndscape/scope.cod\n");
1041 sscape_pnp_free_dma(devc);
1042 return;
1043 }
1044
1045 i = sscape_read_host_ctrl( devc );
1046
1047 if ( (i & 0x0F) > 7 ) {
1048 printk(KERN_ERR "sscape: scope.cod faild\n");
1049 sscape_pnp_free_dma(devc);
1050 return;
1051 }
1052 if ( i & 0x10 ) sscape_write( devc, 7, 0x2F);
1053 code_file_name[21] = (char) ( i & 0x0F) + 0x30;
1054 if (sscape_pnp_upload_file( devc, code_file_name) == 0) {
1055 printk(KERN_ERR "sscape: faild to upload file %s\n", code_file_name);
1056 sscape_pnp_free_dma(devc);
1057 return;
1058 }
1059
1060 if (devc->ic_type != IC_ODIE) {
1061 sscape_pnp_write_codec( devc, 10, (sscape_pnp_read_codec(devc, 10) & 0x7f) |
1062 ( sscape_mic_enable == 0 ? 0x00 : 0x80) );
1063 }
1064 sscape_write_host_ctrl2( devc, 0x84, 0x64 ); /* MIDI volume */
1065 sscape_write_host_ctrl2( devc, 0x86, 0x64 ); /* MIDI volume?? */
1066 sscape_write_host_ctrl2( devc, 0x8A, sscape_ext_midi);
1067
1068 sscape_pnp_write_codec ( devc, 6, 0x3f ); //WAV_VOL
1069 sscape_pnp_write_codec ( devc, 7, 0x3f ); //WAV_VOL
1070 sscape_pnp_write_codec ( devc, 2, 0x1F ); //WD_CDXVOLL
1071 sscape_pnp_write_codec ( devc, 3, 0x1F ); //WD_CDXVOLR
1072
1073 if (devc -> codec_type == 1) {
1074 sscape_pnp_write_codec ( devc, 4, 0x1F );
1075 sscape_pnp_write_codec ( devc, 5, 0x1F );
1076 sscape_write_host_ctrl2( devc, 0x88, sscape_mic_enable);
1077 } else {
1078 int t;
1079 sscape_pnp_write_codec ( devc, 0x10, 0x1F << 1);
1080 sscape_pnp_write_codec ( devc, 0x11, 0xC0 | (0x1F << 1));
1081
1082 t = sscape_pnp_read_codec( devc, 0x00) & 0xDF;
1083 if ( (sscape_mic_enable == 0)) t |= 0;
1084 else t |= 0x20;
1085 sscape_pnp_write_codec ( devc, 0x00, t);
1086 t = sscape_pnp_read_codec( devc, 0x01) & 0xDF;
1087 if ( (sscape_mic_enable == 0) ) t |= 0;
1088 else t |= 0x20;
1089 sscape_pnp_write_codec ( devc, 0x01, t);
1090 sscape_pnp_write_codec ( devc, 0x40 | 29 , 0x20);
1091 outb(0, devc -> codec);
1092 }
1093 if (devc -> ic_type == IC_OPUS ) {
1094 int i = sscape_read( devc, 9 );
1095 sscape_write( devc, 9, i | 3 );
1096 sscape_write( devc, 3, 0x40);
1097
1098 if (request_region(0x228, 1, "sscape setup junk")) {
1099 outb(0, 0x228);
1100 release_region(0x228,1);
1101 }
1102 sscape_write( devc, 3, (devc -> dma << 4) | 0x80);
1103 sscape_write( devc, 9, i );
1104 }
1105
1106 host_close ( devc );
1107 sscape_pnp_free_dma(devc);
1108}
1109
1110static int __init detect_sscape_pnp(sscape_info* devc)
1111{
1112 long i, irq_bits = 0xff;
1113 unsigned int d;
1114
1115 DDB(printk("Entered detect_sscape_pnp(%x)\n", devc->base));
1116
1117 if (!request_region(devc->codec, 2, "sscape codec")) {
1118 printk(KERN_ERR "detect_sscape_pnp: port %x is not free\n", devc->codec);
1119 return 0;
1120 }
1121
1122 if ((inb(devc->base + 2) & 0x78) != 0)
1123 goto fail;
1124
1125 d = inb ( devc -> base + 4) & 0xF0;
1126 if (d & 0x80)
1127 goto fail;
1128
1129 if (d == 0) {
1130 devc->codec_type = 1;
1131 devc->ic_type = IC_ODIE;
1132 } else if ( (d & 0x60) != 0) {
1133 devc->codec_type = 2;
1134 devc->ic_type = IC_OPUS;
1135 } else if ( (d & 0x40) != 0) { /* WTF? */
1136 devc->codec_type = 2;
1137 devc->ic_type = IC_ODIE;
1138 } else
1139 goto fail;
1140
1141 sscape_is_pnp = 1;
1142
1143 outb(0xFA, devc -> base+4);
1144 if ((inb( devc -> base+4) & 0x9F) != 0x0A)
1145 goto fail;
1146 outb(0xFE, devc -> base+4);
1147 if ( (inb(devc -> base+4) & 0x9F) != 0x0E)
1148 goto fail;
1149 if ( (inb(devc -> base+5) & 0x9F) != 0x0E)
1150 goto fail;
1151
1152 if (devc->codec_type == 2) {
1153 if (devc->codec != devc->base + 8) {
1154 printk("soundscape warning: incorrect codec port specified\n");
1155 goto fail;
1156 }
1157 d = 0x10 | (sscape_read(devc, 9) & 0xCF);
1158 sscape_write(devc, 9, d);
1159 sscape_write(devc, 6, 0x80);
1160 } else {
1161 //todo: check codec is not base + 8
1162 }
1163
1164 d = (sscape_read(devc, 9) & 0x3F) | 0xC0;
1165 sscape_write(devc, 9, d);
1166
1167 for (i = 0; i < 550000; i++)
1168 if ( !(inb(devc -> codec) & 0x80) ) break;
1169
1170 d = inb(devc -> codec);
1171 if (d & 0x80)
1172 goto fail;
1173 if ( inb(devc -> codec + 2) == 0xFF)
1174 goto fail;
1175
1176 sscape_write(devc, 9, sscape_read(devc, 9) & 0x3F );
1177
1178 d = inb(devc -> codec) & 0x80;
1179 if ( d == 0) {
1180 printk(KERN_INFO "soundscape: hardware detected\n");
1181 valid_interrupts = valid_interrupts_new;
1182 } else {
1183 printk(KERN_INFO "soundscape: board looks like media fx\n");
1184 valid_interrupts = valid_interrupts_old;
1185 old_hardware = 1;
1186 }
1187
1188 sscape_write( devc, 9, 0xC0 | (sscape_read(devc, 9) & 0x3F) );
1189
1190 for (i = 0; i < 550000; i++)
1191 if ( !(inb(devc -> codec) & 0x80))
1192 break;
1193
1194 sscape_pnp_init_hw(devc);
1195
1196 for (i = 0; i < 4; i++)
1197 {
1198 if (devc->codec_irq == valid_interrupts[i]) {
1199 irq_bits = i;
1200 break;
1201 }
1202 }
1203 sscape_write(devc, GA_INTENA_REG, 0x00);
1204 sscape_write(devc, GA_DMACFG_REG, 0x50);
1205 sscape_write(devc, GA_DMAA_REG, 0x70);
1206 sscape_write(devc, GA_DMAB_REG, 0x20);
1207 sscape_write(devc, GA_INTCFG_REG, 0xf0);
1208 sscape_write(devc, GA_CDCFG_REG, 0x89 | (devc->dma << 4) | (irq_bits << 1));
1209
1210 sscape_pnp_write_codec( devc, 0, sscape_pnp_read_codec( devc, 0) | 0x20);
1211 sscape_pnp_write_codec( devc, 0, sscape_pnp_read_codec( devc, 1) | 0x20);
1212
1213 return 1;
1214fail:
1215 release_region(devc->codec, 2);
1216 return 0;
1217}
1218
1219static int __init probe_sscape(struct address_info *hw_config)
1220{
1221 devc->base = hw_config->io_base;
1222 devc->irq = hw_config->irq;
1223 devc->dma = hw_config->dma;
1224 devc->osp = hw_config->osp;
1225
1226#ifdef SSCAPE_DEBUG1
1227 /*
1228 * Temporary debugging aid. Print contents of the registers before
1229 * changing them.
1230 */
1231 {
1232 int i;
1233
1234 for (i = 0; i < 13; i++)
1235 printk("I%d = %02x (old value)\n", i, sscape_read(devc, i));
1236 }
1237#endif
1238 devc->failed = 1;
1239
1240 sscape_ports = request_region(devc->base, 2, "mpu401");
1241 if (!sscape_ports)
1242 return 0;
1243
1244 if (!request_region(devc->base + 2, 6, "SoundScape")) {
1245 release_region(devc->base, 2);
1246 return 0;
1247 }
1248
1249 if (!detect_ga(devc)) {
1250 if (detect_sscape_pnp(devc))
1251 return 1;
1252 release_region(devc->base, 2);
1253 release_region(devc->base + 2, 6);
1254 return 0;
1255 }
1256
1257 if (old_hardware) /* Check that it's really an old Spea/Reveal card. */
1258 {
1259 unsigned char tmp;
1260 int cc;
1261
1262 if (!((tmp = sscape_read(devc, GA_HMCTL_REG)) & 0xc0))
1263 {
1264 sscape_write(devc, GA_HMCTL_REG, tmp | 0x80);
1265 for (cc = 0; cc < 200000; ++cc)
1266 inb(devc->base + ODIE_ADDR);
1267 }
1268 }
1269 return 1;
1270}
1271
1272static int __init init_ss_ms_sound(struct address_info *hw_config)
1273{
1274 int i, irq_bits = 0xff;
1275 int ad_flags = 0;
1276 struct resource *ports;
1277
1278 if (devc->failed)
1279 {
1280 printk(KERN_ERR "soundscape: Card not detected\n");
1281 return 0;
1282 }
1283 if (devc->ok == 0)
1284 {
1285 printk(KERN_ERR "soundscape: Invalid initialization order.\n");
1286 return 0;
1287 }
1288 for (i = 0; i < 4; i++)
1289 {
1290 if (hw_config->irq == valid_interrupts[i])
1291 {
1292 irq_bits = i;
1293 break;
1294 }
1295 }
1296 if (irq_bits == 0xff) {
1297 printk(KERN_ERR "soundscape: Invalid MSS IRQ%d\n", hw_config->irq);
1298 return 0;
1299 }
1300
1301 if (old_hardware)
1302 ad_flags = 0x12345677; /* Tell that we may have a CS4248 chip (Spea-V7 Media FX) */
1303 else if (sscape_is_pnp)
1304 ad_flags = 0x87654321; /* Tell that we have a soundscape pnp with 1845 chip */
1305
1306 ports = request_region(hw_config->io_base, 4, "ad1848");
1307 if (!ports) {
1308 printk(KERN_ERR "soundscape: ports busy\n");
1309 return 0;
1310 }
1311
1312 if (!ad1848_detect(ports, &ad_flags, hw_config->osp)) {
1313 release_region(hw_config->io_base, 4);
1314 return 0;
1315 }
1316
1317 if (!sscape_is_pnp) /*pnp is already setup*/
1318 {
1319 /*
1320 * Setup the DMA polarity.
1321 */
1322 sscape_write(devc, GA_DMACFG_REG, 0x50);
1323
1324 /*
1325 * Take the gate-array off of the DMA channel.
1326 */
1327 sscape_write(devc, GA_DMAB_REG, 0x20);
1328
1329 /*
1330 * Init the AD1848 (CD-ROM) config reg.
1331 */
1332 sscape_write(devc, GA_CDCFG_REG, 0x89 | (hw_config->dma << 4) | (irq_bits << 1));
1333 }
1334
1335 if (hw_config->irq == devc->irq)
1336 printk(KERN_WARNING "soundscape: Warning! The WSS mode can't share IRQ with MIDI\n");
1337
1338 hw_config->slots[0] = ad1848_init(
1339 sscape_is_pnp ? "SoundScape" : "SoundScape PNP",
1340 ports,
1341 hw_config->irq,
1342 hw_config->dma,
1343 hw_config->dma,
1344 0,
1345 devc->osp,
1346 THIS_MODULE);
1347
1348
1349 if (hw_config->slots[0] != -1) /* The AD1848 driver installed itself */
1350 {
1351 audio_devs[hw_config->slots[0]]->coproc = &sscape_coproc_operations;
1352 devc->codec_audiodev = hw_config->slots[0];
1353 devc->my_audiodev = hw_config->slots[0];
1354
1355 /* Set proper routings here (what are they) */
1356 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE);
1357 }
1358
1359#ifdef SSCAPE_DEBUG5
1360 /*
1361 * Temporary debugging aid. Print contents of the registers
1362 * after the AD1848 device has been initialized.
1363 */
1364 {
1365 int i;
1366
1367 for (i = 0; i < 13; i++)
1368 printk("I%d = %02x\n", i, sscape_read(devc, i));
1369 }
1370#endif
1371 return 1;
1372}
1373
1374static void __exit unload_sscape(struct address_info *hw_config)
1375{
1376 release_region(devc->base + 2, 6);
1377 unload_mpu401(hw_config);
1378 if (sscape_is_pnp)
1379 release_region(devc->codec, 2);
1380}
1381
1382static void __exit unload_ss_ms_sound(struct address_info *hw_config)
1383{
1384 ad1848_unload(hw_config->io_base,
1385 hw_config->irq,
1386 devc->dma,
1387 devc->dma,
1388 0);
1389 sound_unload_audiodev(hw_config->slots[0]);
1390}
1391
1392static struct address_info cfg;
1393static struct address_info cfg_mpu;
1394
1395static int __initdata spea = -1;
1396static int mss = 0;
1397static int __initdata dma = -1;
1398static int __initdata irq = -1;
1399static int __initdata io = -1;
1400static int __initdata mpu_irq = -1;
1401static int __initdata mpu_io = -1;
1402
1403module_param(dma, int, 0);
1404module_param(irq, int, 0);
1405module_param(io, int, 0);
1406module_param(spea, int, 0); /* spea=0/1 set the old_hardware */
1407module_param(mpu_irq, int, 0);
1408module_param(mpu_io, int, 0);
1409module_param(mss, int, 0);
1410
1411static int __init init_sscape(void)
1412{
1413 printk(KERN_INFO "Soundscape driver Copyright (C) by Hannu Savolainen 1993-1996\n");
1414
1415 cfg.irq = irq;
1416 cfg.dma = dma;
1417 cfg.io_base = io;
1418
1419 cfg_mpu.irq = mpu_irq;
1420 cfg_mpu.io_base = mpu_io;
1421 /* WEH - Try to get right dma channel */
1422 cfg_mpu.dma = dma;
1423
1424 devc->codec = cfg.io_base;
1425 devc->codec_irq = cfg.irq;
1426 devc->codec_type = 0;
1427 devc->ic_type = 0;
1428 devc->raw_buf = NULL;
1429 spin_lock_init(&devc->lock);
1430
1431 if (cfg.dma == -1 || cfg.irq == -1 || cfg.io_base == -1) {
1432 printk(KERN_ERR "DMA, IRQ, and IO port must be specified.\n");
1433 return -EINVAL;
1434 }
1435
1436 if (cfg_mpu.irq == -1 && cfg_mpu.io_base != -1) {
1437 printk(KERN_ERR "MPU_IRQ must be specified if MPU_IO is set.\n");
1438 return -EINVAL;
1439 }
1440
1441 if(spea != -1) {
1442 old_hardware = spea;
1443 printk(KERN_INFO "Forcing %s hardware support.\n",
1444 spea?"new":"old");
1445 }
1446 if (probe_sscape(&cfg_mpu) == 0)
1447 return -ENODEV;
1448
1449 attach_sscape(&cfg_mpu);
1450
1451 mss = init_ss_ms_sound(&cfg);
1452
1453 return 0;
1454}
1455
1456static void __exit cleanup_sscape(void)
1457{
1458 if (mss)
1459 unload_ss_ms_sound(&cfg);
1460 unload_sscape(&cfg_mpu);
1461}
1462
1463module_init(init_sscape);
1464module_exit(cleanup_sscape);
1465
1466#ifndef MODULE
1467static int __init setup_sscape(char *str)
1468{
1469 /* io, irq, dma, mpu_io, mpu_irq */
1470 int ints[6];
1471
1472 str = get_options(str, ARRAY_SIZE(ints), ints);
1473
1474 io = ints[1];
1475 irq = ints[2];
1476 dma = ints[3];
1477 mpu_io = ints[4];
1478 mpu_irq = ints[5];
1479
1480 return 1;
1481}
1482
1483__setup("sscape=", setup_sscape);
1484#endif
1485MODULE_LICENSE("GPL");
diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
new file mode 100644
index 000000000000..df4d3771fa84
--- /dev/null
+++ b/sound/oss/swarm_cs4297a.c
@@ -0,0 +1,2742 @@
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.h>
68#include <linux/delay.h>
69#include <linux/sound.h>
70#include <linux/slab.h>
71#include <linux/soundcard.h>
72#include <linux/ac97_codec.h>
73#include <linux/pci.h>
74#include <linux/bitops.h>
75#include <linux/interrupt.h>
76#include <linux/init.h>
77#include <linux/poll.h>
78#include <linux/smp_lock.h>
79
80#include <asm/byteorder.h>
81#include <asm/dma.h>
82#include <asm/io.h>
83#include <asm/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
93struct cs4297a_state;
94
95static void stop_dac(struct cs4297a_state *s);
96static void stop_adc(struct cs4297a_state *s);
97static void start_dac(struct cs4297a_state *s);
98static void start_adc(struct cs4297a_state *s);
99#undef OSS_DOCUMENTED_MIXER_SEMANTICS
100
101// ---------------------------------------------------------------------
102
103#define CS4297a_MAGIC 0xf00beef1
104
105// buffer order determines the size of the dma buffer for the driver.
106// under Linux, a smaller buffer allows more responsiveness from many of the
107// applications (e.g. games). A larger buffer allows some of the apps (esound)
108// to not underrun the dma buffer as easily. As default, use 32k (order=3)
109// rather than 64k as some of the games work more responsively.
110// log base 2( buff sz = 32k).
111
112//static unsigned long defaultorder = 3;
113//MODULE_PARM(defaultorder, "i");
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_PARM(cs_debuglevel, "i");
157MODULE_PARM(cs_debugmask, "i");
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
203struct list_head cs4297a_devs = { &cs4297a_devs, &cs4297a_devs };
204
205typedef struct serdma_descr_s {
206 u64 descr_a;
207 u64 descr_b;
208} serdma_descr_t;
209
210typedef unsigned long paddr_t;
211
212typedef struct serdma_s {
213 unsigned ringsz;
214 serdma_descr_t *descrtab;
215 serdma_descr_t *descrtab_end;
216 paddr_t descrtab_phys;
217
218 serdma_descr_t *descr_add;
219 serdma_descr_t *descr_rem;
220
221 u64 *dma_buf; // buffer for DMA contents (frames)
222 paddr_t dma_buf_phys;
223 u16 *sample_buf; // tmp buffer for sample conversions
224 u16 *sb_swptr;
225 u16 *sb_hwptr;
226 u16 *sb_end;
227
228 dma_addr_t dmaaddr;
229// unsigned buforder; // Log base 2 of 'dma_buf' size in bytes..
230 unsigned numfrag; // # of 'fragments' in the buffer.
231 unsigned fragshift; // Log base 2 of fragment size.
232 unsigned hwptr, swptr;
233 unsigned total_bytes; // # bytes process since open.
234 unsigned blocks; // last returned blocks value GETOPTR
235 unsigned wakeup; // interrupt occurred on block
236 int count;
237 unsigned underrun; // underrun flag
238 unsigned error; // over/underrun
239 wait_queue_head_t wait;
240 wait_queue_head_t reg_wait;
241 // redundant, but makes calculations easier
242 unsigned fragsize; // 2**fragshift..
243 unsigned sbufsz; // 2**buforder.
244 unsigned fragsamples;
245 // OSS stuff
246 unsigned mapped:1; // Buffer mapped in cs4297a_mmap()?
247 unsigned ready:1; // prog_dmabuf_dac()/adc() successful?
248 unsigned endcleared:1;
249 unsigned type:1; // adc or dac buffer (CS_TYPE_XXX)
250 unsigned ossfragshift;
251 int ossmaxfrags;
252 unsigned subdivision;
253} serdma_t;
254
255struct cs4297a_state {
256 // magic
257 unsigned int magic;
258
259 struct list_head list;
260
261 // soundcore stuff
262 int dev_audio;
263 int dev_mixer;
264
265 // hardware resources
266 unsigned int irq;
267
268 struct {
269 unsigned int rx_ovrrn; /* FIFO */
270 unsigned int rx_overflow; /* staging buffer */
271 unsigned int tx_underrun;
272 unsigned int rx_bad;
273 unsigned int rx_good;
274 } stats;
275
276 // mixer registers
277 struct {
278 unsigned short vol[10];
279 unsigned int recsrc;
280 unsigned int modcnt;
281 unsigned short micpreamp;
282 } mix;
283
284 // wave stuff
285 struct properties {
286 unsigned fmt;
287 unsigned fmt_original; // original requested format
288 unsigned channels;
289 unsigned rate;
290 } prop_dac, prop_adc;
291 unsigned conversion:1; // conversion from 16 to 8 bit in progress
292 unsigned ena;
293 spinlock_t lock;
294 struct semaphore open_sem;
295 struct semaphore open_sem_adc;
296 struct semaphore open_sem_dac;
297 mode_t open_mode;
298 wait_queue_head_t open_wait;
299 wait_queue_head_t open_wait_adc;
300 wait_queue_head_t open_wait_dac;
301
302 dma_addr_t dmaaddr_sample_buf;
303 unsigned buforder_sample_buf; // Log base 2 of 'dma_buf' size in bytes..
304
305 serdma_t dma_dac, dma_adc;
306
307 volatile u16 read_value;
308 volatile u16 read_reg;
309 volatile u64 reg_request;
310};
311
312#if 1
313#define prog_codec(a,b)
314#define dealloc_dmabuf(a,b);
315#endif
316
317static int prog_dmabuf_adc(struct cs4297a_state *s)
318{
319 s->dma_adc.ready = 1;
320 return 0;
321}
322
323
324static int prog_dmabuf_dac(struct cs4297a_state *s)
325{
326 s->dma_dac.ready = 1;
327 return 0;
328}
329
330static void clear_advance(void *buf, unsigned bsize, unsigned bptr,
331 unsigned len, unsigned char c)
332{
333 if (bptr + len > bsize) {
334 unsigned x = bsize - bptr;
335 memset(((char *) buf) + bptr, c, x);
336 bptr = 0;
337 len -= x;
338 }
339 CS_DBGOUT(CS_WAVE_WRITE, 4, printk(KERN_INFO
340 "cs4297a: clear_advance(): memset %d at 0x%.8x for %d size \n",
341 (unsigned)c, (unsigned)((char *) buf) + bptr, len));
342 memset(((char *) buf) + bptr, c, len);
343}
344
345#if CSDEBUG
346
347// DEBUG ROUTINES
348
349#define SOUND_MIXER_CS_GETDBGLEVEL _SIOWR('M',120, int)
350#define SOUND_MIXER_CS_SETDBGLEVEL _SIOWR('M',121, int)
351#define SOUND_MIXER_CS_GETDBGMASK _SIOWR('M',122, int)
352#define SOUND_MIXER_CS_SETDBGMASK _SIOWR('M',123, int)
353
354static void cs_printioctl(unsigned int x)
355{
356 unsigned int i;
357 unsigned char vidx;
358 // Index of mixtable1[] member is Device ID
359 // and must be <= SOUND_MIXER_NRDEVICES.
360 // Value of array member is index into s->mix.vol[]
361 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
362 [SOUND_MIXER_PCM] = 1, // voice
363 [SOUND_MIXER_LINE1] = 2, // AUX
364 [SOUND_MIXER_CD] = 3, // CD
365 [SOUND_MIXER_LINE] = 4, // Line
366 [SOUND_MIXER_SYNTH] = 5, // FM
367 [SOUND_MIXER_MIC] = 6, // Mic
368 [SOUND_MIXER_SPEAKER] = 7, // Speaker
369 [SOUND_MIXER_RECLEV] = 8, // Recording level
370 [SOUND_MIXER_VOLUME] = 9 // Master Volume
371 };
372
373 switch (x) {
374 case SOUND_MIXER_CS_GETDBGMASK:
375 CS_DBGOUT(CS_IOCTL, 4,
376 printk("SOUND_MIXER_CS_GETDBGMASK:\n"));
377 break;
378 case SOUND_MIXER_CS_GETDBGLEVEL:
379 CS_DBGOUT(CS_IOCTL, 4,
380 printk("SOUND_MIXER_CS_GETDBGLEVEL:\n"));
381 break;
382 case SOUND_MIXER_CS_SETDBGMASK:
383 CS_DBGOUT(CS_IOCTL, 4,
384 printk("SOUND_MIXER_CS_SETDBGMASK:\n"));
385 break;
386 case SOUND_MIXER_CS_SETDBGLEVEL:
387 CS_DBGOUT(CS_IOCTL, 4,
388 printk("SOUND_MIXER_CS_SETDBGLEVEL:\n"));
389 break;
390 case OSS_GETVERSION:
391 CS_DBGOUT(CS_IOCTL, 4, printk("OSS_GETVERSION:\n"));
392 break;
393 case SNDCTL_DSP_SYNC:
394 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SYNC:\n"));
395 break;
396 case SNDCTL_DSP_SETDUPLEX:
397 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETDUPLEX:\n"));
398 break;
399 case SNDCTL_DSP_GETCAPS:
400 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETCAPS:\n"));
401 break;
402 case SNDCTL_DSP_RESET:
403 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_RESET:\n"));
404 break;
405 case SNDCTL_DSP_SPEED:
406 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SPEED:\n"));
407 break;
408 case SNDCTL_DSP_STEREO:
409 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_STEREO:\n"));
410 break;
411 case SNDCTL_DSP_CHANNELS:
412 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_CHANNELS:\n"));
413 break;
414 case SNDCTL_DSP_GETFMTS:
415 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETFMTS:\n"));
416 break;
417 case SNDCTL_DSP_SETFMT:
418 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETFMT:\n"));
419 break;
420 case SNDCTL_DSP_POST:
421 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_POST:\n"));
422 break;
423 case SNDCTL_DSP_GETTRIGGER:
424 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETTRIGGER:\n"));
425 break;
426 case SNDCTL_DSP_SETTRIGGER:
427 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETTRIGGER:\n"));
428 break;
429 case SNDCTL_DSP_GETOSPACE:
430 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOSPACE:\n"));
431 break;
432 case SNDCTL_DSP_GETISPACE:
433 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETISPACE:\n"));
434 break;
435 case SNDCTL_DSP_NONBLOCK:
436 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_NONBLOCK:\n"));
437 break;
438 case SNDCTL_DSP_GETODELAY:
439 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETODELAY:\n"));
440 break;
441 case SNDCTL_DSP_GETIPTR:
442 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETIPTR:\n"));
443 break;
444 case SNDCTL_DSP_GETOPTR:
445 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOPTR:\n"));
446 break;
447 case SNDCTL_DSP_GETBLKSIZE:
448 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETBLKSIZE:\n"));
449 break;
450 case SNDCTL_DSP_SETFRAGMENT:
451 CS_DBGOUT(CS_IOCTL, 4,
452 printk("SNDCTL_DSP_SETFRAGMENT:\n"));
453 break;
454 case SNDCTL_DSP_SUBDIVIDE:
455 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SUBDIVIDE:\n"));
456 break;
457 case SOUND_PCM_READ_RATE:
458 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_RATE:\n"));
459 break;
460 case SOUND_PCM_READ_CHANNELS:
461 CS_DBGOUT(CS_IOCTL, 4,
462 printk("SOUND_PCM_READ_CHANNELS:\n"));
463 break;
464 case SOUND_PCM_READ_BITS:
465 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_BITS:\n"));
466 break;
467 case SOUND_PCM_WRITE_FILTER:
468 CS_DBGOUT(CS_IOCTL, 4,
469 printk("SOUND_PCM_WRITE_FILTER:\n"));
470 break;
471 case SNDCTL_DSP_SETSYNCRO:
472 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETSYNCRO:\n"));
473 break;
474 case SOUND_PCM_READ_FILTER:
475 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_FILTER:\n"));
476 break;
477 case SOUND_MIXER_PRIVATE1:
478 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE1:\n"));
479 break;
480 case SOUND_MIXER_PRIVATE2:
481 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE2:\n"));
482 break;
483 case SOUND_MIXER_PRIVATE3:
484 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE3:\n"));
485 break;
486 case SOUND_MIXER_PRIVATE4:
487 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE4:\n"));
488 break;
489 case SOUND_MIXER_PRIVATE5:
490 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE5:\n"));
491 break;
492 case SOUND_MIXER_INFO:
493 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_INFO:\n"));
494 break;
495 case SOUND_OLD_MIXER_INFO:
496 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_OLD_MIXER_INFO:\n"));
497 break;
498
499 default:
500 switch (_IOC_NR(x)) {
501 case SOUND_MIXER_VOLUME:
502 CS_DBGOUT(CS_IOCTL, 4,
503 printk("SOUND_MIXER_VOLUME:\n"));
504 break;
505 case SOUND_MIXER_SPEAKER:
506 CS_DBGOUT(CS_IOCTL, 4,
507 printk("SOUND_MIXER_SPEAKER:\n"));
508 break;
509 case SOUND_MIXER_RECLEV:
510 CS_DBGOUT(CS_IOCTL, 4,
511 printk("SOUND_MIXER_RECLEV:\n"));
512 break;
513 case SOUND_MIXER_MIC:
514 CS_DBGOUT(CS_IOCTL, 4,
515 printk("SOUND_MIXER_MIC:\n"));
516 break;
517 case SOUND_MIXER_SYNTH:
518 CS_DBGOUT(CS_IOCTL, 4,
519 printk("SOUND_MIXER_SYNTH:\n"));
520 break;
521 case SOUND_MIXER_RECSRC:
522 CS_DBGOUT(CS_IOCTL, 4,
523 printk("SOUND_MIXER_RECSRC:\n"));
524 break;
525 case SOUND_MIXER_DEVMASK:
526 CS_DBGOUT(CS_IOCTL, 4,
527 printk("SOUND_MIXER_DEVMASK:\n"));
528 break;
529 case SOUND_MIXER_RECMASK:
530 CS_DBGOUT(CS_IOCTL, 4,
531 printk("SOUND_MIXER_RECMASK:\n"));
532 break;
533 case SOUND_MIXER_STEREODEVS:
534 CS_DBGOUT(CS_IOCTL, 4,
535 printk("SOUND_MIXER_STEREODEVS:\n"));
536 break;
537 case SOUND_MIXER_CAPS:
538 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CAPS:\n"));
539 break;
540 default:
541 i = _IOC_NR(x);
542 if (i >= SOUND_MIXER_NRDEVICES
543 || !(vidx = mixtable1[i])) {
544 CS_DBGOUT(CS_IOCTL, 4, printk
545 ("UNKNOWN IOCTL: 0x%.8x NR=%d\n",
546 x, i));
547 } else {
548 CS_DBGOUT(CS_IOCTL, 4, printk
549 ("SOUND_MIXER_IOCTL AC9x: 0x%.8x NR=%d\n",
550 x, i));
551 }
552 break;
553 }
554 }
555}
556#endif
557
558
559static int ser_init(struct cs4297a_state *s)
560{
561 int i;
562
563 CS_DBGOUT(CS_INIT, 2,
564 printk(KERN_INFO "cs4297a: Setting up serial parameters\n"));
565
566 __raw_writeq(M_SYNCSER_CMD_RX_RESET | M_SYNCSER_CMD_TX_RESET, SS_CSR(R_SER_CMD));
567
568 __raw_writeq(M_SYNCSER_MSB_FIRST, SS_CSR(R_SER_MODE));
569 __raw_writeq(32, SS_CSR(R_SER_MINFRM_SZ));
570 __raw_writeq(32, SS_CSR(R_SER_MAXFRM_SZ));
571
572 __raw_writeq(1, SS_CSR(R_SER_TX_RD_THRSH));
573 __raw_writeq(4, SS_CSR(R_SER_TX_WR_THRSH));
574 __raw_writeq(8, SS_CSR(R_SER_RX_RD_THRSH));
575
576 /* This looks good from experimentation */
577 __raw_writeq((M_SYNCSER_TXSYNC_INT | V_SYNCSER_TXSYNC_DLY(0) | M_SYNCSER_TXCLK_EXT |
578 M_SYNCSER_RXSYNC_INT | V_SYNCSER_RXSYNC_DLY(1) | M_SYNCSER_RXCLK_EXT | M_SYNCSER_RXSYNC_EDGE),
579 SS_CSR(R_SER_LINE_MODE));
580
581 /* This looks good from experimentation */
582 __raw_writeq(V_SYNCSER_SEQ_COUNT(14) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE,
583 SS_TXTBL(0));
584 __raw_writeq(V_SYNCSER_SEQ_COUNT(15) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
585 SS_TXTBL(1));
586 __raw_writeq(V_SYNCSER_SEQ_COUNT(13) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
587 SS_TXTBL(2));
588 __raw_writeq(V_SYNCSER_SEQ_COUNT( 0) | M_SYNCSER_SEQ_ENABLE |
589 M_SYNCSER_SEQ_STROBE | M_SYNCSER_SEQ_LAST, SS_TXTBL(3));
590
591 __raw_writeq(V_SYNCSER_SEQ_COUNT(14) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE,
592 SS_RXTBL(0));
593 __raw_writeq(V_SYNCSER_SEQ_COUNT(15) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
594 SS_RXTBL(1));
595 __raw_writeq(V_SYNCSER_SEQ_COUNT(13) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
596 SS_RXTBL(2));
597 __raw_writeq(V_SYNCSER_SEQ_COUNT( 0) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE |
598 M_SYNCSER_SEQ_LAST, SS_RXTBL(3));
599
600 for (i=4; i<16; i++) {
601 /* Just in case... */
602 __raw_writeq(M_SYNCSER_SEQ_LAST, SS_TXTBL(i));
603 __raw_writeq(M_SYNCSER_SEQ_LAST, SS_RXTBL(i));
604 }
605
606 return 0;
607}
608
609static int init_serdma(serdma_t *dma)
610{
611 CS_DBGOUT(CS_INIT, 2,
612 printk(KERN_ERR "cs4297a: desc - %d sbufsize - %d dbufsize - %d\n",
613 DMA_DESCR, SAMPLE_BUF_SIZE, DMA_BUF_SIZE));
614
615 /* Descriptors */
616 dma->ringsz = DMA_DESCR;
617 dma->descrtab = kmalloc(dma->ringsz * sizeof(serdma_descr_t), GFP_KERNEL);
618 if (!dma->descrtab) {
619 printk(KERN_ERR "cs4297a: kmalloc descrtab failed\n");
620 return -1;
621 }
622 memset(dma->descrtab, 0, dma->ringsz * sizeof(serdma_descr_t));
623 dma->descrtab_end = dma->descrtab + dma->ringsz;
624 /* XXX bloddy mess, use proper DMA API here ... */
625 dma->descrtab_phys = CPHYSADDR((long)dma->descrtab);
626 dma->descr_add = dma->descr_rem = dma->descrtab;
627
628 /* Frame buffer area */
629 dma->dma_buf = kmalloc(DMA_BUF_SIZE, GFP_KERNEL);
630 if (!dma->dma_buf) {
631 printk(KERN_ERR "cs4297a: kmalloc dma_buf failed\n");
632 kfree(dma->descrtab);
633 return -1;
634 }
635 memset(dma->dma_buf, 0, DMA_BUF_SIZE);
636 dma->dma_buf_phys = CPHYSADDR((long)dma->dma_buf);
637
638 /* Samples buffer area */
639 dma->sbufsz = SAMPLE_BUF_SIZE;
640 dma->sample_buf = kmalloc(dma->sbufsz, GFP_KERNEL);
641 if (!dma->sample_buf) {
642 printk(KERN_ERR "cs4297a: kmalloc sample_buf failed\n");
643 kfree(dma->descrtab);
644 kfree(dma->dma_buf);
645 return -1;
646 }
647 dma->sb_swptr = dma->sb_hwptr = dma->sample_buf;
648 dma->sb_end = (u16 *)((void *)dma->sample_buf + dma->sbufsz);
649 dma->fragsize = dma->sbufsz >> 1;
650
651 CS_DBGOUT(CS_INIT, 4,
652 printk(KERN_ERR "cs4297a: descrtab - %08x dma_buf - %x sample_buf - %x\n",
653 (int)dma->descrtab, (int)dma->dma_buf,
654 (int)dma->sample_buf));
655
656 return 0;
657}
658
659static int dma_init(struct cs4297a_state *s)
660{
661 int i;
662
663 CS_DBGOUT(CS_INIT, 2,
664 printk(KERN_INFO "cs4297a: Setting up DMA\n"));
665
666 if (init_serdma(&s->dma_adc) ||
667 init_serdma(&s->dma_dac))
668 return -1;
669
670 if (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_RX))||
671 __raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX))) {
672 panic("DMA state corrupted?!");
673 }
674
675 /* Initialize now - the descr/buffer pairings will never
676 change... */
677 for (i=0; i<DMA_DESCR; i++) {
678 s->dma_dac.descrtab[i].descr_a = M_DMA_SERRX_SOP | V_DMA_DSCRA_A_SIZE(1) |
679 (s->dma_dac.dma_buf_phys + i*FRAME_BYTES);
680 s->dma_dac.descrtab[i].descr_b = V_DMA_DSCRB_PKT_SIZE(FRAME_BYTES);
681 s->dma_adc.descrtab[i].descr_a = V_DMA_DSCRA_A_SIZE(1) |
682 (s->dma_adc.dma_buf_phys + i*FRAME_BYTES);
683 s->dma_adc.descrtab[i].descr_b = 0;
684 }
685
686 __raw_writeq((M_DMA_EOP_INT_EN | V_DMA_INT_PKTCNT(DMA_INT_CNT) |
687 V_DMA_RINGSZ(DMA_DESCR) | M_DMA_TDX_EN),
688 SS_CSR(R_SER_DMA_CONFIG0_RX));
689 __raw_writeq(M_DMA_L2CA, SS_CSR(R_SER_DMA_CONFIG1_RX));
690 __raw_writeq(s->dma_adc.descrtab_phys, SS_CSR(R_SER_DMA_DSCR_BASE_RX));
691
692 __raw_writeq(V_DMA_RINGSZ(DMA_DESCR), SS_CSR(R_SER_DMA_CONFIG0_TX));
693 __raw_writeq(M_DMA_L2CA | M_DMA_NO_DSCR_UPDT, SS_CSR(R_SER_DMA_CONFIG1_TX));
694 __raw_writeq(s->dma_dac.descrtab_phys, SS_CSR(R_SER_DMA_DSCR_BASE_TX));
695
696 /* Prep the receive DMA descriptor ring */
697 __raw_writeq(DMA_DESCR, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
698
699 __raw_writeq(M_SYNCSER_DMA_RX_EN | M_SYNCSER_DMA_TX_EN, SS_CSR(R_SER_DMA_ENABLE));
700
701 __raw_writeq((M_SYNCSER_RX_SYNC_ERR | M_SYNCSER_RX_OVERRUN | M_SYNCSER_RX_EOP_COUNT),
702 SS_CSR(R_SER_INT_MASK));
703
704 /* Enable the rx/tx; let the codec warm up to the sync and
705 start sending good frames before the receive FIFO is
706 enabled */
707 __raw_writeq(M_SYNCSER_CMD_TX_EN, SS_CSR(R_SER_CMD));
708 udelay(1000);
709 __raw_writeq(M_SYNCSER_CMD_RX_EN | M_SYNCSER_CMD_TX_EN, SS_CSR(R_SER_CMD));
710
711 /* XXXKW is this magic? (the "1" part) */
712 while ((__raw_readq(SS_CSR(R_SER_STATUS)) & 0xf1) != 1)
713 ;
714
715 CS_DBGOUT(CS_INIT, 4,
716 printk(KERN_INFO "cs4297a: status: %08x\n",
717 (unsigned int)(__raw_readq(SS_CSR(R_SER_STATUS)) & 0xffffffff)));
718
719 return 0;
720}
721
722static int serdma_reg_access(struct cs4297a_state *s, u64 data)
723{
724 serdma_t *d = &s->dma_dac;
725 u64 *data_p;
726 unsigned swptr;
727 int flags;
728 serdma_descr_t *descr;
729
730 if (s->reg_request) {
731 printk(KERN_ERR "cs4297a: attempt to issue multiple reg_access\n");
732 return -1;
733 }
734
735 if (s->ena & FMODE_WRITE) {
736 /* Since a writer has the DSP open, we have to mux the
737 request in */
738 s->reg_request = data;
739 interruptible_sleep_on(&s->dma_dac.reg_wait);
740 /* XXXKW how can I deal with the starvation case where
741 the opener isn't writing? */
742 } else {
743 /* Be safe when changing ring pointers */
744 spin_lock_irqsave(&s->lock, flags);
745 if (d->hwptr != d->swptr) {
746 printk(KERN_ERR "cs4297a: reg access found bookkeeping error (hw/sw = %d/%d\n",
747 d->hwptr, d->swptr);
748 spin_unlock_irqrestore(&s->lock, flags);
749 return -1;
750 }
751 swptr = d->swptr;
752 d->hwptr = d->swptr = (d->swptr + 1) % d->ringsz;
753 spin_unlock_irqrestore(&s->lock, flags);
754
755 descr = &d->descrtab[swptr];
756 data_p = &d->dma_buf[swptr * 4];
757 *data_p = cpu_to_be64(data);
758 __raw_writeq(1, SS_CSR(R_SER_DMA_DSCR_COUNT_TX));
759 CS_DBGOUT(CS_DESCR, 4,
760 printk(KERN_INFO "cs4297a: add_tx %p (%x -> %x)\n",
761 data_p, swptr, d->hwptr));
762 }
763
764 CS_DBGOUT(CS_FUNCTION, 6,
765 printk(KERN_INFO "cs4297a: serdma_reg_access()-\n"));
766
767 return 0;
768}
769
770//****************************************************************************
771// "cs4297a_read_ac97" -- Reads an AC97 register
772//****************************************************************************
773static int cs4297a_read_ac97(struct cs4297a_state *s, u32 offset,
774 u32 * value)
775{
776 CS_DBGOUT(CS_AC97, 1,
777 printk(KERN_INFO "cs4297a: read reg %2x\n", offset));
778 if (serdma_reg_access(s, (0xCLL << 60) | (1LL << 47) | ((u64)(offset & 0x7F) << 40)))
779 return -1;
780
781 interruptible_sleep_on(&s->dma_adc.reg_wait);
782 *value = s->read_value;
783 CS_DBGOUT(CS_AC97, 2,
784 printk(KERN_INFO "cs4297a: rdr reg %x -> %x\n", s->read_reg, s->read_value));
785
786 return 0;
787}
788
789
790//****************************************************************************
791// "cs4297a_write_ac97()"-- writes an AC97 register
792//****************************************************************************
793static int cs4297a_write_ac97(struct cs4297a_state *s, u32 offset,
794 u32 value)
795{
796 CS_DBGOUT(CS_AC97, 1,
797 printk(KERN_INFO "cs4297a: write reg %2x -> %04x\n", offset, value));
798 return (serdma_reg_access(s, (0xELL << 60) | ((u64)(offset & 0x7F) << 40) | ((value & 0xffff) << 12)));
799}
800
801static void stop_dac(struct cs4297a_state *s)
802{
803 unsigned long flags;
804
805 CS_DBGOUT(CS_WAVE_WRITE, 3, printk(KERN_INFO "cs4297a: stop_dac():\n"));
806 spin_lock_irqsave(&s->lock, flags);
807 s->ena &= ~FMODE_WRITE;
808#if 0
809 /* XXXKW what do I really want here? My theory for now is
810 that I just flip the "ena" bit, and the interrupt handler
811 will stop processing the xmit channel */
812 __raw_writeq((s->ena & FMODE_READ) ? M_SYNCSER_DMA_RX_EN : 0,
813 SS_CSR(R_SER_DMA_ENABLE));
814#endif
815
816 spin_unlock_irqrestore(&s->lock, flags);
817}
818
819
820static void start_dac(struct cs4297a_state *s)
821{
822 unsigned long flags;
823
824 CS_DBGOUT(CS_FUNCTION, 3, printk(KERN_INFO "cs4297a: start_dac()+\n"));
825 spin_lock_irqsave(&s->lock, flags);
826 if (!(s->ena & FMODE_WRITE) && (s->dma_dac.mapped ||
827 (s->dma_dac.count > 0
828 && s->dma_dac.ready))) {
829 s->ena |= FMODE_WRITE;
830 /* XXXKW what do I really want here? My theory for
831 now is that I just flip the "ena" bit, and the
832 interrupt handler will start processing the xmit
833 channel */
834
835 CS_DBGOUT(CS_WAVE_WRITE | CS_PARMS, 8, printk(KERN_INFO
836 "cs4297a: start_dac(): start dma\n"));
837
838 }
839 spin_unlock_irqrestore(&s->lock, flags);
840 CS_DBGOUT(CS_FUNCTION, 3,
841 printk(KERN_INFO "cs4297a: start_dac()-\n"));
842}
843
844
845static void stop_adc(struct cs4297a_state *s)
846{
847 unsigned long flags;
848
849 CS_DBGOUT(CS_FUNCTION, 3,
850 printk(KERN_INFO "cs4297a: stop_adc()+\n"));
851
852 spin_lock_irqsave(&s->lock, flags);
853 s->ena &= ~FMODE_READ;
854
855 if (s->conversion == 1) {
856 s->conversion = 0;
857 s->prop_adc.fmt = s->prop_adc.fmt_original;
858 }
859 /* Nothing to do really, I need to keep the DMA going
860 XXXKW when do I get here, and is there more I should do? */
861 spin_unlock_irqrestore(&s->lock, flags);
862 CS_DBGOUT(CS_FUNCTION, 3,
863 printk(KERN_INFO "cs4297a: stop_adc()-\n"));
864}
865
866
867static void start_adc(struct cs4297a_state *s)
868{
869 unsigned long flags;
870
871 CS_DBGOUT(CS_FUNCTION, 2,
872 printk(KERN_INFO "cs4297a: start_adc()+\n"));
873
874 if (!(s->ena & FMODE_READ) &&
875 (s->dma_adc.mapped || s->dma_adc.count <=
876 (signed) (s->dma_adc.sbufsz - 2 * s->dma_adc.fragsize))
877 && s->dma_adc.ready) {
878 if (s->prop_adc.fmt & AFMT_S8 || s->prop_adc.fmt & AFMT_U8) {
879 //
880 // now only use 16 bit capture, due to truncation issue
881 // in the chip, noticable distortion occurs.
882 // allocate buffer and then convert from 16 bit to
883 // 8 bit for the user buffer.
884 //
885 s->prop_adc.fmt_original = s->prop_adc.fmt;
886 if (s->prop_adc.fmt & AFMT_S8) {
887 s->prop_adc.fmt &= ~AFMT_S8;
888 s->prop_adc.fmt |= AFMT_S16_LE;
889 }
890 if (s->prop_adc.fmt & AFMT_U8) {
891 s->prop_adc.fmt &= ~AFMT_U8;
892 s->prop_adc.fmt |= AFMT_U16_LE;
893 }
894 //
895 // prog_dmabuf_adc performs a stop_adc() but that is
896 // ok since we really haven't started the DMA yet.
897 //
898 prog_codec(s, CS_TYPE_ADC);
899
900 prog_dmabuf_adc(s);
901 s->conversion = 1;
902 }
903 spin_lock_irqsave(&s->lock, flags);
904 s->ena |= FMODE_READ;
905 /* Nothing to do really, I am probably already
906 DMAing... XXXKW when do I get here, and is there
907 more I should do? */
908 spin_unlock_irqrestore(&s->lock, flags);
909
910 CS_DBGOUT(CS_PARMS, 6, printk(KERN_INFO
911 "cs4297a: start_adc(): start adc\n"));
912 }
913 CS_DBGOUT(CS_FUNCTION, 2,
914 printk(KERN_INFO "cs4297a: start_adc()-\n"));
915
916}
917
918
919// call with spinlock held!
920static void cs4297a_update_ptr(struct cs4297a_state *s, int intflag)
921{
922 int good_diff, diff, diff2;
923 u64 *data_p, data;
924 u32 *s_ptr;
925 unsigned hwptr;
926 u32 status;
927 serdma_t *d;
928 serdma_descr_t *descr;
929
930 // update ADC pointer
931 status = intflag ? __raw_readq(SS_CSR(R_SER_STATUS)) : 0;
932
933 if ((s->ena & FMODE_READ) || (status & (M_SYNCSER_RX_EOP_COUNT))) {
934 d = &s->dma_adc;
935 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
936 d->descrtab_phys) / sizeof(serdma_descr_t));
937
938 if (s->ena & FMODE_READ) {
939 CS_DBGOUT(CS_FUNCTION, 2,
940 printk(KERN_INFO "cs4297a: upd_rcv sw->hw->hw %x/%x/%x (int-%d)n",
941 d->swptr, d->hwptr, hwptr, intflag));
942 /* Number of DMA buffers available for software: */
943 diff2 = diff = (d->ringsz + hwptr - d->hwptr) % d->ringsz;
944 d->hwptr = hwptr;
945 good_diff = 0;
946 s_ptr = (u32 *)&(d->dma_buf[d->swptr*4]);
947 descr = &d->descrtab[d->swptr];
948 while (diff2--) {
949 u64 data = be64_to_cpu(*(u64 *)s_ptr);
950 u64 descr_a;
951 u16 left, right;
952 descr_a = descr->descr_a;
953 descr->descr_a &= ~M_DMA_SERRX_SOP;
954 if ((descr_a & M_DMA_DSCRA_A_ADDR) != CPHYSADDR((long)s_ptr)) {
955 printk(KERN_ERR "cs4297a: RX Bad address (read)\n");
956 }
957 if (((data & 0x9800000000000000) != 0x9800000000000000) ||
958 (!(descr_a & M_DMA_SERRX_SOP)) ||
959 (G_DMA_DSCRB_PKT_SIZE(descr->descr_b) != FRAME_BYTES)) {
960 s->stats.rx_bad++;
961 printk(KERN_DEBUG "cs4297a: RX Bad attributes (read)\n");
962 continue;
963 }
964 s->stats.rx_good++;
965 if ((data >> 61) == 7) {
966 s->read_value = (data >> 12) & 0xffff;
967 s->read_reg = (data >> 40) & 0x7f;
968 wake_up(&d->reg_wait);
969 }
970 if (d->count && (d->sb_hwptr == d->sb_swptr)) {
971 s->stats.rx_overflow++;
972 printk(KERN_DEBUG "cs4297a: RX overflow\n");
973 continue;
974 }
975 good_diff++;
976 left = ((be32_to_cpu(s_ptr[1]) & 0xff) << 8) |
977 ((be32_to_cpu(s_ptr[2]) >> 24) & 0xff);
978 right = (be32_to_cpu(s_ptr[2]) >> 4) & 0xffff;
979 *d->sb_hwptr++ = cpu_to_be16(left);
980 *d->sb_hwptr++ = cpu_to_be16(right);
981 if (d->sb_hwptr == d->sb_end)
982 d->sb_hwptr = d->sample_buf;
983 descr++;
984 if (descr == d->descrtab_end) {
985 descr = d->descrtab;
986 s_ptr = (u32 *)s->dma_adc.dma_buf;
987 } else {
988 s_ptr += 8;
989 }
990 }
991 d->total_bytes += good_diff * FRAME_SAMPLE_BYTES;
992 d->count += good_diff * FRAME_SAMPLE_BYTES;
993 if (d->count > d->sbufsz) {
994 printk(KERN_ERR "cs4297a: bogus receive overflow!!\n");
995 }
996 d->swptr = (d->swptr + diff) % d->ringsz;
997 __raw_writeq(diff, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
998 if (d->mapped) {
999 if (d->count >= (signed) d->fragsize)
1000 wake_up(&d->wait);
1001 } else {
1002 if (d->count > 0) {
1003 CS_DBGOUT(CS_WAVE_READ, 4,
1004 printk(KERN_INFO
1005 "cs4297a: update count -> %d\n", d->count));
1006 wake_up(&d->wait);
1007 }
1008 }
1009 } else {
1010 /* Receive is going even if no one is
1011 listening (for register accesses and to
1012 avoid FIFO overrun) */
1013 diff2 = diff = (hwptr + d->ringsz - d->hwptr) % d->ringsz;
1014 if (!diff) {
1015 printk(KERN_ERR "cs4297a: RX full or empty?\n");
1016 }
1017
1018 descr = &d->descrtab[d->swptr];
1019 data_p = &d->dma_buf[d->swptr*4];
1020
1021 /* Force this to happen at least once; I got
1022 here because of an interrupt, so there must
1023 be a buffer to process. */
1024 do {
1025 data = be64_to_cpu(*data_p);
1026 if ((descr->descr_a & M_DMA_DSCRA_A_ADDR) != CPHYSADDR((long)data_p)) {
1027 printk(KERN_ERR "cs4297a: RX Bad address %d (%llx %lx)\n", d->swptr,
1028 (long long)(descr->descr_a & M_DMA_DSCRA_A_ADDR),
1029 (long)CPHYSADDR((long)data_p));
1030 }
1031 if (!(data & (1LL << 63)) ||
1032 !(descr->descr_a & M_DMA_SERRX_SOP) ||
1033 (G_DMA_DSCRB_PKT_SIZE(descr->descr_b) != FRAME_BYTES)) {
1034 s->stats.rx_bad++;
1035 printk(KERN_DEBUG "cs4297a: RX Bad attributes\n");
1036 } else {
1037 s->stats.rx_good++;
1038 if ((data >> 61) == 7) {
1039 s->read_value = (data >> 12) & 0xffff;
1040 s->read_reg = (data >> 40) & 0x7f;
1041 wake_up(&d->reg_wait);
1042 }
1043 }
1044 descr->descr_a &= ~M_DMA_SERRX_SOP;
1045 descr++;
1046 d->swptr++;
1047 data_p += 4;
1048 if (descr == d->descrtab_end) {
1049 descr = d->descrtab;
1050 d->swptr = 0;
1051 data_p = d->dma_buf;
1052 }
1053 __raw_writeq(1, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
1054 } while (--diff);
1055 d->hwptr = hwptr;
1056
1057 CS_DBGOUT(CS_DESCR, 6,
1058 printk(KERN_INFO "cs4297a: hw/sw %x/%x\n", d->hwptr, d->swptr));
1059 }
1060
1061 CS_DBGOUT(CS_PARMS, 8, printk(KERN_INFO
1062 "cs4297a: cs4297a_update_ptr(): s=0x%.8x hwptr=%d total_bytes=%d count=%d \n",
1063 (unsigned)s, d->hwptr,
1064 d->total_bytes, d->count));
1065 }
1066
1067 /* XXXKW worry about s->reg_request -- there is a starvation
1068 case if s->ena has FMODE_WRITE on, but the client isn't
1069 doing writes */
1070
1071 // update DAC pointer
1072 //
1073 // check for end of buffer, means that we are going to wait for another interrupt
1074 // to allow silence to fill the fifos on the part, to keep pops down to a minimum.
1075 //
1076 if (s->ena & FMODE_WRITE) {
1077 serdma_t *d = &s->dma_dac;
1078 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1079 d->descrtab_phys) / sizeof(serdma_descr_t));
1080 diff = (d->ringsz + hwptr - d->hwptr) % d->ringsz;
1081 CS_DBGOUT(CS_WAVE_WRITE, 4, printk(KERN_INFO
1082 "cs4297a: cs4297a_update_ptr(): hw/hw/sw %x/%x/%x diff %d count %d\n",
1083 d->hwptr, hwptr, d->swptr, diff, d->count));
1084 d->hwptr = hwptr;
1085 /* XXXKW stereo? conversion? Just assume 2 16-bit samples for now */
1086 d->total_bytes += diff * FRAME_SAMPLE_BYTES;
1087 if (d->mapped) {
1088 d->count += diff * FRAME_SAMPLE_BYTES;
1089 if (d->count >= d->fragsize) {
1090 d->wakeup = 1;
1091 wake_up(&d->wait);
1092 if (d->count > d->sbufsz)
1093 d->count &= d->sbufsz - 1;
1094 }
1095 } else {
1096 d->count -= diff * FRAME_SAMPLE_BYTES;
1097 if (d->count <= 0) {
1098 //
1099 // fill with silence, and do not shut down the DAC.
1100 // Continue to play silence until the _release.
1101 //
1102 CS_DBGOUT(CS_WAVE_WRITE, 6, printk(KERN_INFO
1103 "cs4297a: cs4297a_update_ptr(): memset %d at 0x%.8x for %d size \n",
1104 (unsigned)(s->prop_dac.fmt &
1105 (AFMT_U8 | AFMT_U16_LE)) ? 0x80 : 0,
1106 (unsigned)d->dma_buf,
1107 d->ringsz));
1108 memset(d->dma_buf, 0, d->ringsz * FRAME_BYTES);
1109 if (d->count < 0) {
1110 d->underrun = 1;
1111 s->stats.tx_underrun++;
1112 d->count = 0;
1113 CS_DBGOUT(CS_ERROR, 9, printk(KERN_INFO
1114 "cs4297a: cs4297a_update_ptr(): underrun\n"));
1115 }
1116 } else if (d->count <=
1117 (signed) d->fragsize
1118 && !d->endcleared) {
1119 /* XXXKW what is this for? */
1120 clear_advance(d->dma_buf,
1121 d->sbufsz,
1122 d->swptr,
1123 d->fragsize,
1124 0);
1125 d->endcleared = 1;
1126 }
1127 if ( (d->count <= (signed) d->sbufsz/2) || intflag)
1128 {
1129 CS_DBGOUT(CS_WAVE_WRITE, 4,
1130 printk(KERN_INFO
1131 "cs4297a: update count -> %d\n", d->count));
1132 wake_up(&d->wait);
1133 }
1134 }
1135 CS_DBGOUT(CS_PARMS, 8, printk(KERN_INFO
1136 "cs4297a: cs4297a_update_ptr(): s=0x%.8x hwptr=%d total_bytes=%d count=%d \n",
1137 (unsigned) s, d->hwptr,
1138 d->total_bytes, d->count));
1139 }
1140}
1141
1142static int mixer_ioctl(struct cs4297a_state *s, unsigned int cmd,
1143 unsigned long arg)
1144{
1145 // Index to mixer_src[] is value of AC97 Input Mux Select Reg.
1146 // Value of array member is recording source Device ID Mask.
1147 static const unsigned int mixer_src[8] = {
1148 SOUND_MASK_MIC, SOUND_MASK_CD, 0, SOUND_MASK_LINE1,
1149 SOUND_MASK_LINE, SOUND_MASK_VOLUME, 0, 0
1150 };
1151
1152 // Index of mixtable1[] member is Device ID
1153 // and must be <= SOUND_MIXER_NRDEVICES.
1154 // Value of array member is index into s->mix.vol[]
1155 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
1156 [SOUND_MIXER_PCM] = 1, // voice
1157 [SOUND_MIXER_LINE1] = 2, // AUX
1158 [SOUND_MIXER_CD] = 3, // CD
1159 [SOUND_MIXER_LINE] = 4, // Line
1160 [SOUND_MIXER_SYNTH] = 5, // FM
1161 [SOUND_MIXER_MIC] = 6, // Mic
1162 [SOUND_MIXER_SPEAKER] = 7, // Speaker
1163 [SOUND_MIXER_RECLEV] = 8, // Recording level
1164 [SOUND_MIXER_VOLUME] = 9 // Master Volume
1165 };
1166
1167 static const unsigned mixreg[] = {
1168 AC97_PCMOUT_VOL,
1169 AC97_AUX_VOL,
1170 AC97_CD_VOL,
1171 AC97_LINEIN_VOL
1172 };
1173 unsigned char l, r, rl, rr, vidx;
1174 unsigned char attentbl[11] =
1175 { 63, 42, 26, 17, 14, 11, 8, 6, 4, 2, 0 };
1176 unsigned temp1;
1177 int i, val;
1178
1179 VALIDATE_STATE(s);
1180 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
1181 "cs4297a: mixer_ioctl(): s=0x%.8x cmd=0x%.8x\n",
1182 (unsigned) s, cmd));
1183#if CSDEBUG
1184 cs_printioctl(cmd);
1185#endif
1186#if CSDEBUG_INTERFACE
1187
1188 if ((cmd == SOUND_MIXER_CS_GETDBGMASK) ||
1189 (cmd == SOUND_MIXER_CS_SETDBGMASK) ||
1190 (cmd == SOUND_MIXER_CS_GETDBGLEVEL) ||
1191 (cmd == SOUND_MIXER_CS_SETDBGLEVEL))
1192 {
1193 switch (cmd) {
1194
1195 case SOUND_MIXER_CS_GETDBGMASK:
1196 return put_user(cs_debugmask,
1197 (unsigned long *) arg);
1198
1199 case SOUND_MIXER_CS_GETDBGLEVEL:
1200 return put_user(cs_debuglevel,
1201 (unsigned long *) arg);
1202
1203 case SOUND_MIXER_CS_SETDBGMASK:
1204 if (get_user(val, (unsigned long *) arg))
1205 return -EFAULT;
1206 cs_debugmask = val;
1207 return 0;
1208
1209 case SOUND_MIXER_CS_SETDBGLEVEL:
1210 if (get_user(val, (unsigned long *) arg))
1211 return -EFAULT;
1212 cs_debuglevel = val;
1213 return 0;
1214 default:
1215 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
1216 "cs4297a: mixer_ioctl(): ERROR unknown debug cmd\n"));
1217 return 0;
1218 }
1219 }
1220#endif
1221
1222 if (cmd == SOUND_MIXER_PRIVATE1) {
1223 return -EINVAL;
1224 }
1225 if (cmd == SOUND_MIXER_PRIVATE2) {
1226 // enable/disable/query spatializer
1227 if (get_user(val, (int *) arg))
1228 return -EFAULT;
1229 if (val != -1) {
1230 temp1 = (val & 0x3f) >> 2;
1231 cs4297a_write_ac97(s, AC97_3D_CONTROL, temp1);
1232 cs4297a_read_ac97(s, AC97_GENERAL_PURPOSE,
1233 &temp1);
1234 cs4297a_write_ac97(s, AC97_GENERAL_PURPOSE,
1235 temp1 | 0x2000);
1236 }
1237 cs4297a_read_ac97(s, AC97_3D_CONTROL, &temp1);
1238 return put_user((temp1 << 2) | 3, (int *) arg);
1239 }
1240 if (cmd == SOUND_MIXER_INFO) {
1241 mixer_info info;
1242 memset(&info, 0, sizeof(info));
1243 strlcpy(info.id, "CS4297a", sizeof(info.id));
1244 strlcpy(info.name, "Crystal CS4297a", sizeof(info.name));
1245 info.modify_counter = s->mix.modcnt;
1246 if (copy_to_user((void *) arg, &info, sizeof(info)))
1247 return -EFAULT;
1248 return 0;
1249 }
1250 if (cmd == SOUND_OLD_MIXER_INFO) {
1251 _old_mixer_info info;
1252 memset(&info, 0, sizeof(info));
1253 strlcpy(info.id, "CS4297a", sizeof(info.id));
1254 strlcpy(info.name, "Crystal CS4297a", sizeof(info.name));
1255 if (copy_to_user((void *) arg, &info, sizeof(info)))
1256 return -EFAULT;
1257 return 0;
1258 }
1259 if (cmd == OSS_GETVERSION)
1260 return put_user(SOUND_VERSION, (int *) arg);
1261
1262 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
1263 return -EINVAL;
1264
1265 // If ioctl has only the SIOC_READ bit(bit 31)
1266 // on, process the only-read commands.
1267 if (_SIOC_DIR(cmd) == _SIOC_READ) {
1268 switch (_IOC_NR(cmd)) {
1269 case SOUND_MIXER_RECSRC: // Arg contains a bit for each recording source
1270 cs4297a_read_ac97(s, AC97_RECORD_SELECT,
1271 &temp1);
1272 return put_user(mixer_src[temp1 & 7], (int *) arg);
1273
1274 case SOUND_MIXER_DEVMASK: // Arg contains a bit for each supported device
1275 return put_user(SOUND_MASK_PCM | SOUND_MASK_LINE |
1276 SOUND_MASK_VOLUME | SOUND_MASK_RECLEV,
1277 (int *) arg);
1278
1279 case SOUND_MIXER_RECMASK: // Arg contains a bit for each supported recording source
1280 return put_user(SOUND_MASK_LINE | SOUND_MASK_VOLUME,
1281 (int *) arg);
1282
1283 case SOUND_MIXER_STEREODEVS: // Mixer channels supporting stereo
1284 return put_user(SOUND_MASK_PCM | SOUND_MASK_LINE |
1285 SOUND_MASK_VOLUME | SOUND_MASK_RECLEV,
1286 (int *) arg);
1287
1288 case SOUND_MIXER_CAPS:
1289 return put_user(SOUND_CAP_EXCL_INPUT, (int *) arg);
1290
1291 default:
1292 i = _IOC_NR(cmd);
1293 if (i >= SOUND_MIXER_NRDEVICES
1294 || !(vidx = mixtable1[i]))
1295 return -EINVAL;
1296 return put_user(s->mix.vol[vidx - 1], (int *) arg);
1297 }
1298 }
1299 // If ioctl doesn't have both the SIOC_READ and
1300 // the SIOC_WRITE bit set, return invalid.
1301 if (_SIOC_DIR(cmd) != (_SIOC_READ | _SIOC_WRITE))
1302 return -EINVAL;
1303
1304 // Increment the count of volume writes.
1305 s->mix.modcnt++;
1306
1307 // Isolate the command; it must be a write.
1308 switch (_IOC_NR(cmd)) {
1309
1310 case SOUND_MIXER_RECSRC: // Arg contains a bit for each recording source
1311 if (get_user(val, (int *) arg))
1312 return -EFAULT;
1313 i = hweight32(val); // i = # bits on in val.
1314 if (i != 1) // One & only 1 bit must be on.
1315 return 0;
1316 for (i = 0; i < sizeof(mixer_src) / sizeof(int); i++) {
1317 if (val == mixer_src[i]) {
1318 temp1 = (i << 8) | i;
1319 cs4297a_write_ac97(s,
1320 AC97_RECORD_SELECT,
1321 temp1);
1322 return 0;
1323 }
1324 }
1325 return 0;
1326
1327 case SOUND_MIXER_VOLUME:
1328 if (get_user(val, (int *) arg))
1329 return -EFAULT;
1330 l = val & 0xff;
1331 if (l > 100)
1332 l = 100; // Max soundcard.h vol is 100.
1333 if (l < 6) {
1334 rl = 63;
1335 l = 0;
1336 } else
1337 rl = attentbl[(10 * l) / 100]; // Convert 0-100 vol to 63-0 atten.
1338
1339 r = (val >> 8) & 0xff;
1340 if (r > 100)
1341 r = 100; // Max right volume is 100, too
1342 if (r < 6) {
1343 rr = 63;
1344 r = 0;
1345 } else
1346 rr = attentbl[(10 * r) / 100]; // Convert volume to attenuation.
1347
1348 if ((rl > 60) && (rr > 60)) // If both l & r are 'low',
1349 temp1 = 0x8000; // turn on the mute bit.
1350 else
1351 temp1 = 0;
1352
1353 temp1 |= (rl << 8) | rr;
1354
1355 cs4297a_write_ac97(s, AC97_MASTER_VOL_STEREO, temp1);
1356 cs4297a_write_ac97(s, AC97_PHONE_VOL, temp1);
1357
1358#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1359 s->mix.vol[8] = ((unsigned int) r << 8) | l;
1360#else
1361 s->mix.vol[8] = val;
1362#endif
1363 return put_user(s->mix.vol[8], (int *) arg);
1364
1365 case SOUND_MIXER_SPEAKER:
1366 if (get_user(val, (int *) arg))
1367 return -EFAULT;
1368 l = val & 0xff;
1369 if (l > 100)
1370 l = 100;
1371 if (l < 3) {
1372 rl = 0;
1373 l = 0;
1374 } else {
1375 rl = (l * 2 - 5) / 13; // Convert 0-100 range to 0-15.
1376 l = (rl * 13 + 5) / 2;
1377 }
1378
1379 if (rl < 3) {
1380 temp1 = 0x8000;
1381 rl = 0;
1382 } else
1383 temp1 = 0;
1384 rl = 15 - rl; // Convert volume to attenuation.
1385 temp1 |= rl << 1;
1386 cs4297a_write_ac97(s, AC97_PCBEEP_VOL, temp1);
1387
1388#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1389 s->mix.vol[6] = l << 8;
1390#else
1391 s->mix.vol[6] = val;
1392#endif
1393 return put_user(s->mix.vol[6], (int *) arg);
1394
1395 case SOUND_MIXER_RECLEV:
1396 if (get_user(val, (int *) arg))
1397 return -EFAULT;
1398 l = val & 0xff;
1399 if (l > 100)
1400 l = 100;
1401 r = (val >> 8) & 0xff;
1402 if (r > 100)
1403 r = 100;
1404 rl = (l * 2 - 5) / 13; // Convert 0-100 scale to 0-15.
1405 rr = (r * 2 - 5) / 13;
1406 if (rl < 3 && rr < 3)
1407 temp1 = 0x8000;
1408 else
1409 temp1 = 0;
1410
1411 temp1 = temp1 | (rl << 8) | rr;
1412 cs4297a_write_ac97(s, AC97_RECORD_GAIN, temp1);
1413
1414#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1415 s->mix.vol[7] = ((unsigned int) r << 8) | l;
1416#else
1417 s->mix.vol[7] = val;
1418#endif
1419 return put_user(s->mix.vol[7], (int *) arg);
1420
1421 case SOUND_MIXER_MIC:
1422 if (get_user(val, (int *) arg))
1423 return -EFAULT;
1424 l = val & 0xff;
1425 if (l > 100)
1426 l = 100;
1427 if (l < 1) {
1428 l = 0;
1429 rl = 0;
1430 } else {
1431 rl = ((unsigned) l * 5 - 4) / 16; // Convert 0-100 range to 0-31.
1432 l = (rl * 16 + 4) / 5;
1433 }
1434 cs4297a_read_ac97(s, AC97_MIC_VOL, &temp1);
1435 temp1 &= 0x40; // Isolate 20db gain bit.
1436 if (rl < 3) {
1437 temp1 |= 0x8000;
1438 rl = 0;
1439 }
1440 rl = 31 - rl; // Convert volume to attenuation.
1441 temp1 |= rl;
1442 cs4297a_write_ac97(s, AC97_MIC_VOL, temp1);
1443
1444#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1445 s->mix.vol[5] = val << 8;
1446#else
1447 s->mix.vol[5] = val;
1448#endif
1449 return put_user(s->mix.vol[5], (int *) arg);
1450
1451
1452 case SOUND_MIXER_SYNTH:
1453 if (get_user(val, (int *) arg))
1454 return -EFAULT;
1455 l = val & 0xff;
1456 if (l > 100)
1457 l = 100;
1458 if (get_user(val, (int *) arg))
1459 return -EFAULT;
1460 r = (val >> 8) & 0xff;
1461 if (r > 100)
1462 r = 100;
1463 rl = (l * 2 - 11) / 3; // Convert 0-100 range to 0-63.
1464 rr = (r * 2 - 11) / 3;
1465 if (rl < 3) // If l is low, turn on
1466 temp1 = 0x0080; // the mute bit.
1467 else
1468 temp1 = 0;
1469
1470 rl = 63 - rl; // Convert vol to attenuation.
1471// writel(temp1 | rl, s->pBA0 + FMLVC);
1472 if (rr < 3) // If rr is low, turn on
1473 temp1 = 0x0080; // the mute bit.
1474 else
1475 temp1 = 0;
1476 rr = 63 - rr; // Convert vol to attenuation.
1477// writel(temp1 | rr, s->pBA0 + FMRVC);
1478
1479#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1480 s->mix.vol[4] = (r << 8) | l;
1481#else
1482 s->mix.vol[4] = val;
1483#endif
1484 return put_user(s->mix.vol[4], (int *) arg);
1485
1486
1487 default:
1488 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
1489 "cs4297a: mixer_ioctl(): default\n"));
1490
1491 i = _IOC_NR(cmd);
1492 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i]))
1493 return -EINVAL;
1494 if (get_user(val, (int *) arg))
1495 return -EFAULT;
1496 l = val & 0xff;
1497 if (l > 100)
1498 l = 100;
1499 if (l < 1) {
1500 l = 0;
1501 rl = 31;
1502 } else
1503 rl = (attentbl[(l * 10) / 100]) >> 1;
1504
1505 r = (val >> 8) & 0xff;
1506 if (r > 100)
1507 r = 100;
1508 if (r < 1) {
1509 r = 0;
1510 rr = 31;
1511 } else
1512 rr = (attentbl[(r * 10) / 100]) >> 1;
1513 if ((rl > 30) && (rr > 30))
1514 temp1 = 0x8000;
1515 else
1516 temp1 = 0;
1517 temp1 = temp1 | (rl << 8) | rr;
1518 cs4297a_write_ac97(s, mixreg[vidx - 1], temp1);
1519
1520#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1521 s->mix.vol[vidx - 1] = ((unsigned int) r << 8) | l;
1522#else
1523 s->mix.vol[vidx - 1] = val;
1524#endif
1525 return put_user(s->mix.vol[vidx - 1], (int *) arg);
1526 }
1527}
1528
1529
1530// ---------------------------------------------------------------------
1531
1532static int cs4297a_open_mixdev(struct inode *inode, struct file *file)
1533{
1534 int minor = iminor(inode);
1535 struct cs4297a_state *s=NULL;
1536 struct list_head *entry;
1537
1538 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
1539 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()+\n"));
1540
1541 list_for_each(entry, &cs4297a_devs)
1542 {
1543 s = list_entry(entry, struct cs4297a_state, list);
1544 if(s->dev_mixer == minor)
1545 break;
1546 }
1547 if (!s)
1548 {
1549 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
1550 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- -ENODEV\n"));
1551 return -ENODEV;
1552 }
1553 VALIDATE_STATE(s);
1554 file->private_data = s;
1555
1556 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
1557 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- 0\n"));
1558
1559 return nonseekable_open(inode, file);
1560}
1561
1562
1563static int cs4297a_release_mixdev(struct inode *inode, struct file *file)
1564{
1565 struct cs4297a_state *s =
1566 (struct cs4297a_state *) file->private_data;
1567
1568 VALIDATE_STATE(s);
1569 return 0;
1570}
1571
1572
1573static int cs4297a_ioctl_mixdev(struct inode *inode, struct file *file,
1574 unsigned int cmd, unsigned long arg)
1575{
1576 return mixer_ioctl((struct cs4297a_state *) file->private_data, cmd,
1577 arg);
1578}
1579
1580
1581// ******************************************************************************************
1582// Mixer file operations struct.
1583// ******************************************************************************************
1584static /*const */ struct file_operations cs4297a_mixer_fops = {
1585 .owner = THIS_MODULE,
1586 .llseek = no_llseek,
1587 .ioctl = cs4297a_ioctl_mixdev,
1588 .open = cs4297a_open_mixdev,
1589 .release = cs4297a_release_mixdev,
1590};
1591
1592// ---------------------------------------------------------------------
1593
1594
1595static int drain_adc(struct cs4297a_state *s, int nonblock)
1596{
1597 /* This routine serves no purpose currently - any samples
1598 sitting in the receive queue will just be processed by the
1599 background consumer. This would be different if DMA
1600 actually stopped when there were no clients. */
1601 return 0;
1602}
1603
1604static int drain_dac(struct cs4297a_state *s, int nonblock)
1605{
1606 DECLARE_WAITQUEUE(wait, current);
1607 unsigned long flags;
1608 unsigned hwptr;
1609 unsigned tmo;
1610 int count;
1611
1612 if (s->dma_dac.mapped)
1613 return 0;
1614 if (nonblock)
1615 return -EBUSY;
1616 add_wait_queue(&s->dma_dac.wait, &wait);
1617 while ((count = __raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX))) ||
1618 (s->dma_dac.count > 0)) {
1619 if (!signal_pending(current)) {
1620 set_current_state(TASK_INTERRUPTIBLE);
1621 /* XXXKW is this calculation working? */
1622 tmo = ((count * FRAME_TX_US) * HZ) / 1000000;
1623 schedule_timeout(tmo + 1);
1624 } else {
1625 /* XXXKW do I care if there is a signal pending? */
1626 }
1627 }
1628 spin_lock_irqsave(&s->lock, flags);
1629 /* Reset the bookkeeping */
1630 hwptr = (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1631 s->dma_dac.descrtab_phys) / sizeof(serdma_descr_t));
1632 s->dma_dac.hwptr = s->dma_dac.swptr = hwptr;
1633 spin_unlock_irqrestore(&s->lock, flags);
1634 remove_wait_queue(&s->dma_dac.wait, &wait);
1635 current->state = TASK_RUNNING;
1636 return 0;
1637}
1638
1639
1640// ---------------------------------------------------------------------
1641
1642static ssize_t cs4297a_read(struct file *file, char *buffer, size_t count,
1643 loff_t * ppos)
1644{
1645 struct cs4297a_state *s =
1646 (struct cs4297a_state *) file->private_data;
1647 ssize_t ret;
1648 unsigned long flags;
1649 int cnt, count_fr, cnt_by;
1650 unsigned copied = 0;
1651
1652 CS_DBGOUT(CS_FUNCTION | CS_WAVE_READ, 2,
1653 printk(KERN_INFO "cs4297a: cs4297a_read()+ %d \n", count));
1654
1655 VALIDATE_STATE(s);
1656 if (s->dma_adc.mapped)
1657 return -ENXIO;
1658 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1659 return ret;
1660 if (!access_ok(VERIFY_WRITE, buffer, count))
1661 return -EFAULT;
1662 ret = 0;
1663//
1664// "count" is the amount of bytes to read (from app), is decremented each loop
1665// by the amount of bytes that have been returned to the user buffer.
1666// "cnt" is the running total of each read from the buffer (changes each loop)
1667// "buffer" points to the app's buffer
1668// "ret" keeps a running total of the amount of bytes that have been copied
1669// to the user buffer.
1670// "copied" is the total bytes copied into the user buffer for each loop.
1671//
1672 while (count > 0) {
1673 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
1674 "_read() count>0 count=%d .count=%d .swptr=%d .hwptr=%d \n",
1675 count, s->dma_adc.count,
1676 s->dma_adc.swptr, s->dma_adc.hwptr));
1677 spin_lock_irqsave(&s->lock, flags);
1678
1679 /* cnt will be the number of available samples (16-bit
1680 stereo); it starts out as the maxmimum consequetive
1681 samples */
1682 cnt = (s->dma_adc.sb_end - s->dma_adc.sb_swptr) / 2;
1683 count_fr = s->dma_adc.count / FRAME_SAMPLE_BYTES;
1684
1685 // dma_adc.count is the current total bytes that have not been read.
1686 // if the amount of unread bytes from the current sw pointer to the
1687 // end of the buffer is greater than the current total bytes that
1688 // have not been read, then set the "cnt" (unread bytes) to the
1689 // amount of unread bytes.
1690
1691 if (count_fr < cnt)
1692 cnt = count_fr;
1693 cnt_by = cnt * FRAME_SAMPLE_BYTES;
1694 spin_unlock_irqrestore(&s->lock, flags);
1695 //
1696 // if we are converting from 8/16 then we need to copy
1697 // twice the number of 16 bit bytes then 8 bit bytes.
1698 //
1699 if (s->conversion) {
1700 if (cnt_by > (count * 2)) {
1701 cnt = (count * 2) / FRAME_SAMPLE_BYTES;
1702 cnt_by = count * 2;
1703 }
1704 } else {
1705 if (cnt_by > count) {
1706 cnt = count / FRAME_SAMPLE_BYTES;
1707 cnt_by = count;
1708 }
1709 }
1710 //
1711 // "cnt" NOW is the smaller of the amount that will be read,
1712 // and the amount that is requested in this read (or partial).
1713 // if there are no bytes in the buffer to read, then start the
1714 // ADC and wait for the interrupt handler to wake us up.
1715 //
1716 if (cnt <= 0) {
1717
1718 // start up the dma engine and then continue back to the top of
1719 // the loop when wake up occurs.
1720 start_adc(s);
1721 if (file->f_flags & O_NONBLOCK)
1722 return ret ? ret : -EAGAIN;
1723 interruptible_sleep_on(&s->dma_adc.wait);
1724 if (signal_pending(current))
1725 return ret ? ret : -ERESTARTSYS;
1726 continue;
1727 }
1728 // there are bytes in the buffer to read.
1729 // copy from the hw buffer over to the user buffer.
1730 // user buffer is designated by "buffer"
1731 // virtual address to copy from is dma_buf+swptr
1732 // the "cnt" is the number of bytes to read.
1733
1734 CS_DBGOUT(CS_WAVE_READ, 2, printk(KERN_INFO
1735 "_read() copy_to cnt=%d count=%d ", cnt_by, count));
1736 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
1737 " .sbufsz=%d .count=%d buffer=0x%.8x ret=%d\n",
1738 s->dma_adc.sbufsz, s->dma_adc.count,
1739 (unsigned) buffer, ret));
1740
1741 if (copy_to_user (buffer, ((void *)s->dma_adc.sb_swptr), cnt_by))
1742 return ret ? ret : -EFAULT;
1743 copied = cnt_by;
1744
1745 /* Return the descriptors */
1746 spin_lock_irqsave(&s->lock, flags);
1747 CS_DBGOUT(CS_FUNCTION, 2,
1748 printk(KERN_INFO "cs4297a: upd_rcv sw->hw %x/%x\n", s->dma_adc.swptr, s->dma_adc.hwptr));
1749 s->dma_adc.count -= cnt_by;
1750 s->dma_adc.sb_swptr += cnt * 2;
1751 if (s->dma_adc.sb_swptr == s->dma_adc.sb_end)
1752 s->dma_adc.sb_swptr = s->dma_adc.sample_buf;
1753 spin_unlock_irqrestore(&s->lock, flags);
1754 count -= copied;
1755 buffer += copied;
1756 ret += copied;
1757 start_adc(s);
1758 }
1759 CS_DBGOUT(CS_FUNCTION | CS_WAVE_READ, 2,
1760 printk(KERN_INFO "cs4297a: cs4297a_read()- %d\n", ret));
1761 return ret;
1762}
1763
1764
1765static ssize_t cs4297a_write(struct file *file, const char *buffer,
1766 size_t count, loff_t * ppos)
1767{
1768 struct cs4297a_state *s =
1769 (struct cs4297a_state *) file->private_data;
1770 ssize_t ret;
1771 unsigned long flags;
1772 unsigned swptr, hwptr;
1773 int cnt;
1774
1775 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE, 2,
1776 printk(KERN_INFO "cs4297a: cs4297a_write()+ count=%d\n",
1777 count));
1778 VALIDATE_STATE(s);
1779
1780 if (s->dma_dac.mapped)
1781 return -ENXIO;
1782 if (!s->dma_dac.ready && (ret = prog_dmabuf_dac(s)))
1783 return ret;
1784 if (!access_ok(VERIFY_READ, buffer, count))
1785 return -EFAULT;
1786 ret = 0;
1787 while (count > 0) {
1788 serdma_t *d = &s->dma_dac;
1789 int copy_cnt;
1790 u32 *s_tmpl;
1791 u32 *t_tmpl;
1792 u32 left, right;
1793 int swap = (s->prop_dac.fmt == AFMT_S16_LE) || (s->prop_dac.fmt == AFMT_U16_LE);
1794
1795 /* XXXXXX this is broken for BLOAT_FACTOR */
1796 spin_lock_irqsave(&s->lock, flags);
1797 if (d->count < 0) {
1798 d->count = 0;
1799 d->swptr = d->hwptr;
1800 }
1801 if (d->underrun) {
1802 d->underrun = 0;
1803 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1804 d->descrtab_phys) / sizeof(serdma_descr_t));
1805 d->swptr = d->hwptr = hwptr;
1806 }
1807 swptr = d->swptr;
1808 cnt = d->sbufsz - (swptr * FRAME_SAMPLE_BYTES);
1809 /* Will this write fill up the buffer? */
1810 if (d->count + cnt > d->sbufsz)
1811 cnt = d->sbufsz - d->count;
1812 spin_unlock_irqrestore(&s->lock, flags);
1813 if (cnt > count)
1814 cnt = count;
1815 if (cnt <= 0) {
1816 start_dac(s);
1817 if (file->f_flags & O_NONBLOCK)
1818 return ret ? ret : -EAGAIN;
1819 interruptible_sleep_on(&d->wait);
1820 if (signal_pending(current))
1821 return ret ? ret : -ERESTARTSYS;
1822 continue;
1823 }
1824 if (copy_from_user(d->sample_buf, buffer, cnt))
1825 return ret ? ret : -EFAULT;
1826
1827 copy_cnt = cnt;
1828 s_tmpl = (u32 *)d->sample_buf;
1829 t_tmpl = (u32 *)(d->dma_buf + (swptr * 4));
1830
1831 /* XXXKW assuming 16-bit stereo! */
1832 do {
1833 u32 tmp;
1834
1835 t_tmpl[0] = cpu_to_be32(0x98000000);
1836
1837 tmp = be32_to_cpu(s_tmpl[0]);
1838 left = tmp & 0xffff;
1839 right = tmp >> 16;
1840 if (swap) {
1841 left = swab16(left);
1842 right = swab16(right);
1843 }
1844 t_tmpl[1] = cpu_to_be32(left >> 8);
1845 t_tmpl[2] = cpu_to_be32(((left & 0xff) << 24) |
1846 (right << 4));
1847
1848 s_tmpl++;
1849 t_tmpl += 8;
1850 copy_cnt -= 4;
1851 } while (copy_cnt);
1852
1853 /* Mux in any pending read/write accesses */
1854 if (s->reg_request) {
1855 *(u64 *)(d->dma_buf + (swptr * 4)) |=
1856 cpu_to_be64(s->reg_request);
1857 s->reg_request = 0;
1858 wake_up(&s->dma_dac.reg_wait);
1859 }
1860
1861 CS_DBGOUT(CS_WAVE_WRITE, 4,
1862 printk(KERN_INFO
1863 "cs4297a: copy in %d to swptr %x\n", cnt, swptr));
1864
1865 swptr = (swptr + (cnt/FRAME_SAMPLE_BYTES)) % d->ringsz;
1866 __raw_writeq(cnt/FRAME_SAMPLE_BYTES, SS_CSR(R_SER_DMA_DSCR_COUNT_TX));
1867 spin_lock_irqsave(&s->lock, flags);
1868 d->swptr = swptr;
1869 d->count += cnt;
1870 d->endcleared = 0;
1871 spin_unlock_irqrestore(&s->lock, flags);
1872 count -= cnt;
1873 buffer += cnt;
1874 ret += cnt;
1875 start_dac(s);
1876 }
1877 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE, 2,
1878 printk(KERN_INFO "cs4297a: cs4297a_write()- %d\n", ret));
1879 return ret;
1880}
1881
1882
1883static unsigned int cs4297a_poll(struct file *file,
1884 struct poll_table_struct *wait)
1885{
1886 struct cs4297a_state *s =
1887 (struct cs4297a_state *) file->private_data;
1888 unsigned long flags;
1889 unsigned int mask = 0;
1890
1891 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1892 printk(KERN_INFO "cs4297a: cs4297a_poll()+\n"));
1893 VALIDATE_STATE(s);
1894 if (file->f_mode & FMODE_WRITE) {
1895 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1896 printk(KERN_INFO
1897 "cs4297a: cs4297a_poll() wait on FMODE_WRITE\n"));
1898 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
1899 return 0;
1900 poll_wait(file, &s->dma_dac.wait, wait);
1901 }
1902 if (file->f_mode & FMODE_READ) {
1903 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1904 printk(KERN_INFO
1905 "cs4297a: cs4297a_poll() wait on FMODE_READ\n"));
1906 if(!s->dma_dac.ready && prog_dmabuf_adc(s))
1907 return 0;
1908 poll_wait(file, &s->dma_adc.wait, wait);
1909 }
1910 spin_lock_irqsave(&s->lock, flags);
1911 cs4297a_update_ptr(s,CS_FALSE);
1912 if (file->f_mode & FMODE_WRITE) {
1913 if (s->dma_dac.mapped) {
1914 if (s->dma_dac.count >=
1915 (signed) s->dma_dac.fragsize) {
1916 if (s->dma_dac.wakeup)
1917 mask |= POLLOUT | POLLWRNORM;
1918 else
1919 mask = 0;
1920 s->dma_dac.wakeup = 0;
1921 }
1922 } else {
1923 if ((signed) (s->dma_dac.sbufsz/2) >= s->dma_dac.count)
1924 mask |= POLLOUT | POLLWRNORM;
1925 }
1926 } else if (file->f_mode & FMODE_READ) {
1927 if (s->dma_adc.mapped) {
1928 if (s->dma_adc.count >= (signed) s->dma_adc.fragsize)
1929 mask |= POLLIN | POLLRDNORM;
1930 } else {
1931 if (s->dma_adc.count > 0)
1932 mask |= POLLIN | POLLRDNORM;
1933 }
1934 }
1935 spin_unlock_irqrestore(&s->lock, flags);
1936 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1937 printk(KERN_INFO "cs4297a: cs4297a_poll()- 0x%.8x\n",
1938 mask));
1939 return mask;
1940}
1941
1942
1943static int cs4297a_mmap(struct file *file, struct vm_area_struct *vma)
1944{
1945 /* XXXKW currently no mmap support */
1946 return -EINVAL;
1947 return 0;
1948}
1949
1950
1951static int cs4297a_ioctl(struct inode *inode, struct file *file,
1952 unsigned int cmd, unsigned long arg)
1953{
1954 struct cs4297a_state *s =
1955 (struct cs4297a_state *) file->private_data;
1956 unsigned long flags;
1957 audio_buf_info abinfo;
1958 count_info cinfo;
1959 int val, mapped, ret;
1960
1961 CS_DBGOUT(CS_FUNCTION|CS_IOCTL, 4, printk(KERN_INFO
1962 "cs4297a: cs4297a_ioctl(): file=0x%.8x cmd=0x%.8x\n",
1963 (unsigned) file, cmd));
1964#if CSDEBUG
1965 cs_printioctl(cmd);
1966#endif
1967 VALIDATE_STATE(s);
1968 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1969 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1970 switch (cmd) {
1971 case OSS_GETVERSION:
1972 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
1973 "cs4297a: cs4297a_ioctl(): SOUND_VERSION=0x%.8x\n",
1974 SOUND_VERSION));
1975 return put_user(SOUND_VERSION, (int *) arg);
1976
1977 case SNDCTL_DSP_SYNC:
1978 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
1979 "cs4297a: cs4297a_ioctl(): DSP_SYNC\n"));
1980 if (file->f_mode & FMODE_WRITE)
1981 return drain_dac(s,
1982 0 /*file->f_flags & O_NONBLOCK */
1983 );
1984 return 0;
1985
1986 case SNDCTL_DSP_SETDUPLEX:
1987 return 0;
1988
1989 case SNDCTL_DSP_GETCAPS:
1990 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
1991 DSP_CAP_TRIGGER | DSP_CAP_MMAP,
1992 (int *) arg);
1993
1994 case SNDCTL_DSP_RESET:
1995 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
1996 "cs4297a: cs4297a_ioctl(): DSP_RESET\n"));
1997 if (file->f_mode & FMODE_WRITE) {
1998 stop_dac(s);
1999 synchronize_irq(s->irq);
2000 s->dma_dac.count = s->dma_dac.total_bytes =
2001 s->dma_dac.blocks = s->dma_dac.wakeup = 0;
2002 s->dma_dac.swptr = s->dma_dac.hwptr =
2003 (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
2004 s->dma_dac.descrtab_phys) / sizeof(serdma_descr_t));
2005 }
2006 if (file->f_mode & FMODE_READ) {
2007 stop_adc(s);
2008 synchronize_irq(s->irq);
2009 s->dma_adc.count = s->dma_adc.total_bytes =
2010 s->dma_adc.blocks = s->dma_dac.wakeup = 0;
2011 s->dma_adc.swptr = s->dma_adc.hwptr =
2012 (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
2013 s->dma_adc.descrtab_phys) / sizeof(serdma_descr_t));
2014 }
2015 return 0;
2016
2017 case SNDCTL_DSP_SPEED:
2018 if (get_user(val, (int *) arg))
2019 return -EFAULT;
2020 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2021 "cs4297a: cs4297a_ioctl(): DSP_SPEED val=%d -> 48000\n", val));
2022 val = 48000;
2023 return put_user(val, (int *) arg);
2024
2025 case SNDCTL_DSP_STEREO:
2026 if (get_user(val, (int *) arg))
2027 return -EFAULT;
2028 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2029 "cs4297a: cs4297a_ioctl(): DSP_STEREO val=%d\n", val));
2030 if (file->f_mode & FMODE_READ) {
2031 stop_adc(s);
2032 s->dma_adc.ready = 0;
2033 s->prop_adc.channels = val ? 2 : 1;
2034 }
2035 if (file->f_mode & FMODE_WRITE) {
2036 stop_dac(s);
2037 s->dma_dac.ready = 0;
2038 s->prop_dac.channels = val ? 2 : 1;
2039 }
2040 return 0;
2041
2042 case SNDCTL_DSP_CHANNELS:
2043 if (get_user(val, (int *) arg))
2044 return -EFAULT;
2045 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2046 "cs4297a: cs4297a_ioctl(): DSP_CHANNELS val=%d\n",
2047 val));
2048 if (val != 0) {
2049 if (file->f_mode & FMODE_READ) {
2050 stop_adc(s);
2051 s->dma_adc.ready = 0;
2052 if (val >= 2)
2053 s->prop_adc.channels = 2;
2054 else
2055 s->prop_adc.channels = 1;
2056 }
2057 if (file->f_mode & FMODE_WRITE) {
2058 stop_dac(s);
2059 s->dma_dac.ready = 0;
2060 if (val >= 2)
2061 s->prop_dac.channels = 2;
2062 else
2063 s->prop_dac.channels = 1;
2064 }
2065 }
2066
2067 if (file->f_mode & FMODE_WRITE)
2068 val = s->prop_dac.channels;
2069 else if (file->f_mode & FMODE_READ)
2070 val = s->prop_adc.channels;
2071
2072 return put_user(val, (int *) arg);
2073
2074 case SNDCTL_DSP_GETFMTS: // Returns a mask
2075 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2076 "cs4297a: cs4297a_ioctl(): DSP_GETFMT val=0x%.8x\n",
2077 AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
2078 AFMT_U8));
2079 return put_user(AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
2080 AFMT_U8, (int *) arg);
2081
2082 case SNDCTL_DSP_SETFMT:
2083 if (get_user(val, (int *) arg))
2084 return -EFAULT;
2085 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2086 "cs4297a: cs4297a_ioctl(): DSP_SETFMT val=0x%.8x\n",
2087 val));
2088 if (val != AFMT_QUERY) {
2089 if (file->f_mode & FMODE_READ) {
2090 stop_adc(s);
2091 s->dma_adc.ready = 0;
2092 if (val != AFMT_S16_LE
2093 && val != AFMT_U16_LE && val != AFMT_S8
2094 && val != AFMT_U8)
2095 val = AFMT_U8;
2096 s->prop_adc.fmt = val;
2097 s->prop_adc.fmt_original = s->prop_adc.fmt;
2098 }
2099 if (file->f_mode & FMODE_WRITE) {
2100 stop_dac(s);
2101 s->dma_dac.ready = 0;
2102 if (val != AFMT_S16_LE
2103 && val != AFMT_U16_LE && val != AFMT_S8
2104 && val != AFMT_U8)
2105 val = AFMT_U8;
2106 s->prop_dac.fmt = val;
2107 s->prop_dac.fmt_original = s->prop_dac.fmt;
2108 }
2109 } else {
2110 if (file->f_mode & FMODE_WRITE)
2111 val = s->prop_dac.fmt_original;
2112 else if (file->f_mode & FMODE_READ)
2113 val = s->prop_adc.fmt_original;
2114 }
2115 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2116 "cs4297a: cs4297a_ioctl(): DSP_SETFMT return val=0x%.8x\n",
2117 val));
2118 return put_user(val, (int *) arg);
2119
2120 case SNDCTL_DSP_POST:
2121 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
2122 "cs4297a: cs4297a_ioctl(): DSP_POST\n"));
2123 return 0;
2124
2125 case SNDCTL_DSP_GETTRIGGER:
2126 val = 0;
2127 if (file->f_mode & s->ena & FMODE_READ)
2128 val |= PCM_ENABLE_INPUT;
2129 if (file->f_mode & s->ena & FMODE_WRITE)
2130 val |= PCM_ENABLE_OUTPUT;
2131 return put_user(val, (int *) arg);
2132
2133 case SNDCTL_DSP_SETTRIGGER:
2134 if (get_user(val, (int *) arg))
2135 return -EFAULT;
2136 if (file->f_mode & FMODE_READ) {
2137 if (val & PCM_ENABLE_INPUT) {
2138 if (!s->dma_adc.ready
2139 && (ret = prog_dmabuf_adc(s)))
2140 return ret;
2141 start_adc(s);
2142 } else
2143 stop_adc(s);
2144 }
2145 if (file->f_mode & FMODE_WRITE) {
2146 if (val & PCM_ENABLE_OUTPUT) {
2147 if (!s->dma_dac.ready
2148 && (ret = prog_dmabuf_dac(s)))
2149 return ret;
2150 start_dac(s);
2151 } else
2152 stop_dac(s);
2153 }
2154 return 0;
2155
2156 case SNDCTL_DSP_GETOSPACE:
2157 if (!(file->f_mode & FMODE_WRITE))
2158 return -EINVAL;
2159 if (!s->dma_dac.ready && (val = prog_dmabuf_dac(s)))
2160 return val;
2161 spin_lock_irqsave(&s->lock, flags);
2162 cs4297a_update_ptr(s,CS_FALSE);
2163 abinfo.fragsize = s->dma_dac.fragsize;
2164 if (s->dma_dac.mapped)
2165 abinfo.bytes = s->dma_dac.sbufsz;
2166 else
2167 abinfo.bytes =
2168 s->dma_dac.sbufsz - s->dma_dac.count;
2169 abinfo.fragstotal = s->dma_dac.numfrag;
2170 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
2171 CS_DBGOUT(CS_FUNCTION | CS_PARMS, 4, printk(KERN_INFO
2172 "cs4297a: cs4297a_ioctl(): GETOSPACE .fragsize=%d .bytes=%d .fragstotal=%d .fragments=%d\n",
2173 abinfo.fragsize,abinfo.bytes,abinfo.fragstotal,
2174 abinfo.fragments));
2175 spin_unlock_irqrestore(&s->lock, flags);
2176 return copy_to_user((void *) arg, &abinfo,
2177 sizeof(abinfo)) ? -EFAULT : 0;
2178
2179 case SNDCTL_DSP_GETISPACE:
2180 if (!(file->f_mode & FMODE_READ))
2181 return -EINVAL;
2182 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)))
2183 return val;
2184 spin_lock_irqsave(&s->lock, flags);
2185 cs4297a_update_ptr(s,CS_FALSE);
2186 if (s->conversion) {
2187 abinfo.fragsize = s->dma_adc.fragsize / 2;
2188 abinfo.bytes = s->dma_adc.count / 2;
2189 abinfo.fragstotal = s->dma_adc.numfrag;
2190 abinfo.fragments =
2191 abinfo.bytes >> (s->dma_adc.fragshift - 1);
2192 } else {
2193 abinfo.fragsize = s->dma_adc.fragsize;
2194 abinfo.bytes = s->dma_adc.count;
2195 abinfo.fragstotal = s->dma_adc.numfrag;
2196 abinfo.fragments =
2197 abinfo.bytes >> s->dma_adc.fragshift;
2198 }
2199 spin_unlock_irqrestore(&s->lock, flags);
2200 return copy_to_user((void *) arg, &abinfo,
2201 sizeof(abinfo)) ? -EFAULT : 0;
2202
2203 case SNDCTL_DSP_NONBLOCK:
2204 file->f_flags |= O_NONBLOCK;
2205 return 0;
2206
2207 case SNDCTL_DSP_GETODELAY:
2208 if (!(file->f_mode & FMODE_WRITE))
2209 return -EINVAL;
2210 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
2211 return 0;
2212 spin_lock_irqsave(&s->lock, flags);
2213 cs4297a_update_ptr(s,CS_FALSE);
2214 val = s->dma_dac.count;
2215 spin_unlock_irqrestore(&s->lock, flags);
2216 return put_user(val, (int *) arg);
2217
2218 case SNDCTL_DSP_GETIPTR:
2219 if (!(file->f_mode & FMODE_READ))
2220 return -EINVAL;
2221 if(!s->dma_adc.ready && prog_dmabuf_adc(s))
2222 return 0;
2223 spin_lock_irqsave(&s->lock, flags);
2224 cs4297a_update_ptr(s,CS_FALSE);
2225 cinfo.bytes = s->dma_adc.total_bytes;
2226 if (s->dma_adc.mapped) {
2227 cinfo.blocks =
2228 (cinfo.bytes >> s->dma_adc.fragshift) -
2229 s->dma_adc.blocks;
2230 s->dma_adc.blocks =
2231 cinfo.bytes >> s->dma_adc.fragshift;
2232 } else {
2233 if (s->conversion) {
2234 cinfo.blocks =
2235 s->dma_adc.count /
2236 2 >> (s->dma_adc.fragshift - 1);
2237 } else
2238 cinfo.blocks =
2239 s->dma_adc.count >> s->dma_adc.
2240 fragshift;
2241 }
2242 if (s->conversion)
2243 cinfo.ptr = s->dma_adc.hwptr / 2;
2244 else
2245 cinfo.ptr = s->dma_adc.hwptr;
2246 if (s->dma_adc.mapped)
2247 s->dma_adc.count &= s->dma_adc.fragsize - 1;
2248 spin_unlock_irqrestore(&s->lock, flags);
2249 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2250
2251 case SNDCTL_DSP_GETOPTR:
2252 if (!(file->f_mode & FMODE_WRITE))
2253 return -EINVAL;
2254 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
2255 return 0;
2256 spin_lock_irqsave(&s->lock, flags);
2257 cs4297a_update_ptr(s,CS_FALSE);
2258 cinfo.bytes = s->dma_dac.total_bytes;
2259 if (s->dma_dac.mapped) {
2260 cinfo.blocks =
2261 (cinfo.bytes >> s->dma_dac.fragshift) -
2262 s->dma_dac.blocks;
2263 s->dma_dac.blocks =
2264 cinfo.bytes >> s->dma_dac.fragshift;
2265 } else {
2266 cinfo.blocks =
2267 s->dma_dac.count >> s->dma_dac.fragshift;
2268 }
2269 cinfo.ptr = s->dma_dac.hwptr;
2270 if (s->dma_dac.mapped)
2271 s->dma_dac.count &= s->dma_dac.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_GETBLKSIZE:
2276 if (file->f_mode & FMODE_WRITE) {
2277 if ((val = prog_dmabuf_dac(s)))
2278 return val;
2279 return put_user(s->dma_dac.fragsize, (int *) arg);
2280 }
2281 if ((val = prog_dmabuf_adc(s)))
2282 return val;
2283 if (s->conversion)
2284 return put_user(s->dma_adc.fragsize / 2,
2285 (int *) arg);
2286 else
2287 return put_user(s->dma_adc.fragsize, (int *) arg);
2288
2289 case SNDCTL_DSP_SETFRAGMENT:
2290 if (get_user(val, (int *) arg))
2291 return -EFAULT;
2292 return 0; // Say OK, but do nothing.
2293
2294 case SNDCTL_DSP_SUBDIVIDE:
2295 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision)
2296 || (file->f_mode & FMODE_WRITE
2297 && s->dma_dac.subdivision)) return -EINVAL;
2298 if (get_user(val, (int *) arg))
2299 return -EFAULT;
2300 if (val != 1 && val != 2 && val != 4)
2301 return -EINVAL;
2302 if (file->f_mode & FMODE_READ)
2303 s->dma_adc.subdivision = val;
2304 else if (file->f_mode & FMODE_WRITE)
2305 s->dma_dac.subdivision = val;
2306 return 0;
2307
2308 case SOUND_PCM_READ_RATE:
2309 if (file->f_mode & FMODE_READ)
2310 return put_user(s->prop_adc.rate, (int *) arg);
2311 else if (file->f_mode & FMODE_WRITE)
2312 return put_user(s->prop_dac.rate, (int *) arg);
2313
2314 case SOUND_PCM_READ_CHANNELS:
2315 if (file->f_mode & FMODE_READ)
2316 return put_user(s->prop_adc.channels, (int *) arg);
2317 else if (file->f_mode & FMODE_WRITE)
2318 return put_user(s->prop_dac.channels, (int *) arg);
2319
2320 case SOUND_PCM_READ_BITS:
2321 if (file->f_mode & FMODE_READ)
2322 return
2323 put_user(
2324 (s->prop_adc.
2325 fmt & (AFMT_S8 | AFMT_U8)) ? 8 : 16,
2326 (int *) arg);
2327 else if (file->f_mode & FMODE_WRITE)
2328 return
2329 put_user(
2330 (s->prop_dac.
2331 fmt & (AFMT_S8 | AFMT_U8)) ? 8 : 16,
2332 (int *) arg);
2333
2334 case SOUND_PCM_WRITE_FILTER:
2335 case SNDCTL_DSP_SETSYNCRO:
2336 case SOUND_PCM_READ_FILTER:
2337 return -EINVAL;
2338 }
2339 return mixer_ioctl(s, cmd, arg);
2340}
2341
2342
2343static int cs4297a_release(struct inode *inode, struct file *file)
2344{
2345 struct cs4297a_state *s =
2346 (struct cs4297a_state *) file->private_data;
2347
2348 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 2, printk(KERN_INFO
2349 "cs4297a: cs4297a_release(): inode=0x%.8x file=0x%.8x f_mode=0x%x\n",
2350 (unsigned) inode, (unsigned) file, file->f_mode));
2351 VALIDATE_STATE(s);
2352
2353 if (file->f_mode & FMODE_WRITE) {
2354 drain_dac(s, file->f_flags & O_NONBLOCK);
2355 down(&s->open_sem_dac);
2356 stop_dac(s);
2357 dealloc_dmabuf(s, &s->dma_dac);
2358 s->open_mode &= ~FMODE_WRITE;
2359 up(&s->open_sem_dac);
2360 wake_up(&s->open_wait_dac);
2361 }
2362 if (file->f_mode & FMODE_READ) {
2363 drain_adc(s, file->f_flags & O_NONBLOCK);
2364 down(&s->open_sem_adc);
2365 stop_adc(s);
2366 dealloc_dmabuf(s, &s->dma_adc);
2367 s->open_mode &= ~FMODE_READ;
2368 up(&s->open_sem_adc);
2369 wake_up(&s->open_wait_adc);
2370 }
2371 return 0;
2372}
2373
2374static int cs4297a_open(struct inode *inode, struct file *file)
2375{
2376 int minor = iminor(inode);
2377 struct cs4297a_state *s=NULL;
2378 struct list_head *entry;
2379
2380 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2381 "cs4297a: cs4297a_open(): inode=0x%.8x file=0x%.8x f_mode=0x%x\n",
2382 (unsigned) inode, (unsigned) file, file->f_mode));
2383 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2384 "cs4297a: status = %08x\n", (int)__raw_readq(SS_CSR(R_SER_STATUS_DEBUG))));
2385
2386 list_for_each(entry, &cs4297a_devs)
2387 {
2388 s = list_entry(entry, struct cs4297a_state, list);
2389
2390 if (!((s->dev_audio ^ minor) & ~0xf))
2391 break;
2392 }
2393 if (entry == &cs4297a_devs)
2394 return -ENODEV;
2395 if (!s) {
2396 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2397 "cs4297a: cs4297a_open(): Error - unable to find audio state struct\n"));
2398 return -ENODEV;
2399 }
2400 VALIDATE_STATE(s);
2401 file->private_data = s;
2402
2403 // wait for device to become free
2404 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) {
2405 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2, printk(KERN_INFO
2406 "cs4297a: cs4297a_open(): Error - must open READ and/or WRITE\n"));
2407 return -ENODEV;
2408 }
2409 if (file->f_mode & FMODE_WRITE) {
2410 if (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX)) != 0) {
2411 printk(KERN_ERR "cs4297a: TX pipe needs to drain\n");
2412 while (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX)))
2413 ;
2414 }
2415
2416 down(&s->open_sem_dac);
2417 while (s->open_mode & FMODE_WRITE) {
2418 if (file->f_flags & O_NONBLOCK) {
2419 up(&s->open_sem_dac);
2420 return -EBUSY;
2421 }
2422 up(&s->open_sem_dac);
2423 interruptible_sleep_on(&s->open_wait_dac);
2424
2425 if (signal_pending(current)) {
2426 printk("open - sig pending\n");
2427 return -ERESTARTSYS;
2428 }
2429 down(&s->open_sem_dac);
2430 }
2431 }
2432 if (file->f_mode & FMODE_READ) {
2433 down(&s->open_sem_adc);
2434 while (s->open_mode & FMODE_READ) {
2435 if (file->f_flags & O_NONBLOCK) {
2436 up(&s->open_sem_adc);
2437 return -EBUSY;
2438 }
2439 up(&s->open_sem_adc);
2440 interruptible_sleep_on(&s->open_wait_adc);
2441
2442 if (signal_pending(current)) {
2443 printk("open - sig pending\n");
2444 return -ERESTARTSYS;
2445 }
2446 down(&s->open_sem_adc);
2447 }
2448 }
2449 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2450 if (file->f_mode & FMODE_READ) {
2451 s->prop_adc.fmt = AFMT_S16_BE;
2452 s->prop_adc.fmt_original = s->prop_adc.fmt;
2453 s->prop_adc.channels = 2;
2454 s->prop_adc.rate = 48000;
2455 s->conversion = 0;
2456 s->ena &= ~FMODE_READ;
2457 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
2458 s->dma_adc.subdivision = 0;
2459 up(&s->open_sem_adc);
2460
2461 if (prog_dmabuf_adc(s)) {
2462 CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
2463 "cs4297a: adc Program dmabufs failed.\n"));
2464 cs4297a_release(inode, file);
2465 return -ENOMEM;
2466 }
2467 }
2468 if (file->f_mode & FMODE_WRITE) {
2469 s->prop_dac.fmt = AFMT_S16_BE;
2470 s->prop_dac.fmt_original = s->prop_dac.fmt;
2471 s->prop_dac.channels = 2;
2472 s->prop_dac.rate = 48000;
2473 s->conversion = 0;
2474 s->ena &= ~FMODE_WRITE;
2475 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
2476 s->dma_dac.subdivision = 0;
2477 up(&s->open_sem_dac);
2478
2479 if (prog_dmabuf_dac(s)) {
2480 CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
2481 "cs4297a: dac Program dmabufs failed.\n"));
2482 cs4297a_release(inode, file);
2483 return -ENOMEM;
2484 }
2485 }
2486 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2,
2487 printk(KERN_INFO "cs4297a: cs4297a_open()- 0\n"));
2488 return nonseekable_open(inode, file);
2489}
2490
2491
2492// ******************************************************************************************
2493// Wave (audio) file operations struct.
2494// ******************************************************************************************
2495static /*const */ struct file_operations cs4297a_audio_fops = {
2496 .owner = THIS_MODULE,
2497 .llseek = no_llseek,
2498 .read = cs4297a_read,
2499 .write = cs4297a_write,
2500 .poll = cs4297a_poll,
2501 .ioctl = cs4297a_ioctl,
2502 .mmap = cs4297a_mmap,
2503 .open = cs4297a_open,
2504 .release = cs4297a_release,
2505};
2506
2507static void cs4297a_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2508{
2509 struct cs4297a_state *s = (struct cs4297a_state *) dev_id;
2510 u32 status;
2511
2512 status = __raw_readq(SS_CSR(R_SER_STATUS_DEBUG));
2513
2514 CS_DBGOUT(CS_INTERRUPT, 6, printk(KERN_INFO
2515 "cs4297a: cs4297a_interrupt() HISR=0x%.8x\n", status));
2516
2517#if 0
2518 /* XXXKW what check *should* be done here? */
2519 if (!(status & (M_SYNCSER_RX_EOP_COUNT | M_SYNCSER_RX_OVERRUN | M_SYNCSER_RX_SYNC_ERR))) {
2520 status = __raw_readq(SS_CSR(R_SER_STATUS));
2521 printk(KERN_ERR "cs4297a: unexpected interrupt (status %08x)\n", status);
2522 return;
2523 }
2524#endif
2525
2526 if (status & M_SYNCSER_RX_SYNC_ERR) {
2527 status = __raw_readq(SS_CSR(R_SER_STATUS));
2528 printk(KERN_ERR "cs4297a: rx sync error (status %08x)\n", status);
2529 return;
2530 }
2531
2532 if (status & M_SYNCSER_RX_OVERRUN) {
2533 int newptr, i;
2534 s->stats.rx_ovrrn++;
2535 printk(KERN_ERR "cs4297a: receive FIFO overrun\n");
2536
2537 /* Fix things up: get the receive descriptor pool
2538 clean and give them back to the hardware */
2539 while (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_RX)))
2540 ;
2541 newptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
2542 s->dma_adc.descrtab_phys) / sizeof(serdma_descr_t));
2543 for (i=0; i<DMA_DESCR; i++) {
2544 s->dma_adc.descrtab[i].descr_a &= ~M_DMA_SERRX_SOP;
2545 }
2546 s->dma_adc.swptr = s->dma_adc.hwptr = newptr;
2547 s->dma_adc.count = 0;
2548 s->dma_adc.sb_swptr = s->dma_adc.sb_hwptr = s->dma_adc.sample_buf;
2549 __raw_writeq(DMA_DESCR, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
2550 }
2551
2552 spin_lock(&s->lock);
2553 cs4297a_update_ptr(s,CS_TRUE);
2554 spin_unlock(&s->lock);
2555
2556 CS_DBGOUT(CS_INTERRUPT, 6, printk(KERN_INFO
2557 "cs4297a: cs4297a_interrupt()-\n"));
2558}
2559
2560#if 0
2561static struct initvol {
2562 int mixch;
2563 int vol;
2564} initvol[] __initdata = {
2565
2566 {SOUND_MIXER_WRITE_VOLUME, 0x4040},
2567 {SOUND_MIXER_WRITE_PCM, 0x4040},
2568 {SOUND_MIXER_WRITE_SYNTH, 0x4040},
2569 {SOUND_MIXER_WRITE_CD, 0x4040},
2570 {SOUND_MIXER_WRITE_LINE, 0x4040},
2571 {SOUND_MIXER_WRITE_LINE1, 0x4040},
2572 {SOUND_MIXER_WRITE_RECLEV, 0x0000},
2573 {SOUND_MIXER_WRITE_SPEAKER, 0x4040},
2574 {SOUND_MIXER_WRITE_MIC, 0x0000}
2575};
2576#endif
2577
2578static int __init cs4297a_init(void)
2579{
2580 struct cs4297a_state *s;
2581 u32 pwr, id;
2582 mm_segment_t fs;
2583 int rval;
2584#ifndef CONFIG_BCM_CS4297A_CSWARM
2585 u64 cfg;
2586 int mdio_val;
2587#endif
2588
2589 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
2590 "cs4297a: cs4297a_init_module()+ \n"));
2591
2592#ifndef CONFIG_BCM_CS4297A_CSWARM
2593 mdio_val = __raw_readq(KSEG1 + A_MAC_REGISTER(2, R_MAC_MDIO)) &
2594 (M_MAC_MDIO_DIR|M_MAC_MDIO_OUT);
2595
2596 /* Check syscfg for synchronous serial on port 1 */
2597 cfg = __raw_readq(KSEG1 + A_SCD_SYSTEM_CFG);
2598 if (!(cfg & M_SYS_SER1_ENABLE)) {
2599 __raw_writeq(cfg | M_SYS_SER1_ENABLE, KSEG1+A_SCD_SYSTEM_CFG);
2600 cfg = __raw_readq(KSEG1 + A_SCD_SYSTEM_CFG);
2601 if (!(cfg & M_SYS_SER1_ENABLE)) {
2602 printk(KERN_INFO "cs4297a: serial port 1 not configured for synchronous operation\n");
2603 return -1;
2604 }
2605
2606 printk(KERN_INFO "cs4297a: serial port 1 switching to synchronous operation\n");
2607
2608 /* Force the codec (on SWARM) to reset by clearing
2609 GENO, preserving MDIO (no effect on CSWARM) */
2610 __raw_writeq(mdio_val, KSEG1+A_MAC_REGISTER(2, R_MAC_MDIO));
2611 udelay(10);
2612 }
2613
2614 /* Now set GENO */
2615 __raw_writeq(mdio_val | M_MAC_GENC, KSEG1+A_MAC_REGISTER(2, R_MAC_MDIO));
2616 /* Give the codec some time to finish resetting (start the bit clock) */
2617 udelay(100);
2618#endif
2619
2620 if (!(s = kmalloc(sizeof(struct cs4297a_state), GFP_KERNEL))) {
2621 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
2622 "cs4297a: probe() no memory for state struct.\n"));
2623 return -1;
2624 }
2625 memset(s, 0, sizeof(struct cs4297a_state));
2626 s->magic = CS4297a_MAGIC;
2627 init_waitqueue_head(&s->dma_adc.wait);
2628 init_waitqueue_head(&s->dma_dac.wait);
2629 init_waitqueue_head(&s->dma_adc.reg_wait);
2630 init_waitqueue_head(&s->dma_dac.reg_wait);
2631 init_waitqueue_head(&s->open_wait);
2632 init_waitqueue_head(&s->open_wait_adc);
2633 init_waitqueue_head(&s->open_wait_dac);
2634 init_MUTEX(&s->open_sem_adc);
2635 init_MUTEX(&s->open_sem_dac);
2636 spin_lock_init(&s->lock);
2637
2638 s->irq = K_INT_SER_1;
2639
2640 if (request_irq
2641 (s->irq, cs4297a_interrupt, 0, "Crystal CS4297a", s)) {
2642 CS_DBGOUT(CS_INIT | CS_ERROR, 1,
2643 printk(KERN_ERR "cs4297a: irq %u in use\n", s->irq));
2644 goto err_irq;
2645 }
2646 if ((s->dev_audio = register_sound_dsp(&cs4297a_audio_fops, -1)) <
2647 0) {
2648 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2649 "cs4297a: probe() register_sound_dsp() failed.\n"));
2650 goto err_dev1;
2651 }
2652 if ((s->dev_mixer = register_sound_mixer(&cs4297a_mixer_fops, -1)) <
2653 0) {
2654 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2655 "cs4297a: probe() register_sound_mixer() failed.\n"));
2656 goto err_dev2;
2657 }
2658
2659 if (ser_init(s) || dma_init(s)) {
2660 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2661 "cs4297a: ser_init failed.\n"));
2662 goto err_dev3;
2663 }
2664
2665 do {
2666 udelay(4000);
2667 rval = cs4297a_read_ac97(s, AC97_POWER_CONTROL, &pwr);
2668 } while (!rval && (pwr != 0xf));
2669
2670 if (!rval) {
2671 char *sb1250_duart_present;
2672
2673 fs = get_fs();
2674 set_fs(KERNEL_DS);
2675#if 0
2676 val = SOUND_MASK_LINE;
2677 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
2678 for (i = 0; i < sizeof(initvol) / sizeof(initvol[0]); i++) {
2679 val = initvol[i].vol;
2680 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
2681 }
2682// cs4297a_write_ac97(s, 0x18, 0x0808);
2683#else
2684 // cs4297a_write_ac97(s, 0x5e, 0x180);
2685 cs4297a_write_ac97(s, 0x02, 0x0808);
2686 cs4297a_write_ac97(s, 0x18, 0x0808);
2687#endif
2688 set_fs(fs);
2689
2690 list_add(&s->list, &cs4297a_devs);
2691
2692 cs4297a_read_ac97(s, AC97_VENDOR_ID1, &id);
2693
2694 sb1250_duart_present = symbol_get(sb1250_duart_present);
2695 if (sb1250_duart_present)
2696 sb1250_duart_present[1] = 0;
2697
2698 printk(KERN_INFO "cs4297a: initialized (vendor id = %x)\n", id);
2699
2700 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
2701 printk(KERN_INFO "cs4297a: cs4297a_init_module()-\n"));
2702
2703 return 0;
2704 }
2705
2706 err_dev3:
2707 unregister_sound_mixer(s->dev_mixer);
2708 err_dev2:
2709 unregister_sound_dsp(s->dev_audio);
2710 err_dev1:
2711 free_irq(s->irq, s);
2712 err_irq:
2713 kfree(s);
2714
2715 printk(KERN_INFO "cs4297a: initialization failed\n");
2716
2717 return -1;
2718}
2719
2720static void __exit cs4297a_cleanup(void)
2721{
2722 /*
2723 XXXKW
2724 disable_irq, free_irq
2725 drain DMA queue
2726 disable DMA
2727 disable TX/RX
2728 free memory
2729 */
2730 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
2731 printk(KERN_INFO "cs4297a: cleanup_cs4297a() finished\n"));
2732}
2733
2734// ---------------------------------------------------------------------
2735
2736MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
2737MODULE_DESCRIPTION("Cirrus Logic CS4297a Driver for Broadcom SWARM board");
2738
2739// ---------------------------------------------------------------------
2740
2741module_init(cs4297a_init);
2742module_exit(cs4297a_cleanup);
diff --git a/sound/oss/sys_timer.c b/sound/oss/sys_timer.c
new file mode 100644
index 000000000000..6afe29b763b7
--- /dev/null
+++ b/sound/oss/sys_timer.c
@@ -0,0 +1,289 @@
1/*
2 * sound/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 time_t 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);
31
32static struct timer_list def_tmr = TIMER_INITIALIZER(poll_def_tmr, 0, 0);
33
34static unsigned long
35tmr2ticks(int tmr_value)
36{
37 /*
38 * Convert timer ticks to MIDI ticks
39 */
40
41 unsigned long tmp;
42 unsigned long scale;
43
44 /* tmr_value (ticks per sec) *
45 1000000 (usecs per sec) / HZ (ticks per sec) -=> usecs */
46 tmp = tmr_value * (1000000 / HZ);
47 scale = (60 * 1000000) / (curr_tempo * curr_timebase); /* usecs per MIDI tick */
48 return (tmp + scale / 2) / scale;
49}
50
51static void
52poll_def_tmr(unsigned long dummy)
53{
54
55 if (opened)
56 {
57
58 {
59 def_tmr.expires = (1) + jiffies;
60 add_timer(&def_tmr);
61 };
62
63 if (tmr_running)
64 {
65 spin_lock(&lock);
66 tmr_ctr++;
67 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
68
69 if (curr_ticks >= next_event_time)
70 {
71 next_event_time = (unsigned long) -1;
72 sequencer_timer(0);
73 }
74 spin_unlock(&lock);
75 }
76 }
77}
78
79static void
80tmr_reset(void)
81{
82 unsigned long flags;
83
84 spin_lock_irqsave(&lock,flags);
85 tmr_offs = 0;
86 ticks_offs = 0;
87 tmr_ctr = 0;
88 next_event_time = (unsigned long) -1;
89 prev_event_time = 0;
90 curr_ticks = 0;
91 spin_unlock_irqrestore(&lock,flags);
92}
93
94static int
95def_tmr_open(int dev, int mode)
96{
97 if (opened)
98 return -EBUSY;
99
100 tmr_reset();
101 curr_tempo = 60;
102 curr_timebase = 100;
103 opened = 1;
104
105 ;
106
107 {
108 def_tmr.expires = (1) + jiffies;
109 add_timer(&def_tmr);
110 };
111
112 return 0;
113}
114
115static void
116def_tmr_close(int dev)
117{
118 opened = tmr_running = 0;
119 del_timer(&def_tmr);
120}
121
122static int
123def_tmr_event(int dev, unsigned char *event)
124{
125 unsigned char cmd = event[1];
126 unsigned long parm = *(int *) &event[4];
127
128 switch (cmd)
129 {
130 case TMR_WAIT_REL:
131 parm += prev_event_time;
132 case TMR_WAIT_ABS:
133 if (parm > 0)
134 {
135 long time;
136
137 if (parm <= curr_ticks) /* It's the time */
138 return TIMER_NOT_ARMED;
139
140 time = parm;
141 next_event_time = prev_event_time = time;
142
143 return TIMER_ARMED;
144 }
145 break;
146
147 case TMR_START:
148 tmr_reset();
149 tmr_running = 1;
150 break;
151
152 case TMR_STOP:
153 tmr_running = 0;
154 break;
155
156 case TMR_CONTINUE:
157 tmr_running = 1;
158 break;
159
160 case TMR_TEMPO:
161 if (parm)
162 {
163 if (parm < 8)
164 parm = 8;
165 if (parm > 360)
166 parm = 360;
167 tmr_offs = tmr_ctr;
168 ticks_offs += tmr2ticks(tmr_ctr);
169 tmr_ctr = 0;
170 curr_tempo = parm;
171 }
172 break;
173
174 case TMR_ECHO:
175 seq_copy_to_input(event, 8);
176 break;
177
178 default:;
179 }
180
181 return TIMER_NOT_ARMED;
182}
183
184static unsigned long
185def_tmr_get_time(int dev)
186{
187 if (!opened)
188 return 0;
189
190 return curr_ticks;
191}
192
193/* same as sound_timer.c:timer_ioctl!? */
194static int def_tmr_ioctl(int dev, unsigned int cmd, void __user *arg)
195{
196 int __user *p = arg;
197 int val;
198
199 switch (cmd) {
200 case SNDCTL_TMR_SOURCE:
201 return __put_user(TMR_INTERNAL, p);
202
203 case SNDCTL_TMR_START:
204 tmr_reset();
205 tmr_running = 1;
206 return 0;
207
208 case SNDCTL_TMR_STOP:
209 tmr_running = 0;
210 return 0;
211
212 case SNDCTL_TMR_CONTINUE:
213 tmr_running = 1;
214 return 0;
215
216 case SNDCTL_TMR_TIMEBASE:
217 if (__get_user(val, p))
218 return -EFAULT;
219 if (val) {
220 if (val < 1)
221 val = 1;
222 if (val > 1000)
223 val = 1000;
224 curr_timebase = val;
225 }
226 return __put_user(curr_timebase, p);
227
228 case SNDCTL_TMR_TEMPO:
229 if (__get_user(val, p))
230 return -EFAULT;
231 if (val) {
232 if (val < 8)
233 val = 8;
234 if (val > 250)
235 val = 250;
236 tmr_offs = tmr_ctr;
237 ticks_offs += tmr2ticks(tmr_ctr);
238 tmr_ctr = 0;
239 curr_tempo = val;
240 reprogram_timer();
241 }
242 return __put_user(curr_tempo, p);
243
244 case SNDCTL_SEQ_CTRLRATE:
245 if (__get_user(val, p))
246 return -EFAULT;
247 if (val != 0) /* Can't change */
248 return -EINVAL;
249 val = ((curr_tempo * curr_timebase) + 30) / 60;
250 return __put_user(val, p);
251
252 case SNDCTL_SEQ_GETTIME:
253 return __put_user(curr_ticks, p);
254
255 case SNDCTL_TMR_METRONOME:
256 /* NOP */
257 break;
258
259 default:;
260 }
261 return -EINVAL;
262}
263
264static void
265def_tmr_arm(int dev, long time)
266{
267 if (time < 0)
268 time = curr_ticks + 1;
269 else if (time <= curr_ticks) /* It's the time */
270 return;
271
272 next_event_time = prev_event_time = time;
273
274 return;
275}
276
277struct sound_timer_operations default_sound_timer =
278{
279 .owner = THIS_MODULE,
280 .info = {"System clock", 0},
281 .priority = 0, /* Priority */
282 .devlink = 0, /* Local device link */
283 .open = def_tmr_open,
284 .close = def_tmr_close,
285 .event = def_tmr_event,
286 .get_time = def_tmr_get_time,
287 .ioctl = def_tmr_ioctl,
288 .arm_timer = def_tmr_arm
289};
diff --git a/sound/oss/trident.c b/sound/oss/trident.c
new file mode 100644
index 000000000000..47537f0a5b05
--- /dev/null
+++ b/sound/oss/trident.c
@@ -0,0 +1,4628 @@
1/*
2 * OSS driver for Linux 2.[46].x for
3 *
4 * Trident 4D-Wave
5 * SiS 7018
6 * ALi 5451
7 * Tvia/IGST CyberPro 5050
8 *
9 * Driver: Alan Cox <alan@redhat.com>
10 *
11 * Built from:
12 * Low level code: <audio@tridentmicro.com> from ALSA
13 * Framework: Thomas Sailer <sailer@ife.ee.ethz.ch>
14 * Extended by: Zach Brown <zab@redhat.com>
15 *
16 * Hacked up by:
17 * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
18 * Ollie Lho <ollie@sis.com.tw> SiS 7018 Audio Core Support
19 * Ching-Ling Lee <cling-li@ali.com.tw> ALi 5451 Audio Core Support
20 * Matt Wu <mattwu@acersoftech.com.cn> ALi 5451 Audio Core Support
21 * Peter Wächtler <pwaechtler@loewe-komp.de> CyberPro5050 support
22 * Muli Ben-Yehuda <mulix@mulix.org>
23 *
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38 *
39 * History
40 * v0.14.10j
41 * January 3 2004 Eugene Teo <eugeneteo@eugeneteo.net>
42 * minor cleanup to use pr_debug instead of TRDBG since it is already
43 * defined in linux/kernel.h.
44 * v0.14.10i
45 * December 29 2003 Muli Ben-Yehuda <mulix@mulix.org>
46 * major cleanup for 2.6, fix a few error patch buglets
47 * with returning without properly cleaning up first,
48 * get rid of lock_kernel().
49 * v0.14.10h
50 * Sept 10 2002 Pascal Schmidt <der.eremit@email.de>
51 * added support for ALi 5451 joystick port
52 * v0.14.10g
53 * Sept 05 2002 Alan Cox <alan@redhat.com>
54 * adapt to new pci joystick attachment interface
55 * v0.14.10f
56 * July 24 2002 Muli Ben-Yehuda <mulix@actcom.co.il>
57 * patch from Eric Lemar (via Ian Soboroff): in suspend and resume,
58 * fix wrong cast from pci_dev* to struct trident_card*.
59 * v0.14.10e
60 * July 19 2002 Muli Ben-Yehuda <mulix@actcom.co.il>
61 * rewrite the DMA buffer allocation/deallcoation functions, to make it
62 * modular and fix a bug where we would call free_pages on memory
63 * obtained with pci_alloc_consistent. Also remove unnecessary #ifdef
64 * CONFIG_PROC_FS and various other cleanups.
65 * v0.14.10d
66 * July 19 2002 Muli Ben-Yehuda <mulix@actcom.co.il>
67 * made several printk(KERN_NOTICE...) into TRDBG(...), to avoid spamming
68 * my syslog with hundreds of messages.
69 * v0.14.10c
70 * July 16 2002 Muli Ben-Yehuda <mulix@actcom.co.il>
71 * Cleaned up Lei Hu's 0.4.10 driver to conform to Documentation/CodingStyle
72 * and the coding style used in the rest of the file.
73 * v0.14.10b
74 * June 23 2002 Muli Ben-Yehuda <mulix@actcom.co.il>
75 * add a missing unlock_set_fmt, remove a superflous lock/unlock pair
76 * with nothing in between.
77 * v0.14.10a
78 * June 21 2002 Muli Ben-Yehuda <mulix@actcom.co.il>
79 * use a debug macro instead of #ifdef CONFIG_DEBUG, trim to 80 columns
80 * per line, use 'do {} while (0)' in statement macros.
81 * v0.14.10
82 * June 6 2002 Lei Hu <Lei_hu@ali.com.tw>
83 * rewrite the part to read/write registers of audio codec for Ali5451
84 * v0.14.9e
85 * January 2 2002 Vojtech Pavlik <vojtech@ucw.cz> added gameport
86 * support to avoid resource conflict with pcigame.c
87 * v0.14.9d
88 * October 8 2001 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
89 * use set_current_state, properly release resources on failure in
90 * trident_probe, get rid of check_region
91 * v0.14.9c
92 * August 10 2001 Peter Wächtler <pwaechtler@loewe-komp.de>
93 * added support for Tvia (formerly Integraphics/IGST) CyberPro5050
94 * this chip is often found in settop boxes (combined video+audio)
95 * v0.14.9b
96 * Switch to static inline not extern inline (gcc 3)
97 * v0.14.9a
98 * Aug 6 2001 Alan Cox
99 * 0.14.9 crashed on rmmod due to a timer/bh left running. Simplified
100 * the existing logic (the BH doesn't help as ac97 is lock_irqsave)
101 * and used del_timer_sync to clean up
102 * Fixed a problem where the ALi change broke my generic card
103 * v0.14.9
104 * Jul 10 2001 Matt Wu
105 * Add H/W Volume Control
106 * v0.14.8a
107 * July 7 2001 Alan Cox
108 * Moved Matt Wu's ac97 register cache into the card structure
109 * v0.14.8
110 * Apr 30 2001 Matt Wu
111 * Set EBUF1 and EBUF2 to still mode
112 * Add dc97/ac97 reset function
113 * Fix power management: ali_restore_regs
114 * unreleased
115 * Mar 09 2001 Matt Wu
116 * Add cache for ac97 access
117 * v0.14.7
118 * Feb 06 2001 Matt Wu
119 * Fix ac97 initialization
120 * Fix bug: an extra tail will be played when playing
121 * Jan 05 2001 Matt Wu
122 * Implement multi-channels and S/PDIF in support for ALi 1535+
123 * v0.14.6
124 * Nov 1 2000 Ching-Ling Lee
125 * Fix the bug of memory leak when switching 5.1-channels to 2 channels.
126 * Add lock protection into dynamic changing format of data.
127 * Oct 18 2000 Ching-Ling Lee
128 * 5.1-channels support for ALi
129 * June 28 2000 Ching-Ling Lee
130 * S/PDIF out/in(playback/record) support for ALi 1535+, using /proc to be selected by user
131 * Simple Power Management support for ALi
132 * v0.14.5 May 23 2000 Ollie Lho
133 * Misc bug fix from the Net
134 * v0.14.4 May 20 2000 Aaron Holtzman
135 * Fix kfree'd memory access in release
136 * Fix race in open while looking for a free virtual channel slot
137 * remove open_wait wq (which appears to be unused)
138 * v0.14.3 May 10 2000 Ollie Lho
139 * fixed a small bug in trident_update_ptr, xmms 1.0.1 no longer uses 100% CPU
140 * v0.14.2 Mar 29 2000 Ching-Ling Lee
141 * Add clear to silence advance in trident_update_ptr
142 * fix invalid data of the end of the sound
143 * v0.14.1 Mar 24 2000 Ching-Ling Lee
144 * ALi 5451 support added, playback and recording O.K.
145 * ALi 5451 originally developed and structured based on sonicvibes, and
146 * suggested to merge into this file by Alan Cox.
147 * v0.14 Mar 15 2000 Ollie Lho
148 * 5.1 channel output support with channel binding. What's the Matrix ?
149 * v0.13.1 Mar 10 2000 Ollie Lho
150 * few minor bugs on dual codec support, needs more testing
151 * v0.13 Mar 03 2000 Ollie Lho
152 * new pci_* for 2.4 kernel, back ported to 2.2
153 * v0.12 Feb 23 2000 Ollie Lho
154 * Preliminary Recording support
155 * v0.11.2 Feb 19 2000 Ollie Lho
156 * removed incomplete full-dulplex support
157 * v0.11.1 Jan 28 2000 Ollie Lho
158 * small bug in setting sample rate for 4d-nx (reported by Aaron)
159 * v0.11 Jan 27 2000 Ollie Lho
160 * DMA bug, scheduler latency, second try
161 * v0.10 Jan 24 2000 Ollie Lho
162 * DMA bug fixed, found kernel scheduling problem
163 * v0.09 Jan 20 2000 Ollie Lho
164 * Clean up of channel register access routine (prepare for channel binding)
165 * v0.08 Jan 14 2000 Ollie Lho
166 * Isolation of AC97 codec code
167 * v0.07 Jan 13 2000 Ollie Lho
168 * Get rid of ugly old low level access routines (e.g. CHRegs.lp****)
169 * v0.06 Jan 11 2000 Ollie Lho
170 * Preliminary support for dual (more ?) AC97 codecs
171 * v0.05 Jan 08 2000 Luca Montecchiani <m.luca@iname.com>
172 * adapt to 2.3.x new __setup/__init call
173 * v0.04 Dec 31 1999 Ollie Lho
174 * Multiple Open, using Middle Loop Interrupt to smooth playback
175 * v0.03 Dec 24 1999 Ollie Lho
176 * mem leak in prog_dmabuf and dealloc_dmabuf removed
177 * v0.02 Dec 15 1999 Ollie Lho
178 * SiS 7018 support added, playback O.K.
179 * v0.01 Alan Cox et. al.
180 * Initial Release in kernel 2.3.30, does not work
181 *
182 * ToDo
183 * Clean up of low level channel register access code. (done)
184 * Fix the bug on dma buffer management in update_ptr, read/write, drain_dac (done)
185 * Dual AC97 codecs support (done)
186 * Recording support (done)
187 * Mmap support
188 * "Channel Binding" ioctl extension (done)
189 * new pci device driver interface for 2.4 kernel (done)
190 *
191 * Lock order (high->low)
192 * lock - hardware lock
193 * open_sem - guard opens
194 * sem - guard dmabuf, write re-entry etc
195 */
196
197#include <linux/config.h>
198#include <linux/module.h>
199#include <linux/string.h>
200#include <linux/ctype.h>
201#include <linux/ioport.h>
202#include <linux/sched.h>
203#include <linux/delay.h>
204#include <linux/sound.h>
205#include <linux/slab.h>
206#include <linux/soundcard.h>
207#include <linux/pci.h>
208#include <linux/init.h>
209#include <linux/poll.h>
210#include <linux/spinlock.h>
211#include <linux/smp_lock.h>
212#include <linux/ac97_codec.h>
213#include <linux/bitops.h>
214#include <linux/proc_fs.h>
215#include <linux/interrupt.h>
216#include <linux/pm.h>
217#include <linux/gameport.h>
218#include <linux/kernel.h>
219#include <asm/uaccess.h>
220#include <asm/io.h>
221#include <asm/dma.h>
222
223#if defined(CONFIG_ALPHA_NAUTILUS) || defined(CONFIG_ALPHA_GENERIC)
224#include <asm/hwrpb.h>
225#endif
226
227#include "trident.h"
228
229#define DRIVER_VERSION "0.14.10j-2.6"
230
231/* magic numbers to protect our data structures */
232#define TRIDENT_CARD_MAGIC 0x5072696E /* "Prin" */
233#define TRIDENT_STATE_MAGIC 0x63657373 /* "cess" */
234
235#define TRIDENT_DMA_MASK 0x3fffffff /* DMA buffer mask for pci_alloc_consist */
236#define ALI_DMA_MASK 0x7fffffff /* ALI Tridents have 31-bit DMA. Wow. */
237
238#define NR_HW_CH 32
239
240/* maximum number of AC97 codecs connected, AC97 2.0 defined 4, but 7018 and 4D-NX only
241 have 2 SDATA_IN lines (currently) */
242#define NR_AC97 2
243
244/* minor number of /dev/swmodem (temporary, experimental) */
245#define SND_DEV_SWMODEM 7
246
247static const unsigned ali_multi_channels_5_1[] = {
248 /*ALI_SURR_LEFT_CHANNEL, ALI_SURR_RIGHT_CHANNEL, */
249 ALI_CENTER_CHANNEL,
250 ALI_LEF_CHANNEL,
251 ALI_SURR_LEFT_CHANNEL,
252 ALI_SURR_RIGHT_CHANNEL
253};
254
255static const unsigned sample_size[] = { 1, 2, 2, 4 };
256static const unsigned sample_shift[] = { 0, 1, 1, 2 };
257
258static const char invalid_magic[] = KERN_CRIT "trident: invalid magic value in %s\n";
259
260enum {
261 TRIDENT_4D_DX = 0,
262 TRIDENT_4D_NX,
263 SIS_7018,
264 ALI_5451,
265 CYBER5050
266};
267
268static char *card_names[] = {
269 "Trident 4DWave DX",
270 "Trident 4DWave NX",
271 "SiS 7018 PCI Audio",
272 "ALi Audio Accelerator",
273 "Tvia/IGST CyberPro 5050"
274};
275
276static struct pci_device_id trident_pci_tbl[] = {
277 {PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_DX,
278 PCI_ANY_ID, PCI_ANY_ID, 0, 0, TRIDENT_4D_DX},
279 {PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_NX,
280 PCI_ANY_ID, PCI_ANY_ID, 0, 0, TRIDENT_4D_NX},
281 {PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7018,
282 PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_7018},
283 {PCI_VENDOR_ID_ALI, PCI_DEVICE_ID_ALI_5451,
284 PCI_ANY_ID, PCI_ANY_ID, 0, 0, ALI_5451},
285 {PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_5050,
286 PCI_ANY_ID, PCI_ANY_ID, 0, 0, CYBER5050},
287 {0,}
288};
289
290MODULE_DEVICE_TABLE(pci, trident_pci_tbl);
291
292/* "software" or virtual channel, an instance of opened /dev/dsp */
293struct trident_state {
294 unsigned int magic;
295 struct trident_card *card; /* Card info */
296
297 /* file mode */
298 mode_t open_mode;
299
300 /* virtual channel number */
301 int virt;
302
303 struct dmabuf {
304 /* wave sample stuff */
305 unsigned int rate;
306 unsigned char fmt, enable;
307
308 /* hardware channel */
309 struct trident_channel *channel;
310
311 /* OSS buffer management stuff */
312 void *rawbuf;
313 dma_addr_t dma_handle;
314 unsigned buforder;
315 unsigned numfrag;
316 unsigned fragshift;
317
318 /* our buffer acts like a circular ring */
319 unsigned hwptr; /* where dma last started, updated by update_ptr */
320 unsigned swptr; /* where driver last clear/filled, updated by read/write */
321 int count; /* bytes to be comsumed or been generated by dma machine */
322 unsigned total_bytes; /* total bytes dmaed by hardware */
323
324 unsigned error; /* number of over/underruns */
325 /* put process on wait queue when no more space in buffer */
326 wait_queue_head_t wait;
327
328 /* redundant, but makes calculations easier */
329 unsigned fragsize;
330 unsigned dmasize;
331 unsigned fragsamples;
332
333 /* OSS stuff */
334 unsigned mapped:1;
335 unsigned ready:1;
336 unsigned endcleared:1;
337 unsigned update_flag;
338 unsigned ossfragshift;
339 int ossmaxfrags;
340 unsigned subdivision;
341
342 } dmabuf;
343
344 /* 5.1 channels */
345 struct trident_state *other_states[4];
346 int multi_channels_adjust_count;
347 unsigned chans_num;
348 unsigned long fmt_flag;
349 /* Guard against mmap/write/read races */
350 struct semaphore sem;
351
352};
353
354/* hardware channels */
355struct trident_channel {
356 int num; /* channel number */
357 u32 lba; /* Loop Begine Address, where dma buffer starts */
358 u32 eso; /* End Sample Offset, wehre dma buffer ends */
359 /* (in the unit of samples) */
360 u32 delta; /* delta value, sample rate / 48k for playback, */
361 /* 48k/sample rate for recording */
362 u16 attribute; /* control where PCM data go and come */
363 u16 fm_vol;
364 u32 control; /* signed/unsigned, 8/16 bits, mono/stereo */
365};
366
367struct trident_pcm_bank_address {
368 u32 start;
369 u32 stop;
370 u32 aint;
371 u32 aint_en;
372};
373
374static struct trident_pcm_bank_address bank_a_addrs = {
375 T4D_START_A,
376 T4D_STOP_A,
377 T4D_AINT_A,
378 T4D_AINTEN_A
379};
380
381static struct trident_pcm_bank_address bank_b_addrs = {
382 T4D_START_B,
383 T4D_STOP_B,
384 T4D_AINT_B,
385 T4D_AINTEN_B
386};
387
388struct trident_pcm_bank {
389 /* register addresses to control bank operations */
390 struct trident_pcm_bank_address *addresses;
391 /* each bank has 32 channels */
392 u32 bitmap; /* channel allocation bitmap */
393 struct trident_channel channels[32];
394};
395
396struct trident_card {
397 unsigned int magic;
398
399 /* We keep trident cards in a linked list */
400 struct trident_card *next;
401
402 /* single open lock mechanism, only used for recording */
403 struct semaphore open_sem;
404
405 /* The trident has a certain amount of cross channel interaction
406 so we use a single per card lock */
407 spinlock_t lock;
408
409 /* PCI device stuff */
410 struct pci_dev *pci_dev;
411 u16 pci_id;
412 u8 revision;
413
414 /* soundcore stuff */
415 int dev_audio;
416
417 /* structures for abstraction of hardware facilities, codecs, */
418 /* banks and channels */
419 struct ac97_codec *ac97_codec[NR_AC97];
420 struct trident_pcm_bank banks[NR_BANKS];
421 struct trident_state *states[NR_HW_CH];
422
423 /* hardware resources */
424 unsigned long iobase;
425 u32 irq;
426
427 /* Function support */
428 struct trident_channel *(*alloc_pcm_channel) (struct trident_card *);
429 struct trident_channel *(*alloc_rec_pcm_channel) (struct trident_card *);
430 void (*free_pcm_channel) (struct trident_card *, unsigned int chan);
431 void (*address_interrupt) (struct trident_card *);
432
433 /* Added by Matt Wu 01-05-2001 for spdif in */
434 int multi_channel_use_count;
435 int rec_channel_use_count;
436 u16 mixer_regs[64][NR_AC97]; /* Made card local by Alan */
437 int mixer_regs_ready;
438
439 /* Added for hardware volume control */
440 int hwvolctl;
441 struct timer_list timer;
442
443 /* Game port support */
444 struct gameport *gameport;
445};
446
447enum dmabuf_mode {
448 DM_PLAYBACK = 0,
449 DM_RECORD
450};
451
452/* table to map from CHANNELMASK to channel attribute for SiS 7018 */
453static u16 mask2attr[] = {
454 PCM_LR, PCM_LR, SURR_LR, CENTER_LFE,
455 HSET, MIC, MODEM_LINE1, MODEM_LINE2,
456 I2S_LR, SPDIF_LR
457};
458
459/* table to map from channel attribute to CHANNELMASK for SiS 7018 */
460static int attr2mask[] = {
461 DSP_BIND_MODEM1, DSP_BIND_MODEM2, DSP_BIND_FRONT, DSP_BIND_HANDSET,
462 DSP_BIND_I2S, DSP_BIND_CENTER_LFE, DSP_BIND_SURR, DSP_BIND_SPDIF
463};
464
465/* Added by Matt Wu 01-05-2001 for spdif in */
466static int ali_close_multi_channels(void);
467static void ali_delay(struct trident_card *card, int interval);
468static void ali_detect_spdif_rate(struct trident_card *card);
469
470static void ali_ac97_write(struct ac97_codec *codec, u8 reg, u16 val);
471static u16 ali_ac97_read(struct ac97_codec *codec, u8 reg);
472
473static struct trident_card *devs;
474
475static void trident_ac97_set(struct ac97_codec *codec, u8 reg, u16 val);
476static u16 trident_ac97_get(struct ac97_codec *codec, u8 reg);
477
478static int trident_open_mixdev(struct inode *inode, struct file *file);
479static int trident_ioctl_mixdev(struct inode *inode, struct file *file,
480 unsigned int cmd, unsigned long arg);
481
482static void ali_ac97_set(struct trident_card *card, int secondary, u8 reg, u16 val);
483static u16 ali_ac97_get(struct trident_card *card, int secondary, u8 reg);
484static void ali_set_spdif_out_rate(struct trident_card *card, unsigned int rate);
485static void ali_enable_special_channel(struct trident_state *stat);
486static struct trident_channel *ali_alloc_rec_pcm_channel(struct trident_card *card);
487static struct trident_channel *ali_alloc_pcm_channel(struct trident_card *card);
488static void ali_restore_regs(struct trident_card *card);
489static void ali_save_regs(struct trident_card *card);
490static int trident_suspend(struct pci_dev *dev, pm_message_t unused);
491static int trident_resume(struct pci_dev *dev);
492static void ali_free_pcm_channel(struct trident_card *card, unsigned int channel);
493static int ali_setup_multi_channels(struct trident_card *card, int chan_nums);
494static unsigned int ali_get_spdif_in_rate(struct trident_card *card);
495static void ali_setup_spdif_in(struct trident_card *card);
496static void ali_disable_spdif_in(struct trident_card *card);
497static void ali_disable_special_channel(struct trident_card *card, int ch);
498static void ali_setup_spdif_out(struct trident_card *card, int flag);
499static int ali_write_5_1(struct trident_state *state,
500 const char __user *buffer,
501 int cnt_for_multi_channel, unsigned int *copy_count,
502 unsigned int *state_cnt);
503static int ali_allocate_other_states_resources(struct trident_state *state,
504 int chan_nums);
505static void ali_free_other_states_resources(struct trident_state *state);
506
507/* save registers for ALi Power Management */
508static struct ali_saved_registers {
509 unsigned long global_regs[ALI_GLOBAL_REGS];
510 unsigned long channel_regs[ALI_CHANNELS][ALI_CHANNEL_REGS];
511 unsigned mixer_regs[ALI_MIXER_REGS];
512} ali_registers;
513
514#define seek_offset(dma_ptr, buffer, cnt, offset, copy_count) do { \
515 (dma_ptr) += (offset); \
516 (buffer) += (offset); \
517 (cnt) -= (offset); \
518 (copy_count) += (offset); \
519} while (0)
520
521static inline int lock_set_fmt(struct trident_state* state)
522{
523 if (test_and_set_bit(0, &state->fmt_flag))
524 return -EFAULT;
525
526 return 0;
527}
528
529static inline void unlock_set_fmt(struct trident_state* state)
530{
531 clear_bit(0, &state->fmt_flag);
532}
533
534static int
535trident_enable_loop_interrupts(struct trident_card *card)
536{
537 u32 global_control;
538
539 global_control = inl(TRID_REG(card, T4D_LFO_GC_CIR));
540
541 switch (card->pci_id) {
542 case PCI_DEVICE_ID_SI_7018:
543 global_control |= (ENDLP_IE | MIDLP_IE | BANK_B_EN);
544 break;
545 case PCI_DEVICE_ID_ALI_5451:
546 case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX:
547 case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX:
548 case PCI_DEVICE_ID_INTERG_5050:
549 global_control |= (ENDLP_IE | MIDLP_IE);
550 break;
551 default:
552 return 0;
553 }
554
555 outl(global_control, TRID_REG(card, T4D_LFO_GC_CIR));
556
557 pr_debug("trident: Enable Loop Interrupts, globctl = 0x%08X\n",
558 inl(TRID_REG(card, T4D_LFO_GC_CIR)));
559
560 return 1;
561}
562
563static int
564trident_disable_loop_interrupts(struct trident_card *card)
565{
566 u32 global_control;
567
568 global_control = inl(TRID_REG(card, T4D_LFO_GC_CIR));
569 global_control &= ~(ENDLP_IE | MIDLP_IE);
570 outl(global_control, TRID_REG(card, T4D_LFO_GC_CIR));
571
572 pr_debug("trident: Disabled Loop Interrupts, globctl = 0x%08X\n",
573 global_control);
574
575 return 1;
576}
577
578static void
579trident_enable_voice_irq(struct trident_card *card, unsigned int channel)
580{
581 unsigned int mask = 1 << (channel & 0x1f);
582 struct trident_pcm_bank *bank = &card->banks[channel >> 5];
583 u32 reg, addr = bank->addresses->aint_en;
584
585 reg = inl(TRID_REG(card, addr));
586 reg |= mask;
587 outl(reg, TRID_REG(card, addr));
588
589#ifdef DEBUG
590 reg = inl(TRID_REG(card, addr));
591 pr_debug("trident: enabled IRQ on channel %d, %s = 0x%08x(addr:%X)\n",
592 channel, addr == T4D_AINTEN_B ? "AINTEN_B" : "AINTEN_A",
593 reg, addr);
594#endif /* DEBUG */
595}
596
597static void
598trident_disable_voice_irq(struct trident_card *card, unsigned int channel)
599{
600 unsigned int mask = 1 << (channel & 0x1f);
601 struct trident_pcm_bank *bank = &card->banks[channel >> 5];
602 u32 reg, addr = bank->addresses->aint_en;
603
604 reg = inl(TRID_REG(card, addr));
605 reg &= ~mask;
606 outl(reg, TRID_REG(card, addr));
607
608 /* Ack the channel in case the interrupt was set before we disable it. */
609 outl(mask, TRID_REG(card, bank->addresses->aint));
610
611#ifdef DEBUG
612 reg = inl(TRID_REG(card, addr));
613 pr_debug("trident: disabled IRQ on channel %d, %s = 0x%08x(addr:%X)\n",
614 channel, addr == T4D_AINTEN_B ? "AINTEN_B" : "AINTEN_A",
615 reg, addr);
616#endif /* DEBUG */
617}
618
619static void
620trident_start_voice(struct trident_card *card, unsigned int channel)
621{
622 unsigned int mask = 1 << (channel & 0x1f);
623 struct trident_pcm_bank *bank = &card->banks[channel >> 5];
624 u32 addr = bank->addresses->start;
625
626#ifdef DEBUG
627 u32 reg;
628#endif /* DEBUG */
629
630 outl(mask, TRID_REG(card, addr));
631
632#ifdef DEBUG
633 reg = inl(TRID_REG(card, addr));
634 pr_debug("trident: start voice on channel %d, %s = 0x%08x(addr:%X)\n",
635 channel, addr == T4D_START_B ? "START_B" : "START_A",
636 reg, addr);
637#endif /* DEBUG */
638}
639
640static void
641trident_stop_voice(struct trident_card *card, unsigned int channel)
642{
643 unsigned int mask = 1 << (channel & 0x1f);
644 struct trident_pcm_bank *bank = &card->banks[channel >> 5];
645 u32 addr = bank->addresses->stop;
646
647#ifdef DEBUG
648 u32 reg;
649#endif /* DEBUG */
650
651 outl(mask, TRID_REG(card, addr));
652
653#ifdef DEBUG
654 reg = inl(TRID_REG(card, addr));
655 pr_debug("trident: stop voice on channel %d, %s = 0x%08x(addr:%X)\n",
656 channel, addr == T4D_STOP_B ? "STOP_B" : "STOP_A",
657 reg, addr);
658#endif /* DEBUG */
659}
660
661static u32
662trident_get_interrupt_mask(struct trident_card *card, unsigned int channel)
663{
664 struct trident_pcm_bank *bank = &card->banks[channel];
665 u32 addr = bank->addresses->aint;
666 return inl(TRID_REG(card, addr));
667}
668
669static int
670trident_check_channel_interrupt(struct trident_card *card, unsigned int channel)
671{
672 unsigned int mask = 1 << (channel & 0x1f);
673 u32 reg = trident_get_interrupt_mask(card, channel >> 5);
674
675#ifdef DEBUG
676 if (reg & mask)
677 pr_debug("trident: channel %d has interrupt, %s = 0x%08x\n",
678 channel, reg == T4D_AINT_B ? "AINT_B" : "AINT_A",
679 reg);
680#endif /* DEBUG */
681 return (reg & mask) ? 1 : 0;
682}
683
684static void
685trident_ack_channel_interrupt(struct trident_card *card, unsigned int channel)
686{
687 unsigned int mask = 1 << (channel & 0x1f);
688 struct trident_pcm_bank *bank = &card->banks[channel >> 5];
689 u32 reg, addr = bank->addresses->aint;
690
691 reg = inl(TRID_REG(card, addr));
692 reg &= mask;
693 outl(reg, TRID_REG(card, addr));
694
695#ifdef DEBUG
696 reg = inl(TRID_REG(card, T4D_AINT_B));
697 pr_debug("trident: Ack channel %d interrupt, AINT_B = 0x%08x\n",
698 channel, reg);
699#endif /* DEBUG */
700}
701
702static struct trident_channel *
703trident_alloc_pcm_channel(struct trident_card *card)
704{
705 struct trident_pcm_bank *bank;
706 int idx;
707
708 bank = &card->banks[BANK_B];
709
710 for (idx = 31; idx >= 0; idx--) {
711 if (!(bank->bitmap & (1 << idx))) {
712 struct trident_channel *channel = &bank->channels[idx];
713 bank->bitmap |= 1 << idx;
714 channel->num = idx + 32;
715 return channel;
716 }
717 }
718
719 /* no more free channels available */
720 printk(KERN_ERR "trident: no more channels available on Bank B.\n");
721 return NULL;
722}
723
724static void
725trident_free_pcm_channel(struct trident_card *card, unsigned int channel)
726{
727 int bank;
728 unsigned char b;
729
730 if (channel < 31 || channel > 63)
731 return;
732
733 if (card->pci_id == PCI_DEVICE_ID_TRIDENT_4DWAVE_DX ||
734 card->pci_id == PCI_DEVICE_ID_TRIDENT_4DWAVE_NX) {
735 b = inb(TRID_REG(card, T4D_REC_CH));
736 if ((b & ~0x80) == channel)
737 outb(0x0, TRID_REG(card, T4D_REC_CH));
738 }
739
740 bank = channel >> 5;
741 channel = channel & 0x1f;
742
743 card->banks[bank].bitmap &= ~(1 << (channel));
744}
745
746static struct trident_channel *
747cyber_alloc_pcm_channel(struct trident_card *card)
748{
749 struct trident_pcm_bank *bank;
750 int idx;
751
752 /* The cyberpro 5050 has only 32 voices and one bank */
753 /* .. at least they are not documented (if you want to call that
754 * crap documentation), perhaps broken ? */
755
756 bank = &card->banks[BANK_A];
757
758 for (idx = 31; idx >= 0; idx--) {
759 if (!(bank->bitmap & (1 << idx))) {
760 struct trident_channel *channel = &bank->channels[idx];
761 bank->bitmap |= 1 << idx;
762 channel->num = idx;
763 return channel;
764 }
765 }
766
767 /* no more free channels available */
768 printk(KERN_ERR "cyberpro5050: no more channels available on Bank A.\n");
769 return NULL;
770}
771
772static void
773cyber_free_pcm_channel(struct trident_card *card, unsigned int channel)
774{
775 if (channel > 31)
776 return;
777 card->banks[BANK_A].bitmap &= ~(1 << (channel));
778}
779
780static inline void
781cyber_outidx(int port, int idx, int data)
782{
783 outb(idx, port);
784 outb(data, port + 1);
785}
786
787static inline int
788cyber_inidx(int port, int idx)
789{
790 outb(idx, port);
791 return inb(port + 1);
792}
793
794static int
795cyber_init_ritual(struct trident_card *card)
796{
797 /* some black magic, taken from SDK samples */
798 /* remove this and nothing will work */
799 int portDat;
800 int ret = 0;
801 unsigned long flags;
802
803 /*
804 * Keep interrupts off for the configure - we don't want to
805 * clash with another cyberpro config event
806 */
807
808 spin_lock_irqsave(&card->lock, flags);
809 portDat = cyber_inidx(CYBER_PORT_AUDIO, CYBER_IDX_AUDIO_ENABLE);
810 /* enable, if it was disabled */
811 if ((portDat & CYBER_BMSK_AUENZ) != CYBER_BMSK_AUENZ_ENABLE) {
812 printk(KERN_INFO "cyberpro5050: enabling audio controller\n");
813 cyber_outidx(CYBER_PORT_AUDIO, CYBER_IDX_AUDIO_ENABLE,
814 portDat | CYBER_BMSK_AUENZ_ENABLE);
815 /* check again if hardware is enabled now */
816 portDat = cyber_inidx(CYBER_PORT_AUDIO, CYBER_IDX_AUDIO_ENABLE);
817 }
818 if ((portDat & CYBER_BMSK_AUENZ) != CYBER_BMSK_AUENZ_ENABLE) {
819 printk(KERN_ERR "cyberpro5050: initAudioAccess: no success\n");
820 ret = -1;
821 } else {
822 cyber_outidx(CYBER_PORT_AUDIO, CYBER_IDX_IRQ_ENABLE,
823 CYBER_BMSK_AUDIO_INT_ENABLE);
824 cyber_outidx(CYBER_PORT_AUDIO, 0xbf, 0x01);
825 cyber_outidx(CYBER_PORT_AUDIO, 0xba, 0x20);
826 cyber_outidx(CYBER_PORT_AUDIO, 0xbb, 0x08);
827 cyber_outidx(CYBER_PORT_AUDIO, 0xbf, 0x02);
828 cyber_outidx(CYBER_PORT_AUDIO, 0xb3, 0x06);
829 cyber_outidx(CYBER_PORT_AUDIO, 0xbf, 0x00);
830 }
831 spin_unlock_irqrestore(&card->lock, flags);
832 return ret;
833}
834
835/* called with spin lock held */
836
837static int
838trident_load_channel_registers(struct trident_card *card, u32 * data,
839 unsigned int channel)
840{
841 int i;
842
843 if (channel > 63)
844 return 0;
845
846 /* select hardware channel to write */
847 outb(channel, TRID_REG(card, T4D_LFO_GC_CIR));
848
849 /* Output the channel registers, but don't write register
850 three to an ALI chip. */
851 for (i = 0; i < CHANNEL_REGS; i++) {
852 if (i == 3 && card->pci_id == PCI_DEVICE_ID_ALI_5451)
853 continue;
854 outl(data[i], TRID_REG(card, CHANNEL_START + 4 * i));
855 }
856 if (card->pci_id == PCI_DEVICE_ID_ALI_5451 ||
857 card->pci_id == PCI_DEVICE_ID_INTERG_5050) {
858 outl(ALI_EMOD_Still, TRID_REG(card, ALI_EBUF1));
859 outl(ALI_EMOD_Still, TRID_REG(card, ALI_EBUF2));
860 }
861 return 1;
862}
863
864/* called with spin lock held */
865static int
866trident_write_voice_regs(struct trident_state *state)
867{
868 unsigned int data[CHANNEL_REGS + 1];
869 struct trident_channel *channel;
870
871 channel = state->dmabuf.channel;
872
873 data[1] = channel->lba;
874 data[4] = channel->control;
875
876 switch (state->card->pci_id) {
877 case PCI_DEVICE_ID_ALI_5451:
878 data[0] = 0; /* Current Sample Offset */
879 data[2] = (channel->eso << 16) | (channel->delta & 0xffff);
880 data[3] = 0;
881 break;
882 case PCI_DEVICE_ID_SI_7018:
883 case PCI_DEVICE_ID_INTERG_5050:
884 data[0] = 0; /* Current Sample Offset */
885 data[2] = (channel->eso << 16) | (channel->delta & 0xffff);
886 data[3] = (channel->attribute << 16) | (channel->fm_vol & 0xffff);
887 break;
888 case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX:
889 data[0] = 0; /* Current Sample Offset */
890 data[2] = (channel->eso << 16) | (channel->delta & 0xffff);
891 data[3] = channel->fm_vol & 0xffff;
892 break;
893 case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX:
894 data[0] = (channel->delta << 24);
895 data[2] = ((channel->delta << 16) & 0xff000000) |
896 (channel->eso & 0x00ffffff);
897 data[3] = channel->fm_vol & 0xffff;
898 break;
899 default:
900 return 0;
901 }
902
903 return trident_load_channel_registers(state->card, data, channel->num);
904}
905
906static int
907compute_rate_play(u32 rate)
908{
909 int delta;
910 /* We special case 44100 and 8000 since rounding with the equation
911 does not give us an accurate enough value. For 11025 and 22050
912 the equation gives us the best answer. All other frequencies will
913 also use the equation. JDW */
914 if (rate == 44100)
915 delta = 0xeb3;
916 else if (rate == 8000)
917 delta = 0x2ab;
918 else if (rate == 48000)
919 delta = 0x1000;
920 else
921 delta = (((rate << 12) + rate) / 48000) & 0x0000ffff;
922 return delta;
923}
924
925static int
926compute_rate_rec(u32 rate)
927{
928 int delta;
929
930 if (rate == 44100)
931 delta = 0x116a;
932 else if (rate == 8000)
933 delta = 0x6000;
934 else if (rate == 48000)
935 delta = 0x1000;
936 else
937 delta = ((48000 << 12) / rate) & 0x0000ffff;
938
939 return delta;
940}
941
942/* set playback sample rate */
943static unsigned int
944trident_set_dac_rate(struct trident_state *state, unsigned int rate)
945{
946 struct dmabuf *dmabuf = &state->dmabuf;
947
948 if (rate > 48000)
949 rate = 48000;
950 if (rate < 4000)
951 rate = 4000;
952
953 dmabuf->rate = rate;
954 dmabuf->channel->delta = compute_rate_play(rate);
955
956 trident_write_voice_regs(state);
957
958 pr_debug("trident: called trident_set_dac_rate : rate = %d\n", rate);
959
960 return rate;
961}
962
963/* set recording sample rate */
964static unsigned int
965trident_set_adc_rate(struct trident_state *state, unsigned int rate)
966{
967 struct dmabuf *dmabuf = &state->dmabuf;
968
969 if (rate > 48000)
970 rate = 48000;
971 if (rate < 4000)
972 rate = 4000;
973
974 dmabuf->rate = rate;
975 dmabuf->channel->delta = compute_rate_rec(rate);
976
977 trident_write_voice_regs(state);
978
979 pr_debug("trident: called trident_set_adc_rate : rate = %d\n", rate);
980
981 return rate;
982}
983
984/* prepare channel attributes for playback */
985static void
986trident_play_setup(struct trident_state *state)
987{
988 struct dmabuf *dmabuf = &state->dmabuf;
989 struct trident_channel *channel = dmabuf->channel;
990
991 channel->lba = dmabuf->dma_handle;
992 channel->delta = compute_rate_play(dmabuf->rate);
993
994 channel->eso = dmabuf->dmasize >> sample_shift[dmabuf->fmt];
995 channel->eso -= 1;
996
997 if (state->card->pci_id != PCI_DEVICE_ID_SI_7018) {
998 channel->attribute = 0;
999 if (state->card->pci_id == PCI_DEVICE_ID_ALI_5451) {
1000 if ((channel->num == ALI_SPDIF_IN_CHANNEL) ||
1001 (channel->num == ALI_PCM_IN_CHANNEL))
1002 ali_disable_special_channel(state->card, channel->num);
1003 else if ((inl(TRID_REG(state->card, ALI_GLOBAL_CONTROL))
1004 & ALI_SPDIF_OUT_CH_ENABLE)
1005 && (channel->num == ALI_SPDIF_OUT_CHANNEL)) {
1006 ali_set_spdif_out_rate(state->card,
1007 state->dmabuf.rate);
1008 state->dmabuf.channel->delta = 0x1000;
1009 }
1010 }
1011 }
1012
1013 channel->fm_vol = 0x0;
1014
1015 channel->control = CHANNEL_LOOP;
1016 if (dmabuf->fmt & TRIDENT_FMT_16BIT) {
1017 /* 16-bits */
1018 channel->control |= CHANNEL_16BITS;
1019 /* signed */
1020 channel->control |= CHANNEL_SIGNED;
1021 }
1022 if (dmabuf->fmt & TRIDENT_FMT_STEREO)
1023 /* stereo */
1024 channel->control |= CHANNEL_STEREO;
1025
1026 pr_debug("trident: trident_play_setup, LBA = 0x%08x, Delta = 0x%08x, "
1027 "ESO = 0x%08x, Control = 0x%08x\n", channel->lba,
1028 channel->delta, channel->eso, channel->control);
1029
1030 trident_write_voice_regs(state);
1031}
1032
1033/* prepare channel attributes for recording */
1034static void
1035trident_rec_setup(struct trident_state *state)
1036{
1037 u16 w;
1038 u8 bval;
1039
1040 struct trident_card *card = state->card;
1041 struct dmabuf *dmabuf = &state->dmabuf;
1042 struct trident_channel *channel = dmabuf->channel;
1043 unsigned int rate;
1044
1045 /* Enable AC-97 ADC (capture) */
1046 switch (card->pci_id) {
1047 case PCI_DEVICE_ID_ALI_5451:
1048 ali_enable_special_channel(state);
1049 break;
1050 case PCI_DEVICE_ID_SI_7018:
1051 /* for 7018, the ac97 is always in playback/record (duplex) mode */
1052 break;
1053 case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX:
1054 w = inb(TRID_REG(card, DX_ACR2_AC97_COM_STAT));
1055 outb(w | 0x48, TRID_REG(card, DX_ACR2_AC97_COM_STAT));
1056 /* enable and set record channel */
1057 outb(0x80 | channel->num, TRID_REG(card, T4D_REC_CH));
1058 break;
1059 case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX:
1060 w = inw(TRID_REG(card, T4D_MISCINT));
1061 outw(w | 0x1000, TRID_REG(card, T4D_MISCINT));
1062 /* enable and set record channel */
1063 outb(0x80 | channel->num, TRID_REG(card, T4D_REC_CH));
1064 break;
1065 case PCI_DEVICE_ID_INTERG_5050:
1066 /* don't know yet, using special channel 22 in GC1(0xd4)? */
1067 break;
1068 default:
1069 return;
1070 }
1071
1072 channel->lba = dmabuf->dma_handle;
1073 channel->delta = compute_rate_rec(dmabuf->rate);
1074 if ((card->pci_id == PCI_DEVICE_ID_ALI_5451) &&
1075 (channel->num == ALI_SPDIF_IN_CHANNEL)) {
1076 rate = ali_get_spdif_in_rate(card);
1077 if (rate == 0) {
1078 printk(KERN_WARNING "trident: ALi 5451 "
1079 "S/PDIF input setup error!\n");
1080 rate = 48000;
1081 }
1082 bval = inb(TRID_REG(card, ALI_SPDIF_CTRL));
1083 if (bval & 0x10) {
1084 outb(bval, TRID_REG(card, ALI_SPDIF_CTRL));
1085 printk(KERN_WARNING "trident: cleared ALi "
1086 "5451 S/PDIF parity error flag.\n");
1087 }
1088
1089 if (rate != 48000)
1090 channel->delta = ((rate << 12) / dmabuf->rate) & 0x0000ffff;
1091 }
1092
1093 channel->eso = dmabuf->dmasize >> sample_shift[dmabuf->fmt];
1094 channel->eso -= 1;
1095
1096 if (state->card->pci_id != PCI_DEVICE_ID_SI_7018) {
1097 channel->attribute = 0;
1098 }
1099
1100 channel->fm_vol = 0x0;
1101
1102 channel->control = CHANNEL_LOOP;
1103 if (dmabuf->fmt & TRIDENT_FMT_16BIT) {
1104 /* 16-bits */
1105 channel->control |= CHANNEL_16BITS;
1106 /* signed */
1107 channel->control |= CHANNEL_SIGNED;
1108 }
1109 if (dmabuf->fmt & TRIDENT_FMT_STEREO)
1110 /* stereo */
1111 channel->control |= CHANNEL_STEREO;
1112
1113 pr_debug("trident: trident_rec_setup, LBA = 0x%08x, Delat = 0x%08x, "
1114 "ESO = 0x%08x, Control = 0x%08x\n", channel->lba,
1115 channel->delta, channel->eso, channel->control);
1116
1117 trident_write_voice_regs(state);
1118}
1119
1120/* get current playback/recording dma buffer pointer (byte offset from LBA),
1121 called with spinlock held! */
1122static inline unsigned
1123trident_get_dma_addr(struct trident_state *state)
1124{
1125 struct dmabuf *dmabuf = &state->dmabuf;
1126 u32 cso;
1127
1128 if (!dmabuf->enable)
1129 return 0;
1130
1131 outb(dmabuf->channel->num, TRID_REG(state->card, T4D_LFO_GC_CIR));
1132
1133 switch (state->card->pci_id) {
1134 case PCI_DEVICE_ID_ALI_5451:
1135 case PCI_DEVICE_ID_SI_7018:
1136 case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX:
1137 case PCI_DEVICE_ID_INTERG_5050:
1138 /* 16 bits ESO, CSO for 7018 and DX */
1139 cso = inw(TRID_REG(state->card, CH_DX_CSO_ALPHA_FMS + 2));
1140 break;
1141 case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX:
1142 /* 24 bits ESO, CSO for NX */
1143 cso = inl(TRID_REG(state->card, CH_NX_DELTA_CSO)) & 0x00ffffff;
1144 break;
1145 default:
1146 return 0;
1147 }
1148
1149 pr_debug("trident: trident_get_dma_addr: chip reported channel: %d, "
1150 "cso = 0x%04x\n", dmabuf->channel->num, cso);
1151
1152 /* ESO and CSO are in units of Samples, convert to byte offset */
1153 cso <<= sample_shift[dmabuf->fmt];
1154
1155 return (cso % dmabuf->dmasize);
1156}
1157
1158/* Stop recording (lock held) */
1159static inline void
1160__stop_adc(struct trident_state *state)
1161{
1162 struct dmabuf *dmabuf = &state->dmabuf;
1163 unsigned int chan_num = dmabuf->channel->num;
1164 struct trident_card *card = state->card;
1165
1166 dmabuf->enable &= ~ADC_RUNNING;
1167 trident_stop_voice(card, chan_num);
1168 trident_disable_voice_irq(card, chan_num);
1169}
1170
1171static void
1172stop_adc(struct trident_state *state)
1173{
1174 struct trident_card *card = state->card;
1175 unsigned long flags;
1176
1177 spin_lock_irqsave(&card->lock, flags);
1178 __stop_adc(state);
1179 spin_unlock_irqrestore(&card->lock, flags);
1180}
1181
1182static void
1183start_adc(struct trident_state *state)
1184{
1185 struct dmabuf *dmabuf = &state->dmabuf;
1186 unsigned int chan_num = dmabuf->channel->num;
1187 struct trident_card *card = state->card;
1188 unsigned long flags;
1189
1190 spin_lock_irqsave(&card->lock, flags);
1191 if ((dmabuf->mapped ||
1192 dmabuf->count < (signed) dmabuf->dmasize) &&
1193 dmabuf->ready) {
1194 dmabuf->enable |= ADC_RUNNING;
1195 trident_enable_voice_irq(card, chan_num);
1196 trident_start_voice(card, chan_num);
1197 }
1198 spin_unlock_irqrestore(&card->lock, flags);
1199}
1200
1201/* stop playback (lock held) */
1202static inline void
1203__stop_dac(struct trident_state *state)
1204{
1205 struct dmabuf *dmabuf = &state->dmabuf;
1206 unsigned int chan_num = dmabuf->channel->num;
1207 struct trident_card *card = state->card;
1208
1209 dmabuf->enable &= ~DAC_RUNNING;
1210 trident_stop_voice(card, chan_num);
1211 if (state->chans_num == 6) {
1212 trident_stop_voice(card, state->other_states[0]->
1213 dmabuf.channel->num);
1214 trident_stop_voice(card, state->other_states[1]->
1215 dmabuf.channel->num);
1216 trident_stop_voice(card, state->other_states[2]->
1217 dmabuf.channel->num);
1218 trident_stop_voice(card, state->other_states[3]->
1219 dmabuf.channel->num);
1220 }
1221 trident_disable_voice_irq(card, chan_num);
1222}
1223
1224static void
1225stop_dac(struct trident_state *state)
1226{
1227 struct trident_card *card = state->card;
1228 unsigned long flags;
1229
1230 spin_lock_irqsave(&card->lock, flags);
1231 __stop_dac(state);
1232 spin_unlock_irqrestore(&card->lock, flags);
1233}
1234
1235static void
1236start_dac(struct trident_state *state)
1237{
1238 struct dmabuf *dmabuf = &state->dmabuf;
1239 unsigned int chan_num = dmabuf->channel->num;
1240 struct trident_card *card = state->card;
1241 unsigned long flags;
1242
1243 spin_lock_irqsave(&card->lock, flags);
1244 if ((dmabuf->mapped || dmabuf->count > 0) && dmabuf->ready) {
1245 dmabuf->enable |= DAC_RUNNING;
1246 trident_enable_voice_irq(card, chan_num);
1247 trident_start_voice(card, chan_num);
1248 if (state->chans_num == 6) {
1249 trident_start_voice(card, state->other_states[0]->
1250 dmabuf.channel->num);
1251 trident_start_voice(card, state->other_states[1]->
1252 dmabuf.channel->num);
1253 trident_start_voice(card, state->other_states[2]->
1254 dmabuf.channel->num);
1255 trident_start_voice(card, state->other_states[3]->
1256 dmabuf.channel->num);
1257 }
1258 }
1259 spin_unlock_irqrestore(&card->lock, flags);
1260}
1261
1262#define DMABUF_DEFAULTORDER (15-PAGE_SHIFT)
1263#define DMABUF_MINORDER 1
1264
1265/* alloc a DMA buffer of with a buffer of this order */
1266static int
1267alloc_dmabuf(struct dmabuf *dmabuf, struct pci_dev *pci_dev, int order)
1268{
1269 void *rawbuf = NULL;
1270 struct page *page, *pend;
1271
1272 if (!(rawbuf = pci_alloc_consistent(pci_dev, PAGE_SIZE << order,
1273 &dmabuf->dma_handle)))
1274 return -ENOMEM;
1275
1276 pr_debug("trident: allocated %ld (order = %d) bytes at %p\n",
1277 PAGE_SIZE << order, order, rawbuf);
1278
1279 dmabuf->ready = dmabuf->mapped = 0;
1280 dmabuf->rawbuf = rawbuf;
1281 dmabuf->buforder = order;
1282
1283 /* now mark the pages as reserved; otherwise */
1284 /* remap_pfn_range doesn't do what we want */
1285 pend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1);
1286 for (page = virt_to_page(rawbuf); page <= pend; page++)
1287 SetPageReserved(page);
1288
1289 return 0;
1290}
1291
1292/* allocate the main DMA buffer, playback and recording buffer should be */
1293/* allocated separately */
1294static int
1295alloc_main_dmabuf(struct trident_state *state)
1296{
1297 struct dmabuf *dmabuf = &state->dmabuf;
1298 int order;
1299 int ret = -ENOMEM;
1300
1301 /* alloc as big a chunk as we can, FIXME: is this necessary ?? */
1302 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--) {
1303 if (!(ret = alloc_dmabuf(dmabuf, state->card->pci_dev, order)))
1304 return 0;
1305 /* else try again */
1306 }
1307 return ret;
1308}
1309
1310/* deallocate a DMA buffer */
1311static void
1312dealloc_dmabuf(struct dmabuf *dmabuf, struct pci_dev *pci_dev)
1313{
1314 struct page *page, *pend;
1315
1316 if (dmabuf->rawbuf) {
1317 /* undo marking the pages as reserved */
1318 pend = virt_to_page(dmabuf->rawbuf + (PAGE_SIZE << dmabuf->buforder) - 1);
1319 for (page = virt_to_page(dmabuf->rawbuf); page <= pend; page++)
1320 ClearPageReserved(page);
1321 pci_free_consistent(pci_dev, PAGE_SIZE << dmabuf->buforder,
1322 dmabuf->rawbuf, dmabuf->dma_handle);
1323 dmabuf->rawbuf = NULL;
1324 }
1325 dmabuf->mapped = dmabuf->ready = 0;
1326}
1327
1328static int
1329prog_dmabuf(struct trident_state *state, enum dmabuf_mode rec)
1330{
1331 struct dmabuf *dmabuf = &state->dmabuf;
1332 unsigned bytepersec;
1333 struct trident_state *s = state;
1334 unsigned bufsize, dma_nums;
1335 unsigned long flags;
1336 int ret, i, order;
1337
1338 if ((ret = lock_set_fmt(state)) < 0)
1339 return ret;
1340
1341 if (state->chans_num == 6)
1342 dma_nums = 5;
1343 else
1344 dma_nums = 1;
1345
1346 for (i = 0; i < dma_nums; i++) {
1347 if (i > 0) {
1348 s = state->other_states[i - 1];
1349 dmabuf = &s->dmabuf;
1350 dmabuf->fmt = state->dmabuf.fmt;
1351 dmabuf->rate = state->dmabuf.rate;
1352 }
1353
1354 spin_lock_irqsave(&s->card->lock, flags);
1355 dmabuf->hwptr = dmabuf->swptr = dmabuf->total_bytes = 0;
1356 dmabuf->count = dmabuf->error = 0;
1357 spin_unlock_irqrestore(&s->card->lock, flags);
1358
1359 /* allocate DMA buffer if not allocated yet */
1360 if (!dmabuf->rawbuf) {
1361 if (i == 0) {
1362 if ((ret = alloc_main_dmabuf(state))) {
1363 unlock_set_fmt(state);
1364 return ret;
1365 }
1366 } else {
1367 ret = -ENOMEM;
1368 order = state->dmabuf.buforder - 1;
1369 if (order >= DMABUF_MINORDER) {
1370 ret = alloc_dmabuf(dmabuf,
1371 state->card->pci_dev,
1372 order);
1373 }
1374 if (ret) {
1375 /* release the main DMA buffer */
1376 dealloc_dmabuf(&state->dmabuf, state->card->pci_dev);
1377 /* release the auxiliary DMA buffers */
1378 for (i -= 2; i >= 0; i--)
1379 dealloc_dmabuf(&state->other_states[i]->dmabuf,
1380 state->card->pci_dev);
1381 unlock_set_fmt(state);
1382 return ret;
1383 }
1384 }
1385 }
1386 /* FIXME: figure out all this OSS fragment stuff */
1387 bytepersec = dmabuf->rate << sample_shift[dmabuf->fmt];
1388 bufsize = PAGE_SIZE << dmabuf->buforder;
1389 if (dmabuf->ossfragshift) {
1390 if ((1000 << dmabuf->ossfragshift) < bytepersec)
1391 dmabuf->fragshift = ld2(bytepersec / 1000);
1392 else
1393 dmabuf->fragshift = dmabuf->ossfragshift;
1394 } else {
1395 /* lets hand out reasonable big ass buffers by default */
1396 dmabuf->fragshift = (dmabuf->buforder + PAGE_SHIFT - 2);
1397 }
1398 dmabuf->numfrag = bufsize >> dmabuf->fragshift;
1399 while (dmabuf->numfrag < 4 && dmabuf->fragshift > 3) {
1400 dmabuf->fragshift--;
1401 dmabuf->numfrag = bufsize >> dmabuf->fragshift;
1402 }
1403 dmabuf->fragsize = 1 << dmabuf->fragshift;
1404 if (dmabuf->ossmaxfrags >= 4 && dmabuf->ossmaxfrags < dmabuf->numfrag)
1405 dmabuf->numfrag = dmabuf->ossmaxfrags;
1406 dmabuf->fragsamples = dmabuf->fragsize >> sample_shift[dmabuf->fmt];
1407 dmabuf->dmasize = dmabuf->numfrag << dmabuf->fragshift;
1408
1409 memset(dmabuf->rawbuf, (dmabuf->fmt & TRIDENT_FMT_16BIT) ? 0 : 0x80,
1410 dmabuf->dmasize);
1411
1412 spin_lock_irqsave(&s->card->lock, flags);
1413 if (rec == DM_RECORD)
1414 trident_rec_setup(s);
1415 else /* DM_PLAYBACK */
1416 trident_play_setup(s);
1417
1418 spin_unlock_irqrestore(&s->card->lock, flags);
1419
1420 /* set the ready flag for the dma buffer */
1421 dmabuf->ready = 1;
1422
1423 pr_debug("trident: prog_dmabuf(%d), sample rate = %d, "
1424 "format = %d, numfrag = %d, fragsize = %d "
1425 "dmasize = %d\n", dmabuf->channel->num,
1426 dmabuf->rate, dmabuf->fmt, dmabuf->numfrag,
1427 dmabuf->fragsize, dmabuf->dmasize);
1428 }
1429 unlock_set_fmt(state);
1430 return 0;
1431}
1432
1433
1434static inline int prog_dmabuf_record(struct trident_state* state)
1435{
1436 return prog_dmabuf(state, DM_RECORD);
1437}
1438
1439static inline int prog_dmabuf_playback(struct trident_state* state)
1440{
1441 return prog_dmabuf(state, DM_PLAYBACK);
1442}
1443
1444/* we are doing quantum mechanics here, the buffer can only be empty, half or full filled i.e.
1445 |------------|------------| or |xxxxxxxxxxxx|------------| or |xxxxxxxxxxxx|xxxxxxxxxxxx|
1446 but we almost always get this
1447 |xxxxxx------|------------| or |xxxxxxxxxxxx|xxxxx-------|
1448 so we have to clear the tail space to "silence"
1449 |xxxxxx000000|------------| or |xxxxxxxxxxxx|xxxxxx000000|
1450*/
1451static void
1452trident_clear_tail(struct trident_state *state)
1453{
1454 struct dmabuf *dmabuf = &state->dmabuf;
1455 unsigned swptr;
1456 unsigned char silence = (dmabuf->fmt & TRIDENT_FMT_16BIT) ? 0 : 0x80;
1457 unsigned int len;
1458 unsigned long flags;
1459
1460 spin_lock_irqsave(&state->card->lock, flags);
1461 swptr = dmabuf->swptr;
1462 spin_unlock_irqrestore(&state->card->lock, flags);
1463
1464 if (swptr == 0 || swptr == dmabuf->dmasize / 2 ||
1465 swptr == dmabuf->dmasize)
1466 return;
1467
1468 if (swptr < dmabuf->dmasize / 2)
1469 len = dmabuf->dmasize / 2 - swptr;
1470 else
1471 len = dmabuf->dmasize - swptr;
1472
1473 memset(dmabuf->rawbuf + swptr, silence, len);
1474 if (state->card->pci_id != PCI_DEVICE_ID_ALI_5451) {
1475 spin_lock_irqsave(&state->card->lock, flags);
1476 dmabuf->swptr += len;
1477 dmabuf->count += len;
1478 spin_unlock_irqrestore(&state->card->lock, flags);
1479 }
1480
1481 /* restart the dma machine in case it is halted */
1482 start_dac(state);
1483}
1484
1485static int
1486drain_dac(struct trident_state *state, int nonblock)
1487{
1488 DECLARE_WAITQUEUE(wait, current);
1489 struct dmabuf *dmabuf = &state->dmabuf;
1490 unsigned long flags;
1491 unsigned long tmo;
1492 int count;
1493 unsigned long diff = 0;
1494
1495 if (dmabuf->mapped || !dmabuf->ready)
1496 return 0;
1497
1498 add_wait_queue(&dmabuf->wait, &wait);
1499 for (;;) {
1500 /* It seems that we have to set the current state to TASK_INTERRUPTIBLE
1501 every time to make the process really go to sleep */
1502 set_current_state(TASK_INTERRUPTIBLE);
1503
1504 spin_lock_irqsave(&state->card->lock, flags);
1505 count = dmabuf->count;
1506 spin_unlock_irqrestore(&state->card->lock, flags);
1507
1508 if (count <= 0)
1509 break;
1510
1511 if (signal_pending(current))
1512 break;
1513
1514 if (nonblock) {
1515 remove_wait_queue(&dmabuf->wait, &wait);
1516 set_current_state(TASK_RUNNING);
1517 return -EBUSY;
1518 }
1519
1520 /* No matter how much data is left in the buffer, we have to wait until
1521 CSO == ESO/2 or CSO == ESO when address engine interrupts */
1522 if (state->card->pci_id == PCI_DEVICE_ID_ALI_5451 ||
1523 state->card->pci_id == PCI_DEVICE_ID_INTERG_5050) {
1524 diff = dmabuf->swptr - trident_get_dma_addr(state) + dmabuf->dmasize;
1525 diff = diff % (dmabuf->dmasize);
1526 tmo = (diff * HZ) / dmabuf->rate;
1527 } else {
1528 tmo = (dmabuf->dmasize * HZ) / dmabuf->rate;
1529 }
1530 tmo >>= sample_shift[dmabuf->fmt];
1531 if (!schedule_timeout(tmo ? tmo : 1) && tmo) {
1532 break;
1533 }
1534 }
1535 remove_wait_queue(&dmabuf->wait, &wait);
1536 set_current_state(TASK_RUNNING);
1537 if (signal_pending(current))
1538 return -ERESTARTSYS;
1539
1540 return 0;
1541}
1542
1543/* update buffer manangement pointers, especially, */
1544/* dmabuf->count and dmabuf->hwptr */
1545static void
1546trident_update_ptr(struct trident_state *state)
1547{
1548 struct dmabuf *dmabuf = &state->dmabuf;
1549 unsigned hwptr, swptr;
1550 int clear_cnt = 0;
1551 int diff;
1552 unsigned char silence;
1553 unsigned half_dmasize;
1554
1555 /* update hardware pointer */
1556 hwptr = trident_get_dma_addr(state);
1557 diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize;
1558 dmabuf->hwptr = hwptr;
1559 dmabuf->total_bytes += diff;
1560
1561 /* error handling and process wake up for ADC */
1562 if (dmabuf->enable == ADC_RUNNING) {
1563 if (dmabuf->mapped) {
1564 dmabuf->count -= diff;
1565 if (dmabuf->count >= (signed) dmabuf->fragsize)
1566 wake_up(&dmabuf->wait);
1567 } else {
1568 dmabuf->count += diff;
1569
1570 if (dmabuf->count < 0 ||
1571 dmabuf->count > dmabuf->dmasize) {
1572 /* buffer underrun or buffer overrun, */
1573 /* we have no way to recover it here, just */
1574 /* stop the machine and let the process */
1575 /* force hwptr and swptr to sync */
1576 __stop_adc(state);
1577 dmabuf->error++;
1578 }
1579 if (dmabuf->count < (signed) dmabuf->dmasize / 2)
1580 wake_up(&dmabuf->wait);
1581 }
1582 }
1583
1584 /* error handling and process wake up for DAC */
1585 if (dmabuf->enable == DAC_RUNNING) {
1586 if (dmabuf->mapped) {
1587 dmabuf->count += diff;
1588 if (dmabuf->count >= (signed) dmabuf->fragsize)
1589 wake_up(&dmabuf->wait);
1590 } else {
1591 dmabuf->count -= diff;
1592
1593 if (dmabuf->count < 0 ||
1594 dmabuf->count > dmabuf->dmasize) {
1595 /* buffer underrun or buffer overrun, we have no way to recover
1596 it here, just stop the machine and let the process force hwptr
1597 and swptr to sync */
1598 __stop_dac(state);
1599 dmabuf->error++;
1600 } else if (!dmabuf->endcleared) {
1601 swptr = dmabuf->swptr;
1602 silence = (dmabuf->fmt & TRIDENT_FMT_16BIT ? 0 : 0x80);
1603 if (dmabuf->update_flag & ALI_ADDRESS_INT_UPDATE) {
1604 /* We must clear end data of 1/2 dmabuf if needed.
1605 According to 1/2 algorithm of Address Engine Interrupt,
1606 check the validation of the data of half dmasize. */
1607 half_dmasize = dmabuf->dmasize / 2;
1608 if ((diff = hwptr - half_dmasize) < 0)
1609 diff = hwptr;
1610 if ((dmabuf->count + diff) < half_dmasize) {
1611 //there is invalid data in the end of half buffer
1612 if ((clear_cnt = half_dmasize - swptr) < 0)
1613 clear_cnt += half_dmasize;
1614 //clear the invalid data
1615 memset(dmabuf->rawbuf + swptr, silence, clear_cnt);
1616 if (state->chans_num == 6) {
1617 clear_cnt = clear_cnt / 2;
1618 swptr = swptr / 2;
1619 memset(state->other_states[0]->dmabuf.rawbuf + swptr,
1620 silence, clear_cnt);
1621 memset(state->other_states[1]->dmabuf.rawbuf + swptr,
1622 silence, clear_cnt);
1623 memset(state->other_states[2]->dmabuf.rawbuf + swptr,
1624 silence, clear_cnt);
1625 memset(state->other_states[3]->dmabuf.rawbuf + swptr,
1626 silence, clear_cnt);
1627 }
1628 dmabuf->endcleared = 1;
1629 }
1630 } else if (dmabuf->count < (signed) dmabuf->fragsize) {
1631 clear_cnt = dmabuf->fragsize;
1632 if ((swptr + clear_cnt) > dmabuf->dmasize)
1633 clear_cnt = dmabuf->dmasize - swptr;
1634 memset(dmabuf->rawbuf + swptr, silence, clear_cnt);
1635 if (state->chans_num == 6) {
1636 clear_cnt = clear_cnt / 2;
1637 swptr = swptr / 2;
1638 memset(state->other_states[0]->dmabuf.rawbuf + swptr,
1639 silence, clear_cnt);
1640 memset(state->other_states[1]->dmabuf.rawbuf + swptr,
1641 silence, clear_cnt);
1642 memset(state->other_states[2]->dmabuf.rawbuf + swptr,
1643 silence, clear_cnt);
1644 memset(state->other_states[3]->dmabuf.rawbuf + swptr,
1645 silence, clear_cnt);
1646 }
1647 dmabuf->endcleared = 1;
1648 }
1649 }
1650 /* trident_update_ptr is called by interrupt handler or by process via
1651 ioctl/poll, we only wake up the waiting process when we have more
1652 than 1/2 buffer free (always true for interrupt handler) */
1653 if (dmabuf->count < (signed) dmabuf->dmasize / 2)
1654 wake_up(&dmabuf->wait);
1655 }
1656 }
1657 dmabuf->update_flag &= ~ALI_ADDRESS_INT_UPDATE;
1658}
1659
1660static void
1661trident_address_interrupt(struct trident_card *card)
1662{
1663 int i;
1664 struct trident_state *state;
1665 unsigned int channel;
1666
1667 /* Update the pointers for all channels we are running. */
1668 /* FIXME: should read interrupt status only once */
1669 for (i = 0; i < NR_HW_CH; i++) {
1670 channel = 63 - i;
1671 if (trident_check_channel_interrupt(card, channel)) {
1672 trident_ack_channel_interrupt(card, channel);
1673 if ((state = card->states[i]) != NULL) {
1674 trident_update_ptr(state);
1675 } else {
1676 printk(KERN_WARNING "trident: spurious channel "
1677 "irq %d.\n", channel);
1678 trident_stop_voice(card, channel);
1679 trident_disable_voice_irq(card, channel);
1680 }
1681 }
1682 }
1683}
1684
1685static void
1686ali_hwvol_control(struct trident_card *card, int opt)
1687{
1688 u16 dwTemp, volume[2], mute, diff, *pVol[2];
1689
1690 dwTemp = ali_ac97_read(card->ac97_codec[0], 0x02);
1691 mute = dwTemp & 0x8000;
1692 volume[0] = dwTemp & 0x001f;
1693 volume[1] = (dwTemp & 0x1f00) >> 8;
1694 if (volume[0] < volume[1]) {
1695 pVol[0] = &volume[0];
1696 pVol[1] = &volume[1];
1697 } else {
1698 pVol[1] = &volume[0];
1699 pVol[0] = &volume[1];
1700 }
1701 diff = *(pVol[1]) - *(pVol[0]);
1702
1703 if (opt == 1) { // MUTE
1704 dwTemp ^= 0x8000;
1705 ali_ac97_write(card->ac97_codec[0],
1706 0x02, dwTemp);
1707 } else if (opt == 2) { // Down
1708 if (mute)
1709 return;
1710 if (*(pVol[1]) < 0x001f) {
1711 (*pVol[1])++;
1712 *(pVol[0]) = *(pVol[1]) - diff;
1713 }
1714 dwTemp &= 0xe0e0;
1715 dwTemp |= (volume[0]) | (volume[1] << 8);
1716 ali_ac97_write(card->ac97_codec[0], 0x02, dwTemp);
1717 card->ac97_codec[0]->mixer_state[0] = ((32 - volume[0]) * 25 / 8) |
1718 (((32 - volume[1]) * 25 / 8) << 8);
1719 } else if (opt == 4) { // Up
1720 if (mute)
1721 return;
1722 if (*(pVol[0]) > 0) {
1723 (*pVol[0])--;
1724 *(pVol[1]) = *(pVol[0]) + diff;
1725 }
1726 dwTemp &= 0xe0e0;
1727 dwTemp |= (volume[0]) | (volume[1] << 8);
1728 ali_ac97_write(card->ac97_codec[0], 0x02, dwTemp);
1729 card->ac97_codec[0]->mixer_state[0] = ((32 - volume[0]) * 25 / 8) |
1730 (((32 - volume[1]) * 25 / 8) << 8);
1731 } else {
1732 /* Nothing needs doing */
1733 }
1734}
1735
1736/*
1737 * Re-enable reporting of vol change after 0.1 seconds
1738 */
1739
1740static void
1741ali_timeout(unsigned long ptr)
1742{
1743 struct trident_card *card = (struct trident_card *) ptr;
1744 u16 temp = 0;
1745
1746 /* Enable GPIO IRQ (MISCINT bit 18h) */
1747 temp = inw(TRID_REG(card, T4D_MISCINT + 2));
1748 temp |= 0x0004;
1749 outw(temp, TRID_REG(card, T4D_MISCINT + 2));
1750}
1751
1752/*
1753 * Set up the timer to clear the vol change notification
1754 */
1755
1756static void
1757ali_set_timer(struct trident_card *card)
1758{
1759 /* Add Timer Routine to Enable GPIO IRQ */
1760 del_timer(&card->timer); /* Never queue twice */
1761 card->timer.function = ali_timeout;
1762 card->timer.data = (unsigned long) card;
1763 card->timer.expires = jiffies + HZ / 10;
1764 add_timer(&card->timer);
1765}
1766
1767/*
1768 * Process a GPIO event
1769 */
1770
1771static void
1772ali_queue_task(struct trident_card *card, int opt)
1773{
1774 u16 temp;
1775
1776 /* Disable GPIO IRQ (MISCINT bit 18h) */
1777 temp = inw(TRID_REG(card, T4D_MISCINT + 2));
1778 temp &= (u16) (~0x0004);
1779 outw(temp, TRID_REG(card, T4D_MISCINT + 2));
1780
1781 /* Adjust the volume */
1782 ali_hwvol_control(card, opt);
1783
1784 /* Set the timer for 1/10th sec */
1785 ali_set_timer(card);
1786}
1787
1788static void
1789cyber_address_interrupt(struct trident_card *card)
1790{
1791 int i, irq_status;
1792 struct trident_state *state;
1793 unsigned int channel;
1794
1795 /* Update the pointers for all channels we are running. */
1796 /* FIXED: read interrupt status only once */
1797 irq_status = inl(TRID_REG(card, T4D_AINT_A));
1798
1799 pr_debug("cyber_address_interrupt: irq_status 0x%X\n", irq_status);
1800
1801 for (i = 0; i < NR_HW_CH; i++) {
1802 channel = 31 - i;
1803 if (irq_status & (1 << channel)) {
1804 /* clear bit by writing a 1, zeroes are ignored */
1805 outl((1 << channel), TRID_REG(card, T4D_AINT_A));
1806
1807 pr_debug("cyber_interrupt: channel %d\n", channel);
1808
1809 if ((state = card->states[i]) != NULL) {
1810 trident_update_ptr(state);
1811 } else {
1812 printk(KERN_WARNING "cyber5050: spurious "
1813 "channel irq %d.\n", channel);
1814 trident_stop_voice(card, channel);
1815 trident_disable_voice_irq(card, channel);
1816 }
1817 }
1818 }
1819}
1820
1821static irqreturn_t
1822trident_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1823{
1824 struct trident_card *card = (struct trident_card *) dev_id;
1825 u32 event;
1826 u32 gpio;
1827
1828 spin_lock(&card->lock);
1829 event = inl(TRID_REG(card, T4D_MISCINT));
1830
1831 pr_debug("trident: trident_interrupt called, MISCINT = 0x%08x\n",
1832 event);
1833
1834 if (event & ADDRESS_IRQ) {
1835 card->address_interrupt(card);
1836 }
1837
1838 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
1839 /* GPIO IRQ (H/W Volume Control) */
1840 event = inl(TRID_REG(card, T4D_MISCINT));
1841 if (event & (1 << 25)) {
1842 gpio = inl(TRID_REG(card, ALI_GPIO));
1843 if (!timer_pending(&card->timer))
1844 ali_queue_task(card, gpio & 0x07);
1845 }
1846 event = inl(TRID_REG(card, T4D_MISCINT));
1847 outl(event | (ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW),
1848 TRID_REG(card, T4D_MISCINT));
1849 spin_unlock(&card->lock);
1850 return IRQ_HANDLED;
1851 }
1852
1853 /* manually clear interrupt status, bad hardware design, blame T^2 */
1854 outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW),
1855 TRID_REG(card, T4D_MISCINT));
1856 spin_unlock(&card->lock);
1857 return IRQ_HANDLED;
1858}
1859
1860/* in this loop, dmabuf.count signifies the amount of data that is waiting */
1861/* to be copied to the user's buffer. it is filled by the dma machine and */
1862/* drained by this loop. */
1863static ssize_t
1864trident_read(struct file *file, char __user *buffer, size_t count, loff_t * ppos)
1865{
1866 struct trident_state *state = (struct trident_state *)file->private_data;
1867 struct dmabuf *dmabuf = &state->dmabuf;
1868 ssize_t ret = 0;
1869 unsigned long flags;
1870 unsigned swptr;
1871 int cnt;
1872
1873 pr_debug("trident: trident_read called, count = %d\n", count);
1874
1875 VALIDATE_STATE(state);
1876
1877 if (dmabuf->mapped)
1878 return -ENXIO;
1879 if (!access_ok(VERIFY_WRITE, buffer, count))
1880 return -EFAULT;
1881
1882 down(&state->sem);
1883 if (!dmabuf->ready && (ret = prog_dmabuf_record(state)))
1884 goto out;
1885
1886 while (count > 0) {
1887 spin_lock_irqsave(&state->card->lock, flags);
1888 if (dmabuf->count > (signed) dmabuf->dmasize) {
1889 /* buffer overrun, we are recovering from */
1890 /* sleep_on_timeout, resync hwptr and swptr, */
1891 /* make process flush the buffer */
1892 dmabuf->count = dmabuf->dmasize;
1893 dmabuf->swptr = dmabuf->hwptr;
1894 }
1895 swptr = dmabuf->swptr;
1896 cnt = dmabuf->dmasize - swptr;
1897 if (dmabuf->count < cnt)
1898 cnt = dmabuf->count;
1899 spin_unlock_irqrestore(&state->card->lock, flags);
1900
1901 if (cnt > count)
1902 cnt = count;
1903 if (cnt <= 0) {
1904 unsigned long tmo;
1905 /* buffer is empty, start the dma machine and */
1906 /* wait for data to be recorded */
1907 start_adc(state);
1908 if (file->f_flags & O_NONBLOCK) {
1909 if (!ret)
1910 ret = -EAGAIN;
1911 goto out;
1912 }
1913
1914 up(&state->sem);
1915 /* No matter how much space left in the buffer, */
1916 /* we have to wait until CSO == ESO/2 or CSO == ESO */
1917 /* when address engine interrupts */
1918 tmo = (dmabuf->dmasize * HZ) / (dmabuf->rate * 2);
1919 tmo >>= sample_shift[dmabuf->fmt];
1920 /* There are two situations when sleep_on_timeout returns, one is when
1921 the interrupt is serviced correctly and the process is waked up by
1922 ISR ON TIME. Another is when timeout is expired, which means that
1923 either interrupt is NOT serviced correctly (pending interrupt) or it
1924 is TOO LATE for the process to be scheduled to run (scheduler latency)
1925 which results in a (potential) buffer overrun. And worse, there is
1926 NOTHING we can do to prevent it. */
1927 if (!interruptible_sleep_on_timeout(&dmabuf->wait, tmo)) {
1928 pr_debug(KERN_ERR "trident: recording schedule timeout, "
1929 "dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1930 dmabuf->dmasize, dmabuf->fragsize, dmabuf->count,
1931 dmabuf->hwptr, dmabuf->swptr);
1932
1933 /* a buffer overrun, we delay the recovery until next time the
1934 while loop begin and we REALLY have space to record */
1935 }
1936 if (signal_pending(current)) {
1937 if (!ret)
1938 ret = -ERESTARTSYS;
1939 goto out;
1940 }
1941 down(&state->sem);
1942 if (dmabuf->mapped) {
1943 if (!ret)
1944 ret = -ENXIO;
1945 goto out;
1946 }
1947 continue;
1948 }
1949
1950 if (copy_to_user(buffer, dmabuf->rawbuf + swptr, cnt)) {
1951 if (!ret)
1952 ret = -EFAULT;
1953 goto out;
1954 }
1955
1956 swptr = (swptr + cnt) % dmabuf->dmasize;
1957
1958 spin_lock_irqsave(&state->card->lock, flags);
1959 dmabuf->swptr = swptr;
1960 dmabuf->count -= cnt;
1961 spin_unlock_irqrestore(&state->card->lock, flags);
1962
1963 count -= cnt;
1964 buffer += cnt;
1965 ret += cnt;
1966 start_adc(state);
1967 }
1968out:
1969 up(&state->sem);
1970 return ret;
1971}
1972
1973/* in this loop, dmabuf.count signifies the amount of data that is waiting to be dma to
1974 the soundcard. it is drained by the dma machine and filled by this loop. */
1975
1976static ssize_t
1977trident_write(struct file *file, const char __user *buffer, size_t count, loff_t * ppos)
1978{
1979 struct trident_state *state = (struct trident_state *)file->private_data;
1980 struct dmabuf *dmabuf = &state->dmabuf;
1981 ssize_t ret;
1982 unsigned long flags;
1983 unsigned swptr;
1984 int cnt;
1985 unsigned int state_cnt;
1986 unsigned int copy_count;
1987 int lret; /* for lock_set_fmt */
1988
1989 pr_debug("trident: trident_write called, count = %d\n", count);
1990
1991 VALIDATE_STATE(state);
1992
1993 /*
1994 * Guard against an mmap or ioctl while writing
1995 */
1996
1997 down(&state->sem);
1998
1999 if (dmabuf->mapped) {
2000 ret = -ENXIO;
2001 goto out;
2002 }
2003 if (!dmabuf->ready && (ret = prog_dmabuf_playback(state)))
2004 goto out;
2005
2006 if (!access_ok(VERIFY_READ, buffer, count)) {
2007 ret = -EFAULT;
2008 goto out;
2009 }
2010
2011 ret = 0;
2012
2013 while (count > 0) {
2014 spin_lock_irqsave(&state->card->lock, flags);
2015 if (dmabuf->count < 0) {
2016 /* buffer underrun, we are recovering from */
2017 /* sleep_on_timeout, resync hwptr and swptr */
2018 dmabuf->count = 0;
2019 dmabuf->swptr = dmabuf->hwptr;
2020 }
2021 swptr = dmabuf->swptr;
2022 cnt = dmabuf->dmasize - swptr;
2023 if (dmabuf->count + cnt > dmabuf->dmasize)
2024 cnt = dmabuf->dmasize - dmabuf->count;
2025 spin_unlock_irqrestore(&state->card->lock, flags);
2026
2027 if (cnt > count)
2028 cnt = count;
2029 if (cnt <= 0) {
2030 unsigned long tmo;
2031 /* buffer is full, start the dma machine and */
2032 /* wait for data to be played */
2033 start_dac(state);
2034 if (file->f_flags & O_NONBLOCK) {
2035 if (!ret)
2036 ret = -EAGAIN;
2037 goto out;
2038 }
2039 /* No matter how much data left in the buffer, */
2040 /* we have to wait until CSO == ESO/2 or CSO == ESO */
2041 /* when address engine interrupts */
2042 lock_set_fmt(state);
2043 tmo = (dmabuf->dmasize * HZ) / (dmabuf->rate * 2);
2044 tmo >>= sample_shift[dmabuf->fmt];
2045 unlock_set_fmt(state);
2046 up(&state->sem);
2047
2048 /* There are two situations when sleep_on_timeout */
2049 /* returns, one is when the interrupt is serviced */
2050 /* correctly and the process is waked up by ISR */
2051 /* ON TIME. Another is when timeout is expired, which */
2052 /* means that either interrupt is NOT serviced */
2053 /* correctly (pending interrupt) or it is TOO LATE */
2054 /* for the process to be scheduled to run */
2055 /* (scheduler latency) which results in a (potential) */
2056 /* buffer underrun. And worse, there is NOTHING we */
2057 /* can do to prevent it. */
2058 if (!interruptible_sleep_on_timeout(&dmabuf->wait, tmo)) {
2059 pr_debug(KERN_ERR "trident: playback schedule "
2060 "timeout, dmasz %u fragsz %u count %i "
2061 "hwptr %u swptr %u\n", dmabuf->dmasize,
2062 dmabuf->fragsize, dmabuf->count,
2063 dmabuf->hwptr, dmabuf->swptr);
2064
2065 /* a buffer underrun, we delay the recovery */
2066 /* until next time the while loop begin and */
2067 /* we REALLY have data to play */
2068 }
2069 if (signal_pending(current)) {
2070 if (!ret)
2071 ret = -ERESTARTSYS;
2072 goto out_nolock;
2073 }
2074 down(&state->sem);
2075 if (dmabuf->mapped) {
2076 if (!ret)
2077 ret = -ENXIO;
2078 goto out;
2079 }
2080 continue;
2081 }
2082 if ((lret = lock_set_fmt(state)) < 0) {
2083 ret = lret;
2084 goto out;
2085 }
2086
2087 if (state->chans_num == 6) {
2088 copy_count = 0;
2089 state_cnt = 0;
2090 if (ali_write_5_1(state, buffer, cnt, &copy_count,
2091 &state_cnt) == -EFAULT) {
2092 if (state_cnt) {
2093 swptr = (swptr + state_cnt) % dmabuf->dmasize;
2094 spin_lock_irqsave(&state->card->lock, flags);
2095 dmabuf->swptr = swptr;
2096 dmabuf->count += state_cnt;
2097 dmabuf->endcleared = 0;
2098 spin_unlock_irqrestore(&state->card->lock, flags);
2099 }
2100 ret += copy_count;
2101 if (!ret)
2102 ret = -EFAULT;
2103 unlock_set_fmt(state);
2104 goto out;
2105 }
2106 } else {
2107 if (copy_from_user(dmabuf->rawbuf + swptr,
2108 buffer, cnt)) {
2109 if (!ret)
2110 ret = -EFAULT;
2111 unlock_set_fmt(state);
2112 goto out;
2113 }
2114 state_cnt = cnt;
2115 }
2116 unlock_set_fmt(state);
2117
2118 swptr = (swptr + state_cnt) % dmabuf->dmasize;
2119
2120 spin_lock_irqsave(&state->card->lock, flags);
2121 dmabuf->swptr = swptr;
2122 dmabuf->count += state_cnt;
2123 dmabuf->endcleared = 0;
2124 spin_unlock_irqrestore(&state->card->lock, flags);
2125
2126 count -= cnt;
2127 buffer += cnt;
2128 ret += cnt;
2129 start_dac(state);
2130 }
2131out:
2132 up(&state->sem);
2133out_nolock:
2134 return ret;
2135}
2136
2137/* No kernel lock - we have our own spinlock */
2138static unsigned int
2139trident_poll(struct file *file, struct poll_table_struct *wait)
2140{
2141 struct trident_state *state = (struct trident_state *)file->private_data;
2142 struct dmabuf *dmabuf = &state->dmabuf;
2143 unsigned long flags;
2144 unsigned int mask = 0;
2145
2146 VALIDATE_STATE(state);
2147
2148 /*
2149 * Guard against a parallel poll and write causing multiple
2150 * prog_dmabuf events
2151 */
2152
2153 down(&state->sem);
2154
2155 if (file->f_mode & FMODE_WRITE) {
2156 if (!dmabuf->ready && prog_dmabuf_playback(state)) {
2157 up(&state->sem);
2158 return 0;
2159 }
2160 poll_wait(file, &dmabuf->wait, wait);
2161 }
2162 if (file->f_mode & FMODE_READ) {
2163 if (!dmabuf->ready && prog_dmabuf_record(state)) {
2164 up(&state->sem);
2165 return 0;
2166 }
2167 poll_wait(file, &dmabuf->wait, wait);
2168 }
2169
2170 up(&state->sem);
2171
2172 spin_lock_irqsave(&state->card->lock, flags);
2173 trident_update_ptr(state);
2174 if (file->f_mode & FMODE_READ) {
2175 if (dmabuf->count >= (signed) dmabuf->fragsize)
2176 mask |= POLLIN | POLLRDNORM;
2177 }
2178 if (file->f_mode & FMODE_WRITE) {
2179 if (dmabuf->mapped) {
2180 if (dmabuf->count >= (signed) dmabuf->fragsize)
2181 mask |= POLLOUT | POLLWRNORM;
2182 } else {
2183 if ((signed) dmabuf->dmasize >= dmabuf->count +
2184 (signed) dmabuf->fragsize)
2185 mask |= POLLOUT | POLLWRNORM;
2186 }
2187 }
2188 spin_unlock_irqrestore(&state->card->lock, flags);
2189
2190 return mask;
2191}
2192
2193static int
2194trident_mmap(struct file *file, struct vm_area_struct *vma)
2195{
2196 struct trident_state *state = (struct trident_state *)file->private_data;
2197 struct dmabuf *dmabuf = &state->dmabuf;
2198 int ret = -EINVAL;
2199 unsigned long size;
2200
2201 VALIDATE_STATE(state);
2202
2203 /*
2204 * Lock against poll read write or mmap creating buffers. Also lock
2205 * a read or write against an mmap.
2206 */
2207
2208 down(&state->sem);
2209
2210 if (vma->vm_flags & VM_WRITE) {
2211 if ((ret = prog_dmabuf_playback(state)) != 0)
2212 goto out;
2213 } else if (vma->vm_flags & VM_READ) {
2214 if ((ret = prog_dmabuf_record(state)) != 0)
2215 goto out;
2216 } else
2217 goto out;
2218
2219 ret = -EINVAL;
2220 if (vma->vm_pgoff != 0)
2221 goto out;
2222 size = vma->vm_end - vma->vm_start;
2223 if (size > (PAGE_SIZE << dmabuf->buforder))
2224 goto out;
2225 ret = -EAGAIN;
2226 if (remap_pfn_range(vma, vma->vm_start,
2227 virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT,
2228 size, vma->vm_page_prot))
2229 goto out;
2230 dmabuf->mapped = 1;
2231 ret = 0;
2232out:
2233 up(&state->sem);
2234 return ret;
2235}
2236
2237static int
2238trident_ioctl(struct inode *inode, struct file *file,
2239 unsigned int cmd, unsigned long arg)
2240{
2241 struct trident_state *state = (struct trident_state *)file->private_data;
2242 struct dmabuf *dmabuf = &state->dmabuf;
2243 unsigned long flags;
2244 audio_buf_info abinfo;
2245 count_info cinfo;
2246 int val, mapped, ret = 0;
2247 struct trident_card *card = state->card;
2248 void __user *argp = (void __user *)arg;
2249 int __user *p = argp;
2250
2251 VALIDATE_STATE(state);
2252
2253
2254 mapped = ((file->f_mode & (FMODE_WRITE | FMODE_READ)) && dmabuf->mapped);
2255
2256 pr_debug("trident: trident_ioctl, command = %2d, arg = 0x%08x\n",
2257 _IOC_NR(cmd), arg ? *p : 0);
2258
2259 switch (cmd) {
2260 case OSS_GETVERSION:
2261 ret = put_user(SOUND_VERSION, p);
2262 break;
2263
2264 case SNDCTL_DSP_RESET:
2265 /* FIXME: spin_lock ? */
2266 if (file->f_mode & FMODE_WRITE) {
2267 stop_dac(state);
2268 synchronize_irq(card->irq);
2269 dmabuf->ready = 0;
2270 dmabuf->swptr = dmabuf->hwptr = 0;
2271 dmabuf->count = dmabuf->total_bytes = 0;
2272 }
2273 if (file->f_mode & FMODE_READ) {
2274 stop_adc(state);
2275 synchronize_irq(card->irq);
2276 dmabuf->ready = 0;
2277 dmabuf->swptr = dmabuf->hwptr = 0;
2278 dmabuf->count = dmabuf->total_bytes = 0;
2279 }
2280 break;
2281
2282 case SNDCTL_DSP_SYNC:
2283 if (file->f_mode & FMODE_WRITE)
2284 ret = drain_dac(state, file->f_flags & O_NONBLOCK);
2285 break;
2286
2287 case SNDCTL_DSP_SPEED: /* set smaple rate */
2288 if (get_user(val, p)) {
2289 ret = -EFAULT;
2290 break;
2291 }
2292 if (val >= 0) {
2293 if (file->f_mode & FMODE_WRITE) {
2294 stop_dac(state);
2295 dmabuf->ready = 0;
2296 spin_lock_irqsave(&state->card->lock, flags);
2297 trident_set_dac_rate(state, val);
2298 spin_unlock_irqrestore(&state->card->lock, flags);
2299 }
2300 if (file->f_mode & FMODE_READ) {
2301 stop_adc(state);
2302 dmabuf->ready = 0;
2303 spin_lock_irqsave(&state->card->lock, flags);
2304 trident_set_adc_rate(state, val);
2305 spin_unlock_irqrestore(&state->card->lock, flags);
2306 }
2307 }
2308 ret = put_user(dmabuf->rate, p);
2309 break;
2310
2311 case SNDCTL_DSP_STEREO: /* set stereo or mono channel */
2312 if (get_user(val, p)) {
2313 ret = -EFAULT;
2314 break;
2315 }
2316 if ((ret = lock_set_fmt(state)) < 0)
2317 return ret;
2318
2319 if (file->f_mode & FMODE_WRITE) {
2320 stop_dac(state);
2321 dmabuf->ready = 0;
2322 if (val)
2323 dmabuf->fmt |= TRIDENT_FMT_STEREO;
2324 else
2325 dmabuf->fmt &= ~TRIDENT_FMT_STEREO;
2326 }
2327 if (file->f_mode & FMODE_READ) {
2328 stop_adc(state);
2329 dmabuf->ready = 0;
2330 if (val)
2331 dmabuf->fmt |= TRIDENT_FMT_STEREO;
2332 else
2333 dmabuf->fmt &= ~TRIDENT_FMT_STEREO;
2334 }
2335 unlock_set_fmt(state);
2336 break;
2337
2338 case SNDCTL_DSP_GETBLKSIZE:
2339 if (file->f_mode & FMODE_WRITE) {
2340 if ((val = prog_dmabuf_playback(state)))
2341 ret = val;
2342 else
2343 ret = put_user(dmabuf->fragsize, p);
2344 break;
2345 }
2346 if (file->f_mode & FMODE_READ) {
2347 if ((val = prog_dmabuf_record(state)))
2348 ret = val;
2349 else
2350 ret = put_user(dmabuf->fragsize, p);
2351 break;
2352 }
2353 /* neither READ nor WRITE? is this even possible? */
2354 ret = -EINVAL;
2355 break;
2356
2357
2358 case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format */
2359 ret = put_user(AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
2360 AFMT_U8, p);
2361 break;
2362
2363 case SNDCTL_DSP_SETFMT: /* Select sample format */
2364 if (get_user(val, p)) {
2365 ret = -EFAULT;
2366 break;
2367 }
2368 if ((ret = lock_set_fmt(state)) < 0)
2369 return ret;
2370
2371 if (val != AFMT_QUERY) {
2372 if (file->f_mode & FMODE_WRITE) {
2373 stop_dac(state);
2374 dmabuf->ready = 0;
2375 if (val == AFMT_S16_LE)
2376 dmabuf->fmt |= TRIDENT_FMT_16BIT;
2377 else
2378 dmabuf->fmt &= ~TRIDENT_FMT_16BIT;
2379 }
2380 if (file->f_mode & FMODE_READ) {
2381 stop_adc(state);
2382 dmabuf->ready = 0;
2383 if (val == AFMT_S16_LE)
2384 dmabuf->fmt |= TRIDENT_FMT_16BIT;
2385 else
2386 dmabuf->fmt &= ~TRIDENT_FMT_16BIT;
2387 }
2388 }
2389 unlock_set_fmt(state);
2390 ret = put_user((dmabuf->fmt & TRIDENT_FMT_16BIT) ? AFMT_S16_LE :
2391 AFMT_U8, p);
2392 break;
2393
2394 case SNDCTL_DSP_CHANNELS:
2395 if (get_user(val, p)) {
2396 ret = -EFAULT;
2397 break;
2398 }
2399 if (val != 0) {
2400 if ((ret = lock_set_fmt(state)) < 0)
2401 return ret;
2402
2403 if (file->f_mode & FMODE_WRITE) {
2404 stop_dac(state);
2405 dmabuf->ready = 0;
2406
2407 //prevent from memory leak
2408 if ((state->chans_num > 2) && (state->chans_num != val)) {
2409 ali_free_other_states_resources(state);
2410 state->chans_num = 1;
2411 }
2412
2413 if (val >= 2) {
2414
2415 dmabuf->fmt |= TRIDENT_FMT_STEREO;
2416 if ((val == 6) && (state->card->pci_id == PCI_DEVICE_ID_ALI_5451)) {
2417 if (card->rec_channel_use_count > 0) {
2418 printk(KERN_ERR "trident: Record is "
2419 "working on the card!\n");
2420 ret = -EBUSY;
2421 unlock_set_fmt(state);
2422 break;
2423 }
2424
2425 ret = ali_setup_multi_channels(state->card, 6);
2426 if (ret < 0) {
2427 unlock_set_fmt(state);
2428 break;
2429 }
2430 down(&state->card->open_sem);
2431 ret = ali_allocate_other_states_resources(state, 6);
2432 if (ret < 0) {
2433 up(&state->card->open_sem);
2434 unlock_set_fmt(state);
2435 break;
2436 }
2437 state->card->multi_channel_use_count++;
2438 up(&state->card->open_sem);
2439 } else
2440 val = 2; /*yield to 2-channels */
2441 } else
2442 dmabuf->fmt &= ~TRIDENT_FMT_STEREO;
2443 state->chans_num = val;
2444 }
2445 if (file->f_mode & FMODE_READ) {
2446 stop_adc(state);
2447 dmabuf->ready = 0;
2448 if (val >= 2) {
2449 if (!((file->f_mode & FMODE_WRITE) &&
2450 (val == 6)))
2451 val = 2;
2452 dmabuf->fmt |= TRIDENT_FMT_STEREO;
2453 } else
2454 dmabuf->fmt &= ~TRIDENT_FMT_STEREO;
2455 state->chans_num = val;
2456 }
2457 unlock_set_fmt(state);
2458 }
2459 ret = put_user(val, p);
2460 break;
2461
2462 case SNDCTL_DSP_POST:
2463 /* Cause the working fragment to be output */
2464 break;
2465
2466 case SNDCTL_DSP_SUBDIVIDE:
2467 if (dmabuf->subdivision) {
2468 ret = -EINVAL;
2469 break;
2470 }
2471 if (get_user(val, p)) {
2472 ret = -EFAULT;
2473 break;
2474 }
2475 if (val != 1 && val != 2 && val != 4) {
2476 ret = -EINVAL;
2477 break;
2478 }
2479 dmabuf->subdivision = val;
2480 break;
2481
2482 case SNDCTL_DSP_SETFRAGMENT:
2483 if (get_user(val, p)) {
2484 ret = -EFAULT;
2485 break;
2486 }
2487
2488 dmabuf->ossfragshift = val & 0xffff;
2489 dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
2490 if (dmabuf->ossfragshift < 4)
2491 dmabuf->ossfragshift = 4;
2492 if (dmabuf->ossfragshift > 15)
2493 dmabuf->ossfragshift = 15;
2494 if (dmabuf->ossmaxfrags < 4)
2495 dmabuf->ossmaxfrags = 4;
2496
2497 break;
2498
2499 case SNDCTL_DSP_GETOSPACE:
2500 if (!(file->f_mode & FMODE_WRITE)) {
2501 ret = -EINVAL;
2502 break;
2503 }
2504 if (!dmabuf->ready && (val = prog_dmabuf_playback(state)) != 0) {
2505 ret = val;
2506 break;
2507 }
2508 spin_lock_irqsave(&state->card->lock, flags);
2509 trident_update_ptr(state);
2510 abinfo.fragsize = dmabuf->fragsize;
2511 abinfo.bytes = dmabuf->dmasize - dmabuf->count;
2512 abinfo.fragstotal = dmabuf->numfrag;
2513 abinfo.fragments = abinfo.bytes >> dmabuf->fragshift;
2514 spin_unlock_irqrestore(&state->card->lock, flags);
2515 ret = copy_to_user(argp, &abinfo, sizeof (abinfo)) ?
2516 -EFAULT : 0;
2517 break;
2518
2519 case SNDCTL_DSP_GETISPACE:
2520 if (!(file->f_mode & FMODE_READ)) {
2521 ret = -EINVAL;
2522 break;
2523 }
2524 if (!dmabuf->ready && (val = prog_dmabuf_record(state)) != 0) {
2525 ret = val;
2526 break;
2527 }
2528 spin_lock_irqsave(&state->card->lock, flags);
2529 trident_update_ptr(state);
2530 abinfo.fragsize = dmabuf->fragsize;
2531 abinfo.bytes = dmabuf->count;
2532 abinfo.fragstotal = dmabuf->numfrag;
2533 abinfo.fragments = abinfo.bytes >> dmabuf->fragshift;
2534 spin_unlock_irqrestore(&state->card->lock, flags);
2535 ret = copy_to_user(argp, &abinfo, sizeof (abinfo)) ?
2536 -EFAULT : 0;
2537 break;
2538
2539 case SNDCTL_DSP_NONBLOCK:
2540 file->f_flags |= O_NONBLOCK;
2541 break;
2542
2543 case SNDCTL_DSP_GETCAPS:
2544 ret = put_user(DSP_CAP_REALTIME | DSP_CAP_TRIGGER |
2545 DSP_CAP_MMAP | DSP_CAP_BIND, p);
2546 break;
2547
2548 case SNDCTL_DSP_GETTRIGGER:
2549 val = 0;
2550 if ((file->f_mode & FMODE_READ) && dmabuf->enable)
2551 val |= PCM_ENABLE_INPUT;
2552 if ((file->f_mode & FMODE_WRITE) && dmabuf->enable)
2553 val |= PCM_ENABLE_OUTPUT;
2554 ret = put_user(val, p);
2555 break;
2556
2557 case SNDCTL_DSP_SETTRIGGER:
2558 if (get_user(val, p)) {
2559 ret = -EFAULT;
2560 break;
2561 }
2562 if (file->f_mode & FMODE_READ) {
2563 if (val & PCM_ENABLE_INPUT) {
2564 if (!dmabuf->ready &&
2565 (ret = prog_dmabuf_record(state)))
2566 break;
2567 start_adc(state);
2568 } else
2569 stop_adc(state);
2570 }
2571 if (file->f_mode & FMODE_WRITE) {
2572 if (val & PCM_ENABLE_OUTPUT) {
2573 if (!dmabuf->ready &&
2574 (ret = prog_dmabuf_playback(state)))
2575 break;
2576 start_dac(state);
2577 } else
2578 stop_dac(state);
2579 }
2580 break;
2581
2582 case SNDCTL_DSP_GETIPTR:
2583 if (!(file->f_mode & FMODE_READ)) {
2584 ret = -EINVAL;
2585 break;
2586 }
2587 if (!dmabuf->ready && (val = prog_dmabuf_record(state))
2588 != 0) {
2589 ret = val;
2590 break;
2591 }
2592 spin_lock_irqsave(&state->card->lock, flags);
2593 trident_update_ptr(state);
2594 cinfo.bytes = dmabuf->total_bytes;
2595 cinfo.blocks = dmabuf->count >> dmabuf->fragshift;
2596 cinfo.ptr = dmabuf->hwptr;
2597 if (dmabuf->mapped)
2598 dmabuf->count &= dmabuf->fragsize - 1;
2599 spin_unlock_irqrestore(&state->card->lock, flags);
2600 ret = copy_to_user(argp, &cinfo, sizeof (cinfo)) ?
2601 -EFAULT : 0;
2602 break;
2603
2604 case SNDCTL_DSP_GETOPTR:
2605 if (!(file->f_mode & FMODE_WRITE)) {
2606 ret = -EINVAL;
2607 break;
2608 }
2609 if (!dmabuf->ready && (val = prog_dmabuf_playback(state))
2610 != 0) {
2611 ret = val;
2612 break;
2613 }
2614
2615 spin_lock_irqsave(&state->card->lock, flags);
2616 trident_update_ptr(state);
2617 cinfo.bytes = dmabuf->total_bytes;
2618 cinfo.blocks = dmabuf->count >> dmabuf->fragshift;
2619 cinfo.ptr = dmabuf->hwptr;
2620 if (dmabuf->mapped)
2621 dmabuf->count &= dmabuf->fragsize - 1;
2622 spin_unlock_irqrestore(&state->card->lock, flags);
2623 ret = copy_to_user(argp, &cinfo, sizeof (cinfo)) ?
2624 -EFAULT : 0;
2625 break;
2626
2627 case SNDCTL_DSP_SETDUPLEX:
2628 ret = -EINVAL;
2629 break;
2630
2631 case SNDCTL_DSP_GETODELAY:
2632 if (!(file->f_mode & FMODE_WRITE)) {
2633 ret = -EINVAL;
2634 break;
2635 }
2636 if (!dmabuf->ready && (val = prog_dmabuf_playback(state)) != 0) {
2637 ret = val;
2638 break;
2639 }
2640 spin_lock_irqsave(&state->card->lock, flags);
2641 trident_update_ptr(state);
2642 val = dmabuf->count;
2643 spin_unlock_irqrestore(&state->card->lock, flags);
2644 ret = put_user(val, p);
2645 break;
2646
2647 case SOUND_PCM_READ_RATE:
2648 ret = put_user(dmabuf->rate, p);
2649 break;
2650
2651 case SOUND_PCM_READ_CHANNELS:
2652 ret = put_user((dmabuf->fmt & TRIDENT_FMT_STEREO) ? 2 : 1,
2653 p);
2654 break;
2655
2656 case SOUND_PCM_READ_BITS:
2657 ret = put_user((dmabuf->fmt & TRIDENT_FMT_16BIT) ? AFMT_S16_LE :
2658 AFMT_U8, p);
2659 break;
2660
2661 case SNDCTL_DSP_GETCHANNELMASK:
2662 ret = put_user(DSP_BIND_FRONT | DSP_BIND_SURR |
2663 DSP_BIND_CENTER_LFE, p);
2664 break;
2665
2666 case SNDCTL_DSP_BIND_CHANNEL:
2667 if (state->card->pci_id != PCI_DEVICE_ID_SI_7018) {
2668 ret = -EINVAL;
2669 break;
2670 }
2671
2672 if (get_user(val, p)) {
2673 ret = -EFAULT;
2674 break;
2675 }
2676 if (val == DSP_BIND_QUERY) {
2677 val = dmabuf->channel->attribute | 0x3c00;
2678 val = attr2mask[val >> 8];
2679 } else {
2680 dmabuf->ready = 0;
2681 if (file->f_mode & FMODE_READ)
2682 dmabuf->channel->attribute = (CHANNEL_REC |
2683 SRC_ENABLE);
2684 if (file->f_mode & FMODE_WRITE)
2685 dmabuf->channel->attribute = (CHANNEL_SPC_PB |
2686 SRC_ENABLE);
2687 dmabuf->channel->attribute |= mask2attr[ffs(val)];
2688 }
2689 ret = put_user(val, p);
2690 break;
2691
2692 case SNDCTL_DSP_MAPINBUF:
2693 case SNDCTL_DSP_MAPOUTBUF:
2694 case SNDCTL_DSP_SETSYNCRO:
2695 case SOUND_PCM_WRITE_FILTER:
2696 case SOUND_PCM_READ_FILTER:
2697 default:
2698 ret = -EINVAL;
2699 break;
2700
2701 }
2702 return ret;
2703}
2704
2705static int
2706trident_open(struct inode *inode, struct file *file)
2707{
2708 int i = 0;
2709 int minor = iminor(inode);
2710 struct trident_card *card = devs;
2711 struct trident_state *state = NULL;
2712 struct dmabuf *dmabuf = NULL;
2713
2714 /* Added by Matt Wu 01-05-2001 */
2715 /* TODO: there's some redundacy here wrt the check below */
2716 /* for multi_use_count > 0. Should we return -EBUSY or find */
2717 /* a different card? for now, don't break current behaviour */
2718 /* -- mulix */
2719 if (file->f_mode & FMODE_READ) {
2720 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
2721 if (card->multi_channel_use_count > 0)
2722 return -EBUSY;
2723 }
2724 }
2725
2726 /* find an available virtual channel (instance of /dev/dsp) */
2727 while (card != NULL) {
2728 down(&card->open_sem);
2729 if (file->f_mode & FMODE_READ) {
2730 /* Skip opens on cards that are in 6 channel mode */
2731 if (card->multi_channel_use_count > 0) {
2732 up(&card->open_sem);
2733 card = card->next;
2734 continue;
2735 }
2736 }
2737 for (i = 0; i < NR_HW_CH; i++) {
2738 if (card->states[i] == NULL) {
2739 state = card->states[i] = kmalloc(sizeof(*state), GFP_KERNEL);
2740 if (state == NULL) {
2741 up(&card->open_sem);
2742 return -ENOMEM;
2743 }
2744 memset(state, 0, sizeof(*state));
2745 init_MUTEX(&state->sem);
2746 dmabuf = &state->dmabuf;
2747 goto found_virt;
2748 }
2749 }
2750 up(&card->open_sem);
2751 card = card->next;
2752 }
2753 /* no more virtual channel avaiable */
2754 if (!state) {
2755 return -ENODEV;
2756 }
2757 found_virt:
2758 /* found a free virtual channel, allocate hardware channels */
2759 if (file->f_mode & FMODE_READ)
2760 dmabuf->channel = card->alloc_rec_pcm_channel(card);
2761 else
2762 dmabuf->channel = card->alloc_pcm_channel(card);
2763
2764 if (dmabuf->channel == NULL) {
2765 kfree(card->states[i]);
2766 card->states[i] = NULL;
2767 return -ENODEV;
2768 }
2769
2770 /* initialize the virtual channel */
2771 state->virt = i;
2772 state->card = card;
2773 state->magic = TRIDENT_STATE_MAGIC;
2774 init_waitqueue_head(&dmabuf->wait);
2775 file->private_data = state;
2776
2777 /* set default sample format. According to OSS Programmer's */
2778 /* Guide /dev/dsp should be default to unsigned 8-bits, mono, */
2779 /* with sample rate 8kHz and /dev/dspW will accept 16-bits sample */
2780 if (file->f_mode & FMODE_WRITE) {
2781 dmabuf->fmt &= ~TRIDENT_FMT_MASK;
2782 if ((minor & 0x0f) == SND_DEV_DSP16)
2783 dmabuf->fmt |= TRIDENT_FMT_16BIT;
2784 dmabuf->ossfragshift = 0;
2785 dmabuf->ossmaxfrags = 0;
2786 dmabuf->subdivision = 0;
2787 if (card->pci_id == PCI_DEVICE_ID_SI_7018) {
2788 /* set default channel attribute to normal playback */
2789 dmabuf->channel->attribute = CHANNEL_PB;
2790 }
2791 trident_set_dac_rate(state, 8000);
2792 }
2793
2794 if (file->f_mode & FMODE_READ) {
2795 /* FIXME: Trident 4d can only record in signed 16-bits stereo, */
2796 /* 48kHz sample, to be dealed with in trident_set_adc_rate() ?? */
2797 dmabuf->fmt &= ~TRIDENT_FMT_MASK;
2798 if ((minor & 0x0f) == SND_DEV_DSP16)
2799 dmabuf->fmt |= TRIDENT_FMT_16BIT;
2800 dmabuf->ossfragshift = 0;
2801 dmabuf->ossmaxfrags = 0;
2802 dmabuf->subdivision = 0;
2803 if (card->pci_id == PCI_DEVICE_ID_SI_7018) {
2804 /* set default channel attribute to 0x8a80, record from
2805 PCM L/R FIFO and mono = (left + right + 1)/2 */
2806 dmabuf->channel->attribute = (CHANNEL_REC | PCM_LR |
2807 MONO_MIX);
2808 }
2809 trident_set_adc_rate(state, 8000);
2810
2811 /* Added by Matt Wu 01-05-2001 */
2812 if (card->pci_id == PCI_DEVICE_ID_ALI_5451)
2813 card->rec_channel_use_count++;
2814 }
2815
2816 state->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2817 up(&card->open_sem);
2818
2819 pr_debug("trident: open virtual channel %d, hard channel %d\n",
2820 state->virt, dmabuf->channel->num);
2821
2822 return nonseekable_open(inode, file);
2823}
2824
2825static int
2826trident_release(struct inode *inode, struct file *file)
2827{
2828 struct trident_state *state = (struct trident_state *)file->private_data;
2829 struct trident_card *card;
2830 struct dmabuf *dmabuf;
2831
2832 VALIDATE_STATE(state);
2833
2834 card = state->card;
2835 dmabuf = &state->dmabuf;
2836
2837 if (file->f_mode & FMODE_WRITE) {
2838 trident_clear_tail(state);
2839 drain_dac(state, file->f_flags & O_NONBLOCK);
2840 }
2841
2842 pr_debug("trident: closing virtual channel %d, hard channel %d\n",
2843 state->virt, dmabuf->channel->num);
2844
2845 /* stop DMA state machine and free DMA buffers/channels */
2846 down(&card->open_sem);
2847
2848 if (file->f_mode & FMODE_WRITE) {
2849 stop_dac(state);
2850 dealloc_dmabuf(&state->dmabuf, state->card->pci_dev);
2851 state->card->free_pcm_channel(state->card, dmabuf->channel->num);
2852
2853 /* Added by Matt Wu */
2854 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
2855 if (state->chans_num > 2) {
2856 if (card->multi_channel_use_count-- < 0)
2857 card->multi_channel_use_count = 0;
2858 if (card->multi_channel_use_count == 0)
2859 ali_close_multi_channels();
2860 ali_free_other_states_resources(state);
2861 }
2862 }
2863 }
2864 if (file->f_mode & FMODE_READ) {
2865 stop_adc(state);
2866 dealloc_dmabuf(&state->dmabuf, state->card->pci_dev);
2867 state->card->free_pcm_channel(state->card, dmabuf->channel->num);
2868
2869 /* Added by Matt Wu */
2870 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
2871 if (card->rec_channel_use_count-- < 0)
2872 card->rec_channel_use_count = 0;
2873 }
2874 }
2875
2876 card->states[state->virt] = NULL;
2877 kfree(state);
2878
2879 /* we're covered by the open_sem */
2880 up(&card->open_sem);
2881
2882 return 0;
2883}
2884
2885static /*const */ struct file_operations trident_audio_fops = {
2886 .owner = THIS_MODULE,
2887 .llseek = no_llseek,
2888 .read = trident_read,
2889 .write = trident_write,
2890 .poll = trident_poll,
2891 .ioctl = trident_ioctl,
2892 .mmap = trident_mmap,
2893 .open = trident_open,
2894 .release = trident_release,
2895};
2896
2897/* trident specific AC97 functions */
2898/* Write AC97 codec registers */
2899static void
2900trident_ac97_set(struct ac97_codec *codec, u8 reg, u16 val)
2901{
2902 struct trident_card *card = (struct trident_card *)codec->private_data;
2903 unsigned int address, mask, busy;
2904 unsigned short count = 0xffff;
2905 unsigned long flags;
2906 u32 data;
2907
2908 data = ((u32) val) << 16;
2909
2910 switch (card->pci_id) {
2911 default:
2912 case PCI_DEVICE_ID_SI_7018:
2913 address = SI_AC97_WRITE;
2914 mask = SI_AC97_BUSY_WRITE | SI_AC97_AUDIO_BUSY;
2915 if (codec->id)
2916 mask |= SI_AC97_SECONDARY;
2917 busy = SI_AC97_BUSY_WRITE;
2918 break;
2919 case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX:
2920 address = DX_ACR0_AC97_W;
2921 mask = busy = DX_AC97_BUSY_WRITE;
2922 break;
2923 case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX:
2924 address = NX_ACR1_AC97_W;
2925 mask = NX_AC97_BUSY_WRITE;
2926 if (codec->id)
2927 mask |= NX_AC97_WRITE_SECONDARY;
2928 busy = NX_AC97_BUSY_WRITE;
2929 break;
2930 case PCI_DEVICE_ID_INTERG_5050:
2931 address = SI_AC97_WRITE;
2932 mask = busy = SI_AC97_BUSY_WRITE;
2933 if (codec->id)
2934 mask |= SI_AC97_SECONDARY;
2935 break;
2936 }
2937
2938 spin_lock_irqsave(&card->lock, flags);
2939 do {
2940 if ((inw(TRID_REG(card, address)) & busy) == 0)
2941 break;
2942 } while (count--);
2943
2944 data |= (mask | (reg & AC97_REG_ADDR));
2945
2946 if (count == 0) {
2947 printk(KERN_ERR "trident: AC97 CODEC write timed out.\n");
2948 spin_unlock_irqrestore(&card->lock, flags);
2949 return;
2950 }
2951
2952 outl(data, TRID_REG(card, address));
2953 spin_unlock_irqrestore(&card->lock, flags);
2954}
2955
2956/* Read AC97 codec registers */
2957static u16
2958trident_ac97_get(struct ac97_codec *codec, u8 reg)
2959{
2960 struct trident_card *card = (struct trident_card *)codec->private_data;
2961 unsigned int address, mask, busy;
2962 unsigned short count = 0xffff;
2963 unsigned long flags;
2964 u32 data;
2965
2966 switch (card->pci_id) {
2967 default:
2968 case PCI_DEVICE_ID_SI_7018:
2969 address = SI_AC97_READ;
2970 mask = SI_AC97_BUSY_READ | SI_AC97_AUDIO_BUSY;
2971 if (codec->id)
2972 mask |= SI_AC97_SECONDARY;
2973 busy = SI_AC97_BUSY_READ;
2974 break;
2975 case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX:
2976 address = DX_ACR1_AC97_R;
2977 mask = busy = DX_AC97_BUSY_READ;
2978 break;
2979 case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX:
2980 if (codec->id)
2981 address = NX_ACR3_AC97_R_SECONDARY;
2982 else
2983 address = NX_ACR2_AC97_R_PRIMARY;
2984 mask = NX_AC97_BUSY_READ;
2985 busy = NX_AC97_BUSY_READ | NX_AC97_BUSY_DATA;
2986 break;
2987 case PCI_DEVICE_ID_INTERG_5050:
2988 address = SI_AC97_READ;
2989 mask = busy = SI_AC97_BUSY_READ;
2990 if (codec->id)
2991 mask |= SI_AC97_SECONDARY;
2992 break;
2993 }
2994
2995 data = (mask | (reg & AC97_REG_ADDR));
2996
2997 spin_lock_irqsave(&card->lock, flags);
2998 outl(data, TRID_REG(card, address));
2999 do {
3000 data = inl(TRID_REG(card, address));
3001 if ((data & busy) == 0)
3002 break;
3003 } while (count--);
3004 spin_unlock_irqrestore(&card->lock, flags);
3005
3006 if (count == 0) {
3007 printk(KERN_ERR "trident: AC97 CODEC read timed out.\n");
3008 data = 0;
3009 }
3010 return ((u16) (data >> 16));
3011}
3012
3013/* rewrite ac97 read and write mixer register by hulei for ALI*/
3014static int
3015acquirecodecaccess(struct trident_card *card)
3016{
3017 u16 wsemamask = 0x6000; /* bit 14..13 */
3018 u16 wsemabits;
3019 u16 wcontrol;
3020 int block = 0;
3021 int ncount = 25;
3022 while (1) {
3023 wcontrol = inw(TRID_REG(card, ALI_AC97_WRITE));
3024 wsemabits = wcontrol & wsemamask;
3025
3026 if (wsemabits == 0x4000)
3027 return 1; /* 0x4000 is audio ,then success */
3028 if (ncount-- < 0)
3029 break;
3030 if (wsemabits == 0) {
3031 unlock:
3032 outl(((u32) (wcontrol & 0x1eff) | 0x00004000),
3033 TRID_REG(card, ALI_AC97_WRITE));
3034 continue;
3035 }
3036 udelay(20);
3037 }
3038 if (!block) {
3039 pr_debug("accesscodecsemaphore: try unlock\n");
3040 block = 1;
3041 goto unlock;
3042 }
3043 return 0;
3044}
3045
3046static void
3047releasecodecaccess(struct trident_card *card)
3048{
3049 unsigned long wcontrol;
3050 wcontrol = inl(TRID_REG(card, ALI_AC97_WRITE));
3051 outl((wcontrol & 0xffff1eff), TRID_REG(card, ALI_AC97_WRITE));
3052}
3053
3054static int
3055waitforstimertick(struct trident_card *card)
3056{
3057 unsigned long chk1, chk2;
3058 unsigned int wcount = 0xffff;
3059 chk1 = inl(TRID_REG(card, ALI_STIMER));
3060
3061 while (1) {
3062 chk2 = inl(TRID_REG(card, ALI_STIMER));
3063 if ((wcount > 0) && chk1 != chk2)
3064 return 1;
3065 if (wcount <= 0)
3066 break;
3067 udelay(50);
3068 }
3069 return 0;
3070}
3071
3072/* Read AC97 codec registers for ALi*/
3073static u16
3074ali_ac97_get(struct trident_card *card, int secondary, u8 reg)
3075{
3076 unsigned int address, mask;
3077 unsigned int ncount;
3078 unsigned long aud_reg;
3079 u32 data;
3080 u16 wcontrol;
3081 unsigned long flags;
3082
3083 if (!card)
3084 BUG();
3085
3086 address = ALI_AC97_READ;
3087 if (card->revision == ALI_5451_V02) {
3088 address = ALI_AC97_WRITE;
3089 }
3090 mask = ALI_AC97_READ_ACTION | ALI_AC97_AUDIO_BUSY;
3091 if (secondary)
3092 mask |= ALI_AC97_SECONDARY;
3093
3094 spin_lock_irqsave(&card->lock, flags);
3095
3096 if (!acquirecodecaccess(card))
3097 printk(KERN_ERR "access codec fail\n");
3098
3099 wcontrol = inw(TRID_REG(card, ALI_AC97_WRITE));
3100 wcontrol &= 0xfe00;
3101 wcontrol |= (0x8000 | reg);
3102 outw(wcontrol, TRID_REG(card, ALI_AC97_WRITE));
3103
3104 data = (mask | (reg & AC97_REG_ADDR));
3105
3106 if (!waitforstimertick(card)) {
3107 printk(KERN_ERR "ali_ac97_read: BIT_CLOCK is dead\n");
3108 goto releasecodec;
3109 }
3110
3111 udelay(20);
3112
3113 ncount = 10;
3114
3115 while (1) {
3116 if ((inw(TRID_REG(card, ALI_AC97_WRITE)) & ALI_AC97_BUSY_READ)
3117 != 0)
3118 break;
3119 if (ncount <= 0)
3120 break;
3121 if (ncount-- == 1) {
3122 pr_debug("ali_ac97_read :try clear busy flag\n");
3123 aud_reg = inl(TRID_REG(card, ALI_AC97_WRITE));
3124 outl((aud_reg & 0xffff7fff),
3125 TRID_REG(card, ALI_AC97_WRITE));
3126 }
3127 udelay(10);
3128 }
3129
3130 data = inl(TRID_REG(card, address));
3131
3132 spin_unlock_irqrestore(&card->lock, flags);
3133
3134 return ((u16) (data >> 16));
3135
3136 releasecodec:
3137 releasecodecaccess(card);
3138 spin_unlock_irqrestore(&card->lock, flags);
3139 printk(KERN_ERR "ali_ac97_read: AC97 CODEC read timed out.\n");
3140 return 0;
3141}
3142
3143/* Write AC97 codec registers for hulei*/
3144static void
3145ali_ac97_set(struct trident_card *card, int secondary, u8 reg, u16 val)
3146{
3147 unsigned int address, mask;
3148 unsigned int ncount;
3149 u32 data;
3150 u16 wcontrol;
3151 unsigned long flags;
3152
3153 data = ((u32) val) << 16;
3154
3155 if (!card)
3156 BUG();
3157
3158 address = ALI_AC97_WRITE;
3159 mask = ALI_AC97_WRITE_ACTION | ALI_AC97_AUDIO_BUSY;
3160 if (secondary)
3161 mask |= ALI_AC97_SECONDARY;
3162 if (card->revision == ALI_5451_V02)
3163 mask |= ALI_AC97_WRITE_MIXER_REGISTER;
3164
3165 spin_lock_irqsave(&card->lock, flags);
3166 if (!acquirecodecaccess(card))
3167 printk(KERN_ERR "ali_ac97_write: access codec fail\n");
3168
3169 wcontrol = inw(TRID_REG(card, ALI_AC97_WRITE));
3170 wcontrol &= 0xff00;
3171 wcontrol |= (0x8100 | reg); /* bit 8=1: (ali1535 )reserved/ */
3172 /* ali1535+ write */
3173 outl((data | wcontrol), TRID_REG(card, ALI_AC97_WRITE));
3174
3175 if (!waitforstimertick(card)) {
3176 printk(KERN_ERR "BIT_CLOCK is dead\n");
3177 goto releasecodec;
3178 }
3179
3180 ncount = 10;
3181 while (1) {
3182 wcontrol = inw(TRID_REG(card, ALI_AC97_WRITE));
3183 if (!(wcontrol & 0x8000))
3184 break;
3185 if (ncount <= 0)
3186 break;
3187 if (ncount-- == 1) {
3188 pr_debug("ali_ac97_set :try clear busy flag!!\n");
3189 outw(wcontrol & 0x7fff,
3190 TRID_REG(card, ALI_AC97_WRITE));
3191 }
3192 udelay(10);
3193 }
3194
3195 releasecodec:
3196 releasecodecaccess(card);
3197 spin_unlock_irqrestore(&card->lock, flags);
3198 return;
3199}
3200
3201static void
3202ali_enable_special_channel(struct trident_state *stat)
3203{
3204 struct trident_card *card = stat->card;
3205 unsigned long s_channels;
3206
3207 s_channels = inl(TRID_REG(card, ALI_GLOBAL_CONTROL));
3208 s_channels |= (1 << stat->dmabuf.channel->num);
3209 outl(s_channels, TRID_REG(card, ALI_GLOBAL_CONTROL));
3210}
3211
3212static u16
3213ali_ac97_read(struct ac97_codec *codec, u8 reg)
3214{
3215 int id;
3216 u16 data;
3217 struct trident_card *card = NULL;
3218
3219 /* Added by Matt Wu */
3220 if (!codec)
3221 BUG();
3222
3223 card = (struct trident_card *) codec->private_data;
3224
3225 if (!card->mixer_regs_ready)
3226 return ali_ac97_get(card, codec->id, reg);
3227
3228 /*
3229 * FIXME: need to stop this caching some registers
3230 */
3231 if (codec->id)
3232 id = 1;
3233 else
3234 id = 0;
3235
3236 data = card->mixer_regs[reg / 2][id];
3237 return data;
3238}
3239
3240static void
3241ali_ac97_write(struct ac97_codec *codec, u8 reg, u16 val)
3242{
3243 int id;
3244 struct trident_card *card;
3245
3246 /* Added by Matt Wu */
3247 if (!codec)
3248 BUG();
3249
3250 card = (struct trident_card *) codec->private_data;
3251
3252 if (!card->mixer_regs_ready) {
3253 ali_ac97_set(card, codec->id, reg, val);
3254 return;
3255 }
3256
3257 if (codec->id)
3258 id = 1;
3259 else
3260 id = 0;
3261
3262 card->mixer_regs[reg / 2][id] = val;
3263 ali_ac97_set(card, codec->id, reg, val);
3264}
3265
3266/*
3267flag: ALI_SPDIF_OUT_TO_SPDIF_OUT
3268 ALI_PCM_TO_SPDIF_OUT
3269*/
3270
3271static void
3272ali_setup_spdif_out(struct trident_card *card, int flag)
3273{
3274 unsigned long spdif;
3275 unsigned char ch;
3276
3277 char temp;
3278 struct pci_dev *pci_dev = NULL;
3279
3280 pci_dev = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
3281 pci_dev);
3282 if (pci_dev == NULL)
3283 return;
3284 pci_read_config_byte(pci_dev, 0x61, &temp);
3285 temp |= 0x40;
3286 pci_write_config_byte(pci_dev, 0x61, temp);
3287 pci_read_config_byte(pci_dev, 0x7d, &temp);
3288 temp |= 0x01;
3289 pci_write_config_byte(pci_dev, 0x7d, temp);
3290 pci_read_config_byte(pci_dev, 0x7e, &temp);
3291 temp &= (~0x20);
3292 temp |= 0x10;
3293 pci_write_config_byte(pci_dev, 0x7e, temp);
3294
3295 ch = inb(TRID_REG(card, ALI_SCTRL));
3296 outb(ch | ALI_SPDIF_OUT_ENABLE, TRID_REG(card, ALI_SCTRL));
3297 ch = inb(TRID_REG(card, ALI_SPDIF_CTRL));
3298 outb(ch & ALI_SPDIF_OUT_CH_STATUS, TRID_REG(card, ALI_SPDIF_CTRL));
3299
3300 if (flag & ALI_SPDIF_OUT_TO_SPDIF_OUT) {
3301 spdif = inw(TRID_REG(card, ALI_GLOBAL_CONTROL));
3302 spdif |= ALI_SPDIF_OUT_CH_ENABLE;
3303 spdif &= ALI_SPDIF_OUT_SEL_SPDIF;
3304 outw(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL));
3305 spdif = inw(TRID_REG(card, ALI_SPDIF_CS));
3306 if (flag & ALI_SPDIF_OUT_NON_PCM)
3307 spdif |= 0x0002;
3308 else
3309 spdif &= (~0x0002);
3310 outw(spdif, TRID_REG(card, ALI_SPDIF_CS));
3311 } else {
3312 spdif = inw(TRID_REG(card, ALI_GLOBAL_CONTROL));
3313 spdif |= ALI_SPDIF_OUT_SEL_PCM;
3314 outw(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL));
3315 }
3316}
3317
3318static void
3319ali_disable_special_channel(struct trident_card *card, int ch)
3320{
3321 unsigned long sc;
3322
3323 sc = inl(TRID_REG(card, ALI_GLOBAL_CONTROL));
3324 sc &= ~(1 << ch);
3325 outl(sc, TRID_REG(card, ALI_GLOBAL_CONTROL));
3326}
3327
3328static void
3329ali_disable_spdif_in(struct trident_card *card)
3330{
3331 unsigned long spdif;
3332
3333 spdif = inl(TRID_REG(card, ALI_GLOBAL_CONTROL));
3334 spdif &= (~ALI_SPDIF_IN_SUPPORT);
3335 outl(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL));
3336
3337 ali_disable_special_channel(card, ALI_SPDIF_IN_CHANNEL);
3338}
3339
3340static void
3341ali_setup_spdif_in(struct trident_card *card)
3342{
3343 unsigned long spdif;
3344
3345 //Set SPDIF IN Supported
3346 spdif = inl(TRID_REG(card, ALI_GLOBAL_CONTROL));
3347 spdif |= ALI_SPDIF_IN_SUPPORT;
3348 outl(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL));
3349
3350 //Set SPDIF IN Rec
3351 spdif = inl(TRID_REG(card, ALI_GLOBAL_CONTROL));
3352 spdif |= ALI_SPDIF_IN_CH_ENABLE;
3353 outl(spdif, TRID_REG(card, ALI_GLOBAL_CONTROL));
3354
3355 spdif = inb(TRID_REG(card, ALI_SPDIF_CTRL));
3356 spdif |= ALI_SPDIF_IN_CH_STATUS;
3357 outb(spdif, TRID_REG(card, ALI_SPDIF_CTRL));
3358/*
3359 spdif = inb(TRID_REG(card, ALI_SPDIF_CTRL));
3360 spdif |= ALI_SPDIF_IN_FUNC_ENABLE;
3361 outb(spdif, TRID_REG(card, ALI_SPDIF_CTRL));
3362*/
3363}
3364
3365static void
3366ali_delay(struct trident_card *card, int interval)
3367{
3368 unsigned long begintimer, currenttimer;
3369
3370 begintimer = inl(TRID_REG(card, ALI_STIMER));
3371 currenttimer = inl(TRID_REG(card, ALI_STIMER));
3372
3373 while (currenttimer < begintimer + interval)
3374 currenttimer = inl(TRID_REG(card, ALI_STIMER));
3375}
3376
3377static void
3378ali_detect_spdif_rate(struct trident_card *card)
3379{
3380 u16 wval = 0;
3381 u16 count = 0;
3382 u8 bval = 0, R1 = 0, R2 = 0;
3383
3384 bval = inb(TRID_REG(card, ALI_SPDIF_CTRL));
3385 bval |= 0x02;
3386 outb(bval, TRID_REG(card, ALI_SPDIF_CTRL));
3387
3388 bval = inb(TRID_REG(card, ALI_SPDIF_CTRL + 1));
3389 bval |= 0x1F;
3390 outb(bval, TRID_REG(card, ALI_SPDIF_CTRL + 1));
3391
3392 while (((R1 < 0x0B) || (R1 > 0x0E)) && (R1 != 0x12) &&
3393 count <= 50000) {
3394 count++;
3395
3396 ali_delay(card, 6);
3397
3398 bval = inb(TRID_REG(card, ALI_SPDIF_CTRL + 1));
3399 R1 = bval & 0x1F;
3400 }
3401
3402 if (count > 50000) {
3403 printk(KERN_WARNING "trident: Error in "
3404 "ali_detect_spdif_rate!\n");
3405 return;
3406 }
3407
3408 count = 0;
3409
3410 while (count <= 50000) {
3411 count++;
3412
3413 ali_delay(card, 6);
3414
3415 bval = inb(TRID_REG(card, ALI_SPDIF_CTRL + 1));
3416 R2 = bval & 0x1F;
3417
3418 if (R2 != R1)
3419 R1 = R2;
3420 else
3421 break;
3422 }
3423
3424 if (count > 50000) {
3425 printk(KERN_WARNING "trident: Error in "
3426 "ali_detect_spdif_rate!\n");
3427 return;
3428 }
3429
3430 switch (R2) {
3431 case 0x0b:
3432 case 0x0c:
3433 case 0x0d:
3434 case 0x0e:
3435 wval = inw(TRID_REG(card, ALI_SPDIF_CTRL + 2));
3436 wval &= 0xE0F0;
3437 wval |= (u16) 0x09 << 8 | (u16) 0x05;
3438 outw(wval, TRID_REG(card, ALI_SPDIF_CTRL + 2));
3439
3440 bval = inb(TRID_REG(card, ALI_SPDIF_CS + 3)) & 0xF0;
3441 outb(bval | 0x02, TRID_REG(card, ALI_SPDIF_CS + 3));
3442 break;
3443
3444 case 0x12:
3445 wval = inw(TRID_REG(card, ALI_SPDIF_CTRL + 2));
3446 wval &= 0xE0F0;
3447 wval |= (u16) 0x0E << 8 | (u16) 0x08;
3448 outw(wval, TRID_REG(card, ALI_SPDIF_CTRL + 2));
3449
3450 bval = inb(TRID_REG(card, ALI_SPDIF_CS + 3)) & 0xF0;
3451 outb(bval | 0x03, TRID_REG(card, ALI_SPDIF_CS + 3));
3452 break;
3453
3454 default:
3455 break;
3456 }
3457
3458}
3459
3460static unsigned int
3461ali_get_spdif_in_rate(struct trident_card *card)
3462{
3463 u32 dwRate = 0;
3464 u8 bval = 0;
3465
3466 ali_detect_spdif_rate(card);
3467
3468 bval = inb(TRID_REG(card, ALI_SPDIF_CTRL));
3469 bval &= 0x7F;
3470 bval |= 0x40;
3471 outb(bval, TRID_REG(card, ALI_SPDIF_CTRL));
3472
3473 bval = inb(TRID_REG(card, ALI_SPDIF_CS + 3));
3474 bval &= 0x0F;
3475
3476 switch (bval) {
3477 case 0:
3478 dwRate = 44100;
3479 break;
3480 case 1:
3481 dwRate = 48000;
3482 break;
3483 case 2:
3484 dwRate = 32000;
3485 break;
3486 default:
3487 // Error occurs
3488 break;
3489 }
3490
3491 return dwRate;
3492
3493}
3494
3495static int
3496ali_close_multi_channels(void)
3497{
3498 char temp = 0;
3499 struct pci_dev *pci_dev = NULL;
3500
3501 pci_dev = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
3502 pci_dev);
3503 if (pci_dev == NULL)
3504 return -1;
3505 pci_read_config_byte(pci_dev, 0x59, &temp);
3506 temp &= ~0x80;
3507 pci_write_config_byte(pci_dev, 0x59, temp);
3508
3509 pci_dev = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,
3510 pci_dev);
3511 if (pci_dev == NULL)
3512 return -1;
3513
3514 pci_read_config_byte(pci_dev, 0xB8, &temp);
3515 temp &= ~0x20;
3516 pci_write_config_byte(pci_dev, 0xB8, temp);
3517
3518 return 0;
3519}
3520
3521static int
3522ali_setup_multi_channels(struct trident_card *card, int chan_nums)
3523{
3524 unsigned long dwValue;
3525 char temp = 0;
3526 struct pci_dev *pci_dev = NULL;
3527
3528 pci_dev = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
3529 pci_dev);
3530 if (pci_dev == NULL)
3531 return -1;
3532 pci_read_config_byte(pci_dev, 0x59, &temp);
3533 temp |= 0x80;
3534 pci_write_config_byte(pci_dev, 0x59, temp);
3535
3536 pci_dev = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,
3537 pci_dev);
3538 if (pci_dev == NULL)
3539 return -1;
3540 pci_read_config_byte(pci_dev, (int) 0xB8, &temp);
3541 temp |= 0x20;
3542 pci_write_config_byte(pci_dev, (int) 0xB8, (u8) temp);
3543 if (chan_nums == 6) {
3544 dwValue = inl(TRID_REG(card, ALI_SCTRL)) | 0x000f0000;
3545 outl(dwValue, TRID_REG(card, ALI_SCTRL));
3546 mdelay(4);
3547 dwValue = inl(TRID_REG(card, ALI_SCTRL));
3548 if (dwValue & 0x2000000) {
3549 ali_ac97_write(card->ac97_codec[0], 0x02, 8080);
3550 ali_ac97_write(card->ac97_codec[0], 0x36, 0);
3551 ali_ac97_write(card->ac97_codec[0], 0x38, 0);
3552 /*
3553 * On a board with a single codec you won't get the
3554 * surround. On other boards configure it.
3555 */
3556 if (card->ac97_codec[1] != NULL) {
3557 ali_ac97_write(card->ac97_codec[1], 0x36, 0);
3558 ali_ac97_write(card->ac97_codec[1], 0x38, 0);
3559 ali_ac97_write(card->ac97_codec[1], 0x02, 0x0606);
3560 ali_ac97_write(card->ac97_codec[1], 0x18, 0x0303);
3561 ali_ac97_write(card->ac97_codec[1], 0x74, 0x3);
3562 }
3563 return 1;
3564 }
3565 }
3566 return -EINVAL;
3567}
3568
3569static void
3570ali_free_pcm_channel(struct trident_card *card, unsigned int channel)
3571{
3572 int bank;
3573
3574 if (channel > 31)
3575 return;
3576
3577 bank = channel >> 5;
3578 channel = channel & 0x1f;
3579
3580 card->banks[bank].bitmap &= ~(1 << (channel));
3581}
3582
3583static int
3584ali_allocate_other_states_resources(struct trident_state *state, int chan_nums)
3585{
3586 struct trident_card *card = state->card;
3587 struct trident_state *s;
3588 int i, state_count = 0;
3589 struct trident_pcm_bank *bank;
3590 struct trident_channel *channel;
3591 unsigned long num;
3592
3593 bank = &card->banks[BANK_A];
3594
3595 if (chan_nums != 6)
3596 return 0;
3597
3598 for (i = 0; (i < ALI_CHANNELS) && (state_count != 4); i++) {
3599 if (card->states[i])
3600 continue;
3601
3602 num = ali_multi_channels_5_1[state_count];
3603 if (!(bank->bitmap & (1 << num))) {
3604 bank->bitmap |= 1 << num;
3605 channel = &bank->channels[num];
3606 channel->num = num;
3607 } else {
3608 state_count--;
3609 for (; state_count >= 0; state_count--) {
3610 kfree(state->other_states[state_count]);
3611 num = ali_multi_channels_5_1[state_count];
3612 ali_free_pcm_channel(card, num);
3613 }
3614 return -EBUSY;
3615 }
3616 s = card->states[i] = kmalloc(sizeof(*state), GFP_KERNEL);
3617 if (!s) {
3618 num = ali_multi_channels_5_1[state_count];
3619 ali_free_pcm_channel(card, num);
3620 state_count--;
3621 for (; state_count >= 0; state_count--) {
3622 num = ali_multi_channels_5_1[state_count];
3623 ali_free_pcm_channel(card, num);
3624 kfree(state->other_states[state_count]);
3625 }
3626 return -ENOMEM;
3627 }
3628 memset(s, 0, sizeof(*state));
3629
3630 s->dmabuf.channel = channel;
3631 s->dmabuf.ossfragshift = s->dmabuf.ossmaxfrags =
3632 s->dmabuf.subdivision = 0;
3633 init_waitqueue_head(&s->dmabuf.wait);
3634 s->magic = card->magic;
3635 s->card = card;
3636 s->virt = i;
3637 ali_enable_special_channel(s);
3638 state->other_states[state_count++] = s;
3639 }
3640
3641 if (state_count != 4) {
3642 state_count--;
3643 for (; state_count >= 0; state_count--) {
3644 kfree(state->other_states[state_count]);
3645 num = ali_multi_channels_5_1[state_count];
3646 ali_free_pcm_channel(card, num);
3647 }
3648 return -EBUSY;
3649 }
3650 return 0;
3651}
3652
3653static void
3654ali_save_regs(struct trident_card *card)
3655{
3656 unsigned long flags;
3657 int i, j;
3658
3659 spin_lock_irqsave(&card->lock, flags);
3660
3661 ali_registers.global_regs[0x2c] = inl(TRID_REG(card, T4D_MISCINT));
3662 //ali_registers.global_regs[0x20] = inl(TRID_REG(card,T4D_START_A));
3663 ali_registers.global_regs[0x21] = inl(TRID_REG(card, T4D_STOP_A));
3664
3665 //disable all IRQ bits
3666 outl(ALI_DISABLE_ALL_IRQ, TRID_REG(card, T4D_MISCINT));
3667
3668 for (i = 1; i < ALI_MIXER_REGS; i++)
3669 ali_registers.mixer_regs[i] = ali_ac97_read(card->ac97_codec[0],
3670 i * 2);
3671
3672 for (i = 0; i < ALI_GLOBAL_REGS; i++) {
3673 if ((i * 4 == T4D_MISCINT) || (i * 4 == T4D_STOP_A))
3674 continue;
3675 ali_registers.global_regs[i] = inl(TRID_REG(card, i * 4));
3676 }
3677
3678 for (i = 0; i < ALI_CHANNELS; i++) {
3679 outb(i, TRID_REG(card, T4D_LFO_GC_CIR));
3680 for (j = 0; j < ALI_CHANNEL_REGS; j++)
3681 ali_registers.channel_regs[i][j] = inl(TRID_REG(card,
3682 j * 4 + 0xe0));
3683 }
3684
3685 //Stop all HW channel
3686 outl(ALI_STOP_ALL_CHANNELS, TRID_REG(card, T4D_STOP_A));
3687
3688 spin_unlock_irqrestore(&card->lock, flags);
3689}
3690
3691static void
3692ali_restore_regs(struct trident_card *card)
3693{
3694 unsigned long flags;
3695 int i, j;
3696
3697 spin_lock_irqsave(&card->lock, flags);
3698
3699 for (i = 1; i < ALI_MIXER_REGS; i++)
3700 ali_ac97_write(card->ac97_codec[0], i * 2,
3701 ali_registers.mixer_regs[i]);
3702
3703 for (i = 0; i < ALI_CHANNELS; i++) {
3704 outb(i, TRID_REG(card, T4D_LFO_GC_CIR));
3705 for (j = 0; j < ALI_CHANNEL_REGS; j++)
3706 outl(ali_registers.channel_regs[i][j],
3707 TRID_REG(card, j * 4 + 0xe0));
3708 }
3709
3710 for (i = 0; i < ALI_GLOBAL_REGS; i++) {
3711 if ((i * 4 == T4D_MISCINT) || (i * 4 == T4D_STOP_A) ||
3712 (i * 4 == T4D_START_A))
3713 continue;
3714 outl(ali_registers.global_regs[i], TRID_REG(card, i * 4));
3715 }
3716
3717 //start HW channel
3718 outl(ali_registers.global_regs[0x20], TRID_REG(card, T4D_START_A));
3719 //restore IRQ enable bits
3720 outl(ali_registers.global_regs[0x2c], TRID_REG(card, T4D_MISCINT));
3721
3722 spin_unlock_irqrestore(&card->lock, flags);
3723}
3724
3725static int
3726trident_suspend(struct pci_dev *dev, pm_message_t unused)
3727{
3728 struct trident_card *card = pci_get_drvdata(dev);
3729
3730 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
3731 ali_save_regs(card);
3732 }
3733 return 0;
3734}
3735
3736static int
3737trident_resume(struct pci_dev *dev)
3738{
3739 struct trident_card *card = pci_get_drvdata(dev);
3740
3741 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
3742 ali_restore_regs(card);
3743 }
3744 return 0;
3745}
3746
3747static struct trident_channel *
3748ali_alloc_pcm_channel(struct trident_card *card)
3749{
3750 struct trident_pcm_bank *bank;
3751 int idx;
3752
3753 bank = &card->banks[BANK_A];
3754
3755 if (inl(TRID_REG(card, ALI_GLOBAL_CONTROL)) &
3756 (ALI_SPDIF_OUT_CH_ENABLE)) {
3757 idx = ALI_SPDIF_OUT_CHANNEL;
3758 if (!(bank->bitmap & (1 << idx))) {
3759 struct trident_channel *channel = &bank->channels[idx];
3760 bank->bitmap |= 1 << idx;
3761 channel->num = idx;
3762 return channel;
3763 }
3764 }
3765
3766 for (idx = ALI_PCM_OUT_CHANNEL_FIRST; idx <= ALI_PCM_OUT_CHANNEL_LAST;
3767 idx++) {
3768 if (!(bank->bitmap & (1 << idx))) {
3769 struct trident_channel *channel = &bank->channels[idx];
3770 bank->bitmap |= 1 << idx;
3771 channel->num = idx;
3772 return channel;
3773 }
3774 }
3775
3776 /* no more free channels avaliable */
3777#if 0
3778 printk(KERN_ERR "ali: no more channels available on Bank A.\n");
3779#endif /* 0 */
3780 return NULL;
3781}
3782
3783static struct trident_channel *
3784ali_alloc_rec_pcm_channel(struct trident_card *card)
3785{
3786 struct trident_pcm_bank *bank;
3787 int idx;
3788
3789 if (inl(TRID_REG(card, ALI_GLOBAL_CONTROL)) & ALI_SPDIF_IN_SUPPORT)
3790 idx = ALI_SPDIF_IN_CHANNEL;
3791 else
3792 idx = ALI_PCM_IN_CHANNEL;
3793
3794 bank = &card->banks[BANK_A];
3795
3796 if (!(bank->bitmap & (1 << idx))) {
3797 struct trident_channel *channel = &bank->channels[idx];
3798 bank->bitmap |= 1 << idx;
3799 channel->num = idx;
3800 return channel;
3801 }
3802
3803 /* no free recordable channels avaliable */
3804#if 0
3805 printk(KERN_ERR "ali: no recordable channels available on Bank A.\n");
3806#endif /* 0 */
3807 return NULL;
3808}
3809
3810static void
3811ali_set_spdif_out_rate(struct trident_card *card, unsigned int rate)
3812{
3813 unsigned char ch_st_sel;
3814 unsigned short status_rate;
3815
3816 switch (rate) {
3817 case 44100:
3818 status_rate = 0;
3819 break;
3820 case 32000:
3821 status_rate = 0x300;
3822 break;
3823 case 48000:
3824 default:
3825 status_rate = 0x200;
3826 break;
3827 }
3828
3829 /* select spdif_out */
3830 ch_st_sel = inb(TRID_REG(card, ALI_SPDIF_CTRL)) & ALI_SPDIF_OUT_CH_STATUS;
3831
3832 ch_st_sel |= 0x80; /* select right */
3833 outb(ch_st_sel, TRID_REG(card, ALI_SPDIF_CTRL));
3834 outb(status_rate | 0x20, TRID_REG(card, ALI_SPDIF_CS + 2));
3835
3836 ch_st_sel &= (~0x80); /* select left */
3837 outb(ch_st_sel, TRID_REG(card, ALI_SPDIF_CTRL));
3838 outw(status_rate | 0x10, TRID_REG(card, ALI_SPDIF_CS + 2));
3839}
3840
3841static void
3842ali_address_interrupt(struct trident_card *card)
3843{
3844 int i, channel;
3845 struct trident_state *state;
3846 u32 mask, channel_mask;
3847
3848 mask = trident_get_interrupt_mask(card, 0);
3849 for (i = 0; i < NR_HW_CH; i++) {
3850 if ((state = card->states[i]) == NULL)
3851 continue;
3852 channel = state->dmabuf.channel->num;
3853 if ((channel_mask = 1 << channel) & mask) {
3854 mask &= ~channel_mask;
3855 trident_ack_channel_interrupt(card, channel);
3856 udelay(100);
3857 state->dmabuf.update_flag |= ALI_ADDRESS_INT_UPDATE;
3858 trident_update_ptr(state);
3859 }
3860 }
3861 if (mask) {
3862 for (i = 0; i < NR_HW_CH; i++) {
3863 if (mask & (1 << i)) {
3864 printk("ali: spurious channel irq %d.\n", i);
3865 trident_ack_channel_interrupt(card, i);
3866 trident_stop_voice(card, i);
3867 trident_disable_voice_irq(card, i);
3868 }
3869 }
3870 }
3871}
3872
3873/* Updating the values of counters of other_states' DMAs without lock
3874protection is no harm because all DMAs of multi-channels and interrupt
3875depend on a master state's DMA, and changing the counters of the master
3876state DMA is protected by a spinlock.
3877*/
3878static int
3879ali_write_5_1(struct trident_state *state, const char __user *buf,
3880 int cnt_for_multi_channel, unsigned int *copy_count,
3881 unsigned int *state_cnt)
3882{
3883
3884 struct dmabuf *dmabuf = &state->dmabuf;
3885 struct dmabuf *dmabuf_temp;
3886 const char __user *buffer = buf;
3887 unsigned swptr, other_dma_nums, sample_s;
3888 unsigned int i, loop;
3889
3890 other_dma_nums = 4;
3891 sample_s = sample_size[dmabuf->fmt] >> 1;
3892 swptr = dmabuf->swptr;
3893
3894 if ((i = state->multi_channels_adjust_count) > 0) {
3895 if (i == 1) {
3896 if (copy_from_user(dmabuf->rawbuf + swptr,
3897 buffer, sample_s))
3898 return -EFAULT;
3899 seek_offset(swptr, buffer, cnt_for_multi_channel,
3900 sample_s, *copy_count);
3901 i--;
3902 (*state_cnt) += sample_s;
3903 state->multi_channels_adjust_count++;
3904 } else
3905 i = i - (state->chans_num - other_dma_nums);
3906 for (; (i < other_dma_nums) && (cnt_for_multi_channel > 0); i++) {
3907 dmabuf_temp = &state->other_states[i]->dmabuf;
3908 if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr,
3909 buffer, sample_s))
3910 return -EFAULT;
3911 seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel,
3912 sample_s, *copy_count);
3913 }
3914 if (cnt_for_multi_channel == 0)
3915 state->multi_channels_adjust_count += i;
3916 }
3917 if (cnt_for_multi_channel > 0) {
3918 loop = cnt_for_multi_channel / (state->chans_num * sample_s);
3919 for (i = 0; i < loop; i++) {
3920 if (copy_from_user(dmabuf->rawbuf + swptr, buffer,
3921 sample_s * 2))
3922 return -EFAULT;
3923 seek_offset(swptr, buffer, cnt_for_multi_channel,
3924 sample_s * 2, *copy_count);
3925 (*state_cnt) += (sample_s * 2);
3926
3927 dmabuf_temp = &state->other_states[0]->dmabuf;
3928 if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr,
3929 buffer, sample_s))
3930 return -EFAULT;
3931 seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel,
3932 sample_s, *copy_count);
3933
3934 dmabuf_temp = &state->other_states[1]->dmabuf;
3935 if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr,
3936 buffer, sample_s))
3937 return -EFAULT;
3938 seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel,
3939 sample_s, *copy_count);
3940
3941 dmabuf_temp = &state->other_states[2]->dmabuf;
3942 if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr,
3943 buffer, sample_s))
3944 return -EFAULT;
3945 seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel,
3946 sample_s, *copy_count);
3947
3948 dmabuf_temp = &state->other_states[3]->dmabuf;
3949 if (copy_from_user(dmabuf_temp->rawbuf + dmabuf_temp->swptr,
3950 buffer, sample_s))
3951 return -EFAULT;
3952 seek_offset(dmabuf_temp->swptr, buffer, cnt_for_multi_channel,
3953 sample_s, *copy_count);
3954 }
3955
3956 if (cnt_for_multi_channel > 0) {
3957 state->multi_channels_adjust_count = cnt_for_multi_channel / sample_s;
3958
3959 if (copy_from_user(dmabuf->rawbuf + swptr, buffer, sample_s))
3960 return -EFAULT;
3961 seek_offset(swptr, buffer, cnt_for_multi_channel,
3962 sample_s, *copy_count);
3963 (*state_cnt) += sample_s;
3964
3965 if (cnt_for_multi_channel > 0) {
3966 if (copy_from_user(dmabuf->rawbuf + swptr,
3967 buffer, sample_s))
3968 return -EFAULT;
3969 seek_offset(swptr, buffer, cnt_for_multi_channel,
3970 sample_s, *copy_count);
3971 (*state_cnt) += sample_s;
3972
3973 if (cnt_for_multi_channel > 0) {
3974 int diff = state->chans_num - other_dma_nums;
3975 loop = state->multi_channels_adjust_count - diff;
3976 for (i = 0; i < loop; i++) {
3977 dmabuf_temp = &state->other_states[i]->dmabuf;
3978 if (copy_from_user(dmabuf_temp->rawbuf +
3979 dmabuf_temp->swptr,
3980 buffer, sample_s))
3981 return -EFAULT;
3982 seek_offset(dmabuf_temp->swptr, buffer,
3983 cnt_for_multi_channel,
3984 sample_s, *copy_count);
3985 }
3986 }
3987 }
3988 } else
3989 state->multi_channels_adjust_count = 0;
3990 }
3991 for (i = 0; i < other_dma_nums; i++) {
3992 dmabuf_temp = &state->other_states[i]->dmabuf;
3993 dmabuf_temp->swptr = dmabuf_temp->swptr % dmabuf_temp->dmasize;
3994 }
3995 return *state_cnt;
3996}
3997
3998static void
3999ali_free_other_states_resources(struct trident_state *state)
4000{
4001 int i;
4002 struct trident_card *card = state->card;
4003 struct trident_state *s;
4004 unsigned other_states_count;
4005
4006 other_states_count = state->chans_num - 2; /* except PCM L/R channels */
4007 for (i = 0; i < other_states_count; i++) {
4008 s = state->other_states[i];
4009 dealloc_dmabuf(&s->dmabuf, card->pci_dev);
4010 ali_disable_special_channel(s->card, s->dmabuf.channel->num);
4011 state->card->free_pcm_channel(s->card, s->dmabuf.channel->num);
4012 card->states[s->virt] = NULL;
4013 kfree(s);
4014 }
4015}
4016
4017static struct proc_dir_entry *res;
4018
4019static int
4020ali_write_proc(struct file *file, const char __user *buffer, unsigned long count, void *data)
4021{
4022 struct trident_card *card = (struct trident_card *) data;
4023 unsigned long flags;
4024 char c;
4025
4026 if (count < 0)
4027 return -EINVAL;
4028 if (count == 0)
4029 return 0;
4030 if (get_user(c, buffer))
4031 return -EFAULT;
4032
4033 spin_lock_irqsave(&card->lock, flags);
4034 switch (c) {
4035 case '0':
4036 ali_setup_spdif_out(card, ALI_PCM_TO_SPDIF_OUT);
4037 ali_disable_special_channel(card, ALI_SPDIF_OUT_CHANNEL);
4038 break;
4039 case '1':
4040 ali_setup_spdif_out(card, ALI_SPDIF_OUT_TO_SPDIF_OUT |
4041 ALI_SPDIF_OUT_PCM);
4042 break;
4043 case '2':
4044 ali_setup_spdif_out(card, ALI_SPDIF_OUT_TO_SPDIF_OUT |
4045 ALI_SPDIF_OUT_NON_PCM);
4046 break;
4047 case '3':
4048 ali_disable_spdif_in(card); //default
4049 break;
4050 case '4':
4051 ali_setup_spdif_in(card);
4052 break;
4053 }
4054 spin_unlock_irqrestore(&card->lock, flags);
4055
4056 return count;
4057}
4058
4059/* OSS /dev/mixer file operation methods */
4060static int
4061trident_open_mixdev(struct inode *inode, struct file *file)
4062{
4063 int i = 0;
4064 int minor = iminor(inode);
4065 struct trident_card *card = devs;
4066
4067 for (card = devs; card != NULL; card = card->next)
4068 for (i = 0; i < NR_AC97; i++)
4069 if (card->ac97_codec[i] != NULL &&
4070 card->ac97_codec[i]->dev_mixer == minor)
4071 goto match;
4072
4073 if (!card) {
4074 return -ENODEV;
4075 }
4076 match:
4077 file->private_data = card->ac97_codec[i];
4078
4079 return nonseekable_open(inode, file);
4080}
4081
4082static int
4083trident_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
4084 unsigned long arg)
4085{
4086 struct ac97_codec *codec = (struct ac97_codec *) file->private_data;
4087
4088 return codec->mixer_ioctl(codec, cmd, arg);
4089}
4090
4091static /*const */ struct file_operations trident_mixer_fops = {
4092 .owner = THIS_MODULE,
4093 .llseek = no_llseek,
4094 .ioctl = trident_ioctl_mixdev,
4095 .open = trident_open_mixdev,
4096};
4097
4098static int
4099ali_reset_5451(struct trident_card *card)
4100{
4101 struct pci_dev *pci_dev = NULL;
4102 unsigned int dwVal;
4103 unsigned short wCount, wReg;
4104
4105 pci_dev = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533,
4106 pci_dev);
4107 if (pci_dev == NULL)
4108 return -1;
4109
4110 pci_read_config_dword(pci_dev, 0x7c, &dwVal);
4111 pci_write_config_dword(pci_dev, 0x7c, dwVal | 0x08000000);
4112 udelay(5000);
4113 pci_read_config_dword(pci_dev, 0x7c, &dwVal);
4114 pci_write_config_dword(pci_dev, 0x7c, dwVal & 0xf7ffffff);
4115 udelay(5000);
4116
4117 pci_dev = card->pci_dev;
4118 if (pci_dev == NULL)
4119 return -1;
4120
4121 pci_read_config_dword(pci_dev, 0x44, &dwVal);
4122 pci_write_config_dword(pci_dev, 0x44, dwVal | 0x000c0000);
4123 udelay(500);
4124 pci_read_config_dword(pci_dev, 0x44, &dwVal);
4125 pci_write_config_dword(pci_dev, 0x44, dwVal & 0xfffbffff);
4126 udelay(5000);
4127
4128 /* TODO: recognize if we have a PM capable codec and only do this */
4129 /* if the codec is PM capable */
4130 wCount = 2000;
4131 while (wCount--) {
4132 wReg = ali_ac97_get(card, 0, AC97_POWER_CONTROL);
4133 if ((wReg & 0x000f) == 0x000f)
4134 return 0;
4135 udelay(5000);
4136 }
4137 /* This is non fatal if you have a non PM capable codec.. */
4138 return 0;
4139}
4140
4141/* AC97 codec initialisation. */
4142static int __devinit
4143trident_ac97_init(struct trident_card *card)
4144{
4145 int num_ac97 = 0;
4146 unsigned long ready_2nd = 0;
4147 struct ac97_codec *codec;
4148 int i = 0;
4149
4150 /* initialize controller side of AC link, and find out if secondary codes
4151 really exist */
4152 switch (card->pci_id) {
4153 case PCI_DEVICE_ID_ALI_5451:
4154 if (ali_reset_5451(card)) {
4155 printk(KERN_ERR "trident_ac97_init: error "
4156 "resetting 5451.\n");
4157 return -1;
4158 }
4159 outl(0x80000001, TRID_REG(card, ALI_GLOBAL_CONTROL));
4160 outl(0x00000000, TRID_REG(card, T4D_AINTEN_A));
4161 outl(0xffffffff, TRID_REG(card, T4D_AINT_A));
4162 outl(0x00000000, TRID_REG(card, T4D_MUSICVOL_WAVEVOL));
4163 outb(0x10, TRID_REG(card, ALI_MPUR2));
4164 ready_2nd = inl(TRID_REG(card, ALI_SCTRL));
4165 ready_2nd &= 0x3fff;
4166 outl(ready_2nd | PCMOUT | 0x8000, TRID_REG(card, ALI_SCTRL));
4167 ready_2nd = inl(TRID_REG(card, ALI_SCTRL));
4168 ready_2nd &= SI_AC97_SECONDARY_READY;
4169 if (card->revision < ALI_5451_V02)
4170 ready_2nd = 0;
4171 break;
4172 case PCI_DEVICE_ID_SI_7018:
4173 /* disable AC97 GPIO interrupt */
4174 outl(0x00, TRID_REG(card, SI_AC97_GPIO));
4175 /* when power up the AC link is in cold reset mode so stop it */
4176 outl(PCMOUT | SURROUT | CENTEROUT | LFEOUT | SECONDARY_ID,
4177 TRID_REG(card, SI_SERIAL_INTF_CTRL));
4178 /* it take a long time to recover from a cold reset */
4179 /* (especially when you have more than one codec) */
4180 udelay(2000);
4181 ready_2nd = inl(TRID_REG(card, SI_SERIAL_INTF_CTRL));
4182 ready_2nd &= SI_AC97_SECONDARY_READY;
4183 break;
4184 case PCI_DEVICE_ID_TRIDENT_4DWAVE_DX:
4185 /* playback on */
4186 outl(DX_AC97_PLAYBACK, TRID_REG(card, DX_ACR2_AC97_COM_STAT));
4187 break;
4188 case PCI_DEVICE_ID_TRIDENT_4DWAVE_NX:
4189 /* enable AC97 Output Slot 3,4 (PCM Left/Right Playback) */
4190 outl(NX_AC97_PCM_OUTPUT, TRID_REG(card, NX_ACR0_AC97_COM_STAT));
4191 ready_2nd = inl(TRID_REG(card, NX_ACR0_AC97_COM_STAT));
4192 ready_2nd &= NX_AC97_SECONDARY_READY;
4193 break;
4194 case PCI_DEVICE_ID_INTERG_5050:
4195 /* disable AC97 GPIO interrupt */
4196 outl(0x00, TRID_REG(card, SI_AC97_GPIO));
4197 /* when power up, the AC link is in cold reset mode, so stop it */
4198 outl(PCMOUT | SURROUT | CENTEROUT | LFEOUT,
4199 TRID_REG(card, SI_SERIAL_INTF_CTRL));
4200 /* it take a long time to recover from a cold reset (especially */
4201 /* when you have more than one codec) */
4202 udelay(2000);
4203 ready_2nd = inl(TRID_REG(card, SI_SERIAL_INTF_CTRL));
4204 ready_2nd &= SI_AC97_SECONDARY_READY;
4205 break;
4206 }
4207
4208 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
4209 if ((codec = ac97_alloc_codec()) == NULL)
4210 return -ENOMEM;
4211
4212 /* initialize some basic codec information, other fields */
4213 /* will be filled in ac97_probe_codec */
4214 codec->private_data = card;
4215 codec->id = num_ac97;
4216
4217 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
4218 codec->codec_read = ali_ac97_read;
4219 codec->codec_write = ali_ac97_write;
4220 } else {
4221 codec->codec_read = trident_ac97_get;
4222 codec->codec_write = trident_ac97_set;
4223 }
4224
4225 if (ac97_probe_codec(codec) == 0)
4226 break;
4227
4228 codec->dev_mixer = register_sound_mixer(&trident_mixer_fops, -1);
4229 if (codec->dev_mixer < 0) {
4230 printk(KERN_ERR "trident: couldn't register mixer!\n");
4231 ac97_release_codec(codec);
4232 break;
4233 }
4234
4235 card->ac97_codec[num_ac97] = codec;
4236
4237 /* if there is no secondary codec at all, don't probe any more */
4238 if (!ready_2nd)
4239 break;
4240 }
4241
4242 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
4243 for (num_ac97 = 0; num_ac97 < NR_AC97; num_ac97++) {
4244 if (card->ac97_codec[num_ac97] == NULL)
4245 break;
4246 for (i = 0; i < 64; i++) {
4247 u16 reg = ali_ac97_get(card, num_ac97, i * 2);
4248 card->mixer_regs[i][num_ac97] = reg;
4249 }
4250 }
4251 }
4252 return num_ac97 + 1;
4253}
4254
4255/* Gameport functions for the cards ADC gameport */
4256
4257static unsigned char
4258trident_game_read(struct gameport *gameport)
4259{
4260 struct trident_card *card = gameport->port_data;
4261 return inb(TRID_REG(card, T4D_GAME_LEG));
4262}
4263
4264static void
4265trident_game_trigger(struct gameport *gameport)
4266{
4267 struct trident_card *card = gameport->port_data;
4268 outb(0xff, TRID_REG(card, T4D_GAME_LEG));
4269}
4270
4271static int
4272trident_game_cooked_read(struct gameport *gameport, int *axes, int *buttons)
4273{
4274 struct trident_card *card = gameport->port_data;
4275 int i;
4276
4277 *buttons = (~inb(TRID_REG(card, T4D_GAME_LEG)) >> 4) & 0xf;
4278
4279 for (i = 0; i < 4; i++) {
4280 axes[i] = inw(TRID_REG(card, T4D_GAME_AXD) + i * sizeof (u16));
4281 if (axes[i] == 0xffff)
4282 axes[i] = -1;
4283 }
4284
4285 return 0;
4286}
4287
4288static int
4289trident_game_open(struct gameport *gameport, int mode)
4290{
4291 struct trident_card *card = gameport->port_data;
4292
4293 switch (mode) {
4294 case GAMEPORT_MODE_COOKED:
4295 outb(0x80, TRID_REG(card, T4D_GAME_CR));
4296 msleep(20);
4297 return 0;
4298 case GAMEPORT_MODE_RAW:
4299 outb(0x00, TRID_REG(card, T4D_GAME_CR));
4300 return 0;
4301 default:
4302 return -1;
4303 }
4304
4305 return 0;
4306}
4307
4308static int __devinit
4309trident_register_gameport(struct trident_card *card)
4310{
4311 struct gameport *gp;
4312
4313 card->gameport = gp = gameport_allocate_port();
4314 if (!gp) {
4315 printk(KERN_ERR "trident: can not allocate memory for gameport\n");
4316 return -ENOMEM;
4317 }
4318
4319 gameport_set_name(gp, "Trident 4DWave");
4320 gameport_set_phys(gp, "pci%s/gameport0", pci_name(card->pci_dev));
4321 gp->read = trident_game_read;
4322 gp->trigger = trident_game_trigger;
4323 gp->cooked_read = trident_game_cooked_read;
4324 gp->open = trident_game_open;
4325 gp->fuzz = 64;
4326 gp->port_data = card;
4327
4328 gameport_register_port(gp);
4329
4330 return 0;
4331}
4332
4333/* install the driver, we do not allocate hardware channel nor DMA buffer */
4334/* now, they are defered until "ACCESS" time (in prog_dmabuf called by */
4335/* open/read/write/ioctl/mmap) */
4336static int __devinit
4337trident_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
4338{
4339 unsigned long iobase;
4340 struct trident_card *card;
4341 u8 bits;
4342 u8 revision;
4343 int i = 0;
4344 u16 temp;
4345 struct pci_dev *pci_dev_m1533 = NULL;
4346 int rc = -ENODEV;
4347 u64 dma_mask;
4348
4349 if (pci_enable_device(pci_dev))
4350 goto out;
4351
4352 if (pci_dev->device == PCI_DEVICE_ID_ALI_5451)
4353 dma_mask = ALI_DMA_MASK;
4354 else
4355 dma_mask = TRIDENT_DMA_MASK;
4356 if (pci_set_dma_mask(pci_dev, dma_mask)) {
4357 printk(KERN_ERR "trident: architecture does not support"
4358 " %s PCI busmaster DMA\n",
4359 pci_dev->device == PCI_DEVICE_ID_ALI_5451 ?
4360 "32-bit" : "30-bit");
4361 goto out;
4362 }
4363 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &revision);
4364
4365 if (pci_id->device == PCI_DEVICE_ID_INTERG_5050)
4366 iobase = pci_resource_start(pci_dev, 1);
4367 else
4368 iobase = pci_resource_start(pci_dev, 0);
4369
4370 if (!request_region(iobase, 256, card_names[pci_id->driver_data])) {
4371 printk(KERN_ERR "trident: can't allocate I/O space at "
4372 "0x%4.4lx\n", iobase);
4373 goto out;
4374 }
4375
4376 rc = -ENOMEM;
4377 if ((card = kmalloc(sizeof(*card), GFP_KERNEL)) == NULL) {
4378 printk(KERN_ERR "trident: out of memory\n");
4379 goto out_release_region;
4380 }
4381 memset(card, 0, sizeof (*card));
4382
4383 init_timer(&card->timer);
4384 card->iobase = iobase;
4385 card->pci_dev = pci_dev;
4386 card->pci_id = pci_id->device;
4387 card->revision = revision;
4388 card->irq = pci_dev->irq;
4389 card->next = devs;
4390 card->magic = TRIDENT_CARD_MAGIC;
4391 card->banks[BANK_A].addresses = &bank_a_addrs;
4392 card->banks[BANK_A].bitmap = 0UL;
4393 card->banks[BANK_B].addresses = &bank_b_addrs;
4394 card->banks[BANK_B].bitmap = 0UL;
4395
4396 init_MUTEX(&card->open_sem);
4397 spin_lock_init(&card->lock);
4398 init_timer(&card->timer);
4399
4400 devs = card;
4401
4402 pci_set_master(pci_dev);
4403
4404 printk(KERN_INFO "trident: %s found at IO 0x%04lx, IRQ %d\n",
4405 card_names[pci_id->driver_data], card->iobase, card->irq);
4406
4407 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
4408 /* ALi channel Management */
4409 card->alloc_pcm_channel = ali_alloc_pcm_channel;
4410 card->alloc_rec_pcm_channel = ali_alloc_rec_pcm_channel;
4411 card->free_pcm_channel = ali_free_pcm_channel;
4412
4413 card->address_interrupt = ali_address_interrupt;
4414
4415 /* Added by Matt Wu 01-05-2001 for spdif in */
4416 card->multi_channel_use_count = 0;
4417 card->rec_channel_use_count = 0;
4418
4419 /* ALi SPDIF OUT function */
4420 if (card->revision == ALI_5451_V02) {
4421 ali_setup_spdif_out(card, ALI_PCM_TO_SPDIF_OUT);
4422 res = create_proc_entry("ALi5451", 0, NULL);
4423 if (res) {
4424 res->write_proc = ali_write_proc;
4425 res->data = card;
4426 }
4427 }
4428
4429 /* Add H/W Volume Control By Matt Wu Jul. 06, 2001 */
4430 card->hwvolctl = 0;
4431 pci_dev_m1533 = pci_find_device(PCI_VENDOR_ID_AL,
4432 PCI_DEVICE_ID_AL_M1533,
4433 pci_dev_m1533);
4434 rc = -ENODEV;
4435 if (pci_dev_m1533 == NULL)
4436 goto out_proc_fs;
4437 pci_read_config_byte(pci_dev_m1533, 0x63, &bits);
4438 if (bits & (1 << 5))
4439 card->hwvolctl = 1;
4440 if (card->hwvolctl) {
4441 /* Clear m1533 pci cfg 78h bit 30 to zero, which makes
4442 GPIO11/12/13 work as ACGP_UP/DOWN/MUTE. */
4443 pci_read_config_byte(pci_dev_m1533, 0x7b, &bits);
4444 bits &= 0xbf; /*clear bit 6 */
4445 pci_write_config_byte(pci_dev_m1533, 0x7b, bits);
4446 }
4447 } else if (card->pci_id == PCI_DEVICE_ID_INTERG_5050) {
4448 card->alloc_pcm_channel = cyber_alloc_pcm_channel;
4449 card->alloc_rec_pcm_channel = cyber_alloc_pcm_channel;
4450 card->free_pcm_channel = cyber_free_pcm_channel;
4451 card->address_interrupt = cyber_address_interrupt;
4452 cyber_init_ritual(card);
4453 } else {
4454 card->alloc_pcm_channel = trident_alloc_pcm_channel;
4455 card->alloc_rec_pcm_channel = trident_alloc_pcm_channel;
4456 card->free_pcm_channel = trident_free_pcm_channel;
4457 card->address_interrupt = trident_address_interrupt;
4458 }
4459
4460 /* claim our irq */
4461 rc = -ENODEV;
4462 if (request_irq(card->irq, &trident_interrupt, SA_SHIRQ,
4463 card_names[pci_id->driver_data], card)) {
4464 printk(KERN_ERR "trident: unable to allocate irq %d\n",
4465 card->irq);
4466 goto out_proc_fs;
4467 }
4468 /* register /dev/dsp */
4469 if ((card->dev_audio = register_sound_dsp(&trident_audio_fops, -1)) < 0) {
4470 printk(KERN_ERR "trident: couldn't register DSP device!\n");
4471 goto out_free_irq;
4472 }
4473 card->mixer_regs_ready = 0;
4474 /* initialize AC97 codec and register /dev/mixer */
4475 if (trident_ac97_init(card) <= 0) {
4476 /* unregister audio devices */
4477 for (i = 0; i < NR_AC97; i++) {
4478 if (card->ac97_codec[i] != NULL) {
4479 struct ac97_codec* codec = card->ac97_codec[i];
4480 unregister_sound_mixer(codec->dev_mixer);
4481 ac97_release_codec(codec);
4482 }
4483 }
4484 goto out_unregister_sound_dsp;
4485 }
4486 card->mixer_regs_ready = 1;
4487 outl(0x00, TRID_REG(card, T4D_MUSICVOL_WAVEVOL));
4488
4489 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
4490 /* Add H/W Volume Control By Matt Wu Jul. 06, 2001 */
4491 if (card->hwvolctl) {
4492 /* Enable GPIO IRQ (MISCINT bit 18h) */
4493 temp = inw(TRID_REG(card, T4D_MISCINT + 2));
4494 temp |= 0x0004;
4495 outw(temp, TRID_REG(card, T4D_MISCINT + 2));
4496
4497 /* Enable H/W Volume Control GLOVAL CONTROL bit 0 */
4498 temp = inw(TRID_REG(card, ALI_GLOBAL_CONTROL));
4499 temp |= 0x0001;
4500 outw(temp, TRID_REG(card, ALI_GLOBAL_CONTROL));
4501
4502 }
4503 if (card->revision == ALI_5451_V02)
4504 ali_close_multi_channels();
4505 /* edited by HMSEO for GT sound */
4506#if defined(CONFIG_ALPHA_NAUTILUS) || defined(CONFIG_ALPHA_GENERIC)
4507 {
4508 u16 ac97_data;
4509 extern struct hwrpb_struct *hwrpb;
4510
4511 if ((hwrpb->sys_type) == 201) {
4512 printk(KERN_INFO "trident: Running on Alpha system "
4513 "type Nautilus\n");
4514 ac97_data = ali_ac97_get(card, 0, AC97_POWER_CONTROL);
4515 ali_ac97_set(card, 0, AC97_POWER_CONTROL,
4516 ac97_data | ALI_EAPD_POWER_DOWN);
4517 }
4518 }
4519#endif /* CONFIG_ALPHA_NAUTILUS || CONFIG_ALPHA_GENERIC */
4520 /* edited by HMSEO for GT sound */
4521 }
4522 rc = 0;
4523 pci_set_drvdata(pci_dev, card);
4524
4525 /* Enable Address Engine Interrupts */
4526 trident_enable_loop_interrupts(card);
4527
4528 /* Register gameport */
4529 trident_register_gameport(card);
4530
4531out:
4532 return rc;
4533
4534out_unregister_sound_dsp:
4535 unregister_sound_dsp(card->dev_audio);
4536out_free_irq:
4537 free_irq(card->irq, card);
4538out_proc_fs:
4539 if (res) {
4540 remove_proc_entry("ALi5451", NULL);
4541 res = NULL;
4542 }
4543 kfree(card);
4544 devs = NULL;
4545out_release_region:
4546 release_region(iobase, 256);
4547 return rc;
4548}
4549
4550static void __devexit
4551trident_remove(struct pci_dev *pci_dev)
4552{
4553 int i;
4554 struct trident_card *card = pci_get_drvdata(pci_dev);
4555
4556 /*
4557 * Kill running timers before unload. We can't have them
4558 * going off after rmmod!
4559 */
4560 if (card->hwvolctl)
4561 del_timer_sync(&card->timer);
4562
4563 /* ALi S/PDIF and Power Management */
4564 if (card->pci_id == PCI_DEVICE_ID_ALI_5451) {
4565 ali_setup_spdif_out(card, ALI_PCM_TO_SPDIF_OUT);
4566 ali_disable_special_channel(card, ALI_SPDIF_OUT_CHANNEL);
4567 ali_disable_spdif_in(card);
4568 remove_proc_entry("ALi5451", NULL);
4569 }
4570
4571 /* Unregister gameport */
4572 if (card->gameport)
4573 gameport_unregister_port(card->gameport);
4574
4575 /* Kill interrupts, and SP/DIF */
4576 trident_disable_loop_interrupts(card);
4577
4578 /* free hardware resources */
4579 free_irq(card->irq, card);
4580 release_region(card->iobase, 256);
4581
4582 /* unregister audio devices */
4583 for (i = 0; i < NR_AC97; i++)
4584 if (card->ac97_codec[i] != NULL) {
4585 unregister_sound_mixer(card->ac97_codec[i]->dev_mixer);
4586 ac97_release_codec(card->ac97_codec[i]);
4587 }
4588 unregister_sound_dsp(card->dev_audio);
4589
4590 kfree(card);
4591
4592 pci_set_drvdata(pci_dev, NULL);
4593}
4594
4595MODULE_AUTHOR("Alan Cox, Aaron Holtzman, Ollie Lho, Ching Ling Lee, Muli Ben-Yehuda");
4596MODULE_DESCRIPTION("Trident 4DWave/SiS 7018/ALi 5451 and Tvia/IGST CyberPro5050 PCI "
4597 "Audio Driver");
4598MODULE_LICENSE("GPL");
4599
4600#define TRIDENT_MODULE_NAME "trident"
4601
4602static struct pci_driver trident_pci_driver = {
4603 .name = TRIDENT_MODULE_NAME,
4604 .id_table = trident_pci_tbl,
4605 .probe = trident_probe,
4606 .remove = __devexit_p(trident_remove),
4607 .suspend = trident_suspend,
4608 .resume = trident_resume
4609};
4610
4611static int __init
4612trident_init_module(void)
4613{
4614 printk(KERN_INFO "Trident 4DWave/SiS 7018/ALi 5451,Tvia CyberPro "
4615 "5050 PCI Audio, version " DRIVER_VERSION ", " __TIME__ " "
4616 __DATE__ "\n");
4617
4618 return pci_register_driver(&trident_pci_driver);
4619}
4620
4621static void __exit
4622trident_cleanup_module(void)
4623{
4624 pci_unregister_driver(&trident_pci_driver);
4625}
4626
4627module_init(trident_init_module);
4628module_exit(trident_cleanup_module);
diff --git a/sound/oss/trident.h b/sound/oss/trident.h
new file mode 100644
index 000000000000..4713b49fc91d
--- /dev/null
+++ b/sound/oss/trident.h
@@ -0,0 +1,358 @@
1#ifndef __TRID4DWAVE_H
2#define __TRID4DWAVE_H
3
4/*
5 * audio@tridentmicro.com
6 * Fri Feb 19 15:55:28 MST 1999
7 * Definitions for Trident 4DWave DX/NX chips
8 *
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26/* PCI vendor and device ID */
27#ifndef PCI_VENDOR_ID_TRIDENT
28#define PCI_VENDOR_ID_TRIDENT 0x1023
29#endif
30
31#ifndef PCI_VENDOR_ID_SI
32#define PCI_VENDOR_ID_SI 0x1039
33#endif
34
35#ifndef PCI_VENDOR_ID_ALI
36#define PCI_VENDOR_ID_ALI 0x10b9
37#endif
38
39#ifndef PCI_DEVICE_ID_TRIDENT_4DWAVE_DX
40#define PCI_DEVICE_ID_TRIDENT_4DWAVE_DX 0x2000
41#endif
42
43#ifndef PCI_DEVICE_ID_TRIDENT_4DWAVE_NX
44#define PCI_DEVICE_ID_TRIDENT_4DWAVE_NX 0x2001
45#endif
46
47#ifndef PCI_DEVICE_ID_SI_7018
48#define PCI_DEVICE_ID_SI_7018 0x7018
49#endif
50
51#ifndef PCI_DEVICE_ID_ALI_5451
52#define PCI_DEVICE_ID_ALI_5451 0x5451
53#endif
54
55#ifndef PCI_DEVICE_ID_ALI_1533
56#define PCI_DEVICE_ID_ALI_1533 0x1533
57#endif
58
59#define CHANNEL_REGS 5
60#define CHANNEL_START 0xe0 // The first bytes of the contiguous register space.
61
62#define BANK_A 0
63#define BANK_B 1
64#define NR_BANKS 2
65
66#define TRIDENT_FMT_STEREO 0x01
67#define TRIDENT_FMT_16BIT 0x02
68#define TRIDENT_FMT_MASK 0x03
69
70#define DAC_RUNNING 0x01
71#define ADC_RUNNING 0x02
72
73/* Register Addresses */
74
75/* operational registers common to DX, NX, 7018 */
76enum trident_op_registers {
77 T4D_GAME_CR = 0x30, T4D_GAME_LEG = 0x31,
78 T4D_GAME_AXD = 0x34,
79 T4D_REC_CH = 0x70,
80 T4D_START_A = 0x80, T4D_STOP_A = 0x84,
81 T4D_DLY_A = 0x88, T4D_SIGN_CSO_A = 0x8c,
82 T4D_CSPF_A = 0x90, T4D_CEBC_A = 0x94,
83 T4D_AINT_A = 0x98, T4D_EINT_A = 0x9c,
84 T4D_LFO_GC_CIR = 0xa0, T4D_AINTEN_A = 0xa4,
85 T4D_MUSICVOL_WAVEVOL = 0xa8, T4D_SBDELTA_DELTA_R = 0xac,
86 T4D_MISCINT = 0xb0, T4D_START_B = 0xb4,
87 T4D_STOP_B = 0xb8, T4D_CSPF_B = 0xbc,
88 T4D_SBBL_SBCL = 0xc0, T4D_SBCTRL_SBE2R_SBDD = 0xc4,
89 T4D_STIMER = 0xc8, T4D_LFO_B_I2S_DELTA = 0xcc,
90 T4D_AINT_B = 0xd8, T4D_AINTEN_B = 0xdc,
91 ALI_MPUR2 = 0x22, ALI_GPIO = 0x7c,
92 ALI_EBUF1 = 0xf4,
93 ALI_EBUF2 = 0xf8
94};
95
96enum ali_op_registers {
97 ALI_SCTRL = 0x48,
98 ALI_GLOBAL_CONTROL = 0xd4,
99 ALI_STIMER = 0xc8,
100 ALI_SPDIF_CS = 0x70,
101 ALI_SPDIF_CTRL = 0x74
102};
103
104enum ali_registers_number {
105 ALI_GLOBAL_REGS = 56,
106 ALI_CHANNEL_REGS = 8,
107 ALI_MIXER_REGS = 20
108};
109
110enum ali_sctrl_control_bit {
111 ALI_SPDIF_OUT_ENABLE = 0x20
112};
113
114enum ali_global_control_bit {
115 ALI_SPDIF_OUT_SEL_PCM = 0x00000400,
116 ALI_SPDIF_IN_SUPPORT = 0x00000800,
117 ALI_SPDIF_OUT_CH_ENABLE = 0x00008000,
118 ALI_SPDIF_IN_CH_ENABLE = 0x00080000,
119 ALI_PCM_IN_DISABLE = 0x7fffffff,
120 ALI_PCM_IN_ENABLE = 0x80000000,
121 ALI_SPDIF_IN_CH_DISABLE = 0xfff7ffff,
122 ALI_SPDIF_OUT_CH_DISABLE = 0xffff7fff,
123 ALI_SPDIF_OUT_SEL_SPDIF = 0xfffffbff
124
125};
126
127enum ali_spdif_control_bit {
128 ALI_SPDIF_IN_FUNC_ENABLE = 0x02,
129 ALI_SPDIF_IN_CH_STATUS = 0x40,
130 ALI_SPDIF_OUT_CH_STATUS = 0xbf
131
132};
133
134enum ali_control_all {
135 ALI_DISABLE_ALL_IRQ = 0,
136 ALI_CHANNELS = 32,
137 ALI_STOP_ALL_CHANNELS = 0xffffffff,
138 ALI_MULTI_CHANNELS_START_STOP = 0x07800000
139};
140
141enum ali_EMOD_control_bit {
142 ALI_EMOD_DEC = 0x00000000,
143 ALI_EMOD_INC = 0x10000000,
144 ALI_EMOD_Delay = 0x20000000,
145 ALI_EMOD_Still = 0x30000000
146};
147
148enum ali_pcm_in_channel_num {
149 ALI_NORMAL_CHANNEL = 0,
150 ALI_SPDIF_OUT_CHANNEL = 15,
151 ALI_SPDIF_IN_CHANNEL = 19,
152 ALI_LEF_CHANNEL = 23,
153 ALI_CENTER_CHANNEL = 24,
154 ALI_SURR_RIGHT_CHANNEL = 25,
155 ALI_SURR_LEFT_CHANNEL = 26,
156 ALI_PCM_IN_CHANNEL = 31
157};
158
159enum ali_pcm_out_channel_num {
160 ALI_PCM_OUT_CHANNEL_FIRST = 0,
161 ALI_PCM_OUT_CHANNEL_LAST = 31
162};
163
164enum ali_ac97_power_control_bit {
165 ALI_EAPD_POWER_DOWN = 0x8000
166};
167
168enum ali_update_ptr_flags {
169 ALI_ADDRESS_INT_UPDATE = 0x01
170};
171
172enum ali_revision {
173 ALI_5451_V02 = 0x02
174};
175
176enum ali_spdif_out_control {
177 ALI_PCM_TO_SPDIF_OUT = 0,
178 ALI_SPDIF_OUT_TO_SPDIF_OUT = 1,
179 ALI_SPDIF_OUT_PCM = 0,
180 ALI_SPDIF_OUT_NON_PCM = 2
181};
182
183/* S/PDIF Operational Registers for 4D-NX */
184enum nx_spdif_registers {
185 NX_SPCTRL_SPCSO = 0x24, NX_SPLBA = 0x28,
186 NX_SPESO = 0x2c, NX_SPCSTATUS = 0x64
187};
188
189/* OP registers to access each hardware channel */
190enum channel_registers {
191 CH_DX_CSO_ALPHA_FMS = 0xe0, CH_DX_ESO_DELTA = 0xe8,
192 CH_DX_FMC_RVOL_CVOL = 0xec,
193 CH_NX_DELTA_CSO = 0xe0, CH_NX_DELTA_ESO = 0xe8,
194 CH_NX_ALPHA_FMS_FMC_RVOL_CVOL = 0xec,
195 CH_LBA = 0xe4,
196 CH_GVSEL_PAN_VOL_CTRL_EC = 0xf0
197};
198
199/* registers to read/write/control AC97 codec */
200enum dx_ac97_registers {
201 DX_ACR0_AC97_W = 0x40, DX_ACR1_AC97_R = 0x44,
202 DX_ACR2_AC97_COM_STAT = 0x48
203};
204
205enum nx_ac97_registers {
206 NX_ACR0_AC97_COM_STAT = 0x40, NX_ACR1_AC97_W = 0x44,
207 NX_ACR2_AC97_R_PRIMARY = 0x48, NX_ACR3_AC97_R_SECONDARY = 0x4c
208};
209
210enum si_ac97_registers {
211 SI_AC97_WRITE = 0x40, SI_AC97_READ = 0x44,
212 SI_SERIAL_INTF_CTRL = 0x48, SI_AC97_GPIO = 0x4c
213};
214
215enum ali_ac97_registers {
216 ALI_AC97_WRITE = 0x40, ALI_AC97_READ = 0x44
217};
218
219/* Bit mask for operational registers */
220#define AC97_REG_ADDR 0x000000ff
221
222enum ali_ac97_bits {
223 ALI_AC97_BUSY_WRITE = 0x8000, ALI_AC97_BUSY_READ = 0x8000,
224 ALI_AC97_WRITE_ACTION = 0x8000, ALI_AC97_READ_ACTION = 0x8000,
225 ALI_AC97_AUDIO_BUSY = 0x4000, ALI_AC97_SECONDARY = 0x0080,
226 ALI_AC97_READ_MIXER_REGISTER = 0xfeff,
227 ALI_AC97_WRITE_MIXER_REGISTER = 0x0100
228};
229
230enum sis7018_ac97_bits {
231 SI_AC97_BUSY_WRITE = 0x8000, SI_AC97_BUSY_READ = 0x8000,
232 SI_AC97_AUDIO_BUSY = 0x4000, SI_AC97_MODEM_BUSY = 0x2000,
233 SI_AC97_SECONDARY = 0x0080
234};
235
236enum trident_dx_ac97_bits {
237 DX_AC97_BUSY_WRITE = 0x8000, DX_AC97_BUSY_READ = 0x8000,
238 DX_AC97_READY = 0x0010, DX_AC97_RECORD = 0x0008,
239 DX_AC97_PLAYBACK = 0x0002
240};
241
242enum trident_nx_ac97_bits {
243 /* ACR1-3 */
244 NX_AC97_BUSY_WRITE = 0x0800, NX_AC97_BUSY_READ = 0x0800,
245 NX_AC97_BUSY_DATA = 0x0400, NX_AC97_WRITE_SECONDARY = 0x0100,
246 /* ACR0 */
247 NX_AC97_SECONDARY_READY = 0x0040, NX_AC97_SECONDARY_RECORD = 0x0020,
248 NX_AC97_SURROUND_OUTPUT = 0x0010,
249 NX_AC97_PRIMARY_READY = 0x0008, NX_AC97_PRIMARY_RECORD = 0x0004,
250 NX_AC97_PCM_OUTPUT = 0x0002,
251 NX_AC97_WARM_RESET = 0x0001
252};
253
254enum serial_intf_ctrl_bits {
255 WARM_REST = 0x00000001, COLD_RESET = 0x00000002,
256 I2S_CLOCK = 0x00000004, PCM_SEC_AC97= 0x00000008,
257 AC97_DBL_RATE = 0x00000010, SPDIF_EN = 0x00000020,
258 I2S_OUTPUT_EN = 0x00000040, I2S_INPUT_EN = 0x00000080,
259 PCMIN = 0x00000100, LINE1IN = 0x00000200,
260 MICIN = 0x00000400, LINE2IN = 0x00000800,
261 HEAD_SET_IN = 0x00001000, GPIOIN = 0x00002000,
262 /* 7018 spec says id = 01 but the demo board routed to 10
263 SECONDARY_ID= 0x00004000, */
264 SECONDARY_ID= 0x00004000,
265 PCMOUT = 0x00010000, SURROUT = 0x00020000,
266 CENTEROUT = 0x00040000, LFEOUT = 0x00080000,
267 LINE1OUT = 0x00100000, LINE2OUT = 0x00200000,
268 GPIOOUT = 0x00400000,
269 SI_AC97_PRIMARY_READY = 0x01000000,
270 SI_AC97_SECONDARY_READY = 0x02000000,
271};
272
273enum global_control_bits {
274 CHANNLE_IDX = 0x0000003f, PB_RESET = 0x00000100,
275 PAUSE_ENG = 0x00000200,
276 OVERRUN_IE = 0x00000400, UNDERRUN_IE = 0x00000800,
277 ENDLP_IE = 0x00001000, MIDLP_IE = 0x00002000,
278 ETOG_IE = 0x00004000,
279 EDROP_IE = 0x00008000, BANK_B_EN = 0x00010000
280};
281
282enum channel_control_bits {
283 CHANNEL_LOOP = 0x00001000, CHANNEL_SIGNED = 0x00002000,
284 CHANNEL_STEREO = 0x00004000, CHANNEL_16BITS = 0x00008000,
285};
286
287enum channel_attribute {
288 /* playback/record select */
289 CHANNEL_PB = 0x0000, CHANNEL_SPC_PB = 0x4000,
290 CHANNEL_REC = 0x8000, CHANNEL_REC_PB = 0xc000,
291 /* playback destination/record source select */
292 MODEM_LINE1 = 0x0000, MODEM_LINE2 = 0x0400,
293 PCM_LR = 0x0800, HSET = 0x0c00,
294 I2S_LR = 0x1000, CENTER_LFE = 0x1400,
295 SURR_LR = 0x1800, SPDIF_LR = 0x1c00,
296 MIC = 0x1400,
297 /* mist stuff */
298 MONO_LEFT = 0x0000, MONO_RIGHT = 0x0100,
299 MONO_MIX = 0x0200, SRC_ENABLE = 0x0080,
300};
301
302enum miscint_bits {
303 PB_UNDERRUN_IRO = 0x00000001, REC_OVERRUN_IRQ = 0x00000002,
304 SB_IRQ = 0x00000004, MPU401_IRQ = 0x00000008,
305 OPL3_IRQ = 0x00000010, ADDRESS_IRQ = 0x00000020,
306 ENVELOPE_IRQ = 0x00000040, ST_IRQ = 0x00000080,
307 PB_UNDERRUN = 0x00000100, REC_OVERRUN = 0x00000200,
308 MIXER_UNDERFLOW = 0x00000400, MIXER_OVERFLOW = 0x00000800,
309 ST_TARGET_REACHED = 0x00008000, PB_24K_MODE = 0x00010000,
310 ST_IRQ_EN = 0x00800000, ACGPIO_IRQ = 0x01000000
311};
312
313#define TRID_REG( trident, x ) ( (trident) -> iobase + (x) )
314
315#define CYBER_PORT_AUDIO 0x3CE
316#define CYBER_IDX_AUDIO_ENABLE 0x7B
317#define CYBER_BMSK_AUDIO_INT_ENABLE 0x09
318#define CYBER_BMSK_AUENZ 0x01
319#define CYBER_BMSK_AUENZ_ENABLE 0x00
320#define CYBER_IDX_IRQ_ENABLE 0x12
321
322#define VALIDATE_MAGIC(FOO,MAG) \
323({ \
324 if (!(FOO) || (FOO)->magic != MAG) { \
325 printk(invalid_magic,__FUNCTION__); \
326 return -ENXIO; \
327 } \
328})
329
330#define VALIDATE_STATE(a) VALIDATE_MAGIC(a,TRIDENT_STATE_MAGIC)
331#define VALIDATE_CARD(a) VALIDATE_MAGIC(a,TRIDENT_CARD_MAGIC)
332
333static inline unsigned ld2(unsigned int x)
334{
335 unsigned r = 0;
336
337 if (x >= 0x10000) {
338 x >>= 16;
339 r += 16;
340 }
341 if (x >= 0x100) {
342 x >>= 8;
343 r += 8;
344 }
345 if (x >= 0x10) {
346 x >>= 4;
347 r += 4;
348 }
349 if (x >= 4) {
350 x >>= 2;
351 r += 2;
352 }
353 if (x >= 2)
354 r++;
355 return r;
356}
357
358#endif /* __TRID4DWAVE_H */
diff --git a/sound/oss/trix.c b/sound/oss/trix.c
new file mode 100644
index 000000000000..d1f1f154dcce
--- /dev/null
+++ b/sound/oss/trix.c
@@ -0,0 +1,525 @@
1/*
2 * sound/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 int 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(io, int, 0);
417module_param(irq, int, 0);
418module_param(dma, int, 0);
419module_param(dma2, int, 0);
420module_param(sb_io, int, 0);
421module_param(sb_dma, int, 0);
422module_param(sb_irq, int, 0);
423module_param(mpu_io, int, 0);
424module_param(mpu_irq, int, 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 && trix_boot)
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
new file mode 100644
index 000000000000..858e1fe6c618
--- /dev/null
+++ b/sound/oss/tuning.h
@@ -0,0 +1,29 @@
1#ifdef SEQUENCER_C
2
3unsigned short semitone_tuning[24] =
4{
5/* 0 */ 10000, 10595, 11225, 11892, 12599, 13348, 14142, 14983,
6/* 8 */ 15874, 16818, 17818, 18877, 20000, 21189, 22449, 23784,
7/* 16 */ 25198, 26697, 28284, 29966, 31748, 33636, 35636, 37755
8};
9
10unsigned short cent_tuning[100] =
11{
12/* 0 */ 10000, 10006, 10012, 10017, 10023, 10029, 10035, 10041,
13/* 8 */ 10046, 10052, 10058, 10064, 10070, 10075, 10081, 10087,
14/* 16 */ 10093, 10099, 10105, 10110, 10116, 10122, 10128, 10134,
15/* 24 */ 10140, 10145, 10151, 10157, 10163, 10169, 10175, 10181,
16/* 32 */ 10187, 10192, 10198, 10204, 10210, 10216, 10222, 10228,
17/* 40 */ 10234, 10240, 10246, 10251, 10257, 10263, 10269, 10275,
18/* 48 */ 10281, 10287, 10293, 10299, 10305, 10311, 10317, 10323,
19/* 56 */ 10329, 10335, 10341, 10347, 10353, 10359, 10365, 10371,
20/* 64 */ 10377, 10383, 10389, 10395, 10401, 10407, 10413, 10419,
21/* 72 */ 10425, 10431, 10437, 10443, 10449, 10455, 10461, 10467,
22/* 80 */ 10473, 10479, 10485, 10491, 10497, 10503, 10509, 10515,
23/* 88 */ 10521, 10528, 10534, 10540, 10546, 10552, 10558, 10564,
24/* 96 */ 10570, 10576, 10582, 10589
25};
26#else
27extern unsigned short semitone_tuning[24];
28extern unsigned short cent_tuning[100];
29#endif
diff --git a/sound/oss/uart401.c b/sound/oss/uart401.c
new file mode 100644
index 000000000000..a3d75baf6df8
--- /dev/null
+++ b/sound/oss/uart401.c
@@ -0,0 +1,481 @@
1/*
2 * sound/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/spinlock.h>
28#include "sound_config.h"
29
30#include "mpu401.h"
31
32typedef struct uart401_devc
33{
34 int base;
35 int irq;
36 int *osp;
37 void (*midi_input_intr) (int dev, unsigned char data);
38 int opened, disabled;
39 volatile unsigned char input_byte;
40 int my_dev;
41 int share_irq;
42 spinlock_t lock;
43}
44uart401_devc;
45
46#define DATAPORT (devc->base)
47#define COMDPORT (devc->base+1)
48#define STATPORT (devc->base+1)
49
50static int uart401_status(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(uart401_devc * devc, unsigned char cmd)
59{
60 outb((cmd), COMDPORT);
61}
62
63static int uart401_read(uart401_devc * devc)
64{
65 return inb(DATAPORT);
66}
67
68static void uart401_write(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(uart401_devc * devc);
80static void enter_uart_mode(uart401_devc * devc);
81
82static void uart401_input_loop(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, struct pt_regs *dummy)
100{
101 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 uart401_devc *devc = (uart401_devc *) midi_devs[dev]->devc;
121
122 if (devc->opened)
123 return -EBUSY;
124
125 /* Flush the UART */
126
127 while (input_avail(devc))
128 uart401_read(devc);
129
130 devc->midi_input_intr = input;
131 devc->opened = mode;
132 enter_uart_mode(devc);
133 devc->disabled = 0;
134
135 return 0;
136}
137
138static void uart401_close(int dev)
139{
140 uart401_devc *devc = (uart401_devc *) midi_devs[dev]->devc;
141
142 reset_uart401(devc);
143 devc->opened = 0;
144}
145
146static int uart401_out(int dev, unsigned char midi_byte)
147{
148 int timeout;
149 unsigned long flags;
150 uart401_devc *devc = (uart401_devc *) midi_devs[dev]->devc;
151
152 if (devc->disabled)
153 return 1;
154 /*
155 * Test for input since pending input seems to block the output.
156 */
157
158 spin_lock_irqsave(&devc->lock,flags);
159 if (input_avail(devc))
160 uart401_input_loop(devc);
161
162 spin_unlock_irqrestore(&devc->lock,flags);
163
164 /*
165 * Sometimes it takes about 13000 loops before the output becomes ready
166 * (After reset). Normally it takes just about 10 loops.
167 */
168
169 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
170
171 if (!output_ready(devc))
172 {
173 printk(KERN_WARNING "uart401: Timeout - Device not responding\n");
174 devc->disabled = 1;
175 reset_uart401(devc);
176 enter_uart_mode(devc);
177 return 1;
178 }
179 uart401_write(devc, midi_byte);
180 return 1;
181}
182
183static inline int uart401_start_read(int dev)
184{
185 return 0;
186}
187
188static inline int uart401_end_read(int dev)
189{
190 return 0;
191}
192
193static inline void uart401_kick(int dev)
194{
195}
196
197static inline int uart401_buffer_status(int dev)
198{
199 return 0;
200}
201
202#define MIDI_SYNTH_NAME "MPU-401 UART"
203#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
204#include "midi_synth.h"
205
206static const struct midi_operations uart401_operations =
207{
208 .owner = THIS_MODULE,
209 .info = {"MPU-401 (UART) MIDI", 0, 0, SNDCARD_MPU401},
210 .converter = &std_midi_synth,
211 .in_info = {0},
212 .open = uart401_open,
213 .close = uart401_close,
214 .outputc = uart401_out,
215 .start_read = uart401_start_read,
216 .end_read = uart401_end_read,
217 .kick = uart401_kick,
218 .buffer_status = uart401_buffer_status,
219};
220
221static void enter_uart_mode(uart401_devc * devc)
222{
223 int ok, timeout;
224 unsigned long flags;
225
226 spin_lock_irqsave(&devc->lock,flags);
227 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
228
229 devc->input_byte = 0;
230 uart401_cmd(devc, UART_MODE_ON);
231
232 ok = 0;
233 for (timeout = 50000; timeout > 0 && !ok; timeout--)
234 if (devc->input_byte == MPU_ACK)
235 ok = 1;
236 else if (input_avail(devc))
237 if (uart401_read(devc) == MPU_ACK)
238 ok = 1;
239
240 spin_unlock_irqrestore(&devc->lock,flags);
241}
242
243static int reset_uart401(uart401_devc * devc)
244{
245 int ok, timeout, n;
246
247 /*
248 * Send the RESET command. Try again if no success at the first time.
249 */
250
251 ok = 0;
252
253 for (n = 0; n < 2 && !ok; n++)
254 {
255 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
256 devc->input_byte = 0;
257 uart401_cmd(devc, MPU_RESET);
258
259 /*
260 * Wait at least 25 msec. This method is not accurate so let's make the
261 * loop bit longer. Cannot sleep since this is called during boot.
262 */
263
264 for (timeout = 50000; timeout > 0 && !ok; timeout--)
265 {
266 if (devc->input_byte == MPU_ACK) /* Interrupt */
267 ok = 1;
268 else if (input_avail(devc))
269 {
270 if (uart401_read(devc) == MPU_ACK)
271 ok = 1;
272 }
273 }
274 }
275
276
277 if (ok)
278 {
279 DEB(printk("Reset UART401 OK\n"));
280 }
281 else
282 DDB(printk("Reset UART401 failed - No hardware detected.\n"));
283
284 if (ok)
285 uart401_input_loop(devc); /*
286 * Flush input before enabling interrupts
287 */
288
289 return ok;
290}
291
292int probe_uart401(struct address_info *hw_config, struct module *owner)
293{
294 uart401_devc *devc;
295 char *name = "MPU-401 (UART) MIDI";
296 int ok = 0;
297 unsigned long flags;
298
299 DDB(printk("Entered probe_uart401()\n"));
300
301 /* Default to "not found" */
302 hw_config->slots[4] = -1;
303
304 if (!request_region(hw_config->io_base, 4, "MPU-401 UART")) {
305 printk(KERN_INFO "uart401: could not request_region(%d, 4)\n", hw_config->io_base);
306 return 0;
307 }
308
309 devc = kmalloc(sizeof(uart401_devc), GFP_KERNEL);
310 if (!devc) {
311 printk(KERN_WARNING "uart401: Can't allocate memory\n");
312 goto cleanup_region;
313 }
314
315 devc->base = hw_config->io_base;
316 devc->irq = hw_config->irq;
317 devc->osp = hw_config->osp;
318 devc->midi_input_intr = NULL;
319 devc->opened = 0;
320 devc->input_byte = 0;
321 devc->my_dev = 0;
322 devc->share_irq = 0;
323 spin_lock_init(&devc->lock);
324
325 spin_lock_irqsave(&devc->lock,flags);
326 ok = reset_uart401(devc);
327 spin_unlock_irqrestore(&devc->lock,flags);
328
329 if (!ok)
330 goto cleanup_devc;
331
332 if (hw_config->name)
333 name = hw_config->name;
334
335 if (devc->irq < 0) {
336 devc->share_irq = 1;
337 devc->irq *= -1;
338 } else
339 devc->share_irq = 0;
340
341 if (!devc->share_irq)
342 if (request_irq(devc->irq, uart401intr, 0, "MPU-401 UART", devc) < 0) {
343 printk(KERN_WARNING "uart401: Failed to allocate IRQ%d\n", devc->irq);
344 devc->share_irq = 1;
345 }
346 devc->my_dev = sound_alloc_mididev();
347 enter_uart_mode(devc);
348
349 if (devc->my_dev == -1) {
350 printk(KERN_INFO "uart401: Too many midi devices detected\n");
351 goto cleanup_irq;
352 }
353 conf_printf(name, hw_config);
354 midi_devs[devc->my_dev] = kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
355 if (!midi_devs[devc->my_dev]) {
356 printk(KERN_ERR "uart401: Failed to allocate memory\n");
357 goto cleanup_unload_mididev;
358 }
359 memcpy(midi_devs[devc->my_dev], &uart401_operations, sizeof(struct midi_operations));
360
361 if (owner)
362 midi_devs[devc->my_dev]->owner = owner;
363
364 midi_devs[devc->my_dev]->devc = devc;
365 midi_devs[devc->my_dev]->converter = kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
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 memcpy(midi_devs[devc->my_dev]->converter, &std_midi_synth, sizeof(struct synth_operations));
371 strcpy(midi_devs[devc->my_dev]->info.name, name);
372 midi_devs[devc->my_dev]->converter->id = "UART401";
373 midi_devs[devc->my_dev]->converter->midi_dev = devc->my_dev;
374
375 if (owner)
376 midi_devs[devc->my_dev]->converter->owner = owner;
377
378 hw_config->slots[4] = devc->my_dev;
379 sequencer_init();
380 devc->opened = 0;
381 return 1;
382cleanup_midi_devs:
383 kfree(midi_devs[devc->my_dev]);
384cleanup_unload_mididev:
385 sound_unload_mididev(devc->my_dev);
386cleanup_irq:
387 if (!devc->share_irq)
388 free_irq(devc->irq, devc);
389cleanup_devc:
390 kfree(devc);
391cleanup_region:
392 release_region(hw_config->io_base, 4);
393 return 0;
394}
395
396void unload_uart401(struct address_info *hw_config)
397{
398 uart401_devc *devc;
399 int n=hw_config->slots[4];
400
401 /* Not set up */
402 if(n==-1 || midi_devs[n]==NULL)
403 return;
404
405 /* Not allocated (erm ??) */
406
407 devc = midi_devs[hw_config->slots[4]]->devc;
408 if (devc == NULL)
409 return;
410
411 reset_uart401(devc);
412 release_region(hw_config->io_base, 4);
413
414 if (!devc->share_irq)
415 free_irq(devc->irq, devc);
416 if (devc)
417 {
418 kfree(midi_devs[devc->my_dev]->converter);
419 kfree(midi_devs[devc->my_dev]);
420 kfree(devc);
421 devc = NULL;
422 }
423 /* This kills midi_devs[x] */
424 sound_unload_mididev(hw_config->slots[4]);
425}
426
427EXPORT_SYMBOL(probe_uart401);
428EXPORT_SYMBOL(unload_uart401);
429EXPORT_SYMBOL(uart401intr);
430
431static struct address_info cfg_mpu;
432
433static int io = -1;
434static int irq = -1;
435
436module_param(io, int, 0444);
437module_param(irq, int, 0444);
438
439
440static int __init init_uart401(void)
441{
442 cfg_mpu.irq = irq;
443 cfg_mpu.io_base = io;
444
445 /* Can be loaded either for module use or to provide functions
446 to others */
447 if (cfg_mpu.io_base != -1 && cfg_mpu.irq != -1) {
448 printk(KERN_INFO "MPU-401 UART driver Copyright (C) Hannu Savolainen 1993-1997");
449 if (!probe_uart401(&cfg_mpu, THIS_MODULE))
450 return -ENODEV;
451 }
452
453 return 0;
454}
455
456static void __exit cleanup_uart401(void)
457{
458 if (cfg_mpu.io_base != -1 && cfg_mpu.irq != -1)
459 unload_uart401(&cfg_mpu);
460}
461
462module_init(init_uart401);
463module_exit(cleanup_uart401);
464
465#ifndef MODULE
466static int __init setup_uart401(char *str)
467{
468 /* io, irq */
469 int ints[3];
470
471 str = get_options(str, ARRAY_SIZE(ints), ints);
472
473 io = ints[1];
474 irq = ints[2];
475
476 return 1;
477}
478
479__setup("uart401=", setup_uart401);
480#endif
481MODULE_LICENSE("GPL");
diff --git a/sound/oss/uart6850.c b/sound/oss/uart6850.c
new file mode 100644
index 000000000000..be00cf128651
--- /dev/null
+++ b/sound/oss/uart6850.c
@@ -0,0 +1,362 @@
1/*
2 * sound/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 struct timer_list uart6850_timer =
82 TIMER_INITIALIZER(poll_uart6850, 0, 0);
83
84static void uart6850_input_loop(void)
85{
86 int count = 10;
87
88 while (count)
89 {
90 /*
91 * Not timed out
92 */
93 if (input_avail())
94 {
95 unsigned char c = uart6850_read();
96 count = 100;
97 if (uart6850_opened & OPEN_READ)
98 midi_input_intr(my_dev, c);
99 }
100 else
101 {
102 while (!input_avail() && count)
103 count--;
104 }
105 }
106}
107
108static irqreturn_t m6850intr(int irq, void *dev_id, struct pt_regs *dummy)
109{
110 if (input_avail())
111 uart6850_input_loop();
112 return IRQ_HANDLED;
113}
114
115/*
116 * It looks like there is no input interrupts in the UART mode. Let's try
117 * polling.
118 */
119
120static void poll_uart6850(unsigned long dummy)
121{
122 unsigned long flags;
123
124 if (!(uart6850_opened & OPEN_READ))
125 return; /* Device has been closed */
126
127 spin_lock_irqsave(&lock,flags);
128 if (input_avail())
129 uart6850_input_loop();
130
131 uart6850_timer.expires = 1 + jiffies;
132 add_timer(&uart6850_timer);
133
134 /*
135 * Come back later
136 */
137
138 spin_unlock_irqrestore(&lock,flags);
139}
140
141static int uart6850_open(int dev, int mode,
142 void (*input) (int dev, unsigned char data),
143 void (*output) (int dev)
144)
145{
146 if (uart6850_opened)
147 {
148/* printk("Midi6850: Midi busy\n");*/
149 return -EBUSY;
150 };
151
152 uart6850_cmd(UART_RESET);
153 uart6850_input_loop();
154 midi_input_intr = input;
155 uart6850_opened = mode;
156 poll_uart6850(0); /*
157 * Enable input polling
158 */
159
160 return 0;
161}
162
163static void uart6850_close(int dev)
164{
165 uart6850_cmd(UART_MODE_ON);
166 del_timer(&uart6850_timer);
167 uart6850_opened = 0;
168}
169
170static int uart6850_out(int dev, unsigned char midi_byte)
171{
172 int timeout;
173 unsigned long flags;
174
175 /*
176 * Test for input since pending input seems to block the output.
177 */
178
179 spin_lock_irqsave(&lock,flags);
180
181 if (input_avail())
182 uart6850_input_loop();
183
184 spin_unlock_irqrestore(&lock,flags);
185
186 /*
187 * Sometimes it takes about 13000 loops before the output becomes ready
188 * (After reset). Normally it takes just about 10 loops.
189 */
190
191 for (timeout = 30000; timeout > 0 && !output_ready(); timeout--); /*
192 * Wait
193 */
194 if (!output_ready())
195 {
196 printk(KERN_WARNING "Midi6850: Timeout\n");
197 return 0;
198 }
199 uart6850_write(midi_byte);
200 return 1;
201}
202
203static inline int uart6850_command(int dev, unsigned char *midi_byte)
204{
205 return 1;
206}
207
208static inline int uart6850_start_read(int dev)
209{
210 return 0;
211}
212
213static inline int uart6850_end_read(int dev)
214{
215 return 0;
216}
217
218static inline void uart6850_kick(int dev)
219{
220}
221
222static inline int uart6850_buffer_status(int dev)
223{
224 return 0; /*
225 * No data in buffers
226 */
227}
228
229#define MIDI_SYNTH_NAME "6850 UART Midi"
230#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
231#include "midi_synth.h"
232
233static struct midi_operations uart6850_operations =
234{
235 .owner = THIS_MODULE,
236 .info = {"6850 UART", 0, 0, SNDCARD_UART6850},
237 .converter = &std_midi_synth,
238 .in_info = {0},
239 .open = uart6850_open,
240 .close = uart6850_close,
241 .outputc = uart6850_out,
242 .start_read = uart6850_start_read,
243 .end_read = uart6850_end_read,
244 .kick = uart6850_kick,
245 .command = uart6850_command,
246 .buffer_status = uart6850_buffer_status
247};
248
249
250static void __init attach_uart6850(struct address_info *hw_config)
251{
252 int ok, timeout;
253 unsigned long flags;
254
255 if (!uart6850_detected)
256 return;
257
258 if ((my_dev = sound_alloc_mididev()) == -1)
259 {
260 printk(KERN_INFO "uart6850: Too many midi devices detected\n");
261 return;
262 }
263 uart6850_base = hw_config->io_base;
264 uart6850_osp = hw_config->osp;
265 uart6850_irq = hw_config->irq;
266
267 spin_lock_irqsave(&lock,flags);
268
269 for (timeout = 30000; timeout > 0 && !output_ready(); timeout--); /*
270 * Wait
271 */
272 uart6850_cmd(UART_MODE_ON);
273 ok = 1;
274 spin_unlock_irqrestore(&lock,flags);
275
276 conf_printf("6850 Midi Interface", hw_config);
277
278 std_midi_synth.midi_dev = my_dev;
279 hw_config->slots[4] = my_dev;
280 midi_devs[my_dev] = &uart6850_operations;
281 sequencer_init();
282}
283
284static inline int reset_uart6850(void)
285{
286 uart6850_read();
287 return 1; /*
288 * OK
289 */
290}
291
292static int __init probe_uart6850(struct address_info *hw_config)
293{
294 int ok;
295
296 uart6850_osp = hw_config->osp;
297 uart6850_base = hw_config->io_base;
298 uart6850_irq = hw_config->irq;
299
300 if (request_irq(uart6850_irq, m6850intr, 0, "MIDI6850", NULL) < 0)
301 return 0;
302
303 ok = reset_uart6850();
304 uart6850_detected = ok;
305 return ok;
306}
307
308static void __exit unload_uart6850(struct address_info *hw_config)
309{
310 free_irq(hw_config->irq, NULL);
311 sound_unload_mididev(hw_config->slots[4]);
312}
313
314static struct address_info cfg_mpu;
315
316static int __initdata io = -1;
317static int __initdata irq = -1;
318
319module_param(io, int, 0);
320module_param(irq, int, 0);
321
322static int __init init_uart6850(void)
323{
324 cfg_mpu.io_base = io;
325 cfg_mpu.irq = irq;
326
327 if (cfg_mpu.io_base == -1 || cfg_mpu.irq == -1) {
328 printk(KERN_INFO "uart6850: irq and io must be set.\n");
329 return -EINVAL;
330 }
331
332 if (probe_uart6850(&cfg_mpu))
333 return -ENODEV;
334 attach_uart6850(&cfg_mpu);
335
336 return 0;
337}
338
339static void __exit cleanup_uart6850(void)
340{
341 unload_uart6850(&cfg_mpu);
342}
343
344module_init(init_uart6850);
345module_exit(cleanup_uart6850);
346
347#ifndef MODULE
348static int __init setup_uart6850(char *str)
349{
350 /* io, irq */
351 int ints[3];
352
353 str = get_options(str, ARRAY_SIZE(ints), ints);
354
355 io = ints[1];
356 irq = ints[2];
357
358 return 1;
359}
360__setup("uart6850=", setup_uart6850);
361#endif
362MODULE_LICENSE("GPL");
diff --git a/sound/oss/ulaw.h b/sound/oss/ulaw.h
new file mode 100644
index 000000000000..0ff8c0a3bda0
--- /dev/null
+++ b/sound/oss/ulaw.h
@@ -0,0 +1,69 @@
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
new file mode 100644
index 000000000000..077b76797665
--- /dev/null
+++ b/sound/oss/v_midi.c
@@ -0,0 +1,291 @@
1/*
2 * sound/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/spinlock.h>
25#include "sound_config.h"
26
27#include "v_midi.h"
28
29static vmidi_devc *v_devc[2] = { NULL, NULL};
30static int midi1,midi2;
31static void *midi_mem = NULL;
32
33/*
34 * The DSP channel can be used either for input or output. Variable
35 * 'sb_irq_mode' will be set when the program calls read or write first time
36 * after open. Current version doesn't support mode changes without closing
37 * and reopening the device. Support for this feature may be implemented in a
38 * future version of this driver.
39 */
40
41
42void (*midi_input_intr) (int dev, unsigned char data);
43
44static int v_midi_open (int dev, int mode,
45 void (*input) (int dev, unsigned char data),
46 void (*output) (int dev)
47)
48{
49 vmidi_devc *devc = midi_devs[dev]->devc;
50 unsigned long flags;
51
52 if (devc == NULL)
53 return -(ENXIO);
54
55 spin_lock_irqsave(&devc->lock,flags);
56 if (devc->opened)
57 {
58 spin_unlock_irqrestore(&devc->lock,flags);
59 return -(EBUSY);
60 }
61 devc->opened = 1;
62 spin_unlock_irqrestore(&devc->lock,flags);
63
64 devc->intr_active = 1;
65
66 if (mode & OPEN_READ)
67 {
68 devc->input_opened = 1;
69 devc->midi_input_intr = input;
70 }
71
72 return 0;
73}
74
75static void v_midi_close (int dev)
76{
77 vmidi_devc *devc = midi_devs[dev]->devc;
78 unsigned long flags;
79
80 if (devc == NULL)
81 return;
82
83 spin_lock_irqsave(&devc->lock,flags);
84 devc->intr_active = 0;
85 devc->input_opened = 0;
86 devc->opened = 0;
87 spin_unlock_irqrestore(&devc->lock,flags);
88}
89
90static int v_midi_out (int dev, unsigned char midi_byte)
91{
92 vmidi_devc *devc = midi_devs[dev]->devc;
93 vmidi_devc *pdevc;
94
95 if (devc == NULL)
96 return -ENXIO;
97
98 pdevc = midi_devs[devc->pair_mididev]->devc;
99 if (pdevc->input_opened > 0){
100 if (MIDIbuf_avail(pdevc->my_mididev) > 500)
101 return 0;
102 pdevc->midi_input_intr (pdevc->my_mididev, midi_byte);
103 }
104 return 1;
105}
106
107static inline int v_midi_start_read (int dev)
108{
109 return 0;
110}
111
112static int v_midi_end_read (int dev)
113{
114 vmidi_devc *devc = midi_devs[dev]->devc;
115 if (devc == NULL)
116 return -ENXIO;
117
118 devc->intr_active = 0;
119 return 0;
120}
121
122/* why -EPERM and not -EINVAL?? */
123
124static inline int v_midi_ioctl (int dev, unsigned cmd, void __user *arg)
125{
126 return -EPERM;
127}
128
129
130#define MIDI_SYNTH_NAME "Loopback MIDI"
131#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
132
133#include "midi_synth.h"
134
135static struct midi_operations v_midi_operations =
136{
137 .owner = THIS_MODULE,
138 .info = {"Loopback MIDI Port 1", 0, 0, SNDCARD_VMIDI},
139 .converter = &std_midi_synth,
140 .in_info = {0},
141 .open = v_midi_open,
142 .close = v_midi_close,
143 .ioctl = v_midi_ioctl,
144 .outputc = v_midi_out,
145 .start_read = v_midi_start_read,
146 .end_read = v_midi_end_read,
147};
148
149static struct midi_operations v_midi_operations2 =
150{
151 .owner = THIS_MODULE,
152 .info = {"Loopback MIDI Port 2", 0, 0, SNDCARD_VMIDI},
153 .converter = &std_midi_synth,
154 .in_info = {0},
155 .open = v_midi_open,
156 .close = v_midi_close,
157 .ioctl = v_midi_ioctl,
158 .outputc = v_midi_out,
159 .start_read = v_midi_start_read,
160 .end_read = v_midi_end_read,
161};
162
163/*
164 * We kmalloc just one of these - it makes life simpler and the code
165 * cleaner and the memory handling far more efficient
166 */
167
168struct vmidi_memory
169{
170 /* Must be first */
171 struct midi_operations m_ops[2];
172 struct synth_operations s_ops[2];
173 struct vmidi_devc v_ops[2];
174};
175
176static void __init attach_v_midi (struct address_info *hw_config)
177{
178 struct vmidi_memory *m;
179 /* printk("Attaching v_midi device.....\n"); */
180
181 midi1 = sound_alloc_mididev();
182 if (midi1 == -1)
183 {
184 printk(KERN_ERR "v_midi: Too many midi devices detected\n");
185 return;
186 }
187
188 m=(struct vmidi_memory *)kmalloc(sizeof(struct vmidi_memory), GFP_KERNEL);
189 if (m == NULL)
190 {
191 printk(KERN_WARNING "Loopback MIDI: Failed to allocate memory\n");
192 sound_unload_mididev(midi1);
193 return;
194 }
195
196 midi_mem = m;
197
198 midi_devs[midi1] = &m->m_ops[0];
199
200
201 midi2 = sound_alloc_mididev();
202 if (midi2 == -1)
203 {
204 printk (KERN_ERR "v_midi: Too many midi devices detected\n");
205 kfree(m);
206 sound_unload_mididev(midi1);
207 return;
208 }
209
210 midi_devs[midi2] = &m->m_ops[1];
211
212 /* printk("VMIDI1: %d VMIDI2: %d\n",midi1,midi2); */
213
214 /* for MIDI-1 */
215 v_devc[0] = &m->v_ops[0];
216 memcpy ((char *) midi_devs[midi1], (char *) &v_midi_operations,
217 sizeof (struct midi_operations));
218
219 v_devc[0]->my_mididev = midi1;
220 v_devc[0]->pair_mididev = midi2;
221 v_devc[0]->opened = v_devc[0]->input_opened = 0;
222 v_devc[0]->intr_active = 0;
223 v_devc[0]->midi_input_intr = NULL;
224 spin_lock_init(&v_devc[0]->lock);
225
226 midi_devs[midi1]->devc = v_devc[0];
227
228 midi_devs[midi1]->converter = &m->s_ops[0];
229 std_midi_synth.midi_dev = midi1;
230 memcpy ((char *) midi_devs[midi1]->converter, (char *) &std_midi_synth,
231 sizeof (struct synth_operations));
232 midi_devs[midi1]->converter->id = "V_MIDI 1";
233
234 /* for MIDI-2 */
235 v_devc[1] = &m->v_ops[1];
236
237 memcpy ((char *) midi_devs[midi2], (char *) &v_midi_operations2,
238 sizeof (struct midi_operations));
239
240 v_devc[1]->my_mididev = midi2;
241 v_devc[1]->pair_mididev = midi1;
242 v_devc[1]->opened = v_devc[1]->input_opened = 0;
243 v_devc[1]->intr_active = 0;
244 v_devc[1]->midi_input_intr = NULL;
245 spin_lock_init(&v_devc[1]->lock);
246
247 midi_devs[midi2]->devc = v_devc[1];
248 midi_devs[midi2]->converter = &m->s_ops[1];
249
250 std_midi_synth.midi_dev = midi2;
251 memcpy ((char *) midi_devs[midi2]->converter, (char *) &std_midi_synth,
252 sizeof (struct synth_operations));
253 midi_devs[midi2]->converter->id = "V_MIDI 2";
254
255 sequencer_init();
256 /* printk("Attached v_midi device\n"); */
257}
258
259static inline int __init probe_v_midi(struct address_info *hw_config)
260{
261 return(1); /* always OK */
262}
263
264
265static void __exit unload_v_midi(struct address_info *hw_config)
266{
267 sound_unload_mididev(midi1);
268 sound_unload_mididev(midi2);
269 kfree(midi_mem);
270}
271
272static struct address_info cfg; /* dummy */
273
274static int __init init_vmidi(void)
275{
276 printk("MIDI Loopback device driver\n");
277 if (!probe_v_midi(&cfg))
278 return -ENODEV;
279 attach_v_midi(&cfg);
280
281 return 0;
282}
283
284static void __exit cleanup_vmidi(void)
285{
286 unload_v_midi(&cfg);
287}
288
289module_init(init_vmidi);
290module_exit(cleanup_vmidi);
291MODULE_LICENSE("GPL");
diff --git a/sound/oss/v_midi.h b/sound/oss/v_midi.h
new file mode 100644
index 000000000000..1b86cb45c607
--- /dev/null
+++ b/sound/oss/v_midi.h
@@ -0,0 +1,15 @@
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;
15
diff --git a/sound/oss/via82cxxx_audio.c b/sound/oss/via82cxxx_audio.c
new file mode 100644
index 000000000000..b387e1e52485
--- /dev/null
+++ b/sound/oss/via82cxxx_audio.c
@@ -0,0 +1,3615 @@
1/*
2 * Support for VIA 82Cxxx Audio Codecs
3 * Copyright 1999,2000 Jeff Garzik
4 *
5 * Updated to support the VIA 8233/8235 audio subsystem
6 * Alan Cox <alan@redhat.com> (C) Copyright 2002, 2003 Red Hat Inc
7 *
8 * Distributed under the GNU GENERAL PUBLIC LICENSE (GPL) Version 2.
9 * See the "COPYING" file distributed with this software for more info.
10 * NO WARRANTY
11 *
12 * For a list of known bugs (errata) and documentation,
13 * see via-audio.pdf in Documentation/DocBook.
14 * If this documentation does not exist, run "make pdfdocs".
15 */
16
17
18#define VIA_VERSION "1.9.1-ac4-2.5"
19
20
21#include <linux/config.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/fs.h>
25#include <linux/mm.h>
26#include <linux/pci.h>
27#include <linux/init.h>
28#include <linux/interrupt.h>
29#include <linux/proc_fs.h>
30#include <linux/spinlock.h>
31#include <linux/sound.h>
32#include <linux/poll.h>
33#include <linux/soundcard.h>
34#include <linux/ac97_codec.h>
35#include <linux/smp_lock.h>
36#include <linux/ioport.h>
37#include <linux/delay.h>
38#include <asm/io.h>
39#include <asm/uaccess.h>
40#include <asm/semaphore.h>
41#include "sound_config.h"
42#include "dev_table.h"
43#include "mpu401.h"
44
45
46#undef VIA_DEBUG /* define to enable debugging output and checks */
47#ifdef VIA_DEBUG
48/* note: prints function name for you */
49#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
50#else
51#define DPRINTK(fmt, args...)
52#endif
53
54#undef VIA_NDEBUG /* define to disable lightweight runtime checks */
55#ifdef VIA_NDEBUG
56#define assert(expr)
57#else
58#define assert(expr) \
59 if(!(expr)) { \
60 printk( "Assertion failed! %s,%s,%s,line=%d\n", \
61 #expr,__FILE__,__FUNCTION__,__LINE__); \
62 }
63#endif
64
65#define VIA_SUPPORT_MMAP 1 /* buggy, for now... */
66
67#define MAX_CARDS 1
68
69#define VIA_CARD_NAME "VIA 82Cxxx Audio driver " VIA_VERSION
70#define VIA_MODULE_NAME "via82cxxx"
71#define PFX VIA_MODULE_NAME ": "
72
73#define VIA_COUNTER_LIMIT 100000
74
75/* size of DMA buffers */
76#define VIA_MAX_BUFFER_DMA_PAGES 32
77
78/* buffering default values in ms */
79#define VIA_DEFAULT_FRAG_TIME 20
80#define VIA_DEFAULT_BUFFER_TIME 500
81
82/* the hardware has a 256 fragment limit */
83#define VIA_MIN_FRAG_NUMBER 2
84#define VIA_MAX_FRAG_NUMBER 128
85
86#define VIA_MAX_FRAG_SIZE PAGE_SIZE
87#define VIA_MIN_FRAG_SIZE (VIA_MAX_BUFFER_DMA_PAGES * PAGE_SIZE / VIA_MAX_FRAG_NUMBER)
88
89
90/* 82C686 function 5 (audio codec) PCI configuration registers */
91#define VIA_ACLINK_STATUS 0x40
92#define VIA_ACLINK_CTRL 0x41
93#define VIA_FUNC_ENABLE 0x42
94#define VIA_PNP_CONTROL 0x43
95#define VIA_FM_NMI_CTRL 0x48
96
97/*
98 * controller base 0 (scatter-gather) registers
99 *
100 * NOTE: Via datasheet lists first channel as "read"
101 * channel and second channel as "write" channel.
102 * I changed the naming of the constants to be more
103 * clear than I felt the datasheet to be.
104 */
105
106#define VIA_BASE0_PCM_OUT_CHAN 0x00 /* output PCM to user */
107#define VIA_BASE0_PCM_OUT_CHAN_STATUS 0x00
108#define VIA_BASE0_PCM_OUT_CHAN_CTRL 0x01
109#define VIA_BASE0_PCM_OUT_CHAN_TYPE 0x02
110
111#define VIA_BASE0_PCM_IN_CHAN 0x10 /* input PCM from user */
112#define VIA_BASE0_PCM_IN_CHAN_STATUS 0x10
113#define VIA_BASE0_PCM_IN_CHAN_CTRL 0x11
114#define VIA_BASE0_PCM_IN_CHAN_TYPE 0x12
115
116/* offsets from base */
117#define VIA_PCM_STATUS 0x00
118#define VIA_PCM_CONTROL 0x01
119#define VIA_PCM_TYPE 0x02
120#define VIA_PCM_LEFTVOL 0x02
121#define VIA_PCM_RIGHTVOL 0x03
122#define VIA_PCM_TABLE_ADDR 0x04
123#define VIA_PCM_STOPRATE 0x08 /* 8233+ */
124#define VIA_PCM_BLOCK_COUNT 0x0C
125
126/* XXX unused DMA channel for FM PCM data */
127#define VIA_BASE0_FM_OUT_CHAN 0x20
128#define VIA_BASE0_FM_OUT_CHAN_STATUS 0x20
129#define VIA_BASE0_FM_OUT_CHAN_CTRL 0x21
130#define VIA_BASE0_FM_OUT_CHAN_TYPE 0x22
131
132/* Six channel audio output on 8233 */
133#define VIA_BASE0_MULTI_OUT_CHAN 0x40
134#define VIA_BASE0_MULTI_OUT_CHAN_STATUS 0x40
135#define VIA_BASE0_MULTI_OUT_CHAN_CTRL 0x41
136#define VIA_BASE0_MULTI_OUT_CHAN_TYPE 0x42
137
138#define VIA_BASE0_AC97_CTRL 0x80
139#define VIA_BASE0_SGD_STATUS_SHADOW 0x84
140#define VIA_BASE0_GPI_INT_ENABLE 0x8C
141#define VIA_INTR_OUT ((1<<0) | (1<<4) | (1<<8))
142#define VIA_INTR_IN ((1<<1) | (1<<5) | (1<<9))
143#define VIA_INTR_FM ((1<<2) | (1<<6) | (1<<10))
144#define VIA_INTR_MASK (VIA_INTR_OUT | VIA_INTR_IN | VIA_INTR_FM)
145
146/* Newer VIA we need to monitor the low 3 bits of each channel. This
147 mask covers the channels we don't yet use as well
148 */
149
150#define VIA_NEW_INTR_MASK 0x77077777UL
151
152/* VIA_BASE0_AUDIO_xxx_CHAN_TYPE bits */
153#define VIA_IRQ_ON_FLAG (1<<0) /* int on each flagged scatter block */
154#define VIA_IRQ_ON_EOL (1<<1) /* int at end of scatter list */
155#define VIA_INT_SEL_PCI_LAST_LINE_READ (0) /* int at PCI read of last line */
156#define VIA_INT_SEL_LAST_SAMPLE_SENT (1<<2) /* int at last sample sent */
157#define VIA_INT_SEL_ONE_LINE_LEFT (1<<3) /* int at less than one line to send */
158#define VIA_PCM_FMT_STEREO (1<<4) /* PCM stereo format (bit clear == mono) */
159#define VIA_PCM_FMT_16BIT (1<<5) /* PCM 16-bit format (bit clear == 8-bit) */
160#define VIA_PCM_REC_FIFO (1<<6) /* PCM Recording FIFO */
161#define VIA_RESTART_SGD_ON_EOL (1<<7) /* restart scatter-gather at EOL */
162#define VIA_PCM_FMT_MASK (VIA_PCM_FMT_STEREO|VIA_PCM_FMT_16BIT)
163#define VIA_CHAN_TYPE_MASK (VIA_RESTART_SGD_ON_EOL | \
164 VIA_IRQ_ON_FLAG | \
165 VIA_IRQ_ON_EOL)
166#define VIA_CHAN_TYPE_INT_SELECT (VIA_INT_SEL_LAST_SAMPLE_SENT)
167
168/* PCI configuration register bits and masks */
169#define VIA_CR40_AC97_READY 0x01
170#define VIA_CR40_AC97_LOW_POWER 0x02
171#define VIA_CR40_SECONDARY_READY 0x04
172
173#define VIA_CR41_AC97_ENABLE 0x80 /* enable AC97 codec */
174#define VIA_CR41_AC97_RESET 0x40 /* clear bit to reset AC97 */
175#define VIA_CR41_AC97_WAKEUP 0x20 /* wake up from power-down mode */
176#define VIA_CR41_AC97_SDO 0x10 /* force Serial Data Out (SDO) high */
177#define VIA_CR41_VRA 0x08 /* enable variable sample rate */
178#define VIA_CR41_PCM_ENABLE 0x04 /* AC Link SGD Read Channel PCM Data Output */
179#define VIA_CR41_FM_PCM_ENABLE 0x02 /* AC Link FM Channel PCM Data Out */
180#define VIA_CR41_SB_PCM_ENABLE 0x01 /* AC Link SB PCM Data Output */
181#define VIA_CR41_BOOT_MASK (VIA_CR41_AC97_ENABLE | \
182 VIA_CR41_AC97_WAKEUP | \
183 VIA_CR41_AC97_SDO)
184#define VIA_CR41_RUN_MASK (VIA_CR41_AC97_ENABLE | \
185 VIA_CR41_AC97_RESET | \
186 VIA_CR41_VRA | \
187 VIA_CR41_PCM_ENABLE)
188
189#define VIA_CR42_SB_ENABLE 0x01
190#define VIA_CR42_MIDI_ENABLE 0x02
191#define VIA_CR42_FM_ENABLE 0x04
192#define VIA_CR42_GAME_ENABLE 0x08
193#define VIA_CR42_MIDI_IRQMASK 0x40
194#define VIA_CR42_MIDI_PNP 0x80
195
196#define VIA_CR44_SECOND_CODEC_SUPPORT (1 << 6)
197#define VIA_CR44_AC_LINK_ACCESS (1 << 7)
198
199#define VIA_CR48_FM_TRAP_TO_NMI (1 << 2)
200
201/* controller base 0 register bitmasks */
202#define VIA_INT_DISABLE_MASK (~(0x01|0x02))
203#define VIA_SGD_STOPPED (1 << 2)
204#define VIA_SGD_PAUSED (1 << 6)
205#define VIA_SGD_ACTIVE (1 << 7)
206#define VIA_SGD_TERMINATE (1 << 6)
207#define VIA_SGD_FLAG (1 << 0)
208#define VIA_SGD_EOL (1 << 1)
209#define VIA_SGD_START (1 << 7)
210
211#define VIA_CR80_FIRST_CODEC 0
212#define VIA_CR80_SECOND_CODEC (1 << 30)
213#define VIA_CR80_FIRST_CODEC_VALID (1 << 25)
214#define VIA_CR80_VALID (1 << 25)
215#define VIA_CR80_SECOND_CODEC_VALID (1 << 27)
216#define VIA_CR80_BUSY (1 << 24)
217#define VIA_CR83_BUSY (1)
218#define VIA_CR83_FIRST_CODEC_VALID (1 << 1)
219#define VIA_CR80_READ (1 << 23)
220#define VIA_CR80_WRITE_MODE 0
221#define VIA_CR80_REG_IDX(idx) ((((idx) & 0xFF) >> 1) << 16)
222
223/* capabilities we announce */
224#ifdef VIA_SUPPORT_MMAP
225#define VIA_DSP_CAP (DSP_CAP_REVISION | DSP_CAP_DUPLEX | DSP_CAP_MMAP | \
226 DSP_CAP_TRIGGER | DSP_CAP_REALTIME)
227#else
228#define VIA_DSP_CAP (DSP_CAP_REVISION | DSP_CAP_DUPLEX | \
229 DSP_CAP_TRIGGER | DSP_CAP_REALTIME)
230#endif
231
232/* scatter-gather DMA table entry, exactly as passed to hardware */
233struct via_sgd_table {
234 u32 addr;
235 u32 count; /* includes additional VIA_xxx bits also */
236};
237
238#define VIA_EOL (1 << 31)
239#define VIA_FLAG (1 << 30)
240#define VIA_STOP (1 << 29)
241
242
243enum via_channel_states {
244 sgd_stopped = 0,
245 sgd_in_progress = 1,
246};
247
248
249struct via_buffer_pgtbl {
250 dma_addr_t handle;
251 void *cpuaddr;
252};
253
254
255struct via_channel {
256 atomic_t n_frags;
257 atomic_t hw_ptr;
258 wait_queue_head_t wait;
259
260 unsigned int sw_ptr;
261 unsigned int slop_len;
262 unsigned int n_irqs;
263 int bytes;
264
265 unsigned is_active : 1;
266 unsigned is_record : 1;
267 unsigned is_mapped : 1;
268 unsigned is_enabled : 1;
269 unsigned is_multi: 1; /* 8233 6 channel */
270 u8 pcm_fmt; /* VIA_PCM_FMT_xxx */
271 u8 channels; /* Channel count */
272
273 unsigned rate; /* sample rate */
274 unsigned int frag_size;
275 unsigned int frag_number;
276
277 unsigned char intmask;
278
279 volatile struct via_sgd_table *sgtable;
280 dma_addr_t sgt_handle;
281
282 unsigned int page_number;
283 struct via_buffer_pgtbl pgtbl[VIA_MAX_BUFFER_DMA_PAGES];
284
285 long iobase;
286
287 const char *name;
288};
289
290
291/* data stored for each chip */
292struct via_info {
293 struct pci_dev *pdev;
294 long baseaddr;
295
296 struct ac97_codec *ac97;
297 spinlock_t ac97_lock;
298 spinlock_t lock;
299 int card_num; /* unique card number, from 0 */
300
301 int dev_dsp; /* /dev/dsp index from register_sound_dsp() */
302
303 unsigned rev_h : 1;
304 unsigned legacy: 1; /* Has legacy ports */
305 unsigned intmask: 1; /* Needs int bits */
306 unsigned sixchannel: 1; /* 8233/35 with 6 channel support */
307 unsigned volume: 1;
308
309 int locked_rate : 1;
310
311 int mixer_vol; /* 8233/35 volume - not yet implemented */
312
313 struct semaphore syscall_sem;
314 struct semaphore open_sem;
315
316 /* The 8233/8235 have 4 DX audio channels, two record and
317 one six channel out. We bind ch_in to DX 1, ch_out to multichannel
318 and ch_fm to DX 2. DX 3 and REC0/REC1 are unused at the
319 moment */
320
321 struct via_channel ch_in;
322 struct via_channel ch_out;
323 struct via_channel ch_fm;
324
325#ifdef CONFIG_MIDI_VIA82CXXX
326 void *midi_devc;
327 struct address_info midi_info;
328#endif
329};
330
331
332/* number of cards, used for assigning unique numbers to cards */
333static unsigned via_num_cards;
334
335
336
337/****************************************************************
338 *
339 * prototypes
340 *
341 *
342 */
343
344static int via_init_one (struct pci_dev *dev, const struct pci_device_id *id);
345static void __devexit via_remove_one (struct pci_dev *pdev);
346
347static ssize_t via_dsp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos);
348static ssize_t via_dsp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos);
349static unsigned int via_dsp_poll(struct file *file, struct poll_table_struct *wait);
350static int via_dsp_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
351static int via_dsp_open (struct inode *inode, struct file *file);
352static int via_dsp_release(struct inode *inode, struct file *file);
353static int via_dsp_mmap(struct file *file, struct vm_area_struct *vma);
354
355static u16 via_ac97_read_reg (struct ac97_codec *codec, u8 reg);
356static void via_ac97_write_reg (struct ac97_codec *codec, u8 reg, u16 value);
357static u8 via_ac97_wait_idle (struct via_info *card);
358
359static void via_chan_free (struct via_info *card, struct via_channel *chan);
360static void via_chan_clear (struct via_info *card, struct via_channel *chan);
361static void via_chan_pcm_fmt (struct via_channel *chan, int reset);
362static void via_chan_buffer_free (struct via_info *card, struct via_channel *chan);
363
364
365/****************************************************************
366 *
367 * Various data the driver needs
368 *
369 *
370 */
371
372
373static struct pci_device_id via_pci_tbl[] = {
374 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5,
375 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
376 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5,
377 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
378 { 0, }
379};
380MODULE_DEVICE_TABLE(pci,via_pci_tbl);
381
382
383static struct pci_driver via_driver = {
384 .name = VIA_MODULE_NAME,
385 .id_table = via_pci_tbl,
386 .probe = via_init_one,
387 .remove = __devexit_p(via_remove_one),
388};
389
390
391/****************************************************************
392 *
393 * Low-level base 0 register read/write helpers
394 *
395 *
396 */
397
398/**
399 * via_chan_stop - Terminate DMA on specified PCM channel
400 * @iobase: PCI base address for SGD channel registers
401 *
402 * Terminate scatter-gather DMA operation for given
403 * channel (derived from @iobase), if DMA is active.
404 *
405 * Note that @iobase is not the PCI base address,
406 * but the PCI base address plus an offset to
407 * one of three PCM channels supported by the chip.
408 *
409 */
410
411static inline void via_chan_stop (long iobase)
412{
413 if (inb (iobase + VIA_PCM_STATUS) & VIA_SGD_ACTIVE)
414 outb (VIA_SGD_TERMINATE, iobase + VIA_PCM_CONTROL);
415}
416
417
418/**
419 * via_chan_status_clear - Clear status flags on specified DMA channel
420 * @iobase: PCI base address for SGD channel registers
421 *
422 * Clear any pending status flags for the given
423 * DMA channel (derived from @iobase), if any
424 * flags are asserted.
425 *
426 * Note that @iobase is not the PCI base address,
427 * but the PCI base address plus an offset to
428 * one of three PCM channels supported by the chip.
429 *
430 */
431
432static inline void via_chan_status_clear (long iobase)
433{
434 u8 tmp = inb (iobase + VIA_PCM_STATUS);
435
436 if (tmp != 0)
437 outb (tmp, iobase + VIA_PCM_STATUS);
438}
439
440
441/**
442 * sg_begin - Begin recording or playback on a PCM channel
443 * @chan: Channel for which DMA operation shall begin
444 *
445 * Start scatter-gather DMA for the given channel.
446 *
447 */
448
449static inline void sg_begin (struct via_channel *chan)
450{
451 DPRINTK("Start with intmask %d\n", chan->intmask);
452 DPRINTK("About to start from %d to %d\n",
453 inl(chan->iobase + VIA_PCM_BLOCK_COUNT),
454 inb(chan->iobase + VIA_PCM_STOPRATE + 3));
455 outb (VIA_SGD_START|chan->intmask, chan->iobase + VIA_PCM_CONTROL);
456 DPRINTK("Status is now %02X\n", inb(chan->iobase + VIA_PCM_STATUS));
457 DPRINTK("Control is now %02X\n", inb(chan->iobase + VIA_PCM_CONTROL));
458}
459
460
461static int sg_active (long iobase)
462{
463 u8 tmp = inb (iobase + VIA_PCM_STATUS);
464 if ((tmp & VIA_SGD_STOPPED) || (tmp & VIA_SGD_PAUSED)) {
465 printk(KERN_WARNING "via82cxxx warning: SG stopped or paused\n");
466 return 0;
467 }
468 if (tmp & VIA_SGD_ACTIVE)
469 return 1;
470 return 0;
471}
472
473static int via_sg_offset(struct via_channel *chan)
474{
475 return inl (chan->iobase + VIA_PCM_BLOCK_COUNT) & 0x00FFFFFF;
476}
477
478/****************************************************************
479 *
480 * Miscellaneous debris
481 *
482 *
483 */
484
485
486/**
487 * via_syscall_down - down the card-specific syscell semaphore
488 * @card: Private info for specified board
489 * @nonblock: boolean, non-zero if O_NONBLOCK is set
490 *
491 * Encapsulates standard method of acquiring the syscall sem.
492 *
493 * Returns negative errno on error, or zero for success.
494 */
495
496static inline int via_syscall_down (struct via_info *card, int nonblock)
497{
498 /* Thomas Sailer:
499 * EAGAIN is supposed to be used if IO is pending,
500 * not if there is contention on some internal
501 * synchronization primitive which should be
502 * held only for a short time anyway
503 */
504 nonblock = 0;
505
506 if (nonblock) {
507 if (down_trylock (&card->syscall_sem))
508 return -EAGAIN;
509 } else {
510 if (down_interruptible (&card->syscall_sem))
511 return -ERESTARTSYS;
512 }
513
514 return 0;
515}
516
517
518/**
519 * via_stop_everything - Stop all audio operations
520 * @card: Private info for specified board
521 *
522 * Stops all DMA operations and interrupts, and clear
523 * any pending status bits resulting from those operations.
524 */
525
526static void via_stop_everything (struct via_info *card)
527{
528 u8 tmp, new_tmp;
529
530 DPRINTK ("ENTER\n");
531
532 assert (card != NULL);
533
534 /*
535 * terminate any existing operations on audio read/write channels
536 */
537 via_chan_stop (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN);
538 via_chan_stop (card->baseaddr + VIA_BASE0_PCM_IN_CHAN);
539 via_chan_stop (card->baseaddr + VIA_BASE0_FM_OUT_CHAN);
540 if(card->sixchannel)
541 via_chan_stop (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN);
542
543 /*
544 * clear any existing stops / flags (sanity check mainly)
545 */
546 via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN);
547 via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_IN_CHAN);
548 via_chan_status_clear (card->baseaddr + VIA_BASE0_FM_OUT_CHAN);
549 if(card->sixchannel)
550 via_chan_status_clear (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN);
551
552 /*
553 * clear any enabled interrupt bits
554 */
555 tmp = inb (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN_TYPE);
556 new_tmp = tmp & ~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL);
557 if (tmp != new_tmp)
558 outb (0, card->baseaddr + VIA_BASE0_PCM_OUT_CHAN_TYPE);
559
560 tmp = inb (card->baseaddr + VIA_BASE0_PCM_IN_CHAN_TYPE);
561 new_tmp = tmp & ~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL);
562 if (tmp != new_tmp)
563 outb (0, card->baseaddr + VIA_BASE0_PCM_IN_CHAN_TYPE);
564
565 tmp = inb (card->baseaddr + VIA_BASE0_FM_OUT_CHAN_TYPE);
566 new_tmp = tmp & ~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL);
567 if (tmp != new_tmp)
568 outb (0, card->baseaddr + VIA_BASE0_FM_OUT_CHAN_TYPE);
569
570 if(card->sixchannel)
571 {
572 tmp = inb (card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN_TYPE);
573 new_tmp = tmp & ~(VIA_IRQ_ON_FLAG|VIA_IRQ_ON_EOL|VIA_RESTART_SGD_ON_EOL);
574 if (tmp != new_tmp)
575 outb (0, card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN_TYPE);
576 }
577
578 udelay(10);
579
580 /*
581 * clear any existing flags
582 */
583 via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_OUT_CHAN);
584 via_chan_status_clear (card->baseaddr + VIA_BASE0_PCM_IN_CHAN);
585 via_chan_status_clear (card->baseaddr + VIA_BASE0_FM_OUT_CHAN);
586
587 DPRINTK ("EXIT\n");
588}
589
590
591/**
592 * via_set_rate - Set PCM rate for given channel
593 * @ac97: Pointer to generic codec info struct
594 * @chan: Private info for specified channel
595 * @rate: Desired PCM sample rate, in Khz
596 *
597 * Sets the PCM sample rate for a channel.
598 *
599 * Values for @rate are clamped to a range of 4000 Khz through 48000 Khz,
600 * due to hardware constraints.
601 */
602
603static int via_set_rate (struct ac97_codec *ac97,
604 struct via_channel *chan, unsigned rate)
605{
606 struct via_info *card = ac97->private_data;
607 int rate_reg;
608 u32 dacp;
609 u32 mast_vol, phone_vol, mono_vol, pcm_vol;
610 u32 mute_vol = 0x8000; /* The mute volume? -- Seems to work! */
611
612 DPRINTK ("ENTER, rate = %d\n", rate);
613
614 if (chan->rate == rate)
615 goto out;
616 if (card->locked_rate) {
617 chan->rate = 48000;
618 goto out;
619 }
620
621 if (rate > 48000) rate = 48000;
622 if (rate < 4000) rate = 4000;
623
624 rate_reg = chan->is_record ? AC97_PCM_LR_ADC_RATE :
625 AC97_PCM_FRONT_DAC_RATE;
626
627 /* Save current state */
628 dacp=via_ac97_read_reg(ac97, AC97_POWER_CONTROL);
629 mast_vol = via_ac97_read_reg(ac97, AC97_MASTER_VOL_STEREO);
630 mono_vol = via_ac97_read_reg(ac97, AC97_MASTER_VOL_MONO);
631 phone_vol = via_ac97_read_reg(ac97, AC97_HEADPHONE_VOL);
632 pcm_vol = via_ac97_read_reg(ac97, AC97_PCMOUT_VOL);
633 /* Mute - largely reduces popping */
634 via_ac97_write_reg(ac97, AC97_MASTER_VOL_STEREO, mute_vol);
635 via_ac97_write_reg(ac97, AC97_MASTER_VOL_MONO, mute_vol);
636 via_ac97_write_reg(ac97, AC97_HEADPHONE_VOL, mute_vol);
637 via_ac97_write_reg(ac97, AC97_PCMOUT_VOL, mute_vol);
638 /* Power down the DAC */
639 via_ac97_write_reg(ac97, AC97_POWER_CONTROL, dacp|0x0200);
640
641 /* Set new rate */
642 via_ac97_write_reg (ac97, rate_reg, rate);
643
644 /* Power DAC back up */
645 via_ac97_write_reg(ac97, AC97_POWER_CONTROL, dacp);
646 udelay (200); /* reduces popping */
647
648 /* Restore volumes */
649 via_ac97_write_reg(ac97, AC97_MASTER_VOL_STEREO, mast_vol);
650 via_ac97_write_reg(ac97, AC97_MASTER_VOL_MONO, mono_vol);
651 via_ac97_write_reg(ac97, AC97_HEADPHONE_VOL, phone_vol);
652 via_ac97_write_reg(ac97, AC97_PCMOUT_VOL, pcm_vol);
653
654 /* the hardware might return a value different than what we
655 * passed to it, so read the rate value back from hardware
656 * to see what we came up with
657 */
658 chan->rate = via_ac97_read_reg (ac97, rate_reg);
659
660 if (chan->rate == 0) {
661 card->locked_rate = 1;
662 chan->rate = 48000;
663 printk (KERN_WARNING PFX "Codec rate locked at 48Khz\n");
664 }
665
666out:
667 DPRINTK ("EXIT, returning rate %d Hz\n", chan->rate);
668 return chan->rate;
669}
670
671
672/****************************************************************
673 *
674 * Channel-specific operations
675 *
676 *
677 */
678
679
680/**
681 * via_chan_init_defaults - Initialize a struct via_channel
682 * @card: Private audio chip info
683 * @chan: Channel to be initialized
684 *
685 * Zero @chan, and then set all static defaults for the structure.
686 */
687
688static void via_chan_init_defaults (struct via_info *card, struct via_channel *chan)
689{
690 memset (chan, 0, sizeof (*chan));
691
692 if(card->intmask)
693 chan->intmask = 0x23; /* Turn on the IRQ bits */
694
695 if (chan == &card->ch_out) {
696 chan->name = "PCM-OUT";
697 if(card->sixchannel)
698 {
699 chan->iobase = card->baseaddr + VIA_BASE0_MULTI_OUT_CHAN;
700 chan->is_multi = 1;
701 DPRINTK("Using multichannel for pcm out\n");
702 }
703 else
704 chan->iobase = card->baseaddr + VIA_BASE0_PCM_OUT_CHAN;
705 } else if (chan == &card->ch_in) {
706 chan->name = "PCM-IN";
707 chan->iobase = card->baseaddr + VIA_BASE0_PCM_IN_CHAN;
708 chan->is_record = 1;
709 } else if (chan == &card->ch_fm) {
710 chan->name = "PCM-OUT-FM";
711 chan->iobase = card->baseaddr + VIA_BASE0_FM_OUT_CHAN;
712 } else {
713 BUG();
714 }
715
716 init_waitqueue_head (&chan->wait);
717
718 chan->pcm_fmt = VIA_PCM_FMT_MASK;
719 chan->is_enabled = 1;
720
721 chan->frag_number = 0;
722 chan->frag_size = 0;
723 atomic_set(&chan->n_frags, 0);
724 atomic_set (&chan->hw_ptr, 0);
725}
726
727/**
728 * via_chan_init - Initialize PCM channel
729 * @card: Private audio chip info
730 * @chan: Channel to be initialized
731 *
732 * Performs some of the preparations necessary to begin
733 * using a PCM channel.
734 *
735 * Currently the preparations consist of
736 * setting the PCM channel to a known state.
737 */
738
739
740static void via_chan_init (struct via_info *card, struct via_channel *chan)
741{
742
743 DPRINTK ("ENTER\n");
744
745 /* bzero channel structure, and init members to defaults */
746 via_chan_init_defaults (card, chan);
747
748 /* stop any existing channel output */
749 via_chan_clear (card, chan);
750 via_chan_status_clear (chan->iobase);
751 via_chan_pcm_fmt (chan, 1);
752
753 DPRINTK ("EXIT\n");
754}
755
756/**
757 * via_chan_buffer_init - Initialize PCM channel buffer
758 * @card: Private audio chip info
759 * @chan: Channel to be initialized
760 *
761 * Performs some of the preparations necessary to begin
762 * using a PCM channel.
763 *
764 * Currently the preparations include allocating the
765 * scatter-gather DMA table and buffers,
766 * and passing the
767 * address of the DMA table to the hardware.
768 *
769 * Note that special care is taken when passing the
770 * DMA table address to hardware, because it was found
771 * during driver development that the hardware did not
772 * always "take" the address.
773 */
774
775static int via_chan_buffer_init (struct via_info *card, struct via_channel *chan)
776{
777 int page, offset;
778 int i;
779
780 DPRINTK ("ENTER\n");
781
782
783 chan->intmask = 0;
784 if(card->intmask)
785 chan->intmask = 0x23; /* Turn on the IRQ bits */
786
787 if (chan->sgtable != NULL) {
788 DPRINTK ("EXIT\n");
789 return 0;
790 }
791
792 /* alloc DMA-able memory for scatter-gather table */
793 chan->sgtable = pci_alloc_consistent (card->pdev,
794 (sizeof (struct via_sgd_table) * chan->frag_number),
795 &chan->sgt_handle);
796 if (!chan->sgtable) {
797 printk (KERN_ERR PFX "DMA table alloc fail, aborting\n");
798 DPRINTK ("EXIT\n");
799 return -ENOMEM;
800 }
801
802 memset ((void*)chan->sgtable, 0,
803 (sizeof (struct via_sgd_table) * chan->frag_number));
804
805 /* alloc DMA-able memory for scatter-gather buffers */
806
807 chan->page_number = (chan->frag_number * chan->frag_size) / PAGE_SIZE +
808 (((chan->frag_number * chan->frag_size) % PAGE_SIZE) ? 1 : 0);
809
810 for (i = 0; i < chan->page_number; i++) {
811 chan->pgtbl[i].cpuaddr = pci_alloc_consistent (card->pdev, PAGE_SIZE,
812 &chan->pgtbl[i].handle);
813
814 if (!chan->pgtbl[i].cpuaddr) {
815 chan->page_number = i;
816 goto err_out_nomem;
817 }
818
819#ifndef VIA_NDEBUG
820 memset (chan->pgtbl[i].cpuaddr, 0xBC, chan->frag_size);
821#endif
822
823#if 1
824 DPRINTK ("dmabuf_pg #%d (h=%lx, v2p=%lx, a=%p)\n",
825 i, (long)chan->pgtbl[i].handle,
826 virt_to_phys(chan->pgtbl[i].cpuaddr),
827 chan->pgtbl[i].cpuaddr);
828#endif
829 }
830
831 for (i = 0; i < chan->frag_number; i++) {
832
833 page = i / (PAGE_SIZE / chan->frag_size);
834 offset = (i % (PAGE_SIZE / chan->frag_size)) * chan->frag_size;
835
836 chan->sgtable[i].count = cpu_to_le32 (chan->frag_size | VIA_FLAG);
837 chan->sgtable[i].addr = cpu_to_le32 (chan->pgtbl[page].handle + offset);
838
839#if 1
840 DPRINTK ("dmabuf #%d (32(h)=%lx)\n",
841 i,
842 (long)chan->sgtable[i].addr);
843#endif
844 }
845
846 /* overwrite the last buffer information */
847 chan->sgtable[chan->frag_number - 1].count = cpu_to_le32 (chan->frag_size | VIA_EOL);
848
849 /* set location of DMA-able scatter-gather info table */
850 DPRINTK ("outl (0x%X, 0x%04lX)\n",
851 chan->sgt_handle, chan->iobase + VIA_PCM_TABLE_ADDR);
852
853 via_ac97_wait_idle (card);
854 outl (chan->sgt_handle, chan->iobase + VIA_PCM_TABLE_ADDR);
855 udelay (20);
856 via_ac97_wait_idle (card);
857 /* load no rate adaption, stereo 16bit, set up ring slots */
858 if(card->sixchannel)
859 {
860 if(!chan->is_multi)
861 {
862 outl (0xFFFFF | (0x3 << 20) | (chan->frag_number << 24), chan->iobase + VIA_PCM_STOPRATE);
863 udelay (20);
864 via_ac97_wait_idle (card);
865 }
866 }
867
868 DPRINTK ("inl (0x%lX) = %x\n",
869 chan->iobase + VIA_PCM_TABLE_ADDR,
870 inl(chan->iobase + VIA_PCM_TABLE_ADDR));
871
872 DPRINTK ("EXIT\n");
873 return 0;
874
875err_out_nomem:
876 printk (KERN_ERR PFX "DMA buffer alloc fail, aborting\n");
877 via_chan_buffer_free (card, chan);
878 DPRINTK ("EXIT\n");
879 return -ENOMEM;
880}
881
882
883/**
884 * via_chan_free - Release a PCM channel
885 * @card: Private audio chip info
886 * @chan: Channel to be released
887 *
888 * Performs all the functions necessary to clean up
889 * an initialized channel.
890 *
891 * Currently these functions include disabled any
892 * active DMA operations, setting the PCM channel
893 * back to a known state, and releasing any allocated
894 * sound buffers.
895 */
896
897static void via_chan_free (struct via_info *card, struct via_channel *chan)
898{
899 DPRINTK ("ENTER\n");
900
901 spin_lock_irq (&card->lock);
902
903 /* stop any existing channel output */
904 via_chan_status_clear (chan->iobase);
905 via_chan_stop (chan->iobase);
906 via_chan_status_clear (chan->iobase);
907
908 spin_unlock_irq (&card->lock);
909
910 synchronize_irq(card->pdev->irq);
911
912 DPRINTK ("EXIT\n");
913}
914
915static void via_chan_buffer_free (struct via_info *card, struct via_channel *chan)
916{
917 int i;
918
919 DPRINTK ("ENTER\n");
920
921 /* zero location of DMA-able scatter-gather info table */
922 via_ac97_wait_idle(card);
923 outl (0, chan->iobase + VIA_PCM_TABLE_ADDR);
924
925 for (i = 0; i < chan->page_number; i++)
926 if (chan->pgtbl[i].cpuaddr) {
927 pci_free_consistent (card->pdev, PAGE_SIZE,
928 chan->pgtbl[i].cpuaddr,
929 chan->pgtbl[i].handle);
930 chan->pgtbl[i].cpuaddr = NULL;
931 chan->pgtbl[i].handle = 0;
932 }
933
934 chan->page_number = 0;
935
936 if (chan->sgtable) {
937 pci_free_consistent (card->pdev,
938 (sizeof (struct via_sgd_table) * chan->frag_number),
939 (void*)chan->sgtable, chan->sgt_handle);
940 chan->sgtable = NULL;
941 }
942
943 DPRINTK ("EXIT\n");
944}
945
946
947/**
948 * via_chan_pcm_fmt - Update PCM channel settings
949 * @chan: Channel to be updated
950 * @reset: Boolean. If non-zero, channel will be reset
951 * to 8-bit mono mode.
952 *
953 * Stores the settings of the current PCM format,
954 * 8-bit or 16-bit, and mono/stereo, into the
955 * hardware settings for the specified channel.
956 * If @reset is non-zero, the channel is reset
957 * to 8-bit mono mode. Otherwise, the channel
958 * is set to the values stored in the channel
959 * information struct @chan.
960 */
961
962static void via_chan_pcm_fmt (struct via_channel *chan, int reset)
963{
964 DPRINTK ("ENTER, pcm_fmt=0x%02X, reset=%s\n",
965 chan->pcm_fmt, reset ? "yes" : "no");
966
967 assert (chan != NULL);
968
969 if (reset)
970 {
971 /* reset to 8-bit mono mode */
972 chan->pcm_fmt = 0;
973 chan->channels = 1;
974 }
975
976 /* enable interrupts on FLAG and EOL */
977 chan->pcm_fmt |= VIA_CHAN_TYPE_MASK;
978
979 /* if we are recording, enable recording fifo bit */
980 if (chan->is_record)
981 chan->pcm_fmt |= VIA_PCM_REC_FIFO;
982 /* set interrupt select bits where applicable (PCM in & out channels) */
983 if (!chan->is_record)
984 chan->pcm_fmt |= VIA_CHAN_TYPE_INT_SELECT;
985
986 DPRINTK("SET FMT - %02x %02x\n", chan->intmask , chan->is_multi);
987
988 if(chan->intmask)
989 {
990 u32 m;
991
992 /*
993 * Channel 0x4 is up to 6 x 16bit and has to be
994 * programmed differently
995 */
996
997 if(chan->is_multi)
998 {
999 u8 c = 0;
1000
1001 /*
1002 * Load the type bit for num channels
1003 * and 8/16bit
1004 */
1005
1006 if(chan->pcm_fmt & VIA_PCM_FMT_16BIT)
1007 c = 1 << 7;
1008 if(chan->pcm_fmt & VIA_PCM_FMT_STEREO)
1009 c |= (2<<4);
1010 else
1011 c |= (1<<4);
1012
1013 outb(c, chan->iobase + VIA_PCM_TYPE);
1014
1015 /*
1016 * Set the channel steering
1017 * Mono
1018 * Channel 0 to slot 3
1019 * Channel 0 to slot 4
1020 * Stereo
1021 * Channel 0 to slot 3
1022 * Channel 1 to slot 4
1023 */
1024
1025 switch(chan->channels)
1026 {
1027 case 1:
1028 outl(0xFF000000 | (1<<0) | (1<<4) , chan->iobase + VIA_PCM_STOPRATE);
1029 break;
1030 case 2:
1031 outl(0xFF000000 | (1<<0) | (2<<4) , chan->iobase + VIA_PCM_STOPRATE);
1032 break;
1033 case 4:
1034 outl(0xFF000000 | (1<<0) | (2<<4) | (3<<8) | (4<<12), chan->iobase + VIA_PCM_STOPRATE);
1035 break;
1036 case 6:
1037 outl(0xFF000000 | (1<<0) | (2<<4) | (5<<8) | (6<<12) | (3<<16) | (4<<20), chan->iobase + VIA_PCM_STOPRATE);
1038 break;
1039 }
1040 }
1041 else
1042 {
1043 /*
1044 * New style, turn off channel volume
1045 * control, set bits in the right register
1046 */
1047 outb(0x0, chan->iobase + VIA_PCM_LEFTVOL);
1048 outb(0x0, chan->iobase + VIA_PCM_RIGHTVOL);
1049
1050 m = inl(chan->iobase + VIA_PCM_STOPRATE);
1051 m &= ~(3<<20);
1052 if(chan->pcm_fmt & VIA_PCM_FMT_STEREO)
1053 m |= (1 << 20);
1054 if(chan->pcm_fmt & VIA_PCM_FMT_16BIT)
1055 m |= (1 << 21);
1056 outl(m, chan->iobase + VIA_PCM_STOPRATE);
1057 }
1058 }
1059 else
1060 outb (chan->pcm_fmt, chan->iobase + VIA_PCM_TYPE);
1061
1062
1063 DPRINTK ("EXIT, pcm_fmt = 0x%02X, reg = 0x%02X\n",
1064 chan->pcm_fmt,
1065 inb (chan->iobase + VIA_PCM_TYPE));
1066}
1067
1068
1069/**
1070 * via_chan_clear - Stop DMA channel operation, and reset pointers
1071 * @card: the chip to accessed
1072 * @chan: Channel to be cleared
1073 *
1074 * Call via_chan_stop to halt DMA operations, and then resets
1075 * all software pointers which track DMA operation.
1076 */
1077
1078static void via_chan_clear (struct via_info *card, struct via_channel *chan)
1079{
1080 DPRINTK ("ENTER\n");
1081 via_chan_stop (chan->iobase);
1082 via_chan_buffer_free(card, chan);
1083 chan->is_active = 0;
1084 chan->is_mapped = 0;
1085 chan->is_enabled = 1;
1086 chan->slop_len = 0;
1087 chan->sw_ptr = 0;
1088 chan->n_irqs = 0;
1089 atomic_set (&chan->hw_ptr, 0);
1090 DPRINTK ("EXIT\n");
1091}
1092
1093
1094/**
1095 * via_chan_set_speed - Set PCM sample rate for given channel
1096 * @card: Private info for specified board
1097 * @chan: Channel whose sample rate will be adjusted
1098 * @val: New sample rate, in Khz
1099 *
1100 * Helper function for the %SNDCTL_DSP_SPEED ioctl. OSS semantics
1101 * demand that all audio operations halt (if they are not already
1102 * halted) when the %SNDCTL_DSP_SPEED is given.
1103 *
1104 * This function halts all audio operations for the given channel
1105 * @chan, and then calls via_set_rate to set the audio hardware
1106 * to the new rate.
1107 */
1108
1109static int via_chan_set_speed (struct via_info *card,
1110 struct via_channel *chan, int val)
1111{
1112 DPRINTK ("ENTER, requested rate = %d\n", val);
1113
1114 via_chan_clear (card, chan);
1115
1116 val = via_set_rate (card->ac97, chan, val);
1117
1118 DPRINTK ("EXIT, returning %d\n", val);
1119 return val;
1120}
1121
1122
1123/**
1124 * via_chan_set_fmt - Set PCM sample size for given channel
1125 * @card: Private info for specified board
1126 * @chan: Channel whose sample size will be adjusted
1127 * @val: New sample size, use the %AFMT_xxx constants
1128 *
1129 * Helper function for the %SNDCTL_DSP_SETFMT ioctl. OSS semantics
1130 * demand that all audio operations halt (if they are not already
1131 * halted) when the %SNDCTL_DSP_SETFMT is given.
1132 *
1133 * This function halts all audio operations for the given channel
1134 * @chan, and then calls via_chan_pcm_fmt to set the audio hardware
1135 * to the new sample size, either 8-bit or 16-bit.
1136 */
1137
1138static int via_chan_set_fmt (struct via_info *card,
1139 struct via_channel *chan, int val)
1140{
1141 DPRINTK ("ENTER, val=%s\n",
1142 val == AFMT_U8 ? "AFMT_U8" :
1143 val == AFMT_S16_LE ? "AFMT_S16_LE" :
1144 "unknown");
1145
1146 via_chan_clear (card, chan);
1147
1148 assert (val != AFMT_QUERY); /* this case is handled elsewhere */
1149
1150 switch (val) {
1151 case AFMT_S16_LE:
1152 if ((chan->pcm_fmt & VIA_PCM_FMT_16BIT) == 0) {
1153 chan->pcm_fmt |= VIA_PCM_FMT_16BIT;
1154 via_chan_pcm_fmt (chan, 0);
1155 }
1156 break;
1157
1158 case AFMT_U8:
1159 if (chan->pcm_fmt & VIA_PCM_FMT_16BIT) {
1160 chan->pcm_fmt &= ~VIA_PCM_FMT_16BIT;
1161 via_chan_pcm_fmt (chan, 0);
1162 }
1163 break;
1164
1165 default:
1166 DPRINTK ("unknown AFMT: 0x%X\n", val);
1167 val = AFMT_S16_LE;
1168 }
1169
1170 DPRINTK ("EXIT\n");
1171 return val;
1172}
1173
1174
1175/**
1176 * via_chan_set_stereo - Enable or disable stereo for a DMA channel
1177 * @card: Private info for specified board
1178 * @chan: Channel whose stereo setting will be adjusted
1179 * @val: New sample size, use the %AFMT_xxx constants
1180 *
1181 * Helper function for the %SNDCTL_DSP_CHANNELS and %SNDCTL_DSP_STEREO ioctls. OSS semantics
1182 * demand that all audio operations halt (if they are not already
1183 * halted) when %SNDCTL_DSP_CHANNELS or SNDCTL_DSP_STEREO is given.
1184 *
1185 * This function halts all audio operations for the given channel
1186 * @chan, and then calls via_chan_pcm_fmt to set the audio hardware
1187 * to enable or disable stereo.
1188 */
1189
1190static int via_chan_set_stereo (struct via_info *card,
1191 struct via_channel *chan, int val)
1192{
1193 DPRINTK ("ENTER, channels = %d\n", val);
1194
1195 via_chan_clear (card, chan);
1196
1197 switch (val) {
1198
1199 /* mono */
1200 case 1:
1201 chan->pcm_fmt &= ~VIA_PCM_FMT_STEREO;
1202 chan->channels = 1;
1203 via_chan_pcm_fmt (chan, 0);
1204 break;
1205
1206 /* stereo */
1207 case 2:
1208 chan->pcm_fmt |= VIA_PCM_FMT_STEREO;
1209 chan->channels = 2;
1210 via_chan_pcm_fmt (chan, 0);
1211 break;
1212
1213 case 4:
1214 case 6:
1215 if(chan->is_multi)
1216 {
1217 chan->pcm_fmt |= VIA_PCM_FMT_STEREO;
1218 chan->channels = val;
1219 break;
1220 }
1221 /* unknown */
1222 default:
1223 val = -EINVAL;
1224 break;
1225 }
1226
1227 DPRINTK ("EXIT, returning %d\n", val);
1228 return val;
1229}
1230
1231static int via_chan_set_buffering (struct via_info *card,
1232 struct via_channel *chan, int val)
1233{
1234 int shift;
1235
1236 DPRINTK ("ENTER\n");
1237
1238 /* in both cases the buffer cannot be changed */
1239 if (chan->is_active || chan->is_mapped) {
1240 DPRINTK ("EXIT\n");
1241 return -EINVAL;
1242 }
1243
1244 /* called outside SETFRAGMENT */
1245 /* set defaults or do nothing */
1246 if (val < 0) {
1247
1248 if (chan->frag_size && chan->frag_number)
1249 goto out;
1250
1251 DPRINTK ("\n");
1252
1253 chan->frag_size = (VIA_DEFAULT_FRAG_TIME * chan->rate * chan->channels
1254 * ((chan->pcm_fmt & VIA_PCM_FMT_16BIT) ? 2 : 1)) / 1000 - 1;
1255
1256 shift = 0;
1257 while (chan->frag_size) {
1258 chan->frag_size >>= 1;
1259 shift++;
1260 }
1261 chan->frag_size = 1 << shift;
1262
1263 chan->frag_number = (VIA_DEFAULT_BUFFER_TIME / VIA_DEFAULT_FRAG_TIME);
1264
1265 DPRINTK ("setting default values %d %d\n", chan->frag_size, chan->frag_number);
1266 } else {
1267 chan->frag_size = 1 << (val & 0xFFFF);
1268 chan->frag_number = (val >> 16) & 0xFFFF;
1269
1270 DPRINTK ("using user values %d %d\n", chan->frag_size, chan->frag_number);
1271 }
1272
1273 /* quake3 wants frag_number to be a power of two */
1274 shift = 0;
1275 while (chan->frag_number) {
1276 chan->frag_number >>= 1;
1277 shift++;
1278 }
1279 chan->frag_number = 1 << shift;
1280
1281 if (chan->frag_size > VIA_MAX_FRAG_SIZE)
1282 chan->frag_size = VIA_MAX_FRAG_SIZE;
1283 else if (chan->frag_size < VIA_MIN_FRAG_SIZE)
1284 chan->frag_size = VIA_MIN_FRAG_SIZE;
1285
1286 if (chan->frag_number < VIA_MIN_FRAG_NUMBER)
1287 chan->frag_number = VIA_MIN_FRAG_NUMBER;
1288 if (chan->frag_number > VIA_MAX_FRAG_NUMBER)
1289 chan->frag_number = VIA_MAX_FRAG_NUMBER;
1290
1291 if ((chan->frag_number * chan->frag_size) / PAGE_SIZE > VIA_MAX_BUFFER_DMA_PAGES)
1292 chan->frag_number = (VIA_MAX_BUFFER_DMA_PAGES * PAGE_SIZE) / chan->frag_size;
1293
1294out:
1295 if (chan->is_record)
1296 atomic_set (&chan->n_frags, 0);
1297 else
1298 atomic_set (&chan->n_frags, chan->frag_number);
1299
1300 DPRINTK ("EXIT\n");
1301
1302 return 0;
1303}
1304
1305#ifdef VIA_CHAN_DUMP_BUFS
1306/**
1307 * via_chan_dump_bufs - Display DMA table contents
1308 * @chan: Channel whose DMA table will be displayed
1309 *
1310 * Debugging function which displays the contents of the
1311 * scatter-gather DMA table for the given channel @chan.
1312 */
1313
1314static void via_chan_dump_bufs (struct via_channel *chan)
1315{
1316 int i;
1317
1318 for (i = 0; i < chan->frag_number; i++) {
1319 DPRINTK ("#%02d: addr=%x, count=%u, flag=%d, eol=%d\n",
1320 i, chan->sgtable[i].addr,
1321 chan->sgtable[i].count & 0x00FFFFFF,
1322 chan->sgtable[i].count & VIA_FLAG ? 1 : 0,
1323 chan->sgtable[i].count & VIA_EOL ? 1 : 0);
1324 }
1325 DPRINTK ("buf_in_use = %d, nextbuf = %d\n",
1326 atomic_read (&chan->buf_in_use),
1327 atomic_read (&chan->sw_ptr));
1328}
1329#endif /* VIA_CHAN_DUMP_BUFS */
1330
1331
1332/**
1333 * via_chan_flush_frag - Flush partially-full playback buffer to hardware
1334 * @chan: Channel whose DMA table will be flushed
1335 *
1336 * Flushes partially-full playback buffer to hardware.
1337 */
1338
1339static void via_chan_flush_frag (struct via_channel *chan)
1340{
1341 DPRINTK ("ENTER\n");
1342
1343 assert (chan->slop_len > 0);
1344
1345 if (chan->sw_ptr == (chan->frag_number - 1))
1346 chan->sw_ptr = 0;
1347 else
1348 chan->sw_ptr++;
1349
1350 chan->slop_len = 0;
1351
1352 assert (atomic_read (&chan->n_frags) > 0);
1353 atomic_dec (&chan->n_frags);
1354
1355 DPRINTK ("EXIT\n");
1356}
1357
1358
1359
1360/**
1361 * via_chan_maybe_start - Initiate audio hardware DMA operation
1362 * @chan: Channel whose DMA is to be started
1363 *
1364 * Initiate DMA operation, if the DMA engine for the given
1365 * channel @chan is not already active.
1366 */
1367
1368static inline void via_chan_maybe_start (struct via_channel *chan)
1369{
1370 assert (chan->is_active == sg_active(chan->iobase));
1371
1372 DPRINTK ("MAYBE START %s\n", chan->name);
1373 if (!chan->is_active && chan->is_enabled) {
1374 chan->is_active = 1;
1375 sg_begin (chan);
1376 DPRINTK ("starting channel %s\n", chan->name);
1377 }
1378}
1379
1380
1381/****************************************************************
1382 *
1383 * Interface to ac97-codec module
1384 *
1385 *
1386 */
1387
1388/**
1389 * via_ac97_wait_idle - Wait until AC97 codec is not busy
1390 * @card: Private info for specified board
1391 *
1392 * Sleep until the AC97 codec is no longer busy.
1393 * Returns the final value read from the SGD
1394 * register being polled.
1395 */
1396
1397static u8 via_ac97_wait_idle (struct via_info *card)
1398{
1399 u8 tmp8;
1400 int counter = VIA_COUNTER_LIMIT;
1401
1402 DPRINTK ("ENTER/EXIT\n");
1403
1404 assert (card != NULL);
1405 assert (card->pdev != NULL);
1406
1407 do {
1408 udelay (15);
1409
1410 tmp8 = inb (card->baseaddr + 0x83);
1411 } while ((tmp8 & VIA_CR83_BUSY) && (counter-- > 0));
1412
1413 if (tmp8 & VIA_CR83_BUSY)
1414 printk (KERN_WARNING PFX "timeout waiting on AC97 codec\n");
1415 return tmp8;
1416}
1417
1418
1419/**
1420 * via_ac97_read_reg - Read AC97 standard register
1421 * @codec: Pointer to generic AC97 codec info
1422 * @reg: Index of AC97 register to be read
1423 *
1424 * Read the value of a single AC97 codec register,
1425 * as defined by the Intel AC97 specification.
1426 *
1427 * Defines the standard AC97 read-register operation
1428 * required by the kernel's ac97_codec interface.
1429 *
1430 * Returns the 16-bit value stored in the specified
1431 * register.
1432 */
1433
1434static u16 via_ac97_read_reg (struct ac97_codec *codec, u8 reg)
1435{
1436 unsigned long data;
1437 struct via_info *card;
1438 int counter;
1439
1440 DPRINTK ("ENTER\n");
1441
1442 assert (codec != NULL);
1443 assert (codec->private_data != NULL);
1444
1445 card = codec->private_data;
1446
1447 spin_lock(&card->ac97_lock);
1448
1449 /* Every time we write to register 80 we cause a transaction.
1450 The only safe way to clear the valid bit is to write it at
1451 the same time as the command */
1452 data = (reg << 16) | VIA_CR80_READ | VIA_CR80_VALID;
1453
1454 outl (data, card->baseaddr + VIA_BASE0_AC97_CTRL);
1455 udelay (20);
1456
1457 for (counter = VIA_COUNTER_LIMIT; counter > 0; counter--) {
1458 udelay (1);
1459 if ((((data = inl(card->baseaddr + VIA_BASE0_AC97_CTRL)) &
1460 (VIA_CR80_VALID|VIA_CR80_BUSY)) == VIA_CR80_VALID))
1461 goto out;
1462 }
1463
1464 printk (KERN_WARNING PFX "timeout while reading AC97 codec (0x%lX)\n", data);
1465 goto err_out;
1466
1467out:
1468 /* Once the valid bit has become set, we must wait a complete AC97
1469 frame before the data has settled. */
1470 udelay(25);
1471 data = (unsigned long) inl (card->baseaddr + VIA_BASE0_AC97_CTRL);
1472
1473 outb (0x02, card->baseaddr + 0x83);
1474
1475 if (((data & 0x007F0000) >> 16) == reg) {
1476 DPRINTK ("EXIT, success, data=0x%lx, retval=0x%lx\n",
1477 data, data & 0x0000FFFF);
1478 spin_unlock(&card->ac97_lock);
1479 return data & 0x0000FFFF;
1480 }
1481
1482 printk (KERN_WARNING "via82cxxx_audio: not our index: reg=0x%x, newreg=0x%lx\n",
1483 reg, ((data & 0x007F0000) >> 16));
1484
1485err_out:
1486 spin_unlock(&card->ac97_lock);
1487 DPRINTK ("EXIT, returning 0\n");
1488 return 0;
1489}
1490
1491
1492/**
1493 * via_ac97_write_reg - Write AC97 standard register
1494 * @codec: Pointer to generic AC97 codec info
1495 * @reg: Index of AC97 register to be written
1496 * @value: Value to be written to AC97 register
1497 *
1498 * Write the value of a single AC97 codec register,
1499 * as defined by the Intel AC97 specification.
1500 *
1501 * Defines the standard AC97 write-register operation
1502 * required by the kernel's ac97_codec interface.
1503 */
1504
1505static void via_ac97_write_reg (struct ac97_codec *codec, u8 reg, u16 value)
1506{
1507 u32 data;
1508 struct via_info *card;
1509 int counter;
1510
1511 DPRINTK ("ENTER\n");
1512
1513 assert (codec != NULL);
1514 assert (codec->private_data != NULL);
1515
1516 card = codec->private_data;
1517
1518 spin_lock(&card->ac97_lock);
1519
1520 data = (reg << 16) + value;
1521 outl (data, card->baseaddr + VIA_BASE0_AC97_CTRL);
1522 udelay (10);
1523
1524 for (counter = VIA_COUNTER_LIMIT; counter > 0; counter--) {
1525 if ((inb (card->baseaddr + 0x83) & VIA_CR83_BUSY) == 0)
1526 goto out;
1527
1528 udelay (15);
1529 }
1530
1531 printk (KERN_WARNING PFX "timeout after AC97 codec write (0x%X, 0x%X)\n", reg, value);
1532
1533out:
1534 spin_unlock(&card->ac97_lock);
1535 DPRINTK ("EXIT\n");
1536}
1537
1538
1539static int via_mixer_open (struct inode *inode, struct file *file)
1540{
1541 int minor = iminor(inode);
1542 struct via_info *card;
1543 struct pci_dev *pdev = NULL;
1544 struct pci_driver *drvr;
1545
1546 DPRINTK ("ENTER\n");
1547
1548 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
1549 drvr = pci_dev_driver (pdev);
1550 if (drvr == &via_driver) {
1551 assert (pci_get_drvdata (pdev) != NULL);
1552
1553 card = pci_get_drvdata (pdev);
1554 if (card->ac97->dev_mixer == minor)
1555 goto match;
1556 }
1557 }
1558
1559 DPRINTK ("EXIT, returning -ENODEV\n");
1560 return -ENODEV;
1561
1562match:
1563 file->private_data = card->ac97;
1564
1565 DPRINTK ("EXIT, returning 0\n");
1566 return nonseekable_open(inode, file);
1567}
1568
1569static int via_mixer_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
1570 unsigned long arg)
1571{
1572 struct ac97_codec *codec = file->private_data;
1573 struct via_info *card;
1574 int nonblock = (file->f_flags & O_NONBLOCK);
1575 int rc;
1576
1577 DPRINTK ("ENTER\n");
1578
1579 assert (codec != NULL);
1580 card = codec->private_data;
1581 assert (card != NULL);
1582
1583 rc = via_syscall_down (card, nonblock);
1584 if (rc) goto out;
1585
1586#if 0
1587 /*
1588 * Intercept volume control on 8233 and 8235
1589 */
1590 if(card->volume)
1591 {
1592 switch(cmd)
1593 {
1594 case SOUND_MIXER_READ_VOLUME:
1595 return card->mixer_vol;
1596 case SOUND_MIXER_WRITE_VOLUME:
1597 {
1598 int v;
1599 if(get_user(v, (int *)arg))
1600 {
1601 rc = -EFAULT;
1602 goto out;
1603 }
1604 card->mixer_vol = v;
1605 }
1606 }
1607 }
1608#endif
1609 rc = codec->mixer_ioctl(codec, cmd, arg);
1610
1611 up (&card->syscall_sem);
1612
1613out:
1614 DPRINTK ("EXIT, returning %d\n", rc);
1615 return rc;
1616}
1617
1618
1619static struct file_operations via_mixer_fops = {
1620 .owner = THIS_MODULE,
1621 .open = via_mixer_open,
1622 .llseek = no_llseek,
1623 .ioctl = via_mixer_ioctl,
1624};
1625
1626
1627static int __devinit via_ac97_reset (struct via_info *card)
1628{
1629 struct pci_dev *pdev = card->pdev;
1630 u8 tmp8;
1631 u16 tmp16;
1632
1633 DPRINTK ("ENTER\n");
1634
1635 assert (pdev != NULL);
1636
1637#ifndef NDEBUG
1638 {
1639 u8 r40,r41,r42,r43,r44,r48;
1640 pci_read_config_byte (card->pdev, 0x40, &r40);
1641 pci_read_config_byte (card->pdev, 0x41, &r41);
1642 pci_read_config_byte (card->pdev, 0x42, &r42);
1643 pci_read_config_byte (card->pdev, 0x43, &r43);
1644 pci_read_config_byte (card->pdev, 0x44, &r44);
1645 pci_read_config_byte (card->pdev, 0x48, &r48);
1646 DPRINTK ("PCI config: %02X %02X %02X %02X %02X %02X\n",
1647 r40,r41,r42,r43,r44,r48);
1648
1649 spin_lock_irq (&card->lock);
1650 DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n",
1651 inb (card->baseaddr + 0x00),
1652 inb (card->baseaddr + 0x01),
1653 inb (card->baseaddr + 0x02),
1654 inl (card->baseaddr + 0x04),
1655 inl (card->baseaddr + 0x0C),
1656 inl (card->baseaddr + 0x80),
1657 inl (card->baseaddr + 0x84));
1658 spin_unlock_irq (&card->lock);
1659
1660 }
1661#endif
1662
1663 /*
1664 * Reset AC97 controller: enable, disable, enable,
1665 * pausing after each command for good luck. Only
1666 * do this if the codec is not ready, because it causes
1667 * loud pops and such due to such a hard codec reset.
1668 */
1669 pci_read_config_byte (pdev, VIA_ACLINK_STATUS, &tmp8);
1670 if ((tmp8 & VIA_CR40_AC97_READY) == 0) {
1671 pci_write_config_byte (pdev, VIA_ACLINK_CTRL,
1672 VIA_CR41_AC97_ENABLE |
1673 VIA_CR41_AC97_RESET |
1674 VIA_CR41_AC97_WAKEUP);
1675 udelay (100);
1676
1677 pci_write_config_byte (pdev, VIA_ACLINK_CTRL, 0);
1678 udelay (100);
1679
1680 pci_write_config_byte (pdev, VIA_ACLINK_CTRL,
1681 VIA_CR41_AC97_ENABLE |
1682 VIA_CR41_PCM_ENABLE |
1683 VIA_CR41_VRA | VIA_CR41_AC97_RESET);
1684 udelay (100);
1685 }
1686
1687 /* Make sure VRA is enabled, in case we didn't do a
1688 * complete codec reset, above
1689 */
1690 pci_read_config_byte (pdev, VIA_ACLINK_CTRL, &tmp8);
1691 if (((tmp8 & VIA_CR41_VRA) == 0) ||
1692 ((tmp8 & VIA_CR41_AC97_ENABLE) == 0) ||
1693 ((tmp8 & VIA_CR41_PCM_ENABLE) == 0) ||
1694 ((tmp8 & VIA_CR41_AC97_RESET) == 0)) {
1695 pci_write_config_byte (pdev, VIA_ACLINK_CTRL,
1696 VIA_CR41_AC97_ENABLE |
1697 VIA_CR41_PCM_ENABLE |
1698 VIA_CR41_VRA | VIA_CR41_AC97_RESET);
1699 udelay (100);
1700 }
1701
1702 if(card->legacy)
1703 {
1704#if 0 /* this breaks on K7M */
1705 /* disable legacy stuff */
1706 pci_write_config_byte (pdev, 0x42, 0x00);
1707 udelay(10);
1708#endif
1709
1710 /* route FM trap to IRQ, disable FM trap */
1711 pci_write_config_byte (pdev, 0x48, 0x05);
1712 udelay(10);
1713 }
1714
1715 /* disable all codec GPI interrupts */
1716 outl (0, pci_resource_start (pdev, 0) + 0x8C);
1717
1718 /* WARNING: this line is magic. Remove this
1719 * and things break. */
1720 /* enable variable rate */
1721 tmp16 = via_ac97_read_reg (card->ac97, AC97_EXTENDED_STATUS);
1722 if ((tmp16 & 1) == 0)
1723 via_ac97_write_reg (card->ac97, AC97_EXTENDED_STATUS, tmp16 | 1);
1724
1725 DPRINTK ("EXIT, returning 0\n");
1726 return 0;
1727}
1728
1729
1730static void via_ac97_codec_wait (struct ac97_codec *codec)
1731{
1732 assert (codec->private_data != NULL);
1733 via_ac97_wait_idle (codec->private_data);
1734}
1735
1736
1737static int __devinit via_ac97_init (struct via_info *card)
1738{
1739 int rc;
1740 u16 tmp16;
1741
1742 DPRINTK ("ENTER\n");
1743
1744 assert (card != NULL);
1745
1746 card->ac97 = ac97_alloc_codec();
1747 if(card->ac97 == NULL)
1748 return -ENOMEM;
1749
1750 card->ac97->private_data = card;
1751 card->ac97->codec_read = via_ac97_read_reg;
1752 card->ac97->codec_write = via_ac97_write_reg;
1753 card->ac97->codec_wait = via_ac97_codec_wait;
1754
1755 card->ac97->dev_mixer = register_sound_mixer (&via_mixer_fops, -1);
1756 if (card->ac97->dev_mixer < 0) {
1757 printk (KERN_ERR PFX "unable to register AC97 mixer, aborting\n");
1758 DPRINTK ("EXIT, returning -EIO\n");
1759 ac97_release_codec(card->ac97);
1760 return -EIO;
1761 }
1762
1763 rc = via_ac97_reset (card);
1764 if (rc) {
1765 printk (KERN_ERR PFX "unable to reset AC97 codec, aborting\n");
1766 goto err_out;
1767 }
1768
1769 mdelay(10);
1770
1771 if (ac97_probe_codec (card->ac97) == 0) {
1772 printk (KERN_ERR PFX "unable to probe AC97 codec, aborting\n");
1773 rc = -EIO;
1774 goto err_out;
1775 }
1776
1777 /* enable variable rate */
1778 tmp16 = via_ac97_read_reg (card->ac97, AC97_EXTENDED_STATUS);
1779 via_ac97_write_reg (card->ac97, AC97_EXTENDED_STATUS, tmp16 | 1);
1780
1781 /*
1782 * If we cannot enable VRA, we have a locked-rate codec.
1783 * We try again to enable VRA before assuming so, however.
1784 */
1785 tmp16 = via_ac97_read_reg (card->ac97, AC97_EXTENDED_STATUS);
1786 if ((tmp16 & 1) == 0) {
1787 via_ac97_write_reg (card->ac97, AC97_EXTENDED_STATUS, tmp16 | 1);
1788 tmp16 = via_ac97_read_reg (card->ac97, AC97_EXTENDED_STATUS);
1789 if ((tmp16 & 1) == 0) {
1790 card->locked_rate = 1;
1791 printk (KERN_WARNING PFX "Codec rate locked at 48Khz\n");
1792 }
1793 }
1794
1795 DPRINTK ("EXIT, returning 0\n");
1796 return 0;
1797
1798err_out:
1799 unregister_sound_mixer (card->ac97->dev_mixer);
1800 DPRINTK ("EXIT, returning %d\n", rc);
1801 ac97_release_codec(card->ac97);
1802 return rc;
1803}
1804
1805
1806static void via_ac97_cleanup (struct via_info *card)
1807{
1808 DPRINTK ("ENTER\n");
1809
1810 assert (card != NULL);
1811 assert (card->ac97->dev_mixer >= 0);
1812
1813 unregister_sound_mixer (card->ac97->dev_mixer);
1814 ac97_release_codec(card->ac97);
1815
1816 DPRINTK ("EXIT\n");
1817}
1818
1819
1820
1821/****************************************************************
1822 *
1823 * Interrupt-related code
1824 *
1825 */
1826
1827/**
1828 * via_intr_channel - handle an interrupt for a single channel
1829 * @card: unused
1830 * @chan: handle interrupt for this channel
1831 *
1832 * This is the "meat" of the interrupt handler,
1833 * containing the actions taken each time an interrupt
1834 * occurs. All communication and coordination with
1835 * userspace takes place here.
1836 *
1837 * Locking: inside card->lock
1838 */
1839
1840static void via_intr_channel (struct via_info *card, struct via_channel *chan)
1841{
1842 u8 status;
1843 int n;
1844
1845 /* check pertinent bits of status register for action bits */
1846 status = inb (chan->iobase) & (VIA_SGD_FLAG | VIA_SGD_EOL | VIA_SGD_STOPPED);
1847 if (!status)
1848 return;
1849
1850 /* acknowledge any flagged bits ASAP */
1851 outb (status, chan->iobase);
1852
1853 if (!chan->sgtable) /* XXX: temporary solution */
1854 return;
1855
1856 /* grab current h/w ptr value */
1857 n = atomic_read (&chan->hw_ptr);
1858
1859 /* sanity check: make sure our h/w ptr doesn't have a weird value */
1860 assert (n >= 0);
1861 assert (n < chan->frag_number);
1862
1863
1864 /* reset SGD data structure in memory to reflect a full buffer,
1865 * and advance the h/w ptr, wrapping around to zero if needed
1866 */
1867 if (n == (chan->frag_number - 1)) {
1868 chan->sgtable[n].count = cpu_to_le32(chan->frag_size | VIA_EOL);
1869 atomic_set (&chan->hw_ptr, 0);
1870 } else {
1871 chan->sgtable[n].count = cpu_to_le32(chan->frag_size | VIA_FLAG);
1872 atomic_inc (&chan->hw_ptr);
1873 }
1874
1875 /* accounting crap for SNDCTL_DSP_GETxPTR */
1876 chan->n_irqs++;
1877 chan->bytes += chan->frag_size;
1878 /* FIXME - signed overflow is undefined */
1879 if (chan->bytes < 0) /* handle overflow of 31-bit value */
1880 chan->bytes = chan->frag_size;
1881 /* all following checks only occur when not in mmap(2) mode */
1882 if (!chan->is_mapped)
1883 {
1884 /* If we are recording, then n_frags represents the number
1885 * of fragments waiting to be handled by userspace.
1886 * If we are playback, then n_frags represents the number
1887 * of fragments remaining to be filled by userspace.
1888 * We increment here. If we reach max number of fragments,
1889 * this indicates an underrun/overrun. For this case under OSS,
1890 * we stop the record/playback process.
1891 */
1892 if (atomic_read (&chan->n_frags) < chan->frag_number)
1893 atomic_inc (&chan->n_frags);
1894 assert (atomic_read (&chan->n_frags) <= chan->frag_number);
1895 if (atomic_read (&chan->n_frags) == chan->frag_number) {
1896 chan->is_active = 0;
1897 via_chan_stop (chan->iobase);
1898 }
1899 }
1900 /* wake up anyone listening to see when interrupts occur */
1901 wake_up_all (&chan->wait);
1902
1903 DPRINTK ("%s intr, status=0x%02X, hwptr=0x%lX, chan->hw_ptr=%d\n",
1904 chan->name, status, (long) inl (chan->iobase + 0x04),
1905 atomic_read (&chan->hw_ptr));
1906
1907 DPRINTK ("%s intr, channel n_frags == %d, missed %d\n", chan->name,
1908 atomic_read (&chan->n_frags), missed);
1909}
1910
1911
1912static irqreturn_t via_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1913{
1914 struct via_info *card = dev_id;
1915 u32 status32;
1916
1917 /* to minimize interrupt sharing costs, we use the SGD status
1918 * shadow register to check the status of all inputs and
1919 * outputs with a single 32-bit bus read. If no interrupt
1920 * conditions are flagged, we exit immediately
1921 */
1922 status32 = inl (card->baseaddr + VIA_BASE0_SGD_STATUS_SHADOW);
1923 if (!(status32 & VIA_INTR_MASK))
1924 {
1925#ifdef CONFIG_MIDI_VIA82CXXX
1926 if (card->midi_devc)
1927 uart401intr(irq, card->midi_devc, regs);
1928#endif
1929 return IRQ_HANDLED;
1930 }
1931 DPRINTK ("intr, status32 == 0x%08X\n", status32);
1932
1933 /* synchronize interrupt handling under SMP. this spinlock
1934 * goes away completely on UP
1935 */
1936 spin_lock (&card->lock);
1937
1938 if (status32 & VIA_INTR_OUT)
1939 via_intr_channel (card, &card->ch_out);
1940 if (status32 & VIA_INTR_IN)
1941 via_intr_channel (card, &card->ch_in);
1942 if (status32 & VIA_INTR_FM)
1943 via_intr_channel (card, &card->ch_fm);
1944
1945 spin_unlock (&card->lock);
1946
1947 return IRQ_HANDLED;
1948}
1949
1950static irqreturn_t via_new_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1951{
1952 struct via_info *card = dev_id;
1953 u32 status32;
1954
1955 /* to minimize interrupt sharing costs, we use the SGD status
1956 * shadow register to check the status of all inputs and
1957 * outputs with a single 32-bit bus read. If no interrupt
1958 * conditions are flagged, we exit immediately
1959 */
1960 status32 = inl (card->baseaddr + VIA_BASE0_SGD_STATUS_SHADOW);
1961 if (!(status32 & VIA_NEW_INTR_MASK))
1962 return IRQ_NONE;
1963 /*
1964 * goes away completely on UP
1965 */
1966 spin_lock (&card->lock);
1967
1968 via_intr_channel (card, &card->ch_out);
1969 via_intr_channel (card, &card->ch_in);
1970 via_intr_channel (card, &card->ch_fm);
1971
1972 spin_unlock (&card->lock);
1973 return IRQ_HANDLED;
1974}
1975
1976
1977/**
1978 * via_interrupt_init - Initialize interrupt handling
1979 * @card: Private info for specified board
1980 *
1981 * Obtain and reserve IRQ for using in handling audio events.
1982 * Also, disable any IRQ-generating resources, to make sure
1983 * we don't get interrupts before we want them.
1984 */
1985
1986static int via_interrupt_init (struct via_info *card)
1987{
1988 u8 tmp8;
1989
1990 DPRINTK ("ENTER\n");
1991
1992 assert (card != NULL);
1993 assert (card->pdev != NULL);
1994
1995 /* check for sane IRQ number. can this ever happen? */
1996 if (card->pdev->irq < 2) {
1997 printk (KERN_ERR PFX "insane IRQ %d, aborting\n",
1998 card->pdev->irq);
1999 DPRINTK ("EXIT, returning -EIO\n");
2000 return -EIO;
2001 }
2002
2003 /* VIA requires this is done */
2004 pci_write_config_byte(card->pdev, PCI_INTERRUPT_LINE, card->pdev->irq);
2005
2006 if(card->legacy)
2007 {
2008 /* make sure FM irq is not routed to us */
2009 pci_read_config_byte (card->pdev, VIA_FM_NMI_CTRL, &tmp8);
2010 if ((tmp8 & VIA_CR48_FM_TRAP_TO_NMI) == 0) {
2011 tmp8 |= VIA_CR48_FM_TRAP_TO_NMI;
2012 pci_write_config_byte (card->pdev, VIA_FM_NMI_CTRL, tmp8);
2013 }
2014 if (request_irq (card->pdev->irq, via_interrupt, SA_SHIRQ, VIA_MODULE_NAME, card)) {
2015 printk (KERN_ERR PFX "unable to obtain IRQ %d, aborting\n",
2016 card->pdev->irq);
2017 DPRINTK ("EXIT, returning -EBUSY\n");
2018 return -EBUSY;
2019 }
2020 }
2021 else
2022 {
2023 if (request_irq (card->pdev->irq, via_new_interrupt, SA_SHIRQ, VIA_MODULE_NAME, card)) {
2024 printk (KERN_ERR PFX "unable to obtain IRQ %d, aborting\n",
2025 card->pdev->irq);
2026 DPRINTK ("EXIT, returning -EBUSY\n");
2027 return -EBUSY;
2028 }
2029 }
2030
2031 DPRINTK ("EXIT, returning 0\n");
2032 return 0;
2033}
2034
2035
2036/****************************************************************
2037 *
2038 * OSS DSP device
2039 *
2040 */
2041
2042static struct file_operations via_dsp_fops = {
2043 .owner = THIS_MODULE,
2044 .open = via_dsp_open,
2045 .release = via_dsp_release,
2046 .read = via_dsp_read,
2047 .write = via_dsp_write,
2048 .poll = via_dsp_poll,
2049 .llseek = no_llseek,
2050 .ioctl = via_dsp_ioctl,
2051 .mmap = via_dsp_mmap,
2052};
2053
2054
2055static int __devinit via_dsp_init (struct via_info *card)
2056{
2057 u8 tmp8;
2058
2059 DPRINTK ("ENTER\n");
2060
2061 assert (card != NULL);
2062
2063 if(card->legacy)
2064 {
2065 /* turn off legacy features, if not already */
2066 pci_read_config_byte (card->pdev, VIA_FUNC_ENABLE, &tmp8);
2067 if (tmp8 & (VIA_CR42_SB_ENABLE | VIA_CR42_FM_ENABLE)) {
2068 tmp8 &= ~(VIA_CR42_SB_ENABLE | VIA_CR42_FM_ENABLE);
2069 pci_write_config_byte (card->pdev, VIA_FUNC_ENABLE, tmp8);
2070 }
2071 }
2072
2073 via_stop_everything (card);
2074
2075 card->dev_dsp = register_sound_dsp (&via_dsp_fops, -1);
2076 if (card->dev_dsp < 0) {
2077 DPRINTK ("EXIT, returning -ENODEV\n");
2078 return -ENODEV;
2079 }
2080 DPRINTK ("EXIT, returning 0\n");
2081 return 0;
2082}
2083
2084
2085static void via_dsp_cleanup (struct via_info *card)
2086{
2087 DPRINTK ("ENTER\n");
2088
2089 assert (card != NULL);
2090 assert (card->dev_dsp >= 0);
2091
2092 via_stop_everything (card);
2093
2094 unregister_sound_dsp (card->dev_dsp);
2095
2096 DPRINTK ("EXIT\n");
2097}
2098
2099
2100static struct page * via_mm_nopage (struct vm_area_struct * vma,
2101 unsigned long address, int *type)
2102{
2103 struct via_info *card = vma->vm_private_data;
2104 struct via_channel *chan = &card->ch_out;
2105 struct page *dmapage;
2106 unsigned long pgoff;
2107 int rd, wr;
2108
2109 DPRINTK ("ENTER, start %lXh, ofs %lXh, pgoff %ld, addr %lXh\n",
2110 vma->vm_start,
2111 address - vma->vm_start,
2112 (address - vma->vm_start) >> PAGE_SHIFT,
2113 address);
2114
2115 if (address > vma->vm_end) {
2116 DPRINTK ("EXIT, returning NOPAGE_SIGBUS\n");
2117 return NOPAGE_SIGBUS; /* Disallow mremap */
2118 }
2119 if (!card) {
2120 DPRINTK ("EXIT, returning NOPAGE_OOM\n");
2121 return NOPAGE_OOM; /* Nothing allocated */
2122 }
2123
2124 pgoff = vma->vm_pgoff + ((address - vma->vm_start) >> PAGE_SHIFT);
2125 rd = card->ch_in.is_mapped;
2126 wr = card->ch_out.is_mapped;
2127
2128#ifndef VIA_NDEBUG
2129 {
2130 unsigned long max_bufs = chan->frag_number;
2131 if (rd && wr) max_bufs *= 2;
2132 /* via_dsp_mmap() should ensure this */
2133 assert (pgoff < max_bufs);
2134 }
2135#endif
2136
2137 /* if full-duplex (read+write) and we have two sets of bufs,
2138 * then the playback buffers come first, sez soundcard.c */
2139 if (pgoff >= chan->page_number) {
2140 pgoff -= chan->page_number;
2141 chan = &card->ch_in;
2142 } else if (!wr)
2143 chan = &card->ch_in;
2144
2145 assert ((((unsigned long)chan->pgtbl[pgoff].cpuaddr) % PAGE_SIZE) == 0);
2146
2147 dmapage = virt_to_page (chan->pgtbl[pgoff].cpuaddr);
2148 DPRINTK ("EXIT, returning page %p for cpuaddr %lXh\n",
2149 dmapage, (unsigned long) chan->pgtbl[pgoff].cpuaddr);
2150 get_page (dmapage);
2151 if (type)
2152 *type = VM_FAULT_MINOR;
2153 return dmapage;
2154}
2155
2156
2157#ifndef VM_RESERVED
2158static int via_mm_swapout (struct page *page, struct file *filp)
2159{
2160 return 0;
2161}
2162#endif /* VM_RESERVED */
2163
2164
2165static struct vm_operations_struct via_mm_ops = {
2166 .nopage = via_mm_nopage,
2167
2168#ifndef VM_RESERVED
2169 .swapout = via_mm_swapout,
2170#endif
2171};
2172
2173
2174static int via_dsp_mmap(struct file *file, struct vm_area_struct *vma)
2175{
2176 struct via_info *card;
2177 int nonblock = (file->f_flags & O_NONBLOCK);
2178 int rc = -EINVAL, rd=0, wr=0;
2179 unsigned long max_size, size, start, offset;
2180
2181 assert (file != NULL);
2182 assert (vma != NULL);
2183 card = file->private_data;
2184 assert (card != NULL);
2185
2186 DPRINTK ("ENTER, start %lXh, size %ld, pgoff %ld\n",
2187 vma->vm_start,
2188 vma->vm_end - vma->vm_start,
2189 vma->vm_pgoff);
2190
2191 max_size = 0;
2192 if (vma->vm_flags & VM_READ) {
2193 rd = 1;
2194 via_chan_set_buffering(card, &card->ch_in, -1);
2195 via_chan_buffer_init (card, &card->ch_in);
2196 max_size += card->ch_in.page_number << PAGE_SHIFT;
2197 }
2198 if (vma->vm_flags & VM_WRITE) {
2199 wr = 1;
2200 via_chan_set_buffering(card, &card->ch_out, -1);
2201 via_chan_buffer_init (card, &card->ch_out);
2202 max_size += card->ch_out.page_number << PAGE_SHIFT;
2203 }
2204
2205 start = vma->vm_start;
2206 offset = (vma->vm_pgoff << PAGE_SHIFT);
2207 size = vma->vm_end - vma->vm_start;
2208
2209 /* some basic size/offset sanity checks */
2210 if (size > max_size)
2211 goto out;
2212 if (offset > max_size - size)
2213 goto out;
2214
2215 rc = via_syscall_down (card, nonblock);
2216 if (rc) goto out;
2217
2218 vma->vm_ops = &via_mm_ops;
2219 vma->vm_private_data = card;
2220
2221#ifdef VM_RESERVED
2222 vma->vm_flags |= VM_RESERVED;
2223#endif
2224
2225 if (rd)
2226 card->ch_in.is_mapped = 1;
2227 if (wr)
2228 card->ch_out.is_mapped = 1;
2229
2230 up (&card->syscall_sem);
2231 rc = 0;
2232
2233out:
2234 DPRINTK ("EXIT, returning %d\n", rc);
2235 return rc;
2236}
2237
2238
2239static ssize_t via_dsp_do_read (struct via_info *card,
2240 char __user *userbuf, size_t count,
2241 int nonblock)
2242{
2243 DECLARE_WAITQUEUE(wait, current);
2244 const char __user *orig_userbuf = userbuf;
2245 struct via_channel *chan = &card->ch_in;
2246 size_t size;
2247 int n, tmp;
2248 ssize_t ret = 0;
2249
2250 /* if SGD has not yet been started, start it */
2251 via_chan_maybe_start (chan);
2252
2253handle_one_block:
2254 /* just to be a nice neighbor */
2255 /* Thomas Sailer:
2256 * But also to ourselves, release semaphore if we do so */
2257 if (need_resched()) {
2258 up(&card->syscall_sem);
2259 schedule ();
2260 ret = via_syscall_down (card, nonblock);
2261 if (ret)
2262 goto out;
2263 }
2264
2265 /* grab current channel software pointer. In the case of
2266 * recording, this is pointing to the next buffer that
2267 * will receive data from the audio hardware.
2268 */
2269 n = chan->sw_ptr;
2270
2271 /* n_frags represents the number of fragments waiting
2272 * to be copied to userland. sleep until at least
2273 * one buffer has been read from the audio hardware.
2274 */
2275 add_wait_queue(&chan->wait, &wait);
2276 for (;;) {
2277 __set_current_state(TASK_INTERRUPTIBLE);
2278 tmp = atomic_read (&chan->n_frags);
2279 assert (tmp >= 0);
2280 assert (tmp <= chan->frag_number);
2281 if (tmp)
2282 break;
2283 if (nonblock || !chan->is_active) {
2284 ret = -EAGAIN;
2285 break;
2286 }
2287
2288 up(&card->syscall_sem);
2289
2290 DPRINTK ("Sleeping on block %d\n", n);
2291 schedule();
2292
2293 ret = via_syscall_down (card, nonblock);
2294 if (ret)
2295 break;
2296
2297 if (signal_pending (current)) {
2298 ret = -ERESTARTSYS;
2299 break;
2300 }
2301 }
2302 set_current_state(TASK_RUNNING);
2303 remove_wait_queue(&chan->wait, &wait);
2304 if (ret)
2305 goto out;
2306
2307 /* Now that we have a buffer we can read from, send
2308 * as much as sample data possible to userspace.
2309 */
2310 while ((count > 0) && (chan->slop_len < chan->frag_size)) {
2311 size_t slop_left = chan->frag_size - chan->slop_len;
2312 void *base = chan->pgtbl[n / (PAGE_SIZE / chan->frag_size)].cpuaddr;
2313 unsigned ofs = (n % (PAGE_SIZE / chan->frag_size)) * chan->frag_size;
2314
2315 size = (count < slop_left) ? count : slop_left;
2316 if (copy_to_user (userbuf,
2317 base + ofs + chan->slop_len,
2318 size)) {
2319 ret = -EFAULT;
2320 goto out;
2321 }
2322
2323 count -= size;
2324 chan->slop_len += size;
2325 userbuf += size;
2326 }
2327
2328 /* If we didn't copy the buffer completely to userspace,
2329 * stop now.
2330 */
2331 if (chan->slop_len < chan->frag_size)
2332 goto out;
2333
2334 /*
2335 * If we get to this point, we copied one buffer completely
2336 * to userspace, give the buffer back to the hardware.
2337 */
2338
2339 /* advance channel software pointer to point to
2340 * the next buffer from which we will copy
2341 */
2342 if (chan->sw_ptr == (chan->frag_number - 1))
2343 chan->sw_ptr = 0;
2344 else
2345 chan->sw_ptr++;
2346
2347 /* mark one less buffer waiting to be processed */
2348 assert (atomic_read (&chan->n_frags) > 0);
2349 atomic_dec (&chan->n_frags);
2350
2351 /* we are at a block boundary, there is no fragment data */
2352 chan->slop_len = 0;
2353
2354 DPRINTK ("Flushed block %u, sw_ptr now %u, n_frags now %d\n",
2355 n, chan->sw_ptr, atomic_read (&chan->n_frags));
2356
2357 DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n",
2358 inb (card->baseaddr + 0x00),
2359 inb (card->baseaddr + 0x01),
2360 inb (card->baseaddr + 0x02),
2361 inl (card->baseaddr + 0x04),
2362 inl (card->baseaddr + 0x0C),
2363 inl (card->baseaddr + 0x80),
2364 inl (card->baseaddr + 0x84));
2365
2366 if (count > 0)
2367 goto handle_one_block;
2368
2369out:
2370 return (userbuf != orig_userbuf) ? (userbuf - orig_userbuf) : ret;
2371}
2372
2373
2374static ssize_t via_dsp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2375{
2376 struct via_info *card;
2377 int nonblock = (file->f_flags & O_NONBLOCK);
2378 int rc;
2379
2380 DPRINTK ("ENTER, file=%p, buffer=%p, count=%u, ppos=%lu\n",
2381 file, buffer, count, ppos ? ((unsigned long)*ppos) : 0);
2382
2383 assert (file != NULL);
2384 card = file->private_data;
2385 assert (card != NULL);
2386
2387 rc = via_syscall_down (card, nonblock);
2388 if (rc) goto out;
2389
2390 if (card->ch_in.is_mapped) {
2391 rc = -ENXIO;
2392 goto out_up;
2393 }
2394
2395 via_chan_set_buffering(card, &card->ch_in, -1);
2396 rc = via_chan_buffer_init (card, &card->ch_in);
2397
2398 if (rc)
2399 goto out_up;
2400
2401 rc = via_dsp_do_read (card, buffer, count, nonblock);
2402
2403out_up:
2404 up (&card->syscall_sem);
2405out:
2406 DPRINTK ("EXIT, returning %ld\n",(long) rc);
2407 return rc;
2408}
2409
2410
2411static ssize_t via_dsp_do_write (struct via_info *card,
2412 const char __user *userbuf, size_t count,
2413 int nonblock)
2414{
2415 DECLARE_WAITQUEUE(wait, current);
2416 const char __user *orig_userbuf = userbuf;
2417 struct via_channel *chan = &card->ch_out;
2418 volatile struct via_sgd_table *sgtable = chan->sgtable;
2419 size_t size;
2420 int n, tmp;
2421 ssize_t ret = 0;
2422
2423handle_one_block:
2424 /* just to be a nice neighbor */
2425 /* Thomas Sailer:
2426 * But also to ourselves, release semaphore if we do so */
2427 if (need_resched()) {
2428 up(&card->syscall_sem);
2429 schedule ();
2430 ret = via_syscall_down (card, nonblock);
2431 if (ret)
2432 goto out;
2433 }
2434
2435 /* grab current channel fragment pointer. In the case of
2436 * playback, this is pointing to the next fragment that
2437 * should receive data from userland.
2438 */
2439 n = chan->sw_ptr;
2440
2441 /* n_frags represents the number of fragments remaining
2442 * to be filled by userspace. Sleep until
2443 * at least one fragment is available for our use.
2444 */
2445 add_wait_queue(&chan->wait, &wait);
2446 for (;;) {
2447 __set_current_state(TASK_INTERRUPTIBLE);
2448 tmp = atomic_read (&chan->n_frags);
2449 assert (tmp >= 0);
2450 assert (tmp <= chan->frag_number);
2451 if (tmp)
2452 break;
2453 if (nonblock || !chan->is_active) {
2454 ret = -EAGAIN;
2455 break;
2456 }
2457
2458 up(&card->syscall_sem);
2459
2460 DPRINTK ("Sleeping on page %d, tmp==%d, ir==%d\n", n, tmp, chan->is_record);
2461 schedule();
2462
2463 ret = via_syscall_down (card, nonblock);
2464 if (ret)
2465 break;
2466
2467 if (signal_pending (current)) {
2468 ret = -ERESTARTSYS;
2469 break;
2470 }
2471 }
2472 set_current_state(TASK_RUNNING);
2473 remove_wait_queue(&chan->wait, &wait);
2474 if (ret)
2475 goto out;
2476
2477 /* Now that we have at least one fragment we can write to, fill the buffer
2478 * as much as possible with data from userspace.
2479 */
2480 while ((count > 0) && (chan->slop_len < chan->frag_size)) {
2481 size_t slop_left = chan->frag_size - chan->slop_len;
2482
2483 size = (count < slop_left) ? count : slop_left;
2484 if (copy_from_user (chan->pgtbl[n / (PAGE_SIZE / chan->frag_size)].cpuaddr + (n % (PAGE_SIZE / chan->frag_size)) * chan->frag_size + chan->slop_len,
2485 userbuf, size)) {
2486 ret = -EFAULT;
2487 goto out;
2488 }
2489
2490 count -= size;
2491 chan->slop_len += size;
2492 userbuf += size;
2493 }
2494
2495 /* If we didn't fill up the buffer with data, stop now.
2496 * Put a 'stop' marker in the DMA table too, to tell the
2497 * audio hardware to stop if it gets here.
2498 */
2499 if (chan->slop_len < chan->frag_size) {
2500 sgtable[n].count = cpu_to_le32 (chan->slop_len | VIA_EOL | VIA_STOP);
2501 goto out;
2502 }
2503
2504 /*
2505 * If we get to this point, we have filled a buffer with
2506 * audio data, flush the buffer to audio hardware.
2507 */
2508
2509 /* Record the true size for the audio hardware to notice */
2510 if (n == (chan->frag_number - 1))
2511 sgtable[n].count = cpu_to_le32 (chan->frag_size | VIA_EOL);
2512 else
2513 sgtable[n].count = cpu_to_le32 (chan->frag_size | VIA_FLAG);
2514
2515 /* advance channel software pointer to point to
2516 * the next buffer we will fill with data
2517 */
2518 if (chan->sw_ptr == (chan->frag_number - 1))
2519 chan->sw_ptr = 0;
2520 else
2521 chan->sw_ptr++;
2522
2523 /* mark one less buffer as being available for userspace consumption */
2524 assert (atomic_read (&chan->n_frags) > 0);
2525 atomic_dec (&chan->n_frags);
2526
2527 /* we are at a block boundary, there is no fragment data */
2528 chan->slop_len = 0;
2529
2530 /* if SGD has not yet been started, start it */
2531 via_chan_maybe_start (chan);
2532
2533 DPRINTK ("Flushed block %u, sw_ptr now %u, n_frags now %d\n",
2534 n, chan->sw_ptr, atomic_read (&chan->n_frags));
2535
2536 DPRINTK ("regs==S=%02X C=%02X TP=%02X BP=%08X RT=%08X SG=%08X CC=%08X SS=%08X\n",
2537 inb (card->baseaddr + 0x00),
2538 inb (card->baseaddr + 0x01),
2539 inb (card->baseaddr + 0x02),
2540 inl (card->baseaddr + 0x04),
2541 inl (card->baseaddr + 0x08),
2542 inl (card->baseaddr + 0x0C),
2543 inl (card->baseaddr + 0x80),
2544 inl (card->baseaddr + 0x84));
2545
2546 if (count > 0)
2547 goto handle_one_block;
2548
2549out:
2550 if (userbuf - orig_userbuf)
2551 return userbuf - orig_userbuf;
2552 else
2553 return ret;
2554}
2555
2556
2557static ssize_t via_dsp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2558{
2559 struct via_info *card;
2560 ssize_t rc;
2561 int nonblock = (file->f_flags & O_NONBLOCK);
2562
2563 DPRINTK ("ENTER, file=%p, buffer=%p, count=%u, ppos=%lu\n",
2564 file, buffer, count, ppos ? ((unsigned long)*ppos) : 0);
2565
2566 assert (file != NULL);
2567 card = file->private_data;
2568 assert (card != NULL);
2569
2570 rc = via_syscall_down (card, nonblock);
2571 if (rc) goto out;
2572
2573 if (card->ch_out.is_mapped) {
2574 rc = -ENXIO;
2575 goto out_up;
2576 }
2577
2578 via_chan_set_buffering(card, &card->ch_out, -1);
2579 rc = via_chan_buffer_init (card, &card->ch_out);
2580
2581 if (rc)
2582 goto out_up;
2583
2584 rc = via_dsp_do_write (card, buffer, count, nonblock);
2585
2586out_up:
2587 up (&card->syscall_sem);
2588out:
2589 DPRINTK ("EXIT, returning %ld\n",(long) rc);
2590 return rc;
2591}
2592
2593
2594static unsigned int via_dsp_poll(struct file *file, struct poll_table_struct *wait)
2595{
2596 struct via_info *card;
2597 struct via_channel *chan;
2598 unsigned int mask = 0;
2599
2600 DPRINTK ("ENTER\n");
2601
2602 assert (file != NULL);
2603 card = file->private_data;
2604 assert (card != NULL);
2605
2606 if (file->f_mode & FMODE_READ) {
2607 chan = &card->ch_in;
2608 if (sg_active (chan->iobase))
2609 poll_wait(file, &chan->wait, wait);
2610 if (atomic_read (&chan->n_frags) > 0)
2611 mask |= POLLIN | POLLRDNORM;
2612 }
2613
2614 if (file->f_mode & FMODE_WRITE) {
2615 chan = &card->ch_out;
2616 if (sg_active (chan->iobase))
2617 poll_wait(file, &chan->wait, wait);
2618 if (atomic_read (&chan->n_frags) > 0)
2619 mask |= POLLOUT | POLLWRNORM;
2620 }
2621
2622 DPRINTK ("EXIT, returning %u\n", mask);
2623 return mask;
2624}
2625
2626
2627/**
2628 * via_dsp_drain_playback - sleep until all playback samples are flushed
2629 * @card: Private info for specified board
2630 * @chan: Channel to drain
2631 * @nonblock: boolean, non-zero if O_NONBLOCK is set
2632 *
2633 * Sleeps until all playback has been flushed to the audio
2634 * hardware.
2635 *
2636 * Locking: inside card->syscall_sem
2637 */
2638
2639static int via_dsp_drain_playback (struct via_info *card,
2640 struct via_channel *chan, int nonblock)
2641{
2642 DECLARE_WAITQUEUE(wait, current);
2643 int ret = 0;
2644
2645 DPRINTK ("ENTER, nonblock = %d\n", nonblock);
2646
2647 if (chan->slop_len > 0)
2648 via_chan_flush_frag (chan);
2649
2650 if (atomic_read (&chan->n_frags) == chan->frag_number)
2651 goto out;
2652
2653 via_chan_maybe_start (chan);
2654
2655 add_wait_queue(&chan->wait, &wait);
2656 for (;;) {
2657 DPRINTK ("FRAGS %d FRAGNUM %d\n", atomic_read(&chan->n_frags), chan->frag_number);
2658 __set_current_state(TASK_INTERRUPTIBLE);
2659 if (atomic_read (&chan->n_frags) >= chan->frag_number)
2660 break;
2661
2662 if (nonblock) {
2663 DPRINTK ("EXIT, returning -EAGAIN\n");
2664 ret = -EAGAIN;
2665 break;
2666 }
2667
2668#ifdef VIA_DEBUG
2669 {
2670 u8 r40,r41,r42,r43,r44,r48;
2671 pci_read_config_byte (card->pdev, 0x40, &r40);
2672 pci_read_config_byte (card->pdev, 0x41, &r41);
2673 pci_read_config_byte (card->pdev, 0x42, &r42);
2674 pci_read_config_byte (card->pdev, 0x43, &r43);
2675 pci_read_config_byte (card->pdev, 0x44, &r44);
2676 pci_read_config_byte (card->pdev, 0x48, &r48);
2677 DPRINTK ("PCI config: %02X %02X %02X %02X %02X %02X\n",
2678 r40,r41,r42,r43,r44,r48);
2679
2680 DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n",
2681 inb (card->baseaddr + 0x00),
2682 inb (card->baseaddr + 0x01),
2683 inb (card->baseaddr + 0x02),
2684 inl (card->baseaddr + 0x04),
2685 inl (card->baseaddr + 0x0C),
2686 inl (card->baseaddr + 0x80),
2687 inl (card->baseaddr + 0x84));
2688 }
2689
2690 if (!chan->is_active)
2691 printk (KERN_ERR "sleeping but not active\n");
2692#endif
2693
2694 up(&card->syscall_sem);
2695
2696 DPRINTK ("sleeping, nbufs=%d\n", atomic_read (&chan->n_frags));
2697 schedule();
2698
2699 if ((ret = via_syscall_down (card, nonblock)))
2700 break;
2701
2702 if (signal_pending (current)) {
2703 DPRINTK ("EXIT, returning -ERESTARTSYS\n");
2704 ret = -ERESTARTSYS;
2705 break;
2706 }
2707 }
2708 set_current_state(TASK_RUNNING);
2709 remove_wait_queue(&chan->wait, &wait);
2710
2711#ifdef VIA_DEBUG
2712 {
2713 u8 r40,r41,r42,r43,r44,r48;
2714 pci_read_config_byte (card->pdev, 0x40, &r40);
2715 pci_read_config_byte (card->pdev, 0x41, &r41);
2716 pci_read_config_byte (card->pdev, 0x42, &r42);
2717 pci_read_config_byte (card->pdev, 0x43, &r43);
2718 pci_read_config_byte (card->pdev, 0x44, &r44);
2719 pci_read_config_byte (card->pdev, 0x48, &r48);
2720 DPRINTK ("PCI config: %02X %02X %02X %02X %02X %02X\n",
2721 r40,r41,r42,r43,r44,r48);
2722
2723 DPRINTK ("regs==%02X %02X %02X %08X %08X %08X %08X\n",
2724 inb (card->baseaddr + 0x00),
2725 inb (card->baseaddr + 0x01),
2726 inb (card->baseaddr + 0x02),
2727 inl (card->baseaddr + 0x04),
2728 inl (card->baseaddr + 0x0C),
2729 inl (card->baseaddr + 0x80),
2730 inl (card->baseaddr + 0x84));
2731
2732 DPRINTK ("final nbufs=%d\n", atomic_read (&chan->n_frags));
2733 }
2734#endif
2735
2736out:
2737 DPRINTK ("EXIT, returning %d\n", ret);
2738 return ret;
2739}
2740
2741
2742/**
2743 * via_dsp_ioctl_space - get information about channel buffering
2744 * @card: Private info for specified board
2745 * @chan: pointer to channel-specific info
2746 * @arg: user buffer for returned information
2747 *
2748 * Handles SNDCTL_DSP_GETISPACE and SNDCTL_DSP_GETOSPACE.
2749 *
2750 * Locking: inside card->syscall_sem
2751 */
2752
2753static int via_dsp_ioctl_space (struct via_info *card,
2754 struct via_channel *chan,
2755 void __user *arg)
2756{
2757 audio_buf_info info;
2758
2759 via_chan_set_buffering(card, chan, -1);
2760
2761 info.fragstotal = chan->frag_number;
2762 info.fragsize = chan->frag_size;
2763
2764 /* number of full fragments we can read/write without blocking */
2765 info.fragments = atomic_read (&chan->n_frags);
2766
2767 if ((chan->slop_len % chan->frag_size > 0) && (info.fragments > 0))
2768 info.fragments--;
2769
2770 /* number of bytes that can be read or written immediately
2771 * without blocking.
2772 */
2773 info.bytes = (info.fragments * chan->frag_size);
2774 if (chan->slop_len % chan->frag_size > 0)
2775 info.bytes += chan->frag_size - (chan->slop_len % chan->frag_size);
2776
2777 DPRINTK ("EXIT, returning fragstotal=%d, fragsize=%d, fragments=%d, bytes=%d\n",
2778 info.fragstotal,
2779 info.fragsize,
2780 info.fragments,
2781 info.bytes);
2782
2783 return copy_to_user (arg, &info, sizeof (info))?-EFAULT:0;
2784}
2785
2786
2787/**
2788 * via_dsp_ioctl_ptr - get information about hardware buffer ptr
2789 * @card: Private info for specified board
2790 * @chan: pointer to channel-specific info
2791 * @arg: user buffer for returned information
2792 *
2793 * Handles SNDCTL_DSP_GETIPTR and SNDCTL_DSP_GETOPTR.
2794 *
2795 * Locking: inside card->syscall_sem
2796 */
2797
2798static int via_dsp_ioctl_ptr (struct via_info *card,
2799 struct via_channel *chan,
2800 void __user *arg)
2801{
2802 count_info info;
2803
2804 spin_lock_irq (&card->lock);
2805
2806 info.bytes = chan->bytes;
2807 info.blocks = chan->n_irqs;
2808 chan->n_irqs = 0;
2809
2810 spin_unlock_irq (&card->lock);
2811
2812 if (chan->is_active) {
2813 unsigned long extra;
2814 info.ptr = atomic_read (&chan->hw_ptr) * chan->frag_size;
2815 extra = chan->frag_size - via_sg_offset(chan);
2816 info.ptr += extra;
2817 info.bytes += extra;
2818 } else {
2819 info.ptr = 0;
2820 }
2821
2822 DPRINTK ("EXIT, returning bytes=%d, blocks=%d, ptr=%d\n",
2823 info.bytes,
2824 info.blocks,
2825 info.ptr);
2826
2827 return copy_to_user (arg, &info, sizeof (info))?-EFAULT:0;
2828}
2829
2830
2831static int via_dsp_ioctl_trigger (struct via_channel *chan, int val)
2832{
2833 int enable, do_something;
2834
2835 if (chan->is_record)
2836 enable = (val & PCM_ENABLE_INPUT);
2837 else
2838 enable = (val & PCM_ENABLE_OUTPUT);
2839
2840 if (!chan->is_enabled && enable) {
2841 do_something = 1;
2842 } else if (chan->is_enabled && !enable) {
2843 do_something = -1;
2844 } else {
2845 do_something = 0;
2846 }
2847
2848 DPRINTK ("enable=%d, do_something=%d\n",
2849 enable, do_something);
2850
2851 if (chan->is_active && do_something)
2852 return -EINVAL;
2853
2854 if (do_something == 1) {
2855 chan->is_enabled = 1;
2856 via_chan_maybe_start (chan);
2857 DPRINTK ("Triggering input\n");
2858 }
2859
2860 else if (do_something == -1) {
2861 chan->is_enabled = 0;
2862 DPRINTK ("Setup input trigger\n");
2863 }
2864
2865 return 0;
2866}
2867
2868
2869static int via_dsp_ioctl (struct inode *inode, struct file *file,
2870 unsigned int cmd, unsigned long arg)
2871{
2872 int rc, rd=0, wr=0, val=0;
2873 struct via_info *card;
2874 struct via_channel *chan;
2875 int nonblock = (file->f_flags & O_NONBLOCK);
2876 int __user *ip = (int __user *)arg;
2877 void __user *p = (void __user *)arg;
2878
2879 assert (file != NULL);
2880 card = file->private_data;
2881 assert (card != NULL);
2882
2883 if (file->f_mode & FMODE_WRITE)
2884 wr = 1;
2885 if (file->f_mode & FMODE_READ)
2886 rd = 1;
2887
2888 rc = via_syscall_down (card, nonblock);
2889 if (rc)
2890 return rc;
2891 rc = -EINVAL;
2892
2893 switch (cmd) {
2894
2895 /* OSS API version. XXX unverified */
2896 case OSS_GETVERSION:
2897 DPRINTK ("ioctl OSS_GETVERSION, EXIT, returning SOUND_VERSION\n");
2898 rc = put_user (SOUND_VERSION, ip);
2899 break;
2900
2901 /* list of supported PCM data formats */
2902 case SNDCTL_DSP_GETFMTS:
2903 DPRINTK ("DSP_GETFMTS, EXIT, returning AFMT U8|S16_LE\n");
2904 rc = put_user (AFMT_U8 | AFMT_S16_LE, ip);
2905 break;
2906
2907 /* query or set current channel's PCM data format */
2908 case SNDCTL_DSP_SETFMT:
2909 if (get_user(val, ip)) {
2910 rc = -EFAULT;
2911 break;
2912 }
2913 DPRINTK ("DSP_SETFMT, val==%d\n", val);
2914 if (val != AFMT_QUERY) {
2915 rc = 0;
2916
2917 if (rd)
2918 rc = via_chan_set_fmt (card, &card->ch_in, val);
2919
2920 if (rc >= 0 && wr)
2921 rc = via_chan_set_fmt (card, &card->ch_out, val);
2922
2923 if (rc < 0)
2924 break;
2925
2926 val = rc;
2927 } else {
2928 if ((rd && (card->ch_in.pcm_fmt & VIA_PCM_FMT_16BIT)) ||
2929 (wr && (card->ch_out.pcm_fmt & VIA_PCM_FMT_16BIT)))
2930 val = AFMT_S16_LE;
2931 else
2932 val = AFMT_U8;
2933 }
2934 DPRINTK ("SETFMT EXIT, returning %d\n", val);
2935 rc = put_user (val, ip);
2936 break;
2937
2938 /* query or set number of channels (1=mono, 2=stereo, 4/6 for multichannel) */
2939 case SNDCTL_DSP_CHANNELS:
2940 if (get_user(val, ip)) {
2941 rc = -EFAULT;
2942 break;
2943 }
2944 DPRINTK ("DSP_CHANNELS, val==%d\n", val);
2945 if (val != 0) {
2946 rc = 0;
2947
2948 if (rd)
2949 rc = via_chan_set_stereo (card, &card->ch_in, val);
2950
2951 if (rc >= 0 && wr)
2952 rc = via_chan_set_stereo (card, &card->ch_out, val);
2953
2954 if (rc < 0)
2955 break;
2956
2957 val = rc;
2958 } else {
2959 if (rd)
2960 val = card->ch_in.channels;
2961 else
2962 val = card->ch_out.channels;
2963 }
2964 DPRINTK ("CHANNELS EXIT, returning %d\n", val);
2965 rc = put_user (val, ip);
2966 break;
2967
2968 /* enable (val is not zero) or disable (val == 0) stereo */
2969 case SNDCTL_DSP_STEREO:
2970 if (get_user(val, ip)) {
2971 rc = -EFAULT;
2972 break;
2973 }
2974 DPRINTK ("DSP_STEREO, val==%d\n", val);
2975 rc = 0;
2976
2977 if (rd)
2978 rc = via_chan_set_stereo (card, &card->ch_in, val ? 2 : 1);
2979 if (rc >= 0 && wr)
2980 rc = via_chan_set_stereo (card, &card->ch_out, val ? 2 : 1);
2981
2982 if (rc < 0)
2983 break;
2984
2985 val = rc - 1;
2986
2987 DPRINTK ("STEREO EXIT, returning %d\n", val);
2988 rc = put_user(val, ip);
2989 break;
2990
2991 /* query or set sampling rate */
2992 case SNDCTL_DSP_SPEED:
2993 if (get_user(val, ip)) {
2994 rc = -EFAULT;
2995 break;
2996 }
2997 DPRINTK ("DSP_SPEED, val==%d\n", val);
2998 if (val < 0) {
2999 rc = -EINVAL;
3000 break;
3001 }
3002 if (val > 0) {
3003 rc = 0;
3004
3005 if (rd)
3006 rc = via_chan_set_speed (card, &card->ch_in, val);
3007 if (rc >= 0 && wr)
3008 rc = via_chan_set_speed (card, &card->ch_out, val);
3009
3010 if (rc < 0)
3011 break;
3012
3013 val = rc;
3014 } else {
3015 if (rd)
3016 val = card->ch_in.rate;
3017 else if (wr)
3018 val = card->ch_out.rate;
3019 else
3020 val = 0;
3021 }
3022 DPRINTK ("SPEED EXIT, returning %d\n", val);
3023 rc = put_user (val, ip);
3024 break;
3025
3026 /* wait until all buffers have been played, and then stop device */
3027 case SNDCTL_DSP_SYNC:
3028 DPRINTK ("DSP_SYNC\n");
3029 rc = 0;
3030 if (wr) {
3031 DPRINTK ("SYNC EXIT (after calling via_dsp_drain_playback)\n");
3032 rc = via_dsp_drain_playback (card, &card->ch_out, nonblock);
3033 }
3034 break;
3035
3036 /* stop recording/playback immediately */
3037 case SNDCTL_DSP_RESET:
3038 DPRINTK ("DSP_RESET\n");
3039 if (rd) {
3040 via_chan_clear (card, &card->ch_in);
3041 card->ch_in.frag_number = 0;
3042 card->ch_in.frag_size = 0;
3043 atomic_set(&card->ch_in.n_frags, 0);
3044 }
3045
3046 if (wr) {
3047 via_chan_clear (card, &card->ch_out);
3048 card->ch_out.frag_number = 0;
3049 card->ch_out.frag_size = 0;
3050 atomic_set(&card->ch_out.n_frags, 0);
3051 }
3052
3053 rc = 0;
3054 break;
3055
3056 case SNDCTL_DSP_NONBLOCK:
3057 file->f_flags |= O_NONBLOCK;
3058 rc = 0;
3059 break;
3060
3061 /* obtain bitmask of device capabilities, such as mmap, full duplex, etc. */
3062 case SNDCTL_DSP_GETCAPS:
3063 DPRINTK ("DSP_GETCAPS\n");
3064 rc = put_user(VIA_DSP_CAP, ip);
3065 break;
3066
3067 /* obtain buffer fragment size */
3068 case SNDCTL_DSP_GETBLKSIZE:
3069 DPRINTK ("DSP_GETBLKSIZE\n");
3070
3071 if (rd) {
3072 via_chan_set_buffering(card, &card->ch_in, -1);
3073 rc = put_user(card->ch_in.frag_size, ip);
3074 } else if (wr) {
3075 via_chan_set_buffering(card, &card->ch_out, -1);
3076 rc = put_user(card->ch_out.frag_size, ip);
3077 }
3078 break;
3079
3080 /* obtain information about input buffering */
3081 case SNDCTL_DSP_GETISPACE:
3082 DPRINTK ("DSP_GETISPACE\n");
3083 if (rd)
3084 rc = via_dsp_ioctl_space (card, &card->ch_in, p);
3085 break;
3086
3087 /* obtain information about output buffering */
3088 case SNDCTL_DSP_GETOSPACE:
3089 DPRINTK ("DSP_GETOSPACE\n");
3090 if (wr)
3091 rc = via_dsp_ioctl_space (card, &card->ch_out, p);
3092 break;
3093
3094 /* obtain information about input hardware pointer */
3095 case SNDCTL_DSP_GETIPTR:
3096 DPRINTK ("DSP_GETIPTR\n");
3097 if (rd)
3098 rc = via_dsp_ioctl_ptr (card, &card->ch_in, p);
3099 break;
3100
3101 /* obtain information about output hardware pointer */
3102 case SNDCTL_DSP_GETOPTR:
3103 DPRINTK ("DSP_GETOPTR\n");
3104 if (wr)
3105 rc = via_dsp_ioctl_ptr (card, &card->ch_out, p);
3106 break;
3107
3108 /* return number of bytes remaining to be played by DMA engine */
3109 case SNDCTL_DSP_GETODELAY:
3110 {
3111 DPRINTK ("DSP_GETODELAY\n");
3112
3113 chan = &card->ch_out;
3114
3115 if (!wr)
3116 break;
3117
3118 if (chan->is_active) {
3119
3120 val = chan->frag_number - atomic_read (&chan->n_frags);
3121
3122 assert(val >= 0);
3123
3124 if (val > 0) {
3125 val *= chan->frag_size;
3126 val -= chan->frag_size - via_sg_offset(chan);
3127 }
3128 val += chan->slop_len % chan->frag_size;
3129 } else
3130 val = 0;
3131
3132 assert (val <= (chan->frag_size * chan->frag_number));
3133
3134 DPRINTK ("GETODELAY EXIT, val = %d bytes\n", val);
3135 rc = put_user (val, ip);
3136 break;
3137 }
3138
3139 /* handle the quick-start of a channel,
3140 * or the notification that a quick-start will
3141 * occur in the future
3142 */
3143 case SNDCTL_DSP_SETTRIGGER:
3144 if (get_user(val, ip)) {
3145 rc = -EFAULT;
3146 break;
3147 }
3148 DPRINTK ("DSP_SETTRIGGER, rd=%d, wr=%d, act=%d/%d, en=%d/%d\n",
3149 rd, wr, card->ch_in.is_active, card->ch_out.is_active,
3150 card->ch_in.is_enabled, card->ch_out.is_enabled);
3151
3152 rc = 0;
3153
3154 if (rd)
3155 rc = via_dsp_ioctl_trigger (&card->ch_in, val);
3156
3157 if (!rc && wr)
3158 rc = via_dsp_ioctl_trigger (&card->ch_out, val);
3159
3160 break;
3161
3162 case SNDCTL_DSP_GETTRIGGER:
3163 val = 0;
3164 if ((file->f_mode & FMODE_READ) && card->ch_in.is_enabled)
3165 val |= PCM_ENABLE_INPUT;
3166 if ((file->f_mode & FMODE_WRITE) && card->ch_out.is_enabled)
3167 val |= PCM_ENABLE_OUTPUT;
3168 rc = put_user(val, ip);
3169 break;
3170
3171 /* Enable full duplex. Since we do this as soon as we are opened
3172 * with O_RDWR, this is mainly a no-op that always returns success.
3173 */
3174 case SNDCTL_DSP_SETDUPLEX:
3175 DPRINTK ("DSP_SETDUPLEX\n");
3176 if (!rd || !wr)
3177 break;
3178 rc = 0;
3179 break;
3180
3181 /* set fragment size. implemented as a successful no-op for now */
3182 case SNDCTL_DSP_SETFRAGMENT:
3183 if (get_user(val, ip)) {
3184 rc = -EFAULT;
3185 break;
3186 }
3187 DPRINTK ("DSP_SETFRAGMENT, val==%d\n", val);
3188
3189 if (rd)
3190 rc = via_chan_set_buffering(card, &card->ch_in, val);
3191
3192 if (wr)
3193 rc = via_chan_set_buffering(card, &card->ch_out, val);
3194
3195 DPRINTK ("SNDCTL_DSP_SETFRAGMENT (fragshift==0x%04X (%d), maxfrags==0x%04X (%d))\n",
3196 val & 0xFFFF,
3197 val & 0xFFFF,
3198 (val >> 16) & 0xFFFF,
3199 (val >> 16) & 0xFFFF);
3200
3201 rc = 0;
3202 break;
3203
3204 /* inform device of an upcoming pause in input (or output). */
3205 case SNDCTL_DSP_POST:
3206 DPRINTK ("DSP_POST\n");
3207 if (wr) {
3208 if (card->ch_out.slop_len > 0)
3209 via_chan_flush_frag (&card->ch_out);
3210 via_chan_maybe_start (&card->ch_out);
3211 }
3212
3213 rc = 0;
3214 break;
3215
3216 /* not implemented */
3217 default:
3218 DPRINTK ("unhandled ioctl, cmd==%u, arg==%p\n",
3219 cmd, p);
3220 break;
3221 }
3222
3223 up (&card->syscall_sem);
3224 DPRINTK ("EXIT, returning %d\n", rc);
3225 return rc;
3226}
3227
3228
3229static int via_dsp_open (struct inode *inode, struct file *file)
3230{
3231 int minor = iminor(inode);
3232 struct via_info *card;
3233 struct pci_dev *pdev = NULL;
3234 struct via_channel *chan;
3235 struct pci_driver *drvr;
3236 int nonblock = (file->f_flags & O_NONBLOCK);
3237
3238 DPRINTK ("ENTER, minor=%d, file->f_mode=0x%x\n", minor, file->f_mode);
3239
3240 if (!(file->f_mode & (FMODE_READ | FMODE_WRITE))) {
3241 DPRINTK ("EXIT, returning -EINVAL\n");
3242 return -EINVAL;
3243 }
3244
3245 card = NULL;
3246 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
3247 drvr = pci_dev_driver (pdev);
3248 if (drvr == &via_driver) {
3249 assert (pci_get_drvdata (pdev) != NULL);
3250
3251 card = pci_get_drvdata (pdev);
3252 DPRINTK ("dev_dsp = %d, minor = %d, assn = %d\n",
3253 card->dev_dsp, minor,
3254 (card->dev_dsp ^ minor) & ~0xf);
3255
3256 if (((card->dev_dsp ^ minor) & ~0xf) == 0)
3257 goto match;
3258 }
3259 }
3260
3261 DPRINTK ("no matching %s found\n", card ? "minor" : "driver");
3262 return -ENODEV;
3263
3264match:
3265 if (nonblock) {
3266 if (down_trylock (&card->open_sem)) {
3267 DPRINTK ("EXIT, returning -EAGAIN\n");
3268 return -EAGAIN;
3269 }
3270 } else {
3271 if (down_interruptible (&card->open_sem)) {
3272 DPRINTK ("EXIT, returning -ERESTARTSYS\n");
3273 return -ERESTARTSYS;
3274 }
3275 }
3276
3277 file->private_data = card;
3278 DPRINTK ("file->f_mode == 0x%x\n", file->f_mode);
3279
3280 /* handle input from analog source */
3281 if (file->f_mode & FMODE_READ) {
3282 chan = &card->ch_in;
3283
3284 via_chan_init (card, chan);
3285
3286 /* why is this forced to 16-bit stereo in all drivers? */
3287 chan->pcm_fmt = VIA_PCM_FMT_16BIT | VIA_PCM_FMT_STEREO;
3288 chan->channels = 2;
3289
3290 // TO DO - use FIFO: via_capture_fifo(card, 1);
3291 via_chan_pcm_fmt (chan, 0);
3292 via_set_rate (card->ac97, chan, 44100);
3293 }
3294
3295 /* handle output to analog source */
3296 if (file->f_mode & FMODE_WRITE) {
3297 chan = &card->ch_out;
3298
3299 via_chan_init (card, chan);
3300
3301 if (file->f_mode & FMODE_READ) {
3302 /* if in duplex mode make the recording and playback channels
3303 have the same settings */
3304 chan->pcm_fmt = VIA_PCM_FMT_16BIT | VIA_PCM_FMT_STEREO;
3305 chan->channels = 2;
3306 via_chan_pcm_fmt (chan, 0);
3307 via_set_rate (card->ac97, chan, 44100);
3308 } else {
3309 if ((minor & 0xf) == SND_DEV_DSP16) {
3310 chan->pcm_fmt = VIA_PCM_FMT_16BIT;
3311 via_chan_pcm_fmt (chan, 0);
3312 via_set_rate (card->ac97, chan, 44100);
3313 } else {
3314 via_chan_pcm_fmt (chan, 1);
3315 via_set_rate (card->ac97, chan, 8000);
3316 }
3317 }
3318 }
3319
3320 DPRINTK ("EXIT, returning 0\n");
3321 return nonseekable_open(inode, file);
3322}
3323
3324
3325static int via_dsp_release(struct inode *inode, struct file *file)
3326{
3327 struct via_info *card;
3328 int nonblock = (file->f_flags & O_NONBLOCK);
3329 int rc;
3330
3331 DPRINTK ("ENTER\n");
3332
3333 assert (file != NULL);
3334 card = file->private_data;
3335 assert (card != NULL);
3336
3337 rc = via_syscall_down (card, nonblock);
3338 if (rc) {
3339 DPRINTK ("EXIT (syscall_down error), rc=%d\n", rc);
3340 return rc;
3341 }
3342
3343 if (file->f_mode & FMODE_WRITE) {
3344 rc = via_dsp_drain_playback (card, &card->ch_out, nonblock);
3345 if (rc && rc != -ERESTARTSYS) /* Nobody needs to know about ^C */
3346 printk (KERN_DEBUG "via_audio: ignoring drain playback error %d\n", rc);
3347
3348 via_chan_free (card, &card->ch_out);
3349 via_chan_buffer_free(card, &card->ch_out);
3350 }
3351
3352 if (file->f_mode & FMODE_READ) {
3353 via_chan_free (card, &card->ch_in);
3354 via_chan_buffer_free (card, &card->ch_in);
3355 }
3356
3357 up (&card->syscall_sem);
3358 up (&card->open_sem);
3359
3360 DPRINTK ("EXIT, returning 0\n");
3361 return 0;
3362}
3363
3364
3365/****************************************************************
3366 *
3367 * Chip setup and kernel registration
3368 *
3369 *
3370 */
3371
3372static int __devinit via_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
3373{
3374#ifdef CONFIG_MIDI_VIA82CXXX
3375 u8 r42;
3376#endif
3377 int rc;
3378 struct via_info *card;
3379 static int printed_version;
3380
3381 DPRINTK ("ENTER\n");
3382
3383 if (printed_version++ == 0)
3384 printk (KERN_INFO "Via 686a/8233/8235 audio driver " VIA_VERSION "\n");
3385
3386 rc = pci_enable_device (pdev);
3387 if (rc)
3388 goto err_out;
3389
3390 rc = pci_request_regions (pdev, "via82cxxx_audio");
3391 if (rc)
3392 goto err_out_disable;
3393
3394 rc = pci_set_dma_mask(pdev, 0xffffffffULL);
3395 if (rc)
3396 goto err_out_res;
3397 rc = pci_set_consistent_dma_mask(pdev, 0xffffffffULL);
3398 if (rc)
3399 goto err_out_res;
3400
3401 card = kmalloc (sizeof (*card), GFP_KERNEL);
3402 if (!card) {
3403 printk (KERN_ERR PFX "out of memory, aborting\n");
3404 rc = -ENOMEM;
3405 goto err_out_res;
3406 }
3407
3408 pci_set_drvdata (pdev, card);
3409
3410 memset (card, 0, sizeof (*card));
3411 card->pdev = pdev;
3412 card->baseaddr = pci_resource_start (pdev, 0);
3413 card->card_num = via_num_cards++;
3414 spin_lock_init (&card->lock);
3415 spin_lock_init (&card->ac97_lock);
3416 init_MUTEX (&card->syscall_sem);
3417 init_MUTEX (&card->open_sem);
3418
3419 /* we must init these now, in case the intr handler needs them */
3420 via_chan_init_defaults (card, &card->ch_out);
3421 via_chan_init_defaults (card, &card->ch_in);
3422 via_chan_init_defaults (card, &card->ch_fm);
3423
3424 /* if BAR 2 is present, chip is Rev H or later,
3425 * which means it has a few extra features */
3426 if (pci_resource_start (pdev, 2) > 0)
3427 card->rev_h = 1;
3428
3429 /* Overkill for now, but more flexible done right */
3430
3431 card->intmask = id->driver_data;
3432 card->legacy = !card->intmask;
3433 card->sixchannel = id->driver_data;
3434
3435 if(card->sixchannel)
3436 printk(KERN_INFO PFX "Six channel audio available\n");
3437 if (pdev->irq < 1) {
3438 printk (KERN_ERR PFX "invalid PCI IRQ %d, aborting\n", pdev->irq);
3439 rc = -ENODEV;
3440 goto err_out_kfree;
3441 }
3442
3443 if (!(pci_resource_flags (pdev, 0) & IORESOURCE_IO)) {
3444 printk (KERN_ERR PFX "unable to locate I/O resources, aborting\n");
3445 rc = -ENODEV;
3446 goto err_out_kfree;
3447 }
3448
3449 pci_set_master(pdev);
3450
3451 /*
3452 * init AC97 mixer and codec
3453 */
3454 rc = via_ac97_init (card);
3455 if (rc) {
3456 printk (KERN_ERR PFX "AC97 init failed, aborting\n");
3457 goto err_out_kfree;
3458 }
3459
3460 /*
3461 * init DSP device
3462 */
3463 rc = via_dsp_init (card);
3464 if (rc) {
3465 printk (KERN_ERR PFX "DSP device init failed, aborting\n");
3466 goto err_out_have_mixer;
3467 }
3468
3469 /*
3470 * init and turn on interrupts, as the last thing we do
3471 */
3472 rc = via_interrupt_init (card);
3473 if (rc) {
3474 printk (KERN_ERR PFX "interrupt init failed, aborting\n");
3475 goto err_out_have_dsp;
3476 }
3477
3478 printk (KERN_INFO PFX "board #%d at 0x%04lX, IRQ %d\n",
3479 card->card_num + 1, card->baseaddr, pdev->irq);
3480
3481#ifdef CONFIG_MIDI_VIA82CXXX
3482 /* Disable by default */
3483 card->midi_info.io_base = 0;
3484
3485 if(card->legacy)
3486 {
3487 pci_read_config_byte (pdev, 0x42, &r42);
3488 /* Disable MIDI interrupt */
3489 pci_write_config_byte (pdev, 0x42, r42 | VIA_CR42_MIDI_IRQMASK);
3490 if (r42 & VIA_CR42_MIDI_ENABLE)
3491 {
3492 if (r42 & VIA_CR42_MIDI_PNP) /* Address selected by iobase 2 - not tested */
3493 card->midi_info.io_base = pci_resource_start (pdev, 2);
3494 else /* Address selected by byte 0x43 */
3495 {
3496 u8 r43;
3497 pci_read_config_byte (pdev, 0x43, &r43);
3498 card->midi_info.io_base = 0x300 + ((r43 & 0x0c) << 2);
3499 }
3500
3501 card->midi_info.irq = -pdev->irq;
3502 if (probe_uart401(& card->midi_info, THIS_MODULE))
3503 {
3504 card->midi_devc=midi_devs[card->midi_info.slots[4]]->devc;
3505 pci_write_config_byte(pdev, 0x42, r42 & ~VIA_CR42_MIDI_IRQMASK);
3506 printk("Enabled Via MIDI\n");
3507 }
3508 }
3509 }
3510#endif
3511
3512 DPRINTK ("EXIT, returning 0\n");
3513 return 0;
3514
3515err_out_have_dsp:
3516 via_dsp_cleanup (card);
3517
3518err_out_have_mixer:
3519 via_ac97_cleanup (card);
3520
3521err_out_kfree:
3522#ifndef VIA_NDEBUG
3523 memset (card, 0xAB, sizeof (*card)); /* poison memory */
3524#endif
3525 kfree (card);
3526
3527err_out_res:
3528 pci_release_regions (pdev);
3529
3530err_out_disable:
3531 pci_disable_device (pdev);
3532
3533err_out:
3534 pci_set_drvdata (pdev, NULL);
3535 DPRINTK ("EXIT - returning %d\n", rc);
3536 return rc;
3537}
3538
3539
3540static void __devexit via_remove_one (struct pci_dev *pdev)
3541{
3542 struct via_info *card;
3543
3544 DPRINTK ("ENTER\n");
3545
3546 assert (pdev != NULL);
3547 card = pci_get_drvdata (pdev);
3548 assert (card != NULL);
3549
3550#ifdef CONFIG_MIDI_VIA82CXXX
3551 if (card->midi_info.io_base)
3552 unload_uart401(&card->midi_info);
3553#endif
3554
3555 free_irq (card->pdev->irq, card);
3556 via_dsp_cleanup (card);
3557 via_ac97_cleanup (card);
3558
3559#ifndef VIA_NDEBUG
3560 memset (card, 0xAB, sizeof (*card)); /* poison memory */
3561#endif
3562 kfree (card);
3563
3564 pci_set_drvdata (pdev, NULL);
3565
3566 pci_release_regions (pdev);
3567 pci_disable_device (pdev);
3568 pci_set_power_state (pdev, 3); /* ...zzzzzz */
3569
3570 DPRINTK ("EXIT\n");
3571 return;
3572}
3573
3574
3575/****************************************************************
3576 *
3577 * Driver initialization and cleanup
3578 *
3579 *
3580 */
3581
3582static int __init init_via82cxxx_audio(void)
3583{
3584 int rc;
3585
3586 DPRINTK ("ENTER\n");
3587
3588 rc = pci_register_driver (&via_driver);
3589 if (rc) {
3590 DPRINTK ("EXIT, returning %d\n", rc);
3591 return rc;
3592 }
3593
3594 DPRINTK ("EXIT, returning 0\n");
3595 return 0;
3596}
3597
3598
3599static void __exit cleanup_via82cxxx_audio(void)
3600{
3601 DPRINTK ("ENTER\n");
3602
3603 pci_unregister_driver (&via_driver);
3604
3605 DPRINTK ("EXIT\n");
3606}
3607
3608
3609module_init(init_via82cxxx_audio);
3610module_exit(cleanup_via82cxxx_audio);
3611
3612MODULE_AUTHOR("Jeff Garzik");
3613MODULE_DESCRIPTION("DSP audio and mixer driver for Via 82Cxxx audio devices");
3614MODULE_LICENSE("GPL");
3615
diff --git a/sound/oss/vidc.c b/sound/oss/vidc.c
new file mode 100644
index 000000000000..00fe5cec9dc1
--- /dev/null
+++ b/sound/oss/vidc.c
@@ -0,0 +1,561 @@
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/config.h>
21#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/interrupt.h>
25
26#include <asm/hardware.h>
27#include <asm/dma.h>
28#include <asm/io.h>
29#include <asm/hardware/iomd.h>
30#include <asm/irq.h>
31#include <asm/system.h>
32
33#include "sound_config.h"
34#include "vidc.h"
35
36#ifndef _SIOC_TYPE
37#define _SIOC_TYPE(x) _IOC_TYPE(x)
38#endif
39#ifndef _SIOC_NR
40#define _SIOC_NR(x) _IOC_NR(x)
41#endif
42
43#define VIDC_SOUND_CLOCK (250000)
44#define VIDC_SOUND_CLOCK_EXT (176400)
45
46/*
47 * When using SERIAL SOUND mode (external DAC), the number of physical
48 * channels is fixed at 2.
49 */
50static int vidc_busy;
51static int vidc_adev;
52static int vidc_audio_rate;
53static char vidc_audio_format;
54static char vidc_audio_channels;
55
56static unsigned char vidc_level_l[SOUND_MIXER_NRDEVICES] = {
57 85, /* master */
58 50, /* bass */
59 50, /* treble */
60 0, /* synth */
61 75, /* pcm */
62 0, /* speaker */
63 100, /* ext line */
64 0, /* mic */
65 100, /* CD */
66 0,
67};
68
69static unsigned char vidc_level_r[SOUND_MIXER_NRDEVICES] = {
70 85, /* master */
71 50, /* bass */
72 50, /* treble */
73 0, /* synth */
74 75, /* pcm */
75 0, /* speaker */
76 100, /* ext line */
77 0, /* mic */
78 100, /* CD */
79 0,
80};
81
82static unsigned int vidc_audio_volume_l; /* left PCM vol, 0 - 65536 */
83static unsigned int vidc_audio_volume_r; /* right PCM vol, 0 - 65536 */
84
85extern void vidc_update_filler(int bits, int channels);
86extern int softoss_dev;
87
88static void
89vidc_mixer_set(int mdev, unsigned int level)
90{
91 unsigned int lev_l = level & 0x007f;
92 unsigned int lev_r = (level & 0x7f00) >> 8;
93 unsigned int mlev_l, mlev_r;
94
95 if (lev_l > 100)
96 lev_l = 100;
97 if (lev_r > 100)
98 lev_r = 100;
99
100#define SCALE(lev,master) ((lev) * (master) * 65536 / 10000)
101
102 mlev_l = vidc_level_l[SOUND_MIXER_VOLUME];
103 mlev_r = vidc_level_r[SOUND_MIXER_VOLUME];
104
105 switch (mdev) {
106 case SOUND_MIXER_VOLUME:
107 case SOUND_MIXER_PCM:
108 vidc_level_l[mdev] = lev_l;
109 vidc_level_r[mdev] = lev_r;
110
111 vidc_audio_volume_l = SCALE(lev_l, mlev_l);
112 vidc_audio_volume_r = SCALE(lev_r, mlev_r);
113/*printk("VIDC: PCM vol %05X %05X\n", vidc_audio_volume_l, vidc_audio_volume_r);*/
114 break;
115 }
116#undef SCALE
117}
118
119static int vidc_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
120{
121 unsigned int val;
122 unsigned int mdev;
123
124 if (_SIOC_TYPE(cmd) != 'M')
125 return -EINVAL;
126
127 mdev = _SIOC_NR(cmd);
128
129 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
130 if (get_user(val, (unsigned int __user *)arg))
131 return -EFAULT;
132
133 if (mdev < SOUND_MIXER_NRDEVICES)
134 vidc_mixer_set(mdev, val);
135 else
136 return -EINVAL;
137 }
138
139 /*
140 * Return parameters
141 */
142 switch (mdev) {
143 case SOUND_MIXER_RECSRC:
144 val = 0;
145 break;
146
147 case SOUND_MIXER_DEVMASK:
148 val = SOUND_MASK_VOLUME | SOUND_MASK_PCM | SOUND_MASK_SYNTH;
149 break;
150
151 case SOUND_MIXER_STEREODEVS:
152 val = SOUND_MASK_VOLUME | SOUND_MASK_PCM | SOUND_MASK_SYNTH;
153 break;
154
155 case SOUND_MIXER_RECMASK:
156 val = 0;
157 break;
158
159 case SOUND_MIXER_CAPS:
160 val = 0;
161 break;
162
163 default:
164 if (mdev < SOUND_MIXER_NRDEVICES)
165 val = vidc_level_l[mdev] | vidc_level_r[mdev] << 8;
166 else
167 return -EINVAL;
168 }
169
170 return put_user(val, (unsigned int __user *)arg) ? -EFAULT : 0;
171}
172
173static unsigned int vidc_audio_set_format(int dev, unsigned int fmt)
174{
175 switch (fmt) {
176 default:
177 fmt = AFMT_S16_LE;
178 case AFMT_U8:
179 case AFMT_S8:
180 case AFMT_S16_LE:
181 vidc_audio_format = fmt;
182 vidc_update_filler(vidc_audio_format, vidc_audio_channels);
183 case AFMT_QUERY:
184 break;
185 }
186 return vidc_audio_format;
187}
188
189#define my_abs(i) ((i)<0 ? -(i) : (i))
190
191static int vidc_audio_set_speed(int dev, int rate)
192{
193 if (rate) {
194 unsigned int hwctrl, hwrate, hwrate_ext, rate_int, rate_ext;
195 unsigned int diff_int, diff_ext;
196 unsigned int newsize, new2size;
197
198 hwctrl = 0x00000003;
199
200 /* Using internal clock */
201 hwrate = (((VIDC_SOUND_CLOCK * 2) / rate) + 1) >> 1;
202 if (hwrate < 3)
203 hwrate = 3;
204 if (hwrate > 255)
205 hwrate = 255;
206
207 /* Using exernal clock */
208 hwrate_ext = (((VIDC_SOUND_CLOCK_EXT * 2) / rate) + 1) >> 1;
209 if (hwrate_ext < 3)
210 hwrate_ext = 3;
211 if (hwrate_ext > 255)
212 hwrate_ext = 255;
213
214 rate_int = VIDC_SOUND_CLOCK / hwrate;
215 rate_ext = VIDC_SOUND_CLOCK_EXT / hwrate_ext;
216
217 /* Chose between external and internal clock */
218 diff_int = my_abs(rate_ext-rate);
219 diff_ext = my_abs(rate_int-rate);
220 if (diff_ext < diff_int) {
221 /*printk("VIDC: external %d %d %d\n", rate, rate_ext, hwrate_ext);*/
222 hwrate=hwrate_ext;
223 hwctrl=0x00000002;
224 /* Allow roughly 0.4% tolerance */
225 if (diff_ext > (rate/256))
226 rate=rate_ext;
227 } else {
228 /*printk("VIDC: internal %d %d %d\n", rate, rate_int, hwrate);*/
229 hwctrl=0x00000003;
230 /* Allow rougly 0.4% tolerance */
231 if (diff_int > (rate/256))
232 rate=rate_int;
233 }
234
235 vidc_writel(0xb0000000 | (hwrate - 2));
236 vidc_writel(0xb1000000 | hwctrl);
237
238 newsize = (10000 / hwrate) & ~3;
239 if (newsize < 208)
240 newsize = 208;
241 if (newsize > 4096)
242 newsize = 4096;
243 for (new2size = 128; new2size < newsize; new2size <<= 1);
244 if (new2size - newsize > newsize - (new2size >> 1))
245 new2size >>= 1;
246 if (new2size > 4096) {
247 printk(KERN_ERR "VIDC: error: dma buffer (%d) %d > 4K\n",
248 newsize, new2size);
249 new2size = 4096;
250 }
251 /*printk("VIDC: dma size %d\n", new2size);*/
252 dma_bufsize = new2size;
253 vidc_audio_rate = rate;
254 }
255 return vidc_audio_rate;
256}
257
258static short vidc_audio_set_channels(int dev, short channels)
259{
260 switch (channels) {
261 default:
262 channels = 2;
263 case 1:
264 case 2:
265 vidc_audio_channels = channels;
266 vidc_update_filler(vidc_audio_format, vidc_audio_channels);
267 case 0:
268 break;
269 }
270 return vidc_audio_channels;
271}
272
273/*
274 * Open the device
275 */
276static int vidc_audio_open(int dev, int mode)
277{
278 /* This audio device does not have recording capability */
279 if (mode == OPEN_READ)
280 return -EPERM;
281
282 if (vidc_busy)
283 return -EBUSY;
284
285 vidc_busy = 1;
286 return 0;
287}
288
289/*
290 * Close the device
291 */
292static void vidc_audio_close(int dev)
293{
294 vidc_busy = 0;
295}
296
297/*
298 * Output a block via DMA to sound device.
299 *
300 * We just set the DMA start and count; the DMA interrupt routine
301 * will take care of formatting the samples (via the appropriate
302 * vidc_filler routine), and flag via vidc_audio_dma_interrupt when
303 * more data is required.
304 */
305static void
306vidc_audio_output_block(int dev, unsigned long buf, int total_count, int one)
307{
308 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
309 unsigned long flags;
310
311 local_irq_save(flags);
312 dma_start = buf - (unsigned long)dmap->raw_buf_phys + (unsigned long)dmap->raw_buf;
313 dma_count = total_count;
314 local_irq_restore(flags);
315}
316
317static void
318vidc_audio_start_input(int dev, unsigned long buf, int count, int intrflag)
319{
320}
321
322static int vidc_audio_prepare_for_input(int dev, int bsize, int bcount)
323{
324 return -EINVAL;
325}
326
327static irqreturn_t vidc_audio_dma_interrupt(void)
328{
329 DMAbuf_outputintr(vidc_adev, 1);
330 return IRQ_HANDLED;
331}
332
333/*
334 * Prepare for outputting samples.
335 *
336 * Each buffer that will be passed will be `bsize' bytes long,
337 * with a total of `bcount' buffers.
338 */
339static int vidc_audio_prepare_for_output(int dev, int bsize, int bcount)
340{
341 struct audio_operations *adev = audio_devs[dev];
342
343 dma_interrupt = NULL;
344 adev->dmap_out->flags |= DMA_NODMA;
345
346 return 0;
347}
348
349/*
350 * Stop our current operation.
351 */
352static void vidc_audio_reset(int dev)
353{
354 dma_interrupt = NULL;
355}
356
357static int vidc_audio_local_qlen(int dev)
358{
359 return /*dma_count !=*/ 0;
360}
361
362static void vidc_audio_trigger(int dev, int enable_bits)
363{
364 struct audio_operations *adev = audio_devs[dev];
365
366 if (enable_bits & PCM_ENABLE_OUTPUT) {
367 if (!(adev->flags & DMA_ACTIVE)) {
368 unsigned long flags;
369
370 local_irq_save(flags);
371
372 /* prevent recusion */
373 adev->flags |= DMA_ACTIVE;
374
375 dma_interrupt = vidc_audio_dma_interrupt;
376 vidc_sound_dma_irq(0, NULL, NULL);
377 iomd_writeb(DMA_CR_E | 0x10, IOMD_SD0CR);
378
379 local_irq_restore(flags);
380 }
381 }
382}
383
384static struct audio_driver vidc_audio_driver =
385{
386 .owner = THIS_MODULE,
387 .open = vidc_audio_open,
388 .close = vidc_audio_close,
389 .output_block = vidc_audio_output_block,
390 .start_input = vidc_audio_start_input,
391 .prepare_for_input = vidc_audio_prepare_for_input,
392 .prepare_for_output = vidc_audio_prepare_for_output,
393 .halt_io = vidc_audio_reset,
394 .local_qlen = vidc_audio_local_qlen,
395 .trigger = vidc_audio_trigger,
396 .set_speed = vidc_audio_set_speed,
397 .set_bits = vidc_audio_set_format,
398 .set_channels = vidc_audio_set_channels
399};
400
401static struct mixer_operations vidc_mixer_operations = {
402 .owner = THIS_MODULE,
403 .id = "VIDC",
404 .name = "VIDCsound",
405 .ioctl = vidc_mixer_ioctl
406};
407
408void vidc_update_filler(int format, int channels)
409{
410#define TYPE(fmt,ch) (((fmt)<<2) | ((ch)&3))
411
412 switch (TYPE(format, channels)) {
413 default:
414 case TYPE(AFMT_U8, 1):
415 vidc_filler = vidc_fill_1x8_u;
416 break;
417
418 case TYPE(AFMT_U8, 2):
419 vidc_filler = vidc_fill_2x8_u;
420 break;
421
422 case TYPE(AFMT_S8, 1):
423 vidc_filler = vidc_fill_1x8_s;
424 break;
425
426 case TYPE(AFMT_S8, 2):
427 vidc_filler = vidc_fill_2x8_s;
428 break;
429
430 case TYPE(AFMT_S16_LE, 1):
431 vidc_filler = vidc_fill_1x16_s;
432 break;
433
434 case TYPE(AFMT_S16_LE, 2):
435 vidc_filler = vidc_fill_2x16_s;
436 break;
437 }
438}
439
440static void __init attach_vidc(struct address_info *hw_config)
441{
442 char name[32];
443 int i, adev;
444
445 sprintf(name, "VIDC %d-bit sound", hw_config->card_subtype);
446 conf_printf(name, hw_config);
447 memset(dma_buf, 0, sizeof(dma_buf));
448
449 adev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, name,
450 &vidc_audio_driver, sizeof(vidc_audio_driver),
451 DMA_AUTOMODE, AFMT_U8 | AFMT_S8 | AFMT_S16_LE,
452 NULL, hw_config->dma, hw_config->dma2);
453
454 if (adev < 0)
455 goto audio_failed;
456
457 /*
458 * 1024 bytes => 64 buffers
459 */
460 audio_devs[adev]->min_fragment = 10;
461 audio_devs[adev]->mixer_dev = num_mixers;
462
463 audio_devs[adev]->mixer_dev =
464 sound_install_mixer(MIXER_DRIVER_VERSION,
465 name, &vidc_mixer_operations,
466 sizeof(vidc_mixer_operations), NULL);
467
468 if (audio_devs[adev]->mixer_dev < 0)
469 goto mixer_failed;
470
471 for (i = 0; i < 2; i++) {
472 dma_buf[i] = get_zeroed_page(GFP_KERNEL);
473 if (!dma_buf[i]) {
474 printk(KERN_ERR "%s: can't allocate required buffers\n",
475 name);
476 goto mem_failed;
477 }
478 dma_pbuf[i] = virt_to_phys((void *)dma_buf[i]);
479 }
480
481 if (sound_alloc_dma(hw_config->dma, hw_config->name)) {
482 printk(KERN_ERR "%s: DMA %d is in use\n", name, hw_config->dma);
483 goto dma_failed;
484 }
485
486 if (request_irq(hw_config->irq, vidc_sound_dma_irq, 0,
487 hw_config->name, &dma_start)) {
488 printk(KERN_ERR "%s: IRQ %d is in use\n", name, hw_config->irq);
489 goto irq_failed;
490 }
491 vidc_adev = adev;
492 vidc_mixer_set(SOUND_MIXER_VOLUME, (85 | 85 << 8));
493
494#if defined(CONFIG_SOUND_SOFTOSS) || defined(CONFIG_SOUND_SOFTOSS_MODULE)
495 softoss_dev = adev;
496#endif
497 return;
498
499irq_failed:
500 sound_free_dma(hw_config->dma);
501dma_failed:
502mem_failed:
503 for (i = 0; i < 2; i++)
504 free_page(dma_buf[i]);
505 sound_unload_mixerdev(audio_devs[adev]->mixer_dev);
506mixer_failed:
507 sound_unload_audiodev(adev);
508audio_failed:
509 return;
510}
511
512static int __init probe_vidc(struct address_info *hw_config)
513{
514 hw_config->irq = IRQ_DMAS0;
515 hw_config->dma = DMA_VIRTUAL_SOUND;
516 hw_config->dma2 = -1;
517 hw_config->card_subtype = 16;
518 hw_config->name = "VIDC20";
519 return 1;
520}
521
522static void __exit unload_vidc(struct address_info *hw_config)
523{
524 int i, adev = vidc_adev;
525
526 vidc_adev = -1;
527
528 free_irq(hw_config->irq, &dma_start);
529 sound_free_dma(hw_config->dma);
530
531 if (adev >= 0) {
532 sound_unload_mixerdev(audio_devs[adev]->mixer_dev);
533 sound_unload_audiodev(adev);
534 for (i = 0; i < 2; i++)
535 free_page(dma_buf[i]);
536 }
537}
538
539static struct address_info cfg;
540
541static int __init init_vidc(void)
542{
543 if (probe_vidc(&cfg) == 0)
544 return -ENODEV;
545
546 attach_vidc(&cfg);
547
548 return 0;
549}
550
551static void __exit cleanup_vidc(void)
552{
553 unload_vidc(&cfg);
554}
555
556module_init(init_vidc);
557module_exit(cleanup_vidc);
558
559MODULE_AUTHOR("Russell King");
560MODULE_DESCRIPTION("VIDC20 audio driver");
561MODULE_LICENSE("GPL");
diff --git a/sound/oss/vidc.h b/sound/oss/vidc.h
new file mode 100644
index 000000000000..bab7044572d3
--- /dev/null
+++ b/sound/oss/vidc.h
@@ -0,0 +1,67 @@
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.c */
14
15extern int vidc_busy;
16
17/* vidc_fill.S */
18
19/*
20 * Filler routines for different channels and sample sizes
21 */
22
23extern unsigned long vidc_fill_1x8_u(unsigned long ibuf, unsigned long iend,
24 unsigned long obuf, int mask);
25extern unsigned long vidc_fill_2x8_u(unsigned long ibuf, unsigned long iend,
26 unsigned long obuf, int mask);
27extern unsigned long vidc_fill_1x8_s(unsigned long ibuf, unsigned long iend,
28 unsigned long obuf, int mask);
29extern unsigned long vidc_fill_2x8_s(unsigned long ibuf, unsigned long iend,
30 unsigned long obuf, int mask);
31extern unsigned long vidc_fill_1x16_s(unsigned long ibuf, unsigned long iend,
32 unsigned long obuf, int mask);
33extern unsigned long vidc_fill_2x16_s(unsigned long ibuf, unsigned long iend,
34 unsigned long obuf, int mask);
35
36/*
37 * DMA Interrupt handler
38 */
39
40extern irqreturn_t vidc_sound_dma_irq(int irqnr, void *ref, struct pt_regs *regs);
41
42/*
43 * Filler routine pointer
44 */
45
46extern unsigned long (*vidc_filler) (unsigned long ibuf, unsigned long iend,
47 unsigned long obuf, int mask);
48
49/*
50 * Virtual DMA buffer exhausted
51 */
52
53extern irqreturn_t (*dma_interrupt) (void);
54
55/*
56 * Virtual DMA buffer addresses
57 */
58
59extern unsigned long dma_start, dma_count, dma_bufsize;
60extern unsigned long dma_buf[2], dma_pbuf[2];
61
62/* vidc_synth.c */
63
64extern void vidc_synth_init(struct address_info *hw_config);
65extern void vidc_synth_exit(struct address_info *hw_config);
66extern int vidc_synth_get_volume(void);
67extern int vidc_synth_set_volume(int vol);
diff --git a/sound/oss/vidc_fill.S b/sound/oss/vidc_fill.S
new file mode 100644
index 000000000000..01ccc074cc11
--- /dev/null
+++ b/sound/oss/vidc_fill.S
@@ -0,0 +1,218 @@
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 <asm/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/vwsnd.c b/sound/oss/vwsnd.c
new file mode 100644
index 000000000000..265423054caf
--- /dev/null
+++ b/sound/oss/vwsnd.c
@@ -0,0 +1,3486 @@
1/*
2 * Sound driver for Silicon Graphics 320 and 540 Visual Workstations'
3 * onboard audio. See notes in Documentation/sound/oss/vwsnd .
4 *
5 * Copyright 1999 Silicon Graphics, Inc. All rights reserved.
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#undef VWSND_DEBUG /* define for debugging */
23
24/*
25 * XXX to do -
26 *
27 * External sync.
28 * Rename swbuf, hwbuf, u&i, hwptr&swptr to something rational.
29 * Bug - if select() called before read(), pcm_setup() not called.
30 * Bug - output doesn't stop soon enough if process killed.
31 */
32
33/*
34 * Things to test -
35 *
36 * Will readv/writev work? Write a test.
37 *
38 * insmod/rmmod 100 million times.
39 *
40 * Run I/O until int ptrs wrap around (roughly 6.2 hours @ DAT
41 * rate).
42 *
43 * Concurrent threads banging on mixer simultaneously, both UP
44 * and SMP kernels. Especially, watch for thread A changing
45 * OUTSRC while thread B changes gain -- both write to the same
46 * ad1843 register.
47 *
48 * What happens if a client opens /dev/audio then forks?
49 * Do two procs have /dev/audio open? Test.
50 *
51 * Pump audio through the CD, MIC and line inputs and verify that
52 * they mix/mute into the output.
53 *
54 * Apps:
55 * amp
56 * mpg123
57 * x11amp
58 * mxv
59 * kmedia
60 * esound
61 * need more input apps
62 *
63 * Run tests while bombarding with signals. setitimer(2) will do it... */
64
65/*
66 * This driver is organized in nine sections.
67 * The nine sections are:
68 *
69 * debug stuff
70 * low level lithium access
71 * high level lithium access
72 * AD1843 access
73 * PCM I/O
74 * audio driver
75 * mixer driver
76 * probe/attach/unload
77 * initialization and loadable kernel module interface
78 *
79 * That is roughly the order of increasing abstraction, so forward
80 * dependencies are minimal.
81 */
82
83/*
84 * Locking Notes
85 *
86 * INC_USE_COUNT and DEC_USE_COUNT keep track of the number of
87 * open descriptors to this driver. They store it in vwsnd_use_count.
88 * The global device list, vwsnd_dev_list, is immutable when the IN_USE
89 * is true.
90 *
91 * devc->open_lock is a semaphore that is used to enforce the
92 * single reader/single writer rule for /dev/audio. The rule is
93 * that each device may have at most one reader and one writer.
94 * Open will block until the previous client has closed the
95 * device, unless O_NONBLOCK is specified.
96 *
97 * The semaphore devc->io_sema serializes PCM I/O syscalls. This
98 * is unnecessary in Linux 2.2, because the kernel lock
99 * serializes read, write, and ioctl globally, but it's there,
100 * ready for the brave, new post-kernel-lock world.
101 *
102 * Locking between interrupt and baselevel is handled by the
103 * "lock" spinlock in vwsnd_port (one lock each for read and
104 * write). Each half holds the lock just long enough to see what
105 * area it owns and update its pointers. See pcm_output() and
106 * pcm_input() for most of the gory stuff.
107 *
108 * devc->mix_sema serializes all mixer ioctls. This is also
109 * redundant because of the kernel lock.
110 *
111 * The lowest level lock is lith->lithium_lock. It is a
112 * spinlock which is held during the two-register tango of
113 * reading/writing an AD1843 register. See
114 * li_{read,write}_ad1843_reg().
115 */
116
117/*
118 * Sample Format Notes
119 *
120 * Lithium's DMA engine has two formats: 16-bit 2's complement
121 * and 8-bit unsigned . 16-bit transfers the data unmodified, 2
122 * bytes per sample. 8-bit unsigned transfers 1 byte per sample
123 * and XORs each byte with 0x80. Lithium can input or output
124 * either mono or stereo in either format.
125 *
126 * The AD1843 has four formats: 16-bit 2's complement, 8-bit
127 * unsigned, 8-bit mu-Law and 8-bit A-Law.
128 *
129 * This driver supports five formats: AFMT_S8, AFMT_U8,
130 * AFMT_MU_LAW, AFMT_A_LAW, and AFMT_S16_LE.
131 *
132 * For AFMT_U8 output, we keep the AD1843 in 16-bit mode, and
133 * rely on Lithium's XOR to translate between U8 and S8.
134 *
135 * For AFMT_S8, AFMT_MU_LAW and AFMT_A_LAW output, we have to XOR
136 * the 0x80 bit in software to compensate for Lithium's XOR.
137 * This happens in pcm_copy_{in,out}().
138 *
139 * Changes:
140 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
141 * Added some __init/__exit
142 */
143
144#include <linux/module.h>
145#include <linux/init.h>
146
147#include <linux/spinlock.h>
148#include <linux/smp_lock.h>
149#include <linux/wait.h>
150#include <linux/interrupt.h>
151#include <asm/semaphore.h>
152#include <asm/mach-visws/cobalt.h>
153
154#include "sound_config.h"
155
156/*****************************************************************************/
157/* debug stuff */
158
159#ifdef VWSND_DEBUG
160
161static int shut_up = 1;
162
163/*
164 * dbgassert - called when an assertion fails.
165 */
166
167static void dbgassert(const char *fcn, int line, const char *expr)
168{
169 if (in_interrupt())
170 panic("ASSERTION FAILED IN INTERRUPT, %s:%s:%d %s\n",
171 __FILE__, fcn, line, expr);
172 else {
173 int x;
174 printk(KERN_ERR "ASSERTION FAILED, %s:%s:%d %s\n",
175 __FILE__, fcn, line, expr);
176 x = * (volatile int *) 0; /* force proc to exit */
177 }
178}
179
180/*
181 * Bunch of useful debug macros:
182 *
183 * ASSERT - print unless e nonzero (panic if in interrupt)
184 * DBGDO - include arbitrary code if debugging
185 * DBGX - debug print raw (w/o function name)
186 * DBGP - debug print w/ function name
187 * DBGE - debug print function entry
188 * DBGC - debug print function call
189 * DBGR - debug print function return
190 * DBGXV - debug print raw when verbose
191 * DBGPV - debug print when verbose
192 * DBGEV - debug print function entry when verbose
193 * DBGRV - debug print function return when verbose
194 */
195
196#define ASSERT(e) ((e) ? (void) 0 : dbgassert(__FUNCTION__, __LINE__, #e))
197#define DBGDO(x) x
198#define DBGX(fmt, args...) (in_interrupt() ? 0 : printk(KERN_ERR fmt, ##args))
199#define DBGP(fmt, args...) (DBGX("%s: " fmt, __FUNCTION__ , ##args))
200#define DBGE(fmt, args...) (DBGX("%s" fmt, __FUNCTION__ , ##args))
201#define DBGC(rtn) (DBGP("calling %s\n", rtn))
202#define DBGR() (DBGP("returning\n"))
203#define DBGXV(fmt, args...) (shut_up ? 0 : DBGX(fmt, ##args))
204#define DBGPV(fmt, args...) (shut_up ? 0 : DBGP(fmt, ##args))
205#define DBGEV(fmt, args...) (shut_up ? 0 : DBGE(fmt, ##args))
206#define DBGCV(rtn) (shut_up ? 0 : DBGC(rtn))
207#define DBGRV() (shut_up ? 0 : DBGR())
208
209#else /* !VWSND_DEBUG */
210
211#define ASSERT(e) ((void) 0)
212#define DBGDO(x) /* don't */
213#define DBGX(fmt, args...) ((void) 0)
214#define DBGP(fmt, args...) ((void) 0)
215#define DBGE(fmt, args...) ((void) 0)
216#define DBGC(rtn) ((void) 0)
217#define DBGR() ((void) 0)
218#define DBGPV(fmt, args...) ((void) 0)
219#define DBGXV(fmt, args...) ((void) 0)
220#define DBGEV(fmt, args...) ((void) 0)
221#define DBGCV(rtn) ((void) 0)
222#define DBGRV() ((void) 0)
223
224#endif /* !VWSND_DEBUG */
225
226/*****************************************************************************/
227/* low level lithium access */
228
229/*
230 * We need to talk to Lithium registers on three pages. Here are
231 * the pages' offsets from the base address (0xFF001000).
232 */
233
234enum {
235 LI_PAGE0_OFFSET = 0x01000 - 0x1000, /* FF001000 */
236 LI_PAGE1_OFFSET = 0x0F000 - 0x1000, /* FF00F000 */
237 LI_PAGE2_OFFSET = 0x10000 - 0x1000, /* FF010000 */
238};
239
240/* low-level lithium data */
241
242typedef struct lithium {
243 void * page0; /* virtual addresses */
244 void * page1;
245 void * page2;
246 spinlock_t lock; /* protects codec and UST/MSC access */
247} lithium_t;
248
249/*
250 * li_create initializes the lithium_t structure and sets up vm mappings
251 * to access the registers.
252 * Returns 0 on success, -errno on failure.
253 */
254
255static int __init li_create(lithium_t *lith, unsigned long baseaddr)
256{
257 static void li_destroy(lithium_t *);
258
259 spin_lock_init(&lith->lock);
260 lith->page0 = ioremap_nocache(baseaddr + LI_PAGE0_OFFSET, PAGE_SIZE);
261 lith->page1 = ioremap_nocache(baseaddr + LI_PAGE1_OFFSET, PAGE_SIZE);
262 lith->page2 = ioremap_nocache(baseaddr + LI_PAGE2_OFFSET, PAGE_SIZE);
263 if (!lith->page0 || !lith->page1 || !lith->page2) {
264 li_destroy(lith);
265 return -ENOMEM;
266 }
267 return 0;
268}
269
270/*
271 * li_destroy destroys the lithium_t structure and vm mappings.
272 */
273
274static void li_destroy(lithium_t *lith)
275{
276 if (lith->page0) {
277 iounmap(lith->page0);
278 lith->page0 = NULL;
279 }
280 if (lith->page1) {
281 iounmap(lith->page1);
282 lith->page1 = NULL;
283 }
284 if (lith->page2) {
285 iounmap(lith->page2);
286 lith->page2 = NULL;
287 }
288}
289
290/*
291 * basic register accessors - read/write long/byte
292 */
293
294static __inline__ unsigned long li_readl(lithium_t *lith, int off)
295{
296 return * (volatile unsigned long *) (lith->page0 + off);
297}
298
299static __inline__ unsigned char li_readb(lithium_t *lith, int off)
300{
301 return * (volatile unsigned char *) (lith->page0 + off);
302}
303
304static __inline__ void li_writel(lithium_t *lith, int off, unsigned long val)
305{
306 * (volatile unsigned long *) (lith->page0 + off) = val;
307}
308
309static __inline__ void li_writeb(lithium_t *lith, int off, unsigned char val)
310{
311 * (volatile unsigned char *) (lith->page0 + off) = val;
312}
313
314/*****************************************************************************/
315/* High Level Lithium Access */
316
317/*
318 * Lithium DMA Notes
319 *
320 * Lithium has two dedicated DMA channels for audio. They are known
321 * as comm1 and comm2 (communication areas 1 and 2). Comm1 is for
322 * input, and comm2 is for output. Each is controlled by three
323 * registers: BASE (base address), CFG (config) and CCTL
324 * (config/control).
325 *
326 * Each DMA channel points to a physically contiguous ring buffer in
327 * main memory of up to 8 Kbytes. (This driver always uses 8 Kb.)
328 * There are three pointers into the ring buffer: read, write, and
329 * trigger. The pointers are 8 bits each. Each pointer points to
330 * 32-byte "chunks" of data. The DMA engine moves 32 bytes at a time,
331 * so there is no finer-granularity control.
332 *
333 * In comm1, the hardware updates the write ptr, and software updates
334 * the read ptr. In comm2, it's the opposite: hardware updates the
335 * read ptr, and software updates the write ptr. I designate the
336 * hardware-updated ptr as the hwptr, and the software-updated ptr as
337 * the swptr.
338 *
339 * The trigger ptr and trigger mask are used to trigger interrupts.
340 * From the Lithium spec, section 5.6.8, revision of 12/15/1998:
341 *
342 * Trigger Mask Value
343 *
344 * A three bit wide field that represents a power of two mask
345 * that is used whenever the trigger pointer is compared to its
346 * respective read or write pointer. A value of zero here
347 * implies a mask of 0xFF and a value of seven implies a mask
348 * 0x01. This value can be used to sub-divide the ring buffer
349 * into pie sections so that interrupts monitor the progress of
350 * hardware from section to section.
351 *
352 * My interpretation of that is, whenever the hw ptr is updated, it is
353 * compared with the trigger ptr, and the result is masked by the
354 * trigger mask. (Actually, by the complement of the trigger mask.)
355 * If the result is zero, an interrupt is triggered. I.e., interrupt
356 * if ((hwptr & ~mask) == (trptr & ~mask)). The mask is formed from
357 * the trigger register value as mask = (1 << (8 - tmreg)) - 1.
358 *
359 * In yet different words, setting tmreg to 0 causes an interrupt after
360 * every 256 DMA chunks (8192 bytes) or once per traversal of the
361 * ring buffer. Setting it to 7 caues an interrupt every 2 DMA chunks
362 * (64 bytes) or 128 times per traversal of the ring buffer.
363 */
364
365/* Lithium register offsets and bit definitions */
366
367#define LI_HOST_CONTROLLER 0x000
368# define LI_HC_RESET 0x00008000
369# define LI_HC_LINK_ENABLE 0x00004000
370# define LI_HC_LINK_FAILURE 0x00000004
371# define LI_HC_LINK_CODEC 0x00000002
372# define LI_HC_LINK_READY 0x00000001
373
374#define LI_INTR_STATUS 0x010
375#define LI_INTR_MASK 0x014
376# define LI_INTR_LINK_ERR 0x00008000
377# define LI_INTR_COMM2_TRIG 0x00000008
378# define LI_INTR_COMM2_UNDERFLOW 0x00000004
379# define LI_INTR_COMM1_TRIG 0x00000002
380# define LI_INTR_COMM1_OVERFLOW 0x00000001
381
382#define LI_CODEC_COMMAND 0x018
383# define LI_CC_BUSY 0x00008000
384# define LI_CC_DIR 0x00000080
385# define LI_CC_DIR_RD LI_CC_DIR
386# define LI_CC_DIR_WR (!LI_CC_DIR)
387# define LI_CC_ADDR_MASK 0x0000007F
388
389#define LI_CODEC_DATA 0x01C
390
391#define LI_COMM1_BASE 0x100
392#define LI_COMM1_CTL 0x104
393# define LI_CCTL_RESET 0x80000000
394# define LI_CCTL_SIZE 0x70000000
395# define LI_CCTL_DMA_ENABLE 0x08000000
396# define LI_CCTL_TMASK 0x07000000 /* trigger mask */
397# define LI_CCTL_TPTR 0x00FF0000 /* trigger pointer */
398# define LI_CCTL_RPTR 0x0000FF00
399# define LI_CCTL_WPTR 0x000000FF
400#define LI_COMM1_CFG 0x108
401# define LI_CCFG_LOCK 0x00008000
402# define LI_CCFG_SLOT 0x00000070
403# define LI_CCFG_DIRECTION 0x00000008
404# define LI_CCFG_DIR_IN (!LI_CCFG_DIRECTION)
405# define LI_CCFG_DIR_OUT LI_CCFG_DIRECTION
406# define LI_CCFG_MODE 0x00000004
407# define LI_CCFG_MODE_MONO (!LI_CCFG_MODE)
408# define LI_CCFG_MODE_STEREO LI_CCFG_MODE
409# define LI_CCFG_FORMAT 0x00000003
410# define LI_CCFG_FMT_8BIT 0x00000000
411# define LI_CCFG_FMT_16BIT 0x00000001
412#define LI_COMM2_BASE 0x10C
413#define LI_COMM2_CTL 0x110
414 /* bit definitions are the same as LI_COMM1_CTL */
415#define LI_COMM2_CFG 0x114
416 /* bit definitions are the same as LI_COMM1_CFG */
417
418#define LI_UST_LOW 0x200 /* 64-bit Unadjusted System Time is */
419#define LI_UST_HIGH 0x204 /* microseconds since boot */
420
421#define LI_AUDIO1_UST 0x300 /* UST-MSC pairs */
422#define LI_AUDIO1_MSC 0x304 /* MSC (Media Stream Counter) */
423#define LI_AUDIO2_UST 0x308 /* counts samples actually */
424#define LI_AUDIO2_MSC 0x30C /* processed as of time UST */
425
426/*
427 * Lithium's DMA engine operates on chunks of 32 bytes. We call that
428 * a DMACHUNK.
429 */
430
431#define DMACHUNK_SHIFT 5
432#define DMACHUNK_SIZE (1 << DMACHUNK_SHIFT)
433#define BYTES_TO_CHUNKS(bytes) ((bytes) >> DMACHUNK_SHIFT)
434#define CHUNKS_TO_BYTES(chunks) ((chunks) << DMACHUNK_SHIFT)
435
436/*
437 * Two convenient macros to shift bitfields into/out of position.
438 *
439 * Observe that (mask & -mask) is (1 << low_set_bit_of(mask)).
440 * As long as mask is constant, we trust the compiler will change the
441 * multipy and divide into shifts.
442 */
443
444#define SHIFT_FIELD(val, mask) (((val) * ((mask) & -(mask))) & (mask))
445#define UNSHIFT_FIELD(val, mask) (((val) & (mask)) / ((mask) & -(mask)))
446
447/*
448 * dma_chan_desc is invariant information about a Lithium
449 * DMA channel. There are two instances, li_comm1 and li_comm2.
450 *
451 * Note that the CCTL register fields are write ptr and read ptr, but what
452 * we care about are which pointer is updated by software and which by
453 * hardware.
454 */
455
456typedef struct dma_chan_desc {
457 int basereg;
458 int cfgreg;
459 int ctlreg;
460 int hwptrreg;
461 int swptrreg;
462 int ustreg;
463 int mscreg;
464 unsigned long swptrmask;
465 int ad1843_slot;
466 int direction; /* LI_CCTL_DIR_IN/OUT */
467} dma_chan_desc_t;
468
469static const dma_chan_desc_t li_comm1 = {
470 LI_COMM1_BASE, /* base register offset */
471 LI_COMM1_CFG, /* config register offset */
472 LI_COMM1_CTL, /* control register offset */
473 LI_COMM1_CTL + 0, /* hw ptr reg offset (write ptr) */
474 LI_COMM1_CTL + 1, /* sw ptr reg offset (read ptr) */
475 LI_AUDIO1_UST, /* ust reg offset */
476 LI_AUDIO1_MSC, /* msc reg offset */
477 LI_CCTL_RPTR, /* sw ptr bitmask in ctlval */
478 2, /* ad1843 serial slot */
479 LI_CCFG_DIR_IN /* direction */
480};
481
482static const dma_chan_desc_t li_comm2 = {
483 LI_COMM2_BASE, /* base register offset */
484 LI_COMM2_CFG, /* config register offset */
485 LI_COMM2_CTL, /* control register offset */
486 LI_COMM2_CTL + 1, /* hw ptr reg offset (read ptr) */
487 LI_COMM2_CTL + 0, /* sw ptr reg offset (writr ptr) */
488 LI_AUDIO2_UST, /* ust reg offset */
489 LI_AUDIO2_MSC, /* msc reg offset */
490 LI_CCTL_WPTR, /* sw ptr bitmask in ctlval */
491 2, /* ad1843 serial slot */
492 LI_CCFG_DIR_OUT /* direction */
493};
494
495/*
496 * dma_chan is variable information about a Lithium DMA channel.
497 *
498 * The desc field points to invariant information.
499 * The lith field points to a lithium_t which is passed
500 * to li_read* and li_write* to access the registers.
501 * The *val fields shadow the lithium registers' contents.
502 */
503
504typedef struct dma_chan {
505 const dma_chan_desc_t *desc;
506 lithium_t *lith;
507 unsigned long baseval;
508 unsigned long cfgval;
509 unsigned long ctlval;
510} dma_chan_t;
511
512/*
513 * ustmsc is a UST/MSC pair (Unadjusted System Time/Media Stream Counter).
514 * UST is time in microseconds since the system booted, and MSC is a
515 * counter that increments with every audio sample.
516 */
517
518typedef struct ustmsc {
519 unsigned long long ust;
520 unsigned long msc;
521} ustmsc_t;
522
523/*
524 * li_ad1843_wait waits until lithium says the AD1843 register
525 * exchange is not busy. Returns 0 on success, -EBUSY on timeout.
526 *
527 * Locking: must be called with lithium_lock held.
528 */
529
530static int li_ad1843_wait(lithium_t *lith)
531{
532 unsigned long later = jiffies + 2;
533 while (li_readl(lith, LI_CODEC_COMMAND) & LI_CC_BUSY)
534 if (time_after_eq(jiffies, later))
535 return -EBUSY;
536 return 0;
537}
538
539/*
540 * li_read_ad1843_reg returns the current contents of a 16 bit AD1843 register.
541 *
542 * Returns unsigned register value on success, -errno on failure.
543 */
544
545static int li_read_ad1843_reg(lithium_t *lith, int reg)
546{
547 int val;
548
549 ASSERT(!in_interrupt());
550 spin_lock(&lith->lock);
551 {
552 val = li_ad1843_wait(lith);
553 if (val == 0) {
554 li_writel(lith, LI_CODEC_COMMAND, LI_CC_DIR_RD | reg);
555 val = li_ad1843_wait(lith);
556 }
557 if (val == 0)
558 val = li_readl(lith, LI_CODEC_DATA);
559 }
560 spin_unlock(&lith->lock);
561
562 DBGXV("li_read_ad1843_reg(lith=0x%p, reg=%d) returns 0x%04x\n",
563 lith, reg, val);
564
565 return val;
566}
567
568/*
569 * li_write_ad1843_reg writes the specified value to a 16 bit AD1843 register.
570 */
571
572static void li_write_ad1843_reg(lithium_t *lith, int reg, int newval)
573{
574 spin_lock(&lith->lock);
575 {
576 if (li_ad1843_wait(lith) == 0) {
577 li_writel(lith, LI_CODEC_DATA, newval);
578 li_writel(lith, LI_CODEC_COMMAND, LI_CC_DIR_WR | reg);
579 }
580 }
581 spin_unlock(&lith->lock);
582}
583
584/*
585 * li_setup_dma calculates all the register settings for DMA in a particular
586 * mode. It takes too many arguments.
587 */
588
589static void li_setup_dma(dma_chan_t *chan,
590 const dma_chan_desc_t *desc,
591 lithium_t *lith,
592 unsigned long buffer_paddr,
593 int bufshift,
594 int fragshift,
595 int channels,
596 int sampsize)
597{
598 unsigned long mode, format;
599 unsigned long size, tmask;
600
601 DBGEV("(chan=0x%p, desc=0x%p, lith=0x%p, buffer_paddr=0x%lx, "
602 "bufshift=%d, fragshift=%d, channels=%d, sampsize=%d)\n",
603 chan, desc, lith, buffer_paddr,
604 bufshift, fragshift, channels, sampsize);
605
606 /* Reset the channel first. */
607
608 li_writel(lith, desc->ctlreg, LI_CCTL_RESET);
609
610 ASSERT(channels == 1 || channels == 2);
611 if (channels == 2)
612 mode = LI_CCFG_MODE_STEREO;
613 else
614 mode = LI_CCFG_MODE_MONO;
615 ASSERT(sampsize == 1 || sampsize == 2);
616 if (sampsize == 2)
617 format = LI_CCFG_FMT_16BIT;
618 else
619 format = LI_CCFG_FMT_8BIT;
620 chan->desc = desc;
621 chan->lith = lith;
622
623 /*
624 * Lithium DMA address register takes a 40-bit physical
625 * address, right-shifted by 8 so it fits in 32 bits. Bit 37
626 * must be set -- it enables cache coherence.
627 */
628
629 ASSERT(!(buffer_paddr & 0xFF));
630 chan->baseval = (buffer_paddr >> 8) | 1 << (37 - 8);
631
632 chan->cfgval = (!LI_CCFG_LOCK |
633 SHIFT_FIELD(desc->ad1843_slot, LI_CCFG_SLOT) |
634 desc->direction |
635 mode |
636 format);
637
638 size = bufshift - 6;
639 tmask = 13 - fragshift; /* See Lithium DMA Notes above. */
640 ASSERT(size >= 2 && size <= 7);
641 ASSERT(tmask >= 1 && tmask <= 7);
642 chan->ctlval = (!LI_CCTL_RESET |
643 SHIFT_FIELD(size, LI_CCTL_SIZE) |
644 !LI_CCTL_DMA_ENABLE |
645 SHIFT_FIELD(tmask, LI_CCTL_TMASK) |
646 SHIFT_FIELD(0, LI_CCTL_TPTR));
647
648 DBGPV("basereg 0x%x = 0x%lx\n", desc->basereg, chan->baseval);
649 DBGPV("cfgreg 0x%x = 0x%lx\n", desc->cfgreg, chan->cfgval);
650 DBGPV("ctlreg 0x%x = 0x%lx\n", desc->ctlreg, chan->ctlval);
651
652 li_writel(lith, desc->basereg, chan->baseval);
653 li_writel(lith, desc->cfgreg, chan->cfgval);
654 li_writel(lith, desc->ctlreg, chan->ctlval);
655
656 DBGRV();
657}
658
659static void li_shutdown_dma(dma_chan_t *chan)
660{
661 lithium_t *lith = chan->lith;
662 void * lith1 = lith->page1;
663
664 DBGEV("(chan=0x%p)\n", chan);
665
666 chan->ctlval &= ~LI_CCTL_DMA_ENABLE;
667 DBGPV("ctlreg 0x%x = 0x%lx\n", chan->desc->ctlreg, chan->ctlval);
668 li_writel(lith, chan->desc->ctlreg, chan->ctlval);
669
670 /*
671 * Offset 0x500 on Lithium page 1 is an undocumented,
672 * unsupported register that holds the zero sample value.
673 * Lithium is supposed to output zero samples when DMA is
674 * inactive, and repeat the last sample when DMA underflows.
675 * But it has a bug, where, after underflow occurs, the zero
676 * sample is not reset.
677 *
678 * I expect this to break in a future rev of Lithium.
679 */
680
681 if (lith1 && chan->desc->direction == LI_CCFG_DIR_OUT)
682 * (volatile unsigned long *) (lith1 + 0x500) = 0;
683}
684
685/*
686 * li_activate_dma always starts dma at the beginning of the buffer.
687 *
688 * N.B., these may be called from interrupt.
689 */
690
691static __inline__ void li_activate_dma(dma_chan_t *chan)
692{
693 chan->ctlval |= LI_CCTL_DMA_ENABLE;
694 DBGPV("ctlval = 0x%lx\n", chan->ctlval);
695 li_writel(chan->lith, chan->desc->ctlreg, chan->ctlval);
696}
697
698static void li_deactivate_dma(dma_chan_t *chan)
699{
700 lithium_t *lith = chan->lith;
701 void * lith2 = lith->page2;
702
703 chan->ctlval &= ~(LI_CCTL_DMA_ENABLE | LI_CCTL_RPTR | LI_CCTL_WPTR);
704 DBGPV("ctlval = 0x%lx\n", chan->ctlval);
705 DBGPV("ctlreg 0x%x = 0x%lx\n", chan->desc->ctlreg, chan->ctlval);
706 li_writel(lith, chan->desc->ctlreg, chan->ctlval);
707
708 /*
709 * Offsets 0x98 and 0x9C on Lithium page 2 are undocumented,
710 * unsupported registers that are internal copies of the DMA
711 * read and write pointers. Because of a Lithium bug, these
712 * registers aren't zeroed correctly when DMA is shut off. So
713 * we whack them directly.
714 *
715 * I expect this to break in a future rev of Lithium.
716 */
717
718 if (lith2 && chan->desc->direction == LI_CCFG_DIR_OUT) {
719 * (volatile unsigned long *) (lith2 + 0x98) = 0;
720 * (volatile unsigned long *) (lith2 + 0x9C) = 0;
721 }
722}
723
724/*
725 * read/write the ring buffer pointers. These routines' arguments and results
726 * are byte offsets from the beginning of the ring buffer.
727 */
728
729static __inline__ int li_read_swptr(dma_chan_t *chan)
730{
731 const unsigned long mask = chan->desc->swptrmask;
732
733 return CHUNKS_TO_BYTES(UNSHIFT_FIELD(chan->ctlval, mask));
734}
735
736static __inline__ int li_read_hwptr(dma_chan_t *chan)
737{
738 return CHUNKS_TO_BYTES(li_readb(chan->lith, chan->desc->hwptrreg));
739}
740
741static __inline__ void li_write_swptr(dma_chan_t *chan, int val)
742{
743 const unsigned long mask = chan->desc->swptrmask;
744
745 ASSERT(!(val & ~CHUNKS_TO_BYTES(0xFF)));
746 val = BYTES_TO_CHUNKS(val);
747 chan->ctlval = (chan->ctlval & ~mask) | SHIFT_FIELD(val, mask);
748 li_writeb(chan->lith, chan->desc->swptrreg, val);
749}
750
751/* li_read_USTMSC() returns a UST/MSC pair for the given channel. */
752
753static void li_read_USTMSC(dma_chan_t *chan, ustmsc_t *ustmsc)
754{
755 lithium_t *lith = chan->lith;
756 const dma_chan_desc_t *desc = chan->desc;
757 unsigned long now_low, now_high0, now_high1, chan_ust;
758
759 spin_lock(&lith->lock);
760 {
761 /*
762 * retry until we do all five reads without the
763 * high word changing. (High word increments
764 * every 2^32 microseconds, i.e., not often)
765 */
766 do {
767 now_high0 = li_readl(lith, LI_UST_HIGH);
768 now_low = li_readl(lith, LI_UST_LOW);
769
770 /*
771 * Lithium guarantees these two reads will be
772 * atomic -- ust will not increment after msc
773 * is read.
774 */
775
776 ustmsc->msc = li_readl(lith, desc->mscreg);
777 chan_ust = li_readl(lith, desc->ustreg);
778
779 now_high1 = li_readl(lith, LI_UST_HIGH);
780 } while (now_high0 != now_high1);
781 }
782 spin_unlock(&lith->lock);
783 ustmsc->ust = ((unsigned long long) now_high0 << 32 | chan_ust);
784}
785
786static void li_enable_interrupts(lithium_t *lith, unsigned int mask)
787{
788 DBGEV("(lith=0x%p, mask=0x%x)\n", lith, mask);
789
790 /* clear any already-pending interrupts. */
791
792 li_writel(lith, LI_INTR_STATUS, mask);
793
794 /* enable the interrupts. */
795
796 mask |= li_readl(lith, LI_INTR_MASK);
797 li_writel(lith, LI_INTR_MASK, mask);
798}
799
800static void li_disable_interrupts(lithium_t *lith, unsigned int mask)
801{
802 unsigned int keepmask;
803
804 DBGEV("(lith=0x%p, mask=0x%x)\n", lith, mask);
805
806 /* disable the interrupts */
807
808 keepmask = li_readl(lith, LI_INTR_MASK) & ~mask;
809 li_writel(lith, LI_INTR_MASK, keepmask);
810
811 /* clear any pending interrupts. */
812
813 li_writel(lith, LI_INTR_STATUS, mask);
814}
815
816/* Get the interrupt status and clear all pending interrupts. */
817
818static unsigned int li_get_clear_intr_status(lithium_t *lith)
819{
820 unsigned int status;
821
822 status = li_readl(lith, LI_INTR_STATUS);
823 li_writel(lith, LI_INTR_STATUS, ~0);
824 return status & li_readl(lith, LI_INTR_MASK);
825}
826
827static int li_init(lithium_t *lith)
828{
829 /* 1. System power supplies stabilize. */
830
831 /* 2. Assert the ~RESET signal. */
832
833 li_writel(lith, LI_HOST_CONTROLLER, LI_HC_RESET);
834 udelay(1);
835
836 /* 3. Deassert the ~RESET signal and enter a wait period to allow
837 the AD1843 internal clocks and the external crystal oscillator
838 to stabilize. */
839
840 li_writel(lith, LI_HOST_CONTROLLER, LI_HC_LINK_ENABLE);
841 udelay(1);
842
843 return 0;
844}
845
846/*****************************************************************************/
847/* AD1843 access */
848
849/*
850 * AD1843 bitfield definitions. All are named as in the AD1843 data
851 * sheet, with ad1843_ prepended and individual bit numbers removed.
852 *
853 * E.g., bits LSS0 through LSS2 become ad1843_LSS.
854 *
855 * Only the bitfields we need are defined.
856 */
857
858typedef struct ad1843_bitfield {
859 char reg;
860 char lo_bit;
861 char nbits;
862} ad1843_bitfield_t;
863
864static const ad1843_bitfield_t
865 ad1843_PDNO = { 0, 14, 1 }, /* Converter Power-Down Flag */
866 ad1843_INIT = { 0, 15, 1 }, /* Clock Initialization Flag */
867 ad1843_RIG = { 2, 0, 4 }, /* Right ADC Input Gain */
868 ad1843_RMGE = { 2, 4, 1 }, /* Right ADC Mic Gain Enable */
869 ad1843_RSS = { 2, 5, 3 }, /* Right ADC Source Select */
870 ad1843_LIG = { 2, 8, 4 }, /* Left ADC Input Gain */
871 ad1843_LMGE = { 2, 12, 1 }, /* Left ADC Mic Gain Enable */
872 ad1843_LSS = { 2, 13, 3 }, /* Left ADC Source Select */
873 ad1843_RX1M = { 4, 0, 5 }, /* Right Aux 1 Mix Gain/Atten */
874 ad1843_RX1MM = { 4, 7, 1 }, /* Right Aux 1 Mix Mute */
875 ad1843_LX1M = { 4, 8, 5 }, /* Left Aux 1 Mix Gain/Atten */
876 ad1843_LX1MM = { 4, 15, 1 }, /* Left Aux 1 Mix Mute */
877 ad1843_RX2M = { 5, 0, 5 }, /* Right Aux 2 Mix Gain/Atten */
878 ad1843_RX2MM = { 5, 7, 1 }, /* Right Aux 2 Mix Mute */
879 ad1843_LX2M = { 5, 8, 5 }, /* Left Aux 2 Mix Gain/Atten */
880 ad1843_LX2MM = { 5, 15, 1 }, /* Left Aux 2 Mix Mute */
881 ad1843_RMCM = { 7, 0, 5 }, /* Right Mic Mix Gain/Atten */
882 ad1843_RMCMM = { 7, 7, 1 }, /* Right Mic Mix Mute */
883 ad1843_LMCM = { 7, 8, 5 }, /* Left Mic Mix Gain/Atten */
884 ad1843_LMCMM = { 7, 15, 1 }, /* Left Mic Mix Mute */
885 ad1843_HPOS = { 8, 4, 1 }, /* Headphone Output Voltage Swing */
886 ad1843_HPOM = { 8, 5, 1 }, /* Headphone Output Mute */
887 ad1843_RDA1G = { 9, 0, 6 }, /* Right DAC1 Analog/Digital Gain */
888 ad1843_RDA1GM = { 9, 7, 1 }, /* Right DAC1 Analog Mute */
889 ad1843_LDA1G = { 9, 8, 6 }, /* Left DAC1 Analog/Digital Gain */
890 ad1843_LDA1GM = { 9, 15, 1 }, /* Left DAC1 Analog Mute */
891 ad1843_RDA1AM = { 11, 7, 1 }, /* Right DAC1 Digital Mute */
892 ad1843_LDA1AM = { 11, 15, 1 }, /* Left DAC1 Digital Mute */
893 ad1843_ADLC = { 15, 0, 2 }, /* ADC Left Sample Rate Source */
894 ad1843_ADRC = { 15, 2, 2 }, /* ADC Right Sample Rate Source */
895 ad1843_DA1C = { 15, 8, 2 }, /* DAC1 Sample Rate Source */
896 ad1843_C1C = { 17, 0, 16 }, /* Clock 1 Sample Rate Select */
897 ad1843_C2C = { 20, 0, 16 }, /* Clock 1 Sample Rate Select */
898 ad1843_DAADL = { 25, 4, 2 }, /* Digital ADC Left Source Select */
899 ad1843_DAADR = { 25, 6, 2 }, /* Digital ADC Right Source Select */
900 ad1843_DRSFLT = { 25, 15, 1 }, /* Digital Reampler Filter Mode */
901 ad1843_ADLF = { 26, 0, 2 }, /* ADC Left Channel Data Format */
902 ad1843_ADRF = { 26, 2, 2 }, /* ADC Right Channel Data Format */
903 ad1843_ADTLK = { 26, 4, 1 }, /* ADC Transmit Lock Mode Select */
904 ad1843_SCF = { 26, 7, 1 }, /* SCLK Frequency Select */
905 ad1843_DA1F = { 26, 8, 2 }, /* DAC1 Data Format Select */
906 ad1843_DA1SM = { 26, 14, 1 }, /* DAC1 Stereo/Mono Mode Select */
907 ad1843_ADLEN = { 27, 0, 1 }, /* ADC Left Channel Enable */
908 ad1843_ADREN = { 27, 1, 1 }, /* ADC Right Channel Enable */
909 ad1843_AAMEN = { 27, 4, 1 }, /* Analog to Analog Mix Enable */
910 ad1843_ANAEN = { 27, 7, 1 }, /* Analog Channel Enable */
911 ad1843_DA1EN = { 27, 8, 1 }, /* DAC1 Enable */
912 ad1843_DA2EN = { 27, 9, 1 }, /* DAC2 Enable */
913 ad1843_C1EN = { 28, 11, 1 }, /* Clock Generator 1 Enable */
914 ad1843_C2EN = { 28, 12, 1 }, /* Clock Generator 2 Enable */
915 ad1843_PDNI = { 28, 15, 1 }; /* Converter Power Down */
916
917/*
918 * The various registers of the AD1843 use three different formats for
919 * specifying gain. The ad1843_gain structure parameterizes the
920 * formats.
921 */
922
923typedef struct ad1843_gain {
924
925 int negative; /* nonzero if gain is negative. */
926 const ad1843_bitfield_t *lfield;
927 const ad1843_bitfield_t *rfield;
928
929} ad1843_gain_t;
930
931static const ad1843_gain_t ad1843_gain_RECLEV
932 = { 0, &ad1843_LIG, &ad1843_RIG };
933static const ad1843_gain_t ad1843_gain_LINE
934 = { 1, &ad1843_LX1M, &ad1843_RX1M };
935static const ad1843_gain_t ad1843_gain_CD
936 = { 1, &ad1843_LX2M, &ad1843_RX2M };
937static const ad1843_gain_t ad1843_gain_MIC
938 = { 1, &ad1843_LMCM, &ad1843_RMCM };
939static const ad1843_gain_t ad1843_gain_PCM
940 = { 1, &ad1843_LDA1G, &ad1843_RDA1G };
941
942/* read the current value of an AD1843 bitfield. */
943
944static int ad1843_read_bits(lithium_t *lith, const ad1843_bitfield_t *field)
945{
946 int w = li_read_ad1843_reg(lith, field->reg);
947 int val = w >> field->lo_bit & ((1 << field->nbits) - 1);
948
949 DBGXV("ad1843_read_bits(lith=0x%p, field->{%d %d %d}) returns 0x%x\n",
950 lith, field->reg, field->lo_bit, field->nbits, val);
951
952 return val;
953}
954
955/*
956 * write a new value to an AD1843 bitfield and return the old value.
957 */
958
959static int ad1843_write_bits(lithium_t *lith,
960 const ad1843_bitfield_t *field,
961 int newval)
962{
963 int w = li_read_ad1843_reg(lith, field->reg);
964 int mask = ((1 << field->nbits) - 1) << field->lo_bit;
965 int oldval = (w & mask) >> field->lo_bit;
966 int newbits = (newval << field->lo_bit) & mask;
967 w = (w & ~mask) | newbits;
968 (void) li_write_ad1843_reg(lith, field->reg, w);
969
970 DBGXV("ad1843_write_bits(lith=0x%p, field->{%d %d %d}, val=0x%x) "
971 "returns 0x%x\n",
972 lith, field->reg, field->lo_bit, field->nbits, newval,
973 oldval);
974
975 return oldval;
976}
977
978/*
979 * ad1843_read_multi reads multiple bitfields from the same AD1843
980 * register. It uses a single read cycle to do it. (Reading the
981 * ad1843 requires 256 bit times at 12.288 MHz, or nearly 20
982 * microseconds.)
983 *
984 * Called ike this.
985 *
986 * ad1843_read_multi(lith, nfields,
987 * &ad1843_FIELD1, &val1,
988 * &ad1843_FIELD2, &val2, ...);
989 */
990
991static void ad1843_read_multi(lithium_t *lith, int argcount, ...)
992{
993 va_list ap;
994 const ad1843_bitfield_t *fp;
995 int w = 0, mask, *value, reg = -1;
996
997 va_start(ap, argcount);
998 while (--argcount >= 0) {
999 fp = va_arg(ap, const ad1843_bitfield_t *);
1000 value = va_arg(ap, int *);
1001 if (reg == -1) {
1002 reg = fp->reg;
1003 w = li_read_ad1843_reg(lith, reg);
1004 }
1005 ASSERT(reg == fp->reg);
1006 mask = (1 << fp->nbits) - 1;
1007 *value = w >> fp->lo_bit & mask;
1008 }
1009 va_end(ap);
1010}
1011
1012/*
1013 * ad1843_write_multi stores multiple bitfields into the same AD1843
1014 * register. It uses one read and one write cycle to do it.
1015 *
1016 * Called like this.
1017 *
1018 * ad1843_write_multi(lith, nfields,
1019 * &ad1843_FIELD1, val1,
1020 * &ad1843_FIELF2, val2, ...);
1021 */
1022
1023static void ad1843_write_multi(lithium_t *lith, int argcount, ...)
1024{
1025 va_list ap;
1026 int reg;
1027 const ad1843_bitfield_t *fp;
1028 int value;
1029 int w, m, mask, bits;
1030
1031 mask = 0;
1032 bits = 0;
1033 reg = -1;
1034
1035 va_start(ap, argcount);
1036 while (--argcount >= 0) {
1037 fp = va_arg(ap, const ad1843_bitfield_t *);
1038 value = va_arg(ap, int);
1039 if (reg == -1)
1040 reg = fp->reg;
1041 ASSERT(fp->reg == reg);
1042 m = ((1 << fp->nbits) - 1) << fp->lo_bit;
1043 mask |= m;
1044 bits |= (value << fp->lo_bit) & m;
1045 }
1046 va_end(ap);
1047 ASSERT(!(bits & ~mask));
1048 if (~mask & 0xFFFF)
1049 w = li_read_ad1843_reg(lith, reg);
1050 else
1051 w = 0;
1052 w = (w & ~mask) | bits;
1053 (void) li_write_ad1843_reg(lith, reg, w);
1054}
1055
1056/*
1057 * ad1843_get_gain reads the specified register and extracts the gain value
1058 * using the supplied gain type. It returns the gain in OSS format.
1059 */
1060
1061static int ad1843_get_gain(lithium_t *lith, const ad1843_gain_t *gp)
1062{
1063 int lg, rg;
1064 unsigned short mask = (1 << gp->lfield->nbits) - 1;
1065
1066 ad1843_read_multi(lith, 2, gp->lfield, &lg, gp->rfield, &rg);
1067 if (gp->negative) {
1068 lg = mask - lg;
1069 rg = mask - rg;
1070 }
1071 lg = (lg * 100 + (mask >> 1)) / mask;
1072 rg = (rg * 100 + (mask >> 1)) / mask;
1073 return lg << 0 | rg << 8;
1074}
1075
1076/*
1077 * Set an audio channel's gain. Converts from OSS format to AD1843's
1078 * format.
1079 *
1080 * Returns the new gain, which may be lower than the old gain.
1081 */
1082
1083static int ad1843_set_gain(lithium_t *lith,
1084 const ad1843_gain_t *gp,
1085 int newval)
1086{
1087 unsigned short mask = (1 << gp->lfield->nbits) - 1;
1088
1089 int lg = newval >> 0 & 0xFF;
1090 int rg = newval >> 8;
1091 if (lg < 0 || lg > 100 || rg < 0 || rg > 100)
1092 return -EINVAL;
1093 lg = (lg * mask + (mask >> 1)) / 100;
1094 rg = (rg * mask + (mask >> 1)) / 100;
1095 if (gp->negative) {
1096 lg = mask - lg;
1097 rg = mask - rg;
1098 }
1099 ad1843_write_multi(lith, 2, gp->lfield, lg, gp->rfield, rg);
1100 return ad1843_get_gain(lith, gp);
1101}
1102
1103/* Returns the current recording source, in OSS format. */
1104
1105static int ad1843_get_recsrc(lithium_t *lith)
1106{
1107 int ls = ad1843_read_bits(lith, &ad1843_LSS);
1108
1109 switch (ls) {
1110 case 1:
1111 return SOUND_MASK_MIC;
1112 case 2:
1113 return SOUND_MASK_LINE;
1114 case 3:
1115 return SOUND_MASK_CD;
1116 case 6:
1117 return SOUND_MASK_PCM;
1118 default:
1119 ASSERT(0);
1120 return -1;
1121 }
1122}
1123
1124/*
1125 * Enable/disable digital resample mode in the AD1843.
1126 *
1127 * The AD1843 requires that ADL, ADR, DA1 and DA2 be powered down
1128 * while switching modes. So we save DA1's state (DA2's state is not
1129 * interesting), power them down, switch into/out of resample mode,
1130 * power them up, and restore state.
1131 *
1132 * This will cause audible glitches if D/A or A/D is going on, so the
1133 * driver disallows that (in mixer_write_ioctl()).
1134 *
1135 * The open question is, is this worth doing? I'm leaving it in,
1136 * because it's written, but...
1137 */
1138
1139static void ad1843_set_resample_mode(lithium_t *lith, int onoff)
1140{
1141 /* Save DA1 mute and gain (addr 9 is DA1 analog gain/attenuation) */
1142 int save_da1 = li_read_ad1843_reg(lith, 9);
1143
1144 /* Power down A/D and D/A. */
1145 ad1843_write_multi(lith, 4,
1146 &ad1843_DA1EN, 0,
1147 &ad1843_DA2EN, 0,
1148 &ad1843_ADLEN, 0,
1149 &ad1843_ADREN, 0);
1150
1151 /* Switch mode */
1152 ASSERT(onoff == 0 || onoff == 1);
1153 ad1843_write_bits(lith, &ad1843_DRSFLT, onoff);
1154
1155 /* Power up A/D and D/A. */
1156 ad1843_write_multi(lith, 3,
1157 &ad1843_DA1EN, 1,
1158 &ad1843_ADLEN, 1,
1159 &ad1843_ADREN, 1);
1160
1161 /* Restore DA1 mute and gain. */
1162 li_write_ad1843_reg(lith, 9, save_da1);
1163}
1164
1165/*
1166 * Set recording source. Arg newsrc specifies an OSS channel mask.
1167 *
1168 * The complication is that when we switch into/out of loopback mode
1169 * (i.e., src = SOUND_MASK_PCM), we change the AD1843 into/out of
1170 * digital resampling mode.
1171 *
1172 * Returns newsrc on success, -errno on failure.
1173 */
1174
1175static int ad1843_set_recsrc(lithium_t *lith, int newsrc)
1176{
1177 int bits;
1178 int oldbits;
1179
1180 switch (newsrc) {
1181 case SOUND_MASK_PCM:
1182 bits = 6;
1183 break;
1184
1185 case SOUND_MASK_MIC:
1186 bits = 1;
1187 break;
1188
1189 case SOUND_MASK_LINE:
1190 bits = 2;
1191 break;
1192
1193 case SOUND_MASK_CD:
1194 bits = 3;
1195 break;
1196
1197 default:
1198 return -EINVAL;
1199 }
1200 oldbits = ad1843_read_bits(lith, &ad1843_LSS);
1201 if (newsrc == SOUND_MASK_PCM && oldbits != 6) {
1202 DBGP("enabling digital resample mode\n");
1203 ad1843_set_resample_mode(lith, 1);
1204 ad1843_write_multi(lith, 2,
1205 &ad1843_DAADL, 2,
1206 &ad1843_DAADR, 2);
1207 } else if (newsrc != SOUND_MASK_PCM && oldbits == 6) {
1208 DBGP("disabling digital resample mode\n");
1209 ad1843_set_resample_mode(lith, 0);
1210 ad1843_write_multi(lith, 2,
1211 &ad1843_DAADL, 0,
1212 &ad1843_DAADR, 0);
1213 }
1214 ad1843_write_multi(lith, 2, &ad1843_LSS, bits, &ad1843_RSS, bits);
1215 return newsrc;
1216}
1217
1218/*
1219 * Return current output sources, in OSS format.
1220 */
1221
1222static int ad1843_get_outsrc(lithium_t *lith)
1223{
1224 int pcm, line, mic, cd;
1225
1226 pcm = ad1843_read_bits(lith, &ad1843_LDA1GM) ? 0 : SOUND_MASK_PCM;
1227 line = ad1843_read_bits(lith, &ad1843_LX1MM) ? 0 : SOUND_MASK_LINE;
1228 cd = ad1843_read_bits(lith, &ad1843_LX2MM) ? 0 : SOUND_MASK_CD;
1229 mic = ad1843_read_bits(lith, &ad1843_LMCMM) ? 0 : SOUND_MASK_MIC;
1230
1231 return pcm | line | cd | mic;
1232}
1233
1234/*
1235 * Set output sources. Arg is a mask of active sources in OSS format.
1236 *
1237 * Returns source mask on success, -errno on failure.
1238 */
1239
1240static int ad1843_set_outsrc(lithium_t *lith, int mask)
1241{
1242 int pcm, line, mic, cd;
1243
1244 if (mask & ~(SOUND_MASK_PCM | SOUND_MASK_LINE |
1245 SOUND_MASK_CD | SOUND_MASK_MIC))
1246 return -EINVAL;
1247 pcm = (mask & SOUND_MASK_PCM) ? 0 : 1;
1248 line = (mask & SOUND_MASK_LINE) ? 0 : 1;
1249 mic = (mask & SOUND_MASK_MIC) ? 0 : 1;
1250 cd = (mask & SOUND_MASK_CD) ? 0 : 1;
1251
1252 ad1843_write_multi(lith, 2, &ad1843_LDA1GM, pcm, &ad1843_RDA1GM, pcm);
1253 ad1843_write_multi(lith, 2, &ad1843_LX1MM, line, &ad1843_RX1MM, line);
1254 ad1843_write_multi(lith, 2, &ad1843_LX2MM, cd, &ad1843_RX2MM, cd);
1255 ad1843_write_multi(lith, 2, &ad1843_LMCMM, mic, &ad1843_RMCMM, mic);
1256
1257 return mask;
1258}
1259
1260/* Setup ad1843 for D/A conversion. */
1261
1262static void ad1843_setup_dac(lithium_t *lith,
1263 int framerate,
1264 int fmt,
1265 int channels)
1266{
1267 int ad_fmt = 0, ad_mode = 0;
1268
1269 DBGEV("(lith=0x%p, framerate=%d, fmt=%d, channels=%d)\n",
1270 lith, framerate, fmt, channels);
1271
1272 switch (fmt) {
1273 case AFMT_S8: ad_fmt = 1; break;
1274 case AFMT_U8: ad_fmt = 1; break;
1275 case AFMT_S16_LE: ad_fmt = 1; break;
1276 case AFMT_MU_LAW: ad_fmt = 2; break;
1277 case AFMT_A_LAW: ad_fmt = 3; break;
1278 default: ASSERT(0);
1279 }
1280
1281 switch (channels) {
1282 case 2: ad_mode = 0; break;
1283 case 1: ad_mode = 1; break;
1284 default: ASSERT(0);
1285 }
1286
1287 DBGPV("ad_mode = %d, ad_fmt = %d\n", ad_mode, ad_fmt);
1288 ASSERT(framerate >= 4000 && framerate <= 49000);
1289 ad1843_write_bits(lith, &ad1843_C1C, framerate);
1290 ad1843_write_multi(lith, 2,
1291 &ad1843_DA1SM, ad_mode, &ad1843_DA1F, ad_fmt);
1292}
1293
1294static void ad1843_shutdown_dac(lithium_t *lith)
1295{
1296 ad1843_write_bits(lith, &ad1843_DA1F, 1);
1297}
1298
1299static void ad1843_setup_adc(lithium_t *lith, int framerate, int fmt, int channels)
1300{
1301 int da_fmt = 0;
1302
1303 DBGEV("(lith=0x%p, framerate=%d, fmt=%d, channels=%d)\n",
1304 lith, framerate, fmt, channels);
1305
1306 switch (fmt) {
1307 case AFMT_S8: da_fmt = 1; break;
1308 case AFMT_U8: da_fmt = 1; break;
1309 case AFMT_S16_LE: da_fmt = 1; break;
1310 case AFMT_MU_LAW: da_fmt = 2; break;
1311 case AFMT_A_LAW: da_fmt = 3; break;
1312 default: ASSERT(0);
1313 }
1314
1315 DBGPV("da_fmt = %d\n", da_fmt);
1316 ASSERT(framerate >= 4000 && framerate <= 49000);
1317 ad1843_write_bits(lith, &ad1843_C2C, framerate);
1318 ad1843_write_multi(lith, 2,
1319 &ad1843_ADLF, da_fmt, &ad1843_ADRF, da_fmt);
1320}
1321
1322static void ad1843_shutdown_adc(lithium_t *lith)
1323{
1324 /* nothing to do */
1325}
1326
1327/*
1328 * Fully initialize the ad1843. As described in the AD1843 data
1329 * sheet, section "START-UP SEQUENCE". The numbered comments are
1330 * subsection headings from the data sheet. See the data sheet, pages
1331 * 52-54, for more info.
1332 *
1333 * return 0 on success, -errno on failure. */
1334
1335static int __init ad1843_init(lithium_t *lith)
1336{
1337 unsigned long later;
1338 int err;
1339
1340 err = li_init(lith);
1341 if (err)
1342 return err;
1343
1344 if (ad1843_read_bits(lith, &ad1843_INIT) != 0) {
1345 printk(KERN_ERR "vwsnd sound: AD1843 won't initialize\n");
1346 return -EIO;
1347 }
1348
1349 ad1843_write_bits(lith, &ad1843_SCF, 1);
1350
1351 /* 4. Put the conversion resources into standby. */
1352
1353 ad1843_write_bits(lith, &ad1843_PDNI, 0);
1354 later = jiffies + HZ / 2; /* roughly half a second */
1355 DBGDO(shut_up++);
1356 while (ad1843_read_bits(lith, &ad1843_PDNO)) {
1357 if (time_after(jiffies, later)) {
1358 printk(KERN_ERR
1359 "vwsnd audio: AD1843 won't power up\n");
1360 return -EIO;
1361 }
1362 schedule();
1363 }
1364 DBGDO(shut_up--);
1365
1366 /* 5. Power up the clock generators and enable clock output pins. */
1367
1368 ad1843_write_multi(lith, 2, &ad1843_C1EN, 1, &ad1843_C2EN, 1);
1369
1370 /* 6. Configure conversion resources while they are in standby. */
1371
1372 /* DAC1 uses clock 1 as source, ADC uses clock 2. Always. */
1373
1374 ad1843_write_multi(lith, 3,
1375 &ad1843_DA1C, 1,
1376 &ad1843_ADLC, 2,
1377 &ad1843_ADRC, 2);
1378
1379 /* 7. Enable conversion resources. */
1380
1381 ad1843_write_bits(lith, &ad1843_ADTLK, 1);
1382 ad1843_write_multi(lith, 5,
1383 &ad1843_ANAEN, 1,
1384 &ad1843_AAMEN, 1,
1385 &ad1843_DA1EN, 1,
1386 &ad1843_ADLEN, 1,
1387 &ad1843_ADREN, 1);
1388
1389 /* 8. Configure conversion resources while they are enabled. */
1390
1391 ad1843_write_bits(lith, &ad1843_DA1C, 1);
1392
1393 /* Unmute all channels. */
1394
1395 ad1843_set_outsrc(lith,
1396 (SOUND_MASK_PCM | SOUND_MASK_LINE |
1397 SOUND_MASK_MIC | SOUND_MASK_CD));
1398 ad1843_write_multi(lith, 2, &ad1843_LDA1AM, 0, &ad1843_RDA1AM, 0);
1399
1400 /* Set default recording source to Line In and set
1401 * mic gain to +20 dB.
1402 */
1403
1404 ad1843_set_recsrc(lith, SOUND_MASK_LINE);
1405 ad1843_write_multi(lith, 2, &ad1843_LMGE, 1, &ad1843_RMGE, 1);
1406
1407 /* Set Speaker Out level to +/- 4V and unmute it. */
1408
1409 ad1843_write_multi(lith, 2, &ad1843_HPOS, 1, &ad1843_HPOM, 0);
1410
1411 return 0;
1412}
1413
1414/*****************************************************************************/
1415/* PCM I/O */
1416
1417#define READ_INTR_MASK (LI_INTR_COMM1_TRIG | LI_INTR_COMM1_OVERFLOW)
1418#define WRITE_INTR_MASK (LI_INTR_COMM2_TRIG | LI_INTR_COMM2_UNDERFLOW)
1419
1420typedef enum vwsnd_port_swstate { /* software state */
1421 SW_OFF,
1422 SW_INITIAL,
1423 SW_RUN,
1424 SW_DRAIN,
1425} vwsnd_port_swstate_t;
1426
1427typedef enum vwsnd_port_hwstate { /* hardware state */
1428 HW_STOPPED,
1429 HW_RUNNING,
1430} vwsnd_port_hwstate_t;
1431
1432/*
1433 * These flags are read by ISR, but only written at baseline.
1434 */
1435
1436typedef enum vwsnd_port_flags {
1437 DISABLED = 1 << 0,
1438 ERFLOWN = 1 << 1, /* overflown or underflown */
1439 HW_BUSY = 1 << 2,
1440} vwsnd_port_flags_t;
1441
1442/*
1443 * vwsnd_port is the per-port data structure. Each device has two
1444 * ports, one for input and one for output.
1445 *
1446 * Locking:
1447 *
1448 * port->lock protects: hwstate, flags, swb_[iu]_avail.
1449 *
1450 * devc->io_sema protects: swstate, sw_*, swb_[iu]_idx.
1451 *
1452 * everything else is only written by open/release or
1453 * pcm_{setup,shutdown}(), which are serialized by a
1454 * combination of devc->open_sema and devc->io_sema.
1455 */
1456
1457typedef struct vwsnd_port {
1458
1459 spinlock_t lock;
1460 wait_queue_head_t queue;
1461 vwsnd_port_swstate_t swstate;
1462 vwsnd_port_hwstate_t hwstate;
1463 vwsnd_port_flags_t flags;
1464
1465 int sw_channels;
1466 int sw_samplefmt;
1467 int sw_framerate;
1468 int sample_size;
1469 int frame_size;
1470 unsigned int zero_word; /* zero for the sample format */
1471
1472 int sw_fragshift;
1473 int sw_fragcount;
1474 int sw_subdivshift;
1475
1476 unsigned int hw_fragshift;
1477 unsigned int hw_fragsize;
1478 unsigned int hw_fragcount;
1479
1480 int hwbuf_size;
1481 unsigned long hwbuf_paddr;
1482 unsigned long hwbuf_vaddr;
1483 void * hwbuf; /* hwbuf == hwbuf_vaddr */
1484 int hwbuf_max; /* max bytes to preload */
1485
1486 void * swbuf;
1487 unsigned int swbuf_size; /* size in bytes */
1488 unsigned int swb_u_idx; /* index of next user byte */
1489 unsigned int swb_i_idx; /* index of next intr byte */
1490 unsigned int swb_u_avail; /* # bytes avail to user */
1491 unsigned int swb_i_avail; /* # bytes avail to intr */
1492
1493 dma_chan_t chan;
1494
1495 /* Accounting */
1496
1497 int byte_count;
1498 int frag_count;
1499 int MSC_offset;
1500
1501} vwsnd_port_t;
1502
1503/* vwsnd_dev is the per-device data structure. */
1504
1505typedef struct vwsnd_dev {
1506 struct vwsnd_dev *next_dev;
1507 int audio_minor; /* minor number of audio device */
1508 int mixer_minor; /* minor number of mixer device */
1509
1510 struct semaphore open_sema;
1511 struct semaphore io_sema;
1512 struct semaphore mix_sema;
1513 mode_t open_mode;
1514 wait_queue_head_t open_wait;
1515
1516 lithium_t lith;
1517
1518 vwsnd_port_t rport;
1519 vwsnd_port_t wport;
1520} vwsnd_dev_t;
1521
1522static vwsnd_dev_t *vwsnd_dev_list; /* linked list of all devices */
1523
1524static atomic_t vwsnd_use_count = ATOMIC_INIT(0);
1525
1526# define INC_USE_COUNT (atomic_inc(&vwsnd_use_count))
1527# define DEC_USE_COUNT (atomic_dec(&vwsnd_use_count))
1528# define IN_USE (atomic_read(&vwsnd_use_count) != 0)
1529
1530/*
1531 * Lithium can only DMA multiples of 32 bytes. Its DMA buffer may
1532 * be up to 8 Kb. This driver always uses 8 Kb.
1533 *
1534 * Memory bug workaround -- I'm not sure what's going on here, but
1535 * somehow pcm_copy_out() was triggering segv's going on to the next
1536 * page of the hw buffer. So, I make the hw buffer one size bigger
1537 * than we actually use. That way, the following page is allocated
1538 * and mapped, and no error. I suspect that something is broken
1539 * in Cobalt, but haven't really investigated. HBO is the actual
1540 * size of the buffer, and HWBUF_ORDER is what we allocate.
1541 */
1542
1543#define HWBUF_SHIFT 13
1544#define HWBUF_SIZE (1 << HWBUF_SHIFT)
1545# define HBO (HWBUF_SHIFT > PAGE_SHIFT ? HWBUF_SHIFT - PAGE_SHIFT : 0)
1546# define HWBUF_ORDER (HBO + 1) /* next size bigger */
1547#define MIN_SPEED 4000
1548#define MAX_SPEED 49000
1549
1550#define MIN_FRAGSHIFT (DMACHUNK_SHIFT + 1)
1551#define MAX_FRAGSHIFT (PAGE_SHIFT)
1552#define MIN_FRAGSIZE (1 << MIN_FRAGSHIFT)
1553#define MAX_FRAGSIZE (1 << MAX_FRAGSHIFT)
1554#define MIN_FRAGCOUNT(fragsize) 3
1555#define MAX_FRAGCOUNT(fragsize) (32 * PAGE_SIZE / (fragsize))
1556#define DEFAULT_FRAGSHIFT 12
1557#define DEFAULT_FRAGCOUNT 16
1558#define DEFAULT_SUBDIVSHIFT 0
1559
1560/*
1561 * The software buffer (swbuf) is a ring buffer shared between user
1562 * level and interrupt level. Each level owns some of the bytes in
1563 * the buffer, and may give bytes away by calling swb_inc_{u,i}().
1564 * User level calls _u for user, and interrupt level calls _i for
1565 * interrupt.
1566 *
1567 * port->swb_{u,i}_avail is the number of bytes available to that level.
1568 *
1569 * port->swb_{u,i}_idx is the index of the first available byte in the
1570 * buffer.
1571 *
1572 * Each level calls swb_inc_{u,i}() to atomically increment its index,
1573 * recalculate the number of bytes available for both sides, and
1574 * return the number of bytes available. Since each side can only
1575 * give away bytes, the other side can only increase the number of
1576 * bytes available to this side. Each side updates its own index
1577 * variable, swb_{u,i}_idx, so no lock is needed to read it.
1578 *
1579 * To query the number of bytes available, call swb_inc_{u,i} with an
1580 * increment of zero.
1581 */
1582
1583static __inline__ unsigned int __swb_inc_u(vwsnd_port_t *port, int inc)
1584{
1585 if (inc) {
1586 port->swb_u_idx += inc;
1587 port->swb_u_idx %= port->swbuf_size;
1588 port->swb_u_avail -= inc;
1589 port->swb_i_avail += inc;
1590 }
1591 return port->swb_u_avail;
1592}
1593
1594static __inline__ unsigned int swb_inc_u(vwsnd_port_t *port, int inc)
1595{
1596 unsigned long flags;
1597 unsigned int ret;
1598
1599 spin_lock_irqsave(&port->lock, flags);
1600 {
1601 ret = __swb_inc_u(port, inc);
1602 }
1603 spin_unlock_irqrestore(&port->lock, flags);
1604 return ret;
1605}
1606
1607static __inline__ unsigned int __swb_inc_i(vwsnd_port_t *port, int inc)
1608{
1609 if (inc) {
1610 port->swb_i_idx += inc;
1611 port->swb_i_idx %= port->swbuf_size;
1612 port->swb_i_avail -= inc;
1613 port->swb_u_avail += inc;
1614 }
1615 return port->swb_i_avail;
1616}
1617
1618static __inline__ unsigned int swb_inc_i(vwsnd_port_t *port, int inc)
1619{
1620 unsigned long flags;
1621 unsigned int ret;
1622
1623 spin_lock_irqsave(&port->lock, flags);
1624 {
1625 ret = __swb_inc_i(port, inc);
1626 }
1627 spin_unlock_irqrestore(&port->lock, flags);
1628 return ret;
1629}
1630
1631/*
1632 * pcm_setup - this routine initializes all port state after
1633 * mode-setting ioctls have been done, but before the first I/O is
1634 * done.
1635 *
1636 * Locking: called with devc->io_sema held.
1637 *
1638 * Returns 0 on success, -errno on failure.
1639 */
1640
1641static int pcm_setup(vwsnd_dev_t *devc,
1642 vwsnd_port_t *rport,
1643 vwsnd_port_t *wport)
1644{
1645 vwsnd_port_t *aport = rport ? rport : wport;
1646 int sample_size;
1647 unsigned int zero_word;
1648
1649 DBGEV("(devc=0x%p, rport=0x%p, wport=0x%p)\n", devc, rport, wport);
1650
1651 ASSERT(aport != NULL);
1652 if (aport->swbuf != NULL)
1653 return 0;
1654 switch (aport->sw_samplefmt) {
1655 case AFMT_MU_LAW:
1656 sample_size = 1;
1657 zero_word = 0xFFFFFFFF ^ 0x80808080;
1658 break;
1659
1660 case AFMT_A_LAW:
1661 sample_size = 1;
1662 zero_word = 0xD5D5D5D5 ^ 0x80808080;
1663 break;
1664
1665 case AFMT_U8:
1666 sample_size = 1;
1667 zero_word = 0x80808080;
1668 break;
1669
1670 case AFMT_S8:
1671 sample_size = 1;
1672 zero_word = 0x00000000;
1673 break;
1674
1675 case AFMT_S16_LE:
1676 sample_size = 2;
1677 zero_word = 0x00000000;
1678 break;
1679
1680 default:
1681 sample_size = 0; /* prevent compiler warning */
1682 zero_word = 0;
1683 ASSERT(0);
1684 }
1685 aport->sample_size = sample_size;
1686 aport->zero_word = zero_word;
1687 aport->frame_size = aport->sw_channels * aport->sample_size;
1688 aport->hw_fragshift = aport->sw_fragshift - aport->sw_subdivshift;
1689 aport->hw_fragsize = 1 << aport->hw_fragshift;
1690 aport->hw_fragcount = aport->sw_fragcount << aport->sw_subdivshift;
1691 ASSERT(aport->hw_fragsize >= MIN_FRAGSIZE);
1692 ASSERT(aport->hw_fragsize <= MAX_FRAGSIZE);
1693 ASSERT(aport->hw_fragcount >= MIN_FRAGCOUNT(aport->hw_fragsize));
1694 ASSERT(aport->hw_fragcount <= MAX_FRAGCOUNT(aport->hw_fragsize));
1695 if (rport) {
1696 int hwfrags, swfrags;
1697 rport->hwbuf_max = aport->hwbuf_size - DMACHUNK_SIZE;
1698 hwfrags = rport->hwbuf_max >> aport->hw_fragshift;
1699 swfrags = aport->hw_fragcount - hwfrags;
1700 if (swfrags < 2)
1701 swfrags = 2;
1702 rport->swbuf_size = swfrags * aport->hw_fragsize;
1703 DBGPV("hwfrags = %d, swfrags = %d\n", hwfrags, swfrags);
1704 DBGPV("read hwbuf_max = %d, swbuf_size = %d\n",
1705 rport->hwbuf_max, rport->swbuf_size);
1706 }
1707 if (wport) {
1708 int hwfrags, swfrags;
1709 int total_bytes = aport->hw_fragcount * aport->hw_fragsize;
1710 wport->hwbuf_max = aport->hwbuf_size - DMACHUNK_SIZE;
1711 if (wport->hwbuf_max > total_bytes)
1712 wport->hwbuf_max = total_bytes;
1713 hwfrags = wport->hwbuf_max >> aport->hw_fragshift;
1714 DBGPV("hwfrags = %d\n", hwfrags);
1715 swfrags = aport->hw_fragcount - hwfrags;
1716 if (swfrags < 2)
1717 swfrags = 2;
1718 wport->swbuf_size = swfrags * aport->hw_fragsize;
1719 DBGPV("hwfrags = %d, swfrags = %d\n", hwfrags, swfrags);
1720 DBGPV("write hwbuf_max = %d, swbuf_size = %d\n",
1721 wport->hwbuf_max, wport->swbuf_size);
1722 }
1723
1724 aport->swb_u_idx = 0;
1725 aport->swb_i_idx = 0;
1726 aport->byte_count = 0;
1727
1728 /*
1729 * Is this a Cobalt bug? We need to make this buffer extend
1730 * one page further than we actually use -- somehow memcpy
1731 * causes an exceptoin otherwise. I suspect there's a bug in
1732 * Cobalt (or somewhere) where it's generating a fault on a
1733 * speculative load or something. Obviously, I haven't taken
1734 * the time to track it down.
1735 */
1736
1737 aport->swbuf = vmalloc(aport->swbuf_size + PAGE_SIZE);
1738 if (!aport->swbuf)
1739 return -ENOMEM;
1740 if (rport && wport) {
1741 ASSERT(aport == rport);
1742 ASSERT(wport->swbuf == NULL);
1743 /* One extra page - see comment above. */
1744 wport->swbuf = vmalloc(aport->swbuf_size + PAGE_SIZE);
1745 if (!wport->swbuf) {
1746 vfree(aport->swbuf);
1747 aport->swbuf = NULL;
1748 return -ENOMEM;
1749 }
1750 wport->sample_size = rport->sample_size;
1751 wport->zero_word = rport->zero_word;
1752 wport->frame_size = rport->frame_size;
1753 wport->hw_fragshift = rport->hw_fragshift;
1754 wport->hw_fragsize = rport->hw_fragsize;
1755 wport->hw_fragcount = rport->hw_fragcount;
1756 wport->swbuf_size = rport->swbuf_size;
1757 wport->hwbuf_max = rport->hwbuf_max;
1758 wport->swb_u_idx = rport->swb_u_idx;
1759 wport->swb_i_idx = rport->swb_i_idx;
1760 wport->byte_count = rport->byte_count;
1761 }
1762 if (rport) {
1763 rport->swb_u_avail = 0;
1764 rport->swb_i_avail = rport->swbuf_size;
1765 rport->swstate = SW_RUN;
1766 li_setup_dma(&rport->chan,
1767 &li_comm1,
1768 &devc->lith,
1769 rport->hwbuf_paddr,
1770 HWBUF_SHIFT,
1771 rport->hw_fragshift,
1772 rport->sw_channels,
1773 rport->sample_size);
1774 ad1843_setup_adc(&devc->lith,
1775 rport->sw_framerate,
1776 rport->sw_samplefmt,
1777 rport->sw_channels);
1778 li_enable_interrupts(&devc->lith, READ_INTR_MASK);
1779 if (!(rport->flags & DISABLED)) {
1780 ustmsc_t ustmsc;
1781 rport->hwstate = HW_RUNNING;
1782 li_activate_dma(&rport->chan);
1783 li_read_USTMSC(&rport->chan, &ustmsc);
1784 rport->MSC_offset = ustmsc.msc;
1785 }
1786 }
1787 if (wport) {
1788 if (wport->hwbuf_max > wport->swbuf_size)
1789 wport->hwbuf_max = wport->swbuf_size;
1790 wport->flags &= ~ERFLOWN;
1791 wport->swb_u_avail = wport->swbuf_size;
1792 wport->swb_i_avail = 0;
1793 wport->swstate = SW_RUN;
1794 li_setup_dma(&wport->chan,
1795 &li_comm2,
1796 &devc->lith,
1797 wport->hwbuf_paddr,
1798 HWBUF_SHIFT,
1799 wport->hw_fragshift,
1800 wport->sw_channels,
1801 wport->sample_size);
1802 ad1843_setup_dac(&devc->lith,
1803 wport->sw_framerate,
1804 wport->sw_samplefmt,
1805 wport->sw_channels);
1806 li_enable_interrupts(&devc->lith, WRITE_INTR_MASK);
1807 }
1808 DBGRV();
1809 return 0;
1810}
1811
1812/*
1813 * pcm_shutdown_port - shut down one port (direction) for PCM I/O.
1814 * Only called from pcm_shutdown.
1815 */
1816
1817static void pcm_shutdown_port(vwsnd_dev_t *devc,
1818 vwsnd_port_t *aport,
1819 unsigned int mask)
1820{
1821 unsigned long flags;
1822 vwsnd_port_hwstate_t hwstate;
1823 DECLARE_WAITQUEUE(wait, current);
1824
1825 aport->swstate = SW_INITIAL;
1826 add_wait_queue(&aport->queue, &wait);
1827 while (1) {
1828 set_current_state(TASK_UNINTERRUPTIBLE);
1829 spin_lock_irqsave(&aport->lock, flags);
1830 {
1831 hwstate = aport->hwstate;
1832 }
1833 spin_unlock_irqrestore(&aport->lock, flags);
1834 if (hwstate == HW_STOPPED)
1835 break;
1836 schedule();
1837 }
1838 current->state = TASK_RUNNING;
1839 remove_wait_queue(&aport->queue, &wait);
1840 li_disable_interrupts(&devc->lith, mask);
1841 if (aport == &devc->rport)
1842 ad1843_shutdown_adc(&devc->lith);
1843 else /* aport == &devc->wport) */
1844 ad1843_shutdown_dac(&devc->lith);
1845 li_shutdown_dma(&aport->chan);
1846 vfree(aport->swbuf);
1847 aport->swbuf = NULL;
1848 aport->byte_count = 0;
1849}
1850
1851/*
1852 * pcm_shutdown undoes what pcm_setup did.
1853 * Also sets the ports' swstate to newstate.
1854 */
1855
1856static void pcm_shutdown(vwsnd_dev_t *devc,
1857 vwsnd_port_t *rport,
1858 vwsnd_port_t *wport)
1859{
1860 DBGEV("(devc=0x%p, rport=0x%p, wport=0x%p)\n", devc, rport, wport);
1861
1862 if (rport && rport->swbuf) {
1863 DBGPV("shutting down rport\n");
1864 pcm_shutdown_port(devc, rport, READ_INTR_MASK);
1865 }
1866 if (wport && wport->swbuf) {
1867 DBGPV("shutting down wport\n");
1868 pcm_shutdown_port(devc, wport, WRITE_INTR_MASK);
1869 }
1870 DBGRV();
1871}
1872
1873static void pcm_copy_in(vwsnd_port_t *rport, int swidx, int hwidx, int nb)
1874{
1875 char *src = rport->hwbuf + hwidx;
1876 char *dst = rport->swbuf + swidx;
1877 int fmt = rport->sw_samplefmt;
1878
1879 DBGPV("swidx = %d, hwidx = %d\n", swidx, hwidx);
1880 ASSERT(rport->hwbuf != NULL);
1881 ASSERT(rport->swbuf != NULL);
1882 ASSERT(nb > 0 && (nb % 32) == 0);
1883 ASSERT(swidx % 32 == 0 && hwidx % 32 == 0);
1884 ASSERT(swidx >= 0 && swidx + nb <= rport->swbuf_size);
1885 ASSERT(hwidx >= 0 && hwidx + nb <= rport->hwbuf_size);
1886
1887 if (fmt == AFMT_MU_LAW || fmt == AFMT_A_LAW || fmt == AFMT_S8) {
1888
1889 /* See Sample Format Notes above. */
1890
1891 char *end = src + nb;
1892 while (src < end)
1893 *dst++ = *src++ ^ 0x80;
1894 } else
1895 memcpy(dst, src, nb);
1896}
1897
1898static void pcm_copy_out(vwsnd_port_t *wport, int swidx, int hwidx, int nb)
1899{
1900 char *src = wport->swbuf + swidx;
1901 char *dst = wport->hwbuf + hwidx;
1902 int fmt = wport->sw_samplefmt;
1903
1904 ASSERT(nb > 0 && (nb % 32) == 0);
1905 ASSERT(wport->hwbuf != NULL);
1906 ASSERT(wport->swbuf != NULL);
1907 ASSERT(swidx % 32 == 0 && hwidx % 32 == 0);
1908 ASSERT(swidx >= 0 && swidx + nb <= wport->swbuf_size);
1909 ASSERT(hwidx >= 0 && hwidx + nb <= wport->hwbuf_size);
1910 if (fmt == AFMT_MU_LAW || fmt == AFMT_A_LAW || fmt == AFMT_S8) {
1911
1912 /* See Sample Format Notes above. */
1913
1914 char *end = src + nb;
1915 while (src < end)
1916 *dst++ = *src++ ^ 0x80;
1917 } else
1918 memcpy(dst, src, nb);
1919}
1920
1921/*
1922 * pcm_output() is called both from baselevel and from interrupt level.
1923 * This is where audio frames are copied into the hardware-accessible
1924 * ring buffer.
1925 *
1926 * Locking note: The part of this routine that figures out what to do
1927 * holds wport->lock. The longer part releases wport->lock, but sets
1928 * wport->flags & HW_BUSY. Afterward, it reacquires wport->lock, and
1929 * checks for more work to do.
1930 *
1931 * If another thread calls pcm_output() while HW_BUSY is set, it
1932 * returns immediately, knowing that the thread that set HW_BUSY will
1933 * look for more work to do before returning.
1934 *
1935 * This has the advantage that port->lock is held for several short
1936 * periods instead of one long period. Also, when pcm_output is
1937 * called from base level, it reenables interrupts.
1938 */
1939
1940static void pcm_output(vwsnd_dev_t *devc, int erflown, int nb)
1941{
1942 vwsnd_port_t *wport = &devc->wport;
1943 const int hwmax = wport->hwbuf_max;
1944 const int hwsize = wport->hwbuf_size;
1945 const int swsize = wport->swbuf_size;
1946 const int fragsize = wport->hw_fragsize;
1947 unsigned long iflags;
1948
1949 DBGEV("(devc=0x%p, erflown=%d, nb=%d)\n", devc, erflown, nb);
1950 spin_lock_irqsave(&wport->lock, iflags);
1951 if (erflown)
1952 wport->flags |= ERFLOWN;
1953 (void) __swb_inc_u(wport, nb);
1954 if (wport->flags & HW_BUSY) {
1955 spin_unlock_irqrestore(&wport->lock, iflags);
1956 DBGPV("returning: HW BUSY\n");
1957 return;
1958 }
1959 if (wport->flags & DISABLED) {
1960 spin_unlock_irqrestore(&wport->lock, iflags);
1961 DBGPV("returning: DISABLED\n");
1962 return;
1963 }
1964 wport->flags |= HW_BUSY;
1965 while (1) {
1966 int swptr, hwptr, hw_avail, sw_avail, swidx;
1967 vwsnd_port_hwstate_t hwstate = wport->hwstate;
1968 vwsnd_port_swstate_t swstate = wport->swstate;
1969 int hw_unavail;
1970 ustmsc_t ustmsc;
1971
1972 hwptr = li_read_hwptr(&wport->chan);
1973 swptr = li_read_swptr(&wport->chan);
1974 hw_unavail = (swptr - hwptr + hwsize) % hwsize;
1975 hw_avail = (hwmax - hw_unavail) & -fragsize;
1976 sw_avail = wport->swb_i_avail & -fragsize;
1977 if (sw_avail && swstate == SW_RUN) {
1978 if (wport->flags & ERFLOWN) {
1979 wport->flags &= ~ERFLOWN;
1980 }
1981 } else if (swstate == SW_INITIAL ||
1982 swstate == SW_OFF ||
1983 (swstate == SW_DRAIN &&
1984 !sw_avail &&
1985 (wport->flags & ERFLOWN))) {
1986 DBGP("stopping. hwstate = %d\n", hwstate);
1987 if (hwstate != HW_STOPPED) {
1988 li_deactivate_dma(&wport->chan);
1989 wport->hwstate = HW_STOPPED;
1990 }
1991 wake_up(&wport->queue);
1992 break;
1993 }
1994 if (!sw_avail || !hw_avail)
1995 break;
1996 spin_unlock_irqrestore(&wport->lock, iflags);
1997
1998 /*
1999 * We gave up the port lock, but we have the HW_BUSY flag.
2000 * Proceed without accessing any nonlocal state.
2001 * Do not exit the loop -- must check for more work.
2002 */
2003
2004 swidx = wport->swb_i_idx;
2005 nb = hw_avail;
2006 if (nb > sw_avail)
2007 nb = sw_avail;
2008 if (nb > hwsize - swptr)
2009 nb = hwsize - swptr; /* don't overflow hwbuf */
2010 if (nb > swsize - swidx)
2011 nb = swsize - swidx; /* don't overflow swbuf */
2012 ASSERT(nb > 0);
2013 if (nb % fragsize) {
2014 DBGP("nb = %d, fragsize = %d\n", nb, fragsize);
2015 DBGP("hw_avail = %d\n", hw_avail);
2016 DBGP("sw_avail = %d\n", sw_avail);
2017 DBGP("hwsize = %d, swptr = %d\n", hwsize, swptr);
2018 DBGP("swsize = %d, swidx = %d\n", swsize, swidx);
2019 }
2020 ASSERT(!(nb % fragsize));
2021 DBGPV("copying swb[%d..%d] to hwb[%d..%d]\n",
2022 swidx, swidx + nb, swptr, swptr + nb);
2023 pcm_copy_out(wport, swidx, swptr, nb);
2024 li_write_swptr(&wport->chan, (swptr + nb) % hwsize);
2025 spin_lock_irqsave(&wport->lock, iflags);
2026 if (hwstate == HW_STOPPED) {
2027 DBGPV("starting\n");
2028 li_activate_dma(&wport->chan);
2029 wport->hwstate = HW_RUNNING;
2030 li_read_USTMSC(&wport->chan, &ustmsc);
2031 ASSERT(wport->byte_count % wport->frame_size == 0);
2032 wport->MSC_offset = ustmsc.msc - wport->byte_count / wport->frame_size;
2033 }
2034 __swb_inc_i(wport, nb);
2035 wport->byte_count += nb;
2036 wport->frag_count += nb / fragsize;
2037 ASSERT(nb % fragsize == 0);
2038 wake_up(&wport->queue);
2039 }
2040 wport->flags &= ~HW_BUSY;
2041 spin_unlock_irqrestore(&wport->lock, iflags);
2042 DBGRV();
2043}
2044
2045/*
2046 * pcm_input() is called both from baselevel and from interrupt level.
2047 * This is where audio frames are copied out of the hardware-accessible
2048 * ring buffer.
2049 *
2050 * Locking note: The part of this routine that figures out what to do
2051 * holds rport->lock. The longer part releases rport->lock, but sets
2052 * rport->flags & HW_BUSY. Afterward, it reacquires rport->lock, and
2053 * checks for more work to do.
2054 *
2055 * If another thread calls pcm_input() while HW_BUSY is set, it
2056 * returns immediately, knowing that the thread that set HW_BUSY will
2057 * look for more work to do before returning.
2058 *
2059 * This has the advantage that port->lock is held for several short
2060 * periods instead of one long period. Also, when pcm_input is
2061 * called from base level, it reenables interrupts.
2062 */
2063
2064static void pcm_input(vwsnd_dev_t *devc, int erflown, int nb)
2065{
2066 vwsnd_port_t *rport = &devc->rport;
2067 const int hwmax = rport->hwbuf_max;
2068 const int hwsize = rport->hwbuf_size;
2069 const int swsize = rport->swbuf_size;
2070 const int fragsize = rport->hw_fragsize;
2071 unsigned long iflags;
2072
2073 DBGEV("(devc=0x%p, erflown=%d, nb=%d)\n", devc, erflown, nb);
2074
2075 spin_lock_irqsave(&rport->lock, iflags);
2076 if (erflown)
2077 rport->flags |= ERFLOWN;
2078 (void) __swb_inc_u(rport, nb);
2079 if (rport->flags & HW_BUSY || !rport->swbuf) {
2080 spin_unlock_irqrestore(&rport->lock, iflags);
2081 DBGPV("returning: HW BUSY or !swbuf\n");
2082 return;
2083 }
2084 if (rport->flags & DISABLED) {
2085 spin_unlock_irqrestore(&rport->lock, iflags);
2086 DBGPV("returning: DISABLED\n");
2087 return;
2088 }
2089 rport->flags |= HW_BUSY;
2090 while (1) {
2091 int swptr, hwptr, hw_avail, sw_avail, swidx;
2092 vwsnd_port_hwstate_t hwstate = rport->hwstate;
2093 vwsnd_port_swstate_t swstate = rport->swstate;
2094
2095 hwptr = li_read_hwptr(&rport->chan);
2096 swptr = li_read_swptr(&rport->chan);
2097 hw_avail = (hwptr - swptr + hwsize) % hwsize & -fragsize;
2098 if (hw_avail > hwmax)
2099 hw_avail = hwmax;
2100 sw_avail = rport->swb_i_avail & -fragsize;
2101 if (swstate != SW_RUN) {
2102 DBGP("stopping. hwstate = %d\n", hwstate);
2103 if (hwstate != HW_STOPPED) {
2104 li_deactivate_dma(&rport->chan);
2105 rport->hwstate = HW_STOPPED;
2106 }
2107 wake_up(&rport->queue);
2108 break;
2109 }
2110 if (!sw_avail || !hw_avail)
2111 break;
2112 spin_unlock_irqrestore(&rport->lock, iflags);
2113
2114 /*
2115 * We gave up the port lock, but we have the HW_BUSY flag.
2116 * Proceed without accessing any nonlocal state.
2117 * Do not exit the loop -- must check for more work.
2118 */
2119
2120 swidx = rport->swb_i_idx;
2121 nb = hw_avail;
2122 if (nb > sw_avail)
2123 nb = sw_avail;
2124 if (nb > hwsize - swptr)
2125 nb = hwsize - swptr; /* don't overflow hwbuf */
2126 if (nb > swsize - swidx)
2127 nb = swsize - swidx; /* don't overflow swbuf */
2128 ASSERT(nb > 0);
2129 if (nb % fragsize) {
2130 DBGP("nb = %d, fragsize = %d\n", nb, fragsize);
2131 DBGP("hw_avail = %d\n", hw_avail);
2132 DBGP("sw_avail = %d\n", sw_avail);
2133 DBGP("hwsize = %d, swptr = %d\n", hwsize, swptr);
2134 DBGP("swsize = %d, swidx = %d\n", swsize, swidx);
2135 }
2136 ASSERT(!(nb % fragsize));
2137 DBGPV("copying hwb[%d..%d] to swb[%d..%d]\n",
2138 swptr, swptr + nb, swidx, swidx + nb);
2139 pcm_copy_in(rport, swidx, swptr, nb);
2140 li_write_swptr(&rport->chan, (swptr + nb) % hwsize);
2141 spin_lock_irqsave(&rport->lock, iflags);
2142 __swb_inc_i(rport, nb);
2143 rport->byte_count += nb;
2144 rport->frag_count += nb / fragsize;
2145 ASSERT(nb % fragsize == 0);
2146 wake_up(&rport->queue);
2147 }
2148 rport->flags &= ~HW_BUSY;
2149 spin_unlock_irqrestore(&rport->lock, iflags);
2150 DBGRV();
2151}
2152
2153/*
2154 * pcm_flush_frag() writes zero samples to fill the current fragment,
2155 * then flushes it to the hardware.
2156 *
2157 * It is only meaningful to flush output, not input.
2158 */
2159
2160static void pcm_flush_frag(vwsnd_dev_t *devc)
2161{
2162 vwsnd_port_t *wport = &devc->wport;
2163
2164 DBGPV("swstate = %d\n", wport->swstate);
2165 if (wport->swstate == SW_RUN) {
2166 int idx = wport->swb_u_idx;
2167 int end = (idx + wport->hw_fragsize - 1)
2168 >> wport->hw_fragshift
2169 << wport->hw_fragshift;
2170 int nb = end - idx;
2171 DBGPV("clearing %d bytes\n", nb);
2172 if (nb)
2173 memset(wport->swbuf + idx,
2174 (char) wport->zero_word,
2175 nb);
2176 wport->swstate = SW_DRAIN;
2177 pcm_output(devc, 0, nb);
2178 }
2179 DBGRV();
2180}
2181
2182/*
2183 * Wait for output to drain. This sleeps uninterruptibly because
2184 * there is nothing intelligent we can do if interrupted. This
2185 * means the process will be delayed in responding to the signal.
2186 */
2187
2188static void pcm_write_sync(vwsnd_dev_t *devc)
2189{
2190 vwsnd_port_t *wport = &devc->wport;
2191 DECLARE_WAITQUEUE(wait, current);
2192 unsigned long flags;
2193 vwsnd_port_hwstate_t hwstate;
2194
2195 DBGEV("(devc=0x%p)\n", devc);
2196 add_wait_queue(&wport->queue, &wait);
2197 while (1) {
2198 set_current_state(TASK_UNINTERRUPTIBLE);
2199 spin_lock_irqsave(&wport->lock, flags);
2200 {
2201 hwstate = wport->hwstate;
2202 }
2203 spin_unlock_irqrestore(&wport->lock, flags);
2204 if (hwstate == HW_STOPPED)
2205 break;
2206 schedule();
2207 }
2208 current->state = TASK_RUNNING;
2209 remove_wait_queue(&wport->queue, &wait);
2210 DBGPV("swstate = %d, hwstate = %d\n", wport->swstate, wport->hwstate);
2211 DBGRV();
2212}
2213
2214/*****************************************************************************/
2215/* audio driver */
2216
2217/*
2218 * seek on an audio device always fails.
2219 */
2220
2221static void vwsnd_audio_read_intr(vwsnd_dev_t *devc, unsigned int status)
2222{
2223 int overflown = status & LI_INTR_COMM1_OVERFLOW;
2224
2225 if (status & READ_INTR_MASK)
2226 pcm_input(devc, overflown, 0);
2227}
2228
2229static void vwsnd_audio_write_intr(vwsnd_dev_t *devc, unsigned int status)
2230{
2231 int underflown = status & LI_INTR_COMM2_UNDERFLOW;
2232
2233 if (status & WRITE_INTR_MASK)
2234 pcm_output(devc, underflown, 0);
2235}
2236
2237static irqreturn_t vwsnd_audio_intr(int irq, void *dev_id, struct pt_regs *regs)
2238{
2239 vwsnd_dev_t *devc = (vwsnd_dev_t *) dev_id;
2240 unsigned int status;
2241
2242 DBGEV("(irq=%d, dev_id=0x%p, regs=0x%p)\n", irq, dev_id, regs);
2243
2244 status = li_get_clear_intr_status(&devc->lith);
2245 vwsnd_audio_read_intr(devc, status);
2246 vwsnd_audio_write_intr(devc, status);
2247 return IRQ_HANDLED;
2248}
2249
2250static ssize_t vwsnd_audio_do_read(struct file *file,
2251 char *buffer,
2252 size_t count,
2253 loff_t *ppos)
2254{
2255 vwsnd_dev_t *devc = file->private_data;
2256 vwsnd_port_t *rport = ((file->f_mode & FMODE_READ) ?
2257 &devc->rport : NULL);
2258 int ret, nb;
2259
2260 DBGEV("(file=0x%p, buffer=0x%p, count=%d, ppos=0x%p)\n",
2261 file, buffer, count, ppos);
2262
2263 if (!rport)
2264 return -EINVAL;
2265
2266 if (rport->swbuf == NULL) {
2267 vwsnd_port_t *wport = (file->f_mode & FMODE_WRITE) ?
2268 &devc->wport : NULL;
2269 ret = pcm_setup(devc, rport, wport);
2270 if (ret < 0)
2271 return ret;
2272 }
2273
2274 if (!access_ok(VERIFY_READ, buffer, count))
2275 return -EFAULT;
2276 ret = 0;
2277 while (count) {
2278 DECLARE_WAITQUEUE(wait, current);
2279 add_wait_queue(&rport->queue, &wait);
2280 while ((nb = swb_inc_u(rport, 0)) == 0) {
2281 DBGPV("blocking\n");
2282 set_current_state(TASK_INTERRUPTIBLE);
2283 if (rport->flags & DISABLED ||
2284 file->f_flags & O_NONBLOCK) {
2285 current->state = TASK_RUNNING;
2286 remove_wait_queue(&rport->queue, &wait);
2287 return ret ? ret : -EAGAIN;
2288 }
2289 schedule();
2290 if (signal_pending(current)) {
2291 current->state = TASK_RUNNING;
2292 remove_wait_queue(&rport->queue, &wait);
2293 return ret ? ret : -ERESTARTSYS;
2294 }
2295 }
2296 current->state = TASK_RUNNING;
2297 remove_wait_queue(&rport->queue, &wait);
2298 pcm_input(devc, 0, 0);
2299 /* nb bytes are available in userbuf. */
2300 if (nb > count)
2301 nb = count;
2302 DBGPV("nb = %d\n", nb);
2303 if (copy_to_user(buffer, rport->swbuf + rport->swb_u_idx, nb))
2304 return -EFAULT;
2305 (void) swb_inc_u(rport, nb);
2306 buffer += nb;
2307 count -= nb;
2308 ret += nb;
2309 }
2310 DBGPV("returning %d\n", ret);
2311 return ret;
2312}
2313
2314static ssize_t vwsnd_audio_read(struct file *file,
2315 char *buffer,
2316 size_t count,
2317 loff_t *ppos)
2318{
2319 vwsnd_dev_t *devc = file->private_data;
2320 ssize_t ret;
2321
2322 down(&devc->io_sema);
2323 ret = vwsnd_audio_do_read(file, buffer, count, ppos);
2324 up(&devc->io_sema);
2325 return ret;
2326}
2327
2328static ssize_t vwsnd_audio_do_write(struct file *file,
2329 const char *buffer,
2330 size_t count,
2331 loff_t *ppos)
2332{
2333 vwsnd_dev_t *devc = file->private_data;
2334 vwsnd_port_t *wport = ((file->f_mode & FMODE_WRITE) ?
2335 &devc->wport : NULL);
2336 int ret, nb;
2337
2338 DBGEV("(file=0x%p, buffer=0x%p, count=%d, ppos=0x%p)\n",
2339 file, buffer, count, ppos);
2340
2341 if (!wport)
2342 return -EINVAL;
2343
2344 if (wport->swbuf == NULL) {
2345 vwsnd_port_t *rport = (file->f_mode & FMODE_READ) ?
2346 &devc->rport : NULL;
2347 ret = pcm_setup(devc, rport, wport);
2348 if (ret < 0)
2349 return ret;
2350 }
2351 if (!access_ok(VERIFY_WRITE, buffer, count))
2352 return -EFAULT;
2353 ret = 0;
2354 while (count) {
2355 DECLARE_WAITQUEUE(wait, current);
2356 add_wait_queue(&wport->queue, &wait);
2357 while ((nb = swb_inc_u(wport, 0)) == 0) {
2358 set_current_state(TASK_INTERRUPTIBLE);
2359 if (wport->flags & DISABLED ||
2360 file->f_flags & O_NONBLOCK) {
2361 current->state = TASK_RUNNING;
2362 remove_wait_queue(&wport->queue, &wait);
2363 return ret ? ret : -EAGAIN;
2364 }
2365 schedule();
2366 if (signal_pending(current)) {
2367 current->state = TASK_RUNNING;
2368 remove_wait_queue(&wport->queue, &wait);
2369 return ret ? ret : -ERESTARTSYS;
2370 }
2371 }
2372 current->state = TASK_RUNNING;
2373 remove_wait_queue(&wport->queue, &wait);
2374 /* nb bytes are available in userbuf. */
2375 if (nb > count)
2376 nb = count;
2377 DBGPV("nb = %d\n", nb);
2378 if (copy_from_user(wport->swbuf + wport->swb_u_idx, buffer, nb))
2379 return -EFAULT;
2380 pcm_output(devc, 0, nb);
2381 buffer += nb;
2382 count -= nb;
2383 ret += nb;
2384 }
2385 DBGPV("returning %d\n", ret);
2386 return ret;
2387}
2388
2389static ssize_t vwsnd_audio_write(struct file *file,
2390 const char *buffer,
2391 size_t count,
2392 loff_t *ppos)
2393{
2394 vwsnd_dev_t *devc = file->private_data;
2395 ssize_t ret;
2396
2397 down(&devc->io_sema);
2398 ret = vwsnd_audio_do_write(file, buffer, count, ppos);
2399 up(&devc->io_sema);
2400 return ret;
2401}
2402
2403/* No kernel lock - fine */
2404static unsigned int vwsnd_audio_poll(struct file *file,
2405 struct poll_table_struct *wait)
2406{
2407 vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data;
2408 vwsnd_port_t *rport = (file->f_mode & FMODE_READ) ?
2409 &devc->rport : NULL;
2410 vwsnd_port_t *wport = (file->f_mode & FMODE_WRITE) ?
2411 &devc->wport : NULL;
2412 unsigned int mask = 0;
2413
2414 DBGEV("(file=0x%p, wait=0x%p)\n", file, wait);
2415
2416 ASSERT(rport || wport);
2417 if (rport) {
2418 poll_wait(file, &rport->queue, wait);
2419 if (swb_inc_u(rport, 0))
2420 mask |= (POLLIN | POLLRDNORM);
2421 }
2422 if (wport) {
2423 poll_wait(file, &wport->queue, wait);
2424 if (wport->swbuf == NULL || swb_inc_u(wport, 0))
2425 mask |= (POLLOUT | POLLWRNORM);
2426 }
2427
2428 DBGPV("returning 0x%x\n", mask);
2429 return mask;
2430}
2431
2432static int vwsnd_audio_do_ioctl(struct inode *inode,
2433 struct file *file,
2434 unsigned int cmd,
2435 unsigned long arg)
2436{
2437 vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data;
2438 vwsnd_port_t *rport = (file->f_mode & FMODE_READ) ?
2439 &devc->rport : NULL;
2440 vwsnd_port_t *wport = (file->f_mode & FMODE_WRITE) ?
2441 &devc->wport : NULL;
2442 vwsnd_port_t *aport = rport ? rport : wport;
2443 struct audio_buf_info buf_info;
2444 struct count_info info;
2445 unsigned long flags;
2446 int ival;
2447
2448
2449 DBGEV("(inode=0x%p, file=0x%p, cmd=0x%x, arg=0x%lx)\n",
2450 inode, file, cmd, arg);
2451 switch (cmd) {
2452 case OSS_GETVERSION: /* _SIOR ('M', 118, int) */
2453 DBGX("OSS_GETVERSION\n");
2454 ival = SOUND_VERSION;
2455 return put_user(ival, (int *) arg);
2456
2457 case SNDCTL_DSP_GETCAPS: /* _SIOR ('P',15, int) */
2458 DBGX("SNDCTL_DSP_GETCAPS\n");
2459 ival = DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER;
2460 return put_user(ival, (int *) arg);
2461
2462 case SNDCTL_DSP_GETFMTS: /* _SIOR ('P',11, int) */
2463 DBGX("SNDCTL_DSP_GETFMTS\n");
2464 ival = (AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW |
2465 AFMT_U8 | AFMT_S8);
2466 return put_user(ival, (int *) arg);
2467 break;
2468
2469 case SOUND_PCM_READ_RATE: /* _SIOR ('P', 2, int) */
2470 DBGX("SOUND_PCM_READ_RATE\n");
2471 ival = aport->sw_framerate;
2472 return put_user(ival, (int *) arg);
2473
2474 case SOUND_PCM_READ_CHANNELS: /* _SIOR ('P', 6, int) */
2475 DBGX("SOUND_PCM_READ_CHANNELS\n");
2476 ival = aport->sw_channels;
2477 return put_user(ival, (int *) arg);
2478
2479 case SNDCTL_DSP_SPEED: /* _SIOWR('P', 2, int) */
2480 if (get_user(ival, (int *) arg))
2481 return -EFAULT;
2482 DBGX("SNDCTL_DSP_SPEED %d\n", ival);
2483 if (ival) {
2484 if (aport->swstate != SW_INITIAL) {
2485 DBGX("SNDCTL_DSP_SPEED failed: swstate = %d\n",
2486 aport->swstate);
2487 return -EINVAL;
2488 }
2489 if (ival < MIN_SPEED)
2490 ival = MIN_SPEED;
2491 if (ival > MAX_SPEED)
2492 ival = MAX_SPEED;
2493 if (rport)
2494 rport->sw_framerate = ival;
2495 if (wport)
2496 wport->sw_framerate = ival;
2497 } else
2498 ival = aport->sw_framerate;
2499 return put_user(ival, (int *) arg);
2500
2501 case SNDCTL_DSP_STEREO: /* _SIOWR('P', 3, int) */
2502 if (get_user(ival, (int *) arg))
2503 return -EFAULT;
2504 DBGX("SNDCTL_DSP_STEREO %d\n", ival);
2505 if (ival != 0 && ival != 1)
2506 return -EINVAL;
2507 if (aport->swstate != SW_INITIAL)
2508 return -EINVAL;
2509 if (rport)
2510 rport->sw_channels = ival + 1;
2511 if (wport)
2512 wport->sw_channels = ival + 1;
2513 return put_user(ival, (int *) arg);
2514
2515 case SNDCTL_DSP_CHANNELS: /* _SIOWR('P', 6, int) */
2516 if (get_user(ival, (int *) arg))
2517 return -EFAULT;
2518 DBGX("SNDCTL_DSP_CHANNELS %d\n", ival);
2519 if (ival != 1 && ival != 2)
2520 return -EINVAL;
2521 if (aport->swstate != SW_INITIAL)
2522 return -EINVAL;
2523 if (rport)
2524 rport->sw_channels = ival;
2525 if (wport)
2526 wport->sw_channels = ival;
2527 return put_user(ival, (int *) arg);
2528
2529 case SNDCTL_DSP_GETBLKSIZE: /* _SIOWR('P', 4, int) */
2530 ival = pcm_setup(devc, rport, wport);
2531 if (ival < 0) {
2532 DBGX("SNDCTL_DSP_GETBLKSIZE failed, errno %d\n", ival);
2533 return ival;
2534 }
2535 ival = 1 << aport->sw_fragshift;
2536 DBGX("SNDCTL_DSP_GETBLKSIZE returning %d\n", ival);
2537 return put_user(ival, (int *) arg);
2538
2539 case SNDCTL_DSP_SETFRAGMENT: /* _SIOWR('P',10, int) */
2540 if (get_user(ival, (int *) arg))
2541 return -EFAULT;
2542 DBGX("SNDCTL_DSP_SETFRAGMENT %d:%d\n",
2543 ival >> 16, ival & 0xFFFF);
2544 if (aport->swstate != SW_INITIAL)
2545 return -EINVAL;
2546 {
2547 int sw_fragshift = ival & 0xFFFF;
2548 int sw_subdivshift = aport->sw_subdivshift;
2549 int hw_fragshift = sw_fragshift - sw_subdivshift;
2550 int sw_fragcount = (ival >> 16) & 0xFFFF;
2551 int hw_fragsize;
2552 if (hw_fragshift < MIN_FRAGSHIFT)
2553 hw_fragshift = MIN_FRAGSHIFT;
2554 if (hw_fragshift > MAX_FRAGSHIFT)
2555 hw_fragshift = MAX_FRAGSHIFT;
2556 sw_fragshift = hw_fragshift + aport->sw_subdivshift;
2557 hw_fragsize = 1 << hw_fragshift;
2558 if (sw_fragcount < MIN_FRAGCOUNT(hw_fragsize))
2559 sw_fragcount = MIN_FRAGCOUNT(hw_fragsize);
2560 if (sw_fragcount > MAX_FRAGCOUNT(hw_fragsize))
2561 sw_fragcount = MAX_FRAGCOUNT(hw_fragsize);
2562 DBGPV("sw_fragshift = %d\n", sw_fragshift);
2563 DBGPV("rport = 0x%p, wport = 0x%p\n", rport, wport);
2564 if (rport) {
2565 rport->sw_fragshift = sw_fragshift;
2566 rport->sw_fragcount = sw_fragcount;
2567 }
2568 if (wport) {
2569 wport->sw_fragshift = sw_fragshift;
2570 wport->sw_fragcount = sw_fragcount;
2571 }
2572 ival = sw_fragcount << 16 | sw_fragshift;
2573 }
2574 DBGX("SNDCTL_DSP_SETFRAGMENT returns %d:%d\n",
2575 ival >> 16, ival & 0xFFFF);
2576 return put_user(ival, (int *) arg);
2577
2578 case SNDCTL_DSP_SUBDIVIDE: /* _SIOWR('P', 9, int) */
2579 if (get_user(ival, (int *) arg))
2580 return -EFAULT;
2581 DBGX("SNDCTL_DSP_SUBDIVIDE %d\n", ival);
2582 if (aport->swstate != SW_INITIAL)
2583 return -EINVAL;
2584 {
2585 int subdivshift;
2586 int hw_fragshift, hw_fragsize, hw_fragcount;
2587 switch (ival) {
2588 case 1: subdivshift = 0; break;
2589 case 2: subdivshift = 1; break;
2590 case 4: subdivshift = 2; break;
2591 default: return -EINVAL;
2592 }
2593 hw_fragshift = aport->sw_fragshift - subdivshift;
2594 if (hw_fragshift < MIN_FRAGSHIFT ||
2595 hw_fragshift > MAX_FRAGSHIFT)
2596 return -EINVAL;
2597 hw_fragsize = 1 << hw_fragshift;
2598 hw_fragcount = aport->sw_fragcount >> subdivshift;
2599 if (hw_fragcount < MIN_FRAGCOUNT(hw_fragsize) ||
2600 hw_fragcount > MAX_FRAGCOUNT(hw_fragsize))
2601 return -EINVAL;
2602 if (rport)
2603 rport->sw_subdivshift = subdivshift;
2604 if (wport)
2605 wport->sw_subdivshift = subdivshift;
2606 }
2607 return 0;
2608
2609 case SNDCTL_DSP_SETFMT: /* _SIOWR('P',5, int) */
2610 if (get_user(ival, (int *) arg))
2611 return -EFAULT;
2612 DBGX("SNDCTL_DSP_SETFMT %d\n", ival);
2613 if (ival != AFMT_QUERY) {
2614 if (aport->swstate != SW_INITIAL) {
2615 DBGP("SETFMT failed, swstate = %d\n",
2616 aport->swstate);
2617 return -EINVAL;
2618 }
2619 switch (ival) {
2620 case AFMT_MU_LAW:
2621 case AFMT_A_LAW:
2622 case AFMT_U8:
2623 case AFMT_S8:
2624 case AFMT_S16_LE:
2625 if (rport)
2626 rport->sw_samplefmt = ival;
2627 if (wport)
2628 wport->sw_samplefmt = ival;
2629 break;
2630 default:
2631 return -EINVAL;
2632 }
2633 }
2634 ival = aport->sw_samplefmt;
2635 return put_user(ival, (int *) arg);
2636
2637 case SNDCTL_DSP_GETOSPACE: /* _SIOR ('P',12, audio_buf_info) */
2638 DBGXV("SNDCTL_DSP_GETOSPACE\n");
2639 if (!wport)
2640 return -EINVAL;
2641 ival = pcm_setup(devc, rport, wport);
2642 if (ival < 0)
2643 return ival;
2644 ival = swb_inc_u(wport, 0);
2645 buf_info.fragments = ival >> wport->sw_fragshift;
2646 buf_info.fragstotal = wport->sw_fragcount;
2647 buf_info.fragsize = 1 << wport->sw_fragshift;
2648 buf_info.bytes = ival;
2649 DBGXV("SNDCTL_DSP_GETOSPACE returns { %d %d %d %d }\n",
2650 buf_info.fragments, buf_info.fragstotal,
2651 buf_info.fragsize, buf_info.bytes);
2652 if (copy_to_user((void *) arg, &buf_info, sizeof buf_info))
2653 return -EFAULT;
2654 return 0;
2655
2656 case SNDCTL_DSP_GETISPACE: /* _SIOR ('P',13, audio_buf_info) */
2657 DBGX("SNDCTL_DSP_GETISPACE\n");
2658 if (!rport)
2659 return -EINVAL;
2660 ival = pcm_setup(devc, rport, wport);
2661 if (ival < 0)
2662 return ival;
2663 ival = swb_inc_u(rport, 0);
2664 buf_info.fragments = ival >> rport->sw_fragshift;
2665 buf_info.fragstotal = rport->sw_fragcount;
2666 buf_info.fragsize = 1 << rport->sw_fragshift;
2667 buf_info.bytes = ival;
2668 DBGX("SNDCTL_DSP_GETISPACE returns { %d %d %d %d }\n",
2669 buf_info.fragments, buf_info.fragstotal,
2670 buf_info.fragsize, buf_info.bytes);
2671 if (copy_to_user((void *) arg, &buf_info, sizeof buf_info))
2672 return -EFAULT;
2673 return 0;
2674
2675 case SNDCTL_DSP_NONBLOCK: /* _SIO ('P',14) */
2676 DBGX("SNDCTL_DSP_NONBLOCK\n");
2677 file->f_flags |= O_NONBLOCK;
2678 return 0;
2679
2680 case SNDCTL_DSP_RESET: /* _SIO ('P', 0) */
2681 DBGX("SNDCTL_DSP_RESET\n");
2682 /*
2683 * Nothing special needs to be done for input. Input
2684 * samples sit in swbuf, but it will be reinitialized
2685 * to empty when pcm_setup() is called.
2686 */
2687 if (wport && wport->swbuf) {
2688 wport->swstate = SW_INITIAL;
2689 pcm_output(devc, 0, 0);
2690 pcm_write_sync(devc);
2691 }
2692 pcm_shutdown(devc, rport, wport);
2693 return 0;
2694
2695 case SNDCTL_DSP_SYNC: /* _SIO ('P', 1) */
2696 DBGX("SNDCTL_DSP_SYNC\n");
2697 if (wport) {
2698 pcm_flush_frag(devc);
2699 pcm_write_sync(devc);
2700 }
2701 pcm_shutdown(devc, rport, wport);
2702 return 0;
2703
2704 case SNDCTL_DSP_POST: /* _SIO ('P', 8) */
2705 DBGX("SNDCTL_DSP_POST\n");
2706 if (!wport)
2707 return -EINVAL;
2708 pcm_flush_frag(devc);
2709 return 0;
2710
2711 case SNDCTL_DSP_GETIPTR: /* _SIOR ('P', 17, count_info) */
2712 DBGX("SNDCTL_DSP_GETIPTR\n");
2713 if (!rport)
2714 return -EINVAL;
2715 spin_lock_irqsave(&rport->lock, flags);
2716 {
2717 ustmsc_t ustmsc;
2718 if (rport->hwstate == HW_RUNNING) {
2719 ASSERT(rport->swstate == SW_RUN);
2720 li_read_USTMSC(&rport->chan, &ustmsc);
2721 info.bytes = ustmsc.msc - rport->MSC_offset;
2722 info.bytes *= rport->frame_size;
2723 } else {
2724 info.bytes = rport->byte_count;
2725 }
2726 info.blocks = rport->frag_count;
2727 info.ptr = 0; /* not implemented */
2728 rport->frag_count = 0;
2729 }
2730 spin_unlock_irqrestore(&rport->lock, flags);
2731 if (copy_to_user((void *) arg, &info, sizeof info))
2732 return -EFAULT;
2733 return 0;
2734
2735 case SNDCTL_DSP_GETOPTR: /* _SIOR ('P',18, count_info) */
2736 DBGX("SNDCTL_DSP_GETOPTR\n");
2737 if (!wport)
2738 return -EINVAL;
2739 spin_lock_irqsave(&wport->lock, flags);
2740 {
2741 ustmsc_t ustmsc;
2742 if (wport->hwstate == HW_RUNNING) {
2743 ASSERT(wport->swstate == SW_RUN);
2744 li_read_USTMSC(&wport->chan, &ustmsc);
2745 info.bytes = ustmsc.msc - wport->MSC_offset;
2746 info.bytes *= wport->frame_size;
2747 } else {
2748 info.bytes = wport->byte_count;
2749 }
2750 info.blocks = wport->frag_count;
2751 info.ptr = 0; /* not implemented */
2752 wport->frag_count = 0;
2753 }
2754 spin_unlock_irqrestore(&wport->lock, flags);
2755 if (copy_to_user((void *) arg, &info, sizeof info))
2756 return -EFAULT;
2757 return 0;
2758
2759 case SNDCTL_DSP_GETODELAY: /* _SIOR ('P', 23, int) */
2760 DBGX("SNDCTL_DSP_GETODELAY\n");
2761 if (!wport)
2762 return -EINVAL;
2763 spin_lock_irqsave(&wport->lock, flags);
2764 {
2765 int fsize = wport->frame_size;
2766 ival = wport->swb_i_avail / fsize;
2767 if (wport->hwstate == HW_RUNNING) {
2768 int swptr, hwptr, hwframes, hwbytes, hwsize;
2769 int totalhwbytes;
2770 ustmsc_t ustmsc;
2771
2772 hwsize = wport->hwbuf_size;
2773 swptr = li_read_swptr(&wport->chan);
2774 li_read_USTMSC(&wport->chan, &ustmsc);
2775 hwframes = ustmsc.msc - wport->MSC_offset;
2776 totalhwbytes = hwframes * fsize;
2777 hwptr = totalhwbytes % hwsize;
2778 hwbytes = (swptr - hwptr + hwsize) % hwsize;
2779 ival += hwbytes / fsize;
2780 }
2781 }
2782 spin_unlock_irqrestore(&wport->lock, flags);
2783 return put_user(ival, (int *) arg);
2784
2785 case SNDCTL_DSP_PROFILE: /* _SIOW ('P', 23, int) */
2786 DBGX("SNDCTL_DSP_PROFILE\n");
2787
2788 /*
2789 * Thomas Sailer explains SNDCTL_DSP_PROFILE
2790 * (private email, March 24, 1999):
2791 *
2792 * This gives the sound driver a hint on what it
2793 * should do with partial fragments
2794 * (i.e. fragments partially filled with write).
2795 * This can direct the driver to zero them or
2796 * leave them alone. But don't ask me what this
2797 * is good for, my driver just zeroes the last
2798 * fragment before the receiver stops, no idea
2799 * what good for any other behaviour could
2800 * be. Implementing it as NOP seems safe.
2801 */
2802
2803 break;
2804
2805 case SNDCTL_DSP_GETTRIGGER: /* _SIOR ('P',16, int) */
2806 DBGX("SNDCTL_DSP_GETTRIGGER\n");
2807 ival = 0;
2808 if (rport) {
2809 spin_lock_irqsave(&rport->lock, flags);
2810 {
2811 if (!(rport->flags & DISABLED))
2812 ival |= PCM_ENABLE_INPUT;
2813 }
2814 spin_unlock_irqrestore(&rport->lock, flags);
2815 }
2816 if (wport) {
2817 spin_lock_irqsave(&wport->lock, flags);
2818 {
2819 if (!(wport->flags & DISABLED))
2820 ival |= PCM_ENABLE_OUTPUT;
2821 }
2822 spin_unlock_irqrestore(&wport->lock, flags);
2823 }
2824 return put_user(ival, (int *) arg);
2825
2826 case SNDCTL_DSP_SETTRIGGER: /* _SIOW ('P',16, int) */
2827 if (get_user(ival, (int *) arg))
2828 return -EFAULT;
2829 DBGX("SNDCTL_DSP_SETTRIGGER %d\n", ival);
2830
2831 /*
2832 * If user is disabling I/O and port is not in initial
2833 * state, fail with EINVAL.
2834 */
2835
2836 if (((rport && !(ival & PCM_ENABLE_INPUT)) ||
2837 (wport && !(ival & PCM_ENABLE_OUTPUT))) &&
2838 aport->swstate != SW_INITIAL)
2839 return -EINVAL;
2840
2841 if (rport) {
2842 vwsnd_port_hwstate_t hwstate;
2843 spin_lock_irqsave(&rport->lock, flags);
2844 {
2845 hwstate = rport->hwstate;
2846 if (ival & PCM_ENABLE_INPUT)
2847 rport->flags &= ~DISABLED;
2848 else
2849 rport->flags |= DISABLED;
2850 }
2851 spin_unlock_irqrestore(&rport->lock, flags);
2852 if (hwstate != HW_RUNNING && ival & PCM_ENABLE_INPUT) {
2853
2854 if (rport->swstate == SW_INITIAL)
2855 pcm_setup(devc, rport, wport);
2856 else
2857 li_activate_dma(&rport->chan);
2858 }
2859 }
2860 if (wport) {
2861 vwsnd_port_flags_t pflags;
2862 spin_lock_irqsave(&wport->lock, flags);
2863 {
2864 pflags = wport->flags;
2865 if (ival & PCM_ENABLE_OUTPUT)
2866 wport->flags &= ~DISABLED;
2867 else
2868 wport->flags |= DISABLED;
2869 }
2870 spin_unlock_irqrestore(&wport->lock, flags);
2871 if (pflags & DISABLED && ival & PCM_ENABLE_OUTPUT) {
2872 if (wport->swstate == SW_RUN)
2873 pcm_output(devc, 0, 0);
2874 }
2875 }
2876 return 0;
2877
2878 default:
2879 DBGP("unknown ioctl 0x%x\n", cmd);
2880 return -EINVAL;
2881 }
2882 DBGP("unimplemented ioctl 0x%x\n", cmd);
2883 return -EINVAL;
2884}
2885
2886static int vwsnd_audio_ioctl(struct inode *inode,
2887 struct file *file,
2888 unsigned int cmd,
2889 unsigned long arg)
2890{
2891 vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data;
2892 int ret;
2893
2894 down(&devc->io_sema);
2895 ret = vwsnd_audio_do_ioctl(inode, file, cmd, arg);
2896 up(&devc->io_sema);
2897 return ret;
2898}
2899
2900/* No mmap. */
2901
2902static int vwsnd_audio_mmap(struct file *file, struct vm_area_struct *vma)
2903{
2904 DBGE("(file=0x%p, vma=0x%p)\n", file, vma);
2905 return -ENODEV;
2906}
2907
2908/*
2909 * Open the audio device for read and/or write.
2910 *
2911 * Returns 0 on success, -errno on failure.
2912 */
2913
2914static int vwsnd_audio_open(struct inode *inode, struct file *file)
2915{
2916 vwsnd_dev_t *devc;
2917 int minor = iminor(inode);
2918 int sw_samplefmt;
2919
2920 DBGE("(inode=0x%p, file=0x%p)\n", inode, file);
2921
2922 INC_USE_COUNT;
2923 for (devc = vwsnd_dev_list; devc; devc = devc->next_dev)
2924 if ((devc->audio_minor & ~0x0F) == (minor & ~0x0F))
2925 break;
2926
2927 if (devc == NULL) {
2928 DEC_USE_COUNT;
2929 return -ENODEV;
2930 }
2931
2932 down(&devc->open_sema);
2933 while (devc->open_mode & file->f_mode) {
2934 up(&devc->open_sema);
2935 if (file->f_flags & O_NONBLOCK) {
2936 DEC_USE_COUNT;
2937 return -EBUSY;
2938 }
2939 interruptible_sleep_on(&devc->open_wait);
2940 if (signal_pending(current)) {
2941 DEC_USE_COUNT;
2942 return -ERESTARTSYS;
2943 }
2944 down(&devc->open_sema);
2945 }
2946 devc->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2947 up(&devc->open_sema);
2948
2949 /* get default sample format from minor number. */
2950
2951 sw_samplefmt = 0;
2952 if ((minor & 0xF) == SND_DEV_DSP)
2953 sw_samplefmt = AFMT_U8;
2954 else if ((minor & 0xF) == SND_DEV_AUDIO)
2955 sw_samplefmt = AFMT_MU_LAW;
2956 else if ((minor & 0xF) == SND_DEV_DSP16)
2957 sw_samplefmt = AFMT_S16_LE;
2958 else
2959 ASSERT(0);
2960
2961 /* Initialize vwsnd_ports. */
2962
2963 down(&devc->io_sema);
2964 {
2965 if (file->f_mode & FMODE_READ) {
2966 devc->rport.swstate = SW_INITIAL;
2967 devc->rport.flags = 0;
2968 devc->rport.sw_channels = 1;
2969 devc->rport.sw_samplefmt = sw_samplefmt;
2970 devc->rport.sw_framerate = 8000;
2971 devc->rport.sw_fragshift = DEFAULT_FRAGSHIFT;
2972 devc->rport.sw_fragcount = DEFAULT_FRAGCOUNT;
2973 devc->rport.sw_subdivshift = DEFAULT_SUBDIVSHIFT;
2974 devc->rport.byte_count = 0;
2975 devc->rport.frag_count = 0;
2976 }
2977 if (file->f_mode & FMODE_WRITE) {
2978 devc->wport.swstate = SW_INITIAL;
2979 devc->wport.flags = 0;
2980 devc->wport.sw_channels = 1;
2981 devc->wport.sw_samplefmt = sw_samplefmt;
2982 devc->wport.sw_framerate = 8000;
2983 devc->wport.sw_fragshift = DEFAULT_FRAGSHIFT;
2984 devc->wport.sw_fragcount = DEFAULT_FRAGCOUNT;
2985 devc->wport.sw_subdivshift = DEFAULT_SUBDIVSHIFT;
2986 devc->wport.byte_count = 0;
2987 devc->wport.frag_count = 0;
2988 }
2989 }
2990 up(&devc->io_sema);
2991
2992 file->private_data = devc;
2993 DBGRV();
2994 return 0;
2995}
2996
2997/*
2998 * Release (close) the audio device.
2999 */
3000
3001static int vwsnd_audio_release(struct inode *inode, struct file *file)
3002{
3003 vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data;
3004 vwsnd_port_t *wport = NULL, *rport = NULL;
3005 int err = 0;
3006
3007 lock_kernel();
3008 down(&devc->io_sema);
3009 {
3010 DBGEV("(inode=0x%p, file=0x%p)\n", inode, file);
3011
3012 if (file->f_mode & FMODE_READ)
3013 rport = &devc->rport;
3014 if (file->f_mode & FMODE_WRITE) {
3015 wport = &devc->wport;
3016 pcm_flush_frag(devc);
3017 pcm_write_sync(devc);
3018 }
3019 pcm_shutdown(devc, rport, wport);
3020 if (rport)
3021 rport->swstate = SW_OFF;
3022 if (wport)
3023 wport->swstate = SW_OFF;
3024 }
3025 up(&devc->io_sema);
3026
3027 down(&devc->open_sema);
3028 {
3029 devc->open_mode &= ~file->f_mode;
3030 }
3031 up(&devc->open_sema);
3032 wake_up(&devc->open_wait);
3033 DEC_USE_COUNT;
3034 DBGR();
3035 unlock_kernel();
3036 return err;
3037}
3038
3039static struct file_operations vwsnd_audio_fops = {
3040 .owner = THIS_MODULE,
3041 .llseek = no_llseek,
3042 .read = vwsnd_audio_read,
3043 .write = vwsnd_audio_write,
3044 .poll = vwsnd_audio_poll,
3045 .ioctl = vwsnd_audio_ioctl,
3046 .mmap = vwsnd_audio_mmap,
3047 .open = vwsnd_audio_open,
3048 .release = vwsnd_audio_release,
3049};
3050
3051/*****************************************************************************/
3052/* mixer driver */
3053
3054/* open the mixer device. */
3055
3056static int vwsnd_mixer_open(struct inode *inode, struct file *file)
3057{
3058 vwsnd_dev_t *devc;
3059
3060 DBGEV("(inode=0x%p, file=0x%p)\n", inode, file);
3061
3062 INC_USE_COUNT;
3063 for (devc = vwsnd_dev_list; devc; devc = devc->next_dev)
3064 if (devc->mixer_minor == iminor(inode))
3065 break;
3066
3067 if (devc == NULL) {
3068 DEC_USE_COUNT;
3069 return -ENODEV;
3070 }
3071 file->private_data = devc;
3072 return 0;
3073}
3074
3075/* release (close) the mixer device. */
3076
3077static int vwsnd_mixer_release(struct inode *inode, struct file *file)
3078{
3079 DBGEV("(inode=0x%p, file=0x%p)\n", inode, file);
3080 DEC_USE_COUNT;
3081 return 0;
3082}
3083
3084/* mixer_read_ioctl handles all read ioctls on the mixer device. */
3085
3086static int mixer_read_ioctl(vwsnd_dev_t *devc, unsigned int nr, void __user *arg)
3087{
3088 int val = -1;
3089
3090 DBGEV("(devc=0x%p, nr=0x%x, arg=0x%p)\n", devc, nr, arg);
3091
3092 switch (nr) {
3093 case SOUND_MIXER_CAPS:
3094 val = SOUND_CAP_EXCL_INPUT;
3095 break;
3096
3097 case SOUND_MIXER_DEVMASK:
3098 val = (SOUND_MASK_PCM | SOUND_MASK_LINE |
3099 SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_RECLEV);
3100 break;
3101
3102 case SOUND_MIXER_STEREODEVS:
3103 val = (SOUND_MASK_PCM | SOUND_MASK_LINE |
3104 SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_RECLEV);
3105 break;
3106
3107 case SOUND_MIXER_OUTMASK:
3108 val = (SOUND_MASK_PCM | SOUND_MASK_LINE |
3109 SOUND_MASK_MIC | SOUND_MASK_CD);
3110 break;
3111
3112 case SOUND_MIXER_RECMASK:
3113 val = (SOUND_MASK_PCM | SOUND_MASK_LINE |
3114 SOUND_MASK_MIC | SOUND_MASK_CD);
3115 break;
3116
3117 case SOUND_MIXER_PCM:
3118 val = ad1843_get_gain(&devc->lith, &ad1843_gain_PCM);
3119 break;
3120
3121 case SOUND_MIXER_LINE:
3122 val = ad1843_get_gain(&devc->lith, &ad1843_gain_LINE);
3123 break;
3124
3125 case SOUND_MIXER_MIC:
3126 val = ad1843_get_gain(&devc->lith, &ad1843_gain_MIC);
3127 break;
3128
3129 case SOUND_MIXER_CD:
3130 val = ad1843_get_gain(&devc->lith, &ad1843_gain_CD);
3131 break;
3132
3133 case SOUND_MIXER_RECLEV:
3134 val = ad1843_get_gain(&devc->lith, &ad1843_gain_RECLEV);
3135 break;
3136
3137 case SOUND_MIXER_RECSRC:
3138 val = ad1843_get_recsrc(&devc->lith);
3139 break;
3140
3141 case SOUND_MIXER_OUTSRC:
3142 val = ad1843_get_outsrc(&devc->lith);
3143 break;
3144
3145 default:
3146 return -EINVAL;
3147 }
3148 return put_user(val, (int __user *) arg);
3149}
3150
3151/* mixer_write_ioctl handles all write ioctls on the mixer device. */
3152
3153static int mixer_write_ioctl(vwsnd_dev_t *devc, unsigned int nr, void __user *arg)
3154{
3155 int val;
3156 int err;
3157
3158 DBGEV("(devc=0x%p, nr=0x%x, arg=0x%p)\n", devc, nr, arg);
3159
3160 err = get_user(val, (int __user *) arg);
3161 if (err)
3162 return -EFAULT;
3163 switch (nr) {
3164 case SOUND_MIXER_PCM:
3165 val = ad1843_set_gain(&devc->lith, &ad1843_gain_PCM, val);
3166 break;
3167
3168 case SOUND_MIXER_LINE:
3169 val = ad1843_set_gain(&devc->lith, &ad1843_gain_LINE, val);
3170 break;
3171
3172 case SOUND_MIXER_MIC:
3173 val = ad1843_set_gain(&devc->lith, &ad1843_gain_MIC, val);
3174 break;
3175
3176 case SOUND_MIXER_CD:
3177 val = ad1843_set_gain(&devc->lith, &ad1843_gain_CD, val);
3178 break;
3179
3180 case SOUND_MIXER_RECLEV:
3181 val = ad1843_set_gain(&devc->lith, &ad1843_gain_RECLEV, val);
3182 break;
3183
3184 case SOUND_MIXER_RECSRC:
3185 if (devc->rport.swbuf || devc->wport.swbuf)
3186 return -EBUSY; /* can't change recsrc while running */
3187 val = ad1843_set_recsrc(&devc->lith, val);
3188 break;
3189
3190 case SOUND_MIXER_OUTSRC:
3191 val = ad1843_set_outsrc(&devc->lith, val);
3192 break;
3193
3194 default:
3195 return -EINVAL;
3196 }
3197 if (val < 0)
3198 return val;
3199 return put_user(val, (int __user *) arg);
3200}
3201
3202/* This is the ioctl entry to the mixer driver. */
3203
3204static int vwsnd_mixer_ioctl(struct inode *ioctl,
3205 struct file *file,
3206 unsigned int cmd,
3207 unsigned long arg)
3208{
3209 vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data;
3210 const unsigned int nrmask = _IOC_NRMASK << _IOC_NRSHIFT;
3211 const unsigned int nr = (cmd & nrmask) >> _IOC_NRSHIFT;
3212 int retval;
3213
3214 DBGEV("(devc=0x%p, cmd=0x%x, arg=0x%lx)\n", devc, cmd, arg);
3215
3216 down(&devc->mix_sema);
3217 {
3218 if ((cmd & ~nrmask) == MIXER_READ(0))
3219 retval = mixer_read_ioctl(devc, nr, (void __user *) arg);
3220 else if ((cmd & ~nrmask) == MIXER_WRITE(0))
3221 retval = mixer_write_ioctl(devc, nr, (void __user *) arg);
3222 else
3223 retval = -EINVAL;
3224 }
3225 up(&devc->mix_sema);
3226 return retval;
3227}
3228
3229static struct file_operations vwsnd_mixer_fops = {
3230 .owner = THIS_MODULE,
3231 .llseek = no_llseek,
3232 .ioctl = vwsnd_mixer_ioctl,
3233 .open = vwsnd_mixer_open,
3234 .release = vwsnd_mixer_release,
3235};
3236
3237/*****************************************************************************/
3238/* probe/attach/unload */
3239
3240/* driver probe routine. Return nonzero if hardware is found. */
3241
3242static int __init probe_vwsnd(struct address_info *hw_config)
3243{
3244 lithium_t lith;
3245 int w;
3246 unsigned long later;
3247
3248 DBGEV("(hw_config=0x%p)\n", hw_config);
3249
3250 /* XXX verify lithium present (to prevent crash on non-vw) */
3251
3252 if (li_create(&lith, hw_config->io_base) != 0) {
3253 printk(KERN_WARNING "probe_vwsnd: can't map lithium\n");
3254 return 0;
3255 }
3256 later = jiffies + 2;
3257 li_writel(&lith, LI_HOST_CONTROLLER, LI_HC_LINK_ENABLE);
3258 do {
3259 w = li_readl(&lith, LI_HOST_CONTROLLER);
3260 } while (w == LI_HC_LINK_ENABLE && time_before(jiffies, later));
3261
3262 li_destroy(&lith);
3263
3264 DBGPV("HC = 0x%04x\n", w);
3265
3266 if ((w == LI_HC_LINK_ENABLE) || (w & LI_HC_LINK_CODEC)) {
3267
3268 /* This may indicate a beta machine with no audio,
3269 * or a future machine with different audio.
3270 * On beta-release 320 w/ no audio, HC == 0x4000 */
3271
3272 printk(KERN_WARNING "probe_vwsnd: audio codec not found\n");
3273 return 0;
3274 }
3275
3276 if (w & LI_HC_LINK_FAILURE) {
3277 printk(KERN_WARNING "probe_vwsnd: can't init audio codec\n");
3278 return 0;
3279 }
3280
3281 printk(KERN_INFO "vwsnd: lithium audio at mmio %#x irq %d\n",
3282 hw_config->io_base, hw_config->irq);
3283
3284 return 1;
3285}
3286
3287/*
3288 * driver attach routine. Initialize driver data structures and
3289 * initialize hardware. A new vwsnd_dev_t is allocated and put
3290 * onto the global list, vwsnd_dev_list.
3291 *
3292 * Return +minor_dev on success, -errno on failure.
3293 */
3294
3295static int __init attach_vwsnd(struct address_info *hw_config)
3296{
3297 vwsnd_dev_t *devc = NULL;
3298 int err = -ENOMEM;
3299
3300 DBGEV("(hw_config=0x%p)\n", hw_config);
3301
3302 devc = kmalloc(sizeof (vwsnd_dev_t), GFP_KERNEL);
3303 if (devc == NULL)
3304 goto fail0;
3305
3306 err = li_create(&devc->lith, hw_config->io_base);
3307 if (err)
3308 goto fail1;
3309
3310 init_waitqueue_head(&devc->open_wait);
3311
3312 devc->rport.hwbuf_size = HWBUF_SIZE;
3313 devc->rport.hwbuf_vaddr = __get_free_pages(GFP_KERNEL, HWBUF_ORDER);
3314 if (!devc->rport.hwbuf_vaddr)
3315 goto fail2;
3316 devc->rport.hwbuf = (void *) devc->rport.hwbuf_vaddr;
3317 devc->rport.hwbuf_paddr = virt_to_phys(devc->rport.hwbuf);
3318
3319 /*
3320 * Quote from the NT driver:
3321 *
3322 * // WARNING!!! HACK to setup output dma!!!
3323 * // This is required because even on output there is some data
3324 * // trickling into the input DMA channel. This is a bug in the
3325 * // Lithium microcode.
3326 * // --sde
3327 *
3328 * We set the input side's DMA base address here. It will remain
3329 * valid until the driver is unloaded.
3330 */
3331
3332 li_writel(&devc->lith, LI_COMM1_BASE,
3333 devc->rport.hwbuf_paddr >> 8 | 1 << (37 - 8));
3334
3335 devc->wport.hwbuf_size = HWBUF_SIZE;
3336 devc->wport.hwbuf_vaddr = __get_free_pages(GFP_KERNEL, HWBUF_ORDER);
3337 if (!devc->wport.hwbuf_vaddr)
3338 goto fail3;
3339 devc->wport.hwbuf = (void *) devc->wport.hwbuf_vaddr;
3340 devc->wport.hwbuf_paddr = virt_to_phys(devc->wport.hwbuf);
3341 DBGP("wport hwbuf = 0x%p\n", devc->wport.hwbuf);
3342
3343 DBGDO(shut_up++);
3344 err = ad1843_init(&devc->lith);
3345 DBGDO(shut_up--);
3346 if (err)
3347 goto fail4;
3348
3349 /* install interrupt handler */
3350
3351 err = request_irq(hw_config->irq, vwsnd_audio_intr, 0, "vwsnd", devc);
3352 if (err)
3353 goto fail5;
3354
3355 /* register this device's drivers. */
3356
3357 devc->audio_minor = register_sound_dsp(&vwsnd_audio_fops, -1);
3358 if ((err = devc->audio_minor) < 0) {
3359 DBGDO(printk(KERN_WARNING
3360 "attach_vwsnd: register_sound_dsp error %d\n",
3361 err));
3362 goto fail6;
3363 }
3364 devc->mixer_minor = register_sound_mixer(&vwsnd_mixer_fops,
3365 devc->audio_minor >> 4);
3366 if ((err = devc->mixer_minor) < 0) {
3367 DBGDO(printk(KERN_WARNING
3368 "attach_vwsnd: register_sound_mixer error %d\n",
3369 err));
3370 goto fail7;
3371 }
3372
3373 /* Squirrel away device indices for unload routine. */
3374
3375 hw_config->slots[0] = devc->audio_minor;
3376
3377 /* Initialize as much of *devc as possible */
3378
3379 init_MUTEX(&devc->open_sema);
3380 init_MUTEX(&devc->io_sema);
3381 init_MUTEX(&devc->mix_sema);
3382 devc->open_mode = 0;
3383 spin_lock_init(&devc->rport.lock);
3384 init_waitqueue_head(&devc->rport.queue);
3385 devc->rport.swstate = SW_OFF;
3386 devc->rport.hwstate = HW_STOPPED;
3387 devc->rport.flags = 0;
3388 devc->rport.swbuf = NULL;
3389 spin_lock_init(&devc->wport.lock);
3390 init_waitqueue_head(&devc->wport.queue);
3391 devc->wport.swstate = SW_OFF;
3392 devc->wport.hwstate = HW_STOPPED;
3393 devc->wport.flags = 0;
3394 devc->wport.swbuf = NULL;
3395
3396 /* Success. Link us onto the local device list. */
3397
3398 devc->next_dev = vwsnd_dev_list;
3399 vwsnd_dev_list = devc;
3400 return devc->audio_minor;
3401
3402 /* So many ways to fail. Undo what we did. */
3403
3404 fail7:
3405 unregister_sound_dsp(devc->audio_minor);
3406 fail6:
3407 free_irq(hw_config->irq, devc);
3408 fail5:
3409 fail4:
3410 free_pages(devc->wport.hwbuf_vaddr, HWBUF_ORDER);
3411 fail3:
3412 free_pages(devc->rport.hwbuf_vaddr, HWBUF_ORDER);
3413 fail2:
3414 li_destroy(&devc->lith);
3415 fail1:
3416 kfree(devc);
3417 fail0:
3418 return err;
3419}
3420
3421static int __exit unload_vwsnd(struct address_info *hw_config)
3422{
3423 vwsnd_dev_t *devc, **devcp;
3424
3425 DBGE("()\n");
3426
3427 devcp = &vwsnd_dev_list;
3428 while ((devc = *devcp)) {
3429 if (devc->audio_minor == hw_config->slots[0]) {
3430 *devcp = devc->next_dev;
3431 break;
3432 }
3433 devcp = &devc->next_dev;
3434 }
3435
3436 if (!devc)
3437 return -ENODEV;
3438
3439 unregister_sound_mixer(devc->mixer_minor);
3440 unregister_sound_dsp(devc->audio_minor);
3441 free_irq(hw_config->irq, devc);
3442 free_pages(devc->wport.hwbuf_vaddr, HWBUF_ORDER);
3443 free_pages(devc->rport.hwbuf_vaddr, HWBUF_ORDER);
3444 li_destroy(&devc->lith);
3445 kfree(devc);
3446
3447 return 0;
3448}
3449
3450/*****************************************************************************/
3451/* initialization and loadable kernel module interface */
3452
3453static struct address_info the_hw_config = {
3454 0xFF001000, /* lithium phys addr */
3455 CO_IRQ(CO_APIC_LI_AUDIO) /* irq */
3456};
3457
3458MODULE_DESCRIPTION("SGI Visual Workstation sound module");
3459MODULE_AUTHOR("Bob Miller <kbob@sgi.com>");
3460MODULE_LICENSE("GPL");
3461
3462static int __init init_vwsnd(void)
3463{
3464 int err;
3465
3466 DBGXV("\n");
3467 DBGXV("sound::vwsnd::init_module()\n");
3468
3469 if (!probe_vwsnd(&the_hw_config))
3470 return -ENODEV;
3471
3472 err = attach_vwsnd(&the_hw_config);
3473 if (err < 0)
3474 return err;
3475 return 0;
3476}
3477
3478static void __exit cleanup_vwsnd(void)
3479{
3480 DBGX("sound::vwsnd::cleanup_module()\n");
3481
3482 unload_vwsnd(&the_hw_config);
3483}
3484
3485module_init(init_vwsnd);
3486module_exit(cleanup_vwsnd);
diff --git a/sound/oss/waveartist.c b/sound/oss/waveartist.c
new file mode 100644
index 000000000000..99d04ad3ca13
--- /dev/null
+++ b/sound/oss/waveartist.c
@@ -0,0 +1,2035 @@
1/*
2 * linux/drivers/sound/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/config.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#include <asm/system.h>
46
47#include "sound_config.h"
48#include "waveartist.h"
49
50#ifdef CONFIG_ARM
51#include <asm/hardware.h>
52#include <asm/mach-types.h>
53#endif
54
55#ifndef NO_DMA
56#define NO_DMA 255
57#endif
58
59#define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
60 SOUND_MASK_PCM |\
61 SOUND_MASK_LINE |\
62 SOUND_MASK_MIC |\
63 SOUND_MASK_LINE1 |\
64 SOUND_MASK_RECLEV |\
65 SOUND_MASK_VOLUME |\
66 SOUND_MASK_IMIX)
67
68static unsigned short levels[SOUND_MIXER_NRDEVICES] = {
69 0x5555, /* Master Volume */
70 0x0000, /* Bass */
71 0x0000, /* Treble */
72 0x2323, /* Synth (FM) */
73 0x4b4b, /* PCM */
74 0x6464, /* PC Speaker */
75 0x0000, /* Ext Line */
76 0x0000, /* Mic */
77 0x0000, /* CD */
78 0x6464, /* Recording monitor */
79 0x0000, /* SB PCM (ALT PCM) */
80 0x0000, /* Recording level */
81 0x6464, /* Input gain */
82 0x6464, /* Output gain */
83 0x0000, /* Line1 (Aux1) */
84 0x0000, /* Line2 (Aux2) */
85 0x0000, /* Line3 (Aux3) */
86 0x0000, /* Digital1 */
87 0x0000, /* Digital2 */
88 0x0000, /* Digital3 */
89 0x0000, /* Phone In */
90 0x6464, /* Phone Out */
91 0x0000, /* Video */
92 0x0000, /* Radio */
93 0x0000 /* Monitor */
94};
95
96typedef struct {
97 struct address_info hw; /* hardware */
98 char *chip_name;
99
100 int xfer_count;
101 int audio_mode;
102 int open_mode;
103 int audio_flags;
104 int record_dev;
105 int playback_dev;
106 int dev_no;
107
108 /* Mixer parameters */
109 const struct waveartist_mixer_info *mix;
110
111 unsigned short *levels; /* cache of volume settings */
112 int recmask; /* currently enabled recording device! */
113
114#ifdef CONFIG_ARCH_NETWINDER
115 signed int slider_vol; /* hardware slider volume */
116 unsigned int handset_detect :1;
117 unsigned int telephone_detect:1;
118 unsigned int no_autoselect :1;/* handset/telephone autoselects a path */
119 unsigned int spkr_mute_state :1;/* set by ioctl or autoselect */
120 unsigned int line_mute_state :1;/* set by ioctl or autoselect */
121 unsigned int use_slider :1;/* use slider setting for o/p vol */
122#endif
123} wavnc_info;
124
125/*
126 * This is the implementation specific mixer information.
127 */
128struct waveartist_mixer_info {
129 unsigned int supported_devs; /* Supported devices */
130 unsigned int recording_devs; /* Recordable devies */
131 unsigned int stereo_devs; /* Stereo devices */
132
133 unsigned int (*select_input)(wavnc_info *, unsigned int,
134 unsigned char *, unsigned char *);
135 int (*decode_mixer)(wavnc_info *, int,
136 unsigned char, unsigned char);
137 int (*get_mixer)(wavnc_info *, int);
138};
139
140typedef struct wavnc_port_info {
141 int open_mode;
142 int speed;
143 int channels;
144 int audio_format;
145} wavnc_port_info;
146
147static int nr_waveartist_devs;
148static wavnc_info adev_info[MAX_AUDIO_DEV];
149static DEFINE_SPINLOCK(waveartist_lock);
150
151#ifndef CONFIG_ARCH_NETWINDER
152#define machine_is_netwinder() 0
153#else
154static struct timer_list vnc_timer;
155static void vnc_configure_mixer(wavnc_info *devc, 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(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 = timeout_ms * 10 * HZ / 100;
188
189 do {
190 set_current_state(TASK_INTERRUPTIBLE);
191 timeout = schedule_timeout(timeout);
192 } while (timeout);
193
194 return 0;
195}
196
197static int
198waveartist_reset(wavnc_info *devc)
199{
200 struct address_info *hw = &devc->hw;
201 unsigned int timeout, res = -1;
202
203 waveartist_set_ctlr(hw, -1, RESET);
204 waveartist_sleep(2);
205 waveartist_set_ctlr(hw, RESET, 0);
206
207 timeout = 500;
208 do {
209 mdelay(2);
210
211 if (inb(hw->io_base + STATR) & CMD_RF) {
212 res = inw(hw->io_base + CMDR);
213 if (res == 0x55aa)
214 break;
215 }
216 } while (--timeout);
217
218 if (timeout == 0) {
219 printk(KERN_WARNING "WaveArtist: reset timeout ");
220 if (res != (unsigned int)-1)
221 printk("(res=%04X)", res);
222 printk("\n");
223 return 1;
224 }
225 return 0;
226}
227
228/* Helper function to send and receive words
229 * from WaveArtist. It handles all the handshaking
230 * and can send or receive multiple words.
231 */
232static int
233waveartist_cmd(wavnc_info *devc,
234 int nr_cmd, unsigned int *cmd,
235 int nr_resp, unsigned int *resp)
236{
237 unsigned int io_base = devc->hw.io_base;
238 unsigned int timed_out = 0;
239 unsigned int i;
240
241 if (debug_flg & DEBUG_CMD) {
242 printk("waveartist_cmd: cmd=");
243
244 for (i = 0; i < nr_cmd; i++)
245 printk("%04X ", cmd[i]);
246
247 printk("\n");
248 }
249
250 if (inb(io_base + STATR) & CMD_RF) {
251 int old_data;
252
253 /* flush the port
254 */
255
256 old_data = inw(io_base + CMDR);
257
258 if (debug_flg & DEBUG_CMD)
259 printk("flushed %04X...", old_data);
260
261 udelay(10);
262 }
263
264 for (i = 0; !timed_out && i < nr_cmd; i++) {
265 int count;
266
267 for (count = 5000; count; count--)
268 if (inb(io_base + STATR) & CMD_WE)
269 break;
270
271 if (!count)
272 timed_out = 1;
273 else
274 outw(cmd[i], io_base + CMDR);
275 }
276
277 for (i = 0; !timed_out && i < nr_resp; i++) {
278 int count;
279
280 for (count = 5000; count; count--)
281 if (inb(io_base + STATR) & CMD_RF)
282 break;
283
284 if (!count)
285 timed_out = 1;
286 else
287 resp[i] = inw(io_base + CMDR);
288 }
289
290 if (debug_flg & DEBUG_CMD) {
291 if (!timed_out) {
292 printk("waveartist_cmd: resp=");
293
294 for (i = 0; i < nr_resp; i++)
295 printk("%04X ", resp[i]);
296
297 printk("\n");
298 } else
299 printk("waveartist_cmd: timed out\n");
300 }
301
302 return timed_out ? 1 : 0;
303}
304
305/*
306 * Send one command word
307 */
308static inline int
309waveartist_cmd1(wavnc_info *devc, unsigned int cmd)
310{
311 return waveartist_cmd(devc, 1, &cmd, 0, NULL);
312}
313
314/*
315 * Send one command, receive one word
316 */
317static inline unsigned int
318waveartist_cmd1_r(wavnc_info *devc, unsigned int cmd)
319{
320 unsigned int ret;
321
322 waveartist_cmd(devc, 1, &cmd, 1, &ret);
323
324 return ret;
325}
326
327/*
328 * Send a double command, receive one
329 * word (and throw it away)
330 */
331static inline int
332waveartist_cmd2(wavnc_info *devc, unsigned int cmd, unsigned int arg)
333{
334 unsigned int vals[2];
335
336 vals[0] = cmd;
337 vals[1] = arg;
338
339 return waveartist_cmd(devc, 2, vals, 1, vals);
340}
341
342/*
343 * Send a triple command
344 */
345static inline int
346waveartist_cmd3(wavnc_info *devc, unsigned int cmd,
347 unsigned int arg1, unsigned int arg2)
348{
349 unsigned int vals[3];
350
351 vals[0] = cmd;
352 vals[1] = arg1;
353 vals[2] = arg2;
354
355 return waveartist_cmd(devc, 3, vals, 0, NULL);
356}
357
358static int
359waveartist_getrev(wavnc_info *devc, char *rev)
360{
361 unsigned int temp[2];
362 unsigned int cmd = WACMD_GETREV;
363
364 waveartist_cmd(devc, 1, &cmd, 2, temp);
365
366 rev[0] = temp[0] >> 8;
367 rev[1] = temp[0] & 255;
368 rev[2] = '\0';
369
370 return temp[0];
371}
372
373static void waveartist_halt_output(int dev);
374static void waveartist_halt_input(int dev);
375static void waveartist_halt(int dev);
376static void waveartist_trigger(int dev, int state);
377
378static int
379waveartist_open(int dev, int mode)
380{
381 wavnc_info *devc;
382 wavnc_port_info *portc;
383 unsigned long flags;
384
385 if (dev < 0 || dev >= num_audiodevs)
386 return -ENXIO;
387
388 devc = (wavnc_info *) audio_devs[dev]->devc;
389 portc = (wavnc_port_info *) audio_devs[dev]->portc;
390
391 spin_lock_irqsave(&waveartist_lock, flags);
392 if (portc->open_mode || (devc->open_mode & mode)) {
393 spin_unlock_irqrestore(&waveartist_lock, flags);
394 return -EBUSY;
395 }
396
397 devc->audio_mode = 0;
398 devc->open_mode |= mode;
399 portc->open_mode = mode;
400 waveartist_trigger(dev, 0);
401
402 if (mode & OPEN_READ)
403 devc->record_dev = dev;
404 if (mode & OPEN_WRITE)
405 devc->playback_dev = dev;
406 spin_unlock_irqrestore(&waveartist_lock, flags);
407
408 return 0;
409}
410
411static void
412waveartist_close(int dev)
413{
414 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
415 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
416 unsigned long flags;
417
418 spin_lock_irqsave(&waveartist_lock, flags);
419
420 waveartist_halt(dev);
421
422 devc->audio_mode = 0;
423 devc->open_mode &= ~portc->open_mode;
424 portc->open_mode = 0;
425
426 spin_unlock_irqrestore(&waveartist_lock, flags);
427}
428
429static void
430waveartist_output_block(int dev, unsigned long buf, int __count, int intrflag)
431{
432 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
433 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
434 unsigned long flags;
435 unsigned int count = __count;
436
437 if (debug_flg & DEBUG_OUT)
438 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
439 buf, count);
440 /*
441 * 16 bit data
442 */
443 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
444 count >>= 1;
445
446 if (portc->channels > 1)
447 count >>= 1;
448
449 count -= 1;
450
451 if (devc->audio_mode & PCM_ENABLE_OUTPUT &&
452 audio_devs[dev]->flags & DMA_AUTOMODE &&
453 intrflag &&
454 count == devc->xfer_count) {
455 devc->audio_mode |= PCM_ENABLE_OUTPUT;
456 return; /*
457 * Auto DMA mode on. No need to react
458 */
459 }
460
461 spin_lock_irqsave(&waveartist_lock, flags);
462
463 /*
464 * set sample count
465 */
466 waveartist_cmd2(devc, WACMD_OUTPUTSIZE, count);
467
468 devc->xfer_count = count;
469 devc->audio_mode |= PCM_ENABLE_OUTPUT;
470
471 spin_unlock_irqrestore(&waveartist_lock, flags);
472}
473
474static void
475waveartist_start_input(int dev, unsigned long buf, int __count, int intrflag)
476{
477 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
478 wavnc_info *devc = (wavnc_info *) 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(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(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 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
571 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
572 unsigned int speed, bits;
573
574 if (devc->audio_mode)
575 return 0;
576
577 speed = waveartist_get_speed(portc);
578 bits = waveartist_get_bits(portc);
579
580 spin_lock_irqsave(&waveartist_lock, flags);
581
582 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
583 printk(KERN_WARNING "waveartist: error setting the "
584 "record format to %d\n", portc->audio_format);
585
586 if (waveartist_cmd2(devc, WACMD_INPUTCHANNELS, portc->channels))
587 printk(KERN_WARNING "waveartist: error setting record "
588 "to %d channels\n", portc->channels);
589
590 /*
591 * write cmd SetSampleSpeedTimeConstant
592 */
593 if (waveartist_cmd2(devc, WACMD_INPUTSPEED, speed))
594 printk(KERN_WARNING "waveartist: error setting the record "
595 "speed to %dHz.\n", portc->speed);
596
597 if (waveartist_cmd2(devc, WACMD_INPUTDMA, 1))
598 printk(KERN_WARNING "waveartist: error setting the record "
599 "data path to 0x%X\n", 1);
600
601 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
602 printk(KERN_WARNING "waveartist: error setting the record "
603 "format to %d\n", portc->audio_format);
604
605 devc->xfer_count = 0;
606 spin_unlock_irqrestore(&waveartist_lock, flags);
607 waveartist_halt_input(dev);
608
609 if (debug_flg & DEBUG_INTR) {
610 printk("WA CTLR reg: 0x%02X.\n",
611 inb(devc->hw.io_base + CTLR));
612 printk("WA STAT reg: 0x%02X.\n",
613 inb(devc->hw.io_base + STATR));
614 printk("WA IRQS reg: 0x%02X.\n",
615 inb(devc->hw.io_base + IRQSTAT));
616 }
617
618 return 0;
619}
620
621static int
622waveartist_prepare_for_output(int dev, int bsize, int bcount)
623{
624 unsigned long flags;
625 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
626 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
627 unsigned int speed, bits;
628
629 /*
630 * program the speed, channels, bits
631 */
632 speed = waveartist_get_speed(portc);
633 bits = waveartist_get_bits(portc);
634
635 spin_lock_irqsave(&waveartist_lock, flags);
636
637 if (waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed) &&
638 waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed))
639 printk(KERN_WARNING "waveartist: error setting the playback "
640 "speed to %dHz.\n", portc->speed);
641
642 if (waveartist_cmd2(devc, WACMD_OUTPUTCHANNELS, portc->channels))
643 printk(KERN_WARNING "waveartist: error setting the playback "
644 "to %d channels\n", portc->channels);
645
646 if (waveartist_cmd2(devc, WACMD_OUTPUTDMA, 0))
647 printk(KERN_WARNING "waveartist: error setting the playback "
648 "data path to 0x%X\n", 0);
649
650 if (waveartist_cmd2(devc, WACMD_OUTPUTFORMAT, bits))
651 printk(KERN_WARNING "waveartist: error setting the playback "
652 "format to %d\n", portc->audio_format);
653
654 devc->xfer_count = 0;
655 spin_unlock_irqrestore(&waveartist_lock, flags);
656 waveartist_halt_output(dev);
657
658 if (debug_flg & DEBUG_INTR) {
659 printk("WA CTLR reg: 0x%02X.\n",inb(devc->hw.io_base + CTLR));
660 printk("WA STAT reg: 0x%02X.\n",inb(devc->hw.io_base + STATR));
661 printk("WA IRQS reg: 0x%02X.\n",inb(devc->hw.io_base + IRQSTAT));
662 }
663
664 return 0;
665}
666
667static void
668waveartist_halt(int dev)
669{
670 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
671 wavnc_info *devc;
672
673 if (portc->open_mode & OPEN_WRITE)
674 waveartist_halt_output(dev);
675
676 if (portc->open_mode & OPEN_READ)
677 waveartist_halt_input(dev);
678
679 devc = (wavnc_info *) audio_devs[dev]->devc;
680 devc->audio_mode = 0;
681}
682
683static void
684waveartist_halt_input(int dev)
685{
686 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
687 unsigned long flags;
688
689 spin_lock_irqsave(&waveartist_lock, flags);
690
691 /*
692 * Stop capture
693 */
694 waveartist_cmd1(devc, WACMD_INPUTSTOP);
695
696 devc->audio_mode &= ~PCM_ENABLE_INPUT;
697
698 /*
699 * Clear interrupt by toggling
700 * the IRQ_ACK bit in CTRL
701 */
702 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
703 waveartist_iack(devc);
704
705// devc->audio_mode &= ~PCM_ENABLE_INPUT;
706
707 spin_unlock_irqrestore(&waveartist_lock, flags);
708}
709
710static void
711waveartist_halt_output(int dev)
712{
713 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
714 unsigned long flags;
715
716 spin_lock_irqsave(&waveartist_lock, flags);
717
718 waveartist_cmd1(devc, WACMD_OUTPUTSTOP);
719
720 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
721
722 /*
723 * Clear interrupt by toggling
724 * the IRQ_ACK bit in CTRL
725 */
726 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
727 waveartist_iack(devc);
728
729// devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
730
731 spin_unlock_irqrestore(&waveartist_lock, flags);
732}
733
734static void
735waveartist_trigger(int dev, int state)
736{
737 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
738 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
739 unsigned long flags;
740
741 if (debug_flg & DEBUG_TRIGGER) {
742 printk("wavnc: audio trigger ");
743 if (state & PCM_ENABLE_INPUT)
744 printk("in ");
745 if (state & PCM_ENABLE_OUTPUT)
746 printk("out");
747 printk("\n");
748 }
749
750 spin_lock_irqsave(&waveartist_lock, flags);
751
752 state &= devc->audio_mode;
753
754 if (portc->open_mode & OPEN_READ &&
755 state & PCM_ENABLE_INPUT)
756 /*
757 * enable ADC Data Transfer to PC
758 */
759 waveartist_cmd1(devc, WACMD_INPUTSTART);
760
761 if (portc->open_mode & OPEN_WRITE &&
762 state & PCM_ENABLE_OUTPUT)
763 /*
764 * enable DAC data transfer from PC
765 */
766 waveartist_cmd1(devc, WACMD_OUTPUTSTART);
767
768 spin_unlock_irqrestore(&waveartist_lock, flags);
769}
770
771static int
772waveartist_set_speed(int dev, int arg)
773{
774 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
775
776 if (arg <= 0)
777 return portc->speed;
778
779 if (arg < 5000)
780 arg = 5000;
781 if (arg > 44100)
782 arg = 44100;
783
784 portc->speed = arg;
785 return portc->speed;
786
787}
788
789static short
790waveartist_set_channels(int dev, short arg)
791{
792 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
793
794 if (arg != 1 && arg != 2)
795 return portc->channels;
796
797 portc->channels = arg;
798 return arg;
799}
800
801static unsigned int
802waveartist_set_bits(int dev, unsigned int arg)
803{
804 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
805
806 if (arg == 0)
807 return portc->audio_format;
808
809 if ((arg != AFMT_U8) && (arg != AFMT_S16_LE) && (arg != AFMT_S8))
810 arg = AFMT_U8;
811
812 portc->audio_format = arg;
813
814 return arg;
815}
816
817static struct audio_driver waveartist_audio_driver = {
818 .owner = THIS_MODULE,
819 .open = waveartist_open,
820 .close = waveartist_close,
821 .output_block = waveartist_output_block,
822 .start_input = waveartist_start_input,
823 .ioctl = waveartist_ioctl,
824 .prepare_for_input = waveartist_prepare_for_input,
825 .prepare_for_output = waveartist_prepare_for_output,
826 .halt_io = waveartist_halt,
827 .halt_input = waveartist_halt_input,
828 .halt_output = waveartist_halt_output,
829 .trigger = waveartist_trigger,
830 .set_speed = waveartist_set_speed,
831 .set_bits = waveartist_set_bits,
832 .set_channels = waveartist_set_channels
833};
834
835
836static irqreturn_t
837waveartist_intr(int irq, void *dev_id, struct pt_regs *regs)
838{
839 wavnc_info *devc = (wavnc_info *)dev_id;
840 int irqstatus, status;
841
842 spin_lock(&waveartist_lock);
843 irqstatus = inb(devc->hw.io_base + IRQSTAT);
844 status = inb(devc->hw.io_base + STATR);
845
846 if (debug_flg & DEBUG_INTR)
847 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
848 status, irqstatus);
849
850 if (status & IRQ_REQ) /* Clear interrupt */
851 waveartist_iack(devc);
852 else
853 printk(KERN_WARNING "waveartist: unexpected interrupt\n");
854
855 if (irqstatus & 0x01) {
856 int temp = 1;
857
858 /* PCM buffer done
859 */
860 if ((status & DMA0) && (devc->audio_mode & PCM_ENABLE_OUTPUT)) {
861 DMAbuf_outputintr(devc->playback_dev, 1);
862 temp = 0;
863 }
864 if ((status & DMA1) && (devc->audio_mode & PCM_ENABLE_INPUT)) {
865 DMAbuf_inputintr(devc->record_dev);
866 temp = 0;
867 }
868 if (temp) //default:
869 printk(KERN_WARNING "waveartist: Unknown interrupt\n");
870 }
871 if (irqstatus & 0x2)
872 // We do not use SB mode natively...
873 printk(KERN_WARNING "waveartist: Unexpected SB interrupt...\n");
874 spin_unlock(&waveartist_lock);
875 return IRQ_HANDLED;
876}
877
878/* -------------------------------------------------------------------------
879 * Mixer stuff
880 */
881struct mix_ent {
882 unsigned char reg_l;
883 unsigned char reg_r;
884 unsigned char shift;
885 unsigned char max;
886};
887
888static const struct mix_ent mix_devs[SOUND_MIXER_NRDEVICES] = {
889 { 2, 6, 1, 7 }, /* SOUND_MIXER_VOLUME */
890 { 0, 0, 0, 0 }, /* SOUND_MIXER_BASS */
891 { 0, 0, 0, 0 }, /* SOUND_MIXER_TREBLE */
892 { 0, 0, 0, 0 }, /* SOUND_MIXER_SYNTH */
893 { 0, 0, 0, 0 }, /* SOUND_MIXER_PCM */
894 { 0, 0, 0, 0 }, /* SOUND_MIXER_SPEAKER */
895 { 0, 4, 6, 31 }, /* SOUND_MIXER_LINE */
896 { 2, 6, 4, 3 }, /* SOUND_MIXER_MIC */
897 { 0, 0, 0, 0 }, /* SOUND_MIXER_CD */
898 { 0, 0, 0, 0 }, /* SOUND_MIXER_IMIX */
899 { 0, 0, 0, 0 }, /* SOUND_MIXER_ALTPCM */
900#if 0
901 { 3, 7, 0, 10 }, /* SOUND_MIXER_RECLEV */
902 { 0, 0, 0, 0 }, /* SOUND_MIXER_IGAIN */
903#else
904 { 0, 0, 0, 0 }, /* SOUND_MIXER_RECLEV */
905 { 3, 7, 0, 7 }, /* SOUND_MIXER_IGAIN */
906#endif
907 { 0, 0, 0, 0 }, /* SOUND_MIXER_OGAIN */
908 { 0, 4, 1, 31 }, /* SOUND_MIXER_LINE1 */
909 { 1, 5, 6, 31 }, /* SOUND_MIXER_LINE2 */
910 { 0, 0, 0, 0 }, /* SOUND_MIXER_LINE3 */
911 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL1 */
912 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL2 */
913 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL3 */
914 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEIN */
915 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEOUT */
916 { 0, 0, 0, 0 }, /* SOUND_MIXER_VIDEO */
917 { 0, 0, 0, 0 }, /* SOUND_MIXER_RADIO */
918 { 0, 0, 0, 0 } /* SOUND_MIXER_MONITOR */
919};
920
921static void
922waveartist_mixer_update(wavnc_info *devc, int whichDev)
923{
924 unsigned int lev_left, lev_right;
925
926 lev_left = devc->levels[whichDev] & 0xff;
927 lev_right = devc->levels[whichDev] >> 8;
928
929 if (lev_left > 100)
930 lev_left = 100;
931 if (lev_right > 100)
932 lev_right = 100;
933
934#define SCALE(lev,max) ((lev) * (max) / 100)
935
936 if (machine_is_netwinder() && whichDev == SOUND_MIXER_PHONEOUT)
937 whichDev = SOUND_MIXER_VOLUME;
938
939 if (mix_devs[whichDev].reg_l || mix_devs[whichDev].reg_r) {
940 const struct mix_ent *mix = mix_devs + whichDev;
941 unsigned int mask, left, right;
942
943 mask = mix->max << mix->shift;
944 lev_left = SCALE(lev_left, mix->max) << mix->shift;
945 lev_right = SCALE(lev_right, mix->max) << mix->shift;
946
947 /* read left setting */
948 left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
949 mix->reg_l << 8);
950
951 /* read right setting */
952 right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
953 mix->reg_r << 8);
954
955 left = (left & ~mask) | (lev_left & mask);
956 right = (right & ~mask) | (lev_right & mask);
957
958 /* write left,right back */
959 waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
960 } else {
961 switch(whichDev) {
962 case SOUND_MIXER_PCM:
963 waveartist_cmd3(devc, WACMD_SET_LEVEL,
964 SCALE(lev_left, 32767),
965 SCALE(lev_right, 32767));
966 break;
967
968 case SOUND_MIXER_SYNTH:
969 waveartist_cmd3(devc, 0x0100 | WACMD_SET_LEVEL,
970 SCALE(lev_left, 32767),
971 SCALE(lev_right, 32767));
972 break;
973 }
974 }
975}
976
977/*
978 * Set the ADC MUX to the specified values. We do NOT do any
979 * checking of the values passed, since we assume that the
980 * relevant *_select_input function has done that for us.
981 */
982static void
983waveartist_set_adc_mux(wavnc_info *devc, char left_dev, char right_dev)
984{
985 unsigned int reg_08, reg_09;
986
987 reg_08 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0800);
988 reg_09 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0900);
989
990 reg_08 = (reg_08 & ~0x3f) | right_dev << 3 | left_dev;
991
992 waveartist_cmd3(devc, WACMD_SET_MIXER, reg_08, reg_09);
993}
994
995/*
996 * Decode a recording mask into a mixer selection as follows:
997 *
998 * OSS Source WA Source Actual source
999 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1000 * SOUND_MASK_LINE Line Line in
1001 * SOUND_MASK_LINE1 Aux 1 Aux 1 in
1002 * SOUND_MASK_LINE2 Aux 2 Aux 2 in
1003 * SOUND_MASK_MIC Mic Microphone
1004 */
1005static unsigned int
1006waveartist_select_input(wavnc_info *devc, unsigned int recmask,
1007 unsigned char *dev_l, unsigned char *dev_r)
1008{
1009 unsigned int recdev = ADC_MUX_NONE;
1010
1011 if (recmask & SOUND_MASK_IMIX) {
1012 recmask = SOUND_MASK_IMIX;
1013 recdev = ADC_MUX_MIXER;
1014 } else if (recmask & SOUND_MASK_LINE2) {
1015 recmask = SOUND_MASK_LINE2;
1016 recdev = ADC_MUX_AUX2;
1017 } else if (recmask & SOUND_MASK_LINE1) {
1018 recmask = SOUND_MASK_LINE1;
1019 recdev = ADC_MUX_AUX1;
1020 } else if (recmask & SOUND_MASK_LINE) {
1021 recmask = SOUND_MASK_LINE;
1022 recdev = ADC_MUX_LINE;
1023 } else if (recmask & SOUND_MASK_MIC) {
1024 recmask = SOUND_MASK_MIC;
1025 recdev = ADC_MUX_MIC;
1026 }
1027
1028 *dev_l = *dev_r = recdev;
1029
1030 return recmask;
1031}
1032
1033static int
1034waveartist_decode_mixer(wavnc_info *devc, int dev, unsigned char lev_l,
1035 unsigned char lev_r)
1036{
1037 switch (dev) {
1038 case SOUND_MIXER_VOLUME:
1039 case SOUND_MIXER_SYNTH:
1040 case SOUND_MIXER_PCM:
1041 case SOUND_MIXER_LINE:
1042 case SOUND_MIXER_MIC:
1043 case SOUND_MIXER_IGAIN:
1044 case SOUND_MIXER_LINE1:
1045 case SOUND_MIXER_LINE2:
1046 devc->levels[dev] = lev_l | lev_r << 8;
1047 break;
1048
1049 case SOUND_MIXER_IMIX:
1050 break;
1051
1052 default:
1053 dev = -EINVAL;
1054 break;
1055 }
1056
1057 return dev;
1058}
1059
1060static int waveartist_get_mixer(wavnc_info *devc, int dev)
1061{
1062 return devc->levels[dev];
1063}
1064
1065static const struct waveartist_mixer_info waveartist_mixer = {
1066 .supported_devs = SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN,
1067 .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
1068 SOUND_MASK_LINE1 | SOUND_MASK_LINE2 |
1069 SOUND_MASK_IMIX,
1070 .stereo_devs = (SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN) & ~
1071 (SOUND_MASK_SPEAKER | SOUND_MASK_IMIX),
1072 .select_input = waveartist_select_input,
1073 .decode_mixer = waveartist_decode_mixer,
1074 .get_mixer = waveartist_get_mixer,
1075};
1076
1077static void
1078waveartist_set_recmask(wavnc_info *devc, unsigned int recmask)
1079{
1080 unsigned char dev_l, dev_r;
1081
1082 recmask &= devc->mix->recording_devs;
1083
1084 /*
1085 * If more than one recording device selected,
1086 * disable the device that is currently in use.
1087 */
1088 if (hweight32(recmask) > 1)
1089 recmask &= ~devc->recmask;
1090
1091 /*
1092 * Translate the recording device mask into
1093 * the ADC multiplexer settings.
1094 */
1095 devc->recmask = devc->mix->select_input(devc, recmask,
1096 &dev_l, &dev_r);
1097
1098 waveartist_set_adc_mux(devc, dev_l, dev_r);
1099}
1100
1101static int
1102waveartist_set_mixer(wavnc_info *devc, int dev, unsigned int level)
1103{
1104 unsigned int lev_left = level & 0x00ff;
1105 unsigned int lev_right = (level & 0xff00) >> 8;
1106
1107 if (lev_left > 100)
1108 lev_left = 100;
1109 if (lev_right > 100)
1110 lev_right = 100;
1111
1112 /*
1113 * Mono devices have their right volume forced to their
1114 * left volume. (from ALSA driver OSS emulation).
1115 */
1116 if (!(devc->mix->stereo_devs & (1 << dev)))
1117 lev_right = lev_left;
1118
1119 dev = devc->mix->decode_mixer(devc, dev, lev_left, lev_right);
1120
1121 if (dev >= 0)
1122 waveartist_mixer_update(devc, dev);
1123
1124 return dev < 0 ? dev : 0;
1125}
1126
1127static int
1128waveartist_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
1129{
1130 wavnc_info *devc = (wavnc_info *)audio_devs[dev]->devc;
1131 int ret = 0, val, nr;
1132
1133 /*
1134 * All SOUND_MIXER_* ioctls use type 'M'
1135 */
1136 if (((cmd >> 8) & 255) != 'M')
1137 return -ENOIOCTLCMD;
1138
1139#ifdef CONFIG_ARCH_NETWINDER
1140 if (machine_is_netwinder()) {
1141 ret = vnc_private_ioctl(dev, cmd, arg);
1142 if (ret != -ENOIOCTLCMD)
1143 return ret;
1144 else
1145 ret = 0;
1146 }
1147#endif
1148
1149 nr = cmd & 0xff;
1150
1151 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1152 if (get_user(val, (int __user *)arg))
1153 return -EFAULT;
1154
1155 switch (nr) {
1156 case SOUND_MIXER_RECSRC:
1157 waveartist_set_recmask(devc, val);
1158 break;
1159
1160 default:
1161 ret = -EINVAL;
1162 if (nr < SOUND_MIXER_NRDEVICES &&
1163 devc->mix->supported_devs & (1 << nr))
1164 ret = waveartist_set_mixer(devc, nr, val);
1165 }
1166 }
1167
1168 if (ret == 0 && _SIOC_DIR(cmd) & _SIOC_READ) {
1169 ret = -EINVAL;
1170
1171 switch (nr) {
1172 case SOUND_MIXER_RECSRC:
1173 ret = devc->recmask;
1174 break;
1175
1176 case SOUND_MIXER_DEVMASK:
1177 ret = devc->mix->supported_devs;
1178 break;
1179
1180 case SOUND_MIXER_STEREODEVS:
1181 ret = devc->mix->stereo_devs;
1182 break;
1183
1184 case SOUND_MIXER_RECMASK:
1185 ret = devc->mix->recording_devs;
1186 break;
1187
1188 case SOUND_MIXER_CAPS:
1189 ret = SOUND_CAP_EXCL_INPUT;
1190 break;
1191
1192 default:
1193 if (nr < SOUND_MIXER_NRDEVICES)
1194 ret = devc->mix->get_mixer(devc, nr);
1195 break;
1196 }
1197
1198 if (ret >= 0)
1199 ret = put_user(ret, (int __user *)arg) ? -EFAULT : 0;
1200 }
1201
1202 return ret;
1203}
1204
1205static struct mixer_operations waveartist_mixer_operations =
1206{
1207 .owner = THIS_MODULE,
1208 .id = "WaveArtist",
1209 .name = "WaveArtist",
1210 .ioctl = waveartist_mixer_ioctl
1211};
1212
1213static void
1214waveartist_mixer_reset(wavnc_info *devc)
1215{
1216 int i;
1217
1218 if (debug_flg & DEBUG_MIXER)
1219 printk("%s: mixer_reset\n", devc->hw.name);
1220
1221 /*
1222 * reset mixer cmd
1223 */
1224 waveartist_cmd1(devc, WACMD_RST_MIXER);
1225
1226 /*
1227 * set input for ADC to come from 'quiet'
1228 * turn on default modes
1229 */
1230 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x9800, 0xa836);
1231
1232 /*
1233 * set mixer input select to none, RX filter gains 0 dB
1234 */
1235 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x4c00, 0x8c00);
1236
1237 /*
1238 * set bit 0 reg 2 to 1 - unmute MonoOut
1239 */
1240 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x2801, 0x6800);
1241
1242 /* set default input device = internal mic
1243 * current recording device = none
1244 */
1245 waveartist_set_recmask(devc, 0);
1246
1247 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1248 waveartist_mixer_update(devc, i);
1249}
1250
1251static int __init waveartist_init(wavnc_info *devc)
1252{
1253 wavnc_port_info *portc;
1254 char rev[3], dev_name[64];
1255 int my_dev;
1256
1257 if (waveartist_reset(devc))
1258 return -ENODEV;
1259
1260 sprintf(dev_name, "%s (%s", devc->hw.name, devc->chip_name);
1261
1262 if (waveartist_getrev(devc, rev)) {
1263 strcat(dev_name, " rev. ");
1264 strcat(dev_name, rev);
1265 }
1266 strcat(dev_name, ")");
1267
1268 conf_printf2(dev_name, devc->hw.io_base, devc->hw.irq,
1269 devc->hw.dma, devc->hw.dma2);
1270
1271 portc = (wavnc_port_info *)kmalloc(sizeof(wavnc_port_info), GFP_KERNEL);
1272 if (portc == NULL)
1273 goto nomem;
1274
1275 memset(portc, 0, sizeof(wavnc_port_info));
1276
1277 my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, dev_name,
1278 &waveartist_audio_driver, sizeof(struct audio_driver),
1279 devc->audio_flags, AFMT_U8 | AFMT_S16_LE | AFMT_S8,
1280 devc, devc->hw.dma, devc->hw.dma2);
1281
1282 if (my_dev < 0)
1283 goto free;
1284
1285 audio_devs[my_dev]->portc = portc;
1286
1287 waveartist_mixer_reset(devc);
1288
1289 /*
1290 * clear any pending interrupt
1291 */
1292 waveartist_iack(devc);
1293
1294 if (request_irq(devc->hw.irq, waveartist_intr, 0, devc->hw.name, devc) < 0) {
1295 printk(KERN_ERR "%s: IRQ %d in use\n",
1296 devc->hw.name, devc->hw.irq);
1297 goto uninstall;
1298 }
1299
1300 if (sound_alloc_dma(devc->hw.dma, devc->hw.name)) {
1301 printk(KERN_ERR "%s: Can't allocate DMA%d\n",
1302 devc->hw.name, devc->hw.dma);
1303 goto uninstall_irq;
1304 }
1305
1306 if (devc->hw.dma != devc->hw.dma2 && devc->hw.dma2 != NO_DMA)
1307 if (sound_alloc_dma(devc->hw.dma2, devc->hw.name)) {
1308 printk(KERN_ERR "%s: can't allocate DMA%d\n",
1309 devc->hw.name, devc->hw.dma2);
1310 goto uninstall_dma;
1311 }
1312
1313 waveartist_set_ctlr(&devc->hw, 0, DMA1_IE | DMA0_IE);
1314
1315 audio_devs[my_dev]->mixer_dev =
1316 sound_install_mixer(MIXER_DRIVER_VERSION,
1317 dev_name,
1318 &waveartist_mixer_operations,
1319 sizeof(struct mixer_operations),
1320 devc);
1321
1322 return my_dev;
1323
1324uninstall_dma:
1325 sound_free_dma(devc->hw.dma);
1326
1327uninstall_irq:
1328 free_irq(devc->hw.irq, devc);
1329
1330uninstall:
1331 sound_unload_audiodev(my_dev);
1332
1333free:
1334 kfree(portc);
1335
1336nomem:
1337 return -1;
1338}
1339
1340static int __init probe_waveartist(struct address_info *hw_config)
1341{
1342 wavnc_info *devc = &adev_info[nr_waveartist_devs];
1343
1344 if (nr_waveartist_devs >= MAX_AUDIO_DEV) {
1345 printk(KERN_WARNING "waveartist: too many audio devices\n");
1346 return 0;
1347 }
1348
1349 if (!request_region(hw_config->io_base, 15, hw_config->name)) {
1350 printk(KERN_WARNING "WaveArtist: I/O port conflict\n");
1351 return 0;
1352 }
1353
1354 if (hw_config->irq > 15 || hw_config->irq < 0) {
1355 release_region(hw_config->io_base, 15);
1356 printk(KERN_WARNING "WaveArtist: Bad IRQ %d\n",
1357 hw_config->irq);
1358 return 0;
1359 }
1360
1361 if (hw_config->dma != 3) {
1362 release_region(hw_config->io_base, 15);
1363 printk(KERN_WARNING "WaveArtist: Bad DMA %d\n",
1364 hw_config->dma);
1365 return 0;
1366 }
1367
1368 hw_config->name = "WaveArtist";
1369 devc->hw = *hw_config;
1370 devc->open_mode = 0;
1371 devc->chip_name = "RWA-010";
1372
1373 return 1;
1374}
1375
1376static void __init
1377attach_waveartist(struct address_info *hw, const struct waveartist_mixer_info *mix)
1378{
1379 wavnc_info *devc = &adev_info[nr_waveartist_devs];
1380
1381 /*
1382 * NOTE! If irq < 0, there is another driver which has allocated the
1383 * IRQ so that this driver doesn't need to allocate/deallocate it.
1384 * The actually used IRQ is ABS(irq).
1385 */
1386 devc->hw = *hw;
1387 devc->hw.irq = (hw->irq > 0) ? hw->irq : 0;
1388 devc->open_mode = 0;
1389 devc->playback_dev = 0;
1390 devc->record_dev = 0;
1391 devc->audio_flags = DMA_AUTOMODE;
1392 devc->levels = levels;
1393
1394 if (hw->dma != hw->dma2 && hw->dma2 != NO_DMA)
1395 devc->audio_flags |= DMA_DUPLEX;
1396
1397 devc->mix = mix;
1398 devc->dev_no = waveartist_init(devc);
1399
1400 if (devc->dev_no < 0)
1401 release_region(hw->io_base, 15);
1402 else {
1403#ifdef CONFIG_ARCH_NETWINDER
1404 if (machine_is_netwinder()) {
1405 init_timer(&vnc_timer);
1406 vnc_timer.function = vnc_slider_tick;
1407 vnc_timer.expires = jiffies;
1408 vnc_timer.data = nr_waveartist_devs;
1409 add_timer(&vnc_timer);
1410
1411 vnc_configure_mixer(devc, 0);
1412
1413 devc->no_autoselect = 1;
1414 }
1415#endif
1416 nr_waveartist_devs += 1;
1417 }
1418}
1419
1420static void __exit unload_waveartist(struct address_info *hw)
1421{
1422 wavnc_info *devc = NULL;
1423 int i;
1424
1425 for (i = 0; i < nr_waveartist_devs; i++)
1426 if (hw->io_base == adev_info[i].hw.io_base) {
1427 devc = adev_info + i;
1428 break;
1429 }
1430
1431 if (devc != NULL) {
1432 int mixer;
1433
1434#ifdef CONFIG_ARCH_NETWINDER
1435 if (machine_is_netwinder())
1436 del_timer(&vnc_timer);
1437#endif
1438
1439 release_region(devc->hw.io_base, 15);
1440
1441 waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
1442
1443 if (devc->hw.irq >= 0)
1444 free_irq(devc->hw.irq, devc);
1445
1446 sound_free_dma(devc->hw.dma);
1447
1448 if (devc->hw.dma != devc->hw.dma2 &&
1449 devc->hw.dma2 != NO_DMA)
1450 sound_free_dma(devc->hw.dma2);
1451
1452 mixer = audio_devs[devc->dev_no]->mixer_dev;
1453
1454 if (mixer >= 0)
1455 sound_unload_mixerdev(mixer);
1456
1457 if (devc->dev_no >= 0)
1458 sound_unload_audiodev(devc->dev_no);
1459
1460 nr_waveartist_devs -= 1;
1461
1462 for (; i < nr_waveartist_devs; i++)
1463 adev_info[i] = adev_info[i + 1];
1464 } else
1465 printk(KERN_WARNING "waveartist: can't find device "
1466 "to unload\n");
1467}
1468
1469#ifdef CONFIG_ARCH_NETWINDER
1470
1471/*
1472 * Rebel.com Netwinder specifics...
1473 */
1474
1475#include <asm/hardware/dec21285.h>
1476
1477#define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1478
1479#define MIXER_PRIVATE3_RESET 0x53570000
1480#define MIXER_PRIVATE3_READ 0x53570001
1481#define MIXER_PRIVATE3_WRITE 0x53570002
1482
1483#define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
1484#define VNC_MUTE_LINE_OUT 0x10
1485#define VNC_PHONE_DETECT 0x20
1486#define VNC_HANDSET_DETECT 0x40
1487#define VNC_DISABLE_AUTOSWITCH 0x80
1488
1489extern spinlock_t gpio_lock;
1490
1491static inline void
1492vnc_mute_spkr(wavnc_info *devc)
1493{
1494 unsigned long flags;
1495
1496 spin_lock_irqsave(&gpio_lock, flags);
1497 cpld_modify(CPLD_UNMUTE, devc->spkr_mute_state ? 0 : CPLD_UNMUTE);
1498 spin_unlock_irqrestore(&gpio_lock, flags);
1499}
1500
1501static void
1502vnc_mute_lout(wavnc_info *devc)
1503{
1504 unsigned int left, right;
1505
1506 left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL);
1507 right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x400);
1508
1509 if (devc->line_mute_state) {
1510 left &= ~1;
1511 right &= ~1;
1512 } else {
1513 left |= 1;
1514 right |= 1;
1515 }
1516 waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
1517
1518}
1519
1520static int
1521vnc_volume_slider(wavnc_info *devc)
1522{
1523 static signed int old_slider_volume;
1524 unsigned long flags;
1525 signed int volume = 255;
1526
1527 *CSR_TIMER1_LOAD = 0x00ffffff;
1528
1529 spin_lock_irqsave(&waveartist_lock, flags);
1530
1531 outb(0xFF, 0x201);
1532 *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
1533
1534 while (volume && (inb(0x201) & 0x01))
1535 volume--;
1536
1537 *CSR_TIMER1_CNTL = 0;
1538
1539 spin_unlock_irqrestore(&waveartist_lock,flags);
1540
1541 volume = 0x00ffffff - *CSR_TIMER1_VALUE;
1542
1543
1544#ifndef REVERSE
1545 volume = 150 - (volume >> 5);
1546#else
1547 volume = (volume >> 6) - 25;
1548#endif
1549
1550 if (volume < 0)
1551 volume = 0;
1552
1553 if (volume > 100)
1554 volume = 100;
1555
1556 /*
1557 * slider quite often reads +-8, so debounce this random noise
1558 */
1559 if (abs(volume - old_slider_volume) > 7) {
1560 old_slider_volume = volume;
1561
1562 if (debug_flg & DEBUG_MIXER)
1563 printk(KERN_DEBUG "Slider volume: %d.\n", volume);
1564 }
1565
1566 return old_slider_volume;
1567}
1568
1569/*
1570 * Decode a recording mask into a mixer selection on the NetWinder
1571 * as follows:
1572 *
1573 * OSS Source WA Source Actual source
1574 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1575 * SOUND_MASK_LINE Line Line in
1576 * SOUND_MASK_LINE1 Left Mic Handset
1577 * SOUND_MASK_PHONEIN Left Aux Telephone microphone
1578 * SOUND_MASK_MIC Right Mic Builtin microphone
1579 */
1580static unsigned int
1581netwinder_select_input(wavnc_info *devc, unsigned int recmask,
1582 unsigned char *dev_l, unsigned char *dev_r)
1583{
1584 unsigned int recdev_l = ADC_MUX_NONE, recdev_r = ADC_MUX_NONE;
1585
1586 if (recmask & SOUND_MASK_IMIX) {
1587 recmask = SOUND_MASK_IMIX;
1588 recdev_l = ADC_MUX_MIXER;
1589 recdev_r = ADC_MUX_MIXER;
1590 } else if (recmask & SOUND_MASK_LINE) {
1591 recmask = SOUND_MASK_LINE;
1592 recdev_l = ADC_MUX_LINE;
1593 recdev_r = ADC_MUX_LINE;
1594 } else if (recmask & SOUND_MASK_LINE1) {
1595 recmask = SOUND_MASK_LINE1;
1596 waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
1597 recdev_l = ADC_MUX_MIC;
1598 recdev_r = ADC_MUX_NONE;
1599 } else if (recmask & SOUND_MASK_PHONEIN) {
1600 recmask = SOUND_MASK_PHONEIN;
1601 waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
1602 recdev_l = ADC_MUX_AUX1;
1603 recdev_r = ADC_MUX_NONE;
1604 } else if (recmask & SOUND_MASK_MIC) {
1605 recmask = SOUND_MASK_MIC;
1606 waveartist_cmd1(devc, WACMD_SET_MONO | 0x100); /* right */
1607 recdev_l = ADC_MUX_NONE;
1608 recdev_r = ADC_MUX_MIC;
1609 }
1610
1611 *dev_l = recdev_l;
1612 *dev_r = recdev_r;
1613
1614 return recmask;
1615}
1616
1617static int
1618netwinder_decode_mixer(wavnc_info *devc, int dev, unsigned char lev_l,
1619 unsigned char lev_r)
1620{
1621 switch (dev) {
1622 case SOUND_MIXER_VOLUME:
1623 case SOUND_MIXER_SYNTH:
1624 case SOUND_MIXER_PCM:
1625 case SOUND_MIXER_LINE:
1626 case SOUND_MIXER_IGAIN:
1627 devc->levels[dev] = lev_l | lev_r << 8;
1628 break;
1629
1630 case SOUND_MIXER_MIC: /* right mic only */
1631 devc->levels[SOUND_MIXER_MIC] &= 0xff;
1632 devc->levels[SOUND_MIXER_MIC] |= lev_l << 8;
1633 break;
1634
1635 case SOUND_MIXER_LINE1: /* left mic only */
1636 devc->levels[SOUND_MIXER_MIC] &= 0xff00;
1637 devc->levels[SOUND_MIXER_MIC] |= lev_l;
1638 dev = SOUND_MIXER_MIC;
1639 break;
1640
1641 case SOUND_MIXER_PHONEIN: /* left aux only */
1642 devc->levels[SOUND_MIXER_LINE1] = lev_l;
1643 dev = SOUND_MIXER_LINE1;
1644 break;
1645
1646 case SOUND_MIXER_IMIX:
1647 case SOUND_MIXER_PHONEOUT:
1648 break;
1649
1650 default:
1651 dev = -EINVAL;
1652 break;
1653 }
1654 return dev;
1655}
1656
1657static int netwinder_get_mixer(wavnc_info *devc, int dev)
1658{
1659 int levels;
1660
1661 switch (dev) {
1662 case SOUND_MIXER_VOLUME:
1663 case SOUND_MIXER_SYNTH:
1664 case SOUND_MIXER_PCM:
1665 case SOUND_MIXER_LINE:
1666 case SOUND_MIXER_IGAIN:
1667 levels = devc->levels[dev];
1668 break;
1669
1670 case SOUND_MIXER_MIC: /* builtin mic: right mic only */
1671 levels = devc->levels[SOUND_MIXER_MIC] >> 8;
1672 levels |= levels << 8;
1673 break;
1674
1675 case SOUND_MIXER_LINE1: /* handset mic: left mic only */
1676 levels = devc->levels[SOUND_MIXER_MIC] & 0xff;
1677 levels |= levels << 8;
1678 break;
1679
1680 case SOUND_MIXER_PHONEIN: /* phone mic: left aux1 only */
1681 levels = devc->levels[SOUND_MIXER_LINE1] & 0xff;
1682 levels |= levels << 8;
1683 break;
1684
1685 default:
1686 levels = 0;
1687 }
1688
1689 return levels;
1690}
1691
1692/*
1693 * Waveartist specific mixer information.
1694 */
1695static const struct waveartist_mixer_info netwinder_mixer = {
1696 .supported_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
1697 SOUND_MASK_PCM | SOUND_MASK_SPEAKER |
1698 SOUND_MASK_LINE | SOUND_MASK_MIC |
1699 SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
1700 SOUND_MASK_PHONEIN | SOUND_MASK_PHONEOUT|
1701 SOUND_MASK_IGAIN,
1702
1703 .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
1704 SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
1705 SOUND_MASK_PHONEIN,
1706
1707 .stereo_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
1708 SOUND_MASK_PCM | SOUND_MASK_LINE |
1709 SOUND_MASK_IMIX | SOUND_MASK_IGAIN,
1710
1711 .select_input = netwinder_select_input,
1712 .decode_mixer = netwinder_decode_mixer,
1713 .get_mixer = netwinder_get_mixer,
1714};
1715
1716static void
1717vnc_configure_mixer(wavnc_info *devc, unsigned int recmask)
1718{
1719 if (!devc->no_autoselect) {
1720 if (devc->handset_detect) {
1721 recmask = SOUND_MASK_LINE1;
1722 devc->spkr_mute_state = devc->line_mute_state = 1;
1723 } else if (devc->telephone_detect) {
1724 recmask = SOUND_MASK_PHONEIN;
1725 devc->spkr_mute_state = devc->line_mute_state = 1;
1726 } else {
1727 /* unless someone has asked for LINE-IN,
1728 * we default to MIC
1729 */
1730 if ((devc->recmask & SOUND_MASK_LINE) == 0)
1731 devc->recmask = SOUND_MASK_MIC;
1732 devc->spkr_mute_state = devc->line_mute_state = 0;
1733 }
1734 vnc_mute_spkr(devc);
1735 vnc_mute_lout(devc);
1736
1737 if (recmask != devc->recmask)
1738 waveartist_set_recmask(devc, recmask);
1739 }
1740}
1741
1742static int
1743vnc_slider(wavnc_info *devc)
1744{
1745 signed int slider_volume;
1746 unsigned int temp, old_hs, old_td;
1747
1748 /*
1749 * read the "buttons" state.
1750 * Bit 4 = 0 means handset present
1751 * Bit 5 = 1 means phone offhook
1752 */
1753 temp = inb(0x201);
1754
1755 old_hs = devc->handset_detect;
1756 old_td = devc->telephone_detect;
1757
1758 devc->handset_detect = !(temp & 0x10);
1759 devc->telephone_detect = !!(temp & 0x20);
1760
1761 if (!devc->no_autoselect &&
1762 (old_hs != devc->handset_detect ||
1763 old_td != devc->telephone_detect))
1764 vnc_configure_mixer(devc, devc->recmask);
1765
1766 slider_volume = vnc_volume_slider(devc);
1767
1768 /*
1769 * If we're using software controlled volume, and
1770 * the slider moves by more than 20%, then we
1771 * switch back to slider controlled volume.
1772 */
1773 if (abs(devc->slider_vol - slider_volume) > 20)
1774 devc->use_slider = 1;
1775
1776 /*
1777 * use only left channel
1778 */
1779 temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
1780
1781 if (slider_volume != temp && devc->use_slider) {
1782 devc->slider_vol = slider_volume;
1783
1784 waveartist_set_mixer(devc, SOUND_MIXER_VOLUME,
1785 slider_volume | slider_volume << 8);
1786
1787 return 1;
1788 }
1789
1790 return 0;
1791}
1792
1793static void
1794vnc_slider_tick(unsigned long data)
1795{
1796 int next_timeout;
1797
1798 if (vnc_slider(adev_info + data))
1799 next_timeout = 5; // mixer reported change
1800 else
1801 next_timeout = VNC_TIMER_PERIOD;
1802
1803 mod_timer(&vnc_timer, jiffies + next_timeout);
1804}
1805
1806static int
1807vnc_private_ioctl(int dev, unsigned int cmd, int __user * arg)
1808{
1809 wavnc_info *devc = (wavnc_info *)audio_devs[dev]->devc;
1810 int val;
1811
1812 switch (cmd) {
1813 case SOUND_MIXER_PRIVATE1:
1814 {
1815 u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
1816 int val;
1817
1818 if (get_user(val, arg))
1819 return -EFAULT;
1820
1821 /* check if parameter is logical */
1822 if (val & ~(VNC_MUTE_INTERNAL_SPKR |
1823 VNC_MUTE_LINE_OUT |
1824 VNC_DISABLE_AUTOSWITCH))
1825 return -EINVAL;
1826
1827 prev_auto_state = devc->no_autoselect;
1828 prev_spkr_mute = devc->spkr_mute_state;
1829 prev_line_mute = devc->line_mute_state;
1830
1831 devc->no_autoselect = (val & VNC_DISABLE_AUTOSWITCH) ? 1 : 0;
1832 devc->spkr_mute_state = (val & VNC_MUTE_INTERNAL_SPKR) ? 1 : 0;
1833 devc->line_mute_state = (val & VNC_MUTE_LINE_OUT) ? 1 : 0;
1834
1835 if (prev_spkr_mute != devc->spkr_mute_state)
1836 vnc_mute_spkr(devc);
1837
1838 if (prev_line_mute != devc->line_mute_state)
1839 vnc_mute_lout(devc);
1840
1841 if (prev_auto_state != devc->no_autoselect)
1842 vnc_configure_mixer(devc, devc->recmask);
1843
1844 return 0;
1845 }
1846
1847 case SOUND_MIXER_PRIVATE2:
1848 if (get_user(val, arg))
1849 return -EFAULT;
1850
1851 switch (val) {
1852#define VNC_SOUND_PAUSE 0x53 //to pause the DSP
1853#define VNC_SOUND_RESUME 0x57 //to unpause the DSP
1854 case VNC_SOUND_PAUSE:
1855 waveartist_cmd1(devc, 0x16);
1856 break;
1857
1858 case VNC_SOUND_RESUME:
1859 waveartist_cmd1(devc, 0x18);
1860 break;
1861
1862 default:
1863 return -EINVAL;
1864 }
1865 return 0;
1866
1867 /* private ioctl to allow bulk access to waveartist */
1868 case SOUND_MIXER_PRIVATE3:
1869 {
1870 unsigned long flags;
1871 int mixer_reg[15], i, val;
1872
1873 if (get_user(val, arg))
1874 return -EFAULT;
1875 if (copy_from_user(mixer_reg, (void *)val, sizeof(mixer_reg)))
1876 return -EFAULT;
1877
1878 switch (mixer_reg[14]) {
1879 case MIXER_PRIVATE3_RESET:
1880 waveartist_mixer_reset(devc);
1881 break;
1882
1883 case MIXER_PRIVATE3_WRITE:
1884 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[0], mixer_reg[4]);
1885 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[1], mixer_reg[5]);
1886 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[2], mixer_reg[6]);
1887 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[3], mixer_reg[7]);
1888 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[8], mixer_reg[9]);
1889
1890 waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[10], mixer_reg[11]);
1891 waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[12], mixer_reg[13]);
1892 break;
1893
1894 case MIXER_PRIVATE3_READ:
1895 spin_lock_irqsave(&waveartist_lock, flags);
1896
1897 for (i = 0x30; i < 14 << 8; i += 1 << 8)
1898 waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
1899
1900 spin_unlock_irqrestore(&waveartist_lock, flags);
1901
1902 if (copy_to_user((void *)val, mixer_reg, sizeof(mixer_reg)))
1903 return -EFAULT;
1904 break;
1905
1906 default:
1907 return -EINVAL;
1908 }
1909 return 0;
1910 }
1911
1912 /* read back the state from PRIVATE1 */
1913 case SOUND_MIXER_PRIVATE4:
1914 val = (devc->spkr_mute_state ? VNC_MUTE_INTERNAL_SPKR : 0) |
1915 (devc->line_mute_state ? VNC_MUTE_LINE_OUT : 0) |
1916 (devc->handset_detect ? VNC_HANDSET_DETECT : 0) |
1917 (devc->telephone_detect ? VNC_PHONE_DETECT : 0) |
1918 (devc->no_autoselect ? VNC_DISABLE_AUTOSWITCH : 0);
1919
1920 return put_user(val, arg) ? -EFAULT : 0;
1921 }
1922
1923 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1924 /*
1925 * special case for master volume: if we
1926 * received this call - switch from hw
1927 * volume control to a software volume
1928 * control, till the hw volume is modified
1929 * to signal that user wants to be back in
1930 * hardware...
1931 */
1932 if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
1933 devc->use_slider = 0;
1934
1935 /* speaker output */
1936 if ((cmd & 0xff) == SOUND_MIXER_SPEAKER) {
1937 unsigned int val, l, r;
1938
1939 if (get_user(val, arg))
1940 return -EFAULT;
1941
1942 l = val & 0x7f;
1943 r = (val & 0x7f00) >> 8;
1944 val = (l + r) / 2;
1945 devc->levels[SOUND_MIXER_SPEAKER] = val | (val << 8);
1946 devc->spkr_mute_state = (val <= 50);
1947 vnc_mute_spkr(devc);
1948 return 0;
1949 }
1950 }
1951
1952 return -ENOIOCTLCMD;
1953}
1954
1955#endif
1956
1957static struct address_info cfg;
1958
1959static int attached;
1960
1961static int __initdata io = 0;
1962static int __initdata irq = 0;
1963static int __initdata dma = 0;
1964static int __initdata dma2 = 0;
1965
1966
1967static int __init init_waveartist(void)
1968{
1969 const struct waveartist_mixer_info *mix;
1970
1971 if (!io && machine_is_netwinder()) {
1972 /*
1973 * The NetWinder WaveArtist is at a fixed address.
1974 * If the user does not supply an address, use the
1975 * well-known parameters.
1976 */
1977 io = 0x250;
1978 irq = 12;
1979 dma = 3;
1980 dma2 = 7;
1981 }
1982
1983 mix = &waveartist_mixer;
1984#ifdef CONFIG_ARCH_NETWINDER
1985 if (machine_is_netwinder())
1986 mix = &netwinder_mixer;
1987#endif
1988
1989 cfg.io_base = io;
1990 cfg.irq = irq;
1991 cfg.dma = dma;
1992 cfg.dma2 = dma2;
1993
1994 if (!probe_waveartist(&cfg))
1995 return -ENODEV;
1996
1997 attach_waveartist(&cfg, mix);
1998 attached = 1;
1999
2000 return 0;
2001}
2002
2003static void __exit cleanup_waveartist(void)
2004{
2005 if (attached)
2006 unload_waveartist(&cfg);
2007}
2008
2009module_init(init_waveartist);
2010module_exit(cleanup_waveartist);
2011
2012#ifndef MODULE
2013static int __init setup_waveartist(char *str)
2014{
2015 /* io, irq, dma, dma2 */
2016 int ints[5];
2017
2018 str = get_options(str, ARRAY_SIZE(ints), ints);
2019
2020 io = ints[1];
2021 irq = ints[2];
2022 dma = ints[3];
2023 dma2 = ints[4];
2024
2025 return 1;
2026}
2027__setup("waveartist=", setup_waveartist);
2028#endif
2029
2030MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
2031MODULE_PARM(io, "i"); /* IO base */
2032MODULE_PARM(irq, "i"); /* IRQ */
2033MODULE_PARM(dma, "i"); /* DMA */
2034MODULE_PARM(dma2, "i"); /* DMA2 */
2035MODULE_LICENSE("GPL");
diff --git a/sound/oss/waveartist.h b/sound/oss/waveartist.h
new file mode 100644
index 000000000000..2033fb87b247
--- /dev/null
+++ b/sound/oss/waveartist.h
@@ -0,0 +1,92 @@
1/*
2 * linux/drivers/sound/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);
diff --git a/sound/oss/wavfront.c b/sound/oss/wavfront.c
new file mode 100644
index 000000000000..cce1278dc487
--- /dev/null
+++ b/sound/oss/wavfront.c
@@ -0,0 +1,3538 @@
1/* -*- linux-c -*-
2 *
3 * sound/wavfront.c
4 *
5 * A Linux driver for Turtle Beach WaveFront Series (Maui, Tropez, Tropez Plus)
6 *
7 * This driver supports the onboard wavetable synthesizer (an ICS2115),
8 * including patch, sample and program loading and unloading, conversion
9 * of GUS patches during loading, and full user-level access to all
10 * WaveFront commands. It tries to provide semi-intelligent patch and
11 * sample management as well.
12 *
13 * It also provides support for the ICS emulation of an MPU-401. Full
14 * support for the ICS emulation's "virtual MIDI mode" is provided in
15 * wf_midi.c.
16 *
17 * Support is also provided for the Tropez Plus' onboard FX processor,
18 * a Yamaha YSS225. Currently, code exists to configure the YSS225,
19 * and there is an interface allowing tweaking of any of its memory
20 * addresses. However, I have been unable to decipher the logical
21 * positioning of the configuration info for various effects, so for
22 * now, you just get the YSS225 in the same state as Turtle Beach's
23 * "SETUPSND.EXE" utility leaves it.
24 *
25 * The boards' DAC/ADC (a Crystal CS4232) is supported by cs4232.[co],
26 * This chip also controls the configuration of the card: the wavefront
27 * synth is logical unit 4.
28 *
29 *
30 * Supported devices:
31 *
32 * /dev/dsp - using cs4232+ad1848 modules, OSS compatible
33 * /dev/midiNN and /dev/midiNN+1 - using wf_midi code, OSS compatible
34 * /dev/synth00 - raw synth interface
35 *
36 **********************************************************************
37 *
38 * Copyright (C) by Paul Barton-Davis 1998
39 *
40 * Some portions of this file are taken from work that is
41 * copyright (C) by Hannu Savolainen 1993-1996
42 *
43 * Although the relevant code here is all new, the handling of
44 * sample/alias/multi- samples is entirely based on a driver by Matt
45 * Martin and Rutger Nijlunsing which demonstrated how to get things
46 * to work correctly. The GUS patch loading code has been almost
47 * unaltered by me, except to fit formatting and function names in the
48 * rest of the file. Many thanks to them.
49 *
50 * Appreciation and thanks to Hannu Savolainen for his early work on the Maui
51 * driver, and answering a few questions while this one was developed.
52 *
53 * Absolutely NO thanks to Turtle Beach/Voyetra and Yamaha for their
54 * complete lack of help in developing this driver, and in particular
55 * for their utter silence in response to questions about undocumented
56 * aspects of configuring a WaveFront soundcard, particularly the
57 * effects processor.
58 *
59 * $Id: wavfront.c,v 0.7 1998/09/09 15:47:36 pbd Exp $
60 *
61 * This program is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
62 * Version 2 (June 1991). See the "COPYING" file distributed with this software
63 * for more info.
64 *
65 * Changes:
66 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
67 * Added some __init and __initdata to entries in yss225.c
68 */
69
70#include <linux/module.h>
71
72#include <linux/kernel.h>
73#include <linux/init.h>
74#include <linux/sched.h>
75#include <linux/smp_lock.h>
76#include <linux/ptrace.h>
77#include <linux/fcntl.h>
78#include <linux/syscalls.h>
79#include <linux/ioport.h>
80#include <linux/spinlock.h>
81#include <linux/interrupt.h>
82#include <linux/config.h>
83
84#include <linux/delay.h>
85
86#include "sound_config.h"
87
88#include <linux/wavefront.h>
89
90#define _MIDI_SYNTH_C_
91#define MIDI_SYNTH_NAME "WaveFront MIDI"
92#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
93#include "midi_synth.h"
94
95/* Compile-time control of the extent to which OSS is supported.
96
97 I consider /dev/sequencer to be an anachronism, but given its
98 widespread usage by various Linux MIDI software, it seems worth
99 offering support to it if it's not too painful. Instead of using
100 /dev/sequencer, I recommend:
101
102 for synth programming and patch loading: /dev/synthNN
103 for kernel-synchronized MIDI sequencing: the ALSA sequencer
104 for direct MIDI control: /dev/midiNN
105
106 I have never tried static compilation into the kernel. The #if's
107 for this are really just notes to myself about what the code is
108 for.
109*/
110
111#define OSS_SUPPORT_SEQ 0x1 /* use of /dev/sequencer */
112#define OSS_SUPPORT_STATIC_INSTALL 0x2 /* static compilation into kernel */
113
114#define OSS_SUPPORT_LEVEL 0x1 /* just /dev/sequencer for now */
115
116#if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
117static int (*midi_load_patch) (int devno, int format, const char __user *addr,
118 int offs, int count, int pmgr_flag) = NULL;
119#endif /* OSS_SUPPORT_SEQ */
120
121/* if WF_DEBUG not defined, no run-time debugging messages will
122 be available via the debug flag setting. Given the current
123 beta state of the driver, this will remain set until a future
124 version.
125*/
126
127#define WF_DEBUG 1
128
129#ifdef WF_DEBUG
130
131/* Thank goodness for gcc's preprocessor ... */
132
133#define DPRINT(cond, format, args...) \
134 if ((dev.debug & (cond)) == (cond)) { \
135 printk (KERN_DEBUG LOGNAME format, ## args); \
136 }
137#else
138#define DPRINT(cond, format, args...)
139#endif
140
141#define LOGNAME "WaveFront: "
142
143/* bitmasks for WaveFront status port value */
144
145#define STAT_RINTR_ENABLED 0x01
146#define STAT_CAN_READ 0x02
147#define STAT_INTR_READ 0x04
148#define STAT_WINTR_ENABLED 0x10
149#define STAT_CAN_WRITE 0x20
150#define STAT_INTR_WRITE 0x40
151
152/*** Module-accessible parameters ***************************************/
153
154int wf_raw; /* we normally check for "raw state" to firmware
155 loading. if set, then during driver loading, the
156 state of the board is ignored, and we reset the
157 board and load the firmware anyway.
158 */
159
160static int fx_raw = 1; /* if this is zero, we'll leave the FX processor in
161 whatever state it is when the driver is loaded.
162 The default is to download the microprogram and
163 associated coefficients to set it up for "default"
164 operation, whatever that means.
165 */
166
167static int debug_default; /* you can set this to control debugging
168 during driver loading. it takes any combination
169 of the WF_DEBUG_* flags defined in
170 wavefront.h
171 */
172
173/* XXX this needs to be made firmware and hardware version dependent */
174
175static char *ospath = "/etc/sound/wavefront.os"; /* where to find a processed
176 version of the WaveFront OS
177 */
178
179static int wait_polls = 2000; /* This is a number of tries we poll the
180 status register before resorting to sleeping.
181 WaveFront being an ISA card each poll takes
182 about 1.2us. So before going to
183 sleep we wait up to 2.4ms in a loop.
184 */
185
186static int sleep_length = HZ/100; /* This says how long we're going to
187 sleep between polls.
188 10ms sounds reasonable for fast response.
189 */
190
191static int sleep_tries = 50; /* Wait for status 0.5 seconds total. */
192
193static int reset_time = 2; /* hundreths of a second we wait after a HW reset for
194 the expected interrupt.
195 */
196
197static int ramcheck_time = 20; /* time in seconds to wait while ROM code
198 checks on-board RAM.
199 */
200
201static int osrun_time = 10; /* time in seconds we wait for the OS to
202 start running.
203 */
204
205module_param(wf_raw, int, 0);
206module_param(fx_raw, int, 0);
207module_param(debug_default, int, 0);
208module_param(wait_polls, int, 0);
209module_param(sleep_length, int, 0);
210module_param(sleep_tries, int, 0);
211module_param(ospath, charp, 0);
212module_param(reset_time, int, 0);
213module_param(ramcheck_time, int, 0);
214module_param(osrun_time, int, 0);
215
216/***************************************************************************/
217
218/* Note: because this module doesn't export any symbols, this really isn't
219 a global variable, even if it looks like one. I was quite confused by
220 this when I started writing this as a (newer) module -- pbd.
221*/
222
223struct wf_config {
224 int devno; /* device number from kernel */
225 int irq; /* "you were one, one of the few ..." */
226 int base; /* low i/o port address */
227
228#define mpu_data_port base
229#define mpu_command_port base + 1 /* write semantics */
230#define mpu_status_port base + 1 /* read semantics */
231#define data_port base + 2
232#define status_port base + 3 /* read semantics */
233#define control_port base + 3 /* write semantics */
234#define block_port base + 4 /* 16 bit, writeonly */
235#define last_block_port base + 6 /* 16 bit, writeonly */
236
237 /* FX ports. These are mapped through the ICS2115 to the YS225.
238 The ICS2115 takes care of flipping the relevant pins on the
239 YS225 so that access to each of these ports does the right
240 thing. Note: these are NOT documented by Turtle Beach.
241 */
242
243#define fx_status base + 8
244#define fx_op base + 8
245#define fx_lcr base + 9
246#define fx_dsp_addr base + 0xa
247#define fx_dsp_page base + 0xb
248#define fx_dsp_lsb base + 0xc
249#define fx_dsp_msb base + 0xd
250#define fx_mod_addr base + 0xe
251#define fx_mod_data base + 0xf
252
253 volatile int irq_ok; /* set by interrupt handler */
254 volatile int irq_cnt; /* ditto */
255 int opened; /* flag, holds open(2) mode */
256 char debug; /* debugging flags */
257 int freemem; /* installed RAM, in bytes */
258
259 int synth_dev; /* devno for "raw" synth */
260 int mididev; /* devno for internal MIDI */
261 int ext_mididev; /* devno for external MIDI */
262 int fx_mididev; /* devno for FX MIDI interface */
263#if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
264 int oss_dev; /* devno for OSS sequencer synth */
265#endif /* OSS_SUPPORT_SEQ */
266
267 char fw_version[2]; /* major = [0], minor = [1] */
268 char hw_version[2]; /* major = [0], minor = [1] */
269 char israw; /* needs Motorola microcode */
270 char has_fx; /* has FX processor (Tropez+) */
271 char prog_status[WF_MAX_PROGRAM]; /* WF_SLOT_* */
272 char patch_status[WF_MAX_PATCH]; /* WF_SLOT_* */
273 char sample_status[WF_MAX_SAMPLE]; /* WF_ST_* | WF_SLOT_* */
274 int samples_used; /* how many */
275 char interrupts_on; /* h/w MPU interrupts enabled ? */
276 char rom_samples_rdonly; /* can we write on ROM samples */
277 wait_queue_head_t interrupt_sleeper;
278} dev;
279
280static DEFINE_SPINLOCK(lock);
281static int detect_wffx(void);
282static int wffx_ioctl (wavefront_fx_info *);
283static int wffx_init (void);
284
285static int wavefront_delete_sample (int sampnum);
286static int wavefront_find_free_sample (void);
287
288/* From wf_midi.c */
289
290extern int virtual_midi_enable (void);
291extern int virtual_midi_disable (void);
292extern int detect_wf_mpu (int, int);
293extern int install_wf_mpu (void);
294extern int uninstall_wf_mpu (void);
295
296typedef struct {
297 int cmd;
298 char *action;
299 unsigned int read_cnt;
300 unsigned int write_cnt;
301 int need_ack;
302} wavefront_command;
303
304static struct {
305 int errno;
306 const char *errstr;
307} wavefront_errors[] = {
308 { 0x01, "Bad sample number" },
309 { 0x02, "Out of sample memory" },
310 { 0x03, "Bad patch number" },
311 { 0x04, "Error in number of voices" },
312 { 0x06, "Sample load already in progress" },
313 { 0x0B, "No sample load request pending" },
314 { 0x0E, "Bad MIDI channel number" },
315 { 0x10, "Download Record Error" },
316 { 0x80, "Success" },
317 { 0 }
318};
319
320#define NEEDS_ACK 1
321
322static wavefront_command wavefront_commands[] = {
323 { WFC_SET_SYNTHVOL, "set synthesizer volume", 0, 1, NEEDS_ACK },
324 { WFC_GET_SYNTHVOL, "get synthesizer volume", 1, 0, 0},
325 { WFC_SET_NVOICES, "set number of voices", 0, 1, NEEDS_ACK },
326 { WFC_GET_NVOICES, "get number of voices", 1, 0, 0 },
327 { WFC_SET_TUNING, "set synthesizer tuning", 0, 2, NEEDS_ACK },
328 { WFC_GET_TUNING, "get synthesizer tuning", 2, 0, 0 },
329 { WFC_DISABLE_CHANNEL, "disable synth channel", 0, 1, NEEDS_ACK },
330 { WFC_ENABLE_CHANNEL, "enable synth channel", 0, 1, NEEDS_ACK },
331 { WFC_GET_CHANNEL_STATUS, "get synth channel status", 3, 0, 0 },
332 { WFC_MISYNTH_OFF, "disable midi-in to synth", 0, 0, NEEDS_ACK },
333 { WFC_MISYNTH_ON, "enable midi-in to synth", 0, 0, NEEDS_ACK },
334 { WFC_VMIDI_ON, "enable virtual midi mode", 0, 0, NEEDS_ACK },
335 { WFC_VMIDI_OFF, "disable virtual midi mode", 0, 0, NEEDS_ACK },
336 { WFC_MIDI_STATUS, "report midi status", 1, 0, 0 },
337 { WFC_FIRMWARE_VERSION, "report firmware version", 2, 0, 0 },
338 { WFC_HARDWARE_VERSION, "report hardware version", 2, 0, 0 },
339 { WFC_GET_NSAMPLES, "report number of samples", 2, 0, 0 },
340 { WFC_INSTOUT_LEVELS, "report instantaneous output levels", 7, 0, 0 },
341 { WFC_PEAKOUT_LEVELS, "report peak output levels", 7, 0, 0 },
342 { WFC_DOWNLOAD_SAMPLE, "download sample",
343 0, WF_SAMPLE_BYTES, NEEDS_ACK },
344 { WFC_DOWNLOAD_BLOCK, "download block", 0, 0, NEEDS_ACK},
345 { WFC_DOWNLOAD_SAMPLE_HEADER, "download sample header",
346 0, WF_SAMPLE_HDR_BYTES, NEEDS_ACK },
347 { WFC_UPLOAD_SAMPLE_HEADER, "upload sample header", 13, 2, 0 },
348
349 /* This command requires a variable number of bytes to be written.
350 There is a hack in wavefront_cmd() to support this. The actual
351 count is passed in as the read buffer ptr, cast appropriately.
352 Ugh.
353 */
354
355 { WFC_DOWNLOAD_MULTISAMPLE, "download multisample", 0, 0, NEEDS_ACK },
356
357 /* This one is a hack as well. We just read the first byte of the
358 response, don't fetch an ACK, and leave the rest to the
359 calling function. Ugly, ugly, ugly.
360 */
361
362 { WFC_UPLOAD_MULTISAMPLE, "upload multisample", 2, 1, 0 },
363 { WFC_DOWNLOAD_SAMPLE_ALIAS, "download sample alias",
364 0, WF_ALIAS_BYTES, NEEDS_ACK },
365 { WFC_UPLOAD_SAMPLE_ALIAS, "upload sample alias", WF_ALIAS_BYTES, 2, 0},
366 { WFC_DELETE_SAMPLE, "delete sample", 0, 2, NEEDS_ACK },
367 { WFC_IDENTIFY_SAMPLE_TYPE, "identify sample type", 5, 2, 0 },
368 { WFC_UPLOAD_SAMPLE_PARAMS, "upload sample parameters" },
369 { WFC_REPORT_FREE_MEMORY, "report free memory", 4, 0, 0 },
370 { WFC_DOWNLOAD_PATCH, "download patch", 0, 134, NEEDS_ACK },
371 { WFC_UPLOAD_PATCH, "upload patch", 132, 2, 0 },
372 { WFC_DOWNLOAD_PROGRAM, "download program", 0, 33, NEEDS_ACK },
373 { WFC_UPLOAD_PROGRAM, "upload program", 32, 1, 0 },
374 { WFC_DOWNLOAD_EDRUM_PROGRAM, "download enhanced drum program", 0, 9,
375 NEEDS_ACK},
376 { WFC_UPLOAD_EDRUM_PROGRAM, "upload enhanced drum program", 8, 1, 0},
377 { WFC_SET_EDRUM_CHANNEL, "set enhanced drum program channel",
378 0, 1, NEEDS_ACK },
379 { WFC_DISABLE_DRUM_PROGRAM, "disable drum program", 0, 1, NEEDS_ACK },
380 { WFC_REPORT_CHANNEL_PROGRAMS, "report channel program numbers",
381 32, 0, 0 },
382 { WFC_NOOP, "the no-op command", 0, 0, NEEDS_ACK },
383 { 0x00 }
384};
385
386static const char *
387wavefront_errorstr (int errnum)
388
389{
390 int i;
391
392 for (i = 0; wavefront_errors[i].errstr; i++) {
393 if (wavefront_errors[i].errno == errnum) {
394 return wavefront_errors[i].errstr;
395 }
396 }
397
398 return "Unknown WaveFront error";
399}
400
401static wavefront_command *
402wavefront_get_command (int cmd)
403
404{
405 int i;
406
407 for (i = 0; wavefront_commands[i].cmd != 0; i++) {
408 if (cmd == wavefront_commands[i].cmd) {
409 return &wavefront_commands[i];
410 }
411 }
412
413 return (wavefront_command *) 0;
414}
415
416static inline int
417wavefront_status (void)
418
419{
420 return inb (dev.status_port);
421}
422
423static int
424wavefront_wait (int mask)
425
426{
427 int i;
428
429 for (i = 0; i < wait_polls; i++)
430 if (wavefront_status() & mask)
431 return 1;
432
433 for (i = 0; i < sleep_tries; i++) {
434
435 if (wavefront_status() & mask) {
436 set_current_state(TASK_RUNNING);
437 return 1;
438 }
439
440 set_current_state(TASK_INTERRUPTIBLE);
441 schedule_timeout(sleep_length);
442 if (signal_pending(current))
443 break;
444 }
445
446 set_current_state(TASK_RUNNING);
447 return 0;
448}
449
450static int
451wavefront_read (void)
452
453{
454 if (wavefront_wait (STAT_CAN_READ))
455 return inb (dev.data_port);
456
457 DPRINT (WF_DEBUG_DATA, "read timeout.\n");
458
459 return -1;
460}
461
462static int
463wavefront_write (unsigned char data)
464
465{
466 if (wavefront_wait (STAT_CAN_WRITE)) {
467 outb (data, dev.data_port);
468 return 0;
469 }
470
471 DPRINT (WF_DEBUG_DATA, "write timeout.\n");
472
473 return -1;
474}
475
476static int
477wavefront_cmd (int cmd, unsigned char *rbuf, unsigned char *wbuf)
478
479{
480 int ack;
481 int i;
482 int c;
483 wavefront_command *wfcmd;
484
485 if ((wfcmd = wavefront_get_command (cmd)) == (wavefront_command *) 0) {
486 printk (KERN_WARNING LOGNAME "command 0x%x not supported.\n",
487 cmd);
488 return 1;
489 }
490
491 /* Hack to handle the one variable-size write command. See
492 wavefront_send_multisample() for the other half of this
493 gross and ugly strategy.
494 */
495
496 if (cmd == WFC_DOWNLOAD_MULTISAMPLE) {
497 wfcmd->write_cnt = (unsigned int) rbuf;
498 rbuf = NULL;
499 }
500
501 DPRINT (WF_DEBUG_CMD, "0x%x [%s] (%d,%d,%d)\n",
502 cmd, wfcmd->action, wfcmd->read_cnt,
503 wfcmd->write_cnt, wfcmd->need_ack);
504
505 if (wavefront_write (cmd)) {
506 DPRINT ((WF_DEBUG_IO|WF_DEBUG_CMD), "cannot request "
507 "0x%x [%s].\n",
508 cmd, wfcmd->action);
509 return 1;
510 }
511
512 if (wfcmd->write_cnt > 0) {
513 DPRINT (WF_DEBUG_DATA, "writing %d bytes "
514 "for 0x%x\n",
515 wfcmd->write_cnt, cmd);
516
517 for (i = 0; i < wfcmd->write_cnt; i++) {
518 if (wavefront_write (wbuf[i])) {
519 DPRINT (WF_DEBUG_IO, "bad write for byte "
520 "%d of 0x%x [%s].\n",
521 i, cmd, wfcmd->action);
522 return 1;
523 }
524
525 DPRINT (WF_DEBUG_DATA, "write[%d] = 0x%x\n",
526 i, wbuf[i]);
527 }
528 }
529
530 if (wfcmd->read_cnt > 0) {
531 DPRINT (WF_DEBUG_DATA, "reading %d ints "
532 "for 0x%x\n",
533 wfcmd->read_cnt, cmd);
534
535 for (i = 0; i < wfcmd->read_cnt; i++) {
536
537 if ((c = wavefront_read()) == -1) {
538 DPRINT (WF_DEBUG_IO, "bad read for byte "
539 "%d of 0x%x [%s].\n",
540 i, cmd, wfcmd->action);
541 return 1;
542 }
543
544 /* Now handle errors. Lots of special cases here */
545
546 if (c == 0xff) {
547 if ((c = wavefront_read ()) == -1) {
548 DPRINT (WF_DEBUG_IO, "bad read for "
549 "error byte at "
550 "read byte %d "
551 "of 0x%x [%s].\n",
552 i, cmd,
553 wfcmd->action);
554 return 1;
555 }
556
557 /* Can you believe this madness ? */
558
559 if (c == 1 &&
560 wfcmd->cmd == WFC_IDENTIFY_SAMPLE_TYPE) {
561 rbuf[0] = WF_ST_EMPTY;
562 return (0);
563
564 } else if (c == 3 &&
565 wfcmd->cmd == WFC_UPLOAD_PATCH) {
566
567 return 3;
568
569 } else if (c == 1 &&
570 wfcmd->cmd == WFC_UPLOAD_PROGRAM) {
571
572 return 1;
573
574 } else {
575
576 DPRINT (WF_DEBUG_IO, "error %d (%s) "
577 "during "
578 "read for byte "
579 "%d of 0x%x "
580 "[%s].\n",
581 c,
582 wavefront_errorstr (c),
583 i, cmd,
584 wfcmd->action);
585 return 1;
586
587 }
588
589 } else {
590 rbuf[i] = c;
591 }
592
593 DPRINT (WF_DEBUG_DATA, "read[%d] = 0x%x\n",i, rbuf[i]);
594 }
595 }
596
597 if ((wfcmd->read_cnt == 0 && wfcmd->write_cnt == 0) || wfcmd->need_ack) {
598
599 DPRINT (WF_DEBUG_CMD, "reading ACK for 0x%x\n", cmd);
600
601 /* Some commands need an ACK, but return zero instead
602 of the standard value.
603 */
604
605 if ((ack = wavefront_read()) == 0) {
606 ack = WF_ACK;
607 }
608
609 if (ack != WF_ACK) {
610 if (ack == -1) {
611 DPRINT (WF_DEBUG_IO, "cannot read ack for "
612 "0x%x [%s].\n",
613 cmd, wfcmd->action);
614 return 1;
615
616 } else {
617 int err = -1; /* something unknown */
618
619 if (ack == 0xff) { /* explicit error */
620
621 if ((err = wavefront_read ()) == -1) {
622 DPRINT (WF_DEBUG_DATA,
623 "cannot read err "
624 "for 0x%x [%s].\n",
625 cmd, wfcmd->action);
626 }
627 }
628
629 DPRINT (WF_DEBUG_IO, "0x%x [%s] "
630 "failed (0x%x, 0x%x, %s)\n",
631 cmd, wfcmd->action, ack, err,
632 wavefront_errorstr (err));
633
634 return -err;
635 }
636 }
637
638 DPRINT (WF_DEBUG_DATA, "ack received "
639 "for 0x%x [%s]\n",
640 cmd, wfcmd->action);
641 } else {
642
643 DPRINT (WF_DEBUG_CMD, "0x%x [%s] does not need "
644 "ACK (%d,%d,%d)\n",
645 cmd, wfcmd->action, wfcmd->read_cnt,
646 wfcmd->write_cnt, wfcmd->need_ack);
647 }
648
649 return 0;
650
651}
652
653/***********************************************************************
654WaveFront: data munging
655
656Things here are weird. All data written to the board cannot
657have its most significant bit set. Any data item with values
658potentially > 0x7F (127) must be split across multiple bytes.
659
660Sometimes, we need to munge numeric values that are represented on
661the x86 side as 8-32 bit values. Sometimes, we need to munge data
662that is represented on the x86 side as an array of bytes. The most
663efficient approach to handling both cases seems to be to use 2
664different functions for munging and 2 for de-munging. This avoids
665weird casting and worrying about bit-level offsets.
666
667**********************************************************************/
668
669static
670unsigned char *
671munge_int32 (unsigned int src,
672 unsigned char *dst,
673 unsigned int dst_size)
674{
675 int i;
676
677 for (i = 0;i < dst_size; i++) {
678 *dst = src & 0x7F; /* Mask high bit of LSB */
679 src = src >> 7; /* Rotate Right 7 bits */
680 /* Note: we leave the upper bits in place */
681
682 dst++;
683 };
684 return dst;
685};
686
687static int
688demunge_int32 (unsigned char* src, int src_size)
689
690{
691 int i;
692 int outval = 0;
693
694 for (i = src_size - 1; i >= 0; i--) {
695 outval=(outval<<7)+src[i];
696 }
697
698 return outval;
699};
700
701static
702unsigned char *
703munge_buf (unsigned char *src, unsigned char *dst, unsigned int dst_size)
704
705{
706 int i;
707 unsigned int last = dst_size / 2;
708
709 for (i = 0; i < last; i++) {
710 *dst++ = src[i] & 0x7f;
711 *dst++ = src[i] >> 7;
712 }
713 return dst;
714}
715
716static
717unsigned char *
718demunge_buf (unsigned char *src, unsigned char *dst, unsigned int src_bytes)
719
720{
721 int i;
722 unsigned char *end = src + src_bytes;
723
724 end = src + src_bytes;
725
726 /* NOTE: src and dst *CAN* point to the same address */
727
728 for (i = 0; src != end; i++) {
729 dst[i] = *src++;
730 dst[i] |= (*src++)<<7;
731 }
732
733 return dst;
734}
735
736/***********************************************************************
737WaveFront: sample, patch and program management.
738***********************************************************************/
739
740static int
741wavefront_delete_sample (int sample_num)
742
743{
744 unsigned char wbuf[2];
745 int x;
746
747 wbuf[0] = sample_num & 0x7f;
748 wbuf[1] = sample_num >> 7;
749
750 if ((x = wavefront_cmd (WFC_DELETE_SAMPLE, NULL, wbuf)) == 0) {
751 dev.sample_status[sample_num] = WF_ST_EMPTY;
752 }
753
754 return x;
755}
756
757static int
758wavefront_get_sample_status (int assume_rom)
759
760{
761 int i;
762 unsigned char rbuf[32], wbuf[32];
763 unsigned int sc_real, sc_alias, sc_multi;
764
765 /* check sample status */
766
767 if (wavefront_cmd (WFC_GET_NSAMPLES, rbuf, wbuf)) {
768 printk (KERN_WARNING LOGNAME "cannot request sample count.\n");
769 return -1;
770 }
771
772 sc_real = sc_alias = sc_multi = dev.samples_used = 0;
773
774 for (i = 0; i < WF_MAX_SAMPLE; i++) {
775
776 wbuf[0] = i & 0x7f;
777 wbuf[1] = i >> 7;
778
779 if (wavefront_cmd (WFC_IDENTIFY_SAMPLE_TYPE, rbuf, wbuf)) {
780 printk (KERN_WARNING LOGNAME
781 "cannot identify sample "
782 "type of slot %d\n", i);
783 dev.sample_status[i] = WF_ST_EMPTY;
784 continue;
785 }
786
787 dev.sample_status[i] = (WF_SLOT_FILLED|rbuf[0]);
788
789 if (assume_rom) {
790 dev.sample_status[i] |= WF_SLOT_ROM;
791 }
792
793 switch (rbuf[0] & WF_ST_MASK) {
794 case WF_ST_SAMPLE:
795 sc_real++;
796 break;
797 case WF_ST_MULTISAMPLE:
798 sc_multi++;
799 break;
800 case WF_ST_ALIAS:
801 sc_alias++;
802 break;
803 case WF_ST_EMPTY:
804 break;
805
806 default:
807 printk (KERN_WARNING LOGNAME "unknown sample type for "
808 "slot %d (0x%x)\n",
809 i, rbuf[0]);
810 }
811
812 if (rbuf[0] != WF_ST_EMPTY) {
813 dev.samples_used++;
814 }
815 }
816
817 printk (KERN_INFO LOGNAME
818 "%d samples used (%d real, %d aliases, %d multi), "
819 "%d empty\n", dev.samples_used, sc_real, sc_alias, sc_multi,
820 WF_MAX_SAMPLE - dev.samples_used);
821
822
823 return (0);
824
825}
826
827static int
828wavefront_get_patch_status (void)
829
830{
831 unsigned char patchbuf[WF_PATCH_BYTES];
832 unsigned char patchnum[2];
833 wavefront_patch *p;
834 int i, x, cnt, cnt2;
835
836 for (i = 0; i < WF_MAX_PATCH; i++) {
837 patchnum[0] = i & 0x7f;
838 patchnum[1] = i >> 7;
839
840 if ((x = wavefront_cmd (WFC_UPLOAD_PATCH, patchbuf,
841 patchnum)) == 0) {
842
843 dev.patch_status[i] |= WF_SLOT_FILLED;
844 p = (wavefront_patch *) patchbuf;
845 dev.sample_status
846 [p->sample_number|(p->sample_msb<<7)] |=
847 WF_SLOT_USED;
848
849 } else if (x == 3) { /* Bad patch number */
850 dev.patch_status[i] = 0;
851 } else {
852 printk (KERN_ERR LOGNAME "upload patch "
853 "error 0x%x\n", x);
854 dev.patch_status[i] = 0;
855 return 1;
856 }
857 }
858
859 /* program status has already filled in slot_used bits */
860
861 for (i = 0, cnt = 0, cnt2 = 0; i < WF_MAX_PATCH; i++) {
862 if (dev.patch_status[i] & WF_SLOT_FILLED) {
863 cnt++;
864 }
865 if (dev.patch_status[i] & WF_SLOT_USED) {
866 cnt2++;
867 }
868
869 }
870 printk (KERN_INFO LOGNAME
871 "%d patch slots filled, %d in use\n", cnt, cnt2);
872
873 return (0);
874}
875
876static int
877wavefront_get_program_status (void)
878
879{
880 unsigned char progbuf[WF_PROGRAM_BYTES];
881 wavefront_program prog;
882 unsigned char prognum;
883 int i, x, l, cnt;
884
885 for (i = 0; i < WF_MAX_PROGRAM; i++) {
886 prognum = i;
887
888 if ((x = wavefront_cmd (WFC_UPLOAD_PROGRAM, progbuf,
889 &prognum)) == 0) {
890
891 dev.prog_status[i] |= WF_SLOT_USED;
892
893 demunge_buf (progbuf, (unsigned char *) &prog,
894 WF_PROGRAM_BYTES);
895
896 for (l = 0; l < WF_NUM_LAYERS; l++) {
897 if (prog.layer[l].mute) {
898 dev.patch_status
899 [prog.layer[l].patch_number] |=
900 WF_SLOT_USED;
901 }
902 }
903 } else if (x == 1) { /* Bad program number */
904 dev.prog_status[i] = 0;
905 } else {
906 printk (KERN_ERR LOGNAME "upload program "
907 "error 0x%x\n", x);
908 dev.prog_status[i] = 0;
909 }
910 }
911
912 for (i = 0, cnt = 0; i < WF_MAX_PROGRAM; i++) {
913 if (dev.prog_status[i]) {
914 cnt++;
915 }
916 }
917
918 printk (KERN_INFO LOGNAME "%d programs slots in use\n", cnt);
919
920 return (0);
921}
922
923static int
924wavefront_send_patch (wavefront_patch_info *header)
925
926{
927 unsigned char buf[WF_PATCH_BYTES+2];
928 unsigned char *bptr;
929
930 DPRINT (WF_DEBUG_LOAD_PATCH, "downloading patch %d\n",
931 header->number);
932
933 dev.patch_status[header->number] |= WF_SLOT_FILLED;
934
935 bptr = buf;
936 bptr = munge_int32 (header->number, buf, 2);
937 munge_buf ((unsigned char *)&header->hdr.p, bptr, WF_PATCH_BYTES);
938
939 if (wavefront_cmd (WFC_DOWNLOAD_PATCH, NULL, buf)) {
940 printk (KERN_ERR LOGNAME "download patch failed\n");
941 return -(EIO);
942 }
943
944 return (0);
945}
946
947static int
948wavefront_send_program (wavefront_patch_info *header)
949
950{
951 unsigned char buf[WF_PROGRAM_BYTES+1];
952 int i;
953
954 DPRINT (WF_DEBUG_LOAD_PATCH, "downloading program %d\n",
955 header->number);
956
957 dev.prog_status[header->number] = WF_SLOT_USED;
958
959 /* XXX need to zero existing SLOT_USED bit for program_status[i]
960 where `i' is the program that's being (potentially) overwritten.
961 */
962
963 for (i = 0; i < WF_NUM_LAYERS; i++) {
964 if (header->hdr.pr.layer[i].mute) {
965 dev.patch_status[header->hdr.pr.layer[i].patch_number] |=
966 WF_SLOT_USED;
967
968 /* XXX need to mark SLOT_USED for sample used by
969 patch_number, but this means we have to load it. Ick.
970 */
971 }
972 }
973
974 buf[0] = header->number;
975 munge_buf ((unsigned char *)&header->hdr.pr, &buf[1], WF_PROGRAM_BYTES);
976
977 if (wavefront_cmd (WFC_DOWNLOAD_PROGRAM, NULL, buf)) {
978 printk (KERN_WARNING LOGNAME "download patch failed\n");
979 return -(EIO);
980 }
981
982 return (0);
983}
984
985static int
986wavefront_freemem (void)
987
988{
989 char rbuf[8];
990
991 if (wavefront_cmd (WFC_REPORT_FREE_MEMORY, rbuf, NULL)) {
992 printk (KERN_WARNING LOGNAME "can't get memory stats.\n");
993 return -1;
994 } else {
995 return demunge_int32 (rbuf, 4);
996 }
997}
998
999static int
1000wavefront_send_sample (wavefront_patch_info *header,
1001 UINT16 __user *dataptr,
1002 int data_is_unsigned)
1003
1004{
1005 /* samples are downloaded via a 16-bit wide i/o port
1006 (you could think of it as 2 adjacent 8-bit wide ports
1007 but its less efficient that way). therefore, all
1008 the blocksizes and so forth listed in the documentation,
1009 and used conventionally to refer to sample sizes,
1010 which are given in 8-bit units (bytes), need to be
1011 divided by 2.
1012 */
1013
1014 UINT16 sample_short;
1015 UINT32 length;
1016 UINT16 __user *data_end = NULL;
1017 unsigned int i;
1018 const int max_blksize = 4096/2;
1019 unsigned int written;
1020 unsigned int blocksize;
1021 int dma_ack;
1022 int blocknum;
1023 unsigned char sample_hdr[WF_SAMPLE_HDR_BYTES];
1024 unsigned char *shptr;
1025 int skip = 0;
1026 int initial_skip = 0;
1027
1028 DPRINT (WF_DEBUG_LOAD_PATCH, "sample %sdownload for slot %d, "
1029 "type %d, %d bytes from %p\n",
1030 header->size ? "" : "header ",
1031 header->number, header->subkey,
1032 header->size,
1033 header->dataptr);
1034
1035 if (header->number == WAVEFRONT_FIND_FREE_SAMPLE_SLOT) {
1036 int x;
1037
1038 if ((x = wavefront_find_free_sample ()) < 0) {
1039 return -ENOMEM;
1040 }
1041 printk (KERN_DEBUG LOGNAME "unspecified sample => %d\n", x);
1042 header->number = x;
1043 }
1044
1045 if (header->size) {
1046
1047 /* XXX it's a debatable point whether or not RDONLY semantics
1048 on the ROM samples should cover just the sample data or
1049 the sample header. For now, it only covers the sample data,
1050 so anyone is free at all times to rewrite sample headers.
1051
1052 My reason for this is that we have the sample headers
1053 available in the WFB file for General MIDI, and so these
1054 can always be reset if needed. The sample data, however,
1055 cannot be recovered without a complete reset and firmware
1056 reload of the ICS2115, which is a very expensive operation.
1057
1058 So, doing things this way allows us to honor the notion of
1059 "RESETSAMPLES" reasonably cheaply. Note however, that this
1060 is done purely at user level: there is no WFB parser in
1061 this driver, and so a complete reset (back to General MIDI,
1062 or theoretically some other configuration) is the
1063 responsibility of the user level library.
1064
1065 To try to do this in the kernel would be a little
1066 crazy: we'd need 158K of kernel space just to hold
1067 a copy of the patch/program/sample header data.
1068 */
1069
1070 if (dev.rom_samples_rdonly) {
1071 if (dev.sample_status[header->number] & WF_SLOT_ROM) {
1072 printk (KERN_ERR LOGNAME "sample slot %d "
1073 "write protected\n",
1074 header->number);
1075 return -EACCES;
1076 }
1077 }
1078
1079 wavefront_delete_sample (header->number);
1080 }
1081
1082 if (header->size) {
1083 dev.freemem = wavefront_freemem ();
1084
1085 if (dev.freemem < header->size) {
1086 printk (KERN_ERR LOGNAME
1087 "insufficient memory to "
1088 "load %d byte sample.\n",
1089 header->size);
1090 return -ENOMEM;
1091 }
1092
1093 }
1094
1095 skip = WF_GET_CHANNEL(&header->hdr.s);
1096
1097 if (skip > 0 && header->hdr.s.SampleResolution != LINEAR_16BIT) {
1098 printk (KERN_ERR LOGNAME "channel selection only "
1099 "possible on 16-bit samples");
1100 return -(EINVAL);
1101 }
1102
1103 switch (skip) {
1104 case 0:
1105 initial_skip = 0;
1106 skip = 1;
1107 break;
1108 case 1:
1109 initial_skip = 0;
1110 skip = 2;
1111 break;
1112 case 2:
1113 initial_skip = 1;
1114 skip = 2;
1115 break;
1116 case 3:
1117 initial_skip = 2;
1118 skip = 3;
1119 break;
1120 case 4:
1121 initial_skip = 3;
1122 skip = 4;
1123 break;
1124 case 5:
1125 initial_skip = 4;
1126 skip = 5;
1127 break;
1128 case 6:
1129 initial_skip = 5;
1130 skip = 6;
1131 break;
1132 }
1133
1134 DPRINT (WF_DEBUG_LOAD_PATCH, "channel selection: %d => "
1135 "initial skip = %d, skip = %d\n",
1136 WF_GET_CHANNEL (&header->hdr.s),
1137 initial_skip, skip);
1138
1139 /* Be safe, and zero the "Unused" bits ... */
1140
1141 WF_SET_CHANNEL(&header->hdr.s, 0);
1142
1143 /* adjust size for 16 bit samples by dividing by two. We always
1144 send 16 bits per write, even for 8 bit samples, so the length
1145 is always half the size of the sample data in bytes.
1146 */
1147
1148 length = header->size / 2;
1149
1150 /* the data we're sent has not been munged, and in fact, the
1151 header we have to send isn't just a munged copy either.
1152 so, build the sample header right here.
1153 */
1154
1155 shptr = &sample_hdr[0];
1156
1157 shptr = munge_int32 (header->number, shptr, 2);
1158
1159 if (header->size) {
1160 shptr = munge_int32 (length, shptr, 4);
1161 }
1162
1163 /* Yes, a 4 byte result doesn't contain all of the offset bits,
1164 but the offset only uses 24 bits.
1165 */
1166
1167 shptr = munge_int32 (*((UINT32 *) &header->hdr.s.sampleStartOffset),
1168 shptr, 4);
1169 shptr = munge_int32 (*((UINT32 *) &header->hdr.s.loopStartOffset),
1170 shptr, 4);
1171 shptr = munge_int32 (*((UINT32 *) &header->hdr.s.loopEndOffset),
1172 shptr, 4);
1173 shptr = munge_int32 (*((UINT32 *) &header->hdr.s.sampleEndOffset),
1174 shptr, 4);
1175
1176 /* This one is truly weird. What kind of weirdo decided that in
1177 a system dominated by 16 and 32 bit integers, they would use
1178 a just 12 bits ?
1179 */
1180
1181 shptr = munge_int32 (header->hdr.s.FrequencyBias, shptr, 3);
1182
1183 /* Why is this nybblified, when the MSB is *always* zero ?
1184 Anyway, we can't take address of bitfield, so make a
1185 good-faith guess at where it starts.
1186 */
1187
1188 shptr = munge_int32 (*(&header->hdr.s.FrequencyBias+1),
1189 shptr, 2);
1190
1191 if (wavefront_cmd (header->size ?
1192 WFC_DOWNLOAD_SAMPLE : WFC_DOWNLOAD_SAMPLE_HEADER,
1193 NULL, sample_hdr)) {
1194 printk (KERN_WARNING LOGNAME "sample %sdownload refused.\n",
1195 header->size ? "" : "header ");
1196 return -(EIO);
1197 }
1198
1199 if (header->size == 0) {
1200 goto sent; /* Sorry. Just had to have one somewhere */
1201 }
1202
1203 data_end = dataptr + length;
1204
1205 /* Do any initial skip over an unused channel's data */
1206
1207 dataptr += initial_skip;
1208
1209 for (written = 0, blocknum = 0;
1210 written < length; written += max_blksize, blocknum++) {
1211
1212 if ((length - written) > max_blksize) {
1213 blocksize = max_blksize;
1214 } else {
1215 /* round to nearest 16-byte value */
1216 blocksize = ((length-written+7)&~0x7);
1217 }
1218
1219 if (wavefront_cmd (WFC_DOWNLOAD_BLOCK, NULL, NULL)) {
1220 printk (KERN_WARNING LOGNAME "download block "
1221 "request refused.\n");
1222 return -(EIO);
1223 }
1224
1225 for (i = 0; i < blocksize; i++) {
1226
1227 if (dataptr < data_end) {
1228
1229 __get_user (sample_short, dataptr);
1230 dataptr += skip;
1231
1232 if (data_is_unsigned) { /* GUS ? */
1233
1234 if (WF_SAMPLE_IS_8BIT(&header->hdr.s)) {
1235
1236 /* 8 bit sample
1237 resolution, sign
1238 extend both bytes.
1239 */
1240
1241 ((unsigned char*)
1242 &sample_short)[0] += 0x7f;
1243 ((unsigned char*)
1244 &sample_short)[1] += 0x7f;
1245
1246 } else {
1247
1248 /* 16 bit sample
1249 resolution, sign
1250 extend the MSB.
1251 */
1252
1253 sample_short += 0x7fff;
1254 }
1255 }
1256
1257 } else {
1258
1259 /* In padding section of final block:
1260
1261 Don't fetch unsupplied data from
1262 user space, just continue with
1263 whatever the final value was.
1264 */
1265 }
1266
1267 if (i < blocksize - 1) {
1268 outw (sample_short, dev.block_port);
1269 } else {
1270 outw (sample_short, dev.last_block_port);
1271 }
1272 }
1273
1274 /* Get "DMA page acknowledge", even though its really
1275 nothing to do with DMA at all.
1276 */
1277
1278 if ((dma_ack = wavefront_read ()) != WF_DMA_ACK) {
1279 if (dma_ack == -1) {
1280 printk (KERN_ERR LOGNAME "upload sample "
1281 "DMA ack timeout\n");
1282 return -(EIO);
1283 } else {
1284 printk (KERN_ERR LOGNAME "upload sample "
1285 "DMA ack error 0x%x\n",
1286 dma_ack);
1287 return -(EIO);
1288 }
1289 }
1290 }
1291
1292 dev.sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_SAMPLE);
1293
1294 /* Note, label is here because sending the sample header shouldn't
1295 alter the sample_status info at all.
1296 */
1297
1298 sent:
1299 return (0);
1300}
1301
1302static int
1303wavefront_send_alias (wavefront_patch_info *header)
1304
1305{
1306 unsigned char alias_hdr[WF_ALIAS_BYTES];
1307
1308 DPRINT (WF_DEBUG_LOAD_PATCH, "download alias, %d is "
1309 "alias for %d\n",
1310 header->number,
1311 header->hdr.a.OriginalSample);
1312
1313 munge_int32 (header->number, &alias_hdr[0], 2);
1314 munge_int32 (header->hdr.a.OriginalSample, &alias_hdr[2], 2);
1315 munge_int32 (*((unsigned int *)&header->hdr.a.sampleStartOffset),
1316 &alias_hdr[4], 4);
1317 munge_int32 (*((unsigned int *)&header->hdr.a.loopStartOffset),
1318 &alias_hdr[8], 4);
1319 munge_int32 (*((unsigned int *)&header->hdr.a.loopEndOffset),
1320 &alias_hdr[12], 4);
1321 munge_int32 (*((unsigned int *)&header->hdr.a.sampleEndOffset),
1322 &alias_hdr[16], 4);
1323 munge_int32 (header->hdr.a.FrequencyBias, &alias_hdr[20], 3);
1324 munge_int32 (*(&header->hdr.a.FrequencyBias+1), &alias_hdr[23], 2);
1325
1326 if (wavefront_cmd (WFC_DOWNLOAD_SAMPLE_ALIAS, NULL, alias_hdr)) {
1327 printk (KERN_ERR LOGNAME "download alias failed.\n");
1328 return -(EIO);
1329 }
1330
1331 dev.sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_ALIAS);
1332
1333 return (0);
1334}
1335
1336static int
1337wavefront_send_multisample (wavefront_patch_info *header)
1338{
1339 int i;
1340 int num_samples;
1341 unsigned char msample_hdr[WF_MSAMPLE_BYTES];
1342
1343 munge_int32 (header->number, &msample_hdr[0], 2);
1344
1345 /* You'll recall at this point that the "number of samples" value
1346 in a wavefront_multisample struct is actually the log2 of the
1347 real number of samples.
1348 */
1349
1350 num_samples = (1<<(header->hdr.ms.NumberOfSamples&7));
1351 msample_hdr[2] = (unsigned char) header->hdr.ms.NumberOfSamples;
1352
1353 DPRINT (WF_DEBUG_LOAD_PATCH, "multi %d with %d=%d samples\n",
1354 header->number,
1355 header->hdr.ms.NumberOfSamples,
1356 num_samples);
1357
1358 for (i = 0; i < num_samples; i++) {
1359 DPRINT(WF_DEBUG_LOAD_PATCH|WF_DEBUG_DATA, "sample[%d] = %d\n",
1360 i, header->hdr.ms.SampleNumber[i]);
1361 munge_int32 (header->hdr.ms.SampleNumber[i],
1362 &msample_hdr[3+(i*2)], 2);
1363 }
1364
1365 /* Need a hack here to pass in the number of bytes
1366 to be written to the synth. This is ugly, and perhaps
1367 one day, I'll fix it.
1368 */
1369
1370 if (wavefront_cmd (WFC_DOWNLOAD_MULTISAMPLE,
1371 (unsigned char *) ((num_samples*2)+3),
1372 msample_hdr)) {
1373 printk (KERN_ERR LOGNAME "download of multisample failed.\n");
1374 return -(EIO);
1375 }
1376
1377 dev.sample_status[header->number] = (WF_SLOT_FILLED|WF_ST_MULTISAMPLE);
1378
1379 return (0);
1380}
1381
1382static int
1383wavefront_fetch_multisample (wavefront_patch_info *header)
1384{
1385 int i;
1386 unsigned char log_ns[1];
1387 unsigned char number[2];
1388 int num_samples;
1389
1390 munge_int32 (header->number, number, 2);
1391
1392 if (wavefront_cmd (WFC_UPLOAD_MULTISAMPLE, log_ns, number)) {
1393 printk (KERN_ERR LOGNAME "upload multisample failed.\n");
1394 return -(EIO);
1395 }
1396
1397 DPRINT (WF_DEBUG_DATA, "msample %d has %d samples\n",
1398 header->number, log_ns[0]);
1399
1400 header->hdr.ms.NumberOfSamples = log_ns[0];
1401
1402 /* get the number of samples ... */
1403
1404 num_samples = (1 << log_ns[0]);
1405
1406 for (i = 0; i < num_samples; i++) {
1407 s8 d[2];
1408
1409 if ((d[0] = wavefront_read ()) == -1) {
1410 printk (KERN_ERR LOGNAME "upload multisample failed "
1411 "during sample loop.\n");
1412 return -(EIO);
1413 }
1414
1415 if ((d[1] = wavefront_read ()) == -1) {
1416 printk (KERN_ERR LOGNAME "upload multisample failed "
1417 "during sample loop.\n");
1418 return -(EIO);
1419 }
1420
1421 header->hdr.ms.SampleNumber[i] =
1422 demunge_int32 ((unsigned char *) d, 2);
1423
1424 DPRINT (WF_DEBUG_DATA, "msample sample[%d] = %d\n",
1425 i, header->hdr.ms.SampleNumber[i]);
1426 }
1427
1428 return (0);
1429}
1430
1431
1432static int
1433wavefront_send_drum (wavefront_patch_info *header)
1434
1435{
1436 unsigned char drumbuf[WF_DRUM_BYTES];
1437 wavefront_drum *drum = &header->hdr.d;
1438 int i;
1439
1440 DPRINT (WF_DEBUG_LOAD_PATCH, "downloading edrum for MIDI "
1441 "note %d, patch = %d\n",
1442 header->number, drum->PatchNumber);
1443
1444 drumbuf[0] = header->number & 0x7f;
1445
1446 for (i = 0; i < 4; i++) {
1447 munge_int32 (((unsigned char *)drum)[i], &drumbuf[1+(i*2)], 2);
1448 }
1449
1450 if (wavefront_cmd (WFC_DOWNLOAD_EDRUM_PROGRAM, NULL, drumbuf)) {
1451 printk (KERN_ERR LOGNAME "download drum failed.\n");
1452 return -(EIO);
1453 }
1454
1455 return (0);
1456}
1457
1458static int
1459wavefront_find_free_sample (void)
1460
1461{
1462 int i;
1463
1464 for (i = 0; i < WF_MAX_SAMPLE; i++) {
1465 if (!(dev.sample_status[i] & WF_SLOT_FILLED)) {
1466 return i;
1467 }
1468 }
1469 printk (KERN_WARNING LOGNAME "no free sample slots!\n");
1470 return -1;
1471}
1472
1473static int
1474wavefront_find_free_patch (void)
1475
1476{
1477 int i;
1478
1479 for (i = 0; i < WF_MAX_PATCH; i++) {
1480 if (!(dev.patch_status[i] & WF_SLOT_FILLED)) {
1481 return i;
1482 }
1483 }
1484 printk (KERN_WARNING LOGNAME "no free patch slots!\n");
1485 return -1;
1486}
1487
1488static int
1489log2_2048(int n)
1490
1491{
1492 int tbl[]={0, 0, 2048, 3246, 4096, 4755, 5294, 5749, 6143,
1493 6492, 6803, 7084, 7342, 7578, 7797, 8001, 8192,
1494 8371, 8540, 8699, 8851, 8995, 9132, 9264, 9390,
1495 9510, 9626, 9738, 9845, 9949, 10049, 10146};
1496 int i;
1497
1498 /* Returns 2048*log2(n) */
1499
1500 /* FIXME: this is like doing integer math
1501 on quantum particles (RuN) */
1502
1503 i=0;
1504 while(n>=32*256) {
1505 n>>=8;
1506 i+=2048*8;
1507 }
1508 while(n>=32) {
1509 n>>=1;
1510 i+=2048;
1511 }
1512 i+=tbl[n];
1513 return(i);
1514}
1515
1516static int
1517wavefront_load_gus_patch (int devno, int format, const char __user *addr,
1518 int offs, int count, int pmgr_flag)
1519{
1520 struct patch_info guspatch;
1521 wavefront_patch_info *samp, *pat, *prog;
1522 wavefront_patch *patp;
1523 wavefront_sample *sampp;
1524 wavefront_program *progp;
1525
1526 int i,base_note;
1527 long sizeof_patch;
1528 int rc = -ENOMEM;
1529
1530 samp = kmalloc(3 * sizeof(wavefront_patch_info), GFP_KERNEL);
1531 if (!samp)
1532 goto free_fail;
1533 pat = samp + 1;
1534 prog = pat + 1;
1535
1536 /* Copy in the header of the GUS patch */
1537
1538 sizeof_patch = (long) &guspatch.data[0] - (long) &guspatch;
1539 if (copy_from_user(&((char *) &guspatch)[offs],
1540 &(addr)[offs], sizeof_patch - offs)) {
1541 rc = -EFAULT;
1542 goto free_fail;
1543 }
1544
1545 if ((i = wavefront_find_free_patch ()) == -1) {
1546 rc = -EBUSY;
1547 goto free_fail;
1548 }
1549 pat->number = i;
1550 pat->subkey = WF_ST_PATCH;
1551 patp = &pat->hdr.p;
1552
1553 if ((i = wavefront_find_free_sample ()) == -1) {
1554 rc = -EBUSY;
1555 goto free_fail;
1556 }
1557 samp->number = i;
1558 samp->subkey = WF_ST_SAMPLE;
1559 samp->size = guspatch.len;
1560 sampp = &samp->hdr.s;
1561
1562 prog->number = guspatch.instr_no;
1563 progp = &prog->hdr.pr;
1564
1565 /* Setup the patch structure */
1566
1567 patp->amplitude_bias=guspatch.volume;
1568 patp->portamento=0;
1569 patp->sample_number= samp->number & 0xff;
1570 patp->sample_msb= samp->number >> 8;
1571 patp->pitch_bend= /*12*/ 0;
1572 patp->mono=1;
1573 patp->retrigger=1;
1574 patp->nohold=(guspatch.mode & WAVE_SUSTAIN_ON) ? 0:1;
1575 patp->frequency_bias=0;
1576 patp->restart=0;
1577 patp->reuse=0;
1578 patp->reset_lfo=1;
1579 patp->fm_src2=0;
1580 patp->fm_src1=WF_MOD_MOD_WHEEL;
1581 patp->am_src=WF_MOD_PRESSURE;
1582 patp->am_amount=127;
1583 patp->fc1_mod_amount=0;
1584 patp->fc2_mod_amount=0;
1585 patp->fm_amount1=0;
1586 patp->fm_amount2=0;
1587 patp->envelope1.attack_level=127;
1588 patp->envelope1.decay1_level=127;
1589 patp->envelope1.decay2_level=127;
1590 patp->envelope1.sustain_level=127;
1591 patp->envelope1.release_level=0;
1592 patp->envelope2.attack_velocity=127;
1593 patp->envelope2.attack_level=127;
1594 patp->envelope2.decay1_level=127;
1595 patp->envelope2.decay2_level=127;
1596 patp->envelope2.sustain_level=127;
1597 patp->envelope2.release_level=0;
1598 patp->envelope2.attack_velocity=127;
1599 patp->randomizer=0;
1600
1601 /* Program for this patch */
1602
1603 progp->layer[0].patch_number= pat->number; /* XXX is this right ? */
1604 progp->layer[0].mute=1;
1605 progp->layer[0].pan_or_mod=1;
1606 progp->layer[0].pan=7;
1607 progp->layer[0].mix_level=127 /* guspatch.volume */;
1608 progp->layer[0].split_type=0;
1609 progp->layer[0].split_point=0;
1610 progp->layer[0].play_below=0;
1611
1612 for (i = 1; i < 4; i++) {
1613 progp->layer[i].mute=0;
1614 }
1615
1616 /* Sample data */
1617
1618 sampp->SampleResolution=((~guspatch.mode & WAVE_16_BITS)<<1);
1619
1620 for (base_note=0;
1621 note_to_freq (base_note) < guspatch.base_note;
1622 base_note++);
1623
1624 if ((guspatch.base_note-note_to_freq(base_note))
1625 >(note_to_freq(base_note)-guspatch.base_note))
1626 base_note++;
1627
1628 printk(KERN_DEBUG "ref freq=%d,base note=%d\n",
1629 guspatch.base_freq,
1630 base_note);
1631
1632 sampp->FrequencyBias = (29550 - log2_2048(guspatch.base_freq)
1633 + base_note*171);
1634 printk(KERN_DEBUG "Freq Bias is %d\n", sampp->FrequencyBias);
1635 sampp->Loop=(guspatch.mode & WAVE_LOOPING) ? 1:0;
1636 sampp->sampleStartOffset.Fraction=0;
1637 sampp->sampleStartOffset.Integer=0;
1638 sampp->loopStartOffset.Fraction=0;
1639 sampp->loopStartOffset.Integer=guspatch.loop_start
1640 >>((guspatch.mode&WAVE_16_BITS) ? 1:0);
1641 sampp->loopEndOffset.Fraction=0;
1642 sampp->loopEndOffset.Integer=guspatch.loop_end
1643 >>((guspatch.mode&WAVE_16_BITS) ? 1:0);
1644 sampp->sampleEndOffset.Fraction=0;
1645 sampp->sampleEndOffset.Integer=guspatch.len >> (guspatch.mode&1);
1646 sampp->Bidirectional=(guspatch.mode&WAVE_BIDIR_LOOP) ? 1:0;
1647 sampp->Reverse=(guspatch.mode&WAVE_LOOP_BACK) ? 1:0;
1648
1649 /* Now ship it down */
1650
1651 wavefront_send_sample (samp,
1652 (unsigned short __user *) &(addr)[sizeof_patch],
1653 (guspatch.mode & WAVE_UNSIGNED) ? 1:0);
1654 wavefront_send_patch (pat);
1655 wavefront_send_program (prog);
1656
1657 /* Now pan as best we can ... use the slave/internal MIDI device
1658 number if it exists (since it talks to the WaveFront), or the
1659 master otherwise.
1660 */
1661
1662 if (dev.mididev > 0) {
1663 midi_synth_controller (dev.mididev, guspatch.instr_no, 10,
1664 ((guspatch.panning << 4) > 127) ?
1665 127 : (guspatch.panning << 4));
1666 }
1667 rc = 0;
1668
1669free_fail:
1670 kfree(samp);
1671 return rc;
1672}
1673
1674static int
1675wavefront_load_patch (const char __user *addr)
1676
1677
1678{
1679 wavefront_patch_info header;
1680
1681 if (copy_from_user (&header, addr, sizeof(wavefront_patch_info) -
1682 sizeof(wavefront_any))) {
1683 printk (KERN_WARNING LOGNAME "bad address for load patch.\n");
1684 return -EFAULT;
1685 }
1686
1687 DPRINT (WF_DEBUG_LOAD_PATCH, "download "
1688 "Sample type: %d "
1689 "Sample number: %d "
1690 "Sample size: %d\n",
1691 header.subkey,
1692 header.number,
1693 header.size);
1694
1695 switch (header.subkey) {
1696 case WF_ST_SAMPLE: /* sample or sample_header, based on patch->size */
1697
1698 if (copy_from_user((unsigned char *) &header.hdr.s,
1699 (unsigned char __user *) header.hdrptr,
1700 sizeof (wavefront_sample)))
1701 return -EFAULT;
1702
1703 return wavefront_send_sample (&header, header.dataptr, 0);
1704
1705 case WF_ST_MULTISAMPLE:
1706
1707 if (copy_from_user(&header.hdr.s, header.hdrptr,
1708 sizeof(wavefront_multisample)))
1709 return -EFAULT;
1710
1711 return wavefront_send_multisample (&header);
1712
1713
1714 case WF_ST_ALIAS:
1715
1716 if (copy_from_user(&header.hdr.a, header.hdrptr,
1717 sizeof (wavefront_alias)))
1718 return -EFAULT;
1719
1720 return wavefront_send_alias (&header);
1721
1722 case WF_ST_DRUM:
1723 if (copy_from_user(&header.hdr.d, header.hdrptr,
1724 sizeof (wavefront_drum)))
1725 return -EFAULT;
1726
1727 return wavefront_send_drum (&header);
1728
1729 case WF_ST_PATCH:
1730 if (copy_from_user(&header.hdr.p, header.hdrptr,
1731 sizeof (wavefront_patch)))
1732 return -EFAULT;
1733
1734 return wavefront_send_patch (&header);
1735
1736 case WF_ST_PROGRAM:
1737 if (copy_from_user(&header.hdr.pr, header.hdrptr,
1738 sizeof (wavefront_program)))
1739 return -EFAULT;
1740
1741 return wavefront_send_program (&header);
1742
1743 default:
1744 printk (KERN_ERR LOGNAME "unknown patch type %d.\n",
1745 header.subkey);
1746 return -(EINVAL);
1747 }
1748
1749 return 0;
1750}
1751
1752/***********************************************************************
1753WaveFront: /dev/sequencer{,2} and other hardware-dependent interfaces
1754***********************************************************************/
1755
1756static void
1757process_sample_hdr (UCHAR8 *buf)
1758
1759{
1760 wavefront_sample s;
1761 UCHAR8 *ptr;
1762
1763 ptr = buf;
1764
1765 /* The board doesn't send us an exact copy of a "wavefront_sample"
1766 in response to an Upload Sample Header command. Instead, we
1767 have to convert the data format back into our data structure,
1768 just as in the Download Sample command, where we have to do
1769 something very similar in the reverse direction.
1770 */
1771
1772 *((UINT32 *) &s.sampleStartOffset) = demunge_int32 (ptr, 4); ptr += 4;
1773 *((UINT32 *) &s.loopStartOffset) = demunge_int32 (ptr, 4); ptr += 4;
1774 *((UINT32 *) &s.loopEndOffset) = demunge_int32 (ptr, 4); ptr += 4;
1775 *((UINT32 *) &s.sampleEndOffset) = demunge_int32 (ptr, 4); ptr += 4;
1776 *((UINT32 *) &s.FrequencyBias) = demunge_int32 (ptr, 3); ptr += 3;
1777
1778 s.SampleResolution = *ptr & 0x3;
1779 s.Loop = *ptr & 0x8;
1780 s.Bidirectional = *ptr & 0x10;
1781 s.Reverse = *ptr & 0x40;
1782
1783 /* Now copy it back to where it came from */
1784
1785 memcpy (buf, (unsigned char *) &s, sizeof (wavefront_sample));
1786}
1787
1788static int
1789wavefront_synth_control (int cmd, wavefront_control *wc)
1790
1791{
1792 unsigned char patchnumbuf[2];
1793 int i;
1794
1795 DPRINT (WF_DEBUG_CMD, "synth control with "
1796 "cmd 0x%x\n", wc->cmd);
1797
1798 /* Pre-handling of or for various commands */
1799
1800 switch (wc->cmd) {
1801 case WFC_DISABLE_INTERRUPTS:
1802 printk (KERN_INFO LOGNAME "interrupts disabled.\n");
1803 outb (0x80|0x20, dev.control_port);
1804 dev.interrupts_on = 0;
1805 return 0;
1806
1807 case WFC_ENABLE_INTERRUPTS:
1808 printk (KERN_INFO LOGNAME "interrupts enabled.\n");
1809 outb (0x80|0x40|0x20, dev.control_port);
1810 dev.interrupts_on = 1;
1811 return 0;
1812
1813 case WFC_INTERRUPT_STATUS:
1814 wc->rbuf[0] = dev.interrupts_on;
1815 return 0;
1816
1817 case WFC_ROMSAMPLES_RDONLY:
1818 dev.rom_samples_rdonly = wc->wbuf[0];
1819 wc->status = 0;
1820 return 0;
1821
1822 case WFC_IDENTIFY_SLOT_TYPE:
1823 i = wc->wbuf[0] | (wc->wbuf[1] << 7);
1824 if (i <0 || i >= WF_MAX_SAMPLE) {
1825 printk (KERN_WARNING LOGNAME "invalid slot ID %d\n",
1826 i);
1827 wc->status = EINVAL;
1828 return 0;
1829 }
1830 wc->rbuf[0] = dev.sample_status[i];
1831 wc->status = 0;
1832 return 0;
1833
1834 case WFC_DEBUG_DRIVER:
1835 dev.debug = wc->wbuf[0];
1836 printk (KERN_INFO LOGNAME "debug = 0x%x\n", dev.debug);
1837 return 0;
1838
1839 case WFC_FX_IOCTL:
1840 wffx_ioctl ((wavefront_fx_info *) &wc->wbuf[0]);
1841 return 0;
1842
1843 case WFC_UPLOAD_PATCH:
1844 munge_int32 (*((UINT32 *) wc->wbuf), patchnumbuf, 2);
1845 memcpy (wc->wbuf, patchnumbuf, 2);
1846 break;
1847
1848 case WFC_UPLOAD_MULTISAMPLE:
1849 /* multisamples have to be handled differently, and
1850 cannot be dealt with properly by wavefront_cmd() alone.
1851 */
1852 wc->status = wavefront_fetch_multisample
1853 ((wavefront_patch_info *) wc->rbuf);
1854 return 0;
1855
1856 case WFC_UPLOAD_SAMPLE_ALIAS:
1857 printk (KERN_INFO LOGNAME "support for sample alias upload "
1858 "being considered.\n");
1859 wc->status = EINVAL;
1860 return -EINVAL;
1861 }
1862
1863 wc->status = wavefront_cmd (wc->cmd, wc->rbuf, wc->wbuf);
1864
1865 /* Post-handling of certain commands.
1866
1867 In particular, if the command was an upload, demunge the data
1868 so that the user-level doesn't have to think about it.
1869 */
1870
1871 if (wc->status == 0) {
1872 switch (wc->cmd) {
1873 /* intercept any freemem requests so that we know
1874 we are always current with the user-level view
1875 of things.
1876 */
1877
1878 case WFC_REPORT_FREE_MEMORY:
1879 dev.freemem = demunge_int32 (wc->rbuf, 4);
1880 break;
1881
1882 case WFC_UPLOAD_PATCH:
1883 demunge_buf (wc->rbuf, wc->rbuf, WF_PATCH_BYTES);
1884 break;
1885
1886 case WFC_UPLOAD_PROGRAM:
1887 demunge_buf (wc->rbuf, wc->rbuf, WF_PROGRAM_BYTES);
1888 break;
1889
1890 case WFC_UPLOAD_EDRUM_PROGRAM:
1891 demunge_buf (wc->rbuf, wc->rbuf, WF_DRUM_BYTES - 1);
1892 break;
1893
1894 case WFC_UPLOAD_SAMPLE_HEADER:
1895 process_sample_hdr (wc->rbuf);
1896 break;
1897
1898 case WFC_UPLOAD_SAMPLE_ALIAS:
1899 printk (KERN_INFO LOGNAME "support for "
1900 "sample aliases still "
1901 "being considered.\n");
1902 break;
1903
1904 case WFC_VMIDI_OFF:
1905 if (virtual_midi_disable () < 0) {
1906 return -(EIO);
1907 }
1908 break;
1909
1910 case WFC_VMIDI_ON:
1911 if (virtual_midi_enable () < 0) {
1912 return -(EIO);
1913 }
1914 break;
1915 }
1916 }
1917
1918 return 0;
1919}
1920
1921
1922/***********************************************************************/
1923/* WaveFront: Linux file system interface (for access via raw synth) */
1924/***********************************************************************/
1925
1926static int
1927wavefront_open (struct inode *inode, struct file *file)
1928{
1929 /* XXX fix me */
1930 dev.opened = file->f_flags;
1931 return 0;
1932}
1933
1934static int
1935wavefront_release(struct inode *inode, struct file *file)
1936{
1937 lock_kernel();
1938 dev.opened = 0;
1939 dev.debug = 0;
1940 unlock_kernel();
1941 return 0;
1942}
1943
1944static int
1945wavefront_ioctl(struct inode *inode, struct file *file,
1946 unsigned int cmd, unsigned long arg)
1947{
1948 wavefront_control wc;
1949 int err;
1950
1951 switch (cmd) {
1952
1953 case WFCTL_WFCMD:
1954 if (copy_from_user(&wc, (void __user *) arg, sizeof (wc)))
1955 return -EFAULT;
1956
1957 if ((err = wavefront_synth_control (cmd, &wc)) == 0) {
1958 if (copy_to_user ((void __user *) arg, &wc, sizeof (wc)))
1959 return -EFAULT;
1960 }
1961
1962 return err;
1963
1964 case WFCTL_LOAD_SPP:
1965 return wavefront_load_patch ((const char __user *) arg);
1966
1967 default:
1968 printk (KERN_WARNING LOGNAME "invalid ioctl %#x\n", cmd);
1969 return -(EINVAL);
1970
1971 }
1972 return 0;
1973}
1974
1975static /*const*/ struct file_operations wavefront_fops = {
1976 .owner = THIS_MODULE,
1977 .llseek = no_llseek,
1978 .ioctl = wavefront_ioctl,
1979 .open = wavefront_open,
1980 .release = wavefront_release,
1981};
1982
1983
1984/***********************************************************************/
1985/* WaveFront: OSS installation and support interface */
1986/***********************************************************************/
1987
1988#if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
1989
1990static struct synth_info wavefront_info =
1991{"Turtle Beach WaveFront", 0, SYNTH_TYPE_SAMPLE, SAMPLE_TYPE_WAVEFRONT,
1992 0, 32, 0, 0, SYNTH_CAP_INPUT};
1993
1994static int
1995wavefront_oss_open (int devno, int mode)
1996
1997{
1998 dev.opened = mode;
1999 return 0;
2000}
2001
2002static void
2003wavefront_oss_close (int devno)
2004
2005{
2006 dev.opened = 0;
2007 dev.debug = 0;
2008 return;
2009}
2010
2011static int
2012wavefront_oss_ioctl (int devno, unsigned int cmd, void __user * arg)
2013
2014{
2015 wavefront_control wc;
2016 int err;
2017
2018 switch (cmd) {
2019 case SNDCTL_SYNTH_INFO:
2020 if(copy_to_user(arg, &wavefront_info, sizeof (wavefront_info)))
2021 return -EFAULT;
2022 return 0;
2023
2024 case SNDCTL_SEQ_RESETSAMPLES:
2025// printk (KERN_WARNING LOGNAME "driver cannot reset samples.\n");
2026 return 0; /* don't force an error */
2027
2028 case SNDCTL_SEQ_PERCMODE:
2029 return 0; /* don't force an error */
2030
2031 case SNDCTL_SYNTH_MEMAVL:
2032 if ((dev.freemem = wavefront_freemem ()) < 0) {
2033 printk (KERN_ERR LOGNAME "cannot get memory size\n");
2034 return -EIO;
2035 } else {
2036 return dev.freemem;
2037 }
2038 break;
2039
2040 case SNDCTL_SYNTH_CONTROL:
2041 if(copy_from_user (&wc, arg, sizeof (wc)))
2042 err = -EFAULT;
2043 else if ((err = wavefront_synth_control (cmd, &wc)) == 0) {
2044 if(copy_to_user (arg, &wc, sizeof (wc)))
2045 err = -EFAULT;
2046 }
2047
2048 return err;
2049
2050 default:
2051 return -(EINVAL);
2052 }
2053}
2054
2055static int
2056wavefront_oss_load_patch (int devno, int format, const char __user *addr,
2057 int offs, int count, int pmgr_flag)
2058{
2059
2060 if (format == SYSEX_PATCH) { /* Handled by midi_synth.c */
2061 if (midi_load_patch == NULL) {
2062 printk (KERN_ERR LOGNAME
2063 "SYSEX not loadable: "
2064 "no midi patch loader!\n");
2065 return -(EINVAL);
2066 }
2067
2068 return midi_load_patch (devno, format, addr,
2069 offs, count, pmgr_flag);
2070
2071 } else if (format == GUS_PATCH) {
2072 return wavefront_load_gus_patch (devno, format,
2073 addr, offs, count, pmgr_flag);
2074
2075 } else if (format != WAVEFRONT_PATCH) {
2076 printk (KERN_ERR LOGNAME "unknown patch format %d\n", format);
2077 return -(EINVAL);
2078 }
2079
2080 if (count < sizeof (wavefront_patch_info)) {
2081 printk (KERN_ERR LOGNAME "sample header too short\n");
2082 return -(EINVAL);
2083 }
2084
2085 /* "addr" points to a user-space wavefront_patch_info */
2086
2087 return wavefront_load_patch (addr);
2088}
2089
2090static struct synth_operations wavefront_operations =
2091{
2092 .owner = THIS_MODULE,
2093 .id = "WaveFront",
2094 .info = &wavefront_info,
2095 .midi_dev = 0,
2096 .synth_type = SYNTH_TYPE_SAMPLE,
2097 .synth_subtype = SAMPLE_TYPE_WAVEFRONT,
2098 .open = wavefront_oss_open,
2099 .close = wavefront_oss_close,
2100 .ioctl = wavefront_oss_ioctl,
2101 .kill_note = midi_synth_kill_note,
2102 .start_note = midi_synth_start_note,
2103 .set_instr = midi_synth_set_instr,
2104 .reset = midi_synth_reset,
2105 .load_patch = midi_synth_load_patch,
2106 .aftertouch = midi_synth_aftertouch,
2107 .controller = midi_synth_controller,
2108 .panning = midi_synth_panning,
2109 .bender = midi_synth_bender,
2110 .setup_voice = midi_synth_setup_voice
2111};
2112#endif /* OSS_SUPPORT_SEQ */
2113
2114#if OSS_SUPPORT_LEVEL & OSS_SUPPORT_STATIC_INSTALL
2115
2116static void __init attach_wavefront (struct address_info *hw_config)
2117{
2118 (void) install_wavefront ();
2119}
2120
2121static int __init probe_wavefront (struct address_info *hw_config)
2122{
2123 return !detect_wavefront (hw_config->irq, hw_config->io_base);
2124}
2125
2126static void __exit unload_wavefront (struct address_info *hw_config)
2127{
2128 (void) uninstall_wavefront ();
2129}
2130
2131#endif /* OSS_SUPPORT_STATIC_INSTALL */
2132
2133/***********************************************************************/
2134/* WaveFront: Linux modular sound kernel installation interface */
2135/***********************************************************************/
2136
2137static irqreturn_t
2138wavefrontintr(int irq, void *dev_id, struct pt_regs *dummy)
2139{
2140 struct wf_config *hw = dev_id;
2141
2142 /*
2143 Some comments on interrupts. I attempted a version of this
2144 driver that used interrupts throughout the code instead of
2145 doing busy and/or sleep-waiting. Alas, it appears that once
2146 the Motorola firmware is downloaded, the card *never*
2147 generates an RX interrupt. These are successfully generated
2148 during firmware loading, and after that wavefront_status()
2149 reports that an interrupt is pending on the card from time
2150 to time, but it never seems to be delivered to this
2151 driver. Note also that wavefront_status() continues to
2152 report that RX interrupts are enabled, suggesting that I
2153 didn't goof up and disable them by mistake.
2154
2155 Thus, I stepped back to a prior version of
2156 wavefront_wait(), the only place where this really
2157 matters. Its sad, but I've looked through the code to check
2158 on things, and I really feel certain that the Motorola
2159 firmware prevents RX-ready interrupts.
2160 */
2161
2162 if ((wavefront_status() & (STAT_INTR_READ|STAT_INTR_WRITE)) == 0) {
2163 return IRQ_NONE;
2164 }
2165
2166 hw->irq_ok = 1;
2167 hw->irq_cnt++;
2168 wake_up_interruptible (&hw->interrupt_sleeper);
2169 return IRQ_HANDLED;
2170}
2171
2172/* STATUS REGISTER
2173
21740 Host Rx Interrupt Enable (1=Enabled)
21751 Host Rx Register Full (1=Full)
21762 Host Rx Interrupt Pending (1=Interrupt)
21773 Unused
21784 Host Tx Interrupt (1=Enabled)
21795 Host Tx Register empty (1=Empty)
21806 Host Tx Interrupt Pending (1=Interrupt)
21817 Unused
2182*/
2183
2184static int
2185wavefront_interrupt_bits (int irq)
2186
2187{
2188 int bits;
2189
2190 switch (irq) {
2191 case 9:
2192 bits = 0x00;
2193 break;
2194 case 5:
2195 bits = 0x08;
2196 break;
2197 case 12:
2198 bits = 0x10;
2199 break;
2200 case 15:
2201 bits = 0x18;
2202 break;
2203
2204 default:
2205 printk (KERN_WARNING LOGNAME "invalid IRQ %d\n", irq);
2206 bits = -1;
2207 }
2208
2209 return bits;
2210}
2211
2212static void
2213wavefront_should_cause_interrupt (int val, int port, int timeout)
2214
2215{
2216 unsigned long flags;
2217
2218 /* this will not help on SMP - but at least it compiles */
2219 spin_lock_irqsave(&lock, flags);
2220 dev.irq_ok = 0;
2221 outb (val,port);
2222 interruptible_sleep_on_timeout (&dev.interrupt_sleeper, timeout);
2223 spin_unlock_irqrestore(&lock,flags);
2224}
2225
2226static int __init wavefront_hw_reset (void)
2227{
2228 int bits;
2229 int hwv[2];
2230 unsigned long irq_mask;
2231 short reported_irq;
2232
2233 /* IRQ already checked in init_module() */
2234
2235 bits = wavefront_interrupt_bits (dev.irq);
2236
2237 printk (KERN_DEBUG LOGNAME "autodetecting WaveFront IRQ\n");
2238
2239 irq_mask = probe_irq_on ();
2240
2241 outb (0x0, dev.control_port);
2242 outb (0x80 | 0x40 | bits, dev.data_port);
2243 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2244 dev.control_port,
2245 (reset_time*HZ)/100);
2246
2247 reported_irq = probe_irq_off (irq_mask);
2248
2249 if (reported_irq != dev.irq) {
2250 if (reported_irq == 0) {
2251 printk (KERN_ERR LOGNAME
2252 "No unassigned interrupts detected "
2253 "after h/w reset\n");
2254 } else if (reported_irq < 0) {
2255 printk (KERN_ERR LOGNAME
2256 "Multiple unassigned interrupts detected "
2257 "after h/w reset\n");
2258 } else {
2259 printk (KERN_ERR LOGNAME "autodetected IRQ %d not the "
2260 "value provided (%d)\n", reported_irq,
2261 dev.irq);
2262 }
2263 dev.irq = -1;
2264 return 1;
2265 } else {
2266 printk (KERN_INFO LOGNAME "autodetected IRQ at %d\n",
2267 reported_irq);
2268 }
2269
2270 if (request_irq (dev.irq, wavefrontintr,
2271 SA_INTERRUPT|SA_SHIRQ,
2272 "wavefront synth", &dev) < 0) {
2273 printk (KERN_WARNING LOGNAME "IRQ %d not available!\n",
2274 dev.irq);
2275 return 1;
2276 }
2277
2278 /* try reset of port */
2279
2280 outb (0x0, dev.control_port);
2281
2282 /* At this point, the board is in reset, and the H/W initialization
2283 register is accessed at the same address as the data port.
2284
2285 Bit 7 - Enable IRQ Driver
2286 0 - Tri-state the Wave-Board drivers for the PC Bus IRQs
2287 1 - Enable IRQ selected by bits 5:3 to be driven onto the PC Bus.
2288
2289 Bit 6 - MIDI Interface Select
2290
2291 0 - Use the MIDI Input from the 26-pin WaveBlaster
2292 compatible header as the serial MIDI source
2293 1 - Use the MIDI Input from the 9-pin D connector as the
2294 serial MIDI source.
2295
2296 Bits 5:3 - IRQ Selection
2297 0 0 0 - IRQ 2/9
2298 0 0 1 - IRQ 5
2299 0 1 0 - IRQ 12
2300 0 1 1 - IRQ 15
2301 1 0 0 - Reserved
2302 1 0 1 - Reserved
2303 1 1 0 - Reserved
2304 1 1 1 - Reserved
2305
2306 Bits 2:1 - Reserved
2307 Bit 0 - Disable Boot ROM
2308 0 - memory accesses to 03FC30-03FFFFH utilize the internal Boot ROM
2309 1 - memory accesses to 03FC30-03FFFFH are directed to external
2310 storage.
2311
2312 */
2313
2314 /* configure hardware: IRQ, enable interrupts,
2315 plus external 9-pin MIDI interface selected
2316 */
2317
2318 outb (0x80 | 0x40 | bits, dev.data_port);
2319
2320 /* CONTROL REGISTER
2321
2322 0 Host Rx Interrupt Enable (1=Enabled) 0x1
2323 1 Unused 0x2
2324 2 Unused 0x4
2325 3 Unused 0x8
2326 4 Host Tx Interrupt Enable 0x10
2327 5 Mute (0=Mute; 1=Play) 0x20
2328 6 Master Interrupt Enable (1=Enabled) 0x40
2329 7 Master Reset (0=Reset; 1=Run) 0x80
2330
2331 Take us out of reset, mute output, master + TX + RX interrupts on.
2332
2333 We'll get an interrupt presumably to tell us that the TX
2334 register is clear.
2335 */
2336
2337 wavefront_should_cause_interrupt(0x80|0x40|0x10|0x1,
2338 dev.control_port,
2339 (reset_time*HZ)/100);
2340
2341 /* Note: data port is now the data port, not the h/w initialization
2342 port.
2343 */
2344
2345 if (!dev.irq_ok) {
2346 printk (KERN_WARNING LOGNAME
2347 "intr not received after h/w un-reset.\n");
2348 goto gone_bad;
2349 }
2350
2351 dev.interrupts_on = 1;
2352
2353 /* Note: data port is now the data port, not the h/w initialization
2354 port.
2355
2356 At this point, only "HW VERSION" or "DOWNLOAD OS" commands
2357 will work. So, issue one of them, and wait for TX
2358 interrupt. This can take a *long* time after a cold boot,
2359 while the ISC ROM does its RAM test. The SDK says up to 4
2360 seconds - with 12MB of RAM on a Tropez+, it takes a lot
2361 longer than that (~16secs). Note that the card understands
2362 the difference between a warm and a cold boot, so
2363 subsequent ISC2115 reboots (say, caused by module
2364 reloading) will get through this much faster.
2365
2366 XXX Interesting question: why is no RX interrupt received first ?
2367 */
2368
2369 wavefront_should_cause_interrupt(WFC_HARDWARE_VERSION,
2370 dev.data_port, ramcheck_time*HZ);
2371
2372 if (!dev.irq_ok) {
2373 printk (KERN_WARNING LOGNAME
2374 "post-RAM-check interrupt not received.\n");
2375 goto gone_bad;
2376 }
2377
2378 if (!wavefront_wait (STAT_CAN_READ)) {
2379 printk (KERN_WARNING LOGNAME
2380 "no response to HW version cmd.\n");
2381 goto gone_bad;
2382 }
2383
2384 if ((hwv[0] = wavefront_read ()) == -1) {
2385 printk (KERN_WARNING LOGNAME
2386 "board not responding correctly.\n");
2387 goto gone_bad;
2388 }
2389
2390 if (hwv[0] == 0xFF) { /* NAK */
2391
2392 /* Board's RAM test failed. Try to read error code,
2393 and tell us about it either way.
2394 */
2395
2396 if ((hwv[0] = wavefront_read ()) == -1) {
2397 printk (KERN_WARNING LOGNAME "on-board RAM test failed "
2398 "(bad error code).\n");
2399 } else {
2400 printk (KERN_WARNING LOGNAME "on-board RAM test failed "
2401 "(error code: 0x%x).\n",
2402 hwv[0]);
2403 }
2404 goto gone_bad;
2405 }
2406
2407 /* We're OK, just get the next byte of the HW version response */
2408
2409 if ((hwv[1] = wavefront_read ()) == -1) {
2410 printk (KERN_WARNING LOGNAME "incorrect h/w response.\n");
2411 goto gone_bad;
2412 }
2413
2414 printk (KERN_INFO LOGNAME "hardware version %d.%d\n",
2415 hwv[0], hwv[1]);
2416
2417 return 0;
2418
2419
2420 gone_bad:
2421 if (dev.irq >= 0) {
2422 free_irq (dev.irq, &dev);
2423 dev.irq = -1;
2424 }
2425 return (1);
2426}
2427
2428static int __init detect_wavefront (int irq, int io_base)
2429{
2430 unsigned char rbuf[4], wbuf[4];
2431
2432 /* TB docs say the device takes up 8 ports, but we know that
2433 if there is an FX device present (i.e. a Tropez+) it really
2434 consumes 16.
2435 */
2436
2437 if (check_region (io_base, 16)) {
2438 printk (KERN_ERR LOGNAME "IO address range 0x%x - 0x%x "
2439 "already in use - ignored\n", dev.base,
2440 dev.base+15);
2441 return -1;
2442 }
2443
2444 dev.irq = irq;
2445 dev.base = io_base;
2446 dev.israw = 0;
2447 dev.debug = debug_default;
2448 dev.interrupts_on = 0;
2449 dev.irq_cnt = 0;
2450 dev.rom_samples_rdonly = 1; /* XXX default lock on ROM sample slots */
2451
2452 if (wavefront_cmd (WFC_FIRMWARE_VERSION, rbuf, wbuf) == 0) {
2453
2454 dev.fw_version[0] = rbuf[0];
2455 dev.fw_version[1] = rbuf[1];
2456 printk (KERN_INFO LOGNAME
2457 "firmware %d.%d already loaded.\n",
2458 rbuf[0], rbuf[1]);
2459
2460 /* check that a command actually works */
2461
2462 if (wavefront_cmd (WFC_HARDWARE_VERSION,
2463 rbuf, wbuf) == 0) {
2464 dev.hw_version[0] = rbuf[0];
2465 dev.hw_version[1] = rbuf[1];
2466 } else {
2467 printk (KERN_WARNING LOGNAME "not raw, but no "
2468 "hardware version!\n");
2469 return 0;
2470 }
2471
2472 if (!wf_raw) {
2473 return 1;
2474 } else {
2475 printk (KERN_INFO LOGNAME
2476 "reloading firmware anyway.\n");
2477 dev.israw = 1;
2478 }
2479
2480 } else {
2481
2482 dev.israw = 1;
2483 printk (KERN_INFO LOGNAME
2484 "no response to firmware probe, assume raw.\n");
2485
2486 }
2487
2488 init_waitqueue_head (&dev.interrupt_sleeper);
2489
2490 if (wavefront_hw_reset ()) {
2491 printk (KERN_WARNING LOGNAME "hardware reset failed\n");
2492 return 0;
2493 }
2494
2495 /* Check for FX device, present only on Tropez+ */
2496
2497 dev.has_fx = (detect_wffx () == 0);
2498
2499 return 1;
2500}
2501
2502#include "os.h"
2503#include <linux/fs.h>
2504#include <linux/mm.h>
2505#include <linux/slab.h>
2506#include <asm/uaccess.h>
2507
2508
2509static int
2510wavefront_download_firmware (char *path)
2511
2512{
2513 unsigned char section[WF_SECTION_MAX];
2514 char section_length; /* yes, just a char; max value is WF_SECTION_MAX */
2515 int section_cnt_downloaded = 0;
2516 int fd;
2517 int c;
2518 int i;
2519 mm_segment_t fs;
2520
2521 /* This tries to be a bit cleverer than the stuff Alan Cox did for
2522 the generic sound firmware, in that it actually knows
2523 something about the structure of the Motorola firmware. In
2524 particular, it uses a version that has been stripped of the
2525 20K of useless header information, and had section lengths
2526 added, making it possible to load the entire OS without any
2527 [kv]malloc() activity, since the longest entity we ever read is
2528 42 bytes (well, WF_SECTION_MAX) long.
2529 */
2530
2531 fs = get_fs();
2532 set_fs (get_ds());
2533
2534 if ((fd = sys_open (path, 0, 0)) < 0) {
2535 printk (KERN_WARNING LOGNAME "Unable to load \"%s\".\n",
2536 path);
2537 return 1;
2538 }
2539
2540 while (1) {
2541 int x;
2542
2543 if ((x = sys_read (fd, &section_length, sizeof (section_length))) !=
2544 sizeof (section_length)) {
2545 printk (KERN_ERR LOGNAME "firmware read error.\n");
2546 goto failure;
2547 }
2548
2549 if (section_length == 0) {
2550 break;
2551 }
2552
2553 if (sys_read (fd, section, section_length) != section_length) {
2554 printk (KERN_ERR LOGNAME "firmware section "
2555 "read error.\n");
2556 goto failure;
2557 }
2558
2559 /* Send command */
2560
2561 if (wavefront_write (WFC_DOWNLOAD_OS)) {
2562 goto failure;
2563 }
2564
2565 for (i = 0; i < section_length; i++) {
2566 if (wavefront_write (section[i])) {
2567 goto failure;
2568 }
2569 }
2570
2571 /* get ACK */
2572
2573 if (wavefront_wait (STAT_CAN_READ)) {
2574
2575 if ((c = inb (dev.data_port)) != WF_ACK) {
2576
2577 printk (KERN_ERR LOGNAME "download "
2578 "of section #%d not "
2579 "acknowledged, ack = 0x%x\n",
2580 section_cnt_downloaded + 1, c);
2581 goto failure;
2582
2583 }
2584
2585 } else {
2586 printk (KERN_ERR LOGNAME "time out for firmware ACK.\n");
2587 goto failure;
2588 }
2589
2590 }
2591
2592 sys_close (fd);
2593 set_fs (fs);
2594 return 0;
2595
2596 failure:
2597 sys_close (fd);
2598 set_fs (fs);
2599 printk (KERN_ERR "\nWaveFront: firmware download failed!!!\n");
2600 return 1;
2601}
2602
2603static int __init wavefront_config_midi (void)
2604{
2605 unsigned char rbuf[4], wbuf[4];
2606
2607 if (detect_wf_mpu (dev.irq, dev.base) < 0) {
2608 printk (KERN_WARNING LOGNAME
2609 "could not find working MIDI device\n");
2610 return -1;
2611 }
2612
2613 if ((dev.mididev = install_wf_mpu ()) < 0) {
2614 printk (KERN_WARNING LOGNAME
2615 "MIDI interfaces not configured\n");
2616 return -1;
2617 }
2618
2619 /* Route external MIDI to WaveFront synth (by default) */
2620
2621 if (wavefront_cmd (WFC_MISYNTH_ON, rbuf, wbuf)) {
2622 printk (KERN_WARNING LOGNAME
2623 "cannot enable MIDI-IN to synth routing.\n");
2624 /* XXX error ? */
2625 }
2626
2627
2628#if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2629 /* Get the regular MIDI patch loading function, so we can
2630 use it if we ever get handed a SYSEX patch. This is
2631 unlikely, because its so damn slow, but we may as well
2632 leave this functionality from maui.c behind, since it
2633 could be useful for sequencer applications that can
2634 only use MIDI to do patch loading.
2635 */
2636
2637 if (midi_devs[dev.mididev]->converter != NULL) {
2638 midi_load_patch = midi_devs[dev.mididev]->converter->load_patch;
2639 midi_devs[dev.mididev]->converter->load_patch =
2640 &wavefront_oss_load_patch;
2641 }
2642
2643#endif /* OSS_SUPPORT_SEQ */
2644
2645 /* Turn on Virtual MIDI, but first *always* turn it off,
2646 since otherwise consectutive reloads of the driver will
2647 never cause the hardware to generate the initial "internal" or
2648 "external" source bytes in the MIDI data stream. This
2649 is pretty important, since the internal hardware generally will
2650 be used to generate none or very little MIDI output, and
2651 thus the only source of MIDI data is actually external. Without
2652 the switch bytes, the driver will think it all comes from
2653 the internal interface. Duh.
2654 */
2655
2656 if (wavefront_cmd (WFC_VMIDI_OFF, rbuf, wbuf)) {
2657 printk (KERN_WARNING LOGNAME
2658 "virtual MIDI mode not disabled\n");
2659 return 0; /* We're OK, but missing the external MIDI dev */
2660 }
2661
2662 if ((dev.ext_mididev = virtual_midi_enable ()) < 0) {
2663 printk (KERN_WARNING LOGNAME "no virtual MIDI access.\n");
2664 } else {
2665 if (wavefront_cmd (WFC_VMIDI_ON, rbuf, wbuf)) {
2666 printk (KERN_WARNING LOGNAME
2667 "cannot enable virtual MIDI mode.\n");
2668 virtual_midi_disable ();
2669 }
2670 }
2671
2672 return 0;
2673}
2674
2675static int __init wavefront_do_reset (int atboot)
2676{
2677 char voices[1];
2678
2679 if (!atboot && wavefront_hw_reset ()) {
2680 printk (KERN_WARNING LOGNAME "hw reset failed.\n");
2681 goto gone_bad;
2682 }
2683
2684 if (dev.israw) {
2685 if (wavefront_download_firmware (ospath)) {
2686 goto gone_bad;
2687 }
2688
2689 dev.israw = 0;
2690
2691 /* Wait for the OS to get running. The protocol for
2692 this is non-obvious, and was determined by
2693 using port-IO tracing in DOSemu and some
2694 experimentation here.
2695
2696 Rather than using timed waits, use interrupts creatively.
2697 */
2698
2699 wavefront_should_cause_interrupt (WFC_NOOP,
2700 dev.data_port,
2701 (osrun_time*HZ));
2702
2703 if (!dev.irq_ok) {
2704 printk (KERN_WARNING LOGNAME
2705 "no post-OS interrupt.\n");
2706 goto gone_bad;
2707 }
2708
2709 /* Now, do it again ! */
2710
2711 wavefront_should_cause_interrupt (WFC_NOOP,
2712 dev.data_port, (10*HZ));
2713
2714 if (!dev.irq_ok) {
2715 printk (KERN_WARNING LOGNAME
2716 "no post-OS interrupt(2).\n");
2717 goto gone_bad;
2718 }
2719
2720 /* OK, no (RX/TX) interrupts any more, but leave mute
2721 in effect.
2722 */
2723
2724 outb (0x80|0x40, dev.control_port);
2725
2726 /* No need for the IRQ anymore */
2727
2728 free_irq (dev.irq, &dev);
2729
2730 }
2731
2732 if (dev.has_fx && fx_raw) {
2733 wffx_init ();
2734 }
2735
2736 /* SETUPSND.EXE asks for sample memory config here, but since i
2737 have no idea how to interpret the result, we'll forget
2738 about it.
2739 */
2740
2741 if ((dev.freemem = wavefront_freemem ()) < 0) {
2742 goto gone_bad;
2743 }
2744
2745 printk (KERN_INFO LOGNAME "available DRAM %dk\n", dev.freemem / 1024);
2746
2747 if (wavefront_write (0xf0) ||
2748 wavefront_write (1) ||
2749 (wavefront_read () < 0)) {
2750 dev.debug = 0;
2751 printk (KERN_WARNING LOGNAME "MPU emulation mode not set.\n");
2752 goto gone_bad;
2753 }
2754
2755 voices[0] = 32;
2756
2757 if (wavefront_cmd (WFC_SET_NVOICES, NULL, voices)) {
2758 printk (KERN_WARNING LOGNAME
2759 "cannot set number of voices to 32.\n");
2760 goto gone_bad;
2761 }
2762
2763
2764 return 0;
2765
2766 gone_bad:
2767 /* reset that sucker so that it doesn't bother us. */
2768
2769 outb (0x0, dev.control_port);
2770 dev.interrupts_on = 0;
2771 if (dev.irq >= 0) {
2772 free_irq (dev.irq, &dev);
2773 }
2774 return 1;
2775}
2776
2777static int __init wavefront_init (int atboot)
2778{
2779 int samples_are_from_rom;
2780
2781 if (dev.israw) {
2782 samples_are_from_rom = 1;
2783 } else {
2784 /* XXX is this always true ? */
2785 samples_are_from_rom = 0;
2786 }
2787
2788 if (dev.israw || fx_raw) {
2789 if (wavefront_do_reset (atboot)) {
2790 return -1;
2791 }
2792 }
2793
2794 wavefront_get_sample_status (samples_are_from_rom);
2795 wavefront_get_program_status ();
2796 wavefront_get_patch_status ();
2797
2798 /* Start normal operation: unreset, master interrupt enabled, no mute
2799 */
2800
2801 outb (0x80|0x40|0x20, dev.control_port);
2802
2803 return (0);
2804}
2805
2806static int __init install_wavefront (void)
2807
2808{
2809 if ((dev.synth_dev = register_sound_synth (&wavefront_fops, -1)) < 0) {
2810 printk (KERN_ERR LOGNAME "cannot register raw synth\n");
2811 return -1;
2812 }
2813
2814#if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2815 if ((dev.oss_dev = sound_alloc_synthdev()) == -1) {
2816 printk (KERN_ERR LOGNAME "Too many sequencers\n");
2817 return -1;
2818 } else {
2819 synth_devs[dev.oss_dev] = &wavefront_operations;
2820 }
2821#endif /* OSS_SUPPORT_SEQ */
2822
2823 if (wavefront_init (1) < 0) {
2824 printk (KERN_WARNING LOGNAME "initialization failed.\n");
2825
2826#if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2827 sound_unload_synthdev (dev.oss_dev);
2828#endif /* OSS_SUPPORT_SEQ */
2829
2830 return -1;
2831 }
2832
2833 request_region (dev.base+2, 6, "wavefront synth");
2834
2835 if (dev.has_fx) {
2836 request_region (dev.base+8, 8, "wavefront fx");
2837 }
2838
2839 if (wavefront_config_midi ()) {
2840 printk (KERN_WARNING LOGNAME "could not initialize MIDI.\n");
2841 }
2842
2843 return dev.oss_dev;
2844}
2845
2846static void __exit uninstall_wavefront (void)
2847{
2848 /* the first two i/o addresses are freed by the wf_mpu code */
2849 release_region (dev.base+2, 6);
2850
2851 if (dev.has_fx) {
2852 release_region (dev.base+8, 8);
2853 }
2854
2855 unregister_sound_synth (dev.synth_dev);
2856
2857#if OSS_SUPPORT_LEVEL & OSS_SUPPORT_SEQ
2858 sound_unload_synthdev (dev.oss_dev);
2859#endif /* OSS_SUPPORT_SEQ */
2860 uninstall_wf_mpu ();
2861}
2862
2863/***********************************************************************/
2864/* WaveFront FX control */
2865/***********************************************************************/
2866
2867#include "yss225.h"
2868
2869/* Control bits for the Load Control Register
2870 */
2871
2872#define FX_LSB_TRANSFER 0x01 /* transfer after DSP LSB byte written */
2873#define FX_MSB_TRANSFER 0x02 /* transfer after DSP MSB byte written */
2874#define FX_AUTO_INCR 0x04 /* auto-increment DSP address after transfer */
2875
2876static int
2877wffx_idle (void)
2878
2879{
2880 int i;
2881 unsigned int x = 0x80;
2882
2883 for (i = 0; i < 1000; i++) {
2884 x = inb (dev.fx_status);
2885 if ((x & 0x80) == 0) {
2886 break;
2887 }
2888 }
2889
2890 if (x & 0x80) {
2891 printk (KERN_ERR LOGNAME "FX device never idle.\n");
2892 return 0;
2893 }
2894
2895 return (1);
2896}
2897
2898int __init detect_wffx (void)
2899{
2900 /* This is a crude check, but its the best one I have for now.
2901 Certainly on the Maui and the Tropez, wffx_idle() will
2902 report "never idle", which suggests that this test should
2903 work OK.
2904 */
2905
2906 if (inb (dev.fx_status) & 0x80) {
2907 printk (KERN_INFO LOGNAME "Hmm, probably a Maui or Tropez.\n");
2908 return -1;
2909 }
2910
2911 return 0;
2912}
2913
2914void
2915wffx_mute (int onoff)
2916
2917{
2918 if (!wffx_idle()) {
2919 return;
2920 }
2921
2922 outb (onoff ? 0x02 : 0x00, dev.fx_op);
2923}
2924
2925static int
2926wffx_memset (int page,
2927 int addr, int cnt, unsigned short *data)
2928{
2929 if (page < 0 || page > 7) {
2930 printk (KERN_ERR LOGNAME "FX memset: "
2931 "page must be >= 0 and <= 7\n");
2932 return -(EINVAL);
2933 }
2934
2935 if (addr < 0 || addr > 0x7f) {
2936 printk (KERN_ERR LOGNAME "FX memset: "
2937 "addr must be >= 0 and <= 7f\n");
2938 return -(EINVAL);
2939 }
2940
2941 if (cnt == 1) {
2942
2943 outb (FX_LSB_TRANSFER, dev.fx_lcr);
2944 outb (page, dev.fx_dsp_page);
2945 outb (addr, dev.fx_dsp_addr);
2946 outb ((data[0] >> 8), dev.fx_dsp_msb);
2947 outb ((data[0] & 0xff), dev.fx_dsp_lsb);
2948
2949 printk (KERN_INFO LOGNAME "FX: addr %d:%x set to 0x%x\n",
2950 page, addr, data[0]);
2951
2952 } else {
2953 int i;
2954
2955 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
2956 outb (page, dev.fx_dsp_page);
2957 outb (addr, dev.fx_dsp_addr);
2958
2959 for (i = 0; i < cnt; i++) {
2960 outb ((data[i] >> 8), dev.fx_dsp_msb);
2961 outb ((data[i] & 0xff), dev.fx_dsp_lsb);
2962 if (!wffx_idle ()) {
2963 break;
2964 }
2965 }
2966
2967 if (i != cnt) {
2968 printk (KERN_WARNING LOGNAME
2969 "FX memset "
2970 "(0x%x, 0x%x, %p, %d) incomplete\n",
2971 page, addr, data, cnt);
2972 return -(EIO);
2973 }
2974 }
2975
2976 return 0;
2977}
2978
2979static int
2980wffx_ioctl (wavefront_fx_info *r)
2981
2982{
2983 unsigned short page_data[256];
2984 unsigned short *pd;
2985
2986 switch (r->request) {
2987 case WFFX_MUTE:
2988 wffx_mute (r->data[0]);
2989 return 0;
2990
2991 case WFFX_MEMSET:
2992
2993 if (r->data[2] <= 0) {
2994 printk (KERN_ERR LOGNAME "cannot write "
2995 "<= 0 bytes to FX\n");
2996 return -(EINVAL);
2997 } else if (r->data[2] == 1) {
2998 pd = (unsigned short *) &r->data[3];
2999 } else {
3000 if (r->data[2] > sizeof (page_data)) {
3001 printk (KERN_ERR LOGNAME "cannot write "
3002 "> 255 bytes to FX\n");
3003 return -(EINVAL);
3004 }
3005 if (copy_from_user(page_data,
3006 (unsigned char __user *)r->data[3],
3007 r->data[2]))
3008 return -EFAULT;
3009 pd = page_data;
3010 }
3011
3012 return wffx_memset (r->data[0], /* page */
3013 r->data[1], /* addr */
3014 r->data[2], /* cnt */
3015 pd);
3016
3017 default:
3018 printk (KERN_WARNING LOGNAME
3019 "FX: ioctl %d not yet supported\n",
3020 r->request);
3021 return -(EINVAL);
3022 }
3023}
3024
3025/* YSS225 initialization.
3026
3027 This code was developed using DOSEMU. The Turtle Beach SETUPSND
3028 utility was run with I/O tracing in DOSEMU enabled, and a reconstruction
3029 of the port I/O done, using the Yamaha faxback document as a guide
3030 to add more logic to the code. Its really pretty weird.
3031
3032 There was an alternative approach of just dumping the whole I/O
3033 sequence as a series of port/value pairs and a simple loop
3034 that output it. However, I hope that eventually I'll get more
3035 control over what this code does, and so I tried to stick with
3036 a somewhat "algorithmic" approach.
3037*/
3038
3039static int __init wffx_init (void)
3040{
3041 int i;
3042 int j;
3043
3044 /* Set all bits for all channels on the MOD unit to zero */
3045 /* XXX But why do this twice ? */
3046
3047 for (j = 0; j < 2; j++) {
3048 for (i = 0x10; i <= 0xff; i++) {
3049
3050 if (!wffx_idle ()) {
3051 return (-1);
3052 }
3053
3054 outb (i, dev.fx_mod_addr);
3055 outb (0x0, dev.fx_mod_data);
3056 }
3057 }
3058
3059 if (!wffx_idle()) return (-1);
3060 outb (0x02, dev.fx_op); /* mute on */
3061
3062 if (!wffx_idle()) return (-1);
3063 outb (0x07, dev.fx_dsp_page);
3064 outb (0x44, dev.fx_dsp_addr);
3065 outb (0x00, dev.fx_dsp_msb);
3066 outb (0x00, dev.fx_dsp_lsb);
3067 if (!wffx_idle()) return (-1);
3068 outb (0x07, dev.fx_dsp_page);
3069 outb (0x42, dev.fx_dsp_addr);
3070 outb (0x00, dev.fx_dsp_msb);
3071 outb (0x00, dev.fx_dsp_lsb);
3072 if (!wffx_idle()) return (-1);
3073 outb (0x07, dev.fx_dsp_page);
3074 outb (0x43, dev.fx_dsp_addr);
3075 outb (0x00, dev.fx_dsp_msb);
3076 outb (0x00, dev.fx_dsp_lsb);
3077 if (!wffx_idle()) return (-1);
3078 outb (0x07, dev.fx_dsp_page);
3079 outb (0x7c, dev.fx_dsp_addr);
3080 outb (0x00, dev.fx_dsp_msb);
3081 outb (0x00, dev.fx_dsp_lsb);
3082 if (!wffx_idle()) return (-1);
3083 outb (0x07, dev.fx_dsp_page);
3084 outb (0x7e, dev.fx_dsp_addr);
3085 outb (0x00, dev.fx_dsp_msb);
3086 outb (0x00, dev.fx_dsp_lsb);
3087 if (!wffx_idle()) return (-1);
3088 outb (0x07, dev.fx_dsp_page);
3089 outb (0x46, dev.fx_dsp_addr);
3090 outb (0x00, dev.fx_dsp_msb);
3091 outb (0x00, dev.fx_dsp_lsb);
3092 if (!wffx_idle()) return (-1);
3093 outb (0x07, dev.fx_dsp_page);
3094 outb (0x49, dev.fx_dsp_addr);
3095 outb (0x00, dev.fx_dsp_msb);
3096 outb (0x00, dev.fx_dsp_lsb);
3097 if (!wffx_idle()) return (-1);
3098 outb (0x07, dev.fx_dsp_page);
3099 outb (0x47, dev.fx_dsp_addr);
3100 outb (0x00, dev.fx_dsp_msb);
3101 outb (0x00, dev.fx_dsp_lsb);
3102 if (!wffx_idle()) return (-1);
3103 outb (0x07, dev.fx_dsp_page);
3104 outb (0x4a, dev.fx_dsp_addr);
3105 outb (0x00, dev.fx_dsp_msb);
3106 outb (0x00, dev.fx_dsp_lsb);
3107
3108 /* either because of stupidity by TB's programmers, or because it
3109 actually does something, rezero the MOD page.
3110 */
3111 for (i = 0x10; i <= 0xff; i++) {
3112
3113 if (!wffx_idle ()) {
3114 return (-1);
3115 }
3116
3117 outb (i, dev.fx_mod_addr);
3118 outb (0x0, dev.fx_mod_data);
3119 }
3120 /* load page zero */
3121
3122 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3123 outb (0x00, dev.fx_dsp_page);
3124 outb (0x00, dev.fx_dsp_addr);
3125
3126 for (i = 0; i < sizeof (page_zero); i += 2) {
3127 outb (page_zero[i], dev.fx_dsp_msb);
3128 outb (page_zero[i+1], dev.fx_dsp_lsb);
3129 if (!wffx_idle()) return (-1);
3130 }
3131
3132 /* Now load page one */
3133
3134 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3135 outb (0x01, dev.fx_dsp_page);
3136 outb (0x00, dev.fx_dsp_addr);
3137
3138 for (i = 0; i < sizeof (page_one); i += 2) {
3139 outb (page_one[i], dev.fx_dsp_msb);
3140 outb (page_one[i+1], dev.fx_dsp_lsb);
3141 if (!wffx_idle()) return (-1);
3142 }
3143
3144 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3145 outb (0x02, dev.fx_dsp_page);
3146 outb (0x00, dev.fx_dsp_addr);
3147
3148 for (i = 0; i < sizeof (page_two); i++) {
3149 outb (page_two[i], dev.fx_dsp_lsb);
3150 if (!wffx_idle()) return (-1);
3151 }
3152
3153 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3154 outb (0x03, dev.fx_dsp_page);
3155 outb (0x00, dev.fx_dsp_addr);
3156
3157 for (i = 0; i < sizeof (page_three); i++) {
3158 outb (page_three[i], dev.fx_dsp_lsb);
3159 if (!wffx_idle()) return (-1);
3160 }
3161
3162 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3163 outb (0x04, dev.fx_dsp_page);
3164 outb (0x00, dev.fx_dsp_addr);
3165
3166 for (i = 0; i < sizeof (page_four); i++) {
3167 outb (page_four[i], dev.fx_dsp_lsb);
3168 if (!wffx_idle()) return (-1);
3169 }
3170
3171 /* Load memory area (page six) */
3172
3173 outb (FX_LSB_TRANSFER, dev.fx_lcr);
3174 outb (0x06, dev.fx_dsp_page);
3175
3176 for (i = 0; i < sizeof (page_six); i += 3) {
3177 outb (page_six[i], dev.fx_dsp_addr);
3178 outb (page_six[i+1], dev.fx_dsp_msb);
3179 outb (page_six[i+2], dev.fx_dsp_lsb);
3180 if (!wffx_idle()) return (-1);
3181 }
3182
3183 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3184 outb (0x07, dev.fx_dsp_page);
3185 outb (0x00, dev.fx_dsp_addr);
3186
3187 for (i = 0; i < sizeof (page_seven); i += 2) {
3188 outb (page_seven[i], dev.fx_dsp_msb);
3189 outb (page_seven[i+1], dev.fx_dsp_lsb);
3190 if (!wffx_idle()) return (-1);
3191 }
3192
3193 /* Now setup the MOD area. We do this algorithmically in order to
3194 save a little data space. It could be done in the same fashion
3195 as the "pages".
3196 */
3197
3198 for (i = 0x00; i <= 0x0f; i++) {
3199 outb (0x01, dev.fx_mod_addr);
3200 outb (i, dev.fx_mod_data);
3201 if (!wffx_idle()) return (-1);
3202 outb (0x02, dev.fx_mod_addr);
3203 outb (0x00, dev.fx_mod_data);
3204 if (!wffx_idle()) return (-1);
3205 }
3206
3207 for (i = 0xb0; i <= 0xbf; i++) {
3208 outb (i, dev.fx_mod_addr);
3209 outb (0x20, dev.fx_mod_data);
3210 if (!wffx_idle()) return (-1);
3211 }
3212
3213 for (i = 0xf0; i <= 0xff; i++) {
3214 outb (i, dev.fx_mod_addr);
3215 outb (0x20, dev.fx_mod_data);
3216 if (!wffx_idle()) return (-1);
3217 }
3218
3219 for (i = 0x10; i <= 0x1d; i++) {
3220 outb (i, dev.fx_mod_addr);
3221 outb (0xff, dev.fx_mod_data);
3222 if (!wffx_idle()) return (-1);
3223 }
3224
3225 outb (0x1e, dev.fx_mod_addr);
3226 outb (0x40, dev.fx_mod_data);
3227 if (!wffx_idle()) return (-1);
3228
3229 for (i = 0x1f; i <= 0x2d; i++) {
3230 outb (i, dev.fx_mod_addr);
3231 outb (0xff, dev.fx_mod_data);
3232 if (!wffx_idle()) return (-1);
3233 }
3234
3235 outb (0x2e, dev.fx_mod_addr);
3236 outb (0x00, dev.fx_mod_data);
3237 if (!wffx_idle()) return (-1);
3238
3239 for (i = 0x2f; i <= 0x3e; i++) {
3240 outb (i, dev.fx_mod_addr);
3241 outb (0x00, dev.fx_mod_data);
3242 if (!wffx_idle()) return (-1);
3243 }
3244
3245 outb (0x3f, dev.fx_mod_addr);
3246 outb (0x20, dev.fx_mod_data);
3247 if (!wffx_idle()) return (-1);
3248
3249 for (i = 0x40; i <= 0x4d; i++) {
3250 outb (i, dev.fx_mod_addr);
3251 outb (0x00, dev.fx_mod_data);
3252 if (!wffx_idle()) return (-1);
3253 }
3254
3255 outb (0x4e, dev.fx_mod_addr);
3256 outb (0x0e, dev.fx_mod_data);
3257 if (!wffx_idle()) return (-1);
3258 outb (0x4f, dev.fx_mod_addr);
3259 outb (0x0e, dev.fx_mod_data);
3260 if (!wffx_idle()) return (-1);
3261
3262
3263 for (i = 0x50; i <= 0x6b; i++) {
3264 outb (i, dev.fx_mod_addr);
3265 outb (0x00, dev.fx_mod_data);
3266 if (!wffx_idle()) return (-1);
3267 }
3268
3269 outb (0x6c, dev.fx_mod_addr);
3270 outb (0x40, dev.fx_mod_data);
3271 if (!wffx_idle()) return (-1);
3272
3273 outb (0x6d, dev.fx_mod_addr);
3274 outb (0x00, dev.fx_mod_data);
3275 if (!wffx_idle()) return (-1);
3276
3277 outb (0x6e, dev.fx_mod_addr);
3278 outb (0x40, dev.fx_mod_data);
3279 if (!wffx_idle()) return (-1);
3280
3281 outb (0x6f, dev.fx_mod_addr);
3282 outb (0x40, dev.fx_mod_data);
3283 if (!wffx_idle()) return (-1);
3284
3285 for (i = 0x70; i <= 0x7f; i++) {
3286 outb (i, dev.fx_mod_addr);
3287 outb (0xc0, dev.fx_mod_data);
3288 if (!wffx_idle()) return (-1);
3289 }
3290
3291 for (i = 0x80; i <= 0xaf; i++) {
3292 outb (i, dev.fx_mod_addr);
3293 outb (0x00, dev.fx_mod_data);
3294 if (!wffx_idle()) return (-1);
3295 }
3296
3297 for (i = 0xc0; i <= 0xdd; i++) {
3298 outb (i, dev.fx_mod_addr);
3299 outb (0x00, dev.fx_mod_data);
3300 if (!wffx_idle()) return (-1);
3301 }
3302
3303 outb (0xde, dev.fx_mod_addr);
3304 outb (0x10, dev.fx_mod_data);
3305 if (!wffx_idle()) return (-1);
3306 outb (0xdf, dev.fx_mod_addr);
3307 outb (0x10, dev.fx_mod_data);
3308 if (!wffx_idle()) return (-1);
3309
3310 for (i = 0xe0; i <= 0xef; i++) {
3311 outb (i, dev.fx_mod_addr);
3312 outb (0x00, dev.fx_mod_data);
3313 if (!wffx_idle()) return (-1);
3314 }
3315
3316 for (i = 0x00; i <= 0x0f; i++) {
3317 outb (0x01, dev.fx_mod_addr);
3318 outb (i, dev.fx_mod_data);
3319 outb (0x02, dev.fx_mod_addr);
3320 outb (0x01, dev.fx_mod_data);
3321 if (!wffx_idle()) return (-1);
3322 }
3323
3324 outb (0x02, dev.fx_op); /* mute on */
3325
3326 /* Now set the coefficients and so forth for the programs above */
3327
3328 for (i = 0; i < sizeof (coefficients); i += 4) {
3329 outb (coefficients[i], dev.fx_dsp_page);
3330 outb (coefficients[i+1], dev.fx_dsp_addr);
3331 outb (coefficients[i+2], dev.fx_dsp_msb);
3332 outb (coefficients[i+3], dev.fx_dsp_lsb);
3333 if (!wffx_idle()) return (-1);
3334 }
3335
3336 /* Some settings (?) that are too small to bundle into loops */
3337
3338 if (!wffx_idle()) return (-1);
3339 outb (0x1e, dev.fx_mod_addr);
3340 outb (0x14, dev.fx_mod_data);
3341 if (!wffx_idle()) return (-1);
3342 outb (0xde, dev.fx_mod_addr);
3343 outb (0x20, dev.fx_mod_data);
3344 if (!wffx_idle()) return (-1);
3345 outb (0xdf, dev.fx_mod_addr);
3346 outb (0x20, dev.fx_mod_data);
3347
3348 /* some more coefficients */
3349
3350 if (!wffx_idle()) return (-1);
3351 outb (0x06, dev.fx_dsp_page);
3352 outb (0x78, dev.fx_dsp_addr);
3353 outb (0x00, dev.fx_dsp_msb);
3354 outb (0x40, dev.fx_dsp_lsb);
3355 if (!wffx_idle()) return (-1);
3356 outb (0x07, dev.fx_dsp_page);
3357 outb (0x03, dev.fx_dsp_addr);
3358 outb (0x0f, dev.fx_dsp_msb);
3359 outb (0xff, dev.fx_dsp_lsb);
3360 if (!wffx_idle()) return (-1);
3361 outb (0x07, dev.fx_dsp_page);
3362 outb (0x0b, dev.fx_dsp_addr);
3363 outb (0x0f, dev.fx_dsp_msb);
3364 outb (0xff, dev.fx_dsp_lsb);
3365 if (!wffx_idle()) return (-1);
3366 outb (0x07, dev.fx_dsp_page);
3367 outb (0x02, dev.fx_dsp_addr);
3368 outb (0x00, dev.fx_dsp_msb);
3369 outb (0x00, dev.fx_dsp_lsb);
3370 if (!wffx_idle()) return (-1);
3371 outb (0x07, dev.fx_dsp_page);
3372 outb (0x0a, dev.fx_dsp_addr);
3373 outb (0x00, dev.fx_dsp_msb);
3374 outb (0x00, dev.fx_dsp_lsb);
3375 if (!wffx_idle()) return (-1);
3376 outb (0x07, dev.fx_dsp_page);
3377 outb (0x46, dev.fx_dsp_addr);
3378 outb (0x00, dev.fx_dsp_msb);
3379 outb (0x00, dev.fx_dsp_lsb);
3380 if (!wffx_idle()) return (-1);
3381 outb (0x07, dev.fx_dsp_page);
3382 outb (0x49, dev.fx_dsp_addr);
3383 outb (0x00, dev.fx_dsp_msb);
3384 outb (0x00, dev.fx_dsp_lsb);
3385
3386 /* Now, for some strange reason, lets reload every page
3387 and all the coefficients over again. I have *NO* idea
3388 why this is done. I do know that no sound is produced
3389 is this phase is omitted.
3390 */
3391
3392 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3393 outb (0x00, dev.fx_dsp_page);
3394 outb (0x10, dev.fx_dsp_addr);
3395
3396 for (i = 0; i < sizeof (page_zero_v2); i += 2) {
3397 outb (page_zero_v2[i], dev.fx_dsp_msb);
3398 outb (page_zero_v2[i+1], dev.fx_dsp_lsb);
3399 if (!wffx_idle()) return (-1);
3400 }
3401
3402 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3403 outb (0x01, dev.fx_dsp_page);
3404 outb (0x10, dev.fx_dsp_addr);
3405
3406 for (i = 0; i < sizeof (page_one_v2); i += 2) {
3407 outb (page_one_v2[i], dev.fx_dsp_msb);
3408 outb (page_one_v2[i+1], dev.fx_dsp_lsb);
3409 if (!wffx_idle()) return (-1);
3410 }
3411
3412 if (!wffx_idle()) return (-1);
3413 if (!wffx_idle()) return (-1);
3414
3415 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3416 outb (0x02, dev.fx_dsp_page);
3417 outb (0x10, dev.fx_dsp_addr);
3418
3419 for (i = 0; i < sizeof (page_two_v2); i++) {
3420 outb (page_two_v2[i], dev.fx_dsp_lsb);
3421 if (!wffx_idle()) return (-1);
3422 }
3423 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3424 outb (0x03, dev.fx_dsp_page);
3425 outb (0x10, dev.fx_dsp_addr);
3426
3427 for (i = 0; i < sizeof (page_three_v2); i++) {
3428 outb (page_three_v2[i], dev.fx_dsp_lsb);
3429 if (!wffx_idle()) return (-1);
3430 }
3431
3432 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3433 outb (0x04, dev.fx_dsp_page);
3434 outb (0x10, dev.fx_dsp_addr);
3435
3436 for (i = 0; i < sizeof (page_four_v2); i++) {
3437 outb (page_four_v2[i], dev.fx_dsp_lsb);
3438 if (!wffx_idle()) return (-1);
3439 }
3440
3441 outb (FX_LSB_TRANSFER, dev.fx_lcr);
3442 outb (0x06, dev.fx_dsp_page);
3443
3444 /* Page six v.2 is algorithmic */
3445
3446 for (i = 0x10; i <= 0x3e; i += 2) {
3447 outb (i, dev.fx_dsp_addr);
3448 outb (0x00, dev.fx_dsp_msb);
3449 outb (0x00, dev.fx_dsp_lsb);
3450 if (!wffx_idle()) return (-1);
3451 }
3452
3453 outb (FX_AUTO_INCR|FX_LSB_TRANSFER, dev.fx_lcr);
3454 outb (0x07, dev.fx_dsp_page);
3455 outb (0x10, dev.fx_dsp_addr);
3456
3457 for (i = 0; i < sizeof (page_seven_v2); i += 2) {
3458 outb (page_seven_v2[i], dev.fx_dsp_msb);
3459 outb (page_seven_v2[i+1], dev.fx_dsp_lsb);
3460 if (!wffx_idle()) return (-1);
3461 }
3462
3463 for (i = 0x00; i < sizeof(mod_v2); i += 2) {
3464 outb (mod_v2[i], dev.fx_mod_addr);
3465 outb (mod_v2[i+1], dev.fx_mod_data);
3466 if (!wffx_idle()) return (-1);
3467 }
3468
3469 for (i = 0; i < sizeof (coefficients2); i += 4) {
3470 outb (coefficients2[i], dev.fx_dsp_page);
3471 outb (coefficients2[i+1], dev.fx_dsp_addr);
3472 outb (coefficients2[i+2], dev.fx_dsp_msb);
3473 outb (coefficients2[i+3], dev.fx_dsp_lsb);
3474 if (!wffx_idle()) return (-1);
3475 }
3476
3477 for (i = 0; i < sizeof (coefficients3); i += 2) {
3478 int x;
3479
3480 outb (0x07, dev.fx_dsp_page);
3481 x = (i % 4) ? 0x4e : 0x4c;
3482 outb (x, dev.fx_dsp_addr);
3483 outb (coefficients3[i], dev.fx_dsp_msb);
3484 outb (coefficients3[i+1], dev.fx_dsp_lsb);
3485 }
3486
3487 outb (0x00, dev.fx_op); /* mute off */
3488 if (!wffx_idle()) return (-1);
3489
3490 return (0);
3491}
3492
3493static int io = -1;
3494static int irq = -1;
3495
3496MODULE_AUTHOR ("Paul Barton-Davis <pbd@op.net>");
3497MODULE_DESCRIPTION ("Turtle Beach WaveFront Linux Driver");
3498MODULE_LICENSE("GPL");
3499module_param (io, int, 0);
3500module_param (irq, int, 0);
3501
3502static int __init init_wavfront (void)
3503{
3504 printk ("Turtle Beach WaveFront Driver\n"
3505 "Copyright (C) by Hannu Solvainen, "
3506 "Paul Barton-Davis 1993-1998.\n");
3507
3508 /* XXX t'would be lovely to ask the CS4232 for these values, eh ? */
3509
3510 if (io == -1 || irq == -1) {
3511 printk (KERN_INFO LOGNAME "irq and io options must be set.\n");
3512 return -EINVAL;
3513 }
3514
3515 if (wavefront_interrupt_bits (irq) < 0) {
3516 printk (KERN_INFO LOGNAME
3517 "IRQ must be 9, 5, 12 or 15 (not %d)\n", irq);
3518 return -ENODEV;
3519 }
3520
3521 if (detect_wavefront (irq, io) < 0) {
3522 return -ENODEV;
3523 }
3524
3525 if (install_wavefront () < 0) {
3526 return -EIO;
3527 }
3528
3529 return 0;
3530}
3531
3532static void __exit cleanup_wavfront (void)
3533{
3534 uninstall_wavefront ();
3535}
3536
3537module_init(init_wavfront);
3538module_exit(cleanup_wavfront);
diff --git a/sound/oss/wf_midi.c b/sound/oss/wf_midi.c
new file mode 100644
index 000000000000..7b167b74375b
--- /dev/null
+++ b/sound/oss/wf_midi.c
@@ -0,0 +1,880 @@
1/*
2 * sound/wf_midi.c
3 *
4 * The low level driver for the WaveFront ICS2115 MIDI interface(s)
5 * Note that there is also an MPU-401 emulation (actually, a UART-401
6 * emulation) on the CS4232 on the Tropez Plus. This code has nothing
7 * to do with that interface at all.
8 *
9 * The interface is essentially just a UART-401, but is has the
10 * interesting property of supporting what Turtle Beach called
11 * "Virtual MIDI" mode. In this mode, there are effectively *two*
12 * MIDI buses accessible via the interface, one that is routed
13 * solely to/from the external WaveFront synthesizer and the other
14 * corresponding to the pin/socket connector used to link external
15 * MIDI devices to the board.
16 *
17 * This driver fully supports this mode, allowing two distinct
18 * midi devices (/dev/midiNN and /dev/midiNN+1) to be used
19 * completely independently, giving 32 channels of MIDI routing,
20 * 16 to the WaveFront synth and 16 to the external MIDI bus.
21 *
22 * Switching between the two is accomplished externally by the driver
23 * using the two otherwise unused MIDI bytes. See the code for more details.
24 *
25 * NOTE: VIRTUAL MIDI MODE IS ON BY DEFAULT (see wavefront.c)
26 *
27 * The main reason to turn off Virtual MIDI mode is when you want to
28 * tightly couple the WaveFront synth with an external MIDI
29 * device. You won't be able to distinguish the source of any MIDI
30 * data except via SysEx ID, but thats probably OK, since for the most
31 * part, the WaveFront won't be sending any MIDI data at all.
32 *
33 * The main reason to turn on Virtual MIDI Mode is to provide two
34 * completely independent 16-channel MIDI buses, one to the
35 * WaveFront and one to any external MIDI devices. Given the 32
36 * voice nature of the WaveFront, its pretty easy to find a use
37 * for all 16 channels driving just that synth.
38 *
39 */
40
41/*
42 * Copyright (C) by Paul Barton-Davis 1998
43 * Some portions of this file are derived from work that is:
44 *
45 * CopyriGht (C) by Hannu Savolainen 1993-1996
46 *
47 * USS/Lite for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
48 * Version 2 (June 1991). See the "COPYING" file distributed with this software
49 * for more info.
50 */
51
52#include <linux/init.h>
53#include <linux/interrupt.h>
54#include <linux/spinlock.h>
55#include "sound_config.h"
56
57#include <linux/wavefront.h>
58
59#ifdef MODULE
60
61struct wf_mpu_config {
62 int base;
63#define DATAPORT(d) (d)->base
64#define COMDPORT(d) (d)->base+1
65#define STATPORT(d) (d)->base+1
66
67 int irq;
68 int opened;
69 int devno;
70 int synthno;
71 int mode;
72#define MODE_MIDI 1
73#define MODE_SYNTH 2
74
75 void (*inputintr) (int dev, unsigned char data);
76 char isvirtual; /* do virtual I/O stuff */
77};
78
79static struct wf_mpu_config devs[2];
80static struct wf_mpu_config *phys_dev = &devs[0];
81static struct wf_mpu_config *virt_dev = &devs[1];
82
83static void start_uart_mode (void);
84static DEFINE_SPINLOCK(lock);
85
86#define OUTPUT_READY 0x40
87#define INPUT_AVAIL 0x80
88#define MPU_ACK 0xFE
89#define UART_MODE_ON 0x3F
90
91static inline int wf_mpu_status (void)
92{
93 return inb (STATPORT (phys_dev));
94}
95
96static inline int input_avail (void)
97{
98 return !(wf_mpu_status() & INPUT_AVAIL);
99}
100
101static inline int output_ready (void)
102{
103 return !(wf_mpu_status() & OUTPUT_READY);
104}
105
106static inline int read_data (void)
107{
108 return inb (DATAPORT (phys_dev));
109}
110
111static inline void write_data (unsigned char byte)
112{
113 outb (byte, DATAPORT (phys_dev));
114}
115
116/*
117 * States for the input scanner (should be in dev_table.h)
118 */
119
120#define MST_SYSMSG 100 /* System message (sysx etc). */
121#define MST_MTC 102 /* Midi Time Code (MTC) qframe msg */
122#define MST_SONGSEL 103 /* Song select */
123#define MST_SONGPOS 104 /* Song position pointer */
124#define MST_TIMED 105 /* Leading timing byte rcvd */
125
126/* buffer space check for input scanner */
127
128#define BUFTEST(mi) if (mi->m_ptr >= MI_MAX || mi->m_ptr < 0) \
129{printk(KERN_ERR "WF-MPU: Invalid buffer pointer %d/%d, s=%d\n", \
130 mi->m_ptr, mi->m_left, mi->m_state);mi->m_ptr--;}
131
132static unsigned char len_tab[] = /* # of data bytes following a status
133 */
134{
135 2, /* 8x */
136 2, /* 9x */
137 2, /* Ax */
138 2, /* Bx */
139 1, /* Cx */
140 1, /* Dx */
141 2, /* Ex */
142 0 /* Fx */
143};
144
145static int
146wf_mpu_input_scanner (int devno, int synthdev, unsigned char midic)
147
148{
149 struct midi_input_info *mi = &midi_devs[devno]->in_info;
150
151 switch (mi->m_state) {
152 case MST_INIT:
153 switch (midic) {
154 case 0xf8:
155 /* Timer overflow */
156 break;
157
158 case 0xfc:
159 break;
160
161 case 0xfd:
162 /* XXX do something useful with this. If there is
163 an external MIDI timer (e.g. a hardware sequencer,
164 a useful timer can be derived ...
165
166 For now, no timer support.
167 */
168 break;
169
170 case 0xfe:
171 return MPU_ACK;
172 break;
173
174 case 0xf0:
175 case 0xf1:
176 case 0xf2:
177 case 0xf3:
178 case 0xf4:
179 case 0xf5:
180 case 0xf6:
181 case 0xf7:
182 break;
183
184 case 0xf9:
185 break;
186
187 case 0xff:
188 mi->m_state = MST_SYSMSG;
189 break;
190
191 default:
192 if (midic <= 0xef) {
193 mi->m_state = MST_TIMED;
194 }
195 else
196 printk (KERN_ERR "<MPU: Unknown event %02x> ",
197 midic);
198 }
199 break;
200
201 case MST_TIMED:
202 {
203 int msg = ((int) (midic & 0xf0) >> 4);
204
205 mi->m_state = MST_DATA;
206
207 if (msg < 8) { /* Data byte */
208
209 msg = ((int) (mi->m_prev_status & 0xf0) >> 4);
210 msg -= 8;
211 mi->m_left = len_tab[msg] - 1;
212
213 mi->m_ptr = 2;
214 mi->m_buf[0] = mi->m_prev_status;
215 mi->m_buf[1] = midic;
216
217 if (mi->m_left <= 0) {
218 mi->m_state = MST_INIT;
219 do_midi_msg (synthdev, mi->m_buf, mi->m_ptr);
220 mi->m_ptr = 0;
221 }
222 } else if (msg == 0xf) { /* MPU MARK */
223
224 mi->m_state = MST_INIT;
225
226 switch (midic) {
227 case 0xf8:
228 break;
229
230 case 0xf9:
231 break;
232
233 case 0xfc:
234 break;
235
236 default:
237 break;
238 }
239 } else {
240 mi->m_prev_status = midic;
241 msg -= 8;
242 mi->m_left = len_tab[msg];
243
244 mi->m_ptr = 1;
245 mi->m_buf[0] = midic;
246
247 if (mi->m_left <= 0) {
248 mi->m_state = MST_INIT;
249 do_midi_msg (synthdev, mi->m_buf, mi->m_ptr);
250 mi->m_ptr = 0;
251 }
252 }
253 }
254 break;
255
256 case MST_SYSMSG:
257 switch (midic) {
258 case 0xf0:
259 mi->m_state = MST_SYSEX;
260 break;
261
262 case 0xf1:
263 mi->m_state = MST_MTC;
264 break;
265
266 case 0xf2:
267 mi->m_state = MST_SONGPOS;
268 mi->m_ptr = 0;
269 break;
270
271 case 0xf3:
272 mi->m_state = MST_SONGSEL;
273 break;
274
275 case 0xf6:
276 mi->m_state = MST_INIT;
277
278 /*
279 * Real time messages
280 */
281 case 0xf8:
282 /* midi clock */
283 mi->m_state = MST_INIT;
284 /* XXX need ext MIDI timer support */
285 break;
286
287 case 0xfA:
288 mi->m_state = MST_INIT;
289 /* XXX need ext MIDI timer support */
290 break;
291
292 case 0xFB:
293 mi->m_state = MST_INIT;
294 /* XXX need ext MIDI timer support */
295 break;
296
297 case 0xFC:
298 mi->m_state = MST_INIT;
299 /* XXX need ext MIDI timer support */
300 break;
301
302 case 0xFE:
303 /* active sensing */
304 mi->m_state = MST_INIT;
305 break;
306
307 case 0xff:
308 mi->m_state = MST_INIT;
309 break;
310
311 default:
312 printk (KERN_ERR "unknown MIDI sysmsg %0x\n", midic);
313 mi->m_state = MST_INIT;
314 }
315 break;
316
317 case MST_MTC:
318 mi->m_state = MST_INIT;
319 break;
320
321 case MST_SYSEX:
322 if (midic == 0xf7) {
323 mi->m_state = MST_INIT;
324 } else {
325 /* XXX fix me */
326 }
327 break;
328
329 case MST_SONGPOS:
330 BUFTEST (mi);
331 mi->m_buf[mi->m_ptr++] = midic;
332 if (mi->m_ptr == 2) {
333 mi->m_state = MST_INIT;
334 mi->m_ptr = 0;
335 /* XXX need ext MIDI timer support */
336 }
337 break;
338
339 case MST_DATA:
340 BUFTEST (mi);
341 mi->m_buf[mi->m_ptr++] = midic;
342 if ((--mi->m_left) <= 0) {
343 mi->m_state = MST_INIT;
344 do_midi_msg (synthdev, mi->m_buf, mi->m_ptr);
345 mi->m_ptr = 0;
346 }
347 break;
348
349 default:
350 printk (KERN_ERR "Bad state %d ", mi->m_state);
351 mi->m_state = MST_INIT;
352 }
353
354 return 1;
355}
356
357static irqreturn_t
358wf_mpuintr(int irq, void *dev_id, struct pt_regs *dummy)
359
360{
361 struct wf_mpu_config *physical_dev = dev_id;
362 static struct wf_mpu_config *input_dev;
363 struct midi_input_info *mi = &midi_devs[physical_dev->devno]->in_info;
364 int n;
365
366 if (!input_avail()) { /* not for us */
367 return IRQ_NONE;
368 }
369
370 if (mi->m_busy)
371 return IRQ_HANDLED;
372 spin_lock(&lock);
373 mi->m_busy = 1;
374
375 if (!input_dev) {
376 input_dev = physical_dev;
377 }
378
379 n = 50; /* XXX why ? */
380
381 do {
382 unsigned char c = read_data ();
383
384 if (phys_dev->isvirtual) {
385
386 if (c == WF_EXTERNAL_SWITCH) {
387 input_dev = virt_dev;
388 continue;
389 } else if (c == WF_INTERNAL_SWITCH) {
390 input_dev = phys_dev;
391 continue;
392 } /* else just leave it as it is */
393
394 } else {
395 input_dev = phys_dev;
396 }
397
398 if (input_dev->mode == MODE_SYNTH) {
399
400 wf_mpu_input_scanner (input_dev->devno,
401 input_dev->synthno, c);
402
403 } else if (input_dev->opened & OPEN_READ) {
404
405 if (input_dev->inputintr) {
406 input_dev->inputintr (input_dev->devno, c);
407 }
408 }
409
410 } while (input_avail() && n-- > 0);
411
412 mi->m_busy = 0;
413 spin_unlock(&lock);
414 return IRQ_HANDLED;
415}
416
417static int
418wf_mpu_open (int dev, int mode,
419 void (*input) (int dev, unsigned char data),
420 void (*output) (int dev)
421 )
422{
423 struct wf_mpu_config *devc;
424
425 if (dev < 0 || dev >= num_midis || midi_devs[dev]==NULL)
426 return -(ENXIO);
427
428 if (phys_dev->devno == dev) {
429 devc = phys_dev;
430 } else if (phys_dev->isvirtual && virt_dev->devno == dev) {
431 devc = virt_dev;
432 } else {
433 printk (KERN_ERR "WF-MPU: unknown device number %d\n", dev);
434 return -(EINVAL);
435 }
436
437 if (devc->opened) {
438 return -(EBUSY);
439 }
440
441 devc->mode = MODE_MIDI;
442 devc->opened = mode;
443 devc->synthno = 0;
444
445 devc->inputintr = input;
446 return 0;
447}
448
449static void
450wf_mpu_close (int dev)
451{
452 struct wf_mpu_config *devc;
453
454 if (dev < 0 || dev >= num_midis || midi_devs[dev]==NULL)
455 return;
456
457 if (phys_dev->devno == dev) {
458 devc = phys_dev;
459 } else if (phys_dev->isvirtual && virt_dev->devno == dev) {
460 devc = virt_dev;
461 } else {
462 printk (KERN_ERR "WF-MPU: unknown device number %d\n", dev);
463 return;
464 }
465
466 devc->mode = 0;
467 devc->inputintr = NULL;
468 devc->opened = 0;
469}
470
471static int
472wf_mpu_out (int dev, unsigned char midi_byte)
473{
474 int timeout;
475 unsigned long flags;
476 static int lastoutdev = -1;
477 unsigned char switchch;
478
479 if (phys_dev->isvirtual && lastoutdev != dev) {
480
481 if (dev == phys_dev->devno) {
482 switchch = WF_INTERNAL_SWITCH;
483 } else if (dev == virt_dev->devno) {
484 switchch = WF_EXTERNAL_SWITCH;
485 } else {
486 printk (KERN_ERR "WF-MPU: bad device number %d", dev);
487 return (0);
488 }
489
490 /* XXX fix me */
491
492 for (timeout = 30000; timeout > 0 && !output_ready ();
493 timeout--);
494
495 spin_lock_irqsave(&lock,flags);
496
497 if (!output_ready ()) {
498 printk (KERN_WARNING "WF-MPU: Send switch "
499 "byte timeout\n");
500 spin_unlock_irqrestore(&lock,flags);
501 return 0;
502 }
503
504 write_data (switchch);
505 spin_unlock_irqrestore(&lock,flags);
506 }
507
508 lastoutdev = dev;
509
510 /*
511 * Sometimes it takes about 30000 loops before the output becomes ready
512 * (After reset). Normally it takes just about 10 loops.
513 */
514
515 /* XXX fix me */
516
517 for (timeout = 30000; timeout > 0 && !output_ready (); timeout--);
518
519 spin_lock_irqsave(&lock,flags);
520 if (!output_ready ()) {
521 spin_unlock_irqrestore(&lock,flags);
522 printk (KERN_WARNING "WF-MPU: Send data timeout\n");
523 return 0;
524 }
525
526 write_data (midi_byte);
527 spin_unlock_irqrestore(&lock,flags);
528
529 return 1;
530}
531
532static inline int wf_mpu_start_read (int dev) {
533 return 0;
534}
535
536static inline int wf_mpu_end_read (int dev) {
537 return 0;
538}
539
540static int wf_mpu_ioctl (int dev, unsigned cmd, void __user *arg)
541{
542 printk (KERN_WARNING
543 "WF-MPU: Intelligent mode not supported by hardware.\n");
544 return -(EINVAL);
545}
546
547static int wf_mpu_buffer_status (int dev)
548{
549 return 0;
550}
551
552static struct synth_operations wf_mpu_synth_operations[2];
553static struct midi_operations wf_mpu_midi_operations[2];
554
555static struct midi_operations wf_mpu_midi_proto =
556{
557 .owner = THIS_MODULE,
558 .info = {"WF-MPU MIDI", 0, MIDI_CAP_MPU401, SNDCARD_MPU401},
559 .in_info = {0}, /* in_info */
560 .open = wf_mpu_open,
561 .close = wf_mpu_close,
562 .ioctl = wf_mpu_ioctl,
563 .outputc = wf_mpu_out,
564 .start_read = wf_mpu_start_read,
565 .end_read = wf_mpu_end_read,
566 .buffer_status = wf_mpu_buffer_status,
567};
568
569static struct synth_info wf_mpu_synth_info_proto =
570{"WaveFront MPU-401 interface", 0,
571 SYNTH_TYPE_MIDI, MIDI_TYPE_MPU401, 0, 128, 0, 128, SYNTH_CAP_INPUT};
572
573static struct synth_info wf_mpu_synth_info[2];
574
575static int
576wf_mpu_synth_ioctl (int dev, unsigned int cmd, void __user *arg)
577{
578 int midi_dev;
579 int index;
580
581 midi_dev = synth_devs[dev]->midi_dev;
582
583 if (midi_dev < 0 || midi_dev > num_midis || midi_devs[midi_dev]==NULL)
584 return -(ENXIO);
585
586 if (midi_dev == phys_dev->devno) {
587 index = 0;
588 } else if (phys_dev->isvirtual && midi_dev == virt_dev->devno) {
589 index = 1;
590 } else {
591 return -(EINVAL);
592 }
593
594 switch (cmd) {
595
596 case SNDCTL_SYNTH_INFO:
597 if (copy_to_user(arg,
598 &wf_mpu_synth_info[index],
599 sizeof (struct synth_info)))
600 return -EFAULT;
601 return 0;
602
603 case SNDCTL_SYNTH_MEMAVL:
604 return 0x7fffffff;
605
606 default:
607 return -EINVAL;
608 }
609}
610
611static int
612wf_mpu_synth_open (int dev, int mode)
613{
614 int midi_dev;
615 struct wf_mpu_config *devc;
616
617 midi_dev = synth_devs[dev]->midi_dev;
618
619 if (midi_dev < 0 || midi_dev > num_midis || midi_devs[midi_dev]==NULL) {
620 return -(ENXIO);
621 }
622
623 if (phys_dev->devno == midi_dev) {
624 devc = phys_dev;
625 } else if (phys_dev->isvirtual && virt_dev->devno == midi_dev) {
626 devc = virt_dev;
627 } else {
628 printk (KERN_ERR "WF-MPU: unknown device number %d\n", dev);
629 return -(EINVAL);
630 }
631
632 if (devc->opened) {
633 return -(EBUSY);
634 }
635
636 devc->mode = MODE_SYNTH;
637 devc->synthno = dev;
638 devc->opened = mode;
639 devc->inputintr = NULL;
640 return 0;
641}
642
643static void
644wf_mpu_synth_close (int dev)
645{
646 int midi_dev;
647 struct wf_mpu_config *devc;
648
649 midi_dev = synth_devs[dev]->midi_dev;
650
651 if (phys_dev->devno == midi_dev) {
652 devc = phys_dev;
653 } else if (phys_dev->isvirtual && virt_dev->devno == midi_dev) {
654 devc = virt_dev;
655 } else {
656 printk (KERN_ERR "WF-MPU: unknown device number %d\n", dev);
657 return;
658 }
659
660 devc->inputintr = NULL;
661 devc->opened = 0;
662 devc->mode = 0;
663}
664
665#define _MIDI_SYNTH_C_
666#define MIDI_SYNTH_NAME "WaveFront (MIDI)"
667#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
668#include "midi_synth.h"
669
670static struct synth_operations wf_mpu_synth_proto =
671{
672 .owner = THIS_MODULE,
673 .id = "WaveFront (ICS2115)",
674 .info = NULL, /* info field, filled in during configuration */
675 .midi_dev = 0, /* MIDI dev XXX should this be -1 ? */
676 .synth_type = SYNTH_TYPE_MIDI,
677 .synth_subtype = SAMPLE_TYPE_WAVEFRONT,
678 .open = wf_mpu_synth_open,
679 .close = wf_mpu_synth_close,
680 .ioctl = wf_mpu_synth_ioctl,
681 .kill_note = midi_synth_kill_note,
682 .start_note = midi_synth_start_note,
683 .set_instr = midi_synth_set_instr,
684 .reset = midi_synth_reset,
685 .hw_control = midi_synth_hw_control,
686 .load_patch = midi_synth_load_patch,
687 .aftertouch = midi_synth_aftertouch,
688 .controller = midi_synth_controller,
689 .panning = midi_synth_panning,
690 .bender = midi_synth_bender,
691 .setup_voice = midi_synth_setup_voice,
692 .send_sysex = midi_synth_send_sysex
693};
694
695static int
696config_wf_mpu (struct wf_mpu_config *dev)
697
698{
699 int is_external;
700 char *name;
701 int index;
702
703 if (dev == phys_dev) {
704 name = "WaveFront internal MIDI";
705 is_external = 0;
706 index = 0;
707 memcpy ((char *) &wf_mpu_synth_operations[index],
708 (char *) &wf_mpu_synth_proto,
709 sizeof (struct synth_operations));
710 } else {
711 name = "WaveFront external MIDI";
712 is_external = 1;
713 index = 1;
714 /* no synth operations for an external MIDI interface */
715 }
716
717 memcpy ((char *) &wf_mpu_synth_info[dev->devno],
718 (char *) &wf_mpu_synth_info_proto,
719 sizeof (struct synth_info));
720
721 strcpy (wf_mpu_synth_info[index].name, name);
722
723 wf_mpu_synth_operations[index].midi_dev = dev->devno;
724 wf_mpu_synth_operations[index].info = &wf_mpu_synth_info[index];
725
726 memcpy ((char *) &wf_mpu_midi_operations[index],
727 (char *) &wf_mpu_midi_proto,
728 sizeof (struct midi_operations));
729
730 if (is_external) {
731 wf_mpu_midi_operations[index].converter = NULL;
732 } else {
733 wf_mpu_midi_operations[index].converter =
734 &wf_mpu_synth_operations[index];
735 }
736
737 strcpy (wf_mpu_midi_operations[index].info.name, name);
738
739 midi_devs[dev->devno] = &wf_mpu_midi_operations[index];
740 midi_devs[dev->devno]->in_info.m_busy = 0;
741 midi_devs[dev->devno]->in_info.m_state = MST_INIT;
742 midi_devs[dev->devno]->in_info.m_ptr = 0;
743 midi_devs[dev->devno]->in_info.m_left = 0;
744 midi_devs[dev->devno]->in_info.m_prev_status = 0;
745
746 devs[index].opened = 0;
747 devs[index].mode = 0;
748
749 return (0);
750}
751
752int virtual_midi_enable (void)
753
754{
755 if ((virt_dev->devno < 0) &&
756 (virt_dev->devno = sound_alloc_mididev()) == -1) {
757 printk (KERN_ERR
758 "WF-MPU: too many midi devices detected\n");
759 return -1;
760 }
761
762 config_wf_mpu (virt_dev);
763
764 phys_dev->isvirtual = 1;
765 return virt_dev->devno;
766}
767
768int
769virtual_midi_disable (void)
770
771{
772 unsigned long flags;
773
774 spin_lock_irqsave(&lock,flags);
775
776 wf_mpu_close (virt_dev->devno);
777 /* no synth on virt_dev, so no need to call wf_mpu_synth_close() */
778 phys_dev->isvirtual = 0;
779
780 spin_unlock_irqrestore(&lock,flags);
781
782 return 0;
783}
784
785int __init detect_wf_mpu (int irq, int io_base)
786{
787 if (!request_region(io_base, 2, "wavefront midi")) {
788 printk (KERN_WARNING "WF-MPU: I/O port %x already in use.\n",
789 io_base);
790 return -1;
791 }
792
793 phys_dev->base = io_base;
794 phys_dev->irq = irq;
795 phys_dev->devno = -1;
796 virt_dev->devno = -1;
797
798 return 0;
799}
800
801int __init install_wf_mpu (void)
802{
803 if ((phys_dev->devno = sound_alloc_mididev()) < 0){
804
805 printk (KERN_ERR "WF-MPU: Too many MIDI devices detected.\n");
806 release_region(phys_dev->base, 2);
807 return -1;
808 }
809
810 phys_dev->isvirtual = 0;
811
812 if (config_wf_mpu (phys_dev)) {
813
814 printk (KERN_WARNING
815 "WF-MPU: configuration for MIDI device %d failed\n",
816 phys_dev->devno);
817 sound_unload_mididev (phys_dev->devno);
818
819 }
820
821 /* OK, now we're configured to handle an interrupt ... */
822
823 if (request_irq (phys_dev->irq, wf_mpuintr, SA_INTERRUPT|SA_SHIRQ,
824 "wavefront midi", phys_dev) < 0) {
825
826 printk (KERN_ERR "WF-MPU: Failed to allocate IRQ%d\n",
827 phys_dev->irq);
828 return -1;
829
830 }
831
832 /* This being a WaveFront (ICS-2115) emulated MPU-401, we have
833 to switch it into UART (dumb) mode, because otherwise, it
834 won't do anything at all.
835 */
836
837 start_uart_mode ();
838
839 return phys_dev->devno;
840}
841
842void
843uninstall_wf_mpu (void)
844
845{
846 release_region (phys_dev->base, 2);
847 free_irq (phys_dev->irq, phys_dev);
848 sound_unload_mididev (phys_dev->devno);
849
850 if (virt_dev->devno >= 0) {
851 sound_unload_mididev (virt_dev->devno);
852 }
853}
854
855static void
856start_uart_mode (void)
857
858{
859 int ok, i;
860 unsigned long flags;
861
862 spin_lock_irqsave(&lock,flags);
863
864 /* XXX fix me */
865
866 for (i = 0; i < 30000 && !output_ready (); i++);
867
868 outb (UART_MODE_ON, COMDPORT(phys_dev));
869
870 for (ok = 0, i = 50000; i > 0 && !ok; i--) {
871 if (input_avail ()) {
872 if (read_data () == MPU_ACK) {
873 ok = 1;
874 }
875 }
876 }
877
878 spin_unlock_irqrestore(&lock,flags);
879}
880#endif
diff --git a/sound/oss/ymfpci.c b/sound/oss/ymfpci.c
new file mode 100644
index 000000000000..05203ad523f7
--- /dev/null
+++ b/sound/oss/ymfpci.c
@@ -0,0 +1,2691 @@
1/*
2 * Copyright 1999 Jaroslav Kysela <perex@suse.cz>
3 * Copyright 2000 Alan Cox <alan@redhat.com>
4 * Copyright 2001 Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
5 * Copyright 2002 Pete Zaitcev <zaitcev@yahoo.com>
6 *
7 * Yamaha YMF7xx driver.
8 *
9 * This code is a result of high-speed collision
10 * between ymfpci.c of ALSA and cs46xx.c of Linux.
11 * -- Pete Zaitcev <zaitcev@yahoo.com>; 2000/09/18
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 * TODO:
28 * - Use P44Slot for 44.1 playback (beware of idle buzzing in P44Slot).
29 * - 96KHz playback for DVD - use pitch of 2.0.
30 * - Retain DMA buffer on close, do not wait the end of frame.
31 * - Resolve XXX tagged questions.
32 * - Cannot play 5133Hz.
33 * - 2001/01/07 Consider if we can remove voice_lock, like so:
34 * : Allocate/deallocate voices in open/close under semafore.
35 * : We access voices in interrupt, that only for pcms that open.
36 * voice_lock around playback_prepare closes interrupts for insane duration.
37 * - Revisit the way voice_alloc is done - too confusing, overcomplicated.
38 * Should support various channel types, however.
39 * - Remove prog_dmabuf from read/write, leave it in open.
40 * - 2001/01/07 Replace the OPL3 part of CONFIG_SOUND_YMFPCI_LEGACY code with
41 * native synthesizer through a playback slot.
42 * - 2001/11/29 ac97_save_state
43 * Talk to Kai to remove ac97_save_state before it's too late!
44 * - Second AC97
45 * - Restore S/PDIF - Toshibas have it.
46 *
47 * Kai used pci_alloc_consistent for DMA buffer, which sounds a little
48 * unconventional. However, given how small our fragments can be,
49 * a little uncached access is perhaps better than endless flushing.
50 * On i386 and other I/O-coherent architectures pci_alloc_consistent
51 * is entirely harmless.
52 */
53
54#include <linux/config.h>
55#include <linux/module.h>
56#include <linux/init.h>
57#include <linux/interrupt.h>
58#include <linux/ioport.h>
59#include <linux/delay.h>
60#include <linux/pci.h>
61#include <linux/slab.h>
62#include <linux/poll.h>
63#include <linux/soundcard.h>
64#include <linux/ac97_codec.h>
65#include <linux/sound.h>
66
67#include <asm/io.h>
68#include <asm/dma.h>
69#include <asm/uaccess.h>
70
71#ifdef CONFIG_SOUND_YMFPCI_LEGACY
72# include "sound_config.h"
73# include "mpu401.h"
74#endif
75#include "ymfpci.h"
76
77/*
78 * I do not believe in debug levels as I never can guess what
79 * part of the code is going to be problematic in the future.
80 * Don't forget to run your klogd with -c 8.
81 *
82 * Example (do not remove):
83 * #define YMFDBG(fmt, arg...) do{ printk(KERN_DEBUG fmt, ##arg); }while(0)
84 */
85#define YMFDBGW(fmt, arg...) /* */ /* write counts */
86#define YMFDBGI(fmt, arg...) /* */ /* interrupts */
87#define YMFDBGX(fmt, arg...) /* */ /* ioctl */
88
89static int ymf_playback_trigger(ymfpci_t *unit, struct ymf_pcm *ypcm, int cmd);
90static void ymf_capture_trigger(ymfpci_t *unit, struct ymf_pcm *ypcm, int cmd);
91static void ymfpci_voice_free(ymfpci_t *unit, ymfpci_voice_t *pvoice);
92static int ymf_capture_alloc(struct ymf_unit *unit, int *pbank);
93static int ymf_playback_prepare(struct ymf_state *state);
94static int ymf_capture_prepare(struct ymf_state *state);
95static struct ymf_state *ymf_state_alloc(ymfpci_t *unit);
96
97static void ymfpci_aclink_reset(struct pci_dev * pci);
98static void ymfpci_disable_dsp(ymfpci_t *unit);
99static void ymfpci_download_image(ymfpci_t *codec);
100static void ymf_memload(ymfpci_t *unit);
101
102static DEFINE_SPINLOCK(ymf_devs_lock);
103static LIST_HEAD(ymf_devs);
104
105/*
106 * constants
107 */
108
109static struct pci_device_id ymf_id_tbl[] = {
110#define DEV(v, d, data) \
111 { PCI_VENDOR_ID_##v, PCI_DEVICE_ID_##v##_##d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long)data }
112 DEV (YAMAHA, 724, "YMF724"),
113 DEV (YAMAHA, 724F, "YMF724F"),
114 DEV (YAMAHA, 740, "YMF740"),
115 DEV (YAMAHA, 740C, "YMF740C"),
116 DEV (YAMAHA, 744, "YMF744"),
117 DEV (YAMAHA, 754, "YMF754"),
118#undef DEV
119 { }
120};
121MODULE_DEVICE_TABLE(pci, ymf_id_tbl);
122
123/*
124 * common I/O routines
125 */
126
127static inline void ymfpci_writeb(ymfpci_t *codec, u32 offset, u8 val)
128{
129 writeb(val, codec->reg_area_virt + offset);
130}
131
132static inline u16 ymfpci_readw(ymfpci_t *codec, u32 offset)
133{
134 return readw(codec->reg_area_virt + offset);
135}
136
137static inline void ymfpci_writew(ymfpci_t *codec, u32 offset, u16 val)
138{
139 writew(val, codec->reg_area_virt + offset);
140}
141
142static inline u32 ymfpci_readl(ymfpci_t *codec, u32 offset)
143{
144 return readl(codec->reg_area_virt + offset);
145}
146
147static inline void ymfpci_writel(ymfpci_t *codec, u32 offset, u32 val)
148{
149 writel(val, codec->reg_area_virt + offset);
150}
151
152static int ymfpci_codec_ready(ymfpci_t *codec, int secondary, int sched)
153{
154 signed long end_time;
155 u32 reg = secondary ? YDSXGR_SECSTATUSADR : YDSXGR_PRISTATUSADR;
156
157 end_time = jiffies + 3 * (HZ / 4);
158 do {
159 if ((ymfpci_readw(codec, reg) & 0x8000) == 0)
160 return 0;
161 if (sched) {
162 set_current_state(TASK_UNINTERRUPTIBLE);
163 schedule_timeout(1);
164 }
165 } while (end_time - (signed long)jiffies >= 0);
166 printk(KERN_ERR "ymfpci_codec_ready: codec %i is not ready [0x%x]\n",
167 secondary, ymfpci_readw(codec, reg));
168 return -EBUSY;
169}
170
171static void ymfpci_codec_write(struct ac97_codec *dev, u8 reg, u16 val)
172{
173 ymfpci_t *codec = dev->private_data;
174 u32 cmd;
175
176 spin_lock(&codec->ac97_lock);
177 /* XXX Do make use of dev->id */
178 ymfpci_codec_ready(codec, 0, 0);
179 cmd = ((YDSXG_AC97WRITECMD | reg) << 16) | val;
180 ymfpci_writel(codec, YDSXGR_AC97CMDDATA, cmd);
181 spin_unlock(&codec->ac97_lock);
182}
183
184static u16 _ymfpci_codec_read(ymfpci_t *unit, u8 reg)
185{
186 int i;
187
188 if (ymfpci_codec_ready(unit, 0, 0))
189 return ~0;
190 ymfpci_writew(unit, YDSXGR_AC97CMDADR, YDSXG_AC97READCMD | reg);
191 if (ymfpci_codec_ready(unit, 0, 0))
192 return ~0;
193 if (unit->pci->device == PCI_DEVICE_ID_YAMAHA_744 && unit->rev < 2) {
194 for (i = 0; i < 600; i++)
195 ymfpci_readw(unit, YDSXGR_PRISTATUSDATA);
196 }
197 return ymfpci_readw(unit, YDSXGR_PRISTATUSDATA);
198}
199
200static u16 ymfpci_codec_read(struct ac97_codec *dev, u8 reg)
201{
202 ymfpci_t *unit = dev->private_data;
203 u16 ret;
204
205 spin_lock(&unit->ac97_lock);
206 ret = _ymfpci_codec_read(unit, reg);
207 spin_unlock(&unit->ac97_lock);
208
209 return ret;
210}
211
212/*
213 * Misc routines
214 */
215
216/*
217 * Calculate the actual sampling rate relatetively to the base clock (48kHz).
218 */
219static u32 ymfpci_calc_delta(u32 rate)
220{
221 switch (rate) {
222 case 8000: return 0x02aaab00;
223 case 11025: return 0x03accd00;
224 case 16000: return 0x05555500;
225 case 22050: return 0x07599a00;
226 case 32000: return 0x0aaaab00;
227 case 44100: return 0x0eb33300;
228 default: return ((rate << 16) / 48000) << 12;
229 }
230}
231
232static u32 def_rate[8] = {
233 100, 2000, 8000, 11025, 16000, 22050, 32000, 48000
234};
235
236static u32 ymfpci_calc_lpfK(u32 rate)
237{
238 u32 i;
239 static u32 val[8] = {
240 0x00570000, 0x06AA0000, 0x18B20000, 0x20930000,
241 0x2B9A0000, 0x35A10000, 0x3EAA0000, 0x40000000
242 };
243
244 if (rate == 44100)
245 return 0x40000000; /* FIXME: What's the right value? */
246 for (i = 0; i < 8; i++)
247 if (rate <= def_rate[i])
248 return val[i];
249 return val[0];
250}
251
252static u32 ymfpci_calc_lpfQ(u32 rate)
253{
254 u32 i;
255 static u32 val[8] = {
256 0x35280000, 0x34A70000, 0x32020000, 0x31770000,
257 0x31390000, 0x31C90000, 0x33D00000, 0x40000000
258 };
259
260 if (rate == 44100)
261 return 0x370A0000;
262 for (i = 0; i < 8; i++)
263 if (rate <= def_rate[i])
264 return val[i];
265 return val[0];
266}
267
268static u32 ymf_calc_lend(u32 rate)
269{
270 return (rate * YMF_SAMPF) / 48000;
271}
272
273/*
274 * We ever allow only a few formats, but let's be generic, for smaller surprise.
275 */
276static int ymf_pcm_format_width(int format)
277{
278 static int mask16 = AFMT_S16_LE|AFMT_S16_BE|AFMT_U16_LE|AFMT_U16_BE;
279
280 if ((format & (format-1)) != 0) {
281 printk(KERN_ERR "ymfpci: format 0x%x is not a power of 2\n", format);
282 return 8;
283 }
284
285 if (format == AFMT_IMA_ADPCM) return 4;
286 if ((format & mask16) != 0) return 16;
287 return 8;
288}
289
290static void ymf_pcm_update_shift(struct ymf_pcm_format *f)
291{
292 f->shift = 0;
293 if (f->voices == 2)
294 f->shift++;
295 if (ymf_pcm_format_width(f->format) == 16)
296 f->shift++;
297}
298
299/* Are you sure 32K is not too much? See if mpg123 skips on loaded systems. */
300#define DMABUF_DEFAULTORDER (15-PAGE_SHIFT)
301#define DMABUF_MINORDER 1
302
303/*
304 * Allocate DMA buffer
305 */
306static int alloc_dmabuf(ymfpci_t *unit, struct ymf_dmabuf *dmabuf)
307{
308 void *rawbuf = NULL;
309 dma_addr_t dma_addr;
310 int order;
311 struct page *map, *mapend;
312
313 /* alloc as big a chunk as we can */
314 for (order = DMABUF_DEFAULTORDER; order >= DMABUF_MINORDER; order--) {
315 rawbuf = pci_alloc_consistent(unit->pci, PAGE_SIZE << order, &dma_addr);
316 if (rawbuf)
317 break;
318 }
319 if (!rawbuf)
320 return -ENOMEM;
321
322#if 0
323 printk(KERN_DEBUG "ymfpci: allocated %ld (order = %d) bytes at %p\n",
324 PAGE_SIZE << order, order, rawbuf);
325#endif
326
327 dmabuf->ready = dmabuf->mapped = 0;
328 dmabuf->rawbuf = rawbuf;
329 dmabuf->dma_addr = dma_addr;
330 dmabuf->buforder = order;
331
332 /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
333 mapend = virt_to_page(rawbuf + (PAGE_SIZE << order) - 1);
334 for (map = virt_to_page(rawbuf); map <= mapend; map++)
335 set_bit(PG_reserved, &map->flags);
336
337 return 0;
338}
339
340/*
341 * Free DMA buffer
342 */
343static void dealloc_dmabuf(ymfpci_t *unit, struct ymf_dmabuf *dmabuf)
344{
345 struct page *map, *mapend;
346
347 if (dmabuf->rawbuf) {
348 /* undo marking the pages as reserved */
349 mapend = virt_to_page(dmabuf->rawbuf + (PAGE_SIZE << dmabuf->buforder) - 1);
350 for (map = virt_to_page(dmabuf->rawbuf); map <= mapend; map++)
351 clear_bit(PG_reserved, &map->flags);
352
353 pci_free_consistent(unit->pci, PAGE_SIZE << dmabuf->buforder,
354 dmabuf->rawbuf, dmabuf->dma_addr);
355 }
356 dmabuf->rawbuf = NULL;
357 dmabuf->mapped = dmabuf->ready = 0;
358}
359
360static int prog_dmabuf(struct ymf_state *state, int rec)
361{
362 struct ymf_dmabuf *dmabuf;
363 int w_16;
364 unsigned bufsize;
365 unsigned long flags;
366 int redzone, redfrags;
367 int ret;
368
369 w_16 = ymf_pcm_format_width(state->format.format) == 16;
370 dmabuf = rec ? &state->rpcm.dmabuf : &state->wpcm.dmabuf;
371
372 spin_lock_irqsave(&state->unit->reg_lock, flags);
373 dmabuf->hwptr = dmabuf->swptr = 0;
374 dmabuf->total_bytes = 0;
375 dmabuf->count = 0;
376 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
377
378 /* allocate DMA buffer if not allocated yet */
379 if (!dmabuf->rawbuf)
380 if ((ret = alloc_dmabuf(state->unit, dmabuf)))
381 return ret;
382
383 /*
384 * Create fake fragment sizes and numbers for OSS ioctls.
385 * Import what Doom might have set with SNDCTL_DSP_SETFRAGMENT.
386 */
387 bufsize = PAGE_SIZE << dmabuf->buforder;
388 /* By default we give 4 big buffers. */
389 dmabuf->fragshift = (dmabuf->buforder + PAGE_SHIFT - 2);
390 if (dmabuf->ossfragshift > 3 &&
391 dmabuf->ossfragshift < dmabuf->fragshift) {
392 /* If OSS set smaller fragments, give more smaller buffers. */
393 dmabuf->fragshift = dmabuf->ossfragshift;
394 }
395 dmabuf->fragsize = 1 << dmabuf->fragshift;
396
397 dmabuf->numfrag = bufsize >> dmabuf->fragshift;
398 dmabuf->dmasize = dmabuf->numfrag << dmabuf->fragshift;
399
400 if (dmabuf->ossmaxfrags >= 2) {
401 redzone = ymf_calc_lend(state->format.rate);
402 redzone <<= state->format.shift;
403 redzone *= 3;
404 redfrags = (redzone + dmabuf->fragsize-1) >> dmabuf->fragshift;
405
406 if (dmabuf->ossmaxfrags + redfrags < dmabuf->numfrag) {
407 dmabuf->numfrag = dmabuf->ossmaxfrags + redfrags;
408 dmabuf->dmasize = dmabuf->numfrag << dmabuf->fragshift;
409 }
410 }
411
412 memset(dmabuf->rawbuf, w_16 ? 0 : 0x80, dmabuf->dmasize);
413
414 /*
415 * Now set up the ring
416 */
417
418 /* XXX ret = rec? cap_pre(): pbk_pre(); */
419 spin_lock_irqsave(&state->unit->voice_lock, flags);
420 if (rec) {
421 if ((ret = ymf_capture_prepare(state)) != 0) {
422 spin_unlock_irqrestore(&state->unit->voice_lock, flags);
423 return ret;
424 }
425 } else {
426 if ((ret = ymf_playback_prepare(state)) != 0) {
427 spin_unlock_irqrestore(&state->unit->voice_lock, flags);
428 return ret;
429 }
430 }
431 spin_unlock_irqrestore(&state->unit->voice_lock, flags);
432
433 /* set the ready flag for the dma buffer (this comment is not stupid) */
434 dmabuf->ready = 1;
435
436#if 0
437 printk(KERN_DEBUG "prog_dmabuf: rate %d format 0x%x,"
438 " numfrag %d fragsize %d dmasize %d\n",
439 state->format.rate, state->format.format, dmabuf->numfrag,
440 dmabuf->fragsize, dmabuf->dmasize);
441#endif
442
443 return 0;
444}
445
446static void ymf_start_dac(struct ymf_state *state)
447{
448 ymf_playback_trigger(state->unit, &state->wpcm, 1);
449}
450
451// static void ymf_start_adc(struct ymf_state *state)
452// {
453// ymf_capture_trigger(state->unit, &state->rpcm, 1);
454// }
455
456/*
457 * Wait until output is drained.
458 * This does not kill the hardware for the sake of ioctls.
459 */
460static void ymf_wait_dac(struct ymf_state *state)
461{
462 struct ymf_unit *unit = state->unit;
463 struct ymf_pcm *ypcm = &state->wpcm;
464 DECLARE_WAITQUEUE(waita, current);
465 unsigned long flags;
466
467 add_wait_queue(&ypcm->dmabuf.wait, &waita);
468
469 spin_lock_irqsave(&unit->reg_lock, flags);
470 if (ypcm->dmabuf.count != 0 && !ypcm->running) {
471 ymf_playback_trigger(unit, ypcm, 1);
472 }
473
474#if 0
475 if (file->f_flags & O_NONBLOCK) {
476 /*
477 * XXX Our mistake is to attach DMA buffer to state
478 * rather than to some per-device structure.
479 * Cannot skip waiting, can only make it shorter.
480 */
481 }
482#endif
483
484 set_current_state(TASK_UNINTERRUPTIBLE);
485 while (ypcm->running) {
486 spin_unlock_irqrestore(&unit->reg_lock, flags);
487 schedule();
488 spin_lock_irqsave(&unit->reg_lock, flags);
489 set_current_state(TASK_UNINTERRUPTIBLE);
490 }
491 spin_unlock_irqrestore(&unit->reg_lock, flags);
492
493 set_current_state(TASK_RUNNING);
494 remove_wait_queue(&ypcm->dmabuf.wait, &waita);
495
496 /*
497 * This function may take up to 4 seconds to reach this point
498 * (32K circular buffer, 8000 Hz). User notices.
499 */
500}
501
502/* Can just stop, without wait. Or can we? */
503static void ymf_stop_adc(struct ymf_state *state)
504{
505 struct ymf_unit *unit = state->unit;
506 unsigned long flags;
507
508 spin_lock_irqsave(&unit->reg_lock, flags);
509 ymf_capture_trigger(unit, &state->rpcm, 0);
510 spin_unlock_irqrestore(&unit->reg_lock, flags);
511}
512
513/*
514 * Hardware start management
515 */
516
517static void ymfpci_hw_start(ymfpci_t *unit)
518{
519 unsigned long flags;
520
521 spin_lock_irqsave(&unit->reg_lock, flags);
522 if (unit->start_count++ == 0) {
523 ymfpci_writel(unit, YDSXGR_MODE,
524 ymfpci_readl(unit, YDSXGR_MODE) | 3);
525 unit->active_bank = ymfpci_readl(unit, YDSXGR_CTRLSELECT) & 1;
526 }
527 spin_unlock_irqrestore(&unit->reg_lock, flags);
528}
529
530static void ymfpci_hw_stop(ymfpci_t *unit)
531{
532 unsigned long flags;
533 long timeout = 1000;
534
535 spin_lock_irqsave(&unit->reg_lock, flags);
536 if (--unit->start_count == 0) {
537 ymfpci_writel(unit, YDSXGR_MODE,
538 ymfpci_readl(unit, YDSXGR_MODE) & ~3);
539 while (timeout-- > 0) {
540 if ((ymfpci_readl(unit, YDSXGR_STATUS) & 2) == 0)
541 break;
542 }
543 }
544 spin_unlock_irqrestore(&unit->reg_lock, flags);
545}
546
547/*
548 * Playback voice management
549 */
550
551static int voice_alloc(ymfpci_t *codec, ymfpci_voice_type_t type, int pair, ymfpci_voice_t *rvoice[])
552{
553 ymfpci_voice_t *voice, *voice2;
554 int idx;
555
556 for (idx = 0; idx < YDSXG_PLAYBACK_VOICES; idx += pair ? 2 : 1) {
557 voice = &codec->voices[idx];
558 voice2 = pair ? &codec->voices[idx+1] : NULL;
559 if (voice->use || (voice2 && voice2->use))
560 continue;
561 voice->use = 1;
562 if (voice2)
563 voice2->use = 1;
564 switch (type) {
565 case YMFPCI_PCM:
566 voice->pcm = 1;
567 if (voice2)
568 voice2->pcm = 1;
569 break;
570 case YMFPCI_SYNTH:
571 voice->synth = 1;
572 break;
573 case YMFPCI_MIDI:
574 voice->midi = 1;
575 break;
576 }
577 ymfpci_hw_start(codec);
578 rvoice[0] = voice;
579 if (voice2) {
580 ymfpci_hw_start(codec);
581 rvoice[1] = voice2;
582 }
583 return 0;
584 }
585 return -EBUSY; /* Your audio channel is open by someone else. */
586}
587
588static void ymfpci_voice_free(ymfpci_t *unit, ymfpci_voice_t *pvoice)
589{
590 ymfpci_hw_stop(unit);
591 pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = 0;
592 pvoice->ypcm = NULL;
593}
594
595/*
596 */
597
598static void ymf_pcm_interrupt(ymfpci_t *codec, ymfpci_voice_t *voice)
599{
600 struct ymf_pcm *ypcm;
601 int redzone;
602 int pos, delta, swptr;
603 int played, distance;
604 struct ymf_state *state;
605 struct ymf_dmabuf *dmabuf;
606 char silence;
607
608 if ((ypcm = voice->ypcm) == NULL) {
609 return;
610 }
611 if ((state = ypcm->state) == NULL) {
612 ypcm->running = 0; // lock it
613 return;
614 }
615 dmabuf = &ypcm->dmabuf;
616 spin_lock(&codec->reg_lock);
617 if (ypcm->running) {
618 YMFDBGI("ymfpci: %d, intr bank %d count %d start 0x%x:%x\n",
619 voice->number, codec->active_bank, dmabuf->count,
620 le32_to_cpu(voice->bank[0].start),
621 le32_to_cpu(voice->bank[1].start));
622 silence = (ymf_pcm_format_width(state->format.format) == 16) ?
623 0 : 0x80;
624 /* We need actual left-hand-side redzone size here. */
625 redzone = ymf_calc_lend(state->format.rate);
626 redzone <<= (state->format.shift + 1);
627 swptr = dmabuf->swptr;
628
629 pos = le32_to_cpu(voice->bank[codec->active_bank].start);
630 pos <<= state->format.shift;
631 if (pos < 0 || pos >= dmabuf->dmasize) { /* ucode bug */
632 printk(KERN_ERR "ymfpci%d: runaway voice %d: hwptr %d=>%d dmasize %d\n",
633 codec->dev_audio, voice->number,
634 dmabuf->hwptr, pos, dmabuf->dmasize);
635 pos = 0;
636 }
637 if (pos < dmabuf->hwptr) {
638 delta = dmabuf->dmasize - dmabuf->hwptr;
639 memset(dmabuf->rawbuf + dmabuf->hwptr, silence, delta);
640 delta += pos;
641 memset(dmabuf->rawbuf, silence, pos);
642 } else {
643 delta = pos - dmabuf->hwptr;
644 memset(dmabuf->rawbuf + dmabuf->hwptr, silence, delta);
645 }
646 dmabuf->hwptr = pos;
647
648 if (dmabuf->count == 0) {
649 printk(KERN_ERR "ymfpci%d: %d: strain: hwptr %d\n",
650 codec->dev_audio, voice->number, dmabuf->hwptr);
651 ymf_playback_trigger(codec, ypcm, 0);
652 }
653
654 if (swptr <= pos) {
655 distance = pos - swptr;
656 } else {
657 distance = dmabuf->dmasize - (swptr - pos);
658 }
659 if (distance < redzone) {
660 /*
661 * hwptr inside redzone => DMA ran out of samples.
662 */
663 if (delta < dmabuf->count) {
664 /*
665 * Lost interrupt or other screwage.
666 */
667 printk(KERN_ERR "ymfpci%d: %d: lost: delta %d"
668 " hwptr %d swptr %d distance %d count %d\n",
669 codec->dev_audio, voice->number, delta,
670 dmabuf->hwptr, swptr, distance, dmabuf->count);
671 } else {
672 /*
673 * Normal end of DMA.
674 */
675 YMFDBGI("ymfpci%d: %d: done: delta %d"
676 " hwptr %d swptr %d distance %d count %d\n",
677 codec->dev_audio, voice->number, delta,
678 dmabuf->hwptr, swptr, distance, dmabuf->count);
679 }
680 played = dmabuf->count;
681 if (ypcm->running) {
682 ymf_playback_trigger(codec, ypcm, 0);
683 }
684 } else {
685 /*
686 * hwptr is chipping away towards a remote swptr.
687 * Calculate other distance and apply it to count.
688 */
689 if (swptr >= pos) {
690 distance = swptr - pos;
691 } else {
692 distance = dmabuf->dmasize - (pos - swptr);
693 }
694 if (distance < dmabuf->count) {
695 played = dmabuf->count - distance;
696 } else {
697 played = 0;
698 }
699 }
700
701 dmabuf->total_bytes += played;
702 dmabuf->count -= played;
703 if (dmabuf->count < dmabuf->dmasize / 2) {
704 wake_up(&dmabuf->wait);
705 }
706 }
707 spin_unlock(&codec->reg_lock);
708}
709
710static void ymf_cap_interrupt(ymfpci_t *unit, struct ymf_capture *cap)
711{
712 struct ymf_pcm *ypcm;
713 int redzone;
714 struct ymf_state *state;
715 struct ymf_dmabuf *dmabuf;
716 int pos, delta;
717 int cnt;
718
719 if ((ypcm = cap->ypcm) == NULL) {
720 return;
721 }
722 if ((state = ypcm->state) == NULL) {
723 ypcm->running = 0; // lock it
724 return;
725 }
726 dmabuf = &ypcm->dmabuf;
727 spin_lock(&unit->reg_lock);
728 if (ypcm->running) {
729 redzone = ymf_calc_lend(state->format.rate);
730 redzone <<= (state->format.shift + 1);
731
732 pos = le32_to_cpu(cap->bank[unit->active_bank].start);
733 // pos <<= state->format.shift;
734 if (pos < 0 || pos >= dmabuf->dmasize) { /* ucode bug */
735 printk(KERN_ERR "ymfpci%d: runaway capture %d: hwptr %d=>%d dmasize %d\n",
736 unit->dev_audio, ypcm->capture_bank_number,
737 dmabuf->hwptr, pos, dmabuf->dmasize);
738 pos = 0;
739 }
740 if (pos < dmabuf->hwptr) {
741 delta = dmabuf->dmasize - dmabuf->hwptr;
742 delta += pos;
743 } else {
744 delta = pos - dmabuf->hwptr;
745 }
746 dmabuf->hwptr = pos;
747
748 cnt = dmabuf->count;
749 cnt += delta;
750 if (cnt + redzone > dmabuf->dmasize) {
751 /* Overflow - bump swptr */
752 dmabuf->count = dmabuf->dmasize - redzone;
753 dmabuf->swptr = dmabuf->hwptr + redzone;
754 if (dmabuf->swptr >= dmabuf->dmasize) {
755 dmabuf->swptr -= dmabuf->dmasize;
756 }
757 } else {
758 dmabuf->count = cnt;
759 }
760
761 dmabuf->total_bytes += delta;
762 if (dmabuf->count) { /* && is_sleeping XXX */
763 wake_up(&dmabuf->wait);
764 }
765 }
766 spin_unlock(&unit->reg_lock);
767}
768
769static int ymf_playback_trigger(ymfpci_t *codec, struct ymf_pcm *ypcm, int cmd)
770{
771
772 if (ypcm->voices[0] == NULL) {
773 return -EINVAL;
774 }
775 if (cmd != 0) {
776 codec->ctrl_playback[ypcm->voices[0]->number + 1] =
777 cpu_to_le32(ypcm->voices[0]->bank_ba);
778 if (ypcm->voices[1] != NULL)
779 codec->ctrl_playback[ypcm->voices[1]->number + 1] =
780 cpu_to_le32(ypcm->voices[1]->bank_ba);
781 ypcm->running = 1;
782 } else {
783 codec->ctrl_playback[ypcm->voices[0]->number + 1] = 0;
784 if (ypcm->voices[1] != NULL)
785 codec->ctrl_playback[ypcm->voices[1]->number + 1] = 0;
786 ypcm->running = 0;
787 }
788 return 0;
789}
790
791static void ymf_capture_trigger(ymfpci_t *codec, struct ymf_pcm *ypcm, int cmd)
792{
793 u32 tmp;
794
795 if (cmd != 0) {
796 tmp = ymfpci_readl(codec, YDSXGR_MAPOFREC) | (1 << ypcm->capture_bank_number);
797 ymfpci_writel(codec, YDSXGR_MAPOFREC, tmp);
798 ypcm->running = 1;
799 } else {
800 tmp = ymfpci_readl(codec, YDSXGR_MAPOFREC) & ~(1 << ypcm->capture_bank_number);
801 ymfpci_writel(codec, YDSXGR_MAPOFREC, tmp);
802 ypcm->running = 0;
803 }
804}
805
806static int ymfpci_pcm_voice_alloc(struct ymf_pcm *ypcm, int voices)
807{
808 struct ymf_unit *unit;
809 int err;
810
811 unit = ypcm->state->unit;
812 if (ypcm->voices[1] != NULL && voices < 2) {
813 ymfpci_voice_free(unit, ypcm->voices[1]);
814 ypcm->voices[1] = NULL;
815 }
816 if (voices == 1 && ypcm->voices[0] != NULL)
817 return 0; /* already allocated */
818 if (voices == 2 && ypcm->voices[0] != NULL && ypcm->voices[1] != NULL)
819 return 0; /* already allocated */
820 if (voices > 1) {
821 if (ypcm->voices[0] != NULL && ypcm->voices[1] == NULL) {
822 ymfpci_voice_free(unit, ypcm->voices[0]);
823 ypcm->voices[0] = NULL;
824 }
825 if ((err = voice_alloc(unit, YMFPCI_PCM, 1, ypcm->voices)) < 0)
826 return err;
827 ypcm->voices[0]->ypcm = ypcm;
828 ypcm->voices[1]->ypcm = ypcm;
829 } else {
830 if ((err = voice_alloc(unit, YMFPCI_PCM, 0, ypcm->voices)) < 0)
831 return err;
832 ypcm->voices[0]->ypcm = ypcm;
833 }
834 return 0;
835}
836
837static void ymf_pcm_init_voice(ymfpci_voice_t *voice, int stereo,
838 int rate, int w_16, unsigned long addr, unsigned int end, int spdif)
839{
840 u32 format;
841 u32 delta = ymfpci_calc_delta(rate);
842 u32 lpfQ = ymfpci_calc_lpfQ(rate);
843 u32 lpfK = ymfpci_calc_lpfK(rate);
844 ymfpci_playback_bank_t *bank;
845 int nbank;
846
847 /*
848 * The gain is a floating point number. According to the manual,
849 * bit 31 indicates a sign bit, bit 30 indicates an integer part,
850 * and bits [29:15] indicate a decimal fraction part. Thus,
851 * for a gain of 1.0 the constant of 0x40000000 is loaded.
852 */
853 unsigned default_gain = cpu_to_le32(0x40000000);
854
855 format = (stereo ? 0x00010000 : 0) | (w_16 ? 0 : 0x80000000);
856 if (stereo)
857 end >>= 1;
858 if (w_16)
859 end >>= 1;
860 for (nbank = 0; nbank < 2; nbank++) {
861 bank = &voice->bank[nbank];
862 bank->format = cpu_to_le32(format);
863 bank->loop_default = 0; /* 0-loops forever, otherwise count */
864 bank->base = cpu_to_le32(addr);
865 bank->loop_start = 0;
866 bank->loop_end = cpu_to_le32(end);
867 bank->loop_frac = 0;
868 bank->eg_gain_end = default_gain;
869 bank->lpfQ = cpu_to_le32(lpfQ);
870 bank->status = 0;
871 bank->num_of_frames = 0;
872 bank->loop_count = 0;
873 bank->start = 0;
874 bank->start_frac = 0;
875 bank->delta =
876 bank->delta_end = cpu_to_le32(delta);
877 bank->lpfK =
878 bank->lpfK_end = cpu_to_le32(lpfK);
879 bank->eg_gain = default_gain;
880 bank->lpfD1 =
881 bank->lpfD2 = 0;
882
883 bank->left_gain =
884 bank->right_gain =
885 bank->left_gain_end =
886 bank->right_gain_end =
887 bank->eff1_gain =
888 bank->eff2_gain =
889 bank->eff3_gain =
890 bank->eff1_gain_end =
891 bank->eff2_gain_end =
892 bank->eff3_gain_end = 0;
893
894 if (!stereo) {
895 if (!spdif) {
896 bank->left_gain =
897 bank->right_gain =
898 bank->left_gain_end =
899 bank->right_gain_end = default_gain;
900 } else {
901 bank->eff2_gain =
902 bank->eff2_gain_end =
903 bank->eff3_gain =
904 bank->eff3_gain_end = default_gain;
905 }
906 } else {
907 if (!spdif) {
908 if ((voice->number & 1) == 0) {
909 bank->left_gain =
910 bank->left_gain_end = default_gain;
911 } else {
912 bank->format |= cpu_to_le32(1);
913 bank->right_gain =
914 bank->right_gain_end = default_gain;
915 }
916 } else {
917 if ((voice->number & 1) == 0) {
918 bank->eff2_gain =
919 bank->eff2_gain_end = default_gain;
920 } else {
921 bank->format |= cpu_to_le32(1);
922 bank->eff3_gain =
923 bank->eff3_gain_end = default_gain;
924 }
925 }
926 }
927 }
928}
929
930/*
931 * XXX Capture channel allocation is entirely fake at the moment.
932 * We use only one channel and mark it busy as required.
933 */
934static int ymf_capture_alloc(struct ymf_unit *unit, int *pbank)
935{
936 struct ymf_capture *cap;
937 int cbank;
938
939 cbank = 1; /* Only ADC slot is used for now. */
940 cap = &unit->capture[cbank];
941 if (cap->use)
942 return -EBUSY;
943 cap->use = 1;
944 *pbank = cbank;
945 return 0;
946}
947
948static int ymf_playback_prepare(struct ymf_state *state)
949{
950 struct ymf_pcm *ypcm = &state->wpcm;
951 int err, nvoice;
952
953 if ((err = ymfpci_pcm_voice_alloc(ypcm, state->format.voices)) < 0) {
954 /* Somebody started 32 mpg123's in parallel? */
955 printk(KERN_INFO "ymfpci%d: cannot allocate voice\n",
956 state->unit->dev_audio);
957 return err;
958 }
959
960 for (nvoice = 0; nvoice < state->format.voices; nvoice++) {
961 ymf_pcm_init_voice(ypcm->voices[nvoice],
962 state->format.voices == 2, state->format.rate,
963 ymf_pcm_format_width(state->format.format) == 16,
964 ypcm->dmabuf.dma_addr, ypcm->dmabuf.dmasize,
965 ypcm->spdif);
966 }
967 return 0;
968}
969
970static int ymf_capture_prepare(struct ymf_state *state)
971{
972 ymfpci_t *unit = state->unit;
973 struct ymf_pcm *ypcm = &state->rpcm;
974 ymfpci_capture_bank_t * bank;
975 /* XXX This is confusing, gotta rename one of them banks... */
976 int nbank; /* flip-flop bank */
977 int cbank; /* input [super-]bank */
978 struct ymf_capture *cap;
979 u32 rate, format;
980
981 if (ypcm->capture_bank_number == -1) {
982 if (ymf_capture_alloc(unit, &cbank) != 0)
983 return -EBUSY;
984
985 ypcm->capture_bank_number = cbank;
986
987 cap = &unit->capture[cbank];
988 cap->bank = unit->bank_capture[cbank][0];
989 cap->ypcm = ypcm;
990 ymfpci_hw_start(unit);
991 }
992
993 // ypcm->frag_size = snd_pcm_lib_transfer_fragment(substream);
994 // frag_size is replaced with nonfragged byte-aligned rolling buffer
995 rate = ((48000 * 4096) / state->format.rate) - 1;
996 format = 0;
997 if (state->format.voices == 2)
998 format |= 2;
999 if (ymf_pcm_format_width(state->format.format) == 8)
1000 format |= 1;
1001 switch (ypcm->capture_bank_number) {
1002 case 0:
1003 ymfpci_writel(unit, YDSXGR_RECFORMAT, format);
1004 ymfpci_writel(unit, YDSXGR_RECSLOTSR, rate);
1005 break;
1006 case 1:
1007 ymfpci_writel(unit, YDSXGR_ADCFORMAT, format);
1008 ymfpci_writel(unit, YDSXGR_ADCSLOTSR, rate);
1009 break;
1010 }
1011 for (nbank = 0; nbank < 2; nbank++) {
1012 bank = unit->bank_capture[ypcm->capture_bank_number][nbank];
1013 bank->base = cpu_to_le32(ypcm->dmabuf.dma_addr);
1014 // bank->loop_end = ypcm->dmabuf.dmasize >> state->format.shift;
1015 bank->loop_end = cpu_to_le32(ypcm->dmabuf.dmasize);
1016 bank->start = 0;
1017 bank->num_of_loops = 0;
1018 }
1019#if 0 /* s/pdif */
1020 if (state->digital.dig_valid)
1021 /*state->digital.type == SND_PCM_DIG_AES_IEC958*/
1022 ymfpci_writew(codec, YDSXGR_SPDIFOUTSTATUS,
1023 state->digital.dig_status[0] | (state->digital.dig_status[1] << 8));
1024#endif
1025 return 0;
1026}
1027
1028static irqreturn_t ymf_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1029{
1030 ymfpci_t *codec = dev_id;
1031 u32 status, nvoice, mode;
1032 struct ymf_voice *voice;
1033 struct ymf_capture *cap;
1034
1035 status = ymfpci_readl(codec, YDSXGR_STATUS);
1036 if (status & 0x80000000) {
1037 codec->active_bank = ymfpci_readl(codec, YDSXGR_CTRLSELECT) & 1;
1038 spin_lock(&codec->voice_lock);
1039 for (nvoice = 0; nvoice < YDSXG_PLAYBACK_VOICES; nvoice++) {
1040 voice = &codec->voices[nvoice];
1041 if (voice->use)
1042 ymf_pcm_interrupt(codec, voice);
1043 }
1044 for (nvoice = 0; nvoice < YDSXG_CAPTURE_VOICES; nvoice++) {
1045 cap = &codec->capture[nvoice];
1046 if (cap->use)
1047 ymf_cap_interrupt(codec, cap);
1048 }
1049 spin_unlock(&codec->voice_lock);
1050 spin_lock(&codec->reg_lock);
1051 ymfpci_writel(codec, YDSXGR_STATUS, 0x80000000);
1052 mode = ymfpci_readl(codec, YDSXGR_MODE) | 2;
1053 ymfpci_writel(codec, YDSXGR_MODE, mode);
1054 spin_unlock(&codec->reg_lock);
1055 }
1056
1057 status = ymfpci_readl(codec, YDSXGR_INTFLAG);
1058 if (status & 1) {
1059 /* timer handler */
1060 ymfpci_writel(codec, YDSXGR_INTFLAG, ~0);
1061 }
1062 return IRQ_HANDLED;
1063}
1064
1065static void ymf_pcm_free_substream(struct ymf_pcm *ypcm)
1066{
1067 unsigned long flags;
1068 struct ymf_unit *unit;
1069
1070 unit = ypcm->state->unit;
1071
1072 if (ypcm->type == PLAYBACK_VOICE) {
1073 spin_lock_irqsave(&unit->voice_lock, flags);
1074 if (ypcm->voices[1])
1075 ymfpci_voice_free(unit, ypcm->voices[1]);
1076 if (ypcm->voices[0])
1077 ymfpci_voice_free(unit, ypcm->voices[0]);
1078 spin_unlock_irqrestore(&unit->voice_lock, flags);
1079 } else {
1080 if (ypcm->capture_bank_number != -1) {
1081 unit->capture[ypcm->capture_bank_number].use = 0;
1082 ypcm->capture_bank_number = -1;
1083 ymfpci_hw_stop(unit);
1084 }
1085 }
1086}
1087
1088static struct ymf_state *ymf_state_alloc(ymfpci_t *unit)
1089{
1090 struct ymf_pcm *ypcm;
1091 struct ymf_state *state;
1092
1093 if ((state = kmalloc(sizeof(struct ymf_state), GFP_KERNEL)) == NULL) {
1094 goto out0;
1095 }
1096 memset(state, 0, sizeof(struct ymf_state));
1097
1098 ypcm = &state->wpcm;
1099 ypcm->state = state;
1100 ypcm->type = PLAYBACK_VOICE;
1101 ypcm->capture_bank_number = -1;
1102 init_waitqueue_head(&ypcm->dmabuf.wait);
1103
1104 ypcm = &state->rpcm;
1105 ypcm->state = state;
1106 ypcm->type = CAPTURE_AC97;
1107 ypcm->capture_bank_number = -1;
1108 init_waitqueue_head(&ypcm->dmabuf.wait);
1109
1110 state->unit = unit;
1111
1112 state->format.format = AFMT_U8;
1113 state->format.rate = 8000;
1114 state->format.voices = 1;
1115 ymf_pcm_update_shift(&state->format);
1116
1117 return state;
1118
1119out0:
1120 return NULL;
1121}
1122
1123/* AES/IEC958 channel status bits */
1124#define SND_PCM_AES0_PROFESSIONAL (1<<0) /* 0 = consumer, 1 = professional */
1125#define SND_PCM_AES0_NONAUDIO (1<<1) /* 0 = audio, 1 = non-audio */
1126#define SND_PCM_AES0_PRO_EMPHASIS (7<<2) /* mask - emphasis */
1127#define SND_PCM_AES0_PRO_EMPHASIS_NOTID (0<<2) /* emphasis not indicated */
1128#define SND_PCM_AES0_PRO_EMPHASIS_NONE (1<<2) /* none emphasis */
1129#define SND_PCM_AES0_PRO_EMPHASIS_5015 (3<<2) /* 50/15us emphasis */
1130#define SND_PCM_AES0_PRO_EMPHASIS_CCITT (7<<2) /* CCITT J.17 emphasis */
1131#define SND_PCM_AES0_PRO_FREQ_UNLOCKED (1<<5) /* source sample frequency: 0 = locked, 1 = unlocked */
1132#define SND_PCM_AES0_PRO_FS (3<<6) /* mask - sample frequency */
1133#define SND_PCM_AES0_PRO_FS_NOTID (0<<6) /* fs not indicated */
1134#define SND_PCM_AES0_PRO_FS_44100 (1<<6) /* 44.1kHz */
1135#define SND_PCM_AES0_PRO_FS_48000 (2<<6) /* 48kHz */
1136#define SND_PCM_AES0_PRO_FS_32000 (3<<6) /* 32kHz */
1137#define SND_PCM_AES0_CON_NOT_COPYRIGHT (1<<2) /* 0 = copyright, 1 = not copyright */
1138#define SND_PCM_AES0_CON_EMPHASIS (7<<3) /* mask - emphasis */
1139#define SND_PCM_AES0_CON_EMPHASIS_NONE (0<<3) /* none emphasis */
1140#define SND_PCM_AES0_CON_EMPHASIS_5015 (1<<3) /* 50/15us emphasis */
1141#define SND_PCM_AES0_CON_MODE (3<<6) /* mask - mode */
1142#define SND_PCM_AES1_PRO_MODE (15<<0) /* mask - channel mode */
1143#define SND_PCM_AES1_PRO_MODE_NOTID (0<<0) /* not indicated */
1144#define SND_PCM_AES1_PRO_MODE_STEREOPHONIC (2<<0) /* stereophonic - ch A is left */
1145#define SND_PCM_AES1_PRO_MODE_SINGLE (4<<0) /* single channel */
1146#define SND_PCM_AES1_PRO_MODE_TWO (8<<0) /* two channels */
1147#define SND_PCM_AES1_PRO_MODE_PRIMARY (12<<0) /* primary/secondary */
1148#define SND_PCM_AES1_PRO_MODE_BYTE3 (15<<0) /* vector to byte 3 */
1149#define SND_PCM_AES1_PRO_USERBITS (15<<4) /* mask - user bits */
1150#define SND_PCM_AES1_PRO_USERBITS_NOTID (0<<4) /* not indicated */
1151#define SND_PCM_AES1_PRO_USERBITS_192 (8<<4) /* 192-bit structure */
1152#define SND_PCM_AES1_PRO_USERBITS_UDEF (12<<4) /* user defined application */
1153#define SND_PCM_AES1_CON_CATEGORY 0x7f
1154#define SND_PCM_AES1_CON_GENERAL 0x00
1155#define SND_PCM_AES1_CON_EXPERIMENTAL 0x40
1156#define SND_PCM_AES1_CON_SOLIDMEM_MASK 0x0f
1157#define SND_PCM_AES1_CON_SOLIDMEM_ID 0x08
1158#define SND_PCM_AES1_CON_BROADCAST1_MASK 0x07
1159#define SND_PCM_AES1_CON_BROADCAST1_ID 0x04
1160#define SND_PCM_AES1_CON_DIGDIGCONV_MASK 0x07
1161#define SND_PCM_AES1_CON_DIGDIGCONV_ID 0x02
1162#define SND_PCM_AES1_CON_ADC_COPYRIGHT_MASK 0x1f
1163#define SND_PCM_AES1_CON_ADC_COPYRIGHT_ID 0x06
1164#define SND_PCM_AES1_CON_ADC_MASK 0x1f
1165#define SND_PCM_AES1_CON_ADC_ID 0x16
1166#define SND_PCM_AES1_CON_BROADCAST2_MASK 0x0f
1167#define SND_PCM_AES1_CON_BROADCAST2_ID 0x0e
1168#define SND_PCM_AES1_CON_LASEROPT_MASK 0x07
1169#define SND_PCM_AES1_CON_LASEROPT_ID 0x01
1170#define SND_PCM_AES1_CON_MUSICAL_MASK 0x07
1171#define SND_PCM_AES1_CON_MUSICAL_ID 0x05
1172#define SND_PCM_AES1_CON_MAGNETIC_MASK 0x07
1173#define SND_PCM_AES1_CON_MAGNETIC_ID 0x03
1174#define SND_PCM_AES1_CON_IEC908_CD (SND_PCM_AES1_CON_LASEROPT_ID|0x00)
1175#define SND_PCM_AES1_CON_NON_IEC908_CD (SND_PCM_AES1_CON_LASEROPT_ID|0x08)
1176#define SND_PCM_AES1_CON_PCM_CODER (SND_PCM_AES1_CON_DIGDIGCONV_ID|0x00)
1177#define SND_PCM_AES1_CON_SAMPLER (SND_PCM_AES1_CON_DIGDIGCONV_ID|0x20)
1178#define SND_PCM_AES1_CON_MIXER (SND_PCM_AES1_CON_DIGDIGCONV_ID|0x10)
1179#define SND_PCM_AES1_CON_RATE_CONVERTER (SND_PCM_AES1_CON_DIGDIGCONV_ID|0x18)
1180#define SND_PCM_AES1_CON_SYNTHESIZER (SND_PCM_AES1_CON_MUSICAL_ID|0x00)
1181#define SND_PCM_AES1_CON_MICROPHONE (SND_PCM_AES1_CON_MUSICAL_ID|0x08)
1182#define SND_PCM_AES1_CON_DAT (SND_PCM_AES1_CON_MAGNETIC_ID|0x00)
1183#define SND_PCM_AES1_CON_VCR (SND_PCM_AES1_CON_MAGNETIC_ID|0x08)
1184#define SND_PCM_AES1_CON_ORIGINAL (1<<7) /* this bits depends on the category code */
1185#define SND_PCM_AES2_PRO_SBITS (7<<0) /* mask - sample bits */
1186#define SND_PCM_AES2_PRO_SBITS_20 (2<<0) /* 20-bit - coordination */
1187#define SND_PCM_AES2_PRO_SBITS_24 (4<<0) /* 24-bit - main audio */
1188#define SND_PCM_AES2_PRO_SBITS_UDEF (6<<0) /* user defined application */
1189#define SND_PCM_AES2_PRO_WORDLEN (7<<3) /* mask - source word length */
1190#define SND_PCM_AES2_PRO_WORDLEN_NOTID (0<<3) /* not indicated */
1191#define SND_PCM_AES2_PRO_WORDLEN_22_18 (2<<3) /* 22-bit or 18-bit */
1192#define SND_PCM_AES2_PRO_WORDLEN_23_19 (4<<3) /* 23-bit or 19-bit */
1193#define SND_PCM_AES2_PRO_WORDLEN_24_20 (5<<3) /* 24-bit or 20-bit */
1194#define SND_PCM_AES2_PRO_WORDLEN_20_16 (6<<3) /* 20-bit or 16-bit */
1195#define SND_PCM_AES2_CON_SOURCE (15<<0) /* mask - source number */
1196#define SND_PCM_AES2_CON_SOURCE_UNSPEC (0<<0) /* unspecified */
1197#define SND_PCM_AES2_CON_CHANNEL (15<<4) /* mask - channel number */
1198#define SND_PCM_AES2_CON_CHANNEL_UNSPEC (0<<4) /* unspecified */
1199#define SND_PCM_AES3_CON_FS (15<<0) /* mask - sample frequency */
1200#define SND_PCM_AES3_CON_FS_44100 (0<<0) /* 44.1kHz */
1201#define SND_PCM_AES3_CON_FS_48000 (2<<0) /* 48kHz */
1202#define SND_PCM_AES3_CON_FS_32000 (3<<0) /* 32kHz */
1203#define SND_PCM_AES3_CON_CLOCK (3<<4) /* mask - clock accuracy */
1204#define SND_PCM_AES3_CON_CLOCK_1000PPM (0<<4) /* 1000 ppm */
1205#define SND_PCM_AES3_CON_CLOCK_50PPM (1<<4) /* 50 ppm */
1206#define SND_PCM_AES3_CON_CLOCK_VARIABLE (2<<4) /* variable pitch */
1207
1208/*
1209 * User interface
1210 */
1211
1212/*
1213 * in this loop, dmabuf.count signifies the amount of data that is
1214 * waiting to be copied to the user's buffer. it is filled by the dma
1215 * machine and drained by this loop.
1216 */
1217static ssize_t
1218ymf_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1219{
1220 struct ymf_state *state = (struct ymf_state *)file->private_data;
1221 struct ymf_dmabuf *dmabuf = &state->rpcm.dmabuf;
1222 struct ymf_unit *unit = state->unit;
1223 DECLARE_WAITQUEUE(waita, current);
1224 ssize_t ret;
1225 unsigned long flags;
1226 unsigned int swptr;
1227 int cnt; /* This many to go in this revolution */
1228
1229 if (dmabuf->mapped)
1230 return -ENXIO;
1231 if (!dmabuf->ready && (ret = prog_dmabuf(state, 1)))
1232 return ret;
1233 ret = 0;
1234
1235 add_wait_queue(&dmabuf->wait, &waita);
1236 set_current_state(TASK_INTERRUPTIBLE);
1237 while (count > 0) {
1238 spin_lock_irqsave(&unit->reg_lock, flags);
1239 if (unit->suspended) {
1240 spin_unlock_irqrestore(&unit->reg_lock, flags);
1241 schedule();
1242 set_current_state(TASK_INTERRUPTIBLE);
1243 if (signal_pending(current)) {
1244 if (!ret) ret = -EAGAIN;
1245 break;
1246 }
1247 continue;
1248 }
1249 swptr = dmabuf->swptr;
1250 cnt = dmabuf->dmasize - swptr;
1251 if (dmabuf->count < cnt)
1252 cnt = dmabuf->count;
1253 spin_unlock_irqrestore(&unit->reg_lock, flags);
1254
1255 if (cnt > count)
1256 cnt = count;
1257 if (cnt <= 0) {
1258 unsigned long tmo;
1259 /* buffer is empty, start the dma machine and wait for data to be
1260 recorded */
1261 spin_lock_irqsave(&state->unit->reg_lock, flags);
1262 if (!state->rpcm.running) {
1263 ymf_capture_trigger(state->unit, &state->rpcm, 1);
1264 }
1265 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1266 if (file->f_flags & O_NONBLOCK) {
1267 if (!ret) ret = -EAGAIN;
1268 break;
1269 }
1270 /* This isnt strictly right for the 810 but it'll do */
1271 tmo = (dmabuf->dmasize * HZ) / (state->format.rate * 2);
1272 tmo >>= state->format.shift;
1273 /* There are two situations when sleep_on_timeout returns, one is when
1274 the interrupt is serviced correctly and the process is waked up by
1275 ISR ON TIME. Another is when timeout is expired, which means that
1276 either interrupt is NOT serviced correctly (pending interrupt) or it
1277 is TOO LATE for the process to be scheduled to run (scheduler latency)
1278 which results in a (potential) buffer overrun. And worse, there is
1279 NOTHING we can do to prevent it. */
1280 tmo = schedule_timeout(tmo);
1281 spin_lock_irqsave(&state->unit->reg_lock, flags);
1282 set_current_state(TASK_INTERRUPTIBLE);
1283 if (tmo == 0 && dmabuf->count == 0) {
1284 printk(KERN_ERR "ymfpci%d: recording schedule timeout, "
1285 "dmasz %u fragsz %u count %i hwptr %u swptr %u\n",
1286 state->unit->dev_audio,
1287 dmabuf->dmasize, dmabuf->fragsize, dmabuf->count,
1288 dmabuf->hwptr, dmabuf->swptr);
1289 }
1290 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1291 if (signal_pending(current)) {
1292 if (!ret) ret = -ERESTARTSYS;
1293 break;
1294 }
1295 continue;
1296 }
1297
1298 if (copy_to_user(buffer, dmabuf->rawbuf + swptr, cnt)) {
1299 if (!ret) ret = -EFAULT;
1300 break;
1301 }
1302
1303 swptr = (swptr + cnt) % dmabuf->dmasize;
1304
1305 spin_lock_irqsave(&unit->reg_lock, flags);
1306 if (unit->suspended) {
1307 spin_unlock_irqrestore(&unit->reg_lock, flags);
1308 continue;
1309 }
1310
1311 dmabuf->swptr = swptr;
1312 dmabuf->count -= cnt;
1313 // spin_unlock_irqrestore(&unit->reg_lock, flags);
1314
1315 count -= cnt;
1316 buffer += cnt;
1317 ret += cnt;
1318 // spin_lock_irqsave(&unit->reg_lock, flags);
1319 if (!state->rpcm.running) {
1320 ymf_capture_trigger(unit, &state->rpcm, 1);
1321 }
1322 spin_unlock_irqrestore(&unit->reg_lock, flags);
1323 }
1324 set_current_state(TASK_RUNNING);
1325 remove_wait_queue(&dmabuf->wait, &waita);
1326
1327 return ret;
1328}
1329
1330static ssize_t
1331ymf_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1332{
1333 struct ymf_state *state = (struct ymf_state *)file->private_data;
1334 struct ymf_dmabuf *dmabuf = &state->wpcm.dmabuf;
1335 struct ymf_unit *unit = state->unit;
1336 DECLARE_WAITQUEUE(waita, current);
1337 ssize_t ret;
1338 unsigned long flags;
1339 unsigned int swptr;
1340 int cnt; /* This many to go in this revolution */
1341 int redzone;
1342 int delay;
1343
1344 YMFDBGW("ymf_write: count %d\n", count);
1345
1346 if (dmabuf->mapped)
1347 return -ENXIO;
1348 if (!dmabuf->ready && (ret = prog_dmabuf(state, 0)))
1349 return ret;
1350 ret = 0;
1351
1352 /*
1353 * Alan's cs46xx works without a red zone - marvel of ingenuity.
1354 * We are not so brilliant... Red zone does two things:
1355 * 1. allows for safe start after a pause as we have no way
1356 * to know what the actual, relentlessly advancing, hwptr is.
1357 * 2. makes computations in ymf_pcm_interrupt simpler.
1358 */
1359 redzone = ymf_calc_lend(state->format.rate) << state->format.shift;
1360 redzone *= 3; /* 2 redzone + 1 possible uncertainty reserve. */
1361
1362 add_wait_queue(&dmabuf->wait, &waita);
1363 set_current_state(TASK_INTERRUPTIBLE);
1364 while (count > 0) {
1365 spin_lock_irqsave(&unit->reg_lock, flags);
1366 if (unit->suspended) {
1367 spin_unlock_irqrestore(&unit->reg_lock, flags);
1368 schedule();
1369 set_current_state(TASK_INTERRUPTIBLE);
1370 if (signal_pending(current)) {
1371 if (!ret) ret = -EAGAIN;
1372 break;
1373 }
1374 continue;
1375 }
1376 if (dmabuf->count < 0) {
1377 printk(KERN_ERR
1378 "ymf_write: count %d, was legal in cs46xx\n",
1379 dmabuf->count);
1380 dmabuf->count = 0;
1381 }
1382 if (dmabuf->count == 0) {
1383 swptr = dmabuf->hwptr;
1384 if (state->wpcm.running) {
1385 /*
1386 * Add uncertainty reserve.
1387 */
1388 cnt = ymf_calc_lend(state->format.rate);
1389 cnt <<= state->format.shift;
1390 if ((swptr += cnt) >= dmabuf->dmasize) {
1391 swptr -= dmabuf->dmasize;
1392 }
1393 }
1394 dmabuf->swptr = swptr;
1395 } else {
1396 /*
1397 * XXX This is not right if dmabuf->count is small -
1398 * about 2*x frame size or less. We cannot count on
1399 * on appending and not causing an artefact.
1400 * Should use a variation of the count==0 case above.
1401 */
1402 swptr = dmabuf->swptr;
1403 }
1404 cnt = dmabuf->dmasize - swptr;
1405 if (dmabuf->count + cnt > dmabuf->dmasize - redzone)
1406 cnt = (dmabuf->dmasize - redzone) - dmabuf->count;
1407 spin_unlock_irqrestore(&unit->reg_lock, flags);
1408
1409 if (cnt > count)
1410 cnt = count;
1411 if (cnt <= 0) {
1412 YMFDBGW("ymf_write: full, count %d swptr %d\n",
1413 dmabuf->count, dmabuf->swptr);
1414 /*
1415 * buffer is full, start the dma machine and
1416 * wait for data to be played
1417 */
1418 spin_lock_irqsave(&unit->reg_lock, flags);
1419 if (!state->wpcm.running) {
1420 ymf_playback_trigger(unit, &state->wpcm, 1);
1421 }
1422 spin_unlock_irqrestore(&unit->reg_lock, flags);
1423 if (file->f_flags & O_NONBLOCK) {
1424 if (!ret) ret = -EAGAIN;
1425 break;
1426 }
1427 schedule();
1428 set_current_state(TASK_INTERRUPTIBLE);
1429 if (signal_pending(current)) {
1430 if (!ret) ret = -ERESTARTSYS;
1431 break;
1432 }
1433 continue;
1434 }
1435 if (copy_from_user(dmabuf->rawbuf + swptr, buffer, cnt)) {
1436 if (!ret) ret = -EFAULT;
1437 break;
1438 }
1439
1440 if ((swptr += cnt) >= dmabuf->dmasize) {
1441 swptr -= dmabuf->dmasize;
1442 }
1443
1444 spin_lock_irqsave(&unit->reg_lock, flags);
1445 if (unit->suspended) {
1446 spin_unlock_irqrestore(&unit->reg_lock, flags);
1447 continue;
1448 }
1449 dmabuf->swptr = swptr;
1450 dmabuf->count += cnt;
1451
1452 /*
1453 * Start here is a bad idea - may cause startup click
1454 * in /bin/play when dmabuf is not full yet.
1455 * However, some broken applications do not make
1456 * any use of SNDCTL_DSP_SYNC (Doom is the worst).
1457 * One frame is about 5.3ms, Doom write size is 46ms.
1458 */
1459 delay = state->format.rate / 20; /* 50ms */
1460 delay <<= state->format.shift;
1461 if (dmabuf->count >= delay && !state->wpcm.running) {
1462 ymf_playback_trigger(unit, &state->wpcm, 1);
1463 }
1464
1465 spin_unlock_irqrestore(&unit->reg_lock, flags);
1466
1467 count -= cnt;
1468 buffer += cnt;
1469 ret += cnt;
1470 }
1471
1472 set_current_state(TASK_RUNNING);
1473 remove_wait_queue(&dmabuf->wait, &waita);
1474
1475 YMFDBGW("ymf_write: ret %d dmabuf.count %d\n", ret, dmabuf->count);
1476 return ret;
1477}
1478
1479static unsigned int ymf_poll(struct file *file, struct poll_table_struct *wait)
1480{
1481 struct ymf_state *state = (struct ymf_state *)file->private_data;
1482 struct ymf_dmabuf *dmabuf;
1483 int redzone;
1484 unsigned long flags;
1485 unsigned int mask = 0;
1486
1487 if (file->f_mode & FMODE_WRITE)
1488 poll_wait(file, &state->wpcm.dmabuf.wait, wait);
1489 if (file->f_mode & FMODE_READ)
1490 poll_wait(file, &state->rpcm.dmabuf.wait, wait);
1491
1492 spin_lock_irqsave(&state->unit->reg_lock, flags);
1493 if (file->f_mode & FMODE_READ) {
1494 dmabuf = &state->rpcm.dmabuf;
1495 if (dmabuf->count >= (signed)dmabuf->fragsize)
1496 mask |= POLLIN | POLLRDNORM;
1497 }
1498 if (file->f_mode & FMODE_WRITE) {
1499 redzone = ymf_calc_lend(state->format.rate);
1500 redzone <<= state->format.shift;
1501 redzone *= 3;
1502
1503 dmabuf = &state->wpcm.dmabuf;
1504 if (dmabuf->mapped) {
1505 if (dmabuf->count >= (signed)dmabuf->fragsize)
1506 mask |= POLLOUT | POLLWRNORM;
1507 } else {
1508 /*
1509 * Don't select unless a full fragment is available.
1510 * Otherwise artsd does GETOSPACE, sees 0, and loops.
1511 */
1512 if (dmabuf->count + redzone + dmabuf->fragsize
1513 <= dmabuf->dmasize)
1514 mask |= POLLOUT | POLLWRNORM;
1515 }
1516 }
1517 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1518
1519 return mask;
1520}
1521
1522static int ymf_mmap(struct file *file, struct vm_area_struct *vma)
1523{
1524 struct ymf_state *state = (struct ymf_state *)file->private_data;
1525 struct ymf_dmabuf *dmabuf = &state->wpcm.dmabuf;
1526 int ret;
1527 unsigned long size;
1528
1529 if (vma->vm_flags & VM_WRITE) {
1530 if ((ret = prog_dmabuf(state, 0)) != 0)
1531 return ret;
1532 } else if (vma->vm_flags & VM_READ) {
1533 if ((ret = prog_dmabuf(state, 1)) != 0)
1534 return ret;
1535 } else
1536 return -EINVAL;
1537
1538 if (vma->vm_pgoff != 0)
1539 return -EINVAL;
1540 size = vma->vm_end - vma->vm_start;
1541 if (size > (PAGE_SIZE << dmabuf->buforder))
1542 return -EINVAL;
1543 if (remap_pfn_range(vma, vma->vm_start,
1544 virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT,
1545 size, vma->vm_page_prot))
1546 return -EAGAIN;
1547 dmabuf->mapped = 1;
1548
1549/* P3 */ printk(KERN_INFO "ymfpci: using memory mapped sound, untested!\n");
1550 return 0;
1551}
1552
1553static int ymf_ioctl(struct inode *inode, struct file *file,
1554 unsigned int cmd, unsigned long arg)
1555{
1556 struct ymf_state *state = (struct ymf_state *)file->private_data;
1557 struct ymf_dmabuf *dmabuf;
1558 unsigned long flags;
1559 audio_buf_info abinfo;
1560 count_info cinfo;
1561 int redzone;
1562 int val;
1563 void __user *argp = (void __user *)arg;
1564 int __user *p = argp;
1565
1566 switch (cmd) {
1567 case OSS_GETVERSION:
1568 YMFDBGX("ymf_ioctl: cmd 0x%x(GETVER) arg 0x%lx\n", cmd, arg);
1569 return put_user(SOUND_VERSION, p);
1570
1571 case SNDCTL_DSP_RESET:
1572 YMFDBGX("ymf_ioctl: cmd 0x%x(RESET)\n", cmd);
1573 if (file->f_mode & FMODE_WRITE) {
1574 ymf_wait_dac(state);
1575 dmabuf = &state->wpcm.dmabuf;
1576 spin_lock_irqsave(&state->unit->reg_lock, flags);
1577 dmabuf->ready = 0;
1578 dmabuf->swptr = dmabuf->hwptr;
1579 dmabuf->count = dmabuf->total_bytes = 0;
1580 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1581 }
1582 if (file->f_mode & FMODE_READ) {
1583 ymf_stop_adc(state);
1584 dmabuf = &state->rpcm.dmabuf;
1585 spin_lock_irqsave(&state->unit->reg_lock, flags);
1586 dmabuf->ready = 0;
1587 dmabuf->swptr = dmabuf->hwptr;
1588 dmabuf->count = dmabuf->total_bytes = 0;
1589 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1590 }
1591 return 0;
1592
1593 case SNDCTL_DSP_SYNC:
1594 YMFDBGX("ymf_ioctl: cmd 0x%x(SYNC)\n", cmd);
1595 if (file->f_mode & FMODE_WRITE) {
1596 dmabuf = &state->wpcm.dmabuf;
1597 if (file->f_flags & O_NONBLOCK) {
1598 spin_lock_irqsave(&state->unit->reg_lock, flags);
1599 if (dmabuf->count != 0 && !state->wpcm.running) {
1600 ymf_start_dac(state);
1601 }
1602 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1603 } else {
1604 ymf_wait_dac(state);
1605 }
1606 }
1607 /* XXX What does this do for reading? dmabuf->count=0; ? */
1608 return 0;
1609
1610 case SNDCTL_DSP_SPEED: /* set smaple rate */
1611 if (get_user(val, p))
1612 return -EFAULT;
1613 YMFDBGX("ymf_ioctl: cmd 0x%x(SPEED) sp %d\n", cmd, val);
1614 if (val >= 8000 && val <= 48000) {
1615 if (file->f_mode & FMODE_WRITE) {
1616 ymf_wait_dac(state);
1617 dmabuf = &state->wpcm.dmabuf;
1618 spin_lock_irqsave(&state->unit->reg_lock, flags);
1619 dmabuf->ready = 0;
1620 state->format.rate = val;
1621 ymf_pcm_update_shift(&state->format);
1622 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1623 }
1624 if (file->f_mode & FMODE_READ) {
1625 ymf_stop_adc(state);
1626 dmabuf = &state->rpcm.dmabuf;
1627 spin_lock_irqsave(&state->unit->reg_lock, flags);
1628 dmabuf->ready = 0;
1629 state->format.rate = val;
1630 ymf_pcm_update_shift(&state->format);
1631 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1632 }
1633 }
1634 return put_user(state->format.rate, p);
1635
1636 /*
1637 * OSS manual does not mention SNDCTL_DSP_STEREO at all.
1638 * All channels are mono and if you want stereo, you
1639 * play into two channels with SNDCTL_DSP_CHANNELS.
1640 * However, mpg123 calls it. I wonder, why Michael Hipp used it.
1641 */
1642 case SNDCTL_DSP_STEREO: /* set stereo or mono channel */
1643 if (get_user(val, p))
1644 return -EFAULT;
1645 YMFDBGX("ymf_ioctl: cmd 0x%x(STEREO) st %d\n", cmd, val);
1646 if (file->f_mode & FMODE_WRITE) {
1647 ymf_wait_dac(state);
1648 dmabuf = &state->wpcm.dmabuf;
1649 spin_lock_irqsave(&state->unit->reg_lock, flags);
1650 dmabuf->ready = 0;
1651 state->format.voices = val ? 2 : 1;
1652 ymf_pcm_update_shift(&state->format);
1653 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1654 }
1655 if (file->f_mode & FMODE_READ) {
1656 ymf_stop_adc(state);
1657 dmabuf = &state->rpcm.dmabuf;
1658 spin_lock_irqsave(&state->unit->reg_lock, flags);
1659 dmabuf->ready = 0;
1660 state->format.voices = val ? 2 : 1;
1661 ymf_pcm_update_shift(&state->format);
1662 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1663 }
1664 return 0;
1665
1666 case SNDCTL_DSP_GETBLKSIZE:
1667 YMFDBGX("ymf_ioctl: cmd 0x%x(GETBLK)\n", cmd);
1668 if (file->f_mode & FMODE_WRITE) {
1669 if ((val = prog_dmabuf(state, 0)))
1670 return val;
1671 val = state->wpcm.dmabuf.fragsize;
1672 YMFDBGX("ymf_ioctl: GETBLK w %d\n", val);
1673 return put_user(val, p);
1674 }
1675 if (file->f_mode & FMODE_READ) {
1676 if ((val = prog_dmabuf(state, 1)))
1677 return val;
1678 val = state->rpcm.dmabuf.fragsize;
1679 YMFDBGX("ymf_ioctl: GETBLK r %d\n", val);
1680 return put_user(val, p);
1681 }
1682 return -EINVAL;
1683
1684 case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format*/
1685 YMFDBGX("ymf_ioctl: cmd 0x%x(GETFMTS)\n", cmd);
1686 return put_user(AFMT_S16_LE|AFMT_U8, p);
1687
1688 case SNDCTL_DSP_SETFMT: /* Select sample format */
1689 if (get_user(val, p))
1690 return -EFAULT;
1691 YMFDBGX("ymf_ioctl: cmd 0x%x(SETFMT) fmt %d\n", cmd, val);
1692 if (val == AFMT_S16_LE || val == AFMT_U8) {
1693 if (file->f_mode & FMODE_WRITE) {
1694 ymf_wait_dac(state);
1695 dmabuf = &state->wpcm.dmabuf;
1696 spin_lock_irqsave(&state->unit->reg_lock, flags);
1697 dmabuf->ready = 0;
1698 state->format.format = val;
1699 ymf_pcm_update_shift(&state->format);
1700 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1701 }
1702 if (file->f_mode & FMODE_READ) {
1703 ymf_stop_adc(state);
1704 dmabuf = &state->rpcm.dmabuf;
1705 spin_lock_irqsave(&state->unit->reg_lock, flags);
1706 dmabuf->ready = 0;
1707 state->format.format = val;
1708 ymf_pcm_update_shift(&state->format);
1709 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1710 }
1711 }
1712 return put_user(state->format.format, p);
1713
1714 case SNDCTL_DSP_CHANNELS:
1715 if (get_user(val, p))
1716 return -EFAULT;
1717 YMFDBGX("ymf_ioctl: cmd 0x%x(CHAN) ch %d\n", cmd, val);
1718 if (val != 0) {
1719 if (file->f_mode & FMODE_WRITE) {
1720 ymf_wait_dac(state);
1721 if (val == 1 || val == 2) {
1722 spin_lock_irqsave(&state->unit->reg_lock, flags);
1723 dmabuf = &state->wpcm.dmabuf;
1724 dmabuf->ready = 0;
1725 state->format.voices = val;
1726 ymf_pcm_update_shift(&state->format);
1727 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1728 }
1729 }
1730 if (file->f_mode & FMODE_READ) {
1731 ymf_stop_adc(state);
1732 if (val == 1 || val == 2) {
1733 spin_lock_irqsave(&state->unit->reg_lock, flags);
1734 dmabuf = &state->rpcm.dmabuf;
1735 dmabuf->ready = 0;
1736 state->format.voices = val;
1737 ymf_pcm_update_shift(&state->format);
1738 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1739 }
1740 }
1741 }
1742 return put_user(state->format.voices, p);
1743
1744 case SNDCTL_DSP_POST:
1745 YMFDBGX("ymf_ioctl: cmd 0x%x(POST)\n", cmd);
1746 /*
1747 * Quoting OSS PG:
1748 * The ioctl SNDCTL_DSP_POST is a lightweight version of
1749 * SNDCTL_DSP_SYNC. It just tells to the driver that there
1750 * is likely to be a pause in the output. This makes it
1751 * possible for the device to handle the pause more
1752 * intelligently. This ioctl doesn't block the application.
1753 *
1754 * The paragraph above is a clumsy way to say "flush ioctl".
1755 * This ioctl is used by mpg123.
1756 */
1757 spin_lock_irqsave(&state->unit->reg_lock, flags);
1758 if (state->wpcm.dmabuf.count != 0 && !state->wpcm.running) {
1759 ymf_start_dac(state);
1760 }
1761 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1762 return 0;
1763
1764 case SNDCTL_DSP_SETFRAGMENT:
1765 if (get_user(val, p))
1766 return -EFAULT;
1767 YMFDBGX("ymf_ioctl: cmd 0x%x(SETFRAG) fr 0x%04x:%04x(%d:%d)\n",
1768 cmd,
1769 (val >> 16) & 0xFFFF, val & 0xFFFF,
1770 (val >> 16) & 0xFFFF, val & 0xFFFF);
1771 dmabuf = &state->wpcm.dmabuf;
1772 dmabuf->ossfragshift = val & 0xffff;
1773 dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
1774 if (dmabuf->ossfragshift < 4)
1775 dmabuf->ossfragshift = 4;
1776 if (dmabuf->ossfragshift > 15)
1777 dmabuf->ossfragshift = 15;
1778 return 0;
1779
1780 case SNDCTL_DSP_GETOSPACE:
1781 YMFDBGX("ymf_ioctl: cmd 0x%x(GETOSPACE)\n", cmd);
1782 if (!(file->f_mode & FMODE_WRITE))
1783 return -EINVAL;
1784 dmabuf = &state->wpcm.dmabuf;
1785 if (!dmabuf->ready && (val = prog_dmabuf(state, 0)) != 0)
1786 return val;
1787 redzone = ymf_calc_lend(state->format.rate);
1788 redzone <<= state->format.shift;
1789 redzone *= 3;
1790 spin_lock_irqsave(&state->unit->reg_lock, flags);
1791 abinfo.fragsize = dmabuf->fragsize;
1792 abinfo.bytes = dmabuf->dmasize - dmabuf->count - redzone;
1793 abinfo.fragstotal = dmabuf->numfrag;
1794 abinfo.fragments = abinfo.bytes >> dmabuf->fragshift;
1795 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1796 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1797
1798 case SNDCTL_DSP_GETISPACE:
1799 YMFDBGX("ymf_ioctl: cmd 0x%x(GETISPACE)\n", cmd);
1800 if (!(file->f_mode & FMODE_READ))
1801 return -EINVAL;
1802 dmabuf = &state->rpcm.dmabuf;
1803 if (!dmabuf->ready && (val = prog_dmabuf(state, 1)) != 0)
1804 return val;
1805 spin_lock_irqsave(&state->unit->reg_lock, flags);
1806 abinfo.fragsize = dmabuf->fragsize;
1807 abinfo.bytes = dmabuf->count;
1808 abinfo.fragstotal = dmabuf->numfrag;
1809 abinfo.fragments = abinfo.bytes >> dmabuf->fragshift;
1810 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1811 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
1812
1813 case SNDCTL_DSP_NONBLOCK:
1814 YMFDBGX("ymf_ioctl: cmd 0x%x(NONBLOCK)\n", cmd);
1815 file->f_flags |= O_NONBLOCK;
1816 return 0;
1817
1818 case SNDCTL_DSP_GETCAPS:
1819 YMFDBGX("ymf_ioctl: cmd 0x%x(GETCAPS)\n", cmd);
1820 /* return put_user(DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP,
1821 p); */
1822 return put_user(0, p);
1823
1824 case SNDCTL_DSP_GETIPTR:
1825 YMFDBGX("ymf_ioctl: cmd 0x%x(GETIPTR)\n", cmd);
1826 if (!(file->f_mode & FMODE_READ))
1827 return -EINVAL;
1828 dmabuf = &state->rpcm.dmabuf;
1829 spin_lock_irqsave(&state->unit->reg_lock, flags);
1830 cinfo.bytes = dmabuf->total_bytes;
1831 cinfo.blocks = dmabuf->count >> dmabuf->fragshift;
1832 cinfo.ptr = dmabuf->hwptr;
1833 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1834 YMFDBGX("ymf_ioctl: GETIPTR ptr %d bytes %d\n",
1835 cinfo.ptr, cinfo.bytes);
1836 return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
1837
1838 case SNDCTL_DSP_GETOPTR:
1839 YMFDBGX("ymf_ioctl: cmd 0x%x(GETOPTR)\n", cmd);
1840 if (!(file->f_mode & FMODE_WRITE))
1841 return -EINVAL;
1842 dmabuf = &state->wpcm.dmabuf;
1843 spin_lock_irqsave(&state->unit->reg_lock, flags);
1844 cinfo.bytes = dmabuf->total_bytes;
1845 cinfo.blocks = dmabuf->count >> dmabuf->fragshift;
1846 cinfo.ptr = dmabuf->hwptr;
1847 spin_unlock_irqrestore(&state->unit->reg_lock, flags);
1848 YMFDBGX("ymf_ioctl: GETOPTR ptr %d bytes %d\n",
1849 cinfo.ptr, cinfo.bytes);
1850 return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
1851
1852 case SNDCTL_DSP_SETDUPLEX:
1853 YMFDBGX("ymf_ioctl: cmd 0x%x(SETDUPLEX)\n", cmd);
1854 return 0; /* Always duplex */
1855
1856 case SOUND_PCM_READ_RATE:
1857 YMFDBGX("ymf_ioctl: cmd 0x%x(READ_RATE)\n", cmd);
1858 return put_user(state->format.rate, p);
1859
1860 case SOUND_PCM_READ_CHANNELS:
1861 YMFDBGX("ymf_ioctl: cmd 0x%x(READ_CH)\n", cmd);
1862 return put_user(state->format.voices, p);
1863
1864 case SOUND_PCM_READ_BITS:
1865 YMFDBGX("ymf_ioctl: cmd 0x%x(READ_BITS)\n", cmd);
1866 return put_user(AFMT_S16_LE, p);
1867
1868 case SNDCTL_DSP_MAPINBUF:
1869 case SNDCTL_DSP_MAPOUTBUF:
1870 case SNDCTL_DSP_SETSYNCRO:
1871 case SOUND_PCM_WRITE_FILTER:
1872 case SOUND_PCM_READ_FILTER:
1873 YMFDBGX("ymf_ioctl: cmd 0x%x unsupported\n", cmd);
1874 return -ENOTTY;
1875
1876 default:
1877 /*
1878 * Some programs mix up audio devices and ioctls
1879 * or perhaps they expect "universal" ioctls,
1880 * for instance we get SNDCTL_TMR_CONTINUE here.
1881 * (mpg123 -g 100 ends here too - to be fixed.)
1882 */
1883 YMFDBGX("ymf_ioctl: cmd 0x%x unknown\n", cmd);
1884 break;
1885 }
1886 return -ENOTTY;
1887}
1888
1889/*
1890 * open(2)
1891 * We use upper part of the minor to distinguish between soundcards.
1892 * Channels are opened with a clone open.
1893 */
1894static int ymf_open(struct inode *inode, struct file *file)
1895{
1896 struct list_head *list;
1897 ymfpci_t *unit = NULL;
1898 int minor;
1899 struct ymf_state *state;
1900 int err;
1901
1902 minor = iminor(inode);
1903 if ((minor & 0x0F) == 3) { /* /dev/dspN */
1904 ;
1905 } else {
1906 return -ENXIO;
1907 }
1908
1909 unit = NULL; /* gcc warns */
1910 spin_lock(&ymf_devs_lock);
1911 list_for_each(list, &ymf_devs) {
1912 unit = list_entry(list, ymfpci_t, ymf_devs);
1913 if (((unit->dev_audio ^ minor) & ~0x0F) == 0)
1914 break;
1915 }
1916 spin_unlock(&ymf_devs_lock);
1917 if (unit == NULL)
1918 return -ENODEV;
1919
1920 down(&unit->open_sem);
1921
1922 if ((state = ymf_state_alloc(unit)) == NULL) {
1923 up(&unit->open_sem);
1924 return -ENOMEM;
1925 }
1926 list_add_tail(&state->chain, &unit->states);
1927
1928 file->private_data = state;
1929
1930 /*
1931 * ymf_read and ymf_write that we borrowed from cs46xx
1932 * allocate buffers with prog_dmabuf(). We call prog_dmabuf
1933 * here so that in case of DMA memory exhaustion open
1934 * fails rather than write.
1935 *
1936 * XXX prog_dmabuf allocates voice. Should allocate explicitly, above.
1937 */
1938 if (file->f_mode & FMODE_WRITE) {
1939 if (!state->wpcm.dmabuf.ready) {
1940 if ((err = prog_dmabuf(state, 0)) != 0) {
1941 goto out_nodma;
1942 }
1943 }
1944 }
1945 if (file->f_mode & FMODE_READ) {
1946 if (!state->rpcm.dmabuf.ready) {
1947 if ((err = prog_dmabuf(state, 1)) != 0) {
1948 goto out_nodma;
1949 }
1950 }
1951 }
1952
1953#if 0 /* test if interrupts work */
1954 ymfpci_writew(unit, YDSXGR_TIMERCOUNT, 0xfffe); /* ~ 680ms */
1955 ymfpci_writeb(unit, YDSXGR_TIMERCTRL,
1956 (YDSXGR_TIMERCTRL_TEN|YDSXGR_TIMERCTRL_TIEN));
1957#endif
1958 up(&unit->open_sem);
1959
1960 return nonseekable_open(inode, file);
1961
1962out_nodma:
1963 /*
1964 * XXX Broken custom: "goto out_xxx" in other place is
1965 * a nestable exception, but here it is not nestable due to semaphore.
1966 * XXX Doubtful technique of self-describing objects....
1967 */
1968 dealloc_dmabuf(unit, &state->wpcm.dmabuf);
1969 dealloc_dmabuf(unit, &state->rpcm.dmabuf);
1970 ymf_pcm_free_substream(&state->wpcm);
1971 ymf_pcm_free_substream(&state->rpcm);
1972
1973 list_del(&state->chain);
1974 kfree(state);
1975
1976 up(&unit->open_sem);
1977 return err;
1978}
1979
1980static int ymf_release(struct inode *inode, struct file *file)
1981{
1982 struct ymf_state *state = (struct ymf_state *)file->private_data;
1983 ymfpci_t *unit = state->unit;
1984
1985#if 0 /* test if interrupts work */
1986 ymfpci_writeb(unit, YDSXGR_TIMERCTRL, 0);
1987#endif
1988
1989 down(&unit->open_sem);
1990
1991 /*
1992 * XXX Solve the case of O_NONBLOCK close - don't deallocate here.
1993 * Deallocate when unloading the driver and we can wait.
1994 */
1995 ymf_wait_dac(state);
1996 ymf_stop_adc(state); /* fortunately, it's immediate */
1997 dealloc_dmabuf(unit, &state->wpcm.dmabuf);
1998 dealloc_dmabuf(unit, &state->rpcm.dmabuf);
1999 ymf_pcm_free_substream(&state->wpcm);
2000 ymf_pcm_free_substream(&state->rpcm);
2001
2002 list_del(&state->chain);
2003 file->private_data = NULL; /* Can you tell I programmed Solaris */
2004 kfree(state);
2005
2006 up(&unit->open_sem);
2007
2008 return 0;
2009}
2010
2011/*
2012 * Mixer operations are based on cs46xx.
2013 */
2014static int ymf_open_mixdev(struct inode *inode, struct file *file)
2015{
2016 int minor = iminor(inode);
2017 struct list_head *list;
2018 ymfpci_t *unit;
2019 int i;
2020
2021 spin_lock(&ymf_devs_lock);
2022 list_for_each(list, &ymf_devs) {
2023 unit = list_entry(list, ymfpci_t, ymf_devs);
2024 for (i = 0; i < NR_AC97; i++) {
2025 if (unit->ac97_codec[i] != NULL &&
2026 unit->ac97_codec[i]->dev_mixer == minor) {
2027 spin_unlock(&ymf_devs_lock);
2028 goto match;
2029 }
2030 }
2031 }
2032 spin_unlock(&ymf_devs_lock);
2033 return -ENODEV;
2034
2035 match:
2036 file->private_data = unit->ac97_codec[i];
2037
2038 return nonseekable_open(inode, file);
2039}
2040
2041static int ymf_ioctl_mixdev(struct inode *inode, struct file *file,
2042 unsigned int cmd, unsigned long arg)
2043{
2044 struct ac97_codec *codec = (struct ac97_codec *)file->private_data;
2045
2046 return codec->mixer_ioctl(codec, cmd, arg);
2047}
2048
2049static int ymf_release_mixdev(struct inode *inode, struct file *file)
2050{
2051 return 0;
2052}
2053
2054static /*const*/ struct file_operations ymf_fops = {
2055 .owner = THIS_MODULE,
2056 .llseek = no_llseek,
2057 .read = ymf_read,
2058 .write = ymf_write,
2059 .poll = ymf_poll,
2060 .ioctl = ymf_ioctl,
2061 .mmap = ymf_mmap,
2062 .open = ymf_open,
2063 .release = ymf_release,
2064};
2065
2066static /*const*/ struct file_operations ymf_mixer_fops = {
2067 .owner = THIS_MODULE,
2068 .llseek = no_llseek,
2069 .ioctl = ymf_ioctl_mixdev,
2070 .open = ymf_open_mixdev,
2071 .release = ymf_release_mixdev,
2072};
2073
2074/*
2075 */
2076
2077static int ymf_suspend(struct pci_dev *pcidev, pm_message_t unused)
2078{
2079 struct ymf_unit *unit = pci_get_drvdata(pcidev);
2080 unsigned long flags;
2081 struct ymf_dmabuf *dmabuf;
2082 struct list_head *p;
2083 struct ymf_state *state;
2084 struct ac97_codec *codec;
2085 int i;
2086
2087 spin_lock_irqsave(&unit->reg_lock, flags);
2088
2089 unit->suspended = 1;
2090
2091 for (i = 0; i < NR_AC97; i++) {
2092 if ((codec = unit->ac97_codec[i]) != NULL)
2093 ac97_save_state(codec);
2094 }
2095
2096 list_for_each(p, &unit->states) {
2097 state = list_entry(p, struct ymf_state, chain);
2098
2099 dmabuf = &state->wpcm.dmabuf;
2100 dmabuf->hwptr = dmabuf->swptr = 0;
2101 dmabuf->total_bytes = 0;
2102 dmabuf->count = 0;
2103
2104 dmabuf = &state->rpcm.dmabuf;
2105 dmabuf->hwptr = dmabuf->swptr = 0;
2106 dmabuf->total_bytes = 0;
2107 dmabuf->count = 0;
2108 }
2109
2110 ymfpci_writel(unit, YDSXGR_NATIVEDACOUTVOL, 0);
2111 ymfpci_disable_dsp(unit);
2112
2113 spin_unlock_irqrestore(&unit->reg_lock, flags);
2114
2115 return 0;
2116}
2117
2118static int ymf_resume(struct pci_dev *pcidev)
2119{
2120 struct ymf_unit *unit = pci_get_drvdata(pcidev);
2121 unsigned long flags;
2122 struct list_head *p;
2123 struct ymf_state *state;
2124 struct ac97_codec *codec;
2125 int i;
2126
2127 ymfpci_aclink_reset(unit->pci);
2128 ymfpci_codec_ready(unit, 0, 1); /* prints diag if not ready. */
2129
2130#ifdef CONFIG_SOUND_YMFPCI_LEGACY
2131 /* XXX At this time the legacy registers are probably deprogrammed. */
2132#endif
2133
2134 ymfpci_download_image(unit);
2135
2136 ymf_memload(unit);
2137
2138 spin_lock_irqsave(&unit->reg_lock, flags);
2139
2140 if (unit->start_count) {
2141 ymfpci_writel(unit, YDSXGR_MODE, 3);
2142 unit->active_bank = ymfpci_readl(unit, YDSXGR_CTRLSELECT) & 1;
2143 }
2144
2145 for (i = 0; i < NR_AC97; i++) {
2146 if ((codec = unit->ac97_codec[i]) != NULL)
2147 ac97_restore_state(codec);
2148 }
2149
2150 unit->suspended = 0;
2151 list_for_each(p, &unit->states) {
2152 state = list_entry(p, struct ymf_state, chain);
2153 wake_up(&state->wpcm.dmabuf.wait);
2154 wake_up(&state->rpcm.dmabuf.wait);
2155 }
2156
2157 spin_unlock_irqrestore(&unit->reg_lock, flags);
2158 return 0;
2159}
2160
2161/*
2162 * initialization routines
2163 */
2164
2165#ifdef CONFIG_SOUND_YMFPCI_LEGACY
2166
2167static int ymfpci_setup_legacy(ymfpci_t *unit, struct pci_dev *pcidev)
2168{
2169 int v;
2170 int mpuio = -1, oplio = -1;
2171
2172 switch (unit->iomidi) {
2173 case 0x330:
2174 mpuio = 0;
2175 break;
2176 case 0x300:
2177 mpuio = 1;
2178 break;
2179 case 0x332:
2180 mpuio = 2;
2181 break;
2182 case 0x334:
2183 mpuio = 3;
2184 break;
2185 default: ;
2186 }
2187
2188 switch (unit->iosynth) {
2189 case 0x388:
2190 oplio = 0;
2191 break;
2192 case 0x398:
2193 oplio = 1;
2194 break;
2195 case 0x3a0:
2196 oplio = 2;
2197 break;
2198 case 0x3a8:
2199 oplio = 3;
2200 break;
2201 default: ;
2202 }
2203
2204 if (mpuio >= 0 || oplio >= 0) {
2205 /* 0x0020: 1 - 10 bits of I/O address decoded, 0 - 16 bits. */
2206 v = 0x001e;
2207 pci_write_config_word(pcidev, PCIR_LEGCTRL, v);
2208
2209 switch (pcidev->device) {
2210 case PCI_DEVICE_ID_YAMAHA_724:
2211 case PCI_DEVICE_ID_YAMAHA_740:
2212 case PCI_DEVICE_ID_YAMAHA_724F:
2213 case PCI_DEVICE_ID_YAMAHA_740C:
2214 v = 0x8800;
2215 if (mpuio >= 0) { v |= mpuio<<4; }
2216 if (oplio >= 0) { v |= oplio; }
2217 pci_write_config_word(pcidev, PCIR_ELEGCTRL, v);
2218 break;
2219
2220 case PCI_DEVICE_ID_YAMAHA_744:
2221 case PCI_DEVICE_ID_YAMAHA_754:
2222 v = 0x8800;
2223 pci_write_config_word(pcidev, PCIR_ELEGCTRL, v);
2224 if (oplio >= 0) {
2225 pci_write_config_word(pcidev, PCIR_OPLADR, unit->iosynth);
2226 }
2227 if (mpuio >= 0) {
2228 pci_write_config_word(pcidev, PCIR_MPUADR, unit->iomidi);
2229 }
2230 break;
2231
2232 default:
2233 printk(KERN_ERR "ymfpci: Unknown device ID: 0x%x\n",
2234 pcidev->device);
2235 return -EINVAL;
2236 }
2237 }
2238
2239 return 0;
2240}
2241#endif /* CONFIG_SOUND_YMFPCI_LEGACY */
2242
2243static void ymfpci_aclink_reset(struct pci_dev * pci)
2244{
2245 u8 cmd;
2246
2247 /*
2248 * In the 744, 754 only 0x01 exists, 0x02 is undefined.
2249 * It does not seem to hurt to trip both regardless of revision.
2250 */
2251 pci_read_config_byte(pci, PCIR_DSXGCTRL, &cmd);
2252 pci_write_config_byte(pci, PCIR_DSXGCTRL, cmd & 0xfc);
2253 pci_write_config_byte(pci, PCIR_DSXGCTRL, cmd | 0x03);
2254 pci_write_config_byte(pci, PCIR_DSXGCTRL, cmd & 0xfc);
2255
2256 pci_write_config_word(pci, PCIR_DSXPWRCTRL1, 0);
2257 pci_write_config_word(pci, PCIR_DSXPWRCTRL2, 0);
2258}
2259
2260static void ymfpci_enable_dsp(ymfpci_t *codec)
2261{
2262 ymfpci_writel(codec, YDSXGR_CONFIG, 0x00000001);
2263}
2264
2265static void ymfpci_disable_dsp(ymfpci_t *codec)
2266{
2267 u32 val;
2268 int timeout = 1000;
2269
2270 val = ymfpci_readl(codec, YDSXGR_CONFIG);
2271 if (val)
2272 ymfpci_writel(codec, YDSXGR_CONFIG, 0x00000000);
2273 while (timeout-- > 0) {
2274 val = ymfpci_readl(codec, YDSXGR_STATUS);
2275 if ((val & 0x00000002) == 0)
2276 break;
2277 }
2278}
2279
2280#include "ymfpci_image.h"
2281
2282static void ymfpci_download_image(ymfpci_t *codec)
2283{
2284 int i, ver_1e;
2285 u16 ctrl;
2286
2287 ymfpci_writel(codec, YDSXGR_NATIVEDACOUTVOL, 0x00000000);
2288 ymfpci_disable_dsp(codec);
2289 ymfpci_writel(codec, YDSXGR_MODE, 0x00010000);
2290 ymfpci_writel(codec, YDSXGR_MODE, 0x00000000);
2291 ymfpci_writel(codec, YDSXGR_MAPOFREC, 0x00000000);
2292 ymfpci_writel(codec, YDSXGR_MAPOFEFFECT, 0x00000000);
2293 ymfpci_writel(codec, YDSXGR_PLAYCTRLBASE, 0x00000000);
2294 ymfpci_writel(codec, YDSXGR_RECCTRLBASE, 0x00000000);
2295 ymfpci_writel(codec, YDSXGR_EFFCTRLBASE, 0x00000000);
2296 ctrl = ymfpci_readw(codec, YDSXGR_GLOBALCTRL);
2297 ymfpci_writew(codec, YDSXGR_GLOBALCTRL, ctrl & ~0x0007);
2298
2299 /* setup DSP instruction code */
2300 for (i = 0; i < YDSXG_DSPLENGTH / 4; i++)
2301 ymfpci_writel(codec, YDSXGR_DSPINSTRAM + (i << 2), DspInst[i]);
2302
2303 switch (codec->pci->device) {
2304 case PCI_DEVICE_ID_YAMAHA_724F:
2305 case PCI_DEVICE_ID_YAMAHA_740C:
2306 case PCI_DEVICE_ID_YAMAHA_744:
2307 case PCI_DEVICE_ID_YAMAHA_754:
2308 ver_1e = 1;
2309 break;
2310 default:
2311 ver_1e = 0;
2312 }
2313
2314 if (ver_1e) {
2315 /* setup control instruction code */
2316 for (i = 0; i < YDSXG_CTRLLENGTH / 4; i++)
2317 ymfpci_writel(codec, YDSXGR_CTRLINSTRAM + (i << 2), CntrlInst1E[i]);
2318 } else {
2319 for (i = 0; i < YDSXG_CTRLLENGTH / 4; i++)
2320 ymfpci_writel(codec, YDSXGR_CTRLINSTRAM + (i << 2), CntrlInst[i]);
2321 }
2322
2323 ymfpci_enable_dsp(codec);
2324
2325 /* 0.02s sounds not too bad, we may do schedule_timeout() later. */
2326 mdelay(20); /* seems we need some delay after downloading image.. */
2327}
2328
2329static int ymfpci_memalloc(ymfpci_t *codec)
2330{
2331 unsigned int playback_ctrl_size;
2332 unsigned int bank_size_playback;
2333 unsigned int bank_size_capture;
2334 unsigned int bank_size_effect;
2335 unsigned int size;
2336 unsigned int off;
2337 char *ptr;
2338 dma_addr_t pba;
2339 int voice, bank;
2340
2341 playback_ctrl_size = 4 + 4 * YDSXG_PLAYBACK_VOICES;
2342 bank_size_playback = ymfpci_readl(codec, YDSXGR_PLAYCTRLSIZE) << 2;
2343 bank_size_capture = ymfpci_readl(codec, YDSXGR_RECCTRLSIZE) << 2;
2344 bank_size_effect = ymfpci_readl(codec, YDSXGR_EFFCTRLSIZE) << 2;
2345 codec->work_size = YDSXG_DEFAULT_WORK_SIZE;
2346
2347 size = ((playback_ctrl_size + 0x00ff) & ~0x00ff) +
2348 ((bank_size_playback * 2 * YDSXG_PLAYBACK_VOICES + 0xff) & ~0xff) +
2349 ((bank_size_capture * 2 * YDSXG_CAPTURE_VOICES + 0xff) & ~0xff) +
2350 ((bank_size_effect * 2 * YDSXG_EFFECT_VOICES + 0xff) & ~0xff) +
2351 codec->work_size;
2352
2353 ptr = pci_alloc_consistent(codec->pci, size + 0xff, &pba);
2354 if (ptr == NULL)
2355 return -ENOMEM;
2356 codec->dma_area_va = ptr;
2357 codec->dma_area_ba = pba;
2358 codec->dma_area_size = size + 0xff;
2359
2360 off = (unsigned long)ptr & 0xff;
2361 if (off) {
2362 ptr += 0x100 - off;
2363 pba += 0x100 - off;
2364 }
2365
2366 /*
2367 * Hardware requires only ptr[playback_ctrl_size] zeroed,
2368 * but in our judgement it is a wrong kind of savings, so clear it all.
2369 */
2370 memset(ptr, 0, size);
2371
2372 codec->ctrl_playback = (u32 *)ptr;
2373 codec->ctrl_playback_ba = pba;
2374 codec->ctrl_playback[0] = cpu_to_le32(YDSXG_PLAYBACK_VOICES);
2375 ptr += (playback_ctrl_size + 0x00ff) & ~0x00ff;
2376 pba += (playback_ctrl_size + 0x00ff) & ~0x00ff;
2377
2378 off = 0;
2379 for (voice = 0; voice < YDSXG_PLAYBACK_VOICES; voice++) {
2380 codec->voices[voice].number = voice;
2381 codec->voices[voice].bank =
2382 (ymfpci_playback_bank_t *) (ptr + off);
2383 codec->voices[voice].bank_ba = pba + off;
2384 off += 2 * bank_size_playback; /* 2 banks */
2385 }
2386 off = (off + 0xff) & ~0xff;
2387 ptr += off;
2388 pba += off;
2389
2390 off = 0;
2391 codec->bank_base_capture = pba;
2392 for (voice = 0; voice < YDSXG_CAPTURE_VOICES; voice++)
2393 for (bank = 0; bank < 2; bank++) {
2394 codec->bank_capture[voice][bank] =
2395 (ymfpci_capture_bank_t *) (ptr + off);
2396 off += bank_size_capture;
2397 }
2398 off = (off + 0xff) & ~0xff;
2399 ptr += off;
2400 pba += off;
2401
2402 off = 0;
2403 codec->bank_base_effect = pba;
2404 for (voice = 0; voice < YDSXG_EFFECT_VOICES; voice++)
2405 for (bank = 0; bank < 2; bank++) {
2406 codec->bank_effect[voice][bank] =
2407 (ymfpci_effect_bank_t *) (ptr + off);
2408 off += bank_size_effect;
2409 }
2410 off = (off + 0xff) & ~0xff;
2411 ptr += off;
2412 pba += off;
2413
2414 codec->work_base = pba;
2415
2416 return 0;
2417}
2418
2419static void ymfpci_memfree(ymfpci_t *codec)
2420{
2421 ymfpci_writel(codec, YDSXGR_PLAYCTRLBASE, 0);
2422 ymfpci_writel(codec, YDSXGR_RECCTRLBASE, 0);
2423 ymfpci_writel(codec, YDSXGR_EFFCTRLBASE, 0);
2424 ymfpci_writel(codec, YDSXGR_WORKBASE, 0);
2425 ymfpci_writel(codec, YDSXGR_WORKSIZE, 0);
2426 pci_free_consistent(codec->pci,
2427 codec->dma_area_size, codec->dma_area_va, codec->dma_area_ba);
2428}
2429
2430static void ymf_memload(ymfpci_t *unit)
2431{
2432
2433 ymfpci_writel(unit, YDSXGR_PLAYCTRLBASE, unit->ctrl_playback_ba);
2434 ymfpci_writel(unit, YDSXGR_RECCTRLBASE, unit->bank_base_capture);
2435 ymfpci_writel(unit, YDSXGR_EFFCTRLBASE, unit->bank_base_effect);
2436 ymfpci_writel(unit, YDSXGR_WORKBASE, unit->work_base);
2437 ymfpci_writel(unit, YDSXGR_WORKSIZE, unit->work_size >> 2);
2438
2439 /* S/PDIF output initialization */
2440 ymfpci_writew(unit, YDSXGR_SPDIFOUTCTRL, 0);
2441 ymfpci_writew(unit, YDSXGR_SPDIFOUTSTATUS,
2442 SND_PCM_AES0_CON_EMPHASIS_NONE |
2443 (SND_PCM_AES1_CON_ORIGINAL << 8) |
2444 (SND_PCM_AES1_CON_PCM_CODER << 8));
2445
2446 /* S/PDIF input initialization */
2447 ymfpci_writew(unit, YDSXGR_SPDIFINCTRL, 0);
2448
2449 /* move this volume setup to mixer */
2450 ymfpci_writel(unit, YDSXGR_NATIVEDACOUTVOL, 0x3fff3fff);
2451 ymfpci_writel(unit, YDSXGR_BUF441OUTVOL, 0);
2452 ymfpci_writel(unit, YDSXGR_NATIVEADCINVOL, 0x3fff3fff);
2453 ymfpci_writel(unit, YDSXGR_NATIVEDACINVOL, 0x3fff3fff);
2454}
2455
2456static int ymf_ac97_init(ymfpci_t *unit, int num_ac97)
2457{
2458 struct ac97_codec *codec;
2459 u16 eid;
2460
2461 if ((codec = ac97_alloc_codec()) == NULL)
2462 return -ENOMEM;
2463
2464 /* initialize some basic codec information, other fields will be filled
2465 in ac97_probe_codec */
2466 codec->private_data = unit;
2467 codec->id = num_ac97;
2468
2469 codec->codec_read = ymfpci_codec_read;
2470 codec->codec_write = ymfpci_codec_write;
2471
2472 if (ac97_probe_codec(codec) == 0) {
2473 printk(KERN_ERR "ymfpci: ac97_probe_codec failed\n");
2474 goto out_kfree;
2475 }
2476
2477 eid = ymfpci_codec_read(codec, AC97_EXTENDED_ID);
2478 if (eid==0xFFFF) {
2479 printk(KERN_WARNING "ymfpci: no codec attached ?\n");
2480 goto out_kfree;
2481 }
2482
2483 unit->ac97_features = eid;
2484
2485 if ((codec->dev_mixer = register_sound_mixer(&ymf_mixer_fops, -1)) < 0) {
2486 printk(KERN_ERR "ymfpci: couldn't register mixer!\n");
2487 goto out_kfree;
2488 }
2489
2490 unit->ac97_codec[num_ac97] = codec;
2491
2492 return 0;
2493 out_kfree:
2494 ac97_release_codec(codec);
2495 return -ENODEV;
2496}
2497
2498#ifdef CONFIG_SOUND_YMFPCI_LEGACY
2499# ifdef MODULE
2500static int mpu_io;
2501static int synth_io;
2502module_param(mpu_io, int, 0);
2503module_param(synth_io, int, 0);
2504# else
2505static int mpu_io = 0x330;
2506static int synth_io = 0x388;
2507# endif
2508static int assigned;
2509#endif /* CONFIG_SOUND_YMFPCI_LEGACY */
2510
2511static int __devinit ymf_probe_one(struct pci_dev *pcidev, const struct pci_device_id *ent)
2512{
2513 u16 ctrl;
2514 unsigned long base;
2515 ymfpci_t *codec;
2516
2517 int err;
2518
2519 if ((err = pci_enable_device(pcidev)) != 0) {
2520 printk(KERN_ERR "ymfpci: pci_enable_device failed\n");
2521 return err;
2522 }
2523 base = pci_resource_start(pcidev, 0);
2524
2525 if ((codec = kmalloc(sizeof(ymfpci_t), GFP_KERNEL)) == NULL) {
2526 printk(KERN_ERR "ymfpci: no core\n");
2527 return -ENOMEM;
2528 }
2529 memset(codec, 0, sizeof(*codec));
2530
2531 spin_lock_init(&codec->reg_lock);
2532 spin_lock_init(&codec->voice_lock);
2533 spin_lock_init(&codec->ac97_lock);
2534 init_MUTEX(&codec->open_sem);
2535 INIT_LIST_HEAD(&codec->states);
2536 codec->pci = pcidev;
2537
2538 pci_read_config_byte(pcidev, PCI_REVISION_ID, &codec->rev);
2539
2540 if (request_mem_region(base, 0x8000, "ymfpci") == NULL) {
2541 printk(KERN_ERR "ymfpci: unable to request mem region\n");
2542 goto out_free;
2543 }
2544
2545 if ((codec->reg_area_virt = ioremap(base, 0x8000)) == NULL) {
2546 printk(KERN_ERR "ymfpci: unable to map registers\n");
2547 goto out_release_region;
2548 }
2549
2550 pci_set_master(pcidev);
2551
2552 printk(KERN_INFO "ymfpci: %s at 0x%lx IRQ %d\n",
2553 (char *)ent->driver_data, base, pcidev->irq);
2554
2555 ymfpci_aclink_reset(pcidev);
2556 if (ymfpci_codec_ready(codec, 0, 1) < 0)
2557 goto out_unmap;
2558
2559#ifdef CONFIG_SOUND_YMFPCI_LEGACY
2560 if (assigned == 0) {
2561 codec->iomidi = mpu_io;
2562 codec->iosynth = synth_io;
2563 if (ymfpci_setup_legacy(codec, pcidev) < 0)
2564 goto out_unmap;
2565 assigned = 1;
2566 }
2567#endif
2568
2569 ymfpci_download_image(codec);
2570
2571 if (ymfpci_memalloc(codec) < 0)
2572 goto out_disable_dsp;
2573 ymf_memload(codec);
2574
2575 if (request_irq(pcidev->irq, ymf_interrupt, SA_SHIRQ, "ymfpci", codec) != 0) {
2576 printk(KERN_ERR "ymfpci: unable to request IRQ %d\n",
2577 pcidev->irq);
2578 goto out_memfree;
2579 }
2580
2581 /* register /dev/dsp */
2582 if ((codec->dev_audio = register_sound_dsp(&ymf_fops, -1)) < 0) {
2583 printk(KERN_ERR "ymfpci: unable to register dsp\n");
2584 goto out_free_irq;
2585 }
2586
2587 /*
2588 * Poke just the primary for the moment.
2589 */
2590 if ((err = ymf_ac97_init(codec, 0)) != 0)
2591 goto out_unregister_sound_dsp;
2592
2593#ifdef CONFIG_SOUND_YMFPCI_LEGACY
2594 codec->opl3_data.name = "ymfpci";
2595 codec->mpu_data.name = "ymfpci";
2596
2597 codec->opl3_data.io_base = codec->iosynth;
2598 codec->opl3_data.irq = -1;
2599
2600 codec->mpu_data.io_base = codec->iomidi;
2601 codec->mpu_data.irq = -1; /* May be different from our PCI IRQ. */
2602
2603 if (codec->iomidi) {
2604 if (!probe_uart401(&codec->mpu_data, THIS_MODULE)) {
2605 codec->iomidi = 0; /* XXX kludge */
2606 }
2607 }
2608#endif /* CONFIG_SOUND_YMFPCI_LEGACY */
2609
2610 /* put it into driver list */
2611 spin_lock(&ymf_devs_lock);
2612 list_add_tail(&codec->ymf_devs, &ymf_devs);
2613 spin_unlock(&ymf_devs_lock);
2614 pci_set_drvdata(pcidev, codec);
2615
2616 return 0;
2617
2618 out_unregister_sound_dsp:
2619 unregister_sound_dsp(codec->dev_audio);
2620 out_free_irq:
2621 free_irq(pcidev->irq, codec);
2622 out_memfree:
2623 ymfpci_memfree(codec);
2624 out_disable_dsp:
2625 ymfpci_disable_dsp(codec);
2626 ctrl = ymfpci_readw(codec, YDSXGR_GLOBALCTRL);
2627 ymfpci_writew(codec, YDSXGR_GLOBALCTRL, ctrl & ~0x0007);
2628 ymfpci_writel(codec, YDSXGR_STATUS, ~0);
2629 out_unmap:
2630 iounmap(codec->reg_area_virt);
2631 out_release_region:
2632 release_mem_region(pci_resource_start(pcidev, 0), 0x8000);
2633 out_free:
2634 if (codec->ac97_codec[0])
2635 ac97_release_codec(codec->ac97_codec[0]);
2636 return -ENODEV;
2637}
2638
2639static void __devexit ymf_remove_one(struct pci_dev *pcidev)
2640{
2641 __u16 ctrl;
2642 ymfpci_t *codec = pci_get_drvdata(pcidev);
2643
2644 /* remove from list of devices */
2645 spin_lock(&ymf_devs_lock);
2646 list_del(&codec->ymf_devs);
2647 spin_unlock(&ymf_devs_lock);
2648
2649 unregister_sound_mixer(codec->ac97_codec[0]->dev_mixer);
2650 ac97_release_codec(codec->ac97_codec[0]);
2651 unregister_sound_dsp(codec->dev_audio);
2652 free_irq(pcidev->irq, codec);
2653 ymfpci_memfree(codec);
2654 ymfpci_writel(codec, YDSXGR_STATUS, ~0);
2655 ymfpci_disable_dsp(codec);
2656 ctrl = ymfpci_readw(codec, YDSXGR_GLOBALCTRL);
2657 ymfpci_writew(codec, YDSXGR_GLOBALCTRL, ctrl & ~0x0007);
2658 iounmap(codec->reg_area_virt);
2659 release_mem_region(pci_resource_start(pcidev, 0), 0x8000);
2660#ifdef CONFIG_SOUND_YMFPCI_LEGACY
2661 if (codec->iomidi) {
2662 unload_uart401(&codec->mpu_data);
2663 }
2664#endif /* CONFIG_SOUND_YMFPCI_LEGACY */
2665}
2666
2667MODULE_AUTHOR("Jaroslav Kysela");
2668MODULE_DESCRIPTION("Yamaha YMF7xx PCI Audio");
2669MODULE_LICENSE("GPL");
2670
2671static struct pci_driver ymfpci_driver = {
2672 .name = "ymfpci",
2673 .id_table = ymf_id_tbl,
2674 .probe = ymf_probe_one,
2675 .remove = __devexit_p(ymf_remove_one),
2676 .suspend = ymf_suspend,
2677 .resume = ymf_resume
2678};
2679
2680static int __init ymf_init_module(void)
2681{
2682 return pci_module_init(&ymfpci_driver);
2683}
2684
2685static void __exit ymf_cleanup_module (void)
2686{
2687 pci_unregister_driver(&ymfpci_driver);
2688}
2689
2690module_init(ymf_init_module);
2691module_exit(ymf_cleanup_module);
diff --git a/sound/oss/ymfpci.h b/sound/oss/ymfpci.h
new file mode 100644
index 000000000000..f810a100c641
--- /dev/null
+++ b/sound/oss/ymfpci.h
@@ -0,0 +1,360 @@
1#ifndef __YMFPCI_H
2#define __YMFPCI_H
3
4/*
5 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
6 * Definitions for Yahama YMF724/740/744/754 chips
7 *
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#include <linux/config.h>
25
26/*
27 * Direct registers
28 */
29
30/* #define YMFREG(codec, reg) (codec->port + YDSXGR_##reg) */
31
32#define YDSXGR_INTFLAG 0x0004
33#define YDSXGR_ACTIVITY 0x0006
34#define YDSXGR_GLOBALCTRL 0x0008
35#define YDSXGR_ZVCTRL 0x000A
36#define YDSXGR_TIMERCTRL 0x0010
37#define YDSXGR_TIMERCTRL_TEN 0x0001
38#define YDSXGR_TIMERCTRL_TIEN 0x0002
39#define YDSXGR_TIMERCOUNT 0x0012
40#define YDSXGR_SPDIFOUTCTRL 0x0018
41#define YDSXGR_SPDIFOUTSTATUS 0x001C
42#define YDSXGR_EEPROMCTRL 0x0020
43#define YDSXGR_SPDIFINCTRL 0x0034
44#define YDSXGR_SPDIFINSTATUS 0x0038
45#define YDSXGR_DSPPROGRAMDL 0x0048
46#define YDSXGR_DLCNTRL 0x004C
47#define YDSXGR_GPIOININTFLAG 0x0050
48#define YDSXGR_GPIOININTENABLE 0x0052
49#define YDSXGR_GPIOINSTATUS 0x0054
50#define YDSXGR_GPIOOUTCTRL 0x0056
51#define YDSXGR_GPIOFUNCENABLE 0x0058
52#define YDSXGR_GPIOTYPECONFIG 0x005A
53#define YDSXGR_AC97CMDDATA 0x0060
54#define YDSXGR_AC97CMDADR 0x0062
55#define YDSXGR_PRISTATUSDATA 0x0064
56#define YDSXGR_PRISTATUSADR 0x0066
57#define YDSXGR_SECSTATUSDATA 0x0068
58#define YDSXGR_SECSTATUSADR 0x006A
59#define YDSXGR_SECCONFIG 0x0070
60#define YDSXGR_LEGACYOUTVOL 0x0080
61#define YDSXGR_LEGACYOUTVOLL 0x0080
62#define YDSXGR_LEGACYOUTVOLR 0x0082
63#define YDSXGR_NATIVEDACOUTVOL 0x0084
64#define YDSXGR_NATIVEDACOUTVOLL 0x0084
65#define YDSXGR_NATIVEDACOUTVOLR 0x0086
66#define YDSXGR_SPDIFOUTVOL 0x0088
67#define YDSXGR_SPDIFOUTVOLL 0x0088
68#define YDSXGR_SPDIFOUTVOLR 0x008A
69#define YDSXGR_AC3OUTVOL 0x008C
70#define YDSXGR_AC3OUTVOLL 0x008C
71#define YDSXGR_AC3OUTVOLR 0x008E
72#define YDSXGR_PRIADCOUTVOL 0x0090
73#define YDSXGR_PRIADCOUTVOLL 0x0090
74#define YDSXGR_PRIADCOUTVOLR 0x0092
75#define YDSXGR_LEGACYLOOPVOL 0x0094
76#define YDSXGR_LEGACYLOOPVOLL 0x0094
77#define YDSXGR_LEGACYLOOPVOLR 0x0096
78#define YDSXGR_NATIVEDACLOOPVOL 0x0098
79#define YDSXGR_NATIVEDACLOOPVOLL 0x0098
80#define YDSXGR_NATIVEDACLOOPVOLR 0x009A
81#define YDSXGR_SPDIFLOOPVOL 0x009C
82#define YDSXGR_SPDIFLOOPVOLL 0x009E
83#define YDSXGR_SPDIFLOOPVOLR 0x009E
84#define YDSXGR_AC3LOOPVOL 0x00A0
85#define YDSXGR_AC3LOOPVOLL 0x00A0
86#define YDSXGR_AC3LOOPVOLR 0x00A2
87#define YDSXGR_PRIADCLOOPVOL 0x00A4
88#define YDSXGR_PRIADCLOOPVOLL 0x00A4
89#define YDSXGR_PRIADCLOOPVOLR 0x00A6
90#define YDSXGR_NATIVEADCINVOL 0x00A8
91#define YDSXGR_NATIVEADCINVOLL 0x00A8
92#define YDSXGR_NATIVEADCINVOLR 0x00AA
93#define YDSXGR_NATIVEDACINVOL 0x00AC
94#define YDSXGR_NATIVEDACINVOLL 0x00AC
95#define YDSXGR_NATIVEDACINVOLR 0x00AE
96#define YDSXGR_BUF441OUTVOL 0x00B0
97#define YDSXGR_BUF441OUTVOLL 0x00B0
98#define YDSXGR_BUF441OUTVOLR 0x00B2
99#define YDSXGR_BUF441LOOPVOL 0x00B4
100#define YDSXGR_BUF441LOOPVOLL 0x00B4
101#define YDSXGR_BUF441LOOPVOLR 0x00B6
102#define YDSXGR_SPDIFOUTVOL2 0x00B8
103#define YDSXGR_SPDIFOUTVOL2L 0x00B8
104#define YDSXGR_SPDIFOUTVOL2R 0x00BA
105#define YDSXGR_SPDIFLOOPVOL2 0x00BC
106#define YDSXGR_SPDIFLOOPVOL2L 0x00BC
107#define YDSXGR_SPDIFLOOPVOL2R 0x00BE
108#define YDSXGR_ADCSLOTSR 0x00C0
109#define YDSXGR_RECSLOTSR 0x00C4
110#define YDSXGR_ADCFORMAT 0x00C8
111#define YDSXGR_RECFORMAT 0x00CC
112#define YDSXGR_P44SLOTSR 0x00D0
113#define YDSXGR_STATUS 0x0100
114#define YDSXGR_CTRLSELECT 0x0104
115#define YDSXGR_MODE 0x0108
116#define YDSXGR_SAMPLECOUNT 0x010C
117#define YDSXGR_NUMOFSAMPLES 0x0110
118#define YDSXGR_CONFIG 0x0114
119#define YDSXGR_PLAYCTRLSIZE 0x0140
120#define YDSXGR_RECCTRLSIZE 0x0144
121#define YDSXGR_EFFCTRLSIZE 0x0148
122#define YDSXGR_WORKSIZE 0x014C
123#define YDSXGR_MAPOFREC 0x0150
124#define YDSXGR_MAPOFEFFECT 0x0154
125#define YDSXGR_PLAYCTRLBASE 0x0158
126#define YDSXGR_RECCTRLBASE 0x015C
127#define YDSXGR_EFFCTRLBASE 0x0160
128#define YDSXGR_WORKBASE 0x0164
129#define YDSXGR_DSPINSTRAM 0x1000
130#define YDSXGR_CTRLINSTRAM 0x4000
131
132#define YDSXG_AC97READCMD 0x8000
133#define YDSXG_AC97WRITECMD 0x0000
134
135#define PCIR_LEGCTRL 0x40
136#define PCIR_ELEGCTRL 0x42
137#define PCIR_DSXGCTRL 0x48
138#define PCIR_DSXPWRCTRL1 0x4a
139#define PCIR_DSXPWRCTRL2 0x4e
140#define PCIR_OPLADR 0x60
141#define PCIR_SBADR 0x62
142#define PCIR_MPUADR 0x64
143
144#define YDSXG_DSPLENGTH 0x0080
145#define YDSXG_CTRLLENGTH 0x3000
146
147#define YDSXG_DEFAULT_WORK_SIZE 0x0400
148
149#define YDSXG_PLAYBACK_VOICES 64
150#define YDSXG_CAPTURE_VOICES 2
151#define YDSXG_EFFECT_VOICES 5
152
153/* maxinum number of AC97 codecs connected, AC97 2.0 defined 4 */
154#define NR_AC97 2
155
156#define YMF_SAMPF 256 /* Samples per frame @48000 */
157
158/*
159 * The slot/voice control bank (2 of these per voice)
160 */
161
162typedef struct stru_ymfpci_playback_bank {
163 u32 format;
164 u32 loop_default;
165 u32 base; /* 32-bit address */
166 u32 loop_start; /* 32-bit offset */
167 u32 loop_end; /* 32-bit offset */
168 u32 loop_frac; /* 8-bit fraction - loop_start */
169 u32 delta_end; /* pitch delta end */
170 u32 lpfK_end;
171 u32 eg_gain_end;
172 u32 left_gain_end;
173 u32 right_gain_end;
174 u32 eff1_gain_end;
175 u32 eff2_gain_end;
176 u32 eff3_gain_end;
177 u32 lpfQ;
178 u32 status; /* P3: Always 0 for some reason. */
179 u32 num_of_frames;
180 u32 loop_count;
181 u32 start; /* P3: J. reads this to know where chip is. */
182 u32 start_frac;
183 u32 delta;
184 u32 lpfK;
185 u32 eg_gain;
186 u32 left_gain;
187 u32 right_gain;
188 u32 eff1_gain;
189 u32 eff2_gain;
190 u32 eff3_gain;
191 u32 lpfD1;
192 u32 lpfD2;
193} ymfpci_playback_bank_t;
194
195typedef struct stru_ymfpci_capture_bank {
196 u32 base; /* 32-bit address (aligned at 4) */
197 u32 loop_end; /* size in BYTES (aligned at 4) */
198 u32 start; /* 32-bit offset */
199 u32 num_of_loops; /* counter */
200} ymfpci_capture_bank_t;
201
202typedef struct stru_ymfpci_effect_bank {
203 u32 base; /* 32-bit address */
204 u32 loop_end; /* 32-bit offset */
205 u32 start; /* 32-bit offset */
206 u32 temp;
207} ymfpci_effect_bank_t;
208
209typedef struct ymf_voice ymfpci_voice_t;
210/*
211 * Throughout the code Yaroslav names YMF unit pointer "codec"
212 * even though it does not correspond to any codec. Must be historic.
213 * We replace it with "unit" over time.
214 * AC97 parts use "codec" to denote a codec, naturally.
215 */
216typedef struct ymf_unit ymfpci_t;
217
218typedef enum {
219 YMFPCI_PCM,
220 YMFPCI_SYNTH,
221 YMFPCI_MIDI
222} ymfpci_voice_type_t;
223
224struct ymf_voice {
225 // ymfpci_t *codec;
226 int number;
227 char use, pcm, synth, midi; // bool
228 ymfpci_playback_bank_t *bank;
229 struct ymf_pcm *ypcm;
230 dma_addr_t bank_ba;
231};
232
233struct ymf_capture {
234 // struct ymf_unit *unit;
235 int use;
236 ymfpci_capture_bank_t *bank;
237 struct ymf_pcm *ypcm;
238};
239
240struct ymf_unit {
241 u8 rev; /* PCI revision */
242 void __iomem *reg_area_virt;
243 void *dma_area_va;
244 dma_addr_t dma_area_ba;
245 unsigned int dma_area_size;
246
247 dma_addr_t bank_base_capture;
248 dma_addr_t bank_base_effect;
249 dma_addr_t work_base;
250 unsigned int work_size;
251
252 u32 *ctrl_playback;
253 dma_addr_t ctrl_playback_ba;
254 ymfpci_playback_bank_t *bank_playback[YDSXG_PLAYBACK_VOICES][2];
255 ymfpci_capture_bank_t *bank_capture[YDSXG_CAPTURE_VOICES][2];
256 ymfpci_effect_bank_t *bank_effect[YDSXG_EFFECT_VOICES][2];
257
258 int start_count;
259 int suspended;
260
261 u32 active_bank;
262 struct ymf_voice voices[YDSXG_PLAYBACK_VOICES];
263 struct ymf_capture capture[YDSXG_CAPTURE_VOICES];
264
265 struct ac97_codec *ac97_codec[NR_AC97];
266 u16 ac97_features;
267
268 struct pci_dev *pci;
269
270#ifdef CONFIG_SOUND_YMFPCI_LEGACY
271 /* legacy hardware resources */
272 unsigned int iosynth, iomidi;
273 struct address_info opl3_data, mpu_data;
274#endif
275
276 spinlock_t reg_lock;
277 spinlock_t voice_lock;
278 spinlock_t ac97_lock;
279
280 /* soundcore stuff */
281 int dev_audio;
282 struct semaphore open_sem;
283
284 struct list_head ymf_devs;
285 struct list_head states; /* List of states for this unit */
286};
287
288struct ymf_dmabuf {
289 dma_addr_t dma_addr;
290 void *rawbuf;
291 unsigned buforder;
292
293 /* OSS buffer management stuff */
294 unsigned numfrag;
295 unsigned fragshift;
296
297 /* our buffer acts like a circular ring */
298 unsigned hwptr; /* where dma last started */
299 unsigned swptr; /* where driver last clear/filled */
300 int count; /* fill count */
301 unsigned total_bytes; /* total bytes dmaed by hardware */
302
303 wait_queue_head_t wait; /* put process on wait queue when no more space in buffer */
304
305 /* redundant, but makes calculations easier */
306 unsigned fragsize;
307 unsigned dmasize; /* Total rawbuf[] size */
308
309 /* OSS stuff */
310 unsigned mapped:1;
311 unsigned ready:1;
312 unsigned ossfragshift;
313 int ossmaxfrags;
314 unsigned subdivision;
315};
316
317struct ymf_pcm_format {
318 int format; /* OSS format */
319 int rate; /* rate in Hz */
320 int voices; /* number of voices */
321 int shift; /* redundant, computed from the above */
322};
323
324typedef enum {
325 PLAYBACK_VOICE,
326 CAPTURE_REC,
327 CAPTURE_AC97,
328 EFFECT_DRY_LEFT,
329 EFFECT_DRY_RIGHT,
330 EFFECT_EFF1,
331 EFFECT_EFF2,
332 EFFECT_EFF3
333} ymfpci_pcm_type_t;
334
335/* This is variant record, but we hate unions. Little waste on pointers []. */
336struct ymf_pcm {
337 ymfpci_pcm_type_t type;
338 struct ymf_state *state;
339
340 ymfpci_voice_t *voices[2];
341 int capture_bank_number;
342
343 struct ymf_dmabuf dmabuf;
344 int running;
345 int spdif;
346};
347
348/*
349 * "Software" or virtual channel, an instance of opened /dev/dsp.
350 * It may have two physical channels (pcms) for duplex operations.
351 */
352
353struct ymf_state {
354 struct list_head chain;
355 struct ymf_unit *unit; /* backpointer */
356 struct ymf_pcm rpcm, wpcm;
357 struct ymf_pcm_format format;
358};
359
360#endif /* __YMFPCI_H */
diff --git a/sound/oss/ymfpci_image.h b/sound/oss/ymfpci_image.h
new file mode 100644
index 000000000000..112f2fff6c8e
--- /dev/null
+++ b/sound/oss/ymfpci_image.h
@@ -0,0 +1,1565 @@
1#ifndef _HWMCODE_
2#define _HWMCODE_
3
4static u32 DspInst[YDSXG_DSPLENGTH / 4] = {
5 0x00000081, 0x000001a4, 0x0000000a, 0x0000002f,
6 0x00080253, 0x01800317, 0x0000407b, 0x0000843f,
7 0x0001483c, 0x0001943c, 0x0005d83c, 0x00001c3c,
8 0x0000c07b, 0x00050c3f, 0x0121503c, 0x00000000,
9 0x00000000, 0x00000000, 0x00000000, 0x00000000,
10 0x00000000, 0x00000000, 0x00000000, 0x00000000,
11 0x00000000, 0x00000000, 0x00000000, 0x00000000,
12 0x00000000, 0x00000000, 0x00000000, 0x00000000
13};
14
15static u32 CntrlInst[YDSXG_CTRLLENGTH / 4] = {
16 0x000007, 0x240007, 0x0C0007, 0x1C0007,
17 0x060007, 0x700002, 0x000020, 0x030040,
18 0x007104, 0x004286, 0x030040, 0x000F0D,
19 0x000810, 0x20043A, 0x000282, 0x00020D,
20 0x000810, 0x20043A, 0x001282, 0x200E82,
21 0x001A82, 0x032D0D, 0x000810, 0x10043A,
22 0x02D38D, 0x000810, 0x18043A, 0x00010D,
23 0x020015, 0x0000FD, 0x000020, 0x038860,
24 0x039060, 0x038060, 0x038040, 0x038040,
25 0x038040, 0x018040, 0x000A7D, 0x038040,
26 0x038040, 0x018040, 0x200402, 0x000882,
27 0x08001A, 0x000904, 0x015986, 0x000007,
28 0x260007, 0x000007, 0x000007, 0x018A06,
29 0x000007, 0x030C8D, 0x000810, 0x18043A,
30 0x260007, 0x00087D, 0x018042, 0x00160A,
31 0x04A206, 0x000007, 0x00218D, 0x000810,
32 0x08043A, 0x21C206, 0x000007, 0x0007FD,
33 0x018042, 0x08000A, 0x000904, 0x029386,
34 0x000195, 0x090D04, 0x000007, 0x000820,
35 0x0000F5, 0x000B7D, 0x01F060, 0x0000FD,
36 0x032206, 0x018040, 0x000A7D, 0x038042,
37 0x13804A, 0x18000A, 0x001820, 0x059060,
38 0x058860, 0x018040, 0x0000FD, 0x018042,
39 0x70000A, 0x000115, 0x071144, 0x032386,
40 0x030000, 0x007020, 0x034A06, 0x018040,
41 0x00348D, 0x000810, 0x08043A, 0x21EA06,
42 0x000007, 0x02D38D, 0x000810, 0x18043A,
43 0x018206, 0x000007, 0x240007, 0x000F8D,
44 0x000810, 0x00163A, 0x002402, 0x005C02,
45 0x0028FD, 0x000020, 0x018040, 0x08000D,
46 0x000815, 0x510984, 0x000007, 0x00004D,
47 0x000E5D, 0x000E02, 0x00418D, 0x000810,
48 0x08043A, 0x2C8A06, 0x000007, 0x00008D,
49 0x000924, 0x000F02, 0x00458D, 0x000810,
50 0x08043A, 0x2C8A06, 0x000007, 0x00387D,
51 0x018042, 0x08000A, 0x001015, 0x010984,
52 0x018386, 0x000007, 0x01AA06, 0x000007,
53 0x0008FD, 0x018042, 0x18000A, 0x001904,
54 0x218086, 0x280007, 0x001810, 0x28043A,
55 0x280C02, 0x00000D, 0x000810, 0x28143A,
56 0x08808D, 0x000820, 0x0002FD, 0x018040,
57 0x200007, 0x00020D, 0x189904, 0x000007,
58 0x00402D, 0x0000BD, 0x0002FD, 0x018042,
59 0x08000A, 0x000904, 0x055A86, 0x000007,
60 0x000100, 0x000A20, 0x00047D, 0x018040,
61 0x018042, 0x20000A, 0x003015, 0x012144,
62 0x034986, 0x000007, 0x002104, 0x034986,
63 0x000007, 0x000F8D, 0x000810, 0x280C3A,
64 0x023944, 0x06C986, 0x000007, 0x001810,
65 0x28043A, 0x08810D, 0x000820, 0x0002FD,
66 0x018040, 0x200007, 0x002810, 0x78003A,
67 0x00688D, 0x000810, 0x08043A, 0x288A06,
68 0x000007, 0x00400D, 0x001015, 0x189904,
69 0x292904, 0x393904, 0x000007, 0x060206,
70 0x000007, 0x0004F5, 0x00007D, 0x000020,
71 0x00008D, 0x010860, 0x018040, 0x00047D,
72 0x038042, 0x21804A, 0x18000A, 0x021944,
73 0x215886, 0x000007, 0x004075, 0x71F104,
74 0x000007, 0x010042, 0x28000A, 0x002904,
75 0x212086, 0x000007, 0x003C0D, 0x30A904,
76 0x000007, 0x00077D, 0x018042, 0x08000A,
77 0x000904, 0x07DA86, 0x00057D, 0x002820,
78 0x03B060, 0x07F206, 0x018040, 0x003020,
79 0x03A860, 0x018040, 0x0002FD, 0x018042,
80 0x08000A, 0x000904, 0x07FA86, 0x000007,
81 0x00057D, 0x018042, 0x28040A, 0x000E8D,
82 0x000810, 0x280C3A, 0x00000D, 0x000810,
83 0x28143A, 0x09000D, 0x000820, 0x0002FD,
84 0x018040, 0x200007, 0x003DFD, 0x000020,
85 0x018040, 0x00107D, 0x008D8D, 0x000810,
86 0x08043A, 0x288A06, 0x000007, 0x000815,
87 0x08001A, 0x010984, 0x095186, 0x00137D,
88 0x200500, 0x280F20, 0x338F60, 0x3B8F60,
89 0x438F60, 0x4B8F60, 0x538F60, 0x5B8F60,
90 0x038A60, 0x018040, 0x007FBD, 0x383DC4,
91 0x000007, 0x001A7D, 0x001375, 0x018042,
92 0x09004A, 0x10000A, 0x0B8D04, 0x139504,
93 0x000007, 0x000820, 0x019060, 0x001104,
94 0x212086, 0x010040, 0x0017FD, 0x018042,
95 0x08000A, 0x000904, 0x212286, 0x000007,
96 0x00197D, 0x038042, 0x09804A, 0x10000A,
97 0x000924, 0x001664, 0x0011FD, 0x038042,
98 0x2B804A, 0x19804A, 0x00008D, 0x218944,
99 0x000007, 0x002244, 0x0AE186, 0x000007,
100 0x001A64, 0x002A24, 0x00197D, 0x080102,
101 0x100122, 0x000820, 0x039060, 0x018040,
102 0x003DFD, 0x00008D, 0x000820, 0x018040,
103 0x001375, 0x001A7D, 0x010042, 0x09804A,
104 0x10000A, 0x00021D, 0x0189E4, 0x2992E4,
105 0x309144, 0x000007, 0x00060D, 0x000A15,
106 0x000C1D, 0x001025, 0x00A9E4, 0x012BE4,
107 0x000464, 0x01B3E4, 0x0232E4, 0x000464,
108 0x000464, 0x000464, 0x000464, 0x00040D,
109 0x08B1C4, 0x000007, 0x000820, 0x000BF5,
110 0x030040, 0x00197D, 0x038042, 0x09804A,
111 0x000A24, 0x08000A, 0x080E64, 0x000007,
112 0x100122, 0x000820, 0x031060, 0x010040,
113 0x0064AC, 0x00027D, 0x000020, 0x018040,
114 0x00107D, 0x018042, 0x0011FD, 0x3B804A,
115 0x09804A, 0x20000A, 0x000095, 0x1A1144,
116 0x00A144, 0x0D2086, 0x00040D, 0x00B984,
117 0x0D2186, 0x0018FD, 0x018042, 0x0010FD,
118 0x09804A, 0x28000A, 0x000095, 0x010924,
119 0x002A64, 0x0D1186, 0x000007, 0x002904,
120 0x0D2286, 0x000007, 0x0D2A06, 0x080002,
121 0x00008D, 0x00387D, 0x000820, 0x018040,
122 0x00127D, 0x018042, 0x10000A, 0x003904,
123 0x0DD186, 0x00080D, 0x7FFFB5, 0x00B984,
124 0x0DA186, 0x000025, 0x0E7A06, 0x00002D,
125 0x000015, 0x00082D, 0x02C78D, 0x000820,
126 0x0EC206, 0x00000D, 0x7F8035, 0x00B984,
127 0x0E7186, 0x400025, 0x00008D, 0x110944,
128 0x000007, 0x00018D, 0x109504, 0x000007,
129 0x009164, 0x000424, 0x000424, 0x000424,
130 0x100102, 0x280002, 0x02C68D, 0x000820,
131 0x0EC206, 0x00018D, 0x00042D, 0x00008D,
132 0x109504, 0x000007, 0x00020D, 0x109184,
133 0x000007, 0x02C70D, 0x000820, 0x00008D,
134 0x0038FD, 0x018040, 0x003BFD, 0x001020,
135 0x03A860, 0x000815, 0x313184, 0x212184,
136 0x000007, 0x03B060, 0x03A060, 0x018040,
137 0x0022FD, 0x000095, 0x010924, 0x000424,
138 0x000424, 0x001264, 0x100102, 0x000820,
139 0x039060, 0x018040, 0x001924, 0x00FB8D,
140 0x00397D, 0x000820, 0x058040, 0x038042,
141 0x09844A, 0x000606, 0x08040A, 0x000424,
142 0x000424, 0x00117D, 0x018042, 0x08000A,
143 0x000A24, 0x280502, 0x280C02, 0x09800D,
144 0x000820, 0x0002FD, 0x018040, 0x200007,
145 0x0022FD, 0x018042, 0x08000A, 0x000095,
146 0x280DC4, 0x011924, 0x00197D, 0x018042,
147 0x0011FD, 0x09804A, 0x10000A, 0x0000B5,
148 0x113144, 0x0A8D04, 0x000007, 0x080A44,
149 0x129504, 0x000007, 0x0023FD, 0x001020,
150 0x038040, 0x101244, 0x000007, 0x000820,
151 0x039060, 0x018040, 0x0002FD, 0x018042,
152 0x08000A, 0x000904, 0x10FA86, 0x000007,
153 0x003BFD, 0x000100, 0x000A10, 0x0B807A,
154 0x13804A, 0x090984, 0x000007, 0x000095,
155 0x013D04, 0x118086, 0x10000A, 0x100002,
156 0x090984, 0x000007, 0x038042, 0x11804A,
157 0x090D04, 0x000007, 0x10000A, 0x090D84,
158 0x000007, 0x00257D, 0x000820, 0x018040,
159 0x00010D, 0x000810, 0x28143A, 0x00127D,
160 0x018042, 0x20000A, 0x00197D, 0x018042,
161 0x00117D, 0x31804A, 0x10000A, 0x003124,
162 0x01280D, 0x00397D, 0x000820, 0x058040,
163 0x038042, 0x09844A, 0x000606, 0x08040A,
164 0x300102, 0x003124, 0x000424, 0x000424,
165 0x001224, 0x280502, 0x001A4C, 0x130186,
166 0x700002, 0x00002D, 0x030000, 0x00387D,
167 0x018042, 0x10000A, 0x132A06, 0x002124,
168 0x0000AD, 0x100002, 0x00010D, 0x000924,
169 0x006B24, 0x01368D, 0x00397D, 0x000820,
170 0x058040, 0x038042, 0x09844A, 0x000606,
171 0x08040A, 0x003264, 0x00008D, 0x000A24,
172 0x001020, 0x00227D, 0x018040, 0x013C0D,
173 0x000810, 0x08043A, 0x29D206, 0x000007,
174 0x002820, 0x00207D, 0x018040, 0x00117D,
175 0x038042, 0x13804A, 0x33800A, 0x00387D,
176 0x018042, 0x08000A, 0x000904, 0x163A86,
177 0x000007, 0x00008D, 0x030964, 0x01478D,
178 0x00397D, 0x000820, 0x058040, 0x038042,
179 0x09844A, 0x000606, 0x08040A, 0x380102,
180 0x000424, 0x000424, 0x001224, 0x0002FD,
181 0x018042, 0x08000A, 0x000904, 0x14A286,
182 0x000007, 0x280502, 0x001A4C, 0x163986,
183 0x000007, 0x032164, 0x00632C, 0x003DFD,
184 0x018042, 0x08000A, 0x000095, 0x090904,
185 0x000007, 0x000820, 0x001A4C, 0x156186,
186 0x018040, 0x030000, 0x157A06, 0x002124,
187 0x00010D, 0x000924, 0x006B24, 0x015B8D,
188 0x00397D, 0x000820, 0x058040, 0x038042,
189 0x09844A, 0x000606, 0x08040A, 0x003A64,
190 0x000095, 0x001224, 0x0002FD, 0x018042,
191 0x08000A, 0x000904, 0x15DA86, 0x000007,
192 0x01628D, 0x000810, 0x08043A, 0x29D206,
193 0x000007, 0x14D206, 0x000007, 0x007020,
194 0x08010A, 0x10012A, 0x0020FD, 0x038860,
195 0x039060, 0x018040, 0x00227D, 0x018042,
196 0x003DFD, 0x08000A, 0x31844A, 0x000904,
197 0x16D886, 0x18008B, 0x00008D, 0x189904,
198 0x00312C, 0x17AA06, 0x000007, 0x00324C,
199 0x173386, 0x000007, 0x001904, 0x173086,
200 0x000007, 0x000095, 0x199144, 0x00222C,
201 0x003124, 0x00636C, 0x000E3D, 0x001375,
202 0x000BFD, 0x010042, 0x09804A, 0x10000A,
203 0x038AEC, 0x0393EC, 0x00224C, 0x17A986,
204 0x000007, 0x00008D, 0x189904, 0x00226C,
205 0x00322C, 0x30050A, 0x301DAB, 0x002083,
206 0x0018FD, 0x018042, 0x08000A, 0x018924,
207 0x300502, 0x001083, 0x001875, 0x010042,
208 0x10000A, 0x00008D, 0x010924, 0x001375,
209 0x330542, 0x330CCB, 0x332CCB, 0x3334CB,
210 0x333CCB, 0x3344CB, 0x334CCB, 0x3354CB,
211 0x305C8B, 0x006083, 0x0002F5, 0x010042,
212 0x08000A, 0x000904, 0x187A86, 0x000007,
213 0x001E2D, 0x0005FD, 0x018042, 0x08000A,
214 0x028924, 0x280502, 0x00060D, 0x000810,
215 0x280C3A, 0x00008D, 0x000810, 0x28143A,
216 0x0A808D, 0x000820, 0x0002F5, 0x010040,
217 0x220007, 0x001275, 0x030042, 0x21004A,
218 0x00008D, 0x1A0944, 0x000007, 0x01980D,
219 0x000810, 0x08043A, 0x2B2206, 0x000007,
220 0x0001F5, 0x030042, 0x0D004A, 0x10000A,
221 0x089144, 0x000007, 0x000820, 0x010040,
222 0x0025F5, 0x0A3144, 0x000007, 0x000820,
223 0x032860, 0x030040, 0x00217D, 0x038042,
224 0x0B804A, 0x10000A, 0x000820, 0x031060,
225 0x030040, 0x00008D, 0x000124, 0x00012C,
226 0x000E64, 0x001A64, 0x00636C, 0x08010A,
227 0x10012A, 0x000820, 0x031060, 0x030040,
228 0x0020FD, 0x018042, 0x08000A, 0x00227D,
229 0x018042, 0x10000A, 0x000820, 0x031060,
230 0x030040, 0x00197D, 0x018042, 0x08000A,
231 0x0022FD, 0x038042, 0x10000A, 0x000820,
232 0x031060, 0x030040, 0x090D04, 0x000007,
233 0x000820, 0x030040, 0x038042, 0x0B804A,
234 0x10000A, 0x000820, 0x031060, 0x030040,
235 0x038042, 0x13804A, 0x19804A, 0x110D04,
236 0x198D04, 0x000007, 0x08000A, 0x001020,
237 0x031860, 0x030860, 0x030040, 0x00008D,
238 0x0B0944, 0x000007, 0x000820, 0x010040,
239 0x0005F5, 0x030042, 0x08000A, 0x000820,
240 0x010040, 0x0000F5, 0x010042, 0x08000A,
241 0x000904, 0x1C6086, 0x001E75, 0x030042,
242 0x01044A, 0x000C0A, 0x1C7206, 0x000007,
243 0x000402, 0x000C02, 0x00177D, 0x001AF5,
244 0x018042, 0x03144A, 0x031C4A, 0x03244A,
245 0x032C4A, 0x03344A, 0x033C4A, 0x03444A,
246 0x004C0A, 0x00043D, 0x0013F5, 0x001AFD,
247 0x030042, 0x0B004A, 0x1B804A, 0x13804A,
248 0x20000A, 0x089144, 0x19A144, 0x0389E4,
249 0x0399EC, 0x005502, 0x005D0A, 0x030042,
250 0x0B004A, 0x1B804A, 0x13804A, 0x20000A,
251 0x089144, 0x19A144, 0x0389E4, 0x0399EC,
252 0x006502, 0x006D0A, 0x030042, 0x0B004A,
253 0x19004A, 0x2B804A, 0x13804A, 0x21804A,
254 0x30000A, 0x089144, 0x19A144, 0x2AB144,
255 0x0389E4, 0x0399EC, 0x007502, 0x007D0A,
256 0x03A9E4, 0x000702, 0x00107D, 0x000415,
257 0x018042, 0x08000A, 0x0109E4, 0x000F02,
258 0x002AF5, 0x0019FD, 0x010042, 0x09804A,
259 0x10000A, 0x000934, 0x001674, 0x0029F5,
260 0x010042, 0x10000A, 0x00917C, 0x002075,
261 0x010042, 0x08000A, 0x000904, 0x1ED286,
262 0x0026F5, 0x0027F5, 0x030042, 0x09004A,
263 0x10000A, 0x000A3C, 0x00167C, 0x001A75,
264 0x000BFD, 0x010042, 0x51804A, 0x48000A,
265 0x160007, 0x001075, 0x010042, 0x282C0A,
266 0x281D12, 0x282512, 0x001F32, 0x1E0007,
267 0x0E0007, 0x001975, 0x010042, 0x002DF5,
268 0x0D004A, 0x10000A, 0x009144, 0x1FB286,
269 0x010042, 0x28340A, 0x000E5D, 0x00008D,
270 0x000375, 0x000820, 0x010040, 0x05D2F4,
271 0x54D104, 0x00735C, 0x205386, 0x000007,
272 0x0C0007, 0x080007, 0x0A0007, 0x02040D,
273 0x000810, 0x08043A, 0x332206, 0x000007,
274 0x205A06, 0x000007, 0x080007, 0x002275,
275 0x010042, 0x20000A, 0x002104, 0x212086,
276 0x001E2D, 0x0002F5, 0x010042, 0x08000A,
277 0x000904, 0x209286, 0x000007, 0x002010,
278 0x30043A, 0x00057D, 0x0180C3, 0x08000A,
279 0x028924, 0x280502, 0x280C02, 0x0A810D,
280 0x000820, 0x0002F5, 0x010040, 0x220007,
281 0x0004FD, 0x018042, 0x70000A, 0x030000,
282 0x007020, 0x06FA06, 0x018040, 0x02180D,
283 0x000810, 0x08043A, 0x2B2206, 0x000007,
284 0x0002FD, 0x018042, 0x08000A, 0x000904,
285 0x218A86, 0x000007, 0x01F206, 0x000007,
286 0x000875, 0x0009FD, 0x00010D, 0x220A06,
287 0x000295, 0x000B75, 0x00097D, 0x00000D,
288 0x000515, 0x010042, 0x18000A, 0x001904,
289 0x287886, 0x0006F5, 0x001020, 0x010040,
290 0x0004F5, 0x000820, 0x010040, 0x000775,
291 0x010042, 0x09804A, 0x10000A, 0x001124,
292 0x000904, 0x22BA86, 0x000815, 0x080102,
293 0x101204, 0x22DA06, 0x000575, 0x081204,
294 0x000007, 0x100102, 0x000575, 0x000425,
295 0x021124, 0x100102, 0x000820, 0x031060,
296 0x010040, 0x001924, 0x287886, 0x00008D,
297 0x000464, 0x009D04, 0x278886, 0x180102,
298 0x000575, 0x010042, 0x28040A, 0x00018D,
299 0x000924, 0x280D02, 0x00000D, 0x000924,
300 0x281502, 0x10000D, 0x000820, 0x0002F5,
301 0x010040, 0x200007, 0x001175, 0x0002FD,
302 0x018042, 0x08000A, 0x000904, 0x23C286,
303 0x000007, 0x000100, 0x080B20, 0x130B60,
304 0x1B0B60, 0x030A60, 0x010040, 0x050042,
305 0x3D004A, 0x35004A, 0x2D004A, 0x20000A,
306 0x0006F5, 0x010042, 0x28140A, 0x0004F5,
307 0x010042, 0x08000A, 0x000315, 0x010D04,
308 0x24CA86, 0x004015, 0x000095, 0x010D04,
309 0x24B886, 0x100022, 0x10002A, 0x24E206,
310 0x000007, 0x333104, 0x2AA904, 0x000007,
311 0x032124, 0x280502, 0x001124, 0x000424,
312 0x000424, 0x003224, 0x00292C, 0x00636C,
313 0x25F386, 0x000007, 0x02B164, 0x000464,
314 0x000464, 0x00008D, 0x000A64, 0x280D02,
315 0x10008D, 0x000820, 0x0002F5, 0x010040,
316 0x220007, 0x00008D, 0x38B904, 0x000007,
317 0x03296C, 0x30010A, 0x0002F5, 0x010042,
318 0x08000A, 0x000904, 0x25BA86, 0x000007,
319 0x02312C, 0x28050A, 0x00008D, 0x01096C,
320 0x280D0A, 0x10010D, 0x000820, 0x0002F5,
321 0x010040, 0x220007, 0x001124, 0x000424,
322 0x000424, 0x003224, 0x300102, 0x032944,
323 0x267A86, 0x000007, 0x300002, 0x0004F5,
324 0x010042, 0x08000A, 0x000315, 0x010D04,
325 0x26C086, 0x003124, 0x000464, 0x300102,
326 0x0002F5, 0x010042, 0x08000A, 0x000904,
327 0x26CA86, 0x000007, 0x003124, 0x300502,
328 0x003924, 0x300583, 0x000883, 0x0005F5,
329 0x010042, 0x28040A, 0x00008D, 0x008124,
330 0x280D02, 0x00008D, 0x008124, 0x281502,
331 0x10018D, 0x000820, 0x0002F5, 0x010040,
332 0x220007, 0x001025, 0x000575, 0x030042,
333 0x09004A, 0x10000A, 0x0A0904, 0x121104,
334 0x000007, 0x001020, 0x050860, 0x050040,
335 0x0006FD, 0x018042, 0x09004A, 0x10000A,
336 0x0000A5, 0x0A0904, 0x121104, 0x000007,
337 0x000820, 0x019060, 0x010040, 0x0002F5,
338 0x010042, 0x08000A, 0x000904, 0x284286,
339 0x000007, 0x230A06, 0x000007, 0x000606,
340 0x000007, 0x0002F5, 0x010042, 0x08000A,
341 0x000904, 0x289286, 0x000007, 0x000100,
342 0x080B20, 0x138B60, 0x1B8B60, 0x238B60,
343 0x2B8B60, 0x338B60, 0x3B8B60, 0x438B60,
344 0x4B8B60, 0x538B60, 0x5B8B60, 0x638B60,
345 0x6B8B60, 0x738B60, 0x7B8B60, 0x038F60,
346 0x0B8F60, 0x138F60, 0x1B8F60, 0x238F60,
347 0x2B8F60, 0x338F60, 0x3B8F60, 0x438F60,
348 0x4B8F60, 0x538F60, 0x5B8F60, 0x638F60,
349 0x6B8F60, 0x738F60, 0x7B8F60, 0x038A60,
350 0x000606, 0x018040, 0x00008D, 0x000A64,
351 0x280D02, 0x000A24, 0x00027D, 0x018042,
352 0x10000A, 0x001224, 0x0003FD, 0x018042,
353 0x08000A, 0x000904, 0x2A8286, 0x000007,
354 0x00018D, 0x000A24, 0x000464, 0x000464,
355 0x080102, 0x000924, 0x000424, 0x000424,
356 0x100102, 0x02000D, 0x009144, 0x2AD986,
357 0x000007, 0x0001FD, 0x018042, 0x08000A,
358 0x000A44, 0x2ABB86, 0x018042, 0x0A000D,
359 0x000820, 0x0002FD, 0x018040, 0x200007,
360 0x00027D, 0x001020, 0x000606, 0x018040,
361 0x0002F5, 0x010042, 0x08000A, 0x000904,
362 0x2B2A86, 0x000007, 0x00037D, 0x018042,
363 0x08000A, 0x000904, 0x2B5A86, 0x000007,
364 0x000075, 0x002E7D, 0x010042, 0x0B804A,
365 0x000020, 0x000904, 0x000686, 0x010040,
366 0x31844A, 0x30048B, 0x000883, 0x00008D,
367 0x000810, 0x28143A, 0x00008D, 0x000810,
368 0x280C3A, 0x000675, 0x010042, 0x08000A,
369 0x003815, 0x010924, 0x280502, 0x0B000D,
370 0x000820, 0x0002F5, 0x010040, 0x000606,
371 0x220007, 0x000464, 0x000464, 0x000606,
372 0x000007, 0x000134, 0x007F8D, 0x00093C,
373 0x281D12, 0x282512, 0x001F32, 0x0E0007,
374 0x00010D, 0x00037D, 0x000820, 0x018040,
375 0x05D2F4, 0x000007, 0x080007, 0x00037D,
376 0x018042, 0x08000A, 0x000904, 0x2D0286,
377 0x000007, 0x000606, 0x000007, 0x000007,
378 0x000012, 0x100007, 0x320007, 0x600007,
379 0x100080, 0x48001A, 0x004904, 0x2D6186,
380 0x000007, 0x001210, 0x58003A, 0x000145,
381 0x5C5D04, 0x000007, 0x000080, 0x48001A,
382 0x004904, 0x2DB186, 0x000007, 0x001210,
383 0x50003A, 0x005904, 0x2E0886, 0x000045,
384 0x0000C5, 0x7FFFF5, 0x7FFF7D, 0x07D524,
385 0x004224, 0x500102, 0x200502, 0x000082,
386 0x40001A, 0x004104, 0x2E3986, 0x000007,
387 0x003865, 0x40001A, 0x004020, 0x00104D,
388 0x04C184, 0x301B86, 0x000040, 0x040007,
389 0x000165, 0x000145, 0x004020, 0x000040,
390 0x000765, 0x080080, 0x40001A, 0x004104,
391 0x2EC986, 0x000007, 0x001210, 0x40003A,
392 0x004104, 0x2F2286, 0x00004D, 0x0000CD,
393 0x004810, 0x20043A, 0x000882, 0x40001A,
394 0x004104, 0x2F3186, 0x000007, 0x004820,
395 0x005904, 0x300886, 0x000040, 0x0007E5,
396 0x200480, 0x2816A0, 0x3216E0, 0x3A16E0,
397 0x4216E0, 0x021260, 0x000040, 0x000032,
398 0x400075, 0x00007D, 0x07D574, 0x200512,
399 0x000082, 0x40001A, 0x004104, 0x2FE186,
400 0x000007, 0x037206, 0x640007, 0x060007,
401 0x0000E5, 0x000020, 0x000040, 0x000A65,
402 0x000020, 0x020040, 0x020040, 0x000040,
403 0x000165, 0x000042, 0x70000A, 0x007104,
404 0x30A286, 0x000007, 0x018206, 0x640007,
405 0x050000, 0x007020, 0x000040, 0x037206,
406 0x640007, 0x000007, 0x00306D, 0x028860,
407 0x029060, 0x08000A, 0x028860, 0x008040,
408 0x100012, 0x00100D, 0x009184, 0x314186,
409 0x000E0D, 0x009184, 0x325186, 0x000007,
410 0x300007, 0x001020, 0x003B6D, 0x008040,
411 0x000080, 0x08001A, 0x000904, 0x316186,
412 0x000007, 0x001220, 0x000DED, 0x008040,
413 0x008042, 0x10000A, 0x40000D, 0x109544,
414 0x000007, 0x001020, 0x000DED, 0x008040,
415 0x008042, 0x20040A, 0x000082, 0x08001A,
416 0x000904, 0x31F186, 0x000007, 0x003B6D,
417 0x008042, 0x08000A, 0x000E15, 0x010984,
418 0x329B86, 0x600007, 0x08001A, 0x000C15,
419 0x010984, 0x328386, 0x000020, 0x1A0007,
420 0x0002ED, 0x008040, 0x620007, 0x00306D,
421 0x028042, 0x0A804A, 0x000820, 0x0A804A,
422 0x000606, 0x10804A, 0x000007, 0x282512,
423 0x001F32, 0x05D2F4, 0x54D104, 0x00735C,
424 0x000786, 0x000007, 0x0C0007, 0x0A0007,
425 0x1C0007, 0x003465, 0x020040, 0x004820,
426 0x025060, 0x40000A, 0x024060, 0x000040,
427 0x454944, 0x000007, 0x004020, 0x003AE5,
428 0x000040, 0x0028E5, 0x000042, 0x48000A,
429 0x004904, 0x386886, 0x002C65, 0x000042,
430 0x40000A, 0x0000D5, 0x454104, 0x000007,
431 0x000655, 0x054504, 0x34F286, 0x0001D5,
432 0x054504, 0x34F086, 0x002B65, 0x000042,
433 0x003AE5, 0x50004A, 0x40000A, 0x45C3D4,
434 0x000007, 0x454504, 0x000007, 0x0000CD,
435 0x444944, 0x000007, 0x454504, 0x000007,
436 0x00014D, 0x554944, 0x000007, 0x045144,
437 0x34E986, 0x002C65, 0x000042, 0x48000A,
438 0x4CD104, 0x000007, 0x04C144, 0x34F386,
439 0x000007, 0x160007, 0x002CE5, 0x040042,
440 0x40000A, 0x004020, 0x000040, 0x002965,
441 0x000042, 0x40000A, 0x004104, 0x356086,
442 0x000007, 0x002402, 0x36A206, 0x005C02,
443 0x0025E5, 0x000042, 0x40000A, 0x004274,
444 0x002AE5, 0x000042, 0x40000A, 0x004274,
445 0x500112, 0x0029E5, 0x000042, 0x40000A,
446 0x004234, 0x454104, 0x000007, 0x004020,
447 0x000040, 0x003EE5, 0x000020, 0x000040,
448 0x002DE5, 0x400152, 0x50000A, 0x045144,
449 0x364A86, 0x0000C5, 0x003EE5, 0x004020,
450 0x000040, 0x002BE5, 0x000042, 0x40000A,
451 0x404254, 0x000007, 0x002AE5, 0x004020,
452 0x000040, 0x500132, 0x040134, 0x005674,
453 0x0029E5, 0x020042, 0x42000A, 0x000042,
454 0x50000A, 0x05417C, 0x0028E5, 0x000042,
455 0x48000A, 0x0000C5, 0x4CC144, 0x371086,
456 0x0026E5, 0x0027E5, 0x020042, 0x40004A,
457 0x50000A, 0x00423C, 0x00567C, 0x0028E5,
458 0x004820, 0x000040, 0x281D12, 0x282512,
459 0x001F72, 0x002965, 0x000042, 0x40000A,
460 0x004104, 0x37AA86, 0x0E0007, 0x160007,
461 0x1E0007, 0x003EE5, 0x000042, 0x40000A,
462 0x004104, 0x37E886, 0x002D65, 0x000042,
463 0x28340A, 0x003465, 0x020042, 0x42004A,
464 0x004020, 0x4A004A, 0x50004A, 0x05D2F4,
465 0x54D104, 0x00735C, 0x385186, 0x000007,
466 0x000606, 0x080007, 0x0C0007, 0x080007,
467 0x0A0007, 0x0001E5, 0x020045, 0x004020,
468 0x000060, 0x000365, 0x000040, 0x002E65,
469 0x001A20, 0x0A1A60, 0x000040, 0x003465,
470 0x020042, 0x42004A, 0x004020, 0x4A004A,
471 0x000606, 0x50004A, 0x000000, 0x000000,
472 0x000000, 0x000000, 0x000000, 0x000000,
473 0x000000, 0x000000, 0x000000, 0x000000,
474 0x000000, 0x000000, 0x000000, 0x000000,
475 0x000000, 0x000000, 0x000000, 0x000000,
476 0x000000, 0x000000, 0x000000, 0x000000,
477 0x000000, 0x000000, 0x000000, 0x000000,
478 0x000000, 0x000000, 0x000000, 0x000000,
479 0x000000, 0x000000, 0x000000, 0x000000,
480 0x000000, 0x000000, 0x000000, 0x000000,
481 0x000000, 0x000000, 0x000000, 0x000000,
482 0x000000, 0x000000, 0x000000, 0x000000,
483 0x000000, 0x000000, 0x000000, 0x000000,
484 0x000000, 0x000000, 0x000000, 0x000000,
485 0x000000, 0x000000, 0x000000, 0x000000,
486 0x000000, 0x000000, 0x000000, 0x000000,
487 0x000000, 0x000000, 0x000000, 0x000000,
488 0x000000, 0x000000, 0x000000, 0x000000,
489 0x000000, 0x000000, 0x000000, 0x000000,
490 0x000000, 0x000000, 0x000000, 0x000000,
491 0x000000, 0x000000, 0x000000, 0x000000,
492 0x000000, 0x000000, 0x000000, 0x000000,
493 0x000000, 0x000000, 0x000000, 0x000000,
494 0x000000, 0x000000, 0x000000, 0x000000,
495 0x000000, 0x000000, 0x000000, 0x000000,
496 0x000000, 0x000000, 0x000000, 0x000000,
497 0x000000, 0x000000, 0x000000, 0x000000,
498 0x000000, 0x000000, 0x000000, 0x000000,
499 0x000000, 0x000000, 0x000000, 0x000000,
500 0x000000, 0x000000, 0x000000, 0x000000,
501 0x000000, 0x000000, 0x000000, 0x000000,
502 0x000000, 0x000000, 0x000000, 0x000000,
503 0x000000, 0x000000, 0x000000, 0x000000,
504 0x000000, 0x000000, 0x000000, 0x000000,
505 0x000000, 0x000000, 0x000000, 0x000000,
506 0x000000, 0x000000, 0x000000, 0x000000,
507 0x000000, 0x000000, 0x000000, 0x000000,
508 0x000000, 0x000000, 0x000000, 0x000000,
509 0x000000, 0x000000, 0x000000, 0x000000,
510 0x000000, 0x000000, 0x000000, 0x000000,
511 0x000000, 0x000000, 0x000000, 0x000000,
512 0x000000, 0x000000, 0x000000, 0x000000,
513 0x000000, 0x000000, 0x000000, 0x000000,
514 0x000000, 0x000000, 0x000000, 0x000000,
515 0x000000, 0x000000, 0x000000, 0x000000,
516 0x000000, 0x000000, 0x000000, 0x000000,
517 0x000000, 0x000000, 0x000000, 0x000000,
518 0x000000, 0x000000, 0x000000, 0x000000,
519 0x000000, 0x000000, 0x000000, 0x000000,
520 0x000000, 0x000000, 0x000000, 0x000000,
521 0x000000, 0x000000, 0x000000, 0x000000,
522 0x000000, 0x000000, 0x000000, 0x000000,
523 0x000000, 0x000000, 0x000000, 0x000000,
524 0x000000, 0x000000, 0x000000, 0x000000,
525 0x000000, 0x000000, 0x000000, 0x000000,
526 0x000000, 0x000000, 0x000000, 0x000000,
527 0x000000, 0x000000, 0x000000, 0x000000,
528 0x000000, 0x000000, 0x000000, 0x000000,
529 0x000000, 0x000000, 0x000000, 0x000000,
530 0x000000, 0x000000, 0x000000, 0x000000,
531 0x000000, 0x000000, 0x000000, 0x000000,
532 0x000000, 0x000000, 0x000000, 0x000000,
533 0x000000, 0x000000, 0x000000, 0x000000,
534 0x000000, 0x000000, 0x000000, 0x000000,
535 0x000000, 0x000000, 0x000000, 0x000000,
536 0x000000, 0x000000, 0x000000, 0x000000,
537 0x000000, 0x000000, 0x000000, 0x000000,
538 0x000000, 0x000000, 0x000000, 0x000000,
539 0x000000, 0x000000, 0x000000, 0x000000,
540 0x000000, 0x000000, 0x000000, 0x000000,
541 0x000000, 0x000000, 0x000000, 0x000000,
542 0x000000, 0x000000, 0x000000, 0x000000,
543 0x000000, 0x000000, 0x000000, 0x000000,
544 0x000000, 0x000000, 0x000000, 0x000000,
545 0x000000, 0x000000, 0x000000, 0x000000,
546 0x000000, 0x000000, 0x000000, 0x000000,
547 0x000000, 0x000000, 0x000000, 0x000000,
548 0x000000, 0x000000, 0x000000, 0x000000,
549 0x000000, 0x000000, 0x000000, 0x000000,
550 0x000000, 0x000000, 0x000000, 0x000000,
551 0x000000, 0x000000, 0x000000, 0x000000,
552 0x000000, 0x000000, 0x000000, 0x000000,
553 0x000000, 0x000000, 0x000000, 0x000000,
554 0x000000, 0x000000, 0x000000, 0x000000,
555 0x000000, 0x000000, 0x000000, 0x000000,
556 0x000000, 0x000000, 0x000000, 0x000000,
557 0x000000, 0x000000, 0x000000, 0x000000,
558 0x000000, 0x000000, 0x000000, 0x000000,
559 0x000000, 0x000000, 0x000000, 0x000000,
560 0x000000, 0x000000, 0x000000, 0x000000,
561 0x000000, 0x000000, 0x000000, 0x000000,
562 0x000000, 0x000000, 0x000000, 0x000000,
563 0x000000, 0x000000, 0x000000, 0x000000,
564 0x000000, 0x000000, 0x000000, 0x000000,
565 0x000000, 0x000000, 0x000000, 0x000000,
566 0x000000, 0x000000, 0x000000, 0x000000,
567 0x000000, 0x000000, 0x000000, 0x000000,
568 0x000000, 0x000000, 0x000000, 0x000000,
569 0x000000, 0x000000, 0x000000, 0x000000,
570 0x000000, 0x000000, 0x000000, 0x000000,
571 0x000000, 0x000000, 0x000000, 0x000000,
572 0x000000, 0x000000, 0x000000, 0x000000,
573 0x000000, 0x000000, 0x000000, 0x000000,
574 0x000000, 0x000000, 0x000000, 0x000000,
575 0x000000, 0x000000, 0x000000, 0x000000,
576 0x000000, 0x000000, 0x000000, 0x000000,
577 0x000000, 0x000000, 0x000000, 0x000000,
578 0x000000, 0x000000, 0x000000, 0x000000,
579 0x000000, 0x000000, 0x000000, 0x000000,
580 0x000000, 0x000000, 0x000000, 0x000000,
581 0x000000, 0x000000, 0x000000, 0x000000,
582 0x000000, 0x000000, 0x000000, 0x000000,
583 0x000000, 0x000000, 0x000000, 0x000000,
584 0x000000, 0x000000, 0x000000, 0x000000,
585 0x000000, 0x000000, 0x000000, 0x000000,
586 0x000000, 0x000000, 0x000000, 0x000000,
587 0x000000, 0x000000, 0x000000, 0x000000,
588 0x000000, 0x000000, 0x000000, 0x000000,
589 0x000000, 0x000000, 0x000000, 0x000000,
590 0x000000, 0x000000, 0x000000, 0x000000,
591 0x000000, 0x000000, 0x000000, 0x000000,
592 0x000000, 0x000000, 0x000000, 0x000000,
593 0x000000, 0x000000, 0x000000, 0x000000,
594 0x000000, 0x000000, 0x000000, 0x000000,
595 0x000000, 0x000000, 0x000000, 0x000000,
596 0x000000, 0x000000, 0x000000, 0x000000,
597 0x000000, 0x000000, 0x000000, 0x000000,
598 0x000000, 0x000000, 0x000000, 0x000000,
599 0x000000, 0x000000, 0x000000, 0x000000,
600 0x000000, 0x000000, 0x000000, 0x000000,
601 0x000000, 0x000000, 0x000000, 0x000000,
602 0x000000, 0x000000, 0x000000, 0x000000,
603 0x000000, 0x000000, 0x000000, 0x000000,
604 0x000000, 0x000000, 0x000000, 0x000000,
605 0x000000, 0x000000, 0x000000, 0x000000,
606 0x000000, 0x000000, 0x000000, 0x000000,
607 0x000000, 0x000000, 0x000000, 0x000000,
608 0x000000, 0x000000, 0x000000, 0x000000,
609 0x000000, 0x000000, 0x000000, 0x000000,
610 0x000000, 0x000000, 0x000000, 0x000000,
611 0x000000, 0x000000, 0x000000, 0x000000,
612 0x000000, 0x000000, 0x000000, 0x000000,
613 0x000000, 0x000000, 0x000000, 0x000000,
614 0x000000, 0x000000, 0x000000, 0x000000,
615 0x000000, 0x000000, 0x000000, 0x000000,
616 0x000000, 0x000000, 0x000000, 0x000000,
617 0x000000, 0x000000, 0x000000, 0x000000,
618 0x000000, 0x000000, 0x000000, 0x000000,
619 0x000000, 0x000000, 0x000000, 0x000000,
620 0x000000, 0x000000, 0x000000, 0x000000,
621 0x000000, 0x000000, 0x000000, 0x000000,
622 0x000000, 0x000000, 0x000000, 0x000000,
623 0x000000, 0x000000, 0x000000, 0x000000,
624 0x000000, 0x000000, 0x000000, 0x000000,
625 0x000000, 0x000000, 0x000000, 0x000000,
626 0x000000, 0x000000, 0x000000, 0x000000,
627 0x000000, 0x000000, 0x000000, 0x000000,
628 0x000000, 0x000000, 0x000000, 0x000000,
629 0x000000, 0x000000, 0x000000, 0x000000,
630 0x000000, 0x000000, 0x000000, 0x000000,
631 0x000000, 0x000000, 0x000000, 0x000000,
632 0x000000, 0x000000, 0x000000, 0x000000,
633 0x000000, 0x000000, 0x000000, 0x000000,
634 0x000000, 0x000000, 0x000000, 0x000000,
635 0x000000, 0x000000, 0x000000, 0x000000,
636 0x000000, 0x000000, 0x000000, 0x000000,
637 0x000000, 0x000000, 0x000000, 0x000000,
638 0x000000, 0x000000, 0x000000, 0x000000,
639 0x000000, 0x000000, 0x000000, 0x000000,
640 0x000000, 0x000000, 0x000000, 0x000000,
641 0x000000, 0x000000, 0x000000, 0x000000,
642 0x000000, 0x000000, 0x000000, 0x000000,
643 0x000000, 0x000000, 0x000000, 0x000000,
644 0x000000, 0x000000, 0x000000, 0x000000,
645 0x000000, 0x000000, 0x000000, 0x000000,
646 0x000000, 0x000000, 0x000000, 0x000000,
647 0x000000, 0x000000, 0x000000, 0x000000,
648 0x000000, 0x000000, 0x000000, 0x000000,
649 0x000000, 0x000000, 0x000000, 0x000000,
650 0x000000, 0x000000, 0x000000, 0x000000,
651 0x000000, 0x000000, 0x000000, 0x000000,
652 0x000000, 0x000000, 0x000000, 0x000000,
653 0x000000, 0x000000, 0x000000, 0x000000,
654 0x000000, 0x000000, 0x000000, 0x000000,
655 0x000000, 0x000000, 0x000000, 0x000000,
656 0x000000, 0x000000, 0x000000, 0x000000,
657 0x000000, 0x000000, 0x000000, 0x000000,
658 0x000000, 0x000000, 0x000000, 0x000000,
659 0x000000, 0x000000, 0x000000, 0x000000,
660 0x000000, 0x000000, 0x000000, 0x000000,
661 0x000000, 0x000000, 0x000000, 0x000000,
662 0x000000, 0x000000, 0x000000, 0x000000,
663 0x000000, 0x000000, 0x000000, 0x000000,
664 0x000000, 0x000000, 0x000000, 0x000000,
665 0x000000, 0x000000, 0x000000, 0x000000,
666 0x000000, 0x000000, 0x000000, 0x000000,
667 0x000000, 0x000000, 0x000000, 0x000000,
668 0x000000, 0x000000, 0x000000, 0x000000,
669 0x000000, 0x000000, 0x000000, 0x000000,
670 0x000000, 0x000000, 0x000000, 0x000000,
671 0x000000, 0x000000, 0x000000, 0x000000,
672 0x000000, 0x000000, 0x000000, 0x000000,
673 0x000000, 0x000000, 0x000000, 0x000000,
674 0x000000, 0x000000, 0x000000, 0x000000,
675 0x000000, 0x000000, 0x000000, 0x000000,
676 0x000000, 0x000000, 0x000000, 0x000000,
677 0x000000, 0x000000, 0x000000, 0x000000,
678 0x000000, 0x000000, 0x000000, 0x000000,
679 0x000000, 0x000000, 0x000000, 0x000000,
680 0x000000, 0x000000, 0x000000, 0x000000,
681 0x000000, 0x000000, 0x000000, 0x000000,
682 0x000000, 0x000000, 0x000000, 0x000000,
683 0x000000, 0x000000, 0x000000, 0x000000,
684 0x000000, 0x000000, 0x000000, 0x000000,
685 0x000000, 0x000000, 0x000000, 0x000000,
686 0x000000, 0x000000, 0x000000, 0x000000,
687 0x000000, 0x000000, 0x000000, 0x000000,
688 0x000000, 0x000000, 0x000000, 0x000000,
689 0x000000, 0x000000, 0x000000, 0x000000,
690 0x000000, 0x000000, 0x000000, 0x000000,
691 0x000000, 0x000000, 0x000000, 0x000000,
692 0x000000, 0x000000, 0x000000, 0x000000,
693 0x000000, 0x000000, 0x000000, 0x000000,
694 0x000000, 0x000000, 0x000000, 0x000000,
695 0x000000, 0x000000, 0x000000, 0x000000,
696 0x000000, 0x000000, 0x000000, 0x000000,
697 0x000000, 0x000000, 0x000000, 0x000000,
698 0x000000, 0x000000, 0x000000, 0x000000,
699 0x000000, 0x000000, 0x000000, 0x000000,
700 0x000000, 0x000000, 0x000000, 0x000000,
701 0x000000, 0x000000, 0x000000, 0x000000,
702 0x000000, 0x000000, 0x000000, 0x000000,
703 0x000000, 0x000000, 0x000000, 0x000000,
704 0x000000, 0x000000, 0x000000, 0x000000,
705 0x000000, 0x000000, 0x000000, 0x000000,
706 0x000000, 0x000000, 0x000000, 0x000000,
707 0x000000, 0x000000, 0x000000, 0x000000,
708 0x000000, 0x000000, 0x000000, 0x000000,
709 0x000000, 0x000000, 0x000000, 0x000000,
710 0x000000, 0x000000, 0x000000, 0x000000,
711 0x000000, 0x000000, 0x000000, 0x000000,
712 0x000000, 0x000000, 0x000000, 0x000000,
713 0x000000, 0x000000, 0x000000, 0x000000,
714 0x000000, 0x000000, 0x000000, 0x000000,
715 0x000000, 0x000000, 0x000000, 0x000000,
716 0x000000, 0x000000, 0x000000, 0x000000,
717 0x000000, 0x000000, 0x000000, 0x000000,
718 0x000000, 0x000000, 0x000000, 0x000000,
719 0x000000, 0x000000, 0x000000, 0x000000,
720 0x000000, 0x000000, 0x000000, 0x000000,
721 0x000000, 0x000000, 0x000000, 0x000000,
722 0x000000, 0x000000, 0x000000, 0x000000,
723 0x000000, 0x000000, 0x000000, 0x000000,
724 0x000000, 0x000000, 0x000000, 0x000000,
725 0x000000, 0x000000, 0x000000, 0x000000,
726 0x000000, 0x000000, 0x000000, 0x000000,
727 0x000000, 0x000000, 0x000000, 0x000000,
728 0x000000, 0x000000, 0x000000, 0x000000,
729 0x000000, 0x000000, 0x000000, 0x000000,
730 0x000000, 0x000000, 0x000000, 0x000000,
731 0x000000, 0x000000, 0x000000, 0x000000,
732 0x000000, 0x000000, 0x000000, 0x000000,
733 0x000000, 0x000000, 0x000000, 0x000000,
734 0x000000, 0x000000, 0x000000, 0x000000,
735 0x000000, 0x000000, 0x000000, 0x000000,
736 0x000000, 0x000000, 0x000000, 0x000000,
737 0x000000, 0x000000, 0x000000, 0x000000,
738 0x000000, 0x000000, 0x000000, 0x000000,
739 0x000000, 0x000000, 0x000000, 0x000000,
740 0x000000, 0x000000, 0x000000, 0x000000,
741 0x000000, 0x000000, 0x000000, 0x000000,
742 0x000000, 0x000000, 0x000000, 0x000000,
743 0x000000, 0x000000, 0x000000, 0x000000,
744 0x000000, 0x000000, 0x000000, 0x000000,
745 0x000000, 0x000000, 0x000000, 0x000000,
746 0x000000, 0x000000, 0x000000, 0x000000,
747 0x000000, 0x000000, 0x000000, 0x000000,
748 0x000000, 0x000000, 0x000000, 0x000000,
749 0x000000, 0x000000, 0x000000, 0x000000,
750 0x000000, 0x000000, 0x000000, 0x000000,
751 0x000000, 0x000000, 0x000000, 0x000000,
752 0x000000, 0x000000, 0x000000, 0x000000,
753 0x000000, 0x000000, 0x000000, 0x000000,
754 0x000000, 0x000000, 0x000000, 0x000000,
755 0x000000, 0x000000, 0x000000, 0x000000,
756 0x000000, 0x000000, 0x000000, 0x000000,
757 0x000000, 0x000000, 0x000000, 0x000000,
758 0x000000, 0x000000, 0x000000, 0x000000,
759 0x000000, 0x000000, 0x000000, 0x000000,
760 0x000000, 0x000000, 0x000000, 0x000000,
761 0x000000, 0x000000, 0x000000, 0x000000,
762 0x000000, 0x000000, 0x000000, 0x000000,
763 0x000000, 0x000000, 0x000000, 0x000000,
764 0x000000, 0x000000, 0x000000, 0x000000,
765 0x000000, 0x000000, 0x000000, 0x000000,
766 0x000000, 0x000000, 0x000000, 0x000000,
767 0x000000, 0x000000, 0x000000, 0x000000,
768 0x000000, 0x000000, 0x000000, 0x000000,
769 0x000000, 0x000000, 0x000000, 0x000000,
770 0x000000, 0x000000, 0x000000, 0x000000,
771 0x000000, 0x000000, 0x000000, 0x000000,
772 0x000000, 0x000000, 0x000000, 0x000000,
773 0x000000, 0x000000, 0x000000, 0x000000,
774 0x000000, 0x000000, 0x000000, 0x000000,
775 0x000000, 0x000000, 0x000000, 0x000000,
776 0x000000, 0x000000, 0x000000, 0x000000,
777 0x000000, 0x000000, 0x000000, 0x000000,
778 0x000000, 0x000000, 0x000000, 0x000000,
779 0x000000, 0x000000, 0x000000, 0x000000,
780 0x000000, 0x000000, 0x000000, 0x000000,
781 0x000000, 0x000000, 0x000000, 0x000000,
782 0x000000, 0x000000, 0x000000, 0x000000,
783 0x000000, 0x000000, 0x000000, 0x000000
784};
785
786// --------------------------------------------
787// DS-1E Controller InstructionRAM Code
788// 1999/06/21
789// Buf441 slot is Enabled.
790// --------------------------------------------
791// 04/09 creat
792// 04/12 stop nise fix
793// 06/21 WorkingOff timming
794static u32 CntrlInst1E[YDSXG_CTRLLENGTH / 4] = {
795 0x000007, 0x240007, 0x0C0007, 0x1C0007,
796 0x060007, 0x700002, 0x000020, 0x030040,
797 0x007104, 0x004286, 0x030040, 0x000F0D,
798 0x000810, 0x20043A, 0x000282, 0x00020D,
799 0x000810, 0x20043A, 0x001282, 0x200E82,
800 0x00800D, 0x000810, 0x20043A, 0x001A82,
801 0x03460D, 0x000810, 0x10043A, 0x02EC0D,
802 0x000810, 0x18043A, 0x00010D, 0x020015,
803 0x0000FD, 0x000020, 0x038860, 0x039060,
804 0x038060, 0x038040, 0x038040, 0x038040,
805 0x018040, 0x000A7D, 0x038040, 0x038040,
806 0x018040, 0x200402, 0x000882, 0x08001A,
807 0x000904, 0x017186, 0x000007, 0x260007,
808 0x400007, 0x000007, 0x03258D, 0x000810,
809 0x18043A, 0x260007, 0x284402, 0x00087D,
810 0x018042, 0x00160A, 0x05A206, 0x000007,
811 0x440007, 0x00230D, 0x000810, 0x08043A,
812 0x22FA06, 0x000007, 0x0007FD, 0x018042,
813 0x08000A, 0x000904, 0x02AB86, 0x000195,
814 0x090D04, 0x000007, 0x000820, 0x0000F5,
815 0x000B7D, 0x01F060, 0x0000FD, 0x033A06,
816 0x018040, 0x000A7D, 0x038042, 0x13804A,
817 0x18000A, 0x001820, 0x059060, 0x058860,
818 0x018040, 0x0000FD, 0x018042, 0x70000A,
819 0x000115, 0x071144, 0x033B86, 0x030000,
820 0x007020, 0x036206, 0x018040, 0x00360D,
821 0x000810, 0x08043A, 0x232206, 0x000007,
822 0x02EC0D, 0x000810, 0x18043A, 0x019A06,
823 0x000007, 0x240007, 0x000F8D, 0x000810,
824 0x00163A, 0x002402, 0x005C02, 0x0028FD,
825 0x000020, 0x018040, 0x08000D, 0x000815,
826 0x510984, 0x000007, 0x00004D, 0x000E5D,
827 0x000E02, 0x00430D, 0x000810, 0x08043A,
828 0x2E1206, 0x000007, 0x00008D, 0x000924,
829 0x000F02, 0x00470D, 0x000810, 0x08043A,
830 0x2E1206, 0x000007, 0x480480, 0x001210,
831 0x28043A, 0x00778D, 0x000810, 0x280C3A,
832 0x00068D, 0x000810, 0x28143A, 0x284402,
833 0x03258D, 0x000810, 0x18043A, 0x07FF8D,
834 0x000820, 0x0002FD, 0x018040, 0x260007,
835 0x200007, 0x0002FD, 0x018042, 0x08000A,
836 0x000904, 0x051286, 0x000007, 0x240007,
837 0x02EC0D, 0x000810, 0x18043A, 0x00387D,
838 0x018042, 0x08000A, 0x001015, 0x010984,
839 0x019B86, 0x000007, 0x01B206, 0x000007,
840 0x0008FD, 0x018042, 0x18000A, 0x001904,
841 0x22B886, 0x280007, 0x001810, 0x28043A,
842 0x280C02, 0x00000D, 0x000810, 0x28143A,
843 0x08808D, 0x000820, 0x0002FD, 0x018040,
844 0x200007, 0x00020D, 0x189904, 0x000007,
845 0x00402D, 0x0000BD, 0x0002FD, 0x018042,
846 0x08000A, 0x000904, 0x065A86, 0x000007,
847 0x000100, 0x000A20, 0x00047D, 0x018040,
848 0x018042, 0x20000A, 0x003015, 0x012144,
849 0x036186, 0x000007, 0x002104, 0x036186,
850 0x000007, 0x000F8D, 0x000810, 0x280C3A,
851 0x023944, 0x07C986, 0x000007, 0x001810,
852 0x28043A, 0x08810D, 0x000820, 0x0002FD,
853 0x018040, 0x200007, 0x002810, 0x78003A,
854 0x00788D, 0x000810, 0x08043A, 0x2A1206,
855 0x000007, 0x00400D, 0x001015, 0x189904,
856 0x292904, 0x393904, 0x000007, 0x070206,
857 0x000007, 0x0004F5, 0x00007D, 0x000020,
858 0x00008D, 0x010860, 0x018040, 0x00047D,
859 0x038042, 0x21804A, 0x18000A, 0x021944,
860 0x229086, 0x000007, 0x004075, 0x71F104,
861 0x000007, 0x010042, 0x28000A, 0x002904,
862 0x225886, 0x000007, 0x003C0D, 0x30A904,
863 0x000007, 0x00077D, 0x018042, 0x08000A,
864 0x000904, 0x08DA86, 0x00057D, 0x002820,
865 0x03B060, 0x08F206, 0x018040, 0x003020,
866 0x03A860, 0x018040, 0x0002FD, 0x018042,
867 0x08000A, 0x000904, 0x08FA86, 0x000007,
868 0x00057D, 0x018042, 0x28040A, 0x000E8D,
869 0x000810, 0x280C3A, 0x00000D, 0x000810,
870 0x28143A, 0x09000D, 0x000820, 0x0002FD,
871 0x018040, 0x200007, 0x003DFD, 0x000020,
872 0x018040, 0x00107D, 0x009D8D, 0x000810,
873 0x08043A, 0x2A1206, 0x000007, 0x000815,
874 0x08001A, 0x010984, 0x0A5186, 0x00137D,
875 0x200500, 0x280F20, 0x338F60, 0x3B8F60,
876 0x438F60, 0x4B8F60, 0x538F60, 0x5B8F60,
877 0x038A60, 0x018040, 0x00107D, 0x018042,
878 0x08000A, 0x000215, 0x010984, 0x3A8186,
879 0x000007, 0x007FBD, 0x383DC4, 0x000007,
880 0x001A7D, 0x001375, 0x018042, 0x09004A,
881 0x10000A, 0x0B8D04, 0x139504, 0x000007,
882 0x000820, 0x019060, 0x001104, 0x225886,
883 0x010040, 0x0017FD, 0x018042, 0x08000A,
884 0x000904, 0x225A86, 0x000007, 0x00197D,
885 0x038042, 0x09804A, 0x10000A, 0x000924,
886 0x001664, 0x0011FD, 0x038042, 0x2B804A,
887 0x19804A, 0x00008D, 0x218944, 0x000007,
888 0x002244, 0x0C1986, 0x000007, 0x001A64,
889 0x002A24, 0x00197D, 0x080102, 0x100122,
890 0x000820, 0x039060, 0x018040, 0x003DFD,
891 0x00008D, 0x000820, 0x018040, 0x001375,
892 0x001A7D, 0x010042, 0x09804A, 0x10000A,
893 0x00021D, 0x0189E4, 0x2992E4, 0x309144,
894 0x000007, 0x00060D, 0x000A15, 0x000C1D,
895 0x001025, 0x00A9E4, 0x012BE4, 0x000464,
896 0x01B3E4, 0x0232E4, 0x000464, 0x000464,
897 0x000464, 0x000464, 0x00040D, 0x08B1C4,
898 0x000007, 0x000820, 0x000BF5, 0x030040,
899 0x00197D, 0x038042, 0x09804A, 0x000A24,
900 0x08000A, 0x080E64, 0x000007, 0x100122,
901 0x000820, 0x031060, 0x010040, 0x0064AC,
902 0x00027D, 0x000020, 0x018040, 0x00107D,
903 0x018042, 0x0011FD, 0x3B804A, 0x09804A,
904 0x20000A, 0x000095, 0x1A1144, 0x00A144,
905 0x0E5886, 0x00040D, 0x00B984, 0x0E5986,
906 0x0018FD, 0x018042, 0x0010FD, 0x09804A,
907 0x28000A, 0x000095, 0x010924, 0x002A64,
908 0x0E4986, 0x000007, 0x002904, 0x0E5A86,
909 0x000007, 0x0E6206, 0x080002, 0x00008D,
910 0x00387D, 0x000820, 0x018040, 0x00127D,
911 0x018042, 0x10000A, 0x003904, 0x0F0986,
912 0x00080D, 0x7FFFB5, 0x00B984, 0x0ED986,
913 0x000025, 0x0FB206, 0x00002D, 0x000015,
914 0x00082D, 0x02E00D, 0x000820, 0x0FFA06,
915 0x00000D, 0x7F8035, 0x00B984, 0x0FA986,
916 0x400025, 0x00008D, 0x110944, 0x000007,
917 0x00018D, 0x109504, 0x000007, 0x009164,
918 0x000424, 0x000424, 0x000424, 0x100102,
919 0x280002, 0x02DF0D, 0x000820, 0x0FFA06,
920 0x00018D, 0x00042D, 0x00008D, 0x109504,
921 0x000007, 0x00020D, 0x109184, 0x000007,
922 0x02DF8D, 0x000820, 0x00008D, 0x0038FD,
923 0x018040, 0x003BFD, 0x001020, 0x03A860,
924 0x000815, 0x313184, 0x212184, 0x000007,
925 0x03B060, 0x03A060, 0x018040, 0x0022FD,
926 0x000095, 0x010924, 0x000424, 0x000424,
927 0x001264, 0x100102, 0x000820, 0x039060,
928 0x018040, 0x001924, 0x010F0D, 0x00397D,
929 0x000820, 0x058040, 0x038042, 0x09844A,
930 0x000606, 0x08040A, 0x000424, 0x000424,
931 0x00117D, 0x018042, 0x08000A, 0x000A24,
932 0x280502, 0x280C02, 0x09800D, 0x000820,
933 0x0002FD, 0x018040, 0x200007, 0x0022FD,
934 0x018042, 0x08000A, 0x000095, 0x280DC4,
935 0x011924, 0x00197D, 0x018042, 0x0011FD,
936 0x09804A, 0x10000A, 0x0000B5, 0x113144,
937 0x0A8D04, 0x000007, 0x080A44, 0x129504,
938 0x000007, 0x0023FD, 0x001020, 0x038040,
939 0x101244, 0x000007, 0x000820, 0x039060,
940 0x018040, 0x0002FD, 0x018042, 0x08000A,
941 0x000904, 0x123286, 0x000007, 0x003BFD,
942 0x000100, 0x000A10, 0x0B807A, 0x13804A,
943 0x090984, 0x000007, 0x000095, 0x013D04,
944 0x12B886, 0x10000A, 0x100002, 0x090984,
945 0x000007, 0x038042, 0x11804A, 0x090D04,
946 0x000007, 0x10000A, 0x090D84, 0x000007,
947 0x00257D, 0x000820, 0x018040, 0x00010D,
948 0x000810, 0x28143A, 0x00127D, 0x018042,
949 0x20000A, 0x00197D, 0x018042, 0x00117D,
950 0x31804A, 0x10000A, 0x003124, 0x013B8D,
951 0x00397D, 0x000820, 0x058040, 0x038042,
952 0x09844A, 0x000606, 0x08040A, 0x300102,
953 0x003124, 0x000424, 0x000424, 0x001224,
954 0x280502, 0x001A4C, 0x143986, 0x700002,
955 0x00002D, 0x030000, 0x00387D, 0x018042,
956 0x10000A, 0x146206, 0x002124, 0x0000AD,
957 0x100002, 0x00010D, 0x000924, 0x006B24,
958 0x014A0D, 0x00397D, 0x000820, 0x058040,
959 0x038042, 0x09844A, 0x000606, 0x08040A,
960 0x003264, 0x00008D, 0x000A24, 0x001020,
961 0x00227D, 0x018040, 0x014F8D, 0x000810,
962 0x08043A, 0x2B5A06, 0x000007, 0x002820,
963 0x00207D, 0x018040, 0x00117D, 0x038042,
964 0x13804A, 0x33800A, 0x00387D, 0x018042,
965 0x08000A, 0x000904, 0x177286, 0x000007,
966 0x00008D, 0x030964, 0x015B0D, 0x00397D,
967 0x000820, 0x058040, 0x038042, 0x09844A,
968 0x000606, 0x08040A, 0x380102, 0x000424,
969 0x000424, 0x001224, 0x0002FD, 0x018042,
970 0x08000A, 0x000904, 0x15DA86, 0x000007,
971 0x280502, 0x001A4C, 0x177186, 0x000007,
972 0x032164, 0x00632C, 0x003DFD, 0x018042,
973 0x08000A, 0x000095, 0x090904, 0x000007,
974 0x000820, 0x001A4C, 0x169986, 0x018040,
975 0x030000, 0x16B206, 0x002124, 0x00010D,
976 0x000924, 0x006B24, 0x016F0D, 0x00397D,
977 0x000820, 0x058040, 0x038042, 0x09844A,
978 0x000606, 0x08040A, 0x003A64, 0x000095,
979 0x001224, 0x0002FD, 0x018042, 0x08000A,
980 0x000904, 0x171286, 0x000007, 0x01760D,
981 0x000810, 0x08043A, 0x2B5A06, 0x000007,
982 0x160A06, 0x000007, 0x007020, 0x08010A,
983 0x10012A, 0x0020FD, 0x038860, 0x039060,
984 0x018040, 0x00227D, 0x018042, 0x003DFD,
985 0x08000A, 0x31844A, 0x000904, 0x181086,
986 0x18008B, 0x00008D, 0x189904, 0x00312C,
987 0x18E206, 0x000007, 0x00324C, 0x186B86,
988 0x000007, 0x001904, 0x186886, 0x000007,
989 0x000095, 0x199144, 0x00222C, 0x003124,
990 0x00636C, 0x000E3D, 0x001375, 0x000BFD,
991 0x010042, 0x09804A, 0x10000A, 0x038AEC,
992 0x0393EC, 0x00224C, 0x18E186, 0x000007,
993 0x00008D, 0x189904, 0x00226C, 0x00322C,
994 0x30050A, 0x301DAB, 0x002083, 0x0018FD,
995 0x018042, 0x08000A, 0x018924, 0x300502,
996 0x001083, 0x001875, 0x010042, 0x10000A,
997 0x00008D, 0x010924, 0x001375, 0x330542,
998 0x330CCB, 0x332CCB, 0x3334CB, 0x333CCB,
999 0x3344CB, 0x334CCB, 0x3354CB, 0x305C8B,
1000 0x006083, 0x0002F5, 0x010042, 0x08000A,
1001 0x000904, 0x19B286, 0x000007, 0x001E2D,
1002 0x0005FD, 0x018042, 0x08000A, 0x028924,
1003 0x280502, 0x00060D, 0x000810, 0x280C3A,
1004 0x00008D, 0x000810, 0x28143A, 0x0A808D,
1005 0x000820, 0x0002F5, 0x010040, 0x220007,
1006 0x001275, 0x030042, 0x21004A, 0x00008D,
1007 0x1A0944, 0x000007, 0x01AB8D, 0x000810,
1008 0x08043A, 0x2CAA06, 0x000007, 0x0001F5,
1009 0x030042, 0x0D004A, 0x10000A, 0x089144,
1010 0x000007, 0x000820, 0x010040, 0x0025F5,
1011 0x0A3144, 0x000007, 0x000820, 0x032860,
1012 0x030040, 0x00217D, 0x038042, 0x0B804A,
1013 0x10000A, 0x000820, 0x031060, 0x030040,
1014 0x00008D, 0x000124, 0x00012C, 0x000E64,
1015 0x001A64, 0x00636C, 0x08010A, 0x10012A,
1016 0x000820, 0x031060, 0x030040, 0x0020FD,
1017 0x018042, 0x08000A, 0x00227D, 0x018042,
1018 0x10000A, 0x000820, 0x031060, 0x030040,
1019 0x00197D, 0x018042, 0x08000A, 0x0022FD,
1020 0x038042, 0x10000A, 0x000820, 0x031060,
1021 0x030040, 0x090D04, 0x000007, 0x000820,
1022 0x030040, 0x038042, 0x0B804A, 0x10000A,
1023 0x000820, 0x031060, 0x030040, 0x038042,
1024 0x13804A, 0x19804A, 0x110D04, 0x198D04,
1025 0x000007, 0x08000A, 0x001020, 0x031860,
1026 0x030860, 0x030040, 0x00008D, 0x0B0944,
1027 0x000007, 0x000820, 0x010040, 0x0005F5,
1028 0x030042, 0x08000A, 0x000820, 0x010040,
1029 0x0000F5, 0x010042, 0x08000A, 0x000904,
1030 0x1D9886, 0x001E75, 0x030042, 0x01044A,
1031 0x000C0A, 0x1DAA06, 0x000007, 0x000402,
1032 0x000C02, 0x00177D, 0x001AF5, 0x018042,
1033 0x03144A, 0x031C4A, 0x03244A, 0x032C4A,
1034 0x03344A, 0x033C4A, 0x03444A, 0x004C0A,
1035 0x00043D, 0x0013F5, 0x001AFD, 0x030042,
1036 0x0B004A, 0x1B804A, 0x13804A, 0x20000A,
1037 0x089144, 0x19A144, 0x0389E4, 0x0399EC,
1038 0x005502, 0x005D0A, 0x030042, 0x0B004A,
1039 0x1B804A, 0x13804A, 0x20000A, 0x089144,
1040 0x19A144, 0x0389E4, 0x0399EC, 0x006502,
1041 0x006D0A, 0x030042, 0x0B004A, 0x19004A,
1042 0x2B804A, 0x13804A, 0x21804A, 0x30000A,
1043 0x089144, 0x19A144, 0x2AB144, 0x0389E4,
1044 0x0399EC, 0x007502, 0x007D0A, 0x03A9E4,
1045 0x000702, 0x00107D, 0x000415, 0x018042,
1046 0x08000A, 0x0109E4, 0x000F02, 0x002AF5,
1047 0x0019FD, 0x010042, 0x09804A, 0x10000A,
1048 0x000934, 0x001674, 0x0029F5, 0x010042,
1049 0x10000A, 0x00917C, 0x002075, 0x010042,
1050 0x08000A, 0x000904, 0x200A86, 0x0026F5,
1051 0x0027F5, 0x030042, 0x09004A, 0x10000A,
1052 0x000A3C, 0x00167C, 0x001A75, 0x000BFD,
1053 0x010042, 0x51804A, 0x48000A, 0x160007,
1054 0x001075, 0x010042, 0x282C0A, 0x281D12,
1055 0x282512, 0x001F32, 0x1E0007, 0x0E0007,
1056 0x001975, 0x010042, 0x002DF5, 0x0D004A,
1057 0x10000A, 0x009144, 0x20EA86, 0x010042,
1058 0x28340A, 0x000E5D, 0x00008D, 0x000375,
1059 0x000820, 0x010040, 0x05D2F4, 0x54D104,
1060 0x00735C, 0x218B86, 0x000007, 0x0C0007,
1061 0x080007, 0x0A0007, 0x02178D, 0x000810,
1062 0x08043A, 0x34B206, 0x000007, 0x219206,
1063 0x000007, 0x080007, 0x002275, 0x010042,
1064 0x20000A, 0x002104, 0x225886, 0x001E2D,
1065 0x0002F5, 0x010042, 0x08000A, 0x000904,
1066 0x21CA86, 0x000007, 0x002010, 0x30043A,
1067 0x00057D, 0x0180C3, 0x08000A, 0x028924,
1068 0x280502, 0x280C02, 0x0A810D, 0x000820,
1069 0x0002F5, 0x010040, 0x220007, 0x0004FD,
1070 0x018042, 0x70000A, 0x030000, 0x007020,
1071 0x07FA06, 0x018040, 0x022B8D, 0x000810,
1072 0x08043A, 0x2CAA06, 0x000007, 0x0002FD,
1073 0x018042, 0x08000A, 0x000904, 0x22C286,
1074 0x000007, 0x020206, 0x000007, 0x000875,
1075 0x0009FD, 0x00010D, 0x234206, 0x000295,
1076 0x000B75, 0x00097D, 0x00000D, 0x000515,
1077 0x010042, 0x18000A, 0x001904, 0x2A0086,
1078 0x0006F5, 0x001020, 0x010040, 0x0004F5,
1079 0x000820, 0x010040, 0x000775, 0x010042,
1080 0x09804A, 0x10000A, 0x001124, 0x000904,
1081 0x23F286, 0x000815, 0x080102, 0x101204,
1082 0x241206, 0x000575, 0x081204, 0x000007,
1083 0x100102, 0x000575, 0x000425, 0x021124,
1084 0x100102, 0x000820, 0x031060, 0x010040,
1085 0x001924, 0x2A0086, 0x00008D, 0x000464,
1086 0x009D04, 0x291086, 0x180102, 0x000575,
1087 0x010042, 0x28040A, 0x00018D, 0x000924,
1088 0x280D02, 0x00000D, 0x000924, 0x281502,
1089 0x10000D, 0x000820, 0x0002F5, 0x010040,
1090 0x200007, 0x001175, 0x0002FD, 0x018042,
1091 0x08000A, 0x000904, 0x24FA86, 0x000007,
1092 0x000100, 0x080B20, 0x130B60, 0x1B0B60,
1093 0x030A60, 0x010040, 0x050042, 0x3D004A,
1094 0x35004A, 0x2D004A, 0x20000A, 0x0006F5,
1095 0x010042, 0x28140A, 0x0004F5, 0x010042,
1096 0x08000A, 0x000315, 0x010D04, 0x260286,
1097 0x004015, 0x000095, 0x010D04, 0x25F086,
1098 0x100022, 0x10002A, 0x261A06, 0x000007,
1099 0x333104, 0x2AA904, 0x000007, 0x032124,
1100 0x280502, 0x284402, 0x001124, 0x400102,
1101 0x000424, 0x000424, 0x003224, 0x00292C,
1102 0x00636C, 0x277386, 0x000007, 0x02B164,
1103 0x000464, 0x000464, 0x00008D, 0x000A64,
1104 0x280D02, 0x10008D, 0x000820, 0x0002F5,
1105 0x010040, 0x220007, 0x00008D, 0x38B904,
1106 0x000007, 0x03296C, 0x30010A, 0x0002F5,
1107 0x010042, 0x08000A, 0x000904, 0x270286,
1108 0x000007, 0x00212C, 0x28050A, 0x00316C,
1109 0x00046C, 0x00046C, 0x28450A, 0x001124,
1110 0x006B64, 0x100102, 0x00008D, 0x01096C,
1111 0x280D0A, 0x10010D, 0x000820, 0x0002F5,
1112 0x010040, 0x220007, 0x004124, 0x000424,
1113 0x000424, 0x003224, 0x300102, 0x032944,
1114 0x27FA86, 0x000007, 0x300002, 0x0004F5,
1115 0x010042, 0x08000A, 0x000315, 0x010D04,
1116 0x284086, 0x003124, 0x000464, 0x300102,
1117 0x0002F5, 0x010042, 0x08000A, 0x000904,
1118 0x284A86, 0x000007, 0x284402, 0x003124,
1119 0x300502, 0x003924, 0x300583, 0x000883,
1120 0x0005F5, 0x010042, 0x28040A, 0x00008D,
1121 0x008124, 0x280D02, 0x00008D, 0x008124,
1122 0x281502, 0x10018D, 0x000820, 0x0002F5,
1123 0x010040, 0x220007, 0x001025, 0x000575,
1124 0x030042, 0x09004A, 0x10000A, 0x0A0904,
1125 0x121104, 0x000007, 0x001020, 0x050860,
1126 0x050040, 0x0006FD, 0x018042, 0x09004A,
1127 0x10000A, 0x0000A5, 0x0A0904, 0x121104,
1128 0x000007, 0x000820, 0x019060, 0x010040,
1129 0x0002F5, 0x010042, 0x08000A, 0x000904,
1130 0x29CA86, 0x000007, 0x244206, 0x000007,
1131 0x000606, 0x000007, 0x0002F5, 0x010042,
1132 0x08000A, 0x000904, 0x2A1A86, 0x000007,
1133 0x000100, 0x080B20, 0x138B60, 0x1B8B60,
1134 0x238B60, 0x2B8B60, 0x338B60, 0x3B8B60,
1135 0x438B60, 0x4B8B60, 0x538B60, 0x5B8B60,
1136 0x638B60, 0x6B8B60, 0x738B60, 0x7B8B60,
1137 0x038F60, 0x0B8F60, 0x138F60, 0x1B8F60,
1138 0x238F60, 0x2B8F60, 0x338F60, 0x3B8F60,
1139 0x438F60, 0x4B8F60, 0x538F60, 0x5B8F60,
1140 0x638F60, 0x6B8F60, 0x738F60, 0x7B8F60,
1141 0x038A60, 0x000606, 0x018040, 0x00008D,
1142 0x000A64, 0x280D02, 0x000A24, 0x00027D,
1143 0x018042, 0x10000A, 0x001224, 0x0003FD,
1144 0x018042, 0x08000A, 0x000904, 0x2C0A86,
1145 0x000007, 0x00018D, 0x000A24, 0x000464,
1146 0x000464, 0x080102, 0x000924, 0x000424,
1147 0x000424, 0x100102, 0x02000D, 0x009144,
1148 0x2C6186, 0x000007, 0x0001FD, 0x018042,
1149 0x08000A, 0x000A44, 0x2C4386, 0x018042,
1150 0x0A000D, 0x000820, 0x0002FD, 0x018040,
1151 0x200007, 0x00027D, 0x001020, 0x000606,
1152 0x018040, 0x0002F5, 0x010042, 0x08000A,
1153 0x000904, 0x2CB286, 0x000007, 0x00037D,
1154 0x018042, 0x08000A, 0x000904, 0x2CE286,
1155 0x000007, 0x000075, 0x002E7D, 0x010042,
1156 0x0B804A, 0x000020, 0x000904, 0x000686,
1157 0x010040, 0x31844A, 0x30048B, 0x000883,
1158 0x00008D, 0x000810, 0x28143A, 0x00008D,
1159 0x000810, 0x280C3A, 0x000675, 0x010042,
1160 0x08000A, 0x003815, 0x010924, 0x280502,
1161 0x0B000D, 0x000820, 0x0002F5, 0x010040,
1162 0x000606, 0x220007, 0x000464, 0x000464,
1163 0x000606, 0x000007, 0x000134, 0x007F8D,
1164 0x00093C, 0x281D12, 0x282512, 0x001F32,
1165 0x0E0007, 0x00010D, 0x00037D, 0x000820,
1166 0x018040, 0x05D2F4, 0x000007, 0x080007,
1167 0x00037D, 0x018042, 0x08000A, 0x000904,
1168 0x2E8A86, 0x000007, 0x000606, 0x000007,
1169 0x000007, 0x000012, 0x100007, 0x320007,
1170 0x600007, 0x460007, 0x100080, 0x48001A,
1171 0x004904, 0x2EF186, 0x000007, 0x001210,
1172 0x58003A, 0x000145, 0x5C5D04, 0x000007,
1173 0x000080, 0x48001A, 0x004904, 0x2F4186,
1174 0x000007, 0x001210, 0x50003A, 0x005904,
1175 0x2F9886, 0x000045, 0x0000C5, 0x7FFFF5,
1176 0x7FFF7D, 0x07D524, 0x004224, 0x500102,
1177 0x200502, 0x000082, 0x40001A, 0x004104,
1178 0x2FC986, 0x000007, 0x003865, 0x40001A,
1179 0x004020, 0x00104D, 0x04C184, 0x31AB86,
1180 0x000040, 0x040007, 0x000165, 0x000145,
1181 0x004020, 0x000040, 0x000765, 0x080080,
1182 0x40001A, 0x004104, 0x305986, 0x000007,
1183 0x001210, 0x40003A, 0x004104, 0x30B286,
1184 0x00004D, 0x0000CD, 0x004810, 0x20043A,
1185 0x000882, 0x40001A, 0x004104, 0x30C186,
1186 0x000007, 0x004820, 0x005904, 0x319886,
1187 0x000040, 0x0007E5, 0x200480, 0x2816A0,
1188 0x3216E0, 0x3A16E0, 0x4216E0, 0x021260,
1189 0x000040, 0x000032, 0x400075, 0x00007D,
1190 0x07D574, 0x200512, 0x000082, 0x40001A,
1191 0x004104, 0x317186, 0x000007, 0x038A06,
1192 0x640007, 0x0000E5, 0x000020, 0x000040,
1193 0x000A65, 0x000020, 0x020040, 0x020040,
1194 0x000040, 0x000165, 0x000042, 0x70000A,
1195 0x007104, 0x323286, 0x000007, 0x060007,
1196 0x019A06, 0x640007, 0x050000, 0x007020,
1197 0x000040, 0x038A06, 0x640007, 0x000007,
1198 0x00306D, 0x028860, 0x029060, 0x08000A,
1199 0x028860, 0x008040, 0x100012, 0x00100D,
1200 0x009184, 0x32D186, 0x000E0D, 0x009184,
1201 0x33E186, 0x000007, 0x300007, 0x001020,
1202 0x003B6D, 0x008040, 0x000080, 0x08001A,
1203 0x000904, 0x32F186, 0x000007, 0x001220,
1204 0x000DED, 0x008040, 0x008042, 0x10000A,
1205 0x40000D, 0x109544, 0x000007, 0x001020,
1206 0x000DED, 0x008040, 0x008042, 0x20040A,
1207 0x000082, 0x08001A, 0x000904, 0x338186,
1208 0x000007, 0x003B6D, 0x008042, 0x08000A,
1209 0x000E15, 0x010984, 0x342B86, 0x600007,
1210 0x08001A, 0x000C15, 0x010984, 0x341386,
1211 0x000020, 0x1A0007, 0x0002ED, 0x008040,
1212 0x620007, 0x00306D, 0x028042, 0x0A804A,
1213 0x000820, 0x0A804A, 0x000606, 0x10804A,
1214 0x000007, 0x282512, 0x001F32, 0x05D2F4,
1215 0x54D104, 0x00735C, 0x000786, 0x000007,
1216 0x0C0007, 0x0A0007, 0x1C0007, 0x003465,
1217 0x020040, 0x004820, 0x025060, 0x40000A,
1218 0x024060, 0x000040, 0x454944, 0x000007,
1219 0x004020, 0x003AE5, 0x000040, 0x0028E5,
1220 0x000042, 0x48000A, 0x004904, 0x39F886,
1221 0x002C65, 0x000042, 0x40000A, 0x0000D5,
1222 0x454104, 0x000007, 0x000655, 0x054504,
1223 0x368286, 0x0001D5, 0x054504, 0x368086,
1224 0x002B65, 0x000042, 0x003AE5, 0x50004A,
1225 0x40000A, 0x45C3D4, 0x000007, 0x454504,
1226 0x000007, 0x0000CD, 0x444944, 0x000007,
1227 0x454504, 0x000007, 0x00014D, 0x554944,
1228 0x000007, 0x045144, 0x367986, 0x002C65,
1229 0x000042, 0x48000A, 0x4CD104, 0x000007,
1230 0x04C144, 0x368386, 0x000007, 0x160007,
1231 0x002CE5, 0x040042, 0x40000A, 0x004020,
1232 0x000040, 0x002965, 0x000042, 0x40000A,
1233 0x004104, 0x36F086, 0x000007, 0x002402,
1234 0x383206, 0x005C02, 0x0025E5, 0x000042,
1235 0x40000A, 0x004274, 0x002AE5, 0x000042,
1236 0x40000A, 0x004274, 0x500112, 0x0029E5,
1237 0x000042, 0x40000A, 0x004234, 0x454104,
1238 0x000007, 0x004020, 0x000040, 0x003EE5,
1239 0x000020, 0x000040, 0x002DE5, 0x400152,
1240 0x50000A, 0x045144, 0x37DA86, 0x0000C5,
1241 0x003EE5, 0x004020, 0x000040, 0x002BE5,
1242 0x000042, 0x40000A, 0x404254, 0x000007,
1243 0x002AE5, 0x004020, 0x000040, 0x500132,
1244 0x040134, 0x005674, 0x0029E5, 0x020042,
1245 0x42000A, 0x000042, 0x50000A, 0x05417C,
1246 0x0028E5, 0x000042, 0x48000A, 0x0000C5,
1247 0x4CC144, 0x38A086, 0x0026E5, 0x0027E5,
1248 0x020042, 0x40004A, 0x50000A, 0x00423C,
1249 0x00567C, 0x0028E5, 0x004820, 0x000040,
1250 0x281D12, 0x282512, 0x001F72, 0x002965,
1251 0x000042, 0x40000A, 0x004104, 0x393A86,
1252 0x0E0007, 0x160007, 0x1E0007, 0x003EE5,
1253 0x000042, 0x40000A, 0x004104, 0x397886,
1254 0x002D65, 0x000042, 0x28340A, 0x003465,
1255 0x020042, 0x42004A, 0x004020, 0x4A004A,
1256 0x50004A, 0x05D2F4, 0x54D104, 0x00735C,
1257 0x39E186, 0x000007, 0x000606, 0x080007,
1258 0x0C0007, 0x080007, 0x0A0007, 0x0001E5,
1259 0x020045, 0x004020, 0x000060, 0x000365,
1260 0x000040, 0x002E65, 0x001A20, 0x0A1A60,
1261 0x000040, 0x003465, 0x020042, 0x42004A,
1262 0x004020, 0x4A004A, 0x000606, 0x50004A,
1263 0x0017FD, 0x018042, 0x08000A, 0x000904,
1264 0x225A86, 0x000007, 0x00107D, 0x018042,
1265 0x0011FD, 0x33804A, 0x19804A, 0x20000A,
1266 0x000095, 0x2A1144, 0x01A144, 0x3B9086,
1267 0x00040D, 0x00B184, 0x3B9186, 0x0018FD,
1268 0x018042, 0x0010FD, 0x09804A, 0x38000A,
1269 0x000095, 0x010924, 0x003A64, 0x3B8186,
1270 0x000007, 0x003904, 0x3B9286, 0x000007,
1271 0x3B9A06, 0x00000D, 0x00008D, 0x000820,
1272 0x00387D, 0x018040, 0x700002, 0x00117D,
1273 0x018042, 0x00197D, 0x29804A, 0x30000A,
1274 0x380002, 0x003124, 0x000424, 0x000424,
1275 0x002A24, 0x280502, 0x00068D, 0x000810,
1276 0x28143A, 0x00750D, 0x00B124, 0x002264,
1277 0x3D0386, 0x284402, 0x000810, 0x280C3A,
1278 0x0B800D, 0x000820, 0x0002FD, 0x018040,
1279 0x200007, 0x00758D, 0x00B124, 0x100102,
1280 0x012144, 0x3E4986, 0x001810, 0x10003A,
1281 0x00387D, 0x018042, 0x08000A, 0x000904,
1282 0x3E4886, 0x030000, 0x3E4A06, 0x0000BD,
1283 0x00008D, 0x023164, 0x000A64, 0x280D02,
1284 0x0B808D, 0x000820, 0x0002FD, 0x018040,
1285 0x200007, 0x00387D, 0x018042, 0x08000A,
1286 0x000904, 0x3E3286, 0x030000, 0x0002FD,
1287 0x018042, 0x08000A, 0x000904, 0x3D8286,
1288 0x000007, 0x002810, 0x28043A, 0x00750D,
1289 0x030924, 0x002264, 0x280D02, 0x02316C,
1290 0x28450A, 0x0B810D, 0x000820, 0x0002FD,
1291 0x018040, 0x200007, 0x00008D, 0x000A24,
1292 0x3E4A06, 0x100102, 0x001810, 0x10003A,
1293 0x0000BD, 0x003810, 0x30043A, 0x00187D,
1294 0x018042, 0x0018FD, 0x09804A, 0x20000A,
1295 0x0000AD, 0x028924, 0x07212C, 0x001010,
1296 0x300583, 0x300D8B, 0x3014BB, 0x301C83,
1297 0x002083, 0x00137D, 0x038042, 0x33844A,
1298 0x33ACCB, 0x33B4CB, 0x33BCCB, 0x33C4CB,
1299 0x33CCCB, 0x33D4CB, 0x305C8B, 0x006083,
1300 0x001E0D, 0x0005FD, 0x018042, 0x20000A,
1301 0x020924, 0x00068D, 0x00A96C, 0x00009D,
1302 0x0002FD, 0x018042, 0x08000A, 0x000904,
1303 0x3F6A86, 0x000007, 0x280502, 0x280D0A,
1304 0x284402, 0x001810, 0x28143A, 0x0C008D,
1305 0x000820, 0x0002FD, 0x018040, 0x220007,
1306 0x003904, 0x225886, 0x001E0D, 0x00057D,
1307 0x018042, 0x20000A, 0x020924, 0x0000A5,
1308 0x0002FD, 0x018042, 0x08000A, 0x000904,
1309 0x402A86, 0x000007, 0x280502, 0x280C02,
1310 0x002010, 0x28143A, 0x0C010D, 0x000820,
1311 0x0002FD, 0x018040, 0x225A06, 0x220007,
1312 0x000000, 0x000000, 0x000000, 0x000000,
1313 0x000000, 0x000000, 0x000000, 0x000000,
1314 0x000000, 0x000000, 0x000000, 0x000000,
1315 0x000000, 0x000000, 0x000000, 0x000000,
1316 0x000000, 0x000000, 0x000000, 0x000000,
1317 0x000000, 0x000000, 0x000000, 0x000000,
1318 0x000000, 0x000000, 0x000000, 0x000000,
1319 0x000000, 0x000000, 0x000000, 0x000000,
1320 0x000000, 0x000000, 0x000000, 0x000000,
1321 0x000000, 0x000000, 0x000000, 0x000000,
1322 0x000000, 0x000000, 0x000000, 0x000000,
1323 0x000000, 0x000000, 0x000000, 0x000000,
1324 0x000000, 0x000000, 0x000000, 0x000000,
1325 0x000000, 0x000000, 0x000000, 0x000000,
1326 0x000000, 0x000000, 0x000000, 0x000000,
1327 0x000000, 0x000000, 0x000000, 0x000000,
1328 0x000000, 0x000000, 0x000000, 0x000000,
1329 0x000000, 0x000000, 0x000000, 0x000000,
1330 0x000000, 0x000000, 0x000000, 0x000000,
1331 0x000000, 0x000000, 0x000000, 0x000000,
1332 0x000000, 0x000000, 0x000000, 0x000000,
1333 0x000000, 0x000000, 0x000000, 0x000000,
1334 0x000000, 0x000000, 0x000000, 0x000000,
1335 0x000000, 0x000000, 0x000000, 0x000000,
1336 0x000000, 0x000000, 0x000000, 0x000000,
1337 0x000000, 0x000000, 0x000000, 0x000000,
1338 0x000000, 0x000000, 0x000000, 0x000000,
1339 0x000000, 0x000000, 0x000000, 0x000000,
1340 0x000000, 0x000000, 0x000000, 0x000000,
1341 0x000000, 0x000000, 0x000000, 0x000000,
1342 0x000000, 0x000000, 0x000000, 0x000000,
1343 0x000000, 0x000000, 0x000000, 0x000000,
1344 0x000000, 0x000000, 0x000000, 0x000000,
1345 0x000000, 0x000000, 0x000000, 0x000000,
1346 0x000000, 0x000000, 0x000000, 0x000000,
1347 0x000000, 0x000000, 0x000000, 0x000000,
1348 0x000000, 0x000000, 0x000000, 0x000000,
1349 0x000000, 0x000000, 0x000000, 0x000000,
1350 0x000000, 0x000000, 0x000000, 0x000000,
1351 0x000000, 0x000000, 0x000000, 0x000000,
1352 0x000000, 0x000000, 0x000000, 0x000000,
1353 0x000000, 0x000000, 0x000000, 0x000000,
1354 0x000000, 0x000000, 0x000000, 0x000000,
1355 0x000000, 0x000000, 0x000000, 0x000000,
1356 0x000000, 0x000000, 0x000000, 0x000000,
1357 0x000000, 0x000000, 0x000000, 0x000000,
1358 0x000000, 0x000000, 0x000000, 0x000000,
1359 0x000000, 0x000000, 0x000000, 0x000000,
1360 0x000000, 0x000000, 0x000000, 0x000000,
1361 0x000000, 0x000000, 0x000000, 0x000000,
1362 0x000000, 0x000000, 0x000000, 0x000000,
1363 0x000000, 0x000000, 0x000000, 0x000000,
1364 0x000000, 0x000000, 0x000000, 0x000000,
1365 0x000000, 0x000000, 0x000000, 0x000000,
1366 0x000000, 0x000000, 0x000000, 0x000000,
1367 0x000000, 0x000000, 0x000000, 0x000000,
1368 0x000000, 0x000000, 0x000000, 0x000000,
1369 0x000000, 0x000000, 0x000000, 0x000000,
1370 0x000000, 0x000000, 0x000000, 0x000000,
1371 0x000000, 0x000000, 0x000000, 0x000000,
1372 0x000000, 0x000000, 0x000000, 0x000000,
1373 0x000000, 0x000000, 0x000000, 0x000000,
1374 0x000000, 0x000000, 0x000000, 0x000000,
1375 0x000000, 0x000000, 0x000000, 0x000000,
1376 0x000000, 0x000000, 0x000000, 0x000000,
1377 0x000000, 0x000000, 0x000000, 0x000000,
1378 0x000000, 0x000000, 0x000000, 0x000000,
1379 0x000000, 0x000000, 0x000000, 0x000000,
1380 0x000000, 0x000000, 0x000000, 0x000000,
1381 0x000000, 0x000000, 0x000000, 0x000000,
1382 0x000000, 0x000000, 0x000000, 0x000000,
1383 0x000000, 0x000000, 0x000000, 0x000000,
1384 0x000000, 0x000000, 0x000000, 0x000000,
1385 0x000000, 0x000000, 0x000000, 0x000000,
1386 0x000000, 0x000000, 0x000000, 0x000000,
1387 0x000000, 0x000000, 0x000000, 0x000000,
1388 0x000000, 0x000000, 0x000000, 0x000000,
1389 0x000000, 0x000000, 0x000000, 0x000000,
1390 0x000000, 0x000000, 0x000000, 0x000000,
1391 0x000000, 0x000000, 0x000000, 0x000000,
1392 0x000000, 0x000000, 0x000000, 0x000000,
1393 0x000000, 0x000000, 0x000000, 0x000000,
1394 0x000000, 0x000000, 0x000000, 0x000000,
1395 0x000000, 0x000000, 0x000000, 0x000000,
1396 0x000000, 0x000000, 0x000000, 0x000000,
1397 0x000000, 0x000000, 0x000000, 0x000000,
1398 0x000000, 0x000000, 0x000000, 0x000000,
1399 0x000000, 0x000000, 0x000000, 0x000000,
1400 0x000000, 0x000000, 0x000000, 0x000000,
1401 0x000000, 0x000000, 0x000000, 0x000000,
1402 0x000000, 0x000000, 0x000000, 0x000000,
1403 0x000000, 0x000000, 0x000000, 0x000000,
1404 0x000000, 0x000000, 0x000000, 0x000000,
1405 0x000000, 0x000000, 0x000000, 0x000000,
1406 0x000000, 0x000000, 0x000000, 0x000000,
1407 0x000000, 0x000000, 0x000000, 0x000000,
1408 0x000000, 0x000000, 0x000000, 0x000000,
1409 0x000000, 0x000000, 0x000000, 0x000000,
1410 0x000000, 0x000000, 0x000000, 0x000000,
1411 0x000000, 0x000000, 0x000000, 0x000000,
1412 0x000000, 0x000000, 0x000000, 0x000000,
1413 0x000000, 0x000000, 0x000000, 0x000000,
1414 0x000000, 0x000000, 0x000000, 0x000000,
1415 0x000000, 0x000000, 0x000000, 0x000000,
1416 0x000000, 0x000000, 0x000000, 0x000000,
1417 0x000000, 0x000000, 0x000000, 0x000000,
1418 0x000000, 0x000000, 0x000000, 0x000000,
1419 0x000000, 0x000000, 0x000000, 0x000000,
1420 0x000000, 0x000000, 0x000000, 0x000000,
1421 0x000000, 0x000000, 0x000000, 0x000000,
1422 0x000000, 0x000000, 0x000000, 0x000000,
1423 0x000000, 0x000000, 0x000000, 0x000000,
1424 0x000000, 0x000000, 0x000000, 0x000000,
1425 0x000000, 0x000000, 0x000000, 0x000000,
1426 0x000000, 0x000000, 0x000000, 0x000000,
1427 0x000000, 0x000000, 0x000000, 0x000000,
1428 0x000000, 0x000000, 0x000000, 0x000000,
1429 0x000000, 0x000000, 0x000000, 0x000000,
1430 0x000000, 0x000000, 0x000000, 0x000000,
1431 0x000000, 0x000000, 0x000000, 0x000000,
1432 0x000000, 0x000000, 0x000000, 0x000000,
1433 0x000000, 0x000000, 0x000000, 0x000000,
1434 0x000000, 0x000000, 0x000000, 0x000000,
1435 0x000000, 0x000000, 0x000000, 0x000000,
1436 0x000000, 0x000000, 0x000000, 0x000000,
1437 0x000000, 0x000000, 0x000000, 0x000000,
1438 0x000000, 0x000000, 0x000000, 0x000000,
1439 0x000000, 0x000000, 0x000000, 0x000000,
1440 0x000000, 0x000000, 0x000000, 0x000000,
1441 0x000000, 0x000000, 0x000000, 0x000000,
1442 0x000000, 0x000000, 0x000000, 0x000000,
1443 0x000000, 0x000000, 0x000000, 0x000000,
1444 0x000000, 0x000000, 0x000000, 0x000000,
1445 0x000000, 0x000000, 0x000000, 0x000000,
1446 0x000000, 0x000000, 0x000000, 0x000000,
1447 0x000000, 0x000000, 0x000000, 0x000000,
1448 0x000000, 0x000000, 0x000000, 0x000000,
1449 0x000000, 0x000000, 0x000000, 0x000000,
1450 0x000000, 0x000000, 0x000000, 0x000000,
1451 0x000000, 0x000000, 0x000000, 0x000000,
1452 0x000000, 0x000000, 0x000000, 0x000000,
1453 0x000000, 0x000000, 0x000000, 0x000000,
1454 0x000000, 0x000000, 0x000000, 0x000000,
1455 0x000000, 0x000000, 0x000000, 0x000000,
1456 0x000000, 0x000000, 0x000000, 0x000000,
1457 0x000000, 0x000000, 0x000000, 0x000000,
1458 0x000000, 0x000000, 0x000000, 0x000000,
1459 0x000000, 0x000000, 0x000000, 0x000000,
1460 0x000000, 0x000000, 0x000000, 0x000000,
1461 0x000000, 0x000000, 0x000000, 0x000000,
1462 0x000000, 0x000000, 0x000000, 0x000000,
1463 0x000000, 0x000000, 0x000000, 0x000000,
1464 0x000000, 0x000000, 0x000000, 0x000000,
1465 0x000000, 0x000000, 0x000000, 0x000000,
1466 0x000000, 0x000000, 0x000000, 0x000000,
1467 0x000000, 0x000000, 0x000000, 0x000000,
1468 0x000000, 0x000000, 0x000000, 0x000000,
1469 0x000000, 0x000000, 0x000000, 0x000000,
1470 0x000000, 0x000000, 0x000000, 0x000000,
1471 0x000000, 0x000000, 0x000000, 0x000000,
1472 0x000000, 0x000000, 0x000000, 0x000000,
1473 0x000000, 0x000000, 0x000000, 0x000000,
1474 0x000000, 0x000000, 0x000000, 0x000000,
1475 0x000000, 0x000000, 0x000000, 0x000000,
1476 0x000000, 0x000000, 0x000000, 0x000000,
1477 0x000000, 0x000000, 0x000000, 0x000000,
1478 0x000000, 0x000000, 0x000000, 0x000000,
1479 0x000000, 0x000000, 0x000000, 0x000000,
1480 0x000000, 0x000000, 0x000000, 0x000000,
1481 0x000000, 0x000000, 0x000000, 0x000000,
1482 0x000000, 0x000000, 0x000000, 0x000000,
1483 0x000000, 0x000000, 0x000000, 0x000000,
1484 0x000000, 0x000000, 0x000000, 0x000000,
1485 0x000000, 0x000000, 0x000000, 0x000000,
1486 0x000000, 0x000000, 0x000000, 0x000000,
1487 0x000000, 0x000000, 0x000000, 0x000000,
1488 0x000000, 0x000000, 0x000000, 0x000000,
1489 0x000000, 0x000000, 0x000000, 0x000000,
1490 0x000000, 0x000000, 0x000000, 0x000000,
1491 0x000000, 0x000000, 0x000000, 0x000000,
1492 0x000000, 0x000000, 0x000000, 0x000000,
1493 0x000000, 0x000000, 0x000000, 0x000000,
1494 0x000000, 0x000000, 0x000000, 0x000000,
1495 0x000000, 0x000000, 0x000000, 0x000000,
1496 0x000000, 0x000000, 0x000000, 0x000000,
1497 0x000000, 0x000000, 0x000000, 0x000000,
1498 0x000000, 0x000000, 0x000000, 0x000000,
1499 0x000000, 0x000000, 0x000000, 0x000000,
1500 0x000000, 0x000000, 0x000000, 0x000000,
1501 0x000000, 0x000000, 0x000000, 0x000000,
1502 0x000000, 0x000000, 0x000000, 0x000000,
1503 0x000000, 0x000000, 0x000000, 0x000000,
1504 0x000000, 0x000000, 0x000000, 0x000000,
1505 0x000000, 0x000000, 0x000000, 0x000000,
1506 0x000000, 0x000000, 0x000000, 0x000000,
1507 0x000000, 0x000000, 0x000000, 0x000000,
1508 0x000000, 0x000000, 0x000000, 0x000000,
1509 0x000000, 0x000000, 0x000000, 0x000000,
1510 0x000000, 0x000000, 0x000000, 0x000000,
1511 0x000000, 0x000000, 0x000000, 0x000000,
1512 0x000000, 0x000000, 0x000000, 0x000000,
1513 0x000000, 0x000000, 0x000000, 0x000000,
1514 0x000000, 0x000000, 0x000000, 0x000000,
1515 0x000000, 0x000000, 0x000000, 0x000000,
1516 0x000000, 0x000000, 0x000000, 0x000000,
1517 0x000000, 0x000000, 0x000000, 0x000000,
1518 0x000000, 0x000000, 0x000000, 0x000000,
1519 0x000000, 0x000000, 0x000000, 0x000000,
1520 0x000000, 0x000000, 0x000000, 0x000000,
1521 0x000000, 0x000000, 0x000000, 0x000000,
1522 0x000000, 0x000000, 0x000000, 0x000000,
1523 0x000000, 0x000000, 0x000000, 0x000000,
1524 0x000000, 0x000000, 0x000000, 0x000000,
1525 0x000000, 0x000000, 0x000000, 0x000000,
1526 0x000000, 0x000000, 0x000000, 0x000000,
1527 0x000000, 0x000000, 0x000000, 0x000000,
1528 0x000000, 0x000000, 0x000000, 0x000000,
1529 0x000000, 0x000000, 0x000000, 0x000000,
1530 0x000000, 0x000000, 0x000000, 0x000000,
1531 0x000000, 0x000000, 0x000000, 0x000000,
1532 0x000000, 0x000000, 0x000000, 0x000000,
1533 0x000000, 0x000000, 0x000000, 0x000000,
1534 0x000000, 0x000000, 0x000000, 0x000000,
1535 0x000000, 0x000000, 0x000000, 0x000000,
1536 0x000000, 0x000000, 0x000000, 0x000000,
1537 0x000000, 0x000000, 0x000000, 0x000000,
1538 0x000000, 0x000000, 0x000000, 0x000000,
1539 0x000000, 0x000000, 0x000000, 0x000000,
1540 0x000000, 0x000000, 0x000000, 0x000000,
1541 0x000000, 0x000000, 0x000000, 0x000000,
1542 0x000000, 0x000000, 0x000000, 0x000000,
1543 0x000000, 0x000000, 0x000000, 0x000000,
1544 0x000000, 0x000000, 0x000000, 0x000000,
1545 0x000000, 0x000000, 0x000000, 0x000000,
1546 0x000000, 0x000000, 0x000000, 0x000000,
1547 0x000000, 0x000000, 0x000000, 0x000000,
1548 0x000000, 0x000000, 0x000000, 0x000000,
1549 0x000000, 0x000000, 0x000000, 0x000000,
1550 0x000000, 0x000000, 0x000000, 0x000000,
1551 0x000000, 0x000000, 0x000000, 0x000000,
1552 0x000000, 0x000000, 0x000000, 0x000000,
1553 0x000000, 0x000000, 0x000000, 0x000000,
1554 0x000000, 0x000000, 0x000000, 0x000000,
1555 0x000000, 0x000000, 0x000000, 0x000000,
1556 0x000000, 0x000000, 0x000000, 0x000000,
1557 0x000000, 0x000000, 0x000000, 0x000000,
1558 0x000000, 0x000000, 0x000000, 0x000000,
1559 0x000000, 0x000000, 0x000000, 0x000000,
1560 0x000000, 0x000000, 0x000000, 0x000000,
1561 0x000000, 0x000000, 0x000000, 0x000000,
1562 0x000000, 0x000000, 0x000000, 0x000000
1563};
1564
1565#endif //_HWMCODE_
diff --git a/sound/oss/yss225.c b/sound/oss/yss225.c
new file mode 100644
index 000000000000..e700400576d8
--- /dev/null
+++ b/sound/oss/yss225.c
@@ -0,0 +1,319 @@
1#include <linux/init.h>
2
3unsigned char page_zero[] __initdata = {
40x01, 0x7c, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf5, 0x00,
50x11, 0x00, 0x20, 0x00, 0x32, 0x00, 0x40, 0x00, 0x13, 0x00, 0x00,
60x00, 0x14, 0x02, 0x76, 0x00, 0x60, 0x00, 0x80, 0x02, 0x00, 0x00,
70x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x19,
160x01, 0x1a, 0x01, 0x20, 0x01, 0x40, 0x01, 0x17, 0x00, 0x00, 0x01,
170x80, 0x01, 0x20, 0x00, 0x10, 0x01, 0xa0, 0x03, 0xd1, 0x00, 0x00,
180x01, 0xf2, 0x02, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0xf4, 0x02,
190xe0, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17,
200x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x50, 0x00, 0x00, 0x00,
210x40, 0x00, 0x00, 0x00, 0x71, 0x02, 0x00, 0x00, 0x60, 0x00, 0x00,
220x00, 0x92, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xb3, 0x02,
230x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x40,
240x00, 0x80, 0x00, 0xf5, 0x00, 0x20, 0x00, 0x70, 0x00, 0xa0, 0x02,
250x11, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
260x02, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x17, 0x00, 0x1b, 0x00,
270x1d, 0x02, 0xdf
28};
29
30unsigned char page_one[] __initdata = {
310x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x19, 0x00,
320x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xd8, 0x00, 0x00,
330x02, 0x20, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01,
340xc0, 0x01, 0xfa, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
350x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
360x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
370x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
380x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
400x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
410x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
420x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x02, 0x60,
430x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xc0, 0x02, 0x80, 0x00,
440x00, 0x02, 0xfb, 0x02, 0xa0, 0x00, 0x00, 0x00, 0x1b, 0x02, 0xd7,
450x00, 0x00, 0x02, 0xf7, 0x03, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00,
460x1c, 0x03, 0x3c, 0x00, 0x00, 0x03, 0x3f, 0x00, 0x00, 0x03, 0xc0,
470x00, 0x00, 0x03, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x03, 0x5d, 0x00,
480x00, 0x03, 0xc0, 0x00, 0x00, 0x03, 0x7d, 0x00, 0x00, 0x03, 0xc0,
490x00, 0x00, 0x03, 0x9e, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x03,
500xbe, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
510x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
520xdb, 0x00, 0x00, 0x02, 0xdb, 0x00, 0x00, 0x02, 0xe0, 0x00, 0x00,
530x02, 0xfb, 0x00, 0x00, 0x02, 0xc0, 0x02, 0x40, 0x02, 0xfb, 0x02,
540x60, 0x00, 0x1b
55};
56
57unsigned char page_two[] __initdata = {
580xc4, 0x00, 0x44, 0x07, 0x44, 0x00, 0x40, 0x25, 0x01, 0x06, 0xc4,
590x07, 0x40, 0x25, 0x01, 0x00, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00,
600x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
610x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
620x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
630x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x07,
640x05, 0x05, 0x05, 0x04, 0x07, 0x05, 0x04, 0x07, 0x05, 0x44, 0x46,
650x44, 0x46, 0x46, 0x07, 0x05, 0x44, 0x46, 0x05, 0x46, 0x05, 0x46,
660x05, 0x46, 0x05, 0x44, 0x46, 0x05, 0x07, 0x44, 0x46, 0x05, 0x07,
670x44, 0x46, 0x05, 0x07, 0x44, 0x46, 0x05, 0x07, 0x44, 0x05, 0x05,
680x05, 0x44, 0x05, 0x05, 0x05, 0x46, 0x05, 0x46, 0x05, 0x46, 0x05,
690x46, 0x05, 0x46, 0x07, 0x46, 0x07, 0x44
70};
71
72unsigned char page_three[] __initdata = {
730x07, 0x40, 0x00, 0x00, 0x00, 0x47, 0x00, 0x40, 0x00, 0x40, 0x06,
740x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
750x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
760x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
770x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
780x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80,
790xc0, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x40, 0x00,
800x60, 0x00, 0x70, 0x00, 0x40, 0x00, 0x40, 0x00, 0x42, 0x00, 0x40,
810x00, 0x02, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
820x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
830x00, 0x42, 0x00, 0x40, 0x00, 0x42, 0x00, 0x02, 0x00, 0x02, 0x00,
840x02, 0x00, 0x42, 0x00, 0xc0, 0x00, 0x40
85};
86
87unsigned char page_four[] __initdata = {
880x63, 0x03, 0x26, 0x02, 0x2c, 0x00, 0x24, 0x00, 0x2e, 0x02, 0x02,
890x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
900x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
910x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
920x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
930x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
940x20, 0x00, 0x60, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
950x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x60, 0x00,
960x20, 0x00, 0x60, 0x00, 0x20, 0x00, 0x60, 0x00, 0x20, 0x00, 0x60,
970x00, 0x20, 0x00, 0x60, 0x00, 0x20, 0x00, 0x60, 0x00, 0x20, 0x00,
980x20, 0x00, 0x22, 0x02, 0x22, 0x02, 0x20, 0x00, 0x60, 0x00, 0x22,
990x02, 0x62, 0x02, 0x20, 0x01, 0x21, 0x01
100};
101
102unsigned char page_six[] __initdata = {
1030x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x06, 0x00,
1040x00, 0x08, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x0e,
1050x00, 0x00, 0x10, 0x00, 0x00, 0x12, 0x00, 0x00, 0x14, 0x00, 0x00,
1060x16, 0x00, 0x00, 0x18, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x1c, 0x00,
1070x00, 0x1e, 0x00, 0x00, 0x20, 0x00, 0x00, 0x22, 0x00, 0x00, 0x24,
1080x00, 0x00, 0x26, 0x00, 0x00, 0x28, 0x00, 0x00, 0x2a, 0x00, 0x00,
1090x2c, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x30, 0x00, 0x00, 0x32, 0x00,
1100x00, 0x34, 0x00, 0x00, 0x36, 0x00, 0x00, 0x38, 0x00, 0x00, 0x3a,
1110x00, 0x00, 0x3c, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x40, 0x00, 0x00,
1120x42, 0x03, 0x00, 0x44, 0x01, 0x00, 0x46, 0x0a, 0x21, 0x48, 0x0d,
1130x23, 0x4a, 0x23, 0x1b, 0x4c, 0x37, 0x8f, 0x4e, 0x45, 0x77, 0x50,
1140x52, 0xe2, 0x52, 0x1c, 0x92, 0x54, 0x1c, 0x52, 0x56, 0x07, 0x00,
1150x58, 0x2f, 0xc6, 0x5a, 0x0b, 0x00, 0x5c, 0x30, 0x06, 0x5e, 0x17,
1160x00, 0x60, 0x3d, 0xda, 0x62, 0x29, 0x00, 0x64, 0x3e, 0x41, 0x66,
1170x39, 0x00, 0x68, 0x4c, 0x48, 0x6a, 0x49, 0x00, 0x6c, 0x4c, 0x6c,
1180x6e, 0x11, 0xd2, 0x70, 0x16, 0x0c, 0x72, 0x00, 0x00, 0x74, 0x00,
1190x80, 0x76, 0x0f, 0x00, 0x78, 0x00, 0x80, 0x7a, 0x13, 0x00, 0x7c,
1200x80, 0x00, 0x7e, 0x80, 0x80
121};
122
123unsigned char page_seven[] __initdata = {
1240x0f, 0xff, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00,
1250x00, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
1260x08, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0f,
1270xff, 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1280x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1290x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1300x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1310x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1320x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1330x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1340x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1350x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1360x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1370x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x0f, 0xff,
1380x0f, 0xff, 0x0f, 0xff, 0x02, 0xe9, 0x06, 0x8c, 0x06, 0x8c, 0x0f,
1390xff, 0x1a, 0x75, 0x0d, 0x8b, 0x04, 0xe9, 0x0b, 0x16, 0x1a, 0x38,
1400x0d, 0xc8, 0x04, 0x6f, 0x0b, 0x91, 0x0f, 0xff, 0x06, 0x40, 0x06,
1410x40, 0x02, 0x8f, 0x0f, 0xff, 0x06, 0x62, 0x06, 0x62, 0x02, 0x7b,
1420x0f, 0xff, 0x06, 0x97, 0x06, 0x97, 0x02, 0x52, 0x0f, 0xff, 0x06,
1430xf6, 0x06, 0xf6, 0x02, 0x19, 0x05, 0x55, 0x05, 0x55, 0x05, 0x55,
1440x05, 0x55, 0x05, 0x55, 0x05, 0x55, 0x05, 0x55, 0x05, 0x55, 0x14,
1450xda, 0x0d, 0x93, 0x04, 0xda, 0x05, 0x93, 0x14, 0xda, 0x0d, 0x93,
1460x04, 0xda, 0x05, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1470x00, 0x02, 0x00
148};
149
150unsigned char page_zero_v2[] __initdata = {
1510x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1520x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1530x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1540x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1550x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1560x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1570x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1580x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1590x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
160};
161
162unsigned char page_one_v2[] __initdata = {
1630x01, 0xc0, 0x01, 0xfa, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00,
1640x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1650x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1660x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1670x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1680x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1690x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1700x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1710x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
172};
173
174unsigned char page_two_v2[] __initdata = {
1750x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1760x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1770x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1780x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1790x00, 0x00, 0x00, 0x00
180};
181unsigned char page_three_v2[] __initdata = {
1820x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1830x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1840x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1850x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1860x00, 0x00, 0x00, 0x00
187};
188unsigned char page_four_v2[] __initdata = {
1890x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1900x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1910x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1920x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1930x00, 0x00, 0x00, 0x00
194};
195
196unsigned char page_seven_v2[] __initdata = {
1970x0f, 0xff, 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1980x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1990x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2000x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2010x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2020x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2030x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2040x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2050x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
206};
207unsigned char mod_v2[] __initdata = {
2080x01, 0x00, 0x02, 0x00, 0x01, 0x01, 0x02, 0x00, 0x01, 0x02, 0x02,
2090x00, 0x01, 0x03, 0x02, 0x00, 0x01, 0x04, 0x02, 0x00, 0x01, 0x05,
2100x02, 0x00, 0x01, 0x06, 0x02, 0x00, 0x01, 0x07, 0x02, 0x00, 0xb0,
2110x20, 0xb1, 0x20, 0xb2, 0x20, 0xb3, 0x20, 0xb4, 0x20, 0xb5, 0x20,
2120xb6, 0x20, 0xb7, 0x20, 0xf0, 0x20, 0xf1, 0x20, 0xf2, 0x20, 0xf3,
2130x20, 0xf4, 0x20, 0xf5, 0x20, 0xf6, 0x20, 0xf7, 0x20, 0x10, 0xff,
2140x11, 0xff, 0x12, 0xff, 0x13, 0xff, 0x14, 0xff, 0x15, 0xff, 0x16,
2150xff, 0x17, 0xff, 0x20, 0xff, 0x21, 0xff, 0x22, 0xff, 0x23, 0xff,
2160x24, 0xff, 0x25, 0xff, 0x26, 0xff, 0x27, 0xff, 0x30, 0x00, 0x31,
2170x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, 0x35, 0x00, 0x36, 0x00,
2180x37, 0x00, 0x40, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, 0x44,
2190x00, 0x45, 0x00, 0x46, 0x00, 0x47, 0x00, 0x50, 0x00, 0x51, 0x00,
2200x52, 0x00, 0x53, 0x00, 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, 0x57,
2210x00, 0x60, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x64, 0x00,
2220x65, 0x00, 0x66, 0x00, 0x67, 0x00, 0x70, 0xc0, 0x71, 0xc0, 0x72,
2230xc0, 0x73, 0xc0, 0x74, 0xc0, 0x75, 0xc0, 0x76, 0xc0, 0x77, 0xc0,
2240x80, 0x00, 0x81, 0x00, 0x82, 0x00, 0x83, 0x00, 0x84, 0x00, 0x85,
2250x00, 0x86, 0x00, 0x87, 0x00, 0x90, 0x00, 0x91, 0x00, 0x92, 0x00,
2260x93, 0x00, 0x94, 0x00, 0x95, 0x00, 0x96, 0x00, 0x97, 0x00, 0xa0,
2270x00, 0xa1, 0x00, 0xa2, 0x00, 0xa3, 0x00, 0xa4, 0x00, 0xa5, 0x00,
2280xa6, 0x00, 0xa7, 0x00, 0xc0, 0x00, 0xc1, 0x00, 0xc2, 0x00, 0xc3,
2290x00, 0xc4, 0x00, 0xc5, 0x00, 0xc6, 0x00, 0xc7, 0x00, 0xd0, 0x00,
2300xd1, 0x00, 0xd2, 0x00, 0xd3, 0x00, 0xd4, 0x00, 0xd5, 0x00, 0xd6,
2310x00, 0xd7, 0x00, 0xe0, 0x00, 0xe1, 0x00, 0xe2, 0x00, 0xe3, 0x00,
2320xe4, 0x00, 0xe5, 0x00, 0xe6, 0x00, 0xe7, 0x00, 0x01, 0x00, 0x02,
2330x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x02, 0x01, 0x01, 0x03,
2340x02, 0x01, 0x01, 0x04, 0x02, 0x01, 0x01, 0x05, 0x02, 0x01, 0x01,
2350x06, 0x02, 0x01, 0x01, 0x07, 0x02, 0x01
236};
237unsigned char coefficients[] __initdata = {
2380x07, 0x46, 0x00, 0x00, 0x07, 0x49, 0x00, 0x00, 0x00, 0x4b, 0x03,
2390x11, 0x00, 0x4d, 0x01, 0x32, 0x07, 0x46, 0x00, 0x00, 0x07, 0x49,
2400x00, 0x00, 0x07, 0x40, 0x00, 0x00, 0x07, 0x41, 0x00, 0x00, 0x01,
2410x40, 0x02, 0x40, 0x01, 0x41, 0x02, 0x60, 0x07, 0x40, 0x00, 0x00,
2420x07, 0x41, 0x00, 0x00, 0x07, 0x47, 0x00, 0x00, 0x07, 0x4a, 0x00,
2430x00, 0x00, 0x47, 0x01, 0x00, 0x00, 0x4a, 0x01, 0x20, 0x07, 0x47,
2440x00, 0x00, 0x07, 0x4a, 0x00, 0x00, 0x07, 0x7c, 0x00, 0x00, 0x07,
2450x7e, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1c, 0x07, 0x7c, 0x00, 0x00,
2460x07, 0x7e, 0x00, 0x00, 0x07, 0x44, 0x00, 0x00, 0x00, 0x44, 0x01,
2470x00, 0x07, 0x44, 0x00, 0x00, 0x07, 0x42, 0x00, 0x00, 0x07, 0x43,
2480x00, 0x00, 0x00, 0x42, 0x01, 0x1a, 0x00, 0x43, 0x01, 0x20, 0x07,
2490x42, 0x00, 0x00, 0x07, 0x43, 0x00, 0x00, 0x07, 0x40, 0x00, 0x00,
2500x07, 0x41, 0x00, 0x00, 0x01, 0x40, 0x02, 0x40, 0x01, 0x41, 0x02,
2510x60, 0x07, 0x40, 0x00, 0x00, 0x07, 0x41, 0x00, 0x00, 0x07, 0x44,
2520x0f, 0xff, 0x07, 0x42, 0x00, 0x00, 0x07, 0x43, 0x00, 0x00, 0x07,
2530x40, 0x00, 0x00, 0x07, 0x41, 0x00, 0x00, 0x07, 0x51, 0x06, 0x40,
2540x07, 0x50, 0x06, 0x40, 0x07, 0x4f, 0x03, 0x81, 0x07, 0x53, 0x1a,
2550x76, 0x07, 0x54, 0x0d, 0x8b, 0x07, 0x55, 0x04, 0xe9, 0x07, 0x56,
2560x0b, 0x17, 0x07, 0x57, 0x1a, 0x38, 0x07, 0x58, 0x0d, 0xc9, 0x07,
2570x59, 0x04, 0x6f, 0x07, 0x5a, 0x0b, 0x91, 0x07, 0x73, 0x14, 0xda,
2580x07, 0x74, 0x0d, 0x93, 0x07, 0x75, 0x04, 0xd9, 0x07, 0x76, 0x05,
2590x93, 0x07, 0x77, 0x14, 0xda, 0x07, 0x78, 0x0d, 0x93, 0x07, 0x79,
2600x04, 0xd9, 0x07, 0x7a, 0x05, 0x93, 0x07, 0x5e, 0x03, 0x68, 0x07,
2610x5c, 0x04, 0x31, 0x07, 0x5d, 0x04, 0x31, 0x07, 0x62, 0x03, 0x52,
2620x07, 0x60, 0x04, 0x76, 0x07, 0x61, 0x04, 0x76, 0x07, 0x66, 0x03,
2630x2e, 0x07, 0x64, 0x04, 0xda, 0x07, 0x65, 0x04, 0xda, 0x07, 0x6a,
2640x02, 0xf6, 0x07, 0x68, 0x05, 0x62, 0x07, 0x69, 0x05, 0x62, 0x06,
2650x46, 0x0a, 0x22, 0x06, 0x48, 0x0d, 0x24, 0x06, 0x6e, 0x11, 0xd3,
2660x06, 0x70, 0x15, 0xcb, 0x06, 0x52, 0x20, 0x93, 0x06, 0x54, 0x20,
2670x54, 0x06, 0x4a, 0x27, 0x1d, 0x06, 0x58, 0x2f, 0xc8, 0x06, 0x5c,
2680x30, 0x07, 0x06, 0x4c, 0x37, 0x90, 0x06, 0x60, 0x3d, 0xdb, 0x06,
2690x64, 0x3e, 0x42, 0x06, 0x4e, 0x45, 0x78, 0x06, 0x68, 0x4c, 0x48,
2700x06, 0x6c, 0x4c, 0x6c, 0x06, 0x50, 0x52, 0xe2, 0x06, 0x42, 0x02,
2710xba
272};
273unsigned char coefficients2[] __initdata = {
2740x07, 0x46, 0x00, 0x00, 0x07, 0x49, 0x00, 0x00, 0x07, 0x45, 0x0f,
2750xff, 0x07, 0x48, 0x0f, 0xff, 0x07, 0x7b, 0x04, 0xcc, 0x07, 0x7d,
2760x04, 0xcc, 0x07, 0x7c, 0x00, 0x00, 0x07, 0x7e, 0x00, 0x00, 0x07,
2770x46, 0x00, 0x00, 0x07, 0x49, 0x00, 0x00, 0x07, 0x47, 0x00, 0x00,
2780x07, 0x4a, 0x00, 0x00, 0x07, 0x4c, 0x00, 0x00, 0x07, 0x4e, 0x00, 0x00
279};
280unsigned char coefficients3[] __initdata = {
2810x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x28, 0x00, 0x51, 0x00,
2820x51, 0x00, 0x7a, 0x00, 0x7a, 0x00, 0xa3, 0x00, 0xa3, 0x00, 0xcc,
2830x00, 0xcc, 0x00, 0xf5, 0x00, 0xf5, 0x01, 0x1e, 0x01, 0x1e, 0x01,
2840x47, 0x01, 0x47, 0x01, 0x70, 0x01, 0x70, 0x01, 0x99, 0x01, 0x99,
2850x01, 0xc2, 0x01, 0xc2, 0x01, 0xeb, 0x01, 0xeb, 0x02, 0x14, 0x02,
2860x14, 0x02, 0x3d, 0x02, 0x3d, 0x02, 0x66, 0x02, 0x66, 0x02, 0x8f,
2870x02, 0x8f, 0x02, 0xb8, 0x02, 0xb8, 0x02, 0xe1, 0x02, 0xe1, 0x03,
2880x0a, 0x03, 0x0a, 0x03, 0x33, 0x03, 0x33, 0x03, 0x5c, 0x03, 0x5c,
2890x03, 0x85, 0x03, 0x85, 0x03, 0xae, 0x03, 0xae, 0x03, 0xd7, 0x03,
2900xd7, 0x04, 0x00, 0x04, 0x00, 0x04, 0x28, 0x04, 0x28, 0x04, 0x51,
2910x04, 0x51, 0x04, 0x7a, 0x04, 0x7a, 0x04, 0xa3, 0x04, 0xa3, 0x04,
2920xcc, 0x04, 0xcc, 0x04, 0xf5, 0x04, 0xf5, 0x05, 0x1e, 0x05, 0x1e,
2930x05, 0x47, 0x05, 0x47, 0x05, 0x70, 0x05, 0x70, 0x05, 0x99, 0x05,
2940x99, 0x05, 0xc2, 0x05, 0xc2, 0x05, 0xeb, 0x05, 0xeb, 0x06, 0x14,
2950x06, 0x14, 0x06, 0x3d, 0x06, 0x3d, 0x06, 0x66, 0x06, 0x66, 0x06,
2960x8f, 0x06, 0x8f, 0x06, 0xb8, 0x06, 0xb8, 0x06, 0xe1, 0x06, 0xe1,
2970x07, 0x0a, 0x07, 0x0a, 0x07, 0x33, 0x07, 0x33, 0x07, 0x5c, 0x07,
2980x5c, 0x07, 0x85, 0x07, 0x85, 0x07, 0xae, 0x07, 0xae, 0x07, 0xd7,
2990x07, 0xd7, 0x08, 0x00, 0x08, 0x00, 0x08, 0x28, 0x08, 0x28, 0x08,
3000x51, 0x08, 0x51, 0x08, 0x7a, 0x08, 0x7a, 0x08, 0xa3, 0x08, 0xa3,
3010x08, 0xcc, 0x08, 0xcc, 0x08, 0xf5, 0x08, 0xf5, 0x09, 0x1e, 0x09,
3020x1e, 0x09, 0x47, 0x09, 0x47, 0x09, 0x70, 0x09, 0x70, 0x09, 0x99,
3030x09, 0x99, 0x09, 0xc2, 0x09, 0xc2, 0x09, 0xeb, 0x09, 0xeb, 0x0a,
3040x14, 0x0a, 0x14, 0x0a, 0x3d, 0x0a, 0x3d, 0x0a, 0x66, 0x0a, 0x66,
3050x0a, 0x8f, 0x0a, 0x8f, 0x0a, 0xb8, 0x0a, 0xb8, 0x0a, 0xe1, 0x0a,
3060xe1, 0x0b, 0x0a, 0x0b, 0x0a, 0x0b, 0x33, 0x0b, 0x33, 0x0b, 0x5c,
3070x0b, 0x5c, 0x0b, 0x85, 0x0b, 0x85, 0x0b, 0xae, 0x0b, 0xae, 0x0b,
3080xd7, 0x0b, 0xd7, 0x0c, 0x00, 0x0c, 0x00, 0x0c, 0x28, 0x0c, 0x28,
3090x0c, 0x51, 0x0c, 0x51, 0x0c, 0x7a, 0x0c, 0x7a, 0x0c, 0xa3, 0x0c,
3100xa3, 0x0c, 0xcc, 0x0c, 0xcc, 0x0c, 0xf5, 0x0c, 0xf5, 0x0d, 0x1e,
3110x0d, 0x1e, 0x0d, 0x47, 0x0d, 0x47, 0x0d, 0x70, 0x0d, 0x70, 0x0d,
3120x99, 0x0d, 0x99, 0x0d, 0xc2, 0x0d, 0xc2, 0x0d, 0xeb, 0x0d, 0xeb,
3130x0e, 0x14, 0x0e, 0x14, 0x0e, 0x3d, 0x0e, 0x3d, 0x0e, 0x66, 0x0e,
3140x66, 0x0e, 0x8f, 0x0e, 0x8f, 0x0e, 0xb8, 0x0e, 0xb8, 0x0e, 0xe1,
3150x0e, 0xe1, 0x0f, 0x0a, 0x0f, 0x0a, 0x0f, 0x33, 0x0f, 0x33, 0x0f,
3160x5c, 0x0f, 0x5c, 0x0f, 0x85, 0x0f, 0x85, 0x0f, 0xae, 0x0f, 0xae,
3170x0f, 0xd7, 0x0f, 0xd7, 0x0f, 0xff, 0x0f, 0xff
318};
319
diff --git a/sound/oss/yss225.h b/sound/oss/yss225.h
new file mode 100644
index 000000000000..56d8b6b5e432
--- /dev/null
+++ b/sound/oss/yss225.h
@@ -0,0 +1,24 @@
1#ifndef __yss255_h__
2#define __yss255_h__
3
4extern unsigned char page_zero[256];
5extern unsigned char page_one[256];
6extern unsigned char page_two[128];
7extern unsigned char page_three[128];
8extern unsigned char page_four[128];
9extern unsigned char page_six[192];
10extern unsigned char page_seven[256];
11extern unsigned char page_zero_v2[96];
12extern unsigned char page_one_v2[96];
13extern unsigned char page_two_v2[48];
14extern unsigned char page_three_v2[48];
15extern unsigned char page_four_v2[48];
16extern unsigned char page_seven_v2[96];
17extern unsigned char mod_v2[304];
18extern unsigned char coefficients[364];
19extern unsigned char coefficients2[56];
20extern unsigned char coefficients3[404];
21
22
23#endif /* __ys225_h__ */
24