From patchwork Mon Feb 17 03:16:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11385049 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 7B070924 for ; Mon, 17 Feb 2020 03:17:33 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 54ABC2070B for ; Mon, 17 Feb 2020 03:17:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uzpnxcSK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="XM+8y09N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 54ABC2070B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=X+MucpNAlEl/OoR7vNng0V1eHWECF/lqKpgIM1aSfK4=; b=uzpnxcSK708TiF G0t8BuFfYLmU5ub0UJcWgZkShyyocrHGoRYQvdBQWAM0FYHjI1Ymz0mk5YBG408gU99FUcbxSr4Bq IauIH49HFgjsiWstiB7JHyuLPumn0FZ/FvH420hMwBznpi9Gxr167ROBTauTLnIaRcis5FuoPoubv pV6BFZKEuKob8ElODxeee/7VNBEIWc2Sx7buGeXV0YKgGEiOTJlbmZqY1ey2o53JnLRr8MuBm75Gp UQRNmxNR8Z+JL0Nij8u42WPttU/f21c0F0acsKXsXjPQ73U6URS3wBqDKlmEByx8ovMj1T5DVgaWY i52Q+vUo7z5uvafFV9BA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j3WuY-00038S-10; Mon, 17 Feb 2020 03:17:30 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j3WuF-0002iK-KT for linux-mediatek@lists.infradead.org; Mon, 17 Feb 2020 03:17:12 +0000 Received: by mail-pg1-x549.google.com with SMTP id i21so10824315pgm.21 for ; Sun, 16 Feb 2020 19:17:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=WyY8AR/W9Xhoq+FoZI+JwslnVAFfNuC6P4tiCJpqlNM=; b=XM+8y09NmdcBqI5tENuyJPgoZPkNcFlWhBEVm/VyNB+qqCVUPFfySf1XAX9fcSBAQN eoRDs7U0lYvGlwNkmFXyFzeq6BdniLjOJdL8ITVb/+H3yghkqT+ZlpKBIGI884IyFMKE W+qoM4sYK9ncnSBM1vyoFvhdPR3Y+wXyKIsptwL6L4IBBER1s29g3hi9t7du2SiwtH9a ihemetgpwqoBtq8J7DqYEER4KfPtAMXdRYwRUdSF3OwK5AHiXTqky3ZK0LAlUctdGYFs xmKWCss+5sKWOwC/dkSf/EEGUoIDUZOJFRfZNiJ+iincRUpl9wM1x5EGjizutSP0ABkC De8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WyY8AR/W9Xhoq+FoZI+JwslnVAFfNuC6P4tiCJpqlNM=; b=luYv22kiHhR0zbXqwKNixH5qpaPH19UbYW4kh3OEHxq9o9CgDNywIp/PtK7Bw18oBV r5V45LHDMxkJuuiBBgFW//lp+w/F709FEmJMHZ+EtdoS+MDvUTKA5NvPi3Auk1msWwZS 7Bq81xeNr5E52/AbhoKXKMugI/pKU7aGeZRZ2KxPpgs0vXltQG9YVbhHO971sKYDF6hA JTAPyjG9oghY1e8V+DXzfTbZ7SFHFgg2AuVW+nVQqkBT36SJeMjDmWhR/C9zwP1YBRow mQJfd0AhW8os2peo9X6yGK3/R/1I0yMRNcZOefa3Jx8jSaVEl+enfT/tNQVXSvS3jcLQ 64+A== X-Gm-Message-State: APjAAAU0aPr/k2icplNeGq6uISdT4jXs2zTCYLlqVU2TSH0AHbzADZnH QP77h0vpUW6vyxE4MZUgkG9azcnk3zpq X-Google-Smtp-Source: APXvYqyaA0c4C3Cy5dT8KODvRZRHXgVJd5DJOU44ArgLhO1/lknUXh2t3cF80g4vSNUWgNRWhTevS8xJmETl X-Received: by 2002:a63:ac46:: with SMTP id z6mr13808575pgn.301.1581909425929; Sun, 16 Feb 2020 19:17:05 -0800 (PST) Date: Mon, 17 Feb 2020 11:16:52 +0800 In-Reply-To: <20200217031653.52345-1-tzungbi@google.com> Message-Id: <20200217105513.1.Icc323daaf71ad02f191fd8d91136b01b61eca5e3@changeid> Mime-Version: 1.0 References: <20200217031653.52345-1-tzungbi@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v2 1/2] ASoC: hdmi-codec: set plugged_cb to NULL when component removing From: Tzung-Bi Shih To: broonie@kernel.org, airlied@linux.ie, daniel@ffwll.ch X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200216_191711_691512_C1DA8EF0 X-CRM114-Status: GOOD ( 10.05 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:549 listed in] [list.dnswl.org] -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_MED DKIMwl.org - Medium sender X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, cychiang@google.com, tzungbi@google.com, dri-devel@lists.freedesktop.org, ck.hu@mediatek.com, linux-mediatek@lists.infradead.org, p.zabel@pengutronix.de, matthias.bgg@gmail.com, dgreid@google.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org Sets plugged_cb to NULL when component removing to notify its consumers : no further plugged status report is required. Signed-off-by: Tzung-Bi Shih --- sound/soc/codecs/hdmi-codec.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index 444cc4e3374e..f005751da2cc 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -779,7 +779,17 @@ static int hdmi_of_xlate_dai_id(struct snd_soc_component *component, return ret; } +static void hdmi_remove(struct snd_soc_component *component) +{ + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); + + if (hcp->hcd.ops->hook_plugged_cb) + hcp->hcd.ops->hook_plugged_cb(component->dev->parent, + hcp->hcd.data, NULL, NULL); +} + static const struct snd_soc_component_driver hdmi_driver = { + .remove = hdmi_remove, .dapm_widgets = hdmi_widgets, .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), .of_xlate_dai_id = hdmi_of_xlate_dai_id, From patchwork Mon Feb 17 03:16:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11385051 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 77841924 for ; Mon, 17 Feb 2020 03:17:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 54EC12070B for ; Mon, 17 Feb 2020 03:17:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="YOacd+La"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="NS+hvD7V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 54EC12070B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8Q+EunFu0aiMB5iQVEmkgCw/2i2lq3kiUiTsbNswcFk=; b=YOacd+Lah398P1 Tg+u7Z4kNF56YlSx2d0iEG2BA1MWVtfbVyJyc4e+fEuE4wtkL+LYcNAnic7U0qqmm+73JGMAKg+jt T9Ve8MihAOYskfdeBl6J5NlVXg2+lBpSAJXH+2UcPyAWn1DsRnm1QfyrPQNGv1VVtLTJWwmcv39Y6 BpsCSdBSikYF4Q/0E7B7r6GDD/WKmXEfYwk1LmEfpK9lUXAkRsWgGSg3di9rKWgIfvEaekHflIYtw sMVBJdhXbl8Hgnx2WVfpya2A2PEOVtyPdVhYj87rgHLIzxHmwWFtPucpe4ToKBpoOzGrQEXib+wk4 lnTbcVwv0yeOV6T1uk8g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j3Wub-0003BU-6D; Mon, 17 Feb 2020 03:17:33 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j3WuH-0002nI-0E for linux-mediatek@lists.infradead.org; Mon, 17 Feb 2020 03:17:14 +0000 Received: by mail-pl1-x64a.google.com with SMTP id p19so7500905plr.8 for ; Sun, 16 Feb 2020 19:17:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=E5BCGldRe7eFAGLQVFmcBimFYUghF+IzwiWzbxZYe7o=; b=NS+hvD7VZRtKE2R/Xq1U75r1q6HgBSXd3k2OLQjZfHV8YaUAHr1smXbLENNirFdHsj PtSomq4XOq1mVdmGlECgRU5iTiJHjiRBYDjMPhCsUSgwRhxV1WnmYjht+97oXpYXp5a3 kZHl4MHCDRntHydqUWIj6KHo0KmUBhC5b1yTRVfM5/0q/UXBC//Xx9Gtpc6ekyaG1Hk0 eZpoybGZzoHdV2kgPX9L3vVhZ3WvtqnE0cvx+IktBq2MYvS0Yx6UgWqflya9nUMrr63U 98DLX1iN+RwZH0ZxFfNuSUFkcM55pIzjwkxZsvbbBH25fTgYKgHTKKIUHPcW9YIXIKlb /MUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=E5BCGldRe7eFAGLQVFmcBimFYUghF+IzwiWzbxZYe7o=; b=ato/OVKtnatN1bN9U7XoFFCQxaH5qowcp9xr8aLjODdu8tbQfjO10A6cOFl8eGLjeD fHq274R3J4y4RQxQVaGGvOq17DC9GrGeVLYaCaoJpHi/RF7JnS2hslv2OWb7eeFSbci/ Uq9KTUpCjvWh08a+BUSB6EPTMv/VDHzPnRmw3t4Nmyim1ObFiB5Uy6ZUFnYs3Up3+NHx 7pd7eLWTx29rR4dGcNRxp9tYFAb6W5WBQP0JTsCDoaGAFWah1bEb4LCIqUDTvbN0ZoXk 4VJZIOtJ4NRB/9uRJv2wgDxRqQEJ3J5z1O3FQZvf1oxwcf4OJJSitWkTIHTnhBxai60h 5ttg== X-Gm-Message-State: APjAAAUzqmRF3Bwc9WmxVGv/OvB5jEF9hmRMJmSwWALMJ7gpvbj9lAHW XJ2seYv8rft3ocv2R0NdC36dk4KTd+tI X-Google-Smtp-Source: APXvYqwFBo1TW5OKjVbnTeWNYS7iTLxNwp5AqpuvTgk8sGrNAAP3BgmmBO1Yc/QvcgfKirYdziuDCiuk48HH X-Received: by 2002:a63:de54:: with SMTP id y20mr15796824pgi.79.1581909431033; Sun, 16 Feb 2020 19:17:11 -0800 (PST) Date: Mon, 17 Feb 2020 11:16:53 +0800 In-Reply-To: <20200217031653.52345-1-tzungbi@google.com> Message-Id: <20200217105513.2.I477092c2f104fd589133436c3ae4590e6fc6323b@changeid> Mime-Version: 1.0 References: <20200217031653.52345-1-tzungbi@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v2 2/2] drm/mediatek: fix race condition for HDMI jack status reporting From: Tzung-Bi Shih To: broonie@kernel.org, airlied@linux.ie, daniel@ffwll.ch X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200216_191713_068553_6194E272 X-CRM114-Status: GOOD ( 11.85 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:64a listed in] [list.dnswl.org] -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_MED DKIMwl.org - Medium sender X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, cychiang@google.com, tzungbi@google.com, dri-devel@lists.freedesktop.org, ck.hu@mediatek.com, linux-mediatek@lists.infradead.org, p.zabel@pengutronix.de, matthias.bgg@gmail.com, dgreid@google.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org hdmi_conn_detect and mtk_hdmi_audio_hook_plugged_cb would be called by different threads. Imaging the following calling sequence: Thread A Thread B -------------------------------------------------------------------- mtk_hdmi_audio_hook_plugged_cb() mtk_cec_hpd_high() -> disconnected hdmi_conn_detect() mtk_cec_hpd_high() -> connected plugged_cb(connected) plugged_cb(disconnected) The latest disconnected is false reported. Makes mtk_cec_hpd_high and plugged_cb atomic to fix. Also uses the same lock to protect read/write of plugged_cb and codec_dev. Fixes: 5d3c64477392 ("drm/mediatek: support HDMI jack status reporting") Signed-off-by: Tzung-Bi Shih Acked-by: CK Hu --- drivers/gpu/drm/mediatek/mtk_hdmi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c index 03aeb73005ef..d80017e3d84a 100644 --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -171,6 +172,7 @@ struct mtk_hdmi { bool enabled; hdmi_codec_plugged_cb plugged_cb; struct device *codec_dev; + struct mutex update_plugged_status_lock; }; static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b) @@ -1199,10 +1201,13 @@ static void mtk_hdmi_clk_disable_audio(struct mtk_hdmi *hdmi) static enum drm_connector_status mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi) { - bool connected = mtk_cec_hpd_high(hdmi->cec_dev); + bool connected; + mutex_lock(&hdmi->update_plugged_status_lock); + connected = mtk_cec_hpd_high(hdmi->cec_dev); if (hdmi->plugged_cb && hdmi->codec_dev) hdmi->plugged_cb(hdmi->codec_dev, connected); + mutex_unlock(&hdmi->update_plugged_status_lock); return connected ? connector_status_connected : connector_status_disconnected; @@ -1669,8 +1674,11 @@ static int mtk_hdmi_audio_hook_plugged_cb(struct device *dev, void *data, { struct mtk_hdmi *hdmi = data; + mutex_lock(&hdmi->update_plugged_status_lock); hdmi->plugged_cb = fn; hdmi->codec_dev = codec_dev; + mutex_unlock(&hdmi->update_plugged_status_lock); + mtk_hdmi_update_plugged_status(hdmi); return 0; @@ -1729,6 +1737,7 @@ static int mtk_drm_hdmi_probe(struct platform_device *pdev) return ret; } + mutex_init(&hdmi->update_plugged_status_lock); platform_set_drvdata(pdev, hdmi); ret = mtk_hdmi_output_init(hdmi);