aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/pcm.c
AgeCommit message (Collapse)Author
2013-04-10ALSA: snd-usb: Playback Design: use usb_set_inferface quirk from more locationsDaniel Mack
It turns out the devices from Playback Design need the delay quirk after usb_set_interface from clocks.c as well. Make it a proper quirks function and factor out the code to quirks.c. Signed-off-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-04ALSA: usb-audio: spelling correctionEldad Zack
Correct spelling of snd_usb_endpoint_implict_feedback_sink in all occurances. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-04ALSA: usb-audio: convert list_for_each to entry variantEldad Zack
Change occurances of list_for_each into list_for_each_entry where applicable. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-03-18ALSA: snd-usb: add delay quirk for "Playback Design" productsDaniel Mack
"Playback Design" products need a 50ms delay after setting the USB interface. Signed-off-by: Daniel Mack <zonque@gmail.com> Reported-by: Andreas Koch <andreas@akdesigninc.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-02-11ALSA: usb-audio: add support for M-Audio FT C600Matt Gruskin
Adds quirks and mixer support for the M-Audio Fast Track C600 USB audio interface. This device is very similar to the C400 - the C600 simply has some more inputs and outputs, so the existing C400 support is extended to support this device as well. Signed-off-by: Matt Gruskin <matthew.gruskin@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-01-25ALSA: Make snd_printd() and snd_printdd() inlineTakashi Iwai
Because currently snd_printd() and snd_printdd() macros are expanded to empty when CONFIG_SND_DEBUG=n, a compile warning like below appears sometimes, and we had to covert it by ugly ifdefs: sound/pci/hda/patch_sigmatel.c: In function ‘stac92hd71bxx_fixup_hp’: sound/pci/hda/patch_sigmatel.c:2434:24: warning: unused variable ‘spec’ [-Wunused-variable] For "fixing" these issues better, this patch replaces snd_printd() and snd_printdd() definitions with empty inline functions instead of macros. This should have the same effect but shut up warnings like above. But since we had already put ifdefs, changing to inline functions would trigger compile errors. So, such ifdefs is removed in this patch. In addition, snd_pci_quirk name field is defined only when CONFIG_SND_DEBUG_VERBOSE is set, and the reference to it in snd_printdd() argument triggers the build errors, too. For avoiding these errors, introduce a new macro snd_pci_quirk_name() that is defined no matter how the debug option is set. Reported-by: Stratos Karafotis <stratosk@semaphore.gr> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-01-23Merge branch 'for-linus' into for-nextTakashi Iwai
This is a preliminary merge before the upcoming merge of generic parser branch.
2013-01-11ALSA: usb-audio: Fix NULL dereference by access to non-existing substreamTakashi Iwai
The commit [0d9741c0: ALSA: usb-audio: sync ep init fix for audioformat mismatch] introduced the correction of parameters to be set for sync EP. But since the new code assumes that the sync EP is always paired with the data EP of another direction, it triggers Oops when a device only with a single direction is used. This patch adds a proper check of sync EP type and the presence of the paired substream for avoiding the crash. Reported-and-tested-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-12-24ALSA: usb-audio: support delay calculation on capture streamsPierre-Louis Bossart
Enable delay report on capture path. The delay is reset when an URB is retired and increment at each call to .pointer based on frame counter changes. The precision of the delay information is limited to 1ms as in the playback case. This reverts commit 3f94fad09538ec988919ec3f371841182df71d04. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-12-04ALSA: usb-audio: sync ep init fix for audioformat mismatchEldad Zack
Commit 947d299686aa9cc8aecf749d54e8475c6e498956 , "ALSA: snd-usb: properly initialize the sync endpoint", while correcting the initialization of the sync endpoint when opening just the data endpoint, prevents devices that has a sync endpoint, with a channel number different than that of the data endpoint, from functioning. Due to a different channel and period bytes count, attempting to initialize the sync endpoint will fail at the usb host driver. For example, when using xhci: cannot submit urb 0, error -90: internal error With this patch, if a sync endpoint has multiple audioformats, a matching audioformat is preferred. An audioformat must be found with at least one channel and support the requested sample rate and PCM format, otherwise the stream will not be opened. If the number of channels differ between the selected audioformat and the requested format, adjust the period bytes count accordingly. It is safe to perform the calculation on the basis of the channel count, since the requested PCM audio format and the rate must be supported by the selected audioformat. Cc: Jeffrey Barish <jeff_barish@earthlink.net> Cc: Daniel Mack <zonque@gmail.com> Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-29ALSA: usb-audio: FT C400 sync playback EP to capture EPEldad Zack
The playback endpoint uses implicit feedback mode, similar to the M-Audio FTU. Like with the FTU, we need to associate the sync pipe ourselves. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-29ALSA: usb-audio: replace hardcoded value with constEldad Zack
In this context, 0x01 is USB_ENDPOINT_XFER_ISOC. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-23ALSA: usb-audio: fix delay account during pauseTakashi Iwai
When a playback stream is paused, the stream isn't actually stopped, thus we still need to take care of the in-flight data amount for the delay calculation. Otherwise the value of subs->last_delay is no longer reliable and can give a bogus value after resuming from pause. This will result in "delay: estimated XX, actual YY" error messages. Also, during pause after all in flight data are processed (i.e. last_delay = 0), we don't have to calculate the actual delay from the current frame. Give a short path in such a case. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-23ALSA: usb-audio: ignore delay calculation for capture streamTakashi Iwai
It doesn't make sense to calculate the delay for capture streams in the current implementation. It's always zero, so we should skip the computation in snd_usb_pcm_pointer() in the case of capture. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-22Merge branch 'for-linus' into for-nextTakashi Iwai
2012-11-22ALSA: snd-usb: properly initialize the sync endpointDaniel Mack
Jeffrey Barish reported an obvious bug in the pcm part of the usb-audio driver which causes the code to not initialize the sync endpoint from configure_endpoint(). Reported-by: Jeffrey Barish <jeff_barish@earthlink.net> Signed-off-by: Daniel Mack <zonque@gmail.com> Cc: stable@kernel.org [3.5+] Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-21ALSA: usb-audio: process pending stop at PCM hw_free and closeTakashi Iwai
PCM hw_free and close should wait until all the pending stop operations have been finished. Basically only PCM trigger callback should use non-wait calls. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-21ALSA: usb-audio: stop both data and sync endpoints asynchronouslyTakashi Iwai
As we are stopping the endpoints asynchronously now, it's better to trigger the stop of both data and sync endpoints and wait for pending stopping operations, instead of the sequential trigger-and-wait procedure. So the wait argument in snd_usb_endpoint_stop() is dropped, and it's expected that the caller synchronizes explicitly by calling snd_usb_endpoint_sync_pending_stop(). (Actually there is only one place calling this, so it was safe to change.) Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-21ALSA: usb-audio: simplify snd_usb_endpoint_start/stop argumentsTakashi Iwai
Reduce the redundant arguments for snd_usb_endpoint_start() and snd_usb_endpoint_stop(). Also replaced from int to bool. No functional changes by this commit. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-11-08Merge branch 'for-linus' into for-nextTakashi Iwai
2012-11-08ALSA: usb-audio: Fix crash at re-preparing the PCM streamTakashi Iwai
There are bug reports of a crash with USB-audio devices when PCM prepare is performed immediately after the stream is stopped via trigger callback. It turned out that the problem is that we don't wait until all URBs are killed. This patch adds a new function to synchronize the pending stop operation on an endpoint, and calls in the prepare callback for avoiding the crash above. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=49181 Reported-and-tested-by: Artem S. Tashkinov <t.artem@lycos.com> Cc: <stable@vger.kernel.org> [v3.6] Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-10-30Merge branch 'for-linus' into for-nextTakashi Iwai
... for migrating the core changes for USB-audio disconnection fixes
2012-10-30ALSA: usb-audio: Use rwsem for disconnect protectionTakashi Iwai
Replace mutex with rwsem for codec->shutdown protection so that concurrent accesses are allowed. Also add the protection to snd_usb_autosuspend() and snd_usb_autoresume(), too. Reported-by: Matthieu CASTET <matthieu.castet@parrot.com> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-10-30ALSA: usb-audio: Fix races at disconnectionTakashi Iwai
Close some races at disconnection of a USB audio device by adding the chip->shutdown_mutex and chip->shutdown check at appropriate places. The spots to put bandaids are: - PCM prepare, hw_params and hw_free - where the usb device is accessed for communication or get speed, in mixer.c and others; the device speed is now cached in subs->speed instead of accessing to chip->dev The accesses in PCM open and close don't need the mutex protection because these are already handled in the core PCM disconnection code. The autosuspend/autoresume codes are still uncovered by this patch because of possible mutex deadlocks. They'll be covered by the upcoming change to rwsem. Also the mixer codes are untouched, too. These will be fixed in another patch, too. Reported-by: Matthieu CASTET <matthieu.castet@parrot.com> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-10-21ALSA: snd-usb: remove unused variable in init_pitch_v2()Wei Yongjun
The variable ep is initialized but never used otherwise, so remove the unused variable. dpatch engine is used to auto generate this patch. (https://github.com/weiyj/dpatch) Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-09-19ALSA: usb-audio: Avoid unnecessary EP setups in prepareTakashi Iwai
The recent fix for USB suspend breakage moved the code to set up EP from hw_params to prepare, but it means also the EP setup might be called multiple times unnecessarily because the prepare callback can be called multiple times without starting the stream (e.g. OSS emulation). This patch adds a new flag to struct snd_usb_substream indicating whether the setup of EP is required, and do it only when necessary, i.e. right after hw_params or suspend. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-09-19ALSA: usb-audio: Move configuration to prepare.Dylan Reid
Move interface and endpoint configuration from hw_params to prepare callback. During system suspend/resume when the USB device power isn't cycled the interface and endpoint configuration need to be set before audio playback can continue. Resume involves another call to prepare but not to hw_params, moving it here allows a playing stream to continue after resume. Signed-off-by: Dylan Reid <dgreid@chromium.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-09-19ALSA: usb-audio: Don't require hw_params in endpoint.Dylan Reid
Change the interface to configure an endpoint so that it doesn't require a hw_params struct. This will allow it to be called from prepare instead of hw_params, configuring it after system resume. Signed-off-by: Dylan Reid <dgreid@chromium.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-09-19ALSA: usb-audio: set period_bytes in substream.Dylan Reid
Set the peiod_bytes member of snd_usb_substream. It was no longer being set, but will be needed to resume properly in a future commit. Signed-off-by: Dylan Reid <dgreid@chromium.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-09-06ALSA: usb-audio: Fix bogus error messages for delay accountingTakashi Iwai
The recent fix for the missing fine delayed time adjustment gives strange error messages at each start of the playback stream, such as delay: estimated 0, actual 352 delay: estimated 353, actual 705 These come from the sanity check in retire_playback_urb(). Before the stream is activated via start_endpoints(), a few silent packets have been already sent. And at this point the delay account is still in the state as if the new packets are just queued, so the driver gets confused and spews the bogus error messages. For fixing the issue, we just need to check whether the received packet is valid, whether it's zero sized or not. Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de> Cc: <stable@vger.kernel.org> [v3.5+] Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-31ALSA: snd-usb: fix cross-interface streaming devicesDaniel Mack
Commit 68e67f40b ("ALSA: snd-usb: move calls to usb_set_interface") saved us some unnecessary calls to snd_usb_set_interface() but ignored the fact that there is at least one device out there which operates on two endpoint in different interfaces simultaniously. Take care for this by catching the case where data and sync endpoints are located on different interfaces and calling snd_usb_set_interface() between the start of the two endpoints. Signed-off-by: Daniel Mack <zonque@gmail.com> Reported-by: Robert M. Albrecht <linux@romal.de> Cc: stable@kernel.org [v3.5+] Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-31ALSA: snd-usb: fix calls to next_packet_sizeDaniel Mack
In order to support devices with implicit feedback streaming models, packet sizes are now stored with each individual urb, and the PCM handling code which fills the buffers purely relies on the size fields now. However, calling snd_usb_audio_next_packet_size() for all possible packets in an URB at once, prior to letting the PCM code do its job does in fact not lead to the same behaviour than what the old code did: The PCM code will break its loop once a period boundary is reached, consequently using up less packets that it really could. As snd_usb_audio_next_packet_size() implements a feedback mechanism to the endpoints phase accumulator, the number of calls to that function matters, and when called too often, the data rate runs out of bounds. Fix this by making the next_packet function public, and call it from the PCM code as before if the packet data sizes are not defined. Signed-off-by: Daniel Mack <zonque@gmail.com> Cc: stable@kernel.org [v3.5+] Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-31ALSA: snd-usb: restore delay informationDaniel Mack
Parts of commit 294c4fb8 ("ALSA: usb: refine delay information with USB frame counter") were unfortunately lost during the refactoring of the snd-usb driver in 3.5. This patch adds them back, restoring the correct delay information behaviour. Signed-off-by: Daniel Mack <zonque@gmail.com> Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Cc: stable@kernel.org [3.5+] Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-30ALSA: snd-usb: Fix URB cancellation at stream startDaniel Mack
Commit e9ba389c5 ("ALSA: usb-audio: Fix scheduling-while-atomic bug in PCM capture stream") fixed a scheduling-while-atomic bug that happened when snd_usb_endpoint_start was called from the trigger callback, which is an atmic context. However, the patch breaks the idea of the endpoints reference counting, which is the reason why the driver has been refactored lately. Revert that commit and let snd_usb_endpoint_start() take care of the URB cancellation again. As this function is called from both atomic and non-atomic context, add a flag to denote whether the function may sleep. Signed-off-by: Daniel Mack <zonque@gmail.com> Cc: stable@kernel.org [3.5+] Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-16ALSA: usb-audio: Fix scheduling-while-atomic bug in PCM capture streamTakashi Iwai
A PCM capture stream on usb-audio causes a scheduling-while-atomic BUG, as reported in the bugzilla entry below. It's because snd_usb_endpoint_start() is called at first at trigger START for a capture stream, and this function contains the left-over EP deactivation codes. The problem doesn't happen for a playback stream because the function is called at PCM prepare time, which can sleep. This patch fixes the BUG by moving the EP deactivation code into the PCM prepare callback. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=46011 Cc: <stable@vger.kernel.org> [v3.5+] Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-07-13ALSA: snd-usb: move calls to usb_set_interfaceDaniel Mack
The rework of the snd-usb endpoint logic moved the calls to snd_usb_set_interface() into the snd_usb_endpoint implemenation. This changed the order in which these calls are issued to the device, and thereby caused regressions for some webcams. Fix this by moving the calls back to pcm.c for now to make it work again and use snd_usb_endpoint_activate() to really tear down all remaining URBs in the flight, consequently fixing another regression caused by USB packets on the wire after altsetting 0 has been selected. Signed-off-by: Daniel Mack <zonque@gmail.com> Reported-and-tested-by: Philipp Dreimann <philipp@dreimann.net> Reported-by: Joseph Salisbury <joseph.salisbury@canonical.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-07-06ALSA: usb-audio: Fix the first PCM interface assignmentTakashi Iwai
In the new PCM streaming logic, the interface number is assigned to usb stream instance (subs->interface) after the format and rate setups are succeeded, but some codes are still passing subs->interface as the reference to helper functions. This leads to initializing with an invalid iface number (-1). This patch replaces the wrong references with the ones from the target fmt correctly. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-06-18ALSA: snd-usb: make snd_usb_substream_capture_trigger staticDaniel Mack
Signed-off-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-06-18ALSA: snd-usb: fix sync pipe checkDaniel Mack
Fix a bogus sanity check for sync pipe in pcm.c. This flaw was introduced during the streaming logic refactorization. While at it, improve the error messages that are generated in such cases. Signed-off-by: Daniel Mack <zonque@gmail.com> Reported-and-tested-by: <ben@b1c1l1.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-05-31ALSA: usb-audio: fix rate_list memory leakClemens Ladisch
The array of sample rates is reallocated every time when opening the PCM device, but was freed only once when unplugging the device. Reported-by: "Alexander E. Patrakov" <patrakov@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-05-21ALSA: snd-usb: fix stream info output in /procDaniel Mack
Set some substream struct members to make the proc interface code work again. Signed-off-by: Daniel Mack <zonque@gmail.com> Reported-by: Felix Homann <linuxaudio@showlabor.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-04-13ALSA: snd-usb: add support for implicit feedbackDaniel Mack
Implicit feedback is a streaming mode that does not rely on dedicated sync endpoints but uses the information provided by record streams to clock output streams. Now that the streaming logic is decoupled from the PCM streams, this is easy to implement. Signed-off-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-04-13ALSA: snd-usb: switch over to new endpoint streaming logicDaniel Mack
With the previous commit that added the new streaming model, all endpoint and streaming related code is now in endpoint.c, and pcm.c only acts as a wrapper for handling the packet's payload. Signed-off-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-03-15ALSA: usb-audio - Fix build error by consitification of rate listTakashi Iwai
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-09-27ALSA: usb-audio: increase control transfer timeoutClemens Ladisch
There are certain devices that are reportedly so slow that they need more than 100 ms to handle control transfers. Therefore, increase the timeout in mixer(_quirks).c to 1000 ms. The timeout parameter of snd_usb_ctl_msg() is now constant, so we can drop it. Reported-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-09-14ALSA: snd-usb: move code from urb.c to endpoint.cDaniel Mack
No code altered at this point, simply preparing for upcoming refactorizations. Signed-off-by: Daniel Mack <zonque@gmail.com> Acked-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-09-12ALSA: usb: refine delay information with USB frame counterPierre-Louis Bossart
Existing code only updates the audio delay when URBs were submitted/retired. This can introduce an uncertainty of 8ms on the number of samples played out with the default settings, and a lot more when URBs convey more packets to reduce the interrupt rate and power consumption. This patch relies on the USB frame counter to reduce the uncertainty to less than 2ms worst-case. The delay information essentially becomes independent of the URB size and number of packets. This should help applications like PulseAudio which require accurate audio timing. Clemens Ladisch reported a decrease of mplayer's A-V difference from nrpacks down to at most 1ms. Thanks to Clemens for also pointing out that the implementation of frame counters varies between different HCDs. Only the 8 lowest-bits are used to estimate the delay. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> [clemens: changed debug code] Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-03-11ALSA: usbaudio: implement USB autosuspendOliver Neukum
Devices are autosuspended if no pcm nor midi channel is open Mixer devices may be opened. This way they are active when in use to play or record sound, but can be suspended while users have a mixer application running. [Small clean-ups using static inline by tiwai] Signed-off-by: Oliver Neukum <oneukum@suse.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-02-23ALSA: usb-audio: fix oops due to cleanup race when disconnectingTakashi Iwai
When a USB audio device is disconnected, snd_usb_audio_disconnect() kills all audio URBs. At the same time, the application, after being notified of the disconnection, might close the device, in which case ALSA calls the .hw_free callback, which should free the URBs too. Commit de1b8b93a0ba "[ALSA] Fix hang-up at disconnection of usb-audio" prevented snd_usb_hw_free() from freeing the URBs to avoid a hang that resulted from this race, but this introduced another race because the URB callbacks could now be executed after snd_usb_hw_free() has returned, and try to access already freed data. Fix the first race by introducing a mutex to serialize the disconnect callback and all PCM callbacks that manage URBs (hw_free and hw_params). Reported-and-tested-by: Pierre-Louis Bossart <pierre-louis.bossart@intel.com> Cc: <stable@kernel.org> [CL: also serialize hw_params callback] Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-11-01ALSA: usb - driver neglects kmalloc return value check and may deref NULLJesper Juhl
sound/usb/pcm.c::snd_usb_pcm_check_knot() fails to check the return value from kmalloc() and may end up dereferencing a null pointer. The patch below (compile tested only) should take care of that little problem. Signed-off-by: Jesper Juhl <jj@chaosbits.net> Signed-off-by: Takashi Iwai <tiwai@suse.de>