Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751291AbdLQGIK (ORCPT ); Sun, 17 Dec 2017 01:08:10 -0500 Received: from mail-sn1nam02on0085.outbound.protection.outlook.com ([104.47.36.85]:61472 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750789AbdLQGII (ORCPT ); Sun, 17 Dec 2017 01:08:08 -0500 From: Dhaval Rajeshbhai Shah To: Randy Dunlap , "arnd@arndb.de" , "gregkh@linuxfoundation.org" , "robh+dt@kernel.org" , "mark.rutland@arm.com" CC: "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "michal.simek@xilinx.com" , Hyun Kwon Subject: RE: [PATCH v4 2/2] misc: xlnx_vcu: Add Xilinx ZYNQMP VCU logicoreIP init driver Thread-Topic: [PATCH v4 2/2] misc: xlnx_vcu: Add Xilinx ZYNQMP VCU logicoreIP init driver Thread-Index: AQHTdXXfzc8WifQZzEuO3wpYZwF/YaNGjJGAgACCMqA= Date: Sun, 17 Dec 2017 06:07:59 +0000 Message-ID: References: <29198c0a-783e-8aa0-00e4-44b1fa1acef7@infradead.org> <1513322656-4571-1-git-send-email-dshah@xilinx.com> <1513322656-4571-3-git-send-email-dshah@xilinx.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=DSHAH@xilinx.com; x-originating-ip: [149.199.62.254] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY1PR0201MB1003;6:0Kx8DN6RwSTeEa4d1rarauj8QeQB9ySPyz3Leeflrv5H4Slj7JbpEPs9JM1+kyN6qk2AmnCQcWYH8fh2C2HJ184lEm0aLmWesaGqVWLoW0V8oLAWrOR6aOODNc31Eht9DNp3Yatn9FR5QuFBTcRM80ZrGH5t/jNXVSHchnrcK8a4aPkH/ihL3Rjdk3ctYV2HsfPg59D/UuID9ER6RnqgBo2ywU0XN+MxNGTZl81To380b6ck2MUJjJZtuAx906cvryq1nA2o4msEgiz24C52VO5nG8htL5RDLc7GUTipx60TTIkbSUl26iu0fgbgwFinrGWjlNfn6OB05VDe/2Q6wqd38Tn0pstZCi/Tj0e67es=;5:0EjVkW51nlmy9VBaG6S+NCXPs5ZeBDzCDJ4htzRBvoUlCAorBd57uwlkwrqpEuUGOU8AEuVpTxqGVoq5d7m1W+ldCXY+8Q7XF4nQuB7lEBk7PhxCx7/wPqy9yZ/e1Qp6CSEbzhb+WJKd0LHxBIE76fPjEtOanCQwgOoNfOUBUl4=;24:UdpUA0WpAOztcdWJPzI44ESKE2cZDd0hnkGt6Qkz6uq95Jt1qdVMMwlqBJWUySn1CgC7w3p8/Cz5reft6xZVB/srfIiY7Kh1Lhg2rBUhTtQ=;7:2gkSe4G6K2emIBRSWdnVDwB/C9C11k6B65eqle5OrZSUYWRclw6FaTuYj7Y4DTtD2PbTERURw3s/H/ILi4hmxQ3tGjV4qb+LcHBS3kBYo3JH7BNrNYrIzAqJMvX34XqOYfrj+LudKLggcytGqAn5zTy9jweDZQL6A9cQaEB5F8pYrExr+IpzJVmaiAoMIa6jSPJTE5J2MJCpqvyi7NOmE4euoP+DyFIJWWHhrDLIIhL+WbrRJl1pW+Ki1cTrNW/n x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10009020)(376002)(366004)(39850400004)(396003)(346002)(24454002)(189003)(199004)(13464003)(3846002)(99286004)(59450400001)(68736007)(7696005)(81166006)(74316002)(5660300001)(478600001)(4326008)(8676002)(54906003)(110136005)(6116002)(2950100002)(305945005)(7736002)(316002)(2900100001)(77096006)(66066001)(53546011)(6506007)(25786009)(102836003)(76176011)(81156014)(2201001)(93886005)(2906002)(33656002)(9686003)(80792005)(53936002)(6436002)(97736004)(105586002)(106356001)(8936002)(6246003)(3280700002)(2501003)(14454004)(72206003)(86362001)(55016002)(229853002)(107886003)(3660700001)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0201MB1003;H:BY2PR0201MB1879.namprd02.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-ms-office365-filtering-correlation-id: 0f9462c2-86f4-414d-7a58-08d545148634 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603307);SRVR:CY1PR0201MB1003; x-ms-traffictypediagnostic: CY1PR0201MB1003: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(9452136761055)(192813158149592); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231023)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(6072148)(201708071742011);SRVR:CY1PR0201MB1003;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY1PR0201MB1003; x-forefront-prvs: 05245CA661 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f9462c2-86f4-414d-7a58-08d545148634 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Dec 2017 06:07:59.4010 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0201MB1003 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id vBH68Fr0009934 Content-Length: 5696 Lines: 164 Hi Randy, Thanks a lot for the review. > -----Original Message----- > From: Randy Dunlap [mailto:rdunlap@infradead.org] > Sent: Saturday, December 16, 2017 2:18 PM > To: Dhaval Rajeshbhai Shah ; arnd@arndb.de; > gregkh@linuxfoundation.org; robh+dt@kernel.org; mark.rutland@arm.com > Cc: devicetree@vger.kernel.org; linux-kernel@vger.kernel.org; > michal.simek@xilinx.com; Hyun Kwon ; Dhaval Rajeshbhai > Shah > Subject: Re: [PATCH v4 2/2] misc: xlnx_vcu: Add Xilinx ZYNQMP VCU logicoreIP > init driver > > On 12/14/2017 11:24 PM, Dhaval Shah wrote: > > Xilinx ZYNQMP logicoreIP Init driver is based on the new LogiCoreIP > > design created. This driver provides the processing system and > > programmable logic isolation. Set the frequency based on the clock > > information get from the logicoreIP register set. > > > > It is put in drivers/misc as there is no subsystem for this logicoreIP. > > > > Signed-off-by: Dhaval Shah > > --- > > > > drivers/misc/Kconfig | 15 ++ > > drivers/misc/Makefile | 1 + > > drivers/misc/xlnx_vcu.c | 631 > > ++++++++++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 647 insertions(+) > > create mode 100644 drivers/misc/xlnx_vcu.c > > > diff --git a/drivers/misc/xlnx_vcu.c b/drivers/misc/xlnx_vcu.c new > > file mode 100644 index 0000000..f489d34 > > --- /dev/null > > +++ b/drivers/misc/xlnx_vcu.c > > @@ -0,0 +1,631 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Xilinx VCU Init > > + * > > + * Copyright (C) 2016 - 2017 Xilinx, Inc. > > + * > > + * Contacts Dhaval Shah > > + */ > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > [snip] > > > > +/** > > + * xvcu_set_vcu_pll_info - Set the VCU PLL info > > + * @xvcu: Pointer to the xvcu_device structure > > + * > > + * Programming the VCU PLL based on the user configuration > > + * (ref clock freq, core clock freq, mcu clock freq). > > + * Core clock frequency has higher priority than mcu clock frequency > > + * Errors in following cases > > + * - When mcu or clock clock get from logicoreIP is 0 > > + * - When VCU PLL DIV related bits value other than 1 > > + * - When proper data not found for given data > > + * - When sis570_1 clocksource related operation failed > > + * > > + * Return: Returns status, either success or error+reason > > + */ > > +static int xvcu_set_vcu_pll_info(struct xvcu_device *xvcu) { > > + u32 refclk, coreclk, mcuclk, inte, deci; > > + u32 divisor_mcu, divisor_core, fvco; > > + u32 clkoutdiv, vcu_pll_ctrl, pll_clk; > > + u32 cfg_val, mod, ctrl; > > + int ret; > > + unsigned int i; > > + const struct xvcu_pll_cfg *found = NULL; > > + > > + inte = xvcu_read(xvcu->logicore_reg_ba, VCU_PLL_CLK); > > + deci = xvcu_read(xvcu->logicore_reg_ba, VCU_PLL_CLK_DEC); > > + coreclk = xvcu_read(xvcu->logicore_reg_ba, VCU_CORE_CLK) * MHZ; > > + mcuclk = xvcu_read(xvcu->logicore_reg_ba, VCU_MCU_CLK) * MHZ; > > + if (!mcuclk || !coreclk) { > > + dev_err(xvcu->dev, "Invalid mcu and core clock data\n"); > > + return -EINVAL; > > + } > > + > > + refclk = (inte * MHZ) + (deci * (MHZ / FRAC)); > > + dev_dbg(xvcu->dev, "Ref clock from logicoreIP is %uHz\n", refclk); > > + dev_dbg(xvcu->dev, "Core clock from logicoreIP is %uHz\n", coreclk); > > + dev_dbg(xvcu->dev, "Mcu clock from logicoreIP is %uHz\n", mcuclk); > > + > > + clk_disable_unprepare(xvcu->pll_ref); > > + ret = clk_set_rate(xvcu->pll_ref, refclk); > > + if (ret) > > + dev_warn(xvcu->dev, "failed to set logicoreIP refclk rate\n"); > > + > > + ret = clk_prepare_enable(xvcu->pll_ref); > > + if (ret) { > > + dev_err(xvcu->dev, "failed to enable pll_ref clock source\n"); > > + return ret; > > + } > > + > > + refclk = clk_get_rate(xvcu->pll_ref); > > + > > + /* > > + * The divide-by-2 should be always enabled (==1) > > + * to meet the timing in the design. > > + * Otherwise, it's an error > > + */ > > + vcu_pll_ctrl = xvcu_read(xvcu->vcu_slcr_ba, VCU_PLL_CTRL); > > + clkoutdiv = vcu_pll_ctrl >> VCU_PLL_CTRL_CLKOUTDIV_SHIFT; > > + clkoutdiv = clkoutdiv && VCU_PLL_CTRL_CLKOUTDIV_MASK; > > + if (clkoutdiv != 1) { > > + dev_err(xvcu->dev, "clkoutdiv value is invalid\n"); > > + return -EINVAL; > > + } > > + > > + for (i = ARRAY_SIZE(xvcu_pll_cfg) - 1; i > 0; i--) { > > When does that for loop terminate? > This loop will terminate either it reach to i =0 and one other case is when it find the proper expected value. Break statement is used to exit in that case. > > + const struct xvcu_pll_cfg *cfg = &xvcu_pll_cfg[i]; > > + > > + fvco = cfg->fbdiv * refclk; > > + if (fvco >= FVCO_MIN && fvco <= FVCO_MAX) { > > + pll_clk = fvco / VCU_PLL_DIV2; > > + if (fvco % VCU_PLL_DIV2 != 0) > > + pll_clk++; > > + mod = pll_clk % coreclk; > > + if (mod < LIMIT) { > > + divisor_core = pll_clk / coreclk; > > + } else if (coreclk - mod < LIMIT) { > > + divisor_core = pll_clk / coreclk; > > + divisor_core++; > > + } else { > > + continue; > > + } > > + if (divisor_core >= DIVISOR_MIN && > > + divisor_core <= DIVISOR_MAX) { > > + found = cfg; > > + divisor_mcu = pll_clk / mcuclk; > > + mod = pll_clk % mcuclk; > > + if (mcuclk - mod < LIMIT) > > + divisor_mcu++; > > + break; This is the break statement to exit when proper value is find. > > + } > > + } > > + } > > + > > + if (!found) { > > + dev_err(xvcu->dev, "Invalid clock combination.\n"); > > + return -EINVAL; > > + } > > [snip] > > -- > ~Randy