Commit dd5bba52 authored by Bjorn Helgaas's avatar Bjorn Helgaas

Merge branches 'pci/host-aardvark', 'pci/host-altera', 'pci/host-iproc',...

Merge branches 'pci/host-aardvark', 'pci/host-altera', 'pci/host-iproc', 'pci/host-mvebu', 'pci/host-rcar', 'pci/host-rockchip', 'pci/host-tegra', 'pci/host-xgene' and 'pci/host-xilinx' into next

* pci/host-aardvark:
  MAINTAINERS: Add DT binding to the Aardvark PCIe driver maintainer
  PCI: aardvark: Remove unused platform data
  PCI: aardvark: Add local struct device pointers

* pci/host-altera:
  PCI: altera: Simplify TLP_CFG_DW1 usage
  PCI: altera: Simplify TLB_CFG_DW0 usage
  PCI: altera: Rename altera_pcie_valid_config() to altera_pcie_valid_device()
  PCI: altera: Remove redundant platform_get_resource() return value check
  PCI: altera: Remove unused platform data
  PCI: altera: Add local struct device pointers

* pci/host-iproc:
  PCI: iproc: Hard-code PCIe capability offset instead of searching
  PCI: iproc: Remove redundant null pointer checking
  PCI: iproc: Validate CSR base in BCMA setup code
  PCI: iproc: Set drvdata at end of probe function
  PCI: iproc: Add local struct device pointers

* pci/host-mvebu:
  PCI: mvebu: Use existing of_node pointer
  PCI: mvebu: Add local struct device pointers

* pci/host-rcar:
  PCI: rcar-gen2: Add local struct device pointers
  PCI: rcar: Remove DRV_NAME macro
  PCI: rcar: Remove unused rcar_pcie_get_resources() platform_device arg
  PCI: rcar: Remove unused platform data
  PCI: rcar: Add local struct device pointers

* pci/host-rockchip:
  PCI: rockchip: Indent "if" statement body
  PCI: rockchip: Remove unused platform data

* pci/host-tegra:
  PCI: tegra: Remove unused platform data
  PCI: tegra: Add local struct device pointers
  PCI: tegra: Fix argument order in tegra_pcie_phy_disable()

* pci/host-xgene:
  PCI: xgene: Add register accessors
  PCI: xgene: Pass struct xgene_pcie_port to setup functions
  PCI: xgene: Remove unused platform data
  PCI: xgene: Add local struct device pointers

* pci/host-xilinx:
  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
...@@ -8982,6 +8982,7 @@ M: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> ...@@ -8982,6 +8982,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;
} }
......
...@@ -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;
} }
......
...@@ -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;
} }
......
...@@ -63,6 +63,8 @@ ...@@ -63,6 +63,8 @@
#define OARR_SIZE_CFG_SHIFT 1 #define OARR_SIZE_CFG_SHIFT 1
#define OARR_SIZE_CFG BIT(OARR_SIZE_CFG_SHIFT) #define OARR_SIZE_CFG BIT(OARR_SIZE_CFG_SHIFT)
#define PCI_EXP_CAP 0xac
#define MAX_NUM_OB_WINDOWS 2 #define MAX_NUM_OB_WINDOWS 2
#define IPROC_PCIE_REG_INVALID 0xffff #define IPROC_PCIE_REG_INVALID 0xffff
...@@ -258,9 +260,10 @@ static void iproc_pcie_reset(struct iproc_pcie *pcie) ...@@ -258,9 +260,10 @@ static void iproc_pcie_reset(struct iproc_pcie *pcie)
static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus) static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
{ {
struct device *dev = pcie->dev;
u8 hdr_type; u8 hdr_type;
u32 link_ctrl, class, val; u32 link_ctrl, class, val;
u16 pos, link_status; u16 pos = PCI_EXP_CAP, link_status;
bool link_is_active = false; bool link_is_active = false;
/* /*
...@@ -272,14 +275,14 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus) ...@@ -272,14 +275,14 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
val = iproc_pcie_read_reg(pcie, IPROC_PCIE_LINK_STATUS); val = iproc_pcie_read_reg(pcie, IPROC_PCIE_LINK_STATUS);
if (!(val & PCIE_PHYLINKUP) || !(val & PCIE_DL_ACTIVE)) { if (!(val & PCIE_PHYLINKUP) || !(val & PCIE_DL_ACTIVE)) {
dev_err(pcie->dev, "PHY or data link is INACTIVE!\n"); dev_err(dev, "PHY or data link is INACTIVE!\n");
return -ENODEV; return -ENODEV;
} }
/* make sure we are not in EP mode */ /* make sure we are not in EP mode */
pci_bus_read_config_byte(bus, 0, PCI_HEADER_TYPE, &hdr_type); pci_bus_read_config_byte(bus, 0, PCI_HEADER_TYPE, &hdr_type);
if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE) { if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE) {
dev_err(pcie->dev, "in EP mode, hdr=%#02x\n", hdr_type); dev_err(dev, "in EP mode, hdr=%#02x\n", hdr_type);
return -EFAULT; return -EFAULT;
} }
...@@ -293,30 +296,27 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus) ...@@ -293,30 +296,27 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
pci_bus_write_config_dword(bus, 0, PCI_BRIDGE_CTRL_REG_OFFSET, class); pci_bus_write_config_dword(bus, 0, PCI_BRIDGE_CTRL_REG_OFFSET, class);
/* check link status to see if link is active */ /* check link status to see if link is active */
pos = pci_bus_find_capability(bus, 0, PCI_CAP_ID_EXP);
pci_bus_read_config_word(bus, 0, pos + PCI_EXP_LNKSTA, &link_status); pci_bus_read_config_word(bus, 0, pos + PCI_EXP_LNKSTA, &link_status);
if (link_status & PCI_EXP_LNKSTA_NLW) if (link_status & PCI_EXP_LNKSTA_NLW)
link_is_active = true; link_is_active = true;
if (!link_is_active) { if (!link_is_active) {
/* try GEN 1 link speed */ /* try GEN 1 link speed */
#define PCI_LINK_STATUS_CTRL_2_OFFSET 0x0dc
#define PCI_TARGET_LINK_SPEED_MASK 0xf #define PCI_TARGET_LINK_SPEED_MASK 0xf
#define PCI_TARGET_LINK_SPEED_GEN2 0x2 #define PCI_TARGET_LINK_SPEED_GEN2 0x2
#define PCI_TARGET_LINK_SPEED_GEN1 0x1 #define PCI_TARGET_LINK_SPEED_GEN1 0x1
pci_bus_read_config_dword(bus, 0, pci_bus_read_config_dword(bus, 0,
PCI_LINK_STATUS_CTRL_2_OFFSET, pos + PCI_EXP_LNKCTL2,
&link_ctrl); &link_ctrl);
if ((link_ctrl & PCI_TARGET_LINK_SPEED_MASK) == if ((link_ctrl & PCI_TARGET_LINK_SPEED_MASK) ==
PCI_TARGET_LINK_SPEED_GEN2) { PCI_TARGET_LINK_SPEED_GEN2) {
link_ctrl &= ~PCI_TARGET_LINK_SPEED_MASK; link_ctrl &= ~PCI_TARGET_LINK_SPEED_MASK;
link_ctrl |= PCI_TARGET_LINK_SPEED_GEN1; link_ctrl |= PCI_TARGET_LINK_SPEED_GEN1;
pci_bus_write_config_dword(bus, 0, pci_bus_write_config_dword(bus, 0,
PCI_LINK_STATUS_CTRL_2_OFFSET, pos + PCI_EXP_LNKCTL2,
link_ctrl); link_ctrl);
msleep(100); msleep(100);
pos = pci_bus_find_capability(bus, 0, PCI_CAP_ID_EXP);
pci_bus_read_config_word(bus, 0, pos + PCI_EXP_LNKSTA, pci_bus_read_config_word(bus, 0, pos + PCI_EXP_LNKSTA,
&link_status); &link_status);
if (link_status & PCI_EXP_LNKSTA_NLW) if (link_status & PCI_EXP_LNKSTA_NLW)
...@@ -324,7 +324,7 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus) ...@@ -324,7 +324,7 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
} }
} }
dev_info(pcie->dev, "link: %s\n", link_is_active ? "UP" : "DOWN"); dev_info(dev, "link: %s\n", link_is_active ? "UP" : "DOWN");
return link_is_active ? 0 : -ENODEV; return link_is_active ? 0 : -ENODEV;
} }
...@@ -349,12 +349,13 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr, ...@@ -349,12 +349,13 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr,
u64 pci_addr, resource_size_t size) u64 pci_addr, resource_size_t size)
{ {
struct iproc_pcie_ob *ob = &pcie->ob; struct iproc_pcie_ob *ob = &pcie->ob;
struct device *dev = pcie->dev;
unsigned i; unsigned i;
u64 max_size = (u64)ob->window_size * MAX_NUM_OB_WINDOWS; u64 max_size = (u64)ob->window_size * MAX_NUM_OB_WINDOWS;
u64 remainder; u64 remainder;
if (size > max_size) { if (size > max_size) {
dev_err(pcie->dev, dev_err(dev,
"res size %pap exceeds max supported size 0x%llx\n", "res size %pap exceeds max supported size 0x%llx\n",
&size, max_size); &size, max_size);
return -EINVAL; return -EINVAL;
...@@ -362,15 +363,14 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr, ...@@ -362,15 +363,14 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr,
div64_u64_rem(size, ob->window_size, &remainder); div64_u64_rem(size, ob->window_size, &remainder);
if (remainder) { if (remainder) {
dev_err(pcie->dev, dev_err(dev,
"res size %pap needs to be multiple of window size %pap\n", "res size %pap needs to be multiple of window size %pap\n",
&size, &ob->window_size); &size, &ob->window_size);
return -EINVAL; return -EINVAL;
} }
if (axi_addr < ob->axi_offset) { if (axi_addr < ob->axi_offset) {
dev_err(pcie->dev, dev_err(dev, "axi address %pap less than offset %pap\n",
"axi address %pap less than offset %pap\n",
&axi_addr, &ob->axi_offset); &axi_addr, &ob->axi_offset);
return -EINVAL; return -EINVAL;
} }
...@@ -406,6 +406,7 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr, ...@@ -406,6 +406,7 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr,
static int iproc_pcie_map_ranges(struct iproc_pcie *pcie, static int iproc_pcie_map_ranges(struct iproc_pcie *pcie,
struct list_head *resources) struct list_head *resources)
{ {
struct device *dev = pcie->dev;
struct resource_entry *window; struct resource_entry *window;
int ret; int ret;
...@@ -425,7 +426,7 @@ static int iproc_pcie_map_ranges(struct iproc_pcie *pcie, ...@@ -425,7 +426,7 @@ static int iproc_pcie_map_ranges(struct iproc_pcie *pcie,
return ret; return ret;
break; break;
default: default:
dev_err(pcie->dev, "invalid resource %pR\n", res); dev_err(dev, "invalid resource %pR\n", res);
return -EINVAL; return -EINVAL;
} }
} }
...@@ -455,26 +456,25 @@ static void iproc_pcie_msi_disable(struct iproc_pcie *pcie) ...@@ -455,26 +456,25 @@ static void iproc_pcie_msi_disable(struct iproc_pcie *pcie)
int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
{ {
struct device *dev;
int ret; int ret;
void *sysdata; void *sysdata;
struct pci_bus *bus; struct pci_bus *bus;
if (!pcie || !pcie->dev || !pcie->base) dev = pcie->dev;
return -EINVAL; ret = devm_request_pci_bus_resources(dev, res);
ret = devm_request_pci_bus_resources(pcie->dev, res);
if (ret) if (ret)
return ret; return ret;
ret = phy_init(pcie->phy); ret = phy_init(pcie->phy);
if (ret) { if (ret) {
dev_err(pcie->dev, "unable to initialize PCIe PHY\n"); dev_err(dev, "unable to initialize PCIe PHY\n");
return ret; return ret;
} }
ret = phy_power_on(pcie->phy); ret = phy_power_on(pcie->phy);
if (ret) { if (ret) {
dev_err(pcie->dev, "unable to power on PCIe PHY\n"); dev_err(dev, "unable to power on PCIe PHY\n");
goto err_exit_phy; goto err_exit_phy;
} }
...@@ -486,7 +486,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) ...@@ -486,7 +486,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
pcie->reg_offsets = iproc_pcie_reg_paxc; pcie->reg_offsets = iproc_pcie_reg_paxc;
break; break;
default: default:
dev_err(pcie->dev, "incompatible iProc PCIe interface\n"); dev_err(dev, "incompatible iProc PCIe interface\n");
ret = -EINVAL; ret = -EINVAL;
goto err_power_off_phy; goto err_power_off_phy;
} }
...@@ -496,7 +496,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) ...@@ -496,7 +496,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
if (pcie->need_ob_cfg) { if (pcie->need_ob_cfg) {
ret = iproc_pcie_map_ranges(pcie, res); ret = iproc_pcie_map_ranges(pcie, res);
if (ret) { if (ret) {
dev_err(pcie->dev, "map failed\n"); dev_err(dev, "map failed\n");
goto err_power_off_phy; goto err_power_off_phy;
} }
} }
...@@ -508,9 +508,9 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) ...@@ -508,9 +508,9 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
sysdata = pcie; sysdata = pcie;
#endif #endif
bus = pci_create_root_bus(pcie->dev, 0, &iproc_pcie_ops, sysdata, res); bus = pci_create_root_bus(dev, 0, &iproc_pcie_ops, sysdata, res);
if (!bus) { if (!bus) {
dev_err(pcie->dev, "unable to create PCI root bus\n"); dev_err(dev, "unable to create PCI root bus\n");
ret = -ENOMEM; ret = -ENOMEM;
goto err_power_off_phy; goto err_power_off_phy;
} }
...@@ -518,7 +518,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) ...@@ -518,7 +518,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
ret = iproc_pcie_check_link(pcie, bus); ret = iproc_pcie_check_link(pcie, bus);
if (ret) { if (ret) {
dev_err(pcie->dev, "no PCIe EP device detected\n"); dev_err(dev, "no PCIe EP device detected\n");
goto err_rm_root_bus; goto err_rm_root_bus;
} }
...@@ -526,7 +526,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) ...@@ -526,7 +526,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
if (IS_ENABLED(CONFIG_PCI_MSI)) if (IS_ENABLED(CONFIG_PCI_MSI))
if (iproc_pcie_msi_enable(pcie)) if (iproc_pcie_msi_enable(pcie))
dev_info(pcie->dev, "not using iProc MSI\n"); dev_info(dev, "not using iProc MSI\n");
pci_scan_child_bus(bus); pci_scan_child_bus(bus);
pci_assign_unassigned_bus_resources(bus); pci_assign_unassigned_bus_resources(bus);
......
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/slab.h> #include <linux/slab.h>
#define DRV_NAME "rcar-pcie"
#define PCIECAR 0x000010 #define PCIECAR 0x000010
#define PCIECCTLR 0x000018 #define PCIECCTLR 0x000018
#define CONFIG_SEND_ENABLE (1 << 31) #define CONFIG_SEND_ENABLE (1 << 31)
...@@ -397,6 +395,7 @@ static int rcar_pcie_setup(struct list_head *resource, struct rcar_pcie *pci) ...@@ -397,6 +395,7 @@ static int rcar_pcie_setup(struct list_head *resource, struct rcar_pcie *pci)
static void rcar_pcie_force_speedup(struct rcar_pcie *pcie) static void rcar_pcie_force_speedup(struct rcar_pcie *pcie)
{ {
struct device *dev = pcie->dev;
unsigned int timeout = 1000; unsigned int timeout = 1000;
u32 macsr; u32 macsr;
...@@ -404,7 +403,7 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie) ...@@ -404,7 +403,7 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie)
return; return;
if (rcar_pci_read_reg(pcie, MACCTLR) & SPEED_CHANGE) { if (rcar_pci_read_reg(pcie, MACCTLR) & SPEED_CHANGE) {
dev_err(pcie->dev, "Speed change already in progress\n"); dev_err(dev, "Speed change already in progress\n");
return; return;
} }
...@@ -433,7 +432,7 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie) ...@@ -433,7 +432,7 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie)
rcar_pci_write_reg(pcie, macsr, MACSR); rcar_pci_write_reg(pcie, macsr, MACSR);
if (macsr & SPCHGFAIL) if (macsr & SPCHGFAIL)
dev_err(pcie->dev, "Speed change failed\n"); dev_err(dev, "Speed change failed\n");
goto done; goto done;
} }
...@@ -441,15 +440,16 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie) ...@@ -441,15 +440,16 @@ static void rcar_pcie_force_speedup(struct rcar_pcie *pcie)
msleep(1); msleep(1);
}; };
dev_err(pcie->dev, "Speed change timed out\n"); dev_err(dev, "Speed change timed out\n");
done: done:
dev_info(pcie->dev, "Current link speed is %s GT/s\n", dev_info(dev, "Current link speed is %s GT/s\n",
(macsr & LINK_SPEED) == LINK_SPEED_5_0GTS ? "5" : "2.5"); (macsr & LINK_SPEED) == LINK_SPEED_5_0GTS ? "5" : "2.5");
} }
static int rcar_pcie_enable(struct rcar_pcie *pcie) static int rcar_pcie_enable(struct rcar_pcie *pcie)
{ {
struct device *dev = pcie->dev;
struct pci_bus *bus, *child; struct pci_bus *bus, *child;
LIST_HEAD(res); LIST_HEAD(res);
...@@ -461,14 +461,14 @@ static int rcar_pcie_enable(struct rcar_pcie *pcie) ...@@ -461,14 +461,14 @@ static int rcar_pcie_enable(struct rcar_pcie *pcie)
pci_add_flags(PCI_REASSIGN_ALL_RSRC | PCI_REASSIGN_ALL_BUS); pci_add_flags(PCI_REASSIGN_ALL_RSRC | PCI_REASSIGN_ALL_BUS);
if (IS_ENABLED(CONFIG_PCI_MSI)) if (IS_ENABLED(CONFIG_PCI_MSI))
bus = pci_scan_root_bus_msi(pcie->dev, pcie->root_bus_nr, bus = pci_scan_root_bus_msi(dev, pcie->root_bus_nr,
&rcar_pcie_ops, pcie, &res, &pcie->msi.chip); &rcar_pcie_ops, pcie, &res, &pcie->msi.chip);
else else
bus = pci_scan_root_bus(pcie->dev, pcie->root_bus_nr, bus = pci_scan_root_bus(dev, pcie->root_bus_nr,
&rcar_pcie_ops, pcie, &res); &rcar_pcie_ops, pcie, &res);
if (!bus) { if (!bus) {
dev_err(pcie->dev, "Scanning rootbus failed"); dev_err(dev, "Scanning rootbus failed");
return -ENODEV; return -ENODEV;
} }
...@@ -487,6 +487,7 @@ static int rcar_pcie_enable(struct rcar_pcie *pcie) ...@@ -487,6 +487,7 @@ static int rcar_pcie_enable(struct rcar_pcie *pcie)
static int phy_wait_for_ack(struct rcar_pcie *pcie) static int phy_wait_for_ack(struct rcar_pcie *pcie)
{ {
struct device *dev = pcie->dev;
unsigned int timeout = 100; unsigned int timeout = 100;
while (timeout--) { while (timeout--) {
...@@ -496,7 +497,7 @@ static int phy_wait_for_ack(struct rcar_pcie *pcie) ...@@ -496,7 +497,7 @@ static int phy_wait_for_ack(struct rcar_pcie *pcie)
udelay(100); udelay(100);
} }
dev_err(pcie->dev, "Access to PCIe phy timed out\n"); dev_err(dev, "Access to PCIe phy timed out\n");
return -ETIMEDOUT; return -ETIMEDOUT;
} }
...@@ -697,6 +698,7 @@ static irqreturn_t rcar_pcie_msi_irq(int irq, void *data) ...@@ -697,6 +698,7 @@ static irqreturn_t rcar_pcie_msi_irq(int irq, void *data)
{ {
struct rcar_pcie *pcie = data; struct rcar_pcie *pcie = data;
struct rcar_msi *msi = &pcie->msi; struct rcar_msi *msi = &pcie->msi;
struct device *dev = pcie->dev;
unsigned long reg; unsigned long reg;
reg = rcar_pci_read_reg(pcie, PCIEMSIFR); reg = rcar_pci_read_reg(pcie, PCIEMSIFR);
...@@ -717,10 +719,10 @@ static irqreturn_t rcar_pcie_msi_irq(int irq, void *data) ...@@ -717,10 +719,10 @@ static irqreturn_t rcar_pcie_msi_irq(int irq, void *data)
if (test_bit(index, msi->used)) if (test_bit(index, msi->used))
generic_handle_irq(irq); generic_handle_irq(irq);
else else
dev_info(pcie->dev, "unhandled MSI\n"); dev_info(dev, "unhandled MSI\n");
} else { } else {
/* Unknown MSI, just clear it */ /* Unknown MSI, just clear it */
dev_dbg(pcie->dev, "unexpected MSI\n"); dev_dbg(dev, "unexpected MSI\n");
} }
/* see if there's any more pending in this vector */ /* see if there's any more pending in this vector */
...@@ -843,22 +845,22 @@ static const struct irq_domain_ops msi_domain_ops = { ...@@ -843,22 +845,22 @@ static const struct irq_domain_ops msi_domain_ops = {
static int rcar_pcie_enable_msi(struct rcar_pcie *pcie) static int rcar_pcie_enable_msi(struct rcar_pcie *pcie)
{ {
struct platform_device *pdev = to_platform_device(pcie->dev); struct device *dev = pcie->dev;
struct rcar_msi *msi = &pcie->msi; struct rcar_msi *msi = &pcie->msi;
unsigned long base; unsigned long base;
int err, i; int err, i;
mutex_init(&msi->lock); mutex_init(&msi->lock);
msi->chip.dev = pcie->dev; msi->chip.dev = dev;
msi->chip.setup_irq = rcar_msi_setup_irq; msi->chip.setup_irq = rcar_msi_setup_irq;
msi->chip.setup_irqs = rcar_msi_setup_irqs; msi->chip.setup_irqs = rcar_msi_setup_irqs;
msi->chip.teardown_irq = rcar_msi_teardown_irq; msi->chip.teardown_irq = rcar_msi_teardown_irq;
msi->domain = irq_domain_add_linear(pcie->dev->of_node, INT_PCI_MSI_NR, msi->domain = irq_domain_add_linear(dev->of_node, INT_PCI_MSI_NR,
&msi_domain_ops, &msi->chip); &msi_domain_ops, &msi->chip);
if (!msi->domain) { if (!msi->domain) {
dev_err(&pdev->dev, "failed to create IRQ domain\n"); dev_err(dev, "failed to create IRQ domain\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -866,19 +868,19 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie) ...@@ -866,19 +868,19 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie)
irq_create_mapping(msi->domain, i); irq_create_mapping(msi->domain, i);
/* Two irqs are for MSI, but they are also used for non-MSI irqs */ /* Two irqs are for MSI, but they are also used for non-MSI irqs */
err = devm_request_irq(&pdev->dev, msi->irq1, rcar_pcie_msi_irq, err = devm_request_irq(dev, msi->irq1, rcar_pcie_msi_irq,
IRQF_SHARED | IRQF_NO_THREAD, IRQF_SHARED | IRQF_NO_THREAD,
rcar_msi_irq_chip.name, pcie); rcar_msi_irq_chip.name, pcie);
if (err < 0) { if (err < 0) {
dev_err(&pdev->dev, "failed to request IRQ: %d\n", err); dev_err(dev, "failed to request IRQ: %d\n", err);
goto err; goto err;
} }
err = devm_request_irq(&pdev->dev, msi->irq2, rcar_pcie_msi_irq, err = devm_request_irq(dev, msi->irq2, rcar_pcie_msi_irq,
IRQF_SHARED | IRQF_NO_THREAD, IRQF_SHARED | IRQF_NO_THREAD,
rcar_msi_irq_chip.name, pcie); rcar_msi_irq_chip.name, pcie);
if (err < 0) { if (err < 0) {
dev_err(&pdev->dev, "failed to request IRQ: %d\n", err); dev_err(dev, "failed to request IRQ: %d\n", err);
goto err; goto err;
} }
...@@ -899,32 +901,32 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie) ...@@ -899,32 +901,32 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie)
return err; return err;
} }
static int rcar_pcie_get_resources(struct platform_device *pdev, static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
struct rcar_pcie *pcie)
{ {
struct device *dev = pcie->dev;
struct resource res; struct resource res;
int err, i; int err, i;
err = of_address_to_resource(pdev->dev.of_node, 0, &res); err = of_address_to_resource(dev->of_node, 0, &res);
if (err) if (err)
return err; return err;
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);
pcie->clk = devm_clk_get(&pdev->dev, "pcie"); pcie->clk = devm_clk_get(dev, "pcie");
if (IS_ERR(pcie->clk)) { if (IS_ERR(pcie->clk)) {
dev_err(pcie->dev, "cannot get platform clock\n"); dev_err(dev, "cannot get platform clock\n");
return PTR_ERR(pcie->clk); return PTR_ERR(pcie->clk);
} }
err = clk_prepare_enable(pcie->clk); err = clk_prepare_enable(pcie->clk);
if (err) if (err)
return err; return err;
pcie->bus_clk = devm_clk_get(&pdev->dev, "pcie_bus"); pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
if (IS_ERR(pcie->bus_clk)) { if (IS_ERR(pcie->bus_clk)) {
dev_err(pcie->dev, "cannot get pcie bus clock\n"); dev_err(dev, "cannot get pcie bus clock\n");
err = PTR_ERR(pcie->bus_clk); err = PTR_ERR(pcie->bus_clk);
goto fail_clk; goto fail_clk;
} }
...@@ -932,17 +934,17 @@ static int rcar_pcie_get_resources(struct platform_device *pdev, ...@@ -932,17 +934,17 @@ static int rcar_pcie_get_resources(struct platform_device *pdev,
if (err) if (err)
goto fail_clk; goto fail_clk;
i = irq_of_parse_and_map(pdev->dev.of_node, 0); i = irq_of_parse_and_map(dev->of_node, 0);
if (!i) { if (!i) {
dev_err(pcie->dev, "cannot get platform resources for msi interrupt\n"); dev_err(dev, "cannot get platform resources for msi interrupt\n");
err = -ENOENT; err = -ENOENT;
goto err_map_reg; goto err_map_reg;
} }
pcie->msi.irq1 = i; pcie->msi.irq1 = i;
i = irq_of_parse_and_map(pdev->dev.of_node, 1); i = irq_of_parse_and_map(dev->of_node, 1);
if (!i) { if (!i) {
dev_err(pcie->dev, "cannot get platform resources for msi interrupt\n"); dev_err(dev, "cannot get platform resources for msi interrupt\n");
err = -ENOENT; err = -ENOENT;
goto err_map_reg; goto err_map_reg;
} }
...@@ -1119,60 +1121,60 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci) ...@@ -1119,60 +1121,60 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci)
static int rcar_pcie_probe(struct platform_device *pdev) static int rcar_pcie_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev;
struct rcar_pcie *pcie; struct rcar_pcie *pcie;
unsigned int data; unsigned int data;
const struct of_device_id *of_id; const struct of_device_id *of_id;
int err; int err;
int (*hw_init_fn)(struct rcar_pcie *); int (*hw_init_fn)(struct rcar_pcie *);
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;
pcie->dev = &pdev->dev; pcie->dev = dev;
platform_set_drvdata(pdev, pcie);
INIT_LIST_HEAD(&pcie->resources); INIT_LIST_HEAD(&pcie->resources);
rcar_pcie_parse_request_of_pci_ranges(pcie); rcar_pcie_parse_request_of_pci_ranges(pcie);
err = rcar_pcie_get_resources(pdev, pcie); err = rcar_pcie_get_resources(pcie);
if (err < 0) { if (err < 0) {
dev_err(&pdev->dev, "failed to request resources: %d\n", err); dev_err(dev, "failed to request resources: %d\n", err);
return err; return err;
} }
err = rcar_pcie_parse_map_dma_ranges(pcie, pdev->dev.of_node); err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
if (err) if (err)
return err; return err;
of_id = of_match_device(rcar_pcie_of_match, pcie->dev); of_id = of_match_device(rcar_pcie_of_match, dev);
if (!of_id || !of_id->data) if (!of_id || !of_id->data)
return -EINVAL; return -EINVAL;
hw_init_fn = of_id->data; hw_init_fn = of_id->data;
pm_runtime_enable(pcie->dev); pm_runtime_enable(dev);
err = pm_runtime_get_sync(pcie->dev); err = pm_runtime_get_sync(dev);
if (err < 0) { if (err < 0) {
dev_err(pcie->dev, "pm_runtime_get_sync failed\n"); dev_err(dev, "pm_runtime_get_sync failed\n");
goto err_pm_disable; goto err_pm_disable;
} }
/* Failure to get a link might just be that no cards are inserted */ /* Failure to get a link might just be that no cards are inserted */
err = hw_init_fn(pcie); err = hw_init_fn(pcie);
if (err) { if (err) {
dev_info(&pdev->dev, "PCIe link down\n"); dev_info(dev, "PCIe link down\n");
err = 0; err = 0;
goto err_pm_put; goto err_pm_put;
} }
data = rcar_pci_read_reg(pcie, MACSR); data = rcar_pci_read_reg(pcie, MACSR);
dev_info(&pdev->dev, "PCIe x%d: link up\n", (data >> 20) & 0x3f); dev_info(dev, "PCIe x%d: link up\n", (data >> 20) & 0x3f);
if (IS_ENABLED(CONFIG_PCI_MSI)) { if (IS_ENABLED(CONFIG_PCI_MSI)) {
err = rcar_pcie_enable_msi(pcie); err = rcar_pcie_enable_msi(pcie);
if (err < 0) { if (err < 0) {
dev_err(&pdev->dev, dev_err(dev,
"failed to enable MSI support: %d\n", "failed to enable MSI support: %d\n",
err); err);
goto err_pm_put; goto err_pm_put;
...@@ -1186,16 +1188,16 @@ static int rcar_pcie_probe(struct platform_device *pdev) ...@@ -1186,16 +1188,16 @@ static int rcar_pcie_probe(struct platform_device *pdev)
return 0; return 0;
err_pm_put: err_pm_put:
pm_runtime_put(pcie->dev); pm_runtime_put(dev);
err_pm_disable: err_pm_disable:
pm_runtime_disable(pcie->dev); pm_runtime_disable(dev);
return err; return err;
} }
static struct platform_driver rcar_pcie_driver = { static struct platform_driver rcar_pcie_driver = {
.driver = { .driver = {
.name = DRV_NAME, .name = "rcar-pcie",
.of_match_table = rcar_pcie_of_match, .of_match_table = rcar_pcie_of_match,
.suppress_bind_attrs = true, .suppress_bind_attrs = true,
}, },
......
...@@ -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.
...@@ -140,10 +140,11 @@ static inline bool xilinx_pcie_link_is_up(struct xilinx_pcie_port *port) ...@@ -140,10 +140,11 @@ static inline bool xilinx_pcie_link_is_up(struct xilinx_pcie_port *port)
*/ */
static void xilinx_pcie_clear_err_interrupts(struct xilinx_pcie_port *port) static void xilinx_pcie_clear_err_interrupts(struct xilinx_pcie_port *port)
{ {
struct device *dev = port->dev;
unsigned long val = pcie_read(port, XILINX_PCIE_REG_RPEFR); unsigned long val = pcie_read(port, XILINX_PCIE_REG_RPEFR);
if (val & XILINX_PCIE_RPEFR_ERR_VALID) { if (val & XILINX_PCIE_RPEFR_ERR_VALID) {
dev_dbg(port->dev, "Requester ID %lu\n", dev_dbg(dev, "Requester ID %lu\n",
val & XILINX_PCIE_RPEFR_REQ_ID); val & XILINX_PCIE_RPEFR_REQ_ID);
pcie_write(port, XILINX_PCIE_RPEFR_ALL_MASK, pcie_write(port, XILINX_PCIE_RPEFR_ALL_MASK,
XILINX_PCIE_REG_RPEFR); XILINX_PCIE_REG_RPEFR);
...@@ -228,11 +229,10 @@ static void xilinx_pcie_destroy_msi(unsigned int irq) ...@@ -228,11 +229,10 @@ static void xilinx_pcie_destroy_msi(unsigned int irq)
/** /**
* xilinx_pcie_assign_msi - Allocate MSI number * xilinx_pcie_assign_msi - Allocate MSI number
* @port: PCIe port structure
* *
* Return: A valid IRQ on success and error value on failure. * Return: A valid IRQ on success and error value on failure.
*/ */
static int xilinx_pcie_assign_msi(struct xilinx_pcie_port *port) static int xilinx_pcie_assign_msi(void)
{ {
int pos; int pos;
...@@ -275,7 +275,7 @@ static int xilinx_pcie_msi_setup_irq(struct msi_controller *chip, ...@@ -275,7 +275,7 @@ static int xilinx_pcie_msi_setup_irq(struct msi_controller *chip,
struct msi_msg msg; struct msi_msg msg;
phys_addr_t msg_addr; phys_addr_t msg_addr;
hwirq = xilinx_pcie_assign_msi(port); hwirq = xilinx_pcie_assign_msi();
if (hwirq < 0) if (hwirq < 0)
return hwirq; return hwirq;
...@@ -383,6 +383,7 @@ static const struct irq_domain_ops intx_domain_ops = { ...@@ -383,6 +383,7 @@ static const struct irq_domain_ops intx_domain_ops = {
static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
{ {
struct xilinx_pcie_port *port = (struct xilinx_pcie_port *)data; struct xilinx_pcie_port *port = (struct xilinx_pcie_port *)data;
struct device *dev = port->dev;
u32 val, mask, status, msi_data; u32 val, mask, status, msi_data;
/* Read interrupt decode and mask registers */ /* Read interrupt decode and mask registers */
...@@ -394,32 +395,32 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) ...@@ -394,32 +395,32 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
return IRQ_NONE; return IRQ_NONE;
if (status & XILINX_PCIE_INTR_LINK_DOWN) if (status & XILINX_PCIE_INTR_LINK_DOWN)
dev_warn(port->dev, "Link Down\n"); dev_warn(dev, "Link Down\n");
if (status & XILINX_PCIE_INTR_ECRC_ERR) if (status & XILINX_PCIE_INTR_ECRC_ERR)
dev_warn(port->dev, "ECRC failed\n"); dev_warn(dev, "ECRC failed\n");
if (status & XILINX_PCIE_INTR_STR_ERR) if (status & XILINX_PCIE_INTR_STR_ERR)
dev_warn(port->dev, "Streaming error\n"); dev_warn(dev, "Streaming error\n");
if (status & XILINX_PCIE_INTR_HOT_RESET) if (status & XILINX_PCIE_INTR_HOT_RESET)
dev_info(port->dev, "Hot reset\n"); dev_info(dev, "Hot reset\n");
if (status & XILINX_PCIE_INTR_CFG_TIMEOUT) if (status & XILINX_PCIE_INTR_CFG_TIMEOUT)
dev_warn(port->dev, "ECAM access timeout\n"); dev_warn(dev, "ECAM access timeout\n");
if (status & XILINX_PCIE_INTR_CORRECTABLE) { if (status & XILINX_PCIE_INTR_CORRECTABLE) {
dev_warn(port->dev, "Correctable error message\n"); dev_warn(dev, "Correctable error message\n");
xilinx_pcie_clear_err_interrupts(port); xilinx_pcie_clear_err_interrupts(port);
} }
if (status & XILINX_PCIE_INTR_NONFATAL) { if (status & XILINX_PCIE_INTR_NONFATAL) {
dev_warn(port->dev, "Non fatal error message\n"); dev_warn(dev, "Non fatal error message\n");
xilinx_pcie_clear_err_interrupts(port); xilinx_pcie_clear_err_interrupts(port);
} }
if (status & XILINX_PCIE_INTR_FATAL) { if (status & XILINX_PCIE_INTR_FATAL) {
dev_warn(port->dev, "Fatal error message\n"); dev_warn(dev, "Fatal error message\n");
xilinx_pcie_clear_err_interrupts(port); xilinx_pcie_clear_err_interrupts(port);
} }
...@@ -429,7 +430,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) ...@@ -429,7 +430,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
/* Check whether interrupt valid */ /* Check whether interrupt valid */
if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) { if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) {
dev_warn(port->dev, "RP Intr FIFO1 read error\n"); dev_warn(dev, "RP Intr FIFO1 read error\n");
goto error; goto error;
} }
...@@ -451,7 +452,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) ...@@ -451,7 +452,7 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
val = pcie_read(port, XILINX_PCIE_REG_RPIFR1); val = pcie_read(port, XILINX_PCIE_REG_RPIFR1);
if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) { if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) {
dev_warn(port->dev, "RP Intr FIFO1 read error\n"); dev_warn(dev, "RP Intr FIFO1 read error\n");
goto error; goto error;
} }
...@@ -471,31 +472,31 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data) ...@@ -471,31 +472,31 @@ static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
} }
if (status & XILINX_PCIE_INTR_SLV_UNSUPP) if (status & XILINX_PCIE_INTR_SLV_UNSUPP)
dev_warn(port->dev, "Slave unsupported request\n"); dev_warn(dev, "Slave unsupported request\n");
if (status & XILINX_PCIE_INTR_SLV_UNEXP) if (status & XILINX_PCIE_INTR_SLV_UNEXP)
dev_warn(port->dev, "Slave unexpected completion\n"); dev_warn(dev, "Slave unexpected completion\n");
if (status & XILINX_PCIE_INTR_SLV_COMPL) if (status & XILINX_PCIE_INTR_SLV_COMPL)
dev_warn(port->dev, "Slave completion timeout\n"); dev_warn(dev, "Slave completion timeout\n");
if (status & XILINX_PCIE_INTR_SLV_ERRP) if (status & XILINX_PCIE_INTR_SLV_ERRP)
dev_warn(port->dev, "Slave Error Poison\n"); dev_warn(dev, "Slave Error Poison\n");
if (status & XILINX_PCIE_INTR_SLV_CMPABT) if (status & XILINX_PCIE_INTR_SLV_CMPABT)
dev_warn(port->dev, "Slave Completer Abort\n"); dev_warn(dev, "Slave Completer Abort\n");
if (status & XILINX_PCIE_INTR_SLV_ILLBUR) if (status & XILINX_PCIE_INTR_SLV_ILLBUR)
dev_warn(port->dev, "Slave Illegal Burst\n"); dev_warn(dev, "Slave Illegal Burst\n");
if (status & XILINX_PCIE_INTR_MST_DECERR) if (status & XILINX_PCIE_INTR_MST_DECERR)
dev_warn(port->dev, "Master decode error\n"); dev_warn(dev, "Master decode error\n");
if (status & XILINX_PCIE_INTR_MST_SLVERR) if (status & XILINX_PCIE_INTR_MST_SLVERR)
dev_warn(port->dev, "Master slave error\n"); dev_warn(dev, "Master slave error\n");
if (status & XILINX_PCIE_INTR_MST_ERRP) if (status & XILINX_PCIE_INTR_MST_ERRP)
dev_warn(port->dev, "Master error poison\n"); dev_warn(dev, "Master error poison\n");
error: error:
/* Clear the Interrupt Decode register */ /* Clear the Interrupt Decode register */
...@@ -554,10 +555,12 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) ...@@ -554,10 +555,12 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
*/ */
static void xilinx_pcie_init_port(struct xilinx_pcie_port *port) static void xilinx_pcie_init_port(struct xilinx_pcie_port *port)
{ {
struct device *dev = port->dev;
if (xilinx_pcie_link_is_up(port)) if (xilinx_pcie_link_is_up(port))
dev_info(port->dev, "PCIe Link is UP\n"); dev_info(dev, "PCIe Link is UP\n");
else else
dev_info(port->dev, "PCIe Link is DOWN\n"); dev_info(dev, "PCIe Link is DOWN\n");
/* Disable all interrupts */ /* Disable all interrupts */
pcie_write(port, ~XILINX_PCIE_IDR_ALL_MASK, pcie_write(port, ~XILINX_PCIE_IDR_ALL_MASK,
...@@ -627,8 +630,8 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie_port *port) ...@@ -627,8 +630,8 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie_port *port)
*/ */
static int xilinx_pcie_probe(struct platform_device *pdev) static int xilinx_pcie_probe(struct platform_device *pdev)
{ {
struct xilinx_pcie_port *port;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct xilinx_pcie_port *port;
struct pci_bus *bus; struct pci_bus *bus;
int err; int err;
resource_size_t iobase = 0; resource_size_t iobase = 0;
...@@ -668,15 +671,14 @@ static int xilinx_pcie_probe(struct platform_device *pdev) ...@@ -668,15 +671,14 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
if (err) if (err)
goto error; goto error;
bus = pci_create_root_bus(&pdev->dev, 0, bus = pci_create_root_bus(dev, 0, &xilinx_pcie_ops, port, &res);
&xilinx_pcie_ops, port, &res);
if (!bus) { if (!bus) {
err = -ENOMEM; err = -ENOMEM;
goto error; goto error;
} }
#ifdef CONFIG_PCI_MSI #ifdef CONFIG_PCI_MSI
xilinx_pcie_msi_chip.dev = port->dev; xilinx_pcie_msi_chip.dev = dev;
bus->msi = &xilinx_pcie_msi_chip; bus->msi = &xilinx_pcie_msi_chip;
#endif #endif
pci_scan_child_bus(bus); pci_scan_child_bus(bus);
...@@ -685,8 +687,6 @@ static int xilinx_pcie_probe(struct platform_device *pdev) ...@@ -685,8 +687,6 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci); pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
#endif #endif
pci_bus_add_devices(bus); pci_bus_add_devices(bus);
platform_set_drvdata(pdev, port);
return 0; return 0;
error: error:
......
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