Lines Matching +full:pci +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2013-2014 Texas Instruments., Ltd.
8 * Author: Murali Karicheri <m-karicheri2@ti.com>
9 * Implementation based on pci-exynos.c and pcie-designware.c
25 #include <linux/phy/phy.h>
31 #include "../../pci.h"
32 #include "pcie-designware.h"
55 #define PCIE_LEGACY_IRQ_ENABLE_SET(n) (0x188 + (0x10 * ((n) - 1)))
56 #define PCIE_LEGACY_IRQ_ENABLE_CLR(n) (0x18c + (0x10 * ((n) - 1)))
80 #define ERR_NONFATAL BIT(2) /* Non-fatal error */
106 #define to_keystone_pcie(x) dev_get_drvdata((x)->dev)
116 struct dw_pcie *pci; member
117 /* PCI Device ID */
125 struct phy **phy; member
139 return readl(ks_pcie->va_app_base + offset); in ks_pcie_app_readl()
145 writel(val, ks_pcie->va_app_base + offset); in ks_pcie_app_writel()
152 u32 irq = data->hwirq; in ks_pcie_msi_irq_ack()
153 struct dw_pcie *pci; in ks_pcie_msi_irq_ack() local
157 pci = to_dw_pcie_from_pp(pp); in ks_pcie_msi_irq_ack()
158 ks_pcie = to_keystone_pcie(pci); in ks_pcie_msi_irq_ack()
172 struct dw_pcie *pci; in ks_pcie_compose_msi_msg() local
175 pci = to_dw_pcie_from_pp(pp); in ks_pcie_compose_msi_msg()
176 ks_pcie = to_keystone_pcie(pci); in ks_pcie_compose_msi_msg()
178 msi_target = ks_pcie->app.start + MSI_IRQ; in ks_pcie_compose_msi_msg()
179 msg->address_lo = lower_32_bits(msi_target); in ks_pcie_compose_msi_msg()
180 msg->address_hi = upper_32_bits(msi_target); in ks_pcie_compose_msi_msg()
181 msg->data = data->hwirq; in ks_pcie_compose_msi_msg()
183 dev_dbg(pci->dev, "msi#%d address_hi %#x address_lo %#x\n", in ks_pcie_compose_msi_msg()
184 (int)data->hwirq, msg->address_hi, msg->address_lo); in ks_pcie_compose_msi_msg()
190 return -EINVAL; in ks_pcie_msi_set_affinity()
197 u32 irq = data->hwirq; in ks_pcie_msi_mask()
198 struct dw_pcie *pci; in ks_pcie_msi_mask() local
203 raw_spin_lock_irqsave(&pp->lock, flags); in ks_pcie_msi_mask()
205 pci = to_dw_pcie_from_pp(pp); in ks_pcie_msi_mask()
206 ks_pcie = to_keystone_pcie(pci); in ks_pcie_msi_mask()
214 raw_spin_unlock_irqrestore(&pp->lock, flags); in ks_pcie_msi_mask()
221 u32 irq = data->hwirq; in ks_pcie_msi_unmask()
222 struct dw_pcie *pci; in ks_pcie_msi_unmask() local
227 raw_spin_lock_irqsave(&pp->lock, flags); in ks_pcie_msi_unmask()
229 pci = to_dw_pcie_from_pp(pp); in ks_pcie_msi_unmask()
230 ks_pcie = to_keystone_pcie(pci); in ks_pcie_msi_unmask()
238 raw_spin_unlock_irqrestore(&pp->lock, flags); in ks_pcie_msi_unmask()
242 .name = "KEYSTONE-PCI-MSI",
252 pp->msi_irq_chip = &ks_pcie_msi_irq_chip; in ks_pcie_msi_host_init()
259 struct dw_pcie *pci = ks_pcie->pci; in ks_pcie_handle_legacy_irq() local
260 struct device *dev = pci->dev; in ks_pcie_handle_legacy_irq()
267 generic_handle_domain_irq(ks_pcie->legacy_irq_domain, offset); in ks_pcie_handle_legacy_irq()
282 struct device *dev = ks_pcie->pci->dev; in ks_pcie_handle_error_irq()
300 if (!ks_pcie->is_am6 && (reg & ERR_AXI)) in ks_pcie_handle_error_irq()
303 if (reg & ERR_AER || (ks_pcie->is_am6 && (reg & AM6_ERR_AER))) in ks_pcie_handle_error_irq()
324 .name = "Keystone-PCI-Legacy-IRQ",
336 irq_set_chip_data(irq, d->host_data); in ks_pcie_init_legacy_irq_map()
347 * ks_pcie_set_dbi_mode() - Set DBI mode to access overlaid BAR mask registers
368 * ks_pcie_clear_dbi_mode() - Disable DBI mode
391 u32 num_viewport = ks_pcie->num_viewport; in ks_pcie_setup_rc_app_regs()
392 struct dw_pcie *pci = ks_pcie->pci; in ks_pcie_setup_rc_app_regs() local
393 struct dw_pcie_rp *pp = &pci->pp; in ks_pcie_setup_rc_app_regs()
398 mem = resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM)->res; in ks_pcie_setup_rc_app_regs()
399 start = mem->start; in ks_pcie_setup_rc_app_regs()
400 end = mem->end; in ks_pcie_setup_rc_app_regs()
404 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0); in ks_pcie_setup_rc_app_regs()
405 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_1, 0); in ks_pcie_setup_rc_app_regs()
408 if (ks_pcie->is_am6) in ks_pcie_setup_rc_app_regs()
414 /* Using Direct 1:1 mapping of RC <-> PCI memory space */ in ks_pcie_setup_rc_app_regs()
431 struct dw_pcie_rp *pp = bus->sysdata; in ks_pcie_other_map_bus()
432 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in ks_pcie_other_map_bus() local
433 struct keystone_pcie *ks_pcie = to_keystone_pcie(pci); in ks_pcie_other_map_bus()
436 reg = CFG_BUS(bus->number) | CFG_DEVICE(PCI_SLOT(devfn)) | in ks_pcie_other_map_bus()
438 if (!pci_is_root_bus(bus->parent)) in ks_pcie_other_map_bus()
442 return pp->va_cfg0_base + where; in ks_pcie_other_map_bus()
452 * ks_pcie_v3_65_add_bus() - keystone add_bus post initialization
453 * @bus: A pointer to the PCI bus structure.
459 struct dw_pcie_rp *pp = bus->sysdata; in ks_pcie_v3_65_add_bus()
460 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in ks_pcie_v3_65_add_bus() local
461 struct keystone_pcie *ks_pcie = to_keystone_pcie(pci); in ks_pcie_v3_65_add_bus()
470 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 1); in ks_pcie_v3_65_add_bus()
471 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, SZ_4K - 1); in ks_pcie_v3_65_add_bus()
479 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, ks_pcie->app.start); in ks_pcie_v3_65_add_bus()
492 * ks_pcie_link_up() - Check if link up
493 * @pci: A pointer to the dw_pcie structure which holds the DesignWare PCIe host
496 static int ks_pcie_link_up(struct dw_pcie *pci) in ks_pcie_link_up() argument
500 val = dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0); in ks_pcie_link_up()
505 static void ks_pcie_stop_link(struct dw_pcie *pci) in ks_pcie_stop_link() argument
507 struct keystone_pcie *ks_pcie = to_keystone_pcie(pci); in ks_pcie_stop_link()
516 static int ks_pcie_start_link(struct dw_pcie *pci) in ks_pcie_start_link() argument
518 struct keystone_pcie *ks_pcie = to_keystone_pcie(pci); in ks_pcie_start_link()
530 struct pci_bus *bus = dev->bus; in ks_pcie_quirk()
549 bridge = bus->self; in ks_pcie_quirk()
550 bus = bus->parent; in ks_pcie_quirk()
557 * Keystone PCI controller has a h/w limitation of in ks_pcie_quirk()
564 dev_info(&dev->dev, "limiting MRRS to 256\n"); in ks_pcie_quirk()
573 unsigned int irq = desc->irq_data.hwirq; in ks_pcie_msi_irq_handler()
575 u32 offset = irq - ks_pcie->msi_host_irq; in ks_pcie_msi_irq_handler()
576 struct dw_pcie *pci = ks_pcie->pci; in ks_pcie_msi_irq_handler() local
577 struct dw_pcie_rp *pp = &pci->pp; in ks_pcie_msi_irq_handler()
578 struct device *dev = pci->dev; in ks_pcie_msi_irq_handler()
593 * MSI0 status bit 0-3 shows vectors 0, 8, 16, 24, MSI1 status bit in ks_pcie_msi_irq_handler()
602 generic_handle_domain_irq(pp->irq_domain, vector); in ks_pcie_msi_irq_handler()
609 * ks_pcie_legacy_irq_handler() - Handle legacy interrupt
619 struct dw_pcie *pci = ks_pcie->pci; in ks_pcie_legacy_irq_handler() local
620 struct device *dev = pci->dev; in ks_pcie_legacy_irq_handler()
621 u32 irq_offset = irq - ks_pcie->legacy_host_irqs[0]; in ks_pcie_legacy_irq_handler()
638 struct device *dev = ks_pcie->pci->dev; in ks_pcie_config_msi_irq()
639 struct device_node *np = ks_pcie->np; in ks_pcie_config_msi_irq()
647 intc_np = of_get_child_by_name(np, "msi-interrupt-controller"); in ks_pcie_config_msi_irq()
649 if (ks_pcie->is_am6) in ks_pcie_config_msi_irq()
651 dev_warn(dev, "msi-interrupt-controller node is absent\n"); in ks_pcie_config_msi_irq()
652 return -EINVAL; in ks_pcie_config_msi_irq()
657 dev_err(dev, "No IRQ entries in msi-interrupt-controller\n"); in ks_pcie_config_msi_irq()
658 ret = -EINVAL; in ks_pcie_config_msi_irq()
665 ret = -EINVAL; in ks_pcie_config_msi_irq()
669 if (!ks_pcie->msi_host_irq) { in ks_pcie_config_msi_irq()
672 ret = -EINVAL; in ks_pcie_config_msi_irq()
675 ks_pcie->msi_host_irq = irq_data->hwirq; in ks_pcie_config_msi_irq()
692 struct device *dev = ks_pcie->pci->dev; in ks_pcie_config_legacy_irq()
694 struct device_node *np = ks_pcie->np; in ks_pcie_config_legacy_irq()
698 intc_np = of_get_child_by_name(np, "legacy-interrupt-controller"); in ks_pcie_config_legacy_irq()
701 * Since legacy interrupts are modeled as edge-interrupts in in ks_pcie_config_legacy_irq()
704 if (ks_pcie->is_am6) in ks_pcie_config_legacy_irq()
706 dev_warn(dev, "legacy-interrupt-controller node is absent\n"); in ks_pcie_config_legacy_irq()
707 return -EINVAL; in ks_pcie_config_legacy_irq()
712 dev_err(dev, "No IRQ entries in legacy-interrupt-controller\n"); in ks_pcie_config_legacy_irq()
713 ret = -EINVAL; in ks_pcie_config_legacy_irq()
720 ret = -EINVAL; in ks_pcie_config_legacy_irq()
723 ks_pcie->legacy_host_irqs[i] = irq; in ks_pcie_config_legacy_irq()
735 ret = -EINVAL; in ks_pcie_config_legacy_irq()
738 ks_pcie->legacy_irq_domain = legacy_irq_domain; in ks_pcie_config_legacy_irq()
750 * When a PCI device does not exist during config cycles, keystone host
762 regs->uregs[reg] = -1; in ks_pcie_fault()
763 regs->ARM_pc += 4; in ks_pcie_fault()
775 struct dw_pcie *pci = ks_pcie->pci; in ks_pcie_init_id() local
776 struct device *dev = pci->dev; in ks_pcie_init_id()
777 struct device_node *np = dev->of_node; in ks_pcie_init_id()
781 devctrl_regs = syscon_regmap_lookup_by_phandle(np, "ti,syscon-pcie-id"); in ks_pcie_init_id()
786 ret = of_parse_phandle_with_fixed_args(np, "ti,syscon-pcie-id", 1, 0, &args); in ks_pcie_init_id()
794 dw_pcie_dbi_ro_wr_en(pci); in ks_pcie_init_id()
795 dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, id & PCIE_VENDORID_MASK); in ks_pcie_init_id()
796 dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, id >> PCIE_DEVICEID_SHIFT); in ks_pcie_init_id()
797 dw_pcie_dbi_ro_wr_dis(pci); in ks_pcie_init_id()
804 struct dw_pcie *pci = to_dw_pcie_from_pp(pp); in ks_pcie_host_init() local
805 struct keystone_pcie *ks_pcie = to_keystone_pcie(pci); in ks_pcie_host_init()
808 pp->bridge->ops = &ks_pcie_ops; in ks_pcie_host_init()
809 if (!ks_pcie->is_am6) in ks_pcie_host_init()
810 pp->bridge->child_ops = &ks_child_pcie_ops; in ks_pcie_host_init()
820 ks_pcie_stop_link(pci); in ks_pcie_host_init()
823 pci->dbi_base + PCI_IO_BASE); in ks_pcie_host_init()
857 static void ks_pcie_am654_write_dbi2(struct dw_pcie *pci, void __iomem *base, in ks_pcie_am654_write_dbi2() argument
860 struct keystone_pcie *ks_pcie = to_keystone_pcie(pci); in ks_pcie_am654_write_dbi2()
876 struct dw_pcie *pci = to_dw_pcie_from_ep(ep); in ks_pcie_am654_ep_init() local
879 ep->page_size = AM654_WIN_SIZE; in ks_pcie_am654_ep_init()
881 dw_pcie_writel_dbi2(pci, PCI_BASE_ADDRESS_0, APP_ADDR_SPACE_0 - 1); in ks_pcie_am654_ep_init()
882 dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, flags); in ks_pcie_am654_ep_init()
887 struct dw_pcie *pci = ks_pcie->pci; in ks_pcie_am654_raise_legacy_irq() local
890 int_pin = dw_pcie_readb_dbi(pci, PCI_INTERRUPT_PIN); in ks_pcie_am654_raise_legacy_irq()
907 struct dw_pcie *pci = to_dw_pcie_from_ep(ep); in ks_pcie_am654_raise_irq() local
908 struct keystone_pcie *ks_pcie = to_keystone_pcie(pci); in ks_pcie_am654_raise_irq()
921 dev_err(pci->dev, "UNKNOWN IRQ type\n"); in ks_pcie_am654_raise_irq()
922 return -EINVAL; in ks_pcie_am654_raise_irq()
955 int num_lanes = ks_pcie->num_lanes; in ks_pcie_disable_phy()
957 while (num_lanes--) { in ks_pcie_disable_phy()
958 phy_power_off(ks_pcie->phy[num_lanes]); in ks_pcie_disable_phy()
959 phy_exit(ks_pcie->phy[num_lanes]); in ks_pcie_disable_phy()
967 int num_lanes = ks_pcie->num_lanes; in ks_pcie_enable_phy()
970 ret = phy_reset(ks_pcie->phy[i]); in ks_pcie_enable_phy()
974 ret = phy_init(ks_pcie->phy[i]); in ks_pcie_enable_phy()
978 ret = phy_power_on(ks_pcie->phy[i]); in ks_pcie_enable_phy()
980 phy_exit(ks_pcie->phy[i]); in ks_pcie_enable_phy()
988 while (--i >= 0) { in ks_pcie_enable_phy()
989 phy_power_off(ks_pcie->phy[i]); in ks_pcie_enable_phy()
990 phy_exit(ks_pcie->phy[i]); in ks_pcie_enable_phy()
998 struct device_node *np = dev->of_node; in ks_pcie_set_mode()
1006 syscon = syscon_regmap_lookup_by_phandle(np, "ti,syscon-pcie-mode"); in ks_pcie_set_mode()
1011 ret = of_parse_phandle_with_fixed_args(np, "ti,syscon-pcie-mode", 1, 0, &args); in ks_pcie_set_mode()
1030 struct device_node *np = dev->of_node; in ks_pcie_am654_set_mode()
1038 syscon = syscon_regmap_lookup_by_phandle(np, "ti,syscon-pcie-mode"); in ks_pcie_am654_set_mode()
1043 ret = of_parse_phandle_with_fixed_args(np, "ti,syscon-pcie-mode", 1, 0, &args); in ks_pcie_am654_set_mode()
1058 return -EINVAL; in ks_pcie_am654_set_mode()
1089 .type = "pci",
1091 .compatible = "ti,keystone-pcie",
1095 .compatible = "ti,am654-pcie-rc",
1099 .compatible = "ti,am654-pcie-ep",
1108 struct device *dev = &pdev->dev; in ks_pcie_probe()
1109 struct device_node *np = dev->of_node; in ks_pcie_probe()
1112 struct dw_pcie *pci; in ks_pcie_probe() local
1119 struct phy **phy; in ks_pcie_probe() local
1129 return -EINVAL; in ks_pcie_probe()
1131 version = data->version; in ks_pcie_probe()
1132 host_ops = data->host_ops; in ks_pcie_probe()
1133 ep_ops = data->ep_ops; in ks_pcie_probe()
1134 mode = data->mode; in ks_pcie_probe()
1138 return -ENOMEM; in ks_pcie_probe()
1140 pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); in ks_pcie_probe()
1141 if (!pci) in ks_pcie_probe()
1142 return -ENOMEM; in ks_pcie_probe()
1145 ks_pcie->va_app_base = devm_ioremap_resource(dev, res); in ks_pcie_probe()
1146 if (IS_ERR(ks_pcie->va_app_base)) in ks_pcie_probe()
1147 return PTR_ERR(ks_pcie->va_app_base); in ks_pcie_probe()
1149 ks_pcie->app = *res; in ks_pcie_probe()
1156 if (of_device_is_compatible(np, "ti,am654-pcie-rc")) in ks_pcie_probe()
1157 ks_pcie->is_am6 = true; in ks_pcie_probe()
1159 pci->dbi_base = base; in ks_pcie_probe()
1160 pci->dbi_base2 = base; in ks_pcie_probe()
1161 pci->dev = dev; in ks_pcie_probe()
1162 pci->ops = &ks_pcie_dw_pcie_ops; in ks_pcie_probe()
1163 pci->version = version; in ks_pcie_probe()
1170 "ks-pcie-error-irq", ks_pcie); in ks_pcie_probe()
1177 ret = of_property_read_u32(np, "num-lanes", &num_lanes); in ks_pcie_probe()
1181 phy = devm_kzalloc(dev, sizeof(*phy) * num_lanes, GFP_KERNEL); in ks_pcie_probe()
1182 if (!phy) in ks_pcie_probe()
1183 return -ENOMEM; in ks_pcie_probe()
1187 return -ENOMEM; in ks_pcie_probe()
1190 snprintf(name, sizeof(name), "pcie-phy%d", i); in ks_pcie_probe()
1191 phy[i] = devm_phy_optional_get(dev, name); in ks_pcie_probe()
1192 if (IS_ERR(phy[i])) { in ks_pcie_probe()
1193 ret = PTR_ERR(phy[i]); in ks_pcie_probe()
1197 if (!phy[i]) in ks_pcie_probe()
1200 link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS); in ks_pcie_probe()
1202 ret = -EINVAL; in ks_pcie_probe()
1207 ks_pcie->np = np; in ks_pcie_probe()
1208 ks_pcie->pci = pci; in ks_pcie_probe()
1209 ks_pcie->link = link; in ks_pcie_probe()
1210 ks_pcie->num_lanes = num_lanes; in ks_pcie_probe()
1211 ks_pcie->phy = phy; in ks_pcie_probe()
1217 if (ret != -EPROBE_DEFER) in ks_pcie_probe()
1224 dev_err(dev, "failed to enable phy\n"); in ks_pcie_probe()
1236 if (dw_pcie_ver_is_ge(pci, 480A)) in ks_pcie_probe()
1246 ret = -ENODEV; in ks_pcie_probe()
1250 ret = of_property_read_u32(np, "num-viewport", &num_viewport); in ks_pcie_probe()
1252 dev_err(dev, "unable to read *num-viewport* property\n"); in ks_pcie_probe()
1258 * PCI EXPRESS CARD ELECTROMECHANICAL SPECIFICATION, REV. 2.0 in ks_pcie_probe()
1261 * mode is selected while enabling the PHY. So deassert PERST# in ks_pcie_probe()
1269 ks_pcie->num_viewport = num_viewport; in ks_pcie_probe()
1270 pci->pp.ops = host_ops; in ks_pcie_probe()
1271 ret = dw_pcie_host_init(&pci->pp); in ks_pcie_probe()
1277 ret = -ENODEV; in ks_pcie_probe()
1281 pci->ep.ops = ep_ops; in ks_pcie_probe()
1282 ret = dw_pcie_ep_init(&pci->ep); in ks_pcie_probe()
1300 while (--i >= 0 && link[i]) in ks_pcie_probe()
1309 struct device_link **link = ks_pcie->link; in ks_pcie_remove()
1310 int num_lanes = ks_pcie->num_lanes; in ks_pcie_remove()
1311 struct device *dev = &pdev->dev; in ks_pcie_remove()
1316 while (num_lanes--) in ks_pcie_remove()
1326 .name = "keystone-pcie",