10 #define pr_fmt(fmt) "PCI: " fmt
12 #include <linux/pci.h>
14 #include <linux/kernel.h>
18 #include <linux/slab.h>
23 #include <asm/sizes.h>
34 static unsigned int nr_ports;
36 static struct sh7786_pcie_hwops {
41 static struct resource sh7786_pci0_resources[] = {
45 .end = 0xfd000000 +
SZ_8M - 1,
48 .name =
"PCIe0 MEM 0",
50 .end = 0xc0000000 +
SZ_512M - 1,
53 .name =
"PCIe0 MEM 1",
55 .end = 0x10000000 +
SZ_64M - 1,
58 .name =
"PCIe0 MEM 2",
60 .end = 0xfe100000 +
SZ_1M - 1,
65 static struct resource sh7786_pci1_resources[] = {
69 .end = 0xfd800000 +
SZ_8M - 1,
72 .name =
"PCIe1 MEM 0",
74 .end = 0xa0000000 +
SZ_512M - 1,
77 .name =
"PCIe1 MEM 1",
79 .end = 0x30000000 +
SZ_256M - 1,
82 .name =
"PCIe1 MEM 2",
84 .end = 0xfe300000 +
SZ_1M - 1,
89 static struct resource sh7786_pci2_resources[] = {
93 .end = 0xfc800000 +
SZ_4M - 1,
96 .name =
"PCIe2 MEM 0",
98 .end = 0x80000000 +
SZ_512M - 1,
101 .name =
"PCIe2 MEM 1",
103 .end = 0x20000000 +
SZ_256M - 1,
106 .name =
"PCIe2 MEM 2",
108 .end = 0xfcd00000 +
SZ_1M - 1,
115 #define DEFINE_CONTROLLER(start, idx) \
117 .pci_ops = &sh7786_pci_ops, \
118 .resources = sh7786_pci##idx##_resources, \
119 .nr_resources = ARRAY_SIZE(sh7786_pci##idx##_resources), \
125 static struct pci_channel sh7786_pci_channels[] = {
131 static struct clk fixed_pciexclkp = {
140 if (pci_is_root_bus(dev->
bus) && dev->
devfn == 0) {
153 static int __init phy_wait_for_ack(
struct pci_channel *
chan)
167 static int __init pci_wait_for_irq(
struct pci_channel *chan,
unsigned int mask)
169 unsigned int timeout = 100;
181 static void __init phy_write_reg(
struct pci_channel *chan,
unsigned int addr,
182 unsigned int lane,
unsigned int data)
193 phy_wait_for_ack(chan);
199 phy_wait_for_ack(chan);
204 struct pci_channel *chan = port->
hose;
221 snprintf(fclk_name,
sizeof(fclk_name),
"pcie%d_fck", port->
index);
224 if (IS_ERR(port->
fclk)) {
225 ret = PTR_ERR(port->
fclk);
236 memset(clk, 0,
sizeof(
struct clk));
238 clk->
parent = &fixed_pciexclkp;
259 struct pci_channel *chan = port->
hose;
260 unsigned int timeout = 100;
265 phy_write_reg(chan, 0x60, 0xf, 0x004b008b);
266 phy_write_reg(chan, 0x61, 0xf, 0x00007b41);
267 phy_write_reg(chan, 0x64, 0xf, 0x00ff4f00);
268 phy_write_reg(chan, 0x65, 0xf, 0x09070907);
269 phy_write_reg(chan, 0x66, 0xf, 0x00000010);
270 phy_write_reg(chan, 0x74, 0xf, 0x0007001c);
271 phy_write_reg(chan, 0x79, 0xf, 0x01fc000d);
272 phy_write_reg(chan, 0xb0, 0xf, 0x00000610);
275 phy_write_reg(chan, 0x67, 0x1, 0x00000400);
292 struct pci_channel *chan = port->
hose;
302 struct pci_channel *chan = port->
hose;
342 data |= (port->
index + 1) << 19;
357 data |= (0xff << 16);
426 port->
index, (data >> 20) & 0x3f);
431 for (i = win = 0; i < chan->nr_resources; i++) {
449 size = resource_size(res);
475 static int __init sh7786_pcie_core_init(
void)
495 ret = pcie_clk_init(port);
497 pr_err(
"clock initialization failed for port#%d\n",
502 ret = phy_init(port);
504 pr_err(
"phy initialization failed for port#%d\n",
509 ret = pcie_init(port);
511 pr_err(
"core initialization failed for port#%d\n",
522 static struct sh7786_pcie_hwops sh7786_65nm_pcie_hwops
__initdata = {
523 .core_init = sh7786_pcie_core_init,
524 .port_init_hw = sh7786_pcie_init_hw,
527 static int __init sh7786_pcie_init(
void)
534 sh7786_pcie_hwops = &sh7786_65nm_pcie_hwops;
536 nr_ports = sh7786_pcie_hwops->core_init();
556 if (IS_ERR(platclk)) {
565 for (i = 0; i < nr_ports; i++) {
569 port->
hose = sh7786_pci_channels +
i;
570 port->
hose->io_map_base = port->
hose->resources[0].start;