From patchwork Fri Sep 6 19:46:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135957 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 8FDD41593 for ; Fri, 6 Sep 2019 19:49: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 240A2208C3 for ; Fri, 6 Sep 2019 19:49:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="O3zxrJq9"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="P1vfjZJW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 240A2208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 44E6315E2; Fri, 6 Sep 2019 21:48:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 44E6315E2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799364; bh=g8egl986clhDxlO5cvnxITtGjNt1/BHnxo+p/7NC0qw=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=O3zxrJq9Mst8cAMlfNNi/FQ4wXKI2FG2sLAJ9M4akHxkzaKPMshG5eFsAiW3y2+6m 4WCO89oLgfBtriANsAkB8NovZtg3JMmKLDyeBK0zCHveuu9o+a6Y4fLKGOKKm+o+bl DgP4leR1w/Qq6iOAnP1/hG3BaFyfA4iO4d/zONx4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 62971F803A6; Fri, 6 Sep 2019 21:47:43 +0200 (CEST) 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 AD266F805E2; Fri, 6 Sep 2019 21:47:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (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 52DA0F803D6 for ; Fri, 6 Sep 2019 21:47:37 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 52DA0F803D6 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="P1vfjZJW" Received: by mail-pl1-x642.google.com with SMTP id bd8so3637615plb.6 for ; Fri, 06 Sep 2019 12:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kLjZnC6r5JtqlbdUGnRN8/ZCpUEOGWMWHxfYOkGlfb0=; b=P1vfjZJW04HkNxMQFWVotWmIa8+QmL/qKvlDJWCfMnUcf+JcvpOpM6LvQIhD23xI1Z 6WwhNDOCZ3i0JyXqgnx4KHB4Es62zLWPC1JNANcJoNsbQhq2vwJTrdBgVD/UWmMOIHXN XASgenE7EmRwNzX14lohKjVXtYl0qsw+pjJPs= 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=kLjZnC6r5JtqlbdUGnRN8/ZCpUEOGWMWHxfYOkGlfb0=; b=rSS6OLmeRQfnEs0416QMjWa2MKtwAVae/MPzAxxTX8HTm9p6M13ZdCd9lMRnfIj9c3 aDHaDlyhBSuKRTudMj0awBVr17cx/I6BPsU6k/crG+lHx+2n36/6Wz9uzl8MnvU1s/cs rV+z+eGR4sVGlgGKq3H65PhdLMXZQ8sFZQG4SMNnamw80YCbfWS4ux1Rn1Rsn8c714mk ouFCbPDBUcz6EEs/osgo1a0jNgPZu0/gI2bd4PemhyXPLnmn/9bwfyR3zU0fz/VxshTr P1a1oG9e0DtRcl4gDZdhr2vuhTJIzNzgidaBGILuO61S/jABNICUFTICcNBZQ447bflR l9Ww== X-Gm-Message-State: APjAAAXjoYKNT44fyA/9/m9167FaPPfzjJe8377k7Xa05VDzJdkGj0TA swLqmHBD0VaY4v1O6X7GKe2qZeSakw== X-Google-Smtp-Source: APXvYqyIhxKwELzZlNRW0EHLfjeBhJBIdt2dAHjtisRZ09MRgLTq2OYNLsDumPKYx9y68fNLlfTjqA== X-Received: by 2002:a17:902:9889:: with SMTP id s9mr11277628plp.100.1567799255767; Fri, 06 Sep 2019 12:47:35 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id v8sm12728153pje.6.2019.09.06.12.47.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:47:35 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:23 -0700 Message-Id: <20190906194636.217881-2-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 01/15] ASoC: rt5677: Remove magic number register writes 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" In order to simplify understanding what register values are being written to the codec for debugging more advanced features (such as hotwording) it is best to remove magic numbers Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index c779dc3474f9..5b6ca3ced13b 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -691,10 +691,12 @@ static void rt5677_set_dsp_mode(struct snd_soc_component *component, bool on) struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); if (on) { - regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x2, 0x2); + regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, + RT5677_PWR_DSP, RT5677_PWR_DSP); rt5677->is_dsp_mode = true; } else { - regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x2, 0x0); + regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, + RT5677_PWR_DSP, 0x0); rt5677->is_dsp_mode = false; } } @@ -4466,7 +4468,8 @@ static int rt5677_set_bias_level(struct snd_soc_component *component, regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1, RT5677_LDO1_SEL_MASK | RT5677_LDO2_SEL_MASK, - 0x0055); + 5 << RT5677_LDO1_SEL_SFT | + 5 << RT5677_LDO2_SEL_SFT); regmap_update_bits(rt5677->regmap, RT5677_PR_BASE + RT5677_BIAS_CUR4, 0x0f00, 0x0f00); @@ -4491,7 +4494,9 @@ static int rt5677_set_bias_level(struct snd_soc_component *component, regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x0); regmap_write(rt5677->regmap, RT5677_PWR_DIG1, 0x0000); regmap_write(rt5677->regmap, RT5677_PWR_DIG2, 0x0000); - regmap_write(rt5677->regmap, RT5677_PWR_ANLG1, 0x0022); + regmap_write(rt5677->regmap, RT5677_PWR_ANLG1, + 2 << RT5677_LDO1_SEL_SFT | + 2 << RT5677_LDO2_SEL_SFT); regmap_write(rt5677->regmap, RT5677_PWR_ANLG2, 0x0000); regmap_update_bits(rt5677->regmap, RT5677_PR_BASE + RT5677_BIAS_CUR4, 0x0f00, 0x0000); @@ -4719,7 +4724,8 @@ static int rt5677_probe(struct snd_soc_component *component) regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, ~RT5677_IRQ_DEBOUNCE_SEL_MASK, 0x0020); - regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x0c00); + regmap_write(rt5677->regmap, RT5677_PWR_DSP2, + RT5677_PWR_SLIM_ISO | RT5677_PWR_CORE_ISO); for (i = 0; i < RT5677_GPIO_NUM; i++) rt5677_gpio_config(rt5677, i, rt5677->pdata.gpio_config[i]); From patchwork Fri Sep 6 19:46:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135959 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 83A2C15E6 for ; Fri, 6 Sep 2019 19:50:19 +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 1718E20838 for ; Fri, 6 Sep 2019 19:50:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="oV/f8Mlc"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Wmc2HURf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1718E20838 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 4C8C438; Fri, 6 Sep 2019 21:49:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4C8C438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799417; bh=La29u3APkXgJj5ZTthgCpidD16Yct7qrKbdo8y/+HLE=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oV/f8MlcelYBh+E4voNm669tDuxocupJCE5+8YMgDwNu2hfVlYza9kJkeQLYSf2aO huuU7k5RFZhpRqlFSP+8i9QG/XlLw0tVG1XQY5TwrohUIajGwECXD3x88HOy6EnEDi bDy3fJYvMAAoQItn5RV78OSh3Z1pM/4wcTXuVYjs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 10782F805FE; Fri, 6 Sep 2019 21:47:51 +0200 (CEST) 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 86B48F80600; Fri, 6 Sep 2019 21:47:48 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (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 456C3F805FE for ; Fri, 6 Sep 2019 21:47:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 456C3F805FE Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Wmc2HURf" Received: by mail-pf1-x443.google.com with SMTP id q10so5228932pfl.0 for ; Fri, 06 Sep 2019 12:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VMZf9y8f78GCqGODfxIvn20OROjDjSr5IHdEDwFOH+Q=; b=Wmc2HURf/sjhxQelDf2rrIZimmJgaPiwbo4I06HQ3bgQgG/xa3z5YtuznwKgOnVXVZ qdJyUw2nOyLavUHIY1rI5mpKIODabKoCHbCb9xnTH/XTtNZkenBEpU5drxOuIMfC6cNE NekqLN8tBgU3GkPwvTEycjUmE7BUoGySn5Kdo= 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=VMZf9y8f78GCqGODfxIvn20OROjDjSr5IHdEDwFOH+Q=; b=XUkazi/eco3Np3p005FkgxcnNKiF3yibqrkgw2dLBVv3zpoA/OwJ1zrFDXhFxJREWM b1pgS3eK6BNyzR7F29cRyArd42SkIriWu/s5qguM9H/B2Zsde4nVYjTQpHFht56808Sc KO4GGsOCYkWuf+jOQ95ZDs/L9l9k1Asp4hezs5p/4uBRwyRcGHrBA/Rryaoi6Kk2oL2k Kg4TwOrerckaFQHekAcDkFkL4Yew7HNPP5CQbmBy03Gox5KTtX+2TIZ5s5ZVR0ctnoOL 18hqiUQd282fx8mIlc/iT5OW7qHkrCWb4pHNlipwPhbZUv//KnlE57uLcgdKAdTTn/5c D7wQ== X-Gm-Message-State: APjAAAUbr79iMkSsogsuR4jtwZBPDLWauEkn6Z/LUbds7AQpIZCjCAhO dEm0WZb/H8ojvCPIFSYWRhPUZQE/Sw== X-Google-Smtp-Source: APXvYqzSqTTVtPR7R0z/60g2LvYBYYsvccPN0Yg+m9ObhpYL3KBSIuLeyzn6wjrOdsC8sNDFHmfzIA== X-Received: by 2002:aa7:91d3:: with SMTP id z19mr12701017pfa.135.1567799262919; Fri, 06 Sep 2019 12:47:42 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id g11sm5626075pgu.11.2019.09.06.12.47.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:47:42 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:24 -0700 Message-Id: <20190906194636.217881-3-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 02/15] ASoC: rt5677: keep analog power register at SND_SOC_BIAS_OFF 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" From: Ben Zhang Instead of clearing RT5677_PWR_ANLG2 (MX-64h) to 0 at SND_SOC_BIAS_OFF, we only clear the RT5677_PWR_CORE bit which is set at SND_SOC_BIAS_PREPARE. MICBIAS control bits are left unchanged. This fixed the bug where if MICBIAS1 widget is forced on, MICBIAS control bits will be cleared at suspend and never turned back on again, since DAPM thinks the widget is always on. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 5b6ca3ced13b..315a3d39bc09 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -4493,11 +4493,11 @@ static int rt5677_set_bias_level(struct snd_soc_component *component, case SND_SOC_BIAS_OFF: regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x0); regmap_write(rt5677->regmap, RT5677_PWR_DIG1, 0x0000); - regmap_write(rt5677->regmap, RT5677_PWR_DIG2, 0x0000); regmap_write(rt5677->regmap, RT5677_PWR_ANLG1, 2 << RT5677_LDO1_SEL_SFT | 2 << RT5677_LDO2_SEL_SFT); - regmap_write(rt5677->regmap, RT5677_PWR_ANLG2, 0x0000); + regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2, + RT5677_PWR_CORE, 0); regmap_update_bits(rt5677->regmap, RT5677_PR_BASE + RT5677_BIAS_CUR4, 0x0f00, 0x0000); From patchwork Fri Sep 6 19:46:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135961 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 1A4AC1593 for ; Fri, 6 Sep 2019 19:51:07 +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 A15E3206CD for ; Fri, 6 Sep 2019 19:51:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="aLzFcuTw"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gIfihF6/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A15E3206CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 DB4D31664; Fri, 6 Sep 2019 21:50:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DB4D31664 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799464; bh=juvjR6YxbBb+UAYryAVEYCU2EpF9AZkRdO2cI9Cg0Rs=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=aLzFcuTw1PvTnyDoHd3UQRB0TIOhlshaVRfEO4ue/xX6HPsXA3v83iEitDmcRgKSD pLU7tNjXEDrweZfB7lMtKXdCcevBhljba7AL0AdbGYBppR19T8JV+NWKhx91aTfVeR aGAi5uzIkstJlhpcbd1px+trJdHgHhdyu5mQJ4Kg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id F3D09F80612; Fri, 6 Sep 2019 21:47:55 +0200 (CEST) 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 E6DB5F80612; Fri, 6 Sep 2019 21:47:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (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 B8817F8060E for ; Fri, 6 Sep 2019 21:47:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B8817F8060E Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gIfihF6/" Received: by mail-pf1-x441.google.com with SMTP id r12so5238465pfh.1 for ; Fri, 06 Sep 2019 12:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=moKloexR9vorDQM4Iosj84blg7yZVcNp+szO8t+Ry2A=; b=gIfihF6/9VLzqid9Qar35yfcL/R2oiYK2NKvvKimBd2Ok976folsyXi5WqguJymasd 8HOHFkSykA4yD62UjBPLWCmeW6mUKE7o108FA832XfErHH+e+BJ5mnqZCYvVButrTAVF Qy4eqt0huoPoNCwRybGIjxqEACBaJbLill4GU= 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=moKloexR9vorDQM4Iosj84blg7yZVcNp+szO8t+Ry2A=; b=jb/4pe3DjkHIbpvhURydct9bDMWXRYM7J2k6dG0Yu93+47gSmqmJgRXk0ZgGG71UsF 8IVGFFvDNaB1XdlzDFffK9qg7/sq0jzmlv1uD5btNje6kckTFEm1UKLY6xHLZ+aWnbeU OrRO/teSQerx15s1YmzSp4gpuVp5fYtTCCU/tKoe95q9oGnaXCER6SAKqtNewyzs+Xyo DsrsvXnlqKD4IC965/E+7jxpCjM8t9a5ngfciahFbNAA58T7FPCLxsQ+9CHwWWrXsFhO rRXSodBe/Z8SRdYeC7LUhovycC3Ecpv1QWniZhj2Y7nwmYHf5c6BfOV8aAz2CXY2S9GX k49w== X-Gm-Message-State: APjAAAX+1m7P56aJkwiPaZYOnlvaT35may6ejiB/r51adX4FAF0i35+N eaSSB9pbnySnLFHuF7rRzMuglhEluw== X-Google-Smtp-Source: APXvYqy68yyUvEm5xGhBP7gNLofxqIloeHIHweP9SFnwv/iMIyxuymPge8ji73T/pUYbCKbFyuFvkw== X-Received: by 2002:a62:ed04:: with SMTP id u4mr12635666pfh.220.1567799268622; Fri, 06 Sep 2019 12:47:48 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id h70sm5482135pgc.36.2019.09.06.12.47.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:47:48 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:25 -0700 Message-Id: <20190906194636.217881-4-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 03/15] ASoC: rt5677: Add a PCM device for streaming hotword via SPI 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" From: Ben Zhang This patch implements a PCM interface for streaming hotword phrases over SPI. Userspace can open the PCM device at anytime. The stream is blocked when no hotword is detected. The mic audio buffer on the DSP is a ~128KByte ring buffer that holds ~4sec of audio samples recorded from the DMIC (S16_LE, mono, 16KHz). After a hotword is detected, previous 2 seconds of audio (containing the detected hotword) is streamed first, then live capture continues until userspace closes the PCM stream. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677-spi.c | 360 ++++++++++++++++++++++++++++++++++ sound/soc/codecs/rt5677-spi.h | 1 + 2 files changed, 361 insertions(+) diff --git a/sound/soc/codecs/rt5677-spi.c b/sound/soc/codecs/rt5677-spi.c index d681488f5312..62621fe4747c 100644 --- a/sound/soc/codecs/rt5677-spi.c +++ b/sound/soc/codecs/rt5677-spi.c @@ -24,6 +24,8 @@ #include #include +#include + #include "rt5677-spi.h" #define DRV_NAME "rt5677spi" @@ -45,9 +47,330 @@ #define RT5677_SPI_WRITE_16 0x1 #define RT5677_SPI_READ_16 0x0 +#define RT5677_BUF_BYTES_TOTAL 0x20000 +#define RT5677_MIC_BUF_ADDR 0x60030000 +#define RT5677_MODEL_ADDR 0x5FFC9800 +#define RT5677_MIC_BUF_BYTES (RT5677_BUF_BYTES_TOTAL - sizeof(u32)) +#define RT5677_MIC_BUF_FIRST_READ_SIZE 0x10000 + static struct spi_device *g_spi; static DEFINE_MUTEX(spi_mutex); +struct rt5677_dsp { + struct device *dev; + struct delayed_work copy_work; + struct mutex dma_lock; + struct snd_pcm_substream *substream; + size_t dma_offset; /* zero-based offset into runtime->dma_area */ + size_t avail_bytes; /* number of new bytes since last period */ + u32 mic_read_offset; /* zero-based offset into DSP's mic buffer */ + bool new_hotword; /* a new hotword is fired */ +}; + +static const struct snd_pcm_hardware rt5677_spi_pcm_hardware = { + .info = SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_MMAP_VALID | + SNDRV_PCM_INFO_INTERLEAVED, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .period_bytes_min = PAGE_SIZE, + .period_bytes_max = RT5677_BUF_BYTES_TOTAL / 8, + .periods_min = 8, + .periods_max = 8, + .channels_min = 1, + .channels_max = 1, + .buffer_bytes_max = RT5677_BUF_BYTES_TOTAL, +}; + +static struct snd_soc_dai_driver rt5677_spi_dai = { + /* The DAI name "rt5677-dsp-cpu-dai" is not used. The actual DAI name + * registered with ASoC is the name of the device "spi-RT5677AA:00", + * because we only have one DAI. See snd_soc_register_dais(). + */ + .name = "rt5677-dsp-cpu-dai", + .id = 0, + .capture = { + .stream_name = "DSP Capture", + .channels_min = 1, + .channels_max = 1, + .rates = SNDRV_PCM_RATE_16000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, +}; + +/* PCM for streaming audio from the DSP buffer */ +static int rt5677_spi_pcm_open(struct snd_pcm_substream *substream) +{ + snd_soc_set_runtime_hwparams(substream, &rt5677_spi_pcm_hardware); + return 0; +} + +static int rt5677_spi_pcm_close(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = + snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct rt5677_dsp *rt5677_dsp = + snd_soc_component_get_drvdata(component); + + cancel_delayed_work_sync(&rt5677_dsp->copy_work); + return 0; +} + +static int rt5677_spi_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = + snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct rt5677_dsp *rt5677_dsp = + snd_soc_component_get_drvdata(component); + int ret; + + mutex_lock(&rt5677_dsp->dma_lock); + ret = snd_pcm_lib_alloc_vmalloc_buffer(substream, + params_buffer_bytes(hw_params)); + rt5677_dsp->substream = substream; + mutex_unlock(&rt5677_dsp->dma_lock); + + return ret; +} + +static int rt5677_spi_hw_free(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = + snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct rt5677_dsp *rt5677_dsp = + snd_soc_component_get_drvdata(component); + + mutex_lock(&rt5677_dsp->dma_lock); + rt5677_dsp->substream = 0; + mutex_unlock(&rt5677_dsp->dma_lock); + + return snd_pcm_lib_free_vmalloc_buffer(substream); +} + +static int rt5677_spi_prepare(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = + snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct rt5677_dsp *rt5677_dsp = + snd_soc_component_get_drvdata(component); + + rt5677_dsp->dma_offset = 0; + rt5677_dsp->avail_bytes = 0; + return 0; +} + +static snd_pcm_uframes_t rt5677_spi_pcm_pointer( + struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = + snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct rt5677_dsp *rt5677_dsp = + snd_soc_component_get_drvdata(component); + + return bytes_to_frames(runtime, rt5677_dsp->dma_offset); +} + +static int rt5677_spi_mic_write_offset(u32 *mic_write_offset) +{ + int ret; + /* Grab the first 4 bytes that hold the write pointer on the + * dsp, and check to make sure that it points somewhere inside the + * buffer. + */ + ret = rt5677_spi_read(RT5677_MIC_BUF_ADDR, mic_write_offset, + sizeof(u32)); + if (ret) + return ret; + /* Adjust the offset so that it's zero-based */ + *mic_write_offset = *mic_write_offset - sizeof(u32); + return *mic_write_offset < RT5677_MIC_BUF_BYTES ? 0 : -EFAULT; +} + +/* + * Copy a block of audio samples from the DSP mic buffer to the dma_area of + * the pcm runtime. The receiving buffer may wrap around. + * @begin: start offset of the block to copy, in bytes. + * @end: offset of the first byte after the block to copy, must be greater + * than or equal to begin. + * + * Return: Zero if successful, or a negative error code on failure. + */ +static int rt5677_spi_append_data(struct rt5677_dsp *rt5677_dsp, + u32 begin, u32 end) +{ + struct snd_pcm_runtime *runtime = rt5677_dsp->substream->runtime; + size_t bytes_per_frame = frames_to_bytes(runtime, 1); + size_t first_chunk_len, second_chunk_len; + int ret; + + if (begin > end || runtime->dma_bytes < 2 * bytes_per_frame) { + dev_err(rt5677_dsp->dev, + "Invalid copy from (%u, %u), dma_area size %zu\n", + begin, end, runtime->dma_bytes); + return -EINVAL; + } + + /* The block to copy is empty */ + if (begin == end) + return 0; + + /* If the incoming chunk is too big for the receiving buffer, only the + * last "receiving buffer size - one frame" bytes are copied. + */ + if (end - begin > runtime->dma_bytes - bytes_per_frame) + begin = end - (runtime->dma_bytes - bytes_per_frame); + + /* May need to split to two chunks, calculate the size of each */ + first_chunk_len = end - begin; + second_chunk_len = 0; + if (rt5677_dsp->dma_offset + first_chunk_len > runtime->dma_bytes) { + /* Receiving buffer wrapped around */ + second_chunk_len = first_chunk_len; + first_chunk_len = runtime->dma_bytes - rt5677_dsp->dma_offset; + second_chunk_len -= first_chunk_len; + } + + /* Copy first chunk */ + ret = rt5677_spi_read(RT5677_MIC_BUF_ADDR + sizeof(u32) + begin, + runtime->dma_area + rt5677_dsp->dma_offset, + first_chunk_len); + if (ret) + return ret; + rt5677_dsp->dma_offset += first_chunk_len; + if (rt5677_dsp->dma_offset == runtime->dma_bytes) + rt5677_dsp->dma_offset = 0; + + /* Copy second chunk */ + if (second_chunk_len) { + ret = rt5677_spi_read(RT5677_MIC_BUF_ADDR + sizeof(u32) + + begin + first_chunk_len, runtime->dma_area, + second_chunk_len); + if (!ret) + rt5677_dsp->dma_offset = second_chunk_len; + } + return ret; +} + +/* + * A delayed work that streams audio samples from the DSP mic buffer to the + * dma_area of the pcm runtime via SPI. + */ +static void rt5677_spi_copy_work(struct work_struct *work) +{ + struct rt5677_dsp *rt5677_dsp = + container_of(work, struct rt5677_dsp, copy_work.work); + struct snd_pcm_runtime *runtime; + u32 mic_write_offset; + size_t bytes_copied, period_bytes; + int ret = 0; + + /* Ensure runtime->dma_area buffer does not go away while copying. */ + mutex_lock(&rt5677_dsp->dma_lock); + if (!rt5677_dsp->substream) { + dev_err(rt5677_dsp->dev, "No pcm substream\n"); + goto done; + } + + runtime = rt5677_dsp->substream->runtime; + + if (rt5677_spi_mic_write_offset(&mic_write_offset)) { + dev_err(rt5677_dsp->dev, "No mic_write_offset\n"); + goto done; + } + + /* If this is the first time that we've asked for streaming data after + * a hotword is fired, we should start reading from the previous 2 + * seconds of audio from wherever the mic_write_offset is currently. + */ + if (rt5677_dsp->new_hotword) { + rt5677_dsp->new_hotword = false; + /* See if buffer wraparound happens */ + if (mic_write_offset < RT5677_MIC_BUF_FIRST_READ_SIZE) + rt5677_dsp->mic_read_offset = RT5677_MIC_BUF_BYTES - + (RT5677_MIC_BUF_FIRST_READ_SIZE - + mic_write_offset); + else + rt5677_dsp->mic_read_offset = mic_write_offset - + RT5677_MIC_BUF_FIRST_READ_SIZE; + } + + /* Copy all new samples from DSP's mic buffer to dma_area */ + bytes_copied = 0; + if (rt5677_dsp->mic_read_offset < mic_write_offset) { + /* One chunk in DSP's mic buffer */ + ret |= rt5677_spi_append_data(rt5677_dsp, + rt5677_dsp->mic_read_offset, mic_write_offset); + bytes_copied = mic_write_offset - rt5677_dsp->mic_read_offset; + } else if (rt5677_dsp->mic_read_offset > mic_write_offset) { + /* Wrap around, two chunks in DSP's mic buffer */ + ret |= rt5677_spi_append_data(rt5677_dsp, + rt5677_dsp->mic_read_offset, + RT5677_MIC_BUF_BYTES); + ret |= rt5677_spi_append_data(rt5677_dsp, 0, mic_write_offset); + bytes_copied = RT5677_MIC_BUF_BYTES - + rt5677_dsp->mic_read_offset + mic_write_offset; + } + if (ret) { + dev_err(rt5677_dsp->dev, "Copy failed %d\n", ret); + goto done; + } + + rt5677_dsp->mic_read_offset = mic_write_offset; + rt5677_dsp->avail_bytes += bytes_copied; + period_bytes = snd_pcm_lib_period_bytes(rt5677_dsp->substream); + + if (rt5677_dsp->avail_bytes >= period_bytes) { + snd_pcm_period_elapsed(rt5677_dsp->substream); + rt5677_dsp->avail_bytes = 0; + } + /* TODO benzh: use better delay time based on period_bytes */ + schedule_delayed_work(&rt5677_dsp->copy_work, msecs_to_jiffies(5)); +done: + mutex_unlock(&rt5677_dsp->dma_lock); +} + +struct page *rt5677_spi_pcm_page(struct snd_pcm_substream *substream, + unsigned long offset) +{ + return snd_pcm_lib_get_vmalloc_page(substream, offset); +} + +static struct snd_pcm_ops rt5677_spi_pcm_ops = { + .open = rt5677_spi_pcm_open, + .close = rt5677_spi_pcm_close, + .hw_params = rt5677_spi_hw_params, + .hw_free = rt5677_spi_hw_free, + .prepare = rt5677_spi_prepare, + .pointer = rt5677_spi_pcm_pointer, + .page = rt5677_spi_pcm_page, +}; + +static int rt5677_spi_pcm_probe(struct snd_soc_component *component) +{ + struct rt5677_dsp *rt5677_dsp; + + rt5677_dsp = devm_kzalloc(component->dev, sizeof(*rt5677_dsp), + GFP_KERNEL); + rt5677_dsp->dev = &g_spi->dev; + mutex_init(&rt5677_dsp->dma_lock); + INIT_DELAYED_WORK(&rt5677_dsp->copy_work, rt5677_spi_copy_work); + + snd_soc_component_set_drvdata(component, rt5677_dsp); + return 0; +} + +static const struct snd_soc_component_driver rt5677_spi_dai_component = { + .name = DRV_NAME, + .probe = rt5677_spi_pcm_probe, + .ops = &rt5677_spi_pcm_ops, +}; + /* Select a suitable transfer command for the next transfer to ensure * the transfer address is always naturally aligned while minimizing * the total number of transfers required. @@ -218,9 +541,45 @@ int rt5677_spi_write_firmware(u32 addr, const struct firmware *fw) } EXPORT_SYMBOL_GPL(rt5677_spi_write_firmware); +void rt5677_spi_hotword_detected(void) +{ + struct rt5677_dsp *rt5677_dsp; + + if (!g_spi) + return; + + rt5677_dsp = dev_get_drvdata(&g_spi->dev); + if (!rt5677_dsp) { + dev_err(&g_spi->dev, "Can't get rt5677_dsp\n"); + return; + } + + mutex_lock(&rt5677_dsp->dma_lock); + dev_info(rt5677_dsp->dev, "Hotword detected\n"); + rt5677_dsp->new_hotword = true; + mutex_unlock(&rt5677_dsp->dma_lock); + + schedule_delayed_work(&rt5677_dsp->copy_work, 0); +} +EXPORT_SYMBOL_GPL(rt5677_spi_hotword_detected); + static int rt5677_spi_probe(struct spi_device *spi) { + int ret; + g_spi = spi; + + ret = snd_soc_register_component(&spi->dev, &rt5677_spi_dai_component, + &rt5677_spi_dai, 1); + if (ret < 0) + dev_err(&spi->dev, "Failed to register component.\n"); + + return ret; +} + +static int rt5677_spi_remove(struct spi_device *spi) +{ + snd_soc_unregister_component(&spi->dev); return 0; } @@ -236,6 +595,7 @@ static struct spi_driver rt5677_spi_driver = { .acpi_match_table = ACPI_PTR(rt5677_spi_acpi_id), }, .probe = rt5677_spi_probe, + .remove = rt5677_spi_remove, }; module_spi_driver(rt5677_spi_driver); diff --git a/sound/soc/codecs/rt5677-spi.h b/sound/soc/codecs/rt5677-spi.h index 6ba3369dc235..3af36ec928e9 100644 --- a/sound/soc/codecs/rt5677-spi.h +++ b/sound/soc/codecs/rt5677-spi.h @@ -12,5 +12,6 @@ int rt5677_spi_read(u32 addr, void *rxbuf, size_t len); int rt5677_spi_write(u32 addr, const void *txbuf, size_t len); int rt5677_spi_write_firmware(u32 addr, const struct firmware *fw); +void rt5677_spi_hotword_detected(void); #endif /* __RT5677_SPI_H__ */ From patchwork Fri Sep 6 19:46:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135963 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 204321593 for ; Fri, 6 Sep 2019 19:51:46 +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 A8C7D20842 for ; Fri, 6 Sep 2019 19:51:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="dkbmRJB5"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fyOKSHzR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8C7D20842 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 E003415E4; Fri, 6 Sep 2019 21:50:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E003415E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799504; bh=qjYmvXQZ10S2t2sGM7DIIBvwT+2AsKKN2jr9Q/yDEbo=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=dkbmRJB5EYZwzw+F37dVQugXdDWB7k6z4BFmqKVi8+RaAQuULBAqt+Gfx0FzVCldr f/5ZPnIfy4jaR0WoPRHybr+6VHlG8HGhMNtXasftbLIlH6WzefiFyHqxSa0Ys2Z+uY EU8lSyy+vEOboUzQnR/5VvtzwJ05DQp01S2ZSxfA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 0376BF80611; Fri, 6 Sep 2019 21:48:01 +0200 (CEST) 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 32796F80639; Fri, 6 Sep 2019 21:47:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 F0638F80611 for ; Fri, 6 Sep 2019 21:47:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz F0638F80611 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fyOKSHzR" Received: by mail-pf1-x444.google.com with SMTP id d15so5198671pfo.10 for ; Fri, 06 Sep 2019 12:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gapN+hwSxlX78IFbIdAVK+5HSLsRdoV1q4n7vdli/0M=; b=fyOKSHzRz1Z4ZpCazORsupQKTsZRPUwAz/zEfvMErPCQG2PEWeq7X04+4ivUYgJ190 4xODZsonRh/LZyqHKGss44tNLRsFTSfP6hBfCV3jiNiJulW68Hw9r2wjH4nI6Tms03tI PJZ1Ir0eCpVjvT21g99SWFV2ImqNg6Ezn8vc4= 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=gapN+hwSxlX78IFbIdAVK+5HSLsRdoV1q4n7vdli/0M=; b=CVREJNGeESGzTBDmkxUcjaKwjlba72jvWBpAl14oqPfFmwbeDDAy/NS8IRC55ljnrO Kvd4VQU5QfNvBbmUMzNZjJj/3JIUWKxlbSSA0gga761M1n4o5b+AEvGqY6yvCwpaXRhB UOT2cOxzQCMXMVwNypzi71b/+LLeJv3SJxnHnb6eVElcUoPDSVmmDYzszbUAJxE44CTS fM/hAF5TsJ0WPiEx0PdmBekTeWwHDKZYBMsyvf3m7j/7lLS4563J9NqKYWjH0rgUnrhJ /nCCMQxTf6w1ONusVo+Kb16rN3qrqNjnuEbnbVHcBa+Uf1WQla2lpJXgrLdy70fDOZps SIYA== X-Gm-Message-State: APjAAAUuV0pQmQlpfE2iZXcNzFPJHVDp5+jqiMl9jUnmBnj3zTHdPb0O 4Q61oj4//Y/PNkoWx6G3Xnd6kNeRBg== X-Google-Smtp-Source: APXvYqwHylr6B3zkbaQtWvFsWxl1pBH6vAQPgfdRctKwf2KN5PsW859rr8CKNvRtkf8dC0ZBTe9CAQ== X-Received: by 2002:a63:c009:: with SMTP id h9mr9428539pgg.166.1567799272456; Fri, 06 Sep 2019 12:47:52 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id m4sm7504579pgs.71.2019.09.06.12.47.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:47:52 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:26 -0700 Message-Id: <20190906194636.217881-5-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 04/15] ASoC: rt5677: Load firmware via SPI 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" From: Ben Zhang The firmware rt5677_elf_vad is an ELF binary obtained from request_firmware(). Sections of the ELF are loaded to the DSP via SPI. A model (e.g. en_us.mmap) can optionally be loaded to the DSP at RT5677_MODEL_ADDR to overwrite the baked-in model in rt5677_elf_vad. When 'DSP VAD Switch' is turned on, rt5677_set_vad_source() enables the following digital path: DMIC L1 -> Mono DMIC L Mux -> Mono ADC2 L Mux -> Mono ADC MIXL -> VAD ADC Mux -> IB01 Mux Then we switch to DSP mode, load firmware, and let DSP run. When a hotword is detected, an interrupt is fired and rt5677_irq() is called. When 'DSP VAD Switch' is turned off, the codec is set back to normal mode. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 306 +++++++++++++++++++++++++++++++------- sound/soc/codecs/rt5677.h | 1 + 2 files changed, 254 insertions(+), 53 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 315a3d39bc09..35d4ec1b7dfd 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -38,6 +38,10 @@ #define RT5677_DEVICE_ID 0x6327 +/* Register controlling boot vector */ +#define RT5677_DSP_BOOT_VECTOR 0x1801f090 +#define RT5677_MODEL_ADDR 0x5FFC9800 + #define RT5677_PR_RANGE_BASE (0xff + 1) #define RT5677_PR_SPACING 0x100 @@ -701,6 +705,210 @@ static void rt5677_set_dsp_mode(struct snd_soc_component *component, bool on) } } +static unsigned int rt5677_set_vad_source( + struct snd_soc_component *component) +{ + struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); + + /* Mono ADC Capture Switch = unmute (default) */ + regmap_update_bits(rt5677->regmap, RT5677_MONO_ADC_DIG_VOL, + RT5677_L_MUTE, 0); + + /* Mono ADC Boost Volume = 24dB */ + regmap_update_bits(rt5677->regmap, RT5677_ADC_BST_CTRL2, + RT5677_MONO_ADC_L_BST_MASK | RT5677_MONO_ADC_R_BST_MASK, + (0x2 << RT5677_MONO_ADC_L_BST_SFT) | + (0x2 << RT5677_MONO_ADC_R_BST_SFT)); + + /* Mono ADC MIXL = Mono ADC2 L Mux (unmute) + * Mono ADC1 L Mux (mute) + * Mono ADC2 L Mux = Mono DMIC L Mux + * Mono DMIC L Mux = DMIC1 (left) + */ + regmap_update_bits(rt5677->regmap, RT5677_MONO_ADC_MIXER, + RT5677_M_MONO_ADC_L2 | RT5677_M_MONO_ADC_L1 | + RT5677_SEL_MONO_ADC_L2_MASK | RT5677_SEL_MONO_DMIC_L_MASK, + RT5677_M_MONO_ADC_L1 | (1 << RT5677_SEL_MONO_ADC_L2_SFT) | + (0 << RT5677_SEL_MONO_DMIC_L_SFT)); + + /* DMIC1 power = enabled + * DMIC CLK = 256 * fs / 12 + */ + regmap_update_bits(rt5677->regmap, RT5677_DMIC_CTRL1, + RT5677_DMIC_1_EN_MASK | RT5677_DMIC_CLK_MASK, + RT5677_DMIC_1_EN | (5 << RT5677_DMIC_CLK_SFT)); + + /* I2S pre divide 2 = /6 (clk_sys2) */ + regmap_update_bits(rt5677->regmap, RT5677_CLK_TREE_CTRL1, + RT5677_I2S_PD2_MASK, RT5677_I2S_PD2_6); + + /* System Clock = MCLK1 + * Stereo ADC/DAC over sample rate = 128Fs (default) + */ + regmap_write(rt5677->regmap, RT5677_GLB_CLK1, 0x0000); + + /* DSP Clock = MCLK1 (bypassed PLL2) */ + regmap_write(rt5677->regmap, RT5677_GLB_CLK2, + RT5677_DSP_CLK_SRC_BYPASS); + + /* Clock source for Mono L ADC = clk_sys2 */ + regmap_update_bits(rt5677->regmap, RT5677_ASRC_6, + RT5677_AD_MONOL_CLK_SEL_MASK, 7 << RT5677_AD_MONOL_CLK_SEL_SFT); + + /* SAD Threshold1 */ + regmap_write(rt5677->regmap, RT5677_VAD_CTRL2, 0x013f); + /* SAD Threshold2 */ + regmap_write(rt5677->regmap, RT5677_VAD_CTRL3, 0x0ae5); + /* SAD Sample Rate Converter = Up 6 (8K to 48K) + * SAD Output Sample Rate = Same as I2S + * VAD ADC Mux = MONO ADC MIX L + * SAD Threshold3 + */ + regmap_write(rt5677->regmap, RT5677_VAD_CTRL4, + 0x01 << RT5677_VAD_SRC_SFT | + 0x7f << RT5677_VAD_LV_DIFF_SFT); + /* Minimum frame level within a pre-determined duration = 32 frames + * Bypass ADPCM Encoder/Decoder = Bypass ADPCM + * Automatic Push Data to SAD Buffer Once SAD Flag is triggered = enable + * SAD Buffer Over-Writing = enable + * SAD Buffer Pop Mode Control = disable + * SAD Buffer Push Mode Control = enable + * SAD Detector Control = enable + * SAD Function Control = enable + * SAD Function Reset = normal + */ + regmap_write(rt5677->regmap, RT5677_VAD_CTRL1, + RT5677_VAD_FUNC_RESET | RT5677_VAD_FUNC_ENABLE | + RT5677_VAD_DET_ENABLE | RT5677_VAD_BUF_PUSH | + RT5677_VAD_BUF_OW | RT5677_VAD_FG2ENC | + RT5677_VAD_ADPCM_BYPASS | 1 << RT5677_VAD_MIN_DUR_SFT); + + /* InBound0/1 Source = VAD ADC/DAC1 FS */ + regmap_update_bits(rt5677->regmap, RT5677_DSP_INB_CTRL1, + RT5677_IB01_SRC_MASK, 4 << RT5677_IB01_SRC_SFT); + + /* IRQ Source of VAD Jack Detection = enable */ + regmap_write(rt5677->regmap, RT5677_IRQ_CTRL2, 0x4000); + + /* Enable Gating Mode with MCLK = enable */ + regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x1); + + /* Private register, no doc */ + regmap_update_bits(rt5677->regmap, RT5677_PR_BASE + RT5677_BIAS_CUR4, + 0x0f00, 0x0100); + + /* adc mono left filter = power on */ + regmap_update_bits(rt5677->regmap, RT5677_PWR_DIG2, + RT5677_PWR_ADC_MF_L, RT5677_PWR_ADC_MF_L); + + /* LDO2 output = 1.2V + * LDO1 output = 1.2V (LDO_IN = 1.8V) + */ + regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1, + RT5677_LDO1_SEL_MASK | RT5677_LDO2_SEL_MASK, + 5 << RT5677_LDO1_SEL_SFT | 5 << RT5677_LDO2_SEL_SFT); + + /* Codec core power = power on + * LDO1 power = power on + */ + regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2, + RT5677_PWR_CORE | RT5677_PWR_LDO1, + RT5677_PWR_CORE | RT5677_PWR_LDO1); + + /* Isolation for DCVDD4 = normal (set during probe) + * Isolation for DCVDD2 = normal (set during probe) + * Isolation for DSP = normal + * Isolation for Band 0~7 = disable + * Isolation for InBound 4~10 and OutBound 4~10 = disable + */ + regmap_write(rt5677->regmap, RT5677_PWR_DSP2, + RT5677_PWR_CORE_ISO | RT5677_PWR_DSP_ISO | + RT5677_PWR_SR7_ISO | RT5677_PWR_SR6_ISO | + RT5677_PWR_SR5_ISO | RT5677_PWR_SR4_ISO | + RT5677_PWR_SR3_ISO | RT5677_PWR_SR2_ISO | + RT5677_PWR_SR1_ISO | RT5677_PWR_SR0_ISO | + RT5677_PWR_MLT_ISO); + + /* System Band 0~7 = power on + * InBound 4~10 and OutBound 4~10 = power on + * DSP = power on + * DSP CPU = stop (will be set to "run" after firmware loaded) + */ + regmap_write(rt5677->regmap, RT5677_PWR_DSP1, + RT5677_PWR_SR7 | RT5677_PWR_SR6 | + RT5677_PWR_SR5 | RT5677_PWR_SR4 | + RT5677_PWR_SR3 | RT5677_PWR_SR2 | + RT5677_PWR_SR1 | RT5677_PWR_SR0 | + RT5677_PWR_MLT | RT5677_PWR_DSP | + RT5677_PWR_DSP_CPU); + + return 0; +} + +static int rt5677_parse_and_load_dsp(struct rt5677_priv *rt5677, const u8 *buf, + unsigned int len) +{ + struct snd_soc_component *component = rt5677->component; + Elf32_Ehdr *elf_hdr; + Elf32_Phdr *pr_hdr; + Elf32_Half i; + int ret = 0; + + if (!buf || (len < sizeof(Elf32_Ehdr))) + return -ENOMEM; + + elf_hdr = (Elf32_Ehdr *)buf; +#ifndef EM_XTENSA +#define EM_XTENSA 94 +#endif + if (strncmp(elf_hdr->e_ident, ELFMAG, sizeof(ELFMAG) - 1)) + dev_err(component->dev, "Wrong ELF header prefix\n"); + if (elf_hdr->e_ehsize != sizeof(Elf32_Ehdr)) + dev_err(component->dev, "Wrong Elf header size\n"); + if (elf_hdr->e_machine != EM_XTENSA) + dev_err(component->dev, "Wrong DSP code file\n"); + + if (len < elf_hdr->e_phoff) + return -ENOMEM; + pr_hdr = (Elf32_Phdr *)(buf + elf_hdr->e_phoff); + for (i = 0; i < elf_hdr->e_phnum; i++) { + /* TODO: handle p_memsz != p_filesz */ + if (pr_hdr->p_paddr && pr_hdr->p_filesz) { + dev_info(component->dev, "Load 0x%x bytes to 0x%x\n", + pr_hdr->p_filesz, pr_hdr->p_paddr); + + ret = rt5677_spi_write(pr_hdr->p_paddr, + buf + pr_hdr->p_offset, + pr_hdr->p_filesz); + if (ret) + dev_err(component->dev, "Load firmware failed %d\n", + ret); + } + pr_hdr++; + } + return ret; +} + +static int rt5677_load_dsp_from_file(struct snd_soc_component *component) +{ + struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); + const struct firmware *fwp; + int ret = 0; + + /* Load dsp firmware from rt5677_elf_vad file */ + ret = request_firmware(&fwp, "rt5677_elf_vad", component->dev); + if (ret) { + dev_err(component->dev, "Request rt5677_elf_vad failed %d\n", + ret); + return ret; + } + dev_info(component->dev, "Requested rt5677_elf_vad (%zu)\n", fwp->size); + + ret = rt5677_parse_and_load_dsp(rt5677, fwp->data, fwp->size); + release_firmware(fwp); + return ret; +} + static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) { struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); @@ -710,74 +918,52 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) if (!IS_ENABLED(CONFIG_SND_SOC_RT5677_SPI)) return -ENXIO; + dev_info(component->dev, "DSP VAD: on=%d, activity=%d\n", on, activity); if (on && !activity) { activity = true; - regcache_cache_only(rt5677->regmap, false); - regcache_cache_bypass(rt5677->regmap, true); + /* Set GPIO1 as an output pin driving a 0. Firmware will + * raise GPIO1 upon hotword detect. + */ + regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL2, + RT5677_GPIO1_DIR_MASK | RT5677_GPIO1_OUT_MASK | + RT5677_GPIO1_P_MASK, RT5677_GPIO1_DIR_OUT | + RT5677_GPIO1_OUT_LO | RT5677_GPIO1_P_NOR); + regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1, + RT5677_GPIO1_PIN_MASK, RT5677_GPIO1_PIN_GPIO1); - regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x1); - regmap_update_bits(rt5677->regmap, - RT5677_PR_BASE + RT5677_BIAS_CUR4, 0x0f00, 0x0f00); - regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1, - RT5677_LDO1_SEL_MASK, 0x0); - regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG2, - RT5677_PWR_LDO1, RT5677_PWR_LDO1); - switch (rt5677->type) { - case RT5677: - regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK1, - RT5677_MCLK_SRC_MASK, RT5677_MCLK2_SRC); - regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK2, - RT5677_PLL2_PR_SRC_MASK | - RT5677_DSP_CLK_SRC_MASK, - RT5677_PLL2_PR_SRC_MCLK2 | - RT5677_DSP_CLK_SRC_BYPASS); - break; - case RT5676: - regmap_update_bits(rt5677->regmap, RT5677_GLB_CLK2, - RT5677_DSP_CLK_SRC_MASK, - RT5677_DSP_CLK_SRC_BYPASS); - break; - default: - break; - } - regmap_write(rt5677->regmap, RT5677_PWR_DSP2, 0x07ff); - regmap_write(rt5677->regmap, RT5677_PWR_DSP1, 0x07fd); + rt5677_set_vad_source(component); rt5677_set_dsp_mode(component, true); - ret = request_firmware(&rt5677->fw1, RT5677_FIRMWARE1, - component->dev); - if (ret == 0) { - rt5677_spi_write_firmware(0x50000000, rt5677->fw1); - release_firmware(rt5677->fw1); - } + /* Boot the firmware from IRAM instead of SRAM0. */ + rt5677_dsp_mode_i2c_write_addr(rt5677, RT5677_DSP_BOOT_VECTOR, + 0x0009, 0x0003); + rt5677_dsp_mode_i2c_write_addr(rt5677, RT5677_DSP_BOOT_VECTOR, + 0x0019, 0x0003); + rt5677_dsp_mode_i2c_write_addr(rt5677, RT5677_DSP_BOOT_VECTOR, + 0x0009, 0x0003); - ret = request_firmware(&rt5677->fw2, RT5677_FIRMWARE2, - component->dev); - if (ret == 0) { - rt5677_spi_write_firmware(0x60000000, rt5677->fw2); - release_firmware(rt5677->fw2); - } + ret = rt5677_load_dsp_from_file(component); + /* Set DSP CPU to Run */ regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x1, 0x0); - - regcache_cache_bypass(rt5677->regmap, false); - regcache_cache_only(rt5677->regmap, true); } else if (!on && activity) { activity = false; - regcache_cache_only(rt5677->regmap, false); - regcache_cache_bypass(rt5677->regmap, true); - - regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x1, 0x1); + /* Set DSP CPU to Stop */ + regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, + RT5677_PWR_DSP_CPU, RT5677_PWR_DSP_CPU); rt5677_set_dsp_mode(component, false); - regmap_write(rt5677->regmap, RT5677_PWR_DSP1, 0x0001); - regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec); + /* Disable and clear VAD interrupt */ + regmap_write(rt5677->regmap, RT5677_VAD_CTRL1, 0x2184); + regmap_update_bits(rt5677->regmap, RT5677_IRQ_CTRL2, + 0xF000, 0x0000); + + /* Set GPIO1 pin back to be IRQ output for jack detect */ + regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1, + RT5677_GPIO1_PIN_MASK, RT5677_GPIO1_PIN_IRQ); - regcache_cache_bypass(rt5677->regmap, false); - regcache_mark_dirty(rt5677->regmap); - regcache_sync(rt5677->regmap); } return 0; @@ -4938,6 +5124,17 @@ static struct snd_soc_dai_driver rt5677_dai[] = { }, .ops = &rt5677_aif_dai_ops, }, + { + .name = "rt5677-dspbuffer", + .id = RT5677_DSPBUFF, + .capture = { + .stream_name = "DSP Buffer", + .channels_min = 1, + .channels_max = 1, + .rates = SNDRV_PCM_RATE_16000, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + }, + }, }; static const struct snd_soc_component_driver soc_component_dev_rt5677 = { @@ -5081,6 +5278,9 @@ static irqreturn_t rt5677_irq(int unused, void *data) mutex_lock(&rt5677->irq_lock); + if (rt5677->dsp_vad_en) + rt5677_spi_hotword_detected(); + /* * Loop to handle interrupts until the last i2c read shows no pending * irqs. The interrupt line is shared by multiple interrupt sources. diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index 213f4b8ca269..2bbd618b51ac 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1730,6 +1730,7 @@ enum { RT5677_AIF4, RT5677_AIF5, RT5677_AIFS, + RT5677_DSPBUFF, }; enum { From patchwork Fri Sep 6 19:46:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135965 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 D50A815E6 for ; Fri, 6 Sep 2019 19:52:28 +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 6962120854 for ; Fri, 6 Sep 2019 19:52:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="nFheuqSK"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="afmphl1F" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6962120854 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 949D7820; Fri, 6 Sep 2019 21:51:36 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 949D7820 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799546; bh=DMW6yfqfohf1GGOFsCCb3OU1liHID74v1Kb+xvKbjVY=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nFheuqSKPlSqfRNhDTqvAL1jM0gFGmBHmHXR90tJRusYFj1GtMrPKmCR+naZ4f+U/ r62esG5qah3WMZavEw2fpQfgmthbKsOCvom0SxGiQkdoO1D6u5QfcP/6H0Wh5Auh6n 8f2NnaKIZaTXFkl9bbu5syxaIN+douecmzrs7y7Y= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 40656F8065A; Fri, 6 Sep 2019 21:48:07 +0200 (CEST) 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 AB7E0F8063A; Fri, 6 Sep 2019 21:48:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (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 A3A98F80635 for ; Fri, 6 Sep 2019 21:47:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A3A98F80635 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="afmphl1F" Received: by mail-pl1-x642.google.com with SMTP id f19so3642231plr.3 for ; Fri, 06 Sep 2019 12:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YVCTQkuykSmc51JVcb5TCMfC/BldcbHzDSM0b9aVMTE=; b=afmphl1F0j+2pBwX51htvQ6z2OZ1fie7MEB7tnc4tFz0IXkBycTN7BsJOSXkvK+hqR vwhWIG10GeSe8jPBU2VofEITRGE56cxV1iS70wpQCogDS4TSUnm9mqQsn1lrCBlEspMr VKN1RfNw8KbytdETzu7O3roYESqRnwkN4acVo= 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=YVCTQkuykSmc51JVcb5TCMfC/BldcbHzDSM0b9aVMTE=; b=oRENkdo4KSU1ykdf0mUNXlXhJoC9t4aB5adY+fMnVipIF1aI0/6YLb+s3zP3LykEmT y2B4uXraW+jmPCSdwpXjWcTLanMp05hdmVPKFDKt5oxxui7TqZ09A9/kOxCHDbQ45TMR kPDv+rauokb2v9eTvlOyb+Qpnh+m5umWGOKEPKwoEdF6Ss/hAqYxQpDQdrvfPwgzGBbr 7TDZy2OklsRwuUOGRGydj6zGnQOvomw1x6moyB7Y78aaN66gn1fDAlCg+cJIyacyVHMN 4CGXoSRPd1xo/HcOPd1P45Az4PDCdPTOaxL1cdm4Yr8f+3y89wVKmLng2agJen5+pILM pJTQ== X-Gm-Message-State: APjAAAVGTeH5RKKBPUmqXdAytKCws41DRCoz4LbLuH9/D7kKb4pYDBjB u3QIQf1IWTmb5vy6hERC1I5wbltOpQ== X-Google-Smtp-Source: APXvYqyvgop/xGqvDaCerkvm8+A+wR1wnsg2ykOdlUA4S5qA49vvo89GtvGlQHa6Moi6G1mDg4UBpQ== X-Received: by 2002:a17:902:8f90:: with SMTP id z16mr11075628plo.138.1567799275499; Fri, 06 Sep 2019 12:47:55 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id e24sm7122116pgk.21.2019.09.06.12.47.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:47:55 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:27 -0700 Message-Id: <20190906194636.217881-6-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 05/15] ASoC: rt5677: Auto enable/disable DSP for hotwording 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" From: Ben Zhang The kcontrol 'DSP VAD Switch' is automatically enabled/disabled when the hotwording PCM stream is opened/closed. A function pointer in struct rt5677_priv is used to avoid module dependency cycle between snd_soc_rt5677 and snd_soc_rt5677_spi. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677-spi.c | 12 ++++++++++++ sound/soc/codecs/rt5677.c | 6 +++++- sound/soc/codecs/rt5677.h | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt5677-spi.c b/sound/soc/codecs/rt5677-spi.c index 62621fe4747c..25d75a803cb5 100644 --- a/sound/soc/codecs/rt5677-spi.c +++ b/sound/soc/codecs/rt5677-spi.c @@ -26,6 +26,7 @@ #include +#include "rt5677.h" #include "rt5677-spi.h" #define DRV_NAME "rt5677spi" @@ -100,6 +101,12 @@ static struct snd_soc_dai_driver rt5677_spi_dai = { /* PCM for streaming audio from the DSP buffer */ static int rt5677_spi_pcm_open(struct snd_pcm_substream *substream) { + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_component *component = + snd_soc_rtdcom_lookup(rtd, "rt5677"); + struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); + + rt5677->set_dsp_vad(component, true); snd_soc_set_runtime_hwparams(substream, &rt5677_spi_pcm_hardware); return 0; } @@ -109,10 +116,15 @@ static int rt5677_spi_pcm_close(struct snd_pcm_substream *substream) struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME); + struct snd_soc_component *codec_component = + snd_soc_rtdcom_lookup(rtd, "rt5677"); + struct rt5677_priv *rt5677 = + snd_soc_component_get_drvdata(codec_component); struct rt5677_dsp *rt5677_dsp = snd_soc_component_get_drvdata(component); cancel_delayed_work_sync(&rt5677_dsp->copy_work); + rt5677->set_dsp_vad(codec_component, false); return 0; } diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 35d4ec1b7dfd..9cdfe7d488fe 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -918,7 +918,9 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) if (!IS_ENABLED(CONFIG_SND_SOC_RT5677_SPI)) return -ENXIO; + rt5677->dsp_vad_en = on; dev_info(component->dev, "DSP VAD: on=%d, activity=%d\n", on, activity); + if (on && !activity) { activity = true; @@ -1005,7 +1007,8 @@ static int rt5677_dsp_vad_put(struct snd_kcontrol *kcontrol, rt5677->dsp_vad_en = !!ucontrol->value.integer.value[0]; if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) - rt5677_set_dsp_vad(component, rt5677->dsp_vad_en); + rt5677_set_dsp_vad(component, + !!ucontrol->value.integer.value[0]); return 0; } @@ -5471,6 +5474,7 @@ static int rt5677_i2c_probe(struct i2c_client *i2c) return -ENOMEM; rt5677->dev = &i2c->dev; + rt5677->set_dsp_vad = rt5677_set_dsp_vad; i2c_set_clientdata(i2c, rt5677); if (i2c->dev.of_node) { diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index 2bbd618b51ac..ec5be7e01fd1 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1854,6 +1854,8 @@ struct rt5677_priv { struct irq_domain *domain; struct mutex irq_lock; unsigned int irq_en; + + int (*set_dsp_vad)(struct snd_soc_component *component, bool on); }; int rt5677_sel_asrc_clk_src(struct snd_soc_component *component, From patchwork Fri Sep 6 19:46:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135967 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 BA9FB1593 for ; Fri, 6 Sep 2019 19:52:58 +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 4D8C020842 for ; Fri, 6 Sep 2019 19:52:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="vR/XE07F"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XKzI8t6p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D8C020842 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 861BD1676; Fri, 6 Sep 2019 21:52:06 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 861BD1676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799576; bh=7+iA4bm+nxOnHMRnA6YQx4x4tuJrfec+4MCPDcKK+wI=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vR/XE07Fa29Kj/1PkrdkQzPNd0wgfvQJeluEqAcQHMolwiURkgkL1AEllDO/MOUW8 Flx8teSblLe/if1Wr1mTKf61jOprbRHr1cmfbpaaQXU769jmKIcrhJ3MpzxfT6bUMI t1w6mztZSEwj8OGS80TzI3fOTnt5b0sO70x811LM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id CB742F80673; Fri, 6 Sep 2019 21:48:11 +0200 (CEST) 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 09469F80639; Fri, 6 Sep 2019 21:48:06 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 50AE8F80639 for ; Fri, 6 Sep 2019 21:48:02 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 50AE8F80639 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XKzI8t6p" Received: by mail-pf1-x444.google.com with SMTP id w22so5208423pfi.9 for ; Fri, 06 Sep 2019 12:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n/0NVdzNWICBGegkM7LroKepQhiV/8r77ExOHngHUuI=; b=XKzI8t6p2bfJm4IRrEjlmupWX2xoEuL3WkdZ0Q8Q/KA6G7EQXsfW743EdcCJ9j32dV DcKMV+p9Y9go3gwdK/X/xLRBChiONU4/a1bZwdhjsNmFglp2O0XK/Yia6EsxDkUsMdJj WWGOZQyL5ln2sK5IPVFyNcBZhxR256icbDTQo= 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=n/0NVdzNWICBGegkM7LroKepQhiV/8r77ExOHngHUuI=; b=YdDZ+o/kQ4XoKuYeUYC/kBWCIGuvfE4AdS5T8oZ5vxSlF7xImzmVawN+RajLEBkdQP ke9ydzoDG3kM92kvh393MGIAbkIU1Bf0f1M+aWORltpjJ24YEzjn7EfoKZ40/91XA6Xi GUcI9b8d+BS4Yd3p+VuT1ICkNPTUVS8JRYuNXtJbe8CG+HHrIRJCsZai6qF8FpwWzu5Q I9kBvA8+HbeiltMAw0sYS7nmlToA+VdrLLCuafVET2/fy+qBfUV7UZ/qVawwwn/AbfbJ Y0MwMhD4FkJ8YNnZnyV9+0KnalntosFqp8IeYZ46X7GOSa1ileUk7YWngZqIoykTb403 /D1w== X-Gm-Message-State: APjAAAVkFgYdUslWRko7S60zK3T0IReQH+ylElBn+Eva6pQ0SoMTgWS7 yGxkMzm8eTZI84/AS9XdJ+6XpK32FQ== X-Google-Smtp-Source: APXvYqy3bPjuLD6bPHfRpcXX/a0WQG9hLr+QL+drr+KgpZDfXH+9HyJXq+VVyfPkXP9AZToU+Bnyug== X-Received: by 2002:a63:3203:: with SMTP id y3mr9586994pgy.191.1567799280467; Fri, 06 Sep 2019 12:48:00 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id o129sm7174895pfg.1.2019.09.06.12.47.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:00 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:28 -0700 Message-Id: <20190906194636.217881-7-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Cezary Rojewski , Kuninori Morimoto , Takashi Iwai , Jie Yang , Pierre-Louis Bossart , Liam Girdwood , Ben Zhang , Mark Brown , Steve Winslow , Curtis Malainey , Thomas Gleixner , Allison Randal Subject: [alsa-devel] [RFC 06/15] ASoC: bdw-rt5677: Add a DAI link for rt5677 SPI PCM device 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" From: Ben Zhang This link is needed for the RT5677 DSP to do hotwording Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/intel/boards/bdw-rt5677.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sound/soc/intel/boards/bdw-rt5677.c b/sound/soc/intel/boards/bdw-rt5677.c index 4a4d3353e26d..a02622fae035 100644 --- a/sound/soc/intel/boards/bdw-rt5677.c +++ b/sound/soc/intel/boards/bdw-rt5677.c @@ -74,6 +74,7 @@ static const struct snd_soc_dapm_route bdw_rt5677_map[] = { /* CODEC BE connections */ {"SSP0 CODEC IN", NULL, "AIF1 Capture"}, {"AIF1 Playback", NULL, "SSP0 CODEC OUT"}, + {"DSP Capture", NULL, "DSP Buffer"}, }; static const struct snd_kcontrol_new bdw_rt5677_controls[] = { @@ -258,6 +259,16 @@ SND_SOC_DAILINK_DEF(platform, SND_SOC_DAILINK_DEF(be, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RT5677CE:00", "rt5677-aif1"))); +/* Wake on voice interface */ +SND_SOC_DAILINK_DEF(fe_dsp, + DAILINK_COMP_ARRAY(COMP_CPU("spi-RT5677AA:00"))); + +SND_SOC_DAILINK_DEF(platform_dsp, + DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-RT5677AA:00"))); + +SND_SOC_DAILINK_DEF(be_dsp, + DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RT5677CE:00", "rt5677-dspbuffer"))); + static struct snd_soc_dai_link bdw_rt5677_dais[] = { /* Front End DAI links */ { @@ -276,6 +287,13 @@ static struct snd_soc_dai_link bdw_rt5677_dais[] = { SND_SOC_DAILINK_REG(fe, dummy, platform), }, + /* Non-DPCM links */ + { + .name = "Codec DSP", + .stream_name = "Wake on Voice", + SND_SOC_DAILINK_REG(fe_dsp, be_dsp, platform_dsp), + }, + /* Back End DAI links */ { /* SSP0 - Codec */ From patchwork Fri Sep 6 19:46:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135969 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 6C75615E6 for ; Fri, 6 Sep 2019 19:53: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 023B921907 for ; Fri, 6 Sep 2019 19:53:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="qY/5iccG"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="L78QqkeG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 023B921907 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 2C50915E4; Fri, 6 Sep 2019 21:52:51 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2C50915E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799621; bh=xyGRq9IOeoqWWYzW8HOF0LmIVlCJ5pCOD+dUANvmt5w=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=qY/5iccGWUCkCcF3iGqdrj8OJyBXxwZ8Qm/cszuOKEjE6xGIWIs+Ej5E9pBPhXoHu sRECTV0+fE1iSZcXoA6OL95rtIw0HlKkhzIUpkejV7TqkKfGXTAjCmJu+FKcbFbMw+ K2WOClw2IL7tTVO2mvjoGBlTgC6wx2kq9NH+i0Io= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 5E5A6F8067A; Fri, 6 Sep 2019 21:48:15 +0200 (CEST) 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 5D6F0F80671; Fri, 6 Sep 2019 21:48:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 2B641F80649 for ; Fri, 6 Sep 2019 21:48:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2B641F80649 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="L78QqkeG" Received: by mail-pl1-x644.google.com with SMTP id d3so3679328plr.1 for ; Fri, 06 Sep 2019 12:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pllqCVA+R/UnPqv2tlb9+gzMN21zylvfyhR5C3t3ahU=; b=L78QqkeG1uic4wb4e4O6CpiVbEUwZshI6Av/86E51UYQ8zRG0hu8gMjd5K9J6vH+fS S43ekhypDVv9Cx80mG5IWFLsc+J8XFw8m4+d2pZuYPM+N2t0A3Cx2KMBZhv6D6p/rpl4 /ALZBpLaDKEivtnJwifAQ4TlXfqB6WUvz3Fc8= 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=pllqCVA+R/UnPqv2tlb9+gzMN21zylvfyhR5C3t3ahU=; b=cbgKgBpOqMu3PXwzwhbO2QrPq/sGl3JXmZ+/UxUV0otjC8mmxPibstlD3SACKhb4GI lMrsCgsAEDXLYtlDqKuOHecdESrjq47LpJxuDunIUzOlc3sha6Phjnw9ITbxKVXrCUok 9POsxdcm9HJQoxESTRt0df00M5JOI7lo57nOmqjCXCIsiAcHgAyu35dIgB3CCblmUP0J ndHyJe93RbADfW0Jirr/jPiK3/n1MwenpoZAwVoG/bZMA71CbuAOjc5mjjj3d3GDWVwf qm+QTu7Gq881GX5BCtetnjxn3DnVMemVHmeQ8cKMCaloOiqmTzqNeAyuS4jSZP2gqGCA F7QA== X-Gm-Message-State: APjAAAUpH+YGuVVAYIVwc/PinpB03IpZbmXpY5i6QK2SVHun/LtWYHUJ BFdMoQMy0HxNlFNwZ+xLWOcRWiRhYQ== X-Google-Smtp-Source: APXvYqzzA+RK/+H/vEubq0n3csZbv4Sqjupr9FXXwbj0GJRoQkbXSrJ04m4JSM9xVbZMx/KrTnL/Cw== X-Received: by 2002:a17:902:a415:: with SMTP id p21mr10347968plq.319.1567799282967; Fri, 06 Sep 2019 12:48:02 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id m19sm4842322pjv.9.2019.09.06.12.48.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:02 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:29 -0700 Message-Id: <20190906194636.217881-8-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 07/15] ASoC: rt5677: Enable jack detect while DSP is running 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" From: Ben Zhang Before a hotword is detected, GPIO1 pin is configured as IRQ output so that jack detect works. When a hotword is detected, the DSP firmware configures the GPIO1 pin as GPIO1 and drives a 1. rt5677_irq() is called after a rising edge on the GPIO1 pin, due to either jack detect event or hotword event, or both. All possible events are checked and handled in rt5677_irq() where GPIO1 pin is configured back to IRQ output if a hotword is detected. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 64 +++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 9cdfe7d488fe..8f5e4882120c 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -312,6 +312,8 @@ static bool rt5677_volatile_register(struct device *dev, unsigned int reg) case RT5677_IRQ_CTRL1: case RT5677_IRQ_CTRL2: case RT5677_GPIO_ST: + case RT5677_GPIO_CTRL1: /* Modified by DSP firmware */ + case RT5677_GPIO_CTRL2: /* Modified by DSP firmware */ case RT5677_DSP_INB1_SRC_CTRL4: case RT5677_DSP_INB2_SRC_CTRL4: case RT5677_DSP_INB3_SRC_CTRL4: @@ -787,8 +789,11 @@ static unsigned int rt5677_set_vad_source( regmap_update_bits(rt5677->regmap, RT5677_DSP_INB_CTRL1, RT5677_IB01_SRC_MASK, 4 << RT5677_IB01_SRC_SFT); - /* IRQ Source of VAD Jack Detection = enable */ - regmap_write(rt5677->regmap, RT5677_IRQ_CTRL2, 0x4000); + /* VAD/SAD is not routed to the IRQ output (i.e. MX-BE[14] = 0), but it + * is routed to DSP_IRQ_0, so DSP firmware may use it to sleep and save + * power. See ALC5677 datasheet section 9.17 "GPIO, Interrupt and Jack + * Detection" for more info. + */ /* Enable Gating Mode with MCLK = enable */ regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x1); @@ -924,15 +929,15 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) if (on && !activity) { activity = true; - /* Set GPIO1 as an output pin driving a 0. Firmware will - * raise GPIO1 upon hotword detect. + /* Before a hotword is detected, GPIO1 pin is configured as IRQ + * output so that jack detect works. When a hotword is detected, + * the DSP firmware configures the GPIO1 pin as GPIO1 and + * drives a 1. rt5677_irq() is called after a rising edge on + * the GPIO1 pin, due to either jack detect event or hotword + * event, or both. All possible events are checked and handled + * in rt5677_irq() where GPIO1 pin is configured back to IRQ + * output if a hotword is detected. */ - regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL2, - RT5677_GPIO1_DIR_MASK | RT5677_GPIO1_OUT_MASK | - RT5677_GPIO1_P_MASK, RT5677_GPIO1_DIR_OUT | - RT5677_GPIO1_OUT_LO | RT5677_GPIO1_P_NOR); - regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1, - RT5677_GPIO1_PIN_MASK, RT5677_GPIO1_PIN_GPIO1); rt5677_set_vad_source(component); rt5677_set_dsp_mode(component, true); @@ -952,6 +957,8 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) } else if (!on && activity) { activity = false; + /* Don't turn off the DSP while handling irqs */ + mutex_lock(&rt5677->irq_lock); /* Set DSP CPU to Stop */ regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, RT5677_PWR_DSP_CPU, RT5677_PWR_DSP_CPU); @@ -959,13 +966,12 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) /* Disable and clear VAD interrupt */ regmap_write(rt5677->regmap, RT5677_VAD_CTRL1, 0x2184); - regmap_update_bits(rt5677->regmap, RT5677_IRQ_CTRL2, - 0xF000, 0x0000); /* Set GPIO1 pin back to be IRQ output for jack detect */ regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1, RT5677_GPIO1_PIN_MASK, RT5677_GPIO1_PIN_IRQ); + mutex_unlock(&rt5677->irq_lock); } return 0; @@ -5273,6 +5279,28 @@ static const struct rt5677_irq_desc rt5677_irq_descs[] = { }, }; +bool rt5677_check_hotword(struct rt5677_priv *rt5677) +{ + int reg_gpio; + + if (!rt5677->is_dsp_mode) + return false; + + if (regmap_read(rt5677->regmap, RT5677_GPIO_CTRL1, ®_gpio)) + return false; + + /* Firmware sets GPIO1 pin to be GPIO1 after hotword is detected */ + if ((reg_gpio & RT5677_GPIO1_PIN_MASK) == RT5677_GPIO1_PIN_IRQ) + return false; + + /* Set GPIO1 pin back to be IRQ output for jack detect */ + regmap_update_bits(rt5677->regmap, RT5677_GPIO_CTRL1, + RT5677_GPIO1_PIN_MASK, RT5677_GPIO1_PIN_IRQ); + + rt5677_spi_hotword_detected(); + return true; +} + static irqreturn_t rt5677_irq(int unused, void *data) { struct rt5677_priv *rt5677 = data; @@ -5281,9 +5309,6 @@ static irqreturn_t rt5677_irq(int unused, void *data) mutex_lock(&rt5677->irq_lock); - if (rt5677->dsp_vad_en) - rt5677_spi_hotword_detected(); - /* * Loop to handle interrupts until the last i2c read shows no pending * irqs. The interrupt line is shared by multiple interrupt sources. @@ -5321,7 +5346,13 @@ static irqreturn_t rt5677_irq(int unused, void *data) reg_irq ^= rt5677_irq_descs[i].polarity_mask; } } - if (!irq_fired) + + /* Exit the loop only when we know for sure that GPIO1 pin + * was low at some point since irq_lock was acquired. Any event + * after that point creates a rising edge that triggers another + * call to rt5677_irq(). + */ + if (!irq_fired && !rt5677_check_hotword(rt5677)) goto exit; ret = regmap_write(rt5677->regmap, RT5677_IRQ_CTRL1, reg_irq); @@ -5332,6 +5363,7 @@ static irqreturn_t rt5677_irq(int unused, void *data) } } exit: + WARN_ON_ONCE(loop == 20); mutex_unlock(&rt5677->irq_lock); if (irq_fired) return IRQ_HANDLED; From patchwork Fri Sep 6 19:46:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135971 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 0E1D615E6 for ; Fri, 6 Sep 2019 19:54:29 +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 9772A20838 for ; Fri, 6 Sep 2019 19:54:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="vA+F14Rf"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hWeb0IiV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9772A20838 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 DF9E1166C; Fri, 6 Sep 2019 21:53:36 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DF9E1166C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799667; bh=sXnRaKCT4A0yLk0BX/DMBM26nXEZby3rotW0EFGtNN0=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vA+F14RffH9P+Pjn1fX3q4Abx+FgHtSZRRr6q2N7huOwdT0C+jGzisWQI33yNEmXD dMMWn6LlnnKK7x9K9L/tBlD23nFdwzkRhzHBjKt8ebQY2CXo2WgAEjdfzB5IW/G9AD YjOUhCRE4v7XPIyrgtmIEnkSm2VtRtbF+CgL/gEc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id BE09DF806E5; Fri, 6 Sep 2019 21:48:17 +0200 (CEST) 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 BE021F80676; Fri, 6 Sep 2019 21:48:12 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 65695F8065D for ; Fri, 6 Sep 2019 21:48:06 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 65695F8065D Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hWeb0IiV" Received: by mail-pg1-x544.google.com with SMTP id p3so4064233pgb.9 for ; Fri, 06 Sep 2019 12:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iPzlrVlKug7CDGqubv+4tYMRbelSxU1XKXtPDFFoeTM=; b=hWeb0IiV7GSTMHrKPl/jVE2m49foAUp2sKFoPZ+YXUbd/I4TuuwSioQl5XsUYKITzr OVJL1FtBGbuIqujfEfRYywRsXfpDRCG1YUg7OQc9MdHxU9A6P9Skwoa4oh246AjZ9zo+ /jmzjsUtJ6EOIH2aG4pRQAia1a/UyOtk3Y3PI= 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=iPzlrVlKug7CDGqubv+4tYMRbelSxU1XKXtPDFFoeTM=; b=QQTd8Eo6kvtYyASIG6M0UoPhIghe28ZbhA8o2TgGkdg/OfrJ/E4gauLtMZn5dvnhWK ClCnugKO58uiCLzRTdO1GpYqdakG/3dbUUDKXDp75GPqycJBypWxfN8ITUE4xSQ/7xIL GrxXjI2f+KADFSZIXzSKUigm+iwKqjTFxylMEaoF5NNjqR9z5n3++Sr4fdGgguErjQ9h 1j+9rrJ8fir7q5QoPQU3YYfO3k+2k0Y3UhXniMVNpSjY2ag9vjzuU7CCujPOJ7rkUQXU 18Uoyf8PumFyjqGYuGj4nNxfytVi7nO8cobX0v6ySnOsgyrrFctxYskPPP5kriRQfPHU 8PYQ== X-Gm-Message-State: APjAAAX69DasqDavIeqcflJ69PtzrjXRvEI8YQYaD2w/QZ5OjT67e0J/ Zdev6CUkoChTsGI8UPcWWk2C48hy5Q== X-Google-Smtp-Source: APXvYqw6j6yA+VqPPLXMIS4xGhARu2V2ahow8/ySVzgmT/Nf7EPOAdvNuew3AprcY+OAhQQwxPLz3A== X-Received: by 2002:a63:3006:: with SMTP id w6mr9534659pgw.440.1567799285094; Fri, 06 Sep 2019 12:48:05 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id i14sm7659370pfo.50.2019.09.06.12.48.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:04 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:30 -0700 Message-Id: <20190906194636.217881-9-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 08/15] ASoC: rt5677: Use delayed work for DSP firmware load 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" From: Ben Zhang Without this patch, the DSP firmware is loaded/unloaded synchronously in snd_pcm_ops.open/close context. When a hotword stream is opened, snd_pcm_ops.open/close is called multiple times. Loading firmware in the open/close context takes too long and makes audio playback choppy. This patch moves the firmware load to a delayed work. snd_pcm_ops.open/close sets a flag to request DSP VAD enable/disable, and schedules the delayed work. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 57 ++++++++++++++++++++++----------------- sound/soc/codecs/rt5677.h | 3 ++- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 8f5e4882120c..f01fc9d44774 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -692,10 +692,8 @@ static int rt5677_dsp_mode_i2c_read( return ret; } -static void rt5677_set_dsp_mode(struct snd_soc_component *component, bool on) +static void rt5677_set_dsp_mode(struct rt5677_priv *rt5677, bool on) { - struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); - if (on) { regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, RT5677_PWR_DSP, RT5677_PWR_DSP); @@ -707,11 +705,8 @@ static void rt5677_set_dsp_mode(struct snd_soc_component *component, bool on) } } -static unsigned int rt5677_set_vad_source( - struct snd_soc_component *component) +static unsigned int rt5677_set_vad_source(struct rt5677_priv *rt5677) { - struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); - /* Mono ADC Capture Switch = unmute (default) */ regmap_update_bits(rt5677->regmap, RT5677_MONO_ADC_DIG_VOL, RT5677_L_MUTE, 0); @@ -894,20 +889,19 @@ static int rt5677_parse_and_load_dsp(struct rt5677_priv *rt5677, const u8 *buf, return ret; } -static int rt5677_load_dsp_from_file(struct snd_soc_component *component) +static int rt5677_load_dsp_from_file(struct rt5677_priv *rt5677) { - struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); const struct firmware *fwp; + struct device *dev = rt5677->component->dev; int ret = 0; /* Load dsp firmware from rt5677_elf_vad file */ - ret = request_firmware(&fwp, "rt5677_elf_vad", component->dev); + ret = request_firmware(&fwp, "rt5677_elf_vad", dev); if (ret) { - dev_err(component->dev, "Request rt5677_elf_vad failed %d\n", - ret); + dev_err(dev, "Request rt5677_elf_vad failed %d\n", ret); return ret; } - dev_info(component->dev, "Requested rt5677_elf_vad (%zu)\n", fwp->size); + dev_info(dev, "Requested rt5677_elf_vad (%zu)\n", fwp->size); ret = rt5677_parse_and_load_dsp(rt5677, fwp->data, fwp->size); release_firmware(fwp); @@ -917,16 +911,27 @@ static int rt5677_load_dsp_from_file(struct snd_soc_component *component) static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) { struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); - static bool activity; - int ret; + rt5677->dsp_vad_en = on; if (!IS_ENABLED(CONFIG_SND_SOC_RT5677_SPI)) return -ENXIO; - rt5677->dsp_vad_en = on; - dev_info(component->dev, "DSP VAD: on=%d, activity=%d\n", on, activity); + schedule_delayed_work(&rt5677->dsp_work, 0); + return 0; +} + +static void rt5677_dsp_work(struct work_struct *work) +{ + struct rt5677_priv *rt5677 = + container_of(work, struct rt5677_priv, dsp_work.work); + static bool activity; + bool enable = rt5677->dsp_vad_en; + - if (on && !activity) { + dev_info(rt5677->component->dev, "DSP VAD: enable=%d, activity=%d\n", + enable, activity); + + if (enable && !activity) { activity = true; /* Before a hotword is detected, GPIO1 pin is configured as IRQ @@ -939,8 +944,8 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) * output if a hotword is detected. */ - rt5677_set_vad_source(component); - rt5677_set_dsp_mode(component, true); + rt5677_set_vad_source(rt5677); + rt5677_set_dsp_mode(rt5677, true); /* Boot the firmware from IRAM instead of SRAM0. */ rt5677_dsp_mode_i2c_write_addr(rt5677, RT5677_DSP_BOOT_VECTOR, @@ -950,11 +955,11 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) rt5677_dsp_mode_i2c_write_addr(rt5677, RT5677_DSP_BOOT_VECTOR, 0x0009, 0x0003); - ret = rt5677_load_dsp_from_file(component); + rt5677_load_dsp_from_file(rt5677); /* Set DSP CPU to Run */ regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, 0x1, 0x0); - } else if (!on && activity) { + } else if (!enable && activity) { activity = false; /* Don't turn off the DSP while handling irqs */ @@ -962,7 +967,8 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) /* Set DSP CPU to Stop */ regmap_update_bits(rt5677->regmap, RT5677_PWR_DSP1, RT5677_PWR_DSP_CPU, RT5677_PWR_DSP_CPU); - rt5677_set_dsp_mode(component, false); + + rt5677_set_dsp_mode(rt5677, false); /* Disable and clear VAD interrupt */ regmap_write(rt5677->regmap, RT5677_VAD_CTRL1, 0x2184); @@ -973,8 +979,6 @@ static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) mutex_unlock(&rt5677->irq_lock); } - - return 0; } static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0); @@ -4935,6 +4939,8 @@ static void rt5677_remove(struct snd_soc_component *component) { struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); + cancel_delayed_work_sync(&rt5677->dsp_work); + regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec); gpiod_set_value_cansleep(rt5677->pow_ldo2, 0); gpiod_set_value_cansleep(rt5677->reset_pin, 1); @@ -5507,6 +5513,7 @@ static int rt5677_i2c_probe(struct i2c_client *i2c) rt5677->dev = &i2c->dev; rt5677->set_dsp_vad = rt5677_set_dsp_vad; + INIT_DELAYED_WORK(&rt5677->dsp_work, rt5677_dsp_work); i2c_set_clientdata(i2c, rt5677); if (i2c->dev.of_node) { diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index ec5be7e01fd1..d18b41da1176 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1846,9 +1846,10 @@ struct rt5677_priv { #ifdef CONFIG_GPIOLIB struct gpio_chip gpio_chip; #endif - bool dsp_vad_en; + bool dsp_vad_en; /* DSP VAD enable/disable request */ bool is_dsp_mode; bool is_vref_slow; + struct delayed_work dsp_work; /* Interrupt handling */ struct irq_domain *domain; From patchwork Fri Sep 6 19:46:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135973 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 8A6541593 for ; Fri, 6 Sep 2019 19:55:19 +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 1F9D520854 for ; Fri, 6 Sep 2019 19:55:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="HRTi/kAi"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="cPJw9SwH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F9D520854 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 66E33846; Fri, 6 Sep 2019 21:54:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 66E33846 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799717; bh=enoPpq6zI++bUcLKm7CQYbxunNNRZUkvCXnfHWLC1oQ=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HRTi/kAiOYqIk2/PQtmw0+UDgoL8tO+OhziW6B+Jqb2Skmr21/1WvdJEX+VU+PJgx TzqWRlDqGd91LEeZ14EE9fHh1C8b8wlMywPZWUsUnexOVLVXX24jIXSQgflhAJYtu4 8l8RfB6pQVVBhp0/rsqCvHe5/iK4VoRr8mUoIXrw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E388CF806E9; Fri, 6 Sep 2019 21:48:27 +0200 (CEST) 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 5CBB8F80677; Fri, 6 Sep 2019 21:48:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (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 6D3AFF8065E for ; Fri, 6 Sep 2019 21:48:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6D3AFF8065E Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="cPJw9SwH" Received: by mail-pf1-x443.google.com with SMTP id y72so5187284pfb.12 for ; Fri, 06 Sep 2019 12:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k0zzTPlGcwPAw52gcXgnsH058VHFC5y6j8AIZUYPvUA=; b=cPJw9SwHetz+UQxgxCRZLpeNFUSrrPQNah7xYjpl/fBOuZQN2vxzkmacgchBBdfK6H DkrqZl7BHV40bLhAQfpd8BaBjbxJNIVrc/cg5bSJcYWCxlTWOkT/oaWqhLm5QbpHs8iW F6lpLsuWCe+rOWi4Kqk9sMLW2uYvbUS+T0m9g= 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=k0zzTPlGcwPAw52gcXgnsH058VHFC5y6j8AIZUYPvUA=; b=tUODLhN5Gje3wMBHsapO65OcMFNref/oqtopBW5v8ODqDjLug/0/nE0YHgzTN3rI7r wg5a4pr8BlnwqwPSN3WPPADNgNvkgbFYbzXWofJLB0Ck4v8j0lqQiwF1wCvIDJXItNcl i5IGHiqhLwe51N9/A0O4lepfO6JVXhYKRHLtM7UK5UOmgZGEZkSawf2dU8rnjXIhIWTr s8DyNw1rLFBQutKIQ9K1cfu08JRt3uXGMmjzvVO/GL1rRo3tnPq8htHb+oCxerLIHuLD QpRc7QZ0vMRzx5/aaU+xXM5MwTpL/l9ZVXEGWDM58VC9QjHKPRl5vQzo/GHkTBRRLGB1 oCrQ== X-Gm-Message-State: APjAAAVBfyln8JqgykuUGt8PONLPKHNdOBGcfM2Ya2jiXgiPJH0J7BGk KkjwdV6ww2JxUYzYxOWq+A8asgIVyg== X-Google-Smtp-Source: APXvYqxYEyQZvfCbXuof2/m4j8jVEpvJX/ejSJSf++pCf2wLTPwPXitXw4L90LcjVie0zwe32bSx7w== X-Received: by 2002:a65:690e:: with SMTP id s14mr4206758pgq.47.1567799288195; Fri, 06 Sep 2019 12:48:08 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id t7sm10812873pgc.68.2019.09.06.12.48.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:07 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:31 -0700 Message-Id: <20190906194636.217881-10-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 09/15] ASoC: rt5677: Add DAPM audio path for hotword stream 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" From: Ben Zhang Add a DAPM audio path from "DMIC L1" to "DSP Buffer" so that when hotwording is enabled, DAPM does not power off the codec with SND_SOC_BIAS_OFF. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index f01fc9d44774..3db26cb242d2 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -707,6 +707,15 @@ static void rt5677_set_dsp_mode(struct rt5677_priv *rt5677, bool on) static unsigned int rt5677_set_vad_source(struct rt5677_priv *rt5677) { + struct snd_soc_dapm_context *dapm = + snd_soc_component_get_dapm(rt5677->component); + /* The hotword audio path is from "DMIC L1" to "DSP Buffer". + * "DSP Buffer" is then connected to "DSP Capture" which is the + * rt5677-dsp-cpu-dai with a PCM interface in rt5677-spi. + */ + snd_soc_dapm_enable_pin(dapm, "DMIC L1"); + snd_soc_dapm_sync(dapm); + /* Mono ADC Capture Switch = unmute (default) */ regmap_update_bits(rt5677->regmap, RT5677_MONO_ADC_DIG_VOL, RT5677_L_MUTE, 0); @@ -3209,6 +3218,7 @@ static const struct snd_soc_dapm_widget rt5677_dapm_widgets[] = { SND_SOC_DAPM_AIF_OUT("AIF4TX", "AIF4 Capture", 0, SND_SOC_NOPM, 0, 0), SND_SOC_DAPM_AIF_IN("SLBRX", "SLIMBus Playback", 0, SND_SOC_NOPM, 0, 0), SND_SOC_DAPM_AIF_OUT("SLBTX", "SLIMBus Capture", 0, SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_AIF_OUT("DSPTX", "DSP Buffer", 0, SND_SOC_NOPM, 0, 0), /* Sidetone Mux */ SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0, @@ -3743,11 +3753,24 @@ static const struct snd_soc_dapm_route rt5677_dapm_routes[] = { { "SLBTX", NULL, "SLB ADC3 Mux" }, { "SLBTX", NULL, "SLB ADC4 Mux" }, + { "DSPTX", NULL, "IB01 Bypass Mux" }, + { "IB01 Mux", "IF1 DAC 01", "IF1 DAC01" }, { "IB01 Mux", "IF2 DAC 01", "IF2 DAC01" }, { "IB01 Mux", "SLB DAC 01", "SLB DAC01" }, { "IB01 Mux", "STO1 ADC MIX", "Stereo1 ADC MIX" }, - { "IB01 Mux", "VAD ADC/DAC1 FS", "DAC1 FS" }, + /* The IB01 Mux controls the source for InBound0 and InBound1. + * When the mux option "VAD ADC/DAC1 FS" is selected, "VAD ADC" goes to + * InBound0 and "DAC1 FS" goes to InBound1. "VAD ADC" is used for + * hotwording. "DAC1 FS" is not used currently. + * + * Creating a common widget node for "VAD ADC" + "DAC1 FS" and + * connecting the common widget to IB01 Mux causes the issue where + * there is an active path going from system playback -> "DAC1 FS" -> + * IB01 Mux -> DSP Buffer -> hotword stream. This wrong path confuses + * DAPM. Therefore "DAC1 FS" is ignored for now. + */ + { "IB01 Mux", "VAD ADC/DAC1 FS", "VAD ADC Mux" }, { "IB01 Bypass Mux", "Bypass", "IB01 Mux" }, { "IB01 Bypass Mux", "Pass SRC", "IB01 Mux" }, From patchwork Fri Sep 6 19:46:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135975 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 CDEFC1593 for ; Fri, 6 Sep 2019 19:55:52 +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 63DE620854 for ; Fri, 6 Sep 2019 19:55:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="tOZC42aY"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="A4RGbTtv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63DE620854 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 9DBCB828; Fri, 6 Sep 2019 21:55:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9DBCB828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799750; bh=rJxuYm0zRxN/+gtxl6INPle7kDd8d3D5oTlR0m3RPPE=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=tOZC42aYt0QwYR0lFY39V+rd2wlGCHS5Mb41dPOfU5E/2SiIRTS1iTwWgYlJ+xzPs LMirrAEMjSlPUZ/Ofx+BHgfdidfHWkOK0qnoPuiGVsRvygrwEi3lWA5ofWdXavz1em +Ic5xKRMSJDQKedZOL4naafh9hFGDB0k+9Fzb4tc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 22097F8070E; Fri, 6 Sep 2019 21:48:33 +0200 (CEST) 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 A7261F806EF; Fri, 6 Sep 2019 21:48:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 0ADF6F80679 for ; Fri, 6 Sep 2019 21:48:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0ADF6F80679 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="A4RGbTtv" Received: by mail-pl1-x644.google.com with SMTP id gn20so3644275plb.2 for ; Fri, 06 Sep 2019 12:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rySU15ygIQhT7lY0CFfGk5dF4YSEgWQKt7fn4j4JCJc=; b=A4RGbTtvjbWDDD7parKemBXc0Uv5AgEBE+nzCgSvTrPFHzsILUV5OkT0YIFtz9zB+l rC/LheG8uVtDYwByNy0ZJWk3MVyzzNmDZMRD8B7hHH2h45WMO8BTDEsK60az8RWHVeZ1 hNvhNVM31dp9lVOmPH8tsBD0teb8HieT/5DgY= 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=rySU15ygIQhT7lY0CFfGk5dF4YSEgWQKt7fn4j4JCJc=; b=Z4og/tMPZnlE9SZsLHKSgPgDKj4S3Xao3oaxIn5+JYdpeCq13OOt/kUMEMkQTJfuK7 XBTGk6yJR2rClJlarvQFVKk7O3QF7hsiNYBuq/GFCErYI8S8MPCzb8waxIkhN5IR4ZzU b+n+6ZiRwmdWSuTdE+KOjrpTtcRKcAv20w1damTOdCv0aYlVpu63o552zUsvGAGZO2YP 99g1EfOb5qu6ZPdocyTY6ugHSaZdJDydUealzgWCVwOkIL/isKTbLvSMtN2Sd65xN/BU duESxwAJojkzx6u9Xa2mj/Zjmo7bwAPTCvphuRnSnG8o0ylT4CvHapKhCNYN0pGJ4GGF iGLA== X-Gm-Message-State: APjAAAXfLyZOqcGl8V2XABTg95LIe7AJobqdG56ek/apGcmWScjW91dQ jo/D0Zu4dcT0SMHNnfy8x+fR0y5B4w== X-Google-Smtp-Source: APXvYqwtcHOa+RW4W4V/fhw1RQTGLKsbbmlee/RjoygHgSzoGHtQJlwgDwzW0VI0v6RadYC7Is+p9A== X-Received: by 2002:a17:902:b115:: with SMTP id q21mr11249559plr.241.1567799293795; Fri, 06 Sep 2019 12:48:13 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id f14sm12251609pfq.187.2019.09.06.12.48.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:13 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:32 -0700 Message-Id: <20190906194636.217881-11-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 10/15] ASoC: rt5677: Mark reg RT5677_PWR_ANLG2 as volatile 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" From: Ben Zhang The codec dies when RT5677_PWR_ANLG2(MX-64h) is set to 0xACE1 while it's streaming audio over SPI. The DSP firmware turns on PLL2 (MX-64 bit 8) when SPI streaming starts. However regmap does not believe that register can change by itself. When BST1 (bit 15) is turned on with regmap_update_bits(), it doesn't read the register first before write, so PLL2 power bit is cleared by accident. Marking MX-64h as volatile in regmap solved the issue. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 3db26cb242d2..f07d10a8b045 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -302,6 +302,7 @@ static bool rt5677_volatile_register(struct device *dev, unsigned int reg) case RT5677_I2C_MASTER_CTRL7: case RT5677_I2C_MASTER_CTRL8: case RT5677_HAP_GENE_CTRL2: + case RT5677_PWR_ANLG2: /* Modified by DSP firmware */ case RT5677_PWR_DSP_ST: case RT5677_PRIV_DATA: case RT5677_ASRC_22: From patchwork Fri Sep 6 19:46:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135977 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 BE8571593 for ; Fri, 6 Sep 2019 19:56:25 +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 5216C20854 for ; Fri, 6 Sep 2019 19:56:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="gUrLUit6"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YW0k1PU5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5216C20854 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 8EF8F1670; Fri, 6 Sep 2019 21:55:33 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8EF8F1670 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799783; bh=GD0nc+pdJfOanRgMdcaFbJMzWh9IagvtFCCEy5IKbMw=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gUrLUit63eRg1opiI/JfwKUePrnWrRHId4l//m6ZFqRmTdiHTwymCvJjJTUoIOcDE uLmzV9lzbTBqg9pHlBrvTUC25VAmZd8ZTWsfpIYJwxJmNJa7S0MIo7vrJB/LAOSTN6 MZ3vmHqPyaViFUL/PzYqGAhMSx0n/ROrsUMqRZY8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AA62FF80716; Fri, 6 Sep 2019 21:48:36 +0200 (CEST) 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 4102CF806EF; Fri, 6 Sep 2019 21:48:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (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 DA418F80679 for ; Fri, 6 Sep 2019 21:48:19 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DA418F80679 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YW0k1PU5" Received: by mail-pg1-x543.google.com with SMTP id n190so4090545pgn.0 for ; Fri, 06 Sep 2019 12:48:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ovWve/Pf/vgU6/XEYbPPN869G7pjHo6uDWX9Rl3uHyI=; b=YW0k1PU5JHyefHoHhntqmiLEw8CUJH840c3QuBEYc/hfG8KIOnBgFlUTBc0dbGajE+ ubUfrxyKdQJY9QBCyWHojiDMLe27ENKXVRT+mpPy7Gz10RFqi+01UVflfyeToIbsEKl/ 0H9IuSPat+BXfIjVzCeqsuAZfjVndTPYKw27M= 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=ovWve/Pf/vgU6/XEYbPPN869G7pjHo6uDWX9Rl3uHyI=; b=N4FU1vOgp6NabTnNra4gLj2yG/wAEPyweCohxRPB0cqORcyg57fOxfdeX3Q6xitSpO 5uUtDIrRpD/03U4ECBOYuSQW8U9LpYKU/n5LuF4Oo2PV8jZ3wCAaD2jOvdfz9l2zuWJk 4MmceIrGuKjkpYe+nGnvZjS3+JZXcoJr8Y1R+/gCvBY3OaVH5xHliChWok8rPiBN+giw gyT3X3qDjN5uc7mt27JmYaIaHWtmh9MDkqwd83mpl0LSW2k+h3Co4RatAMtb9/wSIqz6 azvREeBnYID58fHmWXpiMllJ0sGVMeg1Vh+Ars0ZRufWtaIfk+W/J19vnGS7xfeReF7c 15jA== X-Gm-Message-State: APjAAAVSgB9BUu0kcEcSKfnsXzH+5w9h89GOaj9LXFSZkrbVOgWxK9CZ xuWpWTNHRIXsjlgCnj2H59SVrjRorA== X-Google-Smtp-Source: APXvYqzJgWCTMeAVCn60xahKjRFrZA4OyIud6uNgyIMaoj9XJsSr606EYoRHlskNVZDiDM51bl3zJA== X-Received: by 2002:aa7:8005:: with SMTP id j5mr12756323pfi.50.1567799297726; Fri, 06 Sep 2019 12:48:17 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id 129sm8340308pfd.173.2019.09.06.12.48.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:17 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:33 -0700 Message-Id: <20190906194636.217881-12-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 11/15] ASoC: rt5677: Stop and restart DSP over suspend/resume 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" From: Ben Zhang MCLK1 gets disabled at suspend and re-enabled at resume. Before MCLK1 is re-enabled, if the DSP is already on (either the DSP was left on during suspend, or the DSP is turned on early at resume), i2c register read returns garbage and corrupts the regmap cache. This patch stops the DSP before suspend and restarts it after resume with a dalay to ensure MCLK is on while loading firmware. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 24 +++++++++++++++++++++--- sound/soc/codecs/rt5677.h | 3 ++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index f07d10a8b045..098dcbaa4539 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -921,6 +921,7 @@ static int rt5677_load_dsp_from_file(struct rt5677_priv *rt5677) static int rt5677_set_dsp_vad(struct snd_soc_component *component, bool on) { struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); + rt5677->dsp_vad_en_request = on; rt5677->dsp_vad_en = on; if (!IS_ENABLED(CONFIG_SND_SOC_RT5677_SPI)) @@ -1013,7 +1014,7 @@ static int rt5677_dsp_vad_get(struct snd_kcontrol *kcontrol, struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); - ucontrol->value.integer.value[0] = rt5677->dsp_vad_en; + ucontrol->value.integer.value[0] = rt5677->dsp_vad_en_request; return 0; } @@ -4680,14 +4681,15 @@ static int rt5677_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); + enum snd_soc_bias_level prev_bias = + snd_soc_component_get_bias_level(component); switch (level) { case SND_SOC_BIAS_ON: break; case SND_SOC_BIAS_PREPARE: - if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY) { - rt5677_set_dsp_vad(component, false); + if (prev_bias == SND_SOC_BIAS_STANDBY) { regmap_update_bits(rt5677->regmap, RT5677_PWR_ANLG1, RT5677_LDO1_SEL_MASK | RT5677_LDO2_SEL_MASK, @@ -4711,9 +4713,25 @@ static int rt5677_set_bias_level(struct snd_soc_component *component, break; case SND_SOC_BIAS_STANDBY: + if (prev_bias == SND_SOC_BIAS_OFF && + rt5677->dsp_vad_en_request) { + /* Re-enable the DSP if it was turned off at suspend */ + rt5677->dsp_vad_en = true; + /* The delay is to wait for MCLK */ + schedule_delayed_work(&rt5677->dsp_work, + msecs_to_jiffies(1000)); + } break; case SND_SOC_BIAS_OFF: + flush_delayed_work(&rt5677->dsp_work); + if (rt5677->is_dsp_mode) { + /* Turn off the DSP before suspend */ + rt5677->dsp_vad_en = false; + schedule_delayed_work(&rt5677->dsp_work, 0); + flush_delayed_work(&rt5677->dsp_work); + } + regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x1, 0x0); regmap_write(rt5677->regmap, RT5677_PWR_DIG1, 0x0000); regmap_write(rt5677->regmap, RT5677_PWR_ANLG1, diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index d18b41da1176..046ed2ee8e31 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1846,7 +1846,8 @@ struct rt5677_priv { #ifdef CONFIG_GPIOLIB struct gpio_chip gpio_chip; #endif - bool dsp_vad_en; /* DSP VAD enable/disable request */ + bool dsp_vad_en_request; /* DSP VAD enable/disable request */ + bool dsp_vad_en; /* dsp_work parameter */ bool is_dsp_mode; bool is_vref_slow; struct delayed_work dsp_work; From patchwork Fri Sep 6 19:46:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135979 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 CA17D15E6 for ; Fri, 6 Sep 2019 19:57:08 +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 5F3DD208C3 for ; Fri, 6 Sep 2019 19:57:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="oVoDWRpy"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aMDbX4rg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F3DD208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 8F6CB1658; Fri, 6 Sep 2019 21:56:16 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8F6CB1658 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799826; bh=34o/pYdwCOTkO2NtMRLpg/gn57bUxCXkOzn3ICOW8Ig=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oVoDWRpyAujS+g1yvszzamEzVTi9qYp1cpHea1V1uV+l6c8VzpJFVrZzgsj2nvJuz vcLvUysWSStiUB/6iN0zkDR+NcTJZXdsUEqVzp4ruL0mI0TGZKNKi3i0wxePtvLkNQ F2RUcSc+BBfUkKzsccJjLqNo/bPUCKWKqQilMK/M= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 0C1B0F80722; Fri, 6 Sep 2019 21:48:39 +0200 (CEST) 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 869F8F8070C; Fri, 6 Sep 2019 21:48:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (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 A5BACF806E9 for ; Fri, 6 Sep 2019 21:48:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A5BACF806E9 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aMDbX4rg" Received: by mail-pf1-x443.google.com with SMTP id b13so5199400pfo.8 for ; Fri, 06 Sep 2019 12:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ivA4BmllxkGqd9dbObaLfF3lVYJE+SjIVnNG77bpZeg=; b=aMDbX4rgzCOyBjxScfXsvhyHQReDoA+lq4/mAi4pvImTNF7E7BjUnE3OhjBE9b3ZUa 3DafviMV1xGK7UHinH9Z23+h3zqnPdbUIin0waj1HE6pI77tdI11LKo8aYx/xAMM7UjK /Sr2m8iJBDTWjBXmswcRJVvrOCNcQv7LK11BQ= 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=ivA4BmllxkGqd9dbObaLfF3lVYJE+SjIVnNG77bpZeg=; b=oAAaxoFVh/YnKMHrnWdplG3Mot/+p6yz/Yw75x8+/ZGnXKqqbcO41La3q/aahpsU0R BfbHAFySI0cdX4wpyGajBt+QWj8/cKBoeNRyNoMxXP5IMb9Cb/V6YoWiTs00JIQZ2cKa k+IU/kzHrvvZ/kAmyfcu77wU5YG8hiDM5TqPbAwhLOtSzrEFt1j4sCjG7PBPvcJx3jhx unOKRvMnZBeSQNKdbJd5Etzu5Qh7USU5holXvVzsHNEffWtll+1Snf8lDUESKVEHL6RL 2m7xej7yTfnE6W6AtIy9/ng7HO2YACWJzYSTGttsEGmsZMPzcoemU1yCK4lkpcVqJgDA CApg== X-Gm-Message-State: APjAAAVlAKprFgZPJwN6U0F8/OT2NSDlEqAobkoNWIHfiTj8oV1txp6/ /3HcuSPR51GOvLxuKCn0VG8pFd0mOA== X-Google-Smtp-Source: APXvYqw6eKDHG0YCSas+eYCTLTMjGt53QILBW6UKA8KDtCpOWsCyy6Z/oatwXkW2vZlLhYuvI5g2Kg== X-Received: by 2002:aa7:8c01:: with SMTP id c1mr12890764pfd.224.1567799302074; Fri, 06 Sep 2019 12:48:22 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id x125sm3663741pfb.93.2019.09.06.12.48.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:21 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:34 -0700 Message-Id: <20190906194636.217881-13-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 12/15] ASoC: rt5677: Transfer one period at a time over SPI 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" From: Ben Zhang Rewrite the ring buffer transfer functions to copy one period at a time then call snd_pcm_period_elapsed(). This reduces the latency of transferring the initial ~2sec of audio after hotword detect since audio samples are available for userspace earlier. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677-spi.c | 91 +++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/sound/soc/codecs/rt5677-spi.c b/sound/soc/codecs/rt5677-spi.c index 25d75a803cb5..b9b0f646127d 100644 --- a/sound/soc/codecs/rt5677-spi.c +++ b/sound/soc/codecs/rt5677-spi.c @@ -51,7 +51,8 @@ #define RT5677_BUF_BYTES_TOTAL 0x20000 #define RT5677_MIC_BUF_ADDR 0x60030000 #define RT5677_MODEL_ADDR 0x5FFC9800 -#define RT5677_MIC_BUF_BYTES (RT5677_BUF_BYTES_TOTAL - sizeof(u32)) +#define RT5677_MIC_BUF_BYTES ((u32)(RT5677_BUF_BYTES_TOTAL - \ + sizeof(u32))) #define RT5677_MIC_BUF_FIRST_READ_SIZE 0x10000 static struct spi_device *g_spi; @@ -205,15 +206,15 @@ static int rt5677_spi_mic_write_offset(u32 *mic_write_offset) } /* - * Copy a block of audio samples from the DSP mic buffer to the dma_area of - * the pcm runtime. The receiving buffer may wrap around. + * Copy one contiguous block of audio samples from the DSP mic buffer to the + * dma_area of the pcm runtime. The receiving buffer may wrap around. * @begin: start offset of the block to copy, in bytes. * @end: offset of the first byte after the block to copy, must be greater * than or equal to begin. * * Return: Zero if successful, or a negative error code on failure. */ -static int rt5677_spi_append_data(struct rt5677_dsp *rt5677_dsp, +static int rt5677_spi_copy_block(struct rt5677_dsp *rt5677_dsp, u32 begin, u32 end) { struct snd_pcm_runtime *runtime = rt5677_dsp->substream->runtime; @@ -269,6 +270,38 @@ static int rt5677_spi_append_data(struct rt5677_dsp *rt5677_dsp, return ret; } +/* + * Copy a given amount of audio samples from the DSP mic buffer starting at + * mic_read_offset, to the dma_area of the pcm runtime. The source buffer may + * wrap around. mic_read_offset is updated after successful copy. + * @amount: amount of samples to copy, in bytes. + * + * Return: Zero if successful, or a negative error code on failure. + */ +static int rt5677_spi_copy(struct rt5677_dsp *rt5677_dsp, u32 amount) +{ + int ret = 0; + u32 target; + + if (amount == 0) + return ret; + + target = rt5677_dsp->mic_read_offset + amount; + /* Copy the first chunk in DSP's mic buffer */ + ret |= rt5677_spi_copy_block(rt5677_dsp, rt5677_dsp->mic_read_offset, + min(target, RT5677_MIC_BUF_BYTES)); + + if (target >= RT5677_MIC_BUF_BYTES) { + /* Wrap around, copy the second chunk */ + target -= RT5677_MIC_BUF_BYTES; + ret |= rt5677_spi_copy_block(rt5677_dsp, 0, target); + } + + if (!ret) + rt5677_dsp->mic_read_offset = target; + return ret; +} + /* * A delayed work that streams audio samples from the DSP mic buffer to the * dma_area of the pcm runtime via SPI. @@ -279,7 +312,7 @@ static void rt5677_spi_copy_work(struct work_struct *work) container_of(work, struct rt5677_dsp, copy_work.work); struct snd_pcm_runtime *runtime; u32 mic_write_offset; - size_t bytes_copied, period_bytes; + size_t new_bytes, copy_bytes, period_bytes; int ret = 0; /* Ensure runtime->dma_area buffer does not go away while copying. */ @@ -312,35 +345,31 @@ static void rt5677_spi_copy_work(struct work_struct *work) RT5677_MIC_BUF_FIRST_READ_SIZE; } - /* Copy all new samples from DSP's mic buffer to dma_area */ - bytes_copied = 0; - if (rt5677_dsp->mic_read_offset < mic_write_offset) { - /* One chunk in DSP's mic buffer */ - ret |= rt5677_spi_append_data(rt5677_dsp, - rt5677_dsp->mic_read_offset, mic_write_offset); - bytes_copied = mic_write_offset - rt5677_dsp->mic_read_offset; - } else if (rt5677_dsp->mic_read_offset > mic_write_offset) { - /* Wrap around, two chunks in DSP's mic buffer */ - ret |= rt5677_spi_append_data(rt5677_dsp, - rt5677_dsp->mic_read_offset, - RT5677_MIC_BUF_BYTES); - ret |= rt5677_spi_append_data(rt5677_dsp, 0, mic_write_offset); - bytes_copied = RT5677_MIC_BUF_BYTES - - rt5677_dsp->mic_read_offset + mic_write_offset; - } - if (ret) { - dev_err(rt5677_dsp->dev, "Copy failed %d\n", ret); - goto done; - } + /* Calculate the amount of new samples in bytes */ + if (rt5677_dsp->mic_read_offset <= mic_write_offset) + new_bytes = mic_write_offset - rt5677_dsp->mic_read_offset; + else + new_bytes = RT5677_MIC_BUF_BYTES + mic_write_offset + - rt5677_dsp->mic_read_offset; - rt5677_dsp->mic_read_offset = mic_write_offset; - rt5677_dsp->avail_bytes += bytes_copied; + /* Copy all new samples from DSP mic buffer, one period at a time */ period_bytes = snd_pcm_lib_period_bytes(rt5677_dsp->substream); - - if (rt5677_dsp->avail_bytes >= period_bytes) { - snd_pcm_period_elapsed(rt5677_dsp->substream); - rt5677_dsp->avail_bytes = 0; + while (new_bytes) { + copy_bytes = min(new_bytes, period_bytes + - rt5677_dsp->avail_bytes); + ret = rt5677_spi_copy(rt5677_dsp, copy_bytes); + if (ret) { + dev_err(rt5677_dsp->dev, "Copy failed %d\n", ret); + goto done; + } + rt5677_dsp->avail_bytes += copy_bytes; + if (rt5677_dsp->avail_bytes >= period_bytes) { + snd_pcm_period_elapsed(rt5677_dsp->substream); + rt5677_dsp->avail_bytes = 0; + } + new_bytes -= copy_bytes; } + /* TODO benzh: use better delay time based on period_bytes */ schedule_delayed_work(&rt5677_dsp->copy_work, msecs_to_jiffies(5)); done: From patchwork Fri Sep 6 19:46:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11135981 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 26A9A1593 for ; Fri, 6 Sep 2019 19:57:56 +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 B0F7720854 for ; Fri, 6 Sep 2019 19:57:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="alemUh2H"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OTw85TZF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0F7720854 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 035991668; Fri, 6 Sep 2019 21:57:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 035991668 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799874; bh=cqk3XY86QFXaX63OhGI0kgJIYvljWYxc1zopFZGYsPg=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=alemUh2HTTnMCTtVWH+MVY6G9KW3kt6P9hh/UUhCaJF5L1aGH5Bxely2hzxLgjEfK vLApWH2ZdRC4DWsOWfDulWi1o4rzFr+lXT9rRgNrHQNeCHYUk8pgba3gdnjKDCIAWZ lhUKOXtKorj61QOryRzPYz7bB0TIfNOkbQSlT5Gw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A8C55F80733; Fri, 6 Sep 2019 21:48:40 +0200 (CEST) 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 2AA49F8070B; Fri, 6 Sep 2019 21:48:31 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,PRX_BODY_30,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (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 81105F8070B for ; Fri, 6 Sep 2019 21:48:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 81105F8070B Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OTw85TZF" Received: by mail-pf1-x443.google.com with SMTP id x127so5213970pfb.7 for ; Fri, 06 Sep 2019 12:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dj/8llU1tD7dv2vk46pNupHaGLnVIU2qJGiFUXCzwn4=; b=OTw85TZFh94kvC5jp/D3QabaMmGVceg8CudQH4LudLuFA9EaToNbQ34C5YPYJds0uV A/08rnz/wQD0sqipzCYbpP9EU7lffQIdU6xP8kksFt+9gcWAnhnOcrGXFYTbFujm0KOT cinuStorYwDr64XVggCVfG+dd7x4JF0+TgUR4= 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=dj/8llU1tD7dv2vk46pNupHaGLnVIU2qJGiFUXCzwn4=; b=qOs+vfnItTkS9Bn3EpF45u4Pm1eT6FmGveFyknP5f9nsLpMeeDtxPM4dKuED2G7gIx jsABgt/otj2HQHtfpz1v16YsQ4Qx9WFad5Nw+HiWU42YYV5WkKiMSZx78asIt5fmsBNY Zl2M8n+exexKZTfstQBiBq88LL9HdqF748em7cH0Xzcwlr2OCdfo4Vb9bOdEK5FRFupr ojl3RA+v6JMfuKkRuO4zQmWptz8irQr3lG3UdxpCJgFG4+hVNESovpg3ASXvE6TqHXj5 uk/JhD5LplpPMeZscgTmDg2JYEhna1CQMYujQh7bX5MgzANA2eHv9qSN0QniOxoh6U9f 9Myg== X-Gm-Message-State: APjAAAWHMcKzLwB++H8BAhW8903sFHCgCZXYYNWzJmlpSv/SndxXUkb2 shkhKFYzuoSsQk6RFyq/vf41e3XIDA== X-Google-Smtp-Source: APXvYqysgm69HYUE/wspPcCu8Nz7UeJZG7SPd7yHwOlNnVCJWw7Dbk/w8I/l7hIvG3WUBUhZsYe1FQ== X-Received: by 2002:a63:cb4f:: with SMTP id m15mr9409079pgi.100.1567799304814; Fri, 06 Sep 2019 12:48:24 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id d20sm10513667pfq.88.2019.09.06.12.48.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:24 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:35 -0700 Message-Id: <20190906194636.217881-14-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Ben Zhang , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 13/15] ASoC: rt5677: Disable irq at suspend 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" From: Ben Zhang The irq is disabled at suspend to avoid running the threaded irq handler after the codec has been powered off. At resume, codec irq is re-enabled and the interrupt status register is checked to see if headphone has been pluggnd/unplugged while the device is suspended. There is still a chance that the headphone gets enabled or disabled after the codec is suspended. disable_irq syncs the threaded irq handler, but soc-jack's threaded irq handler schedules a delayed work to poll gpios (for debounce). This is still OK. The codec won't be powered back on again because all audio paths have been suspended, and there are no force enabled supply widgets (MICBIAS1 is disabled). The gpio status read after codec power off could be wrong, so the gpio values are checked again after resume. Signed-off-by: Ben Zhang Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 46 +++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/rt5677.h | 2 ++ 2 files changed, 48 insertions(+) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 098dcbaa4539..a262a3dfbe2b 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -4993,6 +4993,11 @@ static int rt5677_suspend(struct snd_soc_component *component) { struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); + if (rt5677->irq) { + cancel_delayed_work_sync(&rt5677->resume_irq_check); + disable_irq(rt5677->irq); + } + if (!rt5677->dsp_vad_en) { regcache_cache_only(rt5677->regmap, true); regcache_mark_dirty(rt5677->regmap); @@ -5021,6 +5026,11 @@ static int rt5677_resume(struct snd_soc_component *component) regcache_sync(rt5677->regmap); } + if (rt5677->irq) { + enable_irq(rt5677->irq); + schedule_delayed_work(&rt5677->resume_irq_check, 0); + } + return 0; } #else @@ -5419,6 +5429,39 @@ static irqreturn_t rt5677_irq(int unused, void *data) return IRQ_NONE; } +static void rt5677_resume_irq_check(struct work_struct *work) +{ + int i, virq; + struct rt5677_priv *rt5677 = + container_of(work, struct rt5677_priv, resume_irq_check.work); + + /* This is needed to check and clear the interrupt status register + * at resume. If the headset is plugged/unplugged when the device is + * fully suspended, there won't be a rising edge at resume to trigger + * the interrupt. Without this, we miss the next unplug/plug event. + */ + rt5677_irq(0, rt5677); + + /* Call all enabled jack detect irq handlers again. This is needed in + * addition to the above check for a corner case caused by jack gpio + * debounce. After codec irq is disabled at suspend, the delayed work + * scheduled by soc-jack may run and read wrong jack gpio values, since + * the regmap is in cache only mode. At resume, there is no irq because + * rt5677_irq has already ran and cleared the irq status at suspend. + * Without this explicit check, unplug the headset right after suspend + * starts, then after resume the headset is still shown as plugged in. + */ + mutex_lock(&rt5677->irq_lock); + for (i = 0; i < RT5677_IRQ_NUM; i++) { + if (rt5677->irq_en & rt5677_irq_descs[i].enable_mask) { + virq = irq_find_mapping(rt5677->domain, i); + if (virq) + handle_nested_irq(virq); + } + } + mutex_unlock(&rt5677->irq_lock); +} + static void rt5677_irq_bus_lock(struct irq_data *data) { struct rt5677_priv *rt5677 = irq_data_get_irq_chip_data(data); @@ -5494,6 +5537,7 @@ static int rt5677_init_irq(struct i2c_client *i2c) } mutex_init(&rt5677->irq_lock); + INIT_DELAYED_WORK(&rt5677->resume_irq_check, rt5677_resume_irq_check); /* * Select RC as the debounce clock so that GPIO works even when @@ -5539,6 +5583,8 @@ static int rt5677_init_irq(struct i2c_client *i2c) if (ret) dev_err(&i2c->dev, "Failed to request IRQ: %d\n", ret); + rt5677->irq = i2c->irq; + return ret; } diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index 046ed2ee8e31..f8ada967fdbc 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h @@ -1856,6 +1856,8 @@ struct rt5677_priv { struct irq_domain *domain; struct mutex irq_lock; unsigned int irq_en; + struct delayed_work resume_irq_check; + int irq; int (*set_dsp_vad)(struct snd_soc_component *component, bool on); }; From patchwork Fri Sep 6 19:46:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11136003 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 B334F1593 for ; Fri, 6 Sep 2019 19:58:45 +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 44ED620854 for ; Fri, 6 Sep 2019 19:58:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="ocnv187t"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RrvCXvFM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44ED620854 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 747491669; Fri, 6 Sep 2019 21:57:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 747491669 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799923; bh=6oYnvu04bM0Wqax5NjyWhvMigAqwn6OVRQZTeKEp974=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ocnv187tWopIsMvSU0koHkkw2hmknyX6U6+PWrj9ULALL1JEbtRC71sQ0ehHXYtmR 1mQ8cy1cTqJD3T1j8faI31H+EG/f+E7Ve/5e2GH6g9zsr2QMZoK6CF0n9uo2fFhqCu OKChDJycqz2a5H/Ed2GHM+9thXqPJzkT9bLGwUKk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id D3C0FF80753; Fri, 6 Sep 2019 21:48:42 +0200 (CEST) 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 1EEE3F80716; Fri, 6 Sep 2019 21:48:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (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 D092FF8070D for ; Fri, 6 Sep 2019 21:48:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D092FF8070D Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RrvCXvFM" Received: by mail-pf1-x441.google.com with SMTP id q5so5197728pfg.13 for ; Fri, 06 Sep 2019 12:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b15e9a8jnXI2D/g2HPNMQHRyWy1Aa/vLPeajdGxCjYA=; b=RrvCXvFMIZeiP0Wg3jy20nWHjV47aWviTjqXvsPTiBEHRACYBSHZy9VIm0JJzvtr8e 4e1ajbE/OSKWILwKx0WVTbkHiTme/h17/guuTzIC3mytmvT2DQZ2BvqXHF7gRnb0gROu 0bOparTqUFSNpmJJL9uW6bd7yXdBDqBuzNRcI= 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=b15e9a8jnXI2D/g2HPNMQHRyWy1Aa/vLPeajdGxCjYA=; b=pcQF0ugT7cNBZHGv6TYgdn5onk16qhvypb4XqqiFdSCpUWwccLbjJxp/xEG7WLsfJv gUv5KydeWzFfAKrc3W/54xsEBO8zRvUia9Q378ONeJwl46kdsWSBhrB9LPKhrRRrJY7C mGCTU2y6JU4KuDCIIoLA9L5NgmTT/QuqWcmH1m2vv0Yvle7SDi83YY1IXDaW5nY69PHD bmDq4E+Sa0gMlzPxq2v4SXu9pO6Y8/JF3G5e+kSkaQB7NxxrYQlkfL3aoER83MIafEsZ ZfhaptwQ5qZV5D4ZsZmGcza+8vKg7UaCH9G1mfCkqCalrgdRK/UuVq1Upp5nRSWWQ4ZV KuUA== X-Gm-Message-State: APjAAAVpMkayf7IM4//5d3bl/c9nglTDTzvD5MUv1oM4ACHNuicpjNso dxfEnD+RA4kNbcMUqXptIwXVNteWfA== X-Google-Smtp-Source: APXvYqxh/83IBx2QJe/ME09ZV3uJvpQhC/UBbJovMQ4ikVHDJRomq50OJGC/dNIe29O76YiqHZBKTg== X-Received: by 2002:a63:e44b:: with SMTP id i11mr9212094pgk.297.1567799309199; Fri, 06 Sep 2019 12:48:29 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id q204sm5660149pfq.176.2019.09.06.12.48.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:28 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:36 -0700 Message-Id: <20190906194636.217881-15-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 14/15] ASoC: rt5677: Allow VAD to be shut on/off at all times 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" Due to limitations of the clocking configuration, we have no way of scheduling our hibernation before the bdw dsp hibernates. This causes issues when the system suspends with an open stream. We need userspace to toggle the kcontrol before we are suspended so that any writes on suspend are not lost and we don't corrupt the regmap. Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index a262a3dfbe2b..29233ec8906e 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -1023,13 +1023,8 @@ static int rt5677_dsp_vad_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); - struct rt5677_priv *rt5677 = snd_soc_component_get_drvdata(component); - - rt5677->dsp_vad_en = !!ucontrol->value.integer.value[0]; - if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) - rt5677_set_dsp_vad(component, - !!ucontrol->value.integer.value[0]); + rt5677_set_dsp_vad(component, !!ucontrol->value.integer.value[0]); return 0; } From patchwork Fri Sep 6 19:46:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Curtis Malainey X-Patchwork-Id: 11136005 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 BCAFC15E6 for ; Fri, 6 Sep 2019 19:59:16 +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 5161820854 for ; Fri, 6 Sep 2019 19:59:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="YQ8Ntp/A"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VR5c0Hk9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5161820854 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 8AB9415F9; Fri, 6 Sep 2019 21:58:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8AB9415F9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567799954; bh=msRbE+C6P2IJn42SPGzzwEMpBpFtwQbVMw7Trg+ngV0=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YQ8Ntp/ApLmkscxgqzyjdIMONGzFsqWgSP4LAaIz28Mnaz4rvBWoaM3rFUJJsVkfa eBcVo5j3NdscTmPXCHc6xnAjUAp0oDKQfLnwDNrzFlyYtcTrQfxBExh3uS9dvIKexT fwdDlDCCSHG/mcGQJnajvKTsM6/zCOcI01YY256I= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 51B74F80764; Fri, 6 Sep 2019 21:48:44 +0200 (CEST) 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 00359F80720; Fri, 6 Sep 2019 21:48:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 1D0AEF80713 for ; Fri, 6 Sep 2019 21:48:33 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 1D0AEF80713 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VR5c0Hk9" Received: by mail-pf1-x444.google.com with SMTP id b13so5199796pfo.8 for ; Fri, 06 Sep 2019 12:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FHelXmRjjAMyFKQqQPCAX20BQlp6Mvh3GA9PT+l9JFE=; b=VR5c0Hk9O79Y7WTUOEB64lcc0fLMari2XneVvolAHuMYrkvW5jhDnkKpZzMGVKLbVT Y1F25ro9kf/ceRehAoKZUufJZTa11reKjVX6Fcq6i97OmdqUMuSKOyITy4NWolScCtCe nGZ3XwsM7AcW4A08iEe3sgnEvpV+ch09yE/WQ= 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=FHelXmRjjAMyFKQqQPCAX20BQlp6Mvh3GA9PT+l9JFE=; b=FVyRgLrgJziJ3v4RzD/5EZQ1vNaQbTPsTPJPOWnZ9FJl3R73t6IFxumZVFA1Y04H8E vUP/dyesMqr7burJ7L03aMTwPqdLpUuXfrJaCfMpuyuW5NALRd74rfubqjV6GGHWOTJH edH4qKRAxW2zSyUHqrmcZQzioNyfBgs7IwzCXDdGqXCnxcm95UAaBUJCsWaTYFJbg7Wk 167NdfljppT5zVnuRdUJSJMyeBBW4AsQvBQym675mXFJCyjUGz54KSWCcJEU2L0UfWzZ qKxkaFd+DyIDIm910YZLTTXgqZVWyDGFrCffBhWGgpxfldAtYqVo7PRAI2wJ0NCxnuiO tcsA== X-Gm-Message-State: APjAAAWszg+n8o+/7GBn1WrfZOQoGtPoGmSOKCWb4e/uS5a2AeeiWWAq lkUOIQlYp/GSiYNxLGqkn1Sy/XoihQ== X-Google-Smtp-Source: APXvYqzd943Uapw3haUtFGonAKR9Ewoj4rqbVOCSUA2pGh6XEaYRVmh66QeBPF6GT6rQP2EZL56FoQ== X-Received: by 2002:a63:2004:: with SMTP id g4mr9041851pgg.97.1567799311873; Fri, 06 Sep 2019 12:48:31 -0700 (PDT) Received: from localhost ([2620:15c:202:201:c87a:31ae:9107:f63d]) by smtp.gmail.com with ESMTPSA id o129sm7175686pfg.1.2019.09.06.12.48.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Sep 2019 12:48:31 -0700 (PDT) From: Curtis Malainey To: alsa-devel@alsa-project.org Date: Fri, 6 Sep 2019 12:46:37 -0700 Message-Id: <20190906194636.217881-16-cujomalainey@chromium.org> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog In-Reply-To: <20190906194636.217881-1-cujomalainey@chromium.org> References: <20190906194636.217881-1-cujomalainey@chromium.org> MIME-Version: 1.0 Cc: Oder Chiou , Takashi Iwai , Liam Girdwood , Mark Brown , Bard Liao , Curtis Malainey Subject: [alsa-devel] [RFC 15/15] ASoC: rt5677: Turn on MCLK1 for DSP via DAPM 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" The RT5677 DSP needs the I2S MCLK1 to run its DSP. Add a dapm route to SSP0 CODEC IN so the clock is turned on automatically when the DSP is turned on. Signed-off-by: Curtis Malainey --- sound/soc/codecs/rt5677.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 29233ec8906e..2827a6d00ead 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c @@ -4305,6 +4305,8 @@ static const struct snd_soc_dapm_route rt5677_dapm_routes[] = { { "PDM1R", NULL, "PDM1 R Mux" }, { "PDM2L", NULL, "PDM2 L Mux" }, { "PDM2R", NULL, "PDM2 R Mux" }, + { "DSP Buffer", NULL, "SSP0 CODEC IN" }, + { "SSP0 CODEC IN", NULL, "DSPTX" }, }; static const struct snd_soc_dapm_route rt5677_dmic2_clk_1[] = {