Lines Matching +full:ssc +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (C) 2009 - 2019 Broadcom */
26 #include <linux/pci-ecam.h>
37 /* BRCM_PCIE_CAP_REGS - Offset for the mandatory capability config regs */
165 #define BRCM_INT_PCI_MSI_MASK GENMASK(BRCM_INT_PCI_MSI_NR - 1, 0)
167 32 - BRCM_INT_PCI_MSI_LEGACY_NR)
194 #define IDX_ADDR(pcie) ((pcie)->reg_offsets[EXT_CFG_INDEX])
195 #define DATA_ADDR(pcie) ((pcie)->reg_offsets[EXT_CFG_DATA])
196 #define PCIE_RGR1_SW_INIT_1(pcie) ((pcie)->reg_offsets[RGR1_SW_INIT_1])
197 #define HARD_DEBUG(pcie) ((pcie)->reg_offsets[PCIE_HARD_DEBUG])
198 #define INTR2_CPU_BASE(pcie) ((pcie)->reg_offsets[PCIE_INTR2_CPU_BASE])
275 bool ssc; member
298 return pcie->soc_base == BCM7435 || pcie->soc_base == BCM7425; in is_bmips()
303 * non-linear values of PCIE_X_MISC_RC_BAR[123]_CONFIG_LO.SIZE
311 return (log2_in - 12) + 0x1c; in brcm_pcie_encode_ibar_size()
314 return log2_in - 15; in brcm_pcie_encode_ibar_size()
364 * Configures device for Spread Spectrum Clocking (SSC) mode; a negative
369 int pll, ssc; in brcm_pcie_set_ssc() local
373 ret = brcm_pcie_mdio_write(pcie->base, MDIO_PORT0, SET_ADDR_OFFSET, in brcm_pcie_set_ssc()
378 ret = brcm_pcie_mdio_read(pcie->base, MDIO_PORT0, in brcm_pcie_set_ssc()
385 ret = brcm_pcie_mdio_write(pcie->base, MDIO_PORT0, in brcm_pcie_set_ssc()
391 ret = brcm_pcie_mdio_read(pcie->base, MDIO_PORT0, in brcm_pcie_set_ssc()
396 ssc = FIELD_GET(SSC_STATUS_SSC_MASK, tmp); in brcm_pcie_set_ssc()
399 return ssc && pll ? 0 : -EIO; in brcm_pcie_set_ssc()
405 u16 lnkctl2 = readw(pcie->base + BRCM_PCIE_CAP_REGS + PCI_EXP_LNKCTL2); in brcm_pcie_set_gen()
406 u32 lnkcap = readl(pcie->base + BRCM_PCIE_CAP_REGS + PCI_EXP_LNKCAP); in brcm_pcie_set_gen()
409 writel(lnkcap, pcie->base + BRCM_PCIE_CAP_REGS + PCI_EXP_LNKCAP); in brcm_pcie_set_gen()
412 writew(lnkctl2, pcie->base + BRCM_PCIE_CAP_REGS + PCI_EXP_LNKCTL2); in brcm_pcie_set_gen()
425 writel(lower_32_bits(pcie_addr), pcie->base + PCIE_MEM_WIN0_LO(win)); in brcm_pcie_set_outbound_win()
426 writel(upper_32_bits(pcie_addr), pcie->base + PCIE_MEM_WIN0_HI(win)); in brcm_pcie_set_outbound_win()
430 limit_addr_mb = (cpu_addr + size - 1) / SZ_1M; in brcm_pcie_set_outbound_win()
432 tmp = readl(pcie->base + PCIE_MEM_WIN0_BASE_LIMIT(win)); in brcm_pcie_set_outbound_win()
437 writel(tmp, pcie->base + PCIE_MEM_WIN0_BASE_LIMIT(win)); in brcm_pcie_set_outbound_win()
447 tmp = readl(pcie->base + PCIE_MEM_WIN0_BASE_HI(win)); in brcm_pcie_set_outbound_win()
450 writel(tmp, pcie->base + PCIE_MEM_WIN0_BASE_HI(win)); in brcm_pcie_set_outbound_win()
453 tmp = readl(pcie->base + PCIE_MEM_WIN0_LIMIT_HI(win)); in brcm_pcie_set_outbound_win()
456 writel(tmp, pcie->base + PCIE_MEM_WIN0_LIMIT_HI(win)); in brcm_pcie_set_outbound_win()
482 dev = msi->dev; in brcm_pcie_msi_isr()
484 status = readl(msi->intr_base + MSI_INT_STATUS); in brcm_pcie_msi_isr()
485 status >>= msi->legacy_shift; in brcm_pcie_msi_isr()
487 for_each_set_bit(bit, &status, msi->nr) { in brcm_pcie_msi_isr()
489 ret = generic_handle_domain_irq(msi->inner_domain, bit); in brcm_pcie_msi_isr()
501 msg->address_lo = lower_32_bits(msi->target_addr); in brcm_msi_compose_msi_msg()
502 msg->address_hi = upper_32_bits(msi->target_addr); in brcm_msi_compose_msi_msg()
503 msg->data = (0xffff & PCIE_MISC_MSI_DATA_CONFIG_VAL_32) | data->hwirq; in brcm_msi_compose_msi_msg()
509 const int shift_amt = data->hwirq + msi->legacy_shift; in brcm_msi_ack_irq()
511 writel(1 << shift_amt, msi->intr_base + MSI_INT_CLR); in brcm_msi_ack_irq()
525 mutex_lock(&msi->lock); in brcm_msi_alloc()
526 hwirq = bitmap_find_free_region(msi->used, msi->nr, in brcm_msi_alloc()
528 mutex_unlock(&msi->lock); in brcm_msi_alloc()
536 mutex_lock(&msi->lock); in brcm_msi_free()
537 bitmap_release_region(msi->used, hwirq, order_base_2(nr_irqs)); in brcm_msi_free()
538 mutex_unlock(&msi->lock); in brcm_msi_free()
544 struct brcm_msi *msi = domain->host_data; in brcm_irq_domain_alloc()
554 &brcm_msi_bottom_irq_chip, domain->host_data, in brcm_irq_domain_alloc()
565 brcm_msi_free(msi, d->hwirq, nr_irqs); in brcm_irq_domain_free()
575 struct fwnode_handle *fwnode = of_node_to_fwnode(msi->np); in brcm_allocate_domains()
576 struct device *dev = msi->dev; in brcm_allocate_domains()
578 msi->inner_domain = irq_domain_add_linear(NULL, msi->nr, &msi_domain_ops, msi); in brcm_allocate_domains()
579 if (!msi->inner_domain) { in brcm_allocate_domains()
581 return -ENOMEM; in brcm_allocate_domains()
584 msi->msi_domain = pci_msi_create_irq_domain(fwnode, in brcm_allocate_domains()
586 msi->inner_domain); in brcm_allocate_domains()
587 if (!msi->msi_domain) { in brcm_allocate_domains()
589 irq_domain_remove(msi->inner_domain); in brcm_allocate_domains()
590 return -ENOMEM; in brcm_allocate_domains()
598 irq_domain_remove(msi->msi_domain); in brcm_free_domains()
599 irq_domain_remove(msi->inner_domain); in brcm_free_domains()
604 struct brcm_msi *msi = pcie->msi; in brcm_msi_remove()
608 irq_set_chained_handler_and_data(msi->irq, NULL, NULL); in brcm_msi_remove()
614 u32 val = msi->legacy ? BRCM_INT_PCI_MSI_LEGACY_MASK : in brcm_msi_set_regs()
617 writel(val, msi->intr_base + MSI_INT_MASK_CLR); in brcm_msi_set_regs()
618 writel(val, msi->intr_base + MSI_INT_CLR); in brcm_msi_set_regs()
624 writel(lower_32_bits(msi->target_addr) | 0x1, in brcm_msi_set_regs()
625 msi->base + PCIE_MISC_MSI_BAR_CONFIG_LO); in brcm_msi_set_regs()
626 writel(upper_32_bits(msi->target_addr), in brcm_msi_set_regs()
627 msi->base + PCIE_MISC_MSI_BAR_CONFIG_HI); in brcm_msi_set_regs()
629 val = msi->legacy ? PCIE_MISC_MSI_DATA_CONFIG_VAL_8 : PCIE_MISC_MSI_DATA_CONFIG_VAL_32; in brcm_msi_set_regs()
630 writel(val, msi->base + PCIE_MISC_MSI_DATA_CONFIG); in brcm_msi_set_regs()
637 struct device *dev = pcie->dev; in brcm_pcie_enable_msi()
639 irq = irq_of_parse_and_map(dev->of_node, 1); in brcm_pcie_enable_msi()
642 return -ENODEV; in brcm_pcie_enable_msi()
647 return -ENOMEM; in brcm_pcie_enable_msi()
649 mutex_init(&msi->lock); in brcm_pcie_enable_msi()
650 msi->dev = dev; in brcm_pcie_enable_msi()
651 msi->base = pcie->base; in brcm_pcie_enable_msi()
652 msi->np = pcie->np; in brcm_pcie_enable_msi()
653 msi->target_addr = pcie->msi_target_addr; in brcm_pcie_enable_msi()
654 msi->irq = irq; in brcm_pcie_enable_msi()
655 msi->legacy = pcie->hw_rev < BRCM_PCIE_HW_REV_33; in brcm_pcie_enable_msi()
663 if (msi->legacy) { in brcm_pcie_enable_msi()
664 msi->intr_base = msi->base + INTR2_CPU_BASE(pcie); in brcm_pcie_enable_msi()
665 msi->nr = BRCM_INT_PCI_MSI_LEGACY_NR; in brcm_pcie_enable_msi()
666 msi->legacy_shift = 24; in brcm_pcie_enable_msi()
668 msi->intr_base = msi->base + PCIE_MSI_INTR2_BASE; in brcm_pcie_enable_msi()
669 msi->nr = BRCM_INT_PCI_MSI_NR; in brcm_pcie_enable_msi()
670 msi->legacy_shift = 0; in brcm_pcie_enable_msi()
677 irq_set_chained_handler_and_data(msi->irq, brcm_pcie_msi_isr, msi); in brcm_pcie_enable_msi()
680 pcie->msi = msi; in brcm_pcie_enable_msi()
688 void __iomem *base = pcie->base; in brcm_pcie_rc_mode()
696 u32 val = readl(pcie->base + PCIE_MISC_PCIE_STATUS); in brcm_pcie_link_up()
706 struct brcm_pcie *pcie = bus->sysdata; in brcm_pcie_map_bus()
707 void __iomem *base = pcie->base; in brcm_pcie_map_bus()
714 /* An access to our HW w/o link-up will cause a CPU Abort */ in brcm_pcie_map_bus()
719 idx = PCIE_ECAM_OFFSET(bus->number, devfn, 0); in brcm_pcie_map_bus()
720 writel(idx, pcie->base + PCIE_EXT_CFG_INDEX); in brcm_pcie_map_bus()
727 struct brcm_pcie *pcie = bus->sysdata; in brcm7425_pcie_map_bus()
728 void __iomem *base = pcie->base; in brcm7425_pcie_map_bus()
735 /* An access to our HW w/o link-up will cause a CPU Abort */ in brcm7425_pcie_map_bus()
740 idx = PCIE_ECAM_OFFSET(bus->number, devfn, where); in brcm7425_pcie_map_bus()
751 if (pcie->bridge_reset) { in brcm_pcie_bridge_sw_init_set_generic()
753 ret = reset_control_assert(pcie->bridge_reset); in brcm_pcie_bridge_sw_init_set_generic()
755 ret = reset_control_deassert(pcie->bridge_reset); in brcm_pcie_bridge_sw_init_set_generic()
758 dev_err(pcie->dev, "failed to %s 'bridge' reset, err=%d\n", in brcm_pcie_bridge_sw_init_set_generic()
764 tmp = readl(pcie->base + PCIE_RGR1_SW_INIT_1(pcie)); in brcm_pcie_bridge_sw_init_set_generic()
766 writel(tmp, pcie->base + PCIE_RGR1_SW_INIT_1(pcie)); in brcm_pcie_bridge_sw_init_set_generic()
776 tmp = readl(pcie->base + PCIE_RGR1_SW_INIT_1(pcie)); in brcm_pcie_bridge_sw_init_set_7278()
778 writel(tmp, pcie->base + PCIE_RGR1_SW_INIT_1(pcie)); in brcm_pcie_bridge_sw_init_set_7278()
787 if (WARN_ONCE(!pcie->perst_reset, "missing PERST# reset controller\n")) in brcm_pcie_perst_set_4908()
788 return -EINVAL; in brcm_pcie_perst_set_4908()
791 ret = reset_control_assert(pcie->perst_reset); in brcm_pcie_perst_set_4908()
793 ret = reset_control_deassert(pcie->perst_reset); in brcm_pcie_perst_set_4908()
796 dev_err(pcie->dev, "failed to %s 'perst' reset, err=%d\n", in brcm_pcie_perst_set_4908()
806 tmp = readl(pcie->base + PCIE_MISC_PCIE_CTRL); in brcm_pcie_perst_set_7278()
808 writel(tmp, pcie->base + PCIE_MISC_PCIE_CTRL); in brcm_pcie_perst_set_7278()
817 tmp = readl(pcie->base + PCIE_RGR1_SW_INIT_1(pcie)); in brcm_pcie_perst_set_generic()
819 writel(tmp, pcie->base + PCIE_RGR1_SW_INIT_1(pcie)); in brcm_pcie_perst_set_generic()
827 b->size = size; in add_inbound_win()
828 b->cpu_addr = cpu_addr; in add_inbound_win()
829 b->pci_offset = pci_offset; in add_inbound_win()
839 struct device *dev = pcie->dev; in brcm_pcie_get_inbound_wins()
845 * The HW registers (and PCIe) use order-1 numbering for BARs. As such, in brcm_pcie_get_inbound_wins()
858 if (pcie->soc_base != BCM7712) in brcm_pcie_get_inbound_wins()
861 resource_list_for_each_entry(entry, &bridge->dma_ranges) { in brcm_pcie_get_inbound_wins()
862 u64 pcie_start = entry->res->start - entry->offset; in brcm_pcie_get_inbound_wins()
863 u64 cpu_start = entry->res->start; in brcm_pcie_get_inbound_wins()
865 size = resource_size(entry->res); in brcm_pcie_get_inbound_wins()
871 * offering a non-overlapping viewport to system memory. in brcm_pcie_get_inbound_wins()
875 if (pcie->soc_base == BCM7712) in brcm_pcie_get_inbound_wins()
878 if (n > pcie->num_inbound_wins) in brcm_pcie_get_inbound_wins()
883 dev_err(dev, "DT node has no dma-ranges\n"); in brcm_pcie_get_inbound_wins()
884 return -EINVAL; in brcm_pcie_get_inbound_wins()
892 if (pcie->soc_base == BCM7712) in brcm_pcie_get_inbound_wins()
895 ret = of_property_read_variable_u64_array(pcie->np, "brcm,scb-sizes", pcie->memc_size, 1, in brcm_pcie_get_inbound_wins()
899 pcie->num_memc = 1; in brcm_pcie_get_inbound_wins()
900 pcie->memc_size[0] = 1ULL << fls64(tot_size - 1); in brcm_pcie_get_inbound_wins()
902 pcie->num_memc = ret; in brcm_pcie_get_inbound_wins()
906 for (i = 0, size = 0; i < pcie->num_memc; i++) in brcm_pcie_get_inbound_wins()
907 size += pcie->memc_size[i]; in brcm_pcie_get_inbound_wins()
910 size = 1ULL << fls64(size - 1); in brcm_pcie_get_inbound_wins()
921 * whatever the device-tree provides. This is because of an HW issue on in brcm_pcie_get_inbound_wins()
923 * firmware has to dynamically edit dma-ranges due to a bug on the in brcm_pcie_get_inbound_wins()
925 * lower 3GB of memory. Given this, we decided to keep the dma-ranges in brcm_pcie_get_inbound_wins()
926 * in check, avoiding hard to debug device-tree related issues in the in brcm_pcie_get_inbound_wins()
932 * matters, the viewport must start on a pcie-address that is aligned in brcm_pcie_get_inbound_wins()
934 * represent system memory -- e.g. 3GB of memory requires a 4GB in brcm_pcie_get_inbound_wins()
935 * viewport -- we can map the outbound memory in or after 3GB and even in brcm_pcie_get_inbound_wins()
942 * - The best-case scenario, memory up to 3GB, is to place the inbound in brcm_pcie_get_inbound_wins()
943 * region in the first 4GB of pcie-space, as some legacy devices can in brcm_pcie_get_inbound_wins()
947 * - If the system memory is 4GB or larger we cannot start the inbound in brcm_pcie_get_inbound_wins()
952 if (!size || (pci_offset & (size - 1)) || in brcm_pcie_get_inbound_wins()
956 return -EINVAL; in brcm_pcie_get_inbound_wins()
974 return PCIE_MISC_RC_BAR1_CONFIG_LO + 8 * (bar - 1); in brcm_bar_reg_offset()
976 return PCIE_MISC_RC_BAR4_CONFIG_LO + 8 * (bar - 4); in brcm_bar_reg_offset()
982 return PCIE_MISC_UBUS_BAR1_CONFIG_REMAP + 8 * (bar - 1); in brcm_ubus_reg_offset()
984 return PCIE_MISC_UBUS_BAR4_CONFIG_REMAP + 8 * (bar - 4); in brcm_ubus_reg_offset()
991 void __iomem *base = pcie->base; in set_inbound_win_registers()
1015 if (pcie->soc_base == BCM7712) { in set_inbound_win_registers()
1030 void __iomem *base = pcie->base; in brcm_pcie_setup()
1039 ret = pcie->bridge_sw_init_set(pcie, 1); in brcm_pcie_setup()
1044 if (pcie->soc_base == BCM2711) { in brcm_pcie_setup()
1045 ret = pcie->perst_set(pcie, 1); in brcm_pcie_setup()
1047 pcie->bridge_sw_init_set(pcie, 0); in brcm_pcie_setup()
1055 ret = pcie->bridge_sw_init_set(pcie, 0); in brcm_pcie_setup()
1075 else if (pcie->soc_base == BCM2711) in brcm_pcie_setup()
1077 else if (pcie->soc_base == BCM7278) in brcm_pcie_setup()
1101 dev_err(pcie->dev, "PCIe RC controller misconfigured as Endpoint\n"); in brcm_pcie_setup()
1102 return -EINVAL; in brcm_pcie_setup()
1106 for (memc = 0; memc < pcie->num_memc; memc++) { in brcm_pcie_setup()
1107 u32 scb_size_val = ilog2(pcie->memc_size[memc]) - 15; in brcm_pcie_setup()
1123 * account the rounding-up we're forced to perform). in brcm_pcie_setup()
1127 pcie->msi_target_addr = BRCM_MSI_TARGET_ADDR_LT_4GB; in brcm_pcie_setup()
1129 pcie->msi_target_addr = BRCM_MSI_TARGET_ADDR_GT_4GB; in brcm_pcie_setup()
1132 /* Don't advertise L0s capability if 'aspm-no-l0s' */ in brcm_pcie_setup()
1134 if (!of_property_read_bool(pcie->np, "aspm-no-l0s")) in brcm_pcie_setup()
1143 * a PCIe-PCIe bridge (the default setting is to be EP mode). in brcm_pcie_setup()
1151 resource_list_for_each_entry(entry, &bridge->windows) { in brcm_pcie_setup()
1152 struct resource *res = entry->res; in brcm_pcie_setup()
1158 dev_err(pcie->dev, "too many outbound wins\n"); in brcm_pcie_setup()
1159 return -EINVAL; in brcm_pcie_setup()
1163 u64 start = res->start; in brcm_pcie_setup()
1171 start - entry->offset, in brcm_pcie_setup()
1175 brcm_pcie_set_outbound_win(pcie, num_out_wins, res->start, in brcm_pcie_setup()
1176 res->start - entry->offset, in brcm_pcie_setup()
1181 /* PCIe->SCB endian mode for inbound window */ in brcm_pcie_setup()
1198 const unsigned int REG_OFFSET = PCIE_RGR1_SW_INIT_1(pcie) - 8; in brcm_extend_rbus_timeout()
1202 if (pcie->soc_base == BCM7712) in brcm_extend_rbus_timeout()
1206 writel(216 * timeout_us, pcie->base + REG_OFFSET); in brcm_extend_rbus_timeout()
1211 static const char err_msg[] = "invalid 'brcm,clkreq-mode' DT string\n"; in brcm_config_clkreq()
1212 const char *mode = "default"; in brcm_config_clkreq() local
1216 ret = of_property_read_string(pcie->np, "brcm,clkreq-mode", &mode); in brcm_config_clkreq()
1217 if (ret && ret != -EINVAL) { in brcm_config_clkreq()
1218 dev_err(pcie->dev, err_msg); in brcm_config_clkreq()
1219 mode = "safe"; in brcm_config_clkreq()
1222 /* Start out assuming safe mode (both mode bits cleared) */ in brcm_config_clkreq()
1223 clkreq_cntl = readl(pcie->base + HARD_DEBUG(pcie)); in brcm_config_clkreq()
1226 if (strcmp(mode, "no-l1ss") == 0) { in brcm_config_clkreq()
1228 * "no-l1ss" -- Provides Clock Power Management, L0s, and in brcm_config_clkreq()
1236 * We want to un-advertise L1 substates because if the OS in brcm_config_clkreq()
1239 * "no-l1ss" mode. in brcm_config_clkreq()
1241 tmp = readl(pcie->base + PCIE_RC_CFG_PRIV1_ROOT_CAP); in brcm_config_clkreq()
1243 writel(tmp, pcie->base + PCIE_RC_CFG_PRIV1_ROOT_CAP); in brcm_config_clkreq()
1245 } else if (strcmp(mode, "default") == 0) { in brcm_config_clkreq()
1247 * "default" -- Provides L0s, L1, and L1SS, but not in brcm_config_clkreq()
1259 * "safe" -- No power savings; refclk is driven by RC in brcm_config_clkreq()
1262 if (strcmp(mode, "safe") != 0) in brcm_config_clkreq()
1263 dev_err(pcie->dev, err_msg); in brcm_config_clkreq()
1264 mode = "safe"; in brcm_config_clkreq()
1266 writel(clkreq_cntl, pcie->base + HARD_DEBUG(pcie)); in brcm_config_clkreq()
1268 dev_info(pcie->dev, "clkreq-mode set to %s\n", mode); in brcm_config_clkreq()
1273 struct device *dev = pcie->dev; in brcm_pcie_start_link()
1274 void __iomem *base = pcie->base; in brcm_pcie_start_link()
1280 ret = pcie->perst_set(pcie, 0); in brcm_pcie_start_link()
1292 * configure RC. Intermittently check status for link-up, up to a in brcm_pcie_start_link()
1300 return -ENODEV; in brcm_pcie_start_link()
1305 if (pcie->gen) in brcm_pcie_start_link()
1306 brcm_pcie_set_gen(pcie, pcie->gen); in brcm_pcie_start_link()
1308 if (pcie->ssc) { in brcm_pcie_start_link()
1313 dev_err(dev, "failed attempt to enter ssc mode\n"); in brcm_pcie_start_link()
1321 ssc_good ? "(SSC)" : "(!SSC)"); in brcm_pcie_start_link()
1341 sr->num_supplies = ARRAY_SIZE(supplies); in alloc_subdev_regulators()
1343 sr->supplies[i].supply = supplies[i]; in alloc_subdev_regulators()
1351 struct brcm_pcie *pcie = bus->sysdata; in brcm_pcie_add_bus()
1352 struct device *dev = &bus->dev; in brcm_pcie_add_bus()
1356 if (!bus->parent || !pci_is_root_bus(bus->parent)) in brcm_pcie_add_bus()
1359 if (dev->of_node) { in brcm_pcie_add_bus()
1366 pcie->sr = sr; in brcm_pcie_add_bus()
1368 ret = regulator_bulk_get(dev, sr->num_supplies, sr->supplies); in brcm_pcie_add_bus()
1374 ret = regulator_bulk_enable(sr->num_supplies, sr->supplies); in brcm_pcie_add_bus()
1377 regulator_bulk_free(sr->num_supplies, sr->supplies); in brcm_pcie_add_bus()
1378 pcie->sr = NULL; in brcm_pcie_add_bus()
1389 struct brcm_pcie *pcie = bus->sysdata; in brcm_pcie_remove_bus()
1390 struct subdev_regulators *sr = pcie->sr; in brcm_pcie_remove_bus()
1391 struct device *dev = &bus->dev; in brcm_pcie_remove_bus()
1396 if (regulator_bulk_disable(sr->num_supplies, sr->supplies)) in brcm_pcie_remove_bus()
1398 regulator_bulk_free(sr->num_supplies, sr->supplies); in brcm_pcie_remove_bus()
1399 pcie->sr = NULL; in brcm_pcie_remove_bus()
1402 /* L23 is a low-power PCIe link state */
1405 void __iomem *base = pcie->base; in brcm_pcie_enter_l23()
1425 dev_err(pcie->dev, "failed to enter low-power link state\n"); in brcm_pcie_enter_l23()
1438 const int beg = start ? 0 : PCIE_DVT_PMU_PCIE_PHY_CTRL_DAST_NFLDS - 1; in brcm_phy_cntl()
1439 const int end = start ? PCIE_DVT_PMU_PCIE_PHY_CTRL_DAST_NFLDS : -1; in brcm_phy_cntl()
1442 void __iomem *base = pcie->base; in brcm_phy_cntl()
1445 for (i = beg; i != end; start ? i++ : i--) { in brcm_phy_cntl()
1457 ret = (tmp & combined_mask) == val ? 0 : -EIO; in brcm_phy_cntl()
1459 dev_err(pcie->dev, "failed to %s phy\n", (start ? "start" : "stop")); in brcm_phy_cntl()
1466 return pcie->has_phy ? brcm_phy_cntl(pcie, 1) : 0; in brcm_phy_start()
1471 return pcie->has_phy ? brcm_phy_cntl(pcie, 0) : 0; in brcm_phy_stop()
1476 void __iomem *base = pcie->base; in brcm_pcie_turn_off()
1482 ret = pcie->perst_set(pcie, 1); in brcm_pcie_turn_off()
1497 ret = pcie->bridge_sw_init_set(pcie, 1); in brcm_pcie_turn_off()
1506 if (device_may_wakeup(&dev->dev)) { in pci_dev_may_wakeup()
1508 dev_info(&dev->dev, "Possible wake-up device; regulators will not be disabled\n"); in pci_dev_may_wakeup()
1531 ret = reset_control_rearm(pcie->rescal); in brcm_pcie_suspend_noirq()
1537 if (pcie->sr) { in brcm_pcie_suspend_noirq()
1540 * downstream device is enabled as a wake-up source, do not in brcm_pcie_suspend_noirq()
1543 pcie->ep_wakeup_capable = false; in brcm_pcie_suspend_noirq()
1544 pci_walk_bus(bridge->bus, pci_dev_may_wakeup, in brcm_pcie_suspend_noirq()
1545 &pcie->ep_wakeup_capable); in brcm_pcie_suspend_noirq()
1546 if (!pcie->ep_wakeup_capable) { in brcm_pcie_suspend_noirq()
1547 ret = regulator_bulk_disable(pcie->sr->num_supplies, in brcm_pcie_suspend_noirq()
1548 pcie->sr->supplies); in brcm_pcie_suspend_noirq()
1551 rret = reset_control_reset(pcie->rescal); in brcm_pcie_suspend_noirq()
1559 clk_disable_unprepare(pcie->clk); in brcm_pcie_suspend_noirq()
1571 base = pcie->base; in brcm_pcie_resume_noirq()
1572 ret = clk_prepare_enable(pcie->clk); in brcm_pcie_resume_noirq()
1576 ret = reset_control_reset(pcie->rescal); in brcm_pcie_resume_noirq()
1585 pcie->bridge_sw_init_set(pcie, 0); in brcm_pcie_resume_noirq()
1599 if (pcie->sr) { in brcm_pcie_resume_noirq()
1600 if (pcie->ep_wakeup_capable) { in brcm_pcie_resume_noirq()
1607 pcie->ep_wakeup_capable = false; in brcm_pcie_resume_noirq()
1609 ret = regulator_bulk_enable(pcie->sr->num_supplies, in brcm_pcie_resume_noirq()
1610 pcie->sr->supplies); in brcm_pcie_resume_noirq()
1622 if (pcie->msi) in brcm_pcie_resume_noirq()
1623 brcm_msi_set_regs(pcie->msi); in brcm_pcie_resume_noirq()
1628 if (pcie->sr) in brcm_pcie_resume_noirq()
1629 regulator_bulk_disable(pcie->sr->num_supplies, pcie->sr->supplies); in brcm_pcie_resume_noirq()
1631 rret = reset_control_rearm(pcie->rescal); in brcm_pcie_resume_noirq()
1633 dev_err(pcie->dev, "failed to rearm 'rescal' reset, err=%d\n", rret); in brcm_pcie_resume_noirq()
1635 clk_disable_unprepare(pcie->clk); in brcm_pcie_resume_noirq()
1644 dev_err(pcie->dev, "Could not stop phy\n"); in __brcm_pcie_remove()
1645 if (reset_control_rearm(pcie->rescal)) in __brcm_pcie_remove()
1646 dev_err(pcie->dev, "Could not rearm rescal reset\n"); in __brcm_pcie_remove()
1647 clk_disable_unprepare(pcie->clk); in __brcm_pcie_remove()
1655 pci_stop_root_bus(bridge->bus); in brcm_pcie_remove()
1656 pci_remove_root_bus(bridge->bus); in brcm_pcie_remove()
1757 { .compatible = "brcm,bcm2711-pcie", .data = &bcm2711_cfg },
1758 { .compatible = "brcm,bcm4908-pcie", .data = &bcm4908_cfg },
1759 { .compatible = "brcm,bcm7211-pcie", .data = &generic_cfg },
1760 { .compatible = "brcm,bcm7216-pcie", .data = &bcm7216_cfg },
1761 { .compatible = "brcm,bcm7278-pcie", .data = &bcm7278_cfg },
1762 { .compatible = "brcm,bcm7425-pcie", .data = &bcm7425_cfg },
1763 { .compatible = "brcm,bcm7435-pcie", .data = &bcm7435_cfg },
1764 { .compatible = "brcm,bcm7445-pcie", .data = &generic_cfg },
1765 { .compatible = "brcm,bcm7712-pcie", .data = &bcm7712_cfg },
1787 struct device_node *np = pdev->dev.of_node, *msi_np; in brcm_pcie_probe()
1793 bridge = devm_pci_alloc_host_bridge(&pdev->dev, sizeof(*pcie)); in brcm_pcie_probe()
1795 return -ENOMEM; in brcm_pcie_probe()
1797 data = of_device_get_match_data(&pdev->dev); in brcm_pcie_probe()
1800 return -EINVAL; in brcm_pcie_probe()
1804 pcie->dev = &pdev->dev; in brcm_pcie_probe()
1805 pcie->np = np; in brcm_pcie_probe()
1806 pcie->reg_offsets = data->offsets; in brcm_pcie_probe()
1807 pcie->soc_base = data->soc_base; in brcm_pcie_probe()
1808 pcie->perst_set = data->perst_set; in brcm_pcie_probe()
1809 pcie->bridge_sw_init_set = data->bridge_sw_init_set; in brcm_pcie_probe()
1810 pcie->has_phy = data->has_phy; in brcm_pcie_probe()
1811 pcie->num_inbound_wins = data->num_inbound_wins; in brcm_pcie_probe()
1813 pcie->base = devm_platform_ioremap_resource(pdev, 0); in brcm_pcie_probe()
1814 if (IS_ERR(pcie->base)) in brcm_pcie_probe()
1815 return PTR_ERR(pcie->base); in brcm_pcie_probe()
1817 pcie->clk = devm_clk_get_optional(&pdev->dev, "sw_pcie"); in brcm_pcie_probe()
1818 if (IS_ERR(pcie->clk)) in brcm_pcie_probe()
1819 return PTR_ERR(pcie->clk); in brcm_pcie_probe()
1822 pcie->gen = (ret < 0) ? 0 : ret; in brcm_pcie_probe()
1824 pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc"); in brcm_pcie_probe()
1826 pcie->rescal = devm_reset_control_get_optional_shared(&pdev->dev, "rescal"); in brcm_pcie_probe()
1827 if (IS_ERR(pcie->rescal)) in brcm_pcie_probe()
1828 return PTR_ERR(pcie->rescal); in brcm_pcie_probe()
1830 pcie->perst_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, "perst"); in brcm_pcie_probe()
1831 if (IS_ERR(pcie->perst_reset)) in brcm_pcie_probe()
1832 return PTR_ERR(pcie->perst_reset); in brcm_pcie_probe()
1834 pcie->bridge_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, "bridge"); in brcm_pcie_probe()
1835 if (IS_ERR(pcie->bridge_reset)) in brcm_pcie_probe()
1836 return PTR_ERR(pcie->bridge_reset); in brcm_pcie_probe()
1838 pcie->swinit_reset = devm_reset_control_get_optional_exclusive(&pdev->dev, "swinit"); in brcm_pcie_probe()
1839 if (IS_ERR(pcie->swinit_reset)) in brcm_pcie_probe()
1840 return PTR_ERR(pcie->swinit_reset); in brcm_pcie_probe()
1842 ret = clk_prepare_enable(pcie->clk); in brcm_pcie_probe()
1844 return dev_err_probe(&pdev->dev, ret, "could not enable clock\n"); in brcm_pcie_probe()
1846 pcie->bridge_sw_init_set(pcie, 0); in brcm_pcie_probe()
1848 if (pcie->swinit_reset) { in brcm_pcie_probe()
1849 ret = reset_control_assert(pcie->swinit_reset); in brcm_pcie_probe()
1851 clk_disable_unprepare(pcie->clk); in brcm_pcie_probe()
1852 return dev_err_probe(&pdev->dev, ret, in brcm_pcie_probe()
1859 ret = reset_control_deassert(pcie->swinit_reset); in brcm_pcie_probe()
1861 clk_disable_unprepare(pcie->clk); in brcm_pcie_probe()
1862 return dev_err_probe(&pdev->dev, ret, in brcm_pcie_probe()
1863 "could not de-assert reset 'swinit'\n"); in brcm_pcie_probe()
1867 ret = reset_control_reset(pcie->rescal); in brcm_pcie_probe()
1869 clk_disable_unprepare(pcie->clk); in brcm_pcie_probe()
1870 return dev_err_probe(&pdev->dev, ret, "failed to deassert 'rescal'\n"); in brcm_pcie_probe()
1875 reset_control_rearm(pcie->rescal); in brcm_pcie_probe()
1876 clk_disable_unprepare(pcie->clk); in brcm_pcie_probe()
1884 pcie->hw_rev = readl(pcie->base + PCIE_MISC_REVISION); in brcm_pcie_probe()
1885 if (pcie->soc_base == BCM4908 && pcie->hw_rev >= BRCM_PCIE_HW_REV_3_20) { in brcm_pcie_probe()
1886 dev_err(pcie->dev, "hardware revision with unsupported PERST# setup\n"); in brcm_pcie_probe()
1887 ret = -ENODEV; in brcm_pcie_probe()
1891 msi_np = of_parse_phandle(pcie->np, "msi-parent", 0); in brcm_pcie_probe()
1892 if (pci_msi_enabled() && msi_np == pcie->np) { in brcm_pcie_probe()
1895 dev_err(pcie->dev, "probe of internal MSI failed"); in brcm_pcie_probe()
1900 bridge->ops = pcie->soc_base == BCM7425 ? &brcm7425_pcie_ops : &brcm_pcie_ops; in brcm_pcie_probe()
1901 bridge->sysdata = pcie; in brcm_pcie_probe()
1907 ret = -ENODEV; in brcm_pcie_probe()
1933 .name = "brcm-pcie",