[PATCH 1/2] PCI: rockchip: Work around missing device_type property in DT
From: Marc Zyngier
Date: Sat Aug 15 2020 - 18:12:03 EST
Recent changes to the DT PCI bus parsing made it mandatory for
device tree nodes describing a PCI controller to have the
'device_type = "pci"' property for the node to be matched.
Although this follows the letter of the specification, it
breaks existing device-trees that have been working fine
for years. Rockchip rk3399-based systems are a prime example
of such collateral damage, and have stopped discovering their
PCI bus.
In order to paper over the blunder, let's add a workaround
to the pcie-rockchip driver, adding the missing property when
none is found at boot time. A warning will hopefully nudge the
user into updating their DT to a fixed version if they can, but
the insentive is obviously pretty small.
Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
Suggested-by: Roh Herring <robh+dt@xxxxxxxxxx>
Signed-off-by: Marc Zyngier <maz@xxxxxxxxxx>
---
drivers/pci/controller/pcie-rockchip-host.c | 29 +++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/drivers/pci/controller/pcie-rockchip-host.c b/drivers/pci/controller/pcie-rockchip-host.c
index 0bb2fb3e8a0b..d7dd04430a99 100644
--- a/drivers/pci/controller/pcie-rockchip-host.c
+++ b/drivers/pci/controller/pcie-rockchip-host.c
@@ -949,6 +949,35 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
if (!dev->of_node)
return -ENODEV;
+ /*
+ * Most rk3399 DTs are missing the 'device_type = "pci"' property,
+ * potentially leading to PCIe probing failure. Be kind to the
+ * users and fix it up for them. Upgrading is recommended.
+ */
+ if (!of_find_property(dev->of_node, "device_type", NULL)) {
+ const char dtype[] = "pci";
+ struct property *prop;
+
+ dev_warn(dev, "Working around missing device_type property\n");
+
+ prop = kzalloc(sizeof(*prop), GFP_KERNEL);
+ if (!prop)
+ return -ENOMEM;
+
+ prop->name = kstrdup("device_type", GFP_KERNEL);
+ prop->value = kstrdup(dtype, GFP_KERNEL);
+ prop->length = ARRAY_SIZE(dtype);
+ if (!prop->name || !prop->value) {
+ kfree(prop->name);
+ kfree(prop->value);
+ kfree(prop);
+ return -ENOMEM;
+ }
+
+ if (of_add_property(dev->of_node, prop))
+ dev_warn(dev, "Failed to add property, probing may fail");
+ }
+
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rockchip));
if (!bridge)
return -ENOMEM;
--
2.27.0