summaryrefslogtreecommitdiff
path: root/sound/usb/clock.c
AgeCommit message (Collapse)Author
2017-11-21ALSA: usb-audio: Add sanity checks in v2 clock parsersTakashi Iwai
The helper functions to parse and look for the clock source, selector and multiplier unit may return the descriptor with a too short length than required, while there is no sanity check in the caller side. Add some sanity checks in the parsers, at least, to guarantee the given descriptor size, for avoiding the potential crashes. Fixes: 79f920fbff56 ("ALSA: usb-audio: parse clock topology of UAC2 devices") Reported-by: Andrey Konovalov <andreyknvl@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-04-29ALSA: usb-audio: Limit retrying sample rate readsTakashi Iwai
There are many USB audio devices with buggy firmware that don't react with the sample rate reading properly. This often results in the flood of error messages and slowing down the operation. The sample rate read back is basically only for confirming the sample rate setup, and it's not critically important. As a compromise, in this patch, we stop the sample rate read back once when the device gives errors more than tolerance (twice, as of now). This should improve most of error cases while we still can catch the firmware bugginess. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2016-03-16ALSA: usb-audio: Add sanity checks for endpoint accessesTakashi Iwai
Add some sanity check codes before actually accessing the endpoint via get_endpoint() in order to avoid the invalid access through a malformed USB descriptor. Mostly just checking bNumEndpoints, but in one place (snd_microii_spdif_default_get()), the validity of iface and altsetting index is checked as well. Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=971125 Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-17ALSA: usb-audio: Don't attempt to get Lifecam HD-5000 sample rateJoe Turner
Adds a quirk to disable the check that the sample rate has been set correctly, as the Lifecam does not support getting the sample rate. This means that we don't need to wait for the USB timeout when attempting to get the sample rate. Waiting for the timeout causes problems in some applications, which give up on the device acquisition process before it has had time to complete, resulting in no sound. [minor tidy up by tiwai] Signed-off-by: Joe Turner <joe@oampo.co.uk> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2014-02-26ALSA: usb-audio: Use standard printk helpersTakashi Iwai
Convert with dev_err() and co from snd_printk(), etc. As there are too deep indirections (e.g. ep->chip->dev->dev), a few new local macros, usb_audio_err() & co, are introduced. Also, the device numbers in some messages are dropped, as they are shown in the prefix automatically. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-06-27ALSA: usb-audio: store protocol version in struct audioformatClemens Ladisch
Instead of reading bInterfaceProtocol from the descriptor whenever it's needed, store this value in the audioformat structure. Besides simplifying some code, this will allow us to correctly handle vendor- specific devices where the descriptors are marked with other values. Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
2013-04-26ALSA: usb - Avoid unnecessary sample rate changes on USB 2.0 clock sourcesDavid Henningsson
The Scarlett 2i2 seems to take almost 500 ms to set the sample rate, even if the clock is currently set to that value. This patch speeds up prepare of the device, by avoiding setting the clock to something it already is. Signed-off-by: David Henningsson <david.henningsson@canonical.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
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: UAC2: support read-only freq controlEldad Zack
Some clocks might be read-only, e.g., external clocks (see also UAC2 4.7.2.1). In this case, setting the sample frequency will always fail (even if the rate is equal to the current clock rate), therefore do not write, but read the value and compare to the requested rate. If the clock is read only, avoid reading it twice. If it doesn't match, return -ENXIO since the clock is invalid for this configuration. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-04ALSA: usb-audio: show err in set_sample_rate_v2 debugEldad Zack
Show the error code returned from the USB subsystem in the debug messages. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-04ALSA: usb-audio: UAC2: auto clock selection module paramEldad Zack
Add a module param to disable auto clock selection. This is provided for users that expect the audio stream to fail when the clock source is invalid (e.g., the word clock was unintentionally disconnected). Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-04ALSA: usb-audio: UAC2: try to find and switch to valid clockEldad Zack
If a selector is available on a device, it may be pointing to a clock source which is currently invalid. If there is a valid clock source which can be selected, switch to it. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-04ALSA: usb-audio: UAC2: do clock validity check earlierEldad Zack
Move the check that parse_audio_format_rates_v2() do after receiving the clock source entity ID directly into the find function and add a validation flag to the function. This patch does not introduce any logic flow change. It is provided to allow introducing automatic clock switching easier later. By moving this uac_clock_source_is_valid callsite, 2 additional callsites can be avoided. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-04ALSA: usb-audio: use endianness macrosEldad Zack
Replace the endianness conversions with the kernel-wide swabbing macros in get/set_sample_rate_v2. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-03ALSA: usb-audio: Clean up the code in set_sample_rate_v2()Takashi Iwai
Just for cleaning up, introduce a new function get_sample_rate_v2() for replacing two identical calls in set_sample_rate_v2(). No functional change. Signed-off-by: Takashi Iwai <tiwai@suse.de>
2013-04-03ALSA: usb: Work around CM6631 sample rate change bugTorstein Hegge
The C-Media CM6631 USB receiver doesn't respond to changes in sample rate while the interface is active. The same behavior is observed in other UAC2 hardware like the VIA VT1731. Reset the interface after setting the sampling frequency on sample rate changes, to ensure that the sample rate set by snd_usb_init_sample_rate() is used. Otherwise, the device will try to use the sample rate of the previous stream, causing distorted sound on sample rate changes. The reset is performed for all UAC2 devices, as it should not affect a standards compliant device, but it is only necessary for C-Media CM6631, VIA VT1731 and possibly others. Failure to read sample rate from the device is not handled as an error in set_sample_rate_v2(), as (permanent or intermittent) failure to read sample rate isn't essential for a successful sample rate set. Signed-off-by: Torstein Hegge <hegge@resisty.net> Acked-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2012-08-01ALSA: snd-usb: fix clock source validity indexDaniel Mack
uac_clock_source_is_valid() uses the control selector value to access the bmControls bitmap of the clock source unit. This is wrong, as control selector values start from 1, while the bitmap uses all available bits. In other words, "Clock Validity Control" is stored in D3..2, not D5..4 of the clock selector unit's bmControls. Signed-off-by: Daniel Mack <zonque@gmail.com> Reported-by: Andreas Koch <andreas@akdesigninc.com> Cc: stable@kernel.org 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-05-18ALSA: usb-audio: assume valid clockDaniel Mack
If the interface can't report a clock's validity, assume that it's valid. Signed-off-by: Daniel Mack <zonque@gmail.com> Reported-by: Vicente Joel <vicentejoel@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-09-03ALSA: usb-audio: fix detection of vendor-specific device protocol settingsClemens Ladisch
The Audio Class v2 support code in 2.6.35 added checks for the bInterfaceProtocol field. However, there are devices (usually those detected by vendor-specific quirks) that do not have one of the predefined values in this field, which made the driver reject them. To fix this regression, restore the old behaviour, i.e., assume that a device with an unknown bInterfaceProtocol field (other than UAC_VERSION_2) has more or less UAC-v1-compatible descriptors. [compile warning fixes by tiwai] Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Cc: Daniel Mack <daniel@caiaq.de> Cc: <stable@kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-07-09ALSA: usb-audio: silence a superfluous warningClemens Ladisch
It is not advisable to print a warning when a device does not support setting the sample rate because this is perfectly valid for devices with a single rate or where rates are implicitly changed by selecting another alternate setting. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-06-23ALSA: usb-audio: simplify control interface accessDaniel Mack
As the control interface is now carried in struct snd_usb_audio, we can simplify the API a little and also drop the private ctrlif field from struct usb_mixer_interface. Also remove a left-over function prototype in pcm.h. Signed-off-by: Daniel Mack <daniel@caiaq.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-06-23ALSA: usb-audio: move and add some commentsDaniel Mack
Also add a list of open topics. Signed-off-by: Daniel Mack <daniel@caiaq.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-06-23ALSA: usb-audio: clean up includes in clock.cDaniel Mack
Signed-off-by: Daniel Mack <daniel@caiaq.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-06-11ALSA: usb-audio: fix control messages for USB_RECIP_INTERFACEDaniel Mack
Control messages directed to an interface must have the interface number set in the lower 8 bits of wIndex. This wasn't done correctly for some clock and mixer messages. Signed-off-by: Daniel Mack <daniel@caiaq.de> Reported-by: Alex Lee <alexlee188@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
2010-05-31ALSA: usb-audio: parse clock topology of UAC2 devicesDaniel Mack
Audio devices which comply to the UAC2 standard can export complex clock topologies in its descriptors and set up links between them. The entities that are defined are - clock sources, which define the end-leafs. - clock selectors, which act as switch to select one out of many possible clocks sources. - clock multipliers, which have an input clock source, and act as clock source again. They can be used to derive one clock from another. All sample rate changes, clock validity queries and the like must go to clock source elements, while clock selectors and multipliers can be used as terminal clock source. The following patch adds a parser for these elements and functions to iterate over the tree and find the leaf nodes (clock sources). The samplerate set functions were moved to the new clock.c file. Signed-off-by: Daniel Mack <daniel@caiaq.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>