From patchwork Fri Jul 21 08:27:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?U2h1bWluZyBb6IyD5pu46YqYXQ==?= X-Patchwork-Id: 13321660 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 48EE6EB64DD for ; Fri, 21 Jul 2023 08:28:11 +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 EBDD5EAF; Fri, 21 Jul 2023 10:27:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EBDD5EAF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1689928089; bh=Kz9WBz1KXYep6OcTqAcHbVepccI2jxd2QSMJE0bkg30=; h=From:To:CC:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=JGzyigkhfs5wIS0+e5roHCxUR4bmfMqCBm1x9F+GXyyYuXYb+2X4ImJJRUnvCoMCb 66Ok4IPOk7b+lorvpVsJyLkytcsqcPwkqOy5F8JTQfedc6dZEKMP59JvYJ8z/OKehK /1cUmNScU0fgI/LQojirpw2b+JViIZsfgXyOsuk8= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5495CF80551; Fri, 21 Jul 2023 10:27:18 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id EF587F804DA; Fri, 21 Jul 2023 10:27:17 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 60D35F804DA; Fri, 21 Jul 2023 10:27:14 +0200 (CEST) Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by alsa1.perex.cz (Postfix) with ESMTP id 58698F800D2 for ; Fri, 21 Jul 2023 10:27:10 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 58698F800D2 Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 36L8QuTF2006599, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 36L8QuTF2006599 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Fri, 21 Jul 2023 16:26:56 +0800 Received: from RTEXMBS01.realtek.com.tw (172.21.6.94) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Fri, 21 Jul 2023 16:27:06 +0800 Received: from ubuntu.localdomain (172.22.102.209) by RTEXMBS01.realtek.com.tw (172.21.6.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 21 Jul 2023 16:27:05 +0800 From: To: , CC: , , , , , , , Shuming Fan Subject: [PATCH 2/2] ASoC: rt711-sdca: check pin sense when system resumes Date: Fri, 21 Jul 2023 16:27:00 +0800 Message-ID: <20230721082700.114069-1-shumingf@realtek.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [172.22.102.209] X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS01.realtek.com.tw (172.21.6.94) X-KSE-ServerInfo: RTEXMBS01.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback Message-ID-Hash: 2QBPWRN33NFX4HIFO4X6D2RC25WAW4SY X-Message-ID-Hash: 2QBPWRN33NFX4HIFO4X6D2RC25WAW4SY X-MailFrom: shumingf@realtek.com 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 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: Shuming Fan If the jack is unplugged when the system was suspended, the system will believe the jack exists for a while after the system resumes. The codec needs some time, then alerts the host to detect whether the jack exists or not. This patch wants to use the pin sense to detect whether the jack exists or not when the system resumes. It could report the status immediately if the jack was unplugged. It will improve the user experience. Signed-off-by: Shuming Fan --- sound/soc/codecs/rt711-sdca-sdw.c | 18 ++++++++++++++++++ sound/soc/codecs/rt711-sdca.c | 2 +- sound/soc/codecs/rt711-sdca.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index cb27b4a98fb6..13a5316ba999 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "rt711-sdca.h" #include "rt711-sdca-sdw.h" @@ -435,6 +436,8 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) struct sdw_slave *slave = dev_to_sdw_dev(dev); struct rt711_sdca_priv *rt711 = dev_get_drvdata(dev); unsigned long time; + unsigned int pin_sense; + int ret; if (!rt711->first_hw_init) return 0; @@ -457,6 +460,21 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) regcache_sync(rt711->regmap); regcache_cache_only(rt711->mbq_regmap, false); regcache_sync(rt711->mbq_regmap); + + /* + * detect whether jack exists or not + * if the jack is unplugged, we will report it immediately + * if the jack exists, it will take some time to detect, then alert the host + */ + ret = rt711_sdca_index_read(rt711, RT711_VENDOR_REG, RT711_IRQ_FLAG_TABLE2, &pin_sense); + pin_sense = ((pin_sense & 0x100) >> 8); + if (ret < 0) { + dev_err(&slave->dev, "Pin Sense read failed:%d\n", ret); + return ret; + } + if (rt711->hs_jack && !pin_sense) + snd_soc_jack_report(rt711->hs_jack, 0, SND_JACK_HEADSET); + return 0; } diff --git a/sound/soc/codecs/rt711-sdca.c b/sound/soc/codecs/rt711-sdca.c index f1a93e3ffa1c..29dce5173f90 100644 --- a/sound/soc/codecs/rt711-sdca.c +++ b/sound/soc/codecs/rt711-sdca.c @@ -42,7 +42,7 @@ static int rt711_sdca_index_write(struct rt711_sdca_priv *rt711, return ret; } -static int rt711_sdca_index_read(struct rt711_sdca_priv *rt711, +int rt711_sdca_index_read(struct rt711_sdca_priv *rt711, unsigned int nid, unsigned int reg, unsigned int *value) { int ret; diff --git a/sound/soc/codecs/rt711-sdca.h b/sound/soc/codecs/rt711-sdca.h index 11d421e8ab2b..aeedb38a0260 100644 --- a/sound/soc/codecs/rt711-sdca.h +++ b/sound/soc/codecs/rt711-sdca.h @@ -240,4 +240,6 @@ int rt711_sdca_init(struct device *dev, struct regmap *regmap, struct regmap *mbq_regmap, struct sdw_slave *slave); int rt711_sdca_jack_detect(struct rt711_sdca_priv *rt711, bool *hp, bool *mic); +int rt711_sdca_index_read(struct rt711_sdca_priv *rt711, + unsigned int nid, unsigned int reg, unsigned int *value); #endif /* __RT711_SDCA_H__ */