Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3085702pxx; Sun, 1 Nov 2020 22:26:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwT2D7T27bgw4sl3WnJWt8v10KjDj7SClAM3wCQz0WpFDL8e93ZiKc7EetC0GWspR3wH/PY X-Received: by 2002:a50:e789:: with SMTP id b9mr14897588edn.272.1604298407970; Sun, 01 Nov 2020 22:26:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604298407; cv=none; d=google.com; s=arc-20160816; b=QvW977nVZyERJqOZALTbsLBIbzviUdwpk+zdIdM1XdprYWLOXJi9GvbOHE0frpD5i8 j+A858eQ5h07QD9BdcE87Rh4C2dMTG2UKh2fj2Ga71rjKVTeoa6DG1v2aEoMtEoVpM4F wAAO0VqmK+xhzVXD2QlrkRF3UYney8576bvd47L7kSPaWrQmYG7NDzxmjpK9hPiOvcCO wxrVzEZisXMoKJYhpACFXwjYdx4UKISd8XjiqvSrV7CxXQ9xQJ/6Q8KAuLNyCF1AX89A WSvxbvmK68JmlMIpjBp2xyIOQXgELW/8xo2u/Jdhx9bVO9baHSCTcSjX4BJvLATzGkUZ WiSQ== 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=MAJnFss+8YqpgdzXd2h0YDHLM++nuYC1QpV+6xW1bs0=; b=ucGLvWbgHZjYM7Irz0+7FbqvXpg3DapW6nSTe3jKKnNf/up1+yzT606zL9MrHdKFeX FkwCXx3YCySydbIJo8QKI8NU4evSkVUe1f9QmvffiDX9UEEmBwbyK/Xi7R3CmQ0Zy0Iw xLK5tlcBaCC8LYr1SDYaQ+MuofJfZYZpZnYtwEdDM+XDkZUHwDkdRWxsa/kOpVO5OEyU veX8PNb0mjUDCqQ7Jm4FXRpjomQsINZBEFmspGrvovHHuue4su0uMBOlgFT2J+y7JTQ5 Et4zEoGTu4mnj4ADDRO4DJBebjcEYFzXYIEvV+d6Vj53kitNrEDktNmFWlHdFsHeTVFz CIzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BJJtCf2D; 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 t12si14218961edc.298.2020.11.01.22.26.25; Sun, 01 Nov 2020 22:26:47 -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=BJJtCf2D; 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 S1728002AbgKBGYb (ORCPT + 99 others); Mon, 2 Nov 2020 01:24:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727826AbgKBGYa (ORCPT ); Mon, 2 Nov 2020 01:24:30 -0500 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2BF0C0617A6; Sun, 1 Nov 2020 22:24:30 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id j5so6330922plk.7; Sun, 01 Nov 2020 22:24:30 -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=MAJnFss+8YqpgdzXd2h0YDHLM++nuYC1QpV+6xW1bs0=; b=BJJtCf2DTq9wwFtyTheu27SYm9gCalSl6N2TqhNR+aZK8vwS07NMFAa5erIUQdTKYx r25nq9XZnoPiCtbotUy5ZEPtwKATRhgWygvqImIEcV2d7kODHJQFUCJ/mrKbWkL2rJAZ R2qnfcnZP2ZzuiMqoZMG2Nkc/EhjHbz9Z2ODUtMhYp7QM5IW9KztuZPDLJWj40tbm87B JiSCh982cZkw7Rsa4hw5OmQVwkqtJUB3mOywU4st+LKDqePADz366LWb8so9B5OATqKA 7n0fe1sJYFJTLCSkFLV9cbPQ+XW9hOPukkpOChET9bG3sPYzsEconefvB49TYoz2KRkT BV2w== 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=MAJnFss+8YqpgdzXd2h0YDHLM++nuYC1QpV+6xW1bs0=; b=ewz+KbZXabICqIiSKhru0pH5UwJ6FA+S2cggzelBhgZWvQXfOjmqE1bQI3tJCiVxbM aK5KeQ/5tNls3s/l5MgUCC1v1QpDGRZY/w5ZtUrsaxQ45cKm84GJi+bt3f8k4gN4wZe1 ijoLGbhepHYdaR/yT2GuaLkBeur/yAbsArsTrqz4k46RZ+AvZa7EterVkFFme+jbE6gQ DTGxI5pWet47tEfmV7K4OIz6dl/6EVKtamz6OfdJoZdMAsyCf+NaT0sxsY9uH8b0dD/K YpbbLiwFp3jFhMUfJww9pDsSB0gVLXSFM/0sA70E9+Ch8gWTd7ym1bHsE6lZoMCt2TUo XtIg== X-Gm-Message-State: AOAM532+g1iOczfgB5ZxXIL/aEerHDEFDsqlrnucwuoHgyWwmkJTDYjS tMD7p5p0hvD+brxPsMvNHFZ+XIjp9H5KGA== X-Received: by 2002:a17:902:864b:b029:d3:ce46:2829 with SMTP id y11-20020a170902864bb02900d3ce462829mr20574853plt.16.1604298270218; Sun, 01 Nov 2020 22:24:30 -0800 (PST) Received: from localhost (114-34-18-97.HINET-IP.hinet.net. [114.34.18.97]) by smtp.gmail.com with ESMTPSA id q8sm12197245pfg.118.2020.11.01.22.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2020 22:24:29 -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 Subject: [PATCH v3 2/2] ASoC: qcom: sc7180: Modify machine driver for 2mic Date: Mon, 2 Nov 2020 14:24:08 +0800 Message-Id: <20201102062408.331572-3-ajye_huang@compal.corp-partner.google.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201102062408.331572-1-ajye_huang@compal.corp-partner.google.com> References: <20201102062408.331572-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 | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/sound/soc/qcom/sc7180.c b/sound/soc/qcom/sc7180.c index b391f64c3a80..f86db7871999 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,30 @@ 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); + + if (data) + 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); + + if (data) { + 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 +234,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 +290,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), + 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=%d\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