blob: 85348590848bdf16f2d8745179d90f582dd2c2c4 [file] [log] [blame]
Valentine Barshakba3eb9f2013-10-29 20:12:51 +04001/*
2 * pci-rcar-gen2: internal PCI bus support
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Cogent Embedded, Inc.
6 *
Paul Gortmaker0b9c1582016-07-02 19:13:30 -04007 * Author: Valentine Barshak <valentine.barshak@cogentembedded.com>
8 *
Valentine Barshakba3eb9f2013-10-29 20:12:51 +04009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/delay.h>
15#include <linux/init.h>
16#include <linux/interrupt.h>
17#include <linux/io.h>
18#include <linux/kernel.h>
Phil Edworthy8d598ca2015-11-03 16:19:26 +000019#include <linux/of_address.h>
Lucas Stachb9bfe1b2014-04-07 11:30:20 +020020#include <linux/of_pci.h>
Valentine Barshakba3eb9f2013-10-29 20:12:51 +040021#include <linux/pci.h>
22#include <linux/platform_device.h>
Valentine Barshakfb178d82013-12-04 20:33:35 +040023#include <linux/pm_runtime.h>
Magnus Damm33966fd2014-02-18 11:11:32 +090024#include <linux/sizes.h>
Valentine Barshakba3eb9f2013-10-29 20:12:51 +040025#include <linux/slab.h>
26
27/* AHB-PCI Bridge PCI communication registers */
28#define RCAR_AHBPCI_PCICOM_OFFSET 0x800
29
30#define RCAR_PCIAHB_WIN1_CTR_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x00)
31#define RCAR_PCIAHB_WIN2_CTR_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x04)
32#define RCAR_PCIAHB_PREFETCH0 0x0
33#define RCAR_PCIAHB_PREFETCH4 0x1
34#define RCAR_PCIAHB_PREFETCH8 0x2
35#define RCAR_PCIAHB_PREFETCH16 0x3
36
37#define RCAR_AHBPCI_WIN1_CTR_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x10)
38#define RCAR_AHBPCI_WIN2_CTR_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x14)
39#define RCAR_AHBPCI_WIN_CTR_MEM (3 << 1)
40#define RCAR_AHBPCI_WIN_CTR_CFG (5 << 1)
41#define RCAR_AHBPCI_WIN1_HOST (1 << 30)
42#define RCAR_AHBPCI_WIN1_DEVICE (1 << 31)
43
44#define RCAR_PCI_INT_ENABLE_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x20)
45#define RCAR_PCI_INT_STATUS_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x24)
Ben Dooks80a595d2014-02-18 11:11:01 +090046#define RCAR_PCI_INT_SIGTABORT (1 << 0)
47#define RCAR_PCI_INT_SIGRETABORT (1 << 1)
48#define RCAR_PCI_INT_REMABORT (1 << 2)
49#define RCAR_PCI_INT_PERR (1 << 3)
50#define RCAR_PCI_INT_SIGSERR (1 << 4)
51#define RCAR_PCI_INT_RESERR (1 << 5)
52#define RCAR_PCI_INT_WIN1ERR (1 << 12)
53#define RCAR_PCI_INT_WIN2ERR (1 << 13)
Valentine Barshakba3eb9f2013-10-29 20:12:51 +040054#define RCAR_PCI_INT_A (1 << 16)
55#define RCAR_PCI_INT_B (1 << 17)
56#define RCAR_PCI_INT_PME (1 << 19)
Ben Dooks80a595d2014-02-18 11:11:01 +090057#define RCAR_PCI_INT_ALLERRORS (RCAR_PCI_INT_SIGTABORT | \
58 RCAR_PCI_INT_SIGRETABORT | \
59 RCAR_PCI_INT_SIGRETABORT | \
60 RCAR_PCI_INT_REMABORT | \
61 RCAR_PCI_INT_PERR | \
62 RCAR_PCI_INT_SIGSERR | \
63 RCAR_PCI_INT_RESERR | \
64 RCAR_PCI_INT_WIN1ERR | \
65 RCAR_PCI_INT_WIN2ERR)
Valentine Barshakba3eb9f2013-10-29 20:12:51 +040066
67#define RCAR_AHB_BUS_CTR_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x30)
68#define RCAR_AHB_BUS_MMODE_HTRANS (1 << 0)
69#define RCAR_AHB_BUS_MMODE_BYTE_BURST (1 << 1)
70#define RCAR_AHB_BUS_MMODE_WR_INCR (1 << 2)
71#define RCAR_AHB_BUS_MMODE_HBUS_REQ (1 << 7)
72#define RCAR_AHB_BUS_SMODE_READYCTR (1 << 17)
73#define RCAR_AHB_BUS_MODE (RCAR_AHB_BUS_MMODE_HTRANS | \
74 RCAR_AHB_BUS_MMODE_BYTE_BURST | \
75 RCAR_AHB_BUS_MMODE_WR_INCR | \
76 RCAR_AHB_BUS_MMODE_HBUS_REQ | \
77 RCAR_AHB_BUS_SMODE_READYCTR)
78
79#define RCAR_USBCTR_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x34)
80#define RCAR_USBCTR_USBH_RST (1 << 0)
81#define RCAR_USBCTR_PCICLK_MASK (1 << 1)
82#define RCAR_USBCTR_PLL_RST (1 << 2)
83#define RCAR_USBCTR_DIRPD (1 << 8)
84#define RCAR_USBCTR_PCIAHB_WIN2_EN (1 << 9)
85#define RCAR_USBCTR_PCIAHB_WIN1_256M (0 << 10)
86#define RCAR_USBCTR_PCIAHB_WIN1_512M (1 << 10)
87#define RCAR_USBCTR_PCIAHB_WIN1_1G (2 << 10)
88#define RCAR_USBCTR_PCIAHB_WIN1_2G (3 << 10)
89#define RCAR_USBCTR_PCIAHB_WIN1_MASK (3 << 10)
90
91#define RCAR_PCI_ARBITER_CTR_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x40)
92#define RCAR_PCI_ARBITER_PCIREQ0 (1 << 0)
93#define RCAR_PCI_ARBITER_PCIREQ1 (1 << 1)
94#define RCAR_PCI_ARBITER_PCIBP_MODE (1 << 12)
95
96#define RCAR_PCI_UNIT_REV_REG (RCAR_AHBPCI_PCICOM_OFFSET + 0x48)
97
Valentine Barshakba3eb9f2013-10-29 20:12:51 +040098struct rcar_pci_priv {
Valentine Barshakfb178d82013-12-04 20:33:35 +040099 struct device *dev;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400100 void __iomem *reg;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400101 struct resource mem_res;
102 struct resource *cfg_res;
Ben Dooksd47b62f2014-05-20 01:10:20 +0400103 unsigned busnr;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400104 int irq;
Magnus Damm33966fd2014-02-18 11:11:32 +0900105 unsigned long window_size;
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000106 unsigned long window_addr;
107 unsigned long window_pci;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400108};
109
110/* PCI configuration space operations */
111static void __iomem *rcar_pci_cfg_base(struct pci_bus *bus, unsigned int devfn,
112 int where)
113{
114 struct pci_sys_data *sys = bus->sysdata;
115 struct rcar_pci_priv *priv = sys->private_data;
116 int slot, val;
117
118 if (sys->busnr != bus->number || PCI_FUNC(devfn))
119 return NULL;
120
121 /* Only one EHCI/OHCI device built-in */
122 slot = PCI_SLOT(devfn);
123 if (slot > 2)
124 return NULL;
125
Ben Dookse64a2a92014-02-18 11:11:11 +0900126 /* bridge logic only has registers to 0x40 */
127 if (slot == 0x0 && where >= 0x40)
128 return NULL;
129
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400130 val = slot ? RCAR_AHBPCI_WIN1_DEVICE | RCAR_AHBPCI_WIN_CTR_CFG :
131 RCAR_AHBPCI_WIN1_HOST | RCAR_AHBPCI_WIN_CTR_CFG;
132
133 iowrite32(val, priv->reg + RCAR_AHBPCI_WIN1_CTR_REG);
134 return priv->reg + (slot >> 1) * 0x100 + where;
135}
136
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400137/* PCI interrupt mapping */
Magnus Damm546cadd2014-02-18 11:11:21 +0900138static int rcar_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400139{
140 struct pci_sys_data *sys = dev->bus->sysdata;
141 struct rcar_pci_priv *priv = sys->private_data;
Lucas Stachb9bfe1b2014-04-07 11:30:20 +0200142 int irq;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400143
Lucas Stachb9bfe1b2014-04-07 11:30:20 +0200144 irq = of_irq_parse_and_map_pci(dev, slot, pin);
145 if (!irq)
146 irq = priv->irq;
147
148 return irq;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400149}
150
Ben Dooks80a595d2014-02-18 11:11:01 +0900151#ifdef CONFIG_PCI_DEBUG
152/* if debug enabled, then attach an error handler irq to the bridge */
153
154static irqreturn_t rcar_pci_err_irq(int irq, void *pw)
155{
156 struct rcar_pci_priv *priv = pw;
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500157 struct device *dev = priv->dev;
Ben Dooks80a595d2014-02-18 11:11:01 +0900158 u32 status = ioread32(priv->reg + RCAR_PCI_INT_STATUS_REG);
159
160 if (status & RCAR_PCI_INT_ALLERRORS) {
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500161 dev_err(dev, "error irq: status %08x\n", status);
Ben Dooks80a595d2014-02-18 11:11:01 +0900162
163 /* clear the error(s) */
164 iowrite32(status & RCAR_PCI_INT_ALLERRORS,
165 priv->reg + RCAR_PCI_INT_STATUS_REG);
166 return IRQ_HANDLED;
167 }
168
169 return IRQ_NONE;
170}
171
172static void rcar_pci_setup_errirq(struct rcar_pci_priv *priv)
173{
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500174 struct device *dev = priv->dev;
Ben Dooks80a595d2014-02-18 11:11:01 +0900175 int ret;
176 u32 val;
177
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500178 ret = devm_request_irq(dev, priv->irq, rcar_pci_err_irq,
Ben Dooks80a595d2014-02-18 11:11:01 +0900179 IRQF_SHARED, "error irq", priv);
180 if (ret) {
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500181 dev_err(dev, "cannot claim IRQ for error handling\n");
Ben Dooks80a595d2014-02-18 11:11:01 +0900182 return;
183 }
184
185 val = ioread32(priv->reg + RCAR_PCI_INT_ENABLE_REG);
186 val |= RCAR_PCI_INT_ALLERRORS;
187 iowrite32(val, priv->reg + RCAR_PCI_INT_ENABLE_REG);
188}
189#else
190static inline void rcar_pci_setup_errirq(struct rcar_pci_priv *priv) { }
191#endif
192
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400193/* PCI host controller setup */
Magnus Damm546cadd2014-02-18 11:11:21 +0900194static int rcar_pci_setup(int nr, struct pci_sys_data *sys)
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400195{
196 struct rcar_pci_priv *priv = sys->private_data;
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500197 struct device *dev = priv->dev;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400198 void __iomem *reg = priv->reg;
199 u32 val;
Bjorn Helgaasac575ea2016-06-06 17:26:31 -0500200 int ret;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400201
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500202 pm_runtime_enable(dev);
203 pm_runtime_get_sync(dev);
Valentine Barshakfb178d82013-12-04 20:33:35 +0400204
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400205 val = ioread32(reg + RCAR_PCI_UNIT_REV_REG);
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500206 dev_info(dev, "PCI: bus%u revision %x\n", sys->busnr, val);
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400207
208 /* Disable Direct Power Down State and assert reset */
209 val = ioread32(reg + RCAR_USBCTR_REG) & ~RCAR_USBCTR_DIRPD;
210 val |= RCAR_USBCTR_USBH_RST | RCAR_USBCTR_PLL_RST;
211 iowrite32(val, reg + RCAR_USBCTR_REG);
212 udelay(4);
213
Magnus Damm33966fd2014-02-18 11:11:32 +0900214 /* De-assert reset and reset PCIAHB window1 size */
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400215 val &= ~(RCAR_USBCTR_PCIAHB_WIN1_MASK | RCAR_USBCTR_PCICLK_MASK |
216 RCAR_USBCTR_USBH_RST | RCAR_USBCTR_PLL_RST);
Magnus Damm33966fd2014-02-18 11:11:32 +0900217
218 /* Setup PCIAHB window1 size */
219 switch (priv->window_size) {
220 case SZ_2G:
221 val |= RCAR_USBCTR_PCIAHB_WIN1_2G;
222 break;
223 case SZ_1G:
224 val |= RCAR_USBCTR_PCIAHB_WIN1_1G;
225 break;
226 case SZ_512M:
227 val |= RCAR_USBCTR_PCIAHB_WIN1_512M;
228 break;
229 default:
230 pr_warn("unknown window size %ld - defaulting to 256M\n",
231 priv->window_size);
232 priv->window_size = SZ_256M;
233 /* fall-through */
234 case SZ_256M:
235 val |= RCAR_USBCTR_PCIAHB_WIN1_256M;
236 break;
237 }
238 iowrite32(val, reg + RCAR_USBCTR_REG);
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400239
240 /* Configure AHB master and slave modes */
241 iowrite32(RCAR_AHB_BUS_MODE, reg + RCAR_AHB_BUS_CTR_REG);
242
243 /* Configure PCI arbiter */
244 val = ioread32(reg + RCAR_PCI_ARBITER_CTR_REG);
245 val |= RCAR_PCI_ARBITER_PCIREQ0 | RCAR_PCI_ARBITER_PCIREQ1 |
246 RCAR_PCI_ARBITER_PCIBP_MODE;
247 iowrite32(val, reg + RCAR_PCI_ARBITER_CTR_REG);
248
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000249 /* PCI-AHB mapping */
250 iowrite32(priv->window_addr | RCAR_PCIAHB_PREFETCH16,
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400251 reg + RCAR_PCIAHB_WIN1_CTR_REG);
252
253 /* AHB-PCI mapping: OHCI/EHCI registers */
254 val = priv->mem_res.start | RCAR_AHBPCI_WIN_CTR_MEM;
255 iowrite32(val, reg + RCAR_AHBPCI_WIN2_CTR_REG);
256
257 /* Enable AHB-PCI bridge PCI configuration access */
258 iowrite32(RCAR_AHBPCI_WIN1_HOST | RCAR_AHBPCI_WIN_CTR_CFG,
259 reg + RCAR_AHBPCI_WIN1_CTR_REG);
260 /* Set PCI-AHB Window1 address */
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000261 iowrite32(priv->window_pci | PCI_BASE_ADDRESS_MEM_PREFETCH,
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400262 reg + PCI_BASE_ADDRESS_1);
263 /* Set AHB-PCI bridge PCI communication area address */
264 val = priv->cfg_res->start + RCAR_AHBPCI_PCICOM_OFFSET;
265 iowrite32(val, reg + PCI_BASE_ADDRESS_0);
266
267 val = ioread32(reg + PCI_COMMAND);
268 val |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
269 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
270 iowrite32(val, reg + PCI_COMMAND);
271
272 /* Enable PCI interrupts */
273 iowrite32(RCAR_PCI_INT_A | RCAR_PCI_INT_B | RCAR_PCI_INT_PME,
274 reg + RCAR_PCI_INT_ENABLE_REG);
275
Ben Dooks80a595d2014-02-18 11:11:01 +0900276 if (priv->irq > 0)
277 rcar_pci_setup_errirq(priv);
278
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400279 /* Add PCI resources */
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400280 pci_add_resource(&sys->resources, &priv->mem_res);
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500281 ret = devm_request_pci_bus_resources(dev, &sys->resources);
Bjorn Helgaasac575ea2016-06-06 17:26:31 -0500282 if (ret < 0)
283 return ret;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400284
Ben Dooksd47b62f2014-05-20 01:10:20 +0400285 /* Setup bus number based on platform device id / of bus-range */
286 sys->busnr = priv->busnr;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400287 return 1;
288}
289
290static struct pci_ops rcar_pci_ops = {
Rob Herringb44923b2015-01-09 20:34:47 -0600291 .map_bus = rcar_pci_cfg_base,
292 .read = pci_generic_config_read,
293 .write = pci_generic_config_write,
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400294};
295
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000296static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
297 struct device_node *node)
298{
299 const int na = 3, ns = 2;
300 int rlen;
301
302 parser->node = node;
303 parser->pna = of_n_addr_cells(node);
304 parser->np = parser->pna + na + ns;
305
306 parser->range = of_get_property(node, "dma-ranges", &rlen);
307 if (!parser->range)
308 return -ENOENT;
309
310 parser->end = parser->range + rlen / sizeof(__be32);
311 return 0;
312}
313
314static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci,
315 struct device_node *np)
316{
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500317 struct device *dev = pci->dev;
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000318 struct of_pci_range range;
319 struct of_pci_range_parser parser;
320 int index = 0;
321
322 /* Failure to parse is ok as we fall back to defaults */
323 if (pci_dma_range_parser_init(&parser, np))
324 return 0;
325
326 /* Get the dma-ranges from DT */
327 for_each_of_pci_range(&parser, &range) {
328 /* Hardware only allows one inbound 32-bit range */
329 if (index)
330 return -EINVAL;
331
332 pci->window_addr = (unsigned long)range.cpu_addr;
333 pci->window_pci = (unsigned long)range.pci_addr;
334 pci->window_size = (unsigned long)range.size;
335
336 /* Catch HW limitations */
337 if (!(range.flags & IORESOURCE_PREFETCH)) {
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500338 dev_err(dev, "window must be prefetchable\n");
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000339 return -EINVAL;
340 }
341 if (pci->window_addr) {
342 u32 lowaddr = 1 << (ffs(pci->window_addr) - 1);
343
344 if (lowaddr < pci->window_size) {
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500345 dev_err(dev, "invalid window size/addr\n");
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000346 return -EINVAL;
347 }
348 }
349 index++;
350 }
351
352 return 0;
353}
354
Magnus Damm546cadd2014-02-18 11:11:21 +0900355static int rcar_pci_probe(struct platform_device *pdev)
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400356{
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500357 struct device *dev = &pdev->dev;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400358 struct resource *cfg_res, *mem_res;
359 struct rcar_pci_priv *priv;
360 void __iomem *reg;
Magnus Damm546cadd2014-02-18 11:11:21 +0900361 struct hw_pci hw;
362 void *hw_private[1];
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400363
364 cfg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500365 reg = devm_ioremap_resource(dev, cfg_res);
Wei Yongjunc176d1c2013-11-19 11:40:28 +0800366 if (IS_ERR(reg))
367 return PTR_ERR(reg);
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400368
369 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
370 if (!mem_res || !mem_res->start)
371 return -ENODEV;
372
Nobuhiro Iwamatsu7a27db22015-02-16 10:54:08 +0900373 if (mem_res->start & 0xFFFF)
374 return -EINVAL;
375
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500376 priv = devm_kzalloc(dev, sizeof(struct rcar_pci_priv), GFP_KERNEL);
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400377 if (!priv)
378 return -ENOMEM;
379
380 priv->mem_res = *mem_res;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400381 priv->cfg_res = cfg_res;
382
383 priv->irq = platform_get_irq(pdev, 0);
384 priv->reg = reg;
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500385 priv->dev = dev;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400386
Ben Dooksed65b782014-02-18 11:10:51 +0900387 if (priv->irq < 0) {
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500388 dev_err(dev, "no valid irq found\n");
Ben Dooksed65b782014-02-18 11:10:51 +0900389 return priv->irq;
390 }
391
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000392 /* default window addr and size if not specified in DT */
393 priv->window_addr = 0x40000000;
394 priv->window_pci = 0x40000000;
Magnus Damm33966fd2014-02-18 11:11:32 +0900395 priv->window_size = SZ_1G;
396
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500397 if (dev->of_node) {
Ben Dooksd47b62f2014-05-20 01:10:20 +0400398 struct resource busnr;
399 int ret;
400
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500401 ret = of_pci_parse_bus_range(dev->of_node, &busnr);
Ben Dooksd47b62f2014-05-20 01:10:20 +0400402 if (ret < 0) {
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500403 dev_err(dev, "failed to parse bus-range\n");
Ben Dooksd47b62f2014-05-20 01:10:20 +0400404 return ret;
405 }
406
407 priv->busnr = busnr.start;
408 if (busnr.end != busnr.start)
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500409 dev_warn(dev, "only one bus number supported\n");
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000410
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500411 ret = rcar_pci_parse_map_dma_ranges(priv, dev->of_node);
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000412 if (ret < 0) {
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500413 dev_err(dev, "failed to parse dma-range\n");
Phil Edworthy8d598ca2015-11-03 16:19:26 +0000414 return ret;
415 }
Ben Dooksd47b62f2014-05-20 01:10:20 +0400416 } else {
417 priv->busnr = pdev->id;
418 }
419
Magnus Damm546cadd2014-02-18 11:11:21 +0900420 hw_private[0] = priv;
421 memset(&hw, 0, sizeof(hw));
422 hw.nr_controllers = ARRAY_SIZE(hw_private);
Bjorn Helgaasb2a5d3e2016-06-21 09:19:34 -0500423 hw.io_optional = 1;
Magnus Damm546cadd2014-02-18 11:11:21 +0900424 hw.private_data = hw_private;
425 hw.map_irq = rcar_pci_map_irq;
426 hw.ops = &rcar_pci_ops;
427 hw.setup = rcar_pci_setup;
Bjorn Helgaasde9e6bc2016-10-10 15:04:14 -0500428 pci_common_init_dev(dev, &hw);
Magnus Damm546cadd2014-02-18 11:11:21 +0900429 return 0;
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400430}
431
Ben Dooksd47b62f2014-05-20 01:10:20 +0400432static struct of_device_id rcar_pci_of_match[] = {
433 { .compatible = "renesas,pci-r8a7790", },
434 { .compatible = "renesas,pci-r8a7791", },
Sergei Shtylyovde24c182015-09-12 02:06:09 +0300435 { .compatible = "renesas,pci-r8a7794", },
Simon Horman7b99d942016-12-06 16:51:29 +0100436 { .compatible = "renesas,pci-rcar-gen2", },
Ben Dooksd47b62f2014-05-20 01:10:20 +0400437 { },
438};
439
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400440static struct platform_driver rcar_pci_driver = {
441 .driver = {
442 .name = "pci-rcar-gen2",
Magnus Damm546cadd2014-02-18 11:11:21 +0900443 .suppress_bind_attrs = true,
Ben Dooksd47b62f2014-05-20 01:10:20 +0400444 .of_match_table = rcar_pci_of_match,
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400445 },
Magnus Damm546cadd2014-02-18 11:11:21 +0900446 .probe = rcar_pci_probe,
Valentine Barshakba3eb9f2013-10-29 20:12:51 +0400447};
Paul Gortmaker0b9c1582016-07-02 19:13:30 -0400448builtin_platform_driver(rcar_pci_driver);