From patchwork Wed Jul 18 20:41:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Goode X-Patchwork-Id: 10533239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B326A600F4 for ; Wed, 18 Jul 2018 20:41:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A261D29B65 for ; Wed, 18 Jul 2018 20:41:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94AFE29BCC; Wed, 18 Jul 2018 20:41:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE, RDNS_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (unknown [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC6FE29B65 for ; Wed, 18 Jul 2018 20:41:21 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E2B30267818; Wed, 18 Jul 2018 22:41:18 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 251E326781D; Wed, 18 Jul 2018 22:41:17 +0200 (CEST) Received: from mail-vk0-f73.google.com (mail-vk0-f73.google.com [209.85.213.73]) by alsa0.perex.cz (Postfix) with ESMTP id 9B4FE2677A0 for ; Wed, 18 Jul 2018 22:41:14 +0200 (CEST) Received: by mail-vk0-f73.google.com with SMTP id g71-v6so2132197vke.15 for ; Wed, 18 Jul 2018 13:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:message-id:subject:from:to:cc; bh=uwKrOEjYPowAMDpUGixoKNBfZv1Y17KMIuxtkrumTGQ=; b=syP4D4pQfh/tKz6TgG8u703inF2D7QZWMeI9xas5YCPKTvg1KvbxKDPUE1CmGaQh1A KnepBUsKw2eU8q9HiAGr1ZLWtZBy7yAv9u1a8Amtxn8hWCRZMn9K1r27nGsqQ3hTfVKL jOWe9VaIHTKmjqzr6pmQGFgzEJTpjbrQAJnpSqpRI+tOpjqmTV1lXEncSub8q3L8NEDo EqmuEHMWorWwGFWBy3zI512BjN8RgE0YrIBAt6O5sRq2WryUCAMoG1WC9FgoAx44iHu1 IUVtFFeVmk4RF5p1D+egksvkdlAYpcAYPlDcwsZh4rYwoBdroc56LVeU866RTim+wmlt U1OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=uwKrOEjYPowAMDpUGixoKNBfZv1Y17KMIuxtkrumTGQ=; b=BlmAm6xymWxpASU8LGI1Z8JwcsV2Q/TQ2ZJdorMyPzwxHTnjb1+qHv5584+Aftcjhp tkldMbdl/0nbNx24J+wXxjin5k+je97H3BJozK+Bqcg24iBDsebz4mlvGwTryPRdSG8d axq/yU1iV19bXqznrQKU/EMiBuodiqx+fRXiW6OqftMAhATF9U1afUslIOAnPEVz2/2Z wK3HYtOPfbBR2o+lqWeRygxHIVK+CvecFMoPLyRu9MwPZ4ZStLeHiFLGgEhf2oxgFlCO hAYYqZbo4fxwfQKeUKsLE+XuJ//nw5uHojzTEp1UaBOLJp5auef4WZpZvfpZEuWUxMs7 UUFw== X-Gm-Message-State: AOUpUlH2cktv0o8II4B3pZfDSkmLkhRrBedM0MVy3A/pa7611Frmhm6i fQaQnfsw/Rezv6/lissSyF2vhgjsJQ8= X-Google-Smtp-Source: AAOMgpeAOLC4IkuAVjFC38WmqPJNuagHgKuhHxRom9Zfa0HpSxq0P5fk5go4+r5OwSjtzlLyGw8b9ONbrbk= MIME-Version: 1.0 X-Received: by 2002:a1f:9404:: with SMTP id w4-v6mr3584425vkd.80.1531946473223; Wed, 18 Jul 2018 13:41:13 -0700 (PDT) Date: Wed, 18 Jul 2018 16:41:05 -0400 Message-Id: <20180718204105.166439-1-agoode@google.com> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog From: Adam Goode To: patch@alsa-project.org Cc: Adam Goode , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - usb-audio v2 1/1] ALSA: usb-audio: Allow changing from a bad sample rate X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP If the audio device is externally clocked and set to a rate that does not match the external clock, the clock will never be valid and we cannot set the rate successfully. To fix this, allow a rate change even if the clock is initially invalid, and validate again after the rate is changed. This fixes problems with MOTU UltraLite AVB hardware over USB. Signed-off-by: Adam Goode diff --git a/sound/usb/clock.c b/sound/usb/clock.c index c79749613fa6..db5e39d67a90 100644 --- a/sound/usb/clock.c +++ b/sound/usb/clock.c @@ -513,14 +513,28 @@ static int set_sample_rate_v2v3(struct snd_usb_audio *chip, int iface, bool writeable; u32 bmControls; + /* First, try to find a valid clock. This may trigger + * automatic clock selection if the current clock is not + * valid. + */ clock = snd_usb_clock_find_source(chip, fmt->protocol, fmt->clock, true); - if (clock < 0) - return clock; + if (clock < 0) { + /* We did not find a valid clock, but that might be + * because the current sample rate does not match an + * external clock source. Try again without validation + * and we will do another validation after setting the + * rate. + */ + clock = snd_usb_clock_find_source(chip, fmt->protocol, + fmt->clock, false); + if (clock < 0) + return clock; + } prev_rate = get_sample_rate_v2v3(chip, iface, fmt->altsetting, clock); if (prev_rate == rate) - return 0; + goto validation; if (fmt->protocol == UAC_VERSION_3) { struct uac3_clock_source_descriptor *cs_desc; @@ -577,6 +591,10 @@ static int set_sample_rate_v2v3(struct snd_usb_audio *chip, int iface, snd_usb_set_interface_quirk(dev); } +validation: + /* validate clock after rate change */ + if (!uac_clock_source_is_valid(chip, fmt->protocol, clock)) + return -ENXIO; return 0; }