Commit e09e1a40 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'pci-v5.17-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci

Pull pci fixes from Bjorn Helgaas:

 - Restructure j721e_pcie_probe() so we don't dereference a NULL pointer
   (Bjorn Helgaas)

 - Add a kirin_pcie_data struct to identify different Kirin variants to
   fix probe failure for controllers with an internal PHY (Bjorn
   Helgaas)

* tag 'pci-v5.17-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci:
  PCI: kirin: Add dev struct for of_device_get_match_data()
  PCI: j721e: Initialize pcie->cdns_pcie before using it
parents 86286e48 7dd38762
...@@ -356,8 +356,8 @@ static int j721e_pcie_probe(struct platform_device *pdev) ...@@ -356,8 +356,8 @@ static int j721e_pcie_probe(struct platform_device *pdev)
const struct j721e_pcie_data *data; const struct j721e_pcie_data *data;
struct cdns_pcie *cdns_pcie; struct cdns_pcie *cdns_pcie;
struct j721e_pcie *pcie; struct j721e_pcie *pcie;
struct cdns_pcie_rc *rc; struct cdns_pcie_rc *rc = NULL;
struct cdns_pcie_ep *ep; struct cdns_pcie_ep *ep = NULL;
struct gpio_desc *gpiod; struct gpio_desc *gpiod;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
...@@ -376,6 +376,46 @@ static int j721e_pcie_probe(struct platform_device *pdev) ...@@ -376,6 +376,46 @@ static int j721e_pcie_probe(struct platform_device *pdev)
if (!pcie) if (!pcie)
return -ENOMEM; return -ENOMEM;
switch (mode) {
case PCI_MODE_RC:
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_HOST))
return -ENODEV;
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc));
if (!bridge)
return -ENOMEM;
if (!data->byte_access_allowed)
bridge->ops = &cdns_ti_pcie_host_ops;
rc = pci_host_bridge_priv(bridge);
rc->quirk_retrain_flag = data->quirk_retrain_flag;
rc->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag;
cdns_pcie = &rc->pcie;
cdns_pcie->dev = dev;
cdns_pcie->ops = &j721e_pcie_ops;
pcie->cdns_pcie = cdns_pcie;
break;
case PCI_MODE_EP:
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_EP))
return -ENODEV;
ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL);
if (!ep)
return -ENOMEM;
ep->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag;
cdns_pcie = &ep->pcie;
cdns_pcie->dev = dev;
cdns_pcie->ops = &j721e_pcie_ops;
pcie->cdns_pcie = cdns_pcie;
break;
default:
dev_err(dev, "INVALID device type %d\n", mode);
return 0;
}
pcie->mode = mode; pcie->mode = mode;
pcie->linkdown_irq_regfield = data->linkdown_irq_regfield; pcie->linkdown_irq_regfield = data->linkdown_irq_regfield;
...@@ -426,28 +466,6 @@ static int j721e_pcie_probe(struct platform_device *pdev) ...@@ -426,28 +466,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)
switch (mode) { switch (mode) {
case PCI_MODE_RC: case PCI_MODE_RC:
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_HOST)) {
ret = -ENODEV;
goto err_get_sync;
}
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc));
if (!bridge) {
ret = -ENOMEM;
goto err_get_sync;
}
if (!data->byte_access_allowed)
bridge->ops = &cdns_ti_pcie_host_ops;
rc = pci_host_bridge_priv(bridge);
rc->quirk_retrain_flag = data->quirk_retrain_flag;
rc->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag;
cdns_pcie = &rc->pcie;
cdns_pcie->dev = dev;
cdns_pcie->ops = &j721e_pcie_ops;
pcie->cdns_pcie = cdns_pcie;
gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(gpiod)) { if (IS_ERR(gpiod)) {
ret = PTR_ERR(gpiod); ret = PTR_ERR(gpiod);
...@@ -497,23 +515,6 @@ static int j721e_pcie_probe(struct platform_device *pdev) ...@@ -497,23 +515,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)
break; break;
case PCI_MODE_EP: case PCI_MODE_EP:
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_EP)) {
ret = -ENODEV;
goto err_get_sync;
}
ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL);
if (!ep) {
ret = -ENOMEM;
goto err_get_sync;
}
ep->quirk_detect_quiet_flag = data->quirk_detect_quiet_flag;
cdns_pcie = &ep->pcie;
cdns_pcie->dev = dev;
cdns_pcie->ops = &j721e_pcie_ops;
pcie->cdns_pcie = cdns_pcie;
ret = cdns_pcie_init_phy(dev, cdns_pcie); ret = cdns_pcie_init_phy(dev, cdns_pcie);
if (ret) { if (ret) {
dev_err(dev, "Failed to init phy\n"); dev_err(dev, "Failed to init phy\n");
...@@ -525,8 +526,6 @@ static int j721e_pcie_probe(struct platform_device *pdev) ...@@ -525,8 +526,6 @@ static int j721e_pcie_probe(struct platform_device *pdev)
goto err_pcie_setup; goto err_pcie_setup;
break; break;
default:
dev_err(dev, "INVALID device type %d\n", mode);
} }
return 0; return 0;
......
...@@ -756,22 +756,28 @@ static int __exit kirin_pcie_remove(struct platform_device *pdev) ...@@ -756,22 +756,28 @@ static int __exit kirin_pcie_remove(struct platform_device *pdev)
return 0; return 0;
} }
struct kirin_pcie_data {
enum pcie_kirin_phy_type phy_type;
};
static const struct kirin_pcie_data kirin_960_data = {
.phy_type = PCIE_KIRIN_INTERNAL_PHY,
};
static const struct kirin_pcie_data kirin_970_data = {
.phy_type = PCIE_KIRIN_EXTERNAL_PHY,
};
static const struct of_device_id kirin_pcie_match[] = { static const struct of_device_id kirin_pcie_match[] = {
{ { .compatible = "hisilicon,kirin960-pcie", .data = &kirin_960_data },
.compatible = "hisilicon,kirin960-pcie", { .compatible = "hisilicon,kirin970-pcie", .data = &kirin_970_data },
.data = (void *)PCIE_KIRIN_INTERNAL_PHY
},
{
.compatible = "hisilicon,kirin970-pcie",
.data = (void *)PCIE_KIRIN_EXTERNAL_PHY
},
{}, {},
}; };
static int kirin_pcie_probe(struct platform_device *pdev) static int kirin_pcie_probe(struct platform_device *pdev)
{ {
enum pcie_kirin_phy_type phy_type;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
const struct kirin_pcie_data *data;
struct kirin_pcie *kirin_pcie; struct kirin_pcie *kirin_pcie;
struct dw_pcie *pci; struct dw_pcie *pci;
int ret; int ret;
...@@ -781,13 +787,12 @@ static int kirin_pcie_probe(struct platform_device *pdev) ...@@ -781,13 +787,12 @@ static int kirin_pcie_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
phy_type = (long)of_device_get_match_data(dev); data = of_device_get_match_data(dev);
if (!phy_type) { if (!data) {
dev_err(dev, "OF data missing\n"); dev_err(dev, "OF data missing\n");
return -EINVAL; return -EINVAL;
} }
kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL); kirin_pcie = devm_kzalloc(dev, sizeof(struct kirin_pcie), GFP_KERNEL);
if (!kirin_pcie) if (!kirin_pcie)
return -ENOMEM; return -ENOMEM;
...@@ -800,7 +805,7 @@ static int kirin_pcie_probe(struct platform_device *pdev) ...@@ -800,7 +805,7 @@ static int kirin_pcie_probe(struct platform_device *pdev)
pci->ops = &kirin_dw_pcie_ops; pci->ops = &kirin_dw_pcie_ops;
pci->pp.ops = &kirin_pcie_host_ops; pci->pp.ops = &kirin_pcie_host_ops;
kirin_pcie->pci = pci; kirin_pcie->pci = pci;
kirin_pcie->type = phy_type; kirin_pcie->type = data->phy_type;
ret = kirin_pcie_get_resource(kirin_pcie, pdev); ret = kirin_pcie_get_resource(kirin_pcie, pdev);
if (ret) if (ret)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment