aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Lin <shawn.lin@rock-chips.com>2016-12-07 16:05:59 -0500
committerBjorn Helgaas <bhelgaas@google.com>2016-12-07 16:05:59 -0500
commitf2fb5b8f2a0cb67ba4535eb08d9cfb301ac92429 (patch)
treeab5612c901646171d9b609884d5f1acccad25e60
parent45e9320f3a4ef9588ee50a2eb1891c4bfdbb07df (diff)
PCI: rockchip: Specify the link capability
rk3399 supports PCIe 2.x link speeds marginally at best, and on some boards, the link won't train at 5 GT/s at all. Rather than sacrifice 500ms waiting for training that will never happen, let's use the helper function, of_pci_get_max_link_speed(), to get the max link speed from DT and specify link capability. Signed-off-by: Brian Norris <briannorris@chromium.org> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r--drivers/pci/host/pcie-rockchip.c60
1 files changed, 37 insertions, 23 deletions
diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c
index f641a4e6f605..13e0dd6097a4 100644
--- a/drivers/pci/host/pcie-rockchip.c
+++ b/drivers/pci/host/pcie-rockchip.c
@@ -53,6 +53,7 @@
53#define PCIE_CLIENT_ARI_ENABLE HIWORD_UPDATE_BIT(0x0008) 53#define PCIE_CLIENT_ARI_ENABLE HIWORD_UPDATE_BIT(0x0008)
54#define PCIE_CLIENT_CONF_LANE_NUM(x) HIWORD_UPDATE(0x0030, ENCODE_LANES(x)) 54#define PCIE_CLIENT_CONF_LANE_NUM(x) HIWORD_UPDATE(0x0030, ENCODE_LANES(x))
55#define PCIE_CLIENT_MODE_RC HIWORD_UPDATE_BIT(0x0040) 55#define PCIE_CLIENT_MODE_RC HIWORD_UPDATE_BIT(0x0040)
56#define PCIE_CLIENT_GEN_SEL_1 HIWORD_UPDATE(0x0080, 0)
56#define PCIE_CLIENT_GEN_SEL_2 HIWORD_UPDATE_BIT(0x0080) 57#define PCIE_CLIENT_GEN_SEL_2 HIWORD_UPDATE_BIT(0x0080)
57#define PCIE_CLIENT_BASIC_STATUS1 (PCIE_CLIENT_BASE + 0x48) 58#define PCIE_CLIENT_BASIC_STATUS1 (PCIE_CLIENT_BASE + 0x48)
58#define PCIE_CLIENT_LINK_STATUS_UP 0x00300000 59#define PCIE_CLIENT_LINK_STATUS_UP 0x00300000
@@ -208,6 +209,7 @@ struct rockchip_pcie {
208 struct gpio_desc *ep_gpio; 209 struct gpio_desc *ep_gpio;
209 u32 lanes; 210 u32 lanes;
210 u8 root_bus_nr; 211 u8 root_bus_nr;
212 int link_gen;
211 struct device *dev; 213 struct device *dev;
212 struct irq_domain *irq_domain; 214 struct irq_domain *irq_domain;
213}; 215};
@@ -518,14 +520,20 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
518 return err; 520 return err;
519 } 521 }
520 522
523 if (rockchip->link_gen == 2)
524 rockchip_pcie_write(rockchip, PCIE_CLIENT_GEN_SEL_2,
525 PCIE_CLIENT_CONFIG);
526 else
527 rockchip_pcie_write(rockchip, PCIE_CLIENT_GEN_SEL_1,
528 PCIE_CLIENT_CONFIG);
529
521 rockchip_pcie_write(rockchip, 530 rockchip_pcie_write(rockchip,
522 PCIE_CLIENT_CONF_ENABLE | 531 PCIE_CLIENT_CONF_ENABLE |
523 PCIE_CLIENT_LINK_TRAIN_ENABLE | 532 PCIE_CLIENT_LINK_TRAIN_ENABLE |
524 PCIE_CLIENT_ARI_ENABLE | 533 PCIE_CLIENT_ARI_ENABLE |
525 PCIE_CLIENT_CONF_LANE_NUM(rockchip->lanes) | 534 PCIE_CLIENT_CONF_LANE_NUM(rockchip->lanes) |
526 PCIE_CLIENT_MODE_RC | 535 PCIE_CLIENT_MODE_RC,
527 PCIE_CLIENT_GEN_SEL_2, 536 PCIE_CLIENT_CONFIG);
528 PCIE_CLIENT_CONFIG);
529 537
530 err = phy_power_on(rockchip->phy); 538 err = phy_power_on(rockchip->phy);
531 if (err) { 539 if (err) {
@@ -609,29 +617,31 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
609 msleep(20); 617 msleep(20);
610 } 618 }
611 619
612 /* 620 if (rockchip->link_gen == 2) {
613 * Enable retrain for gen2. This should be configured only after 621 /*
614 * gen1 finished. 622 * Enable retrain for gen2. This should be configured only after
615 */ 623 * gen1 finished.
616 status = rockchip_pcie_read(rockchip, PCIE_RC_CONFIG_LCS); 624 */
617 status |= PCIE_RC_CONFIG_LCS_RETRAIN_LINK; 625 status = rockchip_pcie_read(rockchip, PCIE_RC_CONFIG_LCS);
618 rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_LCS); 626 status |= PCIE_RC_CONFIG_LCS_RETRAIN_LINK;
627 rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_LCS);
628
629 timeout = jiffies + msecs_to_jiffies(500);
630 for (;;) {
631 status = rockchip_pcie_read(rockchip, PCIE_CORE_CTRL);
632 if ((status & PCIE_CORE_PL_CONF_SPEED_MASK) ==
633 PCIE_CORE_PL_CONF_SPEED_5G) {
634 dev_dbg(dev, "PCIe link training gen2 pass!\n");
635 break;
636 }
619 637
620 timeout = jiffies + msecs_to_jiffies(500); 638 if (time_after(jiffies, timeout)) {
621 for (;;) { 639 dev_dbg(dev, "PCIe link training gen2 timeout, fall back to gen1!\n");
622 status = rockchip_pcie_read(rockchip, PCIE_CORE_CTRL); 640 break;
623 if ((status & PCIE_CORE_PL_CONF_SPEED_MASK) == 641 }
624 PCIE_CORE_PL_CONF_SPEED_5G) {
625 dev_dbg(dev, "PCIe link training gen2 pass!\n");
626 break;
627 }
628 642
629 if (time_after(jiffies, timeout)) { 643 msleep(20);
630 dev_dbg(dev, "PCIe link training gen2 timeout, fall back to gen1!\n");
631 break;
632 } 644 }
633
634 msleep(20);
635 } 645 }
636 646
637 /* Check the final link width from negotiated lane counter from MGMT */ 647 /* Check the final link width from negotiated lane counter from MGMT */
@@ -840,6 +850,10 @@ static int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip)
840 rockchip->lanes = 1; 850 rockchip->lanes = 1;
841 } 851 }
842 852
853 rockchip->link_gen = of_pci_get_max_link_speed(node);
854 if (rockchip->link_gen < 0 || rockchip->link_gen > 2)
855 rockchip->link_gen = 2;
856
843 rockchip->core_rst = devm_reset_control_get(dev, "core"); 857 rockchip->core_rst = devm_reset_control_get(dev, "core");
844 if (IS_ERR(rockchip->core_rst)) { 858 if (IS_ERR(rockchip->core_rst)) {
845 if (PTR_ERR(rockchip->core_rst) != -EPROBE_DEFER) 859 if (PTR_ERR(rockchip->core_rst) != -EPROBE_DEFER)