Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3411033imm; Sun, 16 Sep 2018 17:58:59 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda/xSPkpSBTcIG4V+iYH7FYO5cyX0pjN7Ifsdx9bN/jOw9JGSzAChdIqb1sLyMywJTBWqGq X-Received: by 2002:a62:5ec3:: with SMTP id s186-v6mr23667700pfb.146.1537145939662; Sun, 16 Sep 2018 17:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537145939; cv=none; d=google.com; s=arc-20160816; b=I1HfyYy4F52taRx1rLKrjRurKSNddQJ+NU7tvfluCDDY/WItnJzgtYqT5k7XAN8Ppp upzpJ/I//lO1TLjsk0UZIVzQqNJnPxkmxMbiUdtEN60dp8N5/wAIwE6lD5lFMeO313n3 RDxGjnJMLSv6YOi58Mf8NKNzV7upIGy4T5zeChpC5IYqV698NuBxJpY0tYc7d6atLMMe 4buycD5HwYawanZI3zneoTA8KEQJLYyznJrNS+BARB3djddv3iveLf0jHX5LCCtw2sFI LUcRBuZs96plRaYQKyPXYmddvCHI24rr657KuFD0KjwFiL/a+R5qLTxO38hQ84q3Px5P 7TVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=eJH11aBb5GlguuXS0xBxC+fzG4Kc/S3a2ZBQ9aPxUZQ=; b=SxuV4N16CyI2rMv+BXmuJBwco7EzvFwF36vbvB8mg5Nd/8lJZokvQSuUpT41WP0P40 NUNOjd3AJZ4ODyAPQnJNju0h7SWTyipm4/fH0IjxadDlia24JdeK5z3vNLlR12oy1VXY yDiVqp+7vdW5j73kRvTeadPSF2w+h/A55tLF7kN0tC/fVlpHCDgSswQVQ76YWUw+oaU+ a+FLm8oajEbaEyVWPdi1wDk+e8SeGxM+nYrtCG5osZtf3vKv9IGxBjJuxGc72OrqDLyM DICtcMukJa9t5G4BbyZedZ4YYcWVuRBWa/YxuOSFAxaW2FRBKZC6evCaUIWHgHXT3hfx Db1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KvmAE2K1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11-v6si14328576plg.237.2018.09.16.17.58.44; Sun, 16 Sep 2018 17:58:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KvmAE2K1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728533AbeIQGXN (ORCPT + 99 others); Mon, 17 Sep 2018 02:23:13 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:52587 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728511AbeIQGXM (ORCPT ); Mon, 17 Sep 2018 02:23:12 -0400 Received: by mail-it0-f66.google.com with SMTP id h3-v6so9079248ita.2 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=Dn1sabPXUa6rykGO3RscbuR6556Xc7JgkujftQcIVzMpfoa68ogIhDm9TkGvscNZIo 0XSkBI6G+oJqvq4l/DfmMdOmI9OFe7dyaXr8N6u7hUMuiai2kA/aNPOPFBmcf2Bo3WTb vsmKbXAxoi1V/FulKLfyH0PJXvpcq2op/vLn1grP6GnFIIRJwVFqYw0C9upnFwomJeWl vGISFaIvIdP2NsF/yMbKBY6wVmpnWlVU9sE9zmBzbWr+w3cStxB/k4tJZJnSnwbnCmdl DulSVbVnCeqzVh3aU4L4SiS6G3gRBNfGDwLJtinbo6HjveJ5FuOwtZryLKS4MpMcKGXO BNmQ== X-Gm-Message-State: APzg51BXPQu+84AIC17tYBW3jD5YT6ee2rXdiDza40PN93bTpYlLD8Mv vt56NE3tMkgxt3z+XjOtCkuleA== 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 Cc: mark.rutland@arm.com, lgirdwood@gmail.com, bgoswami@codeaurora.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, vkoul@kernel.org, alsa-devel@alsa-project.org, Srinivas Kandagatla Subject: [PATCH v4 13/14] ASoC: apq8096: add headset JACK support 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.9.3