From patchwork Thu Feb 2 20:13:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 139206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A8BAC104792 for ; Fri, 3 Feb 2012 07:14:05 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751411Ab2BBUOF (ORCPT ); Thu, 2 Feb 2012 15:14:05 -0500 Received: from mail-ee0-f46.google.com ([74.125.83.46]:37409 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750797Ab2BBUOE (ORCPT ); Thu, 2 Feb 2012 15:14:04 -0500 Received: by eekc14 with SMTP id c14so902057eek.19 for ; Thu, 02 Feb 2012 12:14:03 -0800 (PST) Received: by 10.14.99.198 with SMTP id x46mr1350635eef.92.1328213643060; Thu, 02 Feb 2012 12:14:03 -0800 (PST) Received: from localhost.localdomain (bzq-84-109-86-120.red.bezeqint.net. [84.109.86.120]) by mx.google.com with ESMTPS id t11sm12891514eea.10.2012.02.02.12.14.01 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 02 Feb 2012 12:14:02 -0800 (PST) From: Leon Romanovsky To: broonie@opensource.wolfsonmicro.com, lrg@ti.com, swarren@nvidia.com, olof@lixom.net, alsa-devel@alsa-project.org, linux-tegra@vger.kernel.org Cc: Leon Romanovsky Subject: [PATCH v2 3/4] ASoC: Tegra+ALC5632: Enable headset autodetection on PAZ00 board. Date: Thu, 2 Feb 2012 22:13:37 +0200 Message-Id: <1328213618-15870-4-git-send-email-leon@leon.nu> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1328213618-15870-1-git-send-email-leon@leon.nu> References: <1328213618-15870-1-git-send-email-leon@leon.nu> Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org This patch is adding device tree support of headset autodetection on PAZ00 board. Signed-off-by: Leon Romanovsky --- sound/soc/tegra/tegra_alc5632.c | 39 +++++++++++++++++++++++++++++++++++---- 1 files changed, 35 insertions(+), 4 deletions(-) diff --git a/sound/soc/tegra/tegra_alc5632.c b/sound/soc/tegra/tegra_alc5632.c index c0ba1e4..1794139 100644 --- a/sound/soc/tegra/tegra_alc5632.c +++ b/sound/soc/tegra/tegra_alc5632.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -34,9 +35,13 @@ #define DRV_NAME "tegra-alc5632" +#define GPIO_HP_DET BIT(0) + struct tegra_alc5632 { struct tegra_asoc_utils_data util_data; struct platform_device *pcm_dev; + int gpio_requested; + int gpio_hp_det; }; static int tegra_alc5632_asoc_hw_params(struct snd_pcm_substream *substream, @@ -86,6 +91,13 @@ static struct snd_soc_jack_pin tegra_alc5632_hs_jack_pins[] = { }, }; +static struct snd_soc_jack_gpio tegra_alc5632_hp_jack_gpio = { + .name = "Headset detection", + .report = SND_JACK_HEADSET, + .debounce_time = 150, + .invert = 1, +}; + static const struct snd_soc_dapm_widget tegra_alc5632_dapm_widgets[] = { SND_SOC_DAPM_SPK("Int Spk", NULL), SND_SOC_DAPM_HP("Headset Stereophone", NULL), @@ -114,6 +126,9 @@ static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_codec *codec = rtd->codec; struct snd_soc_dapm_context *dapm = &codec->dapm; + struct device_node *np = codec->card->dev->of_node; + struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(codec->card); + int ret; snd_soc_jack_new(codec, "Headset Jack", SND_JACK_HEADSET, &tegra_alc5632_hs_jack); @@ -121,6 +136,16 @@ static int tegra_alc5632_asoc_init(struct snd_soc_pcm_runtime *rtd) ARRAY_SIZE(tegra_alc5632_hs_jack_pins), tegra_alc5632_hs_jack_pins); + machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0); + + if (gpio_is_valid(machine->gpio_hp_det)) { + tegra_alc5632_hp_jack_gpio.gpio = machine->gpio_hp_det; + snd_soc_jack_add_gpios(&tegra_alc5632_hs_jack, + 1, + &tegra_alc5632_hp_jack_gpio); + machine->gpio_requested |= GPIO_HP_DET; + } + snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1"); return 0; @@ -239,13 +264,19 @@ err: static int __devexit tegra_alc5632_remove(struct platform_device *pdev) { struct snd_soc_card *card = platform_get_drvdata(pdev); - struct tegra_alc5632 *alc5632 = snd_soc_card_get_drvdata(card); + struct tegra_alc5632 *machine = snd_soc_card_get_drvdata(card); + + if (machine->gpio_requested & GPIO_HP_DET) + snd_soc_jack_free_gpios(&tegra_alc5632_hs_jack, + 1, + &tegra_alc5632_hp_jack_gpio); + machine->gpio_requested = 0; snd_soc_unregister_card(card); - tegra_asoc_utils_fini(&alc5632->util_data); - if (!IS_ERR(alc5632->pcm_dev)) - platform_device_unregister(alc5632->pcm_dev); + tegra_asoc_utils_fini(&machine->util_data); + if (!IS_ERR(machine->pcm_dev)) + platform_device_unregister(machine->pcm_dev); return 0; }