Lines Matching +full:pcie +full:- +full:phy +full:- +full:2
1 // SPDX-License-Identifier: GPL-2.0
3 // Cadence PCIe controller driver.
4 // Author: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
9 #include "pcie-cadence.h"
11 void cdns_pcie_detect_quiet_min_delay_set(struct cdns_pcie *pcie) in cdns_pcie_detect_quiet_min_delay_set() argument
17 * Set the LTSSM Detect Quiet state min. delay to 2ms. in cdns_pcie_detect_quiet_min_delay_set()
19 ltssm_control_cap = cdns_pcie_readl(pcie, CDNS_PCIE_LTSSM_CONTROL_CAP); in cdns_pcie_detect_quiet_min_delay_set()
24 cdns_pcie_writel(pcie, CDNS_PCIE_LTSSM_CONTROL_CAP, ltssm_control_cap); in cdns_pcie_detect_quiet_min_delay_set()
27 void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 busnr, u8 fn, in cdns_pcie_set_outbound_region() argument
35 u64 sz = 1ULL << fls64(size - 1); in cdns_pcie_set_outbound_region()
47 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), addr0); in cdns_pcie_set_outbound_region()
48 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), addr1); in cdns_pcie_set_outbound_region()
50 /* Set the PCIe header descriptor */ in cdns_pcie_set_outbound_region()
59 * PCIe descriptor, the PCI function number must be set into in cdns_pcie_set_outbound_region()
63 * mode, the PCIe controller may support more than one function. This in cdns_pcie_set_outbound_region()
64 * function number needs to be set properly into the outbound PCIe in cdns_pcie_set_outbound_region()
73 * the PCIe controller will use the captured values for the bus and in cdns_pcie_set_outbound_region()
76 if (pcie->is_rc) { in cdns_pcie_set_outbound_region()
89 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), desc0); in cdns_pcie_set_outbound_region()
90 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), desc1); in cdns_pcie_set_outbound_region()
93 if (pcie->ops->cpu_addr_fixup) in cdns_pcie_set_outbound_region()
94 cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr); in cdns_pcie_set_outbound_region()
100 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), addr0); in cdns_pcie_set_outbound_region()
101 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), addr1); in cdns_pcie_set_outbound_region()
104 void cdns_pcie_set_outbound_region_for_normal_msg(struct cdns_pcie *pcie, in cdns_pcie_set_outbound_region_for_normal_msg() argument
114 if (pcie->is_rc) { in cdns_pcie_set_outbound_region_for_normal_msg()
123 if (pcie->ops->cpu_addr_fixup) in cdns_pcie_set_outbound_region_for_normal_msg()
124 cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr); in cdns_pcie_set_outbound_region_for_normal_msg()
130 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), 0); in cdns_pcie_set_outbound_region_for_normal_msg()
131 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), 0); in cdns_pcie_set_outbound_region_for_normal_msg()
132 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), desc0); in cdns_pcie_set_outbound_region_for_normal_msg()
133 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), desc1); in cdns_pcie_set_outbound_region_for_normal_msg()
134 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), addr0); in cdns_pcie_set_outbound_region_for_normal_msg()
135 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), addr1); in cdns_pcie_set_outbound_region_for_normal_msg()
138 void cdns_pcie_reset_outbound_region(struct cdns_pcie *pcie, u32 r) in cdns_pcie_reset_outbound_region() argument
140 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), 0); in cdns_pcie_reset_outbound_region()
141 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), 0); in cdns_pcie_reset_outbound_region()
143 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), 0); in cdns_pcie_reset_outbound_region()
144 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), 0); in cdns_pcie_reset_outbound_region()
146 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), 0); in cdns_pcie_reset_outbound_region()
147 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), 0); in cdns_pcie_reset_outbound_region()
150 void cdns_pcie_disable_phy(struct cdns_pcie *pcie) in cdns_pcie_disable_phy() argument
152 int i = pcie->phy_count; in cdns_pcie_disable_phy()
154 while (i--) { in cdns_pcie_disable_phy()
155 phy_power_off(pcie->phy[i]); in cdns_pcie_disable_phy()
156 phy_exit(pcie->phy[i]); in cdns_pcie_disable_phy()
160 int cdns_pcie_enable_phy(struct cdns_pcie *pcie) in cdns_pcie_enable_phy() argument
165 for (i = 0; i < pcie->phy_count; i++) { in cdns_pcie_enable_phy()
166 ret = phy_init(pcie->phy[i]); in cdns_pcie_enable_phy()
170 ret = phy_power_on(pcie->phy[i]); in cdns_pcie_enable_phy()
172 phy_exit(pcie->phy[i]); in cdns_pcie_enable_phy()
180 while (--i >= 0) { in cdns_pcie_enable_phy()
181 phy_power_off(pcie->phy[i]); in cdns_pcie_enable_phy()
182 phy_exit(pcie->phy[i]); in cdns_pcie_enable_phy()
188 int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie) in cdns_pcie_init_phy() argument
190 struct device_node *np = dev->of_node; in cdns_pcie_init_phy()
192 struct phy **phy; in cdns_pcie_init_phy() local
198 phy_count = of_property_count_strings(np, "phy-names"); in cdns_pcie_init_phy()
200 dev_err(dev, "no phy-names. PHY will not be initialized\n"); in cdns_pcie_init_phy()
201 pcie->phy_count = 0; in cdns_pcie_init_phy()
205 phy = devm_kcalloc(dev, phy_count, sizeof(*phy), GFP_KERNEL); in cdns_pcie_init_phy()
206 if (!phy) in cdns_pcie_init_phy()
207 return -ENOMEM; in cdns_pcie_init_phy()
211 return -ENOMEM; in cdns_pcie_init_phy()
214 of_property_read_string_index(np, "phy-names", i, &name); in cdns_pcie_init_phy()
215 phy[i] = devm_phy_get(dev, name); in cdns_pcie_init_phy()
216 if (IS_ERR(phy[i])) { in cdns_pcie_init_phy()
217 ret = PTR_ERR(phy[i]); in cdns_pcie_init_phy()
220 link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS); in cdns_pcie_init_phy()
222 devm_phy_put(dev, phy[i]); in cdns_pcie_init_phy()
223 ret = -EINVAL; in cdns_pcie_init_phy()
228 pcie->phy_count = phy_count; in cdns_pcie_init_phy()
229 pcie->phy = phy; in cdns_pcie_init_phy()
230 pcie->link = link; in cdns_pcie_init_phy()
232 ret = cdns_pcie_enable_phy(pcie); in cdns_pcie_init_phy()
239 while (--i >= 0) { in cdns_pcie_init_phy()
241 devm_phy_put(dev, phy[i]); in cdns_pcie_init_phy()
249 struct cdns_pcie *pcie = dev_get_drvdata(dev); in cdns_pcie_suspend_noirq() local
251 cdns_pcie_disable_phy(pcie); in cdns_pcie_suspend_noirq()
258 struct cdns_pcie *pcie = dev_get_drvdata(dev); in cdns_pcie_resume_noirq() local
261 ret = cdns_pcie_enable_phy(pcie); in cdns_pcie_resume_noirq()
263 dev_err(dev, "failed to enable phy\n"); in cdns_pcie_resume_noirq()