Lines Matching +full:pcie +full:- +full:ep

1 // SPDX-License-Identifier: GPL-2.0+
3 * PCIe host controller driver for Tegra194 SoC
33 #include "pcie-designware.h"
35 #include <soc/tegra/bpmp-abi.h>
319 static inline void appl_writel(struct tegra_pcie_dw *pcie, const u32 value, in appl_writel() argument
322 writel_relaxed(value, pcie->appl_base + reg); in appl_writel()
325 static inline u32 appl_readl(struct tegra_pcie_dw *pcie, const u32 reg) in appl_readl() argument
327 return readl_relaxed(pcie->appl_base + reg); in appl_readl()
337 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in apply_bad_link_workaround() local
342 * NOTE:- Since this scenario is uncommon and link as such is not in apply_bad_link_workaround()
344 * transitioning to Gen-2 speed in apply_bad_link_workaround()
346 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA); in apply_bad_link_workaround()
350 if (pcie->init_link_width > current_link_width) { in apply_bad_link_workaround()
351 dev_warn(pci->dev, "PCIe link is bad, width reduced\n"); in apply_bad_link_workaround()
352 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
356 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
359 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
362 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
370 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_rp_irq_handler() local
371 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_rp_irq_handler()
372 struct pcie_port *pp = &pci->pp; in tegra_pcie_rp_irq_handler()
376 val = appl_readl(pcie, APPL_INTR_STATUS_L0); in tegra_pcie_rp_irq_handler()
378 val = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_rp_irq_handler()
380 appl_writel(pcie, val, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_rp_irq_handler()
383 val = appl_readl(pcie, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
385 appl_writel(pcie, val, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
387 val = appl_readl(pcie, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
389 appl_writel(pcie, val, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
398 val = appl_readl(pcie, APPL_INTR_STATUS_L1_8_0); in tegra_pcie_rp_irq_handler()
400 appl_writel(pcie, in tegra_pcie_rp_irq_handler()
406 appl_writel(pcie, in tegra_pcie_rp_irq_handler()
410 val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in tegra_pcie_rp_irq_handler()
412 dev_dbg(pci->dev, "Link Speed : Gen-%u\n", val_w & in tegra_pcie_rp_irq_handler()
417 val = appl_readl(pcie, APPL_INTR_STATUS_L0); in tegra_pcie_rp_irq_handler()
419 val = appl_readl(pcie, APPL_INTR_STATUS_L1_18); in tegra_pcie_rp_irq_handler()
422 dev_info(pci->dev, "CDM check complete\n"); in tegra_pcie_rp_irq_handler()
426 dev_err(pci->dev, "CDM comparison mismatch\n"); in tegra_pcie_rp_irq_handler()
430 dev_err(pci->dev, "CDM Logic error\n"); in tegra_pcie_rp_irq_handler()
435 dev_err(pci->dev, "CDM Error Address Offset = 0x%08X\n", tmp); in tegra_pcie_rp_irq_handler()
441 static void pex_ep_event_hot_rst_done(struct tegra_pcie_dw *pcie) in pex_ep_event_hot_rst_done() argument
445 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in pex_ep_event_hot_rst_done()
446 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in pex_ep_event_hot_rst_done()
447 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in pex_ep_event_hot_rst_done()
448 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in pex_ep_event_hot_rst_done()
449 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in pex_ep_event_hot_rst_done()
450 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in pex_ep_event_hot_rst_done()
451 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in pex_ep_event_hot_rst_done()
452 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in pex_ep_event_hot_rst_done()
453 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in pex_ep_event_hot_rst_done()
454 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in pex_ep_event_hot_rst_done()
455 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in pex_ep_event_hot_rst_done()
456 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in pex_ep_event_hot_rst_done()
457 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in pex_ep_event_hot_rst_done()
458 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in pex_ep_event_hot_rst_done()
459 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in pex_ep_event_hot_rst_done()
460 appl_writel(pcie, 0xFFFFFFFF, APPL_MSI_CTRL_2); in pex_ep_event_hot_rst_done()
462 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_hot_rst_done()
464 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_hot_rst_done()
469 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_irq_thread() local
470 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_ep_irq_thread()
473 speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) & in tegra_pcie_ep_irq_thread()
475 clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]); in tegra_pcie_ep_irq_thread()
477 /* If EP doesn't advertise L1SS, just return */ in tegra_pcie_ep_irq_thread()
478 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub); in tegra_pcie_ep_irq_thread()
487 /* 110us for both snoop and no-snoop */ in tegra_pcie_ep_irq_thread()
490 appl_writel(pcie, val, APPL_LTR_MSG_1); in tegra_pcie_ep_irq_thread()
493 val = appl_readl(pcie, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
495 appl_writel(pcie, val, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
499 val = appl_readl(pcie, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
507 dev_err(pcie->dev, "Failed to send LTR message\n"); in tegra_pcie_ep_irq_thread()
515 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_hard_irq() local
516 struct dw_pcie_ep *ep = &pcie->pci.ep; in tegra_pcie_ep_hard_irq() local
520 val = appl_readl(pcie, APPL_INTR_STATUS_L0); in tegra_pcie_ep_hard_irq()
522 val = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_ep_hard_irq()
523 appl_writel(pcie, val, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_ep_hard_irq()
526 pex_ep_event_hot_rst_done(pcie); in tegra_pcie_ep_hard_irq()
529 tmp = appl_readl(pcie, APPL_LINK_STATUS); in tegra_pcie_ep_hard_irq()
531 dev_dbg(pcie->dev, "Link is up with Host\n"); in tegra_pcie_ep_hard_irq()
532 dw_pcie_ep_linkup(ep); in tegra_pcie_ep_hard_irq()
540 val = appl_readl(pcie, APPL_INTR_STATUS_L1_15); in tegra_pcie_ep_hard_irq()
541 appl_writel(pcie, val, APPL_INTR_STATUS_L1_15); in tegra_pcie_ep_hard_irq()
550 dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n", in tegra_pcie_ep_hard_irq()
552 appl_writel(pcie, val, APPL_INTR_STATUS_L0); in tegra_pcie_ep_hard_irq()
564 * when it is accessed with link being in ASPM-L1 state. in tegra_pcie_dw_rd_own_conf()
581 * when it is accessed with link being in ASPM-L1 state. in tegra_pcie_dw_wr_own_conf()
597 static void disable_aspm_l11(struct tegra_pcie_dw *pcie) in disable_aspm_l11() argument
601 val = dw_pcie_readl_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub); in disable_aspm_l11()
603 dw_pcie_writel_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub, val); in disable_aspm_l11()
606 static void disable_aspm_l12(struct tegra_pcie_dw *pcie) in disable_aspm_l12() argument
610 val = dw_pcie_readl_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub); in disable_aspm_l12()
612 dw_pcie_writel_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub, val); in disable_aspm_l12()
615 static inline u32 event_counter_prog(struct tegra_pcie_dw *pcie, u32 event) in event_counter_prog() argument
619 val = dw_pcie_readl_dbi(&pcie->pci, event_cntr_ctrl_offset[pcie->cid]); in event_counter_prog()
624 dw_pcie_writel_dbi(&pcie->pci, event_cntr_ctrl_offset[pcie->cid], val); in event_counter_prog()
625 val = dw_pcie_readl_dbi(&pcie->pci, event_cntr_data_offset[pcie->cid]); in event_counter_prog()
632 struct tegra_pcie_dw *pcie = (struct tegra_pcie_dw *) in aspm_state_cnt() local
633 dev_get_drvdata(s->private); in aspm_state_cnt()
637 event_counter_prog(pcie, EVENT_COUNTER_EVENT_Tx_L0S)); in aspm_state_cnt()
640 event_counter_prog(pcie, EVENT_COUNTER_EVENT_Rx_L0S)); in aspm_state_cnt()
643 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1)); in aspm_state_cnt()
646 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_1)); in aspm_state_cnt()
649 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_2)); in aspm_state_cnt()
652 dw_pcie_writel_dbi(&pcie->pci, event_cntr_ctrl_offset[pcie->cid], in aspm_state_cnt()
655 /* Re-enable counting */ in aspm_state_cnt()
658 dw_pcie_writel_dbi(&pcie->pci, event_cntr_ctrl_offset[pcie->cid], val); in aspm_state_cnt()
663 static void init_host_aspm(struct tegra_pcie_dw *pcie) in init_host_aspm() argument
665 struct dw_pcie *pci = &pcie->pci; in init_host_aspm()
669 pcie->cfg_link_cap_l1sub = val + PCI_L1SS_CAP; in init_host_aspm()
674 dw_pcie_writel_dbi(pci, event_cntr_ctrl_offset[pcie->cid], val); in init_host_aspm()
677 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub); in init_host_aspm()
679 val |= (pcie->aspm_cmrt << 8); in init_host_aspm()
680 val |= (pcie->aspm_pwr_on_t << 19); in init_host_aspm()
681 dw_pcie_writel_dbi(pci, pcie->cfg_link_cap_l1sub, val); in init_host_aspm()
686 val |= (pcie->aspm_l0s_enter_lat << PORT_AFR_L0S_ENTRANCE_LAT_SHIFT); in init_host_aspm()
691 static void init_debugfs(struct tegra_pcie_dw *pcie) in init_debugfs() argument
693 debugfs_create_devm_seqfile(pcie->dev, "aspm_state_cnt", pcie->debugfs, in init_debugfs()
697 static inline void disable_aspm_l12(struct tegra_pcie_dw *pcie) { return; } in disable_aspm_l12() argument
698 static inline void disable_aspm_l11(struct tegra_pcie_dw *pcie) { return; } in disable_aspm_l11() argument
699 static inline void init_host_aspm(struct tegra_pcie_dw *pcie) { return; } in init_host_aspm() argument
700 static inline void init_debugfs(struct tegra_pcie_dw *pcie) { return; } in init_debugfs() argument
706 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_system_interrupts() local
710 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_system_interrupts()
712 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_system_interrupts()
714 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0); in tegra_pcie_enable_system_interrupts()
716 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0); in tegra_pcie_enable_system_interrupts()
718 if (pcie->enable_cdm_check) { in tegra_pcie_enable_system_interrupts()
719 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_system_interrupts()
721 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_system_interrupts()
723 val = appl_readl(pcie, APPL_INTR_EN_L1_18); in tegra_pcie_enable_system_interrupts()
726 appl_writel(pcie, val, APPL_INTR_EN_L1_18); in tegra_pcie_enable_system_interrupts()
729 val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base + in tegra_pcie_enable_system_interrupts()
731 pcie->init_link_width = (val_w & PCI_EXP_LNKSTA_NLW) >> in tegra_pcie_enable_system_interrupts()
734 val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base + in tegra_pcie_enable_system_interrupts()
737 dw_pcie_writew_dbi(&pcie->pci, pcie->pcie_cap_base + PCI_EXP_LNKCTL, in tegra_pcie_enable_system_interrupts()
744 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_legacy_interrupts() local
748 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_legacy_interrupts()
751 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_legacy_interrupts()
753 val = appl_readl(pcie, APPL_INTR_EN_L1_8_0); in tegra_pcie_enable_legacy_interrupts()
759 appl_writel(pcie, val, APPL_INTR_EN_L1_8_0); in tegra_pcie_enable_legacy_interrupts()
765 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_msi_interrupts() local
771 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_msi_interrupts()
774 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_msi_interrupts()
780 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_interrupts() local
783 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in tegra_pcie_enable_interrupts()
784 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_enable_interrupts()
785 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in tegra_pcie_enable_interrupts()
786 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in tegra_pcie_enable_interrupts()
787 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in tegra_pcie_enable_interrupts()
788 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in tegra_pcie_enable_interrupts()
789 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in tegra_pcie_enable_interrupts()
790 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in tegra_pcie_enable_interrupts()
791 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in tegra_pcie_enable_interrupts()
792 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in tegra_pcie_enable_interrupts()
793 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in tegra_pcie_enable_interrupts()
794 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in tegra_pcie_enable_interrupts()
795 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in tegra_pcie_enable_interrupts()
796 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in tegra_pcie_enable_interrupts()
797 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in tegra_pcie_enable_interrupts()
805 static void config_gen3_gen4_eq_presets(struct tegra_pcie_dw *pcie) in config_gen3_gen4_eq_presets() argument
807 struct dw_pcie *pci = &pcie->pci; in config_gen3_gen4_eq_presets()
811 for (i = 0; i < pcie->num_lanes; i++) { in config_gen3_gen4_eq_presets()
861 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_prepare_host() local
883 val = dw_pcie_readl_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKCAP); in tegra_pcie_prepare_host()
885 val |= (pcie->num_lanes << PCI_EXP_LNKSTA_NLW_SHIFT); in tegra_pcie_prepare_host()
886 dw_pcie_writel_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKCAP, val); in tegra_pcie_prepare_host()
888 config_gen3_gen4_eq_presets(pcie); in tegra_pcie_prepare_host()
890 init_host_aspm(pcie); in tegra_pcie_prepare_host()
896 if (pcie->update_fc_fixup) { in tegra_pcie_prepare_host()
904 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ); in tegra_pcie_prepare_host()
907 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_prepare_host()
909 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_prepare_host()
914 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_prepare_host()
916 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_prepare_host()
918 /* De-assert RST */ in tegra_pcie_prepare_host()
919 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_prepare_host()
921 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_prepare_host()
929 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_host_init() local
932 pp->bridge->ops = &tegra_pci_ops; in tegra_pcie_dw_host_init()
945 val = appl_readl(pcie, APPL_DEBUG); in tegra_pcie_dw_host_init()
948 tmp = appl_readl(pcie, APPL_LINK_STATUS); in tegra_pcie_dw_host_init()
955 dev_info(pci->dev, "Link is down in DLL"); in tegra_pcie_dw_host_init()
956 dev_info(pci->dev, "Trying again with DLFE disabled\n"); in tegra_pcie_dw_host_init()
958 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_host_init()
960 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_host_init()
962 reset_control_assert(pcie->core_rst); in tegra_pcie_dw_host_init()
963 reset_control_deassert(pcie->core_rst); in tegra_pcie_dw_host_init()
976 speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) & in tegra_pcie_dw_host_init()
978 clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]); in tegra_pcie_dw_host_init()
987 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_link_up() local
988 u32 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA); in tegra_pcie_dw_link_up()
995 pp->num_vectors = MAX_MSI_IRQS; in tegra_pcie_set_msi_vec_num()
1000 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_start_link() local
1002 enable_irq(pcie->pex_rst_irq); in tegra_pcie_dw_start_link()
1009 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_stop_link() local
1011 disable_irq(pcie->pex_rst_irq); in tegra_pcie_dw_stop_link()
1025 static void tegra_pcie_disable_phy(struct tegra_pcie_dw *pcie) in tegra_pcie_disable_phy() argument
1027 unsigned int phy_count = pcie->phy_count; in tegra_pcie_disable_phy()
1029 while (phy_count--) { in tegra_pcie_disable_phy()
1030 phy_power_off(pcie->phys[phy_count]); in tegra_pcie_disable_phy()
1031 phy_exit(pcie->phys[phy_count]); in tegra_pcie_disable_phy()
1035 static int tegra_pcie_enable_phy(struct tegra_pcie_dw *pcie) in tegra_pcie_enable_phy() argument
1040 for (i = 0; i < pcie->phy_count; i++) { in tegra_pcie_enable_phy()
1041 ret = phy_init(pcie->phys[i]); in tegra_pcie_enable_phy()
1045 ret = phy_power_on(pcie->phys[i]); in tegra_pcie_enable_phy()
1053 while (i--) { in tegra_pcie_enable_phy()
1054 phy_power_off(pcie->phys[i]); in tegra_pcie_enable_phy()
1056 phy_exit(pcie->phys[i]); in tegra_pcie_enable_phy()
1062 static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie) in tegra_pcie_dw_parse_dt() argument
1064 struct device_node *np = pcie->dev->of_node; in tegra_pcie_dw_parse_dt()
1067 ret = of_property_read_u32(np, "nvidia,aspm-cmrt-us", &pcie->aspm_cmrt); in tegra_pcie_dw_parse_dt()
1069 dev_info(pcie->dev, "Failed to read ASPM T_cmrt: %d\n", ret); in tegra_pcie_dw_parse_dt()
1073 ret = of_property_read_u32(np, "nvidia,aspm-pwr-on-t-us", in tegra_pcie_dw_parse_dt()
1074 &pcie->aspm_pwr_on_t); in tegra_pcie_dw_parse_dt()
1076 dev_info(pcie->dev, "Failed to read ASPM Power On time: %d\n", in tegra_pcie_dw_parse_dt()
1079 ret = of_property_read_u32(np, "nvidia,aspm-l0s-entrance-latency-us", in tegra_pcie_dw_parse_dt()
1080 &pcie->aspm_l0s_enter_lat); in tegra_pcie_dw_parse_dt()
1082 dev_info(pcie->dev, in tegra_pcie_dw_parse_dt()
1085 ret = of_property_read_u32(np, "num-lanes", &pcie->num_lanes); in tegra_pcie_dw_parse_dt()
1087 dev_err(pcie->dev, "Failed to read num-lanes: %d\n", ret); in tegra_pcie_dw_parse_dt()
1091 ret = of_property_read_u32_index(np, "nvidia,bpmp", 1, &pcie->cid); in tegra_pcie_dw_parse_dt()
1093 dev_err(pcie->dev, "Failed to read Controller-ID: %d\n", ret); in tegra_pcie_dw_parse_dt()
1097 ret = of_property_count_strings(np, "phy-names"); in tegra_pcie_dw_parse_dt()
1099 dev_err(pcie->dev, "Failed to find PHY entries: %d\n", in tegra_pcie_dw_parse_dt()
1103 pcie->phy_count = ret; in tegra_pcie_dw_parse_dt()
1105 if (of_property_read_bool(np, "nvidia,update-fc-fixup")) in tegra_pcie_dw_parse_dt()
1106 pcie->update_fc_fixup = true; in tegra_pcie_dw_parse_dt()
1108 pcie->supports_clkreq = in tegra_pcie_dw_parse_dt()
1109 of_property_read_bool(pcie->dev->of_node, "supports-clkreq"); in tegra_pcie_dw_parse_dt()
1111 pcie->enable_cdm_check = in tegra_pcie_dw_parse_dt()
1112 of_property_read_bool(np, "snps,enable-cdm-check"); in tegra_pcie_dw_parse_dt()
1114 if (pcie->mode == DW_PCIE_RC_TYPE) in tegra_pcie_dw_parse_dt()
1118 pcie->pex_rst_gpiod = devm_gpiod_get(pcie->dev, "reset", GPIOD_IN); in tegra_pcie_dw_parse_dt()
1119 if (IS_ERR(pcie->pex_rst_gpiod)) { in tegra_pcie_dw_parse_dt()
1120 int err = PTR_ERR(pcie->pex_rst_gpiod); in tegra_pcie_dw_parse_dt()
1123 if (err == -EPROBE_DEFER) in tegra_pcie_dw_parse_dt()
1126 dev_printk(level, pcie->dev, in tegra_pcie_dw_parse_dt()
1132 pcie->pex_refclk_sel_gpiod = devm_gpiod_get(pcie->dev, in tegra_pcie_dw_parse_dt()
1133 "nvidia,refclk-select", in tegra_pcie_dw_parse_dt()
1135 if (IS_ERR(pcie->pex_refclk_sel_gpiod)) { in tegra_pcie_dw_parse_dt()
1136 int err = PTR_ERR(pcie->pex_refclk_sel_gpiod); in tegra_pcie_dw_parse_dt()
1139 if (err == -EPROBE_DEFER) in tegra_pcie_dw_parse_dt()
1142 dev_printk(level, pcie->dev, in tegra_pcie_dw_parse_dt()
1145 pcie->pex_refclk_sel_gpiod = NULL; in tegra_pcie_dw_parse_dt()
1151 static int tegra_pcie_bpmp_set_ctrl_state(struct tegra_pcie_dw *pcie, in tegra_pcie_bpmp_set_ctrl_state() argument
1158 /* Controller-5 doesn't need to have its state set by BPMP-FW */ in tegra_pcie_bpmp_set_ctrl_state()
1159 if (pcie->cid == 5) in tegra_pcie_bpmp_set_ctrl_state()
1166 req.controller_state.pcie_controller = pcie->cid; in tegra_pcie_bpmp_set_ctrl_state()
1176 return tegra_bpmp_transfer(pcie->bpmp, &msg); in tegra_pcie_bpmp_set_ctrl_state()
1179 static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie, in tegra_pcie_bpmp_set_pll_state() argument
1191 req.ep_ctrlr_pll_init.ep_controller = pcie->cid; in tegra_pcie_bpmp_set_pll_state()
1194 req.ep_ctrlr_pll_off.ep_controller = pcie->cid; in tegra_pcie_bpmp_set_pll_state()
1204 return tegra_bpmp_transfer(pcie->bpmp, &msg); in tegra_pcie_bpmp_set_pll_state()
1207 static void tegra_pcie_downstream_dev_to_D0(struct tegra_pcie_dw *pcie) in tegra_pcie_downstream_dev_to_D0() argument
1209 struct pcie_port *pp = &pcie->pci.pp; in tegra_pcie_downstream_dev_to_D0()
1218 * This is as per PCI Express Base r4.0 v1.0 September 27-2017, in tegra_pcie_downstream_dev_to_D0()
1222 list_for_each_entry(child, &pp->bridge->bus->children, node) { in tegra_pcie_downstream_dev_to_D0()
1224 if (child->parent == pp->bridge->bus) { in tegra_pcie_downstream_dev_to_D0()
1231 dev_err(pcie->dev, "Failed to find downstream devices\n"); in tegra_pcie_downstream_dev_to_D0()
1235 list_for_each_entry(pdev, &root_bus->devices, bus_list) { in tegra_pcie_downstream_dev_to_D0()
1236 if (PCI_SLOT(pdev->devfn) == 0) { in tegra_pcie_downstream_dev_to_D0()
1238 dev_err(pcie->dev, in tegra_pcie_downstream_dev_to_D0()
1240 dev_name(&pdev->dev)); in tegra_pcie_downstream_dev_to_D0()
1245 static int tegra_pcie_get_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_get_slot_regulators() argument
1247 pcie->slot_ctl_3v3 = devm_regulator_get_optional(pcie->dev, "vpcie3v3"); in tegra_pcie_get_slot_regulators()
1248 if (IS_ERR(pcie->slot_ctl_3v3)) { in tegra_pcie_get_slot_regulators()
1249 if (PTR_ERR(pcie->slot_ctl_3v3) != -ENODEV) in tegra_pcie_get_slot_regulators()
1250 return PTR_ERR(pcie->slot_ctl_3v3); in tegra_pcie_get_slot_regulators()
1252 pcie->slot_ctl_3v3 = NULL; in tegra_pcie_get_slot_regulators()
1255 pcie->slot_ctl_12v = devm_regulator_get_optional(pcie->dev, "vpcie12v"); in tegra_pcie_get_slot_regulators()
1256 if (IS_ERR(pcie->slot_ctl_12v)) { in tegra_pcie_get_slot_regulators()
1257 if (PTR_ERR(pcie->slot_ctl_12v) != -ENODEV) in tegra_pcie_get_slot_regulators()
1258 return PTR_ERR(pcie->slot_ctl_12v); in tegra_pcie_get_slot_regulators()
1260 pcie->slot_ctl_12v = NULL; in tegra_pcie_get_slot_regulators()
1266 static int tegra_pcie_enable_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_enable_slot_regulators() argument
1270 if (pcie->slot_ctl_3v3) { in tegra_pcie_enable_slot_regulators()
1271 ret = regulator_enable(pcie->slot_ctl_3v3); in tegra_pcie_enable_slot_regulators()
1273 dev_err(pcie->dev, in tegra_pcie_enable_slot_regulators()
1279 if (pcie->slot_ctl_12v) { in tegra_pcie_enable_slot_regulators()
1280 ret = regulator_enable(pcie->slot_ctl_12v); in tegra_pcie_enable_slot_regulators()
1282 dev_err(pcie->dev, in tegra_pcie_enable_slot_regulators()
1290 * Revision 1.1, Table-2.4, T_PVPERL (Power stable to PERST# inactive) in tegra_pcie_enable_slot_regulators()
1293 if (pcie->slot_ctl_3v3 || pcie->slot_ctl_12v) in tegra_pcie_enable_slot_regulators()
1299 if (pcie->slot_ctl_3v3) in tegra_pcie_enable_slot_regulators()
1300 regulator_disable(pcie->slot_ctl_3v3); in tegra_pcie_enable_slot_regulators()
1304 static void tegra_pcie_disable_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_disable_slot_regulators() argument
1306 if (pcie->slot_ctl_12v) in tegra_pcie_disable_slot_regulators()
1307 regulator_disable(pcie->slot_ctl_12v); in tegra_pcie_disable_slot_regulators()
1308 if (pcie->slot_ctl_3v3) in tegra_pcie_disable_slot_regulators()
1309 regulator_disable(pcie->slot_ctl_3v3); in tegra_pcie_disable_slot_regulators()
1312 static int tegra_pcie_config_controller(struct tegra_pcie_dw *pcie, in tegra_pcie_config_controller() argument
1318 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true); in tegra_pcie_config_controller()
1320 dev_err(pcie->dev, in tegra_pcie_config_controller()
1321 "Failed to enable controller %u: %d\n", pcie->cid, ret); in tegra_pcie_config_controller()
1325 ret = tegra_pcie_enable_slot_regulators(pcie); in tegra_pcie_config_controller()
1329 ret = regulator_enable(pcie->pex_ctl_supply); in tegra_pcie_config_controller()
1331 dev_err(pcie->dev, "Failed to enable regulator: %d\n", ret); in tegra_pcie_config_controller()
1335 ret = clk_prepare_enable(pcie->core_clk); in tegra_pcie_config_controller()
1337 dev_err(pcie->dev, "Failed to enable core clock: %d\n", ret); in tegra_pcie_config_controller()
1341 ret = reset_control_deassert(pcie->core_apb_rst); in tegra_pcie_config_controller()
1343 dev_err(pcie->dev, "Failed to deassert core APB reset: %d\n", in tegra_pcie_config_controller()
1350 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_config_controller()
1354 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_config_controller()
1357 ret = tegra_pcie_enable_phy(pcie); in tegra_pcie_config_controller()
1359 dev_err(pcie->dev, "Failed to enable PHY: %d\n", ret); in tegra_pcie_config_controller()
1364 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK, in tegra_pcie_config_controller()
1368 appl_writel(pcie, APPL_DM_TYPE_RP, APPL_DM_TYPE); in tegra_pcie_config_controller()
1370 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE); in tegra_pcie_config_controller()
1372 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_config_controller()
1373 appl_writel(pcie, val | APPL_CTRL_SYS_PRE_DET_STATE, APPL_CTRL); in tegra_pcie_config_controller()
1375 val = appl_readl(pcie, APPL_CFG_MISC); in tegra_pcie_config_controller()
1377 appl_writel(pcie, val, APPL_CFG_MISC); in tegra_pcie_config_controller()
1379 if (!pcie->supports_clkreq) { in tegra_pcie_config_controller()
1380 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_config_controller()
1383 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_config_controller()
1387 appl_writel(pcie, in tegra_pcie_config_controller()
1388 pcie->atu_dma_res->start & APPL_CFG_IATU_DMA_BASE_ADDR_MASK, in tegra_pcie_config_controller()
1391 reset_control_deassert(pcie->core_rst); in tegra_pcie_config_controller()
1393 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci, in tegra_pcie_config_controller()
1396 /* Disable ASPM-L1SS advertisement as there is no CLKREQ routing */ in tegra_pcie_config_controller()
1397 if (!pcie->supports_clkreq) { in tegra_pcie_config_controller()
1398 disable_aspm_l11(pcie); in tegra_pcie_config_controller()
1399 disable_aspm_l12(pcie); in tegra_pcie_config_controller()
1405 reset_control_assert(pcie->core_apb_rst); in tegra_pcie_config_controller()
1407 clk_disable_unprepare(pcie->core_clk); in tegra_pcie_config_controller()
1409 regulator_disable(pcie->pex_ctl_supply); in tegra_pcie_config_controller()
1411 tegra_pcie_disable_slot_regulators(pcie); in tegra_pcie_config_controller()
1413 tegra_pcie_bpmp_set_ctrl_state(pcie, false); in tegra_pcie_config_controller()
1418 static int __deinit_controller(struct tegra_pcie_dw *pcie) in __deinit_controller() argument
1422 ret = reset_control_assert(pcie->core_rst); in __deinit_controller()
1424 dev_err(pcie->dev, "Failed to assert \"core\" reset: %d\n", in __deinit_controller()
1429 tegra_pcie_disable_phy(pcie); in __deinit_controller()
1431 ret = reset_control_assert(pcie->core_apb_rst); in __deinit_controller()
1433 dev_err(pcie->dev, "Failed to assert APB reset: %d\n", ret); in __deinit_controller()
1437 clk_disable_unprepare(pcie->core_clk); in __deinit_controller()
1439 ret = regulator_disable(pcie->pex_ctl_supply); in __deinit_controller()
1441 dev_err(pcie->dev, "Failed to disable regulator: %d\n", ret); in __deinit_controller()
1445 tegra_pcie_disable_slot_regulators(pcie); in __deinit_controller()
1447 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, false); in __deinit_controller()
1449 dev_err(pcie->dev, "Failed to disable controller %d: %d\n", in __deinit_controller()
1450 pcie->cid, ret); in __deinit_controller()
1457 static int tegra_pcie_init_controller(struct tegra_pcie_dw *pcie) in tegra_pcie_init_controller() argument
1459 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_init_controller()
1460 struct pcie_port *pp = &pci->pp; in tegra_pcie_init_controller()
1463 ret = tegra_pcie_config_controller(pcie, false); in tegra_pcie_init_controller()
1467 pp->ops = &tegra_pcie_dw_host_ops; in tegra_pcie_init_controller()
1471 dev_err(pcie->dev, "Failed to add PCIe port: %d\n", ret); in tegra_pcie_init_controller()
1478 return __deinit_controller(pcie); in tegra_pcie_init_controller()
1481 static int tegra_pcie_try_link_l2(struct tegra_pcie_dw *pcie) in tegra_pcie_try_link_l2() argument
1485 if (!tegra_pcie_dw_link_up(&pcie->pci)) in tegra_pcie_try_link_l2()
1488 val = appl_readl(pcie, APPL_RADM_STATUS); in tegra_pcie_try_link_l2()
1490 appl_writel(pcie, val, APPL_RADM_STATUS); in tegra_pcie_try_link_l2()
1492 return readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, val, in tegra_pcie_try_link_l2()
1497 static void tegra_pcie_dw_pme_turnoff(struct tegra_pcie_dw *pcie) in tegra_pcie_dw_pme_turnoff() argument
1502 if (!tegra_pcie_dw_link_up(&pcie->pci)) { in tegra_pcie_dw_pme_turnoff()
1503 dev_dbg(pcie->dev, "PCIe link is not up...!\n"); in tegra_pcie_dw_pme_turnoff()
1507 if (tegra_pcie_try_link_l2(pcie)) { in tegra_pcie_dw_pme_turnoff()
1508 dev_info(pcie->dev, "Link didn't transition to L2 state\n"); in tegra_pcie_dw_pme_turnoff()
1515 data = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1517 appl_writel(pcie, data, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1519 err = readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, in tegra_pcie_dw_pme_turnoff()
1527 dev_info(pcie->dev, "Link didn't go to detect state\n"); in tegra_pcie_dw_pme_turnoff()
1530 data = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_pme_turnoff()
1532 appl_writel(pcie, data, APPL_CTRL); in tegra_pcie_dw_pme_turnoff()
1536 * DBI registers may not be accessible after this as PLL-E would be in tegra_pcie_dw_pme_turnoff()
1539 data = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1544 appl_writel(pcie, data, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1547 static int tegra_pcie_deinit_controller(struct tegra_pcie_dw *pcie) in tegra_pcie_deinit_controller() argument
1549 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_deinit_controller()
1550 dw_pcie_host_deinit(&pcie->pci.pp); in tegra_pcie_deinit_controller()
1551 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_deinit_controller()
1553 return __deinit_controller(pcie); in tegra_pcie_deinit_controller()
1556 static int tegra_pcie_config_rp(struct tegra_pcie_dw *pcie) in tegra_pcie_config_rp() argument
1558 struct pcie_port *pp = &pcie->pci.pp; in tegra_pcie_config_rp()
1559 struct device *dev = pcie->dev; in tegra_pcie_config_rp()
1564 pp->msi_irq = of_irq_get_byname(dev->of_node, "msi"); in tegra_pcie_config_rp()
1565 if (!pp->msi_irq) { in tegra_pcie_config_rp()
1567 return -ENODEV; in tegra_pcie_config_rp()
1575 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n", in tegra_pcie_config_rp()
1586 tegra_pcie_init_controller(pcie); in tegra_pcie_config_rp()
1588 pcie->link_state = tegra_pcie_dw_link_up(&pcie->pci); in tegra_pcie_config_rp()
1589 if (!pcie->link_state) { in tegra_pcie_config_rp()
1590 ret = -ENOMEDIUM; in tegra_pcie_config_rp()
1594 name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node); in tegra_pcie_config_rp()
1596 ret = -ENOMEM; in tegra_pcie_config_rp()
1600 pcie->debugfs = debugfs_create_dir(name, NULL); in tegra_pcie_config_rp()
1601 init_debugfs(pcie); in tegra_pcie_config_rp()
1606 tegra_pcie_deinit_controller(pcie); in tegra_pcie_config_rp()
1613 static void pex_ep_event_pex_rst_assert(struct tegra_pcie_dw *pcie) in pex_ep_event_pex_rst_assert() argument
1618 if (pcie->ep_state == EP_STATE_DISABLED) in pex_ep_event_pex_rst_assert()
1622 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_assert()
1624 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_assert()
1626 ret = readl_poll_timeout(pcie->appl_base + APPL_DEBUG, val, in pex_ep_event_pex_rst_assert()
1632 dev_err(pcie->dev, "Failed to go Detect state: %d\n", ret); in pex_ep_event_pex_rst_assert()
1634 reset_control_assert(pcie->core_rst); in pex_ep_event_pex_rst_assert()
1636 tegra_pcie_disable_phy(pcie); in pex_ep_event_pex_rst_assert()
1638 reset_control_assert(pcie->core_apb_rst); in pex_ep_event_pex_rst_assert()
1640 clk_disable_unprepare(pcie->core_clk); in pex_ep_event_pex_rst_assert()
1642 pm_runtime_put_sync(pcie->dev); in pex_ep_event_pex_rst_assert()
1644 ret = tegra_pcie_bpmp_set_pll_state(pcie, false); in pex_ep_event_pex_rst_assert()
1646 dev_err(pcie->dev, "Failed to turn off UPHY: %d\n", ret); in pex_ep_event_pex_rst_assert()
1648 pcie->ep_state = EP_STATE_DISABLED; in pex_ep_event_pex_rst_assert()
1649 dev_dbg(pcie->dev, "Uninitialization of endpoint is completed\n"); in pex_ep_event_pex_rst_assert()
1652 static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie) in pex_ep_event_pex_rst_deassert() argument
1654 struct dw_pcie *pci = &pcie->pci; in pex_ep_event_pex_rst_deassert()
1655 struct dw_pcie_ep *ep = &pci->ep; in pex_ep_event_pex_rst_deassert() local
1656 struct device *dev = pcie->dev; in pex_ep_event_pex_rst_deassert()
1660 if (pcie->ep_state == EP_STATE_ENABLED) in pex_ep_event_pex_rst_deassert()
1665 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n", in pex_ep_event_pex_rst_deassert()
1670 ret = tegra_pcie_bpmp_set_pll_state(pcie, true); in pex_ep_event_pex_rst_deassert()
1672 dev_err(dev, "Failed to init UPHY for PCIe EP: %d\n", ret); in pex_ep_event_pex_rst_deassert()
1676 ret = clk_prepare_enable(pcie->core_clk); in pex_ep_event_pex_rst_deassert()
1682 ret = reset_control_deassert(pcie->core_apb_rst); in pex_ep_event_pex_rst_deassert()
1688 ret = tegra_pcie_enable_phy(pcie); in pex_ep_event_pex_rst_deassert()
1695 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in pex_ep_event_pex_rst_deassert()
1696 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in pex_ep_event_pex_rst_deassert()
1697 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in pex_ep_event_pex_rst_deassert()
1698 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in pex_ep_event_pex_rst_deassert()
1699 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in pex_ep_event_pex_rst_deassert()
1700 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in pex_ep_event_pex_rst_deassert()
1701 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in pex_ep_event_pex_rst_deassert()
1702 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in pex_ep_event_pex_rst_deassert()
1703 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in pex_ep_event_pex_rst_deassert()
1704 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in pex_ep_event_pex_rst_deassert()
1705 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in pex_ep_event_pex_rst_deassert()
1706 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in pex_ep_event_pex_rst_deassert()
1707 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in pex_ep_event_pex_rst_deassert()
1708 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in pex_ep_event_pex_rst_deassert()
1709 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in pex_ep_event_pex_rst_deassert()
1711 /* configure this core for EP mode operation */ in pex_ep_event_pex_rst_deassert()
1712 val = appl_readl(pcie, APPL_DM_TYPE); in pex_ep_event_pex_rst_deassert()
1715 appl_writel(pcie, val, APPL_DM_TYPE); in pex_ep_event_pex_rst_deassert()
1717 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE); in pex_ep_event_pex_rst_deassert()
1719 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1722 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1724 val = appl_readl(pcie, APPL_CFG_MISC); in pex_ep_event_pex_rst_deassert()
1727 appl_writel(pcie, val, APPL_CFG_MISC); in pex_ep_event_pex_rst_deassert()
1729 val = appl_readl(pcie, APPL_PINMUX); in pex_ep_event_pex_rst_deassert()
1732 appl_writel(pcie, val, APPL_PINMUX); in pex_ep_event_pex_rst_deassert()
1734 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK, in pex_ep_event_pex_rst_deassert()
1737 appl_writel(pcie, pcie->atu_dma_res->start & in pex_ep_event_pex_rst_deassert()
1741 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in pex_ep_event_pex_rst_deassert()
1745 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in pex_ep_event_pex_rst_deassert()
1747 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0); in pex_ep_event_pex_rst_deassert()
1750 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0); in pex_ep_event_pex_rst_deassert()
1752 reset_control_deassert(pcie->core_rst); in pex_ep_event_pex_rst_deassert()
1754 if (pcie->update_fc_fixup) { in pex_ep_event_pex_rst_deassert()
1760 config_gen3_gen4_eq_presets(pcie); in pex_ep_event_pex_rst_deassert()
1762 init_host_aspm(pcie); in pex_ep_event_pex_rst_deassert()
1764 /* Disable ASPM-L1SS advertisement if there is no CLKREQ routing */ in pex_ep_event_pex_rst_deassert()
1765 if (!pcie->supports_clkreq) { in pex_ep_event_pex_rst_deassert()
1766 disable_aspm_l11(pcie); in pex_ep_event_pex_rst_deassert()
1767 disable_aspm_l12(pcie); in pex_ep_event_pex_rst_deassert()
1774 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci, in pex_ep_event_pex_rst_deassert()
1776 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ); in pex_ep_event_pex_rst_deassert()
1778 val = (ep->msi_mem_phys & MSIX_ADDR_MATCH_LOW_OFF_MASK); in pex_ep_event_pex_rst_deassert()
1781 val = (lower_32_bits(ep->msi_mem_phys) & MSIX_ADDR_MATCH_HIGH_OFF_MASK); in pex_ep_event_pex_rst_deassert()
1784 ret = dw_pcie_ep_init_complete(ep); in pex_ep_event_pex_rst_deassert()
1790 dw_pcie_ep_init_notify(ep); in pex_ep_event_pex_rst_deassert()
1793 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1795 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1797 pcie->ep_state = EP_STATE_ENABLED; in pex_ep_event_pex_rst_deassert()
1803 reset_control_assert(pcie->core_rst); in pex_ep_event_pex_rst_deassert()
1804 tegra_pcie_disable_phy(pcie); in pex_ep_event_pex_rst_deassert()
1806 reset_control_assert(pcie->core_apb_rst); in pex_ep_event_pex_rst_deassert()
1808 clk_disable_unprepare(pcie->core_clk); in pex_ep_event_pex_rst_deassert()
1810 tegra_pcie_bpmp_set_pll_state(pcie, false); in pex_ep_event_pex_rst_deassert()
1817 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_pex_rst_irq() local
1819 if (gpiod_get_value(pcie->pex_rst_gpiod)) in tegra_pcie_ep_pex_rst_irq()
1820 pex_ep_event_pex_rst_assert(pcie); in tegra_pcie_ep_pex_rst_irq()
1822 pex_ep_event_pex_rst_deassert(pcie); in tegra_pcie_ep_pex_rst_irq()
1827 static int tegra_pcie_ep_raise_legacy_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_legacy_irq() argument
1831 return -EINVAL; in tegra_pcie_ep_raise_legacy_irq()
1833 appl_writel(pcie, 1, APPL_LEGACY_INTX); in tegra_pcie_ep_raise_legacy_irq()
1835 appl_writel(pcie, 0, APPL_LEGACY_INTX); in tegra_pcie_ep_raise_legacy_irq()
1839 static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_msi_irq() argument
1842 return -EINVAL; in tegra_pcie_ep_raise_msi_irq()
1844 appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1); in tegra_pcie_ep_raise_msi_irq()
1849 static int tegra_pcie_ep_raise_msix_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_msix_irq() argument
1851 struct dw_pcie_ep *ep = &pcie->pci.ep; in tegra_pcie_ep_raise_msix_irq() local
1853 writel(irq, ep->msi_mem); in tegra_pcie_ep_raise_msix_irq()
1858 static int tegra_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, in tegra_pcie_ep_raise_irq() argument
1862 struct dw_pcie *pci = to_dw_pcie_from_ep(ep); in tegra_pcie_ep_raise_irq()
1863 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_ep_raise_irq() local
1867 return tegra_pcie_ep_raise_legacy_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
1870 return tegra_pcie_ep_raise_msi_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
1873 return tegra_pcie_ep_raise_msix_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
1876 dev_err(pci->dev, "Unknown IRQ type\n"); in tegra_pcie_ep_raise_irq()
1877 return -EPERM; in tegra_pcie_ep_raise_irq()
1894 tegra_pcie_ep_get_features(struct dw_pcie_ep *ep) in tegra_pcie_ep_get_features() argument
1904 static int tegra_pcie_config_ep(struct tegra_pcie_dw *pcie, in tegra_pcie_config_ep() argument
1907 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_config_ep()
1908 struct device *dev = pcie->dev; in tegra_pcie_config_ep()
1909 struct dw_pcie_ep *ep; in tegra_pcie_config_ep() local
1914 ep = &pci->ep; in tegra_pcie_config_ep()
1915 ep->ops = &pcie_ep_ops; in tegra_pcie_config_ep()
1919 return -EINVAL; in tegra_pcie_config_ep()
1921 ep->phys_base = res->start; in tegra_pcie_config_ep()
1922 ep->addr_size = resource_size(res); in tegra_pcie_config_ep()
1923 ep->page_size = SZ_64K; in tegra_pcie_config_ep()
1925 ret = gpiod_set_debounce(pcie->pex_rst_gpiod, PERST_DEBOUNCE_TIME); in tegra_pcie_config_ep()
1932 ret = gpiod_to_irq(pcie->pex_rst_gpiod); in tegra_pcie_config_ep()
1937 pcie->pex_rst_irq = (unsigned int)ret; in tegra_pcie_config_ep()
1940 pcie->cid); in tegra_pcie_config_ep()
1943 return -ENOMEM; in tegra_pcie_config_ep()
1946 irq_set_status_flags(pcie->pex_rst_irq, IRQ_NOAUTOEN); in tegra_pcie_config_ep()
1948 pcie->ep_state = EP_STATE_DISABLED; in tegra_pcie_config_ep()
1950 ret = devm_request_threaded_irq(dev, pcie->pex_rst_irq, NULL, in tegra_pcie_config_ep()
1954 name, (void *)pcie); in tegra_pcie_config_ep()
1961 pcie->cid); in tegra_pcie_config_ep()
1963 dev_err(dev, "Failed to create PCIe EP work thread string\n"); in tegra_pcie_config_ep()
1964 return -ENOMEM; in tegra_pcie_config_ep()
1969 ret = dw_pcie_ep_init(ep); in tegra_pcie_config_ep()
1982 struct device *dev = &pdev->dev; in tegra_pcie_dw_probe()
1984 struct tegra_pcie_dw *pcie; in tegra_pcie_dw_probe() local
1995 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); in tegra_pcie_dw_probe()
1996 if (!pcie) in tegra_pcie_dw_probe()
1997 return -ENOMEM; in tegra_pcie_dw_probe()
1999 pci = &pcie->pci; in tegra_pcie_dw_probe()
2000 pci->dev = &pdev->dev; in tegra_pcie_dw_probe()
2001 pci->ops = &tegra_dw_pcie_ops; in tegra_pcie_dw_probe()
2002 pci->n_fts[0] = N_FTS_VAL; in tegra_pcie_dw_probe()
2003 pci->n_fts[1] = FTS_VAL; in tegra_pcie_dw_probe()
2005 pp = &pci->pp; in tegra_pcie_dw_probe()
2006 pcie->dev = &pdev->dev; in tegra_pcie_dw_probe()
2007 pcie->mode = (enum dw_pcie_device_mode)data->mode; in tegra_pcie_dw_probe()
2009 ret = tegra_pcie_dw_parse_dt(pcie); in tegra_pcie_dw_probe()
2013 if (ret == -EPROBE_DEFER) in tegra_pcie_dw_probe()
2022 ret = tegra_pcie_get_slot_regulators(pcie); in tegra_pcie_dw_probe()
2026 if (ret == -EPROBE_DEFER) in tegra_pcie_dw_probe()
2035 if (pcie->pex_refclk_sel_gpiod) in tegra_pcie_dw_probe()
2036 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 1); in tegra_pcie_dw_probe()
2038 pcie->pex_ctl_supply = devm_regulator_get(dev, "vddio-pex-ctl"); in tegra_pcie_dw_probe()
2039 if (IS_ERR(pcie->pex_ctl_supply)) { in tegra_pcie_dw_probe()
2040 ret = PTR_ERR(pcie->pex_ctl_supply); in tegra_pcie_dw_probe()
2041 if (ret != -EPROBE_DEFER) in tegra_pcie_dw_probe()
2043 PTR_ERR(pcie->pex_ctl_supply)); in tegra_pcie_dw_probe()
2047 pcie->core_clk = devm_clk_get(dev, "core"); in tegra_pcie_dw_probe()
2048 if (IS_ERR(pcie->core_clk)) { in tegra_pcie_dw_probe()
2050 PTR_ERR(pcie->core_clk)); in tegra_pcie_dw_probe()
2051 return PTR_ERR(pcie->core_clk); in tegra_pcie_dw_probe()
2054 pcie->appl_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, in tegra_pcie_dw_probe()
2056 if (!pcie->appl_res) { in tegra_pcie_dw_probe()
2058 return -ENODEV; in tegra_pcie_dw_probe()
2061 pcie->appl_base = devm_ioremap_resource(dev, pcie->appl_res); in tegra_pcie_dw_probe()
2062 if (IS_ERR(pcie->appl_base)) in tegra_pcie_dw_probe()
2063 return PTR_ERR(pcie->appl_base); in tegra_pcie_dw_probe()
2065 pcie->core_apb_rst = devm_reset_control_get(dev, "apb"); in tegra_pcie_dw_probe()
2066 if (IS_ERR(pcie->core_apb_rst)) { in tegra_pcie_dw_probe()
2068 PTR_ERR(pcie->core_apb_rst)); in tegra_pcie_dw_probe()
2069 return PTR_ERR(pcie->core_apb_rst); in tegra_pcie_dw_probe()
2072 phys = devm_kcalloc(dev, pcie->phy_count, sizeof(*phys), GFP_KERNEL); in tegra_pcie_dw_probe()
2074 return -ENOMEM; in tegra_pcie_dw_probe()
2076 for (i = 0; i < pcie->phy_count; i++) { in tegra_pcie_dw_probe()
2077 name = kasprintf(GFP_KERNEL, "p2u-%u", i); in tegra_pcie_dw_probe()
2080 return -ENOMEM; in tegra_pcie_dw_probe()
2086 if (ret != -EPROBE_DEFER) in tegra_pcie_dw_probe()
2092 pcie->phys = phys; in tegra_pcie_dw_probe()
2097 return -ENODEV; in tegra_pcie_dw_probe()
2099 pcie->dbi_res = dbi_res; in tegra_pcie_dw_probe()
2101 pci->dbi_base = devm_ioremap_resource(dev, dbi_res); in tegra_pcie_dw_probe()
2102 if (IS_ERR(pci->dbi_base)) in tegra_pcie_dw_probe()
2103 return PTR_ERR(pci->dbi_base); in tegra_pcie_dw_probe()
2106 pci->dbi_base2 = pci->dbi_base + 0x1000; in tegra_pcie_dw_probe()
2112 return -ENODEV; in tegra_pcie_dw_probe()
2114 pcie->atu_dma_res = atu_dma_res; in tegra_pcie_dw_probe()
2116 pci->atu_base = devm_ioremap_resource(dev, atu_dma_res); in tegra_pcie_dw_probe()
2117 if (IS_ERR(pci->atu_base)) in tegra_pcie_dw_probe()
2118 return PTR_ERR(pci->atu_base); in tegra_pcie_dw_probe()
2120 pcie->core_rst = devm_reset_control_get(dev, "core"); in tegra_pcie_dw_probe()
2121 if (IS_ERR(pcie->core_rst)) { in tegra_pcie_dw_probe()
2123 PTR_ERR(pcie->core_rst)); in tegra_pcie_dw_probe()
2124 return PTR_ERR(pcie->core_rst); in tegra_pcie_dw_probe()
2127 pp->irq = platform_get_irq_byname(pdev, "intr"); in tegra_pcie_dw_probe()
2128 if (pp->irq < 0) in tegra_pcie_dw_probe()
2129 return pp->irq; in tegra_pcie_dw_probe()
2131 pcie->bpmp = tegra_bpmp_get(dev); in tegra_pcie_dw_probe()
2132 if (IS_ERR(pcie->bpmp)) in tegra_pcie_dw_probe()
2133 return PTR_ERR(pcie->bpmp); in tegra_pcie_dw_probe()
2135 platform_set_drvdata(pdev, pcie); in tegra_pcie_dw_probe()
2137 switch (pcie->mode) { in tegra_pcie_dw_probe()
2139 ret = devm_request_irq(dev, pp->irq, tegra_pcie_rp_irq_handler, in tegra_pcie_dw_probe()
2140 IRQF_SHARED, "tegra-pcie-intr", pcie); in tegra_pcie_dw_probe()
2142 dev_err(dev, "Failed to request IRQ %d: %d\n", pp->irq, in tegra_pcie_dw_probe()
2147 ret = tegra_pcie_config_rp(pcie); in tegra_pcie_dw_probe()
2148 if (ret && ret != -ENOMEDIUM) in tegra_pcie_dw_probe()
2155 ret = devm_request_threaded_irq(dev, pp->irq, in tegra_pcie_dw_probe()
2159 "tegra-pcie-ep-intr", pcie); in tegra_pcie_dw_probe()
2161 dev_err(dev, "Failed to request IRQ %d: %d\n", pp->irq, in tegra_pcie_dw_probe()
2166 ret = tegra_pcie_config_ep(pcie, pdev); in tegra_pcie_dw_probe()
2172 dev_err(dev, "Invalid PCIe device type %d\n", pcie->mode); in tegra_pcie_dw_probe()
2176 tegra_bpmp_put(pcie->bpmp); in tegra_pcie_dw_probe()
2182 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev); in tegra_pcie_dw_remove() local
2184 if (!pcie->link_state) in tegra_pcie_dw_remove()
2187 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_dw_remove()
2188 tegra_pcie_deinit_controller(pcie); in tegra_pcie_dw_remove()
2189 pm_runtime_put_sync(pcie->dev); in tegra_pcie_dw_remove()
2190 pm_runtime_disable(pcie->dev); in tegra_pcie_dw_remove()
2191 tegra_bpmp_put(pcie->bpmp); in tegra_pcie_dw_remove()
2192 if (pcie->pex_refclk_sel_gpiod) in tegra_pcie_dw_remove()
2193 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 0); in tegra_pcie_dw_remove()
2200 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_suspend_late() local
2203 if (!pcie->link_state) in tegra_pcie_dw_suspend_late()
2207 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_suspend_late()
2211 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_suspend_late()
2218 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_suspend_noirq() local
2220 if (!pcie->link_state) in tegra_pcie_dw_suspend_noirq()
2224 pcie->msi_ctrl_int = dw_pcie_readl_dbi(&pcie->pci, in tegra_pcie_dw_suspend_noirq()
2226 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_dw_suspend_noirq()
2227 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_dw_suspend_noirq()
2229 return __deinit_controller(pcie); in tegra_pcie_dw_suspend_noirq()
2234 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_resume_noirq() local
2237 if (!pcie->link_state) in tegra_pcie_dw_resume_noirq()
2240 ret = tegra_pcie_config_controller(pcie, true); in tegra_pcie_dw_resume_noirq()
2244 ret = tegra_pcie_dw_host_init(&pcie->pci.pp); in tegra_pcie_dw_resume_noirq()
2251 dw_pcie_writel_dbi(&pcie->pci, PORT_LOGIC_MSI_CTRL_INT_0_EN, in tegra_pcie_dw_resume_noirq()
2252 pcie->msi_ctrl_int); in tegra_pcie_dw_resume_noirq()
2257 return __deinit_controller(pcie); in tegra_pcie_dw_resume_noirq()
2262 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_resume_early() local
2265 if (!pcie->link_state) in tegra_pcie_dw_resume_early()
2269 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_resume_early()
2275 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_resume_early()
2282 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev); in tegra_pcie_dw_shutdown() local
2284 if (!pcie->link_state) in tegra_pcie_dw_shutdown()
2287 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_dw_shutdown()
2288 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_dw_shutdown()
2290 disable_irq(pcie->pci.pp.irq); in tegra_pcie_dw_shutdown()
2292 disable_irq(pcie->pci.pp.msi_irq); in tegra_pcie_dw_shutdown()
2294 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_dw_shutdown()
2295 __deinit_controller(pcie); in tegra_pcie_dw_shutdown()
2308 .compatible = "nvidia,tegra194-pcie",
2312 .compatible = "nvidia,tegra194-pcie-ep",
2330 .name = "tegra194-pcie",
2340 MODULE_DESCRIPTION("NVIDIA PCIe host controller driver");