From patchwork Fri Jan 5 20:39:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 10147039 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 4442C60155 for ; Fri, 5 Jan 2018 20:40:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC8DF287DE for ; Fri, 5 Jan 2018 20:40:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0F2828827; Fri, 5 Jan 2018 20:40:56 +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 CAAC3287DE for ; Fri, 5 Jan 2018 20:40:55 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 3C82A267AB5; Fri, 5 Jan 2018 21:40:53 +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 CC560267AB9; Fri, 5 Jan 2018 21:40:49 +0100 (CET) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by alsa0.perex.cz (Postfix) with ESMTP id B2224267AA9 for ; Fri, 5 Jan 2018 21:40:45 +0100 (CET) Received: by mail-pg0-f67.google.com with SMTP id c194so1427970pga.12 for ; Fri, 05 Jan 2018 12:40:45 -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=AHhNTMu6QKIXxAZ9enq9ceGNYR7LALbwd+bi/qZsUF0=; b=B2nt8D6KYPLQ+TEZJmm8ADFfLRmiXy8FhhPVbxIeyOtAIkkU9BMqm9ZZ3NHVUGyJoX OR7QqBqQvtm2OGbWOOKhMZIa+hLARpu4F+tvUDGHjNlF6Ju1ipb3Xmfeh7gsMCtgLmfx ZrEInfxjocpBEVoWbHfp67OUV/7RmlT4P7V+HFphtDQv1kIgo+L0k7JKf+6VIvFPc4AF WD+amaBCnQ+FF0TezZjbPgj2L9GQyOPKfVKzjtbD2xP9CkICNl3Iq/HAugxNrqDkBOuj 1EDvGATgAspCsHvV6ukqlHuEEWs3vAzjRotXVCPLhYxy+PUqeI8YL+hewnm1jDgF33wt yWBg== X-Gm-Message-State: AKGB3mJJINQ1WWQWphdxUQ0w+pLvv2A1eU2zcgF53kB5ZssRoVutOl3t BfInG+aQ4jNyJJ73dREWm7/yEQ== X-Google-Smtp-Source: ACJfBouy5TzPWwuQCU8QqSRB6cHpAkGcRPgX2k0oaHVyJaRAG1dvcB8fI9dBDhcCSNnBwL/wUb56iA== X-Received: by 10.99.119.142 with SMTP id s136mr3474728pgc.108.1515184843607; Fri, 05 Jan 2018 12:40:43 -0800 (PST) Received: from mka.mtv.corp.google.com ([172.22.112.49]) by smtp.gmail.com with ESMTPSA id e12sm12755672pgu.81.2018.01.05.12.40.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Jan 2018 12:40:42 -0800 (PST) From: Matthias Kaehlcke To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Rob Herring , Mark Rutland Date: Fri, 5 Jan 2018 12:39:57 -0800 Message-Id: <20180105203957.184883-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 , Brian Norris , Arnaud Pouliquen , linux-kernel@vger.kernel.org, Matthias Kaehlcke , Dylan Reid , Bhumika Goyal Subject: [alsa-devel] [PATCH] ASoC: codecs: dmic: Make number of channels configurable 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. When specified this value overwrites the default channels_max value of 8 in the snd_soc_dai_driver struct of the codec. Signed-off-by: Matthias Kaehlcke Reviewed-by: Rob Herring Acked-by: Arnaud Pouliquen --- Documentation/devicetree/bindings/sound/dmic.txt | 2 ++ sound/soc/codecs/dmic.c | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) 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..c88f974ebe3e 100644 --- a/sound/soc/codecs/dmic.c +++ b/sound/soc/codecs/dmic.c @@ -107,8 +107,30 @@ static const struct snd_soc_codec_driver soc_dmic = { static int dmic_dev_probe(struct platform_device *pdev) { + int err; + u32 chans; + struct snd_soc_dai_driver *dai_drv = &dmic_dai; + + if (pdev->dev.of_node) { + err = of_property_read_u32(pdev->dev.of_node, "num-channels", &chans); + if (err && (err != -ENOENT)) + return err; + + if (!err) { + if (chans < 1 || chans > 8) + return -EINVAL; + + dai_drv = devm_kzalloc(&pdev->dev, sizeof(*dai_drv), GFP_KERNEL); + if (!dai_drv) + return -ENOMEM; + + memcpy(dai_drv, &dmic_dai, sizeof(*dai_drv)); + dai_drv->capture.channels_max = chans; + } + } + return snd_soc_register_codec(&pdev->dev, - &soc_dmic, &dmic_dai, 1); + &soc_dmic, dai_drv, 1); } static int dmic_dev_remove(struct platform_device *pdev)