Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp980068imu; Wed, 28 Nov 2018 02:42:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wki3Gbu29/1NmITS1dOqg5bbhNMge7DZRBll2247F2zSdJoWNO8L4lIQquwVgC94cAhZ0C X-Received: by 2002:a63:6782:: with SMTP id b124mr33111210pgc.151.1543401774262; Wed, 28 Nov 2018 02:42:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543401774; cv=none; d=google.com; s=arc-20160816; b=SF2xZYaTRv3RkgR4KaIJXi5rpqDzDpSeDIGDlRwzn9F9W6cAEyoK5Y/Aqsx14rvZKt o5+AUWtOj9orA5V1Ny+DaXapGVK1a/drBNhWXsvSkkHE0TNG2b8teNglfukLOVqXSRT/ a5EYr9r+Fz0WDB03ADiVrypBpAhYRdntaQ+bPoR1lZrBoU5vmEpvufU0LPJdQjysZg+b PBEzMDq1aaIuoOSza0/7GbB37afLjPwrzqTjw/MLB/f+rE4lEvz8ajG2yxKuQfCSMz4J Mgz4ZCn6gGjPY/1ReCq6TLKrHyR1B8jnUQ62smmhD9xVvW8uJbYZ4aWXhTAkgvsNSfLa v08Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1/yiL8MSzU0TPG6wYpvLbVxtNR5gac1eR3sg1WCS69w=; b=hF7Mlq+oE8cwoywKtNcLJ13a4GYh80EKgE6QD1VmPx1TR1/EJU2xWL8gR5gOUUEKCm JZyoeM7MABeheOJPhLT5FN0keOBdlefpQB0SIxeqbYTZr4k8sArCQXTsJjgCx9iBkC20 PMnyvvU/Y9w3TYqMrT42fUS3XRANBFmgse51HiTj4Gg78ShQdoONP8F9CLNzwNtQo7aK 8iPg5JEbtxF6n8IftMWUAWA2mcJLe1MVrc/LjmGtTI7zWC7n6WHhryeKxmUzm3neaQk/ SGBVs76+xQY/ET+kz8rt90Ca/3u7Nue2sZvoXGPtuzsvn9hhUDq1K5OHYUJnCVRsNele q+VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EjzPp3Vj; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16si6919976pfh.138.2018.11.28.02.42.39; Wed, 28 Nov 2018 02:42:54 -0800 (PST) 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=@chromium.org header.s=google header.b=EjzPp3Vj; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727819AbeK1UBt (ORCPT + 99 others); Wed, 28 Nov 2018 15:01:49 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45775 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727519AbeK1UBs (ORCPT ); Wed, 28 Nov 2018 15:01:48 -0500 Received: by mail-pl1-f194.google.com with SMTP id a14so17049546plm.12 for ; Wed, 28 Nov 2018 01:00:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1/yiL8MSzU0TPG6wYpvLbVxtNR5gac1eR3sg1WCS69w=; b=EjzPp3Vj30r+aaQN9fFDKU0gZUe9/1vuDU+RKl0wWU00nAvNfaC3TJvWo5Nmna3PSs xE7WoH6PslE7lzmfkgpryEhOtRGlKipQeTzAbsv/Z8PmOoFLK/0h1DfJTlGNjxmL0mfc FEhpKWckQEqqOGqnvyqNiH8P3Gcbx6W3PmYxs= 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:mime-version:content-transfer-encoding; bh=1/yiL8MSzU0TPG6wYpvLbVxtNR5gac1eR3sg1WCS69w=; b=Q/ogFW+V59Hxfoix/HYmHuwnL2/zFx6PUDaDjQPpujRutRaBQAm3CcYapWbx17mVVn pvGMO7S2GAOPhgQwRrLPUBaT1RCyMF01RhazjliAv29BcnF0z/vmA5u11gq+xZno4cAf C0hRk5HszG9e9bDjJegZ51XwT94XtR3yaRtVyDPYr/kXy3qduWrTTTGpwde6NOZa3UHG +MH/1Cz1GKOTp5+4IOk79JtSQFCbAPunzmX47YM9/+S+CW16iR0SHeO0dpDjr4Cb5ZgP HbvJ0fVxPS0wc91ftoAAKPu9rTA3BwwPqTPQBiRXj1SVazlpIStTBEdZ5Eepwt65P46e WbBg== X-Gm-Message-State: AA+aEWa4K+toxE1+K5vLbagjDYeNAXIEBy/KDcWxy5gNz+c/6dbBjY0Z bFLZ3EnRWVIE5LpfEb0jOMhj7udxmcE= X-Received: by 2002:a17:902:8d8e:: with SMTP id v14mr3527024plo.133.1543395654486; Wed, 28 Nov 2018 01:00:54 -0800 (PST) Received: from cychiang-z840.tpe.corp.google.com ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id i72sm11568607pfe.181.2018.11.28.01.00.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Nov 2018 01:00:53 -0800 (PST) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Cc: Mark Brown , alsa-devel@alsa-project.org, dgreid@chromium.org, tzungbi@chromium.org, Rohit kumar , Cheng-Yi Chiang Subject: [PATCH v2 2/5] ASoC: qcom: sdm845: Create and setup jack in init callback Date: Wed, 28 Nov 2018 17:00:34 +0800 Message-Id: <20181128090037.257359-2-cychiang@chromium.org> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-goog In-Reply-To: <20181128090037.257359-1-cychiang@chromium.org> References: <20181128090037.257359-1-cychiang@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a callback for init ops on dai_link to create and setup jack. Signed-off-by: Rohit kumar Signed-off-by: Cheng-Yi Chiang --- sound/soc/qcom/sdm845.c | 57 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c index 95d8d4422dae0..43c03f8e8cdc2 100644 --- a/sound/soc/qcom/sdm845.c +++ b/sound/soc/qcom/sdm845.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "common.h" #include "qdsp6/q6afe.h" @@ -17,6 +19,8 @@ #define MI2S_BCLK_RATE 1536000 struct sdm845_snd_data { + struct snd_soc_jack jack; + bool jack_setup; struct snd_soc_card *card; uint32_t pri_mi2s_clk_count; uint32_t sec_mi2s_clk_count; @@ -100,6 +104,54 @@ static int sdm845_snd_hw_params(struct snd_pcm_substream *substream, return ret; } +static int sdm845_dai_init(struct snd_soc_pcm_runtime *rtd) +{ + struct snd_soc_component *component; + struct snd_soc_dai_link *dai_link = rtd->dai_link; + struct snd_soc_card *card = rtd->card; + struct sdm845_snd_data *pdata = snd_soc_card_get_drvdata(card); + int i, rval; + + if (!pdata->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, + &pdata->jack, NULL, 0); + + if (rval < 0) { + dev_err(card->dev, "Unable to add Headphone Jack\n"); + return rval; + } + + jack = pdata->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); + pdata->jack_setup = true; + } + + for (i = 0 ; i < dai_link->num_codecs; i++) { + struct snd_soc_dai *dai = rtd->codec_dais[i]; + + component = dai->component; + rval = snd_soc_component_set_jack( + component, &pdata->jack, NULL); + if (rval != 0 && rval != -ENOTSUPP) { + dev_warn(card->dev, "Failed to set jack: %d\n", rval); + return rval; + } + } + + return 0; +} + + static int sdm845_snd_startup(struct snd_pcm_substream *substream) { unsigned int fmt = SND_SOC_DAIFMT_CBS_CFS; @@ -220,7 +272,7 @@ static const struct snd_soc_dapm_widget sdm845_snd_widgets[] = { SND_SOC_DAPM_MIC("Int Mic", NULL), }; -static void sdm845_add_be_ops(struct snd_soc_card *card) +static void sdm845_add_ops(struct snd_soc_card *card) { struct snd_soc_dai_link *link; int i; @@ -230,6 +282,7 @@ static void sdm845_add_be_ops(struct snd_soc_card *card) link->ops = &sdm845_be_ops; link->be_hw_params_fixup = sdm845_be_hw_params_fixup; } + link->init = sdm845_dai_init; } } @@ -264,7 +317,7 @@ static int sdm845_snd_platform_probe(struct platform_device *pdev) data->card = card; snd_soc_card_set_drvdata(card, data); - sdm845_add_be_ops(card); + sdm845_add_ops(card); ret = snd_soc_register_card(card); if (ret) { dev_err(dev, "Sound card registration failed\n"); -- 2.20.0.rc0.387.gc7a69e6b6c-goog