From patchwork Thu Aug 17 02:24:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huang lin X-Patchwork-Id: 9904821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3E2B260231 for ; Thu, 17 Aug 2017 02:25:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28CFE288C4 for ; Thu, 17 Aug 2017 02:25:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D9F8289B8; Thu, 17 Aug 2017 02:25:12 +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=-1.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no 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 6A972288C4 for ; Thu, 17 Aug 2017 02:25:07 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 99BED2675BB; Thu, 17 Aug 2017 04:25:05 +0200 (CEST) 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 C601F2675BB; Thu, 17 Aug 2017 04:25:03 +0200 (CEST) Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by alsa0.perex.cz (Postfix) with ESMTP id 744AB266BF6 for ; Thu, 17 Aug 2017 04:25:00 +0200 (CEST) Received: by mail-pg0-f65.google.com with SMTP id t80so1224311pgb.2 for ; Wed, 16 Aug 2017 19:25:00 -0700 (PDT) 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; bh=9CB6cBvPTF1yBQn9+jHhitq1cw13XNfB93oQftnlwYc=; b=boVtnWBd7FKUkjERXFXW9UgRFOaDuRnQJzv03fR2dQqx/ewWRZ15Q9xqm32ynmmjSJ 16rFRI93QaoqQ4xJLVTIu91yMgCcI8k/AMEfyrbixlUrZzAJ1TfXg1pQNt9asY/UW1W8 H5M7zhSLS7YAozwlwwFCc5dkQz+MfajNBXsKgzr2sX4pVi8eVCd03pMN1zJ432T/4m5z yHCGGnZVapsduA1iXiTDCb3N6hBJlNP6lt3uQmU7z+pQZhvs95+vQgK8nPZ3dN7t6sab ReDYfNGyBr0X36Ye6+TRhu4o3Rx08Du+b7+xWHlUmva06rjUbMjHqRJBRKW9n8zKCuJ+ 5wcQ== X-Gm-Message-State: AHYfb5jxVC5qMy62fauPT5CS5SjKK0tZndD3dMxXFgCk5YWsTQU3tYLh bVWY7pyZQ30y8g== X-Received: by 10.98.71.142 with SMTP id p14mr3572805pfi.96.1502936699291; Wed, 16 Aug 2017 19:24:59 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id m3sm4356238pfg.16.2017.08.16.19.24.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Aug 2017 19:24:58 -0700 (PDT) From: Lin Huang To: broonie@kernel.org, arnaud.pouliquen@st.com, dgreif@chromium.org Date: Thu, 17 Aug 2017 10:24:44 +0800 Message-Id: <1502936685-24414-1-git-send-email-hl@rock-chips.com> X-Mailer: git-send-email 2.7.4 Cc: alsa-devel@alsa-project.org, dianders@chromium.org, huang lin , linux-kernel@vger.kernel.org, briannorris@chromium.org, tiwai@suse.com, lgirdwood@gmail.com, mka@chromium.org Subject: [alsa-devel] [PATCH v2 1/2] ASoC: codec: use enable pin to control dmic start and stop 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: huang lin on some board use enable pin to control dmic start and stop, so add this feature in dmic driver. Signed-off-by: Lin Huang --- sound/soc/codecs/Kconfig | 2 +- sound/soc/codecs/dmic.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 010811e..d98233b 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -71,7 +71,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_DA732X if I2C select SND_SOC_DA9055 if I2C select SND_SOC_DIO2125 - select SND_SOC_DMIC + select SND_SOC_DMIC if GPIOLIB select SND_SOC_ES8316 if I2C select SND_SOC_ES8328_SPI if SPI_MASTER select SND_SOC_ES8328_I2C if I2C diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c index 12e07f9..b88a1ee 100644 --- a/sound/soc/codecs/dmic.c +++ b/sound/soc/codecs/dmic.c @@ -19,6 +19,8 @@ * */ +#include +#include #include #include #include @@ -27,6 +29,34 @@ #include #include +static int dmic_daiops_trigger(struct snd_pcm_substream *substream, + int cmd, struct snd_soc_dai *dai) +{ + struct gpio_desc *dmic_en = snd_soc_dai_get_drvdata(dai); + + if (!dmic_en) + return 0; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + gpiod_set_value(dmic_en, 1); + break; + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + gpiod_set_value(dmic_en, 0); + break; + } + + return 0; +} + +static const struct snd_soc_dai_ops dmic_dai_ops = { + .trigger = dmic_daiops_trigger, +}; + static struct snd_soc_dai_driver dmic_dai = { .name = "dmic-hifi", .capture = { @@ -38,8 +68,23 @@ static struct snd_soc_dai_driver dmic_dai = { | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE, }, + .ops = &dmic_dai_ops, }; +static int dmic_codec_probe(struct snd_soc_codec *codec) +{ + struct gpio_desc *dmic_en; + + dmic_en = devm_gpiod_get_optional(codec->dev, + "dmicen", GPIOD_OUT_LOW); + if (IS_ERR(dmic_en)) + return PTR_ERR(dmic_en); + + snd_soc_codec_set_drvdata(codec, dmic_en); + + return 0; +} + static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = { SND_SOC_DAPM_AIF_OUT("DMIC AIF", "Capture", 0, SND_SOC_NOPM, 0, 0), @@ -51,6 +96,7 @@ static const struct snd_soc_dapm_route intercon[] = { }; static const struct snd_soc_codec_driver soc_dmic = { + .probe = dmic_codec_probe, .component_driver = { .dapm_widgets = dmic_dapm_widgets, .num_dapm_widgets = ARRAY_SIZE(dmic_dapm_widgets),