Lines Matching +full:vpcie +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0+
7 * Author: Shawn Lin <shawn.lin@rock-chips.com>
8 * Wenrui Li <wenrui.li@rock-chips.com>
37 #include "pcie-rockchip.h"
76 if (pci_is_root_bus(bus) || pci_is_root_bus(bus->parent)) in rockchip_pcie_valid_device()
87 if (rockchip->legacy_phy) in rockchip_pcie_lane_map()
88 return GENMASK(MAX_LANE_NUM - 1, 0); in rockchip_pcie_lane_map()
93 /* The link may be using a reverse-indexed mapping. */ in rockchip_pcie_lane_map()
105 addr = rockchip->apb_base + PCIE_RC_CONFIG_NORMAL_BASE + where; in rockchip_pcie_rd_own_conf()
132 addr = rockchip->apb_base + PCIE_RC_CONFIG_NORMAL_BASE + offset; in rockchip_pcie_wr_own_conf()
139 mask = ~(((1 << (size * 8)) - 1) << ((where & 0x3) * 8)); in rockchip_pcie_wr_own_conf()
159 addr = rockchip->reg_base + PCIE_ECAM_OFFSET(bus->number, devfn, where); in rockchip_pcie_rd_other_conf()
166 if (pci_is_root_bus(bus->parent)) in rockchip_pcie_rd_other_conf()
192 addr = rockchip->reg_base + PCIE_ECAM_OFFSET(bus->number, devfn, where); in rockchip_pcie_wr_other_conf()
197 if (pci_is_root_bus(bus->parent)) in rockchip_pcie_wr_other_conf()
219 struct rockchip_pcie *rockchip = bus->sysdata; in rockchip_pcie_rd_conf()
234 struct rockchip_pcie *rockchip = bus->sysdata; in rockchip_pcie_wr_conf()
256 if (IS_ERR(rockchip->vpcie3v3)) in rockchip_pcie_set_power_limit()
263 * to the actual power supply. in rockchip_pcie_set_power_limit()
265 curr = regulator_get_current_limit(rockchip->vpcie3v3); in rockchip_pcie_set_power_limit()
274 dev_warn(rockchip->dev, "invalid power supply\n"); in rockchip_pcie_set_power_limit()
277 scale--; in rockchip_pcie_set_power_limit()
288 * rockchip_pcie_host_init_port - Initialize hardware
293 struct device *dev = rockchip->dev; in rockchip_pcie_host_init_port()
297 gpiod_set_value_cansleep(rockchip->ep_gpio, 0); in rockchip_pcie_host_init_port()
326 gpiod_set_value_cansleep(rockchip->ep_gpio, 1); in rockchip_pcie_host_init_port()
331 err = readl_poll_timeout(rockchip->apb_base + PCIE_CLIENT_BASIC_STATUS1, in rockchip_pcie_host_init_port()
339 if (rockchip->link_gen == 2) { in rockchip_pcie_host_init_port()
348 err = readl_poll_timeout(rockchip->apb_base + PCIE_CORE_CTRL, in rockchip_pcie_host_init_port()
362 rockchip->lanes_map = rockchip_pcie_lane_map(rockchip); in rockchip_pcie_host_init_port()
364 if (!(rockchip->lanes_map & BIT(i))) { in rockchip_pcie_host_init_port()
366 phy_power_off(rockchip->phys[i]); in rockchip_pcie_host_init_port()
382 if (of_property_read_bool(dev->of_node, "aspm-no-l0s")) { in rockchip_pcie_host_init_port()
395 while (i--) in rockchip_pcie_host_init_port()
396 phy_power_off(rockchip->phys[i]); in rockchip_pcie_host_init_port()
398 while (i--) in rockchip_pcie_host_init_port()
399 phy_exit(rockchip->phys[i]); in rockchip_pcie_host_init_port()
406 struct device *dev = rockchip->dev; in rockchip_pcie_subsys_irq_handler()
472 struct device *dev = rockchip->dev; in rockchip_pcie_client_irq_handler()
515 struct device *dev = rockchip->dev; in rockchip_pcie_intx_handler()
526 hwirq = ffs(reg) - 1; in rockchip_pcie_intx_handler()
529 ret = generic_handle_domain_irq(rockchip->irq_domain, hwirq); in rockchip_pcie_intx_handler()
540 struct device *dev = rockchip->dev; in rockchip_pcie_setup_irq()
548 IRQF_SHARED, "pcie-sys", rockchip); in rockchip_pcie_setup_irq()
567 IRQF_SHARED, "pcie-client", rockchip); in rockchip_pcie_setup_irq()
577 * rockchip_pcie_parse_host_dt - Parse Device Tree
584 struct device *dev = rockchip->dev; in rockchip_pcie_parse_host_dt()
591 rockchip->vpcie12v = devm_regulator_get_optional(dev, "vpcie12v"); in rockchip_pcie_parse_host_dt()
592 if (IS_ERR(rockchip->vpcie12v)) { in rockchip_pcie_parse_host_dt()
593 if (PTR_ERR(rockchip->vpcie12v) != -ENODEV) in rockchip_pcie_parse_host_dt()
594 return PTR_ERR(rockchip->vpcie12v); in rockchip_pcie_parse_host_dt()
598 rockchip->vpcie3v3 = devm_regulator_get_optional(dev, "vpcie3v3"); in rockchip_pcie_parse_host_dt()
599 if (IS_ERR(rockchip->vpcie3v3)) { in rockchip_pcie_parse_host_dt()
600 if (PTR_ERR(rockchip->vpcie3v3) != -ENODEV) in rockchip_pcie_parse_host_dt()
601 return PTR_ERR(rockchip->vpcie3v3); in rockchip_pcie_parse_host_dt()
605 rockchip->vpcie1v8 = devm_regulator_get(dev, "vpcie1v8"); in rockchip_pcie_parse_host_dt()
606 if (IS_ERR(rockchip->vpcie1v8)) in rockchip_pcie_parse_host_dt()
607 return PTR_ERR(rockchip->vpcie1v8); in rockchip_pcie_parse_host_dt()
609 rockchip->vpcie0v9 = devm_regulator_get(dev, "vpcie0v9"); in rockchip_pcie_parse_host_dt()
610 if (IS_ERR(rockchip->vpcie0v9)) in rockchip_pcie_parse_host_dt()
611 return PTR_ERR(rockchip->vpcie0v9); in rockchip_pcie_parse_host_dt()
618 struct device *dev = rockchip->dev; in rockchip_pcie_set_vpcie()
621 if (!IS_ERR(rockchip->vpcie12v)) { in rockchip_pcie_set_vpcie()
622 err = regulator_enable(rockchip->vpcie12v); in rockchip_pcie_set_vpcie()
629 if (!IS_ERR(rockchip->vpcie3v3)) { in rockchip_pcie_set_vpcie()
630 err = regulator_enable(rockchip->vpcie3v3); in rockchip_pcie_set_vpcie()
637 err = regulator_enable(rockchip->vpcie1v8); in rockchip_pcie_set_vpcie()
643 err = regulator_enable(rockchip->vpcie0v9); in rockchip_pcie_set_vpcie()
652 regulator_disable(rockchip->vpcie1v8); in rockchip_pcie_set_vpcie()
654 if (!IS_ERR(rockchip->vpcie3v3)) in rockchip_pcie_set_vpcie()
655 regulator_disable(rockchip->vpcie3v3); in rockchip_pcie_set_vpcie()
657 if (!IS_ERR(rockchip->vpcie12v)) in rockchip_pcie_set_vpcie()
658 regulator_disable(rockchip->vpcie12v); in rockchip_pcie_set_vpcie()
677 irq_set_chip_data(irq, domain->host_data); in rockchip_pcie_intx_map()
688 struct device *dev = rockchip->dev; in rockchip_pcie_init_irq_domain()
689 struct device_node *intc = of_get_next_child(dev->of_node, NULL); in rockchip_pcie_init_irq_domain()
692 dev_err(dev, "missing child interrupt-controller node\n"); in rockchip_pcie_init_irq_domain()
693 return -EINVAL; in rockchip_pcie_init_irq_domain()
696 rockchip->irq_domain = irq_domain_add_linear(intc, PCI_NUM_INTX, in rockchip_pcie_init_irq_domain()
699 if (!rockchip->irq_domain) { in rockchip_pcie_init_irq_domain()
701 return -EINVAL; in rockchip_pcie_init_irq_domain()
717 return -EINVAL; in rockchip_pcie_prog_ob_atu()
719 return -EINVAL; in rockchip_pcie_prog_ob_atu()
721 return -EINVAL; in rockchip_pcie_prog_ob_atu()
724 return -EINVAL; in rockchip_pcie_prog_ob_atu()
728 return -EINVAL; in rockchip_pcie_prog_ob_atu()
759 return -EINVAL; in rockchip_pcie_prog_ib_atu()
761 return -EINVAL; in rockchip_pcie_prog_ib_atu()
763 return -EINVAL; in rockchip_pcie_prog_ib_atu()
779 struct device *dev = rockchip->dev; in rockchip_pcie_cfg_atu()
789 entry = resource_list_first_type(&bridge->windows, IORESOURCE_MEM); in rockchip_pcie_cfg_atu()
791 return -ENODEV; in rockchip_pcie_cfg_atu()
793 size = resource_size(entry->res); in rockchip_pcie_cfg_atu()
794 pci_addr = entry->res->start - entry->offset; in rockchip_pcie_cfg_atu()
795 rockchip->msg_bus_addr = pci_addr; in rockchip_pcie_cfg_atu()
800 20 - 1, in rockchip_pcie_cfg_atu()
809 err = rockchip_pcie_prog_ib_atu(rockchip, 2, 32 - 1, 0x0, 0); in rockchip_pcie_cfg_atu()
815 entry = resource_list_first_type(&bridge->windows, IORESOURCE_IO); in rockchip_pcie_cfg_atu()
817 return -ENODEV; in rockchip_pcie_cfg_atu()
822 size = resource_size(entry->res); in rockchip_pcie_cfg_atu()
823 pci_addr = entry->res->start - entry->offset; in rockchip_pcie_cfg_atu()
829 20 - 1, in rockchip_pcie_cfg_atu()
841 20 - 1, 0, 0); in rockchip_pcie_cfg_atu()
843 rockchip->msg_bus_addr += ((reg_no + offset) << 20); in rockchip_pcie_cfg_atu()
853 writel(0x0, rockchip->msg_region + PCIE_RC_SEND_PME_OFF); in rockchip_pcie_wait_l2()
856 err = readl_poll_timeout(rockchip->apb_base + PCIE_CLIENT_DEBUG_OUT_0, in rockchip_pcie_wait_l2()
860 dev_err(rockchip->dev, "PCIe link enter L2 timeout!\n"); in rockchip_pcie_wait_l2()
887 regulator_disable(rockchip->vpcie0v9); in rockchip_pcie_suspend_noirq()
897 err = regulator_enable(rockchip->vpcie0v9); in rockchip_pcie_resume_noirq()
926 regulator_disable(rockchip->vpcie0v9); in rockchip_pcie_resume_noirq()
933 struct device *dev = &pdev->dev; in rockchip_pcie_probe()
937 if (!dev->of_node) in rockchip_pcie_probe()
938 return -ENODEV; in rockchip_pcie_probe()
942 return -ENOMEM; in rockchip_pcie_probe()
947 rockchip->dev = dev; in rockchip_pcie_probe()
948 rockchip->is_rc = true; in rockchip_pcie_probe()
960 dev_err(dev, "failed to set vpcie regulator\n"); in rockchip_pcie_probe()
976 rockchip->msg_region = devm_ioremap(dev, rockchip->msg_bus_addr, SZ_1M); in rockchip_pcie_probe()
977 if (!rockchip->msg_region) { in rockchip_pcie_probe()
978 err = -ENOMEM; in rockchip_pcie_probe()
982 bridge->sysdata = rockchip; in rockchip_pcie_probe()
983 bridge->ops = &rockchip_pcie_ops; in rockchip_pcie_probe()
998 irq_domain_remove(rockchip->irq_domain); in rockchip_pcie_probe()
1002 if (!IS_ERR(rockchip->vpcie12v)) in rockchip_pcie_probe()
1003 regulator_disable(rockchip->vpcie12v); in rockchip_pcie_probe()
1004 if (!IS_ERR(rockchip->vpcie3v3)) in rockchip_pcie_probe()
1005 regulator_disable(rockchip->vpcie3v3); in rockchip_pcie_probe()
1006 regulator_disable(rockchip->vpcie1v8); in rockchip_pcie_probe()
1007 regulator_disable(rockchip->vpcie0v9); in rockchip_pcie_probe()
1015 struct device *dev = &pdev->dev; in rockchip_pcie_remove()
1019 pci_stop_root_bus(bridge->bus); in rockchip_pcie_remove()
1020 pci_remove_root_bus(bridge->bus); in rockchip_pcie_remove()
1021 irq_domain_remove(rockchip->irq_domain); in rockchip_pcie_remove()
1027 if (!IS_ERR(rockchip->vpcie12v)) in rockchip_pcie_remove()
1028 regulator_disable(rockchip->vpcie12v); in rockchip_pcie_remove()
1029 if (!IS_ERR(rockchip->vpcie3v3)) in rockchip_pcie_remove()
1030 regulator_disable(rockchip->vpcie3v3); in rockchip_pcie_remove()
1031 regulator_disable(rockchip->vpcie1v8); in rockchip_pcie_remove()
1032 regulator_disable(rockchip->vpcie0v9); in rockchip_pcie_remove()
1041 { .compatible = "rockchip,rk3399-pcie", },
1048 .name = "rockchip-pcie",