From: Niklas Cassel <cassel@kernel.org>
To: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Damien Le Moal" <dlemoal@kernel.org>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Marek Vasut" <marek.vasut+renesas@mailbox.org>,
"Koichiro Den" <den@valinux.co.jp>
Subject: Re: [RFC PATCH v2 0/3] PCI: Describe the reference clock architecture of a Link
Date: Tue, 1 Dec 2026 00:38:53 +0100 [thread overview]
Message-ID: <aw4JDZkEBKzetyer@ryzen> (raw)
In-Reply-To: <20261130225254.204664-5-cassel@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 1333 bytes --]
On Mon, Nov 30, 2026 at 11:52:55PM +0100, Niklas Cassel wrote:
> i.e. Common Refclk, Separate Refclk with No SSC, and Separate Refclk
> with Independent SSC. It can replace vendor specific properties like
> "nvidia,enable-ext-refclk", "nvidia,enable-srns" and
> "rockchip,rx-common-refclk-mode", and drivers keep their default when it
> is absent. It also helps discoverability: an endpoint which does not use
> the REFCLK of the slot can report Slot Clock Configuration = 0, so that
> the host does not enable Common Clock Configuration.
Since Krzysztof asked for a user of this property on the RFC v1:
https://lore.kernel.org/linux-pci/51fa853a-61d6-4c8f-8636-80cce90d0a94@kernel.org/
Attaching a patch (compile tested only) that clears the Slot Clock
Configuration bit in the Link Status register for the DWC driver
(if the Link uses separate REFCLKs - i.e. SRNS or SRIS).
This is what the Tegra194 driver already does for its vendor specific
"nvidia,enable-srns" property, but this really ought to be done in
common DWC code and not in the glue drivers themselves (using the new
generic property).
I should probably have included this as a 4/4 in this series, but as
mentioned in the cover-letter, a generic binding is also needed for
R-Car Gen4 and S32G, but I guess they would send follow-up series.
Kind regards,
Niklas
[-- Attachment #2: 0001-PCI-dwc-Clear-Slot-Clock-Configuration-for-separate-.patch --]
[-- Type: text/plain, Size: 6592 bytes --]
From 4c610c4ede52abf25f8f5c3d17314b9a552c0b03 Mon Sep 17 00:00:00 2001
From: Niklas Cassel <cassel@kernel.org>
Date: Tue, 1 Dec 2026 00:08:30 +0100
Subject: [PATCH] PCI: dwc: Clear Slot Clock Configuration for separate
reference clocks
The Slot Clock Configuration bit in the Link Status register indicates
that a component uses the same physical reference clock (REFCLK) that
the platform provides on the connector. The bit is HwInit, and in the
DWC controller its value after reset is a synthesis parameter, so it can
be wrong for a given board, e.g. for an endpoint which uses a REFCLK of
its own instead of the REFCLK of the slot.
If both ends of a Link report Slot Clock Configuration, the PCI core
enables Common Clock Configuration (see
pcie_aspm_configure_common_clock()), even if the REFCLKs are separate.
Parse the generic refclk-mode property, from the controller node or
from the Root Port node, and clear Slot Clock Configuration if the Link
uses separate REFCLKs (SRNS or SRIS). For a multi-function endpoint,
clear it for all functions, since all functions have to report the same
value. Keep the value after reset if the property is absent or set to
"common". The read-modify-write masks the RW1C status bits of the Link
Status register, so that they are not cleared by accident.
This is what the Tegra194 driver already does for its vendor specific
"nvidia,enable-srns" property.
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
.../pci/controller/dwc/pcie-designware-ep.c | 11 +++++
drivers/pci/controller/dwc/pcie-designware.c | 48 +++++++++++++++++++
drivers/pci/controller/dwc/pcie-designware.h | 14 ++++++
3 files changed, 73 insertions(+)
diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
index e6060bb0bbbd..5dfa9ba26392 100644
--- a/drivers/pci/controller/dwc/pcie-designware-ep.c
+++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
@@ -1251,6 +1251,7 @@ static void dw_pcie_ep_init_non_sticky_registers(struct dw_pcie *pci)
u8 funcs = ep->epc->max_functions;
u32 func0_lnkcap, lnkcap;
u8 func_no, offset;
+ u16 lnksta;
dw_pcie_dbi_ro_wr_en(pci);
@@ -1281,6 +1282,16 @@ static void dw_pcie_ep_init_non_sticky_registers(struct dw_pcie *pci)
&lnkcap, func0_lnkcap);
dw_pcie_ep_writel_dbi(ep, func_no,
offset + PCI_EXP_LNKCAP, lnkcap);
+
+ if (!dw_pcie_refclk_is_separate(pci))
+ continue;
+
+ lnksta = dw_pcie_ep_readw_dbi(ep, func_no,
+ offset + PCI_EXP_LNKSTA);
+ lnksta &= ~(PCI_EXP_LNKSTA_SLC | PCI_EXP_LNKSTA_LBMS |
+ PCI_EXP_LNKSTA_LABS);
+ dw_pcie_ep_writew_dbi(ep, func_no,
+ offset + PCI_EXP_LNKSTA, lnksta);
}
}
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
index 12f102f48d5d..985b248cb6c0 100644
--- a/drivers/pci/controller/dwc/pcie-designware.c
+++ b/drivers/pci/controller/dwc/pcie-designware.c
@@ -17,6 +17,7 @@
#include <linux/ioport.h>
#include <linux/of.h>
#include <linux/of_address.h>
+#include <linux/of_pci.h>
#include <linux/pcie-dwc.h>
#include <linux/platform_device.h>
#include <linux/sizes.h>
@@ -111,6 +112,38 @@ static int dw_pcie_get_resets(struct dw_pcie *pci)
return 0;
}
+static enum dw_pcie_refclk_mode dw_pcie_of_get_refclk_mode(struct device *dev,
+ struct device_node *np)
+{
+ static const char * const modes[] = { "common", "srns", "sris" };
+ const char *mode;
+ int ret;
+
+ if (of_property_read_string(np, "refclk-mode", &mode))
+ return DW_PCIE_REFCLK_MODE_UNSPECIFIED;
+
+ ret = match_string(modes, ARRAY_SIZE(modes), mode);
+ if (ret < 0) {
+ dev_warn(dev, "Invalid refclk-mode \"%s\"\n", mode);
+ return DW_PCIE_REFCLK_MODE_UNSPECIFIED;
+ }
+
+ return DW_PCIE_REFCLK_MODE_COMMON + ret;
+}
+
+static void dw_pcie_get_refclk_mode(struct dw_pcie *pci)
+{
+ struct device_node *np = dev_of_node(pci->dev);
+ struct device_node *rp;
+
+ pci->refclk_mode = dw_pcie_of_get_refclk_mode(pci->dev, np);
+
+ rp = of_pci_find_child_device(np, 0);
+ if (rp && of_property_present(rp, "refclk-mode"))
+ pci->refclk_mode = dw_pcie_of_get_refclk_mode(pci->dev, rp);
+ of_node_put(rp);
+}
+
int dw_pcie_get_resources(struct dw_pcie *pci)
{
struct platform_device *pdev = to_platform_device(pci->dev);
@@ -198,6 +231,8 @@ int dw_pcie_get_resources(struct dw_pcie *pci)
of_property_read_u32(np, "num-lanes", &pci->num_lanes);
+ dw_pcie_get_refclk_mode(pci);
+
if (of_property_read_bool(np, "snps,enable-cdm-check"))
dw_pcie_cap_set(pci, CDM_CHECK);
@@ -1268,6 +1303,16 @@ void dw_pcie_program_t_power_on(struct dw_pcie *pci, u32 t_power_on)
dw_pcie_dbi_ro_wr_dis(pci);
}
+static void dw_pcie_clear_slot_clk_config(struct dw_pcie *pci)
+{
+ u8 offset = dw_pcie_get_pcie_cap(pci);
+ u16 val;
+
+ val = dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKSTA);
+ val &= ~(PCI_EXP_LNKSTA_SLC | PCI_EXP_LNKSTA_LBMS | PCI_EXP_LNKSTA_LABS);
+ dw_pcie_writew_dbi(pci, offset + PCI_EXP_LNKSTA, val);
+}
+
void dw_pcie_setup(struct dw_pcie *pci)
{
u32 val;
@@ -1304,6 +1349,9 @@ void dw_pcie_setup(struct dw_pcie *pci)
dw_pcie_writel_dbi(pci, PORT_LINK_CTRL, val);
dw_pcie_link_set_max_link_width(pci, pci->num_lanes);
+
+ if (dw_pcie_refclk_is_separate(pci))
+ dw_pcie_clear_slot_clk_config(pci);
}
resource_size_t dw_pcie_parent_bus_offset(struct dw_pcie *pci,
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index 6d788aa00011..202c68dcf8db 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -340,6 +340,13 @@ enum dw_pcie_device_mode {
DW_PCIE_RC_TYPE,
};
+enum dw_pcie_refclk_mode {
+ DW_PCIE_REFCLK_MODE_UNSPECIFIED,
+ DW_PCIE_REFCLK_MODE_COMMON,
+ DW_PCIE_REFCLK_MODE_SRNS,
+ DW_PCIE_REFCLK_MODE_SRIS,
+};
+
enum dw_pcie_app_clk {
DW_PCIE_DBI_CLK,
DW_PCIE_MSTR_CLK,
@@ -566,6 +573,7 @@ struct dw_pcie {
unsigned long caps;
int num_lanes;
int max_link_speed;
+ enum dw_pcie_refclk_mode refclk_mode;
u8 n_fts[2];
struct dw_edma_chip edma;
phys_addr_t edma_reg_phys;
@@ -660,6 +668,12 @@ static inline u16 dw_pcie_readw_dbi(struct dw_pcie *pci, u32 reg)
return dw_pcie_read_dbi(pci, reg, 0x2);
}
+static inline bool dw_pcie_refclk_is_separate(struct dw_pcie *pci)
+{
+ return pci->refclk_mode == DW_PCIE_REFCLK_MODE_SRNS ||
+ pci->refclk_mode == DW_PCIE_REFCLK_MODE_SRIS;
+}
+
static inline void dw_pcie_writeb_dbi(struct dw_pcie *pci, u32 reg, u8 val)
{
dw_pcie_write_dbi(pci, reg, 0x1, val);
--
2.56.1
prev parent reply other threads:[~2026-11-30 23:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 22:52 [RFC PATCH v2 0/3] PCI: Describe the reference clock architecture of a Link Niklas Cassel
2026-11-30 22:52 ` [RFC PATCH v2 1/3] schemas: pci: bridge: Document the REFCLK supplied to the Link Niklas Cassel
2026-11-30 22:52 ` [RFC PATCH v2 2/3] schemas: pci-bus-common: Add 'refclk-mode' property Niklas Cassel
2026-11-30 22:52 ` [RFC PATCH v2 3/3] dt-bindings: PCI: pci-ep: Add refclk-mode property Niklas Cassel
2026-11-30 23:38 ` Niklas Cassel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aw4JDZkEBKzetyer@ryzen \
--to=cassel@kernel.org \
--cc=bhelgaas@google.com \
--cc=conor+dt@kernel.org \
--cc=den@valinux.co.jp \
--cc=devicetree@vger.kernel.org \
--cc=dlemoal@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mani@kernel.org \
--cc=marek.vasut+renesas@mailbox.org \
--cc=robh@kernel.org \
--cc=vincent.guittot@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox