From patchwork Wed May 8 10:58:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 795516 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 A95DCC04FFE for ; Wed, 8 May 2024 12:54: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 AD26982C; Wed, 8 May 2024 14:54:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AD26982C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1715172850; bh=x4CRj3HPQjjxV02Uhbn39jzTSMCqAM5BsNr5zZc40mM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=rd49nOaFwpeDloS9i6+LbFKRZTWNcxiP37qO0ezBVDISXsXdWvkCt1p9dFpP8vNhb AhAojqNNCt4jDnu3R+KJAngJcu3tXIyP9lbOoy1xJxpajCSLbVddhqBYELGj64c4sJ hdNNh9duGKbLPuyvL7BNY62twO895OiAnm7k7/BU= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3FEC2F806BC; Wed, 8 May 2024 14:51:54 +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 832DFF806D1; Wed, 8 May 2024 14:51:54 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 80F08F80564; Wed, 8 May 2024 13:01:41 +0200 (CEST) Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (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 4E587F80423 for ; Wed, 8 May 2024 13:01:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4E587F80423 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=HtRCNnOJ Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a59cc765c29so783224466b.3 for ; Wed, 08 May 2024 04:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715166080; x=1715770880; darn=alsa-project.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=bT4moxnFWMX+ROOOxuh3w595mSjqjEQ1yI4SN/pV6pw=; b=HtRCNnOJsWYUHtXXGYmvCNH1vIBIzhpCXmWv2L6J6WdYXsMzXLxVBTesotGhS2X6rd XTZpCdKUngsU5X+xZjGtOi9B3kDKRYP4qB6Zg8FPUSZHeMBw2AdweWJyeLf8dGYFVKjW TXS23aSgOAaLGgh3otWT9aoYdXPG+RZiWtAlOZsmWBk4tZ9NRMk/IE9rp4EhU9vPzgLI sW3XLMrx88UU8VPJNF1PVnVSdB5gLwRK8JeXT33UVwBvv4UVSdw3dE4vLtJ5ZkSZ4ah8 nsHN5v4sL/97ud3y8x8F82Sc8IBWV8HSpHxxL5y8gK6Fp2caJspMtL9vhRTGFw/4u5iZ 3qIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715166080; x=1715770880; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bT4moxnFWMX+ROOOxuh3w595mSjqjEQ1yI4SN/pV6pw=; b=Efuvg5vlml2toxGLwS4DJ/8gufH5vIo8/3nV1h6TxmOqhBadExd9bOTGyV2mnO8LlE /cPrtIm+OyVnb6T3cUMOfw+UFJ+ccyMEwczqc5dv0duTQihrZbmZ6IpKegpdKvn+eV1i ilsqbeKNO0Fjx8nHgDFyVyIG8UlkoPbfmQtRKZ96/itYPX86M25OWs4lM6OgnRgqcL+0 LQTxB1jskcXMrOZ/lhWlFidJ+/9jGwD+W/PrGxIymfkmt9HoDTGS4QibrBcrbH2Amewq iVq/RY/pvzMpSCpKGeTLO22LdgzNaLi8Fsp+Twk0EgxBaNhRODABMfHLvHz6CZG1k0ON 3Dtw== X-Forwarded-Encrypted: i=1; AJvYcCWZpEMMUqnZZDghoz88EsjqfTaX9udQ7AlCJFM+RATAt9TGKE7kKYZsnmUjyk0EfxCsVNbHz1Qdizuv989dsmpsEyaJHheBut/naJM= X-Gm-Message-State: AOJu0Yx6o04skquxawWNGmeVLYJWG2ICJr4ImPWegBU7mpQroU5ULtaj 0h+i6XKObNZi2Qm8u/KZsMvCLc16k/EdOoergcfxpoOVAU1fqCs/ X-Google-Smtp-Source: AGHT+IGyZZH2dVq+LOe0zaf4rz7kDLtf4v4iLQC8umEfCOPDmCDuJtUXH0SpHIqe1/sL73DxJ3vqeQ== X-Received: by 2002:a50:ab49:0:b0:570:1ea8:c50a with SMTP id 4fb4d7f45d1cf-5731d9cd410mr1935750a12.6.1715166080555; Wed, 08 May 2024 04:01:20 -0700 (PDT) Received: from hex.my.domain (83.8.126.253.ipv4.supernova.orange.pl. [83.8.126.253]) by smtp.gmail.com with ESMTPSA id m6-20020a056402510600b005726b58a436sm7455793edd.30.2024.05.08.04.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:01:20 -0700 (PDT) From: Artur Weber Date: Wed, 08 May 2024 12:58:50 +0200 Subject: [PATCH v2 2/7] ASoC: dt-bindings: samsung,midas-audio: Add GPIO-based headset jack detection MIME-Version: 1.0 Message-Id: <20240508-midas-wm1811-gpio-jack-v2-2-b4d36cd02c6e@gmail.com> References: <20240508-midas-wm1811-gpio-jack-v2-0-b4d36cd02c6e@gmail.com> In-Reply-To: <20240508-midas-wm1811-gpio-jack-v2-0-b4d36cd02c6e@gmail.com> To: Sylwester Nawrocki , Krzysztof Kozlowski Cc: Liam Girdwood , Mark Brown , Rob Herring , Conor Dooley , Jaroslav Kysela , Takashi Iwai , Alim Akhtar , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Artur Weber X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715166076; l=2135; i=aweber.kernel@gmail.com; s=20231030; h=from:subject:message-id; bh=x4CRj3HPQjjxV02Uhbn39jzTSMCqAM5BsNr5zZc40mM=; b=zsZQ0yeh7zg0Ep6m1GYQPRjfMq2PTI5dByvyZhsHCpPeLOEvFLhyar0/PfAzi8k6j4w1bXraj /eDPEpjzkwMAq1iMHceo6NnRRQvuVdZXpOxSY/0HEXQIzSIoLMG5QuW X-Developer-Key: i=aweber.kernel@gmail.com; a=ed25519; pk=RhDBfWbJEHqDibXbhNEBAnc9FMkyznGxX/hwfhL8bv8= X-MailFrom: aweber.kernel@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: SYHDIV5N446GUK7NGB3NCL6ULQNIRQ5L X-Message-ID-Hash: SYHDIV5N446GUK7NGB3NCL6ULQNIRQ5L X-Mailman-Approved-At: Wed, 08 May 2024 12:51:30 +0000 X-Mailman-Version: 3.3.9 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: Some Samsung devices that share the midas-audio driver use a GPIO-based approach to headset jack detection, as opposed to using the built-in jack detection provided by the wm8994 driver. This setup uses two GPIOs (one for jack detection and another for key detection) and an ADC channel for determining the jack type or button pressed. Add DT configuration values that allow for describing these setups. Signed-off-by: Artur Weber --- Changes in v2: - Added vendor prefix to threshold properties - Dropped pipe (|) character from description: field --- .../bindings/sound/samsung,midas-audio.yaml | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/samsung,midas-audio.yaml b/Documentation/devicetree/bindings/sound/samsung,midas-audio.yaml index 6ed53dd0bb53..6b760a73e8bf 100644 --- a/Documentation/devicetree/bindings/sound/samsung,midas-audio.yaml +++ b/Documentation/devicetree/bindings/sound/samsung,midas-audio.yaml @@ -64,6 +64,36 @@ properties: maxItems: 1 description: GPIO pin for line out selection + headset-detect-gpios: + maxItems: 1 + description: GPIO for detection of headset insertion + + headset-key-gpios: + maxItems: 1 + description: GPIO for detection of headset key press + + io-channels: + maxItems: 1 + description: IO channel to read micbias voltage for headset detection + + io-channel-names: + const: headset-detect + + samsung,headset-4pole-threshold-microvolt: + minItems: 2 + maxItems: 2 + description: + Array containing minimum and maximum IO channel value for 4-pole + (with microphone/button) headsets. If the IO channel value is + outside of this range, a 3-pole headset is assumed. + + samsung,headset-button-threshold-microvolt: + minItems: 3 + maxItems: 3 + description: + Array of minimum (inclusive) IO channel values for headset button + detection, in order: "Media", "Volume Up" and "Volume Down". + required: - compatible - cpu From patchwork Wed May 8 10:58:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 795515 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 9A032C04FFE for ; Wed, 8 May 2024 12:54:40 +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 C445E7F8; Wed, 8 May 2024 14:54:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C445E7F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1715172878; bh=tvVeHRzJ1CkifWQbFGlvF0EVZIoz7vxKkkPUGFuk7jM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=uUHSjZIeze4wTkXh1Giuvyp7mg3pnAGXajOVakxRehZ/xQV/JxcUPbtccsCy8qlO+ 5elApb7M/tRhsLwi5eyWDuuGCvdCZm+cKV+RHg+RyC5occrkqUEHfSKSJLMfeEdb0P nYTUP20GwRjDalrrPfXug5bvdJBwBxfN2lTaM3yM= Received: by alsa1.perex.cz (Postfix, from userid 50401) id B29F8F8072A; Wed, 8 May 2024 14:52:00 +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 998EDF80718; Wed, 8 May 2024 14:51:59 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 75590F80570; Wed, 8 May 2024 13:01:52 +0200 (CEST) Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (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 A3F93F804F2 for ; Wed, 8 May 2024 13:01:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A3F93F804F2 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TsZED3Um Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a59ae3efbb3so438300166b.1 for ; Wed, 08 May 2024 04:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715166083; x=1715770883; darn=alsa-project.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=poVyIDrS2b/ZXWDdTK9RH0R8g9cefahYbIBUWzC1UWE=; b=TsZED3UmylVpAeAm29lVSibPKDPOi/ShtY5TxoXiXMOPVamnMCfNVkp2zt7/EzH4y/ cTI3n6w2f7n480s64ghWCAOXTB385nNXYPsd/BuMsKn77W14fWMcuahJKWkrXpYntBqJ jLBiaqt/4ogcay50jMiwbaG3lZADlG94k5USBjO8U4Q7PjrX+84YkEsfFf0cOjZAKSE0 x9GwDsYRAnQipDgCqh6yMeGxkAZV46Mx1lYcz/oqjwjUIJ6mwU+WFSAQRNEpmnLoWljs WakF2u9s08nKgPGK7P5gWNY0Vq7YaFx7DFTagqPBq1mJ08JocBROYok7i1uASS8SCPMm 1Usw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715166083; x=1715770883; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=poVyIDrS2b/ZXWDdTK9RH0R8g9cefahYbIBUWzC1UWE=; b=BfsOxeVpNnQZJRLq7VmdKYkDOi+dnf1b/IvyNiLCSqM9z8YEvLWjvgeL0xXl6LrQY8 lY67vohcETMM+SMZmliGgsAsJLZyW2Hst0xC1LGX3cxnXFUxpuh7HBlv2ftLOF+NiFzj GSEH9m78onrgF02DIiLVz7gbPPw2+bysYaHAT7vS3ASHFDNGQLjkvzv+HqYvGAT6epSp uRdjnh2NQNtKx44kWIlfXsK+Zi319JgivSAHbPixo/gxTUcbUrzO7e7NNN8EFbGcooUO YbPzbn1/fSRixgRKLjj8e/zXs/JmzQQNYCeILmKo2ceYHKiVyh/ZEqw0RBBDzHhVVXqT H2mA== X-Forwarded-Encrypted: i=1; AJvYcCW5PbT85wdpVZ/EMqfvG5OqAuDqX6b3cVdmbngzu6j/bg2LHiSZZ7uAXf6sZ714/YgWl6jI+hrQh72QTGf/VO/9RBVLRKLy1099sCE= X-Gm-Message-State: AOJu0YwzAp7EGM3eTVqSFh8oaeLRR/EJjqRUG/ErMM7q6sS77KH88Zg1 71hgVFrYL2Iym9g/OvoVZAfCHb+GFmstXQwTffaQscoiFPqWvhEq X-Google-Smtp-Source: AGHT+IErlStSHhT96t/fwnFEZHJuSLP/+wFJhG8ZdY2sMgKbw/O8rSpOa93NRwjSXZruRQb51QZNkA== X-Received: by 2002:a50:baa4:0:b0:572:325a:8515 with SMTP id 4fb4d7f45d1cf-5731da69864mr2264617a12.36.1715166083131; Wed, 08 May 2024 04:01:23 -0700 (PDT) Received: from hex.my.domain (83.8.126.253.ipv4.supernova.orange.pl. [83.8.126.253]) by smtp.gmail.com with ESMTPSA id m6-20020a056402510600b005726b58a436sm7455793edd.30.2024.05.08.04.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:01:22 -0700 (PDT) From: Artur Weber Date: Wed, 08 May 2024 12:58:52 +0200 Subject: [PATCH v2 4/7] ASoC: samsung: midas_wm1811: Add GPIO-based headset jack detection MIME-Version: 1.0 Message-Id: <20240508-midas-wm1811-gpio-jack-v2-4-b4d36cd02c6e@gmail.com> References: <20240508-midas-wm1811-gpio-jack-v2-0-b4d36cd02c6e@gmail.com> In-Reply-To: <20240508-midas-wm1811-gpio-jack-v2-0-b4d36cd02c6e@gmail.com> To: Sylwester Nawrocki , Krzysztof Kozlowski Cc: Liam Girdwood , Mark Brown , Rob Herring , Conor Dooley , Jaroslav Kysela , Takashi Iwai , Alim Akhtar , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Artur Weber X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715166076; l=12054; i=aweber.kernel@gmail.com; s=20231030; h=from:subject:message-id; bh=tvVeHRzJ1CkifWQbFGlvF0EVZIoz7vxKkkPUGFuk7jM=; b=V677zzpo8A7us92yAktmq5gJ+zyaHEVr7Zft2eFcqj3mrO1MOtjS/95kPwIwYR4ypCfWpwUHC uhHCuobK+CsC+PXlwA4nqSae+/5+hzhAktw2rS+3V+8q2YEHSuPSw5P X-Developer-Key: i=aweber.kernel@gmail.com; a=ed25519; pk=RhDBfWbJEHqDibXbhNEBAnc9FMkyznGxX/hwfhL8bv8= X-MailFrom: aweber.kernel@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: ZVVDP6JIJHQFCT5XC37EX4TMWIKUO4GB X-Message-ID-Hash: ZVVDP6JIJHQFCT5XC37EX4TMWIKUO4GB X-Mailman-Approved-At: Wed, 08 May 2024 12:51:38 +0000 X-Mailman-Version: 3.3.9 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: Some Samsung devices that use the midas_wm1811 driver use a GPIO-based method for detecting whether the headset jack is plugged in, as well as detecting which headset buttons are pressed. There are two GPIOs: a "headset detect" GPIO responsible for detecting jack insertion, and a "headset key" GPIO which triggers when a button on the headset is pressed. The plug type and the button pressed are determined based on information from an ADC channel. The headset mic is enabled by a headset mic bias regulator. Add support for the GPIO-based headset jack detection mechanism, and make it configurable from the device tree. This implementation borrows somewhat from the aries_wm8994.c driver, though there are a few changes to make the code cleaner, and to add support for DT-based configuration. Notably, a dependency on IIO is introduced, to accommodate the ADC reading requirement. Signed-off-by: Artur Weber --- Changes in v2: - Added separate headset mic bias regulator - Added samsung preset to threshold properties - Replaced dev_err+return with return dev_err_probe where needed --- sound/soc/samsung/Kconfig | 2 +- sound/soc/samsung/midas_wm1811.c | 286 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 277 insertions(+), 11 deletions(-) diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig index 93c2b1b08d0a..4b1ea7b2c796 100644 --- a/sound/soc/samsung/Kconfig +++ b/sound/soc/samsung/Kconfig @@ -140,7 +140,7 @@ config SND_SOC_SAMSUNG_ARIES_WM8994 config SND_SOC_SAMSUNG_MIDAS_WM1811 tristate "SoC I2S Audio support for Midas boards" - depends on SND_SOC_SAMSUNG + depends on SND_SOC_SAMSUNG && IIO select SND_SAMSUNG_I2S select SND_SOC_WM8994 help diff --git a/sound/soc/samsung/midas_wm1811.c b/sound/soc/samsung/midas_wm1811.c index ab0a4804b45e..ce94550ee32e 100644 --- a/sound/soc/samsung/midas_wm1811.c +++ b/sound/soc/samsung/midas_wm1811.c @@ -7,7 +7,9 @@ #include #include +#include #include +#include #include #include #include @@ -32,6 +34,9 @@ struct midas_priv { struct regulator *reg_headset_mic_bias; struct gpio_desc *gpio_fm_sel; struct gpio_desc *gpio_lineout_sel; + struct gpio_desc *gpio_headset_detect; + struct gpio_desc *gpio_headset_key; + struct iio_channel *adc_headset_detect; unsigned int fll1_rate; struct snd_soc_jack headset_jack; @@ -48,6 +53,131 @@ static struct snd_soc_jack_pin headset_jack_pins[] = { }, }; +/* + * min_mv/max_mv values in this struct are set up based on DT values. + */ +static struct snd_soc_jack_zone headset_jack_zones[] = { + { .jack_type = SND_JACK_HEADPHONE, }, + { .jack_type = SND_JACK_HEADSET, }, + { .jack_type = SND_JACK_HEADPHONE, }, +}; + +/* + * This is used for manual detection in headset_key_check, we reuse the + * structure since it's convenient. + * + * min_mv/max_mv values in this struct are set up based on DT values. + */ +static struct snd_soc_jack_zone headset_key_zones[] = { + { .jack_type = SND_JACK_BTN_0, }, /* Media */ + { .jack_type = SND_JACK_BTN_1, }, /* Volume Up */ + { .jack_type = SND_JACK_BTN_2, }, /* Volume Down */ +}; + +static int headset_jack_check(void *data) +{ + struct midas_priv *priv = (struct midas_priv *) data; + int adc, jack_type, ret; + int bias_already_on = 0; + + if (!gpiod_get_value_cansleep(priv->gpio_headset_detect)) + return 0; + + if (priv->reg_headset_mic_bias) { + /* + * Get state of Headset Mic switch by checking the headset mic + * bias regulator + */ + bias_already_on = \ + regulator_is_enabled(priv->reg_headset_mic_bias); + + /* + * If it's not enabled yet, temporarily enable headset mic bias + * for ADC measurement + */ + if (bias_already_on < 0) + pr_err("%s: Failed to get headset mic bias state: %d", + __func__, ret); + else if (!bias_already_on) { + ret = regulator_enable(priv->reg_headset_mic_bias); + if (ret) + pr_err("%s: Failed to enable micbias: %d\n", + __func__, ret); + } + } + + /* Sleep for a small amount of time to get the value to stabilize */ + msleep(20); + + ret = iio_read_channel_processed(priv->adc_headset_detect, &adc); + if (ret) { + pr_err("%s: Failed to read ADC (%d), assuming headphones\n", + __func__, ret); + return SND_JACK_HEADPHONE; + } + pr_debug("%s: ADC value is %d\n", __func__, adc); + + jack_type = snd_soc_jack_get_type(&priv->headset_jack, adc); + + /* + * Revert the headset mic bias supply to its previous state + * (i.e. if it was disabled before the check, disable it again) + */ + if (priv->reg_headset_mic_bias && bias_already_on == 0) { + ret = regulator_disable(priv->reg_headset_mic_bias); + if (ret) + pr_err("%s: Failed to disable micbias: %d\n", + __func__, ret); + } + + return jack_type; +} + +static int headset_key_check(void *data) +{ + struct midas_priv *priv = (struct midas_priv *) data; + int adc, i, ret; + + if (!gpiod_get_value_cansleep(priv->gpio_headset_key)) + return 0; + + /* Filter out keypresses when 4 pole jack not detected */ + if (!(priv->headset_jack.status & SND_JACK_MICROPHONE)) + return 0; + + ret = iio_read_channel_processed(priv->adc_headset_detect, &adc); + if (ret) { + pr_err("%s: Failed to read ADC (%d), can't detect key type\n", + __func__, ret); + return 0; + } + pr_debug("%s: ADC value is %d\n", __func__, adc); + + for (i = 0; i < ARRAY_SIZE(headset_key_zones); i++) { + if (adc >= headset_key_zones[i].min_mv && + adc <= headset_key_zones[i].max_mv) { + return headset_key_zones[i].jack_type; + } + } + + return 0; +} + +static struct snd_soc_jack_gpio headset_gpio[] = { + { + .name = "Headset Jack", + .report = SND_JACK_HEADSET, + .debounce_time = 150, + .jack_status_check = headset_jack_check, + }, + { + .name = "Headset Key", + .report = SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2, + .debounce_time = 30, + .jack_status_check = headset_key_check, + }, +}; + static int midas_start_fll1(struct snd_soc_pcm_runtime *rtd, unsigned int rate) { struct snd_soc_card *card = rtd->card; @@ -335,18 +465,67 @@ static int midas_late_probe(struct snd_soc_card *card) return ret; } - ret = snd_soc_card_jack_new_pins(card, "Headset", - SND_JACK_HEADSET | SND_JACK_MECHANICAL | - SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 | - SND_JACK_BTN_3 | SND_JACK_BTN_4 | SND_JACK_BTN_5, - &priv->headset_jack, - headset_jack_pins, - ARRAY_SIZE(headset_jack_pins)); - if (ret) + if (!priv->gpio_headset_detect) { + ret = snd_soc_card_jack_new_pins(card, "Headset", + SND_JACK_HEADSET | SND_JACK_MECHANICAL | + SND_JACK_BTN_0 | SND_JACK_BTN_1 | + SND_JACK_BTN_2 | SND_JACK_BTN_3 | + SND_JACK_BTN_4 | SND_JACK_BTN_5, + &priv->headset_jack, + headset_jack_pins, + ARRAY_SIZE(headset_jack_pins)); + if (ret) + return ret; + + wm8958_mic_detect(aif1_dai->component, &priv->headset_jack, + NULL, NULL, NULL, NULL); + } else { + /* Some devices (n8000, t310) use a GPIO to detect the jack. */ + ret = snd_soc_card_jack_new_pins(card, "Headset", + SND_JACK_HEADSET | SND_JACK_BTN_0 | + SND_JACK_BTN_1 | SND_JACK_BTN_2, + &priv->headset_jack, + headset_jack_pins, + ARRAY_SIZE(headset_jack_pins)); + if (ret) { + dev_err(card->dev, + "Failed to set up headset pins: %d\n", ret); + return ret; + } + + ret = snd_soc_jack_add_zones(&priv->headset_jack, + ARRAY_SIZE(headset_jack_zones), + headset_jack_zones); + if (ret) { + dev_err(card->dev, + "Failed to set up headset zones: %d\n", ret); + return ret; + } + + headset_gpio[0].data = priv; + headset_gpio[0].desc = priv->gpio_headset_detect; + + headset_gpio[1].data = priv; + headset_gpio[1].desc = priv->gpio_headset_key; + + snd_jack_set_key(priv->headset_jack.jack, + SND_JACK_BTN_0, KEY_MEDIA); + snd_jack_set_key(priv->headset_jack.jack, + SND_JACK_BTN_1, KEY_VOLUMEUP); + snd_jack_set_key(priv->headset_jack.jack, + SND_JACK_BTN_2, KEY_VOLUMEDOWN); + + ret = snd_soc_jack_add_gpios(&priv->headset_jack, + ARRAY_SIZE(headset_gpio), + headset_gpio); + if (ret) + dev_err(card->dev, + "Failed to set up headset jack GPIOs: %d\n", + ret); + return ret; + } - wm8958_mic_detect(aif1_dai->component, &priv->headset_jack, - NULL, NULL, NULL, NULL); return 0; } @@ -453,6 +632,9 @@ static int midas_probe(struct platform_device *pdev) struct snd_soc_card *card = &midas_card; struct device *dev = &pdev->dev; static struct snd_soc_dai_link *dai_link; + enum iio_chan_type channel_type; + u32 fourpole_threshold[2]; + u32 button_threshold[3]; struct midas_priv *priv; int ret, i; @@ -499,6 +681,90 @@ static int midas_probe(struct platform_device *pdev) return PTR_ERR(priv->gpio_lineout_sel); } + priv->gpio_headset_detect = devm_gpiod_get_optional(dev, + "headset-detect", GPIOD_IN); + if (IS_ERR(priv->gpio_headset_detect)) + return dev_err_probe(dev, PTR_ERR(priv->gpio_headset_detect), + "Failed to get headset jack detect GPIO\n"); + + if (priv->gpio_headset_detect) { + priv->adc_headset_detect = devm_iio_channel_get(dev, + "headset-detect"); + if (IS_ERR(priv->adc_headset_detect)) + return dev_err_probe(dev, + PTR_ERR(priv->adc_headset_detect), + "Failed to get ADC channel\n"); + + ret = iio_get_channel_type(priv->adc_headset_detect, + &channel_type); + if (ret) { + dev_err(dev, "Failed to get ADC channel type\n"); + return ret; + } + + if (channel_type != IIO_VOLTAGE) { + dev_err(dev, "ADC channel is not voltage\n"); + return ret; + } + + priv->gpio_headset_key = devm_gpiod_get(dev, "headset-key", + GPIOD_IN); + if (IS_ERR(priv->gpio_headset_key)) + return dev_err_probe(dev, + PTR_ERR(priv->gpio_headset_key), + "Failed to get headset key GPIO\n"); + + ret = of_property_read_u32_array(dev->of_node, + "samsung,headset-4pole-threshold-microvolt", + fourpole_threshold, + ARRAY_SIZE(fourpole_threshold)); + if (ret) { + dev_err(dev, "Failed to get 4-pole jack detection threshold\n"); + return ret; + } + + if (fourpole_threshold[0] > fourpole_threshold[1]) { + dev_err(dev, "Invalid 4-pole jack detection threshold value\n"); + return -EINVAL; + } + + headset_jack_zones[0].max_mv = (fourpole_threshold[0]); + headset_jack_zones[1].min_mv = (fourpole_threshold[0] + 1); + + headset_jack_zones[1].max_mv = (fourpole_threshold[1]); + headset_jack_zones[2].min_mv = (fourpole_threshold[1] + 1); + + ret = of_property_read_u32_array(dev->of_node, + "samsung,headset-button-threshold-microvolt", + button_threshold, + ARRAY_SIZE(button_threshold)); + if (ret) { + dev_err(dev, "Failed to get headset button detection threshold\n"); + return ret; + } + + if (button_threshold[0] > button_threshold[1] || + button_threshold[1] > button_threshold[2]) { + dev_err(dev, "Invalid headset button detection threshold value\n"); + return -EINVAL; + } + + for (i = 0; i < 3; i++) { + if (i != 0 && button_threshold[i] <= 0) { + dev_err(dev, "Invalid headset button detection threshold value\n"); + return -EINVAL; + } + + headset_key_zones[i].min_mv = button_threshold[i]; + + if (i == 2) + headset_key_zones[i].max_mv = UINT_MAX; + else + headset_key_zones[i].max_mv = \ + (button_threshold[i+1] - 1); + } + } + ret = snd_soc_of_parse_card_name(card, "model"); if (ret < 0) { dev_err(dev, "Card name is not specified\n"); From patchwork Wed May 8 10:58:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 795514 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 8EB2EC19F4F for ; Wed, 8 May 2024 12:55:17 +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 4CB1093A; Wed, 8 May 2024 14:55:05 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4CB1093A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1715172915; bh=7ghoUuP1F66lo5lQILjtg4IgiT6Z0TAcd0jCIemjWlQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=BMSkFKhZBevuy6XXbDVbj6itZZ2EfkxwUGBBOG0P11O06uohbPp41fZDOT3BJyf0X 9/JcRNooorXMZS3PrI/RFde0ZsEcFyJI6jrb/5AcJJUu8JApP+GcPD8WKlt/5RLQDN gZ/FC82f5QU3PTZRXdT0svno3rvJl13BtSf0VDcQ= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7B409F8079B; Wed, 8 May 2024 14:52: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 ABA27F807D0; Wed, 8 May 2024 14:52:06 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1C7AAF80423; Wed, 8 May 2024 13:03:17 +0200 (CEST) Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) (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 95243F804FB for ; Wed, 8 May 2024 13:01:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 95243F804FB Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=eJqprRwl Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-51fc01b6fe7so3849323e87.0 for ; Wed, 08 May 2024 04:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715166086; x=1715770886; darn=alsa-project.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JckYzcWe8w+0grZPS9NysF8GgHh7PfoFNUhYz6cHvfw=; b=eJqprRwlFx0vvQ8ryXhIDXJuAOgiMfyBGxAkAyIaCMRRN3/m8ejZ/TwugPjlDN1eMH 2fYIoBojMY3SC7XY5NLtEBQ3vdrLRvMXJc+AL+jgKn+AVK1HOmNy/VfV/wa2n5tboXUX gmv1sR20pH0X2cCtEpr/b+9tao+alQ8hokT0RYnXwmzzBrvZLFRcvucKuB2l0V/VAlOJ Qhs3nFTMBH+vHFVtK2kcGGDSrGs+QN0qaHndfhjr2fV0ZkbGojs7hcjRQBDkZ/bEYEYf BIx0oyVJGKWk3Dv6nlTLw2bnMo2Ggye/1uVSqyjO89Iot8dsHh35KsmruuMy5tUBU5jP Btow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715166086; x=1715770886; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JckYzcWe8w+0grZPS9NysF8GgHh7PfoFNUhYz6cHvfw=; b=UPNups3jorCMSbVn7diSaO8X6q257VZydSVkmnG0pXt+7X46jRNE2eqt7y49Rx84pK Teiu+F83k+MpvUHrfbprS7yU2bNWFkfHChrCHiPsFnIUZlsoIwd1LDNBRCK0PL+jvA/U /qApzeVwNDFJOXzlBSMWUxdFm7l5SxT4dtTlCj5m/MAaYOkO7kJGhRReslvYf0xJzoT/ MhXm2aW9yon3dr28xXJKyMpRi9HJt3ywDCYoci4V5+FOlUu08X7WUWzB1Tm1+z49sZvj ZDZ5IwUa5pKKsInqIxq312KIeMNc9cSaZUss9sulirGhDEP15hKb3pq34H/RNSrh/0xC /w+g== X-Forwarded-Encrypted: i=1; AJvYcCVgK3X61ipribOudF4SXaac8Q4VF0Ho02/DjKligDLxAjkkVNyj70sQWy7osYpw8Ye04JWNm5JVtpf6Ybng9D/ay9BfSNFo5POVcKI= X-Gm-Message-State: AOJu0YzycsB3Xaa8lXqg3TAHFfY+kfKItnawcwuPG1cfyz/wF05At6iM 6KdnZVV3WfJ70av/Y6xIVymyEAl0bjEiWJjD+wsBCv0067eLUlAk X-Google-Smtp-Source: AGHT+IGeO76uQCED1J00VN9QCAey1wfpGDo3fQs8/bwbKEbtAP/7na2lzT5MZkH/YfwFEC18bO8Zag== X-Received: by 2002:a05:6512:40e:b0:518:9362:f63 with SMTP id 2adb3069b0e04-5217b5a6837mr1384384e87.0.1715166085711; Wed, 08 May 2024 04:01:25 -0700 (PDT) Received: from hex.my.domain (83.8.126.253.ipv4.supernova.orange.pl. [83.8.126.253]) by smtp.gmail.com with ESMTPSA id m6-20020a056402510600b005726b58a436sm7455793edd.30.2024.05.08.04.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:01:25 -0700 (PDT) From: Artur Weber Date: Wed, 08 May 2024 12:58:54 +0200 Subject: [PATCH v2 6/7] ARM: dts: samsung: exynos4212-tab3: Fix headset mic, add jack detection MIME-Version: 1.0 Message-Id: <20240508-midas-wm1811-gpio-jack-v2-6-b4d36cd02c6e@gmail.com> References: <20240508-midas-wm1811-gpio-jack-v2-0-b4d36cd02c6e@gmail.com> In-Reply-To: <20240508-midas-wm1811-gpio-jack-v2-0-b4d36cd02c6e@gmail.com> To: Sylwester Nawrocki , Krzysztof Kozlowski Cc: Liam Girdwood , Mark Brown , Rob Herring , Conor Dooley , Jaroslav Kysela , Takashi Iwai , Alim Akhtar , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Artur Weber X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715166076; l=1934; i=aweber.kernel@gmail.com; s=20231030; h=from:subject:message-id; bh=7ghoUuP1F66lo5lQILjtg4IgiT6Z0TAcd0jCIemjWlQ=; b=l0DFXbMoynUW/3tl/JJn+d4FFNg8IhQpMsG9UJeOU2kGTDNLpMYNTOAalpniOTbooBzyKlSiZ P9EqRrOaA4YA0I/fq2SM0f9GJDPc5NwRz+qYyqlEMUZfFI//F0HjlH5 X-Developer-Key: i=aweber.kernel@gmail.com; a=ed25519; pk=RhDBfWbJEHqDibXbhNEBAnc9FMkyznGxX/hwfhL8bv8= X-MailFrom: aweber.kernel@gmail.com X-Mailman-Rule-Hits: nonmember-moderation 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 Message-ID-Hash: 753OCVVCKNV4V3CESJVB4IJSLOQPKJMV X-Message-ID-Hash: 753OCVVCKNV4V3CESJVB4IJSLOQPKJMV X-Mailman-Approved-At: Wed, 08 May 2024 12:51:39 +0000 X-Mailman-Version: 3.3.9 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: Set up headset mic bias regulator and add the necessary properties to the samsung,midas-audio node to allow for headset jack detection. Signed-off-by: Artur Weber --- Changes in v2: - Added headset mic bias regulator - Added samsung prefix to threshold properties - Dropped wm1811 config changes --- arch/arm/boot/dts/samsung/exynos4212-tab3.dtsi | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm/boot/dts/samsung/exynos4212-tab3.dtsi b/arch/arm/boot/dts/samsung/exynos4212-tab3.dtsi index e5254e32aa8f..8dc81112172c 100644 --- a/arch/arm/boot/dts/samsung/exynos4212-tab3.dtsi +++ b/arch/arm/boot/dts/samsung/exynos4212-tab3.dtsi @@ -294,11 +294,30 @@ submic_bias_reg: voltage-regulator-5 { regulator-max-microvolt = <2800000>; }; + earmic_bias_reg: voltage-regulator-6 { + compatible = "regulator-fixed"; + regulator-name = "EAR_MICBIAS_LDO_2.8V"; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <2800000>; + gpio = <&gpm0 0 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; + sound: sound { compatible = "samsung,midas-audio"; model = "TAB3"; mic-bias-supply = <&mic_bias_reg>; submic-bias-supply = <&submic_bias_reg>; + headset-mic-bias-supply = <&earmic_bias_reg>; + + lineout-sel-gpios = <&gpj1 2 GPIO_ACTIVE_HIGH>; + + headset-detect-gpios = <&gpx0 4 GPIO_ACTIVE_LOW>; + headset-key-gpios = <&gpx3 6 GPIO_ACTIVE_LOW>; + samsung,headset-4pole-threshold-microvolt = <710 2000>; + samsung,headset-button-threshold-microvolt = <0 130 260>; + io-channel-names = "headset-detect"; + io-channels = <&adc 0>; audio-routing = "HP", "HPOUT1L", "HP", "HPOUT1R", @@ -345,6 +364,11 @@ wlan_pwrseq: sdhci3-pwrseq { }; }; +&adc { + vdd-supply = <&ldo3_reg>; + status = "okay"; +}; + &bus_acp { devfreq = <&bus_dmc>; status = "okay";