22 Aug, 2016

1 commit

  • The quirk seems to be necessary not only for TEAC UD-H01 devices, but to
    more that are based on the Tenor 8802TL chipset. Devices built by T+A
    are affected too, and they apparently all use the same USB PID:PID.

    Extend the quirky handling for that device as well, and rename the
    quirks flag.

    Reported-and-tested-by: Thomas Gresens
    Signed-off-by: Daniel Mack
    Signed-off-by: Takashi Iwai

    Daniel Mack
     

01 Apr, 2016

1 commit

  • Unfortunately, this patch caused several regressions at au0828 and
    snd-usb-audio, like this one:
    https://bugzilla.kernel.org/show_bug.cgi?id=115561

    It also showed several troubles at the MC core that handles pretty
    poorly the memory protections and data lifetime management.

    So, better to revert it and fix the core before reapplying this
    change.

    This reverts commit aebb2b89bff0 ("[media] sound/usb: Use Media
    Controller API to share media resources")'

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     

04 Mar, 2016

1 commit

  • Change ALSA driver to use Media Controller API to share media resources
    with DVB and V4L2 drivers on a AU0828 media device. Media Controller
    specific initialization is done after sound card is registered. ALSA
    creates Media interface and entity function graph nodes for Control,
    Mixer, PCM Playback, and PCM Capture devices.

    snd_usb_hw_params() will call Media Controller enable source handler
    interface to request the media resource. If resource request is
    granted, it will release it from snd_usb_hw_free(). If resource is
    busy, -EBUSY is returned.

    Media specific cleanup is done in usb_audio_disconnect().

    Signed-off-by: Shuah Khan
    Acked-by: Takashi Iwai
    Signed-off-by: Mauro Carvalho Chehab

    Shuah Khan
     

19 Oct, 2015

1 commit

  • The Zoom R16/24 have a nonstandard playback format where each isochronous
    packet contains a length descriptor in the first four bytes. (Curiously,
    capture data does not contain this and requires no quirk.)

    The quirk involves adding the extra length descriptor whenever outgoing
    isochronous packets are generated, both in pcm.c (outgoing audio) and
    endpoint.c (silent data).

    In order to make the quirk as unintrusive as possible, for
    pcm.c:prepare_playback_urb(), the isochronous packet descriptors are
    initially set up in the same way no matter if the quirk is enabled or not.
    Once it is time to actually copy the data into the outgoing packet buffer
    (together with the added length descriptors) the isochronous descriptors
    are adjusted in order take the increased payload length into account.

    For endpoint.c:prepare_silent_urb() it makes more sense to modify the
    actual function, partly because the function is less complex to start with
    and partly because it is not as time-critical as prepare_playback_urb()
    (whose bulk is run with interrupts disabled), so the (minute) additional
    time spent in the non-quirk case is motivated by the simplicity of having
    a single function for all cases.

    The quirk is controlled by the new tx_length_quirk member in struct
    snd_usb_substream and struct snd_usb_audio, which is conveyed to pcm.c
    and endpoint.c from quirks.c in a similar manner to the txfr_quirk member
    in the same structs.

    In contrast to txfr_quirk however, the quirk is enabled directly in
    quirks.c:create_standard_audio_quirk() by checking the USB ID in that
    function. Another option would be to introduce a new
    QUIRK_AUDIO_ZOOM_INTERFACE or somesuch, which would have made the quirk
    very plain to see in the quirk table, but it was felt that the additional
    code needed to implement it this way would just make the implementation
    more complex with no real gain.

    Tested with a Zoom R16, both by doing capture and playback separately
    using arecord and aplay (8 channel capture and 2 channel playback,
    respectively), as well as capture and playback together using Ardour, as
    well as Audacity and Qtractor together with jackd.

    The R24 is reportedly compatible with the R16 when used as an audio
    interface. Both devices share the same USB ID and have the same number of
    inputs (8) and outputs (2). Therefore "R16/24" is mentioned throughout the
    patch.

    Regression tested using an Edirol UA-5 in both class compliant (16-bit)
    and "advanced" (24 bit, forces the use of quirks) modes.

    Signed-off-by: Ricard Wanderlof
    Tested-by: Panu Matilainen
    Signed-off-by: Takashi Iwai

    Ricard Wanderlof
     

09 Feb, 2015

1 commit

  • The first URBs are submitted during the prepare stage. When .trigger is
    called, the ALSA core saves a trigger tstamp that doesn't correspond to
    the actual time when the samples are submitted. The trigger_tstamp is
    now updated when the first data are submitted to avoid any time offsets.

    A usb-specific trigger_tstamp_pending_update flag is used for now,
    at some point the flag would need to move to the ALSA core, USB
    is not the only interface where silent block transfers are programmed
    as part of the prepare stage, with actual data enabled when .trigger
    is called.

    Signed-off-by: Pierre-Louis Bossart
    Signed-off-by: Takashi Iwai

    Pierre-Louis Bossart
     

03 May, 2014

1 commit

  • The TEAC UD-H01 firmware sends wrong feedback frequency values, thus
    causing the PC to send the samples at a wrong rate, which results in
    clicks and crackles in the output.

    Add a workaround to detect and fix the corruption.

    Signed-off-by: Clemens Ladisch
    [mick37@gmx.de: use sender->udh01_fb_quirk rather than
    ep->udh01_fb_quirk in snd_usb_handle_sync_urb()]
    Reported-and-tested-by: Mick
    Reported-and-tested-by: Andrea Messa
    Cc:
    Signed-off-by: Takashi Iwai

    Clemens Ladisch
     

07 Oct, 2013

1 commit

  • As Clemens Ladisch kindly explained:
    "Please note that there are two methods to identify alternate settings:
    the number, which is the value in bAlternateSetting, and the index,
    which is the index in the descriptor array. There might be some wording
    in the USB spec that these two values must be the same, but in reality,
    [insert standard rant about firmware writers], bAlternateSetting
    must be treated as a random ID value."

    This patch changes the name to express the correct usage semantics.
    No functional change.

    Signed-off-by: Eldad Zack
    Signed-off-by: Takashi Iwai

    Eldad Zack
     

26 Sep, 2013

1 commit

  • This patch changes the way URBs are allocated and their sizes are
    determined for PCM playback in the snd-usb-audio driver. Currently
    the driver allocates too few URBs for endpoints that don't use
    implicit sync, making underruns more likely to occur. This may be a
    holdover from before I/O delays could be measured accurately; in any
    case, it is no longer necessary.

    The patch allocates as many URBs as possible, subject to four
    limitations:

    The total number of URBs for the endpoint is not allowed to
    exceed MAX_URBS (which the patch increases from 8 to 12).

    The total number of packets per URB is not allowed to exceed
    MAX_PACKS (or MAX_PACKS_HS for high-speed devices), which is
    decreased from 20 to 6.

    The total duration of queued data is not allowed to exceed
    MAX_QUEUE, which is decreased from 24 ms to 18 ms.

    The total number of ALSA frames in the output queue is not
    allowed to exceed the ALSA buffer size.

    The last requirement is the hardest to implement. Currently the
    number of URBs needed to fill a buffer cannot be determined in
    advance, because a buffer contains a fixed number of frames whereas
    the number of frames in an URB varies to match shifts in the device's
    clock rate. To solve this problem, the patch changes the logic for
    deciding how many packets an URB should contain. Rather than using as
    many as possible without exceeding an ALSA period boundary, now the
    driver uses only as many packets as needed to transfer a predetermined
    number of frames. As a result, unless the device's clock has an
    exceedingly variable rate, the number of URBs making up each period
    (and hence each buffer) will remain constant.

    The overall effect of the patch is that playback works better in
    low-latency settings. The user can still specify values for
    frames/period and periods/buffer that exceed the capabilities of the
    hardware, of course. But for values that are within those
    capabilities, the performance will be improved. For example, testing
    shows that a high-speed device can handle 32 frames/period and 3
    periods/buffer at 48 KHz, whereas the current driver starts to get
    glitchy at 64 frames/period and 2 periods/buffer.

    A side effect of these changes is that the "nrpacks" module parameter
    is no longer used. The patch removes it.

    Signed-off-by: Alan Stern
    CC: Clemens Ladisch
    Tested-by: Daniel Mack
    Tested-by: Eldad Zack
    Signed-off-by: Takashi Iwai

    Alan Stern
     

28 Jun, 2013

1 commit


18 Apr, 2013

2 commits

  • There is quite some confusion around the bit-ordering in DSD samples,
    and no general agreement that defines whether hardware is supposed to
    expect the oldest sample in the MSB or the LSB of a byte.

    ALSA will hence set the rule that on the software API layer, bytes
    always carry the oldest bit in the most significant bit of a byte, and
    the driver has to translate that at runtime in order to match the
    hardware layout.

    This patch adds support for this by adding a boolean flag to the
    audio format struct.

    Signed-off-by: Daniel Mack
    Signed-off-by: Takashi Iwai

    Daniel Mack
     
  • In order to provide a compatibility way for pushing DSD
    samples through ordinary PCM channels, the "DoP open Standard" was
    invented. See http://www.dsd-guide.com for the official document.

    The host is required to stuff DSD marker bytes (0x05, 0xfa,
    alternating) in the MSB of 24 bit wide samples on the bus, in addition
    to the 16 bits of actual DSD sample payload.

    To support this, the hardware and software stride logic in the driver
    has to be tweaked a bit, as we make the userspace believe we're
    operating on 16 bit samples, while we in fact push one more byte per
    channel down to the hardware.

    The DOP runtime information is stored in struct snd_usb_substream, so
    we can keep track of our state across multiple calls to
    prepare_playback_urb_dsd_dop().

    Signed-off-by: Daniel Mack
    Signed-off-by: Takashi Iwai

    Daniel Mack
     

13 Apr, 2013

1 commit

  • When recording at 176.2KHz or 192Khz, the device adds a 32-bit length
    header to the capture packets, which obviously needs to be ignored for
    recording to work properly.

    Userspace expected: L0 L1 L2 R0 R1 R2
    ...but actually got: R2 L0 L1 L2 R0 R1

    Also, the last byte of the length header being interpreted as L0 of
    the first sample caused spikes every 0.5ms, resulting in a loud 16KHz
    tone (about the highest 'B' on a piano) being present throughout
    captures.

    Tested at all sample rates on an E-Mu 0404USB, and tested for
    regressions on a generic USB headset.

    Signed-off-by: Calvin Owens
    Cc:
    Signed-off-by: Takashi Iwai

    Calvin Owens
     

26 Nov, 2012

1 commit

  • Add the support for channel maps of the PCM streams on USB audio
    devices. The channel map information is already found in
    ChannelConfig descriptor entries, which haven't been referred until
    now.

    Each chmap entry is added to audioformat list entry and copied to TLV
    dynamically instead of creating a whole chmap array.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

30 Oct, 2012

1 commit

  • 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
    Cc:
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

19 Sep, 2012

2 commits

  • 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

    Takashi Iwai
     
  • 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
    Signed-off-by: Takashi Iwai

    Dylan Reid
     

04 Sep, 2012

1 commit

  • Playback Designs' USB devices have some hardware limitations on their
    USB interface. In particular:

    - They need a 20ms delay after each class compliant request as the
    hardware ACKs the USB packets before the device is actually ready
    for the next command. Sending data immediately will result in buffer
    overflows in the hardware.
    - The devices send bogus feedback data at the start of each stream
    which confuse the feedback format auto-detection.

    This patch introduces a new quirks hook that is called after each
    control packet and which adds a delay for all devices that match
    Playback Designs' USB VID for now.

    In addition, it adds a counter to snd_usb_endpoint to drop received
    packets on the floor. Another new quirks function that is called once
    an endpoint is started initializes that counter for these devices on
    their sync endpoint.

    Signed-off-by: Daniel Mack
    Reported-and-tested-by: Andreas Koch
    Supported-by: Demian Martin
    Signed-off-by: Takashi Iwai

    Daniel Mack
     

29 Aug, 2012

1 commit


08 Jun, 2012

1 commit

  • In 3.5 kernel, the endpoint is assigned dynamically for the
    substreams, but the PCM assignment still checks the presence of the
    endpoint pointer. This ended up in duplicated PCM substream creations
    at probing time, resulting in kernel warnings like:

    WARNING: at fs/proc/generic.c:586 proc_register+0x169/0x1a6()
    Pid: 1152, comm: modprobe Not tainted 3.5.0-rc1-00110-g71fae7e #2
    Call Trace:
    [] warn_slowpath_common+0x83/0x9c
    [] warn_slowpath_fmt+0x46/0x48
    [] ? add_preempt_count+0x39/0x3b
    [] proc_register+0x169/0x1a6
    [] create_proc_entry+0x74/0x8c
    [] snd_info_register+0x3e/0xc3 [snd]
    [] snd_pcm_new_stream+0xb1/0x404 [snd_pcm]
    [] snd_usb_add_audio_stream+0xd2/0x230 [snd_usb_audio]
    [] ? snd_usb_parse_audio_format+0x252/0x34f [snd_usb_audio]
    [] ? kmem_cache_alloc_trace+0xab/0xbb
    [] snd_usb_parse_audio_interface+0x4ac/0x567 [snd_usb_audio]
    [] snd_usb_create_stream+0xe9/0x125 [snd_usb_audio]
    [] usb_audio_probe+0x62a/0x72c [snd_usb_audio]
    .....

    This patch fixes the regression by checking the fixed endpoint number
    for each substream instead of the endpoint pointer.

    Reported-and-tested-by: Jamie Heilman
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

21 Apr, 2012

1 commit


13 Apr, 2012

3 commits

  • Many fields have been moved to struct snd_usb_endpoint.
    Also fix the proc output to correspond to the new structure.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     
  • 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
    Signed-off-by: Takashi Iwai

    Daniel Mack
     
  • This patch adds a new generic streaming logic for audio over USB.

    It defines a model (snd_usb_endpoint) that handles everything that
    is related to an USB endpoint and its streaming. There are functions to
    activate and deactivate an endpoint (which call usb_set_interface()),
    and to start and stop its URBs. It also has function pointers to be
    called when data was received or is about to be sent, and pointer to
    a sync slave (another snd_usb_endpoint) that is informed when data has
    been received.

    A snd_usb_endpoint knows about its state and implements a refcounting,
    so only the first user will actually start the URBs and only the last
    one to stop it will tear them down again.

    With this sort of abstraction, the actual streaming is decoupled from
    the pcm handling, which makes the "implicit feedback" mechanisms easy to
    implement.

    In order to split changes properly, this patch only adds the new
    implementation but leaves the old one around, so the the driver doesn't
    change its behaviour. The switch to actually use the new code is
    submitted separately.

    Signed-off-by: Daniel Mack
    Signed-off-by: Takashi Iwai

    Daniel Mack
     

15 Feb, 2012

1 commit

  • A malicious USB device could feed in a large nr_rates value. This would
    cause the subsequent call to kmemdup() to allocate a smaller buffer than
    expected, leading to out-of-bounds access.

    This patch validates the nr_rates value and reuses the limit introduced
    in commit 4fa0e81b ("ALSA: usb-audio: fix possible hang and overflow
    in parse_uac2_sample_rate_range()").

    Signed-off-by: Xi Wang
    Signed-off-by: Takashi Iwai

    Xi Wang
     

12 Sep, 2011

1 commit

  • 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
    [clemens: changed debug code]
    Signed-off-by: Clemens Ladisch
    Signed-off-by: Takashi Iwai

    Pierre-Louis Bossart
     

27 Oct, 2010

1 commit

  • There are two USB Audio Class specifications (v1 and v2), but neither of
    them clearly defines the feedback format for high-speed UAC v1 devices.
    Add to this whatever the Creative and M-Audio firmware writers have been
    smoking, and it becomes impossible to predict the exact feedback format
    used by a particular device.

    Therefore, automatically detect the feedback format by looking at the
    magnitude of the first received feedback value.

    Also, this allows us to get rid of some special cases for E-Mu devices.

    Signed-off-by: Clemens Ladisch
    Signed-off-by: Takashi Iwai

    Clemens Ladisch
     

01 Jun, 2010

1 commit

  • 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
    Signed-off-by: Takashi Iwai

    Daniel Mack
     

05 Mar, 2010

3 commits

  • In preparation for USB audio 2.0 support, change the audioformat
    structure so that it uses a bitmask to specify possible formats.

    Signed-off-by: Clemens Ladisch
    Signed-off-by: Takashi Iwai

    Clemens Ladisch
     
  • The snd_usb_substream::format field actually contains the index of the
    current alternate setting, so rename it to altset_idx to avoid
    confusion.

    Signed-off-by: Clemens Ladisch
    Signed-off-by: Takashi Iwai

    Clemens Ladisch
     
  • Clean up the usb audio driver by factoring out a lot of functions to
    separate files. Code for procfs, quirks, urbs, format parsers etc all
    got a new home now.

    Moved almost all special quirk handling to quirks.c and introduced new
    generic functions to handle them, so the exceptions do not pollute the
    whole driver.

    Renamed usbaudio.c to card.c because this is what it actually does now.
    Renamed usbmidi.c to midi.c for namespace clarity.
    Removed more things from usbaudio.h.

    The non-standard drivers were adopted accordingly.

    Signed-off-by: Daniel Mack
    Cc: Clemens Ladisch
    Signed-off-by: Takashi Iwai

    Daniel Mack