Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp296718lqa; Sat, 27 Apr 2024 02:55:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUo0cAmhgkAua5icN8baNK/5CARZU4KESWviM1+wWVxVsu7Tx6wJeqeuFFC/O2pC06o+wCZohlYsFYMJJeJd6cYQakXqNHTXHsq4yieZA== X-Google-Smtp-Source: AGHT+IFSvICT7bA9wvQ0S4x65JFucQoKAQjDJAANcmhUFGY+LLF6DzNZRdOQR/4N9HLltTfKwtmg X-Received: by 2002:a05:622a:4acf:b0:437:9c7e:ab1f with SMTP id fx15-20020a05622a4acf00b004379c7eab1fmr3581073qtb.33.1714211708454; Sat, 27 Apr 2024 02:55:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714211708; cv=pass; d=google.com; s=arc-20160816; b=uJATv2RJnGa6EmR+9teEJCg9ydB/t2J83Pd0CAR4Z7XatsCOa9TY5s4vILwuJjPSUa 1Ljh2n3OS7gZs3neXNQ5LopFDbm9E9mRSiD5ovmD3kXO0HySGswleuW4IcLqF23gq1VE ij3uBjavIjB8t/e+Bw3Db+F3Odm50roEsrTEutsLOQGGXk5udOgtDTKcFh8rn/9GhsSa QVimY7DAtft3j7L8jb4D18jfJQUt8deh3bl4zHcxG0pY6pNtCqQ4U2QRR2faphZLlvo9 IfRSHTlUSNMm09FzRXdQwIjaO33/ZjNoyDJIBve8a9g27WwlOWJFUzbSYOH9i+M2e8jI oNUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=q7IJCY5rJWmDi7bRkGY/6TU0zJug2sXYMpCIYdgYukw=; fh=vCrvpacNsXvBCmWM+2gbxOHiQ1DK6Nzh0le+Y19lgVY=; b=jlcrGa6DJgeM/J2a09gQv17OeG78BrzhPN6cQ5WiFPZ8VBp7upldkmHmbJhj9v9TIG iv/413J4P9DNCtTmgU0JSNCrbwKYVZWHmie14YZ1E8B+Fg8PaUuj+Q9nKebiFz0Je5bN dpPTdFINBmlTTBMWzN9j7NvssPEF7MOW7qQNWLw5uWgLWt8LOcwXMdB89B6ql1sKAHgx j5VPC8XPM21xuHtTnVQCO42RN5iNXtmpei2MyrZSepODXbW113eiNhIxXPmqY3kd7x8p Yy1hQkCAjBLLP57ykOxSQfsr1wxEVBw6XJq5kzE5C1068dEPjJsGaLFnLCbEs/XeqSul BJ5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rjbUlxk2; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-160985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fv27-20020a05622a4a1b00b00439755df2d0si17956876qtb.620.2024.04.27.02.55.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Apr 2024 02:55:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rjbUlxk2; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-160985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 08C301C21235 for ; Sat, 27 Apr 2024 09:55:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9DC2481A8; Sat, 27 Apr 2024 09:54:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rjbUlxk2" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5906647F62 for ; Sat, 27 Apr 2024 09:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714211696; cv=none; b=SQbrjmdosyiDatA5CULlE2m8cg3nx4mfc79FbYBXJYKkkJAsY2GDmOhikbG8L1+c6M9ns0zwKcb4wokmAk1bp0SGOrkkOgnz/oBJltpVm3scqGqutAMERNQF/K+dxA3ivYJ8A6q/ky4RzMFKdWbMwuzBwFINKwqv2J+1k2CueyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714211696; c=relaxed/simple; bh=oAKyMTR8eWOSyqxbhlem5MYmleLa9lzfZXEEcetSXnM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hTdZEeicowhSkC7TcuMdb1VyqCtlU1MoMwwEhm87dzvs/r1YY7ZUlQCQ1FJ4nFrSIeVykThFxdPVf1i+EUE/uTkEJbRP3sNrzF0bH/0OVN7rjGnrKL4e8ttTAWQhEKJ4y1mmS2HrLFE+Pb630G3A/T2P5UZ/Q4SAjdHS1+jGRec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=rjbUlxk2; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6ed2170d89fso2750521b3a.1 for ; Sat, 27 Apr 2024 02:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714211695; x=1714816495; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=q7IJCY5rJWmDi7bRkGY/6TU0zJug2sXYMpCIYdgYukw=; b=rjbUlxk2e7bHQLJkTEDScQs9ZP23EPeVPFtV6zJYKHO+0S1B8pN7ld9U0JlukRfyXM NcxfANbIhJFq8zWB6TY2nWiwr783kv8jaX0FQdqdYxm9cdfWOvoMx0f0IwMrjOscwslH aXoOBLYpzdWvSR3UDtr113Ddz3PIoXkzYcigG7EgSS6TYBUJlePY9Wi8qK+eEYCerEWl xsMz4EIVXjyiG5E0ABWqsENmGuu3AdYnnTjiZdjp30IImNMYxk3fdsBHvg38xN9EdIYS bj/XMI4/ZpQEKdaqegeZT+6TlOVt7UxQU1+TSHGkthR6gyL8LFJpy+5nJWGa8mDbISUr L7Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714211695; x=1714816495; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=q7IJCY5rJWmDi7bRkGY/6TU0zJug2sXYMpCIYdgYukw=; b=bhoOOMyiGlSwqPrRffk/48Pl8xMm9tNxrTBcdg4ztpmkQtJbdnnyj85CDTHHf0IobP yL5lRlJZEtYe6KqxWH8rD1C/Xb/qeYa90qJqeECCj0oKrERRCoC7vV1p5ss7Lf2qbiwF NAoDw1lB2L2KHE/abgFTkCkdVokllBdUhFzSkYhzrHq3N0k88O0LaC86RdkOPRQ6rScr gVcxvfzScfGeuLXRJkpvxg3quChIw8T007K9NQq14JB9ZWE7uYH0zEIiRsX69l9rQhWP 9qJgVDFrFAukoYTcUOzNwkonCffPckpOT1hhG5R6dkpoa4fZBMdZmAMf1ZcsIpN4VpJU OefQ== X-Forwarded-Encrypted: i=1; AJvYcCXzwuZDq2kp0UrduyiJTVll/LEnM6bsMbMIzghha/vewEVXGqZKpNCy5hT4cBwhvozufhWZLsc66kOTskz5oYyni6ZG1QWvkIbsXs5K X-Gm-Message-State: AOJu0YwgGUMoiAMN+J2YW50j6T8nYsaJ2WeqS/Jac14koopBULg9oS4P 04iG/lvhM9buYG6LvbWiepXrRNPieGzQfcDxw0+jWksG1B+AyyaoRxfzHIDyqg== X-Received: by 2002:a17:90b:246:b0:2aa:cadb:d290 with SMTP id fz6-20020a17090b024600b002aacadbd290mr7383922pjb.13.1714211694536; Sat, 27 Apr 2024 02:54:54 -0700 (PDT) Received: from thinkpad ([117.213.97.210]) by smtp.gmail.com with ESMTPSA id y10-20020a17090ad70a00b002a63e966fd7sm15753781pju.47.2024.04.27.02.54.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Apr 2024 02:54:54 -0700 (PDT) Date: Sat, 27 Apr 2024 15:24:44 +0530 From: Manivannan Sadhasivam To: Frank Li Cc: Richard Zhu , Lucas Stach , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Philipp Zabel , Liam Girdwood , Mark Brown , Krzysztof Kozlowski , Conor Dooley , linux-pci@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v3 06/11] PCI: imx: Simplify switch-case logic by involve set_ref_clk callback Message-ID: <20240427095444.GK1981@thinkpad> References: <20240402-pci2_upstream-v3-0-803414bdb430@nxp.com> <20240402-pci2_upstream-v3-6-803414bdb430@nxp.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240402-pci2_upstream-v3-6-803414bdb430@nxp.com> On Tue, Apr 02, 2024 at 10:33:42AM -0400, Frank Li wrote: PCI: imx6: Introduce SoC specific callbacks for controlling REFCLK > Instead of using the switch case statement to enable/disable the reference > clock handled by this driver itself, let's introduce a new callback > set_ref_clk() and define it for platforms that require it. This simplifies > the code. > > Signed-off-by: Frank Li > --- > drivers/pci/controller/dwc/pcie-imx.c | 119 ++++++++++++++++------------------ > 1 file changed, 55 insertions(+), 64 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pcie-imx.c b/drivers/pci/controller/dwc/pcie-imx.c > index e93070d60df52..77dae5c3f7057 100644 > --- a/drivers/pci/controller/dwc/pcie-imx.c > +++ b/drivers/pci/controller/dwc/pcie-imx.c > @@ -103,6 +103,7 @@ struct imx_pcie_drvdata { > const u32 mode_mask[IMX_PCIE_MAX_INSTANCES]; > const struct pci_epc_features *epc_features; > int (*init_phy)(struct imx_pcie *pcie); > + int (*set_ref_clk)(struct imx_pcie *pcie, bool enable); > }; > > struct imx_pcie { > @@ -585,77 +586,54 @@ static int imx_pcie_attach_pd(struct device *dev) > return 0; > } > > -static int imx_pcie_enable_ref_clk(struct imx_pcie *imx_pcie) > +static int imx6sx_pcie_set_ref_clk(struct imx_pcie *imx_pcie, bool enable) > { > - unsigned int offset; > - int ret = 0; > + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, IMX6SX_GPR12_PCIE_TEST_POWERDOWN, > + enable ? 0 : IMX6SX_GPR12_PCIE_TEST_POWERDOWN); > > - switch (imx_pcie->drvdata->variant) { > - case IMX6SX: > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, > - IMX6SX_GPR12_PCIE_TEST_POWERDOWN, 0); > - break; > - case IMX6QP: > - case IMX6Q: > + return 0; > +} > + > +static int imx6q_pcie_set_ref_clk(struct imx_pcie *imx_pcie, bool enable) > +{ > + if (enable) { > /* power up core phy and enable ref clock */ > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > - IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18); > + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_TEST_PD, 0); > /* > - * the async reset input need ref clock to sync internally, > - * when the ref clock comes after reset, internal synced > - * reset time is too short, cannot meet the requirement. > - * add one ~10us delay here. > + * the async reset input need ref clock to sync internally, when the ref clock comes > + * after reset, internal synced reset time is too short, cannot meet the > + * requirement.add one ~10us delay here. Please wrap the comments to 80 column width. > */ > usleep_range(10, 100); > regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > - IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16); > - break; > - case IMX7D: > - case IMX95: > - case IMX95_EP: > - break; > - case IMX8MM: > - case IMX8MM_EP: > - case IMX8MQ: > - case IMX8MQ_EP: > - case IMX8MP: > - case IMX8MP_EP: > - offset = imx_pcie_grp_offset(imx_pcie); > - /* > - * Set the over ride low and enabled > - * make sure that REF_CLK is turned on. > - */ > - regmap_update_bits(imx_pcie->iomuxc_gpr, offset, > - IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE, > - 0); > - regmap_update_bits(imx_pcie->iomuxc_gpr, offset, > - IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN, > - IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN); > - break; > + IMX6Q_GPR1_PCIE_REF_CLK_EN, IMX6Q_GPR1_PCIE_REF_CLK_EN); > + } else { > + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > + IMX6Q_GPR1_PCIE_REF_CLK_EN, 0); > + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > + IMX6Q_GPR1_PCIE_TEST_PD, IMX6Q_GPR1_PCIE_TEST_PD); > } > > - return ret; > + return 0; > } > > -static void imx_pcie_disable_ref_clk(struct imx_pcie *imx_pcie) > +static int imx8mm_pcie_set_ref_clk(struct imx_pcie *imx_pcie, bool enable) > { > - switch (imx_pcie->drvdata->variant) { > - case IMX6QP: > - case IMX6Q: > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > - IMX6Q_GPR1_PCIE_REF_CLK_EN, 0); > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > - IMX6Q_GPR1_PCIE_TEST_PD, > - IMX6Q_GPR1_PCIE_TEST_PD); > - break; > - case IMX7D: > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, > - IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, > - IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); > - break; > - default: > - break; > - } > + int offset = imx_pcie_grp_offset(imx_pcie); > + > + /* Set the over ride low and enabled make sure that REF_CLK is turned on.*/ > + regmap_update_bits(imx_pcie->iomuxc_gpr, offset, IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE, > + enable ? 0 : IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE); > + regmap_update_bits(imx_pcie->iomuxc_gpr, offset, IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN, > + enable ? IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN : 0); Extra space after : > + return 0; > +} > + > +static int imx7d_pcie_set_ref_clk(struct imx_pcie *imx_pcie, bool enable) > +{ > + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, > + enable ? 0 : IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); > + return 0; > } > > static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie) > @@ -668,10 +646,12 @@ static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie) > if (ret) > return ret; > > - ret = imx_pcie_enable_ref_clk(imx_pcie); > - if (ret) { > - dev_err(dev, "unable to enable pcie ref clock\n"); > - goto err_ref_clk; > + if (imx_pcie->drvdata->set_ref_clk) { > + ret = imx_pcie->drvdata->set_ref_clk(imx_pcie, true); > + if (ret) { > + dev_err(dev, "unable to enable pcie ref clock\n"); 'Failed to enable PCIe REFCLK' - Mani -- மணிவண்ணன் சதாசிவம்