[PATCH v5 4/5] PCI: mediatek: convert bool to single flags entry and bitmap
From: Christian Marangi <ansuelsmth@gmail.com>
Date: 2025-10-12 20:59:15
Also in:
linux-devicetree, linux-mediatek, linux-pci, lkml
Subsystem:
pci native host bridge and endpoint drivers, pci subsystem, pcie driver for mediatek, the rest · Maintainers:
Lorenzo Pieralisi, Krzysztof Wilczyński, Manivannan Sadhasivam, Bjorn Helgaas, Ryder Lee, Linus Torvalds
To clean Mediatek SoC PCIe struct, convert all the bool to a bitmap and use a single flags to reference all the values. This permits cleaner addition of new flag without having to define a new bool in the struct. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> --- drivers/pci/controller/pcie-mediatek.c | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index 24cc30a2ab6c..1678461e56d3 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c@@ -142,24 +142,29 @@ struct mtk_pcie_port; +enum mtk_pcie_flags { + NEED_FIX_CLASS_ID = BIT(0), /* host's class ID needed to be fixed */ + NEED_FIX_DEVICE_ID = BIT(1), /* host's device ID needed to be fixed */ + NO_MSI = BIT(2), /* Bridge has no MSI support, and relies on an + * external block + */ +}; + /** * struct mtk_pcie_soc - differentiate between host generations - * @need_fix_class_id: whether this host's class ID needed to be fixed or not - * @need_fix_device_id: whether this host's device ID needed to be fixed or not * @no_msi: Bridge has no MSI support, and relies on an external block * @device_id: device ID which this host need to be fixed * @ops: pointer to configuration access functions * @startup: pointer to controller setting functions * @setup_irq: pointer to initialize IRQ functions + * @flags: pcie device flags. */ struct mtk_pcie_soc { - bool need_fix_class_id; - bool need_fix_device_id; - bool no_msi; unsigned int device_id; struct pci_ops *ops; int (*startup)(struct mtk_pcie_port *port); int (*setup_irq)(struct mtk_pcie_port *port, struct device_node *node); + u32 flags; }; /**
@@ -703,7 +708,7 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) writel(val, port->base + PCIE_RST_CTRL); /* Set up vendor ID and class code */ - if (soc->need_fix_class_id) { + if (soc->flags & NEED_FIX_CLASS_ID) { val = PCI_VENDOR_ID_MEDIATEK; writew(val, port->base + PCIE_CONF_VEND_ID);
@@ -711,7 +716,7 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) writew(val, port->base + PCIE_CONF_CLASS_ID); } - if (soc->need_fix_device_id) + if (soc->flags & NEED_FIX_DEVICE_ID) writew(soc->device_id, port->base + PCIE_CONF_DEVICE_ID); /* 100ms timeout value should be enough for Gen1/2 training */
@@ -1099,7 +1104,7 @@ static int mtk_pcie_probe(struct platform_device *pdev) host->ops = pcie->soc->ops; host->sysdata = pcie; - host->msi_domain = pcie->soc->no_msi; + host->msi_domain = !!(pcie->soc->flags & NO_MSI); err = pci_host_probe(host); if (err)
@@ -1187,9 +1192,9 @@ static const struct dev_pm_ops mtk_pcie_pm_ops = { }; static const struct mtk_pcie_soc mtk_pcie_soc_v1 = { - .no_msi = true, .ops = &mtk_pcie_ops, .startup = mtk_pcie_startup_port, + .flags = NO_MSI, }; static const struct mtk_pcie_soc mtk_pcie_soc_mt2712 = {
@@ -1199,19 +1204,18 @@ static const struct mtk_pcie_soc mtk_pcie_soc_mt2712 = { }; static const struct mtk_pcie_soc mtk_pcie_soc_mt7622 = { - .need_fix_class_id = true, .ops = &mtk_pcie_ops_v2, .startup = mtk_pcie_startup_port_v2, .setup_irq = mtk_pcie_setup_irq, + .flags = NEED_FIX_CLASS_ID, }; static const struct mtk_pcie_soc mtk_pcie_soc_mt7629 = { - .need_fix_class_id = true, - .need_fix_device_id = true, .device_id = PCI_DEVICE_ID_MEDIATEK_7629, .ops = &mtk_pcie_ops_v2, .startup = mtk_pcie_startup_port_v2, .setup_irq = mtk_pcie_setup_irq, + .flags = NEED_FIX_CLASS_ID | NEED_FIX_DEVICE_ID, }; static const struct of_device_id mtk_pcie_ids[] = {
--
2.51.0