From patchwork Wed Nov 28 09:00:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-yi Chiang X-Patchwork-Id: 10702091 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 5D377109C for ; Wed, 28 Nov 2018 09:01:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CCE82CE1C for ; Wed, 28 Nov 2018 09:01:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 412402CE37; Wed, 28 Nov 2018 09:01:04 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE 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 7EA102CE33 for ; Wed, 28 Nov 2018 09:01:03 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 81240267B0E; Wed, 28 Nov 2018 10:01:01 +0100 (CET) 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 54709267B0F; Wed, 28 Nov 2018 10:00:58 +0100 (CET) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by alsa0.perex.cz (Postfix) with ESMTP id 6470D267B0E for ; Wed, 28 Nov 2018 10:00:55 +0100 (CET) Received: by mail-pl1-f196.google.com with SMTP id p8so6782514plo.2 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=F+I3ifpWbVMgzelMrwHaNFg24GxF+h2LTdEohlxhF0IXOKnsPxPYAoZcFJHEG/8AOh 8P7D5NhScpBiMxts8BdhGqM3u0uT3ElKK9ifbNgbYvGu+NrQ9fP2jGQTj1UBCY8FqaXA L8eDkkO0o3sKWP+eNSqwuqDAEOXE/aDmTSnLLiqsj4O7l2dkUo97vfjn7SSFCOmREkEH TmBVU+lp+UstXY+XcSdzSCAiSf39Sh5dxUplgw1BjbUADWc3JVrJfDYyD6GlwyIMAndr fs6qWUz6cLVYZrYgAOhTvGeN5/4NNn0aQVMMWvzlkMTVUVBSvTd+1rG5hXPg7ioZwu70 Ytqw== X-Gm-Message-State: AA+aEWbkyNlyMDtkYQPsZG2/qLbmQObs2XQlvW0FBz5yvop91Lg24IE3 P8m/IH+OXW4nQuQTj0TFSW1buQ== X-Google-Smtp-Source: AFSGD/XiocVg9xvtj+pDwb2daqzCSNZlvID6QiPNZTmdLbOoIccPkgrIYlpypGJECd8e9HTLXPjMuw== 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 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 Cc: alsa-devel@alsa-project.org, tzungbi@chromium.org, Mark Brown , Rohit kumar , dgreid@chromium.org, Cheng-Yi Chiang Subject: [alsa-devel] [PATCH v2 2/5] ASoC: qcom: sdm845: Create and setup jack in init callback 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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");