PCI: tegra: Enable PCIe xclk clock clamping [Linux 5.3]

This Linux kernel change "PCI: tegra: Enable PCIe xclk clock clamping" is included in the Linux 5.3 release. This change is authored by Manikanta Maddireddy <mmaddireddy [at] nvidia.com> on Tue Jun 18 23:31:51 2019 +0530. The commit for this change in Linux stable tree is f117809 (patch).

PCI: tegra: Enable PCIe xclk clock clamping

Enable xclk clock clamping when entering L1. Clamp threshold will
determine the time spent waiting for clock module to turn on xclk after
signaling it. Default threshold value in Tegra124 and Tegra210 is not
enough to turn on xclk clock. Increase the clamp threshold to meet the
clock module timing in Tegra124 and Tegra210. Default threshold value is
enough in Tegra20, Tegra30 and Tegra186.

Signed-off-by: Manikanta Maddireddy <mmaddireddy@nvidia.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Thierry Reding <treding@nvidia.com>

There are 30 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/pci/controller/pci-tegra.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pci-tegra.c b/drivers/pci/controller/pci-tegra.c
index d079cde..56648b2 100644
--- a/drivers/pci/controller/pci-tegra.c
+++ b/drivers/pci/controller/pci-tegra.c
@@ -219,8 +219,14 @@
 #define  RP_VEND_CTL2_PCA_ENABLE (1 << 7)

 #define RP_PRIV_MISC   0x00000fe0
-#define  RP_PRIV_MISC_PRSNT_MAP_EP_PRSNT (0xe << 0)
-#define  RP_PRIV_MISC_PRSNT_MAP_EP_ABSNT (0xf << 0)
+#define  RP_PRIV_MISC_PRSNT_MAP_EP_PRSNT       (0xe << 0)
+#define  RP_PRIV_MISC_PRSNT_MAP_EP_ABSNT       (0xf << 0)
+#define  RP_PRIV_MISC_CTLR_CLK_CLAMP_THRESHOLD_MASK    (0x7f << 16)
+#define  RP_PRIV_MISC_CTLR_CLK_CLAMP_THRESHOLD     (0xf << 16)
+#define  RP_PRIV_MISC_CTLR_CLK_CLAMP_ENABLE        (1 << 23)
+#define  RP_PRIV_MISC_TMS_CLK_CLAMP_THRESHOLD_MASK (0x7f << 24)
+#define  RP_PRIV_MISC_TMS_CLK_CLAMP_THRESHOLD      (0xf << 24)
+#define  RP_PRIV_MISC_TMS_CLK_CLAMP_ENABLE     (1 << 31)

 #define RP_LINK_CONTROL_STATUS         0x00000090
 #define  RP_LINK_CONTROL_STATUS_DL_LINK_ACTIVE 0x20000000
@@ -298,6 +304,7 @@ struct tegra_pcie_soc {
    bool has_gen2;
    bool force_pca_enable;
    bool program_uphy;
+   bool update_clamp_threshold;
    struct {
        struct {
            u32 rp_ectl_2_r1;
@@ -529,6 +536,7 @@ static void tegra_pcie_port_reset(struct tegra_pcie_port *port)

 static void tegra_pcie_enable_rp_features(struct tegra_pcie_port *port)
 {
+   const struct tegra_pcie_soc *soc = port->pcie->soc;
    u32 value;

    /* Enable AER capability */
@@ -549,6 +557,19 @@ static void tegra_pcie_enable_rp_features(struct tegra_pcie_port *port)
    value = readl(port->base + RP_VEND_XP_BIST);
    value |= RP_VEND_XP_BIST_GOTO_L1_L2_AFTER_DLLP_DONE;
    writel(value, port->base + RP_VEND_XP_BIST);
+
+   value = readl(port->base + RP_PRIV_MISC);
+   value |= RP_PRIV_MISC_CTLR_CLK_CLAMP_ENABLE;
+   value |= RP_PRIV_MISC_TMS_CLK_CLAMP_ENABLE;
+
+   if (soc->update_clamp_threshold) {
+       value &= ~(RP_PRIV_MISC_CTLR_CLK_CLAMP_THRESHOLD_MASK |
+               RP_PRIV_MISC_TMS_CLK_CLAMP_THRESHOLD_MASK);
+       value |= RP_PRIV_MISC_CTLR_CLK_CLAMP_THRESHOLD |
+           RP_PRIV_MISC_TMS_CLK_CLAMP_THRESHOLD;
+   }
+
+   writel(value, port->base + RP_PRIV_MISC);
 }

 static void tegra_pcie_program_ectl_settings(struct tegra_pcie_port *port)
@@ -2353,6 +2374,7 @@ static void tegra_pcie_disable_ports(struct tegra_pcie *pcie)
    .has_gen2 = false,
    .force_pca_enable = false,
    .program_uphy = true,
+   .update_clamp_threshold = false,
    .ectl.enable = false,
 };

@@ -2377,6 +2399,7 @@ static void tegra_pcie_disable_ports(struct tegra_pcie *pcie)
    .has_gen2 = false,
    .force_pca_enable = false,
    .program_uphy = true,
+   .update_clamp_threshold = false,
    .ectl.enable = false,
 };

@@ -2394,6 +2417,7 @@ static void tegra_pcie_disable_ports(struct tegra_pcie *pcie)
    .has_gen2 = true,
    .force_pca_enable = false,
    .program_uphy = true,
+   .update_clamp_threshold = true,
    .ectl.enable = false,
 };

@@ -2411,6 +2435,7 @@ static void tegra_pcie_disable_ports(struct tegra_pcie *pcie)
    .has_gen2 = true,
    .force_pca_enable = true,
    .program_uphy = true,
+   .update_clamp_threshold = true,
    .ectl = {
        .regs = {
            .rp_ectl_2_r1 = 0x0000000f,
@@ -2447,6 +2472,7 @@ static void tegra_pcie_disable_ports(struct tegra_pcie *pcie)
    .has_gen2 = true,
    .force_pca_enable = false,
    .program_uphy = false,
+   .update_clamp_threshold = false,
    .ectl.enable = false,
 };

Leave a Reply

Your email address will not be published. Required fields are marked *