From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 886ECC27C4F for ; Sun, 30 Jun 2024 16:11:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IszfV8T4b9z12YmSOdHo4qEq5YZATMox6eGaVhw+N9Y=; b=yZAQYwg3YB4W5IZafthdsPAJLY WvhTnmwVwbF08KPXTx79+29GspWtqZZ2xN8VjPzbl3arHj/TBxzDEx30hSBVMtKd8gqj7qeVLSK6U ISVOALeB0H/3BgN1qUW/Btddqdo8YxpG9wYeNH7dWyQeqjo4XfwZSQWHLcXD01XWjr6MWH64mlbuZ KCt/S/MWsORa1RgsmRESK9krAMJ0I6ShhxZtEvZ+ASQ+6DQGfCi7YSolrYFq/K0XgkQto3Ktll/1N NugrAlhB9bzZucWWAyh6mY8c1W1SF1kseEt7MX4F2PhkT6KEOmYFAomf4exrGBTF71ApYZJPSuRyG VbIj7dew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sNx8Z-00000000fzO-04Jz; Sun, 30 Jun 2024 16:10:47 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sNx8O-00000000fxK-1Hrl for linux-arm-kernel@lists.infradead.org; Sun, 30 Jun 2024 16:10:38 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7066c9741b7so1227465b3a.1 for ; Sun, 30 Jun 2024 09:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719763835; x=1720368635; darn=lists.infradead.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=IszfV8T4b9z12YmSOdHo4qEq5YZATMox6eGaVhw+N9Y=; b=L8LscGkeD1ER8QkMx2vUhHFzEb6lBWmbRfT80ikW7LG/KA18FTbgNKRWu/mWgEu/62 rZM6vNWjwxETxmW4NuqCXMWuxmE8po7qyPzErOL9K+TXWgWuNJT5UPvoYEsASpzcUNL0 giYgxhOR9kSUr1xU6csZidIpURWum67Htr+c1B6NMn62Jv8D/jCxoAYGWitEq5mH+cCX UkOyoSxRiRVA63FDCpm2E2aFyKNyMityYtpn8/NBVCobhg1cJ5bJqfq7t4ueIZ9DtR+/ DshWm5KVHTRA/rCEFo4/t6ZHf7a+odPX0cm/bJQjgtfFfvOYgymAdhMK0z6Lqsvzv9FU blGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719763835; x=1720368635; 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=IszfV8T4b9z12YmSOdHo4qEq5YZATMox6eGaVhw+N9Y=; b=lmn7oedkVuY+E6aeGC8qatQjiPoeN6fnjILvgrC0ylhwHoHMeST5yckbEOXUEZbZWL dYe5WxnsC4gxH9y+H73g0EwI4fgQf2VX+Q+5ZHiTSIlo61XhIoBy+do2L9rnJlSbAXXy z2ruQnAzr3a/mW0ddK5DVNjqLpworVJcS5BhvNqihgHF32hZK+U6iLNERBvokxpZvPEd Oqev70tAahR+ph5of7vDrdyZ6WI5nMF7lxOymHhFscNFeyvz/pyqjOEG6OqCjlI0mRrU 9pH1f1DMVvgkS1O8OasZGFcUPOR6tZBKDbcS7MDyLOMN3JCVSi5nXIGdw5qplygDBw48 Sy5A== X-Forwarded-Encrypted: i=1; AJvYcCWO8Wq4fFU8VikpHMICstQRtMEZj5c01FAjiV73c+Czdo5ygqbEfHctPbPidUykFUnkgAuSJmFXrmJovR3UC+HFf1mf5vofoB4az5B2bh22OvLNECY= X-Gm-Message-State: AOJu0YwWgj3j11X2VTF5+ggS7re4r0wqsR4KgnKSELjEDdKM+da4u9wF gPgvzHYunNwtyDtHYDrjHIwmLW6Ge4+a7hj2yWC9lU9ND6gajdi+nghIN9fKOg== X-Google-Smtp-Source: AGHT+IEOaTTCA8LuEGruX/jibPIx1BjotjXmxzwtWRUj2Jf71MrMEA1a/SOWBV+dVrHr2t3qRyLbaQ== X-Received: by 2002:a05:6a00:2381:b0:707:ffb3:5933 with SMTP id d2e1a72fcca58-70aaad480f2mr2041308b3a.11.1719763834662; Sun, 30 Jun 2024 09:10:34 -0700 (PDT) Received: from thinkpad ([220.158.156.215]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70801e53f83sm4846872b3a.26.2024.06.30.09.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 09:10:34 -0700 (PDT) Date: Sun, 30 Jun 2024 21:40:26 +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 v6 05/10] PCI: imx6: Simplify switch-case logic by involve core_reset callback Message-ID: <20240630161026.GB5264@thinkpad> References: <20240617-pci2_upstream-v6-0-e0821238f997@nxp.com> <20240617-pci2_upstream-v6-5-e0821238f997@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240617-pci2_upstream-v6-5-e0821238f997@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240630_091036_384635_141BE0D0 X-CRM114-Status: GOOD ( 28.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jun 17, 2024 at 04:16:41PM -0400, Frank Li wrote: > Instead of using the switch case statement to assert/dassert the core reset > handled by this driver itself, let's introduce a new callback core_reset() > and define it for platforms that require it. This simplifies the code. > > Signed-off-by: Frank Li Reviewed-by: Manivannan Sadhasivam - Mani > --- > drivers/pci/controller/dwc/pci-imx6.c | 134 ++++++++++++++++++---------------- > 1 file changed, 71 insertions(+), 63 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index ff9d0098294fa..6f68bee111029 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -104,6 +104,7 @@ struct imx_pcie_drvdata { > const struct pci_epc_features *epc_features; > int (*init_phy)(struct imx_pcie *pcie); > int (*set_ref_clk)(struct imx_pcie *pcie, bool enable); > + int (*core_reset)(struct imx_pcie *pcie, bool assert); > }; > > struct imx_pcie { > @@ -672,35 +673,75 @@ static void imx_pcie_clk_disable(struct imx_pcie *imx_pcie) > clk_bulk_disable_unprepare(imx_pcie->drvdata->clks_cnt, imx_pcie->clks); > } > > +static int imx6sx_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) > +{ > + if (assert) > + regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, > + IMX6SX_GPR12_PCIE_TEST_POWERDOWN); > + > + /* Force PCIe PHY reset */ > + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR5, IMX6SX_GPR5_PCIE_BTNRST_RESET, > + assert ? IMX6SX_GPR5_PCIE_BTNRST_RESET : 0); > + return 0; > +} > + > +static int imx6qp_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) > +{ > + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_SW_RST, > + assert ? IMX6Q_GPR1_PCIE_SW_RST : 0); > + if (!assert) > + usleep_range(200, 500); > + > + return 0; > +} > + > +static int imx6q_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) > +{ > + if (!assert) > + return 0; > + > + regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_TEST_PD); > + regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_REF_CLK_EN); > + > + return 0; > +} > + > +static int imx7d_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert) > +{ > + struct dw_pcie *pci = imx_pcie->pci; > + struct device *dev = pci->dev; > + > + if (assert) > + return 0; > + > + /* > + * Workaround for ERR010728, failure of PCI-e PLL VCO to > + * oscillate, especially when cold. This turns off "Duty-cycle > + * Corrector" and other mysterious undocumented things. > + */ > + > + if (likely(imx_pcie->phy_base)) { > + /* De-assert DCC_FB_EN */ > + writel(PCIE_PHY_CMN_REG4_DCC_FB_EN, imx_pcie->phy_base + PCIE_PHY_CMN_REG4); > + /* Assert RX_EQS and RX_EQS_SEL */ > + writel(PCIE_PHY_CMN_REG24_RX_EQ_SEL | PCIE_PHY_CMN_REG24_RX_EQ, > + imx_pcie->phy_base + PCIE_PHY_CMN_REG24); > + /* Assert ATT_MODE */ > + writel(PCIE_PHY_CMN_REG26_ATT_MODE, imx_pcie->phy_base + PCIE_PHY_CMN_REG26); > + } else { > + dev_warn(dev, "Unable to apply ERR010728 workaround. DT missing fsl,imx7d-pcie-phy phandle ?\n"); > + } > + imx7d_pcie_wait_for_phy_pll_lock(imx_pcie); > + return 0; > +} > + > static void imx_pcie_assert_core_reset(struct imx_pcie *imx_pcie) > { > reset_control_assert(imx_pcie->pciephy_reset); > reset_control_assert(imx_pcie->apps_reset); > > - switch (imx_pcie->drvdata->variant) { > - case IMX6SX: > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, > - IMX6SX_GPR12_PCIE_TEST_POWERDOWN, > - IMX6SX_GPR12_PCIE_TEST_POWERDOWN); > - /* Force PCIe PHY reset */ > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR5, > - IMX6SX_GPR5_PCIE_BTNRST_RESET, > - IMX6SX_GPR5_PCIE_BTNRST_RESET); > - break; > - case IMX6QP: > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > - IMX6Q_GPR1_PCIE_SW_RST, > - IMX6Q_GPR1_PCIE_SW_RST); > - break; > - case IMX6Q: > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > - IMX6Q_GPR1_PCIE_TEST_PD, 1 << 18); > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > - IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16); > - break; > - default: > - break; > - } > + if (imx_pcie->drvdata->core_reset) > + imx_pcie->drvdata->core_reset(imx_pcie, true); > > /* Some boards don't have PCIe reset GPIO. */ > if (gpio_is_valid(imx_pcie->reset_gpio)) > @@ -710,47 +751,10 @@ static void imx_pcie_assert_core_reset(struct imx_pcie *imx_pcie) > > static int imx_pcie_deassert_core_reset(struct imx_pcie *imx_pcie) > { > - struct dw_pcie *pci = imx_pcie->pci; > - struct device *dev = pci->dev; > - > reset_control_deassert(imx_pcie->pciephy_reset); > > - switch (imx_pcie->drvdata->variant) { > - case IMX7D: > - /* Workaround for ERR010728, failure of PCI-e PLL VCO to > - * oscillate, especially when cold. This turns off "Duty-cycle > - * Corrector" and other mysterious undocumented things. > - */ > - if (likely(imx_pcie->phy_base)) { > - /* De-assert DCC_FB_EN */ > - writel(PCIE_PHY_CMN_REG4_DCC_FB_EN, > - imx_pcie->phy_base + PCIE_PHY_CMN_REG4); > - /* Assert RX_EQS and RX_EQS_SEL */ > - writel(PCIE_PHY_CMN_REG24_RX_EQ_SEL > - | PCIE_PHY_CMN_REG24_RX_EQ, > - imx_pcie->phy_base + PCIE_PHY_CMN_REG24); > - /* Assert ATT_MODE */ > - writel(PCIE_PHY_CMN_REG26_ATT_MODE, > - imx_pcie->phy_base + PCIE_PHY_CMN_REG26); > - } else { > - dev_warn(dev, "Unable to apply ERR010728 workaround. DT missing fsl,imx7d-pcie-phy phandle ?\n"); > - } > - > - imx7d_pcie_wait_for_phy_pll_lock(imx_pcie); > - break; > - case IMX6SX: > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR5, > - IMX6SX_GPR5_PCIE_BTNRST_RESET, 0); > - break; > - case IMX6QP: > - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, > - IMX6Q_GPR1_PCIE_SW_RST, 0); > - > - usleep_range(200, 500); > - break; > - default: > - break; > - } > + if (imx_pcie->drvdata->core_reset) > + imx_pcie->drvdata->core_reset(imx_pcie, false); > > /* Some boards don't have PCIe reset GPIO. */ > if (gpio_is_valid(imx_pcie->reset_gpio)) { > @@ -1458,6 +1462,7 @@ static const struct imx_pcie_drvdata drvdata[] = { > .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > .init_phy = imx_pcie_init_phy, > .set_ref_clk = imx6q_pcie_set_ref_clk, > + .core_reset = imx6q_pcie_core_reset, > }, > [IMX6SX] = { > .variant = IMX6SX, > @@ -1473,6 +1478,7 @@ static const struct imx_pcie_drvdata drvdata[] = { > .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > .init_phy = imx6sx_pcie_init_phy, > .set_ref_clk = imx6sx_pcie_set_ref_clk, > + .core_reset = imx6sx_pcie_core_reset, > }, > [IMX6QP] = { > .variant = IMX6QP, > @@ -1489,6 +1495,7 @@ static const struct imx_pcie_drvdata drvdata[] = { > .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > .init_phy = imx_pcie_init_phy, > .set_ref_clk = imx6q_pcie_set_ref_clk, > + .core_reset = imx6qp_pcie_core_reset, > }, > [IMX7D] = { > .variant = IMX7D, > @@ -1502,6 +1509,7 @@ static const struct imx_pcie_drvdata drvdata[] = { > .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, > .init_phy = imx7d_pcie_init_phy, > .set_ref_clk = imx7d_pcie_set_ref_clk, > + .core_reset = imx7d_pcie_core_reset, > }, > [IMX8MQ] = { > .variant = IMX8MQ, > > -- > 2.34.1 > -- மணிவண்ணன் சதாசிவம்