From patchwork Mon Sep 17 00:57:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10601973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51AAC13AD for ; Mon, 17 Sep 2018 00:59:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 459C929497 for ; Mon, 17 Sep 2018 00:59:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39725294CD; Mon, 17 Sep 2018 00:59:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7721C29497 for ; Mon, 17 Sep 2018 00:59:57 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id C40842678FB; Mon, 17 Sep 2018 02:58: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 E3AEE2678D5; Mon, 17 Sep 2018 02:58:25 +0200 (CEST) Received: from mail-it0-f68.google.com (mail-it0-f68.google.com [209.85.214.68]) by alsa0.perex.cz (Postfix) with ESMTP id A48372678CA for ; Mon, 17 Sep 2018 02:58:19 +0200 (CEST) Received: by mail-it0-f68.google.com with SMTP id p79-v6so9058793itp.3 for ; Sun, 16 Sep 2018 17:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eJH11aBb5GlguuXS0xBxC+fzG4Kc/S3a2ZBQ9aPxUZQ=; b=KvmAE2K1QPiVuM0vacAsHLFyQN0Yg3RlgWSBKLvPjztxElR5VxAbIyg96z2S6a9zNM QsOsvLhGc9v0dguuCHLkUiiT6RbniOu0NPl56r94CnhrzwD92zDdqNKLUJFUUABcvNac rYe5EpXv69pnU5yMECXbjyoLaKlc/Uniq8j4Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eJH11aBb5GlguuXS0xBxC+fzG4Kc/S3a2ZBQ9aPxUZQ=; b=ihHCLZNoCqEZDCjhWeEE4xHFTcJg7U583ZBg5aY8C1FS7gYRh6hJXjcXx/TmrPt+de C2Lnyoc+Xh/R06u/HgmmE+0aIgtP+K+TfKekWzd1oKCPHu9y42DxCLrSSmqg7Jenbnj+ KwzN7toMCDef8Y2CXR51qmhTk+OGxRcs2PksE/VN3HtG2UOhfTYPWMY3JyiT+8vyOux5 adBtzoRyIFFbU74kGdfD9RzqGh/CiC+0BzJ8Pp0uT5tjfKDf9+jJvr9IyvEur0YAYPv0 5fjvnmxYCdwDFNfRYNn/l3TW0JrH/IuzHmo7q3jJI9+Qfas5Ms6jSyePxpK9vOCyGtX+ QIaA== X-Gm-Message-State: APzg51ASsTN3dtUPe96BnmEv7kv61xATavbRW/ONF/AoV3FLDUVia8gM 7h8eH95eg44NeqNR7VwzDlFC9Q== X-Google-Smtp-Source: ANB0VdY3Ug7+qHV9HRxeHemw1MsUahz7XN0r0zw1Kzw6eD8ZEEn3EEmKwZsj+pxfo4GkJNUcsX78Ww== X-Received: by 2002:a24:1d52:: with SMTP id 79-v6mr10305796itj.142.1537145898993; Sun, 16 Sep 2018 17:58:18 -0700 (PDT) Received: from localhost.localdomain ([209.82.80.116]) by smtp.gmail.com with ESMTPSA id f64-v6sm829972ite.4.2018.09.16.17.58.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Sep 2018 17:58:18 -0700 (PDT) From: srinivas.kandagatla@linaro.org To: lee.jones@linaro.org, robh+dt@kernel.org, broonie@kernel.org Date: Sun, 16 Sep 2018 17:57:26 -0700 Message-Id: <20180917005727.32728-14-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180917005727.32728-1-srinivas.kandagatla@linaro.org> References: <20180917005727.32728-1-srinivas.kandagatla@linaro.org> Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, bgoswami@codeaurora.org, lgirdwood@gmail.com, linux-kernel@vger.kernel.org, vkoul@kernel.org, Srinivas Kandagatla Subject: [alsa-devel] [PATCH v4 13/14] ASoC: apq8096: add headset JACK support 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 From: Srinivas Kandagatla Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/apq8096.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/sound/soc/qcom/apq8096.c b/sound/soc/qcom/apq8096.c index 66a28c2..daad43f 100644 --- a/sound/soc/qcom/apq8096.c +++ b/sound/soc/qcom/apq8096.c @@ -5,14 +5,21 @@ #include #include #include +#include #include #include +#include #include "common.h" #define SLIM_MAX_TX_PORTS 16 #define SLIM_MAX_RX_PORTS 16 #define WCD9335_DEFAULT_MCLK_RATE 9600000 +struct apq8096_card_data { + struct snd_soc_jack jack; + bool jack_setup; +}; + static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { @@ -68,6 +75,7 @@ static struct snd_soc_ops apq8096_ops = { static int apq8096_init(struct snd_soc_pcm_runtime *rtd) { struct snd_soc_dai *codec_dai = rtd->codec_dai; + struct apq8096_card_data *data = snd_soc_card_get_drvdata(rtd->card); /* * Codec SLIMBUS configuration @@ -80,6 +88,8 @@ static int apq8096_init(struct snd_soc_pcm_runtime *rtd) unsigned int tx_ch[SLIM_MAX_TX_PORTS] = {128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143}; + struct snd_soc_card *card = rtd->card; + int rval; snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch), tx_ch, ARRAY_SIZE(rx_ch), rx_ch); @@ -87,6 +97,38 @@ static int apq8096_init(struct snd_soc_pcm_runtime *rtd) snd_soc_dai_set_sysclk(codec_dai, 0, WCD9335_DEFAULT_MCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK); + if (!data->jack_setup) { + struct snd_jack *jack; + + rval = snd_soc_card_jack_new(card, "Headset Jack", + SND_JACK_HEADSET | + SND_JACK_HEADPHONE | + SND_JACK_BTN_0 | SND_JACK_BTN_1 | + SND_JACK_BTN_2 | SND_JACK_BTN_3 | + SND_JACK_BTN_4, + &data->jack, NULL, 0); + + if (rval < 0) { + dev_err(card->dev, "Unable to add Headphone Jack\n"); + return rval; + } + + jack = data->jack.jack; + + snd_jack_set_key(jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); + snd_jack_set_key(jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); + snd_jack_set_key(jack, SND_JACK_BTN_2, KEY_VOLUMEUP); + snd_jack_set_key(jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); + data->jack_setup = true; + } + + rval = snd_soc_component_set_jack(codec_dai->component, + &data->jack, NULL); + if (rval != 0 && rval != -ENOTSUPP) { + dev_warn(card->dev, "Failed to set jack: %d\n", rval); + return rval; + } + return 0; } @@ -107,6 +149,7 @@ static void apq8096_add_be_ops(struct snd_soc_card *card) static int apq8096_platform_probe(struct platform_device *pdev) { + struct apq8096_card_data *data; struct snd_soc_card *card; struct device *dev = &pdev->dev; int ret; @@ -115,8 +158,15 @@ static int apq8096_platform_probe(struct platform_device *pdev) if (!card) return -ENOMEM; + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) { + kfree(card); + return -ENOMEM; + } + card->dev = dev; dev_set_drvdata(dev, card); + snd_soc_card_set_drvdata(card, data); ret = qcom_snd_parse_of(card); if (ret) { dev_err(dev, "Error parsing OF data\n"); @@ -134,16 +184,19 @@ static int apq8096_platform_probe(struct platform_device *pdev) kfree(card->dai_link); err: kfree(card); + kfree(data); return ret; } static int apq8096_platform_remove(struct platform_device *pdev) { struct snd_soc_card *card = dev_get_drvdata(&pdev->dev); + struct apq8096_card_data *data = snd_soc_card_get_drvdata(card); snd_soc_unregister_card(card); kfree(card->dai_link); kfree(card); + kfree(data); return 0; }