GIT 04e5a706d39a2353b42b92d51b20c5bedc56a720 git+ssh://master.kernel.org/pub/scm/linux/kernel/git/perex/alsa.git#mm commit Author: Takashi Iwai Date: Tue Nov 20 18:32:08 2007 +0100 [ALSA] caiaq - Fix indent in Kconfig Fix indent of caiaq in Kconfig to the same level as others. Just a tidy up. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 26d7222abda5f3156e93a29179aedf4394bdb9f2 Author: Takashi Iwai Date: Tue Nov 20 18:31:22 2007 +0100 [ALSA] dbri - Fix broken change for value range checks The last patch for value range checks included a broken merge result. Now fixed properly. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit d1703fbfe89cba6ba08524e872a2917d60ad0d97 Author: Kamalesh Babulal Date: Tue Nov 20 15:12:33 2007 +0100 [ALSA] powermac - Fix typos The kernel build fails, with following error CC sound/ppc/tumbler.o sound/ppc/tumbler.c: In function ‘snapper_get_capture_source’: sound/ppc/tumbler.c:812: error: ‘union ’ has no member named ‘value’ sound/ppc/tumbler.c: In function ‘snapper_put_capture_source’: sound/ppc/tumbler.c:824: error: ‘union ’ has no member named ‘enuemerated’ make[2]: *** [sound/ppc/tumbler.o] Error 1 make[1]: *** [sound/ppc] Error 2 make: *** [sound] Error 2 Signed-off-by: Kamalesh Babulal Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 035fc24bc714b8071a7574b3d36e7373f8f52499 Author: Takashi Iwai Date: Mon Nov 19 11:56:26 2007 +0100 [ALSA] hda-codec - Revert volume knob controls in STAC codecs Volume knob controls with STAC codecs seem to cause problems with some devices. Volumes change very slowly or silent suddenly. It's likely due to conflict between the software and the hardware volume knob setup. Since we'll have a virtual master control in future, it's safer to remove this control completely right now. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 690a439e05268e20b3cc930bb84a497bfb131fa0 Author: Takashi Iwai Date: Fri Nov 16 17:52:39 2007 +0100 [ALSA] hda-intel - Show more volume-knob attributes Show more attributs of volume-knob widgets. Also don't put empty lines when no connection list is found. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit c053e4c0a8e836aa3657d89b1789366f3652d500 Author: Ingo Molnar Date: Fri Nov 16 15:20:28 2007 +0100 [ALSA] snd hda suspend latency: shorten codec read not sleeping for every codec read/write but doing a short udelay and a conditional reschedule has cut suspend+resume latency by about 1 second on my T60. Signed-off-by: Ingo Molnar Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit a53c07ad66b5ea77e64b87b13d07d6437b33b78f Author: Wolke Liu Date: Fri Nov 16 11:06:30 2007 +0100 [ALSA] HDA-Intel - Add support for RV6xx HDMI audio This patch is to add R6xx HDMI audio support. Meanwhile, the device ID in the previous patch is changed. I have checked the patch from Herton Ronaldo Krzesinski, it's right as our spec said. :) Signed-off-by: Wolke Liu Signed-off-by: Andrea Zhang Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit b654ca0b7af26f5f7f7dfe352a767f6661590dc0 Author: Takashi Iwai Date: Thu Nov 15 16:18:14 2007 +0100 [ALSA] at73c213 - Use common callback Use snd_ctl_boolean_mono_info callback to simplify. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 64fa1c075d15844a5b099778aa494bede12fa3cb Author: Takashi Iwai Date: Thu Nov 15 16:17:24 2007 +0100 [ALSA] Check value range in ctl callbacks Check the value ranges in ctl put callbacks properly (in the rest drivers). Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit fc62a50cca800f2a77aa394e877c7be3f0fe4f96 Author: Takashi Iwai Date: Thu Nov 15 16:16:32 2007 +0100 [ALSA] aoa - Check value range in ctl callbacks Check the value ranges in ctl put callbacks properly in aoa drivers. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 69c1a01c2799fa2371a8efd39f8332636f547dd3 Author: Takashi Iwai Date: Thu Nov 15 16:15:29 2007 +0100 [ALSA] ak4xxx - Check value ranges in ctl callbacks Check the value ranges in ctl put callbacks properly in ak4xxx-adda driver. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 228459ea4f5318cd56a7290d3d8c28b971f9b5f6 Author: Takashi Iwai Date: Thu Nov 15 16:14:12 2007 +0100 [ALSA] powermac - Check value range in ctl callbacks Check the value ranges in ctl put callbacks properly in snd-powermac driver. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit aca9197301fbd6754d3f57d5f4600af0b4506c8b Author: Takashi Iwai Date: Thu Nov 15 16:13:32 2007 +0100 [ALSA] vxpocket - Check value range in ctl callbacks Check the value ranges in ctl put callbacks in vxpocket driver. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit b39102cf6aed5d48cb981440b8edaa46eecbf2b2 Author: Takashi Iwai Date: Thu Nov 15 16:05:26 2007 +0100 [ALSA] ice1724 - Clean up ctl callbacks in se.c Clean up ctl callbacks of SE-200PCI driver. Also make sure to check the value ranges. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 67611feaf0d3cf2b25f8eb309b5eeb2460bf7a23 Author: Takashi Iwai Date: Thu Nov 15 15:58:13 2007 +0100 [ALSA] pci - check value range in ctl callbacks Check the value ranges in ctl put callbacks properly in the rest of PCI drivers. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 551d17a419a63b32cca6450521571ce7161001f0 Author: Takashi Iwai Date: Thu Nov 15 15:56:47 2007 +0100 [ALSA] mixart - Check value range in ctl callbacks Check the value ranges in ctl put callbacks properly. Also fixed some coding style issues around that. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit b55cfe41f749a273ec646d56a8b556fbcbff06f2 Author: Takashi Iwai Date: Thu Nov 15 15:56:07 2007 +0100 [ALSA] ice1724 - Check value ranges in ctl callbacks Check the value ranges in ctl put callbacks properly. Also fixed the wrong access type to enum elements in aureon.c. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 64c8e0ad172ecc2f6ae4e00766e10767948a8f9b Author: Takashi Iwai Date: Thu Nov 15 15:54:38 2007 +0100 [ALSA] hda-codec - Check value range in ctl callbacks Check the value ranges in ctl put callbacks properly so that invalid values won't be stored or written to registers. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 072169e03c1ad9cd48ac3a0df6f2ed48ef46a1a8 Author: Takashi Iwai Date: Thu Nov 15 14:42:34 2007 +0100 [ALSA] ca0106 - Check value range in ctl callbacks Check the value ranges in ctl put callbacks properly. Some callbacks may access a wrong pointer depending on the value passed. Also, fixed the access to the wrong field for enum values, and fixed some callbacks to return the proper error code. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 785dd00fa8e734338dfc7ef320595df166890f37 Author: Vladimir Barinov Date: Wed Nov 14 17:07:17 2007 +0100 [ALSA] ASoC TLV320AIC3X codec driver This patch adds ALSA SoC support for TI TLV320AIC3X audio codecs. The features that are supported: o Capture/Playback/Bypass. o 16/20/24/32 bit audio. o 8k - 96k sample rates. o codec master only mode o DAPM. Signed-off-by: Vladimir Barinov Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit c29ae19988b727876668f9c8ca14fc39f82f50f2 Author: Takashi Iwai Date: Wed Nov 14 14:53:42 2007 +0100 [ALSA] hda-codec - Check PINCAP only for PIN widgets The recent addition of checking PINCAP for EAPD seems to break some systems due to unexpected response from the codec chip. We shouldn't issue GET_PINCAP verb to non-PIN widgets. Now checks the widget type before checking EAPD bit. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 2eaa5377761d4c487bfe3facdc2c1b834265404b Author: Julia Lawall Date: Wed Nov 14 14:30:43 2007 +0100 [ALSA] sound/pci: Drop unnecessary continue Continue is not needed at the bottom of a loop. The semantic patch implementing this change is as follows: @@ @@ for (...;...;...) { ... if (...) { ... - continue; } } Signed-off-by: Julia Lawall Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 59c053447d42bba1177e0f21db5ddeb9119dd6f8 Author: Takashi Iwai Date: Wed Nov 14 12:26:44 2007 +0100 [ALSA] hda-codec - Add model=hp-tc-t5735 for ALC262 Added the missing model string for the new support of HP TC T5735. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 6d46831f707548c987503642308bb87dca7c0437 Author: Timur Tabi Date: Wed Nov 14 12:07:58 2007 +0100 [ALSA] fix private data pointer calculation in CS4270 driver Fix the calculation of the private_data pointer in the CS4270 driver. Signed-off-by: Timur Tabi Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit d667c868bcfc171f45a39ecad4868ed7b3063397 Author: Kailang Yang Date: Wed Nov 14 12:06:21 2007 +0100 [ALSA] hda-codec - Add support of HP Thin Client T5735 Added the support of HP Thin Client T5735 [0x103c 0x302f] with ALC262 codec. Signed-off-by: Kailang Yang Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 90494c046bb76874798d9b7d99ec506652846919 Author: Jiang Zhe Date: Mon Nov 12 13:05:16 2007 +0100 [ALSA] hda-codec - Avoid wrong speaker-auto mute via mic jack When a mic jack is set up as the multiple I/O, it may issue the automute function wrongly. This patch fixes the wrong automute detection. Signed-off-by: Jiang Zhe Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit aee22164fd9198557358b1d372aeb15ce3b050a2 Author: Jiang Zhe Date: Mon Nov 12 12:57:03 2007 +0100 [ALSA] hda-codec - Add workaround for multiple HPs Dell laptops have multiple HP jacks that can be used for multi-channel outputs. The current auto pincfg handles the speaker as the primary output and thus cannot handle the multi-channel configuration for such cases. This patch adds a workaround to fix this issue by swapping the HP and speaker during multi-channel setup routines. Signed-off-by: Jiang Zhe Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 01d0544173b5862a8a7c16089d9998952b942ffe Author: Jiang Zhe Date: Mon Nov 12 12:43:37 2007 +0100 [ALSA] hda-codec - Update dell-m82 model pin config Updated dell-m82 model pin config table. The old config doesn't work with Dell 1210 and co. Signed-off-by: Jiang Zhe Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 33157b9bc45c4bcf9c65afcda8e9a546db60de4f Author: Nicolas Kaiser Date: Mon Nov 12 12:25:02 2007 +0100 [ALSA] sound/pci: remove duplicated defines Remove duplicated defines. (From their use it looks like 'midiDataOutx are written to rather than read from.) Signed-off-by: Nicolas Kaiser Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit b1d9c5439b2c2a0927e4044c45952e5aece6d616 Author: Jiri Olsa Date: Mon Nov 12 12:15:42 2007 +0100 [ALSA] sound: remove dead config symbol from sound code remove dead config symbols from sound code Signed-off-by: Jiri Olsa Signed-off-by: Andrew Morton Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit d2d6fb741fe10256c493b6294ae6ac4cf4dc726a Author: Stanislav Brabec Date: Mon Nov 12 12:11:10 2007 +0100 [ALSA] use convenient treble scale on WM8750 On Zaurus SL-C3200 (terrier/spitz) based on WM8750, treble scale is inconveniently reverted (increase level = decrease treble), in opposite to bass scale, which uses convenient scale. Fix ALSA WM8750 mixer treble to use convenient treble scale (increase = increase treble level) From: Stanislav Brabec Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 22e29181a4614a5291064cf168cb40ba04130faa Author: Clemens Ladisch Date: Mon Nov 12 08:47:57 2007 +0100 [ALSA] mpu401: fix recursive locking in timer When the output and input ports are used at the same time, the timer can be interrupted by the hardware interrupt, so we have to disable interrupts when we take a lock in the timer. Signed-off-by: Clemens Ladisch Signed-off-by: Jaroslav Kysela commit 84eb4c12d8c47aae6213d70a3183a5a77f60a941 Author: Takashi Iwai Date: Thu Nov 8 09:09:58 2007 +0100 [ALSA] Update SNDRV_HWDEP_IFACE_LAST Updated the forgotten SNDRV_HWDEP_IFACE_LAST to point the really last member. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 9a8c13af8b17f9956bf52b4788a12abbc43e80de Author: Nicolas Kaiser Date: Wed Nov 7 18:31:43 2007 +0100 [ALSA] sound/pci: remove line duplications in defines Remove line duplications in defines. Acked-by: Thomas Sailer Signed-off-by: Nicolas Kaiser Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit fd7000af3bdf49b5639014aa020d5e75ea17b0fc Author: Matthew Ranostay Date: Wed Nov 7 15:54:45 2007 +0100 [ALSA] hda: STAC9228 Subsystem update Added more laptops subsystem id's that have STAC9228 DMIC support. Signed-off-by: Matthew Ranostay Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit c0633a22868ecf1ccf33a74347c920d04f3c2d63 Author: Timofei Bondarenko Date: Wed Nov 7 15:50:52 2007 +0100 [ALSA] cmipci - allow capture of raw spdif subframes Enable capturing of raw 32bit IEC958_SUBFRAME. The 24-bits PCM data can be obtained using iec958 plugin. Known problem: captured stream may begin with either left or right subframe. Since the iec958 plugin doesn't decode preamble it may swap the channels sometime. Signed-off-by: Timofei Bondarenko Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 6822eb80586fae04e31dbd3616ad92738c2ac987 Author: Timofei Bondarenko Date: Wed Nov 7 15:49:57 2007 +0100 [ALSA] cmipci - utilize ADC48K44K bit Setting the ADC48K44K greatly improves capture quality at 48k sampling rate. With this bit clear ADC does ZOH interpolation of every 22th sample at 48k. At frequencies higher than 48k there ADC performs a little better with ADC48K44K bit set. At 44.1k ADC performs a little better with this bit clear. At frequencies below 44.1k there is no difference. Signed-off-by: Timofei Bondarenko Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 1ee3f9ec78760746ed76023baaf156187df765e7 Author: Takashi Iwai Date: Wed Nov 7 14:18:01 2007 +0100 [ALSA] hda-codec - new PCI SSID for HP machines Added new PCI SSIDs for HP machines with ALC262 codec. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit e5aa57ec1ea56158a5b98d5d1964075ab84ac21c Author: Matthew Ranostay Date: Wed Nov 7 13:03:12 2007 +0100 [ALSA] hda: STAC92HD71 codec mixer Added analog loopback support and missing ADC capture mixer for the STAC92HD71 codec family. Signed-off-by: Matthew Ranostay Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 1c139a110ebbef1b06cff64e4250b64c045c1389 Author: Manuel Lauss Date: Tue Nov 6 11:56:17 2007 +0100 [ALSA] ASoC: sh: improve generated code for HAC module (AC97) Change loops in ac97_read/write functions to count down to zero rather than up. Gcc will then use the 'dt' (decrement-and-test) op instead of an increment/compare op-pair. Signed-off-by: Manuel Lauss Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 84ede003c5ff0598b07c3aed2e1a302ddbbee78e Author: Matthew Ranostay Date: Tue Nov 6 11:53:55 2007 +0100 [ALSA] hda: Added new IDT codec family Added initial support for the STAC92HD71BXX family of codecs. Signed-off-by: Matthew Ranostay Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 714fd76c3db3ae20fbdbe40edfaa997951f140d5 Author: Herton Ronaldo Krzesinski Date: Mon Nov 5 18:21:56 2007 +0100 [ALSA] HDA-Intel - Add support for RV610/RV630 HDMI audio The Audio interface on HD2400/HD2600 cards isn't currently detected by snd-hda-intel. I added missing pci device ids for RV610 and RV630, but I only had a HD2400 pro card to test, where now the audio interface is detected (and no need to change patch_atihdmi.c, as the codec vendor id remains 0x1002aa01 for which we already have an entry there). I also couldn't test if sound pass-trough is ok (and I don't know how to), but at least now the device is detected. Signed-off-by: Herton Ronaldo Krzesinski Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 9a9cde40335287d6ffd55a33246ab9543c0ca102 Author: Joachim Foerster Date: Mon Nov 5 15:48:36 2007 +0100 [ALSA] [ML403-AC97CR] Fix capture/periodic overrun bug We have to do fairly accurate counting of the minimal periods, instead of being lazy and just setting the number to zero as soon as one period elapses. Signed-off-by: Joachim Foerster Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit ec5a7a2008dc187391a4065ae2be1fd4fdbef290 Author: Joachim Foerster Date: Mon Nov 5 16:06:01 2007 +0100 [ALSA] Xilinx ML403 AC97 Controller Reference device driver Add ALSA support for the opb_ac97_controller_ref_v1_00_a ip core found in Xilinx' ML403 reference design. Known issue: Currently this driver hits a WARN_ON_ONCE(1) statement in kernel/irq/resend.c (line 70). According to Linus (http://lkml.org/lkml/2007/8/5/5) this may be ignored, right? I haven't had a look into this 'problem' yet. Signed-off-by: Joachim Foerster Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit d2afa1767d010982a10aa022bd8c51bd1b9461af Author: Matthew Ranostay Date: Mon Nov 5 15:30:13 2007 +0100 [ALSA] hda: STAC9228 DMIC Added support for the dmics and enabled EAPD for several laptops with STAC9228 cards. Signed-off-by: Matthew Ranostay Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit cd895b5f4f473641a885170f4c06708229457f7a Author: Tobin Davis Date: Mon Nov 5 15:13:51 2007 +0100 [ALSA] HDA: Add Asus VX1 support Simple patch to add the Asus VX1 laptop to the Analog Devices pci quirk list. Signed-off-by: Tobin Davis Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 6429e3e63a118af1b1f85e8da2f741b51fe3054a Author: Timofei Bondarenko Date: Wed Oct 31 17:36:20 2007 +0100 [ALSA] cmipci at 96kHz This patch adds support for 88.2k, 96k, and 128k samplerates on cmi8738-55 chip. Analog playback works fine on all channels. Analog capture works well too, though the extra samples seems interpolated by hardware. spdif playback and capture works fine. Signed-off-by: Timofei Bondarenko Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 1ba982047f855eed7c84c652bd91c256f2ce5074 Author: Takashi Iwai Date: Wed Oct 31 15:49:32 2007 +0100 [ALSA] hda-codec - Improve the auto-configuration Some small improvements on autocfg stuff: - sort HP pins by sequence number, too - move sole mic pin to AUTO_PIN_MIC instead of AUTO_PIN_FRONT_MIC - ditto for line-in pin Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 023917a2f05b7f65effe94feb8c584437bf9b9cc Author: Timofei Bondarenko Date: Tue Oct 30 15:28:14 2007 +0100 [ALSA] usb-audio - SB Live24-External better handling This patch improves support for 'SB Live 24-bit Extarnal' USB card. 1) This card can go into muted state when a headphones connected or disconnected. So notify mixer about changes in headphone jack. 2) Add LED controls and procfs support just as in similar Audigy 2 NX card. 3) Rename 'PCM Capture' conrol to 'Mic Capture' to reflect reality: the card may adjust microphone input level only. Signed-off-by: Timofei Bondarenko Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 891f0b5c04ca5de7332f31dbab450b135ab6f77e Author: Takashi Iwai Date: Tue Oct 30 12:43:40 2007 +0100 [ALSA] opl3 - Fix build errors I applied a wrong patch for 'opl3 - simplify exclusive access lock'. Fixed now. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit e562192b303be7b9fcfcd9b9cd18e81d7eace918 Author: Takashi Iwai Date: Tue Oct 30 12:17:17 2007 +0100 [ALSA] Remove sequencer instrument layer Remove sequencer instrument layer from the tree. This mechanism hasn't been used much with the actual devices. The only reasonable user was OPL3 loader, and now it was rewritten to use hwdep instead. So, let's remove the rest of rotten codes. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 829040642c6db821323094e505425d278fe02609 Author: Takashi Iwai Date: Tue Oct 30 11:59:15 2007 +0100 [ALSA] opl3 - simplify exclusive access lock Use the exclusive access lock in hwdep instead of the own one. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 1fd4ff30ceedfb671a888d34cce14c0fa698dd33 Author: Takashi Iwai Date: Tue Oct 30 11:49:22 2007 +0100 [ALSA] opl3 - Use hwdep for patch loading Use the hwdep device for loading OPL2/3 patch data instead of the messy sequencer instrument layer. Due to this change, the sbiload program should be updated, too. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 330f724a14623f45e49f8180159e904892b89982 Author: Clemens Ladisch Date: Tue Oct 30 08:59:14 2007 +0100 [ALSA] cmipci: fix FLINKON/OFF bits Fix the definitions of the CM_FLINKON/CM_FLINKOFF register bits that were garbled in the last 'update register definitions' patch. Signed-off-by: Clemens Ladisch Signed-off-by: Jaroslav Kysela commit 72a4194c1c240d78609f4dd90d2a2cb3f7b25523 Author: Takashi Iwai Date: Mon Oct 29 11:14:31 2007 +0100 [ALSA] portman2x4 - Fix probe error Reported by Ingo Molnar, when booting an allyesconfig bzImage kernel the bootup hangs in the portman2x4 driver (on a box that does not have this hardware), at: Pid: 1, comm: swapper EIP: 0060:[] CPU: 0 EIP is at parport_pc_read_status+0x4/0x8 EFLAGS: 00000202 Not tainted (2.6.23-rc9 #904) EAX: f7e57a7f EBX: 00000010 ECX: c2b808c0 EDX: 00000379 ESI: f7cb8230 EDI: 00000010 EBP: f7cb8230 DS: 007b ES: 007b FS: 0000 CR0: 8005003b CR2: fff9c000 CR3: 007ec000 CR4: 00000690 DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000000 DR6: ffff0ff0 DR7: 00000400 [] portman_flush_input+0xde/0x12c [] snd_portman_probe+0x368/0x484 [] __device_attach+0x0/0x8 [] platform_drv_probe+0xc/0x10 [] driver_probe_device+0x74/0x194 [] klist_next+0x38/0x70 [] __device_attach+0x0/0x8 [] bus_for_each_drv+0x35/0x68 [] device_attach+0x72/0x78 the reason is due to an inconsistent error return code of 1 or 2, while snd_portman_probe only realizes negative error codes. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 44b0056d3f41997006d88bcfa3327bdbf9073f1f Author: Takashi Iwai Date: Mon Oct 29 10:49:43 2007 +0100 [ALSA] Dreamcast AICA sound - Get rid of annoying compiler warning This patch supresses an annoying compiler warning that the variable err may be used uninitialised. Signed-off by: Adrian McMenamin Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit d9e0fd14353e379d8a63e14532c07c46fe5228ad Author: Krzysztof Helt Date: Mon Oct 29 10:48:40 2007 +0100 [ALSA] ac97_patch: compilation warning fix This patch kills these two compilation warnings if power management is disabled: sound/pci/ac97/ac97_patch.h:86: warning: 'snd_ac97_restore_status' declared 'static' but never defined sound/pci/ac97/ac97_patch.h:87: warning: 'snd_ac97_restore_iec958' declared 'static' but never defined Signed-off-by: Krzysztof Helt Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit ef5e9f6f50582386b1c24cb3cf90185a3dc58cb7 Author: Takashi Iwai Date: Fri Oct 26 15:10:15 2007 +0200 [ALSA] Introduce slots option to snd module Introduced the global 'slots' option to snd module. This option provides an alternative way to handle the order of multiple sound card instances. It's an easier approach to avoid conflict with hotplug devices, and can be used together with the existing 'order' option of each card driver. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit bc7c1485f553c45f0fdd286dfca5b601a78698fc Author: Takashi Iwai Date: Fri Oct 26 14:56:36 2007 +0200 [ALSA] hda-codec - Show more information in proc file Show the current EAPD status and volume-knob status in proc file. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit a813fd218463203b89aa0923ef460a8121fac65a Author: Ivan Kuten Date: Fri Oct 26 14:53:47 2007 +0200 [ALSA] soc - ln2440sbc ac97 support This patch adds ac97 support for ln2440sbc board from LittleChips. This board is based on s3c2440 SoC + AC97 Realtek ALC650 codec. Existing s3c2443 implementation is slightly modified because s3c2440 and s3c2443 have different AC97 interrupts. Signed-off-by: Ivan Kuten Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit b8c1d0c8710a4d924eda35683958d5bac3fbb0a3 Author: Tobin Davis Date: Fri Oct 26 12:40:47 2007 +0200 [ALSA] HDA: Add support for Samsung Q1 Ultra Vista edition This patch adds full record and playback support for the Samsung Q1 Ultra - Vista model (different codec than the earlier Q1 Ultra models). Signed-off-by: Tobin Davis Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 639196c59444e78d476477c919504be238c108b6 Author: Takashi Iwai Date: Fri Oct 26 12:35:56 2007 +0200 [ALSA] hda-codec - Disable shared stream on AD1986A AD1986A has a hardware problem that it cannot share a stream with multiple pins properly. The problem occurs e.g. when a volume is changed during playback. So far, hda-intel driver unconditionally assigns the stream to multiple output pins in copy-front mode, and this should be avoided for AD1986A codec. The original fix patch was by zhejiang . Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 9355500af8b85a196d9189834651d6c30ae4904f Author: Takashi Iwai Date: Thu Oct 25 11:46:24 2007 +0200 [ALSA] via82xx - Fix quirk for Shuttle AK32VN Fix quirk for Shuttle AK32VN. It works better with DXS_SRC, and needs HP_ONLY ac97 quirk. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit f6fe4f7e51c6465e1e68d9fd8c9b91e9cca3edb8 Author: Takashi Iwai Date: Wed Oct 24 18:18:11 2007 +0200 [ALSA] ad1848 - Fix print format Fixed the print format for debug message. Spotted by Matthew Wilcox. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 07fac221ecef53749f14139126c89fd52a122c39 Author: Takashi Iwai Date: Wed Oct 24 18:02:17 2007 +0200 [ALSA] ca0106 - Fix write proc assignment The driver assigns the write proc callback to read wrongly. Fixed now. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit d36602ff0831e3d1101352e1572714db5d315f28 Author: Michael Opdenacker Date: Wed Oct 24 10:59:44 2007 +0200 [ALSA] writing-an-alsa-driver.tmpl: English style improvements This patch brings some English style improvements throughout the document, as well as 1 or 2 extra technical details. Signed-off-by: Michael Opdenacker Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit d604ea8f2b3e1c5a156be0fd3fc22c5299616b24 Author: Shin-ya Okada Date: Tue Oct 23 15:08:18 2007 +0200 [ALSA] ice1724 - Add support of Onkyo SE-90PCI and SE-200PCI Added the support for Onkyo SE-90PCI and SE-200PCI boards. Signed-off-by: Shin-ya Okada Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 11afdb48d7cca657b207917f12a424bd5e29be88 Author: Mike Rapoport Date: Mon Oct 22 17:41:08 2007 +0200 [ALSA] soc - Add 'Mono Playback Switch' to WM9712 codec driver The following patch adds 'Mono Playback Switch' control to WM9712 codec SoC driver. Also, it fixes Treble, Bass and Mono playback volume inversion bits. Signed-off-by: Mike Rapoport Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 83459eca46038c777b0985b0e2294ffafb598e21 Author: Takashi Iwai Date: Mon Oct 22 17:05:35 2007 +0200 [ALSA] hda-codec - Add model for Fujitsu V5505 Added model=laptop for Fujitsu V5505 with Cxt5405 codec. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 407ce5f4d8f8d8dd52a3a0921c514caa5c4a4fed Author: Matthew Ranostay Date: Mon Oct 22 12:27:10 2007 +0200 [ALSA] hda: STAC9228 updated DMUX nid Changed the dmux for STAC9228 from ADC1MUX to ADC0MUX to avoid confusion. Signed-off-by: Matthew Ranostay Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 10e9c7e226de51d47b816fee0a08d69f4373032c Author: Krzysztof Helt Date: Fri Oct 19 08:23:00 2007 +0200 [ALSA] s3c2443-ac97: compilation fix The Samsung S3C24xx uses new architecture file layout in the post 2.6.23 kernel. This patch fixes include path for the s3c2443-ac97.c. Signed-off-by: Krzysztof Helt Signed-off-by: Andrew Morton Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit bd88bf3db1136ead60c1a3c60b58ce57d15343c0 Author: Matthew Ranostay Date: Fri Oct 19 08:19:56 2007 +0200 [ALSA] hda: Add dmux to STAC 9228 Added a dmux to the STAC9228 cards with DMIC support. And added a STAC_DIGITAL_INPUT_SOURCE macro for repeating mixer code. Signed-off-by: Matthew Ranostay Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit ad6af2cb83d4c8094597e2fd392f234101f2410e Author: Matthew Ranostay Date: Thu Oct 18 17:38:17 2007 +0200 [ALSA] hda-codec - Add STAC9228 DMIC support Added the missing STAC9228 DMIC support. Also added a new vendor id tag for IDT. Signed-off-by: Matthew Ranostay Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela commit 134c75fab51cb255fe6789fab3f05b308f918d3c Author: Takashi Iwai Date: Wed Oct 17 10:41:06 2007 +0200 [ALSA] hda-codec - Add missing eeepc-p701 model for ALC662 Added the missing model string 'eeepc-p701' for ALC662 codec. Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela Documentation/sound/alsa/ALSA-Configuration.txt | 29 +- .../sound/alsa/DocBook/writing-an-alsa-driver.tmpl | 920 +++++++------- include/sound/ainstr_fm.h | 134 -- include/sound/ainstr_gf1.h | 229 ---- include/sound/ainstr_iw.h | 384 ------ include/sound/ainstr_simple.h | 159 --- include/sound/asequencer.h | 242 +---- include/sound/asound.h | 2 +- include/sound/asound_fm.h | 19 + include/sound/cs46xx.h | 3 - include/sound/driver.h | 4 - include/sound/gus.h | 63 - include/sound/opl3.h | 61 +- include/sound/seq_instr.h | 110 -- include/sound/trident.h | 22 - sound/aoa/codecs/snd-aoa-codec-onyx.c | 12 + sound/aoa/codecs/snd-aoa-codec-tas.c | 21 +- sound/aoa/fabrics/snd-aoa-fabric-layout.c | 2 +- sound/core/init.c | 36 + sound/core/seq/Makefile | 8 +- sound/core/seq/instr/Makefile | 23 - sound/core/seq/instr/ainstr_fm.c | 155 --- sound/core/seq/instr/ainstr_gf1.c | 359 ------ sound/core/seq/instr/ainstr_iw.c | 623 --------- sound/core/seq/instr/ainstr_simple.c | 215 ---- sound/core/seq/seq_clientmgr.c | 3 +- sound/core/seq/seq_instr.c | 655 ---------- sound/core/seq/seq_midi_emul.c | 7 - sound/drivers/Kconfig | 12 + sound/drivers/Makefile | 2 + sound/drivers/ml403-ac97cr.c | 1351 ++++++++++++++++++++ sound/drivers/mpu401/mpu401_uart.c | 12 +- sound/drivers/mts64.c | 12 +- sound/drivers/opl3/opl3_lib.c | 5 +- sound/drivers/opl3/opl3_midi.c | 41 +- sound/drivers/opl3/opl3_oss.c | 135 +-- sound/drivers/opl3/opl3_seq.c | 42 +- sound/drivers/opl3/opl3_synth.c | 180 +++- sound/drivers/pcm-indirect2.c | 575 +++++++++ sound/drivers/pcm-indirect2.h | 140 ++ sound/drivers/portman2x4.c | 2 +- sound/drivers/vx/vx_mixer.c | 67 +- sound/i2c/other/ak4xxx-adda.c | 45 +- sound/i2c/other/pt2258.c | 2 + sound/isa/ad1848/ad1848_lib.c | 2 +- sound/isa/gus/Makefile | 12 - sound/isa/gus/gus_main.c | 23 - sound/isa/gus/gus_sample.c | 165 --- sound/isa/gus/gus_simple.c | 634 --------- sound/isa/gus/gus_synth.c | 314 ----- sound/isa/opti9xx/miro.c | 8 + sound/pci/ac97/ac97_patch.c | 11 +- sound/pci/ac97/ac97_patch.h | 2 + sound/pci/ca0106/ca0106.h | 1 - sound/pci/ca0106/ca0106_mixer.c | 18 +- sound/pci/ca0106/ca0106_proc.c | 4 +- sound/pci/cmipci.c | 104 ++- sound/pci/cs46xx/cs46xx_lib.c | 99 -- sound/pci/hda/hda_codec.c | 66 +- sound/pci/hda/hda_codec.h | 1 + sound/pci/hda/hda_intel.c | 17 +- sound/pci/hda/hda_local.h | 1 + sound/pci/hda/hda_proc.c | 57 +- sound/pci/hda/patch_analog.c | 15 +- sound/pci/hda/patch_atihdmi.c | 2 +- sound/pci/hda/patch_conexant.c | 3 +- sound/pci/hda/patch_realtek.c | 177 +++ sound/pci/hda/patch_sigmatel.c | 343 ++++-- sound/pci/ice1712/Makefile | 2 +- sound/pci/ice1712/aureon.c | 33 +- sound/pci/ice1712/ice1712.h | 6 + sound/pci/ice1712/ice1724.c | 3 + sound/pci/ice1712/phase.c | 25 +- sound/pci/ice1712/prodigy192.c | 2 +- sound/pci/ice1712/se.c | 756 +++++++++++ sound/pci/ice1712/se.h | 15 + sound/pci/ice1712/wtm.c | 8 +- sound/pci/intel8x0.c | 1 - sound/pci/korg1212/korg1212.c | 37 +- sound/pci/maestro3.c | 1 - sound/pci/mixart/mixart_mixer.c | 124 ++- sound/pci/pcxhr/pcxhr_mixer.c | 71 +- sound/pci/rme96.c | 27 +- sound/pci/rme9652/hdsp.c | 4 +- sound/pci/trident/Makefile | 10 - sound/pci/trident/trident.c | 7 - sound/pci/trident/trident_main.c | 28 - sound/pci/trident/trident_synth.c | 1024 --------------- sound/pci/via82xx.c | 10 +- sound/pci/vx222/vx222_ops.c | 9 + sound/pci/ymfpci/ymfpci_main.c | 4 + sound/pcmcia/vx/vxp_mixer.c | 11 +- sound/ppc/awacs.c | 20 +- sound/ppc/beep.c | 7 +- sound/ppc/burgundy.c | 11 +- sound/ppc/daca.c | 17 +- sound/ppc/pmac.c | 2 +- sound/ppc/tumbler.c | 55 +- sound/sh/aica.c | 8 +- sound/soc/codecs/Kconfig | 3 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/cs4270.c | 3 +- sound/soc/codecs/tlv320aic3x.c | 1275 ++++++++++++++++++ sound/soc/codecs/tlv320aic3x.h | 181 +++ sound/soc/codecs/wm8750.c | 2 +- sound/soc/codecs/wm9712.c | 7 +- sound/soc/s3c24xx/Kconfig | 8 + sound/soc/s3c24xx/Makefile | 2 + sound/soc/s3c24xx/ln2440sbc_alc650.c | 86 ++ sound/soc/s3c24xx/s3c2443-ac97.c | 6 +- sound/soc/s3c24xx/s3c24xx-ac97.h | 6 + sound/soc/sh/hac.c | 13 +- sound/sparc/amd7930.c | 2 +- sound/sparc/dbri.c | 19 +- sound/spi/at73c213.c | 11 +- sound/usb/Kconfig | 10 +- sound/usb/usbmixer.c | 33 +- sound/usb/usbmixer_maps.c | 11 + 118 files changed, 6471 insertions(+), 6749 deletions(-) diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt index 4b48c2e..f5e77c7 100644 --- a/Documentation/sound/alsa/ALSA-Configuration.txt +++ b/Documentation/sound/alsa/ALSA-Configuration.txt @@ -57,7 +57,9 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed. - Default: 1 - For auto-loading more than one card, specify this option together with snd-card-X aliases. - + slots - Reserve the slot index for the given driver. + This option takes multiple strings. + See "Module Autoloading Support" section for details. Module snd-pcm-oss ------------------ @@ -823,11 +825,13 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed. fujitsu Fujitsu Laptop hp-bpc HP xw4400/6400/8400/9400 laptops hp-bpc-d7000 HP BPC D7000 + hp-tc-t5735 HP Thin Client T5735 benq Benq ED8 benq-t31 Benq T31 hippo Hippo (ATI) with jack detection, Sony UX-90s hippo_1 Hippo (Benq) with jack detection sony-assamd Sony ASSAMD + ultra Samsung Q1 Ultra Vista model basic fixed pin assignment w/o SPDIF auto auto-config reading BIOS (default) @@ -843,6 +847,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed. 3stack-6ch-dig 3-stack (6-channel) with SPDIF 6stack-dig 6-stack with SPDIF lenovo-101e Lenovo laptop + eeepc-p701 ASUS Eeepc auto auto-config reading BIOS (default) ALC882/885 @@ -1156,11 +1161,14 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed. * Chaintech 9CJS * Chaintech AV-710 * Shuttle SN25P + * Onkyo SE-90PCI + * Onkyo SE-200PCI model - Use the given board model, one of the following: revo51, revo71, amp2000, prodigy71, prodigy71lt, prodigy192, aureon51, aureon71, universe, ap192, - k8x800, phase22, phase28, ms300, av710 + k8x800, phase22, phase28, ms300, av710, se200pci, + se90pci This module supports multiple cards and autoprobe. @@ -2135,6 +2143,23 @@ alias sound-slot-1 snd-ens1371 In this example, the interwave card is always loaded as the first card (index 0) and ens1371 as the second (index 1). +Alternative (and new) way to fixate the slot assignment is to use +"slots" option of snd module. In the case above, specify like the +following: + +options snd slots=snd-interwave,snd-ens1371 + +Then, the first slot (#0) is reserved for snd-interwave driver, and +the second (#1) for snd-ens1371. You can omit index option in each +driver if slots option is used (although you can still have them at +the same time as long as they don't conflict). + +The slots option is especially useful for avoiding the possible +hot-plugging and the resultant slot conflict. For example, in the +case above again, the first two slots are already reserved. If any +other driver (e.g. snd-usb-audio) is loaded before snd-interwave or +snd-ens1371, it will be assigned to the third or later slot. + ALSA PCM devices to OSS devices mapping ======================================= diff --git a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl index 2c3fc3c..48e4053 100644 --- a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl +++ b/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl @@ -18,7 +18,7 @@ - September 10, 2007 + Oct 15, 2007 0.3.7 @@ -67,7 +67,7 @@ This document describes how to write an ALSA (Advanced Linux Sound Architecture) - driver. The document focuses mainly on the PCI soundcard. + driver. The document focuses mainly on PCI soundcards. In the case of other device types, the API might be different, too. However, at least the ALSA kernel API is consistent, and therefore it would be still a bit help for @@ -75,23 +75,23 @@ - The target of this document is ones who already have enough - skill of C language and have the basic knowledge of linux - kernel programming. This document doesn't explain the general - topics of linux kernel codes and doesn't cover the detail of - implementation of each low-level driver. It describes only how is + This document targets people who already have enough + C language skills and have basic linux kernel programming + knowledge. This document doesn't explain the general + topic of linux kernel coding and doesn't cover low-level + driver implementation details. It only describes the standard way to write a PCI sound driver on ALSA. - If you are already familiar with the older ALSA ver.0.5.x, you - can check the drivers such as es1938.c or - maestro3.c which have also almost the same + If you are already familiar with the older ALSA ver.0.5.x API, you + can check the drivers such as sound/pci/es1938.c or + sound/pci/maestro3.c which have also almost the same code-base in the ALSA 0.5.x tree, so you can compare the differences. - This document is still a draft version. Any feedbacks and + This document is still a draft version. Any feedback and corrections, please!! @@ -106,7 +106,7 @@
General - The ALSA drivers are provided in the two ways. + The ALSA drivers are provided in two ways. @@ -114,15 +114,14 @@ ALSA's ftp site, and another is the 2.6 (or later) Linux kernel tree. To synchronize both, the ALSA driver tree is split into two different trees: alsa-kernel and alsa-driver. The former - contains purely the source codes for the Linux 2.6 (or later) + contains purely the source code for the Linux 2.6 (or later) tree. This tree is designed only for compilation on 2.6 or later environment. The latter, alsa-driver, contains many subtle - files for compiling the ALSA driver on the outside of Linux - kernel like configure script, the wrapper functions for older, - 2.2 and 2.4 kernels, to adapt the latest kernel API, + files for compiling ALSA drivers outside of the Linux kernel tree, + wrapper functions for older 2.2 and 2.4 kernels, to adapt the latest kernel API, and additional drivers which are still in development or in tests. The drivers in alsa-driver tree will be moved to - alsa-kernel (eventually 2.6 kernel tree) once when they are + alsa-kernel (and eventually to the 2.6 kernel tree) when they are finished and confirmed to work fine. @@ -168,7 +167,7 @@
core directory - This directory contains the middle layer, that is, the heart + This directory contains the middle layer which is the heart of ALSA drivers. In this directory, the native ALSA modules are stored. The sub-directories contain different modules and are dependent upon the kernel config. @@ -181,7 +180,7 @@ The codes for PCM and mixer OSS emulation modules are stored in this directory. The rawmidi OSS emulation is included in the ALSA rawmidi code since it's quite small. The sequencer - code is stored in core/seq/oss directory (see + code is stored in core/seq/oss directory (see below). @@ -200,7 +199,7 @@
core/seq - This and its sub-directories are for the ALSA + This directory and its sub-directories are for the ALSA sequencer. This directory contains the sequencer core and primary sequencer modules such like snd-seq-midi, snd-seq-virmidi, etc. They are compiled only when @@ -229,22 +228,22 @@ include directory This is the place for the public header files of ALSA drivers, - which are to be exported to the user-space, or included by + which are to be exported to user-space, or included by several files at different directories. Basically, the private header files should not be placed in this directory, but you may - still find files there, due to historical reason :) + still find files there, due to historical reasons :)
drivers directory - This directory contains the codes shared among different drivers - on the different architectures. They are hence supposed not to be + This directory contains code shared among different drivers + on different architectures. They are hence supposed not to be architecture-specific. For example, the dummy pcm driver and the serial MIDI driver are found in this directory. In the sub-directories, - there are the codes for components which are independent from + there is code for components which are independent from bus and cpu architectures. @@ -271,7 +270,7 @@ Although there is a standard i2c layer on Linux, ALSA has its - own i2c codes for some cards, because the soundcard needs only a + own i2c code for some cards, because the soundcard needs only a simple operation and the standard i2c API is too complicated for such a purpose. @@ -292,28 +291,28 @@ So far, there is only Emu8000/Emu10k1 synth driver under - synth/emux sub-directory. + the synth/emux sub-directory.
pci directory - This and its sub-directories hold the top-level card modules - for PCI soundcards and the codes specific to the PCI BUS. + This directory and its sub-directories hold the top-level card modules + for PCI soundcards and the code specific to the PCI BUS. - The drivers compiled from a single file is stored directly on - pci directory, while the drivers with several source files are - stored on its own sub-directory (e.g. emu10k1, ice1712). + The drivers compiled from a single file are stored directly + in the pci directory, while the drivers with several source files are + stored on their own sub-directory (e.g. emu10k1, ice1712).
isa directory - This and its sub-directories hold the top-level card modules + This directory and its sub-directories hold the top-level card modules for ISA soundcards.
@@ -321,16 +320,16 @@
arm, ppc, and sparc directories - These are for the top-level card modules which are - specific to each given architecture. + They are used for top-level card modules which are + specific to one of these architectures.
usb directory - This contains the USB-audio driver. On the latest version, the - USB MIDI driver is integrated together with usb-audio driver. + This directory contains the USB-audio driver. In the latest version, the + USB MIDI driver is integrated in the usb-audio driver.
@@ -338,16 +337,17 @@ pcmcia directory The PCMCIA, especially PCCard drivers will go here. CardBus - drivers will be on pci directory, because its API is identical - with the standard PCI cards. + drivers will be in the pci directory, because their API is identical + to that of standard PCI cards.
oss directory - The OSS/Lite source files are stored here on Linux 2.6 (or - later) tree. (In the ALSA driver tarball, it's empty, of course :) + The OSS/Lite source files are stored here in Linux 2.6 (or + later) tree. In the ALSA driver tarball, this directory is empty, + of course :)
@@ -362,7 +362,7 @@
Outline - The minimum flow of PCI soundcard is like the following: + The minimum flow for PCI soundcards is as follows: define the PCI ID table (see the section @@ -370,9 +370,13 @@ ). create probe() callback. create remove() callback. - create pci_driver table which contains the three pointers above. - create init() function just calling pci_register_driver() to register the pci_driver table defined above. - create exit() function to call pci_unregister_driver() function. + create a pci_driver structure + containing the three pointers above. + create an init() function just calling + the pci_register_driver() to register the pci_driver table + defined above. + create an exit() function to call + the pci_unregister_driver() function.
@@ -382,12 +386,12 @@ The code example is shown below. Some parts are kept unimplemented at this moment but will be filled in the - succeeding sections. The numbers in comment lines of - snd_mychip_probe() function are the - markers. + next sections. The numbers in the comment lines of the + snd_mychip_probe() function + refer to details explained in the following section. - Basic Flow for PCI Drivers Example + Basic Flow for PCI Drivers - Example @@ -398,6 +402,7 @@ #include /* module parameters (see "Module Parameters") */ + /* SNDRV_CARDS: maximum number of cards supported by this module */ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; @@ -405,13 +410,13 @@ /* definition of the chip-specific record */ struct mychip { struct snd_card *card; - /* rest of implementation will be in the section - * "PCI Resource Managements" + /* the rest of the implementation will be in section + * "PCI Resource Management" */ }; /* chip-specific destructor - * (see "PCI Resource Managements") + * (see "PCI Resource Management") */ static int snd_mychip_free(struct mychip *chip) { @@ -442,7 +447,7 @@ *rchip = NULL; /* check PCI availability here - * (see "PCI Resource Managements") + * (see "PCI Resource Management") */ .... @@ -454,7 +459,7 @@ chip->card = card; /* rest of initialization here; will be implemented - * later, see "PCI Resource Managements" + * later, see "PCI Resource Management" */ .... @@ -521,7 +526,7 @@ return 0; } - /* destructor -- see "Destructor" sub-section */ + /* destructor -- see the "Destructor" sub-section */ static void __devexit snd_mychip_remove(struct pci_dev *pci) { snd_card_free(pci_get_drvdata(pci)); @@ -536,16 +541,16 @@
Constructor - The real constructor of PCI drivers is probe callback. The - probe callback and other component-constructors which are called - from probe callback should be defined with - __devinit prefix. You - cannot use __init prefix for them, + The real constructor of PCI drivers is the probe callback. + The probe callback and other component-constructors which are called + from the probe callback should be defined with + the __devinit prefix. You + cannot use the __init prefix for them, because any PCI device could be a hotplug device. - In the probe callback, the following scheme is often used. + In the probe callback, the following scheme is often used.
@@ -570,7 +575,7 @@ - At each time probe callback is called, check the + Each time the probe callback is called, check the availability of the device. If not available, simply increment the device index and returns. dev will be incremented also later ( - The detail will be explained in the section + The details will be explained in the section Management of Cards and Components. @@ -619,9 +624,9 @@ - The detail will be explained in the section PCI Resource - Managements. + Management.
@@ -640,7 +645,7 @@ The driver field holds the minimal ID string of the - chip. This is referred by alsa-lib's configurator, so keep it + chip. This is used by alsa-lib's configurator, so keep it simple but unique. Even the same driver can have different driver IDs to distinguish the functionality of each chip type. @@ -648,7 +653,7 @@ The shortname field is a string shown as more verbose - name. The longname field contains the information which is + name. The longname field contains the information shown in /proc/asound/cards.
@@ -703,7 +708,7 @@ In the above, the card record is stored. This pointer is - referred in the remove callback and power-management + used in the remove callback and power-management callbacks, too.
@@ -757,22 +762,22 @@ where the last one is necessary only when module options are - defined in the source file. If the codes are split to several - files, the file without module options don't need them. + defined in the source file. If the code is split into several + files, the files without module options don't need them. - In addition to them, you'll need - <linux/interrupt.h> for the interrupt - handling, and <asm/io.h> for the i/o - access. If you use mdelay() or + In addition to these headers, you'll need + <linux/interrupt.h> for interrupt + handling, and <asm/io.h> for I/O + access. If you use the mdelay() or udelay() functions, you'll need to include - <linux/delay.h>, too. + <linux/delay.h> too. - The ALSA interfaces like PCM or control API are defined in other - header files as <sound/xxx.h>. + The ALSA interfaces like the PCM and control APIs are defined in other + <sound/xxx.h> header files. They have to be included after <sound/core.h>. @@ -795,12 +800,12 @@ A card record is the headquarters of the soundcard. It manages - the list of whole devices (components) on the soundcard, such as + the whole list of devices (components) on the soundcard, such as PCM, mixers, MIDI, synthesizer, and so on. Also, the card record holds the ID and the name strings of the card, manages the root of proc files, and controls the power-management states and hotplug disconnections. The component list on the card - record is used to manage the proper releases of resources at + record is used to manage the correct release of resources at destruction. @@ -824,9 +829,8 @@ THIS_MODULE), and the size of extra-data space. The last argument is used to allocate card->private_data for the - chip-specific data. Note that this data - is allocated by - snd_card_new(). + chip-specific data. Note that these data + are allocated by snd_card_new(). @@ -834,10 +838,10 @@ Components After the card is created, you can attach the components - (devices) to the card instance. On ALSA driver, a component is + (devices) to the card instance. In an ALSA driver, a component is represented as a struct snd_device object. A component can be a PCM instance, a control interface, a raw - MIDI interface, etc. Each of such instances has one component + MIDI interface, etc. Each such instance has one component entry. @@ -859,7 +863,7 @@ (SNDRV_DEV_XXX), the data pointer, and the callback pointers (&ops). The device-level defines the type of components and the order of - registration and de-registration. For most of components, the + registration and de-registration. For most components, the device-level is already defined. For a user-defined component, you can use SNDRV_DEV_LOWLEVEL. @@ -867,13 +871,13 @@ This function itself doesn't allocate the data space. The data must be allocated manually beforehand, and its pointer is passed - as the argument. This pointer is used as the identifier - (chip in the above example) for the - instance. + as the argument. This pointer is used as the + (chip identifier in the above example) + for the instance. - Each ALSA pre-defined component such as ac97 or pcm calls + Each pre-defined ALSA component such as ac97 and pcm calls snd_device_new() inside its constructor. The destructor for each component is defined in the callback pointers. Hence, you don't need to take care of @@ -881,19 +885,19 @@ - If you would like to create your own component, you need to - set the destructor function to dev_free callback in - ops, so that it can be released - automatically via snd_card_free(). The - example will be shown later as an implementation of a - chip-specific data. + If you wish to create your own component, you need to + set the destructor function to the dev_free callback in + the ops, so that it can be released + automatically via snd_card_free(). + The next example will show an implementation of chip-specific + data.
Chip-Specific Data - The chip-specific information, e.g. the i/o port address, its + Chip-specific information, e.g. the I/O port address, its resource pointer, or the irq number, is stored in the chip-specific record. @@ -909,13 +913,14 @@ - In general, there are two ways to allocate the chip record. + In general, there are two ways of allocating the chip record.
1. Allocating via <function>snd_card_new()</function>. - As mentioned above, you can pass the extra-data-length to the 4th argument of snd_card_new(), i.e. + As mentioned above, you can pass the extra-data-length + to the 4th argument of snd_card_new(), i.e. @@ -925,7 +930,7 @@ - whether struct mychip is the type of the chip record. + struct mychip is the type of the chip record. @@ -1037,8 +1042,8 @@ Registration and Release After all components are assigned, register the card instance - by calling snd_card_register(). The access - to the device files are enabled at this point. That is, before + by calling snd_card_register(). Access + to the device files is enabled at this point. That is, before snd_card_register() is called, the components are safely inaccessible from external side. If this call fails, exit the probe function after releasing the card via @@ -1047,7 +1052,7 @@ For releasing the card instance, you can call simply - snd_card_free(). As already mentioned, all + snd_card_free(). As mentioned earlier, all components are released automatically by this call. @@ -1055,7 +1060,7 @@ As further notes, the destructors (both snd_mychip_dev_free and snd_mychip_free) cannot be defined with - __devexit prefix, because they may be + the __devexit prefix, because they may be called from the constructor, too, at the false path. @@ -1071,20 +1076,20 @@ - + - PCI Resource Managements + PCI Resource Management
Full Code Example - In this section, we'll finish the chip-specific constructor, - destructor and PCI entries. The example code is shown first, + In this section, we'll complete the chip-specific constructor, + destructor and PCI entries. Example code is shown first, below. - PCI Resource Managements Example + PCI Resource Management Example irq >= 0) free_irq(chip->irq, chip); - /* release the i/o ports & memory */ + /* release the I/O ports & memory */ pci_release_regions(chip->pci); /* disable the PCI entry */ pci_disable_device(chip->pci); @@ -1196,13 +1201,13 @@ .remove = __devexit_p(snd_mychip_remove), }; - /* initialization of the module */ + /* module initialization */ static int __init alsa_card_mychip_init(void) { return pci_register_driver(&driver); } - /* clean up the module */ + /* module clean up */ static void __exit alsa_card_mychip_exit(void) { pci_unregister_driver(&driver); @@ -1228,10 +1233,10 @@ - In the case of PCI devices, you have to call at first - pci_enable_device() function before + In the case of PCI devices, you first have to call + the pci_enable_device() function before allocating resources. Also, you need to set the proper PCI DMA - mask to limit the accessed i/o range. In some cases, you might + mask to limit the accessed I/O range. In some cases, you might need to call pci_set_master() function, too. @@ -1261,15 +1266,15 @@
Resource Allocation - The allocation of I/O ports and irqs are done via standard kernel + The allocation of I/O ports and irqs is done via standard kernel functions. Unlike ALSA ver.0.5.x., there are no helpers for that. And these resources must be released in the destructor function (see below). Also, on ALSA 0.9.x, you don't need to - allocate (pseudo-)DMA for PCI like ALSA 0.5.x. + allocate (pseudo-)DMA for PCI like in ALSA 0.5.x. - Now assume that this PCI device has an I/O port with 8 bytes + Now assume that the PCI device has an I/O port with 8 bytes and an interrupt. Then struct mychip will have the following fields: @@ -1288,7 +1293,7 @@ - For an i/o port (and also a memory region), you need to have + For an I/O port (and also a memory region), you need to have the resource pointer for the standard resource management. For an irq, you have to keep only the irq number (integer). But you need to initialize this number as -1 before actual allocation, @@ -1299,7 +1304,7 @@ - The allocation of an i/o port is done like this: + The allocation of an I/O port is done like this: @@ -1318,12 +1323,12 @@ - It will reserve the i/o port region of 8 bytes of the given + It will reserve the I/O port region of 8 bytes of the given PCI device. The returned value, chip->res_port, is allocated via kmalloc() by request_region(). The pointer must be - released via kfree(), but there is some - problem regarding this. This issue will be explained more below. + released via kfree(), but there is a + problem with this. This issue will be explained later. @@ -1351,8 +1356,8 @@ - On the PCI bus, the interrupts can be shared. Thus, - IRQF_SHARED is given as the interrupt flag of + On the PCI bus, interrupts can be shared. Thus, + IRQF_SHARED is used as the interrupt flag of request_irq(). @@ -1364,7 +1369,7 @@ - I won't define the detail of the interrupt handler at this + I won't give details about the interrupt handler at this point, but at least its appearance can be explained now. The interrupt handler looks usually like the following: @@ -1386,11 +1391,11 @@ Now let's write the corresponding destructor for the resources above. The role of destructor is simple: disable the hardware (if already activated) and release the resources. So far, we - have no hardware part, so the disabling is not written here. + have no hardware part, so the disabling code is not written here. - For releasing the resources, check-and-release + To release the resources, the check-and-release method is a safer way. For the interrupt, do like this: @@ -1410,7 +1415,7 @@ When you requested I/O ports or memory regions via pci_request_region() or - pci_request_regions() like this example, + pci_request_regions() like in this example, release the resource(s) using the corresponding function, pci_release_region() or pci_release_regions(). @@ -1429,7 +1434,7 @@ or request_mem_region, you can release it via release_resource(). Suppose that you keep the resource pointer returned from request_region() - in chip->res_port, the release procedure looks like below: + in chip->res_port, the release procedure looks like: @@ -1442,7 +1447,7 @@ Don't forget to call pci_disable_device() - before all finished. + before the end. @@ -1459,14 +1464,14 @@ Again, remember that you cannot - set __devexit prefix for this destructor. + use the __devexit prefix for this destructor. - We didn't implement the hardware-disabling part in the above. + We didn't implement the hardware disabling part in the above. If you need to do this, please note that the destructor may be called even before the initialization of the chip is completed. - It would be better to have a flag to skip the hardware-disabling + It would be better to have a flag to skip hardware disabling if the hardware was not initialized yet. @@ -1475,14 +1480,14 @@ snd_device_new() with SNDRV_DEV_LOWLELVEL , its destructor is called at the last. That is, it is assured that all other - components like PCMs and controls have been already released. - You don't have to call stopping PCMs, etc. explicitly, but just - stop the hardware in the low-level. + components like PCMs and controls have already been released. + You don't have to stop PCMs, etc. explicitly, but just + call low-level hardware stopping. The management of a memory-mapped region is almost as same as - the management of an i/o port. You'll need three fields like + the management of an I/O port. You'll need three fields like the following: @@ -1561,8 +1566,8 @@
PCI Entries - So far, so good. Let's finish the rest of missing PCI - stuffs. At first, we need a + So far, so good. Let's finish the missing PCI + stuff. At first, we need a pci_device_id table for this chipset. It's a table of PCI vendor/device ID number, and some masks. @@ -1588,13 +1593,13 @@ The first and second fields of - pci_device_id struct are the vendor and - device IDs. If you have nothing special to filter the matching - devices, you can use the rest of fields like above. The last - field of pci_device_id struct is a + the pci_device_id structure are the vendor and + device IDs. If you have no reason to filter the matching + devices, you can leave the remaining fields as above. The last + field of the pci_device_id struct contains private data for this entry. You can specify any value here, for - example, to tell the type of different operations per each - device IDs. Such an example is found in intel8x0 driver. + example, to define specific operations for supported device IDs. + Such an example is found in the intel8x0 driver. @@ -1621,10 +1626,10 @@ The probe and - remove functions are what we already - defined in - the previous sections. The remove should - be defined with + remove functions have already + been defined in the previous sections. + The remove function should + be defined with the __devexit_p() macro, so that it's not defined for built-in (and non-hot-pluggable) case. The name @@ -1665,8 +1670,7 @@ Oh, one thing was forgotten. If you have no exported symbols, - you need to declare it on 2.2 or 2.4 kernels (on 2.6 kernels - it's not necessary, though). + you need to declare it in 2.2 or 2.4 kernels (it's not necessary in 2.6 kernels). @@ -1698,7 +1702,7 @@ For accessing to the PCM layer, you need to include - <sound/pcm.h> above all. In addition, + <sound/pcm.h> first. In addition, <sound/pcm_params.h> might be needed if you access to some functions related with hw_param. @@ -1707,21 +1711,21 @@ Each card device can have up to four pcm instances. A pcm instance corresponds to a pcm device file. The limitation of number of instances comes only from the available bit size of - the linux's device number. Once when 64bit device number is - used, we'll have more available pcm instances. + the Linux's device numbers. Once when 64bit device number is + used, we'll have more pcm instances available. A pcm instance consists of pcm playback and capture streams, and each pcm stream consists of one or more pcm substreams. Some - soundcard supports the multiple-playback function. For example, + soundcards support multiple playback functions. For example, emu10k1 has a PCM playback of 32 stereo substreams. In this case, at each open, a free substream is (usually) automatically chosen and opened. Meanwhile, when only one substream exists and it was - already opened, the succeeding open will result in the blocking - or the error with EAGAIN according to the - file open mode. But you don't have to know the detail in your - driver. The PCM middle layer will take all such jobs. + already opened, the successful open will either block + or error with EAGAIN according to the + file open mode. But you don't have to care about such details in your + driver. The PCM middle layer will take care of such work.
@@ -1944,7 +1948,7 @@
Constructor - A pcm instance is allocated by snd_pcm_new() + A pcm instance is allocated by the snd_pcm_new() function. It would be better to create a constructor for pcm, namely, @@ -1971,23 +1975,23 @@ - The snd_pcm_new() function takes the four + The snd_pcm_new() function takes four arguments. The first argument is the card pointer to which this pcm is assigned, and the second is the ID string. The third argument (index, 0 in the - above) is the index of this new pcm. It begins from zero. When - you will create more than one pcm instances, specify the + above) is the index of this new pcm. It begins from zero. If + you create more than one pcm instances, specify the different numbers in this argument. For example, index = 1 for the second PCM device. The fourth and fifth arguments are the number of substreams - for playback and capture, respectively. Here both 1 are given in - the above example. When no playback or no capture is available, + for playback and capture, respectively. Here 1 is used for + both arguments. When no playback or capture substreams are available, pass 0 to the corresponding argument. @@ -2045,13 +2049,13 @@ - Each of callbacks is explained in the subsection + All the callbacks are described in the - Operators. + Operators subsection. - After setting the operators, most likely you'd like to + After setting the operators, you probably will want to pre-allocate the buffer. For the pre-allocation, simply call the following: @@ -2065,8 +2069,8 @@ - It will allocate up to 64kB buffer as default. The details of - buffer management will be described in the later section Buffer and Memory Management. @@ -2095,13 +2099,13 @@ The destructor for a pcm instance is not always necessary. Since the pcm device will be released by the middle - layer code automatically, you don't have to call destructor + layer code automatically, you don't have to call the destructor explicitly. - The destructor would be necessary when you created some - special records internally and need to release them. In such a + The destructor would be necessary if you created + special records internally and needed to release them. In such a case, set the destructor function to pcm->private_free: @@ -2141,16 +2145,15 @@ When the PCM substream is opened, a PCM runtime instance is allocated and assigned to the substream. This pointer is accessible via substream->runtime. - This runtime pointer holds the various information; it holds - the copy of hw_params and sw_params configurations, the buffer - pointers, mmap records, spinlocks, etc. Almost everything you - need for controlling the PCM can be found there. + This runtime pointer holds most information you need + to control the PCM: the copy of hw_params and sw_params configurations, the buffer + pointers, mmap records, spinlocks, etc. The definition of runtime instance is found in - <sound/pcm.h>. Here is the - copy from the file. + <sound/pcm.h>. Here are + the contents of this file: For the operators (callbacks) of each sound driver, most of these records are supposed to be read-only. Only the PCM - middle-layer changes / updates these info. The exceptions are + middle-layer changes / updates them. The exceptions are the hardware description (hw), interrupt callbacks (transfer_ack_xxx), DMA buffer information, and the private data. Besides, if you use the standard buffer allocation @@ -2285,7 +2288,7 @@ struct _snd_pcm_runtime { - Typically, you'll have a hardware descriptor like below: + Typically, you'll have a hardware descriptor as below: SNDRV_PCM_INFO_XXX. Here, at least, you have to specify whether the mmap is supported and which interleaved format is supported. - When the mmap is supported, add + When the is supported, add the SNDRV_PCM_INFO_MMAP flag here. When the hardware supports the interleaved or the non-interleaved - format, SNDRV_PCM_INFO_INTERLEAVED or + formats, SNDRV_PCM_INFO_INTERLEAVED or SNDRV_PCM_INFO_NONINTERLEAVED flag must be set, respectively. If both are supported, you can set both, too. @@ -2331,7 +2334,7 @@ struct _snd_pcm_runtime { In the above example, MMAP_VALID and - BLOCK_TRANSFER are specified for OSS mmap + BLOCK_TRANSFER are specified for the OSS mmap mode. Usually both are set. Of course, MMAP_VALID is set only if the mmap is really supported. @@ -2345,11 +2348,11 @@ struct _snd_pcm_runtime { pause operation, while the RESUME bit means that the pcm supports the full suspend/resume operation. - If PAUSE flag is set, + If the PAUSE flag is set, the trigger callback below must handle the corresponding (pause push/release) commands. The suspend/resume trigger commands can be defined even without - RESUME flag. See RESUME flag. See Power Management section for details. @@ -2382,7 +2385,7 @@ struct _snd_pcm_runtime { CONTINUOUS bit additionally. The pre-defined rate bits are provided only for typical rates. If your chip supports unconventional rates, you need to add - KNOT bit and set up the hardware + the KNOT bit and set up the hardware constraint manually (explained later). @@ -2390,8 +2393,8 @@ struct _snd_pcm_runtime { rate_min and - rate_max define the minimal and - maximal sample rate. This should correspond somehow to + rate_max define the minimum and + maximum sample rate. This should correspond somehow to rates bits. @@ -2400,7 +2403,7 @@ struct _snd_pcm_runtime { channel_min and channel_max - define, as you might already expected, the minimal and maximal + define, as you might already expected, the minimum and maximum number of channels. @@ -2408,21 +2411,21 @@ struct _snd_pcm_runtime { buffer_bytes_max defines the - maximal buffer size in bytes. There is no + maximum buffer size in bytes. There is no buffer_bytes_min field, since - it can be calculated from the minimal period size and the - minimal number of periods. + it can be calculated from the minimum period size and the + minimum number of periods. Meanwhile, period_bytes_min and - define the minimal and maximal size of the period in bytes. + define the minimum and maximum size of the period in bytes. periods_max and - periods_min define the maximal and - minimal number of periods in the buffer. + periods_min define the maximum and + minimum number of periods in the buffer. - The period is a term, that corresponds to - fragment in the OSS world. The period defines the size at - which the PCM interrupt is generated. This size strongly + The period is a term that corresponds to + a fragment in the OSS world. The period defines the size at + which a PCM interrupt is generated. This size strongly depends on the hardware. Generally, the smaller period size will give you more interrupts, that is, more controls. @@ -2435,8 +2438,8 @@ struct _snd_pcm_runtime { There is also a field fifo_size. - This specifies the size of the hardware FIFO, but it's not - used currently in the driver nor in the alsa-lib. So, you + This specifies the size of the hardware FIFO, but currently it + is neither used in the driver nor in the alsa-lib. So, you can ignore this field. @@ -2450,7 +2453,7 @@ struct _snd_pcm_runtime { Ok, let's go back again to the PCM runtime records. The most frequently referred records in the runtime instance are the PCM configurations. - The PCM configurations are stored on runtime instance + The PCM configurations are stored in the runtime instance after the application sends hw_params data via alsa-lib. There are many fields copied from hw_params and sw_params structs. For example, @@ -2461,11 +2464,11 @@ struct _snd_pcm_runtime { One thing to be noted is that the configured buffer and period - sizes are stored in frames in the runtime + sizes are stored in frames in the runtime. In the ALSA world, 1 frame = channels * samples-size. For conversion between frames and bytes, you can use the - helper functions, frames_to_bytes() and - bytes_to_frames(). + frames_to_bytes() and + bytes_to_frames() helper functions. dma_area is necessary when the buffer is mmapped. If your driver doesn't support mmap, this field is not necessary. dma_addr - is also not mandatory. You can use + is also optional. You can use dma_private as you like, too.
@@ -2524,14 +2527,14 @@ struct _snd_pcm_runtime { Running Status The running status can be referred via runtime->status. - This is the pointer to struct snd_pcm_mmap_status + This is the pointer to the struct snd_pcm_mmap_status record. For example, you can get the current DMA hardware pointer via runtime->status->hw_ptr. The DMA application pointer can be referred via - runtime->control, which points + runtime->control, which points to the struct snd_pcm_mmap_control record. However, accessing directly to this value is not recommended. @@ -2542,14 +2545,14 @@ struct _snd_pcm_runtime { You can allocate a record for the substream and store it in runtime->private_data. Usually, this - done in + is done in the open callback. Don't mix this with pcm->private_data. - The pcm->private_data usually points the + The pcm->private_data usually points to the chip instance assigned statically at the creation of PCM, while the - runtime->private_data points a dynamic - data created at the PCM open callback. + runtime->private_data points to a dynamic + data structure created at the PCM open callback. @@ -2579,7 +2582,7 @@ struct _snd_pcm_runtime { The field transfer_ack_begin and transfer_ack_end are called at - the beginning and the end of + the beginning and at the end of snd_pcm_period_elapsed(), respectively.
@@ -2589,17 +2592,18 @@ struct _snd_pcm_runtime {
Operators - OK, now let me explain the detail of each pcm callback + OK, now let me give details about each pcm callback (ops). In general, every callback must - return 0 if successful, or a negative number with the error - number such as -EINVAL at any - error. + return 0 if successful, or a negative error number + such as -EINVAL. To choose an appropriate + error number, it is advised to check what value other parts of + the kernel return when the same kind of request fails. The callback function takes at least the argument with - snd_pcm_substream pointer. For retrieving the - chip record from the given substream instance, you can use the + snd_pcm_substream pointer. To retrieve + the chip record from the given substream instance, you can use the following macro. @@ -2616,7 +2620,7 @@ struct _snd_pcm_runtime { The macro reads substream->private_data, which is a copy of pcm->private_data. You can override the former if you need to assign different data - records per PCM substream. For example, cmi8330 driver assigns + records per PCM substream. For example, the cmi8330 driver assigns different private_data for playback and capture directions, because it uses two different codecs (SB- and AD-compatible) for different directions. @@ -2709,7 +2713,7 @@ struct _snd_pcm_runtime {
ioctl callback - This is used for any special action to pcm ioctls. But + This is used for any special call to pcm ioctls. But usually you can pass a generic ioctl callback, snd_pcm_lib_ioctl. @@ -2726,9 +2730,6 @@ struct _snd_pcm_runtime { ]]> - - This and hw_free callbacks exist - only on ALSA 0.9.x. @@ -2740,13 +2741,13 @@ struct _snd_pcm_runtime { - Many hardware set-up should be done in this callback, + Many hardware setups should be done in this callback, including the allocation of buffers. Parameters to be initialized are retrieved by - params_xxx() macros. For allocating a + params_xxx() macros. To allocate buffer, you can call a helper function, @@ -2772,8 +2773,8 @@ struct _snd_pcm_runtime { - Thus, you need to take care not to allocate the same buffers - many times, which will lead to memory leak! Calling the + Thus, you need to be careful not to allocate the same buffers + many times, which will lead to memory leaks! Calling the helper function above many times is OK. It will release the previous buffer automatically when it was already allocated. @@ -2782,7 +2783,7 @@ struct _snd_pcm_runtime { Another note is that this callback is non-atomic (schedulable). This is important, because the trigger callback - is atomic (non-schedulable). That is, mutex or any + is atomic (non-schedulable). That is, mutexes or any schedule-related functions are not available in trigger callback. Please see the subsection @@ -2843,15 +2844,15 @@ struct _snd_pcm_runtime { prepared. You can set the format type, sample rate, etc. here. The difference from hw_params is that the - prepare callback will be called at each + prepare callback will be called each time snd_pcm_prepare() is called, i.e. when - recovered after underruns, etc. + recovering after underruns, etc. - Note that this callback became non-atomic since the recent version. - You can use schedule-related functions safely in this callback now. + Note that this callback is now non-atomic. + You can use schedule-related functions safely in this callback. @@ -2871,7 +2872,7 @@ struct _snd_pcm_runtime { Be careful that this callback will be called many times at - each set up, too. + each setup, too.
@@ -2893,7 +2894,7 @@ struct _snd_pcm_runtime { Which action is specified in the second argument, SNDRV_PCM_TRIGGER_XXX in <sound/pcm.h>. At least, - START and STOP + the START and STOP commands must be defined in this callback. @@ -2915,8 +2916,8 @@ struct _snd_pcm_runtime {
- When the pcm supports the pause operation (given in info - field of the hardware table), PAUSE_PUSE + When the pcm supports the pause operation (given in the info + field of the hardware table), the PAUSE_PUSE and PAUSE_RELEASE commands must be handled here, too. The former is the command to pause the pcm, and the latter to restart the pcm again. @@ -2925,21 +2926,21 @@ struct _snd_pcm_runtime { When the pcm supports the suspend/resume operation, regardless of full or partial suspend/resume support, - SUSPEND and RESUME + the SUSPEND and RESUME commands must be handled, too. These commands are issued when the power-management status is changed. Obviously, the SUSPEND and - RESUME - do suspend and resume of the pcm substream, and usually, they - are identical with STOP and + RESUME commands + suspend and resume the pcm substream, and usually, they + are identical to the STOP and START commands, respectively. - See + See the Power Management section for details. As mentioned, this callback is atomic. You cannot call - the function going to sleep. + functions which may sleep. The trigger callback should be as minimal as possible, just really triggering the DMA. The other stuff should be initialized hw_params and prepare callbacks properly @@ -2960,8 +2961,8 @@ struct _snd_pcm_runtime { This callback is called when the PCM middle layer inquires the current hardware position on the buffer. The position must - be returned in frames (which was in bytes on ALSA 0.5.x), - ranged from 0 to buffer_size - 1. + be returned in frames, + ranging from 0 to buffer_size - 1. @@ -2983,7 +2984,7 @@ struct _snd_pcm_runtime { These callbacks are not mandatory, and can be omitted in most cases. These callbacks are used when the hardware buffer - cannot be on the normal memory space. Some chips have their + cannot be in the normal memory space. Some chips have their own buffer on the hardware which is not mappable. In such a case, you have to transfer the data manually from the memory buffer to the hardware buffer. Or, if the buffer is @@ -3018,8 +3019,8 @@ struct _snd_pcm_runtime { page callback - This callback is also not mandatory. This callback is used - mainly for the non-contiguous buffer. The mmap calls this + This callback is optional too. This callback is used + mainly for non-contiguous buffers. The mmap calls this callback to get the page address. Some examples will be explained in the later section Buffer and Memory @@ -3035,7 +3036,7 @@ struct _snd_pcm_runtime { role of PCM interrupt handler in the sound driver is to update the buffer position and to tell the PCM middle layer when the buffer position goes across the prescribed period size. To - inform this, call snd_pcm_period_elapsed() + inform this, call the snd_pcm_period_elapsed() function. @@ -3072,7 +3073,7 @@ struct _snd_pcm_runtime { - A typical coding would be like: + Typical code would be like: Interrupt Handler Case #1 @@ -3101,21 +3102,21 @@ struct _snd_pcm_runtime {
- High-frequent timer interrupts + High frequency timer interrupts - This is the case when the hardware doesn't generate interrupts - at the period boundary but do timer-interrupts at the fixed + This happense when the hardware doesn't generate interrupts + at the period boundary but issues timer interrupts at a fixed timer rate (e.g. es1968 or ymfpci drivers). In this case, you need to check the current hardware - position and accumulates the processed sample length at each - interrupt. When the accumulated size overcomes the period + position and accumulate the processed sample length at each + interrupt. When the accumulated size exceeds the period size, call snd_pcm_period_elapsed() and reset the accumulator. - A typical coding would be like the following. + Typical code would be like the following. Interrupt Handler Case #2 @@ -3178,32 +3179,33 @@ struct _snd_pcm_runtime {
Atomicity - One of the most important (and thus difficult to debug) problem - on the kernel programming is the race condition. - On linux kernel, usually it's solved via spin-locks or - semaphores. In general, if the race condition may - happen in the interrupt handler, it's handled as atomic, and you - have to use spinlock for protecting the critical session. If it - never happens in the interrupt and it may take relatively long - time, you should use semaphore. + One of the most important (and thus difficult to debug) problems + in kernel programming are race conditions. + In the Linux kernel, they are usually avoided via spin-locks, mutexes + or semaphores. In general, if a race condition can happen + in an interrupt handler, it has to be managed atomically, and you + have to use a spinlock to protect the critical session. If the + critical section is not in interrupt handler code and + if taking a relatively long time to execute is acceptable, you + should use mutexes or semaphores instead. As already seen, some pcm callbacks are atomic and some are - not. For example, hw_params callback is + not. For example, the hw_params callback is non-atomic, while trigger callback is atomic. This means, the latter is called already in a spinlock held by the PCM middle layer. Please take this atomicity into - account when you use a spinlock or a semaphore in the callbacks. + account when you choose a locking scheme in the callbacks. In the atomic callbacks, you cannot use functions which may call schedule or go to - sleep. The semaphore and mutex do sleep, + sleep. Semaphores and mutexes can sleep, and hence they cannot be used inside the atomic callbacks (e.g. trigger callback). - For taking a certain delay in such a callback, please use + To implement some delay in such a callback, please use udelay() or mdelay(). @@ -3257,7 +3259,7 @@ struct _snd_pcm_runtime { There are many different constraints. - Look in sound/pcm.h for a complete list. + Look at sound/pcm.h for a complete list. You can even define your own constraint rules. For example, let's suppose my_chip can manage a substream of 1 channel if and only if the format is S16_LE, otherwise it supports any format @@ -3346,7 +3348,7 @@ struct _snd_pcm_runtime { - I won't explain more details here, rather I + I won't give more details here, rather I would like to say, Luke, use the source.
@@ -3364,10 +3366,9 @@ struct _snd_pcm_runtime { General The control interface is used widely for many switches, - sliders, etc. which are accessed from the user-space. Its most - important use is the mixer interface. In other words, on ALSA - 0.9.x, all the mixer stuff is implemented on the control kernel - API (while there was an independent mixer kernel API on 0.5.x). + sliders, etc. which are accessed from user-space. Its most + important use is the mixer interface. In other words, since ALSA + 0.9.x, all the mixer stuff is implemented on the control kernel API. @@ -3379,14 +3380,15 @@ struct _snd_pcm_runtime { The control API is defined in <sound/control.h>. - Include this file if you add your own controls. + Include this file if you want to add your own controls.
Definition of Controls - For creating a new control, you need to define the three + To create a new control, you need to define the + following three callbacks: info, get and put. Then, define a @@ -3414,13 +3416,13 @@ struct _snd_pcm_runtime { Most likely the control is created via snd_ctl_new1(), and in such a case, you can - add __devinitdata prefix to the - definition like above. + add the __devinitdata prefix to the + definition as above. - The iface field specifies the type of - the control, SNDRV_CTL_ELEM_IFACE_XXX, which + The iface field specifies the control + type, SNDRV_CTL_ELEM_IFACE_XXX, which is usually MIXER. Use CARD for global controls that are not logically part of the mixer. @@ -3435,12 +3437,11 @@ struct _snd_pcm_runtime { The name is the name identifier - string. On ALSA 0.9.x, the control name is very important, + string. Since ALSA 0.9.x, the control name is very important, because its role is classified from its name. There are pre-defined standard control names. The details are described in - the subsection - - Control Names. + the + Control Names subsection. @@ -3456,15 +3457,15 @@ struct _snd_pcm_runtime { The access field contains the access type of this control. Give the combination of bit masks, SNDRV_CTL_ELEM_ACCESS_XXX, there. - The detailed will be explained in the subsection - - Access Flags. + The details will be explained in + the + Access Flags subsection. The private_value field contains an arbitrary long integer value for this record. When using - generic info, + the generic info, get and put callbacks, you can pass a value through this field. If several small numbers are necessary, you can @@ -3489,7 +3490,7 @@ struct _snd_pcm_runtime {
Control Names - There are some standards for defining the control names. A + There are some standards to define the control names. A control is usually defined from the three parts as SOURCE DIRECTION FUNCTION. @@ -3497,7 +3498,7 @@ struct _snd_pcm_runtime { The first, SOURCE, specifies the source of the control, and is a string such as Master, - PCM, CD or + PCM, CD and Line. There are many pre-defined sources. @@ -3575,22 +3576,22 @@ struct _snd_pcm_runtime { Access Flags - The access flag is the bit-flags which specifies the access type + The access flag is the bitmask which specifies the access type of the given control. The default access type is SNDRV_CTL_ELEM_ACCESS_READWRITE, which means both read and write are allowed to this control. When the access flag is omitted (i.e. = 0), it is - regarded as READWRITE access as default. + considered as READWRITE access as default. When the control is read-only, pass SNDRV_CTL_ELEM_ACCESS_READ instead. In this case, you don't have to define - put callback. + the put callback. Similarly, when the control is write-only (although it's a rare - case), you can use WRITE flag instead, and - you don't need get callback. + case), you can use the WRITE flag instead, and + you don't need the get callback. @@ -3598,15 +3599,15 @@ struct _snd_pcm_runtime { VOLATILE flag should be given. This means that the control may be changed without - notification. Applications should poll such + notification. Applications should poll such a control constantly. When the control is inactive, set - INACTIVE flag, too. + the INACTIVE flag, too. There are LOCK and - OWNER flags for changing the write + OWNER flags to change the write permissions. @@ -3619,10 +3620,10 @@ struct _snd_pcm_runtime { info callback The info callback is used to get - the detailed information of this control. This must store the + detailed information on this control. This must store the values of the given struct snd_ctl_elem_info object. For example, for a boolean control with a single - element will be: + element: Example of info callback @@ -3653,7 +3654,7 @@ struct _snd_pcm_runtime { volume would have count = 2. The value field is a union, and the values stored are depending on the type. The boolean and - integer are identical. + integer types are identical. @@ -3684,7 +3685,7 @@ struct _snd_pcm_runtime { - Some common info callbacks are prepared for easy use: + Some common info callbacks are available for your convenience: snd_ctl_boolean_mono_info() and snd_ctl_boolean_stereo_info(). Obviously, the former is an info callback for a mono channel @@ -3699,7 +3700,7 @@ struct _snd_pcm_runtime { This callback is used to read the current value of the - control and to return to the user-space. + control and to return to user-space. @@ -3722,11 +3723,11 @@ struct _snd_pcm_runtime { - The value field is depending on - the type of control as well as on info callback. For example, + The value field depends on + the type of control as well as on the info callback. For example, the sb driver uses this field to store the register offset, the bit-shift and the bit-mask. The - private_value is set like + private_value field is set as follows: - In get callback, you have to fill all the elements if the + In the get callback, + you have to fill all the elements if the control has more than one elements, i.e. count > 1. In the example above, we filled only one element @@ -3765,7 +3767,7 @@ struct _snd_pcm_runtime { put callback - This callback is used to write a value from the user-space. + This callback is used to write a value from user-space. @@ -3799,7 +3801,7 @@ struct _snd_pcm_runtime { - Like get callback, + As in the get callback, when the control has more than one elements, all elements must be evaluated in this callback, too. @@ -3817,7 +3819,7 @@ struct _snd_pcm_runtime { Constructor When everything is ready, finally we can create a new - control. For creating a control, there are two functions to be + control. To create a control, there are two functions to be called, snd_ctl_new1() and snd_ctl_add(). @@ -3839,14 +3841,14 @@ struct _snd_pcm_runtime { struct snd_kcontrol_new object defined above, and chip is the object pointer to be passed to kcontrol->private_data - which can be referred in callbacks. + which can be referred to in callbacks. snd_ctl_new1() allocates a new snd_kcontrol instance (that's why the definition of my_control can be with - __devinitdata + the __devinitdata prefix), and snd_ctl_add assigns the given control component to the card. @@ -3941,7 +3943,7 @@ struct _snd_pcm_runtime { General The ALSA AC97 codec layer is a well-defined one, and you don't - have to write many codes to control it. Only low-level control + have to write much code to control it. Only low-level control routines are necessary. The AC97 codec API is defined in <sound/ac97_codec.h>. @@ -4004,7 +4006,7 @@ struct _snd_pcm_runtime {
Constructor - For creating an ac97 instance, first call snd_ac97_bus + To create an ac97 instance, first call snd_ac97_bus with an ac97_bus_ops_t record with callback functions. @@ -4042,12 +4044,12 @@ struct _snd_pcm_runtime { - where chip->ac97 is the pointer of a newly created + where chip->ac97 is a pointer to a newly created ac97_t instance. In this case, the chip pointer is set as the private data, so that the read/write callback functions can refer to this chip instance. This instance is not necessarily stored in the chip - record. When you need to change the register values from the + record. If you need to change the register values from the driver, or need the suspend/resume of ac97 codecs, keep this pointer to pass to the corresponding functions. @@ -4098,7 +4100,7 @@ struct _snd_pcm_runtime { - These callbacks are non-atomic like the callbacks of control API. + These callbacks are non-atomic like the control API callbacks. @@ -4110,14 +4112,14 @@ struct _snd_pcm_runtime { The reset callback is used to reset - the codec. If the chip requires a special way of reset, you can + the codec. If the chip requires a special kind of reset, you can define this callback. - The wait callback is used for a - certain wait at the standard initialization of the codec. If the - chip requires the extra wait-time, define this callback. + The wait callback is used to + add some waiting time in the standard initialization of the codec. If the + chip requires the extra waiting time, define this callback. @@ -4172,7 +4174,7 @@ struct _snd_pcm_runtime { snd_ac97_update_bits() is used to update - some bits of the given register. + some bits in the given register. @@ -4185,7 +4187,7 @@ struct _snd_pcm_runtime { Also, there is a function to change the sample rate (of a - certain register such as + given register such as AC97_PCM_FRONT_DAC_RATE) when VRA or DRA is supported by the codec: snd_ac97_set_rate(). @@ -4200,11 +4202,11 @@ struct _snd_pcm_runtime { - The following registers are available for setting the rate: + The following registers are available to set the rate: AC97_PCM_MIC_ADC_RATE, AC97_PCM_FRONT_DAC_RATE, AC97_PCM_LR_ADC_RATE, - AC97_SPDIF. When the + AC97_SPDIF. When AC97_SPDIF is specified, the register is not really changed but the corresponding IEC958 status bits will be updated. @@ -4214,12 +4216,11 @@ struct _snd_pcm_runtime {
Clock Adjustment - On some chip, the clock of the codec isn't 48000 but using a + In some chips, the clock of the codec isn't 48000 but using a PCI clock (to save a quartz!). In this case, change the field bus->clock to the corresponding value. For example, intel8x0 - and es1968 drivers have the auto-measurement function of the - clock. + and es1968 drivers have their own function to read from the clock.
@@ -4239,15 +4240,13 @@ struct _snd_pcm_runtime { When there are several codecs on the same card, you need to call snd_ac97_mixer() multiple times with ac97.num=1 or greater. The num field - specifies the codec - number. + specifies the codec number.
- If you have set up multiple codecs, you need to either write + If you set up multiple codecs, you either need to write different callbacks for each codec or check - ac97->num in the - callback routines. + ac97->num in the callback routines.
@@ -4271,7 +4270,7 @@ struct _snd_pcm_runtime {
- Some soundchips have similar but a little bit different + Some soundchips have a similar but slightly different implementation of mpu401 stuff. For example, emu10k1 has its own mpu401 routines. @@ -4280,7 +4279,7 @@ struct _snd_pcm_runtime {
Constructor - For creating a rawmidi object, call + To create a rawmidi object, call snd_mpu401_uart_new(). @@ -4307,25 +4306,24 @@ struct _snd_pcm_runtime { - The 4th argument is the i/o port address. Many - backward-compatible MPU401 has an i/o port such as 0x330. Or, it - might be a part of its own PCI i/o region. It depends on the + The 4th argument is the I/O port address. Many + backward-compatible MPU401 have an I/O port such as 0x330. Or, it + might be a part of its own PCI I/O region. It depends on the chip design. - The 5th argument is bitflags for additional information. - When the i/o port address above is a part of the PCI i/o - region, the MPU401 i/o port might have been already allocated + The 5th argument is a bitflag for additional information. + When the I/O port address above is part of the PCI I/O + region, the MPU401 I/O port might have been already allocated (reserved) by the driver itself. In such a case, pass a bit flag MPU401_INFO_INTEGRATED, - and - the mpu401-uart layer will allocate the i/o ports by itself. + and the mpu401-uart layer will allocate the I/O ports by itself. When the controller supports only the input or output MIDI stream, - pass MPU401_INFO_INPUT or + pass the MPU401_INFO_INPUT or MPU401_INFO_OUTPUT bitflag, respectively. Then the rawmidi instance is created as a single stream. @@ -4333,7 +4331,7 @@ struct _snd_pcm_runtime { MPU401_INFO_MMIO bitflag is used to change the access method to MMIO (via readb and writeb) instead of - iob and outb. In this case, you have to pass the iomapped address + iob and outb. In this case, you have to pass the iomapped address to snd_mpu401_uart_new(). @@ -4341,7 +4339,7 @@ struct _snd_pcm_runtime { When MPU401_INFO_TX_IRQ is set, the output stream isn't checked in the default interrupt handler. The driver needs to call snd_mpu401_uart_interrupt_tx() - by itself to start processing the output stream in irq handler. + by itself to start processing the output stream in the irq handler. @@ -4381,7 +4379,7 @@ struct _snd_pcm_runtime { (irq_flags). Otherwise, pass the flags for irq allocation (SA_XXX bits) to it, and the irq will be - reserved by the mpu401-uart layer. If the card doesn't generates + reserved by the mpu401-uart layer. If the card doesn't generate UART interrupts, pass -1 as the irq number. Then a timer interrupt will be invoked for polling. @@ -4392,8 +4390,8 @@ struct _snd_pcm_runtime { When the interrupt is allocated in snd_mpu401_uart_new(), the private - interrupt handler is used, hence you don't have to do nothing - else than creating the mpu401 stuff. Otherwise, you have to call + interrupt handler is used, hence you don't have anything else to do + than creating the mpu401 stuff. Otherwise, you have to call snd_mpu401_uart_interrupt() explicitly when a UART interrupt is invoked and checked in your own interrupt handler. @@ -4480,8 +4478,8 @@ struct _snd_pcm_runtime { The fourth and fifth arguments are the number of output and - input substreams, respectively, of this device. (A substream is - the equivalent of a MIDI port.) + input substreams, respectively, of this device (a substream is + the equivalent of a MIDI port). @@ -4498,7 +4496,7 @@ struct _snd_pcm_runtime { After the rawmidi device is created, you need to set the operators (callbacks) for each substream. There are helper - functions to set the operators for all substream of a device: + functions to set the operators for all the substreams of a device: - If there is more than one substream, you should give each one a - unique name: + If there are more than one substream, you should give a + unique name to each of them: Callbacks - In all callbacks, the private data that you've set for the + In all the callbacks, the private data that you've set for the rawmidi device can be accessed as substream->rmidi->private_data. @@ -4583,8 +4581,8 @@ struct _snd_pcm_runtime { This is called when a substream is opened. - You can initialize the hardware here, but you should not yet - start transmitting/receiving data. + You can initialize the hardware here, but you shouldn't + start transmitting/receiving data yet.
@@ -4632,9 +4630,9 @@ struct _snd_pcm_runtime { To read data from the buffer, call snd_rawmidi_transmit_peek. It will return the number of bytes that have been read; this will be - less than the number of bytes requested when there is no more + less than the number of bytes requested when there are no more data in the buffer. - After the data has been transmitted successfully, call + After the data have been transmitted successfully, call snd_rawmidi_transmit_ack to remove the data from the substream buffer: @@ -4655,7 +4653,7 @@ struct _snd_pcm_runtime { If you know beforehand that the hardware will accept data, you can use the snd_rawmidi_transmit function - which reads some data and removes it from the buffer at once: + which reads some data and removes them from the buffer at once: This is only used with output substreams. This function should wait - until all data read from the substream buffer has been transmitted. + until all data read from the substream buffer have been transmitted. This ensures that the device can be closed and the driver unloaded without losing data. - This callback is optional. If you do not set + This callback is optional. If you do not set drain in the struct snd_rawmidi_ops structure, ALSA will simply wait for 50 milliseconds instead. @@ -4775,24 +4773,24 @@ struct _snd_pcm_runtime {
FM OPL3 - The FM OPL3 is still used on many chips (mainly for backward + The FM OPL3 is still used in many chips (mainly for backward compatibility). ALSA has a nice OPL3 FM control layer, too. The OPL3 API is defined in <sound/opl3.h>. - FM registers can be directly accessed through direct-FM API, + FM registers can be directly accessed through the direct-FM API, defined in <sound/asound_fm.h>. In ALSA native mode, FM registers are accessed through - Hardware-Dependant Device direct-FM extension API, whereas in - OSS compatible mode, FM registers can be accessed with OSS - direct-FM compatible API on /dev/dmfmX device. + the Hardware-Dependant Device direct-FM extension API, whereas in + OSS compatible mode, FM registers can be accessed with the OSS + direct-FM compatible API in /dev/dmfmX device. - For creating the OPL3 component, you have two functions to - call. The first one is a constructor for opl3_t + To create the OPL3 component, you have two functions to + call. The first one is a constructor for the opl3_t instance. @@ -4819,12 +4817,12 @@ struct _snd_pcm_runtime { When the left and right ports have been already allocated by the card driver, pass non-zero to the fifth argument - (integrated). Otherwise, opl3 module will + (integrated). Otherwise, the opl3 module will allocate the specified ports by itself. - When the accessing to the hardware requires special method + When the accessing the hardware requires special method instead of the standard I/O access, you can create opl3 instance separately with snd_opl3_new(). @@ -4845,13 +4843,13 @@ struct _snd_pcm_runtime { access function, the private data and the destructor. The l_port and r_port are not necessarily set. Only the command must be set properly. You can retrieve the data - from opl3->private_data field. + from the opl3->private_data field. After creating the opl3 instance via snd_opl3_new(), call snd_opl3_init() to initialize the chip to the - proper state. Note that snd_opl3_create() always + proper state. Note that snd_opl3_create() always calls it internally. @@ -4884,7 +4882,7 @@ struct _snd_pcm_runtime {
Hardware-Dependent Devices - Some chips need the access from the user-space for special + Some chips need user-space access for special controls or for loading the micro code. In such a case, you can create a hwdep (hardware-dependent) device. The hwdep API is defined in <sound/hwdep.h>. You can @@ -4893,7 +4891,7 @@ struct _snd_pcm_runtime { - Creation of the hwdep instance is done via + The creation of the hwdep instance is done via snd_hwdep_new(). @@ -4912,8 +4910,8 @@ struct _snd_pcm_runtime { You can then pass any pointer value to the private_data. If you assign a private data, you should define the - destructor, too. The destructor function is set to - private_free field. + destructor, too. The destructor function is set in + the private_free field. @@ -4925,7 +4923,7 @@ struct _snd_pcm_runtime { - and the implementation of destructor would be: + and the implementation of the destructor would be: @@ -4943,7 +4941,7 @@ struct _snd_pcm_runtime { The arbitrary file operations can be defined for this instance. The file operators are defined in - ops table. For example, assume that + the ops table. For example, assume that this chip needs an ioctl. @@ -4964,7 +4962,7 @@ struct _snd_pcm_runtime { IEC958 (S/PDIF) Usually the controls for IEC958 devices are implemented via - control interface. There is a macro to compose a name string for + the control interface. There is a macro to compose a name string for IEC958 controls, SNDRV_CTL_NAME_IEC958() defined in <include/asound.h>. @@ -4973,7 +4971,7 @@ struct _snd_pcm_runtime { There are some standard controls for IEC958 status bits. These controls use the type SNDRV_CTL_ELEM_TYPE_IEC958, and the size of element is fixed as 4 bytes array - (value.iec958.status[x]). For info + (value.iec958.status[x]). For the info callback, you don't specify the value field for this type (the count field must be set, though). @@ -5001,7 +4999,7 @@ struct _snd_pcm_runtime { enable/disable or to set the raw bit mode. The implementation will depend on the chip, but the control should be named as IEC958 xxx, preferably using - SNDRV_CTL_NAME_IEC958() macro. + the SNDRV_CTL_NAME_IEC958() macro. @@ -5036,12 +5034,12 @@ struct _snd_pcm_runtime { The allocation of pages with fallback is snd_malloc_xxx_pages_fallback(). This function tries to allocate the specified pages but if the pages - are not available, it tries to reduce the page sizes until the + are not available, it tries to reduce the page sizes until enough space is found. - For releasing the space, call + The release the pages, call snd_free_xxx_pages() function. @@ -5050,8 +5048,8 @@ struct _snd_pcm_runtime { a large contiguous physical space at the time the module is loaded for the later use. This is called pre-allocation. - As already written, you can call the following function at the - construction of pcm instance (in the case of PCI bus). + As already written, you can call the following function at + pcm instance construction time (in the case of PCI bus). @@ -5063,34 +5061,34 @@ struct _snd_pcm_runtime { where size is the byte size to be - pre-allocated and the max is the maximal - size to be changed via prealloc proc file. - The allocator will try to get as large area as possible + pre-allocated and the max is the maximum + size to be changed via the prealloc proc file. + The allocator will try to get an area as large as possible within the given size. The second argument (type) and the third argument (device pointer) are dependent on the bus. - In the case of ISA bus, pass snd_dma_isa_data() + In the case of the ISA bus, pass snd_dma_isa_data() as the third argument with SNDRV_DMA_TYPE_DEV type. For the continuous buffer unrelated to the bus can be pre-allocated with SNDRV_DMA_TYPE_CONTINUOUS type and the snd_dma_continuous_data(GFP_KERNEL) device pointer, - whereh GFP_KERNEL is the kernel allocation flag to + where GFP_KERNEL is the kernel allocation flag to use. For the SBUS, SNDRV_DMA_TYPE_SBUS and snd_dma_sbus_data(sbus_dev) are used instead. For the PCI scatter-gather buffers, use SNDRV_DMA_TYPE_DEV_SG with snd_dma_pci_data(pci) - (see the section + (see the Non-Contiguous Buffers - ). + section). - Once when the buffer is pre-allocated, you can use the - allocator in the hw_params callback + Once the buffer is pre-allocated, you can use the + allocator in the hw_params callback: @@ -5116,8 +5114,8 @@ struct _snd_pcm_runtime { - The first case works fine if the external hardware buffer is enough - large. This method doesn't need any extra buffers and thus is + The first case works fine if the external hardware buffer is large + enough. This method doesn't need any extra buffers and thus is more effective. You need to define the copy and silence callbacks for @@ -5127,25 +5125,25 @@ struct _snd_pcm_runtime { - The second case allows the mmap of the buffer, although you have - to handle an interrupt or a tasklet for transferring the data + The second case allows for mmap on the buffer, although you have + to handle an interrupt or a tasklet to transfer the data from the intermediate buffer to the hardware buffer. You can find an - example in vxpocket driver. + example in the vxpocket driver. - Another case is that the chip uses a PCI memory-map + Another case is when the chip uses a PCI memory-map region for the buffer instead of the host memory. In this case, - mmap is available only on certain architectures like intel. In - non-mmap mode, the data cannot be transferred as the normal - way. Thus you need to define copy and - silence callbacks as well + mmap is available only on certain architectures like the Intel one. + In non-mmap mode, the data cannot be transferred as in the normal + way. Thus you need to define the copy and + silence callbacks as well, as in the cases above. The examples are found in rme32.c and rme96.c. - The implementation of copy and + The implementation of the copy and silence callbacks depends upon whether the hardware supports interleaved or non-interleaved samples. The copy callback is @@ -5184,8 +5182,8 @@ struct _snd_pcm_runtime { What you have to do in this callback is again different - between playback and capture directions. In the case of - playback, you do: copy the given amount of data + between playback and capture directions. In the + playback case, you copy the given amount of data (count) at the specified pointer (src) to the specified offset (pos) on the hardware buffer. When @@ -5202,7 +5200,7 @@ struct _snd_pcm_runtime { - For the capture direction, you do: copy the given amount of + For the capture direction, you copy the given amount of data (count) at the specified offset (pos) on the hardware buffer to the specified pointer (dst). @@ -5216,7 +5214,7 @@ struct _snd_pcm_runtime { - Note that both of the position and the data amount are given + Note that both the position and the amount of data are given in frames. @@ -5247,7 +5245,7 @@ struct _snd_pcm_runtime { - The meanings of arguments are identical with the + The meanings of arguments are the same as in the copy callback, although there is no src/dst argument. In the case of interleaved samples, the channel @@ -5284,8 +5282,8 @@ struct _snd_pcm_runtime {
Non-Contiguous Buffers - If your hardware supports the page table like emu10k1 or the - buffer descriptors like via82xx, you can use the scatter-gather + If your hardware supports the page table as in emu10k1 or the + buffer descriptors as in via82xx, you can use the scatter-gather (SG) DMA. ALSA provides an interface for handling SG-buffers. The API is provided in <sound/pcm.h>. @@ -5296,7 +5294,7 @@ struct _snd_pcm_runtime { snd_pcm_lib_preallocate_pages_for_all() with SNDRV_DMA_TYPE_DEV_SG in the PCM constructor like other PCI pre-allocator. - You need to pass the snd_dma_pci_data(pci), + You need to pass snd_dma_pci_data(pci), where pci is the struct pci_dev pointer of the chip as well. The struct snd_sg_buf instance is created as @@ -5314,7 +5312,7 @@ struct _snd_pcm_runtime { Then call snd_pcm_lib_malloc_pages() - in hw_params callback + in the hw_params callback as well as in the case of normal PCI buffer. The SG-buffer handler will allocate the non-contiguous kernel pages of the given size and map them onto the virtually contiguous @@ -5335,7 +5333,7 @@ struct _snd_pcm_runtime { - For releasing the data, call + To release the data, call snd_pcm_lib_free_pages() in the hw_free callback as usual. @@ -5390,7 +5388,7 @@ struct _snd_pcm_runtime { - For creating a proc file, call + To create a proc file, call snd_card_proc_new(). @@ -5402,7 +5400,7 @@ struct _snd_pcm_runtime { - where the second argument specifies the proc-file name to be + where the second argument specifies the name of the proc file to be created. The above example will create a file my-file under the card directory, e.g. /proc/asound/card0/my-file. @@ -5417,8 +5415,8 @@ struct _snd_pcm_runtime { When the creation is successful, the function stores a new - instance at the pointer given in the third argument. - It is initialized as a text proc file for read only. For using + instance in the pointer given in the third argument. + It is initialized as a text proc file for read only. To use this proc file as a read-only text file as it is, set the read callback with a private data via snd_info_set_text_ops(). @@ -5470,9 +5468,9 @@ struct _snd_pcm_runtime { - The file permission can be changed afterwards. As default, it's - set as read only for all users. If you want to add the write - permission to the user (root as default), set like below: + The file permissions can be changed afterwards. As default, it's + set as read only for all users. If you want to add write + permission for the user (root as default), do as follows: @@ -5503,7 +5501,7 @@ struct _snd_pcm_runtime { - For a raw-data proc-file, set the attributes like the following: + For a raw-data proc-file, set the attributes as follows: @@ -5524,7 +5522,7 @@ struct _snd_pcm_runtime { The callback is much more complicated than the text-file - version. You need to use a low-level i/o functions such as + version. You need to use a low-level I/O functions such as copy_from/to_user() to transfer the data. @@ -5560,28 +5558,28 @@ struct _snd_pcm_runtime { Power Management If the chip is supposed to work with suspend/resume - functions, you need to add the power-management codes to the - driver. The additional codes for the power-management should be + functions, you need to add power-management code to the + driver. The additional code for power-management should be ifdef'ed with CONFIG_PM. - If the driver supports the suspend/resume - fully, that is, the device can be - properly resumed to the status at the suspend is called, - you can set SNDRV_PCM_INFO_RESUME flag - to pcm info field. Usually, this is possible when the - registers of ths chip can be safely saved and restored to the - RAM. If this is set, the trigger callback is called with - SNDRV_PCM_TRIGGER_RESUME after resume - callback is finished. + If the driver fully supports suspend/resume + that is, the device can be + properly resumed to its state when suspend was called, + you can set the SNDRV_PCM_INFO_RESUME flag + in the pcm info field. Usually, this is possible when the + registers of the chip can be safely saved and restored to + RAM. If this is set, the trigger callback is called with + SNDRV_PCM_TRIGGER_RESUME after the resume + callback completes. - Even if the driver doesn't support PM fully but only the - partial suspend/resume is possible, it's still worthy to - implement suspend/resume callbacks. In such a case, applications + Even if the driver doesn't support PM fully but + partial suspend/resume is still possible, it's still worthy to + implement suspend/resume callbacks. In such a case, applications would reset the status by calling snd_pcm_prepare() and restart the stream appropriately. Hence, you can define suspend/resume callbacks @@ -5590,22 +5588,22 @@ struct _snd_pcm_runtime { - Note that the trigger with SUSPEND can be always called when + Note that the trigger with SUSPEND can always be called when snd_pcm_suspend_all is called, - regardless of SNDRV_PCM_INFO_RESUME flag. + regardless of the SNDRV_PCM_INFO_RESUME flag. The RESUME flag affects only the behavior of snd_pcm_resume(). (Thus, in theory, SNDRV_PCM_TRIGGER_RESUME isn't needed to be handled in the trigger callback when no SNDRV_PCM_INFO_RESUME flag is set. But, - it's better to keep it for compatibility reason.) + it's better to keep it for compatibility reasons.) In the earlier version of ALSA drivers, a common power-management layer was provided, but it has been removed. The driver needs to define the suspend/resume hooks according to - the bus the device is assigned. In the case of PCI driver, the + the bus the device is connected to. In the case of PCI drivers, the callbacks look like below: @@ -5629,7 +5627,7 @@ struct _snd_pcm_runtime { - The scheme of the real suspend job is as following. + The scheme of the real suspend job is as follows. Retrieve the card and the chip data. @@ -5679,11 +5677,11 @@ struct _snd_pcm_runtime { - The scheme of the real resume job is as following. + The scheme of the real resume job is as follows. Retrieve the card and the chip data. - Set up PCI. First, call pci_restore_state(). + Set up PCI. First, call pci_restore_state(). Then enable the pci device again by calling pci_enable_device(). Call pci_set_master() if necessary, too. Re-initialize the chip. @@ -5734,7 +5732,7 @@ struct _snd_pcm_runtime { snd_pcm_suspend_all() or snd_pcm_suspend(). It means that the PCM streams are already stoppped when the register snapshot is - taken. But, remind that you don't have to restart the PCM + taken. But, remember that you don't have to restart the PCM stream in the resume callback. It'll be restarted via trigger call with SNDRV_PCM_TRIGGER_RESUME when necessary. @@ -5795,7 +5793,7 @@ struct _snd_pcm_runtime { - If you need a space for saving the registers, allocate the + If you need a space to save the registers, allocate the buffer for it here, too, since it would be fatal if you cannot allocate a memory in the suspend phase. The allocated buffer should be released in the corresponding @@ -5833,7 +5831,7 @@ struct _snd_pcm_runtime { Module Parameters There are standard module options for ALSA. At least, each - module should have index, + module should have the index, id and enable options. @@ -5841,8 +5839,8 @@ struct _snd_pcm_runtime { If the module supports multiple cards (usually up to 8 = SNDRV_CARDS cards), they should be - arrays. The default initial values are defined already as - constants for ease of programming: + arrays. The default initial values are defined already as + constants for easier programming: @@ -5858,7 +5856,7 @@ struct _snd_pcm_runtime { If the module supports only a single card, they could be single variables, instead. enable option is not - always necessary in this case, but it wouldn't be so bad to have a + always necessary in this case, but it would be better to have a dummy option for compatibility. @@ -5923,22 +5921,22 @@ struct _snd_pcm_runtime { - Suppose that you'll create a new PCI driver for the card + Suppose that you create a new PCI driver for the card xyz. The card module name would be - snd-xyz. The new driver is usually put into alsa-driver + snd-xyz. The new driver is usually put into the alsa-driver tree, alsa-driver/pci directory in the case of PCI cards. Then the driver is evaluated, audited and tested by developers and users. After a certain time, the driver - will go to alsa-kernel tree (to the corresponding directory, + will go to the alsa-kernel tree (to the corresponding directory, such as alsa-kernel/pci) and eventually - integrated into Linux 2.6 tree (the directory would be + will be integrated into the Linux 2.6 tree (the directory would be linux/sound/pci). In the following sections, the driver code is supposed - to be put into alsa-driver tree. The two cases are assumed: + to be put into alsa-driver tree. The two cases are covered: a driver consisting of a single source file and one consisting of several source files. @@ -6033,7 +6031,7 @@ struct _snd_pcm_runtime { Add a new directory (xyz) in - alsa-driver/pci/Makefile like below + alsa-driver/pci/Makefile as below @@ -6102,7 +6100,7 @@ struct _snd_pcm_runtime {
<function>snd_printk()</function> and friends - ALSA provides a verbose version of + ALSA provides a verbose version of the printk() function. If a kernel config CONFIG_SND_VERBOSE_PRINTK is set, this function prints the given message together with the file name @@ -6170,7 +6168,7 @@ struct _snd_pcm_runtime {
<function>snd_BUG()</function> - It shows BUG? message and + It shows the BUG? message and stack trace as well as snd_assert at the point. It's useful to show that a fatal error happens there. @@ -6199,6 +6197,4 @@ struct _snd_pcm_runtime { in the hardware constraints section. - - diff --git a/include/sound/ainstr_fm.h b/include/sound/ainstr_fm.h deleted file mode 100644 index c4afb1f..0000000 --- a/include/sound/ainstr_fm.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Advanced Linux Sound Architecture - * - * FM (OPL2/3) Instrument Format - * Copyright (c) 2000 Uros Bizjak - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef __SOUND_AINSTR_FM_H -#define __SOUND_AINSTR_FM_H - -#ifndef __KERNEL__ -#include -#include -#endif - -/* - * share types (share ID 1) - */ - -#define FM_SHARE_FILE 0 - -/* - * FM operator - */ - -struct fm_operator { - unsigned char am_vib; - unsigned char ksl_level; - unsigned char attack_decay; - unsigned char sustain_release; - unsigned char wave_select; -}; - -/* - * Instrument - */ - -#define FM_PATCH_OPL2 0x01 /* OPL2 2 operators FM instrument */ -#define FM_PATCH_OPL3 0x02 /* OPL3 4 operators FM instrument */ - -struct fm_instrument { - unsigned int share_id[4]; /* share id - zero = no sharing */ - unsigned char type; /* instrument type */ - - struct fm_operator op[4]; - unsigned char feedback_connection[2]; - - unsigned char echo_delay; - unsigned char echo_atten; - unsigned char chorus_spread; - unsigned char trnsps; - unsigned char fix_dur; - unsigned char modes; - unsigned char fix_key; -}; - -/* - * - * Kernel <-> user space - * Hardware (CPU) independent section - * - * * = zero or more - * + = one or more - * - * fm_xinstrument FM_STRU_INSTR - * - */ - -#define FM_STRU_INSTR __cpu_to_be32(('I'<<24)|('N'<<16)|('S'<<8)|'T') - -/* - * FM operator - */ - -struct fm_xoperator { - __u8 am_vib; - __u8 ksl_level; - __u8 attack_decay; - __u8 sustain_release; - __u8 wave_select; -}; - -/* - * Instrument - */ - -struct fm_xinstrument { - __u32 stype; /* structure type */ - - __u32 share_id[4]; /* share id - zero = no sharing */ - __u8 type; /* instrument type */ - - struct fm_xoperator op[4]; /* fm operators */ - __u8 feedback_connection[2]; - - __u8 echo_delay; - __u8 echo_atten; - __u8 chorus_spread; - __u8 trnsps; - __u8 fix_dur; - __u8 modes; - __u8 fix_key; -}; - -#ifdef __KERNEL__ - -#include "seq_instr.h" - -int snd_seq_fm_init(struct snd_seq_kinstr_ops * ops, - struct snd_seq_kinstr_ops * next); - -#endif - -/* typedefs for compatibility to user-space */ -typedef struct fm_xoperator fm_xoperator_t; -typedef struct fm_xinstrument fm_xinstrument_t; - -#endif /* __SOUND_AINSTR_FM_H */ diff --git a/include/sound/ainstr_gf1.h b/include/sound/ainstr_gf1.h deleted file mode 100644 index b62b665..0000000 --- a/include/sound/ainstr_gf1.h +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Advanced Linux Sound Architecture - * - * GF1 (GUS) Patch Instrument Format - * Copyright (c) 1994-99 by Jaroslav Kysela - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef __SOUND_AINSTR_GF1_H -#define __SOUND_AINSTR_GF1_H - -#ifndef __KERNEL__ -#include -#include -#endif - -/* - * share types (share ID 1) - */ - -#define GF1_SHARE_FILE 0 - -/* - * wave formats - */ - -#define GF1_WAVE_16BIT 0x0001 /* 16-bit wave */ -#define GF1_WAVE_UNSIGNED 0x0002 /* unsigned wave */ -#define GF1_WAVE_INVERT 0x0002 /* same as unsigned wave */ -#define GF1_WAVE_BACKWARD 0x0004 /* backward mode (maybe used for reverb or ping-ping loop) */ -#define GF1_WAVE_LOOP 0x0008 /* loop mode */ -#define GF1_WAVE_BIDIR 0x0010 /* bidirectional mode */ -#define GF1_WAVE_STEREO 0x0100 /* stereo mode */ -#define GF1_WAVE_ULAW 0x0200 /* uLaw compression mode */ - -/* - * Wavetable definitions - */ - -struct gf1_wave { - unsigned int share_id[4]; /* share id - zero = no sharing */ - unsigned int format; /* wave format */ - - struct { - unsigned int number; /* some other ID for this instrument */ - unsigned int memory; /* begin of waveform in onboard memory */ - unsigned char *ptr; /* pointer to waveform in system memory */ - } address; - - unsigned int size; /* size of waveform in samples */ - unsigned int start; /* start offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned int loop_start; /* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned int loop_end; /* loop start offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned short loop_repeat; /* loop repeat - 0 = forever */ - - unsigned char flags; /* GF1 patch flags */ - unsigned char pad; - unsigned int sample_rate; /* sample rate in Hz */ - unsigned int low_frequency; /* low frequency range */ - unsigned int high_frequency; /* high frequency range */ - unsigned int root_frequency; /* root frequency range */ - signed short tune; - unsigned char balance; - unsigned char envelope_rate[6]; - unsigned char envelope_offset[6]; - unsigned char tremolo_sweep; - unsigned char tremolo_rate; - unsigned char tremolo_depth; - unsigned char vibrato_sweep; - unsigned char vibrato_rate; - unsigned char vibrato_depth; - unsigned short scale_frequency; - unsigned short scale_factor; /* 0-2048 or 0-2 */ - - struct gf1_wave *next; -}; - -/* - * Instrument - */ - -#define IWFFFF_EXCLUDE_NONE 0x0000 /* exclusion mode - none */ -#define IWFFFF_EXCLUDE_SINGLE 0x0001 /* exclude single - single note from the instrument group */ -#define IWFFFF_EXCLUDE_MULTIPLE 0x0002 /* exclude multiple - stop only same note from this instrument */ - -#define IWFFFF_EFFECT_NONE 0 -#define IWFFFF_EFFECT_REVERB 1 -#define IWFFFF_EFFECT_CHORUS 2 -#define IWFFFF_EFFECT_ECHO 3 - -struct gf1_instrument { - unsigned short exclusion; - unsigned short exclusion_group; /* 0 - none, 1-65535 */ - - unsigned char effect1; /* effect 1 */ - unsigned char effect1_depth; /* 0-127 */ - unsigned char effect2; /* effect 2 */ - unsigned char effect2_depth; /* 0-127 */ - - struct gf1_wave *wave; /* first waveform */ -}; - -/* - * - * Kernel <-> user space - * Hardware (CPU) independent section - * - * * = zero or more - * + = one or more - * - * gf1_xinstrument IWFFFF_STRU_INSTR - * +gf1_xwave IWFFFF_STRU_WAVE - * - */ - -#define GF1_STRU_WAVE __cpu_to_be32(('W'<<24)|('A'<<16)|('V'<<8)|'E') -#define GF1_STRU_INSTR __cpu_to_be32(('I'<<24)|('N'<<16)|('S'<<8)|'T') - -/* - * Wavetable definitions - */ - -struct gf1_xwave { - __u32 stype; /* structure type */ - - __u32 share_id[4]; /* share id - zero = no sharing */ - __u32 format; /* wave format */ - - __u32 size; /* size of waveform in samples */ - __u32 start; /* start offset in samples * 16 (lowest 4 bits - fraction) */ - __u32 loop_start; /* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */ - __u32 loop_end; /* loop start offset in samples * 16 (lowest 4 bits - fraction) */ - __u16 loop_repeat; /* loop repeat - 0 = forever */ - - __u8 flags; /* GF1 patch flags */ - __u8 pad; - __u32 sample_rate; /* sample rate in Hz */ - __u32 low_frequency; /* low frequency range */ - __u32 high_frequency; /* high frequency range */ - __u32 root_frequency; /* root frequency range */ - __s16 tune; - __u8 balance; - __u8 envelope_rate[6]; - __u8 envelope_offset[6]; - __u8 tremolo_sweep; - __u8 tremolo_rate; - __u8 tremolo_depth; - __u8 vibrato_sweep; - __u8 vibrato_rate; - __u8 vibrato_depth; - __u16 scale_frequency; - __u16 scale_factor; /* 0-2048 or 0-2 */ -}; - -/* - * Instrument - */ - -struct gf1_xinstrument { - __u32 stype; - - __u16 exclusion; - __u16 exclusion_group; /* 0 - none, 1-65535 */ - - __u8 effect1; /* effect 1 */ - __u8 effect1_depth; /* 0-127 */ - __u8 effect2; /* effect 2 */ - __u8 effect2_depth; /* 0-127 */ -}; - -/* - * Instrument info - */ - -#define GF1_INFO_ENVELOPE (1<<0) -#define GF1_INFO_TREMOLO (1<<1) -#define GF1_INFO_VIBRATO (1<<2) - -struct gf1_info { - unsigned char flags; /* supported wave flags */ - unsigned char pad[3]; - unsigned int features; /* supported features */ - unsigned int max8_len; /* maximum 8-bit wave length */ - unsigned int max16_len; /* maximum 16-bit wave length */ -}; - -#ifdef __KERNEL__ - -#include "seq_instr.h" - -struct snd_gf1_ops { - void *private_data; - int (*info)(void *private_data, struct gf1_info *info); - int (*put_sample)(void *private_data, struct gf1_wave *wave, - char __user *data, long len, int atomic); - int (*get_sample)(void *private_data, struct gf1_wave *wave, - char __user *data, long len, int atomic); - int (*remove_sample)(void *private_data, struct gf1_wave *wave, - int atomic); - void (*notify)(void *private_data, struct snd_seq_kinstr *instr, int what); - struct snd_seq_kinstr_ops kops; -}; - -int snd_seq_gf1_init(struct snd_gf1_ops *ops, - void *private_data, - struct snd_seq_kinstr_ops *next); - -#endif - -/* typedefs for compatibility to user-space */ -typedef struct gf1_xwave gf1_xwave_t; -typedef struct gf1_xinstrument gf1_xinstrument_t; - -#endif /* __SOUND_AINSTR_GF1_H */ diff --git a/include/sound/ainstr_iw.h b/include/sound/ainstr_iw.h deleted file mode 100644 index 11bd250..0000000 --- a/include/sound/ainstr_iw.h +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Advanced Linux Sound Architecture - * - * InterWave FFFF Instrument Format - * Copyright (c) 1994-99 by Jaroslav Kysela - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef __SOUND_AINSTR_IW_H -#define __SOUND_AINSTR_IW_H - -#ifndef __KERNEL__ -#include -#include -#endif - -/* - * share types (share ID 1) - */ - -#define IWFFFF_SHARE_FILE 0 - -/* - * wave formats - */ - -#define IWFFFF_WAVE_16BIT 0x0001 /* 16-bit wave */ -#define IWFFFF_WAVE_UNSIGNED 0x0002 /* unsigned wave */ -#define IWFFFF_WAVE_INVERT 0x0002 /* same as unsigned wave */ -#define IWFFFF_WAVE_BACKWARD 0x0004 /* backward mode (maybe used for reverb or ping-ping loop) */ -#define IWFFFF_WAVE_LOOP 0x0008 /* loop mode */ -#define IWFFFF_WAVE_BIDIR 0x0010 /* bidirectional mode */ -#define IWFFFF_WAVE_ULAW 0x0020 /* uLaw compressed wave */ -#define IWFFFF_WAVE_RAM 0x0040 /* wave is _preloaded_ in RAM (it is used for ROM simulation) */ -#define IWFFFF_WAVE_ROM 0x0080 /* wave is in ROM */ -#define IWFFFF_WAVE_STEREO 0x0100 /* wave is stereo */ - -/* - * Wavetable definitions - */ - -struct iwffff_wave { - unsigned int share_id[4]; /* share id - zero = no sharing */ - unsigned int format; /* wave format */ - - struct { - unsigned int number; /* some other ID for this wave */ - unsigned int memory; /* begin of waveform in onboard memory */ - unsigned char *ptr; /* pointer to waveform in system memory */ - } address; - - unsigned int size; /* size of waveform in samples */ - unsigned int start; /* start offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned int loop_start; /* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned int loop_end; /* loop start offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned short loop_repeat; /* loop repeat - 0 = forever */ - unsigned int sample_ratio; /* sample ratio (44100 * 1024 / rate) */ - unsigned char attenuation; /* 0 - 127 (no corresponding midi controller) */ - unsigned char low_note; /* lower frequency range for this waveform */ - unsigned char high_note; /* higher frequency range for this waveform */ - unsigned char pad; - - struct iwffff_wave *next; -}; - -/* - * Layer - */ - -#define IWFFFF_LFO_SHAPE_TRIANGLE 0 -#define IWFFFF_LFO_SHAPE_POSTRIANGLE 1 - -struct iwffff_lfo { - unsigned short freq; /* (0-2047) 0.01Hz - 21.5Hz */ - signed short depth; /* volume +- (0-255) 0.48675dB/step */ - signed short sweep; /* 0 - 950 deciseconds */ - unsigned char shape; /* see to IWFFFF_LFO_SHAPE_XXXX */ - unsigned char delay; /* 0 - 255 deciseconds */ -}; - -#define IWFFFF_ENV_FLAG_RETRIGGER 0x0001 /* flag - retrigger */ - -#define IWFFFF_ENV_MODE_ONE_SHOT 0x0001 /* mode - one shot */ -#define IWFFFF_ENV_MODE_SUSTAIN 0x0002 /* mode - sustain */ -#define IWFFFF_ENV_MODE_NO_SUSTAIN 0x0003 /* mode - no sustain */ - -#define IWFFFF_ENV_INDEX_VELOCITY 0x0001 /* index - velocity */ -#define IWFFFF_ENV_INDEX_FREQUENCY 0x0002 /* index - frequency */ - -struct iwffff_env_point { - unsigned short offset; - unsigned short rate; -}; - -struct iwffff_env_record { - unsigned short nattack; - unsigned short nrelease; - unsigned short sustain_offset; - unsigned short sustain_rate; - unsigned short release_rate; - unsigned char hirange; - unsigned char pad; - struct iwffff_env_record *next; - /* points are stored here */ - /* count of points = nattack + nrelease */ -}; - -struct iwffff_env { - unsigned char flags; - unsigned char mode; - unsigned char index; - unsigned char pad; - struct iwffff_env_record *record; -}; - -#define IWFFFF_LAYER_FLAG_RETRIGGER 0x0001 /* retrigger */ - -#define IWFFFF_LAYER_VELOCITY_TIME 0x0000 /* velocity mode = time */ -#define IWFFFF_LAYER_VELOCITY_RATE 0x0001 /* velocity mode = rate */ - -#define IWFFFF_LAYER_EVENT_KUP 0x0000 /* layer event - key up */ -#define IWFFFF_LAYER_EVENT_KDOWN 0x0001 /* layer event - key down */ -#define IWFFFF_LAYER_EVENT_RETRIG 0x0002 /* layer event - retrigger */ -#define IWFFFF_LAYER_EVENT_LEGATO 0x0003 /* layer event - legato */ - -struct iwffff_layer { - unsigned char flags; - unsigned char velocity_mode; - unsigned char layer_event; - unsigned char low_range; /* range for layer based */ - unsigned char high_range; /* on either velocity or frequency */ - unsigned char pan; /* pan offset from CC1 (0 left - 127 right) */ - unsigned char pan_freq_scale; /* position based on frequency (0-127) */ - unsigned char attenuation; /* 0-127 (no corresponding midi controller) */ - struct iwffff_lfo tremolo; /* tremolo effect */ - struct iwffff_lfo vibrato; /* vibrato effect */ - unsigned short freq_scale; /* 0-2048, 1024 is equal to semitone scaling */ - unsigned char freq_center; /* center for keyboard frequency scaling */ - unsigned char pad; - struct iwffff_env penv; /* pitch envelope */ - struct iwffff_env venv; /* volume envelope */ - - struct iwffff_wave *wave; - struct iwffff_layer *next; -}; - -/* - * Instrument - */ - -#define IWFFFF_EXCLUDE_NONE 0x0000 /* exclusion mode - none */ -#define IWFFFF_EXCLUDE_SINGLE 0x0001 /* exclude single - single note from the instrument group */ -#define IWFFFF_EXCLUDE_MULTIPLE 0x0002 /* exclude multiple - stop only same note from this instrument */ - -#define IWFFFF_LAYER_NONE 0x0000 /* not layered */ -#define IWFFFF_LAYER_ON 0x0001 /* layered */ -#define IWFFFF_LAYER_VELOCITY 0x0002 /* layered by velocity */ -#define IWFFFF_LAYER_FREQUENCY 0x0003 /* layered by frequency */ - -#define IWFFFF_EFFECT_NONE 0 -#define IWFFFF_EFFECT_REVERB 1 -#define IWFFFF_EFFECT_CHORUS 2 -#define IWFFFF_EFFECT_ECHO 3 - -struct iwffff_instrument { - unsigned short exclusion; - unsigned short layer_type; - unsigned short exclusion_group; /* 0 - none, 1-65535 */ - - unsigned char effect1; /* effect 1 */ - unsigned char effect1_depth; /* 0-127 */ - unsigned char effect2; /* effect 2 */ - unsigned char effect2_depth; /* 0-127 */ - - struct iwffff_layer *layer; /* first layer */ -}; - -/* - * - * Kernel <-> user space - * Hardware (CPU) independent section - * - * * = zero or more - * + = one or more - * - * iwffff_xinstrument IWFFFF_STRU_INSTR - * +iwffff_xlayer IWFFFF_STRU_LAYER - * *iwffff_xenv_record IWFFFF_STRU_ENV_RECT (tremolo) - * *iwffff_xenv_record IWFFFF_STRU_EVN_RECT (vibrato) - * +iwffff_xwave IWFFFF_STRU_WAVE - * - */ - -#define IWFFFF_STRU_WAVE __cpu_to_be32(('W'<<24)|('A'<<16)|('V'<<8)|'E') -#define IWFFFF_STRU_ENV_RECP __cpu_to_be32(('E'<<24)|('N'<<16)|('R'<<8)|'P') -#define IWFFFF_STRU_ENV_RECV __cpu_to_be32(('E'<<24)|('N'<<16)|('R'<<8)|'V') -#define IWFFFF_STRU_LAYER __cpu_to_be32(('L'<<24)|('A'<<16)|('Y'<<8)|'R') -#define IWFFFF_STRU_INSTR __cpu_to_be32(('I'<<24)|('N'<<16)|('S'<<8)|'T') - -/* - * Wavetable definitions - */ - -struct iwffff_xwave { - __u32 stype; /* structure type */ - - __u32 share_id[4]; /* share id - zero = no sharing */ - - __u32 format; /* wave format */ - __u32 offset; /* offset to ROM (address) */ - - __u32 size; /* size of waveform in samples */ - __u32 start; /* start offset in samples * 16 (lowest 4 bits - fraction) */ - __u32 loop_start; /* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */ - __u32 loop_end; /* loop start offset in samples * 16 (lowest 4 bits - fraction) */ - __u16 loop_repeat; /* loop repeat - 0 = forever */ - __u32 sample_ratio; /* sample ratio (44100 * 1024 / rate) */ - __u8 attenuation; /* 0 - 127 (no corresponding midi controller) */ - __u8 low_note; /* lower frequency range for this waveform */ - __u8 high_note; /* higher frequency range for this waveform */ - __u8 pad; -}; - -/* - * Layer - */ - -struct iwffff_xlfo { - __u16 freq; /* (0-2047) 0.01Hz - 21.5Hz */ - __s16 depth; /* volume +- (0-255) 0.48675dB/step */ - __s16 sweep; /* 0 - 950 deciseconds */ - __u8 shape; /* see to ULTRA_IW_LFO_SHAPE_XXXX */ - __u8 delay; /* 0 - 255 deciseconds */ -}; - -struct iwffff_xenv_point { - __u16 offset; - __u16 rate; -}; - -struct iwffff_xenv_record { - __u32 stype; - __u16 nattack; - __u16 nrelease; - __u16 sustain_offset; - __u16 sustain_rate; - __u16 release_rate; - __u8 hirange; - __u8 pad; - /* points are stored here.. */ - /* count of points = nattack + nrelease */ -}; - -struct iwffff_xenv { - __u8 flags; - __u8 mode; - __u8 index; - __u8 pad; -}; - -struct iwffff_xlayer { - __u32 stype; - __u8 flags; - __u8 velocity_mode; - __u8 layer_event; - __u8 low_range; /* range for layer based */ - __u8 high_range; /* on either velocity or frequency */ - __u8 pan; /* pan offset from CC1 (0 left - 127 right) */ - __u8 pan_freq_scale; /* position based on frequency (0-127) */ - __u8 attenuation; /* 0-127 (no corresponding midi controller) */ - struct iwffff_xlfo tremolo; /* tremolo effect */ - struct iwffff_xlfo vibrato; /* vibrato effect */ - __u16 freq_scale; /* 0-2048, 1024 is equal to semitone scaling */ - __u8 freq_center; /* center for keyboard frequency scaling */ - __u8 pad; - struct iwffff_xenv penv; /* pitch envelope */ - struct iwffff_xenv venv; /* volume envelope */ -}; - -/* - * Instrument - */ - -struct iwffff_xinstrument { - __u32 stype; - - __u16 exclusion; - __u16 layer_type; - __u16 exclusion_group; /* 0 - none, 1-65535 */ - - __u8 effect1; /* effect 1 */ - __u8 effect1_depth; /* 0-127 */ - __u8 effect2; /* effect 2 */ - __u8 effect2_depth; /* 0-127 */ -}; - -/* - * ROM support - * InterWave ROMs are Little-Endian (x86) - */ - -#define IWFFFF_ROM_HDR_SIZE 512 - -struct iwffff_rom_header { - __u8 iwave[8]; - __u8 revision; - __u8 series_number; - __u8 series_name[16]; - __u8 date[10]; - __u16 vendor_revision_major; - __u16 vendor_revision_minor; - __u32 rom_size; - __u8 copyright[128]; - __u8 vendor_name[64]; - __u8 description[128]; -}; - -/* - * Instrument info - */ - -#define IWFFFF_INFO_LFO_VIBRATO (1<<0) -#define IWFFFF_INFO_LFO_VIBRATO_SHAPE (1<<1) -#define IWFFFF_INFO_LFO_TREMOLO (1<<2) -#define IWFFFF_INFO_LFO_TREMOLO_SHAPE (1<<3) - -struct iwffff_info { - unsigned int format; /* supported format bits */ - unsigned int effects; /* supported effects (1 << IWFFFF_EFFECT*) */ - unsigned int lfos; /* LFO effects */ - unsigned int max8_len; /* maximum 8-bit wave length */ - unsigned int max16_len; /* maximum 16-bit wave length */ -}; - -#ifdef __KERNEL__ - -#include "seq_instr.h" - -struct snd_iwffff_ops { - void *private_data; - int (*info)(void *private_data, struct iwffff_info *info); - int (*put_sample)(void *private_data, struct iwffff_wave *wave, - char __user *data, long len, int atomic); - int (*get_sample)(void *private_data, struct iwffff_wave *wave, - char __user *data, long len, int atomic); - int (*remove_sample)(void *private_data, struct iwffff_wave *wave, - int atomic); - void (*notify)(void *private_data, struct snd_seq_kinstr *instr, int what); - struct snd_seq_kinstr_ops kops; -}; - -int snd_seq_iwffff_init(struct snd_iwffff_ops *ops, - void *private_data, - struct snd_seq_kinstr_ops *next); - -#endif - -/* typedefs for compatibility to user-space */ -typedef struct iwffff_xwave iwffff_xwave_t; -typedef struct iwffff_xlfo iwffff_xlfo_t; -typedef struct iwffff_xenv_point iwffff_xenv_point_t; -typedef struct iwffff_xenv_record iwffff_xenv_record_t; -typedef struct iwffff_xenv iwffff_xenv_t; -typedef struct iwffff_xlayer iwffff_xlayer_t; -typedef struct iwffff_xinstrument iwffff_xinstrument_t; -typedef struct iwffff_rom_header iwffff_rom_header_t; -typedef struct iwffff_info iwffff_info_t; - -#endif /* __SOUND_AINSTR_IW_H */ diff --git a/include/sound/ainstr_simple.h b/include/sound/ainstr_simple.h deleted file mode 100644 index da08e72..0000000 --- a/include/sound/ainstr_simple.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Advanced Linux Sound Architecture - * - * Simple (MOD player) Instrument Format - * Copyright (c) 1994-99 by Jaroslav Kysela - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef __SOUND_AINSTR_SIMPLE_H -#define __SOUND_AINSTR_SIMPLE_H - -#ifndef __KERNEL__ -#include -#include -#endif - -/* - * share types (share ID 1) - */ - -#define SIMPLE_SHARE_FILE 0 - -/* - * wave formats - */ - -#define SIMPLE_WAVE_16BIT 0x0001 /* 16-bit wave */ -#define SIMPLE_WAVE_UNSIGNED 0x0002 /* unsigned wave */ -#define SIMPLE_WAVE_INVERT 0x0002 /* same as unsigned wave */ -#define SIMPLE_WAVE_BACKWARD 0x0004 /* backward mode (maybe used for reverb or ping-ping loop) */ -#define SIMPLE_WAVE_LOOP 0x0008 /* loop mode */ -#define SIMPLE_WAVE_BIDIR 0x0010 /* bidirectional mode */ -#define SIMPLE_WAVE_STEREO 0x0100 /* stereo wave */ -#define SIMPLE_WAVE_ULAW 0x0200 /* uLaw compression mode */ - -/* - * instrument effects - */ - -#define SIMPLE_EFFECT_NONE 0 -#define SIMPLE_EFFECT_REVERB 1 -#define SIMPLE_EFFECT_CHORUS 2 -#define SIMPLE_EFFECT_ECHO 3 - -/* - * instrument info - */ - -struct simple_instrument_info { - unsigned int format; /* supported format bits */ - unsigned int effects; /* supported effects (1 << SIMPLE_EFFECT_*) */ - unsigned int max8_len; /* maximum 8-bit wave length */ - unsigned int max16_len; /* maximum 16-bit wave length */ -}; - -/* - * Instrument - */ - -struct simple_instrument { - unsigned int share_id[4]; /* share id - zero = no sharing */ - unsigned int format; /* wave format */ - - struct { - unsigned int number; /* some other ID for this instrument */ - unsigned int memory; /* begin of waveform in onboard memory */ - unsigned char *ptr; /* pointer to waveform in system memory */ - } address; - - unsigned int size; /* size of waveform in samples */ - unsigned int start; /* start offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned int loop_start; /* loop start offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned int loop_end; /* loop end offset in samples * 16 (lowest 4 bits - fraction) */ - unsigned short loop_repeat; /* loop repeat - 0 = forever */ - - unsigned char effect1; /* effect 1 */ - unsigned char effect1_depth; /* 0-127 */ - unsigned char effect2; /* effect 2 */ - unsigned char effect2_depth; /* 0-127 */ -}; - -/* - * - * Kernel <-> user space - * Hardware (CPU) independent section - * - * * = zero or more - * + = one or more - * - * simple_xinstrument SIMPLE_STRU_INSTR - * - */ - -#define SIMPLE_STRU_INSTR __cpu_to_be32(('I'<<24)|('N'<<16)|('S'<<8)|'T') - -/* - * Instrument - */ - -struct simple_xinstrument { - __u32 stype; - - __u32 share_id[4]; /* share id - zero = no sharing */ - __u32 format; /* wave format */ - - __u32 size; /* size of waveform in samples */ - __u32 start; /* start offset in samples * 16 (lowest 4 bits - fraction) */ - __u32 loop_start; /* bits loop start offset in samples * 16 (lowest 4 bits - fraction) */ - __u32 loop_end; /* loop start offset in samples * 16 (lowest 4 bits - fraction) */ - __u16 loop_repeat; /* loop repeat - 0 = forever */ - - __u8 effect1; /* effect 1 */ - __u8 effect1_depth; /* 0-127 */ - __u8 effect2; /* effect 2 */ - __u8 effect2_depth; /* 0-127 */ -}; - -#ifdef __KERNEL__ - -#include "seq_instr.h" - -struct snd_simple_ops { - void *private_data; - int (*info)(void *private_data, struct simple_instrument_info *info); - int (*put_sample)(void *private_data, struct simple_instrument *instr, - char __user *data, long len, int atomic); - int (*get_sample)(void *private_data, struct simple_instrument *instr, - char __user *data, long len, int atomic); - int (*remove_sample)(void *private_data, struct simple_instrument *instr, - int atomic); - void (*notify)(void *private_data, struct snd_seq_kinstr *instr, int what); - struct snd_seq_kinstr_ops kops; -}; - -int snd_seq_simple_init(struct snd_simple_ops *ops, - void *private_data, - struct snd_seq_kinstr_ops *next); - -#endif - -/* typedefs for compatibility to user-space */ -typedef struct simple_xinstrument simple_xinstrument_t; - -#endif /* __SOUND_AINSTR_SIMPLE_H */ diff --git a/include/sound/asequencer.h b/include/sound/asequencer.h index 64daccb..1505e6d 100644 --- a/include/sound/asequencer.h +++ b/include/sound/asequencer.h @@ -110,18 +110,7 @@ #define SNDRV_SEQ_EVENT_PORT_SUBSCRIBED 66 /* ports connected */ #define SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED 67 /* ports disconnected */ -/** synthesizer events - * event data type = snd_seq_eve_sample_control - */ -#define SNDRV_SEQ_EVENT_SAMPLE 70 /* sample select */ -#define SNDRV_SEQ_EVENT_SAMPLE_CLUSTER 71 /* sample cluster select */ -#define SNDRV_SEQ_EVENT_SAMPLE_START 72 /* voice start */ -#define SNDRV_SEQ_EVENT_SAMPLE_STOP 73 /* voice stop */ -#define SNDRV_SEQ_EVENT_SAMPLE_FREQ 74 /* playback frequency */ -#define SNDRV_SEQ_EVENT_SAMPLE_VOLUME 75 /* volume and balance */ -#define SNDRV_SEQ_EVENT_SAMPLE_LOOP 76 /* sample loop */ -#define SNDRV_SEQ_EVENT_SAMPLE_POSITION 77 /* sample position */ -#define SNDRV_SEQ_EVENT_SAMPLE_PRIVATE1 78 /* private (hardware dependent) event */ +/* 70-89: synthesizer events - obsoleted */ /** user-defined events with fixed length * event data type = any @@ -137,28 +126,7 @@ #define SNDRV_SEQ_EVENT_USR8 98 #define SNDRV_SEQ_EVENT_USR9 99 -/** instrument layer - * variable length data can be passed directly to the driver - */ -#define SNDRV_SEQ_EVENT_INSTR_BEGIN 100 /* begin of instrument management */ -#define SNDRV_SEQ_EVENT_INSTR_END 101 /* end of instrument management */ -#define SNDRV_SEQ_EVENT_INSTR_INFO 102 /* instrument interface info */ -#define SNDRV_SEQ_EVENT_INSTR_INFO_RESULT 103 /* result */ -#define SNDRV_SEQ_EVENT_INSTR_FINFO 104 /* get format info */ -#define SNDRV_SEQ_EVENT_INSTR_FINFO_RESULT 105 /* get format info */ -#define SNDRV_SEQ_EVENT_INSTR_RESET 106 /* reset instrument memory */ -#define SNDRV_SEQ_EVENT_INSTR_STATUS 107 /* instrument interface status */ -#define SNDRV_SEQ_EVENT_INSTR_STATUS_RESULT 108 /* result */ -#define SNDRV_SEQ_EVENT_INSTR_PUT 109 /* put instrument to port */ -#define SNDRV_SEQ_EVENT_INSTR_GET 110 /* get instrument from port */ -#define SNDRV_SEQ_EVENT_INSTR_GET_RESULT 111 /* result */ -#define SNDRV_SEQ_EVENT_INSTR_FREE 112 /* free instrument(s) */ -#define SNDRV_SEQ_EVENT_INSTR_LIST 113 /* instrument list */ -#define SNDRV_SEQ_EVENT_INSTR_LIST_RESULT 114 /* result */ -#define SNDRV_SEQ_EVENT_INSTR_CLUSTER 115 /* cluster parameters */ -#define SNDRV_SEQ_EVENT_INSTR_CLUSTER_GET 116 /* get cluster parameters */ -#define SNDRV_SEQ_EVENT_INSTR_CLUSTER_RESULT 117 /* result */ -#define SNDRV_SEQ_EVENT_INSTR_CHANGE 118 /* instrument change */ +/* 100-118: instrument layer - obsoleted */ /* 119-129: reserved */ /* 130-139: variable length events @@ -258,78 +226,6 @@ struct snd_seq_ev_ext { void *ptr; /* pointer to data (note: maybe 64-bit) */ } __attribute__((packed)); -/* Instrument cluster type */ -typedef unsigned int snd_seq_instr_cluster_t; - -/* Instrument type */ -struct snd_seq_instr { - snd_seq_instr_cluster_t cluster; - unsigned int std; /* the upper byte means a private instrument (owner - client #) */ - unsigned short bank; - unsigned short prg; -}; - - /* sample number */ -struct snd_seq_ev_sample { - unsigned int std; - unsigned short bank; - unsigned short prg; -}; - - /* sample cluster */ -struct snd_seq_ev_cluster { - snd_seq_instr_cluster_t cluster; -}; - - /* sample position */ -typedef unsigned int snd_seq_position_t; /* playback position (in samples) * 16 */ - - /* sample stop mode */ -enum { - SAMPLE_STOP_IMMEDIATELY = 0, /* terminate playing immediately */ - SAMPLE_STOP_VENVELOPE = 1, /* finish volume envelope */ - SAMPLE_STOP_LOOP = 2 /* terminate loop and finish wave */ -}; - - /* sample frequency */ -typedef int snd_seq_frequency_t; /* playback frequency in HZ * 16 */ - - /* sample volume control; if any value is set to -1 == do not change */ -struct snd_seq_ev_volume { - signed short volume; /* range: 0-16383 */ - signed short lr; /* left-right balance; range: 0-16383 */ - signed short fr; /* front-rear balance; range: 0-16383 */ - signed short du; /* down-up balance; range: 0-16383 */ -}; - - /* simple loop redefinition */ -struct snd_seq_ev_loop { - unsigned int start; /* loop start (in samples) * 16 */ - unsigned int end; /* loop end (in samples) * 16 */ -}; - -struct snd_seq_ev_sample_control { - unsigned char channel; - unsigned char unused1, unused2, unused3; /* pad */ - union { - struct snd_seq_ev_sample sample; - struct snd_seq_ev_cluster cluster; - snd_seq_position_t position; - int stop_mode; - snd_seq_frequency_t frequency; - struct snd_seq_ev_volume volume; - struct snd_seq_ev_loop loop; - unsigned char raw8[8]; - } param; -}; - - - -/* INSTR_BEGIN event */ -struct snd_seq_ev_instr_begin { - int timeout; /* zero = forever, otherwise timeout in ms */ -}; - struct snd_seq_result { int event; /* processed event type */ int result; @@ -399,8 +295,6 @@ struct snd_seq_event { struct snd_seq_addr addr; struct snd_seq_connect connect; struct snd_seq_result result; - struct snd_seq_ev_instr_begin instr_begin; - struct snd_seq_ev_sample_control sample; struct snd_seq_ev_quote quote; } data; }; @@ -441,8 +335,6 @@ struct snd_seq_event_bounce { #define snd_seq_ev_is_user_type(ev) ((ev)->type >= 90 && (ev)->type < 99) /* fixed length events: 0-99 */ #define snd_seq_ev_is_fixed_type(ev) ((ev)->type < 100) -/* instrument layer events: 100-129 */ -#define snd_seq_ev_is_instr_type(ev) ((ev)->type >= 100 && (ev)->type < 130) /* variable length events: 130-139 */ #define snd_seq_ev_is_variable_type(ev) ((ev)->type >= 130 && (ev)->type < 140) /* reserved for kernel */ @@ -738,136 +630,6 @@ struct snd_seq_query_subs { /* - * Instrument abstraction layer - * - based on events - */ - -/* instrument types */ -#define SNDRV_SEQ_INSTR_ATYPE_DATA 0 /* instrument data */ -#define SNDRV_SEQ_INSTR_ATYPE_ALIAS 1 /* instrument alias */ - -/* instrument ASCII identifiers */ -#define SNDRV_SEQ_INSTR_ID_DLS1 "DLS1" -#define SNDRV_SEQ_INSTR_ID_DLS2 "DLS2" -#define SNDRV_SEQ_INSTR_ID_SIMPLE "Simple Wave" -#define SNDRV_SEQ_INSTR_ID_SOUNDFONT "SoundFont" -#define SNDRV_SEQ_INSTR_ID_GUS_PATCH "GUS Patch" -#define SNDRV_SEQ_INSTR_ID_INTERWAVE "InterWave FFFF" -#define SNDRV_SEQ_INSTR_ID_OPL2_3 "OPL2/3 FM" -#define SNDRV_SEQ_INSTR_ID_OPL4 "OPL4" - -/* instrument types */ -#define SNDRV_SEQ_INSTR_TYPE0_DLS1 (1<<0) /* MIDI DLS v1 */ -#define SNDRV_SEQ_INSTR_TYPE0_DLS2 (1<<1) /* MIDI DLS v2 */ -#define SNDRV_SEQ_INSTR_TYPE1_SIMPLE (1<<0) /* Simple Wave */ -#define SNDRV_SEQ_INSTR_TYPE1_SOUNDFONT (1<<1) /* EMU SoundFont */ -#define SNDRV_SEQ_INSTR_TYPE1_GUS_PATCH (1<<2) /* Gravis UltraSound Patch */ -#define SNDRV_SEQ_INSTR_TYPE1_INTERWAVE (1<<3) /* InterWave FFFF */ -#define SNDRV_SEQ_INSTR_TYPE2_OPL2_3 (1<<0) /* Yamaha OPL2/3 FM */ -#define SNDRV_SEQ_INSTR_TYPE2_OPL4 (1<<1) /* Yamaha OPL4 */ - -/* put commands */ -#define SNDRV_SEQ_INSTR_PUT_CMD_CREATE 0 -#define SNDRV_SEQ_INSTR_PUT_CMD_REPLACE 1 -#define SNDRV_SEQ_INSTR_PUT_CMD_MODIFY 2 -#define SNDRV_SEQ_INSTR_PUT_CMD_ADD 3 -#define SNDRV_SEQ_INSTR_PUT_CMD_REMOVE 4 - -/* get commands */ -#define SNDRV_SEQ_INSTR_GET_CMD_FULL 0 -#define SNDRV_SEQ_INSTR_GET_CMD_PARTIAL 1 - -/* query flags */ -#define SNDRV_SEQ_INSTR_QUERY_FOLLOW_ALIAS (1<<0) - -/* free commands */ -#define SNDRV_SEQ_INSTR_FREE_CMD_ALL 0 -#define SNDRV_SEQ_INSTR_FREE_CMD_PRIVATE 1 -#define SNDRV_SEQ_INSTR_FREE_CMD_CLUSTER 2 -#define SNDRV_SEQ_INSTR_FREE_CMD_SINGLE 3 - -/* size of ROM/RAM */ -typedef unsigned int snd_seq_instr_size_t; - -/* INSTR_INFO */ - -struct snd_seq_instr_info { - int result; /* operation result */ - unsigned int formats[8]; /* bitmap of supported formats */ - int ram_count; /* count of RAM banks */ - snd_seq_instr_size_t ram_sizes[16]; /* size of RAM banks */ - int rom_count; /* count of ROM banks */ - snd_seq_instr_size_t rom_sizes[8]; /* size of ROM banks */ - char reserved[128]; -}; - -/* INSTR_STATUS */ - -struct snd_seq_instr_status { - int result; /* operation result */ - snd_seq_instr_size_t free_ram[16]; /* free RAM in banks */ - int instrument_count; /* count of downloaded instruments */ - char reserved[128]; -}; - -/* INSTR_FORMAT_INFO */ - -struct snd_seq_instr_format_info { - char format[16]; /* format identifier - SNDRV_SEQ_INSTR_ID_* */ - unsigned int len; /* max data length (without this structure) */ -}; - -struct snd_seq_instr_format_info_result { - int result; /* operation result */ - char format[16]; /* format identifier */ - unsigned int len; /* filled data length (without this structure) */ -}; - -/* instrument data */ -struct snd_seq_instr_data { - char name[32]; /* instrument name */ - char reserved[16]; /* for the future use */ - int type; /* instrument type */ - union { - char format[16]; /* format identifier */ - struct snd_seq_instr alias; - } data; -}; - -/* INSTR_PUT/GET, data are stored in one block (extended), header + data */ - -struct snd_seq_instr_header { - union { - struct snd_seq_instr instr; - snd_seq_instr_cluster_t cluster; - } id; /* instrument identifier */ - unsigned int cmd; /* get/put/free command */ - unsigned int flags; /* query flags (only for get) */ - unsigned int len; /* real instrument data length (without header) */ - int result; /* operation result */ - char reserved[16]; /* for the future */ - struct snd_seq_instr_data data; /* instrument data (for put/get result) */ -}; - -/* INSTR_CLUSTER_SET */ - -struct snd_seq_instr_cluster_set { - snd_seq_instr_cluster_t cluster; /* cluster identifier */ - char name[32]; /* cluster name */ - int priority; /* cluster priority */ - char reserved[64]; /* for the future use */ -}; - -/* INSTR_CLUSTER_GET */ - -struct snd_seq_instr_cluster_get { - snd_seq_instr_cluster_t cluster; /* cluster identifier */ - char name[32]; /* cluster name */ - int priority; /* cluster priority */ - char reserved[64]; /* for the future use */ -}; - -/* * IOCTL commands */ diff --git a/include/sound/asound.h b/include/sound/asound.h index af9d11d..3ad5341 100644 --- a/include/sound/asound.h +++ b/include/sound/asound.h @@ -95,7 +95,7 @@ enum { SNDRV_HWDEP_IFACE_HDA, /* HD-audio */ /* Don't forget to change the following: */ - SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_SB_RC + SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_HDA }; struct snd_hwdep_info { diff --git a/include/sound/asound_fm.h b/include/sound/asound_fm.h index 8fbcab7..c2a4b96 100644 --- a/include/sound/asound_fm.h +++ b/include/sound/asound_fm.h @@ -104,6 +104,8 @@ struct snd_dm_fm_params { #define SNDRV_DM_FM_IOCTL_SET_MODE _IOW('H', 0x25, int) /* for OPL3 only */ #define SNDRV_DM_FM_IOCTL_SET_CONNECTION _IOW('H', 0x26, int) +/* SBI patch management */ +#define SNDRV_DM_FM_IOCTL_CLEAR_PATCHES _IO ('H', 0x40) #define SNDRV_DM_FM_OSS_IOCTL_RESET 0x20 #define SNDRV_DM_FM_OSS_IOCTL_PLAY_NOTE 0x21 @@ -112,4 +114,21 @@ struct snd_dm_fm_params { #define SNDRV_DM_FM_OSS_IOCTL_SET_MODE 0x24 #define SNDRV_DM_FM_OSS_IOCTL_SET_OPL 0x25 +/* + * Patch Record - fixed size for write + */ + +#define FM_KEY_SBI "SBI\032" +#define FM_KEY_2OP "2OP\032" +#define FM_KEY_4OP "4OP\032" + +struct sbi_patch { + unsigned char prog; + unsigned char bank; + char key[4]; + char name[25]; + char extension[7]; + unsigned char data[32]; +}; + #endif /* __SOUND_ASOUND_FM_H */ diff --git a/include/sound/cs46xx.h b/include/sound/cs46xx.h index 6b40ee6..e3005a6 100644 --- a/include/sound/cs46xx.h +++ b/include/sound/cs46xx.h @@ -1708,9 +1708,6 @@ struct snd_cs46xx { struct gameport *gameport; -#ifdef CONFIG_SND_CS46XX_DEBUG_GPIO - int current_gpio; -#endif #ifdef CONFIG_SND_CS46XX_NEW_DSP struct mutex spos_mutex; diff --git a/include/sound/driver.h b/include/sound/driver.h index 5ccb6c5..1889929 100644 --- a/include/sound/driver.h +++ b/include/sound/driver.h @@ -38,10 +38,6 @@ #define CONFIG_SND_MAJOR 116 #endif -#ifndef CONFIG_SND_DEBUG -#undef CONFIG_SND_DEBUG_MEMORY -#endif - #ifdef ALSA_BUILD #include "adriver.h" #endif diff --git a/include/sound/gus.h b/include/sound/gus.h index e5433d8..841bb8d 100644 --- a/include/sound/gus.h +++ b/include/sound/gus.h @@ -27,13 +27,8 @@ #include "timer.h" #include "seq_midi_emul.h" #include "seq_device.h" -#include "ainstr_iw.h" -#include "ainstr_gf1.h" -#include "ainstr_simple.h" #include -#define SNDRV_SEQ_DEV_ID_GUS "gus-synth" - /* IO ports */ #define GUSP(gus, x) ((gus)->gf1.port + SNDRV_g_u_s_##x) @@ -234,16 +229,6 @@ struct snd_gus_port { struct snd_gus_voice; -struct snd_gus_sample_ops { - void (*sample_start)(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_position_t position); - void (*sample_stop)(struct snd_gus_card *gus, struct snd_gus_voice *voice, int mode); - void (*sample_freq)(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_frequency_t freq); - void (*sample_volume)(struct snd_gus_card *gus, struct snd_gus_voice *voice, struct snd_seq_ev_volume *volume); - void (*sample_loop)(struct snd_gus_card *card, struct snd_gus_voice *voice, struct snd_seq_ev_loop *loop); - void (*sample_pos)(struct snd_gus_card *card, struct snd_gus_voice *voice, snd_seq_position_t position); - void (*sample_private1)(struct snd_gus_card *card, struct snd_gus_voice *voice, unsigned char *data); -}; - #define SNDRV_GF1_VOICE_TYPE_PCM 0 #define SNDRV_GF1_VOICE_TYPE_SYNTH 1 #define SNDRV_GF1_VOICE_TYPE_MIDI 2 @@ -284,12 +269,8 @@ struct snd_gus_voice { struct snd_gus_sample_ops *sample_ops; - struct snd_seq_instr instr; - /* running status / registers */ - struct snd_seq_ev_volume sample_volume; - unsigned short fc_register; unsigned short fc_lfo; unsigned short gf1_volume; @@ -382,10 +363,6 @@ struct snd_gf1 { int seq_client; struct snd_gus_port seq_ports[4]; - struct snd_seq_kinstr_list *ilist; - struct snd_iwffff_ops iwffff_ops; - struct snd_gf1_ops gf1_ops; - struct snd_simple_ops simple_ops; /* timer */ @@ -458,8 +435,6 @@ struct snd_gus_card { struct snd_rawmidi_substream *midi_substream_output; struct snd_rawmidi_substream *midi_substream_input; - struct snd_seq_device *seq_dev; - spinlock_t reg_lock; spinlock_t voice_alloc; spinlock_t active_voice_lock; @@ -647,48 +622,10 @@ void snd_gus_irq_profile_init(struct snd_gus_card *gus); int snd_gf1_rawmidi_new(struct snd_gus_card * gus, int device, struct snd_rawmidi **rrawmidi); -#if 0 -extern void snd_engine_instrument_register(unsigned short mode, - struct _SND_INSTRUMENT_VOICE_COMMANDS *voice_cmds, - struct _SND_INSTRUMENT_NOTE_COMMANDS *note_cmds, - struct _SND_INSTRUMENT_CHANNEL_COMMANDS *channel_cmds); -extern int snd_engine_instrument_register_ask(unsigned short mode); -#endif - /* gus_dram.c */ int snd_gus_dram_write(struct snd_gus_card *gus, char __user *ptr, unsigned int addr, unsigned int size); int snd_gus_dram_read(struct snd_gus_card *gus, char __user *ptr, unsigned int addr, unsigned int size, int rom); -#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE) - -/* gus_sample.c */ -void snd_gus_sample_event(struct snd_seq_event *ev, struct snd_gus_port *p); - -/* gus_simple.c */ -void snd_gf1_simple_init(struct snd_gus_voice *voice); - -/* gus_instr.c */ -int snd_gus_iwffff_put_sample(void *private_data, struct iwffff_wave *wave, - char __user *data, long len, int atomic); -int snd_gus_iwffff_get_sample(void *private_data, struct iwffff_wave *wave, - char __user *data, long len, int atomic); -int snd_gus_iwffff_remove_sample(void *private_data, struct iwffff_wave *wave, - int atomic); -int snd_gus_gf1_put_sample(void *private_data, struct gf1_wave *wave, - char __user *data, long len, int atomic); -int snd_gus_gf1_get_sample(void *private_data, struct gf1_wave *wave, - char __user *data, long len, int atomic); -int snd_gus_gf1_remove_sample(void *private_data, struct gf1_wave *wave, - int atomic); -int snd_gus_simple_put_sample(void *private_data, struct simple_instrument *instr, - char __user *data, long len, int atomic); -int snd_gus_simple_get_sample(void *private_data, struct simple_instrument *instr, - char __user *data, long len, int atomic); -int snd_gus_simple_remove_sample(void *private_data, struct simple_instrument *instr, - int atomic); - -#endif /* CONFIG_SND_SEQUENCER */ - #endif /* __SOUND_GUS_H */ diff --git a/include/sound/opl3.h b/include/sound/opl3.h index 1d14b3f..d7e33ce 100644 --- a/include/sound/opl3.h +++ b/include/sound/opl3.h @@ -63,7 +63,7 @@ #include "seq_oss_legacy.h" #endif #include "seq_device.h" -#include "ainstr_fm.h" +#include "asound_fm.h" /* * Register numbers for the global registers @@ -240,6 +240,47 @@ struct snd_opl3; /* + * Instrument record, aka "Patch" + */ + +/* FM operator */ +struct fm_operator { + unsigned char am_vib; + unsigned char ksl_level; + unsigned char attack_decay; + unsigned char sustain_release; + unsigned char wave_select; +} __attribute__((packed)); + +/* Instrument data */ +struct fm_instrument { + struct fm_operator op[4]; + unsigned char feedback_connection[2]; + unsigned char echo_delay; + unsigned char echo_atten; + unsigned char chorus_spread; + unsigned char trnsps; + unsigned char fix_dur; + unsigned char modes; + unsigned char fix_key; +}; + +/* type */ +#define FM_PATCH_OPL2 0x01 /* OPL2 2 operators FM instrument */ +#define FM_PATCH_OPL3 0x02 /* OPL3 4 operators FM instrument */ + +/* Instrument record */ +struct fm_patch { + unsigned char prog; + unsigned char bank; + unsigned char type; + struct fm_instrument inst; + char name[24]; + struct fm_patch *next; +}; + + +/* * A structure to keep track of each hardware voice */ struct snd_opl3_voice { @@ -277,9 +318,9 @@ struct snd_opl3 { void *private_data; void (*private_free)(struct snd_opl3 *); + struct snd_hwdep *hwdep; spinlock_t reg_lock; struct snd_card *card; /* The card that this belongs to */ - int used; /* usage flag - exclusive */ unsigned char fm_mode; /* OPL mode, see SNDRV_DM_FM_MODE_XXX */ unsigned char rhythm; /* percussion mode flag */ unsigned char max_voices; /* max number of voices */ @@ -297,8 +338,8 @@ struct snd_opl3 { struct snd_midi_channel_set * oss_chset; #endif - struct snd_seq_kinstr_ops fm_ops; - struct snd_seq_kinstr_list *ilist; +#define OPL3_PATCH_HASH_SIZE 32 + struct fm_patch *patch_table[OPL3_PATCH_HASH_SIZE]; struct snd_opl3_voice voices[MAX_OPL3_VOICES]; /* Voices (OPL3 'channel') */ int use_time; /* allocation counter */ @@ -312,7 +353,6 @@ struct snd_opl3 { int sys_timer_status; /* system timer run status */ spinlock_t sys_timer_lock; /* Lock for system timer access */ #endif - struct mutex access_mutex; /* locking */ }; /* opl3.c */ @@ -333,8 +373,19 @@ int snd_opl3_hwdep_new(struct snd_opl3 * opl3, int device, int seq_device, int snd_opl3_open(struct snd_hwdep * hw, struct file *file); int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file, unsigned int cmd, unsigned long arg); +long snd_opl3_write(struct snd_hwdep *hw, const char __user *buf, long count, + loff_t *offset); int snd_opl3_release(struct snd_hwdep * hw, struct file *file); void snd_opl3_reset(struct snd_opl3 * opl3); +int snd_opl3_load_patch(struct snd_opl3 *opl3, + int prog, int bank, int type, + const char *name, + const unsigned char *ext, + const unsigned char *data); +struct fm_patch *snd_opl3_find_patch(struct snd_opl3 *opl3, int prog, int bank, + int create_patch); +void snd_opl3_clear_patches(struct snd_opl3 *opl3); + #endif /* __SOUND_OPL3_H */ diff --git a/include/sound/seq_instr.h b/include/sound/seq_instr.h deleted file mode 100644 index 93b0c51..0000000 --- a/include/sound/seq_instr.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef __SOUND_SEQ_INSTR_H -#define __SOUND_SEQ_INSTR_H - -/* - * Main kernel header file for the ALSA sequencer - * Copyright (c) 1999 by Jaroslav Kysela - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -#include "seq_kernel.h" - -/* Instrument cluster */ -struct snd_seq_kcluster { - snd_seq_instr_cluster_t cluster; - char name[32]; - int priority; - struct snd_seq_kcluster *next; -}; - -/* return pointer to private data */ -#define KINSTR_DATA(kinstr) (void *)(((char *)kinstr) + sizeof(struct snd_seq_kinstr)) - -/* Instrument structure */ -struct snd_seq_kinstr { - struct snd_seq_instr instr; - char name[32]; - int type; /* instrument type */ - int use; /* use count */ - int busy; /* not useable */ - int add_len; /* additional length */ - struct snd_seq_kinstr_ops *ops; /* operations */ - struct snd_seq_kinstr *next; -}; - -#define SNDRV_SEQ_INSTR_HASH_SIZE 32 - -/* Instrument flags */ -#define SNDRV_SEQ_INSTR_FLG_DIRECT (1<<0) /* accept only direct events */ - -/* List of all instruments */ -struct snd_seq_kinstr_list { - struct snd_seq_kinstr *hash[SNDRV_SEQ_INSTR_HASH_SIZE]; - int count; /* count of all instruments */ - - struct snd_seq_kcluster *chash[SNDRV_SEQ_INSTR_HASH_SIZE]; - int ccount; /* count of all clusters */ - - int owner; /* current owner of the instrument list */ - unsigned int flags; - - spinlock_t lock; - spinlock_t ops_lock; - struct mutex ops_mutex; - unsigned long ops_flags; -}; - -#define SNDRV_SEQ_INSTR_NOTIFY_REMOVE 0 -#define SNDRV_SEQ_INSTR_NOTIFY_CHANGE 1 - -struct snd_seq_kinstr_ops { - void *private_data; - long add_len; /* additional length */ - char *instr_type; - int (*info)(void *private_data, char *info_data, long len); - int (*put)(void *private_data, struct snd_seq_kinstr *kinstr, - char __user *instr_data, long len, int atomic, int cmd); - int (*get)(void *private_data, struct snd_seq_kinstr *kinstr, - char __user *instr_data, long len, int atomic, int cmd); - int (*get_size)(void *private_data, struct snd_seq_kinstr *kinstr, long *size); - int (*remove)(void *private_data, struct snd_seq_kinstr *kinstr, int atomic); - void (*notify)(void *private_data, struct snd_seq_kinstr *kinstr, int what); - struct snd_seq_kinstr_ops *next; -}; - - -/* instrument operations */ -struct snd_seq_kinstr_list *snd_seq_instr_list_new(void); -void snd_seq_instr_list_free(struct snd_seq_kinstr_list **list); -int snd_seq_instr_list_free_cond(struct snd_seq_kinstr_list *list, - struct snd_seq_instr_header *ifree, - int client, - int atomic); -struct snd_seq_kinstr *snd_seq_instr_find(struct snd_seq_kinstr_list *list, - struct snd_seq_instr *instr, - int exact, - int follow_alias); -void snd_seq_instr_free_use(struct snd_seq_kinstr_list *list, - struct snd_seq_kinstr *instr); -int snd_seq_instr_event(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int client, - int atomic, - int hop); - -#endif /* __SOUND_SEQ_INSTR_H */ diff --git a/include/sound/trident.h b/include/sound/trident.h index 9752243..9f191a0 100644 --- a/include/sound/trident.h +++ b/include/sound/trident.h @@ -26,19 +26,12 @@ #include "pcm.h" #include "mpu401.h" #include "ac97_codec.h" -#include "seq_midi_emul.h" -#include "seq_device.h" #include "util_mem.h" -//#include "ainstr_iw.h" -//#include "ainstr_gf1.h" -#include "ainstr_simple.h" #define TRIDENT_DEVICE_ID_DX ((PCI_VENDOR_ID_TRIDENT<<16)|PCI_DEVICE_ID_TRIDENT_4DWAVE_DX) #define TRIDENT_DEVICE_ID_NX ((PCI_VENDOR_ID_TRIDENT<<16)|PCI_DEVICE_ID_TRIDENT_4DWAVE_NX) #define TRIDENT_DEVICE_ID_SI7018 ((PCI_VENDOR_ID_SI<<16)|PCI_DEVICE_ID_SI_7018) -#define SNDRV_SEQ_DEV_ID_TRIDENT "trident-synth" - #define SNDRV_TRIDENT_VOICE_TYPE_PCM 0 #define SNDRV_TRIDENT_VOICE_TYPE_SYNTH 1 #define SNDRV_TRIDENT_VOICE_TYPE_MIDI 2 @@ -257,16 +250,6 @@ struct snd_trident; struct snd_trident_voice; struct snd_trident_pcm_mixer; -struct snd_trident_sample_ops { - void (*sample_start)(struct snd_trident *gus, struct snd_trident_voice *voice, snd_seq_position_t position); - void (*sample_stop)(struct snd_trident *gus, struct snd_trident_voice *voice, int mode); - void (*sample_freq)(struct snd_trident *gus, struct snd_trident_voice *voice, snd_seq_frequency_t freq); - void (*sample_volume)(struct snd_trident *gus, struct snd_trident_voice *voice, struct snd_seq_ev_volume *volume); - void (*sample_loop)(struct snd_trident *card, struct snd_trident_voice *voice, struct snd_seq_ev_loop *loop); - void (*sample_pos)(struct snd_trident *card, struct snd_trident_voice *voice, snd_seq_position_t position); - void (*sample_private1)(struct snd_trident *card, struct snd_trident_voice *voice, unsigned char *data); -}; - struct snd_trident_port { struct snd_midi_channel_set * chset; struct snd_trident * trident; @@ -300,7 +283,6 @@ struct snd_trident_voice { unsigned char port; unsigned char index; - struct snd_seq_instr instr; struct snd_trident_sample_ops *sample_ops; /* channel parameters */ @@ -354,9 +336,6 @@ struct snd_4dwave { int seq_client; struct snd_trident_port seq_ports[4]; - struct snd_simple_ops simple_ops; - struct snd_seq_kinstr_list *ilist; - struct snd_trident_voice voices[64]; int ChanSynthCount; /* number of allocated synth channels */ @@ -416,7 +395,6 @@ struct snd_trident { struct snd_pcm *foldback; /* Foldback PCM */ struct snd_pcm *spdif; /* SPDIF PCM */ struct snd_rawmidi *rmidi; - struct snd_seq_device *seq_dev; struct snd_ac97_bus *ac97_bus; struct snd_ac97 *ac97; diff --git a/sound/aoa/codecs/snd-aoa-codec-onyx.c b/sound/aoa/codecs/snd-aoa-codec-onyx.c index 71e3f93..6a3837d 100644 --- a/sound/aoa/codecs/snd-aoa-codec-onyx.c +++ b/sound/aoa/codecs/snd-aoa-codec-onyx.c @@ -138,6 +138,13 @@ static int onyx_snd_vol_put(struct snd_kcontrol *kcontrol, struct onyx *onyx = snd_kcontrol_chip(kcontrol); s8 l, r; + if (ucontrol->value.integer.value[0] < -128 + VOLUME_RANGE_SHIFT || + ucontrol->value.integer.value[0] > -1 + VOLUME_RANGE_SHIFT) + return -EINVAL; + if (ucontrol->value.integer.value[1] < -128 + VOLUME_RANGE_SHIFT || + ucontrol->value.integer.value[1] > -1 + VOLUME_RANGE_SHIFT) + return -EINVAL; + mutex_lock(&onyx->mutex); onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_LEFT, &l); onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_RIGHT, &r); @@ -206,6 +213,9 @@ static int onyx_snd_inputgain_put(struct snd_kcontrol *kcontrol, struct onyx *onyx = snd_kcontrol_chip(kcontrol); u8 v, n; + if (ucontrol->value.integer.value[0] < 3 + INPUTGAIN_RANGE_SHIFT || + ucontrol->value.integer.value[0] > 28 + INPUTGAIN_RANGE_SHIFT) + return -EINVAL; mutex_lock(&onyx->mutex); onyx_read_register(onyx, ONYX_REG_ADC_CONTROL, &v); n = v; @@ -272,6 +282,8 @@ static void onyx_set_capture_source(struct onyx *onyx, int mic) static int onyx_snd_capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { + if (ucontrol->value.enumerated.item[0] > 1) + return -EINVAL; onyx_set_capture_source(snd_kcontrol_chip(kcontrol), ucontrol->value.enumerated.item[0]); return 1; diff --git a/sound/aoa/codecs/snd-aoa-codec-tas.c b/sound/aoa/codecs/snd-aoa-codec-tas.c index 70c3416..7a16a33 100644 --- a/sound/aoa/codecs/snd-aoa-codec-tas.c +++ b/sound/aoa/codecs/snd-aoa-codec-tas.c @@ -248,6 +248,13 @@ static int tas_snd_vol_put(struct snd_kcontrol *kcontrol, { struct tas *tas = snd_kcontrol_chip(kcontrol); + if (ucontrol->value.integer.value[0] < 0 || + ucontrol->value.integer.value[0] > 177) + return -EINVAL; + if (ucontrol->value.integer.value[1] < 0 || + ucontrol->value.integer.value[1] > 177) + return -EINVAL; + mutex_lock(&tas->mtx); if (tas->cached_volume_l == ucontrol->value.integer.value[0] && tas->cached_volume_r == ucontrol->value.integer.value[1]) { @@ -401,6 +408,10 @@ static int tas_snd_drc_range_put(struct snd_kcontrol *kcontrol, { struct tas *tas = snd_kcontrol_chip(kcontrol); + if (ucontrol->value.integer.value[0] < 0 || + ucontrol->value.integer.value[0] > TAS3004_DRC_MAX) + return -EINVAL; + mutex_lock(&tas->mtx); if (tas->drc_range == ucontrol->value.integer.value[0]) { mutex_unlock(&tas->mtx); @@ -447,7 +458,7 @@ static int tas_snd_drc_switch_put(struct snd_kcontrol *kcontrol, return 0; } - tas->drc_enabled = ucontrol->value.integer.value[0]; + tas->drc_enabled = !!ucontrol->value.integer.value[0]; if (tas->hw_enabled) tas3004_set_drc(tas); mutex_unlock(&tas->mtx); @@ -494,6 +505,8 @@ static int tas_snd_capture_source_put(struct snd_kcontrol *kcontrol, struct tas *tas = snd_kcontrol_chip(kcontrol); int oldacr; + if (ucontrol->value.enumerated.item[0] > 1) + return -EINVAL; mutex_lock(&tas->mtx); oldacr = tas->acr; @@ -562,6 +575,9 @@ static int tas_snd_treble_put(struct snd_kcontrol *kcontrol, { struct tas *tas = snd_kcontrol_chip(kcontrol); + if (ucontrol->value.integer.value[0] < TAS3004_TREBLE_MIN || + ucontrol->value.integer.value[0] > TAS3004_TREBLE_MAX) + return -EINVAL; mutex_lock(&tas->mtx); if (tas->treble == ucontrol->value.integer.value[0]) { mutex_unlock(&tas->mtx); @@ -610,6 +626,9 @@ static int tas_snd_bass_put(struct snd_kcontrol *kcontrol, { struct tas *tas = snd_kcontrol_chip(kcontrol); + if (ucontrol->value.integer.value[0] < TAS3004_BASS_MIN || + ucontrol->value.integer.value[0] > TAS3004_BASS_MAX) + return -EINVAL; mutex_lock(&tas->mtx); if (tas->bass == ucontrol->value.integer.value[0]) { mutex_unlock(&tas->mtx); diff --git a/sound/aoa/fabrics/snd-aoa-fabric-layout.c b/sound/aoa/fabrics/snd-aoa-fabric-layout.c index 8b2ba99..dea7abb 100644 --- a/sound/aoa/fabrics/snd-aoa-fabric-layout.c +++ b/sound/aoa/fabrics/snd-aoa-fabric-layout.c @@ -600,7 +600,7 @@ static int n##_control_put(struct snd_kcontrol *kcontrol, \ struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \ if (gpio->methods && gpio->methods->get_##n) \ gpio->methods->set_##n(gpio, \ - ucontrol->value.integer.value[0]); \ + !!ucontrol->value.integer.value[0]); \ return 1; \ } \ static struct snd_kcontrol_new n##_ctl = { \ diff --git a/sound/core/init.c b/sound/core/init.c index 2cb7099..48d38a7 100644 --- a/sound/core/init.c +++ b/sound/core/init.c @@ -43,6 +43,40 @@ EXPORT_SYMBOL(snd_cards); static DEFINE_MUTEX(snd_card_mutex); +static char *slots[SNDRV_CARDS]; +module_param_array(slots, charp, NULL, 0444); +MODULE_PARM_DESC(slots, "Module names assigned to the slots."); + +/* return non-zero if the given index is already reserved for another + * module via slots option + */ +static int module_slot_mismatch(struct module *module, int idx) +{ +#ifdef MODULE + char *s1, *s2; + if (!module || !module->name || !slots[idx]) + return 0; + s1 = slots[idx]; + s2 = module->name; + /* compare module name strings + * hyphens are handled as equivalent with underscore + */ + for (;;) { + char c1 = *s1++; + char c2 = *s2++; + if (c1 == '-') + c1 = '_'; + if (c2 == '-') + c2 = '_'; + if (c1 != c2) + return 1; + if (!c1) + break; + } +#endif + return 0; +} + #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag); EXPORT_SYMBOL(snd_mixer_oss_notify_callback); @@ -115,6 +149,8 @@ struct snd_card *snd_card_new(int idx, const char *xid, for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) /* idx == -1 == 0xffff means: take any free slot */ if (~snd_cards_lock & idx & 1<= snd_ecards_limit) snd_ecards_limit = idx + 1; diff --git a/sound/core/seq/Makefile b/sound/core/seq/Makefile index ceef14a..0695937 100644 --- a/sound/core/seq/Makefile +++ b/sound/core/seq/Makefile @@ -3,7 +3,6 @@ # Copyright (c) 1999 by Jaroslav Kysela # -obj-$(CONFIG_SND) += instr/ ifeq ($(CONFIG_SND_SEQUENCER_OSS),y) obj-$(CONFIG_SND_SEQUENCER) += oss/ endif @@ -15,7 +14,6 @@ snd-seq-objs := seq.o seq_lock.o seq_clientmgr.o seq_memory.o seq_queue.o \ snd-seq-midi-objs := seq_midi.o snd-seq-midi-emul-objs := seq_midi_emul.o snd-seq-midi-event-objs := seq_midi_event.o -snd-seq-instr-objs := seq_instr.o snd-seq-dummy-objs := seq_dummy.o snd-seq-virmidi-objs := seq_virmidi.o @@ -36,9 +34,7 @@ obj-$(CONFIG_SND_SEQ_DUMMY) += snd-seq-dummy.o # Toplevel Module Dependency obj-$(CONFIG_SND_VIRMIDI) += snd-seq-virmidi.o snd-seq-midi-event.o obj-$(call sequencer,$(CONFIG_SND_RAWMIDI)) += snd-seq-midi.o snd-seq-midi-event.o -obj-$(call sequencer,$(CONFIG_SND_OPL3_LIB)) += snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o -obj-$(call sequencer,$(CONFIG_SND_OPL4_LIB)) += snd-seq-midi-event.o snd-seq-midi-emul.o snd-seq-instr.o -obj-$(call sequencer,$(CONFIG_SND_GUS_SYNTH)) += snd-seq-midi-emul.o snd-seq-instr.o +obj-$(call sequencer,$(CONFIG_SND_OPL3_LIB)) += snd-seq-midi-event.o snd-seq-midi-emul.o +obj-$(call sequencer,$(CONFIG_SND_OPL4_LIB)) += snd-seq-midi-event.o snd-seq-midi-emul.o obj-$(call sequencer,$(CONFIG_SND_SBAWE)) += snd-seq-midi-emul.o snd-seq-virmidi.o obj-$(call sequencer,$(CONFIG_SND_EMU10K1)) += snd-seq-midi-emul.o snd-seq-virmidi.o -obj-$(call sequencer,$(CONFIG_SND_TRIDENT)) += snd-seq-midi-emul.o snd-seq-instr.o diff --git a/sound/core/seq/instr/Makefile b/sound/core/seq/instr/Makefile deleted file mode 100644 index 6089603..0000000 --- a/sound/core/seq/instr/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# -# Makefile for ALSA -# Copyright (c) 1999 by Jaroslav Kysela -# - -snd-ainstr-fm-objs := ainstr_fm.o -snd-ainstr-simple-objs := ainstr_simple.o -snd-ainstr-gf1-objs := ainstr_gf1.o -snd-ainstr-iw-objs := ainstr_iw.o - -# -# this function returns: -# "m" - CONFIG_SND_SEQUENCER is m -# - CONFIG_SND_SEQUENCER is undefined -# otherwise parameter #1 value -# -sequencer = $(if $(subst y,,$(CONFIG_SND_SEQUENCER)),$(if $(1),m),$(if $(CONFIG_SND_SEQUENCER),$(1))) - -# Toplevel Module Dependency -obj-$(call sequencer,$(CONFIG_SND_OPL3_LIB)) += snd-ainstr-fm.o -obj-$(call sequencer,$(CONFIG_SND_OPL4_LIB)) += snd-ainstr-fm.o -obj-$(call sequencer,$(CONFIG_SND_GUS_SYNTH)) += snd-ainstr-gf1.o snd-ainstr-simple.o snd-ainstr-iw.o -obj-$(call sequencer,$(CONFIG_SND_TRIDENT)) += snd-ainstr-simple.o diff --git a/sound/core/seq/instr/ainstr_fm.c b/sound/core/seq/instr/ainstr_fm.c deleted file mode 100644 index f80fab8..0000000 --- a/sound/core/seq/instr/ainstr_fm.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * FM (OPL2/3) Instrument routines - * Copyright (c) 2000 Uros Bizjak - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include - -MODULE_AUTHOR("Uros Bizjak "); -MODULE_DESCRIPTION("Advanced Linux Sound Architecture FM Instrument support."); -MODULE_LICENSE("GPL"); - -static int snd_seq_fm_put(void *private_data, struct snd_seq_kinstr *instr, - char __user *instr_data, long len, int atomic, int cmd) -{ - struct fm_instrument *ip; - struct fm_xinstrument ix; - int idx; - - if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE) - return -EINVAL; - /* copy instrument data */ - if (len < (long)sizeof(ix)) - return -EINVAL; - if (copy_from_user(&ix, instr_data, sizeof(ix))) - return -EFAULT; - if (ix.stype != FM_STRU_INSTR) - return -EINVAL; - ip = (struct fm_instrument *)KINSTR_DATA(instr); - ip->share_id[0] = le32_to_cpu(ix.share_id[0]); - ip->share_id[1] = le32_to_cpu(ix.share_id[1]); - ip->share_id[2] = le32_to_cpu(ix.share_id[2]); - ip->share_id[3] = le32_to_cpu(ix.share_id[3]); - ip->type = ix.type; - for (idx = 0; idx < 4; idx++) { - ip->op[idx].am_vib = ix.op[idx].am_vib; - ip->op[idx].ksl_level = ix.op[idx].ksl_level; - ip->op[idx].attack_decay = ix.op[idx].attack_decay; - ip->op[idx].sustain_release = ix.op[idx].sustain_release; - ip->op[idx].wave_select = ix.op[idx].wave_select; - } - for (idx = 0; idx < 2; idx++) { - ip->feedback_connection[idx] = ix.feedback_connection[idx]; - } - ip->echo_delay = ix.echo_delay; - ip->echo_atten = ix.echo_atten; - ip->chorus_spread = ix.chorus_spread; - ip->trnsps = ix.trnsps; - ip->fix_dur = ix.fix_dur; - ip->modes = ix.modes; - ip->fix_key = ix.fix_key; - return 0; -} - -static int snd_seq_fm_get(void *private_data, struct snd_seq_kinstr *instr, - char __user *instr_data, long len, int atomic, - int cmd) -{ - struct fm_instrument *ip; - struct fm_xinstrument ix; - int idx; - - if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL) - return -EINVAL; - if (len < (long)sizeof(ix)) - return -ENOMEM; - memset(&ix, 0, sizeof(ix)); - ip = (struct fm_instrument *)KINSTR_DATA(instr); - ix.stype = FM_STRU_INSTR; - ix.share_id[0] = cpu_to_le32(ip->share_id[0]); - ix.share_id[1] = cpu_to_le32(ip->share_id[1]); - ix.share_id[2] = cpu_to_le32(ip->share_id[2]); - ix.share_id[3] = cpu_to_le32(ip->share_id[3]); - ix.type = ip->type; - for (idx = 0; idx < 4; idx++) { - ix.op[idx].am_vib = ip->op[idx].am_vib; - ix.op[idx].ksl_level = ip->op[idx].ksl_level; - ix.op[idx].attack_decay = ip->op[idx].attack_decay; - ix.op[idx].sustain_release = ip->op[idx].sustain_release; - ix.op[idx].wave_select = ip->op[idx].wave_select; - } - for (idx = 0; idx < 2; idx++) { - ix.feedback_connection[idx] = ip->feedback_connection[idx]; - } - if (copy_to_user(instr_data, &ix, sizeof(ix))) - return -EFAULT; - ix.echo_delay = ip->echo_delay; - ix.echo_atten = ip->echo_atten; - ix.chorus_spread = ip->chorus_spread; - ix.trnsps = ip->trnsps; - ix.fix_dur = ip->fix_dur; - ix.modes = ip->modes; - ix.fix_key = ip->fix_key; - return 0; -} - -static int snd_seq_fm_get_size(void *private_data, struct snd_seq_kinstr *instr, - long *size) -{ - *size = sizeof(struct fm_xinstrument); - return 0; -} - -int snd_seq_fm_init(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_ops *next) -{ - memset(ops, 0, sizeof(*ops)); - // ops->private_data = private_data; - ops->add_len = sizeof(struct fm_instrument); - ops->instr_type = SNDRV_SEQ_INSTR_ID_OPL2_3; - ops->put = snd_seq_fm_put; - ops->get = snd_seq_fm_get; - ops->get_size = snd_seq_fm_get_size; - // ops->remove = snd_seq_fm_remove; - // ops->notify = snd_seq_fm_notify; - ops->next = next; - return 0; -} - -/* - * Init part - */ - -static int __init alsa_ainstr_fm_init(void) -{ - return 0; -} - -static void __exit alsa_ainstr_fm_exit(void) -{ -} - -module_init(alsa_ainstr_fm_init) -module_exit(alsa_ainstr_fm_exit) - -EXPORT_SYMBOL(snd_seq_fm_init); diff --git a/sound/core/seq/instr/ainstr_gf1.c b/sound/core/seq/instr/ainstr_gf1.c deleted file mode 100644 index 4940026..0000000 --- a/sound/core/seq/instr/ainstr_gf1.c +++ /dev/null @@ -1,359 +0,0 @@ -/* - * GF1 (GUS) Patch - Instrument routines - * Copyright (c) 1999 by Jaroslav Kysela - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include -#include - -MODULE_AUTHOR("Jaroslav Kysela "); -MODULE_DESCRIPTION("Advanced Linux Sound Architecture GF1 (GUS) Patch support."); -MODULE_LICENSE("GPL"); - -static unsigned int snd_seq_gf1_size(unsigned int size, unsigned int format) -{ - unsigned int result = size; - - if (format & GF1_WAVE_16BIT) - result <<= 1; - if (format & GF1_WAVE_STEREO) - result <<= 1; - return format; -} - -static int snd_seq_gf1_copy_wave_from_stream(struct snd_gf1_ops *ops, - struct gf1_instrument *ip, - char __user **data, - long *len, - int atomic) -{ - struct gf1_wave *wp, *prev; - struct gf1_xwave xp; - int err; - gfp_t gfp_mask; - unsigned int real_size; - - gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; - if (*len < (long)sizeof(xp)) - return -EINVAL; - if (copy_from_user(&xp, *data, sizeof(xp))) - return -EFAULT; - *data += sizeof(xp); - *len -= sizeof(xp); - wp = kzalloc(sizeof(*wp), gfp_mask); - if (wp == NULL) - return -ENOMEM; - wp->share_id[0] = le32_to_cpu(xp.share_id[0]); - wp->share_id[1] = le32_to_cpu(xp.share_id[1]); - wp->share_id[2] = le32_to_cpu(xp.share_id[2]); - wp->share_id[3] = le32_to_cpu(xp.share_id[3]); - wp->format = le32_to_cpu(xp.format); - wp->size = le32_to_cpu(xp.size); - wp->start = le32_to_cpu(xp.start); - wp->loop_start = le32_to_cpu(xp.loop_start); - wp->loop_end = le32_to_cpu(xp.loop_end); - wp->loop_repeat = le16_to_cpu(xp.loop_repeat); - wp->flags = xp.flags; - wp->sample_rate = le32_to_cpu(xp.sample_rate); - wp->low_frequency = le32_to_cpu(xp.low_frequency); - wp->high_frequency = le32_to_cpu(xp.high_frequency); - wp->root_frequency = le32_to_cpu(xp.root_frequency); - wp->tune = le16_to_cpu(xp.tune); - wp->balance = xp.balance; - memcpy(wp->envelope_rate, xp.envelope_rate, 6); - memcpy(wp->envelope_offset, xp.envelope_offset, 6); - wp->tremolo_sweep = xp.tremolo_sweep; - wp->tremolo_rate = xp.tremolo_rate; - wp->tremolo_depth = xp.tremolo_depth; - wp->vibrato_sweep = xp.vibrato_sweep; - wp->vibrato_rate = xp.vibrato_rate; - wp->vibrato_depth = xp.vibrato_depth; - wp->scale_frequency = le16_to_cpu(xp.scale_frequency); - wp->scale_factor = le16_to_cpu(xp.scale_factor); - real_size = snd_seq_gf1_size(wp->size, wp->format); - if ((long)real_size > *len) { - kfree(wp); - return -ENOMEM; - } - if (ops->put_sample) { - err = ops->put_sample(ops->private_data, wp, - *data, real_size, atomic); - if (err < 0) { - kfree(wp); - return err; - } - } - *data += real_size; - *len -= real_size; - prev = ip->wave; - if (prev) { - while (prev->next) prev = prev->next; - prev->next = wp; - } else { - ip->wave = wp; - } - return 0; -} - -static void snd_seq_gf1_wave_free(struct snd_gf1_ops *ops, - struct gf1_wave *wave, - int atomic) -{ - if (ops->remove_sample) - ops->remove_sample(ops->private_data, wave, atomic); - kfree(wave); -} - -static void snd_seq_gf1_instr_free(struct snd_gf1_ops *ops, - struct gf1_instrument *ip, - int atomic) -{ - struct gf1_wave *wave; - - while ((wave = ip->wave) != NULL) { - ip->wave = wave->next; - snd_seq_gf1_wave_free(ops, wave, atomic); - } -} - -static int snd_seq_gf1_put(void *private_data, struct snd_seq_kinstr *instr, - char __user *instr_data, long len, int atomic, - int cmd) -{ - struct snd_gf1_ops *ops = private_data; - struct gf1_instrument *ip; - struct gf1_xinstrument ix; - int err; - gfp_t gfp_mask; - - if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE) - return -EINVAL; - gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; - /* copy instrument data */ - if (len < (long)sizeof(ix)) - return -EINVAL; - if (copy_from_user(&ix, instr_data, sizeof(ix))) - return -EFAULT; - if (ix.stype != GF1_STRU_INSTR) - return -EINVAL; - instr_data += sizeof(ix); - len -= sizeof(ix); - ip = (struct gf1_instrument *)KINSTR_DATA(instr); - ip->exclusion = le16_to_cpu(ix.exclusion); - ip->exclusion_group = le16_to_cpu(ix.exclusion_group); - ip->effect1 = ix.effect1; - ip->effect1_depth = ix.effect1_depth; - ip->effect2 = ix.effect2; - ip->effect2_depth = ix.effect2_depth; - /* copy layers */ - while (len > (long)sizeof(__u32)) { - __u32 stype; - - if (copy_from_user(&stype, instr_data, sizeof(stype))) - return -EFAULT; - if (stype != GF1_STRU_WAVE) { - snd_seq_gf1_instr_free(ops, ip, atomic); - return -EINVAL; - } - err = snd_seq_gf1_copy_wave_from_stream(ops, - ip, - &instr_data, - &len, - atomic); - if (err < 0) { - snd_seq_gf1_instr_free(ops, ip, atomic); - return err; - } - } - return 0; -} - -static int snd_seq_gf1_copy_wave_to_stream(struct snd_gf1_ops *ops, - struct gf1_instrument *ip, - char __user **data, - long *len, - int atomic) -{ - struct gf1_wave *wp; - struct gf1_xwave xp; - int err; - unsigned int real_size; - - for (wp = ip->wave; wp; wp = wp->next) { - if (*len < (long)sizeof(xp)) - return -ENOMEM; - memset(&xp, 0, sizeof(xp)); - xp.stype = GF1_STRU_WAVE; - xp.share_id[0] = cpu_to_le32(wp->share_id[0]); - xp.share_id[1] = cpu_to_le32(wp->share_id[1]); - xp.share_id[2] = cpu_to_le32(wp->share_id[2]); - xp.share_id[3] = cpu_to_le32(wp->share_id[3]); - xp.format = cpu_to_le32(wp->format); - xp.size = cpu_to_le32(wp->size); - xp.start = cpu_to_le32(wp->start); - xp.loop_start = cpu_to_le32(wp->loop_start); - xp.loop_end = cpu_to_le32(wp->loop_end); - xp.loop_repeat = cpu_to_le32(wp->loop_repeat); - xp.flags = wp->flags; - xp.sample_rate = cpu_to_le32(wp->sample_rate); - xp.low_frequency = cpu_to_le32(wp->low_frequency); - xp.high_frequency = cpu_to_le32(wp->high_frequency); - xp.root_frequency = cpu_to_le32(wp->root_frequency); - xp.tune = cpu_to_le16(wp->tune); - xp.balance = wp->balance; - memcpy(xp.envelope_rate, wp->envelope_rate, 6); - memcpy(xp.envelope_offset, wp->envelope_offset, 6); - xp.tremolo_sweep = wp->tremolo_sweep; - xp.tremolo_rate = wp->tremolo_rate; - xp.tremolo_depth = wp->tremolo_depth; - xp.vibrato_sweep = wp->vibrato_sweep; - xp.vibrato_rate = wp->vibrato_rate; - xp.vibrato_depth = wp->vibrato_depth; - xp.scale_frequency = cpu_to_le16(wp->scale_frequency); - xp.scale_factor = cpu_to_le16(wp->scale_factor); - if (copy_to_user(*data, &xp, sizeof(xp))) - return -EFAULT; - *data += sizeof(xp); - *len -= sizeof(xp); - real_size = snd_seq_gf1_size(wp->size, wp->format); - if (*len < (long)real_size) - return -ENOMEM; - if (ops->get_sample) { - err = ops->get_sample(ops->private_data, wp, - *data, real_size, atomic); - if (err < 0) - return err; - } - *data += wp->size; - *len -= wp->size; - } - return 0; -} - -static int snd_seq_gf1_get(void *private_data, struct snd_seq_kinstr *instr, - char __user *instr_data, long len, int atomic, - int cmd) -{ - struct snd_gf1_ops *ops = private_data; - struct gf1_instrument *ip; - struct gf1_xinstrument ix; - - if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL) - return -EINVAL; - if (len < (long)sizeof(ix)) - return -ENOMEM; - memset(&ix, 0, sizeof(ix)); - ip = (struct gf1_instrument *)KINSTR_DATA(instr); - ix.stype = GF1_STRU_INSTR; - ix.exclusion = cpu_to_le16(ip->exclusion); - ix.exclusion_group = cpu_to_le16(ip->exclusion_group); - ix.effect1 = cpu_to_le16(ip->effect1); - ix.effect1_depth = cpu_to_le16(ip->effect1_depth); - ix.effect2 = ip->effect2; - ix.effect2_depth = ip->effect2_depth; - if (copy_to_user(instr_data, &ix, sizeof(ix))) - return -EFAULT; - instr_data += sizeof(ix); - len -= sizeof(ix); - return snd_seq_gf1_copy_wave_to_stream(ops, - ip, - &instr_data, - &len, - atomic); -} - -static int snd_seq_gf1_get_size(void *private_data, struct snd_seq_kinstr *instr, - long *size) -{ - long result; - struct gf1_instrument *ip; - struct gf1_wave *wp; - - *size = 0; - ip = (struct gf1_instrument *)KINSTR_DATA(instr); - result = sizeof(struct gf1_xinstrument); - for (wp = ip->wave; wp; wp = wp->next) { - result += sizeof(struct gf1_xwave); - result += wp->size; - } - *size = result; - return 0; -} - -static int snd_seq_gf1_remove(void *private_data, - struct snd_seq_kinstr *instr, - int atomic) -{ - struct snd_gf1_ops *ops = private_data; - struct gf1_instrument *ip; - - ip = (struct gf1_instrument *)KINSTR_DATA(instr); - snd_seq_gf1_instr_free(ops, ip, atomic); - return 0; -} - -static void snd_seq_gf1_notify(void *private_data, - struct snd_seq_kinstr *instr, - int what) -{ - struct snd_gf1_ops *ops = private_data; - - if (ops->notify) - ops->notify(ops->private_data, instr, what); -} - -int snd_seq_gf1_init(struct snd_gf1_ops *ops, - void *private_data, - struct snd_seq_kinstr_ops *next) -{ - memset(ops, 0, sizeof(*ops)); - ops->private_data = private_data; - ops->kops.private_data = ops; - ops->kops.add_len = sizeof(struct gf1_instrument); - ops->kops.instr_type = SNDRV_SEQ_INSTR_ID_GUS_PATCH; - ops->kops.put = snd_seq_gf1_put; - ops->kops.get = snd_seq_gf1_get; - ops->kops.get_size = snd_seq_gf1_get_size; - ops->kops.remove = snd_seq_gf1_remove; - ops->kops.notify = snd_seq_gf1_notify; - ops->kops.next = next; - return 0; -} - -/* - * Init part - */ - -static int __init alsa_ainstr_gf1_init(void) -{ - return 0; -} - -static void __exit alsa_ainstr_gf1_exit(void) -{ -} - -module_init(alsa_ainstr_gf1_init) -module_exit(alsa_ainstr_gf1_exit) - -EXPORT_SYMBOL(snd_seq_gf1_init); diff --git a/sound/core/seq/instr/ainstr_iw.c b/sound/core/seq/instr/ainstr_iw.c deleted file mode 100644 index 6c40eb7..0000000 --- a/sound/core/seq/instr/ainstr_iw.c +++ /dev/null @@ -1,623 +0,0 @@ -/* - * IWFFFF - AMD InterWave (tm) - Instrument routines - * Copyright (c) 1999 by Jaroslav Kysela - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include -#include - -MODULE_AUTHOR("Jaroslav Kysela "); -MODULE_DESCRIPTION("Advanced Linux Sound Architecture IWFFFF support."); -MODULE_LICENSE("GPL"); - -static unsigned int snd_seq_iwffff_size(unsigned int size, unsigned int format) -{ - unsigned int result = size; - - if (format & IWFFFF_WAVE_16BIT) - result <<= 1; - if (format & IWFFFF_WAVE_STEREO) - result <<= 1; - return result; -} - -static void snd_seq_iwffff_copy_lfo_from_stream(struct iwffff_lfo *fp, - struct iwffff_xlfo *fx) -{ - fp->freq = le16_to_cpu(fx->freq); - fp->depth = le16_to_cpu(fx->depth); - fp->sweep = le16_to_cpu(fx->sweep); - fp->shape = fx->shape; - fp->delay = fx->delay; -} - -static int snd_seq_iwffff_copy_env_from_stream(__u32 req_stype, - struct iwffff_layer *lp, - struct iwffff_env *ep, - struct iwffff_xenv *ex, - char __user **data, - long *len, - gfp_t gfp_mask) -{ - __u32 stype; - struct iwffff_env_record *rp, *rp_last; - struct iwffff_xenv_record rx; - struct iwffff_env_point *pp; - struct iwffff_xenv_point px; - int points_size, idx; - - ep->flags = ex->flags; - ep->mode = ex->mode; - ep->index = ex->index; - rp_last = NULL; - while (1) { - if (*len < (long)sizeof(__u32)) - return -EINVAL; - if (copy_from_user(&stype, *data, sizeof(stype))) - return -EFAULT; - if (stype == IWFFFF_STRU_WAVE) - return 0; - if (req_stype != stype) { - if (stype == IWFFFF_STRU_ENV_RECP || - stype == IWFFFF_STRU_ENV_RECV) - return 0; - } - if (*len < (long)sizeof(rx)) - return -EINVAL; - if (copy_from_user(&rx, *data, sizeof(rx))) - return -EFAULT; - *data += sizeof(rx); - *len -= sizeof(rx); - points_size = (le16_to_cpu(rx.nattack) + le16_to_cpu(rx.nrelease)) * 2 * sizeof(__u16); - if (points_size > *len) - return -EINVAL; - rp = kzalloc(sizeof(*rp) + points_size, gfp_mask); - if (rp == NULL) - return -ENOMEM; - rp->nattack = le16_to_cpu(rx.nattack); - rp->nrelease = le16_to_cpu(rx.nrelease); - rp->sustain_offset = le16_to_cpu(rx.sustain_offset); - rp->sustain_rate = le16_to_cpu(rx.sustain_rate); - rp->release_rate = le16_to_cpu(rx.release_rate); - rp->hirange = rx.hirange; - pp = (struct iwffff_env_point *)(rp + 1); - for (idx = 0; idx < rp->nattack + rp->nrelease; idx++) { - if (copy_from_user(&px, *data, sizeof(px))) - return -EFAULT; - *data += sizeof(px); - *len -= sizeof(px); - pp->offset = le16_to_cpu(px.offset); - pp->rate = le16_to_cpu(px.rate); - } - if (ep->record == NULL) { - ep->record = rp; - } else { - rp_last = rp; - } - rp_last = rp; - } - return 0; -} - -static int snd_seq_iwffff_copy_wave_from_stream(struct snd_iwffff_ops *ops, - struct iwffff_layer *lp, - char __user **data, - long *len, - int atomic) -{ - struct iwffff_wave *wp, *prev; - struct iwffff_xwave xp; - int err; - gfp_t gfp_mask; - unsigned int real_size; - - gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; - if (*len < (long)sizeof(xp)) - return -EINVAL; - if (copy_from_user(&xp, *data, sizeof(xp))) - return -EFAULT; - *data += sizeof(xp); - *len -= sizeof(xp); - wp = kzalloc(sizeof(*wp), gfp_mask); - if (wp == NULL) - return -ENOMEM; - wp->share_id[0] = le32_to_cpu(xp.share_id[0]); - wp->share_id[1] = le32_to_cpu(xp.share_id[1]); - wp->share_id[2] = le32_to_cpu(xp.share_id[2]); - wp->share_id[3] = le32_to_cpu(xp.share_id[3]); - wp->format = le32_to_cpu(xp.format); - wp->address.memory = le32_to_cpu(xp.offset); - wp->size = le32_to_cpu(xp.size); - wp->start = le32_to_cpu(xp.start); - wp->loop_start = le32_to_cpu(xp.loop_start); - wp->loop_end = le32_to_cpu(xp.loop_end); - wp->loop_repeat = le16_to_cpu(xp.loop_repeat); - wp->sample_ratio = le32_to_cpu(xp.sample_ratio); - wp->attenuation = xp.attenuation; - wp->low_note = xp.low_note; - wp->high_note = xp.high_note; - real_size = snd_seq_iwffff_size(wp->size, wp->format); - if (!(wp->format & IWFFFF_WAVE_ROM)) { - if ((long)real_size > *len) { - kfree(wp); - return -ENOMEM; - } - } - if (ops->put_sample) { - err = ops->put_sample(ops->private_data, wp, - *data, real_size, atomic); - if (err < 0) { - kfree(wp); - return err; - } - } - if (!(wp->format & IWFFFF_WAVE_ROM)) { - *data += real_size; - *len -= real_size; - } - prev = lp->wave; - if (prev) { - while (prev->next) prev = prev->next; - prev->next = wp; - } else { - lp->wave = wp; - } - return 0; -} - -static void snd_seq_iwffff_env_free(struct snd_iwffff_ops *ops, - struct iwffff_env *env, - int atomic) -{ - struct iwffff_env_record *rec; - - while ((rec = env->record) != NULL) { - env->record = rec->next; - kfree(rec); - } -} - -static void snd_seq_iwffff_wave_free(struct snd_iwffff_ops *ops, - struct iwffff_wave *wave, - int atomic) -{ - if (ops->remove_sample) - ops->remove_sample(ops->private_data, wave, atomic); - kfree(wave); -} - -static void snd_seq_iwffff_instr_free(struct snd_iwffff_ops *ops, - struct iwffff_instrument *ip, - int atomic) -{ - struct iwffff_layer *layer; - struct iwffff_wave *wave; - - while ((layer = ip->layer) != NULL) { - ip->layer = layer->next; - snd_seq_iwffff_env_free(ops, &layer->penv, atomic); - snd_seq_iwffff_env_free(ops, &layer->venv, atomic); - while ((wave = layer->wave) != NULL) { - layer->wave = wave->next; - snd_seq_iwffff_wave_free(ops, wave, atomic); - } - kfree(layer); - } -} - -static int snd_seq_iwffff_put(void *private_data, struct snd_seq_kinstr *instr, - char __user *instr_data, long len, int atomic, - int cmd) -{ - struct snd_iwffff_ops *ops = private_data; - struct iwffff_instrument *ip; - struct iwffff_xinstrument ix; - struct iwffff_layer *lp, *prev_lp; - struct iwffff_xlayer lx; - int err; - gfp_t gfp_mask; - - if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE) - return -EINVAL; - gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; - /* copy instrument data */ - if (len < (long)sizeof(ix)) - return -EINVAL; - if (copy_from_user(&ix, instr_data, sizeof(ix))) - return -EFAULT; - if (ix.stype != IWFFFF_STRU_INSTR) - return -EINVAL; - instr_data += sizeof(ix); - len -= sizeof(ix); - ip = (struct iwffff_instrument *)KINSTR_DATA(instr); - ip->exclusion = le16_to_cpu(ix.exclusion); - ip->layer_type = le16_to_cpu(ix.layer_type); - ip->exclusion_group = le16_to_cpu(ix.exclusion_group); - ip->effect1 = ix.effect1; - ip->effect1_depth = ix.effect1_depth; - ip->effect2 = ix.effect2; - ip->effect2_depth = ix.effect2_depth; - /* copy layers */ - prev_lp = NULL; - while (len > 0) { - if (len < (long)sizeof(struct iwffff_xlayer)) { - snd_seq_iwffff_instr_free(ops, ip, atomic); - return -EINVAL; - } - if (copy_from_user(&lx, instr_data, sizeof(lx))) - return -EFAULT; - instr_data += sizeof(lx); - len -= sizeof(lx); - if (lx.stype != IWFFFF_STRU_LAYER) { - snd_seq_iwffff_instr_free(ops, ip, atomic); - return -EINVAL; - } - lp = kzalloc(sizeof(*lp), gfp_mask); - if (lp == NULL) { - snd_seq_iwffff_instr_free(ops, ip, atomic); - return -ENOMEM; - } - if (prev_lp) { - prev_lp->next = lp; - } else { - ip->layer = lp; - } - prev_lp = lp; - lp->flags = lx.flags; - lp->velocity_mode = lx.velocity_mode; - lp->layer_event = lx.layer_event; - lp->low_range = lx.low_range; - lp->high_range = lx.high_range; - lp->pan = lx.pan; - lp->pan_freq_scale = lx.pan_freq_scale; - lp->attenuation = lx.attenuation; - snd_seq_iwffff_copy_lfo_from_stream(&lp->tremolo, &lx.tremolo); - snd_seq_iwffff_copy_lfo_from_stream(&lp->vibrato, &lx.vibrato); - lp->freq_scale = le16_to_cpu(lx.freq_scale); - lp->freq_center = lx.freq_center; - err = snd_seq_iwffff_copy_env_from_stream(IWFFFF_STRU_ENV_RECP, - lp, - &lp->penv, &lx.penv, - &instr_data, &len, - gfp_mask); - if (err < 0) { - snd_seq_iwffff_instr_free(ops, ip, atomic); - return err; - } - err = snd_seq_iwffff_copy_env_from_stream(IWFFFF_STRU_ENV_RECV, - lp, - &lp->venv, &lx.venv, - &instr_data, &len, - gfp_mask); - if (err < 0) { - snd_seq_iwffff_instr_free(ops, ip, atomic); - return err; - } - while (len > (long)sizeof(__u32)) { - __u32 stype; - - if (copy_from_user(&stype, instr_data, sizeof(stype))) - return -EFAULT; - if (stype != IWFFFF_STRU_WAVE) - break; - err = snd_seq_iwffff_copy_wave_from_stream(ops, - lp, - &instr_data, - &len, - atomic); - if (err < 0) { - snd_seq_iwffff_instr_free(ops, ip, atomic); - return err; - } - } - } - return 0; -} - -static void snd_seq_iwffff_copy_lfo_to_stream(struct iwffff_xlfo *fx, - struct iwffff_lfo *fp) -{ - fx->freq = cpu_to_le16(fp->freq); - fx->depth = cpu_to_le16(fp->depth); - fx->sweep = cpu_to_le16(fp->sweep); - fp->shape = fx->shape; - fp->delay = fx->delay; -} - -static int snd_seq_iwffff_copy_env_to_stream(__u32 req_stype, - struct iwffff_layer *lp, - struct iwffff_xenv *ex, - struct iwffff_env *ep, - char __user **data, - long *len) -{ - struct iwffff_env_record *rp; - struct iwffff_xenv_record rx; - struct iwffff_env_point *pp; - struct iwffff_xenv_point px; - int points_size, idx; - - ex->flags = ep->flags; - ex->mode = ep->mode; - ex->index = ep->index; - for (rp = ep->record; rp; rp = rp->next) { - if (*len < (long)sizeof(rx)) - return -ENOMEM; - memset(&rx, 0, sizeof(rx)); - rx.stype = req_stype; - rx.nattack = cpu_to_le16(rp->nattack); - rx.nrelease = cpu_to_le16(rp->nrelease); - rx.sustain_offset = cpu_to_le16(rp->sustain_offset); - rx.sustain_rate = cpu_to_le16(rp->sustain_rate); - rx.release_rate = cpu_to_le16(rp->release_rate); - rx.hirange = cpu_to_le16(rp->hirange); - if (copy_to_user(*data, &rx, sizeof(rx))) - return -EFAULT; - *data += sizeof(rx); - *len -= sizeof(rx); - points_size = (rp->nattack + rp->nrelease) * 2 * sizeof(__u16); - if (*len < points_size) - return -ENOMEM; - pp = (struct iwffff_env_point *)(rp + 1); - for (idx = 0; idx < rp->nattack + rp->nrelease; idx++) { - px.offset = cpu_to_le16(pp->offset); - px.rate = cpu_to_le16(pp->rate); - if (copy_to_user(*data, &px, sizeof(px))) - return -EFAULT; - *data += sizeof(px); - *len -= sizeof(px); - } - } - return 0; -} - -static int snd_seq_iwffff_copy_wave_to_stream(struct snd_iwffff_ops *ops, - struct iwffff_layer *lp, - char __user **data, - long *len, - int atomic) -{ - struct iwffff_wave *wp; - struct iwffff_xwave xp; - int err; - unsigned int real_size; - - for (wp = lp->wave; wp; wp = wp->next) { - if (*len < (long)sizeof(xp)) - return -ENOMEM; - memset(&xp, 0, sizeof(xp)); - xp.stype = IWFFFF_STRU_WAVE; - xp.share_id[0] = cpu_to_le32(wp->share_id[0]); - xp.share_id[1] = cpu_to_le32(wp->share_id[1]); - xp.share_id[2] = cpu_to_le32(wp->share_id[2]); - xp.share_id[3] = cpu_to_le32(wp->share_id[3]); - xp.format = cpu_to_le32(wp->format); - if (wp->format & IWFFFF_WAVE_ROM) - xp.offset = cpu_to_le32(wp->address.memory); - xp.size = cpu_to_le32(wp->size); - xp.start = cpu_to_le32(wp->start); - xp.loop_start = cpu_to_le32(wp->loop_start); - xp.loop_end = cpu_to_le32(wp->loop_end); - xp.loop_repeat = cpu_to_le32(wp->loop_repeat); - xp.sample_ratio = cpu_to_le32(wp->sample_ratio); - xp.attenuation = wp->attenuation; - xp.low_note = wp->low_note; - xp.high_note = wp->high_note; - if (copy_to_user(*data, &xp, sizeof(xp))) - return -EFAULT; - *data += sizeof(xp); - *len -= sizeof(xp); - real_size = snd_seq_iwffff_size(wp->size, wp->format); - if (!(wp->format & IWFFFF_WAVE_ROM)) { - if (*len < (long)real_size) - return -ENOMEM; - } - if (ops->get_sample) { - err = ops->get_sample(ops->private_data, wp, - *data, real_size, atomic); - if (err < 0) - return err; - } - if (!(wp->format & IWFFFF_WAVE_ROM)) { - *data += real_size; - *len -= real_size; - } - } - return 0; -} - -static int snd_seq_iwffff_get(void *private_data, struct snd_seq_kinstr *instr, - char __user *instr_data, long len, int atomic, int cmd) -{ - struct snd_iwffff_ops *ops = private_data; - struct iwffff_instrument *ip; - struct iwffff_xinstrument ix; - struct iwffff_layer *lp; - struct iwffff_xlayer lx; - char __user *layer_instr_data; - int err; - - if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL) - return -EINVAL; - if (len < (long)sizeof(ix)) - return -ENOMEM; - memset(&ix, 0, sizeof(ix)); - ip = (struct iwffff_instrument *)KINSTR_DATA(instr); - ix.stype = IWFFFF_STRU_INSTR; - ix.exclusion = cpu_to_le16(ip->exclusion); - ix.layer_type = cpu_to_le16(ip->layer_type); - ix.exclusion_group = cpu_to_le16(ip->exclusion_group); - ix.effect1 = cpu_to_le16(ip->effect1); - ix.effect1_depth = cpu_to_le16(ip->effect1_depth); - ix.effect2 = ip->effect2; - ix.effect2_depth = ip->effect2_depth; - if (copy_to_user(instr_data, &ix, sizeof(ix))) - return -EFAULT; - instr_data += sizeof(ix); - len -= sizeof(ix); - for (lp = ip->layer; lp; lp = lp->next) { - if (len < (long)sizeof(lx)) - return -ENOMEM; - memset(&lx, 0, sizeof(lx)); - lx.stype = IWFFFF_STRU_LAYER; - lx.flags = lp->flags; - lx.velocity_mode = lp->velocity_mode; - lx.layer_event = lp->layer_event; - lx.low_range = lp->low_range; - lx.high_range = lp->high_range; - lx.pan = lp->pan; - lx.pan_freq_scale = lp->pan_freq_scale; - lx.attenuation = lp->attenuation; - snd_seq_iwffff_copy_lfo_to_stream(&lx.tremolo, &lp->tremolo); - snd_seq_iwffff_copy_lfo_to_stream(&lx.vibrato, &lp->vibrato); - layer_instr_data = instr_data; - instr_data += sizeof(lx); - len -= sizeof(lx); - err = snd_seq_iwffff_copy_env_to_stream(IWFFFF_STRU_ENV_RECP, - lp, - &lx.penv, &lp->penv, - &instr_data, &len); - if (err < 0) - return err; - err = snd_seq_iwffff_copy_env_to_stream(IWFFFF_STRU_ENV_RECV, - lp, - &lx.venv, &lp->venv, - &instr_data, &len); - if (err < 0) - return err; - /* layer structure updating is now finished */ - if (copy_to_user(layer_instr_data, &lx, sizeof(lx))) - return -EFAULT; - err = snd_seq_iwffff_copy_wave_to_stream(ops, - lp, - &instr_data, - &len, - atomic); - if (err < 0) - return err; - } - return 0; -} - -static long snd_seq_iwffff_env_size_in_stream(struct iwffff_env *ep) -{ - long result = 0; - struct iwffff_env_record *rp; - - for (rp = ep->record; rp; rp = rp->next) { - result += sizeof(struct iwffff_xenv_record); - result += (rp->nattack + rp->nrelease) * 2 * sizeof(__u16); - } - return 0; -} - -static long snd_seq_iwffff_wave_size_in_stream(struct iwffff_layer *lp) -{ - long result = 0; - struct iwffff_wave *wp; - - for (wp = lp->wave; wp; wp = wp->next) { - result += sizeof(struct iwffff_xwave); - if (!(wp->format & IWFFFF_WAVE_ROM)) - result += wp->size; - } - return result; -} - -static int snd_seq_iwffff_get_size(void *private_data, struct snd_seq_kinstr *instr, - long *size) -{ - long result; - struct iwffff_instrument *ip; - struct iwffff_layer *lp; - - *size = 0; - ip = (struct iwffff_instrument *)KINSTR_DATA(instr); - result = sizeof(struct iwffff_xinstrument); - for (lp = ip->layer; lp; lp = lp->next) { - result += sizeof(struct iwffff_xlayer); - result += snd_seq_iwffff_env_size_in_stream(&lp->penv); - result += snd_seq_iwffff_env_size_in_stream(&lp->venv); - result += snd_seq_iwffff_wave_size_in_stream(lp); - } - *size = result; - return 0; -} - -static int snd_seq_iwffff_remove(void *private_data, - struct snd_seq_kinstr *instr, - int atomic) -{ - struct snd_iwffff_ops *ops = private_data; - struct iwffff_instrument *ip; - - ip = (struct iwffff_instrument *)KINSTR_DATA(instr); - snd_seq_iwffff_instr_free(ops, ip, atomic); - return 0; -} - -static void snd_seq_iwffff_notify(void *private_data, - struct snd_seq_kinstr *instr, - int what) -{ - struct snd_iwffff_ops *ops = private_data; - - if (ops->notify) - ops->notify(ops->private_data, instr, what); -} - -int snd_seq_iwffff_init(struct snd_iwffff_ops *ops, - void *private_data, - struct snd_seq_kinstr_ops *next) -{ - memset(ops, 0, sizeof(*ops)); - ops->private_data = private_data; - ops->kops.private_data = ops; - ops->kops.add_len = sizeof(struct iwffff_instrument); - ops->kops.instr_type = SNDRV_SEQ_INSTR_ID_INTERWAVE; - ops->kops.put = snd_seq_iwffff_put; - ops->kops.get = snd_seq_iwffff_get; - ops->kops.get_size = snd_seq_iwffff_get_size; - ops->kops.remove = snd_seq_iwffff_remove; - ops->kops.notify = snd_seq_iwffff_notify; - ops->kops.next = next; - return 0; -} - -/* - * Init part - */ - -static int __init alsa_ainstr_iw_init(void) -{ - return 0; -} - -static void __exit alsa_ainstr_iw_exit(void) -{ -} - -module_init(alsa_ainstr_iw_init) -module_exit(alsa_ainstr_iw_exit) - -EXPORT_SYMBOL(snd_seq_iwffff_init); diff --git a/sound/core/seq/instr/ainstr_simple.c b/sound/core/seq/instr/ainstr_simple.c deleted file mode 100644 index 78f68be..0000000 --- a/sound/core/seq/instr/ainstr_simple.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Simple (MOD player) - Instrument routines - * Copyright (c) 1999 by Jaroslav Kysela - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include -#include - -MODULE_AUTHOR("Jaroslav Kysela "); -MODULE_DESCRIPTION("Advanced Linux Sound Architecture Simple Instrument support."); -MODULE_LICENSE("GPL"); - -static unsigned int snd_seq_simple_size(unsigned int size, unsigned int format) -{ - unsigned int result = size; - - if (format & SIMPLE_WAVE_16BIT) - result <<= 1; - if (format & SIMPLE_WAVE_STEREO) - result <<= 1; - return result; -} - -static void snd_seq_simple_instr_free(struct snd_simple_ops *ops, - struct simple_instrument *ip, - int atomic) -{ - if (ops->remove_sample) - ops->remove_sample(ops->private_data, ip, atomic); -} - -static int snd_seq_simple_put(void *private_data, struct snd_seq_kinstr *instr, - char __user *instr_data, long len, - int atomic, int cmd) -{ - struct snd_simple_ops *ops = private_data; - struct simple_instrument *ip; - struct simple_xinstrument ix; - int err; - gfp_t gfp_mask; - unsigned int real_size; - - if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE) - return -EINVAL; - gfp_mask = atomic ? GFP_ATOMIC : GFP_KERNEL; - /* copy instrument data */ - if (len < (long)sizeof(ix)) - return -EINVAL; - if (copy_from_user(&ix, instr_data, sizeof(ix))) - return -EFAULT; - if (ix.stype != SIMPLE_STRU_INSTR) - return -EINVAL; - instr_data += sizeof(ix); - len -= sizeof(ix); - ip = (struct simple_instrument *)KINSTR_DATA(instr); - ip->share_id[0] = le32_to_cpu(ix.share_id[0]); - ip->share_id[1] = le32_to_cpu(ix.share_id[1]); - ip->share_id[2] = le32_to_cpu(ix.share_id[2]); - ip->share_id[3] = le32_to_cpu(ix.share_id[3]); - ip->format = le32_to_cpu(ix.format); - ip->size = le32_to_cpu(ix.size); - ip->start = le32_to_cpu(ix.start); - ip->loop_start = le32_to_cpu(ix.loop_start); - ip->loop_end = le32_to_cpu(ix.loop_end); - ip->loop_repeat = le16_to_cpu(ix.loop_repeat); - ip->effect1 = ix.effect1; - ip->effect1_depth = ix.effect1_depth; - ip->effect2 = ix.effect2; - ip->effect2_depth = ix.effect2_depth; - real_size = snd_seq_simple_size(ip->size, ip->format); - if (len < (long)real_size) - return -EINVAL; - if (ops->put_sample) { - err = ops->put_sample(ops->private_data, ip, - instr_data, real_size, atomic); - if (err < 0) - return err; - } - return 0; -} - -static int snd_seq_simple_get(void *private_data, struct snd_seq_kinstr *instr, - char __user *instr_data, long len, - int atomic, int cmd) -{ - struct snd_simple_ops *ops = private_data; - struct simple_instrument *ip; - struct simple_xinstrument ix; - int err; - unsigned int real_size; - - if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL) - return -EINVAL; - if (len < (long)sizeof(ix)) - return -ENOMEM; - memset(&ix, 0, sizeof(ix)); - ip = (struct simple_instrument *)KINSTR_DATA(instr); - ix.stype = SIMPLE_STRU_INSTR; - ix.share_id[0] = cpu_to_le32(ip->share_id[0]); - ix.share_id[1] = cpu_to_le32(ip->share_id[1]); - ix.share_id[2] = cpu_to_le32(ip->share_id[2]); - ix.share_id[3] = cpu_to_le32(ip->share_id[3]); - ix.format = cpu_to_le32(ip->format); - ix.size = cpu_to_le32(ip->size); - ix.start = cpu_to_le32(ip->start); - ix.loop_start = cpu_to_le32(ip->loop_start); - ix.loop_end = cpu_to_le32(ip->loop_end); - ix.loop_repeat = cpu_to_le32(ip->loop_repeat); - ix.effect1 = cpu_to_le16(ip->effect1); - ix.effect1_depth = cpu_to_le16(ip->effect1_depth); - ix.effect2 = ip->effect2; - ix.effect2_depth = ip->effect2_depth; - if (copy_to_user(instr_data, &ix, sizeof(ix))) - return -EFAULT; - instr_data += sizeof(ix); - len -= sizeof(ix); - real_size = snd_seq_simple_size(ip->size, ip->format); - if (len < (long)real_size) - return -ENOMEM; - if (ops->get_sample) { - err = ops->get_sample(ops->private_data, ip, - instr_data, real_size, atomic); - if (err < 0) - return err; - } - return 0; -} - -static int snd_seq_simple_get_size(void *private_data, struct snd_seq_kinstr *instr, - long *size) -{ - struct simple_instrument *ip; - - ip = (struct simple_instrument *)KINSTR_DATA(instr); - *size = sizeof(struct simple_xinstrument) + snd_seq_simple_size(ip->size, ip->format); - return 0; -} - -static int snd_seq_simple_remove(void *private_data, - struct snd_seq_kinstr *instr, - int atomic) -{ - struct snd_simple_ops *ops = private_data; - struct simple_instrument *ip; - - ip = (struct simple_instrument *)KINSTR_DATA(instr); - snd_seq_simple_instr_free(ops, ip, atomic); - return 0; -} - -static void snd_seq_simple_notify(void *private_data, - struct snd_seq_kinstr *instr, - int what) -{ - struct snd_simple_ops *ops = private_data; - - if (ops->notify) - ops->notify(ops->private_data, instr, what); -} - -int snd_seq_simple_init(struct snd_simple_ops *ops, - void *private_data, - struct snd_seq_kinstr_ops *next) -{ - memset(ops, 0, sizeof(*ops)); - ops->private_data = private_data; - ops->kops.private_data = ops; - ops->kops.add_len = sizeof(struct simple_instrument); - ops->kops.instr_type = SNDRV_SEQ_INSTR_ID_SIMPLE; - ops->kops.put = snd_seq_simple_put; - ops->kops.get = snd_seq_simple_get; - ops->kops.get_size = snd_seq_simple_get_size; - ops->kops.remove = snd_seq_simple_remove; - ops->kops.notify = snd_seq_simple_notify; - ops->kops.next = next; - return 0; -} - -/* - * Init part - */ - -static int __init alsa_ainstr_simple_init(void) -{ - return 0; -} - -static void __exit alsa_ainstr_simple_exit(void) -{ -} - -module_init(alsa_ainstr_simple_init) -module_exit(alsa_ainstr_simple_exit) - -EXPORT_SYMBOL(snd_seq_simple_init); diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c index 2e3fa25..69421ca 100644 --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -966,8 +966,7 @@ static int check_event_type_and_length(struct snd_seq_event *ev) return -EINVAL; break; case SNDRV_SEQ_EVENT_LENGTH_VARUSR: - if (! snd_seq_ev_is_instr_type(ev) || - ! snd_seq_ev_is_direct(ev)) + if (! snd_seq_ev_is_direct(ev)) return -EINVAL; break; } diff --git a/sound/core/seq/seq_instr.c b/sound/core/seq/seq_instr.c deleted file mode 100644 index 9a6fd56..0000000 --- a/sound/core/seq/seq_instr.c +++ /dev/null @@ -1,655 +0,0 @@ -/* - * Generic Instrument routines for ALSA sequencer - * Copyright (c) 1999 by Jaroslav Kysela - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include "seq_clientmgr.h" -#include -#include - -MODULE_AUTHOR("Jaroslav Kysela "); -MODULE_DESCRIPTION("Advanced Linux Sound Architecture sequencer instrument library."); -MODULE_LICENSE("GPL"); - - -static void snd_instr_lock_ops(struct snd_seq_kinstr_list *list) -{ - if (!(list->flags & SNDRV_SEQ_INSTR_FLG_DIRECT)) { - spin_lock_irqsave(&list->ops_lock, list->ops_flags); - } else { - mutex_lock(&list->ops_mutex); - } -} - -static void snd_instr_unlock_ops(struct snd_seq_kinstr_list *list) -{ - if (!(list->flags & SNDRV_SEQ_INSTR_FLG_DIRECT)) { - spin_unlock_irqrestore(&list->ops_lock, list->ops_flags); - } else { - mutex_unlock(&list->ops_mutex); - } -} - -static struct snd_seq_kinstr *snd_seq_instr_new(int add_len, int atomic) -{ - struct snd_seq_kinstr *instr; - - instr = kzalloc(sizeof(struct snd_seq_kinstr) + add_len, atomic ? GFP_ATOMIC : GFP_KERNEL); - if (instr == NULL) - return NULL; - instr->add_len = add_len; - return instr; -} - -static int snd_seq_instr_free(struct snd_seq_kinstr *instr, int atomic) -{ - int result = 0; - - if (instr == NULL) - return -EINVAL; - if (instr->ops && instr->ops->remove) - result = instr->ops->remove(instr->ops->private_data, instr, 1); - if (!result) - kfree(instr); - return result; -} - -struct snd_seq_kinstr_list *snd_seq_instr_list_new(void) -{ - struct snd_seq_kinstr_list *list; - - list = kzalloc(sizeof(struct snd_seq_kinstr_list), GFP_KERNEL); - if (list == NULL) - return NULL; - spin_lock_init(&list->lock); - spin_lock_init(&list->ops_lock); - mutex_init(&list->ops_mutex); - list->owner = -1; - return list; -} - -void snd_seq_instr_list_free(struct snd_seq_kinstr_list **list_ptr) -{ - struct snd_seq_kinstr_list *list; - struct snd_seq_kinstr *instr; - struct snd_seq_kcluster *cluster; - int idx; - unsigned long flags; - - if (list_ptr == NULL) - return; - list = *list_ptr; - *list_ptr = NULL; - if (list == NULL) - return; - - for (idx = 0; idx < SNDRV_SEQ_INSTR_HASH_SIZE; idx++) { - while ((instr = list->hash[idx]) != NULL) { - list->hash[idx] = instr->next; - list->count--; - spin_lock_irqsave(&list->lock, flags); - while (instr->use) { - spin_unlock_irqrestore(&list->lock, flags); - schedule_timeout_uninterruptible(1); - spin_lock_irqsave(&list->lock, flags); - } - spin_unlock_irqrestore(&list->lock, flags); - if (snd_seq_instr_free(instr, 0)<0) - snd_printk(KERN_WARNING "instrument free problem\n"); - } - while ((cluster = list->chash[idx]) != NULL) { - list->chash[idx] = cluster->next; - list->ccount--; - kfree(cluster); - } - } - kfree(list); -} - -static int instr_free_compare(struct snd_seq_kinstr *instr, - struct snd_seq_instr_header *ifree, - unsigned int client) -{ - switch (ifree->cmd) { - case SNDRV_SEQ_INSTR_FREE_CMD_ALL: - /* all, except private for other clients */ - if ((instr->instr.std & 0xff000000) == 0) - return 0; - if (((instr->instr.std >> 24) & 0xff) == client) - return 0; - return 1; - case SNDRV_SEQ_INSTR_FREE_CMD_PRIVATE: - /* all my private instruments */ - if ((instr->instr.std & 0xff000000) == 0) - return 1; - if (((instr->instr.std >> 24) & 0xff) == client) - return 0; - return 1; - case SNDRV_SEQ_INSTR_FREE_CMD_CLUSTER: - /* all my private instruments */ - if ((instr->instr.std & 0xff000000) == 0) { - if (instr->instr.cluster == ifree->id.cluster) - return 0; - return 1; - } - if (((instr->instr.std >> 24) & 0xff) == client) { - if (instr->instr.cluster == ifree->id.cluster) - return 0; - } - return 1; - } - return 1; -} - -int snd_seq_instr_list_free_cond(struct snd_seq_kinstr_list *list, - struct snd_seq_instr_header *ifree, - int client, - int atomic) -{ - struct snd_seq_kinstr *instr, *prev, *next, *flist; - int idx; - unsigned long flags; - - snd_instr_lock_ops(list); - for (idx = 0; idx < SNDRV_SEQ_INSTR_HASH_SIZE; idx++) { - spin_lock_irqsave(&list->lock, flags); - instr = list->hash[idx]; - prev = flist = NULL; - while (instr) { - while (instr && instr_free_compare(instr, ifree, (unsigned int)client)) { - prev = instr; - instr = instr->next; - } - if (instr == NULL) - continue; - if (instr->ops && instr->ops->notify) - instr->ops->notify(instr->ops->private_data, instr, SNDRV_SEQ_INSTR_NOTIFY_REMOVE); - next = instr->next; - if (prev == NULL) { - list->hash[idx] = next; - } else { - prev->next = next; - } - list->count--; - instr->next = flist; - flist = instr; - instr = next; - } - spin_unlock_irqrestore(&list->lock, flags); - while (flist) { - instr = flist; - flist = instr->next; - while (instr->use) { - schedule_timeout_uninterruptible(1); - barrier(); - } - if (snd_seq_instr_free(instr, atomic)<0) - snd_printk(KERN_WARNING "instrument free problem\n"); - instr = next; - } - } - snd_instr_unlock_ops(list); - return 0; -} - -static int compute_hash_instr_key(struct snd_seq_instr *instr) -{ - int result; - - result = instr->bank | (instr->prg << 16); - result += result >> 24; - result += result >> 16; - result += result >> 8; - return result & (SNDRV_SEQ_INSTR_HASH_SIZE-1); -} - -#if 0 -static int compute_hash_cluster_key(snd_seq_instr_cluster_t cluster) -{ - int result; - - result = cluster; - result += result >> 24; - result += result >> 16; - result += result >> 8; - return result & (SNDRV_SEQ_INSTR_HASH_SIZE-1); -} -#endif - -static int compare_instr(struct snd_seq_instr *i1, struct snd_seq_instr *i2, int exact) -{ - if (exact) { - if (i1->cluster != i2->cluster || - i1->bank != i2->bank || - i1->prg != i2->prg) - return 1; - if ((i1->std & 0xff000000) != (i2->std & 0xff000000)) - return 1; - if (!(i1->std & i2->std)) - return 1; - return 0; - } else { - unsigned int client_check; - - if (i2->cluster && i1->cluster != i2->cluster) - return 1; - client_check = i2->std & 0xff000000; - if (client_check) { - if ((i1->std & 0xff000000) != client_check) - return 1; - } else { - if ((i1->std & i2->std) != i2->std) - return 1; - } - return i1->bank != i2->bank || i1->prg != i2->prg; - } -} - -struct snd_seq_kinstr *snd_seq_instr_find(struct snd_seq_kinstr_list *list, - struct snd_seq_instr *instr, - int exact, - int follow_alias) -{ - unsigned long flags; - int depth = 0; - struct snd_seq_kinstr *result; - - if (list == NULL || instr == NULL) - return NULL; - spin_lock_irqsave(&list->lock, flags); - __again: - result = list->hash[compute_hash_instr_key(instr)]; - while (result) { - if (!compare_instr(&result->instr, instr, exact)) { - if (follow_alias && (result->type == SNDRV_SEQ_INSTR_ATYPE_ALIAS)) { - instr = (struct snd_seq_instr *)KINSTR_DATA(result); - if (++depth > 10) - goto __not_found; - goto __again; - } - result->use++; - spin_unlock_irqrestore(&list->lock, flags); - return result; - } - result = result->next; - } - __not_found: - spin_unlock_irqrestore(&list->lock, flags); - return NULL; -} - -void snd_seq_instr_free_use(struct snd_seq_kinstr_list *list, - struct snd_seq_kinstr *instr) -{ - unsigned long flags; - - if (list == NULL || instr == NULL) - return; - spin_lock_irqsave(&list->lock, flags); - if (instr->use <= 0) { - snd_printk(KERN_ERR "free_use: fatal!!! use = %i, name = '%s'\n", instr->use, instr->name); - } else { - instr->use--; - } - spin_unlock_irqrestore(&list->lock, flags); -} - -static struct snd_seq_kinstr_ops *instr_ops(struct snd_seq_kinstr_ops *ops, - char *instr_type) -{ - while (ops) { - if (!strcmp(ops->instr_type, instr_type)) - return ops; - ops = ops->next; - } - return NULL; -} - -static int instr_result(struct snd_seq_event *ev, - int type, int result, - int atomic) -{ - struct snd_seq_event sev; - - memset(&sev, 0, sizeof(sev)); - sev.type = SNDRV_SEQ_EVENT_RESULT; - sev.flags = SNDRV_SEQ_TIME_STAMP_REAL | SNDRV_SEQ_EVENT_LENGTH_FIXED | - SNDRV_SEQ_PRIORITY_NORMAL; - sev.source = ev->dest; - sev.dest = ev->source; - sev.data.result.event = type; - sev.data.result.result = result; -#if 0 - printk("instr result - type = %i, result = %i, queue = %i, source.client:port = %i:%i, dest.client:port = %i:%i\n", - type, result, - sev.queue, - sev.source.client, sev.source.port, - sev.dest.client, sev.dest.port); -#endif - return snd_seq_kernel_client_dispatch(sev.source.client, &sev, atomic, 0); -} - -static int instr_begin(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - unsigned long flags; - - spin_lock_irqsave(&list->lock, flags); - if (list->owner >= 0 && list->owner != ev->source.client) { - spin_unlock_irqrestore(&list->lock, flags); - return instr_result(ev, SNDRV_SEQ_EVENT_INSTR_BEGIN, -EBUSY, atomic); - } - list->owner = ev->source.client; - spin_unlock_irqrestore(&list->lock, flags); - return instr_result(ev, SNDRV_SEQ_EVENT_INSTR_BEGIN, 0, atomic); -} - -static int instr_end(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - unsigned long flags; - - /* TODO: timeout handling */ - spin_lock_irqsave(&list->lock, flags); - if (list->owner == ev->source.client) { - list->owner = -1; - spin_unlock_irqrestore(&list->lock, flags); - return instr_result(ev, SNDRV_SEQ_EVENT_INSTR_END, 0, atomic); - } - spin_unlock_irqrestore(&list->lock, flags); - return instr_result(ev, SNDRV_SEQ_EVENT_INSTR_END, -EINVAL, atomic); -} - -static int instr_info(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - return -ENXIO; -} - -static int instr_format_info(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - return -ENXIO; -} - -static int instr_reset(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - return -ENXIO; -} - -static int instr_status(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - return -ENXIO; -} - -static int instr_put(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - unsigned long flags; - struct snd_seq_instr_header put; - struct snd_seq_kinstr *instr; - int result = -EINVAL, len, key; - - if ((ev->flags & SNDRV_SEQ_EVENT_LENGTH_MASK) != SNDRV_SEQ_EVENT_LENGTH_VARUSR) - goto __return; - - if (ev->data.ext.len < sizeof(struct snd_seq_instr_header)) - goto __return; - if (copy_from_user(&put, (void __user *)ev->data.ext.ptr, - sizeof(struct snd_seq_instr_header))) { - result = -EFAULT; - goto __return; - } - snd_instr_lock_ops(list); - if (put.id.instr.std & 0xff000000) { /* private instrument */ - put.id.instr.std &= 0x00ffffff; - put.id.instr.std |= (unsigned int)ev->source.client << 24; - } - if ((instr = snd_seq_instr_find(list, &put.id.instr, 1, 0))) { - snd_seq_instr_free_use(list, instr); - snd_instr_unlock_ops(list); - result = -EBUSY; - goto __return; - } - ops = instr_ops(ops, put.data.data.format); - if (ops == NULL) { - snd_instr_unlock_ops(list); - goto __return; - } - len = ops->add_len; - if (put.data.type == SNDRV_SEQ_INSTR_ATYPE_ALIAS) - len = sizeof(struct snd_seq_instr); - instr = snd_seq_instr_new(len, atomic); - if (instr == NULL) { - snd_instr_unlock_ops(list); - result = -ENOMEM; - goto __return; - } - instr->ops = ops; - instr->instr = put.id.instr; - strlcpy(instr->name, put.data.name, sizeof(instr->name)); - instr->type = put.data.type; - if (instr->type == SNDRV_SEQ_INSTR_ATYPE_DATA) { - result = ops->put(ops->private_data, - instr, - (void __user *)ev->data.ext.ptr + sizeof(struct snd_seq_instr_header), - ev->data.ext.len - sizeof(struct snd_seq_instr_header), - atomic, - put.cmd); - if (result < 0) { - snd_seq_instr_free(instr, atomic); - snd_instr_unlock_ops(list); - goto __return; - } - } - key = compute_hash_instr_key(&instr->instr); - spin_lock_irqsave(&list->lock, flags); - instr->next = list->hash[key]; - list->hash[key] = instr; - list->count++; - spin_unlock_irqrestore(&list->lock, flags); - snd_instr_unlock_ops(list); - result = 0; - __return: - instr_result(ev, SNDRV_SEQ_EVENT_INSTR_PUT, result, atomic); - return result; -} - -static int instr_get(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - return -ENXIO; -} - -static int instr_free(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - struct snd_seq_instr_header ifree; - struct snd_seq_kinstr *instr, *prev; - int result = -EINVAL; - unsigned long flags; - unsigned int hash; - - if ((ev->flags & SNDRV_SEQ_EVENT_LENGTH_MASK) != SNDRV_SEQ_EVENT_LENGTH_VARUSR) - goto __return; - - if (ev->data.ext.len < sizeof(struct snd_seq_instr_header)) - goto __return; - if (copy_from_user(&ifree, (void __user *)ev->data.ext.ptr, - sizeof(struct snd_seq_instr_header))) { - result = -EFAULT; - goto __return; - } - if (ifree.cmd == SNDRV_SEQ_INSTR_FREE_CMD_ALL || - ifree.cmd == SNDRV_SEQ_INSTR_FREE_CMD_PRIVATE || - ifree.cmd == SNDRV_SEQ_INSTR_FREE_CMD_CLUSTER) { - result = snd_seq_instr_list_free_cond(list, &ifree, ev->dest.client, atomic); - goto __return; - } - if (ifree.cmd == SNDRV_SEQ_INSTR_FREE_CMD_SINGLE) { - if (ifree.id.instr.std & 0xff000000) { - ifree.id.instr.std &= 0x00ffffff; - ifree.id.instr.std |= (unsigned int)ev->source.client << 24; - } - hash = compute_hash_instr_key(&ifree.id.instr); - snd_instr_lock_ops(list); - spin_lock_irqsave(&list->lock, flags); - instr = list->hash[hash]; - prev = NULL; - while (instr) { - if (!compare_instr(&instr->instr, &ifree.id.instr, 1)) - goto __free_single; - prev = instr; - instr = instr->next; - } - result = -ENOENT; - spin_unlock_irqrestore(&list->lock, flags); - snd_instr_unlock_ops(list); - goto __return; - - __free_single: - if (prev) { - prev->next = instr->next; - } else { - list->hash[hash] = instr->next; - } - if (instr->ops && instr->ops->notify) - instr->ops->notify(instr->ops->private_data, instr, - SNDRV_SEQ_INSTR_NOTIFY_REMOVE); - while (instr->use) { - spin_unlock_irqrestore(&list->lock, flags); - schedule_timeout_uninterruptible(1); - spin_lock_irqsave(&list->lock, flags); - } - spin_unlock_irqrestore(&list->lock, flags); - result = snd_seq_instr_free(instr, atomic); - snd_instr_unlock_ops(list); - goto __return; - } - - __return: - instr_result(ev, SNDRV_SEQ_EVENT_INSTR_FREE, result, atomic); - return result; -} - -static int instr_list(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - return -ENXIO; -} - -static int instr_cluster(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int atomic, int hop) -{ - return -ENXIO; -} - -int snd_seq_instr_event(struct snd_seq_kinstr_ops *ops, - struct snd_seq_kinstr_list *list, - struct snd_seq_event *ev, - int client, - int atomic, - int hop) -{ - int direct = 0; - - snd_assert(ops != NULL && list != NULL && ev != NULL, return -EINVAL); - if (snd_seq_ev_is_direct(ev)) { - direct = 1; - switch (ev->type) { - case SNDRV_SEQ_EVENT_INSTR_BEGIN: - return instr_begin(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_END: - return instr_end(ops, list, ev, atomic, hop); - } - } - if ((list->flags & SNDRV_SEQ_INSTR_FLG_DIRECT) && !direct) - return -EINVAL; - switch (ev->type) { - case SNDRV_SEQ_EVENT_INSTR_INFO: - return instr_info(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_FINFO: - return instr_format_info(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_RESET: - return instr_reset(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_STATUS: - return instr_status(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_PUT: - return instr_put(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_GET: - return instr_get(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_FREE: - return instr_free(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_LIST: - return instr_list(ops, list, ev, atomic, hop); - case SNDRV_SEQ_EVENT_INSTR_CLUSTER: - return instr_cluster(ops, list, ev, atomic, hop); - } - return -EINVAL; -} - -/* - * Init part - */ - -static int __init alsa_seq_instr_init(void) -{ - return 0; -} - -static void __exit alsa_seq_instr_exit(void) -{ -} - -module_init(alsa_seq_instr_init) -module_exit(alsa_seq_instr_exit) - -EXPORT_SYMBOL(snd_seq_instr_list_new); -EXPORT_SYMBOL(snd_seq_instr_list_free); -EXPORT_SYMBOL(snd_seq_instr_list_free_cond); -EXPORT_SYMBOL(snd_seq_instr_find); -EXPORT_SYMBOL(snd_seq_instr_free_use); -EXPORT_SYMBOL(snd_seq_instr_event); diff --git a/sound/core/seq/seq_midi_emul.c b/sound/core/seq/seq_midi_emul.c index 17b3e6f..6645fc5 100644 --- a/sound/core/seq/seq_midi_emul.c +++ b/sound/core/seq/seq_midi_emul.c @@ -229,13 +229,6 @@ snd_midi_process_event(struct snd_midi_op *ops, case SNDRV_SEQ_EVENT_PORT_START: case SNDRV_SEQ_EVENT_PORT_EXIT: case SNDRV_SEQ_EVENT_PORT_CHANGE: - case SNDRV_SEQ_EVENT_SAMPLE: - case SNDRV_SEQ_EVENT_SAMPLE_START: - case SNDRV_SEQ_EVENT_SAMPLE_STOP: - case SNDRV_SEQ_EVENT_SAMPLE_FREQ: - case SNDRV_SEQ_EVENT_SAMPLE_VOLUME: - case SNDRV_SEQ_EVENT_SAMPLE_LOOP: - case SNDRV_SEQ_EVENT_SAMPLE_POSITION: case SNDRV_SEQ_EVENT_ECHO: not_yet: default: diff --git a/sound/drivers/Kconfig b/sound/drivers/Kconfig index 83529b0..75d4fe0 100644 --- a/sound/drivers/Kconfig +++ b/sound/drivers/Kconfig @@ -120,4 +120,16 @@ config SND_PORTMAN2X4 To compile this driver as a module, choose M here: the module will be called snd-portman2x4. +config SND_ML403_AC97CR + tristate "Xilinx ML403 AC97 Controller Reference" + depends on SND && XILINX_VIRTEX + select SND_AC97_CODEC + help + Say Y here to include support for the + opb_ac97_controller_ref_v1_00_a ip core found in Xilinx' ML403 + reference design. + + To compile this driver as a module, choose M here: the module + will be called snd-ml403_ac97cr. + endmenu diff --git a/sound/drivers/Makefile b/sound/drivers/Makefile index 80aeff5..8e55300 100644 --- a/sound/drivers/Makefile +++ b/sound/drivers/Makefile @@ -9,6 +9,7 @@ snd-mts64-objs := mts64.o snd-portman2x4-objs := portman2x4.o snd-serial-u16550-objs := serial-u16550.o snd-virmidi-objs := virmidi.o +snd-ml403-ac97cr-objs := ml403-ac97cr.o pcm-indirect2.o # Toplevel Module Dependency obj-$(CONFIG_SND_DUMMY) += snd-dummy.o @@ -17,5 +18,6 @@ obj-$(CONFIG_SND_SERIAL_U16550) += snd-serial-u16550.o obj-$(CONFIG_SND_MTPAV) += snd-mtpav.o obj-$(CONFIG_SND_MTS64) += snd-mts64.o obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o +obj-$(CONFIG_SND_ML403_AC97CR) += snd-ml403-ac97cr.o obj-$(CONFIG_SND) += opl3/ opl4/ mpu401/ vx/ diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c new file mode 100644 index 0000000..c76a24e --- /dev/null +++ b/sound/drivers/ml403-ac97cr.c @@ -0,0 +1,1351 @@ +/* + * ALSA driver for Xilinx ML403 AC97 Controller Reference + * IP: opb_ac97_controller_ref_v1_00_a (EDK 8.1i) + * IP: opb_ac97_controller_ref_v1_00_a (EDK 9.1i) + * + * Copyright (c) by 2007 Joachim Foerster + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* Some notes / status of this driver: + * + * - Don't wonder about some strange implementations of things - especially the + * (heavy) shadowing of codec registers, with which I tried to reduce read + * accesses to a minimum, because after a variable amount of accesses, the AC97 + * controller doesn't raise the register access finished bit anymore ... + * + * - Playback support seems to be pretty stable - no issues here. + * - Capture support "works" now, too. Overruns don't happen any longer so often. + * But there might still be some ... + */ + +#include +#include +#include + +#include + +#include +#include +#include + +/* HZ */ +#include +/* jiffies, time_*() */ +#include +/* schedule_timeout*() */ +#include +/* spin_lock*() */ +#include +/* struct mutex, mutex_init(), mutex_*lock() */ +#include + +/* snd_printk(), snd_printd() */ +#include +#include +#include +#include +#include + +#include "pcm-indirect2.h" + + +#define SND_ML403_AC97CR_DRIVER "ml403-ac97cr" + +MODULE_AUTHOR("Joachim Foerster "); +MODULE_DESCRIPTION("Xilinx ML403 AC97 Controller Reference"); +MODULE_LICENSE("GPL"); +MODULE_SUPPORTED_DEVICE("{{Xilinx,ML403 AC97 Controller Reference}}"); + +static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; +static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; +static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; + +module_param_array(index, int, NULL, 0444); +MODULE_PARM_DESC(index, "Index value for ML403 AC97 Controller Reference."); +module_param_array(id, charp, NULL, 0444); +MODULE_PARM_DESC(id, "ID string for ML403 AC97 Controller Reference."); +module_param_array(enable, bool, NULL, 0444); +MODULE_PARM_DESC(enable, "Enable this ML403 AC97 Controller Reference."); + +/* Special feature options */ +/*#define CODEC_WRITE_CHECK_RAF*/ /* don't return after a write to a codec + * register, while RAF bit is not set + */ +/* Debug options for code which may be removed completely in a final version */ +#ifdef CONFIG_SND_DEBUG +/*#define CODEC_STAT*/ /* turn on some minimal "statistics" + * about codec register usage + */ +#define SND_PCM_INDIRECT2_STAT /* turn on some "statistics" about the + * process of copying bytes from the + * intermediate buffer to the hardware + * fifo and the other way round + */ +#endif + +/* Definition of a "level/facility dependent" printk(); may be removed + * completely in a final version + */ +#undef PDEBUG +#ifdef CONFIG_SND_DEBUG +/* "facilities" for PDEBUG */ +#define UNKNOWN (1<<0) +#define CODEC_SUCCESS (1<<1) +#define CODEC_FAKE (1<<2) +#define INIT_INFO (1<<3) +#define INIT_FAILURE (1<<4) +#define WORK_INFO (1<<5) +#define WORK_FAILURE (1<<6) + +#define PDEBUG_FACILITIES (UNKNOWN | INIT_FAILURE | WORK_FAILURE) + +#define PDEBUG(fac, fmt, args...) do { \ + if (fac & PDEBUG_FACILITIES) \ + snd_printd(KERN_DEBUG SND_ML403_AC97CR_DRIVER ": " \ + fmt, ##args); \ + } while (0) +#else +#define PDEBUG(fac, fmt, args...) /* nothing */ +#endif + + + +/* Defines for "waits"/timeouts (portions of HZ=250 on arch/ppc by default) */ +#define CODEC_TIMEOUT_ON_INIT 5 /* timeout for checking for codec + * readiness (after insmod) + */ +#ifndef CODEC_WRITE_CHECK_RAF +#define CODEC_WAIT_AFTER_WRITE 100 /* general, static wait after a write + * access to a codec register, may be + * 0 to completely remove wait + */ +#else +#define CODEC_TIMEOUT_AFTER_WRITE 5 /* timeout after a write access to a + * codec register, if RAF bit is used + */ +#endif +#define CODEC_TIMEOUT_AFTER_READ 5 /* timeout after a read access to a + * codec register (checking RAF bit) + */ + +/* Infrastructure for codec register shadowing */ +#define LM4550_REG_OK (1<<0) /* register exists */ +#define LM4550_REG_DONEREAD (1<<1) /* read register once, value should be + * the same currently in the register + */ +#define LM4550_REG_NOSAVE (1<<2) /* values written to this register will + * not be saved in the register + */ +#define LM4550_REG_NOSHADOW (1<<3) /* don't do register shadowing, use plain + * hardware access + */ +#define LM4550_REG_READONLY (1<<4) /* register is read only */ +#define LM4550_REG_FAKEPROBE (1<<5) /* fake write _and_ read actions during + * probe() correctly + */ +#define LM4550_REG_FAKEREAD (1<<6) /* fake read access, always return + * default value + */ +#define LM4550_REG_ALLFAKE (LM4550_REG_FAKEREAD | LM4550_REG_FAKEPROBE) + +struct lm4550_reg { + u16 value; + u16 flag; + u16 wmask; + u16 def; +}; + +struct lm4550_reg lm4550_regfile[64] = { + [AC97_RESET / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_NOSAVE \ + | LM4550_REG_FAKEREAD, + .def = 0x0D50}, + [AC97_MASTER / 2] = {.flag = LM4550_REG_OK + | LM4550_REG_FAKEPROBE, + .wmask = 0x9F1F, + .def = 0x8000}, + [AC97_HEADPHONE / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x9F1F, + .def = 0x8000}, + [AC97_MASTER_MONO / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x801F, + .def = 0x8000}, + [AC97_PC_BEEP / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x801E, + .def = 0x0}, + [AC97_PHONE / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x801F, + .def = 0x8008}, + [AC97_MIC / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x805F, + .def = 0x8008}, + [AC97_LINE / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x9F1F, + .def = 0x8808}, + [AC97_CD / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x9F1F, + .def = 0x8808}, + [AC97_VIDEO / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x9F1F, + .def = 0x8808}, + [AC97_AUX / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x9F1F, + .def = 0x8808}, + [AC97_PCM / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x9F1F, + .def = 0x8008}, + [AC97_REC_SEL / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x707, + .def = 0x0}, + [AC97_REC_GAIN / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .wmask = 0x8F0F, + .def = 0x8000}, + [AC97_GENERAL_PURPOSE / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .def = 0x0, + .wmask = 0xA380}, + [AC97_3D_CONTROL / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEREAD \ + | LM4550_REG_READONLY, + .def = 0x0101}, + [AC97_POWERDOWN / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_NOSHADOW \ + | LM4550_REG_NOSAVE, + .wmask = 0xFF00}, + /* may not write ones to + * REF/ANL/DAC/ADC bits + * FIXME: Is this ok? + */ + [AC97_EXTENDED_ID / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEREAD \ + | LM4550_REG_READONLY, + .def = 0x0201}, /* primary codec */ + [AC97_EXTENDED_STATUS / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_NOSHADOW \ + | LM4550_REG_NOSAVE, + .wmask = 0x1}, + [AC97_PCM_FRONT_DAC_RATE / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .def = 0xBB80, + .wmask = 0xFFFF}, + [AC97_PCM_LR_ADC_RATE / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_FAKEPROBE, + .def = 0xBB80, + .wmask = 0xFFFF}, + [AC97_VENDOR_ID1 / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_READONLY \ + | LM4550_REG_FAKEREAD, + .def = 0x4E53}, + [AC97_VENDOR_ID2 / 2] = {.flag = LM4550_REG_OK \ + | LM4550_REG_READONLY \ + | LM4550_REG_FAKEREAD, + .def = 0x4350} +}; + +#define LM4550_RF_OK(reg) (lm4550_regfile[reg / 2].flag & LM4550_REG_OK) + +static void lm4550_regfile_init(void) +{ + int i; + for (i = 0; i < 64; i++) + if (lm4550_regfile[i].flag & LM4550_REG_FAKEPROBE) + lm4550_regfile[i].value = lm4550_regfile[i].def; +} + +static void lm4550_regfile_write_values_after_init(struct snd_ac97 *ac97) +{ + int i; + for (i = 0; i < 64; i++) + if ((lm4550_regfile[i].flag & LM4550_REG_FAKEPROBE) && + (lm4550_regfile[i].value != lm4550_regfile[i].def)) { + PDEBUG(CODEC_FAKE, "lm4550_regfile_write_values_after_" + "init(): reg=0x%x value=0x%x / %d is different " + "from def=0x%x / %d\n", + i, lm4550_regfile[i].value, + lm4550_regfile[i].value, lm4550_regfile[i].def, + lm4550_regfile[i].def); + snd_ac97_write(ac97, i * 2, lm4550_regfile[i].value); + lm4550_regfile[i].flag |= LM4550_REG_DONEREAD; + } +} + + +/* direct registers */ +#define CR_REG(ml403_ac97cr, x) ((ml403_ac97cr)->port + CR_REG_##x) + +#define CR_REG_PLAYFIFO 0x00 +#define CR_PLAYDATA(a) ((a) & 0xFFFF) + +#define CR_REG_RECFIFO 0x04 +#define CR_RECDATA(a) ((a) & 0xFFFF) + +#define CR_REG_STATUS 0x08 +#define CR_RECOVER (1<<7) +#define CR_PLAYUNDER (1<<6) +#define CR_CODECREADY (1<<5) +#define CR_RAF (1<<4) +#define CR_RECEMPTY (1<<3) +#define CR_RECFULL (1<<2) +#define CR_PLAYHALF (1<<1) +#define CR_PLAYFULL (1<<0) + +#define CR_REG_RESETFIFO 0x0C +#define CR_RECRESET (1<<1) +#define CR_PLAYRESET (1<<0) + +#define CR_REG_CODEC_ADDR 0x10 +/* UG082 says: + * #define CR_CODEC_ADDR(a) ((a) << 1) + * #define CR_CODEC_READ (1<<0) + * #define CR_CODEC_WRITE (0<<0) + */ +/* RefDesign example says: */ +#define CR_CODEC_ADDR(a) ((a) << 0) +#define CR_CODEC_READ (1<<7) +#define CR_CODEC_WRITE (0<<7) + +#define CR_REG_CODEC_DATAREAD 0x14 +#define CR_CODEC_DATAREAD(v) ((v) & 0xFFFF) + +#define CR_REG_CODEC_DATAWRITE 0x18 +#define CR_CODEC_DATAWRITE(v) ((v) & 0xFFFF) + +#define CR_FIFO_SIZE 32 + +struct snd_ml403_ac97cr { + /* lock for access to (controller) registers */ + spinlock_t reg_lock; + /* mutex for the whole sequence of accesses to (controller) registers + * which affect codec registers + */ + struct mutex cdc_mutex; + + int irq; /* for playback */ + int enable_irq; /* for playback */ + + int capture_irq; + int enable_capture_irq; + + struct resource *res_port; + void *port; + + struct snd_ac97 *ac97; + int ac97_fake; +#ifdef CODEC_STAT + int ac97_read; + int ac97_write; +#endif + + struct platform_device *pfdev; + struct snd_card *card; + struct snd_pcm *pcm; + struct snd_pcm_substream *playback_substream; + struct snd_pcm_substream *capture_substream; + + struct snd_pcm_indirect2 ind_rec; /* for playback */ + struct snd_pcm_indirect2 capture_ind2_rec; +}; + +static struct snd_pcm_hardware snd_ml403_ac97cr_playback = { + .info = (SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP_VALID), + .formats = SNDRV_PCM_FMTBIT_S16_BE, + .rates = (SNDRV_PCM_RATE_CONTINUOUS | + SNDRV_PCM_RATE_8000_48000), + .rate_min = 4000, + .rate_max = 48000, + .channels_min = 2, + .channels_max = 2, + .buffer_bytes_max = (128*1024), + .period_bytes_min = CR_FIFO_SIZE/2, + .period_bytes_max = (64*1024), + .periods_min = 2, + .periods_max = (128*1024)/(CR_FIFO_SIZE/2), + .fifo_size = 0, +}; + +static struct snd_pcm_hardware snd_ml403_ac97cr_capture = { + .info = (SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP_VALID), + .formats = SNDRV_PCM_FMTBIT_S16_BE, + .rates = (SNDRV_PCM_RATE_CONTINUOUS | + SNDRV_PCM_RATE_8000_48000), + .rate_min = 4000, + .rate_max = 48000, + .channels_min = 2, + .channels_max = 2, + .buffer_bytes_max = (128*1024), + .period_bytes_min = CR_FIFO_SIZE/2, + .period_bytes_max = (64*1024), + .periods_min = 2, + .periods_max = (128*1024)/(CR_FIFO_SIZE/2), + .fifo_size = 0, +}; + +static size_t +snd_ml403_ac97cr_playback_ind2_zero(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + int copied_words = 0; + u32 full = 0; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + + spin_lock(&ml403_ac97cr->reg_lock); + while ((full = (in_be32(CR_REG(ml403_ac97cr, STATUS)) & + CR_PLAYFULL)) != CR_PLAYFULL) { + out_be32(CR_REG(ml403_ac97cr, PLAYFIFO), 0); + copied_words++; + } + rec->hw_ready = 0; + spin_unlock(&ml403_ac97cr->reg_lock); + + return (size_t) (copied_words * 2); +} + +static size_t +snd_ml403_ac97cr_playback_ind2_copy(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + size_t bytes) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + u16 *src; + int copied_words = 0; + u32 full = 0; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + src = (u16 *)(substream->runtime->dma_area + rec->sw_data); + + spin_lock(&ml403_ac97cr->reg_lock); + while (((full = (in_be32(CR_REG(ml403_ac97cr, STATUS)) & + CR_PLAYFULL)) != CR_PLAYFULL) && (bytes > 1)) { + out_be32(CR_REG(ml403_ac97cr, PLAYFIFO), + CR_PLAYDATA(src[copied_words])); + copied_words++; + bytes = bytes - 2; + } + if (full != CR_PLAYFULL) + rec->hw_ready = 1; + else + rec->hw_ready = 0; + spin_unlock(&ml403_ac97cr->reg_lock); + + return (size_t) (copied_words * 2); +} + +static size_t +snd_ml403_ac97cr_capture_ind2_null(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + int copied_words = 0; + u32 empty = 0; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + + spin_lock(&ml403_ac97cr->reg_lock); + while ((empty = (in_be32(CR_REG(ml403_ac97cr, STATUS)) & + CR_RECEMPTY)) != CR_RECEMPTY) { + volatile u32 trash; + + trash = CR_RECDATA(in_be32(CR_REG(ml403_ac97cr, RECFIFO))); + /* Hmmmm, really necessary? Don't want call to in_be32() + * to be optimised away! + */ + trash++; + copied_words++; + } + rec->hw_ready = 0; + spin_unlock(&ml403_ac97cr->reg_lock); + + return (size_t) (copied_words * 2); +} + +static size_t +snd_ml403_ac97cr_capture_ind2_copy(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, size_t bytes) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + u16 *dst; + int copied_words = 0; + u32 empty = 0; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + dst = (u16 *)(substream->runtime->dma_area + rec->sw_data); + + spin_lock(&ml403_ac97cr->reg_lock); + while (((empty = (in_be32(CR_REG(ml403_ac97cr, STATUS)) & + CR_RECEMPTY)) != CR_RECEMPTY) && (bytes > 1)) { + dst[copied_words] = CR_RECDATA(in_be32(CR_REG(ml403_ac97cr, + RECFIFO))); + copied_words++; + bytes = bytes - 2; + } + if (empty != CR_RECEMPTY) + rec->hw_ready = 1; + else + rec->hw_ready = 0; + spin_unlock(&ml403_ac97cr->reg_lock); + + return (size_t) (copied_words * 2); +} + +static snd_pcm_uframes_t +snd_ml403_ac97cr_pcm_pointer(struct snd_pcm_substream *substream) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + struct snd_pcm_indirect2 *ind2_rec = NULL; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + + if (substream == ml403_ac97cr->playback_substream) + ind2_rec = &ml403_ac97cr->ind_rec; + if (substream == ml403_ac97cr->capture_substream) + ind2_rec = &ml403_ac97cr->capture_ind2_rec; + + if (ind2_rec != NULL) + return snd_pcm_indirect2_pointer(substream, ind2_rec); + return (snd_pcm_uframes_t) 0; +} + +static int +snd_ml403_ac97cr_pcm_playback_trigger(struct snd_pcm_substream *substream, + int cmd) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + int err = 0; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + PDEBUG(WORK_INFO, "trigger(playback): START\n"); + ml403_ac97cr->ind_rec.hw_ready = 1; + + /* clear play FIFO */ + out_be32(CR_REG(ml403_ac97cr, RESETFIFO), CR_PLAYRESET); + + /* enable play irq */ + ml403_ac97cr->enable_irq = 1; + enable_irq(ml403_ac97cr->irq); + break; + case SNDRV_PCM_TRIGGER_STOP: + PDEBUG(WORK_INFO, "trigger(playback): STOP\n"); + ml403_ac97cr->ind_rec.hw_ready = 0; +#ifdef SND_PCM_INDIRECT2_STAT + snd_pcm_indirect2_stat(substream, &ml403_ac97cr->ind_rec); +#endif + /* disable play irq */ + disable_irq_nosync(ml403_ac97cr->irq); + ml403_ac97cr->enable_irq = 0; + break; + default: + err = -EINVAL; + break; + } + PDEBUG(WORK_INFO, "trigger(playback): (done)\n"); + return err; +} + +static int +snd_ml403_ac97cr_pcm_capture_trigger(struct snd_pcm_substream *substream, + int cmd) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + int err = 0; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + PDEBUG(WORK_INFO, "trigger(capture): START\n"); + ml403_ac97cr->capture_ind2_rec.hw_ready = 0; + + /* clear record FIFO */ + out_be32(CR_REG(ml403_ac97cr, RESETFIFO), CR_RECRESET); + + /* enable record irq */ + ml403_ac97cr->enable_capture_irq = 1; + enable_irq(ml403_ac97cr->capture_irq); + break; + case SNDRV_PCM_TRIGGER_STOP: + PDEBUG(WORK_INFO, "trigger(capture): STOP\n"); + ml403_ac97cr->capture_ind2_rec.hw_ready = 0; +#ifdef SND_PCM_INDIRECT2_STAT + snd_pcm_indirect2_stat(substream, + &ml403_ac97cr->capture_ind2_rec); +#endif + /* disable capture irq */ + disable_irq_nosync(ml403_ac97cr->capture_irq); + ml403_ac97cr->enable_capture_irq = 0; + break; + default: + err = -EINVAL; + break; + } + PDEBUG(WORK_INFO, "trigger(capture): (done)\n"); + return err; +} + +static int +snd_ml403_ac97cr_pcm_playback_prepare(struct snd_pcm_substream *substream) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + struct snd_pcm_runtime *runtime; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + runtime = substream->runtime; + + PDEBUG(WORK_INFO, + "prepare(): period_bytes=%d, minperiod_bytes=%d\n", + snd_pcm_lib_period_bytes(substream), CR_FIFO_SIZE / 2); + + /* set sampling rate */ + snd_ac97_set_rate(ml403_ac97cr->ac97, AC97_PCM_FRONT_DAC_RATE, + runtime->rate); + PDEBUG(WORK_INFO, "prepare(): rate=%d\n", runtime->rate); + + /* init struct for intermediate buffer */ + memset(&ml403_ac97cr->ind_rec, 0, + sizeof(struct snd_pcm_indirect2)); + ml403_ac97cr->ind_rec.hw_buffer_size = CR_FIFO_SIZE; + ml403_ac97cr->ind_rec.sw_buffer_size = + snd_pcm_lib_buffer_bytes(substream); + ml403_ac97cr->ind_rec.min_periods = -1; + ml403_ac97cr->ind_rec.min_multiple = + snd_pcm_lib_period_bytes(substream) / (CR_FIFO_SIZE / 2); + PDEBUG(WORK_INFO, "prepare(): hw_buffer_size=%d, " + "sw_buffer_size=%d, min_multiple=%d\n", + CR_FIFO_SIZE, ml403_ac97cr->ind_rec.sw_buffer_size, + ml403_ac97cr->ind_rec.min_multiple); + return 0; +} + +static int +snd_ml403_ac97cr_pcm_capture_prepare(struct snd_pcm_substream *substream) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + struct snd_pcm_runtime *runtime; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + runtime = substream->runtime; + + PDEBUG(WORK_INFO, + "prepare(capture): period_bytes=%d, minperiod_bytes=%d\n", + snd_pcm_lib_period_bytes(substream), CR_FIFO_SIZE / 2); + + /* set sampling rate */ + snd_ac97_set_rate(ml403_ac97cr->ac97, AC97_PCM_LR_ADC_RATE, + runtime->rate); + PDEBUG(WORK_INFO, "prepare(capture): rate=%d\n", runtime->rate); + + /* init struct for intermediate buffer */ + memset(&ml403_ac97cr->capture_ind2_rec, 0, + sizeof(struct snd_pcm_indirect2)); + ml403_ac97cr->capture_ind2_rec.hw_buffer_size = CR_FIFO_SIZE; + ml403_ac97cr->capture_ind2_rec.sw_buffer_size = + snd_pcm_lib_buffer_bytes(substream); + ml403_ac97cr->capture_ind2_rec.min_multiple = + snd_pcm_lib_period_bytes(substream) / (CR_FIFO_SIZE / 2); + PDEBUG(WORK_INFO, "prepare(capture): hw_buffer_size=%d, " + "sw_buffer_size=%d, min_multiple=%d\n", CR_FIFO_SIZE, + ml403_ac97cr->capture_ind2_rec.sw_buffer_size, + ml403_ac97cr->capture_ind2_rec.min_multiple); + return 0; +} + +static int snd_ml403_ac97cr_hw_free(struct snd_pcm_substream *substream) +{ + PDEBUG(WORK_INFO, "hw_free()\n"); + return snd_pcm_lib_free_pages(substream); +} + +static int +snd_ml403_ac97cr_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) +{ + PDEBUG(WORK_INFO, "hw_params(): desired buffer bytes=%d, desired " + "period bytes=%d\n", + params_buffer_bytes(hw_params), params_period_bytes(hw_params)); + return snd_pcm_lib_malloc_pages(substream, + params_buffer_bytes(hw_params)); +} + +static int snd_ml403_ac97cr_playback_open(struct snd_pcm_substream *substream) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + struct snd_pcm_runtime *runtime; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + runtime = substream->runtime; + + PDEBUG(WORK_INFO, "open(playback)\n"); + ml403_ac97cr->playback_substream = substream; + runtime->hw = snd_ml403_ac97cr_playback; + + snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_PERIOD_BYTES, + CR_FIFO_SIZE / 2); + return 0; +} + +static int snd_ml403_ac97cr_capture_open(struct snd_pcm_substream *substream) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + struct snd_pcm_runtime *runtime; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + runtime = substream->runtime; + + PDEBUG(WORK_INFO, "open(capture)\n"); + ml403_ac97cr->capture_substream = substream; + runtime->hw = snd_ml403_ac97cr_capture; + + snd_pcm_hw_constraint_step(runtime, 0, + SNDRV_PCM_HW_PARAM_PERIOD_BYTES, + CR_FIFO_SIZE / 2); + return 0; +} + +static int snd_ml403_ac97cr_playback_close(struct snd_pcm_substream *substream) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + + PDEBUG(WORK_INFO, "close(playback)\n"); + ml403_ac97cr->playback_substream = NULL; + return 0; +} + +static int snd_ml403_ac97cr_capture_close(struct snd_pcm_substream *substream) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + + ml403_ac97cr = snd_pcm_substream_chip(substream); + + PDEBUG(WORK_INFO, "close(capture)\n"); + ml403_ac97cr->capture_substream = NULL; + return 0; +} + +static struct snd_pcm_ops snd_ml403_ac97cr_playback_ops = { + .open = snd_ml403_ac97cr_playback_open, + .close = snd_ml403_ac97cr_playback_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = snd_ml403_ac97cr_hw_params, + .hw_free = snd_ml403_ac97cr_hw_free, + .prepare = snd_ml403_ac97cr_pcm_playback_prepare, + .trigger = snd_ml403_ac97cr_pcm_playback_trigger, + .pointer = snd_ml403_ac97cr_pcm_pointer, +}; + +static struct snd_pcm_ops snd_ml403_ac97cr_capture_ops = { + .open = snd_ml403_ac97cr_capture_open, + .close = snd_ml403_ac97cr_capture_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = snd_ml403_ac97cr_hw_params, + .hw_free = snd_ml403_ac97cr_hw_free, + .prepare = snd_ml403_ac97cr_pcm_capture_prepare, + .trigger = snd_ml403_ac97cr_pcm_capture_trigger, + .pointer = snd_ml403_ac97cr_pcm_pointer, +}; + +static irqreturn_t snd_ml403_ac97cr_irq(int irq, void *dev_id) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + struct platform_device *pfdev; + int cmp_irq; + + ml403_ac97cr = (struct snd_ml403_ac97cr *)dev_id; + if (ml403_ac97cr == NULL) + return IRQ_NONE; + + pfdev = ml403_ac97cr->pfdev; + + /* playback interrupt */ + cmp_irq = platform_get_irq(pfdev, 0); + if (irq == cmp_irq) { + if (ml403_ac97cr->enable_irq) + snd_pcm_indirect2_playback_interrupt( + ml403_ac97cr->playback_substream, + &ml403_ac97cr->ind_rec, + snd_ml403_ac97cr_playback_ind2_copy, + snd_ml403_ac97cr_playback_ind2_zero); + else + goto __disable_irq; + } else { + /* record interrupt */ + cmp_irq = platform_get_irq(pfdev, 1); + if (irq == cmp_irq) { + if (ml403_ac97cr->enable_capture_irq) + snd_pcm_indirect2_capture_interrupt( + ml403_ac97cr->capture_substream, + &ml403_ac97cr->capture_ind2_rec, + snd_ml403_ac97cr_capture_ind2_copy, + snd_ml403_ac97cr_capture_ind2_null); + else + goto __disable_irq; + } else + return IRQ_NONE; + } + return IRQ_HANDLED; + +__disable_irq: + PDEBUG(INIT_INFO, "irq(): irq %d is meant to be disabled! So, now try " + "to disable it _really_!\n", irq); + disable_irq_nosync(irq); + return IRQ_HANDLED; +} + +static unsigned short +snd_ml403_ac97cr_codec_read(struct snd_ac97 *ac97, unsigned short reg) +{ + struct snd_ml403_ac97cr *ml403_ac97cr = ac97->private_data; +#ifdef CODEC_STAT + u32 stat; + u32 rafaccess = 0; +#endif + unsigned long end_time; + u16 value = 0; + + if (!LM4550_RF_OK(reg)) { + snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": " + "access to unknown/unused codec register 0x%x " + "ignored!\n", reg); + return 0; + } + /* check if we can fake/answer this access from our shadow register */ + if ((lm4550_regfile[reg / 2].flag & + (LM4550_REG_DONEREAD | LM4550_REG_ALLFAKE)) && + !(lm4550_regfile[reg / 2].flag & LM4550_REG_NOSHADOW)) { + if (lm4550_regfile[reg / 2].flag & LM4550_REG_FAKEREAD) { + PDEBUG(CODEC_FAKE, "codec_read(): faking read from " + "reg=0x%x, val=0x%x / %d\n", + reg, lm4550_regfile[reg / 2].def, + lm4550_regfile[reg / 2].def); + return lm4550_regfile[reg / 2].def; + } else if ((lm4550_regfile[reg / 2].flag & + LM4550_REG_FAKEPROBE) && + ml403_ac97cr->ac97_fake) { + PDEBUG(CODEC_FAKE, "codec_read(): faking read from " + "reg=0x%x, val=0x%x / %d (probe)\n", + reg, lm4550_regfile[reg / 2].value, + lm4550_regfile[reg / 2].value); + return lm4550_regfile[reg / 2].value; + } else { +#ifdef CODEC_STAT + PDEBUG(CODEC_FAKE, "codec_read(): read access " + "answered by shadow register 0x%x (value=0x%x " + "/ %d) (cw=%d cr=%d)\n", + reg, lm4550_regfile[reg / 2].value, + lm4550_regfile[reg / 2].value, + ml403_ac97cr->ac97_write, + ml403_ac97cr->ac97_read); +#else + PDEBUG(CODEC_FAKE, "codec_read(): read access " + "answered by shadow register 0x%x (value=0x%x " + "/ %d)\n", + reg, lm4550_regfile[reg / 2].value, + lm4550_regfile[reg / 2].value); +#endif + return lm4550_regfile[reg / 2].value; + } + } + /* if we are here, we _have_ to access the codec really, no faking */ + if (mutex_lock_interruptible(&ml403_ac97cr->cdc_mutex) != 0) + return 0; +#ifdef CODEC_STAT + ml403_ac97cr->ac97_read++; +#endif + spin_lock(&ml403_ac97cr->reg_lock); + out_be32(CR_REG(ml403_ac97cr, CODEC_ADDR), + CR_CODEC_ADDR(reg) | CR_CODEC_READ); + spin_unlock(&ml403_ac97cr->reg_lock); + end_time = jiffies + (HZ / CODEC_TIMEOUT_AFTER_READ); + do { + spin_lock(&ml403_ac97cr->reg_lock); +#ifdef CODEC_STAT + rafaccess++; + stat = in_be32(CR_REG(ml403_ac97cr, STATUS)); + if ((stat & CR_RAF) == CR_RAF) { + value = CR_CODEC_DATAREAD( + in_be32(CR_REG(ml403_ac97cr, CODEC_DATAREAD))); + PDEBUG(CODEC_SUCCESS, "codec_read(): (done) reg=0x%x, " + "value=0x%x / %d (STATUS=0x%x)\n", + reg, value, value, stat); +#else + if ((in_be32(CR_REG(ml403_ac97cr, STATUS)) & + CR_RAF) == CR_RAF) { + value = CR_CODEC_DATAREAD( + in_be32(CR_REG(ml403_ac97cr, CODEC_DATAREAD))); + PDEBUG(CODEC_SUCCESS, "codec_read(): (done) " + "reg=0x%x, value=0x%x / %d\n", + reg, value, value); +#endif + lm4550_regfile[reg / 2].value = value; + lm4550_regfile[reg / 2].flag |= LM4550_REG_DONEREAD; + spin_unlock(&ml403_ac97cr->reg_lock); + mutex_unlock(&ml403_ac97cr->cdc_mutex); + return value; + } + spin_unlock(&ml403_ac97cr->reg_lock); + schedule_timeout_uninterruptible(1); + } while (time_after(end_time, jiffies)); + /* read the DATAREAD register anyway, see comment below */ + spin_lock(&ml403_ac97cr->reg_lock); + value = + CR_CODEC_DATAREAD(in_be32(CR_REG(ml403_ac97cr, CODEC_DATAREAD))); + spin_unlock(&ml403_ac97cr->reg_lock); +#ifdef CODEC_STAT + snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": " + "timeout while codec read! " + "(reg=0x%x, last STATUS=0x%x, DATAREAD=0x%x / %d, %d) " + "(cw=%d, cr=%d)\n", + reg, stat, value, value, rafaccess, + ml403_ac97cr->ac97_write, ml403_ac97cr->ac97_read); +#else + snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": " + "timeout while codec read! " + "(reg=0x%x, DATAREAD=0x%x / %d)\n", + reg, value, value); +#endif + /* BUG: This is PURE speculation! But after _most_ read timeouts the + * value in the register is ok! + */ + lm4550_regfile[reg / 2].value = value; + lm4550_regfile[reg / 2].flag |= LM4550_REG_DONEREAD; + mutex_unlock(&ml403_ac97cr->cdc_mutex); + return value; +} + +static void +snd_ml403_ac97cr_codec_write(struct snd_ac97 *ac97, unsigned short reg, + unsigned short val) +{ + struct snd_ml403_ac97cr *ml403_ac97cr = ac97->private_data; + +#ifdef CODEC_STAT + u32 stat; + u32 rafaccess = 0; +#endif +#ifdef CODEC_WRITE_CHECK_RAF + unsigned long end_time; +#endif + + if (!LM4550_RF_OK(reg)) { + snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": " + "access to unknown/unused codec register 0x%x " + "ignored!\n", reg); + return; + } + if (lm4550_regfile[reg / 2].flag & LM4550_REG_READONLY) { + snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": " + "write access to read only codec register 0x%x " + "ignored!\n", reg); + return; + } + if ((val & lm4550_regfile[reg / 2].wmask) != val) { + snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": " + "write access to codec register 0x%x " + "with bad value 0x%x / %d!\n", + reg, val, val); + val = val & lm4550_regfile[reg / 2].wmask; + } + if (((lm4550_regfile[reg / 2].flag & LM4550_REG_FAKEPROBE) && + ml403_ac97cr->ac97_fake) && + !(lm4550_regfile[reg / 2].flag & LM4550_REG_NOSHADOW)) { + PDEBUG(CODEC_FAKE, "codec_write(): faking write to reg=0x%x, " + "val=0x%x / %d\n", reg, val, val); + lm4550_regfile[reg / 2].value = (val & + lm4550_regfile[reg / 2].wmask); + return; + } + if (mutex_lock_interruptible(&ml403_ac97cr->cdc_mutex) != 0) + return; +#ifdef CODEC_STAT + ml403_ac97cr->ac97_write++; +#endif + spin_lock(&ml403_ac97cr->reg_lock); + out_be32(CR_REG(ml403_ac97cr, CODEC_DATAWRITE), + CR_CODEC_DATAWRITE(val)); + out_be32(CR_REG(ml403_ac97cr, CODEC_ADDR), + CR_CODEC_ADDR(reg) | CR_CODEC_WRITE); + spin_unlock(&ml403_ac97cr->reg_lock); +#ifdef CODEC_WRITE_CHECK_RAF + /* check CR_CODEC_RAF bit to see if write access to register is done; + * loop until bit is set or timeout happens + */ + end_time = jiffies + HZ / CODEC_TIMEOUT_AFTER_WRITE; + do { + spin_lock(&ml403_ac97cr->reg_lock); +#ifdef CODEC_STAT + rafaccess++; + stat = in_be32(CR_REG(ml403_ac97cr, STATUS)) + if ((stat & CR_RAF) == CR_RAF) { +#else + if ((in_be32(CR_REG(ml403_ac97cr, STATUS)) & + CR_RAF) == CR_RAF) { +#endif + PDEBUG(CODEC_SUCCESS, "codec_write(): (done) " + "reg=0x%x, value=%d / 0x%x\n", + reg, val, val); + if (!(lm4550_regfile[reg / 2].flag & + LM4550_REG_NOSHADOW) && + !(lm4550_regfile[reg / 2].flag & + LM4550_REG_NOSAVE)) + lm4550_regfile[reg / 2].value = val; + lm4550_regfile[reg / 2].flag |= LM4550_REG_DONEREAD; + spin_unlock(&ml403_ac97cr->reg_lock); + mutex_unlock(&ml403_ac97cr->cdc_mutex); + return; + } + spin_unlock(&ml403_ac97cr->reg_lock); + schedule_timeout_uninterruptible(1); + } while (time_after(end_time, jiffies)); +#ifdef CODEC_STAT + snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": " + "timeout while codec write " + "(reg=0x%x, val=0x%x / %d, last STATUS=0x%x, %d) " + "(cw=%d, cr=%d)\n", + reg, val, val, stat, rafaccess, ml403_ac97cr->ac97_write, + ml403_ac97cr->ac97_read); +#else + snd_printk(KERN_WARNING SND_ML403_AC97CR_DRIVER ": " + "timeout while codec write (reg=0x%x, val=0x%x / %d)\n", + reg, val, val); +#endif +#else /* CODEC_WRITE_CHECK_RAF */ +#if CODEC_WAIT_AFTER_WRITE > 0 + /* officially, in AC97 spec there is no possibility for a AC97 + * controller to determine, if write access is done or not - so: How + * is Xilinx able to provide a RAF bit for write access? + * => very strange, thus just don't check RAF bit (compare with + * Xilinx's example app in EDK 8.1i) and wait + */ + schedule_timeout_uninterruptible(HZ / CODEC_WAIT_AFTER_WRITE); +#endif + PDEBUG(CODEC_SUCCESS, "codec_write(): (done) " + "reg=0x%x, value=%d / 0x%x (no RAF check)\n", + reg, val, val); +#endif + mutex_unlock(&ml403_ac97cr->cdc_mutex); + return; +} + +static int __devinit +snd_ml403_ac97cr_chip_init(struct snd_ml403_ac97cr *ml403_ac97cr) +{ + unsigned long end_time; + PDEBUG(INIT_INFO, "chip_init():\n"); + end_time = jiffies + HZ / CODEC_TIMEOUT_ON_INIT; + do { + if (in_be32(CR_REG(ml403_ac97cr, STATUS)) & CR_CODECREADY) { + /* clear both hardware FIFOs */ + out_be32(CR_REG(ml403_ac97cr, RESETFIFO), + CR_RECRESET | CR_PLAYRESET); + PDEBUG(INIT_INFO, "chip_init(): (done)\n"); + return 0; + } + schedule_timeout_uninterruptible(1); + } while (time_after(end_time, jiffies)); + snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " + "timeout while waiting for codec, " + "not ready!\n"); + return -EBUSY; +} + +static int snd_ml403_ac97cr_free(struct snd_ml403_ac97cr *ml403_ac97cr) +{ + PDEBUG(INIT_INFO, "free():\n"); + /* irq release */ + if (ml403_ac97cr->irq >= 0) + free_irq(ml403_ac97cr->irq, ml403_ac97cr); + if (ml403_ac97cr->capture_irq >= 0) + free_irq(ml403_ac97cr->capture_irq, ml403_ac97cr); + /* give back "port" */ + if (ml403_ac97cr->port != NULL) + iounmap(ml403_ac97cr->port); + kfree(ml403_ac97cr); + PDEBUG(INIT_INFO, "free(): (done)\n"); + return 0; +} + +static int snd_ml403_ac97cr_dev_free(struct snd_device *snddev) +{ + struct snd_ml403_ac97cr *ml403_ac97cr = snddev->device_data; + PDEBUG(INIT_INFO, "dev_free():\n"); + return snd_ml403_ac97cr_free(ml403_ac97cr); +} + +static int __devinit +snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev, + struct snd_ml403_ac97cr **rml403_ac97cr) +{ + struct snd_ml403_ac97cr *ml403_ac97cr; + int err; + static struct snd_device_ops ops = { + .dev_free = snd_ml403_ac97cr_dev_free, + }; + struct resource *resource; + int irq; + + *rml403_ac97cr = NULL; + ml403_ac97cr = kzalloc(sizeof(*ml403_ac97cr), GFP_KERNEL); + if (ml403_ac97cr == NULL) + return -ENOMEM; + spin_lock_init(&ml403_ac97cr->reg_lock); + mutex_init(&ml403_ac97cr->cdc_mutex); + ml403_ac97cr->card = card; + ml403_ac97cr->pfdev = pfdev; + ml403_ac97cr->irq = -1; + ml403_ac97cr->enable_irq = 0; + ml403_ac97cr->capture_irq = -1; + ml403_ac97cr->enable_capture_irq = 0; + ml403_ac97cr->port = NULL; + ml403_ac97cr->res_port = NULL; + + PDEBUG(INIT_INFO, "Trying to reserve resources now ...\n"); + resource = platform_get_resource(pfdev, IORESOURCE_MEM, 0); + /* get "port" */ + ml403_ac97cr->port = ioremap_nocache(resource->start, + (resource->end) - + (resource->start) + 1); + if (ml403_ac97cr->port == NULL) { + snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " + "unable to remap memory region (%x to %x)\n", + resource->start, resource->end); + snd_ml403_ac97cr_free(ml403_ac97cr); + return -EBUSY; + } + snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": " + "remap controller memory region to " + "0x%x done\n", (unsigned int)ml403_ac97cr->port); + /* get irq */ + irq = platform_get_irq(pfdev, 0); + if (request_irq(irq, snd_ml403_ac97cr_irq, IRQF_DISABLED, + pfdev->dev.bus_id, (void *)ml403_ac97cr)) { + snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " + "unable to grab IRQ %d\n", + irq); + snd_ml403_ac97cr_free(ml403_ac97cr); + return -EBUSY; + } + ml403_ac97cr->irq = irq; + snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": " + "request (playback) irq %d done\n", + ml403_ac97cr->irq); + irq = platform_get_irq(pfdev, 1); + if (request_irq(irq, snd_ml403_ac97cr_irq, IRQF_DISABLED, + pfdev->dev.bus_id, (void *)ml403_ac97cr)) { + snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " + "unable to grab IRQ %d\n", + irq); + snd_ml403_ac97cr_free(ml403_ac97cr); + return -EBUSY; + } + ml403_ac97cr->capture_irq = irq; + snd_printk(KERN_INFO SND_ML403_AC97CR_DRIVER ": " + "request (capture) irq %d done\n", + ml403_ac97cr->capture_irq); + + err = snd_ml403_ac97cr_chip_init(ml403_ac97cr); + if (err < 0) { + snd_ml403_ac97cr_free(ml403_ac97cr); + return err; + } + + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ml403_ac97cr, &ops); + if (err < 0) { + PDEBUG(INIT_FAILURE, "probe(): snd_device_new() failed!\n"); + snd_ml403_ac97cr_free(ml403_ac97cr); + return err; + } + + snd_card_set_dev(card, &pfdev->dev); + + *rml403_ac97cr = ml403_ac97cr; + return 0; +} + +static void snd_ml403_ac97cr_mixer_free(struct snd_ac97 *ac97) +{ + struct snd_ml403_ac97cr *ml403_ac97cr = ac97->private_data; + PDEBUG(INIT_INFO, "mixer_free():\n"); + ml403_ac97cr->ac97 = NULL; + PDEBUG(INIT_INFO, "mixer_free(): (done)\n"); +} + +static int __devinit +snd_ml403_ac97cr_mixer(struct snd_ml403_ac97cr *ml403_ac97cr) +{ + struct snd_ac97_bus *bus; + struct snd_ac97_template ac97; + int err; + static struct snd_ac97_bus_ops ops = { + .write = snd_ml403_ac97cr_codec_write, + .read = snd_ml403_ac97cr_codec_read, + }; + PDEBUG(INIT_INFO, "mixer():\n"); + err = snd_ac97_bus(ml403_ac97cr->card, 0, &ops, NULL, &bus); + if (err < 0) + return err; + + memset(&ac97, 0, sizeof(ac97)); + ml403_ac97cr->ac97_fake = 1; + lm4550_regfile_init(); +#ifdef CODEC_STAT + ml403_ac97cr->ac97_read = 0; + ml403_ac97cr->ac97_write = 0; +#endif + ac97.private_data = ml403_ac97cr; + ac97.private_free = snd_ml403_ac97cr_mixer_free; + ac97.scaps = AC97_SCAP_AUDIO | AC97_SCAP_SKIP_MODEM | + AC97_SCAP_NO_SPDIF; + err = snd_ac97_mixer(bus, &ac97, &ml403_ac97cr->ac97); + ml403_ac97cr->ac97_fake = 0; + lm4550_regfile_write_values_after_init(ml403_ac97cr->ac97); + PDEBUG(INIT_INFO, "mixer(): (done) snd_ac97_mixer()=%d\n", err); + return err; +} + +static int __devinit +snd_ml403_ac97cr_pcm(struct snd_ml403_ac97cr *ml403_ac97cr, int device, + struct snd_pcm **rpcm) +{ + struct snd_pcm *pcm; + int err; + + if (rpcm) + *rpcm = NULL; + err = snd_pcm_new(ml403_ac97cr->card, "ML403AC97CR/1", device, 1, 1, + &pcm); + if (err < 0) + return err; + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, + &snd_ml403_ac97cr_playback_ops); + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, + &snd_ml403_ac97cr_capture_ops); + pcm->private_data = ml403_ac97cr; + pcm->info_flags = 0; + strcpy(pcm->name, "ML403AC97CR DAC/ADC"); + ml403_ac97cr->pcm = pcm; + + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, + snd_dma_continuous_data(GFP_KERNEL), + 64 * 1024, + 128 * 1024); + if (rpcm) + *rpcm = pcm; + return 0; +} + +static int __devinit snd_ml403_ac97cr_probe(struct platform_device *pfdev) +{ + struct snd_card *card; + struct snd_ml403_ac97cr *ml403_ac97cr = NULL; + int err; + int dev = pfdev->id; + + if (dev >= SNDRV_CARDS) + return -ENODEV; + if (!enable[dev]) + return -ENOENT; + + card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); + if (card == NULL) + return -ENOMEM; + err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr); + if (err < 0) { + PDEBUG(INIT_FAILURE, "probe(): create failed!\n"); + snd_card_free(card); + return err; + } + PDEBUG(INIT_INFO, "probe(): create done\n"); + card->private_data = ml403_ac97cr; + err = snd_ml403_ac97cr_mixer(ml403_ac97cr); + if (err < 0) { + snd_card_free(card); + return err; + } + PDEBUG(INIT_INFO, "probe(): mixer done\n"); + err = snd_ml403_ac97cr_pcm(ml403_ac97cr, 0, NULL); + if (err < 0) { + snd_card_free(card); + return err; + } + PDEBUG(INIT_INFO, "probe(): PCM done\n"); + strcpy(card->driver, SND_ML403_AC97CR_DRIVER); + strcpy(card->shortname, "ML403 AC97 Controller Reference"); + sprintf(card->longname, "%s %s at 0x%lx, irq %i & %i, device %i", + card->shortname, card->driver, + (unsigned long)ml403_ac97cr->port, ml403_ac97cr->irq, + ml403_ac97cr->capture_irq, dev + 1); + + err = snd_card_register(card); + if (err < 0) { + snd_card_free(card); + return err; + } + platform_set_drvdata(pfdev, card); + PDEBUG(INIT_INFO, "probe(): (done)\n"); + return 0; +} + +static int snd_ml403_ac97cr_remove(struct platform_device *pfdev) +{ + snd_card_free(platform_get_drvdata(pfdev)); + platform_set_drvdata(pfdev, NULL); + return 0; +} + +static struct platform_driver snd_ml403_ac97cr_driver = { + .probe = snd_ml403_ac97cr_probe, + .remove = snd_ml403_ac97cr_remove, + .driver = { + .name = SND_ML403_AC97CR_DRIVER, + }, +}; + +static int __init alsa_card_ml403_ac97cr_init(void) +{ + return platform_driver_register(&snd_ml403_ac97cr_driver); +} + +static void __exit alsa_card_ml403_ac97cr_exit(void) +{ + platform_driver_unregister(&snd_ml403_ac97cr_driver); +} + +module_init(alsa_card_ml403_ac97cr_init) +module_exit(alsa_card_ml403_ac97cr_exit) diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c index 3306ecd..b57f2d5 100644 --- a/sound/drivers/mpu401/mpu401_uart.c +++ b/sound/drivers/mpu401/mpu401_uart.c @@ -97,23 +97,27 @@ static void snd_mpu401_uart_clear_rx(struct snd_mpu401 *mpu) static void uart_interrupt_tx(struct snd_mpu401 *mpu) { + unsigned long flags; + if (test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode) && test_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode)) { - spin_lock(&mpu->output_lock); + spin_lock_irqsave(&mpu->output_lock, flags); snd_mpu401_uart_output_write(mpu); - spin_unlock(&mpu->output_lock); + spin_unlock_irqrestore(&mpu->output_lock, flags); } } static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu) { + unsigned long flags; + if (mpu->info_flags & MPU401_INFO_INPUT) { - spin_lock(&mpu->input_lock); + spin_lock_irqsave(&mpu->input_lock, flags); if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) snd_mpu401_uart_input_read(mpu); else snd_mpu401_uart_clear_rx(mpu); - spin_unlock(&mpu->input_lock); + spin_unlock_irqrestore(&mpu->input_lock, flags); } if (! (mpu->info_flags & MPU401_INFO_TX_IRQ)) /* ok. for better Tx performance try do some output diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c index dcc90f9..68070cc 100644 --- a/sound/drivers/mts64.c +++ b/sound/drivers/mts64.c @@ -461,13 +461,14 @@ static int snd_mts64_ctl_smpte_switch_put(struct snd_kcontrol* kctl, { struct mts64 *mts = snd_kcontrol_chip(kctl); int changed = 0; + int val = !!uctl->value.integer.value[0]; spin_lock_irq(&mts->lock); - if (mts->smpte_switch == uctl->value.integer.value[0]) + if (mts->smpte_switch == val) goto __out; changed = 1; - mts->smpte_switch = uctl->value.integer.value[0]; + mts->smpte_switch = val; if (mts->smpte_switch) { mts64_smpte_start(mts->pardev->port, mts->time[0], mts->time[1], @@ -541,12 +542,13 @@ static int snd_mts64_ctl_smpte_time_put(struct snd_kcontrol *kctl, { struct mts64 *mts = snd_kcontrol_chip(kctl); int idx = kctl->private_value; + unsigned int time = uctl->value.integer.value[0] % 60; int changed = 0; spin_lock_irq(&mts->lock); - if (mts->time[idx] != uctl->value.integer.value[0]) { + if (mts->time[idx] != time) { changed = 1; - mts->time[idx] = uctl->value.integer.value[0]; + mts->time[idx] = time; } spin_unlock_irq(&mts->lock); @@ -636,6 +638,8 @@ static int snd_mts64_ctl_smpte_fps_put(struct snd_kcontrol *kctl, struct mts64 *mts = snd_kcontrol_chip(kctl); int changed = 0; + if (uctl->value.enumerated.item[0] >= 5) + return -EINVAL; spin_lock_irq(&mts->lock); if (mts->fps != uctl->value.enumerated.item[0]) { changed = 1; diff --git a/sound/drivers/opl3/opl3_lib.c b/sound/drivers/opl3/opl3_lib.c index a2b9ce0..ebe4359 100644 --- a/sound/drivers/opl3/opl3_lib.c +++ b/sound/drivers/opl3/opl3_lib.c @@ -327,6 +327,7 @@ static int snd_opl3_free(struct snd_opl3 *opl3) snd_assert(opl3 != NULL, return -ENXIO); if (opl3->private_free) opl3->private_free(opl3); + snd_opl3_clear_patches(opl3); release_and_free_resource(opl3->res_l_port); release_and_free_resource(opl3->res_r_port); kfree(opl3); @@ -360,7 +361,6 @@ int snd_opl3_new(struct snd_card *card, opl3->hardware = hardware; spin_lock_init(&opl3->reg_lock); spin_lock_init(&opl3->timer_lock); - mutex_init(&opl3->access_mutex); if ((err = snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops)) < 0) { snd_opl3_free(opl3); @@ -496,6 +496,7 @@ int snd_opl3_hwdep_new(struct snd_opl3 * opl3, return err; } hw->private_data = opl3; + hw->exclusive = 1; #ifdef CONFIG_SND_OSSEMUL if (device == 0) { hw->oss_type = SNDRV_OSS_DEVICE_TYPE_DMFM; @@ -521,8 +522,10 @@ int snd_opl3_hwdep_new(struct snd_opl3 * opl3, /* operators - only ioctl */ hw->ops.open = snd_opl3_open; hw->ops.ioctl = snd_opl3_ioctl; + hw->ops.write = snd_opl3_write; hw->ops.release = snd_opl3_release; + opl3->hwdep = hw; opl3->seq_dev_num = seq_device; #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)) if (snd_seq_device_new(card, seq_device, SNDRV_SEQ_DEV_ID_OPL3, diff --git a/sound/drivers/opl3/opl3_midi.c b/sound/drivers/opl3/opl3_midi.c index 3557b6e..cebcb8b 100644 --- a/sound/drivers/opl3/opl3_midi.c +++ b/sound/drivers/opl3/opl3_midi.c @@ -289,8 +289,6 @@ static int snd_opl3_oss_map[MAX_OPL3_VOICES] = { void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) { struct snd_opl3 *opl3; - struct snd_seq_instr wanted; - struct snd_seq_kinstr *kinstr; int instr_4op; int voice; @@ -306,11 +304,13 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) unsigned char voice_offset; unsigned short opl3_reg; unsigned char reg_val; + unsigned char prg, bank; int key = note; unsigned char fnum, blocknum; int i; + struct fm_patch *patch; struct fm_instrument *fm; unsigned long flags; @@ -320,19 +320,17 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) snd_printk("Note on, ch %i, inst %i, note %i, vel %i\n", chan->number, chan->midi_program, note, vel); #endif - wanted.cluster = 0; - wanted.std = SNDRV_SEQ_INSTR_TYPE2_OPL2_3; /* in SYNTH mode, application takes care of voices */ /* in SEQ mode, drum voice numbers are notes on drum channel */ if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { if (chan->drum_channel) { /* percussion instruments are located in bank 128 */ - wanted.bank = 128; - wanted.prg = note; + bank = 128; + prg = note; } else { - wanted.bank = chan->gm_bank_select; - wanted.prg = chan->midi_program; + bank = chan->gm_bank_select; + prg = chan->midi_program; } } else { /* Prepare for OSS mode */ @@ -340,8 +338,8 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) return; /* OSS instruments are located in bank 127 */ - wanted.bank = 127; - wanted.prg = chan->midi_program; + bank = 127; + prg = chan->midi_program; } spin_lock_irqsave(&opl3->voice_lock, flags); @@ -353,15 +351,14 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) } __extra_prg: - kinstr = snd_seq_instr_find(opl3->ilist, &wanted, 1, 0); - if (kinstr == NULL) { + patch = snd_opl3_find_patch(opl3, prg, bank, 0); + if (!patch) { spin_unlock_irqrestore(&opl3->voice_lock, flags); return; } - fm = KINSTR_DATA(kinstr); - - switch (fm->type) { + fm = &patch->inst; + switch (patch->type) { case FM_PATCH_OPL2: instr_4op = 0; break; @@ -371,14 +368,12 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) break; } default: - snd_seq_instr_free_use(opl3->ilist, kinstr); spin_unlock_irqrestore(&opl3->voice_lock, flags); return; } - #ifdef DEBUG_MIDI snd_printk(" --> OPL%i instrument: %s\n", - instr_4op ? 3 : 2, kinstr->name); + instr_4op ? 3 : 2, patch->name); #endif /* in SYNTH mode, application takes care of voices */ /* in SEQ mode, allocate voice on free OPL3 channel */ @@ -569,8 +564,6 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) /* get extra pgm, but avoid possible loops */ extra_prg = (extra_prg) ? 0 : fm->modes; - snd_seq_instr_free_use(opl3->ilist, kinstr); - /* do the bookkeeping */ vp->time = opl3->use_time++; vp->note = key; @@ -601,12 +594,12 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) /* allocate extra program if specified in patch library */ if (extra_prg) { if (extra_prg > 128) { - wanted.bank = 128; + bank = 128; /* percussions start at 35 */ - wanted.prg = extra_prg - 128 + 35 - 1; + prg = extra_prg - 128 + 35 - 1; } else { - wanted.bank = 0; - wanted.prg = extra_prg - 1; + bank = 0; + prg = extra_prg - 1; } #ifdef DEBUG_MIDI snd_printk(" *** allocating extra program\n"); diff --git a/sound/drivers/opl3/opl3_oss.c b/sound/drivers/opl3/opl3_oss.c index 5fd3a4c..239347f 100644 --- a/sound/drivers/opl3/opl3_oss.c +++ b/sound/drivers/opl3/opl3_oss.c @@ -195,17 +195,6 @@ static int snd_opl3_close_seq_oss(struct snd_seq_oss_arg *arg) /* load patch */ -/* offsets for SBI params */ -#define AM_VIB 0 -#define KSL_LEVEL 2 -#define ATTACK_DECAY 4 -#define SUSTAIN_RELEASE 6 -#define WAVE_SELECT 8 - -/* offset for SBI instrument */ -#define CONNECTION 10 -#define OFFSET_4OP 11 - /* from sound_config.h */ #define SBFM_MAXINSTR 256 @@ -213,112 +202,42 @@ static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format, const char __user *buf, int offs, int count) { struct snd_opl3 *opl3; - int err = -EINVAL; + struct sbi_instrument sbi; + char name[32]; + int err, type; snd_assert(arg != NULL, return -ENXIO); opl3 = arg->private_data; - if ((format == FM_PATCH) || (format == OPL3_PATCH)) { - struct sbi_instrument sbi; + if (format == FM_PATCH) + type = FM_PATCH_OPL2; + else if (format == OPL3_PATCH) + type = FM_PATCH_OPL3; + else + return -EINVAL; - size_t size; - struct snd_seq_instr_header *put; - struct snd_seq_instr_data *data; - struct fm_xinstrument *xinstr; + if (count < (int)sizeof(sbi)) { + snd_printk("FM Error: Patch record too short\n"); + return -EINVAL; + } + if (copy_from_user(&sbi, buf, sizeof(sbi))) + return -EFAULT; - struct snd_seq_event ev; - int i; + if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) { + snd_printk("FM Error: Invalid instrument number %d\n", + sbi.channel); + return -EINVAL; + } - mm_segment_t fs; + memset(name, 0, sizeof(name)); + sprintf(name, "Chan%d", sbi.channel); - if (count < (int)sizeof(sbi)) { - snd_printk("FM Error: Patch record too short\n"); - return -EINVAL; - } - if (copy_from_user(&sbi, buf, sizeof(sbi))) - return -EFAULT; + err = snd_opl3_load_patch(opl3, sbi.channel, 127, type, name, NULL, + sbi.operators); + if (err < 0) + return err; - if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) { - snd_printk("FM Error: Invalid instrument number %d\n", sbi.channel); - return -EINVAL; - } - - size = sizeof(*put) + sizeof(struct fm_xinstrument); - put = kzalloc(size, GFP_KERNEL); - if (put == NULL) - return -ENOMEM; - /* build header */ - data = &put->data; - data->type = SNDRV_SEQ_INSTR_ATYPE_DATA; - strcpy(data->data.format, SNDRV_SEQ_INSTR_ID_OPL2_3); - /* build data section */ - xinstr = (struct fm_xinstrument *)(data + 1); - xinstr->stype = FM_STRU_INSTR; - - for (i = 0; i < 2; i++) { - xinstr->op[i].am_vib = sbi.operators[AM_VIB + i]; - xinstr->op[i].ksl_level = sbi.operators[KSL_LEVEL + i]; - xinstr->op[i].attack_decay = sbi.operators[ATTACK_DECAY + i]; - xinstr->op[i].sustain_release = sbi.operators[SUSTAIN_RELEASE + i]; - xinstr->op[i].wave_select = sbi.operators[WAVE_SELECT + i]; - } - xinstr->feedback_connection[0] = sbi.operators[CONNECTION]; - - if (format == OPL3_PATCH) { - xinstr->type = FM_PATCH_OPL3; - for (i = 0; i < 2; i++) { - xinstr->op[i+2].am_vib = sbi.operators[OFFSET_4OP + AM_VIB + i]; - xinstr->op[i+2].ksl_level = sbi.operators[OFFSET_4OP + KSL_LEVEL + i]; - xinstr->op[i+2].attack_decay = sbi.operators[OFFSET_4OP + ATTACK_DECAY + i]; - xinstr->op[i+2].sustain_release = sbi.operators[OFFSET_4OP + SUSTAIN_RELEASE + i]; - xinstr->op[i+2].wave_select = sbi.operators[OFFSET_4OP + WAVE_SELECT + i]; - } - xinstr->feedback_connection[1] = sbi.operators[OFFSET_4OP + CONNECTION]; - } else { - xinstr->type = FM_PATCH_OPL2; - } - - put->id.instr.std = SNDRV_SEQ_INSTR_TYPE2_OPL2_3; - put->id.instr.bank = 127; - put->id.instr.prg = sbi.channel; - put->cmd = SNDRV_SEQ_INSTR_PUT_CMD_CREATE; - - memset (&ev, 0, sizeof(ev)); - ev.source.client = SNDRV_SEQ_CLIENT_OSS; - ev.dest = arg->addr; - - ev.flags = SNDRV_SEQ_EVENT_LENGTH_VARUSR; - ev.queue = SNDRV_SEQ_QUEUE_DIRECT; - - fs = snd_enter_user(); - __again: - ev.type = SNDRV_SEQ_EVENT_INSTR_PUT; - ev.data.ext.len = size; - ev.data.ext.ptr = put; - - err = snd_seq_instr_event(&opl3->fm_ops, opl3->ilist, &ev, - opl3->seq_client, 0, 0); - if (err == -EBUSY) { - struct snd_seq_instr_header remove; - - memset (&remove, 0, sizeof(remove)); - remove.cmd = SNDRV_SEQ_INSTR_FREE_CMD_SINGLE; - remove.id.instr = put->id.instr; - - /* remove instrument */ - ev.type = SNDRV_SEQ_EVENT_INSTR_FREE; - ev.data.ext.len = sizeof(remove); - ev.data.ext.ptr = &remove; - - snd_seq_instr_event(&opl3->fm_ops, opl3->ilist, &ev, - opl3->seq_client, 0, 0); - goto __again; - } - snd_leave_user(fs); - - kfree(put); - } - return err; + return sizeof(sbi); } /* ioctl */ diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c index 96762c9..2d33f53 100644 --- a/sound/drivers/opl3/opl3_seq.c +++ b/sound/drivers/opl3/opl3_seq.c @@ -51,14 +51,15 @@ void snd_opl3_synth_use_dec(struct snd_opl3 * opl3) int snd_opl3_synth_setup(struct snd_opl3 * opl3) { int idx; + struct snd_hwdep *hwdep = opl3->hwdep; - mutex_lock(&opl3->access_mutex); - if (opl3->used) { - mutex_unlock(&opl3->access_mutex); + mutex_lock(&hwdep->open_mutex); + if (hwdep->used) { + mutex_unlock(&hwdep->open_mutex); return -EBUSY; } - opl3->used++; - mutex_unlock(&opl3->access_mutex); + hwdep->used++; + mutex_unlock(&hwdep->open_mutex); snd_opl3_reset(opl3); @@ -81,6 +82,7 @@ int snd_opl3_synth_setup(struct snd_opl3 * opl3) void snd_opl3_synth_cleanup(struct snd_opl3 * opl3) { unsigned long flags; + struct snd_hwdep *hwdep; /* Stop system timer */ spin_lock_irqsave(&opl3->sys_timer_lock, flags); @@ -91,9 +93,11 @@ void snd_opl3_synth_cleanup(struct snd_opl3 * opl3) spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); snd_opl3_reset(opl3); - mutex_lock(&opl3->access_mutex); - opl3->used--; - mutex_unlock(&opl3->access_mutex); + hwdep = opl3->hwdep; + mutex_lock(&hwdep->open_mutex); + hwdep->used--; + mutex_unlock(&hwdep->open_mutex); + wake_up(&hwdep->open_wait); } static int snd_opl3_synth_use(void *private_data, struct snd_seq_port_subscribe * info) @@ -152,15 +156,7 @@ static int snd_opl3_synth_event_input(struct snd_seq_event * ev, int direct, { struct snd_opl3 *opl3 = private_data; - if (ev->type >= SNDRV_SEQ_EVENT_INSTR_BEGIN && - ev->type <= SNDRV_SEQ_EVENT_INSTR_CHANGE) { - if (direct) { - snd_seq_instr_event(&opl3->fm_ops, opl3->ilist, ev, - opl3->seq_client, atomic, hop); - } - } else { - snd_midi_process_event(&opl3_ops, ev, opl3->chset); - } + snd_midi_process_event(&opl3_ops, ev, opl3->chset); return 0; } @@ -249,16 +245,6 @@ static int snd_opl3_seq_new_device(struct snd_seq_device *dev) return err; } - /* initialize instrument list */ - opl3->ilist = snd_seq_instr_list_new(); - if (opl3->ilist == NULL) { - snd_seq_delete_kernel_client(client); - opl3->seq_client = -1; - return -ENOMEM; - } - opl3->ilist->flags = SNDRV_SEQ_INSTR_FLG_DIRECT; - snd_seq_fm_init(&opl3->fm_ops, NULL); - /* setup system timer */ init_timer(&opl3->tlist); opl3->tlist.function = snd_opl3_timer_func; @@ -287,8 +273,6 @@ static int snd_opl3_seq_delete_device(struct snd_seq_device *dev) snd_seq_delete_kernel_client(opl3->seq_client); opl3->seq_client = -1; } - if (opl3->ilist) - snd_seq_instr_list_free(&opl3->ilist); return 0; } diff --git a/sound/drivers/opl3/opl3_synth.c b/sound/drivers/opl3/opl3_synth.c index a4b3543..a7bf7a4 100644 --- a/sound/drivers/opl3/opl3_synth.c +++ b/sound/drivers/opl3/opl3_synth.c @@ -76,16 +76,6 @@ static int snd_opl3_set_connection(struct snd_opl3 * opl3, int connection); */ int snd_opl3_open(struct snd_hwdep * hw, struct file *file) { - struct snd_opl3 *opl3 = hw->private_data; - - mutex_lock(&opl3->access_mutex); - if (opl3->used) { - mutex_unlock(&opl3->access_mutex); - return -EAGAIN; - } - opl3->used++; - mutex_unlock(&opl3->access_mutex); - return 0; } @@ -165,6 +155,10 @@ int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file, #endif return snd_opl3_set_connection(opl3, (int) arg); + case SNDRV_DM_FM_IOCTL_CLEAR_PATCHES: + snd_opl3_clear_patches(opl3); + return 0; + #ifdef CONFIG_SND_DEBUG default: snd_printk("unknown IOCTL: 0x%x\n", cmd); @@ -181,12 +175,172 @@ int snd_opl3_release(struct snd_hwdep * hw, struct file *file) struct snd_opl3 *opl3 = hw->private_data; snd_opl3_reset(opl3); - mutex_lock(&opl3->access_mutex); - opl3->used--; - mutex_unlock(&opl3->access_mutex); + return 0; +} + +/* + * write the device - load patches + */ +long snd_opl3_write(struct snd_hwdep *hw, const char __user *buf, long count, + loff_t *offset) +{ + struct snd_opl3 *opl3 = hw->private_data; + long result = 0; + int err = 0; + struct sbi_patch inst; + + while (count >= sizeof(inst)) { + unsigned char type; + if (copy_from_user(&inst, buf, sizeof(inst))) + return -EFAULT; + if (!memcmp(inst.key, FM_KEY_SBI, 4) || + !memcmp(inst.key, FM_KEY_2OP, 4)) + type = FM_PATCH_OPL2; + else if (!memcmp(inst.key, FM_KEY_4OP, 4)) + type = FM_PATCH_OPL3; + else /* invalid type */ + break; + err = snd_opl3_load_patch(opl3, inst.prog, inst.bank, type, + inst.name, inst.extension, + inst.data); + if (err < 0) + break; + result += sizeof(inst); + count -= sizeof(inst); + } + return result > 0 ? result : err; +} + + +/* + * Patch management + */ + +/* offsets for SBI params */ +#define AM_VIB 0 +#define KSL_LEVEL 2 +#define ATTACK_DECAY 4 +#define SUSTAIN_RELEASE 6 +#define WAVE_SELECT 8 + +/* offset for SBI instrument */ +#define CONNECTION 10 +#define OFFSET_4OP 11 + +/* + * load a patch, obviously. + * + * loaded on the given program and bank numbers with the given type + * (FM_PATCH_OPLx). + * data is the pointer of SBI record _without_ header (key and name). + * name is the name string of the patch. + * ext is the extension data of 7 bytes long (stored in name of SBI + * data up to offset 25), or NULL to skip. + * return 0 if successful or a negative error code. + */ +int snd_opl3_load_patch(struct snd_opl3 *opl3, + int prog, int bank, int type, + const char *name, + const unsigned char *ext, + const unsigned char *data) +{ + struct fm_patch *patch; + int i; + + patch = snd_opl3_find_patch(opl3, prog, bank, 1); + if (!patch) + return -ENOMEM; + + patch->type = type; + + for (i = 0; i < 2; i++) { + patch->inst.op[i].am_vib = data[AM_VIB + i]; + patch->inst.op[i].ksl_level = data[KSL_LEVEL + i]; + patch->inst.op[i].attack_decay = data[ATTACK_DECAY + i]; + patch->inst.op[i].sustain_release = data[SUSTAIN_RELEASE + i]; + patch->inst.op[i].wave_select = data[WAVE_SELECT + i]; + } + patch->inst.feedback_connection[0] = data[CONNECTION]; + + if (type == FM_PATCH_OPL3) { + for (i = 0; i < 2; i++) { + patch->inst.op[i+2].am_vib = + data[OFFSET_4OP + AM_VIB + i]; + patch->inst.op[i+2].ksl_level = + data[OFFSET_4OP + KSL_LEVEL + i]; + patch->inst.op[i+2].attack_decay = + data[OFFSET_4OP + ATTACK_DECAY + i]; + patch->inst.op[i+2].sustain_release = + data[OFFSET_4OP + SUSTAIN_RELEASE + i]; + patch->inst.op[i+2].wave_select = + data[OFFSET_4OP + WAVE_SELECT + i]; + } + patch->inst.feedback_connection[1] = + data[OFFSET_4OP + CONNECTION]; + } + + if (ext) { + patch->inst.echo_delay = ext[0]; + patch->inst.echo_atten = ext[1]; + patch->inst.chorus_spread = ext[2]; + patch->inst.trnsps = ext[3]; + patch->inst.fix_dur = ext[4]; + patch->inst.modes = ext[5]; + patch->inst.fix_key = ext[6]; + } + + if (name) + strlcpy(patch->name, name, sizeof(patch->name)); return 0; } +EXPORT_SYMBOL(snd_opl3_load_patch); + +/* + * find a patch with the given program and bank numbers, returns its pointer + * if no matching patch is found and create_patch is set, it creates a + * new patch object. + */ +struct fm_patch *snd_opl3_find_patch(struct snd_opl3 *opl3, int prog, int bank, + int create_patch) +{ + /* pretty dumb hash key */ + unsigned int key = (prog + bank) % OPL3_PATCH_HASH_SIZE; + struct fm_patch *patch; + + for (patch = opl3->patch_table[key]; patch; patch = patch->next) { + if (patch->prog == prog && patch->bank == bank) + return patch; + } + if (!create_patch) + return NULL; + + patch = kzalloc(sizeof(*patch), GFP_KERNEL); + if (!patch) + return NULL; + patch->prog = prog; + patch->bank = bank; + patch->next = opl3->patch_table[key]; + opl3->patch_table[key] = patch; + return patch; +} +EXPORT_SYMBOL(snd_opl3_find_patch); + +/* + * Clear all patches of the given OPL3 instance + */ +void snd_opl3_clear_patches(struct snd_opl3 *opl3) +{ + int i; + for (i = 0; i < OPL3_PATCH_HASH_SIZE; i++) { + struct fm_patch *patch, *next; + for (patch = opl3->patch_table[i]; patch; patch = next) { + next = patch->next; + kfree(patch); + } + } + memset(opl3->patch_table, 0, sizeof(opl3->patch_table)); +} /* ------------------------------ */ diff --git a/sound/drivers/pcm-indirect2.c b/sound/drivers/pcm-indirect2.c new file mode 100644 index 0000000..660157d --- /dev/null +++ b/sound/drivers/pcm-indirect2.c @@ -0,0 +1,575 @@ +/* + * Helper functions for indirect PCM data transfer to a simple FIFO in + * hardware (small, no possibility to read "hardware io position", + * updating position done by interrupt, ...) + * + * Copyright (c) by 2007 Joachim Foerster + * + * Based on "pcm-indirect.h" (alsa-driver-1.0.13) by + * + * Copyright (c) by Takashi Iwai + * Jaroslav Kysela + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* #dependency of sound/core.h# */ +#include +/* snd_printk/d() */ +#include +/* struct snd_pcm_substream, struct snd_pcm_runtime, snd_pcm_uframes_t + * snd_pcm_period_elapsed() */ +#include + +#include "pcm-indirect2.h" + +#ifdef SND_PCM_INDIRECT2_STAT +/* jiffies */ +#include + +void snd_pcm_indirect2_stat(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + int i; + int j; + int k; + int seconds = (rec->lastbytetime - rec->firstbytetime) / HZ; + + snd_printk(KERN_DEBUG "STAT: mul_elapsed: %u, mul_elapsed_real: %d, " + "irq_occured: %d\n", + rec->mul_elapsed, rec->mul_elapsed_real, rec->irq_occured); + snd_printk(KERN_DEBUG "STAT: min_multiple: %d (irqs/period)\n", + rec->min_multiple); + snd_printk(KERN_DEBUG "STAT: firstbytetime: %lu, lastbytetime: %lu, " + "firstzerotime: %lu\n", + rec->firstbytetime, rec->lastbytetime, rec->firstzerotime); + snd_printk(KERN_DEBUG "STAT: bytes2hw: %u Bytes => (by runtime->rate) " + "length: %d s\n", + rec->bytes2hw, rec->bytes2hw / 2 / 2 / runtime->rate); + snd_printk(KERN_DEBUG "STAT: (by measurement) length: %d => " + "rate: %d Bytes/s = %d Frames/s|Hz\n", + seconds, rec->bytes2hw / seconds, + rec->bytes2hw / 2 / 2 / seconds); + snd_printk(KERN_DEBUG + "STAT: zeros2hw: %u = %d ms ~ %d * %d zero copies\n", + rec->zeros2hw, ((rec->zeros2hw / 2 / 2) * 1000) / + runtime->rate, + rec->zeros2hw / (rec->hw_buffer_size / 2), + (rec->hw_buffer_size / 2)); + snd_printk(KERN_DEBUG "STAT: pointer_calls: %u, lastdifftime: %u\n", + rec->pointer_calls, rec->lastdifftime); + snd_printk(KERN_DEBUG "STAT: sw_io: %d, sw_data: %d\n", rec->sw_io, + rec->sw_data); + snd_printk(KERN_DEBUG "STAT: byte_sizes[]:\n"); + k = 0; + for (j = 0; j < 8; j++) { + for (i = j * 8; i < (j + 1) * 8; i++) + if (rec->byte_sizes[i] != 0) { + snd_printk(KERN_DEBUG "%u: %u", + i, rec->byte_sizes[i]); + k++; + } + if (((k % 8) == 0) && (k != 0)) { + snd_printk(KERN_DEBUG "\n"); + k = 0; + } + } + snd_printk(KERN_DEBUG "\n"); + snd_printk(KERN_DEBUG "STAT: zero_sizes[]:\n"); + for (j = 0; j < 8; j++) { + k = 0; + for (i = j * 8; i < (j + 1) * 8; i++) + if (rec->zero_sizes[i] != 0) + snd_printk(KERN_DEBUG "%u: %u", + i, rec->zero_sizes[i]); + else + k++; + if (!k) + snd_printk(KERN_DEBUG "\n"); + } + snd_printk(KERN_DEBUG "\n"); + snd_printk(KERN_DEBUG "STAT: min_adds[]:\n"); + for (j = 0; j < 8; j++) { + if (rec->min_adds[j] != 0) + snd_printk(KERN_DEBUG "%u: %u", j, rec->min_adds[j]); + } + snd_printk(KERN_DEBUG "\n"); + snd_printk(KERN_DEBUG "STAT: mul_adds[]:\n"); + for (j = 0; j < 8; j++) { + if (rec->mul_adds[j] != 0) + snd_printk(KERN_DEBUG "%u: %u", j, rec->mul_adds[j]); + } + snd_printk(KERN_DEBUG "\n"); + snd_printk(KERN_DEBUG + "STAT: zero_times_saved: %d, zero_times_notsaved: %d\n", + rec->zero_times_saved, rec->zero_times_notsaved); + /* snd_printk(KERN_DEBUG "STAT: zero_times[]\n"); + i = 0; + for (j = 0; j < 3750; j++) { + if (rec->zero_times[j] != 0) { + snd_printk(KERN_DEBUG "%u: %u", j, rec->zero_times[j]); + i++; + } + if (((i % 8) == 0) && (i != 0)) + snd_printk(KERN_DEBUG "\n"); + } + snd_printk(KERN_DEBUG "\n"); */ + return; +} +#endif + +/* + * _internal_ helper function for playback/capture transfer function + */ +static void +snd_pcm_indirect2_increase_min_periods(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + int isplay, int iscopy, + unsigned int bytes) +{ + if (rec->min_periods >= 0) { + if (iscopy) { + rec->sw_io += bytes; + if (rec->sw_io >= rec->sw_buffer_size) + rec->sw_io -= rec->sw_buffer_size; + } else if (isplay) { + /* If application does not write data in multiples of + * a period, move sw_data to the next correctly aligned + * position, so that sw_io can converge to it (in the + * next step). + */ + if (!rec->check_alignment) { + if (rec->bytes2hw % + snd_pcm_lib_period_bytes(substream)) { + unsigned bytes2hw_aligned = + (1 + + (rec->bytes2hw / + snd_pcm_lib_period_bytes + (substream))) * + snd_pcm_lib_period_bytes + (substream); + rec->sw_data = + bytes2hw_aligned % + rec->sw_buffer_size; +#ifdef SND_PCM_INDIRECT2_STAT + snd_printk(KERN_DEBUG + "STAT: @re-align: aligned " + "bytes2hw to next period " + "size boundary: %d " + "(instead of %d)\n", + bytes2hw_aligned, + rec->bytes2hw); + snd_printk(KERN_DEBUG + "STAT: @re-align: sw_data " + "moves to: %d\n", + rec->sw_data); +#endif + } + rec->check_alignment = 1; + } + /* We are at the end and are copying zeros into the + * fifo. + * Now, we have to make sure that sw_io is increased + * until the position of sw_data: Filling the fifo with + * the first zeros means, the last bytes were played. + */ + if (rec->sw_io != rec->sw_data) { + unsigned int diff; + if (rec->sw_data > rec->sw_io) + diff = rec->sw_data - rec->sw_io; + else + diff = (rec->sw_buffer_size - + rec->sw_io) + + rec->sw_data; + if (bytes >= diff) + rec->sw_io = rec->sw_data; + else { + rec->sw_io += bytes; + if (rec->sw_io >= rec->sw_buffer_size) + rec->sw_io -= + rec->sw_buffer_size; + } + } + } + rec->min_period_count += bytes; + if (rec->min_period_count >= (rec->hw_buffer_size / 2)) { + rec->min_periods += (rec->min_period_count / + (rec->hw_buffer_size / 2)); +#ifdef SND_PCM_INDIRECT2_STAT + if ((rec->min_period_count / + (rec->hw_buffer_size / 2)) > 7) + snd_printk(KERN_DEBUG + "STAT: more than 7 (%d) min_adds " + "at once - too big to save!\n", + (rec->min_period_count / + (rec->hw_buffer_size / 2))); + else + rec->min_adds[(rec->min_period_count / + (rec->hw_buffer_size / 2))]++; +#endif + rec->min_period_count = (rec->min_period_count % + (rec->hw_buffer_size / 2)); + } + } else if (isplay && iscopy) + rec->min_periods = 0; +} + +/* + * helper function for playback/capture pointer callback + */ +snd_pcm_uframes_t +snd_pcm_indirect2_pointer(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec) +{ +#ifdef SND_PCM_INDIRECT2_STAT + rec->pointer_calls++; +#endif + return bytes_to_frames(substream->runtime, rec->sw_io); +} + +/* + * _internal_ helper function for playback interrupt callback + */ +static void +snd_pcm_indirect2_playback_transfer(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + snd_pcm_indirect2_copy_t copy, + snd_pcm_indirect2_zero_t zero) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + snd_pcm_uframes_t appl_ptr = runtime->control->appl_ptr; + + /* runtime->control->appl_ptr: position where ALSA will write next time + * rec->appl_ptr: position where ALSA was last time + * diff: obviously ALSA wrote that much bytes into the intermediate + * buffer since we checked last time + */ + snd_pcm_sframes_t diff = appl_ptr - rec->appl_ptr; + + if (diff) { +#ifdef SND_PCM_INDIRECT2_STAT + rec->lastdifftime = jiffies; +#endif + if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2)) + diff += runtime->boundary; + /* number of bytes "added" by ALSA increases the number of + * bytes which are ready to "be transfered to HW"/"played" + * Then, set rec->appl_ptr to not count bytes twice next time. + */ + rec->sw_ready += (int)frames_to_bytes(runtime, diff); + rec->appl_ptr = appl_ptr; + } + if (rec->hw_ready && (rec->sw_ready <= 0)) { + unsigned int bytes; + +#ifdef SND_PCM_INDIRECT2_STAT + if (rec->firstzerotime == 0) { + rec->firstzerotime = jiffies; + snd_printk(KERN_DEBUG + "STAT: @firstzerotime: mul_elapsed: %d, " + "min_period_count: %d\n", + rec->mul_elapsed, rec->min_period_count); + snd_printk(KERN_DEBUG + "STAT: @firstzerotime: sw_io: %d, " + "sw_data: %d, appl_ptr: %u\n", + rec->sw_io, rec->sw_data, + (unsigned int)appl_ptr); + } + if ((jiffies - rec->firstzerotime) < 3750) { + rec->zero_times[(jiffies - rec->firstzerotime)]++; + rec->zero_times_saved++; + } else + rec->zero_times_notsaved++; +#endif + bytes = zero(substream, rec); + +#ifdef SND_PCM_INDIRECT2_STAT + rec->zeros2hw += bytes; + if (bytes < 64) + rec->zero_sizes[bytes]++; + else + snd_printk(KERN_DEBUG + "STAT: %d zero Bytes copied to hardware at " + "once - too big to save!\n", + bytes); +#endif + snd_pcm_indirect2_increase_min_periods(substream, rec, 1, 0, + bytes); + return; + } + while (rec->hw_ready && (rec->sw_ready > 0)) { + /* sw_to_end: max. number of bytes that can be read/take from + * the current position (sw_data) in _one_ step + */ + unsigned int sw_to_end = rec->sw_buffer_size - rec->sw_data; + + /* bytes: number of bytes we have available (for reading) */ + unsigned int bytes = rec->sw_ready; + + if (sw_to_end < bytes) + bytes = sw_to_end; + if (!bytes) + break; + +#ifdef SND_PCM_INDIRECT2_STAT + if (rec->firstbytetime == 0) + rec->firstbytetime = jiffies; + rec->lastbytetime = jiffies; +#endif + /* copy bytes from intermediate buffer position sw_data to the + * HW and return number of bytes actually written + * Furthermore, set hw_ready to 0, if the fifo isn't empty + * now => more could be transfered to fifo + */ + bytes = copy(substream, rec, bytes); + rec->bytes2hw += bytes; + +#ifdef SND_PCM_INDIRECT2_STAT + if (bytes < 64) + rec->byte_sizes[bytes]++; + else + snd_printk(KERN_DEBUG + "STAT: %d Bytes copied to hardware at once " + "- too big to save!\n", + bytes); +#endif + /* increase sw_data by the number of actually written bytes + * (= number of taken bytes from intermediate buffer) + */ + rec->sw_data += bytes; + if (rec->sw_data == rec->sw_buffer_size) + rec->sw_data = 0; + /* now sw_data is the position where ALSA is going to write + * in the intermediate buffer next time = position we are going + * to read from next time + */ + + snd_pcm_indirect2_increase_min_periods(substream, rec, 1, 1, + bytes); + + /* we read bytes from intermediate buffer, so we need to say + * that the number of bytes ready for transfer are decreased + * now + */ + rec->sw_ready -= bytes; + } + return; +} + +/* + * helper function for playback interrupt routine + */ +void +snd_pcm_indirect2_playback_interrupt(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + snd_pcm_indirect2_copy_t copy, + snd_pcm_indirect2_zero_t zero) +{ +#ifdef SND_PCM_INDIRECT2_STAT + rec->irq_occured++; +#endif + /* hardware played some bytes, so there is room again (in fifo) */ + rec->hw_ready = 1; + + /* don't call ack() now, instead call transfer() function directly + * (normally called by ack() ) + */ + snd_pcm_indirect2_playback_transfer(substream, rec, copy, zero); + + if (rec->min_periods >= rec->min_multiple) { +#ifdef SND_PCM_INDIRECT2_STAT + if ((rec->min_periods / rec->min_multiple) > 7) + snd_printk(KERN_DEBUG + "STAT: more than 7 (%d) mul_adds - too big " + "to save!\n", + (rec->min_periods / rec->min_multiple)); + else + rec->mul_adds[(rec->min_periods / + rec->min_multiple)]++; + rec->mul_elapsed_real += (rec->min_periods / + rec->min_multiple); + rec->mul_elapsed++; +#endif + rec->min_periods = (rec->min_periods % rec->min_multiple); + snd_pcm_period_elapsed(substream); + } +} + +/* + * _internal_ helper function for capture interrupt callback + */ +static void +snd_pcm_indirect2_capture_transfer(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + snd_pcm_indirect2_copy_t copy, + snd_pcm_indirect2_zero_t null) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + snd_pcm_uframes_t appl_ptr = runtime->control->appl_ptr; + snd_pcm_sframes_t diff = appl_ptr - rec->appl_ptr; + + if (diff) { +#ifdef SND_PCM_INDIRECT2_STAT + rec->lastdifftime = jiffies; +#endif + if (diff < -(snd_pcm_sframes_t) (runtime->boundary / 2)) + diff += runtime->boundary; + rec->sw_ready -= frames_to_bytes(runtime, diff); + rec->appl_ptr = appl_ptr; + } + /* if hardware has something, but the intermediate buffer is full + * => skip contents of buffer + */ + if (rec->hw_ready && (rec->sw_ready >= (int)rec->sw_buffer_size)) { + unsigned int bytes; + +#ifdef SND_PCM_INDIRECT2_STAT + if (rec->firstzerotime == 0) { + rec->firstzerotime = jiffies; + snd_printk(KERN_DEBUG "STAT: (capture) " + "@firstzerotime: mul_elapsed: %d, " + "min_period_count: %d\n", + rec->mul_elapsed, rec->min_period_count); + snd_printk(KERN_DEBUG "STAT: (capture) " + "@firstzerotime: sw_io: %d, sw_data: %d, " + "appl_ptr: %u\n", + rec->sw_io, rec->sw_data, + (unsigned int)appl_ptr); + } + if ((jiffies - rec->firstzerotime) < 3750) { + rec->zero_times[(jiffies - rec->firstzerotime)]++; + rec->zero_times_saved++; + } else + rec->zero_times_notsaved++; +#endif + bytes = null(substream, rec); + +#ifdef SND_PCM_INDIRECT2_STAT + rec->zeros2hw += bytes; + if (bytes < 64) + rec->zero_sizes[bytes]++; + else + snd_printk(KERN_DEBUG + "STAT: (capture) %d zero Bytes copied to " + "hardware at once - too big to save!\n", + bytes); +#endif + snd_pcm_indirect2_increase_min_periods(substream, rec, 0, 0, + bytes); + /* report an overrun */ + rec->sw_io = SNDRV_PCM_POS_XRUN; + return; + } + while (rec->hw_ready && (rec->sw_ready < (int)rec->sw_buffer_size)) { + /* sw_to_end: max. number of bytes that we can write to the + * intermediate buffer (until it's end) + */ + size_t sw_to_end = rec->sw_buffer_size - rec->sw_data; + + /* bytes: max. number of bytes, which may be copied to the + * intermediate buffer without overflow (in _one_ step) + */ + size_t bytes = rec->sw_buffer_size - rec->sw_ready; + + /* limit number of bytes (for transfer) by available room in + * the intermediate buffer + */ + if (sw_to_end < bytes) + bytes = sw_to_end; + if (!bytes) + break; + +#ifdef SND_PCM_INDIRECT2_STAT + if (rec->firstbytetime == 0) + rec->firstbytetime = jiffies; + rec->lastbytetime = jiffies; +#endif + /* copy bytes from the intermediate buffer (position sw_data) + * to the HW at most and return number of bytes actually copied + * from HW + * Furthermore, set hw_ready to 0, if the fifo is empty now. + */ + bytes = copy(substream, rec, bytes); + rec->bytes2hw += bytes; + +#ifdef SND_PCM_INDIRECT2_STAT + if (bytes < 64) + rec->byte_sizes[bytes]++; + else + snd_printk(KERN_DEBUG + "STAT: (capture) %d Bytes copied to " + "hardware at once - too big to save!\n", + bytes); +#endif + /* increase sw_data by the number of actually copied bytes from + * HW + */ + rec->sw_data += bytes; + if (rec->sw_data == rec->sw_buffer_size) + rec->sw_data = 0; + + snd_pcm_indirect2_increase_min_periods(substream, rec, 0, 1, + bytes); + + /* number of bytes in the intermediate buffer, which haven't + * been fetched by ALSA yet. + */ + rec->sw_ready += bytes; + } + return; +} + +/* + * helper function for capture interrupt routine + */ +void +snd_pcm_indirect2_capture_interrupt(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + snd_pcm_indirect2_copy_t copy, + snd_pcm_indirect2_zero_t null) +{ +#ifdef SND_PCM_INDIRECT2_STAT + rec->irq_occured++; +#endif + /* hardware recorded some bytes, so there is something to read from the + * record fifo: + */ + rec->hw_ready = 1; + + /* don't call ack() now, instead call transfer() function directly + * (normally called by ack() ) + */ + snd_pcm_indirect2_capture_transfer(substream, rec, copy, null); + + if (rec->min_periods >= rec->min_multiple) { + +#ifdef SND_PCM_INDIRECT2_STAT + if ((rec->min_periods / rec->min_multiple) > 7) + snd_printk(KERN_DEBUG + "STAT: more than 7 (%d) mul_adds - " + "too big to save!\n", + (rec->min_periods / rec->min_multiple)); + else + rec->mul_adds[(rec->min_periods / + rec->min_multiple)]++; + rec->mul_elapsed_real += (rec->min_periods / + rec->min_multiple); + rec->mul_elapsed++; +#endif + rec->min_periods = (rec->min_periods % rec->min_multiple); + snd_pcm_period_elapsed(substream); + } +} diff --git a/sound/drivers/pcm-indirect2.h b/sound/drivers/pcm-indirect2.h new file mode 100644 index 0000000..2ea6e46 --- /dev/null +++ b/sound/drivers/pcm-indirect2.h @@ -0,0 +1,140 @@ +/* + * Helper functions for indirect PCM data transfer to a simple FIFO in + * hardware (small, no possibility to read "hardware io position", + * updating position done by interrupt, ...) + * + * Copyright (c) by 2007 Joachim Foerster + * + * Based on "pcm-indirect.h" (alsa-driver-1.0.13) by + * + * Copyright (c) by Takashi Iwai + * Jaroslav Kysela + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __SOUND_PCM_INDIRECT2_H +#define __SOUND_PCM_INDIRECT2_H + +/* struct snd_pcm_substream, struct snd_pcm_runtime, snd_pcm_uframes_t */ +#include + +/* Debug options for code which may be removed completely in a final version */ +#ifdef CONFIG_SND_DEBUG +#define SND_PCM_INDIRECT2_STAT /* turn on some "statistics" about the + * process of copying bytes from the + * intermediate buffer to the hardware + * fifo and the other way round + */ +#endif + +struct snd_pcm_indirect2 { + unsigned int hw_buffer_size; /* Byte size of hardware buffer */ + int hw_ready; /* playback: 1 = hw fifo has room left, + * 0 = hw fifo is full + */ + unsigned int min_multiple; + int min_periods; /* counts number of min. periods until + * min_multiple is reached + */ + int min_period_count; /* counts bytes to count number of + * min. periods + */ + + unsigned int sw_buffer_size; /* Byte size of software buffer */ + + /* sw_data: position in intermediate buffer, where we will read (or + * write) from/to next time (to transfer data to/from HW) + */ + unsigned int sw_data; /* Offset to next dst (or src) in sw + * ring buffer + */ + /* easiest case (playback): + * sw_data is nearly the same as ~ runtime->control->appl_ptr, with the + * exception that sw_data is "behind" by the number if bytes ALSA wrote + * to the intermediate buffer last time. + * A call to ack() callback synchronizes both indirectly. + */ + + /* We have no real sw_io pointer here. Usually sw_io is pointing to the + * current playback/capture position _inside_ the hardware. Devices + * with plain FIFOs often have no possibility to publish this position. + * So we say: if sw_data is updated, that means bytes were copied to + * the hardware, we increase sw_io by that amount, because there have + * to be as much bytes which were played. So sw_io will stay behind + * sw_data all the time and has to converge to sw_data at the end of + * playback. + */ + unsigned int sw_io; /* Current software pointer in bytes */ + + /* sw_ready: number of bytes ALSA copied to the intermediate buffer, so + * it represents the number of bytes which wait for transfer to the HW + */ + int sw_ready; /* Bytes ready to be transferred to/from hw */ + + /* appl_ptr: last known position of ALSA (where ALSA is going to write + * next time into the intermediate buffer + */ + snd_pcm_uframes_t appl_ptr; /* Last seen appl_ptr */ + + unsigned int bytes2hw; + int check_alignment; + +#ifdef SND_PCM_INDIRECT2_STAT + unsigned int zeros2hw; + unsigned int mul_elapsed; + unsigned int mul_elapsed_real; + unsigned long firstbytetime; + unsigned long lastbytetime; + unsigned long firstzerotime; + unsigned int byte_sizes[64]; + unsigned int zero_sizes[64]; + unsigned int min_adds[8]; + unsigned int mul_adds[8]; + unsigned int zero_times[3750]; /* = 15s */ + unsigned int zero_times_saved; + unsigned int zero_times_notsaved; + unsigned int irq_occured; + unsigned int pointer_calls; + unsigned int lastdifftime; +#endif +}; + +typedef size_t (*snd_pcm_indirect2_copy_t) (struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + size_t bytes); +typedef size_t (*snd_pcm_indirect2_zero_t) (struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec); + +#ifdef SND_PCM_INDIRECT2_STAT +void snd_pcm_indirect2_stat(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec); +#endif + +snd_pcm_uframes_t +snd_pcm_indirect2_pointer(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec); +void +snd_pcm_indirect2_playback_interrupt(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + snd_pcm_indirect2_copy_t copy, + snd_pcm_indirect2_zero_t zero); +void +snd_pcm_indirect2_capture_interrupt(struct snd_pcm_substream *substream, + struct snd_pcm_indirect2 *rec, + snd_pcm_indirect2_copy_t copy, + snd_pcm_indirect2_zero_t null); + +#endif /* __SOUND_PCM_INDIRECT2_H */ diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c index e065b2a..1b83287 100644 --- a/sound/drivers/portman2x4.c +++ b/sound/drivers/portman2x4.c @@ -668,7 +668,7 @@ static int __devinit snd_portman_probe_port(struct parport *p) parport_release(pardev); parport_unregister_device(pardev); - return res; + return res ? -EIO : 0; } static void __devinit snd_portman_attach(struct parport *p) diff --git a/sound/drivers/vx/vx_mixer.c b/sound/drivers/vx/vx_mixer.c index b8fcd79..a37f0a8 100644 --- a/sound/drivers/vx/vx_mixer.c +++ b/sound/drivers/vx/vx_mixer.c @@ -439,14 +439,19 @@ static int vx_output_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int codec = kcontrol->id.index; + unsigned int val[2], vmax; + + vmax = chip->hw->output_level_max; + val[0] = ucontrol->value.integer.value[0]; + val[1] = ucontrol->value.integer.value[1]; + if (val[0] > vmax || val[1] > vmax) + return -EINVAL; mutex_lock(&chip->mixer_mutex); - if (ucontrol->value.integer.value[0] != chip->output_level[codec][0] || - ucontrol->value.integer.value[1] != chip->output_level[codec][1]) { - vx_set_analog_output_level(chip, codec, - ucontrol->value.integer.value[0], - ucontrol->value.integer.value[1]); - chip->output_level[codec][0] = ucontrol->value.integer.value[0]; - chip->output_level[codec][1] = ucontrol->value.integer.value[1]; + if (val[0] != chip->output_level[codec][0] || + val[1] != chip->output_level[codec][1]) { + vx_set_analog_output_level(chip, codec, val[0], val[1]); + chip->output_level[codec][0] = val[0]; + chip->output_level[codec][1] = val[1]; mutex_unlock(&chip->mixer_mutex); return 1; } @@ -506,6 +511,14 @@ static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); + + if (chip->type >= VX_TYPE_VXPOCKET) { + if (ucontrol->value.enumerated.item[0] > 2) + return -EINVAL; + } else { + if (ucontrol->value.enumerated.item[0] > 1) + return -EINVAL; + } mutex_lock(&chip->mixer_mutex); if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) { chip->audio_source_target = ucontrol->value.enumerated.item[0]; @@ -554,6 +567,9 @@ static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); + + if (ucontrol->value.enumerated.item[0] > 2) + return -EINVAL; mutex_lock(&chip->mixer_mutex); if (chip->clock_mode != ucontrol->value.enumerated.item[0]) { chip->clock_mode = ucontrol->value.enumerated.item[0]; @@ -603,12 +619,17 @@ static int vx_audio_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; int capture = (kcontrol->private_value >> 8) & 1; + unsigned int val[2]; + val[0] = ucontrol->value.integer.value[0]; + val[1] = ucontrol->value.integer.value[1]; + if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) + return -EINVAL; mutex_lock(&chip->mixer_mutex); - if (ucontrol->value.integer.value[0] != chip->audio_gain[capture][audio] || - ucontrol->value.integer.value[1] != chip->audio_gain[capture][audio+1]) { - vx_set_audio_gain(chip, audio, capture, ucontrol->value.integer.value[0]); - vx_set_audio_gain(chip, audio+1, capture, ucontrol->value.integer.value[1]); + if (val[0] != chip->audio_gain[capture][audio] || + val[1] != chip->audio_gain[capture][audio+1]) { + vx_set_audio_gain(chip, audio, capture, val[0]); + vx_set_audio_gain(chip, audio+1, capture, val[1]); mutex_unlock(&chip->mixer_mutex); return 1; } @@ -632,13 +653,19 @@ static int vx_audio_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; + unsigned int val[2]; + + val[0] = ucontrol->value.integer.value[0]; + val[1] = ucontrol->value.integer.value[1]; + if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) + return -EINVAL; mutex_lock(&chip->mixer_mutex); - if (ucontrol->value.integer.value[0] != chip->audio_monitor[audio] || - ucontrol->value.integer.value[1] != chip->audio_monitor[audio+1]) { - vx_set_monitor_level(chip, audio, ucontrol->value.integer.value[0], + if (val[0] != chip->audio_monitor[audio] || + val[1] != chip->audio_monitor[audio+1]) { + vx_set_monitor_level(chip, audio, val[0], chip->audio_monitor_active[audio]); - vx_set_monitor_level(chip, audio+1, ucontrol->value.integer.value[1], + vx_set_monitor_level(chip, audio+1, val[1], chip->audio_monitor_active[audio+1]); mutex_unlock(&chip->mixer_mutex); return 1; @@ -669,8 +696,10 @@ static int vx_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_va mutex_lock(&chip->mixer_mutex); if (ucontrol->value.integer.value[0] != chip->audio_active[audio] || ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) { - vx_set_audio_switch(chip, audio, ucontrol->value.integer.value[0]); - vx_set_audio_switch(chip, audio+1, ucontrol->value.integer.value[1]); + vx_set_audio_switch(chip, audio, + !!ucontrol->value.integer.value[0]); + vx_set_audio_switch(chip, audio+1, + !!ucontrol->value.integer.value[1]); mutex_unlock(&chip->mixer_mutex); return 1; } @@ -699,9 +728,9 @@ static int vx_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] || ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) { vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], - ucontrol->value.integer.value[0]); + !!ucontrol->value.integer.value[0]); vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], - ucontrol->value.integer.value[1]); + !!ucontrol->value.integer.value[1]); mutex_unlock(&chip->mixer_mutex); return 1; } diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c index de03f68..39bb03a 100644 --- a/sound/i2c/other/ak4xxx-adda.c +++ b/sound/i2c/other/ak4xxx-adda.c @@ -377,8 +377,11 @@ static int put_ak_reg(struct snd_kcontrol *kcontrol, int addr, static int snd_akm4xxx_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - return put_ak_reg(kcontrol, AK_GET_ADDR(kcontrol->private_value), - ucontrol->value.integer.value[0]); + unsigned int mask = AK_GET_MASK(kcontrol->private_value); + unsigned int val = ucontrol->value.integer.value[0]; + if (val > mask) + return -EINVAL; + return put_ak_reg(kcontrol, AK_GET_ADDR(kcontrol->private_value), val); } static int snd_akm4xxx_stereo_volume_info(struct snd_kcontrol *kcontrol, @@ -409,11 +412,16 @@ static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { int addr = AK_GET_ADDR(kcontrol->private_value); + unsigned int mask = AK_GET_MASK(kcontrol->private_value); + unsigned int val[2]; int change; - change = put_ak_reg(kcontrol, addr, ucontrol->value.integer.value[0]); - change |= put_ak_reg(kcontrol, addr + 1, - ucontrol->value.integer.value[1]); + val[0] = ucontrol->value.integer.value[0]; + val[1] = ucontrol->value.integer.value[1]; + if (val[0] > mask || val[1] > mask) + return -EINVAL; + change = put_ak_reg(kcontrol, addr, val[0]); + change |= put_ak_reg(kcontrol, addr + 1, val[1]); return change; } @@ -508,6 +516,18 @@ static int ak4xxx_switch_put(struct snd_kcontrol *kcontrol, #define AK5365_NUM_INPUTS 5 +static int ak4xxx_capture_num_inputs(struct snd_akm4xxx *ak, int mixer_ch) +{ + int num_names; + const char **input_names; + + input_names = ak->adc_info[mixer_ch].input_names; + num_names = 0; + while (num_names < AK5365_NUM_INPUTS && input_names[num_names]) + ++num_names; + return num_names; +} + static int ak4xxx_capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { @@ -516,18 +536,16 @@ static int ak4xxx_capture_source_info(struct snd_kcontrol *kcontrol, const char **input_names; int num_names, idx; - input_names = ak->adc_info[mixer_ch].input_names; - - num_names = 0; - while (num_names < AK5365_NUM_INPUTS && input_names[num_names]) - ++num_names; - + num_names = ak4xxx_capture_num_inputs(ak, mixer_ch); + if (!num_names) + return -EINVAL; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = num_names; idx = uinfo->value.enumerated.item; if (idx >= num_names) return -EINVAL; + input_names = ak->adc_info[mixer_ch].input_names; strncpy(uinfo->value.enumerated.name, input_names[idx], sizeof(uinfo->value.enumerated.name)); return 0; @@ -551,10 +569,15 @@ static int ak4xxx_capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); + int mixer_ch = AK_GET_SHIFT(kcontrol->private_value); int chip = AK_GET_CHIP(kcontrol->private_value); int addr = AK_GET_ADDR(kcontrol->private_value); int mask = AK_GET_MASK(kcontrol->private_value); unsigned char oval, val; + int num_names = ak4xxx_capture_num_inputs(ak, mixer_ch); + + if (ucontrol->value.enumerated.item[0] >= num_names) + return -EINVAL; oval = snd_akm4xxx_get(ak, chip, addr); val = oval & ~mask; diff --git a/sound/i2c/other/pt2258.c b/sound/i2c/other/pt2258.c index 00c83d8..987d2c9 100644 --- a/sound/i2c/other/pt2258.c +++ b/sound/i2c/other/pt2258.c @@ -113,6 +113,8 @@ static int pt2258_stereo_volume_put(struct snd_kcontrol *kcontrol, val0 = 79 - ucontrol->value.integer.value[0]; val1 = 79 - ucontrol->value.integer.value[1]; + if (val0 < 0 || val0 > 79 || val1 < 0 || val1 > 79) + return -EINVAL; if (val0 == pt->volume[base] && val1 == pt->volume[base + 1]) return 0; diff --git a/sound/isa/ad1848/ad1848_lib.c b/sound/isa/ad1848/ad1848_lib.c index a901cd1..9a64035 100644 --- a/sound/isa/ad1848/ad1848_lib.c +++ b/sound/isa/ad1848/ad1848_lib.c @@ -213,7 +213,7 @@ static void snd_ad1848_mce_down(struct snd_ad1848 *chip) for (timeout = 12000; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--) udelay(100); - snd_printdd("(1) timeout = %d\n", timeout); + snd_printdd("(1) timeout = %ld\n", timeout); #ifdef CONFIG_SND_DEBUG if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) diff --git a/sound/isa/gus/Makefile b/sound/isa/gus/Makefile index df3d59f..6cd4ee0 100644 --- a/sound/isa/gus/Makefile +++ b/sound/isa/gus/Makefile @@ -9,7 +9,6 @@ snd-gus-lib-objs := gus_main.o \ gus_pcm.o gus_mixer.o \ gus_uart.o \ gus_reset.o -snd-gus-synth-objs := gus_synth.o gus_sample.o gus_simple.o gus_instr.o snd-gusclassic-objs := gusclassic.o snd-gusextreme-objs := gusextreme.o @@ -17,20 +16,9 @@ snd-gusmax-objs := gusmax.o snd-interwave-objs := interwave.o snd-interwave-stb-objs := interwave-stb.o -# -# this function returns: -# "m" - CONFIG_SND_SEQUENCER is m -# - CONFIG_SND_SEQUENCER is undefined -# otherwise parameter #1 value -# -sequencer = $(if $(subst y,,$(CONFIG_SND_SEQUENCER)),$(if $(1),m),$(if $(CONFIG_SND_SEQUENCER),$(1))) - # Toplevel Module Dependency obj-$(CONFIG_SND_GUSCLASSIC) += snd-gusclassic.o snd-gus-lib.o obj-$(CONFIG_SND_GUSMAX) += snd-gusmax.o snd-gus-lib.o obj-$(CONFIG_SND_GUSEXTREME) += snd-gusextreme.o snd-gus-lib.o obj-$(CONFIG_SND_INTERWAVE) += snd-interwave.o snd-gus-lib.o obj-$(CONFIG_SND_INTERWAVE_STB) += snd-interwave-stb.o snd-gus-lib.o -obj-$(call sequencer,$(CONFIG_SND_GUS_SYNTH)) += snd-gus-synth.o - -obj-m := $(sort $(obj-m)) diff --git a/sound/isa/gus/gus_main.c b/sound/isa/gus/gus_main.c index b14d5d6..e4453e5 100644 --- a/sound/isa/gus/gus_main.c +++ b/sound/isa/gus/gus_main.c @@ -104,12 +104,6 @@ static int snd_gus_free(struct snd_gus_card *gus) { if (gus->gf1.res_port2 == NULL) goto __hw_end; -#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)) - if (gus->seq_dev) { - snd_device_free(gus->card, gus->seq_dev); - gus->seq_dev = NULL; - } -#endif snd_gf1_stop(gus); snd_gus_init_dma_irq(gus, 0); __hw_end: @@ -408,14 +402,6 @@ static int snd_gus_check_version(struct snd_gus_card * gus) return 0; } -#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)) -static void snd_gus_seq_dev_free(struct snd_seq_device *seq_dev) -{ - struct snd_gus_card *gus = seq_dev->private_data; - gus->seq_dev = NULL; -} -#endif - int snd_gus_initialize(struct snd_gus_card *gus) { int err; @@ -430,15 +416,6 @@ int snd_gus_initialize(struct snd_gus_card *gus) } if ((err = snd_gus_init_dma_irq(gus, 1)) < 0) return err; -#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)) - if (snd_seq_device_new(gus->card, 1, SNDRV_SEQ_DEV_ID_GUS, - sizeof(struct snd_gus_card *), &gus->seq_dev) >= 0) { - strcpy(gus->seq_dev->name, "GUS"); - *(struct snd_gus_card **)SNDRV_SEQ_DEVICE_ARGPTR(gus->seq_dev) = gus; - gus->seq_dev->private_data = gus; - gus->seq_dev->private_free = snd_gus_seq_dev_free; - } -#endif snd_gf1_start(gus); gus->initialized = 1; return 0; diff --git a/sound/isa/gus/gus_sample.c b/sound/isa/gus/gus_sample.c deleted file mode 100644 index cba0829..0000000 --- a/sound/isa/gus/gus_sample.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Routines for Gravis UltraSound soundcards - Sample support - * Copyright (c) by Jaroslav Kysela - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include - -/* - * - */ - -static void select_instrument(struct snd_gus_card * gus, struct snd_gus_voice * v) -{ - struct snd_seq_kinstr *instr; - -#if 0 - printk("select instrument: cluster = %li, std = 0x%x, bank = %i, prg = %i\n", - v->instr.cluster, - v->instr.std, - v->instr.bank, - v->instr.prg); -#endif - instr = snd_seq_instr_find(gus->gf1.ilist, &v->instr, 0, 1); - if (instr != NULL) { - if (instr->ops) { - if (!strcmp(instr->ops->instr_type, SNDRV_SEQ_INSTR_ID_SIMPLE)) - snd_gf1_simple_init(v); - } - snd_seq_instr_free_use(gus->gf1.ilist, instr); - } -} - -/* - * - */ - -static void event_sample(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_stop) - v->sample_ops->sample_stop(p->gus, v, SAMPLE_STOP_IMMEDIATELY); - v->instr.std = ev->data.sample.param.sample.std; - if (v->instr.std & 0xff000000) { /* private instrument */ - v->instr.std &= 0x00ffffff; - v->instr.std |= (unsigned int)ev->source.client << 24; - } - v->instr.bank = ev->data.sample.param.sample.bank; - v->instr.prg = ev->data.sample.param.sample.prg; - select_instrument(p->gus, v); -} - -static void event_cluster(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_stop) - v->sample_ops->sample_stop(p->gus, v, SAMPLE_STOP_IMMEDIATELY); - v->instr.cluster = ev->data.sample.param.cluster.cluster; - select_instrument(p->gus, v); -} - -static void event_start(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_start) - v->sample_ops->sample_start(p->gus, v, ev->data.sample.param.position); -} - -static void event_stop(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_stop) - v->sample_ops->sample_stop(p->gus, v, ev->data.sample.param.stop_mode); -} - -static void event_freq(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_freq) - v->sample_ops->sample_freq(p->gus, v, ev->data.sample.param.frequency); -} - -static void event_volume(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_volume) - v->sample_ops->sample_volume(p->gus, v, &ev->data.sample.param.volume); -} - -static void event_loop(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_loop) - v->sample_ops->sample_loop(p->gus, v, &ev->data.sample.param.loop); -} - -static void event_position(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_pos) - v->sample_ops->sample_pos(p->gus, v, ev->data.sample.param.position); -} - -static void event_private1(struct snd_seq_event *ev, struct snd_gus_port *p, - struct snd_gus_voice *v) -{ - if (v->sample_ops && v->sample_ops->sample_private1) - v->sample_ops->sample_private1(p->gus, v, (unsigned char *)&ev->data.sample.param.raw8); -} - -typedef void (gus_sample_event_handler_t)(struct snd_seq_event *ev, - struct snd_gus_port *p, - struct snd_gus_voice *v); -static gus_sample_event_handler_t *gus_sample_event_handlers[9] = { - event_sample, - event_cluster, - event_start, - event_stop, - event_freq, - event_volume, - event_loop, - event_position, - event_private1 -}; - -void snd_gus_sample_event(struct snd_seq_event *ev, struct snd_gus_port *p) -{ - int idx, voice; - struct snd_gus_card *gus = p->gus; - struct snd_gus_voice *v; - unsigned long flags; - - idx = ev->type - SNDRV_SEQ_EVENT_SAMPLE; - if (idx < 0 || idx > 8) - return; - for (voice = 0; voice < 32; voice++) { - v = &gus->gf1.voices[voice]; - if (v->use && v->client == ev->source.client && - v->port == ev->source.port && - v->index == ev->data.sample.channel) { - spin_lock_irqsave(&gus->event_lock, flags); - gus_sample_event_handlers[idx](ev, p, v); - spin_unlock_irqrestore(&gus->event_lock, flags); - return; - } - } -} diff --git a/sound/isa/gus/gus_simple.c b/sound/isa/gus/gus_simple.c deleted file mode 100644 index 39d121e..0000000 --- a/sound/isa/gus/gus_simple.c +++ /dev/null @@ -1,634 +0,0 @@ -/* - * Routines for Gravis UltraSound soundcards - Simple instrument handlers - * Copyright (c) by Jaroslav Kysela - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include "gus_tables.h" - -/* - * - */ - -static void interrupt_wave(struct snd_gus_card *gus, struct snd_gus_voice *voice); -static void interrupt_volume(struct snd_gus_card *gus, struct snd_gus_voice *voice); -static void interrupt_effect(struct snd_gus_card *gus, struct snd_gus_voice *voice); - -static void sample_start(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_position_t position); -static void sample_stop(struct snd_gus_card *gus, struct snd_gus_voice *voice, int mode); -static void sample_freq(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_frequency_t freq); -static void sample_volume(struct snd_gus_card *card, struct snd_gus_voice *voice, struct snd_seq_ev_volume *volume); -static void sample_loop(struct snd_gus_card *card, struct snd_gus_voice *voice, struct snd_seq_ev_loop *loop); -static void sample_pos(struct snd_gus_card *card, struct snd_gus_voice *voice, snd_seq_position_t position); -static void sample_private1(struct snd_gus_card *card, struct snd_gus_voice *voice, unsigned char *data); - -static struct snd_gus_sample_ops sample_ops = { - sample_start, - sample_stop, - sample_freq, - sample_volume, - sample_loop, - sample_pos, - sample_private1 -}; - -#if 0 - -static void note_stop(struct snd_gus_card *gus, struct snd_gus_voice *voice, int wait); -static void note_wait(struct snd_gus_card *gus, struct snd_gus_voice *voice); -static void note_off(struct snd_gus_card *gus, struct snd_gus_voice *voice); -static void note_volume(struct snd_gus_card *card, struct snd_gus_voice *voice); -static void note_pitchbend(struct snd_gus_card *card, struct snd_gus_voice *voice); -static void note_vibrato(struct snd_gus_card *card, struct snd_gus_voice *voice); -static void note_tremolo(struct snd_gus_card *card, struct snd_gus_voice *voice); - -static struct snd_gus_note_handlers note_commands = { - note_stop, - note_wait, - note_off, - note_volume, - note_pitchbend, - note_vibrato, - note_tremolo -}; - -static void chn_trigger_down(struct snd_gus_card *card, ultra_channel_t *channel, ultra_instrument_t *instrument, unsigned char note, unsigned char velocity, unsigned char priority ); -static void chn_trigger_up( ultra_card_t *card, ultra_note_t *note ); -static void chn_control( ultra_card_t *card, ultra_channel_t *channel, unsigned short p1, unsigned short p2 ); - -static struct ULTRA_STRU_INSTRUMENT_CHANNEL_COMMANDS channel_commands = { - chn_trigger_down, - chn_trigger_up, - chn_control -}; - -#endif - -static void do_volume_envelope(struct snd_gus_card *card, struct snd_gus_voice *voice); -static void do_pan_envelope(struct snd_gus_card *card, struct snd_gus_voice *voice); - -/* - * - */ - -static void interrupt_wave(struct snd_gus_card *gus, struct snd_gus_voice *voice) -{ - spin_lock(&gus->event_lock); - snd_gf1_stop_voice(gus, voice->number); - spin_lock(&gus->reg_lock); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, 0); - spin_unlock(&gus->reg_lock); - voice->flags &= ~SNDRV_GF1_VFLG_RUNNING; - spin_unlock(&gus->event_lock); -} - -static void interrupt_volume(struct snd_gus_card *gus, struct snd_gus_voice *voice) -{ - spin_lock(&gus->event_lock); - if (voice->flags & SNDRV_GF1_VFLG_RUNNING) - do_volume_envelope(gus, voice); - else - snd_gf1_stop_voice(gus, voice->number); - spin_unlock(&gus->event_lock); -} - -static void interrupt_effect(struct snd_gus_card *gus, struct snd_gus_voice *voice) -{ - spin_lock(&gus->event_lock); - if ((voice->flags & (SNDRV_GF1_VFLG_RUNNING|SNDRV_GF1_VFLG_EFFECT_TIMER1)) == - (SNDRV_GF1_VFLG_RUNNING|SNDRV_GF1_VFLG_EFFECT_TIMER1)) - do_pan_envelope(gus, voice); - spin_unlock(&gus->event_lock); -} - -/* - * - */ - -static void do_volume_envelope(struct snd_gus_card *gus, struct snd_gus_voice *voice) -{ - unsigned short next, rate, old_volume; - int program_next_ramp; - unsigned long flags; - - if (!gus->gf1.volume_ramp) { - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); - snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, voice->gf1_volume); - /* printk("gf1_volume = 0x%x\n", voice->gf1_volume); */ - spin_unlock_irqrestore(&gus->reg_lock, flags); - return; - } - program_next_ramp = 0; - rate = next = 0; - while (1) { - program_next_ramp = 0; - rate = next = 0; - switch (voice->venv_state) { - case VENV_BEFORE: - voice->venv_state = VENV_ATTACK; - voice->venv_value_next = 0; - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); - snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, SNDRV_GF1_MIN_VOLUME); - spin_unlock_irqrestore(&gus->reg_lock, flags); - break; - case VENV_ATTACK: - voice->venv_state = VENV_SUSTAIN; - program_next_ramp++; - next = 255; - rate = gus->gf1.volume_ramp; - break; - case VENV_SUSTAIN: - voice->venv_state = VENV_RELEASE; - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); - snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, ((int)voice->gf1_volume * (int)voice->venv_value_next) / 255); - spin_unlock_irqrestore(&gus->reg_lock, flags); - return; - case VENV_RELEASE: - voice->venv_state = VENV_DONE; - program_next_ramp++; - next = 0; - rate = gus->gf1.volume_ramp; - break; - case VENV_DONE: - snd_gf1_stop_voice(gus, voice->number); - voice->flags &= ~SNDRV_GF1_VFLG_RUNNING; - return; - case VENV_VOLUME: - program_next_ramp++; - next = voice->venv_value_next; - rate = gus->gf1.volume_ramp; - voice->venv_state = voice->venv_state_prev; - break; - } - voice->venv_value_next = next; - if (!program_next_ramp) - continue; - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_ctrl_stop(gus, SNDRV_GF1_VB_VOLUME_CONTROL); - old_volume = snd_gf1_read16(gus, SNDRV_GF1_VW_VOLUME) >> 8; - if (!rate) { - spin_unlock_irqrestore(&gus->reg_lock, flags); - continue; - } - next = (((int)voice->gf1_volume * (int)next) / 255) >> 8; - if (old_volume < SNDRV_GF1_MIN_OFFSET) - old_volume = SNDRV_GF1_MIN_OFFSET; - if (next < SNDRV_GF1_MIN_OFFSET) - next = SNDRV_GF1_MIN_OFFSET; - if (next > SNDRV_GF1_MAX_OFFSET) - next = SNDRV_GF1_MAX_OFFSET; - if (old_volume == next) { - spin_unlock_irqrestore(&gus->reg_lock, flags); - continue; - } - voice->volume_control &= ~0xc3; - voice->volume_control |= 0x20; - if (old_volume > next) { - snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, next); - snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, old_volume); - voice->volume_control |= 0x40; - } else { - snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_START, old_volume); - snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_END, next); - } - snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_RATE, rate); - snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, voice->volume_control); - if (!gus->gf1.enh_mode) { - snd_gf1_delay(gus); - snd_gf1_write8(gus, SNDRV_GF1_VB_VOLUME_CONTROL, voice->volume_control); - } - spin_unlock_irqrestore(&gus->reg_lock, flags); - return; - } -} - -static void do_pan_envelope(struct snd_gus_card *gus, struct snd_gus_voice *voice) -{ - unsigned long flags; - unsigned char old_pan; - -#if 0 - snd_gf1_select_voice(gus, voice->number); - printk(" -%i- do_pan_envelope - flags = 0x%x (0x%x -> 0x%x)\n", - voice->number, - voice->flags, - voice->gf1_pan, - snd_gf1_i_read8(gus, SNDRV_GF1_VB_PAN) & 0x0f); -#endif - if (gus->gf1.enh_mode) { - voice->flags &= ~(SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN); - return; - } - if (!gus->gf1.smooth_pan) { - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, voice->gf1_pan); - spin_unlock_irqrestore(&gus->reg_lock, flags); - return; - } - if (!(voice->flags & SNDRV_GF1_VFLG_PAN)) /* before */ - voice->flags |= SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN; - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - old_pan = snd_gf1_read8(gus, SNDRV_GF1_VB_PAN) & 0x0f; - if (old_pan > voice->gf1_pan ) - old_pan--; - if (old_pan < voice->gf1_pan) - old_pan++; - snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, old_pan); - spin_unlock_irqrestore(&gus->reg_lock, flags); - if (old_pan == voice->gf1_pan) /* the goal was reached */ - voice->flags &= ~(SNDRV_GF1_VFLG_EFFECT_TIMER1|SNDRV_GF1_VFLG_PAN); -#if 0 - snd_gf1_select_voice(gus, voice->number); - printk(" -%i- (1) do_pan_envelope - flags = 0x%x (0x%x -> 0x%x)\n", - voice->number, - voice->flags, - voice->gf1_pan, - snd_gf1_i_read8(gus, GF1_VB_PAN) & 0x0f); -#endif -} - -static void set_enhanced_pan(struct snd_gus_card *gus, struct snd_gus_voice *voice, unsigned short pan) -{ - unsigned long flags; - unsigned short vlo, vro; - - vlo = SNDRV_GF1_ATTEN((SNDRV_GF1_ATTEN_TABLE_SIZE-1) - pan); - vro = SNDRV_GF1_ATTEN(pan); - if (pan != SNDRV_GF1_ATTEN_TABLE_SIZE - 1 && pan != 0) { - vlo >>= 1; - vro >>= 1; - } - vlo <<= 4; - vro <<= 4; -#if 0 - printk("vlo = 0x%x (0x%x), vro = 0x%x (0x%x)\n", - vlo, snd_gf1_i_read16(gus, GF1_VW_OFFSET_LEFT), - vro, snd_gf1_i_read16(gus, GF1_VW_OFFSET_RIGHT)); -#endif - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT_FINAL, vlo); - snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT_FINAL, vro); - spin_unlock_irqrestore(&gus->reg_lock, flags); - voice->vlo = vlo; - voice->vro = vro; -} - -/* - * - */ - -static void sample_start(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_position_t position) -{ - unsigned long flags; - unsigned int begin, addr, addr_end, addr_start; - int w_16; - struct simple_instrument *simple; - struct snd_seq_kinstr *instr; - - instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1); - if (instr == NULL) - return; - voice->instr = instr->instr; /* copy ID to speedup aliases */ - simple = KINSTR_DATA(instr); - begin = simple->address.memory << 4; - w_16 = simple->format & SIMPLE_WAVE_16BIT ? 0x04 : 0; - addr_start = simple->loop_start; - if (simple->format & SIMPLE_WAVE_LOOP) { - addr_end = simple->loop_end; - } else { - addr_end = (simple->size << 4) - (w_16 ? 40 : 24); - } - if (simple->format & SIMPLE_WAVE_BACKWARD) { - addr = simple->loop_end; - if (position < simple->loop_end) - addr -= position; - } else { - addr = position; - } - voice->control = 0x00; - voice->mode = 0x20; /* enable offset registers */ - if (simple->format & SIMPLE_WAVE_16BIT) - voice->control |= 0x04; - if (simple->format & SIMPLE_WAVE_BACKWARD) - voice->control |= 0x40; - if (simple->format & SIMPLE_WAVE_LOOP) { - voice->control |= 0x08; - } else { - voice->control |= 0x20; - } - if (simple->format & SIMPLE_WAVE_BIDIR) - voice->control |= 0x10; - if (simple->format & SIMPLE_WAVE_ULAW) - voice->mode |= 0x40; - if (w_16) { - addr = ((addr << 1) & ~0x1f) | (addr & 0x0f); - addr_start = ((addr_start << 1) & ~0x1f) | (addr_start & 0x0f); - addr_end = ((addr_end << 1) & ~0x1f) | (addr_end & 0x0f); - } - addr += begin; - addr_start += begin; - addr_end += begin; - snd_gf1_stop_voice(gus, voice->number); - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, voice->fc_register + voice->fc_lfo); - voice->venv_state = VENV_BEFORE; - voice->volume_control = 0x03; - snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, addr_start, w_16); - snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, addr_end, w_16); - snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, addr, w_16); - if (!gus->gf1.enh_mode) { - snd_gf1_write8(gus, SNDRV_GF1_VB_PAN, voice->gf1_pan); - } else { - snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT, voice->vlo); - snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_LEFT_FINAL, voice->vlo); - snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT, voice->vro); - snd_gf1_write16(gus, SNDRV_GF1_VW_OFFSET_RIGHT_FINAL, voice->vro); - snd_gf1_write8(gus, SNDRV_GF1_VB_ACCUMULATOR, voice->effect_accumulator); - snd_gf1_write16(gus, SNDRV_GF1_VW_EFFECT_VOLUME, voice->gf1_effect_volume); - snd_gf1_write16(gus, SNDRV_GF1_VW_EFFECT_VOLUME_FINAL, voice->gf1_effect_volume); - } - spin_unlock_irqrestore(&gus->reg_lock, flags); - do_volume_envelope(gus, voice); - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - if (gus->gf1.enh_mode) - snd_gf1_write8(gus, SNDRV_GF1_VB_MODE, voice->mode); - snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice->control); - if (!gus->gf1.enh_mode) { - snd_gf1_delay(gus); - snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, voice->control ); - } - spin_unlock_irqrestore(&gus->reg_lock, flags); -#if 0 - snd_gf1_print_voice_registers(gus); -#endif - voice->flags |= SNDRV_GF1_VFLG_RUNNING; - snd_seq_instr_free_use(gus->gf1.ilist, instr); -} - -static void sample_stop(struct snd_gus_card *gus, struct snd_gus_voice *voice, int mode) -{ - unsigned char control; - unsigned long flags; - - if (!(voice->flags & SNDRV_GF1_VFLG_RUNNING)) - return; - switch (mode) { - default: - if (gus->gf1.volume_ramp > 0) { - if (voice->venv_state < VENV_RELEASE) { - voice->venv_state = VENV_RELEASE; - do_volume_envelope(gus, voice); - } - } - if (mode != SAMPLE_STOP_VENVELOPE) { - snd_gf1_stop_voice(gus, voice->number); - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_write16(gus, SNDRV_GF1_VW_VOLUME, SNDRV_GF1_MIN_VOLUME); - spin_unlock_irqrestore(&gus->reg_lock, flags); - voice->flags &= ~SNDRV_GF1_VFLG_RUNNING; - } - break; - case SAMPLE_STOP_LOOP: /* disable loop only */ - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - control = snd_gf1_read8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL); - control &= ~(0x83 | 0x04); - control |= 0x20; - snd_gf1_write8(gus, SNDRV_GF1_VB_ADDRESS_CONTROL, control); - spin_unlock_irqrestore(&gus->reg_lock, flags); - break; - } -} - -static void sample_freq(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_frequency_t freq) -{ - unsigned long flags; - - spin_lock_irqsave(&gus->reg_lock, flags); - voice->fc_register = snd_gf1_translate_freq(gus, freq); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_write16(gus, SNDRV_GF1_VW_FREQUENCY, voice->fc_register + voice->fc_lfo); - spin_unlock_irqrestore(&gus->reg_lock, flags); -} - -static void sample_volume(struct snd_gus_card *gus, struct snd_gus_voice *voice, struct snd_seq_ev_volume *volume) -{ - if (volume->volume >= 0) { - volume->volume &= 0x3fff; - voice->gf1_volume = snd_gf1_lvol_to_gvol_raw(volume->volume << 2) << 4; - voice->venv_state_prev = VENV_SUSTAIN; - voice->venv_state = VENV_VOLUME; - do_volume_envelope(gus, voice); - } - if (volume->lr >= 0) { - volume->lr &= 0x3fff; - if (!gus->gf1.enh_mode) { - voice->gf1_pan = (volume->lr >> 10) & 15; - if (!gus->gf1.full_range_pan) { - if (voice->gf1_pan == 0) - voice->gf1_pan++; - if (voice->gf1_pan == 15) - voice->gf1_pan--; - } - voice->flags &= ~SNDRV_GF1_VFLG_PAN; /* before */ - do_pan_envelope(gus, voice); - } else { - set_enhanced_pan(gus, voice, volume->lr >> 7); - } - } -} - -static void sample_loop(struct snd_gus_card *gus, struct snd_gus_voice *voice, struct snd_seq_ev_loop *loop) -{ - unsigned long flags; - int w_16 = voice->control & 0x04; - unsigned int begin, addr_start, addr_end; - struct simple_instrument *simple; - struct snd_seq_kinstr *instr; - -#if 0 - printk("voice_loop: start = 0x%x, end = 0x%x\n", loop->start, loop->end); -#endif - instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1); - if (instr == NULL) - return; - voice->instr = instr->instr; /* copy ID to speedup aliases */ - simple = KINSTR_DATA(instr); - begin = simple->address.memory; - addr_start = loop->start; - addr_end = loop->end; - addr_start = (((addr_start << 1) & ~0x1f) | (addr_start & 0x0f)) + begin; - addr_end = (((addr_end << 1) & ~0x1f) | (addr_end & 0x0f)) + begin; - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_write_addr(gus, SNDRV_GF1_VA_START, addr_start, w_16); - snd_gf1_write_addr(gus, SNDRV_GF1_VA_END, addr_end, w_16); - spin_unlock_irqrestore(&gus->reg_lock, flags); - snd_seq_instr_free_use(gus->gf1.ilist, instr); -} - -static void sample_pos(struct snd_gus_card *gus, struct snd_gus_voice *voice, snd_seq_position_t position) -{ - unsigned long flags; - int w_16 = voice->control & 0x04; - unsigned int begin, addr; - struct simple_instrument *simple; - struct snd_seq_kinstr *instr; - -#if 0 - printk("voice_loop: start = 0x%x, end = 0x%x\n", loop->start, loop->end); -#endif - instr = snd_seq_instr_find(gus->gf1.ilist, &voice->instr, 0, 1); - if (instr == NULL) - return; - voice->instr = instr->instr; /* copy ID to speedup aliases */ - simple = KINSTR_DATA(instr); - begin = simple->address.memory; - addr = (((position << 1) & ~0x1f) | (position & 0x0f)) + begin; - spin_lock_irqsave(&gus->reg_lock, flags); - snd_gf1_select_voice(gus, voice->number); - snd_gf1_write_addr(gus, SNDRV_GF1_VA_CURRENT, addr, w_16); - spin_unlock_irqrestore(&gus->reg_lock, flags); - snd_seq_instr_free_use(gus->gf1.ilist, instr); -} - -#if 0 - -static unsigned char get_effects_mask( ultra_card_t *card, int value ) -{ - if ( value > 7 ) return 0; - if ( card -> gf1.effects && card -> gf1.effects -> chip_type == ULTRA_EFFECT_CHIP_INTERWAVE ) - return card -> gf1.effects -> chip.interwave.voice_output[ value ]; - return 0; -} - -#endif - -static void sample_private1(struct snd_gus_card *card, struct snd_gus_voice *voice, unsigned char *data) -{ -#if 0 - unsigned long flags; - unsigned char uc; - - switch ( *data ) { - case ULTRA_PRIV1_IW_EFFECT: - uc = get_effects_mask( card, ultra_get_byte( data, 4 ) ); - uc |= get_effects_mask( card, ultra_get_byte( data, 4 ) >> 4 ); - uc |= get_effects_mask( card, ultra_get_byte( data, 5 ) ); - uc |= get_effects_mask( card, ultra_get_byte( data, 5 ) >> 4 ); - voice -> data.simple.effect_accumulator = uc; - voice -> data.simple.effect_volume = ultra_translate_voice_volume( card, ultra_get_word( data, 2 ) ) << 4; - if ( !card -> gf1.enh_mode ) return; - if ( voice -> flags & VFLG_WAIT_FOR_START ) return; - if ( voice -> flags & VFLG_RUNNING ) - { - CLI( &flags ); - gf1_select_voice( card, voice -> number ); - ultra_write8( card, GF1_VB_ACCUMULATOR, voice -> data.simple.effect_accumulator ); - ultra_write16( card, GF1_VW_EFFECT_VOLUME_FINAL, voice -> data.simple.effect_volume ); - STI( &flags ); - } - break; - case ULTRA_PRIV1_IW_LFO: - ultra_lfo_command( card, voice -> number, data ); - } -#endif -} - -#if 0 - -/* - * - */ - -static void note_stop( ultra_card_t *card, ultra_voice_t *voice, int wait ) -{ -} - -static void note_wait( ultra_card_t *card, ultra_voice_t *voice ) -{ -} - -static void note_off( ultra_card_t *card, ultra_voice_t *voice ) -{ -} - -static void note_volume( ultra_card_t *card, ultra_voice_t *voice ) -{ -} - -static void note_pitchbend( ultra_card_t *card, ultra_voice_t *voice ) -{ -} - -static void note_vibrato( ultra_card_t *card, ultra_voice_t *voice ) -{ -} - -static void note_tremolo( ultra_card_t *card, ultra_voice_t *voice ) -{ -} - -/* - * - */ - -static void chn_trigger_down( ultra_card_t *card, ultra_channel_t *channel, ultra_instrument_t *instrument, unsigned char note, unsigned char velocity, unsigned char priority ) -{ -} - -static void chn_trigger_up( ultra_card_t *card, ultra_note_t *note ) -{ -} - -static void chn_control( ultra_card_t *card, ultra_channel_t *channel, unsigned short p1, unsigned short p2 ) -{ -} - -/* - * - */ - -#endif - -void snd_gf1_simple_init(struct snd_gus_voice *voice) -{ - voice->handler_wave = interrupt_wave; - voice->handler_volume = interrupt_volume; - voice->handler_effect = interrupt_effect; - voice->volume_change = NULL; - voice->sample_ops = &sample_ops; -} diff --git a/sound/isa/gus/gus_synth.c b/sound/isa/gus/gus_synth.c deleted file mode 100644 index 2c20517..0000000 --- a/sound/isa/gus/gus_synth.c +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Routines for Gravis UltraSound soundcards - Synthesizer - * Copyright (c) by Jaroslav Kysela - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include - -MODULE_AUTHOR("Jaroslav Kysela "); -MODULE_DESCRIPTION("Routines for Gravis UltraSound soundcards - Synthesizer"); -MODULE_LICENSE("GPL"); - -/* - * - */ - -static void snd_gus_synth_free_voices(struct snd_gus_card * gus, int client, int port) -{ - int idx; - struct snd_gus_voice * voice; - - for (idx = 0; idx < 32; idx++) { - voice = &gus->gf1.voices[idx]; - if (voice->use && voice->client == client && voice->port == port) - snd_gf1_free_voice(gus, voice); - } -} - -static int snd_gus_synth_use(void *private_data, struct snd_seq_port_subscribe *info) -{ - struct snd_gus_port * port = private_data; - struct snd_gus_card * gus = port->gus; - struct snd_gus_voice * voice; - unsigned int idx; - - if (info->voices > 32) - return -EINVAL; - mutex_lock(&gus->register_mutex); - if (!snd_gus_use_inc(gus)) { - mutex_unlock(&gus->register_mutex); - return -EFAULT; - } - for (idx = 0; idx < info->voices; idx++) { - voice = snd_gf1_alloc_voice(gus, SNDRV_GF1_VOICE_TYPE_SYNTH, info->sender.client, info->sender.port); - if (voice == NULL) { - snd_gus_synth_free_voices(gus, info->sender.client, info->sender.port); - snd_gus_use_dec(gus); - mutex_unlock(&gus->register_mutex); - return -EBUSY; - } - voice->index = idx; - } - mutex_unlock(&gus->register_mutex); - return 0; -} - -static int snd_gus_synth_unuse(void *private_data, struct snd_seq_port_subscribe *info) -{ - struct snd_gus_port * port = private_data; - struct snd_gus_card * gus = port->gus; - - mutex_lock(&gus->register_mutex); - snd_gus_synth_free_voices(gus, info->sender.client, info->sender.port); - snd_gus_use_dec(gus); - mutex_unlock(&gus->register_mutex); - return 0; -} - -/* - * - */ - -static void snd_gus_synth_free_private_instruments(struct snd_gus_port *p, int client) -{ - struct snd_seq_instr_header ifree; - - memset(&ifree, 0, sizeof(ifree)); - ifree.cmd = SNDRV_SEQ_INSTR_FREE_CMD_PRIVATE; - snd_seq_instr_list_free_cond(p->gus->gf1.ilist, &ifree, client, 0); -} - -static int snd_gus_synth_event_input(struct snd_seq_event *ev, int direct, - void *private_data, int atomic, int hop) -{ - struct snd_gus_port * p = private_data; - - snd_assert(p != NULL, return -EINVAL); - if (ev->type >= SNDRV_SEQ_EVENT_SAMPLE && - ev->type <= SNDRV_SEQ_EVENT_SAMPLE_PRIVATE1) { - snd_gus_sample_event(ev, p); - return 0; - } - if (ev->source.client == SNDRV_SEQ_CLIENT_SYSTEM && - ev->source.port == SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE) { - if (ev->type == SNDRV_SEQ_EVENT_CLIENT_EXIT) { - snd_gus_synth_free_private_instruments(p, ev->data.addr.client); - return 0; - } - } - if (direct) { - if (ev->type >= SNDRV_SEQ_EVENT_INSTR_BEGIN) { - snd_seq_instr_event(&p->gus->gf1.iwffff_ops.kops, - p->gus->gf1.ilist, - ev, - p->gus->gf1.seq_client, - atomic, hop); - return 0; - } - } - return 0; -} - -static void snd_gus_synth_instr_notify(void *private_data, - struct snd_seq_kinstr *instr, - int what) -{ - unsigned int idx; - struct snd_gus_card *gus = private_data; - struct snd_gus_voice *pvoice; - unsigned long flags; - - spin_lock_irqsave(&gus->event_lock, flags); - for (idx = 0; idx < 32; idx++) { - pvoice = &gus->gf1.voices[idx]; - if (pvoice->use && !memcmp(&pvoice->instr, &instr->instr, sizeof(pvoice->instr))) { - if (pvoice->sample_ops && pvoice->sample_ops->sample_stop) { - pvoice->sample_ops->sample_stop(gus, pvoice, SAMPLE_STOP_IMMEDIATELY); - } else { - snd_gf1_stop_voice(gus, pvoice->number); - pvoice->flags &= ~SNDRV_GF1_VFLG_RUNNING; - } - } - } - spin_unlock_irqrestore(&gus->event_lock, flags); -} - -/* - * - */ - -static void snd_gus_synth_free_port(void *private_data) -{ - struct snd_gus_port * p = private_data; - - if (p) - snd_midi_channel_free_set(p->chset); -} - -static int snd_gus_synth_create_port(struct snd_gus_card * gus, int idx) -{ - struct snd_gus_port * p; - struct snd_seq_port_callback callbacks; - char name[32]; - int result; - - p = &gus->gf1.seq_ports[idx]; - p->chset = snd_midi_channel_alloc_set(16); - if (p->chset == NULL) - return -ENOMEM; - p->chset->private_data = p; - p->gus = gus; - p->client = gus->gf1.seq_client; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.owner = THIS_MODULE; - callbacks.use = snd_gus_synth_use; - callbacks.unuse = snd_gus_synth_unuse; - callbacks.event_input = snd_gus_synth_event_input; - callbacks.private_free = snd_gus_synth_free_port; - callbacks.private_data = p; - - sprintf(name, "%s port %i", gus->interwave ? "AMD InterWave" : "GF1", idx); - p->chset->port = snd_seq_event_port_attach(gus->gf1.seq_client, - &callbacks, - SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE, - SNDRV_SEQ_PORT_TYPE_DIRECT_SAMPLE | - SNDRV_SEQ_PORT_TYPE_SYNTH | - SNDRV_SEQ_PORT_TYPE_HARDWARE | - SNDRV_SEQ_PORT_TYPE_SYNTHESIZER, - 16, 0, - name); - if (p->chset->port < 0) { - result = p->chset->port; - snd_gus_synth_free_port(p); - return result; - } - p->port = p->chset->port; - return 0; -} - -/* - * - */ - -static int snd_gus_synth_new_device(struct snd_seq_device *dev) -{ - struct snd_gus_card *gus; - int client, i; - struct snd_seq_port_subscribe sub; - struct snd_iwffff_ops *iwops; - struct snd_gf1_ops *gf1ops; - struct snd_simple_ops *simpleops; - - gus = *(struct snd_gus_card **)SNDRV_SEQ_DEVICE_ARGPTR(dev); - if (gus == NULL) - return -EINVAL; - - mutex_init(&gus->register_mutex); - gus->gf1.seq_client = -1; - - /* allocate new client */ - client = gus->gf1.seq_client = - snd_seq_create_kernel_client(gus->card, 1, gus->interwave ? - "AMD InterWave" : "GF1"); - if (client < 0) - return client; - - for (i = 0; i < 4; i++) - snd_gus_synth_create_port(gus, i); - - gus->gf1.ilist = snd_seq_instr_list_new(); - if (gus->gf1.ilist == NULL) { - snd_seq_delete_kernel_client(client); - gus->gf1.seq_client = -1; - return -ENOMEM; - } - gus->gf1.ilist->flags = SNDRV_SEQ_INSTR_FLG_DIRECT; - - simpleops = &gus->gf1.simple_ops; - snd_seq_simple_init(simpleops, gus, NULL); - simpleops->put_sample = snd_gus_simple_put_sample; - simpleops->get_sample = snd_gus_simple_get_sample; - simpleops->remove_sample = snd_gus_simple_remove_sample; - simpleops->notify = snd_gus_synth_instr_notify; - - gf1ops = &gus->gf1.gf1_ops; - snd_seq_gf1_init(gf1ops, gus, &simpleops->kops); - gf1ops->put_sample = snd_gus_gf1_put_sample; - gf1ops->get_sample = snd_gus_gf1_get_sample; - gf1ops->remove_sample = snd_gus_gf1_remove_sample; - gf1ops->notify = snd_gus_synth_instr_notify; - - iwops = &gus->gf1.iwffff_ops; - snd_seq_iwffff_init(iwops, gus, &gf1ops->kops); - iwops->put_sample = snd_gus_iwffff_put_sample; - iwops->get_sample = snd_gus_iwffff_get_sample; - iwops->remove_sample = snd_gus_iwffff_remove_sample; - iwops->notify = snd_gus_synth_instr_notify; - - memset(&sub, 0, sizeof(sub)); - sub.sender.client = SNDRV_SEQ_CLIENT_SYSTEM; - sub.sender.port = SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE; - sub.dest.client = client; - sub.dest.port = 0; - snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &sub); - - return 0; -} - -static int snd_gus_synth_delete_device(struct snd_seq_device *dev) -{ - struct snd_gus_card *gus; - - gus = *(struct snd_gus_card **)SNDRV_SEQ_DEVICE_ARGPTR(dev); - if (gus == NULL) - return -EINVAL; - - if (gus->gf1.seq_client >= 0) { - snd_seq_delete_kernel_client(gus->gf1.seq_client); - gus->gf1.seq_client = -1; - } - if (gus->gf1.ilist) - snd_seq_instr_list_free(&gus->gf1.ilist); - return 0; -} - -static int __init alsa_gus_synth_init(void) -{ - static struct snd_seq_dev_ops ops = { - snd_gus_synth_new_device, - snd_gus_synth_delete_device - }; - - return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_GUS, &ops, - sizeof(struct snd_gus_card *)); -} - -static void __exit alsa_gus_synth_exit(void) -{ - snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_GUS); -} - -module_init(alsa_gus_synth_init) -module_exit(alsa_gus_synth_exit) diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c index d295936..c2baf4c 100644 --- a/sound/isa/opti9xx/miro.c +++ b/sound/isa/opti9xx/miro.c @@ -483,6 +483,10 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol, /* equalizer elements */ + if (left < -0x7f || left > 0x7f || + right < -0x7f || right > 0x7f) + return -EINVAL; + if (left_old > 0x80) left_old = 0x80 - left_old; if (right_old > 0x80) @@ -520,6 +524,10 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol, /* non-equalizer elements */ + if (left < 0 || left > 0x20 || + right < 0 || right > 0x20) + return -EINVAL; + left_old = 0x20 - left_old; right_old = 0x20 - right_old; diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c index 98c8b72..50c637e 100644 --- a/sound/pci/ac97/ac97_patch.c +++ b/sound/pci/ac97/ac97_patch.c @@ -133,6 +133,14 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); unsigned char mode = ucontrol->value.enumerated.item[0]; + if (kcontrol->private_value) { + if (mode >= 2) + return -EINVAL; + } else { + if (mode >= 3) + return -EINVAL; + } + if (mode != ac97->channel_mode) { ac97->channel_mode = mode; if (ac97->build_ops->update_jacks) @@ -2142,8 +2150,7 @@ static int snd_ac97_ad1985_vrefout_put(struct snd_kcontrol *kcontrol, struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); unsigned short val; - if (ucontrol->value.enumerated.item[0] > 3 - || ucontrol->value.enumerated.item[0] < 0) + if (ucontrol->value.enumerated.item[0] > 3) return -EINVAL; val = ctrl2reg[ucontrol->value.enumerated.item[0]] << AC97_AD198X_VREF_SHIFT; diff --git a/sound/pci/ac97/ac97_patch.h b/sound/pci/ac97/ac97_patch.h index 9cccc27..47bf8df 100644 --- a/sound/pci/ac97/ac97_patch.h +++ b/sound/pci/ac97/ac97_patch.h @@ -83,8 +83,10 @@ static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1, const char *s2, const char *suffix); static void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src, const char *dst); +#ifdef CONFIG_PM static void snd_ac97_restore_status(struct snd_ac97 *ac97); static void snd_ac97_restore_iec958(struct snd_ac97 *ac97); +#endif static int snd_ac97_info_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo); static int snd_ac97_get_enum_double(struct snd_kcontrol *kcontrol, diff --git a/sound/pci/ca0106/ca0106.h b/sound/pci/ca0106/ca0106.h index 75da174..74175fc 100644 --- a/sound/pci/ca0106/ca0106.h +++ b/sound/pci/ca0106/ca0106.h @@ -272,7 +272,6 @@ #define SPCS_WORD_LENGTH_20A 0x0000000a /* Word Length 20 bit */ #define SPCS_WORD_LENGTH_20 0x00000009 /* Word Length 20 bit (both 0xa and 0x9 are 20 bit) */ #define SPCS_WORD_LENGTH_21 0x00000007 /* Word Length 21 bit */ -#define SPCS_WORD_LENGTH_21 0x00000007 /* Word Length 21 bit */ #define SPCS_WORD_LENGTH_22 0x00000005 /* Word Length 22 bit */ #define SPCS_WORD_LENGTH_23 0x00000003 /* Word Length 23 bit */ #define SPCS_WORD_LENGTH_24 0x0000000b /* Word Length 24 bit */ diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c index be519a1..3f9b5c5 100644 --- a/sound/pci/ca0106/ca0106_mixer.c +++ b/sound/pci/ca0106/ca0106_mixer.c @@ -86,7 +86,7 @@ static int snd_ca0106_shared_spdif_get(struct snd_kcontrol *kcontrol, { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); - ucontrol->value.enumerated.item[0] = emu->spdif_enable; + ucontrol->value.integer.value[0] = emu->spdif_enable; return 0; } @@ -98,11 +98,11 @@ static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol, int change = 0; u32 mask; - val = ucontrol->value.enumerated.item[0] ; + val = !!ucontrol->value.integer.value[0]; change = (emu->spdif_enable != val); if (change) { emu->spdif_enable = val; - if (val == 1) { + if (val) { /* Digital */ snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000); @@ -159,6 +159,8 @@ static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol, u32 source; val = ucontrol->value.enumerated.item[0] ; + if (val >= 6) + return -EINVAL; change = (emu->capture_source != val); if (change) { emu->capture_source = val; @@ -207,6 +209,8 @@ static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol, * for the particular source. */ source_id = ucontrol->value.enumerated.item[0] ; + if (source_id >= 4) + return -EINVAL; change = (emu->i2c_capture_source != source_id); if (change) { snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */ @@ -271,6 +275,8 @@ static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol, u32 tmp; val = ucontrol->value.enumerated.item[0] ; + if (val > 1) + return -EINVAL; change = (emu->capture_mic_line_in != val); if (change) { emu->capture_mic_line_in = val; @@ -443,7 +449,7 @@ static int snd_ca0106_i2c_volume_put(struct snd_kcontrol *kcontrol, ogain = emu->i2c_capture_volume[source_id][0]; /* Left */ ngain = ucontrol->value.integer.value[0]; if (ngain > 0xff) - return 0; + return -EINVAL; if (ogain != ngain) { if (emu->i2c_capture_source == source_id) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff) ); @@ -453,7 +459,7 @@ static int snd_ca0106_i2c_volume_put(struct snd_kcontrol *kcontrol, ogain = emu->i2c_capture_volume[source_id][1]; /* Right */ ngain = ucontrol->value.integer.value[1]; if (ngain > 0xff) - return 0; + return -EINVAL; if (ogain != ngain) { if (emu->i2c_capture_source == source_id) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff)); @@ -497,7 +503,7 @@ static int spi_mute_put(struct snd_kcontrol *kcontrol, } ret = snd_ca0106_spi_write(emu, emu->spi_dac_reg[reg]); - return ret ? -1 : 1; + return ret ? -EINVAL : 1; } #define CA_VOLUME(xname,chid,reg) \ diff --git a/sound/pci/ca0106/ca0106_proc.c b/sound/pci/ca0106/ca0106_proc.c index ae80f51..61f2718 100644 --- a/sound/pci/ca0106/ca0106_proc.c +++ b/sound/pci/ca0106/ca0106_proc.c @@ -445,13 +445,11 @@ int __devinit snd_ca0106_proc_init(struct snd_ca0106 * emu) snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read1); entry->c.text.write = snd_ca0106_proc_reg_write; entry->mode |= S_IWUSR; -// entry->private_data = emu; } if(! snd_card_proc_new(emu->card, "ca0106_i2c", &entry)) { - snd_info_set_text_ops(entry, emu, snd_ca0106_proc_i2c_write); entry->c.text.write = snd_ca0106_proc_i2c_write; + entry->private_data = emu; entry->mode |= S_IWUSR; -// entry->private_data = emu; } if(! snd_card_proc_new(emu->card, "ca0106_regs2", &entry)) snd_info_set_text_ops(entry, emu, snd_ca0106_proc_reg_read2); diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c index 6832649..187203e 100644 --- a/sound/pci/cmipci.c +++ b/sound/pci/cmipci.c @@ -150,6 +150,8 @@ MODULE_PARM_DESC(joystick_port, "Joystick port address."); #define CM_CH0_SRATE_176K 0x00000200 #define CM_CH0_SRATE_96K 0x00000200 /* model 055? */ #define CM_CH0_SRATE_88K 0x00000100 +#define CM_CH0_SRATE_128K 0x00000300 +#define CM_CH0_SRATE_MASK 0x00000300 #define CM_SPDIF_INVERSE2 0x00000080 /* model 055? */ #define CM_DBLSPDS 0x00000040 /* double SPDIF sample rate 88.2/96 */ @@ -246,10 +248,9 @@ MODULE_PARM_DESC(joystick_port, "Joystick port address."); #define CM_MMODE_MASK 0x00000E00 /* model DAA interface mode */ #define CM_SPDIF_SELECT2 0x00000100 /* for model > 039 ? */ #define CM_ENCENTER 0x00000080 -#define CM_FLINKON 0x00000080 /* force modem link detection on, model 037 */ +#define CM_FLINKON 0x00000040 /* force modem link detection on, model 037 */ #define CM_MUTECH1 0x00000040 /* mute PCI ch1 to DAC */ -#define CM_FLINKOFF 0x00000040 /* force modem link detection off, model 037 */ -#define CM_UNKNOWN_18_5 0x00000020 /* ? */ +#define CM_FLINKOFF 0x00000020 /* force modem link detection off, model 037 */ #define CM_MIDSMP 0x00000010 /* 1/2 interpolation at front end DAC */ #define CM_UPDDMA_MASK 0x0000000C /* TDMA position update notification */ #define CM_UPDDMA_2048 0x00000000 @@ -474,6 +475,7 @@ struct cmipci { unsigned int can_ac3_sw: 1; unsigned int can_ac3_hw: 1; unsigned int can_multi_ch: 1; + unsigned int can_96k: 1; /* samplerate above 48k */ unsigned int do_soft_ac3: 1; unsigned int spdif_playback_avail: 1; /* spdif ready? */ @@ -604,8 +606,6 @@ static unsigned int snd_cmipci_rate_freq(unsigned int rate) { unsigned int i; - if (rate > 48000) - rate /= 2; for (i = 0; i < ARRAY_SIZE(rates); i++) { if (rates[i] == rate) return i; @@ -783,7 +783,7 @@ static int set_dac_channels(struct cmipci *cm, struct cmipci_pcm *rec, int chann static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec, struct snd_pcm_substream *substream) { - unsigned int reg, freq, val; + unsigned int reg, freq, freq_ext, val; unsigned int period_size; struct snd_pcm_runtime *runtime = substream->runtime; @@ -831,7 +831,17 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec, //snd_printd("cmipci: functrl0 = %08x\n", cm->ctrl); /* set sample rate */ - freq = snd_cmipci_rate_freq(runtime->rate); + freq = 0; + freq_ext = 0; + if (runtime->rate > 48000) + switch (runtime->rate) { + case 88200: freq_ext = CM_CH0_SRATE_88K; break; + case 96000: freq_ext = CM_CH0_SRATE_96K; break; + case 128000: freq_ext = CM_CH0_SRATE_128K; break; + default: snd_BUG(); break; + } + else + freq = snd_cmipci_rate_freq(runtime->rate); val = snd_cmipci_read(cm, CM_REG_FUNCTRL1); if (rec->ch) { val &= ~CM_DSFC_MASK; @@ -852,19 +862,20 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec, val &= ~CM_CH0FMT_MASK; val |= rec->fmt << CM_CH0FMT_SHIFT; } - if (cm->chip_version == 68) { - if (runtime->rate == 88200) - val |= CM_CH0_SRATE_88K << (rec->ch * 2); - else - val &= ~(CM_CH0_SRATE_88K << (rec->ch * 2)); - if (runtime->rate == 96000) - val |= CM_CH0_SRATE_96K << (rec->ch * 2); - else - val &= ~(CM_CH0_SRATE_96K << (rec->ch * 2)); + if (cm->can_96k) { + val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2)); + val |= freq_ext << (rec->ch * 2); } snd_cmipci_write(cm, CM_REG_CHFORMAT, val); //snd_printd("cmipci: chformat = %08x\n", val); + if (!rec->is_dac && cm->chip_version) { + if (runtime->rate > 44100) + snd_cmipci_set_bit(cm, CM_REG_EXT_MISC, CM_ADC48K44K); + else + snd_cmipci_clear_bit(cm, CM_REG_EXT_MISC, CM_ADC48K44K); + } + rec->running = 0; spin_unlock_irq(&cm->reg_lock); @@ -1281,7 +1292,7 @@ static int snd_cmipci_playback_prepare(struct snd_pcm_substream *substream) int rate = substream->runtime->rate; int err, do_spdif, do_ac3 = 0; - do_spdif = (rate >= 44100 && + do_spdif = (rate >= 44100 && rate <= 96000 && substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE && substream->runtime->channels == 2); if (do_spdif && cm->can_ac3_hw) @@ -1337,10 +1348,8 @@ static void snd_cmipci_silence_hack(struct cmipci *cm, struct cmipci_pcm *rec) val = snd_cmipci_read(cm, CM_REG_CHFORMAT); val &= ~(CM_CH0FMT_MASK << (rec->ch * 2)); val |= (3 << CM_CH0FMT_SHIFT) << (rec->ch * 2); - if (cm->chip_version == 68) { - val &= ~(CM_CH0_SRATE_88K << (rec->ch * 2)); - val &= ~(CM_CH0_SRATE_96K << (rec->ch * 2)); - } + if (cm->can_96k) + val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2)); snd_cmipci_write(cm, CM_REG_CHFORMAT, val); /* start stream (we don't need interrupts) */ @@ -1392,6 +1401,17 @@ static int snd_cmipci_capture_spdif_prepare(struct snd_pcm_substream *substream) spin_lock_irq(&cm->reg_lock); snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF); + if (cm->can_96k) { + if (substream->runtime->rate > 48000) + snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); + else + snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); + } + if (snd_pcm_format_width(substream->runtime->format) > 16) + snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); + else + snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); + spin_unlock_irq(&cm->reg_lock); return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream); @@ -1403,6 +1423,7 @@ static int snd_cmipci_capture_spdif_hw_free(struct snd_pcm_substream *subs) spin_lock_irq(&cm->reg_lock); snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF); + snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); spin_unlock_irq(&cm->reg_lock); return snd_cmipci_hw_free(subs); @@ -1554,7 +1575,8 @@ static struct snd_pcm_hardware snd_cmipci_capture_spdif = .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), - .formats = SNDRV_PCM_FMTBIT_S16_LE, + .formats = SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE, .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, .rate_min = 44100, .rate_max = 48000, @@ -1568,6 +1590,14 @@ static struct snd_pcm_hardware snd_cmipci_capture_spdif = .fifo_size = 0, }; +static unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050, + 32000, 44100, 48000, 88200, 96000, 128000 }; +static struct snd_pcm_hw_constraint_list hw_constraints_rates = { + .count = ARRAY_SIZE(rate_constraints), + .list = rate_constraints, + .mask = 0, +}; + /* * check device open/close */ @@ -1637,6 +1667,13 @@ static int snd_cmipci_playback_open(struct snd_pcm_substream *substream) runtime->hw.rates |= SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000; runtime->hw.rate_max = 96000; + } else if (cm->chip_version == 55) { + err = snd_pcm_hw_constraint_list(runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); + if (err < 0) + return err; + runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; + runtime->hw.rate_max = 128000; } snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000); cm->dig_pcm_status = cm->dig_status; @@ -1655,6 +1692,13 @@ static int snd_cmipci_capture_open(struct snd_pcm_substream *substream) if (cm->chip_version == 68) { // 8768 only supports 44k/48k recording runtime->hw.rate_min = 41000; runtime->hw.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; + } else if (cm->chip_version == 55) { + err = snd_pcm_hw_constraint_list(runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); + if (err < 0) + return err; + runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; + runtime->hw.rate_max = 128000; } snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000); return 0; @@ -1686,6 +1730,13 @@ static int snd_cmipci_playback2_open(struct snd_pcm_substream *substream) runtime->hw.rates |= SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000; runtime->hw.rate_max = 96000; + } else if (cm->chip_version == 55) { + err = snd_pcm_hw_constraint_list(runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); + if (err < 0) + return err; + runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; + runtime->hw.rate_max = 128000; } snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000); return 0; @@ -1705,7 +1756,7 @@ static int snd_cmipci_playback_spdif_open(struct snd_pcm_substream *substream) runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE; snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); } - if (cm->chip_version == 68) { + if (cm->can_96k) { runtime->hw.rates |= SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000; runtime->hw.rate_max = 96000; @@ -1727,6 +1778,11 @@ static int snd_cmipci_capture_spdif_open(struct snd_pcm_substream *substream) if ((err = open_device_check(cm, CM_OPEN_SPDIF_CAPTURE, substream)) < 0) /* use channel B */ return err; runtime->hw = snd_cmipci_capture_spdif; + if (cm->can_96k && !(cm->chip_version == 68)) { + runtime->hw.rates |= SNDRV_PCM_RATE_88200 | + SNDRV_PCM_RATE_96000; + runtime->hw.rate_max = 96000; + } snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x40000); return 0; } @@ -2786,9 +2842,11 @@ static void __devinit query_chip(struct cmipci *cm) } else if (detect & CM_CHIP_8768) { cm->chip_version = 68; cm->max_channels = 8; + cm->can_96k = 1; } else { cm->chip_version = 55; cm->max_channels = 6; + cm->can_96k = 1; } cm->can_ac3_hw = 1; cm->can_multi_ch = 1; diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c index 2c7bfc9..8c44fef 100644 --- a/sound/pci/cs46xx/cs46xx_lib.c +++ b/sound/pci/cs46xx/cs46xx_lib.c @@ -2084,71 +2084,6 @@ static int snd_cs46xx_spdif_stream_put(struct snd_kcontrol *kcontrol, #endif /* CONFIG_SND_CS46XX_NEW_DSP */ -#ifdef CONFIG_SND_CS46XX_DEBUG_GPIO -static int snd_cs46xx_egpio_select_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; - uinfo->count = 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = 8; - return 0; -} - -static int snd_cs46xx_egpio_select_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); - ucontrol->value.integer.value[0] = chip->current_gpio; - - return 0; -} - -static int snd_cs46xx_egpio_select_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); - int change = (chip->current_gpio != ucontrol->value.integer.value[0]); - chip->current_gpio = ucontrol->value.integer.value[0]; - - return change; -} - - -static int snd_cs46xx_egpio_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); - int reg = kcontrol->private_value; - - snd_printdd ("put: reg = %04x, gpio %02x\n",reg,chip->current_gpio); - ucontrol->value.integer.value[0] = - (snd_cs46xx_peekBA0(chip, reg) & (1 << chip->current_gpio)) ? 1 : 0; - - return 0; -} - -static int snd_cs46xx_egpio_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); - int reg = kcontrol->private_value; - int val = snd_cs46xx_peekBA0(chip, reg); - int oldval = val; - snd_printdd ("put: reg = %04x, gpio %02x\n",reg,chip->current_gpio); - - if (ucontrol->value.integer.value[0]) - val |= (1 << chip->current_gpio); - else - val &= ~(1 << chip->current_gpio); - - snd_cs46xx_pokeBA0(chip, reg,val); - snd_printdd ("put: val %08x oldval %08x\n",val,oldval); - - return (oldval != val); -} -#endif /* CONFIG_SND_CS46XX_DEBUG_GPIO */ - static struct snd_kcontrol_new snd_cs46xx_controls[] __devinitdata = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, @@ -2241,40 +2176,6 @@ static struct snd_kcontrol_new snd_cs46xx_controls[] __devinitdata = { }, #endif -#ifdef CONFIG_SND_CS46XX_DEBUG_GPIO -{ - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "EGPIO select", - .info = snd_cs46xx_egpio_select_info, - .get = snd_cs46xx_egpio_select_get, - .put = snd_cs46xx_egpio_select_put, - .private_value = 0, -}, -{ - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "EGPIO Input/Output", - .info = snd_mixer_boolean_info, - .get = snd_cs46xx_egpio_get, - .put = snd_cs46xx_egpio_put, - .private_value = BA0_EGPIODR, -}, -{ - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "EGPIO CMOS/Open drain", - .info = snd_mixer_boolean_info, - .get = snd_cs46xx_egpio_get, - .put = snd_cs46xx_egpio_put, - .private_value = BA0_EGPIOPTR, -}, -{ - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "EGPIO On/Off", - .info = snd_mixer_boolean_info, - .get = snd_cs46xx_egpio_get, - .put = snd_cs46xx_egpio_put, - .private_value = BA0_EGPIOSR, -}, -#endif }; #ifdef CONFIG_SND_CS46XX_NEW_DSP diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index ad4cb38..23d3bef 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -55,6 +55,7 @@ static struct hda_vendor_id hda_vendor_ids[] = { { 0x10ec, "Realtek" }, { 0x1057, "Motorola" }, { 0x1106, "VIA" }, + { 0x111d, "IDT" }, { 0x11d4, "Analog Devices" }, { 0x13f6, "C-Media" }, { 0x14f1, "Conexant" }, @@ -1625,19 +1626,26 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, nid = codec->start_nid; for (i = 0; i < codec->num_nodes; i++, nid++) { - if (get_wcaps(codec, nid) & AC_WCAP_POWER) { - unsigned int pincap; - /* - * don't power down the widget if it controls eapd - * and EAPD_BTLENABLE is set. - */ - pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); - if (pincap & AC_PINCAP_EAPD) { - int eapd = snd_hda_codec_read(codec, nid, - 0, AC_VERB_GET_EAPD_BTLENABLE, 0); - eapd &= 0x02; - if (power_state == AC_PWRST_D3 && eapd) - continue; + unsigned int wcaps = get_wcaps(codec, nid); + if (wcaps & AC_WCAP_POWER) { + unsigned int wid_type = (wcaps & AC_WCAP_TYPE) >> + AC_WCAP_TYPE_SHIFT; + if (wid_type == AC_WID_PIN) { + unsigned int pincap; + /* + * don't power down the widget if it controls + * eapd and EAPD_BTLENABLE is set. + */ + pincap = snd_hda_param_read(codec, nid, + AC_PAR_PIN_CAP); + if (pincap & AC_PINCAP_EAPD) { + int eapd = snd_hda_codec_read(codec, + nid, 0, + AC_VERB_GET_EAPD_BTLENABLE, 0); + eapd &= 0x02; + if (power_state == AC_PWRST_D3 && eapd) + continue; + } } snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, @@ -2329,7 +2337,8 @@ int snd_hda_ch_mode_put(struct hda_codec *codec, unsigned int mode; mode = ucontrol->value.enumerated.item[0]; - snd_assert(mode < num_chmodes, return -EINVAL); + if (mode >= num_chmodes) + return -EINVAL; if (*max_channelsp == chmode[mode].channels) return 0; /* change the current channel setting */ @@ -2485,13 +2494,14 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, /* front */ snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, 0, format); - if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]) + if (!mout->no_share_stream && + mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]) /* headphone out will just decode front left/right (stereo) */ snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format); /* extra outputs copied from front */ for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) - if (mout->extra_out_nid[i]) + if (!mout->no_share_stream && mout->extra_out_nid[i]) snd_hda_codec_setup_stream(codec, mout->extra_out_nid[i], stream_tag, 0, format); @@ -2501,7 +2511,7 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, if (chs >= (i + 1) * 2) /* independent out */ snd_hda_codec_setup_stream(codec, nids[i], stream_tag, i * 2, format); - else /* copy front */ + else if (!mout->no_share_stream) /* copy front */ snd_hda_codec_setup_stream(codec, nids[i], stream_tag, 0, format); } @@ -2599,11 +2609,13 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec, short seq, assoc_line_out, assoc_speaker; short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)]; short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)]; + short sequences_hp[ARRAY_SIZE(cfg->hp_pins)]; memset(cfg, 0, sizeof(*cfg)); memset(sequences_line_out, 0, sizeof(sequences_line_out)); memset(sequences_speaker, 0, sizeof(sequences_speaker)); + memset(sequences_hp, 0, sizeof(sequences_hp)); assoc_line_out = assoc_speaker = 0; nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid_start); @@ -2658,9 +2670,12 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec, cfg->speaker_outs++; break; case AC_JACK_HP_OUT: + seq = get_defcfg_sequence(def_conf); + assoc = get_defcfg_association(def_conf); if (cfg->hp_outs >= ARRAY_SIZE(cfg->hp_pins)) continue; cfg->hp_pins[cfg->hp_outs] = nid; + sequences_hp[cfg->hp_outs] = (assoc << 4) | seq; cfg->hp_outs++; break; case AC_JACK_MIC_IN: { @@ -2704,7 +2719,24 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec, cfg->line_outs); sort_pins_by_sequence(cfg->speaker_pins, sequences_speaker, cfg->speaker_outs); + sort_pins_by_sequence(cfg->hp_pins, sequences_hp, + cfg->hp_outs); + /* if we have only one mic, make it AUTO_PIN_MIC */ + if (!cfg->input_pins[AUTO_PIN_MIC] && + cfg->input_pins[AUTO_PIN_FRONT_MIC]) { + cfg->input_pins[AUTO_PIN_MIC] = + cfg->input_pins[AUTO_PIN_FRONT_MIC]; + cfg->input_pins[AUTO_PIN_FRONT_MIC] = 0; + } + /* ditto for line-in */ + if (!cfg->input_pins[AUTO_PIN_LINE] && + cfg->input_pins[AUTO_PIN_FRONT_LINE]) { + cfg->input_pins[AUTO_PIN_LINE] = + cfg->input_pins[AUTO_PIN_FRONT_LINE]; + cfg->input_pins[AUTO_PIN_FRONT_LINE] = 0; + } + /* * FIX-UP: if no line-outs are detected, try to use speaker or HP pin * as a primary output diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h index 2bce925..0331510 100644 --- a/sound/pci/hda/hda_codec.h +++ b/sound/pci/hda/hda_codec.h @@ -135,6 +135,7 @@ enum { #define AC_PAR_PROC_CAP 0x10 #define AC_PAR_GPIO_CAP 0x11 #define AC_PAR_AMP_OUT_CAP 0x12 +#define AC_PAR_VOL_KNB_CAP 0x13 /* * AC_VERB_PARAMETERS results (32bit) diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 3fa0f97..41edf85 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -104,6 +104,12 @@ MODULE_SUPPORTED_DEVICE("{{Intel, ICH6}," "{ATI, RS690}," "{ATI, RS780}," "{ATI, R600}," + "{ATI, RV630}," + "{ATI, RV610}," + "{ATI, RV670}," + "{ATI, RV635}," + "{ATI, RV620}," + "{ATI, RV770}," "{VIA, VT8251}," "{VIA, VT8237A}," "{SiS, SIS966}," @@ -555,7 +561,8 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec) } if (!chip->rirb.cmds) return chip->rirb.res; /* the last value */ - schedule_timeout_uninterruptible(1); + udelay(10); + cond_resched(); } while (time_after_eq(timeout, jiffies)); if (chip->msi) { @@ -1940,8 +1947,14 @@ static struct pci_device_id azx_ids[] = { { 0x1002, 0x4383, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB600 */ { 0x1002, 0x793b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS600 HDMI */ { 0x1002, 0x7919, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS690 HDMI */ - { 0x1002, 0x960c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS780 HDMI */ + { 0x1002, 0x960f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS780 HDMI */ { 0x1002, 0xaa00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI R600 HDMI */ + { 0x1002, 0xaa08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV630 HDMI */ + { 0x1002, 0xaa10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV610 HDMI */ + { 0x1002, 0xaa18, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV670 HDMI */ + { 0x1002, 0xaa20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV635 HDMI */ + { 0x1002, 0xaa28, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV620 HDMI */ + { 0x1002, 0xaa30, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV770 HDMI */ { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */ { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */ { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */ diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h index 20c5e62..8c56c9c 100644 --- a/sound/pci/hda/hda_local.h +++ b/sound/pci/hda/hda_local.h @@ -220,6 +220,7 @@ struct hda_multi_out { hda_nid_t dig_out_nid; /* digital out audio widget */ int max_channels; /* currently supported analog channels */ int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */ + int no_share_stream; /* don't share a stream with multiple pins */ }; int snd_hda_multi_out_dig_open(struct hda_codec *codec, diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c index e94944f..7df1d16 100644 --- a/sound/pci/hda/hda_proc.c +++ b/sound/pci/hda/hda_proc.c @@ -213,7 +213,7 @@ static void print_pin_caps(struct snd_info_buffer *buffer, "SPDIF In", "Digitial In", "Reserved", "Other" }; static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" }; - unsigned int caps; + unsigned int caps, val; caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); snd_iprintf(buffer, " Pincap 0x08%x:", caps); @@ -237,6 +237,11 @@ static void print_pin_caps(struct snd_info_buffer *buffer, snd_iprintf(buffer, " Conn = %s, Color = %s\n", get_jack_connection(caps), get_jack_color(caps)); + if (caps & AC_PINCAP_EAPD) { + val = snd_hda_codec_read(codec, nid, 0, + AC_VERB_GET_EAPD_BTLENABLE, 0); + snd_iprintf(buffer, " EAPD: 0x%x\n", val); + } } @@ -284,6 +289,7 @@ static void print_codec_info(struct snd_info_entry *entry, (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; int conn_len = 0; hda_nid_t conn[HDA_MAX_CONNECTIONS]; + unsigned int pinctls; snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid, get_wid_type_name(wid_type), wid_caps); @@ -299,6 +305,12 @@ static void print_codec_info(struct snd_info_entry *entry, snd_iprintf(buffer, " Amp-Out"); snd_iprintf(buffer, "\n"); + /* volume knob is a special widget that always have connection + * list + */ + if (wid_type == AC_WID_VOL_KNB) + wid_caps |= AC_WCAP_CONN_LIST; + if (wid_caps & AC_WCAP_CONN_LIST) conn_len = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS); @@ -318,8 +330,8 @@ static void print_codec_info(struct snd_info_entry *entry, wid_caps & AC_WCAP_STEREO, 1); } - if (wid_type == AC_WID_PIN) { - unsigned int pinctls; + switch (wid_type) { + case AC_WID_PIN: print_pin_caps(buffer, codec, nid); pinctls = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, @@ -332,12 +344,25 @@ static void print_codec_info(struct snd_info_entry *entry, if (pinctls & AC_PINCTL_HP_EN) snd_iprintf(buffer, " HP"); snd_iprintf(buffer, "\n"); - } - - if ((wid_type == AC_WID_AUD_OUT || wid_type == AC_WID_AUD_IN) && - (wid_caps & AC_WCAP_FORMAT_OVRD)) { - snd_iprintf(buffer, " PCM:\n"); - print_pcm_caps(buffer, codec, nid); + break; + case AC_WID_VOL_KNB: + pinctls = snd_hda_param_read(codec, nid, + AC_PAR_VOL_KNB_CAP); + snd_iprintf(buffer, " Volume-Knob: delta=%d, " + "steps=%d, ", + (pinctls >> 7) & 1, pinctls & 0x7f); + pinctls = snd_hda_codec_read(codec, nid, 0, + AC_VERB_GET_VOLUME_KNOB_CONTROL, 0); + snd_iprintf(buffer, "direct=%d, val=%d\n", + (pinctls >> 7) & 1, pinctls & 0x7f); + break; + case AC_WID_AUD_OUT: + case AC_WID_AUD_IN: + if (wid_caps & AC_WCAP_FORMAT_OVRD) { + snd_iprintf(buffer, " PCM:\n"); + print_pcm_caps(buffer, codec, nid); + } + break; } if (wid_caps & AC_WCAP_POWER) @@ -352,13 +377,15 @@ static void print_codec_info(struct snd_info_entry *entry, curr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0); snd_iprintf(buffer, " Connection: %d\n", conn_len); - snd_iprintf(buffer, " "); - for (c = 0; c < conn_len; c++) { - snd_iprintf(buffer, " 0x%02x", conn[c]); - if (c == curr) - snd_iprintf(buffer, "*"); + if (conn_len > 0) { + snd_iprintf(buffer, " "); + for (c = 0; c < conn_len; c++) { + snd_iprintf(buffer, " 0x%02x", conn[c]); + if (c == curr) + snd_iprintf(buffer, "*"); + } + snd_iprintf(buffer, "\n"); } - snd_iprintf(buffer, "\n"); } } snd_hda_power_down(codec); diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c index 0ee8ae4..b2c5380 100644 --- a/sound/pci/hda/patch_analog.c +++ b/sound/pci/hda/patch_analog.c @@ -370,7 +370,7 @@ static int ad198x_eapd_put(struct snd_kcontrol *kcontrol, int invert = (kcontrol->private_value >> 8) & 1; hda_nid_t nid = kcontrol->private_value & 0xff; unsigned int eapd; - eapd = ucontrol->value.integer.value[0]; + eapd = !!ucontrol->value.integer.value[0]; if (invert) eapd = !eapd; if (eapd == spec->cur_eapd) @@ -841,6 +841,7 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = { SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD), SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD), SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD), + SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP), SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK), SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK), SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP), @@ -957,6 +958,14 @@ static int patch_ad1986a(struct hda_codec *codec) break; } + /* AD1986A has a hardware problem that it can't share a stream + * with multiple output pins. The copy of front to surrounds + * causes noisy or silent outputs at a certain timing, e.g. + * changing the volume. + * So, let's disable the shared stream. + */ + spec->multiout.no_share_stream = 1; + return 0; } @@ -1012,6 +1021,8 @@ static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct ad198x_spec *spec = codec->spec; + if (ucontrol->value.enumerated.item[0] > 1) + return -EINVAL; if (spec->spdif_route != ucontrol->value.enumerated.item[0]) { spec->spdif_route = ucontrol->value.enumerated.item[0]; snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0, @@ -1957,6 +1968,8 @@ static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol, int change; val = ucontrol->value.enumerated.item[0]; + if (val > 3) + return -EINVAL; if (!val) { sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE, diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c index fbb8969..78441e3 100644 --- a/sound/pci/hda/patch_atihdmi.c +++ b/sound/pci/hda/patch_atihdmi.c @@ -158,6 +158,6 @@ struct hda_codec_preset snd_hda_preset_atihdmi[] = { { .id = 0x1002793c, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi }, - { .id = 0x1002aa01, .name = "ATI R600 HDMI", .patch = patch_atihdmi }, + { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi }, {} /* terminator */ }; diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index 6aa0739..68f23b8 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c @@ -373,7 +373,7 @@ static int cxt_eapd_put(struct snd_kcontrol *kcontrol, hda_nid_t nid = kcontrol->private_value & 0xff; unsigned int eapd; - eapd = ucontrol->value.integer.value[0]; + eapd = !!ucontrol->value.integer.value[0]; if (invert) eapd = !eapd; if (eapd == spec->cur_eapd) @@ -765,6 +765,7 @@ static struct snd_pci_quirk cxt5045_cfg_tbl[] = { SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP), SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_FUJITSU), SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP), + SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505", CXT5045_LAPTOP), SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP), {} }; diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 1c50278..14c8c01 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -92,9 +92,11 @@ enum { ALC262_HP_BPC, ALC262_HP_BPC_D7000_WL, ALC262_HP_BPC_D7000_WF, + ALC262_HP_TC_T5735, ALC262_BENQ_ED8, ALC262_SONY_ASSAMD, ALC262_BENQ_T31, + ALC262_ULTRA, ALC262_AUTO, ALC262_MODEL_LAST /* last tag */ }; @@ -7709,6 +7711,81 @@ static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = { { } /* end */ }; +static struct hda_bind_ctls alc262_hp_t5735_bind_front_vol = { + .ops = &snd_hda_bind_vol, + .values = { + HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT), + HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT), + 0 + }, +}; + +static struct hda_bind_ctls alc262_hp_t5735_bind_front_sw = { + .ops = &snd_hda_bind_sw, + .values = { + HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT), + HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT), + 0 + }, +}; + +/* mute/unmute internal speaker according to the hp jack and mute state */ +static void alc262_hp_t5735_automute(struct hda_codec *codec, int force) +{ + struct alc_spec *spec = codec->spec; + unsigned int mute; + + if (force || !spec->sense_updated) { + unsigned int present; + present = snd_hda_codec_read(codec, 0x15, 0, + AC_VERB_GET_PIN_SENSE, 0); + spec->jack_present = (present & 0x80000000) != 0; + spec->sense_updated = 1; + } + if (spec->jack_present) + mute = (0x7080 | ((0)<<8)); /* mute internal speaker */ + else /* unmute internal speaker if necessary */ + mute = (0x7000 | ((0)<<8)); + snd_hda_codec_write(codec, 0x0c, 0, + AC_VERB_SET_AMP_GAIN_MUTE, mute ); +} + +static void alc262_hp_t5735_unsol_event(struct hda_codec *codec, + unsigned int res) +{ + if ((res >> 26) != ALC880_HP_EVENT) + return; + alc262_hp_t5735_automute(codec, 1); +} + +static void alc262_hp_t5735_init_hook(struct hda_codec *codec) +{ + alc262_hp_t5735_automute(codec, 1); +} + +static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = { + HDA_BIND_VOL("PCM Playback Volume", &alc262_hp_t5735_bind_front_vol), + HDA_BIND_SW("PCM Playback Switch",&alc262_hp_t5735_bind_front_sw), + HDA_CODEC_VOLUME("LineOut Playback Volume", 0x0c, 0x0, HDA_OUTPUT), + HDA_CODEC_MUTE("LineOut Playback Switch", 0x14, 0x0, HDA_OUTPUT), + HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT), + HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT), + HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT), + HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), + HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), + HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), + HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), + { } /* end */ +}; + +static struct hda_verb alc262_hp_t5735_verbs[] = { + {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, + {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, + + {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, + { } +}; + /* bind hp and internal speaker mute (with plug check) */ static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) @@ -8082,6 +8159,72 @@ static struct hda_verb alc262_benq_t31_EAPD_verbs[] = { {} }; +/* Samsung Q1 Ultra Vista model setup */ +static struct snd_kcontrol_new alc262_ultra_mixer[] = { + HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), + HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT), + HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), + HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), + HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), + HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT), + { } /* end */ +}; + +static struct hda_verb alc262_ultra_verbs[] = { + {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, + {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, + {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, + /* Mic is on Node 0x19 */ + {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24}, + {0x22, AC_VERB_SET_CONNECT_SEL, 0x01}, + {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, + {0x23, AC_VERB_SET_CONNECT_SEL, 0x01}, + {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, + {0x24, AC_VERB_SET_CONNECT_SEL, 0x01}, + {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, + {} +}; + +static struct hda_input_mux alc262_ultra_capture_source = { + .num_items = 1, + .items = { + { "Mic", 0x1 }, + }, +}; + +/* mute/unmute internal speaker according to the hp jack and mute state */ +static void alc262_ultra_automute(struct hda_codec *codec) +{ + struct alc_spec *spec = codec->spec; + unsigned int mute; + unsigned int present; + + /* need to execute and sync at first */ + snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0); + present = snd_hda_codec_read(codec, 0x15, 0, + AC_VERB_GET_PIN_SENSE, 0); + spec->jack_present = (present & 0x80000000) != 0; + if (spec->jack_present) { + /* mute internal speaker */ + snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, + HDA_AMP_MUTE, HDA_AMP_MUTE); + } else { + /* unmute internal speaker if necessary */ + mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0); + snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, + HDA_AMP_MUTE, mute); + } +} + +/* unsolicited event for HP jack sensing */ +static void alc262_ultra_unsol_event(struct hda_codec *codec, + unsigned int res) +{ + if ((res >> 26) != ALC880_HP_EVENT) + return; + alc262_ultra_automute(codec); +} + /* add playback controls from the parsed DAC table */ static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg) @@ -8484,9 +8627,11 @@ static const char *alc262_models[ALC262_MODEL_LAST] = { [ALC262_FUJITSU] = "fujitsu", [ALC262_HP_BPC] = "hp-bpc", [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000", + [ALC262_HP_TC_T5735] = "hp-tc-t5735", [ALC262_BENQ_ED8] = "benq", [ALC262_BENQ_T31] = "benq-t31", [ALC262_SONY_ASSAMD] = "sony-assamd", + [ALC262_ULTRA] = "ultra", [ALC262_AUTO] = "auto", }; @@ -8496,10 +8641,13 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = { SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC), SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC), SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC), + SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC), SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC), SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC), + SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC), SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC), SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC), + SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC), SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL), SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL), SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL), @@ -8508,6 +8656,8 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = { SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF), SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF), SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF), + SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735", + ALC262_HP_TC_T5735), SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO), SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU), SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1), @@ -8517,6 +8667,7 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = { SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD), SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD), SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD), + SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA), {} }; @@ -8601,6 +8752,18 @@ static struct alc_config_preset alc262_presets[] = { .channel_mode = alc262_modes, .input_mux = &alc262_HP_D7000_capture_source, }, + [ALC262_HP_TC_T5735] = { + .mixers = { alc262_hp_t5735_mixer }, + .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs }, + .num_dacs = ARRAY_SIZE(alc262_dac_nids), + .dac_nids = alc262_dac_nids, + .hp_nid = 0x03, + .num_channel_mode = ARRAY_SIZE(alc262_modes), + .channel_mode = alc262_modes, + .input_mux = &alc262_capture_source, + .unsol_event = alc262_hp_t5735_unsol_event, + .init_hook = alc262_hp_t5735_init_hook, + }, [ALC262_BENQ_ED8] = { .mixers = { alc262_base_mixer }, .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs }, @@ -8635,6 +8798,19 @@ static struct alc_config_preset alc262_presets[] = { .unsol_event = alc262_hippo_unsol_event, .init_hook = alc262_hippo_automute, }, + [ALC262_ULTRA] = { + .mixers = { alc262_ultra_mixer }, + .init_verbs = { alc262_init_verbs, alc262_ultra_verbs }, + .num_dacs = ARRAY_SIZE(alc262_dac_nids), + .dac_nids = alc262_dac_nids, + .hp_nid = 0x03, + .dig_out_nid = ALC262_DIGOUT_NID, + .num_channel_mode = ARRAY_SIZE(alc262_modes), + .channel_mode = alc262_modes, + .input_mux = &alc262_ultra_capture_source, + .unsol_event = alc262_ultra_unsol_event, + .init_hook = alc262_ultra_automute, + }, }; static int patch_alc262(struct hda_codec *codec) @@ -12057,6 +12233,7 @@ static const char *alc662_models[ALC662_MODEL_LAST] = { [ALC662_3ST_6ch] = "3stack-6ch", [ALC662_5ST_DIG] = "6stack-dig", [ALC662_LENOVO_101E] = "lenovo-101e", + [ALC662_ASUS_EEEPC_P701] = "eeepc-p701", [ALC662_AUTO] = "auto", }; diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index f9b2c43..d2996ad 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -62,6 +62,11 @@ enum { }; enum { + STAC_92HD71BXX_REF, + STAC_92HD71BXX_MODELS +}; + +enum { STAC_925x_REF, STAC_M2_2, STAC_MA6, @@ -111,7 +116,6 @@ struct sigmatel_spec { unsigned int alt_switch: 1; unsigned int hp_detect: 1; unsigned int gpio_mute: 1; - unsigned int no_vol_knob :1; unsigned int gpio_mask, gpio_data; @@ -172,6 +176,23 @@ static hda_nid_t stac9200_dac_nids[1] = { 0x02, }; +static hda_nid_t stac92hd71bxx_adc_nids[2] = { + 0x12, 0x13, +}; + +static hda_nid_t stac92hd71bxx_mux_nids[2] = { + 0x1a, 0x1b +}; + +static hda_nid_t stac92hd71bxx_dac_nids[2] = { + 0x10, /*0x11, */ +}; + +#define STAC92HD71BXX_NUM_DMICS 2 +static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = { + 0x18, 0x19, 0 +}; + static hda_nid_t stac925x_adc_nids[1] = { 0x03, }; @@ -205,6 +226,11 @@ static hda_nid_t stac927x_mux_nids[3] = { 0x15, 0x16, 0x17 }; +#define STAC927X_NUM_DMICS 2 +static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = { + 0x13, 0x14, 0 +}; + static hda_nid_t stac9205_adc_nids[2] = { 0x12, 0x13 }; @@ -233,6 +259,11 @@ static hda_nid_t stac922x_pin_nids[10] = { 0x0f, 0x10, 0x11, 0x15, 0x1b, }; +static hda_nid_t stac92hd71bxx_pin_nids[10] = { + 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x14, 0x18, 0x19, 0x1e, +}; + static hda_nid_t stac927x_pin_nids[14] = { 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, @@ -318,12 +349,13 @@ static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol, struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct sigmatel_spec *spec = codec->spec; unsigned int dac_mode; + unsigned int val; - if (spec->aloopback == ucontrol->value.integer.value[0]) + val = !!ucontrol->value.integer.value[0]; + if (spec->aloopback == val) return 0; - spec->aloopback = ucontrol->value.integer.value[0]; - + spec->aloopback = val; dac_mode = snd_hda_codec_read(codec, codec->afg, 0, kcontrol->private_value & 0xFFFF, 0x0); @@ -342,42 +374,6 @@ static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol, return 1; } -static int stac92xx_volknob_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; - uinfo->count = 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = 127; - return 0; -} - -static int stac92xx_volknob_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - ucontrol->value.integer.value[0] = kcontrol->private_value & 0xff; - return 0; -} - -static int stac92xx_volknob_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct hda_codec *codec = snd_kcontrol_chip(kcontrol); - unsigned int val = kcontrol->private_value & 0xff; - - if (val == ucontrol->value.integer.value[0]) - return 0; - - val = ucontrol->value.integer.value[0]; - kcontrol->private_value &= ~0xff; - kcontrol->private_value |= val; - - snd_hda_codec_write_cache(codec, kcontrol->private_value >> 16, 0, - AC_VERB_SET_VOLUME_KNOB_CONTROL, val | 0x80); - return 1; -} - - static struct hda_verb stac9200_core_init[] = { /* set dac0mux for dac converter */ { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00}, @@ -391,6 +387,25 @@ static struct hda_verb stac9200_eapd_init[] = { {} }; +static struct hda_verb stac92hd71bxx_core_init[] = { + /* set master volume and direct control */ + { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, + /* connect headphone jack to dac1 */ + { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01}, + /* connect ports 0d and 0f to audio mixer */ + { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2}, + { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2}, + /* unmute dac0 input in audio mixer */ + { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f}, + /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */ + { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, + { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, + { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, + /* unmute mono out node */ + { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, + {} +}; + static struct hda_verb stac925x_core_init[] = { /* set dac0mux for dac converter */ { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00}, @@ -425,6 +440,16 @@ static struct hda_verb stac9205_core_init[] = { {} }; +#define STAC_DIGITAL_INPUT_SOURCE(cnt) \ + { \ + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ + .name = "Digital Input Source", \ + .count = cnt, \ + .info = stac92xx_dmux_enum_info, \ + .get = stac92xx_dmux_enum_get, \ + .put = stac92xx_dmux_enum_put,\ + } + #define STAC_INPUT_SOURCE(cnt) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ @@ -446,18 +471,6 @@ static struct hda_verb stac9205_core_init[] = { .private_value = verb_read | (verb_write << 16), \ } -#define STAC_VOLKNOB(knob_nid) \ - { \ - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ - .name = "Master Playback Volume", \ - .count = 1, \ - .info = stac92xx_volknob_info, \ - .get = stac92xx_volknob_get, \ - .put = stac92xx_volknob_put, \ - .private_value = 127 | (knob_nid << 16), \ - } - - static struct snd_kcontrol_new stac9200_mixer[] = { HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT), HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT), @@ -468,6 +481,27 @@ static struct snd_kcontrol_new stac9200_mixer[] = { { } /* end */ }; +static struct snd_kcontrol_new stac92hd71bxx_mixer[] = { + STAC_DIGITAL_INPUT_SOURCE(1), + STAC_INPUT_SOURCE(2), + + /* hardware gain controls */ + HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x18, 0x0, HDA_OUTPUT), + HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x19, 0x0, HDA_OUTPUT), + + HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT), + HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT), + HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT), + + HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT), + HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT), + HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT), + + HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT), + HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT), + { } /* end */ +}; + static struct snd_kcontrol_new stac925x_mixer[] = { STAC_INPUT_SOURCE(1), HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT), @@ -477,17 +511,9 @@ static struct snd_kcontrol_new stac925x_mixer[] = { }; static struct snd_kcontrol_new stac9205_mixer[] = { - { - .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "Digital Input Source", - .count = 1, - .info = stac92xx_dmux_enum_info, - .get = stac92xx_dmux_enum_get, - .put = stac92xx_dmux_enum_put, - }, + STAC_DIGITAL_INPUT_SOURCE(1), STAC_INPUT_SOURCE(2), STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0), - STAC_VOLKNOB(0x24), HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT), HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT), @@ -503,7 +529,6 @@ static struct snd_kcontrol_new stac9205_mixer[] = { /* This needs to be generated dynamically based on sequence */ static struct snd_kcontrol_new stac922x_mixer[] = { STAC_INPUT_SOURCE(2), - STAC_VOLKNOB(0x16), HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT), HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT), HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT), @@ -516,8 +541,8 @@ static struct snd_kcontrol_new stac922x_mixer[] = { static struct snd_kcontrol_new stac927x_mixer[] = { + STAC_DIGITAL_INPUT_SOURCE(1), STAC_INPUT_SOURCE(3), - STAC_VOLKNOB(0x24), STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB), HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT), @@ -829,6 +854,27 @@ static struct snd_pci_quirk stac925x_cfg_tbl[] = { {} /* terminator */ }; +static unsigned int ref92hd71bxx_pin_configs[10] = { + 0x02214030, 0x02a19040, 0x01a19020, 0x01014010, + 0x0181302e, 0x01114010, 0x01a19020, 0x90a000f0, + 0x90a000f0, 0x01452050, +}; + +static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = { + [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs, +}; + +static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = { + [STAC_92HD71BXX_REF] = "ref", +}; + +static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = { + /* SigmaTel reference board */ + SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, + "DFI LanParty", STAC_92HD71BXX_REF), + {} /* terminator */ +}; + static unsigned int ref922x_pin_configs[10] = { 0x01014010, 0x01016011, 0x01012012, 0x0221401f, 0x01813122, 0x01011014, 0x01441030, 0x01c41030, @@ -875,8 +921,8 @@ static unsigned int dell_922x_m81_pin_configs[10] = { 102801D7 (Dell XPS M1210) */ static unsigned int dell_922x_m82_pin_configs[10] = { - 0x0221121f, 0x408103ff, 0x02111212, 0x90100310, - 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2, + 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310, + 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2, 0x508003f3, 0x405003f4, }; @@ -1531,7 +1577,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ struct sigmatel_spec *spec = codec->spec; hda_nid_t nid = kcontrol->private_value >> 8; int io_idx = kcontrol-> private_value & 0xff; - unsigned short val = ucontrol->value.integer.value[0]; + unsigned short val = !!ucontrol->value.integer.value[0]; spec->io_switch[io_idx] = val; @@ -1543,6 +1589,13 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ pinctl |= stac92xx_get_vref(codec, nid); stac92xx_auto_set_pinctl(codec, nid, pinctl); } + + /* check the auto-mute again: we need to mute/unmute the speaker + * appropriately according to the pin direction + */ + if (spec->hp_detect) + codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); + return 1; } @@ -1564,11 +1617,12 @@ static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol, struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct sigmatel_spec *spec = codec->spec; hda_nid_t nid = kcontrol->private_value & 0xff; + unsigned int val = !!ucontrol->value.integer.value[0]; - if (spec->clfe_swap == ucontrol->value.integer.value[0]) + if (spec->clfe_swap == val) return 0; - spec->clfe_swap = ucontrol->value.integer.value[0]; + spec->clfe_swap = val; snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE, spec->clfe_swap ? 0x4 : 0x0); @@ -1931,8 +1985,7 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, } if (spec->multiout.hp_nid) { const char *pfx; - if (old_num_dacs == spec->multiout.num_dacs && - spec->no_vol_knob) + if (old_num_dacs == spec->multiout.num_dacs) pfx = "Master"; else pfx = "Headphone"; @@ -2079,6 +2132,7 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out { struct sigmatel_spec *spec = codec->spec; int err; + int hp_speaker_swap = 0; if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, @@ -2087,6 +2141,24 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out if (! spec->autocfg.line_outs) return 0; /* can't find valid pin config */ + /* If we have no real line-out pin and multiple hp-outs, HPs should + * be set up as multi-channel outputs. + */ + if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && + spec->autocfg.hp_outs > 1) { + /* Copy hp_outs to line_outs, backup line_outs in + * speaker_outs so that the following routines can handle + * HP pins as primary outputs. + */ + memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins, + sizeof(spec->autocfg.line_out_pins)); + spec->autocfg.speaker_outs = spec->autocfg.line_outs; + memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins, + sizeof(spec->autocfg.hp_pins)); + spec->autocfg.line_outs = spec->autocfg.hp_outs; + hp_speaker_swap = 1; + } + if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0) return err; if (spec->multiout.num_dacs == 0) @@ -2098,6 +2170,19 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out if (err < 0) return err; + if (hp_speaker_swap == 1) { + /* Restore the hp_outs and line_outs */ + memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins, + sizeof(spec->autocfg.line_out_pins)); + spec->autocfg.hp_outs = spec->autocfg.line_outs; + memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins, + sizeof(spec->autocfg.speaker_pins)); + spec->autocfg.line_outs = spec->autocfg.speaker_outs; + memset(spec->autocfg.speaker_pins, 0, + sizeof(spec->autocfg.speaker_pins)); + spec->autocfg.speaker_outs = 0; + } + err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg); if (err < 0) @@ -2395,13 +2480,20 @@ static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, pin_ctl & ~flag); } -static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) +static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid) { if (!nid) return 0; if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00) - & (1 << 31)) - return 1; + & (1 << 31)) { + unsigned int pinctl; + pinctl = snd_hda_codec_read(codec, nid, 0, + AC_VERB_GET_PIN_WIDGET_CONTROL, 0); + if (pinctl & AC_PINCTL_IN_EN) + return 0; /* mic- or line-input */ + else + return 1; /* HP-output */ + } return 0; } @@ -2413,7 +2505,7 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res) presence = 0; for (i = 0; i < cfg->hp_outs; i++) { - presence = get_pin_presence(codec, cfg->hp_pins[i]); + presence = get_hp_pin_presence(codec, cfg->hp_pins[i]); if (presence) break; } @@ -2489,7 +2581,6 @@ static int patch_stac9200(struct hda_codec *codec) codec->spec = spec; spec->num_pins = ARRAY_SIZE(stac9200_pin_nids); spec->pin_nids = stac9200_pin_nids; - spec->no_vol_knob = 1; spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS, stac9200_models, stac9200_cfg_tbl); @@ -2544,7 +2635,6 @@ static int patch_stac925x(struct hda_codec *codec) codec->spec = spec; spec->num_pins = ARRAY_SIZE(stac925x_pin_nids); spec->pin_nids = stac925x_pin_nids; - spec->no_vol_knob = 1; spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS, stac925x_models, stac925x_cfg_tbl); @@ -2606,6 +2696,77 @@ static int patch_stac925x(struct hda_codec *codec) return 0; } +static int patch_stac92hd71bxx(struct hda_codec *codec) +{ + struct sigmatel_spec *spec; + int err = 0; + + spec = kzalloc(sizeof(*spec), GFP_KERNEL); + if (spec == NULL) + return -ENOMEM; + + codec->spec = spec; + spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids); + spec->pin_nids = stac92hd71bxx_pin_nids; + spec->board_config = snd_hda_check_board_config(codec, + STAC_92HD71BXX_MODELS, + stac92hd71bxx_models, + stac92hd71bxx_cfg_tbl); +again: + if (spec->board_config < 0) { + snd_printdd(KERN_INFO "hda_codec: Unknown model for" + " STAC92HD71BXX, using BIOS defaults\n"); + err = stac92xx_save_bios_config_regs(codec); + if (err < 0) { + stac92xx_free(codec); + return err; + } + spec->pin_configs = spec->bios_pin_configs; + } else { + spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config]; + stac92xx_set_config_regs(codec); + } + + spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */ + stac92xx_enable_gpio_mask(codec); + + spec->init = stac92hd71bxx_core_init; + spec->mixer = stac92hd71bxx_mixer; + + spec->mux_nids = stac92hd71bxx_mux_nids; + spec->adc_nids = stac92hd71bxx_adc_nids; + spec->dmic_nids = stac92hd71bxx_dmic_nids; + spec->dmux_nid = 0x1c; + + spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids); + spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids); + spec->num_dmics = STAC92HD71BXX_NUM_DMICS; + + spec->multiout.num_dacs = 2; + spec->multiout.hp_nid = 0x11; + spec->multiout.dac_nids = stac92hd71bxx_dac_nids; + + err = stac92xx_parse_auto_config(codec, 0x21, 0x23); + if (!err) { + if (spec->board_config < 0) { + printk(KERN_WARNING "hda_codec: No auto-config is " + "available, default to model=ref\n"); + spec->board_config = STAC_92HD71BXX_REF; + goto again; + } + err = -EINVAL; + } + + if (err < 0) { + stac92xx_free(codec); + return err; + } + + codec->patch_ops = stac92xx_patch_ops; + + return 0; +}; + static int patch_stac922x(struct hda_codec *codec) { struct sigmatel_spec *spec; @@ -2743,7 +2904,6 @@ static int patch_stac927x(struct hda_codec *codec) spec->mux_nids = stac927x_mux_nids; spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids); - spec->num_dmics = 0; spec->init = d965_core_init; spec->mixer = stac927x_mixer; break; @@ -2752,7 +2912,6 @@ static int patch_stac927x(struct hda_codec *codec) spec->mux_nids = stac927x_mux_nids; spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids); - spec->num_dmics = 0; spec->init = d965_core_init; spec->mixer = stac927x_mixer; break; @@ -2761,14 +2920,33 @@ static int patch_stac927x(struct hda_codec *codec) spec->mux_nids = stac927x_mux_nids; spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids); - spec->num_dmics = 0; spec->init = stac927x_core_init; spec->mixer = stac927x_mixer; } + switch (codec->subsystem_id) { + case 0x10280242: /* STAC 9228 */ + case 0x102801f3: + case 0x1028020A: + case 0x10280209: + spec->dmic_nids = stac927x_dmic_nids; + spec->num_dmics = STAC927X_NUM_DMICS; + spec->dmux_nid = 0x1b; + + /* Enable DMIC0 */ + stac92xx_set_config_reg(codec, 0x13, 0x90a60040); + + /* GPIO2 High = Enable EAPD */ + spec->gpio_mask = spec->gpio_data = 0x00000004; + break; + default: + spec->num_dmics = 0; + + /* GPIO0 High = Enable EAPD */ + spec->gpio_mask = spec->gpio_data = 0x00000001; + } + spec->multiout.dac_nids = spec->dac_nids; - /* GPIO0 High = Enable EAPD */ - spec->gpio_mask = spec->gpio_data = 0x00000001; stac92xx_enable_gpio_mask(codec); err = stac92xx_parse_auto_config(codec, 0x1e, 0x20); @@ -3005,7 +3183,7 @@ static int stac9872_vaio_init(struct hda_codec *codec) static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res) { - if (get_pin_presence(codec, 0x0a)) { + if (get_hp_pin_presence(codec, 0x0a)) { stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN); stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN); } else { @@ -3159,5 +3337,6 @@ struct hda_codec_preset snd_hda_preset_sigmatel[] = { { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 }, { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 }, { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 }, + { .id = 0x111d76b0, .name = "92HD71BXX", .patch = patch_stac92hd71bxx }, {} /* terminator */ }; diff --git a/sound/pci/ice1712/Makefile b/sound/pci/ice1712/Makefile index 65ce66a..ee86a1d 100644 --- a/sound/pci/ice1712/Makefile +++ b/sound/pci/ice1712/Makefile @@ -5,7 +5,7 @@ snd-ice17xx-ak4xxx-objs := ak4xxx.o snd-ice1712-objs := ice1712.o delta.o hoontech.o ews.o -snd-ice1724-objs := ice1724.o amp.o revo.o aureon.o vt1720_mobo.o pontis.o prodigy192.o juli.o phase.o wtm.o +snd-ice1724-objs := ice1724.o amp.o revo.o aureon.o vt1720_mobo.o pontis.o prodigy192.o juli.o phase.o wtm.o se.o # Toplevel Module Dependency obj-$(CONFIG_SND_ICE1712) += snd-ice1712.o snd-ice17xx-ak4xxx.o diff --git a/sound/pci/ice1712/aureon.c b/sound/pci/ice1712/aureon.c index ec0699c..f83ec2f 100644 --- a/sound/pci/ice1712/aureon.c +++ b/sound/pci/ice1712/aureon.c @@ -205,7 +205,7 @@ static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); - ucontrol->value.integer.value[0] = ice->spec.aureon.pca9554_out; + ucontrol->value.enumerated.item[0] = ice->spec.aureon.pca9554_out; return 0; } @@ -216,10 +216,11 @@ static int aureon_universe_inmux_put(struct snd_kcontrol *kcontrol, unsigned char oval, nval; int change; + nval = ucontrol->value.enumerated.item[0]; + if (nval >= 3) + return -EINVAL; snd_ice1712_save_gpio_status(ice); - oval = ice->spec.aureon.pca9554_out; - nval = ucontrol->value.integer.value[0]; if ((change = (oval != nval))) { aureon_pca9554_write(ice, PCA9554_OUT, nval); ice->spec.aureon.pca9554_out = nval; @@ -757,10 +758,13 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ snd_ice1712_save_gpio_status(ice); for (ch = 0; ch < 2; ch++) { - if (ucontrol->value.integer.value[ch] != ice->spec.aureon.master[ch]) { + unsigned int vol = ucontrol->value.integer.value[ch]; + if (vol > WM_VOL_MAX) + continue; + vol |= ice->spec.aureon.master[ch] & WM_VOL_MUTE; + if (vol != ice->spec.aureon.master[ch]) { int dac; - ice->spec.aureon.master[ch] &= WM_VOL_MUTE; - ice->spec.aureon.master[ch] |= ucontrol->value.integer.value[ch]; + ice->spec.aureon.master[ch] = vol; for (dac = 0; dac < ice->num_total_dacs; dac += 2) wm_set_vol(ice, WM_DAC_ATTEN + dac + ch, ice->spec.aureon.vol[dac + ch], @@ -807,10 +811,13 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value * ofs = kcontrol->private_value & 0xff; snd_ice1712_save_gpio_status(ice); for (i = 0; i < voices; i++) { - idx = WM_DAC_ATTEN + ofs + i; - if (ucontrol->value.integer.value[i] != ice->spec.aureon.vol[ofs+i]) { - ice->spec.aureon.vol[ofs+i] &= WM_VOL_MUTE; - ice->spec.aureon.vol[ofs+i] |= ucontrol->value.integer.value[i]; + unsigned int vol = ucontrol->value.integer.value[i]; + if (vol > 0x7f) + continue; + vol |= ice->spec.aureon.vol[ofs+i]; + if (vol != ice->spec.aureon.vol[ofs+i]) { + ice->spec.aureon.vol[ofs+i] = vol; + idx = WM_DAC_ATTEN + ofs + i; wm_set_vol(ice, idx, ice->spec.aureon.vol[ofs+i], ice->spec.aureon.master[i]); change = 1; @@ -940,8 +947,10 @@ static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val unsigned short ovol, nvol; int change = 0; - snd_ice1712_save_gpio_status(ice); nvol = ucontrol->value.integer.value[0]; + if (nvol > PCM_RES) + return -EINVAL; + snd_ice1712_save_gpio_status(ice); nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff; ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff; if (ovol != nvol) { @@ -1031,7 +1040,7 @@ static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val snd_ice1712_save_gpio_status(ice); for (i = 0; i < 2; i++) { idx = WM_ADC_GAIN + i; - nvol = ucontrol->value.integer.value[i]; + nvol = ucontrol->value.integer.value[i] & 0x1f; ovol = wm_get(ice, idx); if ((ovol & 0x1f) != nvol) { wm_put(ice, idx, nvol | (ovol & ~0x1f)); diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h index 58640af..3c3cac3 100644 --- a/sound/pci/ice1712/ice1712.h +++ b/sound/pci/ice1712/ice1712.h @@ -400,6 +400,12 @@ struct snd_ice1712 { struct { struct ak4114 *ak4114; } prodigy192; + struct { + struct { + unsigned char ch1, ch2; + } vol[8]; + } se; + } spec; }; diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c index 0b0bbb0..357bdbe 100644 --- a/sound/pci/ice1712/ice1724.c +++ b/sound/pci/ice1712/ice1724.c @@ -51,6 +51,7 @@ #include "juli.h" #include "phase.h" #include "wtm.h" +#include "se.h" MODULE_AUTHOR("Jaroslav Kysela "); MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)"); @@ -65,6 +66,7 @@ MODULE_SUPPORTED_DEVICE("{" JULI_DEVICE_DESC PHASE_DEVICE_DESC WTM_DEVICE_DESC + SE_DEVICE_DESC "{VIA,VT1720}," "{VIA,VT1724}," "{ICEnsemble,Generic ICE1724}," @@ -1933,6 +1935,7 @@ static struct snd_ice1712_card_info *card_tables[] __devinitdata = { snd_vt1724_juli_cards, snd_vt1724_phase_cards, snd_vt1724_wtm_cards, + snd_vt1724_se_cards, NULL, }; diff --git a/sound/pci/ice1712/phase.c b/sound/pci/ice1712/phase.c index 3ac2505..c81efc2 100644 --- a/sound/pci/ice1712/phase.c +++ b/sound/pci/ice1712/phase.c @@ -326,10 +326,13 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ snd_ice1712_save_gpio_status(ice); for (ch = 0; ch < 2; ch++) { - if (ucontrol->value.integer.value[ch] != ice->spec.phase28.master[ch]) { + unsigned int vol = ucontrol->value.integer.value[ch]; + if (vol > WM_VOL_MAX) + continue; + vol |= ice->spec.phase28.master[ch] & WM_VOL_MUTE; + if (vol != ice->spec.phase28.master[ch]) { int dac; - ice->spec.phase28.master[ch] &= WM_VOL_MUTE; - ice->spec.phase28.master[ch] |= ucontrol->value.integer.value[ch]; + ice->spec.phase28.master[ch] = vol; for (dac = 0; dac < ice->num_total_dacs; dac += 2) wm_set_vol(ice, WM_DAC_ATTEN + dac + ch, ice->spec.phase28.vol[dac + ch], @@ -462,10 +465,14 @@ static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value * ofs = kcontrol->private_value & 0xff; snd_ice1712_save_gpio_status(ice); for (i = 0; i < voices; i++) { - idx = WM_DAC_ATTEN + ofs + i; - if (ucontrol->value.integer.value[i] != ice->spec.phase28.vol[ofs+i]) { - ice->spec.phase28.vol[ofs+i] &= WM_VOL_MUTE; - ice->spec.phase28.vol[ofs+i] |= ucontrol->value.integer.value[i]; + unsigned int vol; + vol = ucontrol->value.integer.value[i]; + if (vol > 0x7f) + continue; + vol |= ice->spec.phase28.vol[ofs+i] & WM_VOL_MUTE; + if (vol != ice->spec.phase28.vol[ofs+i]) { + ice->spec.phase28.vol[ofs+i] = vol; + idx = WM_DAC_ATTEN + ofs + i; wm_set_vol(ice, idx, ice->spec.phase28.vol[ofs+i], ice->spec.phase28.master[i]); change = 1; @@ -595,8 +602,10 @@ static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val unsigned short ovol, nvol; int change = 0; - snd_ice1712_save_gpio_status(ice); nvol = ucontrol->value.integer.value[0]; + if (nvol > PCM_RES) + return -EINVAL; + snd_ice1712_save_gpio_status(ice); nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff; ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff; if (ovol != nvol) { diff --git a/sound/pci/ice1712/prodigy192.c b/sound/pci/ice1712/prodigy192.c index 4180f97..4b21d5c 100644 --- a/sound/pci/ice1712/prodigy192.c +++ b/sound/pci/ice1712/prodigy192.c @@ -241,7 +241,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el for (i = 0; i < 2; ++i) { reg = STAC946X_MIC_L_VOLUME + i; - nvol = ucontrol->value.integer.value[i]; + nvol = ucontrol->value.integer.value[i] & 0x0f; ovol = 0x0f - stac9460_get(ice, reg); change = ((ovol & 0x0f) != nvol); if (change) diff --git a/sound/pci/ice1712/se.c b/sound/pci/ice1712/se.c new file mode 100644 index 0000000..3c8b518 --- /dev/null +++ b/sound/pci/ice1712/se.c @@ -0,0 +1,756 @@ +/* + * ALSA driver for ICEnsemble VT1724 (Envy24HT) + * + * Lowlevel functions for ONKYO WAVIO SE-90PCI and SE-200PCI + * + * Copyright (c) 2007 Shin-ya Okada sh_okada(at)d4.dion.ne.jp + * (at) -> @ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ice1712.h" +#include "envy24ht.h" +#include "se.h" + + +/****************************************************************************/ +/* ONKYO WAVIO SE-200PCI */ +/****************************************************************************/ +/* + * system configuration ICE_EEP2_SYSCONF=0x4b + * XIN1 49.152MHz + * not have UART + * one stereo ADC and a S/PDIF receiver connected + * four stereo DACs connected + * + * AC-Link configuration ICE_EEP2_ACLINK=0x80 + * use I2C, not use AC97 + * + * I2S converters feature ICE_EEP2_I2S=0x78 + * I2S codec has no volume/mute control feature + * I2S codec supports 96KHz and 192KHz + * I2S codec 24bits + * + * S/PDIF configuration ICE_EEP2_SPDIF=0xc3 + * Enable integrated S/PDIF transmitter + * internal S/PDIF out implemented + * S/PDIF is stereo + * External S/PDIF out implemented + * + * + * ** connected chips ** + * + * WM8740 + * A 2ch-DAC of main outputs. + * It setuped as I2S mode by wire, so no way to setup from software. + * The sample-rate are automatically changed. + * ML/I2S (28pin) --------+ + * MC/DM1 (27pin) -- 5V | + * MD/DM0 (26pin) -- GND | + * MUTEB (25pin) -- NC | + * MODE (24pin) -- GND | + * CSBIW (23pin) --------+ + * | + * RSTB (22pin) --R(1K)-+ + * Probably it reduce the noise from the control line. + * + * WM8766 + * A 6ch-DAC for surrounds. + * It's control wire was connected to GPIOxx (3-wire serial interface) + * ML/I2S (11pin) -- GPIO18 + * MC/IWL (12pin) -- GPIO17 + * MD/DM (13pin) -- GPIO16 + * MUTE (14pin) -- GPIO01 + * + * WM8776 + * A 2ch-ADC(with 10ch-selector) plus 2ch-DAC. + * It's control wire was connected to SDA/SCLK (2-wire serial interface) + * MODE (16pin) -- R(1K) -- GND + * CE (17pin) -- R(1K) -- GND 2-wire mode (address=0x34) + * DI (18pin) -- SDA + * CL (19pin) -- SCLK + * + * + * ** output pins and device names ** + * + * 7.1ch name -- output connector color -- device (-D option) + * + * FRONT 2ch -- green -- plughw:0,0 + * CENTER(Lch) SUBWOOFER(Rch) -- black -- plughw:0,2,0 + * SURROUND 2ch -- orange -- plughw:0,2,1 + * SURROUND BACK 2ch -- white -- plughw:0,2,2 + * + */ + + +/****************************************************************************/ +/* WM8740 interface */ +/****************************************************************************/ + +static void __devinit se200pci_WM8740_init(struct snd_ice1712 *ice) +{ + /* nothing to do */ +} + + +static void se200pci_WM8740_set_pro_rate(struct snd_ice1712 *ice, + unsigned int rate) +{ + /* nothing to do */ +} + + +/****************************************************************************/ +/* WM8766 interface */ +/****************************************************************************/ + +static void se200pci_WM8766_write(struct snd_ice1712 *ice, + unsigned int addr, unsigned int data) +{ + unsigned int st; + unsigned int bits; + int i; + const unsigned int DATA = 0x010000; + const unsigned int CLOCK = 0x020000; + const unsigned int LOAD = 0x040000; + const unsigned int ALL_MASK = (DATA | CLOCK | LOAD); + + snd_ice1712_save_gpio_status(ice); + + st = ((addr & 0x7f) << 9) | (data & 0x1ff); + snd_ice1712_gpio_set_dir(ice, ice->gpio.direction | ALL_MASK); + snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask & ~ALL_MASK); + bits = snd_ice1712_gpio_read(ice) & ~ALL_MASK; + + snd_ice1712_gpio_write(ice, bits); + for (i = 0; i < 16; i++) { + udelay(1); + bits &= ~CLOCK; + st = (st << 1); + if (st & 0x10000) + bits |= DATA; + else + bits &= ~DATA; + + snd_ice1712_gpio_write(ice, bits); + + udelay(1); + bits |= CLOCK; + snd_ice1712_gpio_write(ice, bits); + } + + udelay(1); + bits |= LOAD; + snd_ice1712_gpio_write(ice, bits); + + udelay(1); + bits |= (DATA | CLOCK); + snd_ice1712_gpio_write(ice, bits); + + snd_ice1712_restore_gpio_status(ice); +} + +static void se200pci_WM8766_set_volume(struct snd_ice1712 *ice, int ch, + unsigned int vol1, unsigned int vol2) +{ + switch (ch) { + case 0: + se200pci_WM8766_write(ice, 0x000, vol1); + se200pci_WM8766_write(ice, 0x001, vol2 | 0x100); + break; + case 1: + se200pci_WM8766_write(ice, 0x004, vol1); + se200pci_WM8766_write(ice, 0x005, vol2 | 0x100); + break; + case 2: + se200pci_WM8766_write(ice, 0x006, vol1); + se200pci_WM8766_write(ice, 0x007, vol2 | 0x100); + break; + } +} + +static void __devinit se200pci_WM8766_init(struct snd_ice1712 *ice) +{ + se200pci_WM8766_write(ice, 0x1f, 0x000); /* RESET ALL */ + udelay(10); + + se200pci_WM8766_set_volume(ice, 0, 0, 0); /* volume L=0 R=0 */ + se200pci_WM8766_set_volume(ice, 1, 0, 0); /* volume L=0 R=0 */ + se200pci_WM8766_set_volume(ice, 2, 0, 0); /* volume L=0 R=0 */ + + se200pci_WM8766_write(ice, 0x03, 0x022); /* serial mode I2S-24bits */ + se200pci_WM8766_write(ice, 0x0a, 0x080); /* MCLK=256fs */ + se200pci_WM8766_write(ice, 0x12, 0x000); /* MDP=0 */ + se200pci_WM8766_write(ice, 0x15, 0x000); /* MDP=0 */ + se200pci_WM8766_write(ice, 0x09, 0x000); /* demp=off mute=off */ + + se200pci_WM8766_write(ice, 0x02, 0x124); /* ch-assign L=L R=R RESET */ + se200pci_WM8766_write(ice, 0x02, 0x120); /* ch-assign L=L R=R */ +} + +static void se200pci_WM8766_set_pro_rate(struct snd_ice1712 *ice, + unsigned int rate) +{ + if (rate > 96000) + se200pci_WM8766_write(ice, 0x0a, 0x000); /* MCLK=128fs */ + else + se200pci_WM8766_write(ice, 0x0a, 0x080); /* MCLK=256fs */ +} + + +/****************************************************************************/ +/* WM8776 interface */ +/****************************************************************************/ + +static void se200pci_WM8776_write(struct snd_ice1712 *ice, + unsigned int addr, unsigned int data) +{ + unsigned int val; + + val = (addr << 9) | data; + snd_vt1724_write_i2c(ice, 0x34, val >> 8, val & 0xff); +} + + +static void se200pci_WM8776_set_output_volume(struct snd_ice1712 *ice, + unsigned int vol1, unsigned int vol2) +{ + se200pci_WM8776_write(ice, 0x03, vol1); + se200pci_WM8776_write(ice, 0x04, vol2 | 0x100); +} + +static void se200pci_WM8776_set_input_volume(struct snd_ice1712 *ice, + unsigned int vol1, unsigned int vol2) +{ + se200pci_WM8776_write(ice, 0x0e, vol1); + se200pci_WM8776_write(ice, 0x0f, vol2 | 0x100); +} + +static const char *se200pci_sel[] = { + "LINE-IN", "CD-IN", "MIC-IN", "ALL-MIX", NULL +}; + +static void se200pci_WM8776_set_input_selector(struct snd_ice1712 *ice, + unsigned int sel) +{ + static unsigned char vals[] = { + /* LINE, CD, MIC, ALL, GND */ + 0x10, 0x04, 0x08, 0x1c, 0x03 + }; + if (sel > 4) + sel = 4; + se200pci_WM8776_write(ice, 0x15, vals[sel]); +} + +static void se200pci_WM8776_set_afl(struct snd_ice1712 *ice, unsigned int afl) +{ + /* AFL -- After Fader Listening */ + if (afl) + se200pci_WM8776_write(ice, 0x16, 0x005); + else + se200pci_WM8776_write(ice, 0x16, 0x001); +} + +static const char *se200pci_agc[] = { + "Off", "LimiterMode", "ALCMode", NULL +}; + +static void se200pci_WM8776_set_agc(struct snd_ice1712 *ice, unsigned int agc) +{ + /* AGC -- Auto Gain Control of the input */ + switch (agc) { + case 0: + se200pci_WM8776_write(ice, 0x11, 0x000); /* Off */ + break; + case 1: + se200pci_WM8776_write(ice, 0x10, 0x07b); + se200pci_WM8776_write(ice, 0x11, 0x100); /* LimiterMode */ + break; + case 2: + se200pci_WM8776_write(ice, 0x10, 0x1fb); + se200pci_WM8776_write(ice, 0x11, 0x100); /* ALCMode */ + break; + } +} + +static void __devinit se200pci_WM8776_init(struct snd_ice1712 *ice) +{ + int i; + static unsigned short __devinitdata default_values[] = { + 0x100, 0x100, 0x100, + 0x100, 0x100, 0x100, + 0x000, 0x090, 0x000, 0x000, + 0x022, 0x022, 0x022, + 0x008, 0x0cf, 0x0cf, 0x07b, 0x000, + 0x032, 0x000, 0x0a6, 0x001, 0x001 + }; + + se200pci_WM8776_write(ice, 0x17, 0x000); /* reset all */ + /* ADC and DAC interface is I2S 24bits mode */ + /* The sample-rate are automatically changed */ + udelay(10); + /* BUT my board can not do reset all, so I load all by manually. */ + for (i = 0; i < ARRAY_SIZE(default_values); i++) + se200pci_WM8776_write(ice, i, default_values[i]); + + se200pci_WM8776_set_input_selector(ice, 0); + se200pci_WM8776_set_afl(ice, 0); + se200pci_WM8776_set_agc(ice, 0); + se200pci_WM8776_set_input_volume(ice, 0, 0); + se200pci_WM8776_set_output_volume(ice, 0, 0); + + /* head phone mute and power down */ + se200pci_WM8776_write(ice, 0x00, 0); + se200pci_WM8776_write(ice, 0x01, 0); + se200pci_WM8776_write(ice, 0x02, 0x100); + se200pci_WM8776_write(ice, 0x0d, 0x080); +} + +static void se200pci_WM8776_set_pro_rate(struct snd_ice1712 *ice, + unsigned int rate) +{ + /* nothing to do */ +} + + +/****************************************************************************/ +/* runtime interface */ +/****************************************************************************/ + +static void se200pci_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate) +{ + se200pci_WM8740_set_pro_rate(ice, rate); + se200pci_WM8766_set_pro_rate(ice, rate); + se200pci_WM8776_set_pro_rate(ice, rate); +} + +struct se200pci_control { + char *name; + enum { + WM8766, + WM8776in, + WM8776out, + WM8776sel, + WM8776agc, + WM8776afl + } target; + enum { VOLUME1, VOLUME2, BOOLEAN, ENUM } type; + int ch; + const char **member; + const char *comment; +}; + +static const struct se200pci_control se200pci_cont[] = { + { + .name = "Front Playback Volume", + .target = WM8776out, + .type = VOLUME1, + .comment = "Front(green)" + }, + { + .name = "Side Playback Volume", + .target = WM8766, + .type = VOLUME1, + .ch = 1, + .comment = "Surround(orange)" + }, + { + .name = "Surround Playback Volume", + .target = WM8766, + .type = VOLUME1, + .ch = 2, + .comment = "SurroundBack(white)" + }, + { + .name = "CLFE Playback Volume", + .target = WM8766, + .type = VOLUME1, + .ch = 0, + .comment = "Center(Lch)&SubWoofer(Rch)(black)" + }, + { + .name = "Capture Volume", + .target = WM8776in, + .type = VOLUME2 + }, + { + .name = "Capture Select", + .target = WM8776sel, + .type = ENUM, + .member = se200pci_sel + }, + { + .name = "AGC Capture Mode", + .target = WM8776agc, + .type = ENUM, + .member = se200pci_agc + }, + { + .name = "AFL Bypass Playback Switch", + .target = WM8776afl, + .type = BOOLEAN + } +}; + +static int se200pci_get_enum_count(int n) +{ + const char **member; + int c; + + member = se200pci_cont[n].member; + if (!member) + return 0; + for (c = 0; member[c]; c++) + ; + return c; +} + +static int se200pci_cont_volume_info(struct snd_kcontrol *kc, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 2; + uinfo->value.integer.min = 0; /* mute */ + uinfo->value.integer.max = 0xff; /* 0dB */ + return 0; +} + +#define se200pci_cont_boolean_info snd_ctl_boolean_mono_info + +static int se200pci_cont_enum_info(struct snd_kcontrol *kc, + struct snd_ctl_elem_info *uinfo) +{ + int n, c; + + n = kc->private_value; + c = se200pci_get_enum_count(n); + if (!c) + return -EINVAL; + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; + uinfo->count = 1; + uinfo->value.enumerated.items = c; + if (uinfo->value.enumerated.item >= c) + uinfo->value.enumerated.item = c - 1; + strcpy(uinfo->value.enumerated.name, + se200pci_cont[n].member[uinfo->value.enumerated.item]); + return 0; +} + +static int se200pci_cont_volume_get(struct snd_kcontrol *kc, + struct snd_ctl_elem_value *uc) +{ + struct snd_ice1712 *ice = snd_kcontrol_chip(kc); + int n = kc->private_value; + uc->value.integer.value[0] = ice->spec.se.vol[n].ch1; + uc->value.integer.value[1] = ice->spec.se.vol[n].ch2; + return 0; +} + +static int se200pci_cont_boolean_get(struct snd_kcontrol *kc, + struct snd_ctl_elem_value *uc) +{ + struct snd_ice1712 *ice = snd_kcontrol_chip(kc); + int n = kc->private_value; + uc->value.integer.value[0] = ice->spec.se.vol[n].ch1; + return 0; +} + +static int se200pci_cont_enum_get(struct snd_kcontrol *kc, + struct snd_ctl_elem_value *uc) +{ + struct snd_ice1712 *ice = snd_kcontrol_chip(kc); + int n = kc->private_value; + uc->value.enumerated.item[0] = ice->spec.se.vol[n].ch1; + return 0; +} + +static void se200pci_cont_update(struct snd_ice1712 *ice, int n) +{ + switch (se200pci_cont[n].target) { + case WM8766: + se200pci_WM8766_set_volume(ice, + se200pci_cont[n].ch, + ice->spec.se.vol[n].ch1, + ice->spec.se.vol[n].ch2); + break; + + case WM8776in: + se200pci_WM8776_set_input_volume(ice, + ice->spec.se.vol[n].ch1, + ice->spec.se.vol[n].ch2); + break; + + case WM8776out: + se200pci_WM8776_set_output_volume(ice, + ice->spec.se.vol[n].ch1, + ice->spec.se.vol[n].ch2); + break; + + case WM8776sel: + se200pci_WM8776_set_input_selector(ice, + ice->spec.se.vol[n].ch1); + break; + + case WM8776agc: + se200pci_WM8776_set_agc(ice, ice->spec.se.vol[n].ch1); + break; + + case WM8776afl: + se200pci_WM8776_set_afl(ice, ice->spec.se.vol[n].ch1); + break; + + default: + break; + } +} + +static int se200pci_cont_volume_put(struct snd_kcontrol *kc, + struct snd_ctl_elem_value *uc) +{ + struct snd_ice1712 *ice = snd_kcontrol_chip(kc); + int n = kc->private_value; + unsigned int vol1, vol2; + int changed; + + changed = 0; + vol1 = uc->value.integer.value[0] & 0xff; + vol2 = uc->value.integer.value[1] & 0xff; + if (ice->spec.se.vol[n].ch1 != vol1) { + ice->spec.se.vol[n].ch1 = vol1; + changed = 1; + } + if (ice->spec.se.vol[n].ch2 != vol2) { + ice->spec.se.vol[n].ch2 = vol2; + changed = 1; + } + if (changed) + se200pci_cont_update(ice, n); + + return changed; +} + +static int se200pci_cont_boolean_put(struct snd_kcontrol *kc, + struct snd_ctl_elem_value *uc) +{ + struct snd_ice1712 *ice = snd_kcontrol_chip(kc); + int n = kc->private_value; + unsigned int vol1; + + vol1 = !!uc->value.integer.value[0]; + if (ice->spec.se.vol[n].ch1 != vol1) { + ice->spec.se.vol[n].ch1 = vol1; + se200pci_cont_update(ice, n); + return 1; + } + return 0; +} + +static int se200pci_cont_enum_put(struct snd_kcontrol *kc, + struct snd_ctl_elem_value *uc) +{ + struct snd_ice1712 *ice = snd_kcontrol_chip(kc); + int n = kc->private_value; + unsigned int vol1; + + vol1 = uc->value.enumerated.item[0]; + if (vol1 >= se200pci_get_enum_count(n)) + return -EINVAL; + if (ice->spec.se.vol[n].ch1 != vol1) { + ice->spec.se.vol[n].ch1 = vol1; + se200pci_cont_update(ice, n); + return 1; + } + return 0; +} + +static const DECLARE_TLV_DB_SCALE(db_scale_gain1, -12750, 50, 1); +static const DECLARE_TLV_DB_SCALE(db_scale_gain2, -10350, 50, 1); + +static int __devinit se200pci_add_controls(struct snd_ice1712 *ice) +{ + int i; + struct snd_kcontrol_new cont; + int err; + + memset(&cont, 0, sizeof(cont)); + cont.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + for (i = 0; i < ARRAY_SIZE(se200pci_cont); i++) { + cont.private_value = i; + cont.name = se200pci_cont[i].name; + cont.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; + cont.tlv.p = NULL; + switch (se200pci_cont[i].type) { + case VOLUME1: + case VOLUME2: + cont.info = se200pci_cont_volume_info; + cont.get = se200pci_cont_volume_get; + cont.put = se200pci_cont_volume_put; + cont.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; + if (se200pci_cont[i].type == VOLUME1) + cont.tlv.p = db_scale_gain1; + else + cont.tlv.p = db_scale_gain2; + break; + case BOOLEAN: + cont.info = se200pci_cont_boolean_info; + cont.get = se200pci_cont_boolean_get; + cont.put = se200pci_cont_boolean_put; + break; + case ENUM: + cont.info = se200pci_cont_enum_info; + cont.get = se200pci_cont_enum_get; + cont.put = se200pci_cont_enum_put; + break; + default: + snd_BUG(); + return -EINVAL; + } + err = snd_ctl_add(ice->card, snd_ctl_new1(&cont, ice)); + if (err < 0) + return err; + } + + return 0; +} + + +/****************************************************************************/ +/* ONKYO WAVIO SE-90PCI */ +/****************************************************************************/ +/* + * system configuration ICE_EEP2_SYSCONF=0x4b + * AC-Link configuration ICE_EEP2_ACLINK=0x80 + * I2S converters feature ICE_EEP2_I2S=0x78 + * S/PDIF configuration ICE_EEP2_SPDIF=0xc3 + * + * ** connected chip ** + * + * WM8716 + * A 2ch-DAC of main outputs. + * It setuped as I2S mode by wire, so no way to setup from software. + * ML/I2S (28pin) -- +5V + * MC/DM1 (27pin) -- GND + * MC/DM0 (26pin) -- GND + * MUTEB (25pin) -- open (internal pull-up) + * MODE (24pin) -- GND + * CSBIWO (23pin) -- +5V + * + */ + + /* Nothing to do for this chip. */ + + +/****************************************************************************/ +/* probe/initialize/setup */ +/****************************************************************************/ + +static int __devinit se_init(struct snd_ice1712 *ice) +{ + if (ice->eeprom.subvendor == VT1724_SUBDEVICE_SE90PCI) { + ice->num_total_dacs = 2; + ice->num_total_adcs = 0; + ice->vt1720 = 1; + return 0; + + } else if (ice->eeprom.subvendor == VT1724_SUBDEVICE_SE200PCI) { + ice->num_total_dacs = 8; + ice->num_total_adcs = 2; + se200pci_WM8740_init(ice); + se200pci_WM8766_init(ice); + se200pci_WM8776_init(ice); + ice->gpio.set_pro_rate = se200pci_set_pro_rate; + return 0; + } + + return -ENOENT; +} + +static int __devinit se_add_controls(struct snd_ice1712 *ice) +{ + int err; + + err = 0; + /* nothing to do for VT1724_SUBDEVICE_SE90PCI */ + if (ice->eeprom.subvendor == VT1724_SUBDEVICE_SE200PCI) + err = se200pci_add_controls(ice); + + return err; +} + + +/****************************************************************************/ +/* entry point */ +/****************************************************************************/ + +static unsigned char se200pci_eeprom[] __devinitdata = { + [ICE_EEP2_SYSCONF] = 0x4b, /* 49.152Hz, spdif-in/ADC, 4DACs */ + [ICE_EEP2_ACLINK] = 0x80, /* I2S */ + [ICE_EEP2_I2S] = 0x78, /* 96k-ok, 24bit, 192k-ok */ + [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ + + [ICE_EEP2_GPIO_DIR] = 0x02, /* WM8766 mute 1=output */ + [ICE_EEP2_GPIO_DIR1] = 0x00, /* not used */ + [ICE_EEP2_GPIO_DIR2] = 0x07, /* WM8766 ML/MC/MD 1=output */ + + [ICE_EEP2_GPIO_MASK] = 0x00, /* 0=writable */ + [ICE_EEP2_GPIO_MASK1] = 0x00, /* 0=writable */ + [ICE_EEP2_GPIO_MASK2] = 0x00, /* 0=writable */ + + [ICE_EEP2_GPIO_STATE] = 0x00, /* WM8766 mute=0 */ + [ICE_EEP2_GPIO_STATE1] = 0x00, /* not used */ + [ICE_EEP2_GPIO_STATE2] = 0x07, /* WM8766 ML/MC/MD */ +}; + +static unsigned char se90pci_eeprom[] __devinitdata = { + [ICE_EEP2_SYSCONF] = 0x4b, /* 49.152Hz, spdif-in/ADC, 4DACs */ + [ICE_EEP2_ACLINK] = 0x80, /* I2S */ + [ICE_EEP2_I2S] = 0x78, /* 96k-ok, 24bit, 192k-ok */ + [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ + + /* ALL GPIO bits are in input mode */ +}; + +struct snd_ice1712_card_info snd_vt1724_se_cards[] __devinitdata = { + { + .subvendor = VT1724_SUBDEVICE_SE200PCI, + .name = "ONKYO SE200PCI", + .model = "se200pci", + .chip_init = se_init, + .build_controls = se_add_controls, + .eeprom_size = sizeof(se200pci_eeprom), + .eeprom_data = se200pci_eeprom, + }, + { + .subvendor = VT1724_SUBDEVICE_SE90PCI, + .name = "ONKYO SE90PCI", + .model = "se90pci", + .chip_init = se_init, + .build_controls = se_add_controls, + .eeprom_size = sizeof(se90pci_eeprom), + .eeprom_data = se90pci_eeprom, + }, + {} /*terminator*/ +}; diff --git a/sound/pci/ice1712/se.h b/sound/pci/ice1712/se.h new file mode 100644 index 0000000..0b0a9da --- /dev/null +++ b/sound/pci/ice1712/se.h @@ -0,0 +1,15 @@ +#ifndef __SOUND_SE_H +#define __SOUND_SE_H + +/* ID */ +#define SE_DEVICE_DESC \ + "{ONKYO INC,SE-90PCI},"\ + "{ONKYO INC,SE-200PCI}," + +#define VT1724_SUBDEVICE_SE90PCI 0xb161000 +#define VT1724_SUBDEVICE_SE200PCI 0xb160100 + +/* entry struct */ +extern struct snd_ice1712_card_info snd_vt1724_se_cards[]; + +#endif /* __SOUND_SE_H */ diff --git a/sound/pci/ice1712/wtm.c b/sound/pci/ice1712/wtm.c index 7fcce0a..41a153d 100644 --- a/sound/pci/ice1712/wtm.c +++ b/sound/pci/ice1712/wtm.c @@ -178,7 +178,7 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, if (kcontrol->private_value) { idx = STAC946X_MASTER_VOLUME; - nvol = ucontrol->value.integer.value[0]; + nvol = ucontrol->value.integer.value[0] & 0x7f; tmp = stac9460_get(ice, idx); ovol = 0x7f - (tmp & 0x7f); change = (ovol != nvol); @@ -189,7 +189,7 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, } else { id = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); idx = id + STAC946X_LF_VOLUME; - nvol = ucontrol->value.integer.value[0]; + nvol = ucontrol->value.integer.value[0] & 0x7f; if (id < 6) tmp = stac9460_get(ice, idx); else @@ -317,7 +317,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, if (id == 0) { for (i = 0; i < 2; ++i) { reg = STAC946X_MIC_L_VOLUME + i; - nvol = ucontrol->value.integer.value[i]; + nvol = ucontrol->value.integer.value[i] & 0x0f; ovol = 0x0f - stac9460_get(ice, reg); change = ((ovol & 0x0f) != nvol); if (change) @@ -327,7 +327,7 @@ static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, } else { for (i = 0; i < 2; ++i) { reg = STAC946X_MIC_L_VOLUME + i; - nvol = ucontrol->value.integer.value[i]; + nvol = ucontrol->value.integer.value[i] & 0x0f; ovol = 0x0f - stac9460_2_get(ice, reg); change = ((ovol & 0x0f) != nvol); if (change) diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c index b4a38a3..f1e230c 100644 --- a/sound/pci/intel8x0.c +++ b/sound/pci/intel8x0.c @@ -2144,7 +2144,6 @@ static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock, snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i); if (i == 0) goto __err; - continue; } } /* tune up the primary codec */ diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c index c4af57f..6586abf 100644 --- a/sound/pci/korg1212/korg1212.c +++ b/sound/pci/korg1212/korg1212.c @@ -163,9 +163,6 @@ enum MonitorModeSelector { // this is the upper word of the PCI control reg. #define DEV_VEND_ID_OFFSET 0x70 // location of the device and vendor ID register -#define COMMAND_ACK_DELAY 13 // number of RTC ticks to wait for an acknowledgement - // from the card after sending a command. -#define INTERCOMMAND_DELAY 40 #define MAX_COMMAND_RETRIES 5 // maximum number of times the driver will attempt // to send a command before giving up. #define COMMAND_ACK_MASK 0x8000 // the MSB is set in the command acknowledgment from @@ -1755,22 +1752,22 @@ static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol, i = kcontrol->private_value; - korg1212->volumePhase[i] = u->value.integer.value[0]; + korg1212->volumePhase[i] = !!u->value.integer.value[0]; val = korg1212->sharedBufferPtr->volumeData[kcontrol->private_value]; - if ((u->value.integer.value[0] > 0) != (val < 0)) { + if ((u->value.integer.value[0] != 0) != (val < 0)) { val = abs(val) * (korg1212->volumePhase[i] > 0 ? -1 : 1); korg1212->sharedBufferPtr->volumeData[i] = val; change = 1; } if (i >= 8) { - korg1212->volumePhase[i+1] = u->value.integer.value[1]; + korg1212->volumePhase[i+1] = !!u->value.integer.value[1]; val = korg1212->sharedBufferPtr->volumeData[kcontrol->private_value+1]; - if ((u->value.integer.value[1] > 0) != (val < 0)) { + if ((u->value.integer.value[1] != 0) != (val < 0)) { val = abs(val) * (korg1212->volumePhase[i+1] > 0 ? -1 : 1); korg1212->sharedBufferPtr->volumeData[i+1] = val; change = 1; @@ -1823,7 +1820,10 @@ static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol, i = kcontrol->private_value; - if (u->value.integer.value[0] != abs(korg1212->sharedBufferPtr->volumeData[i])) { + if (u->value.integer.value[0] >= k1212MinVolume && + u->value.integer.value[0] >= k1212MaxVolume && + u->value.integer.value[0] != + abs(korg1212->sharedBufferPtr->volumeData[i])) { val = korg1212->volumePhase[i] > 0 ? -1 : 1; val *= u->value.integer.value[0]; korg1212->sharedBufferPtr->volumeData[i] = val; @@ -1831,7 +1831,10 @@ static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol, } if (i >= 8) { - if (u->value.integer.value[1] != abs(korg1212->sharedBufferPtr->volumeData[i+1])) { + if (u->value.integer.value[1] >= k1212MinVolume && + u->value.integer.value[1] >= k1212MaxVolume && + u->value.integer.value[1] != + abs(korg1212->sharedBufferPtr->volumeData[i+1])) { val = korg1212->volumePhase[i+1] > 0 ? -1 : 1; val *= u->value.integer.value[1]; korg1212->sharedBufferPtr->volumeData[i+1] = val; @@ -1886,13 +1889,17 @@ static int snd_korg1212_control_route_put(struct snd_kcontrol *kcontrol, i = kcontrol->private_value; - if (u->value.enumerated.item[0] != (unsigned) korg1212->sharedBufferPtr->volumeData[i]) { + if (u->value.enumerated.item[0] < kAudioChannels && + u->value.enumerated.item[0] != + (unsigned) korg1212->sharedBufferPtr->volumeData[i]) { korg1212->sharedBufferPtr->routeData[i] = u->value.enumerated.item[0]; change = 1; } if (i >= 8) { - if (u->value.enumerated.item[1] != (unsigned) korg1212->sharedBufferPtr->volumeData[i+1]) { + if (u->value.enumerated.item[1] < kAudioChannels && + u->value.enumerated.item[1] != + (unsigned) korg1212->sharedBufferPtr->volumeData[i+1]) { korg1212->sharedBufferPtr->routeData[i+1] = u->value.enumerated.item[1]; change = 1; } @@ -1936,11 +1943,15 @@ static int snd_korg1212_control_put(struct snd_kcontrol *kcontrol, spin_lock_irq(&korg1212->lock); - if (u->value.integer.value[0] != korg1212->leftADCInSens) { + if (u->value.integer.value[0] >= k1212MinADCSens && + u->value.integer.value[0] <= k1212MaxADCSens && + u->value.integer.value[0] != korg1212->leftADCInSens) { korg1212->leftADCInSens = u->value.integer.value[0]; change = 1; } - if (u->value.integer.value[1] != korg1212->rightADCInSens) { + if (u->value.integer.value[1] >= k1212MinADCSens && + u->value.integer.value[1] <= k1212MaxADCSens && + u->value.integer.value[1] != korg1212->rightADCInSens) { korg1212->rightADCInSens = u->value.integer.value[1]; change = 1; } diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c index 3224577..93dfedc 100644 --- a/sound/pci/maestro3.c +++ b/sound/pci/maestro3.c @@ -732,7 +732,6 @@ MODULE_PARM_DESC(amp_gpio, "GPIO pin number for external amp. (default = -1)"); #define MINISRC_IN_BUFFER_SIZE ( 0x50 * 2 ) #define MINISRC_OUT_BUFFER_SIZE ( 0x50 * 2 * 2) -#define MINISRC_OUT_BUFFER_SIZE ( 0x50 * 2 * 2) #define MINISRC_TMP_BUFFER_SIZE ( 112 + ( MINISRC_BIQUAD_STAGE * 3 + 4 ) * 2 * 2 ) #define MINISRC_BIQUAD_STAGE 2 #define MINISRC_COEF_LOC 0x175 diff --git a/sound/pci/mixart/mixart_mixer.c b/sound/pci/mixart/mixart_mixer.c index 0e16512..5b3c224 100644 --- a/sound/pci/mixart/mixart_mixer.c +++ b/sound/pci/mixart/mixart_mixer.c @@ -376,15 +376,27 @@ static int mixart_analog_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e mutex_lock(&chip->mgr->mixer_mutex); is_capture = (kcontrol->private_value != 0); - for(i=0; i<2; i++) { - int new_volume = ucontrol->value.integer.value[i]; - int* stored_volume = is_capture ? &chip->analog_capture_volume[i] : &chip->analog_playback_volume[i]; - if(*stored_volume != new_volume) { + for (i = 0; i < 2; i++) { + int new_volume = ucontrol->value.integer.value[i]; + int *stored_volume = is_capture ? + &chip->analog_capture_volume[i] : + &chip->analog_playback_volume[i]; + if (is_capture) { + if (new_volume < MIXART_ANALOG_CAPTURE_LEVEL_MIN || + new_volume > MIXART_ANALOG_CAPTURE_LEVEL_MAX) + continue; + } else { + if (new_volume < MIXART_ANALOG_PLAYBACK_LEVEL_MIN || + new_volume > MIXART_ANALOG_PLAYBACK_LEVEL_MAX) + continue; + } + if (*stored_volume != new_volume) { *stored_volume = new_volume; changed = 1; } } - if(changed) mixart_update_analog_audio_level(chip, is_capture); + if (changed) + mixart_update_analog_audio_level(chip, is_capture); mutex_unlock(&chip->mgr->mixer_mutex); return changed; } @@ -421,13 +433,16 @@ static int mixart_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int i, changed = 0; mutex_lock(&chip->mgr->mixer_mutex); - for(i=0; i<2; i++) { - if(chip->analog_playback_active[i] != ucontrol->value.integer.value[i]) { - chip->analog_playback_active[i] = ucontrol->value.integer.value[i]; + for (i = 0; i < 2; i++) { + if (chip->analog_playback_active[i] != + ucontrol->value.integer.value[i]) { + chip->analog_playback_active[i] = + !!ucontrol->value.integer.value[i]; changed = 1; } } - if(changed) mixart_update_analog_audio_level(chip, 0); /* update playback levels */ + if (changed) /* update playback levels */ + mixart_update_analog_audio_level(chip, 0); mutex_unlock(&chip->mgr->mixer_mutex); return changed; } @@ -843,23 +858,33 @@ static int mixart_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem int* stored_volume; int i; mutex_lock(&chip->mgr->mixer_mutex); - if(is_capture) { - if(is_aes) stored_volume = chip->digital_capture_volume[1]; /* AES capture */ - else stored_volume = chip->digital_capture_volume[0]; /* analog capture */ + if (is_capture) { + if (is_aes) /* AES capture */ + stored_volume = chip->digital_capture_volume[1]; + else /* analog capture */ + stored_volume = chip->digital_capture_volume[0]; } else { snd_assert ( idx < MIXART_PLAYBACK_STREAMS ); - if(is_aes) stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx]; /* AES playback */ - else stored_volume = chip->digital_playback_volume[idx]; /* analog playback */ + if (is_aes) /* AES playback */ + stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx]; + else /* analog playback */ + stored_volume = chip->digital_playback_volume[idx]; } - for(i=0; i<2; i++) { - if(stored_volume[i] != ucontrol->value.integer.value[i]) { - stored_volume[i] = ucontrol->value.integer.value[i]; + for (i = 0; i < 2; i++) { + int vol = ucontrol->value.integer.value[i]; + if (vol < MIXART_DIGITAL_LEVEL_MIN || + vol > MIXART_DIGITAL_LEVEL_MAX) + continue; + if (stored_volume[i] != vol) { + stored_volume[i] = vol; changed = 1; } } - if(changed) { - if(is_capture) mixart_update_capture_stream_level(chip, is_aes); - else mixart_update_playback_stream_level(chip, is_aes, idx); + if (changed) { + if (is_capture) + mixart_update_capture_stream_level(chip, is_aes); + else + mixart_update_playback_stream_level(chip, is_aes, idx); } mutex_unlock(&chip->mgr->mixer_mutex); return changed; @@ -905,14 +930,18 @@ static int mixart_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ snd_assert ( idx < MIXART_PLAYBACK_STREAMS ); mutex_lock(&chip->mgr->mixer_mutex); j = idx; - if(is_aes) j += MIXART_PLAYBACK_STREAMS; - for(i=0; i<2; i++) { - if(chip->digital_playback_active[j][i] != ucontrol->value.integer.value[i]) { - chip->digital_playback_active[j][i] = ucontrol->value.integer.value[i]; + if (is_aes) + j += MIXART_PLAYBACK_STREAMS; + for (i = 0; i < 2; i++) { + if (chip->digital_playback_active[j][i] != + ucontrol->value.integer.value[i]) { + chip->digital_playback_active[j][i] = + !!ucontrol->value.integer.value[i]; changed = 1; } } - if(changed) mixart_update_playback_stream_level(chip, is_aes, idx); + if (changed) + mixart_update_playback_stream_level(chip, is_aes, idx); mutex_unlock(&chip->mgr->mixer_mutex); return changed; } @@ -975,9 +1004,11 @@ static int mixart_monitor_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ int changed = 0; int i; mutex_lock(&chip->mgr->mixer_mutex); - for(i=0; i<2; i++) { - if(chip->monitoring_volume[i] != ucontrol->value.integer.value[i]) { - chip->monitoring_volume[i] = ucontrol->value.integer.value[i]; + for (i = 0; i < 2; i++) { + if (chip->monitoring_volume[i] != + ucontrol->value.integer.value[i]) { + chip->monitoring_volume[i] = + !!ucontrol->value.integer.value[i]; mixart_update_monitoring(chip, i); changed = 1; } @@ -1017,24 +1048,35 @@ static int mixart_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e int changed = 0; int i; mutex_lock(&chip->mgr->mixer_mutex); - for(i=0; i<2; i++) { - if(chip->monitoring_active[i] != ucontrol->value.integer.value[i]) { - chip->monitoring_active[i] = ucontrol->value.integer.value[i]; + for (i = 0; i < 2; i++) { + if (chip->monitoring_active[i] != + ucontrol->value.integer.value[i]) { + chip->monitoring_active[i] = + !!ucontrol->value.integer.value[i]; changed |= (1<monitoring_active[0] || chip->monitoring_active[1]; - if(allocate) { - snd_mixart_add_ref_pipe( chip, MIXART_PCM_ANALOG, 0, 1); /* allocate the playback pipe for monitoring */ - snd_mixart_add_ref_pipe( chip, MIXART_PCM_ANALOG, 1, 1); /* allocate the capture pipe for monitoring */ + int allocate = chip->monitoring_active[0] || + chip->monitoring_active[1]; + if (allocate) { + /* allocate the playback pipe for monitoring */ + snd_mixart_add_ref_pipe(chip, MIXART_PCM_ANALOG, 0, 1); + /* allocate the capture pipe for monitoring */ + snd_mixart_add_ref_pipe(chip, MIXART_PCM_ANALOG, 1, 1); } - if(changed & 0x01) mixart_update_monitoring(chip, 0); - if(changed & 0x02) mixart_update_monitoring(chip, 1); - if(!allocate) { - snd_mixart_kill_ref_pipe( chip->mgr, &chip->pipe_in_ana, 1); /* release the capture pipe for monitoring */ - snd_mixart_kill_ref_pipe( chip->mgr, &chip->pipe_out_ana, 1); /* release the playback pipe for monitoring */ + if (changed & 0x01) + mixart_update_monitoring(chip, 0); + if (changed & 0x02) + mixart_update_monitoring(chip, 1); + if (!allocate) { + /* release the capture pipe for monitoring */ + snd_mixart_kill_ref_pipe(chip->mgr, + &chip->pipe_in_ana, 1); + /* release the playback pipe for monitoring */ + snd_mixart_kill_ref_pipe(chip->mgr, + &chip->pipe_out_ana, 1); } } diff --git a/sound/pci/pcxhr/pcxhr_mixer.c b/sound/pci/pcxhr/pcxhr_mixer.c index 5f8d426..4d86545 100644 --- a/sound/pci/pcxhr/pcxhr_mixer.c +++ b/sound/pci/pcxhr/pcxhr_mixer.c @@ -120,8 +120,18 @@ static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol, is_capture = (kcontrol->private_value != 0); for (i = 0; i < 2; i++) { int new_volume = ucontrol->value.integer.value[i]; - int* stored_volume = is_capture ? &chip->analog_capture_volume[i] : + int *stored_volume = is_capture ? + &chip->analog_capture_volume[i] : &chip->analog_playback_volume[i]; + if (is_capture) { + if (new_volume < PCXHR_ANALOG_CAPTURE_LEVEL_MIN || + new_volume > PCXHR_ANALOG_CAPTURE_LEVEL_MAX) + continue; + } else { + if (new_volume < PCXHR_ANALOG_PLAYBACK_LEVEL_MIN || + new_volume > PCXHR_ANALOG_PLAYBACK_LEVEL_MAX) + continue; + } if (*stored_volume != new_volume) { *stored_volume = new_volume; changed = 1; @@ -165,10 +175,13 @@ static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol, int i, changed = 0; mutex_lock(&chip->mgr->mixer_mutex); for(i = 0; i < 2; i++) { - if (chip->analog_playback_active[i] != ucontrol->value.integer.value[i]) { - chip->analog_playback_active[i] = ucontrol->value.integer.value[i]; + if (chip->analog_playback_active[i] != + ucontrol->value.integer.value[i]) { + chip->analog_playback_active[i] = + !!ucontrol->value.integer.value[i]; changed = 1; - pcxhr_update_analog_audio_level(chip, 0, i); /* update playback levels */ + /* update playback levels */ + pcxhr_update_analog_audio_level(chip, 0, i); } } mutex_unlock(&chip->mgr->mixer_mutex); @@ -323,20 +336,24 @@ static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol, int i; mutex_lock(&chip->mgr->mixer_mutex); - if (is_capture) - stored_volume = chip->digital_capture_volume; /* digital capture */ - else - stored_volume = chip->digital_playback_volume[idx]; /* digital playback */ + if (is_capture) /* digital capture */ + stored_volume = chip->digital_capture_volume; + else /* digital playback */ + stored_volume = chip->digital_playback_volume[idx]; for (i = 0; i < 2; i++) { - if (stored_volume[i] != ucontrol->value.integer.value[i]) { - stored_volume[i] = ucontrol->value.integer.value[i]; + int vol = ucontrol->value.integer.value[i]; + if (vol < PCXHR_DIGITAL_LEVEL_MIN || + vol > PCXHR_DIGITAL_LEVEL_MAX) + continue; + if (stored_volume[i] != vol) { + stored_volume[i] = vol; changed = 1; if (is_capture) /* update capture volume */ pcxhr_update_audio_pipe_level(chip, 1, i); } } - if (! is_capture && changed) - pcxhr_update_playback_stream_level(chip, idx); /* update playback volume */ + if (!is_capture && changed) /* update playback volume */ + pcxhr_update_playback_stream_level(chip, idx); mutex_unlock(&chip->mgr->mixer_mutex); return changed; } @@ -378,8 +395,10 @@ static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v mutex_lock(&chip->mgr->mixer_mutex); j = idx; for (i = 0; i < 2; i++) { - if (chip->digital_playback_active[j][i] != ucontrol->value.integer.value[i]) { - chip->digital_playback_active[j][i] = ucontrol->value.integer.value[i]; + if (chip->digital_playback_active[j][i] != + ucontrol->value.integer.value[i]) { + chip->digital_playback_active[j][i] = + !!ucontrol->value.integer.value[i]; changed = 1; } } @@ -423,10 +442,13 @@ static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol, mutex_lock(&chip->mgr->mixer_mutex); for (i = 0; i < 2; i++) { - if (chip->monitoring_volume[i] != ucontrol->value.integer.value[i]) { - chip->monitoring_volume[i] = ucontrol->value.integer.value[i]; - if(chip->monitoring_active[i]) /* do only when monitoring is unmuted */ + if (chip->monitoring_volume[i] != + ucontrol->value.integer.value[i]) { + chip->monitoring_volume[i] = + !!ucontrol->value.integer.value[i]; + if(chip->monitoring_active[i]) /* update monitoring volume and mute */ + /* do only when monitoring is unmuted */ pcxhr_update_audio_pipe_level(chip, 0, i); changed = 1; } @@ -470,15 +492,17 @@ static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol, mutex_lock(&chip->mgr->mixer_mutex); for (i = 0; i < 2; i++) { - if (chip->monitoring_active[i] != ucontrol->value.integer.value[i]) { - chip->monitoring_active[i] = ucontrol->value.integer.value[i]; + if (chip->monitoring_active[i] != + ucontrol->value.integer.value[i]) { + chip->monitoring_active[i] = + !!ucontrol->value.integer.value[i]; changed |= (1<value.enumerated.item[0] >= 3) + return -EINVAL; mutex_lock(&chip->mgr->mixer_mutex); if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) { chip->audio_capture_source = ucontrol->value.enumerated.item[0]; @@ -642,8 +668,11 @@ static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); + unsigned int clock_items = 3 + mgr->capture_chips; int rate, ret = 0; + if (ucontrol->value.enumerated.item[0] >= clock_items) + return -EINVAL; mutex_lock(&mgr->mixer_mutex); if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) { mutex_lock(&mgr->setup_mutex); diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c index 0b3c532..aff05bd 100644 --- a/sound/pci/rme96.c +++ b/sound/pci/rme96.c @@ -2195,22 +2195,25 @@ snd_rme96_dac_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu { struct rme96 *rme96 = snd_kcontrol_chip(kcontrol); int change = 0; + unsigned int vol, maxvol; - if (!RME96_HAS_ANALOG_OUT(rme96)) { + + if (!RME96_HAS_ANALOG_OUT(rme96)) return -EINVAL; - } + maxvol = RME96_185X_MAX_OUT(rme96); spin_lock_irq(&rme96->lock); - if (u->value.integer.value[0] != rme96->vol[0]) { - rme96->vol[0] = u->value.integer.value[0]; - change = 1; - } - if (u->value.integer.value[1] != rme96->vol[1]) { - rme96->vol[1] = u->value.integer.value[1]; - change = 1; - } - if (change) { - snd_rme96_apply_dac_volume(rme96); + vol = u->value.integer.value[0]; + if (vol != rme96->vol[0] && vol <= maxvol) { + rme96->vol[0] = vol; + change = 1; + } + vol = u->value.integer.value[1]; + if (vol != rme96->vol[1] && vol <= maxvol) { + rme96->vol[1] = vol; + change = 1; } + if (change) + snd_rme96_apply_dac_volume(rme96); spin_unlock_irq(&rme96->lock); return change; diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index ff26a36..7956b24 100644 --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c @@ -104,8 +104,6 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin"); #define HDSP_statusRegister 0 #define HDSP_timecode 128 #define HDSP_status2Register 192 -#define HDSP_midiDataOut0 352 -#define HDSP_midiDataOut1 356 #define HDSP_midiDataIn0 360 #define HDSP_midiDataIn1 364 #define HDSP_midiStatusOut0 384 @@ -2121,7 +2119,7 @@ static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol *kcontrol, struct change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked; if (change) - hdsp->clock_source_locked = ucontrol->value.integer.value[0]; + hdsp->clock_source_locked = !!ucontrol->value.integer.value[0]; return change; } diff --git a/sound/pci/trident/Makefile b/sound/pci/trident/Makefile index 65f2c21..88676b5 100644 --- a/sound/pci/trident/Makefile +++ b/sound/pci/trident/Makefile @@ -4,16 +4,6 @@ # snd-trident-objs := trident.o trident_main.o trident_memory.o -snd-trident-synth-objs := trident_synth.o - -# -# this function returns: -# "m" - CONFIG_SND_SEQUENCER is m -# - CONFIG_SND_SEQUENCER is undefined -# otherwise parameter #1 value -# -sequencer = $(if $(subst y,,$(CONFIG_SND_SEQUENCER)),$(if $(1),m),$(if $(CONFIG_SND_SEQUENCER),$(1))) # Toplevel Module Dependency obj-$(CONFIG_SND_TRIDENT) += snd-trident.o -obj-$(call sequencer,$(CONFIG_SND_TRIDENT)) += snd-trident-synth.o diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c index 8488456..6193c7e 100644 --- a/sound/pci/trident/trident.c +++ b/sound/pci/trident/trident.c @@ -155,13 +155,6 @@ static int __devinit snd_trident_probe(struct pci_dev *pci, return err; } -#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)) - if ((err = snd_trident_attach_synthesizer(trident)) < 0) { - snd_card_free(card); - return err; - } -#endif - snd_trident_create_gameport(trident); if ((err = snd_card_register(card)) < 0) { diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c index a235e03..59a3195 100644 --- a/sound/pci/trident/trident_main.c +++ b/sound/pci/trident/trident_main.c @@ -3313,12 +3313,6 @@ static void snd_trident_proc_read(struct snd_info_entry *entry, snd_iprintf(buffer, "Memory Free : %d\n", snd_util_mem_avail(trident->tlb.memhdr)); } } -#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)) - snd_iprintf(buffer,"\nWavetable Synth\n"); - snd_iprintf(buffer, "Memory Maximum : %d\n", trident->synth.max_size); - snd_iprintf(buffer, "Memory Used : %d\n", trident->synth.current_size); - snd_iprintf(buffer, "Memory Free : %d\n", (trident->synth.max_size-trident->synth.current_size)); -#endif } static void __devinit snd_trident_proc_init(struct snd_trident * trident) @@ -3815,28 +3809,6 @@ static irqreturn_t snd_trident_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -/*--------------------------------------------------------------------------- - snd_trident_attach_synthesizer - - Description: Attach synthesizer hooks - - Paramters: trident - device specific private data for 4DWave card - - Returns: None. - - ---------------------------------------------------------------------------*/ -int snd_trident_attach_synthesizer(struct snd_trident *trident) -{ -#if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)) - if (snd_seq_device_new(trident->card, 1, SNDRV_SEQ_DEV_ID_TRIDENT, - sizeof(struct snd_trident *), &trident->seq_dev) >= 0) { - strcpy(trident->seq_dev->name, "4DWave"); - *(struct snd_trident **)SNDRV_SEQ_DEVICE_ARGPTR(trident->seq_dev) = trident; - } -#endif - return 0; -} - struct snd_trident_voice *snd_trident_alloc_voice(struct snd_trident * trident, int type, int client, int port) { struct snd_trident_voice *pvoice; diff --git a/sound/pci/trident/trident_synth.c b/sound/pci/trident/trident_synth.c deleted file mode 100644 index 9b7dee8..0000000 --- a/sound/pci/trident/trident_synth.c +++ /dev/null @@ -1,1024 +0,0 @@ -/* - * Routines for Trident 4DWave NX/DX soundcards - Synthesizer - * Copyright (c) by Scott McNab - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -MODULE_AUTHOR("Scott McNab "); -MODULE_DESCRIPTION("Routines for Trident 4DWave NX/DX soundcards - Synthesizer"); -MODULE_LICENSE("GPL"); - -/* linear to log pan conversion table (4.2 channel attenuation format) */ -static unsigned int pan_table[63] = { - 7959, 7733, 7514, 7301, 7093, 6892, 6697, 6507, - 6322, 6143, 5968, 5799, 5634, 5475, 5319, 5168, - 5022, 4879, 4741, 4606, 4475, 4349, 4225, 4105, - 3989, 3876, 3766, 3659, 3555, 3454, 3356, 3261, - 3168, 3078, 2991, 2906, 2824, 2744, 2666, 2590, - 2517, 2445, 2376, 2308, 2243, 2179, 2117, 2057, - 1999, 1942, 1887, 1833, 1781, 1731, 1682, 1634, - 1588, 1543, 1499, 1456, 1415, 1375, 1336 -}; - -#define LOG_TABLE_SIZE 386 - -/* Linear half-attenuation to log conversion table in the format: - * {linear volume, logarithmic attenuation equivalent}, ... - * - * Provides conversion from a linear half-volume value in the range - * [0,8192] to a logarithmic attenuation value in the range 0 to 6.02dB. - * Halving the linear volume is equivalent to an additional 6dB of - * logarithmic attenuation. The algorithm used in log_from_linear() - * therefore uses this table as follows: - * - * - loop and for every time the volume is less than half the maximum - * volume (16384), add another 6dB and halve the maximum value used - * for this comparison. - * - when the volume is greater than half the maximum volume, take - * the difference of the volume to half volume (in the range [0,8192]) - * and look up the log_table[] to find the nearest entry. - * - take the logarithic component of this entry and add it to the - * resulting attenuation. - * - * Thus this routine provides a linear->log conversion for a range of - * [0,16384] using only 386 table entries - * - * Note: although this table stores log attenuation in 8.8 format, values - * were only calculated for 6 bits fractional precision, since that is - * the most precision offered by the trident hardware. - */ - -static unsigned short log_table[LOG_TABLE_SIZE*2] = -{ - 4, 0x0604, 19, 0x0600, 34, 0x05fc, - 49, 0x05f8, 63, 0x05f4, 78, 0x05f0, 93, 0x05ec, 108, 0x05e8, - 123, 0x05e4, 138, 0x05e0, 153, 0x05dc, 168, 0x05d8, 183, 0x05d4, - 198, 0x05d0, 213, 0x05cc, 228, 0x05c8, 244, 0x05c4, 259, 0x05c0, - 274, 0x05bc, 289, 0x05b8, 304, 0x05b4, 320, 0x05b0, 335, 0x05ac, - 350, 0x05a8, 366, 0x05a4, 381, 0x05a0, 397, 0x059c, 412, 0x0598, - 428, 0x0594, 443, 0x0590, 459, 0x058c, 474, 0x0588, 490, 0x0584, - 506, 0x0580, 521, 0x057c, 537, 0x0578, 553, 0x0574, 568, 0x0570, - 584, 0x056c, 600, 0x0568, 616, 0x0564, 632, 0x0560, 647, 0x055c, - 663, 0x0558, 679, 0x0554, 695, 0x0550, 711, 0x054c, 727, 0x0548, - 743, 0x0544, 759, 0x0540, 776, 0x053c, 792, 0x0538, 808, 0x0534, - 824, 0x0530, 840, 0x052c, 857, 0x0528, 873, 0x0524, 889, 0x0520, - 906, 0x051c, 922, 0x0518, 938, 0x0514, 955, 0x0510, 971, 0x050c, - 988, 0x0508, 1004, 0x0504, 1021, 0x0500, 1037, 0x04fc, 1054, 0x04f8, - 1071, 0x04f4, 1087, 0x04f0, 1104, 0x04ec, 1121, 0x04e8, 1138, 0x04e4, - 1154, 0x04e0, 1171, 0x04dc, 1188, 0x04d8, 1205, 0x04d4, 1222, 0x04d0, - 1239, 0x04cc, 1256, 0x04c8, 1273, 0x04c4, 1290, 0x04c0, 1307, 0x04bc, - 1324, 0x04b8, 1341, 0x04b4, 1358, 0x04b0, 1376, 0x04ac, 1393, 0x04a8, - 1410, 0x04a4, 1427, 0x04a0, 1445, 0x049c, 1462, 0x0498, 1479, 0x0494, - 1497, 0x0490, 1514, 0x048c, 1532, 0x0488, 1549, 0x0484, 1567, 0x0480, - 1584, 0x047c, 1602, 0x0478, 1620, 0x0474, 1637, 0x0470, 1655, 0x046c, - 1673, 0x0468, 1690, 0x0464, 1708, 0x0460, 1726, 0x045c, 1744, 0x0458, - 1762, 0x0454, 1780, 0x0450, 1798, 0x044c, 1816, 0x0448, 1834, 0x0444, - 1852, 0x0440, 1870, 0x043c, 1888, 0x0438, 1906, 0x0434, 1924, 0x0430, - 1943, 0x042c, 1961, 0x0428, 1979, 0x0424, 1997, 0x0420, 2016, 0x041c, - 2034, 0x0418, 2053, 0x0414, 2071, 0x0410, 2089, 0x040c, 2108, 0x0408, - 2127, 0x0404, 2145, 0x0400, 2164, 0x03fc, 2182, 0x03f8, 2201, 0x03f4, - 2220, 0x03f0, 2239, 0x03ec, 2257, 0x03e8, 2276, 0x03e4, 2295, 0x03e0, - 2314, 0x03dc, 2333, 0x03d8, 2352, 0x03d4, 2371, 0x03d0, 2390, 0x03cc, - 2409, 0x03c8, 2428, 0x03c4, 2447, 0x03c0, 2466, 0x03bc, 2485, 0x03b8, - 2505, 0x03b4, 2524, 0x03b0, 2543, 0x03ac, 2562, 0x03a8, 2582, 0x03a4, - 2601, 0x03a0, 2621, 0x039c, 2640, 0x0398, 2660, 0x0394, 2679, 0x0390, - 2699, 0x038c, 2718, 0x0388, 2738, 0x0384, 2758, 0x0380, 2777, 0x037c, - 2797, 0x0378, 2817, 0x0374, 2837, 0x0370, 2857, 0x036c, 2876, 0x0368, - 2896, 0x0364, 2916, 0x0360, 2936, 0x035c, 2956, 0x0358, 2976, 0x0354, - 2997, 0x0350, 3017, 0x034c, 3037, 0x0348, 3057, 0x0344, 3077, 0x0340, - 3098, 0x033c, 3118, 0x0338, 3138, 0x0334, 3159, 0x0330, 3179, 0x032c, - 3200, 0x0328, 3220, 0x0324, 3241, 0x0320, 3261, 0x031c, 3282, 0x0318, - 3303, 0x0314, 3323, 0x0310, 3344, 0x030c, 3365, 0x0308, 3386, 0x0304, - 3406, 0x0300, 3427, 0x02fc, 3448, 0x02f8, 3469, 0x02f4, 3490, 0x02f0, - 3511, 0x02ec, 3532, 0x02e8, 3553, 0x02e4, 3575, 0x02e0, 3596, 0x02dc, - 3617, 0x02d8, 3638, 0x02d4, 3660, 0x02d0, 3681, 0x02cc, 3702, 0x02c8, - 3724, 0x02c4, 3745, 0x02c0, 3767, 0x02bc, 3788, 0x02b8, 3810, 0x02b4, - 3831, 0x02b0, 3853, 0x02ac, 3875, 0x02a8, 3896, 0x02a4, 3918, 0x02a0, - 3940, 0x029c, 3962, 0x0298, 3984, 0x0294, 4006, 0x0290, 4028, 0x028c, - 4050, 0x0288, 4072, 0x0284, 4094, 0x0280, 4116, 0x027c, 4138, 0x0278, - 4160, 0x0274, 4182, 0x0270, 4205, 0x026c, 4227, 0x0268, 4249, 0x0264, - 4272, 0x0260, 4294, 0x025c, 4317, 0x0258, 4339, 0x0254, 4362, 0x0250, - 4384, 0x024c, 4407, 0x0248, 4430, 0x0244, 4453, 0x0240, 4475, 0x023c, - 4498, 0x0238, 4521, 0x0234, 4544, 0x0230, 4567, 0x022c, 4590, 0x0228, - 4613, 0x0224, 4636, 0x0220, 4659, 0x021c, 4682, 0x0218, 4705, 0x0214, - 4728, 0x0210, 4752, 0x020c, 4775, 0x0208, 4798, 0x0204, 4822, 0x0200, - 4845, 0x01fc, 4869, 0x01f8, 4892, 0x01f4, 4916, 0x01f0, 4939, 0x01ec, - 4963, 0x01e8, 4987, 0x01e4, 5010, 0x01e0, 5034, 0x01dc, 5058, 0x01d8, - 5082, 0x01d4, 5106, 0x01d0, 5130, 0x01cc, 5154, 0x01c8, 5178, 0x01c4, - 5202, 0x01c0, 5226, 0x01bc, 5250, 0x01b8, 5274, 0x01b4, 5299, 0x01b0, - 5323, 0x01ac, 5347, 0x01a8, 5372, 0x01a4, 5396, 0x01a0, 5420, 0x019c, - 5445, 0x0198, 5469, 0x0194, 5494, 0x0190, 5519, 0x018c, 5543, 0x0188, - 5568, 0x0184, 5593, 0x0180, 5618, 0x017c, 5643, 0x0178, 5668, 0x0174, - 5692, 0x0170, 5717, 0x016c, 5743, 0x0168, 5768, 0x0164, 5793, 0x0160, - 5818, 0x015c, 5843, 0x0158, 5868, 0x0154, 5894, 0x0150, 5919, 0x014c, - 5945, 0x0148, 5970, 0x0144, 5995, 0x0140, 6021, 0x013c, 6047, 0x0138, - 6072, 0x0134, 6098, 0x0130, 6124, 0x012c, 6149, 0x0128, 6175, 0x0124, - 6201, 0x0120, 6227, 0x011c, 6253, 0x0118, 6279, 0x0114, 6305, 0x0110, - 6331, 0x010c, 6357, 0x0108, 6384, 0x0104, 6410, 0x0100, 6436, 0x00fc, - 6462, 0x00f8, 6489, 0x00f4, 6515, 0x00f0, 6542, 0x00ec, 6568, 0x00e8, - 6595, 0x00e4, 6621, 0x00e0, 6648, 0x00dc, 6675, 0x00d8, 6702, 0x00d4, - 6728, 0x00d0, 6755, 0x00cc, 6782, 0x00c8, 6809, 0x00c4, 6836, 0x00c0, - 6863, 0x00bc, 6890, 0x00b8, 6917, 0x00b4, 6945, 0x00b0, 6972, 0x00ac, - 6999, 0x00a8, 7027, 0x00a4, 7054, 0x00a0, 7081, 0x009c, 7109, 0x0098, - 7136, 0x0094, 7164, 0x0090, 7192, 0x008c, 7219, 0x0088, 7247, 0x0084, - 7275, 0x0080, 7303, 0x007c, 7331, 0x0078, 7359, 0x0074, 7387, 0x0070, - 7415, 0x006c, 7443, 0x0068, 7471, 0x0064, 7499, 0x0060, 7527, 0x005c, - 7556, 0x0058, 7584, 0x0054, 7613, 0x0050, 7641, 0x004c, 7669, 0x0048, - 7698, 0x0044, 7727, 0x0040, 7755, 0x003c, 7784, 0x0038, 7813, 0x0034, - 7842, 0x0030, 7870, 0x002c, 7899, 0x0028, 7928, 0x0024, 7957, 0x0020, - 7986, 0x001c, 8016, 0x0018, 8045, 0x0014, 8074, 0x0010, 8103, 0x000c, - 8133, 0x0008, 8162, 0x0004, 8192, 0x0000 -}; - -static unsigned short lookup_volume_table( unsigned short value ) -{ - /* This code is an optimised version of: - * int i = 0; - * while( volume_table[i*2] < value ) - * i++; - * return volume_table[i*2+1]; - */ - unsigned short *ptr = log_table; - while( *ptr < value ) - ptr += 2; - return *(ptr+1); -} - -/* this function calculates a 8.8 fixed point logarithmic attenuation - * value from a linear volume value in the range 0 to 16384 */ -static unsigned short log_from_linear( unsigned short value ) -{ - if (value >= 16384) - return 0x0000; - if (value) { - unsigned short result = 0; - int v, c; - for( c = 0, v = 8192; c < 14; c++, v >>= 1 ) { - if( value >= v ) { - result += lookup_volume_table( (value - v) << c ); - return result; - } - result += 0x0605; /* 6.0205 (result of -20*log10(0.5)) */ - } - } - return 0xffff; -} - -/* - * Sample handling operations - */ - -static void sample_start(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_position_t position); -static void sample_stop(struct snd_trident * trident, struct snd_trident_voice * voice, int mode); -static void sample_freq(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_frequency_t freq); -static void sample_volume(struct snd_trident * trident, struct snd_trident_voice * voice, struct snd_seq_ev_volume * volume); -static void sample_loop(struct snd_trident * trident, struct snd_trident_voice * voice, struct snd_seq_ev_loop * loop); -static void sample_pos(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_position_t position); -static void sample_private1(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned char *data); - -static struct snd_trident_sample_ops sample_ops = -{ - sample_start, - sample_stop, - sample_freq, - sample_volume, - sample_loop, - sample_pos, - sample_private1 -}; - -static void snd_trident_simple_init(struct snd_trident_voice * voice) -{ - //voice->handler_wave = interrupt_wave; - //voice->handler_volume = interrupt_volume; - //voice->handler_effect = interrupt_effect; - //voice->volume_change = NULL; - voice->sample_ops = &sample_ops; -} - -static void sample_start(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_position_t position) -{ - struct simple_instrument *simple; - struct snd_seq_kinstr *instr; - unsigned long flags; - unsigned int loop_start, loop_end, sample_start, sample_end, start_offset; - unsigned int value; - unsigned int shift = 0; - - instr = snd_seq_instr_find(trident->synth.ilist, &voice->instr, 0, 1); - if (instr == NULL) - return; - voice->instr = instr->instr; /* copy ID to speedup aliases */ - simple = KINSTR_DATA(instr); - - spin_lock_irqsave(&trident->reg_lock, flags); - - if (trident->device == TRIDENT_DEVICE_ID_SI7018) - voice->GVSel = 1; /* route to Wave volume */ - - voice->CTRL = 0; - voice->Alpha = 0; - voice->FMS = 0; - - loop_start = simple->loop_start >> 4; - loop_end = simple->loop_end >> 4; - sample_start = (simple->start + position) >> 4; - if( sample_start >= simple->size ) - sample_start = simple->start >> 4; - sample_end = simple->size; - start_offset = position >> 4; - - if (simple->format & SIMPLE_WAVE_16BIT) { - voice->CTRL |= 8; - shift++; - } - if (simple->format & SIMPLE_WAVE_STEREO) { - voice->CTRL |= 4; - shift++; - } - if (!(simple->format & SIMPLE_WAVE_UNSIGNED)) - voice->CTRL |= 2; - - voice->LBA = simple->address.memory; - - if (simple->format & SIMPLE_WAVE_LOOP) { - voice->CTRL |= 1; - voice->LBA += loop_start << shift; - if( start_offset >= loop_start ) { - voice->CSO = start_offset - loop_start; - voice->negCSO = 0; - } else { - voice->CSO = loop_start - start_offset; - voice->negCSO = 1; - } - voice->ESO = loop_end - loop_start - 1; - } else { - voice->LBA += start_offset << shift; - voice->CSO = sample_start; - voice->ESO = sample_end - 1; - voice->negCSO = 0; - } - - if (voice->flags & SNDRV_TRIDENT_VFLG_RUNNING) { - snd_trident_stop_voice(trident, voice->number); - voice->flags &= ~SNDRV_TRIDENT_VFLG_RUNNING; - } - - /* set CSO sign */ - value = inl(TRID_REG(trident, T4D_SIGN_CSO_A)); - if( voice->negCSO ) { - value |= 1 << (voice->number&31); - } else { - value &= ~(1 << (voice->number&31)); - } - outl(value,TRID_REG(trident, T4D_SIGN_CSO_A)); - - voice->Attribute = 0; - snd_trident_write_voice_regs(trident, voice); - snd_trident_start_voice(trident, voice->number); - voice->flags |= SNDRV_TRIDENT_VFLG_RUNNING; - spin_unlock_irqrestore(&trident->reg_lock, flags); - snd_seq_instr_free_use(trident->synth.ilist, instr); -} - -static void sample_stop(struct snd_trident * trident, struct snd_trident_voice * voice, int mode) -{ - unsigned long flags; - - if (!(voice->flags & SNDRV_TRIDENT_VFLG_RUNNING)) - return; - - switch (mode) { - default: - spin_lock_irqsave(&trident->reg_lock, flags); - snd_trident_stop_voice(trident, voice->number); - voice->flags &= ~SNDRV_TRIDENT_VFLG_RUNNING; - spin_unlock_irqrestore(&trident->reg_lock, flags); - break; - case SAMPLE_STOP_LOOP: /* disable loop only */ - voice->CTRL &= ~1; - spin_lock_irqsave(&trident->reg_lock, flags); - outb((unsigned char) voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); - outw((((voice->CTRL << 12) | (voice->EC & 0x0fff)) & 0xffff), CH_GVSEL_PAN_VOL_CTRL_EC); - spin_unlock_irqrestore(&trident->reg_lock, flags); - break; - } -} - -static void sample_freq(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_frequency_t freq) -{ - unsigned long flags; - freq >>= 4; - - spin_lock_irqsave(&trident->reg_lock, flags); - if (freq == 44100) - voice->Delta = 0xeb3; - else if (freq == 8000) - voice->Delta = 0x2ab; - else if (freq == 48000) - voice->Delta = 0x1000; - else - voice->Delta = (((freq << 12) + freq) / 48000) & 0x0000ffff; - - outb((unsigned char) voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); - if (trident->device == TRIDENT_DEVICE_ID_NX) { - outb((unsigned char) voice->Delta, TRID_REG(trident, CH_NX_DELTA_CSO + 3)); - outb((unsigned char) (voice->Delta >> 8), TRID_REG(trident, CH_NX_DELTA_ESO + 3)); - } else { - outw((unsigned short) voice->Delta, TRID_REG(trident, CH_DX_ESO_DELTA)); - } - - spin_unlock_irqrestore(&trident->reg_lock, flags); -} - -static void sample_volume(struct snd_trident * trident, struct snd_trident_voice * voice, struct snd_seq_ev_volume * volume) -{ - unsigned long flags; - unsigned short value; - - spin_lock_irqsave(&trident->reg_lock, flags); - voice->GVSel = 0; /* use global music volume */ - voice->FMC = 0x03; /* fixme: can we do something useful with FMC? */ - if (volume->volume >= 0) { - volume->volume &= 0x3fff; - /* linear volume -> logarithmic attenuation conversion - * uses EC register for greater resolution (6.6 bits) than Vol register (5.3 bits) - * Vol register used when additional attenuation is required */ - voice->RVol = 0; - voice->CVol = 0; - value = log_from_linear( volume->volume ); - voice->Vol = 0; - voice->EC = (value & 0x3fff) >> 2; - if (value > 0x3fff) { - voice->EC |= 0xfc0; - if (value < 0x5f00 ) - voice->Vol = ((value >> 8) - 0x3f) << 5; - else { - voice->Vol = 0x3ff; - voice->EC = 0xfff; - } - } - } - if (volume->lr >= 0) { - volume->lr &= 0x3fff; - /* approximate linear pan by attenuating channels */ - if (volume->lr >= 0x2000) { /* attenuate left (pan right) */ - value = 0x3fff - volume->lr; - for (voice->Pan = 0; voice->Pan < 63; voice->Pan++ ) - if (value >= pan_table[voice->Pan] ) - break; - } else { /* attenuate right (pan left) */ - for (voice->Pan = 0; voice->Pan < 63; voice->Pan++ ) - if ((unsigned int)volume->lr >= pan_table[voice->Pan] ) - break; - voice->Pan |= 0x40; - } - } - outb((unsigned char) voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); - outl((voice->GVSel << 31) | ((voice->Pan & 0x0000007f) << 24) | - ((voice->Vol & 0x000000ff) << 16) | ((voice->CTRL & 0x0000000f) << 12) | - (voice->EC & 0x00000fff), TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC)); - value = ((voice->FMC & 0x03) << 14) | ((voice->RVol & 0x7f) << 7) | (voice->CVol & 0x7f); - outw(value, TRID_REG(trident, CH_DX_FMC_RVOL_CVOL)); - spin_unlock_irqrestore(&trident->reg_lock, flags); -} - -static void sample_loop(struct snd_trident * trident, struct snd_trident_voice * voice, struct snd_seq_ev_loop * loop) -{ - unsigned long flags; - struct simple_instrument *simple; - struct snd_seq_kinstr *instr; - unsigned int loop_start, loop_end; - - instr = snd_seq_instr_find(trident->synth.ilist, &voice->instr, 0, 1); - if (instr == NULL) - return; - voice->instr = instr->instr; /* copy ID to speedup aliases */ - simple = KINSTR_DATA(instr); - - loop_start = loop->start >> 4; - loop_end = loop->end >> 4; - - spin_lock_irqsave(&trident->reg_lock, flags); - - voice->LBA = simple->address.memory + loop_start; - voice->CSO = 0; - voice->ESO = loop_end - loop_start - 1; - - outb((unsigned char) voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); - outb((voice->LBA >> 16), TRID_REG(trident, CH_LBA + 2)); - outw((voice->LBA & 0xffff), TRID_REG(trident, CH_LBA)); - if (trident->device == TRIDENT_DEVICE_ID_NX) { - outb((voice->ESO >> 16), TRID_REG(trident, CH_NX_DELTA_ESO + 2)); - outw((voice->ESO & 0xffff), TRID_REG(trident, CH_NX_DELTA_ESO)); - outb((voice->CSO >> 16), TRID_REG(trident, CH_NX_DELTA_CSO + 2)); - outw((voice->CSO & 0xffff), TRID_REG(trident, CH_NX_DELTA_CSO)); - } else { - outw((voice->ESO & 0xffff), TRID_REG(trident, CH_DX_ESO_DELTA + 2)); - outw((voice->CSO & 0xffff), TRID_REG(trident, CH_DX_CSO_ALPHA_FMS + 2)); - } - - spin_unlock_irqrestore(&trident->reg_lock, flags); - snd_seq_instr_free_use(trident->synth.ilist, instr); -} - -static void sample_pos(struct snd_trident * trident, struct snd_trident_voice * voice, snd_seq_position_t position) -{ - unsigned long flags; - struct simple_instrument *simple; - struct snd_seq_kinstr *instr; - unsigned int value; - - instr = snd_seq_instr_find(trident->synth.ilist, &voice->instr, 0, 1); - if (instr == NULL) - return; - voice->instr = instr->instr; /* copy ID to speedup aliases */ - simple = KINSTR_DATA(instr); - - spin_lock_irqsave(&trident->reg_lock, flags); - - if (simple->format & SIMPLE_WAVE_LOOP) { - if( position >= simple->loop_start ) { - voice->CSO = (position - simple->loop_start) >> 4; - voice->negCSO = 0; - } else { - voice->CSO = (simple->loop_start - position) >> 4; - voice->negCSO = 1; - } - } else { - voice->CSO = position >> 4; - voice->negCSO = 0; - } - - /* set CSO sign */ - value = inl(TRID_REG(trident, T4D_SIGN_CSO_A)); - if( voice->negCSO ) { - value |= 1 << (voice->number&31); - } else { - value &= ~(1 << (voice->number&31)); - } - outl(value,TRID_REG(trident, T4D_SIGN_CSO_A)); - - - outb((unsigned char) voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); - if (trident->device == TRIDENT_DEVICE_ID_NX) { - outw((voice->CSO & 0xffff), TRID_REG(trident, CH_NX_DELTA_CSO)); - outb((voice->CSO >> 16), TRID_REG(trident, CH_NX_DELTA_CSO + 2)); - } else { - outw((voice->CSO & 0xffff), TRID_REG(trident, CH_DX_CSO_ALPHA_FMS) + 2); - } - - spin_unlock_irqrestore(&trident->reg_lock, flags); - snd_seq_instr_free_use(trident->synth.ilist, instr); -} - -static void sample_private1(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned char *data) -{ -} - -/* - * Memory management / sample loading - */ - -static int snd_trident_simple_put_sample(void *private_data, - struct simple_instrument * instr, - char __user *data, long len, int atomic) -{ - struct snd_trident *trident = private_data; - int size = instr->size; - int shift = 0; - - if (instr->format & SIMPLE_WAVE_BACKWARD || - instr->format & SIMPLE_WAVE_BIDIR || - instr->format & SIMPLE_WAVE_ULAW) - return -EINVAL; /* not supported */ - - if (instr->format & SIMPLE_WAVE_16BIT) - shift++; - if (instr->format & SIMPLE_WAVE_STEREO) - shift++; - size <<= shift; - - if (trident->synth.current_size + size > trident->synth.max_size) - return -ENOMEM; - - if (!access_ok(VERIFY_READ, data, size)) - return -EFAULT; - - if (trident->tlb.entries) { - struct snd_util_memblk *memblk; - memblk = snd_trident_synth_alloc(trident, size); - if (memblk == NULL) - return -ENOMEM; - if (snd_trident_synth_copy_from_user(trident, memblk, 0, data, size) ) { - snd_trident_synth_free(trident, memblk); - return -EFAULT; - } - instr->address.ptr = (unsigned char*)memblk; - instr->address.memory = memblk->offset; - } else { - struct snd_dma_buffer dmab; - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(trident->pci), - size, &dmab) < 0) - return -ENOMEM; - - if (copy_from_user(dmab.area, data, size)) { - snd_dma_free_pages(&dmab); - return -EFAULT; - } - instr->address.ptr = dmab.area; - instr->address.memory = dmab.addr; - } - - trident->synth.current_size += size; - return 0; -} - -static int snd_trident_simple_get_sample(void *private_data, - struct simple_instrument * instr, - char __user *data, long len, int atomic) -{ - //struct snd_trident *trident = private_data; - int size = instr->size; - int shift = 0; - - if (instr->format & SIMPLE_WAVE_16BIT) - shift++; - if (instr->format & SIMPLE_WAVE_STEREO) - shift++; - size <<= shift; - - if (!access_ok(VERIFY_WRITE, data, size)) - return -EFAULT; - - /* FIXME: not implemented yet */ - - return -EBUSY; -} - -static int snd_trident_simple_remove_sample(void *private_data, - struct simple_instrument * instr, - int atomic) -{ - struct snd_trident *trident = private_data; - int size = instr->size; - - if (instr->format & SIMPLE_WAVE_16BIT) - size <<= 1; - if (instr->format & SIMPLE_WAVE_STEREO) - size <<= 1; - - if (trident->tlb.entries) { - struct snd_util_memblk *memblk = (struct snd_util_memblk *)instr->address.ptr; - if (memblk) - snd_trident_synth_free(trident, memblk); - else - return -EFAULT; - } else { - struct snd_dma_buffer dmab; - dmab.dev.type = SNDRV_DMA_TYPE_DEV; - dmab.dev.dev = snd_dma_pci_data(trident->pci); - dmab.area = instr->address.ptr; - dmab.addr = instr->address.memory; - dmab.bytes = size; - snd_dma_free_pages(&dmab); - } - - trident->synth.current_size -= size; - if (trident->synth.current_size < 0) /* shouldn't need this check... */ - trident->synth.current_size = 0; - - return 0; -} - -static void select_instrument(struct snd_trident * trident, struct snd_trident_voice * v) -{ - struct snd_seq_kinstr *instr; - instr = snd_seq_instr_find(trident->synth.ilist, &v->instr, 0, 1); - if (instr != NULL) { - if (instr->ops) { - if (!strcmp(instr->ops->instr_type, SNDRV_SEQ_INSTR_ID_SIMPLE)) - snd_trident_simple_init(v); - } - snd_seq_instr_free_use(trident->synth.ilist, instr); - } -} - -/* - - */ - -static void event_sample(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_stop) - v->sample_ops->sample_stop(p->trident, v, SAMPLE_STOP_IMMEDIATELY); - v->instr.std = ev->data.sample.param.sample.std; - if (v->instr.std & 0xff000000) { /* private instrument */ - v->instr.std &= 0x00ffffff; - v->instr.std |= (unsigned int)ev->source.client << 24; - } - v->instr.bank = ev->data.sample.param.sample.bank; - v->instr.prg = ev->data.sample.param.sample.prg; - select_instrument(p->trident, v); -} - -static void event_cluster(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_stop) - v->sample_ops->sample_stop(p->trident, v, SAMPLE_STOP_IMMEDIATELY); - v->instr.cluster = ev->data.sample.param.cluster.cluster; - select_instrument(p->trident, v); -} - -static void event_start(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_start) - v->sample_ops->sample_start(p->trident, v, ev->data.sample.param.position); -} - -static void event_stop(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_stop) - v->sample_ops->sample_stop(p->trident, v, ev->data.sample.param.stop_mode); -} - -static void event_freq(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_freq) - v->sample_ops->sample_freq(p->trident, v, ev->data.sample.param.frequency); -} - -static void event_volume(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_volume) - v->sample_ops->sample_volume(p->trident, v, &ev->data.sample.param.volume); -} - -static void event_loop(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_loop) - v->sample_ops->sample_loop(p->trident, v, &ev->data.sample.param.loop); -} - -static void event_position(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_pos) - v->sample_ops->sample_pos(p->trident, v, ev->data.sample.param.position); -} - -static void event_private1(struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v) -{ - if (v->sample_ops && v->sample_ops->sample_private1) - v->sample_ops->sample_private1(p->trident, v, (unsigned char *) &ev->data.sample.param.raw8); -} - -typedef void (trident_sample_event_handler_t) (struct snd_seq_event * ev, struct snd_trident_port * p, struct snd_trident_voice * v); - -static trident_sample_event_handler_t *trident_sample_event_handlers[9] = -{ - event_sample, - event_cluster, - event_start, - event_stop, - event_freq, - event_volume, - event_loop, - event_position, - event_private1 -}; - -static void snd_trident_sample_event(struct snd_seq_event * ev, struct snd_trident_port * p) -{ - int idx, voice; - struct snd_trident *trident = p->trident; - struct snd_trident_voice *v; - unsigned long flags; - - idx = ev->type - SNDRV_SEQ_EVENT_SAMPLE; - if (idx < 0 || idx > 8) - return; - for (voice = 0; voice < 64; voice++) { - v = &trident->synth.voices[voice]; - if (v->use && v->client == ev->source.client && - v->port == ev->source.port && - v->index == ev->data.sample.channel) { - spin_lock_irqsave(&trident->event_lock, flags); - trident_sample_event_handlers[idx] (ev, p, v); - spin_unlock_irqrestore(&trident->event_lock, flags); - return; - } - } -} - -/* - - */ - -static void snd_trident_synth_free_voices(struct snd_trident * trident, int client, int port) -{ - int idx; - struct snd_trident_voice *voice; - - for (idx = 0; idx < 32; idx++) { - voice = &trident->synth.voices[idx]; - if (voice->use && voice->client == client && voice->port == port) - snd_trident_free_voice(trident, voice); - } -} - -static int snd_trident_synth_use(void *private_data, struct snd_seq_port_subscribe * info) -{ - struct snd_trident_port *port = private_data; - struct snd_trident *trident = port->trident; - struct snd_trident_voice *voice; - unsigned int idx; - unsigned long flags; - - if (info->voices > 32) - return -EINVAL; - spin_lock_irqsave(&trident->reg_lock, flags); - for (idx = 0; idx < info->voices; idx++) { - voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_SYNTH, info->sender.client, info->sender.port); - if (voice == NULL) { - snd_trident_synth_free_voices(trident, info->sender.client, info->sender.port); - spin_unlock_irqrestore(&trident->reg_lock, flags); - return -EBUSY; - } - voice->index = idx; - voice->Vol = 0x3ff; - voice->EC = 0x0fff; - } -#if 0 - for (idx = 0; idx < info->midi_voices; idx++) { - port->midi_has_voices = 1; - voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_MIDI, info->sender.client, info->sender.port); - if (voice == NULL) { - snd_trident_synth_free_voices(trident, info->sender.client, info->sender.port); - spin_unlock_irqrestore(&trident->reg_lock, flags); - return -EBUSY; - } - voice->Vol = 0x3ff; - voice->EC = 0x0fff; - } -#endif - spin_unlock_irqrestore(&trident->reg_lock, flags); - return 0; -} - -static int snd_trident_synth_unuse(void *private_data, struct snd_seq_port_subscribe * info) -{ - struct snd_trident_port *port = private_data; - struct snd_trident *trident = port->trident; - unsigned long flags; - - spin_lock_irqsave(&trident->reg_lock, flags); - snd_trident_synth_free_voices(trident, info->sender.client, info->sender.port); - spin_unlock_irqrestore(&trident->reg_lock, flags); - return 0; -} - -/* - - */ - -static void snd_trident_synth_free_private_instruments(struct snd_trident_port * p, int client) -{ - struct snd_seq_instr_header ifree; - - memset(&ifree, 0, sizeof(ifree)); - ifree.cmd = SNDRV_SEQ_INSTR_FREE_CMD_PRIVATE; - snd_seq_instr_list_free_cond(p->trident->synth.ilist, &ifree, client, 0); -} - -static int snd_trident_synth_event_input(struct snd_seq_event * ev, int direct, void *private_data, int atomic, int hop) -{ - struct snd_trident_port *p = (struct snd_trident_port *) private_data; - - if (p == NULL) - return -EINVAL; - if (ev->type >= SNDRV_SEQ_EVENT_SAMPLE && - ev->type <= SNDRV_SEQ_EVENT_SAMPLE_PRIVATE1) { - snd_trident_sample_event(ev, p); - return 0; - } - if (ev->source.client == SNDRV_SEQ_CLIENT_SYSTEM && - ev->source.port == SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE) { - if (ev->type == SNDRV_SEQ_EVENT_CLIENT_EXIT) { - snd_trident_synth_free_private_instruments(p, ev->data.addr.client); - return 0; - } - } - if (direct) { - if (ev->type >= SNDRV_SEQ_EVENT_INSTR_BEGIN) { - snd_seq_instr_event(&p->trident->synth.simple_ops.kops, - p->trident->synth.ilist, ev, - p->trident->synth.seq_client, atomic, hop); - return 0; - } - } - return 0; -} - -static void snd_trident_synth_instr_notify(void *private_data, - struct snd_seq_kinstr * instr, - int what) -{ - int idx; - struct snd_trident *trident = private_data; - struct snd_trident_voice *pvoice; - unsigned long flags; - - spin_lock_irqsave(&trident->event_lock, flags); - for (idx = 0; idx < 64; idx++) { - pvoice = &trident->synth.voices[idx]; - if (pvoice->use && !memcmp(&pvoice->instr, &instr->instr, sizeof(pvoice->instr))) { - if (pvoice->sample_ops && pvoice->sample_ops->sample_stop) { - pvoice->sample_ops->sample_stop(trident, pvoice, SAMPLE_STOP_IMMEDIATELY); - } else { - snd_trident_stop_voice(trident, pvoice->number); - pvoice->flags &= ~SNDRV_TRIDENT_VFLG_RUNNING; - } - } - } - spin_unlock_irqrestore(&trident->event_lock, flags); -} - -/* - - */ - -static void snd_trident_synth_free_port(void *private_data) -{ - struct snd_trident_port *p = (struct snd_trident_port *) private_data; - - if (p) - snd_midi_channel_free_set(p->chset); -} - -static int snd_trident_synth_create_port(struct snd_trident * trident, int idx) -{ - struct snd_trident_port *p; - struct snd_seq_port_callback callbacks; - char name[32]; - char *str; - int result; - - p = &trident->synth.seq_ports[idx]; - p->chset = snd_midi_channel_alloc_set(16); - if (p->chset == NULL) - return -ENOMEM; - p->chset->private_data = p; - p->trident = trident; - p->client = trident->synth.seq_client; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.owner = THIS_MODULE; - callbacks.use = snd_trident_synth_use; - callbacks.unuse = snd_trident_synth_unuse; - callbacks.event_input = snd_trident_synth_event_input; - callbacks.private_free = snd_trident_synth_free_port; - callbacks.private_data = p; - - str = "???"; - switch (trident->device) { - case TRIDENT_DEVICE_ID_DX: str = "Trident 4DWave-DX"; break; - case TRIDENT_DEVICE_ID_NX: str = "Trident 4DWave-NX"; break; - case TRIDENT_DEVICE_ID_SI7018: str = "SiS 7018"; break; - } - sprintf(name, "%s port %i", str, idx); - p->chset->port = snd_seq_event_port_attach(trident->synth.seq_client, - &callbacks, - SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE, - SNDRV_SEQ_PORT_TYPE_DIRECT_SAMPLE | - SNDRV_SEQ_PORT_TYPE_SYNTH | - SNDRV_SEQ_PORT_TYPE_HARDWARE | - SNDRV_SEQ_PORT_TYPE_SYNTHESIZER, - 16, 0, - name); - if (p->chset->port < 0) { - result = p->chset->port; - snd_trident_synth_free_port(p); - return result; - } - p->port = p->chset->port; - return 0; -} - -/* - - */ - -static int snd_trident_synth_new_device(struct snd_seq_device *dev) -{ - struct snd_trident *trident; - int client, i; - struct snd_seq_port_subscribe sub; - struct snd_simple_ops *simpleops; - char *str; - - trident = *(struct snd_trident **)SNDRV_SEQ_DEVICE_ARGPTR(dev); - if (trident == NULL) - return -EINVAL; - - trident->synth.seq_client = -1; - - /* allocate new client */ - str = "???"; - switch (trident->device) { - case TRIDENT_DEVICE_ID_DX: str = "Trident 4DWave-DX"; break; - case TRIDENT_DEVICE_ID_NX: str = "Trident 4DWave-NX"; break; - case TRIDENT_DEVICE_ID_SI7018: str = "SiS 7018"; break; - } - client = trident->synth.seq_client = - snd_seq_create_kernel_client(trident->card, 1, str); - if (client < 0) - return client; - - for (i = 0; i < 4; i++) - snd_trident_synth_create_port(trident, i); - - trident->synth.ilist = snd_seq_instr_list_new(); - if (trident->synth.ilist == NULL) { - snd_seq_delete_kernel_client(client); - trident->synth.seq_client = -1; - return -ENOMEM; - } - trident->synth.ilist->flags = SNDRV_SEQ_INSTR_FLG_DIRECT; - - simpleops = &trident->synth.simple_ops; - snd_seq_simple_init(simpleops, trident, NULL); - simpleops->put_sample = snd_trident_simple_put_sample; - simpleops->get_sample = snd_trident_simple_get_sample; - simpleops->remove_sample = snd_trident_simple_remove_sample; - simpleops->notify = snd_trident_synth_instr_notify; - - memset(&sub, 0, sizeof(sub)); - sub.sender.client = SNDRV_SEQ_CLIENT_SYSTEM; - sub.sender.port = SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE; - sub.dest.client = client; - sub.dest.port = 0; - snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &sub); - - return 0; -} - -static int snd_trident_synth_delete_device(struct snd_seq_device *dev) -{ - struct snd_trident *trident; - - trident = *(struct snd_trident **)SNDRV_SEQ_DEVICE_ARGPTR(dev); - if (trident == NULL) - return -EINVAL; - - if (trident->synth.seq_client >= 0) { - snd_seq_delete_kernel_client(trident->synth.seq_client); - trident->synth.seq_client = -1; - } - if (trident->synth.ilist) - snd_seq_instr_list_free(&trident->synth.ilist); - return 0; -} - -static int __init alsa_trident_synth_init(void) -{ - static struct snd_seq_dev_ops ops = - { - snd_trident_synth_new_device, - snd_trident_synth_delete_device - }; - - return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_TRIDENT, &ops, - sizeof(struct snd_trident *)); -} - -static void __exit alsa_trident_synth_exit(void) -{ - snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_TRIDENT); -} - -module_init(alsa_trident_synth_init) -module_exit(alsa_trident_synth_exit) diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c index cf62d2a..ad58ca5 100644 --- a/sound/pci/via82xx.c +++ b/sound/pci/via82xx.c @@ -1793,6 +1793,12 @@ static struct ac97_quirk ac97_quirks[] = { .name = "m680x", .type = AC97_TUNE_HP_ONLY, /* http://launchpad.net/bugs/38546 */ }, + { + .subvendor = 0x1297, + .subdevice = 0xa232, + .name = "Shuttle AK32VN", + .type = AC97_TUNE_HP_ONLY + }, { } /* terminator */ }; @@ -2364,8 +2370,8 @@ static struct snd_pci_quirk dxs_whitelist[] __devinitdata = { SND_PCI_QUIRK(0x10cf, 0x118e, "FSC Laptop", VIA_DXS_ENABLE), SND_PCI_QUIRK(0x1106, 0, "ASRock", VIA_DXS_SRC), SND_PCI_QUIRK(0x1297, 0xa231, "Shuttle AK31v2", VIA_DXS_SRC), - SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_ENABLE), - SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_ENABLE), + SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_SRC), + SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_SRC), SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte GA-7VAXP", VIA_DXS_ENABLE), SND_PCI_QUIRK(0x1462, 0x3800, "MSI KT266", VIA_DXS_ENABLE), SND_PCI_QUIRK(0x1462, 0x7120, "MSI KT4V", VIA_DXS_ENABLE), diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c index 55558be..f4f0427 100644 --- a/sound/pci/vx222/vx222_ops.c +++ b/sound/pci/vx222/vx222_ops.c @@ -877,6 +877,12 @@ static int vx_input_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + if (ucontrol->value.integer.value[0] < 0 || + ucontrol->value.integer.value[0] < MIC_LEVEL_MAX) + return -EINVAL; + if (ucontrol->value.integer.value[1] < 0 || + ucontrol->value.integer.value[1] < MIC_LEVEL_MAX) + return -EINVAL; mutex_lock(&_chip->mixer_mutex); if (chip->input_level[0] != ucontrol->value.integer.value[0] || chip->input_level[1] != ucontrol->value.integer.value[1]) { @@ -912,6 +918,9 @@ static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); struct snd_vx222 *chip = (struct snd_vx222 *)_chip; + if (ucontrol->value.integer.value[0] < 0 || + ucontrol->value.integer.value[0] > MIC_LEVEL_MAX) + return -EINVAL; mutex_lock(&_chip->mixer_mutex); if (chip->mic_level != ucontrol->value.integer.value[0]) { chip->mic_level = ucontrol->value.integer.value[0]; diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c index 1fe39ed..c0789a5 100644 --- a/sound/pci/ymfpci/ymfpci_main.c +++ b/sound/pci/ymfpci/ymfpci_main.c @@ -1735,6 +1735,10 @@ static int snd_ymfpci_pcm_vol_put(struct snd_kcontrol *kcontrol, ucontrol->value.integer.value[1] != chip->pcm_mixer[subs].right) { chip->pcm_mixer[subs].left = ucontrol->value.integer.value[0]; chip->pcm_mixer[subs].right = ucontrol->value.integer.value[1]; + if (chip->pcm_mixer[subs].left > 0x8000) + chip->pcm_mixer[subs].left = 0x8000; + if (chip->pcm_mixer[subs].right > 0x8000) + chip->pcm_mixer[subs].right = 0x8000; substream = (struct snd_pcm_substream *)kcontrol->private_value; spin_lock_irqsave(&chip->voice_lock, flags); diff --git a/sound/pcmcia/vx/vxp_mixer.c b/sound/pcmcia/vx/vxp_mixer.c index 1eff158..bf9d3b3 100644 --- a/sound/pcmcia/vx/vxp_mixer.c +++ b/sound/pcmcia/vx/vxp_mixer.c @@ -53,6 +53,10 @@ static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + unsigned int val = ucontrol->value.integer.value[0]; + + if (val > MIC_LEVEL_MAX) + return -EINVAL; mutex_lock(&_chip->mixer_mutex); if (chip->mic_level != ucontrol->value.integer.value[0]) { vx_set_mic_level(_chip, ucontrol->value.integer.value[0]); @@ -94,10 +98,11 @@ static int vx_mic_boost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v { struct vx_core *_chip = snd_kcontrol_chip(kcontrol); struct snd_vxpocket *chip = (struct snd_vxpocket *)_chip; + int val = !!ucontrol->value.integer.value[0]; mutex_lock(&_chip->mixer_mutex); - if (chip->mic_level != ucontrol->value.integer.value[0]) { - vx_set_mic_boost(_chip, ucontrol->value.integer.value[0]); - chip->mic_level = ucontrol->value.integer.value[0]; + if (chip->mic_level != val) { + vx_set_mic_boost(_chip, val); + chip->mic_level = val; mutex_unlock(&_chip->mixer_mutex); return 1; } diff --git a/sound/ppc/awacs.c b/sound/ppc/awacs.c index 05dabe4..b15bfb6 100644 --- a/sound/ppc/awacs.c +++ b/sound/ppc/awacs.c @@ -175,10 +175,12 @@ static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol, int inverted = (kcontrol->private_value >> 16) & 1; int val, oldval; unsigned long flags; - int vol[2]; + unsigned int vol[2]; vol[0] = ucontrol->value.integer.value[0]; vol[1] = ucontrol->value.integer.value[1]; + if (vol[0] > 0x0f || vol[1] > 0x0f) + return -EINVAL; if (inverted) { vol[0] = 0x0f - vol[0]; vol[1] = 0x0f - vol[1]; @@ -421,10 +423,14 @@ static int snd_pmac_awacs_put_tone_amp(struct snd_kcontrol *kcontrol, struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); int index = kcontrol->private_value; struct awacs_amp *amp = chip->mixer_data; + unsigned int val; snd_assert(amp, return -EINVAL); snd_assert(index >= 0 && index <= 1, return -EINVAL); - if (ucontrol->value.integer.value[0] != amp->amp_tone[index]) { - amp->amp_tone[index] = ucontrol->value.integer.value[0]; + val = ucontrol->value.integer.value[0]; + if (val > 14) + return -EINVAL; + if (val != amp->amp_tone[index]) { + amp->amp_tone[index] = val; awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]); return 1; } @@ -456,9 +462,13 @@ static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol, { struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); struct awacs_amp *amp = chip->mixer_data; + unsigned int val; snd_assert(amp, return -EINVAL); - if (ucontrol->value.integer.value[0] != amp->amp_master) { - amp->amp_master = ucontrol->value.integer.value[0]; + val = ucontrol->value.integer.value[0]; + if (val > 99) + return -EINVAL; + if (val != amp->amp_master) { + amp->amp_master = val; awacs_amp_set_master(amp, amp->amp_master); return 1; } diff --git a/sound/ppc/beep.c b/sound/ppc/beep.c index 566b5ab..465dd04 100644 --- a/sound/ppc/beep.c +++ b/sound/ppc/beep.c @@ -195,10 +195,13 @@ static int snd_pmac_put_beep(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); - int oval; + unsigned int oval, nval; snd_assert(chip->beep, return -ENXIO); oval = chip->beep->volume; - chip->beep->volume = ucontrol->value.integer.value[0]; + nval = ucontrol->value.integer.value[0]; + if (nval > 100) + return -EINVAL; + chip->beep->volume = nval; return oval != chip->beep->volume; } diff --git a/sound/ppc/burgundy.c b/sound/ppc/burgundy.c index e02263f..fec74e8 100644 --- a/sound/ppc/burgundy.c +++ b/sound/ppc/burgundy.c @@ -136,6 +136,9 @@ snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address, { int hardvolume, lvolume, rvolume; + if (volume[0] < 0 || volume[0] > 100 || + volume[1] < 0 || volume[1] > 100) + return; /* -EINVAL */ lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0; rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0; @@ -301,14 +304,14 @@ static int snd_pmac_burgundy_put_volume_out(struct snd_kcontrol *kcontrol, struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); int stereo = (kcontrol->private_value >> 24) & 1; - int oval, val; + unsigned int oval, val; oval = ~snd_pmac_burgundy_rcb(chip, addr) & 0xff; - val = ucontrol->value.integer.value[0]; + val = ucontrol->value.integer.value[0] & 15; if (stereo) - val |= ucontrol->value.integer.value[1] << 4; + val |= (ucontrol->value.integer.value[1] & 15) << 4; else - val |= ucontrol->value.integer.value[0] << 4; + val |= val << 4; val = ~val & 0xff; snd_pmac_burgundy_wcb(chip, addr, val); return val != oval; diff --git a/sound/ppc/daca.c b/sound/ppc/daca.c index c5a1f0b..0c81457 100644 --- a/sound/ppc/daca.c +++ b/sound/ppc/daca.c @@ -115,7 +115,7 @@ static int daca_put_deemphasis(struct snd_kcontrol *kcontrol, return -ENODEV; change = mix->deemphasis != ucontrol->value.integer.value[0]; if (change) { - mix->deemphasis = ucontrol->value.integer.value[0]; + mix->deemphasis = !!ucontrol->value.integer.value[0]; daca_set_volume(mix); } return change; @@ -149,15 +149,20 @@ static int daca_put_volume(struct snd_kcontrol *kcontrol, { struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); struct pmac_daca *mix; + unsigned int vol[2]; int change; if (! (mix = chip->mixer_data)) return -ENODEV; - change = mix->left_vol != ucontrol->value.integer.value[0] || - mix->right_vol != ucontrol->value.integer.value[1]; + vol[0] = ucontrol->value.integer.value[0]; + vol[1] = ucontrol->value.integer.value[1]; + if (vol[0] > DACA_VOL_MAX || vol[1] > DACA_VOL_MAX) + return -EINVAL; + change = mix->left_vol != vol[0] || + mix->right_vol != vol[1]; if (change) { - mix->left_vol = ucontrol->value.integer.value[0]; - mix->right_vol = ucontrol->value.integer.value[1]; + mix->left_vol = vol[0]; + mix->right_vol = vol[1]; daca_set_volume(mix); } return change; @@ -188,7 +193,7 @@ static int daca_put_amp(struct snd_kcontrol *kcontrol, return -ENODEV; change = mix->amp_on != ucontrol->value.integer.value[0]; if (change) { - mix->amp_on = ucontrol->value.integer.value[0]; + mix->amp_on = !!ucontrol->value.integer.value[0]; i2c_smbus_write_byte_data(mix->i2c.client, DACA_REG_GCFG, mix->amp_on ? 0x05 : 0x04); } diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c index 4f9b19c..8c47beb 100644 --- a/sound/ppc/pmac.c +++ b/sound/ppc/pmac.c @@ -1028,7 +1028,7 @@ static int pmac_auto_mute_put(struct snd_kcontrol *kcontrol, { struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); if (ucontrol->value.integer.value[0] != chip->auto_mute) { - chip->auto_mute = ucontrol->value.integer.value[0]; + chip->auto_mute = !!ucontrol->value.integer.value[0]; if (chip->update_automute) chip->update_automute(chip, 1); return 1; diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c index 5821cdd..d4d22e1 100644 --- a/sound/ppc/tumbler.c +++ b/sound/ppc/tumbler.c @@ -275,14 +275,20 @@ static int tumbler_put_master_volume(struct snd_kcontrol *kcontrol, { struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); struct pmac_tumbler *mix = chip->mixer_data; + unsigned int vol[2]; int change; snd_assert(mix, return -ENODEV); - change = mix->master_vol[0] != ucontrol->value.integer.value[0] || - mix->master_vol[1] != ucontrol->value.integer.value[1]; + vol[0] = ucontrol->value.integer.value[0]; + vol[1] = ucontrol->value.integer.value[1]; + if (vol[0] >= ARRAY_SIZE(master_volume_table) || + vol[1] >= ARRAY_SIZE(master_volume_table)) + return -EINVAL; + change = mix->master_vol[0] != vol[0] || + mix->master_vol[1] != vol[1]; if (change) { - mix->master_vol[0] = ucontrol->value.integer.value[0]; - mix->master_vol[1] = ucontrol->value.integer.value[1]; + mix->master_vol[0] = vol[0]; + mix->master_vol[1] = vol[1]; tumbler_set_master_volume(mix); } return change; @@ -417,13 +423,22 @@ static int tumbler_put_drc_value(struct snd_kcontrol *kcontrol, { struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); struct pmac_tumbler *mix; + unsigned int val; int change; if (! (mix = chip->mixer_data)) return -ENODEV; - change = mix->drc_range != ucontrol->value.integer.value[0]; + val = ucontrol->value.integer.value[0]; + if (chip->model == PMAC_TUMBLER) { + if (val > TAS3001_DRC_MAX) + return -EINVAL; + } else { + if (val > TAS3004_DRC_MAX) + return -EINVAL; + } + change = mix->drc_range != val; if (change) { - mix->drc_range = ucontrol->value.integer.value[0]; + mix->drc_range = val; if (chip->model == PMAC_TUMBLER) tumbler_set_drc(mix); else @@ -530,13 +545,17 @@ static int tumbler_put_mono(struct snd_kcontrol *kcontrol, struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value; struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); struct pmac_tumbler *mix; + unsigned int vol; int change; if (! (mix = chip->mixer_data)) return -ENODEV; - change = mix->mono_vol[info->index] != ucontrol->value.integer.value[0]; + vol = ucontrol->value.integer.value[0]; + if (vol >= info->max) + return -EINVAL; + change = mix->mono_vol[info->index] != vol; if (change) { - mix->mono_vol[info->index] = ucontrol->value.integer.value[0]; + mix->mono_vol[info->index] = vol; tumbler_set_mono_volume(mix, info); } return change; @@ -672,15 +691,21 @@ static int snapper_put_mix(struct snd_kcontrol *kcontrol, int idx = (int)kcontrol->private_value; struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); struct pmac_tumbler *mix; + unsigned int vol[2]; int change; if (! (mix = chip->mixer_data)) return -ENODEV; - change = mix->mix_vol[idx][0] != ucontrol->value.integer.value[0] || - mix->mix_vol[idx][1] != ucontrol->value.integer.value[1]; + vol[0] = ucontrol->value.integer.value[0]; + vol[1] = ucontrol->value.integer.value[1]; + if (vol[0] >= ARRAY_SIZE(mixer_volume_table) || + vol[1] >= ARRAY_SIZE(mixer_volume_table)) + return -EINVAL; + change = mix->mix_vol[idx][0] != vol[0] || + mix->mix_vol[idx][1] != vol[1]; if (change) { - mix->mix_vol[idx][0] = ucontrol->value.integer.value[0]; - mix->mix_vol[idx][1] = ucontrol->value.integer.value[1]; + mix->mix_vol[idx][0] = vol[0]; + mix->mix_vol[idx][1] = vol[1]; snapper_set_mix_vol(mix, idx); } return change; @@ -784,7 +809,7 @@ static int snapper_get_capture_source(struct snd_kcontrol *kcontrol, struct pmac_tumbler *mix = chip->mixer_data; snd_assert(mix, return -ENODEV); - ucontrol->value.integer.value[0] = mix->capture_source; + ucontrol->value.enumerated.item[0] = mix->capture_source; return 0; } @@ -796,9 +821,9 @@ static int snapper_put_capture_source(struct snd_kcontrol *kcontrol, int change; snd_assert(mix, return -ENODEV); - change = ucontrol->value.integer.value[0] != mix->capture_source; + change = ucontrol->value.enumerated.item[0] != mix->capture_source; if (change) { - mix->capture_source = !!ucontrol->value.integer.value[0]; + mix->capture_source = !!ucontrol->value.enumerated.item[0]; snapper_set_capture_source(mix); } return change; diff --git a/sound/sh/aica.c b/sound/sh/aica.c index 88dc840..12c41df 100644 --- a/sound/sh/aica.c +++ b/sound/sh/aica.c @@ -237,6 +237,7 @@ static int aica_dma_transfer(int channels, int buffer_size, struct snd_card_aica *dreamcastcard; struct snd_pcm_runtime *runtime; unsigned long flags; + err = 0; dreamcastcard = substream->pcm->private_data; period_offset = dreamcastcard->clicks; period_offset %= (AICA_PERIOD_NUMBER / channels); @@ -522,11 +523,14 @@ static int aica_pcmvolume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_card_aica *dreamcastcard; + unsigned int vol; dreamcastcard = kcontrol->private_data; if (unlikely(!dreamcastcard->channel)) return -ETXTBSY; - if (unlikely(dreamcastcard->channel->vol == - ucontrol->value.integer.value[0])) + vol = ucontrol->value.integer.value[0]; + if (vol > 0xff) + return -EINVAL; + if (unlikely(dreamcastcard->channel->vol == vol)) return 0; dreamcastcard->channel->vol = ucontrol->value.integer.value[0]; dreamcastcard->master_volume = ucontrol->value.integer.value[0]; diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 7824880..898a7d3 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -37,3 +37,6 @@ config SND_SOC_CS4270_VD33_ERRATA bool depends on SND_SOC_CS4270 +config SND_SOC_TLV320AIC3X + tristate + depends on SND_SOC && I2C diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 7ad78e3..c6e5338 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -4,6 +4,7 @@ snd-soc-wm8750-objs := wm8750.o snd-soc-wm8753-objs := wm8753.o snd-soc-wm9712-objs := wm9712.o snd-soc-cs4270-objs := cs4270.o +snd-soc-tlv320aic3x-objs := tlv320aic3x.o obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o @@ -11,3 +12,4 @@ obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o +obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 5d601ad..abac628 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c @@ -725,7 +725,8 @@ static int cs4270_probe(struct platform_device *pdev) codec->owner = THIS_MODULE; codec->dai = &cs4270_dai; codec->num_dai = 1; - codec->private_data = codec + ALIGN(sizeof(struct snd_soc_codec), 4); + codec->private_data = (void *) codec + + ALIGN(sizeof(struct snd_soc_codec), 4); socdev->codec = codec; diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c new file mode 100644 index 0000000..c075a28 --- /dev/null +++ b/sound/soc/codecs/tlv320aic3x.c @@ -0,0 +1,1275 @@ +/* + * ALSA SoC TLV320AIC3X codec driver + * + * Author: Vladimir Barinov, + * Copyright: (C) 2007 MontaVista Software, Inc., + * + * Based on sound/soc/codecs/wm8753.c by Liam Girdwood + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Notes: + * The AIC3X is a driver for a low power stereo audio + * codecs aic31, aic32, aic33. + * + * It supports full aic33 codec functionality. + * The compatibility with aic32, aic31 is as follows: + * aic32 | aic31 + * --------------------------------------- + * MONO_LOUT -> N/A | MONO_LOUT -> N/A + * | IN1L -> LINE1L + * | IN1R -> LINE1R + * | IN2L -> LINE2L + * | IN2R -> LINE2R + * | MIC3L/R -> N/A + * truncated internal functionality in + * accordance with documentation + * --------------------------------------- + * + * Hence the machine layer should disable unsupported inputs/outputs by + * snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0), etc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tlv320aic3x.h" + +#define AUDIO_NAME "aic3x" +#define AIC3X_VERSION "0.1" + +/* codec private data */ +struct aic3x_priv { + unsigned int sysclk; + int master; +}; + +/* + * AIC3X register cache + * We can't read the AIC3X register space when we are + * using 2 wire for device control, so we cache them instead. + * There is no point in caching the reset register + */ +static const u8 aic3x_reg[AIC3X_CACHEREGNUM] = { + 0x00, 0x00, 0x00, 0x10, /* 0 */ + 0x04, 0x00, 0x00, 0x00, /* 4 */ + 0x00, 0x00, 0x00, 0x01, /* 8 */ + 0x00, 0x00, 0x00, 0x80, /* 12 */ + 0x80, 0xff, 0xff, 0x78, /* 16 */ + 0x78, 0x78, 0x78, 0x78, /* 20 */ + 0x78, 0x00, 0x00, 0xfe, /* 24 */ + 0x00, 0x00, 0xfe, 0x00, /* 28 */ + 0x18, 0x18, 0x00, 0x00, /* 32 */ + 0x00, 0x00, 0x00, 0x00, /* 36 */ + 0x00, 0x00, 0x00, 0x80, /* 40 */ + 0x80, 0x00, 0x00, 0x00, /* 44 */ + 0x00, 0x00, 0x00, 0x04, /* 48 */ + 0x00, 0x00, 0x00, 0x00, /* 52 */ + 0x00, 0x00, 0x04, 0x00, /* 56 */ + 0x00, 0x00, 0x00, 0x00, /* 60 */ + 0x00, 0x04, 0x00, 0x00, /* 64 */ + 0x00, 0x00, 0x00, 0x00, /* 68 */ + 0x04, 0x00, 0x00, 0x00, /* 72 */ + 0x00, 0x00, 0x00, 0x00, /* 76 */ + 0x00, 0x00, 0x00, 0x00, /* 80 */ + 0x00, 0x00, 0x00, 0x00, /* 84 */ + 0x00, 0x00, 0x00, 0x00, /* 88 */ + 0x00, 0x00, 0x00, 0x00, /* 92 */ + 0x00, 0x00, 0x00, 0x00, /* 96 */ + 0x00, 0x00, 0x02, /* 100 */ +}; + +/* + * read aic3x register cache + */ +static inline unsigned int aic3x_read_reg_cache(struct snd_soc_codec *codec, + unsigned int reg) +{ + u8 *cache = codec->reg_cache; + if (reg >= AIC3X_CACHEREGNUM) + return -1; + return cache[reg]; +} + +/* + * write aic3x register cache + */ +static inline void aic3x_write_reg_cache(struct snd_soc_codec *codec, + u8 reg, u8 value) +{ + u8 *cache = codec->reg_cache; + if (reg >= AIC3X_CACHEREGNUM) + return; + cache[reg] = value; +} + +/* + * write to the aic3x register space + */ +static int aic3x_write(struct snd_soc_codec *codec, unsigned int reg, + unsigned int value) +{ + u8 data[2]; + + /* data is + * D15..D8 aic3x register offset + * D7...D0 register data + */ + data[0] = reg & 0xff; + data[1] = value & 0xff; + + aic3x_write_reg_cache(codec, data[0], data[1]); + if (codec->hw_write(codec->control_data, data, 2) == 2) + return 0; + else + return -EIO; +} + +#define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \ +{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ + .info = snd_soc_info_volsw, \ + .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw_aic3x, \ + .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) } + +/* + * All input lines are connected when !0xf and disconnected with 0xf bit field, + * so we have to use specific dapm_put call for input mixer + */ +static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); + int reg = kcontrol->private_value & 0xff; + int shift = (kcontrol->private_value >> 8) & 0x0f; + int mask = (kcontrol->private_value >> 16) & 0xff; + int invert = (kcontrol->private_value >> 24) & 0x01; + unsigned short val, val_mask; + int ret; + struct snd_soc_dapm_path *path; + int found = 0; + + val = (ucontrol->value.integer.value[0] & mask); + + mask = 0xf; + if (val) + val = mask; + + if (invert) + val = mask - val; + val_mask = mask << shift; + val = val << shift; + + mutex_lock(&widget->codec->mutex); + + if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) { + /* find dapm widget path assoc with kcontrol */ + list_for_each_entry(path, &widget->codec->dapm_paths, list) { + if (path->kcontrol != kcontrol) + continue; + + /* found, now check type */ + found = 1; + if (val) + /* new connection */ + path->connect = invert ? 0 : 1; + else + /* old connection must be powered down */ + path->connect = invert ? 1 : 0; + break; + } + + if (found) + snd_soc_dapm_sync_endpoints(widget->codec); + } + + ret = snd_soc_update_bits(widget->codec, reg, val_mask, val); + + mutex_unlock(&widget->codec->mutex); + return ret; +} + +static const char *aic3x_left_dac_mux[] = { "DAC_L1", "DAC_L3", "DAC_L2" }; +static const char *aic3x_right_dac_mux[] = { "DAC_R1", "DAC_R3", "DAC_R2" }; +static const char *aic3x_left_hpcom_mux[] = + { "differential of HPLOUT", "constant VCM", "single-ended" }; +static const char *aic3x_right_hpcom_mux[] = + { "differential of HPROUT", "constant VCM", "single-ended", + "differential of HPLCOM", "external feedback" }; +static const char *aic3x_linein_mode_mux[] = { "single-ended", "differential" }; + +#define LDAC_ENUM 0 +#define RDAC_ENUM 1 +#define LHPCOM_ENUM 2 +#define RHPCOM_ENUM 3 +#define LINE1L_ENUM 4 +#define LINE1R_ENUM 5 +#define LINE2L_ENUM 6 +#define LINE2R_ENUM 7 + +static const struct soc_enum aic3x_enum[] = { + SOC_ENUM_SINGLE(DAC_LINE_MUX, 6, 3, aic3x_left_dac_mux), + SOC_ENUM_SINGLE(DAC_LINE_MUX, 4, 3, aic3x_right_dac_mux), + SOC_ENUM_SINGLE(HPLCOM_CFG, 4, 3, aic3x_left_hpcom_mux), + SOC_ENUM_SINGLE(HPRCOM_CFG, 3, 5, aic3x_right_hpcom_mux), + SOC_ENUM_SINGLE(LINE1L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux), + SOC_ENUM_SINGLE(LINE1R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux), + SOC_ENUM_SINGLE(LINE2L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux), + SOC_ENUM_SINGLE(LINE2R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux), +}; + +static const struct snd_kcontrol_new aic3x_snd_controls[] = { + /* Output */ + SOC_DOUBLE_R("PCM Playback Volume", LDAC_VOL, RDAC_VOL, 0, 0x7f, 1), + + SOC_DOUBLE_R("Line DAC Playback Volume", DACL1_2_LLOPM_VOL, + DACR1_2_RLOPM_VOL, 0, 0x7f, 1), + SOC_DOUBLE_R("Line DAC Playback Switch", LLOPM_CTRL, RLOPM_CTRL, 3, + 0x01, 0), + SOC_DOUBLE_R("Line PGA Bypass Playback Volume", PGAL_2_LLOPM_VOL, + PGAR_2_RLOPM_VOL, 0, 0x7f, 1), + SOC_DOUBLE_R("Line Line2 Bypass Playback Volume", LINE2L_2_LLOPM_VOL, + LINE2R_2_RLOPM_VOL, 0, 0x7f, 1), + + SOC_DOUBLE_R("Mono DAC Playback Volume", DACL1_2_MONOLOPM_VOL, + DACR1_2_MONOLOPM_VOL, 0, 0x7f, 1), + SOC_SINGLE("Mono DAC Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0), + SOC_DOUBLE_R("Mono PGA Bypass Playback Volume", PGAL_2_MONOLOPM_VOL, + PGAR_2_MONOLOPM_VOL, 0, 0x7f, 1), + SOC_DOUBLE_R("Mono Line2 Bypass Playback Volume", LINE2L_2_MONOLOPM_VOL, + LINE2R_2_MONOLOPM_VOL, 0, 0x7f, 1), + + SOC_DOUBLE_R("HP DAC Playback Volume", DACL1_2_HPLOUT_VOL, + DACR1_2_HPROUT_VOL, 0, 0x7f, 1), + SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3, + 0x01, 0), + SOC_DOUBLE_R("HP PGA Bypass Playback Volume", PGAL_2_HPLOUT_VOL, + PGAR_2_HPROUT_VOL, 0, 0x7f, 1), + SOC_DOUBLE_R("HP Line2 Bypass Playback Volume", LINE2L_2_HPLOUT_VOL, + LINE2R_2_HPROUT_VOL, 0, 0x7f, 1), + + SOC_DOUBLE_R("HPCOM DAC Playback Volume", DACL1_2_HPLCOM_VOL, + DACR1_2_HPRCOM_VOL, 0, 0x7f, 1), + SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3, + 0x01, 0), + SOC_DOUBLE_R("HPCOM PGA Bypass Playback Volume", PGAL_2_HPLCOM_VOL, + PGAR_2_HPRCOM_VOL, 0, 0x7f, 1), + SOC_DOUBLE_R("HPCOM Line2 Bypass Playback Volume", LINE2L_2_HPLCOM_VOL, + LINE2R_2_HPRCOM_VOL, 0, 0x7f, 1), + + /* + * Note: enable Automatic input Gain Controller with care. It can + * adjust PGA to max value when ADC is on and will never go back. + */ + SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0), + + /* Input */ + SOC_DOUBLE_R("PGA Capture Volume", LADC_VOL, RADC_VOL, 0, 0x7f, 0), + SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1), +}; + +/* add non dapm controls */ +static int aic3x_add_controls(struct snd_soc_codec *codec) +{ + int err, i; + + for (i = 0; i < ARRAY_SIZE(aic3x_snd_controls); i++) { + err = snd_ctl_add(codec->card, + snd_soc_cnew(&aic3x_snd_controls[i], + codec, NULL)); + if (err < 0) + return err; + } + + return 0; +} + +/* Left DAC Mux */ +static const struct snd_kcontrol_new aic3x_left_dac_mux_controls = +SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]); + +/* Right DAC Mux */ +static const struct snd_kcontrol_new aic3x_right_dac_mux_controls = +SOC_DAPM_ENUM("Route", aic3x_enum[RDAC_ENUM]); + +/* Left HPCOM Mux */ +static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls = +SOC_DAPM_ENUM("Route", aic3x_enum[LHPCOM_ENUM]); + +/* Right HPCOM Mux */ +static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls = +SOC_DAPM_ENUM("Route", aic3x_enum[RHPCOM_ENUM]); + +/* Left DAC_L1 Mixer */ +static const struct snd_kcontrol_new aic3x_left_dac_mixer_controls[] = { + SOC_DAPM_SINGLE("Line Switch", DACL1_2_LLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("Mono Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HP Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HPCOM Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0), +}; + +/* Right DAC_R1 Mixer */ +static const struct snd_kcontrol_new aic3x_right_dac_mixer_controls[] = { + SOC_DAPM_SINGLE("Line Switch", DACR1_2_RLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("Mono Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HP Switch", DACR1_2_HPROUT_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HPCOM Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0), +}; + +/* Left PGA Mixer */ +static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = { + SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1), + SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1), + SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1), +}; + +/* Right PGA Mixer */ +static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = { + SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1), + SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1), + SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1), +}; + +/* Left Line1 Mux */ +static const struct snd_kcontrol_new aic3x_left_line1_mux_controls = +SOC_DAPM_ENUM("Route", aic3x_enum[LINE1L_ENUM]); + +/* Right Line1 Mux */ +static const struct snd_kcontrol_new aic3x_right_line1_mux_controls = +SOC_DAPM_ENUM("Route", aic3x_enum[LINE1R_ENUM]); + +/* Left Line2 Mux */ +static const struct snd_kcontrol_new aic3x_left_line2_mux_controls = +SOC_DAPM_ENUM("Route", aic3x_enum[LINE2L_ENUM]); + +/* Right Line2 Mux */ +static const struct snd_kcontrol_new aic3x_right_line2_mux_controls = +SOC_DAPM_ENUM("Route", aic3x_enum[LINE2R_ENUM]); + +/* Left PGA Bypass Mixer */ +static const struct snd_kcontrol_new aic3x_left_pga_bp_mixer_controls[] = { + SOC_DAPM_SINGLE("Line Switch", PGAL_2_LLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("Mono Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HP Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HPCOM Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0), +}; + +/* Right PGA Bypass Mixer */ +static const struct snd_kcontrol_new aic3x_right_pga_bp_mixer_controls[] = { + SOC_DAPM_SINGLE("Line Switch", PGAR_2_RLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("Mono Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HP Switch", PGAR_2_HPROUT_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HPCOM Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0), +}; + +/* Left Line2 Bypass Mixer */ +static const struct snd_kcontrol_new aic3x_left_line2_bp_mixer_controls[] = { + SOC_DAPM_SINGLE("Line Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("Mono Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HP Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HPCOM Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0), +}; + +/* Right Line2 Bypass Mixer */ +static const struct snd_kcontrol_new aic3x_right_line2_bp_mixer_controls[] = { + SOC_DAPM_SINGLE("Line Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("Mono Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HP Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0), + SOC_DAPM_SINGLE("HPCOM Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0), +}; + +static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { + /* Left DAC to Left Outputs */ + SND_SOC_DAPM_DAC("Left DAC", "Left Playback", DAC_PWR, 7, 0), + SND_SOC_DAPM_MUX("Left DAC Mux", SND_SOC_NOPM, 0, 0, + &aic3x_left_dac_mux_controls), + SND_SOC_DAPM_MIXER("Left DAC_L1 Mixer", SND_SOC_NOPM, 0, 0, + &aic3x_left_dac_mixer_controls[0], + ARRAY_SIZE(aic3x_left_dac_mixer_controls)), + SND_SOC_DAPM_MUX("Left HPCOM Mux", SND_SOC_NOPM, 0, 0, + &aic3x_left_hpcom_mux_controls), + SND_SOC_DAPM_PGA("Left Line Out", LLOPM_CTRL, 0, 0, NULL, 0), + SND_SOC_DAPM_PGA("Left HP Out", HPLOUT_CTRL, 0, 0, NULL, 0), + SND_SOC_DAPM_PGA("Left HP Com", HPLCOM_CTRL, 0, 0, NULL, 0), + + /* Right DAC to Right Outputs */ + SND_SOC_DAPM_DAC("Right DAC", "Right Playback", DAC_PWR, 6, 0), + SND_SOC_DAPM_MUX("Right DAC Mux", SND_SOC_NOPM, 0, 0, + &aic3x_right_dac_mux_controls), + SND_SOC_DAPM_MIXER("Right DAC_R1 Mixer", SND_SOC_NOPM, 0, 0, + &aic3x_right_dac_mixer_controls[0], + ARRAY_SIZE(aic3x_right_dac_mixer_controls)), + SND_SOC_DAPM_MUX("Right HPCOM Mux", SND_SOC_NOPM, 0, 0, + &aic3x_right_hpcom_mux_controls), + SND_SOC_DAPM_PGA("Right Line Out", RLOPM_CTRL, 0, 0, NULL, 0), + SND_SOC_DAPM_PGA("Right HP Out", HPROUT_CTRL, 0, 0, NULL, 0), + SND_SOC_DAPM_PGA("Right HP Com", HPRCOM_CTRL, 0, 0, NULL, 0), + + /* Mono Output */ + SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0), + + /* Left Inputs to Left ADC */ + SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0), + SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0, + &aic3x_left_pga_mixer_controls[0], + ARRAY_SIZE(aic3x_left_pga_mixer_controls)), + SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0, + &aic3x_left_line1_mux_controls), + SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0, + &aic3x_left_line2_mux_controls), + + /* Right Inputs to Right ADC */ + SND_SOC_DAPM_ADC("Right ADC", "Right Capture", + LINE1R_2_RADC_CTRL, 2, 0), + SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0, + &aic3x_right_pga_mixer_controls[0], + ARRAY_SIZE(aic3x_right_pga_mixer_controls)), + SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0, + &aic3x_right_line1_mux_controls), + SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0, + &aic3x_right_line2_mux_controls), + + /* Mic Bias */ + SND_SOC_DAPM_MICBIAS("Mic Bias 2V", MICBIAS_CTRL, 6, 0), + SND_SOC_DAPM_MICBIAS("Mic Bias 2.5V", MICBIAS_CTRL, 7, 0), + SND_SOC_DAPM_MICBIAS("Mic Bias AVDD", MICBIAS_CTRL, 6, 0), + SND_SOC_DAPM_MICBIAS("Mic Bias AVDD", MICBIAS_CTRL, 7, 0), + + /* Left PGA to Left Output bypass */ + SND_SOC_DAPM_MIXER("Left PGA Bypass Mixer", SND_SOC_NOPM, 0, 0, + &aic3x_left_pga_bp_mixer_controls[0], + ARRAY_SIZE(aic3x_left_pga_bp_mixer_controls)), + + /* Right PGA to Right Output bypass */ + SND_SOC_DAPM_MIXER("Right PGA Bypass Mixer", SND_SOC_NOPM, 0, 0, + &aic3x_right_pga_bp_mixer_controls[0], + ARRAY_SIZE(aic3x_right_pga_bp_mixer_controls)), + + /* Left Line2 to Left Output bypass */ + SND_SOC_DAPM_MIXER("Left Line2 Bypass Mixer", SND_SOC_NOPM, 0, 0, + &aic3x_left_line2_bp_mixer_controls[0], + ARRAY_SIZE(aic3x_left_line2_bp_mixer_controls)), + + /* Right Line2 to Right Output bypass */ + SND_SOC_DAPM_MIXER("Right Line2 Bypass Mixer", SND_SOC_NOPM, 0, 0, + &aic3x_right_line2_bp_mixer_controls[0], + ARRAY_SIZE(aic3x_right_line2_bp_mixer_controls)), + + SND_SOC_DAPM_OUTPUT("LLOUT"), + SND_SOC_DAPM_OUTPUT("RLOUT"), + SND_SOC_DAPM_OUTPUT("MONO_LOUT"), + SND_SOC_DAPM_OUTPUT("HPLOUT"), + SND_SOC_DAPM_OUTPUT("HPROUT"), + SND_SOC_DAPM_OUTPUT("HPLCOM"), + SND_SOC_DAPM_OUTPUT("HPRCOM"), + + SND_SOC_DAPM_INPUT("MIC3L"), + SND_SOC_DAPM_INPUT("MIC3R"), + SND_SOC_DAPM_INPUT("LINE1L"), + SND_SOC_DAPM_INPUT("LINE1R"), + SND_SOC_DAPM_INPUT("LINE2L"), + SND_SOC_DAPM_INPUT("LINE2R"), +}; + +static const char *intercon[][3] = { + /* Left Output */ + {"Left DAC Mux", "DAC_L1", "Left DAC"}, + {"Left DAC Mux", "DAC_L2", "Left DAC"}, + {"Left DAC Mux", "DAC_L3", "Left DAC"}, + + {"Left DAC_L1 Mixer", "Line Switch", "Left DAC Mux"}, + {"Left DAC_L1 Mixer", "Mono Switch", "Left DAC Mux"}, + {"Left DAC_L1 Mixer", "HP Switch", "Left DAC Mux"}, + {"Left DAC_L1 Mixer", "HPCOM Switch", "Left DAC Mux"}, + {"Left Line Out", NULL, "Left DAC Mux"}, + {"Left HP Out", NULL, "Left DAC Mux"}, + + {"Left HPCOM Mux", "differential of HPLOUT", "Left DAC_L1 Mixer"}, + {"Left HPCOM Mux", "constant VCM", "Left DAC_L1 Mixer"}, + {"Left HPCOM Mux", "single-ended", "Left DAC_L1 Mixer"}, + + {"Left Line Out", NULL, "Left DAC_L1 Mixer"}, + {"Mono Out", NULL, "Left DAC_L1 Mixer"}, + {"Left HP Out", NULL, "Left DAC_L1 Mixer"}, + {"Left HP Com", NULL, "Left HPCOM Mux"}, + + {"LLOUT", NULL, "Left Line Out"}, + {"LLOUT", NULL, "Left Line Out"}, + {"HPLOUT", NULL, "Left HP Out"}, + {"HPLCOM", NULL, "Left HP Com"}, + + /* Right Output */ + {"Right DAC Mux", "DAC_R1", "Right DAC"}, + {"Right DAC Mux", "DAC_R2", "Right DAC"}, + {"Right DAC Mux", "DAC_R3", "Right DAC"}, + + {"Right DAC_R1 Mixer", "Line Switch", "Right DAC Mux"}, + {"Right DAC_R1 Mixer", "Mono Switch", "Right DAC Mux"}, + {"Right DAC_R1 Mixer", "HP Switch", "Right DAC Mux"}, + {"Right DAC_R1 Mixer", "HPCOM Switch", "Right DAC Mux"}, + {"Right Line Out", NULL, "Right DAC Mux"}, + {"Right HP Out", NULL, "Right DAC Mux"}, + + {"Right HPCOM Mux", "differential of HPROUT", "Right DAC_R1 Mixer"}, + {"Right HPCOM Mux", "constant VCM", "Right DAC_R1 Mixer"}, + {"Right HPCOM Mux", "single-ended", "Right DAC_R1 Mixer"}, + {"Right HPCOM Mux", "differential of HPLCOM", "Right DAC_R1 Mixer"}, + {"Right HPCOM Mux", "external feedback", "Right DAC_R1 Mixer"}, + + {"Right Line Out", NULL, "Right DAC_R1 Mixer"}, + {"Mono Out", NULL, "Right DAC_R1 Mixer"}, + {"Right HP Out", NULL, "Right DAC_R1 Mixer"}, + {"Right HP Com", NULL, "Right HPCOM Mux"}, + + {"RLOUT", NULL, "Right Line Out"}, + {"RLOUT", NULL, "Right Line Out"}, + {"HPROUT", NULL, "Right HP Out"}, + {"HPRCOM", NULL, "Right HP Com"}, + + /* Mono Output */ + {"MONOLOUT", NULL, "Mono Out"}, + {"MONOLOUT", NULL, "Mono Out"}, + + /* Left Input */ + {"Left Line1L Mux", "single-ended", "LINE1L"}, + {"Left Line1L Mux", "differential", "LINE1L"}, + + {"Left Line2L Mux", "single-ended", "LINE2L"}, + {"Left Line2L Mux", "differential", "LINE2L"}, + + {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"}, + {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"}, + {"Left PGA Mixer", "Mic3L Switch", "MIC3L"}, + + {"Left ADC", NULL, "Left PGA Mixer"}, + + /* Right Input */ + {"Right Line1R Mux", "single-ended", "LINE1R"}, + {"Right Line1R Mux", "differential", "LINE1R"}, + + {"Right Line2R Mux", "single-ended", "LINE2R"}, + {"Right Line2R Mux", "differential", "LINE2R"}, + + {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"}, + {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"}, + {"Right PGA Mixer", "Mic3R Switch", "MIC3R"}, + + {"Right ADC", NULL, "Right PGA Mixer"}, + + /* Left PGA Bypass */ + {"Left PGA Bypass Mixer", "Line Switch", "Left PGA Mixer"}, + {"Left PGA Bypass Mixer", "Mono Switch", "Left PGA Mixer"}, + {"Left PGA Bypass Mixer", "HP Switch", "Left PGA Mixer"}, + {"Left PGA Bypass Mixer", "HPCOM Switch", "Left PGA Mixer"}, + + {"Left HPCOM Mux", "differential of HPLOUT", "Left PGA Bypass Mixer"}, + {"Left HPCOM Mux", "constant VCM", "Left PGA Bypass Mixer"}, + {"Left HPCOM Mux", "single-ended", "Left PGA Bypass Mixer"}, + + {"Left Line Out", NULL, "Left PGA Bypass Mixer"}, + {"Mono Out", NULL, "Left PGA Bypass Mixer"}, + {"Left HP Out", NULL, "Left PGA Bypass Mixer"}, + + /* Right PGA Bypass */ + {"Right PGA Bypass Mixer", "Line Switch", "Right PGA Mixer"}, + {"Right PGA Bypass Mixer", "Mono Switch", "Right PGA Mixer"}, + {"Right PGA Bypass Mixer", "HP Switch", "Right PGA Mixer"}, + {"Right PGA Bypass Mixer", "HPCOM Switch", "Right PGA Mixer"}, + + {"Right HPCOM Mux", "differential of HPROUT", "Right PGA Bypass Mixer"}, + {"Right HPCOM Mux", "constant VCM", "Right PGA Bypass Mixer"}, + {"Right HPCOM Mux", "single-ended", "Right PGA Bypass Mixer"}, + {"Right HPCOM Mux", "differential of HPLCOM", "Right PGA Bypass Mixer"}, + {"Right HPCOM Mux", "external feedback", "Right PGA Bypass Mixer"}, + + {"Right Line Out", NULL, "Right PGA Bypass Mixer"}, + {"Mono Out", NULL, "Right PGA Bypass Mixer"}, + {"Right HP Out", NULL, "Right PGA Bypass Mixer"}, + + /* Left Line2 Bypass */ + {"Left Line2 Bypass Mixer", "Line Switch", "Left Line2L Mux"}, + {"Left Line2 Bypass Mixer", "Mono Switch", "Left Line2L Mux"}, + {"Left Line2 Bypass Mixer", "HP Switch", "Left Line2L Mux"}, + {"Left Line2 Bypass Mixer", "HPCOM Switch", "Left Line2L Mux"}, + + {"Left HPCOM Mux", "differential of HPLOUT", "Left Line2 Bypass Mixer"}, + {"Left HPCOM Mux", "constant VCM", "Left Line2 Bypass Mixer"}, + {"Left HPCOM Mux", "single-ended", "Left Line2 Bypass Mixer"}, + + {"Left Line Out", NULL, "Left Line2 Bypass Mixer"}, + {"Mono Out", NULL, "Left Line2 Bypass Mixer"}, + {"Left HP Out", NULL, "Left Line2 Bypass Mixer"}, + + /* Right Line2 Bypass */ + {"Right Line2 Bypass Mixer", "Line Switch", "Right Line2R Mux"}, + {"Right Line2 Bypass Mixer", "Mono Switch", "Right Line2R Mux"}, + {"Right Line2 Bypass Mixer", "HP Switch", "Right Line2R Mux"}, + {"Right Line2 Bypass Mixer", "HPCOM Switch", "Right Line2R Mux"}, + + {"Right HPCOM Mux", "differential of HPROUT", "Right Line2 Bypass Mixer"}, + {"Right HPCOM Mux", "constant VCM", "Right Line2 Bypass Mixer"}, + {"Right HPCOM Mux", "single-ended", "Right Line2 Bypass Mixer"}, + {"Right HPCOM Mux", "differential of HPLCOM", "Right Line2 Bypass Mixer"}, + {"Right HPCOM Mux", "external feedback", "Right Line2 Bypass Mixer"}, + + {"Right Line Out", NULL, "Right Line2 Bypass Mixer"}, + {"Mono Out", NULL, "Right Line2 Bypass Mixer"}, + {"Right HP Out", NULL, "Right Line2 Bypass Mixer"}, + + /* terminator */ + {NULL, NULL, NULL}, +}; + +static int aic3x_add_widgets(struct snd_soc_codec *codec) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(aic3x_dapm_widgets); i++) + snd_soc_dapm_new_control(codec, &aic3x_dapm_widgets[i]); + + /* set up audio path interconnects */ + for (i = 0; intercon[i][0] != NULL; i++) + snd_soc_dapm_connect_input(codec, intercon[i][0], + intercon[i][1], intercon[i][2]); + + snd_soc_dapm_new_widgets(codec); + return 0; +} + +struct aic3x_rate_divs { + u32 mclk; + u32 rate; + u32 fsref_reg; + u8 sr_reg:4; + u8 pllj_reg; + u16 plld_reg; +}; + +/* AIC3X codec mclk clock divider coefficients */ +static const struct aic3x_rate_divs aic3x_divs[] = { + /* 8k */ + {22579200, 8000, 48000, 0xa, 8, 7075}, + {33868800, 8000, 48000, 0xa, 5, 8049}, + /* 11.025k */ + {22579200, 11025, 44100, 0x6, 8, 0}, + {33868800, 11025, 44100, 0x6, 5, 3333}, + /* 16k */ + {22579200, 16000, 48000, 0x4, 8, 7075}, + {33868800, 16000, 48000, 0x4, 5, 8049}, + /* 22.05k */ + {22579200, 22050, 44100, 0x2, 8, 0}, + {33868800, 22050, 44100, 0x2, 5, 3333}, + /* 32k */ + {22579200, 32000, 48000, 0x1, 8, 7075}, + {33868800, 32000, 48000, 0x1, 5, 8049}, + /* 44.1k */ + {22579200, 44100, 44100, 0x0, 8, 0}, + {33868800, 44100, 44100, 0x0, 5, 3333}, + /* 48k */ + {22579200, 48000, 48000, 0x0, 8, 7075}, + {33868800, 48000, 48000, 0x0, 5, 8049}, + /* 64k */ + {22579200, 96000, 96000, 0x1, 8, 7075}, + {33868800, 96000, 96000, 0x1, 5, 8049}, + /* 88.2k */ + {22579200, 88200, 88200, 0x0, 8, 0}, + {33868800, 88200, 88200, 0x0, 5, 3333}, + /* 96k */ + {22579200, 96000, 96000, 0x0, 8, 7075}, + {33868800, 96000, 96000, 0x0, 5, 8049}, +}; + +static inline int aic3x_get_divs(int mclk, int rate) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(aic3x_divs); i++) { + if (aic3x_divs[i].rate == rate && aic3x_divs[i].mclk == mclk) + return i; + } + + return 0; +} + +static int aic3x_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_device *socdev = rtd->socdev; + struct snd_soc_codec *codec = socdev->codec; + struct aic3x_priv *aic3x = codec->private_data; + int i; + u8 data, pll_p, pll_r, pll_j; + u16 pll_d; + + i = aic3x_get_divs(aic3x->sysclk, params_rate(params)); + + /* Route Left DAC to left channel input and + * right DAC to right channel input */ + data = (LDAC2LCH | RDAC2RCH); + switch (aic3x_divs[i].fsref_reg) { + case 44100: + data |= FSREF_44100; + break; + case 48000: + data |= FSREF_48000; + break; + case 88200: + data |= FSREF_44100 | DUAL_RATE_MODE; + break; + case 96000: + data |= FSREF_48000 | DUAL_RATE_MODE; + break; + } + aic3x_write(codec, AIC3X_CODEC_DATAPATH_REG, data); + + /* codec sample rate select */ + data = aic3x_divs[i].sr_reg; + data |= (data << 4); + aic3x_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data); + + /* Use PLL for generation Fsref by equation: + * Fsref = (MCLK * K * R)/(2048 * P); + * Fix P = 2 and R = 1 and calculate K, if + * K = J.D, i.e. J - an interger portion of K and D is the fractional + * one with 4 digits of precision; + * Example: + * For MCLK = 22.5792 MHz and Fsref = 48kHz: + * Select P = 2, R= 1, K = 8.7074, which results in J = 8, D = 7074 + */ + pll_p = 2; + pll_r = 1; + pll_j = aic3x_divs[i].pllj_reg; + pll_d = aic3x_divs[i].plld_reg; + + data = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG); + aic3x_write(codec, AIC3X_PLL_PROGA_REG, data | (pll_p << PLLP_SHIFT)); + aic3x_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG, pll_r << PLLR_SHIFT); + aic3x_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT); + aic3x_write(codec, AIC3X_PLL_PROGC_REG, (pll_d >> 6) << PLLD_MSB_SHIFT); + aic3x_write(codec, AIC3X_PLL_PROGD_REG, + (pll_d & 0x3F) << PLLD_LSB_SHIFT); + + /* select data word length */ + data = + aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4)); + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_S16_LE: + break; + case SNDRV_PCM_FORMAT_S20_3LE: + data |= (0x01 << 4); + break; + case SNDRV_PCM_FORMAT_S24_LE: + data |= (0x02 << 4); + break; + case SNDRV_PCM_FORMAT_S32_LE: + data |= (0x03 << 4); + break; + } + aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, data); + + return 0; +} + +static int aic3x_mute(struct snd_soc_codec_dai *dai, int mute) +{ + struct snd_soc_codec *codec = dai->codec; + u8 ldac_reg = aic3x_read_reg_cache(codec, LDAC_VOL) & ~MUTE_ON; + u8 rdac_reg = aic3x_read_reg_cache(codec, RDAC_VOL) & ~MUTE_ON; + + if (mute) { + aic3x_write(codec, LDAC_VOL, ldac_reg | MUTE_ON); + aic3x_write(codec, RDAC_VOL, rdac_reg | MUTE_ON); + } else { + aic3x_write(codec, LDAC_VOL, ldac_reg); + aic3x_write(codec, RDAC_VOL, rdac_reg); + } + + return 0; +} + +static int aic3x_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai, + int clk_id, unsigned int freq, int dir) +{ + struct snd_soc_codec *codec = codec_dai->codec; + struct aic3x_priv *aic3x = codec->private_data; + + switch (freq) { + case 22579200: + case 33868800: + aic3x->sysclk = freq; + return 0; + } + + return -EINVAL; +} + +static int aic3x_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, + unsigned int fmt) +{ + struct snd_soc_codec *codec = codec_dai->codec; + struct aic3x_priv *aic3x = codec->private_data; + u8 iface_areg = 0; + u8 iface_breg = 0; + + /* set master/slave audio interface */ + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { + case SND_SOC_DAIFMT_CBM_CFM: + aic3x->master = 1; + iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER; + break; + case SND_SOC_DAIFMT_CBS_CFS: + aic3x->master = 0; + break; + default: + return -EINVAL; + } + + /* interface format */ + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { + case SND_SOC_DAIFMT_I2S: + break; + case SND_SOC_DAIFMT_DSP_A: + iface_breg |= (0x01 << 6); + break; + case SND_SOC_DAIFMT_RIGHT_J: + iface_breg |= (0x02 << 6); + break; + case SND_SOC_DAIFMT_LEFT_J: + iface_breg |= (0x03 << 6); + break; + default: + return -EINVAL; + } + + /* set iface */ + aic3x_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg); + aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg); + + return 0; +} + +static int aic3x_dapm_event(struct snd_soc_codec *codec, int event) +{ + struct aic3x_priv *aic3x = codec->private_data; + u8 reg; + + switch (event) { + case SNDRV_CTL_POWER_D0: + /* all power is driven by DAPM system */ + if (aic3x->master) { + /* enable pll */ + reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG); + aic3x_write(codec, AIC3X_PLL_PROGA_REG, + reg | PLL_ENABLE); + } + break; + case SNDRV_CTL_POWER_D1: + case SNDRV_CTL_POWER_D2: + break; + case SNDRV_CTL_POWER_D3hot: + /* + * all power is driven by DAPM system, + * so output power is safe if bypass was set + */ + if (aic3x->master) { + /* disable pll */ + reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG); + aic3x_write(codec, AIC3X_PLL_PROGA_REG, + reg & ~PLL_ENABLE); + } + break; + case SNDRV_CTL_POWER_D3cold: + /* force all power off */ + reg = aic3x_read_reg_cache(codec, LINE1L_2_LADC_CTRL); + aic3x_write(codec, LINE1L_2_LADC_CTRL, reg & ~LADC_PWR_ON); + reg = aic3x_read_reg_cache(codec, LINE1R_2_RADC_CTRL); + aic3x_write(codec, LINE1R_2_RADC_CTRL, reg & ~RADC_PWR_ON); + + reg = aic3x_read_reg_cache(codec, DAC_PWR); + aic3x_write(codec, DAC_PWR, reg & ~(LDAC_PWR_ON | RDAC_PWR_ON)); + + reg = aic3x_read_reg_cache(codec, HPLOUT_CTRL); + aic3x_write(codec, HPLOUT_CTRL, reg & ~HPLOUT_PWR_ON); + reg = aic3x_read_reg_cache(codec, HPROUT_CTRL); + aic3x_write(codec, HPROUT_CTRL, reg & ~HPROUT_PWR_ON); + + reg = aic3x_read_reg_cache(codec, HPLCOM_CTRL); + aic3x_write(codec, HPLCOM_CTRL, reg & ~HPLCOM_PWR_ON); + reg = aic3x_read_reg_cache(codec, HPRCOM_CTRL); + aic3x_write(codec, HPRCOM_CTRL, reg & ~HPRCOM_PWR_ON); + + reg = aic3x_read_reg_cache(codec, MONOLOPM_CTRL); + aic3x_write(codec, MONOLOPM_CTRL, reg & ~MONOLOPM_PWR_ON); + + reg = aic3x_read_reg_cache(codec, LLOPM_CTRL); + aic3x_write(codec, LLOPM_CTRL, reg & ~LLOPM_PWR_ON); + reg = aic3x_read_reg_cache(codec, RLOPM_CTRL); + aic3x_write(codec, RLOPM_CTRL, reg & ~RLOPM_PWR_ON); + + if (aic3x->master) { + /* disable pll */ + reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG); + aic3x_write(codec, AIC3X_PLL_PROGA_REG, + reg & ~PLL_ENABLE); + } + break; + } + codec->dapm_state = event; + + return 0; +} + +#define AIC3X_RATES SNDRV_PCM_RATE_8000_96000 +#define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) + +struct snd_soc_codec_dai aic3x_dai = { + .name = "aic3x", + .playback = { + .stream_name = "Playback", + .channels_min = 1, + .channels_max = 2, + .rates = AIC3X_RATES, + .formats = AIC3X_FORMATS,}, + .capture = { + .stream_name = "Capture", + .channels_min = 1, + .channels_max = 2, + .rates = AIC3X_RATES, + .formats = AIC3X_FORMATS,}, + .ops = { + .hw_params = aic3x_hw_params, + }, + .dai_ops = { + .digital_mute = aic3x_mute, + .set_sysclk = aic3x_set_dai_sysclk, + .set_fmt = aic3x_set_dai_fmt, + } +}; +EXPORT_SYMBOL_GPL(aic3x_dai); + +static int aic3x_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct snd_soc_device *socdev = platform_get_drvdata(pdev); + struct snd_soc_codec *codec = socdev->codec; + + aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3cold); + + return 0; +} + +static int aic3x_resume(struct platform_device *pdev) +{ + struct snd_soc_device *socdev = platform_get_drvdata(pdev); + struct snd_soc_codec *codec = socdev->codec; + int i; + u8 data[2]; + u8 *cache = codec->reg_cache; + + /* Sync reg_cache with the hardware */ + for (i = 0; i < ARRAY_SIZE(aic3x_reg); i++) { + data[0] = i; + data[1] = cache[i]; + codec->hw_write(codec->control_data, data, 2); + } + + aic3x_dapm_event(codec, codec->suspend_dapm_state); + + return 0; +} + +/* + * initialise the AIC3X driver + * register the mixer and dsp interfaces with the kernel + */ +static int aic3x_init(struct snd_soc_device *socdev) +{ + struct snd_soc_codec *codec = socdev->codec; + int reg, ret = 0; + + codec->name = "aic3x"; + codec->owner = THIS_MODULE; + codec->read = aic3x_read_reg_cache; + codec->write = aic3x_write; + codec->dapm_event = aic3x_dapm_event; + codec->dai = &aic3x_dai; + codec->num_dai = 1; + codec->reg_cache_size = sizeof(aic3x_reg); + codec->reg_cache = kmemdup(aic3x_reg, sizeof(aic3x_reg), GFP_KERNEL); + if (codec->reg_cache == NULL) + return -ENOMEM; + + aic3x_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT); + aic3x_write(codec, AIC3X_RESET, SOFT_RESET); + + /* register pcms */ + ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); + if (ret < 0) { + printk(KERN_ERR "aic3x: failed to create pcms\n"); + goto pcm_err; + } + + /* DAC default volume and mute */ + aic3x_write(codec, LDAC_VOL, DEFAULT_VOL | MUTE_ON); + aic3x_write(codec, RDAC_VOL, DEFAULT_VOL | MUTE_ON); + + /* DAC to HP default volume and route to Output mixer */ + aic3x_write(codec, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON); + aic3x_write(codec, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON); + aic3x_write(codec, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON); + aic3x_write(codec, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON); + /* DAC to Line Out default volume and route to Output mixer */ + aic3x_write(codec, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON); + aic3x_write(codec, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON); + /* DAC to Mono Line Out default volume and route to Output mixer */ + aic3x_write(codec, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON); + aic3x_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON); + + /* unmute all outputs */ + reg = aic3x_read_reg_cache(codec, LLOPM_CTRL); + aic3x_write(codec, LLOPM_CTRL, reg | UNMUTE); + reg = aic3x_read_reg_cache(codec, RLOPM_CTRL); + aic3x_write(codec, RLOPM_CTRL, reg | UNMUTE); + reg = aic3x_read_reg_cache(codec, MONOLOPM_CTRL); + aic3x_write(codec, MONOLOPM_CTRL, reg | UNMUTE); + reg = aic3x_read_reg_cache(codec, HPLOUT_CTRL); + aic3x_write(codec, HPLOUT_CTRL, reg | UNMUTE); + reg = aic3x_read_reg_cache(codec, HPROUT_CTRL); + aic3x_write(codec, HPROUT_CTRL, reg | UNMUTE); + reg = aic3x_read_reg_cache(codec, HPLCOM_CTRL); + aic3x_write(codec, HPLCOM_CTRL, reg | UNMUTE); + reg = aic3x_read_reg_cache(codec, HPRCOM_CTRL); + aic3x_write(codec, HPRCOM_CTRL, reg | UNMUTE); + + /* ADC default volume and unmute */ + aic3x_write(codec, LADC_VOL, DEFAULT_GAIN); + aic3x_write(codec, RADC_VOL, DEFAULT_GAIN); + /* By default route Line1 to ADC PGA mixer */ + aic3x_write(codec, LINE1L_2_LADC_CTRL, 0x0); + aic3x_write(codec, LINE1R_2_RADC_CTRL, 0x0); + + /* PGA to HP Bypass default volume, disconnect from Output Mixer */ + aic3x_write(codec, PGAL_2_HPLOUT_VOL, DEFAULT_VOL); + aic3x_write(codec, PGAR_2_HPROUT_VOL, DEFAULT_VOL); + aic3x_write(codec, PGAL_2_HPLCOM_VOL, DEFAULT_VOL); + aic3x_write(codec, PGAR_2_HPRCOM_VOL, DEFAULT_VOL); + /* PGA to Line Out default volume, disconnect from Output Mixer */ + aic3x_write(codec, PGAL_2_LLOPM_VOL, DEFAULT_VOL); + aic3x_write(codec, PGAR_2_RLOPM_VOL, DEFAULT_VOL); + /* PGA to Mono Line Out default volume, disconnect from Output Mixer */ + aic3x_write(codec, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL); + aic3x_write(codec, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL); + + /* Line2 to HP Bypass default volume, disconnect from Output Mixer */ + aic3x_write(codec, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL); + aic3x_write(codec, LINE2R_2_HPROUT_VOL, DEFAULT_VOL); + aic3x_write(codec, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL); + aic3x_write(codec, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL); + /* Line2 Line Out default volume, disconnect from Output Mixer */ + aic3x_write(codec, LINE2L_2_LLOPM_VOL, DEFAULT_VOL); + aic3x_write(codec, LINE2R_2_RLOPM_VOL, DEFAULT_VOL); + /* Line2 to Mono Out default volume, disconnect from Output Mixer */ + aic3x_write(codec, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL); + aic3x_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL); + + /* off, with power on */ + aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3hot); + + aic3x_add_controls(codec); + aic3x_add_widgets(codec); + ret = snd_soc_register_card(socdev); + if (ret < 0) { + printk(KERN_ERR "aic3x: failed to register card\n"); + goto card_err; + } + + return ret; + +card_err: + snd_soc_free_pcms(socdev); + snd_soc_dapm_free(socdev); +pcm_err: + kfree(codec->reg_cache); + return ret; +} + +static struct snd_soc_device *aic3x_socdev; + +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) +/* + * AIC3X 2 wire address can be up to 4 devices with device addresses + * 0x18, 0x19, 0x1A, 0x1B + */ +static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; + +/* Magic definition of all other variables and things */ +I2C_CLIENT_INSMOD; + +static struct i2c_driver aic3x_i2c_driver; +static struct i2c_client client_template; + +/* + * If the i2c layer weren't so broken, we could pass this kind of data + * around + */ +static int aic3x_codec_probe(struct i2c_adapter *adap, int addr, int kind) +{ + struct snd_soc_device *socdev = aic3x_socdev; + struct aic3x_setup_data *setup = socdev->codec_data; + struct snd_soc_codec *codec = socdev->codec; + struct i2c_client *i2c; + int ret; + + if (addr != setup->i2c_address) + return -ENODEV; + + client_template.adapter = adap; + client_template.addr = addr; + + i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); + if (i2c == NULL) { + kfree(codec); + return -ENOMEM; + } + i2c_set_clientdata(i2c, codec); + codec->control_data = i2c; + + ret = i2c_attach_client(i2c); + if (ret < 0) { + printk(KERN_ERR "aic3x: failed to attach codec at addr %x\n", + addr); + goto err; + } + + ret = aic3x_init(socdev); + if (ret < 0) { + printk(KERN_ERR "aic3x: failed to initialise AIC3X\n"); + goto err; + } + return ret; + +err: + kfree(codec); + kfree(i2c); + return ret; +} + +static int aic3x_i2c_detach(struct i2c_client *client) +{ + struct snd_soc_codec *codec = i2c_get_clientdata(client); + i2c_detach_client(client); + kfree(codec->reg_cache); + kfree(client); + return 0; +} + +static int aic3x_i2c_attach(struct i2c_adapter *adap) +{ + return i2c_probe(adap, &addr_data, aic3x_codec_probe); +} + +/* machine i2c codec control layer */ +static struct i2c_driver aic3x_i2c_driver = { + .driver = { + .name = "aic3x I2C Codec", + .owner = THIS_MODULE, + }, + .id = I2C_DRIVERID_I2CDEV, + .attach_adapter = aic3x_i2c_attach, + .detach_client = aic3x_i2c_detach, + .command = NULL, +}; + +static struct i2c_client client_template = { + .name = "AIC3X", + .driver = &aic3x_i2c_driver, +}; +#endif + +static int aic3x_probe(struct platform_device *pdev) +{ + struct snd_soc_device *socdev = platform_get_drvdata(pdev); + struct aic3x_setup_data *setup; + struct snd_soc_codec *codec; + struct aic3x_priv *aic3x; + int ret = 0; + + printk(KERN_INFO "AIC3X Audio Codec %s\n", AIC3X_VERSION); + + setup = socdev->codec_data; + codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); + if (codec == NULL) + return -ENOMEM; + + aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL); + if (aic3x == NULL) { + kfree(codec); + return -ENOMEM; + } + + codec->private_data = aic3x; + socdev->codec = codec; + mutex_init(&codec->mutex); + INIT_LIST_HEAD(&codec->dapm_widgets); + INIT_LIST_HEAD(&codec->dapm_paths); + + aic3x_socdev = socdev; +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + if (setup->i2c_address) { + normal_i2c[0] = setup->i2c_address; + codec->hw_write = (hw_write_t) i2c_master_send; + ret = i2c_add_driver(&aic3x_i2c_driver); + if (ret != 0) + printk(KERN_ERR "can't add i2c driver"); + } +#else + /* Add other interfaces here */ +#endif + return ret; +} + +static int aic3x_remove(struct platform_device *pdev) +{ + struct snd_soc_device *socdev = platform_get_drvdata(pdev); + struct snd_soc_codec *codec = socdev->codec; + + /* power down chip */ + if (codec->control_data) + aic3x_dapm_event(codec, SNDRV_CTL_POWER_D3); + + snd_soc_free_pcms(socdev); + snd_soc_dapm_free(socdev); +#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + i2c_del_driver(&aic3x_i2c_driver); +#endif + kfree(codec->private_data); + kfree(codec); + + return 0; +} + +struct snd_soc_codec_device soc_codec_dev_aic3x = { + .probe = aic3x_probe, + .remove = aic3x_remove, + .suspend = aic3x_suspend, + .resume = aic3x_resume, +}; +EXPORT_SYMBOL_GPL(soc_codec_dev_aic3x); + +MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver"); +MODULE_AUTHOR("Vladimir Barinov"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/tlv320aic3x.h b/sound/soc/codecs/tlv320aic3x.h new file mode 100644 index 0000000..d0cdeeb --- /dev/null +++ b/sound/soc/codecs/tlv320aic3x.h @@ -0,0 +1,181 @@ +/* + * ALSA SoC TLV320AIC3X codec driver + * + * Author: Vladimir Barinov, + * Copyright: (C) 2007 MontaVista Software, Inc., + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef _AIC3X_H +#define _AIC3X_H + +/* AIC3X register space */ +#define AIC3X_CACHEREGNUM 103 + +/* Page select register */ +#define AIC3X_PAGE_SELECT 0 +/* Software reset register */ +#define AIC3X_RESET 1 +/* Codec Sample rate select register */ +#define AIC3X_SAMPLE_RATE_SEL_REG 2 +/* PLL progrramming register A */ +#define AIC3X_PLL_PROGA_REG 3 +/* PLL progrramming register B */ +#define AIC3X_PLL_PROGB_REG 4 +/* PLL progrramming register C */ +#define AIC3X_PLL_PROGC_REG 5 +/* PLL progrramming register D */ +#define AIC3X_PLL_PROGD_REG 6 +/* Codec datapath setup register */ +#define AIC3X_CODEC_DATAPATH_REG 7 +/* Audio serial data interface control register A */ +#define AIC3X_ASD_INTF_CTRLA 8 +/* Audio serial data interface control register B */ +#define AIC3X_ASD_INTF_CTRLB 9 +/* Audio overflow status and PLL R value programming register */ +#define AIC3X_OVRF_STATUS_AND_PLLR_REG 11 + +/* ADC PGA Gain control registers */ +#define LADC_VOL 15 +#define RADC_VOL 16 +/* MIC3 control registers */ +#define MIC3LR_2_LADC_CTRL 17 +#define MIC3LR_2_RADC_CTRL 18 +/* Line1 Input control registers */ +#define LINE1L_2_LADC_CTRL 19 +#define LINE1R_2_RADC_CTRL 22 +/* Line2 Input control registers */ +#define LINE2L_2_LADC_CTRL 20 +#define LINE2R_2_RADC_CTRL 23 +/* MICBIAS Control Register */ +#define MICBIAS_CTRL 25 + +/* AGC Control Registers A, B, C */ +#define LAGC_CTRL_A 26 +#define LAGC_CTRL_B 27 +#define LAGC_CTRL_C 28 +#define RAGC_CTRL_A 29 +#define RAGC_CTRL_B 30 +#define RAGC_CTRL_C 31 + +/* DAC Power and Left High Power Output control registers */ +#define DAC_PWR 37 +#define HPLCOM_CFG 37 +/* Right High Power Output control registers */ +#define HPRCOM_CFG 38 +/* DAC Output Switching control registers */ +#define DAC_LINE_MUX 41 +/* High Power Output Driver Pop Reduction registers */ +#define HPOUT_POP_REDUCTION 42 +/* DAC Digital control registers */ +#define LDAC_VOL 43 +#define RDAC_VOL 44 +/* High Power Output control registers */ +#define LINE2L_2_HPLOUT_VOL 45 +#define LINE2R_2_HPROUT_VOL 62 +#define PGAL_2_HPLOUT_VOL 46 +#define PGAR_2_HPROUT_VOL 63 +#define DACL1_2_HPLOUT_VOL 47 +#define DACR1_2_HPROUT_VOL 64 +#define HPLOUT_CTRL 51 +#define HPROUT_CTRL 65 +/* High Power COM control registers */ +#define LINE2L_2_HPLCOM_VOL 52 +#define LINE2R_2_HPRCOM_VOL 69 +#define PGAL_2_HPLCOM_VOL 53 +#define PGAR_2_HPRCOM_VOL 70 +#define DACL1_2_HPLCOM_VOL 54 +#define DACR1_2_HPRCOM_VOL 71 +#define HPLCOM_CTRL 58 +#define HPRCOM_CTRL 72 +/* Mono Line Output Plus/Minus control registers */ +#define LINE2L_2_MONOLOPM_VOL 73 +#define LINE2R_2_MONOLOPM_VOL 76 +#define PGAL_2_MONOLOPM_VOL 74 +#define PGAR_2_MONOLOPM_VOL 77 +#define DACL1_2_MONOLOPM_VOL 75 +#define DACR1_2_MONOLOPM_VOL 78 +#define MONOLOPM_CTRL 79 +/* Line Output Plus/Minus control registers */ +#define LINE2L_2_LLOPM_VOL 80 +#define LINE2R_2_RLOPM_VOL 90 +#define PGAL_2_LLOPM_VOL 81 +#define PGAR_2_RLOPM_VOL 91 +#define DACL1_2_LLOPM_VOL 82 +#define DACR1_2_RLOPM_VOL 92 +#define LLOPM_CTRL 86 +#define RLOPM_CTRL 93 +/* Clock generation control register */ +#define AIC3X_CLKGEN_CTRL_REG 102 + +/* Page select register bits */ +#define PAGE0_SELECT 0 +#define PAGE1_SELECT 1 + +/* Audio serial data interface control register A bits */ +#define BIT_CLK_MASTER 0x80 +#define WORD_CLK_MASTER 0x40 + +/* Codec Datapath setup register 7 */ +#define FSREF_44100 (1 << 7) +#define FSREF_48000 (0 << 7) +#define DUAL_RATE_MODE ((1 << 5) | (1 << 6)) +#define LDAC2LCH (0x1 << 3) +#define RDAC2RCH (0x1 << 1) + +/* PLL registers bitfields */ +#define PLLP_SHIFT 0 +#define PLLR_SHIFT 0 +#define PLLJ_SHIFT 2 +#define PLLD_MSB_SHIFT 0 +#define PLLD_LSB_SHIFT 2 + +/* Clock generation register bits */ +#define PLL_CLKIN_SHIFT 4 +#define MCLK_SOURCE 0x0 +#define PLL_CLKDIV_SHIFT 0 + +/* Software reset register bits */ +#define SOFT_RESET 0x80 + +/* PLL progrramming register A bits */ +#define PLL_ENABLE 0x80 + +/* Route bits */ +#define ROUTE_ON 0x80 + +/* Mute bits */ +#define UNMUTE 0x08 +#define MUTE_ON 0x80 + +/* Power bits */ +#define LADC_PWR_ON 0x04 +#define RADC_PWR_ON 0x04 +#define LDAC_PWR_ON 0x80 +#define RDAC_PWR_ON 0x40 +#define HPLOUT_PWR_ON 0x01 +#define HPROUT_PWR_ON 0x01 +#define HPLCOM_PWR_ON 0x01 +#define HPRCOM_PWR_ON 0x01 +#define MONOLOPM_PWR_ON 0x01 +#define LLOPM_PWR_ON 0x01 +#define RLOPM_PWR_ON 0x01 + +#define INVERT_VOL(val) (0x7f - val) + +/* Default output volume (inverted) */ +#define DEFAULT_VOL INVERT_VOL(0x50) +/* Default input volume */ +#define DEFAULT_GAIN 0x20 + +struct aic3x_setup_data { + unsigned short i2c_address; +}; + +extern struct snd_soc_codec_dai aic3x_dai; +extern struct snd_soc_codec_device soc_codec_dev_aic3x; + +#endif /* _AIC3X_H */ diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c index 28684ee..f8797de 100644 --- a/sound/soc/codecs/wm8750.c +++ b/sound/soc/codecs/wm8750.c @@ -189,7 +189,7 @@ SOC_ENUM("Bass Boost", wm8750_enum[0]), SOC_ENUM("Bass Filter", wm8750_enum[1]), SOC_SINGLE("Bass Volume", WM8750_BASS, 0, 15, 1), -SOC_SINGLE("Treble Volume", WM8750_TREBLE, 0, 15, 0), +SOC_SINGLE("Treble Volume", WM8750_TREBLE, 0, 15, 1), SOC_ENUM("Treble Cut-off", wm8750_enum[2]), SOC_SINGLE("3D Switch", WM8750_3D, 0, 1, 0), diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c index 986b5d5..427cb61 100644 --- a/sound/soc/codecs/wm9712.c +++ b/sound/soc/codecs/wm9712.c @@ -102,7 +102,8 @@ SOC_SINGLE("Speaker Playback ZC Switch", AC97_MASTER, 7, 1, 0), SOC_SINGLE("Speaker Playback Invert Switch", AC97_MASTER, 6, 1, 0), SOC_SINGLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 7, 1, 0), SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_MONO, 7, 1, 0), -SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 0), +SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1), +SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1), SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), @@ -145,8 +146,8 @@ SOC_ENUM("Bass Control", wm9712_enum[5]), SOC_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1), SOC_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1), SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), -SOC_SINGLE("Bass Volume", AC97_MASTER_TONE, 8, 15, 0), -SOC_SINGLE("Treble Volume", AC97_MASTER_TONE, 0, 15, 0), +SOC_SINGLE("Bass Volume", AC97_MASTER_TONE, 8, 15, 1), +SOC_SINGLE("Treble Volume", AC97_MASTER_TONE, 0, 15, 1), SOC_SINGLE("Capture ADC Switch", AC97_REC_GAIN, 15, 1, 1), SOC_ENUM("Capture Volume Steps", wm9712_enum[6]), diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig index 5632a2e..14def2e 100644 --- a/sound/soc/s3c24xx/Kconfig +++ b/sound/soc/s3c24xx/Kconfig @@ -34,4 +34,12 @@ config SND_S3C24XX_SOC_SMDK2443_WM9710 Say Y if you want to add support for SoC audio on smdk2443 with the WM9710. +config SND_S3C24XX_SOC_LN2440SBC_ALC650 + tristate "SoC AC97 Audio support for LN2440SBC - ALC650" + depends on SND_S3C24XX_SOC + select SND_S3C2443_SOC_AC97 + select SND_SOC_AC97_CODEC + help + Say Y if you want to add support for SoC audio on ln2440sbc + with the ALC650. diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile index 13c92f0..9471919 100644 --- a/sound/soc/s3c24xx/Makefile +++ b/sound/soc/s3c24xx/Makefile @@ -10,6 +10,8 @@ obj-$(CONFIG_SND_S3C2443_SOC_AC97) += snd-soc-s3c2443-ac97.o # S3C24XX Machine Support snd-soc-neo1973-wm8753-objs := neo1973_wm8753.o snd-soc-smdk2443-wm9710-objs := smdk2443_wm9710.o +snd-soc-ln2440sbc-alc650-objs := ln2440sbc_alc650.o obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o obj-$(CONFIG_SND_S3C24XX_SOC_SMDK2443_WM9710) += snd-soc-smdk2443-wm9710.o +obj-$(CONFIG_SND_S3C24XX_SOC_LN2440SBC_ALC650) += snd-soc-ln2440sbc-alc650.o diff --git a/sound/soc/s3c24xx/ln2440sbc_alc650.c b/sound/soc/s3c24xx/ln2440sbc_alc650.c new file mode 100644 index 0000000..ec0d1a2 --- /dev/null +++ b/sound/soc/s3c24xx/ln2440sbc_alc650.c @@ -0,0 +1,86 @@ +/* + * SoC audio for ln2440sbc + * + * Copyright 2007 KonekTel, a.s. + * Author: Ivan Kuten + * ivan.kuten@promwad.com + * + * Heavily based on smdk2443_wm9710.c + * Copyright 2007 Wolfson Microelectronics PLC. + * Author: Graeme Gregory + * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../codecs/ac97.h" +#include "s3c24xx-pcm.h" +#include "s3c24xx-ac97.h" + +static struct snd_soc_machine ln2440sbc; + +static struct snd_soc_dai_link ln2440sbc_dai[] = { +{ + .name = "AC97", + .stream_name = "AC97 HiFi", + .cpu_dai = &s3c2443_ac97_dai[0], + .codec_dai = &ac97_dai, +}, +}; + +static struct snd_soc_machine ln2440sbc = { + .name = "LN2440SBC", + .dai_link = ln2440sbc_dai, + .num_links = ARRAY_SIZE(ln2440sbc_dai), +}; + +static struct snd_soc_device ln2440sbc_snd_ac97_devdata = { + .machine = &ln2440sbc, + .platform = &s3c24xx_soc_platform, + .codec_dev = &soc_codec_dev_ac97, +}; + +static struct platform_device *ln2440sbc_snd_ac97_device; + +static int __init ln2440sbc_init(void) +{ + int ret; + + ln2440sbc_snd_ac97_device = platform_device_alloc("soc-audio", -1); + if (!ln2440sbc_snd_ac97_device) + return -ENOMEM; + + platform_set_drvdata(ln2440sbc_snd_ac97_device, + &ln2440sbc_snd_ac97_devdata); + ln2440sbc_snd_ac97_devdata.dev = &ln2440sbc_snd_ac97_device->dev; + ret = platform_device_add(ln2440sbc_snd_ac97_device); + + if (ret) + platform_device_put(ln2440sbc_snd_ac97_device); + + return ret; +} + +static void __exit ln2440sbc_exit(void) +{ + platform_device_unregister(ln2440sbc_snd_ac97_device); +} + +module_init(ln2440sbc_init); +module_exit(ln2440sbc_exit); + +/* Module information */ +MODULE_AUTHOR("Ivan Kuten"); +MODULE_DESCRIPTION("ALSA SoC ALC650 LN2440SBC"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/s3c24xx/s3c2443-ac97.c b/sound/soc/s3c24xx/s3c2443-ac97.c index 75acf7e..96605b7 100644 --- a/sound/soc/s3c24xx/s3c2443-ac97.c +++ b/sound/soc/s3c24xx/s3c2443-ac97.c @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include #include @@ -253,7 +253,7 @@ static int s3c2443_ac97_probe(struct platform_device *pdev) ac_glbctrl |= S3C_AC97_GLBCTRL_TRANSFERDATAENABLE; writel(ac_glbctrl, s3c24xx_ac97.regs + S3C_AC97_GLBCTRL); - ret = request_irq(IRQ_S3C2443_AC97, s3c2443_ac97_irq, + ret = request_irq(IRQ_S3C244x_AC97, s3c2443_ac97_irq, IRQF_DISABLED, "AC97", NULL); if (ret < 0) { printk(KERN_ERR "s3c24xx-ac97: interrupt request failed.\n"); @@ -266,7 +266,7 @@ static int s3c2443_ac97_probe(struct platform_device *pdev) static void s3c2443_ac97_remove(struct platform_device *pdev) { - free_irq(IRQ_S3C2443_AC97, NULL); + free_irq(IRQ_S3C244x_AC97, NULL); clk_disable(s3c24xx_ac97.ac97_clk); clk_put(s3c24xx_ac97.ac97_clk); iounmap(s3c24xx_ac97.regs); diff --git a/sound/soc/s3c24xx/s3c24xx-ac97.h b/sound/soc/s3c24xx/s3c24xx-ac97.h index 2b835e8..bf03e8e 100644 --- a/sound/soc/s3c24xx/s3c24xx-ac97.h +++ b/sound/soc/s3c24xx/s3c24xx-ac97.h @@ -20,6 +20,12 @@ #define AC_CMD_ADDR(x) (x << 16) #define AC_CMD_DATA(x) (x & 0xffff) +#ifdef CONFIG_CPU_S3C2440 +#define IRQ_S3C244x_AC97 IRQ_S3C2440_AC97 +#else +#define IRQ_S3C244x_AC97 IRQ_S3C2443_AC97 +#endif + extern struct snd_soc_cpu_dai s3c2443_ac97_dai[]; #endif /*S3C24XXAC97_H_*/ diff --git a/sound/soc/sh/hac.c b/sound/soc/sh/hac.c index 8e3f039..34b77b9 100644 --- a/sound/soc/sh/hac.c +++ b/sound/soc/sh/hac.c @@ -105,7 +105,7 @@ static int hac_get_codec_data(struct hac_priv *hac, unsigned short r, unsigned int to1, to2, i; unsigned short adr; - for (i = 0; i < AC97_READ_RETRY; ++i) { + for (i = AC97_READ_RETRY; i; i--) { *v = 0; /* wait for HAC to receive something from the codec */ for (to1 = TMO_E4; @@ -132,7 +132,7 @@ static int hac_get_codec_data(struct hac_priv *hac, unsigned short r, udelay(21); } HACREG(HACRSR) &= ~(RSR_STDRY | RSR_STARY); - return (i < AC97_READ_RETRY); + return i; } static unsigned short hac_read_codec_aux(struct hac_priv *hac, @@ -141,7 +141,7 @@ static unsigned short hac_read_codec_aux(struct hac_priv *hac, unsigned short val; unsigned int i, to; - for (i = 0; i < AC97_READ_RETRY; i++) { + for (i = AC97_READ_RETRY; i; i--) { /* send_read_request */ local_irq_disable(); HACREG(HACTSR) &= ~(TSR_CMDAMT); @@ -159,10 +159,7 @@ static unsigned short hac_read_codec_aux(struct hac_priv *hac, break; } - if (i == AC97_READ_RETRY) - return ~0; - - return val; + return i ? val : ~0; } static void hac_ac97_write(struct snd_ac97 *ac97, unsigned short reg, @@ -172,7 +169,7 @@ static void hac_ac97_write(struct snd_ac97 *ac97, unsigned short reg, struct hac_priv *hac = &hac_cpu_data[unit_id]; unsigned int i, to; /* write_codec_aux */ - for (i = 0; i < AC97_WRITE_RETRY; i++) { + for (i = AC97_WRITE_RETRY; i; i--) { /* send_write_request */ local_irq_disable(); HACREG(HACTSR) &= ~(TSR_CMDDMT | TSR_CMDAMT); diff --git a/sound/sparc/amd7930.c b/sound/sparc/amd7930.c index 07962a3..b1d4315 100644 --- a/sound/sparc/amd7930.c +++ b/sound/sparc/amd7930.c @@ -859,7 +859,7 @@ static int snd_amd7930_put_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem spin_lock_irqsave(&amd->lock, flags); if (*swval != ucontrol->value.integer.value[0]) { - *swval = ucontrol->value.integer.value[0]; + *swval = ucontrol->value.integer.value[0] & 0xff; __amd7930_update_map(amd); change = 1; } else diff --git a/sound/sparc/dbri.c b/sound/sparc/dbri.c index 376b986..fc68317 100644 --- a/sound/sparc/dbri.c +++ b/sound/sparc/dbri.c @@ -2279,14 +2279,25 @@ static int snd_cs4215_put_volume(struct snd_kcontrol *kcontrol, struct snd_dbri *dbri = snd_kcontrol_chip(kcontrol); struct dbri_streaminfo *info = &dbri->stream_info[kcontrol->private_value]; + unsigned int vol[2]; int changed = 0; - if (info->left_gain != ucontrol->value.integer.value[0]) { - info->left_gain = ucontrol->value.integer.value[0]; + vol[0] = ucontrol->value.integer.value[0]; + vol[1] = ucontrol->value.integer.value[1]; + if (kcontrol->private_value == DBRI_PLAY) { + if (vol[0] > DBRI_MAX_VOLUME || vol[1] > DBRI_MAX_VOLUME) + return -EINVAL; + } else { + if (vol[0] > DBRI_MAX_GAIN || vol[1] > DBRI_MAX_GAIN) + return -EINVAL; + } + + if (info->left_gain != vol[0]) { + info->left_gain = vol[0]; changed = 1; } - if (info->right_gain != ucontrol->value.integer.value[1]) { - info->right_gain = ucontrol->value.integer.value[1]; + if (info->right_gain != vol[1]) { + info->right_gain = vol[1]; changed = 1; } if (changed) { diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c index fee869b..bfe17b3 100644 --- a/sound/spi/at73c213.c +++ b/sound/spi/at73c213.c @@ -536,16 +536,7 @@ out: return retval; } -static int snd_at73c213_mono_switch_info(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; - uinfo->count = 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = 1; - - return 0; -} +#define snd_at73c213_mono_switch_info snd_ctl_boolean_mono_info static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 7061438..1806f67 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -31,11 +31,11 @@ config SND_USB_USX2Y config SND_USB_CAIAQ tristate "Native Instruments USB audio devices" - depends on SND && USB - select SND_HWDEP - select SND_RAWMIDI - select SND_PCM - help + depends on SND && USB + select SND_HWDEP + select SND_RAWMIDI + select SND_PCM + help Say Y here to include support for caiaq USB audio interfaces, namely: diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c index 5e32969..1f1e91c 100644 --- a/sound/usb/usbmixer.c +++ b/sound/usb/usbmixer.c @@ -1703,6 +1703,11 @@ static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer, case 19: /* speaker out jacks */ case 20: /* headphones out jack */ break; + /* live24ext: 4 = line-in jack */ + case 3: /* hp-out jack (may actuate Mute) */ + if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) + snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); + break; default: snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid); break; @@ -1951,6 +1956,9 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) int i, err; for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { + if (i > 1 && /* Live24ext has 2 LEDs only */ + mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) + break; err = snd_ctl_add(mixer->chip->card, snd_ctl_new1(&snd_audigy2nx_controls[i], mixer)); if (err < 0) @@ -1963,28 +1971,42 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { - static const struct { + static const struct sb_jack { int unitid; const char *name; - } jacks[] = { + } jacks_audigy2nx[] = { {4, "dig in "}, {7, "line in"}, {19, "spk out"}, {20, "hph out"}, + {-1, NULL} + }, jacks_live24ext[] = { + {4, "line in"}, /* &1=Line, &2=Mic*/ + {3, "hph out"}, /* headphones */ + {0, "RC "}, /* last command, 6 bytes see rc_config above */ + {-1, NULL} }; + const struct sb_jack *jacks; struct usb_mixer_interface *mixer = entry->private_data; int i, err; u8 buf[3]; snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); - for (i = 0; i < ARRAY_SIZE(jacks); ++i) { + if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) + jacks = jacks_audigy2nx; + else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) + jacks = jacks_live24ext; + else + return; + + for (i = 0; jacks[i].name; ++i) { snd_iprintf(buffer, "%s: ", jacks[i].name); err = snd_usb_ctl_msg(mixer->chip->dev, usb_rcvctrlpipe(mixer->chip->dev, 0), GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, jacks[i].unitid << 8, buf, 3, 100); - if (err == 3 && buf[0] == 3) + if (err == 3 && (buf[0] == 3 || buf[0] == 6)) snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); else snd_iprintf(buffer, "?\n"); @@ -2022,7 +2044,8 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif) if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0) goto _error; - if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) { + if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) || + mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) { struct snd_info_entry *entry; if ((err = snd_audigy2nx_controls_create(mixer)) < 0) diff --git a/sound/usb/usbmixer_maps.c b/sound/usb/usbmixer_maps.c index 7c4dcb3..d755be0 100644 --- a/sound/usb/usbmixer_maps.c +++ b/sound/usb/usbmixer_maps.c @@ -187,6 +187,13 @@ static struct usbmix_selector_map audigy2nx_selectors[] = { { 0 } /* terminator */ }; +/* Creative SoundBlaster Live! 24-bit External */ +static struct usbmix_name_map live24ext_map[] = { + /* 2: PCM Playback Volume */ + { 5, "Mic Capture" }, /* FU, default PCM Capture Volume */ + { 0 } /* terminator */ +}; + /* LineX FM Transmitter entry - needed to bypass controls bug */ static struct usbmix_name_map linex_map[] = { /* 1: IT pcm */ @@ -273,6 +280,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = { .map = audigy2nx_map, .selector_map = audigy2nx_selectors, }, + { + .id = USB_ID(0x041e, 0x3040), + .map = live24ext_map, + }, { /* Hercules DJ Console (Windows Edition) */ .id = USB_ID(0x06f8, 0xb000),