From patchwork Mon Dec 21 17:35:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 346427 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4679121jai; Mon, 21 Dec 2020 10:26:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzjXBoFL6bvc8VW3+ZmmXnZ3B8jk9pjYlmvVATsRs+GPWXO5v1dhU/0/xrWecZZ32rTlCu X-Received: by 2002:a17:906:eb5b:: with SMTP id mc27mr16354268ejb.163.1608575174098; Mon, 21 Dec 2020 10:26:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608575174; cv=none; d=google.com; s=arc-20160816; b=yNkN5VO/u6qStBigUviSM/CrV/Z6Cy9VabdsP6qKi4feXLSwIDJuChIYZi7yfrw7KC zNg7QRcQsgLET/fDxCmrfAt7WwnINwgrs0mrfSRE02nhfa7GYC+mbB8T2UCn7IbW76YH 7M3sbS5C2Evlj2uwfl0SuvXer8UPup8ERuwJmEUA03+aJhx4afhnSC7k8mEFykmE4PxK 2Yhgccth4KDB6AQHCJyaZiXJf+m1dPfQKr80D2Drq5G8l+DkFAsB0tMIiOYG+jurahrQ jq1ZkUZb6zxqscJAkQcezoglrfCn2h/Uiqah8ff3gvJSZBan/48QigO5o0XEtSHucRe1 he9g== 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=AQyO6C/K6L/vEBkOD6YR2BFsiv7YjMVpkGyrSO/vhLLVjK6MRWBuUFL4mpCUREblz8 ayTyre3HPWEVhP/MAZuNGlJcC46QJljjGU+Q2wbNy13+v9iHtRehDh7IvrzLH8TqmVFJ 3KMEKqyDSx1k4SBnjww9kgLi8NitoQdABW3Rrt9TBKMbWj1IhwoYNLWRvhqNgUM2yVfz CI95/TTB9I9bVN8Yy0s69+BJU5VffbrZWNC10qXhpJsRtcmPw8lZgy447E9kkxbevfbK 82CdPBjyaHv0K2wPC+/twj2Yq+q8XVLawDSh9sCf1GZE9wBlWZFh7cxK12Tx8YV0Csmc gpeg== 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-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-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 dt1si10825512ejc.558.2020.12.21.10.26.13; Mon, 21 Dec 2020 10:26:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-usb-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-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726188AbgLUSZg (ORCPT + 4 others); Mon, 21 Dec 2020 13:25:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbgLUSZg (ORCPT ); Mon, 21 Dec 2020 13:25:36 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E32ECC061285 for ; Mon, 21 Dec 2020 10:24:49 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id b9so14827025ejy.0 for ; Mon, 21 Dec 2020 10:24:49 -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=V4sjiQn/a4Ha9jRvVj6aaA/KNOPY1AjOnswhosPCUJGOQcPFuuhCmslWZDS8neK8ar DxZJAS0KxETZLKYvyI2Biekwvci3rXfqhjAZqzQ+BERoV2763kGNfm9s9xas+ipxkjYq GKegZ8Un5gp1SoBIFWBGFrU8Wj+YDEFPo4VFTxPoVvGa69aDiaNtA3tS6G9ZqIBonZ0X HYWm4fuqcqZNxDbZ3gEaO0BjnyR8uotny5tM5lEXbtpw0wBD0Wlf27bKpkkISfFgyQVv w9I05qVNlBHqrUJacFSY+BW7NE1+ZM3k3UBbYaKZXQWtDAaAH8NIQWj0NlJ27BZkam2i GuMQ== X-Gm-Message-State: AOAM531eOPMLTdcbvsaTqJP7Hen82F7O0qiuY5fnDPeaeiENy4MDiJGf CDsWWxPTZ9S0tidxKtPzJqEcgPlcRWGIJs1P 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 Precedence: bulk List-ID: X-Mailing-List: linux-usb@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(-) -- 2.29.2 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;