PCI: dwc: endpoint: Introduce .pre_init() and .deinit()
authorYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Wed, 18 Oct 2023 08:56:24 +0000 (17:56 +0900)
committerKrzysztof Wilczyński <kwilczynski@kernel.org>
Mon, 23 Oct 2023 12:40:09 +0000 (12:40 +0000)
Renesas R-Car Gen4 PCIe controllers require vendor-specific
initialization before .init().

To use dw->dbi and dw->num-lanes in the initialization code,
introduce .pre_init() into struct dw_pcie_ep_ops. While at it,
also introduce .deinit() to disable the controller by using
vendor-specific de-initialization.

Note that the ep_init in the struct dw_pcie_ep_ops should be
renamed to init later.

Link: https://lore.kernel.org/linux-pci/20231018085631.1121289-9-yoshihiro.shimoda.uh@renesas.com
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
drivers/pci/controller/dwc/pcie-designware-ep.c
drivers/pci/controller/dwc/pcie-designware.h

index a8bcbc57ef86bb3587bf8b34ea06af3274037b81..d34a5e87ad18af536a2f16d121d791418d3371bc 100644 (file)
@@ -637,6 +637,9 @@ void dw_pcie_ep_exit(struct dw_pcie_ep *ep)
                              epc->mem->window.page_size);
 
        pci_epc_mem_exit(epc);
+
+       if (ep->ops->deinit)
+               ep->ops->deinit(ep);
 }
 EXPORT_SYMBOL_GPL(dw_pcie_ep_exit);
 
@@ -740,6 +743,9 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
        ep->phys_base = res->start;
        ep->addr_size = resource_size(res);
 
+       if (ep->ops->pre_init)
+               ep->ops->pre_init(ep);
+
        dw_pcie_version_detect(pci);
 
        dw_pcie_iatu_detect(pci);
@@ -794,7 +800,7 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
                               ep->page_size);
        if (ret < 0) {
                dev_err(dev, "Failed to initialize address space\n");
-               return ret;
+               goto err_ep_deinit;
        }
 
        ep->msi_mem = pci_epc_mem_alloc_addr(epc, &ep->msi_mem_phys,
@@ -831,6 +837,10 @@ err_free_epc_mem:
 err_exit_epc_mem:
        pci_epc_mem_exit(epc);
 
+err_ep_deinit:
+       if (ep->ops->deinit)
+               ep->ops->deinit(ep);
+
        return ret;
 }
 EXPORT_SYMBOL_GPL(dw_pcie_ep_init);
index e10f7e18b13a4289f1b783460c033be7e3de33a9..8c637392ab083ca4c7d0446711b5780b7e689e72 100644 (file)
@@ -330,7 +330,9 @@ struct dw_pcie_rp {
 };
 
 struct dw_pcie_ep_ops {
+       void    (*pre_init)(struct dw_pcie_ep *ep);
        void    (*ep_init)(struct dw_pcie_ep *ep);
+       void    (*deinit)(struct dw_pcie_ep *ep);
        int     (*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
                             enum pci_epc_irq_type type, u16 interrupt_num);
        const struct pci_epc_features* (*get_features)(struct dw_pcie_ep *ep);