From patchwork Wed Oct 1 21:25:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Reid X-Patchwork-Id: 5014561 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BF28EBEEA6 for ; Wed, 1 Oct 2014 21:26:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C61D22020E for ; Wed, 1 Oct 2014 21:26:50 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 7A98720204 for ; Wed, 1 Oct 2014 21:26:49 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id D6A2D260505; Wed, 1 Oct 2014 23:26:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 5D6A82604F5; Wed, 1 Oct 2014 23:26:37 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id C1C732604F7; Wed, 1 Oct 2014 23:26:36 +0200 (CEST) Received: from mail-ig0-f201.google.com (mail-ig0-f201.google.com [209.85.213.201]) by alsa0.perex.cz (Postfix) with ESMTP id 5A7452604F4 for ; Wed, 1 Oct 2014 23:26:29 +0200 (CEST) Received: by mail-ig0-f201.google.com with SMTP id h15so103597igd.2 for ; Wed, 01 Oct 2014 14:26:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kbgmzZN3+dvSGM4ZIBtiVBzAoFXygMVTv7pS2wpCKgc=; b=YKAU+yaTA8PZgfGLZmvK7A0gq/lKKQK2S1KQ/IVbdWuXw+cakCeqIk5q0Ew7A2o85X 0g0tPM/We943cHLuWhF79iBIzyckBX5nBVZHw+VNm8KhyX02Vsr+JZEk1b1AvYQb2Zu6 i4PB1Y3TSKbsLEEwTyVjJ7od7aBlKfw3T6A2/hc+fom2Zdd6SZZ5bRI0e1Veqycs15Jt tlXUM/bKfdghoS5+LLzxGvKW4ObycN6+Mtscc8prhztNu7RSdMUN/VYDSC9LD0zaRv8a 3jB7RIBtyzFRCa/GaGIz9TCgxqhFM4tvMA3+E0AdyA1Fr7bHBxeXahqCodppCDfa+grm 7PfQ== X-Gm-Message-State: ALoCoQlFNh2fu1PPWaCJT6KfDmbfolGxWMTTw9tu33djAT1tj4cMXVqP9BDNlKRfwLCM+DdeZkv2P1mILAc49x5FHocA5wJcUsnxMaU8Ch6SFUyX5Pv5jY46LQ8ra2h+YgMH6bmi52ktUNjtBIVHKewaXuu8ElUrc+2EOpcluxoQqtG0w0LYD08= X-Received: by 10.42.60.133 with SMTP id q5mr46240966ich.10.1412198787848; Wed, 01 Oct 2014 14:26:27 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id z1si498852qci.3.2014.10.01.14.26.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Oct 2014 14:26:27 -0700 (PDT) Received: from hojo20.mtv.corp.google.com ([172.22.65.103]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id lxp1T7Zb.1; Wed, 01 Oct 2014 14:26:27 -0700 Received: by hojo20.mtv.corp.google.com (Postfix, from userid 123195) id B0EDB1C7B71; Wed, 1 Oct 2014 14:26:26 -0700 (PDT) From: Dylan Reid To: alsa-devel@alsa-project.org Date: Wed, 1 Oct 2014 14:25:20 -0700 Message-Id: <1412198720-2326-1-git-send-email-dgreid@chromium.org> X-Mailer: git-send-email 2.1.2.330.g565301e Cc: sonnyrao@chromium.org, devicetree@vger.kernel.org, Dylan Reid , broonie@kernel.org, jay.xu@rock-chips.com Subject: [alsa-devel] [PATCH] ASoC: simple-card: Add mic and hp detect gpios. X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Allow Headphone and Microphone jack detect gpios to be specified in device tree. This will allow a few systems including rk3288_max98090 to use simple-card instead of having their own board file. Signed-off-by: Dylan Reid --- .../devicetree/bindings/sound/simple-card.txt | 4 ++ sound/soc/generic/simple-card.c | 73 ++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt b/Documentation/devicetree/bindings/sound/simple-card.txt index c2e9841..72d94b7 100644 --- a/Documentation/devicetree/bindings/sound/simple-card.txt +++ b/Documentation/devicetree/bindings/sound/simple-card.txt @@ -17,6 +17,10 @@ Optional properties: source. - simple-audio-card,mclk-fs : Multiplication factor between stream rate and codec mclk. +- simple-audio-card,hp_det_gpio : Reference to GPIO that signals when + headphones are attached. +- simple-audio-card,mic_det_gpio : Reference to GPIO that signals when + a microphone is attached. Optional subnodes: diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 709ce67..fcb431f 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -10,10 +10,13 @@ */ #include #include +#include #include #include +#include #include #include +#include #include #include #include @@ -25,6 +28,8 @@ struct simple_card_data { struct asoc_simple_dai codec_dai; } *dai_props; unsigned int mclk_fs; + int gpio_hp_det; + int gpio_mic_det; struct snd_soc_dai_link dai_link[]; /* dynamically allocated */ }; @@ -54,6 +59,32 @@ static struct snd_soc_ops asoc_simple_card_ops = { .hw_params = asoc_simple_card_hw_params, }; +static struct snd_soc_jack simple_card_hp_jack; +static struct snd_soc_jack_pin simple_card_hp_jack_pins[] = { + { + .pin = "Headphones", + .mask = SND_JACK_HEADPHONE, + }, +}; +static struct snd_soc_jack_gpio simple_card_hp_jack_gpio = { + .name = "Headphone detection", + .report = SND_JACK_HEADPHONE, + .debounce_time = 150, +}; + +static struct snd_soc_jack simple_card_mic_jack; +static struct snd_soc_jack_pin simple_card_mic_jack_pins[] = { + { + .pin = "Mic Jack", + .mask = SND_JACK_MICROPHONE, + }, +}; +static struct snd_soc_jack_gpio simple_card_mic_jack_gpio = { + .name = "Mic detection", + .report = SND_JACK_MICROPHONE, + .debounce_time = 150, +}; + static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, struct asoc_simple_dai *set) { @@ -109,6 +140,28 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) if (ret < 0) return ret; + if (gpio_is_valid(priv->gpio_hp_det)) { + snd_soc_jack_new(codec->codec, "Headphones", SND_JACK_HEADPHONE, + &simple_card_hp_jack); + snd_soc_jack_add_pins(&simple_card_hp_jack, + ARRAY_SIZE(simple_card_hp_jack_pins), + simple_card_hp_jack_pins); + + simple_card_hp_jack_gpio.gpio = priv->gpio_hp_det; + snd_soc_jack_add_gpios(&simple_card_hp_jack, 1, + &simple_card_hp_jack_gpio); + } + + if (gpio_is_valid(priv->gpio_mic_det)) { + snd_soc_jack_new(codec->codec, "Mic Jack", SND_JACK_MICROPHONE, + &simple_card_mic_jack); + snd_soc_jack_add_pins(&simple_card_mic_jack, + ARRAY_SIZE(simple_card_mic_jack_pins), + simple_card_mic_jack_pins); + simple_card_mic_jack_gpio.gpio = priv->gpio_mic_det; + snd_soc_jack_add_gpios(&simple_card_mic_jack, 1, + &simple_card_mic_jack_gpio); + } return 0; } @@ -383,6 +436,16 @@ static int asoc_simple_card_parse_of(struct device_node *node, return ret; } + priv->gpio_hp_det = of_get_named_gpio(node, + "simple-audio-card,hp-det-gpio", 0); + if (priv->gpio_hp_det == -EPROBE_DEFER) + return -EPROBE_DEFER; + + priv->gpio_mic_det = of_get_named_gpio(node, + "simple-audio-card,mic-det-gpio", 0); + if (priv->gpio_mic_det == -EPROBE_DEFER) + return -EPROBE_DEFER; + if (!priv->snd_card.name) priv->snd_card.name = priv->snd_card.dai_link->name; @@ -502,6 +565,16 @@ err: static int asoc_simple_card_remove(struct platform_device *pdev) { + struct snd_soc_card *card = platform_get_drvdata(pdev); + struct simple_card_data *priv = snd_soc_card_get_drvdata(card); + + if (gpio_is_valid(priv->gpio_hp_det)) + snd_soc_jack_free_gpios(&simple_card_hp_jack, 1, + &simple_card_hp_jack_gpio); + if (gpio_is_valid(priv->gpio_mic_det)) + snd_soc_jack_free_gpios(&simple_card_mic_jack, 1, + &simple_card_mic_jack_gpio); + return asoc_simple_card_unref(pdev); }