Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp522241ybh; Wed, 15 Jul 2020 08:11:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuhUjejS+Uamjs5tS6vcAcTPdAgniMfXxOHcQA2CuaZtb3pu8JNLiShyozIhaQGOmH0MJN X-Received: by 2002:a17:906:d286:: with SMTP id ay6mr9756031ejb.400.1594825883413; Wed, 15 Jul 2020 08:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594825883; cv=none; d=google.com; s=arc-20160816; b=SOgifbnfX4Tlkjj7OuVbht84gRphDkhNMEVd/mO01gmwky18SG4KV6MWTp71YSh98J 49+uw2JCpc8BlOMVC1F/5b90fKXIDrv4YpOtxyzSpF9DXTueahgHaLS1oWqu6LxdmsDC 8Sf53aei1AC1LmkPSNp+5T4H8CbxAdDGWyEsDzTJSL7OqBudE79XdjZE/rcOKvv2bALM 8t8CfEOs6xmTNAGMnLODP9eykUvtaFVyoqn+OsDkO2i/iiaUAdzi+kT/zeHQ/gPvRQjw 0+a5oyAuEj02CWJeruqnbzjVxskC3OaczmMggWBj9dWyCZD5G4mrH9L/S1t4f3UxO7rA 2qIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=0pV1C8URjlHoUqgkLhGeHNqB+k0zo4DI5Hhww1sWfN8=; b=AaIcCJ+x6h5Qd+oMdolpx0INQH5iYRzxkbfvi36EfC+TVsCN1Zyo24BO3kLyPv0+Fy SBa70xjG4ar8J7zxn51fE/sOLp7eUHTPEHKTKHQ7AGxib+1tnvdArorZBH/PfYa5YGc9 9B66iEbXzBOEmEaXEZpnoc2y3M1O306HSJaX25Z8fBYMl3eMpjEaiBgPWo9FL3BGAozM 0s3UP3DN4PZnSgbt3dvVUMMsqDVRU6j5knJz7AeXi3bkBQ1Wrk8gHB5Yzw5+w48ZiCGk rcpkEvL5ZzAzRm7jRALtUUja4tVwbvKUs9UopVyl+LG8sglc46++8EAUkkVsROOoLgGC 7sZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si1451520edx.179.2020.07.15.08.10.59; Wed, 15 Jul 2020 08:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727876AbgGOON4 (ORCPT + 99 others); Wed, 15 Jul 2020 10:13:56 -0400 Received: from inva020.nxp.com ([92.121.34.13]:49520 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727771AbgGOONy (ORCPT ); Wed, 15 Jul 2020 10:13:54 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 9267F1A1442; Wed, 15 Jul 2020 16:13:52 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 0F4A31A0241; Wed, 15 Jul 2020 16:13:47 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id A6A80402C1; Wed, 15 Jul 2020 22:13:40 +0800 (SGT) From: Shengjiu Wang To: perex@perex.cz, tiwai@suse.com, lgirdwood@gmail.com, broonie@kernel.org, alsa-devel@alsa-project.org, robh+dt@kernel.org, devicetree@vger.kernel.org, timur@kernel.org, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2 3/3] ASoC: fsl-asoc-card: Support Headphone and Microphone Jack detection Date: Wed, 15 Jul 2020 22:09:39 +0800 Message-Id: <1594822179-1849-4-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1594822179-1849-1-git-send-email-shengjiu.wang@nxp.com> References: <1594822179-1849-1-git-send-email-shengjiu.wang@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use asoc_simple_init_jack function from simple card to implement the Headphone and Microphone detection. Register notifier to disable Speaker when Headphone is plugged in and enable Speaker when Headphone is unplugged. Register notifier to disable Digital Microphone when Analog Microphone is plugged in and enable DMIC when Analog Microphone is unplugged. Signed-off-by: Shengjiu Wang Acked-by: Nicolin Chen --- sound/soc/fsl/Kconfig | 1 + sound/soc/fsl/fsl-asoc-card.c | 77 ++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig index ea7b4787a8af..1c4ca5ec8caf 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig @@ -315,6 +315,7 @@ config SND_SOC_FSL_ASOC_CARD depends on OF && I2C # enforce SND_SOC_FSL_ASOC_CARD=m if SND_AC97_CODEC=m: depends on SND_AC97_CODEC || SND_AC97_CODEC=n + select SND_SIMPLE_CARD_UTILS select SND_SOC_IMX_AUDMUX select SND_SOC_IMX_PCM_DMA select SND_SOC_FSL_ESAI diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c index faac6ce9a82c..f0cde3ecb5b7 100644 --- a/sound/soc/fsl/fsl-asoc-card.c +++ b/sound/soc/fsl/fsl-asoc-card.c @@ -15,6 +15,8 @@ #endif #include #include +#include +#include #include "fsl_esai.h" #include "fsl_sai.h" @@ -65,6 +67,8 @@ struct cpu_priv { /** * struct fsl_asoc_card_priv - Freescale Generic ASOC card private data * @dai_link: DAI link structure including normal one and DPCM link + * @hp_jack: Headphone Jack structure + * @mic_jack: Microphone Jack structure * @pdev: platform device pointer * @codec_priv: CODEC private data * @cpu_priv: CPU private data @@ -79,6 +83,8 @@ struct cpu_priv { struct fsl_asoc_card_priv { struct snd_soc_dai_link dai_link[3]; + struct asoc_simple_jack hp_jack; + struct asoc_simple_jack mic_jack; struct platform_device *pdev; struct codec_priv codec_priv; struct cpu_priv cpu_priv; @@ -445,6 +451,44 @@ static int fsl_asoc_card_audmux_init(struct device_node *np, return 0; } +static int hp_jack_event(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct snd_soc_jack *jack = (struct snd_soc_jack *)data; + struct snd_soc_dapm_context *dapm = &jack->card->dapm; + + if (event & SND_JACK_HEADPHONE) + /* Disable speaker if headphone is plugged in */ + snd_soc_dapm_disable_pin(dapm, "Ext Spk"); + else + snd_soc_dapm_enable_pin(dapm, "Ext Spk"); + + return 0; +} + +static struct notifier_block hp_jack_nb = { + .notifier_call = hp_jack_event, +}; + +static int mic_jack_event(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct snd_soc_jack *jack = (struct snd_soc_jack *)data; + struct snd_soc_dapm_context *dapm = &jack->card->dapm; + + if (event & SND_JACK_MICROPHONE) + /* Disable dmic if microphone is plugged in */ + snd_soc_dapm_disable_pin(dapm, "DMIC"); + else + snd_soc_dapm_enable_pin(dapm, "DMIC"); + + return 0; +} + +static struct notifier_block mic_jack_nb = { + .notifier_call = mic_jack_event, +}; + static int fsl_asoc_card_late_probe(struct snd_soc_card *card) { struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card); @@ -745,8 +789,37 @@ static int fsl_asoc_card_probe(struct platform_device *pdev) snd_soc_card_set_drvdata(&priv->card, priv); ret = devm_snd_soc_register_card(&pdev->dev, &priv->card); - if (ret && ret != -EPROBE_DEFER) - dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); + if (ret) { + if (ret != -EPROBE_DEFER) + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); + goto asrc_fail; + } + + /* + * Properties "hp-det-gpio" and "mic-det-gpio" are optional, and + * asoc_simple_init_jack uses these properties for creating + * Headphone Jack and Microphone Jack. + * + * The notifier is initialized in snd_soc_card_jack_new(), then + * snd_soc_jack_notifier_register can be called. + */ + if (of_property_read_bool(np, "hp-det-gpio")) { + ret = asoc_simple_init_jack(&priv->card, &priv->hp_jack, + 1, NULL, "Headphone Jack"); + if (ret) + goto asrc_fail; + + snd_soc_jack_notifier_register(&priv->hp_jack.jack, &hp_jack_nb); + } + + if (of_property_read_bool(np, "mic-det-gpio")) { + ret = asoc_simple_init_jack(&priv->card, &priv->mic_jack, + 0, NULL, "Mic Jack"); + if (ret) + goto asrc_fail; + + snd_soc_jack_notifier_register(&priv->mic_jack.jack, &mic_jack_nb); + } asrc_fail: of_node_put(asrc_np); -- 2.27.0