Skip to content

Commit 09150ab

Browse files
AnsuelMani-Sadhasivam
authored andcommitted
PCI: mediatek: Add support for Airoha AN7583 SoC
Add support for the second PCIe Root Complex present on Airoha AN7583 SoC. This is based on the Mediatek Gen1/2 PCIe driver and similar to Gen3 also require workaround for the reset signals. Introduce a new quirk to skip having to reset signals and also introduce some additional logic to configure the PBUS registers required for Airoha SoC. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://patch.msgid.link/20251020111121.31779-6-ansuelsmth@gmail.com
1 parent 2d58bc7 commit 09150ab

1 file changed

Lines changed: 61 additions & 14 deletions

File tree

drivers/pci/controller/pcie-mediatek.c

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ struct mtk_pcie_port;
147147
* @MTK_PCIE_FIX_CLASS_ID: host's class ID needed to be fixed
148148
* @MTK_PCIE_FIX_DEVICE_ID: host's device ID needed to be fixed
149149
* @MTK_PCIE_NO_MSI: Bridge has no MSI support, and relies on an external block
150+
* @MTK_PCIE_SKIP_RSTB: Skip calling RSTB bits on PCIe probe
150151
*/
151152
enum mtk_pcie_quirks {
152153
MTK_PCIE_FIX_CLASS_ID = BIT(0),
153154
MTK_PCIE_FIX_DEVICE_ID = BIT(1),
154155
MTK_PCIE_NO_MSI = BIT(2),
156+
MTK_PCIE_SKIP_RSTB = BIT(3),
155157
};
156158

157159
/**
@@ -687,23 +689,25 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port)
687689
regmap_update_bits(pcie->cfg, PCIE_SYS_CFG_V2, val, val);
688690
}
689691

690-
/* Assert all reset signals */
691-
writel(0, port->base + PCIE_RST_CTRL);
692+
if (!(soc->quirks & MTK_PCIE_SKIP_RSTB)) {
693+
/* Assert all reset signals */
694+
writel(0, port->base + PCIE_RST_CTRL);
692695

693-
/*
694-
* Enable PCIe link down reset, if link status changed from link up to
695-
* link down, this will reset MAC control registers and configuration
696-
* space.
697-
*/
698-
writel(PCIE_LINKDOWN_RST_EN, port->base + PCIE_RST_CTRL);
696+
/*
697+
* Enable PCIe link down reset, if link status changed from
698+
* link up to link down, this will reset MAC control registers
699+
* and configuration space.
700+
*/
701+
writel(PCIE_LINKDOWN_RST_EN, port->base + PCIE_RST_CTRL);
699702

700-
msleep(PCIE_T_PVPERL_MS);
703+
msleep(PCIE_T_PVPERL_MS);
701704

702-
/* De-assert PHY, PE, PIPE, MAC and configuration reset */
703-
val = readl(port->base + PCIE_RST_CTRL);
704-
val |= PCIE_PHY_RSTB | PCIE_PERSTB | PCIE_PIPE_SRSTB |
705-
PCIE_MAC_SRSTB | PCIE_CRSTB;
706-
writel(val, port->base + PCIE_RST_CTRL);
705+
/* De-assert PHY, PE, PIPE, MAC and configuration reset */
706+
val = readl(port->base + PCIE_RST_CTRL);
707+
val |= PCIE_PHY_RSTB | PCIE_PERSTB | PCIE_PIPE_SRSTB |
708+
PCIE_MAC_SRSTB | PCIE_CRSTB;
709+
writel(val, port->base + PCIE_RST_CTRL);
710+
}
707711

708712
/* Set up vendor ID and class code */
709713
if (soc->quirks & MTK_PCIE_FIX_CLASS_ID) {
@@ -824,6 +828,41 @@ static int mtk_pcie_startup_port(struct mtk_pcie_port *port)
824828
return 0;
825829
}
826830

831+
static int mtk_pcie_startup_port_an7583(struct mtk_pcie_port *port)
832+
{
833+
struct mtk_pcie *pcie = port->pcie;
834+
struct device *dev = pcie->dev;
835+
struct pci_host_bridge *host;
836+
struct resource_entry *entry;
837+
struct regmap *pbus_regmap;
838+
resource_size_t addr;
839+
u32 args[2], size;
840+
841+
/*
842+
* Configure PBus base address and base address mask to allow
843+
* the hw to detect if a given address is accessible on PCIe
844+
* controller.
845+
*/
846+
pbus_regmap = syscon_regmap_lookup_by_phandle_args(dev->of_node,
847+
"mediatek,pbus-csr",
848+
ARRAY_SIZE(args),
849+
args);
850+
if (IS_ERR(pbus_regmap))
851+
return PTR_ERR(pbus_regmap);
852+
853+
host = pci_host_bridge_from_priv(pcie);
854+
entry = resource_list_first_type(&host->windows, IORESOURCE_MEM);
855+
if (!entry)
856+
return -ENODEV;
857+
858+
addr = entry->res->start - entry->offset;
859+
regmap_write(pbus_regmap, args[0], lower_32_bits(addr));
860+
size = lower_32_bits(resource_size(entry->res));
861+
regmap_write(pbus_regmap, args[1], GENMASK(31, __fls(size)));
862+
863+
return mtk_pcie_startup_port_v2(port);
864+
}
865+
827866
static void mtk_pcie_enable_port(struct mtk_pcie_port *port)
828867
{
829868
struct mtk_pcie *pcie = port->pcie;
@@ -1208,6 +1247,13 @@ static const struct mtk_pcie_soc mtk_pcie_soc_mt7622 = {
12081247
.quirks = MTK_PCIE_FIX_CLASS_ID,
12091248
};
12101249

1250+
static const struct mtk_pcie_soc mtk_pcie_soc_an7583 = {
1251+
.ops = &mtk_pcie_ops_v2,
1252+
.startup = mtk_pcie_startup_port_an7583,
1253+
.setup_irq = mtk_pcie_setup_irq,
1254+
.quirks = MTK_PCIE_FIX_CLASS_ID | MTK_PCIE_SKIP_RSTB,
1255+
};
1256+
12111257
static const struct mtk_pcie_soc mtk_pcie_soc_mt7629 = {
12121258
.device_id = PCI_DEVICE_ID_MEDIATEK_7629,
12131259
.ops = &mtk_pcie_ops_v2,
@@ -1217,6 +1263,7 @@ static const struct mtk_pcie_soc mtk_pcie_soc_mt7629 = {
12171263
};
12181264

12191265
static const struct of_device_id mtk_pcie_ids[] = {
1266+
{ .compatible = "airoha,an7583-pcie", .data = &mtk_pcie_soc_an7583 },
12201267
{ .compatible = "mediatek,mt2701-pcie", .data = &mtk_pcie_soc_v1 },
12211268
{ .compatible = "mediatek,mt7623-pcie", .data = &mtk_pcie_soc_v1 },
12221269
{ .compatible = "mediatek,mt2712-pcie", .data = &mtk_pcie_soc_mt2712 },

0 commit comments

Comments
 (0)