Most ECAM host drivers are just different pci_ecam_ops which can be DT match table data. That's already the case in some cases, but let's do that for all the ECAM drivers. Then we can use of_device_get_match_data() in pci_host_common_probe() and eliminate the probe wrapper functions and use pci_host_common_probe() directly for probe.
Unified · Split
| @@ -332,15 +332,6 @@ static struct platform_driver hisi_pcie_driver = { · 331 unmodified lines | |||
| 332 | }; | 332 | }; |
| 333 | builtin_platform_driver(hisi_pcie_driver); | 333 | builtin_platform_driver(hisi_pcie_driver); |
| 334 | 334 | ||
| 335 | static int hisi_pcie_almost_ecam_probe(struct platform_device *pdev) | ||
| 336 | { | ||
| 337 | struct device *dev = &pdev->dev; | ||
| 338 | struct pci_ecam_ops *ops; | ||
| 339 | |||
| 340 | ops = (struct pci_ecam_ops *)of_device_get_match_data(dev); | ||
| 341 | return pci_host_common_probe(pdev, ops); | ||
| 342 | } | ||
| 343 | |||
| 344 | static int hisi_pcie_platform_init(struct pci_config_window *cfg) | 335 | static int hisi_pcie_platform_init(struct pci_config_window *cfg) |
| 345 | { | 336 | { |
| 346 | struct device *dev = cfg->parent; | 337 | struct device *dev = cfg->parent; |
| @@ -385,7 +376,7 @@ static const struct of_device_id hisi_pcie_almost_ecam_of_match[] = { · 38 unmodified lines | |||
| 385 | }; | 376 | }; |
| 386 | 377 | ||
| 387 | static struct platform_driver hisi_pcie_almost_ecam_driver = { | 378 | static struct platform_driver hisi_pcie_almost_ecam_driver = { |
| 388 | .probe = hisi_pcie_almost_ecam_probe, | 379 | .probe = pci_host_common_probe, |
| 389 | .driver = { | 380 | .driver = { |
| 390 | .name = "hisi-pcie-almost-ecam", | 381 | .name = "hisi-pcie-almost-ecam", |
| 391 | .of_match_table = hisi_pcie_almost_ecam_of_match, | 382 | .of_match_table = hisi_pcie_almost_ecam_of_match, |
| @@ -10,6 +10,7 @@ · 9 unmodified lines | |||
| 10 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
| 12 | #include <linux/of_address.h> | 12 | #include <linux/of_address.h> |
| 13 | #include <linux/of_device.h> | ||
| 13 | #include <linux/of_pci.h> | 14 | #include <linux/of_pci.h> |
| 14 | #include <linux/pci-ecam.h> | 15 | #include <linux/pci-ecam.h> |
| 15 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
| @@ -55,15 +56,19 @@ err_out: · 39 unmodified lines | |||
| 55 | return ERR_PTR(err); | 56 | return ERR_PTR(err); |
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | int pci_host_common_probe(struct platform_device *pdev, | 59 | int pci_host_common_probe(struct platform_device *pdev) |
| 59 | const struct pci_ecam_ops *ops) | ||
| 60 | { | 60 | { |
| 61 | struct device *dev = &pdev->dev; | 61 | struct device *dev = &pdev->dev; |
| 62 | struct pci_host_bridge *bridge; | 62 | struct pci_host_bridge *bridge; |
| 63 | struct pci_config_window *cfg; | 63 | struct pci_config_window *cfg; |
| 64 | struct list_head resources; | 64 | struct list_head resources; |
| 65 | const struct pci_ecam_ops *ops; | ||
| 65 | int ret; | 66 | int ret; |
| 66 | 67 | ||
| 68 | ops = of_device_get_match_data(&pdev->dev); | ||
| 69 | if (!ops) | ||
| 70 | return -ENODEV; | ||
| 71 | |||
| 67 | bridge = devm_pci_alloc_host_bridge(dev, 0); | 72 | bridge = devm_pci_alloc_host_bridge(dev, 0); |
| 68 | if (!bridge) | 73 | if (!bridge) |
| 69 | return -ENOMEM; | 74 | return -ENOMEM; |
| @@ -11,8 +11,6 @@ · 10 unmodified lines | |||
| 11 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
| 14 | #include <linux/of_address.h> | ||
| 15 | #include <linux/of_pci.h> | ||
| 16 | #include <linux/pci-ecam.h> | 14 | #include <linux/pci-ecam.h> |
| 17 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
| 18 | 16 | ||
| @@ -79,23 +77,12 @@ static const struct of_device_id gen_pci_of_match[] = { · 60 unmodified lines | |||
| 79 | }; | 77 | }; |
| 80 | MODULE_DEVICE_TABLE(of, gen_pci_of_match); | 78 | MODULE_DEVICE_TABLE(of, gen_pci_of_match); |
| 81 | 79 | ||
| 82 | static int gen_pci_probe(struct platform_device *pdev) | ||
| 83 | { | ||
| 84 | const struct of_device_id *of_id; | ||
| 85 | struct pci_ecam_ops *ops; | ||
| 86 | |||
| 87 | of_id = of_match_node(gen_pci_of_match, pdev->dev.of_node); | ||
| 88 | ops = (struct pci_ecam_ops *)of_id->data; | ||
| 89 | |||
| 90 | return pci_host_common_probe(pdev, ops); | ||
| 91 | } | ||
| 92 | |||
| 93 | static struct platform_driver gen_pci_driver = { | 80 | static struct platform_driver gen_pci_driver = { |
| 94 | .driver = { | 81 | .driver = { |
| 95 | .name = "pci-host-generic", | 82 | .name = "pci-host-generic", |
| 96 | .of_match_table = gen_pci_of_match, | 83 | .of_match_table = gen_pci_of_match, |
| 97 | }, | 84 | }, |
| 98 | .probe = gen_pci_probe, | 85 | .probe = pci_host_common_probe, |
| 99 | .remove = pci_host_common_remove, | 86 | .remove = pci_host_common_remove, |
| 100 | }; | 87 | }; |
| 101 | module_platform_driver(gen_pci_driver); | 88 | module_platform_driver(gen_pci_driver); |
| @@ -357,22 +357,20 @@ const struct pci_ecam_ops pci_thunder_ecam_ops = { · 356 unmodified lines | |||
| 357 | #ifdef CONFIG_PCI_HOST_THUNDER_ECAM | 357 | #ifdef CONFIG_PCI_HOST_THUNDER_ECAM |
| 358 | 358 | ||
| 359 | static const struct of_device_id thunder_ecam_of_match[] = { | 359 | static const struct of_device_id thunder_ecam_of_match[] = { |
| 360 | { .compatible = "cavium,pci-host-thunder-ecam" }, | 360 | { |
| 361 | .compatible = "cavium,pci-host-thunder-ecam", | ||
| 362 | .data = &pci_thunder_ecam_ops, | ||
| 363 | }, | ||
| 361 | { }, | 364 | { }, |
| 362 | }; | 365 | }; |
| 363 | 366 | ||
| 364 | static int thunder_ecam_probe(struct platform_device *pdev) | ||
| 365 | { | ||
| 366 | return pci_host_common_probe(pdev, &pci_thunder_ecam_ops); | ||
| 367 | } | ||
| 368 | |||
| 369 | static struct platform_driver thunder_ecam_driver = { | 367 | static struct platform_driver thunder_ecam_driver = { |
| 370 | .driver = { | 368 | .driver = { |
| 371 | .name = KBUILD_MODNAME, | 369 | .name = KBUILD_MODNAME, |
| 372 | .of_match_table = thunder_ecam_of_match, | 370 | .of_match_table = thunder_ecam_of_match, |
| 373 | .suppress_bind_attrs = true, | 371 | .suppress_bind_attrs = true, |
| 374 | }, | 372 | }, |
| 375 | .probe = thunder_ecam_probe, | 373 | .probe = pci_host_common_probe, |
| 376 | }; | 374 | }; |
| 377 | builtin_platform_driver(thunder_ecam_driver); | 375 | builtin_platform_driver(thunder_ecam_driver); |
| 378 | 376 | ||
| @@ -451,22 +451,20 @@ static const struct pci_ecam_ops pci_thunder_pem_ops = { · 450 unmodified lines | |||
| 451 | }; | 451 | }; |
| 452 | 452 | ||
| 453 | static const struct of_device_id thunder_pem_of_match[] = { | 453 | static const struct of_device_id thunder_pem_of_match[] = { |
| 454 | { .compatible = "cavium,pci-host-thunder-pem" }, | 454 | { |
| 455 | .compatible = "cavium,pci-host-thunder-pem", | ||
| 456 | .data = &pci_thunder_pem_ops, | ||
| 457 | }, | ||
| 455 | { }, | 458 | { }, |
| 456 | }; | 459 | }; |
| 457 | 460 | ||
| 458 | static int thunder_pem_probe(struct platform_device *pdev) | ||
| 459 | { | ||
| 460 | return pci_host_common_probe(pdev, &pci_thunder_pem_ops); | ||
| 461 | } | ||
| 462 | |||
| 463 | static struct platform_driver thunder_pem_driver = { | 461 | static struct platform_driver thunder_pem_driver = { |
| 464 | .driver = { | 462 | .driver = { |
| 465 | .name = KBUILD_MODNAME, | 463 | .name = KBUILD_MODNAME, |
| 466 | .of_match_table = thunder_pem_of_match, | 464 | .of_match_table = thunder_pem_of_match, |
| 467 | .suppress_bind_attrs = true, | 465 | .suppress_bind_attrs = true, |
| 468 | }, | 466 | }, |
| 469 | .probe = thunder_pem_probe, | 467 | .probe = pci_host_common_probe, |
| 470 | }; | 468 | }; |
| 471 | builtin_platform_driver(thunder_pem_driver); | 469 | builtin_platform_driver(thunder_pem_driver); |
| 472 | 470 | ||
| @@ -295,11 +295,14 @@ static int tango_pcie_probe(struct platform_device *pdev) · 294 unmodified lines | |||
| 295 | spin_lock_init(&pcie->used_msi_lock); | 295 | spin_lock_init(&pcie->used_msi_lock); |
| 296 | irq_set_chained_handler_and_data(virq, tango_msi_isr, pcie); | 296 | irq_set_chained_handler_and_data(virq, tango_msi_isr, pcie); |
| 297 | 297 | ||
| 298 | return pci_host_common_probe(pdev, &smp8759_ecam_ops); | 298 | return pci_host_common_probe(pdev); |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | static const struct of_device_id tango_pcie_ids[] = { | 301 | static const struct of_device_id tango_pcie_ids[] = { |
| 302 | { .compatible = "sigma,smp8759-pcie" }, | 302 | { |
| 303 | .compatible = "sigma,smp8759-pcie", | ||
| 304 | .data = &smp8759_ecam_ops, | ||
| 305 | }, | ||
| 303 | { }, | 306 | { }, |
| 304 | }; | 307 | }; |
| 305 | 308 | ||
| @@ -61,8 +61,7 @@ extern const struct pci_ecam_ops al_pcie_ops; /* Amazon Annapurna Labs PCIe */ · 60 unmodified lines | |||
| 61 | 61 | ||
| 62 | #if IS_ENABLED(CONFIG_PCI_HOST_COMMON) | 62 | #if IS_ENABLED(CONFIG_PCI_HOST_COMMON) |
| 63 | /* for DT-based PCI controllers that support ECAM */ | 63 | /* for DT-based PCI controllers that support ECAM */ |
| 64 | int pci_host_common_probe(struct platform_device *pdev, | 64 | int pci_host_common_probe(struct platform_device *pdev); |
| 65 | const struct pci_ecam_ops *ops); | ||
| 66 | int pci_host_common_remove(struct platform_device *pdev); | 65 | int pci_host_common_remove(struct platform_device *pdev); |
| 67 | #endif | 66 | #endif |
| 68 | #endif | 67 | #endif |