From patchwork Thu Feb 22 18:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Jirman?= X-Patchwork-Id: 204999 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp141393dyb; Thu, 22 Feb 2024 10:51:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXksVUjiaEYFyAnXRpdl4MygvK68N5GJuvPBvF+czChl++DQDg0cGHjkuEVqHAX7qo5wAy2D0AnMqcXVqOZC753fmFqeg== X-Google-Smtp-Source: AGHT+IET2G9RJEvUjNvBDfGlvV+Q+3OsiTu67djYwyDXP9NGSa6hfgC3PcLekPksgdKlqpWmoKlE X-Received: by 2002:a05:6a21:3489:b0:1a0:d8be:55d3 with SMTP id yo9-20020a056a21348900b001a0d8be55d3mr1961913pzb.16.1708627874433; Thu, 22 Feb 2024 10:51:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708627874; cv=pass; d=google.com; s=arc-20160816; b=K7jvmqKeo787GYcAZQLuZmO7tC5PFFyFGZ1TQpyp17np8PvUSUUIehTkhQ+eo8Q/iT fh2E6HVRjhqYwW+EdLPmNeB1Ewxykk1LqxfOjfbrQ1uDlOYXazhkpzRUSjB16EX6HVv8 2tzFo/a6jE3ozIk8XWfFnnwnSGFBvwQnAXgeP92oJnqz3wrrgUcqstw4LWmlvEaY7zh/ FgFGknymVfRJPvM521fqIyIjxssYSW25jQpGQc4FwvLk27TQYOr1ebMJjInMWOTpaOv+ J8Ryg7hIwbPlk1+LC95uJ1d4eUR7zbvnekAP7uHJnA3YVxX6RIkyF81YOML91bkALiDe 5LSQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JGVtLGJoNrifEQCr1YZ3zkxMW3g5EFoYp9uHA+YPkVo=; fh=QGdVBqYg4q7jIiN9KcNXeuSkybNfaLt8K5LfUlN67/I=; b=l+XeD7TGKIsOkI6pO9Dl4CGDm+Nh1Gi2l4xC8swlCUVYEfHNXEW6b1GoLJG2wW1MoW Y6sGk4txqRQaC4vnG1i6h748HVKfDhngm//Jfm2q9gGuv4BaqKSUJWAUfRv9jSvz0nrR ZQ95eXXoONg2KBqYPGKyl3qX0M2dPo9SLA+3uBjxHsjkV285qf8utTAhLA4nuYeOmEwk g3Yqe5uUgMXTQarJNw4Q+a67Ar8+kxPUMYyWtb6Qxjpgu+jyu6RBSKHlZYmUk4nMakw1 vTvlKgmLsWBkfa2ALIbpbokrdhdzfutr/qChip23SEJuXTpCI8BBhFRsGFYuuw07rAMD YC6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b="psPTDIu/"; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-77122-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77122-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b8-20020a056a000cc800b006e4c0eb955bsi2848344pfv.168.2024.02.22.10.51.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:51:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77122-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b="psPTDIu/"; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-77122-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77122-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 32C62B261DD for ; Thu, 22 Feb 2024 18:34:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99D4A15DBA9; Thu, 22 Feb 2024 18:19:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b="psPTDIu/" Received: from vps.xff.cz (vps.xff.cz [195.181.215.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8507F15CD4C; Thu, 22 Feb 2024 18:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.181.215.36 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625939; cv=none; b=qhC02mKSCsbB7ZKpXDxBCWpBZhBYUK7iryLfjwtGoIbOdZBNcsI3kPgsiw4JTsHyAcpyEbsT+k0L5953zV0TPk9pIy0xPW+u8/+8QGt/AEhHiRGxOb8imWcAhkXtiWdqYBxxi2+98lqLWRt8Mm5ldrnvqs0l/ipULI5O/SgTd7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625939; c=relaxed/simple; bh=0xAlq3FKxyKOFVzLVHdJfOKR9ZGZX8El43JyE9dp5i8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jYn44iveC69v6U0n5s4srt1dNcwxFmlSZOP1tOqcWIqAf9CMrcfYeeyVLi682Dyd5KwFQbe61h7DG+CNdiHDfPbSrlsSCeLE5TMuzh/kYaI+gDdGTW6cnxt7kneqVJBPDeTe9pMdR9mst6XTBU2UVf3BSl7uhYvX7KjGH0IqLSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz; spf=pass smtp.mailfrom=xff.cz; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b=psPTDIu/; arc=none smtp.client-ip=195.181.215.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xff.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xff.cz; s=mail; t=1708625934; bh=0xAlq3FKxyKOFVzLVHdJfOKR9ZGZX8El43JyE9dp5i8=; h=From:To:Cc:Subject:Date:References:From; b=psPTDIu/ElVGuGT/SH5gHUemooCcfaafxJ5DKSHWm5j36mhLy6PGAgnbTW9LbJsmJ 7P7SnwrFWG6Xu6m0uq0vqFGUu/kqndVN9HVGlDpp0omgKN1avsYvoNVGQhxKn2xo4T nnCeBqBiGQLcF+7OZdJ/PobIc1RkmZpFHSaF7SMQ= From: =?utf-8?q?Ond=C5=99ej_Jirman?= To: linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Samuel Holland , Chen-Yu Tsai , Jernej Skrabec , Ondrej Jirman , Arnaud Ferraris , linux-sound@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 1/4] ASoC: sun50i-codec-analog: Move suspend/resume to set_bias_level Date: Thu, 22 Feb 2024 19:18:44 +0100 Message-ID: <20240222181851.3398254-2-megi@xff.cz> In-Reply-To: <20240222181851.3398254-1-megi@xff.cz> References: <20240222181851.3398254-1-megi@xff.cz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791626182023414366 X-GMAIL-MSGID: 1791626182023414366 From: Samuel Holland With idle_bias_on and suspend_bias_off, there are bias level transitions that match the suspend/resume callbacks. However, there are also transitions during probe (OFF => STANDBY) and removal (STANDBY => OFF). By using the set_bias_level hook, the driver can have one copy of code that would otherwise be duplicated between the probe/resume and suspend/remove hooks. Signed-off-by: Samuel Holland Signed-off-by: Ondřej Jirman --- sound/soc/sunxi/sun50i-codec-analog.c | 29 +++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/sound/soc/sunxi/sun50i-codec-analog.c b/sound/soc/sunxi/sun50i-codec-analog.c index 8a32d05e23e1..cedd4de42d1a 100644 --- a/sound/soc/sunxi/sun50i-codec-analog.c +++ b/sound/soc/sunxi/sun50i-codec-analog.c @@ -471,17 +471,23 @@ static const struct snd_soc_dapm_route sun50i_a64_codec_routes[] = { { "EARPIECE", NULL, "Earpiece Amp" }, }; -static int sun50i_a64_codec_suspend(struct snd_soc_component *component) +static int sun50i_a64_codec_set_bias_level(struct snd_soc_component *component, + enum snd_soc_bias_level level) { - return regmap_update_bits(component->regmap, SUN50I_ADDA_HP_CTRL, - BIT(SUN50I_ADDA_HP_CTRL_PA_CLK_GATE), - BIT(SUN50I_ADDA_HP_CTRL_PA_CLK_GATE)); -} + switch (level) { + case SND_SOC_BIAS_OFF: + regmap_set_bits(component->regmap, SUN50I_ADDA_HP_CTRL, + BIT(SUN50I_ADDA_HP_CTRL_PA_CLK_GATE)); + break; + case SND_SOC_BIAS_STANDBY: + regmap_clear_bits(component->regmap, SUN50I_ADDA_HP_CTRL, + BIT(SUN50I_ADDA_HP_CTRL_PA_CLK_GATE)); + break; + default: + break; + } -static int sun50i_a64_codec_resume(struct snd_soc_component *component) -{ - return regmap_update_bits(component->regmap, SUN50I_ADDA_HP_CTRL, - BIT(SUN50I_ADDA_HP_CTRL_PA_CLK_GATE), 0); + return 0; } static const struct snd_soc_component_driver sun50i_codec_analog_cmpnt_drv = { @@ -491,8 +497,9 @@ static const struct snd_soc_component_driver sun50i_codec_analog_cmpnt_drv = { .num_dapm_widgets = ARRAY_SIZE(sun50i_a64_codec_widgets), .dapm_routes = sun50i_a64_codec_routes, .num_dapm_routes = ARRAY_SIZE(sun50i_a64_codec_routes), - .suspend = sun50i_a64_codec_suspend, - .resume = sun50i_a64_codec_resume, + .set_bias_level = sun50i_a64_codec_set_bias_level, + .idle_bias_on = true, + .suspend_bias_off = true, }; static const struct of_device_id sun50i_codec_analog_of_match[] = { From patchwork Thu Feb 22 18:18:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Jirman?= X-Patchwork-Id: 204987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp132753dyb; Thu, 22 Feb 2024 10:34:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUhlfMSWjceoEqHIccLlieqf5k1zQLk3o4V5MjO4ns0NPMyDWNf5TMEJGzRh6AtBLXwVDcAKtsVk7lRpT4hW3ndasUMUQ== X-Google-Smtp-Source: AGHT+IFSnT0q3hEaGONxnzqVJcenOExbP5BYowjYKM0LtnBr+Pr1786nqlQzEhZi2pjG0FkS2dEC X-Received: by 2002:a9d:4e97:0:b0:6e2:dd8e:f38d with SMTP id v23-20020a9d4e97000000b006e2dd8ef38dmr23271767otk.4.1708626860786; Thu, 22 Feb 2024 10:34:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626860; cv=pass; d=google.com; s=arc-20160816; b=rLyq8T4zNs2fN2eeoGwGX9yA3CPtq/OInIpXAAfWCa9cygQ2RLEiGjWA8ifvKeg9nU A/QzXZ7QEE5AvedHMhfAT55XuhYKw+RRkuXVAQaDGKeFf2e472ADavvVlDyDtNz6qKC7 T9GYQzZ7WkQN+J8S61CG4wduOxzrTxU+8h0V2yX1041KJEzXe6trHpowJ14bpJgaVVc4 Wg3VKlwAQMOGHBlCn/zSI1CPhyZFAlG1qeHt+F+MVsReM2oiGVh/PAz9FfOGnceLoAXx mwDEh/MijCqauBxxrZqMX1pYTpufkL9Ml5FfKKGKjMN5yPcmQEUxIoLRHvtCQsvCMFc5 k34g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wBePflGuTIzSp+nsddwFz5v1Bexw5+WgmLeux8C68Tg=; fh=QGdVBqYg4q7jIiN9KcNXeuSkybNfaLt8K5LfUlN67/I=; b=GDghqejAUCwBSRbdIewIjybV6Qo9+BC0dftl5wzvJInVrLYIlq88rUxQmh2gw477f3 dI10/lZPyynXydQ8N8slohYBBNuya+E5nZlwiGZJUuzCjr0NPaE3GIgp2WPFj3De7FKf t9cHI/pbYUtaRLeA+66Hp7Ukmi8TOepUfQbqxYlGCPYZPXcirQ/XFIjE1gSSdpk25BYt IYR2oXS//YOXfIJkS3u/iwGROYeq1DwF23NPMTl5C+umfdEQjyfivLqm3dPkfjTA2lMd ZKrMb3QblqO6/zNpRTX0IpNBZ3UuR2191V5l22X/99BiZ5CwE9caGHnPtT8yqNEZdXKN SXrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=YtQDDk44; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-77125-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77125-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y5-20020a05620a44c500b00787162aeb70si15388493qkp.774.2024.02.22.10.34.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:34:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77125-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=YtQDDk44; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-77125-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77125-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8DB6E1C2441F for ; Thu, 22 Feb 2024 18:34:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4CD1A15DBD1; Thu, 22 Feb 2024 18:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b="YtQDDk44" Received: from vps.xff.cz (vps.xff.cz [195.181.215.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDA3F15CD4D; Thu, 22 Feb 2024 18:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.181.215.36 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625940; cv=none; b=NeKLQvyYdUDVtwSaGU8ruRcDMSvkT5xW5geza+gV7tygPlOFn8V3RlmmYY0eXlCXaNLGICrpG86emHJupsm7WI7krQLHQ9tRzNvdEL0WCj06YxRWfirqoHjB/rUNfJicacFT7ieLR5/rbzGV4Zyjv5f6GWCxdEo9FwEtI+VJ0ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625940; c=relaxed/simple; bh=Yqk0ASm3qdzudKQuluB7RYak2VVWIt+QMV2iJnIWwSI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uGpdY98LpfwORHEjBDqA3uEmwX1cCmRQVKmZIxSTh5jb/+YH76Rw+BWaTlGdHVcmAdghlWx4rjXgsCZjiI3uX4660ri+GdMhBXRwZJsZAceynAKx59IkgYXOOe9Or8JqlQTuGvxs2LRNv1G1qOUCMAXiiR/TpPhmgQziilLD/qs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz; spf=pass smtp.mailfrom=xff.cz; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b=YtQDDk44; arc=none smtp.client-ip=195.181.215.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xff.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xff.cz; s=mail; t=1708625934; bh=Yqk0ASm3qdzudKQuluB7RYak2VVWIt+QMV2iJnIWwSI=; h=From:To:Cc:Subject:Date:References:From; b=YtQDDk44LKFLzzv4E8ww19JWbgcN5cXiIHSi2Ww7LvxnSvgoTthuV4jlj1ujsL8TT Y/0WBTPGl6YOPKNL/flpBWsfNm/aIG8RtTZlael3ac6K5DacVQMt2duU2OHmmOVNsr d1asC2MsOZbV+oaO009cCMT+2WbdP15+qnFyCU5A= From: =?utf-8?q?Ond=C5=99ej_Jirman?= To: linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Samuel Holland , Chen-Yu Tsai , Jernej Skrabec , Ondrej Jirman , Arnaud Ferraris , linux-sound@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 2/4] ASoC: sun8i-codec: Enable bus clock at STANDBY and higher bias Date: Thu, 22 Feb 2024 19:18:45 +0100 Message-ID: <20240222181851.3398254-3-megi@xff.cz> In-Reply-To: <20240222181851.3398254-1-megi@xff.cz> References: <20240222181851.3398254-1-megi@xff.cz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791625119418151301 X-GMAIL-MSGID: 1791625119418151301 From: Samuel Holland For codec variants that have a bus clock, that clock must be running to receive interrupts. Since jack and mic accessory detection should work even when no audio is playing, that means the bus clock should be enabled any time the system is on. Accomplish that by tying the bus clock to the runtime PM state, which is then tied to the bias level not being OFF. Since the codec sets idle_bias_on, bias will generally never be OFF. However, we can set suspend_bias_off to maintain the power savings of gating the bus clock during suspend, when we don't expect jack/accessory detection to work. Signed-off-by: Samuel Holland Signed-off-by: Ondřej Jirman --- sound/soc/sunxi/sun8i-codec.c | 41 ++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c index 7b45ddffe990..2a46b96b03cc 100644 --- a/sound/soc/sunxi/sun8i-codec.c +++ b/sound/soc/sunxi/sun8i-codec.c @@ -177,12 +177,14 @@ struct sun8i_codec_aif { }; struct sun8i_codec_quirks { - bool legacy_widgets : 1; - bool lrck_inversion : 1; + bool bus_clock : 1; + bool legacy_widgets : 1; + bool lrck_inversion : 1; }; struct sun8i_codec { struct regmap *regmap; + struct clk *clk_bus; struct clk *clk_module; const struct sun8i_codec_quirks *quirks; struct sun8i_codec_aif aifs[SUN8I_CODEC_NAIFS]; @@ -197,6 +199,14 @@ static int sun8i_codec_runtime_resume(struct device *dev) struct sun8i_codec *scodec = dev_get_drvdata(dev); int ret; + if (scodec->clk_bus) { + ret = clk_prepare_enable(scodec->clk_bus); + if (ret) { + dev_err(dev, "Failed to enable the bus clock\n"); + return ret; + } + } + regcache_cache_only(scodec->regmap, false); ret = regcache_sync(scodec->regmap); @@ -215,6 +225,9 @@ static int sun8i_codec_runtime_suspend(struct device *dev) regcache_cache_only(scodec->regmap, true); regcache_mark_dirty(scodec->regmap); + if (scodec->clk_bus) + clk_disable_unprepare(scodec->clk_bus); + return 0; } @@ -1277,6 +1290,7 @@ static const struct snd_soc_component_driver sun8i_soc_component = { .num_dapm_routes = ARRAY_SIZE(sun8i_codec_dapm_routes), .probe = sun8i_codec_component_probe, .idle_bias_on = 1, + .suspend_bias_off = 1, .endianness = 1, }; @@ -1299,6 +1313,18 @@ static int sun8i_codec_probe(struct platform_device *pdev) if (!scodec) return -ENOMEM; + scodec->quirks = of_device_get_match_data(&pdev->dev); + + platform_set_drvdata(pdev, scodec); + + if (scodec->quirks->bus_clock) { + scodec->clk_bus = devm_clk_get(&pdev->dev, "bus"); + if (IS_ERR(scodec->clk_bus)) { + dev_err(&pdev->dev, "Failed to get the bus clock\n"); + return PTR_ERR(scodec->clk_bus); + } + } + scodec->clk_module = devm_clk_get(&pdev->dev, "mod"); if (IS_ERR(scodec->clk_module)) { dev_err(&pdev->dev, "Failed to get the module clock\n"); @@ -1311,17 +1337,14 @@ static int sun8i_codec_probe(struct platform_device *pdev) return PTR_ERR(base); } - scodec->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "bus", base, - &sun8i_codec_regmap_config); + scodec->regmap = devm_regmap_init_mmio(&pdev->dev, base, + &sun8i_codec_regmap_config); if (IS_ERR(scodec->regmap)) { dev_err(&pdev->dev, "Failed to create our regmap\n"); return PTR_ERR(scodec->regmap); } - scodec->quirks = of_device_get_match_data(&pdev->dev); - - platform_set_drvdata(pdev, scodec); - + regcache_cache_only(scodec->regmap, true); pm_runtime_enable(&pdev->dev); if (!pm_runtime_enabled(&pdev->dev)) { ret = sun8i_codec_runtime_resume(&pdev->dev); @@ -1357,11 +1380,13 @@ static void sun8i_codec_remove(struct platform_device *pdev) } static const struct sun8i_codec_quirks sun8i_a33_quirks = { + .bus_clock = true, .legacy_widgets = true, .lrck_inversion = true, }; static const struct sun8i_codec_quirks sun50i_a64_quirks = { + .bus_clock = true, }; static const struct of_device_id sun8i_codec_of_match[] = { From patchwork Thu Feb 22 18:18:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Jirman?= X-Patchwork-Id: 204986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp132688dyb; Thu, 22 Feb 2024 10:34:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX2wVNIar8u2blghSg/eIk7f+EtKDjioLLPOXf9bSTX6IQibh82xWMefEhS3q22C9akdMzkJTHmkHtdkZI3tOHlgzBrBA== X-Google-Smtp-Source: AGHT+IH4rveU6vBWR1q0IbQEFhtqml8eJIOOhgXSL0+XITW+1pnSTwt6IyXIMjVF8T8IDiTzVla8 X-Received: by 2002:a17:902:680c:b0:1db:a6b9:a311 with SMTP id h12-20020a170902680c00b001dba6b9a311mr17080037plk.41.1708626852918; Thu, 22 Feb 2024 10:34:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626852; cv=pass; d=google.com; s=arc-20160816; b=mKldRGg90fbgRCn4SxQt+JPYhdeW/AQwnJQZtfu4RCSeB6611GAXYXSLTOLu+gX3mR 3Jo3FZlQZOq3UAhXrr1rFRSGZMVPoPxoSaXO6oyDJzvHMG+unPEbz0Hwj9xUtBGoPAGr uuPlTXsHCRURLLnc3+4dfS9Y0/pIPgW5EQEB0lm6PyUpwqQyg4legebis0F31roaoZQl Uph8ADi3K3F0vsAnhhPeiUOqZsiQT3NVhmfqrmSWe3lSExuGC1Re2oRubT/+4svKwQ5c gMvNr552dm9PZjlqmW83ji/Z8+lzg0WceJBvA7ZFbdFP7IBSLlyrHkgFXKZm8KFOkvXf kXQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FWdJspBYMrhtTSLSa4y1djhqrRBMjUznKJebsmkbZis=; fh=lpP2IfcZNV/hf2mJVDijI7IDwsQdGK74Y9L5zbTSxLU=; b=MlAx1rBCZI39+MTrXqz5O+l6GI6UBCkz/XTMS7yQpuE/QqY2Mx4DCYKwmXXtutl65v UEi27+bIvM4AB3XYFsz44f8s/DS9QeIkXKPNCM3/zW5/LN+TK31/b+TCe57c7RbaCJ1O of0XHNBcuO6lidxiE4NhASR3RTI7xIAQ27bRmncJU14oao73zm1NX1b7QrSUd9SVsMLc /twxecl2ixfOrweTU6T/MzqAtRaPvatYITLTEYj0R4Fz/N01TkrlxQ06aONtNMrfXMOd Kcl5MDGhQ5aLNwESz6HumE7vvXfPKVfA53c3+vpKzTPfvA4fLBiD2cSnnwHci5WyDfcO FyfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=NhE6Ftgc; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-77123-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77123-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e6-20020a17090301c600b001db27d25945si10782474plh.560.2024.02.22.10.34.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:34:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77123-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=NhE6Ftgc; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-77123-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77123-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BA232284AAC for ; Thu, 22 Feb 2024 18:34:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D79CB15DBB7; Thu, 22 Feb 2024 18:19:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b="NhE6Ftgc" Received: from vps.xff.cz (vps.xff.cz [195.181.215.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCEC415CD4E; Thu, 22 Feb 2024 18:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.181.215.36 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625940; cv=none; b=Obpni6N3toXBgpf5vWVKCqr8//7rk2eBL99QWXzQiXYZf1JpdykRqSwOWs2o9xS+w6ib5KAZJq0EABh2+G9nvz/fmqvm9DSeu8U4F911nZYyyiG/Egk9Ilqv5pJmGRO9S2ynMWC1/Dxb6aIho4IY2XJBV8NBlInDPLudFHbJs0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625940; c=relaxed/simple; bh=8aPsPyUjJEl/R2IiSeB6qnP9Jf53fx5I0eeKkSCAPzA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VW9pP62QTNK0mPPW0YdfCy630uHJUsOnlgKXlo76+H0CozHyP26oCTbS+P48pk4PYYZ8ha3igFUZytBF1ayRtR4qgLDSXh+LFWTC6eLgyrDC+nnr0Wa44PbKTX0ZKQTDlAHytbhX4GxS5WOiCrjvTMTzfgQPhsnowZMPoQaIF48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz; spf=pass smtp.mailfrom=xff.cz; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b=NhE6Ftgc; arc=none smtp.client-ip=195.181.215.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xff.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xff.cz; s=mail; t=1708625934; bh=8aPsPyUjJEl/R2IiSeB6qnP9Jf53fx5I0eeKkSCAPzA=; h=From:To:Cc:Subject:Date:References:From; b=NhE6FtgcP2iuloogF5pyvdDXOhkAE+0lhI9G8X66gOGEBu1RPFfZ1YPtltDOlC/hT NXdgGQCWt8Va4DJzZLk+XNMHUxvYUfBeEyYCrB447wPaRYVbUarc4Tu/8r6UY8k4Q/ XHA0wrsgnLv+GdZGUic2xQi2wTmGC86QuftVw5dE= From: =?utf-8?q?Ond=C5=99ej_Jirman?= To: linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Arnaud Ferraris , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Ondrej Jirman , linux-sound@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 3/4] ASoC: sun50i-codec-analog: Enable jack detection on startup Date: Thu, 22 Feb 2024 19:18:46 +0100 Message-ID: <20240222181851.3398254-4-megi@xff.cz> In-Reply-To: <20240222181851.3398254-1-megi@xff.cz> References: <20240222181851.3398254-1-megi@xff.cz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791625111222260574 X-GMAIL-MSGID: 1791625111222260574 From: Arnaud Ferraris This commit adds the necessary setup to enable jack detection on startup as well as the callback function enabling the microphone ADC when headset bias is enabled. The microphone ADC is also disabled in suspend. Signed-off-by: Arnaud Ferraris [Samuel: Moved MICADCEN setup to HBIAS event, added bias hooks] Signed-off-by: Samuel Holland Signed-off-by: Ondřej Jirman --- sound/soc/sunxi/sun50i-codec-analog.c | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/sound/soc/sunxi/sun50i-codec-analog.c b/sound/soc/sunxi/sun50i-codec-analog.c index cedd4de42d1a..2081721a8ff2 100644 --- a/sound/soc/sunxi/sun50i-codec-analog.c +++ b/sound/soc/sunxi/sun50i-codec-analog.c @@ -116,8 +116,10 @@ #define SUN50I_ADDA_HS_MBIAS_CTRL_MMICBIASEN 7 #define SUN50I_ADDA_JACK_MIC_CTRL 0x1d +#define SUN50I_ADDA_JACK_MIC_CTRL_JACKDETEN 7 #define SUN50I_ADDA_JACK_MIC_CTRL_INNERRESEN 6 #define SUN50I_ADDA_JACK_MIC_CTRL_HMICBIASEN 5 +#define SUN50I_ADDA_JACK_MIC_CTRL_MICADCEN 4 /* mixer controls */ static const struct snd_kcontrol_new sun50i_a64_codec_mixer_controls[] = { @@ -296,6 +298,19 @@ static const struct snd_kcontrol_new sun50i_codec_earpiece_switch[] = { SUN50I_ADDA_EARPIECE_CTRL1_ESPPA_MUTE, 1, 0), }; +static int sun50i_codec_hbias_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); + u32 value = !!SND_SOC_DAPM_EVENT_ON(event); + + regmap_update_bits(component->regmap, SUN50I_ADDA_JACK_MIC_CTRL, + BIT(SUN50I_ADDA_JACK_MIC_CTRL_MICADCEN), + value << SUN50I_ADDA_JACK_MIC_CTRL_MICADCEN); + + return 0; +} + static const struct snd_soc_dapm_widget sun50i_a64_codec_widgets[] = { /* DAC */ SND_SOC_DAPM_DAC("Left DAC", NULL, SUN50I_ADDA_MIX_DAC_CTRL, @@ -367,7 +382,8 @@ static const struct snd_soc_dapm_widget sun50i_a64_codec_widgets[] = { /* Microphone Bias */ SND_SOC_DAPM_SUPPLY("HBIAS", SUN50I_ADDA_JACK_MIC_CTRL, SUN50I_ADDA_JACK_MIC_CTRL_HMICBIASEN, - 0, NULL, 0), + 0, sun50i_codec_hbias_event, + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), /* Mic input path */ SND_SOC_DAPM_PGA("Mic2 Amplifier", SUN50I_ADDA_MIC2_CTRL, @@ -474,14 +490,28 @@ static const struct snd_soc_dapm_route sun50i_a64_codec_routes[] = { static int sun50i_a64_codec_set_bias_level(struct snd_soc_component *component, enum snd_soc_bias_level level) { + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); + int hbias; + switch (level) { case SND_SOC_BIAS_OFF: + regmap_clear_bits(component->regmap, SUN50I_ADDA_JACK_MIC_CTRL, + BIT(SUN50I_ADDA_JACK_MIC_CTRL_JACKDETEN) | + BIT(SUN50I_ADDA_JACK_MIC_CTRL_MICADCEN)); + regmap_set_bits(component->regmap, SUN50I_ADDA_HP_CTRL, BIT(SUN50I_ADDA_HP_CTRL_PA_CLK_GATE)); break; case SND_SOC_BIAS_STANDBY: regmap_clear_bits(component->regmap, SUN50I_ADDA_HP_CTRL, BIT(SUN50I_ADDA_HP_CTRL_PA_CLK_GATE)); + + hbias = snd_soc_dapm_get_pin_status(dapm, "HBIAS"); + regmap_update_bits(component->regmap, SUN50I_ADDA_JACK_MIC_CTRL, + BIT(SUN50I_ADDA_JACK_MIC_CTRL_JACKDETEN) | + BIT(SUN50I_ADDA_JACK_MIC_CTRL_MICADCEN), + BIT(SUN50I_ADDA_JACK_MIC_CTRL_JACKDETEN) | + hbias << SUN50I_ADDA_JACK_MIC_CTRL_MICADCEN); break; default: break; From patchwork Thu Feb 22 18:18:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Jirman?= X-Patchwork-Id: 204988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp132861dyb; Thu, 22 Feb 2024 10:34:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXKWCVa7L17ithDffP62Au3XhLP8j5xzpeiExRgiv5/4Oyvg7IEKEzRhwUxNPrpkQtZYrzi6J4rwHBYczRuRY87n4VRCg== X-Google-Smtp-Source: AGHT+IGRmZkfgjs8r6DTsyNANYzSlB7Evh8H7UaC5m7HjXXpDdmdexCXb7F/P0CiP3cuVZ1sr4FH X-Received: by 2002:a50:ed96:0:b0:565:2b6:6a7 with SMTP id h22-20020a50ed96000000b0056502b606a7mr3864595edr.34.1708626870854; Thu, 22 Feb 2024 10:34:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626870; cv=pass; d=google.com; s=arc-20160816; b=eo06UrQTRfK6l9yDHX5LsBizrtKyD9vxAj8RtPYQznE4388ZwKV3aUb68+0sRvoNSD 9lGJrBns2MOle1qk4s223YvZdU02ncAXuYCYgM9UJfIw5mTMb8iEIUrjNMGA+snJzXsb 4gie5f7Z8HwKIuhUily4mu1VAKQ0a+AsKBHhTL4AaHu2fKlJ48ACOqb1x9LrOy+Fj1Ju ruVs1UqJU+6J5xivlOWRLG2Xg4jGg+wkQ0FCOFmwPuTmtJOOPIjGun/0rMPbPwfPs1hV TTF5DU7Ew5FSBdC3VuewiINZi4H8HgMl58Cs2bSNVaAtpxoBVKZGExLSysSh3gJ0ouO6 88Qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=geboPF0yp9GF6DYgc+boZaRefl71ch3w5rS53CuUj2E=; fh=lpP2IfcZNV/hf2mJVDijI7IDwsQdGK74Y9L5zbTSxLU=; b=bOONW1+vqzh6Tkyoh7AHbvZBCxI2z4N2GghwO5ThsVV5EQ99uWclotw2DjH0Ro5lVS w1TQ0Av+UZNUH6MeVR6lCpzojjztoHKm94JRLc9C+INiLs2zW8vr6uB1bykh69Kn15j7 enjnlUCdeD2IC5GCIuredf8sBzOuBFT3NS/ZiWnbLyRLUBMK+gx8uyfyBvzwLf4qRUjo NieLkEB9y65yPo4MK1qjmMyi5RjX8huP7cRTCnOMcpCQZ2+OakHPSJybmBsmwyupqDY+ 4YkgsE0z6FQgnAOD7p2CSMCe8XHjw2fqy0P3NkWXGLSKaY9wb2jSrYovszAUNkttZaEF KEmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=wrkOwpD7; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-77121-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77121-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g21-20020a0564021ed500b0056458fa3b8fsi4530004edg.593.2024.02.22.10.34.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:34:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77121-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=wrkOwpD7; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-77121-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77121-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4EB701F22474 for ; Thu, 22 Feb 2024 18:34:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6326F14B803; Thu, 22 Feb 2024 18:19:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b="wrkOwpD7" Received: from vps.xff.cz (vps.xff.cz [195.181.215.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19C1814F99E; Thu, 22 Feb 2024 18:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.181.215.36 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625939; cv=none; b=Mjv269JZWz/2u7/adSzQpVXa6X7t05PPp3qSnY+vl4/PulannDGfHNNNgyjiMI99DV6Ksk6C55ESabzwSfFTbaTO6ijyu1eb/iBoeVgKPWM92fEcbQGfz4cOgE7KRjz91B2oq8kPofKHZZroqjbGkQSdSQbYN2cEu8GVT6k0IEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625939; c=relaxed/simple; bh=zEYEjJpWS/2RpwHzMoVR1JN0VC9wPDX+31y4Z9y8aL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jCh25dP3wZGBN5nNrsVF5i4bjPT+T3PFa94scg2zbPh1Q6iLLOUw06u+/hwsTfj0x8xEMN8+mkHKjtDn8PwLd2QGkrcYfveQx0HwvlwAq5+5pRv3nZk8HeE82UkgjEDkXzggwvlkogEJzlqXu2qqh6GMkOY18J3/m5ldBSyNlBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz; spf=pass smtp.mailfrom=xff.cz; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b=wrkOwpD7; arc=none smtp.client-ip=195.181.215.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xff.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xff.cz; s=mail; t=1708625935; bh=zEYEjJpWS/2RpwHzMoVR1JN0VC9wPDX+31y4Z9y8aL8=; h=From:To:Cc:Subject:Date:References:From; b=wrkOwpD7306NTvSBVZO+Sv31n73MjaIUE4haJd6XWoAOxOEzPiis8t/UCzZLjdOKK MDMWtFMzC38tpNq+PK7EICXCzYG1txOgo0QvStP7qCVIM2GfXXmSP9jAA9re5Et/Zz bT1JFpb99bXPQ+Ne9itQLaRXx8Xms9B8juSqqqlk= From: =?utf-8?q?Ond=C5=99ej_Jirman?= To: linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Arnaud Ferraris , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Ondrej Jirman , linux-sound@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 4/4] ASoC: sun8i-codec: Implement jack and accessory detection Date: Thu, 22 Feb 2024 19:18:47 +0100 Message-ID: <20240222181851.3398254-5-megi@xff.cz> In-Reply-To: <20240222181851.3398254-1-megi@xff.cz> References: <20240222181851.3398254-1-megi@xff.cz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791625129702109965 X-GMAIL-MSGID: 1791625129702109965 From: Arnaud Ferraris Add support for the jack detection functionality in the A64 variant, which uses a pair of IRQs; and microphone accessory (button) detection, which uses an ADC with an IRQ trigger. Since not all users of this component have a headphone or headset jack, only enable jack pins where the corresponding widget exists. Similarly, only enable microphone accessory detection when the microphone is hooked up to a headset jack. IRQs will only be triggered if the JACKDETEN, HMICBIASEN, and MICADCEN bits are set appropriately in the analog codec component, but there is no direct software dependency between the two components. Setup ADC so that it samples with period of 16ms, disable smoothing and enable MDATA threshold (should be below idle voltage/HMIC_DATA value). Also enable HMIC_N, which makes sure we get HMIC_N samples after HMIC_DATA crosses the threshold. This allows us to perform steady state detection of HMIC_DATA, by comparing current and previous ADC samples, to detect end of the transient when the user de-presses the button. Otherwise ADC could sample anywhere within the transient, and the driver may mis-issue key-press events for other buttons attached to the resistor ladder. Signed-off-by: Arnaud Ferraris [Samuel: Decouple from analog codec, automatic pin detection, fixes] Co-developed-by: Samuel Holland Signed-off-by: Samuel Holland [Ondrej: Re-work the sampling mechanism to prevent mis-detection of button presses due to slow transient change of mic line DC voltage. Completely rewritten interrupt handling, to debounce plugin plugout interrupt events properly.] Co-developed-by: Ondrej Jirman Signed-off-by: Ondrej Jirman --- sound/soc/sunxi/sun50i-codec-analog.c | 12 + sound/soc/sunxi/sun8i-codec.c | 351 ++++++++++++++++++++++++++ 2 files changed, 363 insertions(+) diff --git a/sound/soc/sunxi/sun50i-codec-analog.c b/sound/soc/sunxi/sun50i-codec-analog.c index 2081721a8ff2..2dcdf113b66e 100644 --- a/sound/soc/sunxi/sun50i-codec-analog.c +++ b/sound/soc/sunxi/sun50i-codec-analog.c @@ -115,6 +115,11 @@ #define SUN50I_ADDA_HS_MBIAS_CTRL 0x0e #define SUN50I_ADDA_HS_MBIAS_CTRL_MMICBIASEN 7 +#define SUN50I_ADDA_MDET_CTRL 0x1c +#define SUN50I_ADDA_MDET_CTRL_SELDETADC_FS 4 +#define SUN50I_ADDA_MDET_CTRL_SELDETADC_DB 2 +#define SUN50I_ADDA_MDET_CTRL_SELDETADC_BF 0 + #define SUN50I_ADDA_JACK_MIC_CTRL 0x1d #define SUN50I_ADDA_JACK_MIC_CTRL_JACKDETEN 7 #define SUN50I_ADDA_JACK_MIC_CTRL_INNERRESEN 6 @@ -564,6 +569,13 @@ static int sun50i_codec_analog_probe(struct platform_device *pdev) BIT(SUN50I_ADDA_JACK_MIC_CTRL_INNERRESEN), enable << SUN50I_ADDA_JACK_MIC_CTRL_INNERRESEN); + /* Select sample interval of the ADC sample to 16ms */ + regmap_update_bits(regmap, SUN50I_ADDA_MDET_CTRL, + 0x7 << SUN50I_ADDA_MDET_CTRL_SELDETADC_FS | + 0x3 << SUN50I_ADDA_MDET_CTRL_SELDETADC_BF, + 0x3 << SUN50I_ADDA_MDET_CTRL_SELDETADC_FS | + 0x3 << SUN50I_ADDA_MDET_CTRL_SELDETADC_BF); + return devm_snd_soc_register_component(&pdev->dev, &sun50i_codec_analog_cmpnt_drv, NULL, 0); diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c index 2a46b96b03cc..9b78b6226012 100644 --- a/sound/soc/sunxi/sun8i-codec.c +++ b/sound/soc/sunxi/sun8i-codec.c @@ -12,12 +12,16 @@ #include #include #include +#include #include +#include +#include #include #include #include #include +#include #include #include #include @@ -118,6 +122,23 @@ #define SUN8I_ADC_VOL_CTRL 0x104 #define SUN8I_ADC_VOL_CTRL_ADCL_VOL 8 #define SUN8I_ADC_VOL_CTRL_ADCR_VOL 0 +#define SUN8I_HMIC_CTRL1 0x110 +#define SUN8I_HMIC_CTRL1_HMIC_M 12 +#define SUN8I_HMIC_CTRL1_HMIC_N 8 +#define SUN8I_HMIC_CTRL1_MDATA_THRESHOLD_DB 5 +#define SUN8I_HMIC_CTRL1_JACK_OUT_IRQ_EN 4 +#define SUN8I_HMIC_CTRL1_JACK_IN_IRQ_EN 3 +#define SUN8I_HMIC_CTRL1_HMIC_DATA_IRQ_EN 0 +#define SUN8I_HMIC_CTRL2 0x114 +#define SUN8I_HMIC_CTRL2_HMIC_SAMPLE 14 +#define SUN8I_HMIC_CTRL2_HMIC_MDATA_THRESHOLD 8 +#define SUN8I_HMIC_CTRL2_HMIC_SF 6 +#define SUN8I_HMIC_STS 0x118 +#define SUN8I_HMIC_STS_MDATA_DISCARD 13 +#define SUN8I_HMIC_STS_HMIC_DATA 8 +#define SUN8I_HMIC_STS_JACK_OUT_IRQ_ST 4 +#define SUN8I_HMIC_STS_JACK_IN_IRQ_ST 3 +#define SUN8I_HMIC_STS_HMIC_DATA_IRQ_ST 0 #define SUN8I_DAC_DIG_CTRL 0x120 #define SUN8I_DAC_DIG_CTRL_ENDA 15 #define SUN8I_DAC_VOL_CTRL 0x124 @@ -143,6 +164,17 @@ #define SUN8I_AIF_CLK_CTRL_WORD_SIZ_MASK GENMASK(5, 4) #define SUN8I_AIF_CLK_CTRL_DATA_FMT_MASK GENMASK(3, 2) #define SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_MASK GENMASK(1, 0) +#define SUN8I_HMIC_CTRL1_HMIC_M_MASK GENMASK(15, 12) +#define SUN8I_HMIC_CTRL1_HMIC_N_MASK GENMASK(11, 8) +#define SUN8I_HMIC_CTRL1_MDATA_THRESHOLD_DB_MASK GENMASK(6, 5) +#define SUN8I_HMIC_CTRL2_HMIC_SAMPLE_MASK GENMASK(15, 14) +#define SUN8I_HMIC_CTRL2_HMIC_SF_MASK GENMASK(7, 6) +#define SUN8I_HMIC_STS_HMIC_DATA_MASK GENMASK(12, 8) + +#define SUN8I_CODEC_BUTTONS (SND_JACK_BTN_0|\ + SND_JACK_BTN_1|\ + SND_JACK_BTN_2|\ + SND_JACK_BTN_3) #define SUN8I_CODEC_PASSTHROUGH_SAMPLE_RATE 48000 @@ -178,16 +210,33 @@ struct sun8i_codec_aif { struct sun8i_codec_quirks { bool bus_clock : 1; + bool jack_detection : 1; bool legacy_widgets : 1; bool lrck_inversion : 1; }; +enum { + SUN8I_JACK_STATUS_DISCONNECTED, + SUN8I_JACK_STATUS_WAITING_HBIAS, + SUN8I_JACK_STATUS_CONNECTED, +}; + struct sun8i_codec { struct regmap *regmap; + struct snd_soc_card *card; struct clk *clk_bus; struct clk *clk_module; const struct sun8i_codec_quirks *quirks; struct sun8i_codec_aif aifs[SUN8I_CODEC_NAIFS]; + struct snd_soc_jack jack; + struct delayed_work jack_work; + int jack_irq; + int jack_status; + int jack_last_sample; + ktime_t jack_hbias_ready; + int jack_type; + int last_hmic_irq; + struct mutex jack_mutex; unsigned int sysclk_rate; int sysclk_refcnt; }; @@ -1239,12 +1288,79 @@ static const struct snd_soc_dapm_route sun8i_codec_legacy_routes[] = { { "AIF1 Slot 0 Right", NULL, "DACR" }, }; +static struct snd_soc_jack_pin sun8i_codec_jack_pins[] = { + { + .pin = "Headphone Jack", + .mask = SND_JACK_HEADPHONE, + }, + { + .pin = "Headset Microphone", + .mask = SND_JACK_MICROPHONE, + }, +}; + +static int sun8i_codec_jack_init(struct sun8i_codec *scodec) +{ + int pins = 0; + int type = 0; + int i, ret; + + for (i = 0; i < ARRAY_SIZE(sun8i_codec_jack_pins); ++i) { + struct snd_soc_jack_pin *pin = &sun8i_codec_jack_pins[i]; + struct snd_soc_dapm_widget *w; + + for_each_card_widgets(scodec->card, w) { + if (!strcmp(pin->pin, w->name)) { + pins |= BIT(i); + type |= pin->mask; + break; + } + } + } + + if (!type) + return 0; + + if (type & SND_JACK_MICROPHONE) + type |= SUN8I_CODEC_BUTTONS; + + ret = snd_soc_card_jack_new(scodec->card, "Headset Jack", type, + &scodec->jack); + if (ret) + return ret; + + for (i = 0; i < ARRAY_SIZE(sun8i_codec_jack_pins); ++i) { + struct snd_soc_jack_pin *pin = &sun8i_codec_jack_pins[i]; + + if (pins & BIT(i)) { + ret = snd_soc_jack_add_pins(&scodec->jack, 1, pin); + if (ret) + return ret; + } + } + + if (type & SND_JACK_MICROPHONE) { + struct snd_jack *jack = scodec->jack.jack; + + snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); + snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOLUMEUP); + snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); + snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); + } + + scodec->jack_type = type; + + return 0; +} + static int sun8i_codec_component_probe(struct snd_soc_component *component) { struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); struct sun8i_codec *scodec = snd_soc_component_get_drvdata(component); int ret; + scodec->card = component->card; + /* Add widgets for backward compatibility with old device trees. */ if (scodec->quirks->legacy_widgets) { ret = snd_soc_dapm_new_controls(dapm, sun8i_codec_legacy_widgets, @@ -1278,9 +1394,53 @@ static int sun8i_codec_component_probe(struct snd_soc_component *component) /* Program the default sample rate. */ sun8i_codec_update_sample_rate(scodec); + if (scodec->quirks->jack_detection) { + ret = sun8i_codec_jack_init(scodec); + if (ret) + return ret; + } + + if (scodec->jack_type) { + /* Reserved value required for jack IRQs to trigger. */ + regmap_write(scodec->regmap, SUN8I_HMIC_CTRL1, + 0xf << SUN8I_HMIC_CTRL1_HMIC_N | + 0x0 << SUN8I_HMIC_CTRL1_MDATA_THRESHOLD_DB | + 0x4 << SUN8I_HMIC_CTRL1_HMIC_M); + + /* Sample the ADC at 128 Hz; bypass smooth filter. */ + regmap_write(scodec->regmap, SUN8I_HMIC_CTRL2, + 0x0 << SUN8I_HMIC_CTRL2_HMIC_SAMPLE | + 0x17 << SUN8I_HMIC_CTRL2_HMIC_MDATA_THRESHOLD | + 0x0 << SUN8I_HMIC_CTRL2_HMIC_SF); + + /* Do not discard any MDATA, enable user written MDATA threshold. */ + regmap_write(scodec->regmap, SUN8I_HMIC_STS, 0); + + regmap_set_bits(scodec->regmap, SUN8I_HMIC_CTRL1, + BIT(SUN8I_HMIC_CTRL1_JACK_OUT_IRQ_EN) | + BIT(SUN8I_HMIC_CTRL1_JACK_IN_IRQ_EN)); + + enable_irq(scodec->jack_irq); + } + return 0; } +static void sun8i_codec_component_remove(struct snd_soc_component *component) +{ + struct sun8i_codec *scodec = snd_soc_component_get_drvdata(component); + + if (scodec->jack_type) { + disable_irq(scodec->jack_irq); + cancel_delayed_work_sync(&scodec->jack_work); + + regmap_clear_bits(scodec->regmap, SUN8I_HMIC_CTRL1, + BIT(SUN8I_HMIC_CTRL1_JACK_OUT_IRQ_EN) | + BIT(SUN8I_HMIC_CTRL1_JACK_IN_IRQ_EN) | + BIT(SUN8I_HMIC_CTRL1_HMIC_DATA_IRQ_EN)); + } +} + static const struct snd_soc_component_driver sun8i_soc_component = { .controls = sun8i_codec_controls, .num_controls = ARRAY_SIZE(sun8i_codec_controls), @@ -1289,20 +1449,194 @@ static const struct snd_soc_component_driver sun8i_soc_component = { .dapm_routes = sun8i_codec_dapm_routes, .num_dapm_routes = ARRAY_SIZE(sun8i_codec_dapm_routes), .probe = sun8i_codec_component_probe, + .remove = sun8i_codec_component_remove, .idle_bias_on = 1, .suspend_bias_off = 1, .endianness = 1, }; +static bool sun8i_codec_volatile_reg(struct device *dev, unsigned int reg) +{ + return reg == SUN8I_HMIC_STS; +} + static const struct regmap_config sun8i_codec_regmap_config = { .reg_bits = 32, .reg_stride = 4, .val_bits = 32, + .volatile_reg = sun8i_codec_volatile_reg, .max_register = SUN8I_DAC_MXR_SRC, .cache_type = REGCACHE_FLAT, }; +static void sun8i_codec_set_hmic_bias(struct sun8i_codec *scodec, bool enable) +{ + struct snd_soc_dapm_context *dapm = &scodec->card->dapm; + int irq_mask = BIT(SUN8I_HMIC_CTRL1_HMIC_DATA_IRQ_EN); + + if (enable) + snd_soc_dapm_force_enable_pin(dapm, "HBIAS"); + else + snd_soc_dapm_disable_pin(dapm, "HBIAS"); + + snd_soc_dapm_sync(dapm); + + regmap_update_bits(scodec->regmap, SUN8I_HMIC_CTRL1, + irq_mask, enable ? irq_mask : 0); +} + +static void sun8i_codec_jack_work(struct work_struct *work) +{ + struct sun8i_codec *scodec = container_of(work, struct sun8i_codec, + jack_work.work); + unsigned int mdata; + int type; + + guard(mutex)(&scodec->jack_mutex); + + if (scodec->jack_status == SUN8I_JACK_STATUS_DISCONNECTED) { + if (scodec->last_hmic_irq != SUN8I_HMIC_STS_JACK_IN_IRQ_ST) + return; + + scodec->jack_last_sample = -1; + + if (scodec->jack_type & SND_JACK_MICROPHONE) { + /* + * If we were in disconnected state, we enable HBIAS and + * wait 600ms before reading initial HDATA value. + */ + scodec->jack_hbias_ready = ktime_add_ms(ktime_get(), 600); + sun8i_codec_set_hmic_bias(scodec, true); + queue_delayed_work(system_power_efficient_wq, + &scodec->jack_work, + msecs_to_jiffies(610)); + scodec->jack_status = SUN8I_JACK_STATUS_WAITING_HBIAS; + } else { + snd_soc_jack_report(&scodec->jack, SND_JACK_HEADPHONE, + scodec->jack_type); + scodec->jack_status = SUN8I_JACK_STATUS_CONNECTED; + } + } else if (scodec->jack_status == SUN8I_JACK_STATUS_WAITING_HBIAS) { + /* + * If we're waiting for HBIAS to stabilize, and we get plug-out + * interrupt and nothing more for > 100ms, just cancel the + * initialization. + */ + if (scodec->last_hmic_irq == SUN8I_HMIC_STS_JACK_OUT_IRQ_ST) { + scodec->jack_status = SUN8I_JACK_STATUS_DISCONNECTED; + sun8i_codec_set_hmic_bias(scodec, false); + return; + } + + /* + * If we're not done waiting for HBIAS to stabilize, wait more. + */ + if (!ktime_after(ktime_get(), scodec->jack_hbias_ready)) { + s64 msecs = ktime_ms_delta(scodec->jack_hbias_ready, + ktime_get()); + + queue_delayed_work(system_power_efficient_wq, + &scodec->jack_work, + msecs_to_jiffies(msecs + 10)); + return; + } + + /* + * Everything is stabilized, determine jack type and report it. + */ + regmap_read(scodec->regmap, SUN8I_HMIC_STS, &mdata); + mdata &= SUN8I_HMIC_STS_HMIC_DATA_MASK; + mdata >>= SUN8I_HMIC_STS_HMIC_DATA; + + regmap_write(scodec->regmap, SUN8I_HMIC_STS, 0); + + type = mdata < 16 ? SND_JACK_HEADPHONE : SND_JACK_HEADSET; + if (type == SND_JACK_HEADPHONE) + sun8i_codec_set_hmic_bias(scodec, false); + + snd_soc_jack_report(&scodec->jack, type, scodec->jack_type); + scodec->jack_status = SUN8I_JACK_STATUS_CONNECTED; + } else if (scodec->jack_status == SUN8I_JACK_STATUS_CONNECTED) { + if (scodec->last_hmic_irq != SUN8I_HMIC_STS_JACK_OUT_IRQ_ST) + return; + + scodec->jack_status = SUN8I_JACK_STATUS_DISCONNECTED; + if (scodec->jack_type & SND_JACK_MICROPHONE) + sun8i_codec_set_hmic_bias(scodec, false); + + snd_soc_jack_report(&scodec->jack, 0, scodec->jack_type); + } +} + +static irqreturn_t sun8i_codec_jack_irq(int irq, void *dev_id) +{ + struct sun8i_codec *scodec = dev_id; + int type = SND_JACK_HEADSET; + unsigned int status, value; + + guard(mutex)(&scodec->jack_mutex); + + regmap_read(scodec->regmap, SUN8I_HMIC_STS, &status); + regmap_write(scodec->regmap, SUN8I_HMIC_STS, status); + + /* + * De-bounce in/out interrupts via a delayed work re-scheduling to + * 100ms after each interrupt.. + */ + if (status & BIT(SUN8I_HMIC_STS_JACK_OUT_IRQ_ST)) { + /* + * Out interrupt has priority over in interrupt so that if + * we get both, we assume the disconnected state, which is + * safer. + */ + scodec->last_hmic_irq = SUN8I_HMIC_STS_JACK_OUT_IRQ_ST; + mod_delayed_work(system_power_efficient_wq, &scodec->jack_work, + msecs_to_jiffies(100)); + } else if (status & BIT(SUN8I_HMIC_STS_JACK_IN_IRQ_ST)) { + scodec->last_hmic_irq = SUN8I_HMIC_STS_JACK_IN_IRQ_ST; + mod_delayed_work(system_power_efficient_wq, &scodec->jack_work, + msecs_to_jiffies(100)); + } else if (status & BIT(SUN8I_HMIC_STS_HMIC_DATA_IRQ_ST)) { + /* + * Ignore data interrupts until jack status turns to connected + * state, which is after HMIC enable stabilization is completed. + * Until then tha data are bogus. + */ + if (scodec->jack_status != SUN8I_JACK_STATUS_CONNECTED) + return IRQ_HANDLED; + + value = (status & SUN8I_HMIC_STS_HMIC_DATA_MASK) >> + SUN8I_HMIC_STS_HMIC_DATA; + + /* + * Assumes 60 mV per ADC LSB increment, 2V bias voltage, 2.2kOhm + * bias resistor. + */ + if (value == 0) + type |= SND_JACK_BTN_0; + else if (value == 1) + type |= SND_JACK_BTN_3; + else if (value <= 3) + type |= SND_JACK_BTN_1; + else if (value <= 8) + type |= SND_JACK_BTN_2; + + /* + * De-bounce. Only report button after two consecutive A/D + * samples are identical. + */ + if (scodec->jack_last_sample >= 0 && + scodec->jack_last_sample == value) + snd_soc_jack_report(&scodec->jack, type, + scodec->jack_type); + + scodec->jack_last_sample = value; + } + + return IRQ_HANDLED; +} + static int sun8i_codec_probe(struct platform_device *pdev) { struct sun8i_codec *scodec; @@ -1344,6 +1678,22 @@ static int sun8i_codec_probe(struct platform_device *pdev) return PTR_ERR(scodec->regmap); } + if (scodec->quirks->jack_detection) { + scodec->jack_irq = platform_get_irq(pdev, 0); + if (scodec->jack_irq < 0) + return scodec->jack_irq; + + ret = devm_request_threaded_irq(&pdev->dev, scodec->jack_irq, + NULL, sun8i_codec_jack_irq, + IRQF_ONESHOT | IRQF_NO_AUTOEN, + dev_name(&pdev->dev), scodec); + if (ret) + return ret; + + INIT_DELAYED_WORK(&scodec->jack_work, sun8i_codec_jack_work); + mutex_init(&scodec->jack_mutex); + } + regcache_cache_only(scodec->regmap, true); pm_runtime_enable(&pdev->dev); if (!pm_runtime_enabled(&pdev->dev)) { @@ -1387,6 +1737,7 @@ static const struct sun8i_codec_quirks sun8i_a33_quirks = { static const struct sun8i_codec_quirks sun50i_a64_quirks = { .bus_clock = true, + .jack_detection = true, }; static const struct of_device_id sun8i_codec_of_match[] = {