From patchwork Wed Sep 17 08:41:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Hsu X-Patchwork-Id: 37510 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A4B222054D for ; Wed, 17 Sep 2014 08:41:36 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id l4sf17392lbv.4 for ; Wed, 17 Sep 2014 01:41:35 -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=mEesKVvr1Kvfmb+71OXEvy7UdzZpElRI+usuJ4iekuE=; b=cKmE+2iVjOlMRnuvCthPm4ZHOkIawY2DcXFSqt18UEDNhjRuhd8OLb8CQa+rfcw/It 1pLZwKiRJ679FQ9CY6Mxe8IMOXCHuP4ej2+ojBY1mrmPaF76+pFFH62ZEunhH6780G+f wAbWmv32cfWExapUVDVwh5UdKL/7pVuoKs5G9cSMzSNIi10fdAqn4PLZRWsjiBqUDKR5 K0R4X++rpbCESE8Hs2EsVrmWmVc4OAgsYxZZpvMkPtRUp2FibWpyzc2bmuznZRK+1/Om qrC+NL0JbzB7m3KH+dHjNQEeVic/CUDtdFRFlq9LYoX1zQezoXnQNRPJ7xLzqJv+WkvB YaFg== X-Gm-Message-State: ALoCoQnDHinbyascIHpXAnkldyYHlEOtBlhDCHQgQr60q0LTkwNTTO9goVLG7j6iKJFcSW40d2Ac X-Received: by 10.181.28.169 with SMTP id jp9mr644919wid.6.1410943295109; Wed, 17 Sep 2014 01:41:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.135 with SMTP id k7ls28431lah.78.gmail; Wed, 17 Sep 2014 01:41:34 -0700 (PDT) X-Received: by 10.152.87.170 with SMTP id az10mr42679584lab.20.1410943294832; Wed, 17 Sep 2014 01:41:34 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com [209.85.217.170]) by mx.google.com with ESMTPS id l7si27646378lae.29.2014.09.17.01.41.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Sep 2014 01:41:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id c11so1378683lbj.1 for ; Wed, 17 Sep 2014 01:41:34 -0700 (PDT) X-Received: by 10.152.204.231 with SMTP id lb7mr40375892lac.44.1410943294635; Wed, 17 Sep 2014 01:41:34 -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.130.169 with SMTP id of9csp537471lbb; Wed, 17 Sep 2014 01:41:33 -0700 (PDT) X-Received: by 10.70.131.101 with SMTP id ol5mr69466323pdb.77.1410943291052; Wed, 17 Sep 2014 01:41:31 -0700 (PDT) Received: from Kraken ([124.219.7.128]) by mx.google.com with ESMTP id ib4si33440278pbc.249.2014.09.17.01.41.29 for ; Wed, 17 Sep 2014 01:41:31 -0700 (PDT) Received-SPF: none (google.com: xavier@kraken does not designate permitted sender hosts) client-ip=124.219.7.128; Received: by Kraken (Postfix, from userid 1011) id C503D6A27AD; Wed, 17 Sep 2014 16:41:23 +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: [PATCHv4 6/9] Using the constraint based on wm8971_set_dai_sysclk Date: Wed, 17 Sep 2014 16:41:12 +0800 Message-Id: <1410943275-4160-6-git-send-email-xavier.hsu@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1410943275-4160-1-git-send-email-xavier.hsu@linaro.org> References: <1410943275-4160-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.170 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: , This patch improves WM8971. We use the constraint based on the function of wm8971_set_dai_sysclk(). Signed-off-by: Xavier Hsu Signed-off-by: Andy Green --- Any comments about improving the patch are welcome. Thanks. 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 7021f77..5b38c7a 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,