Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4368888pxu; Mon, 21 Dec 2020 10:38:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwymx1Fa4CvrWVcZXtwoYoyLsGEZZ4T75MsbCppfBuqD4iXRxBHKDPB7TUt/14OoSTexSkN X-Received: by 2002:a17:907:1010:: with SMTP id ox16mr16669421ejb.439.1608575879859; Mon, 21 Dec 2020 10:37:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608575879; cv=none; d=google.com; s=arc-20160816; b=uAWjyUJ+sV1OYuCrYCRyJPRzxg9rXyvb9dT+QycvoyEQWFU4T41XAnvrBetP9+DTuA mOtfeeCgal4y82T3A0qKr689GydwItiBXuGggW8kG2oRl4+vW5XDMOxAm6WFIFKHU/WN mSd+3Lg0cgrJEabhZa2yHt8zTqyMwugF0YWziCj6CNmzjn8076SAKs/h7ivdkKfImfBz P4KIpS+ZRxhvUqgnayj0nscvVYuCWq7AgSdgCfs0DMAPiIVsa5y2lHnXnNEUQmkC4Hp2 8U2eCDifr6JciPPfqxcfkvO/KVxqb/HLiXDgY9xZMVBVfub6fNtYcDD4knfVhNLe8HNb Tmbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nk1WbTku/ptwimEpWVF9T+Es0gLNCmrcP2x+3MKG7iM=; b=rXQPjnjABL89HYTZ76AR+fXez7snQdr7rOYYMYY24h1WVu50VaxdRDXWl8nWu1yzaB I+78Ax4U6ldmKkqJAp9GxzVOhUhlLdqnz3buMbk4iYwEHEAenZspBYw960JRl0CsScmn hlaCKqbqI1CkNENLtx2Ciri8kVkg7GKe2jY4mSMbe49tjSzo135bLOKAeRFeO2+ca13d CZ70PvC+Fxap+P23N9y/FZJjrLnnDHRhYbXSb5Ffna/EX9/6j9c7Abv4xkMv/b4chN3j xdX7+pffPdRT/z/zcKLk0L3r8Jc0LT/q5cqBoor329QpBcesVQUREpdEaMRpRiDPGM/z 9bWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JOeMsmrM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z21si9466261ejj.256.2020.12.21.10.37.37; Mon, 21 Dec 2020 10:37:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=JOeMsmrM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726956AbgLUSgX (ORCPT + 99 others); Mon, 21 Dec 2020 13:36:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726855AbgLUSgX (ORCPT ); Mon, 21 Dec 2020 13:36:23 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14DBFC0613D6 for ; Mon, 21 Dec 2020 10:35:42 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id o17so26063825lfg.4 for ; Mon, 21 Dec 2020 10:35:41 -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=nk1WbTku/ptwimEpWVF9T+Es0gLNCmrcP2x+3MKG7iM=; b=JOeMsmrMEqBux4BNP1j8g04oh0OzDgap7eVMEvDocXqACKFHd1t/rBIJ6RZvaHFE2i K8LYMk77pPBkHpLMbeCIx8VCOUujqfswqenZw4UNX6X7Dh2Pi53dbvmazJ0oxf81dg3t wM7nmbhAhodkQr08hkGOG1sE1gzJXdr4IxSCN//ZxoALzdZ70PY5w5BKG0/0kZ+pg4Cn gYfBETlB2MKucmYgUEohEIW9LSpz4naKpk6uuc8ssXjZR6N/oBIE+LvgN9NXW+m7vchU ZLMPmsC60u/YO1xDP14uN7BrAm+kir6WgHB4/kPyNXPU3DkJ/jPrw85UZDZIpwl3JCtK MHpA== 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=nk1WbTku/ptwimEpWVF9T+Es0gLNCmrcP2x+3MKG7iM=; b=Q+A6wDDiURmryJPwUMriA1XPjhsJ0zZu64Dt8peuriDIOHoEdnYQeqy81trYjirrtP DifImYZSBgeGK0Ld+zhN8Y1WE8v7umKbuuyjvrXqHkaJHyp1moLHoYGI8FGs0Ub5eowV vyV91CLXbWTEFp5Wui8NKnuoa0+lRsp2CYkB+QWQqC0fv1OCco+4/c1hUG6+JaVTGDuI CamcyPYE/d607OtsALiiqpVUe+BirT7GcXRPUi9SUDesZ0vHk1wCjGx4ntRjHGUzFPJO B5tNbq5PPhIQrth4JtTJxKTC17yYl1ZALVlEG4w7QbmbuzdJeuytOqcnKZWVvgcmuKgO Qffg== X-Gm-Message-State: AOAM531MPndjg6vmb2HM5WRB0vijz+khgZcdwxK5pOSD4v94T+9OWh2v ASKRbAM2KL2BhVw6wB8Q0cZXwsbYzLFxZQaE X-Received: by 2002:a17:906:ae0c:: with SMTP id le12mr16500568ejb.283.1608572142949; Mon, 21 Dec 2020 09:35:42 -0800 (PST) Received: from starbuck.lan (82-65-169-74.subs.proxad.net. [82.65.169.74]) by smtp.googlemail.com with ESMTPSA id dd18sm9338408ejb.53.2020.12.21.09.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 09:35:42 -0800 (PST) From: Jerome Brunet To: Felipe Balbi , Greg Kroah-Hartman Cc: Jerome Brunet , Ruslan Bilovol , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] usb: gadget: u_audio: factorize ssize to alsa fmt conversion Date: Mon, 21 Dec 2020 18:35:29 +0100 Message-Id: <20201221173531.215169-3-jbrunet@baylibre.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221173531.215169-1-jbrunet@baylibre.com> References: <20201221173531.215169-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factorize format related code common to the capture and playback path. 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 71dd9f16c246..2f69bd572ed7 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 unsigned long uac_ssize_to_fmt(int ssize) +{ + unsigned long 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; -- 2.29.2