Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3365889pxb; Sun, 29 Aug 2021 23:40:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhncHPF1gUv4m7k9K4fCAtieHEi05mahaXKbFbTUE+ToVCYWNQFOOP9Mmcuf2hnrdvUNwp X-Received: by 2002:a6b:b502:: with SMTP id e2mr16699910iof.152.1630305601891; Sun, 29 Aug 2021 23:40:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630305601; cv=none; d=google.com; s=arc-20160816; b=rUDwH/BHtaKTIsrB7VXixy2Uo2kuEkyik7vAv4SOAf9JR5gRLZaUHI4+z6pr88AgLD Ur2JxP71C0r2+I9/vxFHvAOIg38TI7K3Ptxi8zrfZde6HImTie3blOK8sxTr25fpVhjS 8zLHKpHczM7Y0Es9nbZsWfi2dMeHR4WvBpe7fvUUNvVsT2kXc+CjgWewCOBUkPBXpXak 1nlJ5OUEvLraeqOu9cJ8ATRbQB9UUnv96KZHhgzIeZG7ER1uU41fz99geJtDe/XSKd4P y274HEIanD3pZ8W2WFiIsf9yO0UBGEqTX9a9pLgzfekRJzmRlustlLbgAzkKHausSVcI PkNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=iRprwzqRM1CDl3P5N1p9tSc1WuxOUOeMmmS6HP/f/kw=; b=mKANdIzAob1gFhHXQ1+ELpjT1rKFVnPE9dh34Ztv/vXzFFv53YWhtrAp6rZpQFdhBz 0BC/3UD9/aQ6dJOt/6vYOdbfxsQJtTfsW2PPn2oz+oQli71fcxiXBMywDVaCaZafc01r 90ot84fYpjPudN+MsAwf0D/dJi1tlOCywRUAkLGy9KpY6TS4oxeUwTtfz7LcgiEvXKra Nlg8AJNczN5bs5enIFVxSddTbD1aUD6DJ9sH/OJOyehZDReSZZ/8utxDnOeL7pVIW732 yy7fS+X9z+eqcfpYZ4QCM1giEbH2EPjH8xTcu2zn1r200OKhj+YC7zMl1gmCWFGPRy7a NwdQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d8si13775084ilr.109.2021.08.29.23.39.48; Sun, 29 Aug 2021 23:40:01 -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; 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 S232778AbhH3Gjy (ORCPT + 99 others); Mon, 30 Aug 2021 02:39:54 -0400 Received: from lucky1.263xmail.com ([211.157.147.133]:46474 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbhH3Gjx (ORCPT ); Mon, 30 Aug 2021 02:39:53 -0400 Received: from localhost (unknown [192.168.167.16]) by lucky1.263xmail.com (Postfix) with ESMTP id 20F3CD5E13; Mon, 30 Aug 2021 14:38:49 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P704T139881204397824S1630305528227144_; Mon, 30 Aug 2021 14:38:49 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <7b7901ce8f4b6bf32dce0f979db0edb9> X-RL-SENDER: sugar.zhang@rock-chips.com X-SENDER: zxg@rock-chips.com X-LOGIN-NAME: sugar.zhang@rock-chips.com X-FST-TO: broonie@kernel.org X-RCPT-COUNT: 10 X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 From: Sugar Zhang To: broonie@kernel.org, heiko@sntech.de Cc: linux-rockchip@lists.infradead.org, Sugar Zhang , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ASoC: rockchip: i2s: Fix concurrency between tx/rx Date: Mon, 30 Aug 2021 14:38:45 +0800 Message-Id: <1630305525-65759-1-git-send-email-sugar.zhang@rock-chips.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds lock to fix comcurrency between tx/rx to fix 'rockchip-i2s ff070000.i2s; fail to clear' Considering the situation; tx stream rx stream | | | disable enable | | reset After this patch: lock | tx stream | enable | unlock -------- --------- lock | rx stream | disable | reset | unlock Signed-off-by: Sugar Zhang --- Changes in v2: - Fix compile error. sound/soc/rockchip/rockchip_i2s.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c index c7dc350..88e340f 100644 --- a/sound/soc/rockchip/rockchip_i2s.c +++ b/sound/soc/rockchip/rockchip_i2s.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -49,6 +50,7 @@ struct rk_i2s_dev { bool rx_start; bool is_master_mode; const struct rk_i2s_pins *pins; + spinlock_t lock; /* tx/rx lock */ }; static int i2s_runtime_suspend(struct device *dev) @@ -92,6 +94,7 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) unsigned int val = 0; int retry = 10; + spin_lock(&i2s->lock); if (on) { regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); @@ -132,6 +135,7 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) } } } + spin_unlock(&i2s->lock); } static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) @@ -139,6 +143,7 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) unsigned int val = 0; int retry = 10; + spin_lock(&i2s->lock); if (on) { regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE); @@ -179,6 +184,7 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) } } } + spin_unlock(&i2s->lock); } static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, @@ -589,6 +595,7 @@ static int rockchip_i2s_probe(struct platform_device *pdev) if (!i2s) return -ENOMEM; + spin_lock_init(&i2s->lock); i2s->dev = &pdev->dev; i2s->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf"); -- 2.7.4