10 May, 2016

1 commit


29 Apr, 2016

1 commit

  • 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

    Takashi Iwai
     

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
     

16 Nov, 2015

1 commit

  • The CH345 USB MIDI chip has two output ports. However, they are
    multiplexed through one pin, and the number of ports cannot be reduced
    even for hardware that implements only one connector, so for those
    devices, data sent to either port ends up on the same hardware output.
    This becomes a problem when both ports are used at the same time, as
    longer MIDI commands (such as SysEx messages) are likely to be
    interrupted by messages from the other port, and thus to get lost.

    It would not be possible for the driver to detect how many ports the
    device actually has, except that in practice, _all_ devices built with
    the CH345 have only one port. So we can just ignore the device's
    descriptors, and hardcode one output port.

    Signed-off-by: Clemens Ladisch
    Cc: stable@vger.kernel.org
    Signed-off-by: Takashi Iwai

    Clemens Ladisch
     

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
     

26 Aug, 2015

2 commits

  • We can use active refcount for preventing autopm during probe.

    Signed-off-by: Takashi Iwai

    Takashi Iwai
     
  • After the recent fix of runtime PM for USB-audio driver, we got a
    lockdep warning like:

    =============================================
    [ INFO: possible recursive locking detected ]
    4.2.0-rc8+ #61 Not tainted
    ---------------------------------------------
    pulseaudio/980 is trying to acquire lock:
    (&chip->shutdown_rwsem){.+.+.+}, at: [] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]
    but task is already holding lock:
    (&chip->shutdown_rwsem){.+.+.+}, at: [] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]

    This comes from snd_usb_autoresume() invoking down_read() and it's
    used in a nested way. Although it's basically safe, per se (as these
    are read locks), it's better to reduce such spurious warnings.

    The read lock is needed to guarantee the execution of "shutdown"
    (cleanup at disconnection) task after all concurrent tasks are
    finished. This can be implemented in another better way.

    Also, the current check of chip->in_pm isn't good enough for
    protecting the racy execution of multiple auto-resumes.

    This patch rewrites the logic of snd_usb_autoresume() & co; namely,
    - The recursive call of autopm is avoided by the new refcount,
    chip->active. The chip->in_pm flag is removed accordingly.
    - Instead of rwsem, another refcount, chip->usage_count, is introduced
    for tracking the period to delay the shutdown procedure. At
    the last clear of this refcount, wake_up() to the shutdown waiter is
    called.
    - The shutdown flag is replaced with shutdown atomic count; this is
    for reducing the lock.
    - Two new helpers are introduced to simplify the management of these
    refcounts; snd_usb_lock_shutdown() increases the usage_count, checks
    the shutdown state, and does autoresume. snd_usb_unlock_shutdown()
    does the opposite. Most of mixer and other codes just need this,
    and simply returns an error if it receives an error from lock.

    Fixes: 9003ebb13f61 ('ALSA: usb-audio: Fix runtime PM unbalance')
    Reported-and-tested-by: Alexnader Kuleshov
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

03 May, 2014

1 commit

  • The recent addition of the USB audio mixer suspend/resume may lead to
    deadlocks when the driver tries to call usb_autopm_get_interface()
    recursively, since the function tries to sync with the finish of the
    other calls. For avoiding it, introduce a flag indicating the resume
    operation and avoids the recursive usb_autopm_get_interface() calls
    during the resume.

    Reported-and-tested-by: Bryan Quigley
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

26 Feb, 2014

1 commit

  • 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

    Takashi Iwai
     

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

  • Add quirks to detect the various vendor-specific descriptors used by
    Roland and Yamaha in most of their recent USB audio and MIDI devices.

    Together with the previous patch, this should add audio/MIDI support for
    the following USB devices:
    - Edirol motion dive .tokyo performance package
    - Roland MC-808 Synthesizer
    - Roland BK-7m Synthesizer
    - Roland VIMA JM-5/8 Synthesizer
    - Roland SP-555 Sequencer
    - Roland V-Synth GT Synthesizer
    - Roland Music Atelier AT-75/100/300/350C/500/800/900/900C Organ
    - Edirol V-Mixer M-200i/300/380/400/480/R-1000
    - BOSS GT-10B Effects Processor
    - Roland Fantom G6/G7/G8 Keyboard
    - Cakewalk Sonar V-Studio 20/100/700 Audio Interface
    - Roland GW-8 Keyboard
    - Roland AX-Synth Keyboard
    - Roland JUNO-Di/STAGE/Gi Keyboard
    - Roland VB-99 Effects Processor
    - Cakewalk UM-2G MIDI Interface
    - Roland A-500S Keyboard
    - Roland SD-50 Synthesizer
    - Roland OCTAPAD SPD-30 Controller
    - Roland Lucina AX-09 Synthesizer
    - BOSS BR-800 Digital Recorder
    - Roland DUO/TRI-CAPTURE (EX) Audio Interface
    - BOSS RC-300 Loop Station
    - Roland JUPITER-50/80 Keyboard
    - Roland R-26 Recorder
    - Roland SPD-SX Controller
    - BOSS JS-10 Audio Player
    - Roland TD-11/15/30 Drum Module
    - Roland A-49/88 Keyboard
    - Roland INTEGRA-7 Synthesizer
    - Roland R-88 Recorder

    Signed-off-by: Clemens Ladisch

    Clemens Ladisch
     

04 Apr, 2013

1 commit


04 Jan, 2013

1 commit

  • This patch is based on 3.8-rc1. It fixes two things:
    1) A kernel panic caused by incorrect allocation of a u8 variable
    "bootresponse".
    2) A noisy dmesg (urb status -32) caused by broken pipe to an
    invalid midi endpoint.

    It is also a little cleaner because there is no need for a new
    QUIRK_MIDI type as suggested by kernel developers, since the device
    follows exactly the MIDIMAN protocol.

    Signed-off-by: Damien Zammit
    Signed-off-by: Takashi Iwai

    Damien Zammit
     

19 Dec, 2012

1 commit

  • This patch is the result of a lot of trial and error, since there are no specs
    available for the device.

    Full duplex support is provided, i.e. playback and recording in stereo.
    The format is hardcoded at 48000Hz @ 24 bit, which is the maximum that the
    device supports. Also, MIDI in and MIDI out both work.

    Users will notice that the S/PDIF light also flashes when playback or recording
    is active. I believe this means that S/PDIF input/output is simultaneously
    activated with the analogue i/o during use.
    But this particular functionality remains untested.

    Note that this particular version of the patch is so far untested on the
    physical hardware because I have not compiled a full kernel with the changes.
    However, extensive testing has been done by many users of the hardware
    who believe other versions of my patch have worked since circa 2009.

    [Modified to make a function static by tiwai]

    Signed-off-by: Damien Zammit
    Signed-off-by: Takashi Iwai

    Damien Zammit
     

21 Nov, 2012

1 commit


30 Oct, 2012

1 commit


13 Apr, 2012

2 commits

  • 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
     
  • This is needed for new card-wide list operations.

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

    Daniel Mack
     

26 Aug, 2011

1 commit


25 May, 2011

1 commit


11 Mar, 2011

1 commit

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

    Oliver Neukum
     

23 Feb, 2011

1 commit

  • 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
    Cc:
    [CL: also serialize hw_params callback]
    Signed-off-by: Clemens Ladisch
    Signed-off-by: Takashi Iwai

    Takashi Iwai
     

23 Oct, 2010

1 commit


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
     

21 May, 2010

1 commit


05 Mar, 2010

2 commits

  • 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
     
  • Rename snd-usb-lib to snd-usbmidi-lib as MIDI functions are the only
    thing it actually contains. Introduce a new header file to only declare
    these functions.

    Introduced usbmixer.h for all functions exported by usbmixer.c.

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

    Daniel Mack
     

02 Mar, 2010

2 commits


23 Feb, 2010

3 commits

  • Use the definitions from linux/usb/audio.h all over the ALSA USB audio
    driver and add some missing definitions there as well.

    Use the endpoint attribute macros from linux/usb/ch9 and remove the own
    things from sound/usb/usbaudio.h.

    Now things are also nicely prefixed which makes understanding the code
    easier.

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

    Daniel Mack
     
  • This adds a number of parsers for audio class v2.0. In particular, the
    following internals are different and now handled by the code:

    * the number of streaming interfaces is now reported by an interface
    association descriptor. The old approach using a proprietary
    descriptor is deprecated.

    * The number of channels per interface is now stored in the AS_GENERAL
    descriptor (used to be part of the FORMAT_TYPE descriptor).

    * The list of supported sample rates is no longer stored in a variable
    length appendix of the format_type descriptor but is retrieved from
    the device using a class specific GET_RANGE command.

    * Supported sample formats are now reported as 32bit bitmap rather than
    a fixed value. For now, this is worked around by choosing just one of
    them.

    * A devices needs to have at least one CLOCK_SOURCE descriptor which
    denotes a clockID that is needed im the class request command.

    * Many descriptors (format_type, ...) have changed their layout. Handle
    this by casting the descriptors to the appropriate structs.

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

    Daniel Mack
     
  • This patch adds some definitions for audio class v2.

    Unfortunately, the UNIT types PROCESSING_UNIT and EXTENSION_UNIT have
    different numerical representations in both standards, so there is need
    for a _V1 add-on now. usbmixer.c is changed accordingly.

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

    Daniel Mack
     

28 Dec, 2009

3 commits

  • Detect the HVR-950Q HVR-850 urb data alignment quirk using usbquirk.h
    rather than using a case statement in snd_usb_audio_probe.

    Signed-off-by: John S. Gruber
    Signed-off-by: Takashi Iwai

    John S. Gruber
     
  • Addressing audio quality problem.

    In sound/usb/usbaudio.c, for the Hauppage HVR-950Q and HVR-850 only, change
    retire_capture_urb to allow transfers on audio sub-slot boundaries rather
    than audio slots boundaries.

    With these devices the left and right channel samples can be split between
    two different urbs. Throwing away extra channel samples causes a sound
    quality problem for stereo streams as the left and right channels are
    swapped repeatedly, perhaps many times per second.

    Urbs unaligned on sub-slot boundaries are still truncated to the next
    lowest stride (audio slot) to retain synchronization on samples even
    though left/right channel synchronization may be lost in this case.

    Detect the quirk using a case statement in snd_usb_audio_probe.

    BugLink: https://bugs.launchpad.net/ubuntu/+bug/495745

    Signed-off-by: John S. Gruber
    Signed-off-by: Takashi Iwai

    John S. Gruber
     
  • Added functionality:
    1) Extension Units support (all XU settings now available at alsamixer,
    kmix, etc):
    - "AnalogueIn soft limiter" switch;
    - "Sample rate" selector (values 0,1,2,3,4,5 corresponds to 44.1 48 ...
    192 kHz);
    - "DigitalIn CLK source" selector (internal/external) (**);
    - "DigitalOut format SPDIF/AC3" switch (**);
    (**)E-mu-0404usb only.

    2) Automatic device sample rate adjustment depending on substream
    samplerate for both capture and playback substream.

    [minor coding-style fixes by tiwai]

    Signed-off-by: Sergiy Kovalchuk
    Signed-off-by: Takashi Iwai

    Sergiy Kovalchuk
     

15 Dec, 2009

1 commit


24 Nov, 2009

1 commit


07 Nov, 2009

1 commit

  • Fix combine_word problem where first octet is not
    read properly. The only affected place seems to be the
    INPUT_TERMINAL type. Before now, sound controls can be created
    with the output terminal's name which is a fallback mechanism
    used only for unknown input terminal types. For example,
    Line can wrongly appear as Speaker. After the change it
    should appear as Line.

    The side effect of this change can be that users
    can expect the wrong control name in their scripts or
    programs while now we return the correct one.

    Probably, these defines should use get_unaligned_le16 and
    friends.

    Signed-off-by: Julian Anastasov
    Cc:
    Signed-off-by: Takashi Iwai

    Julian Anastasov
     

27 May, 2009

1 commit

  • Kernel 2.6.18 broke the MotU Fastlane, which uses duplicate endpoint
    numbers in a manner that is not only illegal but also confuses the
    kernel's endpoint descriptor caching mechanism. To work around this, we
    have to add a separate usb_set_interface() call to guide the USB core to
    the correct descriptors.

    Signed-off-by: Clemens Ladisch
    Reported-and-tested-by: David Fries
    Cc:
    Signed-off-by: Takashi Iwai

    Clemens Ladisch