1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * BCM6348 PCI Controller Driver
5 * Copyright (C) 2020 Álvaro Fernández Rojas <noltari@gmail.com>
6 * Copyright (C) 2015 Jonas Gorski <jonas.gorski@gmail.com>
7 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
10 #include <linux/clk.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/kernel.h>
14 #include <linux/memblock.h>
16 #include <linux/of_address.h>
17 #include <linux/of_gpio.h>
18 #include <linux/of_irq.h>
19 #include <linux/of_pci.h>
20 #include <linux/of_platform.h>
21 #include <linux/pci.h>
22 #include <linux/reset.h>
23 #include <linux/types.h>
24 #include <linux/vmalloc.h>
28 #define CARDBUS_DUMMY_ID 0x6348
29 #define CARDBUS_PCI_IDSEL 0x8
30 #define FAKE_CB_BRIDGE_SLOT 0x1e
32 #define BCMPCI_REG_TIMERS 0x40
33 #define REG_TIMER_TRDY_SHIFT 0
34 #define REG_TIMER_TRDY_MASK (0xff << REG_TIMER_TRDY_SHIFT)
35 #define REG_TIMER_RETRY_SHIFT 8
36 #define REG_TIMER_RETRY_MASK (0xff << REG_TIMER_RETRY_SHIFT)
38 #define MPI_SP0_RANGE_REG 0x100
39 #define MPI_SP0_REMAP_REG 0x104
40 #define MPI_SP0_REMAP_ENABLE_MASK (1 << 0)
41 #define MPI_SP1_RANGE_REG 0x10C
42 #define MPI_SP1_REMAP_REG 0x110
43 #define MPI_SP1_REMAP_ENABLE_MASK (1 << 0)
45 #define MPI_L2PCFG_REG 0x11c
46 #define MPI_L2PCFG_CFG_TYPE_SHIFT 0
47 #define MPI_L2PCFG_CFG_TYPE_MASK (0x3 << MPI_L2PCFG_CFG_TYPE_SHIFT)
48 #define MPI_L2PCFG_REG_SHIFT 2
49 #define MPI_L2PCFG_REG_MASK (0x3f << MPI_L2PCFG_REG_SHIFT)
50 #define MPI_L2PCFG_FUNC_SHIFT 8
51 #define MPI_L2PCFG_FUNC_MASK (0x7 << MPI_L2PCFG_FUNC_SHIFT)
52 #define MPI_L2PCFG_DEVNUM_SHIFT 11
53 #define MPI_L2PCFG_DEVNUM_MASK (0x1f << MPI_L2PCFG_DEVNUM_SHIFT)
54 #define MPI_L2PCFG_CFG_USEREG_MASK (1 << 30)
55 #define MPI_L2PCFG_CFG_SEL_MASK (1 << 31)
57 #define MPI_L2PMEMRANGE1_REG 0x120
58 #define MPI_L2PMEMBASE1_REG 0x124
59 #define MPI_L2PMEMREMAP1_REG 0x128
60 #define MPI_L2PMEMRANGE2_REG 0x12C
61 #define MPI_L2PMEMBASE2_REG 0x130
62 #define MPI_L2PMEMREMAP2_REG 0x134
63 #define MPI_L2PIORANGE_REG 0x138
64 #define MPI_L2PIOBASE_REG 0x13C
65 #define MPI_L2PIOREMAP_REG 0x140
66 #define MPI_L2P_BASE_MASK (0xffff8000)
67 #define MPI_L2PREMAP_ENABLED_MASK (1 << 0)
68 #define MPI_L2PREMAP_IS_CARDBUS_MASK (1 << 2)
70 #define MPI_PCIMODESEL_REG 0x144
71 #define MPI_PCIMODESEL_BAR1_NOSWAP_MASK (1 << 0)
72 #define MPI_PCIMODESEL_BAR2_NOSWAP_MASK (1 << 1)
73 #define MPI_PCIMODESEL_EXT_ARB_MASK (1 << 2)
74 #define MPI_PCIMODESEL_PREFETCH_SHIFT 4
75 #define MPI_PCIMODESEL_PREFETCH_MASK (0xf << MPI_PCIMODESEL_PREFETCH_SHIFT)
77 #define MPI_LOCBUSCTL_REG 0x14c
78 #define MPI_LOCBUSCTL_EN_PCI_GPIO_MASK (1 << 0)
79 #define MPI_LOCBUSCTL_U2P_NOSWAP_MASK (1 << 1)
81 #define MPI_LOCINT_REG 0x150
82 #define MPI_LOCINT_MASK(x) (1 << (x + 16))
83 #define MPI_LOCINT_STAT(x) (1 << (x))
84 #define MPI_LOCINT_DIR_FAILED 6
85 #define MPI_LOCINT_EXT_PCI_INT 7
86 #define MPI_LOCINT_SERR 8
87 #define MPI_LOCINT_CSERR 9
89 #define MPI_PCICFGCTL_REG 0x178
90 #define MPI_PCICFGCTL_CFGADDR_SHIFT 2
91 #define MPI_PCICFGCTL_CFGADDR_MASK (0x1f << MPI_PCICFGCTL_CFGADDR_SHIFT)
92 #define MPI_PCICFGCTL_WRITEEN_MASK (1 << 7)
94 #define MPI_PCICFGDATA_REG 0x17c
96 #define PCMCIA_OFFSET 0x54
98 #define PCMCIA_C1_REG 0x0
99 #define PCMCIA_C1_CD1_MASK (1 << 0)
100 #define PCMCIA_C1_CD2_MASK (1 << 1)
101 #define PCMCIA_C1_VS1_MASK (1 << 2)
102 #define PCMCIA_C1_VS2_MASK (1 << 3)
103 #define PCMCIA_C1_VS1OE_MASK (1 << 6)
104 #define PCMCIA_C1_VS2OE_MASK (1 << 7)
105 #define PCMCIA_C1_CBIDSEL_SHIFT (8)
106 #define PCMCIA_C1_CBIDSEL_MASK (0x1f << PCMCIA_C1_CBIDSEL_SHIFT)
107 #define PCMCIA_C1_EN_PCMCIA_GPIO_MASK (1 << 13)
108 #define PCMCIA_C1_EN_PCMCIA_MASK (1 << 14)
109 #define PCMCIA_C1_EN_CARDBUS_MASK (1 << 15)
110 #define PCMCIA_C1_RESET_MASK (1 << 18)
112 #ifdef CONFIG_CARDBUS
132 #endif /* CONFIG_CARDBUS */
136 void __iomem
*pcmcia
;
139 struct reset_control
*reset
;
141 #ifdef CONFIG_CARDBUS
142 struct bcm6348_cb cb
;
144 #endif /* CONFIG_CARDBUS */
147 static struct bcm6348_pci bcm6348_pci
;
149 extern int bmips_pci_irq
;
151 static u32
bcm6348_int_cfg_readl(u32 reg
)
153 struct bcm6348_pci
*priv
= &bcm6348_pci
;
156 tmp
= reg
& MPI_PCICFGCTL_CFGADDR_MASK
;
157 tmp
|= MPI_PCICFGCTL_WRITEEN_MASK
;
158 __raw_writel(tmp
, priv
->pci
+ MPI_PCICFGCTL_REG
);
160 return __raw_readl(priv
->pci
+ MPI_PCICFGDATA_REG
);
163 static void bcm6348_int_cfg_writel(u32 val
, u32 reg
)
165 struct bcm6348_pci
*priv
= &bcm6348_pci
;
168 tmp
= reg
& MPI_PCICFGCTL_CFGADDR_MASK
;
169 tmp
|= MPI_PCICFGCTL_WRITEEN_MASK
;
170 __raw_writel(tmp
, priv
->pci
+ MPI_PCICFGCTL_REG
);
171 __raw_writel(val
, priv
->pci
+ MPI_PCICFGDATA_REG
);
175 * swizzle 32bits data to return only the needed part
177 static int postprocess_read(u32 data
, int where
, unsigned int size
)
183 ret
= (data
>> ((where
& 3) << 3)) & 0xff;
186 ret
= (data
>> ((where
& 3) << 3)) & 0xffff;
196 static int preprocess_write(u32 orig_data
, u32 val
, int where
,
203 ret
= (orig_data
& ~(0xff << ((where
& 3) << 3))) |
204 (val
<< ((where
& 3) << 3));
207 ret
= (orig_data
& ~(0xffff << ((where
& 3) << 3))) |
208 (val
<< ((where
& 3) << 3));
218 static int bcm6348_setup_cfg_access(int type
, unsigned int busn
,
219 unsigned int devfn
, int where
)
221 struct bcm6348_pci
*priv
= &bcm6348_pci
;
222 unsigned int slot
, func
, reg
;
225 slot
= PCI_SLOT(devfn
);
226 func
= PCI_FUNC(devfn
);
230 if (slot
> (MPI_L2PCFG_DEVNUM_MASK
>> MPI_L2PCFG_DEVNUM_SHIFT
))
233 if (func
> (MPI_L2PCFG_FUNC_MASK
>> MPI_L2PCFG_FUNC_SHIFT
))
236 if (reg
> (MPI_L2PCFG_REG_MASK
>> MPI_L2PCFG_REG_SHIFT
))
239 /* ok, setup config access */
240 val
= (reg
<< MPI_L2PCFG_REG_SHIFT
);
241 val
|= (func
<< MPI_L2PCFG_FUNC_SHIFT
);
242 val
|= (slot
<< MPI_L2PCFG_DEVNUM_SHIFT
);
243 val
|= MPI_L2PCFG_CFG_USEREG_MASK
;
244 val
|= MPI_L2PCFG_CFG_SEL_MASK
;
245 /* type 0 cycle for local bus, type 1 cycle for anything else */
247 /* FIXME: how to specify bus ??? */
248 val
|= (1 << MPI_L2PCFG_CFG_TYPE_SHIFT
);
250 __raw_writel(val
, priv
->pci
+ MPI_L2PCFG_REG
);
256 static int bcm6348_do_cfg_read(int type
, unsigned int busn
,
257 unsigned int devfn
, int where
, int size
,
260 struct bcm6348_pci
*priv
= &bcm6348_pci
;
263 /* two phase cycle, first we write address, then read data at
264 * another location, caller already has a spinlock so no need
266 if (bcm6348_setup_cfg_access(type
, busn
, devfn
, where
))
267 return PCIBIOS_DEVICE_NOT_FOUND
;
269 data
= le32_to_cpu(__raw_readl(priv
->io
));
270 /* restore IO space normal behaviour */
271 __raw_writel(0, priv
->pci
+ MPI_L2PCFG_REG
);
273 *val
= postprocess_read(data
, where
, size
);
275 return PCIBIOS_SUCCESSFUL
;
278 static int bcm6348_do_cfg_write(int type
, unsigned int busn
,
279 unsigned int devfn
, int where
, int size
,
282 struct bcm6348_pci
*priv
= &bcm6348_pci
;
285 /* two phase cycle, first we write address, then write data to
286 * another location, caller already has a spinlock so no need
288 if (bcm6348_setup_cfg_access(type
, busn
, devfn
, where
))
289 return PCIBIOS_DEVICE_NOT_FOUND
;
292 data
= le32_to_cpu(__raw_readl(priv
->io
));
293 data
= preprocess_write(data
, val
, where
, size
);
295 __raw_writel(cpu_to_le32(data
), priv
->io
);
297 /* no way to know the access is done, we have to wait */
299 /* restore IO space normal behaviour */
300 __raw_writel(0, priv
->pci
+ MPI_L2PCFG_REG
);
302 return PCIBIOS_SUCCESSFUL
;
305 static int bcm6348_pci_read(struct pci_bus
*bus
, unsigned int devfn
,
306 int where
, int size
, u32
*val
)
310 type
= bus
->parent
? 1 : 0;
312 if (type
== 0 && PCI_SLOT(devfn
) == CARDBUS_PCI_IDSEL
)
313 return PCIBIOS_DEVICE_NOT_FOUND
;
315 return bcm6348_do_cfg_read(type
, bus
->number
, devfn
,
319 static int bcm6348_pci_write(struct pci_bus
*bus
, unsigned int devfn
,
320 int where
, int size
, u32 val
)
324 type
= bus
->parent
? 1 : 0;
326 if (type
== 0 && PCI_SLOT(devfn
) == CARDBUS_PCI_IDSEL
)
327 return PCIBIOS_DEVICE_NOT_FOUND
;
329 return bcm6348_do_cfg_write(type
, bus
->number
, devfn
,
333 static struct pci_ops bcm6348_pci_ops
= {
334 .read
= bcm6348_pci_read
,
335 .write
= bcm6348_pci_write
,
338 static struct resource bcm6348_pci_io_resource
;
339 static struct resource bcm6348_pci_mem_resource
;
340 static struct resource bcm6348_pci_busn_resource
;
342 static struct pci_controller bcm6348_pci_controller
= {
343 .pci_ops
= &bcm6348_pci_ops
,
344 .io_resource
= &bcm6348_pci_io_resource
,
345 .mem_resource
= &bcm6348_pci_mem_resource
,
348 #ifdef CONFIG_CARDBUS
349 static int bcm6348_cb_bridge_read(int where
, int size
, u32
*val
)
351 struct bcm6348_cb
*cb
= &bcm6348_pci
.cb
;
358 case (PCI_VENDOR_ID
>> 2):
359 case (PCI_CB_SUBSYSTEM_VENDOR_ID
>> 2):
360 /* create dummy vendor/device id from our cpu id */
361 data
= (CARDBUS_DUMMY_ID
<< 16) | PCI_VENDOR_ID_BROADCOM
;
364 case (PCI_COMMAND
>> 2):
365 data
= (PCI_STATUS_DEVSEL_SLOW
<< 16);
366 data
|= cb
->pci_command
;
369 case (PCI_CLASS_REVISION
>> 2):
370 data
= (PCI_CLASS_BRIDGE_CARDBUS
<< 16);
373 case (PCI_CACHE_LINE_SIZE
>> 2):
374 data
= (PCI_HEADER_TYPE_CARDBUS
<< 16);
377 case (PCI_INTERRUPT_LINE
>> 2):
379 data
= (cb
->bridge_control
<< 16);
380 /* pin:intA line:0xff */
381 data
|= (0x1 << 8) | 0xff;
384 case (PCI_CB_PRIMARY_BUS
>> 2):
385 data
= (cb
->cb_latency
<< 24);
386 data
|= (cb
->subordinate_busn
<< 16);
387 data
|= (cb
->cardbus_busn
<< 8);
388 data
|= cb
->pci_busn
;
391 case (PCI_CB_MEMORY_BASE_0
>> 2):
392 data
= cb
->mem_base0
;
395 case (PCI_CB_MEMORY_LIMIT_0
>> 2):
396 data
= cb
->mem_limit0
;
399 case (PCI_CB_MEMORY_BASE_1
>> 2):
400 data
= cb
->mem_base1
;
403 case (PCI_CB_MEMORY_LIMIT_1
>> 2):
404 data
= cb
->mem_limit1
;
407 case (PCI_CB_IO_BASE_0
>> 2):
408 /* | 1 for 32bits io support */
409 data
= cb
->io_base0
| 0x1;
412 case (PCI_CB_IO_LIMIT_0
>> 2):
413 data
= cb
->io_limit0
;
416 case (PCI_CB_IO_BASE_1
>> 2):
417 /* | 1 for 32bits io support */
418 data
= cb
->io_base1
| 0x1;
421 case (PCI_CB_IO_LIMIT_1
>> 2):
422 data
= cb
->io_limit1
;
426 *val
= postprocess_read(data
, where
, size
);
427 return PCIBIOS_SUCCESSFUL
;
431 * emulate configuration write access on a cardbus bridge
433 static int bcm6348_cb_bridge_write(int where
, int size
, u32 val
)
435 struct bcm6348_cb
*cb
= &bcm6348_pci
.cb
;
440 ret
= bcm6348_cb_bridge_read((where
& ~0x3), 4, &data
);
441 if (ret
!= PCIBIOS_SUCCESSFUL
)
444 data
= preprocess_write(data
, val
, where
, size
);
448 case (PCI_COMMAND
>> 2):
449 cb
->pci_command
= (data
& 0xffff);
452 case (PCI_CB_PRIMARY_BUS
>> 2):
453 cb
->cb_latency
= (data
>> 24) & 0xff;
454 cb
->subordinate_busn
= (data
>> 16) & 0xff;
455 cb
->cardbus_busn
= (data
>> 8) & 0xff;
456 cb
->pci_busn
= data
& 0xff;
457 if (cb
->cardbus_busn
)
458 cb
->bus_assigned
= 1;
461 case (PCI_INTERRUPT_LINE
>> 2):
462 tmp
= (data
>> 16) & 0xffff;
463 /* Disable memory prefetch support */
464 tmp
&= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM0
;
465 tmp
&= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1
;
466 cb
->bridge_control
= tmp
;
469 case (PCI_CB_MEMORY_BASE_0
>> 2):
470 cb
->mem_base0
= data
;
473 case (PCI_CB_MEMORY_LIMIT_0
>> 2):
474 cb
->mem_limit0
= data
;
477 case (PCI_CB_MEMORY_BASE_1
>> 2):
478 cb
->mem_base1
= data
;
481 case (PCI_CB_MEMORY_LIMIT_1
>> 2):
482 cb
->mem_limit1
= data
;
485 case (PCI_CB_IO_BASE_0
>> 2):
489 case (PCI_CB_IO_LIMIT_0
>> 2):
490 cb
->io_limit0
= data
;
493 case (PCI_CB_IO_BASE_1
>> 2):
497 case (PCI_CB_IO_LIMIT_1
>> 2):
498 cb
->io_limit1
= data
;
502 return PCIBIOS_SUCCESSFUL
;
505 static int bcm6348_cb_read(struct pci_bus
*bus
, unsigned int devfn
,
506 int where
, int size
, u32
*val
)
508 struct bcm6348_pci
*priv
= &bcm6348_pci
;
509 struct bcm6348_cb
*cb
= &priv
->cb
;
511 /* Snoop access to slot 0x1e on root bus, we fake a cardbus
512 * bridge at this location */
513 if (!bus
->parent
&& PCI_SLOT(devfn
) == FAKE_CB_BRIDGE_SLOT
) {
514 priv
->cb_bus
= bus
->number
;
515 return bcm6348_cb_bridge_read(where
, size
, val
);
518 /* A configuration cycle for the device behind the cardbus
519 * bridge is actually done as a type 0 cycle on the primary
520 * bus. This means that only one device can be on the cardbus
522 if (cb
->bus_assigned
&&
523 bus
->number
== cb
->cardbus_busn
&&
524 PCI_SLOT(devfn
) == 0)
525 return bcm6348_do_cfg_read(0, 0,
526 PCI_DEVFN(CARDBUS_PCI_IDSEL
, 0),
529 return PCIBIOS_DEVICE_NOT_FOUND
;
532 static int bcm6348_cb_write(struct pci_bus
*bus
, unsigned int devfn
,
533 int where
, int size
, u32 val
)
535 struct bcm6348_pci
*priv
= &bcm6348_pci
;
536 struct bcm6348_cb
*cb
= &priv
->cb
;
538 if (!bus
->parent
&& PCI_SLOT(devfn
) == FAKE_CB_BRIDGE_SLOT
) {
539 priv
->cb_bus
= bus
->number
;
540 return bcm6348_cb_bridge_write(where
, size
, val
);
543 if (cb
->bus_assigned
&&
544 bus
->number
== cb
->cardbus_busn
&&
545 PCI_SLOT(devfn
) == 0)
546 return bcm6348_do_cfg_write(0, 0,
547 PCI_DEVFN(CARDBUS_PCI_IDSEL
, 0),
550 return PCIBIOS_DEVICE_NOT_FOUND
;
553 static struct pci_ops bcm6348_cb_ops
= {
554 .read
= bcm6348_cb_read
,
555 .write
= bcm6348_cb_write
,
559 * only one IO window, so it cannot be shared by PCI and cardbus, use
560 * fixup to choose and detect unhandled configuration
562 static void bcm6348_pci_fixup(struct pci_dev
*dev
)
564 struct bcm6348_pci
*priv
= &bcm6348_pci
;
565 struct bcm6348_cb
*cb
= &priv
->cb
;
566 static int io_window
= -1;
567 int i
, found
, new_io_window
;
570 /* look for any io resource */
572 for (i
= 0; i
< DEVICE_COUNT_RESOURCE
; i
++) {
573 if (pci_resource_flags(dev
, i
) & IORESOURCE_IO
) {
582 /* skip our fake bus with only cardbus bridge on it */
583 if (dev
->bus
->number
== priv
->cb_bus
)
586 /* find on which bus the device is */
587 if (cb
->bus_assigned
&&
588 dev
->bus
->number
== cb
->cardbus_busn
&&
589 PCI_SLOT(dev
->devfn
) == 0)
594 if (new_io_window
== io_window
)
597 if (io_window
!= -1) {
598 pr_err("bcm63xx: both PCI and cardbus devices "
599 "need IO, which hardware cannot do\n");
603 pr_info("bcm63xx: PCI IO window assigned to %s\n",
604 (new_io_window
== 0) ? "PCI" : "cardbus");
606 val
= __raw_readl(priv
->pci
+ MPI_L2PIOREMAP_REG
);
608 val
|= MPI_L2PREMAP_IS_CARDBUS_MASK
;
610 val
&= ~MPI_L2PREMAP_IS_CARDBUS_MASK
;
611 __raw_writel(val
, priv
->pci
+ MPI_L2PIOREMAP_REG
);
613 io_window
= new_io_window
;
615 DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID
, PCI_ANY_ID
, bcm6348_pci_fixup
);
617 static struct resource bcm6348_cb_io_resource
= {
618 .name
= "bcm6348 CB IO space",
619 .flags
= IORESOURCE_IO
,
621 static struct resource bcm6348_cb_mem_resource
;
623 static struct pci_controller bcm6348_cb_controller
= {
624 .pci_ops
= &bcm6348_cb_ops
,
625 .io_resource
= &bcm6348_cb_io_resource
,
626 .mem_resource
= &bcm6348_cb_mem_resource
,
628 #endif /* CONFIG_CARDBUS */
630 static void bcm6348_pci_setup(struct bcm6348_pci
*priv
)
634 /* Setup local bus to PCI access (PCI memory) */
635 val
= bcm6348_pci_mem_resource
.start
& MPI_L2P_BASE_MASK
;
636 __raw_writel(val
, priv
->pci
+ MPI_L2PMEMBASE1_REG
);
637 __raw_writel(~(resource_size(&bcm6348_pci_mem_resource
) - 1),
638 priv
->pci
+ MPI_L2PMEMRANGE1_REG
);
639 __raw_writel(val
| MPI_L2PREMAP_ENABLED_MASK
,
640 priv
->pci
+ MPI_L2PMEMREMAP1_REG
);
642 /* Set Cardbus IDSEL (type 0 cfg access on primary bus for
643 * this IDSEL will be done on Cardbus instead) */
644 val
= __raw_readl(priv
->pcmcia
+ PCMCIA_C1_REG
);
645 val
&= ~PCMCIA_C1_CBIDSEL_MASK
;
646 val
|= (CARDBUS_PCI_IDSEL
<< PCMCIA_C1_CBIDSEL_SHIFT
);
647 __raw_writel(val
, priv
->pcmcia
+ PCMCIA_C1_REG
);
649 #ifdef CONFIG_CARDBUS
650 /* setup local bus to PCI access (Cardbus memory) */
651 val
= bcm6348_cb_mem_resource
.start
& MPI_L2P_BASE_MASK
;
652 __raw_writel(val
, priv
->pci
+ MPI_L2PMEMBASE2_REG
);
653 __raw_writel(~(resource_size(&bcm6348_cb_mem_resource
) - 1),
654 priv
->pci
+ MPI_L2PMEMRANGE2_REG
);
655 val
|= MPI_L2PREMAP_ENABLED_MASK
| MPI_L2PREMAP_IS_CARDBUS_MASK
;
656 __raw_writel(val
, priv
->pci
+ MPI_L2PMEMREMAP2_REG
);
658 /* disable second access windows */
659 __raw_writel(0, priv
->pci
+ MPI_L2PMEMREMAP2_REG
);
662 /* setup local bus to PCI access (IO memory), we have only 1
663 * IO window for both PCI and cardbus, but it cannot handle
664 * both at the same time, assume standard PCI for now, if
665 * cardbus card has IO zone, PCI fixup will change window to
667 val
= bcm6348_pci_io_resource
.start
& MPI_L2P_BASE_MASK
;
668 __raw_writel(val
, priv
->pci
+ MPI_L2PIOBASE_REG
);
669 __raw_writel(~(resource_size(&bcm6348_pci_io_resource
) - 1),
670 priv
->pci
+ MPI_L2PIORANGE_REG
);
671 __raw_writel(val
| MPI_L2PREMAP_ENABLED_MASK
,
672 priv
->pci
+ MPI_L2PIOREMAP_REG
);
674 /* Enable PCI related GPIO pins */
675 __raw_writel(MPI_LOCBUSCTL_EN_PCI_GPIO_MASK
,
676 priv
->pci
+ MPI_LOCBUSCTL_REG
);
678 /* Setup PCI to local bus access, used by PCI device to target
679 * local RAM while bus mastering */
680 bcm6348_int_cfg_writel(0, PCI_BASE_ADDRESS_3
);
682 val
= MPI_SP0_REMAP_ENABLE_MASK
;
685 __raw_writel(val
, priv
->pci
+ MPI_SP0_REMAP_REG
);
687 bcm6348_int_cfg_writel(0, PCI_BASE_ADDRESS_4
);
688 __raw_writel(0, priv
->pci
+ MPI_SP1_REMAP_REG
);
690 /* Setup sp0 range to local RAM size */
691 __raw_writel(~(memblock_phys_mem_size() - 1),
692 priv
->pci
+ MPI_SP0_RANGE_REG
);
693 __raw_writel(0, priv
->pci
+ MPI_SP1_RANGE_REG
);
695 /* Change host bridge retry counter to infinite number of
696 * retries, needed for some broadcom wifi cards with Silicon
697 * Backplane bus where access to srom seems very slow */
698 val
= bcm6348_int_cfg_readl(BCMPCI_REG_TIMERS
);
699 val
&= ~REG_TIMER_RETRY_MASK
;
700 bcm6348_int_cfg_writel(val
, BCMPCI_REG_TIMERS
);
702 /* EEnable memory decoder and bus mastering */
703 val
= bcm6348_int_cfg_readl(PCI_COMMAND
);
704 val
|= (PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
);
705 bcm6348_int_cfg_writel(val
, PCI_COMMAND
);
707 /* Enable read prefetching & disable byte swapping for bus
708 * mastering transfers */
709 val
= __raw_readl(priv
->pci
+ MPI_PCIMODESEL_REG
);
710 val
&= ~MPI_PCIMODESEL_BAR1_NOSWAP_MASK
;
711 val
&= ~MPI_PCIMODESEL_BAR2_NOSWAP_MASK
;
712 val
&= ~MPI_PCIMODESEL_PREFETCH_MASK
;
713 val
|= (8 << MPI_PCIMODESEL_PREFETCH_SHIFT
);
714 __raw_writel(val
, priv
->pci
+ MPI_PCIMODESEL_REG
);
716 /* Enable pci interrupt */
717 val
= __raw_readl(priv
->pci
+ MPI_LOCINT_REG
);
718 val
|= MPI_LOCINT_MASK(MPI_LOCINT_EXT_PCI_INT
);
719 __raw_writel(val
, priv
->pci
+ MPI_LOCINT_REG
);
722 static int bcm6348_pci_probe(struct platform_device
*pdev
)
724 struct device
*dev
= &pdev
->dev
;
725 struct device_node
*np
= dev
->of_node
;
726 struct bcm6348_pci
*priv
= &bcm6348_pci
;
727 struct resource
*res
;
728 LIST_HEAD(resources
);
730 of_pci_check_probe_only();
732 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
733 priv
->pci
= devm_ioremap_resource(dev
, res
);
734 if (IS_ERR(priv
->pci
))
735 return PTR_ERR(priv
->pci
);
737 priv
->pcmcia
= priv
->pci
+ PCMCIA_OFFSET
;
739 priv
->irq
= platform_get_irq(pdev
, 0);
743 bmips_pci_irq
= priv
->irq
;
745 priv
->reset
= devm_reset_control_get(dev
, "pci");
746 if (IS_ERR(priv
->reset
))
747 return PTR_ERR(priv
->reset
);
749 priv
->remap
= of_property_read_bool(np
, "brcm,remap");
751 reset_control_reset(priv
->reset
);
753 pci_load_of_ranges(&bcm6348_pci_controller
, np
);
754 if (!bcm6348_pci_mem_resource
.start
)
757 of_pci_parse_bus_range(np
, &bcm6348_pci_busn_resource
);
758 pci_add_resource(&resources
, &bcm6348_pci_busn_resource
);
760 #ifdef CONFIG_CARDBUS
761 bcm6348_cb_io_resource
.start
= bcm6348_pci_io_resource
.start
+ (resource_size(&bcm6348_pci_io_resource
) >> 1);
762 bcm6348_cb_io_resource
.end
= bcm6348_pci_io_resource
.end
;
763 bcm6348_pci_io_resource
.end
= bcm6348_pci_io_resource
.end
- (resource_size(&bcm6348_pci_io_resource
) >> 1);
767 * Configuration accesses are done through IO space, remap 4
768 * first bytes to access it from CPU.
770 * This means that no IO access from CPU should happen while
771 * we do a configuration cycle, but there's no way we can add
772 * a spinlock for each io access, so this is currently kind of
775 priv
->io
= ioremap(bcm6348_pci_io_resource
.start
, sizeof(u32
));
779 bcm6348_pci_setup(priv
);
781 register_pci_controller(&bcm6348_pci_controller
);
783 #ifdef CONFIG_CARDBUS
785 register_pci_controller(&bcm6348_cb_controller
);
786 #endif /* CONFIG_CARDBUS */
788 /* Mark memory space used for IO mapping as reserved */
789 request_mem_region(bcm6348_pci_io_resource
.start
,
790 resource_size(&bcm6348_pci_io_resource
),
791 "BCM6348 PCI IO space");
796 static const struct of_device_id bcm6348_pci_of_match
[] = {
797 { .compatible
= "brcm,bcm6348-pci", },
801 static struct platform_driver bcm6348_pci_driver
= {
802 .probe
= bcm6348_pci_probe
,
804 .name
= "bcm6348-pci",
805 .of_match_table
= bcm6348_pci_of_match
,
809 int __init
bcm6348_pci_init(void)
811 int ret
= platform_driver_register(&bcm6348_pci_driver
);
813 pr_err("pci-bcm6348: Error registering platform driver!\n");
816 late_initcall_sync(bcm6348_pci_init
);