From patchwork Fri Jul 21 08:26:45 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: 13321659 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 4A2BFEB64DC for ; Fri, 21 Jul 2023 08:28:00 +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 3B139EA4; Fri, 21 Jul 2023 10:27:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3B139EA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1689928078; bh=1PmjbTeRGiRPYo8AJ6R/wBAbXmmLjmnNBE0auP1OJ1w=; h=From:To:CC:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=GjVaOQ9Oiupt9M8L4SND/6xOtWyA/rpLGKdDAPWRXrJo8I56ZDIQDq/gEi/ZLt7LS uRxKB+r3EthvBui1QTWnHRX+5Gvj3FxK3dXmjQUUKIE/VoIL/9nJGy3/rcJr3rEMH7 GWw+q6OIxrV9f6J47oRNUyjBCM8U5I2MkoeVxnyU= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 48708F80549; Fri, 21 Jul 2023 10:27:07 +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 9451FF80527; Fri, 21 Jul 2023 10:27:06 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 23BC3F80527; Fri, 21 Jul 2023 10:27:02 +0200 (CEST) Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by alsa1.perex.cz (Postfix) with ESMTP id 1BECAF800D2 for ; Fri, 21 Jul 2023 10:26:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 1BECAF800D2 Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 36L8QhJtA006516, 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 36L8QhJtA006516 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Fri, 21 Jul 2023 16:26:43 +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:26:52 +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:26:51 +0800 From: To: , CC: , , , , , , , Shuming Fan Subject: [PATCH 1/2] ASoC: rt711-sdca: fix key tone missing Date: Fri, 21 Jul 2023 16:26:45 +0800 Message-ID: <20230721082645.114050-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: RTEXH36505.realtek.com.tw (172.21.6.25) 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: JIPXP2S5OKBQ6NMXXSCQXHFUP4GOVCEQ X-Message-ID-Hash: JIPXP2S5OKBQ6NMXXSCQXHFUP4GOVCEQ 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 This patch uses a bit to check whether the system was hibernated or not. It could avoid repeating the recalibration and CBJ detection. Signed-off-by: Shuming Fan --- sound/soc/codecs/rt711-sdca-sdw.c | 1 + sound/soc/codecs/rt711-sdca.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index 119e1f9605d7..cb27b4a98fb6 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -101,6 +101,7 @@ static bool rt711_sdca_mbq_volatile_register(struct device *dev, unsigned int re case 0x2000080: case 0x2000081: case 0x2000083: + case 0x200009f: case 0x5800000: case 0x5800001: case 0x5f00001: diff --git a/sound/soc/codecs/rt711-sdca.c b/sound/soc/codecs/rt711-sdca.c index 07640d2f6e56..f1a93e3ffa1c 100644 --- a/sound/soc/codecs/rt711-sdca.c +++ b/sound/soc/codecs/rt711-sdca.c @@ -488,6 +488,12 @@ static void rt711_sdca_jack_init(struct rt711_sdca_priv *rt711) /* set SCP_SDCA_IntMask2[0]=1 */ sdw_write_no_pm(rt711->slave, SDW_SCP_SDCA_INTMASK2, SDW_SCP_SDCA_INTMASK_SDCA_8); dev_dbg(&rt711->slave->dev, "in %s enable\n", __func__); + + /* trigger GE interrupt */ + rt711_sdca_index_update_bits(rt711, RT711_VENDOR_HDA_CTL, + RT711_GE_MODE_RELATED_CTL, 0x0080, 0x0080); + rt711_sdca_index_update_bits(rt711, RT711_VENDOR_HDA_CTL, + RT711_GE_MODE_RELATED_CTL, 0x0080, 0x0000); } else { /* disable HID 1/2 event */ rt711_sdca_index_update_bits(rt711, RT711_VENDOR_HDA_CTL, @@ -1493,7 +1499,7 @@ int rt711_sdca_io_init(struct device *dev, struct sdw_slave *slave) { struct rt711_sdca_priv *rt711 = dev_get_drvdata(dev); int ret = 0; - unsigned int val; + unsigned int val, hibernation_flag; rt711->disable_irq = false; @@ -1525,6 +1531,11 @@ int rt711_sdca_io_init(struct device *dev, struct sdw_slave *slave) pm_runtime_get_noresume(&slave->dev); + rt711_sdca_index_read(rt711, RT711_VENDOR_REG, 0x9f, &val); + hibernation_flag = (val >> 8); + if (hibernation_flag) + goto _preset_ready_; + rt711_sdca_reset(rt711); rt711_sdca_index_read(rt711, RT711_VENDOR_REG, RT711_JD_PRODUCT_NUM, &val); @@ -1559,6 +1570,10 @@ int rt711_sdca_io_init(struct device *dev, struct sdw_slave *slave) if (rt711->hs_jack) rt711_sdca_jack_init(rt711); + if (!hibernation_flag) + rt711_sdca_index_update_bits(rt711, RT711_VENDOR_REG, 0x9f, 0x0100, 0x0100); + +_preset_ready_: if (rt711->first_hw_init) { regcache_cache_bypass(rt711->regmap, false); regcache_mark_dirty(rt711->regmap); 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__ */