From patchwork Tue Sep 4 10:25:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 10587093 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 15867112B for ; Tue, 4 Sep 2018 10:55:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FF552896A for ; Tue, 4 Sep 2018 10:55:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02991291AF; Tue, 4 Sep 2018 10:55:10 +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 264872896A for ; Tue, 4 Sep 2018 10:55:10 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D7D4F26792E; Tue, 4 Sep 2018 12:28:09 +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 4DCF6267948; Tue, 4 Sep 2018 12:27:54 +0200 (CEST) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by alsa0.perex.cz (Postfix) with ESMTP id 72B0C2678FC for ; Tue, 4 Sep 2018 12:27:47 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id y2-v6so3831504wma.1 for ; Tue, 04 Sep 2018 03:27:47 -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=kDTb19RTWifFuLfVBk7DXBD9s0ll9MuJJWXgCHepOhA=; b=cN0YocF1mczPl6T85Z2jLVC4dfnPo63mU0ibDJE5hgsO97J42fCAolUQ/6dDWN50Ch h4hwPZFyi3+V+s62YfbVOkwnRGlVmhWn+dq5NP68XYv4L7k3Iisj85yxzo/B3p3Selj+ HJo5dhmS7ff+DEJhM6H7zaaM5KsbtCKKyoCPE= 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=kDTb19RTWifFuLfVBk7DXBD9s0ll9MuJJWXgCHepOhA=; b=YGyrP4oV0VhbFaT2Ed4Ibxg+T9q2LDtFOXCdSdEY5UPGlukOn3yDCxqM59fz0BfYRO JRkv6iY7w4k1HUrqj8Ev/IL+93EAFEo8Dbzzv9ORM5ByEwSXquP0fTDTkUjdBzBh1qe2 VeC/8qGI+JtuvdI8FZ0o+WjA9aNXQ1r9q8RCiBErHUiMdt9l4rUSOKrYA667KvJSlZdY bc9EZU+8DsoGkvkNipw9QlrKb5COIJStTVZ+5b7ciaveJXGilmIJZDJvq2EHmFyyeFOJ CWABFGBeDE7SxBO2Nk5kvw+ji/RAF/+49XQ1d/AiXr9FVV4UUp2OBUO/ckwH+/IyOwrZ pOsw== X-Gm-Message-State: APzg51Csdj6bCnd0aS4woYe8TvPftb2+ApD93ivVN1xZNhtL1yWC5rbM cYa4BIf/NkLe3Vf+CyyfPQdJiA== X-Google-Smtp-Source: ANB0VdbHER0gHLXRvnVqz/tuEFPWE8g9KcZ7ECVeVAFndTzOur4kaKUeGZy6cTitgqJCUR8OGFzQ8w== X-Received: by 2002:a1c:e70b:: with SMTP id e11-v6mr2081581wmh.22.1536056867016; Tue, 04 Sep 2018 03:27:47 -0700 (PDT) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id g129-v6sm16903325wmf.42.2018.09.04.03.27.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Sep 2018 03:27:46 -0700 (PDT) From: Srinivas Kandagatla To: lee.jones@linaro.org, robh+dt@kernel.org, broonie@kernel.org Date: Tue, 4 Sep 2018 11:25:00 +0100 Message-Id: <20180904102500.30318-14-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904102500.30318-1-srinivas.kandagatla@linaro.org> References: <20180904102500.30318-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 v3 13/13] 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 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 db07e9b62daf..78b245261477 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) { @@ -65,6 +72,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 @@ -77,6 +85,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); @@ -84,6 +94,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; } @@ -104,6 +146,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; @@ -112,8 +155,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"); @@ -131,16 +181,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; }