Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3385467ybg; Mon, 28 Oct 2019 11:59:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDJ/r5695AuQGLn6gDHxQXzujsWZub8eoVC8mxZtJCeBEoo/RKSWG0vQASs0jfGoveCdWE X-Received: by 2002:a17:906:1604:: with SMTP id m4mr8078566ejd.124.1572289170255; Mon, 28 Oct 2019 11:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572289170; cv=none; d=google.com; s=arc-20160816; b=mm+EL6w8vvMTb9zVwm+G2bGFyPHTHR2LoEVvYkAinmleEkR6RIDreJXGTLmRKTEdUS 6EtMC5q/ap73HuoQqorcqvQ/xd02NFjCbhsM2iXlRtaeJom5ozNzSyrgdDx1phHET9VH mgr8eGJOBnBoCDXvxyM6eXjsGQMw++B/dWxyiN3nWYwr+coDOHP7R1CS+n5AVWdEcva7 0DcZDnD8/VeikWvpGQAEz8quF7eZQFS3CWhJNAgRj9aru0hJsVphA5W1rN+KoSrtL/gl RE1hhiEd4B8hrelIHPsg6x4mfluAUmeXSsAa7tRBC6hJIvkDZMIRFtgW1TwuGwWv/tgA cDXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=+1awpaw0fCatM7Tjd7aRNy3ryeQGyS1/f5LJ3pW8zDQ=; b=tWXGPZqMGWim3Yx9F/QO8kGEYQbTJcb4+0HsLUemLzbaBpwIkgRxnNEpDYBYunOAER tVWKB9Yjv2wEI4WX2AHK8FAy1jbbwpOJeGz12Wt8wkVvVj9X2oFb1XCSV3J8+Qv3Z7oe ivBkCptpV55Ts8D7luoy0DQc2/tmYnJjY8HF4wgMWN1IGprJ0S851SfCDsWvBzd2SIVt z5MZ2n35qxZZ3Ps5j7BrxXZksq4HtlRDw3+VVv3wDKBe00POGBjwehDqzhK+oDQZvAJp zwZzuPrUBy7EvOCVoRMbLMoHsyJSkn9cFv/NcmJt/1/axluzhdpsY3WDvlRFUmoUwiJP cIow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 13si9004551edw.357.2019.10.28.11.59.06; Mon, 28 Oct 2019 11:59:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387853AbfJ1JO1 (ORCPT + 99 others); Mon, 28 Oct 2019 05:14:27 -0400 Received: from inva020.nxp.com ([92.121.34.13]:55048 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387596AbfJ1JO1 (ORCPT ); Mon, 28 Oct 2019 05:14:27 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id B713B1A070C; Mon, 28 Oct 2019 10:14:24 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 6A4CC1A0707; Mon, 28 Oct 2019 10:14:19 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id E7369402E2; Mon, 28 Oct 2019 17:14:12 +0800 (SGT) From: Shengjiu Wang To: timur@kernel.org, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, broonie@kernel.org, alsa-devel@alsa-project.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH V3] ASoC: fsl_esai: Add spin lock to protect reset, stop and start Date: Mon, 28 Oct 2019 17:11:05 +0800 Message-Id: <52e92c4221a83e39a84a6cd92fc3d5479b44894c.1572252321.git.shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org xrun may happen at the end of stream, the trigger->fsl_esai_trigger_stop maybe called in the middle of fsl_esai_hw_reset, this may cause esai in wrong state after stop, and there may be endless xrun interrupt. This issue may also happen with trigger->fsl_esai_trigger_start. So Add spin lock to lock those functions. Fixes: 7ccafa2b3879 ("ASoC: fsl_esai: recover the channel swap after xrun") Signed-off-by: Shengjiu Wang Acked-by: Nicolin Chen --- Change in v3 -refine comments Change in v2 -add lock for fsl_esai_trigger_start. sound/soc/fsl/fsl_esai.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c index 37b14c48b537..453392a9cd68 100644 --- a/sound/soc/fsl/fsl_esai.c +++ b/sound/soc/fsl/fsl_esai.c @@ -33,6 +33,7 @@ * @fsysclk: system clock source to derive HCK, SCK and FS * @spbaclk: SPBA clock (optional, depending on SoC design) * @task: tasklet to handle the reset operation + * @lock: spin lock between hw_reset() and trigger() * @fifo_depth: depth of tx/rx FIFO * @slot_width: width of each DAI slot * @slots: number of slots @@ -56,6 +57,7 @@ struct fsl_esai { struct clk *fsysclk; struct clk *spbaclk; struct tasklet_struct task; + spinlock_t lock; /* Protect hw_reset and trigger */ u32 fifo_depth; u32 slot_width; u32 slots; @@ -676,8 +678,10 @@ static void fsl_esai_hw_reset(unsigned long arg) { struct fsl_esai *esai_priv = (struct fsl_esai *)arg; bool tx = true, rx = false, enabled[2]; + unsigned long lock_flags; u32 tfcr, rfcr; + spin_lock_irqsave(&esai_priv->lock, lock_flags); /* Save the registers */ regmap_read(esai_priv->regmap, REG_ESAI_TFCR, &tfcr); regmap_read(esai_priv->regmap, REG_ESAI_RFCR, &rfcr); @@ -715,6 +719,8 @@ static void fsl_esai_hw_reset(unsigned long arg) fsl_esai_trigger_start(esai_priv, tx); if (enabled[rx]) fsl_esai_trigger_start(esai_priv, rx); + + spin_unlock_irqrestore(&esai_priv->lock, lock_flags); } static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd, @@ -722,6 +728,7 @@ static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd, { struct fsl_esai *esai_priv = snd_soc_dai_get_drvdata(dai); bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; + unsigned long lock_flags; esai_priv->channels[tx] = substream->runtime->channels; @@ -729,12 +736,16 @@ static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd, case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + spin_lock_irqsave(&esai_priv->lock, lock_flags); fsl_esai_trigger_start(esai_priv, tx); + spin_unlock_irqrestore(&esai_priv->lock, lock_flags); break; case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + spin_lock_irqsave(&esai_priv->lock, lock_flags); fsl_esai_trigger_stop(esai_priv, tx); + spin_unlock_irqrestore(&esai_priv->lock, lock_flags); break; default: return -EINVAL; @@ -1002,6 +1013,7 @@ static int fsl_esai_probe(struct platform_device *pdev) dev_set_drvdata(&pdev->dev, esai_priv); + spin_lock_init(&esai_priv->lock); ret = fsl_esai_hw_init(esai_priv); if (ret) return ret; -- 2.21.0