From patchwork Thu Apr 20 10:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13218426 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 98887C77B72 for ; Thu, 20 Apr 2023 10:18:47 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 49121EF5; Thu, 20 Apr 2023 12:17:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 49121EF5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1681985925; bh=zxar5ggTufySclyWeDoPzCaSQfjlBFR1buy6QsfVEp8=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=gsFcOSE5NtT9OtEf+PvbloA2IhHca3uPuLV4XkMcmi1z5PT8KVS0yMJMg3XXsMzQk agSBRSF1nMAuHGC4Si1eW5XSItw6jjdDbSrqmJnnomf7ilri3R05gKex5u7eZylQLt zd5ibMSzEsAKGj1PKqFVN9SpBwBgOiN3XNimXQ2A= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id E6CB9F80548; Thu, 20 Apr 2023 12:16:45 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 95CF9F80548; Thu, 20 Apr 2023 12:16:42 +0200 (CEST) Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D2E79F800F8 for ; Thu, 20 Apr 2023 12:16:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D2E79F800F8 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Ut6iQ/+C Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-50506ac462bso671359a12.3 for ; Thu, 20 Apr 2023 03:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681985784; x=1684577784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/rqhyU6uXoU+/LhRADh+Yrxp3II6kKdCrObNCj5zZIk=; b=Ut6iQ/+CoIv1rPMxqnZvK0NSWdqeCFUzd6OEx1lKkUgb/r52SzTay59vOp6CZkva05 8SGuiVyeXnxzYx/n6GIJRR8oUGw9tjeCMCLAcQATcoAebowSItrF3GwVrDQDCqTYJTfv nVq35AQtK5pxpUcHSNBA7H0d14o3p7Dzu0lQ4p8r82XQdBVUBsvr4GJ7X4HY22Xt/IIt bUMDdwpLFNd8eyAy7mD+F1M84wUS4ga+3/PganPMZM3Cln5eEY8lqVR/OApIs0lFZn9M pVShqreCbx9e8O1gOETlPSNg8pzNbkIaLUyskwjwBn/1ifnBr+LoakoKoqAWmiDuDezk A3pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681985784; x=1684577784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/rqhyU6uXoU+/LhRADh+Yrxp3II6kKdCrObNCj5zZIk=; b=d4QhXeSGD2RRR8bLBVhWO3l5CRJPZb0Nj/iIDJPyTDKxPv2Mqkq+A3kaz47zfViscA NbqngvW82odB/Q2LMZbaoWWXLN8BZg7SUK07Il/7a7bgyHRovi2SH3v/6yFTKms5qSDm mnYpZSKz01kcrBJ4ECTsN4TVXxg/rGa3pvky7mM1i9lePDs2qhBfAOmRhWfmw8kaMSmT LLDdNP+552g4Y6+79qrUQNh8Gu7ZPhw8wKXDXqf0auNHoKCfai4tVRc1cwq7bPxlwvOY 0GB+7nxkiWJPUWtzo0UoaiC7yipjwPwxHZHkwZRS+4pUQngA/9QOtfNIz2V5mTh0py9c IoFw== X-Gm-Message-State: AAQBX9egKwolHPCkgKX89kKfTCHAI+Gbs/1NLkDe4ihQyccz4ZAUobdV OeS9O7ntwBGRFpGHnDaTAIV7pQ== X-Google-Smtp-Source: AKy350Y+TpaiL2KGRHt+2QkWwuPO6mgxsHGZDuQwdBnUEOwDHb/sJRBqccPNe3HpJgRk5w3gFxXlBw== X-Received: by 2002:aa7:d81a:0:b0:504:98f1:464c with SMTP id v26-20020aa7d81a000000b0050498f1464cmr1260446edq.23.1681985783905; Thu, 20 Apr 2023 03:16:23 -0700 (PDT) Received: from krzk-bin.. ([2a02:810d:15c0:828:bcb8:77e6:8f45:4771]) by smtp.gmail.com with ESMTPSA id l22-20020aa7c3d6000000b00506be898998sm588954edr.29.2023.04.20.03.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 03:16:23 -0700 (PDT) From: Krzysztof Kozlowski To: Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Andy Gross , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 1/6] ASoC: wcd938x: switch to using gpiod API Date: Thu, 20 Apr 2023 12:16:12 +0200 Message-Id: <20230420101617.142225-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> References: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Message-ID-Hash: 37SIXIGYNN22OY5TF5KYIB4RIAHJGAVI X-Message-ID-Hash: 37SIXIGYNN22OY5TF5KYIB4RIAHJGAVI X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Dmitry Torokhov , Krzysztof Kozlowski , Patrick Lai X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Dmitry Torokhov Switch the driver from legacy gpio API that is deprecated to the newer gpiod API that respects line polarities described in ACPI/DT. Signed-off-by: Dmitry Torokhov Reviewed-by: Krzysztof Kozlowski Tested-by: Krzysztof Kozlowski [krzysztof: rebased on recent dev_err_probe() changes] Signed-off-by: Krzysztof Kozlowski --- Cc: Patrick Lai --- sound/soc/codecs/wcd938x.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c index 11b264a63b04..33fd8fdde9fd 100644 --- a/sound/soc/codecs/wcd938x.c +++ b/sound/soc/codecs/wcd938x.c @@ -6,12 +6,14 @@ #include #include #include +#include #include +#include +#include #include #include #include #include -#include #include #include #include @@ -194,7 +196,7 @@ struct wcd938x_priv { int flyback_cur_det_disable; int ear_rx_path; int variant; - int reset_gpio; + struct gpio_desc *reset_gpio; struct gpio_desc *us_euro_gpio; u32 micb1_mv; u32 micb2_mv; @@ -4234,16 +4236,16 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device struct wcd_mbhc_config *cfg = &wcd938x->mbhc_cfg; int ret; - wcd938x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0); - if (wcd938x->reset_gpio < 0) - return dev_err_probe(dev, wcd938x->reset_gpio, - "Failed to get reset gpio\n"); + wcd938x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); + ret = PTR_ERR_OR_ZERO(wcd938x->reset_gpio); + if (ret) + return dev_err_probe(dev, ret, "Failed to get reset gpio\n"); wcd938x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro", GPIOD_OUT_LOW); - if (IS_ERR(wcd938x->us_euro_gpio)) - return dev_err_probe(dev, PTR_ERR(wcd938x->us_euro_gpio), - "us-euro swap Control GPIO not found\n"); + ret = PTR_ERR_OR_ZERO(wcd938x->us_euro_gpio); + if (ret) + return dev_err_probe(dev, ret, "us-euro swap Control GPIO not found\n"); cfg->swap_gnd_mic = wcd938x_swap_gnd_mic; @@ -4278,11 +4280,11 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device static int wcd938x_reset(struct wcd938x_priv *wcd938x) { - gpio_direction_output(wcd938x->reset_gpio, 0); - /* 20us sleep required after pulling the reset gpio to LOW */ + gpiod_set_value_cansleep(wcd938x->reset_gpio, 1); + /* 20us sleep required after asserting the reset gpio */ usleep_range(20, 30); - gpio_set_value(wcd938x->reset_gpio, 1); - /* 20us sleep required after pulling the reset gpio to HIGH */ + gpiod_set_value_cansleep(wcd938x->reset_gpio, 0); + /* 20us sleep required after releasing the reset gpio */ usleep_range(20, 30); return 0; From patchwork Thu Apr 20 10:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13218424 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E2BA9C77B73 for ; Thu, 20 Apr 2023 10:18:21 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1D9D3EE3; Thu, 20 Apr 2023 12:17:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1D9D3EE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1681985899; bh=hG7tW9YFcXEIJSmnkwqj7hx5DHRCpiFJW+qZg1g8oFE=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ABX/v6LYpYmfUPXrHKwsCfn3s6OfYKyhjZ+kKCr0GOBPYabg0eT7xvSPblpgUCo01 nSaoW1gDNmvpQGmQand6hOAaBfMQBgswZVxAmfDABibTIRWi0aDOva7y89jDgWVGVp tuIB3JiFKz/npqTHzH0QJ1bicusS83D8eUdVQTK0= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 2F45FF8052E; Thu, 20 Apr 2023 12:16:39 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B7048F80510; Thu, 20 Apr 2023 12:16:35 +0200 (CEST) Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 0678AF80155 for ; Thu, 20 Apr 2023 12:16:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0678AF80155 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=AmBkVOgl Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-94f32588c13so50307166b.2 for ; Thu, 20 Apr 2023 03:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681985785; x=1684577785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lJ7NFOY+m136Tpa7a3Lvd2KVX0E55mkuZub+f9mfMPg=; b=AmBkVOglK6tDRnpf5e1CjE9fZ783z5mKL+8fZ2ZovSKfIEaRbZG2hMsl/KZYx0GutP I4eilLey7aFQzEn7ekVDO8KmseLtE5PTAZDRLwn2BMgyGrZC7FEDBt/Dp4xCbjrM4nMX PExtibBF1phO8lOFATg7A1Vtim0z+UT6NDLufqy2uoALruXfdu+d+TPVALxWzqlWUzA6 T+GyHuG0AT4R7Gz3SSQotOWrU+a4WRBC/uMDUwxK18phb9KmLz2WNzbTxwMlB5A5NfNH Ets4NSbdZxAlxiComw5hFcoxnnqZUExblUbtNFza39VeKttRMXgdMGu3NppRYjhA4g+x /fyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681985785; x=1684577785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lJ7NFOY+m136Tpa7a3Lvd2KVX0E55mkuZub+f9mfMPg=; b=QuHWD70CyLBu7Pzul5cyCaArFTtGn4eSKlT8qBjEXTEprb7NGCFsaHAbjVTvyj9bmy RBUQWX7VxhjByrybL5z8nxhKNfDOUWM0WmApNgFs3JZLrI3M6YDym8hPdqG7FTE+6mKc xHbR5/2Gv+pEpuAYju63XXj6q0U1DYyTBB/Y0W9hieHvjILNdp25FD98mSU4iVzVYm9A 9jie8DkD90mt0jjZMPDsFC6g6ngQ8/TCKhroFYsYDqHBkCO8VzchsYy0xR3PjhStPO2u GcyZXmNpvdVzt9KgYS5EFMySP7bMgCVnJIvzKcTLem8CmHR46o7prBflh40fjU3p4cmW qV/g== X-Gm-Message-State: AAQBX9dJIfpQ8kxeviLgN9GWin2iu247MFCJHF4gNNgfpV7LKSw0VLTV aZQigTdNsZk7L10qCSXZN6nhzQ== X-Google-Smtp-Source: AKy350a9gCInOAQuMSUpXUGkll+ReqZrf7KjiUJPh73j3eJ9QX2mTKFQOiDbJcquHEnVTHtJWjfuwQ== X-Received: by 2002:a05:6402:1616:b0:504:9c59:7b8f with SMTP id f22-20020a056402161600b005049c597b8fmr1251270edv.36.1681985785537; Thu, 20 Apr 2023 03:16:25 -0700 (PDT) Received: from krzk-bin.. ([2a02:810d:15c0:828:bcb8:77e6:8f45:4771]) by smtp.gmail.com with ESMTPSA id l22-20020aa7c3d6000000b00506be898998sm588954edr.29.2023.04.20.03.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 03:16:25 -0700 (PDT) From: Krzysztof Kozlowski To: Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Andy Gross , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 2/6] ASoC: codecs: wcd938x: Keep device in reset till bind Date: Thu, 20 Apr 2023 12:16:13 +0200 Message-Id: <20230420101617.142225-3-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> References: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Message-ID-Hash: PLNEJ3TQSNKFUNWNSO72VBOAIVMURPXU X-Message-ID-Hash: PLNEJ3TQSNKFUNWNSO72VBOAIVMURPXU X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Krzysztof Kozlowski , Patrick Lai X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The Soundwire master expects that bus devices will be kept in reset state and brought out of it in their Soundwire probe() or bind(). Keeping it in reset state avoids early new Soundwire device interrupts in the master. Fix this in WCD938x platform driver by moving the reset toggle code from platform probe() to component bind(). Signed-off-by: Krzysztof Kozlowski --- I wasn't sure whether this deserves a Fixes tag. It looks like a fix, but OTOH, I don't think Soundwire master expectation is documented anywhere. Cc: Patrick Lai --- sound/soc/codecs/wcd938x.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c index 33fd8fdde9fd..212667a7249c 100644 --- a/sound/soc/codecs/wcd938x.c +++ b/sound/soc/codecs/wcd938x.c @@ -4236,7 +4236,8 @@ static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device struct wcd_mbhc_config *cfg = &wcd938x->mbhc_cfg; int ret; - wcd938x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_ASIS); + /* Keep device in reset status till wcd938x_bind() */ + wcd938x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); ret = PTR_ERR_OR_ZERO(wcd938x->reset_gpio); if (ret) return dev_err_probe(dev, ret, "Failed to get reset gpio\n"); @@ -4407,6 +4408,8 @@ static int wcd938x_bind(struct device *dev) return -EINVAL; } + wcd938x_reset(wcd938x); + wcd938x->regmap = devm_regmap_init_sdw(wcd938x->tx_sdw_dev, &wcd938x_regmap_config); if (IS_ERR(wcd938x->regmap)) { dev_err(dev, "%s: tx csr regmap not found\n", __func__); @@ -4508,8 +4511,6 @@ static int wcd938x_probe(struct platform_device *pdev) if (ret) return ret; - wcd938x_reset(wcd938x); - ret = component_master_add_with_match(dev, &wcd938x_comp_ops, match); if (ret) return ret; From patchwork Thu Apr 20 10:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13218425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 49F72C77B7A for ; Thu, 20 Apr 2023 10:18:27 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id C68C6EEC; Thu, 20 Apr 2023 12:17:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C68C6EEC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1681985904; bh=PUtIcUv4LpxNF7zx+8orlZy9Ak37MkcNokLi6jIVOf8=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Rfsgap53euP6kHSIa0QcyFuI98JPvIFUoCjEnbCQPdSSzqeFB0Xp7D0PonfXNH4FK BOJDk46/mfjC51yL16D1PC+fWZKBZpunZCuTX+3tk2D1FCHmy1/mzqb+6Fav8wMEy5 1XvfKZRVvwC/ta0ODrYWoa3pAm/g4XYR/CzpVN8k= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 95CA2F80534; Thu, 20 Apr 2023 12:16:41 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1FDC8F8052E; Thu, 20 Apr 2023 12:16:38 +0200 (CEST) Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id DD53EF8019B for ; Thu, 20 Apr 2023 12:16:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DD53EF8019B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ZY7V2Fz3 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9505214c47fso62292566b.1 for ; Thu, 20 Apr 2023 03:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681985787; x=1684577787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lh0gzMHKjXIEM7BMaBHJPBXLjPSxY0yCOjmfp2sB3bs=; b=ZY7V2Fz3NbWwq9aEj2mVn5PnKntw3UCQb4JlfiHhYV0ddMHpN+M8YLIYbeYsE+Ffsj HAguHowzIfVychuICmyTnPXqrCiMPohkRBiwJ5gFErVFL2Xe0YgYfZ2mlihhIgNvguNc WJSMsNFB4dEITw8ED4WVadG5Cg82WotrYQZV/esEjZnrq6uR8DvqTnNdmacy7mSZlxCQ dRkhmaqjCEYdd+QWFyqkEGUu1o9bCaNIUC0WDAMjx/nnqTAN2Q4k+sRXaFL1FpwbKdMl TEgTNFQY/B73e3xmmRB2a+UxETkMTtLGmrlFCrgs70IhUoPQd7MKs9vDEzegWoAtzQjv ynxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681985787; x=1684577787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lh0gzMHKjXIEM7BMaBHJPBXLjPSxY0yCOjmfp2sB3bs=; b=JSb3/TekIltrcVYsp2n2jBuRf9cciPiYoUI9Cax/O6I+vzAbK/WQDSQVPzTgCsDycI mZEFhL5dVbg4sV5F8hn0pudC6IVK9vzVx//eTWCM6Kum1SBOCTbg1+Pa5l8Yfngbt+Nw qDUxv6PtURsKjQ9zrLCvTw/UQMwtcRkI7zFvx9XhAlYvFs+ZGr3yqZ3pwGOVtNBEDTDp bLypkthgvmQv7MEjfU44UeljL+dBB+jMzBh+x8MUcIqlLOxQo58e0eCd0tr77EC27O/9 r9TJRzjnTiIdu2evuitQwzpNegZRGmdW3DTpWzTqW30qKleTpOIYLkXL1fqMhpX5g98M qErw== X-Gm-Message-State: AAQBX9eXlANs6RBdwWZW+OHHjgSPGUcuP31WgQYAdTpb98dpNmloegR6 XPsukS/M8TvKVcdnoV8ne1ADLg== X-Google-Smtp-Source: AKy350arZDGHMInHp8GuNY+Ano5ThS/SGyaLKa8v0e+z5Ka6cwm3FR2IPMhl6ymmgxoP66sw2zHKgg== X-Received: by 2002:aa7:d547:0:b0:506:98e8:7e58 with SMTP id u7-20020aa7d547000000b0050698e87e58mr999102edr.34.1681985786794; Thu, 20 Apr 2023 03:16:26 -0700 (PDT) Received: from krzk-bin.. ([2a02:810d:15c0:828:bcb8:77e6:8f45:4771]) by smtp.gmail.com with ESMTPSA id l22-20020aa7c3d6000000b00506be898998sm588954edr.29.2023.04.20.03.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 03:16:26 -0700 (PDT) From: Krzysztof Kozlowski To: Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Andy Gross , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 3/6] ASoC: codecs: wcd938x: Check for enumeration before using TX device Date: Thu, 20 Apr 2023 12:16:14 +0200 Message-Id: <20230420101617.142225-4-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> References: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Message-ID-Hash: XEEQ6263NVAM4USHK6E73HZZKJPRYHCL X-Message-ID-Hash: XEEQ6263NVAM4USHK6E73HZZKJPRYHCL X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Krzysztof Kozlowski , Patrick Lai X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Qualcomm WCD938x Soundwire codecs come as two Soundwire devices - TX and RX - on two Soundwire buses. In DTS they are represented as three device nodes: Soundwire TX, Soundwire RX and the platform codec node (binding to this driver). Probing (and Soundwire enumeration) of all devices can happen in any order, but only the Soundwire TX WCD938x device is used for accessing actual WCD938x registers. It is possible that component bind() in the platform driver will be called too early, before the Soundwire TX device is fully enumerated. This might work or might not, but we cannot handle it correctly from the codec driver. It's job for Soundwire master to bring up devices in correct order. At least add some simple warning, so such condition will not be undetected. Signed-off-by: Krzysztof Kozlowski --- Cc: Patrick Lai --- sound/soc/codecs/wcd938x.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c index 212667a7249c..e8e07e120fa1 100644 --- a/sound/soc/codecs/wcd938x.c +++ b/sound/soc/codecs/wcd938x.c @@ -77,6 +77,8 @@ #define WCD938X_MBHC_MOISTURE_RREF R_24_KOHM #define WCD_MBHC_HS_V_MAX 1600 +#define WCD938X_ENUM_TIMEOUT_MS 500 + #define WCD938X_EAR_PA_GAIN_TLV(xname, reg, shift, max, invert, tlv_array) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ @@ -4425,6 +4427,15 @@ static int wcd938x_bind(struct device *dev) wcd938x->sdw_priv[AIF1_PB]->slave_irq = wcd938x->virq; wcd938x->sdw_priv[AIF1_CAP]->slave_irq = wcd938x->virq; + /* + * Before any TX slave regmap usage, be sure the TX slave is actually + * enumerated. + */ + ret = wait_for_completion_timeout(&wcd938x->tx_sdw_dev->enumeration_complete, + msecs_to_jiffies(WCD938X_ENUM_TIMEOUT_MS)); + if (!ret) + dev_warn(dev, "Enumeration timeout in bind, possible failures in accessing registers\n"); + ret = wcd938x_set_micbias_data(wcd938x); if (ret < 0) { dev_err(dev, "%s: bad micbias pdata\n", __func__); From patchwork Thu Apr 20 10:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13218429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 28FCFC77B73 for ; Thu, 20 Apr 2023 10:19:38 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id F3852EE0; Thu, 20 Apr 2023 12:18:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz F3852EE0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1681985976; bh=PVPNQel4N9VzoSkBVR+6Pghc5HaknxNBVu8OTF/9Nls=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=rly4nX3mr34Rk/hL7jum8muHhY6y27WGNMzFaqPXjqiXf9wo3xvR+od3vh3G3kw0a rq0AEi2HI3YRPuvpPbfl659Ov9HV09SFXWlWUbZu7y4IGzWCz/HghuMa1x0/urOc0q 1WtMg5HBa+JxzOMpvBMN8iqRO6Qz9PzIvhsXx2yk= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id DA8E0F80529; Thu, 20 Apr 2023 12:18:38 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 122FEF8019B; Thu, 20 Apr 2023 12:18:34 +0200 (CEST) Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id DF7BDF80155 for ; Thu, 20 Apr 2023 12:16:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DF7BDF80155 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=juzJCbCa Received: by mail-ej1-x630.google.com with SMTP id fy21so5091567ejb.9 for ; Thu, 20 Apr 2023 03:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681985788; x=1684577788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VpQ/uiByxTl/QsWgu3jLMFo8/XrWsnc9Emr/ALFnhD8=; b=juzJCbCax+ZR55BV6ouJGNxhZQJBPU711okungZ3pQNmrEoyR931ePxvgdve2wtYmq Jo5yCuc760ZT0EihcZnOIQnIn3t5owUZbfZlJQvJ800CK8ZC8LgUFBpb7r64R9csuHyE 47001kvZkfIJ65ZMSPl3gZ6yt9wUk3el6rMgTE9m+u3TbK3BPfozq/QsmkrWWGrwLR6i M4527XvDh3F7Xg2XNVSTDm4k3vyt478WcvpP7rVYUjZqTRacJ9b6O+lOW6x4AQDWIt7w /ufw/IvoZ3WEhYODyW4+IpRx+3EuZaHv4yPAUx2uQlg7SE+LNLdfiLgpGO05csGzezRR 4a7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681985788; x=1684577788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VpQ/uiByxTl/QsWgu3jLMFo8/XrWsnc9Emr/ALFnhD8=; b=PSY4A+J9m6l3l0WNSvZAuZhJOSGqyM0zaOJn+9uJKJH/CiDF393epH+SHycXURiVQ8 3RFemOtA5arubyGCNVNU4liQ/07Oh+E2YMwh2nDr6edHp+WnHY6LayUTLCAUazTAGwMa CvW2rL2tm7WcGRbTYVsy+MQVuGRMF3bdMalaI+cjcMyT5BpE4fBWCruHqDTN8ErIvLEt udbN2mVNoXjLa0RevkaZfprQSg4oP2SU1rfN+Ln0cJEcqirGuPX0rjL4ye5Gx0KIh7Oh XlhStLvljxl8MgYq3GdhrJThwaBly6e2fJEG4UkMDduuqXpUajX3mRgZcciAkKMHm/mP Nnyw== X-Gm-Message-State: AAQBX9fMsU/7T4x4HAIkcuwCeJZ9sfIttH1fwuKilHNUytrFwiwlakBh G85amBuHGa1yQSngukNsskHJzm5CISPUM0hY3K2E2Q== X-Google-Smtp-Source: AKy350aJoXHpvCCTWt/My96Kx7KquB21h2WQBonG6sOA+uTsE5mM4HqBnVFra41oLy4Ah/SCA9aJ4A== X-Received: by 2002:a17:906:4f17:b0:933:3a22:8513 with SMTP id t23-20020a1709064f1700b009333a228513mr1129561eju.53.1681985787930; Thu, 20 Apr 2023 03:16:27 -0700 (PDT) Received: from krzk-bin.. ([2a02:810d:15c0:828:bcb8:77e6:8f45:4771]) by smtp.gmail.com with ESMTPSA id l22-20020aa7c3d6000000b00506be898998sm588954edr.29.2023.04.20.03.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 03:16:27 -0700 (PDT) From: Krzysztof Kozlowski To: Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Andy Gross , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 4/6] soundwire: qcom: drop unused struct qcom_swrm_ctrl members Date: Thu, 20 Apr 2023 12:16:15 +0200 Message-Id: <20230420101617.142225-5-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> References: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Message-ID-Hash: M3JTVCLRPAT2IDSHL6S5E43JMF2H5AIZ X-Message-ID-Hash: M3JTVCLRPAT2IDSHL6S5E43JMF2H5AIZ X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Krzysztof Kozlowski , Patrick Lai X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Drop unused members from the driver state container: struct qcom_swrm_ctrl. Signed-off-by: Krzysztof Kozlowski --- Cc: Patrick Lai --- drivers/soundwire/qcom.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index fae8640b142b..679990dc3cc4 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -187,12 +187,9 @@ struct qcom_swrm_ctrl { #endif struct completion broadcast; struct completion enumeration; - struct work_struct slave_work; /* Port alloc/free lock */ struct mutex port_lock; struct clk *hclk; - u8 wr_cmd_id; - u8 rd_cmd_id; int irq; unsigned int version; int wake_irq; From patchwork Thu Apr 20 10:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13218428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 12D37C77B72 for ; Thu, 20 Apr 2023 10:19:30 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id BD875F05; Thu, 20 Apr 2023 12:18:37 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz BD875F05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1681985967; bh=i5D3ABoYxn9vlmdYv8kaYY/Qr7ojw/0YBJKWr9yoZcs=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=jKXErvmGmRSmHfteWD3c7lg0Bv8/50MggqtB2GLqiO0eUum/S9kT8AhlArebkAe52 daYZ8B1IpdhDcOHUy/dPgNatZdgzzknzjMyFtwm6jnh/6OPHoE8xveu05Qy/nZCrst c/mu7741oGDeXNY4MSTBL2tBe4NA5LaVV/JAJCwA= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 5F9F7F800F8; Thu, 20 Apr 2023 12:18:37 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4642CF8019B; Thu, 20 Apr 2023 12:18:33 +0200 (CEST) Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8E3DDF804FC for ; Thu, 20 Apr 2023 12:16:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8E3DDF804FC Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=PtBULmQb Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-504eccc8fc8so674885a12.2 for ; Thu, 20 Apr 2023 03:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681985789; x=1684577789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AeY19byibaKQU5SmsEhk5n4vvprUavR/0B7l0HzeYIU=; b=PtBULmQbRQK20LScpRHebHKUZ901DjN1+0eDl2Of/GBmLfksDulveUnoVXib8qy+uD QUe+Yb8aMFMzNSO1V+nHCMwhblZ/UApGmT/xVxec0sSS8yLQ3228EM2ky/wV2O6QTinR TbER1FHIeDgGvgB9Dpr62VcWaWGuk53+yeNTODNT1OH4iyNVPz6lswqcRoup8QuiJ7h9 G+ydlD2RLMmNwpNDrzo7jy5U95KruGjzYVechUf+52Nypvhhag90S5KPva7I+4yr5maE zHmELbVNzxsf2OI5Q0g2dnKxKMG6T2PDh7Oz/jga08dkZdQFGAPqpSKSwKTmCzYf9sUv 9KAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681985789; x=1684577789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AeY19byibaKQU5SmsEhk5n4vvprUavR/0B7l0HzeYIU=; b=UVG7gumqar+R/lIDZGS1UjOVMUWOLnCoVzoR2++5fjD+hP5JB4sT4+X3LKqivGY9Qz nGhL46h/6CpSo0njCR21h0u1GIZYXZzSUU3X6Jqv+2RkluGplVNRlmJPsLBeN1+Ue9wM 3HMwaj1KQQKgAJ/BFvvd5eEGVMxbUqF8qKpwW78FLMxn5Aj7nS2jzUvHEEupbswQR9Ad LABVnU6dDE69BWVNCnGe6JrntrTvC10kSRtB2VAkoeXdGX5fMYVWK7KVGrLpqKFhv5Zv PT8aVfsi10VdoZLt4lMkI+SLDcygCpnbNKv0+1/kjJt+mSkcTx8k5zAgWUJyj9wsTdc2 6Fgg== X-Gm-Message-State: AAQBX9dnFvItPXHEy3mx7Nzq0gtkmR/A7FggF8+SPJyOfxcUVSCdveuT xwAk1+dbMc34bFx06ctbNad45g== X-Google-Smtp-Source: AKy350ab0FABnbmrq7aa1gl1X9x4VEUtxamldKuTt6enWYqiZCxTZKEHSXUbjkdPzuX8LK1YY94UYQ== X-Received: by 2002:aa7:d5c1:0:b0:506:8470:c323 with SMTP id d1-20020aa7d5c1000000b005068470c323mr1381184eds.24.1681985789356; Thu, 20 Apr 2023 03:16:29 -0700 (PDT) Received: from krzk-bin.. ([2a02:810d:15c0:828:bcb8:77e6:8f45:4771]) by smtp.gmail.com with ESMTPSA id l22-20020aa7c3d6000000b00506be898998sm588954edr.29.2023.04.20.03.16.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 03:16:28 -0700 (PDT) From: Krzysztof Kozlowski To: Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Andy Gross , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 5/6] soudnwire: master: protect concurrecnt check for bus->md Date: Thu, 20 Apr 2023 12:16:16 +0200 Message-Id: <20230420101617.142225-6-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> References: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Message-ID-Hash: FXJFBWTADUGQT7KAMYH5K7OBVSF5GNNL X-Message-ID-Hash: FXJFBWTADUGQT7KAMYH5K7OBVSF5GNNL X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Krzysztof Kozlowski , Patrick Lai X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The Soundwire master controllers might want to check for bus->md initialization to avoid race between early interrupt and finish of sdw_bus_master_add()/sdw_master_device_add(). Such early interrupt can happen if Soundwire devices are not powered off during their probe. Add a store release barrier, so the Soundwire controllers can safely check it in concurrent (e.g. in interrupt) way. Signed-off-by: Krzysztof Kozlowski --- Cc: Patrick Lai --- drivers/soundwire/master.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/soundwire/master.c b/drivers/soundwire/master.c index 9b05c9e25ebe..d5bf13e7e602 100644 --- a/drivers/soundwire/master.c +++ b/drivers/soundwire/master.c @@ -161,7 +161,12 @@ int sdw_master_device_add(struct sdw_bus *bus, struct device *parent, /* add shortcuts to improve code readability/compactness */ md->bus = bus; bus->dev = &md->dev; - bus->md = md; + /* + * Make sure the contents of md is stored before storing bus->md. + * Paired with new slave attached and slave status interrupts + * on the Soundwire master side. + */ + smp_store_release(&bus->md, md); pm_runtime_set_autosuspend_delay(&bus->md->dev, SDW_MASTER_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(&bus->md->dev); From patchwork Thu Apr 20 10:16:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13218427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1AC45C77B72 for ; Thu, 20 Apr 2023 10:19:12 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id C9E3BF00; Thu, 20 Apr 2023 12:18:19 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C9E3BF00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1681985949; bh=jN8ld25u9/hpYreX3PvryA/Sh0N2V4CloXsfrbczsJ0=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=jId/Vb14ewuZvEVXEJsP3qaAmxQAJR9vUGa0quwLhuMHLE0X8PFjRbp87Q2wrSPDy 9vx6ewEX703UuRfLR+TepXJDPAERpJ7sHlfoPi48bqrpeSERjC0iolOGgxxbpAcGb9 9c61m5lsEfURhqOuGrvuy5A9XhzsnDmYXnW9yz5I= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 5D492F80552; Thu, 20 Apr 2023 12:16:52 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 047ABF80552; Thu, 20 Apr 2023 12:16:48 +0200 (CEST) Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E3A5FF80149 for ; Thu, 20 Apr 2023 12:16:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E3A5FF80149 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ZdhT1l/E Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-50506ac462bso671426a12.3 for ; Thu, 20 Apr 2023 03:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681985790; x=1684577790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gxQN4hZ4JVSgplNB9vM+TACxEqA37qdo6fBUY/Qfhug=; b=ZdhT1l/Ewnw8PJH9WHmYU66panGvAGmseKsA1QI14AcHKVjKMxVnU3LzsyflnJaSsT 0SsaSKbcWs7WckSg27jljRg6VV3DwqhpTLP6IQGi/ukXFFUEFcPf77aJPNk1r6zWsAej 9naiRVNvRcz5F/OBPqzOYQqWgb9MZD3r9qf94IrZh9CvL8ZXCvkjTR+YO2hbADbWUKv2 ATvis3qRCxbidFKHfTut9rMBICDy00uRi9OXLFLIijGALI+2XDJdj8NJtdDDNAw5xgeF S4oFzhhbIZ37jr7lIrwpStGblZyQ9UE3jwRtyUfVymNzKv5D2vUZWLGXgfJtzCSOUzME rw4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681985790; x=1684577790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gxQN4hZ4JVSgplNB9vM+TACxEqA37qdo6fBUY/Qfhug=; b=WiAM16dXZdyCofXz8fBKx6XiV7fTKZ8+W3oXSVli2K6A+FB7nGuDBEQPqzi99UB4Dx 5ftYMqNzTnYTTMUi3KNCAuXDhG7JSkmlg9g87rrlhxN93URsZyQuTExZr/tzPVDuTjXs rpSKIYVTo38O9DxbzP10aG7QG66rs2q5g6IwIaXIAOwvafYnPtqNNncWZkjcf3mRCqi/ MXT561U/WsT3Sw4Q9GLMjoXy9Gk8+zC5o2f5Rta2b1a086/p9q2tSULtHrnr3ZUnuOrJ GmdMM9efuPp1HDcz6RGWi60SsllPKpTBM5eQG9gBX78uKRCnOInXMZv9E+TSWLWsZKyo JBrg== X-Gm-Message-State: AAQBX9cP1Bx1bbOoJFiOoIY23zzht7PbJANofhA0nYvP26EoF2ZDB6Ex YAyVPRXgzrh+dz2sVLMw9LY/+Q== X-Google-Smtp-Source: AKy350ZGpkQT2xEEpIlm7akllE9wiybPG/3gcFKmyhXXX82oydlx7HcP+cAwnEryxuxKBnISy8rfiQ== X-Received: by 2002:aa7:d78d:0:b0:506:be3f:ebb5 with SMTP id s13-20020aa7d78d000000b00506be3febb5mr1365210edq.1.1681985790496; Thu, 20 Apr 2023 03:16:30 -0700 (PDT) Received: from krzk-bin.. ([2a02:810d:15c0:828:bcb8:77e6:8f45:4771]) by smtp.gmail.com with ESMTPSA id l22-20020aa7c3d6000000b00506be898998sm588954edr.29.2023.04.20.03.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 03:16:30 -0700 (PDT) From: Krzysztof Kozlowski To: Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Andy Gross , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 6/6] soundwire: qcom: do not probe devices before bus/link init Date: Thu, 20 Apr 2023 12:16:17 +0200 Message-Id: <20230420101617.142225-7-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> References: <20230420101617.142225-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 Message-ID-Hash: 74WPPAH5RWRAQHHJNZOXLB3V5OMCZ2E3 X-Message-ID-Hash: 74WPPAH5RWRAQHHJNZOXLB3V5OMCZ2E3 X-MailFrom: krzysztof.kozlowski@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Krzysztof Kozlowski , Patrick Lai X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Soundwire devices are supposed to be kept in reset state (powered off) till their probe() or component bind() callbacks. However if they are already powered on, then they might enumerate before the master initializes bus in qcom_swrm_init() leading to occasional errors like: qcom-soundwire 6d30000.soundwire-controller: Qualcomm Soundwire controller v2.0.0 Registered wcd938x_codec audio-codec: bound sdw:0:0217:010d:00:4 (ops wcd938x_sdw_component_ops) wcd938x_codec audio-codec: bound sdw:0:0217:010d:00:3 (ops wcd938x_sdw_component_ops) qcom-soundwire 6ad0000.soundwire-controller: swrm_wait_for_wr_fifo_avail err write overflow The problem primarily lies in Qualcomm Soundwire controller probe() sequence: 1. request_threaded_irq() 2. sdw_bus_master_add() - which will cause probe() and component bind() of Soundwire devices, e.g. WCD938x codec drivers. Device drivers might already start accessing their registers. 3. qcom_swrm_init() - which initializes the link/bus and enables interrupts. Any access to device registers at (2) above, will fail because link/bus is not yet initialized. However the fix is not as simple as moving qcom_swrm_init() before sdw_bus_master_add(), because this will cause early interrupt of new slave attached. The interrupt handler expects bus master (ctrl->bus.md) to be allocated, so this would lead to NULL pointer exception. Rework the init sequence and change the interrupt handler. The correct sequence fixing accessing device registers before link init is now: 1. qcom_swrm_init() 2. request_threaded_irq() 3. sdw_bus_master_add() which still might cause early interrupts, if Soundwire devices are not in powered off state before their probe. This early interrupt issue is fixed by checking if bus master (ctrl->bus.md) was allocated and if not, scheduling delayed work for enumerating the slave device. Since we actually can handle early interrupt now, drop IRQF_TRIGGER_RISING flag from the interrupt, because it is not really valid and driver should use flags provided by DTS. Signed-off-by: Krzysztof Kozlowski --- Change context depends on: https://lore.kernel.org/r/20230209131336.18252-3-srinivas.kandagatla@linaro.org https://lore.kernel.org/all/20230418095447.577001-1-krzysztof.kozlowski@linaro.org/ Cc: Patrick Lai --- drivers/soundwire/qcom.c | 89 ++++++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 17 deletions(-) diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index 679990dc3cc4..802d939ce7aa 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include "bus.h" @@ -187,6 +188,7 @@ struct qcom_swrm_ctrl { #endif struct completion broadcast; struct completion enumeration; + struct delayed_work new_slave_work; /* Port alloc/free lock */ struct mutex port_lock; struct clk *hclk; @@ -606,6 +608,37 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus) return 0; } +static void qcom_swrm_new_slave(struct work_struct *work) +{ + struct qcom_swrm_ctrl *ctrl = container_of(work, struct qcom_swrm_ctrl, + new_slave_work.work); + + /* + * All Soundwire slave deviecs are expected to be in reset state (powered down) + * during sdw_bus_master_add(). The slave device should be brougth + * from reset by its probe() or bind() function, as a result of + * sdw_bus_master_add(). + * Add a simple check to avoid NULL pointer except on early interrupts. + * Note that if this condition happens, the slave device will not be + * enumerated. Its driver should be fixed. + * + * smp_load_acquire() paired with sdw_master_device_add(). + */ + if (!smp_load_acquire(&ctrl->bus.md)) { + dev_err(ctrl->dev, + "Got unexpected, early interrupt, device will not be enumerated\n"); + return; + } + + clk_prepare_enable(ctrl->hclk); + + qcom_swrm_get_device_status(ctrl); + qcom_swrm_enumerate(&ctrl->bus); + sdw_handle_slave_status(&ctrl->bus, ctrl->status); + + clk_disable_unprepare(ctrl->hclk); +}; + static irqreturn_t qcom_swrm_wake_irq_handler(int irq, void *dev_id) { struct qcom_swrm_ctrl *ctrl = dev_id; @@ -668,9 +701,17 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) dev_dbg(ctrl->dev, "Slave status not changed %x\n", slave_status); } else { - qcom_swrm_get_device_status(ctrl); - qcom_swrm_enumerate(&ctrl->bus); - sdw_handle_slave_status(&ctrl->bus, ctrl->status); + unsigned long delay = 0; + + /* + * See qcom_swrm_new_slave() for + * explanation. smp_load_acquire() paired + * with sdw_master_device_add(). + */ + if (!smp_load_acquire(&ctrl->bus.md)) + delay = 10; + schedule_delayed_work(&ctrl->new_slave_work, + delay); } break; case SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET: @@ -780,6 +821,7 @@ static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl) ctrl->intr_mask = SWRM_INTERRUPT_STATUS_RMSK; /* Mask soundwire interrupts */ + if (ctrl->version < SWRM_VERSION_2_0_0) ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_MASK_ADDR], SWRM_INTERRUPT_STATUS_RMSK); @@ -1485,6 +1527,7 @@ static int qcom_swrm_probe(struct platform_device *pdev) mutex_init(&ctrl->port_lock); init_completion(&ctrl->broadcast); init_completion(&ctrl->enumeration); + INIT_DELAYED_WORK(&ctrl->new_slave_work, qcom_swrm_new_slave); ctrl->bus.ops = &qcom_swrm_ops; ctrl->bus.port_ops = &qcom_swrm_port_ops; @@ -1514,9 +1557,10 @@ static int qcom_swrm_probe(struct platform_device *pdev) ctrl->reg_read(ctrl, SWRM_COMP_HW_VERSION, &ctrl->version); + qcom_swrm_init(ctrl); + ret = devm_request_threaded_irq(dev, ctrl->irq, NULL, qcom_swrm_irq_handler, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, "soundwire", ctrl); if (ret) { @@ -1524,18 +1568,6 @@ static int qcom_swrm_probe(struct platform_device *pdev) goto err_clk; } - ctrl->wake_irq = of_irq_get(dev->of_node, 1); - if (ctrl->wake_irq > 0) { - ret = devm_request_threaded_irq(dev, ctrl->wake_irq, NULL, - qcom_swrm_wake_irq_handler, - IRQF_TRIGGER_HIGH | IRQF_ONESHOT, - "swr_wake_irq", ctrl); - if (ret) { - dev_err(dev, "Failed to request soundwire wake irq\n"); - goto err_init; - } - } - pm_runtime_set_autosuspend_delay(dev, 3000); pm_runtime_use_autosuspend(dev); pm_runtime_mark_last_busy(dev); @@ -1549,7 +1581,18 @@ static int qcom_swrm_probe(struct platform_device *pdev) goto err_clk; } - qcom_swrm_init(ctrl); + ctrl->wake_irq = of_irq_get(dev->of_node, 1); + if (ctrl->wake_irq > 0) { + ret = devm_request_threaded_irq(dev, ctrl->wake_irq, NULL, + qcom_swrm_wake_irq_handler, + IRQF_TRIGGER_HIGH | IRQF_ONESHOT, + "swr_wake_irq", ctrl); + if (ret) { + dev_err(dev, "Failed to request soundwire wake irq\n"); + goto err_init; + } + } + wait_for_completion_timeout(&ctrl->enumeration, msecs_to_jiffies(TIMEOUT_MS)); ret = qcom_swrm_register_dais(ctrl); @@ -1589,6 +1632,18 @@ static int qcom_swrm_remove(struct platform_device *pdev) { struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(&pdev->dev); + /* + * Mask interrupts to be sure no delayed work can be scheduler after + * removing Soundwire bus master. + */ + if (ctrl->version < SWRM_VERSION_2_0_0) + ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_MASK_ADDR], + 0); + if (ctrl->mmio) + ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN], + 0); + + cancel_delayed_work_sync(&ctrl->new_slave_work); sdw_bus_master_delete(&ctrl->bus); clk_disable_unprepare(ctrl->hclk);