Lines Matching full:pcie

3  * PCIe host controller driver for Tegra194 SoC
33 #include "pcie-designware.h"
301 static inline void appl_writel(struct tegra_pcie_dw *pcie, const u32 value, in appl_writel() argument
304 writel_relaxed(value, pcie->appl_base + reg); in appl_writel()
307 static inline u32 appl_readl(struct tegra_pcie_dw *pcie, const u32 reg) in appl_readl() argument
309 return readl_relaxed(pcie->appl_base + reg); in appl_readl()
319 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in apply_bad_link_workaround() local
328 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA); in apply_bad_link_workaround()
332 if (pcie->init_link_width > current_link_width) { in apply_bad_link_workaround()
333 dev_warn(pci->dev, "PCIe link is bad, width reduced\n"); in apply_bad_link_workaround()
334 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
338 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
341 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
344 dw_pcie_writew_dbi(pci, pcie->pcie_cap_base + in apply_bad_link_workaround()
352 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_rp_irq_handler() local
353 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_rp_irq_handler()
358 val = appl_readl(pcie, APPL_INTR_STATUS_L0); in tegra_pcie_rp_irq_handler()
360 val = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_rp_irq_handler()
362 appl_writel(pcie, val, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_rp_irq_handler()
365 val = appl_readl(pcie, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
367 appl_writel(pcie, val, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
369 val = appl_readl(pcie, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
371 appl_writel(pcie, val, APPL_CAR_RESET_OVRD); in tegra_pcie_rp_irq_handler()
380 val = appl_readl(pcie, APPL_INTR_STATUS_L1_8_0); in tegra_pcie_rp_irq_handler()
382 appl_writel(pcie, in tegra_pcie_rp_irq_handler()
388 appl_writel(pcie, in tegra_pcie_rp_irq_handler()
392 val_w = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + in tegra_pcie_rp_irq_handler()
399 val = appl_readl(pcie, APPL_INTR_STATUS_L0); in tegra_pcie_rp_irq_handler()
401 val = appl_readl(pcie, APPL_INTR_STATUS_L1_18); in tegra_pcie_rp_irq_handler()
423 static void pex_ep_event_hot_rst_done(struct tegra_pcie_dw *pcie) in pex_ep_event_hot_rst_done() argument
427 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in pex_ep_event_hot_rst_done()
428 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in pex_ep_event_hot_rst_done()
429 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in pex_ep_event_hot_rst_done()
430 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in pex_ep_event_hot_rst_done()
431 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in pex_ep_event_hot_rst_done()
432 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in pex_ep_event_hot_rst_done()
433 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in pex_ep_event_hot_rst_done()
434 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in pex_ep_event_hot_rst_done()
435 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in pex_ep_event_hot_rst_done()
436 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in pex_ep_event_hot_rst_done()
437 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in pex_ep_event_hot_rst_done()
438 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in pex_ep_event_hot_rst_done()
439 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in pex_ep_event_hot_rst_done()
440 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in pex_ep_event_hot_rst_done()
441 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in pex_ep_event_hot_rst_done()
442 appl_writel(pcie, 0xFFFFFFFF, APPL_MSI_CTRL_2); in pex_ep_event_hot_rst_done()
444 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_hot_rst_done()
446 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_hot_rst_done()
451 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_irq_thread() local
452 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_ep_irq_thread()
455 speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) & in tegra_pcie_ep_irq_thread()
457 clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]); in tegra_pcie_ep_irq_thread()
460 val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub); in tegra_pcie_ep_irq_thread()
472 appl_writel(pcie, val, APPL_LTR_MSG_1); in tegra_pcie_ep_irq_thread()
475 val = appl_readl(pcie, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
477 appl_writel(pcie, val, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
481 val = appl_readl(pcie, APPL_LTR_MSG_2); in tegra_pcie_ep_irq_thread()
489 dev_err(pcie->dev, "Failed to send LTR message\n"); in tegra_pcie_ep_irq_thread()
497 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_hard_irq() local
498 struct dw_pcie_ep *ep = &pcie->pci.ep; in tegra_pcie_ep_hard_irq()
502 status_l0 = appl_readl(pcie, APPL_INTR_STATUS_L0); in tegra_pcie_ep_hard_irq()
504 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_ep_hard_irq()
505 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_ep_hard_irq()
508 pex_ep_event_hot_rst_done(pcie); in tegra_pcie_ep_hard_irq()
511 link_status = appl_readl(pcie, APPL_LINK_STATUS); in tegra_pcie_ep_hard_irq()
513 dev_dbg(pcie->dev, "Link is up with Host\n"); in tegra_pcie_ep_hard_irq()
522 status_l1 = appl_readl(pcie, APPL_INTR_STATUS_L1_15); in tegra_pcie_ep_hard_irq()
523 appl_writel(pcie, status_l1, APPL_INTR_STATUS_L1_15); in tegra_pcie_ep_hard_irq()
532 dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n", in tegra_pcie_ep_hard_irq()
534 appl_writel(pcie, status_l0, APPL_INTR_STATUS_L0); in tegra_pcie_ep_hard_irq()
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
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()
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
769 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in tegra_pcie_enable_msi_interrupts()
772 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in tegra_pcie_enable_msi_interrupts()
778 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_enable_interrupts() local
781 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in tegra_pcie_enable_interrupts()
782 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in tegra_pcie_enable_interrupts()
783 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in tegra_pcie_enable_interrupts()
784 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in tegra_pcie_enable_interrupts()
785 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in tegra_pcie_enable_interrupts()
786 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in tegra_pcie_enable_interrupts()
787 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in tegra_pcie_enable_interrupts()
788 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in tegra_pcie_enable_interrupts()
789 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in tegra_pcie_enable_interrupts()
790 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in tegra_pcie_enable_interrupts()
791 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in tegra_pcie_enable_interrupts()
792 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in tegra_pcie_enable_interrupts()
793 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in tegra_pcie_enable_interrupts()
794 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in tegra_pcie_enable_interrupts()
795 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in tegra_pcie_enable_interrupts()
803 static void config_gen3_gen4_eq_presets(struct tegra_pcie_dw *pcie) in config_gen3_gen4_eq_presets() argument
805 struct dw_pcie *pci = &pcie->pci; in config_gen3_gen4_eq_presets()
809 for (i = 0; i < pcie->num_lanes; i++) { in config_gen3_gen4_eq_presets()
859 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_host_init() local
864 if (!pcie->pcie_cap_base) in tegra_pcie_dw_host_init()
865 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci, in tegra_pcie_dw_host_init()
887 val = dw_pcie_readl_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKCAP); in tegra_pcie_dw_host_init()
889 val |= (pcie->num_lanes << PCI_EXP_LNKSTA_NLW_SHIFT); in tegra_pcie_dw_host_init()
890 dw_pcie_writel_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKCAP, val); in tegra_pcie_dw_host_init()
892 config_gen3_gen4_eq_presets(pcie); in tegra_pcie_dw_host_init()
894 init_host_aspm(pcie); in tegra_pcie_dw_host_init()
897 if (!pcie->supports_clkreq) { in tegra_pcie_dw_host_init()
898 disable_aspm_l11(pcie); in tegra_pcie_dw_host_init()
899 disable_aspm_l12(pcie); in tegra_pcie_dw_host_init()
906 if (pcie->update_fc_fixup) { in tegra_pcie_dw_host_init()
912 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ); in tegra_pcie_dw_host_init()
920 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_start_link() local
924 if (pcie->mode == DW_PCIE_EP_TYPE) { in tegra_pcie_dw_start_link()
925 enable_irq(pcie->pex_rst_irq); in tegra_pcie_dw_start_link()
931 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_start_link()
933 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_dw_start_link()
938 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_start_link()
940 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_start_link()
943 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_start_link()
945 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_dw_start_link()
960 val = appl_readl(pcie, APPL_DEBUG); in tegra_pcie_dw_start_link()
963 tmp = appl_readl(pcie, APPL_LINK_STATUS); in tegra_pcie_dw_start_link()
973 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_start_link()
975 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_start_link()
977 reset_control_assert(pcie->core_rst); in tegra_pcie_dw_start_link()
978 reset_control_deassert(pcie->core_rst); in tegra_pcie_dw_start_link()
992 speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) & in tegra_pcie_dw_start_link()
994 clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]); in tegra_pcie_dw_start_link()
1003 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_link_up() local
1004 u32 val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA); in tegra_pcie_dw_link_up()
1011 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_dw_stop_link() local
1013 disable_irq(pcie->pex_rst_irq); in tegra_pcie_dw_stop_link()
1026 static void tegra_pcie_disable_phy(struct tegra_pcie_dw *pcie) in tegra_pcie_disable_phy() argument
1028 unsigned int phy_count = pcie->phy_count; in tegra_pcie_disable_phy()
1031 phy_power_off(pcie->phys[phy_count]); in tegra_pcie_disable_phy()
1032 phy_exit(pcie->phys[phy_count]); in tegra_pcie_disable_phy()
1036 static int tegra_pcie_enable_phy(struct tegra_pcie_dw *pcie) in tegra_pcie_enable_phy() argument
1041 for (i = 0; i < pcie->phy_count; i++) { in tegra_pcie_enable_phy()
1042 ret = phy_init(pcie->phys[i]); in tegra_pcie_enable_phy()
1046 ret = phy_power_on(pcie->phys[i]); in tegra_pcie_enable_phy()
1055 phy_power_off(pcie->phys[i]); in tegra_pcie_enable_phy()
1057 phy_exit(pcie->phys[i]); in tegra_pcie_enable_phy()
1063 static int tegra_pcie_dw_parse_dt(struct tegra_pcie_dw *pcie) in tegra_pcie_dw_parse_dt() argument
1065 struct platform_device *pdev = to_platform_device(pcie->dev); in tegra_pcie_dw_parse_dt()
1066 struct device_node *np = pcie->dev->of_node; in tegra_pcie_dw_parse_dt()
1069 pcie->dbi_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); in tegra_pcie_dw_parse_dt()
1070 if (!pcie->dbi_res) { in tegra_pcie_dw_parse_dt()
1071 dev_err(pcie->dev, "Failed to find \"dbi\" region\n"); in tegra_pcie_dw_parse_dt()
1075 ret = of_property_read_u32(np, "nvidia,aspm-cmrt-us", &pcie->aspm_cmrt); in tegra_pcie_dw_parse_dt()
1077 dev_info(pcie->dev, "Failed to read ASPM T_cmrt: %d\n", ret); in tegra_pcie_dw_parse_dt()
1082 &pcie->aspm_pwr_on_t); in tegra_pcie_dw_parse_dt()
1084 dev_info(pcie->dev, "Failed to read ASPM Power On time: %d\n", in tegra_pcie_dw_parse_dt()
1088 &pcie->aspm_l0s_enter_lat); in tegra_pcie_dw_parse_dt()
1090 dev_info(pcie->dev, in tegra_pcie_dw_parse_dt()
1093 ret = of_property_read_u32(np, "num-lanes", &pcie->num_lanes); in tegra_pcie_dw_parse_dt()
1095 dev_err(pcie->dev, "Failed to read num-lanes: %d\n", ret); in tegra_pcie_dw_parse_dt()
1099 ret = of_property_read_u32_index(np, "nvidia,bpmp", 1, &pcie->cid); in tegra_pcie_dw_parse_dt()
1101 dev_err(pcie->dev, "Failed to read Controller-ID: %d\n", ret); in tegra_pcie_dw_parse_dt()
1107 dev_err(pcie->dev, "Failed to find PHY entries: %d\n", in tegra_pcie_dw_parse_dt()
1111 pcie->phy_count = ret; in tegra_pcie_dw_parse_dt()
1114 pcie->update_fc_fixup = true; in tegra_pcie_dw_parse_dt()
1116 pcie->supports_clkreq = in tegra_pcie_dw_parse_dt()
1117 of_property_read_bool(pcie->dev->of_node, "supports-clkreq"); in tegra_pcie_dw_parse_dt()
1119 pcie->enable_cdm_check = in tegra_pcie_dw_parse_dt()
1122 if (pcie->mode == DW_PCIE_RC_TYPE) in tegra_pcie_dw_parse_dt()
1126 pcie->pex_rst_gpiod = devm_gpiod_get(pcie->dev, "reset", GPIOD_IN); in tegra_pcie_dw_parse_dt()
1127 if (IS_ERR(pcie->pex_rst_gpiod)) { in tegra_pcie_dw_parse_dt()
1128 int err = PTR_ERR(pcie->pex_rst_gpiod); in tegra_pcie_dw_parse_dt()
1134 dev_printk(level, pcie->dev, in tegra_pcie_dw_parse_dt()
1140 pcie->pex_refclk_sel_gpiod = devm_gpiod_get(pcie->dev, in tegra_pcie_dw_parse_dt()
1143 if (IS_ERR(pcie->pex_refclk_sel_gpiod)) { in tegra_pcie_dw_parse_dt()
1144 int err = PTR_ERR(pcie->pex_refclk_sel_gpiod); in tegra_pcie_dw_parse_dt()
1150 dev_printk(level, pcie->dev, in tegra_pcie_dw_parse_dt()
1153 pcie->pex_refclk_sel_gpiod = NULL; in tegra_pcie_dw_parse_dt()
1159 static int tegra_pcie_bpmp_set_ctrl_state(struct tegra_pcie_dw *pcie, in tegra_pcie_bpmp_set_ctrl_state() argument
1167 if (pcie->cid == 5) in tegra_pcie_bpmp_set_ctrl_state()
1174 req.controller_state.pcie_controller = pcie->cid; in tegra_pcie_bpmp_set_ctrl_state()
1184 return tegra_bpmp_transfer(pcie->bpmp, &msg); in tegra_pcie_bpmp_set_ctrl_state()
1187 static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie, in tegra_pcie_bpmp_set_pll_state() argument
1199 req.ep_ctrlr_pll_init.ep_controller = pcie->cid; in tegra_pcie_bpmp_set_pll_state()
1202 req.ep_ctrlr_pll_off.ep_controller = pcie->cid; in tegra_pcie_bpmp_set_pll_state()
1212 return tegra_bpmp_transfer(pcie->bpmp, &msg); in tegra_pcie_bpmp_set_pll_state()
1215 static void tegra_pcie_downstream_dev_to_D0(struct tegra_pcie_dw *pcie) in tegra_pcie_downstream_dev_to_D0() argument
1217 struct pcie_port *pp = &pcie->pci.pp; in tegra_pcie_downstream_dev_to_D0()
1239 dev_err(pcie->dev, "Failed to find downstream devices\n"); in tegra_pcie_downstream_dev_to_D0()
1246 dev_err(pcie->dev, in tegra_pcie_downstream_dev_to_D0()
1253 static int tegra_pcie_get_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_get_slot_regulators() argument
1255 pcie->slot_ctl_3v3 = devm_regulator_get_optional(pcie->dev, "vpcie3v3"); in tegra_pcie_get_slot_regulators()
1256 if (IS_ERR(pcie->slot_ctl_3v3)) { in tegra_pcie_get_slot_regulators()
1257 if (PTR_ERR(pcie->slot_ctl_3v3) != -ENODEV) in tegra_pcie_get_slot_regulators()
1258 return PTR_ERR(pcie->slot_ctl_3v3); in tegra_pcie_get_slot_regulators()
1260 pcie->slot_ctl_3v3 = NULL; in tegra_pcie_get_slot_regulators()
1263 pcie->slot_ctl_12v = devm_regulator_get_optional(pcie->dev, "vpcie12v"); in tegra_pcie_get_slot_regulators()
1264 if (IS_ERR(pcie->slot_ctl_12v)) { in tegra_pcie_get_slot_regulators()
1265 if (PTR_ERR(pcie->slot_ctl_12v) != -ENODEV) in tegra_pcie_get_slot_regulators()
1266 return PTR_ERR(pcie->slot_ctl_12v); in tegra_pcie_get_slot_regulators()
1268 pcie->slot_ctl_12v = NULL; in tegra_pcie_get_slot_regulators()
1274 static int tegra_pcie_enable_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_enable_slot_regulators() argument
1278 if (pcie->slot_ctl_3v3) { in tegra_pcie_enable_slot_regulators()
1279 ret = regulator_enable(pcie->slot_ctl_3v3); in tegra_pcie_enable_slot_regulators()
1281 dev_err(pcie->dev, in tegra_pcie_enable_slot_regulators()
1287 if (pcie->slot_ctl_12v) { in tegra_pcie_enable_slot_regulators()
1288 ret = regulator_enable(pcie->slot_ctl_12v); in tegra_pcie_enable_slot_regulators()
1290 dev_err(pcie->dev, in tegra_pcie_enable_slot_regulators()
1301 if (pcie->slot_ctl_3v3 || pcie->slot_ctl_12v) in tegra_pcie_enable_slot_regulators()
1307 if (pcie->slot_ctl_3v3) in tegra_pcie_enable_slot_regulators()
1308 regulator_disable(pcie->slot_ctl_3v3); in tegra_pcie_enable_slot_regulators()
1312 static void tegra_pcie_disable_slot_regulators(struct tegra_pcie_dw *pcie) in tegra_pcie_disable_slot_regulators() argument
1314 if (pcie->slot_ctl_12v) in tegra_pcie_disable_slot_regulators()
1315 regulator_disable(pcie->slot_ctl_12v); in tegra_pcie_disable_slot_regulators()
1316 if (pcie->slot_ctl_3v3) in tegra_pcie_disable_slot_regulators()
1317 regulator_disable(pcie->slot_ctl_3v3); in tegra_pcie_disable_slot_regulators()
1320 static int tegra_pcie_config_controller(struct tegra_pcie_dw *pcie, in tegra_pcie_config_controller() argument
1326 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, true); in tegra_pcie_config_controller()
1328 dev_err(pcie->dev, in tegra_pcie_config_controller()
1329 "Failed to enable controller %u: %d\n", pcie->cid, ret); in tegra_pcie_config_controller()
1333 ret = tegra_pcie_enable_slot_regulators(pcie); in tegra_pcie_config_controller()
1337 ret = regulator_enable(pcie->pex_ctl_supply); in tegra_pcie_config_controller()
1339 dev_err(pcie->dev, "Failed to enable regulator: %d\n", ret); in tegra_pcie_config_controller()
1343 ret = clk_prepare_enable(pcie->core_clk); in tegra_pcie_config_controller()
1345 dev_err(pcie->dev, "Failed to enable core clock: %d\n", ret); in tegra_pcie_config_controller()
1349 ret = reset_control_deassert(pcie->core_apb_rst); in tegra_pcie_config_controller()
1351 dev_err(pcie->dev, "Failed to deassert core APB reset: %d\n", in tegra_pcie_config_controller()
1358 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_config_controller()
1362 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_config_controller()
1365 ret = tegra_pcie_enable_phy(pcie); in tegra_pcie_config_controller()
1367 dev_err(pcie->dev, "Failed to enable PHY: %d\n", ret); in tegra_pcie_config_controller()
1372 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK, in tegra_pcie_config_controller()
1376 appl_writel(pcie, APPL_DM_TYPE_RP, APPL_DM_TYPE); in tegra_pcie_config_controller()
1378 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE); in tegra_pcie_config_controller()
1380 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_config_controller()
1381 appl_writel(pcie, val | APPL_CTRL_SYS_PRE_DET_STATE, APPL_CTRL); in tegra_pcie_config_controller()
1383 val = appl_readl(pcie, APPL_CFG_MISC); in tegra_pcie_config_controller()
1385 appl_writel(pcie, val, APPL_CFG_MISC); in tegra_pcie_config_controller()
1387 if (!pcie->supports_clkreq) { in tegra_pcie_config_controller()
1388 val = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_config_controller()
1391 appl_writel(pcie, val, APPL_PINMUX); in tegra_pcie_config_controller()
1395 appl_writel(pcie, in tegra_pcie_config_controller()
1396 pcie->atu_dma_res->start & APPL_CFG_IATU_DMA_BASE_ADDR_MASK, in tegra_pcie_config_controller()
1399 reset_control_deassert(pcie->core_rst); in tegra_pcie_config_controller()
1404 reset_control_assert(pcie->core_apb_rst); in tegra_pcie_config_controller()
1406 clk_disable_unprepare(pcie->core_clk); in tegra_pcie_config_controller()
1408 regulator_disable(pcie->pex_ctl_supply); in tegra_pcie_config_controller()
1410 tegra_pcie_disable_slot_regulators(pcie); in tegra_pcie_config_controller()
1412 tegra_pcie_bpmp_set_ctrl_state(pcie, false); in tegra_pcie_config_controller()
1417 static void tegra_pcie_unconfig_controller(struct tegra_pcie_dw *pcie) in tegra_pcie_unconfig_controller() argument
1421 ret = reset_control_assert(pcie->core_rst); in tegra_pcie_unconfig_controller()
1423 dev_err(pcie->dev, "Failed to assert \"core\" reset: %d\n", ret); in tegra_pcie_unconfig_controller()
1425 tegra_pcie_disable_phy(pcie); in tegra_pcie_unconfig_controller()
1427 ret = reset_control_assert(pcie->core_apb_rst); in tegra_pcie_unconfig_controller()
1429 dev_err(pcie->dev, "Failed to assert APB reset: %d\n", ret); in tegra_pcie_unconfig_controller()
1431 clk_disable_unprepare(pcie->core_clk); in tegra_pcie_unconfig_controller()
1433 ret = regulator_disable(pcie->pex_ctl_supply); in tegra_pcie_unconfig_controller()
1435 dev_err(pcie->dev, "Failed to disable regulator: %d\n", ret); in tegra_pcie_unconfig_controller()
1437 tegra_pcie_disable_slot_regulators(pcie); in tegra_pcie_unconfig_controller()
1439 ret = tegra_pcie_bpmp_set_ctrl_state(pcie, false); in tegra_pcie_unconfig_controller()
1441 dev_err(pcie->dev, "Failed to disable controller %d: %d\n", in tegra_pcie_unconfig_controller()
1442 pcie->cid, ret); in tegra_pcie_unconfig_controller()
1445 static int tegra_pcie_init_controller(struct tegra_pcie_dw *pcie) in tegra_pcie_init_controller() argument
1447 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_init_controller()
1451 ret = tegra_pcie_config_controller(pcie, false); in tegra_pcie_init_controller()
1459 dev_err(pcie->dev, "Failed to add PCIe port: %d\n", ret); in tegra_pcie_init_controller()
1466 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_init_controller()
1470 static int tegra_pcie_try_link_l2(struct tegra_pcie_dw *pcie) in tegra_pcie_try_link_l2() argument
1474 if (!tegra_pcie_dw_link_up(&pcie->pci)) in tegra_pcie_try_link_l2()
1477 val = appl_readl(pcie, APPL_RADM_STATUS); in tegra_pcie_try_link_l2()
1479 appl_writel(pcie, val, APPL_RADM_STATUS); in tegra_pcie_try_link_l2()
1481 return readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, val, in tegra_pcie_try_link_l2()
1486 static void tegra_pcie_dw_pme_turnoff(struct tegra_pcie_dw *pcie) in tegra_pcie_dw_pme_turnoff() argument
1491 if (!tegra_pcie_dw_link_up(&pcie->pci)) { in tegra_pcie_dw_pme_turnoff()
1492 dev_dbg(pcie->dev, "PCIe link is not up...!\n"); in tegra_pcie_dw_pme_turnoff()
1497 * PCIe controller exits from L2 only if reset is applied, so in tegra_pcie_dw_pme_turnoff()
1504 appl_writel(pcie, 0x0, APPL_INTR_EN_L0_0); in tegra_pcie_dw_pme_turnoff()
1506 if (tegra_pcie_try_link_l2(pcie)) { in tegra_pcie_dw_pme_turnoff()
1507 dev_info(pcie->dev, "Link didn't transition to L2 state\n"); in tegra_pcie_dw_pme_turnoff()
1514 data = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1516 appl_writel(pcie, data, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1522 data = readl(pcie->appl_base + APPL_CTRL); in tegra_pcie_dw_pme_turnoff()
1524 writel(data, pcie->appl_base + APPL_CTRL); in tegra_pcie_dw_pme_turnoff()
1526 err = readl_poll_timeout_atomic(pcie->appl_base + APPL_DEBUG, in tegra_pcie_dw_pme_turnoff()
1534 dev_info(pcie->dev, "Link didn't go to detect state\n"); in tegra_pcie_dw_pme_turnoff()
1540 data = appl_readl(pcie, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1545 appl_writel(pcie, data, APPL_PINMUX); in tegra_pcie_dw_pme_turnoff()
1548 static void tegra_pcie_deinit_controller(struct tegra_pcie_dw *pcie) in tegra_pcie_deinit_controller() argument
1550 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_deinit_controller()
1551 dw_pcie_host_deinit(&pcie->pci.pp); in tegra_pcie_deinit_controller()
1552 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_deinit_controller()
1553 tegra_pcie_unconfig_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 device *dev = pcie->dev; in tegra_pcie_config_rp()
1566 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n", in tegra_pcie_config_rp()
1577 ret = tegra_pcie_init_controller(pcie); in tegra_pcie_config_rp()
1583 pcie->link_state = tegra_pcie_dw_link_up(&pcie->pci); in tegra_pcie_config_rp()
1584 if (!pcie->link_state) { in tegra_pcie_config_rp()
1595 pcie->debugfs = debugfs_create_dir(name, NULL); in tegra_pcie_config_rp()
1596 init_debugfs(pcie); in tegra_pcie_config_rp()
1601 tegra_pcie_deinit_controller(pcie); in tegra_pcie_config_rp()
1608 static void pex_ep_event_pex_rst_assert(struct tegra_pcie_dw *pcie) in pex_ep_event_pex_rst_assert() argument
1613 if (pcie->ep_state == EP_STATE_DISABLED) in pex_ep_event_pex_rst_assert()
1617 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_assert()
1619 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_assert()
1621 ret = readl_poll_timeout(pcie->appl_base + APPL_DEBUG, val, in pex_ep_event_pex_rst_assert()
1627 dev_err(pcie->dev, "Failed to go Detect state: %d\n", ret); in pex_ep_event_pex_rst_assert()
1629 reset_control_assert(pcie->core_rst); in pex_ep_event_pex_rst_assert()
1631 tegra_pcie_disable_phy(pcie); in pex_ep_event_pex_rst_assert()
1633 reset_control_assert(pcie->core_apb_rst); in pex_ep_event_pex_rst_assert()
1635 clk_disable_unprepare(pcie->core_clk); in pex_ep_event_pex_rst_assert()
1637 pm_runtime_put_sync(pcie->dev); in pex_ep_event_pex_rst_assert()
1639 ret = tegra_pcie_bpmp_set_pll_state(pcie, false); in pex_ep_event_pex_rst_assert()
1641 dev_err(pcie->dev, "Failed to turn off UPHY: %d\n", ret); in pex_ep_event_pex_rst_assert()
1643 pcie->ep_state = EP_STATE_DISABLED; in pex_ep_event_pex_rst_assert()
1644 dev_dbg(pcie->dev, "Uninitialization of endpoint is completed\n"); in pex_ep_event_pex_rst_assert()
1647 static void pex_ep_event_pex_rst_deassert(struct tegra_pcie_dw *pcie) in pex_ep_event_pex_rst_deassert() argument
1649 struct dw_pcie *pci = &pcie->pci; in pex_ep_event_pex_rst_deassert()
1651 struct device *dev = pcie->dev; in pex_ep_event_pex_rst_deassert()
1655 if (pcie->ep_state == EP_STATE_ENABLED) in pex_ep_event_pex_rst_deassert()
1660 dev_err(dev, "Failed to get runtime sync for PCIe dev: %d\n", in pex_ep_event_pex_rst_deassert()
1665 ret = tegra_pcie_bpmp_set_pll_state(pcie, true); in pex_ep_event_pex_rst_deassert()
1667 dev_err(dev, "Failed to init UPHY for PCIe EP: %d\n", ret); in pex_ep_event_pex_rst_deassert()
1671 ret = clk_prepare_enable(pcie->core_clk); in pex_ep_event_pex_rst_deassert()
1677 ret = reset_control_deassert(pcie->core_apb_rst); in pex_ep_event_pex_rst_deassert()
1683 ret = tegra_pcie_enable_phy(pcie); in pex_ep_event_pex_rst_deassert()
1690 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L0); in pex_ep_event_pex_rst_deassert()
1691 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_0_0); in pex_ep_event_pex_rst_deassert()
1692 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_1); in pex_ep_event_pex_rst_deassert()
1693 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_2); in pex_ep_event_pex_rst_deassert()
1694 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_3); in pex_ep_event_pex_rst_deassert()
1695 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_6); in pex_ep_event_pex_rst_deassert()
1696 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_7); in pex_ep_event_pex_rst_deassert()
1697 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_8_0); in pex_ep_event_pex_rst_deassert()
1698 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_9); in pex_ep_event_pex_rst_deassert()
1699 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_10); in pex_ep_event_pex_rst_deassert()
1700 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_11); in pex_ep_event_pex_rst_deassert()
1701 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_13); in pex_ep_event_pex_rst_deassert()
1702 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_14); in pex_ep_event_pex_rst_deassert()
1703 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_15); in pex_ep_event_pex_rst_deassert()
1704 appl_writel(pcie, 0xFFFFFFFF, APPL_INTR_STATUS_L1_17); in pex_ep_event_pex_rst_deassert()
1707 val = appl_readl(pcie, APPL_DM_TYPE); in pex_ep_event_pex_rst_deassert()
1710 appl_writel(pcie, val, APPL_DM_TYPE); in pex_ep_event_pex_rst_deassert()
1712 appl_writel(pcie, 0x0, APPL_CFG_SLCG_OVERRIDE); in pex_ep_event_pex_rst_deassert()
1714 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1717 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1719 val = appl_readl(pcie, APPL_CFG_MISC); in pex_ep_event_pex_rst_deassert()
1722 appl_writel(pcie, val, APPL_CFG_MISC); in pex_ep_event_pex_rst_deassert()
1724 val = appl_readl(pcie, APPL_PINMUX); in pex_ep_event_pex_rst_deassert()
1727 appl_writel(pcie, val, APPL_PINMUX); in pex_ep_event_pex_rst_deassert()
1729 appl_writel(pcie, pcie->dbi_res->start & APPL_CFG_BASE_ADDR_MASK, in pex_ep_event_pex_rst_deassert()
1732 appl_writel(pcie, pcie->atu_dma_res->start & in pex_ep_event_pex_rst_deassert()
1736 val = appl_readl(pcie, APPL_INTR_EN_L0_0); in pex_ep_event_pex_rst_deassert()
1740 appl_writel(pcie, val, APPL_INTR_EN_L0_0); in pex_ep_event_pex_rst_deassert()
1742 val = appl_readl(pcie, APPL_INTR_EN_L1_0_0); in pex_ep_event_pex_rst_deassert()
1745 appl_writel(pcie, val, APPL_INTR_EN_L1_0_0); in pex_ep_event_pex_rst_deassert()
1747 reset_control_deassert(pcie->core_rst); in pex_ep_event_pex_rst_deassert()
1749 if (pcie->update_fc_fixup) { in pex_ep_event_pex_rst_deassert()
1755 config_gen3_gen4_eq_presets(pcie); in pex_ep_event_pex_rst_deassert()
1757 init_host_aspm(pcie); in pex_ep_event_pex_rst_deassert()
1760 if (!pcie->supports_clkreq) { in pex_ep_event_pex_rst_deassert()
1761 disable_aspm_l11(pcie); in pex_ep_event_pex_rst_deassert()
1762 disable_aspm_l12(pcie); in pex_ep_event_pex_rst_deassert()
1769 pcie->pcie_cap_base = dw_pcie_find_capability(&pcie->pci, in pex_ep_event_pex_rst_deassert()
1771 clk_set_rate(pcie->core_clk, GEN4_CORE_CLK_FREQ); in pex_ep_event_pex_rst_deassert()
1788 val = appl_readl(pcie, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1790 appl_writel(pcie, val, APPL_CTRL); in pex_ep_event_pex_rst_deassert()
1792 pcie->ep_state = EP_STATE_ENABLED; in pex_ep_event_pex_rst_deassert()
1798 reset_control_assert(pcie->core_rst); in pex_ep_event_pex_rst_deassert()
1799 tegra_pcie_disable_phy(pcie); in pex_ep_event_pex_rst_deassert()
1801 reset_control_assert(pcie->core_apb_rst); in pex_ep_event_pex_rst_deassert()
1803 clk_disable_unprepare(pcie->core_clk); in pex_ep_event_pex_rst_deassert()
1805 tegra_pcie_bpmp_set_pll_state(pcie, false); in pex_ep_event_pex_rst_deassert()
1812 struct tegra_pcie_dw *pcie = arg; in tegra_pcie_ep_pex_rst_irq() local
1814 if (gpiod_get_value(pcie->pex_rst_gpiod)) in tegra_pcie_ep_pex_rst_irq()
1815 pex_ep_event_pex_rst_assert(pcie); in tegra_pcie_ep_pex_rst_irq()
1817 pex_ep_event_pex_rst_deassert(pcie); in tegra_pcie_ep_pex_rst_irq()
1822 static int tegra_pcie_ep_raise_legacy_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_legacy_irq() argument
1828 appl_writel(pcie, 1, APPL_LEGACY_INTX); in tegra_pcie_ep_raise_legacy_irq()
1830 appl_writel(pcie, 0, APPL_LEGACY_INTX); in tegra_pcie_ep_raise_legacy_irq()
1834 static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_msi_irq() argument
1839 appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1); in tegra_pcie_ep_raise_msi_irq()
1844 static int tegra_pcie_ep_raise_msix_irq(struct tegra_pcie_dw *pcie, u16 irq) in tegra_pcie_ep_raise_msix_irq() argument
1846 struct dw_pcie_ep *ep = &pcie->pci.ep; in tegra_pcie_ep_raise_msix_irq()
1858 struct tegra_pcie_dw *pcie = to_tegra_pcie(pci); in tegra_pcie_ep_raise_irq() local
1862 return tegra_pcie_ep_raise_legacy_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
1865 return tegra_pcie_ep_raise_msi_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
1868 return tegra_pcie_ep_raise_msix_irq(pcie, interrupt_num); in tegra_pcie_ep_raise_irq()
1899 static int tegra_pcie_config_ep(struct tegra_pcie_dw *pcie, in tegra_pcie_config_ep() argument
1902 struct dw_pcie *pci = &pcie->pci; in tegra_pcie_config_ep()
1903 struct device *dev = pcie->dev; in tegra_pcie_config_ep()
1913 ret = gpiod_set_debounce(pcie->pex_rst_gpiod, PERST_DEBOUNCE_TIME); in tegra_pcie_config_ep()
1920 ret = gpiod_to_irq(pcie->pex_rst_gpiod); in tegra_pcie_config_ep()
1925 pcie->pex_rst_irq = (unsigned int)ret; in tegra_pcie_config_ep()
1928 pcie->cid); in tegra_pcie_config_ep()
1934 irq_set_status_flags(pcie->pex_rst_irq, IRQ_NOAUTOEN); in tegra_pcie_config_ep()
1936 pcie->ep_state = EP_STATE_DISABLED; in tegra_pcie_config_ep()
1938 ret = devm_request_threaded_irq(dev, pcie->pex_rst_irq, NULL, in tegra_pcie_config_ep()
1942 name, (void *)pcie); in tegra_pcie_config_ep()
1965 struct tegra_pcie_dw *pcie; in tegra_pcie_dw_probe() local
1975 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); in tegra_pcie_dw_probe()
1976 if (!pcie) in tegra_pcie_dw_probe()
1979 pci = &pcie->pci; in tegra_pcie_dw_probe()
1988 pcie->dev = &pdev->dev; in tegra_pcie_dw_probe()
1989 pcie->mode = (enum dw_pcie_device_mode)data->mode; in tegra_pcie_dw_probe()
1991 ret = tegra_pcie_dw_parse_dt(pcie); in tegra_pcie_dw_probe()
2004 ret = tegra_pcie_get_slot_regulators(pcie); in tegra_pcie_dw_probe()
2017 if (pcie->pex_refclk_sel_gpiod) in tegra_pcie_dw_probe()
2018 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 1); in tegra_pcie_dw_probe()
2020 pcie->pex_ctl_supply = devm_regulator_get(dev, "vddio-pex-ctl"); in tegra_pcie_dw_probe()
2021 if (IS_ERR(pcie->pex_ctl_supply)) { in tegra_pcie_dw_probe()
2022 ret = PTR_ERR(pcie->pex_ctl_supply); in tegra_pcie_dw_probe()
2025 PTR_ERR(pcie->pex_ctl_supply)); in tegra_pcie_dw_probe()
2029 pcie->core_clk = devm_clk_get(dev, "core"); in tegra_pcie_dw_probe()
2030 if (IS_ERR(pcie->core_clk)) { in tegra_pcie_dw_probe()
2032 PTR_ERR(pcie->core_clk)); in tegra_pcie_dw_probe()
2033 return PTR_ERR(pcie->core_clk); in tegra_pcie_dw_probe()
2036 pcie->appl_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, in tegra_pcie_dw_probe()
2038 if (!pcie->appl_res) { in tegra_pcie_dw_probe()
2043 pcie->appl_base = devm_ioremap_resource(dev, pcie->appl_res); in tegra_pcie_dw_probe()
2044 if (IS_ERR(pcie->appl_base)) in tegra_pcie_dw_probe()
2045 return PTR_ERR(pcie->appl_base); in tegra_pcie_dw_probe()
2047 pcie->core_apb_rst = devm_reset_control_get(dev, "apb"); in tegra_pcie_dw_probe()
2048 if (IS_ERR(pcie->core_apb_rst)) { in tegra_pcie_dw_probe()
2050 PTR_ERR(pcie->core_apb_rst)); in tegra_pcie_dw_probe()
2051 return PTR_ERR(pcie->core_apb_rst); in tegra_pcie_dw_probe()
2054 phys = devm_kcalloc(dev, pcie->phy_count, sizeof(*phys), GFP_KERNEL); in tegra_pcie_dw_probe()
2058 for (i = 0; i < pcie->phy_count; i++) { in tegra_pcie_dw_probe()
2074 pcie->phys = phys; in tegra_pcie_dw_probe()
2082 pcie->atu_dma_res = atu_dma_res; in tegra_pcie_dw_probe()
2089 pcie->core_rst = devm_reset_control_get(dev, "core"); in tegra_pcie_dw_probe()
2090 if (IS_ERR(pcie->core_rst)) { in tegra_pcie_dw_probe()
2092 PTR_ERR(pcie->core_rst)); in tegra_pcie_dw_probe()
2093 return PTR_ERR(pcie->core_rst); in tegra_pcie_dw_probe()
2100 pcie->bpmp = tegra_bpmp_get(dev); in tegra_pcie_dw_probe()
2101 if (IS_ERR(pcie->bpmp)) in tegra_pcie_dw_probe()
2102 return PTR_ERR(pcie->bpmp); in tegra_pcie_dw_probe()
2104 platform_set_drvdata(pdev, pcie); in tegra_pcie_dw_probe()
2106 switch (pcie->mode) { in tegra_pcie_dw_probe()
2109 IRQF_SHARED, "tegra-pcie-intr", pcie); in tegra_pcie_dw_probe()
2116 ret = tegra_pcie_config_rp(pcie); in tegra_pcie_dw_probe()
2128 "tegra-pcie-ep-intr", pcie); in tegra_pcie_dw_probe()
2135 ret = tegra_pcie_config_ep(pcie, pdev); in tegra_pcie_dw_probe()
2141 dev_err(dev, "Invalid PCIe device type %d\n", pcie->mode); in tegra_pcie_dw_probe()
2145 tegra_bpmp_put(pcie->bpmp); in tegra_pcie_dw_probe()
2151 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev); in tegra_pcie_dw_remove() local
2153 if (!pcie->link_state) in tegra_pcie_dw_remove()
2156 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_dw_remove()
2157 tegra_pcie_deinit_controller(pcie); in tegra_pcie_dw_remove()
2158 pm_runtime_put_sync(pcie->dev); in tegra_pcie_dw_remove()
2159 pm_runtime_disable(pcie->dev); in tegra_pcie_dw_remove()
2160 tegra_bpmp_put(pcie->bpmp); in tegra_pcie_dw_remove()
2161 if (pcie->pex_refclk_sel_gpiod) in tegra_pcie_dw_remove()
2162 gpiod_set_value(pcie->pex_refclk_sel_gpiod, 0); in tegra_pcie_dw_remove()
2169 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_suspend_late() local
2172 if (!pcie->link_state) in tegra_pcie_dw_suspend_late()
2176 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_suspend_late()
2180 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_suspend_late()
2187 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_suspend_noirq() local
2189 if (!pcie->link_state) in tegra_pcie_dw_suspend_noirq()
2193 pcie->msi_ctrl_int = dw_pcie_readl_dbi(&pcie->pci, in tegra_pcie_dw_suspend_noirq()
2195 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_dw_suspend_noirq()
2196 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_dw_suspend_noirq()
2197 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_dw_suspend_noirq()
2204 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_resume_noirq() local
2207 if (!pcie->link_state) in tegra_pcie_dw_resume_noirq()
2210 ret = tegra_pcie_config_controller(pcie, true); in tegra_pcie_dw_resume_noirq()
2214 ret = tegra_pcie_dw_host_init(&pcie->pci.pp); in tegra_pcie_dw_resume_noirq()
2220 dw_pcie_setup_rc(&pcie->pci.pp); in tegra_pcie_dw_resume_noirq()
2222 ret = tegra_pcie_dw_start_link(&pcie->pci); in tegra_pcie_dw_resume_noirq()
2227 dw_pcie_writel_dbi(&pcie->pci, PORT_LOGIC_MSI_CTRL_INT_0_EN, in tegra_pcie_dw_resume_noirq()
2228 pcie->msi_ctrl_int); in tegra_pcie_dw_resume_noirq()
2233 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_dw_resume_noirq()
2239 struct tegra_pcie_dw *pcie = dev_get_drvdata(dev); in tegra_pcie_dw_resume_early() local
2242 if (pcie->mode == DW_PCIE_EP_TYPE) { in tegra_pcie_dw_resume_early()
2247 if (!pcie->link_state) in tegra_pcie_dw_resume_early()
2251 val = appl_readl(pcie, APPL_CTRL); in tegra_pcie_dw_resume_early()
2257 appl_writel(pcie, val, APPL_CTRL); in tegra_pcie_dw_resume_early()
2264 struct tegra_pcie_dw *pcie = platform_get_drvdata(pdev); in tegra_pcie_dw_shutdown() local
2266 if (!pcie->link_state) in tegra_pcie_dw_shutdown()
2269 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_dw_shutdown()
2270 tegra_pcie_downstream_dev_to_D0(pcie); in tegra_pcie_dw_shutdown()
2272 disable_irq(pcie->pci.pp.irq); in tegra_pcie_dw_shutdown()
2274 disable_irq(pcie->pci.pp.msi_irq); in tegra_pcie_dw_shutdown()
2276 tegra_pcie_dw_pme_turnoff(pcie); in tegra_pcie_dw_shutdown()
2277 tegra_pcie_unconfig_controller(pcie); in tegra_pcie_dw_shutdown()
2290 .compatible = "nvidia,tegra194-pcie",
2294 .compatible = "nvidia,tegra194-pcie-ep",
2312 .name = "tegra194-pcie",
2322 MODULE_DESCRIPTION("NVIDIA PCIe host controller driver");