Skip to content

Commit b609a15

Browse files
AngeloGioacchino Del Regnokwilczynski
authored andcommitted
PCI: mediatek-gen3: Add support for restricting link width
Add support for restricting the port's link width by specifying the num-lanes devicetree property in the PCIe node. The setting is done in the GEN_SETTINGS register (in the driver named as PCIE_SETTING_REG), where each set bit in [11:8] activates a set of lanes (from bits 11 to 8 respectively, x16/x8/x4/x2). Link: https://lore.kernel.org/r/20241104114935.172908-3-angelogioacchino.delregno@collabora.com Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Reviewed-by: Fei Shao <fshao@chromium.org> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
1 parent ade7da1 commit b609a15

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define PCIE_BASE_CFG_SPEED GENMASK(15, 8)
3333

3434
#define PCIE_SETTING_REG 0x80
35+
#define PCIE_SETTING_LINK_WIDTH GENMASK(11, 8)
3536
#define PCIE_SETTING_GEN_SUPPORT GENMASK(14, 12)
3637
#define PCIE_PCI_IDS_1 0x9c
3738
#define PCI_CLASS(class) (class << 8)
@@ -168,6 +169,7 @@ struct mtk_msi_set {
168169
* @clks: PCIe clocks
169170
* @num_clks: PCIe clocks count for this port
170171
* @max_link_speed: Maximum link speed (PCIe Gen) for this port
172+
* @num_lanes: Number of PCIe lanes for this port
171173
* @irq: PCIe controller interrupt number
172174
* @saved_irq_state: IRQ enable state saved at suspend time
173175
* @irq_lock: lock protecting IRQ register access
@@ -189,6 +191,7 @@ struct mtk_gen3_pcie {
189191
struct clk_bulk_data *clks;
190192
int num_clks;
191193
u8 max_link_speed;
194+
u8 num_lanes;
192195

193196
int irq;
194197
u32 saved_irq_state;
@@ -401,6 +404,14 @@ static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
401404
val |= FIELD_PREP(PCIE_SETTING_GEN_SUPPORT,
402405
GENMASK(pcie->max_link_speed - 2, 0));
403406
}
407+
if (pcie->num_lanes) {
408+
val &= ~PCIE_SETTING_LINK_WIDTH;
409+
410+
/* Zero means one lane, each bit activates x2/x4/x8/x16 */
411+
if (pcie->num_lanes > 1)
412+
val |= FIELD_PREP(PCIE_SETTING_LINK_WIDTH,
413+
GENMASK(fls(pcie->num_lanes >> 2), 0));
414+
};
404415
writel_relaxed(val, pcie->base + PCIE_SETTING_REG);
405416

406417
/* Set Link Control 2 (LNKCTL2) speed restriction, if any */
@@ -838,6 +849,7 @@ static int mtk_pcie_parse_port(struct mtk_gen3_pcie *pcie)
838849
struct device *dev = pcie->dev;
839850
struct platform_device *pdev = to_platform_device(dev);
840851
struct resource *regs;
852+
u32 num_lanes;
841853

842854
regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcie-mac");
843855
if (!regs)
@@ -883,6 +895,14 @@ static int mtk_pcie_parse_port(struct mtk_gen3_pcie *pcie)
883895
return pcie->num_clks;
884896
}
885897

898+
ret = of_property_read_u32(dev->of_node, "num-lanes", &num_lanes);
899+
if (ret == 0) {
900+
if (num_lanes == 0 || num_lanes > 16 || (num_lanes != 1 && num_lanes % 2))
901+
dev_warn(dev, "invalid num-lanes, using controller defaults\n");
902+
else
903+
pcie->num_lanes = num_lanes;
904+
}
905+
886906
return 0;
887907
}
888908

0 commit comments

Comments
 (0)