From patchwork Mon Jan 18 08:46:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 12026779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF0BDC433DB for ; Mon, 18 Jan 2021 08:48:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E57321D7A for ; Mon, 18 Jan 2021 08:48:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387972AbhARIsX (ORCPT ); Mon, 18 Jan 2021 03:48:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387946AbhARIsQ (ORCPT ); Mon, 18 Jan 2021 03:48:16 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4532EC0613D3 for ; Mon, 18 Jan 2021 00:47:05 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id m4so15579959wrx.9 for ; Mon, 18 Jan 2021 00:47:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8u2QoVss2UavcelbE4BrawmKFXEyru6c+YRhQ7iYuuo=; b=Sm3PhrpBPJ137AQ3z5B1ZzYmp5XOc27tFEKSH7DZzea2NsslTMdd4ll2jv+fInlKud P4fKiBDUoWVNbFzr2/SJ9PI+ALG3UxWl2WcmrjJyK9OVmlLKWzJccGondH2tASIDy7PN tyDelH5GLOhJplrYl7A4VOdiZKaedrunuuoW66BXfZI/Cw1l36Y1ItbluxTVrrDA9rMX 9vYe7dWh0dmJt5lT0Peg4epzlQmlH4GLPtZaAGvIGljtspNHoqbQr7FuRarayJ4UOe0O GPQ8GlhC/nKpnWqOgGgMFtD+dDfqMVYdKCAAIaxbBhDyzBVZIjqpACvcLx2kiewzP+HJ ZkLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8u2QoVss2UavcelbE4BrawmKFXEyru6c+YRhQ7iYuuo=; b=Lrm4TgAuXteVCJ7wfpDPSQ0NXhYqQrrvzKf+uUrDt2Vpo0mfcYMcsCcDAYClXsf+jn NUEKR6VVhwGUdlCN5PY0W4MzJzOreZ9cnL7FNOKrQ1qZsi6NiQMBei4UUYuYLfrgJowu 7ouZFjSdDUzIwrrqchatk398zKXXm4R1EQ5Sf2ndeZsjBJz66QVnqPay5XB5ud+J8Aqt mXm/joWi11mN5B8mrUKQNeZnvmtBTgrtMzr21b13tBPSCJ+WoRyS0lL12Bfxz7+VXpwC NNRxQ7m89w0xPrO9sF0aXa2/nDtY++PCfRI7GDINiGE1gLWMX/pK/dk61p5b+9lgA0Pr sY2w== X-Gm-Message-State: AOAM533O2ssovIw3wy83QcbV+GMo1+e+kxQerhmEcMqeQHpEIvaPA5gZ Fw4wKak1FaMhdhCjl7F85DBheQ== X-Google-Smtp-Source: ABdhPJyOR062eJcPDrMUnJ6U36q+eusFtWUgiq9folxccNLxdBoqcFKCwo7r0JY1IdYXfHj37a8UOA== X-Received: by 2002:adf:8503:: with SMTP id 3mr24920822wrh.56.1610959624016; Mon, 18 Jan 2021 00:47:04 -0800 (PST) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id y63sm26224518wmd.21.2021.01.18.00.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 00:47:03 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , Jack Pham , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] usb: gadget: u_audio: factorize ssize to alsa fmt conversion Date: Mon, 18 Jan 2021 09:46:40 +0100 Message-Id: <20210118084642.322510-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118084642.322510-1-jbrunet@baylibre.com> References: <20210118084642.322510-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Factorize format related code common to the capture and playback path. Acked-by: Felipe Balbi Signed-off-by: Jerome Brunet --- drivers/usb/gadget/function/u_audio.c | 43 +++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 908e49dafd62..27f941f71a9d 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -244,6 +244,25 @@ static snd_pcm_uframes_t uac_pcm_pointer(struct snd_pcm_substream *substream) return bytes_to_frames(substream->runtime, prm->hw_ptr); } +static u64 uac_ssize_to_fmt(int ssize) +{ + u64 ret; + + switch (ssize) { + case 3: + ret = SNDRV_PCM_FMTBIT_S24_3LE; + break; + case 4: + ret = SNDRV_PCM_FMTBIT_S32_LE; + break; + default: + ret = SNDRV_PCM_FMTBIT_S16_LE; + break; + } + + return ret; +} + static int uac_pcm_open(struct snd_pcm_substream *substream) { struct snd_uac_chip *uac = snd_pcm_substream_chip(substream); @@ -269,34 +288,14 @@ static int uac_pcm_open(struct snd_pcm_substream *substream) if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { spin_lock_init(&uac->p_prm.lock); runtime->hw.rate_min = p_srate; - switch (p_ssize) { - case 3: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE; - break; - case 4: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE; - break; - default: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; - break; - } + runtime->hw.formats = uac_ssize_to_fmt(p_ssize); runtime->hw.channels_min = num_channels(p_chmask); runtime->hw.period_bytes_min = 2 * uac->p_prm.max_psize / runtime->hw.periods_min; } else { spin_lock_init(&uac->c_prm.lock); runtime->hw.rate_min = c_srate; - switch (c_ssize) { - case 3: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_3LE; - break; - case 4: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE; - break; - default: - runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; - break; - } + runtime->hw.formats = uac_ssize_to_fmt(c_ssize); runtime->hw.channels_min = num_channels(c_chmask); runtime->hw.period_bytes_min = 2 * uac->c_prm.max_psize / runtime->hw.periods_min;