Lines Matching +full:pcie +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0
3 // Cadence PCIe controller driver.
4 // Author: Cyrille Pitchen <cyrille.pitchen@free-electrons.com>
10 #include "pcie-cadence.h"
13 u8 cdns_pcie_find_capability(struct cdns_pcie *pcie, u8 cap) in cdns_pcie_find_capability() argument
16 cap, pcie); in cdns_pcie_find_capability()
20 u16 cdns_pcie_find_ext_capability(struct cdns_pcie *pcie, u8 cap) in cdns_pcie_find_ext_capability() argument
22 return PCI_FIND_NEXT_EXT_CAP(cdns_pcie_read_cfg, 0, cap, pcie); in cdns_pcie_find_ext_capability()
26 void cdns_pcie_detect_quiet_min_delay_set(struct cdns_pcie *pcie) in cdns_pcie_detect_quiet_min_delay_set() argument
28 u32 delay = 0x3; in cdns_pcie_detect_quiet_min_delay_set()
34 ltssm_control_cap = cdns_pcie_readl(pcie, CDNS_PCIE_LTSSM_CONTROL_CAP); in cdns_pcie_detect_quiet_min_delay_set()
39 cdns_pcie_writel(pcie, CDNS_PCIE_LTSSM_CONTROL_CAP, ltssm_control_cap); in cdns_pcie_detect_quiet_min_delay_set()
43 void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 busnr, u8 fn, in cdns_pcie_set_outbound_region() argument
51 u64 sz = 1ULL << fls64(size - 1); in cdns_pcie_set_outbound_region()
63 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), addr0); in cdns_pcie_set_outbound_region()
64 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), addr1); in cdns_pcie_set_outbound_region()
66 /* Set the PCIe header descriptor */ in cdns_pcie_set_outbound_region()
71 desc1 = 0; in cdns_pcie_set_outbound_region()
75 * PCIe descriptor, the PCI function number must be set into in cdns_pcie_set_outbound_region()
78 * In Root Complex mode, the function number is always 0 but in Endpoint in cdns_pcie_set_outbound_region()
79 * mode, the PCIe controller may support more than one function. This in cdns_pcie_set_outbound_region()
80 * function number needs to be set properly into the outbound PCIe in cdns_pcie_set_outbound_region()
85 * Bits [7:0] of DESC1, resp. Bits[31:27] of DESC0. Like the function in cdns_pcie_set_outbound_region()
86 * number, the device number is always 0 in Root Complex mode. in cdns_pcie_set_outbound_region()
89 * the PCIe controller will use the captured values for the bus and in cdns_pcie_set_outbound_region()
92 if (pcie->is_rc) { in cdns_pcie_set_outbound_region()
93 /* The device and function numbers are always 0. */ in cdns_pcie_set_outbound_region()
95 CDNS_PCIE_AT_OB_REGION_DESC0_DEVFN(0); in cdns_pcie_set_outbound_region()
105 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), desc0); in cdns_pcie_set_outbound_region()
106 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), desc1); in cdns_pcie_set_outbound_region()
109 if (pcie->ops && pcie->ops->cpu_addr_fixup) in cdns_pcie_set_outbound_region()
110 cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr); in cdns_pcie_set_outbound_region()
116 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), addr0); in cdns_pcie_set_outbound_region()
117 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), addr1); in cdns_pcie_set_outbound_region()
121 void cdns_pcie_set_outbound_region_for_normal_msg(struct cdns_pcie *pcie, in cdns_pcie_set_outbound_region_for_normal_msg() argument
128 desc1 = 0; in cdns_pcie_set_outbound_region_for_normal_msg()
131 if (pcie->is_rc) { in cdns_pcie_set_outbound_region_for_normal_msg()
133 CDNS_PCIE_AT_OB_REGION_DESC0_DEVFN(0); in cdns_pcie_set_outbound_region_for_normal_msg()
140 if (pcie->ops && pcie->ops->cpu_addr_fixup) in cdns_pcie_set_outbound_region_for_normal_msg()
141 cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr); in cdns_pcie_set_outbound_region_for_normal_msg()
147 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), 0); in cdns_pcie_set_outbound_region_for_normal_msg()
148 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), 0); in cdns_pcie_set_outbound_region_for_normal_msg()
149 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), desc0); in cdns_pcie_set_outbound_region_for_normal_msg()
150 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), desc1); in cdns_pcie_set_outbound_region_for_normal_msg()
151 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), addr0); in cdns_pcie_set_outbound_region_for_normal_msg()
152 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), addr1); in cdns_pcie_set_outbound_region_for_normal_msg()
156 void cdns_pcie_reset_outbound_region(struct cdns_pcie *pcie, u32 r) in cdns_pcie_reset_outbound_region() argument
158 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR0(r), 0); in cdns_pcie_reset_outbound_region()
159 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(r), 0); in cdns_pcie_reset_outbound_region()
161 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC0(r), 0); in cdns_pcie_reset_outbound_region()
162 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), 0); in cdns_pcie_reset_outbound_region()
164 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), 0); in cdns_pcie_reset_outbound_region()
165 cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), 0); in cdns_pcie_reset_outbound_region()
169 void cdns_pcie_disable_phy(struct cdns_pcie *pcie) in cdns_pcie_disable_phy() argument
171 int i = pcie->phy_count; in cdns_pcie_disable_phy()
173 while (i--) { in cdns_pcie_disable_phy()
174 phy_power_off(pcie->phy[i]); in cdns_pcie_disable_phy()
175 phy_exit(pcie->phy[i]); in cdns_pcie_disable_phy()
180 int cdns_pcie_enable_phy(struct cdns_pcie *pcie) in cdns_pcie_enable_phy() argument
185 for (i = 0; i < pcie->phy_count; i++) { in cdns_pcie_enable_phy()
186 ret = phy_init(pcie->phy[i]); in cdns_pcie_enable_phy()
187 if (ret < 0) in cdns_pcie_enable_phy()
190 ret = phy_power_on(pcie->phy[i]); in cdns_pcie_enable_phy()
191 if (ret < 0) { in cdns_pcie_enable_phy()
192 phy_exit(pcie->phy[i]); in cdns_pcie_enable_phy()
197 return 0; in cdns_pcie_enable_phy()
200 while (--i >= 0) { in cdns_pcie_enable_phy()
201 phy_power_off(pcie->phy[i]); in cdns_pcie_enable_phy()
202 phy_exit(pcie->phy[i]); in cdns_pcie_enable_phy()
209 int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie) in cdns_pcie_init_phy() argument
211 struct device_node *np = dev->of_node; in cdns_pcie_init_phy()
219 phy_count = of_property_count_strings(np, "phy-names"); in cdns_pcie_init_phy()
221 dev_info(dev, "no \"phy-names\" property found; PHY will not be initialized\n"); in cdns_pcie_init_phy()
222 pcie->phy_count = 0; in cdns_pcie_init_phy()
223 return 0; in cdns_pcie_init_phy()
228 return -ENOMEM; in cdns_pcie_init_phy()
232 return -ENOMEM; in cdns_pcie_init_phy()
234 for (i = 0; i < phy_count; i++) { in cdns_pcie_init_phy()
235 of_property_read_string_index(np, "phy-names", i, &name); in cdns_pcie_init_phy()
241 link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS); in cdns_pcie_init_phy()
244 ret = -EINVAL; in cdns_pcie_init_phy()
249 pcie->phy_count = phy_count; in cdns_pcie_init_phy()
250 pcie->phy = phy; in cdns_pcie_init_phy()
251 pcie->link = link; in cdns_pcie_init_phy()
253 ret = cdns_pcie_enable_phy(pcie); in cdns_pcie_init_phy()
257 return 0; in cdns_pcie_init_phy()
260 while (--i >= 0) { in cdns_pcie_init_phy()
271 struct cdns_pcie *pcie = dev_get_drvdata(dev); in cdns_pcie_suspend_noirq() local
273 cdns_pcie_disable_phy(pcie); in cdns_pcie_suspend_noirq()
275 return 0; in cdns_pcie_suspend_noirq()
280 struct cdns_pcie *pcie = dev_get_drvdata(dev); in cdns_pcie_resume_noirq() local
283 ret = cdns_pcie_enable_phy(pcie); in cdns_pcie_resume_noirq()
289 return 0; in cdns_pcie_resume_noirq()
298 MODULE_DESCRIPTION("Cadence PCIe controller driver");
299 MODULE_AUTHOR("Cyrille Pitchen <cyrille.pitchen@free-electrons.com>");