From patchwork Sat Feb 24 13:54:57 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: 205891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1157218dyb; Sat, 24 Feb 2024 05:58:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU5f2FsqAjlN1/hWvVWFcJe62Aqafkrlx4x0x/u9ksyZQ4WO3ef590Sez0n99WNY1CMHSZPnhf7Rzpvir+irlv/UOxyLA== X-Google-Smtp-Source: AGHT+IGG+REBmGeMX5ammPdb2uYyumbzf9W+Bk1jzfp1fMZkS0ZszRQHkP1RO/jMRUzBZkoSU7ih X-Received: by 2002:a05:6a00:8c04:b0:6e4:62ed:23c3 with SMTP id ih4-20020a056a008c0400b006e462ed23c3mr2982612pfb.9.1708783085778; Sat, 24 Feb 2024 05:58:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708783085; cv=pass; d=google.com; s=arc-20160816; b=PMzQblVGbhFjjPE/dgOXhhLO4SWkx5XPZ8VbYnILbBFPHf6qVTICQoiVAt191Ys0tq M5TYvZfC0p6o7oFVasFxhvO6UGEJaqSt8NBEZTCYI9XxA+wnK79wKpI0kThwYxg7vjC4 phU/r33qUahNtS1jwSV9LbUp6FK2Aw3TU7PtHEYyO1OqpHuXI88H1aADRfm3OtQcfVgQ oLIwz/BQAOLDbCuc33kLo5oSMnx9Ipcpw0MtVBEG5smeofBsXtps3gMyv6E9wftJNbJZ q4eVHdidWxV+7kqWKFPS/uYwI3xH9sacTICYPC2+Sj3/HrZFFKw4p2xCIOIx1Xvh0GLI Dt6w== 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=AvgKWciTdOx1lyoO25YULpYZBLmX1pG/bKEy4jWriL0=; b=ZLXbMPJR8UsaktHxMLlGpob3m/tVNKHSojUi2EJToRVs/hCNbeiVx/UbHY2iwLrxqS G6XwHcQ3Sd67P6DL1Mu81jmC5KnPSX8UTKadI62yQw5ijG/iC5hAGLd8o3SPnOrpDY14 GCPKdXbPwyh5n1JtRWaWQ7jP/mEQdG+0GnDre9jZCelNjmWWhw7rj2Jfs3eT+DCa3lzm KosLpcQSy2pzq5mjyj5GnHfmpCHAnN05UdrlYhnc+vxB2oBaHMJFoJK/R0f+0qq3sGM1 nPgEnq+n1Rs4wJMnFBj7jKoJT7YosTqX+1HaT/ObeMPfxMR/GAum4dV9vKySr7a1VUl7 fHnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=D88CM6ek; 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-79695-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79695-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 e26-20020a63545a000000b005dc88260f76si952334pgm.330.2024.02.24.05.58.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 05:58:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79695-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=D88CM6ek; 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-79695-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79695-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 CB706B212B8 for ; Sat, 24 Feb 2024 13:58:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 746F14E1CE; Sat, 24 Feb 2024 13:55:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b="D88CM6ek" 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 85AC640BFE; Sat, 24 Feb 2024 13:55:11 +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=1708782913; cv=none; b=aYtSryWjLlrOiGz1SEDKCslbKLHuu4eIZ7K05oksYES4rO+pHkqCS8X0e6vC/DfDnWAP4CNj6KpstiTwGise0Az1cxA7WzUq9oMWT304oCGnPQcF5y45UUb4SIqAyKHLPFVdieRTskuqxTLJDvf0ReC4HyMprPUXENvgn8B7J0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708782913; c=relaxed/simple; bh=8aPsPyUjJEl/R2IiSeB6qnP9Jf53fx5I0eeKkSCAPzA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sGLLtW5zWdHZ7Hwp0LDSuOH4S7SXqhmAjebg9FVzwBmw7LSGAkRQWCec1SDP+3k20EYc0g1hW7xeBrh7569zDNTQIsMPrfvP5SzMZ3Wc9UfAP2Az0JUGwVW6Fmhrja8AnYLH7EAi0mebOu2jW9aD8fCvHXLGw1fn0RKPPXVSOuM= 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=D88CM6ek; 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=1708782909; bh=8aPsPyUjJEl/R2IiSeB6qnP9Jf53fx5I0eeKkSCAPzA=; h=From:To:Cc:Subject:Date:References:From; b=D88CM6ekulNrNZzctmxlJ60Qm8q1PGfsrWMse8uyjRRX1OdYsW1eSwCJvWLARfuOH 72MN8+eOGaW0jJUOolgNrp/UpcpKQn7fe2DsxtbSGRSzwAx5xBtpPrpiv93F8FV4x9 QEUZdgpi+wXnGngU5/RIpIQoBDjM2bycR7WwYa3Q= From: =?utf-8?q?Ond=C5=99ej_Jirman?= To: linux-kernel@vger.kernel.org, Liam Girdwood , Rob Herring , Conor Dooley , 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, devicetree@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [RESEND PATCH v2 4/5] ASoC: sun50i-codec-analog: Enable jack detection on startup Date: Sat, 24 Feb 2024 14:54:57 +0100 Message-ID: <20240224135501.3822390-5-megi@xff.cz> In-Reply-To: <20240224135501.3822390-1-megi@xff.cz> References: <20240224135501.3822390-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: 1791788933165207817 X-GMAIL-MSGID: 1791788933165207817 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;