Commit 40bd3a5f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'pci-v4.9-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci

PCI changes for the v4.9 merge window:
 "Here are some more changes I'd like to have in v4.9.  There's one
  small Tegra bug fix in the PHY poweroff path, which is only used in
  failure paths.

  The rest is all strictly cleanup that should make host bridge drivers
  more readable, but shouldn't actually change any behavior.

  Summary:

   - use local struct device pointers in many host bridge drivers for
     clarity

   - remove unused platform data

   - use generic DesignWare accessors

   - misc cleanups: remove redundant structure entries and re-order
     structure members to put comon generic fields first etc"

* tag 'pci-v4.9-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: (108 commits)
  MAINTAINERS: Add maintainer for the PCIe Marvell Armada 8K driver
  MAINTAINERS: Add DT binding to the Aardvark PCIe driver maintainer
  PCI: rockchip: Indent "if" statement body
  PCI: hisi: Reorder struct hisi_pcie
  PCI: hisi: Pass device-specific struct to internal functions
  PCI: hisi: Include register block base in PCIE_SYS_STATE4 address
  PCI: dra7xx: Reorder struct dra7xx_pcie
  PCI: xilinx-nwl: Remove unused platform data
  PCI: xilinx-nwl: Add local struct device pointers
  PCI: xilinx: Removed unused xilinx_pcie_assign_msi() argument
  PCI: xilinx: Remove unused platform data
  PCI: xilinx: Add local struct device pointers
  PCI: xgene: Add register accessors
  PCI: xgene: Pass struct xgene_pcie_port to setup functions
  PCI: xgene: Remove unused platform data
  PCI: tegra: Remove unused platform data
  PCI: tegra: Add local struct device pointers
  PCI: tegra: Fix argument order in tegra_pcie_phy_disable()
  PCI: rockchip: Remove unused platform data
  PCI: rcar-gen2: Add local struct device pointers
  ...
parents 44dc8c9d 217c6d21
...@@ -9189,6 +9189,14 @@ S: Maintained ...@@ -9189,6 +9189,14 @@ S: Maintained
F: Documentation/devicetree/bindings/pci/versatile.txt F: Documentation/devicetree/bindings/pci/versatile.txt
F: drivers/pci/host/pci-versatile.c F: drivers/pci/host/pci-versatile.c
PCI DRIVER FOR ARMADA 8K
M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
L: linux-pci@vger.kernel.org
L: linux-arm-kernel@lists.infradead.org
S: Maintained
F: Documentation/devicetree/bindings/pci/pci-armada8k.txt
F: drivers/pci/host/pcie-armada8k.c
PCI DRIVER FOR APPLIEDMICRO XGENE PCI DRIVER FOR APPLIEDMICRO XGENE
M: Tanmay Inamdar <tinamdar@apm.com> M: Tanmay Inamdar <tinamdar@apm.com>
L: linux-pci@vger.kernel.org L: linux-pci@vger.kernel.org
...@@ -9235,6 +9243,7 @@ M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> ...@@ -9235,6 +9243,7 @@ M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
L: linux-pci@vger.kernel.org L: linux-pci@vger.kernel.org
L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
S: Maintained S: Maintained
F: Documentation/devicetree/bindings/pci/aardvark-pci.txt
F: drivers/pci/host/pci-aardvark.c F: drivers/pci/host/pci-aardvark.c
PCI DRIVER FOR NVIDIA TEGRA PCI DRIVER FOR NVIDIA TEGRA
......
...@@ -230,20 +230,20 @@ static int advk_pcie_link_up(struct advk_pcie *pcie) ...@@ -230,20 +230,20 @@ static int advk_pcie_link_up(struct advk_pcie *pcie)
static int advk_pcie_wait_for_link(struct advk_pcie *pcie) static int advk_pcie_wait_for_link(struct advk_pcie *pcie)
{ {
struct device *dev = &pcie->pdev->dev;
int retries; int retries;
/* check if the link is up or not */ /* check if the link is up or not */
for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) { for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) {
if (advk_pcie_link_up(pcie)) { if (advk_pcie_link_up(pcie)) {
dev_info(&pcie->pdev->dev, "link up\n"); dev_info(dev, "link up\n");
return 0; return 0;
} }
usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX); usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX);
} }
dev_err(&pcie->pdev->dev, "link never came up\n"); dev_err(dev, "link never came up\n");
return -ETIMEDOUT; return -ETIMEDOUT;
} }
...@@ -376,6 +376,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) ...@@ -376,6 +376,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
static void advk_pcie_check_pio_status(struct advk_pcie *pcie) static void advk_pcie_check_pio_status(struct advk_pcie *pcie)
{ {
struct device *dev = &pcie->pdev->dev;
u32 reg; u32 reg;
unsigned int status; unsigned int status;
char *strcomp_status, *str_posted; char *strcomp_status, *str_posted;
...@@ -407,12 +408,13 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie) ...@@ -407,12 +408,13 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie)
else else
str_posted = "Posted"; str_posted = "Posted";
dev_err(&pcie->pdev->dev, "%s PIO Response Status: %s, %#x @ %#x\n", dev_err(dev, "%s PIO Response Status: %s, %#x @ %#x\n",
str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS)); str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS));
} }
static int advk_pcie_wait_pio(struct advk_pcie *pcie) static int advk_pcie_wait_pio(struct advk_pcie *pcie)
{ {
struct device *dev = &pcie->pdev->dev;
unsigned long timeout; unsigned long timeout;
timeout = jiffies + msecs_to_jiffies(PIO_TIMEOUT_MS); timeout = jiffies + msecs_to_jiffies(PIO_TIMEOUT_MS);
...@@ -426,7 +428,7 @@ static int advk_pcie_wait_pio(struct advk_pcie *pcie) ...@@ -426,7 +428,7 @@ static int advk_pcie_wait_pio(struct advk_pcie *pcie)
return 0; return 0;
} }
dev_err(&pcie->pdev->dev, "config read/write timed out\n"); dev_err(dev, "config read/write timed out\n");
return -ETIMEDOUT; return -ETIMEDOUT;
} }
...@@ -560,10 +562,11 @@ static int advk_pcie_alloc_msi(struct advk_pcie *pcie) ...@@ -560,10 +562,11 @@ static int advk_pcie_alloc_msi(struct advk_pcie *pcie)
static void advk_pcie_free_msi(struct advk_pcie *pcie, int hwirq) static void advk_pcie_free_msi(struct advk_pcie *pcie, int hwirq)
{ {
struct device *dev = &pcie->pdev->dev;
mutex_lock(&pcie->msi_used_lock); mutex_lock(&pcie->msi_used_lock);
if (!test_bit(hwirq, pcie->msi_irq_in_use)) if (!test_bit(hwirq, pcie->msi_irq_in_use))
dev_err(&pcie->pdev->dev, "trying to free unused MSI#%d\n", dev_err(dev, "trying to free unused MSI#%d\n", hwirq);
hwirq);
else else
clear_bit(hwirq, pcie->msi_irq_in_use); clear_bit(hwirq, pcie->msi_irq_in_use);
mutex_unlock(&pcie->msi_used_lock); mutex_unlock(&pcie->msi_used_lock);
...@@ -910,6 +913,7 @@ static int advk_pcie_parse_request_of_pci_ranges(struct advk_pcie *pcie) ...@@ -910,6 +913,7 @@ static int advk_pcie_parse_request_of_pci_ranges(struct advk_pcie *pcie)
static int advk_pcie_probe(struct platform_device *pdev) static int advk_pcie_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct advk_pcie *pcie; struct advk_pcie *pcie;
struct resource *res; struct resource *res;
struct pci_bus *bus, *child; struct pci_bus *bus, *child;
...@@ -917,31 +921,29 @@ static int advk_pcie_probe(struct platform_device *pdev) ...@@ -917,31 +921,29 @@ static int advk_pcie_probe(struct platform_device *pdev)
struct device_node *msi_node; struct device_node *msi_node;
int ret, irq; int ret, irq;
pcie = devm_kzalloc(&pdev->dev, sizeof(struct advk_pcie), pcie = devm_kzalloc(dev, sizeof(struct advk_pcie), GFP_KERNEL);
GFP_KERNEL);
if (!pcie) if (!pcie)
return -ENOMEM; return -ENOMEM;
pcie->pdev = pdev; pcie->pdev = pdev;
platform_set_drvdata(pdev, pcie);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pcie->base = devm_ioremap_resource(&pdev->dev, res); pcie->base = devm_ioremap_resource(dev, res);
if (IS_ERR(pcie->base)) if (IS_ERR(pcie->base))
return PTR_ERR(pcie->base); return PTR_ERR(pcie->base);
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
ret = devm_request_irq(&pdev->dev, irq, advk_pcie_irq_handler, ret = devm_request_irq(dev, irq, advk_pcie_irq_handler,
IRQF_SHARED | IRQF_NO_THREAD, "advk-pcie", IRQF_SHARED | IRQF_NO_THREAD, "advk-pcie",
pcie); pcie);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to register interrupt\n"); dev_err(dev, "Failed to register interrupt\n");
return ret; return ret;
} }
ret = advk_pcie_parse_request_of_pci_ranges(pcie); ret = advk_pcie_parse_request_of_pci_ranges(pcie);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to parse resources\n"); dev_err(dev, "Failed to parse resources\n");
return ret; return ret;
} }
...@@ -949,24 +951,24 @@ static int advk_pcie_probe(struct platform_device *pdev) ...@@ -949,24 +951,24 @@ static int advk_pcie_probe(struct platform_device *pdev)
ret = advk_pcie_init_irq_domain(pcie); ret = advk_pcie_init_irq_domain(pcie);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to initialize irq\n"); dev_err(dev, "Failed to initialize irq\n");
return ret; return ret;
} }
ret = advk_pcie_init_msi_irq_domain(pcie); ret = advk_pcie_init_msi_irq_domain(pcie);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to initialize irq\n"); dev_err(dev, "Failed to initialize irq\n");
advk_pcie_remove_irq_domain(pcie); advk_pcie_remove_irq_domain(pcie);
return ret; return ret;
} }
msi_node = of_parse_phandle(pdev->dev.of_node, "msi-parent", 0); msi_node = of_parse_phandle(dev->of_node, "msi-parent", 0);
if (msi_node) if (msi_node)
msi = of_pci_find_msi_chip_by_node(msi_node); msi = of_pci_find_msi_chip_by_node(msi_node);
else else
msi = NULL; msi = NULL;
bus = pci_scan_root_bus_msi(&pdev->dev, 0, &advk_pcie_ops, bus = pci_scan_root_bus_msi(dev, 0, &advk_pcie_ops,
pcie, &pcie->resources, &pcie->msi); pcie, &pcie->resources, &pcie->msi);
if (!bus) { if (!bus) {
advk_pcie_remove_msi_irq_domain(pcie); advk_pcie_remove_msi_irq_domain(pcie);
...@@ -980,7 +982,6 @@ static int advk_pcie_probe(struct platform_device *pdev) ...@@ -980,7 +982,6 @@ static int advk_pcie_probe(struct platform_device *pdev)
pcie_bus_configure_settings(child); pcie_bus_configure_settings(child);
pci_bus_add_devices(bus); pci_bus_add_devices(bus);
return 0; return 0;
} }
......
...@@ -64,11 +64,10 @@ ...@@ -64,11 +64,10 @@
#define DRA7XX_CPU_TO_BUS_ADDR 0x0FFFFFFF #define DRA7XX_CPU_TO_BUS_ADDR 0x0FFFFFFF
struct dra7xx_pcie { struct dra7xx_pcie {
void __iomem *base;
struct phy **phy;
int phy_count;
struct device *dev;
struct pcie_port pp; struct pcie_port pp;
void __iomem *base; /* DT ti_conf */
int phy_count; /* DT phy-names count */
struct phy **phy;
}; };
#define to_dra7xx_pcie(x) container_of((x), struct dra7xx_pcie, pp) #define to_dra7xx_pcie(x) container_of((x), struct dra7xx_pcie, pp)
...@@ -84,17 +83,6 @@ static inline void dra7xx_pcie_writel(struct dra7xx_pcie *pcie, u32 offset, ...@@ -84,17 +83,6 @@ static inline void dra7xx_pcie_writel(struct dra7xx_pcie *pcie, u32 offset,
writel(value, pcie->base + offset); writel(value, pcie->base + offset);
} }
static inline u32 dra7xx_pcie_readl_rc(struct pcie_port *pp, u32 offset)
{
return readl(pp->dbi_base + offset);
}
static inline void dra7xx_pcie_writel_rc(struct pcie_port *pp, u32 offset,
u32 value)
{
writel(value, pp->dbi_base + offset);
}
static int dra7xx_pcie_link_up(struct pcie_port *pp) static int dra7xx_pcie_link_up(struct pcie_port *pp)
{ {
struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp); struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
...@@ -103,13 +91,14 @@ static int dra7xx_pcie_link_up(struct pcie_port *pp) ...@@ -103,13 +91,14 @@ static int dra7xx_pcie_link_up(struct pcie_port *pp)
return !!(reg & LINK_UP); return !!(reg & LINK_UP);
} }
static int dra7xx_pcie_establish_link(struct pcie_port *pp) static int dra7xx_pcie_establish_link(struct dra7xx_pcie *dra7xx)
{ {
struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp); struct pcie_port *pp = &dra7xx->pp;
struct device *dev = pp->dev;
u32 reg; u32 reg;
if (dw_pcie_link_up(pp)) { if (dw_pcie_link_up(pp)) {
dev_err(pp->dev, "link is already up\n"); dev_err(dev, "link is already up\n");
return 0; return 0;
} }
...@@ -120,10 +109,8 @@ static int dra7xx_pcie_establish_link(struct pcie_port *pp) ...@@ -120,10 +109,8 @@ static int dra7xx_pcie_establish_link(struct pcie_port *pp)
return dw_pcie_wait_for_link(pp); return dw_pcie_wait_for_link(pp);
} }
static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp) static void dra7xx_pcie_enable_interrupts(struct dra7xx_pcie *dra7xx)
{ {
struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN, dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN,
~INTERRUPTS); ~INTERRUPTS);
dra7xx_pcie_writel(dra7xx, dra7xx_pcie_writel(dra7xx,
...@@ -142,6 +129,8 @@ static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp) ...@@ -142,6 +129,8 @@ static void dra7xx_pcie_enable_interrupts(struct pcie_port *pp)
static void dra7xx_pcie_host_init(struct pcie_port *pp) static void dra7xx_pcie_host_init(struct pcie_port *pp)
{ {
struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp);
pp->io_base &= DRA7XX_CPU_TO_BUS_ADDR; pp->io_base &= DRA7XX_CPU_TO_BUS_ADDR;
pp->mem_base &= DRA7XX_CPU_TO_BUS_ADDR; pp->mem_base &= DRA7XX_CPU_TO_BUS_ADDR;
pp->cfg0_base &= DRA7XX_CPU_TO_BUS_ADDR; pp->cfg0_base &= DRA7XX_CPU_TO_BUS_ADDR;
...@@ -149,10 +138,10 @@ static void dra7xx_pcie_host_init(struct pcie_port *pp) ...@@ -149,10 +138,10 @@ static void dra7xx_pcie_host_init(struct pcie_port *pp)
dw_pcie_setup_rc(pp); dw_pcie_setup_rc(pp);
dra7xx_pcie_establish_link(pp); dra7xx_pcie_establish_link(dra7xx);
if (IS_ENABLED(CONFIG_PCI_MSI)) if (IS_ENABLED(CONFIG_PCI_MSI))
dw_pcie_msi_init(pp); dw_pcie_msi_init(pp);
dra7xx_pcie_enable_interrupts(pp); dra7xx_pcie_enable_interrupts(dra7xx);
} }
static struct pcie_host_ops dra7xx_pcie_host_ops = { static struct pcie_host_ops dra7xx_pcie_host_ops = {
...@@ -196,8 +185,8 @@ static int dra7xx_pcie_init_irq_domain(struct pcie_port *pp) ...@@ -196,8 +185,8 @@ static int dra7xx_pcie_init_irq_domain(struct pcie_port *pp)
static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg) static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg)
{ {
struct pcie_port *pp = arg; struct dra7xx_pcie *dra7xx = arg;
struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pp); struct pcie_port *pp = &dra7xx->pp;
u32 reg; u32 reg;
reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI); reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MSI);
...@@ -223,51 +212,51 @@ static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg) ...@@ -223,51 +212,51 @@ static irqreturn_t dra7xx_pcie_msi_irq_handler(int irq, void *arg)
static irqreturn_t dra7xx_pcie_irq_handler(int irq, void *arg) static irqreturn_t dra7xx_pcie_irq_handler(int irq, void *arg)
{ {
struct dra7xx_pcie *dra7xx = arg; struct dra7xx_pcie *dra7xx = arg;
struct device *dev = dra7xx->pp.dev;
u32 reg; u32 reg;
reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN); reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN);
if (reg & ERR_SYS) if (reg & ERR_SYS)
dev_dbg(dra7xx->dev, "System Error\n"); dev_dbg(dev, "System Error\n");
if (reg & ERR_FATAL) if (reg & ERR_FATAL)
dev_dbg(dra7xx->dev, "Fatal Error\n"); dev_dbg(dev, "Fatal Error\n");
if (reg & ERR_NONFATAL) if (reg & ERR_NONFATAL)
dev_dbg(dra7xx->dev, "Non Fatal Error\n"); dev_dbg(dev, "Non Fatal Error\n");
if (reg & ERR_COR) if (reg & ERR_COR)
dev_dbg(dra7xx->dev, "Correctable Error\n"); dev_dbg(dev, "Correctable Error\n");
if (reg & ERR_AXI) if (reg & ERR_AXI)
dev_dbg(dra7xx->dev, "AXI tag lookup fatal Error\n"); dev_dbg(dev, "AXI tag lookup fatal Error\n");
if (reg & ERR_ECRC) if (reg & ERR_ECRC)
dev_dbg(dra7xx->dev, "ECRC Error\n"); dev_dbg(dev, "ECRC Error\n");
if (reg & PME_TURN_OFF) if (reg & PME_TURN_OFF)
dev_dbg(dra7xx->dev, dev_dbg(dev,
"Power Management Event Turn-Off message received\n"); "Power Management Event Turn-Off message received\n");
if (reg & PME_TO_ACK) if (reg & PME_TO_ACK)
dev_dbg(dra7xx->dev, dev_dbg(dev,
"Power Management Turn-Off Ack message received\n"); "Power Management Turn-Off Ack message received\n");
if (reg & PM_PME) if (reg & PM_PME)
dev_dbg(dra7xx->dev, dev_dbg(dev, "PM Power Management Event message received\n");
"PM Power Management Event message received\n");
if (reg & LINK_REQ_RST) if (reg & LINK_REQ_RST)
dev_dbg(dra7xx->dev, "Link Request Reset\n"); dev_dbg(dev, "Link Request Reset\n");
if (reg & LINK_UP_EVT) if (reg & LINK_UP_EVT)
dev_dbg(dra7xx->dev, "Link-up state change\n"); dev_dbg(dev, "Link-up state change\n");
if (reg & CFG_BME_EVT) if (reg & CFG_BME_EVT)
dev_dbg(dra7xx->dev, "CFG 'Bus Master Enable' change\n"); dev_dbg(dev, "CFG 'Bus Master Enable' change\n");
if (reg & CFG_MSE_EVT) if (reg & CFG_MSE_EVT)
dev_dbg(dra7xx->dev, "CFG 'Memory Space Enable' change\n"); dev_dbg(dev, "CFG 'Memory Space Enable' change\n");
dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN, reg); dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_IRQSTATUS_MAIN, reg);
...@@ -278,13 +267,9 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx, ...@@ -278,13 +267,9 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
struct platform_device *pdev) struct platform_device *pdev)
{ {
int ret; int ret;
struct pcie_port *pp; struct pcie_port *pp = &dra7xx->pp;
struct device *dev = pp->dev;
struct resource *res; struct resource *res;
struct device *dev = &pdev->dev;
pp = &dra7xx->pp;
pp->dev = dev;
pp->ops = &dra7xx_pcie_host_ops;
pp->irq = platform_get_irq(pdev, 1); pp->irq = platform_get_irq(pdev, 1);
if (pp->irq < 0) { if (pp->irq < 0) {
...@@ -292,12 +277,11 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx, ...@@ -292,12 +277,11 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
return -EINVAL; return -EINVAL;
} }
ret = devm_request_irq(&pdev->dev, pp->irq, ret = devm_request_irq(dev, pp->irq, dra7xx_pcie_msi_irq_handler,
dra7xx_pcie_msi_irq_handler,
IRQF_SHARED | IRQF_NO_THREAD, IRQF_SHARED | IRQF_NO_THREAD,
"dra7-pcie-msi", pp); "dra7-pcie-msi", dra7xx);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to request irq\n"); dev_err(dev, "failed to request irq\n");
return ret; return ret;
} }
...@@ -314,7 +298,7 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx, ...@@ -314,7 +298,7 @@ static int __init dra7xx_add_pcie_port(struct dra7xx_pcie *dra7xx,
ret = dw_pcie_host_init(pp); ret = dw_pcie_host_init(pp);
if (ret) { if (ret) {
dev_err(dra7xx->dev, "failed to initialize host\n"); dev_err(dev, "failed to initialize host\n");
return ret; return ret;
} }
...@@ -332,6 +316,7 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) ...@@ -332,6 +316,7 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
void __iomem *base; void __iomem *base;
struct resource *res; struct resource *res;
struct dra7xx_pcie *dra7xx; struct dra7xx_pcie *dra7xx;
struct pcie_port *pp;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
char name[10]; char name[10];
...@@ -343,6 +328,10 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) ...@@ -343,6 +328,10 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
if (!dra7xx) if (!dra7xx)
return -ENOMEM; return -ENOMEM;
pp = &dra7xx->pp;
pp->dev = dev;
pp->ops = &dra7xx_pcie_host_ops;
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
dev_err(dev, "missing IRQ resource\n"); dev_err(dev, "missing IRQ resource\n");
...@@ -390,7 +379,6 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) ...@@ -390,7 +379,6 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
dra7xx->base = base; dra7xx->base = base;
dra7xx->phy = phy; dra7xx->phy = phy;
dra7xx->dev = dev;
dra7xx->phy_count = phy_count; dra7xx->phy_count = phy_count;
pm_runtime_enable(dev); pm_runtime_enable(dev);
...@@ -407,7 +395,7 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) ...@@ -407,7 +395,7 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
ret = devm_gpio_request_one(dev, gpio_sel, gpio_flags, ret = devm_gpio_request_one(dev, gpio_sel, gpio_flags,
"pcie_reset"); "pcie_reset");
if (ret) { if (ret) {
dev_err(&pdev->dev, "gpio%d request failed, ret %d\n", dev_err(dev, "gpio%d request failed, ret %d\n",
gpio_sel, ret); gpio_sel, ret);
goto err_gpio; goto err_gpio;
} }
...@@ -420,12 +408,11 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev) ...@@ -420,12 +408,11 @@ static int __init dra7xx_pcie_probe(struct platform_device *pdev)
reg &= ~LTSSM_EN; reg &= ~LTSSM_EN;
dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg); dra7xx_pcie_writel(dra7xx, PCIECTRL_DRA7XX_CONF_DEVICE_CMD, reg);
platform_set_drvdata(pdev, dra7xx);
ret = dra7xx_add_pcie_port(dra7xx, pdev); ret = dra7xx_add_pcie_port(dra7xx, pdev);
if (ret < 0) if (ret < 0)
goto err_gpio; goto err_gpio;
platform_set_drvdata(pdev, dra7xx);
return 0; return 0;
err_gpio: err_gpio:
...@@ -451,9 +438,9 @@ static int dra7xx_pcie_suspend(struct device *dev) ...@@ -451,9 +438,9 @@ static int dra7xx_pcie_suspend(struct device *dev)
u32 val; u32 val;
/* clear MSE */ /* clear MSE */
val = dra7xx_pcie_readl_rc(pp, PCI_COMMAND); val = dw_pcie_readl_rc(pp, PCI_COMMAND);
val &= ~PCI_COMMAND_MEMORY; val &= ~PCI_COMMAND_MEMORY;
dra7xx_pcie_writel_rc(pp, PCI_COMMAND, val); dw_pcie_writel_rc(pp, PCI_COMMAND, val);
return 0; return 0;
} }
...@@ -465,9 +452,9 @@ static int dra7xx_pcie_resume(struct device *dev) ...@@ -465,9 +452,9 @@ static int dra7xx_pcie_resume(struct device *dev)
u32 val; u32 val;
/* set MSE */ /* set MSE */
val = dra7xx_pcie_readl_rc(pp, PCI_COMMAND); val = dw_pcie_readl_rc(pp, PCI_COMMAND);
val |= PCI_COMMAND_MEMORY; val |= PCI_COMMAND_MEMORY;
dra7xx_pcie_writel_rc(pp, PCI_COMMAND, val); dw_pcie_writel_rc(pp, PCI_COMMAND, val);
return 0; return 0;
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -89,12 +89,13 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, quirk_limit_mrrs); ...@@ -89,12 +89,13 @@ DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, quirk_limit_mrrs);
static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie) static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie)
{ {
struct pcie_port *pp = &ks_pcie->pp; struct pcie_port *pp = &ks_pcie->pp;
struct device *dev = pp->dev;
unsigned int retries; unsigned int retries;
dw_pcie_setup_rc(pp); dw_pcie_setup_rc(pp);
if (dw_pcie_link_up(pp)) { if (dw_pcie_link_up(pp)) {
dev_err(pp->dev, "Link already up\n"); dev_err(dev, "Link already up\n");
return 0; return 0;
} }
...@@ -105,7 +106,7 @@ static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie) ...@@ -105,7 +106,7 @@ static int ks_pcie_establish_link(struct keystone_pcie *ks_pcie)
return 0; return 0;
} }
dev_err(pp->dev, "phy link never came up\n"); dev_err(dev, "phy link never came up\n");
return -ETIMEDOUT; return -ETIMEDOUT;
} }
...@@ -115,9 +116,10 @@ static void ks_pcie_msi_irq_handler(struct irq_desc *desc) ...@@ -115,9 +116,10 @@ static void ks_pcie_msi_irq_handler(struct irq_desc *desc)
struct keystone_pcie *ks_pcie = irq_desc_get_handler_data(desc); struct keystone_pcie *ks_pcie = irq_desc_get_handler_data(desc);
u32 offset = irq - ks_pcie->msi_host_irqs[0]; u32 offset = irq - ks_pcie->msi_host_irqs[0];
struct pcie_port *pp = &ks_pcie->pp; struct pcie_port *pp = &ks_pcie->pp;
struct device *dev = pp->dev;
struct irq_chip *chip = irq_desc_get_chip(desc); struct irq_chip *chip = irq_desc_get_chip(desc);
dev_dbg(pp->dev, "%s, irq %d\n", __func__, irq); dev_dbg(dev, "%s, irq %d\n", __func__, irq);
/* /*
* The chained irq handler installation would have replaced normal * The chained irq handler installation would have replaced normal
...@@ -142,10 +144,11 @@ static void ks_pcie_legacy_irq_handler(struct irq_desc *desc) ...@@ -142,10 +144,11 @@ static void ks_pcie_legacy_irq_handler(struct irq_desc *desc)
unsigned int irq = irq_desc_get_irq(desc); unsigned int irq = irq_desc_get_irq(desc);
struct keystone_pcie *ks_pcie = irq_desc_get_handler_data(desc); struct keystone_pcie *ks_pcie = irq_desc_get_handler_data(desc);
struct pcie_port *pp = &ks_pcie->pp; struct pcie_port *pp = &ks_pcie->pp;
struct device *dev = pp->dev;
u32 irq_offset = irq - ks_pcie->legacy_host_irqs[0]; u32 irq_offset = irq - ks_pcie->legacy_host_irqs[0];
struct irq_chip *chip = irq_desc_get_chip(desc); struct irq_chip *chip = irq_desc_get_chip(desc);
dev_dbg(pp->dev, ": Handling legacy irq %d\n", irq); dev_dbg(dev, ": Handling legacy irq %d\n", irq);
/* /*
* The chained irq handler installation would have replaced normal * The chained irq handler installation would have replaced normal
...@@ -234,7 +237,7 @@ static void ks_pcie_setup_interrupts(struct keystone_pcie *ks_pcie) ...@@ -234,7 +237,7 @@ static void ks_pcie_setup_interrupts(struct keystone_pcie *ks_pcie)
} }
if (ks_pcie->error_irq > 0) if (ks_pcie->error_irq > 0)
ks_dw_pcie_enable_error_irq(ks_pcie->va_app_base); ks_dw_pcie_enable_error_irq(ks_pcie);
} }
/* /*
...@@ -302,14 +305,14 @@ static irqreturn_t pcie_err_irq_handler(int irq, void *priv) ...@@ -302,14 +305,14 @@ static irqreturn_t pcie_err_irq_handler(int irq, void *priv)
{ {
struct keystone_pcie *ks_pcie = priv; struct keystone_pcie *ks_pcie = priv;
return ks_dw_pcie_handle_error_irq(ks_pcie->pp.dev, return ks_dw_pcie_handle_error_irq(ks_pcie);
ks_pcie->va_app_base);
} }
static int __init ks_add_pcie_port(struct keystone_pcie *ks_pcie, static int __init ks_add_pcie_port(struct keystone_pcie *ks_pcie,
struct platform_device *pdev) struct platform_device *pdev)
{ {
struct pcie_port *pp = &ks_pcie->pp; struct pcie_port *pp = &ks_pcie->pp;
struct device *dev = pp->dev;
int ret; int ret;
ret = ks_pcie_get_irq_controller_info(ks_pcie, ret = ks_pcie_get_irq_controller_info(ks_pcie,
...@@ -332,12 +335,12 @@ static int __init ks_add_pcie_port(struct keystone_pcie *ks_pcie, ...@@ -332,12 +335,12 @@ static int __init ks_add_pcie_port(struct keystone_pcie *ks_pcie,
*/ */
ks_pcie->error_irq = irq_of_parse_and_map(ks_pcie->np, 0); ks_pcie->error_irq = irq_of_parse_and_map(ks_pcie->np, 0);
if (ks_pcie->error_irq <= 0) if (ks_pcie->error_irq <= 0)
dev_info(&pdev->dev, "no error IRQ defined\n"); dev_info(dev, "no error IRQ defined\n");
else { else {
ret = request_irq(ks_pcie->error_irq, pcie_err_irq_handler, ret = request_irq(ks_pcie->error_irq, pcie_err_irq_handler,
IRQF_SHARED, "pcie-error-irq", ks_pcie); IRQF_SHARED, "pcie-error-irq", ks_pcie);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to request error IRQ %d\n", dev_err(dev, "failed to request error IRQ %d\n",
ks_pcie->error_irq); ks_pcie->error_irq);
return ret; return ret;
} }
...@@ -347,7 +350,7 @@ static int __init ks_add_pcie_port(struct keystone_pcie *ks_pcie, ...@@ -347,7 +350,7 @@ static int __init ks_add_pcie_port(struct keystone_pcie *ks_pcie,
pp->ops = &keystone_pcie_host_ops; pp->ops = &keystone_pcie_host_ops;
ret = ks_dw_pcie_host_init(ks_pcie, ks_pcie->msi_intc_np); ret = ks_dw_pcie_host_init(ks_pcie, ks_pcie->msi_intc_np);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize host\n"); dev_err(dev, "failed to initialize host\n");
return ret; return ret;
} }
...@@ -381,12 +384,12 @@ static int __init ks_pcie_probe(struct platform_device *pdev) ...@@ -381,12 +384,12 @@ static int __init ks_pcie_probe(struct platform_device *pdev)
struct phy *phy; struct phy *phy;
int ret; int ret;
ks_pcie = devm_kzalloc(&pdev->dev, sizeof(*ks_pcie), ks_pcie = devm_kzalloc(dev, sizeof(*ks_pcie), GFP_KERNEL);
GFP_KERNEL);
if (!ks_pcie) if (!ks_pcie)
return -ENOMEM; return -ENOMEM;
pp = &ks_pcie->pp; pp = &ks_pcie->pp;
pp->dev = dev;
/* initialize SerDes Phy if present */ /* initialize SerDes Phy if present */
phy = devm_phy_get(dev, "pcie-phy"); phy = devm_phy_get(dev, "pcie-phy");
...@@ -408,7 +411,6 @@ static int __init ks_pcie_probe(struct platform_device *pdev) ...@@ -408,7 +411,6 @@ static int __init ks_pcie_probe(struct platform_device *pdev)
devm_iounmap(dev, reg_p); devm_iounmap(dev, reg_p);
devm_release_mem_region(dev, res->start, resource_size(res)); devm_release_mem_region(dev, res->start, resource_size(res));
pp->dev = dev;
ks_pcie->np = dev->of_node; ks_pcie->np = dev->of_node;
platform_set_drvdata(pdev, ks_pcie); platform_set_drvdata(pdev, ks_pcie);
ks_pcie->clk = devm_clk_get(dev, "pcie"); ks_pcie->clk = devm_clk_get(dev, "pcie");
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#define MAX_LEGACY_HOST_IRQS 4 #define MAX_LEGACY_HOST_IRQS 4
struct keystone_pcie { struct keystone_pcie {
struct pcie_port pp; /* pp.dbi_base is DT 0th res */
struct clk *clk; struct clk *clk;
struct pcie_port pp;
/* PCI Device ID */ /* PCI Device ID */
u32 device_id; u32 device_id;
int num_legacy_host_irqs; int num_legacy_host_irqs;
...@@ -34,7 +34,7 @@ struct keystone_pcie { ...@@ -34,7 +34,7 @@ struct keystone_pcie {
int error_irq; int error_irq;
/* Application register space */ /* Application register space */
void __iomem *va_app_base; void __iomem *va_app_base; /* DT 1st resource */
struct resource app; struct resource app;
}; };
...@@ -45,9 +45,8 @@ phys_addr_t ks_dw_pcie_get_msi_addr(struct pcie_port *pp); ...@@ -45,9 +45,8 @@ phys_addr_t ks_dw_pcie_get_msi_addr(struct pcie_port *pp);
/* Keystone specific PCI controller APIs */ /* Keystone specific PCI controller APIs */
void ks_dw_pcie_enable_legacy_irqs(struct keystone_pcie *ks_pcie); void ks_dw_pcie_enable_legacy_irqs(struct keystone_pcie *ks_pcie);
void ks_dw_pcie_handle_legacy_irq(struct keystone_pcie *ks_pcie, int offset); void ks_dw_pcie_handle_legacy_irq(struct keystone_pcie *ks_pcie, int offset);
void ks_dw_pcie_enable_error_irq(void __iomem *reg_base); void ks_dw_pcie_enable_error_irq(struct keystone_pcie *ks_pcie);
irqreturn_t ks_dw_pcie_handle_error_irq(struct device *dev, irqreturn_t ks_dw_pcie_handle_error_irq(struct keystone_pcie *ks_pcie);
void __iomem *reg_base);
int ks_dw_pcie_host_init(struct keystone_pcie *ks_pcie, int ks_dw_pcie_host_init(struct keystone_pcie *ks_pcie,
struct device_node *msi_intc_np); struct device_node *msi_intc_np);
int ks_dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus, int ks_dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
......
...@@ -45,10 +45,9 @@ struct ls_pcie_drvdata { ...@@ -45,10 +45,9 @@ struct ls_pcie_drvdata {
}; };
struct ls_pcie { struct ls_pcie {
void __iomem *dbi; struct pcie_port pp; /* pp.dbi_base is DT regs */
void __iomem *lut; void __iomem *lut;
struct regmap *scfg; struct regmap *scfg;
struct pcie_port pp;
const struct ls_pcie_drvdata *drvdata; const struct ls_pcie_drvdata *drvdata;
int index; int index;
}; };
...@@ -59,7 +58,7 @@ static bool ls_pcie_is_bridge(struct ls_pcie *pcie) ...@@ -59,7 +58,7 @@ static bool ls_pcie_is_bridge(struct ls_pcie *pcie)
{ {
u32 header_type; u32 header_type;
header_type = ioread8(pcie->dbi + PCI_HEADER_TYPE); header_type = ioread8(pcie->pp.dbi_base + PCI_HEADER_TYPE);
header_type &= 0x7f; header_type &= 0x7f;
return header_type == PCI_HEADER_TYPE_BRIDGE; return header_type == PCI_HEADER_TYPE_BRIDGE;
...@@ -68,13 +67,13 @@ static bool ls_pcie_is_bridge(struct ls_pcie *pcie) ...@@ -68,13 +67,13 @@ static bool ls_pcie_is_bridge(struct ls_pcie *pcie)
/* Clear multi-function bit */ /* Clear multi-function bit */
static void ls_pcie_clear_multifunction(struct ls_pcie *pcie) static void ls_pcie_clear_multifunction(struct ls_pcie *pcie)
{ {
iowrite8(PCI_HEADER_TYPE_BRIDGE, pcie->dbi + PCI_HEADER_TYPE); iowrite8(PCI_HEADER_TYPE_BRIDGE, pcie->pp.dbi_base + PCI_HEADER_TYPE);
} }
/* Fix class value */ /* Fix class value */
static void ls_pcie_fix_class(struct ls_pcie *pcie) static void ls_pcie_fix_class(struct ls_pcie *pcie)
{ {
iowrite16(PCI_CLASS_BRIDGE_PCI, pcie->dbi + PCI_CLASS_DEVICE); iowrite16(PCI_CLASS_BRIDGE_PCI, pcie->pp.dbi_base + PCI_CLASS_DEVICE);
} }
/* Drop MSG TLP except for Vendor MSG */ /* Drop MSG TLP except for Vendor MSG */
...@@ -82,9 +81,9 @@ static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie) ...@@ -82,9 +81,9 @@ static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie)
{ {
u32 val; u32 val;
val = ioread32(pcie->dbi + PCIE_STRFMR1); val = ioread32(pcie->pp.dbi_base + PCIE_STRFMR1);
val &= 0xDFFFFFFF; val &= 0xDFFFFFFF;
iowrite32(val, pcie->dbi + PCIE_STRFMR1); iowrite32(val, pcie->pp.dbi_base + PCIE_STRFMR1);
} }
static int ls1021_pcie_link_up(struct pcie_port *pp) static int ls1021_pcie_link_up(struct pcie_port *pp)
...@@ -106,18 +105,19 @@ static int ls1021_pcie_link_up(struct pcie_port *pp) ...@@ -106,18 +105,19 @@ static int ls1021_pcie_link_up(struct pcie_port *pp)
static void ls1021_pcie_host_init(struct pcie_port *pp) static void ls1021_pcie_host_init(struct pcie_port *pp)
{ {
struct device *dev = pp->dev;
struct ls_pcie *pcie = to_ls_pcie(pp); struct ls_pcie *pcie = to_ls_pcie(pp);
u32 index[2]; u32 index[2];
pcie->scfg = syscon_regmap_lookup_by_phandle(pp->dev->of_node, pcie->scfg = syscon_regmap_lookup_by_phandle(dev->of_node,
"fsl,pcie-scfg"); "fsl,pcie-scfg");
if (IS_ERR(pcie->scfg)) { if (IS_ERR(pcie->scfg)) {
dev_err(pp->dev, "No syscfg phandle specified\n"); dev_err(dev, "No syscfg phandle specified\n");
pcie->scfg = NULL; pcie->scfg = NULL;
return; return;
} }
if (of_property_read_u32_array(pp->dev->of_node, if (of_property_read_u32_array(dev->of_node,
"fsl,pcie-scfg", index, 2)) { "fsl,pcie-scfg", index, 2)) {
pcie->scfg = NULL; pcie->scfg = NULL;
return; return;
...@@ -148,18 +148,19 @@ static void ls_pcie_host_init(struct pcie_port *pp) ...@@ -148,18 +148,19 @@ static void ls_pcie_host_init(struct pcie_port *pp)
{ {
struct ls_pcie *pcie = to_ls_pcie(pp); struct ls_pcie *pcie = to_ls_pcie(pp);
iowrite32(1, pcie->dbi + PCIE_DBI_RO_WR_EN); iowrite32(1, pcie->pp.dbi_base + PCIE_DBI_RO_WR_EN);
ls_pcie_fix_class(pcie); ls_pcie_fix_class(pcie);
ls_pcie_clear_multifunction(pcie); ls_pcie_clear_multifunction(pcie);
ls_pcie_drop_msg_tlp(pcie); ls_pcie_drop_msg_tlp(pcie);
iowrite32(0, pcie->dbi + PCIE_DBI_RO_WR_EN); iowrite32(0, pcie->pp.dbi_base + PCIE_DBI_RO_WR_EN);
} }
static int ls_pcie_msi_host_init(struct pcie_port *pp, static int ls_pcie_msi_host_init(struct pcie_port *pp,
struct msi_controller *chip) struct msi_controller *chip)
{ {
struct device *dev = pp->dev;
struct device_node *np = dev->of_node;
struct device_node *msi_node; struct device_node *msi_node;
struct device_node *np = pp->dev->of_node;
/* /*
* The MSI domain is set by the generic of_msi_configure(). This * The MSI domain is set by the generic of_msi_configure(). This
...@@ -169,7 +170,7 @@ static int ls_pcie_msi_host_init(struct pcie_port *pp, ...@@ -169,7 +170,7 @@ static int ls_pcie_msi_host_init(struct pcie_port *pp,
*/ */
msi_node = of_parse_phandle(np, "msi-parent", 0); msi_node = of_parse_phandle(np, "msi-parent", 0);
if (!msi_node) { if (!msi_node) {
dev_err(pp->dev, "failed to find msi-parent\n"); dev_err(dev, "failed to find msi-parent\n");
return -EINVAL; return -EINVAL;
} }
...@@ -212,19 +213,15 @@ static const struct of_device_id ls_pcie_of_match[] = { ...@@ -212,19 +213,15 @@ static const struct of_device_id ls_pcie_of_match[] = {
{ }, { },
}; };
static int __init ls_add_pcie_port(struct pcie_port *pp, static int __init ls_add_pcie_port(struct ls_pcie *pcie)
struct platform_device *pdev)
{ {
struct pcie_port *pp = &pcie->pp;
struct device *dev = pp->dev;
int ret; int ret;
struct ls_pcie *pcie = to_ls_pcie(pp);
pp->dev = &pdev->dev;
pp->dbi_base = pcie->dbi;
pp->ops = pcie->drvdata->ops;
ret = dw_pcie_host_init(pp); ret = dw_pcie_host_init(pp);
if (ret) { if (ret) {
dev_err(pp->dev, "failed to initialize host\n"); dev_err(dev, "failed to initialize host\n");
return ret; return ret;
} }
...@@ -233,38 +230,42 @@ static int __init ls_add_pcie_port(struct pcie_port *pp, ...@@ -233,38 +230,42 @@ static int __init ls_add_pcie_port(struct pcie_port *pp,
static int __init ls_pcie_probe(struct platform_device *pdev) static int __init ls_pcie_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
const struct of_device_id *match; const struct of_device_id *match;
struct ls_pcie *pcie; struct ls_pcie *pcie;
struct pcie_port *pp;
struct resource *dbi_base; struct resource *dbi_base;
int ret; int ret;
match = of_match_device(ls_pcie_of_match, &pdev->dev); match = of_match_device(ls_pcie_of_match, dev);
if (!match) if (!match)
return -ENODEV; return -ENODEV;
pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL); pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
if (!pcie) if (!pcie)
return -ENOMEM; return -ENOMEM;
pp = &pcie->pp;
pp->dev = dev;
pp->ops = pcie->drvdata->ops;
dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
pcie->dbi = devm_ioremap_resource(&pdev->dev, dbi_base); pcie->pp.dbi_base = devm_ioremap_resource(dev, dbi_base);
if (IS_ERR(pcie->dbi)) { if (IS_ERR(pcie->pp.dbi_base)) {
dev_err(&pdev->dev, "missing *regs* space\n"); dev_err(dev, "missing *regs* space\n");
return PTR_ERR(pcie->dbi); return PTR_ERR(pcie->pp.dbi_base);
} }
pcie->drvdata = match->data; pcie->drvdata = match->data;
pcie->lut = pcie->dbi + pcie->drvdata->lut_offset; pcie->lut = pcie->pp.dbi_base + pcie->drvdata->lut_offset;
if (!ls_pcie_is_bridge(pcie)) if (!ls_pcie_is_bridge(pcie))
return -ENODEV; return -ENODEV;
ret = ls_add_pcie_port(&pcie->pp, pdev); ret = ls_add_pcie_port(pcie);
if (ret < 0) if (ret < 0)
return ret; return ret;
platform_set_drvdata(pdev, pcie);
return 0; return 0;
} }
......
...@@ -1190,13 +1190,13 @@ static void mvebu_pcie_powerdown(struct mvebu_pcie_port *port) ...@@ -1190,13 +1190,13 @@ static void mvebu_pcie_powerdown(struct mvebu_pcie_port *port)
static int mvebu_pcie_probe(struct platform_device *pdev) static int mvebu_pcie_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct mvebu_pcie *pcie; struct mvebu_pcie *pcie;
struct device_node *np = pdev->dev.of_node; struct device_node *np = dev->of_node;
struct device_node *child; struct device_node *child;
int num, i, ret; int num, i, ret;
pcie = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_pcie), pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
GFP_KERNEL);
if (!pcie) if (!pcie)
return -ENOMEM; return -ENOMEM;
...@@ -1206,7 +1206,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev) ...@@ -1206,7 +1206,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
/* Get the PCIe memory and I/O aperture */ /* Get the PCIe memory and I/O aperture */
mvebu_mbus_get_pcie_mem_aperture(&pcie->mem); mvebu_mbus_get_pcie_mem_aperture(&pcie->mem);
if (resource_size(&pcie->mem) == 0) { if (resource_size(&pcie->mem) == 0) {
dev_err(&pdev->dev, "invalid memory aperture size\n"); dev_err(dev, "invalid memory aperture size\n");
return -EINVAL; return -EINVAL;
} }
...@@ -1224,20 +1224,18 @@ static int mvebu_pcie_probe(struct platform_device *pdev) ...@@ -1224,20 +1224,18 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
/* Get the bus range */ /* Get the bus range */
ret = of_pci_parse_bus_range(np, &pcie->busn); ret = of_pci_parse_bus_range(np, &pcie->busn);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to parse bus-range property: %d\n", dev_err(dev, "failed to parse bus-range property: %d\n", ret);
ret);
return ret; return ret;
} }
num = of_get_available_child_count(pdev->dev.of_node); num = of_get_available_child_count(np);
pcie->ports = devm_kcalloc(&pdev->dev, num, sizeof(*pcie->ports), pcie->ports = devm_kcalloc(dev, num, sizeof(*pcie->ports), GFP_KERNEL);
GFP_KERNEL);
if (!pcie->ports) if (!pcie->ports)
return -ENOMEM; return -ENOMEM;
i = 0; i = 0;
for_each_available_child_of_node(pdev->dev.of_node, child) { for_each_available_child_of_node(np, child) {
struct mvebu_pcie_port *port = &pcie->ports[i]; struct mvebu_pcie_port *port = &pcie->ports[i];
ret = mvebu_pcie_parse_port(pcie, port, child); ret = mvebu_pcie_parse_port(pcie, port, child);
...@@ -1266,8 +1264,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev) ...@@ -1266,8 +1264,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
port->base = mvebu_pcie_map_registers(pdev, child, port); port->base = mvebu_pcie_map_registers(pdev, child, port);
if (IS_ERR(port->base)) { if (IS_ERR(port->base)) {
dev_err(&pdev->dev, "%s: cannot map registers\n", dev_err(dev, "%s: cannot map registers\n", port->name);
port->name);
port->base = NULL; port->base = NULL;
mvebu_pcie_powerdown(port); mvebu_pcie_powerdown(port);
continue; continue;
......
...@@ -154,10 +154,11 @@ static int rcar_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) ...@@ -154,10 +154,11 @@ static int rcar_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
static irqreturn_t rcar_pci_err_irq(int irq, void *pw) static irqreturn_t rcar_pci_err_irq(int irq, void *pw)
{ {
struct rcar_pci_priv *priv = pw; struct rcar_pci_priv *priv = pw;
struct device *dev = priv->dev;
u32 status = ioread32(priv->reg + RCAR_PCI_INT_STATUS_REG); u32 status = ioread32(priv->reg + RCAR_PCI_INT_STATUS_REG);
if (status & RCAR_PCI_INT_ALLERRORS) { if (status & RCAR_PCI_INT_ALLERRORS) {
dev_err(priv->dev, "error irq: status %08x\n", status); dev_err(dev, "error irq: status %08x\n", status);
/* clear the error(s) */ /* clear the error(s) */
iowrite32(status & RCAR_PCI_INT_ALLERRORS, iowrite32(status & RCAR_PCI_INT_ALLERRORS,
...@@ -170,13 +171,14 @@ static irqreturn_t rcar_pci_err_irq(int irq, void *pw) ...@@ -170,13 +171,14 @@ static irqreturn_t rcar_pci_err_irq(int irq, void *pw)
static void rcar_pci_setup_errirq(struct rcar_pci_priv *priv) static void rcar_pci_setup_errirq(struct rcar_pci_priv *priv)
{ {
struct device *dev = priv->dev;
int ret; int ret;
u32 val; u32 val;
ret = devm_request_irq(priv->dev, priv->irq, rcar_pci_err_irq, ret = devm_request_irq(dev, priv->irq, rcar_pci_err_irq,
IRQF_SHARED, "error irq", priv); IRQF_SHARED, "error irq", priv);
if (ret) { if (ret) {
dev_err(priv->dev, "cannot claim IRQ for error handling\n"); dev_err(dev, "cannot claim IRQ for error handling\n");
return; return;
} }
...@@ -192,15 +194,16 @@ static inline void rcar_pci_setup_errirq(struct rcar_pci_priv *priv) { } ...@@ -192,15 +194,16 @@ static inline void rcar_pci_setup_errirq(struct rcar_pci_priv *priv) { }
static int rcar_pci_setup(int nr, struct pci_sys_data *sys) static int rcar_pci_setup(int nr, struct pci_sys_data *sys)
{ {
struct rcar_pci_priv *priv = sys->private_data; struct rcar_pci_priv *priv = sys->private_data;
struct device *dev = priv->dev;
void __iomem *reg = priv->reg; void __iomem *reg = priv->reg;
u32 val; u32 val;
int ret; int ret;
pm_runtime_enable(priv->dev); pm_runtime_enable(dev);
pm_runtime_get_sync(priv->dev); pm_runtime_get_sync(dev);
val = ioread32(reg + RCAR_PCI_UNIT_REV_REG); val = ioread32(reg + RCAR_PCI_UNIT_REV_REG);
dev_info(priv->dev, "PCI: bus%u revision %x\n", sys->busnr, val); dev_info(dev, "PCI: bus%u revision %x\n", sys->busnr, val);
/* Disable Direct Power Down State and assert reset */ /* Disable Direct Power Down State and assert reset */
val = ioread32(reg + RCAR_USBCTR_REG) & ~RCAR_USBCTR_DIRPD; val = ioread32(reg + RCAR_USBCTR_REG) & ~RCAR_USBCTR_DIRPD;
...@@ -275,7 +278,7 @@ static int rcar_pci_setup(int nr, struct pci_sys_data *sys) ...@@ -275,7 +278,7 @@ static int rcar_pci_setup(int nr, struct pci_sys_data *sys)
/* Add PCI resources */ /* Add PCI resources */
pci_add_resource(&sys->resources, &priv->mem_res); pci_add_resource(&sys->resources, &priv->mem_res);
ret = devm_request_pci_bus_resources(priv->dev, &sys->resources); ret = devm_request_pci_bus_resources(dev, &sys->resources);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -311,6 +314,7 @@ static int pci_dma_range_parser_init(struct of_pci_range_parser *parser, ...@@ -311,6 +314,7 @@ static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci, static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci,
struct device_node *np) struct device_node *np)
{ {
struct device *dev = pci->dev;
struct of_pci_range range; struct of_pci_range range;
struct of_pci_range_parser parser; struct of_pci_range_parser parser;
int index = 0; int index = 0;
...@@ -331,14 +335,14 @@ static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci, ...@@ -331,14 +335,14 @@ static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci,
/* Catch HW limitations */ /* Catch HW limitations */
if (!(range.flags & IORESOURCE_PREFETCH)) { if (!(range.flags & IORESOURCE_PREFETCH)) {
dev_err(pci->dev, "window must be prefetchable\n"); dev_err(dev, "window must be prefetchable\n");
return -EINVAL; return -EINVAL;
} }
if (pci->window_addr) { if (pci->window_addr) {
u32 lowaddr = 1 << (ffs(pci->window_addr) - 1); u32 lowaddr = 1 << (ffs(pci->window_addr) - 1);
if (lowaddr < pci->window_size) { if (lowaddr < pci->window_size) {
dev_err(pci->dev, "invalid window size/addr\n"); dev_err(dev, "invalid window size/addr\n");
return -EINVAL; return -EINVAL;
} }
} }
...@@ -350,6 +354,7 @@ static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci, ...@@ -350,6 +354,7 @@ static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci,
static int rcar_pci_probe(struct platform_device *pdev) static int rcar_pci_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct resource *cfg_res, *mem_res; struct resource *cfg_res, *mem_res;
struct rcar_pci_priv *priv; struct rcar_pci_priv *priv;
void __iomem *reg; void __iomem *reg;
...@@ -357,7 +362,7 @@ static int rcar_pci_probe(struct platform_device *pdev) ...@@ -357,7 +362,7 @@ static int rcar_pci_probe(struct platform_device *pdev)
void *hw_private[1]; void *hw_private[1];
cfg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); cfg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
reg = devm_ioremap_resource(&pdev->dev, cfg_res); reg = devm_ioremap_resource(dev, cfg_res);
if (IS_ERR(reg)) if (IS_ERR(reg))
return PTR_ERR(reg); return PTR_ERR(reg);
...@@ -368,8 +373,7 @@ static int rcar_pci_probe(struct platform_device *pdev) ...@@ -368,8 +373,7 @@ static int rcar_pci_probe(struct platform_device *pdev)
if (mem_res->start & 0xFFFF) if (mem_res->start & 0xFFFF)
return -EINVAL; return -EINVAL;
priv = devm_kzalloc(&pdev->dev, priv = devm_kzalloc(dev, sizeof(struct rcar_pci_priv), GFP_KERNEL);
sizeof(struct rcar_pci_priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
...@@ -378,10 +382,10 @@ static int rcar_pci_probe(struct platform_device *pdev) ...@@ -378,10 +382,10 @@ static int rcar_pci_probe(struct platform_device *pdev)
priv->irq = platform_get_irq(pdev, 0); priv->irq = platform_get_irq(pdev, 0);
priv->reg = reg; priv->reg = reg;
priv->dev = &pdev->dev; priv->dev = dev;
if (priv->irq < 0) { if (priv->irq < 0) {
dev_err(&pdev->dev, "no valid irq found\n"); dev_err(dev, "no valid irq found\n");
return priv->irq; return priv->irq;
} }
...@@ -390,23 +394,23 @@ static int rcar_pci_probe(struct platform_device *pdev) ...@@ -390,23 +394,23 @@ static int rcar_pci_probe(struct platform_device *pdev)
priv->window_pci = 0x40000000; priv->window_pci = 0x40000000;
priv->window_size = SZ_1G; priv->window_size = SZ_1G;
if (pdev->dev.of_node) { if (dev->of_node) {
struct resource busnr; struct resource busnr;
int ret; int ret;
ret = of_pci_parse_bus_range(pdev->dev.of_node, &busnr); ret = of_pci_parse_bus_range(dev->of_node, &busnr);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to parse bus-range\n"); dev_err(dev, "failed to parse bus-range\n");
return ret; return ret;
} }
priv->busnr = busnr.start; priv->busnr = busnr.start;
if (busnr.end != busnr.start) if (busnr.end != busnr.start)
dev_warn(&pdev->dev, "only one bus number supported\n"); dev_warn(dev, "only one bus number supported\n");
ret = rcar_pci_parse_map_dma_ranges(priv, pdev->dev.of_node); ret = rcar_pci_parse_map_dma_ranges(priv, dev->of_node);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "failed to parse dma-range\n"); dev_err(dev, "failed to parse dma-range\n");
return ret; return ret;
} }
} else { } else {
...@@ -421,7 +425,7 @@ static int rcar_pci_probe(struct platform_device *pdev) ...@@ -421,7 +425,7 @@ static int rcar_pci_probe(struct platform_device *pdev)
hw.map_irq = rcar_pci_map_irq; hw.map_irq = rcar_pci_map_irq;
hw.ops = &rcar_pci_ops; hw.ops = &rcar_pci_ops;
hw.setup = rcar_pci_setup; hw.setup = rcar_pci_setup;
pci_common_init_dev(&pdev->dev, &hw); pci_common_init_dev(dev, &hw);
return 0; return 0;
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -55,15 +55,19 @@ ...@@ -55,15 +55,19 @@
#define TLP_PAYLOAD_SIZE 0x01 #define TLP_PAYLOAD_SIZE 0x01
#define TLP_READ_TAG 0x1d #define TLP_READ_TAG 0x1d
#define TLP_WRITE_TAG 0x10 #define TLP_WRITE_TAG 0x10
#define TLP_CFG_DW0(fmttype) (((fmttype) << 24) | TLP_PAYLOAD_SIZE) #define RP_DEVFN 0
#define TLP_CFG_DW1(reqid, tag, be) (((reqid) << 16) | (tag << 8) | (be)) #define TLP_REQ_ID(bus, devfn) (((bus) << 8) | (devfn))
#define TLP_CFG_DW0(pcie, bus) \
((((bus == pcie->root_bus_nr) ? TLP_FMTTYPE_CFGRD0 \
: TLP_FMTTYPE_CFGRD1) << 24) | \
TLP_PAYLOAD_SIZE)
#define TLP_CFG_DW1(pcie, tag, be) \
(((TLP_REQ_ID(pcie->root_bus_nr, RP_DEVFN)) << 16) | (tag << 8) | (be))
#define TLP_CFG_DW2(bus, devfn, offset) \ #define TLP_CFG_DW2(bus, devfn, offset) \
(((bus) << 24) | ((devfn) << 16) | (offset)) (((bus) << 24) | ((devfn) << 16) | (offset))
#define TLP_REQ_ID(bus, devfn) (((bus) << 8) | (devfn))
#define TLP_COMP_STATUS(s) (((s) >> 12) & 7) #define TLP_COMP_STATUS(s) (((s) >> 12) & 7)
#define TLP_HDR_SIZE 3 #define TLP_HDR_SIZE 3
#define TLP_LOOP 500 #define TLP_LOOP 500
#define RP_DEVFN 0
#define LINK_UP_TIMEOUT HZ #define LINK_UP_TIMEOUT HZ
#define LINK_RETRAIN_TIMEOUT HZ #define LINK_RETRAIN_TIMEOUT HZ
...@@ -74,7 +78,7 @@ ...@@ -74,7 +78,7 @@
struct altera_pcie { struct altera_pcie {
struct platform_device *pdev; struct platform_device *pdev;
void __iomem *cra_base; void __iomem *cra_base; /* DT Cra */
int irq; int irq;
u8 root_bus_nr; u8 root_bus_nr;
struct irq_domain *irq_domain; struct irq_domain *irq_domain;
...@@ -131,7 +135,7 @@ static void tlp_write_tx(struct altera_pcie *pcie, ...@@ -131,7 +135,7 @@ static void tlp_write_tx(struct altera_pcie *pcie,
cra_writel(pcie, tlp_rp_regdata->ctrl, RP_TX_CNTRL); cra_writel(pcie, tlp_rp_regdata->ctrl, RP_TX_CNTRL);
} }
static bool altera_pcie_valid_config(struct altera_pcie *pcie, static bool altera_pcie_valid_device(struct altera_pcie *pcie,
struct pci_bus *bus, int dev) struct pci_bus *bus, int dev)
{ {
/* If there is no link, then there is no device */ /* If there is no link, then there is no device */
...@@ -218,13 +222,8 @@ static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn, ...@@ -218,13 +222,8 @@ static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn,
{ {
u32 headers[TLP_HDR_SIZE]; u32 headers[TLP_HDR_SIZE];
if (bus == pcie->root_bus_nr) headers[0] = TLP_CFG_DW0(pcie, bus);
headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGRD0); headers[1] = TLP_CFG_DW1(pcie, TLP_READ_TAG, byte_en);
else
headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGRD1);
headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, RP_DEVFN),
TLP_READ_TAG, byte_en);
headers[2] = TLP_CFG_DW2(bus, devfn, where); headers[2] = TLP_CFG_DW2(bus, devfn, where);
tlp_write_packet(pcie, headers, 0, false); tlp_write_packet(pcie, headers, 0, false);
...@@ -238,13 +237,8 @@ static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn, ...@@ -238,13 +237,8 @@ static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn,
u32 headers[TLP_HDR_SIZE]; u32 headers[TLP_HDR_SIZE];
int ret; int ret;
if (bus == pcie->root_bus_nr) headers[0] = TLP_CFG_DW0(pcie, bus);
headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGWR0); headers[1] = TLP_CFG_DW1(pcie, TLP_WRITE_TAG, byte_en);
else
headers[0] = TLP_CFG_DW0(TLP_FMTTYPE_CFGWR1);
headers[1] = TLP_CFG_DW1(TLP_REQ_ID(pcie->root_bus_nr, RP_DEVFN),
TLP_WRITE_TAG, byte_en);
headers[2] = TLP_CFG_DW2(bus, devfn, where); headers[2] = TLP_CFG_DW2(bus, devfn, where);
/* check alignment to Qword */ /* check alignment to Qword */
...@@ -342,7 +336,7 @@ static int altera_pcie_cfg_read(struct pci_bus *bus, unsigned int devfn, ...@@ -342,7 +336,7 @@ static int altera_pcie_cfg_read(struct pci_bus *bus, unsigned int devfn,
if (altera_pcie_hide_rc_bar(bus, devfn, where)) if (altera_pcie_hide_rc_bar(bus, devfn, where))
return PCIBIOS_BAD_REGISTER_NUMBER; return PCIBIOS_BAD_REGISTER_NUMBER;
if (!altera_pcie_valid_config(pcie, bus, PCI_SLOT(devfn))) { if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn))) {
*value = 0xffffffff; *value = 0xffffffff;
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
} }
...@@ -359,7 +353,7 @@ static int altera_pcie_cfg_write(struct pci_bus *bus, unsigned int devfn, ...@@ -359,7 +353,7 @@ static int altera_pcie_cfg_write(struct pci_bus *bus, unsigned int devfn,
if (altera_pcie_hide_rc_bar(bus, devfn, where)) if (altera_pcie_hide_rc_bar(bus, devfn, where))
return PCIBIOS_BAD_REGISTER_NUMBER; return PCIBIOS_BAD_REGISTER_NUMBER;
if (!altera_pcie_valid_config(pcie, bus, PCI_SLOT(devfn))) if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn)))
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
return _altera_pcie_cfg_write(pcie, bus->number, devfn, where, size, return _altera_pcie_cfg_write(pcie, bus->number, devfn, where, size,
...@@ -394,6 +388,7 @@ static int altera_write_cap_word(struct altera_pcie *pcie, u8 busno, ...@@ -394,6 +388,7 @@ static int altera_write_cap_word(struct altera_pcie *pcie, u8 busno,
static void altera_wait_link_retrain(struct altera_pcie *pcie) static void altera_wait_link_retrain(struct altera_pcie *pcie)
{ {
struct device *dev = &pcie->pdev->dev;
u16 reg16; u16 reg16;
unsigned long start_jiffies; unsigned long start_jiffies;
...@@ -406,7 +401,7 @@ static void altera_wait_link_retrain(struct altera_pcie *pcie) ...@@ -406,7 +401,7 @@ static void altera_wait_link_retrain(struct altera_pcie *pcie)
break; break;
if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) { if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) {
dev_err(&pcie->pdev->dev, "link retrain timeout\n"); dev_err(dev, "link retrain timeout\n");
break; break;
} }
udelay(100); udelay(100);
...@@ -419,7 +414,7 @@ static void altera_wait_link_retrain(struct altera_pcie *pcie) ...@@ -419,7 +414,7 @@ static void altera_wait_link_retrain(struct altera_pcie *pcie)
break; break;
if (time_after(jiffies, start_jiffies + LINK_UP_TIMEOUT)) { if (time_after(jiffies, start_jiffies + LINK_UP_TIMEOUT)) {
dev_err(&pcie->pdev->dev, "link up timeout\n"); dev_err(dev, "link up timeout\n");
break; break;
} }
udelay(100); udelay(100);
...@@ -460,7 +455,6 @@ static int altera_pcie_intx_map(struct irq_domain *domain, unsigned int irq, ...@@ -460,7 +455,6 @@ static int altera_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
{ {
irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq); irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
irq_set_chip_data(irq, domain->host_data); irq_set_chip_data(irq, domain->host_data);
return 0; return 0;
} }
...@@ -472,12 +466,14 @@ static void altera_pcie_isr(struct irq_desc *desc) ...@@ -472,12 +466,14 @@ static void altera_pcie_isr(struct irq_desc *desc)
{ {
struct irq_chip *chip = irq_desc_get_chip(desc); struct irq_chip *chip = irq_desc_get_chip(desc);
struct altera_pcie *pcie; struct altera_pcie *pcie;
struct device *dev;
unsigned long status; unsigned long status;
u32 bit; u32 bit;
u32 virq; u32 virq;
chained_irq_enter(chip, desc); chained_irq_enter(chip, desc);
pcie = irq_desc_get_handler_data(desc); pcie = irq_desc_get_handler_data(desc);
dev = &pcie->pdev->dev;
while ((status = cra_readl(pcie, P2A_INT_STATUS) while ((status = cra_readl(pcie, P2A_INT_STATUS)
& P2A_INT_STS_ALL) != 0) { & P2A_INT_STS_ALL) != 0) {
...@@ -489,8 +485,7 @@ static void altera_pcie_isr(struct irq_desc *desc) ...@@ -489,8 +485,7 @@ static void altera_pcie_isr(struct irq_desc *desc)
if (virq) if (virq)
generic_handle_irq(virq); generic_handle_irq(virq);
else else
dev_err(&pcie->pdev->dev, dev_err(dev, "unexpected IRQ, INT%d\n", bit);
"unexpected IRQ, INT%d\n", bit);
} }
} }
...@@ -549,30 +544,25 @@ static int altera_pcie_init_irq_domain(struct altera_pcie *pcie) ...@@ -549,30 +544,25 @@ static int altera_pcie_init_irq_domain(struct altera_pcie *pcie)
static int altera_pcie_parse_dt(struct altera_pcie *pcie) static int altera_pcie_parse_dt(struct altera_pcie *pcie)
{ {
struct resource *cra; struct device *dev = &pcie->pdev->dev;
struct platform_device *pdev = pcie->pdev; struct platform_device *pdev = pcie->pdev;
struct resource *cra;
cra = platform_get_resource_byname(pdev, IORESOURCE_MEM, "Cra"); cra = platform_get_resource_byname(pdev, IORESOURCE_MEM, "Cra");
if (!cra) { pcie->cra_base = devm_ioremap_resource(dev, cra);
dev_err(&pdev->dev, "no Cra memory resource defined\n");
return -ENODEV;
}
pcie->cra_base = devm_ioremap_resource(&pdev->dev, cra);
if (IS_ERR(pcie->cra_base)) { if (IS_ERR(pcie->cra_base)) {
dev_err(&pdev->dev, "failed to map cra memory\n"); dev_err(dev, "failed to map cra memory\n");
return PTR_ERR(pcie->cra_base); return PTR_ERR(pcie->cra_base);
} }
/* setup IRQ */ /* setup IRQ */
pcie->irq = platform_get_irq(pdev, 0); pcie->irq = platform_get_irq(pdev, 0);
if (pcie->irq <= 0) { if (pcie->irq <= 0) {
dev_err(&pdev->dev, "failed to get IRQ: %d\n", pcie->irq); dev_err(dev, "failed to get IRQ: %d\n", pcie->irq);
return -EINVAL; return -EINVAL;
} }
irq_set_chained_handler_and_data(pcie->irq, altera_pcie_isr, pcie); irq_set_chained_handler_and_data(pcie->irq, altera_pcie_isr, pcie);
return 0; return 0;
} }
...@@ -583,12 +573,13 @@ static void altera_pcie_host_init(struct altera_pcie *pcie) ...@@ -583,12 +573,13 @@ static void altera_pcie_host_init(struct altera_pcie *pcie)
static int altera_pcie_probe(struct platform_device *pdev) static int altera_pcie_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct altera_pcie *pcie; struct altera_pcie *pcie;
struct pci_bus *bus; struct pci_bus *bus;
struct pci_bus *child; struct pci_bus *child;
int ret; int ret;
pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL); pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
if (!pcie) if (!pcie)
return -ENOMEM; return -ENOMEM;
...@@ -596,7 +587,7 @@ static int altera_pcie_probe(struct platform_device *pdev) ...@@ -596,7 +587,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
ret = altera_pcie_parse_dt(pcie); ret = altera_pcie_parse_dt(pcie);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Parsing DT failed\n"); dev_err(dev, "Parsing DT failed\n");
return ret; return ret;
} }
...@@ -604,13 +595,13 @@ static int altera_pcie_probe(struct platform_device *pdev) ...@@ -604,13 +595,13 @@ static int altera_pcie_probe(struct platform_device *pdev)
ret = altera_pcie_parse_request_of_pci_ranges(pcie); ret = altera_pcie_parse_request_of_pci_ranges(pcie);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed add resources\n"); dev_err(dev, "Failed add resources\n");
return ret; return ret;
} }
ret = altera_pcie_init_irq_domain(pcie); ret = altera_pcie_init_irq_domain(pcie);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed creating IRQ Domain\n"); dev_err(dev, "Failed creating IRQ Domain\n");
return ret; return ret;
} }
...@@ -620,7 +611,7 @@ static int altera_pcie_probe(struct platform_device *pdev) ...@@ -620,7 +611,7 @@ static int altera_pcie_probe(struct platform_device *pdev)
cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE); cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE);
altera_pcie_host_init(pcie); altera_pcie_host_init(pcie);
bus = pci_scan_root_bus(&pdev->dev, pcie->root_bus_nr, &altera_pcie_ops, bus = pci_scan_root_bus(dev, pcie->root_bus_nr, &altera_pcie_ops,
pcie, &pcie->resources); pcie, &pcie->resources);
if (!bus) if (!bus)
return -ENOMEM; return -ENOMEM;
...@@ -633,8 +624,6 @@ static int altera_pcie_probe(struct platform_device *pdev) ...@@ -633,8 +624,6 @@ static int altera_pcie_probe(struct platform_device *pdev)
pcie_bus_configure_settings(child); pcie_bus_configure_settings(child);
pci_bus_add_devices(bus); pci_bus_add_devices(bus);
platform_set_drvdata(pdev, pcie);
return ret; return ret;
} }
......
...@@ -29,34 +29,33 @@ ...@@ -29,34 +29,33 @@
#include "pcie-designware.h" #include "pcie-designware.h"
struct armada8k_pcie { struct armada8k_pcie {
void __iomem *base; struct pcie_port pp; /* pp.dbi_base is DT ctrl */
struct clk *clk; struct clk *clk;
struct pcie_port pp;
}; };
#define PCIE_VENDOR_REGS_OFFSET 0x8000 #define PCIE_VENDOR_REGS_OFFSET 0x8000
#define PCIE_GLOBAL_CONTROL_REG 0x0 #define PCIE_GLOBAL_CONTROL_REG (PCIE_VENDOR_REGS_OFFSET + 0x0)
#define PCIE_APP_LTSSM_EN BIT(2) #define PCIE_APP_LTSSM_EN BIT(2)
#define PCIE_DEVICE_TYPE_SHIFT 4 #define PCIE_DEVICE_TYPE_SHIFT 4
#define PCIE_DEVICE_TYPE_MASK 0xF #define PCIE_DEVICE_TYPE_MASK 0xF
#define PCIE_DEVICE_TYPE_RC 0x4 /* Root complex */ #define PCIE_DEVICE_TYPE_RC 0x4 /* Root complex */
#define PCIE_GLOBAL_STATUS_REG 0x8 #define PCIE_GLOBAL_STATUS_REG (PCIE_VENDOR_REGS_OFFSET + 0x8)
#define PCIE_GLB_STS_RDLH_LINK_UP BIT(1) #define PCIE_GLB_STS_RDLH_LINK_UP BIT(1)
#define PCIE_GLB_STS_PHY_LINK_UP BIT(9) #define PCIE_GLB_STS_PHY_LINK_UP BIT(9)
#define PCIE_GLOBAL_INT_CAUSE1_REG 0x1C #define PCIE_GLOBAL_INT_CAUSE1_REG (PCIE_VENDOR_REGS_OFFSET + 0x1C)
#define PCIE_GLOBAL_INT_MASK1_REG 0x20 #define PCIE_GLOBAL_INT_MASK1_REG (PCIE_VENDOR_REGS_OFFSET + 0x20)
#define PCIE_INT_A_ASSERT_MASK BIT(9) #define PCIE_INT_A_ASSERT_MASK BIT(9)
#define PCIE_INT_B_ASSERT_MASK BIT(10) #define PCIE_INT_B_ASSERT_MASK BIT(10)
#define PCIE_INT_C_ASSERT_MASK BIT(11) #define PCIE_INT_C_ASSERT_MASK BIT(11)
#define PCIE_INT_D_ASSERT_MASK BIT(12) #define PCIE_INT_D_ASSERT_MASK BIT(12)
#define PCIE_ARCACHE_TRC_REG 0x50 #define PCIE_ARCACHE_TRC_REG (PCIE_VENDOR_REGS_OFFSET + 0x50)
#define PCIE_AWCACHE_TRC_REG 0x54 #define PCIE_AWCACHE_TRC_REG (PCIE_VENDOR_REGS_OFFSET + 0x54)
#define PCIE_ARUSER_REG 0x5C #define PCIE_ARUSER_REG (PCIE_VENDOR_REGS_OFFSET + 0x5C)
#define PCIE_AWUSER_REG 0x60 #define PCIE_AWUSER_REG (PCIE_VENDOR_REGS_OFFSET + 0x60)
/* /*
* AR/AW Cache defauls: Normal memory, Write-Back, Read / Write * AR/AW Cache defauls: Normal memory, Write-Back, Read / Write
* allocate * allocate
...@@ -72,11 +71,10 @@ struct armada8k_pcie { ...@@ -72,11 +71,10 @@ struct armada8k_pcie {
static int armada8k_pcie_link_up(struct pcie_port *pp) static int armada8k_pcie_link_up(struct pcie_port *pp)
{ {
struct armada8k_pcie *pcie = to_armada8k_pcie(pp);
u32 reg; u32 reg;
u32 mask = PCIE_GLB_STS_RDLH_LINK_UP | PCIE_GLB_STS_PHY_LINK_UP; u32 mask = PCIE_GLB_STS_RDLH_LINK_UP | PCIE_GLB_STS_PHY_LINK_UP;
reg = readl(pcie->base + PCIE_GLOBAL_STATUS_REG); reg = dw_pcie_readl_rc(pp, PCIE_GLOBAL_STATUS_REG);
if ((reg & mask) == mask) if ((reg & mask) == mask)
return 1; return 1;
...@@ -85,51 +83,50 @@ static int armada8k_pcie_link_up(struct pcie_port *pp) ...@@ -85,51 +83,50 @@ static int armada8k_pcie_link_up(struct pcie_port *pp)
return 0; return 0;
} }
static void armada8k_pcie_establish_link(struct pcie_port *pp) static void armada8k_pcie_establish_link(struct armada8k_pcie *pcie)
{ {
struct armada8k_pcie *pcie = to_armada8k_pcie(pp); struct pcie_port *pp = &pcie->pp;
void __iomem *base = pcie->base;
u32 reg; u32 reg;
if (!dw_pcie_link_up(pp)) { if (!dw_pcie_link_up(pp)) {
/* Disable LTSSM state machine to enable configuration */ /* Disable LTSSM state machine to enable configuration */
reg = readl(base + PCIE_GLOBAL_CONTROL_REG); reg = dw_pcie_readl_rc(pp, PCIE_GLOBAL_CONTROL_REG);
reg &= ~(PCIE_APP_LTSSM_EN); reg &= ~(PCIE_APP_LTSSM_EN);
writel(reg, base + PCIE_GLOBAL_CONTROL_REG); dw_pcie_writel_rc(pp, PCIE_GLOBAL_CONTROL_REG, reg);
} }
/* Set the device to root complex mode */ /* Set the device to root complex mode */
reg = readl(base + PCIE_GLOBAL_CONTROL_REG); reg = dw_pcie_readl_rc(pp, PCIE_GLOBAL_CONTROL_REG);
reg &= ~(PCIE_DEVICE_TYPE_MASK << PCIE_DEVICE_TYPE_SHIFT); reg &= ~(PCIE_DEVICE_TYPE_MASK << PCIE_DEVICE_TYPE_SHIFT);
reg |= PCIE_DEVICE_TYPE_RC << PCIE_DEVICE_TYPE_SHIFT; reg |= PCIE_DEVICE_TYPE_RC << PCIE_DEVICE_TYPE_SHIFT;
writel(reg, base + PCIE_GLOBAL_CONTROL_REG); dw_pcie_writel_rc(pp, PCIE_GLOBAL_CONTROL_REG, reg);
/* Set the PCIe master AxCache attributes */ /* Set the PCIe master AxCache attributes */
writel(ARCACHE_DEFAULT_VALUE, base + PCIE_ARCACHE_TRC_REG); dw_pcie_writel_rc(pp, PCIE_ARCACHE_TRC_REG, ARCACHE_DEFAULT_VALUE);
writel(AWCACHE_DEFAULT_VALUE, base + PCIE_AWCACHE_TRC_REG); dw_pcie_writel_rc(pp, PCIE_AWCACHE_TRC_REG, AWCACHE_DEFAULT_VALUE);
/* Set the PCIe master AxDomain attributes */ /* Set the PCIe master AxDomain attributes */
reg = readl(base + PCIE_ARUSER_REG); reg = dw_pcie_readl_rc(pp, PCIE_ARUSER_REG);
reg &= ~(AX_USER_DOMAIN_MASK << AX_USER_DOMAIN_SHIFT); reg &= ~(AX_USER_DOMAIN_MASK << AX_USER_DOMAIN_SHIFT);
reg |= DOMAIN_OUTER_SHAREABLE << AX_USER_DOMAIN_SHIFT; reg |= DOMAIN_OUTER_SHAREABLE << AX_USER_DOMAIN_SHIFT;
writel(reg, base + PCIE_ARUSER_REG); dw_pcie_writel_rc(pp, PCIE_ARUSER_REG, reg);
reg = readl(base + PCIE_AWUSER_REG); reg = dw_pcie_readl_rc(pp, PCIE_AWUSER_REG);
reg &= ~(AX_USER_DOMAIN_MASK << AX_USER_DOMAIN_SHIFT); reg &= ~(AX_USER_DOMAIN_MASK << AX_USER_DOMAIN_SHIFT);
reg |= DOMAIN_OUTER_SHAREABLE << AX_USER_DOMAIN_SHIFT; reg |= DOMAIN_OUTER_SHAREABLE << AX_USER_DOMAIN_SHIFT;
writel(reg, base + PCIE_AWUSER_REG); dw_pcie_writel_rc(pp, PCIE_AWUSER_REG, reg);
/* Enable INT A-D interrupts */ /* Enable INT A-D interrupts */
reg = readl(base + PCIE_GLOBAL_INT_MASK1_REG); reg = dw_pcie_readl_rc(pp, PCIE_GLOBAL_INT_MASK1_REG);
reg |= PCIE_INT_A_ASSERT_MASK | PCIE_INT_B_ASSERT_MASK | reg |= PCIE_INT_A_ASSERT_MASK | PCIE_INT_B_ASSERT_MASK |
PCIE_INT_C_ASSERT_MASK | PCIE_INT_D_ASSERT_MASK; PCIE_INT_C_ASSERT_MASK | PCIE_INT_D_ASSERT_MASK;
writel(reg, base + PCIE_GLOBAL_INT_MASK1_REG); dw_pcie_writel_rc(pp, PCIE_GLOBAL_INT_MASK1_REG, reg);
if (!dw_pcie_link_up(pp)) { if (!dw_pcie_link_up(pp)) {
/* Configuration done. Start LTSSM */ /* Configuration done. Start LTSSM */
reg = readl(base + PCIE_GLOBAL_CONTROL_REG); reg = dw_pcie_readl_rc(pp, PCIE_GLOBAL_CONTROL_REG);
reg |= PCIE_APP_LTSSM_EN; reg |= PCIE_APP_LTSSM_EN;
writel(reg, base + PCIE_GLOBAL_CONTROL_REG); dw_pcie_writel_rc(pp, PCIE_GLOBAL_CONTROL_REG, reg);
} }
/* Wait until the link becomes active again */ /* Wait until the link becomes active again */
...@@ -139,15 +136,16 @@ static void armada8k_pcie_establish_link(struct pcie_port *pp) ...@@ -139,15 +136,16 @@ static void armada8k_pcie_establish_link(struct pcie_port *pp)
static void armada8k_pcie_host_init(struct pcie_port *pp) static void armada8k_pcie_host_init(struct pcie_port *pp)
{ {
struct armada8k_pcie *pcie = to_armada8k_pcie(pp);
dw_pcie_setup_rc(pp); dw_pcie_setup_rc(pp);
armada8k_pcie_establish_link(pp); armada8k_pcie_establish_link(pcie);
} }
static irqreturn_t armada8k_pcie_irq_handler(int irq, void *arg) static irqreturn_t armada8k_pcie_irq_handler(int irq, void *arg)
{ {
struct pcie_port *pp = arg; struct armada8k_pcie *pcie = arg;
struct armada8k_pcie *pcie = to_armada8k_pcie(pp); struct pcie_port *pp = &pcie->pp;
void __iomem *base = pcie->base;
u32 val; u32 val;
/* /*
...@@ -155,8 +153,8 @@ static irqreturn_t armada8k_pcie_irq_handler(int irq, void *arg) ...@@ -155,8 +153,8 @@ static irqreturn_t armada8k_pcie_irq_handler(int irq, void *arg)
* PCI device. However, they are also latched into the PCIe * PCI device. However, they are also latched into the PCIe
* controller, so we simply discard them. * controller, so we simply discard them.
*/ */
val = readl(base + PCIE_GLOBAL_INT_CAUSE1_REG); val = dw_pcie_readl_rc(pp, PCIE_GLOBAL_INT_CAUSE1_REG);
writel(val, base + PCIE_GLOBAL_INT_CAUSE1_REG); dw_pcie_writel_rc(pp, PCIE_GLOBAL_INT_CAUSE1_REG, val);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -166,9 +164,10 @@ static struct pcie_host_ops armada8k_pcie_host_ops = { ...@@ -166,9 +164,10 @@ static struct pcie_host_ops armada8k_pcie_host_ops = {
.host_init = armada8k_pcie_host_init, .host_init = armada8k_pcie_host_init,
}; };
static int armada8k_add_pcie_port(struct pcie_port *pp, static int armada8k_add_pcie_port(struct armada8k_pcie *pcie,
struct platform_device *pdev) struct platform_device *pdev)
{ {
struct pcie_port *pp = &pcie->pp;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
int ret; int ret;
...@@ -182,7 +181,7 @@ static int armada8k_add_pcie_port(struct pcie_port *pp, ...@@ -182,7 +181,7 @@ static int armada8k_add_pcie_port(struct pcie_port *pp,
} }
ret = devm_request_irq(dev, pp->irq, armada8k_pcie_irq_handler, ret = devm_request_irq(dev, pp->irq, armada8k_pcie_irq_handler,
IRQF_SHARED, "armada8k-pcie", pp); IRQF_SHARED, "armada8k-pcie", pcie);
if (ret) { if (ret) {
dev_err(dev, "failed to request irq %d\n", pp->irq); dev_err(dev, "failed to request irq %d\n", pp->irq);
return ret; return ret;
...@@ -217,7 +216,6 @@ static int armada8k_pcie_probe(struct platform_device *pdev) ...@@ -217,7 +216,6 @@ static int armada8k_pcie_probe(struct platform_device *pdev)
pp = &pcie->pp; pp = &pcie->pp;
pp->dev = dev; pp->dev = dev;
platform_set_drvdata(pdev, pcie);
/* Get the dw-pcie unit configuration/control registers base. */ /* Get the dw-pcie unit configuration/control registers base. */
base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl"); base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl");
...@@ -228,9 +226,7 @@ static int armada8k_pcie_probe(struct platform_device *pdev) ...@@ -228,9 +226,7 @@ static int armada8k_pcie_probe(struct platform_device *pdev)
goto fail; goto fail;
} }
pcie->base = pp->dbi_base + PCIE_VENDOR_REGS_OFFSET; ret = armada8k_add_pcie_port(pcie, pdev);
ret = armada8k_add_pcie_port(pp, pdev);
if (ret) if (ret)
goto fail; goto fail;
......
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
#define to_artpec6_pcie(x) container_of(x, struct artpec6_pcie, pp) #define to_artpec6_pcie(x) container_of(x, struct artpec6_pcie, pp)
struct artpec6_pcie { struct artpec6_pcie {
struct pcie_port pp; struct pcie_port pp; /* pp.dbi_base is DT dbi */
struct regmap *regmap; struct regmap *regmap; /* DT axis,syscon-pcie */
void __iomem *phy_base; void __iomem *phy_base; /* DT phy */
}; };
/* PCIe Port Logic registers (memory-mapped) */ /* PCIe Port Logic registers (memory-mapped) */
...@@ -65,18 +65,31 @@ struct artpec6_pcie { ...@@ -65,18 +65,31 @@ struct artpec6_pcie {
#define ARTPEC6_CPU_TO_BUS_ADDR 0x0fffffff #define ARTPEC6_CPU_TO_BUS_ADDR 0x0fffffff
static int artpec6_pcie_establish_link(struct pcie_port *pp) static u32 artpec6_pcie_readl(struct artpec6_pcie *artpec6_pcie, u32 offset)
{ {
struct artpec6_pcie *artpec6_pcie = to_artpec6_pcie(pp); u32 val;
regmap_read(artpec6_pcie->regmap, offset, &val);
return val;
}
static void artpec6_pcie_writel(struct artpec6_pcie *artpec6_pcie, u32 offset, u32 val)
{
regmap_write(artpec6_pcie->regmap, offset, val);
}
static int artpec6_pcie_establish_link(struct artpec6_pcie *artpec6_pcie)
{
struct pcie_port *pp = &artpec6_pcie->pp;
u32 val; u32 val;
unsigned int retries; unsigned int retries;
/* Hold DW core in reset */ /* Hold DW core in reset */
regmap_read(artpec6_pcie->regmap, PCIECFG, &val); val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
val |= PCIECFG_CORE_RESET_REQ; val |= PCIECFG_CORE_RESET_REQ;
regmap_write(artpec6_pcie->regmap, PCIECFG, val); artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
regmap_read(artpec6_pcie->regmap, PCIECFG, &val); val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
val |= PCIECFG_RISRCREN | /* Receiver term. 50 Ohm */ val |= PCIECFG_RISRCREN | /* Receiver term. 50 Ohm */
PCIECFG_MODE_TX_DRV_EN | PCIECFG_MODE_TX_DRV_EN |
PCIECFG_CISRREN | /* Reference clock term. 100 Ohm */ PCIECFG_CISRREN | /* Reference clock term. 100 Ohm */
...@@ -84,27 +97,27 @@ static int artpec6_pcie_establish_link(struct pcie_port *pp) ...@@ -84,27 +97,27 @@ static int artpec6_pcie_establish_link(struct pcie_port *pp)
val |= PCIECFG_REFCLK_ENABLE; val |= PCIECFG_REFCLK_ENABLE;
val &= ~PCIECFG_DBG_OEN; val &= ~PCIECFG_DBG_OEN;
val &= ~PCIECFG_CLKREQ_B; val &= ~PCIECFG_CLKREQ_B;
regmap_write(artpec6_pcie->regmap, PCIECFG, val); artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
usleep_range(5000, 6000); usleep_range(5000, 6000);
regmap_read(artpec6_pcie->regmap, NOCCFG, &val); val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
val |= NOCCFG_ENABLE_CLK_PCIE; val |= NOCCFG_ENABLE_CLK_PCIE;
regmap_write(artpec6_pcie->regmap, NOCCFG, val); artpec6_pcie_writel(artpec6_pcie, NOCCFG, val);
usleep_range(20, 30); usleep_range(20, 30);
regmap_read(artpec6_pcie->regmap, PCIECFG, &val); val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
val |= PCIECFG_PCLK_ENABLE | PCIECFG_PLL_ENABLE; val |= PCIECFG_PCLK_ENABLE | PCIECFG_PLL_ENABLE;
regmap_write(artpec6_pcie->regmap, PCIECFG, val); artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
usleep_range(6000, 7000); usleep_range(6000, 7000);
regmap_read(artpec6_pcie->regmap, NOCCFG, &val); val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
val &= ~NOCCFG_POWER_PCIE_IDLEREQ; val &= ~NOCCFG_POWER_PCIE_IDLEREQ;
regmap_write(artpec6_pcie->regmap, NOCCFG, val); artpec6_pcie_writel(artpec6_pcie, NOCCFG, val);
retries = 50; retries = 50;
do { do {
usleep_range(1000, 2000); usleep_range(1000, 2000);
regmap_read(artpec6_pcie->regmap, NOCCFG, &val); val = artpec6_pcie_readl(artpec6_pcie, NOCCFG);
retries--; retries--;
} while (retries && } while (retries &&
(val & (NOCCFG_POWER_PCIE_IDLEACK | NOCCFG_POWER_PCIE_IDLE))); (val & (NOCCFG_POWER_PCIE_IDLEACK | NOCCFG_POWER_PCIE_IDLE)));
...@@ -117,16 +130,16 @@ static int artpec6_pcie_establish_link(struct pcie_port *pp) ...@@ -117,16 +130,16 @@ static int artpec6_pcie_establish_link(struct pcie_port *pp)
} while (retries && !(val & PHY_COSPLLLOCK)); } while (retries && !(val & PHY_COSPLLLOCK));
/* Take DW core out of reset */ /* Take DW core out of reset */
regmap_read(artpec6_pcie->regmap, PCIECFG, &val); val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
val &= ~PCIECFG_CORE_RESET_REQ; val &= ~PCIECFG_CORE_RESET_REQ;
regmap_write(artpec6_pcie->regmap, PCIECFG, val); artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
usleep_range(100, 200); usleep_range(100, 200);
/* /*
* Enable writing to config regs. This is required as the Synopsys * Enable writing to config regs. This is required as the Synopsys
* driver changes the class code. That register needs DBI write enable. * driver changes the class code. That register needs DBI write enable.
*/ */
writel(DBI_RO_WR_EN, pp->dbi_base + MISC_CONTROL_1_OFF); dw_pcie_writel_rc(pp, MISC_CONTROL_1_OFF, DBI_RO_WR_EN);
pp->io_base &= ARTPEC6_CPU_TO_BUS_ADDR; pp->io_base &= ARTPEC6_CPU_TO_BUS_ADDR;
pp->mem_base &= ARTPEC6_CPU_TO_BUS_ADDR; pp->mem_base &= ARTPEC6_CPU_TO_BUS_ADDR;
...@@ -137,78 +150,69 @@ static int artpec6_pcie_establish_link(struct pcie_port *pp) ...@@ -137,78 +150,69 @@ static int artpec6_pcie_establish_link(struct pcie_port *pp)
dw_pcie_setup_rc(pp); dw_pcie_setup_rc(pp);
/* assert LTSSM enable */ /* assert LTSSM enable */
regmap_read(artpec6_pcie->regmap, PCIECFG, &val); val = artpec6_pcie_readl(artpec6_pcie, PCIECFG);
val |= PCIECFG_LTSSM_ENABLE; val |= PCIECFG_LTSSM_ENABLE;
regmap_write(artpec6_pcie->regmap, PCIECFG, val); artpec6_pcie_writel(artpec6_pcie, PCIECFG, val);
/* check if the link is up or not */ /* check if the link is up or not */
if (!dw_pcie_wait_for_link(pp)) if (!dw_pcie_wait_for_link(pp))
return 0; return 0;
dev_dbg(pp->dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n", dev_dbg(pp->dev, "DEBUG_R0: 0x%08x, DEBUG_R1: 0x%08x\n",
readl(pp->dbi_base + PCIE_PHY_DEBUG_R0), dw_pcie_readl_rc(pp, PCIE_PHY_DEBUG_R0),
readl(pp->dbi_base + PCIE_PHY_DEBUG_R1)); dw_pcie_readl_rc(pp, PCIE_PHY_DEBUG_R1));
return -ETIMEDOUT; return -ETIMEDOUT;
} }
static void artpec6_pcie_enable_interrupts(struct pcie_port *pp) static void artpec6_pcie_enable_interrupts(struct artpec6_pcie *artpec6_pcie)
{ {
struct pcie_port *pp = &artpec6_pcie->pp;
if (IS_ENABLED(CONFIG_PCI_MSI)) if (IS_ENABLED(CONFIG_PCI_MSI))
dw_pcie_msi_init(pp); dw_pcie_msi_init(pp);
} }
static void artpec6_pcie_host_init(struct pcie_port *pp) static void artpec6_pcie_host_init(struct pcie_port *pp)
{ {
artpec6_pcie_establish_link(pp); struct artpec6_pcie *artpec6_pcie = to_artpec6_pcie(pp);
artpec6_pcie_enable_interrupts(pp);
}
static int artpec6_pcie_link_up(struct pcie_port *pp)
{
u32 rc;
/*
* Get status from Synopsys IP
* link is debug bit 36, debug register 1 starts at bit 32
*/
rc = readl(pp->dbi_base + PCIE_PHY_DEBUG_R1) & (0x1 << (36 - 32));
if (rc)
return 1;
return 0; artpec6_pcie_establish_link(artpec6_pcie);
artpec6_pcie_enable_interrupts(artpec6_pcie);
} }
static struct pcie_host_ops artpec6_pcie_host_ops = { static struct pcie_host_ops artpec6_pcie_host_ops = {
.link_up = artpec6_pcie_link_up,
.host_init = artpec6_pcie_host_init, .host_init = artpec6_pcie_host_init,
}; };
static irqreturn_t artpec6_pcie_msi_handler(int irq, void *arg) static irqreturn_t artpec6_pcie_msi_handler(int irq, void *arg)
{ {
struct pcie_port *pp = arg; struct artpec6_pcie *artpec6_pcie = arg;
struct pcie_port *pp = &artpec6_pcie->pp;
return dw_handle_msi_irq(pp); return dw_handle_msi_irq(pp);
} }
static int artpec6_add_pcie_port(struct pcie_port *pp, static int artpec6_add_pcie_port(struct artpec6_pcie *artpec6_pcie,
struct platform_device *pdev) struct platform_device *pdev)
{ {
struct pcie_port *pp = &artpec6_pcie->pp;
struct device *dev = pp->dev;
int ret; int ret;
if (IS_ENABLED(CONFIG_PCI_MSI)) { if (IS_ENABLED(CONFIG_PCI_MSI)) {
pp->msi_irq = platform_get_irq_byname(pdev, "msi"); pp->msi_irq = platform_get_irq_byname(pdev, "msi");
if (pp->msi_irq <= 0) { if (pp->msi_irq <= 0) {
dev_err(&pdev->dev, "failed to get MSI irq\n"); dev_err(dev, "failed to get MSI irq\n");
return -ENODEV; return -ENODEV;
} }
ret = devm_request_irq(&pdev->dev, pp->msi_irq, ret = devm_request_irq(dev, pp->msi_irq,
artpec6_pcie_msi_handler, artpec6_pcie_msi_handler,
IRQF_SHARED | IRQF_NO_THREAD, IRQF_SHARED | IRQF_NO_THREAD,
"artpec6-pcie-msi", pp); "artpec6-pcie-msi", artpec6_pcie);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to request MSI irq\n"); dev_err(dev, "failed to request MSI irq\n");
return ret; return ret;
} }
} }
...@@ -218,7 +222,7 @@ static int artpec6_add_pcie_port(struct pcie_port *pp, ...@@ -218,7 +222,7 @@ static int artpec6_add_pcie_port(struct pcie_port *pp,
ret = dw_pcie_host_init(pp); ret = dw_pcie_host_init(pp);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize host\n"); dev_err(dev, "failed to initialize host\n");
return ret; return ret;
} }
...@@ -227,41 +231,40 @@ static int artpec6_add_pcie_port(struct pcie_port *pp, ...@@ -227,41 +231,40 @@ static int artpec6_add_pcie_port(struct pcie_port *pp,
static int artpec6_pcie_probe(struct platform_device *pdev) static int artpec6_pcie_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct artpec6_pcie *artpec6_pcie; struct artpec6_pcie *artpec6_pcie;
struct pcie_port *pp; struct pcie_port *pp;
struct resource *dbi_base; struct resource *dbi_base;
struct resource *phy_base; struct resource *phy_base;
int ret; int ret;
artpec6_pcie = devm_kzalloc(&pdev->dev, sizeof(*artpec6_pcie), artpec6_pcie = devm_kzalloc(dev, sizeof(*artpec6_pcie), GFP_KERNEL);
GFP_KERNEL);
if (!artpec6_pcie) if (!artpec6_pcie)
return -ENOMEM; return -ENOMEM;
pp = &artpec6_pcie->pp; pp = &artpec6_pcie->pp;
pp->dev = &pdev->dev; pp->dev = dev;
dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
pp->dbi_base = devm_ioremap_resource(&pdev->dev, dbi_base); pp->dbi_base = devm_ioremap_resource(dev, dbi_base);
if (IS_ERR(pp->dbi_base)) if (IS_ERR(pp->dbi_base))
return PTR_ERR(pp->dbi_base); return PTR_ERR(pp->dbi_base);
phy_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy"); phy_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy");
artpec6_pcie->phy_base = devm_ioremap_resource(&pdev->dev, phy_base); artpec6_pcie->phy_base = devm_ioremap_resource(dev, phy_base);
if (IS_ERR(artpec6_pcie->phy_base)) if (IS_ERR(artpec6_pcie->phy_base))
return PTR_ERR(artpec6_pcie->phy_base); return PTR_ERR(artpec6_pcie->phy_base);
artpec6_pcie->regmap = artpec6_pcie->regmap =
syscon_regmap_lookup_by_phandle(pdev->dev.of_node, syscon_regmap_lookup_by_phandle(dev->of_node,
"axis,syscon-pcie"); "axis,syscon-pcie");
if (IS_ERR(artpec6_pcie->regmap)) if (IS_ERR(artpec6_pcie->regmap))
return PTR_ERR(artpec6_pcie->regmap); return PTR_ERR(artpec6_pcie->regmap);
ret = artpec6_add_pcie_port(pp, pdev); ret = artpec6_add_pcie_port(artpec6_pcie, pdev);
if (ret < 0) if (ret < 0)
return ret; return ret;
platform_set_drvdata(pdev, artpec6_pcie);
return 0; return 0;
} }
......
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
#include "pcie-designware.h" #include "pcie-designware.h"
struct dw_plat_pcie { struct dw_plat_pcie {
void __iomem *mem_base; struct pcie_port pp; /* pp.dbi_base is DT 0th resource */
struct pcie_port pp;
}; };
static irqreturn_t dw_plat_pcie_msi_irq_handler(int irq, void *arg) static irqreturn_t dw_plat_pcie_msi_irq_handler(int irq, void *arg)
...@@ -52,6 +51,7 @@ static struct pcie_host_ops dw_plat_pcie_host_ops = { ...@@ -52,6 +51,7 @@ static struct pcie_host_ops dw_plat_pcie_host_ops = {
static int dw_plat_add_pcie_port(struct pcie_port *pp, static int dw_plat_add_pcie_port(struct pcie_port *pp,
struct platform_device *pdev) struct platform_device *pdev)
{ {
struct device *dev = pp->dev;
int ret; int ret;
pp->irq = platform_get_irq(pdev, 1); pp->irq = platform_get_irq(pdev, 1);
...@@ -63,11 +63,11 @@ static int dw_plat_add_pcie_port(struct pcie_port *pp, ...@@ -63,11 +63,11 @@ static int dw_plat_add_pcie_port(struct pcie_port *pp,
if (pp->msi_irq < 0) if (pp->msi_irq < 0)
return pp->msi_irq; return pp->msi_irq;
ret = devm_request_irq(&pdev->dev, pp->msi_irq, ret = devm_request_irq(dev, pp->msi_irq,
dw_plat_pcie_msi_irq_handler, dw_plat_pcie_msi_irq_handler,
IRQF_SHARED, "dw-plat-pcie-msi", pp); IRQF_SHARED, "dw-plat-pcie-msi", pp);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to request MSI IRQ\n"); dev_err(dev, "failed to request MSI IRQ\n");
return ret; return ret;
} }
} }
...@@ -77,7 +77,7 @@ static int dw_plat_add_pcie_port(struct pcie_port *pp, ...@@ -77,7 +77,7 @@ static int dw_plat_add_pcie_port(struct pcie_port *pp,
ret = dw_pcie_host_init(pp); ret = dw_pcie_host_init(pp);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize host\n"); dev_err(dev, "failed to initialize host\n");
return ret; return ret;
} }
...@@ -86,31 +86,28 @@ static int dw_plat_add_pcie_port(struct pcie_port *pp, ...@@ -86,31 +86,28 @@ static int dw_plat_add_pcie_port(struct pcie_port *pp,
static int dw_plat_pcie_probe(struct platform_device *pdev) static int dw_plat_pcie_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct dw_plat_pcie *dw_plat_pcie; struct dw_plat_pcie *dw_plat_pcie;
struct pcie_port *pp; struct pcie_port *pp;
struct resource *res; /* Resource from DT */ struct resource *res; /* Resource from DT */
int ret; int ret;
dw_plat_pcie = devm_kzalloc(&pdev->dev, sizeof(*dw_plat_pcie), dw_plat_pcie = devm_kzalloc(dev, sizeof(*dw_plat_pcie), GFP_KERNEL);
GFP_KERNEL);
if (!dw_plat_pcie) if (!dw_plat_pcie)
return -ENOMEM; return -ENOMEM;
pp = &dw_plat_pcie->pp; pp = &dw_plat_pcie->pp;
pp->dev = &pdev->dev; pp->dev = dev;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
dw_plat_pcie->mem_base = devm_ioremap_resource(&pdev->dev, res); pp->dbi_base = devm_ioremap_resource(dev, res);
if (IS_ERR(dw_plat_pcie->mem_base)) if (IS_ERR(pp->dbi_base))
return PTR_ERR(dw_plat_pcie->mem_base); return PTR_ERR(pp->dbi_base);
pp->dbi_base = dw_plat_pcie->mem_base;
ret = dw_plat_add_pcie_port(pp, pdev); ret = dw_plat_add_pcie_port(pp, pdev);
if (ret < 0) if (ret < 0)
return ret; return ret;
platform_set_drvdata(pdev, dw_plat_pcie);
return 0; return 0;
} }
......
...@@ -141,41 +141,35 @@ int dw_pcie_cfg_write(void __iomem *addr, int size, u32 val) ...@@ -141,41 +141,35 @@ int dw_pcie_cfg_write(void __iomem *addr, int size, u32 val)
return PCIBIOS_SUCCESSFUL; return PCIBIOS_SUCCESSFUL;
} }
static inline u32 dw_pcie_readl_rc(struct pcie_port *pp, u32 reg) u32 dw_pcie_readl_rc(struct pcie_port *pp, u32 reg)
{ {
if (pp->ops->readl_rc) if (pp->ops->readl_rc)
return pp->ops->readl_rc(pp, pp->dbi_base + reg); return pp->ops->readl_rc(pp, reg);
return readl(pp->dbi_base + reg); return readl(pp->dbi_base + reg);
} }
static inline void dw_pcie_writel_rc(struct pcie_port *pp, u32 val, u32 reg) void dw_pcie_writel_rc(struct pcie_port *pp, u32 reg, u32 val)
{ {
if (pp->ops->writel_rc) if (pp->ops->writel_rc)
pp->ops->writel_rc(pp, val, pp->dbi_base + reg); pp->ops->writel_rc(pp, reg, val);
else else
writel(val, pp->dbi_base + reg); writel(val, pp->dbi_base + reg);
} }
static inline u32 dw_pcie_readl_unroll(struct pcie_port *pp, u32 index, u32 reg) static u32 dw_pcie_readl_unroll(struct pcie_port *pp, u32 index, u32 reg)
{ {
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index); u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
if (pp->ops->readl_rc) return dw_pcie_readl_rc(pp, offset + reg);
return pp->ops->readl_rc(pp, pp->dbi_base + offset + reg);
return readl(pp->dbi_base + offset + reg);
} }
static inline void dw_pcie_writel_unroll(struct pcie_port *pp, u32 index, static void dw_pcie_writel_unroll(struct pcie_port *pp, u32 index, u32 reg,
u32 val, u32 reg) u32 val)
{ {
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index); u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
if (pp->ops->writel_rc) dw_pcie_writel_rc(pp, offset + reg, val);
pp->ops->writel_rc(pp, val, pp->dbi_base + offset + reg);
else
writel(val, pp->dbi_base + offset + reg);
} }
static int dw_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, static int dw_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
...@@ -202,35 +196,35 @@ static void dw_pcie_prog_outbound_atu(struct pcie_port *pp, int index, ...@@ -202,35 +196,35 @@ static void dw_pcie_prog_outbound_atu(struct pcie_port *pp, int index,
u32 retries, val; u32 retries, val;
if (pp->iatu_unroll_enabled) { if (pp->iatu_unroll_enabled) {
dw_pcie_writel_unroll(pp, index, dw_pcie_writel_unroll(pp, index, PCIE_ATU_UNR_LOWER_BASE,
lower_32_bits(cpu_addr), PCIE_ATU_UNR_LOWER_BASE); lower_32_bits(cpu_addr));
dw_pcie_writel_unroll(pp, index, dw_pcie_writel_unroll(pp, index, PCIE_ATU_UNR_UPPER_BASE,
upper_32_bits(cpu_addr), PCIE_ATU_UNR_UPPER_BASE); upper_32_bits(cpu_addr));
dw_pcie_writel_unroll(pp, index, dw_pcie_writel_unroll(pp, index, PCIE_ATU_UNR_LIMIT,
lower_32_bits(cpu_addr + size - 1), PCIE_ATU_UNR_LIMIT); lower_32_bits(cpu_addr + size - 1));
dw_pcie_writel_unroll(pp, index, dw_pcie_writel_unroll(pp, index, PCIE_ATU_UNR_LOWER_TARGET,
lower_32_bits(pci_addr), PCIE_ATU_UNR_LOWER_TARGET); lower_32_bits(pci_addr));
dw_pcie_writel_unroll(pp, index, dw_pcie_writel_unroll(pp, index, PCIE_ATU_UNR_UPPER_TARGET,
upper_32_bits(pci_addr), PCIE_ATU_UNR_UPPER_TARGET); upper_32_bits(pci_addr));
dw_pcie_writel_unroll(pp, index, dw_pcie_writel_unroll(pp, index, PCIE_ATU_UNR_REGION_CTRL1,
type, PCIE_ATU_UNR_REGION_CTRL1); type);
dw_pcie_writel_unroll(pp, index, dw_pcie_writel_unroll(pp, index, PCIE_ATU_UNR_REGION_CTRL2,
PCIE_ATU_ENABLE, PCIE_ATU_UNR_REGION_CTRL2); PCIE_ATU_ENABLE);
} else { } else {
dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | index, dw_pcie_writel_rc(pp, PCIE_ATU_VIEWPORT,
PCIE_ATU_VIEWPORT); PCIE_ATU_REGION_OUTBOUND | index);
dw_pcie_writel_rc(pp, lower_32_bits(cpu_addr), dw_pcie_writel_rc(pp, PCIE_ATU_LOWER_BASE,
PCIE_ATU_LOWER_BASE); lower_32_bits(cpu_addr));
dw_pcie_writel_rc(pp, upper_32_bits(cpu_addr), dw_pcie_writel_rc(pp, PCIE_ATU_UPPER_BASE,
PCIE_ATU_UPPER_BASE); upper_32_bits(cpu_addr));
dw_pcie_writel_rc(pp, lower_32_bits(cpu_addr + size - 1), dw_pcie_writel_rc(pp, PCIE_ATU_LIMIT,
PCIE_ATU_LIMIT); lower_32_bits(cpu_addr + size - 1));
dw_pcie_writel_rc(pp, lower_32_bits(pci_addr), dw_pcie_writel_rc(pp, PCIE_ATU_LOWER_TARGET,
PCIE_ATU_LOWER_TARGET); lower_32_bits(pci_addr));
dw_pcie_writel_rc(pp, upper_32_bits(pci_addr), dw_pcie_writel_rc(pp, PCIE_ATU_UPPER_TARGET,
PCIE_ATU_UPPER_TARGET); upper_32_bits(pci_addr));
dw_pcie_writel_rc(pp, type, PCIE_ATU_CR1); dw_pcie_writel_rc(pp, PCIE_ATU_CR1, type);
dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2); dw_pcie_writel_rc(pp, PCIE_ATU_CR2, PCIE_ATU_ENABLE);
} }
/* /*
...@@ -760,8 +754,8 @@ static int dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus, ...@@ -760,8 +754,8 @@ static int dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
return ret; return ret;
} }
static int dw_pcie_valid_config(struct pcie_port *pp, static int dw_pcie_valid_device(struct pcie_port *pp, struct pci_bus *bus,
struct pci_bus *bus, int dev) int dev)
{ {
/* If there is no link, then there is no device */ /* If there is no link, then there is no device */
if (bus->number != pp->root_bus_nr) { if (bus->number != pp->root_bus_nr) {
...@@ -781,7 +775,7 @@ static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where, ...@@ -781,7 +775,7 @@ static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
{ {
struct pcie_port *pp = bus->sysdata; struct pcie_port *pp = bus->sysdata;
if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0) { if (!dw_pcie_valid_device(pp, bus, PCI_SLOT(devfn))) {
*val = 0xffffffff; *val = 0xffffffff;
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
} }
...@@ -797,7 +791,7 @@ static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn, ...@@ -797,7 +791,7 @@ static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
{ {
struct pcie_port *pp = bus->sysdata; struct pcie_port *pp = bus->sysdata;
if (dw_pcie_valid_config(pp, bus, PCI_SLOT(devfn)) == 0) if (!dw_pcie_valid_device(pp, bus, PCI_SLOT(devfn)))
return PCIBIOS_DEVICE_NOT_FOUND; return PCIBIOS_DEVICE_NOT_FOUND;
if (bus->number == pp->root_bus_nr) if (bus->number == pp->root_bus_nr)
...@@ -835,7 +829,7 @@ void dw_pcie_setup_rc(struct pcie_port *pp) ...@@ -835,7 +829,7 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
dev_err(pp->dev, "num-lanes %u: invalid value\n", pp->lanes); dev_err(pp->dev, "num-lanes %u: invalid value\n", pp->lanes);
return; return;
} }
dw_pcie_writel_rc(pp, val, PCIE_PORT_LINK_CONTROL); dw_pcie_writel_rc(pp, PCIE_PORT_LINK_CONTROL, val);
/* set link width speed control register */ /* set link width speed control register */
val = dw_pcie_readl_rc(pp, PCIE_LINK_WIDTH_SPEED_CONTROL); val = dw_pcie_readl_rc(pp, PCIE_LINK_WIDTH_SPEED_CONTROL);
...@@ -854,30 +848,30 @@ void dw_pcie_setup_rc(struct pcie_port *pp) ...@@ -854,30 +848,30 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
val |= PORT_LOGIC_LINK_WIDTH_8_LANES; val |= PORT_LOGIC_LINK_WIDTH_8_LANES;
break; break;
} }
dw_pcie_writel_rc(pp, val, PCIE_LINK_WIDTH_SPEED_CONTROL); dw_pcie_writel_rc(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
/* setup RC BARs */ /* setup RC BARs */
dw_pcie_writel_rc(pp, 0x00000004, PCI_BASE_ADDRESS_0); dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_0, 0x00000004);
dw_pcie_writel_rc(pp, 0x00000000, PCI_BASE_ADDRESS_1); dw_pcie_writel_rc(pp, PCI_BASE_ADDRESS_1, 0x00000000);
/* setup interrupt pins */ /* setup interrupt pins */
val = dw_pcie_readl_rc(pp, PCI_INTERRUPT_LINE); val = dw_pcie_readl_rc(pp, PCI_INTERRUPT_LINE);
val &= 0xffff00ff; val &= 0xffff00ff;
val |= 0x00000100; val |= 0x00000100;
dw_pcie_writel_rc(pp, val, PCI_INTERRUPT_LINE); dw_pcie_writel_rc(pp, PCI_INTERRUPT_LINE, val);
/* setup bus numbers */ /* setup bus numbers */
val = dw_pcie_readl_rc(pp, PCI_PRIMARY_BUS); val = dw_pcie_readl_rc(pp, PCI_PRIMARY_BUS);
val &= 0xff000000; val &= 0xff000000;
val |= 0x00010100; val |= 0x00010100;
dw_pcie_writel_rc(pp, val, PCI_PRIMARY_BUS); dw_pcie_writel_rc(pp, PCI_PRIMARY_BUS, val);
/* setup command register */ /* setup command register */
val = dw_pcie_readl_rc(pp, PCI_COMMAND); val = dw_pcie_readl_rc(pp, PCI_COMMAND);
val &= 0xffff0000; val &= 0xffff0000;
val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | val |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
PCI_COMMAND_MASTER | PCI_COMMAND_SERR; PCI_COMMAND_MASTER | PCI_COMMAND_SERR;
dw_pcie_writel_rc(pp, val, PCI_COMMAND); dw_pcie_writel_rc(pp, PCI_COMMAND, val);
/* /*
* If the platform provides ->rd_other_conf, it means the platform * If the platform provides ->rd_other_conf, it means the platform
......
...@@ -54,9 +54,8 @@ struct pcie_port { ...@@ -54,9 +54,8 @@ struct pcie_port {
}; };
struct pcie_host_ops { struct pcie_host_ops {
u32 (*readl_rc)(struct pcie_port *pp, void __iomem *dbi_base); u32 (*readl_rc)(struct pcie_port *pp, u32 reg);
void (*writel_rc)(struct pcie_port *pp, void (*writel_rc)(struct pcie_port *pp, u32 reg, u32 val);
u32 val, void __iomem *dbi_base);
int (*rd_own_conf)(struct pcie_port *pp, int where, int size, u32 *val); int (*rd_own_conf)(struct pcie_port *pp, int where, int size, u32 *val);
int (*wr_own_conf)(struct pcie_port *pp, int where, int size, u32 val); int (*wr_own_conf)(struct pcie_port *pp, int where, int size, u32 val);
int (*rd_other_conf)(struct pcie_port *pp, struct pci_bus *bus, int (*rd_other_conf)(struct pcie_port *pp, struct pci_bus *bus,
...@@ -73,6 +72,8 @@ struct pcie_host_ops { ...@@ -73,6 +72,8 @@ struct pcie_host_ops {
int (*msi_host_init)(struct pcie_port *pp, struct msi_controller *chip); int (*msi_host_init)(struct pcie_port *pp, struct msi_controller *chip);
}; };
u32 dw_pcie_readl_rc(struct pcie_port *pp, u32 reg);
void dw_pcie_writel_rc(struct pcie_port *pp, u32 reg, u32 val);
int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val); int dw_pcie_cfg_read(void __iomem *addr, int size, u32 *val);
int dw_pcie_cfg_write(void __iomem *addr, int size, u32 val); int dw_pcie_cfg_write(void __iomem *addr, int size, u32 val);
irqreturn_t dw_handle_msi_irq(struct pcie_port *pp); irqreturn_t dw_handle_msi_irq(struct pcie_port *pp);
......
...@@ -22,51 +22,38 @@ ...@@ -22,51 +22,38 @@
#include "pcie-designware.h" #include "pcie-designware.h"
#define PCIE_LTSSM_LINKUP_STATE 0x11 #define PCIE_SUBCTRL_SYS_STATE4_REG 0x6818
#define PCIE_LTSSM_STATE_MASK 0x3F #define PCIE_HIP06_CTRL_OFF 0x1000
#define PCIE_SUBCTRL_SYS_STATE4_REG 0x6818 #define PCIE_SYS_STATE4 (PCIE_HIP06_CTRL_OFF + 0x31c)
#define PCIE_SYS_STATE4 0x31c #define PCIE_LTSSM_LINKUP_STATE 0x11
#define PCIE_HIP06_CTRL_OFF 0x1000 #define PCIE_LTSSM_STATE_MASK 0x3F
#define to_hisi_pcie(x) container_of(x, struct hisi_pcie, pp) #define to_hisi_pcie(x) container_of(x, struct hisi_pcie, pp)
struct hisi_pcie; struct hisi_pcie;
struct pcie_soc_ops { struct pcie_soc_ops {
int (*hisi_pcie_link_up)(struct hisi_pcie *pcie); int (*hisi_pcie_link_up)(struct hisi_pcie *hisi_pcie);
}; };
struct hisi_pcie { struct hisi_pcie {
struct pcie_port pp; /* pp.dbi_base is DT rc_dbi */
struct regmap *subctrl; struct regmap *subctrl;
void __iomem *reg_base;
u32 port_id; u32 port_id;
struct pcie_port pp;
struct pcie_soc_ops *soc_ops; struct pcie_soc_ops *soc_ops;
}; };
static inline void hisi_pcie_apb_writel(struct hisi_pcie *pcie,
u32 val, u32 reg)
{
writel(val, pcie->reg_base + reg);
}
static inline u32 hisi_pcie_apb_readl(struct hisi_pcie *pcie, u32 reg)
{
return readl(pcie->reg_base + reg);
}
/* HipXX PCIe host only supports 32-bit config access */ /* HipXX PCIe host only supports 32-bit config access */
static int hisi_pcie_cfg_read(struct pcie_port *pp, int where, int size, static int hisi_pcie_cfg_read(struct pcie_port *pp, int where, int size,
u32 *val) u32 *val)
{ {
u32 reg; u32 reg;
u32 reg_val; u32 reg_val;
struct hisi_pcie *pcie = to_hisi_pcie(pp);
void *walker = &reg_val; void *walker = &reg_val;
walker += (where & 0x3); walker += (where & 0x3);
reg = where & ~0x3; reg = where & ~0x3;
reg_val = hisi_pcie_apb_readl(pcie, reg); reg_val = dw_pcie_readl_rc(pp, reg);
if (size == 1) if (size == 1)
*val = *(u8 __force *) walker; *val = *(u8 __force *) walker;
...@@ -86,21 +73,20 @@ static int hisi_pcie_cfg_write(struct pcie_port *pp, int where, int size, ...@@ -86,21 +73,20 @@ static int hisi_pcie_cfg_write(struct pcie_port *pp, int where, int size,
{ {
u32 reg_val; u32 reg_val;
u32 reg; u32 reg;
struct hisi_pcie *pcie = to_hisi_pcie(pp);
void *walker = &reg_val; void *walker = &reg_val;
walker += (where & 0x3); walker += (where & 0x3);
reg = where & ~0x3; reg = where & ~0x3;
if (size == 4) if (size == 4)
hisi_pcie_apb_writel(pcie, val, reg); dw_pcie_writel_rc(pp, reg, val);
else if (size == 2) { else if (size == 2) {
reg_val = hisi_pcie_apb_readl(pcie, reg); reg_val = dw_pcie_readl_rc(pp, reg);
*(u16 __force *) walker = val; *(u16 __force *) walker = val;
hisi_pcie_apb_writel(pcie, reg_val, reg); dw_pcie_writel_rc(pp, reg, reg_val);
} else if (size == 1) { } else if (size == 1) {
reg_val = hisi_pcie_apb_readl(pcie, reg); reg_val = dw_pcie_readl_rc(pp, reg);
*(u8 __force *) walker = val; *(u8 __force *) walker = val;
hisi_pcie_apb_writel(pcie, reg_val, reg); dw_pcie_writel_rc(pp, reg, reg_val);
} else } else
return PCIBIOS_BAD_REGISTER_NUMBER; return PCIBIOS_BAD_REGISTER_NUMBER;
...@@ -119,10 +105,10 @@ static int hisi_pcie_link_up_hip05(struct hisi_pcie *hisi_pcie) ...@@ -119,10 +105,10 @@ static int hisi_pcie_link_up_hip05(struct hisi_pcie *hisi_pcie)
static int hisi_pcie_link_up_hip06(struct hisi_pcie *hisi_pcie) static int hisi_pcie_link_up_hip06(struct hisi_pcie *hisi_pcie)
{ {
struct pcie_port *pp = &hisi_pcie->pp;
u32 val; u32 val;
val = hisi_pcie_apb_readl(hisi_pcie, PCIE_HIP06_CTRL_OFF + val = dw_pcie_readl_rc(pp, PCIE_SYS_STATE4);
PCIE_SYS_STATE4);
return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE); return ((val & PCIE_LTSSM_STATE_MASK) == PCIE_LTSSM_LINKUP_STATE);
} }
...@@ -140,19 +126,20 @@ static struct pcie_host_ops hisi_pcie_host_ops = { ...@@ -140,19 +126,20 @@ static struct pcie_host_ops hisi_pcie_host_ops = {
.link_up = hisi_pcie_link_up, .link_up = hisi_pcie_link_up,
}; };
static int hisi_add_pcie_port(struct pcie_port *pp, static int hisi_add_pcie_port(struct hisi_pcie *hisi_pcie,
struct platform_device *pdev) struct platform_device *pdev)
{ {
struct pcie_port *pp = &hisi_pcie->pp;
struct device *dev = pp->dev;
int ret; int ret;
u32 port_id; u32 port_id;
struct hisi_pcie *hisi_pcie = to_hisi_pcie(pp);
if (of_property_read_u32(pdev->dev.of_node, "port-id", &port_id)) { if (of_property_read_u32(dev->of_node, "port-id", &port_id)) {
dev_err(&pdev->dev, "failed to read port-id\n"); dev_err(dev, "failed to read port-id\n");
return -EINVAL; return -EINVAL;
} }
if (port_id > 3) { if (port_id > 3) {
dev_err(&pdev->dev, "Invalid port-id: %d\n", port_id); dev_err(dev, "Invalid port-id: %d\n", port_id);
return -EINVAL; return -EINVAL;
} }
hisi_pcie->port_id = port_id; hisi_pcie->port_id = port_id;
...@@ -161,7 +148,7 @@ static int hisi_add_pcie_port(struct pcie_port *pp, ...@@ -161,7 +148,7 @@ static int hisi_add_pcie_port(struct pcie_port *pp,
ret = dw_pcie_host_init(pp); ret = dw_pcie_host_init(pp);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to initialize host\n"); dev_err(dev, "failed to initialize host\n");
return ret; return ret;
} }
...@@ -170,6 +157,7 @@ static int hisi_add_pcie_port(struct pcie_port *pp, ...@@ -170,6 +157,7 @@ static int hisi_add_pcie_port(struct pcie_port *pp,
static int hisi_pcie_probe(struct platform_device *pdev) static int hisi_pcie_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct hisi_pcie *hisi_pcie; struct hisi_pcie *hisi_pcie;
struct pcie_port *pp; struct pcie_port *pp;
const struct of_device_id *match; const struct of_device_id *match;
...@@ -177,40 +165,36 @@ static int hisi_pcie_probe(struct platform_device *pdev) ...@@ -177,40 +165,36 @@ static int hisi_pcie_probe(struct platform_device *pdev)
struct device_driver *driver; struct device_driver *driver;
int ret; int ret;
hisi_pcie = devm_kzalloc(&pdev->dev, sizeof(*hisi_pcie), GFP_KERNEL); hisi_pcie = devm_kzalloc(dev, sizeof(*hisi_pcie), GFP_KERNEL);
if (!hisi_pcie) if (!hisi_pcie)
return -ENOMEM; return -ENOMEM;
pp = &hisi_pcie->pp; pp = &hisi_pcie->pp;
pp->dev = &pdev->dev; pp->dev = dev;
driver = (pdev->dev).driver; driver = dev->driver;
match = of_match_device(driver->of_match_table, &pdev->dev); match = of_match_device(driver->of_match_table, dev);
hisi_pcie->soc_ops = (struct pcie_soc_ops *) match->data; hisi_pcie->soc_ops = (struct pcie_soc_ops *) match->data;
hisi_pcie->subctrl = hisi_pcie->subctrl =
syscon_regmap_lookup_by_compatible("hisilicon,pcie-sas-subctrl"); syscon_regmap_lookup_by_compatible("hisilicon,pcie-sas-subctrl");
if (IS_ERR(hisi_pcie->subctrl)) { if (IS_ERR(hisi_pcie->subctrl)) {
dev_err(pp->dev, "cannot get subctrl base\n"); dev_err(dev, "cannot get subctrl base\n");
return PTR_ERR(hisi_pcie->subctrl); return PTR_ERR(hisi_pcie->subctrl);
} }
reg = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc_dbi"); reg = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc_dbi");
hisi_pcie->reg_base = devm_ioremap_resource(&pdev->dev, reg); pp->dbi_base = devm_ioremap_resource(dev, reg);
if (IS_ERR(hisi_pcie->reg_base)) { if (IS_ERR(pp->dbi_base)) {
dev_err(pp->dev, "cannot get rc_dbi base\n"); dev_err(dev, "cannot get rc_dbi base\n");
return PTR_ERR(hisi_pcie->reg_base); return PTR_ERR(pp->dbi_base);
} }
hisi_pcie->pp.dbi_base = hisi_pcie->reg_base; ret = hisi_add_pcie_port(hisi_pcie, pdev);
ret = hisi_add_pcie_port(pp, pdev);
if (ret) if (ret)
return ret; return ret;
platform_set_drvdata(pdev, hisi_pcie); dev_warn(dev, "only 32-bit config accesses supported; smaller writes may corrupt adjacent RW1C fields\n");
dev_warn(pp->dev, "only 32-bit config accesses supported; smaller writes may corrupt adjacent RW1C fields\n");
return 0; return 0;
} }
......
...@@ -42,19 +42,24 @@ static int iproc_pcie_bcma_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) ...@@ -42,19 +42,24 @@ static int iproc_pcie_bcma_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
static int iproc_pcie_bcma_probe(struct bcma_device *bdev) static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
{ {
struct device *dev = &bdev->dev;
struct iproc_pcie *pcie; struct iproc_pcie *pcie;
LIST_HEAD(res); LIST_HEAD(res);
struct resource res_mem; struct resource res_mem;
int ret; int ret;
pcie = devm_kzalloc(&bdev->dev, sizeof(*pcie), GFP_KERNEL); pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
if (!pcie) if (!pcie)
return -ENOMEM; return -ENOMEM;
pcie->dev = &bdev->dev; pcie->dev = dev;
bcma_set_drvdata(bdev, pcie);
pcie->base = bdev->io_addr; pcie->base = bdev->io_addr;
if (!pcie->base) {
dev_err(dev, "no controller registers\n");
return -ENOMEM;
}
pcie->base_addr = bdev->addr; pcie->base_addr = bdev->addr;
res_mem.start = bdev->addr_s[0]; res_mem.start = bdev->addr_s[0];
...@@ -67,10 +72,11 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev) ...@@ -67,10 +72,11 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
ret = iproc_pcie_setup(pcie, &res); ret = iproc_pcie_setup(pcie, &res);
if (ret) if (ret)
dev_err(pcie->dev, "PCIe controller setup failed\n"); dev_err(dev, "PCIe controller setup failed\n");
pci_free_resource_list(&res); pci_free_resource_list(&res);
bcma_set_drvdata(bdev, pcie);
return ret; return ret;
} }
......
...@@ -40,35 +40,35 @@ MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table); ...@@ -40,35 +40,35 @@ MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
static int iproc_pcie_pltfm_probe(struct platform_device *pdev) static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
const struct of_device_id *of_id; const struct of_device_id *of_id;
struct iproc_pcie *pcie; struct iproc_pcie *pcie;
struct device_node *np = pdev->dev.of_node; struct device_node *np = dev->of_node;
struct resource reg; struct resource reg;
resource_size_t iobase = 0; resource_size_t iobase = 0;
LIST_HEAD(res); LIST_HEAD(res);
int ret; int ret;
of_id = of_match_device(iproc_pcie_of_match_table, &pdev->dev); of_id = of_match_device(iproc_pcie_of_match_table, dev);
if (!of_id) if (!of_id)
return -EINVAL; return -EINVAL;
pcie = devm_kzalloc(&pdev->dev, sizeof(struct iproc_pcie), GFP_KERNEL); pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
if (!pcie) if (!pcie)
return -ENOMEM; return -ENOMEM;
pcie->dev = &pdev->dev; pcie->dev = dev;
pcie->type = (enum iproc_pcie_type)of_id->data; pcie->type = (enum iproc_pcie_type)of_id->data;
platform_set_drvdata(pdev, pcie);
ret = of_address_to_resource(np, 0, &reg); ret = of_address_to_resource(np, 0, &reg);
if (ret < 0) { if (ret < 0) {
dev_err(pcie->dev, "unable to obtain controller resources\n"); dev_err(dev, "unable to obtain controller resources\n");
return ret; return ret;
} }
pcie->base = devm_ioremap(pcie->dev, reg.start, resource_size(&reg)); pcie->base = devm_ioremap(dev, reg.start, resource_size(&reg));
if (!pcie->base) { if (!pcie->base) {
dev_err(pcie->dev, "unable to map controller registers\n"); dev_err(dev, "unable to map controller registers\n");
return -ENOMEM; return -ENOMEM;
} }
pcie->base_addr = reg.start; pcie->base_addr = reg.start;
...@@ -79,7 +79,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev) ...@@ -79,7 +79,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset", ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset",
&val); &val);
if (ret) { if (ret) {
dev_err(pcie->dev, dev_err(dev,
"missing brcm,pcie-ob-axi-offset property\n"); "missing brcm,pcie-ob-axi-offset property\n");
return ret; return ret;
} }
...@@ -88,7 +88,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev) ...@@ -88,7 +88,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
ret = of_property_read_u32(np, "brcm,pcie-ob-window-size", ret = of_property_read_u32(np, "brcm,pcie-ob-window-size",
&val); &val);
if (ret) { if (ret) {
dev_err(pcie->dev, dev_err(dev,
"missing brcm,pcie-ob-window-size property\n"); "missing brcm,pcie-ob-window-size property\n");
return ret; return ret;
} }
...@@ -101,7 +101,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev) ...@@ -101,7 +101,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
} }
/* PHY use is optional */ /* PHY use is optional */
pcie->phy = devm_phy_get(&pdev->dev, "pcie-phy"); pcie->phy = devm_phy_get(dev, "pcie-phy");
if (IS_ERR(pcie->phy)) { if (IS_ERR(pcie->phy)) {
if (PTR_ERR(pcie->phy) == -EPROBE_DEFER) if (PTR_ERR(pcie->phy) == -EPROBE_DEFER)
return -EPROBE_DEFER; return -EPROBE_DEFER;
...@@ -110,7 +110,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev) ...@@ -110,7 +110,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &iobase); ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &iobase);
if (ret) { if (ret) {
dev_err(pcie->dev, dev_err(dev,
"unable to get PCI host bridge resources\n"); "unable to get PCI host bridge resources\n");
return ret; return ret;
} }
...@@ -119,10 +119,11 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev) ...@@ -119,10 +119,11 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
ret = iproc_pcie_setup(pcie, &res); ret = iproc_pcie_setup(pcie, &res);
if (ret) if (ret)
dev_err(pcie->dev, "PCIe controller setup failed\n"); dev_err(dev, "PCIe controller setup failed\n");
pci_free_resource_list(&res); pci_free_resource_list(&res);
platform_set_drvdata(pdev, pcie);
return ret; return ret;
} }
......
This diff is collapsed.
...@@ -86,12 +86,10 @@ struct qcom_pcie_ops { ...@@ -86,12 +86,10 @@ struct qcom_pcie_ops {
}; };
struct qcom_pcie { struct qcom_pcie {
struct pcie_port pp; struct pcie_port pp; /* pp.dbi_base is DT dbi */
struct device *dev; void __iomem *parf; /* DT parf */
void __iomem *elbi; /* DT elbi */
union qcom_pcie_resources res; union qcom_pcie_resources res;
void __iomem *parf;
void __iomem *dbi;
void __iomem *elbi;
struct phy *phy; struct phy *phy;
struct gpio_desc *reset; struct gpio_desc *reset;
struct qcom_pcie_ops *ops; struct qcom_pcie_ops *ops;
...@@ -136,7 +134,7 @@ static int qcom_pcie_establish_link(struct qcom_pcie *pcie) ...@@ -136,7 +134,7 @@ static int qcom_pcie_establish_link(struct qcom_pcie *pcie)
static int qcom_pcie_get_resources_v0(struct qcom_pcie *pcie) static int qcom_pcie_get_resources_v0(struct qcom_pcie *pcie)
{ {
struct qcom_pcie_resources_v0 *res = &pcie->res.v0; struct qcom_pcie_resources_v0 *res = &pcie->res.v0;
struct device *dev = pcie->dev; struct device *dev = pcie->pp.dev;
res->vdda = devm_regulator_get(dev, "vdda"); res->vdda = devm_regulator_get(dev, "vdda");
if (IS_ERR(res->vdda)) if (IS_ERR(res->vdda))
...@@ -188,7 +186,7 @@ static int qcom_pcie_get_resources_v0(struct qcom_pcie *pcie) ...@@ -188,7 +186,7 @@ static int qcom_pcie_get_resources_v0(struct qcom_pcie *pcie)
static int qcom_pcie_get_resources_v1(struct qcom_pcie *pcie) static int qcom_pcie_get_resources_v1(struct qcom_pcie *pcie)
{ {
struct qcom_pcie_resources_v1 *res = &pcie->res.v1; struct qcom_pcie_resources_v1 *res = &pcie->res.v1;
struct device *dev = pcie->dev; struct device *dev = pcie->pp.dev;
res->vdda = devm_regulator_get(dev, "vdda"); res->vdda = devm_regulator_get(dev, "vdda");
if (IS_ERR(res->vdda)) if (IS_ERR(res->vdda))
...@@ -237,7 +235,7 @@ static void qcom_pcie_deinit_v0(struct qcom_pcie *pcie) ...@@ -237,7 +235,7 @@ static void qcom_pcie_deinit_v0(struct qcom_pcie *pcie)
static int qcom_pcie_init_v0(struct qcom_pcie *pcie) static int qcom_pcie_init_v0(struct qcom_pcie *pcie)
{ {
struct qcom_pcie_resources_v0 *res = &pcie->res.v0; struct qcom_pcie_resources_v0 *res = &pcie->res.v0;
struct device *dev = pcie->dev; struct device *dev = pcie->pp.dev;
u32 val; u32 val;
int ret; int ret;
...@@ -359,7 +357,7 @@ static void qcom_pcie_deinit_v1(struct qcom_pcie *pcie) ...@@ -359,7 +357,7 @@ static void qcom_pcie_deinit_v1(struct qcom_pcie *pcie)
static int qcom_pcie_init_v1(struct qcom_pcie *pcie) static int qcom_pcie_init_v1(struct qcom_pcie *pcie)
{ {
struct qcom_pcie_resources_v1 *res = &pcie->res.v1; struct qcom_pcie_resources_v1 *res = &pcie->res.v1;
struct device *dev = pcie->dev; struct device *dev = pcie->pp.dev;
int ret; int ret;
ret = reset_control_deassert(res->core); ret = reset_control_deassert(res->core);
...@@ -426,7 +424,7 @@ static int qcom_pcie_init_v1(struct qcom_pcie *pcie) ...@@ -426,7 +424,7 @@ static int qcom_pcie_init_v1(struct qcom_pcie *pcie)
static int qcom_pcie_link_up(struct pcie_port *pp) static int qcom_pcie_link_up(struct pcie_port *pp)
{ {
struct qcom_pcie *pcie = to_qcom_pcie(pp); struct qcom_pcie *pcie = to_qcom_pcie(pp);
u16 val = readw(pcie->dbi + PCIE20_CAP + PCI_EXP_LNKSTA); u16 val = readw(pcie->pp.dbi_base + PCIE20_CAP + PCI_EXP_LNKSTA);
return !!(val & PCI_EXP_LNKSTA_DLLLA); return !!(val & PCI_EXP_LNKSTA_DLLLA);
} }
...@@ -509,8 +507,8 @@ static int qcom_pcie_probe(struct platform_device *pdev) ...@@ -509,8 +507,8 @@ static int qcom_pcie_probe(struct platform_device *pdev)
if (!pcie) if (!pcie)
return -ENOMEM; return -ENOMEM;
pp = &pcie->pp;
pcie->ops = (struct qcom_pcie_ops *)of_device_get_match_data(dev); pcie->ops = (struct qcom_pcie_ops *)of_device_get_match_data(dev);
pcie->dev = dev;
pcie->reset = devm_gpiod_get_optional(dev, "perst", GPIOD_OUT_LOW); pcie->reset = devm_gpiod_get_optional(dev, "perst", GPIOD_OUT_LOW);
if (IS_ERR(pcie->reset)) if (IS_ERR(pcie->reset))
...@@ -522,9 +520,9 @@ static int qcom_pcie_probe(struct platform_device *pdev) ...@@ -522,9 +520,9 @@ static int qcom_pcie_probe(struct platform_device *pdev)
return PTR_ERR(pcie->parf); return PTR_ERR(pcie->parf);
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dbi");
pcie->dbi = devm_ioremap_resource(dev, res); pp->dbi_base = devm_ioremap_resource(dev, res);
if (IS_ERR(pcie->dbi)) if (IS_ERR(pp->dbi_base))
return PTR_ERR(pcie->dbi); return PTR_ERR(pp->dbi_base);
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "elbi"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "elbi");
pcie->elbi = devm_ioremap_resource(dev, res); pcie->elbi = devm_ioremap_resource(dev, res);
...@@ -539,9 +537,7 @@ static int qcom_pcie_probe(struct platform_device *pdev) ...@@ -539,9 +537,7 @@ static int qcom_pcie_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
pp = &pcie->pp;
pp->dev = dev; pp->dev = dev;
pp->dbi_base = pcie->dbi;
pp->root_bus_nr = -1; pp->root_bus_nr = -1;
pp->ops = &qcom_pcie_dw_ops; pp->ops = &qcom_pcie_dw_ops;
...@@ -569,8 +565,6 @@ static int qcom_pcie_probe(struct platform_device *pdev) ...@@ -569,8 +565,6 @@ static int qcom_pcie_probe(struct platform_device *pdev)
return ret; return ret;
} }
platform_set_drvdata(pdev, pcie);
return 0; return 0;
} }
......
This diff is collapsed.
...@@ -972,7 +972,7 @@ static int rockchip_pcie_prog_ob_atu(struct rockchip_pcie *rockchip, ...@@ -972,7 +972,7 @@ static int rockchip_pcie_prog_ob_atu(struct rockchip_pcie *rockchip,
return -EINVAL; return -EINVAL;
if (region_no == 0) { if (region_no == 0) {
if (AXI_REGION_0_SIZE < (2ULL << num_pass_bits)) if (AXI_REGION_0_SIZE < (2ULL << num_pass_bits))
return -EINVAL; return -EINVAL;
} }
if (region_no != 0) { if (region_no != 0) {
if (AXI_REGION_SIZE < (2ULL << num_pass_bits)) if (AXI_REGION_SIZE < (2ULL << num_pass_bits))
...@@ -1091,8 +1091,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev) ...@@ -1091,8 +1091,6 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
if (err) if (err)
goto err_vpcie; goto err_vpcie;
platform_set_drvdata(pdev, rockchip);
rockchip_pcie_enable_interrupts(rockchip); rockchip_pcie_enable_interrupts(rockchip);
err = rockchip_pcie_init_irq_domain(rockchip); err = rockchip_pcie_init_irq_domain(rockchip);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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