Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5713339yba; Thu, 11 Apr 2019 04:18:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqywlzNTxKZtOh1EKyKVMUBzx503CXNuVvLzsk1Svr4cQ+hrH/Tdw9jg5oocwmDBvJ32sav3 X-Received: by 2002:a17:902:e002:: with SMTP id ca2mr49864646plb.131.1554981491620; Thu, 11 Apr 2019 04:18:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554981491; cv=none; d=google.com; s=arc-20160816; b=hEx3rY16h9wiwHdia3WB0HTgn1m7iKXJkTGXvuyH3B1ep5Wu2FD9tTMUemMOkdmIcN hu2u+1pj2a0aWMG8owCswwpsFsW5Hev+hMObD0MNv7STYq7A/gfzFlQYXbQrEtqChO0O zy79pX+vQ7+MdDeF41VhV/D3Bmisy4XQvWiH+G5TqtlyVEqi7bgi16RPkQyG5Oj7ViGg CIxATSed72svRo8HkP90BCPByoXCjb7DrPt1vAJWgZTMSx7rVHTU09uHjAf2yJqsJskH bADUbH4tJ/ZfU98/gcvsGIPp3N5aUMfU/NKh5sTj5q8cxRJ0hxhfMrp3v9ms5PscIBZ4 etXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vMzOF4uSDEO2czI0u54xXAsMS0XJszj2itVS4kGxliE=; b=NDcZ9mCUBcC9tpsWTFaX6gB8UxqnV6/rq1KRBioNL7k38yJpN4k0/xmvMWjIBMu6a/ lz2cvallMTQQ3oBa8Vf6GafrwiIJdt3esnigSaTwqXs251K09/uBnkFmfE+i9OPVI5t6 /FNDC23bOh+3xiCy4hx0Fe5zCMKLbkMC8TvOGMPcRePtrckUxfvji57KCMQix7Ly6Qsf XWxsnYAbHAsqRg3r/CcM0VB5+ZfNKgZTEN5FnSSg8+G7Pw6ZK3y2pmUIZlbldtQ/BDGu Yuiy20IwskdOv4Bn684Kq2kqeb2obXwGg3lQZv9wD7XCX2wxduG3pB+VdQUUB2QL7t/2 +Aug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aIzBGpzE; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 25si28744750pgx.421.2019.04.11.04.17.55; Thu, 11 Apr 2019 04:18:11 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=aIzBGpzE; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726694AbfDKLPm (ORCPT + 99 others); Thu, 11 Apr 2019 07:15:42 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:38600 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726517AbfDKLPm (ORCPT ); Thu, 11 Apr 2019 07:15:42 -0400 Received: by mail-ed1-f66.google.com with SMTP id d13so4858275edr.5 for ; Thu, 11 Apr 2019 04:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vMzOF4uSDEO2czI0u54xXAsMS0XJszj2itVS4kGxliE=; b=aIzBGpzEc+WkohNa9Z2aqEpD+O1b6cnlEt1JZ42UBLnEPAK5ueo66UUwQ/3uDaeSxt CAv2HaWP/4BrjgujYwvqBHpvBGVdlhfbPFql+Z+kidt4EmeC9c3R5JWjhJwCZq6vvVsV NMGmkGZGS/pJIs9cLnp70uyDsdBbaUJ6FO99Z9J6H0rHhGTVTQm1WauPAj3TkDZzt+1P +sZNna9PN0nRvNcrayjq8YJqAp48Y8GJatpCKBuqbyzvKiDiPq+zhDnrqkVUe8smF7jN +iRWRhJJ+ypexp5qB6xmmLttXirrM1lU/AuZY3UD+lL0P9Ptzvk7BX7pF3A5h1IY3K8z Jvuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vMzOF4uSDEO2czI0u54xXAsMS0XJszj2itVS4kGxliE=; b=jkhIzllDhDCBWeBrb5vhmcl6BerjNJu6LxONili6bEsrKhsOSnBFY8MjyRnjPrE4E1 CAyAYkE3LZYWtsvyztJiQYb9Md8FWmGfisJNlba1hbbTuuMHWW4F0s9+VALmdBQUni6V pBSceI9F8rhcDbj+U/tEzyAkWlbAYhk2eqkSJKo6Wi4Z0LAG06yG3VvhDJpjaUqFU6Qf k3LhFjS0iuNkhXG18nfBGF/aXOiaQ0GO8rTYGO0MFIratPLeZ7zuwQH/vz2DeczidUAj KILiAkcDcgfgUmjeUkwRxdqi7vdcG0FiknpKsfxGrWRQEZY4ou0587zQdpq410VF3uxL p9lw== X-Gm-Message-State: APjAAAXjTfIOGYQGVTIhPkKEllRmg2+MoSgdaSVZbWOzq6L5u/7V79XH D1krT5lLick7cjlgOy8mYeNKJM01PuG/48/+Ou8= X-Received: by 2002:a05:6402:12d5:: with SMTP id k21mr16320470edx.75.1554981339790; Thu, 11 Apr 2019 04:15:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Daniel Baluta Date: Thu, 11 Apr 2019 14:15:28 +0300 Message-ID: Subject: Re: [PATCH V2 1/2] ASoC: fsl_asrc: replace the process_option table with function To: "S.j. Wang" Cc: "timur@kernel.org" , "nicoleotsuka@gmail.com" , "Xiubo.Lee@gmail.com" , "festevam@gmail.com" , "broonie@kernel.org" , "alsa-devel@alsa-project.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Shengjiu, Mostly looking good. See few comments inline: > +/* > + * Select the pre-processing and post-processing options > + * > + * Fsin: input sample rate > + * Fsout: output sample rate > + * pre_proc: return value for pre-processing option > + * post_proc: return value for post-processing option > + */ > +static int fsl_asrc_sel_proc(int Fsin, int Fsout, int *pre_proc, int *post_proc) Lets be naming consistent here: Fsin -> fs_in, Fsout -> fs_out. > +{ > + bool det_out_op2_cond; > + bool det_out_op0_cond; > + > + /* Codition for selection of post-processing */ > + det_out_op2_cond = (((Fsin * 15 > Fsout * 16) & (Fsout < 56000)) | > + ((Fsin > 56000) & (Fsout < 56000))); Remove outer parenthesis. Also should here be a logical or (||) instead of bitwise or (|)? Same for && vs &. > + det_out_op0_cond = (Fsin * 23 < Fsout * 8); Remove outer parenthesis. > + > + /* > + * unsupported case: Tsout>16.125*Tsin, and Tsout>8.125*Tsin. > + * Tsout>16.125*Tsin -> Fsin * 8 > 129 * Fsout > + * Tsout>8.125*Tsin -> Fsin * 8 > 65 * Fsout > + * Tsout>4.125*Tsin -> Fsin * 8 > 33 * Fsout > + * Tsout>1.875*Tsin -> Fsin * 8 > 15 * Fsout > + */ > + if (Fsin * 8 > 129 * Fsout) > + *pre_proc = 5; > + else if (Fsin * 8 > 65 * Fsout) > + *pre_proc = 4; > + else if (Fsin * 8 > 33 * Fsout) > + *pre_proc = 2; > + else if (Fsin * 8 > 15 * Fsout) { > + if (Fsin > 152000) > + *pre_proc = 2; > + else > + *pre_proc = 1; > + } else if (Fsin < 76000) > + *pre_proc = 0; > + else if (Fsin > 152000) > + *pre_proc = 2; > + else > + *pre_proc = 1; > + > + if (det_out_op2_cond) > + *post_proc = 2; > + else if (det_out_op0_cond) > + *post_proc = 0; > + else > + *post_proc = 1; > + > + /* unsupported options */ > + if (*pre_proc == 4 || *pre_proc == 5) > + return -EINVAL; > + > + return 0; > +} > + > /** > * Request ASRC pair > * > @@ -239,8 +278,10 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) > u32 inrate, outrate, indiv, outdiv; > u32 clk_index[2], div[2]; > int in, out, channels; > + int pre_proc, post_proc; > struct clk *clk; > bool ideal; > + int ret; > > if (!config) { > pair_err("invalid pair config\n"); > @@ -289,6 +330,12 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) > return -EINVAL; > } > > + ret = fsl_asrc_sel_proc(inrate, outrate, &pre_proc, &post_proc); > + if (ret) { > + pair_err("No supported pre-processing options\n"); > + return ret; > + } > + > /* Validate input and output clock sources */ > clk_index[IN] = clk_map[IN][config->inclk]; > clk_index[OUT] = clk_map[OUT][config->outclk]; > @@ -380,8 +427,8 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *pair) > /* Apply configurations for pre- and post-processing */ > regmap_update_bits(asrc_priv->regmap, REG_ASRCFG, > ASRCFG_PREMODi_MASK(index) | ASRCFG_POSTMODi_MASK(index), > - ASRCFG_PREMOD(index, process_option[in][out][0]) | > - ASRCFG_POSTMOD(index, process_option[in][out][1])); > + ASRCFG_PREMOD(index, pre_proc) | > + ASRCFG_POSTMOD(index, post_proc)); > > return fsl_asrc_set_ideal_ratio(pair, inrate, outrate); > } > -- > 1.9.1 >