Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Low-Level PCI Express Support for the SH7786 |
| 3 | * |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 4 | * Copyright (C) 2009 - 2010 Paul Mundt |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | #include <linux/pci.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/io.h> |
| 14 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 16 | #include "pcie-sh7786.h" |
| 17 | #include <asm/sizes.h> |
| 18 | |
| 19 | struct sh7786_pcie_port { |
| 20 | struct pci_channel *hose; |
| 21 | unsigned int index; |
| 22 | int endpoint; |
| 23 | int link; |
| 24 | }; |
| 25 | |
| 26 | static struct sh7786_pcie_port *sh7786_pcie_ports; |
| 27 | static unsigned int nr_ports; |
| 28 | |
| 29 | static struct sh7786_pcie_hwops { |
| 30 | int (*core_init)(void); |
| 31 | int (*port_init_hw)(struct sh7786_pcie_port *port); |
| 32 | } *sh7786_pcie_hwops; |
| 33 | |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 34 | static struct resource sh7786_pci0_resources[] = { |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 35 | { |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 36 | .name = "PCIe0 IO", |
| 37 | .start = 0xfd000000, |
| 38 | .end = 0xfd000000 + SZ_8M - 1, |
| 39 | .flags = IORESOURCE_IO, |
| 40 | }, { |
| 41 | .name = "PCIe0 MEM 0", |
| 42 | .start = 0xc0000000, |
| 43 | .end = 0xc0000000 + SZ_512M - 1, |
| 44 | .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, |
| 45 | }, { |
| 46 | .name = "PCIe0 MEM 1", |
| 47 | .start = 0x10000000, |
| 48 | .end = 0x10000000 + SZ_64M - 1, |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 49 | .flags = IORESOURCE_MEM, |
| 50 | }, { |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 51 | .name = "PCIe0 MEM 2", |
| 52 | .start = 0xfe100000, |
| 53 | .end = 0xfe100000 + SZ_1M - 1, |
Paul Mundt | 1c3bb38 | 2010-09-07 17:07:05 +0900 | [diff] [blame] | 54 | .flags = IORESOURCE_MEM, |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 55 | }, |
| 56 | }; |
| 57 | |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 58 | static struct resource sh7786_pci1_resources[] = { |
| 59 | { |
| 60 | .name = "PCIe1 IO", |
| 61 | .start = 0xfd800000, |
| 62 | .end = 0xfd800000 + SZ_8M - 1, |
| 63 | .flags = IORESOURCE_IO, |
| 64 | }, { |
| 65 | .name = "PCIe1 MEM 0", |
| 66 | .start = 0xa0000000, |
| 67 | .end = 0xa0000000 + SZ_512M - 1, |
| 68 | .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, |
| 69 | }, { |
| 70 | .name = "PCIe1 MEM 1", |
| 71 | .start = 0x30000000, |
| 72 | .end = 0x30000000 + SZ_256M - 1, |
| 73 | .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, |
| 74 | }, { |
| 75 | .name = "PCIe1 MEM 2", |
| 76 | .start = 0xfe300000, |
| 77 | .end = 0xfe300000 + SZ_1M - 1, |
Paul Mundt | 1c3bb38 | 2010-09-07 17:07:05 +0900 | [diff] [blame] | 78 | .flags = IORESOURCE_MEM, |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 79 | }, |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 80 | }; |
| 81 | |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 82 | static struct resource sh7786_pci2_resources[] = { |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 83 | { |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 84 | .name = "PCIe2 IO", |
| 85 | .start = 0xfc800000, |
| 86 | .end = 0xfc800000 + SZ_4M - 1, |
Paul Mundt | f048519 | 2010-09-07 17:05:08 +0900 | [diff] [blame] | 87 | .flags = IORESOURCE_IO, |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 88 | }, { |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 89 | .name = "PCIe2 MEM 0", |
| 90 | .start = 0x80000000, |
| 91 | .end = 0x80000000 + SZ_512M - 1, |
| 92 | .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 93 | }, { |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 94 | .name = "PCIe2 MEM 1", |
| 95 | .start = 0x20000000, |
| 96 | .end = 0x20000000 + SZ_256M - 1, |
| 97 | .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT, |
| 98 | }, { |
| 99 | .name = "PCIe2 MEM 2", |
| 100 | .start = 0xfcd00000, |
| 101 | .end = 0xfcd00000 + SZ_1M - 1, |
Paul Mundt | 1c3bb38 | 2010-09-07 17:07:05 +0900 | [diff] [blame] | 102 | .flags = IORESOURCE_MEM, |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 103 | }, |
| 104 | }; |
| 105 | |
| 106 | extern struct pci_ops sh7786_pci_ops; |
| 107 | |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 108 | #define DEFINE_CONTROLLER(start, idx) \ |
| 109 | { \ |
| 110 | .pci_ops = &sh7786_pci_ops, \ |
| 111 | .resources = sh7786_pci##idx##_resources, \ |
| 112 | .nr_resources = ARRAY_SIZE(sh7786_pci##idx##_resources), \ |
| 113 | .reg_base = start, \ |
| 114 | .mem_offset = 0, \ |
| 115 | .io_offset = 0, \ |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static struct pci_channel sh7786_pci_channels[] = { |
| 119 | DEFINE_CONTROLLER(0xfe000000, 0), |
| 120 | DEFINE_CONTROLLER(0xfe200000, 1), |
| 121 | DEFINE_CONTROLLER(0xfcc00000, 2), |
| 122 | }; |
| 123 | |
Paul Mundt | 2c65d75 | 2010-09-20 15:39:54 +0900 | [diff] [blame^] | 124 | static void __devinit sh7786_pci_fixup(struct pci_dev *dev) |
| 125 | { |
| 126 | /* |
| 127 | * Prevent enumeration of root complex resources. |
| 128 | */ |
| 129 | if (pci_is_root_bus(dev->bus) && dev->devfn == 0) { |
| 130 | int i; |
| 131 | |
| 132 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 133 | dev->resource[i].start = 0; |
| 134 | dev->resource[i].end = 0; |
| 135 | dev->resource[i].flags = 0; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RENESAS, PCI_DEVICE_ID_RENESAS_SH7786, |
| 140 | sh7786_pci_fixup); |
| 141 | |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 142 | static int phy_wait_for_ack(struct pci_channel *chan) |
| 143 | { |
| 144 | unsigned int timeout = 100; |
| 145 | |
| 146 | while (timeout--) { |
| 147 | if (pci_read_reg(chan, SH4A_PCIEPHYADRR) & (1 << BITS_ACK)) |
| 148 | return 0; |
| 149 | |
| 150 | udelay(100); |
| 151 | } |
| 152 | |
| 153 | return -ETIMEDOUT; |
| 154 | } |
| 155 | |
| 156 | static int pci_wait_for_irq(struct pci_channel *chan, unsigned int mask) |
| 157 | { |
| 158 | unsigned int timeout = 100; |
| 159 | |
| 160 | while (timeout--) { |
| 161 | if ((pci_read_reg(chan, SH4A_PCIEINTR) & mask) == mask) |
| 162 | return 0; |
| 163 | |
| 164 | udelay(100); |
| 165 | } |
| 166 | |
| 167 | return -ETIMEDOUT; |
| 168 | } |
| 169 | |
| 170 | static void phy_write_reg(struct pci_channel *chan, unsigned int addr, |
| 171 | unsigned int lane, unsigned int data) |
| 172 | { |
Paul Mundt | 53178d7 | 2010-08-20 16:04:59 +0900 | [diff] [blame] | 173 | unsigned long phyaddr; |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 174 | |
| 175 | phyaddr = (1 << BITS_CMD) + ((lane & 0xf) << BITS_LANE) + |
| 176 | ((addr & 0xff) << BITS_ADR); |
| 177 | |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 178 | /* Set write data */ |
| 179 | pci_write_reg(chan, data, SH4A_PCIEPHYDOUTR); |
| 180 | pci_write_reg(chan, phyaddr, SH4A_PCIEPHYADRR); |
| 181 | |
| 182 | phy_wait_for_ack(chan); |
| 183 | |
| 184 | /* Clear command */ |
Paul Mundt | 53178d7 | 2010-08-20 16:04:59 +0900 | [diff] [blame] | 185 | pci_write_reg(chan, 0, SH4A_PCIEPHYDOUTR); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 186 | pci_write_reg(chan, 0, SH4A_PCIEPHYADRR); |
| 187 | |
| 188 | phy_wait_for_ack(chan); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | static int phy_init(struct pci_channel *chan) |
| 192 | { |
Paul Mundt | 53178d7 | 2010-08-20 16:04:59 +0900 | [diff] [blame] | 193 | unsigned long ctrl; |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 194 | unsigned int timeout = 100; |
| 195 | |
Paul Mundt | 53178d7 | 2010-08-20 16:04:59 +0900 | [diff] [blame] | 196 | /* Enable clock */ |
| 197 | ctrl = pci_read_reg(chan, SH4A_PCIEPHYCTLR); |
| 198 | ctrl |= (1 << BITS_CKE); |
| 199 | pci_write_reg(chan, ctrl, SH4A_PCIEPHYCTLR); |
| 200 | |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 201 | /* Initialize the phy */ |
| 202 | phy_write_reg(chan, 0x60, 0xf, 0x004b008b); |
| 203 | phy_write_reg(chan, 0x61, 0xf, 0x00007b41); |
| 204 | phy_write_reg(chan, 0x64, 0xf, 0x00ff4f00); |
| 205 | phy_write_reg(chan, 0x65, 0xf, 0x09070907); |
| 206 | phy_write_reg(chan, 0x66, 0xf, 0x00000010); |
| 207 | phy_write_reg(chan, 0x74, 0xf, 0x0007001c); |
| 208 | phy_write_reg(chan, 0x79, 0xf, 0x01fc000d); |
Paul Mundt | 53178d7 | 2010-08-20 16:04:59 +0900 | [diff] [blame] | 209 | phy_write_reg(chan, 0xb0, 0xf, 0x00000610); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 210 | |
| 211 | /* Deassert Standby */ |
Paul Mundt | 53178d7 | 2010-08-20 16:04:59 +0900 | [diff] [blame] | 212 | phy_write_reg(chan, 0x67, 0x1, 0x00000400); |
| 213 | |
| 214 | /* Disable clock */ |
| 215 | ctrl = pci_read_reg(chan, SH4A_PCIEPHYCTLR); |
| 216 | ctrl &= ~(1 << BITS_CKE); |
| 217 | pci_write_reg(chan, ctrl, SH4A_PCIEPHYCTLR); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 218 | |
| 219 | while (timeout--) { |
| 220 | if (pci_read_reg(chan, SH4A_PCIEPHYSR)) |
| 221 | return 0; |
| 222 | |
| 223 | udelay(100); |
| 224 | } |
| 225 | |
| 226 | return -ETIMEDOUT; |
| 227 | } |
| 228 | |
Paul Mundt | 2dbfa1e | 2010-09-07 16:11:04 +0900 | [diff] [blame] | 229 | static void pcie_reset(struct sh7786_pcie_port *port) |
| 230 | { |
| 231 | struct pci_channel *chan = port->hose; |
| 232 | |
| 233 | pci_write_reg(chan, 1, SH4A_PCIESRSTR); |
| 234 | pci_write_reg(chan, 0, SH4A_PCIETCTLR); |
| 235 | pci_write_reg(chan, 0, SH4A_PCIESRSTR); |
| 236 | pci_write_reg(chan, 0, SH4A_PCIETXVC0SR); |
| 237 | } |
| 238 | |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 239 | static int pcie_init(struct sh7786_pcie_port *port) |
| 240 | { |
| 241 | struct pci_channel *chan = port->hose; |
| 242 | unsigned int data; |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 243 | phys_addr_t memphys; |
| 244 | size_t memsize; |
Paul Mundt | da03a63 | 2010-09-07 17:03:10 +0900 | [diff] [blame] | 245 | int ret, i, win; |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 246 | |
| 247 | /* Begin initialization */ |
Paul Mundt | 2dbfa1e | 2010-09-07 16:11:04 +0900 | [diff] [blame] | 248 | pcie_reset(port); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 249 | |
Paul Mundt | 2c65d75 | 2010-09-20 15:39:54 +0900 | [diff] [blame^] | 250 | /* |
| 251 | * Initial header for port config space is type 1, set the device |
| 252 | * class to match. Hardware takes care of propagating the IDSETR |
| 253 | * settings, so there is no need to bother with a quirk. |
| 254 | */ |
| 255 | pci_write_reg(chan, PCI_CLASS_BRIDGE_PCI << 16, SH4A_PCIEIDSETR1); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 256 | |
| 257 | /* Initialize default capabilities. */ |
| 258 | data = pci_read_reg(chan, SH4A_PCIEEXPCAP0); |
| 259 | data &= ~(PCI_EXP_FLAGS_TYPE << 16); |
| 260 | |
| 261 | if (port->endpoint) |
| 262 | data |= PCI_EXP_TYPE_ENDPOINT << 20; |
| 263 | else |
| 264 | data |= PCI_EXP_TYPE_ROOT_PORT << 20; |
| 265 | |
| 266 | data |= PCI_CAP_ID_EXP; |
| 267 | pci_write_reg(chan, data, SH4A_PCIEEXPCAP0); |
| 268 | |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 269 | /* Enable data link layer active state reporting */ |
| 270 | pci_write_reg(chan, PCI_EXP_LNKCAP_DLLLARC, SH4A_PCIEEXPCAP3); |
| 271 | |
| 272 | /* Enable extended sync and ASPM L0s support */ |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 273 | data = pci_read_reg(chan, SH4A_PCIEEXPCAP4); |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 274 | data &= ~PCI_EXP_LNKCTL_ASPMC; |
| 275 | data |= PCI_EXP_LNKCTL_ES | 1; |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 276 | pci_write_reg(chan, data, SH4A_PCIEEXPCAP4); |
| 277 | |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 278 | /* Write out the physical slot number */ |
| 279 | data = pci_read_reg(chan, SH4A_PCIEEXPCAP5); |
| 280 | data &= ~PCI_EXP_SLTCAP_PSN; |
| 281 | data |= (port->index + 1) << 19; |
| 282 | pci_write_reg(chan, data, SH4A_PCIEEXPCAP5); |
| 283 | |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 284 | /* Set the completion timer timeout to the maximum 32ms. */ |
| 285 | data = pci_read_reg(chan, SH4A_PCIETLCTLR); |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 286 | data &= ~0x3f00; |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 287 | data |= 0x32 << 8; |
| 288 | pci_write_reg(chan, data, SH4A_PCIETLCTLR); |
| 289 | |
| 290 | /* |
| 291 | * Set fast training sequences to the maximum 255, |
| 292 | * and enable MAC data scrambling. |
| 293 | */ |
| 294 | data = pci_read_reg(chan, SH4A_PCIEMACCTLR); |
| 295 | data &= ~PCIEMACCTLR_SCR_DIS; |
| 296 | data |= (0xff << 16); |
| 297 | pci_write_reg(chan, data, SH4A_PCIEMACCTLR); |
| 298 | |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 299 | memphys = __pa(memory_start); |
| 300 | memsize = roundup_pow_of_two(memory_end - memory_start); |
| 301 | |
| 302 | /* |
| 303 | * If there's more than 512MB of memory, we need to roll over to |
| 304 | * LAR1/LAMR1. |
| 305 | */ |
| 306 | if (memsize > SZ_512M) { |
| 307 | __raw_writel(memphys + SZ_512M, chan->reg_base + SH4A_PCIELAR1); |
| 308 | __raw_writel(((memsize - SZ_512M) - SZ_256) | 1, |
| 309 | chan->reg_base + SH4A_PCIELAMR1); |
| 310 | memsize = SZ_512M; |
| 311 | } else { |
| 312 | /* |
| 313 | * Otherwise just zero it out and disable it. |
| 314 | */ |
| 315 | __raw_writel(0, chan->reg_base + SH4A_PCIELAR1); |
| 316 | __raw_writel(0, chan->reg_base + SH4A_PCIELAMR1); |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * LAR0/LAMR0 covers up to the first 512MB, which is enough to |
| 321 | * cover all of lowmem on most platforms. |
| 322 | */ |
| 323 | __raw_writel(memphys, chan->reg_base + SH4A_PCIELAR0); |
| 324 | __raw_writel((memsize - SZ_256) | 1, chan->reg_base + SH4A_PCIELAMR0); |
| 325 | |
Paul Mundt | 53178d7 | 2010-08-20 16:04:59 +0900 | [diff] [blame] | 326 | __raw_writel(memphys, chan->reg_base + SH4A_PCIEPCICONF4); |
| 327 | __raw_writel(0, chan->reg_base + SH4A_PCIEPCICONF5); |
| 328 | |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 329 | /* Finish initialization */ |
| 330 | data = pci_read_reg(chan, SH4A_PCIETCTLR); |
| 331 | data |= 0x1; |
| 332 | pci_write_reg(chan, data, SH4A_PCIETCTLR); |
| 333 | |
Paul Mundt | 81df84f | 2010-09-19 13:57:51 +0900 | [diff] [blame] | 334 | /* Let things settle down a bit.. */ |
| 335 | mdelay(100); |
| 336 | |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 337 | /* Enable DL_Active Interrupt generation */ |
| 338 | data = pci_read_reg(chan, SH4A_PCIEDLINTENR); |
| 339 | data |= PCIEDLINTENR_DLL_ACT_ENABLE; |
| 340 | pci_write_reg(chan, data, SH4A_PCIEDLINTENR); |
| 341 | |
| 342 | /* Disable MAC data scrambling. */ |
| 343 | data = pci_read_reg(chan, SH4A_PCIEMACCTLR); |
| 344 | data |= PCIEMACCTLR_SCR_DIS | (0xff << 16); |
| 345 | pci_write_reg(chan, data, SH4A_PCIEMACCTLR); |
| 346 | |
| 347 | ret = pci_wait_for_irq(chan, MASK_INT_TX_CTRL); |
| 348 | if (unlikely(ret != 0)) |
| 349 | return -ENODEV; |
| 350 | |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 351 | data = pci_read_reg(chan, SH4A_PCIEPCICONF1); |
| 352 | data &= ~(PCI_STATUS_DEVSEL_MASK << 16); |
| 353 | data |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | |
| 354 | (PCI_STATUS_CAP_LIST | PCI_STATUS_DEVSEL_FAST) << 16; |
| 355 | pci_write_reg(chan, data, SH4A_PCIEPCICONF1); |
| 356 | |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 357 | pci_write_reg(chan, 0x80888000, SH4A_PCIETXVC0DCTLR); |
| 358 | pci_write_reg(chan, 0x00222000, SH4A_PCIERXVC0DCTLR); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 359 | |
| 360 | wmb(); |
| 361 | |
| 362 | data = pci_read_reg(chan, SH4A_PCIEMACSR); |
| 363 | printk(KERN_NOTICE "PCI: PCIe#%d link width %d\n", |
| 364 | port->index, (data >> 20) & 0x3f); |
| 365 | |
Paul Mundt | da03a63 | 2010-09-07 17:03:10 +0900 | [diff] [blame] | 366 | for (i = win = 0; i < chan->nr_resources; i++) { |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 367 | struct resource *res = chan->resources + i; |
| 368 | resource_size_t size; |
| 369 | u32 enable_mask; |
| 370 | |
Paul Mundt | da03a63 | 2010-09-07 17:03:10 +0900 | [diff] [blame] | 371 | /* |
| 372 | * We can't use the 32-bit mode windows in legacy 29-bit |
| 373 | * mode, so just skip them entirely. |
| 374 | */ |
| 375 | if ((res->flags & IORESOURCE_MEM_32BIT) && __in_29bit_mode()) |
| 376 | continue; |
| 377 | |
| 378 | pci_write_reg(chan, 0x00000000, SH4A_PCIEPTCTLR(win)); |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 379 | |
| 380 | size = resource_size(res); |
| 381 | |
| 382 | /* |
| 383 | * The PAMR mask is calculated in units of 256kB, which |
| 384 | * keeps things pretty simple. |
| 385 | */ |
| 386 | __raw_writel(((roundup_pow_of_two(size) / SZ_256K) - 1) << 18, |
Paul Mundt | da03a63 | 2010-09-07 17:03:10 +0900 | [diff] [blame] | 387 | chan->reg_base + SH4A_PCIEPAMR(win)); |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 388 | |
Paul Mundt | da03a63 | 2010-09-07 17:03:10 +0900 | [diff] [blame] | 389 | pci_write_reg(chan, res->start, SH4A_PCIEPARL(win)); |
| 390 | pci_write_reg(chan, 0x00000000, SH4A_PCIEPARH(win)); |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 391 | |
| 392 | enable_mask = MASK_PARE; |
| 393 | if (res->flags & IORESOURCE_IO) |
| 394 | enable_mask |= MASK_SPC; |
| 395 | |
Paul Mundt | da03a63 | 2010-09-07 17:03:10 +0900 | [diff] [blame] | 396 | pci_write_reg(chan, enable_mask, SH4A_PCIEPTCTLR(win)); |
| 397 | |
| 398 | win++; |
Paul Mundt | 7578a4c | 2010-02-10 16:00:58 +0900 | [diff] [blame] | 399 | } |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin) |
| 405 | { |
| 406 | return 71; |
| 407 | } |
| 408 | |
| 409 | static int sh7786_pcie_core_init(void) |
| 410 | { |
| 411 | /* Return the number of ports */ |
| 412 | return test_mode_pin(MODE_PIN12) ? 3 : 2; |
| 413 | } |
| 414 | |
| 415 | static int __devinit sh7786_pcie_init_hw(struct sh7786_pcie_port *port) |
| 416 | { |
| 417 | int ret; |
| 418 | |
| 419 | ret = phy_init(port->hose); |
| 420 | if (unlikely(ret < 0)) |
| 421 | return ret; |
| 422 | |
| 423 | /* |
| 424 | * Check if we are configured in endpoint or root complex mode, |
| 425 | * this is a fixed pin setting that applies to all PCIe ports. |
| 426 | */ |
| 427 | port->endpoint = test_mode_pin(MODE_PIN11); |
| 428 | |
| 429 | ret = pcie_init(port); |
| 430 | if (unlikely(ret < 0)) |
| 431 | return ret; |
| 432 | |
Paul Mundt | bcf3935 | 2010-02-01 13:11:25 +0900 | [diff] [blame] | 433 | return register_pci_controller(port->hose); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static struct sh7786_pcie_hwops sh7786_65nm_pcie_hwops __initdata = { |
| 437 | .core_init = sh7786_pcie_core_init, |
| 438 | .port_init_hw = sh7786_pcie_init_hw, |
| 439 | }; |
| 440 | |
| 441 | static int __init sh7786_pcie_init(void) |
| 442 | { |
| 443 | int ret = 0, i; |
| 444 | |
Matt Fleming | 3b554c3 | 2010-06-19 00:01:03 +0100 | [diff] [blame] | 445 | printk(KERN_NOTICE "PCI: Starting initialization.\n"); |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 446 | |
| 447 | sh7786_pcie_hwops = &sh7786_65nm_pcie_hwops; |
| 448 | |
| 449 | nr_ports = sh7786_pcie_hwops->core_init(); |
| 450 | BUG_ON(nr_ports > ARRAY_SIZE(sh7786_pci_channels)); |
| 451 | |
| 452 | if (unlikely(nr_ports == 0)) |
| 453 | return -ENODEV; |
| 454 | |
| 455 | sh7786_pcie_ports = kzalloc(nr_ports * sizeof(struct sh7786_pcie_port), |
| 456 | GFP_KERNEL); |
| 457 | if (unlikely(!sh7786_pcie_ports)) |
| 458 | return -ENOMEM; |
| 459 | |
| 460 | printk(KERN_NOTICE "PCI: probing %d ports.\n", nr_ports); |
| 461 | |
| 462 | for (i = 0; i < nr_ports; i++) { |
| 463 | struct sh7786_pcie_port *port = sh7786_pcie_ports + i; |
| 464 | |
| 465 | port->index = i; |
| 466 | port->hose = sh7786_pci_channels + i; |
Paul Mundt | 7561f2d | 2010-02-08 16:36:56 +0900 | [diff] [blame] | 467 | port->hose->io_map_base = port->hose->resources[0].start; |
Paul Mundt | 5713e60 | 2009-06-17 18:20:48 +0900 | [diff] [blame] | 468 | |
| 469 | ret |= sh7786_pcie_hwops->port_init_hw(port); |
| 470 | } |
| 471 | |
| 472 | if (unlikely(ret)) |
| 473 | return ret; |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | arch_initcall(sh7786_pcie_init); |