Lines Matching refs:pcie

160 static void rcar_pci_write_reg(struct rcar_pcie *pcie, unsigned long val,  in rcar_pci_write_reg()  argument
163 writel(val, pcie->base + reg); in rcar_pci_write_reg()
166 static unsigned long rcar_pci_read_reg(struct rcar_pcie *pcie, in rcar_pci_read_reg() argument
169 return readl(pcie->base + reg); in rcar_pci_read_reg()
177 static void rcar_rmw32(struct rcar_pcie *pcie, int where, u32 mask, u32 data) in rcar_rmw32() argument
180 u32 val = rcar_pci_read_reg(pcie, where & ~3); in rcar_rmw32()
184 rcar_pci_write_reg(pcie, val, where & ~3); in rcar_rmw32()
187 static u32 rcar_read_conf(struct rcar_pcie *pcie, int where) in rcar_read_conf() argument
190 u32 val = rcar_pci_read_reg(pcie, where & ~3); in rcar_read_conf()
196 static int rcar_pcie_config_access(struct rcar_pcie *pcie, in rcar_pcie_config_access() argument
227 *data = rcar_pci_read_reg(pcie, PCICONF(index)); in rcar_pcie_config_access()
231 pcie->root_bus_nr = *data & 0xff; in rcar_pcie_config_access()
233 rcar_pci_write_reg(pcie, *data, PCICONF(index)); in rcar_pcie_config_access()
239 if (pcie->root_bus_nr < 0) in rcar_pcie_config_access()
243 rcar_pci_write_reg(pcie, rcar_pci_read_reg(pcie, PCIEERRFR), PCIEERRFR); in rcar_pcie_config_access()
246 rcar_pci_write_reg(pcie, PCIE_CONF_BUS(bus->number) | in rcar_pcie_config_access()
250 if (bus->parent->number == pcie->root_bus_nr) in rcar_pcie_config_access()
251 rcar_pci_write_reg(pcie, CONFIG_SEND_ENABLE | TYPE0, PCIECCTLR); in rcar_pcie_config_access()
253 rcar_pci_write_reg(pcie, CONFIG_SEND_ENABLE | TYPE1, PCIECCTLR); in rcar_pcie_config_access()
256 if (rcar_pci_read_reg(pcie, PCIEERRFR) & UNSUPPORTED_REQUEST) in rcar_pcie_config_access()
260 if (rcar_read_conf(pcie, RCONF(PCI_STATUS)) & in rcar_pcie_config_access()
265 *data = rcar_pci_read_reg(pcie, PCIECDR); in rcar_pcie_config_access()
267 rcar_pci_write_reg(pcie, *data, PCIECDR); in rcar_pcie_config_access()
270 rcar_pci_write_reg(pcie, 0, PCIECCTLR); in rcar_pcie_config_access()
278 struct rcar_pcie *pcie = bus->sysdata; in rcar_pcie_read_conf() local
281 ret = rcar_pcie_config_access(pcie, RCAR_PCI_ACCESS_READ, in rcar_pcie_read_conf()
303 struct rcar_pcie *pcie = bus->sysdata; in rcar_pcie_write_conf() local
307 ret = rcar_pcie_config_access(pcie, RCAR_PCI_ACCESS_READ, in rcar_pcie_write_conf()
326 ret = rcar_pcie_config_access(pcie, RCAR_PCI_ACCESS_WRITE, in rcar_pcie_write_conf()
337 static void rcar_pcie_setup_window(int win, struct rcar_pcie *pcie, in rcar_pcie_setup_window() argument
346 rcar_pci_write_reg(pcie, 0x00000000, PCIEPTCTLR(win)); in rcar_pcie_setup_window()
354 rcar_pci_write_reg(pcie, mask << 7, PCIEPAMR(win)); in rcar_pcie_setup_window()
361 rcar_pci_write_reg(pcie, upper_32_bits(res_start), PCIEPAUR(win)); in rcar_pcie_setup_window()
362 rcar_pci_write_reg(pcie, lower_32_bits(res_start) & ~0x7F, in rcar_pcie_setup_window()
370 rcar_pci_write_reg(pcie, mask, PCIEPTCTLR(win)); in rcar_pcie_setup_window()
404 static void rcar_pcie_force_speedup(struct rcar_pcie *pcie) in rcar_pcie_force_speedup() argument
406 struct device *dev = pcie->dev; in rcar_pcie_force_speedup()
410 if ((rcar_pci_read_reg(pcie, MACS2R) & LINK_SPEED) != LINK_SPEED_5_0GTS) in rcar_pcie_force_speedup()
413 if (rcar_pci_read_reg(pcie, MACCTLR) & SPEED_CHANGE) { in rcar_pcie_force_speedup()
418 macsr = rcar_pci_read_reg(pcie, MACSR); in rcar_pcie_force_speedup()
423 rcar_rmw32(pcie, EXPCAP(12), PCI_EXP_LNKSTA_CLS, in rcar_pcie_force_speedup()
427 rcar_rmw32(pcie, MACCGSPSETR, SPCNGRSN, 0); in rcar_pcie_force_speedup()
431 rcar_pci_write_reg(pcie, macsr, MACSR); in rcar_pcie_force_speedup()
434 rcar_rmw32(pcie, MACCTLR, SPEED_CHANGE, SPEED_CHANGE); in rcar_pcie_force_speedup()
437 macsr = rcar_pci_read_reg(pcie, MACSR); in rcar_pcie_force_speedup()
440 rcar_pci_write_reg(pcie, macsr, MACSR); in rcar_pcie_force_speedup()
458 static int rcar_pcie_enable(struct rcar_pcie *pcie) in rcar_pcie_enable() argument
460 struct device *dev = pcie->dev; in rcar_pcie_enable()
461 struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); in rcar_pcie_enable()
466 rcar_pcie_force_speedup(pcie); in rcar_pcie_enable()
468 rcar_pcie_setup(&bridge->windows, pcie); in rcar_pcie_enable()
473 bridge->sysdata = pcie; in rcar_pcie_enable()
474 bridge->busnr = pcie->root_bus_nr; in rcar_pcie_enable()
479 bridge->msi = &pcie->msi.chip; in rcar_pcie_enable()
498 static int phy_wait_for_ack(struct rcar_pcie *pcie) in phy_wait_for_ack() argument
500 struct device *dev = pcie->dev; in phy_wait_for_ack()
504 if (rcar_pci_read_reg(pcie, H1_PCIEPHYADRR) & PHY_ACK) in phy_wait_for_ack()
515 static void phy_write_reg(struct rcar_pcie *pcie, in phy_write_reg() argument
527 rcar_pci_write_reg(pcie, data, H1_PCIEPHYDOUTR); in phy_write_reg()
528 rcar_pci_write_reg(pcie, phyaddr, H1_PCIEPHYADRR); in phy_write_reg()
531 phy_wait_for_ack(pcie); in phy_write_reg()
534 rcar_pci_write_reg(pcie, 0, H1_PCIEPHYDOUTR); in phy_write_reg()
535 rcar_pci_write_reg(pcie, 0, H1_PCIEPHYADRR); in phy_write_reg()
538 phy_wait_for_ack(pcie); in phy_write_reg()
541 static int rcar_pcie_wait_for_phyrdy(struct rcar_pcie *pcie) in rcar_pcie_wait_for_phyrdy() argument
546 if (rcar_pci_read_reg(pcie, PCIEPHYSR) & PHYRDY) in rcar_pcie_wait_for_phyrdy()
555 static int rcar_pcie_wait_for_dl(struct rcar_pcie *pcie) in rcar_pcie_wait_for_dl() argument
560 if ((rcar_pci_read_reg(pcie, PCIETSTR) & DATA_LINK_ACTIVE)) in rcar_pcie_wait_for_dl()
570 static int rcar_pcie_hw_init(struct rcar_pcie *pcie) in rcar_pcie_hw_init() argument
575 rcar_pci_write_reg(pcie, 0, PCIETCTLR); in rcar_pcie_hw_init()
578 rcar_pci_write_reg(pcie, 1, PCIEMSR); in rcar_pcie_hw_init()
580 err = rcar_pcie_wait_for_phyrdy(pcie); in rcar_pcie_hw_init()
589 rcar_pci_write_reg(pcie, PCI_CLASS_BRIDGE_PCI << 16, IDSETR1); in rcar_pcie_hw_init()
595 rcar_rmw32(pcie, RCONF(PCI_SECONDARY_BUS), 0xff, 1); in rcar_pcie_hw_init()
596 rcar_rmw32(pcie, RCONF(PCI_SUBORDINATE_BUS), 0xff, 1); in rcar_pcie_hw_init()
599 rcar_rmw32(pcie, REXPCAP(0), 0xff, PCI_CAP_ID_EXP); in rcar_pcie_hw_init()
600 rcar_rmw32(pcie, REXPCAP(PCI_EXP_FLAGS), in rcar_pcie_hw_init()
602 rcar_rmw32(pcie, RCONF(PCI_HEADER_TYPE), 0x7f, in rcar_pcie_hw_init()
606 rcar_rmw32(pcie, REXPCAP(PCI_EXP_LNKCAP), PCI_EXP_LNKCAP_DLLLARC, in rcar_pcie_hw_init()
610 rcar_rmw32(pcie, REXPCAP(PCI_EXP_SLTCAP), PCI_EXP_SLTCAP_PSN, 0); in rcar_pcie_hw_init()
613 rcar_rmw32(pcie, TLCTLR + 1, 0x3f, 50); in rcar_pcie_hw_init()
616 rcar_rmw32(pcie, RVCCAP(0), 0xfff00000, 0); in rcar_pcie_hw_init()
620 rcar_pci_write_reg(pcie, 0x801f0000, PCIEMSITXR); in rcar_pcie_hw_init()
622 rcar_pci_write_reg(pcie, MACCTLR_INIT_VAL, MACCTLR); in rcar_pcie_hw_init()
625 rcar_pci_write_reg(pcie, CFINIT, PCIETCTLR); in rcar_pcie_hw_init()
628 err = rcar_pcie_wait_for_dl(pcie); in rcar_pcie_hw_init()
633 rcar_rmw32(pcie, PCIEINTXR, 0, 0xF << 8); in rcar_pcie_hw_init()
640 static int rcar_pcie_phy_init_h1(struct rcar_pcie *pcie) in rcar_pcie_phy_init_h1() argument
643 phy_write_reg(pcie, 0, 0x42, 0x1, 0x0EC34191); in rcar_pcie_phy_init_h1()
644 phy_write_reg(pcie, 1, 0x42, 0x1, 0x0EC34180); in rcar_pcie_phy_init_h1()
645 phy_write_reg(pcie, 0, 0x43, 0x1, 0x00210188); in rcar_pcie_phy_init_h1()
646 phy_write_reg(pcie, 1, 0x43, 0x1, 0x00210188); in rcar_pcie_phy_init_h1()
647 phy_write_reg(pcie, 0, 0x44, 0x1, 0x015C0014); in rcar_pcie_phy_init_h1()
648 phy_write_reg(pcie, 1, 0x44, 0x1, 0x015C0014); in rcar_pcie_phy_init_h1()
649 phy_write_reg(pcie, 1, 0x4C, 0x1, 0x786174A0); in rcar_pcie_phy_init_h1()
650 phy_write_reg(pcie, 1, 0x4D, 0x1, 0x048000BB); in rcar_pcie_phy_init_h1()
651 phy_write_reg(pcie, 0, 0x51, 0x1, 0x079EC062); in rcar_pcie_phy_init_h1()
652 phy_write_reg(pcie, 0, 0x52, 0x1, 0x20000000); in rcar_pcie_phy_init_h1()
653 phy_write_reg(pcie, 1, 0x52, 0x1, 0x20000000); in rcar_pcie_phy_init_h1()
654 phy_write_reg(pcie, 1, 0x56, 0x1, 0x00003806); in rcar_pcie_phy_init_h1()
656 phy_write_reg(pcie, 0, 0x60, 0x1, 0x004B03A5); in rcar_pcie_phy_init_h1()
657 phy_write_reg(pcie, 0, 0x64, 0x1, 0x3F0F1F0F); in rcar_pcie_phy_init_h1()
658 phy_write_reg(pcie, 0, 0x66, 0x1, 0x00008000); in rcar_pcie_phy_init_h1()
663 static int rcar_pcie_phy_init_gen2(struct rcar_pcie *pcie) in rcar_pcie_phy_init_gen2() argument
669 rcar_pci_write_reg(pcie, 0x000f0030, GEN2_PCIEPHYADDR); in rcar_pcie_phy_init_gen2()
670 rcar_pci_write_reg(pcie, 0x00381203, GEN2_PCIEPHYDATA); in rcar_pcie_phy_init_gen2()
671 rcar_pci_write_reg(pcie, 0x00000001, GEN2_PCIEPHYCTRL); in rcar_pcie_phy_init_gen2()
672 rcar_pci_write_reg(pcie, 0x00000006, GEN2_PCIEPHYCTRL); in rcar_pcie_phy_init_gen2()
674 rcar_pci_write_reg(pcie, 0x000f0054, GEN2_PCIEPHYADDR); in rcar_pcie_phy_init_gen2()
676 rcar_pci_write_reg(pcie, 0x13802007, GEN2_PCIEPHYDATA); in rcar_pcie_phy_init_gen2()
677 rcar_pci_write_reg(pcie, 0x00000001, GEN2_PCIEPHYCTRL); in rcar_pcie_phy_init_gen2()
678 rcar_pci_write_reg(pcie, 0x00000006, GEN2_PCIEPHYCTRL); in rcar_pcie_phy_init_gen2()
683 static int rcar_pcie_phy_init_gen3(struct rcar_pcie *pcie) in rcar_pcie_phy_init_gen3() argument
687 err = phy_init(pcie->phy); in rcar_pcie_phy_init_gen3()
691 err = phy_power_on(pcie->phy); in rcar_pcie_phy_init_gen3()
693 phy_exit(pcie->phy); in rcar_pcie_phy_init_gen3()
736 struct rcar_pcie *pcie = data; in rcar_pcie_msi_irq() local
737 struct rcar_msi *msi = &pcie->msi; in rcar_pcie_msi_irq()
738 struct device *dev = pcie->dev; in rcar_pcie_msi_irq()
741 reg = rcar_pci_read_reg(pcie, PCIEMSIFR); in rcar_pcie_msi_irq()
752 rcar_pci_write_reg(pcie, 1 << index, PCIEMSIFR); in rcar_pcie_msi_irq()
766 reg = rcar_pci_read_reg(pcie, PCIEMSIFR); in rcar_pcie_msi_irq()
776 struct rcar_pcie *pcie = container_of(chip, struct rcar_pcie, msi.chip); in rcar_msi_setup_irq() local
793 msg.address_lo = rcar_pci_read_reg(pcie, PCIEMSIALR) & ~MSIFE; in rcar_msi_setup_irq()
794 msg.address_hi = rcar_pci_read_reg(pcie, PCIEMSIAUR); in rcar_msi_setup_irq()
805 struct rcar_pcie *pcie = container_of(chip, struct rcar_pcie, msi.chip); in rcar_msi_setup_irqs() local
845 msg.address_lo = rcar_pci_read_reg(pcie, PCIEMSIALR) & ~MSIFE; in rcar_msi_setup_irqs()
846 msg.address_hi = rcar_pci_read_reg(pcie, PCIEMSIAUR); in rcar_msi_setup_irqs()
883 static void rcar_pcie_unmap_msi(struct rcar_pcie *pcie) in rcar_pcie_unmap_msi() argument
885 struct rcar_msi *msi = &pcie->msi; in rcar_pcie_unmap_msi()
897 static int rcar_pcie_enable_msi(struct rcar_pcie *pcie) in rcar_pcie_enable_msi() argument
899 struct device *dev = pcie->dev; in rcar_pcie_enable_msi()
900 struct rcar_msi *msi = &pcie->msi; in rcar_pcie_enable_msi()
924 rcar_msi_irq_chip.name, pcie); in rcar_pcie_enable_msi()
932 rcar_msi_irq_chip.name, pcie); in rcar_pcie_enable_msi()
946 rcar_pci_write_reg(pcie, lower_32_bits(base) | MSIFE, PCIEMSIALR); in rcar_pcie_enable_msi()
947 rcar_pci_write_reg(pcie, upper_32_bits(base), PCIEMSIAUR); in rcar_pcie_enable_msi()
950 rcar_pci_write_reg(pcie, 0xffffffff, PCIEMSIIER); in rcar_pcie_enable_msi()
955 rcar_pcie_unmap_msi(pcie); in rcar_pcie_enable_msi()
959 static void rcar_pcie_teardown_msi(struct rcar_pcie *pcie) in rcar_pcie_teardown_msi() argument
961 struct rcar_msi *msi = &pcie->msi; in rcar_pcie_teardown_msi()
964 rcar_pci_write_reg(pcie, 0, PCIEMSIIER); in rcar_pcie_teardown_msi()
967 rcar_pci_write_reg(pcie, 0, PCIEMSIALR); in rcar_pcie_teardown_msi()
971 rcar_pcie_unmap_msi(pcie); in rcar_pcie_teardown_msi()
974 static int rcar_pcie_get_resources(struct rcar_pcie *pcie) in rcar_pcie_get_resources() argument
976 struct device *dev = pcie->dev; in rcar_pcie_get_resources()
980 pcie->phy = devm_phy_optional_get(dev, "pcie"); in rcar_pcie_get_resources()
981 if (IS_ERR(pcie->phy)) in rcar_pcie_get_resources()
982 return PTR_ERR(pcie->phy); in rcar_pcie_get_resources()
988 pcie->base = devm_ioremap_resource(dev, &res); in rcar_pcie_get_resources()
989 if (IS_ERR(pcie->base)) in rcar_pcie_get_resources()
990 return PTR_ERR(pcie->base); in rcar_pcie_get_resources()
992 pcie->bus_clk = devm_clk_get(dev, "pcie_bus"); in rcar_pcie_get_resources()
993 if (IS_ERR(pcie->bus_clk)) { in rcar_pcie_get_resources()
995 return PTR_ERR(pcie->bus_clk); in rcar_pcie_get_resources()
1004 pcie->msi.irq1 = i; in rcar_pcie_get_resources()
1012 pcie->msi.irq2 = i; in rcar_pcie_get_resources()
1017 irq_dispose_mapping(pcie->msi.irq1); in rcar_pcie_get_resources()
1022 static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie, in rcar_pcie_inbound_ranges() argument
1061 rcar_pci_write_reg(pcie, lower_32_bits(pci_addr), in rcar_pcie_inbound_ranges()
1063 rcar_pci_write_reg(pcie, lower_32_bits(cpu_addr), PCIELAR(idx)); in rcar_pcie_inbound_ranges()
1064 rcar_pci_write_reg(pcie, lower_32_bits(mask) | flags, in rcar_pcie_inbound_ranges()
1067 rcar_pci_write_reg(pcie, upper_32_bits(pci_addr), in rcar_pcie_inbound_ranges()
1069 rcar_pci_write_reg(pcie, upper_32_bits(cpu_addr), in rcar_pcie_inbound_ranges()
1071 rcar_pci_write_reg(pcie, 0, PCIELAMR(idx + 1)); in rcar_pcie_inbound_ranges()
1078 dev_err(pcie->dev, "Failed to map inbound regions!\n"); in rcar_pcie_inbound_ranges()
1087 static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie, in rcar_pcie_parse_map_dma_ranges() argument
1102 dev_dbg(pcie->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n", in rcar_pcie_parse_map_dma_ranges()
1105 err = rcar_pcie_inbound_ranges(pcie, &range, &index); in rcar_pcie_parse_map_dma_ranges()
1132 struct rcar_pcie *pcie; in rcar_pcie_probe() local
1138 bridge = pci_alloc_host_bridge(sizeof(*pcie)); in rcar_pcie_probe()
1142 pcie = pci_host_bridge_priv(bridge); in rcar_pcie_probe()
1144 pcie->dev = dev; in rcar_pcie_probe()
1145 platform_set_drvdata(pdev, pcie); in rcar_pcie_probe()
1147 err = pci_parse_request_of_pci_ranges(dev, &pcie->resources, NULL); in rcar_pcie_probe()
1151 pm_runtime_enable(pcie->dev); in rcar_pcie_probe()
1152 err = pm_runtime_get_sync(pcie->dev); in rcar_pcie_probe()
1154 dev_err(pcie->dev, "pm_runtime_get_sync failed\n"); in rcar_pcie_probe()
1158 err = rcar_pcie_get_resources(pcie); in rcar_pcie_probe()
1164 err = clk_prepare_enable(pcie->bus_clk); in rcar_pcie_probe()
1170 err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node); in rcar_pcie_probe()
1175 err = phy_init_fn(pcie); in rcar_pcie_probe()
1182 if (rcar_pcie_hw_init(pcie)) { in rcar_pcie_probe()
1188 data = rcar_pci_read_reg(pcie, MACSR); in rcar_pcie_probe()
1192 err = rcar_pcie_enable_msi(pcie); in rcar_pcie_probe()
1201 err = rcar_pcie_enable(pcie); in rcar_pcie_probe()
1209 rcar_pcie_teardown_msi(pcie); in rcar_pcie_probe()
1212 if (pcie->phy) { in rcar_pcie_probe()
1213 phy_power_off(pcie->phy); in rcar_pcie_probe()
1214 phy_exit(pcie->phy); in rcar_pcie_probe()
1218 clk_disable_unprepare(pcie->bus_clk); in rcar_pcie_probe()
1221 irq_dispose_mapping(pcie->msi.irq2); in rcar_pcie_probe()
1222 irq_dispose_mapping(pcie->msi.irq1); in rcar_pcie_probe()
1229 pci_free_resource_list(&pcie->resources); in rcar_pcie_probe()
1239 struct rcar_pcie *pcie = dev_get_drvdata(dev); in rcar_pcie_resume_noirq() local
1241 if (rcar_pci_read_reg(pcie, PMSR) && in rcar_pcie_resume_noirq()
1242 !(rcar_pci_read_reg(pcie, PCIETCTLR) & DL_DOWN)) in rcar_pcie_resume_noirq()
1246 rcar_pci_write_reg(pcie, MACCTLR_INIT_VAL, MACCTLR); in rcar_pcie_resume_noirq()
1247 rcar_pci_write_reg(pcie, CFINIT, PCIETCTLR); in rcar_pcie_resume_noirq()
1248 return rcar_pcie_wait_for_dl(pcie); in rcar_pcie_resume_noirq()