From f2fc7bcd85a5bed8741cdfdd81d3a9a2a992006b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:01:06 +0100 Subject: [PATCH] PCI: dwc: gs201: Advertise L1 PM Substates when CLKREQ# is wired MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DWC core hides the root port's L1 PM Substates capability unless the driver sets l1ss_support, so the Wi-Fi link on Pixel 7 only ever reaches ASPM L1 and the PHY never powers down while idle. Set l1ss_support from the generic supports-clkreq property. When it is set, program the root port's L1SS capability (L1.1/L1.2 for ASPM and PCI-PM, Common_Mode_Restore_Time 42 us, T_POWER_ON 200 us) and the controller's L1.2 entry timings (DBI 0xb44: T_POWER_OFF 2, T_L1_2 10, T_PCLKACK 3). The values are the ones Google's gs201 driver uses with the Broadcom Wi-Fi, in the Wi-Fi branch of exynos_pcie_rc_set_l1ss() in drivers/pci/controller/dwc/pcie-exynos-rc.c: kernel/google-modules/soc/gs, branch android-gs-pantah-6.1-android16, writes T_POWER_ON 200 us there; the older 5.10 driver (kernel/gs, android-gs-pantah-5.10-android15-qpr1) wrote 130 us, which in 6.1 is left only in the uncalled exynos_pcie_rc_set_tpoweron(). This follows the 6.1 driver. The PHY's L1.2 settings and the I/A sequencer that re-locks the CDR on L1.2 exit are already in place. The capability is reprogrammed at every link-up, so the "advertised" line is printed once and as a debug message after that (on resume). On devicetree platforms the PCI core does not enable L1 substates by default, so this only makes them available: they are switched on with the link/l1_2_aspm sysfs attribute or pcie_aspm.policy=powersupersave. Tested on a Pixel 7 (panther) with this driver and supports-clkreq on the Wi-Fi node of my tree (omamobile#195's &pcie_1): the root port reports "L1 PM Substates advertised (cap 0x00692a1f, L1SUB 0xea)", and with pcie_aspm.policy=powersupersave both ends show ASPM L1.1+/L1.2+ in L1SubCtl1. The Wi-Fi stays up (ping to the access point 2.3-3.8 ms). On the S2MPG13 power meter, screen off, 20 s windows alternating the policy: the PCIe PHY rails (LDO3S + LDO18S) go from 71 + 48 mW to 4 + 0 mW, and the Wi-Fi chip's VSYS rail from 281-286 to 221-224 mW. Those measurements were taken with T_POWER_ON 130 us. With this commit (200 us), after reloading the driver on the same phone, lspci -vv shows PortTPowerOnTime=200us on the root port (the Wi-Fi function advertises 50 us) and L1SubCtl2 T_PwrOn=200us on both ends, the driver prints "cap 0x00a12a1f, L1SUB 0xea", and 20 pings to the access point go through with no loss (2.5 ms average). That was a module reload, not a cold boot. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/pci/controller/dwc/pcie-gs201.c | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-gs201.c b/drivers/pci/controller/dwc/pcie-gs201.c index 6ba9f650c4..41f5134d32 100644 --- a/drivers/pci/controller/dwc/pcie-gs201.c +++ b/drivers/pci/controller/dwc/pcie-gs201.c @@ -97,6 +97,21 @@ /* DBI port logic registers used by Samsung's setup */ #define GS201_DBI_AUX_CLK_FREQ 0xb40 #define GS201_DBI_AUX_CLK_FREQ_26MHZ 26 +#define GS201_DBI_L1SUB_CONTROL 0xb44 +#define GS201_DBI_L1SUB_T_POWER_OFF GENMASK(1, 0) +#define GS201_DBI_L1SUB_T_L1_2 GENMASK(5, 2) +#define GS201_DBI_L1SUB_T_PCLKACK GENMASK(7, 6) + +/* + * L1 PM Substates timings of the root port, the values Google's driver uses + * with the Broadcom Wi-Fi on this controller (exynos_pcie_rc_set_l1ss()): + * T_POWER_ON 200 us, as in the 6.1 driver (the 5.10 one wrote 130 us), and + * an effective Common_Mode_Restore_Time of 42 us (Google ORs 0x20 into a + * Control 1 register whose reset value holds 0x0a). + */ +#define GS201_L1SS_T_POWER_ON_SCALE 1 /* 10 us units */ +#define GS201_L1SS_T_POWER_ON_VALUE 20 /* 200 us */ +#define GS201_L1SS_CM_RESTORE_US 42 /* SYSREG_HSI2 shareability control for this controller */ #define GS201_SYSREG_SHARABLE_MASK GENMASK(1, 0) @@ -214,6 +229,7 @@ struct gs201_pcie { bool coherent; bool phy_inited; bool phy_on; + bool l1ss_reported; int irq; struct irq_domain *intx_domain; raw_spinlock_t lock; @@ -389,6 +405,56 @@ static void gs201_pcie_setup_elbi(struct gs201_pcie *gp) GS201_ELBI_HISTORY_ENABLE); } +/* + * With CLKREQ# wired (supports-clkreq), let the root port advertise L1.1 and + * L1.2. The PHY side (ERIO clock gating and the L1.2 entry delay) and the + * I/A sequencer that re-locks the CDR on L1.2 exit are already set up; what + * is left is the root port's L1 PM Substates capability, which the PCI core + * reads to program both ends, and the controller's L1.2 entry timings. + * Called with DBI read-only writes enabled. + */ +static void gs201_pcie_setup_l1ss(struct gs201_pcie *gp) +{ + struct dw_pcie *pci = &gp->pci; + u16 l1ss; + u32 val; + + l1ss = dw_pcie_find_ext_capability(pci, PCI_EXT_CAP_ID_L1SS); + if (!l1ss) { + dev_warn(pci->dev, "no L1 PM Substates capability in DBI\n"); + pci->l1ss_support = false; + return; + } + + val = dw_pcie_readl_dbi(pci, l1ss + PCI_L1SS_CAP); + val &= ~(PCI_L1SS_CAP_CM_RESTORE_TIME | PCI_L1SS_CAP_P_PWR_ON_SCALE | + PCI_L1SS_CAP_P_PWR_ON_VALUE); + val |= FIELD_PREP(PCI_L1SS_CAP_CM_RESTORE_TIME, GS201_L1SS_CM_RESTORE_US) | + FIELD_PREP(PCI_L1SS_CAP_P_PWR_ON_SCALE, GS201_L1SS_T_POWER_ON_SCALE) | + FIELD_PREP(PCI_L1SS_CAP_P_PWR_ON_VALUE, GS201_L1SS_T_POWER_ON_VALUE); + val |= PCI_L1SS_CAP_PCIPM_L1_1 | PCI_L1SS_CAP_PCIPM_L1_2 | + PCI_L1SS_CAP_ASPM_L1_1 | PCI_L1SS_CAP_ASPM_L1_2 | + PCI_L1SS_CAP_L1_PM_SS; + dw_pcie_writel_dbi(pci, l1ss + PCI_L1SS_CAP, val); + + /* Google's L1.2 entry timings, written once at link setup */ + dw_pcie_writel_dbi(pci, GS201_DBI_L1SUB_CONTROL, + FIELD_PREP(GS201_DBI_L1SUB_T_POWER_OFF, 2) | + FIELD_PREP(GS201_DBI_L1SUB_T_L1_2, 10) | + FIELD_PREP(GS201_DBI_L1SUB_T_PCLKACK, 3)); + + if (gp->l1ss_reported) { + dev_dbg(pci->dev, "L1 PM Substates advertised (cap %#010x, L1SUB %#x)\n", + dw_pcie_readl_dbi(pci, l1ss + PCI_L1SS_CAP), + dw_pcie_readl_dbi(pci, GS201_DBI_L1SUB_CONTROL)); + return; + } + gp->l1ss_reported = true; + dev_info(pci->dev, "L1 PM Substates advertised (cap %#010x, L1SUB %#x)\n", + dw_pcie_readl_dbi(pci, l1ss + PCI_L1SS_CAP), + dw_pcie_readl_dbi(pci, GS201_DBI_L1SUB_CONTROL)); +} + static void gs201_pcie_setup_dbi(struct gs201_pcie *gp) { struct dw_pcie *pci = &gp->pci; @@ -432,6 +498,9 @@ static void gs201_pcie_setup_dbi(struct gs201_pcie *gp) dev_warn(pci->dev, "no PCIe capability in DBI\n"); } + if (pci->l1ss_support) + gs201_pcie_setup_l1ss(gp); + dw_pcie_dbi_ro_wr_dis(pci); } @@ -1280,6 +1349,9 @@ static int gs201_pcie_probe(struct platform_device *pdev) if (of_property_read_u32(np, "num-lanes", &pci->num_lanes)) pci->num_lanes = 1; + /* L1 PM Substates need CLKREQ# between the root port and the device */ + pci->l1ss_support = of_property_read_bool(np, "supports-clkreq"); + platform_set_drvdata(pdev, gp); if (stop_after < GS201_STAGE_LINK)