]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/pci/host/pci-mvebu.c
Merge remote-tracking branch 'regmap/for-next'
[karo-tx-linux.git] / drivers / pci / host / pci-mvebu.c
1 /*
2  * PCIe driver for Marvell Armada 370 and Armada XP SoCs
3  *
4  * This file is licensed under the terms of the GNU General Public
5  * License version 2.  This program is licensed "as is" without any
6  * warranty of any kind, whether express or implied.
7  */
8
9 #include <linux/kernel.h>
10 #include <linux/pci.h>
11 #include <linux/clk.h>
12 #include <linux/delay.h>
13 #include <linux/gpio.h>
14 #include <linux/module.h>
15 #include <linux/mbus.h>
16 #include <linux/msi.h>
17 #include <linux/slab.h>
18 #include <linux/platform_device.h>
19 #include <linux/of_address.h>
20 #include <linux/of_irq.h>
21 #include <linux/of_gpio.h>
22 #include <linux/of_pci.h>
23 #include <linux/of_platform.h>
24
25 /*
26  * PCIe unit register offsets.
27  */
28 #define PCIE_DEV_ID_OFF         0x0000
29 #define PCIE_CMD_OFF            0x0004
30 #define PCIE_DEV_REV_OFF        0x0008
31 #define PCIE_BAR_LO_OFF(n)      (0x0010 + ((n) << 3))
32 #define PCIE_BAR_HI_OFF(n)      (0x0014 + ((n) << 3))
33 #define PCIE_CAP_PCIEXP         0x0060
34 #define PCIE_HEADER_LOG_4_OFF   0x0128
35 #define PCIE_BAR_CTRL_OFF(n)    (0x1804 + (((n) - 1) * 4))
36 #define PCIE_WIN04_CTRL_OFF(n)  (0x1820 + ((n) << 4))
37 #define PCIE_WIN04_BASE_OFF(n)  (0x1824 + ((n) << 4))
38 #define PCIE_WIN04_REMAP_OFF(n) (0x182c + ((n) << 4))
39 #define PCIE_WIN5_CTRL_OFF      0x1880
40 #define PCIE_WIN5_BASE_OFF      0x1884
41 #define PCIE_WIN5_REMAP_OFF     0x188c
42 #define PCIE_CONF_ADDR_OFF      0x18f8
43 #define  PCIE_CONF_ADDR_EN              0x80000000
44 #define  PCIE_CONF_REG(r)               ((((r) & 0xf00) << 16) | ((r) & 0xfc))
45 #define  PCIE_CONF_BUS(b)               (((b) & 0xff) << 16)
46 #define  PCIE_CONF_DEV(d)               (((d) & 0x1f) << 11)
47 #define  PCIE_CONF_FUNC(f)              (((f) & 0x7) << 8)
48 #define  PCIE_CONF_ADDR(bus, devfn, where) \
49         (PCIE_CONF_BUS(bus) | PCIE_CONF_DEV(PCI_SLOT(devfn))    | \
50          PCIE_CONF_FUNC(PCI_FUNC(devfn)) | PCIE_CONF_REG(where) | \
51          PCIE_CONF_ADDR_EN)
52 #define PCIE_CONF_DATA_OFF      0x18fc
53 #define PCIE_MASK_OFF           0x1910
54 #define  PCIE_MASK_ENABLE_INTS          0x0f000000
55 #define PCIE_CTRL_OFF           0x1a00
56 #define  PCIE_CTRL_X1_MODE              0x0001
57 #define PCIE_STAT_OFF           0x1a04
58 #define  PCIE_STAT_BUS                  0xff00
59 #define  PCIE_STAT_DEV                  0x1f0000
60 #define  PCIE_STAT_LINK_DOWN            BIT(0)
61 #define PCIE_RC_RTSTA           0x1a14
62 #define PCIE_DEBUG_CTRL         0x1a60
63 #define  PCIE_DEBUG_SOFT_RESET          BIT(20)
64
65 enum {
66         PCISWCAP = PCI_BRIDGE_CONTROL + 2,
67         PCISWCAP_EXP_LIST_ID    = PCISWCAP + PCI_CAP_LIST_ID,
68         PCISWCAP_EXP_DEVCAP     = PCISWCAP + PCI_EXP_DEVCAP,
69         PCISWCAP_EXP_DEVCTL     = PCISWCAP + PCI_EXP_DEVCTL,
70         PCISWCAP_EXP_LNKCAP     = PCISWCAP + PCI_EXP_LNKCAP,
71         PCISWCAP_EXP_LNKCTL     = PCISWCAP + PCI_EXP_LNKCTL,
72         PCISWCAP_EXP_SLTCAP     = PCISWCAP + PCI_EXP_SLTCAP,
73         PCISWCAP_EXP_SLTCTL     = PCISWCAP + PCI_EXP_SLTCTL,
74         PCISWCAP_EXP_RTCTL      = PCISWCAP + PCI_EXP_RTCTL,
75         PCISWCAP_EXP_RTSTA      = PCISWCAP + PCI_EXP_RTSTA,
76         PCISWCAP_EXP_DEVCAP2    = PCISWCAP + PCI_EXP_DEVCAP2,
77         PCISWCAP_EXP_DEVCTL2    = PCISWCAP + PCI_EXP_DEVCTL2,
78         PCISWCAP_EXP_LNKCAP2    = PCISWCAP + PCI_EXP_LNKCAP2,
79         PCISWCAP_EXP_LNKCTL2    = PCISWCAP + PCI_EXP_LNKCTL2,
80         PCISWCAP_EXP_SLTCAP2    = PCISWCAP + PCI_EXP_SLTCAP2,
81         PCISWCAP_EXP_SLTCTL2    = PCISWCAP + PCI_EXP_SLTCTL2,
82 };
83
84 /* PCI configuration space of a PCI-to-PCI bridge */
85 struct mvebu_sw_pci_bridge {
86         u16 vendor;
87         u16 device;
88         u16 command;
89         u16 status;
90         u16 class;
91         u8 interface;
92         u8 revision;
93         u8 bist;
94         u8 header_type;
95         u8 latency_timer;
96         u8 cache_line_size;
97         u32 bar[2];
98         u8 primary_bus;
99         u8 secondary_bus;
100         u8 subordinate_bus;
101         u8 secondary_latency_timer;
102         u8 iobase;
103         u8 iolimit;
104         u16 secondary_status;
105         u16 membase;
106         u16 memlimit;
107         u16 iobaseupper;
108         u16 iolimitupper;
109         u32 romaddr;
110         u8 intline;
111         u8 intpin;
112         u16 bridgectrl;
113
114         /* PCI express capability */
115         u32 pcie_sltcap;
116         u16 pcie_devctl;
117         u16 pcie_rtctl;
118 };
119
120 struct mvebu_pcie_port;
121
122 /* Structure representing all PCIe interfaces */
123 struct mvebu_pcie {
124         struct platform_device *pdev;
125         struct mvebu_pcie_port *ports;
126         struct msi_controller *msi;
127         struct resource io;
128         struct resource realio;
129         struct resource mem;
130         struct resource busn;
131         int nports;
132 };
133
134 /* Structure representing one PCIe interface */
135 struct mvebu_pcie_port {
136         char *name;
137         void __iomem *base;
138         u32 port;
139         u32 lane;
140         int devfn;
141         unsigned int mem_target;
142         unsigned int mem_attr;
143         unsigned int io_target;
144         unsigned int io_attr;
145         struct clk *clk;
146         struct gpio_desc *reset_gpio;
147         char *reset_name;
148         struct mvebu_sw_pci_bridge bridge;
149         struct device_node *dn;
150         struct mvebu_pcie *pcie;
151         phys_addr_t memwin_base;
152         size_t memwin_size;
153         phys_addr_t iowin_base;
154         size_t iowin_size;
155         u32 saved_pcie_stat;
156 };
157
158 static inline void mvebu_writel(struct mvebu_pcie_port *port, u32 val, u32 reg)
159 {
160         writel(val, port->base + reg);
161 }
162
163 static inline u32 mvebu_readl(struct mvebu_pcie_port *port, u32 reg)
164 {
165         return readl(port->base + reg);
166 }
167
168 static inline bool mvebu_has_ioport(struct mvebu_pcie_port *port)
169 {
170         return port->io_target != -1 && port->io_attr != -1;
171 }
172
173 static bool mvebu_pcie_link_up(struct mvebu_pcie_port *port)
174 {
175         return !(mvebu_readl(port, PCIE_STAT_OFF) & PCIE_STAT_LINK_DOWN);
176 }
177
178 static void mvebu_pcie_set_local_bus_nr(struct mvebu_pcie_port *port, int nr)
179 {
180         u32 stat;
181
182         stat = mvebu_readl(port, PCIE_STAT_OFF);
183         stat &= ~PCIE_STAT_BUS;
184         stat |= nr << 8;
185         mvebu_writel(port, stat, PCIE_STAT_OFF);
186 }
187
188 static void mvebu_pcie_set_local_dev_nr(struct mvebu_pcie_port *port, int nr)
189 {
190         u32 stat;
191
192         stat = mvebu_readl(port, PCIE_STAT_OFF);
193         stat &= ~PCIE_STAT_DEV;
194         stat |= nr << 16;
195         mvebu_writel(port, stat, PCIE_STAT_OFF);
196 }
197
198 /*
199  * Setup PCIE BARs and Address Decode Wins:
200  * BAR[0,2] -> disabled, BAR[1] -> covers all DRAM banks
201  * WIN[0-3] -> DRAM bank[0-3]
202  */
203 static void mvebu_pcie_setup_wins(struct mvebu_pcie_port *port)
204 {
205         const struct mbus_dram_target_info *dram;
206         u32 size;
207         int i;
208
209         dram = mv_mbus_dram_info();
210
211         /* First, disable and clear BARs and windows. */
212         for (i = 1; i < 3; i++) {
213                 mvebu_writel(port, 0, PCIE_BAR_CTRL_OFF(i));
214                 mvebu_writel(port, 0, PCIE_BAR_LO_OFF(i));
215                 mvebu_writel(port, 0, PCIE_BAR_HI_OFF(i));
216         }
217
218         for (i = 0; i < 5; i++) {
219                 mvebu_writel(port, 0, PCIE_WIN04_CTRL_OFF(i));
220                 mvebu_writel(port, 0, PCIE_WIN04_BASE_OFF(i));
221                 mvebu_writel(port, 0, PCIE_WIN04_REMAP_OFF(i));
222         }
223
224         mvebu_writel(port, 0, PCIE_WIN5_CTRL_OFF);
225         mvebu_writel(port, 0, PCIE_WIN5_BASE_OFF);
226         mvebu_writel(port, 0, PCIE_WIN5_REMAP_OFF);
227
228         /* Setup windows for DDR banks.  Count total DDR size on the fly. */
229         size = 0;
230         for (i = 0; i < dram->num_cs; i++) {
231                 const struct mbus_dram_window *cs = dram->cs + i;
232
233                 mvebu_writel(port, cs->base & 0xffff0000,
234                              PCIE_WIN04_BASE_OFF(i));
235                 mvebu_writel(port, 0, PCIE_WIN04_REMAP_OFF(i));
236                 mvebu_writel(port,
237                              ((cs->size - 1) & 0xffff0000) |
238                              (cs->mbus_attr << 8) |
239                              (dram->mbus_dram_target_id << 4) | 1,
240                              PCIE_WIN04_CTRL_OFF(i));
241
242                 size += cs->size;
243         }
244
245         /* Round up 'size' to the nearest power of two. */
246         if ((size & (size - 1)) != 0)
247                 size = 1 << fls(size);
248
249         /* Setup BAR[1] to all DRAM banks. */
250         mvebu_writel(port, dram->cs[0].base, PCIE_BAR_LO_OFF(1));
251         mvebu_writel(port, 0, PCIE_BAR_HI_OFF(1));
252         mvebu_writel(port, ((size - 1) & 0xffff0000) | 1,
253                      PCIE_BAR_CTRL_OFF(1));
254 }
255
256 static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
257 {
258         u32 cmd, mask;
259
260         /* Point PCIe unit MBUS decode windows to DRAM space. */
261         mvebu_pcie_setup_wins(port);
262
263         /* Master + slave enable. */
264         cmd = mvebu_readl(port, PCIE_CMD_OFF);
265         cmd |= PCI_COMMAND_IO;
266         cmd |= PCI_COMMAND_MEMORY;
267         cmd |= PCI_COMMAND_MASTER;
268         mvebu_writel(port, cmd, PCIE_CMD_OFF);
269
270         /* Enable interrupt lines A-D. */
271         mask = mvebu_readl(port, PCIE_MASK_OFF);
272         mask |= PCIE_MASK_ENABLE_INTS;
273         mvebu_writel(port, mask, PCIE_MASK_OFF);
274 }
275
276 static int mvebu_pcie_hw_rd_conf(struct mvebu_pcie_port *port,
277                                  struct pci_bus *bus,
278                                  u32 devfn, int where, int size, u32 *val)
279 {
280         void __iomem *conf_data = port->base + PCIE_CONF_DATA_OFF;
281
282         mvebu_writel(port, PCIE_CONF_ADDR(bus->number, devfn, where),
283                      PCIE_CONF_ADDR_OFF);
284
285         switch (size) {
286         case 1:
287                 *val = readb_relaxed(conf_data + (where & 3));
288                 break;
289         case 2:
290                 *val = readw_relaxed(conf_data + (where & 2));
291                 break;
292         case 4:
293                 *val = readl_relaxed(conf_data);
294                 break;
295         }
296
297         return PCIBIOS_SUCCESSFUL;
298 }
299
300 static int mvebu_pcie_hw_wr_conf(struct mvebu_pcie_port *port,
301                                  struct pci_bus *bus,
302                                  u32 devfn, int where, int size, u32 val)
303 {
304         void __iomem *conf_data = port->base + PCIE_CONF_DATA_OFF;
305
306         mvebu_writel(port, PCIE_CONF_ADDR(bus->number, devfn, where),
307                      PCIE_CONF_ADDR_OFF);
308
309         switch (size) {
310         case 1:
311                 writeb(val, conf_data + (where & 3));
312                 break;
313         case 2:
314                 writew(val, conf_data + (where & 2));
315                 break;
316         case 4:
317                 writel(val, conf_data);
318                 break;
319         default:
320                 return PCIBIOS_BAD_REGISTER_NUMBER;
321         }
322
323         return PCIBIOS_SUCCESSFUL;
324 }
325
326 /*
327  * Remove windows, starting from the largest ones to the smallest
328  * ones.
329  */
330 static void mvebu_pcie_del_windows(struct mvebu_pcie_port *port,
331                                    phys_addr_t base, size_t size)
332 {
333         while (size) {
334                 size_t sz = 1 << (fls(size) - 1);
335
336                 mvebu_mbus_del_window(base, sz);
337                 base += sz;
338                 size -= sz;
339         }
340 }
341
342 /*
343  * MBus windows can only have a power of two size, but PCI BARs do not
344  * have this constraint. Therefore, we have to split the PCI BAR into
345  * areas each having a power of two size. We start from the largest
346  * one (i.e highest order bit set in the size).
347  */
348 static void mvebu_pcie_add_windows(struct mvebu_pcie_port *port,
349                                    unsigned int target, unsigned int attribute,
350                                    phys_addr_t base, size_t size,
351                                    phys_addr_t remap)
352 {
353         size_t size_mapped = 0;
354
355         while (size) {
356                 size_t sz = 1 << (fls(size) - 1);
357                 int ret;
358
359                 ret = mvebu_mbus_add_window_remap_by_id(target, attribute, base,
360                                                         sz, remap);
361                 if (ret) {
362                         phys_addr_t end = base + sz - 1;
363
364                         dev_err(&port->pcie->pdev->dev,
365                                 "Could not create MBus window at [mem %pa-%pa]: %d\n",
366                                 &base, &end, ret);
367                         mvebu_pcie_del_windows(port, base - size_mapped,
368                                                size_mapped);
369                         return;
370                 }
371
372                 size -= sz;
373                 size_mapped += sz;
374                 base += sz;
375                 if (remap != MVEBU_MBUS_NO_REMAP)
376                         remap += sz;
377         }
378 }
379
380 static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port)
381 {
382         phys_addr_t iobase;
383
384         /* Are the new iobase/iolimit values invalid? */
385         if (port->bridge.iolimit < port->bridge.iobase ||
386             port->bridge.iolimitupper < port->bridge.iobaseupper ||
387             !(port->bridge.command & PCI_COMMAND_IO)) {
388
389                 /* If a window was configured, remove it */
390                 if (port->iowin_base) {
391                         mvebu_pcie_del_windows(port, port->iowin_base,
392                                                port->iowin_size);
393                         port->iowin_base = 0;
394                         port->iowin_size = 0;
395                 }
396
397                 return;
398         }
399
400         if (dev_WARN(&port->pcie->pdev->dev, !mvebu_has_ioport(port),
401                                 "Attempt to set IO when IO is disabled\n"))
402                 return;
403
404         /*
405          * We read the PCI-to-PCI bridge emulated registers, and
406          * calculate the base address and size of the address decoding
407          * window to setup, according to the PCI-to-PCI bridge
408          * specifications. iobase is the bus address, port->iowin_base
409          * is the CPU address.
410          */
411         iobase = ((port->bridge.iobase & 0xF0) << 8) |
412                 (port->bridge.iobaseupper << 16);
413         port->iowin_base = port->pcie->io.start + iobase;
414         port->iowin_size = ((0xFFF | ((port->bridge.iolimit & 0xF0) << 8) |
415                             (port->bridge.iolimitupper << 16)) -
416                             iobase) + 1;
417
418         mvebu_pcie_add_windows(port, port->io_target, port->io_attr,
419                                port->iowin_base, port->iowin_size,
420                                iobase);
421 }
422
423 static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port)
424 {
425         /* Are the new membase/memlimit values invalid? */
426         if (port->bridge.memlimit < port->bridge.membase ||
427             !(port->bridge.command & PCI_COMMAND_MEMORY)) {
428
429                 /* If a window was configured, remove it */
430                 if (port->memwin_base) {
431                         mvebu_pcie_del_windows(port, port->memwin_base,
432                                                port->memwin_size);
433                         port->memwin_base = 0;
434                         port->memwin_size = 0;
435                 }
436
437                 return;
438         }
439
440         /*
441          * We read the PCI-to-PCI bridge emulated registers, and
442          * calculate the base address and size of the address decoding
443          * window to setup, according to the PCI-to-PCI bridge
444          * specifications.
445          */
446         port->memwin_base  = ((port->bridge.membase & 0xFFF0) << 16);
447         port->memwin_size  =
448                 (((port->bridge.memlimit & 0xFFF0) << 16) | 0xFFFFF) -
449                 port->memwin_base + 1;
450
451         mvebu_pcie_add_windows(port, port->mem_target, port->mem_attr,
452                                port->memwin_base, port->memwin_size,
453                                MVEBU_MBUS_NO_REMAP);
454 }
455
456 /*
457  * Initialize the configuration space of the PCI-to-PCI bridge
458  * associated with the given PCIe interface.
459  */
460 static void mvebu_sw_pci_bridge_init(struct mvebu_pcie_port *port)
461 {
462         struct mvebu_sw_pci_bridge *bridge = &port->bridge;
463
464         memset(bridge, 0, sizeof(struct mvebu_sw_pci_bridge));
465
466         bridge->class = PCI_CLASS_BRIDGE_PCI;
467         bridge->vendor = PCI_VENDOR_ID_MARVELL;
468         bridge->device = mvebu_readl(port, PCIE_DEV_ID_OFF) >> 16;
469         bridge->revision = mvebu_readl(port, PCIE_DEV_REV_OFF) & 0xff;
470         bridge->header_type = PCI_HEADER_TYPE_BRIDGE;
471         bridge->cache_line_size = 0x10;
472
473         /* We support 32 bits I/O addressing */
474         bridge->iobase = PCI_IO_RANGE_TYPE_32;
475         bridge->iolimit = PCI_IO_RANGE_TYPE_32;
476
477         /* Add capabilities */
478         bridge->status = PCI_STATUS_CAP_LIST;
479 }
480
481 /*
482  * Read the configuration space of the PCI-to-PCI bridge associated to
483  * the given PCIe interface.
484  */
485 static int mvebu_sw_pci_bridge_read(struct mvebu_pcie_port *port,
486                                   unsigned int where, int size, u32 *value)
487 {
488         struct mvebu_sw_pci_bridge *bridge = &port->bridge;
489
490         switch (where & ~3) {
491         case PCI_VENDOR_ID:
492                 *value = bridge->device << 16 | bridge->vendor;
493                 break;
494
495         case PCI_COMMAND:
496                 *value = bridge->command | bridge->status << 16;
497                 break;
498
499         case PCI_CLASS_REVISION:
500                 *value = bridge->class << 16 | bridge->interface << 8 |
501                          bridge->revision;
502                 break;
503
504         case PCI_CACHE_LINE_SIZE:
505                 *value = bridge->bist << 24 | bridge->header_type << 16 |
506                          bridge->latency_timer << 8 | bridge->cache_line_size;
507                 break;
508
509         case PCI_BASE_ADDRESS_0 ... PCI_BASE_ADDRESS_1:
510                 *value = bridge->bar[((where & ~3) - PCI_BASE_ADDRESS_0) / 4];
511                 break;
512
513         case PCI_PRIMARY_BUS:
514                 *value = (bridge->secondary_latency_timer << 24 |
515                           bridge->subordinate_bus         << 16 |
516                           bridge->secondary_bus           <<  8 |
517                           bridge->primary_bus);
518                 break;
519
520         case PCI_IO_BASE:
521                 if (!mvebu_has_ioport(port))
522                         *value = bridge->secondary_status << 16;
523                 else
524                         *value = (bridge->secondary_status << 16 |
525                                   bridge->iolimit          <<  8 |
526                                   bridge->iobase);
527                 break;
528
529         case PCI_MEMORY_BASE:
530                 *value = (bridge->memlimit << 16 | bridge->membase);
531                 break;
532
533         case PCI_PREF_MEMORY_BASE:
534                 *value = 0;
535                 break;
536
537         case PCI_IO_BASE_UPPER16:
538                 *value = (bridge->iolimitupper << 16 | bridge->iobaseupper);
539                 break;
540
541         case PCI_CAPABILITY_LIST:
542                 *value = PCISWCAP;
543                 break;
544
545         case PCI_ROM_ADDRESS1:
546                 *value = 0;
547                 break;
548
549         case PCI_INTERRUPT_LINE:
550                 /* LINE PIN MIN_GNT MAX_LAT */
551                 *value = 0;
552                 break;
553
554         case PCISWCAP_EXP_LIST_ID:
555                 /* Set PCIe v2, root port, slot support */
556                 *value = (PCI_EXP_TYPE_ROOT_PORT << 4 | 2 |
557                           PCI_EXP_FLAGS_SLOT) << 16 | PCI_CAP_ID_EXP;
558                 break;
559
560         case PCISWCAP_EXP_DEVCAP:
561                 *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_DEVCAP);
562                 break;
563
564         case PCISWCAP_EXP_DEVCTL:
565                 *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_DEVCTL) &
566                                  ~(PCI_EXP_DEVCTL_URRE | PCI_EXP_DEVCTL_FERE |
567                                    PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_CERE);
568                 *value |= bridge->pcie_devctl;
569                 break;
570
571         case PCISWCAP_EXP_LNKCAP:
572                 /*
573                  * PCIe requires the clock power management capability to be
574                  * hard-wired to zero for downstream ports
575                  */
576                 *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCAP) &
577                          ~PCI_EXP_LNKCAP_CLKPM;
578                 break;
579
580         case PCISWCAP_EXP_LNKCTL:
581                 *value = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL);
582                 break;
583
584         case PCISWCAP_EXP_SLTCAP:
585                 *value = bridge->pcie_sltcap;
586                 break;
587
588         case PCISWCAP_EXP_SLTCTL:
589                 *value = PCI_EXP_SLTSTA_PDS << 16;
590                 break;
591
592         case PCISWCAP_EXP_RTCTL:
593                 *value = bridge->pcie_rtctl;
594                 break;
595
596         case PCISWCAP_EXP_RTSTA:
597                 *value = mvebu_readl(port, PCIE_RC_RTSTA);
598                 break;
599
600         /* PCIe requires the v2 fields to be hard-wired to zero */
601         case PCISWCAP_EXP_DEVCAP2:
602         case PCISWCAP_EXP_DEVCTL2:
603         case PCISWCAP_EXP_LNKCAP2:
604         case PCISWCAP_EXP_LNKCTL2:
605         case PCISWCAP_EXP_SLTCAP2:
606         case PCISWCAP_EXP_SLTCTL2:
607         default:
608                 /*
609                  * PCI defines configuration read accesses to reserved or
610                  * unimplemented registers to read as zero and complete
611                  * normally.
612                  */
613                 *value = 0;
614                 return PCIBIOS_SUCCESSFUL;
615         }
616
617         if (size == 2)
618                 *value = (*value >> (8 * (where & 3))) & 0xffff;
619         else if (size == 1)
620                 *value = (*value >> (8 * (where & 3))) & 0xff;
621
622         return PCIBIOS_SUCCESSFUL;
623 }
624
625 /* Write to the PCI-to-PCI bridge configuration space */
626 static int mvebu_sw_pci_bridge_write(struct mvebu_pcie_port *port,
627                                      unsigned int where, int size, u32 value)
628 {
629         struct mvebu_sw_pci_bridge *bridge = &port->bridge;
630         u32 mask, reg;
631         int err;
632
633         if (size == 4)
634                 mask = 0x0;
635         else if (size == 2)
636                 mask = ~(0xffff << ((where & 3) * 8));
637         else if (size == 1)
638                 mask = ~(0xff << ((where & 3) * 8));
639         else
640                 return PCIBIOS_BAD_REGISTER_NUMBER;
641
642         err = mvebu_sw_pci_bridge_read(port, where & ~3, 4, &reg);
643         if (err)
644                 return err;
645
646         value = (reg & mask) | value << ((where & 3) * 8);
647
648         switch (where & ~3) {
649         case PCI_COMMAND:
650         {
651                 u32 old = bridge->command;
652
653                 if (!mvebu_has_ioport(port))
654                         value &= ~PCI_COMMAND_IO;
655
656                 bridge->command = value & 0xffff;
657                 if ((old ^ bridge->command) & PCI_COMMAND_IO)
658                         mvebu_pcie_handle_iobase_change(port);
659                 if ((old ^ bridge->command) & PCI_COMMAND_MEMORY)
660                         mvebu_pcie_handle_membase_change(port);
661                 break;
662         }
663
664         case PCI_BASE_ADDRESS_0 ... PCI_BASE_ADDRESS_1:
665                 bridge->bar[((where & ~3) - PCI_BASE_ADDRESS_0) / 4] = value;
666                 break;
667
668         case PCI_IO_BASE:
669                 /*
670                  * We also keep bit 1 set, it is a read-only bit that
671                  * indicates we support 32 bits addressing for the
672                  * I/O
673                  */
674                 bridge->iobase = (value & 0xff) | PCI_IO_RANGE_TYPE_32;
675                 bridge->iolimit = ((value >> 8) & 0xff) | PCI_IO_RANGE_TYPE_32;
676                 mvebu_pcie_handle_iobase_change(port);
677                 break;
678
679         case PCI_MEMORY_BASE:
680                 bridge->membase = value & 0xffff;
681                 bridge->memlimit = value >> 16;
682                 mvebu_pcie_handle_membase_change(port);
683                 break;
684
685         case PCI_IO_BASE_UPPER16:
686                 bridge->iobaseupper = value & 0xffff;
687                 bridge->iolimitupper = value >> 16;
688                 mvebu_pcie_handle_iobase_change(port);
689                 break;
690
691         case PCI_PRIMARY_BUS:
692                 bridge->primary_bus             = value & 0xff;
693                 bridge->secondary_bus           = (value >> 8) & 0xff;
694                 bridge->subordinate_bus         = (value >> 16) & 0xff;
695                 bridge->secondary_latency_timer = (value >> 24) & 0xff;
696                 mvebu_pcie_set_local_bus_nr(port, bridge->secondary_bus);
697                 break;
698
699         case PCISWCAP_EXP_DEVCTL:
700                 /*
701                  * Armada370 data says these bits must always
702                  * be zero when in root complex mode.
703                  */
704                 value &= ~(PCI_EXP_DEVCTL_URRE | PCI_EXP_DEVCTL_FERE |
705                            PCI_EXP_DEVCTL_NFERE | PCI_EXP_DEVCTL_CERE);
706
707                 /*
708                  * If the mask is 0xffff0000, then we only want to write
709                  * the device control register, rather than clearing the
710                  * RW1C bits in the device status register.  Mask out the
711                  * status register bits.
712                  */
713                 if (mask == 0xffff0000)
714                         value &= 0xffff;
715
716                 mvebu_writel(port, value, PCIE_CAP_PCIEXP + PCI_EXP_DEVCTL);
717                 break;
718
719         case PCISWCAP_EXP_LNKCTL:
720                 /*
721                  * If we don't support CLKREQ, we must ensure that the
722                  * CLKREQ enable bit always reads zero.  Since we haven't
723                  * had this capability, and it's dependent on board wiring,
724                  * disable it for the time being.
725                  */
726                 value &= ~PCI_EXP_LNKCTL_CLKREQ_EN;
727
728                 /*
729                  * If the mask is 0xffff0000, then we only want to write
730                  * the link control register, rather than clearing the
731                  * RW1C bits in the link status register.  Mask out the
732                  * status register bits.
733                  */
734                 if (mask == 0xffff0000)
735                         value &= 0xffff;
736
737                 mvebu_writel(port, value, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL);
738                 break;
739
740         case PCISWCAP_EXP_RTSTA:
741                 mvebu_writel(port, value, PCIE_RC_RTSTA);
742                 break;
743
744         default:
745                 break;
746         }
747
748         return PCIBIOS_SUCCESSFUL;
749 }
750
751 static inline struct mvebu_pcie *sys_to_pcie(struct pci_sys_data *sys)
752 {
753         return sys->private_data;
754 }
755
756 static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie *pcie,
757                                                     struct pci_bus *bus,
758                                                     int devfn)
759 {
760         int i;
761
762         for (i = 0; i < pcie->nports; i++) {
763                 struct mvebu_pcie_port *port = &pcie->ports[i];
764
765                 if (bus->number == 0 && port->devfn == devfn)
766                         return port;
767                 if (bus->number != 0 &&
768                     bus->number >= port->bridge.secondary_bus &&
769                     bus->number <= port->bridge.subordinate_bus)
770                         return port;
771         }
772
773         return NULL;
774 }
775
776 /* PCI configuration space write function */
777 static int mvebu_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
778                               int where, int size, u32 val)
779 {
780         struct mvebu_pcie *pcie = sys_to_pcie(bus->sysdata);
781         struct mvebu_pcie_port *port;
782         int ret;
783
784         port = mvebu_pcie_find_port(pcie, bus, devfn);
785         if (!port)
786                 return PCIBIOS_DEVICE_NOT_FOUND;
787
788         /* Access the emulated PCI-to-PCI bridge */
789         if (bus->number == 0)
790                 return mvebu_sw_pci_bridge_write(port, where, size, val);
791
792         if (!mvebu_pcie_link_up(port))
793                 return PCIBIOS_DEVICE_NOT_FOUND;
794
795         /* Access the real PCIe interface */
796         ret = mvebu_pcie_hw_wr_conf(port, bus, devfn,
797                                     where, size, val);
798
799         return ret;
800 }
801
802 /* PCI configuration space read function */
803 static int mvebu_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
804                               int size, u32 *val)
805 {
806         struct mvebu_pcie *pcie = sys_to_pcie(bus->sysdata);
807         struct mvebu_pcie_port *port;
808         int ret;
809
810         port = mvebu_pcie_find_port(pcie, bus, devfn);
811         if (!port) {
812                 *val = 0xffffffff;
813                 return PCIBIOS_DEVICE_NOT_FOUND;
814         }
815
816         /* Access the emulated PCI-to-PCI bridge */
817         if (bus->number == 0)
818                 return mvebu_sw_pci_bridge_read(port, where, size, val);
819
820         if (!mvebu_pcie_link_up(port)) {
821                 *val = 0xffffffff;
822                 return PCIBIOS_DEVICE_NOT_FOUND;
823         }
824
825         /* Access the real PCIe interface */
826         ret = mvebu_pcie_hw_rd_conf(port, bus, devfn,
827                                     where, size, val);
828
829         return ret;
830 }
831
832 static struct pci_ops mvebu_pcie_ops = {
833         .read = mvebu_pcie_rd_conf,
834         .write = mvebu_pcie_wr_conf,
835 };
836
837 static int mvebu_pcie_setup(int nr, struct pci_sys_data *sys)
838 {
839         struct mvebu_pcie *pcie = sys_to_pcie(sys);
840         int i;
841
842         pcie->mem.name = "PCI MEM";
843         pcie->realio.name = "PCI I/O";
844
845         if (request_resource(&iomem_resource, &pcie->mem))
846                 return 0;
847
848         if (resource_size(&pcie->realio) != 0) {
849                 if (request_resource(&ioport_resource, &pcie->realio)) {
850                         release_resource(&pcie->mem);
851                         return 0;
852                 }
853                 pci_add_resource_offset(&sys->resources, &pcie->realio,
854                                         sys->io_offset);
855         }
856         pci_add_resource_offset(&sys->resources, &pcie->mem, sys->mem_offset);
857         pci_add_resource(&sys->resources, &pcie->busn);
858
859         for (i = 0; i < pcie->nports; i++) {
860                 struct mvebu_pcie_port *port = &pcie->ports[i];
861
862                 if (!port->base)
863                         continue;
864                 mvebu_pcie_setup_hw(port);
865         }
866
867         return 1;
868 }
869
870 static resource_size_t mvebu_pcie_align_resource(struct pci_dev *dev,
871                                                  const struct resource *res,
872                                                  resource_size_t start,
873                                                  resource_size_t size,
874                                                  resource_size_t align)
875 {
876         if (dev->bus->number != 0)
877                 return start;
878
879         /*
880          * On the PCI-to-PCI bridge side, the I/O windows must have at
881          * least a 64 KB size and the memory windows must have at
882          * least a 1 MB size. Moreover, MBus windows need to have a
883          * base address aligned on their size, and their size must be
884          * a power of two. This means that if the BAR doesn't have a
885          * power of two size, several MBus windows will actually be
886          * created. We need to ensure that the biggest MBus window
887          * (which will be the first one) is aligned on its size, which
888          * explains the rounddown_pow_of_two() being done here.
889          */
890         if (res->flags & IORESOURCE_IO)
891                 return round_up(start, max_t(resource_size_t, SZ_64K,
892                                              rounddown_pow_of_two(size)));
893         else if (res->flags & IORESOURCE_MEM)
894                 return round_up(start, max_t(resource_size_t, SZ_1M,
895                                              rounddown_pow_of_two(size)));
896         else
897                 return start;
898 }
899
900 static void mvebu_pcie_enable(struct mvebu_pcie *pcie)
901 {
902         struct hw_pci hw;
903
904         memset(&hw, 0, sizeof(hw));
905
906 #ifdef CONFIG_PCI_MSI
907         hw.msi_ctrl = pcie->msi;
908 #endif
909
910         hw.nr_controllers = 1;
911         hw.private_data   = (void **)&pcie;
912         hw.setup          = mvebu_pcie_setup;
913         hw.map_irq        = of_irq_parse_and_map_pci;
914         hw.ops            = &mvebu_pcie_ops;
915         hw.align_resource = mvebu_pcie_align_resource;
916
917         pci_common_init_dev(&pcie->pdev->dev, &hw);
918 }
919
920 /*
921  * Looks up the list of register addresses encoded into the reg =
922  * <...> property for one that matches the given port/lane. Once
923  * found, maps it.
924  */
925 static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev,
926                                               struct device_node *np,
927                                               struct mvebu_pcie_port *port)
928 {
929         struct resource regs;
930         int ret = 0;
931
932         ret = of_address_to_resource(np, 0, &regs);
933         if (ret)
934                 return ERR_PTR(ret);
935
936         return devm_ioremap_resource(&pdev->dev, &regs);
937 }
938
939 #define DT_FLAGS_TO_TYPE(flags)       (((flags) >> 24) & 0x03)
940 #define    DT_TYPE_IO                 0x1
941 #define    DT_TYPE_MEM32              0x2
942 #define DT_CPUADDR_TO_TARGET(cpuaddr) (((cpuaddr) >> 56) & 0xFF)
943 #define DT_CPUADDR_TO_ATTR(cpuaddr)   (((cpuaddr) >> 48) & 0xFF)
944
945 static int mvebu_get_tgt_attr(struct device_node *np, int devfn,
946                               unsigned long type,
947                               unsigned int *tgt,
948                               unsigned int *attr)
949 {
950         const int na = 3, ns = 2;
951         const __be32 *range;
952         int rlen, nranges, rangesz, pna, i;
953
954         *tgt = -1;
955         *attr = -1;
956
957         range = of_get_property(np, "ranges", &rlen);
958         if (!range)
959                 return -EINVAL;
960
961         pna = of_n_addr_cells(np);
962         rangesz = pna + na + ns;
963         nranges = rlen / sizeof(__be32) / rangesz;
964
965         for (i = 0; i < nranges; i++, range += rangesz) {
966                 u32 flags = of_read_number(range, 1);
967                 u32 slot = of_read_number(range + 1, 1);
968                 u64 cpuaddr = of_read_number(range + na, pna);
969                 unsigned long rtype;
970
971                 if (DT_FLAGS_TO_TYPE(flags) == DT_TYPE_IO)
972                         rtype = IORESOURCE_IO;
973                 else if (DT_FLAGS_TO_TYPE(flags) == DT_TYPE_MEM32)
974                         rtype = IORESOURCE_MEM;
975                 else
976                         continue;
977
978                 if (slot == PCI_SLOT(devfn) && type == rtype) {
979                         *tgt = DT_CPUADDR_TO_TARGET(cpuaddr);
980                         *attr = DT_CPUADDR_TO_ATTR(cpuaddr);
981                         return 0;
982                 }
983         }
984
985         return -ENOENT;
986 }
987
988 static void mvebu_pcie_msi_enable(struct mvebu_pcie *pcie)
989 {
990         struct device_node *msi_node;
991
992         msi_node = of_parse_phandle(pcie->pdev->dev.of_node,
993                                     "msi-parent", 0);
994         if (!msi_node)
995                 return;
996
997         pcie->msi = of_pci_find_msi_chip_by_node(msi_node);
998         of_node_put(msi_node);
999
1000         if (pcie->msi)
1001                 pcie->msi->dev = &pcie->pdev->dev;
1002 }
1003
1004 static int mvebu_pcie_suspend(struct device *dev)
1005 {
1006         struct mvebu_pcie *pcie;
1007         int i;
1008
1009         pcie = dev_get_drvdata(dev);
1010         for (i = 0; i < pcie->nports; i++) {
1011                 struct mvebu_pcie_port *port = pcie->ports + i;
1012                 port->saved_pcie_stat = mvebu_readl(port, PCIE_STAT_OFF);
1013         }
1014
1015         return 0;
1016 }
1017
1018 static int mvebu_pcie_resume(struct device *dev)
1019 {
1020         struct mvebu_pcie *pcie;
1021         int i;
1022
1023         pcie = dev_get_drvdata(dev);
1024         for (i = 0; i < pcie->nports; i++) {
1025                 struct mvebu_pcie_port *port = pcie->ports + i;
1026                 mvebu_writel(port, port->saved_pcie_stat, PCIE_STAT_OFF);
1027                 mvebu_pcie_setup_hw(port);
1028         }
1029
1030         return 0;
1031 }
1032
1033 static void mvebu_pcie_port_clk_put(void *data)
1034 {
1035         struct mvebu_pcie_port *port = data;
1036
1037         clk_put(port->clk);
1038 }
1039
1040 static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
1041         struct mvebu_pcie_port *port, struct device_node *child)
1042 {
1043         struct device *dev = &pcie->pdev->dev;
1044         enum of_gpio_flags flags;
1045         int reset_gpio, ret;
1046
1047         port->pcie = pcie;
1048
1049         if (of_property_read_u32(child, "marvell,pcie-port", &port->port)) {
1050                 dev_warn(dev, "ignoring %s, missing pcie-port property\n",
1051                          of_node_full_name(child));
1052                 goto skip;
1053         }
1054
1055         if (of_property_read_u32(child, "marvell,pcie-lane", &port->lane))
1056                 port->lane = 0;
1057
1058         port->name = devm_kasprintf(dev, GFP_KERNEL, "pcie%d.%d", port->port,
1059                                     port->lane);
1060         if (!port->name) {
1061                 ret = -ENOMEM;
1062                 goto err;
1063         }
1064
1065         port->devfn = of_pci_get_devfn(child);
1066         if (port->devfn < 0)
1067                 goto skip;
1068
1069         ret = mvebu_get_tgt_attr(dev->of_node, port->devfn, IORESOURCE_MEM,
1070                                  &port->mem_target, &port->mem_attr);
1071         if (ret < 0) {
1072                 dev_err(dev, "%s: cannot get tgt/attr for mem window\n",
1073                         port->name);
1074                 goto skip;
1075         }
1076
1077         if (resource_size(&pcie->io) != 0) {
1078                 mvebu_get_tgt_attr(dev->of_node, port->devfn, IORESOURCE_IO,
1079                                    &port->io_target, &port->io_attr);
1080         } else {
1081                 port->io_target = -1;
1082                 port->io_attr = -1;
1083         }
1084
1085         reset_gpio = of_get_named_gpio_flags(child, "reset-gpios", 0, &flags);
1086         if (reset_gpio == -EPROBE_DEFER) {
1087                 ret = reset_gpio;
1088                 goto err;
1089         }
1090
1091         if (gpio_is_valid(reset_gpio)) {
1092                 unsigned long gpio_flags;
1093
1094                 port->reset_name = devm_kasprintf(dev, GFP_KERNEL, "%s-reset",
1095                                                   port->name);
1096                 if (!port->reset_name) {
1097                         ret = -ENOMEM;
1098                         goto err;
1099                 }
1100
1101                 if (flags & OF_GPIO_ACTIVE_LOW) {
1102                         dev_info(dev, "%s: reset gpio is active low\n",
1103                                  of_node_full_name(child));
1104                         gpio_flags = GPIOF_ACTIVE_LOW |
1105                                      GPIOF_OUT_INIT_LOW;
1106                 } else {
1107                         gpio_flags = GPIOF_OUT_INIT_HIGH;
1108                 }
1109
1110                 ret = devm_gpio_request_one(dev, reset_gpio, gpio_flags,
1111                                             port->reset_name);
1112                 if (ret) {
1113                         if (ret == -EPROBE_DEFER)
1114                                 goto err;
1115                         goto skip;
1116                 }
1117
1118                 port->reset_gpio = gpio_to_desc(reset_gpio);
1119         }
1120
1121         port->clk = of_clk_get_by_name(child, NULL);
1122         if (IS_ERR(port->clk)) {
1123                 dev_err(dev, "%s: cannot get clock\n", port->name);
1124                 goto skip;
1125         }
1126
1127         ret = devm_add_action(dev, mvebu_pcie_port_clk_put, port);
1128         if (ret < 0) {
1129                 clk_put(port->clk);
1130                 goto err;
1131         }
1132
1133         return 1;
1134
1135 skip:
1136         ret = 0;
1137
1138         /* In the case of skipping, we need to free these */
1139         devm_kfree(dev, port->reset_name);
1140         port->reset_name = NULL;
1141         devm_kfree(dev, port->name);
1142         port->name = NULL;
1143
1144 err:
1145         return ret;
1146 }
1147
1148 /*
1149  * Power up a PCIe port.  PCIe requires the refclk to be stable for 100µs
1150  * prior to releasing PERST.  See table 2-4 in section 2.6.2 AC Specifications
1151  * of the PCI Express Card Electromechanical Specification, 1.1.
1152  */
1153 static int mvebu_pcie_powerup(struct mvebu_pcie_port *port)
1154 {
1155         int ret;
1156
1157         ret = clk_prepare_enable(port->clk);
1158         if (ret < 0)
1159                 return ret;
1160
1161         if (port->reset_gpio) {
1162                 u32 reset_udelay = 20000;
1163
1164                 of_property_read_u32(port->dn, "reset-delay-us",
1165                                      &reset_udelay);
1166
1167                 udelay(100);
1168
1169                 gpiod_set_value_cansleep(port->reset_gpio, 0);
1170                 msleep(reset_udelay / 1000);
1171         }
1172
1173         return 0;
1174 }
1175
1176 /*
1177  * Power down a PCIe port.  Strictly, PCIe requires us to place the card
1178  * in D3hot state before asserting PERST#.
1179  */
1180 static void mvebu_pcie_powerdown(struct mvebu_pcie_port *port)
1181 {
1182         if (port->reset_gpio)
1183                 gpiod_set_value_cansleep(port->reset_gpio, 1);
1184
1185         clk_disable_unprepare(port->clk);
1186 }
1187
1188 static int mvebu_pcie_probe(struct platform_device *pdev)
1189 {
1190         struct mvebu_pcie *pcie;
1191         struct device_node *np = pdev->dev.of_node;
1192         struct device_node *child;
1193         int num, i, ret;
1194
1195         pcie = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_pcie),
1196                             GFP_KERNEL);
1197         if (!pcie)
1198                 return -ENOMEM;
1199
1200         pcie->pdev = pdev;
1201         platform_set_drvdata(pdev, pcie);
1202
1203         /* Get the PCIe memory and I/O aperture */
1204         mvebu_mbus_get_pcie_mem_aperture(&pcie->mem);
1205         if (resource_size(&pcie->mem) == 0) {
1206                 dev_err(&pdev->dev, "invalid memory aperture size\n");
1207                 return -EINVAL;
1208         }
1209
1210         mvebu_mbus_get_pcie_io_aperture(&pcie->io);
1211
1212         if (resource_size(&pcie->io) != 0) {
1213                 pcie->realio.flags = pcie->io.flags;
1214                 pcie->realio.start = PCIBIOS_MIN_IO;
1215                 pcie->realio.end = min_t(resource_size_t,
1216                                          IO_SPACE_LIMIT,
1217                                          resource_size(&pcie->io));
1218         } else
1219                 pcie->realio = pcie->io;
1220
1221         /* Get the bus range */
1222         ret = of_pci_parse_bus_range(np, &pcie->busn);
1223         if (ret) {
1224                 dev_err(&pdev->dev, "failed to parse bus-range property: %d\n",
1225                         ret);
1226                 return ret;
1227         }
1228
1229         num = of_get_available_child_count(pdev->dev.of_node);
1230
1231         pcie->ports = devm_kcalloc(&pdev->dev, num, sizeof(*pcie->ports),
1232                                    GFP_KERNEL);
1233         if (!pcie->ports)
1234                 return -ENOMEM;
1235
1236         i = 0;
1237         for_each_available_child_of_node(pdev->dev.of_node, child) {
1238                 struct mvebu_pcie_port *port = &pcie->ports[i];
1239
1240                 ret = mvebu_pcie_parse_port(pcie, port, child);
1241                 if (ret < 0) {
1242                         of_node_put(child);
1243                         return ret;
1244                 } else if (ret == 0) {
1245                         continue;
1246                 }
1247
1248                 port->dn = child;
1249                 i++;
1250         }
1251         pcie->nports = i;
1252
1253         for (i = 0; i < pcie->nports; i++) {
1254                 struct mvebu_pcie_port *port = &pcie->ports[i];
1255
1256                 child = port->dn;
1257                 if (!child)
1258                         continue;
1259
1260                 ret = mvebu_pcie_powerup(port);
1261                 if (ret < 0)
1262                         continue;
1263
1264                 port->base = mvebu_pcie_map_registers(pdev, child, port);
1265                 if (IS_ERR(port->base)) {
1266                         dev_err(&pdev->dev, "%s: cannot map registers\n",
1267                                 port->name);
1268                         port->base = NULL;
1269                         mvebu_pcie_powerdown(port);
1270                         continue;
1271                 }
1272
1273                 mvebu_pcie_set_local_dev_nr(port, 1);
1274                 mvebu_sw_pci_bridge_init(port);
1275         }
1276
1277         pcie->nports = i;
1278
1279         for (i = 0; i < (IO_SPACE_LIMIT - SZ_64K); i += SZ_64K)
1280                 pci_ioremap_io(i, pcie->io.start + i);
1281
1282         mvebu_pcie_msi_enable(pcie);
1283         mvebu_pcie_enable(pcie);
1284
1285         platform_set_drvdata(pdev, pcie);
1286
1287         return 0;
1288 }
1289
1290 static const struct of_device_id mvebu_pcie_of_match_table[] = {
1291         { .compatible = "marvell,armada-xp-pcie", },
1292         { .compatible = "marvell,armada-370-pcie", },
1293         { .compatible = "marvell,dove-pcie", },
1294         { .compatible = "marvell,kirkwood-pcie", },
1295         {},
1296 };
1297 MODULE_DEVICE_TABLE(of, mvebu_pcie_of_match_table);
1298
1299 static struct dev_pm_ops mvebu_pcie_pm_ops = {
1300         .suspend_noirq = mvebu_pcie_suspend,
1301         .resume_noirq = mvebu_pcie_resume,
1302 };
1303
1304 static struct platform_driver mvebu_pcie_driver = {
1305         .driver = {
1306                 .name = "mvebu-pcie",
1307                 .of_match_table = mvebu_pcie_of_match_table,
1308                 /* driver unloading/unbinding currently not supported */
1309                 .suppress_bind_attrs = true,
1310                 .pm = &mvebu_pcie_pm_ops,
1311         },
1312         .probe = mvebu_pcie_probe,
1313 };
1314 module_platform_driver(mvebu_pcie_driver);
1315
1316 MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
1317 MODULE_DESCRIPTION("Marvell EBU PCIe driver");
1318 MODULE_LICENSE("GPL v2");