Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp400543pxb; Tue, 3 Nov 2020 02:36:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8jJk+sXTJ6NlNsV8Ww/8+wpWAGuV+N4UiTpoQjn73B9LT3nBco0K6+OTT5D27PB/zs+WF X-Received: by 2002:a17:906:a108:: with SMTP id t8mr1857267ejy.435.1604399765231; Tue, 03 Nov 2020 02:36:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604399765; cv=none; d=google.com; s=arc-20160816; b=AKhimn8hOn9rk0rT5saOFDq06IJvBhwY/+PawoT+tveI22HuZ6YdYJBNEVCJI8g9OE 3REovxZyH82I3jD8i1L75ipqo9ArjJ3y0KwuGBRVti+fjQ0QZxLyDGEOHBcM+AefCBXe fSGiswynhQM2PawtxKSD1VAaadYG6w56hMolpTDc3XwkA7VCvjar7X5td7jxU2Q+jG17 zs1Un/OpRcwoLhSorQOvsps0BEgzNA/PWLtE7P6hN3pOPD8fXVmrZzfrCUI/IrvQXoIN a/hbX6/SsVlFJLE/quI96+/A7/ASQuTm96mDXdtSAG4OWAMO9ut1i3MGBiI8+UqR+iVt qQTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bCp02/KdQKO37j/RsLXZ8/YoseoQ3xQo6vzDe5cyZuo=; b=BM3iH8F6KoOcWnsvIQDe8v0xS5lYDHylBsyyW8MKty6RVVJICs21HBRL2M0t+Ek8e0 KgHPg34zNy9YAUB+3kLu8AI5mIKLKz/OeiC0JiD4wPpwNx5ePx2l1rTf+ZxjrLIxbEGq yvQdtn2zv8Uur52pI6vACh11pT6WyfUu7oaobWBEsutXShUs9TBKAN5Jdf7LnwtVEK9y m4HcLfFH413Dp//A9W+Ehy7ni9i90w/uI7ckTb2MtlksQaREl8Nx9/JXh/UNyGCjhk/7 4sNeVseCr4I4ic1EfqX/ZcjBW8doFipTlbPS7bqlHjpsLi/v+zAR3dW5QiWW9NM7Xacz wRGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Zseu6A+s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t24si835278ejy.689.2020.11.03.02.35.41; Tue, 03 Nov 2020 02:36:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Zseu6A+s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728179AbgKCKbj (ORCPT + 99 others); Tue, 3 Nov 2020 05:31:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728166AbgKCKbd (ORCPT ); Tue, 3 Nov 2020 05:31:33 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69026C0613D1; Tue, 3 Nov 2020 02:31:32 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id a200so13795932pfa.10; Tue, 03 Nov 2020 02:31:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bCp02/KdQKO37j/RsLXZ8/YoseoQ3xQo6vzDe5cyZuo=; b=Zseu6A+sUJ9lasjDV8hiHRl/01jz3L9WFs+HVKMDzDzI+vPXIKxxMcds1hZxm4hPSV 9Xw+QXdOdhDVZju7eKD4SG3bHwGjoe9mGuddKbZnft2KSlsw9rofcXV735EQ0J9QDs5m GeRAf5Ofbmol44mTTQdFrK8pF384e1Ha0VMc9fmwlIyi+BWGVyKYSN/uKrkewvPRr4c0 ZLaKXkMi89YhHqNDp1Eg56WA4wcA9Ff6CbMCGg42jcSXGhtL6whf0Bz9G4xgJAeURT3o WJ8cC4GAtE8icVF+kdIqOuRkqa96C84RfxLtHp7Sz9gl3e/uuCU5NqYbJ0cwpJgwwcFq nejA== 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=bCp02/KdQKO37j/RsLXZ8/YoseoQ3xQo6vzDe5cyZuo=; b=EDinkdJGceiZsVHhI1UJZ9ZZWToHroDHa8jbMll1cMPJv95aCcgmVz+YtjQ6ESrXk1 G8xU7cx0qhAo4o4Xo+Gx5A1iNvMl6vpIemPYR1mZK3DgA5GP7AdEv+6jnSzR1B4W9u0W 7pL5zrtbRsYF+wSzm1l/ErpRFJN1Y9WCyNVQmNy31i5E/UShXTpeVnAe92G+p4B7/imh Csh6OKa+L7dKB1te/O/XHttQi2w1+h7h6MBtCb0niTUzu0AQRwSSuDcWnW+t/Dq+Csyd /0fI4ujM4n3+3XtPE0CPfz7Oaqj9ah3ooqjynIFavAvLet9y3zXT37PJVe84kFndLkwB B1NA== X-Gm-Message-State: AOAM532LoYW0EIIy2WCjcME4jQU0eVqG0FoBevRpp/8iUUWoxXG8Gfv6 guwITK5OJ5WJHJZhH/7azRrJJOHIH4byYA== X-Received: by 2002:a17:90a:db18:: with SMTP id g24mr639271pjv.175.1604399491785; Tue, 03 Nov 2020 02:31:31 -0800 (PST) Received: from localhost (114-34-18-97.HINET-IP.hinet.net. [114.34.18.97]) by smtp.gmail.com with ESMTPSA id a25sm2553668pfg.138.2020.11.03.02.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 02:31:31 -0800 (PST) From: Ajye Huang X-Google-Original-From: Ajye Huang To: linux-kernel@vger.kernel.org Cc: Mark Brown , Rohit kumar , Banajit Goswami , Patrick Lai , Srinivasa Rao Mandadapu , srinivas.kandagatla@linaro.org, Andy Gross , Bjorn Andersson , Liam Girdwood , Rob Herring , Jaroslav Kysela , cychiang@chromium.org, tzungbi@chromium.org, dianders@chromium.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Ajye Huang , Tzung-Bi Shih Subject: [PATCH v5 2/2] ASoC: qcom: sc7180: Modify machine driver for 2mic Date: Tue, 3 Nov 2020 18:30:51 +0800 Message-Id: <20201103103051.34553-3-ajye_huang@compal.corp-partner.google.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103103051.34553-1-ajye_huang@compal.corp-partner.google.com> References: <20201103103051.34553-1-ajye_huang@compal.corp-partner.google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In addition, having mixer control to switch between DMICs by using "dmic-gpios" property. Refer to this one as an example, commit b7a742cff3f6 ("ASoC: AMD: Use mixer control to switch between DMICs") Signed-off-by: Ajye Huang Reviewed-by: Tzung-Bi Shih --- sound/soc/qcom/sc7180.c | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c index b391f64c3a80..455d3f2b8ce8 100644 --- a/sound/soc/qcom/sc7180.c +++ b/sound/soc/qcom/sc7180.c @@ -5,6 +5,8 @@ // sc7180.c -- ALSA SoC Machine driver for SC7180 #include +#include +#include #include #include #include @@ -28,6 +30,8 @@ struct sc7180_snd_data { u32 pri_mi2s_clk_count; struct snd_soc_jack hs_jack; struct snd_soc_jack hdmi_jack; + struct gpio_desc *dmic_sel; + int dmic_switch; }; static void sc7180_jack_free(struct snd_jack *jack) @@ -169,6 +173,27 @@ static int sc7180_snd_startup(struct snd_pcm_substream *substream) return 0; } +static int dmic_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct sc7180_snd_data *data = snd_soc_card_get_drvdata(dapm->card); + + ucontrol->value.integer.value[0] = data->dmic_switch; + return 0; +} + +static int dmic_set(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct sc7180_snd_data *data = snd_soc_card_get_drvdata(dapm->card); + + data->dmic_switch = ucontrol->value.integer.value[0]; + gpiod_set_value(data->dmic_sel, data->dmic_switch); + return 0; +} + static void sc7180_snd_shutdown(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; @@ -206,6 +231,30 @@ static const struct snd_soc_dapm_widget sc7180_snd_widgets[] = { SND_SOC_DAPM_MIC("Headset Mic", NULL), }; +static const char * const dmic_mux_text[] = { + "Front Mic", + "Rear Mic", +}; + +static SOC_ENUM_SINGLE_DECL(sc7180_dmic_enum, + SND_SOC_NOPM, 0, dmic_mux_text); + +static const struct snd_kcontrol_new sc7180_dmic_mux_control = + SOC_DAPM_ENUM_EXT("DMIC Select Mux", sc7180_dmic_enum, + dmic_get, dmic_set); + +static const struct snd_soc_dapm_widget sc7180_snd_dual_mic_widgets[] = { + SND_SOC_DAPM_HP("Headphone Jack", NULL), + SND_SOC_DAPM_MIC("Headset Mic", NULL), + SND_SOC_DAPM_MIC("DMIC", NULL), + SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, &sc7180_dmic_mux_control), +}; + +static const struct snd_soc_dapm_route sc7180_snd_dual_mic_audio_route[] = { + {"Dmic Mux", "Front Mic", "DMIC"}, + {"Dmic Mux", "Rear Mic", "DMIC"}, +}; + static void sc7180_add_ops(struct snd_soc_card *card) { struct snd_soc_dai_link *link; @@ -238,6 +287,18 @@ static int sc7180_snd_platform_probe(struct platform_device *pdev) card->dapm_widgets = sc7180_snd_widgets; card->num_dapm_widgets = ARRAY_SIZE(sc7180_snd_widgets); + if (of_property_read_bool(dev->of_node, "dmic-gpios")) { + card->dapm_widgets = sc7180_snd_dual_mic_widgets, + card->num_dapm_widgets = ARRAY_SIZE(sc7180_snd_dual_mic_widgets), + card->dapm_routes = sc7180_snd_dual_mic_audio_route, + card->num_dapm_routes = ARRAY_SIZE(sc7180_snd_dual_mic_audio_route), + data->dmic_sel = devm_gpiod_get(&pdev->dev, "dmic", GPIOD_OUT_LOW); + if (IS_ERR(data->dmic_sel)) { + dev_err(&pdev->dev, "DMIC gpio failed err=%ld\n", PTR_ERR(data->dmic_sel)); + return PTR_ERR(data->dmic_sel); + } + } + ret = qcom_snd_parse_of(card); if (ret) return ret; -- 2.25.1