Received: by 10.223.185.116 with SMTP id b49csp1485528wrg; Wed, 14 Feb 2018 18:45:18 -0800 (PST) X-Google-Smtp-Source: AH8x226WaL/A1CaAeNJUKx8/VSG2IsCur5jtZg4buwbPzvnBufIZXdiGZWjePiA79ixAG34Q0NCu X-Received: by 10.101.72.199 with SMTP id o7mr913527pgs.303.1518662718513; Wed, 14 Feb 2018 18:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518662718; cv=none; d=google.com; s=arc-20160816; b=vazMUE8/jX9Zvb7QzsdwQWrXjYB46pcYqxR37pyuZKVAj533x6ObXnLJriSTKm1M7L e/PopVC1dI5Au8ZfJRYqNraOIIpmXaxyzEeb5aqKvs9oTnVIWKc+MYUFhjoAhSJDo8rG ZvZkTYJCrNcvgHuAtufcI+WKuGJHBqjeZdwcs4wQlmKwFoImRbEICKqbHSKXLdq9K5Zq BHxPh3Gh4eCaNM5Ris0OU4iS4P3//kVFxl9yH2g8PhJVhfs+AC9bQmVTxUf3d1bVhM0R LLFIj1/qkSvuZLOk8nF92f03uuDBrIMGcxjcanD2FpXSEu/rnj3sFbwa4GCjiK1HTDBE zvNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=3O69GpGPIWfbyI2K2ByKW32wuyyFgDsnVlH8QxehDf8=; b=ZWe62oM2nDLmH38uhOcZCb1PXcOsLQ2Z2hoCLEiLVyKuWFNUCagfOuyOHhlB1nZcF7 kgBkcX6Soje3oRODXL3FhysxsQ8XtRDMTbwMJDQFsIQIShrzm0ehoJDluJXCoGZ5KLzM ECsylKSqq+IUtaz4e3sU3Pl1SMverVOapwzSszfvi6UXXR4yy71ZH8/rOnqElChmripI XCDyHDrp8wuR+3X8QCP8cSPS/dWwMvCipk1pwqox7xvvsEoEOed+PxNVNjW/XT4GCkMZ 3Bos2PGtQvZt2i2vfVD5WwHWUkW/plidrlpJw+9tNymqljZHRkwcsLqP0DHH85Y/FOLd ayRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MJDahh4L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x33-v6si399473plb.477.2018.02.14.18.45.03; Wed, 14 Feb 2018 18:45:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MJDahh4L; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032636AbeBOCo0 (ORCPT + 99 others); Wed, 14 Feb 2018 21:44:26 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:35584 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032483AbeBOCoY (ORCPT ); Wed, 14 Feb 2018 21:44:24 -0500 Received: by mail-pl0-f67.google.com with SMTP id bb3so265608plb.2 for ; Wed, 14 Feb 2018 18:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=3O69GpGPIWfbyI2K2ByKW32wuyyFgDsnVlH8QxehDf8=; b=MJDahh4LvjagOYoF9jdN8R4hHu5ADJmg+mBKQu5H33i3iIAmoEjkBip0FahhuVpb9/ 7QfKo2jNbATdeVEOjk6EEGfmsbo28Gr1kctz3crYmTbVNVn+hMjAeFmO3A8qqmEzl9q7 T+twVn8p6uJLmeMm6xq8yTuvRcTyJ9PjhgIEE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=3O69GpGPIWfbyI2K2ByKW32wuyyFgDsnVlH8QxehDf8=; b=V+fH24tGCT+s2VMGaZ8HSNtiqKGFyLDrMSSVTBC9yLS/RhNofwTN+R//mJVdUsKguT uRxGBwzR9C8jhFIoZpWI8tH80gSchB4gIr0UU4oYDm+bIPD9S/KhvRzQrpnDQD/qNxQ6 7PgAXd9fAO2W3X2biDRg4pqgYrjwvg+tj6bnVN9nrA3TmHNSXY5zyAjbGIblacATi9EZ SYK8xG3FcyqyUnvO5RudbuznZY5eZ4Zg1QW/pqoZsvhWGZgmmx56tAHQeWJyvTS9hY9x x59IMxm2PbVWEbL3gTucYgqv99tkviUX27tMN18q1pcMSdKUn6WVONKwCEPPRyQxOgE+ hI5w== X-Gm-Message-State: APf1xPBDfR6CcCCMGyV+CMPaX8aNudnccOg45pwSXvxuCmShVtIZhoYO qHOSdt4NzV/MoZue6Yrsr57A2w== X-Received: by 2002:a17:902:2881:: with SMTP id f1-v6mr1018073plb.439.1518662663555; Wed, 14 Feb 2018 18:44:23 -0800 (PST) Received: from localhost ([2620:0:1000:1501:9f72:a769:d80e:13c2]) by smtp.gmail.com with ESMTPSA id t3sm10284440pfl.116.2018.02.14.18.44.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Feb 2018 18:44:23 -0800 (PST) Date: Wed, 14 Feb 2018 18:44:22 -0800 From: Matthias Kaehlcke To: Brian Norris Cc: Liam Girdwood , Mark Brown , Rob Herring , Mark Rutland , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Dylan Reid , huang lin Subject: Re: [PATCH] ASoC: dmic: Add optional wakeup delay Message-ID: <20180215024422.GA99727@google.com> References: <20180214235156.81589-1-mka@chromium.org> <20180215002253.GA12697@rodete-desktop-imager.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180215002253.GA12697@rodete-desktop-imager.corp.google.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org El Wed, Feb 14, 2018 at 04:22:54PM -0800 Brian Norris ha dit: > Hi Matthias, > > On Wed, Feb 14, 2018 at 03:51:56PM -0800, Matthias Kaehlcke wrote: > > On some systems a delay is needed after switching on the clocks, to allow > > the DMIC output to stabilize and avoid a popping noise at the beginning > > of the recording. Add the optional device tree property 'wakeup-delay-ms' > > and apply the specified delay in the new dmic_daiops_prepare(). > > > > Signed-off-by: Matthias Kaehlcke > > --- > > .../devicetree/bindings/sound/dmic.txt | 2 + > > sound/soc/codecs/dmic.c | 54 ++++++++++++++----- > > 2 files changed, 42 insertions(+), 14 deletions(-) > > > > diff --git a/Documentation/devicetree/bindings/sound/dmic.txt b/Documentation/devicetree/bindings/sound/dmic.txt > > index 54c8ef6498a8..de741c6609d0 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 > > + - wakeup-delay-ms: Delay (in ms) after enabling the DMIC > > > > Example node: > > > > dmic_codec: dmic@0 { > > compatible = "dmic-codec"; > > dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>; > > + wakeup-delay-ms <50>; > > }; > > diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c > > index b88a1ee66f80..11f6abf11074 100644 > > --- a/sound/soc/codecs/dmic.c > > +++ b/sound/soc/codecs/dmic.c > > @@ -19,6 +19,7 @@ > > * > > */ > > > > +#include > > #include > > #include > > #include > > @@ -29,24 +30,38 @@ > > #include > > #include > > > > +struct dmic { > > + struct gpio_desc *gpio_en; > > + int wakeup_delay; > > +}; > > + > > +static int dmic_daiops_prepare(struct snd_pcm_substream *substream, > > + struct snd_soc_dai *dai) > > +{ > > + struct dmic *dmic = snd_soc_dai_get_drvdata(dai); > > + > > + if (dmic->gpio_en) > > + gpiod_set_value(dmic->gpio_en, 1); > > + > > + if (dmic->wakeup_delay) > > + msleep(dmic->wakeup_delay); > > + > > + return 0; > > +} > > + > > 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->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); > > - 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; > > N00b question: are you sure this is legit? Is it possible to get > START/STOP/START (or similar) with no prepare() in between? To be honest I can't answer this question with authority and have to defer it to the experts. > > } > > > > @@ -54,6 +69,7 @@ static int dmic_daiops_trigger(struct snd_pcm_substream *substream, > > } > > > > static const struct snd_soc_dai_ops dmic_dai_ops = { > > + .prepare = dmic_daiops_prepare, > > .trigger = dmic_daiops_trigger, > > }; > > > > @@ -73,14 +89,24 @@ static struct snd_soc_dai_driver dmic_dai = { > > > > static int dmic_codec_probe(struct snd_soc_codec *codec) > > { > > - struct gpio_desc *dmic_en; > > + struct dmic *dmic; > > + int err; > > + > > + dmic = devm_kzalloc(codec->dev, sizeof(*dmic), GFP_KERNEL); > > + if (!dmic) > > + return -ENOMEM; > > + > > + dmic->gpio_en = devm_gpiod_get_optional(codec->dev, > > + "dmicen", GPIOD_OUT_LOW); > > + if (IS_ERR(dmic->gpio_en)) > > + return PTR_ERR(dmic->gpio_en); > > > > - dmic_en = devm_gpiod_get_optional(codec->dev, > > - "dmicen", GPIOD_OUT_LOW); > > - if (IS_ERR(dmic_en)) > > - return PTR_ERR(dmic_en); > > + err = device_property_read_u32(codec->dev, "wakeup-delay-ms", > > + &dmic->wakeup_delay); > > + if (err && (err != -EINVAL)) > > You really want to be strict about error codes? What about -ENXIO ("no > suitable firmware interface is present")? Seems like we should ignore > that one too. > > In practice, it looks like many drivers that are reading optional > properties like this just tend to ignore the return code entirely. Ok, let's follow the common practice for optional properties then. I'll update it in v2. Thanks Matthias > > + return err; > > > > - snd_soc_codec_set_drvdata(codec, dmic_en); > > + snd_soc_codec_set_drvdata(codec, dmic); > > > > return 0; > > }