From patchwork Fri Jun 5 12:05:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergej Sawazki X-Patchwork-Id: 6553031 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8DBE39F1C1 for ; Fri, 5 Jun 2015 12:08:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9C30220766 for ; Fri, 5 Jun 2015 12:08:20 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 4392420676 for ; Fri, 5 Jun 2015 12:08:17 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5996C2614D1; Fri, 5 Jun 2015 14:08:12 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id C65222614D6; Fri, 5 Jun 2015 14:08:02 +0200 (CEST) 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 6194B2614F4; Fri, 5 Jun 2015 14:07:58 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by alsa0.perex.cz (Postfix) with ESMTP id E57D22614D6 for ; Fri, 5 Jun 2015 14:07:50 +0200 (CEST) Received: from localhost.localdomain ([109.44.3.59]) by mail.gmx.com (mrgmx101) with ESMTPSA (Nemesis) id 0Mcyxq-1Yjrn514sc-00ICp8; Fri, 05 Jun 2015 14:07:41 +0200 From: Sergej Sawazki To: broonie@kernel.org, lgirdwood@gmail.com, ckeepax@opensource.wolfsonmicro.com Date: Fri, 5 Jun 2015 14:05:44 +0200 Message-Id: <1433505944-3961-1-git-send-email-ce3a@gmx.de> X-Mailer: git-send-email 1.9.1 X-Provags-ID: V03:K0:TJ8sbshpKcjNocs1+ttW+eGLfPSa+N/LEXm1qH81LDfaMwcDFqY F48eiy/kuJlikkxB6dUhGmZP4qmaRk+NducedfYCrQMpelKef/GfAP5uTf67nVxsFd3X5ip rwuVILN4UHcc8L8Ona9vVPUBDu4PfMGzzJvhP1QMIJAH4gcSU2LbmrDUFJjQ4se8VWv1FBS 6jWQxv/qmVaNAkRHRfPQA== X-UI-Out-Filterresults: notjunk:1; V01:K0:Nd/LRUd6tUQ=:CBfL2F6+slAdVn3mEBfV8n xG2rvWIXlVpQPARomrb3HCSRwrQ5Q/N6Hk7fmqGuGtUs/N8+dcKc3lTCzIlIuZGzlTc9FQTNr 9EA/aJ3VxtLNfSiVixiazrySMrSgpJ28FdG1dwMpdzy5BLd7BkRCP2BNfatCMffRUq5j2PiqA dJTTu8MOBrUx9/2nB5nGzL/tbIsQCd1NROP3FHMvQQqnakTdB+2guGntj3O0DFKn4Qkl8miWt C+8hVGUf/CW6FJ0e1Jb4k1k6dsxCrqRD4WYJ56geKEjH3uo+890NapVg1Q239nYonrwQ74fcD anohs81iFdfMBUDmKfn4S0Hi4VSPIsqkuykpZEyLf4gl093P58otmaifWniSxsx7r5yw4lJOL RcfVzQaQle3Ka0M631GUAdeNQp8AZRS5zzqi5xiCuO5oYKVbpOBCFMF/4aVCO/OYGmkbDHZSL jGyZRr0Kl0NfvePCMyeRaqeAwddwps0yLy0nPNUdFUz84h9QTFFsnLpdcQcy9/4oNtPbp1zcX wUNscXo38f7bKphwhlkMy26ChL6o/oJdOCG8mAd0Kom8JQ57ljg9rNAGQhNTpuBntVwwXh8+o Ix/8UuqBSvSJNX/60qQvrnTVGdTDLM0biZk01p+txjWW+om7AFeFPnCkvcqbeeZMWYiWTsZ/R JCDLWg94nJlHoAdKKkAYO/Chdj69cuFzLQ35ZMEs7myjtwA== Cc: Sergej Sawazki , alsa-devel@alsa-project.org, lars@metafoo.de, patches@opensource.wolfsonmicro.com, dan.carpenter@oracle.com Subject: [alsa-devel] [RFC PATCH] ASoC: wm8741: Allow master clock switching 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 set of supported sample rates depends on the master clock supplied to the codec. Allow the machine driver to set the required master clock in hw_params(). Signed-off-by: Sergej Sawazki --- This patch has been tested on a board with two master clocks, 22.5792MHz (for 44.1kHz, 88.2kHz, ...) and 24.576MHz (for 48kHz, 96kHz, ...). sound/soc/codecs/wm8741.c | 63 +++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 46 deletions(-) diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c index 09ff01f..47c5577 100644 --- a/sound/soc/codecs/wm8741.c +++ b/sound/soc/codecs/wm8741.c @@ -125,18 +125,6 @@ static const struct snd_soc_dapm_route wm8741_dapm_routes[] = { { "VOUTRN", NULL, "DACR" }, }; -static struct { - int value; - int ratio; -} lrclk_ratios[WM8741_NUM_RATES] = { - { 1, 128 }, - { 2, 192 }, - { 3, 256 }, - { 4, 384 }, - { 5, 512 }, - { 6, 768 }, -}; - static const unsigned int rates_11289[] = { 44100, 88200, }; @@ -209,29 +197,6 @@ static const struct snd_pcm_hw_constraint_list constraints_36864 = { .list = rates_36864, }; - -static int wm8741_startup(struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) -{ - struct snd_soc_codec *codec = dai->codec; - struct wm8741_priv *wm8741 = 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 (!wm8741->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, - wm8741->sysclk_constraints); - - return 0; -} - static int wm8741_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) @@ -241,17 +206,24 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC; int i; - /* Find a supported LRCLK ratio */ - for (i = 0; i < ARRAY_SIZE(lrclk_ratios); i++) { - if (wm8741->sysclk / params_rate(params) == - lrclk_ratios[i].ratio) + /* The set of sample rates that can be supported depends on the + * MCLK supplied to the CODEC - enforce this. + */ + if (!wm8741->sysclk) { + dev_err(codec->dev, + "No MCLK configured, call set_sysclk() on hw_params\n"); + return -EINVAL; + } + + /* Find a supported LRCLK rate */ + for (i = 0; i < wm8741->sysclk_constraints->count; i++) { + if (wm8741->sysclk_constraints->list[i] == params_rate(params)) break; } - /* Should never happen, should be handled by constraints */ - if (i == ARRAY_SIZE(lrclk_ratios)) { - dev_err(codec->dev, "MCLK/fs ratio %d unsupported\n", - wm8741->sysclk / params_rate(params)); + if (i == wm8741->sysclk_constraints->count) { + dev_err(codec->dev, "LRCLK %d unsupported with MCLK %d\n", + params_rate(params), wm8741->sysclk); return -EINVAL; } @@ -274,8 +246,8 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - dev_dbg(codec->dev, "wm8741_hw_params: bit size param = %d", - params_width(params)); + dev_dbg(codec->dev, "wm8741_hw_params: bit size param = %d, rate param = %d", + params_width(params), params_rate(params)); snd_soc_write(codec, WM8741_FORMAT_CONTROL, iface); return 0; @@ -403,7 +375,6 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai, SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) static const struct snd_soc_dai_ops wm8741_dai_ops = { - .startup = wm8741_startup, .hw_params = wm8741_hw_params, .set_sysclk = wm8741_set_dai_sysclk, .set_fmt = wm8741_set_dai_fmt,