Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3537283pxb; Mon, 4 Apr 2022 20:23:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzUOmKFjooLgN7cYTPP64eu095xZ90YvCozmJhwzeVQLwA7U5wILOpCt4RpdtF6HWFV2iv X-Received: by 2002:a65:4c08:0:b0:399:dea:2be6 with SMTP id u8-20020a654c08000000b003990dea2be6mr1103486pgq.289.1649128994673; Mon, 04 Apr 2022 20:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649128994; cv=none; d=google.com; s=arc-20160816; b=RAMqwGsOWlsSZI9pg9/D+QKQk3LuG2SZqtfENw4wlOS4o7Y9ckTAwSATvj+57PZ65/ t8MSYs9HVtdJdS82PI6fSN1LtwyfA1dXnqr1kJfTmAV00+td53iK6yRWAssMwJKJ/TQl imUzANkFlY3+AIV4t7yQQDhYXAoebPVB8oncp2SJGP2IcyvqqHZArxAL7ZzX0IRloNiP 5Idh1C2mYccmk4Mbxrnx/hMmUCpEE+x8QGgSxxAipifMwky2Av5kkg2PcT86VjbRGQUY EuKHgdOWrBekbI9xmlw0BqnLDk91v+YFOkBjzfpnZGZ2R2rkZNVPjFvvuv8pvCTTbOVC 5MFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hkgSMgsyxwXFd/M1nIBXNmLTo9Aauqjl4nSxgobdTAY=; b=xix0U74oQDn1U/Rtu8rmtpBVre2rYNGz1LuSN7NXo9m6Ofaht2Afe1Z3HetIc96l2x 4EkSE6pBsRB+oKrVcyYm6cKsuZgp0obsEzw+tOI77BBX3Cfx1FKFLjFHIVS90r58MGOc V73PjUiqMsqsEiTuUCcwLEJegH67lTdsIo3HsWWEe6uBKcg3ea+jnr13aq6tgTkPad7E GwYl2B//5fzWOYuf5lWb4ePtTSwNUIvQP1vBxERp4BwrxNwRffaTVMuXrIVSY8ZTQEOR xyO7AoHXoVHw2wz65z8HI0D4h7ZO0nxJpVOZjHOiBSzZuqErqs/ye84j4yMApTBBIo7U NsOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wn7ZsKtU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a18-20020a170902ecd200b00156999258cdsi6455685plh.9.2022.04.04.20.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 20:23:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wn7ZsKtU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8D2A440A72A; Mon, 4 Apr 2022 18:22:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355900AbiDCJBd (ORCPT + 99 others); Sun, 3 Apr 2022 05:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229807AbiDCJBZ (ORCPT ); Sun, 3 Apr 2022 05:01:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B13C36324 for ; Sun, 3 Apr 2022 01:59:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C996260FE9 for ; Sun, 3 Apr 2022 08:59:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FD09C340ED; Sun, 3 Apr 2022 08:59:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648976371; bh=+Ovtq48x9WL5YWh33WVxrg+kW8FgwJJJ7TN4VKMgd2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wn7ZsKtU5/LIt20FVIU+LruzwbQQhvTwUzUso8KkfOCC31Hf2S5lmWk7ZIf42xQzV vkdWEokkgWAoeWYusINceJ4rUbOEFWRFCQP0RnwUGg7GjkGM4erSvDPVG00R3mUWAJ wjjcXar7QLc4P+RfFsdUQL4ZpWUBI+aPgVBAdRBMTWwFjuyD8lQX7MpNeM076vRAuz CwbjM1rg6+7GWjUCLYvjwqL9/d1nN6jb0DBQAF3fl6LxgBT7w6YGEQMSvgPfG8wEhX wLPGEn4zwe0fH268gsTDtI7agn/7OPVc+MlZxFCCe66BiKoeYL96Ux3WXHAT2pvwSI dcwEWbOK2H1Bg== Received: from mchehab by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1naw52-00D6f4-JN; Sun, 03 Apr 2022 10:59:28 +0200 From: Mauro Carvalho Chehab To: Pierre-Louis Bossart Cc: Mauro Carvalho Chehab , "Hans de Goede" , =?UTF-8?q?P=C3=A9ter=20Ujfalusi?= , Bard Liao , Cezary Rojewski , Jaroslav Kysela , Jie Yang , Liam Girdwood , Mark Brown , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab Subject: [PATCH RFC 1/2] ASoC: Intel: sof_es8336: support a separate gpio to control headphone Date: Sun, 3 Apr 2022 10:59:24 +0200 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mauro Carvalho Chehab Some devices may use both gpio0 and gpio1 to independently switch the speaker and the headphone. Add support for that. Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Mauro Carvalho Chehab --- See [PATCH RFC 0/2] at: https://lore.kernel.org/all/cover.1648975926.git.mchehab@kernel.org/ sound/soc/intel/boards/sof_es8336.c | 76 +++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/sound/soc/intel/boards/sof_es8336.c b/sound/soc/intel/boards/sof_es8336.c index 5e0529aa4f1d..96920d3eed8a 100644 --- a/sound/soc/intel/boards/sof_es8336.c +++ b/sound/soc/intel/boards/sof_es8336.c @@ -30,6 +30,7 @@ #define SOF_ES8336_TGL_GPIO_QUIRK BIT(4) #define SOF_ES8336_ENABLE_DMIC BIT(5) #define SOF_ES8336_JD_INVERTED BIT(6) +#define SOF_ES8336_HEADPHONE_GPIO BIT(7) static unsigned long quirk; @@ -39,10 +40,9 @@ MODULE_PARM_DESC(quirk, "Board-specific quirk override"); struct sof_es8336_private { struct device *codec_dev; - struct gpio_desc *gpio_pa; + struct gpio_desc *gpio_pa, *gpio_pa_headphone; struct snd_soc_jack jack; struct list_head hdmi_pcm_list; - bool speaker_en; }; struct sof_hdmi_pcm { @@ -51,15 +51,28 @@ struct sof_hdmi_pcm { int device; }; -static const struct acpi_gpio_params pa_enable_gpio = { 0, 0, true }; +static const struct acpi_gpio_params pa_enable_gpio0 = { 0, 0, true }; +static const struct acpi_gpio_params pa_enable_gpio1 = { 1, 0, true }; + static const struct acpi_gpio_mapping acpi_es8336_gpios[] = { - { "pa-enable-gpios", &pa_enable_gpio, 1 }, + { "pa-enable-gpios", &pa_enable_gpio0, 1 }, { } }; -static const struct acpi_gpio_params quirk_pa_enable_gpio = { 1, 0, true }; static const struct acpi_gpio_mapping quirk_acpi_es8336_gpios[] = { - { "pa-enable-gpios", &quirk_pa_enable_gpio, 1 }, + { "pa-enable-gpios", &pa_enable_gpio1, 1 }, + { } +}; + +static const struct acpi_gpio_mapping quirk_acpi_headphone_es8336_gpios[] = { + { "pa-enable-gpios", &pa_enable_gpio0, 1 }, + { "pa-enable-headphone-gpios", &pa_enable_gpio1, 1 }, + { } +}; + +static const struct acpi_gpio_mapping quirk_tgl_acpi_headphone_es8336_gpios[] = { + { "pa-enable-gpios", &pa_enable_gpio1, 1 }, + { "pa-enable-headphone-gpios", &pa_enable_gpio0, 1 }, { } }; @@ -71,6 +84,8 @@ static void log_quirks(struct device *dev) dev_info(dev, "quirk SSP%ld\n", SOF_ES8336_SSP_CODEC(quirk)); if (quirk & SOF_ES8336_ENABLE_DMIC) dev_info(dev, "quirk DMIC enabled\n"); + if (quirk & SOF_ES8336_HEADPHONE_GPIO) + dev_info(dev, "quirk headphone GPIO enabled\n"); if (quirk & SOF_ES8336_TGL_GPIO_QUIRK) dev_info(dev, "quirk TGL GPIO enabled\n"); if (quirk & SOF_ES8336_JD_INVERTED) @@ -84,24 +99,35 @@ static int sof_es8316_speaker_power_event(struct snd_soc_dapm_widget *w, struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card); if (SND_SOC_DAPM_EVENT_ON(event)) - priv->speaker_en = false; - else - priv->speaker_en = true; + msleep(70); - gpiod_set_value_cansleep(priv->gpio_pa, priv->speaker_en); + gpiod_set_value_cansleep(priv->gpio_pa, !SND_SOC_DAPM_EVENT_ON(event)); + + return 0; +} + +static int sof_es8316_headphone_power_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_card *card = w->dapm->card; + struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card); + + if (!(quirk & SOF_ES8336_HEADPHONE_GPIO)) + return 0; + + if (SND_SOC_DAPM_EVENT_ON(event)) + msleep(70); + + gpiod_set_value_cansleep(priv->gpio_pa_headphone, SND_SOC_DAPM_EVENT_ON(event)); return 0; } static const struct snd_soc_dapm_widget sof_es8316_widgets[] = { - SND_SOC_DAPM_SPK("Speaker", NULL), - SND_SOC_DAPM_HP("Headphone", NULL), + SND_SOC_DAPM_SPK("Speaker", sof_es8316_speaker_power_event), + SND_SOC_DAPM_HP("Headphone", sof_es8316_headphone_power_event), SND_SOC_DAPM_MIC("Headset Mic", NULL), SND_SOC_DAPM_MIC("Internal Mic", NULL), - - SND_SOC_DAPM_SUPPLY("Speaker Power", SND_SOC_NOPM, 0, 0, - sof_es8316_speaker_power_event, - SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), }; static const struct snd_soc_dapm_widget dmic_widgets[] = { @@ -114,11 +140,10 @@ static const struct snd_soc_dapm_route sof_es8316_audio_map[] = { /* * There is no separate speaker output instead the speakers are muxed to - * the HP outputs. The mux is controlled by the "Speaker Power" supply. + * the HP outputs. The mux is controlled Speaker and/or headphone switch. */ {"Speaker", NULL, "HPOL"}, {"Speaker", NULL, "HPOR"}, - {"Speaker", NULL, "Speaker Power"}, }; static const struct snd_soc_dapm_route sof_es8316_intmic_in1_map[] = { @@ -233,8 +258,14 @@ static int sof_es8336_quirk_cb(const struct dmi_system_id *id) { quirk = (unsigned long)id->driver_data; - if (quirk & SOF_ES8336_TGL_GPIO_QUIRK) + if (quirk & SOF_ES8336_HEADPHONE_GPIO) { + if (quirk & SOF_ES8336_TGL_GPIO_QUIRK) + gpio_mapping = quirk_tgl_acpi_headphone_es8336_gpios; + else + gpio_mapping = quirk_acpi_headphone_es8336_gpios; + } else if (quirk & SOF_ES8336_TGL_GPIO_QUIRK) { gpio_mapping = quirk_acpi_es8336_gpios; + } return 1; } @@ -592,6 +623,13 @@ static int sof_es8336_probe(struct platform_device *pdev) goto err_put_codec; } + priv->gpio_pa_headphone = gpiod_get_optional(codec_dev, "pa-enable-headphone", GPIOD_OUT_LOW); + if (IS_ERR(priv->gpio_pa_headphone)) { + ret = dev_err_probe(dev, PTR_ERR(priv->gpio_pa_headphone), + "could not get pa-enable-headphone GPIO\n"); + goto err_put_codec; + } + INIT_LIST_HEAD(&priv->hdmi_pcm_list); snd_soc_card_set_drvdata(card, priv); -- 2.35.1