From patchwork Sun Jun 14 02:28:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 6603491 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 735A89F2F4 for ; Sun, 14 Jun 2015 02:28:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9740C2069F for ; Sun, 14 Jun 2015 02:28:29 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 3A0E72069E for ; Sun, 14 Jun 2015 02:28:28 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9C2F22604EF; Sun, 14 Jun 2015 04:28:26 +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, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 4D0822604CE; Sun, 14 Jun 2015 04:28:19 +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 571EB2604D1; Sun, 14 Jun 2015 04:28:17 +0200 (CEST) Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by alsa0.perex.cz (Postfix) with ESMTP id 0CE552604C6 for ; Sun, 14 Jun 2015 04:28:09 +0200 (CEST) Received: by pacyx8 with SMTP id yx8so43849649pac.2 for ; Sat, 13 Jun 2015 19:28:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=dDXjHBvmfp8ypLc6Oen/rTJs3xofsANGD2ZB1QwcxIw=; b=H/3EOk4QWCOfTQirSkfjN95PyPR9hvajIQl1x03qyMUsFFc/gCSSU//MlT4+aBjb/K Nzw/BNZfMS6vDyL/m6Lb1QYRAETjyJKQb9uvQfSwgNKcREaH+qiI41gisXeDQpOvkWjy hQ2TkygB0jdAvN1IlK5cAdu341ymhzJLVEMpzId0ZlGUMJz4OjhdZtZ2LRczZhBAu8nw z9XGibw6rPN12Q7P2RckiKC26hGSfc/ML4DadNwfLQMHJcyMg+S20/HZGN8Th0jFaWVU OyH/r9VZEJBtS4uky7b1WyXktlyf0zK87FYrWcV5z3TV3GsMLwTtt7XxZ6TL9ld4FAsZ pWBw== X-Gm-Message-State: ALoCoQlB8VrLhCgM6rXeQ2q5pswG4wEuPq6lf7twki65LaDe1jIxEkiaJ8r46684CqhSBJwhOSB1 X-Received: by 10.68.113.132 with SMTP id iy4mr36230909pbb.71.1434248888186; Sat, 13 Jun 2015 19:28:08 -0700 (PDT) Received: from phoenix.local (118-171-136-229.dynamic.hinet.net. [118.171.136.229]) by mx.google.com with ESMTPSA id jz10sm7902138pbc.48.2015.06.13.19.28.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Jun 2015 19:28:06 -0700 (PDT) Message-ID: <1434248881.10956.2.camel@ingics.com> From: Axel Lin To: Mark Brown Date: Sun, 14 Jun 2015 10:28:01 +0800 X-Mailer: Evolution 3.12.10-0ubuntu1~14.10.1 Mime-Version: 1.0 Cc: "alsa-devel@alsa-project.org" , Tomoya MORINAGA , Liam Girdwood Subject: [alsa-devel] [PATCH] ASoC: ml26124: Remove duplicate code 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Current code has duplicate code for 16000, 32000 and 48000 sample rates. get_srate() returns negative error code for unsupported rate, so we can remove the duplicate code in the swith cases by calling get_srate() first. Signed-off-by: Axel Lin --- sound/soc/codecs/ml26124.c | 58 +++++++++------------------------------------- 1 file changed, 11 insertions(+), 47 deletions(-) diff --git a/sound/soc/codecs/ml26124.c b/sound/soc/codecs/ml26124.c index 62dda24..b74118e 100644 --- a/sound/soc/codecs/ml26124.c +++ b/sound/soc/codecs/ml26124.c @@ -341,6 +341,7 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream, struct snd_soc_codec *codec = dai->codec; struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec); int i = get_coeff(priv->mclk, params_rate(hw_params)); + int srate; if (i < 0) return i; @@ -370,53 +371,16 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream, BIT(0) | BIT(1), 0); } - switch (params_rate(hw_params)) { - case 16000: - snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, - get_srate(params_rate(hw_params))); - snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, - coeff_div[i].pllnl); - snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, - coeff_div[i].pllnh); - snd_soc_update_bits(codec, ML26124_PLLML, 0xff, - coeff_div[i].pllml); - snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, - coeff_div[i].pllmh); - snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, - coeff_div[i].plldiv); - break; - case 32000: - snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, - get_srate(params_rate(hw_params))); - snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, - coeff_div[i].pllnl); - snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, - coeff_div[i].pllnh); - snd_soc_update_bits(codec, ML26124_PLLML, 0xff, - coeff_div[i].pllml); - snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, - coeff_div[i].pllmh); - snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, - coeff_div[i].plldiv); - break; - case 48000: - snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, - get_srate(params_rate(hw_params))); - snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, - coeff_div[i].pllnl); - snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, - coeff_div[i].pllnh); - snd_soc_update_bits(codec, ML26124_PLLML, 0xff, - coeff_div[i].pllml); - snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, - coeff_div[i].pllmh); - snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, - coeff_div[i].plldiv); - break; - default: - pr_err("%s:this rate is no support for ml26124\n", __func__); - return -EINVAL; - } + srate = get_srate(params_rate(hw_params)); + if (srate < 0) + return srate; + + snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, srate); + snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, coeff_div[i].pllnl); + snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, coeff_div[i].pllnh); + snd_soc_update_bits(codec, ML26124_PLLML, 0xff, coeff_div[i].pllml); + snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, coeff_div[i].pllmh); + snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, coeff_div[i].plldiv); return 0; }