Skip to content

Commit

Permalink
PCI: H6 ugly hack
Browse files Browse the repository at this point in the history
  • Loading branch information
clementperon committed Mar 21, 2020
1 parent 22cb876 commit 52b0d71
Show file tree
Hide file tree
Showing 7 changed files with 1,212 additions and 5 deletions.
20 changes: 20 additions & 0 deletions drivers/pci/controller/dwc/pcie-designware-host.c
Expand Up @@ -21,6 +21,13 @@

static struct pci_ops dw_pcie_ops;

// HACK Allwinner H6
#define PCIE_MISC_CONTROL_1_CFG 0x8bc

#ifdef CONFIG_PCIE_SUNXI
extern void __iomem *dbi_base;
#endif

static int dw_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
u32 *val)
{
Expand Down Expand Up @@ -388,6 +395,9 @@ int dw_pcie_host_init(struct pcie_port *pp)
}
}

#ifdef CONFIG_PCIE_SUNXI
dbi_base = pci->dbi_base;
#endif
pp->mem_base = pp->mem->start;

if (!pp->va_cfg0_base) {
Expand Down Expand Up @@ -698,9 +708,19 @@ void dw_pcie_setup_rc(struct pcie_port *pp)

dw_pcie_wr_own_conf(pp, PCI_BASE_ADDRESS_0, 4, 0);

/* Hack Allwiner H6 */
dw_pcie_rd_own_conf(pp, PCIE_MISC_CONTROL_1_CFG, 4, &val);
val |= 0x1;
dw_pcie_wr_own_conf(pp, PCIE_MISC_CONTROL_1_CFG, 4, val);

/* Program correct class for RC */
dw_pcie_wr_own_conf(pp, PCI_CLASS_DEVICE, 2, PCI_CLASS_BRIDGE_PCI);

/* Hack Allwiner H6 */
dw_pcie_rd_own_conf(pp, PCIE_MISC_CONTROL_1_CFG, 4, &val);
val &= ~(0x1<<0);
dw_pcie_wr_own_conf(pp, PCIE_MISC_CONTROL_1_CFG, 4, val);

dw_pcie_rd_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, &val);
val |= PORT_LOGIC_SPEED_CHANGE;
dw_pcie_wr_own_conf(pp, PCIE_LINK_WIDTH_SPEED_CONTROL, 4, val);
Expand Down
5 changes: 5 additions & 0 deletions drivers/pci/controller/dwc/pcie-designware.h
Expand Up @@ -141,6 +141,11 @@
#define MAX_IATU_IN 256
#define MAX_IATU_OUT 256

/* HACK H6 */
#define PCIE_BAR_NUM 6
#define MEM_BASE_LEN 16
#define MEM_BASE_MASK 0xffff

struct pcie_port;
struct dw_pcie;
struct dw_pcie_ep;
Expand Down
17 changes: 14 additions & 3 deletions drivers/pci/controller/dwc/pcie-sunxi.c
Expand Up @@ -56,6 +56,9 @@

#define to_sunxi_pcie(x) dev_get_drvdata((x)->dev)

void __iomem *dbi_base;
//static void __iomem *mem_base_start;

struct sunxi_pcie {
struct dw_pcie *pci;
int link_irq;
Expand Down Expand Up @@ -319,7 +322,7 @@ static int sunxi_pcie_regulator_enable(struct sunxi_pcie *pcie)
regulator_disable(pcie->reg_vdd);
disable_vcc:
regulator_disable(pcie->reg_vcc);

return ret;
}

Expand Down Expand Up @@ -431,7 +434,7 @@ static int sunxi_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
u32 busdev, cfg_size;
u64 cpu_addr;
void __iomem *va_cfg_base;
int pcie_page;
int pcie_page, mem_base;
unsigned long flags = 0;
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);

Expand Down Expand Up @@ -459,7 +462,9 @@ static int sunxi_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
ret = dw_pcie_read(va_cfg_base + where, size, val);
for (i = 0; i < PCIE_BAR_NUM; i++) {
pcie_page = readl(pp->va_cfg0_base + PCI_BASE_ADDRESS_0 + i * PCIE_BAR_REG);
if (pcie_page & PCIE_MEM_FLAGS)
mem_base = readl(pci->dbi_base + PCI_MEMORY_BASE);
if (((pcie_page >> MEM_BASE_LEN) & MEM_BASE_MASK)
== (mem_base & MEM_BASE_MASK))
break;
}
dw_pcie_writel_dbi(pci, PCIE_ADDR_PAGE_CFG, pcie_page >> 16);
Expand Down Expand Up @@ -532,13 +537,15 @@ static int sunxi_pcie_host_init(struct pcie_port *pp)

dw_pcie_setup_rc(pp);

#if 0
dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX0,
PCIE_ATU_TYPE_MEM, pp->mem_base,
pp->mem_bus_addr, pp->mem_size);
if (pci->num_viewport > 2)
dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX2,
PCIE_ATU_TYPE_IO, pp->io_base,
pp->io_bus_addr, pp->io_size);
#endif

sunxi_pcie_establish_link(pci);
if (IS_ENABLED(CONFIG_PCI_MSI))
Expand Down Expand Up @@ -588,6 +595,10 @@ static int sunxi_add_pcie_port(struct sunxi_pcie *pcie,
return ret;
}

// Ugly hack
dbi_base = pcie->pci->dbi_base;
//mem_base_start = pp->va_cfg0_base;

return 0;
}

Expand Down

0 comments on commit 52b0d71

Please sign in to comment.