Skip to content

Commit 69b8d3c

Browse files
wensbjorn-helgaas
authored andcommitted
PCI: mediatek-gen3: Split out device power helpers
In preparation for adding full power on/off control with the pwrctrl API, split out the existing code that only partially deals with device power sequencing into separate helper functions. The existing code only handles PERST#. This is purely moving code around, and brings no functional changes. Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> [mani: moved the 'err' variable to next commit] Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> Reviewed-by: Manivannan Sadhasivam <mani@kernel.org> Link: https://patch.msgid.link/20260324052002.4072430-6-wenst@chromium.org
1 parent 8670544 commit 69b8d3c

1 file changed

Lines changed: 51 additions & 35 deletions

File tree

drivers/pci/controller/pcie-mediatek-gen3.c

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,53 @@ static void mtk_pcie_enable_msi(struct mtk_gen3_pcie *pcie)
403403
writel_relaxed(val, pcie->base + PCIE_INT_ENABLE_REG);
404404
}
405405

406+
static int mtk_pcie_devices_power_up(struct mtk_gen3_pcie *pcie)
407+
{
408+
u32 val;
409+
410+
/*
411+
* Airoha EN7581 has a hw bug asserting/releasing PCIE_PE_RSTB signal
412+
* causing occasional PCIe link down. In order to overcome the issue,
413+
* PCIE_RSTB signals are not asserted/released at this stage and the
414+
* PCIe block is reset using en7523_reset_assert() and
415+
* en7581_pci_enable().
416+
*/
417+
if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) {
418+
/* Assert all reset signals */
419+
val = readl_relaxed(pcie->base + PCIE_RST_CTRL_REG);
420+
val |= PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
421+
PCIE_PE_RSTB;
422+
writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
423+
424+
/*
425+
* Described in PCIe CEM specification revision 6.0.
426+
*
427+
* The deassertion of PERST# should be delayed 100ms (TPVPERL)
428+
* for the power and clock to become stable.
429+
*/
430+
msleep(PCIE_T_PVPERL_MS);
431+
432+
/* De-assert reset signals */
433+
val &= ~(PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
434+
PCIE_PE_RSTB);
435+
writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
436+
}
437+
438+
return 0;
439+
}
440+
441+
static void mtk_pcie_devices_power_down(struct mtk_gen3_pcie *pcie)
442+
{
443+
u32 val;
444+
445+
if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) {
446+
/* Assert the PERST# pin */
447+
val = readl_relaxed(pcie->base + PCIE_RST_CTRL_REG);
448+
val |= PCIE_PE_RSTB;
449+
writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
450+
}
451+
}
452+
406453
static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
407454
{
408455
struct resource_entry *entry;
@@ -489,33 +536,9 @@ static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
489536
return err;
490537
}
491538

492-
/*
493-
* Airoha EN7581 has a hw bug asserting/releasing PCIE_PE_RSTB signal
494-
* causing occasional PCIe link down. In order to overcome the issue,
495-
* PCIE_RSTB signals are not asserted/released at this stage and the
496-
* PCIe block is reset using en7523_reset_assert() and
497-
* en7581_pci_enable().
498-
*/
499-
if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) {
500-
/* Assert all reset signals */
501-
val = readl_relaxed(pcie->base + PCIE_RST_CTRL_REG);
502-
val |= PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
503-
PCIE_PE_RSTB;
504-
writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
505-
506-
/*
507-
* Described in PCIe CEM specification revision 6.0.
508-
*
509-
* The deassertion of PERST# should be delayed 100ms (TPVPERL)
510-
* for the power and clock to become stable.
511-
*/
512-
msleep(PCIE_T_PVPERL_MS);
513-
514-
/* De-assert reset signals */
515-
val &= ~(PCIE_MAC_RSTB | PCIE_PHY_RSTB | PCIE_BRG_RSTB |
516-
PCIE_PE_RSTB);
517-
writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
518-
}
539+
err = mtk_pcie_devices_power_up(pcie);
540+
if (err)
541+
return err;
519542

520543
/* Check if the link is up or not */
521544
err = readl_poll_timeout(pcie->base + PCIE_LINK_STATUS_REG, val,
@@ -1270,7 +1293,6 @@ static int mtk_pcie_suspend_noirq(struct device *dev)
12701293
{
12711294
struct mtk_gen3_pcie *pcie = dev_get_drvdata(dev);
12721295
int err;
1273-
u32 val;
12741296

12751297
/* Trigger link to L2 state */
12761298
err = mtk_pcie_turn_off_link(pcie);
@@ -1279,13 +1301,7 @@ static int mtk_pcie_suspend_noirq(struct device *dev)
12791301
return err;
12801302
}
12811303

1282-
if (!(pcie->soc->flags & SKIP_PCIE_RSTB)) {
1283-
/* Assert the PERST# pin */
1284-
val = readl_relaxed(pcie->base + PCIE_RST_CTRL_REG);
1285-
val |= PCIE_PE_RSTB;
1286-
writel_relaxed(val, pcie->base + PCIE_RST_CTRL_REG);
1287-
}
1288-
1304+
mtk_pcie_devices_power_down(pcie);
12891305
dev_dbg(pcie->dev, "entered L2 states successfully");
12901306

12911307
mtk_pcie_irq_save(pcie);

0 commit comments

Comments
 (0)