From patchwork Thu Jan 4 19:48:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 10145599 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 521FC6034B for ; Thu, 4 Jan 2018 19:49:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4784028852 for ; Thu, 4 Jan 2018 19:49:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C60128854; Thu, 4 Jan 2018 19:49:23 +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.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=unavailable 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 A7AAD28852 for ; Thu, 4 Jan 2018 19:49:21 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 8334E267965; Thu, 4 Jan 2018 20:49:20 +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 7E5FC267967; Thu, 4 Jan 2018 20:49:19 +0100 (CET) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) by alsa0.perex.cz (Postfix) with ESMTP id A0A27267900 for ; Thu, 4 Jan 2018 20:49:17 +0100 (CET) Received: by mail-pl0-f66.google.com with SMTP id i6so1620706plt.13 for ; Thu, 04 Jan 2018 11:49:17 -0800 (PST) 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=SEXgF4hzyRFd1o2uRopAnDEa6V56XpXF/Dl6ljQdFyc=; b=CGxzfykb/gcEP81gGUGtdVukD6pegJqonvCCSP/sE9NjmiZJMzN/bTg+ZkmM4zsmve LUpqg9sNCisoyw0098jrfKp8iYp472/xGYEuaFKQrdw3hN9TJLU35EAYsw0jTthe+wQe aI3ThIevIPOCxmzAPUyxXb4v/XUvBATJKbY95DRiLDug8QswFEY5zsji1rdP+f2JcSw/ F0YhwlL4ig+Db9d5vH3/tm8sdlHKAOGTP1/UXCv5vBKnVUTRWLThxOB8RVBhuyNPSiq4 hSJE2DVyDDqmZ/lOgTHzSya93cAfIvC+YHfLxRxo5RYj9I4pZCqq/U6OuBvOMvK3ytTh OJGA== X-Gm-Message-State: AKGB3mIdadNeyPTsYsrpMuzkqHUTy3Go83o0tY+CzHM5PXMCnr8ZIBc/ mD0u1tdjxmSJTZ+6Q/0rwjz0/A== X-Google-Smtp-Source: ACJfBovVZW+fh/26/Mgg8McBFIae9P2v8bY25WqZI++4DHa/Dn0MYaKzZIOx+ssweoi37zrrTC+1lg== X-Received: by 10.124.25.3 with SMTP id c3mr613626plz.303.1515095356001; Thu, 04 Jan 2018 11:49:16 -0800 (PST) Received: from mka.mtv.corp.google.com ([172.22.112.49]) by smtp.gmail.com with ESMTPSA id o64sm1185938pga.1.2018.01.04.11.49.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Jan 2018 11:49:15 -0800 (PST) From: Matthias Kaehlcke To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Rob Herring , Mark Rutland Date: Thu, 4 Jan 2018 11:48:48 -0800 Message-Id: <20180104194848.198941-1-mka@chromium.org> X-Mailer: git-send-email 2.16.0.rc0.223.g4a4ac83678-goog Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, huang lin , Arnaud Pouliquen , linux-kernel@vger.kernel.org, Matthias Kaehlcke , Bhumika Goyal Subject: [alsa-devel] [PATCH] ASoC: codecs: dmic: Use channel map for configs with a single mic 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 The DMIC DAI driver specifies a number of 1 to 8 channels for each DAI. The actual number of mics can currently not be configured in the device tree or audio glue, but is derived from the min/max channels of the CPU and codec DAI. A typical CPU DAI has two or more channels, in consequence a single mic is treated as a stereo/multi channel device, even though only one channel carries audio data. This change adds the option to specify the number of used DMIC channels in the device tree. If a single channel is used we export a channel map that marks all unused channels as invalid to indicate userspace that the capture device is mono. Signed-off-by: Matthias Kaehlcke --- Documentation/devicetree/bindings/sound/dmic.txt | 2 + sound/soc/codecs/dmic.c | 72 +++++++++++++++++++++--- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/dmic.txt b/Documentation/devicetree/bindings/sound/dmic.txt index 54c8ef6498a8..f7bf65611453 100644 --- a/Documentation/devicetree/bindings/sound/dmic.txt +++ b/Documentation/devicetree/bindings/sound/dmic.txt @@ -7,10 +7,12 @@ Required properties: Optional properties: - dmicen-gpios: GPIO specifier for dmic to control start and stop + - num-channels: Number of microphones on this DAI Example node: dmic_codec: dmic@0 { compatible = "dmic-codec"; dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; + num-channels = <1>; }; diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c index b88a1ee66f80..c705a25b138e 100644 --- a/sound/soc/codecs/dmic.c +++ b/sound/soc/codecs/dmic.c @@ -29,24 +29,29 @@ #include #include +struct dmic { + struct gpio_desc *gpio_en; + int channels; +}; + 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); + struct dmic *dmic = snd_soc_dai_get_drvdata(dai); - if (!dmic_en) + if (!dmic || !dmic->gpio_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); + gpiod_set_value(dmic->gpio_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); + gpiod_set_value(dmic->gpio_en, 0); break; } @@ -57,6 +62,42 @@ static const struct snd_soc_dai_ops dmic_dai_ops = { .trigger = dmic_daiops_trigger, }; +const struct snd_pcm_chmap_elem dmic_chmaps_single[] = { + { .channels = 1, + .map = { SNDRV_CHMAP_MONO } }, + { .channels = 2, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_NA } }, + { .channels = 4, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_NA, + SNDRV_CHMAP_NA, SNDRV_CHMAP_NA } }, + { .channels = 6, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_NA, + SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, + SNDRV_CHMAP_NA, SNDRV_CHMAP_NA } }, + { .channels = 8, + .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_NA, + SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, + SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, + SNDRV_CHMAP_NA, SNDRV_CHMAP_NA } }, + { } +}; + +static int dmic_pcm_new(struct snd_soc_pcm_runtime *rtd, + struct snd_soc_dai *dai) +{ + struct dmic *dmic = snd_soc_dai_get_drvdata(dai); + int err; + + if (dmic->channels == 1) { + err = snd_pcm_add_chmap_ctls(rtd->pcm, SNDRV_PCM_STREAM_CAPTURE, + dmic_chmaps_single, 8, 0, NULL); + if (err < 0) + return err; + } + + return 0; +} + static struct snd_soc_dai_driver dmic_dai = { .name = "dmic-hifi", .capture = { @@ -69,18 +110,31 @@ static struct snd_soc_dai_driver dmic_dai = { | SNDRV_PCM_FMTBIT_S16_LE, }, .ops = &dmic_dai_ops, + .pcm_new = dmic_pcm_new, }; static int dmic_codec_probe(struct snd_soc_codec *codec) { - struct gpio_desc *dmic_en; + struct dmic *dmic; + int err; + u32 pval; + + dmic = devm_kzalloc(codec->dev, sizeof(*dmic), GFP_KERNEL); + if (!dmic) + return -ENOMEM; - dmic_en = devm_gpiod_get_optional(codec->dev, + dmic->gpio_en = devm_gpiod_get_optional(codec->dev, "dmicen", GPIOD_OUT_LOW); - if (IS_ERR(dmic_en)) - return PTR_ERR(dmic_en); + if (IS_ERR(dmic->gpio_en)) + return PTR_ERR(dmic->gpio_en); + + err = of_property_read_u32(codec->dev->of_node, "num-channels", &pval); + if (!err) + dmic->channels = (int)pval; + else if (err != -ENOENT) + return err; - snd_soc_codec_set_drvdata(codec, dmic_en); + snd_soc_codec_set_drvdata(codec, dmic); return 0; }