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: 365489 Delivered-To: patch@linaro.org Received: by 2002:a02:ccad:0:0:0:0:0 with SMTP id t13csp2060462jap; Mon, 18 Jan 2021 00:49:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4KQnT5gBDoez3Ha31v9LirZv4EMOq0hfD2ClgQR7GrH/hPvnVHXQMFwHCNDNPNOe45Tpe X-Received: by 2002:a17:906:5043:: with SMTP id e3mr16769229ejk.260.1610959758425; Mon, 18 Jan 2021 00:49:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610959758; cv=none; d=google.com; s=arc-20160816; b=YZyZnn8ZEcx/howDjmX4xtfNrYmptoFfw4hy3BKUuf08gsebtDTxa1Pqw2Pq2zYEFP MbXWcsm0f7iNV8BHDcikTcqsYDXGDgg+wdiExNrSHWZ8tJg/0IV9JEqbKtiH+l16feBU oihHgeJqd2JH+QJXuqNUe9VpV8q0e1SJMWIDUHPI6l7yJrUDzMsWTpTkafgKhsAieGEh Zy0RrySc8z8IodUgnomfBVoTPkIv6+8Eyc8zkvfYHCdwvIfi9luPUIuJ9HOiBNZ5+WRA p47IlYErtjYifwPzh3Ee1JtySAf0IMlMIYkEYsNcvjeTbLNfSaPKHU1891H5DMBrBlJD Ye0g== 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=8u2QoVss2UavcelbE4BrawmKFXEyru6c+YRhQ7iYuuo=; b=Al4THLfi2i32w23NzVkc9ZNxmZuByaXnIUjbD8WbJkHwuyw6DD+17Yy4iSmgcIUwje +k4ArSl38WnUA5qiKjNALYEjvtokKAPdBZKUQC/xlQXRau4Pnmeb4JhWyuVKV0RfBUo2 H8tPqu2O0WSl58kFpDkYBaAH9Zl6KbSFp0FFh74duF5lZ9dDiuotRTTZq+L34XYPmfvv LjtIVWBmFJA5AN9R8eiqHblANDOmYZoPMSG7y8yxMoEZjxKWDRRK0WxXORMzEf/MvdCf w9itjYVUD4Q0qcr6RyBQnsidoZ+4znFmdrXYP3ZAF8AQGnltotPS452h1e68+wV+nf5D P/Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=Sm3PhrpB; 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 t14si7889997edd.161.2021.01.18.00.49.18; Mon, 18 Jan 2021 00:49:18 -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=Sm3PhrpB; 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 S2387972AbhARIsX (ORCPT + 3 others); 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-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(-) -- 2.29.2 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;