Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1075561pxx; Fri, 30 Oct 2020 01:00:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrY2lGI9QFkrJeO7YBBrw5k714SR+nEjisDCnQOAZF1WOnEVANcZnx5S+NWQZc9SfkQvpr X-Received: by 2002:a05:6402:1004:: with SMTP id c4mr980623edu.149.1604044811582; Fri, 30 Oct 2020 01:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604044811; cv=none; d=google.com; s=arc-20160816; b=riVYqvuMdnqpMobJ20PMYbZu0ilLOVwHR83uGYIzckiSID/8kOtJrYzEtviXOzCrCF aLy+EM4QUCyVxq0Sv0akDQ2WmaGprrDrLmFvbAJGFCKH88IfJycwglmy/OJZg3G3KL+7 3gMR2HY4A5Q+qvX/9k+NhxiJOINDxcAUKtNRgDCRRoxS5DEvfZOiRo9YG3rPMIUEWqrU UR3Wm3jXPxi4rkWbbiql9k9bXcbVB3BaQWOvpoNYIR2QvgJsisrumM3ito1haHcAC5P6 e/fX5QzpNza+hJW1ffC23S8ulp1h8gMRMDhQWTSq9Uli0fMbB+EVR907IFFs5YjcyjI4 TJTg== 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=PdodUo+6mcNMJwIz8HCiSd/BPrJxVSi77oUzRemdDVU=; b=UwxyDl7po11f1xc5xktabZbGex7YMDX2ydpDfH7lOpFDRlLdt5qnp25Ol/dAwicDO7 MJJrZcEqyFa2Pj8z/KKKZE/eBWzqMVK5FTopkKVGhkIqiyYFKDF78yJ615lGqOmGKvog 6k8A3LH44LZCLwyxt3yk/AbujbEHMuengX+rXH1pxgviizWHRg+U47Zz3fiJZRD+/Amz fYm3eI4ivqHLRAY5I8U9J8f5R05CbPIpyR3PXaJfBrfDtRGknh6cmiEufor1/chmXFjh QfvIxnPa/sHa1hId+kulx3wiuzMbMNm1naJXv6ObkpBdHTlaMr7Cf86H5scDdwkQcxlk tvwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tQoyLfsy; 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 r25si6129959edc.210.2020.10.30.00.59.48; Fri, 30 Oct 2020 01:00:11 -0700 (PDT) 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=tQoyLfsy; 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 S1726095AbgJ3H5r (ORCPT + 99 others); Fri, 30 Oct 2020 03:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbgJ3H5r (ORCPT ); Fri, 30 Oct 2020 03:57:47 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1042FC0613CF; Fri, 30 Oct 2020 00:57:47 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id i7so2596444pgh.6; Fri, 30 Oct 2020 00:57:47 -0700 (PDT) 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=PdodUo+6mcNMJwIz8HCiSd/BPrJxVSi77oUzRemdDVU=; b=tQoyLfsyZlXvHg2b1MunUYxzh17UMQmrrYCBspTbicI7tC8VuB0FbNbVRCUIuoZgxP 1yq7jk0/YnRMA1qLOLLJ4K6q/K/rVnEa5FPA1f3EZNExA37wdvy8GXHh/hnTjf+3xoGp ASskqvXt7SCPfELXlJD2UFCqwhnMLfug3Cf3j3x4TGYptej0TZEihb+wGLfcjlUHqAaf luQu9EQyaV3O0U99lydlXufUR6zUitfBX/J6h1B9u+zviLuN4raKOOG2oen2jJL679tt izRQwYT2zqLL7dpxhXb84uZ4gz0dE95sNod5mskV+/pkOk2k3bMYNu9Mv8rxrOZJWJT4 Vwgw== 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=PdodUo+6mcNMJwIz8HCiSd/BPrJxVSi77oUzRemdDVU=; b=RnifNdlvwjn/LECdKxw0i3czLhlUCO3yMOZe9CdbT/Okx2xxODYzIvRUis7NtIM+lI 8dJHtQnBtuD0q/bBQyJYElEkLUGyWuWWsHLm9DL+0zaNxw/rumdsTTLClwMGMpTwvaoJ LVt1ljf99VZs1YMhhz3QQY4wOMKqxUkBv8xJ0iKNXp7nXJSmzgLAKx0ZZzSw/+vPIDnD gGB8SHQAqeVh7EFplaeKpdU1qML0JvUi9ItLeMrlZpCZZ3npsjoOe6KIxHINr7nplyZk cTz/RRJhdltsCxm5tcJt3+5atAXPUK76HcooownQbcyt4CuzJEChaNt/yP6Kl93GogjR HU9Q== X-Gm-Message-State: AOAM531FTTboeIcI9zRJWf7hBjFWcQMPqmAWoan7axYQ7P0wlV/Io7mr lMX3+3pIChcTLwujSvFoI/BqNv2B6/t3gQ== X-Received: by 2002:aa7:96f6:0:b029:164:2def:5ef7 with SMTP id i22-20020aa796f60000b02901642def5ef7mr8009841pfq.44.1604044666400; Fri, 30 Oct 2020 00:57:46 -0700 (PDT) Received: from localhost (114-34-18-97.HINET-IP.hinet.net. [114.34.18.97]) by smtp.gmail.com with ESMTPSA id e4sm2388392pjg.44.2020.10.30.00.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 00:57:45 -0700 (PDT) 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 Subject: [PATCH v2 2/2] ASoC: qcom: sc7180: Modify machine driver for 2mic Date: Fri, 30 Oct 2020 15:57:24 +0800 Message-Id: <20201030075724.1616766-3-ajye_huang@compal.corp-partner.google.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201030075724.1616766-1-ajye_huang@compal.corp-partner.google.com> References: <20201030075724.1616766-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 --- sound/soc/qcom/sc7180.c | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c index b391f64c3a80..e9366bb5f3c2 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 @@ -23,6 +25,9 @@ #define DRIVER_NAME "SC7180" +static struct gpio_desc *dmic_sel; +static int dmic_switch; + struct sc7180_snd_data { struct snd_soc_card card; u32 pri_mi2s_clk_count; @@ -169,6 +174,23 @@ 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) +{ + ucontrol->value.integer.value[0] = dmic_switch; + return 0; +} + +static int dmic_set(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + if (dmic_sel) { + dmic_switch = ucontrol->value.integer.value[0]; + gpiod_set_value(dmic_sel, 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 +228,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 +284,19 @@ 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), + dmic_sel = devm_gpiod_get(&pdev->dev, "dmic", GPIOD_OUT_LOW); + if (IS_ERR(dmic_sel)) { + dev_err(&pdev->dev, "DMIC gpio failed err=%d\n", + PTR_ERR(dmic_sel)); + return PTR_ERR(dmic_sel); + } + } + ret = qcom_snd_parse_of(card); if (ret) return ret; -- 2.25.1