Lines Matching full:pcie

3  * PCIe host controller driver for the following SoCs
35 #include "pcie-designware.h"
300 static inline void appl_writel(struct tegra_pcie_dw *pcie, const u32 value, in appl_writel() argument
303 writel_relaxed(value, pcie->appl_base + reg); in appl_writel()
306 static inline u32 appl_readl(struct tegra_pcie_dw *pcie, const u32 reg) in appl_readl() argument
308 return readl_relaxed(pcie->appl_base + reg); in appl_readl()
315 static void tegra_pcie_icc_set(struct tegra_pcie_dw *pcie) in tegra_pcie_icc_set() argument
317 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_icc_set()
320 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA); in tegra_pcie_icc_set()
327 if (icc_set_bw(pcie->icc_path, Mbps_to_icc(val), 0)) in tegra_pcie_icc_set()
328 dev_err(pcie->dev, "can't set bw[%u]\n", val); in tegra_pcie_icc_set()
333 clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]); in tegra_pcie_icc_set()
339 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in apply_bad_link_workaround() local
348 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA); in apply_bad_link_workaround()
351 if (pcie->init_link_width > current_link_width) { in apply_bad_link_workaround()
352 dev_warn(pci->dev, "PCIe link is bad, width reduced\n"); in apply_bad_link_workaround()
353 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
357 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
360 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
363 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
371 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_rp_irq_handler() local
372 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_rp_irq_handler()
377 status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0); in tegra_pcie_rp_irq_handler()
379 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_rp_irq_handler()
380 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_rp_irq_handler()
381 if (!pcie->of_data->has_sbr_reset_fix && in tegra_pcie_rp_irq_handler()
384 val = appl_readl(pcie, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
386 appl_writel(pcie, val, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
388 val = appl_readl(pcie, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
390 appl_writel(pcie, val, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
399 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_8_0); in tegra_pcie_rp_irq_handler()
401 appl_writel(pcie, in tegra_pcie_rp_irq_handler()
407 val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in tegra_pcie_rp_irq_handler()
410 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + in tegra_pcie_rp_irq_handler()
413 appl_writel(pcie, in tegra_pcie_rp_irq_handler()
417 val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in tegra_pcie_rp_irq_handler()
425 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_18); in tegra_pcie_rp_irq_handler()
447 static void pex_ep_event_hot_rst_done(struct tegra_pcie_dw *pcie) in pex_ep_event_hot_rst_done() argument
451 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in pex_ep_event_hot_rst_done()
452 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in pex_ep_event_hot_rst_done()
453 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in pex_ep_event_hot_rst_done()
454 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in pex_ep_event_hot_rst_done()
455 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in pex_ep_event_hot_rst_done()
456 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in pex_ep_event_hot_rst_done()
457 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in pex_ep_event_hot_rst_done()
458 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in pex_ep_event_hot_rst_done()
459 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in pex_ep_event_hot_rst_done()
460 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in pex_ep_event_hot_rst_done()
461 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in pex_ep_event_hot_rst_done()
462 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in pex_ep_event_hot_rst_done()
463 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in pex_ep_event_hot_rst_done()
464 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in pex_ep_event_hot_rst_done()
465 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in pex_ep_event_hot_rst_done()
466 appl_writel(pcie, 0xFFFFFFFF, APPL_MSI_CTRL_2); in pex_ep_event_hot_rst_done()
468 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_hot_rst_done()
470 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_hot_rst_done()
475 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_irq_thread() local
476 struct dw_pcie_ep *ep = &pcie->pci.ep; in tegra_pcie_ep_irq_thread()
477 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_ep_irq_thread()
480 if (test_and_clear_bit(0, &pcie->link_status)) in tegra_pcie_ep_irq_thread()
483 tegra_pcie_icc_set(pcie); in tegra_pcie_ep_irq_thread()
485 if (pcie->of_data->has_ltr_req_fix) in tegra_pcie_ep_irq_thread()
489 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub); in tegra_pcie_ep_irq_thread()
505 appl_writel(pcie, val, APPL_LTR_MSG_1); in tegra_pcie_ep_irq_thread()
508 val = appl_readl(pcie, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
510 appl_writel(pcie, val, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
514 val = appl_readl(pcie, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
522 dev_err(pcie->dev, "Failed to send LTR message\n"); in tegra_pcie_ep_irq_thread()
530 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_hard_irq() local
534 status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0); in tegra_pcie_ep_hard_irq()
536 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_ep_hard_irq()
537 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_ep_hard_irq()
540 pex_ep_event_hot_rst_done(pcie); in tegra_pcie_ep_hard_irq()
543 link_status = appl_readl(pcie, APPL_LINK_STATUS); in tegra_pcie_ep_hard_irq()
545 dev_dbg(pcie->dev, "Link is up with Host\n"); in tegra_pcie_ep_hard_irq()
546 set_bit(0, &pcie->link_status); in tegra_pcie_ep_hard_irq()
555 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_15); in tegra_pcie_ep_hard_irq()
556 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_15); in tegra_pcie_ep_hard_irq()
565 dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n", in tegra_pcie_ep_hard_irq()
567 appl_writel(pcie, status_l0, APPL_INTR_STATUS_L0); in tegra_pcie_ep_hard_irq()
578 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_rd_own_conf() local
586 if (!pcie->of_data->has_msix_doorbell_access_fix && in tegra_pcie_dw_rd_own_conf()
600 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_wr_own_conf() local
608 if (!pcie->of_data->has_msix_doorbell_access_fix && in tegra_pcie_dw_wr_own_conf()
622 static void disable_aspm_l11(struct tegra_pcie_dw *pcie) in disable_aspm_l11() argument
626 val = dw_pcie_readl_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub); in disable_aspm_l11()
628 dw_pcie_writel_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub, val); in disable_aspm_l11()
631 static void disable_aspm_l12(struct tegra_pcie_dw *pcie) in disable_aspm_l12() argument
635 val = dw_pcie_readl_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub); in disable_aspm_l12()
637 dw_pcie_writel_dbi(&pcie->pci, pcie->cfg_link_cap_l1sub, val); in disable_aspm_l12()
640 static inline u32 event_counter_prog(struct tegra_pcie_dw *pcie, u32 event) in event_counter_prog() argument
644 val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap + in event_counter_prog()
650 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap + in event_counter_prog()
652 val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap + in event_counter_prog()
660 struct tegra_pcie_dw *pcie = (struct tegra_pcie_dw *) in aspm_state_cnt() local
665 event_counter_prog(pcie, EVENT_COUNTER_EVENT_Tx_L0S)); in aspm_state_cnt()
668 event_counter_prog(pcie, EVENT_COUNTER_EVENT_Rx_L0S)); in aspm_state_cnt()
671 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1)); in aspm_state_cnt()
674 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_1)); in aspm_state_cnt()
677 event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_2)); in aspm_state_cnt()
680 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap + in aspm_state_cnt()
687 dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap + in aspm_state_cnt()
693 static void init_host_aspm(struct tegra_pcie_dw *pcie) in init_host_aspm() argument
695 struct dw_pcie *pci = &pcie->pci; in init_host_aspm()
699 pcie->cfg_link_cap_l1sub = val + PCI_L1SS_CAP; in init_host_aspm()
701 pcie->ras_des_cap = dw_pcie_find_ext_capability(&pcie->pci, in init_host_aspm()
707 dw_pcie_writel_dbi(pci, pcie->ras_des_cap + in init_host_aspm()
711 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub); in init_host_aspm()
713 val |= (pcie->aspm_cmrt << 8); in init_host_aspm()
714 val |= (pcie->aspm_pwr_on_t << 19); in init_host_aspm()
715 dw_pcie_writel_dbi(pci, pcie->cfg_link_cap_l1sub, val); in init_host_aspm()
720 val |= (pcie->aspm_l0s_enter_lat << PORT_AFR_L0S_ENTRANCE_LAT_SHIFT); in init_host_aspm()
725 static void init_debugfs(struct tegra_pcie_dw *pcie) in init_debugfs() argument
727 debugfs_create_devm_seqfile(pcie->dev, "aspm_state_cnt", pcie->debugfs, in init_debugfs()
731 static inline void disable_aspm_l12(struct tegra_pcie_dw *pcie) { return; } in disable_aspm_l12() argument
732 static inline void disable_aspm_l11(struct tegra_pcie_dw *pcie) { return; } in disable_aspm_l11() argument
733 static inline void init_host_aspm(struct tegra_pcie_dw *pcie) { return; } in init_host_aspm() argument
734 static inline void init_debugfs(struct tegra_pcie_dw *pcie) { return; } in init_debugfs() argument
740 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_system_interrupts() local
744 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_system_interrupts()
746 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_system_interrupts()
748 if (!pcie->of_data->has_sbr_reset_fix) { in tegra_pcie_enable_system_interrupts()
749 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0); in tegra_pcie_enable_system_interrupts()
751 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0); in tegra_pcie_enable_system_interrupts()
754 if (pcie->enable_cdm_check) { in tegra_pcie_enable_system_interrupts()
755 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_system_interrupts()
756 val |= pcie->of_data->cdm_chk_int_en_bit; in tegra_pcie_enable_system_interrupts()
757 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_system_interrupts()
759 val = appl_readl(pcie, APPL_INTR_EN_L1_18); in tegra_pcie_enable_system_interrupts()
762 appl_writel(pcie, val, APPL_INTR_EN_L1_18); in tegra_pcie_enable_system_interrupts()
765 val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base + in tegra_pcie_enable_system_interrupts()
767 pcie->init_link_width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val_w); in tegra_pcie_enable_system_interrupts()
769 val_w = dw_pcie_readw_dbi(&pcie->pci, pcie->pcie_cap_base + in tegra_pcie_enable_system_interrupts()
772 dw_pcie_writew_dbi(&pcie->pci, pcie->pcie_cap_base + PCI_EXP_LNKCTL, in tegra_pcie_enable_system_interrupts()
779 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_intx_interrupts() local
783 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_intx_interrupts()
786 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_intx_interrupts()
788 val = appl_readl(pcie, APPL_INTR_EN_L1_8_0); in tegra_pcie_enable_intx_interrupts()
794 appl_writel(pcie, val, APPL_INTR_EN_L1_8_0); in tegra_pcie_enable_intx_interrupts()
800 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_msi_interrupts() local
804 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_msi_interrupts()
807 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_msi_interrupts()
813 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_interrupts() local
816 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in tegra_pcie_enable_interrupts()
817 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_enable_interrupts()
818 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in tegra_pcie_enable_interrupts()
819 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in tegra_pcie_enable_interrupts()
820 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in tegra_pcie_enable_interrupts()
821 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in tegra_pcie_enable_interrupts()
822 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in tegra_pcie_enable_interrupts()
823 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in tegra_pcie_enable_interrupts()
824 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in tegra_pcie_enable_interrupts()
825 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in tegra_pcie_enable_interrupts()
826 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in tegra_pcie_enable_interrupts()
827 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in tegra_pcie_enable_interrupts()
828 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in tegra_pcie_enable_interrupts()
829 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in tegra_pcie_enable_interrupts()
830 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in tegra_pcie_enable_interrupts()
838 static void config_gen3_gen4_eq_presets(struct tegra_pcie_dw *pcie) in config_gen3_gen4_eq_presets() argument
840 struct dw_pcie *pci = &pcie->pci; in config_gen3_gen4_eq_presets()
844 for (i = 0; i < pcie->num_lanes; i++) { in config_gen3_gen4_eq_presets()
882 val |= (pcie->of_data->gen4_preset_vec << in config_gen3_gen4_eq_presets()
895 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_host_init() local
901 if (!pcie->pcie_cap_base) in tegra_pcie_dw_host_init()
902 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci, in tegra_pcie_dw_host_init()
924 if (pcie->enable_srns) { in tegra_pcie_dw_host_init()
925 val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in tegra_pcie_dw_host_init()
928 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA, in tegra_pcie_dw_host_init()
932 config_gen3_gen4_eq_presets(pcie); in tegra_pcie_dw_host_init()
934 init_host_aspm(pcie); in tegra_pcie_dw_host_init()
937 if (!pcie->supports_clkreq) { in tegra_pcie_dw_host_init()
938 disable_aspm_l11(pcie); in tegra_pcie_dw_host_init()
939 disable_aspm_l12(pcie); in tegra_pcie_dw_host_init()
942 if (!pcie->of_data->has_l1ss_exit_fix) { in tegra_pcie_dw_host_init()
948 if (pcie->update_fc_fixup) { in tegra_pcie_dw_host_init()
954 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ); in tegra_pcie_dw_host_init()
961 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_start_link() local
966 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) { in tegra_pcie_dw_start_link()
967 enable_irq(pcie->pex_rst_irq); in tegra_pcie_dw_start_link()
973 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_start_link()
975 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_dw_start_link()
980 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_start_link()
982 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_start_link()
985 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_start_link()
987 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_dw_start_link()
1002 val = appl_readl(pcie, APPL_DEBUG); in tegra_pcie_dw_start_link()
1005 tmp = appl_readl(pcie, APPL_LINK_STATUS); in tegra_pcie_dw_start_link()
1015 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_start_link()
1017 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_start_link()
1019 reset_control_assert(pcie->core_rst); in tegra_pcie_dw_start_link()
1020 reset_control_deassert(pcie->core_rst); in tegra_pcie_dw_start_link()
1034 tegra_pcie_icc_set(pcie); in tegra_pcie_dw_start_link()
1043 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_link_up() local
1044 u32 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA); in tegra_pcie_dw_link_up()
1051 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_stop_link() local
1053 disable_irq(pcie->pex_rst_irq); in tegra_pcie_dw_stop_link()
1066 static void tegra_pcie_disable_phy(struct tegra_pcie_dw *pcie) in tegra_pcie_disable_phy() argument
1068 unsigned int phy_count = pcie->phy_count; in tegra_pcie_disable_phy()
1071 phy_power_off(pcie->phys[phy_count]); in tegra_pcie_disable_phy()
1072 phy_exit(pcie->phys[phy_count]); in tegra_pcie_disable_phy()
1076 static int tegra_pcie_enable_phy(struct tegra_pcie_dw *pcie) in tegra_pcie_enable_phy() argument
1081 for (i = 0; i < pcie->phy_count; i++) { in tegra_pcie_enable_phy()
1082 ret = phy_init(pcie->phys[i]); in tegra_pcie_enable_phy()
1086 ret = phy_power_on(pcie->phys[i]); in tegra_pcie_enable_phy()
1095 phy_power_off(pcie->phys[i]); in tegra_pcie_enable_phy()
1097 phy_exit(pcie->phys[i]); in tegra_pcie_enable_phy()
1103 static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie) in tegra_pcie_dw_parse_dt() argument
1105 struct platform_device *pdev = to_platform_device(pcie->dev); in tegra_pcie_dw_parse_dt()
1106 struct device_node *np = pcie->dev->of_node; in tegra_pcie_dw_parse_dt()
1109 pcie->dbi_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); in tegra_pcie_dw_parse_dt()
1110 if (!pcie->dbi_res) { in tegra_pcie_dw_parse_dt()
1111 dev_err(pcie->dev, "Failed to find \"dbi\" region\n"); in tegra_pcie_dw_parse_dt()
1115 ret = of_property_read_u32(np, "nvidia,aspm-cmrt-us", &pcie->aspm_cmrt); in tegra_pcie_dw_parse_dt()
1117 dev_info(pcie->dev, "Failed to read ASPM T_cmrt: %d\n", ret); in tegra_pcie_dw_parse_dt()
1122 &pcie->aspm_pwr_on_t); in tegra_pcie_dw_parse_dt()
1124 dev_info(pcie->dev, "Failed to read ASPM Power On time: %d\n", in tegra_pcie_dw_parse_dt()
1128 &pcie->aspm_l0s_enter_lat); in tegra_pcie_dw_parse_dt()
1130 dev_info(pcie->dev, in tegra_pcie_dw_parse_dt()
1133 ret = of_property_read_u32(np, "num-lanes", &pcie->num_lanes); in tegra_pcie_dw_parse_dt()
1135 dev_err(pcie->dev, "Failed to read num-lanes: %d\n", ret); in tegra_pcie_dw_parse_dt()
1139 ret = of_property_read_u32_index(np, "nvidia,bpmp", 1, &pcie->cid); in tegra_pcie_dw_parse_dt()
1141 dev_err(pcie->dev, "Failed to read Controller-ID: %d\n", ret); in tegra_pcie_dw_parse_dt()
1147 dev_err(pcie->dev, "Failed to find PHY entries: %d\n", in tegra_pcie_dw_parse_dt()
1151 pcie->phy_count = ret; in tegra_pcie_dw_parse_dt()
1154 pcie->update_fc_fixup = true; in tegra_pcie_dw_parse_dt()
1157 if (pcie->of_data->version == TEGRA194_DWC_IP_VER) { in tegra_pcie_dw_parse_dt()
1158 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) in tegra_pcie_dw_parse_dt()
1159 pcie->enable_ext_refclk = true; in tegra_pcie_dw_parse_dt()
1161 pcie->enable_ext_refclk = in tegra_pcie_dw_parse_dt()
1162 of_property_read_bool(pcie->dev->of_node, in tegra_pcie_dw_parse_dt()
1166 pcie->supports_clkreq = in tegra_pcie_dw_parse_dt()
1167 of_property_read_bool(pcie->dev->of_node, "supports-clkreq"); in tegra_pcie_dw_parse_dt()
1169 pcie->enable_cdm_check = in tegra_pcie_dw_parse_dt()
1172 if (pcie->of_data->version == TEGRA234_DWC_IP_VER) in tegra_pcie_dw_parse_dt()
1173 pcie->enable_srns = in tegra_pcie_dw_parse_dt()
1176 if (pcie->of_data->mode == DW_PCIE_RC_TYPE) in tegra_pcie_dw_parse_dt()
1180 pcie->pex_rst_gpiod = devm_gpiod_get(pcie->dev, "reset", GPIOD_IN); in tegra_pcie_dw_parse_dt()
1181 if (IS_ERR(pcie->pex_rst_gpiod)) { in tegra_pcie_dw_parse_dt()
1182 int err = PTR_ERR(pcie->pex_rst_gpiod); in tegra_pcie_dw_parse_dt()
1188 dev_printk(level, pcie->dev, in tegra_pcie_dw_parse_dt()
1194 pcie->pex_refclk_sel_gpiod = devm_gpiod_get(pcie->dev, in tegra_pcie_dw_parse_dt()
1197 if (IS_ERR(pcie->pex_refclk_sel_gpiod)) { in tegra_pcie_dw_parse_dt()
1198 int err = PTR_ERR(pcie->pex_refclk_sel_gpiod); in tegra_pcie_dw_parse_dt()
1204 dev_printk(level, pcie->dev, in tegra_pcie_dw_parse_dt()
1207 pcie->pex_refclk_sel_gpiod = NULL; in tegra_pcie_dw_parse_dt()
1213 static int tegra_pcie_bpmp_set_ctrl_state(struct tegra_pcie_dw *pcie, in tegra_pcie_bpmp_set_ctrl_state() argument
1224 if (pcie->of_data->version == TEGRA194_DWC_IP_VER && pcie->cid == 5) in tegra_pcie_bpmp_set_ctrl_state()
1231 req.controller_state.pcie_controller = pcie->cid; in tegra_pcie_bpmp_set_ctrl_state()
1241 return tegra_bpmp_transfer(pcie->bpmp, &msg); in tegra_pcie_bpmp_set_ctrl_state()
1244 static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie, in tegra_pcie_bpmp_set_pll_state() argument
1256 req.ep_ctrlr_pll_init.ep_controller = pcie->cid; in tegra_pcie_bpmp_set_pll_state()
1259 req.ep_ctrlr_pll_off.ep_controller = pcie->cid; in tegra_pcie_bpmp_set_pll_state()
1269 return tegra_bpmp_transfer(pcie->bpmp, &msg); in tegra_pcie_bpmp_set_pll_state()
1272 static void tegra_pcie_downstream_dev_to_D0(struct tegra_pcie_dw *pcie) in tegra_pcie_downstream_dev_to_D0() argument
1274 struct dw_pcie_rp *pp = &pcie->pci.pp; in tegra_pcie_downstream_dev_to_D0()
1296 dev_err(pcie->dev, "Failed to find downstream devices\n"); in tegra_pcie_downstream_dev_to_D0()
1303 dev_err(pcie->dev, in tegra_pcie_downstream_dev_to_D0()
1310 static int tegra_pcie_get_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_get_slot_regulators() argument
1312 pcie->slot_ctl_3v3 = devm_regulator_get_optional(pcie->dev, "vpcie3v3"); in tegra_pcie_get_slot_regulators()
1313 if (IS_ERR(pcie->slot_ctl_3v3)) { in tegra_pcie_get_slot_regulators()
1314 if (PTR_ERR(pcie->slot_ctl_3v3) != -ENODEV) in tegra_pcie_get_slot_regulators()
1315 return PTR_ERR(pcie->slot_ctl_3v3); in tegra_pcie_get_slot_regulators()
1317 pcie->slot_ctl_3v3 = NULL; in tegra_pcie_get_slot_regulators()
1320 pcie->slot_ctl_12v = devm_regulator_get_optional(pcie->dev, "vpcie12v"); in tegra_pcie_get_slot_regulators()
1321 if (IS_ERR(pcie->slot_ctl_12v)) { in tegra_pcie_get_slot_regulators()
1322 if (PTR_ERR(pcie->slot_ctl_12v) != -ENODEV) in tegra_pcie_get_slot_regulators()
1323 return PTR_ERR(pcie->slot_ctl_12v); in tegra_pcie_get_slot_regulators()
1325 pcie->slot_ctl_12v = NULL; in tegra_pcie_get_slot_regulators()
1331 static int tegra_pcie_enable_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_enable_slot_regulators() argument
1335 if (pcie->slot_ctl_3v3) { in tegra_pcie_enable_slot_regulators()
1336 ret = regulator_enable(pcie->slot_ctl_3v3); in tegra_pcie_enable_slot_regulators()
1338 dev_err(pcie->dev, in tegra_pcie_enable_slot_regulators()
1344 if (pcie->slot_ctl_12v) { in tegra_pcie_enable_slot_regulators()
1345 ret = regulator_enable(pcie->slot_ctl_12v); in tegra_pcie_enable_slot_regulators()
1347 dev_err(pcie->dev, in tegra_pcie_enable_slot_regulators()
1358 if (pcie->slot_ctl_3v3 || pcie->slot_ctl_12v) in tegra_pcie_enable_slot_regulators()
1364 if (pcie->slot_ctl_3v3) in tegra_pcie_enable_slot_regulators()
1365 regulator_disable(pcie->slot_ctl_3v3); in tegra_pcie_enable_slot_regulators()
1369 static void tegra_pcie_disable_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_disable_slot_regulators() argument
1371 if (pcie->slot_ctl_12v) in tegra_pcie_disable_slot_regulators()
1372 regulator_disable(pcie->slot_ctl_12v); in tegra_pcie_disable_slot_regulators()
1373 if (pcie->slot_ctl_3v3) in tegra_pcie_disable_slot_regulators()
1374 regulator_disable(pcie->slot_ctl_3v3); in tegra_pcie_disable_slot_regulators()
1377 static int tegra_pcie_config_controller(struct tegra_pcie_dw *pcie, in tegra_pcie_config_controller() argument
1383 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true); in tegra_pcie_config_controller()
1385 dev_err(pcie->dev, in tegra_pcie_config_controller()
1386 "Failed to enable controller %u: %d\n", pcie->cid, ret); in tegra_pcie_config_controller()
1390 if (pcie->enable_ext_refclk) { in tegra_pcie_config_controller()
1391 ret = tegra_pcie_bpmp_set_pll_state(pcie, true); in tegra_pcie_config_controller()
1393 dev_err(pcie->dev, "Failed to init UPHY: %d\n", ret); in tegra_pcie_config_controller()
1398 ret = tegra_pcie_enable_slot_regulators(pcie); in tegra_pcie_config_controller()
1402 ret = regulator_enable(pcie->pex_ctl_supply); in tegra_pcie_config_controller()
1404 dev_err(pcie->dev, "Failed to enable regulator: %d\n", ret); in tegra_pcie_config_controller()
1408 ret = clk_prepare_enable(pcie->core_clk); in tegra_pcie_config_controller()
1410 dev_err(pcie->dev, "Failed to enable core clock: %d\n", ret); in tegra_pcie_config_controller()
1414 ret = reset_control_deassert(pcie->core_apb_rst); in tegra_pcie_config_controller()
1416 dev_err(pcie->dev, "Failed to deassert core APB reset: %d\n", in tegra_pcie_config_controller()
1421 if (en_hw_hot_rst || pcie->of_data->has_sbr_reset_fix) { in tegra_pcie_config_controller()
1423 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_config_controller()
1429 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_config_controller()
1432 ret = tegra_pcie_enable_phy(pcie); in tegra_pcie_config_controller()
1434 dev_err(pcie->dev, "Failed to enable PHY: %d\n", ret); in tegra_pcie_config_controller()
1439 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK, in tegra_pcie_config_controller()
1443 appl_writel(pcie, APPL_DM_TYPE_RP, APPL_DM_TYPE); in tegra_pcie_config_controller()
1445 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE); in tegra_pcie_config_controller()
1447 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_config_controller()
1448 appl_writel(pcie, val | APPL_CTRL_SYS_PRE_DET_STATE, APPL_CTRL); in tegra_pcie_config_controller()
1450 val = appl_readl(pcie, APPL_CFG_MISC); in tegra_pcie_config_controller()
1452 appl_writel(pcie, val, APPL_CFG_MISC); in tegra_pcie_config_controller()
1454 if (pcie->enable_srns || pcie->enable_ext_refclk) { in tegra_pcie_config_controller()
1456 * When Tegra PCIe RP is using external clock, it cannot supply in tegra_pcie_config_controller()
1457 * same clock to its downstream hierarchy. Hence, gate PCIe RP in tegra_pcie_config_controller()
1461 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_config_controller()
1464 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_config_controller()
1467 if (!pcie->supports_clkreq) { in tegra_pcie_config_controller()
1468 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_config_controller()
1471 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_config_controller()
1475 appl_writel(pcie, in tegra_pcie_config_controller()
1476 pcie->atu_dma_res->start & APPL_CFG_IATU_DMA_BASE_ADDR_MASK, in tegra_pcie_config_controller()
1479 reset_control_deassert(pcie->core_rst); in tegra_pcie_config_controller()
1484 reset_control_assert(pcie->core_apb_rst); in tegra_pcie_config_controller()
1486 clk_disable_unprepare(pcie->core_clk); in tegra_pcie_config_controller()
1488 regulator_disable(pcie->pex_ctl_supply); in tegra_pcie_config_controller()
1490 tegra_pcie_disable_slot_regulators(pcie); in tegra_pcie_config_controller()
1492 if (pcie->enable_ext_refclk) in tegra_pcie_config_controller()
1493 tegra_pcie_bpmp_set_pll_state(pcie, false); in tegra_pcie_config_controller()
1495 tegra_pcie_bpmp_set_ctrl_state(pcie, false); in tegra_pcie_config_controller()
1500 static void tegra_pcie_unconfig_controller(struct tegra_pcie_dw *pcie) in tegra_pcie_unconfig_controller() argument
1504 ret = reset_control_assert(pcie->core_rst); in tegra_pcie_unconfig_controller()
1506 dev_err(pcie->dev, "Failed to assert \"core\" reset: %d\n", ret); in tegra_pcie_unconfig_controller()
1508 tegra_pcie_disable_phy(pcie); in tegra_pcie_unconfig_controller()
1510 ret = reset_control_assert(pcie->core_apb_rst); in tegra_pcie_unconfig_controller()
1512 dev_err(pcie->dev, "Failed to assert APB reset: %d\n", ret); in tegra_pcie_unconfig_controller()
1514 clk_disable_unprepare(pcie->core_clk); in tegra_pcie_unconfig_controller()
1516 ret = regulator_disable(pcie->pex_ctl_supply); in tegra_pcie_unconfig_controller()
1518 dev_err(pcie->dev, "Failed to disable regulator: %d\n", ret); in tegra_pcie_unconfig_controller()
1520 tegra_pcie_disable_slot_regulators(pcie); in tegra_pcie_unconfig_controller()
1522 if (pcie->enable_ext_refclk) { in tegra_pcie_unconfig_controller()
1523 ret = tegra_pcie_bpmp_set_pll_state(pcie, false); in tegra_pcie_unconfig_controller()
1525 dev_err(pcie->dev, "Failed to deinit UPHY: %d\n", ret); in tegra_pcie_unconfig_controller()
1528 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, false); in tegra_pcie_unconfig_controller()
1530 dev_err(pcie->dev, "Failed to disable controller %d: %d\n", in tegra_pcie_unconfig_controller()
1531 pcie->cid, ret); in tegra_pcie_unconfig_controller()
1534 static int tegra_pcie_init_controller(struct tegra_pcie_dw *pcie) in tegra_pcie_init_controller() argument
1536 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_init_controller()
1540 ret = tegra_pcie_config_controller(pcie, false); in tegra_pcie_init_controller()
1548 dev_err(pcie->dev, "Failed to add PCIe port: %d\n", ret); in tegra_pcie_init_controller()
1555 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_init_controller()
1559 static int tegra_pcie_try_link_l2(struct tegra_pcie_dw *pcie) in tegra_pcie_try_link_l2() argument
1563 if (!tegra_pcie_dw_link_up(&pcie->pci)) in tegra_pcie_try_link_l2()
1566 val = appl_readl(pcie, APPL_RADM_STATUS); in tegra_pcie_try_link_l2()
1568 appl_writel(pcie, val, APPL_RADM_STATUS); in tegra_pcie_try_link_l2()
1570 return readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, val, in tegra_pcie_try_link_l2()
1575 static void tegra_pcie_dw_pme_turnoff(struct tegra_pcie_dw *pcie) in tegra_pcie_dw_pme_turnoff() argument
1580 if (!tegra_pcie_dw_link_up(&pcie->pci)) { in tegra_pcie_dw_pme_turnoff()
1581 dev_dbg(pcie->dev, "PCIe link is not up...!\n"); in tegra_pcie_dw_pme_turnoff()
1586 * PCIe controller exits from L2 only if reset is applied, so in tegra_pcie_dw_pme_turnoff()
1593 appl_writel(pcie, 0x0, APPL_INTR_EN_L0_0); in tegra_pcie_dw_pme_turnoff()
1595 if (tegra_pcie_try_link_l2(pcie)) { in tegra_pcie_dw_pme_turnoff()
1596 dev_info(pcie->dev, "Link didn't transition to L2 state\n"); in tegra_pcie_dw_pme_turnoff()
1603 data = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1605 appl_writel(pcie, data, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1611 data = readl(pcie->appl_base + APPL_CTRL); in tegra_pcie_dw_pme_turnoff()
1613 writel(data, pcie->appl_base + APPL_CTRL); in tegra_pcie_dw_pme_turnoff()
1615 err = readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, in tegra_pcie_dw_pme_turnoff()
1623 dev_info(pcie->dev, "Link didn't go to detect state\n"); in tegra_pcie_dw_pme_turnoff()
1629 data = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1634 appl_writel(pcie, data, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1637 static void tegra_pcie_deinit_controller(struct tegra_pcie_dw *pcie) in tegra_pcie_deinit_controller() argument
1639 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_deinit_controller()
1640 dw_pcie_host_deinit(&pcie->pci.pp); in tegra_pcie_deinit_controller()
1641 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_deinit_controller()
1642 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_deinit_controller()
1645 static int tegra_pcie_config_rp(struct tegra_pcie_dw *pcie) in tegra_pcie_config_rp() argument
1647 struct device *dev = pcie->dev; in tegra_pcie_config_rp()
1655 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n", in tegra_pcie_config_rp()
1666 ret = tegra_pcie_init_controller(pcie); in tegra_pcie_config_rp()
1672 pcie->link_state = tegra_pcie_dw_link_up(&pcie->pci); in tegra_pcie_config_rp()
1673 if (!pcie->link_state) { in tegra_pcie_config_rp()
1684 pcie->debugfs = debugfs_create_dir(name, NULL); in tegra_pcie_config_rp()
1685 init_debugfs(pcie); in tegra_pcie_config_rp()
1690 tegra_pcie_deinit_controller(pcie); in tegra_pcie_config_rp()
1697 static void pex_ep_event_pex_rst_assert(struct tegra_pcie_dw *pcie) in pex_ep_event_pex_rst_assert() argument
1702 if (pcie->ep_state == EP_STATE_DISABLED) in pex_ep_event_pex_rst_assert()
1706 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_assert()
1708 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_assert()
1710 ret = readl_poll_timeout(pcie->appl_base + APPL_DEBUG, val, in pex_ep_event_pex_rst_assert()
1716 dev_err(pcie->dev, "Failed to go Detect state: %d\n", ret); in pex_ep_event_pex_rst_assert()
1718 reset_control_assert(pcie->core_rst); in pex_ep_event_pex_rst_assert()
1720 tegra_pcie_disable_phy(pcie); in pex_ep_event_pex_rst_assert()
1722 reset_control_assert(pcie->core_apb_rst); in pex_ep_event_pex_rst_assert()
1724 clk_disable_unprepare(pcie->core_clk); in pex_ep_event_pex_rst_assert()
1726 pm_runtime_put_sync(pcie->dev); in pex_ep_event_pex_rst_assert()
1728 if (pcie->enable_ext_refclk) { in pex_ep_event_pex_rst_assert()
1729 ret = tegra_pcie_bpmp_set_pll_state(pcie, false); in pex_ep_event_pex_rst_assert()
1731 dev_err(pcie->dev, "Failed to turn off UPHY: %d\n", in pex_ep_event_pex_rst_assert()
1735 ret = tegra_pcie_bpmp_set_pll_state(pcie, false); in pex_ep_event_pex_rst_assert()
1737 dev_err(pcie->dev, "Failed to turn off UPHY: %d\n", ret); in pex_ep_event_pex_rst_assert()
1739 pcie->ep_state = EP_STATE_DISABLED; in pex_ep_event_pex_rst_assert()
1740 dev_dbg(pcie->dev, "Uninitialization of endpoint is completed\n"); in pex_ep_event_pex_rst_assert()
1743 static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie) in pex_ep_event_pex_rst_deassert() argument
1745 struct dw_pcie *pci = &pcie->pci; in pex_ep_event_pex_rst_deassert()
1747 struct device *dev = pcie->dev; in pex_ep_event_pex_rst_deassert()
1752 if (pcie->ep_state == EP_STATE_ENABLED) in pex_ep_event_pex_rst_deassert()
1757 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n", in pex_ep_event_pex_rst_deassert()
1762 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true); in pex_ep_event_pex_rst_deassert()
1764 dev_err(pcie->dev, "Failed to enable controller %u: %d\n", in pex_ep_event_pex_rst_deassert()
1765 pcie->cid, ret); in pex_ep_event_pex_rst_deassert()
1769 if (pcie->enable_ext_refclk) { in pex_ep_event_pex_rst_deassert()
1770 ret = tegra_pcie_bpmp_set_pll_state(pcie, true); in pex_ep_event_pex_rst_deassert()
1772 dev_err(dev, "Failed to init UPHY for PCIe EP: %d\n", in pex_ep_event_pex_rst_deassert()
1778 ret = clk_prepare_enable(pcie->core_clk); in pex_ep_event_pex_rst_deassert()
1784 ret = reset_control_deassert(pcie->core_apb_rst); in pex_ep_event_pex_rst_deassert()
1790 ret = tegra_pcie_enable_phy(pcie); in pex_ep_event_pex_rst_deassert()
1797 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in pex_ep_event_pex_rst_deassert()
1798 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in pex_ep_event_pex_rst_deassert()
1799 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in pex_ep_event_pex_rst_deassert()
1800 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in pex_ep_event_pex_rst_deassert()
1801 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in pex_ep_event_pex_rst_deassert()
1802 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in pex_ep_event_pex_rst_deassert()
1803 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in pex_ep_event_pex_rst_deassert()
1804 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in pex_ep_event_pex_rst_deassert()
1805 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in pex_ep_event_pex_rst_deassert()
1806 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in pex_ep_event_pex_rst_deassert()
1807 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in pex_ep_event_pex_rst_deassert()
1808 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in pex_ep_event_pex_rst_deassert()
1809 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in pex_ep_event_pex_rst_deassert()
1810 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in pex_ep_event_pex_rst_deassert()
1811 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in pex_ep_event_pex_rst_deassert()
1814 val = appl_readl(pcie, APPL_DM_TYPE); in pex_ep_event_pex_rst_deassert()
1817 appl_writel(pcie, val, APPL_DM_TYPE); in pex_ep_event_pex_rst_deassert()
1819 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE); in pex_ep_event_pex_rst_deassert()
1821 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1824 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1826 val = appl_readl(pcie, APPL_CFG_MISC); in pex_ep_event_pex_rst_deassert()
1829 appl_writel(pcie, val, APPL_CFG_MISC); in pex_ep_event_pex_rst_deassert()
1831 val = appl_readl(pcie, APPL_PINMUX); in pex_ep_event_pex_rst_deassert()
1834 appl_writel(pcie, val, APPL_PINMUX); in pex_ep_event_pex_rst_deassert()
1836 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK, in pex_ep_event_pex_rst_deassert()
1839 appl_writel(pcie, pcie->atu_dma_res->start & in pex_ep_event_pex_rst_deassert()
1843 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in pex_ep_event_pex_rst_deassert()
1847 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in pex_ep_event_pex_rst_deassert()
1849 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0); in pex_ep_event_pex_rst_deassert()
1852 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0); in pex_ep_event_pex_rst_deassert()
1854 reset_control_deassert(pcie->core_rst); in pex_ep_event_pex_rst_deassert()
1856 if (pcie->update_fc_fixup) { in pex_ep_event_pex_rst_deassert()
1862 config_gen3_gen4_eq_presets(pcie); in pex_ep_event_pex_rst_deassert()
1864 init_host_aspm(pcie); in pex_ep_event_pex_rst_deassert()
1867 if (!pcie->supports_clkreq) { in pex_ep_event_pex_rst_deassert()
1868 disable_aspm_l11(pcie); in pex_ep_event_pex_rst_deassert()
1869 disable_aspm_l12(pcie); in pex_ep_event_pex_rst_deassert()
1872 if (!pcie->of_data->has_l1ss_exit_fix) { in pex_ep_event_pex_rst_deassert()
1878 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci, in pex_ep_event_pex_rst_deassert()
1882 if (pcie->enable_srns) { in pex_ep_event_pex_rst_deassert()
1883 val_16 = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in pex_ep_event_pex_rst_deassert()
1886 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA, in pex_ep_event_pex_rst_deassert()
1890 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ); in pex_ep_event_pex_rst_deassert()
1907 if (pcie->of_data->has_ltr_req_fix) { in pex_ep_event_pex_rst_deassert()
1908 val = appl_readl(pcie, APPL_LTR_MSG_2); in pex_ep_event_pex_rst_deassert()
1910 appl_writel(pcie, val, APPL_LTR_MSG_2); in pex_ep_event_pex_rst_deassert()
1914 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1916 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1918 pcie->ep_state = EP_STATE_ENABLED; in pex_ep_event_pex_rst_deassert()
1924 reset_control_assert(pcie->core_rst); in pex_ep_event_pex_rst_deassert()
1925 tegra_pcie_disable_phy(pcie); in pex_ep_event_pex_rst_deassert()
1927 reset_control_assert(pcie->core_apb_rst); in pex_ep_event_pex_rst_deassert()
1929 clk_disable_unprepare(pcie->core_clk); in pex_ep_event_pex_rst_deassert()
1931 tegra_pcie_bpmp_set_pll_state(pcie, false); in pex_ep_event_pex_rst_deassert()
1933 tegra_pcie_bpmp_set_ctrl_state(pcie, false); in pex_ep_event_pex_rst_deassert()
1940 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_pex_rst_irq() local
1942 if (gpiod_get_value(pcie->pex_rst_gpiod)) in tegra_pcie_ep_pex_rst_irq()
1943 pex_ep_event_pex_rst_assert(pcie); in tegra_pcie_ep_pex_rst_irq()
1945 pex_ep_event_pex_rst_deassert(pcie); in tegra_pcie_ep_pex_rst_irq()
1950 static int tegra_pcie_ep_raise_intx_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_intx_irq() argument
1956 appl_writel(pcie, 1, APPL_LEGACY_INTX); in tegra_pcie_ep_raise_intx_irq()
1958 appl_writel(pcie, 0, APPL_LEGACY_INTX); in tegra_pcie_ep_raise_intx_irq()
1962 static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_msi_irq() argument
1967 appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1); in tegra_pcie_ep_raise_msi_irq()
1972 static int tegra_pcie_ep_raise_msix_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_msix_irq() argument
1974 struct dw_pcie_ep *ep = &pcie->pci.ep; in tegra_pcie_ep_raise_msix_irq()
1985 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_ep_raise_irq() local
1989 return tegra_pcie_ep_raise_intx_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
1992 return tegra_pcie_ep_raise_msi_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
1995 return tegra_pcie_ep_raise_msix_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
2026 static int tegra_pcie_config_ep(struct tegra_pcie_dw *pcie, in tegra_pcie_config_ep() argument
2029 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_config_ep()
2030 struct device *dev = pcie->dev; in tegra_pcie_config_ep()
2040 ret = gpiod_set_debounce(pcie->pex_rst_gpiod, PERST_DEBOUNCE_TIME); in tegra_pcie_config_ep()
2047 ret = gpiod_to_irq(pcie->pex_rst_gpiod); in tegra_pcie_config_ep()
2052 pcie->pex_rst_irq = (unsigned int)ret; in tegra_pcie_config_ep()
2055 pcie->cid); in tegra_pcie_config_ep()
2061 irq_set_status_flags(pcie->pex_rst_irq, IRQ_NOAUTOEN); in tegra_pcie_config_ep()
2063 pcie->ep_state = EP_STATE_DISABLED; in tegra_pcie_config_ep()
2065 ret = devm_request_threaded_irq(dev, pcie->pex_rst_irq, NULL, in tegra_pcie_config_ep()
2069 name, (void *)pcie); in tegra_pcie_config_ep()
2093 struct tegra_pcie_dw *pcie; in tegra_pcie_dw_probe() local
2103 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); in tegra_pcie_dw_probe()
2104 if (!pcie) in tegra_pcie_dw_probe()
2107 pci = &pcie->pci; in tegra_pcie_dw_probe()
2110 pcie->dev = &pdev->dev; in tegra_pcie_dw_probe()
2111 pcie->of_data = (struct tegra_pcie_dw_of_data *)data; in tegra_pcie_dw_probe()
2112 pci->n_fts[0] = pcie->of_data->n_fts[0]; in tegra_pcie_dw_probe()
2113 pci->n_fts[1] = pcie->of_data->n_fts[1]; in tegra_pcie_dw_probe()
2117 ret = tegra_pcie_dw_parse_dt(pcie); in tegra_pcie_dw_probe()
2130 ret = tegra_pcie_get_slot_regulators(pcie); in tegra_pcie_dw_probe()
2143 if (pcie->pex_refclk_sel_gpiod) in tegra_pcie_dw_probe()
2144 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 1); in tegra_pcie_dw_probe()
2146 pcie->pex_ctl_supply = devm_regulator_get(dev, "vddio-pex-ctl"); in tegra_pcie_dw_probe()
2147 if (IS_ERR(pcie->pex_ctl_supply)) { in tegra_pcie_dw_probe()
2148 ret = PTR_ERR(pcie->pex_ctl_supply); in tegra_pcie_dw_probe()
2151 PTR_ERR(pcie->pex_ctl_supply)); in tegra_pcie_dw_probe()
2155 pcie->core_clk = devm_clk_get(dev, "core"); in tegra_pcie_dw_probe()
2156 if (IS_ERR(pcie->core_clk)) { in tegra_pcie_dw_probe()
2158 PTR_ERR(pcie->core_clk)); in tegra_pcie_dw_probe()
2159 return PTR_ERR(pcie->core_clk); in tegra_pcie_dw_probe()
2162 pcie->appl_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, in tegra_pcie_dw_probe()
2164 if (!pcie->appl_res) { in tegra_pcie_dw_probe()
2169 pcie->appl_base = devm_ioremap_resource(dev, pcie->appl_res); in tegra_pcie_dw_probe()
2170 if (IS_ERR(pcie->appl_base)) in tegra_pcie_dw_probe()
2171 return PTR_ERR(pcie->appl_base); in tegra_pcie_dw_probe()
2173 pcie->core_apb_rst = devm_reset_control_get(dev, "apb"); in tegra_pcie_dw_probe()
2174 if (IS_ERR(pcie->core_apb_rst)) { in tegra_pcie_dw_probe()
2176 PTR_ERR(pcie->core_apb_rst)); in tegra_pcie_dw_probe()
2177 return PTR_ERR(pcie->core_apb_rst); in tegra_pcie_dw_probe()
2180 phys = devm_kcalloc(dev, pcie->phy_count, sizeof(*phys), GFP_KERNEL); in tegra_pcie_dw_probe()
2184 for (i = 0; i < pcie->phy_count; i++) { in tegra_pcie_dw_probe()
2200 pcie->phys = phys; in tegra_pcie_dw_probe()
2208 pcie->atu_dma_res = atu_dma_res; in tegra_pcie_dw_probe()
2215 pcie->core_rst = devm_reset_control_get(dev, "core"); in tegra_pcie_dw_probe()
2216 if (IS_ERR(pcie->core_rst)) { in tegra_pcie_dw_probe()
2218 PTR_ERR(pcie->core_rst)); in tegra_pcie_dw_probe()
2219 return PTR_ERR(pcie->core_rst); in tegra_pcie_dw_probe()
2226 pcie->bpmp = tegra_bpmp_get(dev); in tegra_pcie_dw_probe()
2227 if (IS_ERR(pcie->bpmp)) in tegra_pcie_dw_probe()
2228 return PTR_ERR(pcie->bpmp); in tegra_pcie_dw_probe()
2230 platform_set_drvdata(pdev, pcie); in tegra_pcie_dw_probe()
2232 pcie->icc_path = devm_of_icc_get(&pdev->dev, "write"); in tegra_pcie_dw_probe()
2233 ret = PTR_ERR_OR_ZERO(pcie->icc_path); in tegra_pcie_dw_probe()
2235 tegra_bpmp_put(pcie->bpmp); in tegra_pcie_dw_probe()
2240 switch (pcie->of_data->mode) { in tegra_pcie_dw_probe()
2243 IRQF_SHARED, "tegra-pcie-intr", pcie); in tegra_pcie_dw_probe()
2250 ret = tegra_pcie_config_rp(pcie); in tegra_pcie_dw_probe()
2262 "tegra-pcie-ep-intr", pcie); in tegra_pcie_dw_probe()
2269 ret = tegra_pcie_config_ep(pcie, pdev); in tegra_pcie_dw_probe()
2275 dev_err(dev, "Invalid PCIe device type %d\n", in tegra_pcie_dw_probe()
2276 pcie->of_data->mode); in tegra_pcie_dw_probe()
2280 tegra_bpmp_put(pcie->bpmp); in tegra_pcie_dw_probe()
2286 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev); in tegra_pcie_dw_remove() local
2288 if (pcie->of_data->mode == DW_PCIE_RC_TYPE) { in tegra_pcie_dw_remove()
2289 if (!pcie->link_state) in tegra_pcie_dw_remove()
2292 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_dw_remove()
2293 tegra_pcie_deinit_controller(pcie); in tegra_pcie_dw_remove()
2294 pm_runtime_put_sync(pcie->dev); in tegra_pcie_dw_remove()
2296 disable_irq(pcie->pex_rst_irq); in tegra_pcie_dw_remove()
2297 pex_ep_event_pex_rst_assert(pcie); in tegra_pcie_dw_remove()
2300 pm_runtime_disable(pcie->dev); in tegra_pcie_dw_remove()
2301 tegra_bpmp_put(pcie->bpmp); in tegra_pcie_dw_remove()
2302 if (pcie->pex_refclk_sel_gpiod) in tegra_pcie_dw_remove()
2303 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 0); in tegra_pcie_dw_remove()
2308 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_suspend_late() local
2311 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) { in tegra_pcie_dw_suspend_late()
2312 dev_err(dev, "Failed to Suspend as Tegra PCIe is in EP mode\n"); in tegra_pcie_dw_suspend_late()
2316 if (!pcie->link_state) in tegra_pcie_dw_suspend_late()
2320 if (!pcie->of_data->has_sbr_reset_fix) { in tegra_pcie_dw_suspend_late()
2321 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_suspend_late()
2325 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_suspend_late()
2333 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_suspend_noirq() local
2335 if (!pcie->link_state) in tegra_pcie_dw_suspend_noirq()
2338 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_dw_suspend_noirq()
2339 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_dw_suspend_noirq()
2340 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_dw_suspend_noirq()
2347 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_resume_noirq() local
2350 if (!pcie->link_state) in tegra_pcie_dw_resume_noirq()
2353 ret = tegra_pcie_config_controller(pcie, true); in tegra_pcie_dw_resume_noirq()
2357 ret = tegra_pcie_dw_host_init(&pcie->pci.pp); in tegra_pcie_dw_resume_noirq()
2363 dw_pcie_setup_rc(&pcie->pci.pp); in tegra_pcie_dw_resume_noirq()
2365 ret = tegra_pcie_dw_start_link(&pcie->pci); in tegra_pcie_dw_resume_noirq()
2372 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_dw_resume_noirq()
2378 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_resume_early() local
2381 if (pcie->of_data->mode == DW_PCIE_EP_TYPE) { in tegra_pcie_dw_resume_early()
2386 if (!pcie->link_state) in tegra_pcie_dw_resume_early()
2390 if (!pcie->of_data->has_sbr_reset_fix) { in tegra_pcie_dw_resume_early()
2391 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_resume_early()
2397 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_resume_early()
2405 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev); in tegra_pcie_dw_shutdown() local
2407 if (pcie->of_data->mode == DW_PCIE_RC_TYPE) { in tegra_pcie_dw_shutdown()
2408 if (!pcie->link_state) in tegra_pcie_dw_shutdown()
2411 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_dw_shutdown()
2412 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_dw_shutdown()
2414 disable_irq(pcie->pci.pp.irq); in tegra_pcie_dw_shutdown()
2416 disable_irq(pcie->pci.pp.msi_irq[0]); in tegra_pcie_dw_shutdown()
2418 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_dw_shutdown()
2419 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_dw_shutdown()
2420 pm_runtime_put_sync(pcie->dev); in tegra_pcie_dw_shutdown()
2422 disable_irq(pcie->pex_rst_irq); in tegra_pcie_dw_shutdown()
2423 pex_ep_event_pex_rst_assert(pcie); in tegra_pcie_dw_shutdown()
2470 .compatible = "nvidia,tegra194-pcie",
2474 .compatible = "nvidia,tegra194-pcie-ep",
2478 .compatible = "nvidia,tegra234-pcie",
2482 .compatible = "nvidia,tegra234-pcie-ep",
2500 .name = "tegra194-pcie",
2510 MODULE_DESCRIPTION("NVIDIA PCIe host controller driver");