From patchwork Wed Nov 20 06:02:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11253213 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96DE11390 for ; Wed, 20 Nov 2019 06:04:43 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 922B121850 for ; Wed, 20 Nov 2019 06:04:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="lbWMG3ZS"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="csjy0tOc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 922B121850 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5565F168A; Wed, 20 Nov 2019 07:03:50 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5565F168A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1574229880; bh=+Ch4s5U+4hNoWFsNuBsF22JYB3mK/00zDULitv5b/kw=; h=Date:In-Reply-To:References:From:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lbWMG3ZS9iPWJ7MuRMisrFVhjsM/rvqmHVywz/+jpyc50jvMc4m7i4zd89HRKpFXM i4Sq+WEWgTRtXM95AG/suq3mSXG9DUhHezwcg6fbbWkMlcY0x/tUF7LD3q1141ExRV WmfgE6SeY1X0M8Wn2pt2PYCOZtGvQ35Zg5cVvz4M= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AB4CCF8013C; Wed, 20 Nov 2019 07:03:44 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2811FF80140; Wed, 20 Nov 2019 07:03:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.0 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D14A3F8013C for ; Wed, 20 Nov 2019 07:03:17 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D14A3F8013C Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="csjy0tOc" Received: by mail-pj1-x104a.google.com with SMTP id d21so2012867pjs.21 for ; Tue, 19 Nov 2019 22:03:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=rHvSP+r9Lb+DeD2PMrAaobDRLM7O+VFG6q0IT34Km/U=; b=csjy0tOcIwufMLaU5xSZtfs0SGJF+nnovtK9gquaBsQ7B7+f5sYTLiVgImOrMBJWPa TBP4MiaR94snITMt1g7oOOLleVUuuzE05yKqCgPYS1HmDNGlANjOKoAGUoToCBByMfFK OhmcNv5WbZvYcvuth85LAaNoJ74kryn0/F6fpIce33r/VQwSyleIrXTlOwsvcMvBsN5I z7VsP1GBr3orbBioPL+RYH2bfKNklUg8jTroGjGHdynMBwp+Ewfqe5pX9U5ehYhz3ahC OOtM6qy2QSpodxqzmpXn4rZQOWiO72LbnZNS2g7Z7GmJYgLpKKktY6OY31OcMLHfrpzG LgNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=rHvSP+r9Lb+DeD2PMrAaobDRLM7O+VFG6q0IT34Km/U=; b=D3AVO5EnDU8KDU5cxxejJoLkhTag5MxTIrRvLaECWrMHBx3Csahu45lexsnNSMsKkH N2XIs66Mkq49aXE+Z9kp/DvHaGOXZ52SWA5Gqgh28FxcrlawzIFidLC+ivS2Qcro3i+Y cseY+qAZY5H1Gp53c1iJKzt2hM5pr9hr/gG0W9E6oy78VuLWuejsXMTKLmORnJ24cUS8 +Ym8sWUijXAER+NpHwekLQJ3nAnZgdx7TDFBHt5qjgkXGAwKaP9Ppo2u5gGA8tZXNuZf PhZFQbUG6LN6DGens6bJngJDxNMKIr7+rJ2UV6IKgK9WTuePvQGpn+tLdkQwiJCblUe/ ipVA== X-Gm-Message-State: APjAAAVTiR8sdRd19md/XTCjMA3t860Qp3liznSkdUZvwYXUPAwolC6z pj4EdUif1/uCFolgWGk/Vna24OXtcHL3 X-Google-Smtp-Source: APXvYqyncm8dq+VdWQeOLEhiBIBHzjAAKv8i0ywII1O6PqXBzGB57jT4OPrmP+RVdhz7/LzIi7VIBmtvCc7o X-Received: by 2002:a63:3144:: with SMTP id x65mr1196978pgx.283.1574229794345; Tue, 19 Nov 2019 22:03:14 -0800 (PST) Date: Wed, 20 Nov 2019 14:02:54 +0800 In-Reply-To: <20191120060256.212818-1-tzungbi@google.com> Message-Id: <20191120060256.212818-2-tzungbi@google.com> Mime-Version: 1.0 References: <20191120060256.212818-1-tzungbi@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog From: Tzung-Bi Shih To: broonie@kernel.org Cc: tzungbi@google.com, alsa-devel@alsa-project.org, dgreid@google.com, cychiang@google.com Subject: [alsa-devel] [PATCH 1/3] ASoC: max98090: remove msleep in PLL unlocked workaround X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" It was observed Baytrail-based chromebooks could cause continuous PLL unlocked when using playback stream and capture stream simultaneously. Specifically, starting a capture stream after started a playback stream. As a result, the audio data could corrupt or turn completely silent. As the datasheet suggested, the maximum PLL lock time should be 7 msec. The workaround resets the codec softly by toggling SHDN off and on if PLL failed to lock for 10 msec. Notably, there is no suggested hold time for SHDN off. On Baytrail-based chromebooks, it would easily happen continuous PLL unlocked if there is a 10 msec delay between SHDN off and on. Removes the msleep(). Signed-off-by: Tzung-Bi Shih --- sound/soc/codecs/max98090.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c index f6bf4cfbea23..8382a77586ee 100644 --- a/sound/soc/codecs/max98090.c +++ b/sound/soc/codecs/max98090.c @@ -2117,7 +2117,6 @@ static void max98090_pll_work(struct work_struct *work) /* Toggle shutdown OFF then ON */ snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN, M98090_SHDNN_MASK, 0); - msleep(10); snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN, M98090_SHDNN_MASK, M98090_SHDNN_MASK); From patchwork Wed Nov 20 06:02:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11253219 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BFC61390 for ; Wed, 20 Nov 2019 06:07:14 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E46EA22460 for ; Wed, 20 Nov 2019 06:07:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="ZQJf380L"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="IV6S7D2S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E46EA22460 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 183981689; Wed, 20 Nov 2019 07:06:22 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 183981689 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1574230032; bh=+D2uIbeqX3gLq2l98r1OlLOomSYgnxt/nyrZapJaeY4=; h=Date:In-Reply-To:References:From:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ZQJf380Lk7DuUZ6O29qI1p89WFEGceHtd5/dV3VpMx1lHIH5pNRngIOilDzhl6xCV tg2WLBFjgv+kpEIz91i7QPPjx8ba7+RPSqN6CnaL7jQgAQ7NIYA6LQwhdW6k0AnUoX E7mpTOtjrn/ztcMn40j3469E33zxjDpD80pkO/iU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 47127F80150; Wed, 20 Nov 2019 07:04:05 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 22BF5F8014A; Wed, 20 Nov 2019 07:03:46 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_NONE,USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.0 Received: from mail-yw1-xc4a.google.com (mail-yw1-xc4a.google.com [IPv6:2607:f8b0:4864:20::c4a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 90C90F800FF for ; Wed, 20 Nov 2019 07:03:20 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 90C90F800FF Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IV6S7D2S" Received: by mail-yw1-xc4a.google.com with SMTP id o3so13656267ywl.23 for ; Tue, 19 Nov 2019 22:03:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=6lgEc4aHXrMDzrrTwjbYqif4GDvgvoecAPUZTUK0d9Y=; b=IV6S7D2SQ/6DG9WZRXKipSdDHjafWpONiCuSilso8kh/yxWeCBocfsfLJgJlxafWe0 kSHOECP+1oQqpBZiv6SiFAi3sMYDp0fV5AUP/qdyaSonZu5PFzPC1tSQmXGYMW5hVX6/ 077pxIp1OpWyuBenmSbyPcyVpcLtjkLMbIHTFkuOQf+6/MrqyEB7+oaJA2bvDqr+qSgG ewDZlMR5qNBQkMV277l1dDvyDJ+U7AAHbNkJ6+PMs1k0z7BXKunH674GWQ8MdneWd3K7 0QlO1QSI0BwF0xLWeOzbDRfIXF0K1FVoKwBAT7x32r89pcw+kITg25eDlv8b1zAYlRLG 0Zsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6lgEc4aHXrMDzrrTwjbYqif4GDvgvoecAPUZTUK0d9Y=; b=j3q6a4ix39wQwtmtBsxEJudVdtXODfkfwDTNSyPhZbl7yHMYtAFzg78QaT6ZsB7wsm IOULarIOm9f4ZHW4KJyj+sqVg9fJw/IyrOVAaXLoiYKc7Gx7xqeBC+txnzlbYs+Aj6YU +ob2c5M2Ragcf/rxA33K6TFQP629sG8GUbTLXK/Gq5Ry+3ghDdypOrjU+S8iipaS1aWE 1rzw4hSSHAAS5FsnR+nxAC5InfWEuzBu4q2k5NVMW3MwYtbclU14fqsWGS/zWOVJUz84 Gw32aAxUHLFXQsCOtCrcjRzU3Pj9UEP6baIWfa7GS8sUy0PJ2pPeG6FDo2XScA2MKjMM zaOQ== X-Gm-Message-State: APjAAAUtyIdTvPOezohaZtPy2acQjQ+zy8aQKZwuwUeEDaSu4vH32e5+ bou3uuCFryo55xlKEGWJ1RHIBTdTDlTI X-Google-Smtp-Source: APXvYqy2AjjGIryOYswWJEUFXn4t0C3qqSFp+URKKXP/kvOO9jcK37UeXkfz7evJC+Pe0j75UJxuf/UTy2iP X-Received: by 2002:a81:498e:: with SMTP id w136mr531108ywa.494.1574229799381; Tue, 19 Nov 2019 22:03:19 -0800 (PST) Date: Wed, 20 Nov 2019 14:02:55 +0800 In-Reply-To: <20191120060256.212818-1-tzungbi@google.com> Message-Id: <20191120060256.212818-3-tzungbi@google.com> Mime-Version: 1.0 References: <20191120060256.212818-1-tzungbi@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog From: Tzung-Bi Shih To: broonie@kernel.org Cc: tzungbi@google.com, alsa-devel@alsa-project.org, dgreid@google.com, cychiang@google.com Subject: [alsa-devel] [PATCH 2/3] ASoC: max98090: exit workaround earlier if PLL is locked X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" According to the datasheet, PLL lock time typically takes 2 msec and at most takes 7 msec. Check the lock status every 1 msec and exit the workaround if PLL is locked. Signed-off-by: Tzung-Bi Shih --- sound/soc/codecs/max98090.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c index 8382a77586ee..2ccdfb2383b7 100644 --- a/sound/soc/codecs/max98090.c +++ b/sound/soc/codecs/max98090.c @@ -2108,6 +2108,8 @@ static void max98090_pll_work(struct work_struct *work) struct max98090_priv *max98090 = container_of(work, struct max98090_priv, pll_work); struct snd_soc_component *component = max98090->component; + unsigned int pll; + int i; if (!snd_soc_component_is_active(component)) return; @@ -2120,8 +2122,16 @@ static void max98090_pll_work(struct work_struct *work) snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN, M98090_SHDNN_MASK, M98090_SHDNN_MASK); - /* Give PLL time to lock */ - msleep(10); + for (i = 0; i < 10; ++i) { + /* Check lock status */ + pll = snd_soc_component_read32( + component, M98090_REG_DEVICE_STATUS); + if (!(pll & M98090_ULK_MASK)) + break; + + /* Give PLL time to lock */ + usleep_range(1000, 1200); + } } static void max98090_jack_work(struct work_struct *work) From patchwork Wed Nov 20 06:02:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11253217 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42F1C1390 for ; Wed, 20 Nov 2019 06:06:27 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC51322461 for ; Wed, 20 Nov 2019 06:06:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="TGQVB5KG"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="cy7Dprxu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC51322461 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 29DA116A3; Wed, 20 Nov 2019 07:05:35 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 29DA116A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1574229985; bh=NwrZp+fdNZNzy3t4456q2po3wuw8fefJGamipccjXhQ=; h=Date:In-Reply-To:References:From:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TGQVB5KGawI5A31x/Hlacn3PTg6UbDTkTWdjmv6jLDgtl137NMJ55ga5wRv9UIxw1 6HdaG1ngcpfxC5LV1eJBCNnx7bZvj2PQ3JZ2bWmRCB33NFVv2UBz5OaHFhdFWNoyHI fzdKs1lfFJ0dzwFt7XHfVRr/S82pDauY+kJYVjjU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E2DDAF8014E; Wed, 20 Nov 2019 07:04:03 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 788EAF8013E; Wed, 20 Nov 2019 07:03:44 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_NONE, USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.0 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id C8CCBF8013D for ; Wed, 20 Nov 2019 07:03:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C8CCBF8013D Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cy7Dprxu" Received: by mail-pg1-x54a.google.com with SMTP id t11so17211864pgm.2 for ; Tue, 19 Nov 2019 22:03:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Rj5jKMrZLCyz1LkWVBkT6xeM2EOIBG2OeJCuLSdQyq8=; b=cy7DprxuzzBiGwynCwOPCMA/gABy2u6CBHvgksnBVdgwyk4DkB9RKyfwjqXis9Zvyx TxGY4SNqBGrriA97Ka1TRUWSFlGb7pJXKtymnP7Raphw64hn1KU/YdnKlCfbxHjlJaFb lVb4sKR9PWt/H4kQeirIHlN9QyYj8HRSlz8xB7Dt9Iukd5N+WrkLH1eFU/GsCL8+WNX2 scNwpZp30AxKsKmVqSjHdOBUXIBB4UcFJjltEGjzbtGizV3cU3KVVyTiYUAPSuhutpo+ nz5jLqMpOEnKJ1eu6p3UCDR9veCa3i9i6MNrDeYCAI8iAhxY0lq1M3BDyTeX1PMw4z9w 5NlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Rj5jKMrZLCyz1LkWVBkT6xeM2EOIBG2OeJCuLSdQyq8=; b=dsr+thFqmxU0X/OLxhSM8wrtfXLBDI4iF6NzdkbIzVn8s2lpO6UaeqWjQqBTnfnzFe t1P97mbKDeKwpQmuic5iAMNzVScupS9nJNXzt7N3qrg/NF+NNnpyQB+VwctuNXrka27H CFIiMwd7rscf8siJb4hDU993Lv2F/SiM/m5PsfSgaShZUUzzt90ogiy2pV/eG6t1MdNq vJtUfdy0CMRooZ/9ub6RLWmLefdOTYWylrXbW8NZ6Kd1YqRxtNJj2f3vAGInjD79fzWX BZoRq5KTptO/G+9qHYfZQDGyIpjbwmFGi0T64hXsl0I4YdDKi8fNgX46/NaaNnjUY5tR WUUQ== X-Gm-Message-State: APjAAAW7+HyvuKMMw3cX409//9VtS00Pw7Wx+oVO8SCjSwtQOIUur+xw tfgIWidvMiuXXFosuyIZxfMZYSlE+xd2 X-Google-Smtp-Source: APXvYqyo4En1X/QR4yxh4H9iVKWVF9f94uhM9ShZSL1D1sF8tDgijt3I9rk0VHTfMBX/LZkojHHn43drUlnb X-Received: by 2002:a63:d617:: with SMTP id q23mr1295833pgg.146.1574229804189; Tue, 19 Nov 2019 22:03:24 -0800 (PST) Date: Wed, 20 Nov 2019 14:02:56 +0800 In-Reply-To: <20191120060256.212818-1-tzungbi@google.com> Message-Id: <20191120060256.212818-4-tzungbi@google.com> Mime-Version: 1.0 References: <20191120060256.212818-1-tzungbi@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog From: Tzung-Bi Shih To: broonie@kernel.org Cc: tzungbi@google.com, alsa-devel@alsa-project.org, dgreid@google.com, cychiang@google.com Subject: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" max98090_interrupt() and max98090_pll_work() run in 2 different threads. There are 2 possible races: Note: M98090_REG_DEVICE_STATUS = 0x01. Note: ULK == 0, PLL is locked; ULK == 1, PLL is unlocked. max98090_interrupt max98090_pll_work ---------------------------------------------- schedule max98090_pll_work restart max98090 codec receive ULK INT assert ULK == 0 schedule max98090_pll_work (1). In the case (1), the PLL is locked but max98090_interrupt unnecessarily schedules another max98090_pll_work. max98090_interrupt max98090_pll_work max98090 codec ---------------------------------------------------------------------- ULK = 1 receive ULK INT read 0x01 ULK = 0 (clear on read) schedule max98090_pll_work restart max98090 codec ULK = 1 receive ULK INT read 0x01 ULK = 0 (clear on read) read 0x1 assert ULK == 0 (2). In the case (2), both max98090_interrupt and max98090_pll_work read the same clear-on-read register. max98090_pll_work would falsely thought PLL is locked. There are 2 possible options: A. turn off ULK interrupt before scheduling max98090_pll_work; and turn on again before exiting max98090_pll_work. B. remove the second thread of execution. Adopts option B which is more straightforward. Signed-off-by: Tzung-Bi Shih --- sound/soc/codecs/max98090.c | 8 ++------ sound/soc/codecs/max98090.h | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c index 2ccdfb2383b7..75abe98dfc44 100644 --- a/sound/soc/codecs/max98090.c +++ b/sound/soc/codecs/max98090.c @@ -2103,10 +2103,8 @@ static void max98090_pll_det_disable_work(struct work_struct *work) M98090_IULK_MASK, 0); } -static void max98090_pll_work(struct work_struct *work) +static void max98090_pll_work(struct max98090_priv *max98090) { - struct max98090_priv *max98090 = - container_of(work, struct max98090_priv, pll_work); struct snd_soc_component *component = max98090->component; unsigned int pll; int i; @@ -2268,7 +2266,7 @@ static irqreturn_t max98090_interrupt(int irq, void *data) if (active & M98090_ULK_MASK) { dev_dbg(component->dev, "M98090_ULK_MASK\n"); - schedule_work(&max98090->pll_work); + max98090_pll_work(max98090); } if (active & M98090_JDET_MASK) { @@ -2431,7 +2429,6 @@ static int max98090_probe(struct snd_soc_component *component) max98090_pll_det_enable_work); INIT_WORK(&max98090->pll_det_disable_work, max98090_pll_det_disable_work); - INIT_WORK(&max98090->pll_work, max98090_pll_work); /* Enable jack detection */ snd_soc_component_write(component, M98090_REG_JACK_DETECT, @@ -2484,7 +2481,6 @@ static void max98090_remove(struct snd_soc_component *component) cancel_delayed_work_sync(&max98090->jack_work); cancel_delayed_work_sync(&max98090->pll_det_enable_work); cancel_work_sync(&max98090->pll_det_disable_work); - cancel_work_sync(&max98090->pll_work); max98090->component = NULL; } diff --git a/sound/soc/codecs/max98090.h b/sound/soc/codecs/max98090.h index 57965cd678b4..a197114b0dad 100644 --- a/sound/soc/codecs/max98090.h +++ b/sound/soc/codecs/max98090.h @@ -1530,7 +1530,6 @@ struct max98090_priv { struct delayed_work jack_work; struct delayed_work pll_det_enable_work; struct work_struct pll_det_disable_work; - struct work_struct pll_work; struct snd_soc_jack *jack; unsigned int dai_fmt; int tdm_slots;