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()
325 gpiod_set_value_cansleep(rockchip->ep_gpio, 1); in rockchip_pcie_host_init_port()
328 err = readl_poll_timeout(rockchip->apb_base + PCIE_CLIENT_BASIC_STATUS1, in rockchip_pcie_host_init_port()
336 if (rockchip->link_gen == 2) { in rockchip_pcie_host_init_port()
345 err = readl_poll_timeout(rockchip->apb_base + PCIE_CORE_CTRL, in rockchip_pcie_host_init_port()
359 rockchip->lanes_map = rockchip_pcie_lane_map(rockchip); in rockchip_pcie_host_init_port()
361 if (!(rockchip->lanes_map & BIT(i))) { in rockchip_pcie_host_init_port()
363 phy_power_off(rockchip->phys[i]); in rockchip_pcie_host_init_port()
379 if (of_property_read_bool(dev->of_node, "aspm-no-l0s")) { in rockchip_pcie_host_init_port()
392 while (i--) in rockchip_pcie_host_init_port()
393 phy_power_off(rockchip->phys[i]); in rockchip_pcie_host_init_port()
395 while (i--) in rockchip_pcie_host_init_port()
396 phy_exit(rockchip->phys[i]); in rockchip_pcie_host_init_port()
403 struct device *dev = rockchip->dev; in rockchip_pcie_subsys_irq_handler()
469 struct device *dev = rockchip->dev; in rockchip_pcie_client_irq_handler()
512 struct device *dev = rockchip->dev; in rockchip_pcie_legacy_int_handler()
523 hwirq = ffs(reg) - 1; in rockchip_pcie_legacy_int_handler()
526 ret = generic_handle_domain_irq(rockchip->irq_domain, hwirq); in rockchip_pcie_legacy_int_handler()
537 struct device *dev = rockchip->dev; in rockchip_pcie_setup_irq()
545 IRQF_SHARED, "pcie-sys", rockchip); in rockchip_pcie_setup_irq()
564 IRQF_SHARED, "pcie-client", rockchip); in rockchip_pcie_setup_irq()
574 * rockchip_pcie_parse_host_dt - Parse Device Tree
581 struct device *dev = rockchip->dev; in rockchip_pcie_parse_host_dt()
588 rockchip->vpcie12v = devm_regulator_get_optional(dev, "vpcie12v"); in rockchip_pcie_parse_host_dt()
589 if (IS_ERR(rockchip->vpcie12v)) { in rockchip_pcie_parse_host_dt()
590 if (PTR_ERR(rockchip->vpcie12v) != -ENODEV) in rockchip_pcie_parse_host_dt()
591 return PTR_ERR(rockchip->vpcie12v); in rockchip_pcie_parse_host_dt()
595 rockchip->vpcie3v3 = devm_regulator_get_optional(dev, "vpcie3v3"); in rockchip_pcie_parse_host_dt()
596 if (IS_ERR(rockchip->vpcie3v3)) { in rockchip_pcie_parse_host_dt()
597 if (PTR_ERR(rockchip->vpcie3v3) != -ENODEV) in rockchip_pcie_parse_host_dt()
598 return PTR_ERR(rockchip->vpcie3v3); in rockchip_pcie_parse_host_dt()
602 rockchip->vpcie1v8 = devm_regulator_get(dev, "vpcie1v8"); in rockchip_pcie_parse_host_dt()
603 if (IS_ERR(rockchip->vpcie1v8)) in rockchip_pcie_parse_host_dt()
604 return PTR_ERR(rockchip->vpcie1v8); in rockchip_pcie_parse_host_dt()
606 rockchip->vpcie0v9 = devm_regulator_get(dev, "vpcie0v9"); in rockchip_pcie_parse_host_dt()
607 if (IS_ERR(rockchip->vpcie0v9)) in rockchip_pcie_parse_host_dt()
608 return PTR_ERR(rockchip->vpcie0v9); in rockchip_pcie_parse_host_dt()
615 struct device *dev = rockchip->dev; in rockchip_pcie_set_vpcie()
618 if (!IS_ERR(rockchip->vpcie12v)) { in rockchip_pcie_set_vpcie()
619 err = regulator_enable(rockchip->vpcie12v); in rockchip_pcie_set_vpcie()
626 if (!IS_ERR(rockchip->vpcie3v3)) { in rockchip_pcie_set_vpcie()
627 err = regulator_enable(rockchip->vpcie3v3); in rockchip_pcie_set_vpcie()
634 err = regulator_enable(rockchip->vpcie1v8); in rockchip_pcie_set_vpcie()
640 err = regulator_enable(rockchip->vpcie0v9); in rockchip_pcie_set_vpcie()
649 regulator_disable(rockchip->vpcie1v8); in rockchip_pcie_set_vpcie()
651 if (!IS_ERR(rockchip->vpcie3v3)) in rockchip_pcie_set_vpcie()
652 regulator_disable(rockchip->vpcie3v3); in rockchip_pcie_set_vpcie()
654 if (!IS_ERR(rockchip->vpcie12v)) in rockchip_pcie_set_vpcie()
655 regulator_disable(rockchip->vpcie12v); in rockchip_pcie_set_vpcie()
674 irq_set_chip_data(irq, domain->host_data); in rockchip_pcie_intx_map()
685 struct device *dev = rockchip->dev; in rockchip_pcie_init_irq_domain()
686 struct device_node *intc = of_get_next_child(dev->of_node, NULL); in rockchip_pcie_init_irq_domain()
689 dev_err(dev, "missing child interrupt-controller node\n"); in rockchip_pcie_init_irq_domain()
690 return -EINVAL; in rockchip_pcie_init_irq_domain()
693 rockchip->irq_domain = irq_domain_add_linear(intc, PCI_NUM_INTX, in rockchip_pcie_init_irq_domain()
696 if (!rockchip->irq_domain) { in rockchip_pcie_init_irq_domain()
698 return -EINVAL; in rockchip_pcie_init_irq_domain()
714 return -EINVAL; in rockchip_pcie_prog_ob_atu()
716 return -EINVAL; in rockchip_pcie_prog_ob_atu()
718 return -EINVAL; in rockchip_pcie_prog_ob_atu()
721 return -EINVAL; in rockchip_pcie_prog_ob_atu()
725 return -EINVAL; in rockchip_pcie_prog_ob_atu()
756 return -EINVAL; in rockchip_pcie_prog_ib_atu()
758 return -EINVAL; in rockchip_pcie_prog_ib_atu()
760 return -EINVAL; in rockchip_pcie_prog_ib_atu()
776 struct device *dev = rockchip->dev; in rockchip_pcie_cfg_atu()
786 entry = resource_list_first_type(&bridge->windows, IORESOURCE_MEM); in rockchip_pcie_cfg_atu()
788 return -ENODEV; in rockchip_pcie_cfg_atu()
790 size = resource_size(entry->res); in rockchip_pcie_cfg_atu()
791 pci_addr = entry->res->start - entry->offset; in rockchip_pcie_cfg_atu()
792 rockchip->msg_bus_addr = pci_addr; in rockchip_pcie_cfg_atu()
797 20 - 1, in rockchip_pcie_cfg_atu()
806 err = rockchip_pcie_prog_ib_atu(rockchip, 2, 32 - 1, 0x0, 0); in rockchip_pcie_cfg_atu()
812 entry = resource_list_first_type(&bridge->windows, IORESOURCE_IO); in rockchip_pcie_cfg_atu()
814 return -ENODEV; in rockchip_pcie_cfg_atu()
819 size = resource_size(entry->res); in rockchip_pcie_cfg_atu()
820 pci_addr = entry->res->start - entry->offset; in rockchip_pcie_cfg_atu()
826 20 - 1, in rockchip_pcie_cfg_atu()
838 20 - 1, 0, 0); in rockchip_pcie_cfg_atu()
840 rockchip->msg_bus_addr += ((reg_no + offset) << 20); in rockchip_pcie_cfg_atu()
850 writel(0x0, rockchip->msg_region + PCIE_RC_SEND_PME_OFF); in rockchip_pcie_wait_l2()
853 err = readl_poll_timeout(rockchip->apb_base + PCIE_CLIENT_DEBUG_OUT_0, in rockchip_pcie_wait_l2()
857 dev_err(rockchip->dev, "PCIe link enter L2 timeout!\n"); in rockchip_pcie_wait_l2()
884 regulator_disable(rockchip->vpcie0v9); in rockchip_pcie_suspend_noirq()
894 err = regulator_enable(rockchip->vpcie0v9); in rockchip_pcie_resume_noirq()
923 regulator_disable(rockchip->vpcie0v9); in rockchip_pcie_resume_noirq()
930 struct device *dev = &pdev->dev; in rockchip_pcie_probe()
934 if (!dev->of_node) in rockchip_pcie_probe()
935 return -ENODEV; in rockchip_pcie_probe()
939 return -ENOMEM; in rockchip_pcie_probe()
944 rockchip->dev = dev; in rockchip_pcie_probe()
945 rockchip->is_rc = true; in rockchip_pcie_probe()
957 dev_err(dev, "failed to set vpcie regulator\n"); in rockchip_pcie_probe()
973 rockchip->msg_region = devm_ioremap(dev, rockchip->msg_bus_addr, SZ_1M); in rockchip_pcie_probe()
974 if (!rockchip->msg_region) { in rockchip_pcie_probe()
975 err = -ENOMEM; in rockchip_pcie_probe()
979 bridge->sysdata = rockchip; in rockchip_pcie_probe()
980 bridge->ops = &rockchip_pcie_ops; in rockchip_pcie_probe()
995 irq_domain_remove(rockchip->irq_domain); in rockchip_pcie_probe()
999 if (!IS_ERR(rockchip->vpcie12v)) in rockchip_pcie_probe()
1000 regulator_disable(rockchip->vpcie12v); in rockchip_pcie_probe()
1001 if (!IS_ERR(rockchip->vpcie3v3)) in rockchip_pcie_probe()
1002 regulator_disable(rockchip->vpcie3v3); in rockchip_pcie_probe()
1003 regulator_disable(rockchip->vpcie1v8); in rockchip_pcie_probe()
1004 regulator_disable(rockchip->vpcie0v9); in rockchip_pcie_probe()
1012 struct device *dev = &pdev->dev; in rockchip_pcie_remove()
1016 pci_stop_root_bus(bridge->bus); in rockchip_pcie_remove()
1017 pci_remove_root_bus(bridge->bus); in rockchip_pcie_remove()
1018 irq_domain_remove(rockchip->irq_domain); in rockchip_pcie_remove()
1024 if (!IS_ERR(rockchip->vpcie12v)) in rockchip_pcie_remove()
1025 regulator_disable(rockchip->vpcie12v); in rockchip_pcie_remove()
1026 if (!IS_ERR(rockchip->vpcie3v3)) in rockchip_pcie_remove()
1027 regulator_disable(rockchip->vpcie3v3); in rockchip_pcie_remove()
1028 regulator_disable(rockchip->vpcie1v8); in rockchip_pcie_remove()
1029 regulator_disable(rockchip->vpcie0v9); in rockchip_pcie_remove()
1038 { .compatible = "rockchip,rk3399-pcie", },
1045 .name = "rockchip-pcie",