Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3661633pxu; Sun, 11 Oct 2020 19:14:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuJRNjnQEoi+58HBS+PgLPlcxndKw81yCHJU2ucUAHDvOhHb5Yz3opCw0WRRm+0T4E23I0 X-Received: by 2002:a17:906:aad5:: with SMTP id kt21mr25639031ejb.5.1602468891922; Sun, 11 Oct 2020 19:14:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602468891; cv=none; d=google.com; s=arc-20160816; b=eCs4uHnG8eB28hgU+i6qchflWnwftZ176zFAfyVKxfFIC7bd/Qkmwc/Pq/dnapXpAD hL3gMgBr/hAHyIEPwdCqEQzBTb/bO1WnWfgsyCg6CJuRYoUKg31EbkqLVNTSt6ifVQCn w2t13ZSNB9AXCbYAAgJVC+RxBn7GxJhrmjSyuad7P9zVqXV81IyIcrboYxbWZnyXQKgH cMVb+KnggaOpAWQaHBRFX/8rUqsoHFOyzzTdiKeZgF0TLdV9KiQFinUVUG/G3Lzxwc7a nYqm4cCSwXdoWrXufgYa34+J/B2KNNGQNdjVre2J1YjDEW1m6U8LjfI3YfW6nZLCR+AE Q3Yw== 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=PAK5kacH2+ECsZKBJRcAW2rWTDohVNDq66jg71dHghQ=; b=mK9wxw+1VZ0nxXq4+LCkc1hbfqEQZ89bq5uYFkUkRVTUmZHzxc5Y5twhedXJP184M9 N8M2MGRcmvvGtT5dbvu/liaeXk2UthRP5DuAIV/y7VW2dThP6mK01oj+u0ESYb7YI6rJ yE+h+BWexouUpO8ELpK/rMGjL2Bs3Gd2Sm/tlCmZkhsU9UZGbtouC2DaHDpt3ClDML8Q Y1hFucj28V81HKHHnGbkkfPcIvJ9TUngFiQZvCj4awr+xktEzc3m+3Q6sdUZOBnJKHkn kEhgakTadyX2F9+rfKP8uk1GuTDbAr8i1ezki3PXO4kKDdI87ekgeqgRatMEhiV79m+q wkCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=U4O5kX9f; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t1si11097230ejb.712.2020.10.11.19.14.29; Sun, 11 Oct 2020 19:14:51 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=U4O5kX9f; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729160AbgJKUWk (ORCPT + 99 others); Sun, 11 Oct 2020 16:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbgJKUWg (ORCPT ); Sun, 11 Oct 2020 16:22:36 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17C97C0613CE; Sun, 11 Oct 2020 13:22:36 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id c2so16016621qkf.10; Sun, 11 Oct 2020 13:22:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PAK5kacH2+ECsZKBJRcAW2rWTDohVNDq66jg71dHghQ=; b=U4O5kX9f3gpRV0fc4KOkBhcF9I7pqXyR6K58/wgl8VCUs93mzrs9lgBy6Ibx160kbr ACqBpPToCs/k7E1Cue9fXd4uAZ7XB/dhhom8hKkoBoNhSxJTm12p0+V9519NEOpc3M3R 6aV/prgYt1M4w7Xmxq0PPjyvbvhO0o1YbMkLqTL3co4z22piCyCUhwftUcK93+NWldGG UnJNQzC+IT9IdjJ9+xg/QUGwHH1pAx8ucxswGPCS7n8PnccOgqTIAP/eLWIVOJnJtjiA 2HDQjDb9GkdnBQUJB8pISuZUFgJtbii1XyOwax9SSirfhC+le71D28ypynK6qwz7dBwx dtYA== 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=PAK5kacH2+ECsZKBJRcAW2rWTDohVNDq66jg71dHghQ=; b=fG9p25HZmlgxh91WviTwcecTVkkeu1GM3tsLAsFJjpl6xo6zScCINK0IdUY+5s/sTd NYTNQeQ5aDnooILmOdfEkeT/Iaz7uRramjZpoiuJ/fAIFVHeJo3rVu3WtKTb+Bg3TX3d 4N6JLzlHYxpz25PVKfqJFRJz9i9BZV7wFk6wdaQCcIuL/AUlLdKytHs7HEvTcKSvcgWj OjF5vZd9qyVMony8BAnBYvrkWsZICr4mfcfIkbje1b1i8jiBnQSK34ahtrq0YqxuwDdM xffxaODDXMujq7IOxe4KUkmqBw5FvtHwz6rQR/w+ubxEqE3HnRvuFK2O91030gj5MY8G +WTA== X-Gm-Message-State: AOAM533uIB5e4a8KBQJeK4Nz15xn4RovBsUYEEp/XIQ8BGI9XDpwCNR4 J5VwI7QvmzrhSux/HKU3wQk= X-Received: by 2002:a37:5941:: with SMTP id n62mr6789479qkb.402.1602447755176; Sun, 11 Oct 2020 13:22:35 -0700 (PDT) Received: from clement-Latitude-7490.numericable.fr (213-245-241-245.rev.numericable.fr. [213.245.241.245]) by smtp.gmail.com with ESMTPSA id c72sm2987778qkg.56.2020.10.11.13.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Oct 2020 13:22:34 -0700 (PDT) From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= To: Maxime Ripard , Chen-Yu Tsai , Rob Herring , Mark Brown , Liam Girdwood Cc: Jaroslav Kysela , Takashi Iwai , Marcus Cooper , Jernej Skrabec , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= , Samuel Holland Subject: [PATCH v7 01/14] ASoC: sun4i-i2s: Change set_chan_cfg() params Date: Sun, 11 Oct 2020 22:22:11 +0200 Message-Id: <20201011202224.47544-2-peron.clem@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201011202224.47544-1-peron.clem@gmail.com> References: <20201011202224.47544-1-peron.clem@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As slots and slot_width can be set manually using set_tdm(). These values are then kept in sun4i_i2s struct. So we need to check if these values are set or not. This is not done actually and will trigger a bug. For example, if we set to the simple soundcard in the device-tree dai-tdm-slot-width = <32> and then start a stream using S16_LE, currently we would calculate BCLK for 32-bit slots, but program lrck_period for 16-bit slots, making the sample rate double what we expected. To fix this, we need to check if these values are set or not but as this logic is already done by the caller. Avoid duplicating this logic and just pass the required values as params to set_chan_cfg(). Suggested-by: Samuel Holland Signed-off-by: Clément Péron --- sound/soc/sunxi/sun4i-i2s.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c index f23ff29e7c1d..bfbd4207d075 100644 --- a/sound/soc/sunxi/sun4i-i2s.c +++ b/sound/soc/sunxi/sun4i-i2s.c @@ -162,8 +162,9 @@ struct sun4i_i2s_quirks { unsigned long (*get_bclk_parent_rate)(const struct sun4i_i2s *); s8 (*get_sr)(const struct sun4i_i2s *, int); s8 (*get_wss)(const struct sun4i_i2s *, int); - int (*set_chan_cfg)(const struct sun4i_i2s *, - const struct snd_pcm_hw_params *); + int (*set_chan_cfg)(const struct sun4i_i2s *i2s, + unsigned int channels, unsigned int slots, + unsigned int slot_width); int (*set_fmt)(const struct sun4i_i2s *, unsigned int); }; @@ -399,10 +400,9 @@ static s8 sun8i_i2s_get_sr_wss(const struct sun4i_i2s *i2s, int width) } static int sun4i_i2s_set_chan_cfg(const struct sun4i_i2s *i2s, - const struct snd_pcm_hw_params *params) + unsigned int channels, unsigned int slots, + unsigned int slot_width) { - unsigned int channels = params_channels(params); - /* Map the channels for playback and capture */ regmap_write(i2s->regmap, SUN4I_I2S_TX_CHAN_MAP_REG, 0x76543210); regmap_write(i2s->regmap, SUN4I_I2S_RX_CHAN_MAP_REG, 0x00003210); @@ -419,15 +419,11 @@ static int sun4i_i2s_set_chan_cfg(const struct sun4i_i2s *i2s, } static int sun8i_i2s_set_chan_cfg(const struct sun4i_i2s *i2s, - const struct snd_pcm_hw_params *params) + unsigned int channels, unsigned int slots, + unsigned int slot_width) { - unsigned int channels = params_channels(params); - unsigned int slots = channels; unsigned int lrck_period; - if (i2s->slots) - slots = i2s->slots; - /* Map the channels for playback and capture */ regmap_write(i2s->regmap, SUN8I_I2S_TX_CHAN_MAP_REG, 0x76543210); regmap_write(i2s->regmap, SUN8I_I2S_RX_CHAN_MAP_REG, 0x76543210); @@ -452,11 +448,11 @@ static int sun8i_i2s_set_chan_cfg(const struct sun4i_i2s *i2s, case SND_SOC_DAIFMT_DSP_B: case SND_SOC_DAIFMT_LEFT_J: case SND_SOC_DAIFMT_RIGHT_J: - lrck_period = params_physical_width(params) * slots; + lrck_period = slot_width * slots; break; case SND_SOC_DAIFMT_I2S: - lrck_period = params_physical_width(params); + lrck_period = slot_width; break; default: @@ -492,7 +488,7 @@ static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream, if (i2s->slot_width) slot_width = i2s->slot_width; - ret = i2s->variant->set_chan_cfg(i2s, params); + ret = i2s->variant->set_chan_cfg(i2s, channels, slots, slot_width); if (ret < 0) { dev_err(dai->dev, "Invalid channel configuration\n"); return ret; -- 2.25.1