PCI: rockchip: Split out rockchip_cfg_atu()

Split out a new function, rockchip_cfg_atu(), in order to re-configure the
ATU when missing these information after wakeup from S3.

[bhelgaas: add "dev" temporary, return 0 when known]
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
This commit is contained in:
Shawn Lin 2016-11-24 09:54:20 +08:00 коммит произвёл Bjorn Helgaas
Родитель f37500b8aa
Коммит 9e663d3f11
1 изменённых файлов: 55 добавлений и 49 удалений

Просмотреть файл

@ -208,6 +208,11 @@ struct rockchip_pcie {
int link_gen; int link_gen;
struct device *dev; struct device *dev;
struct irq_domain *irq_domain; struct irq_domain *irq_domain;
u32 io_size;
int offset;
phys_addr_t io_bus_addr;
u32 mem_size;
phys_addr_t mem_bus_addr;
}; };
static u32 rockchip_pcie_read(struct rockchip_pcie *rockchip, u32 reg) static u32 rockchip_pcie_read(struct rockchip_pcie *rockchip, u32 reg)
@ -1140,6 +1145,50 @@ static int rockchip_pcie_prog_ib_atu(struct rockchip_pcie *rockchip,
return 0; return 0;
} }
static int rockchip_cfg_atu(struct rockchip_pcie *rockchip)
{
struct device *dev = rockchip->dev;
int offset;
int err;
int reg_no;
for (reg_no = 0; reg_no < (rockchip->mem_size >> 20); reg_no++) {
err = rockchip_pcie_prog_ob_atu(rockchip, reg_no + 1,
AXI_WRAPPER_MEM_WRITE,
20 - 1,
rockchip->mem_bus_addr +
(reg_no << 20),
0);
if (err) {
dev_err(dev, "program RC mem outbound ATU failed\n");
return err;
}
}
err = rockchip_pcie_prog_ib_atu(rockchip, 2, 32 - 1, 0x0, 0);
if (err) {
dev_err(dev, "program RC mem inbound ATU failed\n");
return err;
}
offset = rockchip->mem_size >> 20;
for (reg_no = 0; reg_no < (rockchip->io_size >> 20); reg_no++) {
err = rockchip_pcie_prog_ob_atu(rockchip,
reg_no + 1 + offset,
AXI_WRAPPER_IO_WRITE,
20 - 1,
rockchip->io_bus_addr +
(reg_no << 20),
0);
if (err) {
dev_err(dev, "program RC io outbound ATU failed\n");
return err;
}
}
return 0;
}
static int rockchip_pcie_probe(struct platform_device *pdev) static int rockchip_pcie_probe(struct platform_device *pdev)
{ {
struct rockchip_pcie *rockchip; struct rockchip_pcie *rockchip;
@ -1149,13 +1198,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
resource_size_t io_base; resource_size_t io_base;
struct resource *mem; struct resource *mem;
struct resource *io; struct resource *io;
phys_addr_t io_bus_addr = 0;
u32 io_size;
phys_addr_t mem_bus_addr = 0;
u32 mem_size = 0;
int reg_no;
int err; int err;
int offset;
LIST_HEAD(res); LIST_HEAD(res);
@ -1222,14 +1265,13 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
goto err_vpcie; goto err_vpcie;
/* Get the I/O and memory ranges from DT */ /* Get the I/O and memory ranges from DT */
io_size = 0;
resource_list_for_each_entry(win, &res) { resource_list_for_each_entry(win, &res) {
switch (resource_type(win->res)) { switch (resource_type(win->res)) {
case IORESOURCE_IO: case IORESOURCE_IO:
io = win->res; io = win->res;
io->name = "I/O"; io->name = "I/O";
io_size = resource_size(io); rockchip->io_size = resource_size(io);
io_bus_addr = io->start - win->offset; rockchip->io_bus_addr = io->start - win->offset;
err = pci_remap_iospace(io, io_base); err = pci_remap_iospace(io, io_base);
if (err) { if (err) {
dev_warn(dev, "error %d: failed to map resource %pR\n", dev_warn(dev, "error %d: failed to map resource %pR\n",
@ -1240,8 +1282,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
case IORESOURCE_MEM: case IORESOURCE_MEM:
mem = win->res; mem = win->res;
mem->name = "MEM"; mem->name = "MEM";
mem_size = resource_size(mem); rockchip->mem_size = resource_size(mem);
mem_bus_addr = mem->start - win->offset; rockchip->mem_bus_addr = mem->start - win->offset;
break; break;
case IORESOURCE_BUS: case IORESOURCE_BUS:
rockchip->root_bus_nr = win->res->start; rockchip->root_bus_nr = win->res->start;
@ -1251,45 +1293,9 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
} }
} }
if (mem_size) { err = rockchip_cfg_atu(rockchip);
for (reg_no = 0; reg_no < (mem_size >> 20); reg_no++) { if (err)
err = rockchip_pcie_prog_ob_atu(rockchip, reg_no + 1,
AXI_WRAPPER_MEM_WRITE,
20 - 1,
mem_bus_addr +
(reg_no << 20),
0);
if (err) {
dev_err(dev, "program RC mem outbound ATU failed\n");
goto err_vpcie;
}
}
}
err = rockchip_pcie_prog_ib_atu(rockchip, 2, 32 - 1, 0x0, 0);
if (err) {
dev_err(dev, "program RC mem inbound ATU failed\n");
goto err_vpcie; goto err_vpcie;
}
offset = mem_size >> 20;
if (io_size) {
for (reg_no = 0; reg_no < (io_size >> 20); reg_no++) {
err = rockchip_pcie_prog_ob_atu(rockchip,
reg_no + 1 + offset,
AXI_WRAPPER_IO_WRITE,
20 - 1,
io_bus_addr +
(reg_no << 20),
0);
if (err) {
dev_err(dev, "program RC io outbound ATU failed\n");
goto err_vpcie;
}
}
}
bus = pci_scan_root_bus(&pdev->dev, 0, &rockchip_pcie_ops, rockchip, &res); bus = pci_scan_root_bus(&pdev->dev, 0, &rockchip_pcie_ops, rockchip, &res);
if (!bus) { if (!bus) {
err = -ENOMEM; err = -ENOMEM;