From patchwork Fri Oct 24 06:00:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Hsu X-Patchwork-Id: 39407 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CF8DD20341 for ; Fri, 24 Oct 2014 06:01:14 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf1385696lab.7 for ; Thu, 23 Oct 2014 23:01:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=6Wf/Qrye53dN7kM6zlB2RlkFxioGDo/I791qKogV8eE=; b=UHjMCG4F/5XRpjMN2M2n74vl8bWNubHOYxO8rGHR0MHQ8HDfU/aEw5OKdr9Kos8ETJ jk31sEoiNmDB4Zhsa9aeYL5ACQuHndOlBDn0AcJNW4RCW0nbFYK2U9O6JCEqRWAF40LX Ekil7EMtjYa4MzrDnZfLA1lUn7yGLfMF558ZLi+UHrgd+mBQnwpVR822pBpZLO+WPkih uiXk1y2jcLmMDdAIaaKA/omxLsYCwMsCFfcjF363OHhVPSe9g2B0TPuRsVTYWQV5SUzv mglx3CMC0xhPzhFgY9ZOeJR7uyleOtz0BV2OZkJR6blXW1EmJ1/opmb/MwNHbP04kAwu 4/8A== X-Gm-Message-State: ALoCoQlrfv/PEukIIJXe273xirGWxNIwMrIaT1g7NVn6d5majH1j3S9izWEAjs2gMPnsTGtnFOv1 X-Received: by 10.180.36.176 with SMTP id r16mr385476wij.7.1414130473664; Thu, 23 Oct 2014 23:01:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.10 with SMTP id m10ls404206laj.72.gmail; Thu, 23 Oct 2014 23:01:13 -0700 (PDT) X-Received: by 10.152.163.101 with SMTP id yh5mr2044136lab.68.1414130473514; Thu, 23 Oct 2014 23:01:13 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id x6si5421659lbo.81.2014.10.23.23.01.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Oct 2014 23:01:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id 10so2000253lbg.32 for ; Thu, 23 Oct 2014 23:01:13 -0700 (PDT) X-Received: by 10.152.120.199 with SMTP id le7mr1982357lab.67.1414130473434; Thu, 23 Oct 2014 23:01:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.84.229 with SMTP id c5csp374992lbz; Thu, 23 Oct 2014 23:01:12 -0700 (PDT) X-Received: by 10.68.57.205 with SMTP id k13mr2555897pbq.60.1414130471874; Thu, 23 Oct 2014 23:01:11 -0700 (PDT) Received: from Kraken ([124.219.7.128]) by mx.google.com with ESMTP id rh13si3461081pdb.36.2014.10.23.23.01.10 for ; Thu, 23 Oct 2014 23:01:11 -0700 (PDT) Received-SPF: temperror (google.com: error in processing during lookup of xavier@kraken: DNS timeout) client-ip=124.219.7.128; Received: by Kraken (Postfix, from userid 1011) id C416B6A27A9; Fri, 24 Oct 2014 14:01:00 +0800 (CST) From: Xavier Hsu To: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com, patches@linaro.org Cc: lars@metafoo.de, ckeepax@opensource.wolfsonmicro.com, Xavier Hsu , Andy Green Subject: [PATCHv5 6/9] ASOC: wm8971: add constraint for setting set_sysclk() Date: Fri, 24 Oct 2014 14:00:32 +0800 Message-Id: <1414130435-14183-6-git-send-email-xavier.hsu@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414130435-14183-1-git-send-email-xavier.hsu@linaro.org> References: <1414130435-14183-1-git-send-email-xavier.hsu@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: xavier.hsu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Xavier Hsu Signed-off-by: Andy Green --- sound/soc/codecs/wm8971.c | 80 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c index 1c871de..7663de4 100755 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c @@ -40,7 +40,9 @@ static struct workqueue_struct *wm8971_workq; /* codec private data */ struct wm8971_priv { + /* MCLK */ unsigned int sysclk; + struct snd_pcm_hw_constraint_list *sysclk_constraints; /* De-emphasis */ struct mutex deemph_mutex; @@ -530,6 +532,35 @@ static int get_coeff(int mclk, int rate) return -EINVAL; } +/* The set of rates we can generate from the above for each SYSCLK */ +static const unsigned int rates_48000[] = { + 8000, 12000, 16000, 24000, 32000, 48000, 96000 +}; + +static struct snd_pcm_hw_constraint_list constraints_48000 = { + .count = ARRAY_SIZE(rates_48000), + .list = rates_48000, +}; + +static const unsigned int rates_44100[] = { + 8000, 11025, 22050, 44100, 88200 +}; + +static struct snd_pcm_hw_constraint_list constraints_44100 = { + .count = ARRAY_SIZE(rates_44100), + .list = rates_44100, +}; + +static const unsigned int rates_12[] = { + 8000, 11025, 12000, 16000, 22050, 24000, 32000, 41100, 48000, + 88235, 96000, +}; + +static struct snd_pcm_hw_constraint_list constraints_12 = { + .count = ARRAY_SIZE(rates_12), + .list = rates_12, +}; + static int wm8971_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id, unsigned int freq, int dir) { @@ -537,15 +568,29 @@ static int wm8971_set_dai_sysclk(struct snd_soc_dai *codec_dai, struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); switch (freq) { - case 11289600: - case 12000000: case 12288000: - case 16934400: + case 24576000: case 18432000: - wm8971->sysclk = freq; - return 0; + case 36864000: + wm8971->sysclk_constraints = &constraints_48000; + break; + case 11289600: + case 22579200: + case 16934400: + case 33868800: + wm8971->sysclk_constraints = &constraints_44100; + break; + case 12000000: + case 24000000: + wm8971->sysclk_constraints = &constraints_12; + break; + default: + return -EINVAL; } - return -EINVAL; + + wm8971->sysclk = freq; + + return 0; } static int wm8971_set_dai_fmt(struct snd_soc_dai *codec_dai, @@ -604,6 +649,28 @@ static int wm8971_set_dai_fmt(struct snd_soc_dai *codec_dai, return 0; } +static int wm8971_pcm_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_soc_codec *codec = dai->codec; + struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); + + /* The set of sample rates that can be supported depends on the + * MCLK supplied to the CODEC - enforce this. + */ + if (!wm8971->sysclk) { + dev_err(codec->dev, + "No MCLK configured, call set_sysclk() on init\n"); + return -EINVAL; + } + + snd_pcm_hw_constraint_list(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, + wm8971->sysclk_constraints); + + return 0; +} + static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) @@ -688,6 +755,7 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec, SNDRV_PCM_FMTBIT_S24_LE) static const struct snd_soc_dai_ops wm8971_dai_ops = { + .startup = wm8971_pcm_startup, .hw_params = wm8971_pcm_hw_params, .digital_mute = wm8971_mute, .set_fmt = wm8971_set_dai_fmt,