Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp230490yba; Tue, 14 May 2019 23:46:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqx13ZK0M1l5R/EJY5p8Zzbt+j83ZWnqYdvf0o8jbKZ3cGHNwS9UNzxkdGg5yDxfSN6mMUWZ X-Received: by 2002:a63:441c:: with SMTP id r28mr42466937pga.255.1557902777173; Tue, 14 May 2019 23:46:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557902777; cv=none; d=google.com; s=arc-20160816; b=PkmxSIdPoICAfW4LXPhB4aNN8WnfE1kOc4/FbpKeoLw85JLb/ABPjy/oT4rDcBtIy7 Vjw+pzpQ0aL4nTPq5ThMBgQt4xByCZnNLwKGBqBHGs++CPG0idls9/o0LvxRAbxGaf6n ch05hVmyfLEZr4+OgAXYM+rIEEoYiwoAcB3zYeckh1Cc9G6UreRi6UY9z2GaTJ9B8NEo RkaGQNC5sye5k6SeVLQ9ZIMf9ejoSGqpnSxOcrno0jKvGDETCQkBBw1hWI0zsWwjZUjf mOqPTH5RpQsBNW1h/TI9qZ7pGd3YIdiXY96neOlzgggeNfJoGuqyFa8Na8eXix+uDpvz QVGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=4JmSzAPQKN+QzL+RGTE9eLARP/11+3/amAwILeD9cD0=; b=N1wsHTuZhTcn1Inu4tBy6UQTqeth0UuG6zMCa8Mq1rO+pPZuG6dMaFwLlhQufCbVQW G2QtM2V/rTwfAfpuOM8VQ7UxVd+LoCXl0TmhSQs2FM0QRr9q5gdcHb6ba1LcuF22wSP8 OBsnXbZ5OFnlR09OkbfyOEjNGinXBS3fTXRaWP3Vp1OTENS7hx5+bNSPT7vRNUsmTrRC Q9455Ihl0uyaDvCYSpOVsQqp0jczqekohS2S/fszdec1VcOTnPXmUHqrdBLoH8j9Bcra P715EVQInBHd2aTYLtRfNkOIQuoMifRzGwZ+XL33BRyNTSUuv9Nohw1uYB2duV0w5dsd DzOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=MVaTL+QZ; 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=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l4si1008731plb.305.2019.05.14.23.46.02; Tue, 14 May 2019 23:46:17 -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=@nxp.com header.s=selector2 header.b=MVaTL+QZ; 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=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726501AbfEOGmd (ORCPT + 99 others); Wed, 15 May 2019 02:42:33 -0400 Received: from mail-eopbgr10045.outbound.protection.outlook.com ([40.107.1.45]:3889 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726084AbfEOGm2 (ORCPT ); Wed, 15 May 2019 02:42:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4JmSzAPQKN+QzL+RGTE9eLARP/11+3/amAwILeD9cD0=; b=MVaTL+QZADZBAj96oj9LhHYa+co5ksPAwBxQnFSCRbwe4o7MjY05lIFFCrMZcr/md9zjQIkLsCBJwLUPHrAV8Fw0wj+nVdyiSNBse5KiiENOJFwtGT8UDvQHHabcWcrIF5/BgJCIGWUNsmkanpPZk5UelU2b7Dce/G4fquVvCR4= Received: from AM0PR04MB6468.eurprd04.prod.outlook.com (20.179.253.81) by AM0PR04MB4513.eurprd04.prod.outlook.com (52.135.149.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1878.24; Wed, 15 May 2019 06:42:23 +0000 Received: from AM0PR04MB6468.eurprd04.prod.outlook.com ([fe80::659b:59f5:6a7e:1862]) by AM0PR04MB6468.eurprd04.prod.outlook.com ([fe80::659b:59f5:6a7e:1862%5]) with mapi id 15.20.1878.024; Wed, 15 May 2019 06:42:23 +0000 From: "S.j. Wang" To: "timur@kernel.org" , "nicoleotsuka@gmail.com" , "Xiubo.Lee@gmail.com" , "festevam@gmail.com" , "broonie@kernel.org" , "alsa-devel@alsa-project.org" CC: "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH RESEND V6 2/3] ASoC: fsl_asrc: replace the process_option table with function Thread-Topic: [PATCH RESEND V6 2/3] ASoC: fsl_asrc: replace the process_option table with function Thread-Index: AQHVCulZN6Zg9CWEL0yqCEiSG9fUHg== Date: Wed, 15 May 2019 06:42:22 +0000 Message-ID: <7d683186c3de9314e361fd4ead42f9691968e65c.1557901312.git.shengjiu.wang@nxp.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.21.0 x-clientproxiedby: HK2PR03CA0054.apcprd03.prod.outlook.com (2603:1096:202:17::24) To AM0PR04MB6468.eurprd04.prod.outlook.com (2603:10a6:208:16e::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=shengjiu.wang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 54625804-dfbc-4882-1f61-08d6d9007bd4 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:AM0PR04MB4513; x-ms-traffictypediagnostic: AM0PR04MB4513: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0038DE95A2 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39860400002)(366004)(136003)(396003)(346002)(376002)(199004)(189003)(14454004)(26005)(71200400001)(71190400001)(110136005)(52116002)(54906003)(14444005)(256004)(5660300002)(316002)(3846002)(102836004)(68736007)(66946007)(73956011)(2906002)(64756008)(66556008)(66476007)(66446008)(476003)(186003)(76176011)(486006)(8936002)(81166006)(6512007)(8676002)(6486002)(2616005)(81156014)(50226002)(66066001)(4326008)(7736002)(11346002)(305945005)(6436002)(6116002)(36756003)(446003)(25786009)(6506007)(386003)(99286004)(2501003)(53936002)(86362001)(2201001)(118296001)(478600001);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR04MB4513;H:AM0PR04MB6468.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: eCH2kd5IHfFb7geOIF0azuof49DLaePslAPl0ZXdRl3QtLKv/r6C4Y5wTJRmsZ/Gyt0ivsvscYJananxnO73HXp1PZ/WNX7ZLDUKFjka1KLOI6CrFhzubz0JA6q10ldOTPlc0qm8FHVUqz15BlDlHuaqTaLxEIs/dGhmppxrTVH6oDSOsKvY48KGY683yZjWyevcuCBwkoJBcHAetq7A830n5aR9LGuKCbY2DUtLhu+u4wmLAQeAC+WCClgjiwKWsBIUe9DXchCIJBMmKi4tXq8493oWj/Pb7Qw0sUHdM2Zs2dMrUeuhLeiPoKHSn9OTpzcgy78Ff63cYRYYcNJPQLTnUToUoyzPSXS5Ump2ud1IIYMiEKJoTcM14xLFtv+LkuRXtXg88aXHEXCblQRCGQKd3X3F0AoZyVkDbx6HzM8= Content-Type: text/plain; charset="iso-8859-1" Content-ID: <5C0AFBBD663E6B41ADF889F596EA3EFA@eurprd04.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54625804-dfbc-4882-1f61-08d6d9007bd4 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 May 2019 06:42:22.4568 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4513 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we want to support more sample rate, for example 12kHz/24kHz we need update the process_option table, if we want to support more sample rate next time, the table need to be updated again. which is not flexible. We got a function fsl_asrc_sel_proc to replace the table, which can give the pre-processing and post-processing options according to the sample rate. Signed-off-by: Shengjiu Wang Acked-by: Nicolin Chen --- sound/soc/fsl/fsl_asrc.c | 71 +++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c index ea035c12a325..a8d6710f2541 100644 --- a/sound/soc/fsl/fsl_asrc.c +++ b/sound/soc/fsl/fsl_asrc.c @@ -26,24 +26,6 @@ #define pair_dbg(fmt, ...) \ dev_dbg(&asrc_priv->pdev->dev, "Pair %c: " fmt, 'A' + index, ##__VA_ARGS_= _) =20 -/* Sample rates are aligned with that defined in pcm.h file */ -static const u8 process_option[][12][2] =3D { - /* 8kHz 11.025kHz 16kHz 22.05kHz 32kHz 44.1kHz 48kHz 64kHz 88.2kHz 96= kHz 176kHz 192kHz */ - {{0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, = {0, 0}, {0, 0}, {0, 0},}, /* 5512Hz */ - {{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, = {0, 0}, {0, 0}, {0, 0},}, /* 8kHz */ - {{0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, = {0, 0}, {0, 0}, {0, 0},}, /* 11025Hz */ - {{1, 2}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, = {0, 0}, {0, 0}, {0, 0},}, /* 16kHz */ - {{1, 2}, {1, 2}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 0}, {0, 0}, = {0, 0}, {0, 0}, {0, 0},}, /* 22050Hz */ - {{1, 2}, {2, 1}, {2, 1}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, = {0, 0}, {0, 0}, {0, 0},}, /* 32kHz */ - {{2, 2}, {2, 2}, {2, 1}, {2, 1}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, = {0, 1}, {0, 0}, {0, 0},}, /* 44.1kHz */ - {{2, 2}, {2, 2}, {2, 1}, {2, 1}, {0, 2}, {0, 2}, {0, 1}, {0, 1}, {0, 1}, = {0, 1}, {0, 0}, {0, 0},}, /* 48kHz */ - {{2, 2}, {2, 2}, {2, 2}, {2, 1}, {1, 2}, {0, 2}, {0, 2}, {0, 1}, {0, 1}, = {0, 1}, {0, 1}, {0, 0},}, /* 64kHz */ - {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 1}, {1, 1}, = {1, 1}, {1, 1}, {1, 1},}, /* 88.2kHz */ - {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 1}, {1, 1}, = {1, 1}, {1, 1}, {1, 1},}, /* 96kHz */ - {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 1}, {2, 1}, = {2, 1}, {2, 1}, {2, 1},}, /* 176kHz */ - {{2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 1}, {2, 1}, = {2, 1}, {2, 1}, {2, 1},}, /* 192kHz */ -}; - /* Corresponding to process_option */ static int supported_input_rate[] =3D { 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, @@ -79,6 +61,52 @@ static unsigned char output_clk_map_imx53[] =3D { =20 static unsigned char *clk_map[2]; =20 +/** + * Select the pre-processing and post-processing options + * Make sure to exclude following unsupported cases before + * calling this function: + * 1) inrate > 8.125 * outrate + * 2) inrate > 16.125 * outrate + * + * inrate: input sample rate + * outrate: output sample rate + * pre_proc: return value for pre-processing option + * post_proc: return value for post-processing option + */ +static void fsl_asrc_sel_proc(int inrate, int outrate, + int *pre_proc, int *post_proc) +{ + bool post_proc_cond2; + bool post_proc_cond0; + + /* select pre_proc between [0, 2] */ + if (inrate * 8 > 33 * outrate) + *pre_proc =3D 2; + else if (inrate * 8 > 15 * outrate) { + if (inrate > 152000) + *pre_proc =3D 2; + else + *pre_proc =3D 1; + } else if (inrate < 76000) + *pre_proc =3D 0; + else if (inrate > 152000) + *pre_proc =3D 2; + else + *pre_proc =3D 1; + + /* Condition for selection of post-processing */ + post_proc_cond2 =3D (inrate * 15 > outrate * 16 && outrate < 56000) || + (inrate > 56000 && outrate < 56000); + post_proc_cond0 =3D inrate * 23 < outrate * 8; + + if (post_proc_cond2) + *post_proc =3D 2; + else if (post_proc_cond0) + *post_proc =3D 0; + else + *post_proc =3D 1; +} + /** * Request ASRC pair * @@ -239,6 +267,7 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair *p= air) 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; =20 @@ -377,11 +406,13 @@ static int fsl_asrc_config_pair(struct fsl_asrc_pair = *pair) ASRCTR_IDRi_MASK(index) | ASRCTR_USRi_MASK(index), ASRCTR_IDR(index) | ASRCTR_USR(index)); =20 + fsl_asrc_sel_proc(inrate, outrate, &pre_proc, &post_proc); + /* 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)); =20 return fsl_asrc_set_ideal_ratio(pair, inrate, outrate); } --=20 2.21.0