Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp498670pxb; Fri, 3 Sep 2021 06:52:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycBLD1gVupJRvTqZoHs00DfixQzQwtALM6a0cuT6vfurXTdu1+nIjFa/DAtEXGSxrFqH8P X-Received: by 2002:a05:6e02:1c86:: with SMTP id w6mr2665617ill.52.1630677162070; Fri, 03 Sep 2021 06:52:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630677162; cv=none; d=google.com; s=arc-20160816; b=gkPLd/TtU3KRw6IaNuCGmSYK4KQLWeT1Vw6jPWGZ7CWjjIwhNfgy+gB8JcAYTndLP2 9Hr0phvkFfPMIH/C1tAf3v1wOYwbAJ65KwGw/eeNAqhqXhVVvWpqvCN0Siw6TYhPQRz1 rqS55VqOyLNR0RQSrZDVoZNS3cm5MJAiAqEmytPaELAD7QG+Qo8JFdlJM/5Mx6u0UNAw XYc9RBlvNGsjiba2qnCOozCcVOp+PFy4m5PAAopagpocmYOpo/+oH3oJNqBrafwJyO03 MZz8N02N+Hr39IbPRE3SPWtW94ds98JfVAO/8lZzNKHJ9SPnbsgwAWJcxN/kQ4QmBgS+ yDrg== 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=t+ipMT8QXUFvNgPCXBtYVvp9giFGAZhxadTus4JIUIM=; b=QF1Aefo+yD5hcfrOrFFyI6eaZCfZWOw9J+t3KPRCWkL98mUneKm0i5CtanUPZIOXlI UIMQINqMg8Lqh7W1nkvw8jdt0c/yGGUGFWj4Isv2uL5OnWr45hy/TYfXONcQ2qrp3JPE FPxz3y4A2acehAo6eXbYCnkshPv+yX1mvXrEgFM3jENwt7QL0iv2So4cFNTZaBBY+o8J WuggqhPcFxVsmktJ5gmEAOTA2j0+Ew9Zan/Aa6A17o6v1C0j9QH4WUJ2KMqizPiHEiK7 Wz+ej43oJJPi0HQfPLqTY3NaHCcgt8g19JO3dJagxiMfBHUF/ABGxO/zCDERHaEF2RbY nUaw== 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 h5si6131829iol.44.2021.09.03.06.52.29; Fri, 03 Sep 2021 06:52:42 -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 S1348168AbhICNI3 (ORCPT + 99 others); Fri, 3 Sep 2021 09:08:29 -0400 Received: from lucky1.263xmail.com ([211.157.147.135]:33736 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbhICNI2 (ORCPT ); Fri, 3 Sep 2021 09:08:28 -0400 Received: from localhost (unknown [192.168.167.235]) by lucky1.263xmail.com (Postfix) with ESMTP id 372F0B3008; Fri, 3 Sep 2021 21:07:20 +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 P32763T139760968193792S1630674439782258_; Fri, 03 Sep 2021 21:07:20 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <40f3246eea4f3cec33a301ef3fe9f8e0> 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 v3] ASoC: rockchip: i2s: Fix concurrency between tx/rx Date: Fri, 3 Sep 2021 21:07:14 +0800 Message-Id: <1630674434-650-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 v3: - Rebase and fix conflicts. 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 53e0b4a..7e89f5b 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 @@ -53,6 +54,7 @@ struct rk_i2s_dev { bool is_master_mode; const struct rk_i2s_pins *pins; unsigned int bclk_ratio; + spinlock_t lock; /* tx/rx lock */ }; static int i2s_runtime_suspend(struct device *dev) @@ -96,6 +98,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); @@ -136,6 +139,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) @@ -143,6 +147,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); @@ -183,6 +188,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, @@ -684,6 +690,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